diff options
author | Jean-François Moine <moinejf@free.fr> | 2010-10-16 13:07:06 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2010-10-21 05:55:52 -0400 |
commit | e3b4d2c6ae5d15f9f9ae36cfc5335b3a0861644f (patch) | |
tree | df8b461418365021eb207e47b28b025f00d3cee9 /drivers/media/video/gspca | |
parent | 2e0544a8ac5d96efc17bab94f08957ce0efb1220 (diff) |
[media] gspca - mars: Use the new video control mechanism
Signed-off-by: Jean-François Moine <moinejf@free.fr>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/gspca')
-rw-r--r-- | drivers/media/video/gspca/mars.c | 206 |
1 files changed, 75 insertions, 131 deletions
diff --git a/drivers/media/video/gspca/mars.c b/drivers/media/video/gspca/mars.c index 45be6a872795..cd0d69277b02 100644 --- a/drivers/media/video/gspca/mars.c +++ b/drivers/media/video/gspca/mars.c | |||
@@ -28,14 +28,21 @@ MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); | |||
28 | MODULE_DESCRIPTION("GSPCA/Mars USB Camera Driver"); | 28 | MODULE_DESCRIPTION("GSPCA/Mars USB Camera Driver"); |
29 | MODULE_LICENSE("GPL"); | 29 | MODULE_LICENSE("GPL"); |
30 | 30 | ||
31 | /* controls */ | ||
32 | enum e_ctrl { | ||
33 | BRIGHTNESS, | ||
34 | COLORS, | ||
35 | GAMMA, | ||
36 | SHARPNESS, | ||
37 | NCTRLS /* number of controls */ | ||
38 | }; | ||
39 | |||
31 | /* specific webcam descriptor */ | 40 | /* specific webcam descriptor */ |
32 | struct sd { | 41 | struct sd { |
33 | struct gspca_dev gspca_dev; /* !! must be the first item */ | 42 | struct gspca_dev gspca_dev; /* !! must be the first item */ |
34 | 43 | ||
35 | u8 brightness; | 44 | struct gspca_ctrl ctrls[NCTRLS]; |
36 | u8 colors; | 45 | |
37 | u8 gamma; | ||
38 | u8 sharpness; | ||
39 | u8 quality; | 46 | u8 quality; |
40 | #define QUALITY_MIN 40 | 47 | #define QUALITY_MIN 40 |
41 | #define QUALITY_MAX 70 | 48 | #define QUALITY_MAX 70 |
@@ -45,17 +52,13 @@ struct sd { | |||
45 | }; | 52 | }; |
46 | 53 | ||
47 | /* V4L2 controls supported by the driver */ | 54 | /* V4L2 controls supported by the driver */ |
48 | static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); | 55 | static void setbrightness(struct gspca_dev *gspca_dev); |
49 | static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); | 56 | static void setcolors(struct gspca_dev *gspca_dev); |
50 | static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val); | 57 | static void setgamma(struct gspca_dev *gspca_dev); |
51 | static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val); | 58 | static void setsharpness(struct gspca_dev *gspca_dev); |
52 | static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val); | 59 | |
53 | static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val); | 60 | static const struct ctrl sd_ctrls[NCTRLS] = { |
54 | static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val); | 61 | [BRIGHTNESS] = { |
55 | static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val); | ||
56 | |||
57 | static const struct ctrl sd_ctrls[] = { | ||
58 | { | ||
59 | { | 62 | { |
60 | .id = V4L2_CID_BRIGHTNESS, | 63 | .id = V4L2_CID_BRIGHTNESS, |
61 | .type = V4L2_CTRL_TYPE_INTEGER, | 64 | .type = V4L2_CTRL_TYPE_INTEGER, |
@@ -63,13 +66,11 @@ static const struct ctrl sd_ctrls[] = { | |||
63 | .minimum = 0, | 66 | .minimum = 0, |
64 | .maximum = 30, | 67 | .maximum = 30, |
65 | .step = 1, | 68 | .step = 1, |
66 | #define BRIGHTNESS_DEF 15 | 69 | .default_value = 15, |
67 | .default_value = BRIGHTNESS_DEF, | ||
68 | }, | 70 | }, |
69 | .set = sd_setbrightness, | 71 | .set_control = setbrightness |
70 | .get = sd_getbrightness, | ||
71 | }, | 72 | }, |
72 | { | 73 | [COLORS] = { |
73 | { | 74 | { |
74 | .id = V4L2_CID_SATURATION, | 75 | .id = V4L2_CID_SATURATION, |
75 | .type = V4L2_CTRL_TYPE_INTEGER, | 76 | .type = V4L2_CTRL_TYPE_INTEGER, |
@@ -77,13 +78,11 @@ static const struct ctrl sd_ctrls[] = { | |||
77 | .minimum = 1, | 78 | .minimum = 1, |
78 | .maximum = 255, | 79 | .maximum = 255, |
79 | .step = 1, | 80 | .step = 1, |
80 | #define COLOR_DEF 200 | 81 | .default_value = 200, |
81 | .default_value = COLOR_DEF, | ||
82 | }, | 82 | }, |
83 | .set = sd_setcolors, | 83 | .set_control = setcolors |
84 | .get = sd_getcolors, | ||
85 | }, | 84 | }, |
86 | { | 85 | [GAMMA] = { |
87 | { | 86 | { |
88 | .id = V4L2_CID_GAMMA, | 87 | .id = V4L2_CID_GAMMA, |
89 | .type = V4L2_CTRL_TYPE_INTEGER, | 88 | .type = V4L2_CTRL_TYPE_INTEGER, |
@@ -91,13 +90,11 @@ static const struct ctrl sd_ctrls[] = { | |||
91 | .minimum = 0, | 90 | .minimum = 0, |
92 | .maximum = 3, | 91 | .maximum = 3, |
93 | .step = 1, | 92 | .step = 1, |
94 | #define GAMMA_DEF 1 | 93 | .default_value = 1, |
95 | .default_value = GAMMA_DEF, | ||
96 | }, | 94 | }, |
97 | .set = sd_setgamma, | 95 | .set_control = setgamma |
98 | .get = sd_getgamma, | ||
99 | }, | 96 | }, |
100 | { | 97 | [SHARPNESS] = { |
101 | { | 98 | { |
102 | .id = V4L2_CID_SHARPNESS, | 99 | .id = V4L2_CID_SHARPNESS, |
103 | .type = V4L2_CTRL_TYPE_INTEGER, | 100 | .type = V4L2_CTRL_TYPE_INTEGER, |
@@ -105,11 +102,9 @@ static const struct ctrl sd_ctrls[] = { | |||
105 | .minimum = 0, | 102 | .minimum = 0, |
106 | .maximum = 2, | 103 | .maximum = 2, |
107 | .step = 1, | 104 | .step = 1, |
108 | #define SHARPNESS_DEF 1 | 105 | .default_value = 1, |
109 | .default_value = SHARPNESS_DEF, | ||
110 | }, | 106 | }, |
111 | .set = sd_setsharpness, | 107 | .set_control = setsharpness |
112 | .get = sd_getsharpness, | ||
113 | }, | 108 | }, |
114 | }; | 109 | }; |
115 | 110 | ||
@@ -167,6 +162,45 @@ static void mi_w(struct gspca_dev *gspca_dev, | |||
167 | reg_w(gspca_dev, 4); | 162 | reg_w(gspca_dev, 4); |
168 | } | 163 | } |
169 | 164 | ||
165 | static void setbrightness(struct gspca_dev *gspca_dev) | ||
166 | { | ||
167 | struct sd *sd = (struct sd *) gspca_dev; | ||
168 | |||
169 | gspca_dev->usb_buf[0] = 0x61; | ||
170 | gspca_dev->usb_buf[1] = sd->ctrls[BRIGHTNESS].val; | ||
171 | reg_w(gspca_dev, 2); | ||
172 | } | ||
173 | |||
174 | static void setcolors(struct gspca_dev *gspca_dev) | ||
175 | { | ||
176 | struct sd *sd = (struct sd *) gspca_dev; | ||
177 | s16 val; | ||
178 | |||
179 | val = sd->ctrls[COLORS].val; | ||
180 | gspca_dev->usb_buf[0] = 0x5f; | ||
181 | gspca_dev->usb_buf[1] = val << 3; | ||
182 | gspca_dev->usb_buf[2] = ((val >> 2) & 0xf8) | 0x04; | ||
183 | reg_w(gspca_dev, 3); | ||
184 | } | ||
185 | |||
186 | static void setgamma(struct gspca_dev *gspca_dev) | ||
187 | { | ||
188 | struct sd *sd = (struct sd *) gspca_dev; | ||
189 | |||
190 | gspca_dev->usb_buf[0] = 0x06; | ||
191 | gspca_dev->usb_buf[1] = sd->ctrls[GAMMA].val * 0x40; | ||
192 | reg_w(gspca_dev, 2); | ||
193 | } | ||
194 | |||
195 | static void setsharpness(struct gspca_dev *gspca_dev) | ||
196 | { | ||
197 | struct sd *sd = (struct sd *) gspca_dev; | ||
198 | |||
199 | gspca_dev->usb_buf[0] = 0x67; | ||
200 | gspca_dev->usb_buf[1] = sd->ctrls[SHARPNESS].val * 4 + 3; | ||
201 | reg_w(gspca_dev, 2); | ||
202 | } | ||
203 | |||
170 | /* this function is called at probe time */ | 204 | /* this function is called at probe time */ |
171 | static int sd_config(struct gspca_dev *gspca_dev, | 205 | static int sd_config(struct gspca_dev *gspca_dev, |
172 | const struct usb_device_id *id) | 206 | const struct usb_device_id *id) |
@@ -177,10 +211,7 @@ static int sd_config(struct gspca_dev *gspca_dev, | |||
177 | cam = &gspca_dev->cam; | 211 | cam = &gspca_dev->cam; |
178 | cam->cam_mode = vga_mode; | 212 | cam->cam_mode = vga_mode; |
179 | cam->nmodes = ARRAY_SIZE(vga_mode); | 213 | cam->nmodes = ARRAY_SIZE(vga_mode); |
180 | sd->brightness = BRIGHTNESS_DEF; | 214 | cam->ctrls = sd->ctrls; |
181 | sd->colors = COLOR_DEF; | ||
182 | sd->gamma = GAMMA_DEF; | ||
183 | sd->sharpness = SHARPNESS_DEF; | ||
184 | sd->quality = QUALITY_DEF; | 215 | sd->quality = QUALITY_DEF; |
185 | gspca_dev->nbalt = 9; /* use the altsetting 08 */ | 216 | gspca_dev->nbalt = 9; /* use the altsetting 08 */ |
186 | return 0; | 217 | return 0; |
@@ -223,7 +254,7 @@ static int sd_start(struct gspca_dev *gspca_dev) | |||
223 | data[5] = 0x30; /* reg 4, MI, PAS5101 : | 254 | data[5] = 0x30; /* reg 4, MI, PAS5101 : |
224 | * 0x30 for 24mhz , 0x28 for 12mhz */ | 255 | * 0x30 for 24mhz , 0x28 for 12mhz */ |
225 | data[6] = 0x02; /* reg 5, H start - was 0x04 */ | 256 | data[6] = 0x02; /* reg 5, H start - was 0x04 */ |
226 | data[7] = sd->gamma * 0x40; /* reg 0x06: gamma */ | 257 | data[7] = sd->ctrls[GAMMA].val * 0x40; /* reg 0x06: gamma */ |
227 | data[8] = 0x01; /* reg 7, V start - was 0x03 */ | 258 | data[8] = 0x01; /* reg 7, V start - was 0x03 */ |
228 | /* if (h_size == 320 ) */ | 259 | /* if (h_size == 320 ) */ |
229 | /* data[9]= 0x56; * reg 8, 24MHz, 2:1 scale down */ | 260 | /* data[9]= 0x56; * reg 8, 24MHz, 2:1 scale down */ |
@@ -261,9 +292,9 @@ static int sd_start(struct gspca_dev *gspca_dev) | |||
261 | /* reg 0x5f/0x60 (LE) = saturation */ | 292 | /* reg 0x5f/0x60 (LE) = saturation */ |
262 | /* h (60): xxxx x100 | 293 | /* h (60): xxxx x100 |
263 | * l (5f): xxxx x000 */ | 294 | * l (5f): xxxx x000 */ |
264 | data[2] = sd->colors << 3; | 295 | data[2] = sd->ctrls[COLORS].val << 3; |
265 | data[3] = ((sd->colors >> 2) & 0xf8) | 0x04; | 296 | data[3] = ((sd->ctrls[COLORS].val >> 2) & 0xf8) | 0x04; |
266 | data[4] = sd->brightness; /* reg 0x61 = brightness */ | 297 | data[4] = sd->ctrls[BRIGHTNESS].val; /* reg 0x61 = brightness */ |
267 | data[5] = 0x00; | 298 | data[5] = 0x00; |
268 | 299 | ||
269 | err_code = reg_w(gspca_dev, 6); | 300 | err_code = reg_w(gspca_dev, 6); |
@@ -272,7 +303,7 @@ static int sd_start(struct gspca_dev *gspca_dev) | |||
272 | 303 | ||
273 | data[0] = 0x67; | 304 | data[0] = 0x67; |
274 | /*jfm: from win trace*/ | 305 | /*jfm: from win trace*/ |
275 | data[1] = sd->sharpness * 4 + 3; | 306 | data[1] = sd->ctrls[SHARPNESS].val * 4 + 3; |
276 | data[2] = 0x14; | 307 | data[2] = 0x14; |
277 | err_code = reg_w(gspca_dev, 3); | 308 | err_code = reg_w(gspca_dev, 3); |
278 | if (err_code < 0) | 309 | if (err_code < 0) |
@@ -352,93 +383,6 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev, | |||
352 | gspca_frame_add(gspca_dev, INTER_PACKET, data, len); | 383 | gspca_frame_add(gspca_dev, INTER_PACKET, data, len); |
353 | } | 384 | } |
354 | 385 | ||
355 | static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) | ||
356 | { | ||
357 | struct sd *sd = (struct sd *) gspca_dev; | ||
358 | |||
359 | sd->brightness = val; | ||
360 | if (gspca_dev->streaming) { | ||
361 | gspca_dev->usb_buf[0] = 0x61; | ||
362 | gspca_dev->usb_buf[1] = val; | ||
363 | reg_w(gspca_dev, 2); | ||
364 | } | ||
365 | return 0; | ||
366 | } | ||
367 | |||
368 | static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val) | ||
369 | { | ||
370 | struct sd *sd = (struct sd *) gspca_dev; | ||
371 | |||
372 | *val = sd->brightness; | ||
373 | return 0; | ||
374 | } | ||
375 | |||
376 | static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val) | ||
377 | { | ||
378 | struct sd *sd = (struct sd *) gspca_dev; | ||
379 | |||
380 | sd->colors = val; | ||
381 | if (gspca_dev->streaming) { | ||
382 | |||
383 | /* see sd_start */ | ||
384 | gspca_dev->usb_buf[0] = 0x5f; | ||
385 | gspca_dev->usb_buf[1] = sd->colors << 3; | ||
386 | gspca_dev->usb_buf[2] = ((sd->colors >> 2) & 0xf8) | 0x04; | ||
387 | reg_w(gspca_dev, 3); | ||
388 | } | ||
389 | return 0; | ||
390 | } | ||
391 | |||
392 | static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val) | ||
393 | { | ||
394 | struct sd *sd = (struct sd *) gspca_dev; | ||
395 | |||
396 | *val = sd->colors; | ||
397 | return 0; | ||
398 | } | ||
399 | |||
400 | static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val) | ||
401 | { | ||
402 | struct sd *sd = (struct sd *) gspca_dev; | ||
403 | |||
404 | sd->gamma = val; | ||
405 | if (gspca_dev->streaming) { | ||
406 | gspca_dev->usb_buf[0] = 0x06; | ||
407 | gspca_dev->usb_buf[1] = val * 0x40; | ||
408 | reg_w(gspca_dev, 2); | ||
409 | } | ||
410 | return 0; | ||
411 | } | ||
412 | |||
413 | static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val) | ||
414 | { | ||
415 | struct sd *sd = (struct sd *) gspca_dev; | ||
416 | |||
417 | *val = sd->gamma; | ||
418 | return 0; | ||
419 | } | ||
420 | |||
421 | static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val) | ||
422 | { | ||
423 | struct sd *sd = (struct sd *) gspca_dev; | ||
424 | |||
425 | sd->sharpness = val; | ||
426 | if (gspca_dev->streaming) { | ||
427 | gspca_dev->usb_buf[0] = 0x67; | ||
428 | gspca_dev->usb_buf[1] = val * 4 + 3; | ||
429 | reg_w(gspca_dev, 2); | ||
430 | } | ||
431 | return 0; | ||
432 | } | ||
433 | |||
434 | static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val) | ||
435 | { | ||
436 | struct sd *sd = (struct sd *) gspca_dev; | ||
437 | |||
438 | *val = sd->sharpness; | ||
439 | return 0; | ||
440 | } | ||
441 | |||
442 | static int sd_set_jcomp(struct gspca_dev *gspca_dev, | 386 | static int sd_set_jcomp(struct gspca_dev *gspca_dev, |
443 | struct v4l2_jpegcompression *jcomp) | 387 | struct v4l2_jpegcompression *jcomp) |
444 | { | 388 | { |
@@ -471,7 +415,7 @@ static int sd_get_jcomp(struct gspca_dev *gspca_dev, | |||
471 | static const struct sd_desc sd_desc = { | 415 | static const struct sd_desc sd_desc = { |
472 | .name = MODULE_NAME, | 416 | .name = MODULE_NAME, |
473 | .ctrls = sd_ctrls, | 417 | .ctrls = sd_ctrls, |
474 | .nctrls = ARRAY_SIZE(sd_ctrls), | 418 | .nctrls = NCTRLS, |
475 | .config = sd_config, | 419 | .config = sd_config, |
476 | .init = sd_init, | 420 | .init = sd_init, |
477 | .start = sd_start, | 421 | .start = sd_start, |