2 * @file stk11xx-dev-a821.c
3 * @author Nicolas VIVIEN
7 * @brief Driver for Syntek USB video camera
9 * @note Copyright (C) Nicolas VIVIEN
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
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
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>
47 #include "stk11xx-dev.h"
50 //=============================================================================
54 //=============================================================================
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_stka821_initialize_device(struct usb_stk11xx
*dev
)
75 STK_INFO("Initialize USB2.0 Syntek Camera\n");
77 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
78 usb_stk11xx_write_registry(dev
, 0x0002, 0x0068);
79 usb_stk11xx_write_registry(dev
, 0x0003, 0x0080);
81 usb_stk11xx_write_registry(dev
, 0x0002, 0x006f);
82 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
83 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
84 usb_stk11xx_write_registry(dev
, 0x0000, 0x0026);
85 usb_stk11xx_write_registry(dev
, 0x0000, 0x0027);
86 usb_stk11xx_write_registry(dev
, 0x0000, 0x0026);
87 usb_stk11xx_write_registry(dev
, 0x0000, 0x0026);
88 usb_stk11xx_write_registry(dev
, 0x0000, 0x0027);
89 usb_stk11xx_write_registry(dev
, 0x0000, 0x0026);
90 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
91 usb_stk11xx_write_registry(dev
, 0x0000, 0x0025);
92 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
93 usb_stk11xx_write_registry(dev
, 0x0000, 0x0026);
94 usb_stk11xx_write_registry(dev
, 0x0000, 0x0027);
95 usb_stk11xx_write_registry(dev
, 0x0000, 0x0026);
96 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
97 usb_stk11xx_write_registry(dev
, 0x0000, 0x0025);
98 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
99 usb_stk11xx_write_registry(dev
, 0x0000, 0x0026);
100 usb_stk11xx_write_registry(dev
, 0x0000, 0x0027);
101 usb_stk11xx_write_registry(dev
, 0x0000, 0x0026);
102 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
103 usb_stk11xx_write_registry(dev
, 0x0000, 0x0025);
104 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
105 usb_stk11xx_write_registry(dev
, 0x0000, 0x0026);
106 usb_stk11xx_write_registry(dev
, 0x0000, 0x0027);
107 usb_stk11xx_write_registry(dev
, 0x0000, 0x0026);
108 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
109 usb_stk11xx_write_registry(dev
, 0x0000, 0x0025);
110 usb_stk11xx_write_registry(dev
, 0x0002, 0x006d);
111 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
113 for (i
=0; i
<16; i
++) {
114 usb_stk11xx_write_registry(dev
, 0x0000, 0x0025);
115 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
116 usb_stk11xx_read_registry(dev
, 0x0000, &value
);
118 STK_DEBUG("Loop 1 : Read 0x0000 = %02X\n", value
);
121 usb_stk11xx_write_registry(dev
, 0x0000, 0x0025);
122 usb_stk11xx_write_registry(dev
, 0x0000, 0x0020);
124 usb_stk11xx_write_registry(dev
, 0x0002, 0x006f);
125 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
126 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
127 usb_stk11xx_write_registry(dev
, 0x0000, 0x0026);
128 usb_stk11xx_write_registry(dev
, 0x0000, 0x0027);
129 usb_stk11xx_write_registry(dev
, 0x0000, 0x0026);
130 usb_stk11xx_write_registry(dev
, 0x0000, 0x0026);
131 usb_stk11xx_write_registry(dev
, 0x0000, 0x0027);
132 usb_stk11xx_write_registry(dev
, 0x0000, 0x0026);
133 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
134 usb_stk11xx_write_registry(dev
, 0x0000, 0x0025);
135 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
136 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
137 usb_stk11xx_write_registry(dev
, 0x0000, 0x0025);
138 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
139 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
140 usb_stk11xx_write_registry(dev
, 0x0000, 0x0025);
141 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
142 usb_stk11xx_write_registry(dev
, 0x0000, 0x0026);
143 usb_stk11xx_write_registry(dev
, 0x0000, 0x0027);
144 usb_stk11xx_write_registry(dev
, 0x0000, 0x0026);
145 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
146 usb_stk11xx_write_registry(dev
, 0x0000, 0x0025);
147 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
148 usb_stk11xx_write_registry(dev
, 0x0000, 0x0026);
149 usb_stk11xx_write_registry(dev
, 0x0000, 0x0027);
150 usb_stk11xx_write_registry(dev
, 0x0000, 0x0026);
151 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
152 usb_stk11xx_write_registry(dev
, 0x0000, 0x0025);
153 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
154 usb_stk11xx_write_registry(dev
, 0x0000, 0x0026);
155 usb_stk11xx_write_registry(dev
, 0x0000, 0x0027);
156 usb_stk11xx_write_registry(dev
, 0x0000, 0x0026);
157 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
158 usb_stk11xx_write_registry(dev
, 0x0000, 0x0025);
159 usb_stk11xx_write_registry(dev
, 0x0002, 0x006d);
160 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
162 for (i
=0; i
<16; i
++) {
163 usb_stk11xx_write_registry(dev
, 0x0000, 0x0025);
164 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
165 usb_stk11xx_read_registry(dev
, 0x0000, &value
);
167 STK_DEBUG("Loop 2 : Read 0x0000 = %02X\n", value
);
170 usb_stk11xx_write_registry(dev
, 0x0000, 0x0025);
171 usb_stk11xx_write_registry(dev
, 0x0000, 0x0020);
173 usb_stk11xx_write_registry(dev
, 0x0002, 0x006f);
174 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
175 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
176 usb_stk11xx_write_registry(dev
, 0x0000, 0x0026);
177 usb_stk11xx_write_registry(dev
, 0x0000, 0x0027);
178 usb_stk11xx_write_registry(dev
, 0x0000, 0x0026);
179 usb_stk11xx_write_registry(dev
, 0x0000, 0x0026);
180 usb_stk11xx_write_registry(dev
, 0x0000, 0x0027);
181 usb_stk11xx_write_registry(dev
, 0x0000, 0x0026);
182 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
183 usb_stk11xx_write_registry(dev
, 0x0000, 0x0025);
184 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
185 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
186 usb_stk11xx_write_registry(dev
, 0x0000, 0x0025);
187 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
188 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
189 usb_stk11xx_write_registry(dev
, 0x0000, 0x0025);
190 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
191 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
192 usb_stk11xx_write_registry(dev
, 0x0000, 0x0025);
193 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
194 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
195 usb_stk11xx_write_registry(dev
, 0x0000, 0x0025);
196 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
197 usb_stk11xx_write_registry(dev
, 0x0000, 0x0026);
198 usb_stk11xx_write_registry(dev
, 0x0000, 0x0027);
199 usb_stk11xx_write_registry(dev
, 0x0000, 0x0026);
200 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
201 usb_stk11xx_write_registry(dev
, 0x0000, 0x0025);
202 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
203 usb_stk11xx_write_registry(dev
, 0x0000, 0x0026);
204 usb_stk11xx_write_registry(dev
, 0x0000, 0x0027);
205 usb_stk11xx_write_registry(dev
, 0x0000, 0x0026);
206 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
207 usb_stk11xx_write_registry(dev
, 0x0000, 0x0025);
208 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
209 usb_stk11xx_write_registry(dev
, 0x0000, 0x0026);
210 usb_stk11xx_write_registry(dev
, 0x0000, 0x0027);
211 usb_stk11xx_write_registry(dev
, 0x0000, 0x0026);
212 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
213 usb_stk11xx_write_registry(dev
, 0x0000, 0x0025);
214 usb_stk11xx_write_registry(dev
, 0x0002, 0x006d);
215 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
217 for (i
=0; i
<16; i
++) {
218 usb_stk11xx_write_registry(dev
, 0x0000, 0x0025);
219 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
220 usb_stk11xx_read_registry(dev
, 0x0000, &value
);
222 STK_DEBUG("Loop 3 : Read 0x0000 = %02X\n", value
);
225 usb_stk11xx_write_registry(dev
, 0x0000, 0x0025);
226 usb_stk11xx_write_registry(dev
, 0x0000, 0x0020);
227 usb_stk11xx_write_registry(dev
, 0x0002, 0x006f);
228 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
229 usb_stk11xx_write_registry(dev
, 0x0000, 0x0020);
231 usb_stk11xx_write_registry(dev
, 0x0117, 0x0000);
232 usb_stk11xx_read_registry(dev
, 0x0103, &value
);
233 usb_stk11xx_write_registry(dev
, 0x0103, 0x0001);
234 usb_stk11xx_read_registry(dev
, 0x0103, &value
);
235 usb_stk11xx_write_registry(dev
, 0x0103, 0x0000);
237 usb_stk11xx_write_registry(dev
, 0x0000, 0x00e0);
238 usb_stk11xx_write_registry(dev
, 0x0002, 0x00e8);
239 usb_stk11xx_write_registry(dev
, 0x0002, 0x0068);
240 usb_stk11xx_write_registry(dev
, 0x0000, 0x0020);
242 dev_stka821_configure_device(dev
, 0);
243 dev_stk11xx_check_device(dev
, 65);
244 usb_stk11xx_write_registry(dev
, 0x0200, 0x0008);
246 dev_stka821_configure_device(dev
, 1);
247 dev_stk11xx_check_device(dev
, 65);
248 usb_stk11xx_write_registry(dev
, 0x0200, 0x0008);
250 dev_stka821_configure_device(dev
, 2);
251 dev_stk11xx_check_device(dev
, 65);
252 usb_stk11xx_write_registry(dev
, 0x0200, 0x0008);
254 dev_stka821_configure_device(dev
, 3);
255 dev_stk11xx_check_device(dev
, 65);
256 usb_stk11xx_write_registry(dev
, 0x0200, 0x0008);
258 dev_stka821_configure_device(dev
, 4);
259 dev_stk11xx_check_device(dev
, 65);
260 usb_stk11xx_write_registry(dev
, 0x0200, 0x0008);
262 dev_stka821_configure_device(dev
, 5);
263 dev_stk11xx_check_device(dev
, 65);
264 usb_stk11xx_write_registry(dev
, 0x0200, 0x0008);
266 dev_stka821_configure_device(dev
, 6);
267 dev_stk11xx_check_device(dev
, 65);
268 usb_stk11xx_write_registry(dev
, 0x0200, 0x0008);
270 dev_stka821_configure_device(dev
, 7);
271 dev_stk11xx_check_device(dev
, 65);
272 usb_stk11xx_write_registry(dev
, 0x0200, 0x0008);
274 dev_stka821_configure_device(dev
, 8);
275 dev_stk11xx_check_device(dev
, 65);
276 usb_stk11xx_write_registry(dev
, 0x0200, 0x0008);
278 dev_stka821_configure_device(dev
, 9);
279 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
280 usb_stk11xx_write_registry(dev
, 0x0002, 0x006d);
281 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
282 usb_stk11xx_write_registry(dev
, 0x0000, 0x0025);
283 usb_stk11xx_write_registry(dev
, 0x0000, 0x0020);
285 dev_stka821_configure_device(dev
, 10);
286 usb_stk11xx_write_registry(dev
, 0x0200, 0x0080);
287 usb_stk11xx_write_registry(dev
, 0x0200, 0x0000);
288 usb_stk11xx_write_registry(dev
, 0x02ff, 0x0001);
289 usb_stk11xx_write_registry(dev
, 0x0203, 0x00a0);
291 dev_stka821_camera_asleep(dev
);
293 usb_stk11xx_set_feature(dev
, 0);
295 // Device is initialized and is ready !!!
296 STK_INFO("Syntek USB2.0 Camera is ready\n");
303 * @param dev Device structure
304 * @param step The step of configuration [0-11]
306 * @returns 0 if all is OK
308 * @brief This function permits to configure the device.
310 * The configuration of device is composed of 12 steps.
311 * This function is called by the initialization process.
313 * We don't know the meaning of these steps ! We only replay the USB log.
315 int dev_stka821_configure_device(struct usb_stk11xx
*dev
, int step
)
319 // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13
320 static const int values_001B
[] = {
321 0x0e, 0x03, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x07, 0x07, 0x07, 0x07, 0x07
323 static const int values_001C
[] = {
324 0x06, 0x02, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06
326 static const int values_0202
[] = {
327 0x1e, 0x0a, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e
329 static const int values_0110
[] = {
330 0x07, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x3e, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00
332 static const int values_0112
[] = {
333 0x07, 0x00, 0x00, 0x00, 0x00, 0x09, 0x09, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00
335 static const int values_0114
[] = {
336 0x87, 0x80, 0x80, 0x80, 0x80, 0xbe, 0xbe, 0x80, 0x84, 0x80, 0x80, 0x80, 0x80, 0x80
338 static const int values_0116
[] = {
339 0xe7, 0xe0, 0xe0, 0xe0, 0xe0, 0xe9, 0xe9, 0xe0, 0xe4, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0
341 static const int values_0100
[] = {
342 0x20, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x23, 0x20, 0x20, 0x20, 0x20, 0x20
345 STK_DEBUG("dev_stka821_configure_device : %d\n", step
);
347 usb_stk11xx_write_registry(dev
, 0x0000, 0x0024);
348 usb_stk11xx_write_registry(dev
, 0x0002, 0x0068);
349 usb_stk11xx_write_registry(dev
, 0x0003, 0x0080);
350 usb_stk11xx_write_registry(dev
, 0x0005, 0x0000);
352 usb_stk11xx_write_registry(dev
, 0x0007, 0x0003);
353 usb_stk11xx_write_registry(dev
, 0x000d, 0x0000);
354 usb_stk11xx_write_registry(dev
, 0x000f, 0x0002);
355 usb_stk11xx_write_registry(dev
, 0x0300, 0x0012);
356 usb_stk11xx_write_registry(dev
, 0x0350, 0x0041);
358 usb_stk11xx_write_registry(dev
, 0x0351, 0x0000);
359 usb_stk11xx_write_registry(dev
, 0x0352, 0x0000);
360 usb_stk11xx_write_registry(dev
, 0x0353, 0x0000);
361 usb_stk11xx_write_registry(dev
, 0x0018, 0x0010);
362 usb_stk11xx_write_registry(dev
, 0x0019, 0x0000);
364 usb_stk11xx_write_registry(dev
, 0x001b, values_001B
[step
]);
365 usb_stk11xx_write_registry(dev
, 0x001c, values_001C
[step
]);
366 usb_stk11xx_write_registry(dev
, 0x0300, 0x0080);
367 usb_stk11xx_write_registry(dev
, 0x001a, 0x0004);
368 usb_stk11xx_write_registry(dev
, 0x0202, values_0202
[step
]);
370 usb_stk11xx_write_registry(dev
, 0x0110, values_0110
[step
]);
371 usb_stk11xx_write_registry(dev
, 0x0111, 0x0000);
372 usb_stk11xx_write_registry(dev
, 0x0112, values_0112
[step
]);
373 usb_stk11xx_write_registry(dev
, 0x0113, 0x0000);
374 usb_stk11xx_write_registry(dev
, 0x0114, values_0114
[step
]);
376 usb_stk11xx_write_registry(dev
, 0x0115, 0x0002);
377 usb_stk11xx_write_registry(dev
, 0x0116, values_0116
[step
]);
378 usb_stk11xx_write_registry(dev
, 0x0117, 0x0001);
380 usb_stk11xx_read_registry(dev
, 0x0100, &value
);
381 usb_stk11xx_write_registry(dev
, 0x0100, values_0100
[step
]);
383 usb_stk11xx_write_registry(dev
, 0x0200, 0x0080);
384 usb_stk11xx_write_registry(dev
, 0x0200, 0x0000);
385 usb_stk11xx_write_registry(dev
, 0x02ff, 0x0000);
390 usb_stk11xx_write_registry(dev
, 0x0203, 0x0040);
392 usb_stk11xx_write_registry(dev
, 0x0204, 0x0041);
393 usb_stk11xx_write_registry(dev
, 0x0205, 0x0001);
394 usb_stk11xx_write_registry(dev
, 0x0204, 0x001c);
395 usb_stk11xx_write_registry(dev
, 0x0205, 0x0002);
397 usb_stk11xx_write_registry(dev
, 0x0200, 0x0005);
402 usb_stk11xx_write_registry(dev
, 0x0203, 0x0022);
404 usb_stk11xx_write_registry(dev
, 0x0204, 0x0027);
405 usb_stk11xx_write_registry(dev
, 0x0205, 0x00a5);
407 usb_stk11xx_write_registry(dev
, 0x0200, 0x0005);
412 usb_stk11xx_write_registry(dev
, 0x0203, 0x0060);
414 usb_stk11xx_write_registry(dev
, 0x0204, 0x0012);
415 usb_stk11xx_write_registry(dev
, 0x0205, 0x0080);
416 usb_stk11xx_write_registry(dev
, 0x0204, 0x0013);
417 usb_stk11xx_write_registry(dev
, 0x0205, 0x00bf);
419 usb_stk11xx_write_registry(dev
, 0x0200, 0x0005);
424 usb_stk11xx_write_registry(dev
, 0x0203, 0x0042);
426 usb_stk11xx_write_registry(dev
, 0x0204, 0x0012);
427 usb_stk11xx_write_registry(dev
, 0x0205, 0x0080);
428 usb_stk11xx_write_registry(dev
, 0x0204, 0x0024);
429 usb_stk11xx_write_registry(dev
, 0x0205, 0x00a5);
431 usb_stk11xx_write_registry(dev
, 0x0200, 0x0005);
436 usb_stk11xx_write_registry(dev
, 0x0203, 0x0042);
438 usb_stk11xx_write_registry(dev
, 0x0204, 0x0012);
439 usb_stk11xx_write_registry(dev
, 0x0205, 0x0080);
440 usb_stk11xx_write_registry(dev
, 0x0204, 0x0013);
441 usb_stk11xx_write_registry(dev
, 0x0205, 0x00e0);
442 usb_stk11xx_write_registry(dev
, 0x0204, 0x0024);
443 usb_stk11xx_write_registry(dev
, 0x0205, 0x00a5);
445 usb_stk11xx_write_registry(dev
, 0x0200, 0x0005);
450 usb_stk11xx_write_registry(dev
, 0x0203, 0x0060);
452 usb_stk11xx_write_registry(dev
, 0x0204, 0x0012);
453 usb_stk11xx_write_registry(dev
, 0x0205, 0x0080);
454 usb_stk11xx_write_registry(dev
, 0x0204, 0x0013);
455 usb_stk11xx_write_registry(dev
, 0x0205, 0x00ff);
457 usb_stk11xx_write_registry(dev
, 0x0200, 0x0005);
462 usb_stk11xx_write_registry(dev
, 0x0203, 0x0060);
464 usb_stk11xx_write_registry(dev
, 0x0204, 0x0012);
465 usb_stk11xx_write_registry(dev
, 0x0205, 0x0080);
466 usb_stk11xx_write_registry(dev
, 0x0204, 0x0013);
467 usb_stk11xx_write_registry(dev
, 0x0205, 0x00ff);
469 usb_stk11xx_write_registry(dev
, 0x0200, 0x0005);
474 usb_stk11xx_write_registry(dev
, 0x0203, 0x0060);
476 usb_stk11xx_write_registry(dev
, 0x0204, 0x0012);
477 usb_stk11xx_write_registry(dev
, 0x0205, 0x0080);
478 usb_stk11xx_write_registry(dev
, 0x0204, 0x0013);
479 usb_stk11xx_write_registry(dev
, 0x0205, 0x00b7);
481 usb_stk11xx_write_registry(dev
, 0x0200, 0x0005);
486 usb_stk11xx_write_registry(dev
, 0x0203, 0x0080);
488 usb_stk11xx_write_registry(dev
, 0x0204, 0x0012);
489 usb_stk11xx_write_registry(dev
, 0x0205, 0x0080);
490 usb_stk11xx_write_registry(dev
, 0x0204, 0x000a);
491 usb_stk11xx_write_registry(dev
, 0x0205, 0x00ff);
493 usb_stk11xx_write_registry(dev
, 0x0200, 0x0005);
498 usb_stk11xx_write_registry(dev
, 0x0203, 0x00dc);
500 usb_stk11xx_write_registry(dev
, 0x0204, 0x0015);
501 usb_stk11xx_write_registry(dev
, 0x0205, 0x0080);
503 usb_stk11xx_write_registry(dev
, 0x0200, 0x0005);
505 dev_stk11xx_check_device(dev
, 500);
506 usb_stk11xx_read_registry(dev
, 0x02ff, &value
);
507 usb_stk11xx_write_registry(dev
, 0x02ff, 0x0000);
508 usb_stk11xx_write_registry(dev
, 0x0208, 0x0000);
509 usb_stk11xx_write_registry(dev
, 0x0200, 0x0020);
510 dev_stk11xx_check_device(dev
, 500);
511 usb_stk11xx_read_registry(dev
, 0x0209, &value
);
512 usb_stk11xx_write_registry(dev
, 0x02ff, 0x0000);
513 usb_stk11xx_read_registry(dev
, 0x02ff, &value
);
514 usb_stk11xx_write_registry(dev
, 0x02ff, 0x0000);
515 usb_stk11xx_write_registry(dev
, 0x0208, 0x0001);
516 usb_stk11xx_write_registry(dev
, 0x0200, 0x0020);
517 dev_stk11xx_check_device(dev
, 500);
518 usb_stk11xx_read_registry(dev
, 0x0209, &value
);
519 usb_stk11xx_write_registry(dev
, 0x02ff, 0x0000);
520 usb_stk11xx_read_registry(dev
, 0x02ff, &value
);
521 usb_stk11xx_write_registry(dev
, 0x02ff, 0x0000);
522 usb_stk11xx_write_registry(dev
, 0x0208, 0x0002);
523 usb_stk11xx_write_registry(dev
, 0x0200, 0x0020);
524 dev_stk11xx_check_device(dev
, 500);
525 usb_stk11xx_read_registry(dev
, 0x0209, &value
);
526 usb_stk11xx_write_registry(dev
, 0x02ff, 0x0000);
527 usb_stk11xx_write_registry(dev
, 0x0002, 0x006f);
532 usb_stk11xx_write_registry(dev
, 0x0203, 0x00dc);
534 dev_stka821_sensor_settings(dev
);
539 usb_stk11xx_write_registry(dev
, 0x0203, 0x00dc);
541 dev_stka821_sensor_settings(dev
);
543 usb_stk11xx_write_registry(dev
, 0x0104, 0x0000);
544 usb_stk11xx_write_registry(dev
, 0x0105, 0x0000);
545 usb_stk11xx_write_registry(dev
, 0x0106, 0x0000);
550 usb_stk11xx_write_registry(dev
, 0x0203, 0x00dc);
552 dev_stka821_sensor_settings(dev
);
554 usb_stk11xx_write_registry(dev
, 0x0104, 0x0000);
555 usb_stk11xx_write_registry(dev
, 0x0105, 0x0000);
556 usb_stk11xx_write_registry(dev
, 0x0106, 0x0000);
561 usb_stk11xx_write_registry(dev
, 0x0203, 0x00dc);
563 dev_stka821_sensor_settings(dev
);
565 usb_stk11xx_write_registry(dev
, 0x0106, 0x0000);
573 * @param dev Device structure
575 * @returns 0 if all is OK
577 * @brief Wake-up the camera.
579 * This function permits to wake-up the device.
581 int dev_stka821_camera_asleep(struct usb_stk11xx
*dev
)
585 usb_stk11xx_read_registry(dev
, 0x0104, &value
);
586 usb_stk11xx_read_registry(dev
, 0x0105, &value
);
587 usb_stk11xx_read_registry(dev
, 0x0106, &value
);
589 usb_stk11xx_write_registry(dev
, 0x0100, 0x0021);
590 usb_stk11xx_write_registry(dev
, 0x0116, 0x0000);
591 usb_stk11xx_write_registry(dev
, 0x0117, 0x0000);
592 usb_stk11xx_write_registry(dev
, 0x0018, 0x0000);
594 usb_stk11xx_read_registry(dev
, 0x0000, &value
);
595 usb_stk11xx_write_registry(dev
, 0x0000, 0x0049);
602 * @param dev Device structure
604 * @returns 0 if all is OK
606 * @brief This function initializes the device for the stream.
608 * It's the start. This function has to be called at first, before
609 * enabling the video stream.
611 int dev_stka821_init_camera(struct usb_stk11xx
*dev
)
616 dev_stka821_camera_asleep(dev
);
618 usb_stk11xx_set_feature(dev
, 0);
620 usb_stk11xx_write_registry(dev
, 0x0000, 0x00e0);
621 usb_stk11xx_write_registry(dev
, 0x0002, 0x00e8);
622 usb_stk11xx_write_registry(dev
, 0x0002, 0x0068);
623 usb_stk11xx_write_registry(dev
, 0x0000, 0x0020);
625 dev_stka821_configure_device(dev
, 11);
627 dev_stk11xx_camera_off(dev
);
629 dev_stka821_camera_settings(dev
);
631 dev_stka821_camera_asleep(dev
);
633 usb_stk11xx_set_feature(dev
, 0);
635 usb_stk11xx_write_registry(dev
, 0x0000, 0x00e0);
636 usb_stk11xx_write_registry(dev
, 0x0002, 0x00e8);
637 usb_stk11xx_write_registry(dev
, 0x0002, 0x0068);
638 usb_stk11xx_write_registry(dev
, 0x0000, 0x0020);
640 dev_stka821_configure_device(dev
, 12);
642 dev_stk11xx_camera_off(dev
);
644 dev_stka821_camera_settings(dev
);
651 * @param dev Device structure
653 * @returns 0 if all is OK
655 * @brief This function permits to set default sensor settings.
657 * We set some registers in using a I2C bus.
658 * WARNING, the sensor settings can be different following the situation.
660 int dev_stka821_sensor_settings(struct usb_stk11xx
*dev
)
667 static const int values_204
[] = {
668 0x17, 0x19, 0xb4, 0xa6, 0x12, 0x13, 0x1e, 0x21, 0x24, 0x32,
669 0x36, 0x39, 0x4d, 0x53, 0x5d, 0x5f, 0x60, 0x61, 0x62, 0x63,
670 0x64, 0x65, 0x66, 0x82, 0x83, 0x85, 0x86, 0x89, 0x97, 0x98,
671 0xad, 0xae, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbf, 0x48, 0xd8,
672 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
673 0x80, 0x81, 0xd8, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c,
674 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0xd8, 0x76, 0x77, 0x78, 0x79,
675 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x5c, 0xc0,
676 0x59, 0x5a, 0x5b, 0xd4, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93,
677 0x94, 0x95, 0x96, 0xb3, 0x73, 0x06, 0x07, 0x0b, 0x15, 0x20,
678 0x4e, 0x4f, 0x49, 0x4a, 0x4b, 0x4c, 0x46, 0x06, 0x07, 0xb9,
679 0xba, 0xbb, 0xbc, 0x61, 0x62, 0x65, 0x66
681 static const int values_205
[] = {
682 0x41, 0x41, 0x03, 0x06, 0x06, 0x08, 0x06, 0x00, 0x02, 0x69,
683 0x35, 0x60, 0xfe, 0x1c, 0x04, 0x08, 0x08, 0x08, 0x08, 0x00,
684 0x00, 0x10, 0x14, 0x01, 0x80, 0x0c, 0xb6, 0x00, 0x25, 0x25,
685 0x3f, 0x24, 0x10, 0x07, 0xcc, 0x1f, 0x30, 0x02, 0x9c, 0x80,
686 0x00, 0x0d, 0x18, 0x22, 0x2c, 0x3e, 0x4f, 0x6f, 0x8e, 0xac,
687 0xc8, 0xe5, 0xa0, 0x00, 0x0d, 0x18, 0x22, 0x2c, 0x3e, 0x4f,
688 0x6f, 0x8e, 0xac, 0xc8, 0xe5, 0xc0, 0x00, 0x0d, 0x18, 0x22,
689 0x2c, 0x3e, 0x4f, 0x6f, 0x8e, 0xac, 0xc8, 0xe5, 0x70, 0x18,
690 0x09, 0x07, 0x07, 0x3c, 0x3d, 0x95, 0x88, 0x89, 0x47, 0x9c,
691 0x81, 0x9c, 0x3d, 0x76, 0x76, 0x01, 0xf3, 0x05, 0x00, 0x44,
692 0x06, 0x0a, 0x96, 0x00, 0x7d, 0x00, 0x20, 0x01, 0xf3, 0x04,
693 0xe4, 0x09, 0xc8, 0x08, 0x08, 0x10, 0x14
697 asize
= ARRAY_SIZE(values_204
);
699 for(i
=0; i
<asize
; i
++) {
700 usb_stk11xx_read_registry(dev
, 0x02ff, &value
);
701 usb_stk11xx_write_registry(dev
, 0x02ff, 0x0000);
703 usb_stk11xx_write_registry(dev
, 0x0204, values_204
[i
]);
704 usb_stk11xx_write_registry(dev
, 0x0205, values_205
[i
]);
705 usb_stk11xx_write_registry(dev
, 0x0200, 0x0001);
707 retok
= dev_stk11xx_check_device(dev
, 500);
710 STK_ERROR("Load default sensor settings fail !\n");
714 usb_stk11xx_write_registry(dev
, 0x02ff, 0x0000);
717 retok
= dev_stk11xx_check_device(dev
, 500);
724 * @param dev Device structure
726 * @returns 0 if all is OK
728 * @brief This function permits to modify the settings of the camera.
730 * This functions permits to modify the settings :
736 int dev_stka821_camera_settings(struct usb_stk11xx
*dev
)
742 static const int values_204
[] = {
743 0xb3, 0x73, 0x46, 0x06, 0x07, 0xb9, 0xba, 0xbb, 0xbc, 0x61, 0x62, 0x65, 0x66
745 static const int values_205
[] = {
746 0x76, 0x76, 0x20, 0x01, 0xf3, 0x04, 0xe4, 0x09, 0xc8, 0x08, 0x08, 0x10, 0x14
751 usb_stk11xx_read_registry(dev
, 0x02ff, &value
);
752 usb_stk11xx_write_registry(dev
, 0x02ff, 0x0000);
754 usb_stk11xx_write_registry(dev
, 0x0204, 0x00b3);
755 usb_stk11xx_write_registry(dev
, 0x0205, (dev
->vsettings
.contrast
>> 8));
757 usb_stk11xx_write_registry(dev
, 0x0200, 0x0001);
758 dev_stk11xx_check_device(dev
, 500);
759 usb_stk11xx_write_registry(dev
, 0x02ff, 0x0000);
761 asize
= ARRAY_SIZE(values_204
);
763 for (i
=1; i
<asize
; i
++) {
764 usb_stk11xx_read_registry(dev
, 0x02ff, &value
);
765 usb_stk11xx_write_registry(dev
, 0x02ff, 0x0000);
767 usb_stk11xx_write_registry(dev
, 0x0204, values_204
[i
]);
768 usb_stk11xx_write_registry(dev
, 0x0205, values_205
[i
]);
770 usb_stk11xx_write_registry(dev
, 0x0200, 0x0001);
771 dev_stk11xx_check_device(dev
, 500);
772 usb_stk11xx_write_registry(dev
, 0x02ff, 0x0000);
780 * @param dev Device structure
782 * @returns 0 if all is OK
784 * @brief This function permits to modify the settings of the camera.
786 * This functions permits to modify the settings :
792 int dev_stka821_set_camera_quality(struct usb_stk11xx
*dev
)
797 usb_stk11xx_read_registry(dev
, 0x02ff, &value
);
798 usb_stk11xx_write_registry(dev
, 0x02ff, 0x0000);
800 usb_stk11xx_write_registry(dev
, 0x0204, 0x00b3);
801 usb_stk11xx_write_registry(dev
, 0x0205, (dev
->vsettings
.contrast
>> 8));
803 usb_stk11xx_write_registry(dev
, 0x0200, 0x0001);
804 dev_stk11xx_check_device(dev
, 500);
805 usb_stk11xx_write_registry(dev
, 0x02ff, 0x0000);
807 STK_DEBUG("Set colour : %d\n", dev
->vsettings
.colour
);
808 STK_DEBUG("Set contrast : %d\n", dev
->vsettings
.contrast
);
809 STK_DEBUG("Set whiteness : %d\n", dev
->vsettings
.whiteness
);
810 STK_DEBUG("Set brightness : %d\n", dev
->vsettings
.brightness
);
817 * @param dev Device structure
819 * @returns 0 if all is OK
821 * @brief This function permits to modify the settings of the camera.
823 * This functions permits to modify the frame rate per second.
825 int dev_stka821_set_camera_fps(struct usb_stk11xx
*dev
)
832 * @param dev Device structure
834 * @returns 0 if all is OK
836 * @brief This function sets the device to start the stream.
838 * After the initialization of the device and the initialization of the video stream,
839 * this function permits to enable the stream.
841 int dev_stka821_start_stream(struct usb_stk11xx
*dev
)
844 int value_116
, value_117
;
846 usb_stk11xx_read_registry(dev
, 0x0116, &value_116
);
847 usb_stk11xx_read_registry(dev
, 0x0117, &value_117
);
849 usb_stk11xx_write_registry(dev
, 0x0116, 0x0000);
850 usb_stk11xx_write_registry(dev
, 0x0117, 0x0000);
852 usb_stk11xx_read_registry(dev
, 0x0100, &value
); // read 0x21
853 usb_stk11xx_write_registry(dev
, 0x0100, 0x00a0);
855 usb_stk11xx_write_registry(dev
, 0x0116, value_116
);
856 usb_stk11xx_write_registry(dev
, 0x0117, value_117
);
863 * @param dev Device structure
865 * @returns 0 if all is OK
867 * @brief Reconfigure the camera before the stream.
869 * Before enabling the video stream, you have to reconfigure the device.
871 int dev_stka821_reconf_camera(struct usb_stk11xx
*dev
)
873 dev_stka821_configure_device(dev
, 13);
875 dev_stk11xx_camera_settings(dev
);
882 * @param dev Device structure
884 * @returns 0 if all is OK
886 * @brief This function sets the device to stop the stream.
888 * You use the function start_stream to enable the video stream. So you
889 * have to use the function stop_strem to disable the video stream.
891 int dev_stka821_stop_stream(struct usb_stk11xx
*dev
)
895 usb_stk11xx_read_registry(dev
, 0x0100, &value
);
896 usb_stk11xx_write_registry(dev
, 0x0100, 0x0020);