blob: abc56e37efcbd460a3d2176b4aff7b9eae685225 [file] [log] [blame]
Kyle Guinnd661e622009-01-16 05:36:14 -03001/*
2 * Mars MR97310A library
3 *
Theodore Kilgore930bf782009-10-05 05:11:35 -03004 * The original mr97310a driver, which supported the Aiptek Pencam VGA+, is
Kyle Guinnd661e622009-01-16 05:36:14 -03005 * Copyright (C) 2009 Kyle Guinn <elyk03@gmail.com>
6 *
Theodore Kilgore89f08632009-08-14 06:51:52 -03007 * Support for the MR97310A cameras in addition to the Aiptek Pencam VGA+
8 * and for the routines for detecting and classifying these various cameras,
Theodore Kilgore930bf782009-10-05 05:11:35 -03009 * is Copyright (C) 2009 Theodore Kilgore <kilgota@auburn.edu>
Theodore Kilgore89f08632009-08-14 06:51:52 -030010 *
Theodore Kilgore930bf782009-10-05 05:11:35 -030011 * Support for the control settings for the CIF cameras is
12 * Copyright (C) 2009 Hans de Goede <hdgoede@redhat.com> and
13 * Thomas Kaiser <thomas@kaiser-linux.li>
14 *
15 * Support for the control settings for the VGA cameras is
Theodore Kilgore89f08632009-08-14 06:51:52 -030016 * Copyright (C) 2009 Theodore Kilgore <kilgota@auburn.edu>
17 *
Theodore Kilgore930bf782009-10-05 05:11:35 -030018 * Several previously unsupported cameras are owned and have been tested by
19 * Hans de Goede <hdgoede@redhat.com> and
20 * Thomas Kaiser <thomas@kaiser-linux.li> and
21 * Theodore Kilgore <kilgota@auburn.edu>
Theodore Kilgore89f08632009-08-14 06:51:52 -030022 *
23 * The MR97311A support in gspca/mars.c has been helpful in understanding some
24 * of the registers in these cameras.
25 *
Kyle Guinnd661e622009-01-16 05:36:14 -030026 * This program is free software; you can redistribute it and/or modify
27 * it under the terms of the GNU General Public License as published by
28 * the Free Software Foundation; either version 2 of the License, or
29 * any later version.
30 *
31 * This program is distributed in the hope that it will be useful,
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 * GNU General Public License for more details.
35 *
36 * You should have received a copy of the GNU General Public License
37 * along with this program; if not, write to the Free Software
38 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
39 */
40
41#define MODULE_NAME "mr97310a"
42
43#include "gspca.h"
44
Theodore Kilgore89f08632009-08-14 06:51:52 -030045#define CAM_TYPE_CIF 0
46#define CAM_TYPE_VGA 1
47
Theodore Kilgore89f08632009-08-14 06:51:52 -030048#define MR97310A_BRIGHTNESS_DEFAULT 0
49
Theodore Kilgore930bf782009-10-05 05:11:35 -030050#define MR97310A_EXPOSURE_MIN 0
Theodore Kilgore89f08632009-08-14 06:51:52 -030051#define MR97310A_EXPOSURE_MAX 4095
52#define MR97310A_EXPOSURE_DEFAULT 1000
53
54#define MR97310A_GAIN_MIN 0
55#define MR97310A_GAIN_MAX 31
56#define MR97310A_GAIN_DEFAULT 25
57
58MODULE_AUTHOR("Kyle Guinn <elyk03@gmail.com>,"
59 "Theodore Kilgore <kilgota@auburn.edu>");
Kyle Guinnd661e622009-01-16 05:36:14 -030060MODULE_DESCRIPTION("GSPCA/Mars-Semi MR97310A USB Camera Driver");
61MODULE_LICENSE("GPL");
62
Hans de Goede78028702009-09-02 09:55:16 -030063/* global parameters */
64int force_sensor_type = -1;
65module_param(force_sensor_type, int, 0644);
66MODULE_PARM_DESC(force_sensor_type, "Force sensor type (-1 (auto), 0 or 1)");
67
Kyle Guinnd661e622009-01-16 05:36:14 -030068/* specific webcam descriptor */
69struct sd {
70 struct gspca_dev gspca_dev; /* !! must be the first item */
Kyle Guinnd661e622009-01-16 05:36:14 -030071 u8 sof_read;
Theodore Kilgore89f08632009-08-14 06:51:52 -030072 u8 cam_type; /* 0 is CIF and 1 is VGA */
73 u8 sensor_type; /* We use 0 and 1 here, too. */
74 u8 do_lcd_stop;
Theodore Kilgore89f08632009-08-14 06:51:52 -030075
76 int brightness;
77 u16 exposure;
Theodore Kilgore89f08632009-08-14 06:51:52 -030078 u8 gain;
Kyle Guinnd661e622009-01-16 05:36:14 -030079};
80
Theodore Kilgore89f08632009-08-14 06:51:52 -030081struct sensor_w_data {
82 u8 reg;
83 u8 flags;
84 u8 data[16];
85 int len;
86};
87
Theodore Kilgore930bf782009-10-05 05:11:35 -030088static void sd_stopN(struct gspca_dev *gspca_dev);
Theodore Kilgore89f08632009-08-14 06:51:52 -030089static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
90static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
91static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
92static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);
93static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
94static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
Hans de Goede9ac69782009-08-14 10:15:52 -030095static void setbrightness(struct gspca_dev *gspca_dev);
96static void setexposure(struct gspca_dev *gspca_dev);
97static void setgain(struct gspca_dev *gspca_dev);
Theodore Kilgore89f08632009-08-14 06:51:52 -030098
Kyle Guinnd661e622009-01-16 05:36:14 -030099/* V4L2 controls supported by the driver */
100static struct ctrl sd_ctrls[] = {
Theodore Kilgore930bf782009-10-05 05:11:35 -0300101/* Seprate brightness control description for Argus QuickClix as it has
102 different limits from to other mr97310a camera's */
Theodore Kilgore89f08632009-08-14 06:51:52 -0300103 {
Theodore Kilgore930bf782009-10-05 05:11:35 -0300104#define NORM_BRIGHTNESS_IDX 0
Theodore Kilgore89f08632009-08-14 06:51:52 -0300105 {
106 .id = V4L2_CID_BRIGHTNESS,
107 .type = V4L2_CTRL_TYPE_INTEGER,
108 .name = "Brightness",
Theodore Kilgore930bf782009-10-05 05:11:35 -0300109 .minimum = -254,
110 .maximum = 255,
Theodore Kilgore89f08632009-08-14 06:51:52 -0300111 .step = 1,
112 .default_value = MR97310A_BRIGHTNESS_DEFAULT,
113 .flags = 0,
114 },
115 .set = sd_setbrightness,
116 .get = sd_getbrightness,
117 },
118 {
Theodore Kilgore930bf782009-10-05 05:11:35 -0300119#define ARGUS_QC_BRIGHTNESS_IDX 1
120 {
121 .id = V4L2_CID_BRIGHTNESS,
122 .type = V4L2_CTRL_TYPE_INTEGER,
123 .name = "Brightness",
124 .minimum = 0,
125 .maximum = 15,
126 .step = 1,
127 .default_value = MR97310A_BRIGHTNESS_DEFAULT,
128 .flags = 0,
129 },
130 .set = sd_setbrightness,
131 .get = sd_getbrightness,
132 },
133 {
134#define EXPOSURE_IDX 2
Theodore Kilgore89f08632009-08-14 06:51:52 -0300135 {
136 .id = V4L2_CID_EXPOSURE,
137 .type = V4L2_CTRL_TYPE_INTEGER,
138 .name = "Exposure",
139 .minimum = MR97310A_EXPOSURE_MIN,
140 .maximum = MR97310A_EXPOSURE_MAX,
141 .step = 1,
142 .default_value = MR97310A_EXPOSURE_DEFAULT,
143 .flags = 0,
144 },
145 .set = sd_setexposure,
146 .get = sd_getexposure,
147 },
148 {
Theodore Kilgore930bf782009-10-05 05:11:35 -0300149#define GAIN_IDX 3
Theodore Kilgore89f08632009-08-14 06:51:52 -0300150 {
151 .id = V4L2_CID_GAIN,
152 .type = V4L2_CTRL_TYPE_INTEGER,
153 .name = "Gain",
154 .minimum = MR97310A_GAIN_MIN,
155 .maximum = MR97310A_GAIN_MAX,
156 .step = 1,
157 .default_value = MR97310A_GAIN_DEFAULT,
158 .flags = 0,
159 },
160 .set = sd_setgain,
161 .get = sd_getgain,
162 },
Kyle Guinnd661e622009-01-16 05:36:14 -0300163};
164
165static const struct v4l2_pix_format vga_mode[] = {
166 {160, 120, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE,
167 .bytesperline = 160,
168 .sizeimage = 160 * 120,
169 .colorspace = V4L2_COLORSPACE_SRGB,
170 .priv = 4},
171 {176, 144, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE,
172 .bytesperline = 176,
173 .sizeimage = 176 * 144,
174 .colorspace = V4L2_COLORSPACE_SRGB,
175 .priv = 3},
176 {320, 240, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE,
177 .bytesperline = 320,
178 .sizeimage = 320 * 240,
179 .colorspace = V4L2_COLORSPACE_SRGB,
180 .priv = 2},
181 {352, 288, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE,
182 .bytesperline = 352,
183 .sizeimage = 352 * 288,
184 .colorspace = V4L2_COLORSPACE_SRGB,
185 .priv = 1},
186 {640, 480, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE,
187 .bytesperline = 640,
188 .sizeimage = 640 * 480,
189 .colorspace = V4L2_COLORSPACE_SRGB,
190 .priv = 0},
191};
192
193/* the bytes to write are in gspca_dev->usb_buf */
Theodore Kilgore89f08632009-08-14 06:51:52 -0300194static int mr_write(struct gspca_dev *gspca_dev, int len)
Kyle Guinnd661e622009-01-16 05:36:14 -0300195{
196 int rc;
197
198 rc = usb_bulk_msg(gspca_dev->dev,
199 usb_sndbulkpipe(gspca_dev->dev, 4),
Jean-Francois Moine92e8c912009-02-02 16:25:38 -0300200 gspca_dev->usb_buf, len, NULL, 500);
Kyle Guinnd661e622009-01-16 05:36:14 -0300201 if (rc < 0)
202 PDEBUG(D_ERR, "reg write [%02x] error %d",
203 gspca_dev->usb_buf[0], rc);
204 return rc;
205}
206
Theodore Kilgore89f08632009-08-14 06:51:52 -0300207/* the bytes are read into gspca_dev->usb_buf */
208static int mr_read(struct gspca_dev *gspca_dev, int len)
209{
210 int rc;
211
212 rc = usb_bulk_msg(gspca_dev->dev,
213 usb_rcvbulkpipe(gspca_dev->dev, 3),
214 gspca_dev->usb_buf, len, NULL, 500);
215 if (rc < 0)
216 PDEBUG(D_ERR, "reg read [%02x] error %d",
217 gspca_dev->usb_buf[0], rc);
218 return rc;
219}
220
221static int sensor_write_reg(struct gspca_dev *gspca_dev, u8 reg, u8 flags,
222 const u8 *data, int len)
223{
224 gspca_dev->usb_buf[0] = 0x1f;
225 gspca_dev->usb_buf[1] = flags;
226 gspca_dev->usb_buf[2] = reg;
227 memcpy(gspca_dev->usb_buf + 3, data, len);
228
229 return mr_write(gspca_dev, len + 3);
230}
231
232static int sensor_write_regs(struct gspca_dev *gspca_dev,
233 const struct sensor_w_data *data, int len)
234{
235 int i, rc;
236
237 for (i = 0; i < len; i++) {
238 rc = sensor_write_reg(gspca_dev, data[i].reg, data[i].flags,
239 data[i].data, data[i].len);
240 if (rc < 0)
241 return rc;
242 }
243
244 return 0;
245}
246
247static int sensor_write1(struct gspca_dev *gspca_dev, u8 reg, u8 data)
248{
Hans de Goedea2e081b2009-08-14 17:11:36 -0300249 struct sd *sd = (struct sd *) gspca_dev;
250 u8 buf, confirm_reg;
Theodore Kilgore89f08632009-08-14 06:51:52 -0300251 int rc;
252
253 buf = data;
Theodore Kilgore930bf782009-10-05 05:11:35 -0300254 if (sd->cam_type == CAM_TYPE_CIF) {
255 rc = sensor_write_reg(gspca_dev, reg, 0x01, &buf, 1);
256 confirm_reg = sd->sensor_type ? 0x13 : 0x11;
257 } else {
258 rc = sensor_write_reg(gspca_dev, reg, 0x00, &buf, 1);
259 confirm_reg = 0x11;
260 }
Theodore Kilgore89f08632009-08-14 06:51:52 -0300261 if (rc < 0)
262 return rc;
263
264 buf = 0x01;
Hans de Goedea2e081b2009-08-14 17:11:36 -0300265 rc = sensor_write_reg(gspca_dev, confirm_reg, 0x00, &buf, 1);
Theodore Kilgore89f08632009-08-14 06:51:52 -0300266 if (rc < 0)
267 return rc;
268
269 return 0;
270}
271
Theodore Kilgore930bf782009-10-05 05:11:35 -0300272static int cam_get_response16(struct gspca_dev *gspca_dev, u8 reg, int verbose)
Theodore Kilgore89f08632009-08-14 06:51:52 -0300273{
Theodore Kilgore89f08632009-08-14 06:51:52 -0300274 int err_code;
275
Theodore Kilgore930bf782009-10-05 05:11:35 -0300276 gspca_dev->usb_buf[0] = reg;
Theodore Kilgore89f08632009-08-14 06:51:52 -0300277 err_code = mr_write(gspca_dev, 1);
278 if (err_code < 0)
279 return err_code;
280
281 err_code = mr_read(gspca_dev, 16);
Theodore Kilgore930bf782009-10-05 05:11:35 -0300282 if (err_code < 0)
283 return err_code;
284
285 if (verbose)
286 PDEBUG(D_PROBE, "Register: %02x reads %02x%02x%02x", reg,
287 gspca_dev->usb_buf[0],
288 gspca_dev->usb_buf[1],
289 gspca_dev->usb_buf[2]);
290
291 return 0;
Theodore Kilgore89f08632009-08-14 06:51:52 -0300292}
293
294static int zero_the_pointer(struct gspca_dev *gspca_dev)
295{
296 __u8 *data = gspca_dev->usb_buf;
297 int err_code;
298 u8 status = 0;
299 int tries = 0;
300
Theodore Kilgore930bf782009-10-05 05:11:35 -0300301 err_code = cam_get_response16(gspca_dev, 0x21, 0);
Theodore Kilgore89f08632009-08-14 06:51:52 -0300302 if (err_code < 0)
303 return err_code;
304
305 err_code = mr_write(gspca_dev, 1);
306 data[0] = 0x19;
307 data[1] = 0x51;
308 err_code = mr_write(gspca_dev, 2);
309 if (err_code < 0)
310 return err_code;
311
Theodore Kilgore930bf782009-10-05 05:11:35 -0300312 err_code = cam_get_response16(gspca_dev, 0x21, 0);
Theodore Kilgore89f08632009-08-14 06:51:52 -0300313 if (err_code < 0)
314 return err_code;
315
316 data[0] = 0x19;
317 data[1] = 0xba;
318 err_code = mr_write(gspca_dev, 2);
319 if (err_code < 0)
320 return err_code;
321
Theodore Kilgore930bf782009-10-05 05:11:35 -0300322 err_code = cam_get_response16(gspca_dev, 0x21, 0);
Theodore Kilgore89f08632009-08-14 06:51:52 -0300323 if (err_code < 0)
324 return err_code;
325
326 data[0] = 0x19;
327 data[1] = 0x00;
328 err_code = mr_write(gspca_dev, 2);
329 if (err_code < 0)
330 return err_code;
331
Theodore Kilgore930bf782009-10-05 05:11:35 -0300332 err_code = cam_get_response16(gspca_dev, 0x21, 0);
Theodore Kilgore89f08632009-08-14 06:51:52 -0300333 if (err_code < 0)
334 return err_code;
335
336 data[0] = 0x19;
337 data[1] = 0x00;
338 err_code = mr_write(gspca_dev, 2);
339 if (err_code < 0)
340 return err_code;
341
342 while (status != 0x0a && tries < 256) {
Theodore Kilgore930bf782009-10-05 05:11:35 -0300343 err_code = cam_get_response16(gspca_dev, 0x21, 0);
Theodore Kilgore89f08632009-08-14 06:51:52 -0300344 status = data[0];
345 tries++;
346 if (err_code < 0)
347 return err_code;
348 }
Hans de Goede54943782009-08-14 11:05:38 -0300349 if (status != 0x0a)
350 PDEBUG(D_ERR, "status is %02x", status);
Theodore Kilgore89f08632009-08-14 06:51:52 -0300351
352 tries = 0;
353 while (tries < 4) {
354 data[0] = 0x19;
355 data[1] = 0x00;
356 err_code = mr_write(gspca_dev, 2);
357 if (err_code < 0)
358 return err_code;
359
Theodore Kilgore930bf782009-10-05 05:11:35 -0300360 err_code = cam_get_response16(gspca_dev, 0x21, 0);
Theodore Kilgore89f08632009-08-14 06:51:52 -0300361 status = data[0];
362 tries++;
363 if (err_code < 0)
364 return err_code;
365 }
Theodore Kilgore89f08632009-08-14 06:51:52 -0300366
367 data[0] = 0x19;
368 err_code = mr_write(gspca_dev, 1);
369 if (err_code < 0)
370 return err_code;
371
372 err_code = mr_read(gspca_dev, 16);
373 if (err_code < 0)
374 return err_code;
375
376 return 0;
377}
378
Theodore Kilgore930bf782009-10-05 05:11:35 -0300379static int stream_start(struct gspca_dev *gspca_dev)
Theodore Kilgore89f08632009-08-14 06:51:52 -0300380{
Theodore Kilgore930bf782009-10-05 05:11:35 -0300381 gspca_dev->usb_buf[0] = 0x01;
382 gspca_dev->usb_buf[1] = 0x01;
383 return mr_write(gspca_dev, 2);
384}
Theodore Kilgore89f08632009-08-14 06:51:52 -0300385
Theodore Kilgore930bf782009-10-05 05:11:35 -0300386static void stream_stop(struct gspca_dev *gspca_dev)
387{
388 gspca_dev->usb_buf[0] = 0x01;
389 gspca_dev->usb_buf[1] = 0x00;
390 if (mr_write(gspca_dev, 2) < 0)
391 PDEBUG(D_ERR, "Stream Stop failed");
392}
Theodore Kilgore89f08632009-08-14 06:51:52 -0300393
Theodore Kilgore930bf782009-10-05 05:11:35 -0300394static void lcd_stop(struct gspca_dev *gspca_dev)
395{
396 gspca_dev->usb_buf[0] = 0x19;
397 gspca_dev->usb_buf[1] = 0x54;
398 if (mr_write(gspca_dev, 2) < 0)
399 PDEBUG(D_ERR, "LCD Stop failed");
400}
Theodore Kilgore89f08632009-08-14 06:51:52 -0300401
Theodore Kilgore930bf782009-10-05 05:11:35 -0300402static int isoc_enable(struct gspca_dev *gspca_dev)
403{
404 gspca_dev->usb_buf[0] = 0x00;
405 gspca_dev->usb_buf[1] = 0x4d; /* ISOC transfering enable... */
406 return mr_write(gspca_dev, 2);
Theodore Kilgore89f08632009-08-14 06:51:52 -0300407}
408
Kyle Guinnd661e622009-01-16 05:36:14 -0300409/* this function is called at probe time */
410static int sd_config(struct gspca_dev *gspca_dev,
411 const struct usb_device_id *id)
412{
Theodore Kilgore89f08632009-08-14 06:51:52 -0300413 struct sd *sd = (struct sd *) gspca_dev;
Kyle Guinnd661e622009-01-16 05:36:14 -0300414 struct cam *cam;
Hans de Goede5f5e26b2009-08-14 10:40:26 -0300415 int err_code;
Kyle Guinnd661e622009-01-16 05:36:14 -0300416
417 cam = &gspca_dev->cam;
418 cam->cam_mode = vga_mode;
419 cam->nmodes = ARRAY_SIZE(vga_mode);
Theodore Kilgore930bf782009-10-05 05:11:35 -0300420 sd->do_lcd_stop = 0;
421
422 /* Now, logical layout of the driver must fall sacrifice to the
423 * realities of the hardware supported. We have to sort out several
424 * cameras which share the USB ID but are in fact different inside.
425 * We need to start the initialization process for the cameras in
426 * order to classify them. Some of the supported cameras require the
427 * memory pointer to be set to 0 as the very first item of business
428 * or else they will not stream. So we do that immediately.
429 */
430 err_code = zero_the_pointer(gspca_dev);
431 if (err_code < 0)
432 return err_code;
Hans de Goede9ac69782009-08-14 10:15:52 -0300433
Theodore Kilgoreb3e440e2009-10-09 03:54:49 -0300434 err_code = stream_start(gspca_dev);
435 if (err_code < 0)
436 return err_code;
437
Theodore Kilgore89f08632009-08-14 06:51:52 -0300438 if (id->idProduct == 0x010e) {
Theodore Kilgore89f08632009-08-14 06:51:52 -0300439 sd->cam_type = CAM_TYPE_CIF;
Hans de Goede9ac69782009-08-14 10:15:52 -0300440 cam->nmodes--;
Theodore Kilgore930bf782009-10-05 05:11:35 -0300441 err_code = cam_get_response16(gspca_dev, 0x06, 1);
442 if (err_code < 0)
443 return err_code;
444 /*
445 * The various CIF cameras share the same USB ID but use
446 * different init routines and different controls. We need to
447 * detect which one is connected!
448 *
449 * A list of known CIF cameras follows. They all report either
450 * 0002 for type 0 or 0003 for type 1.
451 * If you have another to report, please do
452 *
453 * Name sd->sensor_type reported by
454 *
455 * Sakar Spy-shot 0 T. Kilgore
456 * Innovage 0 T. Kilgore
457 * Vivitar Mini 0 H. De Goede
458 * Vivitar Mini 0 E. Rodriguez
459 * Vivitar Mini 1 T. Kilgore
460 * Elta-Media 8212dc 1 T. Kaiser
461 * Philips dig. keych. 1 T. Kilgore
462 */
463 switch (gspca_dev->usb_buf[1]) {
464 case 2:
465 sd->sensor_type = 0;
466 break;
467 case 3:
468 sd->sensor_type = 1;
469 break;
470 default:
471 PDEBUG(D_ERR, "Unknown CIF Sensor id : %02x",
472 gspca_dev->usb_buf[1]);
473 return -ENODEV;
474 }
475 PDEBUG(D_PROBE, "MR97310A CIF camera detected, sensor: %d",
476 sd->sensor_type);
477 } else {
478 sd->cam_type = CAM_TYPE_VGA;
Hans de Goede5f5e26b2009-08-14 10:40:26 -0300479
Theodore Kilgoreb3e440e2009-10-09 03:54:49 -0300480 err_code = cam_get_response16(gspca_dev, 0x07, 1);
Hans de Goede5f5e26b2009-08-14 10:40:26 -0300481 if (err_code < 0)
482 return err_code;
483
Hans de Goede5f5e26b2009-08-14 10:40:26 -0300484 /*
Theodore Kilgoreb3e440e2009-10-09 03:54:49 -0300485 * Here is a table of the responses to the previous command
486 * from the known MR97310A VGA cameras.
Theodore Kilgore930bf782009-10-05 05:11:35 -0300487 *
488 * Name gspca_dev->usb_buf[] sd->sensor_type
Theodore Kilgoreb3e440e2009-10-09 03:54:49 -0300489 * sd->do_lcd_stop
490 * Aiptek Pencam VGA+ 0300 0 1
491 * ION digital 0350 0 1
492 * Argus DC-1620 0450 1 0
493 * Argus QuickClix 0420 1 1
Theodore Kilgore930bf782009-10-05 05:11:35 -0300494 *
Theodore Kilgoreb3e440e2009-10-09 03:54:49 -0300495 * Based upon these results, we assume default settings
496 * and then correct as necessary, as follows.
Theodore Kilgore930bf782009-10-05 05:11:35 -0300497 *
Hans de Goede5f5e26b2009-08-14 10:40:26 -0300498 */
Hans de Goede5f5e26b2009-08-14 10:40:26 -0300499
Theodore Kilgoreb3e440e2009-10-09 03:54:49 -0300500 sd->sensor_type = 1;
501 sd->do_lcd_stop = 0;
502 if ((gspca_dev->usb_buf[0] != 0x03) &&
503 (gspca_dev->usb_buf[0] != 0x04)) {
504 PDEBUG(D_ERR, "Unknown VGA Sensor id Byte 0: %02x",
505 gspca_dev->usb_buf[1]);
506 PDEBUG(D_ERR, "Defaults assumed, may not work");
507 PDEBUG(D_ERR, "Please report this");
508 }
509 if (gspca_dev->usb_buf[0] == 0x04) {
510 sd->do_lcd_stop = 1;
Theodore Kilgore930bf782009-10-05 05:11:35 -0300511 switch (gspca_dev->usb_buf[1]) {
512 case 0x50:
Theodore Kilgoreb3e440e2009-10-09 03:54:49 -0300513 sd->sensor_type = 0;
514 PDEBUG(D_PROBE, "sensor_type corrected to 0");
Theodore Kilgore930bf782009-10-05 05:11:35 -0300515 break;
516 case 0x20:
Theodore Kilgoreb3e440e2009-10-09 03:54:49 -0300517 /* Nothing to do here. */
Theodore Kilgore930bf782009-10-05 05:11:35 -0300518 break;
519 default:
Theodore Kilgoreb3e440e2009-10-09 03:54:49 -0300520 PDEBUG(D_ERR,
521 "Unknown VGA Sensor id Byte 1: %02x",
522 gspca_dev->usb_buf[1]);
523 PDEBUG(D_ERR,
524 "Defaults assumed, may not work");
525 PDEBUG(D_ERR, "Please report this");
Theodore Kilgore930bf782009-10-05 05:11:35 -0300526 }
Hans de Goede78028702009-09-02 09:55:16 -0300527 }
Theodore Kilgore930bf782009-10-05 05:11:35 -0300528 PDEBUG(D_PROBE, "MR97310A VGA camera detected, sensor: %d",
529 sd->sensor_type);
530 }
531 /* Stop streaming as we've started it to probe the sensor type. */
532 sd_stopN(gspca_dev);
Hans de Goede78028702009-09-02 09:55:16 -0300533
Theodore Kilgore930bf782009-10-05 05:11:35 -0300534 if (force_sensor_type != -1) {
535 sd->sensor_type = !!force_sensor_type;
536 PDEBUG(D_PROBE, "Forcing sensor type to: %d",
537 sd->sensor_type);
538 }
539
540 /* Setup controls depending on camera type */
541 if (sd->cam_type == CAM_TYPE_CIF) {
542 /* No brightness for sensor_type 0 */
Hans de Goede5f5e26b2009-08-14 10:40:26 -0300543 if (sd->sensor_type == 0)
Theodore Kilgore930bf782009-10-05 05:11:35 -0300544 gspca_dev->ctrl_dis = (1 << NORM_BRIGHTNESS_IDX) |
545 (1 << ARGUS_QC_BRIGHTNESS_IDX);
546 else
547 gspca_dev->ctrl_dis = (1 << ARGUS_QC_BRIGHTNESS_IDX);
Hans de Goede9ac69782009-08-14 10:15:52 -0300548 } else {
Theodore Kilgore930bf782009-10-05 05:11:35 -0300549 /* All controls need to be disabled if VGA sensor_type is 0 */
550 if (sd->sensor_type == 0)
551 gspca_dev->ctrl_dis = (1 << NORM_BRIGHTNESS_IDX) |
552 (1 << ARGUS_QC_BRIGHTNESS_IDX) |
553 (1 << EXPOSURE_IDX) |
554 (1 << GAIN_IDX);
555 else if (sd->do_lcd_stop)
556 /* Argus QuickClix has different brightness limits */
557 gspca_dev->ctrl_dis = (1 << NORM_BRIGHTNESS_IDX);
558 else
559 gspca_dev->ctrl_dis = (1 << ARGUS_QC_BRIGHTNESS_IDX);
Theodore Kilgore89f08632009-08-14 06:51:52 -0300560 }
Hans de Goede9ac69782009-08-14 10:15:52 -0300561
562 sd->brightness = MR97310A_BRIGHTNESS_DEFAULT;
563 sd->exposure = MR97310A_EXPOSURE_DEFAULT;
564 sd->gain = MR97310A_GAIN_DEFAULT;
565
Kyle Guinnd661e622009-01-16 05:36:14 -0300566 return 0;
567}
568
569/* this function is called at probe and resume time */
570static int sd_init(struct gspca_dev *gspca_dev)
571{
572 return 0;
573}
574
Theodore Kilgore89f08632009-08-14 06:51:52 -0300575static int start_cif_cam(struct gspca_dev *gspca_dev)
Kyle Guinnd661e622009-01-16 05:36:14 -0300576{
577 struct sd *sd = (struct sd *) gspca_dev;
578 __u8 *data = gspca_dev->usb_buf;
579 int err_code;
Theodore Kilgore89f08632009-08-14 06:51:52 -0300580 const __u8 startup_string[] = {
581 0x00,
582 0x0d,
583 0x01,
584 0x00, /* Hsize/8 for 352 or 320 */
585 0x00, /* Vsize/4 for 288 or 240 */
586 0x13, /* or 0xbb, depends on sensor */
587 0x00, /* Hstart, depends on res. */
588 0x00, /* reserved ? */
589 0x00, /* Vstart, depends on res. and sensor */
590 0x50, /* 0x54 to get 176 or 160 */
591 0xc0
592 };
Kyle Guinnd661e622009-01-16 05:36:14 -0300593
Theodore Kilgore89f08632009-08-14 06:51:52 -0300594 /* Note: Some of the above descriptions guessed from MR97113A driver */
Kyle Guinnd661e622009-01-16 05:36:14 -0300595
Theodore Kilgore89f08632009-08-14 06:51:52 -0300596 memcpy(data, startup_string, 11);
597 if (sd->sensor_type)
598 data[5] = 0xbb;
599
600 switch (gspca_dev->width) {
601 case 160:
602 data[9] |= 0x04; /* reg 8, 2:1 scale down from 320 */
603 /* fall thru */
604 case 320:
605 default:
606 data[3] = 0x28; /* reg 2, H size/8 */
607 data[4] = 0x3c; /* reg 3, V size/4 */
608 data[6] = 0x14; /* reg 5, H start */
609 data[8] = 0x1a + sd->sensor_type; /* reg 7, V start */
610 break;
611 case 176:
612 data[9] |= 0x04; /* reg 8, 2:1 scale down from 352 */
613 /* fall thru */
614 case 352:
615 data[3] = 0x2c; /* reg 2, H size/8 */
616 data[4] = 0x48; /* reg 3, V size/4 */
617 data[6] = 0x06; /* reg 5, H start */
Theodore Kilgore32345b02009-11-01 12:59:42 -0300618 data[8] = 0x06 - sd->sensor_type; /* reg 7, V start */
Theodore Kilgore89f08632009-08-14 06:51:52 -0300619 break;
620 }
621 err_code = mr_write(gspca_dev, 11);
622 if (err_code < 0)
623 return err_code;
624
625 if (!sd->sensor_type) {
626 const struct sensor_w_data cif_sensor0_init_data[] = {
627 {0x02, 0x00, {0x03, 0x5a, 0xb5, 0x01,
628 0x0f, 0x14, 0x0f, 0x10}, 8},
629 {0x0c, 0x00, {0x04, 0x01, 0x01, 0x00, 0x1f}, 5},
630 {0x12, 0x00, {0x07}, 1},
631 {0x1f, 0x00, {0x06}, 1},
632 {0x27, 0x00, {0x04}, 1},
633 {0x29, 0x00, {0x0c}, 1},
634 {0x40, 0x00, {0x40, 0x00, 0x04}, 3},
635 {0x50, 0x00, {0x60}, 1},
636 {0x60, 0x00, {0x06}, 1},
637 {0x6b, 0x00, {0x85, 0x85, 0xc8, 0xc8, 0xc8, 0xc8}, 6},
638 {0x72, 0x00, {0x1e, 0x56}, 2},
639 {0x75, 0x00, {0x58, 0x40, 0xa2, 0x02, 0x31, 0x02,
640 0x31, 0x80, 0x00}, 9},
641 {0x11, 0x00, {0x01}, 1},
642 {0, 0, {0}, 0}
643 };
644 err_code = sensor_write_regs(gspca_dev, cif_sensor0_init_data,
645 ARRAY_SIZE(cif_sensor0_init_data));
646 } else { /* sd->sensor_type = 1 */
647 const struct sensor_w_data cif_sensor1_init_data[] = {
Hans de Goede9ac69782009-08-14 10:15:52 -0300648 /* Reg 3,4, 7,8 get set by the controls */
Theodore Kilgore89f08632009-08-14 06:51:52 -0300649 {0x02, 0x00, {0x10}, 1},
Hans de Goede9ac69782009-08-14 10:15:52 -0300650 {0x05, 0x01, {0x22}, 1}, /* 5/6 also seen as 65h/32h */
651 {0x06, 0x01, {0x00}, 1},
Theodore Kilgore89f08632009-08-14 06:51:52 -0300652 {0x09, 0x02, {0x0e}, 1},
653 {0x0a, 0x02, {0x05}, 1},
654 {0x0b, 0x02, {0x05}, 1},
655 {0x0c, 0x02, {0x0f}, 1},
Hans de Goede9ac69782009-08-14 10:15:52 -0300656 {0x0d, 0x02, {0x07}, 1},
Theodore Kilgore89f08632009-08-14 06:51:52 -0300657 {0x0e, 0x02, {0x0c}, 1},
658 {0x0f, 0x00, {0x00}, 1},
659 {0x10, 0x00, {0x06}, 1},
660 {0x11, 0x00, {0x07}, 1},
661 {0x12, 0x00, {0x00}, 1},
662 {0x13, 0x00, {0x01}, 1},
663 {0, 0, {0}, 0}
664 };
665 err_code = sensor_write_regs(gspca_dev, cif_sensor1_init_data,
666 ARRAY_SIZE(cif_sensor1_init_data));
667 }
Theodore Kilgore930bf782009-10-05 05:11:35 -0300668 return err_code;
Theodore Kilgore89f08632009-08-14 06:51:52 -0300669}
670
671static int start_vga_cam(struct gspca_dev *gspca_dev)
672{
673 struct sd *sd = (struct sd *) gspca_dev;
674 __u8 *data = gspca_dev->usb_buf;
675 int err_code;
676 const __u8 startup_string[] = {0x00, 0x0d, 0x01, 0x00, 0x00, 0x2b,
677 0x00, 0x00, 0x00, 0x50, 0xc0};
Theodore Kilgore89f08632009-08-14 06:51:52 -0300678 /* What some of these mean is explained in start_cif_cam(), above */
Theodore Kilgore89f08632009-08-14 06:51:52 -0300679
Theodore Kilgore89f08632009-08-14 06:51:52 -0300680 memcpy(data, startup_string, 11);
681 if (!sd->sensor_type) {
682 data[5] = 0x00;
683 data[10] = 0x91;
684 }
Kyle Guinnd661e622009-01-16 05:36:14 -0300685
686 switch (gspca_dev->width) {
687 case 160:
688 data[9] |= 0x0c; /* reg 8, 4:1 scale down */
689 /* fall thru */
690 case 320:
691 data[9] |= 0x04; /* reg 8, 2:1 scale down */
692 /* fall thru */
693 case 640:
694 default:
Theodore Kilgore89f08632009-08-14 06:51:52 -0300695 data[3] = 0x50; /* reg 2, H size/8 */
696 data[4] = 0x78; /* reg 3, V size/4 */
Kyle Guinnd661e622009-01-16 05:36:14 -0300697 data[6] = 0x04; /* reg 5, H start */
698 data[8] = 0x03; /* reg 7, V start */
Theodore Kilgore89f08632009-08-14 06:51:52 -0300699 if (sd->do_lcd_stop)
700 data[8] = 0x04; /* Bayer tile shifted */
Kyle Guinnd661e622009-01-16 05:36:14 -0300701 break;
702
703 case 176:
704 data[9] |= 0x04; /* reg 8, 2:1 scale down */
705 /* fall thru */
706 case 352:
707 data[3] = 0x2c; /* reg 2, H size */
708 data[4] = 0x48; /* reg 3, V size */
709 data[6] = 0x94; /* reg 5, H start */
710 data[8] = 0x63; /* reg 7, V start */
Theodore Kilgore89f08632009-08-14 06:51:52 -0300711 if (sd->do_lcd_stop)
712 data[8] = 0x64; /* Bayer tile shifted */
Kyle Guinnd661e622009-01-16 05:36:14 -0300713 break;
714 }
715
Theodore Kilgore89f08632009-08-14 06:51:52 -0300716 err_code = mr_write(gspca_dev, 11);
Kyle Guinnd661e622009-01-16 05:36:14 -0300717 if (err_code < 0)
718 return err_code;
719
Theodore Kilgore89f08632009-08-14 06:51:52 -0300720 if (!sd->sensor_type) {
721 /* The only known sensor_type 0 cam is the Argus DC-1620 */
722 const struct sensor_w_data vga_sensor0_init_data[] = {
723 {0x01, 0x00, {0x0c, 0x00, 0x04}, 3},
724 {0x14, 0x00, {0x01, 0xe4, 0x02, 0x84}, 4},
725 {0x20, 0x00, {0x00, 0x80, 0x00, 0x08}, 4},
726 {0x25, 0x00, {0x03, 0xa9, 0x80}, 3},
727 {0x30, 0x00, {0x30, 0x18, 0x10, 0x18}, 4},
728 {0, 0, {0}, 0}
729 };
730 err_code = sensor_write_regs(gspca_dev, vga_sensor0_init_data,
731 ARRAY_SIZE(vga_sensor0_init_data));
732 } else { /* sd->sensor_type = 1 */
733 const struct sensor_w_data vga_sensor1_init_data[] = {
734 {0x02, 0x00, {0x06, 0x59, 0x0c, 0x16, 0x00,
735 0x07, 0x00, 0x01}, 8},
736 {0x11, 0x04, {0x01}, 1},
737 /*{0x0a, 0x00, {0x00, 0x01, 0x00, 0x00, 0x01, */
738 {0x0a, 0x00, {0x01, 0x06, 0x00, 0x00, 0x01,
739 0x00, 0x0a}, 7},
740 {0x11, 0x04, {0x01}, 1},
741 {0x12, 0x00, {0x00, 0x63, 0x00, 0x70, 0x00, 0x00}, 6},
742 {0x11, 0x04, {0x01}, 1},
743 {0, 0, {0}, 0}
744 };
745 err_code = sensor_write_regs(gspca_dev, vga_sensor1_init_data,
746 ARRAY_SIZE(vga_sensor1_init_data));
747 }
Theodore Kilgore89f08632009-08-14 06:51:52 -0300748 return err_code;
749}
750
751static int sd_start(struct gspca_dev *gspca_dev)
752{
753 struct sd *sd = (struct sd *) gspca_dev;
754 int err_code;
Theodore Kilgore89f08632009-08-14 06:51:52 -0300755
Theodore Kilgore89f08632009-08-14 06:51:52 -0300756 sd->sof_read = 0;
Theodore Kilgore930bf782009-10-05 05:11:35 -0300757
758 /* Some of the VGA cameras require the memory pointer
759 * to be set to 0 again. We have been forced to start the
760 * stream somewhere else to detect the hardware, and closed it,
761 * and now since we are restarting the stream we need to do a
762 * completely fresh and clean start. */
763 err_code = zero_the_pointer(gspca_dev);
764 if (err_code < 0)
765 return err_code;
766
767 err_code = stream_start(gspca_dev);
768 if (err_code < 0)
769 return err_code;
770
Theodore Kilgore89f08632009-08-14 06:51:52 -0300771 if (sd->cam_type == CAM_TYPE_CIF) {
Theodore Kilgore89f08632009-08-14 06:51:52 -0300772 err_code = start_cif_cam(gspca_dev);
773 } else {
Theodore Kilgore89f08632009-08-14 06:51:52 -0300774 err_code = start_vga_cam(gspca_dev);
775 }
Theodore Kilgore930bf782009-10-05 05:11:35 -0300776 if (err_code < 0)
777 return err_code;
778
779 setbrightness(gspca_dev);
780 setexposure(gspca_dev);
781 setgain(gspca_dev);
782
783 return isoc_enable(gspca_dev);
Kyle Guinnd661e622009-01-16 05:36:14 -0300784}
785
786static void sd_stopN(struct gspca_dev *gspca_dev)
787{
Theodore Kilgore89f08632009-08-14 06:51:52 -0300788 struct sd *sd = (struct sd *) gspca_dev;
Kyle Guinnd661e622009-01-16 05:36:14 -0300789
Theodore Kilgore930bf782009-10-05 05:11:35 -0300790 stream_stop(gspca_dev);
Theodore Kilgore89f08632009-08-14 06:51:52 -0300791 /* Not all the cams need this, but even if not, probably a good idea */
792 zero_the_pointer(gspca_dev);
Theodore Kilgore930bf782009-10-05 05:11:35 -0300793 if (sd->do_lcd_stop)
794 lcd_stop(gspca_dev);
Theodore Kilgore89f08632009-08-14 06:51:52 -0300795}
796
797static void setbrightness(struct gspca_dev *gspca_dev)
798{
799 struct sd *sd = (struct sd *) gspca_dev;
800 u8 val;
Theodore Kilgore930bf782009-10-05 05:11:35 -0300801 u8 sign_reg = 7; /* This reg and the next one used on CIF cams. */
802 u8 value_reg = 8; /* VGA cams seem to use regs 0x0b and 0x0c */
803 const u8 quick_clix_table[] =
804 /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */
805 { 0, 4, 8, 12, 1, 2, 3, 5, 6, 9, 7, 10, 13, 11, 14, 15};
806 /*
807 * This control is disabled for CIF type 1 and VGA type 0 cameras.
808 * It does not quite act linearly for the Argus QuickClix camera,
809 * but it does control brightness. The values are 0 - 15 only, and
810 * the table above makes them act consecutively.
811 */
812 if ((gspca_dev->ctrl_dis & (1 << NORM_BRIGHTNESS_IDX)) &&
813 (gspca_dev->ctrl_dis & (1 << ARGUS_QC_BRIGHTNESS_IDX)))
Hans de Goede9ac69782009-08-14 10:15:52 -0300814 return;
815
Theodore Kilgore930bf782009-10-05 05:11:35 -0300816 if (sd->cam_type == CAM_TYPE_VGA) {
817 sign_reg += 4;
818 value_reg += 4;
819 }
820
Hans de Goede9ac69782009-08-14 10:15:52 -0300821 /* Note register 7 is also seen as 0x8x or 0xCx in dumps */
Theodore Kilgore89f08632009-08-14 06:51:52 -0300822 if (sd->brightness > 0) {
Theodore Kilgore930bf782009-10-05 05:11:35 -0300823 sensor_write1(gspca_dev, sign_reg, 0x00);
Theodore Kilgore89f08632009-08-14 06:51:52 -0300824 val = sd->brightness;
825 } else {
Theodore Kilgore930bf782009-10-05 05:11:35 -0300826 sensor_write1(gspca_dev, sign_reg, 0x01);
827 val = (257 - sd->brightness);
Theodore Kilgore89f08632009-08-14 06:51:52 -0300828 }
Theodore Kilgore930bf782009-10-05 05:11:35 -0300829 /* Use lookup table for funky Argus QuickClix brightness */
830 if (sd->do_lcd_stop)
831 val = quick_clix_table[val];
832
833 sensor_write1(gspca_dev, value_reg, val);
Theodore Kilgore89f08632009-08-14 06:51:52 -0300834}
835
836static void setexposure(struct gspca_dev *gspca_dev)
837{
838 struct sd *sd = (struct sd *) gspca_dev;
Theodore Kilgore930bf782009-10-05 05:11:35 -0300839 int exposure;
Theodore Kilgore89f08632009-08-14 06:51:52 -0300840
Hans de Goede9ac69782009-08-14 10:15:52 -0300841 if (gspca_dev->ctrl_dis & (1 << EXPOSURE_IDX))
842 return;
843
Theodore Kilgore930bf782009-10-05 05:11:35 -0300844 if (sd->cam_type == CAM_TYPE_CIF && sd->sensor_type == 1) {
845 /* This cam does not like very low exposure settings */
846 exposure = (sd->exposure < 300) ? 300 : sd->exposure;
847 sensor_write1(gspca_dev, 3, exposure >> 4);
848 sensor_write1(gspca_dev, 4, exposure & 0x0f);
Hans de Goedea2e081b2009-08-14 17:11:36 -0300849 } else {
Hans de Goedea2e081b2009-08-14 17:11:36 -0300850 /* We have both a clock divider and an exposure register.
851 We first calculate the clock divider, as that determines
852 the maximum exposure and then we calculayte the exposure
853 register setting (which goes from 0 - 511).
854
855 Note our 0 - 4095 exposure is mapped to 0 - 511
856 milliseconds exposure time */
Theodore Kilgore930bf782009-10-05 05:11:35 -0300857 u8 clockdiv = (60 * sd->exposure + 7999) / 8000;
Hans de Goedea2e081b2009-08-14 17:11:36 -0300858
859 /* Limit framerate to not exceed usb bandwidth */
860 if (clockdiv < 3 && gspca_dev->width >= 320)
861 clockdiv = 3;
862 else if (clockdiv < 2)
863 clockdiv = 2;
864
Theodore Kilgore930bf782009-10-05 05:11:35 -0300865 if (sd->cam_type == CAM_TYPE_VGA && clockdiv < 4)
866 clockdiv = 4;
867
Hans de Goedea2e081b2009-08-14 17:11:36 -0300868 /* Frame exposure time in ms = 1000 * clockdiv / 60 ->
869 exposure = (sd->exposure / 8) * 511 / (1000 * clockdiv / 60) */
870 exposure = (60 * 511 * sd->exposure) / (8000 * clockdiv);
871 if (exposure > 511)
872 exposure = 511;
873
874 /* exposure register value is reversed! */
875 exposure = 511 - exposure;
876
877 sensor_write1(gspca_dev, 0x02, clockdiv);
878 sensor_write1(gspca_dev, 0x0e, exposure & 0xff);
879 sensor_write1(gspca_dev, 0x0f, exposure >> 8);
880 }
Theodore Kilgore89f08632009-08-14 06:51:52 -0300881}
882
883static void setgain(struct gspca_dev *gspca_dev)
884{
885 struct sd *sd = (struct sd *) gspca_dev;
886
Hans de Goede9ac69782009-08-14 10:15:52 -0300887 if (gspca_dev->ctrl_dis & (1 << GAIN_IDX))
888 return;
889
Theodore Kilgore930bf782009-10-05 05:11:35 -0300890 if (sd->cam_type == CAM_TYPE_CIF && sd->sensor_type == 1) {
Hans de Goede823902d2009-08-17 12:25:17 -0300891 sensor_write1(gspca_dev, 0x0e, sd->gain);
Hans de Goedea2e081b2009-08-14 17:11:36 -0300892 } else {
893 sensor_write1(gspca_dev, 0x10, sd->gain);
894 }
Theodore Kilgore89f08632009-08-14 06:51:52 -0300895}
896
897static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
898{
899 struct sd *sd = (struct sd *) gspca_dev;
900
901 sd->brightness = val;
902 if (gspca_dev->streaming)
903 setbrightness(gspca_dev);
904 return 0;
905}
906
907static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
908{
909 struct sd *sd = (struct sd *) gspca_dev;
910
911 *val = sd->brightness;
912 return 0;
913}
914
915static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
916{
917 struct sd *sd = (struct sd *) gspca_dev;
918
919 sd->exposure = val;
920 if (gspca_dev->streaming)
921 setexposure(gspca_dev);
922 return 0;
923}
924
925static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
926{
927 struct sd *sd = (struct sd *) gspca_dev;
928
929 *val = sd->exposure;
930 return 0;
931}
932
933static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
934{
935 struct sd *sd = (struct sd *) gspca_dev;
936
937 sd->gain = val;
938 if (gspca_dev->streaming)
939 setgain(gspca_dev);
940 return 0;
941}
942
943static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
944{
945 struct sd *sd = (struct sd *) gspca_dev;
946
947 *val = sd->gain;
948 return 0;
Kyle Guinnd661e622009-01-16 05:36:14 -0300949}
950
951/* Include pac common sof detection functions */
952#include "pac_common.h"
953
954static void sd_pkt_scan(struct gspca_dev *gspca_dev,
955 struct gspca_frame *frame, /* target */
956 __u8 *data, /* isoc packet */
957 int len) /* iso packet length */
958{
Kyle Guinnd661e622009-01-16 05:36:14 -0300959 unsigned char *sof;
960
961 sof = pac_find_sof(gspca_dev, data, len);
962 if (sof) {
963 int n;
964
965 /* finish decoding current frame */
966 n = sof - data;
967 if (n > sizeof pac_sof_marker)
968 n -= sizeof pac_sof_marker;
969 else
970 n = 0;
971 frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
972 data, n);
Theodore Kilgore9832d762009-03-13 13:04:31 -0300973 /* Start next frame. */
974 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
975 pac_sof_marker, sizeof pac_sof_marker);
Kyle Guinnd661e622009-01-16 05:36:14 -0300976 len -= sof - data;
977 data = sof;
978 }
Kyle Guinnd661e622009-01-16 05:36:14 -0300979 gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
980}
981
982/* sub-driver description */
983static const struct sd_desc sd_desc = {
984 .name = MODULE_NAME,
985 .ctrls = sd_ctrls,
986 .nctrls = ARRAY_SIZE(sd_ctrls),
987 .config = sd_config,
988 .init = sd_init,
989 .start = sd_start,
990 .stopN = sd_stopN,
991 .pkt_scan = sd_pkt_scan,
992};
993
994/* -- module initialisation -- */
995static const __devinitdata struct usb_device_id device_table[] = {
Theodore Kilgore89f08632009-08-14 06:51:52 -0300996 {USB_DEVICE(0x08ca, 0x0111)}, /* Aiptek Pencam VGA+ */
997 {USB_DEVICE(0x093a, 0x010f)}, /* All other known MR97310A VGA cams */
998 {USB_DEVICE(0x093a, 0x010e)}, /* All known MR97310A CIF cams */
Kyle Guinnd661e622009-01-16 05:36:14 -0300999 {}
1000};
1001MODULE_DEVICE_TABLE(usb, device_table);
1002
1003/* -- device connect -- */
1004static int sd_probe(struct usb_interface *intf,
1005 const struct usb_device_id *id)
1006{
1007 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
1008 THIS_MODULE);
1009}
1010
1011static struct usb_driver sd_driver = {
1012 .name = MODULE_NAME,
1013 .id_table = device_table,
1014 .probe = sd_probe,
1015 .disconnect = gspca_disconnect,
1016#ifdef CONFIG_PM
1017 .suspend = gspca_suspend,
1018 .resume = gspca_resume,
1019#endif
1020};
1021
1022/* -- module insert / remove -- */
1023static int __init sd_mod_init(void)
1024{
Alexey Klimov5d3fa302009-03-27 15:57:46 -03001025 int ret;
1026
1027 ret = usb_register(&sd_driver);
1028 if (ret < 0)
1029 return ret;
Kyle Guinnd661e622009-01-16 05:36:14 -03001030 PDEBUG(D_PROBE, "registered");
1031 return 0;
1032}
1033static void __exit sd_mod_exit(void)
1034{
1035 usb_deregister(&sd_driver);
1036 PDEBUG(D_PROBE, "deregistered");
1037}
1038
1039module_init(sd_mod_init);
1040module_exit(sd_mod_exit);