Added support for O_NONBLOCK in DQBUF ioctl
[microdia.git] / microdia.h
blob9f592a4898b99dc4682082c2032b32665fd51bb6
1 /**
2 * @file microdia.h
3 * @author Nicolas VIVIEN
4 * @date 2008-02-01
5 * @version v0.0.0
7 * @brief Driver for Microdia 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: 2007-12-09 14:25:47 +0100 (dim, 09 déc 2007) $
29 * $Revision: 69 $
30 * $Author: nicklas79 $
31 * $HeadURL: https://syntekdriver.svn.sourceforge.net/svnroot/syntekdriver/trunk/driver/microdia.h $
34 #include <linux/kernel.h>
35 #include <linux/version.h>
36 #include <linux/usb.h>
37 #include <media/v4l2-common.h>
39 #ifndef MICRODIA_H
40 #define MICRODIA_H
43 #define DRIVER_NAME "microdia" /**< Name of this driver */
44 #define DRIVER_VERSION "v0.0.0" /**< Version of this driver */
45 #define DRIVER_VERSION_NUM 0x000000 /**< Version numerical of this driver */
46 #define DRIVER_DESC "Microdia USB Video Camera" /**< Short description of this driver */
47 #define DRIVER_AUTHOR "Nicolas VIVIEN" /**< Author of this driver */
48 #define PREFIX DRIVER_NAME ": " /**< Prefix use for the STK "printk" */
50 #define USB_MICRODIA_VENDOR_ID 0x0c45 /**< Vendor ID of the camera */
52 #define USB_UDIA_6027_PRODUCT_ID 0x6027 /**< Product ID of the camera ??? */
53 #define USB_UDIA_608F_PRODUCT_ID 0x608f /**< Product ID of the camera ??? */
54 #define USB_UDIA_60FE_PRODUCT_ID 0x60fe /**< Product ID of the camera ??? */
55 #define USB_UDIA_6242_PRODUCT_ID 0x6242 /**< Product ID of the camera ??? */
56 #define USB_UDIA_6253_PRODUCT_ID 0x6253 /**< Product ID of the camera ??? */
57 #define USB_UDIA_6260_PRODUCT_ID 0x6260 /**< Product ID of the camera ??? */
58 #define USB_UDIA_6270_PRODUCT_ID 0x6270 /**< Product ID of the camera ??? */
59 #define USB_UDIA_60C0_PRODUCT_ID 0x60c0 /**< Product ID of the camera ??? */
60 #define USB_UDIA_613B_PRODUCT_ID 0x613b /**< Product ID of the camera ??? */
61 #define USB_UDIA_613C_PRODUCT_ID 0x613c /**< Product ID of the camera ??? */
62 #define USB_UDIA_624F_PRODUCT_ID 0x624f /**< Product ID of the camera ??? */
63 #define USB_UDIA_627B_PRODUCT_ID 0x627b /**< Product ID of the camera ??? */
64 #define USB_UDIA_62C0_PRODUCT_ID 0x62c0 /**< Product ID of the camera ??? */
65 #define USB_UDIA_8105_PRODUCT_ID 0x8105 /**< Product ID of the camera ??? */
66 #define USB_UDIA_624E_PRODUCT_ID 0x624e /**< Product ID of the camera ??? */
67 #define USB_UDIA_6128_PRODUCT_ID 0x6128 /**< Product ID of the camera ??? */
70 /**
71 * @def VID_HARDWARE_MICRODIA
73 * This value must be inserted into the kernel headers linux/videodev.h
74 * It's useful only for the support of V4L v1
76 #define VID_HARDWARE_MICRODIA 88
81 /**
82 * @def MAX_ISO_BUFS
83 * Number maximal of ISOC buffers
85 * @def ISO_FRAMES_PER_DESC
86 * Number frames per ISOC descriptor
88 #define MAX_ISO_BUFS 16
89 #define ISO_FRAMES_PER_DESC 10
91 /**
92 * @def hb_multiplier(wMaxPacketSize)
93 * USB endpoint high bandwidth multiplier
95 * @def max_packet_sz(wMaxPacketSize)
96 * USB endpoint maximum packet size
98 * These values are both encoded within the wMaxPacketSize field of the usb_endpoint_descriptor structure.
99 * The 11(10:0) lowest bits hold the MaxPacketSize(according to the usb specs a value over 1024 is undefined),
100 * and the bits 12:11 will give the high bandwidth multiplier(this should be a value of 0-2).
103 #define hb_multiplier(wMaxPacketSize) (((wMaxPacketSize >> 11) & 0x03) + 1)
104 #define max_packet_sz(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
107 * @def MICRODIA_MAX_IMAGES
108 * Absolute maximum number of buffers available for mmap()
110 * @def MICRODIA_FRAME_SIZE
111 * Maximum size after decompression
113 #define MICRODIA_MAX_IMAGES 10
114 #define MICRODIA_FRAME_SIZE (1280 * 1024 * 4)
123 * @def DRIVER_SUPPORT
125 * List of supported device
126 * - DC1125 : USB2.0 Syntek chipset
128 #define DRIVER_SUPPORT "Microdia USB Camera"
131 * @def CONFIG_MICRODIA_DEBUG
132 * Enable / Disable the debug mode.
134 * @def UDIA_INFO(str, args...)
135 * Print information message.
136 * @a Use this function like the function printf.
138 * @def UDIA_ERROR(str, args...)
139 * Print error message.
140 * @a Use this function like the function printf.
142 * @def UDIA_WARNING(str, args...)
143 * Print warning message.
144 * @a Use this function like the function printf.
146 * @def UDIA_DEBUG(str, args...)
147 * Print debug message.
148 * @a Use this function like the function printf.
150 #ifndef CONFIG_MICRODIA_DEBUG
151 #define CONFIG_MICRODIA_DEBUG 0
152 #endif
154 #if CONFIG_MICRODIA_DEBUG
156 #define UDIA_INFO(str, args...) printk(KERN_INFO PREFIX str, ##args)
157 #define UDIA_ERROR(str, args...) printk(KERN_ERR PREFIX str, ##args)
158 #define UDIA_WARNING(str, args...) printk(KERN_WARNING PREFIX str, ##args)
159 #define UDIA_DEBUG(str, args...) printk(KERN_DEBUG PREFIX str, ##args)
161 #else
163 #define UDIA_INFO(str, args...) printk(KERN_INFO PREFIX str, ##args)
164 #define UDIA_ERROR(str, args...) printk(KERN_ERR PREFIX str, ##args)
165 #define UDIA_WARNING(str, args...) printk(KERN_WARNING PREFIX str, ##args)
166 #define UDIA_DEBUG(str, args...) do { } while(0)
168 #endif
172 * @def CONFIG_MICRODIA_DEBUG_STREAM
173 * Enable / Disable the debug mode about the stream.
175 * @def UDIA_STREAM(str, args...)
176 * Print stream debug message.
177 * @a Use this function like the function printf.
179 #ifndef CONFIG_MICRODIA_DEBUG_STREAM
180 #define CONFIG_MICRODIA_DEBUG_STREAM 0
181 #endif
183 #if CONFIG_MICRODIA_DEBUG_STREAM
185 #define UDIA_STREAM(str, args...) printk(KERN_DEBUG PREFIX str, ##args)
187 #else
189 #define UDIA_STREAM(str, args...) do { } while(0)
191 #endif
196 * @enum T_MICRODIA_DEVICE Video camera supported by the driver
198 typedef enum {
199 MICRODIA_6027 = 1,
200 MICRODIA_608F = 2,
201 MICRODIA_60EC = 3,
202 MICRODIA_60FE = 4,
203 MICRODIA_6242 = 5,
204 MICRODIA_6253 = 6,
205 MICRODIA_6260 = 7,
206 MICRODIA_6270 = 8,
207 MICRODIA_60C0 = 9,
208 MICRODIA_613B = 10,
209 MICRODIA_613C = 11,
210 MICRODIA_624F = 12,
211 MICRODIA_627B = 13,
212 MICRODIA_62C0 = 14,
213 MICRODIA_8105 = 15,
214 MICRODIA_624E = 16,
215 MICRODIA_6128 = 17
216 } T_MICRODIA_DEVICE;
220 * @enum T_MICRODIA_VIDEOMODE Video feature supported by camera
222 typedef enum {
223 MICRODIA_VGA, /**< For VGA video camera */
224 MICRODIA_SXGA, /**< For SXGA video camera 1.3M */
225 MICRODIA_UXGA /**< For UXGA video camera 2M */
226 } T_MICRODIA_VIDEOMODE;
229 /**
230 * @enum T_MICRODIA_RESOLUTION Video resolution
232 typedef enum {
233 MICRODIA_80x60,
234 /*MICRODIA_128x96,*/
235 MICRODIA_160x120,
236 /*MICRODIA_213x160, */
237 MICRODIA_320x240,
238 MICRODIA_640x480,
239 MICRODIA_800x600,
240 MICRODIA_1024x768,
241 MICRODIA_1280x1024,
242 MICRODIA_NBR_SIZES
243 } T_MICRODIA_RESOLUTION;
247 * @enum T_MICRODIA_PALETTE Color palette
249 typedef enum {
250 MICRODIA_PALETTE_I420,
251 MICRODIA_PALETTE_RGB24,
252 MICRODIA_PALETTE_RGB32,
253 MICRODIA_PALETTE_BGR24,
254 MICRODIA_PALETTE_BGR32,
255 MICRODIA_PALETTE_UYVY,
256 MICRODIA_PALETTE_YUYV
257 } T_MICRODIA_PALETTE;
261 * @struct microdia_iso_buf
263 struct microdia_iso_buf {
264 void *data;
265 int length;
266 int read;
267 struct urb *urb;
272 * @struct microdia_frame_buf
274 struct microdia_frame_buf {
275 int errors;
276 void *data;
277 volatile int filled;
278 struct microdia_frame_buf *next;
283 * @struct microdia_image_buf
285 struct microdia_image_buf {
286 unsigned long offset; /**< Memory offset */
287 int vma_use_count; /**< VMA counter */
292 * @struct microdia_coord
294 struct microdia_coord {
295 int x; /**< X-coordonate */
296 int y; /**< Y-coordonate */
301 * @struct microdia_video
303 struct microdia_video {
304 int fps; /**< FPS setting */
305 int brightness; /**< Brightness setting */
306 int contrast; /**< Contrast setting */
307 int whiteness; /**< Whiteness setting */
308 int colour; /**< Colour setting */
309 int depth; /**< Depth colour setting */
310 int palette; /**< Palette setting */
311 int hue; /**< Hue setting */
312 int hflip; /**< Horizontal flip */
313 int vflip; /**< Vertical flip */
314 int reg; /**< register adress*/
315 int val; /**< register value*/
316 int i2creg; /**< I2C register adress*/
317 int i2cval; /**< I2C register value*/
318 int i2cslave; /**< I2C slave adress*/
319 int exposure;
324 * @struct usb_microdia
326 struct usb_microdia {
327 struct video_device *vdev; /**< Pointer on a V4L2 video device */
328 struct usb_device *udev; /**< Pointer on a USB device */
329 struct usb_interface *interface; /**< Pointer on a USB interface */
331 int release; /**< Release of the device (bcdDevice) */
332 int webcam_model; /**< Model of video camera device */
333 int webcam_type; /**< Type of camera : VGA, SXGA (1.3M), UXGA (2M) */
335 unsigned char *int_in_buffer; /**< Interrupt IN buffer */
336 size_t int_in_size; /**< Interrupt IN buffer size */
337 __u8 int_in_endpointAddr; /**< Interrupt IN endpoint address */
339 size_t isoc_in_size; /**< Isochrone IN size */
340 __u8 isoc_in_endpointAddr; /**< Isochrone IN endpoint address */
342 int watchdog; /**< Counter for the software watchdog */
344 struct microdia_video vsettings; /**< Video settings (brightness, whiteness...) */
346 int error_status;
348 int vopen; /**< Video status (Opened or Closed) */
349 int visoc_errors; /**< Count the number of ISOCH errors */
350 int vframes_error; /**< Count the number of fault frames (so dropped) */
351 int vframes_dumped; /**< Count the number of ignored frames */
354 spinlock_t spinlock; /**< Spin lock */
355 struct semaphore mutex; /**< Mutex */
356 wait_queue_head_t wait_frame; /**< Queue head */
359 // 1: isoc
360 char isoc_init_ok;
361 struct microdia_iso_buf isobuf[MAX_ISO_BUFS];
363 // 2: frame
364 int frame_size;
365 struct microdia_frame_buf *framebuf;
366 struct microdia_frame_buf *empty_frames, *empty_frames_tail;
367 struct microdia_frame_buf *full_frames, *full_frames_tail;
368 struct microdia_frame_buf *fill_frame;
369 struct microdia_frame_buf *read_frame;
371 // 3: image
372 int view_size;
373 int image_size;
374 void *image_data;
375 struct microdia_image_buf images[MICRODIA_MAX_IMAGES];
376 int image_used[MICRODIA_MAX_IMAGES];
377 unsigned int nbuffers;
378 unsigned int len_per_image;
379 int image_read_pos;
380 int fill_image;
381 int resolution;
382 struct microdia_coord view;
383 struct microdia_coord image;
385 int (* initialize) (struct usb_microdia *dev);
386 int (* start_stream) (struct usb_microdia *dev);
387 int (* stop_stream) (struct usb_microdia *dev);
388 int (* set_exposure) (struct usb_microdia *dev);
393 * @def MICRODIA_PERCENT
394 * Calculate a value from a percent
396 #define MICRODIA_PERCENT(x,y) ( ((int)x * (int)y) / 100)
400 * @def to_microdia_dev(d)
401 * Cast a member of a structure out to the containing structure
403 #define to_microdia_dev(d) container_of(d, struct usb_microdia, kref)
406 extern const struct microdia_coord microdia_image_sizes[MICRODIA_NBR_SIZES];
409 int usb_microdia_control_write(struct usb_microdia *, __u16, __u8 *, __u16);
410 int usb_microdia_control_write_multi(struct usb_microdia *, __u16*, __u8 *,
411 __u16, __u16);
412 int usb_microdia_control_read(struct usb_microdia *, __u16, __u8 *, __u16);
413 int usb_microdia_set_feature(struct usb_microdia *, int);
414 int usb_microdia_set_configuration(struct usb_microdia *);
415 int usb_microdia_isoc_init(struct usb_microdia *);
416 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
417 void usb_microdia_isoc_handler(struct urb *, struct pt_regs *);
418 #else
419 void usb_microdia_isoc_handler(struct urb *);
420 #endif
421 void usb_microdia_isoc_cleanup(struct usb_microdia *);
423 int dev_microdia_initialize_device(struct usb_microdia *);
424 int dev_microdia_start_stream(struct usb_microdia *);
425 int dev_microdia_stop_stream(struct usb_microdia *);
426 int dev_microdia_check_device(struct usb_microdia *, int);
427 int dev_microdia_camera_on(struct usb_microdia *);
428 int dev_microdia_camera_off(struct usb_microdia *);
429 int dev_microdia_camera_asleep(struct usb_microdia *);
430 int dev_microdia_init_camera(struct usb_microdia *);
431 int dev_microdia_reconf_camera(struct usb_microdia *);
432 int dev_microdia_camera_settings(struct usb_microdia *);
433 int dev_microdia_camera_set_contrast(struct usb_microdia *);
434 int dev_microdia_camera_set_brightness(struct usb_microdia *);
435 int dev_microdia_camera_set_gamma(struct usb_microdia *);
436 int dev_microdia_camera_set_exposure(struct usb_microdia *);
437 int dev_microdia_set_camera_quality(struct usb_microdia *);
438 int dev_microdia_set_camera_fps(struct usb_microdia *);
439 int dev_microdia_watchdog_camera(struct usb_microdia *);
441 int v4l_microdia_select_video_mode(struct usb_microdia *, int, int);
442 int v4l_microdia_register_video_device(struct usb_microdia *);
443 int v4l_microdia_unregister_video_device(struct usb_microdia *);
445 int microdia_create_sysfs_files(struct video_device *);
446 void microdia_remove_sysfs_files(struct video_device *);
448 int microdia_allocate_buffers(struct usb_microdia *);
449 int microdia_reset_buffers(struct usb_microdia *);
450 int microdia_clear_buffers(struct usb_microdia *);
451 int microdia_free_buffers(struct usb_microdia *);
452 void microdia_next_image(struct usb_microdia *);
453 int microdia_next_frame(struct usb_microdia *);
454 int microdia_handle_frame(struct usb_microdia *);
456 int microdia_decompress(struct usb_microdia *);
459 #endif