blob: 4706a823add0baa395a324acc207bfcdac2b9f6e [file] [log] [blame]
Hans de Goedee2997a72008-04-23 08:09:12 -03001/*
2 * Pixart PAC207BCA library
3 *
Hans de Goededc1fe152008-12-14 09:37:02 -03004 * Copyright (C) 2008 Hans de Goede <hdgoede@redhat.com>
Hans de Goedee2997a72008-04-23 08:09:12 -03005 * Copyright (C) 2005 Thomas Kaiser thomas@kaiser-linux.li
6 * Copyleft (C) 2005 Michel Xhaard mxhaard@magic.fr
7 *
8 * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 */
25
26#define MODULE_NAME "pac207"
27
28#include "gspca.h"
29
Hans de Goededc1fe152008-12-14 09:37:02 -030030MODULE_AUTHOR("Hans de Goede <hdgoede@redhat.com>");
Hans de Goedee2997a72008-04-23 08:09:12 -030031MODULE_DESCRIPTION("Pixart PAC207");
32MODULE_LICENSE("GPL");
33
34#define PAC207_CTRL_TIMEOUT 100 /* ms */
35
36#define PAC207_BRIGHTNESS_MIN 0
37#define PAC207_BRIGHTNESS_MAX 255
Hans de Goede0e4a9092009-07-29 08:03:17 -030038#define PAC207_BRIGHTNESS_DEFAULT 46
Hans de Goedee2997a72008-04-23 08:09:12 -030039
Hans de Goede0e4a9092009-07-29 08:03:17 -030040#define PAC207_EXPOSURE_MIN 3
Hans de Goedee2997a72008-04-23 08:09:12 -030041#define PAC207_EXPOSURE_MAX 26
Hans de Goede0e4a9092009-07-29 08:03:17 -030042#define PAC207_EXPOSURE_DEFAULT 5 /* power on default: 3 */
43#define PAC207_EXPOSURE_KNEE 8 /* 4 = 30 fps, 11 = 8, 15 = 6 */
Hans de Goedee2997a72008-04-23 08:09:12 -030044
45#define PAC207_GAIN_MIN 0
46#define PAC207_GAIN_MAX 31
47#define PAC207_GAIN_DEFAULT 9 /* power on default: 9 */
Hans de Goede0e4a9092009-07-29 08:03:17 -030048#define PAC207_GAIN_KNEE 31
Hans de Goedee2997a72008-04-23 08:09:12 -030049
50#define PAC207_AUTOGAIN_DEADZONE 30
Hans de Goedee2997a72008-04-23 08:09:12 -030051
Hans de Goedee2997a72008-04-23 08:09:12 -030052/* specific webcam descriptor */
53struct sd {
54 struct gspca_dev gspca_dev; /* !! must be the first item */
55
Hans de Goedee2997a72008-04-23 08:09:12 -030056 u8 mode;
57
58 u8 brightness;
59 u8 exposure;
60 u8 autogain;
61 u8 gain;
62
63 u8 sof_read;
Hans de Goedeab8f12c2008-07-04 18:29:32 -030064 u8 header_read;
Hans de Goedee2997a72008-04-23 08:09:12 -030065 u8 autogain_ignore_frames;
66
67 atomic_t avg_lum;
68};
69
70/* V4L2 controls supported by the driver */
71static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
72static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
73static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
74static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);
75static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
76static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
77static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
78static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
79
80static struct ctrl sd_ctrls[] = {
81#define SD_BRIGHTNESS 0
82 {
83 {
84 .id = V4L2_CID_BRIGHTNESS,
85 .type = V4L2_CTRL_TYPE_INTEGER,
86 .name = "Brightness",
87 .minimum = PAC207_BRIGHTNESS_MIN,
88 .maximum = PAC207_BRIGHTNESS_MAX,
89 .step = 1,
90 .default_value = PAC207_BRIGHTNESS_DEFAULT,
91 .flags = 0,
92 },
93 .set = sd_setbrightness,
94 .get = sd_getbrightness,
95 },
96#define SD_EXPOSURE 1
97 {
98 {
99 .id = V4L2_CID_EXPOSURE,
100 .type = V4L2_CTRL_TYPE_INTEGER,
101 .name = "exposure",
102 .minimum = PAC207_EXPOSURE_MIN,
103 .maximum = PAC207_EXPOSURE_MAX,
104 .step = 1,
105 .default_value = PAC207_EXPOSURE_DEFAULT,
106 .flags = 0,
107 },
108 .set = sd_setexposure,
109 .get = sd_getexposure,
110 },
111#define SD_AUTOGAIN 2
112 {
113 {
114 .id = V4L2_CID_AUTOGAIN,
115 .type = V4L2_CTRL_TYPE_BOOLEAN,
116 .name = "Auto Gain",
117 .minimum = 0,
118 .maximum = 1,
119 .step = 1,
Jean-Francois Moine66e41242008-09-03 17:12:16 -0300120#define AUTOGAIN_DEF 1
121 .default_value = AUTOGAIN_DEF,
Hans de Goedee2997a72008-04-23 08:09:12 -0300122 .flags = 0,
123 },
124 .set = sd_setautogain,
125 .get = sd_getautogain,
126 },
127#define SD_GAIN 3
128 {
129 {
130 .id = V4L2_CID_GAIN,
131 .type = V4L2_CTRL_TYPE_INTEGER,
132 .name = "gain",
133 .minimum = PAC207_GAIN_MIN,
134 .maximum = PAC207_GAIN_MAX,
135 .step = 1,
136 .default_value = PAC207_GAIN_DEFAULT,
137 .flags = 0,
138 },
139 .set = sd_setgain,
140 .get = sd_getgain,
141 },
142};
143
Jean-Francois Moinecc611b82008-12-29 07:49:41 -0300144static const struct v4l2_pix_format sif_mode[] = {
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300145 {176, 144, V4L2_PIX_FMT_PAC207, V4L2_FIELD_NONE,
146 .bytesperline = 176,
147 .sizeimage = (176 + 2) * 144,
148 /* uncompressed, add 2 bytes / line for line header */
149 .colorspace = V4L2_COLORSPACE_SRGB,
150 .priv = 1},
151 {352, 288, V4L2_PIX_FMT_PAC207, V4L2_FIELD_NONE,
152 .bytesperline = 352,
Hans de Goede80544d3c2008-07-06 06:40:55 -0300153 /* compressed, but only when needed (not compressed
154 when the framerate is low) */
155 .sizeimage = (352 + 2) * 288,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300156 .colorspace = V4L2_COLORSPACE_SRGB,
157 .priv = 0},
Hans de Goedee2997a72008-04-23 08:09:12 -0300158};
159
160static const __u8 pac207_sensor_init[][8] = {
Hans de Goede0e4a9092009-07-29 08:03:17 -0300161 {0x10, 0x12, 0x0d, 0x12, 0x0c, 0x01, 0x29, 0x84},
162 {0x49, 0x64, 0x64, 0x64, 0x04, 0x10, 0xf0, 0x30},
Hans de Goedee2997a72008-04-23 08:09:12 -0300163 {0x00, 0x00, 0x00, 0x70, 0xa0, 0xf8, 0x00, 0x00},
Hans de Goedee2997a72008-04-23 08:09:12 -0300164 {0x32, 0x00, 0x96, 0x00, 0xA2, 0x02, 0xaf, 0x00},
165};
166
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300167static int pac207_write_regs(struct gspca_dev *gspca_dev, u16 index,
Hans de Goedee2997a72008-04-23 08:09:12 -0300168 const u8 *buffer, u16 length)
169{
170 struct usb_device *udev = gspca_dev->dev;
171 int err;
Hans de Goedee2997a72008-04-23 08:09:12 -0300172
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300173 memcpy(gspca_dev->usb_buf, buffer, length);
Hans de Goedee2997a72008-04-23 08:09:12 -0300174
175 err = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x01,
176 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300177 0x00, index,
178 gspca_dev->usb_buf, length, PAC207_CTRL_TIMEOUT);
Hans de Goedee2997a72008-04-23 08:09:12 -0300179 if (err < 0)
180 PDEBUG(D_ERR,
181 "Failed to write registers to index 0x%04X, error %d)",
182 index, err);
183
184 return err;
185}
186
187
Adrian Bunk903e10a2008-07-22 02:35:05 -0300188static int pac207_write_reg(struct gspca_dev *gspca_dev, u16 index, u16 value)
Hans de Goedee2997a72008-04-23 08:09:12 -0300189{
190 struct usb_device *udev = gspca_dev->dev;
191 int err;
192
193 err = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00,
194 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
195 value, index, NULL, 0, PAC207_CTRL_TIMEOUT);
196 if (err)
197 PDEBUG(D_ERR, "Failed to write a register (index 0x%04X,"
198 " value 0x%02X, error %d)", index, value, err);
199
200 return err;
201}
202
Adrian Bunk903e10a2008-07-22 02:35:05 -0300203static int pac207_read_reg(struct gspca_dev *gspca_dev, u16 index)
Hans de Goedee2997a72008-04-23 08:09:12 -0300204{
205 struct usb_device *udev = gspca_dev->dev;
Hans de Goedee2997a72008-04-23 08:09:12 -0300206 int res;
207
208 res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 0x00,
209 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300210 0x00, index,
211 gspca_dev->usb_buf, 1, PAC207_CTRL_TIMEOUT);
Hans de Goedee2997a72008-04-23 08:09:12 -0300212 if (res < 0) {
213 PDEBUG(D_ERR,
214 "Failed to read a register (index 0x%04X, error %d)",
215 index, res);
216 return res;
217 }
218
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300219 return gspca_dev->usb_buf[0];
Hans de Goedee2997a72008-04-23 08:09:12 -0300220}
221
Hans de Goedee2997a72008-04-23 08:09:12 -0300222/* this function is called at probe time */
223static int sd_config(struct gspca_dev *gspca_dev,
224 const struct usb_device_id *id)
225{
Jean-Francois Moine4aa0d032008-05-04 06:46:21 -0300226 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goedee2997a72008-04-23 08:09:12 -0300227 struct cam *cam;
228 u8 idreg[2];
229
230 idreg[0] = pac207_read_reg(gspca_dev, 0x0000);
231 idreg[1] = pac207_read_reg(gspca_dev, 0x0001);
232 idreg[0] = ((idreg[0] & 0x0F) << 4) | ((idreg[1] & 0xf0) >> 4);
233 idreg[1] = idreg[1] & 0x0f;
234 PDEBUG(D_PROBE, "Pixart Sensor ID 0x%02X Chips ID 0x%02X",
235 idreg[0], idreg[1]);
236
237 if (idreg[0] != 0x27) {
238 PDEBUG(D_PROBE, "Error invalid sensor ID!");
239 return -ENODEV;
240 }
241
Hans de Goedee2997a72008-04-23 08:09:12 -0300242 PDEBUG(D_PROBE,
243 "Pixart PAC207BCA Image Processor and Control Chip detected"
244 " (vid/pid 0x%04X:0x%04X)", id->idVendor, id->idProduct);
245
246 cam = &gspca_dev->cam;
Hans de Goedee2997a72008-04-23 08:09:12 -0300247 cam->cam_mode = sif_mode;
248 cam->nmodes = ARRAY_SIZE(sif_mode);
Jean-Francois Moine4aa0d032008-05-04 06:46:21 -0300249 sd->brightness = PAC207_BRIGHTNESS_DEFAULT;
250 sd->exposure = PAC207_EXPOSURE_DEFAULT;
251 sd->gain = PAC207_GAIN_DEFAULT;
Jean-Francois Moine66e41242008-09-03 17:12:16 -0300252 sd->autogain = AUTOGAIN_DEF;
Hans de Goedee2997a72008-04-23 08:09:12 -0300253
254 return 0;
255}
256
Jean-Francois Moine012d6b02008-09-03 17:12:16 -0300257/* this function is called at probe and resume time */
258static int sd_init(struct gspca_dev *gspca_dev)
Hans de Goedee2997a72008-04-23 08:09:12 -0300259{
Jean-Francois Moine66e41242008-09-03 17:12:16 -0300260 pac207_write_reg(gspca_dev, 0x41, 0x00);
261 /* Bit_0=Image Format,
262 * Bit_1=LED,
263 * Bit_2=Compression test mode enable */
264 pac207_write_reg(gspca_dev, 0x0f, 0x00); /* Power Control */
Hans de Goedee2997a72008-04-23 08:09:12 -0300265
Hans de Goedee2997a72008-04-23 08:09:12 -0300266 return 0;
267}
268
269/* -- start the camera -- */
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -0300270static int sd_start(struct gspca_dev *gspca_dev)
Hans de Goedee2997a72008-04-23 08:09:12 -0300271{
272 struct sd *sd = (struct sd *) gspca_dev;
273 __u8 mode;
274
275 pac207_write_reg(gspca_dev, 0x0f, 0x10); /* Power control (Bit 6-0) */
276 pac207_write_regs(gspca_dev, 0x0002, pac207_sensor_init[0], 8);
277 pac207_write_regs(gspca_dev, 0x000a, pac207_sensor_init[1], 8);
278 pac207_write_regs(gspca_dev, 0x0012, pac207_sensor_init[2], 8);
Hans de Goedec529e552009-07-29 08:02:50 -0300279 pac207_write_regs(gspca_dev, 0x0042, pac207_sensor_init[3], 8);
Hans de Goedee2997a72008-04-23 08:09:12 -0300280
281 /* Compression Balance */
282 if (gspca_dev->width == 176)
283 pac207_write_reg(gspca_dev, 0x4a, 0xff);
284 else
Hans de Goede0e4a9092009-07-29 08:03:17 -0300285 pac207_write_reg(gspca_dev, 0x4a, 0x30);
Hans de Goedee2997a72008-04-23 08:09:12 -0300286 pac207_write_reg(gspca_dev, 0x4b, 0x00); /* Sram test value */
287 pac207_write_reg(gspca_dev, 0x08, sd->brightness);
288
289 /* PGA global gain (Bit 4-0) */
290 pac207_write_reg(gspca_dev, 0x0e, sd->gain);
291 pac207_write_reg(gspca_dev, 0x02, sd->exposure); /* PXCK = 12MHz /n */
292
293 mode = 0x02; /* Image Format (Bit 0), LED (1), Compr. test mode (2) */
Jean-Francois Moined43fa322008-06-12 10:58:58 -0300294 if (gspca_dev->width == 176) { /* 176x144 */
Hans de Goedee2997a72008-04-23 08:09:12 -0300295 mode |= 0x01;
296 PDEBUG(D_STREAM, "pac207_start mode 176x144");
Jean-Francois Moined43fa322008-06-12 10:58:58 -0300297 } else { /* 352x288 */
Hans de Goedee2997a72008-04-23 08:09:12 -0300298 PDEBUG(D_STREAM, "pac207_start mode 352x288");
Jean-Francois Moined43fa322008-06-12 10:58:58 -0300299 }
Hans de Goedee2997a72008-04-23 08:09:12 -0300300 pac207_write_reg(gspca_dev, 0x41, mode);
301
302 pac207_write_reg(gspca_dev, 0x13, 0x01); /* Bit 0, auto clear */
303 pac207_write_reg(gspca_dev, 0x1c, 0x01); /* not documented */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300304 msleep(10);
Hans de Goedee2997a72008-04-23 08:09:12 -0300305 pac207_write_reg(gspca_dev, 0x40, 0x01); /* Start ISO pipe */
306
307 sd->sof_read = 0;
308 sd->autogain_ignore_frames = 0;
309 atomic_set(&sd->avg_lum, -1);
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -0300310 return 0;
Hans de Goedee2997a72008-04-23 08:09:12 -0300311}
312
313static void sd_stopN(struct gspca_dev *gspca_dev)
314{
315 pac207_write_reg(gspca_dev, 0x40, 0x00); /* Stop ISO pipe */
316 pac207_write_reg(gspca_dev, 0x41, 0x00); /* Turn of LED */
317 pac207_write_reg(gspca_dev, 0x0f, 0x00); /* Power Control */
318}
319
Hans de Goede8a5b2e92008-09-03 17:12:17 -0300320/* Include pac common sof detection functions */
321#include "pac_common.h"
322
Hans de Goedee2997a72008-04-23 08:09:12 -0300323static void pac207_do_auto_gain(struct gspca_dev *gspca_dev)
324{
325 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goedee2997a72008-04-23 08:09:12 -0300326 int avg_lum = atomic_read(&sd->avg_lum);
327
Hans de Goededcef3232008-07-10 10:40:53 -0300328 if (avg_lum == -1)
Hans de Goedee2997a72008-04-23 08:09:12 -0300329 return;
330
Hans de Goededcef3232008-07-10 10:40:53 -0300331 if (sd->autogain_ignore_frames > 0)
Hans de Goedee2997a72008-04-23 08:09:12 -0300332 sd->autogain_ignore_frames--;
Hans de Goededcef3232008-07-10 10:40:53 -0300333 else if (gspca_auto_gain_n_exposure(gspca_dev, avg_lum,
Hans de Goede0e4a9092009-07-29 08:03:17 -0300334 100, PAC207_AUTOGAIN_DEADZONE,
Hans de Goededcef3232008-07-10 10:40:53 -0300335 PAC207_GAIN_KNEE, PAC207_EXPOSURE_KNEE))
Hans de Goede8a5b2e92008-09-03 17:12:17 -0300336 sd->autogain_ignore_frames = PAC_AUTOGAIN_IGNORE_FRAMES;
Hans de Goedee2997a72008-04-23 08:09:12 -0300337}
338
Hans de Goedee2997a72008-04-23 08:09:12 -0300339static void sd_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine76dd2722009-11-13 09:21:03 -0300340 u8 *data,
Hans de Goedee2997a72008-04-23 08:09:12 -0300341 int len)
342{
Hans de Goedeab8f12c2008-07-04 18:29:32 -0300343 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goedee2997a72008-04-23 08:09:12 -0300344 unsigned char *sof;
Hans de Goedee2997a72008-04-23 08:09:12 -0300345
Marton Nemetha6b69e42009-11-02 08:05:51 -0300346 sof = pac_find_sof(&sd->sof_read, data, len);
Hans de Goedee2997a72008-04-23 08:09:12 -0300347 if (sof) {
Hans de Goedeab8f12c2008-07-04 18:29:32 -0300348 int n;
349
Hans de Goedee2997a72008-04-23 08:09:12 -0300350 /* finish decoding current frame */
Hans de Goedeab8f12c2008-07-04 18:29:32 -0300351 n = sof - data;
Hans de Goede327c4ab2008-09-03 17:12:14 -0300352 if (n > sizeof pac_sof_marker)
353 n -= sizeof pac_sof_marker;
Hans de Goedeab8f12c2008-07-04 18:29:32 -0300354 else
355 n = 0;
Jean-Francois Moine76dd2722009-11-13 09:21:03 -0300356 gspca_frame_add(gspca_dev, LAST_PACKET,
357 data, n);
Hans de Goedeab8f12c2008-07-04 18:29:32 -0300358 sd->header_read = 0;
Jean-Francois Moine76dd2722009-11-13 09:21:03 -0300359 gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0);
Hans de Goedee2997a72008-04-23 08:09:12 -0300360 len -= sof - data;
361 data = sof;
362 }
Hans de Goedeab8f12c2008-07-04 18:29:32 -0300363 if (sd->header_read < 11) {
364 int needed;
Hans de Goedee2997a72008-04-23 08:09:12 -0300365
Hans de Goedeab8f12c2008-07-04 18:29:32 -0300366 /* get average lumination from frame header (byte 5) */
367 if (sd->header_read < 5) {
368 needed = 5 - sd->header_read;
369 if (len >= needed)
370 atomic_set(&sd->avg_lum, data[needed - 1]);
371 }
372 /* skip the rest of the header */
373 needed = 11 - sd->header_read;
374 if (len <= needed) {
375 sd->header_read += len;
376 return;
377 }
378 data += needed;
379 len -= needed;
380 sd->header_read = 11;
381 }
Hans de Goedee2997a72008-04-23 08:09:12 -0300382
Jean-Francois Moine76dd2722009-11-13 09:21:03 -0300383 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
Hans de Goedee2997a72008-04-23 08:09:12 -0300384}
385
386static void setbrightness(struct gspca_dev *gspca_dev)
387{
388 struct sd *sd = (struct sd *) gspca_dev;
389
390 pac207_write_reg(gspca_dev, 0x08, sd->brightness);
391 pac207_write_reg(gspca_dev, 0x13, 0x01); /* Bit 0, auto clear */
392 pac207_write_reg(gspca_dev, 0x1c, 0x01); /* not documented */
393}
394
395static void setexposure(struct gspca_dev *gspca_dev)
396{
397 struct sd *sd = (struct sd *) gspca_dev;
398
399 pac207_write_reg(gspca_dev, 0x02, sd->exposure);
400 pac207_write_reg(gspca_dev, 0x13, 0x01); /* Bit 0, auto clear */
401 pac207_write_reg(gspca_dev, 0x1c, 0x01); /* not documented */
402}
403
404static void setgain(struct gspca_dev *gspca_dev)
405{
406 struct sd *sd = (struct sd *) gspca_dev;
407
408 pac207_write_reg(gspca_dev, 0x0e, sd->gain);
409 pac207_write_reg(gspca_dev, 0x13, 0x01); /* Bit 0, auto clear */
410 pac207_write_reg(gspca_dev, 0x1c, 0x01); /* not documented */
411}
412
413static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
414{
415 struct sd *sd = (struct sd *) gspca_dev;
416
417 sd->brightness = val;
418 if (gspca_dev->streaming)
419 setbrightness(gspca_dev);
420 return 0;
421}
422
423static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
424{
425 struct sd *sd = (struct sd *) gspca_dev;
426
427 *val = sd->brightness;
428 return 0;
429}
430
431static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
432{
433 struct sd *sd = (struct sd *) gspca_dev;
434
Hans de Goedee2997a72008-04-23 08:09:12 -0300435 sd->exposure = val;
436 if (gspca_dev->streaming)
437 setexposure(gspca_dev);
438 return 0;
439}
440
441static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
442{
443 struct sd *sd = (struct sd *) gspca_dev;
444
445 *val = sd->exposure;
446 return 0;
447}
448
449static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
450{
451 struct sd *sd = (struct sd *) gspca_dev;
452
Hans de Goedee2997a72008-04-23 08:09:12 -0300453 sd->gain = val;
454 if (gspca_dev->streaming)
455 setgain(gspca_dev);
456 return 0;
457}
458
459static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
460{
461 struct sd *sd = (struct sd *) gspca_dev;
462
463 *val = sd->gain;
464 return 0;
465}
466
467static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
468{
469 struct sd *sd = (struct sd *) gspca_dev;
470
471 sd->autogain = val;
472 /* when switching to autogain set defaults to make sure
473 we are on a valid point of the autogain gain /
474 exposure knee graph, and give this change time to
475 take effect before doing autogain. */
476 if (sd->autogain) {
477 sd->exposure = PAC207_EXPOSURE_DEFAULT;
478 sd->gain = PAC207_GAIN_DEFAULT;
479 if (gspca_dev->streaming) {
480 sd->autogain_ignore_frames =
Hans de Goede8a5b2e92008-09-03 17:12:17 -0300481 PAC_AUTOGAIN_IGNORE_FRAMES;
Hans de Goedee2997a72008-04-23 08:09:12 -0300482 setexposure(gspca_dev);
483 setgain(gspca_dev);
484 }
485 }
486
487 return 0;
488}
489
490static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
491{
492 struct sd *sd = (struct sd *) gspca_dev;
493
494 *val = sd->autogain;
495 return 0;
496}
497
498/* sub-driver description */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300499static const struct sd_desc sd_desc = {
Hans de Goedee2997a72008-04-23 08:09:12 -0300500 .name = MODULE_NAME,
501 .ctrls = sd_ctrls,
502 .nctrls = ARRAY_SIZE(sd_ctrls),
503 .config = sd_config,
Jean-Francois Moine012d6b02008-09-03 17:12:16 -0300504 .init = sd_init,
Hans de Goedee2997a72008-04-23 08:09:12 -0300505 .start = sd_start,
506 .stopN = sd_stopN,
Hans de Goedee2997a72008-04-23 08:09:12 -0300507 .dq_callback = pac207_do_auto_gain,
508 .pkt_scan = sd_pkt_scan,
509};
510
511/* -- module initialisation -- */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300512static const __devinitdata struct usb_device_id device_table[] = {
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -0300513 {USB_DEVICE(0x041e, 0x4028)},
514 {USB_DEVICE(0x093a, 0x2460)},
Hans de Goede87945892008-12-20 14:30:58 -0300515 {USB_DEVICE(0x093a, 0x2461)},
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -0300516 {USB_DEVICE(0x093a, 0x2463)},
517 {USB_DEVICE(0x093a, 0x2464)},
518 {USB_DEVICE(0x093a, 0x2468)},
519 {USB_DEVICE(0x093a, 0x2470)},
520 {USB_DEVICE(0x093a, 0x2471)},
521 {USB_DEVICE(0x093a, 0x2472)},
Lierdakildb912352009-01-25 14:37:26 -0300522 {USB_DEVICE(0x093a, 0x2474)},
Jean-Francois Moined654dca2008-09-06 04:18:48 -0300523 {USB_DEVICE(0x093a, 0x2476)},
Jean-Francois Moine91711872008-10-28 08:00:23 -0300524 {USB_DEVICE(0x145f, 0x013a)},
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -0300525 {USB_DEVICE(0x2001, 0xf115)},
Hans de Goedee2997a72008-04-23 08:09:12 -0300526 {}
527};
528MODULE_DEVICE_TABLE(usb, device_table);
529
530/* -- device connect -- */
531static int sd_probe(struct usb_interface *intf,
532 const struct usb_device_id *id)
533{
Jean-Francois Moined43fa322008-06-12 10:58:58 -0300534 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
535 THIS_MODULE);
Hans de Goedee2997a72008-04-23 08:09:12 -0300536}
537
538static struct usb_driver sd_driver = {
539 .name = MODULE_NAME,
540 .id_table = device_table,
541 .probe = sd_probe,
542 .disconnect = gspca_disconnect,
Jean-Francois Moine6a709742008-09-03 16:48:10 -0300543#ifdef CONFIG_PM
544 .suspend = gspca_suspend,
545 .resume = gspca_resume,
546#endif
Hans de Goedee2997a72008-04-23 08:09:12 -0300547};
548
549/* -- module insert / remove -- */
550static int __init sd_mod_init(void)
551{
Alexey Klimovf69e9522009-01-01 13:02:07 -0300552 int ret;
553 ret = usb_register(&sd_driver);
554 if (ret < 0)
Alexey Klimove6b14842009-01-01 13:04:58 -0300555 return ret;
Adrian Bunk903e10a2008-07-22 02:35:05 -0300556 PDEBUG(D_PROBE, "registered");
Hans de Goedee2997a72008-04-23 08:09:12 -0300557 return 0;
558}
559static void __exit sd_mod_exit(void)
560{
561 usb_deregister(&sd_driver);
562 PDEBUG(D_PROBE, "deregistered");
563}
564
565module_init(sd_mod_init);
566module_exit(sd_mod_exit);