aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2013-01-29 05:21:02 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2013-02-05 15:23:47 -0500
commited986d1fee77bbbb62291a1db1c7edbb00d99515 (patch)
tree6c70d0663a9a794e11b28301749faf5dac3c756d /drivers/media
parentcd13823f5db3e66552801c04f0e761408ef17eb0 (diff)
[media] meye: convert to the control framework
Convert the meye driver to the control framework. Some private controls have been replaced with standardized controls (SHARPNESS and JPEGQUAL). The AGC control looks like it can be replaced by the AUTOGAIN control, but it isn't a boolean so I do not know how to interpret it. The FRAMERATE control looks like it can be replaced by S_PARM, but again, without knowing how to interpret it I decided to leave it alone. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media')
-rw-r--r--drivers/media/pci/meye/meye.c278
-rw-r--r--drivers/media/pci/meye/meye.h2
2 files changed, 91 insertions, 189 deletions
diff --git a/drivers/media/pci/meye/meye.c b/drivers/media/pci/meye/meye.c
index 3b39deaa8f6b..7859c43479d7 100644
--- a/drivers/media/pci/meye/meye.c
+++ b/drivers/media/pci/meye/meye.c
@@ -35,6 +35,8 @@
35#include <media/v4l2-common.h> 35#include <media/v4l2-common.h>
36#include <media/v4l2-device.h> 36#include <media/v4l2-device.h>
37#include <media/v4l2-ioctl.h> 37#include <media/v4l2-ioctl.h>
38#include <media/v4l2-fh.h>
39#include <media/v4l2-event.h>
38#include <asm/uaccess.h> 40#include <asm/uaccess.h>
39#include <asm/io.h> 41#include <asm/io.h>
40#include <linux/delay.h> 42#include <linux/delay.h>
@@ -865,7 +867,7 @@ static int meye_open(struct file *file)
865 meye.grab_buffer[i].state = MEYE_BUF_UNUSED; 867 meye.grab_buffer[i].state = MEYE_BUF_UNUSED;
866 kfifo_reset(&meye.grabq); 868 kfifo_reset(&meye.grabq);
867 kfifo_reset(&meye.doneq); 869 kfifo_reset(&meye.doneq);
868 return 0; 870 return v4l2_fh_open(file);
869} 871}
870 872
871static int meye_release(struct file *file) 873static int meye_release(struct file *file)
@@ -873,7 +875,7 @@ static int meye_release(struct file *file)
873 mchip_hic_stop(); 875 mchip_hic_stop();
874 mchip_dma_free(); 876 mchip_dma_free();
875 clear_bit(0, &meye.in_use); 877 clear_bit(0, &meye.in_use);
876 return 0; 878 return v4l2_fh_release(file);
877} 879}
878 880
879static int meyeioc_g_params(struct meye_params *p) 881static int meyeioc_g_params(struct meye_params *p)
@@ -1032,8 +1034,9 @@ static int vidioc_querycap(struct file *file, void *fh,
1032 cap->version = (MEYE_DRIVER_MAJORVERSION << 8) + 1034 cap->version = (MEYE_DRIVER_MAJORVERSION << 8) +
1033 MEYE_DRIVER_MINORVERSION; 1035 MEYE_DRIVER_MINORVERSION;
1034 1036
1035 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | 1037 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE |
1036 V4L2_CAP_STREAMING; 1038 V4L2_CAP_STREAMING;
1039 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
1037 1040
1038 return 0; 1041 return 0;
1039} 1042}
@@ -1063,191 +1066,50 @@ static int vidioc_s_input(struct file *file, void *fh, unsigned int i)
1063 return 0; 1066 return 0;
1064} 1067}
1065 1068
1066static int vidioc_queryctrl(struct file *file, void *fh, 1069static int meye_s_ctrl(struct v4l2_ctrl *ctrl)
1067 struct v4l2_queryctrl *c)
1068{
1069 switch (c->id) {
1070
1071 case V4L2_CID_BRIGHTNESS:
1072 c->type = V4L2_CTRL_TYPE_INTEGER;
1073 strcpy(c->name, "Brightness");
1074 c->minimum = 0;
1075 c->maximum = 63;
1076 c->step = 1;
1077 c->default_value = 32;
1078 c->flags = 0;
1079 break;
1080 case V4L2_CID_HUE:
1081 c->type = V4L2_CTRL_TYPE_INTEGER;
1082 strcpy(c->name, "Hue");
1083 c->minimum = 0;
1084 c->maximum = 63;
1085 c->step = 1;
1086 c->default_value = 32;
1087 c->flags = 0;
1088 break;
1089 case V4L2_CID_CONTRAST:
1090 c->type = V4L2_CTRL_TYPE_INTEGER;
1091 strcpy(c->name, "Contrast");
1092 c->minimum = 0;
1093 c->maximum = 63;
1094 c->step = 1;
1095 c->default_value = 32;
1096 c->flags = 0;
1097 break;
1098 case V4L2_CID_SATURATION:
1099 c->type = V4L2_CTRL_TYPE_INTEGER;
1100 strcpy(c->name, "Saturation");
1101 c->minimum = 0;
1102 c->maximum = 63;
1103 c->step = 1;
1104 c->default_value = 32;
1105 c->flags = 0;
1106 break;
1107 case V4L2_CID_AGC:
1108 c->type = V4L2_CTRL_TYPE_INTEGER;
1109 strcpy(c->name, "Agc");
1110 c->minimum = 0;
1111 c->maximum = 63;
1112 c->step = 1;
1113 c->default_value = 48;
1114 c->flags = 0;
1115 break;
1116 case V4L2_CID_MEYE_SHARPNESS:
1117 case V4L2_CID_SHARPNESS:
1118 c->type = V4L2_CTRL_TYPE_INTEGER;
1119 strcpy(c->name, "Sharpness");
1120 c->minimum = 0;
1121 c->maximum = 63;
1122 c->step = 1;
1123 c->default_value = 32;
1124
1125 /* Continue to report legacy private SHARPNESS ctrl but
1126 * say it is disabled in preference to ctrl in the spec
1127 */
1128 c->flags = (c->id == V4L2_CID_SHARPNESS) ? 0 :
1129 V4L2_CTRL_FLAG_DISABLED;
1130 break;
1131 case V4L2_CID_PICTURE:
1132 c->type = V4L2_CTRL_TYPE_INTEGER;
1133 strcpy(c->name, "Picture");
1134 c->minimum = 0;
1135 c->maximum = 63;
1136 c->step = 1;
1137 c->default_value = 0;
1138 c->flags = 0;
1139 break;
1140 case V4L2_CID_JPEGQUAL:
1141 c->type = V4L2_CTRL_TYPE_INTEGER;
1142 strcpy(c->name, "JPEG quality");
1143 c->minimum = 0;
1144 c->maximum = 10;
1145 c->step = 1;
1146 c->default_value = 8;
1147 c->flags = 0;
1148 break;
1149 case V4L2_CID_FRAMERATE:
1150 c->type = V4L2_CTRL_TYPE_INTEGER;
1151 strcpy(c->name, "Framerate");
1152 c->minimum = 0;
1153 c->maximum = 31;
1154 c->step = 1;
1155 c->default_value = 0;
1156 c->flags = 0;
1157 break;
1158 default:
1159 return -EINVAL;
1160 }
1161
1162 return 0;
1163}
1164
1165static int vidioc_s_ctrl(struct file *file, void *fh, struct v4l2_control *c)
1166{ 1070{
1167 mutex_lock(&meye.lock); 1071 mutex_lock(&meye.lock);
1168 switch (c->id) { 1072 switch (ctrl->id) {
1169 case V4L2_CID_BRIGHTNESS: 1073 case V4L2_CID_BRIGHTNESS:
1170 sony_pic_camera_command( 1074 sony_pic_camera_command(
1171 SONY_PIC_COMMAND_SETCAMERABRIGHTNESS, c->value); 1075 SONY_PIC_COMMAND_SETCAMERABRIGHTNESS, ctrl->val);
1172 meye.brightness = c->value << 10; 1076 meye.brightness = ctrl->val << 10;
1173 break; 1077 break;
1174 case V4L2_CID_HUE: 1078 case V4L2_CID_HUE:
1175 sony_pic_camera_command( 1079 sony_pic_camera_command(
1176 SONY_PIC_COMMAND_SETCAMERAHUE, c->value); 1080 SONY_PIC_COMMAND_SETCAMERAHUE, ctrl->val);
1177 meye.hue = c->value << 10; 1081 meye.hue = ctrl->val << 10;
1178 break; 1082 break;
1179 case V4L2_CID_CONTRAST: 1083 case V4L2_CID_CONTRAST:
1180 sony_pic_camera_command( 1084 sony_pic_camera_command(
1181 SONY_PIC_COMMAND_SETCAMERACONTRAST, c->value); 1085 SONY_PIC_COMMAND_SETCAMERACONTRAST, ctrl->val);
1182 meye.contrast = c->value << 10; 1086 meye.contrast = ctrl->val << 10;
1183 break; 1087 break;
1184 case V4L2_CID_SATURATION: 1088 case V4L2_CID_SATURATION:
1185 sony_pic_camera_command( 1089 sony_pic_camera_command(
1186 SONY_PIC_COMMAND_SETCAMERACOLOR, c->value); 1090 SONY_PIC_COMMAND_SETCAMERACOLOR, ctrl->val);
1187 meye.colour = c->value << 10; 1091 meye.colour = ctrl->val << 10;
1188 break; 1092 break;
1189 case V4L2_CID_AGC: 1093 case V4L2_CID_MEYE_AGC:
1190 sony_pic_camera_command( 1094 sony_pic_camera_command(
1191 SONY_PIC_COMMAND_SETCAMERAAGC, c->value); 1095 SONY_PIC_COMMAND_SETCAMERAAGC, ctrl->val);
1192 meye.params.agc = c->value; 1096 meye.params.agc = ctrl->val;
1193 break; 1097 break;
1194 case V4L2_CID_SHARPNESS: 1098 case V4L2_CID_SHARPNESS:
1195 case V4L2_CID_MEYE_SHARPNESS:
1196 sony_pic_camera_command( 1099 sony_pic_camera_command(
1197 SONY_PIC_COMMAND_SETCAMERASHARPNESS, c->value); 1100 SONY_PIC_COMMAND_SETCAMERASHARPNESS, ctrl->val);
1198 meye.params.sharpness = c->value; 1101 meye.params.sharpness = ctrl->val;
1199 break; 1102 break;
1200 case V4L2_CID_PICTURE: 1103 case V4L2_CID_MEYE_PICTURE:
1201 sony_pic_camera_command( 1104 sony_pic_camera_command(
1202 SONY_PIC_COMMAND_SETCAMERAPICTURE, c->value); 1105 SONY_PIC_COMMAND_SETCAMERAPICTURE, ctrl->val);
1203 meye.params.picture = c->value; 1106 meye.params.picture = ctrl->val;
1204 break; 1107 break;
1205 case V4L2_CID_JPEGQUAL: 1108 case V4L2_CID_JPEG_COMPRESSION_QUALITY:
1206 meye.params.quality = c->value; 1109 meye.params.quality = ctrl->val;
1207 break; 1110 break;
1208 case V4L2_CID_FRAMERATE: 1111 case V4L2_CID_MEYE_FRAMERATE:
1209 meye.params.framerate = c->value; 1112 meye.params.framerate = ctrl->val;
1210 break;
1211 default:
1212 mutex_unlock(&meye.lock);
1213 return -EINVAL;
1214 }
1215 mutex_unlock(&meye.lock);
1216
1217 return 0;
1218}
1219
1220static int vidioc_g_ctrl(struct file *file, void *fh, struct v4l2_control *c)
1221{
1222 mutex_lock(&meye.lock);
1223 switch (c->id) {
1224 case V4L2_CID_BRIGHTNESS:
1225 c->value = meye.brightness >> 10;
1226 break;
1227 case V4L2_CID_HUE:
1228 c->value = meye.hue >> 10;
1229 break;
1230 case V4L2_CID_CONTRAST:
1231 c->value = meye.contrast >> 10;
1232 break;
1233 case V4L2_CID_SATURATION:
1234 c->value = meye.colour >> 10;
1235 break;
1236 case V4L2_CID_AGC:
1237 c->value = meye.params.agc;
1238 break;
1239 case V4L2_CID_SHARPNESS:
1240 case V4L2_CID_MEYE_SHARPNESS:
1241 c->value = meye.params.sharpness;
1242 break;
1243 case V4L2_CID_PICTURE:
1244 c->value = meye.params.picture;
1245 break;
1246 case V4L2_CID_JPEGQUAL:
1247 c->value = meye.params.quality;
1248 break;
1249 case V4L2_CID_FRAMERATE:
1250 c->value = meye.params.framerate;
1251 break; 1113 break;
1252 default: 1114 default:
1253 mutex_unlock(&meye.lock); 1115 mutex_unlock(&meye.lock);
@@ -1577,12 +1439,12 @@ static long vidioc_default(struct file *file, void *fh, bool valid_prio,
1577 1439
1578static unsigned int meye_poll(struct file *file, poll_table *wait) 1440static unsigned int meye_poll(struct file *file, poll_table *wait)
1579{ 1441{
1580 unsigned int res = 0; 1442 unsigned int res = v4l2_ctrl_poll(file, wait);
1581 1443
1582 mutex_lock(&meye.lock); 1444 mutex_lock(&meye.lock);
1583 poll_wait(file, &meye.proc_list, wait); 1445 poll_wait(file, &meye.proc_list, wait);
1584 if (kfifo_len(&meye.doneq)) 1446 if (kfifo_len(&meye.doneq))
1585 res = POLLIN | POLLRDNORM; 1447 res |= POLLIN | POLLRDNORM;
1586 mutex_unlock(&meye.lock); 1448 mutex_unlock(&meye.lock);
1587 return res; 1449 return res;
1588} 1450}
@@ -1669,9 +1531,6 @@ static const struct v4l2_ioctl_ops meye_ioctl_ops = {
1669 .vidioc_enum_input = vidioc_enum_input, 1531 .vidioc_enum_input = vidioc_enum_input,
1670 .vidioc_g_input = vidioc_g_input, 1532 .vidioc_g_input = vidioc_g_input,
1671 .vidioc_s_input = vidioc_s_input, 1533 .vidioc_s_input = vidioc_s_input,
1672 .vidioc_queryctrl = vidioc_queryctrl,
1673 .vidioc_s_ctrl = vidioc_s_ctrl,
1674 .vidioc_g_ctrl = vidioc_g_ctrl,
1675 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, 1534 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1676 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, 1535 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
1677 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, 1536 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
@@ -1682,6 +1541,9 @@ static const struct v4l2_ioctl_ops meye_ioctl_ops = {
1682 .vidioc_dqbuf = vidioc_dqbuf, 1541 .vidioc_dqbuf = vidioc_dqbuf,
1683 .vidioc_streamon = vidioc_streamon, 1542 .vidioc_streamon = vidioc_streamon,
1684 .vidioc_streamoff = vidioc_streamoff, 1543 .vidioc_streamoff = vidioc_streamoff,
1544 .vidioc_log_status = v4l2_ctrl_log_status,
1545 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1546 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1685 .vidioc_default = vidioc_default, 1547 .vidioc_default = vidioc_default,
1686}; 1548};
1687 1549
@@ -1692,6 +1554,10 @@ static struct video_device meye_template = {
1692 .release = video_device_release, 1554 .release = video_device_release,
1693}; 1555};
1694 1556
1557static const struct v4l2_ctrl_ops meye_ctrl_ops = {
1558 .s_ctrl = meye_s_ctrl,
1559};
1560
1695#ifdef CONFIG_PM 1561#ifdef CONFIG_PM
1696static int meye_suspend(struct pci_dev *pdev, pm_message_t state) 1562static int meye_suspend(struct pci_dev *pdev, pm_message_t state)
1697{ 1563{
@@ -1730,6 +1596,32 @@ static int meye_resume(struct pci_dev *pdev)
1730 1596
1731static int meye_probe(struct pci_dev *pcidev, const struct pci_device_id *ent) 1597static int meye_probe(struct pci_dev *pcidev, const struct pci_device_id *ent)
1732{ 1598{
1599 static const struct v4l2_ctrl_config ctrl_agc = {
1600 .id = V4L2_CID_MEYE_AGC,
1601 .type = V4L2_CTRL_TYPE_INTEGER,
1602 .ops = &meye_ctrl_ops,
1603 .name = "AGC",
1604 .max = 63,
1605 .step = 1,
1606 .def = 48,
1607 .flags = V4L2_CTRL_FLAG_SLIDER,
1608 };
1609 static const struct v4l2_ctrl_config ctrl_picture = {
1610 .id = V4L2_CID_MEYE_PICTURE,
1611 .type = V4L2_CTRL_TYPE_INTEGER,
1612 .ops = &meye_ctrl_ops,
1613 .name = "Picture",
1614 .max = 63,
1615 .step = 1,
1616 };
1617 static const struct v4l2_ctrl_config ctrl_framerate = {
1618 .id = V4L2_CID_MEYE_FRAMERATE,
1619 .type = V4L2_CTRL_TYPE_INTEGER,
1620 .ops = &meye_ctrl_ops,
1621 .name = "Framerate",
1622 .max = 31,
1623 .step = 1,
1624 };
1733 struct v4l2_device *v4l2_dev = &meye.v4l2_dev; 1625 struct v4l2_device *v4l2_dev = &meye.v4l2_dev;
1734 int ret = -EBUSY; 1626 int ret = -EBUSY;
1735 unsigned long mchip_adr; 1627 unsigned long mchip_adr;
@@ -1833,24 +1725,31 @@ static int meye_probe(struct pci_dev *pcidev, const struct pci_device_id *ent)
1833 1725
1834 mutex_init(&meye.lock); 1726 mutex_init(&meye.lock);
1835 init_waitqueue_head(&meye.proc_list); 1727 init_waitqueue_head(&meye.proc_list);
1836 meye.brightness = 32 << 10; 1728
1837 meye.hue = 32 << 10; 1729 v4l2_ctrl_handler_init(&meye.hdl, 3);
1838 meye.colour = 32 << 10; 1730 v4l2_ctrl_new_std(&meye.hdl, &meye_ctrl_ops,
1839 meye.contrast = 32 << 10; 1731 V4L2_CID_BRIGHTNESS, 0, 63, 1, 32);
1840 meye.params.subsample = 0; 1732 v4l2_ctrl_new_std(&meye.hdl, &meye_ctrl_ops,
1841 meye.params.quality = 8; 1733 V4L2_CID_HUE, 0, 63, 1, 32);
1842 meye.params.sharpness = 32; 1734 v4l2_ctrl_new_std(&meye.hdl, &meye_ctrl_ops,
1843 meye.params.agc = 48; 1735 V4L2_CID_CONTRAST, 0, 63, 1, 32);
1844 meye.params.picture = 0; 1736 v4l2_ctrl_new_std(&meye.hdl, &meye_ctrl_ops,
1845 meye.params.framerate = 0; 1737 V4L2_CID_SATURATION, 0, 63, 1, 32);
1846 1738 v4l2_ctrl_new_custom(&meye.hdl, &ctrl_agc, NULL);
1847 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERABRIGHTNESS, 32); 1739 v4l2_ctrl_new_std(&meye.hdl, &meye_ctrl_ops,
1848 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAHUE, 32); 1740 V4L2_CID_SHARPNESS, 0, 63, 1, 32);
1849 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERACOLOR, 32); 1741 v4l2_ctrl_new_custom(&meye.hdl, &ctrl_picture, NULL);
1850 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERACONTRAST, 32); 1742 v4l2_ctrl_new_std(&meye.hdl, &meye_ctrl_ops,
1851 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERASHARPNESS, 32); 1743 V4L2_CID_JPEG_COMPRESSION_QUALITY, 0, 10, 1, 8);
1852 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAPICTURE, 0); 1744 v4l2_ctrl_new_custom(&meye.hdl, &ctrl_framerate, NULL);
1853 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAAGC, 48); 1745 if (meye.hdl.error) {
1746 v4l2_err(v4l2_dev, "couldn't register controls\n");
1747 goto outvideoreg;
1748 }
1749
1750 v4l2_ctrl_handler_setup(&meye.hdl);
1751 meye.vdev->ctrl_handler = &meye.hdl;
1752 set_bit(V4L2_FL_USE_FH_PRIO, &meye.vdev->flags);
1854 1753
1855 if (video_register_device(meye.vdev, VFL_TYPE_GRABBER, 1754 if (video_register_device(meye.vdev, VFL_TYPE_GRABBER,
1856 video_nr) < 0) { 1755 video_nr) < 0) {
@@ -1866,6 +1765,7 @@ static int meye_probe(struct pci_dev *pcidev, const struct pci_device_id *ent)
1866 return 0; 1765 return 0;
1867 1766
1868outvideoreg: 1767outvideoreg:
1768 v4l2_ctrl_handler_free(&meye.hdl);
1869 free_irq(meye.mchip_irq, meye_irq); 1769 free_irq(meye.mchip_irq, meye_irq);
1870outreqirq: 1770outreqirq:
1871 iounmap(meye.mchip_mmregs); 1771 iounmap(meye.mchip_mmregs);
diff --git a/drivers/media/pci/meye/meye.h b/drivers/media/pci/meye/meye.h
index 4bdeb03f1644..6fed9274cfa5 100644
--- a/drivers/media/pci/meye/meye.h
+++ b/drivers/media/pci/meye/meye.h
@@ -39,6 +39,7 @@
39#include <linux/types.h> 39#include <linux/types.h>
40#include <linux/pci.h> 40#include <linux/pci.h>
41#include <linux/kfifo.h> 41#include <linux/kfifo.h>
42#include <media/v4l2-ctrls.h>
42 43
43/****************************************************************************/ 44/****************************************************************************/
44/* Motion JPEG chip registers */ 45/* Motion JPEG chip registers */
@@ -290,6 +291,7 @@ struct meye_grab_buffer {
290/* Motion Eye device structure */ 291/* Motion Eye device structure */
291struct meye { 292struct meye {
292 struct v4l2_device v4l2_dev; /* Main v4l2_device struct */ 293 struct v4l2_device v4l2_dev; /* Main v4l2_device struct */
294 struct v4l2_ctrl_handler hdl;
293 struct pci_dev *mchip_dev; /* pci device */ 295 struct pci_dev *mchip_dev; /* pci device */
294 u8 mchip_irq; /* irq */ 296 u8 mchip_irq; /* irq */
295 u8 mchip_mode; /* actual mchip mode: HIC_MODE... */ 297 u8 mchip_mode; /* actual mchip mode: HIC_MODE... */