Commit | Line | Data |
---|---|---|
fbb4c6d2 | 1 | /* |
c52af799 | 2 | * ov534-ov772x gspca driver |
189d92af | 3 | * |
fbb4c6d2 | 4 | * Copyright (C) 2008 Antonio Ospite <ospite@studenti.unina.it> |
0f7a50b2 | 5 | * Copyright (C) 2008 Jim Paris <jim@jtan.com> |
2ce949ec | 6 | * Copyright (C) 2009 Jean-Francois Moine http://moinejf.free.fr |
fbb4c6d2 AO |
7 | * |
8 | * Based on a prototype written by Mark Ferrell <majortrips@gmail.com> | |
9 | * USB protocol reverse engineered by Jim Paris <jim@jtan.com> | |
10 | * https://jim.sh/svn/jim/devl/playstation/ps3/eye/test/ | |
11 | * | |
189d92af | 12 | * PS3 Eye camera enhanced by Richard Kaswy http://kaswy.free.fr |
b014f94b JFM |
13 | * PS3 Eye camera, brightness, contrast, hue, AWB control added |
14 | * by Max Thrun <bear24rw@gmail.com> | |
189d92af | 15 | * |
fbb4c6d2 AO |
16 | * This program is free software; you can redistribute it and/or modify |
17 | * it under the terms of the GNU General Public License as published by | |
18 | * the Free Software Foundation; either version 2 of the License, or | |
19 | * any later version. | |
20 | * | |
21 | * This program is distributed in the hope that it will be useful, | |
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 | * GNU General Public License for more details. | |
25 | * | |
26 | * You should have received a copy of the GNU General Public License | |
27 | * along with this program; if not, write to the Free Software | |
28 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
29 | */ | |
30 | ||
31 | #define MODULE_NAME "ov534" | |
32 | ||
33 | #include "gspca.h" | |
34 | ||
2ce949ec | 35 | #define OV534_REG_ADDRESS 0xf1 /* sensor address */ |
fbb4c6d2 AO |
36 | #define OV534_REG_SUBADDR 0xf2 |
37 | #define OV534_REG_WRITE 0xf3 | |
38 | #define OV534_REG_READ 0xf4 | |
39 | #define OV534_REG_OPERATION 0xf5 | |
40 | #define OV534_REG_STATUS 0xf6 | |
41 | ||
42 | #define OV534_OP_WRITE_3 0x37 | |
43 | #define OV534_OP_WRITE_2 0x33 | |
44 | #define OV534_OP_READ_2 0xf9 | |
45 | ||
46 | #define CTRL_TIMEOUT 500 | |
47 | ||
48 | MODULE_AUTHOR("Antonio Ospite <ospite@studenti.unina.it>"); | |
49 | MODULE_DESCRIPTION("GSPCA/OV534 USB Camera Driver"); | |
50 | MODULE_LICENSE("GPL"); | |
51 | ||
fbb4c6d2 AO |
52 | /* specific webcam descriptor */ |
53 | struct sd { | |
54 | struct gspca_dev gspca_dev; /* !! must be the first item */ | |
8c252050 | 55 | __u32 last_pts; |
84fbdf87 JFM |
56 | u16 last_fid; |
57 | u8 frame_rate; | |
b014f94b JFM |
58 | |
59 | u8 brightness; | |
60 | u8 contrast; | |
189d92af JFM |
61 | u8 gain; |
62 | u8 exposure; | |
8b7fbda4 | 63 | u8 agc; |
b014f94b | 64 | u8 awb; |
f2938822 | 65 | u8 aec; |
c22c4a20 | 66 | s8 sharpness; |
189d92af JFM |
67 | u8 hflip; |
68 | u8 vflip; | |
2ce949ec | 69 | |
fbb4c6d2 AO |
70 | }; |
71 | ||
72 | /* V4L2 controls supported by the driver */ | |
189d92af JFM |
73 | static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val); |
74 | static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val); | |
75 | static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val); | |
76 | static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val); | |
8b7fbda4 MT |
77 | static int sd_setagc(struct gspca_dev *gspca_dev, __s32 val); |
78 | static int sd_getagc(struct gspca_dev *gspca_dev, __s32 *val); | |
189d92af JFM |
79 | static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val); |
80 | static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val); | |
81 | static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val); | |
82 | static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val); | |
83 | static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val); | |
84 | static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val); | |
b014f94b JFM |
85 | static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val); |
86 | static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val); | |
f2938822 MT |
87 | static int sd_setaec(struct gspca_dev *gspca_dev, __s32 val); |
88 | static int sd_getaec(struct gspca_dev *gspca_dev, __s32 *val); | |
b014f94b JFM |
89 | static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); |
90 | static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); | |
91 | static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val); | |
92 | static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val); | |
189d92af | 93 | |
c52af799 | 94 | static const struct ctrl sd_ctrls[] = { |
2d19a2c1 | 95 | { /* 0 */ |
b014f94b JFM |
96 | { |
97 | .id = V4L2_CID_BRIGHTNESS, | |
98 | .type = V4L2_CTRL_TYPE_INTEGER, | |
99 | .name = "Brightness", | |
100 | .minimum = 0, | |
101 | .maximum = 255, | |
102 | .step = 1, | |
8b7fbda4 | 103 | #define BRIGHTNESS_DEF 0 |
c52af799 | 104 | .default_value = BRIGHTNESS_DEF, |
b014f94b JFM |
105 | }, |
106 | .set = sd_setbrightness, | |
107 | .get = sd_getbrightness, | |
108 | }, | |
2d19a2c1 | 109 | { /* 1 */ |
b014f94b JFM |
110 | { |
111 | .id = V4L2_CID_CONTRAST, | |
112 | .type = V4L2_CTRL_TYPE_INTEGER, | |
113 | .name = "Contrast", | |
114 | .minimum = 0, | |
115 | .maximum = 255, | |
116 | .step = 1, | |
8b7fbda4 | 117 | #define CONTRAST_DEF 32 |
c52af799 | 118 | .default_value = CONTRAST_DEF, |
b014f94b JFM |
119 | }, |
120 | .set = sd_setcontrast, | |
121 | .get = sd_getcontrast, | |
122 | }, | |
2d19a2c1 | 123 | { /* 2 */ |
189d92af JFM |
124 | { |
125 | .id = V4L2_CID_GAIN, | |
126 | .type = V4L2_CTRL_TYPE_INTEGER, | |
127 | .name = "Main Gain", | |
128 | .minimum = 0, | |
129 | .maximum = 63, | |
130 | .step = 1, | |
131 | #define GAIN_DEF 20 | |
132 | .default_value = GAIN_DEF, | |
133 | }, | |
134 | .set = sd_setgain, | |
135 | .get = sd_getgain, | |
136 | }, | |
2d19a2c1 | 137 | { /* 3 */ |
189d92af JFM |
138 | { |
139 | .id = V4L2_CID_EXPOSURE, | |
140 | .type = V4L2_CTRL_TYPE_INTEGER, | |
141 | .name = "Exposure", | |
142 | .minimum = 0, | |
143 | .maximum = 255, | |
144 | .step = 1, | |
c52af799 JFM |
145 | #define EXPO_DEF 120 |
146 | .default_value = EXPO_DEF, | |
189d92af JFM |
147 | }, |
148 | .set = sd_setexposure, | |
149 | .get = sd_getexposure, | |
150 | }, | |
2d19a2c1 | 151 | { /* 4 */ |
189d92af JFM |
152 | { |
153 | .id = V4L2_CID_AUTOGAIN, | |
154 | .type = V4L2_CTRL_TYPE_BOOLEAN, | |
8b7fbda4 | 155 | .name = "Auto Gain", |
189d92af JFM |
156 | .minimum = 0, |
157 | .maximum = 1, | |
158 | .step = 1, | |
8b7fbda4 MT |
159 | #define AGC_DEF 1 |
160 | .default_value = AGC_DEF, | |
189d92af | 161 | }, |
8b7fbda4 MT |
162 | .set = sd_setagc, |
163 | .get = sd_getagc, | |
189d92af | 164 | }, |
0c41acf1 AO |
165 | #define AWB_IDX 5 |
166 | { /* 5 */ | |
b014f94b JFM |
167 | { |
168 | .id = V4L2_CID_AUTO_WHITE_BALANCE, | |
169 | .type = V4L2_CTRL_TYPE_BOOLEAN, | |
170 | .name = "Auto White Balance", | |
171 | .minimum = 0, | |
172 | .maximum = 1, | |
173 | .step = 1, | |
8fef9d96 | 174 | #define AWB_DEF 1 |
b014f94b JFM |
175 | .default_value = AWB_DEF, |
176 | }, | |
177 | .set = sd_setawb, | |
178 | .get = sd_getawb, | |
179 | }, | |
0c41acf1 | 180 | { /* 6 */ |
f2938822 MT |
181 | { |
182 | .id = V4L2_CID_EXPOSURE_AUTO, | |
183 | .type = V4L2_CTRL_TYPE_BOOLEAN, | |
184 | .name = "Auto Exposure", | |
185 | .minimum = 0, | |
186 | .maximum = 1, | |
187 | .step = 1, | |
188 | #define AEC_DEF 1 | |
189 | .default_value = AEC_DEF, | |
190 | }, | |
191 | .set = sd_setaec, | |
192 | .get = sd_getaec, | |
193 | }, | |
194 | { /* 7 */ | |
189d92af JFM |
195 | { |
196 | .id = V4L2_CID_SHARPNESS, | |
197 | .type = V4L2_CTRL_TYPE_INTEGER, | |
198 | .name = "Sharpness", | |
199 | .minimum = 0, | |
200 | .maximum = 63, | |
201 | .step = 1, | |
c52af799 JFM |
202 | #define SHARPNESS_DEF 0 |
203 | .default_value = SHARPNESS_DEF, | |
189d92af JFM |
204 | }, |
205 | .set = sd_setsharpness, | |
206 | .get = sd_getsharpness, | |
207 | }, | |
f2938822 | 208 | { /* 8 */ |
189d92af JFM |
209 | { |
210 | .id = V4L2_CID_HFLIP, | |
211 | .type = V4L2_CTRL_TYPE_BOOLEAN, | |
212 | .name = "HFlip", | |
213 | .minimum = 0, | |
214 | .maximum = 1, | |
215 | .step = 1, | |
216 | #define HFLIP_DEF 0 | |
217 | .default_value = HFLIP_DEF, | |
218 | }, | |
219 | .set = sd_sethflip, | |
220 | .get = sd_gethflip, | |
221 | }, | |
f2938822 | 222 | { /* 9 */ |
189d92af JFM |
223 | { |
224 | .id = V4L2_CID_VFLIP, | |
225 | .type = V4L2_CTRL_TYPE_BOOLEAN, | |
226 | .name = "VFlip", | |
227 | .minimum = 0, | |
228 | .maximum = 1, | |
229 | .step = 1, | |
230 | #define VFLIP_DEF 0 | |
231 | .default_value = VFLIP_DEF, | |
232 | }, | |
233 | .set = sd_setvflip, | |
234 | .get = sd_getvflip, | |
235 | }, | |
236 | }; | |
fbb4c6d2 | 237 | |
569691a5 | 238 | static const struct v4l2_pix_format ov772x_mode[] = { |
189d92af JFM |
239 | {320, 240, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE, |
240 | .bytesperline = 320 * 2, | |
241 | .sizeimage = 320 * 240 * 2, | |
b014f94b | 242 | .colorspace = V4L2_COLORSPACE_SRGB, |
189d92af | 243 | .priv = 1}, |
fbb4c6d2 AO |
244 | {640, 480, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE, |
245 | .bytesperline = 640 * 2, | |
246 | .sizeimage = 640 * 480 * 2, | |
191d0e7f JFM |
247 | .colorspace = V4L2_COLORSPACE_SRGB, |
248 | .priv = 0}, | |
249 | }; | |
250 | ||
29b87f04 AO |
251 | static const u8 qvga_rates[] = {125, 100, 75, 60, 50, 40, 30}; |
252 | static const u8 vga_rates[] = {60, 50, 40, 30, 15}; | |
253 | ||
254 | static const struct framerates ov772x_framerates[] = { | |
255 | { /* 320x240 */ | |
256 | .rates = qvga_rates, | |
257 | .nrates = ARRAY_SIZE(qvga_rates), | |
258 | }, | |
259 | { /* 640x480 */ | |
260 | .rates = vga_rates, | |
261 | .nrates = ARRAY_SIZE(vga_rates), | |
262 | }, | |
263 | }; | |
264 | ||
c52af799 | 265 | static const u8 bridge_init[][2] = { |
47dfd21f JP |
266 | { 0xc2, 0x0c }, |
267 | { 0x88, 0xf8 }, | |
268 | { 0xc3, 0x69 }, | |
269 | { 0x89, 0xff }, | |
270 | { 0x76, 0x03 }, | |
271 | { 0x92, 0x01 }, | |
272 | { 0x93, 0x18 }, | |
273 | { 0x94, 0x10 }, | |
274 | { 0x95, 0x10 }, | |
275 | { 0xe2, 0x00 }, | |
276 | { 0xe7, 0x3e }, | |
277 | ||
47dfd21f JP |
278 | { 0x96, 0x00 }, |
279 | ||
280 | { 0x97, 0x20 }, | |
281 | { 0x97, 0x20 }, | |
282 | { 0x97, 0x20 }, | |
283 | { 0x97, 0x0a }, | |
284 | { 0x97, 0x3f }, | |
285 | { 0x97, 0x4a }, | |
286 | { 0x97, 0x20 }, | |
287 | { 0x97, 0x15 }, | |
288 | { 0x97, 0x0b }, | |
289 | ||
290 | { 0x8e, 0x40 }, | |
291 | { 0x1f, 0x81 }, | |
292 | { 0x34, 0x05 }, | |
293 | { 0xe3, 0x04 }, | |
294 | { 0x88, 0x00 }, | |
295 | { 0x89, 0x00 }, | |
296 | { 0x76, 0x00 }, | |
297 | { 0xe7, 0x2e }, | |
298 | { 0x31, 0xf9 }, | |
299 | { 0x25, 0x42 }, | |
300 | { 0x21, 0xf0 }, | |
301 | ||
302 | { 0x1c, 0x00 }, | |
303 | { 0x1d, 0x40 }, | |
0f7a50b2 JP |
304 | { 0x1d, 0x02 }, /* payload size 0x0200 * 4 = 2048 bytes */ |
305 | { 0x1d, 0x00 }, /* payload size */ | |
189d92af | 306 | |
5ea9c4de JP |
307 | { 0x1d, 0x02 }, /* frame size 0x025800 * 4 = 614400 */ |
308 | { 0x1d, 0x58 }, /* frame size */ | |
309 | { 0x1d, 0x00 }, /* frame size */ | |
47dfd21f | 310 | |
c06eb619 JP |
311 | { 0x1c, 0x0a }, |
312 | { 0x1d, 0x08 }, /* turn on UVC header */ | |
313 | { 0x1d, 0x0e }, /* .. */ | |
314 | ||
47dfd21f JP |
315 | { 0x8d, 0x1c }, |
316 | { 0x8e, 0x80 }, | |
317 | { 0xe5, 0x04 }, | |
318 | ||
319 | { 0xc0, 0x50 }, | |
320 | { 0xc1, 0x3c }, | |
321 | { 0xc2, 0x0c }, | |
322 | }; | |
c52af799 | 323 | static const u8 sensor_init[][2] = { |
47dfd21f JP |
324 | { 0x12, 0x80 }, |
325 | { 0x11, 0x01 }, | |
189d92af JFM |
326 | /*fixme: better have a delay?*/ |
327 | { 0x11, 0x01 }, | |
328 | { 0x11, 0x01 }, | |
329 | { 0x11, 0x01 }, | |
330 | { 0x11, 0x01 }, | |
331 | { 0x11, 0x01 }, | |
332 | { 0x11, 0x01 }, | |
333 | { 0x11, 0x01 }, | |
334 | { 0x11, 0x01 }, | |
335 | { 0x11, 0x01 }, | |
336 | { 0x11, 0x01 }, | |
47dfd21f JP |
337 | |
338 | { 0x3d, 0x03 }, | |
339 | { 0x17, 0x26 }, | |
340 | { 0x18, 0xa0 }, | |
341 | { 0x19, 0x07 }, | |
342 | { 0x1a, 0xf0 }, | |
343 | { 0x32, 0x00 }, | |
344 | { 0x29, 0xa0 }, | |
345 | { 0x2c, 0xf0 }, | |
346 | { 0x65, 0x20 }, | |
347 | { 0x11, 0x01 }, | |
348 | { 0x42, 0x7f }, | |
b014f94b | 349 | { 0x63, 0xaa }, /* AWB - was e0 */ |
47dfd21f JP |
350 | { 0x64, 0xff }, |
351 | { 0x66, 0x00 }, | |
b014f94b | 352 | { 0x13, 0xf0 }, /* com8 */ |
47dfd21f JP |
353 | { 0x0d, 0x41 }, |
354 | { 0x0f, 0xc5 }, | |
355 | { 0x14, 0x11 }, | |
356 | ||
357 | { 0x22, 0x7f }, | |
358 | { 0x23, 0x03 }, | |
359 | { 0x24, 0x40 }, | |
360 | { 0x25, 0x30 }, | |
361 | { 0x26, 0xa1 }, | |
362 | { 0x2a, 0x00 }, | |
363 | { 0x2b, 0x00 }, | |
364 | { 0x6b, 0xaa }, | |
b014f94b | 365 | { 0x13, 0xff }, /* AWB */ |
47dfd21f JP |
366 | |
367 | { 0x90, 0x05 }, | |
368 | { 0x91, 0x01 }, | |
369 | { 0x92, 0x03 }, | |
370 | { 0x93, 0x00 }, | |
371 | { 0x94, 0x60 }, | |
372 | { 0x95, 0x3c }, | |
373 | { 0x96, 0x24 }, | |
374 | { 0x97, 0x1e }, | |
375 | { 0x98, 0x62 }, | |
376 | { 0x99, 0x80 }, | |
377 | { 0x9a, 0x1e }, | |
378 | { 0x9b, 0x08 }, | |
379 | { 0x9c, 0x20 }, | |
380 | { 0x9e, 0x81 }, | |
381 | ||
382 | { 0xa6, 0x04 }, | |
383 | { 0x7e, 0x0c }, | |
384 | { 0x7f, 0x16 }, | |
385 | { 0x80, 0x2a }, | |
386 | { 0x81, 0x4e }, | |
387 | { 0x82, 0x61 }, | |
388 | { 0x83, 0x6f }, | |
389 | { 0x84, 0x7b }, | |
390 | { 0x85, 0x86 }, | |
391 | { 0x86, 0x8e }, | |
392 | { 0x87, 0x97 }, | |
393 | { 0x88, 0xa4 }, | |
394 | { 0x89, 0xaf }, | |
395 | { 0x8a, 0xc5 }, | |
396 | { 0x8b, 0xd7 }, | |
397 | { 0x8c, 0xe8 }, | |
398 | { 0x8d, 0x20 }, | |
399 | ||
400 | { 0x0c, 0x90 }, | |
401 | ||
402 | { 0x2b, 0x00 }, | |
403 | { 0x22, 0x7f }, | |
404 | { 0x23, 0x03 }, | |
405 | { 0x11, 0x01 }, | |
406 | { 0x0c, 0xd0 }, | |
407 | { 0x64, 0xff }, | |
408 | { 0x0d, 0x41 }, | |
409 | ||
410 | { 0x14, 0x41 }, | |
411 | { 0x0e, 0xcd }, | |
412 | { 0xac, 0xbf }, | |
b014f94b | 413 | { 0x8e, 0x00 }, /* De-noise threshold */ |
47dfd21f JP |
414 | { 0x0c, 0xd0 } |
415 | }; | |
c52af799 | 416 | static const u8 bridge_start_vga[][2] = { |
189d92af JFM |
417 | {0x1c, 0x00}, |
418 | {0x1d, 0x40}, | |
419 | {0x1d, 0x02}, | |
420 | {0x1d, 0x00}, | |
421 | {0x1d, 0x02}, | |
422 | {0x1d, 0x58}, | |
423 | {0x1d, 0x00}, | |
424 | {0xc0, 0x50}, | |
425 | {0xc1, 0x3c}, | |
426 | }; | |
c52af799 | 427 | static const u8 sensor_start_vga[][2] = { |
189d92af JFM |
428 | {0x12, 0x00}, |
429 | {0x17, 0x26}, | |
430 | {0x18, 0xa0}, | |
431 | {0x19, 0x07}, | |
432 | {0x1a, 0xf0}, | |
433 | {0x29, 0xa0}, | |
434 | {0x2c, 0xf0}, | |
b014f94b | 435 | {0x65, 0x20}, |
189d92af | 436 | }; |
c52af799 | 437 | static const u8 bridge_start_qvga[][2] = { |
189d92af JFM |
438 | {0x1c, 0x00}, |
439 | {0x1d, 0x40}, | |
440 | {0x1d, 0x02}, | |
441 | {0x1d, 0x00}, | |
442 | {0x1d, 0x01}, | |
443 | {0x1d, 0x4b}, | |
444 | {0x1d, 0x00}, | |
445 | {0xc0, 0x28}, | |
446 | {0xc1, 0x1e}, | |
447 | }; | |
c52af799 | 448 | static const u8 sensor_start_qvga[][2] = { |
189d92af JFM |
449 | {0x12, 0x40}, |
450 | {0x17, 0x3f}, | |
451 | {0x18, 0x50}, | |
452 | {0x19, 0x03}, | |
453 | {0x1a, 0x78}, | |
454 | {0x29, 0x50}, | |
455 | {0x2c, 0x78}, | |
b014f94b | 456 | {0x65, 0x2f}, |
189d92af | 457 | }; |
fbb4c6d2 | 458 | |
2ce949ec JFM |
459 | static void ov534_reg_write(struct gspca_dev *gspca_dev, u16 reg, u8 val) |
460 | { | |
461 | struct usb_device *udev = gspca_dev->dev; | |
462 | int ret; | |
463 | ||
464 | PDEBUG(D_USBO, "reg=0x%04x, val=0%02x", reg, val); | |
465 | gspca_dev->usb_buf[0] = val; | |
466 | ret = usb_control_msg(udev, | |
467 | usb_sndctrlpipe(udev, 0), | |
468 | 0x01, | |
469 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | |
470 | 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT); | |
471 | if (ret < 0) | |
472 | PDEBUG(D_ERR, "write failed"); | |
473 | } | |
474 | ||
475 | static u8 ov534_reg_read(struct gspca_dev *gspca_dev, u16 reg) | |
476 | { | |
477 | struct usb_device *udev = gspca_dev->dev; | |
478 | int ret; | |
479 | ||
480 | ret = usb_control_msg(udev, | |
481 | usb_rcvctrlpipe(udev, 0), | |
482 | 0x01, | |
483 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | |
484 | 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT); | |
485 | PDEBUG(D_USBI, "reg=0x%04x, data=0x%02x", reg, gspca_dev->usb_buf[0]); | |
486 | if (ret < 0) | |
487 | PDEBUG(D_ERR, "read failed"); | |
488 | return gspca_dev->usb_buf[0]; | |
489 | } | |
490 | ||
491 | /* Two bits control LED: 0x21 bit 7 and 0x23 bit 7. | |
492 | * (direction and output)? */ | |
493 | static void ov534_set_led(struct gspca_dev *gspca_dev, int status) | |
494 | { | |
495 | u8 data; | |
496 | ||
497 | PDEBUG(D_CONF, "led status: %d", status); | |
498 | ||
499 | data = ov534_reg_read(gspca_dev, 0x21); | |
500 | data |= 0x80; | |
501 | ov534_reg_write(gspca_dev, 0x21, data); | |
502 | ||
503 | data = ov534_reg_read(gspca_dev, 0x23); | |
504 | if (status) | |
505 | data |= 0x80; | |
506 | else | |
507 | data &= ~0x80; | |
508 | ||
509 | ov534_reg_write(gspca_dev, 0x23, data); | |
510 | ||
511 | if (!status) { | |
512 | data = ov534_reg_read(gspca_dev, 0x21); | |
513 | data &= ~0x80; | |
514 | ov534_reg_write(gspca_dev, 0x21, data); | |
515 | } | |
516 | } | |
517 | ||
518 | static int sccb_check_status(struct gspca_dev *gspca_dev) | |
519 | { | |
520 | u8 data; | |
521 | int i; | |
522 | ||
523 | for (i = 0; i < 5; i++) { | |
524 | data = ov534_reg_read(gspca_dev, OV534_REG_STATUS); | |
525 | ||
526 | switch (data) { | |
527 | case 0x00: | |
528 | return 1; | |
529 | case 0x04: | |
530 | return 0; | |
531 | case 0x03: | |
532 | break; | |
533 | default: | |
534 | PDEBUG(D_ERR, "sccb status 0x%02x, attempt %d/5", | |
535 | data, i + 1); | |
536 | } | |
537 | } | |
538 | return 0; | |
539 | } | |
540 | ||
541 | static void sccb_reg_write(struct gspca_dev *gspca_dev, u8 reg, u8 val) | |
542 | { | |
543 | PDEBUG(D_USBO, "reg: 0x%02x, val: 0x%02x", reg, val); | |
544 | ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg); | |
545 | ov534_reg_write(gspca_dev, OV534_REG_WRITE, val); | |
546 | ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_3); | |
547 | ||
548 | if (!sccb_check_status(gspca_dev)) | |
549 | PDEBUG(D_ERR, "sccb_reg_write failed"); | |
550 | } | |
551 | ||
552 | static u8 sccb_reg_read(struct gspca_dev *gspca_dev, u16 reg) | |
553 | { | |
554 | ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg); | |
555 | ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_2); | |
556 | if (!sccb_check_status(gspca_dev)) | |
557 | PDEBUG(D_ERR, "sccb_reg_read failed 1"); | |
558 | ||
559 | ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_READ_2); | |
560 | if (!sccb_check_status(gspca_dev)) | |
561 | PDEBUG(D_ERR, "sccb_reg_read failed 2"); | |
562 | ||
563 | return ov534_reg_read(gspca_dev, OV534_REG_READ); | |
564 | } | |
565 | ||
566 | /* output a bridge sequence (reg - val) */ | |
567 | static void reg_w_array(struct gspca_dev *gspca_dev, | |
568 | const u8 (*data)[2], int len) | |
569 | { | |
570 | while (--len >= 0) { | |
571 | ov534_reg_write(gspca_dev, (*data)[0], (*data)[1]); | |
572 | data++; | |
573 | } | |
574 | } | |
575 | ||
576 | /* output a sensor sequence (reg - val) */ | |
577 | static void sccb_w_array(struct gspca_dev *gspca_dev, | |
578 | const u8 (*data)[2], int len) | |
579 | { | |
580 | while (--len >= 0) { | |
581 | if ((*data)[0] != 0xff) { | |
582 | sccb_reg_write(gspca_dev, (*data)[0], (*data)[1]); | |
583 | } else { | |
584 | sccb_reg_read(gspca_dev, (*data)[1]); | |
585 | sccb_reg_write(gspca_dev, 0xff, 0x00); | |
586 | } | |
587 | data++; | |
588 | } | |
589 | } | |
590 | ||
69f1fe28 JFM |
591 | /* ov772x specific controls */ |
592 | static void set_frame_rate(struct gspca_dev *gspca_dev) | |
11d9f25d JP |
593 | { |
594 | struct sd *sd = (struct sd *) gspca_dev; | |
189d92af JFM |
595 | int i; |
596 | struct rate_s { | |
597 | u8 fps; | |
598 | u8 r11; | |
599 | u8 r0d; | |
600 | u8 re5; | |
601 | }; | |
602 | const struct rate_s *r; | |
603 | static const struct rate_s rate_0[] = { /* 640x480 */ | |
604 | {60, 0x01, 0xc1, 0x04}, | |
605 | {50, 0x01, 0x41, 0x02}, | |
606 | {40, 0x02, 0xc1, 0x04}, | |
607 | {30, 0x04, 0x81, 0x02}, | |
608 | {15, 0x03, 0x41, 0x04}, | |
609 | }; | |
610 | static const struct rate_s rate_1[] = { /* 320x240 */ | |
611 | {125, 0x02, 0x81, 0x02}, | |
612 | {100, 0x02, 0xc1, 0x04}, | |
613 | {75, 0x03, 0xc1, 0x04}, | |
614 | {60, 0x04, 0xc1, 0x04}, | |
615 | {50, 0x02, 0x41, 0x04}, | |
616 | {40, 0x03, 0x41, 0x04}, | |
617 | {30, 0x04, 0x41, 0x04}, | |
618 | }; | |
619 | ||
620 | if (gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv == 0) { | |
621 | r = rate_0; | |
622 | i = ARRAY_SIZE(rate_0); | |
623 | } else { | |
624 | r = rate_1; | |
625 | i = ARRAY_SIZE(rate_1); | |
626 | } | |
627 | while (--i > 0) { | |
628 | if (sd->frame_rate >= r->fps) | |
629 | break; | |
630 | r++; | |
631 | } | |
632 | ||
633 | sccb_reg_write(gspca_dev, 0x11, r->r11); | |
634 | sccb_reg_write(gspca_dev, 0x0d, r->r0d); | |
635 | ov534_reg_write(gspca_dev, 0xe5, r->re5); | |
636 | ||
637 | PDEBUG(D_PROBE, "frame_rate: %d", r->fps); | |
638 | } | |
639 | ||
c52af799 | 640 | static void setbrightness(struct gspca_dev *gspca_dev) |
b014f94b JFM |
641 | { |
642 | struct sd *sd = (struct sd *) gspca_dev; | |
643 | ||
644 | sccb_reg_write(gspca_dev, 0x9B, sd->brightness); | |
645 | } | |
646 | ||
c52af799 | 647 | static void setcontrast(struct gspca_dev *gspca_dev) |
b014f94b JFM |
648 | { |
649 | struct sd *sd = (struct sd *) gspca_dev; | |
650 | ||
651 | sccb_reg_write(gspca_dev, 0x9C, sd->contrast); | |
652 | } | |
653 | ||
189d92af JFM |
654 | static void setgain(struct gspca_dev *gspca_dev) |
655 | { | |
656 | struct sd *sd = (struct sd *) gspca_dev; | |
657 | u8 val; | |
11d9f25d | 658 | |
8b7fbda4 MT |
659 | if (sd->agc) |
660 | return; | |
661 | ||
189d92af JFM |
662 | val = sd->gain; |
663 | switch (val & 0x30) { | |
664 | case 0x00: | |
665 | val &= 0x0f; | |
11d9f25d | 666 | break; |
189d92af JFM |
667 | case 0x10: |
668 | val &= 0x0f; | |
669 | val |= 0x30; | |
11d9f25d | 670 | break; |
189d92af JFM |
671 | case 0x20: |
672 | val &= 0x0f; | |
673 | val |= 0x70; | |
11d9f25d | 674 | break; |
189d92af JFM |
675 | default: |
676 | /* case 0x30: */ | |
677 | val &= 0x0f; | |
678 | val |= 0xf0; | |
11d9f25d JP |
679 | break; |
680 | } | |
189d92af JFM |
681 | sccb_reg_write(gspca_dev, 0x00, val); |
682 | } | |
683 | ||
c52af799 | 684 | static void setexposure(struct gspca_dev *gspca_dev) |
189d92af JFM |
685 | { |
686 | struct sd *sd = (struct sd *) gspca_dev; | |
687 | u8 val; | |
688 | ||
18cf8c91 AO |
689 | if (sd->aec) |
690 | return; | |
691 | ||
692 | /* 'val' is one byte and represents half of the exposure value we are | |
693 | * going to set into registers, a two bytes value: | |
694 | * | |
695 | * MSB: ((u16) val << 1) >> 8 == val >> 7 | |
696 | * LSB: ((u16) val << 1) & 0xff == val << 1 | |
697 | */ | |
189d92af JFM |
698 | val = sd->exposure; |
699 | sccb_reg_write(gspca_dev, 0x08, val >> 7); | |
700 | sccb_reg_write(gspca_dev, 0x10, val << 1); | |
701 | } | |
702 | ||
8b7fbda4 | 703 | static void setagc(struct gspca_dev *gspca_dev) |
189d92af JFM |
704 | { |
705 | struct sd *sd = (struct sd *) gspca_dev; | |
706 | ||
8b7fbda4 MT |
707 | if (sd->agc) { |
708 | sccb_reg_write(gspca_dev, 0x13, | |
709 | sccb_reg_read(gspca_dev, 0x13) | 0x04); | |
189d92af JFM |
710 | sccb_reg_write(gspca_dev, 0x64, |
711 | sccb_reg_read(gspca_dev, 0x64) | 0x03); | |
712 | } else { | |
8b7fbda4 MT |
713 | sccb_reg_write(gspca_dev, 0x13, |
714 | sccb_reg_read(gspca_dev, 0x13) & ~0x04); | |
189d92af | 715 | sccb_reg_write(gspca_dev, 0x64, |
8b7fbda4 MT |
716 | sccb_reg_read(gspca_dev, 0x64) & ~0x03); |
717 | ||
718 | setgain(gspca_dev); | |
189d92af JFM |
719 | } |
720 | } | |
721 | ||
b014f94b JFM |
722 | static void setawb(struct gspca_dev *gspca_dev) |
723 | { | |
724 | struct sd *sd = (struct sd *) gspca_dev; | |
725 | ||
8fef9d96 MT |
726 | if (sd->awb) { |
727 | sccb_reg_write(gspca_dev, 0x13, | |
728 | sccb_reg_read(gspca_dev, 0x13) | 0x02); | |
729 | sccb_reg_write(gspca_dev, 0x63, | |
730 | sccb_reg_read(gspca_dev, 0x63) | 0xc0); | |
731 | } else { | |
732 | sccb_reg_write(gspca_dev, 0x13, | |
733 | sccb_reg_read(gspca_dev, 0x13) & ~0x02); | |
734 | sccb_reg_write(gspca_dev, 0x63, | |
735 | sccb_reg_read(gspca_dev, 0x63) & ~0xc0); | |
736 | } | |
b014f94b JFM |
737 | } |
738 | ||
f2938822 MT |
739 | static void setaec(struct gspca_dev *gspca_dev) |
740 | { | |
741 | struct sd *sd = (struct sd *) gspca_dev; | |
742 | ||
743 | if (sd->aec) | |
744 | sccb_reg_write(gspca_dev, 0x13, | |
745 | sccb_reg_read(gspca_dev, 0x13) | 0x01); | |
746 | else { | |
747 | sccb_reg_write(gspca_dev, 0x13, | |
748 | sccb_reg_read(gspca_dev, 0x13) & ~0x01); | |
749 | setexposure(gspca_dev); | |
750 | } | |
751 | } | |
752 | ||
c52af799 | 753 | static void setsharpness(struct gspca_dev *gspca_dev) |
189d92af JFM |
754 | { |
755 | struct sd *sd = (struct sd *) gspca_dev; | |
756 | u8 val; | |
757 | ||
758 | val = sd->sharpness; | |
759 | sccb_reg_write(gspca_dev, 0x91, val); /* vga noise */ | |
760 | sccb_reg_write(gspca_dev, 0x8e, val); /* qvga noise */ | |
761 | } | |
762 | ||
763 | static void sethflip(struct gspca_dev *gspca_dev) | |
764 | { | |
765 | struct sd *sd = (struct sd *) gspca_dev; | |
766 | ||
767 | if (sd->hflip == 0) | |
768 | sccb_reg_write(gspca_dev, 0x0c, | |
769 | sccb_reg_read(gspca_dev, 0x0c) | 0x40); | |
770 | else | |
771 | sccb_reg_write(gspca_dev, 0x0c, | |
772 | sccb_reg_read(gspca_dev, 0x0c) & 0xbf); | |
773 | } | |
774 | ||
775 | static void setvflip(struct gspca_dev *gspca_dev) | |
776 | { | |
777 | struct sd *sd = (struct sd *) gspca_dev; | |
778 | ||
779 | if (sd->vflip == 0) | |
780 | sccb_reg_write(gspca_dev, 0x0c, | |
781 | sccb_reg_read(gspca_dev, 0x0c) | 0x80); | |
782 | else | |
783 | sccb_reg_write(gspca_dev, 0x0c, | |
784 | sccb_reg_read(gspca_dev, 0x0c) & 0x7f); | |
11d9f25d | 785 | } |
fbb4c6d2 | 786 | |
fbb4c6d2 AO |
787 | /* this function is called at probe time */ |
788 | static int sd_config(struct gspca_dev *gspca_dev, | |
789 | const struct usb_device_id *id) | |
790 | { | |
2ce949ec | 791 | struct sd *sd = (struct sd *) gspca_dev; |
fbb4c6d2 AO |
792 | struct cam *cam; |
793 | ||
794 | cam = &gspca_dev->cam; | |
795 | ||
c52af799 JFM |
796 | cam->cam_mode = ov772x_mode; |
797 | cam->nmodes = ARRAY_SIZE(ov772x_mode); | |
29b87f04 | 798 | cam->mode_framerates = ov772x_framerates; |
191d0e7f | 799 | |
c52af799 JFM |
800 | cam->bulk = 1; |
801 | cam->bulk_size = 16384; | |
802 | cam->bulk_nurbs = 2; | |
fbb4c6d2 | 803 | |
189d92af | 804 | sd->frame_rate = 30; |
b014f94b | 805 | |
c52af799 JFM |
806 | sd->brightness = BRIGHTNESS_DEF; |
807 | sd->contrast = CONTRAST_DEF; | |
808 | sd->gain = GAIN_DEF; | |
809 | sd->exposure = EXPO_DEF; | |
8b7fbda4 MT |
810 | #if AGC_DEF != 0 |
811 | sd->agc = AGC_DEF; | |
2d19a2c1 | 812 | #else |
c52af799 | 813 | gspca_dev->ctrl_inac |= (1 << AWB_IDX); |
b014f94b | 814 | #endif |
8fef9d96 | 815 | sd->awb = AWB_DEF; |
f2938822 | 816 | sd->aec = AEC_DEF; |
c52af799 JFM |
817 | #if SHARPNESS_DEF != 0 |
818 | sd->sharpness = SHARPNESS_DEF; | |
b014f94b | 819 | #endif |
189d92af | 820 | #if HFLIP_DEF != 0 |
c52af799 | 821 | sd->hflip = HFLIP_DEF; |
189d92af JFM |
822 | #endif |
823 | #if VFLIP_DEF != 0 | |
c52af799 | 824 | sd->vflip = VFLIP_DEF; |
c22c4a20 | 825 | #endif |
c52af799 | 826 | |
fbb4c6d2 AO |
827 | return 0; |
828 | } | |
829 | ||
830 | /* this function is called at probe and resume time */ | |
831 | static int sd_init(struct gspca_dev *gspca_dev) | |
832 | { | |
2ce949ec | 833 | u16 sensor_id; |
2ce949ec JFM |
834 | |
835 | /* reset bridge */ | |
836 | ov534_reg_write(gspca_dev, 0xe7, 0x3a); | |
837 | ov534_reg_write(gspca_dev, 0xe0, 0x08); | |
838 | msleep(100); | |
839 | ||
840 | /* initialize the sensor address */ | |
c52af799 | 841 | ov534_reg_write(gspca_dev, OV534_REG_ADDRESS, 0x42); |
2ce949ec JFM |
842 | |
843 | /* reset sensor */ | |
844 | sccb_reg_write(gspca_dev, 0x12, 0x80); | |
845 | msleep(10); | |
846 | ||
847 | /* probe the sensor */ | |
848 | sccb_reg_read(gspca_dev, 0x0a); | |
849 | sensor_id = sccb_reg_read(gspca_dev, 0x0a) << 8; | |
850 | sccb_reg_read(gspca_dev, 0x0b); | |
851 | sensor_id |= sccb_reg_read(gspca_dev, 0x0b); | |
852 | PDEBUG(D_PROBE, "Sensor ID: %04x", sensor_id); | |
853 | ||
854 | /* initialize */ | |
c52af799 JFM |
855 | reg_w_array(gspca_dev, bridge_init, |
856 | ARRAY_SIZE(bridge_init)); | |
857 | ov534_set_led(gspca_dev, 1); | |
858 | sccb_w_array(gspca_dev, sensor_init, | |
859 | ARRAY_SIZE(sensor_init)); | |
860 | ov534_reg_write(gspca_dev, 0xe0, 0x09); | |
861 | ov534_set_led(gspca_dev, 0); | |
862 | set_frame_rate(gspca_dev); | |
fbb4c6d2 AO |
863 | |
864 | return 0; | |
865 | } | |
866 | ||
c52af799 | 867 | static int sd_start(struct gspca_dev *gspca_dev) |
fbb4c6d2 | 868 | { |
191d0e7f | 869 | int mode; |
fbb4c6d2 | 870 | |
189d92af JFM |
871 | mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv; |
872 | if (mode != 0) { /* 320x240 */ | |
c52af799 JFM |
873 | reg_w_array(gspca_dev, bridge_start_qvga, |
874 | ARRAY_SIZE(bridge_start_qvga)); | |
875 | sccb_w_array(gspca_dev, sensor_start_qvga, | |
876 | ARRAY_SIZE(sensor_start_qvga)); | |
189d92af | 877 | } else { /* 640x480 */ |
c52af799 JFM |
878 | reg_w_array(gspca_dev, bridge_start_vga, |
879 | ARRAY_SIZE(bridge_start_vga)); | |
880 | sccb_w_array(gspca_dev, sensor_start_vga, | |
881 | ARRAY_SIZE(sensor_start_vga)); | |
2ce949ec | 882 | } |
69f1fe28 | 883 | set_frame_rate(gspca_dev); |
189d92af | 884 | |
8b7fbda4 | 885 | setagc(gspca_dev); |
b014f94b | 886 | setawb(gspca_dev); |
f2938822 | 887 | setaec(gspca_dev); |
189d92af | 888 | setgain(gspca_dev); |
c52af799 JFM |
889 | setexposure(gspca_dev); |
890 | setbrightness(gspca_dev); | |
891 | setcontrast(gspca_dev); | |
892 | setsharpness(gspca_dev); | |
189d92af JFM |
893 | setvflip(gspca_dev); |
894 | sethflip(gspca_dev); | |
895 | ||
896 | ov534_set_led(gspca_dev, 1); | |
897 | ov534_reg_write(gspca_dev, 0xe0, 0x00); | |
fbb4c6d2 AO |
898 | return 0; |
899 | } | |
900 | ||
c52af799 | 901 | static void sd_stopN(struct gspca_dev *gspca_dev) |
189d92af JFM |
902 | { |
903 | ov534_reg_write(gspca_dev, 0xe0, 0x09); | |
904 | ov534_set_led(gspca_dev, 0); | |
905 | } | |
906 | ||
fb139224 JP |
907 | /* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */ |
908 | #define UVC_STREAM_EOH (1 << 7) | |
909 | #define UVC_STREAM_ERR (1 << 6) | |
910 | #define UVC_STREAM_STI (1 << 5) | |
911 | #define UVC_STREAM_RES (1 << 4) | |
912 | #define UVC_STREAM_SCR (1 << 3) | |
913 | #define UVC_STREAM_PTS (1 << 2) | |
914 | #define UVC_STREAM_EOF (1 << 1) | |
915 | #define UVC_STREAM_FID (1 << 0) | |
916 | ||
76dd272b JFM |
917 | static void sd_pkt_scan(struct gspca_dev *gspca_dev, |
918 | u8 *data, int len) | |
fbb4c6d2 | 919 | { |
8c252050 | 920 | struct sd *sd = (struct sd *) gspca_dev; |
fb139224 | 921 | __u32 this_pts; |
84fbdf87 | 922 | u16 this_fid; |
0f7a50b2 | 923 | int remaining_len = len; |
0f7a50b2 | 924 | |
84fbdf87 | 925 | do { |
c52af799 | 926 | len = min(remaining_len, 2048); |
fb139224 | 927 | |
84fbdf87 JFM |
928 | /* Payloads are prefixed with a UVC-style header. We |
929 | consider a frame to start when the FID toggles, or the PTS | |
930 | changes. A frame ends when EOF is set, and we've received | |
931 | the correct number of bytes. */ | |
fb139224 | 932 | |
84fbdf87 JFM |
933 | /* Verify UVC header. Header length is always 12 */ |
934 | if (data[0] != 12 || len < 12) { | |
935 | PDEBUG(D_PACK, "bad header"); | |
936 | goto discard; | |
937 | } | |
fb139224 | 938 | |
84fbdf87 JFM |
939 | /* Check errors */ |
940 | if (data[1] & UVC_STREAM_ERR) { | |
941 | PDEBUG(D_PACK, "payload error"); | |
942 | goto discard; | |
943 | } | |
fb139224 | 944 | |
84fbdf87 JFM |
945 | /* Extract PTS and FID */ |
946 | if (!(data[1] & UVC_STREAM_PTS)) { | |
947 | PDEBUG(D_PACK, "PTS not present"); | |
fb139224 JP |
948 | goto discard; |
949 | } | |
84fbdf87 JFM |
950 | this_pts = (data[5] << 24) | (data[4] << 16) |
951 | | (data[3] << 8) | data[2]; | |
952 | this_fid = (data[1] & UVC_STREAM_FID) ? 1 : 0; | |
fb139224 | 953 | |
84fbdf87 JFM |
954 | /* If PTS or FID has changed, start a new frame. */ |
955 | if (this_pts != sd->last_pts || this_fid != sd->last_fid) { | |
ed47119f | 956 | if (gspca_dev->last_packet_type == INTER_PACKET) |
76dd272b JFM |
957 | gspca_frame_add(gspca_dev, LAST_PACKET, |
958 | NULL, 0); | |
84fbdf87 JFM |
959 | sd->last_pts = this_pts; |
960 | sd->last_fid = this_fid; | |
76dd272b | 961 | gspca_frame_add(gspca_dev, FIRST_PACKET, |
84fbdf87 | 962 | data + 12, len - 12); |
84fbdf87 | 963 | /* If this packet is marked as EOF, end the frame */ |
ed47119f | 964 | } else if (data[1] & UVC_STREAM_EOF) { |
c52af799 JFM |
965 | struct gspca_frame *frame; |
966 | ||
84fbdf87 | 967 | sd->last_pts = 0; |
c52af799 JFM |
968 | frame = gspca_get_i_frame(gspca_dev); |
969 | if (frame == NULL) | |
970 | goto discard; | |
11edebc2 | 971 | if (frame->data_end - frame->data + (len - 12) != |
c52af799 | 972 | gspca_dev->width * gspca_dev->height * 2) { |
11edebc2 | 973 | PDEBUG(D_PACK, "wrong sized frame"); |
c52af799 JFM |
974 | goto discard; |
975 | } | |
76dd272b JFM |
976 | gspca_frame_add(gspca_dev, LAST_PACKET, |
977 | data + 12, len - 12); | |
ed47119f JFM |
978 | } else { |
979 | ||
980 | /* Add the data from this payload */ | |
76dd272b JFM |
981 | gspca_frame_add(gspca_dev, INTER_PACKET, |
982 | data + 12, len - 12); | |
3481c198 | 983 | } |
fb139224 | 984 | |
84fbdf87 JFM |
985 | /* Done this payload */ |
986 | goto scan_next; | |
fb139224 JP |
987 | |
988 | discard: | |
84fbdf87 | 989 | /* Discard data until a new frame starts. */ |
76dd272b | 990 | gspca_dev->last_packet_type = DISCARD_PACKET; |
84fbdf87 JFM |
991 | |
992 | scan_next: | |
993 | remaining_len -= len; | |
994 | data += len; | |
995 | } while (remaining_len > 0); | |
fbb4c6d2 AO |
996 | } |
997 | ||
c22c4a20 | 998 | /* controls */ |
189d92af JFM |
999 | static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val) |
1000 | { | |
1001 | struct sd *sd = (struct sd *) gspca_dev; | |
1002 | ||
1003 | sd->gain = val; | |
1004 | if (gspca_dev->streaming) | |
1005 | setgain(gspca_dev); | |
1006 | return 0; | |
1007 | } | |
1008 | ||
1009 | static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val) | |
1010 | { | |
1011 | struct sd *sd = (struct sd *) gspca_dev; | |
1012 | ||
1013 | *val = sd->gain; | |
1014 | return 0; | |
1015 | } | |
1016 | ||
1017 | static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val) | |
1018 | { | |
1019 | struct sd *sd = (struct sd *) gspca_dev; | |
1020 | ||
1021 | sd->exposure = val; | |
c52af799 JFM |
1022 | if (gspca_dev->streaming) |
1023 | setexposure(gspca_dev); | |
189d92af JFM |
1024 | return 0; |
1025 | } | |
1026 | ||
1027 | static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val) | |
1028 | { | |
1029 | struct sd *sd = (struct sd *) gspca_dev; | |
1030 | ||
1031 | *val = sd->exposure; | |
1032 | return 0; | |
1033 | } | |
1034 | ||
b014f94b JFM |
1035 | static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) |
1036 | { | |
1037 | struct sd *sd = (struct sd *) gspca_dev; | |
1038 | ||
1039 | sd->brightness = val; | |
c52af799 JFM |
1040 | if (gspca_dev->streaming) |
1041 | setbrightness(gspca_dev); | |
b014f94b JFM |
1042 | return 0; |
1043 | } | |
1044 | ||
1045 | static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val) | |
1046 | { | |
1047 | struct sd *sd = (struct sd *) gspca_dev; | |
1048 | ||
1049 | *val = sd->brightness; | |
1050 | return 0; | |
1051 | } | |
1052 | ||
1053 | static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val) | |
1054 | { | |
1055 | struct sd *sd = (struct sd *) gspca_dev; | |
1056 | ||
1057 | sd->contrast = val; | |
c52af799 JFM |
1058 | if (gspca_dev->streaming) |
1059 | setcontrast(gspca_dev); | |
b014f94b JFM |
1060 | return 0; |
1061 | } | |
1062 | ||
1063 | static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val) | |
1064 | { | |
1065 | struct sd *sd = (struct sd *) gspca_dev; | |
1066 | ||
1067 | *val = sd->contrast; | |
1068 | return 0; | |
1069 | } | |
1070 | ||
8b7fbda4 | 1071 | static int sd_setagc(struct gspca_dev *gspca_dev, __s32 val) |
189d92af JFM |
1072 | { |
1073 | struct sd *sd = (struct sd *) gspca_dev; | |
1074 | ||
8b7fbda4 | 1075 | sd->agc = val; |
2d19a2c1 | 1076 | |
c22c4a20 | 1077 | if (gspca_dev->streaming) { |
c52af799 JFM |
1078 | |
1079 | /* the auto white balance control works only | |
1080 | * when auto gain is set */ | |
1081 | if (val) | |
1082 | gspca_dev->ctrl_inac &= ~(1 << AWB_IDX); | |
1083 | else | |
1084 | gspca_dev->ctrl_inac |= (1 << AWB_IDX); | |
8b7fbda4 | 1085 | setagc(gspca_dev); |
c22c4a20 | 1086 | } |
189d92af JFM |
1087 | return 0; |
1088 | } | |
1089 | ||
8b7fbda4 | 1090 | static int sd_getagc(struct gspca_dev *gspca_dev, __s32 *val) |
189d92af JFM |
1091 | { |
1092 | struct sd *sd = (struct sd *) gspca_dev; | |
1093 | ||
8b7fbda4 | 1094 | *val = sd->agc; |
189d92af JFM |
1095 | return 0; |
1096 | } | |
1097 | ||
b014f94b JFM |
1098 | static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val) |
1099 | { | |
1100 | struct sd *sd = (struct sd *) gspca_dev; | |
1101 | ||
1102 | sd->awb = val; | |
1103 | if (gspca_dev->streaming) | |
1104 | setawb(gspca_dev); | |
1105 | return 0; | |
1106 | } | |
1107 | ||
1108 | static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val) | |
1109 | { | |
1110 | struct sd *sd = (struct sd *) gspca_dev; | |
1111 | ||
1112 | *val = sd->awb; | |
1113 | return 0; | |
1114 | } | |
1115 | ||
f2938822 MT |
1116 | static int sd_setaec(struct gspca_dev *gspca_dev, __s32 val) |
1117 | { | |
1118 | struct sd *sd = (struct sd *) gspca_dev; | |
1119 | ||
1120 | sd->aec = val; | |
1121 | if (gspca_dev->streaming) | |
1122 | setaec(gspca_dev); | |
1123 | return 0; | |
1124 | } | |
1125 | ||
1126 | static int sd_getaec(struct gspca_dev *gspca_dev, __s32 *val) | |
1127 | { | |
1128 | struct sd *sd = (struct sd *) gspca_dev; | |
1129 | ||
1130 | *val = sd->aec; | |
1131 | return 0; | |
1132 | } | |
1133 | ||
189d92af JFM |
1134 | static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val) |
1135 | { | |
1136 | struct sd *sd = (struct sd *) gspca_dev; | |
1137 | ||
1138 | sd->sharpness = val; | |
c52af799 JFM |
1139 | if (gspca_dev->streaming) |
1140 | setsharpness(gspca_dev); | |
189d92af JFM |
1141 | return 0; |
1142 | } | |
1143 | ||
1144 | static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val) | |
1145 | { | |
1146 | struct sd *sd = (struct sd *) gspca_dev; | |
1147 | ||
1148 | *val = sd->sharpness; | |
1149 | return 0; | |
1150 | } | |
1151 | ||
1152 | static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val) | |
1153 | { | |
1154 | struct sd *sd = (struct sd *) gspca_dev; | |
1155 | ||
1156 | sd->hflip = val; | |
1157 | if (gspca_dev->streaming) | |
1158 | sethflip(gspca_dev); | |
1159 | return 0; | |
1160 | } | |
1161 | ||
1162 | static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val) | |
1163 | { | |
1164 | struct sd *sd = (struct sd *) gspca_dev; | |
1165 | ||
1166 | *val = sd->hflip; | |
1167 | return 0; | |
1168 | } | |
1169 | ||
1170 | static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val) | |
1171 | { | |
1172 | struct sd *sd = (struct sd *) gspca_dev; | |
1173 | ||
1174 | sd->vflip = val; | |
1175 | if (gspca_dev->streaming) | |
1176 | setvflip(gspca_dev); | |
1177 | return 0; | |
1178 | } | |
1179 | ||
1180 | static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val) | |
1181 | { | |
1182 | struct sd *sd = (struct sd *) gspca_dev; | |
1183 | ||
1184 | *val = sd->vflip; | |
1185 | return 0; | |
1186 | } | |
1187 | ||
11d9f25d | 1188 | /* get stream parameters (framerate) */ |
5c1a15a1 JFM |
1189 | static int sd_get_streamparm(struct gspca_dev *gspca_dev, |
1190 | struct v4l2_streamparm *parm) | |
11d9f25d JP |
1191 | { |
1192 | struct v4l2_captureparm *cp = &parm->parm.capture; | |
1193 | struct v4l2_fract *tpf = &cp->timeperframe; | |
1194 | struct sd *sd = (struct sd *) gspca_dev; | |
1195 | ||
1196 | if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | |
1197 | return -EINVAL; | |
1198 | ||
1199 | cp->capability |= V4L2_CAP_TIMEPERFRAME; | |
1200 | tpf->numerator = 1; | |
1201 | tpf->denominator = sd->frame_rate; | |
1202 | ||
1203 | return 0; | |
1204 | } | |
1205 | ||
1206 | /* set stream parameters (framerate) */ | |
5c1a15a1 JFM |
1207 | static int sd_set_streamparm(struct gspca_dev *gspca_dev, |
1208 | struct v4l2_streamparm *parm) | |
11d9f25d JP |
1209 | { |
1210 | struct v4l2_captureparm *cp = &parm->parm.capture; | |
1211 | struct v4l2_fract *tpf = &cp->timeperframe; | |
1212 | struct sd *sd = (struct sd *) gspca_dev; | |
1213 | ||
1214 | if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | |
1215 | return -EINVAL; | |
1216 | ||
1217 | /* Set requested framerate */ | |
1218 | sd->frame_rate = tpf->denominator / tpf->numerator; | |
c52af799 | 1219 | if (gspca_dev->streaming) |
69f1fe28 | 1220 | set_frame_rate(gspca_dev); |
11d9f25d JP |
1221 | |
1222 | /* Return the actual framerate */ | |
1223 | tpf->numerator = 1; | |
1224 | tpf->denominator = sd->frame_rate; | |
1225 | ||
1226 | return 0; | |
1227 | } | |
1228 | ||
fbb4c6d2 | 1229 | /* sub-driver description */ |
c52af799 | 1230 | static const struct sd_desc sd_desc = { |
fbb4c6d2 | 1231 | .name = MODULE_NAME, |
c52af799 JFM |
1232 | .ctrls = sd_ctrls, |
1233 | .nctrls = ARRAY_SIZE(sd_ctrls), | |
fbb4c6d2 AO |
1234 | .config = sd_config, |
1235 | .init = sd_init, | |
c52af799 JFM |
1236 | .start = sd_start, |
1237 | .stopN = sd_stopN, | |
189d92af JFM |
1238 | .pkt_scan = sd_pkt_scan, |
1239 | .get_streamparm = sd_get_streamparm, | |
1240 | .set_streamparm = sd_set_streamparm, | |
1241 | }; | |
1242 | ||
fbb4c6d2 AO |
1243 | /* -- module initialisation -- */ |
1244 | static const __devinitdata struct usb_device_id device_table[] = { | |
c52af799 | 1245 | {USB_DEVICE(0x1415, 0x2000)}, |
fbb4c6d2 AO |
1246 | {} |
1247 | }; | |
1248 | ||
1249 | MODULE_DEVICE_TABLE(usb, device_table); | |
1250 | ||
1251 | /* -- device connect -- */ | |
1252 | static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id) | |
1253 | { | |
c52af799 | 1254 | return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd), |
189d92af | 1255 | THIS_MODULE); |
fbb4c6d2 AO |
1256 | } |
1257 | ||
1258 | static struct usb_driver sd_driver = { | |
1259 | .name = MODULE_NAME, | |
1260 | .id_table = device_table, | |
1261 | .probe = sd_probe, | |
1262 | .disconnect = gspca_disconnect, | |
1263 | #ifdef CONFIG_PM | |
1264 | .suspend = gspca_suspend, | |
1265 | .resume = gspca_resume, | |
1266 | #endif | |
1267 | }; | |
1268 | ||
1269 | /* -- module insert / remove -- */ | |
1270 | static int __init sd_mod_init(void) | |
1271 | { | |
f69e9529 | 1272 | int ret; |
189d92af | 1273 | |
f69e9529 AK |
1274 | ret = usb_register(&sd_driver); |
1275 | if (ret < 0) | |
e6b14849 | 1276 | return ret; |
fbb4c6d2 AO |
1277 | PDEBUG(D_PROBE, "registered"); |
1278 | return 0; | |
1279 | } | |
1280 | ||
1281 | static void __exit sd_mod_exit(void) | |
1282 | { | |
1283 | usb_deregister(&sd_driver); | |
1284 | PDEBUG(D_PROBE, "deregistered"); | |
1285 | } | |
1286 | ||
1287 | module_init(sd_mod_init); | |
1288 | module_exit(sd_mod_exit); |