Release 1.2.1
[syntekdriver.git] / stk11xx-dev-6a31.c
bloba9f06e5748c200249ec1b5a840dc5faddaf58582
1 /**
2 * @file stk11xx-dev-6a31.c
3 * @author Nicolas VIVIEN
4 * @date 2007-11-23
5 * @version v1.2.0
7 * @brief Driver for Syntek USB video camera
9 * @note Copyright (C) Nicolas VIVIEN
11 * @par Licences
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 * @par SubVersion
28 * $Date$
29 * $Revision$
30 * $Author$
31 * $HeadURL$
34 #include <linux/module.h>
35 #include <linux/init.h>
36 #include <linux/kernel.h>
37 #include <linux/version.h>
38 #include <linux/errno.h>
39 #include <linux/slab.h>
40 #include <linux/kref.h>
42 #include <linux/usb.h>
43 #include <media/v4l2-common.h>
45 #include "stk11xx.h"
46 #include "stk11xx-dev.h"
49 //=============================================================================
51 // STK-6A31 API
53 //=============================================================================
56 /**
57 * @param dev Device structure
59 * @returns 0 if all is OK
61 * @brief This function permits to initialize the device.
63 * This function must be called at first. It's the start of the
64 * initialization process. After this process, the device is
65 * completly initalized and it's ready.
67 * This function is written from the USB log.
69 int dev_stk6a31_initialize_device(struct usb_stk11xx *dev)
71 int retok;
73 STK_INFO("Initialize USB2.0 Syntek Camera\n");
75 usb_stk11xx_write_registry(dev, 0x0000, 0x00e0);
76 usb_stk11xx_write_registry(dev, 0x0002, 0x00f8);
77 usb_stk11xx_write_registry(dev, 0x0002, 0x0078);
78 usb_stk11xx_write_registry(dev, 0x0000, 0x0020);
80 dev_stk6a31_configure_device(dev, 0);
81 retok = dev_stk11xx_check_device(dev, 65);
82 usb_stk11xx_write_registry(dev, 0x0200, 0x0008);
84 dev_stk6a31_configure_device(dev, 1);
85 retok = dev_stk11xx_check_device(dev, 65);
86 usb_stk11xx_write_registry(dev, 0x0200, 0x0008);
88 dev_stk6a31_configure_device(dev, 2);
89 retok = dev_stk11xx_check_device(dev, 65);
90 usb_stk11xx_write_registry(dev, 0x0200, 0x0008);
92 dev_stk6a31_configure_device(dev, 3);
93 retok = dev_stk11xx_check_device(dev, 65);
94 usb_stk11xx_write_registry(dev, 0x0200, 0x0008);
96 dev_stk6a31_configure_device(dev, 4);
97 retok = dev_stk11xx_check_device(dev, 65);
98 usb_stk11xx_write_registry(dev, 0x0200, 0x0008);
100 dev_stk6a31_configure_device(dev, 5);
101 retok = dev_stk11xx_check_device(dev, 65);
102 usb_stk11xx_write_registry(dev, 0x0200, 0x0008);
104 dev_stk6a31_configure_device(dev, 6);
105 retok = dev_stk11xx_check_device(dev, 65);
106 usb_stk11xx_write_registry(dev, 0x0200, 0x0008);
108 dev_stk6a31_configure_device(dev, 7);
109 retok = dev_stk11xx_check_device(dev, 65);
110 usb_stk11xx_write_registry(dev, 0x0200, 0x0008);
112 dev_stk6a31_configure_device(dev, 8);
114 dev_stk6a31_configure_device(dev, 9);
115 retok = dev_stk11xx_check_device(dev, 65);
116 usb_stk11xx_write_registry(dev, 0x0200, 0x0008);
118 dev_stk6a31_configure_device(dev, 10);
119 retok = dev_stk11xx_check_device(dev, 65);
120 usb_stk11xx_write_registry(dev, 0x0200, 0x0008);
122 dev_stk6a31_configure_device(dev, 11);
124 dev_stk6a31_configure_device(dev, 12);
126 dev_stk6a31_configure_device(dev, 13);
128 dev_stk6a31_configure_device(dev, 14);
130 dev_stk6a31_camera_asleep(dev);
132 usb_stk11xx_set_feature(dev, 0);
134 // Device is initialized and is ready !!!
135 STK_INFO("Syntek USB2.0 Camera is ready\n");
137 return 0;
141 /**
142 * @param dev Device structure
143 * @param step The step of configuration [0-11]
145 * @returns 0 if all is OK
147 * @brief This function permits to configure the device.
149 * The configuration of device is composed of 12 steps.
150 * This function is called by the initialization process.
152 * We don't know the meaning of these steps ! We only replay the USB log.
154 int dev_stk6a31_configure_device(struct usb_stk11xx *dev, int step)
156 int retok;
157 int value;
159 // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
160 static const int values_001B[] = {
161 0x03, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07
163 static const int values_001C[] = {
164 0x02, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06
166 static const int values_0202[] = {
167 0x0a, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x0a, 0x1e, 0x1f, 0x1f, 0x1f, 0x1f
169 static const int values_0110[] = {
170 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
172 static const int values_0112[] = {
173 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
175 static const int values_0114[] = {
176 0x80, 0x80, 0x80, 0x80, 0x00, 0xbe, 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x80
178 static const int values_0115[] = {
179 0x02, 0x02, 0x02, 0x02, 0x05, 0x02, 0x02, 0x02, 0x00, 0x02, 0x02, 0x02, 0x05, 0x02, 0x02, 0x02, 0x02
181 static const int values_0116[] = {
182 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe9, 0xe0, 0xe0, 0x00, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0
184 static const int values_0117[] = {
185 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01
187 static const int values_0100[] = {
188 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
192 STK_DEBUG("dev_stk6a31_configure_device : %d\n", step);
194 usb_stk11xx_write_registry(dev, 0x0000, 0x0024);
195 usb_stk11xx_write_registry(dev, 0x0002, 0x0078);
196 usb_stk11xx_write_registry(dev, 0x0003, 0x0080);
197 usb_stk11xx_write_registry(dev, 0x0005, 0x0000);
199 usb_stk11xx_write_registry(dev, 0x0007, 0x0003);
200 usb_stk11xx_write_registry(dev, 0x000d, 0x0000);
201 usb_stk11xx_write_registry(dev, 0x000f, 0x0002);
202 usb_stk11xx_write_registry(dev, 0x0300, 0x0012);
203 usb_stk11xx_write_registry(dev, 0x0350, 0x0041);
205 usb_stk11xx_write_registry(dev, 0x0351, 0x0000);
206 usb_stk11xx_write_registry(dev, 0x0352, 0x0000);
207 usb_stk11xx_write_registry(dev, 0x0353, 0x0000);
208 usb_stk11xx_write_registry(dev, 0x0018, 0x0010);
209 usb_stk11xx_write_registry(dev, 0x0019, 0x0000);
211 usb_stk11xx_write_registry(dev, 0x001b, values_001B[step]);
212 usb_stk11xx_write_registry(dev, 0x001c, values_001C[step]);
213 usb_stk11xx_write_registry(dev, 0x0300, 0x0080);
214 usb_stk11xx_write_registry(dev, 0x001a, 0x0004);
215 usb_stk11xx_write_registry(dev, 0x0202, values_0202[step]);
217 usb_stk11xx_write_registry(dev, 0x0110, values_0110[step]);
218 usb_stk11xx_write_registry(dev, 0x0111, 0x0000);
219 usb_stk11xx_write_registry(dev, 0x0112, values_0112[step]);
220 usb_stk11xx_write_registry(dev, 0x0113, 0x0000);
221 usb_stk11xx_write_registry(dev, 0x0114, values_0114[step]);
223 usb_stk11xx_write_registry(dev, 0x0115, values_0115[step]);
224 usb_stk11xx_write_registry(dev, 0x0116, values_0116[step]);
225 usb_stk11xx_write_registry(dev, 0x0117, values_0117[step]);
227 usb_stk11xx_read_registry(dev, 0x0100, &value);
228 usb_stk11xx_write_registry(dev, 0x0100, values_0100[step]);
230 // usb_stk11xx_write_registry(dev, 0x0200, 0x0080);
231 // usb_stk11xx_write_registry(dev, 0x0200, 0x0000);
232 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
235 switch (step) {
236 case 0:
237 usb_stk11xx_write_registry(dev, 0x0203, 0x0022);
239 usb_stk11xx_write_registry(dev, 0x0204, 0x0027);
240 usb_stk11xx_write_registry(dev, 0x0205, 0x00a5);
242 usb_stk11xx_write_registry(dev, 0x0200, 0x0005);
244 break;
246 case 1:
247 usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
249 usb_stk11xx_write_registry(dev, 0x0204, 0x0012);
250 usb_stk11xx_write_registry(dev, 0x0205, 0x0080);
251 usb_stk11xx_write_registry(dev, 0x0204, 0x0013);
252 usb_stk11xx_write_registry(dev, 0x0205, 0x00bf);
254 usb_stk11xx_write_registry(dev, 0x0200, 0x0005);
256 break;
258 case 2:
259 usb_stk11xx_write_registry(dev, 0x0203, 0x0042);
261 usb_stk11xx_write_registry(dev, 0x0204, 0x0012);
262 usb_stk11xx_write_registry(dev, 0x0205, 0x0080);
263 usb_stk11xx_write_registry(dev, 0x0204, 0x0024);
264 usb_stk11xx_write_registry(dev, 0x0205, 0x00a5);
266 usb_stk11xx_write_registry(dev, 0x0200, 0x0005);
268 break;
270 case 3:
271 usb_stk11xx_write_registry(dev, 0x0203, 0x0042);
273 usb_stk11xx_write_registry(dev, 0x0204, 0x0012);
274 usb_stk11xx_write_registry(dev, 0x0205, 0x0080);
275 usb_stk11xx_write_registry(dev, 0x0204, 0x0013);
276 usb_stk11xx_write_registry(dev, 0x0205, 0x00e0);
277 usb_stk11xx_write_registry(dev, 0x0204, 0x0024);
278 usb_stk11xx_write_registry(dev, 0x0205, 0x00a5);
280 usb_stk11xx_write_registry(dev, 0x0200, 0x0005);
282 break;
284 case 4:
285 usb_stk11xx_write_registry(dev, 0x0203, 0x0042);
287 usb_stk11xx_write_registry(dev, 0x0204, 0x0012);
288 usb_stk11xx_write_registry(dev, 0x0205, 0x0080);
289 usb_stk11xx_write_registry(dev, 0x0204, 0x0013);
290 usb_stk11xx_write_registry(dev, 0x0205, 0x00bf);
292 usb_stk11xx_write_registry(dev, 0x0200, 0x0005);
294 break;
296 case 5:
297 usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
299 usb_stk11xx_write_registry(dev, 0x0204, 0x0012);
300 usb_stk11xx_write_registry(dev, 0x0205, 0x0080);
301 usb_stk11xx_write_registry(dev, 0x0204, 0x0013);
302 usb_stk11xx_write_registry(dev, 0x0205, 0x00ff);
304 usb_stk11xx_write_registry(dev, 0x0200, 0x0005);
306 break;
308 case 6:
309 usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
311 usb_stk11xx_write_registry(dev, 0x0204, 0x0012);
312 usb_stk11xx_write_registry(dev, 0x0205, 0x0080);
313 usb_stk11xx_write_registry(dev, 0x0204, 0x0013);
314 usb_stk11xx_write_registry(dev, 0x0205, 0x00b7);
316 usb_stk11xx_write_registry(dev, 0x0200, 0x0005);
318 break;
320 case 7:
321 usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
323 usb_stk11xx_write_registry(dev, 0x0204, 0x0012);
324 usb_stk11xx_write_registry(dev, 0x0205, 0x0080);
325 usb_stk11xx_write_registry(dev, 0x0204, 0x0013);
326 usb_stk11xx_write_registry(dev, 0x0205, 0x00b7);
328 usb_stk11xx_write_registry(dev, 0x0200, 0x0005);
330 break;
332 case 8:
333 usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
335 usb_stk11xx_read_registry(dev, 0x02ff, &value);
336 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
338 usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
339 usb_stk11xx_write_registry(dev, 0x0204, 0x00ff);
340 usb_stk11xx_write_registry(dev, 0x0205, 0x0001);
341 usb_stk11xx_write_registry(dev, 0x0200, 0x0001);
342 retok = dev_stk11xx_check_device(dev, 500);
343 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
344 usb_stk11xx_read_registry(dev, 0x02ff, &value);
345 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
347 usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
348 usb_stk11xx_write_registry(dev, 0x0208, 0x000a);
349 usb_stk11xx_write_registry(dev, 0x0200, 0x0020);
350 retok = dev_stk11xx_check_device(dev, 500);
351 usb_stk11xx_read_registry(dev, 0x0209, &value);
352 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
353 usb_stk11xx_read_registry(dev, 0x02ff, &value);
354 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
356 usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
357 usb_stk11xx_write_registry(dev, 0x0208, 0x000b);
358 usb_stk11xx_write_registry(dev, 0x0200, 0x0020);
359 retok = dev_stk11xx_check_device(dev, 500);
360 usb_stk11xx_read_registry(dev, 0x0209, &value);
361 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
362 usb_stk11xx_read_registry(dev, 0x02ff, &value);
363 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
365 usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
366 usb_stk11xx_write_registry(dev, 0x0208, 0x001c);
367 usb_stk11xx_write_registry(dev, 0x0200, 0x0020);
368 retok = dev_stk11xx_check_device(dev, 500);
369 usb_stk11xx_read_registry(dev, 0x0209, &value);
370 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
371 usb_stk11xx_read_registry(dev, 0x02ff, &value);
372 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
374 usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
375 usb_stk11xx_write_registry(dev, 0x0208, 0x001d);
376 usb_stk11xx_write_registry(dev, 0x0200, 0x0020);
377 retok = dev_stk11xx_check_device(dev, 500);
378 usb_stk11xx_read_registry(dev, 0x0209, &value);
379 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
381 break;
383 case 9:
384 usb_stk11xx_write_registry(dev, 0x0203, 0x00dc);
386 usb_stk11xx_write_registry(dev, 0x0204, 0x0015);
387 usb_stk11xx_write_registry(dev, 0x0205, 0x0080);
389 usb_stk11xx_write_registry(dev, 0x0200, 0x0005);
391 break;
393 case 10:
394 usb_stk11xx_write_registry(dev, 0x0203, 0x00ec);
396 usb_stk11xx_write_registry(dev, 0x0204, 0x0015);
397 usb_stk11xx_write_registry(dev, 0x0205, 0x0080);
399 usb_stk11xx_write_registry(dev, 0x0200, 0x0005);
401 break;
403 case 11:
404 usb_stk11xx_write_registry(dev, 0x0203, 0x00ba);
406 usb_stk11xx_read_registry(dev, 0x02ff, &value);
407 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
409 usb_stk11xx_write_registry(dev, 0x0203, 0x00ba);
411 usb_stk11xx_write_registry(dev, 0x0208, 0x0000);
412 usb_stk11xx_write_registry(dev, 0x0200, 0x0020);
413 retok = dev_stk11xx_check_device(dev, 500);
414 usb_stk11xx_read_registry(dev, 0x0209, &value);
415 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
417 break;
419 case 12:
420 usb_stk11xx_write_registry(dev, 0x0203, 0x00ba);
422 usb_stk11xx_write_registry(dev, 0x0204, 0x00f0);
423 usb_stk11xx_write_registry(dev, 0x0205, 0x0000);
424 usb_stk11xx_write_registry(dev, 0x0200, 0x0005);
425 retok = dev_stk11xx_check_device(dev, 500);
426 usb_stk11xx_write_registry(dev, 0x0204, 0x00f1);
427 usb_stk11xx_write_registry(dev, 0x0205, 0x0000);
428 usb_stk11xx_write_registry(dev, 0x0200, 0x0005);
429 retok = dev_stk11xx_check_device(dev, 500);
430 usb_stk11xx_read_registry(dev, 0x02ff, &value);
431 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
433 usb_stk11xx_write_registry(dev, 0x0203, 0x00ba);
434 usb_stk11xx_write_registry(dev, 0x0208, 0x0000);
435 usb_stk11xx_write_registry(dev, 0x0200, 0x0020);
436 retok = dev_stk11xx_check_device(dev, 500);
437 usb_stk11xx_read_registry(dev, 0x0209, &value);
438 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
439 usb_stk11xx_read_registry(dev, 0x02ff, &value);
440 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
442 usb_stk11xx_write_registry(dev, 0x0203, 0x00ba);
443 usb_stk11xx_write_registry(dev, 0x0208, 0x00f1);
444 usb_stk11xx_write_registry(dev, 0x0200, 0x0020);
445 retok = dev_stk11xx_check_device(dev, 500);
446 usb_stk11xx_read_registry(dev, 0x0209, &value);
447 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
449 break;
451 case 13:
452 usb_stk11xx_write_registry(dev, 0x0203, 0x00ba);
454 usb_stk11xx_read_registry(dev, 0x02ff, &value);
455 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
457 usb_stk11xx_write_registry(dev, 0x0203, 0x00ba);
458 usb_stk11xx_write_registry(dev, 0x0208, 0x0000);
459 usb_stk11xx_write_registry(dev, 0x0200, 0x0020);
460 retok = dev_stk11xx_check_device(dev, 500);
461 usb_stk11xx_read_registry(dev, 0x0209, &value);
462 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
463 usb_stk11xx_read_registry(dev, 0x02ff, &value);
464 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
466 usb_stk11xx_write_registry(dev, 0x0203, 0x00ba);
467 usb_stk11xx_write_registry(dev, 0x0208, 0x00f1);
468 usb_stk11xx_write_registry(dev, 0x0200, 0x0020);
469 retok = dev_stk11xx_check_device(dev, 500);
470 usb_stk11xx_read_registry(dev, 0x0209, &value);
471 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
473 break;
475 case 14:
476 usb_stk11xx_write_registry(dev, 0x0203, 0x00ba);
478 usb_stk11xx_write_registry(dev, 0x0204, 0x0001);
479 usb_stk11xx_write_registry(dev, 0x0205, 0x0000);
480 usb_stk11xx_write_registry(dev, 0x0200, 0x0005);
481 retok = dev_stk11xx_check_device(dev, 500);
482 usb_stk11xx_write_registry(dev, 0x0204, 0x00f1);
483 usb_stk11xx_write_registry(dev, 0x0205, 0x0000);
484 usb_stk11xx_write_registry(dev, 0x0200, 0x0005);
485 retok = dev_stk11xx_check_device(dev, 500);
486 usb_stk11xx_read_registry(dev, 0x02ff, &value);
487 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
489 usb_stk11xx_write_registry(dev, 0x0203, 0x00ba);
490 usb_stk11xx_write_registry(dev, 0x0208, 0x0000);
491 usb_stk11xx_write_registry(dev, 0x0200, 0x0020);
492 retok = dev_stk11xx_check_device(dev, 500);
493 usb_stk11xx_read_registry(dev, 0x0209, &value);
494 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
495 usb_stk11xx_read_registry(dev, 0x02ff, &value);
496 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
498 usb_stk11xx_write_registry(dev, 0x0203, 0x00ba);
499 usb_stk11xx_write_registry(dev, 0x0208, 0x00f1);
500 usb_stk11xx_write_registry(dev, 0x0200, 0x0020);
501 retok = dev_stk11xx_check_device(dev, 500);
502 usb_stk11xx_read_registry(dev, 0x0209, &value);
503 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
505 break;
507 case 15:
508 usb_stk11xx_write_registry(dev, 0x0203, 0x00ba);
510 dev_stk6a31_sensor_settings(dev);
512 usb_stk11xx_write_registry(dev, 0x0200, 0x0080);
513 usb_stk11xx_write_registry(dev, 0x0200, 0x0000);
514 usb_stk11xx_write_registry(dev, 0x02ff, 0x0001);
515 usb_stk11xx_write_registry(dev, 0x0203, 0x00a0);
518 break;
520 case 16:
521 usb_stk11xx_write_registry(dev, 0x0203, 0x00ba);
523 dev_stk6a31_sensor_settings(dev);
525 break;
528 return 0;
532 /**
533 * @param dev Device structure
535 * @returns 0 if all is OK
537 * @brief Wake-up the camera.
539 * This function permits to wake-up the device.
541 int dev_stk6a31_camera_asleep(struct usb_stk11xx *dev)
543 int value;
545 usb_stk11xx_read_registry(dev, 0x0104, &value);
546 usb_stk11xx_read_registry(dev, 0x0105, &value);
547 usb_stk11xx_read_registry(dev, 0x0106, &value);
549 usb_stk11xx_write_registry(dev, 0x0100, 0x0021);
550 usb_stk11xx_write_registry(dev, 0x0116, 0x0000);
551 usb_stk11xx_write_registry(dev, 0x0117, 0x0000);
552 usb_stk11xx_write_registry(dev, 0x0018, 0x0000);
554 usb_stk11xx_read_registry(dev, 0x0000, &value);
555 usb_stk11xx_write_registry(dev, 0x0000, 0x0049);
557 return 0;
561 /**
562 * @param dev Device structure
564 * @returns 0 if all is OK
566 * @brief This function initializes the device for the stream.
568 * It's the start. This function has to be called at first, before
569 * enabling the video stream.
571 int dev_stk6a31_init_camera(struct usb_stk11xx *dev)
573 // int retok;
574 // int value;
576 dev_stk6a31_camera_asleep(dev);
578 usb_stk11xx_set_feature(dev, 0);
580 dev_stk6a31_camera_asleep(dev);
582 usb_stk11xx_write_registry(dev, 0x0000, 0x00e0);
583 usb_stk11xx_write_registry(dev, 0x0002, 0x00f8);
584 usb_stk11xx_write_registry(dev, 0x0002, 0x0078);
585 usb_stk11xx_write_registry(dev, 0x0000, 0x0020);
587 dev_stk6a31_configure_device(dev, 15);
589 dev_stk11xx_camera_off(dev);
591 return 0;
595 /**
596 * @param dev Device structure
598 * @returns 0 if all is OK
600 * @brief This function permits to set default sensor settings.
602 * We set some registers in using a I2C bus.
603 * WARNING, the sensor settings can be different following the situation.
605 int dev_stk6a31_sensor_settings(struct usb_stk11xx *dev)
607 int i;
608 int retok;
609 int value;
611 int asize;
612 static const int values_204[] = {
613 0xf0, 0xf1, 0x0d, 0xf1, 0x0d, 0xf1, 0xf0, 0xf1, 0x35, 0xf1,
614 0xf0, 0xf1, 0x06, 0xf1, 0xf0, 0xf1, 0xdd, 0xf1, 0xf0, 0xf1,
615 0x1f, 0xf1, 0x20, 0xf1, 0x21, 0xf1, 0x22, 0xf1, 0x23, 0xf1,
616 0x24, 0xf1, 0x28, 0xf1, 0x29, 0xf1, 0x5e, 0xf1, 0x5f, 0xf1,
617 0x60, 0xf1, 0xef, 0xf1, 0xf2, 0xf1, 0x02, 0xf1, 0x03, 0xf1,
618 0x04, 0xf1, 0x09, 0xf1, 0x0a, 0xf1, 0x0b, 0xf1, 0x0c, 0xf1,
619 0x0d, 0xf1, 0x0e, 0xf1, 0x0f, 0xf1, 0x10, 0xf1, 0x11, 0xf1,
620 0x15, 0xf1, 0x16, 0xf1, 0x17, 0xf1, 0x18, 0xf1, 0x19, 0xf1,
621 0x1a, 0xf1, 0x1b, 0xf1, 0x1c, 0xf1, 0x1d, 0xf1, 0x1e, 0xf1,
622 0xf0, 0xf1, 0x06, 0xf1, 0x06, 0xf1, 0xf0, 0xf1, 0x80, 0xf1,
623 0x81, 0xf1, 0x82, 0xf1, 0x83, 0xf1, 0x84, 0xf1, 0x85, 0xf1,
624 0x86, 0xf1, 0x87, 0xf1, 0x88, 0xf1, 0x89, 0xf1, 0x8a, 0xf1,
625 0x8b, 0xf1, 0x8c, 0xf1, 0x8d, 0xf1, 0x8e, 0xf1, 0x8f, 0xf1,
626 0x90, 0xf1, 0x91, 0xf1, 0x92, 0xf1, 0x93, 0xf1, 0x94, 0xf1,
627 0x95, 0xf1, 0xb6, 0xf1, 0xb7, 0xf1, 0xb8, 0xf1, 0xb9, 0xf1,
628 0xba, 0xf1, 0xbb, 0xf1, 0xbc, 0xf1, 0xbd, 0xf1, 0xbe, 0xf1,
629 0xbf, 0xf1, 0xc0, 0xf1, 0xc1, 0xf1, 0xc2, 0xf1, 0xc3, 0xf1,
630 0xc4, 0xf1, 0x06, 0xf1, 0xf0, 0xf1, 0x53, 0xf1, 0x54, 0xf1,
631 0x55, 0xf1, 0x56, 0xf1, 0x57, 0xf1, 0x58, 0xf1, 0xdc, 0xf1,
632 0xdd, 0xf1, 0xde, 0xf1, 0xdf, 0xf1, 0xe0, 0xf1, 0xe1, 0xf1,
633 0xf0, 0xf1, 0xa7, 0xf1, 0xaa, 0xf1, 0x3a, 0xf1, 0xa1, 0xf1,
634 0xa4, 0xf1, 0x9b, 0xf1, 0x08, 0xf1, 0xf0, 0xf1, 0x2f, 0xf1,
635 0x9c, 0xf1, 0xd2, 0xf1, 0xcc, 0xf1, 0xcb, 0xf1, 0x2e, 0xf1,
636 0x67, 0xf1, 0xf0, 0xf1, 0x65, 0xf1, 0x66, 0xf1, 0x67, 0xf1,
637 0x65, 0xf1, 0xf0, 0xf1, 0x05, 0xf1, 0x07, 0xf1, 0xf0, 0xf1,
638 0x39, 0xf1, 0x3b, 0xf1, 0x3a, 0xf1, 0x3c, 0xf1, 0x57, 0xf1,
639 0x58, 0xf1, 0x59, 0xf1, 0x5a, 0xf1, 0x5c, 0xf1, 0x5d, 0xf1,
640 0x64, 0xf1, 0xf0, 0xf1, 0x5b, 0xf1, 0xf0, 0xf1, 0x36, 0xf1,
641 0x37, 0xf1, 0xf0, 0xf1, 0x08, 0xf1
643 static const int values_205[] = {
644 0x00, 0x00, 0x00, 0x0b, 0x00, 0x08, 0x00, 0x00, 0x00, 0x22,
645 0x00, 0x01, 0x70, 0x0e, 0x00, 0x02, 0x18, 0xe0, 0x00, 0x02,
646 0x01, 0x80, 0xc8, 0x14, 0x80, 0x80, 0xa0, 0x78, 0xa0, 0x78,
647 0x5f, 0x20, 0xea, 0x02, 0x86, 0x7a, 0x59, 0x4c, 0x4d, 0x51,
648 0x00, 0x02, 0x00, 0x08, 0x00, 0x00, 0x00, 0xee, 0x39, 0x23,
649 0x07, 0x24, 0x00, 0xcd, 0x00, 0x93, 0x00, 0x04, 0x00, 0x5c,
650 0x00, 0xd9, 0x00, 0x53, 0x00, 0x08, 0x00, 0x91, 0x00, 0xcf,
651 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
652 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
653 0x00, 0x01, 0xf0, 0x0e, 0x70, 0x0e, 0x00, 0x01, 0x00, 0x07,
654 0xde, 0x13, 0xeb, 0xe2, 0x00, 0xf6, 0xe1, 0x14, 0xea, 0xdd,
655 0xfd, 0xf6, 0xe5, 0x11, 0xed, 0xe6, 0xfb, 0xf7, 0xd6, 0x13,
656 0xed, 0xec, 0xf9, 0xf2, 0x00, 0x00, 0xd8, 0x15, 0xe9, 0xea,
657 0xf9, 0xf1, 0x00, 0x02, 0xde, 0x10, 0xef, 0xef, 0xfb, 0xf4,
658 0x00, 0x02, 0x0e, 0x06, 0x27, 0x13, 0x11, 0x06, 0x27, 0x13,
659 0x0c, 0x03, 0x2a, 0x0f, 0x12, 0x08, 0x1a, 0x16, 0x00, 0x22,
660 0x15, 0x0a, 0x1c, 0x1a, 0x00, 0x2d, 0x11, 0x09, 0x14, 0x14,
661 0x00, 0x2a, 0x74, 0x0e, 0x00, 0x01, 0x0b, 0x03, 0x47, 0x22,
662 0xac, 0x82, 0xda, 0xc7, 0xf5, 0xe9, 0xff, 0x00, 0x0b, 0x03,
663 0x47, 0x22, 0xac, 0x82, 0xda, 0xc7, 0xf5, 0xe9, 0xff, 0x00,
664 0x00, 0x01, 0x02, 0x80, 0x01, 0xe0, 0x43, 0x00, 0x05, 0x00,
665 0x04, 0x00, 0x43, 0x00, 0x01, 0x80, 0x00, 0x02, 0xd1, 0x00,
666 0xd1, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x0c, 0x3c,
667 0x10, 0x10, 0x00, 0x00, 0xa0, 0x00, 0x20, 0x03, 0x05, 0x01,
668 0x20, 0x00, 0x00, 0x00, 0x01, 0xb8, 0x00, 0xd8, 0x00, 0x02,
669 0x06, 0xc0, 0x04, 0x0e, 0x06, 0xc0, 0x05, 0x64, 0x02, 0x08,
670 0x02, 0x71, 0x02, 0x09, 0x02, 0x71, 0x12, 0x0d, 0x17, 0x12,
671 0x5e, 0x1c, 0x00, 0x02, 0x00, 0x03, 0x00, 0x02, 0x78, 0x10,
672 0x83, 0x04, 0x00, 0x00, 0x00, 0x21
676 asize = ARRAY_SIZE(values_204);
678 for(i=0; i<asize; i++) {
679 usb_stk11xx_read_registry(dev, 0x02ff, &value);
680 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
682 usb_stk11xx_write_registry(dev, 0x0203, 0x00ba);
684 usb_stk11xx_write_registry(dev, 0x0204, values_204[i]);
685 usb_stk11xx_write_registry(dev, 0x0205, values_205[i]);
686 usb_stk11xx_write_registry(dev, 0x0200, 0x0001);
688 retok = dev_stk11xx_check_device(dev, 500);
690 if (retok != 1) {
691 STK_ERROR("Load default sensor settings fail !\n");
692 return -1;
695 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
698 retok = dev_stk11xx_check_device(dev, 500);
700 return 0;
704 /**
705 * @param dev Device structure
707 * @returns 0 if all is OK
709 * @brief This function permits to modify the settings of the camera.
711 * This functions permits to modify the settings :
712 * - brightness
713 * - contrast
714 * - white balance
715 * - ...
717 int dev_stk6a31_camera_settings(struct usb_stk11xx *dev)
719 int i;
720 int ret;
721 int value;
723 int asize;
724 static const int values_204[] = {
725 0xf0, 0xf1, 0x2e, 0xf1, 0xf0, 0xf1, 0x5b, 0xf1, 0xf0, 0xf1, 0x36, 0xf1, 0x37, 0xf1, 0xf0, 0xf1, 0x08, 0xf1
727 static const int values_205[] = {
728 0x00, 0x02, 0x0c, 0x3c, 0x00, 0x02, 0x00, 0x03, 0x00, 0x02, 0x78, 0x10, 0x83, 0x04, 0x00, 0x00, 0x00, 0x21
732 asize = ARRAY_SIZE(values_204);
734 // Contrast register
735 for (i=0; i<asize; i++) {
736 usb_stk11xx_read_registry(dev, 0x02ff, &value);
737 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
739 usb_stk11xx_write_registry(dev, 0x0204, values_204[i]);
740 usb_stk11xx_write_registry(dev, 0x0205, values_205[i]);
742 usb_stk11xx_write_registry(dev, 0x0200, 0x0001);
743 ret = dev_stk11xx_check_device(dev, 500);
744 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
747 return 0;
751 /**
752 * @param dev Device structure
754 * @returns 0 if all is OK
756 * @brief This function permits to modify the settings of the camera.
758 * This functions permits to modify the settings :
759 * - brightness
760 * - contrast
761 * - white balance
762 * - ...
764 int dev_stk6a31_set_camera_quality(struct usb_stk11xx *dev)
766 int ret;
767 int value;
769 // Contrast register
770 usb_stk11xx_read_registry(dev, 0x02ff, &value);
771 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
773 usb_stk11xx_write_registry(dev, 0x0204, 0x00b3);
774 usb_stk11xx_write_registry(dev, 0x0205, (dev->vsettings.contrast >> 8));
776 usb_stk11xx_write_registry(dev, 0x0200, 0x0001);
777 ret = dev_stk11xx_check_device(dev, 500);
778 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
780 STK_DEBUG("Set colour : %d\n", dev->vsettings.colour);
781 STK_DEBUG("Set contrast : %d\n", dev->vsettings.contrast);
782 STK_DEBUG("Set whiteness : %d\n", dev->vsettings.whiteness);
783 STK_DEBUG("Set brightness : %d\n", dev->vsettings.brightness);
785 return 0;
789 /**
790 * @param dev Device structure
792 * @returns 0 if all is OK
794 * @brief This function permits to modify the settings of the camera.
796 * This functions permits to modify the frame rate per second.
798 int dev_stk6a31_set_camera_fps(struct usb_stk11xx *dev)
800 return 0;
804 /**
805 * @param dev Device structure
807 * @returns 0 if all is OK
809 * @brief This function sets the device to start the stream.
811 * After the initialization of the device and the initialization of the video stream,
812 * this function permits to enable the stream.
814 int dev_stk6a31_start_stream(struct usb_stk11xx *dev)
816 int value;
817 int value_116, value_117;
819 usb_stk11xx_read_registry(dev, 0x0114, &value); // read 0x80
820 usb_stk11xx_read_registry(dev, 0x0115, &value); // read 0x02
822 usb_stk11xx_read_registry(dev, 0x0116, &value_116);
823 usb_stk11xx_read_registry(dev, 0x0117, &value_117);
825 usb_stk11xx_write_registry(dev, 0x0116, 0x0000);
826 usb_stk11xx_write_registry(dev, 0x0117, 0x0000);
828 usb_stk11xx_read_registry(dev, 0x0100, &value); // read 0x21
829 usb_stk11xx_write_registry(dev, 0x0100, 0x00a0);
831 usb_stk11xx_write_registry(dev, 0x0116, value_116);
832 usb_stk11xx_write_registry(dev, 0x0117, value_117);
834 return 0;
838 /**
839 * @param dev Device structure
841 * @returns 0 if all is OK
843 * @brief Reconfigure the camera before the stream.
845 * Before enabling the video stream, you have to reconfigure the device.
847 int dev_stk6a31_reconf_camera(struct usb_stk11xx *dev)
849 dev_stk6a31_configure_device(dev, 16);
851 dev_stk11xx_camera_settings(dev);
853 return 0;
857 /**
858 * @param dev Device structure
860 * @returns 0 if all is OK
862 * @brief This function sets the device to stop the stream.
864 * You use the function start_stream to enable the video stream. So you
865 * have to use the function stop_strem to disable the video stream.
867 int dev_stk6a31_stop_stream(struct usb_stk11xx *dev)
869 return 0;