Release 1.2.1
[syntekdriver.git] / stk11xx.h
blobe9eac6aceea0f47831bd4bfdd7546ed42f79456f
1 /**
2 * @file stk11xx.h
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 #ifndef STK11XX_H
35 #define STK11XX_H
38 #define DRIVER_NAME "stk11xx" /**< Name of this driver */
39 #define DRIVER_VERSION "v1.2.0" /**< Version of this driver */
40 #define DRIVER_VERSION_NUM 0x010200 /**< Version numerical of this driver */
41 #define DRIVER_DESC "Syntek USB Video Camera" /**< Short description of this driver */
42 #define DRIVER_AUTHOR "Nicolas VIVIEN" /**< Author of this driver */
43 #define PREFIX DRIVER_NAME ": " /**< Prefix use for the STK "printk" */
45 #define USB_SYNTEK1_VENDOR_ID 0x174f /**< Vendor ID of the camera */
46 #define USB_SYNTEK2_VENDOR_ID 0x05e1 /**< Vendor ID of the camera */
48 #define USB_STK_A311_PRODUCT_ID 0xa311 /**< Product ID of the camera STK-1125 */
49 #define USB_STK_A821_PRODUCT_ID 0xa821 /**< Product ID of the camera STK-1135 */
50 #define USB_STK_6A31_PRODUCT_ID 0x6a31 /**< Product ID of the camera DC-NEW */
51 #define USB_STK_6A33_PRODUCT_ID 0x6a33 /**< Product ID of the camera DC-NEW */
52 #define USB_STK_6A54_PRODUCT_ID 0x6a54 /**< Product ID of the camera DC-NEW */
54 #define USB_STK_0501_PRODUCT_ID 0x0501 /**< Product ID of the camera DC-1125 */
57 /**
58 * @def VID_HARDWARE_STK11XX
60 * This value must be inserted into the kernel headers linux/videodev.h
61 * It's useful only for the support of V4L v1
63 #define VID_HARDWARE_STK11XX 88
68 /**
69 * @def MAX_ISO_BUFS
70 * Number maximal of ISOC buffers
72 * @def ISO_FRAMES_PER_DESC
73 * Number frames per ISOC descriptor
75 * @def ISO_MAX_FRAME_SIZE
76 * Maximale size of frame
78 * @def ISO_BUFFER_SIZE
79 * Maximal size of buffer
81 #define MAX_ISO_BUFS 16
82 #define ISO_FRAMES_PER_DESC 10
83 #define ISO_MAX_FRAME_SIZE 3 * 1024
84 #define ISO_BUFFER_SIZE (ISO_FRAMES_PER_DESC * ISO_MAX_FRAME_SIZE)
87 /**
88 * @def STK11XX_MAX_IMAGES
89 * Absolute maximum number of buffers available for mmap()
91 * @def STK11XX_FRAME_SIZE
92 * Maximum size after decompression
94 #define STK11XX_MAX_IMAGES 10
95 #define STK11XX_FRAME_SIZE (1280 * 1024 * 4)
104 * @def DRIVER_SUPPORT
106 * List of supported device
107 * - DC1125 : USB2.0 Syntek chipset
109 #define DRIVER_SUPPORT "Syntek USB Camera : STK-1135"
112 * @def CONFIG_STK11XX_DEBUG
113 * Enable / Disable the debug mode.
115 * @def STK_INFO(str, args...)
116 * Print information message.
117 * @a Use this function like the function printf.
119 * @def STK_ERROR(str, args...)
120 * Print error message.
121 * @a Use this function like the function printf.
123 * @def STK_WARNING(str, args...)
124 * Print warning message.
125 * @a Use this function like the function printf.
127 * @def STK_DEBUG(str, args...)
128 * Print debug message.
129 * @a Use this function like the function printf.
131 #ifndef CONFIG_STK11XX_DEBUG
132 #define CONFIG_STK11XX_DEBUG 0
133 #endif
135 #if CONFIG_STK11XX_DEBUG
137 #define STK_INFO(str, args...) printk(KERN_INFO PREFIX str, ##args)
138 #define STK_ERROR(str, args...) printk(KERN_ERR PREFIX str, ##args)
139 #define STK_WARNING(str, args...) printk(KERN_WARNING PREFIX str, ##args)
140 #define STK_DEBUG(str, args...) printk(KERN_DEBUG PREFIX str, ##args)
142 #else
144 #define STK_INFO(str, args...) printk(KERN_INFO PREFIX str, ##args)
145 #define STK_ERROR(str, args...) printk(KERN_ERR PREFIX str, ##args)
146 #define STK_WARNING(str, args...) printk(KERN_WARNING PREFIX str, ##args)
147 #define STK_DEBUG(str, args...) do { } while(0)
149 #endif
153 * @def CONFIG_STK11XX_DEBUG_STREAM
154 * Enable / Disable the debug mode about the stream.
156 * @def STK_STREAM(str, args...)
157 * Print stream debug message.
158 * @a Use this function like the function printf.
160 #ifndef CONFIG_STK11XX_DEBUG_STREAM
161 #define CONFIG_STK11XX_DEBUG_STREAM 0
162 #endif
164 #if CONFIG_STK11XX_DEBUG_STREAM
166 #define STK_STREAM(str, args...) printk(KERN_DEBUG PREFIX str, ##args)
168 #else
170 #define STK_STREAM(str, args...) do { } while(0)
172 #endif
177 * @enum T_SYNTEK_DEVICE Video camera supported by the driver
179 typedef enum {
180 SYNTEK_STK_M811 = 1,
181 SYNTEK_STK_A311 = 2,
182 SYNTEK_STK_A821 = 3,
183 SYNTEK_STK_6A31 = 4,
184 SYNTEK_STK_6A33 = 5,
185 SYNTEK_STK_6A54 = 6
186 } T_SYNTEK_DEVICE;
190 * @enum T_STK11XX_VIDEOMODE Video feature supported by camera
192 typedef enum {
193 STK11XX_VGA, /**< For VGA video camera */
194 STK11XX_SXGA, /**< For SXGA video camera 1.3M */
195 STK11XX_UXGA /**< For UXGA video camera 2M */
196 } T_STK11XX_VIDEOMODE;
199 /**
200 * @enum T_STK11XX_RESOLUTION Video resolution
202 typedef enum {
203 STK11XX_80x60,
204 STK11XX_128x96,
205 STK11XX_160x120,
206 STK11XX_213x160,
207 STK11XX_320x240,
208 STK11XX_640x480,
209 STK11XX_800x600,
210 STK11XX_1024x768,
211 STK11XX_1280x1024,
212 STK11XX_NBR_SIZES
213 } T_STK11XX_RESOLUTION;
217 * @enum T_STK11XX_PALETTE Color palette
219 typedef enum {
220 STK11XX_PALETTE_RGB24,
221 STK11XX_PALETTE_RGB32,
222 STK11XX_PALETTE_BGR24,
223 STK11XX_PALETTE_BGR32,
224 STK11XX_PALETTE_UYVY,
225 STK11XX_PALETTE_YUYV
226 } T_STK11XX_PALETTE;
230 * @struct stk11xx_iso_buf
232 struct stk11xx_iso_buf {
233 void *data;
234 int length;
235 int read;
236 struct urb *urb;
241 * @struct stk11xx_frame_buf
243 struct stk11xx_frame_buf {
244 int errors;
245 void *data;
246 volatile int filled;
247 struct stk11xx_frame_buf *next;
252 * @struct stk11xx_image_buf
254 struct stk11xx_image_buf {
255 unsigned long offset; /**< Memory offset */
256 int vma_use_count; /**< VMA counter */
261 * @struct stk11xx_coord
263 struct stk11xx_coord {
264 int x; /**< X-coordonate */
265 int y; /**< Y-coordonate */
270 * @struct stk11xx_video
272 struct stk11xx_video {
273 int fps; /**< FPS setting */
274 int brightness; /**< Brightness setting */
275 int contrast; /**< Contrast setting */
276 int whiteness; /**< Whiteness setting */
277 int colour; /**< Colour setting */
278 int depth; /**< Depth colour setting */
279 int palette; /**< Palette setting */
280 int hue; /**< Hue setting */
281 int hflip; /**< Horizontal flip */
282 int vflip; /**< Vertical flip */
287 * @struct usb_stk11xx
289 struct usb_stk11xx {
290 struct video_device *vdev; /**< Pointer on a V4L2 video device */
291 struct usb_device *udev; /**< Pointer on a USB device */
292 struct usb_interface *interface; /**< Pointer on a USB interface */
294 int release; /**< Release of the device (bcdDevice) */
295 int webcam_model; /**< Model of video camera device */
296 int webcam_type; /**< Type of camera : VGA, SXGA (1.3M), UXGA (2M) */
298 unsigned char *int_in_buffer; /**< Interrupt IN buffer */
299 size_t int_in_size; /**< Interrupt IN buffer size */
300 __u8 int_in_endpointAddr; /**< Interrupt IN endpoint address */
302 size_t isoc_in_size; /**< Isochrone IN size */
303 __u8 isoc_in_endpointAddr; /**< Isochrone IN endpoint address */
305 int watchdog; /**< Counter for the software watchdog */
307 struct stk11xx_video vsettings; /**< Video settings (brightness, whiteness...) */
309 int error_status;
311 int vopen; /**< Video status (Opened or Closed) */
312 int visoc_errors; /**< Count the number of ISOCH errors */
313 int vframes_error; /**< Count the number of fault frames (so dropped) */
314 int vframes_dumped; /**< Count the number of ignored frames */
317 spinlock_t spinlock; /**< Spin lock */
318 struct semaphore mutex; /**< Mutex */
319 wait_queue_head_t wait_frame; /**< Queue head */
322 // 1: isoc
323 char isoc_init_ok;
324 struct stk11xx_iso_buf isobuf[MAX_ISO_BUFS];
326 // 2: frame
327 int frame_size;
328 struct stk11xx_frame_buf *framebuf;
329 struct stk11xx_frame_buf *empty_frames, *empty_frames_tail;
330 struct stk11xx_frame_buf *full_frames, *full_frames_tail;
331 struct stk11xx_frame_buf *fill_frame;
332 struct stk11xx_frame_buf *read_frame;
334 // 3: image
335 int image_size;
336 void *image_data;
337 struct stk11xx_image_buf images[STK11XX_MAX_IMAGES];
338 int image_used[STK11XX_MAX_IMAGES];
339 unsigned int nbuffers;
340 unsigned int len_per_image;
341 int image_read_pos;
342 int fill_image;
343 int resolution;
344 struct stk11xx_coord view;
345 struct stk11xx_coord image;
350 * @def STK11XX_PERCENT
351 * Calculate a value from a percent
353 #define STK11XX_PERCENT(x,y) ( ((int)x * (int)y) / 100)
357 * @def to_stk11xx_dev(d)
358 * Cast a member of a structure out to the containing structure
360 #define to_stk11xx_dev(d) container_of(d, struct usb_stk11xx, kref)
363 extern const struct stk11xx_coord stk11xx_image_sizes[STK11XX_NBR_SIZES];
366 int usb_stk11xx_write_registry(struct usb_stk11xx *, __u16, __u16);
367 int usb_stk11xx_read_registry(struct usb_stk11xx *, __u16, int *);
368 int usb_stk11xx_set_feature(struct usb_stk11xx *, int);
369 int usb_stk11xx_set_configuration(struct usb_stk11xx *);
370 int usb_stk11xx_isoc_init(struct usb_stk11xx *);
371 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
372 void usb_stk11xx_isoc_handler(struct urb *, struct pt_regs *);
373 #else
374 void usb_stk11xx_isoc_handler(struct urb *);
375 #endif
376 void usb_stk11xx_isoc_cleanup(struct usb_stk11xx *);
378 int dev_stk11xx_initialize_device(struct usb_stk11xx *);
379 int dev_stk11xx_start_stream(struct usb_stk11xx *);
380 int dev_stk11xx_stop_stream(struct usb_stk11xx *);
381 int dev_stk11xx_check_device(struct usb_stk11xx *, int);
382 int dev_stk11xx_camera_on(struct usb_stk11xx *);
383 int dev_stk11xx_camera_off(struct usb_stk11xx *);
384 int dev_stk11xx_camera_asleep(struct usb_stk11xx *);
385 int dev_stk11xx_init_camera(struct usb_stk11xx *);
386 int dev_stk11xx_reconf_camera(struct usb_stk11xx *);
387 int dev_stk11xx_camera_settings(struct usb_stk11xx *);
388 int dev_stk11xx_set_camera_quality(struct usb_stk11xx *);
389 int dev_stk11xx_set_camera_fps(struct usb_stk11xx *);
390 int dev_stk11xx_watchdog_camera(struct usb_stk11xx *);
392 int v4l_stk11xx_select_video_mode(struct usb_stk11xx *, int, int);
393 int v4l_stk11xx_register_video_device(struct usb_stk11xx *);
394 int v4l_stk11xx_unregister_video_device(struct usb_stk11xx *);
396 int stk11xx_create_sysfs_files(struct video_device *);
397 void stk11xx_remove_sysfs_files(struct video_device *);
399 int stk11xx_allocate_buffers(struct usb_stk11xx *);
400 int stk11xx_reset_buffers(struct usb_stk11xx *);
401 int stk11xx_clear_buffers(struct usb_stk11xx *);
402 int stk11xx_free_buffers(struct usb_stk11xx *);
403 void stk11xx_next_image(struct usb_stk11xx *);
404 int stk11xx_next_frame(struct usb_stk11xx *);
405 int stk11xx_handle_frame(struct usb_stk11xx *);
407 int stk11xx_decompress(struct usb_stk11xx *);
410 #endif