aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-François Moine <moinejf@free.fr>2010-10-02 03:17:38 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2010-10-20 23:18:28 -0400
commit016f2362278b1f235223b12744585676be2a89a7 (patch)
tree3cc9549a7caa966425cbaf3202fbb149ec8926fb
parent6a33091f13d840a2ba020605180a3e591be5c2cd (diff)
[media] gspca - stk014: 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>
-rw-r--r--drivers/media/video/gspca/stk014.c154
1 files changed, 37 insertions, 117 deletions
diff --git a/drivers/media/video/gspca/stk014.c b/drivers/media/video/gspca/stk014.c
index 14601d887c4f..11a192b95ed4 100644
--- a/drivers/media/video/gspca/stk014.c
+++ b/drivers/media/video/gspca/stk014.c
@@ -27,14 +27,21 @@ MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>");
27MODULE_DESCRIPTION("Syntek DV4000 (STK014) USB Camera Driver"); 27MODULE_DESCRIPTION("Syntek DV4000 (STK014) USB Camera Driver");
28MODULE_LICENSE("GPL"); 28MODULE_LICENSE("GPL");
29 29
30/* controls */
31enum e_ctrl {
32 BRIGHTNESS,
33 CONTRAST,
34 COLORS,
35 LIGHTFREQ,
36 NCTRLS /* number of controls */
37};
38
30/* specific webcam descriptor */ 39/* specific webcam descriptor */
31struct sd { 40struct sd {
32 struct gspca_dev gspca_dev; /* !! must be the first item */ 41 struct gspca_dev gspca_dev; /* !! must be the first item */
33 42
34 unsigned char brightness; 43 struct gspca_ctrl ctrls[NCTRLS];
35 unsigned char contrast; 44
36 unsigned char colors;
37 unsigned char lightfreq;
38 u8 quality; 45 u8 quality;
39#define QUALITY_MIN 70 46#define QUALITY_MIN 70
40#define QUALITY_MAX 95 47#define QUALITY_MAX 95
@@ -44,17 +51,13 @@ struct sd {
44}; 51};
45 52
46/* V4L2 controls supported by the driver */ 53/* V4L2 controls supported by the driver */
47static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); 54static void setbrightness(struct gspca_dev *gspca_dev);
48static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); 55static void setcontrast(struct gspca_dev *gspca_dev);
49static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val); 56static void setcolors(struct gspca_dev *gspca_dev);
50static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val); 57static void setlightfreq(struct gspca_dev *gspca_dev);
51static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val); 58
52static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val); 59static const struct ctrl sd_ctrls[NCTRLS] = {
53static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val); 60[BRIGHTNESS] = {
54static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
55
56static const struct ctrl sd_ctrls[] = {
57 {
58 { 61 {
59 .id = V4L2_CID_BRIGHTNESS, 62 .id = V4L2_CID_BRIGHTNESS,
60 .type = V4L2_CTRL_TYPE_INTEGER, 63 .type = V4L2_CTRL_TYPE_INTEGER,
@@ -62,13 +65,11 @@ static const struct ctrl sd_ctrls[] = {
62 .minimum = 0, 65 .minimum = 0,
63 .maximum = 255, 66 .maximum = 255,
64 .step = 1, 67 .step = 1,
65#define BRIGHTNESS_DEF 127 68 .default_value = 127,
66 .default_value = BRIGHTNESS_DEF,
67 }, 69 },
68 .set = sd_setbrightness, 70 .set_control = setbrightness
69 .get = sd_getbrightness,
70 }, 71 },
71 { 72[CONTRAST] = {
72 { 73 {
73 .id = V4L2_CID_CONTRAST, 74 .id = V4L2_CID_CONTRAST,
74 .type = V4L2_CTRL_TYPE_INTEGER, 75 .type = V4L2_CTRL_TYPE_INTEGER,
@@ -76,13 +77,11 @@ static const struct ctrl sd_ctrls[] = {
76 .minimum = 0, 77 .minimum = 0,
77 .maximum = 255, 78 .maximum = 255,
78 .step = 1, 79 .step = 1,
79#define CONTRAST_DEF 127 80 .default_value = 127,
80 .default_value = CONTRAST_DEF,
81 }, 81 },
82 .set = sd_setcontrast, 82 .set_control = setcontrast
83 .get = sd_getcontrast,
84 }, 83 },
85 { 84[COLORS] = {
86 { 85 {
87 .id = V4L2_CID_SATURATION, 86 .id = V4L2_CID_SATURATION,
88 .type = V4L2_CTRL_TYPE_INTEGER, 87 .type = V4L2_CTRL_TYPE_INTEGER,
@@ -90,13 +89,11 @@ static const struct ctrl sd_ctrls[] = {
90 .minimum = 0, 89 .minimum = 0,
91 .maximum = 255, 90 .maximum = 255,
92 .step = 1, 91 .step = 1,
93#define COLOR_DEF 127 92 .default_value = 127,
94 .default_value = COLOR_DEF,
95 }, 93 },
96 .set = sd_setcolors, 94 .set_control = setcolors
97 .get = sd_getcolors,
98 }, 95 },
99 { 96[LIGHTFREQ] = {
100 { 97 {
101 .id = V4L2_CID_POWER_LINE_FREQUENCY, 98 .id = V4L2_CID_POWER_LINE_FREQUENCY,
102 .type = V4L2_CTRL_TYPE_MENU, 99 .type = V4L2_CTRL_TYPE_MENU,
@@ -104,11 +101,9 @@ static const struct ctrl sd_ctrls[] = {
104 .minimum = 1, 101 .minimum = 1,
105 .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */ 102 .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */
106 .step = 1, 103 .step = 1,
107#define FREQ_DEF 1 104 .default_value = 1,
108 .default_value = FREQ_DEF,
109 }, 105 },
110 .set = sd_setfreq, 106 .set_control = setlightfreq
111 .get = sd_getfreq,
112 }, 107 },
113}; 108};
114 109
@@ -264,7 +259,7 @@ static void setbrightness(struct gspca_dev *gspca_dev)
264 int parval; 259 int parval;
265 260
266 parval = 0x06000000 /* whiteness */ 261 parval = 0x06000000 /* whiteness */
267 + (sd->brightness << 16); 262 + (sd->ctrls[BRIGHTNESS].val << 16);
268 set_par(gspca_dev, parval); 263 set_par(gspca_dev, parval);
269} 264}
270 265
@@ -274,7 +269,7 @@ static void setcontrast(struct gspca_dev *gspca_dev)
274 int parval; 269 int parval;
275 270
276 parval = 0x07000000 /* contrast */ 271 parval = 0x07000000 /* contrast */
277 + (sd->contrast << 16); 272 + (sd->ctrls[CONTRAST].val << 16);
278 set_par(gspca_dev, parval); 273 set_par(gspca_dev, parval);
279} 274}
280 275
@@ -284,15 +279,15 @@ static void setcolors(struct gspca_dev *gspca_dev)
284 int parval; 279 int parval;
285 280
286 parval = 0x08000000 /* saturation */ 281 parval = 0x08000000 /* saturation */
287 + (sd->colors << 16); 282 + (sd->ctrls[COLORS].val << 16);
288 set_par(gspca_dev, parval); 283 set_par(gspca_dev, parval);
289} 284}
290 285
291static void setfreq(struct gspca_dev *gspca_dev) 286static void setlightfreq(struct gspca_dev *gspca_dev)
292{ 287{
293 struct sd *sd = (struct sd *) gspca_dev; 288 struct sd *sd = (struct sd *) gspca_dev;
294 289
295 set_par(gspca_dev, sd->lightfreq == 1 290 set_par(gspca_dev, sd->ctrls[LIGHTFREQ].val == 1
296 ? 0x33640000 /* 50 Hz */ 291 ? 0x33640000 /* 50 Hz */
297 : 0x33780000); /* 60 Hz */ 292 : 0x33780000); /* 60 Hz */
298} 293}
@@ -305,10 +300,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
305 300
306 gspca_dev->cam.cam_mode = vga_mode; 301 gspca_dev->cam.cam_mode = vga_mode;
307 gspca_dev->cam.nmodes = ARRAY_SIZE(vga_mode); 302 gspca_dev->cam.nmodes = ARRAY_SIZE(vga_mode);
308 sd->brightness = BRIGHTNESS_DEF; 303 gspca_dev->cam.ctrls = sd->ctrls;
309 sd->contrast = CONTRAST_DEF;
310 sd->colors = COLOR_DEF;
311 sd->lightfreq = FREQ_DEF;
312 sd->quality = QUALITY_DEF; 304 sd->quality = QUALITY_DEF;
313 return 0; 305 return 0;
314} 306}
@@ -378,7 +370,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
378 set_par(gspca_dev, 0x0a800000); /* Green ? */ 370 set_par(gspca_dev, 0x0a800000); /* Green ? */
379 set_par(gspca_dev, 0x0b800000); /* Blue ? */ 371 set_par(gspca_dev, 0x0b800000); /* Blue ? */
380 set_par(gspca_dev, 0x0d030000); /* Gamma ? */ 372 set_par(gspca_dev, 0x0d030000); /* Gamma ? */
381 setfreq(gspca_dev); /* light frequency */ 373 setlightfreq(gspca_dev);
382 374
383 /* start the video flow */ 375 /* start the video flow */
384 set_par(gspca_dev, 0x01000000); 376 set_par(gspca_dev, 0x01000000);
@@ -441,78 +433,6 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
441 gspca_frame_add(gspca_dev, INTER_PACKET, data, len); 433 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
442} 434}
443 435
444static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
445{
446 struct sd *sd = (struct sd *) gspca_dev;
447
448 sd->brightness = val;
449 if (gspca_dev->streaming)
450 setbrightness(gspca_dev);
451 return gspca_dev->usb_err;
452}
453
454static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
455{
456 struct sd *sd = (struct sd *) gspca_dev;
457
458 *val = sd->brightness;
459 return 0;
460}
461
462static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
463{
464 struct sd *sd = (struct sd *) gspca_dev;
465
466 sd->contrast = val;
467 if (gspca_dev->streaming)
468 setcontrast(gspca_dev);
469 return gspca_dev->usb_err;
470}
471
472static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
473{
474 struct sd *sd = (struct sd *) gspca_dev;
475
476 *val = sd->contrast;
477 return 0;
478}
479
480static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
481{
482 struct sd *sd = (struct sd *) gspca_dev;
483
484 sd->colors = val;
485 if (gspca_dev->streaming)
486 setcolors(gspca_dev);
487 return gspca_dev->usb_err;
488}
489
490static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
491{
492 struct sd *sd = (struct sd *) gspca_dev;
493
494 *val = sd->colors;
495 return 0;
496}
497
498static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val)
499{
500 struct sd *sd = (struct sd *) gspca_dev;
501
502 sd->lightfreq = val;
503 if (gspca_dev->streaming)
504 setfreq(gspca_dev);
505 return gspca_dev->usb_err;
506}
507
508static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val)
509{
510 struct sd *sd = (struct sd *) gspca_dev;
511
512 *val = sd->lightfreq;
513 return 0;
514}
515
516static int sd_querymenu(struct gspca_dev *gspca_dev, 436static int sd_querymenu(struct gspca_dev *gspca_dev,
517 struct v4l2_querymenu *menu) 437 struct v4l2_querymenu *menu)
518{ 438{
@@ -563,7 +483,7 @@ static int sd_get_jcomp(struct gspca_dev *gspca_dev,
563static const struct sd_desc sd_desc = { 483static const struct sd_desc sd_desc = {
564 .name = MODULE_NAME, 484 .name = MODULE_NAME,
565 .ctrls = sd_ctrls, 485 .ctrls = sd_ctrls,
566 .nctrls = ARRAY_SIZE(sd_ctrls), 486 .nctrls = NCTRLS,
567 .config = sd_config, 487 .config = sd_config,
568 .init = sd_init, 488 .init = sd_init,
569 .start = sd_start, 489 .start = sd_start,