Release 1.2.1
[syntekdriver.git] / stk11xx-dev.c
blob35895705320bb7f908cf9b3bb7882a309955b56f
1 /**
2 * @file stk11xx-dev.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 /**
50 * @param dev Device structure
52 * @returns 0 if all is OK
54 * @brief This function permits to initialize the device.
56 * This function must be called at first. It's the start of the
57 * initialization process. After this process, the device is
58 * completly initalized and it's ready.
60 * This function is written from the USB log.
62 int dev_stk11xx_initialize_device(struct usb_stk11xx *dev)
64 int ret;
66 switch (dev->webcam_model) {
67 case SYNTEK_STK_M811:
68 case SYNTEK_STK_A311:
69 ret = dev_stka311_initialize_device(dev);
70 break;
72 case SYNTEK_STK_A821:
73 ret = dev_stka821_initialize_device(dev);
74 break;
76 case SYNTEK_STK_6A31:
77 ret = dev_stk6a31_initialize_device(dev);
78 break;
80 case SYNTEK_STK_6A33:
81 ret = dev_stk6a33_initialize_device(dev);
82 break;
84 case SYNTEK_STK_6A54:
85 ret = dev_stk6a54_initialize_device(dev);
86 break;
88 default:
89 ret = -1;
92 return ret;
96 /**
97 * @param dev Device structure
99 * @returns 0 if all is OK
101 * @brief This function initializes the device for the stream.
103 * It's the start. This function has to be called at first, before
104 * enabling the video stream.
106 int dev_stk11xx_init_camera(struct usb_stk11xx *dev)
108 int ret;
110 switch (dev->webcam_model) {
111 case SYNTEK_STK_M811:
112 case SYNTEK_STK_A311:
113 ret = dev_stka311_init_camera(dev);
114 break;
116 case SYNTEK_STK_A821:
117 ret = dev_stka821_init_camera(dev);
118 break;
120 case SYNTEK_STK_6A31:
121 ret = dev_stk6a31_init_camera(dev);
122 break;
124 case SYNTEK_STK_6A33:
125 ret = dev_stk6a33_init_camera(dev);
126 break;
128 case SYNTEK_STK_6A54:
129 ret = dev_stk6a54_init_camera(dev);
130 break;
132 default:
133 ret = -1;
136 return ret;
140 /**
141 * @param dev Device structure
142 * @param nbr Number of tries
144 * @returns 0 if all is OK
146 * @brief This function permits to check the device in reading the register 0x0201.
148 * When we configure the stk11xx, this function is used to check the device status.
149 * - If the read value is 0x00, then the device isn't ready.
150 * - If the read value is 0x04, then the device is ready.
151 * - If the read value is other, then the device is misconfigured.
153 int dev_stk11xx_check_device(struct usb_stk11xx *dev, int nbr)
155 int i;
156 int value;
158 for (i=0; i<nbr; i++) {
159 usb_stk11xx_read_registry(dev, 0x201, &value);
161 if (value == 0x00) {
163 else if (value == 0x01) {
164 return 1;
166 else if (value == 0x04)
167 return 1;
168 else {
169 STK_ERROR("Check device return error (0x0201 = %02X) !\n", value);
170 return -1;
174 return 0;
178 /**
179 * @param dev Device structure
181 * @returns Value of register 0x0001
183 * @brief A espece of software watchdog.
185 * This function reads periodically the value of register 0x0001.
187 * We don't know the purpose. I assume that it seems to a software watchdog.
189 int dev_stk11xx_watchdog_camera(struct usb_stk11xx *dev)
191 int value;
193 usb_stk11xx_read_registry(dev, 0x0001, &value);
195 if (value != 0x03) {
196 STK_ERROR("Error : Register 0x0001 = %02X\n", value);
199 return value;
203 /**
204 * @param dev Device structure
206 * @returns 0 if all is OK
208 * @brief This function switchs on the camera.
210 * In fact, we choose the alternate interface '5'.
212 int dev_stk11xx_camera_on(struct usb_stk11xx *dev)
214 int ret = -1;
215 struct usb_device *udev = dev->udev;
217 ret = usb_set_interface(udev, 0, 5);
219 if (ret < 0)
220 STK_ERROR("usb_set_interface failed !\n");
222 return ret;
226 /**
227 * @param dev Device structure
229 * @returns 0 if all is OK
231 * @brief This function switchs off the camera.
233 * In fact, we choose the alternate interface '0'.
235 int dev_stk11xx_camera_off(struct usb_stk11xx *dev)
237 int ret = -1;
238 struct usb_device *udev = dev->udev;
240 ret = usb_set_interface(udev, 0, 0);
242 if (ret < 0)
243 STK_ERROR("usb_set_interface failed !\n");
245 return 0;
249 /**
250 * @param dev Device structure
252 * @returns 0 if all is OK
254 * @brief Wake-up the camera.
256 * This function permits to wake-up the device.
258 int dev_stk11xx_camera_asleep(struct usb_stk11xx *dev)
260 int ret;
262 switch (dev->webcam_model) {
263 case SYNTEK_STK_M811:
264 case SYNTEK_STK_A311:
265 ret = dev_stka311_camera_asleep(dev);
266 break;
268 case SYNTEK_STK_A821:
269 ret = dev_stka821_camera_asleep(dev);
270 break;
272 case SYNTEK_STK_6A31:
273 ret = dev_stk6a31_camera_asleep(dev);
274 break;
276 case SYNTEK_STK_6A33:
277 ret = dev_stk6a33_camera_asleep(dev);
278 break;
280 case SYNTEK_STK_6A54:
281 ret = dev_stk6a54_camera_asleep(dev);
282 break;
284 default:
285 ret = -1;
288 return ret;
292 /**
293 * @param dev Device structure
295 * @returns 0 if all is OK
297 * @brief This function permits to modify the settings of the camera.
299 * This functions permits to modify the settings :
300 * - brightness
301 * - contrast
302 * - white balance
303 * - ...
305 int dev_stk11xx_camera_settings(struct usb_stk11xx *dev)
307 int ret;
309 switch (dev->webcam_model) {
310 case SYNTEK_STK_M811:
311 case SYNTEK_STK_A311:
312 ret = dev_stka311_camera_settings(dev);
313 break;
315 case SYNTEK_STK_A821:
316 ret = dev_stka821_camera_settings(dev);
317 break;
319 case SYNTEK_STK_6A31:
320 ret = dev_stk6a31_camera_settings(dev);
321 break;
323 case SYNTEK_STK_6A33:
324 ret = dev_stk6a33_camera_settings(dev);
325 break;
327 case SYNTEK_STK_6A54:
328 ret = dev_stk6a54_camera_settings(dev);
329 break;
331 default:
332 ret = -1;
335 return ret;
339 /**
340 * @param dev Device structure
342 * @returns 0 if all is OK
344 * @brief This function permits to modify the quality video of the camera.
346 * This functions permits to modify the settings :
347 * - brightness
348 * - contrast
349 * - white balance
350 * - ...
352 int dev_stk11xx_set_camera_quality(struct usb_stk11xx *dev)
354 int ret;
356 switch (dev->webcam_model) {
357 case SYNTEK_STK_M811:
358 case SYNTEK_STK_A311:
359 ret = dev_stka311_set_camera_quality(dev);
360 break;
362 case SYNTEK_STK_A821:
363 ret = dev_stka821_set_camera_quality(dev);
364 break;
366 case SYNTEK_STK_6A31:
367 ret = dev_stk6a31_set_camera_quality(dev);
368 break;
370 case SYNTEK_STK_6A33:
371 ret = dev_stk6a33_set_camera_quality(dev);
372 break;
374 case SYNTEK_STK_6A54:
375 ret = dev_stk6a54_set_camera_quality(dev);
376 break;
378 default:
379 ret = -1;
382 return ret;
386 /**
387 * @param dev Device structure
389 * @returns 0 if all is OK
391 * @brief This function permits to modify the fps of the camera.
393 * This functions permits to modify the frame rate per second of the camera.
394 * So the number of images per second.
396 int dev_stk11xx_set_camera_fps(struct usb_stk11xx *dev)
398 int ret;
400 switch (dev->webcam_model) {
401 case SYNTEK_STK_M811:
402 case SYNTEK_STK_A311:
403 ret = dev_stka311_set_camera_fps(dev);
404 break;
406 case SYNTEK_STK_A821:
407 ret = dev_stka821_set_camera_fps(dev);
408 break;
410 case SYNTEK_STK_6A31:
411 ret = dev_stk6a31_set_camera_fps(dev);
412 break;
414 case SYNTEK_STK_6A33:
415 ret = dev_stk6a33_set_camera_fps(dev);
416 break;
418 case SYNTEK_STK_6A54:
419 ret = dev_stk6a54_set_camera_fps(dev);
420 break;
422 default:
423 ret = -1;
426 return ret;
430 /**
431 * @param dev Device structure
433 * @returns 0 if all is OK
435 * @brief This function sets the device to start the stream.
437 * After the initialization of the device and the initialization of the video stream,
438 * this function permits to enable the stream.
440 int dev_stk11xx_start_stream(struct usb_stk11xx *dev)
442 int ret;
444 switch (dev->webcam_model) {
445 case SYNTEK_STK_M811:
446 case SYNTEK_STK_A311:
447 ret = dev_stka311_start_stream(dev);
448 break;
450 case SYNTEK_STK_A821:
451 ret = dev_stka821_start_stream(dev);
452 break;
454 case SYNTEK_STK_6A31:
455 ret = dev_stk6a31_start_stream(dev);
456 break;
458 case SYNTEK_STK_6A33:
459 ret = dev_stk6a33_start_stream(dev);
460 break;
462 case SYNTEK_STK_6A54:
463 ret = dev_stk6a54_start_stream(dev);
464 break;
466 default:
467 ret = -1;
470 return ret;
474 /**
475 * @param dev Device structure
477 * @returns 0 if all is OK
479 * @brief Reconfigure the camera before the stream.
481 * Before enabling the video stream, you have to reconfigure the device.
483 int dev_stk11xx_reconf_camera(struct usb_stk11xx *dev)
485 int ret;
487 switch (dev->webcam_model) {
488 case SYNTEK_STK_M811:
489 case SYNTEK_STK_A311:
490 ret = dev_stka311_reconf_camera(dev);
491 break;
493 case SYNTEK_STK_A821:
494 ret = dev_stka821_reconf_camera(dev);
495 break;
497 case SYNTEK_STK_6A31:
498 ret = dev_stk6a31_reconf_camera(dev);
499 break;
501 case SYNTEK_STK_6A33:
502 ret = dev_stk6a33_reconf_camera(dev);
503 break;
505 case SYNTEK_STK_6A54:
506 ret = dev_stk6a54_reconf_camera(dev);
507 break;
509 default:
510 ret = -1;
513 return ret;
517 /**
518 * @param dev Device structure
520 * @returns 0 if all is OK
522 * @brief This function sets the device to stop the stream.
524 * You use the function start_stream to enable the video stream. So you
525 * have to use the function stop_strem to disable the video stream.
527 int dev_stk11xx_stop_stream(struct usb_stk11xx *dev)
529 int ret;
531 switch (dev->webcam_model) {
532 case SYNTEK_STK_M811:
533 case SYNTEK_STK_A311:
534 ret = dev_stka311_stop_stream(dev);
535 break;
537 case SYNTEK_STK_A821:
538 ret = dev_stka821_stop_stream(dev);
539 break;
541 case SYNTEK_STK_6A31:
542 ret = dev_stk6a31_stop_stream(dev);
543 break;
545 case SYNTEK_STK_6A33:
546 ret = dev_stk6a33_stop_stream(dev);
547 break;
549 case SYNTEK_STK_6A54:
550 ret = dev_stk6a54_stop_stream(dev);
551 break;
553 default:
554 ret = -1;
557 return ret;