Fix checkpatch errors in mt9vx11.h
[microdia.git] / microdia.h
bloba0d07c1046ab2efbd01fae41a156660170c4a358
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
28 #include <linux/kernel.h>
29 #include <linux/version.h>
30 #include <linux/usb.h>
31 #include <media/v4l2-common.h>
33 #ifndef MICRODIA_H
34 #define MICRODIA_H
37 #define DRIVER_NAME "microdia" /**< Name of this driver */
38 #define DRIVER_VERSION "v0.0.0" /**< Version of this driver */
39 #define DRIVER_VERSION_NUM 0x000000 /**< Version numerical of this driver */
40 #define DRIVER_DESC "Microdia USB Video Camera" /**< Short description of this driver */
41 #define DRIVER_AUTHOR "Nicolas VIVIEN" /**< Author of this driver */
42 #define PREFIX DRIVER_NAME ": " /**< Prefix use for the MICRODIA "printk" */
44 #define USB_0C45_VID 0x0c45 /**< Vendor ID of MICRODIA */
45 #define USB_045E_VID 0x045e /**< Vendor ID of MICROSOFT */
46 #define USB_04F2_VID 0x04f2 /**< Vendor ID of CHICONY */
47 #define USB_145F_VID 0x145f /**< Vendor ID of TRUST */
49 // SN9C201:
50 #define USB_6240_PID 0x6240 /**< SN9C201 + MI1300 */
51 #define USB_6242_PID 0x6242 /**< SN9C201 + MI1310 */
52 #define USB_6243_PID 0x6243 /**< SN9C201 + S5K4AAFX */
53 #define USB_6248_PID 0x6248 /**< SN9C201 + OV9655 */
54 #define USB_624B_PID 0x624b /**< SN9C201 + CX1332 */
55 #define USB_624C_PID 0x624c /**< SN9C201 + MI1320 */
56 #define USB_624E_PID 0x624e /**< SN9C201 + SOI968 */
57 #define USB_624F_PID 0x624f /**< SN9C201 + OV9650 */
58 #define USB_6253_PID 0x6253 /**< SN9C201 + OV9650 */
59 #define USB_6260_PID 0x6260 /**< SN9C201 + OV7670ISP */
60 #define USB_6262_PID 0x6262 /**< SN9C201 + OM6802 */
61 #define USB_6270_PID 0x6270 /**< SN9C201 + MI0360/MT9V111 */
62 #define USB_627A_PID 0x627a /**< SN9C201 + S5K53BEB */
63 #define USB_627B_PID 0x627b /**< SN9C201 + OV7660 */
64 #define USB_627C_PID 0x627c /**< SN9C201 + HV7131R */
65 #define USB_627F_PID 0x627f /**< EEPROM */
66 // SN9C202:
67 #define USB_6280_PID 0x6280 /**< SN9C202 + MI1300 */
68 #define USB_6282_PID 0x6282 /**< SN9C202 + MI1310 */
69 #define USB_6283_PID 0x6283 /**< SN9C202 + S5K4AAFX */
70 #define USB_6288_PID 0x6288 /**< SN9C202 + OV9655 */
71 #define USB_628A_PID 0x628a /**< SN9C202 + ICM107 */
72 #define USB_628B_PID 0x628b /**< SN9C202 + CX1332 */
73 #define USB_628C_PID 0x628c /**< SN9C202 + MI1320 */
74 #define USB_628E_PID 0x628e /**< SN9C202 + SOI968 */
75 #define USB_628F_PID 0x628f /**< SN9C202 + OV9650 */
76 #define USB_62A0_PID 0x62a0 /**< SN9C202 + OV7670ISP */
77 #define USB_62A2_PID 0x62a2 /**< SN9C202 + OM6802 */
78 #define USB_62B0_PID 0x62b0 /**< SN9C202 + MI0360/MT9V111 */
79 #define USB_62B3_PID 0x62b3 /**< SN9C202 + OV9655 */
80 #define USB_62BA_PID 0x62ba /**< SN9C202 + S5K53BEB */
81 #define USB_62BB_PID 0x62bb /**< SN9C202 + OV7660 */
82 #define USB_62BC_PID 0x62bc /**< SN9C202 + HV7131R */
83 #define USB_62BE_PID 0x62be /**< SN9C202 + OV7663 */
84 // SN9C325:
85 #define USB_6128_PID 0x6128 /**< SN9C325 + OM6802 */
86 #define USB_612A_PID 0x612a /**< SN9C325 + OV7648 + POx1030xC + SOI768 + PO2030N + OV7660 + OV7670 + HV7131R */
87 // *** "Clone"-devices ***:
88 // Microsoft LifeCam VX-6000:
89 #define USB_00F4_PID 0x00f4 /**< => 628f (SN9C202 + OV9650) */
90 // Trust WB-3600R:
91 #define USB_013D_PID 0x013d /**< => 627b (SN9C201 + OV7660) */
92 // Chicony Panda 7, Trust WB-3450P:
93 #define USB_A128_PID 0xa128 /**< => 62be (SN9C202 + OV7663) */
95 #define CAMERA_MODEL(vid, pid) ((vid << 16) | pid)
96 #define CAMERA_VID(model) ((model >> 16) & 0xFFFF)
97 #define CAMERA_PID(model) (model & 0xFFFF)
99 /**
100 * @def VID_HARDWARE_MICRODIA
102 * This value must be inserted into the kernel headers linux/videodev.h
103 * It's useful only for the support of V4L v1
105 #define VID_HARDWARE_MICRODIA 88
111 * @def MAX_ISO_BUFS
112 * Number maximal of ISOC buffers
114 * @def ISO_FRAMES_PER_DESC
115 * Number frames per ISOC descriptor
117 #define MAX_ISO_BUFS 200
118 #define ISO_FRAMES_PER_DESC 10
121 * @def hb_multiplier(wMaxPacketSize)
122 * USB endpoint high bandwidth multiplier
124 * @def max_packet_sz(wMaxPacketSize)
125 * USB endpoint maximum packet size
127 * These values are both encoded within the wMaxPacketSize field of the usb_endpoint_descriptor structure.
128 * The 11(10:0) lowest bits hold the MaxPacketSize(according to the usb specs a value over 1024 is undefined),
129 * and the bits 12:11 will give the high bandwidth multiplier(this should be a value of 0-2).
132 #define hb_multiplier(wMaxPacketSize) (((wMaxPacketSize >> 11) & 0x03) + 1)
133 #define max_packet_sz(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
136 * @def MICRODIA_FRAME_SIZE
137 * Maximum size after decompression
139 #define MICRODIA_FRAME_SIZE (1280 * 1024 * 3)
142 * @def MICRODIA_FRAME_SIZE_DIVISOR_DEFAULT
143 * Most models have a Frame size of image_size + image_size/2
145 * @def MICRODIA_FRAME_SIZE_DIVISOR_6260
146 * The 6260 has a Frame size of image_size + image_size
148 #define MICRODIA_FRAME_SIZE_DIVISOR_DEFAULT 2
149 #define MICRODIA_FRAME_SIZE_DIVISOR_6260 1
152 * @def DRIVER_SUPPORT
154 * List of supported devices
156 #define DRIVER_SUPPORT "Microdia USB Camera"
159 #define MICRODIA_INFO (1 << 0)
160 #define MICRODIA_WARNING (1 << 1)
161 #define MICRODIA_ERROR (1 << 2)
162 #define MICRODIA_DEBUG (1 << 3)
163 #define MICRODIA_STREAM (1 << 4)
166 * @def UDIA_INFO(str, args...)
167 * Print information message.
168 * @a Use this function like the function printf.
170 * @def UDIA_ERROR(str, args...)
171 * Print error message.
172 * @a Use this function like the function printf.
174 * @def UDIA_WARNING(str, args...)
175 * Print warning message.
176 * @a Use this function like the function printf.
178 * @def UDIA_DEBUG(str, args...)
179 * Print debug message.
180 * @a Use this function like the function printf.
182 * @def UDIA_STREAM(str, args...)
183 * Print stream debug message.
184 * @a Use this function like the function printf.
186 extern __u8 log_level;
188 #define UDIA_INFO(str, args...) \
189 do { \
190 if (log_level & MICRODIA_INFO) \
191 printk(KERN_INFO PREFIX str, ##args); \
192 } while (0)
194 #define UDIA_WARNING(str, args...) \
195 do { \
196 if (log_level & MICRODIA_WARNING) \
197 printk(KERN_WARNING PREFIX str, ##args); \
198 } while (0)
200 #define UDIA_ERROR(str, args...) \
201 do { \
202 if (log_level & MICRODIA_ERROR) \
203 printk(KERN_ERR PREFIX str, ##args); \
204 } while (0)
206 #define UDIA_DEBUG(str, args...) \
207 do { \
208 if (log_level & MICRODIA_DEBUG) \
209 printk(KERN_DEBUG PREFIX str, ##args); \
210 } while (0)
212 #define UDIA_STREAM(str, args...) \
213 do { \
214 if (log_level & MICRODIA_STREAM) \
215 printk(KERN_DEBUG PREFIX str, ##args); \
216 } while (0)
219 * @enum T_MICRODIA_VIDEOMODE Video feature supported by camera
221 typedef enum {
222 MICRODIA_VGA, /**< For VGA video camera */
223 MICRODIA_SXGA, /**< For SXGA video camera 1.3M */
224 MICRODIA_UXGA /**< For UXGA video camera 2M */
225 } T_MICRODIA_VIDEOMODE;
227 enum microdia_buffer_state {
228 MICRODIA_BUF_STATE_IDLE = 0,
229 MICRODIA_BUF_STATE_QUEUED = 1,
230 MICRODIA_BUF_STATE_ACTIVE = 2,
231 MICRODIA_BUF_STATE_DONE = 3,
232 MICRODIA_BUF_STATE_ERROR = 4,
235 enum microdia_mode {
236 MICRODIA_MODE_IDLE = 0,
237 MICRODIA_MODE_READ = 1,
238 MICRODIA_MODE_STREAM = 2,
241 struct microdia_buffer {
242 unsigned long vma_use_count;
243 struct list_head stream;
245 /* Touched by interrupt handler. */
246 struct v4l2_buffer buf;
247 struct list_head queue;
248 wait_queue_head_t wait;
249 enum microdia_buffer_state state;
252 struct microdia_video_queue {
253 void *mem;
254 void *scratch;
255 unsigned int streaming : 1,
256 frozen : 1,
257 drop_incomplete : 1;
258 __u32 sequence;
260 unsigned int count;
261 unsigned int min_buffers;
262 unsigned int max_buffers;
263 unsigned int buf_size;
264 unsigned int frame_size; /*current frame size */
265 struct microdia_buffer *buffer;
266 struct microdia_buffer *read_buffer;
267 struct mutex mutex; /* protects buffers and mainqueue */
268 spinlock_t irqlock; /* protects irqqueue */
270 struct list_head mainqueue;
271 struct list_head irqqueue;
276 * @struct microdia_iso_buf
278 struct microdia_iso_buf {
279 void *data;
280 struct urb *urb;
284 * @struct microdia_video
286 struct microdia_video {
287 struct v4l2_pix_format format;
288 int fps; /**< FPS setting */
289 int brightness; /**< Brightness setting */
290 int contrast; /**< Contrast setting */
291 int whiteness; /**< Whiteness setting */
292 int colour; /**< Colour setting */
293 int hue; /**< Hue setting */
294 int hflip; /**< Horizontal flip */
295 int vflip; /**< Vertical flip */
296 int exposure; /**< Exposure */
297 int sharpness; /**< Sharpness */
298 __u8 rgb_gain[4]; /**< RGB Gain (RGGB) */
299 int auto_exposure; /**< Automatic exposure */
300 int auto_whitebalance; /**< Automatic whitebalance */
304 * @struct microdia_debugfs
306 struct microdia_debugfs {
307 struct dentry *dent_device;
308 struct dentry *dent_bridge_addr;
309 struct dentry *dent_bridge_val;
310 struct dentry *dent_bridge_dump;
311 struct dentry *dent_sensor_addr;
312 struct dentry *dent_sensor_val8;
313 struct dentry *dent_sensor_val16;
314 struct dentry *dent_sensor_val32;
316 __u16 bridge_addr; /**< Current bridge register address */
317 __u8 sensor_addr; /**< Current sensor register address */
321 * @struct usb_microdia
323 struct usb_microdia {
324 struct video_device *vdev; /**< Pointer on a V4L2 video device */
325 struct usb_device *udev; /**< Pointer on a USB device */
326 struct usb_interface *interface; /**< Pointer on a USB interface */
328 int release; /**< Release of the device (bcdDevice) */
329 __u32 webcam_model; /**< Model of video camera device */
330 __u8 webcam_type; /**< Type of camera : VGA, SXGA (1.3M), UXGA (2M) */
332 int frame_size_divisor; /**> Used to calculate frame_size */
334 __u8 sensor_slave_address; /**< I2C/SCCB slave address of the image sensor */
335 __u8 sensor_flags; /**< I2C/SCCB flags 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 struct microdia_video vsettings; /**< Video settings (brightness, whiteness...) */
345 struct microdia_debugfs debug; /**< debugfs information structure */
347 struct kref vopen; /**< Video status (Opened or Closed) */
348 struct file *owner; /**< file handler of stream owner */
349 enum microdia_mode mode;/**< camera mode */
351 int vframes_overflow; /**< Buffer overflow frames */
352 int vframes_incomplete; /**< Incomplete frames */
353 int vframes_dropped; /**< Dropped frames */
355 struct mutex mutex; /**< Mutex */
357 struct microdia_iso_buf isobuf[MAX_ISO_BUFS];
359 int resolution;
361 struct microdia_video_queue queue;
363 __u8 supported_fmts;
365 int (* initialize) (struct usb_microdia *dev);
366 int (*sensor_init) (struct usb_microdia *dev);
367 int (* start_stream) (struct usb_microdia *dev);
368 int (* stop_stream) (struct usb_microdia *dev);
369 int (* set_contrast) (struct usb_microdia *dev);
370 int (* set_brightness) (struct usb_microdia *dev);
371 int (* set_gamma) (struct usb_microdia *dev);
372 int (* set_exposure) (struct usb_microdia *dev);
373 int (* flip_detect) (struct usb_microdia *dev);
374 int (* set_hvflip) (struct usb_microdia *dev);
375 int (* set_sharpness) (struct usb_microdia *dev);
376 int (*set_rgb_gain) (struct usb_microdia *dev);
377 int (* set_auto_exposure) (struct usb_microdia *dev);
378 int (* set_auto_whitebalance) (struct usb_microdia *dev);
381 struct microdia_camera {
383 __u32 model; /**< Model of video camera device */
384 __u8 type; /**< Type of camera : VGA, SXGA, UXGA */
385 __u8 supported_fmts;
386 __u8 sensor_slave_address;
387 __u8 sensor_flags;
389 int (*initialize) (struct usb_microdia *dev);
390 int (*sensor_init) (struct usb_microdia *dev);
391 int (*start_stream) (struct usb_microdia *dev);
392 int (*stop_stream) (struct usb_microdia *dev);
393 int (*set_contrast) (struct usb_microdia *dev);
394 int (*set_brightness) (struct usb_microdia *dev);
395 int (*set_gamma) (struct usb_microdia *dev);
396 int (*set_exposure) (struct usb_microdia *dev);
397 int (*flip_detect) (struct usb_microdia *dev);
398 int (*set_hvflip) (struct usb_microdia *dev);
399 int (*set_sharpness) (struct usb_microdia *dev);
400 int (*set_rgb_gain) (struct usb_microdia *dev);
401 int (*set_auto_exposure) (struct usb_microdia *dev);
402 int (*set_auto_whitebalance) (struct usb_microdia *dev);
406 * @def MICRODIA_PERCENT
407 * Calculate a value from a percent
409 #define MICRODIA_PERCENT(x,y) ( ((int)x * (int)y) / 100)
413 * @def to_microdia_dev(d)
414 * Cast a member of a structure out to the containing structure
416 #define to_microdia_dev(d) container_of(d, struct usb_microdia, kref)
418 extern struct mutex open_lock;
420 int usb_microdia_control_write(struct usb_microdia *, __u16, __u8 *, __u16);
421 int usb_microdia_control_write_multi(struct usb_microdia *, __u16*, __u8 *,
422 __u16, __u16);
423 int usb_microdia_control_read(struct usb_microdia *, __u16, __u8 *, __u16);
424 int usb_microdia_set_feature(struct usb_microdia *, int);
426 int usb_microdia_set_configuration(struct usb_microdia *);
427 int usb_microdia_isoc_init(struct usb_microdia *);
428 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
429 void usb_microdia_isoc_handler(struct urb *, struct pt_regs *);
430 #else
431 void usb_microdia_isoc_handler(struct urb *);
432 #endif
433 void usb_microdia_isoc_cleanup(struct usb_microdia *);
434 void usb_microdia_delete(struct kref *);
437 int dev_microdia_initialize_device(struct usb_microdia *);
438 int dev_microdia_start_stream(struct usb_microdia *);
439 int dev_microdia_stop_stream(struct usb_microdia *);
440 int dev_microdia_check_device(struct usb_microdia *, int);
441 int dev_microdia_camera_on(struct usb_microdia *);
442 int dev_microdia_camera_off(struct usb_microdia *);
443 int dev_microdia_camera_asleep(struct usb_microdia *);
444 int dev_microdia_init_camera(struct usb_microdia *);
445 int dev_microdia_reconf_camera(struct usb_microdia *);
446 int dev_microdia_camera_settings(struct usb_microdia *);
447 int dev_microdia_camera_set_contrast(struct usb_microdia *);
448 int dev_microdia_camera_set_brightness(struct usb_microdia *);
449 int dev_microdia_camera_set_gamma(struct usb_microdia *);
450 int dev_microdia_camera_set_exposure(struct usb_microdia *);
451 int dev_microdia_camera_set_hvflip(struct usb_microdia *);
452 int dev_microdia_camera_set_sharpness(struct usb_microdia *dev);
453 int dev_microdia_camera_set_rgb_gain(struct usb_microdia *dev);
454 int dev_microdia_camera_set_auto_exposure(struct usb_microdia *dev);
455 int dev_microdia_camera_set_auto_whitebalance(struct usb_microdia *dev);
456 //int dev_microdia_set_camera_quality(struct usb_microdia *);
457 int dev_microdia_set_camera_fps(struct usb_microdia *);
459 struct v4l2_pix_format *v4l2_enum_supported_formats(struct usb_microdia *,
460 __u8);
461 int v4l_microdia_select_video_mode(struct usb_microdia *, int);
462 int v4l_microdia_register_video_device(struct usb_microdia *);
463 int v4l_microdia_unregister_video_device(struct usb_microdia *);
465 int microdia_create_sysfs_files(struct video_device *);
466 void microdia_remove_sysfs_files(struct video_device *);
468 void microdia_init_debugfs(void);
469 void microdia_uninit_debugfs(void);
470 int microdia_create_debugfs_files(struct usb_microdia *);
471 int microdia_remove_debugfs_files(struct usb_microdia *);
473 void microdia_queue_init(struct microdia_video_queue *);
474 int microdia_alloc_buffers(struct microdia_video_queue *,
475 unsigned int, unsigned int);
476 int microdia_free_buffers(struct microdia_video_queue *);
477 int microdia_queue_enable(struct microdia_video_queue *, int);
478 void microdia_queue_cancel(struct microdia_video_queue *);
479 unsigned int microdia_queue_poll(struct microdia_video_queue *,
480 struct file *, poll_table *);
481 int microdia_query_buffer(struct microdia_video_queue *, struct v4l2_buffer *);
482 int microdia_queue_buffer(struct microdia_video_queue *, struct v4l2_buffer *);
483 int microdia_dequeue_buffer(struct microdia_video_queue *,
484 struct v4l2_buffer *, int);
485 struct microdia_buffer *microdia_queue_next_buffer(
486 struct microdia_video_queue *, struct microdia_buffer *);
488 int microdia_decompress(struct usb_microdia *, struct v4l2_buffer *);
489 #endif