[PATCH] USB: Add ZC0301 Video4Linux2 driver
[linux-2.6/verdex.git] / drivers / usb / media / zc0301.h
blob6fa5075f1e3d777a2a2093e02753b0d8c8e420f6
1 /***************************************************************************
2 * V4L2 driver for ZC0301 Image Processor and Control Chip *
3 * *
4 * Copyright (C) 2006 by Luca Risolia <luca.risolia@studio.unibo.it> *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
19 ***************************************************************************/
21 #ifndef _ZC0301_H_
22 #define _ZC0301_H_
24 #include <linux/version.h>
25 #include <linux/usb.h>
26 #include <linux/videodev2.h>
27 #include <media/v4l2-common.h>
28 #include <linux/device.h>
29 #include <linux/list.h>
30 #include <linux/spinlock.h>
31 #include <linux/time.h>
32 #include <linux/wait.h>
33 #include <linux/types.h>
34 #include <linux/param.h>
35 #include <linux/mutex.h>
36 #include <linux/rwsem.h>
37 #include <asm/semaphore.h>
39 #include "zc0301_sensor.h"
41 /*****************************************************************************/
43 #define ZC0301_DEBUG
44 #define ZC0301_DEBUG_LEVEL 2
45 #define ZC0301_MAX_DEVICES 64
46 #define ZC0301_FORCE_MUNMAP 0
47 #define ZC0301_MAX_FRAMES 32
48 #define ZC0301_COMPRESSION_QUALITY 2
49 #define ZC0301_URBS 2
50 #define ZC0301_ISO_PACKETS 7
51 #define ZC0301_ALTERNATE_SETTING 7
52 #define ZC0301_URB_TIMEOUT msecs_to_jiffies(2 * ZC0301_ISO_PACKETS)
53 #define ZC0301_CTRL_TIMEOUT 100
54 #define ZC0301_FRAME_TIMEOUT 2 * 1000 * msecs_to_jiffies(1)
56 /*****************************************************************************/
58 ZC0301_ID_TABLE
59 ZC0301_SENSOR_TABLE
61 enum zc0301_frame_state {
62 F_UNUSED,
63 F_QUEUED,
64 F_GRABBING,
65 F_DONE,
66 F_ERROR,
69 struct zc0301_frame_t {
70 void* bufmem;
71 struct v4l2_buffer buf;
72 enum zc0301_frame_state state;
73 struct list_head frame;
74 unsigned long vma_use_count;
77 enum zc0301_dev_state {
78 DEV_INITIALIZED = 0x01,
79 DEV_DISCONNECTED = 0x02,
80 DEV_MISCONFIGURED = 0x04,
83 enum zc0301_io_method {
84 IO_NONE,
85 IO_READ,
86 IO_MMAP,
89 enum zc0301_stream_state {
90 STREAM_OFF,
91 STREAM_INTERRUPT,
92 STREAM_ON,
95 struct zc0301_module_param {
96 u8 force_munmap;
99 static DECLARE_RWSEM(zc0301_disconnect);
101 struct zc0301_device {
102 struct video_device* v4ldev;
104 struct zc0301_sensor* sensor;
106 struct usb_device* usbdev;
107 struct urb* urb[ZC0301_URBS];
108 void* transfer_buffer[ZC0301_URBS];
109 u8* control_buffer;
111 struct zc0301_frame_t *frame_current, frame[ZC0301_MAX_FRAMES];
112 struct list_head inqueue, outqueue;
113 u32 frame_count, nbuffers, nreadbuffers;
115 enum zc0301_io_method io;
116 enum zc0301_stream_state stream;
118 struct v4l2_jpegcompression compression;
120 struct zc0301_module_param module_param;
122 enum zc0301_dev_state state;
123 u8 users;
125 struct mutex dev_mutex, fileop_mutex;
126 spinlock_t queue_lock;
127 wait_queue_head_t open, wait_frame, wait_stream;
130 /*****************************************************************************/
132 void
133 zc0301_attach_sensor(struct zc0301_device* cam, struct zc0301_sensor* sensor)
135 cam->sensor = sensor;
136 cam->sensor->usbdev = cam->usbdev;
139 /*****************************************************************************/
141 #undef DBG
142 #undef KDBG
143 #ifdef ZC0301_DEBUG
144 # define DBG(level, fmt, args...) \
145 do { \
146 if (debug >= (level)) { \
147 if ((level) == 1) \
148 dev_err(&cam->usbdev->dev, fmt "\n", ## args); \
149 else if ((level) == 2) \
150 dev_info(&cam->usbdev->dev, fmt "\n", ## args); \
151 else if ((level) >= 3) \
152 dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \
153 __FUNCTION__, __LINE__ , ## args); \
155 } while (0)
156 # define KDBG(level, fmt, args...) \
157 do { \
158 if (debug >= (level)) { \
159 if ((level) == 1 || (level) == 2) \
160 pr_info("zc0301: " fmt "\n", ## args); \
161 else if ((level) == 3) \
162 pr_debug("zc0301: [%s:%d] " fmt "\n", __FUNCTION__, \
163 __LINE__ , ## args); \
165 } while (0)
166 # define V4LDBG(level, name, cmd) \
167 do { \
168 if (debug >= (level)) \
169 v4l_print_ioctl(name, cmd); \
170 } while (0)
171 #else
172 # define DBG(level, fmt, args...) do {;} while(0)
173 # define KDBG(level, fmt, args...) do {;} while(0)
174 # define V4LDBG(level, name, cmd) do {;} while(0)
175 #endif
177 #undef PDBG
178 #define PDBG(fmt, args...) \
179 dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \
180 __FUNCTION__, __LINE__ , ## args)
182 #undef PDBGG
183 #define PDBGG(fmt, args...) do {;} while(0) /* placeholder */
185 #endif /* _ZC0301_H_ */