Release 1.2.1
[syntekdriver.git] / stk11xx-dev-6a54.c
blob894da0fc88b2786ba62e449536271e186cd7b06b
1 /**
2 * @file stk11xx-dev-6a54.c
3 * @author Nicolas VIVIEN
4 * @date 2006-10-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-6A54 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_stk6a54_initialize_device(struct usb_stk11xx *dev)
71 int retok;
72 int value;
74 STK_INFO("Initialize USB2.0 Syntek Camera\n");
76 usb_stk11xx_write_registry(dev, 0x0000, 0x00e0);
77 usb_stk11xx_write_registry(dev, 0x0002, 0x00f8);
78 usb_stk11xx_write_registry(dev, 0x0002, 0x0078);
79 usb_stk11xx_write_registry(dev, 0x0000, 0x0020);
81 dev_stk6a54_configure_device(dev, 0);
82 retok = dev_stk11xx_check_device(dev, 65);
83 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
84 usb_stk11xx_read_registry(dev, 0x02ff, &value);
85 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
86 usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
87 usb_stk11xx_write_registry(dev, 0x0208, 0x000a);
88 usb_stk11xx_write_registry(dev, 0x0200, 0x0020);
89 retok = dev_stk11xx_check_device(dev, 65);
90 usb_stk11xx_read_registry(dev, 0x0209, &value);
91 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
92 usb_stk11xx_read_registry(dev, 0x02ff, &value);
93 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
94 usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
95 usb_stk11xx_write_registry(dev, 0x0208, 0x000b);
96 usb_stk11xx_write_registry(dev, 0x0200, 0x0020);
97 retok = dev_stk11xx_check_device(dev, 65);
98 usb_stk11xx_read_registry(dev, 0x0209, &value);
99 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
100 usb_stk11xx_read_registry(dev, 0x02ff, &value);
101 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
102 usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
103 usb_stk11xx_write_registry(dev, 0x0208, 0x001c);
104 usb_stk11xx_write_registry(dev, 0x0200, 0x0020);
105 retok = dev_stk11xx_check_device(dev, 65);
106 usb_stk11xx_read_registry(dev, 0x0209, &value);
107 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
108 usb_stk11xx_read_registry(dev, 0x02ff, &value);
109 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
110 usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
111 usb_stk11xx_write_registry(dev, 0x0208, 0x001d);
112 usb_stk11xx_write_registry(dev, 0x0200, 0x0020);
113 retok = dev_stk11xx_check_device(dev, 65);
114 usb_stk11xx_read_registry(dev, 0x0209, &value);
115 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
116 usb_stk11xx_write_registry(dev, 0x0000, 0x00e0);
117 usb_stk11xx_write_registry(dev, 0x0002, 0x00f8);
118 usb_stk11xx_write_registry(dev, 0x0002, 0x0078);
119 usb_stk11xx_write_registry(dev, 0x0000, 0x0020);
120 usb_stk11xx_write_registry(dev, 0x0100, 0x0021);
121 usb_stk11xx_read_registry(dev, 0x0000, &value);
122 usb_stk11xx_write_registry(dev, 0x0000, 0x004b);
125 dev_stk6a54_configure_device(dev, 1);
127 usb_stk11xx_set_feature(dev, 0);
129 // Device is initialized and is ready !!!
130 STK_INFO("Syntek USB2.0 Camera is ready\n");
132 return 0;
136 /**
137 * @param dev Device structure
138 * @param step The step of configuration [0-11]
140 * @returns 0 if all is OK
142 * @brief This function permits to configure the device.
144 * The configuration of device is composed of 12 steps.
145 * This function is called by the initialization process.
147 * We don't know the meaning of these steps ! We only replay the USB log.
149 int dev_stk6a54_configure_device(struct usb_stk11xx *dev, int step)
151 int value;
153 // 0, 1
154 static const int values_001B[] = {
155 0x0e, 0x0e
157 static const int values_001C[] = {
158 0x46, 0x46
160 static const int values_0202[] = {
161 0x1e, 0x1e
163 static const int values_0110[] = {
164 0x00, 0x00
166 static const int values_0112[] = {
167 0x00, 0x00
169 static const int values_0114[] = {
170 0x00, 0x00
172 static const int values_0115[] = {
173 0x00, 0x05
175 static const int values_0116[] = {
176 0x00, 0xe0
178 static const int values_0117[] = {
179 0x00, 0x01
181 static const int values_0100[] = {
182 0x21, 0x21
186 STK_DEBUG("dev_stk6a54_configure_device : %d\n", step);
188 usb_stk11xx_write_registry(dev, 0x0000, 0x0024);
189 usb_stk11xx_write_registry(dev, 0x0002, 0x0078);
190 usb_stk11xx_write_registry(dev, 0x0003, 0x0080);
191 usb_stk11xx_write_registry(dev, 0x0005, 0x0000);
193 usb_stk11xx_write_registry(dev, 0x0007, 0x0003);
194 usb_stk11xx_write_registry(dev, 0x000d, 0x0000);
195 usb_stk11xx_write_registry(dev, 0x000f, 0x0002);
196 usb_stk11xx_write_registry(dev, 0x0300, 0x0012);
197 usb_stk11xx_write_registry(dev, 0x0350, 0x0041);
199 usb_stk11xx_write_registry(dev, 0x0351, 0x0000);
200 usb_stk11xx_write_registry(dev, 0x0352, 0x0000);
201 usb_stk11xx_write_registry(dev, 0x0353, 0x0000);
202 usb_stk11xx_write_registry(dev, 0x0018, 0x0010);
203 usb_stk11xx_write_registry(dev, 0x0019, 0x0000);
205 usb_stk11xx_write_registry(dev, 0x001b, values_001B[step]);
206 usb_stk11xx_write_registry(dev, 0x001c, values_001C[step]);
207 usb_stk11xx_write_registry(dev, 0x0300, 0x0080);
208 usb_stk11xx_write_registry(dev, 0x001a, 0x0004);
209 usb_stk11xx_write_registry(dev, 0x0202, values_0202[step]);
211 usb_stk11xx_write_registry(dev, 0x0110, values_0110[step]);
212 usb_stk11xx_write_registry(dev, 0x0111, 0x0000);
213 usb_stk11xx_write_registry(dev, 0x0112, values_0112[step]);
214 usb_stk11xx_write_registry(dev, 0x0113, 0x0000);
215 usb_stk11xx_write_registry(dev, 0x0114, values_0114[step]);
217 usb_stk11xx_write_registry(dev, 0x0115, values_0115[step]);
218 usb_stk11xx_write_registry(dev, 0x0116, values_0116[step]);
219 usb_stk11xx_write_registry(dev, 0x0117, values_0117[step]);
221 usb_stk11xx_read_registry(dev, 0x0100, &value);
222 usb_stk11xx_write_registry(dev, 0x0100, values_0100[step]);
224 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
227 switch (step) {
228 case 0:
229 usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
231 usb_stk11xx_read_registry(dev, 0x02ff, &value);
232 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
234 usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
236 usb_stk11xx_write_registry(dev, 0x0204, 0x00ff);
237 usb_stk11xx_write_registry(dev, 0x0205, 0x0001);
239 usb_stk11xx_write_registry(dev, 0x0200, 0x0001);
241 break;
243 case 1:
244 usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
246 dev_stk6a54_sensor_settings(dev);
248 usb_stk11xx_read_registry(dev, 0x0209, &value);
249 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
251 break;
254 return 0;
258 /**
259 * @param dev Device structure
261 * @returns 0 if all is OK
263 * @brief Wake-up the camera.
265 * This function permits to wake-up the device.
267 int dev_stk6a54_camera_asleep(struct usb_stk11xx *dev)
269 int value;
271 usb_stk11xx_read_registry(dev, 0x0104, &value);
272 usb_stk11xx_read_registry(dev, 0x0105, &value);
273 usb_stk11xx_read_registry(dev, 0x0106, &value);
275 usb_stk11xx_write_registry(dev, 0x0100, 0x0021);
276 usb_stk11xx_write_registry(dev, 0x0116, 0x0000);
277 usb_stk11xx_write_registry(dev, 0x0117, 0x0000);
278 usb_stk11xx_write_registry(dev, 0x0018, 0x0000);
280 usb_stk11xx_read_registry(dev, 0x0000, &value);
281 usb_stk11xx_write_registry(dev, 0x0000, 0x0049);
283 return 0;
287 /**
288 * @param dev Device structure
290 * @returns 0 if all is OK
292 * @brief This function initializes the device for the stream.
294 * It's the start. This function has to be called at first, before
295 * enabling the video stream.
297 int dev_stk6a54_init_camera(struct usb_stk11xx *dev)
299 return 0;
303 /**
304 * @param dev Device structure
306 * @returns 0 if all is OK
308 * @brief This function permits to set default sensor settings.
310 * We set some registers in using a I2C bus.
311 * WARNING, the sensor settings can be different following the situation.
313 int dev_stk6a54_sensor_settings(struct usb_stk11xx *dev)
315 int i;
316 int retok;
317 int value;
319 int asize;
321 static const int values_204[] = {
322 0xff, 0x12, 0xff, 0x2c, 0x2e, 0xff, 0x3c, 0x11, 0x09, 0x04,
323 0x13, 0x14, 0x2c, 0x33, 0x3a, 0x3b, 0x3e, 0x43, 0x16, 0x39,
324 0x35, 0x22, 0x37, 0x23, 0x34, 0x36, 0x06, 0x07, 0x0d, 0x0e,
325 0x4c, 0x4a, 0x21, 0x24, 0x25, 0x26, 0x5c, 0x63, 0x46, 0x0c,
326 0x61, 0x62, 0x7c, 0x20, 0x28, 0x6c, 0x6d, 0x6e, 0x70, 0x71,
327 0x73, 0x3d, 0x5a, 0x4f, 0x50, 0xff, 0xe5, 0xf9, 0x41, 0xe0,
328 0x76, 0x33, 0x42, 0x43, 0x4c, 0x87, 0x88, 0xd7, 0xd9, 0xd3,
329 0xc8, 0xc9, 0x7c, 0x7d, 0x7c, 0x7d, 0x7d, 0x7c, 0x7d, 0x7d,
330 0x7d, 0x90, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91,
331 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x92, 0x93,
332 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93,
333 0x93, 0x93, 0x96, 0x97, 0x97, 0x97, 0x97, 0x97, 0x97, 0x97,
334 0x97, 0x97, 0x97, 0x97, 0x97, 0x97, 0xc3, 0xa4, 0xa8, 0xc5,
335 0xc6, 0xbf, 0xc7, 0xb6, 0xb8, 0xb7, 0xb9, 0xb3, 0xb4, 0xb5,
336 0xb0, 0xb1, 0xb2, 0xc4, 0xc0, 0xc1, 0x86, 0x50, 0x51, 0x52,
337 0x53, 0x54, 0x55, 0x57, 0x5a, 0x5b, 0x5c, 0xc3, 0x7f, 0xda,
338 0xd7, 0xe5, 0xe1, 0xe0, 0xdd, 0x05, 0xff, 0x12, 0x11, 0x17,
339 0x18, 0x19, 0x1a, 0x32, 0x37, 0x4f, 0x50, 0x5a, 0x6d, 0x3d,
340 0x39, 0x35, 0x22, 0x37, 0x23, 0x34, 0x36, 0x06, 0x07, 0x0d,
341 0x0e, 0x4c, 0xff, 0xe0, 0xc0, 0xc1, 0x8c, 0x86, 0x50, 0x51,
342 0x52, 0x53, 0x54, 0x55, 0x5a, 0x5b, 0x5c, 0xd3, 0xe0, 0xff,
343 0xe0, 0xc0, 0xc1, 0x8c, 0x86, 0x50, 0x51, 0x52, 0x53, 0x54,
344 0x55, 0x5a, 0x5b, 0x5c, 0xd3, 0xe0, 0xff, 0xff, 0x04, 0xff,
345 0xff, 0xff, 0x7c, 0x7d, 0x7c, 0x7c, 0x7d, 0x7c, 0x7d, 0x7c,
346 0xff, 0x7c, 0x7d, 0x7c, 0x7d, 0x7c, 0xff, 0x7c, 0x7d, 0x7c,
347 0x7d, 0x7c, 0x7d, 0x7c, 0x7c, 0xff, 0x7c, 0x7d, 0x7c, 0x7d,
348 0x7c, 0x7d, 0xff, 0x92, 0x93, 0xff, 0x90, 0x91, 0x91, 0x91,
349 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91,
350 0x91, 0x91, 0x91, 0xff, 0xc3, 0xc7, 0xce, 0xcc, 0xcd, 0xff,
351 0x04, 0xff, 0x04
354 static const int values_205[] = {
355 0x01, 0x80, 0x00, 0xff, 0xdf, 0x01, 0x32, 0x00, 0x02, 0x28,
356 0xe5, 0x48, 0x0c, 0x78, 0x33, 0xfb, 0x00, 0x11, 0x10, 0x02,
357 0x88, 0x0a, 0x40, 0x00, 0xa0, 0x1a, 0x02, 0xc0, 0xb7, 0x01,
358 0x00, 0x81, 0x99, 0x40, 0x38, 0x82, 0x00, 0x00, 0x3f, 0x3c,
359 0x70, 0x80, 0x05, 0x80, 0x30, 0x00, 0x80, 0x00, 0x02, 0x94,
360 0xc1, 0x34, 0x57, 0xbb, 0x9c, 0x00, 0x7f, 0xc0, 0x24, 0x14,
361 0xff, 0xa0, 0x20, 0x18, 0x00, 0xd0, 0x3f, 0x03, 0x10, 0x82,
362 0x08, 0x80, 0x00, 0x00, 0x03, 0x48, 0x48, 0x08, 0x20, 0x10,
363 0x0e, 0x00, 0x0e, 0x1a, 0x31, 0x5a, 0x69, 0x75, 0x7e, 0x88,
364 0x8f, 0x96, 0xa3, 0xaf, 0xc4, 0xd7, 0xe8, 0x20, 0x00, 0x06,
365 0xe3, 0x05, 0x05, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00,
366 0x00, 0x00, 0x00, 0x08, 0x19, 0x02, 0x0c, 0x24, 0x30, 0x28,
367 0x26, 0x02, 0x98, 0x80, 0x00, 0x00, 0xed, 0x00, 0x00, 0x11,
368 0x51, 0x80, 0x10, 0x66, 0xa5, 0x64, 0x7c, 0xaf, 0x97, 0xff,
369 0xc5, 0x94, 0x0f, 0x5c, 0xc8, 0x96, 0x3d, 0x00, 0x90, 0x18,
370 0x00, 0x00, 0x88, 0x00, 0x90, 0x18, 0x05, 0xed, 0x00, 0x00,
371 0x01, 0x1f, 0x67, 0x00, 0xff, 0x00, 0x01, 0x40, 0x00, 0x11,
372 0x43, 0x00, 0x4b, 0x09, 0xc0, 0xca, 0xa8, 0x23, 0x00, 0x38,
373 0x12, 0xda, 0x1a, 0xc3, 0x00, 0xc0, 0x1a, 0x88, 0xc0, 0x87,
374 0x41, 0x00, 0x00, 0x04, 0x64, 0x4b, 0x00, 0x1d, 0x00, 0xc8,
375 0x96, 0x00, 0x00, 0x00, 0xc8, 0x96, 0x00, 0x82, 0x00, 0x00,
376 0x04, 0x64, 0x4b, 0x00, 0x3d, 0x00, 0xc8, 0x96, 0x00, 0x00,
377 0x00, 0xa0, 0x78, 0x00, 0x82, 0x00, 0x00, 0x01, 0xfa, 0x01,
378 0x00, 0x00, 0x00, 0x04, 0x0a, 0x09, 0x16, 0x0a, 0x06, 0x09,
379 0x00, 0x00, 0x04, 0x08, 0x28, 0x08, 0x00, 0x00, 0x05, 0x01,
380 0x7f, 0x02, 0x00, 0x0a, 0x05, 0x00, 0x00, 0x07, 0x03, 0x4d,
381 0x04, 0x4d, 0x00, 0x01, 0xc5, 0x00, 0x00, 0x00, 0x23, 0x3c,
382 0x50, 0x63, 0x73, 0x83, 0x92, 0xa0, 0xad, 0xba, 0xc6, 0xd2,
383 0xde, 0xe9, 0xf5, 0x01, 0x0c, 0x00, 0x80, 0x80, 0x80, 0x01,
384 0xfa, 0x01, 0xfa
387 asize = ARRAY_SIZE(values_204);
389 for(i=0; i<asize; i++) {
390 usb_stk11xx_read_registry(dev, 0x02ff, &value);
391 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
393 usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
395 usb_stk11xx_write_registry(dev, 0x0204, values_204[i]);
396 usb_stk11xx_write_registry(dev, 0x0205, values_205[i]);
397 usb_stk11xx_write_registry(dev, 0x0200, 0x0001);
399 retok = dev_stk11xx_check_device(dev, 500);
401 if (retok != 1) {
402 STK_ERROR("Load default sensor settings fail !\n");
403 return -1;
406 usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
409 usb_stk11xx_read_registry(dev, 0x02ff, &value);
411 usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
413 usb_stk11xx_write_registry(dev, 0x0208, 0x0004);
415 usb_stk11xx_write_registry(dev, 0x0200, 0x0020);
417 retok = dev_stk11xx_check_device(dev, 500);
419 return 0;
423 /**
424 * @param dev Device structure
426 * @returns 0 if all is OK
428 * @brief This function permits to modify the settings of the camera.
430 * This functions permits to modify the settings :
431 * - brightness
432 * - contrast
433 * - white balance
434 * - ...
436 int dev_stk6a54_camera_settings(struct usb_stk11xx *dev)
438 return 0;
442 /**
443 * @param dev Device structure
445 * @returns 0 if all is OK
447 * @brief This function permits to modify the settings of the camera.
449 * This functions permits to modify the settings :
450 * - brightness
451 * - contrast
452 * - white balance
453 * - ...
455 int dev_stk6a54_set_camera_quality(struct usb_stk11xx *dev)
457 return 0;
461 /**
462 * @param dev Device structure
464 * @returns 0 if all is OK
466 * @brief This function permits to modify the settings of the camera.
468 * This functions permits to modify the frame rate per second.
470 int dev_stk6a54_set_camera_fps(struct usb_stk11xx *dev)
472 return 0;
476 /**
477 * @param dev Device structure
479 * @returns 0 if all is OK
481 * @brief This function sets the device to start the stream.
483 * After the initialization of the device and the initialization of the video stream,
484 * this function permits to enable the stream.
486 int dev_stk6a54_start_stream(struct usb_stk11xx *dev)
488 return 0;
492 /**
493 * @param dev Device structure
495 * @returns 0 if all is OK
497 * @brief Reconfigure the camera before the stream.
499 * Before enabling the video stream, you have to reconfigure the device.
501 int dev_stk6a54_reconf_camera(struct usb_stk11xx *dev)
503 dev_stk11xx_camera_settings(dev);
505 return 0;
509 /**
510 * @param dev Device structure
512 * @returns 0 if all is OK
514 * @brief This function sets the device to stop the stream.
516 * You use the function start_stream to enable the video stream. So you
517 * have to use the function stop_strem to disable the video stream.
519 int dev_stk6a54_stop_stream(struct usb_stk11xx *dev)
521 return 0;