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