From fb8716a3e1e82207691eb1cb11e2daad829c2c20 Mon Sep 17 00:00:00 2001
From: Brian Johnson <brijohn@gmail.com>
Date: Sat, 2 May 2009 20:11:11 -0400
Subject: [PATCH] Implement ENUM_FRAMESIZES

Signed-off-by: Brian Johnson <brijohn@gmail.com>
---
 sn9c20x-v4l2.c |   50 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 49 insertions(+), 1 deletions(-)

diff --git a/sn9c20x-v4l2.c b/sn9c20x-v4l2.c
index 2c99fbc..5362991 100644
--- a/sn9c20x-v4l2.c
+++ b/sn9c20x-v4l2.c
@@ -704,6 +704,36 @@ int sn9c20x_vidioc_querycap(struct file *file, void *priv,
 /**
  * @param file
  * @param priv
+ * @param cap
+ *
+ * @return 0
+ *
+ */
+int sn9c20x_vidioc_enum_framesizes(struct file *file, void *priv,
+	struct v4l2_frmsizeenum *size)
+{
+	struct usb_sn9c20x *dev;
+
+	dev = video_get_drvdata(priv);
+
+	UDIA_DEBUG("ENUM_FRAMESIZES\n");
+
+	if (size->index >= SN9C20X_N_MODES)
+		return -EINVAL;
+
+	size->type = V4L2_FRMSIZE_TYPE_DISCRETE;
+	size->discrete.width = sn9c20x_modes[size->index].width;
+	size->discrete.height = sn9c20x_modes[size->index].height;
+
+	UDIA_DEBUG("Framesize: %dx%d\n", size->discrete.width,
+					 size->discrete.height);
+
+	return 0;
+}
+
+/**
+ * @param file
+ * @param priv
  * @param input
  *
  * @return 0 or negative error code
@@ -1347,7 +1377,22 @@ static long v4l_sn9c20x_ioctl(struct file *fp,
 		return -EFAULT;
 
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
-	err = video_ioctl2(inode, fp, cmd, arg);
+	switch (cmd) {
+	case VIDIOC_ENUM_FRAMESIZES:
+	{
+		struct v4l2_frmsizeenum size;
+		if (copy_from_user(&size, (void __user *)arg, sizeof(size)))
+			return -EFAULT;
+		err = sn9c20x_vidioc_enum_framesizes(fp,
+						     fp->private_data,
+						     &size);
+		if (copy_to_user((void __user *)arg, &size, sizeof(size)))
+			return -EFAULT;
+		break;
+	}
+	default:
+		err = video_ioctl2(inode, fp, cmd, arg);
+	}
 #else
 	err = video_ioctl2(fp, cmd, arg);
 #endif
@@ -1359,6 +1404,9 @@ static long v4l_sn9c20x_ioctl(struct file *fp,
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
 static const struct v4l2_ioctl_ops sn9c20x_v4l2_ioctl_ops = {
 	.vidioc_querycap            = sn9c20x_vidioc_querycap,
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29)
+	.vidioc_enum_framesizes     = sn9c20x_vidioc_enum_framesizes,
+#endif
 	.vidioc_enum_fmt_vid_cap    = sn9c20x_vidioc_enum_fmt_cap,
 	.vidioc_try_fmt_vid_cap     = sn9c20x_vidioc_try_fmt_cap,
 	.vidioc_s_fmt_vid_cap       = sn9c20x_vidioc_s_fmt_cap,
-- 
1.5.6.3

