blob: 0a2b8bc5b855b16ffca03d700f07a64ea984b5c4 [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
23#define MODULE_NAME "spca561"
24
25#include "gspca.h"
26
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030027MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
28MODULE_DESCRIPTION("GSPCA/SPCA561 USB Camera Driver");
29MODULE_LICENSE("GPL");
30
31/* specific webcam descriptor */
32struct sd {
33 struct gspca_dev gspca_dev; /* !! must be the first item */
34
Jean-Francois Moine7879d452008-09-03 16:47:32 -030035 __u16 contrast; /* rev72a only */
36#define CONTRAST_MIN 0x0000
37#define CONTRAST_DEF 0x2000
38#define CONTRAST_MAX 0x3fff
39
40 __u16 exposure; /* rev12a only */
41#define EXPOSURE_MIN 0x0120
42#define EXPOSURE_DEF 0x20ae
43#define EXPOSURE_MAX 0x5720
44
45 __u8 brightness; /* rev72a only */
46#define BRIGHTNESS_MIN 0
47#define BRIGHTNESS_DEF 32
48#define BRIGHTNESS_MAX 63
49
50 __u8 white; /* rev12a only */
51#define WHITE_MIN 0
52#define WHITE_DEF 0x40
53#define WHITE_MAX 0x7f
54
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030055 __u8 autogain;
Jean-Francois Moine7879d452008-09-03 16:47:32 -030056#define AUTOGAIN_MIN 0
57#define AUTOGAIN_DEF 1
58#define AUTOGAIN_MAX 1
59
60 __u8 gain; /* rev12a only */
61#define GAIN_MIN 0x0
62#define GAIN_DEF 0x24
63#define GAIN_MAX 0x24
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030064
65 __u8 chip_revision;
Jean-Francois Moine7879d452008-09-03 16:47:32 -030066#define Rev012A 0
67#define Rev072A 1
68
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030069 signed char ag_cnt;
70#define AG_CNT_START 13
71};
72
Jean-Francois Moinec2446b32008-07-05 11:49:20 -030073static struct v4l2_pix_format sif_mode[] = {
74 {160, 120, V4L2_PIX_FMT_SGBRG8, V4L2_FIELD_NONE,
75 .bytesperline = 160,
76 .sizeimage = 160 * 120,
77 .colorspace = V4L2_COLORSPACE_SRGB,
78 .priv = 3},
79 {176, 144, V4L2_PIX_FMT_SGBRG8, V4L2_FIELD_NONE,
80 .bytesperline = 176,
81 .sizeimage = 176 * 144,
82 .colorspace = V4L2_COLORSPACE_SRGB,
83 .priv = 2},
84 {320, 240, V4L2_PIX_FMT_SPCA561, V4L2_FIELD_NONE,
85 .bytesperline = 320,
86 .sizeimage = 320 * 240 * 4 / 8,
87 .colorspace = V4L2_COLORSPACE_SRGB,
88 .priv = 1},
89 {352, 288, V4L2_PIX_FMT_SPCA561, V4L2_FIELD_NONE,
90 .bytesperline = 352,
91 .sizeimage = 352 * 288 * 4 / 8,
92 .colorspace = V4L2_COLORSPACE_SRGB,
93 .priv = 0},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030094};
95
96/*
97 * Initialization data
98 * I'm not very sure how to split initialization from open data
99 * chunks. For now, we'll consider everything as initialization
100 */
101/* Frame packet header offsets for the spca561 */
102#define SPCA561_OFFSET_SNAP 1
103#define SPCA561_OFFSET_TYPE 2
104#define SPCA561_OFFSET_COMPRESS 3
105#define SPCA561_OFFSET_FRAMSEQ 4
106#define SPCA561_OFFSET_GPIO 5
107#define SPCA561_OFFSET_USBBUFF 6
108#define SPCA561_OFFSET_WIN2GRAVE 7
109#define SPCA561_OFFSET_WIN2RAVE 8
110#define SPCA561_OFFSET_WIN2BAVE 9
111#define SPCA561_OFFSET_WIN2GBAVE 10
112#define SPCA561_OFFSET_WIN1GRAVE 11
113#define SPCA561_OFFSET_WIN1RAVE 12
114#define SPCA561_OFFSET_WIN1BAVE 13
115#define SPCA561_OFFSET_WIN1GBAVE 14
116#define SPCA561_OFFSET_FREQ 15
117#define SPCA561_OFFSET_VSYNC 16
118#define SPCA561_OFFSET_DATA 1
119#define SPCA561_INDEX_I2C_BASE 0x8800
120#define SPCA561_SNAPBIT 0x20
121#define SPCA561_SNAPCTRL 0x40
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300122
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300123static void reg_w_val(struct usb_device *dev, __u16 index, __u8 value)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300124{
125 int ret;
126
127 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
128 0, /* request */
129 USB_TYPE_VENDOR | USB_RECIP_DEVICE,
130 value, index, NULL, 0, 500);
131 PDEBUG(D_USBO, "reg write: 0x%02x:0x%02x", index, value);
132 if (ret < 0)
133 PDEBUG(D_ERR, "reg write: error %d", ret);
134}
135
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300136static void write_vector(struct gspca_dev *gspca_dev,
137 const __u16 data[][2])
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300138{
139 struct usb_device *dev = gspca_dev->dev;
140 int i;
141
142 i = 0;
143 while (data[i][1] != 0) {
144 reg_w_val(dev, data[i][1], data[i][0]);
145 i++;
146 }
147}
148
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300149/* read 'len' bytes to gspca_dev->usb_buf */
150static void reg_r(struct gspca_dev *gspca_dev,
151 __u16 index, __u16 length)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300152{
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300153 usb_control_msg(gspca_dev->dev,
154 usb_rcvctrlpipe(gspca_dev->dev, 0),
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300155 0, /* request */
156 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
157 0, /* value */
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300158 index, gspca_dev->usb_buf, length, 500);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300159}
160
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300161static void reg_w_buf(struct gspca_dev *gspca_dev,
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300162 __u16 index, const __u8 *buffer, __u16 len)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300163{
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300164 memcpy(gspca_dev->usb_buf, buffer, len);
165 usb_control_msg(gspca_dev->dev,
166 usb_sndctrlpipe(gspca_dev->dev, 0),
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300167 0, /* request */
168 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
169 0, /* value */
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300170 index, gspca_dev->usb_buf, len, 500);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300171}
172
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300173static void i2c_write(struct gspca_dev *gspca_dev, __u16 valeur, __u16 reg)
174{
175 int retry = 60;
176 __u8 DataLow;
177 __u8 DataHight;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300178
179 DataLow = valeur;
180 DataHight = valeur >> 8;
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300181 reg_w_val(gspca_dev->dev, 0x8801, reg);
182 reg_w_val(gspca_dev->dev, 0x8805, DataLow);
183 reg_w_val(gspca_dev->dev, 0x8800, DataHight);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300184 while (retry--) {
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300185 reg_r(gspca_dev, 0x8803, 1);
186 if (!gspca_dev->usb_buf[0])
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300187 break;
188 }
189}
190
191static int i2c_read(struct gspca_dev *gspca_dev, __u16 reg, __u8 mode)
192{
193 int retry = 60;
194 __u8 value;
195 __u8 vallsb;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300196
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300197 reg_w_val(gspca_dev->dev, 0x8804, 0x92);
198 reg_w_val(gspca_dev->dev, 0x8801, reg);
199 reg_w_val(gspca_dev->dev, 0x8802, (mode | 0x01));
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300200 while (retry--) {
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300201 reg_r(gspca_dev, 0x8803, 1);
202 if (!gspca_dev->usb_buf)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300203 break;
204 }
205 if (retry == 0)
206 return -1;
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300207 reg_r(gspca_dev, 0x8800, 1);
208 value = gspca_dev->usb_buf[0];
209 reg_r(gspca_dev, 0x8805, 1);
210 vallsb = gspca_dev->usb_buf[0];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300211 return ((int) value << 8) | vallsb;
212}
213
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300214static const __u16 spca561_init_data[][2] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300215 {0x0000, 0x8114}, /* Software GPIO output data */
216 {0x0001, 0x8114}, /* Software GPIO output data */
217 {0x0000, 0x8112}, /* Some kind of reset */
218 {0x0003, 0x8701}, /* PCLK clock delay adjustment */
219 {0x0001, 0x8703}, /* HSYNC from cmos inverted */
220 {0x0011, 0x8118}, /* Enable and conf sensor */
221 {0x0001, 0x8118}, /* Conf sensor */
222 {0x0092, 0x8804}, /* I know nothing about these */
223 {0x0010, 0x8802}, /* 0x88xx registers, so I won't */
224 /***************/
225 {0x000d, 0x8805}, /* sensor default setting */
226 {0x0001, 0x8801}, /* 1 <- 0x0d */
227 {0x0000, 0x8800},
228 {0x0018, 0x8805},
229 {0x0002, 0x8801}, /* 2 <- 0x18 */
230 {0x0000, 0x8800},
231 {0x0065, 0x8805},
232 {0x0004, 0x8801}, /* 4 <- 0x01 0x65 */
233 {0x0001, 0x8800},
234 {0x0021, 0x8805},
235 {0x0005, 0x8801}, /* 5 <- 0x21 */
236 {0x0000, 0x8800},
237 {0x00aa, 0x8805},
238 {0x0007, 0x8801}, /* 7 <- 0xaa */
239 {0x0000, 0x8800},
240 {0x0004, 0x8805},
241 {0x0020, 0x8801}, /* 0x20 <- 0x15 0x04 */
242 {0x0015, 0x8800},
243 {0x0002, 0x8805},
244 {0x0039, 0x8801}, /* 0x39 <- 0x02 */
245 {0x0000, 0x8800},
246 {0x0010, 0x8805},
247 {0x0035, 0x8801}, /* 0x35 <- 0x10 */
248 {0x0000, 0x8800},
249 {0x0049, 0x8805},
250 {0x0009, 0x8801}, /* 0x09 <- 0x10 0x49 */
251 {0x0010, 0x8800},
252 {0x000b, 0x8805},
253 {0x0028, 0x8801}, /* 0x28 <- 0x0b */
254 {0x0000, 0x8800},
255 {0x000f, 0x8805},
256 {0x003b, 0x8801}, /* 0x3b <- 0x0f */
257 {0x0000, 0x8800},
258 {0x0000, 0x8805},
259 {0x003c, 0x8801}, /* 0x3c <- 0x00 */
260 {0x0000, 0x8800},
261 /***************/
262 {0x0018, 0x8601}, /* Pixel/line selection for color separation */
263 {0x0000, 0x8602}, /* Optical black level for user setting */
264 {0x0060, 0x8604}, /* Optical black horizontal offset */
265 {0x0002, 0x8605}, /* Optical black vertical offset */
266 {0x0000, 0x8603}, /* Non-automatic optical black level */
267 {0x0002, 0x865b}, /* Horizontal offset for valid pixels */
268 {0x0000, 0x865f}, /* Vertical valid pixels window (x2) */
269 {0x00b0, 0x865d}, /* Horizontal valid pixels window (x2) */
270 {0x0090, 0x865e}, /* Vertical valid lines window (x2) */
271 {0x00e0, 0x8406}, /* Memory buffer threshold */
272 {0x0000, 0x8660}, /* Compensation memory stuff */
273 {0x0002, 0x8201}, /* Output address for r/w serial EEPROM */
274 {0x0008, 0x8200}, /* Clear valid bit for serial EEPROM */
275 {0x0001, 0x8200}, /* OprMode to be executed by hardware */
276 {0x0007, 0x8201}, /* Output address for r/w serial EEPROM */
277 {0x0008, 0x8200}, /* Clear valid bit for serial EEPROM */
278 {0x0001, 0x8200}, /* OprMode to be executed by hardware */
279 {0x0010, 0x8660}, /* Compensation memory stuff */
280 {0x0018, 0x8660}, /* Compensation memory stuff */
281
282 {0x0004, 0x8611}, /* R offset for white balance */
283 {0x0004, 0x8612}, /* Gr offset for white balance */
284 {0x0007, 0x8613}, /* B offset for white balance */
285 {0x0000, 0x8614}, /* Gb offset for white balance */
286 {0x008c, 0x8651}, /* R gain for white balance */
287 {0x008c, 0x8652}, /* Gr gain for white balance */
288 {0x00b5, 0x8653}, /* B gain for white balance */
289 {0x008c, 0x8654}, /* Gb gain for white balance */
290 {0x0002, 0x8502}, /* Maximum average bit rate stuff */
291
292 {0x0011, 0x8802},
293 {0x0087, 0x8700}, /* Set master clock (96Mhz????) */
294 {0x0081, 0x8702}, /* Master clock output enable */
295
296 {0x0000, 0x8500}, /* Set image type (352x288 no compression) */
297 /* Originally was 0x0010 (352x288 compression) */
298
299 {0x0002, 0x865b}, /* Horizontal offset for valid pixels */
300 {0x0003, 0x865c}, /* Vertical offset for valid lines */
301 /***************//* sensor active */
302 {0x0003, 0x8801}, /* 0x03 <- 0x01 0x21 //289 */
303 {0x0021, 0x8805},
304 {0x0001, 0x8800},
305 {0x0004, 0x8801}, /* 0x04 <- 0x01 0x65 //357 */
306 {0x0065, 0x8805},
307 {0x0001, 0x8800},
308 {0x0005, 0x8801}, /* 0x05 <- 0x2f */
309 {0x002f, 0x8805},
310 {0x0000, 0x8800},
311 {0x0006, 0x8801}, /* 0x06 <- 0 */
312 {0x0000, 0x8805},
313 {0x0000, 0x8800},
314 {0x000a, 0x8801}, /* 0x0a <- 2 */
315 {0x0002, 0x8805},
316 {0x0000, 0x8800},
317 {0x0009, 0x8801}, /* 0x09 <- 0x1061 */
318 {0x0061, 0x8805},
319 {0x0010, 0x8800},
320 {0x0035, 0x8801}, /* 0x35 <-0x14 */
321 {0x0014, 0x8805},
322 {0x0000, 0x8800},
323 {0x0030, 0x8112}, /* ISO and drop packet enable */
324 {0x0000, 0x8112}, /* Some kind of reset ???? */
325 {0x0009, 0x8118}, /* Enable sensor and set standby */
326 {0x0000, 0x8114}, /* Software GPIO output data */
327 {0x0000, 0x8114}, /* Software GPIO output data */
328 {0x0001, 0x8114}, /* Software GPIO output data */
329 {0x0000, 0x8112}, /* Some kind of reset ??? */
330 {0x0003, 0x8701},
331 {0x0001, 0x8703},
332 {0x0011, 0x8118},
333 {0x0001, 0x8118},
334 /***************/
335 {0x0092, 0x8804},
336 {0x0010, 0x8802},
337 {0x000d, 0x8805},
338 {0x0001, 0x8801},
339 {0x0000, 0x8800},
340 {0x0018, 0x8805},
341 {0x0002, 0x8801},
342 {0x0000, 0x8800},
343 {0x0065, 0x8805},
344 {0x0004, 0x8801},
345 {0x0001, 0x8800},
346 {0x0021, 0x8805},
347 {0x0005, 0x8801},
348 {0x0000, 0x8800},
349 {0x00aa, 0x8805},
350 {0x0007, 0x8801}, /* mode 0xaa */
351 {0x0000, 0x8800},
352 {0x0004, 0x8805},
353 {0x0020, 0x8801},
354 {0x0015, 0x8800}, /* mode 0x0415 */
355 {0x0002, 0x8805},
356 {0x0039, 0x8801},
357 {0x0000, 0x8800},
358 {0x0010, 0x8805},
359 {0x0035, 0x8801},
360 {0x0000, 0x8800},
361 {0x0049, 0x8805},
362 {0x0009, 0x8801},
363 {0x0010, 0x8800},
364 {0x000b, 0x8805},
365 {0x0028, 0x8801},
366 {0x0000, 0x8800},
367 {0x000f, 0x8805},
368 {0x003b, 0x8801},
369 {0x0000, 0x8800},
370 {0x0000, 0x8805},
371 {0x003c, 0x8801},
372 {0x0000, 0x8800},
373 {0x0002, 0x8502},
374 {0x0039, 0x8801},
375 {0x0000, 0x8805},
376 {0x0000, 0x8800},
377
378 {0x0087, 0x8700}, /* overwrite by start */
379 {0x0081, 0x8702},
380 {0x0000, 0x8500},
381/* {0x0010, 0x8500}, -- Previous line was this */
382 {0x0002, 0x865b},
383 {0x0003, 0x865c},
384 /***************/
385 {0x0003, 0x8801}, /* 0x121-> 289 */
386 {0x0021, 0x8805},
387 {0x0001, 0x8800},
388 {0x0004, 0x8801}, /* 0x165 -> 357 */
389 {0x0065, 0x8805},
390 {0x0001, 0x8800},
391 {0x0005, 0x8801}, /* 0x2f //blanking control colonne */
392 {0x002f, 0x8805},
393 {0x0000, 0x8800},
394 {0x0006, 0x8801}, /* 0x00 //blanking mode row */
395 {0x0000, 0x8805},
396 {0x0000, 0x8800},
397 {0x000a, 0x8801}, /* 0x01 //0x02 */
398 {0x0001, 0x8805},
399 {0x0000, 0x8800},
400 {0x0009, 0x8801}, /* 0x1061 - setexposure times && pixel clock
401 * 0001 0 | 000 0110 0001 */
402 {0x0061, 0x8805}, /* 61 31 */
403 {0x0008, 0x8800}, /* 08 */
404 {0x0035, 0x8801}, /* 0x14 - set gain general */
405 {0x001f, 0x8805}, /* 0x14 */
406 {0x0000, 0x8800},
Jean-Francois Moine6c9d3c52008-09-03 16:47:30 -0300407 {0x000e, 0x8112}, /* white balance - was 30 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300408 {}
409};
410
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300411
412/******************** QC Express etch2 stuff ********************/
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300413static const __u16 Pb100_1map8300[][2] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300414 /* reg, value */
415 {0x8320, 0x3304},
416
417 {0x8303, 0x0125}, /* image area */
418 {0x8304, 0x0169},
419 {0x8328, 0x000b},
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300420 {0x833c, 0x0001}, /*fixme: win:07*/
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300421
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300422 {0x832f, 0x1904}, /*fixme: was 0419*/
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300423 {0x8307, 0x00aa},
424 {0x8301, 0x0003},
425 {0x8302, 0x000e},
426 {}
427};
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300428static const __u16 Pb100_2map8300[][2] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300429 /* reg, value */
430 {0x8339, 0x0000},
431 {0x8307, 0x00aa},
432 {}
433};
434
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300435static const __u16 spca561_161rev12A_data1[][2] = {
Jean-Francois Moine6c9d3c52008-09-03 16:47:30 -0300436 {0x29, 0x8118}, /* white balance - was 21 */
437 {0x08, 0x8114}, /* white balance - was 01 */
438 {0x0e, 0x8112}, /* white balance - was 00 */
439 {0x00, 0x8102}, /* white balance - new */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300440 {0x92, 0x8804},
441 {0x04, 0x8802}, /* windows uses 08 */
442 {}
443};
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300444static const __u16 spca561_161rev12A_data2[][2] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300445 {0x21, 0x8118},
446 {0x10, 0x8500},
447 {0x07, 0x8601},
448 {0x07, 0x8602},
449 {0x04, 0x8501},
450 {0x21, 0x8118},
451
452 {0x07, 0x8201}, /* windows uses 02 */
453 {0x08, 0x8200},
454 {0x01, 0x8200},
455
456 {0x00, 0x8114},
457 {0x01, 0x8114}, /* windows uses 00 */
458
459 {0x90, 0x8604},
460 {0x00, 0x8605},
461 {0xb0, 0x8603},
462
463 /* sensor gains */
Jean-Francois Moine6c9d3c52008-09-03 16:47:30 -0300464 {0x07, 0x8601}, /* white balance - new */
465 {0x07, 0x8602}, /* white balance - new */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300466 {0x00, 0x8610}, /* *red */
467 {0x00, 0x8611}, /* 3f *green */
468 {0x00, 0x8612}, /* green *blue */
469 {0x00, 0x8613}, /* blue *green */
Jean-Francois Moine6c9d3c52008-09-03 16:47:30 -0300470 {0x43, 0x8614}, /* green *red - white balance - was 0x35 */
471 {0x40, 0x8615}, /* 40 *green - white balance - was 0x35 */
472 {0x71, 0x8616}, /* 7a *blue - white balance - was 0x35 */
473 {0x40, 0x8617}, /* 40 *green - white balance - was 0x35 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300474
475 {0x0c, 0x8620}, /* 0c */
476 {0xc8, 0x8631}, /* c8 */
477 {0xc8, 0x8634}, /* c8 */
478 {0x23, 0x8635}, /* 23 */
479 {0x1f, 0x8636}, /* 1f */
480 {0xdd, 0x8637}, /* dd */
481 {0xe1, 0x8638}, /* e1 */
482 {0x1d, 0x8639}, /* 1d */
483 {0x21, 0x863a}, /* 21 */
484 {0xe3, 0x863b}, /* e3 */
485 {0xdf, 0x863c}, /* df */
486 {0xf0, 0x8505},
487 {0x32, 0x850a},
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300488/* {0x99, 0x8700}, * - white balance - new (removed) */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300489 {}
490};
491
492static void sensor_mapwrite(struct gspca_dev *gspca_dev,
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300493 const __u16 sensormap[][2])
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300494{
495 int i = 0;
496 __u8 usbval[2];
497
498 while (sensormap[i][0]) {
499 usbval[0] = sensormap[i][1];
500 usbval[1] = sensormap[i][1] >> 8;
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300501 reg_w_buf(gspca_dev, sensormap[i][0], usbval, 2);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300502 i++;
503 }
504}
505static void init_161rev12A(struct gspca_dev *gspca_dev)
506{
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300507/* sensor_reset(gspca_dev); (not in win) */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300508 write_vector(gspca_dev, spca561_161rev12A_data1);
509 sensor_mapwrite(gspca_dev, Pb100_1map8300);
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300510/*fixme: should be in sd_start*/
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300511 write_vector(gspca_dev, spca561_161rev12A_data2);
512 sensor_mapwrite(gspca_dev, Pb100_2map8300);
513}
514
515/* this function is called at probe time */
516static int sd_config(struct gspca_dev *gspca_dev,
517 const struct usb_device_id *id)
518{
519 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300520 struct cam *cam;
521 __u16 vendor, product;
522 __u8 data1, data2;
523
524 /* Read frm global register the USB product and vendor IDs, just to
525 * prove that we can communicate with the device. This works, which
526 * confirms at we are communicating properly and that the device
527 * is a 561. */
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300528 reg_r(gspca_dev, 0x8104, 1);
529 data1 = gspca_dev->usb_buf[0];
530 reg_r(gspca_dev, 0x8105, 1);
531 data2 = gspca_dev->usb_buf[0];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300532 vendor = (data2 << 8) | data1;
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300533 reg_r(gspca_dev, 0x8106, 1);
534 data1 = gspca_dev->usb_buf[0];
535 reg_r(gspca_dev, 0x8107, 1);
536 data2 = gspca_dev->usb_buf[0];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300537 product = (data2 << 8) | data1;
538 if (vendor != id->idVendor || product != id->idProduct) {
539 PDEBUG(D_PROBE, "Bad vendor / product from device");
540 return -EINVAL;
541 }
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -0300542
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300543 cam = &gspca_dev->cam;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300544 cam->epaddr = 0x01;
545 gspca_dev->nbalt = 7 + 1; /* choose alternate 7 first */
546 cam->cam_mode = sif_mode;
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300547 cam->nmodes = ARRAY_SIZE(sif_mode);
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -0300548
549 sd->chip_revision = id->driver_info;
Jean-Francois Moine6c9d3c52008-09-03 16:47:30 -0300550 sd->brightness = BRIGHTNESS_DEF;
551 sd->contrast = CONTRAST_DEF;
Jean-Francois Moine6c9d3c52008-09-03 16:47:30 -0300552 sd->white = WHITE_DEF;
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300553 sd->exposure = EXPOSURE_DEF;
554 sd->autogain = AUTOGAIN_DEF;
555 sd->gain = GAIN_DEF;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300556 return 0;
557}
558
559/* this function is called at open time */
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300560static int sd_open_12a(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300561{
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300562 PDEBUG(D_STREAM, "Chip revision: 012a");
563 init_161rev12A(gspca_dev);
564 return 0;
565}
566static int sd_open_72a(struct gspca_dev *gspca_dev)
567{
568 PDEBUG(D_STREAM, "Chip revision: 072a");
569 write_vector(gspca_dev, spca561_init_data);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300570 return 0;
571}
572
573static void setcontrast(struct gspca_dev *gspca_dev)
574{
575 struct sd *sd = (struct sd *) gspca_dev;
576 struct usb_device *dev = gspca_dev->dev;
577 __u8 lowb;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300578
579 switch (sd->chip_revision) {
580 case Rev072A:
581 lowb = sd->contrast >> 8;
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300582 reg_w_val(dev, 0x8651, lowb);
583 reg_w_val(dev, 0x8652, lowb);
584 reg_w_val(dev, 0x8653, lowb);
585 reg_w_val(dev, 0x8654, lowb);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300586 break;
Jean-Francois Moine6c9d3c52008-09-03 16:47:30 -0300587 default: {
588/* case Rev012A: { */
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300589 static const __u8 Reg8391[] =
590 { 0x92, 0x30, 0x20, 0x00, 0x0c, 0x00, 0x00, 0x00 };
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300591
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300592 reg_w_buf(gspca_dev, 0x8391, Reg8391, 8);
593 reg_w_buf(gspca_dev, 0x8390, Reg8391, 8);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300594 break;
595 }
596 }
597}
598
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300599/* rev12a only */
Jean-Francois Moine6c9d3c52008-09-03 16:47:30 -0300600static void setwhite(struct gspca_dev *gspca_dev)
601{
602 struct sd *sd = (struct sd *) gspca_dev;
603 __u16 white;
604 __u8 reg8614, reg8616;
605
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300606 white = sd->white;
607 if (sd->white == 0) {
608 PDEBUG(D_CONF, "Discarding null whiteness");
609 return;
Jean-Francois Moine6c9d3c52008-09-03 16:47:30 -0300610 }
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300611 /* try to emulate MS-win as possible */
612 if (white < 0x45)
613 reg8616 = white;
614 else
615 reg8616 = 0x93 + (white >> 2);
616 reg8614 = 0x28 + (white >> 4);
617 reg_w_val(gspca_dev->dev, 0x8616, reg8616);
618 reg_w_val(gspca_dev->dev, 0x8614, reg8614);
619}
620
621/* rev 12a only */
622static void setexposure(struct gspca_dev *gspca_dev)
623{
624 struct sd *sd = (struct sd *) gspca_dev;
625 struct usb_device *dev = gspca_dev->dev;
626
627 reg_w_val(dev, 0x8309, sd->gain);
628}
629
630/* rev 12a only */
631static void setgain(struct gspca_dev *gspca_dev)
632{
633 struct sd *sd = (struct sd *) gspca_dev;
634 struct usb_device *dev = gspca_dev->dev;
635
636 reg_w_val(dev, 0x8335, sd->gain);
Jean-Francois Moine6c9d3c52008-09-03 16:47:30 -0300637}
638
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -0300639static void setautogain(struct gspca_dev *gspca_dev)
640{
641 struct sd *sd = (struct sd *) gspca_dev;
642
643 if (sd->chip_revision == Rev072A) {
644 if (sd->autogain)
645 sd->ag_cnt = AG_CNT_START;
646 else
647 sd->ag_cnt = -1;
648 }
649}
650
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300651static void sd_start_12a(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300652{
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300653 struct usb_device *dev = gspca_dev->dev;
654 int Clck;
655 __u8 Reg8307[] = { 0xaa, 0x00 };
656 int mode;
657
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300658 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300659 switch (mode) {
660 case 0:
661 case 1:
662 Clck = 0x8a;
663 break;
664 case 2:
665 Clck = 0x85;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300666 break;
667 default:
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300668 Clck = 0x83;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300669 break;
670 }
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300671 if (mode <= 1) {
672 /* Use compression on 320x240 and above */
673 reg_w_val(dev, 0x8500, 0x10 | mode);
674 } else {
675 /* I couldn't get the compression to work below 320x240
676 * Fortunately at these resolutions the bandwidth
677 * is sufficient to push raw frames at ~20fps */
678 reg_w_val(dev, 0x8500, mode);
679 } /* -- qq@kuku.eu.org */
680 reg_w_buf(gspca_dev, 0x8307, Reg8307, 2);
681 reg_w_val(gspca_dev->dev, 0x8700, Clck);
682 /* 0x8f 0x85 0x27 clock */
683 reg_w_val(gspca_dev->dev, 0x8112, 0x1e | 0x20);
684 reg_w_val(gspca_dev->dev, 0x850b, 0x03);
685 setcontrast(gspca_dev);
686 setwhite(gspca_dev);
687}
688static void sd_start_72a(struct gspca_dev *gspca_dev)
689{
690 struct usb_device *dev = gspca_dev->dev;
691 int Clck;
692 int mode;
693
694 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
695 switch (mode) {
696 default:
697/* case 0:
698 case 1: */
699 Clck = 0x25;
700 break;
701 case 2:
702 Clck = 0x22;
703 break;
704 case 3:
705 Clck = 0x21;
706 break;
707 }
708 reg_w_val(dev, 0x8500, mode); /* mode */
709 reg_w_val(dev, 0x8700, Clck); /* 0x27 clock */
710 reg_w_val(dev, 0x8112, 0x10 | 0x20);
711 setautogain(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300712}
713
714static void sd_stopN(struct gspca_dev *gspca_dev)
715{
716 reg_w_val(gspca_dev->dev, 0x8112, 0x20);
Jean-Francois Moine6c9d3c52008-09-03 16:47:30 -0300717 reg_w_val(gspca_dev->dev, 0x8102, 0x00); /* white balance - new */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300718}
719
720static void sd_stop0(struct gspca_dev *gspca_dev)
721{
722}
723
724/* this function is called at close time */
725static void sd_close(struct gspca_dev *gspca_dev)
726{
727 reg_w_val(gspca_dev->dev, 0x8114, 0);
728}
729
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300730/* rev72a only */
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -0300731static void do_autogain(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300732{
733 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -0300734 int expotimes;
735 int pixelclk;
736 int gainG;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300737 __u8 R, Gr, Gb, B;
738 int y;
739 __u8 luma_mean = 110;
740 __u8 luma_delta = 20;
741 __u8 spring = 4;
742
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -0300743 if (sd->ag_cnt < 0)
744 return;
745 if (--sd->ag_cnt >= 0)
746 return;
747 sd->ag_cnt = AG_CNT_START;
748
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300749 switch (sd->chip_revision) {
750 case Rev072A:
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300751 reg_r(gspca_dev, 0x8621, 1);
752 Gr = gspca_dev->usb_buf[0];
753 reg_r(gspca_dev, 0x8622, 1);
754 R = gspca_dev->usb_buf[0];
755 reg_r(gspca_dev, 0x8623, 1);
756 B = gspca_dev->usb_buf[0];
757 reg_r(gspca_dev, 0x8624, 1);
758 Gb = gspca_dev->usb_buf[0];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300759 y = (77 * R + 75 * (Gr + Gb) + 29 * B) >> 8;
760 /* u= (128*B-(43*(Gr+Gb+R))) >> 8; */
761 /* v= (128*R-(53*(Gr+Gb))-21*B) >> 8; */
762 /* PDEBUG(D_CONF,"reading Y %d U %d V %d ",y,u,v); */
763
764 if (y < luma_mean - luma_delta ||
765 y > luma_mean + luma_delta) {
766 expotimes = i2c_read(gspca_dev, 0x09, 0x10);
767 pixelclk = 0x0800;
768 expotimes = expotimes & 0x07ff;
769 /* PDEBUG(D_PACK,
770 "Exposition Times 0x%03X Clock 0x%04X ",
771 expotimes,pixelclk); */
772 gainG = i2c_read(gspca_dev, 0x35, 0x10);
773 /* PDEBUG(D_PACK,
774 "reading Gain register %d", gainG); */
775
776 expotimes += (luma_mean - y) >> spring;
777 gainG += (luma_mean - y) / 50;
778 /* PDEBUG(D_PACK,
779 "compute expotimes %d gain %d",
780 expotimes,gainG); */
781
782 if (gainG > 0x3f)
783 gainG = 0x3f;
784 else if (gainG < 4)
785 gainG = 3;
786 i2c_write(gspca_dev, gainG, 0x35);
787
788 if (expotimes >= 0x0256)
789 expotimes = 0x0256;
790 else if (expotimes < 4)
791 expotimes = 3;
792 i2c_write(gspca_dev, expotimes | pixelclk, 0x09);
793 }
794 break;
795 case Rev012A:
796 /* sensor registers is access and memory mapped to 0x8300 */
797 /* readind all 0x83xx block the sensor */
798 /*
799 * The data from the header seem wrong where is the luma
800 * and chroma mean value
801 * at the moment set exposure in contrast set
802 */
803 break;
804 }
805}
806
807static void sd_pkt_scan(struct gspca_dev *gspca_dev,
808 struct gspca_frame *frame, /* target */
809 __u8 *data, /* isoc packet */
810 int len) /* iso packet length */
811{
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300812 switch (data[0]) {
813 case 0: /* start of frame */
814 frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
815 data, 0);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300816 data += SPCA561_OFFSET_DATA;
817 len -= SPCA561_OFFSET_DATA;
818 if (data[1] & 0x10) {
819 /* compressed bayer */
820 gspca_frame_add(gspca_dev, FIRST_PACKET,
821 frame, data, len);
822 } else {
Hans de Goede54ab92c2008-07-03 11:20:58 -0300823 /* raw bayer (with a header, which we skip) */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300824 data += 20;
825 len -= 20;
826 gspca_frame_add(gspca_dev, FIRST_PACKET,
827 frame, data, len);
828 }
829 return;
830 case 0xff: /* drop */
831/* gspca_dev->last_packet_type = DISCARD_PACKET; */
832 return;
833 }
834 data++;
835 len--;
836 gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
837}
838
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300839/* rev 72a only */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300840static void setbrightness(struct gspca_dev *gspca_dev)
841{
842 struct sd *sd = (struct sd *) gspca_dev;
843 __u8 value;
844
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300845 value = sd->brightness;
846 reg_w_val(gspca_dev->dev, 0x8611, value);
847 reg_w_val(gspca_dev->dev, 0x8612, value);
848 reg_w_val(gspca_dev->dev, 0x8613, value);
849 reg_w_val(gspca_dev->dev, 0x8614, value);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300850}
851
852static void getbrightness(struct gspca_dev *gspca_dev)
853{
854 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300855 __u16 tot;
856
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300857 tot = 0;
858 reg_r(gspca_dev, 0x8611, 1);
859 tot += gspca_dev->usb_buf[0];
860 reg_r(gspca_dev, 0x8612, 1);
861 tot += gspca_dev->usb_buf[0];
862 reg_r(gspca_dev, 0x8613, 1);
863 tot += gspca_dev->usb_buf[0];
864 reg_r(gspca_dev, 0x8614, 1);
865 tot += gspca_dev->usb_buf[0];
866 sd->brightness = tot >> 2;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300867}
868
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300869/* rev72a only */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300870static void getcontrast(struct gspca_dev *gspca_dev)
871{
872 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300873 __u16 tot;
874
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300875 tot = 0;
876 reg_r(gspca_dev, 0x8651, 1);
877 tot += gspca_dev->usb_buf[0];
878 reg_r(gspca_dev, 0x8652, 1);
879 tot += gspca_dev->usb_buf[0];
880 reg_r(gspca_dev, 0x8653, 1);
881 tot += gspca_dev->usb_buf[0];
882 reg_r(gspca_dev, 0x8654, 1);
883 tot += gspca_dev->usb_buf[0];
884 sd->contrast = tot << 6;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300885 PDEBUG(D_CONF, "get contrast %d", sd->contrast);
886}
887
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300888/* rev 72a only */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300889static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
890{
891 struct sd *sd = (struct sd *) gspca_dev;
892
893 sd->brightness = val;
894 if (gspca_dev->streaming)
895 setbrightness(gspca_dev);
896 return 0;
897}
898
899static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
900{
901 struct sd *sd = (struct sd *) gspca_dev;
902
903 getbrightness(gspca_dev);
904 *val = sd->brightness;
905 return 0;
906}
907
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300908/* rev 72a only */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300909static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
910{
911 struct sd *sd = (struct sd *) gspca_dev;
912
913 sd->contrast = val;
914 if (gspca_dev->streaming)
915 setcontrast(gspca_dev);
916 return 0;
917}
918
919static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
920{
921 struct sd *sd = (struct sd *) gspca_dev;
922
923 getcontrast(gspca_dev);
924 *val = sd->contrast;
925 return 0;
926}
927
928static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
929{
930 struct sd *sd = (struct sd *) gspca_dev;
931
932 sd->autogain = val;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -0300933 if (gspca_dev->streaming)
934 setautogain(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300935 return 0;
936}
937
938static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
939{
940 struct sd *sd = (struct sd *) gspca_dev;
941
942 *val = sd->autogain;
943 return 0;
944}
945
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300946/* rev12a only */
Jean-Francois Moine6c9d3c52008-09-03 16:47:30 -0300947static int sd_setwhite(struct gspca_dev *gspca_dev, __s32 val)
948{
949 struct sd *sd = (struct sd *) gspca_dev;
950
951 sd->white = val;
952 if (gspca_dev->streaming)
953 setwhite(gspca_dev);
954 return 0;
955}
956
957static int sd_getwhite(struct gspca_dev *gspca_dev, __s32 *val)
958{
959 struct sd *sd = (struct sd *) gspca_dev;
960
961 *val = sd->white;
962 return 0;
963}
964
Jean-Francois Moine7879d452008-09-03 16:47:32 -0300965/* rev12a only */
966static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
967{
968 struct sd *sd = (struct sd *) gspca_dev;
969
970 sd->exposure = val;
971 if (gspca_dev->streaming)
972 setexposure(gspca_dev);
973 return 0;
974}
975
976static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
977{
978 struct sd *sd = (struct sd *) gspca_dev;
979
980 *val = sd->exposure;
981 return 0;
982}
983
984/* rev12a only */
985static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
986{
987 struct sd *sd = (struct sd *) gspca_dev;
988
989 sd->gain = val;
990 if (gspca_dev->streaming)
991 setgain(gspca_dev);
992 return 0;
993}
994
995static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
996{
997 struct sd *sd = (struct sd *) gspca_dev;
998
999 *val = sd->gain;
1000 return 0;
1001}
1002
1003/* control tables */
1004static struct ctrl sd_ctrls_12a[] = {
1005 {
1006 {
1007 .id = V4L2_CID_DO_WHITE_BALANCE,
1008 .type = V4L2_CTRL_TYPE_INTEGER,
1009 .name = "While Balance",
1010 .minimum = WHITE_MIN,
1011 .maximum = WHITE_MAX,
1012 .step = 1,
1013 .default_value = WHITE_DEF,
1014 },
1015 .set = sd_setwhite,
1016 .get = sd_getwhite,
1017 },
1018 {
1019 {
1020 .id = V4L2_CID_EXPOSURE,
1021 .type = V4L2_CTRL_TYPE_INTEGER,
1022 .name = "Exposure",
1023 .minimum = EXPOSURE_MIN,
1024 .maximum = EXPOSURE_MAX,
1025 .step = 1,
1026 .default_value = EXPOSURE_DEF,
1027 },
1028 .set = sd_setexposure,
1029 .get = sd_getexposure,
1030 },
1031 {
1032 {
1033 .id = V4L2_CID_AUTOGAIN,
1034 .type = V4L2_CTRL_TYPE_BOOLEAN,
1035 .name = "Auto Gain",
1036 .minimum = AUTOGAIN_MIN,
1037 .maximum = AUTOGAIN_MAX,
1038 .step = 1,
1039 .default_value = AUTOGAIN_DEF,
1040 },
1041 .set = sd_setautogain,
1042 .get = sd_getautogain,
1043 },
1044 {
1045 {
1046 .id = V4L2_CID_GAIN,
1047 .type = V4L2_CTRL_TYPE_INTEGER,
1048 .name = "Gain",
1049 .minimum = GAIN_MIN,
1050 .maximum = GAIN_MAX,
1051 .step = 1,
1052 .default_value = GAIN_DEF,
1053 },
1054 .set = sd_setgain,
1055 .get = sd_getgain,
1056 },
1057};
1058
1059static struct ctrl sd_ctrls_72a[] = {
1060 {
1061 {
1062 .id = V4L2_CID_BRIGHTNESS,
1063 .type = V4L2_CTRL_TYPE_INTEGER,
1064 .name = "Brightness",
1065 .minimum = BRIGHTNESS_MIN,
1066 .maximum = BRIGHTNESS_MAX,
1067 .step = 1,
1068 .default_value = BRIGHTNESS_DEF,
1069 },
1070 .set = sd_setbrightness,
1071 .get = sd_getbrightness,
1072 },
1073 {
1074 {
1075 .id = V4L2_CID_CONTRAST,
1076 .type = V4L2_CTRL_TYPE_INTEGER,
1077 .name = "Contrast",
1078 .minimum = CONTRAST_MIN,
1079 .maximum = CONTRAST_MAX,
1080 .step = 1,
1081 .default_value = CONTRAST_DEF,
1082 },
1083 .set = sd_setcontrast,
1084 .get = sd_getcontrast,
1085 },
1086 {
1087 {
1088 .id = V4L2_CID_AUTOGAIN,
1089 .type = V4L2_CTRL_TYPE_BOOLEAN,
1090 .name = "Auto Gain",
1091 .minimum = AUTOGAIN_MIN,
1092 .maximum = AUTOGAIN_MAX,
1093 .step = 1,
1094 .default_value = AUTOGAIN_DEF,
1095 },
1096 .set = sd_setautogain,
1097 .get = sd_getautogain,
1098 },
1099};
1100
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001101/* sub-driver description */
Jean-Francois Moine7879d452008-09-03 16:47:32 -03001102static const struct sd_desc sd_desc_12a = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001103 .name = MODULE_NAME,
Jean-Francois Moine7879d452008-09-03 16:47:32 -03001104 .ctrls = sd_ctrls_12a,
1105 .nctrls = ARRAY_SIZE(sd_ctrls_12a),
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001106 .config = sd_config,
Jean-Francois Moine7879d452008-09-03 16:47:32 -03001107 .open = sd_open_12a,
1108 .start = sd_start_12a,
1109 .stopN = sd_stopN,
1110 .stop0 = sd_stop0,
1111 .close = sd_close,
1112 .pkt_scan = sd_pkt_scan,
1113/* .dq_callback = do_autogain, * fixme */
1114};
1115static const struct sd_desc sd_desc_72a = {
1116 .name = MODULE_NAME,
1117 .ctrls = sd_ctrls_72a,
1118 .nctrls = ARRAY_SIZE(sd_ctrls_72a),
1119 .config = sd_config,
1120 .open = sd_open_72a,
1121 .start = sd_start_72a,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001122 .stopN = sd_stopN,
1123 .stop0 = sd_stop0,
1124 .close = sd_close,
1125 .pkt_scan = sd_pkt_scan,
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001126 .dq_callback = do_autogain,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001127};
Jean-Francois Moine7879d452008-09-03 16:47:32 -03001128static const struct sd_desc *sd_desc[2] = {
1129 &sd_desc_12a,
1130 &sd_desc_72a
1131};
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001132
1133/* -- module initialisation -- */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03001134static const __devinitdata struct usb_device_id device_table[] = {
Jean-Francois Moine87581aa2008-07-26 14:30:01 -03001135 {USB_DEVICE(0x041e, 0x401a), .driver_info = Rev072A},
1136 {USB_DEVICE(0x041e, 0x403b), .driver_info = Rev012A},
1137 {USB_DEVICE(0x0458, 0x7004), .driver_info = Rev072A},
1138 {USB_DEVICE(0x046d, 0x0928), .driver_info = Rev012A},
1139 {USB_DEVICE(0x046d, 0x0929), .driver_info = Rev012A},
1140 {USB_DEVICE(0x046d, 0x092a), .driver_info = Rev012A},
1141 {USB_DEVICE(0x046d, 0x092b), .driver_info = Rev012A},
1142 {USB_DEVICE(0x046d, 0x092c), .driver_info = Rev012A},
1143 {USB_DEVICE(0x046d, 0x092d), .driver_info = Rev012A},
1144 {USB_DEVICE(0x046d, 0x092e), .driver_info = Rev012A},
1145 {USB_DEVICE(0x046d, 0x092f), .driver_info = Rev012A},
1146 {USB_DEVICE(0x04fc, 0x0561), .driver_info = Rev072A},
1147 {USB_DEVICE(0x060b, 0xa001), .driver_info = Rev072A},
1148 {USB_DEVICE(0x10fd, 0x7e50), .driver_info = Rev072A},
1149 {USB_DEVICE(0xabcd, 0xcdee), .driver_info = Rev072A},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001150 {}
1151};
1152
1153MODULE_DEVICE_TABLE(usb, device_table);
1154
1155/* -- device connect -- */
1156static int sd_probe(struct usb_interface *intf,
1157 const struct usb_device_id *id)
1158{
Jean-Francois Moine7879d452008-09-03 16:47:32 -03001159 return gspca_dev_probe(intf, id,
1160 sd_desc[id->driver_info],
1161 sizeof(struct sd),
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001162 THIS_MODULE);
1163}
1164
1165static struct usb_driver sd_driver = {
1166 .name = MODULE_NAME,
1167 .id_table = device_table,
1168 .probe = sd_probe,
1169 .disconnect = gspca_disconnect,
1170};
1171
1172/* -- module insert / remove -- */
1173static int __init sd_mod_init(void)
1174{
1175 if (usb_register(&sd_driver) < 0)
1176 return -1;
Jean-Francois Moine10b0e962008-07-22 05:35:10 -03001177 PDEBUG(D_PROBE, "registered");
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001178 return 0;
1179}
1180static void __exit sd_mod_exit(void)
1181{
1182 usb_deregister(&sd_driver);
1183 PDEBUG(D_PROBE, "deregistered");
1184}
1185
1186module_init(sd_mod_init);
1187module_exit(sd_mod_exit);