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>
46 #include "stk11xx-dev.h"
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
)
66 switch (dev
->webcam_model
) {
69 ret
= dev_stka311_initialize_device(dev
);
73 ret
= dev_stka821_initialize_device(dev
);
77 ret
= dev_stk6a31_initialize_device(dev
);
81 ret
= dev_stk6a33_initialize_device(dev
);
85 ret
= dev_stk6a54_initialize_device(dev
);
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
)
110 switch (dev
->webcam_model
) {
111 case SYNTEK_STK_M811
:
112 case SYNTEK_STK_A311
:
113 ret
= dev_stka311_init_camera(dev
);
116 case SYNTEK_STK_A821
:
117 ret
= dev_stka821_init_camera(dev
);
120 case SYNTEK_STK_6A31
:
121 ret
= dev_stk6a31_init_camera(dev
);
124 case SYNTEK_STK_6A33
:
125 ret
= dev_stk6a33_init_camera(dev
);
128 case SYNTEK_STK_6A54
:
129 ret
= dev_stk6a54_init_camera(dev
);
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
)
158 for (i
=0; i
<nbr
; i
++) {
159 usb_stk11xx_read_registry(dev
, 0x201, &value
);
163 else if (value
== 0x01) {
166 else if (value
== 0x04)
169 STK_ERROR("Check device return error (0x0201 = %02X) !\n", value
);
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
)
193 usb_stk11xx_read_registry(dev
, 0x0001, &value
);
196 STK_ERROR("Error : Register 0x0001 = %02X\n", value
);
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
)
215 struct usb_device
*udev
= dev
->udev
;
217 ret
= usb_set_interface(udev
, 0, 5);
220 STK_ERROR("usb_set_interface failed !\n");
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
)
238 struct usb_device
*udev
= dev
->udev
;
240 ret
= usb_set_interface(udev
, 0, 0);
243 STK_ERROR("usb_set_interface failed !\n");
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
)
262 switch (dev
->webcam_model
) {
263 case SYNTEK_STK_M811
:
264 case SYNTEK_STK_A311
:
265 ret
= dev_stka311_camera_asleep(dev
);
268 case SYNTEK_STK_A821
:
269 ret
= dev_stka821_camera_asleep(dev
);
272 case SYNTEK_STK_6A31
:
273 ret
= dev_stk6a31_camera_asleep(dev
);
276 case SYNTEK_STK_6A33
:
277 ret
= dev_stk6a33_camera_asleep(dev
);
280 case SYNTEK_STK_6A54
:
281 ret
= dev_stk6a54_camera_asleep(dev
);
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 :
305 int dev_stk11xx_camera_settings(struct usb_stk11xx
*dev
)
309 switch (dev
->webcam_model
) {
310 case SYNTEK_STK_M811
:
311 case SYNTEK_STK_A311
:
312 ret
= dev_stka311_camera_settings(dev
);
315 case SYNTEK_STK_A821
:
316 ret
= dev_stka821_camera_settings(dev
);
319 case SYNTEK_STK_6A31
:
320 ret
= dev_stk6a31_camera_settings(dev
);
323 case SYNTEK_STK_6A33
:
324 ret
= dev_stk6a33_camera_settings(dev
);
327 case SYNTEK_STK_6A54
:
328 ret
= dev_stk6a54_camera_settings(dev
);
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 :
352 int dev_stk11xx_set_camera_quality(struct usb_stk11xx
*dev
)
356 switch (dev
->webcam_model
) {
357 case SYNTEK_STK_M811
:
358 case SYNTEK_STK_A311
:
359 ret
= dev_stka311_set_camera_quality(dev
);
362 case SYNTEK_STK_A821
:
363 ret
= dev_stka821_set_camera_quality(dev
);
366 case SYNTEK_STK_6A31
:
367 ret
= dev_stk6a31_set_camera_quality(dev
);
370 case SYNTEK_STK_6A33
:
371 ret
= dev_stk6a33_set_camera_quality(dev
);
374 case SYNTEK_STK_6A54
:
375 ret
= dev_stk6a54_set_camera_quality(dev
);
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
)
400 switch (dev
->webcam_model
) {
401 case SYNTEK_STK_M811
:
402 case SYNTEK_STK_A311
:
403 ret
= dev_stka311_set_camera_fps(dev
);
406 case SYNTEK_STK_A821
:
407 ret
= dev_stka821_set_camera_fps(dev
);
410 case SYNTEK_STK_6A31
:
411 ret
= dev_stk6a31_set_camera_fps(dev
);
414 case SYNTEK_STK_6A33
:
415 ret
= dev_stk6a33_set_camera_fps(dev
);
418 case SYNTEK_STK_6A54
:
419 ret
= dev_stk6a54_set_camera_fps(dev
);
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
)
444 switch (dev
->webcam_model
) {
445 case SYNTEK_STK_M811
:
446 case SYNTEK_STK_A311
:
447 ret
= dev_stka311_start_stream(dev
);
450 case SYNTEK_STK_A821
:
451 ret
= dev_stka821_start_stream(dev
);
454 case SYNTEK_STK_6A31
:
455 ret
= dev_stk6a31_start_stream(dev
);
458 case SYNTEK_STK_6A33
:
459 ret
= dev_stk6a33_start_stream(dev
);
462 case SYNTEK_STK_6A54
:
463 ret
= dev_stk6a54_start_stream(dev
);
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
)
487 switch (dev
->webcam_model
) {
488 case SYNTEK_STK_M811
:
489 case SYNTEK_STK_A311
:
490 ret
= dev_stka311_reconf_camera(dev
);
493 case SYNTEK_STK_A821
:
494 ret
= dev_stka821_reconf_camera(dev
);
497 case SYNTEK_STK_6A31
:
498 ret
= dev_stk6a31_reconf_camera(dev
);
501 case SYNTEK_STK_6A33
:
502 ret
= dev_stk6a33_reconf_camera(dev
);
505 case SYNTEK_STK_6A54
:
506 ret
= dev_stk6a54_reconf_camera(dev
);
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
)
531 switch (dev
->webcam_model
) {
532 case SYNTEK_STK_M811
:
533 case SYNTEK_STK_A311
:
534 ret
= dev_stka311_stop_stream(dev
);
537 case SYNTEK_STK_A821
:
538 ret
= dev_stka821_stop_stream(dev
);
541 case SYNTEK_STK_6A31
:
542 ret
= dev_stk6a31_stop_stream(dev
);
545 case SYNTEK_STK_6A33
:
546 ret
= dev_stk6a33_stop_stream(dev
);
549 case SYNTEK_STK_6A54
:
550 ret
= dev_stk6a54_stop_stream(dev
);