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