This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / drivers / usb / media / sn9c102.h
1 /***************************************************************************
2  * V4L2 driver for SN9C10[12] PC Camera Controllers                        *
3  *                                                                         *
4  * Copyright (C) 2004 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  ***************************************************************************/
20
21 #ifndef _SN9C102_H_
22 #define _SN9C102_H_
23
24 #include <linux/version.h>
25 #include <linux/usb.h>
26 #include <linux/videodev.h>
27 #include <linux/device.h>
28 #include <linux/list.h>
29 #include <linux/spinlock.h>
30 #include <linux/wait.h>
31 #include <linux/types.h>
32 #include <linux/param.h>
33 #include <linux/rwsem.h>
34
35 #include "sn9c102_sensor.h"
36
37 /*****************************************************************************/
38
39 #define SN9C102_DEBUG
40 #define SN9C102_DEBUG_LEVEL       2
41 #define SN9C102_MAX_DEVICES       64
42 #define SN9C102_MAX_FRAMES        32
43 #define SN9C102_URBS              2
44 #define SN9C102_ISO_PACKETS       7
45 #define SN9C102_ALTERNATE_SETTING 8
46 #define SN9C102_CTRL_TIMEOUT      10*HZ
47
48 /*****************************************************************************/
49
50 #define SN9C102_MODULE_NAME  "V4L2 driver for SN9C10[12] PC Camera Controllers"
51 #define SN9C102_MODULE_AUTHOR   "(C) 2004 Luca Risolia"
52 #define SN9C102_AUTHOR_EMAIL    "<luca.risolia@studio.unibo.it>"
53 #define SN9C102_MODULE_LICENSE  "GPL"
54 #define SN9C102_MODULE_VERSION  "1:1.01-beta"
55 #define SN9C102_MODULE_VERSION_CODE  KERNEL_VERSION(1, 0, 1)
56
57 SN9C102_ID_TABLE;
58 SN9C102_SENSOR_TABLE;
59
60 enum sn9c102_frame_state {
61         F_UNUSED,
62         F_QUEUED,
63         F_GRABBING,
64         F_DONE,
65         F_ERROR,
66 };
67
68 struct sn9c102_frame_t {
69         void* bufmem;
70         struct v4l2_buffer buf;
71         enum sn9c102_frame_state state;
72         struct list_head frame;
73         unsigned long vma_use_count;
74 };
75
76 enum sn9c102_dev_state {
77         DEV_INITIALIZED = 0x01,
78         DEV_DISCONNECTED = 0x02,
79         DEV_MISCONFIGURED = 0x04,
80 };
81
82 enum sn9c102_io_method {
83         IO_NONE,
84         IO_READ,
85         IO_MMAP,
86 };
87
88 enum sn9c102_stream_state {
89         STREAM_OFF,
90         STREAM_INTERRUPT,
91         STREAM_ON,
92 };
93
94 struct sn9c102_sysfs_attr {
95         u8 reg, val, i2c_reg, i2c_val;
96 };
97
98 static DECLARE_MUTEX(sn9c102_sysfs_lock);
99 static DECLARE_RWSEM(sn9c102_disconnect);
100
101 struct sn9c102_device {
102         struct device dev;
103
104         struct video_device* v4ldev;
105
106         struct sn9c102_sensor* sensor;
107
108         struct usb_device* usbdev;
109         struct urb* urb[SN9C102_URBS];
110         void* transfer_buffer[SN9C102_URBS];
111         u8* control_buffer;
112
113         struct sn9c102_frame_t *frame_current, frame[SN9C102_MAX_FRAMES];
114         struct list_head inqueue, outqueue;
115         u32 frame_count, nbuffers;
116
117         enum sn9c102_io_method io;
118         enum sn9c102_stream_state stream;
119
120         struct sn9c102_sysfs_attr sysfs;
121         u16 reg[32];
122
123         enum sn9c102_dev_state state;
124         u8 users;
125
126         struct semaphore dev_sem, fileop_sem;
127         spinlock_t queue_lock;
128         wait_queue_head_t open, wait_frame, wait_stream;
129 };
130
131 /*****************************************************************************/
132
133 void
134 sn9c102_attach_sensor(struct sn9c102_device* cam,
135                       struct sn9c102_sensor* sensor)
136 {
137         cam->sensor = sensor;
138         cam->sensor->dev = &cam->dev;
139         cam->sensor->usbdev = cam->usbdev;
140 }
141
142 /*****************************************************************************/
143
144 #undef DBG
145 #undef KDBG
146 #ifdef SN9C102_DEBUG
147 #       define DBG(level, fmt, args...)                                       \
148 {                                                                             \
149         if (debug >= (level)) {                                               \
150                 if ((level) == 1)                                             \
151                         dev_err(&cam->dev, fmt "\n", ## args);                \
152                 else if ((level) == 2)                                        \
153                         dev_info(&cam->dev, fmt "\n", ## args);               \
154                 else if ((level) >= 3)                                        \
155                         dev_info(&cam->dev, "[%s:%d] " fmt "\n",              \
156                                  __FUNCTION__, __LINE__ , ## args);           \
157         }                                                                     \
158 }
159 #       define KDBG(level, fmt, args...)                                      \
160 {                                                                             \
161         if (debug >= (level)) {                                               \
162                 if ((level) == 1 || (level) == 2)                             \
163                         pr_info("sn9c102: " fmt "\n", ## args);               \
164                 else if ((level) == 3)                                        \
165                         pr_debug("sn9c102: [%s:%d] " fmt "\n", __FUNCTION__,  \
166                                  __LINE__ , ## args);                         \
167         }                                                                     \
168 }
169 #else
170 #       define KDBG(level, fmt, args...) do {;} while(0);
171 #       define DBG(level, fmt, args...) do {;} while(0);
172 #endif
173
174 #undef PDBG
175 #define PDBG(fmt, args...)                                                    \
176 dev_info(&cam->dev, "[%s:%d] " fmt "\n", __FUNCTION__, __LINE__ , ## args);
177
178 #undef PDBGG
179 #define PDBGG(fmt, args...) do {;} while(0); /* placeholder */
180
181 #endif /* _SN9C102_H_ */