diff options
author | Hans Verkuil <hans.verkuil@cisco.com> | 2012-05-18 04:22:38 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2012-07-30 17:34:17 -0400 |
commit | 4910adf1d086eb11e6b9d65c271cf20cef0575f4 (patch) | |
tree | 9f15294556243f982514e0d858a64ff9285fe1d4 /drivers/media/video/gspca/vicam.c | |
parent | 726795c1d94f7153edd0038b61fd6dd7dd0163d1 (diff) |
[media] vicam: convert to the control framework
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/gspca/vicam.c')
-rw-r--r-- | drivers/media/video/gspca/vicam.c | 67 |
1 files changed, 26 insertions, 41 deletions
diff --git a/drivers/media/video/gspca/vicam.c b/drivers/media/video/gspca/vicam.c index 15a30f7a4b2a..35afbd002233 100644 --- a/drivers/media/video/gspca/vicam.c +++ b/drivers/media/video/gspca/vicam.c | |||
@@ -44,17 +44,10 @@ MODULE_DESCRIPTION("GSPCA ViCam USB Camera Driver"); | |||
44 | MODULE_LICENSE("GPL"); | 44 | MODULE_LICENSE("GPL"); |
45 | MODULE_FIRMWARE(VICAM_FIRMWARE); | 45 | MODULE_FIRMWARE(VICAM_FIRMWARE); |
46 | 46 | ||
47 | enum e_ctrl { | ||
48 | GAIN, | ||
49 | EXPOSURE, | ||
50 | NCTRL /* number of controls */ | ||
51 | }; | ||
52 | |||
53 | struct sd { | 47 | struct sd { |
54 | struct gspca_dev gspca_dev; /* !! must be the first item */ | 48 | struct gspca_dev gspca_dev; /* !! must be the first item */ |
55 | struct work_struct work_struct; | 49 | struct work_struct work_struct; |
56 | struct workqueue_struct *work_thread; | 50 | struct workqueue_struct *work_thread; |
57 | struct gspca_ctrl ctrls[NCTRL]; | ||
58 | }; | 51 | }; |
59 | 52 | ||
60 | /* The vicam sensor has a resolution of 512 x 244, with I believe square | 53 | /* The vicam sensor has a resolution of 512 x 244, with I believe square |
@@ -86,31 +79,6 @@ static struct v4l2_pix_format vicam_mode[] = { | |||
86 | .colorspace = V4L2_COLORSPACE_SRGB,}, | 79 | .colorspace = V4L2_COLORSPACE_SRGB,}, |
87 | }; | 80 | }; |
88 | 81 | ||
89 | static const struct ctrl sd_ctrls[] = { | ||
90 | [GAIN] = { | ||
91 | { | ||
92 | .id = V4L2_CID_GAIN, | ||
93 | .type = V4L2_CTRL_TYPE_INTEGER, | ||
94 | .name = "Gain", | ||
95 | .minimum = 0, | ||
96 | .maximum = 255, | ||
97 | .step = 1, | ||
98 | .default_value = 200, | ||
99 | }, | ||
100 | }, | ||
101 | [EXPOSURE] = { | ||
102 | { | ||
103 | .id = V4L2_CID_EXPOSURE, | ||
104 | .type = V4L2_CTRL_TYPE_INTEGER, | ||
105 | .name = "Exposure", | ||
106 | .minimum = 0, | ||
107 | .maximum = 2047, | ||
108 | .step = 1, | ||
109 | .default_value = 256, | ||
110 | }, | ||
111 | }, | ||
112 | }; | ||
113 | |||
114 | static int vicam_control_msg(struct gspca_dev *gspca_dev, u8 request, | 82 | static int vicam_control_msg(struct gspca_dev *gspca_dev, u8 request, |
115 | u16 value, u16 index, u8 *data, u16 len) | 83 | u16 value, u16 index, u8 *data, u16 len) |
116 | { | 84 | { |
@@ -146,12 +114,13 @@ static int vicam_set_camera_power(struct gspca_dev *gspca_dev, int state) | |||
146 | */ | 114 | */ |
147 | static int vicam_read_frame(struct gspca_dev *gspca_dev, u8 *data, int size) | 115 | static int vicam_read_frame(struct gspca_dev *gspca_dev, u8 *data, int size) |
148 | { | 116 | { |
149 | struct sd *sd = (struct sd *)gspca_dev; | ||
150 | int ret, unscaled_height, act_len = 0; | 117 | int ret, unscaled_height, act_len = 0; |
151 | u8 *req_data = gspca_dev->usb_buf; | 118 | u8 *req_data = gspca_dev->usb_buf; |
119 | s32 expo = v4l2_ctrl_g_ctrl(gspca_dev->exposure); | ||
120 | s32 gain = v4l2_ctrl_g_ctrl(gspca_dev->gain); | ||
152 | 121 | ||
153 | memset(req_data, 0, 16); | 122 | memset(req_data, 0, 16); |
154 | req_data[0] = sd->ctrls[GAIN].val; | 123 | req_data[0] = gain; |
155 | if (gspca_dev->width == 256) | 124 | if (gspca_dev->width == 256) |
156 | req_data[1] |= 0x01; /* low nibble x-scale */ | 125 | req_data[1] |= 0x01; /* low nibble x-scale */ |
157 | if (gspca_dev->height <= 122) { | 126 | if (gspca_dev->height <= 122) { |
@@ -167,9 +136,9 @@ static int vicam_read_frame(struct gspca_dev *gspca_dev, u8 *data, int size) | |||
167 | else /* Up to 244 lines with req_data[3] == 0x08 */ | 136 | else /* Up to 244 lines with req_data[3] == 0x08 */ |
168 | req_data[3] = 0x08; /* vend? */ | 137 | req_data[3] = 0x08; /* vend? */ |
169 | 138 | ||
170 | if (sd->ctrls[EXPOSURE].val < 256) { | 139 | if (expo < 256) { |
171 | /* Frame rate maxed out, use partial frame expo time */ | 140 | /* Frame rate maxed out, use partial frame expo time */ |
172 | req_data[4] = 255 - sd->ctrls[EXPOSURE].val; | 141 | req_data[4] = 255 - expo; |
173 | req_data[5] = 0x00; | 142 | req_data[5] = 0x00; |
174 | req_data[6] = 0x00; | 143 | req_data[6] = 0x00; |
175 | req_data[7] = 0x01; | 144 | req_data[7] = 0x01; |
@@ -177,8 +146,8 @@ static int vicam_read_frame(struct gspca_dev *gspca_dev, u8 *data, int size) | |||
177 | /* Modify frame rate */ | 146 | /* Modify frame rate */ |
178 | req_data[4] = 0x00; | 147 | req_data[4] = 0x00; |
179 | req_data[5] = 0x00; | 148 | req_data[5] = 0x00; |
180 | req_data[6] = sd->ctrls[EXPOSURE].val & 0xFF; | 149 | req_data[6] = expo & 0xFF; |
181 | req_data[7] = sd->ctrls[EXPOSURE].val >> 8; | 150 | req_data[7] = expo >> 8; |
182 | } | 151 | } |
183 | req_data[8] = ((244 - unscaled_height) / 2) & ~0x01; /* vstart */ | 152 | req_data[8] = ((244 - unscaled_height) / 2) & ~0x01; /* vstart */ |
184 | /* bytes 9-15 do not seem to affect exposure or image quality */ | 153 | /* bytes 9-15 do not seem to affect exposure or image quality */ |
@@ -260,7 +229,6 @@ static int sd_config(struct gspca_dev *gspca_dev, | |||
260 | cam->bulk_size = 64; | 229 | cam->bulk_size = 64; |
261 | cam->cam_mode = vicam_mode; | 230 | cam->cam_mode = vicam_mode; |
262 | cam->nmodes = ARRAY_SIZE(vicam_mode); | 231 | cam->nmodes = ARRAY_SIZE(vicam_mode); |
263 | cam->ctrls = sd->ctrls; | ||
264 | 232 | ||
265 | INIT_WORK(&sd->work_struct, vicam_dostream); | 233 | INIT_WORK(&sd->work_struct, vicam_dostream); |
266 | 234 | ||
@@ -335,6 +303,24 @@ static void sd_stop0(struct gspca_dev *gspca_dev) | |||
335 | vicam_set_camera_power(gspca_dev, 0); | 303 | vicam_set_camera_power(gspca_dev, 0); |
336 | } | 304 | } |
337 | 305 | ||
306 | static int sd_init_controls(struct gspca_dev *gspca_dev) | ||
307 | { | ||
308 | struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler; | ||
309 | |||
310 | gspca_dev->vdev.ctrl_handler = hdl; | ||
311 | v4l2_ctrl_handler_init(hdl, 2); | ||
312 | gspca_dev->exposure = v4l2_ctrl_new_std(hdl, NULL, | ||
313 | V4L2_CID_EXPOSURE, 0, 2047, 1, 256); | ||
314 | gspca_dev->gain = v4l2_ctrl_new_std(hdl, NULL, | ||
315 | V4L2_CID_GAIN, 0, 255, 1, 200); | ||
316 | |||
317 | if (hdl->error) { | ||
318 | pr_err("Could not initialize controls\n"); | ||
319 | return hdl->error; | ||
320 | } | ||
321 | return 0; | ||
322 | } | ||
323 | |||
338 | /* Table of supported USB devices */ | 324 | /* Table of supported USB devices */ |
339 | static const struct usb_device_id device_table[] = { | 325 | static const struct usb_device_id device_table[] = { |
340 | {USB_DEVICE(0x04c1, 0x009d)}, | 326 | {USB_DEVICE(0x04c1, 0x009d)}, |
@@ -347,10 +333,9 @@ MODULE_DEVICE_TABLE(usb, device_table); | |||
347 | /* sub-driver description */ | 333 | /* sub-driver description */ |
348 | static const struct sd_desc sd_desc = { | 334 | static const struct sd_desc sd_desc = { |
349 | .name = MODULE_NAME, | 335 | .name = MODULE_NAME, |
350 | .ctrls = sd_ctrls, | ||
351 | .nctrls = ARRAY_SIZE(sd_ctrls), | ||
352 | .config = sd_config, | 336 | .config = sd_config, |
353 | .init = sd_init, | 337 | .init = sd_init, |
338 | .init_controls = sd_init_controls, | ||
354 | .start = sd_start, | 339 | .start = sd_start, |
355 | .stop0 = sd_stop0, | 340 | .stop0 = sd_stop0, |
356 | }; | 341 | }; |