Linux 4.19.133
[linux/fpc-iii.git] / drivers / media / usb / gspca / se401.c
blob40b87717bb5c5ab76e13970aead7d04b2520d361
1 /*
2 * GSPCA Endpoints (formerly known as AOX) se401 USB Camera sub Driver
4 * Copyright (C) 2011 Hans de Goede <hdegoede@redhat.com>
6 * Based on the v4l1 se401 driver which is:
8 * Copyright (c) 2000 Jeroen B. Vreeken (pe1rxq@amsat.org)
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
22 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24 #define MODULE_NAME "se401"
26 #define BULK_SIZE 4096
27 #define PACKET_SIZE 1024
28 #define READ_REQ_SIZE 64
29 #define MAX_MODES ((READ_REQ_SIZE - 6) / 4)
30 /* The se401 compression algorithm uses a fixed quant factor, which
31 can be configured by setting the high nibble of the SE401_OPERATINGMODE
32 feature. This needs to exactly match what is in libv4l! */
33 #define SE401_QUANT_FACT 8
35 #include <linux/input.h>
36 #include <linux/slab.h>
37 #include "gspca.h"
38 #include "se401.h"
40 MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
41 MODULE_DESCRIPTION("Endpoints se401");
42 MODULE_LICENSE("GPL");
44 /* exposure change state machine states */
45 enum {
46 EXPO_CHANGED,
47 EXPO_DROP_FRAME,
48 EXPO_NO_CHANGE,
51 /* specific webcam descriptor */
52 struct sd {
53 struct gspca_dev gspca_dev; /* !! must be the first item */
54 struct { /* exposure/freq control cluster */
55 struct v4l2_ctrl *exposure;
56 struct v4l2_ctrl *freq;
58 bool has_brightness;
59 struct v4l2_pix_format fmts[MAX_MODES];
60 int pixels_read;
61 int packet_read;
62 u8 packet[PACKET_SIZE];
63 u8 restart_stream;
64 u8 button_state;
65 u8 resetlevel;
66 u8 resetlevel_frame_count;
67 int resetlevel_adjust_dir;
68 int expo_change_state;
72 static void se401_write_req(struct gspca_dev *gspca_dev, u16 req, u16 value,
73 int silent)
75 int err;
77 if (gspca_dev->usb_err < 0)
78 return;
80 err = usb_control_msg(gspca_dev->dev,
81 usb_sndctrlpipe(gspca_dev->dev, 0), req,
82 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
83 value, 0, NULL, 0, 1000);
84 if (err < 0) {
85 if (!silent)
86 pr_err("write req failed req %#04x val %#04x error %d\n",
87 req, value, err);
88 gspca_dev->usb_err = err;
92 static void se401_read_req(struct gspca_dev *gspca_dev, u16 req, int silent)
94 int err;
96 if (gspca_dev->usb_err < 0)
97 return;
99 if (USB_BUF_SZ < READ_REQ_SIZE) {
100 pr_err("USB_BUF_SZ too small!!\n");
101 gspca_dev->usb_err = -ENOBUFS;
102 return;
105 err = usb_control_msg(gspca_dev->dev,
106 usb_rcvctrlpipe(gspca_dev->dev, 0), req,
107 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
108 0, 0, gspca_dev->usb_buf, READ_REQ_SIZE, 1000);
109 if (err < 0) {
110 if (!silent)
111 pr_err("read req failed req %#04x error %d\n",
112 req, err);
113 gspca_dev->usb_err = err;
115 * Make sure the buffer is zeroed to avoid uninitialized
116 * values.
118 memset(gspca_dev->usb_buf, 0, READ_REQ_SIZE);
122 static void se401_set_feature(struct gspca_dev *gspca_dev,
123 u16 selector, u16 param)
125 int err;
127 if (gspca_dev->usb_err < 0)
128 return;
130 err = usb_control_msg(gspca_dev->dev,
131 usb_sndctrlpipe(gspca_dev->dev, 0),
132 SE401_REQ_SET_EXT_FEATURE,
133 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
134 param, selector, NULL, 0, 1000);
135 if (err < 0) {
136 pr_err("set feature failed sel %#04x param %#04x error %d\n",
137 selector, param, err);
138 gspca_dev->usb_err = err;
142 static int se401_get_feature(struct gspca_dev *gspca_dev, u16 selector)
144 int err;
146 if (gspca_dev->usb_err < 0)
147 return gspca_dev->usb_err;
149 if (USB_BUF_SZ < 2) {
150 pr_err("USB_BUF_SZ too small!!\n");
151 gspca_dev->usb_err = -ENOBUFS;
152 return gspca_dev->usb_err;
155 err = usb_control_msg(gspca_dev->dev,
156 usb_rcvctrlpipe(gspca_dev->dev, 0),
157 SE401_REQ_GET_EXT_FEATURE,
158 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
159 0, selector, gspca_dev->usb_buf, 2, 1000);
160 if (err < 0) {
161 pr_err("get feature failed sel %#04x error %d\n",
162 selector, err);
163 gspca_dev->usb_err = err;
164 return err;
166 return gspca_dev->usb_buf[0] | (gspca_dev->usb_buf[1] << 8);
169 static void setbrightness(struct gspca_dev *gspca_dev, s32 val)
171 /* HDG: this does not seem to do anything on my cam */
172 se401_write_req(gspca_dev, SE401_REQ_SET_BRT, val, 0);
175 static void setgain(struct gspca_dev *gspca_dev, s32 val)
177 u16 gain = 63 - val;
179 /* red color gain */
180 se401_set_feature(gspca_dev, HV7131_REG_ARCG, gain);
181 /* green color gain */
182 se401_set_feature(gspca_dev, HV7131_REG_AGCG, gain);
183 /* blue color gain */
184 se401_set_feature(gspca_dev, HV7131_REG_ABCG, gain);
187 static void setexposure(struct gspca_dev *gspca_dev, s32 val, s32 freq)
189 struct sd *sd = (struct sd *) gspca_dev;
190 int integration = val << 6;
191 u8 expose_h, expose_m, expose_l;
193 /* Do this before the set_feature calls, for proper timing wrt
194 the interrupt driven pkt_scan. Note we may still race but that
195 is not a big issue, the expo change state machine is merely for
196 avoiding underexposed frames getting send out, if one sneaks
197 through so be it */
198 sd->expo_change_state = EXPO_CHANGED;
200 if (freq == V4L2_CID_POWER_LINE_FREQUENCY_50HZ)
201 integration = integration - integration % 106667;
202 if (freq == V4L2_CID_POWER_LINE_FREQUENCY_60HZ)
203 integration = integration - integration % 88889;
205 expose_h = (integration >> 16);
206 expose_m = (integration >> 8);
207 expose_l = integration;
209 /* integration time low */
210 se401_set_feature(gspca_dev, HV7131_REG_TITL, expose_l);
211 /* integration time mid */
212 se401_set_feature(gspca_dev, HV7131_REG_TITM, expose_m);
213 /* integration time high */
214 se401_set_feature(gspca_dev, HV7131_REG_TITU, expose_h);
217 static int sd_config(struct gspca_dev *gspca_dev,
218 const struct usb_device_id *id)
220 struct sd *sd = (struct sd *)gspca_dev;
221 struct cam *cam = &gspca_dev->cam;
222 u8 *cd = gspca_dev->usb_buf;
223 int i, j, n;
224 int widths[MAX_MODES], heights[MAX_MODES];
226 /* Read the camera descriptor */
227 se401_read_req(gspca_dev, SE401_REQ_GET_CAMERA_DESCRIPTOR, 1);
228 if (gspca_dev->usb_err) {
229 /* Sometimes after being idle for a while the se401 won't
230 respond and needs a good kicking */
231 usb_reset_device(gspca_dev->dev);
232 gspca_dev->usb_err = 0;
233 se401_read_req(gspca_dev, SE401_REQ_GET_CAMERA_DESCRIPTOR, 0);
236 /* Some cameras start with their LED on */
237 se401_write_req(gspca_dev, SE401_REQ_LED_CONTROL, 0, 0);
238 if (gspca_dev->usb_err)
239 return gspca_dev->usb_err;
241 if (cd[1] != 0x41) {
242 pr_err("Wrong descriptor type\n");
243 return -ENODEV;
246 if (!(cd[2] & SE401_FORMAT_BAYER)) {
247 pr_err("Bayer format not supported!\n");
248 return -ENODEV;
251 if (cd[3])
252 pr_info("ExtraFeatures: %d\n", cd[3]);
254 n = cd[4] | (cd[5] << 8);
255 if (n > MAX_MODES) {
256 pr_err("Too many frame sizes\n");
257 return -ENODEV;
260 for (i = 0; i < n ; i++) {
261 widths[i] = cd[6 + i * 4 + 0] | (cd[6 + i * 4 + 1] << 8);
262 heights[i] = cd[6 + i * 4 + 2] | (cd[6 + i * 4 + 3] << 8);
265 for (i = 0; i < n ; i++) {
266 sd->fmts[i].width = widths[i];
267 sd->fmts[i].height = heights[i];
268 sd->fmts[i].field = V4L2_FIELD_NONE;
269 sd->fmts[i].colorspace = V4L2_COLORSPACE_SRGB;
270 sd->fmts[i].priv = 1;
272 /* janggu compression only works for 1/4th or 1/16th res */
273 for (j = 0; j < n; j++) {
274 if (widths[j] / 2 == widths[i] &&
275 heights[j] / 2 == heights[i]) {
276 sd->fmts[i].priv = 2;
277 break;
280 /* 1/16th if available too is better then 1/4th, because
281 we then use a larger area of the sensor */
282 for (j = 0; j < n; j++) {
283 if (widths[j] / 4 == widths[i] &&
284 heights[j] / 4 == heights[i]) {
285 sd->fmts[i].priv = 4;
286 break;
290 if (sd->fmts[i].priv == 1) {
291 /* Not a 1/4th or 1/16th res, use bayer */
292 sd->fmts[i].pixelformat = V4L2_PIX_FMT_SBGGR8;
293 sd->fmts[i].bytesperline = widths[i];
294 sd->fmts[i].sizeimage = widths[i] * heights[i];
295 pr_info("Frame size: %dx%d bayer\n",
296 widths[i], heights[i]);
297 } else {
298 /* Found a match use janggu compression */
299 sd->fmts[i].pixelformat = V4L2_PIX_FMT_SE401;
300 sd->fmts[i].bytesperline = 0;
301 sd->fmts[i].sizeimage = widths[i] * heights[i] * 3;
302 pr_info("Frame size: %dx%d 1/%dth janggu\n",
303 widths[i], heights[i],
304 sd->fmts[i].priv * sd->fmts[i].priv);
308 cam->cam_mode = sd->fmts;
309 cam->nmodes = n;
310 cam->bulk = 1;
311 cam->bulk_size = BULK_SIZE;
312 cam->bulk_nurbs = 4;
313 sd->resetlevel = 0x2d; /* Set initial resetlevel */
315 /* See if the camera supports brightness */
316 se401_read_req(gspca_dev, SE401_REQ_GET_BRT, 1);
317 sd->has_brightness = !!gspca_dev->usb_err;
318 gspca_dev->usb_err = 0;
320 return 0;
323 /* this function is called at probe and resume time */
324 static int sd_init(struct gspca_dev *gspca_dev)
326 return 0;
329 /* function called at start time before URB creation */
330 static int sd_isoc_init(struct gspca_dev *gspca_dev)
332 gspca_dev->alt = 1; /* Ignore the bogus isoc alt settings */
334 return gspca_dev->usb_err;
337 /* -- start the camera -- */
338 static int sd_start(struct gspca_dev *gspca_dev)
340 struct sd *sd = (struct sd *)gspca_dev;
341 int mult = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
342 int mode = 0;
344 se401_write_req(gspca_dev, SE401_REQ_CAMERA_POWER, 1, 1);
345 if (gspca_dev->usb_err) {
346 /* Sometimes after being idle for a while the se401 won't
347 respond and needs a good kicking */
348 usb_reset_device(gspca_dev->dev);
349 gspca_dev->usb_err = 0;
350 se401_write_req(gspca_dev, SE401_REQ_CAMERA_POWER, 1, 0);
352 se401_write_req(gspca_dev, SE401_REQ_LED_CONTROL, 1, 0);
354 se401_set_feature(gspca_dev, HV7131_REG_MODE_B, 0x05);
356 /* set size + mode */
357 se401_write_req(gspca_dev, SE401_REQ_SET_WIDTH,
358 gspca_dev->pixfmt.width * mult, 0);
359 se401_write_req(gspca_dev, SE401_REQ_SET_HEIGHT,
360 gspca_dev->pixfmt.height * mult, 0);
362 * HDG: disabled this as it does not seem to do anything
363 * se401_write_req(gspca_dev, SE401_REQ_SET_OUTPUT_MODE,
364 * SE401_FORMAT_BAYER, 0);
367 switch (mult) {
368 case 1: /* Raw bayer */
369 mode = 0x03; break;
370 case 2: /* 1/4th janggu */
371 mode = SE401_QUANT_FACT << 4; break;
372 case 4: /* 1/16th janggu */
373 mode = (SE401_QUANT_FACT << 4) | 0x02; break;
375 se401_set_feature(gspca_dev, SE401_OPERATINGMODE, mode);
377 se401_set_feature(gspca_dev, HV7131_REG_ARLV, sd->resetlevel);
379 sd->packet_read = 0;
380 sd->pixels_read = 0;
381 sd->restart_stream = 0;
382 sd->resetlevel_frame_count = 0;
383 sd->resetlevel_adjust_dir = 0;
384 sd->expo_change_state = EXPO_NO_CHANGE;
386 se401_write_req(gspca_dev, SE401_REQ_START_CONTINUOUS_CAPTURE, 0, 0);
388 return gspca_dev->usb_err;
391 static void sd_stopN(struct gspca_dev *gspca_dev)
393 se401_write_req(gspca_dev, SE401_REQ_STOP_CONTINUOUS_CAPTURE, 0, 0);
394 se401_write_req(gspca_dev, SE401_REQ_LED_CONTROL, 0, 0);
395 se401_write_req(gspca_dev, SE401_REQ_CAMERA_POWER, 0, 0);
398 static void sd_dq_callback(struct gspca_dev *gspca_dev)
400 struct sd *sd = (struct sd *)gspca_dev;
401 unsigned int ahrc, alrc;
402 int oldreset, adjust_dir;
404 /* Restart the stream if requested do so by pkt_scan */
405 if (sd->restart_stream) {
406 sd_stopN(gspca_dev);
407 sd_start(gspca_dev);
408 sd->restart_stream = 0;
411 /* Automatically adjust sensor reset level
412 Hyundai have some really nice docs about this and other sensor
413 related stuff on their homepage: www.hei.co.kr */
414 sd->resetlevel_frame_count++;
415 if (sd->resetlevel_frame_count < 20)
416 return;
418 /* For some reason this normally read-only register doesn't get reset
419 to zero after reading them just once... */
420 se401_get_feature(gspca_dev, HV7131_REG_HIREFNOH);
421 se401_get_feature(gspca_dev, HV7131_REG_HIREFNOL);
422 se401_get_feature(gspca_dev, HV7131_REG_LOREFNOH);
423 se401_get_feature(gspca_dev, HV7131_REG_LOREFNOL);
424 ahrc = 256*se401_get_feature(gspca_dev, HV7131_REG_HIREFNOH) +
425 se401_get_feature(gspca_dev, HV7131_REG_HIREFNOL);
426 alrc = 256*se401_get_feature(gspca_dev, HV7131_REG_LOREFNOH) +
427 se401_get_feature(gspca_dev, HV7131_REG_LOREFNOL);
429 /* Not an exact science, but it seems to work pretty well... */
430 oldreset = sd->resetlevel;
431 if (alrc > 10) {
432 while (alrc >= 10 && sd->resetlevel < 63) {
433 sd->resetlevel++;
434 alrc /= 2;
436 } else if (ahrc > 20) {
437 while (ahrc >= 20 && sd->resetlevel > 0) {
438 sd->resetlevel--;
439 ahrc /= 2;
442 /* Detect ping-pong-ing and halve adjustment to avoid overshoot */
443 if (sd->resetlevel > oldreset)
444 adjust_dir = 1;
445 else
446 adjust_dir = -1;
447 if (sd->resetlevel_adjust_dir &&
448 sd->resetlevel_adjust_dir != adjust_dir)
449 sd->resetlevel = oldreset + (sd->resetlevel - oldreset) / 2;
451 if (sd->resetlevel != oldreset) {
452 sd->resetlevel_adjust_dir = adjust_dir;
453 se401_set_feature(gspca_dev, HV7131_REG_ARLV, sd->resetlevel);
456 sd->resetlevel_frame_count = 0;
459 static void sd_complete_frame(struct gspca_dev *gspca_dev, u8 *data, int len)
461 struct sd *sd = (struct sd *)gspca_dev;
463 switch (sd->expo_change_state) {
464 case EXPO_CHANGED:
465 /* The exposure was changed while this frame
466 was being send, so this frame is ok */
467 sd->expo_change_state = EXPO_DROP_FRAME;
468 break;
469 case EXPO_DROP_FRAME:
470 /* The exposure was changed while this frame
471 was being captured, drop it! */
472 gspca_dev->last_packet_type = DISCARD_PACKET;
473 sd->expo_change_state = EXPO_NO_CHANGE;
474 break;
475 case EXPO_NO_CHANGE:
476 break;
478 gspca_frame_add(gspca_dev, LAST_PACKET, data, len);
481 static void sd_pkt_scan_janggu(struct gspca_dev *gspca_dev, u8 *data, int len)
483 struct sd *sd = (struct sd *)gspca_dev;
484 int imagesize = gspca_dev->pixfmt.width * gspca_dev->pixfmt.height;
485 int i, plen, bits, pixels, info, count;
487 if (sd->restart_stream)
488 return;
490 /* Sometimes a 1024 bytes garbage bulk packet is send between frames */
491 if (gspca_dev->last_packet_type == LAST_PACKET && len == 1024) {
492 gspca_dev->last_packet_type = DISCARD_PACKET;
493 return;
496 i = 0;
497 while (i < len) {
498 /* Read header if not already be present from prev bulk pkt */
499 if (sd->packet_read < 4) {
500 count = 4 - sd->packet_read;
501 if (count > len - i)
502 count = len - i;
503 memcpy(&sd->packet[sd->packet_read], &data[i], count);
504 sd->packet_read += count;
505 i += count;
506 if (sd->packet_read < 4)
507 break;
509 bits = sd->packet[3] + (sd->packet[2] << 8);
510 pixels = sd->packet[1] + ((sd->packet[0] & 0x3f) << 8);
511 info = (sd->packet[0] & 0xc0) >> 6;
512 plen = ((bits + 47) >> 4) << 1;
513 /* Sanity checks */
514 if (plen > 1024) {
515 pr_err("invalid packet len %d restarting stream\n",
516 plen);
517 goto error;
519 if (info == 3) {
520 pr_err("unknown frame info value restarting stream\n");
521 goto error;
524 /* Read (remainder of) packet contents */
525 count = plen - sd->packet_read;
526 if (count > len - i)
527 count = len - i;
528 memcpy(&sd->packet[sd->packet_read], &data[i], count);
529 sd->packet_read += count;
530 i += count;
531 if (sd->packet_read < plen)
532 break;
534 sd->pixels_read += pixels;
535 sd->packet_read = 0;
537 switch (info) {
538 case 0: /* Frame data */
539 gspca_frame_add(gspca_dev, INTER_PACKET, sd->packet,
540 plen);
541 break;
542 case 1: /* EOF */
543 if (sd->pixels_read != imagesize) {
544 pr_err("frame size %d expected %d\n",
545 sd->pixels_read, imagesize);
546 goto error;
548 sd_complete_frame(gspca_dev, sd->packet, plen);
549 return; /* Discard the rest of the bulk packet !! */
550 case 2: /* SOF */
551 gspca_frame_add(gspca_dev, FIRST_PACKET, sd->packet,
552 plen);
553 sd->pixels_read = pixels;
554 break;
557 return;
559 error:
560 sd->restart_stream = 1;
561 /* Give userspace a 0 bytes frame, so our dq callback gets
562 called and it can restart the stream */
563 gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0);
564 gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
567 static void sd_pkt_scan_bayer(struct gspca_dev *gspca_dev, u8 *data, int len)
569 struct cam *cam = &gspca_dev->cam;
570 int imagesize = cam->cam_mode[gspca_dev->curr_mode].sizeimage;
572 if (gspca_dev->image_len == 0) {
573 gspca_frame_add(gspca_dev, FIRST_PACKET, data, len);
574 return;
577 if (gspca_dev->image_len + len >= imagesize) {
578 sd_complete_frame(gspca_dev, data, len);
579 return;
582 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
585 static void sd_pkt_scan(struct gspca_dev *gspca_dev, u8 *data, int len)
587 int mult = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
589 if (len == 0)
590 return;
592 if (mult == 1) /* mult == 1 means raw bayer */
593 sd_pkt_scan_bayer(gspca_dev, data, len);
594 else
595 sd_pkt_scan_janggu(gspca_dev, data, len);
598 #if IS_ENABLED(CONFIG_INPUT)
599 static int sd_int_pkt_scan(struct gspca_dev *gspca_dev, u8 *data, int len)
601 struct sd *sd = (struct sd *)gspca_dev;
602 u8 state;
604 if (len != 2)
605 return -EINVAL;
607 switch (data[0]) {
608 case 0:
609 case 1:
610 state = data[0];
611 break;
612 default:
613 return -EINVAL;
615 if (sd->button_state != state) {
616 input_report_key(gspca_dev->input_dev, KEY_CAMERA, state);
617 input_sync(gspca_dev->input_dev);
618 sd->button_state = state;
621 return 0;
623 #endif
625 static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
627 struct gspca_dev *gspca_dev =
628 container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
629 struct sd *sd = (struct sd *)gspca_dev;
631 gspca_dev->usb_err = 0;
633 if (!gspca_dev->streaming)
634 return 0;
636 switch (ctrl->id) {
637 case V4L2_CID_BRIGHTNESS:
638 setbrightness(gspca_dev, ctrl->val);
639 break;
640 case V4L2_CID_GAIN:
641 setgain(gspca_dev, ctrl->val);
642 break;
643 case V4L2_CID_EXPOSURE:
644 setexposure(gspca_dev, ctrl->val, sd->freq->val);
645 break;
647 return gspca_dev->usb_err;
650 static const struct v4l2_ctrl_ops sd_ctrl_ops = {
651 .s_ctrl = sd_s_ctrl,
654 static int sd_init_controls(struct gspca_dev *gspca_dev)
656 struct sd *sd = (struct sd *)gspca_dev;
657 struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
659 gspca_dev->vdev.ctrl_handler = hdl;
660 v4l2_ctrl_handler_init(hdl, 4);
661 if (sd->has_brightness)
662 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
663 V4L2_CID_BRIGHTNESS, 0, 255, 1, 15);
664 /* max is really 63 but > 50 is not pretty */
665 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
666 V4L2_CID_GAIN, 0, 50, 1, 25);
667 sd->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
668 V4L2_CID_EXPOSURE, 0, 32767, 1, 15000);
669 sd->freq = v4l2_ctrl_new_std_menu(hdl, &sd_ctrl_ops,
670 V4L2_CID_POWER_LINE_FREQUENCY,
671 V4L2_CID_POWER_LINE_FREQUENCY_60HZ, 0, 0);
673 if (hdl->error) {
674 pr_err("Could not initialize controls\n");
675 return hdl->error;
677 v4l2_ctrl_cluster(2, &sd->exposure);
678 return 0;
681 /* sub-driver description */
682 static const struct sd_desc sd_desc = {
683 .name = MODULE_NAME,
684 .config = sd_config,
685 .init = sd_init,
686 .init_controls = sd_init_controls,
687 .isoc_init = sd_isoc_init,
688 .start = sd_start,
689 .stopN = sd_stopN,
690 .dq_callback = sd_dq_callback,
691 .pkt_scan = sd_pkt_scan,
692 #if IS_ENABLED(CONFIG_INPUT)
693 .int_pkt_scan = sd_int_pkt_scan,
694 #endif
697 /* -- module initialisation -- */
698 static const struct usb_device_id device_table[] = {
699 {USB_DEVICE(0x03e8, 0x0004)}, /* Endpoints/Aox SE401 */
700 {USB_DEVICE(0x0471, 0x030b)}, /* Philips PCVC665K */
701 {USB_DEVICE(0x047d, 0x5001)}, /* Kensington 67014 */
702 {USB_DEVICE(0x047d, 0x5002)}, /* Kensington 6701(5/7) */
703 {USB_DEVICE(0x047d, 0x5003)}, /* Kensington 67016 */
706 MODULE_DEVICE_TABLE(usb, device_table);
708 /* -- device connect -- */
709 static int sd_probe(struct usb_interface *intf,
710 const struct usb_device_id *id)
712 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
713 THIS_MODULE);
716 static int sd_pre_reset(struct usb_interface *intf)
718 return 0;
721 static int sd_post_reset(struct usb_interface *intf)
723 return 0;
726 static struct usb_driver sd_driver = {
727 .name = MODULE_NAME,
728 .id_table = device_table,
729 .probe = sd_probe,
730 .disconnect = gspca_disconnect,
731 #ifdef CONFIG_PM
732 .suspend = gspca_suspend,
733 .resume = gspca_resume,
734 .reset_resume = gspca_resume,
735 #endif
736 .pre_reset = sd_pre_reset,
737 .post_reset = sd_post_reset,
740 module_usb_driver(sd_driver);