blob: 7ea5e9112b2fe571b6ee14640e88d7a1a692a43e [file] [log] [blame]
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001/*
2 * Sunplus spca561 subdriver
3 *
4 * Copyright (C) 2004 Michel Xhaard mxhaard@magic.fr
5 *
6 * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
Joe Perches133a9fe2011-08-21 19:56:57 -030023#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030025#define MODULE_NAME "spca561"
26
Hans de Goede436c2c52010-02-28 09:41:04 -030027#include <linux/input.h>
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030028#include "gspca.h"
29
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030030MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
31MODULE_DESCRIPTION("GSPCA/SPCA561 USB Camera Driver");
32MODULE_LICENSE("GPL");
33
Hans Verkuil3fa24bf2012-05-16 08:20:44 -030034#define EXPOSURE_MAX (2047 + 325)
35
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030036/* specific webcam descriptor */
37struct sd {
38 struct gspca_dev gspca_dev; /* !! must be the first item */
39
Hans Verkuil3fa24bf2012-05-16 08:20:44 -030040 struct { /* hue/contrast control cluster */
41 struct v4l2_ctrl *contrast;
42 struct v4l2_ctrl *hue;
43 };
44 struct v4l2_ctrl *autogain;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030045
Jean-Francois Moined698dc62008-09-03 16:47:51 -030046#define EXPO12A_DEF 3
47 __u8 expo12a; /* expo/gain? for rev 12a */
48
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030049 __u8 chip_revision;
Jean-Francois Moine7879d452008-09-03 16:47:32 -030050#define Rev012A 0
51#define Rev072A 1
52
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030053 signed char ag_cnt;
54#define AG_CNT_START 13
55};
56
Jean-Francois Moinecc611b82008-12-29 07:49:41 -030057static const struct v4l2_pix_format sif_012a_mode[] = {
Jean-Francois Moinec2446b32008-07-05 11:49:20 -030058 {160, 120, V4L2_PIX_FMT_SGBRG8, V4L2_FIELD_NONE,
59 .bytesperline = 160,
60 .sizeimage = 160 * 120,
61 .colorspace = V4L2_COLORSPACE_SRGB,
62 .priv = 3},
63 {176, 144, V4L2_PIX_FMT_SGBRG8, V4L2_FIELD_NONE,
64 .bytesperline = 176,
65 .sizeimage = 176 * 144,
66 .colorspace = V4L2_COLORSPACE_SRGB,
67 .priv = 2},
68 {320, 240, V4L2_PIX_FMT_SPCA561, V4L2_FIELD_NONE,
69 .bytesperline = 320,
70 .sizeimage = 320 * 240 * 4 / 8,
71 .colorspace = V4L2_COLORSPACE_SRGB,
72 .priv = 1},
73 {352, 288, V4L2_PIX_FMT_SPCA561, V4L2_FIELD_NONE,
74 .bytesperline = 352,
75 .sizeimage = 352 * 288 * 4 / 8,
76 .colorspace = V4L2_COLORSPACE_SRGB,
77 .priv = 0},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030078};
79
Jean-Francois Moinecc611b82008-12-29 07:49:41 -030080static const struct v4l2_pix_format sif_072a_mode[] = {
Jean-Francois Moineb77c0042008-09-04 16:22:56 -030081 {160, 120, V4L2_PIX_FMT_SGBRG8, V4L2_FIELD_NONE,
82 .bytesperline = 160,
83 .sizeimage = 160 * 120,
84 .colorspace = V4L2_COLORSPACE_SRGB,
85 .priv = 3},
86 {176, 144, V4L2_PIX_FMT_SGBRG8, V4L2_FIELD_NONE,
87 .bytesperline = 176,
88 .sizeimage = 176 * 144,
89 .colorspace = V4L2_COLORSPACE_SRGB,
90 .priv = 2},
91 {320, 240, V4L2_PIX_FMT_SGBRG8, V4L2_FIELD_NONE,
92 .bytesperline = 320,
93 .sizeimage = 320 * 240,
94 .colorspace = V4L2_COLORSPACE_SRGB,
95 .priv = 1},
96 {352, 288, V4L2_PIX_FMT_SGBRG8, V4L2_FIELD_NONE,
97 .bytesperline = 352,
98 .sizeimage = 352 * 288,
99 .colorspace = V4L2_COLORSPACE_SRGB,
100 .priv = 0},
101};
102
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300103/*
104 * Initialization data
105 * I'm not very sure how to split initialization from open data
106 * chunks. For now, we'll consider everything as initialization
107 */
108/* Frame packet header offsets for the spca561 */
109#define SPCA561_OFFSET_SNAP 1
110#define SPCA561_OFFSET_TYPE 2
111#define SPCA561_OFFSET_COMPRESS 3
112#define SPCA561_OFFSET_FRAMSEQ 4
113#define SPCA561_OFFSET_GPIO 5
114#define SPCA561_OFFSET_USBBUFF 6
115#define SPCA561_OFFSET_WIN2GRAVE 7
116#define SPCA561_OFFSET_WIN2RAVE 8
117#define SPCA561_OFFSET_WIN2BAVE 9
118#define SPCA561_OFFSET_WIN2GBAVE 10
119#define SPCA561_OFFSET_WIN1GRAVE 11
120#define SPCA561_OFFSET_WIN1RAVE 12
121#define SPCA561_OFFSET_WIN1BAVE 13
122#define SPCA561_OFFSET_WIN1GBAVE 14
123#define SPCA561_OFFSET_FREQ 15
124#define SPCA561_OFFSET_VSYNC 16
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300125#define SPCA561_INDEX_I2C_BASE 0x8800
126#define SPCA561_SNAPBIT 0x20
127#define SPCA561_SNAPCTRL 0x40
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300128
Jean-Francois Moine0dbc2c12009-01-16 16:24:28 -0300129static const u16 rev72a_reset[][2] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300130 {0x0000, 0x8114}, /* Software GPIO output data */
131 {0x0001, 0x8114}, /* Software GPIO output data */
132 {0x0000, 0x8112}, /* Some kind of reset */
Jean-Francois Moine0dbc2c12009-01-16 16:24:28 -0300133 {}
134};
135static const __u16 rev72a_init_data1[][2] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300136 {0x0003, 0x8701}, /* PCLK clock delay adjustment */
137 {0x0001, 0x8703}, /* HSYNC from cmos inverted */
138 {0x0011, 0x8118}, /* Enable and conf sensor */
139 {0x0001, 0x8118}, /* Conf sensor */
140 {0x0092, 0x8804}, /* I know nothing about these */
141 {0x0010, 0x8802}, /* 0x88xx registers, so I won't */
Jean-Francois Moinef8a04a62008-12-19 07:21:26 -0300142 {}
143};
Jean-Francois Moine0dbc2c12009-01-16 16:24:28 -0300144static const u16 rev72a_init_sensor1[][2] = {
145 {0x0001, 0x000d},
146 {0x0002, 0x0018},
147 {0x0004, 0x0165},
148 {0x0005, 0x0021},
149 {0x0007, 0x00aa},
150 {0x0020, 0x1504},
151 {0x0039, 0x0002},
152 {0x0035, 0x0010},
153 {0x0009, 0x1049},
154 {0x0028, 0x000b},
155 {0x003b, 0x000f},
156 {0x003c, 0x0000},
Jean-Francois Moinef8a04a62008-12-19 07:21:26 -0300157 {}
158};
159static const __u16 rev72a_init_data2[][2] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300160 {0x0018, 0x8601}, /* Pixel/line selection for color separation */
161 {0x0000, 0x8602}, /* Optical black level for user setting */
162 {0x0060, 0x8604}, /* Optical black horizontal offset */
163 {0x0002, 0x8605}, /* Optical black vertical offset */
164 {0x0000, 0x8603}, /* Non-automatic optical black level */
165 {0x0002, 0x865b}, /* Horizontal offset for valid pixels */
166 {0x0000, 0x865f}, /* Vertical valid pixels window (x2) */
167 {0x00b0, 0x865d}, /* Horizontal valid pixels window (x2) */
168 {0x0090, 0x865e}, /* Vertical valid lines window (x2) */
169 {0x00e0, 0x8406}, /* Memory buffer threshold */
170 {0x0000, 0x8660}, /* Compensation memory stuff */
171 {0x0002, 0x8201}, /* Output address for r/w serial EEPROM */
172 {0x0008, 0x8200}, /* Clear valid bit for serial EEPROM */
173 {0x0001, 0x8200}, /* OprMode to be executed by hardware */
Jean-Francois Moine0dbc2c12009-01-16 16:24:28 -0300174/* from ms-win */
175 {0x0000, 0x8611}, /* R offset for white balance */
176 {0x00fd, 0x8612}, /* Gr offset for white balance */
177 {0x0003, 0x8613}, /* B offset for white balance */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300178 {0x0000, 0x8614}, /* Gb offset for white balance */
Jean-Francois Moine5b7ed282008-12-18 12:38:15 -0300179/* from ms-win */
180 {0x0035, 0x8651}, /* R gain for white balance */
181 {0x0040, 0x8652}, /* Gr gain for white balance */
182 {0x005f, 0x8653}, /* B gain for white balance */
183 {0x0040, 0x8654}, /* Gb gain for white balance */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300184 {0x0002, 0x8502}, /* Maximum average bit rate stuff */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300185 {0x0011, 0x8802},
Jean-Francois Moine0dbc2c12009-01-16 16:24:28 -0300186
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300187 {0x0087, 0x8700}, /* Set master clock (96Mhz????) */
188 {0x0081, 0x8702}, /* Master clock output enable */
189
190 {0x0000, 0x8500}, /* Set image type (352x288 no compression) */
191 /* Originally was 0x0010 (352x288 compression) */
192
193 {0x0002, 0x865b}, /* Horizontal offset for valid pixels */
194 {0x0003, 0x865c}, /* Vertical offset for valid lines */
Jean-Francois Moinef8a04a62008-12-19 07:21:26 -0300195 {}
196};
Jean-Francois Moine0dbc2c12009-01-16 16:24:28 -0300197static const u16 rev72a_init_sensor2[][2] = {
198 {0x0003, 0x0121},
199 {0x0004, 0x0165},
200 {0x0005, 0x002f}, /* blanking control column */
201 {0x0006, 0x0000}, /* blanking mode row*/
202 {0x000a, 0x0002},
203 {0x0009, 0x1061}, /* setexposure times && pixel clock
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300204 * 0001 0 | 000 0110 0001 */
Jean-Francois Moine0dbc2c12009-01-16 16:24:28 -0300205 {0x0035, 0x0014},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300206 {}
207};
208
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300209/******************** QC Express etch2 stuff ********************/
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300210static const __u16 Pb100_1map8300[][2] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300211 /* reg, value */
212 {0x8320, 0x3304},
213
214 {0x8303, 0x0125}, /* image area */
215 {0x8304, 0x0169},
216 {0x8328, 0x000b},
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300217 {0x833c, 0x0001}, /*fixme: win:07*/
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300218
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300219 {0x832f, 0x1904}, /*fixme: was 0419*/
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300220 {0x8307, 0x00aa},
221 {0x8301, 0x0003},
222 {0x8302, 0x000e},
223 {}
224};
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300225static const __u16 Pb100_2map8300[][2] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300226 /* reg, value */
227 {0x8339, 0x0000},
228 {0x8307, 0x00aa},
229 {}
230};
231
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300232static const __u16 spca561_161rev12A_data1[][2] = {
Hans de Goede6b33e5e2010-02-27 07:18:14 -0300233 {0x29, 0x8118}, /* Control register (various enable bits) */
234 {0x08, 0x8114}, /* GPIO: Led off */
235 {0x0e, 0x8112}, /* 0x0e stream off 0x3e stream on */
Jean-Francois Moine6c9d3c52008-09-03 16:47:30 -0300236 {0x00, 0x8102}, /* white balance - new */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300237 {0x92, 0x8804},
238 {0x04, 0x8802}, /* windows uses 08 */
239 {}
240};
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300241static const __u16 spca561_161rev12A_data2[][2] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300242 {0x21, 0x8118},
243 {0x10, 0x8500},
244 {0x07, 0x8601},
245 {0x07, 0x8602},
246 {0x04, 0x8501},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300247
248 {0x07, 0x8201}, /* windows uses 02 */
249 {0x08, 0x8200},
250 {0x01, 0x8200},
251
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300252 {0x90, 0x8604},
253 {0x00, 0x8605},
254 {0xb0, 0x8603},
255
256 /* sensor gains */
Jean-Francois Moine6c9d3c52008-09-03 16:47:30 -0300257 {0x07, 0x8601}, /* white balance - new */
258 {0x07, 0x8602}, /* white balance - new */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300259 {0x00, 0x8610}, /* *red */
260 {0x00, 0x8611}, /* 3f *green */
261 {0x00, 0x8612}, /* green *blue */
262 {0x00, 0x8613}, /* blue *green */
Jean-Francois Moine6c9d3c52008-09-03 16:47:30 -0300263 {0x43, 0x8614}, /* green *red - white balance - was 0x35 */
264 {0x40, 0x8615}, /* 40 *green - white balance - was 0x35 */
265 {0x71, 0x8616}, /* 7a *blue - white balance - was 0x35 */
266 {0x40, 0x8617}, /* 40 *green - white balance - was 0x35 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300267
268 {0x0c, 0x8620}, /* 0c */
269 {0xc8, 0x8631}, /* c8 */
270 {0xc8, 0x8634}, /* c8 */
271 {0x23, 0x8635}, /* 23 */
272 {0x1f, 0x8636}, /* 1f */
273 {0xdd, 0x8637}, /* dd */
274 {0xe1, 0x8638}, /* e1 */
275 {0x1d, 0x8639}, /* 1d */
276 {0x21, 0x863a}, /* 21 */
277 {0xe3, 0x863b}, /* e3 */
278 {0xdf, 0x863c}, /* df */
279 {0xf0, 0x8505},
280 {0x32, 0x850a},
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300281/* {0x99, 0x8700}, * - white balance - new (removed) */
Hans de Goede6b33e5e2010-02-27 07:18:14 -0300282 /* HDG we used to do this in stop0, making the init state and the state
283 after a start / stop different, so do this here instead. */
284 {0x29, 0x8118},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300285 {}
286};
287
Jean-Francois Moine35dc1b42008-12-17 14:34:53 -0300288static void reg_w_val(struct usb_device *dev, __u16 index, __u8 value)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300289{
Jean-Francois Moine35dc1b42008-12-17 14:34:53 -0300290 int ret;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300291
Jean-Francois Moine35dc1b42008-12-17 14:34:53 -0300292 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
293 0, /* request */
294 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
295 value, index, NULL, 0, 500);
296 PDEBUG(D_USBO, "reg write: 0x%02x:0x%02x", index, value);
297 if (ret < 0)
Joe Perches133a9fe2011-08-21 19:56:57 -0300298 pr_err("reg write: error %d\n", ret);
Jean-Francois Moine35dc1b42008-12-17 14:34:53 -0300299}
300
301static void write_vector(struct gspca_dev *gspca_dev,
302 const __u16 data[][2])
303{
304 struct usb_device *dev = gspca_dev->dev;
305 int i;
306
307 i = 0;
308 while (data[i][1] != 0) {
309 reg_w_val(dev, data[i][1], data[i][0]);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300310 i++;
311 }
312}
Jean-Francois Moine35dc1b42008-12-17 14:34:53 -0300313
314/* read 'len' bytes to gspca_dev->usb_buf */
315static void reg_r(struct gspca_dev *gspca_dev,
316 __u16 index, __u16 length)
317{
318 usb_control_msg(gspca_dev->dev,
319 usb_rcvctrlpipe(gspca_dev->dev, 0),
320 0, /* request */
321 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
322 0, /* value */
323 index, gspca_dev->usb_buf, length, 500);
324}
325
326/* write 'len' bytes from gspca_dev->usb_buf */
327static void reg_w_buf(struct gspca_dev *gspca_dev,
328 __u16 index, __u16 len)
329{
330 usb_control_msg(gspca_dev->dev,
331 usb_sndctrlpipe(gspca_dev->dev, 0),
332 0, /* request */
333 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
334 0, /* value */
335 index, gspca_dev->usb_buf, len, 500);
336}
337
338static void i2c_write(struct gspca_dev *gspca_dev, __u16 value, __u16 reg)
339{
340 int retry = 60;
341
342 reg_w_val(gspca_dev->dev, 0x8801, reg);
343 reg_w_val(gspca_dev->dev, 0x8805, value);
344 reg_w_val(gspca_dev->dev, 0x8800, value >> 8);
345 do {
346 reg_r(gspca_dev, 0x8803, 1);
347 if (!gspca_dev->usb_buf[0])
348 return;
Jean-Francois Moine0dbc2c12009-01-16 16:24:28 -0300349 msleep(10);
Jean-Francois Moine35dc1b42008-12-17 14:34:53 -0300350 } while (--retry);
351}
352
353static int i2c_read(struct gspca_dev *gspca_dev, __u16 reg, __u8 mode)
354{
355 int retry = 60;
356 __u8 value;
357
358 reg_w_val(gspca_dev->dev, 0x8804, 0x92);
359 reg_w_val(gspca_dev->dev, 0x8801, reg);
360 reg_w_val(gspca_dev->dev, 0x8802, mode | 0x01);
361 do {
362 reg_r(gspca_dev, 0x8803, 1);
363 if (!gspca_dev->usb_buf[0]) {
364 reg_r(gspca_dev, 0x8800, 1);
365 value = gspca_dev->usb_buf[0];
366 reg_r(gspca_dev, 0x8805, 1);
367 return ((int) value << 8) | gspca_dev->usb_buf[0];
368 }
Jean-Francois Moine0dbc2c12009-01-16 16:24:28 -0300369 msleep(10);
Jean-Francois Moine35dc1b42008-12-17 14:34:53 -0300370 } while (--retry);
371 return -1;
372}
373
374static void sensor_mapwrite(struct gspca_dev *gspca_dev,
375 const __u16 (*sensormap)[2])
376{
377 while ((*sensormap)[0]) {
378 gspca_dev->usb_buf[0] = (*sensormap)[1];
379 gspca_dev->usb_buf[1] = (*sensormap)[1] >> 8;
380 reg_w_buf(gspca_dev, (*sensormap)[0], 2);
381 sensormap++;
382 }
383}
384
Jean-Francois Moinef8a04a62008-12-19 07:21:26 -0300385static void write_sensor_72a(struct gspca_dev *gspca_dev,
386 const __u16 (*sensor)[2])
387{
388 while ((*sensor)[0]) {
389 i2c_write(gspca_dev, (*sensor)[1], (*sensor)[0]);
390 sensor++;
391 }
392}
393
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300394static void init_161rev12A(struct gspca_dev *gspca_dev)
395{
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300396 write_vector(gspca_dev, spca561_161rev12A_data1);
397 sensor_mapwrite(gspca_dev, Pb100_1map8300);
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300398/*fixme: should be in sd_start*/
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300399 write_vector(gspca_dev, spca561_161rev12A_data2);
400 sensor_mapwrite(gspca_dev, Pb100_2map8300);
401}
402
403/* this function is called at probe time */
404static int sd_config(struct gspca_dev *gspca_dev,
405 const struct usb_device_id *id)
406{
407 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300408 struct cam *cam;
409 __u16 vendor, product;
410 __u8 data1, data2;
411
412 /* Read frm global register the USB product and vendor IDs, just to
413 * prove that we can communicate with the device. This works, which
414 * confirms at we are communicating properly and that the device
415 * is a 561. */
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300416 reg_r(gspca_dev, 0x8104, 1);
417 data1 = gspca_dev->usb_buf[0];
418 reg_r(gspca_dev, 0x8105, 1);
419 data2 = gspca_dev->usb_buf[0];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300420 vendor = (data2 << 8) | data1;
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300421 reg_r(gspca_dev, 0x8106, 1);
422 data1 = gspca_dev->usb_buf[0];
423 reg_r(gspca_dev, 0x8107, 1);
424 data2 = gspca_dev->usb_buf[0];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300425 product = (data2 << 8) | data1;
426 if (vendor != id->idVendor || product != id->idProduct) {
427 PDEBUG(D_PROBE, "Bad vendor / product from device");
428 return -EINVAL;
429 }
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -0300430
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300431 cam = &gspca_dev->cam;
Hans de Goedeeb3fb7c2012-01-01 16:35:01 -0300432 cam->needs_full_bandwidth = 1;
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -0300433
434 sd->chip_revision = id->driver_info;
Jean-Francois Moineb77c0042008-09-04 16:22:56 -0300435 if (sd->chip_revision == Rev012A) {
436 cam->cam_mode = sif_012a_mode;
437 cam->nmodes = ARRAY_SIZE(sif_012a_mode);
438 } else {
439 cam->cam_mode = sif_072a_mode;
440 cam->nmodes = ARRAY_SIZE(sif_072a_mode);
441 }
Jean-Francois Moined698dc62008-09-03 16:47:51 -0300442 sd->expo12a = EXPO12A_DEF;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300443 return 0;
444}
445
Jean-Francois Moine012d6b02008-09-03 17:12:16 -0300446/* this function is called at probe and resume time */
447static int sd_init_12a(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300448{
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300449 PDEBUG(D_STREAM, "Chip revision: 012a");
450 init_161rev12A(gspca_dev);
451 return 0;
452}
Jean-Francois Moine012d6b02008-09-03 17:12:16 -0300453static int sd_init_72a(struct gspca_dev *gspca_dev)
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300454{
455 PDEBUG(D_STREAM, "Chip revision: 072a");
Jean-Francois Moine0dbc2c12009-01-16 16:24:28 -0300456 write_vector(gspca_dev, rev72a_reset);
457 msleep(200);
Jean-Francois Moinef8a04a62008-12-19 07:21:26 -0300458 write_vector(gspca_dev, rev72a_init_data1);
459 write_sensor_72a(gspca_dev, rev72a_init_sensor1);
460 write_vector(gspca_dev, rev72a_init_data2);
461 write_sensor_72a(gspca_dev, rev72a_init_sensor2);
Jean-Francois Moine0dbc2c12009-01-16 16:24:28 -0300462 reg_w_val(gspca_dev->dev, 0x8112, 0x30);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300463 return 0;
464}
465
Jean-Francois Moine5b7ed282008-12-18 12:38:15 -0300466/* rev 72a only */
Hans Verkuil3fa24bf2012-05-16 08:20:44 -0300467static void setbrightness(struct gspca_dev *gspca_dev, s32 val)
468{
469 struct usb_device *dev = gspca_dev->dev;
470
471 /* offsets for white balance */
472 reg_w_val(dev, 0x8611, val); /* R */
473 reg_w_val(dev, 0x8612, val); /* Gr */
474 reg_w_val(dev, 0x8613, val); /* B */
475 reg_w_val(dev, 0x8614, val); /* Gb */
476}
477
478static void setwhite(struct gspca_dev *gspca_dev, s32 white, s32 contrast)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300479{
480 struct sd *sd = (struct sd *) gspca_dev;
481 struct usb_device *dev = gspca_dev->dev;
Jean-Francois Moine5b7ed282008-12-18 12:38:15 -0300482 __u8 blue, red;
483 __u16 reg;
Jean-Francois Moine6c9d3c52008-09-03 16:47:30 -0300484
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300485 /* try to emulate MS-win as possible */
Jean-Francois Moine5b7ed282008-12-18 12:38:15 -0300486 red = 0x20 + white * 3 / 8;
487 blue = 0x90 - white * 5 / 8;
488 if (sd->chip_revision == Rev012A) {
489 reg = 0x8614;
490 } else {
491 reg = 0x8651;
Hans Verkuil3fa24bf2012-05-16 08:20:44 -0300492 red += contrast - 0x20;
493 blue += contrast - 0x20;
494 reg_w_val(dev, 0x8652, contrast + 0x20); /* Gr */
495 reg_w_val(dev, 0x8654, contrast + 0x20); /* Gb */
Jean-Francois Moine5b7ed282008-12-18 12:38:15 -0300496 }
Hans Verkuil3fa24bf2012-05-16 08:20:44 -0300497 reg_w_val(dev, reg, red);
498 reg_w_val(dev, reg + 2, blue);
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300499}
500
501/* rev 12a only */
Hans Verkuil3fa24bf2012-05-16 08:20:44 -0300502static void setexposure(struct gspca_dev *gspca_dev, s32 val)
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300503{
Hans de Goeded0848eb2009-05-25 15:20:16 -0300504 int i, expo = 0;
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300505
Hans de Goede0fc23d22008-09-04 16:22:57 -0300506 /* Register 0x8309 controls exposure for the spca561,
507 the basic exposure setting goes from 1-2047, where 1 is completely
508 dark and 2047 is very bright. It not only influences exposure but
509 also the framerate (to allow for longer exposure) from 1 - 300 it
510 only raises the exposure time then from 300 - 600 it halves the
511 framerate to be able to further raise the exposure time and for every
512 300 more it halves the framerate again. This allows for a maximum
513 exposure time of circa 0.2 - 0.25 seconds (30 / (2000/3000) fps).
514 Sometimes this is not enough, the 1-2047 uses bits 0-10, bits 11-12
515 configure a divider for the base framerate which us used at the
516 exposure setting of 1-300. These bits configure the base framerate
517 according to the following formula: fps = 60 / (value + 2) */
Hans de Goeded0848eb2009-05-25 15:20:16 -0300518
519 /* We choose to use the high bits setting the fixed framerate divisor
520 asap, as setting high basic exposure setting without the fixed
521 divider in combination with high gains makes the cam stop */
522 int table[] = { 0, 450, 550, 625, EXPOSURE_MAX };
523
524 for (i = 0; i < ARRAY_SIZE(table) - 1; i++) {
Hans Verkuil3fa24bf2012-05-16 08:20:44 -0300525 if (val <= table[i + 1]) {
526 expo = val - table[i];
Hans de Goeded0848eb2009-05-25 15:20:16 -0300527 if (i)
528 expo += 300;
529 expo |= i << 11;
530 break;
531 }
Hans de Goede0fc23d22008-09-04 16:22:57 -0300532 }
Hans de Goeded0848eb2009-05-25 15:20:16 -0300533
Jean-Francois Moine35dc1b42008-12-17 14:34:53 -0300534 gspca_dev->usb_buf[0] = expo;
535 gspca_dev->usb_buf[1] = expo >> 8;
536 reg_w_buf(gspca_dev, 0x8309, 2);
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300537}
538
539/* rev 12a only */
Hans Verkuil3fa24bf2012-05-16 08:20:44 -0300540static void setgain(struct gspca_dev *gspca_dev, s32 val)
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300541{
Hans de Goeded0848eb2009-05-25 15:20:16 -0300542 /* gain reg low 6 bits 0-63 gain, bit 6 and 7, both double the
543 sensitivity when set, so 31 + one of them set == 63, and 15
544 with both of them set == 63 */
Hans Verkuil3fa24bf2012-05-16 08:20:44 -0300545 if (val < 64)
546 gspca_dev->usb_buf[0] = val;
547 else if (val < 128)
548 gspca_dev->usb_buf[0] = (val / 2) | 0x40;
Hans de Goeded0848eb2009-05-25 15:20:16 -0300549 else
Hans Verkuil3fa24bf2012-05-16 08:20:44 -0300550 gspca_dev->usb_buf[0] = (val / 4) | 0xc0;
Hans de Goeded0848eb2009-05-25 15:20:16 -0300551
Jean-Francois Moine35dc1b42008-12-17 14:34:53 -0300552 gspca_dev->usb_buf[1] = 0;
553 reg_w_buf(gspca_dev, 0x8335, 2);
Jean-Francois Moine6c9d3c52008-09-03 16:47:30 -0300554}
555
Hans Verkuil3fa24bf2012-05-16 08:20:44 -0300556static void setautogain(struct gspca_dev *gspca_dev, s32 val)
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -0300557{
558 struct sd *sd = (struct sd *) gspca_dev;
559
Hans Verkuil3fa24bf2012-05-16 08:20:44 -0300560 if (val)
Jean-Francois Moined698dc62008-09-03 16:47:51 -0300561 sd->ag_cnt = AG_CNT_START;
562 else
563 sd->ag_cnt = -1;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -0300564}
565
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -0300566static int sd_start_12a(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300567{
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300568 struct usb_device *dev = gspca_dev->dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300569 int mode;
Jean-Francois Moine5b7ed282008-12-18 12:38:15 -0300570 static const __u8 Reg8391[8] =
571 {0x92, 0x30, 0x20, 0x00, 0x0c, 0x00, 0x00, 0x00};
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300572
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300573 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300574 if (mode <= 1) {
575 /* Use compression on 320x240 and above */
576 reg_w_val(dev, 0x8500, 0x10 | mode);
577 } else {
578 /* I couldn't get the compression to work below 320x240
579 * Fortunately at these resolutions the bandwidth
580 * is sufficient to push raw frames at ~20fps */
581 reg_w_val(dev, 0x8500, mode);
582 } /* -- qq@kuku.eu.org */
Jean-Francois Moine35dc1b42008-12-17 14:34:53 -0300583
Jean-Francois Moine5b7ed282008-12-18 12:38:15 -0300584 gspca_dev->usb_buf[0] = 0xaa;
585 gspca_dev->usb_buf[1] = 0x00;
586 reg_w_buf(gspca_dev, 0x8307, 2);
587 /* clock - lower 0x8X values lead to fps > 30 */
588 reg_w_val(gspca_dev->dev, 0x8700, 0x8a);
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300589 /* 0x8f 0x85 0x27 clock */
590 reg_w_val(gspca_dev->dev, 0x8112, 0x1e | 0x20);
591 reg_w_val(gspca_dev->dev, 0x850b, 0x03);
Jean-Francois Moine5b7ed282008-12-18 12:38:15 -0300592 memcpy(gspca_dev->usb_buf, Reg8391, 8);
593 reg_w_buf(gspca_dev, 0x8391, 8);
594 reg_w_buf(gspca_dev, 0x8390, 8);
Hans de Goede6b33e5e2010-02-27 07:18:14 -0300595
596 /* Led ON (bit 3 -> 0 */
597 reg_w_val(gspca_dev->dev, 0x8114, 0x00);
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -0300598 return 0;
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300599}
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -0300600static int sd_start_72a(struct gspca_dev *gspca_dev)
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300601{
Hans Verkuil3fa24bf2012-05-16 08:20:44 -0300602 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300603 struct usb_device *dev = gspca_dev->dev;
604 int Clck;
605 int mode;
606
Jean-Francois Moine0dbc2c12009-01-16 16:24:28 -0300607 write_vector(gspca_dev, rev72a_reset);
608 msleep(200);
609 write_vector(gspca_dev, rev72a_init_data1);
610 write_sensor_72a(gspca_dev, rev72a_init_sensor1);
611
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300612 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
613 switch (mode) {
614 default:
Jean-Francois Moinea48196a2009-01-18 14:24:52 -0300615 case 0:
616 Clck = 0x27; /* ms-win 0x87 */
617 break;
618 case 1:
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300619 Clck = 0x25;
620 break;
621 case 2:
622 Clck = 0x22;
623 break;
624 case 3:
625 Clck = 0x21;
626 break;
627 }
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300628 reg_w_val(dev, 0x8700, Clck); /* 0x27 clock */
Jean-Francois Moinea48196a2009-01-18 14:24:52 -0300629 reg_w_val(dev, 0x8702, 0x81);
630 reg_w_val(dev, 0x8500, mode); /* mode */
Jean-Francois Moine0dbc2c12009-01-16 16:24:28 -0300631 write_sensor_72a(gspca_dev, rev72a_init_sensor2);
Hans Verkuil3fa24bf2012-05-16 08:20:44 -0300632 setwhite(gspca_dev, v4l2_ctrl_g_ctrl(sd->hue),
633 v4l2_ctrl_g_ctrl(sd->contrast));
Jean-Francois Moine5b7ed282008-12-18 12:38:15 -0300634/* setbrightness(gspca_dev); * fixme: bad values */
Hans Verkuil3fa24bf2012-05-16 08:20:44 -0300635 setautogain(gspca_dev, v4l2_ctrl_g_ctrl(sd->autogain));
Jean-Francois Moine0dbc2c12009-01-16 16:24:28 -0300636 reg_w_val(dev, 0x8112, 0x10 | 0x20);
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -0300637 return 0;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300638}
639
640static void sd_stopN(struct gspca_dev *gspca_dev)
641{
Jean-Francois Moined698dc62008-09-03 16:47:51 -0300642 struct sd *sd = (struct sd *) gspca_dev;
643
644 if (sd->chip_revision == Rev012A) {
645 reg_w_val(gspca_dev->dev, 0x8112, 0x0e);
Hans de Goede6b33e5e2010-02-27 07:18:14 -0300646 /* Led Off (bit 3 -> 1 */
647 reg_w_val(gspca_dev->dev, 0x8114, 0x08);
Jean-Francois Moined698dc62008-09-03 16:47:51 -0300648 } else {
649 reg_w_val(gspca_dev->dev, 0x8112, 0x20);
650/* reg_w_val(gspca_dev->dev, 0x8102, 0x00); ?? */
651 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300652}
653
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -0300654static void do_autogain(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300655{
656 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -0300657 int expotimes;
658 int pixelclk;
659 int gainG;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300660 __u8 R, Gr, Gb, B;
661 int y;
662 __u8 luma_mean = 110;
663 __u8 luma_delta = 20;
664 __u8 spring = 4;
665
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -0300666 if (sd->ag_cnt < 0)
667 return;
668 if (--sd->ag_cnt >= 0)
669 return;
670 sd->ag_cnt = AG_CNT_START;
671
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300672 switch (sd->chip_revision) {
673 case Rev072A:
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300674 reg_r(gspca_dev, 0x8621, 1);
675 Gr = gspca_dev->usb_buf[0];
676 reg_r(gspca_dev, 0x8622, 1);
677 R = gspca_dev->usb_buf[0];
678 reg_r(gspca_dev, 0x8623, 1);
679 B = gspca_dev->usb_buf[0];
680 reg_r(gspca_dev, 0x8624, 1);
681 Gb = gspca_dev->usb_buf[0];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300682 y = (77 * R + 75 * (Gr + Gb) + 29 * B) >> 8;
683 /* u= (128*B-(43*(Gr+Gb+R))) >> 8; */
684 /* v= (128*R-(53*(Gr+Gb))-21*B) >> 8; */
685 /* PDEBUG(D_CONF,"reading Y %d U %d V %d ",y,u,v); */
686
687 if (y < luma_mean - luma_delta ||
688 y > luma_mean + luma_delta) {
689 expotimes = i2c_read(gspca_dev, 0x09, 0x10);
690 pixelclk = 0x0800;
691 expotimes = expotimes & 0x07ff;
692 /* PDEBUG(D_PACK,
693 "Exposition Times 0x%03X Clock 0x%04X ",
694 expotimes,pixelclk); */
695 gainG = i2c_read(gspca_dev, 0x35, 0x10);
696 /* PDEBUG(D_PACK,
697 "reading Gain register %d", gainG); */
698
699 expotimes += (luma_mean - y) >> spring;
700 gainG += (luma_mean - y) / 50;
701 /* PDEBUG(D_PACK,
702 "compute expotimes %d gain %d",
703 expotimes,gainG); */
704
705 if (gainG > 0x3f)
706 gainG = 0x3f;
Jean-Francois Moine35dc1b42008-12-17 14:34:53 -0300707 else if (gainG < 3)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300708 gainG = 3;
709 i2c_write(gspca_dev, gainG, 0x35);
710
Jean-Francois Moine35dc1b42008-12-17 14:34:53 -0300711 if (expotimes > 0x0256)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300712 expotimes = 0x0256;
Jean-Francois Moine35dc1b42008-12-17 14:34:53 -0300713 else if (expotimes < 3)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300714 expotimes = 3;
715 i2c_write(gspca_dev, expotimes | pixelclk, 0x09);
716 }
717 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300718 }
719}
720
721static void sd_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine76dd2722009-11-13 09:21:03 -0300722 u8 *data, /* isoc packet */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300723 int len) /* iso packet length */
724{
Hans de Goede0fc23d22008-09-04 16:22:57 -0300725 struct sd *sd = (struct sd *) gspca_dev;
726
Jean-Francois Moine576ed7b2009-01-16 08:57:28 -0300727 len--;
728 switch (*data++) { /* sequence number */
Jean-Francois Moine35dc1b42008-12-17 14:34:53 -0300729 case 0: /* start of frame */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -0300730 gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
Hans de Goede436c2c52010-02-28 09:41:04 -0300731
732 /* This should never happen */
733 if (len < 2) {
734 PDEBUG(D_ERR, "Short SOF packet, ignoring");
735 gspca_dev->last_packet_type = DISCARD_PACKET;
736 return;
737 }
738
Jean-François Moine28566432010-10-01 07:33:26 -0300739#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
Hans de Goede436c2c52010-02-28 09:41:04 -0300740 if (data[0] & 0x20) {
741 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1);
742 input_sync(gspca_dev->input_dev);
743 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
744 input_sync(gspca_dev->input_dev);
745 }
746#endif
747
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300748 if (data[1] & 0x10) {
749 /* compressed bayer */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -0300750 gspca_frame_add(gspca_dev, FIRST_PACKET, data, len);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300751 } else {
Hans de Goede54ab92c2008-07-03 11:20:58 -0300752 /* raw bayer (with a header, which we skip) */
Hans de Goede0fc23d22008-09-04 16:22:57 -0300753 if (sd->chip_revision == Rev012A) {
754 data += 20;
755 len -= 20;
756 } else {
757 data += 16;
758 len -= 16;
759 }
Jean-Francois Moine76dd2722009-11-13 09:21:03 -0300760 gspca_frame_add(gspca_dev, FIRST_PACKET, data, len);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300761 }
762 return;
Jean-Francois Moine35dc1b42008-12-17 14:34:53 -0300763 case 0xff: /* drop (empty mpackets) */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300764 return;
765 }
Jean-Francois Moine76dd2722009-11-13 09:21:03 -0300766 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300767}
768
Hans Verkuil3fa24bf2012-05-16 08:20:44 -0300769static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300770{
Hans Verkuil3fa24bf2012-05-16 08:20:44 -0300771 struct gspca_dev *gspca_dev =
772 container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
773 struct sd *sd = (struct sd *)gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300774
Hans Verkuil3fa24bf2012-05-16 08:20:44 -0300775 gspca_dev->usb_err = 0;
776
777 if (!gspca_dev->streaming)
778 return 0;
779
780 switch (ctrl->id) {
781 case V4L2_CID_BRIGHTNESS:
782 setbrightness(gspca_dev, ctrl->val);
783 break;
784 case V4L2_CID_CONTRAST:
785 /* hue/contrast control cluster for 72a */
786 setwhite(gspca_dev, sd->hue->val, ctrl->val);
787 break;
788 case V4L2_CID_HUE:
789 /* just plain hue control for 12a */
790 setwhite(gspca_dev, ctrl->val, 0);
791 break;
792 case V4L2_CID_EXPOSURE:
793 setexposure(gspca_dev, ctrl->val);
794 break;
795 case V4L2_CID_GAIN:
796 setgain(gspca_dev, ctrl->val);
797 break;
798 case V4L2_CID_AUTOGAIN:
799 setautogain(gspca_dev, ctrl->val);
800 break;
801 }
802 return gspca_dev->usb_err;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300803}
804
Hans Verkuil3fa24bf2012-05-16 08:20:44 -0300805static const struct v4l2_ctrl_ops sd_ctrl_ops = {
806 .s_ctrl = sd_s_ctrl,
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300807};
808
Hans Verkuil3fa24bf2012-05-16 08:20:44 -0300809static int sd_init_controls_12a(struct gspca_dev *gspca_dev)
810{
811 struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
812
813 gspca_dev->vdev.ctrl_handler = hdl;
814 v4l2_ctrl_handler_init(hdl, 3);
815 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
816 V4L2_CID_HUE, 1, 0x7f, 1, 0x40);
817 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
818 V4L2_CID_EXPOSURE, 1, EXPOSURE_MAX, 1, 700);
819 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
820 V4L2_CID_GAIN, 0, 255, 1, 63);
821
822 if (hdl->error) {
823 pr_err("Could not initialize controls\n");
824 return hdl->error;
825 }
826 return 0;
827}
828
829static int sd_init_controls_72a(struct gspca_dev *gspca_dev)
830{
831 struct sd *sd = (struct sd *)gspca_dev;
832 struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
833
834 gspca_dev->vdev.ctrl_handler = hdl;
835 v4l2_ctrl_handler_init(hdl, 4);
836 sd->contrast = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
837 V4L2_CID_CONTRAST, 0, 0x3f, 1, 0x20);
838 sd->hue = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
839 V4L2_CID_HUE, 1, 0x7f, 1, 0x40);
840 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
841 V4L2_CID_BRIGHTNESS, 0, 0x3f, 1, 0x20);
842 sd->autogain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
843 V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
844
845 if (hdl->error) {
846 pr_err("Could not initialize controls\n");
847 return hdl->error;
848 }
849 v4l2_ctrl_cluster(2, &sd->contrast);
850 return 0;
851}
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300852
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300853/* sub-driver description */
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300854static const struct sd_desc sd_desc_12a = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300855 .name = MODULE_NAME,
Hans Verkuil3fa24bf2012-05-16 08:20:44 -0300856 .init_controls = sd_init_controls_12a,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300857 .config = sd_config,
Jean-Francois Moine012d6b02008-09-03 17:12:16 -0300858 .init = sd_init_12a,
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300859 .start = sd_start_12a,
860 .stopN = sd_stopN,
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300861 .pkt_scan = sd_pkt_scan,
Jean-François Moine28566432010-10-01 07:33:26 -0300862#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
Hans de Goede436c2c52010-02-28 09:41:04 -0300863 .other_input = 1,
864#endif
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300865};
866static const struct sd_desc sd_desc_72a = {
867 .name = MODULE_NAME,
Hans Verkuil3fa24bf2012-05-16 08:20:44 -0300868 .init_controls = sd_init_controls_72a,
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300869 .config = sd_config,
Jean-Francois Moine012d6b02008-09-03 17:12:16 -0300870 .init = sd_init_72a,
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300871 .start = sd_start_72a,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300872 .stopN = sd_stopN,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300873 .pkt_scan = sd_pkt_scan,
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -0300874 .dq_callback = do_autogain,
Jean-François Moine28566432010-10-01 07:33:26 -0300875#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
Hans de Goede436c2c52010-02-28 09:41:04 -0300876 .other_input = 1,
877#endif
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300878};
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300879static const struct sd_desc *sd_desc[2] = {
880 &sd_desc_12a,
881 &sd_desc_72a
882};
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300883
884/* -- module initialisation -- */
Jean-François Moine95c967c2011-01-13 05:20:29 -0300885static const struct usb_device_id device_table[] = {
Jean-Francois Moine87581aa2008-07-26 14:30:01 -0300886 {USB_DEVICE(0x041e, 0x401a), .driver_info = Rev072A},
887 {USB_DEVICE(0x041e, 0x403b), .driver_info = Rev012A},
888 {USB_DEVICE(0x0458, 0x7004), .driver_info = Rev072A},
John Ellsonf8f73d02010-03-17 10:22:58 -0300889 {USB_DEVICE(0x0461, 0x0815), .driver_info = Rev072A},
Jean-Francois Moine87581aa2008-07-26 14:30:01 -0300890 {USB_DEVICE(0x046d, 0x0928), .driver_info = Rev012A},
891 {USB_DEVICE(0x046d, 0x0929), .driver_info = Rev012A},
892 {USB_DEVICE(0x046d, 0x092a), .driver_info = Rev012A},
893 {USB_DEVICE(0x046d, 0x092b), .driver_info = Rev012A},
894 {USB_DEVICE(0x046d, 0x092c), .driver_info = Rev012A},
895 {USB_DEVICE(0x046d, 0x092d), .driver_info = Rev012A},
896 {USB_DEVICE(0x046d, 0x092e), .driver_info = Rev012A},
897 {USB_DEVICE(0x046d, 0x092f), .driver_info = Rev012A},
898 {USB_DEVICE(0x04fc, 0x0561), .driver_info = Rev072A},
899 {USB_DEVICE(0x060b, 0xa001), .driver_info = Rev072A},
900 {USB_DEVICE(0x10fd, 0x7e50), .driver_info = Rev072A},
901 {USB_DEVICE(0xabcd, 0xcdee), .driver_info = Rev072A},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300902 {}
903};
904
905MODULE_DEVICE_TABLE(usb, device_table);
906
907/* -- device connect -- */
908static int sd_probe(struct usb_interface *intf,
909 const struct usb_device_id *id)
910{
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300911 return gspca_dev_probe(intf, id,
912 sd_desc[id->driver_info],
913 sizeof(struct sd),
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300914 THIS_MODULE);
915}
916
917static struct usb_driver sd_driver = {
918 .name = MODULE_NAME,
919 .id_table = device_table,
920 .probe = sd_probe,
921 .disconnect = gspca_disconnect,
Jean-Francois Moine6a709742008-09-03 16:48:10 -0300922#ifdef CONFIG_PM
923 .suspend = gspca_suspend,
924 .resume = gspca_resume,
Hans de Goede8bb58962012-06-30 06:44:47 -0300925 .reset_resume = gspca_resume,
Jean-Francois Moine6a709742008-09-03 16:48:10 -0300926#endif
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300927};
928
Greg Kroah-Hartmanecb3b2b2011-11-18 09:46:12 -0800929module_usb_driver(sd_driver);