diff options
Diffstat (limited to 'drivers/media/video/gspca/pac7302.c')
-rw-r--r-- | drivers/media/video/gspca/pac7302.c | 1272 |
1 files changed, 1272 insertions, 0 deletions
diff --git a/drivers/media/video/gspca/pac7302.c b/drivers/media/video/gspca/pac7302.c new file mode 100644 index 000000000000..74acceea8094 --- /dev/null +++ b/drivers/media/video/gspca/pac7302.c | |||
@@ -0,0 +1,1272 @@ | |||
1 | /* | ||
2 | * Pixart PAC7302 library | ||
3 | * Copyright (C) 2005 Thomas Kaiser thomas@kaiser-linux.li | ||
4 | * | ||
5 | * V4L2 by Jean-Francois Moine <http://moinejf.free.fr> | ||
6 | * | ||
7 | * Separated from Pixart PAC7311 library by Márton Németh <nm127@freemail.hu> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
22 | */ | ||
23 | |||
24 | /* Some documentation about various registers as determined by trial and error. | ||
25 | When the register addresses differ between the 7202 and the 7311 the 2 | ||
26 | different addresses are written as 7302addr/7311addr, when one of the 2 | ||
27 | addresses is a - sign that register description is not valid for the | ||
28 | matching IC. | ||
29 | |||
30 | Register page 1: | ||
31 | |||
32 | Address Description | ||
33 | -/0x08 Unknown compressor related, must always be 8 except when not | ||
34 | in 640x480 resolution and page 4 reg 2 <= 3 then set it to 9 ! | ||
35 | -/0x1b Auto white balance related, bit 0 is AWB enable (inverted) | ||
36 | bits 345 seem to toggle per color gains on/off (inverted) | ||
37 | 0x78 Global control, bit 6 controls the LED (inverted) | ||
38 | -/0x80 JPEG compression ratio ? Best not touched | ||
39 | |||
40 | Register page 3/4: | ||
41 | |||
42 | Address Description | ||
43 | 0x02 Clock divider 2-63, fps =~ 60 / val. Must be a multiple of 3 on | ||
44 | the 7302, so one of 3, 6, 9, ..., except when between 6 and 12? | ||
45 | -/0x0f Master gain 1-245, low value = high gain | ||
46 | 0x10/- Master gain 0-31 | ||
47 | -/0x10 Another gain 0-15, limited influence (1-2x gain I guess) | ||
48 | 0x21 Bitfield: 0-1 unused, 2-3 vflip/hflip, 4-5 unknown, 6-7 unused | ||
49 | -/0x27 Seems to toggle various gains on / off, Setting bit 7 seems to | ||
50 | completely disable the analog amplification block. Set to 0x68 | ||
51 | for max gain, 0x14 for minimal gain. | ||
52 | |||
53 | The registers are accessed in the following functions: | ||
54 | |||
55 | Page | Register | Function | ||
56 | -----+------------+--------------------------------------------------- | ||
57 | 0 | 0x0f..0x20 | setcolors() | ||
58 | 0 | 0xa2..0xab | setbrightcont() | ||
59 | 0 | 0xc5 | setredbalance() | ||
60 | 0 | 0xc6 | setwhitebalance() | ||
61 | 0 | 0xc7 | setbluebalance() | ||
62 | 0 | 0xdc | setbrightcont(), setcolors() | ||
63 | 3 | 0x02 | setexposure() | ||
64 | 3 | 0x10 | setgain() | ||
65 | 3 | 0x11 | setcolors(), setgain(), setexposure(), sethvflip() | ||
66 | 3 | 0x21 | sethvflip() | ||
67 | */ | ||
68 | |||
69 | #define MODULE_NAME "pac7302" | ||
70 | |||
71 | #include <media/v4l2-chip-ident.h> | ||
72 | #include "gspca.h" | ||
73 | |||
74 | MODULE_AUTHOR("Thomas Kaiser thomas@kaiser-linux.li"); | ||
75 | MODULE_DESCRIPTION("Pixart PAC7302"); | ||
76 | MODULE_LICENSE("GPL"); | ||
77 | |||
78 | /* specific webcam descriptor for pac7302 */ | ||
79 | struct sd { | ||
80 | struct gspca_dev gspca_dev; /* !! must be the first item */ | ||
81 | |||
82 | unsigned char brightness; | ||
83 | unsigned char contrast; | ||
84 | unsigned char colors; | ||
85 | unsigned char white_balance; | ||
86 | unsigned char red_balance; | ||
87 | unsigned char blue_balance; | ||
88 | unsigned char gain; | ||
89 | unsigned char exposure; | ||
90 | unsigned char autogain; | ||
91 | __u8 hflip; | ||
92 | __u8 vflip; | ||
93 | |||
94 | u8 sof_read; | ||
95 | u8 autogain_ignore_frames; | ||
96 | |||
97 | atomic_t avg_lum; | ||
98 | }; | ||
99 | |||
100 | /* V4L2 controls supported by the driver */ | ||
101 | static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); | ||
102 | static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); | ||
103 | static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val); | ||
104 | static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val); | ||
105 | static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val); | ||
106 | static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val); | ||
107 | static int sd_setwhitebalance(struct gspca_dev *gspca_dev, __s32 val); | ||
108 | static int sd_getwhitebalance(struct gspca_dev *gspca_dev, __s32 *val); | ||
109 | static int sd_setredbalance(struct gspca_dev *gspca_dev, __s32 val); | ||
110 | static int sd_getredbalance(struct gspca_dev *gspca_dev, __s32 *val); | ||
111 | static int sd_setbluebalance(struct gspca_dev *gspca_dev, __s32 val); | ||
112 | static int sd_getbluebalance(struct gspca_dev *gspca_dev, __s32 *val); | ||
113 | static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val); | ||
114 | static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val); | ||
115 | static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val); | ||
116 | static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val); | ||
117 | static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val); | ||
118 | static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val); | ||
119 | static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val); | ||
120 | static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val); | ||
121 | static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val); | ||
122 | static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val); | ||
123 | |||
124 | static struct ctrl sd_ctrls[] = { | ||
125 | /* This control is pac7302 only */ | ||
126 | { | ||
127 | { | ||
128 | .id = V4L2_CID_BRIGHTNESS, | ||
129 | .type = V4L2_CTRL_TYPE_INTEGER, | ||
130 | .name = "Brightness", | ||
131 | .minimum = 0, | ||
132 | #define BRIGHTNESS_MAX 0x20 | ||
133 | .maximum = BRIGHTNESS_MAX, | ||
134 | .step = 1, | ||
135 | #define BRIGHTNESS_DEF 0x10 | ||
136 | .default_value = BRIGHTNESS_DEF, | ||
137 | }, | ||
138 | .set = sd_setbrightness, | ||
139 | .get = sd_getbrightness, | ||
140 | }, | ||
141 | /* This control is for both the 7302 and the 7311 */ | ||
142 | { | ||
143 | { | ||
144 | .id = V4L2_CID_CONTRAST, | ||
145 | .type = V4L2_CTRL_TYPE_INTEGER, | ||
146 | .name = "Contrast", | ||
147 | .minimum = 0, | ||
148 | #define CONTRAST_MAX 255 | ||
149 | .maximum = CONTRAST_MAX, | ||
150 | .step = 1, | ||
151 | #define CONTRAST_DEF 127 | ||
152 | .default_value = CONTRAST_DEF, | ||
153 | }, | ||
154 | .set = sd_setcontrast, | ||
155 | .get = sd_getcontrast, | ||
156 | }, | ||
157 | /* This control is pac7302 only */ | ||
158 | { | ||
159 | { | ||
160 | .id = V4L2_CID_SATURATION, | ||
161 | .type = V4L2_CTRL_TYPE_INTEGER, | ||
162 | .name = "Saturation", | ||
163 | .minimum = 0, | ||
164 | #define COLOR_MAX 255 | ||
165 | .maximum = COLOR_MAX, | ||
166 | .step = 1, | ||
167 | #define COLOR_DEF 127 | ||
168 | .default_value = COLOR_DEF, | ||
169 | }, | ||
170 | .set = sd_setcolors, | ||
171 | .get = sd_getcolors, | ||
172 | }, | ||
173 | { | ||
174 | { | ||
175 | .id = V4L2_CID_WHITE_BALANCE_TEMPERATURE, | ||
176 | .type = V4L2_CTRL_TYPE_INTEGER, | ||
177 | .name = "White Balance", | ||
178 | .minimum = 0, | ||
179 | .maximum = 255, | ||
180 | .step = 1, | ||
181 | #define WHITEBALANCE_DEF 4 | ||
182 | .default_value = WHITEBALANCE_DEF, | ||
183 | }, | ||
184 | .set = sd_setwhitebalance, | ||
185 | .get = sd_getwhitebalance, | ||
186 | }, | ||
187 | { | ||
188 | { | ||
189 | .id = V4L2_CID_RED_BALANCE, | ||
190 | .type = V4L2_CTRL_TYPE_INTEGER, | ||
191 | .name = "Red", | ||
192 | .minimum = 0, | ||
193 | .maximum = 3, | ||
194 | .step = 1, | ||
195 | #define REDBALANCE_DEF 1 | ||
196 | .default_value = REDBALANCE_DEF, | ||
197 | }, | ||
198 | .set = sd_setredbalance, | ||
199 | .get = sd_getredbalance, | ||
200 | }, | ||
201 | { | ||
202 | { | ||
203 | .id = V4L2_CID_BLUE_BALANCE, | ||
204 | .type = V4L2_CTRL_TYPE_INTEGER, | ||
205 | .name = "Blue", | ||
206 | .minimum = 0, | ||
207 | .maximum = 3, | ||
208 | .step = 1, | ||
209 | #define BLUEBALANCE_DEF 1 | ||
210 | .default_value = BLUEBALANCE_DEF, | ||
211 | }, | ||
212 | .set = sd_setbluebalance, | ||
213 | .get = sd_getbluebalance, | ||
214 | }, | ||
215 | /* All controls below are for both the 7302 and the 7311 */ | ||
216 | { | ||
217 | { | ||
218 | .id = V4L2_CID_GAIN, | ||
219 | .type = V4L2_CTRL_TYPE_INTEGER, | ||
220 | .name = "Gain", | ||
221 | .minimum = 0, | ||
222 | #define GAIN_MAX 255 | ||
223 | .maximum = GAIN_MAX, | ||
224 | .step = 1, | ||
225 | #define GAIN_DEF 127 | ||
226 | #define GAIN_KNEE 255 /* Gain seems to cause little noise on the pac73xx */ | ||
227 | .default_value = GAIN_DEF, | ||
228 | }, | ||
229 | .set = sd_setgain, | ||
230 | .get = sd_getgain, | ||
231 | }, | ||
232 | { | ||
233 | { | ||
234 | .id = V4L2_CID_EXPOSURE, | ||
235 | .type = V4L2_CTRL_TYPE_INTEGER, | ||
236 | .name = "Exposure", | ||
237 | .minimum = 0, | ||
238 | #define EXPOSURE_MAX 255 | ||
239 | .maximum = EXPOSURE_MAX, | ||
240 | .step = 1, | ||
241 | #define EXPOSURE_DEF 16 /* 32 ms / 30 fps */ | ||
242 | #define EXPOSURE_KNEE 50 /* 100 ms / 10 fps */ | ||
243 | .default_value = EXPOSURE_DEF, | ||
244 | }, | ||
245 | .set = sd_setexposure, | ||
246 | .get = sd_getexposure, | ||
247 | }, | ||
248 | { | ||
249 | { | ||
250 | .id = V4L2_CID_AUTOGAIN, | ||
251 | .type = V4L2_CTRL_TYPE_BOOLEAN, | ||
252 | .name = "Auto Gain", | ||
253 | .minimum = 0, | ||
254 | .maximum = 1, | ||
255 | .step = 1, | ||
256 | #define AUTOGAIN_DEF 1 | ||
257 | .default_value = AUTOGAIN_DEF, | ||
258 | }, | ||
259 | .set = sd_setautogain, | ||
260 | .get = sd_getautogain, | ||
261 | }, | ||
262 | { | ||
263 | { | ||
264 | .id = V4L2_CID_HFLIP, | ||
265 | .type = V4L2_CTRL_TYPE_BOOLEAN, | ||
266 | .name = "Mirror", | ||
267 | .minimum = 0, | ||
268 | .maximum = 1, | ||
269 | .step = 1, | ||
270 | #define HFLIP_DEF 0 | ||
271 | .default_value = HFLIP_DEF, | ||
272 | }, | ||
273 | .set = sd_sethflip, | ||
274 | .get = sd_gethflip, | ||
275 | }, | ||
276 | { | ||
277 | { | ||
278 | .id = V4L2_CID_VFLIP, | ||
279 | .type = V4L2_CTRL_TYPE_BOOLEAN, | ||
280 | .name = "Vflip", | ||
281 | .minimum = 0, | ||
282 | .maximum = 1, | ||
283 | .step = 1, | ||
284 | #define VFLIP_DEF 0 | ||
285 | .default_value = VFLIP_DEF, | ||
286 | }, | ||
287 | .set = sd_setvflip, | ||
288 | .get = sd_getvflip, | ||
289 | }, | ||
290 | }; | ||
291 | |||
292 | static const struct v4l2_pix_format vga_mode[] = { | ||
293 | {640, 480, V4L2_PIX_FMT_PJPG, V4L2_FIELD_NONE, | ||
294 | .bytesperline = 640, | ||
295 | .sizeimage = 640 * 480 * 3 / 8 + 590, | ||
296 | .colorspace = V4L2_COLORSPACE_JPEG, | ||
297 | .priv = 0}, | ||
298 | }; | ||
299 | |||
300 | #define LOAD_PAGE3 255 | ||
301 | #define LOAD_PAGE4 254 | ||
302 | #define END_OF_SEQUENCE 0 | ||
303 | |||
304 | /* pac 7302 */ | ||
305 | static const __u8 init_7302[] = { | ||
306 | /* index,value */ | ||
307 | 0xff, 0x01, /* page 1 */ | ||
308 | 0x78, 0x00, /* deactivate */ | ||
309 | 0xff, 0x01, | ||
310 | 0x78, 0x40, /* led off */ | ||
311 | }; | ||
312 | static const __u8 start_7302[] = { | ||
313 | /* index, len, [value]* */ | ||
314 | 0xff, 1, 0x00, /* page 0 */ | ||
315 | 0x00, 12, 0x01, 0x40, 0x40, 0x40, 0x01, 0xe0, 0x02, 0x80, | ||
316 | 0x00, 0x00, 0x00, 0x00, | ||
317 | 0x0d, 24, 0x03, 0x01, 0x00, 0xb5, 0x07, 0xcb, 0x00, 0x00, | ||
318 | 0x07, 0xc8, 0x00, 0xea, 0x07, 0xcf, 0x07, 0xf7, | ||
319 | 0x07, 0x7e, 0x01, 0x0b, 0x00, 0x00, 0x00, 0x11, | ||
320 | 0x26, 2, 0xaa, 0xaa, | ||
321 | 0x2e, 1, 0x31, | ||
322 | 0x38, 1, 0x01, | ||
323 | 0x3a, 3, 0x14, 0xff, 0x5a, | ||
324 | 0x43, 11, 0x00, 0x0a, 0x18, 0x11, 0x01, 0x2c, 0x88, 0x11, | ||
325 | 0x00, 0x54, 0x11, | ||
326 | 0x55, 1, 0x00, | ||
327 | 0x62, 4, 0x10, 0x1e, 0x1e, 0x18, | ||
328 | 0x6b, 1, 0x00, | ||
329 | 0x6e, 3, 0x08, 0x06, 0x00, | ||
330 | 0x72, 3, 0x00, 0xff, 0x00, | ||
331 | 0x7d, 23, 0x01, 0x01, 0x58, 0x46, 0x50, 0x3c, 0x50, 0x3c, | ||
332 | 0x54, 0x46, 0x54, 0x56, 0x52, 0x50, 0x52, 0x50, | ||
333 | 0x56, 0x64, 0xa4, 0x00, 0xda, 0x00, 0x00, | ||
334 | 0xa2, 10, 0x22, 0x2c, 0x3c, 0x54, 0x69, 0x7c, 0x9c, 0xb9, | ||
335 | 0xd2, 0xeb, | ||
336 | 0xaf, 1, 0x02, | ||
337 | 0xb5, 2, 0x08, 0x08, | ||
338 | 0xb8, 2, 0x08, 0x88, | ||
339 | 0xc4, 4, 0xae, 0x01, 0x04, 0x01, | ||
340 | 0xcc, 1, 0x00, | ||
341 | 0xd1, 11, 0x01, 0x30, 0x49, 0x5e, 0x6f, 0x7f, 0x8e, 0xa9, | ||
342 | 0xc1, 0xd7, 0xec, | ||
343 | 0xdc, 1, 0x01, | ||
344 | 0xff, 1, 0x01, /* page 1 */ | ||
345 | 0x12, 3, 0x02, 0x00, 0x01, | ||
346 | 0x3e, 2, 0x00, 0x00, | ||
347 | 0x76, 5, 0x01, 0x20, 0x40, 0x00, 0xf2, | ||
348 | 0x7c, 1, 0x00, | ||
349 | 0x7f, 10, 0x4b, 0x0f, 0x01, 0x2c, 0x02, 0x58, 0x03, 0x20, | ||
350 | 0x02, 0x00, | ||
351 | 0x96, 5, 0x01, 0x10, 0x04, 0x01, 0x04, | ||
352 | 0xc8, 14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, | ||
353 | 0x07, 0x00, 0x01, 0x07, 0x04, 0x01, | ||
354 | 0xd8, 1, 0x01, | ||
355 | 0xdb, 2, 0x00, 0x01, | ||
356 | 0xde, 7, 0x00, 0x01, 0x04, 0x04, 0x00, 0x00, 0x00, | ||
357 | 0xe6, 4, 0x00, 0x00, 0x00, 0x01, | ||
358 | 0xeb, 1, 0x00, | ||
359 | 0xff, 1, 0x02, /* page 2 */ | ||
360 | 0x22, 1, 0x00, | ||
361 | 0xff, 1, 0x03, /* page 3 */ | ||
362 | 0, LOAD_PAGE3, /* load the page 3 */ | ||
363 | 0x11, 1, 0x01, | ||
364 | 0xff, 1, 0x02, /* page 2 */ | ||
365 | 0x13, 1, 0x00, | ||
366 | 0x22, 4, 0x1f, 0xa4, 0xf0, 0x96, | ||
367 | 0x27, 2, 0x14, 0x0c, | ||
368 | 0x2a, 5, 0xc8, 0x00, 0x18, 0x12, 0x22, | ||
369 | 0x64, 8, 0x00, 0x00, 0xf0, 0x01, 0x14, 0x44, 0x44, 0x44, | ||
370 | 0x6e, 1, 0x08, | ||
371 | 0xff, 1, 0x01, /* page 1 */ | ||
372 | 0x78, 1, 0x00, | ||
373 | 0, END_OF_SEQUENCE /* end of sequence */ | ||
374 | }; | ||
375 | |||
376 | #define SKIP 0xaa | ||
377 | /* page 3 - the value SKIP says skip the index - see reg_w_page() */ | ||
378 | static const __u8 page3_7302[] = { | ||
379 | 0x90, 0x40, 0x03, 0x50, 0xc2, 0x01, 0x14, 0x16, | ||
380 | 0x14, 0x12, 0x00, 0x00, 0x00, 0x02, 0x33, 0x00, | ||
381 | 0x0f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
382 | 0x00, 0x00, 0x00, 0x47, 0x01, 0xb3, 0x01, 0x00, | ||
383 | 0x00, 0x08, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x21, | ||
384 | 0x00, 0x00, 0x00, 0x54, 0xf4, 0x02, 0x52, 0x54, | ||
385 | 0xa4, 0xb8, 0xe0, 0x2a, 0xf6, 0x00, 0x00, 0x00, | ||
386 | 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
387 | 0x00, 0xfc, 0x00, 0xf2, 0x1f, 0x04, 0x00, 0x00, | ||
388 | 0x00, 0x00, 0x00, 0xc0, 0xc0, 0x10, 0x00, 0x00, | ||
389 | 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
390 | 0x00, 0x40, 0xff, 0x03, 0x19, 0x00, 0x00, 0x00, | ||
391 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
392 | 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0xc8, 0xc8, | ||
393 | 0xc8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, | ||
394 | 0x08, 0x10, 0x24, 0x40, 0x00, 0x00, 0x00, 0x00, | ||
395 | 0x01, 0x00, 0x02, 0x47, 0x00, 0x00, 0x00, 0x00, | ||
396 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
397 | 0x00, 0x02, 0xfa, 0x00, 0x64, 0x5a, 0x28, 0x00, | ||
398 | 0x00 | ||
399 | }; | ||
400 | |||
401 | static int reg_w_buf(struct gspca_dev *gspca_dev, | ||
402 | __u8 index, | ||
403 | const char *buffer, int len) | ||
404 | { | ||
405 | int ret; | ||
406 | |||
407 | memcpy(gspca_dev->usb_buf, buffer, len); | ||
408 | ret = usb_control_msg(gspca_dev->dev, | ||
409 | usb_sndctrlpipe(gspca_dev->dev, 0), | ||
410 | 1, /* request */ | ||
411 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
412 | 0, /* value */ | ||
413 | index, gspca_dev->usb_buf, len, | ||
414 | 500); | ||
415 | if (ret < 0) | ||
416 | PDEBUG(D_ERR, "reg_w_buf(): " | ||
417 | "Failed to write registers to index 0x%x, error %i", | ||
418 | index, ret); | ||
419 | return ret; | ||
420 | } | ||
421 | |||
422 | |||
423 | static int reg_w(struct gspca_dev *gspca_dev, | ||
424 | __u8 index, | ||
425 | __u8 value) | ||
426 | { | ||
427 | int ret; | ||
428 | |||
429 | gspca_dev->usb_buf[0] = value; | ||
430 | ret = usb_control_msg(gspca_dev->dev, | ||
431 | usb_sndctrlpipe(gspca_dev->dev, 0), | ||
432 | 0, /* request */ | ||
433 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
434 | 0, index, gspca_dev->usb_buf, 1, | ||
435 | 500); | ||
436 | if (ret < 0) | ||
437 | PDEBUG(D_ERR, "reg_w(): " | ||
438 | "Failed to write register to index 0x%x, value 0x%x, error %i", | ||
439 | index, value, ret); | ||
440 | return ret; | ||
441 | } | ||
442 | |||
443 | static int reg_w_seq(struct gspca_dev *gspca_dev, | ||
444 | const __u8 *seq, int len) | ||
445 | { | ||
446 | int ret = 0; | ||
447 | while (--len >= 0) { | ||
448 | if (0 <= ret) | ||
449 | ret = reg_w(gspca_dev, seq[0], seq[1]); | ||
450 | seq += 2; | ||
451 | } | ||
452 | return ret; | ||
453 | } | ||
454 | |||
455 | /* load the beginning of a page */ | ||
456 | static int reg_w_page(struct gspca_dev *gspca_dev, | ||
457 | const __u8 *page, int len) | ||
458 | { | ||
459 | int index; | ||
460 | int ret = 0; | ||
461 | |||
462 | for (index = 0; index < len; index++) { | ||
463 | if (page[index] == SKIP) /* skip this index */ | ||
464 | continue; | ||
465 | gspca_dev->usb_buf[0] = page[index]; | ||
466 | ret = usb_control_msg(gspca_dev->dev, | ||
467 | usb_sndctrlpipe(gspca_dev->dev, 0), | ||
468 | 0, /* request */ | ||
469 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
470 | 0, index, gspca_dev->usb_buf, 1, | ||
471 | 500); | ||
472 | if (ret < 0) { | ||
473 | PDEBUG(D_ERR, "reg_w_page(): " | ||
474 | "Failed to write register to index 0x%x, " | ||
475 | "value 0x%x, error %i", | ||
476 | index, page[index], ret); | ||
477 | break; | ||
478 | } | ||
479 | } | ||
480 | return ret; | ||
481 | } | ||
482 | |||
483 | /* output a variable sequence */ | ||
484 | static int reg_w_var(struct gspca_dev *gspca_dev, | ||
485 | const __u8 *seq, | ||
486 | const __u8 *page3, unsigned int page3_len, | ||
487 | const __u8 *page4, unsigned int page4_len) | ||
488 | { | ||
489 | int index, len; | ||
490 | int ret = 0; | ||
491 | |||
492 | for (;;) { | ||
493 | index = *seq++; | ||
494 | len = *seq++; | ||
495 | switch (len) { | ||
496 | case END_OF_SEQUENCE: | ||
497 | return ret; | ||
498 | case LOAD_PAGE4: | ||
499 | ret = reg_w_page(gspca_dev, page4, page4_len); | ||
500 | break; | ||
501 | case LOAD_PAGE3: | ||
502 | ret = reg_w_page(gspca_dev, page3, page3_len); | ||
503 | break; | ||
504 | default: | ||
505 | if (len > USB_BUF_SZ) { | ||
506 | PDEBUG(D_ERR|D_STREAM, | ||
507 | "Incorrect variable sequence"); | ||
508 | return -EINVAL; | ||
509 | } | ||
510 | while (len > 0) { | ||
511 | if (len < 8) { | ||
512 | ret = reg_w_buf(gspca_dev, | ||
513 | index, seq, len); | ||
514 | if (ret < 0) | ||
515 | return ret; | ||
516 | seq += len; | ||
517 | break; | ||
518 | } | ||
519 | ret = reg_w_buf(gspca_dev, index, seq, 8); | ||
520 | seq += 8; | ||
521 | index += 8; | ||
522 | len -= 8; | ||
523 | } | ||
524 | } | ||
525 | if (ret < 0) | ||
526 | return ret; | ||
527 | } | ||
528 | /* not reached */ | ||
529 | } | ||
530 | |||
531 | /* this function is called at probe time for pac7302 */ | ||
532 | static int sd_config(struct gspca_dev *gspca_dev, | ||
533 | const struct usb_device_id *id) | ||
534 | { | ||
535 | struct sd *sd = (struct sd *) gspca_dev; | ||
536 | struct cam *cam; | ||
537 | |||
538 | cam = &gspca_dev->cam; | ||
539 | |||
540 | PDEBUG(D_CONF, "Find Sensor PAC7302"); | ||
541 | cam->cam_mode = vga_mode; /* only 640x480 */ | ||
542 | cam->nmodes = ARRAY_SIZE(vga_mode); | ||
543 | |||
544 | sd->brightness = BRIGHTNESS_DEF; | ||
545 | sd->contrast = CONTRAST_DEF; | ||
546 | sd->colors = COLOR_DEF; | ||
547 | sd->white_balance = WHITEBALANCE_DEF; | ||
548 | sd->red_balance = REDBALANCE_DEF; | ||
549 | sd->blue_balance = BLUEBALANCE_DEF; | ||
550 | sd->gain = GAIN_DEF; | ||
551 | sd->exposure = EXPOSURE_DEF; | ||
552 | sd->autogain = AUTOGAIN_DEF; | ||
553 | sd->hflip = HFLIP_DEF; | ||
554 | sd->vflip = VFLIP_DEF; | ||
555 | return 0; | ||
556 | } | ||
557 | |||
558 | /* This function is used by pac7302 only */ | ||
559 | static int setbrightcont(struct gspca_dev *gspca_dev) | ||
560 | { | ||
561 | struct sd *sd = (struct sd *) gspca_dev; | ||
562 | int i, v; | ||
563 | int ret; | ||
564 | static const __u8 max[10] = | ||
565 | {0x29, 0x33, 0x42, 0x5a, 0x6e, 0x80, 0x9f, 0xbb, | ||
566 | 0xd4, 0xec}; | ||
567 | static const __u8 delta[10] = | ||
568 | {0x35, 0x33, 0x33, 0x2f, 0x2a, 0x25, 0x1e, 0x17, | ||
569 | 0x11, 0x0b}; | ||
570 | |||
571 | ret = reg_w(gspca_dev, 0xff, 0x00); /* page 0 */ | ||
572 | for (i = 0; i < 10; i++) { | ||
573 | v = max[i]; | ||
574 | v += (sd->brightness - BRIGHTNESS_MAX) | ||
575 | * 150 / BRIGHTNESS_MAX; /* 200 ? */ | ||
576 | v -= delta[i] * sd->contrast / CONTRAST_MAX; | ||
577 | if (v < 0) | ||
578 | v = 0; | ||
579 | else if (v > 0xff) | ||
580 | v = 0xff; | ||
581 | if (0 <= ret) | ||
582 | ret = reg_w(gspca_dev, 0xa2 + i, v); | ||
583 | } | ||
584 | if (0 <= ret) | ||
585 | ret = reg_w(gspca_dev, 0xdc, 0x01); | ||
586 | return ret; | ||
587 | } | ||
588 | |||
589 | /* This function is used by pac7302 only */ | ||
590 | static int setcolors(struct gspca_dev *gspca_dev) | ||
591 | { | ||
592 | struct sd *sd = (struct sd *) gspca_dev; | ||
593 | int i, v; | ||
594 | int ret; | ||
595 | static const int a[9] = | ||
596 | {217, -212, 0, -101, 170, -67, -38, -315, 355}; | ||
597 | static const int b[9] = | ||
598 | {19, 106, 0, 19, 106, 1, 19, 106, 1}; | ||
599 | |||
600 | ret = reg_w(gspca_dev, 0xff, 0x03); /* page 3 */ | ||
601 | if (0 <= ret) | ||
602 | ret = reg_w(gspca_dev, 0x11, 0x01); | ||
603 | if (0 <= ret) | ||
604 | ret = reg_w(gspca_dev, 0xff, 0x00); /* page 0 */ | ||
605 | for (i = 0; i < 9; i++) { | ||
606 | v = a[i] * sd->colors / COLOR_MAX + b[i]; | ||
607 | if (0 <= ret) | ||
608 | ret = reg_w(gspca_dev, 0x0f + 2 * i, (v >> 8) & 0x07); | ||
609 | if (0 <= ret) | ||
610 | ret = reg_w(gspca_dev, 0x0f + 2 * i + 1, v); | ||
611 | } | ||
612 | if (0 <= ret) | ||
613 | ret = reg_w(gspca_dev, 0xdc, 0x01); | ||
614 | PDEBUG(D_CONF|D_STREAM, "color: %i", sd->colors); | ||
615 | return ret; | ||
616 | } | ||
617 | |||
618 | static int setwhitebalance(struct gspca_dev *gspca_dev) | ||
619 | { | ||
620 | struct sd *sd = (struct sd *) gspca_dev; | ||
621 | int ret; | ||
622 | |||
623 | ret = reg_w(gspca_dev, 0xff, 0x00); /* page 0 */ | ||
624 | if (0 <= ret) | ||
625 | ret = reg_w(gspca_dev, 0xc6, sd->white_balance); | ||
626 | |||
627 | if (0 <= ret) | ||
628 | ret = reg_w(gspca_dev, 0xdc, 0x01); | ||
629 | PDEBUG(D_CONF|D_STREAM, "white_balance: %i", sd->white_balance); | ||
630 | return ret; | ||
631 | } | ||
632 | |||
633 | static int setredbalance(struct gspca_dev *gspca_dev) | ||
634 | { | ||
635 | struct sd *sd = (struct sd *) gspca_dev; | ||
636 | int ret; | ||
637 | |||
638 | ret = reg_w(gspca_dev, 0xff, 0x00); /* page 0 */ | ||
639 | if (0 <= ret) | ||
640 | ret = reg_w(gspca_dev, 0xc5, sd->red_balance); | ||
641 | |||
642 | if (0 <= ret) | ||
643 | ret = reg_w(gspca_dev, 0xdc, 0x01); | ||
644 | PDEBUG(D_CONF|D_STREAM, "red_balance: %i", sd->red_balance); | ||
645 | return ret; | ||
646 | } | ||
647 | |||
648 | static int setbluebalance(struct gspca_dev *gspca_dev) | ||
649 | { | ||
650 | struct sd *sd = (struct sd *) gspca_dev; | ||
651 | int ret; | ||
652 | |||
653 | ret = reg_w(gspca_dev, 0xff, 0x00); /* page 0 */ | ||
654 | if (0 <= ret) | ||
655 | ret = reg_w(gspca_dev, 0xc7, sd->blue_balance); | ||
656 | |||
657 | if (0 <= ret) | ||
658 | ret = reg_w(gspca_dev, 0xdc, 0x01); | ||
659 | PDEBUG(D_CONF|D_STREAM, "blue_balance: %i", sd->blue_balance); | ||
660 | return ret; | ||
661 | } | ||
662 | |||
663 | static int setgain(struct gspca_dev *gspca_dev) | ||
664 | { | ||
665 | struct sd *sd = (struct sd *) gspca_dev; | ||
666 | int ret; | ||
667 | |||
668 | ret = reg_w(gspca_dev, 0xff, 0x03); /* page 3 */ | ||
669 | if (0 <= ret) | ||
670 | ret = reg_w(gspca_dev, 0x10, sd->gain >> 3); | ||
671 | |||
672 | /* load registers to sensor (Bit 0, auto clear) */ | ||
673 | if (0 <= ret) | ||
674 | ret = reg_w(gspca_dev, 0x11, 0x01); | ||
675 | return ret; | ||
676 | } | ||
677 | |||
678 | static int setexposure(struct gspca_dev *gspca_dev) | ||
679 | { | ||
680 | struct sd *sd = (struct sd *) gspca_dev; | ||
681 | int ret; | ||
682 | __u8 reg; | ||
683 | |||
684 | /* register 2 of frame 3/4 contains the clock divider configuring the | ||
685 | no fps according to the formula: 60 / reg. sd->exposure is the | ||
686 | desired exposure time in ms. */ | ||
687 | reg = 120 * sd->exposure / 1000; | ||
688 | if (reg < 2) | ||
689 | reg = 2; | ||
690 | else if (reg > 63) | ||
691 | reg = 63; | ||
692 | |||
693 | /* On the pac7302 reg2 MUST be a multiple of 3, so round it to | ||
694 | the nearest multiple of 3, except when between 6 and 12? */ | ||
695 | if (reg < 6 || reg > 12) | ||
696 | reg = ((reg + 1) / 3) * 3; | ||
697 | ret = reg_w(gspca_dev, 0xff, 0x03); /* page 3 */ | ||
698 | if (0 <= ret) | ||
699 | ret = reg_w(gspca_dev, 0x02, reg); | ||
700 | |||
701 | /* load registers to sensor (Bit 0, auto clear) */ | ||
702 | if (0 <= ret) | ||
703 | ret = reg_w(gspca_dev, 0x11, 0x01); | ||
704 | return ret; | ||
705 | } | ||
706 | |||
707 | static int sethvflip(struct gspca_dev *gspca_dev) | ||
708 | { | ||
709 | struct sd *sd = (struct sd *) gspca_dev; | ||
710 | int ret; | ||
711 | __u8 data; | ||
712 | |||
713 | ret = reg_w(gspca_dev, 0xff, 0x03); /* page 3 */ | ||
714 | data = (sd->hflip ? 0x08 : 0x00) | (sd->vflip ? 0x04 : 0x00); | ||
715 | if (0 <= ret) | ||
716 | ret = reg_w(gspca_dev, 0x21, data); | ||
717 | /* load registers to sensor (Bit 0, auto clear) */ | ||
718 | if (0 <= ret) | ||
719 | ret = reg_w(gspca_dev, 0x11, 0x01); | ||
720 | return ret; | ||
721 | } | ||
722 | |||
723 | /* this function is called at probe and resume time for pac7302 */ | ||
724 | static int sd_init(struct gspca_dev *gspca_dev) | ||
725 | { | ||
726 | return reg_w_seq(gspca_dev, init_7302, sizeof(init_7302)/2); | ||
727 | } | ||
728 | |||
729 | static int sd_start(struct gspca_dev *gspca_dev) | ||
730 | { | ||
731 | struct sd *sd = (struct sd *) gspca_dev; | ||
732 | int ret = 0; | ||
733 | |||
734 | sd->sof_read = 0; | ||
735 | |||
736 | ret = reg_w_var(gspca_dev, start_7302, | ||
737 | page3_7302, sizeof(page3_7302), | ||
738 | NULL, 0); | ||
739 | if (0 <= ret) | ||
740 | ret = setbrightcont(gspca_dev); | ||
741 | if (0 <= ret) | ||
742 | ret = setcolors(gspca_dev); | ||
743 | if (0 <= ret) | ||
744 | ret = setwhitebalance(gspca_dev); | ||
745 | if (0 <= ret) | ||
746 | ret = setredbalance(gspca_dev); | ||
747 | if (0 <= ret) | ||
748 | ret = setbluebalance(gspca_dev); | ||
749 | if (0 <= ret) | ||
750 | ret = setgain(gspca_dev); | ||
751 | if (0 <= ret) | ||
752 | ret = setexposure(gspca_dev); | ||
753 | if (0 <= ret) | ||
754 | ret = sethvflip(gspca_dev); | ||
755 | |||
756 | /* only resolution 640x480 is supported for pac7302 */ | ||
757 | |||
758 | sd->sof_read = 0; | ||
759 | sd->autogain_ignore_frames = 0; | ||
760 | atomic_set(&sd->avg_lum, -1); | ||
761 | |||
762 | /* start stream */ | ||
763 | if (0 <= ret) | ||
764 | ret = reg_w(gspca_dev, 0xff, 0x01); | ||
765 | if (0 <= ret) | ||
766 | ret = reg_w(gspca_dev, 0x78, 0x01); | ||
767 | |||
768 | return ret; | ||
769 | } | ||
770 | |||
771 | static void sd_stopN(struct gspca_dev *gspca_dev) | ||
772 | { | ||
773 | int ret; | ||
774 | |||
775 | /* stop stream */ | ||
776 | ret = reg_w(gspca_dev, 0xff, 0x01); | ||
777 | if (0 <= ret) | ||
778 | ret = reg_w(gspca_dev, 0x78, 0x00); | ||
779 | } | ||
780 | |||
781 | /* called on streamoff with alt 0 and on disconnect for pac7302 */ | ||
782 | static void sd_stop0(struct gspca_dev *gspca_dev) | ||
783 | { | ||
784 | int ret; | ||
785 | |||
786 | if (!gspca_dev->present) | ||
787 | return; | ||
788 | ret = reg_w(gspca_dev, 0xff, 0x01); | ||
789 | if (0 <= ret) | ||
790 | ret = reg_w(gspca_dev, 0x78, 0x40); | ||
791 | } | ||
792 | |||
793 | /* Include pac common sof detection functions */ | ||
794 | #include "pac_common.h" | ||
795 | |||
796 | static void do_autogain(struct gspca_dev *gspca_dev) | ||
797 | { | ||
798 | struct sd *sd = (struct sd *) gspca_dev; | ||
799 | int avg_lum = atomic_read(&sd->avg_lum); | ||
800 | int desired_lum, deadzone; | ||
801 | |||
802 | if (avg_lum == -1) | ||
803 | return; | ||
804 | |||
805 | desired_lum = 270 + sd->brightness * 4; | ||
806 | /* Hack hack, with the 7202 the first exposure step is | ||
807 | pretty large, so if we're about to make the first | ||
808 | exposure increase make the deadzone large to avoid | ||
809 | oscilating */ | ||
810 | if (desired_lum > avg_lum && sd->gain == GAIN_DEF && | ||
811 | sd->exposure > EXPOSURE_DEF && | ||
812 | sd->exposure < 42) | ||
813 | deadzone = 90; | ||
814 | else | ||
815 | deadzone = 30; | ||
816 | |||
817 | if (sd->autogain_ignore_frames > 0) | ||
818 | sd->autogain_ignore_frames--; | ||
819 | else if (gspca_auto_gain_n_exposure(gspca_dev, avg_lum, desired_lum, | ||
820 | deadzone, GAIN_KNEE, EXPOSURE_KNEE)) | ||
821 | sd->autogain_ignore_frames = PAC_AUTOGAIN_IGNORE_FRAMES; | ||
822 | } | ||
823 | |||
824 | /* JPEG header, part 1 */ | ||
825 | static const unsigned char pac_jpeg_header1[] = { | ||
826 | 0xff, 0xd8, /* SOI: Start of Image */ | ||
827 | |||
828 | 0xff, 0xc0, /* SOF0: Start of Frame (Baseline DCT) */ | ||
829 | 0x00, 0x11, /* length = 17 bytes (including this length field) */ | ||
830 | 0x08 /* Precision: 8 */ | ||
831 | /* 2 bytes is placed here: number of image lines */ | ||
832 | /* 2 bytes is placed here: samples per line */ | ||
833 | }; | ||
834 | |||
835 | /* JPEG header, continued */ | ||
836 | static const unsigned char pac_jpeg_header2[] = { | ||
837 | 0x03, /* Number of image components: 3 */ | ||
838 | 0x01, 0x21, 0x00, /* ID=1, Subsampling 1x1, Quantization table: 0 */ | ||
839 | 0x02, 0x11, 0x01, /* ID=2, Subsampling 2x1, Quantization table: 1 */ | ||
840 | 0x03, 0x11, 0x01, /* ID=3, Subsampling 2x1, Quantization table: 1 */ | ||
841 | |||
842 | 0xff, 0xda, /* SOS: Start Of Scan */ | ||
843 | 0x00, 0x0c, /* length = 12 bytes (including this length field) */ | ||
844 | 0x03, /* number of components: 3 */ | ||
845 | 0x01, 0x00, /* selector 1, table 0x00 */ | ||
846 | 0x02, 0x11, /* selector 2, table 0x11 */ | ||
847 | 0x03, 0x11, /* selector 3, table 0x11 */ | ||
848 | 0x00, 0x3f, /* Spectral selection: 0 .. 63 */ | ||
849 | 0x00 /* Successive approximation: 0 */ | ||
850 | }; | ||
851 | |||
852 | static void pac_start_frame(struct gspca_dev *gspca_dev, | ||
853 | struct gspca_frame *frame, | ||
854 | __u16 lines, __u16 samples_per_line) | ||
855 | { | ||
856 | unsigned char tmpbuf[4]; | ||
857 | |||
858 | gspca_frame_add(gspca_dev, FIRST_PACKET, | ||
859 | pac_jpeg_header1, sizeof(pac_jpeg_header1)); | ||
860 | |||
861 | tmpbuf[0] = lines >> 8; | ||
862 | tmpbuf[1] = lines & 0xff; | ||
863 | tmpbuf[2] = samples_per_line >> 8; | ||
864 | tmpbuf[3] = samples_per_line & 0xff; | ||
865 | |||
866 | gspca_frame_add(gspca_dev, INTER_PACKET, | ||
867 | tmpbuf, sizeof(tmpbuf)); | ||
868 | gspca_frame_add(gspca_dev, INTER_PACKET, | ||
869 | pac_jpeg_header2, sizeof(pac_jpeg_header2)); | ||
870 | } | ||
871 | |||
872 | /* this function is run at interrupt level */ | ||
873 | static void sd_pkt_scan(struct gspca_dev *gspca_dev, | ||
874 | u8 *data, /* isoc packet */ | ||
875 | int len) /* iso packet length */ | ||
876 | { | ||
877 | struct sd *sd = (struct sd *) gspca_dev; | ||
878 | struct gspca_frame *frame; | ||
879 | unsigned char *sof; | ||
880 | |||
881 | sof = pac_find_sof(&sd->sof_read, data, len); | ||
882 | if (sof) { | ||
883 | int n, lum_offset, footer_length; | ||
884 | |||
885 | frame = gspca_get_i_frame(gspca_dev); | ||
886 | if (frame == NULL) { | ||
887 | gspca_dev->last_packet_type = DISCARD_PACKET; | ||
888 | return; | ||
889 | } | ||
890 | |||
891 | /* 6 bytes after the FF D9 EOF marker a number of lumination | ||
892 | bytes are send corresponding to different parts of the | ||
893 | image, the 14th and 15th byte after the EOF seem to | ||
894 | correspond to the center of the image */ | ||
895 | lum_offset = 61 + sizeof pac_sof_marker; | ||
896 | footer_length = 74; | ||
897 | |||
898 | /* Finish decoding current frame */ | ||
899 | n = (sof - data) - (footer_length + sizeof pac_sof_marker); | ||
900 | if (n < 0) { | ||
901 | frame->data_end += n; | ||
902 | n = 0; | ||
903 | } | ||
904 | gspca_frame_add(gspca_dev, INTER_PACKET, | ||
905 | data, n); | ||
906 | if (gspca_dev->last_packet_type != DISCARD_PACKET && | ||
907 | frame->data_end[-2] == 0xff && | ||
908 | frame->data_end[-1] == 0xd9) | ||
909 | gspca_frame_add(gspca_dev, LAST_PACKET, | ||
910 | NULL, 0); | ||
911 | |||
912 | n = sof - data; | ||
913 | len -= n; | ||
914 | data = sof; | ||
915 | |||
916 | /* Get average lumination */ | ||
917 | if (gspca_dev->last_packet_type == LAST_PACKET && | ||
918 | n >= lum_offset) | ||
919 | atomic_set(&sd->avg_lum, data[-lum_offset] + | ||
920 | data[-lum_offset + 1]); | ||
921 | else | ||
922 | atomic_set(&sd->avg_lum, -1); | ||
923 | |||
924 | /* Start the new frame with the jpeg header */ | ||
925 | /* The PAC7302 has the image rotated 90 degrees */ | ||
926 | pac_start_frame(gspca_dev, frame, | ||
927 | gspca_dev->width, gspca_dev->height); | ||
928 | } | ||
929 | gspca_frame_add(gspca_dev, INTER_PACKET, data, len); | ||
930 | } | ||
931 | |||
932 | static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) | ||
933 | { | ||
934 | struct sd *sd = (struct sd *) gspca_dev; | ||
935 | |||
936 | sd->brightness = val; | ||
937 | if (gspca_dev->streaming) | ||
938 | setbrightcont(gspca_dev); | ||
939 | return 0; | ||
940 | } | ||
941 | |||
942 | static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val) | ||
943 | { | ||
944 | struct sd *sd = (struct sd *) gspca_dev; | ||
945 | |||
946 | *val = sd->brightness; | ||
947 | return 0; | ||
948 | } | ||
949 | |||
950 | static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val) | ||
951 | { | ||
952 | struct sd *sd = (struct sd *) gspca_dev; | ||
953 | |||
954 | sd->contrast = val; | ||
955 | if (gspca_dev->streaming) { | ||
956 | setbrightcont(gspca_dev); | ||
957 | } | ||
958 | return 0; | ||
959 | } | ||
960 | |||
961 | static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val) | ||
962 | { | ||
963 | struct sd *sd = (struct sd *) gspca_dev; | ||
964 | |||
965 | *val = sd->contrast; | ||
966 | return 0; | ||
967 | } | ||
968 | |||
969 | static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val) | ||
970 | { | ||
971 | struct sd *sd = (struct sd *) gspca_dev; | ||
972 | |||
973 | sd->colors = val; | ||
974 | if (gspca_dev->streaming) | ||
975 | setcolors(gspca_dev); | ||
976 | return 0; | ||
977 | } | ||
978 | |||
979 | static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val) | ||
980 | { | ||
981 | struct sd *sd = (struct sd *) gspca_dev; | ||
982 | |||
983 | *val = sd->colors; | ||
984 | return 0; | ||
985 | } | ||
986 | |||
987 | static int sd_setwhitebalance(struct gspca_dev *gspca_dev, __s32 val) | ||
988 | { | ||
989 | struct sd *sd = (struct sd *) gspca_dev; | ||
990 | int ret = 0; | ||
991 | |||
992 | sd->white_balance = val; | ||
993 | if (gspca_dev->streaming) | ||
994 | ret = setwhitebalance(gspca_dev); | ||
995 | if (0 <= ret) | ||
996 | ret = 0; | ||
997 | return ret; | ||
998 | } | ||
999 | |||
1000 | static int sd_getwhitebalance(struct gspca_dev *gspca_dev, __s32 *val) | ||
1001 | { | ||
1002 | struct sd *sd = (struct sd *) gspca_dev; | ||
1003 | |||
1004 | *val = sd->white_balance; | ||
1005 | return 0; | ||
1006 | } | ||
1007 | |||
1008 | static int sd_setredbalance(struct gspca_dev *gspca_dev, __s32 val) | ||
1009 | { | ||
1010 | struct sd *sd = (struct sd *) gspca_dev; | ||
1011 | int ret = 0; | ||
1012 | |||
1013 | sd->red_balance = val; | ||
1014 | if (gspca_dev->streaming) | ||
1015 | ret = setredbalance(gspca_dev); | ||
1016 | if (0 <= ret) | ||
1017 | ret = 0; | ||
1018 | return ret; | ||
1019 | } | ||
1020 | |||
1021 | static int sd_getredbalance(struct gspca_dev *gspca_dev, __s32 *val) | ||
1022 | { | ||
1023 | struct sd *sd = (struct sd *) gspca_dev; | ||
1024 | |||
1025 | *val = sd->red_balance; | ||
1026 | return 0; | ||
1027 | } | ||
1028 | |||
1029 | static int sd_setbluebalance(struct gspca_dev *gspca_dev, __s32 val) | ||
1030 | { | ||
1031 | struct sd *sd = (struct sd *) gspca_dev; | ||
1032 | int ret = 0; | ||
1033 | |||
1034 | sd->blue_balance = val; | ||
1035 | if (gspca_dev->streaming) | ||
1036 | ret = setbluebalance(gspca_dev); | ||
1037 | if (0 <= ret) | ||
1038 | ret = 0; | ||
1039 | return ret; | ||
1040 | } | ||
1041 | |||
1042 | static int sd_getbluebalance(struct gspca_dev *gspca_dev, __s32 *val) | ||
1043 | { | ||
1044 | struct sd *sd = (struct sd *) gspca_dev; | ||
1045 | |||
1046 | *val = sd->blue_balance; | ||
1047 | return 0; | ||
1048 | } | ||
1049 | |||
1050 | static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val) | ||
1051 | { | ||
1052 | struct sd *sd = (struct sd *) gspca_dev; | ||
1053 | |||
1054 | sd->gain = val; | ||
1055 | if (gspca_dev->streaming) | ||
1056 | setgain(gspca_dev); | ||
1057 | return 0; | ||
1058 | } | ||
1059 | |||
1060 | static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val) | ||
1061 | { | ||
1062 | struct sd *sd = (struct sd *) gspca_dev; | ||
1063 | |||
1064 | *val = sd->gain; | ||
1065 | return 0; | ||
1066 | } | ||
1067 | |||
1068 | static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val) | ||
1069 | { | ||
1070 | struct sd *sd = (struct sd *) gspca_dev; | ||
1071 | |||
1072 | sd->exposure = val; | ||
1073 | if (gspca_dev->streaming) | ||
1074 | setexposure(gspca_dev); | ||
1075 | return 0; | ||
1076 | } | ||
1077 | |||
1078 | static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val) | ||
1079 | { | ||
1080 | struct sd *sd = (struct sd *) gspca_dev; | ||
1081 | |||
1082 | *val = sd->exposure; | ||
1083 | return 0; | ||
1084 | } | ||
1085 | |||
1086 | static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val) | ||
1087 | { | ||
1088 | struct sd *sd = (struct sd *) gspca_dev; | ||
1089 | |||
1090 | sd->autogain = val; | ||
1091 | /* when switching to autogain set defaults to make sure | ||
1092 | we are on a valid point of the autogain gain / | ||
1093 | exposure knee graph, and give this change time to | ||
1094 | take effect before doing autogain. */ | ||
1095 | if (sd->autogain) { | ||
1096 | sd->exposure = EXPOSURE_DEF; | ||
1097 | sd->gain = GAIN_DEF; | ||
1098 | if (gspca_dev->streaming) { | ||
1099 | sd->autogain_ignore_frames = | ||
1100 | PAC_AUTOGAIN_IGNORE_FRAMES; | ||
1101 | setexposure(gspca_dev); | ||
1102 | setgain(gspca_dev); | ||
1103 | } | ||
1104 | } | ||
1105 | |||
1106 | return 0; | ||
1107 | } | ||
1108 | |||
1109 | static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val) | ||
1110 | { | ||
1111 | struct sd *sd = (struct sd *) gspca_dev; | ||
1112 | |||
1113 | *val = sd->autogain; | ||
1114 | return 0; | ||
1115 | } | ||
1116 | |||
1117 | static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val) | ||
1118 | { | ||
1119 | struct sd *sd = (struct sd *) gspca_dev; | ||
1120 | |||
1121 | sd->hflip = val; | ||
1122 | if (gspca_dev->streaming) | ||
1123 | sethvflip(gspca_dev); | ||
1124 | return 0; | ||
1125 | } | ||
1126 | |||
1127 | static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val) | ||
1128 | { | ||
1129 | struct sd *sd = (struct sd *) gspca_dev; | ||
1130 | |||
1131 | *val = sd->hflip; | ||
1132 | return 0; | ||
1133 | } | ||
1134 | |||
1135 | static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val) | ||
1136 | { | ||
1137 | struct sd *sd = (struct sd *) gspca_dev; | ||
1138 | |||
1139 | sd->vflip = val; | ||
1140 | if (gspca_dev->streaming) | ||
1141 | sethvflip(gspca_dev); | ||
1142 | return 0; | ||
1143 | } | ||
1144 | |||
1145 | static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val) | ||
1146 | { | ||
1147 | struct sd *sd = (struct sd *) gspca_dev; | ||
1148 | |||
1149 | *val = sd->vflip; | ||
1150 | return 0; | ||
1151 | } | ||
1152 | |||
1153 | #ifdef CONFIG_VIDEO_ADV_DEBUG | ||
1154 | static int sd_dbg_s_register(struct gspca_dev *gspca_dev, | ||
1155 | struct v4l2_dbg_register *reg) | ||
1156 | { | ||
1157 | int ret = -EINVAL; | ||
1158 | __u8 index; | ||
1159 | __u8 value; | ||
1160 | |||
1161 | /* reg->reg: bit0..15: reserved for register index (wIndex is 16bit | ||
1162 | long on the USB bus) | ||
1163 | */ | ||
1164 | if (reg->match.type == V4L2_CHIP_MATCH_HOST && | ||
1165 | reg->match.addr == 0 && | ||
1166 | (reg->reg < 0x000000ff) && | ||
1167 | (reg->val <= 0x000000ff) | ||
1168 | ) { | ||
1169 | /* Currently writing to page 0 is only supported. */ | ||
1170 | /* reg_w() only supports 8bit index */ | ||
1171 | index = reg->reg & 0x000000ff; | ||
1172 | value = reg->val & 0x000000ff; | ||
1173 | |||
1174 | /* Note that there shall be no access to other page | ||
1175 | by any other function between the page swith and | ||
1176 | the actual register write */ | ||
1177 | ret = reg_w(gspca_dev, 0xff, 0x00); /* page 0 */ | ||
1178 | if (0 <= ret) | ||
1179 | ret = reg_w(gspca_dev, index, value); | ||
1180 | |||
1181 | if (0 <= ret) | ||
1182 | ret = reg_w(gspca_dev, 0xdc, 0x01); | ||
1183 | } | ||
1184 | return ret; | ||
1185 | } | ||
1186 | |||
1187 | static int sd_chip_ident(struct gspca_dev *gspca_dev, | ||
1188 | struct v4l2_dbg_chip_ident *chip) | ||
1189 | { | ||
1190 | int ret = -EINVAL; | ||
1191 | |||
1192 | if (chip->match.type == V4L2_CHIP_MATCH_HOST && | ||
1193 | chip->match.addr == 0) { | ||
1194 | chip->revision = 0; | ||
1195 | chip->ident = V4L2_IDENT_UNKNOWN; | ||
1196 | ret = 0; | ||
1197 | } | ||
1198 | return ret; | ||
1199 | } | ||
1200 | #endif | ||
1201 | |||
1202 | /* sub-driver description for pac7302 */ | ||
1203 | static struct sd_desc sd_desc = { | ||
1204 | .name = MODULE_NAME, | ||
1205 | .ctrls = sd_ctrls, | ||
1206 | .nctrls = ARRAY_SIZE(sd_ctrls), | ||
1207 | .config = sd_config, | ||
1208 | .init = sd_init, | ||
1209 | .start = sd_start, | ||
1210 | .stopN = sd_stopN, | ||
1211 | .stop0 = sd_stop0, | ||
1212 | .pkt_scan = sd_pkt_scan, | ||
1213 | .dq_callback = do_autogain, | ||
1214 | #ifdef CONFIG_VIDEO_ADV_DEBUG | ||
1215 | .set_register = sd_dbg_s_register, | ||
1216 | .get_chip_ident = sd_chip_ident, | ||
1217 | #endif | ||
1218 | }; | ||
1219 | |||
1220 | /* -- module initialisation -- */ | ||
1221 | static __devinitdata struct usb_device_id device_table[] = { | ||
1222 | {USB_DEVICE(0x06f8, 0x3009)}, | ||
1223 | {USB_DEVICE(0x093a, 0x2620)}, | ||
1224 | {USB_DEVICE(0x093a, 0x2621)}, | ||
1225 | {USB_DEVICE(0x093a, 0x2622)}, | ||
1226 | {USB_DEVICE(0x093a, 0x2624)}, | ||
1227 | {USB_DEVICE(0x093a, 0x2626)}, | ||
1228 | {USB_DEVICE(0x093a, 0x2628)}, | ||
1229 | {USB_DEVICE(0x093a, 0x2629)}, | ||
1230 | {USB_DEVICE(0x093a, 0x262a)}, | ||
1231 | {USB_DEVICE(0x093a, 0x262c)}, | ||
1232 | {} | ||
1233 | }; | ||
1234 | MODULE_DEVICE_TABLE(usb, device_table); | ||
1235 | |||
1236 | /* -- device connect -- */ | ||
1237 | static int sd_probe(struct usb_interface *intf, | ||
1238 | const struct usb_device_id *id) | ||
1239 | { | ||
1240 | return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd), | ||
1241 | THIS_MODULE); | ||
1242 | } | ||
1243 | |||
1244 | static struct usb_driver sd_driver = { | ||
1245 | .name = MODULE_NAME, | ||
1246 | .id_table = device_table, | ||
1247 | .probe = sd_probe, | ||
1248 | .disconnect = gspca_disconnect, | ||
1249 | #ifdef CONFIG_PM | ||
1250 | .suspend = gspca_suspend, | ||
1251 | .resume = gspca_resume, | ||
1252 | #endif | ||
1253 | }; | ||
1254 | |||
1255 | /* -- module insert / remove -- */ | ||
1256 | static int __init sd_mod_init(void) | ||
1257 | { | ||
1258 | int ret; | ||
1259 | ret = usb_register(&sd_driver); | ||
1260 | if (ret < 0) | ||
1261 | return ret; | ||
1262 | PDEBUG(D_PROBE, "registered"); | ||
1263 | return 0; | ||
1264 | } | ||
1265 | static void __exit sd_mod_exit(void) | ||
1266 | { | ||
1267 | usb_deregister(&sd_driver); | ||
1268 | PDEBUG(D_PROBE, "deregistered"); | ||
1269 | } | ||
1270 | |||
1271 | module_init(sd_mod_init); | ||
1272 | module_exit(sd_mod_exit); | ||