don't manage version it's boring.
[syntekdriver.git] / driver / stk11xx-dev-6a31.c
blob92df2f36ae4b96a6d748260619709ceb7c712b8b
1 /**
2 * @file stk11xx-dev-6a31.c
3 * @author Nicolas VIVIEN
4 * @date 2007-11-23
5 * @version v2.2.x
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>
44 #include <media/v4l2-ioctl.h>
46 #include "stk11xx.h"
47 #include "stk11xx-dev.h"
50 //=============================================================================
52 // STK-6A31 API
54 //=============================================================================
57 /**
58 * @param dev Device structure
60 * @returns 0 if all is OK
62 * @brief This function permits to initialize the device.
64 * This function must be called at first. It's the start of the
65 * initialization process. After this process, the device is
66 * completly initalized and it's ready.
68 * This function is written from the USB log.
70 int dev_stk6a31_initialize_device(struct usb_stk11xx *dev)
72 STK_INFO("Initialize USB2.0 Syntek Camera\n");
74 usb_stk11xx_write_registry(dev, 0x0000, 0x00e0);
75 usb_stk11xx_write_registry(dev, 0x0002, 0x00f8);
76 usb_stk11xx_write_registry(dev, 0x0002, 0x0078);
77 usb_stk11xx_write_registry(dev, 0x0000, 0x0020);
79 dev_stk6a31_configure_device(dev, 0);
80 dev_stk11xx_check_device(dev, 65);
81 usb_stk11xx_write_registry(dev, 0x0200, 0x0008);
83 dev_stk6a31_configure_device(dev, 1);
84 dev_stk11xx_check_device(dev, 65);
85 usb_stk11xx_write_registry(dev, 0x0200, 0x0008);
87 dev_stk6a31_configure_device(dev, 2);
88 dev_stk11xx_check_device(dev, 65);
89 usb_stk11xx_write_registry(dev, 0x0200, 0x0008);
91 dev_stk6a31_configure_device(dev, 3);
92 dev_stk11xx_check_device(dev, 65);
93 usb_stk11xx_write_registry(dev, 0x0200, 0x0008);
95 dev_stk6a31_configure_device(dev, 4);
96 dev_stk11xx_check_device(dev, 65);
97 usb_stk11xx_write_registry(dev, 0x0200, 0x0008);
99 dev_stk6a31_configure_device(dev, 5);
100 dev_stk11xx_check_device(dev, 65);
101 usb_stk11xx_write_registry(dev, 0x0200, 0x0008);
103 dev_stk6a31_configure_device(dev, 6);
104 dev_stk11xx_check_device(dev, 65);
105 usb_stk11xx_write_registry(dev, 0x0200, 0x0008);
107 dev_stk6a31_configure_device(dev, 7);
108 dev_stk11xx_check_device(dev, 65);
109 usb_stk11xx_write_registry(dev, 0x0200, 0x0008);
111 dev_stk6a31_configure_device(dev, 8);
113 dev_stk6a31_configure_device(dev, 9);
114 dev_stk11xx_check_device(dev, 65);
115 usb_stk11xx_write_registry(dev, 0x0200, 0x0008);
117 dev_stk6a31_configure_device(dev, 10);
118 dev_stk11xx_check_device(dev, 65);
119 usb_stk11xx_write_registry(dev, 0x0200, 0x0008);
121 dev_stk6a31_configure_device(dev, 11);
123 dev_stk6a31_configure_device(dev, 12);
125 dev_stk6a31_configure_device(dev, 13);
127 dev_stk6a31_configure_device(dev, 14);
129 dev_stk6a31_camera_asleep(dev);
131 usb_stk11xx_set_feature(dev, 0);
133 // Device is initialized and is ready !!!
134 STK_INFO("Syntek USB2.0 Camera is ready\n");
136 return 0;
140 /**
141 * @param dev Device structure
142 * @param step The step of configuration [0-11]
144 * @returns 0 if all is OK
146 * @brief This function permits to configure the device.
148 * The configuration of device is composed of 12 steps.
149 * This function is called by the initialization process.
151 * We don't know the meaning of these steps ! We only replay the USB log.
153 int dev_stk6a31_configure_device(struct usb_stk11xx *dev, int step)
155 int value;
157 // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
158 static const int values_001B[] = {
159 0x03, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07
161 static const int values_001C[] = {
162 0x02, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06
164 static const int values_0202[] = {
165 0x0a, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x0a, 0x1e, 0x1f, 0x1f, 0x1f, 0x1f
167 static const int values_0110[] = {
168 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
170 static const int values_0112[] = {
171 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
173 static const int values_0114[] = {
174 0x80, 0x80, 0x80, 0x80, 0x00, 0xbe, 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x80
176 static const int values_0115[] = {
177 0x02, 0x02, 0x02, 0x02, 0x05, 0x02, 0x02, 0x02, 0x00, 0x02, 0x02, 0x02, 0x05, 0x02, 0x02, 0x02, 0x02
179 static const int values_0116[] = {
180 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe9, 0xe0, 0xe0, 0x00, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0
182 static const int values_0117[] = {
183 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01
185 static const int values_0100[] = {
186 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
190 STK_DEBUG("dev_stk6a31_configure_device : %d\n", step);
192 usb_stk11xx_write_registry(dev, 0x0000, 0x0024);
193 usb_stk11xx_write_registry(dev, 0x0002, 0x0078);
194 usb_stk11xx_write_registry(dev, 0x0003, 0x0080);
195 usb_stk11xx_write_registry(dev, 0x0005, 0x0000);
197 usb_stk11xx_write_registry(dev, 0x0007, 0x0003);
198 usb_stk11xx_write_registry(dev, 0x000d, 0x0000);
199 usb_stk11xx_write_registry(dev, 0x000f, 0x0002);
200 usb_stk11xx_write_registry(dev, 0x0300, 0x0012);
201 usb_stk11xx_write_registry(dev, 0x0350, 0x0041);
203 usb_stk11xx_write_registry(dev, 0x0351, 0x0000);
204 usb_stk11xx_write_registry(dev, 0x0352, 0x0000);
205 usb_stk11xx_write_registry(dev, 0x0353, 0x0000);
206 usb_stk11xx_write_registry(dev, 0x0018, 0x0010);
207 usb_stk11xx_write_registry(dev, 0x0019, 0x0000);
209 usb_stk11xx_write_registry(dev, 0x001b, values_001B[step]);
210 usb_stk11xx_write_registry(dev, 0x001c, values_001C[step]);
211 usb_stk11xx_write_registry(dev, 0x0300, 0x0080);
212 usb_stk11xx_write_registry(dev, 0x001a, 0x0004);
213 usb_stk11xx_write_registry(dev, 0x0202, values_0202[step]);
215 usb_stk11xx_write_registry(dev, 0x0110, values_0110[step]);
216 usb_stk11xx_write_registry(dev, 0x0111, 0x0000);
217 usb_stk11xx_write_registry(dev, 0x0112, values_0112[step]);
218 usb_stk11xx_write_registry(dev, 0x0113, 0x0000);
219 usb_stk11xx_write_registry(dev, 0x0114, values_0114[step]);
221 usb_stk11xx_write_registry(dev, 0x0115, values_0115[step]);
222 usb_stk11xx_write_registry(dev, 0x0116, values_0116[step]);
223 usb_stk11xx_write_registry(dev, 0x0117, values_0117[step]);
225 usb_stk11xx_read_registry(dev, 0x0100, &value);
226 usb_stk11xx_write_registry(dev, 0x0100, values_0100[step]);
228 // usb_stk11xx_write_registry(dev, 0x0200, 0x0080);
229 // usb_stk11xx_write_registry(dev, 0x0200, 0x0000);
230 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
233 switch (step) {
234 case 0:
235 usb_stk11xx_write_registry(dev, 0x0203, 0x0022);
237 usb_stk11xx_write_registry(dev, 0x0204, 0x0027);
238 usb_stk11xx_write_registry(dev, 0x0205, 0x00a5);
240 usb_stk11xx_write_registry(dev, 0x0200, 0x0005);
242 break;
244 case 1:
245 usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
247 usb_stk11xx_write_registry(dev, 0x0204, 0x0012);
248 usb_stk11xx_write_registry(dev, 0x0205, 0x0080);
249 usb_stk11xx_write_registry(dev, 0x0204, 0x0013);
250 usb_stk11xx_write_registry(dev, 0x0205, 0x00bf);
252 usb_stk11xx_write_registry(dev, 0x0200, 0x0005);
254 break;
256 case 2:
257 usb_stk11xx_write_registry(dev, 0x0203, 0x0042);
259 usb_stk11xx_write_registry(dev, 0x0204, 0x0012);
260 usb_stk11xx_write_registry(dev, 0x0205, 0x0080);
261 usb_stk11xx_write_registry(dev, 0x0204, 0x0024);
262 usb_stk11xx_write_registry(dev, 0x0205, 0x00a5);
264 usb_stk11xx_write_registry(dev, 0x0200, 0x0005);
266 break;
268 case 3:
269 usb_stk11xx_write_registry(dev, 0x0203, 0x0042);
271 usb_stk11xx_write_registry(dev, 0x0204, 0x0012);
272 usb_stk11xx_write_registry(dev, 0x0205, 0x0080);
273 usb_stk11xx_write_registry(dev, 0x0204, 0x0013);
274 usb_stk11xx_write_registry(dev, 0x0205, 0x00e0);
275 usb_stk11xx_write_registry(dev, 0x0204, 0x0024);
276 usb_stk11xx_write_registry(dev, 0x0205, 0x00a5);
278 usb_stk11xx_write_registry(dev, 0x0200, 0x0005);
280 break;
282 case 4:
283 usb_stk11xx_write_registry(dev, 0x0203, 0x0042);
285 usb_stk11xx_write_registry(dev, 0x0204, 0x0012);
286 usb_stk11xx_write_registry(dev, 0x0205, 0x0080);
287 usb_stk11xx_write_registry(dev, 0x0204, 0x0013);
288 usb_stk11xx_write_registry(dev, 0x0205, 0x00bf);
290 usb_stk11xx_write_registry(dev, 0x0200, 0x0005);
292 break;
294 case 5:
295 usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
297 usb_stk11xx_write_registry(dev, 0x0204, 0x0012);
298 usb_stk11xx_write_registry(dev, 0x0205, 0x0080);
299 usb_stk11xx_write_registry(dev, 0x0204, 0x0013);
300 usb_stk11xx_write_registry(dev, 0x0205, 0x00ff);
302 usb_stk11xx_write_registry(dev, 0x0200, 0x0005);
304 break;
306 case 6:
307 usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
309 usb_stk11xx_write_registry(dev, 0x0204, 0x0012);
310 usb_stk11xx_write_registry(dev, 0x0205, 0x0080);
311 usb_stk11xx_write_registry(dev, 0x0204, 0x0013);
312 usb_stk11xx_write_registry(dev, 0x0205, 0x00b7);
314 usb_stk11xx_write_registry(dev, 0x0200, 0x0005);
316 break;
318 case 7:
319 usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
321 usb_stk11xx_write_registry(dev, 0x0204, 0x0012);
322 usb_stk11xx_write_registry(dev, 0x0205, 0x0080);
323 usb_stk11xx_write_registry(dev, 0x0204, 0x0013);
324 usb_stk11xx_write_registry(dev, 0x0205, 0x00b7);
326 usb_stk11xx_write_registry(dev, 0x0200, 0x0005);
328 break;
330 case 8:
331 usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
333 usb_stk11xx_read_registry(dev, 0x02ff, &value);
334 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
336 usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
337 usb_stk11xx_write_registry(dev, 0x0204, 0x00ff);
338 usb_stk11xx_write_registry(dev, 0x0205, 0x0001);
339 usb_stk11xx_write_registry(dev, 0x0200, 0x0001);
340 dev_stk11xx_check_device(dev, 500);
341 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
342 usb_stk11xx_read_registry(dev, 0x02ff, &value);
343 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
345 usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
346 usb_stk11xx_write_registry(dev, 0x0208, 0x000a);
347 usb_stk11xx_write_registry(dev, 0x0200, 0x0020);
348 dev_stk11xx_check_device(dev, 500);
349 usb_stk11xx_read_registry(dev, 0x0209, &value);
350 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
351 usb_stk11xx_read_registry(dev, 0x02ff, &value);
352 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
354 usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
355 usb_stk11xx_write_registry(dev, 0x0208, 0x000b);
356 usb_stk11xx_write_registry(dev, 0x0200, 0x0020);
357 dev_stk11xx_check_device(dev, 500);
358 usb_stk11xx_read_registry(dev, 0x0209, &value);
359 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
360 usb_stk11xx_read_registry(dev, 0x02ff, &value);
361 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
363 usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
364 usb_stk11xx_write_registry(dev, 0x0208, 0x001c);
365 usb_stk11xx_write_registry(dev, 0x0200, 0x0020);
366 dev_stk11xx_check_device(dev, 500);
367 usb_stk11xx_read_registry(dev, 0x0209, &value);
368 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
369 usb_stk11xx_read_registry(dev, 0x02ff, &value);
370 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
372 usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
373 usb_stk11xx_write_registry(dev, 0x0208, 0x001d);
374 usb_stk11xx_write_registry(dev, 0x0200, 0x0020);
375 dev_stk11xx_check_device(dev, 500);
376 usb_stk11xx_read_registry(dev, 0x0209, &value);
377 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
379 break;
381 case 9:
382 usb_stk11xx_write_registry(dev, 0x0203, 0x00dc);
384 usb_stk11xx_write_registry(dev, 0x0204, 0x0015);
385 usb_stk11xx_write_registry(dev, 0x0205, 0x0080);
387 usb_stk11xx_write_registry(dev, 0x0200, 0x0005);
389 break;
391 case 10:
392 usb_stk11xx_write_registry(dev, 0x0203, 0x00ec);
394 usb_stk11xx_write_registry(dev, 0x0204, 0x0015);
395 usb_stk11xx_write_registry(dev, 0x0205, 0x0080);
397 usb_stk11xx_write_registry(dev, 0x0200, 0x0005);
399 break;
401 case 11:
402 usb_stk11xx_write_registry(dev, 0x0203, 0x00ba);
404 usb_stk11xx_read_registry(dev, 0x02ff, &value);
405 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
407 usb_stk11xx_write_registry(dev, 0x0203, 0x00ba);
409 usb_stk11xx_write_registry(dev, 0x0208, 0x0000);
410 usb_stk11xx_write_registry(dev, 0x0200, 0x0020);
411 dev_stk11xx_check_device(dev, 500);
412 usb_stk11xx_read_registry(dev, 0x0209, &value);
413 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
415 break;
417 case 12:
418 usb_stk11xx_write_registry(dev, 0x0203, 0x00ba);
420 usb_stk11xx_write_registry(dev, 0x0204, 0x00f0);
421 usb_stk11xx_write_registry(dev, 0x0205, 0x0000);
422 usb_stk11xx_write_registry(dev, 0x0200, 0x0005);
423 dev_stk11xx_check_device(dev, 500);
424 usb_stk11xx_write_registry(dev, 0x0204, 0x00f1);
425 usb_stk11xx_write_registry(dev, 0x0205, 0x0000);
426 usb_stk11xx_write_registry(dev, 0x0200, 0x0005);
427 dev_stk11xx_check_device(dev, 500);
428 usb_stk11xx_read_registry(dev, 0x02ff, &value);
429 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
431 usb_stk11xx_write_registry(dev, 0x0203, 0x00ba);
432 usb_stk11xx_write_registry(dev, 0x0208, 0x0000);
433 usb_stk11xx_write_registry(dev, 0x0200, 0x0020);
434 dev_stk11xx_check_device(dev, 500);
435 usb_stk11xx_read_registry(dev, 0x0209, &value);
436 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
437 usb_stk11xx_read_registry(dev, 0x02ff, &value);
438 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
440 usb_stk11xx_write_registry(dev, 0x0203, 0x00ba);
441 usb_stk11xx_write_registry(dev, 0x0208, 0x00f1);
442 usb_stk11xx_write_registry(dev, 0x0200, 0x0020);
443 dev_stk11xx_check_device(dev, 500);
444 usb_stk11xx_read_registry(dev, 0x0209, &value);
445 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
447 break;
449 case 13:
450 usb_stk11xx_write_registry(dev, 0x0203, 0x00ba);
452 usb_stk11xx_read_registry(dev, 0x02ff, &value);
453 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
455 usb_stk11xx_write_registry(dev, 0x0203, 0x00ba);
456 usb_stk11xx_write_registry(dev, 0x0208, 0x0000);
457 usb_stk11xx_write_registry(dev, 0x0200, 0x0020);
458 dev_stk11xx_check_device(dev, 500);
459 usb_stk11xx_read_registry(dev, 0x0209, &value);
460 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
461 usb_stk11xx_read_registry(dev, 0x02ff, &value);
462 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
464 usb_stk11xx_write_registry(dev, 0x0203, 0x00ba);
465 usb_stk11xx_write_registry(dev, 0x0208, 0x00f1);
466 usb_stk11xx_write_registry(dev, 0x0200, 0x0020);
467 dev_stk11xx_check_device(dev, 500);
468 usb_stk11xx_read_registry(dev, 0x0209, &value);
469 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
471 break;
473 case 14:
474 usb_stk11xx_write_registry(dev, 0x0203, 0x00ba);
476 usb_stk11xx_write_registry(dev, 0x0204, 0x0001);
477 usb_stk11xx_write_registry(dev, 0x0205, 0x0000);
478 usb_stk11xx_write_registry(dev, 0x0200, 0x0005);
479 dev_stk11xx_check_device(dev, 500);
480 usb_stk11xx_write_registry(dev, 0x0204, 0x00f1);
481 usb_stk11xx_write_registry(dev, 0x0205, 0x0000);
482 usb_stk11xx_write_registry(dev, 0x0200, 0x0005);
483 dev_stk11xx_check_device(dev, 500);
484 usb_stk11xx_read_registry(dev, 0x02ff, &value);
485 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
487 usb_stk11xx_write_registry(dev, 0x0203, 0x00ba);
488 usb_stk11xx_write_registry(dev, 0x0208, 0x0000);
489 usb_stk11xx_write_registry(dev, 0x0200, 0x0020);
490 dev_stk11xx_check_device(dev, 500);
491 usb_stk11xx_read_registry(dev, 0x0209, &value);
492 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
493 usb_stk11xx_read_registry(dev, 0x02ff, &value);
494 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
496 usb_stk11xx_write_registry(dev, 0x0203, 0x00ba);
497 usb_stk11xx_write_registry(dev, 0x0208, 0x00f1);
498 usb_stk11xx_write_registry(dev, 0x0200, 0x0020);
499 dev_stk11xx_check_device(dev, 500);
500 usb_stk11xx_read_registry(dev, 0x0209, &value);
501 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
503 break;
505 case 15:
506 usb_stk11xx_write_registry(dev, 0x0203, 0x00ba);
508 dev_stk6a31_sensor_settings(dev);
510 usb_stk11xx_write_registry(dev, 0x0200, 0x0080);
511 usb_stk11xx_write_registry(dev, 0x0200, 0x0000);
512 usb_stk11xx_write_registry(dev, 0x02ff, 0x0001);
513 usb_stk11xx_write_registry(dev, 0x0203, 0x00a0);
516 break;
518 case 16:
519 usb_stk11xx_write_registry(dev, 0x0203, 0x00ba);
521 dev_stk6a31_sensor_settings(dev);
523 break;
526 return 0;
530 /**
531 * @param dev Device structure
533 * @returns 0 if all is OK
535 * @brief Wake-up the camera.
537 * This function permits to wake-up the device.
539 int dev_stk6a31_camera_asleep(struct usb_stk11xx *dev)
541 int value;
543 usb_stk11xx_read_registry(dev, 0x0104, &value);
544 usb_stk11xx_read_registry(dev, 0x0105, &value);
545 usb_stk11xx_read_registry(dev, 0x0106, &value);
547 usb_stk11xx_write_registry(dev, 0x0100, 0x0021);
548 usb_stk11xx_write_registry(dev, 0x0116, 0x0000);
549 usb_stk11xx_write_registry(dev, 0x0117, 0x0000);
550 usb_stk11xx_write_registry(dev, 0x0018, 0x0000);
552 usb_stk11xx_read_registry(dev, 0x0000, &value);
553 usb_stk11xx_write_registry(dev, 0x0000, 0x0049);
555 return 0;
559 /**
560 * @param dev Device structure
562 * @returns 0 if all is OK
564 * @brief This function initializes the device for the stream.
566 * It's the start. This function has to be called at first, before
567 * enabling the video stream.
569 int dev_stk6a31_init_camera(struct usb_stk11xx *dev)
571 // int retok;
572 // int value;
574 dev_stk6a31_camera_asleep(dev);
576 usb_stk11xx_set_feature(dev, 0);
578 dev_stk6a31_camera_asleep(dev);
580 usb_stk11xx_write_registry(dev, 0x0000, 0x00e0);
581 usb_stk11xx_write_registry(dev, 0x0002, 0x00f8);
582 usb_stk11xx_write_registry(dev, 0x0002, 0x0078);
583 usb_stk11xx_write_registry(dev, 0x0000, 0x0020);
585 dev_stk6a31_configure_device(dev, 15);
587 dev_stk11xx_camera_off(dev);
589 return 0;
593 /**
594 * @param dev Device structure
596 * @returns 0 if all is OK
598 * @brief This function permits to set default sensor settings.
600 * We set some registers in using a I2C bus.
601 * WARNING, the sensor settings can be different following the situation.
603 int dev_stk6a31_sensor_settings(struct usb_stk11xx *dev)
605 int i;
606 int retok;
607 int value;
609 int asize;
610 static const int values_204[] = {
611 0xf0, 0xf1, 0x0d, 0xf1, 0x0d, 0xf1, 0xf0, 0xf1, 0x35, 0xf1,
612 0xf0, 0xf1, 0x06, 0xf1, 0xf0, 0xf1, 0xdd, 0xf1, 0xf0, 0xf1,
613 0x1f, 0xf1, 0x20, 0xf1, 0x21, 0xf1, 0x22, 0xf1, 0x23, 0xf1,
614 0x24, 0xf1, 0x28, 0xf1, 0x29, 0xf1, 0x5e, 0xf1, 0x5f, 0xf1,
615 0x60, 0xf1, 0xef, 0xf1, 0xf2, 0xf1, 0x02, 0xf1, 0x03, 0xf1,
616 0x04, 0xf1, 0x09, 0xf1, 0x0a, 0xf1, 0x0b, 0xf1, 0x0c, 0xf1,
617 0x0d, 0xf1, 0x0e, 0xf1, 0x0f, 0xf1, 0x10, 0xf1, 0x11, 0xf1,
618 0x15, 0xf1, 0x16, 0xf1, 0x17, 0xf1, 0x18, 0xf1, 0x19, 0xf1,
619 0x1a, 0xf1, 0x1b, 0xf1, 0x1c, 0xf1, 0x1d, 0xf1, 0x1e, 0xf1,
620 0xf0, 0xf1, 0x06, 0xf1, 0x06, 0xf1, 0xf0, 0xf1, 0x80, 0xf1,
621 0x81, 0xf1, 0x82, 0xf1, 0x83, 0xf1, 0x84, 0xf1, 0x85, 0xf1,
622 0x86, 0xf1, 0x87, 0xf1, 0x88, 0xf1, 0x89, 0xf1, 0x8a, 0xf1,
623 0x8b, 0xf1, 0x8c, 0xf1, 0x8d, 0xf1, 0x8e, 0xf1, 0x8f, 0xf1,
624 0x90, 0xf1, 0x91, 0xf1, 0x92, 0xf1, 0x93, 0xf1, 0x94, 0xf1,
625 0x95, 0xf1, 0xb6, 0xf1, 0xb7, 0xf1, 0xb8, 0xf1, 0xb9, 0xf1,
626 0xba, 0xf1, 0xbb, 0xf1, 0xbc, 0xf1, 0xbd, 0xf1, 0xbe, 0xf1,
627 0xbf, 0xf1, 0xc0, 0xf1, 0xc1, 0xf1, 0xc2, 0xf1, 0xc3, 0xf1,
628 0xc4, 0xf1, 0x06, 0xf1, 0xf0, 0xf1, 0x53, 0xf1, 0x54, 0xf1,
629 0x55, 0xf1, 0x56, 0xf1, 0x57, 0xf1, 0x58, 0xf1, 0xdc, 0xf1,
630 0xdd, 0xf1, 0xde, 0xf1, 0xdf, 0xf1, 0xe0, 0xf1, 0xe1, 0xf1,
631 0xf0, 0xf1, 0xa7, 0xf1, 0xaa, 0xf1, 0x3a, 0xf1, 0xa1, 0xf1,
632 0xa4, 0xf1, 0x9b, 0xf1, 0x08, 0xf1, 0xf0, 0xf1, 0x2f, 0xf1,
633 0x9c, 0xf1, 0xd2, 0xf1, 0xcc, 0xf1, 0xcb, 0xf1, 0x2e, 0xf1,
634 0x67, 0xf1, 0xf0, 0xf1, 0x65, 0xf1, 0x66, 0xf1, 0x67, 0xf1,
635 0x65, 0xf1, 0xf0, 0xf1, 0x05, 0xf1, 0x07, 0xf1, 0xf0, 0xf1,
636 0x39, 0xf1, 0x3b, 0xf1, 0x3a, 0xf1, 0x3c, 0xf1, 0x57, 0xf1,
637 0x58, 0xf1, 0x59, 0xf1, 0x5a, 0xf1, 0x5c, 0xf1, 0x5d, 0xf1,
638 0x64, 0xf1, 0xf0, 0xf1, 0x5b, 0xf1, 0xf0, 0xf1, 0x36, 0xf1,
639 0x37, 0xf1, 0xf0, 0xf1, 0x08, 0xf1
641 static const int values_205[] = {
642 0x00, 0x00, 0x00, 0x0b, 0x00, 0x08, 0x00, 0x00, 0x00, 0x22,
643 0x00, 0x01, 0x70, 0x0e, 0x00, 0x02, 0x18, 0xe0, 0x00, 0x02,
644 0x01, 0x80, 0xc8, 0x14, 0x80, 0x80, 0xa0, 0x78, 0xa0, 0x78,
645 0x5f, 0x20, 0xea, 0x02, 0x86, 0x7a, 0x59, 0x4c, 0x4d, 0x51,
646 0x00, 0x02, 0x00, 0x08, 0x00, 0x00, 0x00, 0xee, 0x39, 0x23,
647 0x07, 0x24, 0x00, 0xcd, 0x00, 0x93, 0x00, 0x04, 0x00, 0x5c,
648 0x00, 0xd9, 0x00, 0x53, 0x00, 0x08, 0x00, 0x91, 0x00, 0xcf,
649 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
650 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
651 0x00, 0x01, 0xf0, 0x0e, 0x70, 0x0e, 0x00, 0x01, 0x00, 0x07,
652 0xde, 0x13, 0xeb, 0xe2, 0x00, 0xf6, 0xe1, 0x14, 0xea, 0xdd,
653 0xfd, 0xf6, 0xe5, 0x11, 0xed, 0xe6, 0xfb, 0xf7, 0xd6, 0x13,
654 0xed, 0xec, 0xf9, 0xf2, 0x00, 0x00, 0xd8, 0x15, 0xe9, 0xea,
655 0xf9, 0xf1, 0x00, 0x02, 0xde, 0x10, 0xef, 0xef, 0xfb, 0xf4,
656 0x00, 0x02, 0x0e, 0x06, 0x27, 0x13, 0x11, 0x06, 0x27, 0x13,
657 0x0c, 0x03, 0x2a, 0x0f, 0x12, 0x08, 0x1a, 0x16, 0x00, 0x22,
658 0x15, 0x0a, 0x1c, 0x1a, 0x00, 0x2d, 0x11, 0x09, 0x14, 0x14,
659 0x00, 0x2a, 0x74, 0x0e, 0x00, 0x01, 0x0b, 0x03, 0x47, 0x22,
660 0xac, 0x82, 0xda, 0xc7, 0xf5, 0xe9, 0xff, 0x00, 0x0b, 0x03,
661 0x47, 0x22, 0xac, 0x82, 0xda, 0xc7, 0xf5, 0xe9, 0xff, 0x00,
662 0x00, 0x01, 0x02, 0x80, 0x01, 0xe0, 0x43, 0x00, 0x05, 0x00,
663 0x04, 0x00, 0x43, 0x00, 0x01, 0x80, 0x00, 0x02, 0xd1, 0x00,
664 0xd1, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x0c, 0x3c,
665 0x10, 0x10, 0x00, 0x00, 0xa0, 0x00, 0x20, 0x03, 0x05, 0x01,
666 0x20, 0x00, 0x00, 0x00, 0x01, 0xb8, 0x00, 0xd8, 0x00, 0x02,
667 0x06, 0xc0, 0x04, 0x0e, 0x06, 0xc0, 0x05, 0x64, 0x02, 0x08,
668 0x02, 0x71, 0x02, 0x09, 0x02, 0x71, 0x12, 0x0d, 0x17, 0x12,
669 0x5e, 0x1c, 0x00, 0x02, 0x00, 0x03, 0x00, 0x02, 0x78, 0x10,
670 0x83, 0x04, 0x00, 0x00, 0x00, 0x21
674 asize = ARRAY_SIZE(values_204);
676 for(i=0; i<asize; i++) {
677 usb_stk11xx_read_registry(dev, 0x02ff, &value);
678 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
680 usb_stk11xx_write_registry(dev, 0x0203, 0x00ba);
682 usb_stk11xx_write_registry(dev, 0x0204, values_204[i]);
683 usb_stk11xx_write_registry(dev, 0x0205, values_205[i]);
684 usb_stk11xx_write_registry(dev, 0x0200, 0x0001);
686 retok = dev_stk11xx_check_device(dev, 500);
688 if (retok != 1) {
689 STK_ERROR("Load default sensor settings fail !\n");
690 return -1;
693 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
696 retok = dev_stk11xx_check_device(dev, 500);
698 return 0;
702 /**
703 * @param dev Device structure
705 * @returns 0 if all is OK
707 * @brief This function permits to modify the settings of the camera.
709 * This functions permits to modify the settings :
710 * - brightness
711 * - contrast
712 * - white balance
713 * - ...
715 int dev_stk6a31_camera_settings(struct usb_stk11xx *dev)
717 int i;
718 int value;
720 int asize;
721 static const int values_204[] = {
722 0xf0, 0xf1, 0x2e, 0xf1, 0xf0, 0xf1, 0x5b, 0xf1, 0xf0, 0xf1, 0x36, 0xf1, 0x37, 0xf1, 0xf0, 0xf1, 0x08, 0xf1
724 static const int values_205[] = {
725 0x00, 0x02, 0x0c, 0x3c, 0x00, 0x02, 0x00, 0x03, 0x00, 0x02, 0x78, 0x10, 0x83, 0x04, 0x00, 0x00, 0x00, 0x21
729 asize = ARRAY_SIZE(values_204);
731 // Contrast register
732 for (i=0; i<asize; i++) {
733 usb_stk11xx_read_registry(dev, 0x02ff, &value);
734 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
736 usb_stk11xx_write_registry(dev, 0x0204, values_204[i]);
737 usb_stk11xx_write_registry(dev, 0x0205, values_205[i]);
739 usb_stk11xx_write_registry(dev, 0x0200, 0x0001);
740 dev_stk11xx_check_device(dev, 500);
741 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
744 return 0;
748 /**
749 * @param dev Device structure
751 * @returns 0 if all is OK
753 * @brief This function permits to modify the settings of the camera.
755 * This functions permits to modify the settings :
756 * - brightness
757 * - contrast
758 * - white balance
759 * - ...
761 int dev_stk6a31_set_camera_quality(struct usb_stk11xx *dev)
763 int value;
765 // Contrast register
766 usb_stk11xx_read_registry(dev, 0x02ff, &value);
767 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
769 usb_stk11xx_write_registry(dev, 0x0204, 0x00b3);
770 usb_stk11xx_write_registry(dev, 0x0205, (dev->vsettings.contrast >> 8));
772 usb_stk11xx_write_registry(dev, 0x0200, 0x0001);
773 dev_stk11xx_check_device(dev, 500);
774 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
776 STK_DEBUG("Set colour : %d\n", dev->vsettings.colour);
777 STK_DEBUG("Set contrast : %d\n", dev->vsettings.contrast);
778 STK_DEBUG("Set whiteness : %d\n", dev->vsettings.whiteness);
779 STK_DEBUG("Set brightness : %d\n", dev->vsettings.brightness);
781 return 0;
785 /**
786 * @param dev Device structure
788 * @returns 0 if all is OK
790 * @brief This function permits to modify the settings of the camera.
792 * This functions permits to modify the frame rate per second.
794 int dev_stk6a31_set_camera_fps(struct usb_stk11xx *dev)
796 return 0;
800 /**
801 * @param dev Device structure
803 * @returns 0 if all is OK
805 * @brief This function sets the device to start the stream.
807 * After the initialization of the device and the initialization of the video stream,
808 * this function permits to enable the stream.
810 int dev_stk6a31_start_stream(struct usb_stk11xx *dev)
812 int value;
813 int value_116, value_117;
815 usb_stk11xx_read_registry(dev, 0x0114, &value); // read 0x80
816 usb_stk11xx_read_registry(dev, 0x0115, &value); // read 0x02
818 usb_stk11xx_read_registry(dev, 0x0116, &value_116);
819 usb_stk11xx_read_registry(dev, 0x0117, &value_117);
821 usb_stk11xx_write_registry(dev, 0x0116, 0x0000);
822 usb_stk11xx_write_registry(dev, 0x0117, 0x0000);
824 usb_stk11xx_read_registry(dev, 0x0100, &value); // read 0x21
825 usb_stk11xx_write_registry(dev, 0x0100, 0x00a0);
827 usb_stk11xx_write_registry(dev, 0x0116, value_116);
828 usb_stk11xx_write_registry(dev, 0x0117, value_117);
830 return 0;
834 /**
835 * @param dev Device structure
837 * @returns 0 if all is OK
839 * @brief Reconfigure the camera before the stream.
841 * Before enabling the video stream, you have to reconfigure the device.
843 int dev_stk6a31_reconf_camera(struct usb_stk11xx *dev)
845 dev_stk6a31_configure_device(dev, 16);
847 dev_stk11xx_camera_settings(dev);
849 return 0;
853 /**
854 * @param dev Device structure
856 * @returns 0 if all is OK
858 * @brief This function sets the device to stop the stream.
860 * You use the function start_stream to enable the video stream. So you
861 * have to use the function stop_strem to disable the video stream.
863 int dev_stk6a31_stop_stream(struct usb_stk11xx *dev)
865 return 0;