3 * @author Nicolas VIVIEN
7 * @brief Driver for Microdia 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
28 * $Date: 2007-12-09 14:25:47 +0100 (dim, 09 déc 2007) $
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>
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 ??? */
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
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
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
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)
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)
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
183 #if CONFIG_MICRODIA_DEBUG_STREAM
185 #define UDIA_STREAM(str, args...) printk(KERN_DEBUG PREFIX str, ##args)
189 #define UDIA_STREAM(str, args...) do { } while(0)
196 * @enum T_MICRODIA_DEVICE Video camera supported by the driver
220 * @enum T_MICRODIA_VIDEOMODE Video feature supported by camera
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
;
230 * @enum T_MICRODIA_RESOLUTION Video resolution
236 /*MICRODIA_213x160, */
243 } T_MICRODIA_RESOLUTION
;
247 * @enum T_MICRODIA_PALETTE Color palette
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
{
272 * @struct microdia_frame_buf
274 struct microdia_frame_buf
{
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*/
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 __u8 sensor_slave_address
; /**< I2C/SCCB slave address of the image sensor */
337 unsigned char *int_in_buffer
; /**< Interrupt IN buffer */
338 size_t int_in_size
; /**< Interrupt IN buffer size */
339 __u8 int_in_endpointAddr
; /**< Interrupt IN endpoint address */
341 size_t isoc_in_size
; /**< Isochrone IN size */
342 __u8 isoc_in_endpointAddr
; /**< Isochrone IN endpoint address */
344 int watchdog
; /**< Counter for the software watchdog */
346 struct microdia_video vsettings
; /**< Video settings (brightness, whiteness...) */
350 int vopen
; /**< Video status (Opened or Closed) */
351 int visoc_errors
; /**< Count the number of ISOCH errors */
352 int vframes_error
; /**< Count the number of fault frames (so dropped) */
353 int vframes_dumped
; /**< Count the number of ignored frames */
356 spinlock_t spinlock
; /**< Spin lock */
357 struct semaphore mutex
; /**< Mutex */
358 wait_queue_head_t wait_frame
; /**< Queue head */
363 struct microdia_iso_buf isobuf
[MAX_ISO_BUFS
];
367 struct microdia_frame_buf
*framebuf
;
368 struct microdia_frame_buf
*empty_frames
, *empty_frames_tail
;
369 struct microdia_frame_buf
*full_frames
, *full_frames_tail
;
370 struct microdia_frame_buf
*fill_frame
;
371 struct microdia_frame_buf
*read_frame
;
377 struct microdia_image_buf images
[MICRODIA_MAX_IMAGES
];
378 int image_used
[MICRODIA_MAX_IMAGES
];
379 unsigned int nbuffers
;
380 unsigned int len_per_image
;
384 struct microdia_coord view
;
385 struct microdia_coord image
;
387 int (* initialize
) (struct usb_microdia
*dev
);
388 int (* start_stream
) (struct usb_microdia
*dev
);
389 int (* stop_stream
) (struct usb_microdia
*dev
);
390 int (* set_exposure
) (struct usb_microdia
*dev
);
391 int (* flip_detect
) (struct usb_microdia
*dev
);
396 * @def MICRODIA_PERCENT
397 * Calculate a value from a percent
399 #define MICRODIA_PERCENT(x,y) ( ((int)x * (int)y) / 100)
403 * @def to_microdia_dev(d)
404 * Cast a member of a structure out to the containing structure
406 #define to_microdia_dev(d) container_of(d, struct usb_microdia, kref)
409 extern const struct microdia_coord microdia_image_sizes
[MICRODIA_NBR_SIZES
];
412 int usb_microdia_control_write(struct usb_microdia
*, __u16
, __u8
*, __u16
);
413 int usb_microdia_control_write_multi(struct usb_microdia
*, __u16
*, __u8
*,
415 int usb_microdia_control_read(struct usb_microdia
*, __u16
, __u8
*, __u16
);
416 int usb_microdia_set_feature(struct usb_microdia
*, int);
417 int usb_microdia_set_configuration(struct usb_microdia
*);
418 int usb_microdia_isoc_init(struct usb_microdia
*);
419 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
420 void usb_microdia_isoc_handler(struct urb
*, struct pt_regs
*);
422 void usb_microdia_isoc_handler(struct urb
*);
424 void usb_microdia_isoc_cleanup(struct usb_microdia
*);
426 int dev_microdia_initialize_device(struct usb_microdia
*);
427 int dev_microdia_start_stream(struct usb_microdia
*);
428 int dev_microdia_stop_stream(struct usb_microdia
*);
429 int dev_microdia_check_device(struct usb_microdia
*, int);
430 int dev_microdia_camera_on(struct usb_microdia
*);
431 int dev_microdia_camera_off(struct usb_microdia
*);
432 int dev_microdia_camera_asleep(struct usb_microdia
*);
433 int dev_microdia_init_camera(struct usb_microdia
*);
434 int dev_microdia_reconf_camera(struct usb_microdia
*);
435 int dev_microdia_camera_settings(struct usb_microdia
*);
436 int dev_microdia_camera_set_contrast(struct usb_microdia
*);
437 int dev_microdia_camera_set_brightness(struct usb_microdia
*);
438 int dev_microdia_camera_set_gamma(struct usb_microdia
*);
439 int dev_microdia_camera_set_exposure(struct usb_microdia
*);
440 int dev_microdia_set_camera_quality(struct usb_microdia
*);
441 int dev_microdia_set_camera_fps(struct usb_microdia
*);
442 int dev_microdia_watchdog_camera(struct usb_microdia
*);
444 int v4l_microdia_select_video_mode(struct usb_microdia
*, int, int);
445 int v4l_microdia_register_video_device(struct usb_microdia
*);
446 int v4l_microdia_unregister_video_device(struct usb_microdia
*);
448 int microdia_create_sysfs_files(struct video_device
*);
449 void microdia_remove_sysfs_files(struct video_device
*);
451 int microdia_allocate_buffers(struct usb_microdia
*);
452 int microdia_reset_buffers(struct usb_microdia
*);
453 int microdia_clear_buffers(struct usb_microdia
*);
454 int microdia_free_buffers(struct usb_microdia
*);
455 void microdia_next_image(struct usb_microdia
*);
456 int microdia_next_frame(struct usb_microdia
*);
457 int microdia_handle_frame(struct usb_microdia
*);
459 int microdia_decompress(struct usb_microdia
*);