aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/gspca
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/gspca')
-rw-r--r--drivers/media/video/gspca/spca1528.c268
1 files changed, 61 insertions, 207 deletions
diff --git a/drivers/media/video/gspca/spca1528.c b/drivers/media/video/gspca/spca1528.c
index 070b9c33b517..315a5bf2034c 100644
--- a/drivers/media/video/gspca/spca1528.c
+++ b/drivers/media/video/gspca/spca1528.c
@@ -33,102 +33,11 @@ MODULE_LICENSE("GPL");
33struct sd { 33struct sd {
34 struct gspca_dev gspca_dev; /* !! must be the first item */ 34 struct gspca_dev gspca_dev; /* !! must be the first item */
35 35
36 u8 brightness;
37 u8 contrast;
38 u8 hue;
39 u8 color;
40 u8 sharpness;
41
42 u8 pkt_seq; 36 u8 pkt_seq;
43 37
44 u8 jpeg_hdr[JPEG_HDR_SZ]; 38 u8 jpeg_hdr[JPEG_HDR_SZ];
45}; 39};
46 40
47/* V4L2 controls supported by the driver */
48static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
49static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
50static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
51static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
52static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val);
53static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val);
54static int sd_setcolor(struct gspca_dev *gspca_dev, __s32 val);
55static int sd_getcolor(struct gspca_dev *gspca_dev, __s32 *val);
56static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
57static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
58
59static const struct ctrl sd_ctrls[] = {
60 {
61 {
62 .id = V4L2_CID_BRIGHTNESS,
63 .type = V4L2_CTRL_TYPE_INTEGER,
64 .name = "Brightness",
65 .minimum = 0,
66 .maximum = 255,
67 .step = 1,
68#define BRIGHTNESS_DEF 128
69 .default_value = BRIGHTNESS_DEF,
70 },
71 .set = sd_setbrightness,
72 .get = sd_getbrightness,
73 },
74 {
75 {
76 .id = V4L2_CID_CONTRAST,
77 .type = V4L2_CTRL_TYPE_INTEGER,
78 .name = "Contrast",
79 .minimum = 0,
80 .maximum = 8,
81 .step = 1,
82#define CONTRAST_DEF 1
83 .default_value = CONTRAST_DEF,
84 },
85 .set = sd_setcontrast,
86 .get = sd_getcontrast,
87 },
88 {
89 {
90 .id = V4L2_CID_HUE,
91 .type = V4L2_CTRL_TYPE_INTEGER,
92 .name = "Hue",
93 .minimum = 0,
94 .maximum = 255,
95 .step = 1,
96#define HUE_DEF 0
97 .default_value = HUE_DEF,
98 },
99 .set = sd_sethue,
100 .get = sd_gethue,
101 },
102 {
103 {
104 .id = V4L2_CID_SATURATION,
105 .type = V4L2_CTRL_TYPE_INTEGER,
106 .name = "Saturation",
107 .minimum = 0,
108 .maximum = 8,
109 .step = 1,
110#define COLOR_DEF 1
111 .default_value = COLOR_DEF,
112 },
113 .set = sd_setcolor,
114 .get = sd_getcolor,
115 },
116 {
117 {
118 .id = V4L2_CID_SHARPNESS,
119 .type = V4L2_CTRL_TYPE_INTEGER,
120 .name = "Sharpness",
121 .minimum = 0,
122 .maximum = 255,
123 .step = 1,
124#define SHARPNESS_DEF 0
125 .default_value = SHARPNESS_DEF,
126 },
127 .set = sd_setsharpness,
128 .get = sd_getsharpness,
129 },
130};
131
132static const struct v4l2_pix_format vga_mode[] = { 41static const struct v4l2_pix_format vga_mode[] = {
133/* (does not work correctly) 42/* (does not work correctly)
134 {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, 43 {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
@@ -259,58 +168,40 @@ static void wait_status_1(struct gspca_dev *gspca_dev)
259 gspca_dev->usb_err = -ETIME; 168 gspca_dev->usb_err = -ETIME;
260} 169}
261 170
262static void setbrightness(struct gspca_dev *gspca_dev) 171static void setbrightness(struct gspca_dev *gspca_dev, s32 val)
263{ 172{
264 struct sd *sd = (struct sd *) gspca_dev; 173 reg_wb(gspca_dev, 0xc0, 0x0000, 0x00c0, val);
265
266 reg_wb(gspca_dev, 0xc0, 0x0000, 0x00c0, sd->brightness);
267} 174}
268 175
269static void setcontrast(struct gspca_dev *gspca_dev) 176static void setcontrast(struct gspca_dev *gspca_dev, s32 val)
270{ 177{
271 struct sd *sd = (struct sd *) gspca_dev; 178 reg_wb(gspca_dev, 0xc1, 0x0000, 0x00c1, val);
272
273 reg_wb(gspca_dev, 0xc1, 0x0000, 0x00c1, sd->contrast);
274} 179}
275 180
276static void sethue(struct gspca_dev *gspca_dev) 181static void sethue(struct gspca_dev *gspca_dev, s32 val)
277{ 182{
278 struct sd *sd = (struct sd *) gspca_dev; 183 reg_wb(gspca_dev, 0xc2, 0x0000, 0x0000, val);
279
280 reg_wb(gspca_dev, 0xc2, 0x0000, 0x0000, sd->hue);
281} 184}
282 185
283static void setcolor(struct gspca_dev *gspca_dev) 186static void setcolor(struct gspca_dev *gspca_dev, s32 val)
284{ 187{
285 struct sd *sd = (struct sd *) gspca_dev; 188 reg_wb(gspca_dev, 0xc3, 0x0000, 0x00c3, val);
286
287 reg_wb(gspca_dev, 0xc3, 0x0000, 0x00c3, sd->color);
288} 189}
289 190
290static void setsharpness(struct gspca_dev *gspca_dev) 191static void setsharpness(struct gspca_dev *gspca_dev, s32 val)
291{ 192{
292 struct sd *sd = (struct sd *) gspca_dev; 193 reg_wb(gspca_dev, 0xc4, 0x0000, 0x00c4, val);
293
294 reg_wb(gspca_dev, 0xc4, 0x0000, 0x00c4, sd->sharpness);
295} 194}
296 195
297/* this function is called at probe time */ 196/* this function is called at probe time */
298static int sd_config(struct gspca_dev *gspca_dev, 197static int sd_config(struct gspca_dev *gspca_dev,
299 const struct usb_device_id *id) 198 const struct usb_device_id *id)
300{ 199{
301 struct sd *sd = (struct sd *) gspca_dev;
302
303 gspca_dev->cam.cam_mode = vga_mode; 200 gspca_dev->cam.cam_mode = vga_mode;
304 gspca_dev->cam.nmodes = ARRAY_SIZE(vga_mode); 201 gspca_dev->cam.nmodes = ARRAY_SIZE(vga_mode);
305 gspca_dev->cam.npkt = 128; /* number of packets per ISOC message */ 202 gspca_dev->cam.npkt = 128; /* number of packets per ISOC message */
306 /*fixme: 256 in ms-win traces*/ 203 /*fixme: 256 in ms-win traces*/
307 204
308 sd->brightness = BRIGHTNESS_DEF;
309 sd->contrast = CONTRAST_DEF;
310 sd->hue = HUE_DEF;
311 sd->color = COLOR_DEF;
312 sd->sharpness = SHARPNESS_DEF;
313
314 return 0; 205 return 0;
315} 206}
316 207
@@ -371,11 +262,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
371 jpeg_set_qual(sd->jpeg_hdr, 85); 262 jpeg_set_qual(sd->jpeg_hdr, 85);
372 263
373 /* set the controls */ 264 /* set the controls */
374 setbrightness(gspca_dev); 265 v4l2_ctrl_handler_setup(&gspca_dev->ctrl_handler);
375 setcontrast(gspca_dev);
376 sethue(gspca_dev);
377 setcolor(gspca_dev);
378 setsharpness(gspca_dev);
379 266
380 msleep(5); 267 msleep(5);
381 reg_r(gspca_dev, 0x00, 0x2520, 1); 268 reg_r(gspca_dev, 0x00, 0x2520, 1);
@@ -457,103 +344,70 @@ err:
457 gspca_dev->last_packet_type = DISCARD_PACKET; 344 gspca_dev->last_packet_type = DISCARD_PACKET;
458} 345}
459 346
460static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) 347static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
461{
462 struct sd *sd = (struct sd *) gspca_dev;
463
464 sd->brightness = val;
465 if (gspca_dev->streaming)
466 setbrightness(gspca_dev);
467 return gspca_dev->usb_err;
468}
469
470static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
471{
472 struct sd *sd = (struct sd *) gspca_dev;
473
474 *val = sd->brightness;
475 return 0;
476}
477
478static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
479{
480 struct sd *sd = (struct sd *) gspca_dev;
481
482 sd->contrast = val;
483 if (gspca_dev->streaming)
484 setcontrast(gspca_dev);
485 return gspca_dev->usb_err;
486}
487
488static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
489{
490 struct sd *sd = (struct sd *) gspca_dev;
491
492 *val = sd->contrast;
493 return 0;
494}
495
496static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val)
497{
498 struct sd *sd = (struct sd *) gspca_dev;
499
500 sd->hue = val;
501 if (gspca_dev->streaming)
502 sethue(gspca_dev);
503 return gspca_dev->usb_err;
504}
505
506static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val)
507{ 348{
508 struct sd *sd = (struct sd *) gspca_dev; 349 struct gspca_dev *gspca_dev =
509 350 container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
510 *val = sd->hue; 351
511 return 0; 352 gspca_dev->usb_err = 0;
512} 353
513 354 if (!gspca_dev->streaming)
514static int sd_setcolor(struct gspca_dev *gspca_dev, __s32 val) 355 return 0;
515{ 356
516 struct sd *sd = (struct sd *) gspca_dev; 357 switch (ctrl->id) {
517 358 case V4L2_CID_BRIGHTNESS:
518 sd->color = val; 359 setbrightness(gspca_dev, ctrl->val);
519 if (gspca_dev->streaming) 360 break;
520 setcolor(gspca_dev); 361 case V4L2_CID_CONTRAST:
362 setcontrast(gspca_dev, ctrl->val);
363 break;
364 case V4L2_CID_HUE:
365 sethue(gspca_dev, ctrl->val);
366 break;
367 case V4L2_CID_SATURATION:
368 setcolor(gspca_dev, ctrl->val);
369 break;
370 case V4L2_CID_SHARPNESS:
371 setsharpness(gspca_dev, ctrl->val);
372 break;
373 }
521 return gspca_dev->usb_err; 374 return gspca_dev->usb_err;
522} 375}
523 376
524static int sd_getcolor(struct gspca_dev *gspca_dev, __s32 *val) 377static const struct v4l2_ctrl_ops sd_ctrl_ops = {
525{ 378 .s_ctrl = sd_s_ctrl,
526 struct sd *sd = (struct sd *) gspca_dev; 379};
527
528 *val = sd->color;
529 return 0;
530}
531
532static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
533{
534 struct sd *sd = (struct sd *) gspca_dev;
535
536 sd->sharpness = val;
537 if (gspca_dev->streaming)
538 setsharpness(gspca_dev);
539 return gspca_dev->usb_err;
540}
541 380
542static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val) 381static int sd_init_controls(struct gspca_dev *gspca_dev)
543{ 382{
544 struct sd *sd = (struct sd *) gspca_dev; 383 struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
545 384
546 *val = sd->sharpness; 385 gspca_dev->vdev.ctrl_handler = hdl;
386 v4l2_ctrl_handler_init(hdl, 5);
387 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
388 V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
389 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
390 V4L2_CID_CONTRAST, 0, 8, 1, 1);
391 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
392 V4L2_CID_HUE, 0, 255, 1, 0);
393 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
394 V4L2_CID_SATURATION, 0, 8, 1, 1);
395 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
396 V4L2_CID_SHARPNESS, 0, 255, 1, 0);
397
398 if (hdl->error) {
399 pr_err("Could not initialize controls\n");
400 return hdl->error;
401 }
547 return 0; 402 return 0;
548} 403}
549 404
550/* sub-driver description */ 405/* sub-driver description */
551static const struct sd_desc sd_desc = { 406static const struct sd_desc sd_desc = {
552 .name = MODULE_NAME, 407 .name = MODULE_NAME,
553 .ctrls = sd_ctrls,
554 .nctrls = ARRAY_SIZE(sd_ctrls),
555 .config = sd_config, 408 .config = sd_config,
556 .init = sd_init, 409 .init = sd_init,
410 .init_controls = sd_init_controls,
557 .isoc_init = sd_isoc_init, 411 .isoc_init = sd_isoc_init,
558 .start = sd_start, 412 .start = sd_start,
559 .stopN = sd_stopN, 413 .stopN = sd_stopN,