diff options
Diffstat (limited to 'drivers/media/video/et61x251/et61x251.h')
-rw-r--r-- | drivers/media/video/et61x251/et61x251.h | 234 |
1 files changed, 234 insertions, 0 deletions
diff --git a/drivers/media/video/et61x251/et61x251.h b/drivers/media/video/et61x251/et61x251.h new file mode 100644 index 000000000000..eee8afc9be72 --- /dev/null +++ b/drivers/media/video/et61x251/et61x251.h | |||
@@ -0,0 +1,234 @@ | |||
1 | /*************************************************************************** | ||
2 | * V4L2 driver for ET61X[12]51 PC Camera Controllers * | ||
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 | ***************************************************************************/ | ||
20 | |||
21 | #ifndef _ET61X251_H_ | ||
22 | #define _ET61X251_H_ | ||
23 | |||
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/rwsem.h> | ||
36 | #include <linux/mutex.h> | ||
37 | #include <linux/stddef.h> | ||
38 | #include <linux/string.h> | ||
39 | |||
40 | #include "et61x251_sensor.h" | ||
41 | |||
42 | /*****************************************************************************/ | ||
43 | |||
44 | #define ET61X251_DEBUG | ||
45 | #define ET61X251_DEBUG_LEVEL 2 | ||
46 | #define ET61X251_MAX_DEVICES 64 | ||
47 | #define ET61X251_PRESERVE_IMGSCALE 0 | ||
48 | #define ET61X251_FORCE_MUNMAP 0 | ||
49 | #define ET61X251_MAX_FRAMES 32 | ||
50 | #define ET61X251_COMPRESSION_QUALITY 0 | ||
51 | #define ET61X251_URBS 2 | ||
52 | #define ET61X251_ISO_PACKETS 7 | ||
53 | #define ET61X251_ALTERNATE_SETTING 13 | ||
54 | #define ET61X251_URB_TIMEOUT msecs_to_jiffies(2 * ET61X251_ISO_PACKETS) | ||
55 | #define ET61X251_CTRL_TIMEOUT 100 | ||
56 | #define ET61X251_FRAME_TIMEOUT 2 | ||
57 | |||
58 | /*****************************************************************************/ | ||
59 | |||
60 | static const struct usb_device_id et61x251_id_table[] = { | ||
61 | { USB_DEVICE(0x102c, 0x6151), }, | ||
62 | { USB_DEVICE(0x102c, 0x6251), }, | ||
63 | { USB_DEVICE(0x102c, 0x6253), }, | ||
64 | { USB_DEVICE(0x102c, 0x6254), }, | ||
65 | { USB_DEVICE(0x102c, 0x6255), }, | ||
66 | { USB_DEVICE(0x102c, 0x6256), }, | ||
67 | { USB_DEVICE(0x102c, 0x6257), }, | ||
68 | { USB_DEVICE(0x102c, 0x6258), }, | ||
69 | { USB_DEVICE(0x102c, 0x6259), }, | ||
70 | { USB_DEVICE(0x102c, 0x625a), }, | ||
71 | { USB_DEVICE(0x102c, 0x625b), }, | ||
72 | { USB_DEVICE(0x102c, 0x625c), }, | ||
73 | { USB_DEVICE(0x102c, 0x625d), }, | ||
74 | { USB_DEVICE(0x102c, 0x625e), }, | ||
75 | { USB_DEVICE(0x102c, 0x625f), }, | ||
76 | { USB_DEVICE(0x102c, 0x6260), }, | ||
77 | { USB_DEVICE(0x102c, 0x6261), }, | ||
78 | { USB_DEVICE(0x102c, 0x6262), }, | ||
79 | { USB_DEVICE(0x102c, 0x6263), }, | ||
80 | { USB_DEVICE(0x102c, 0x6264), }, | ||
81 | { USB_DEVICE(0x102c, 0x6265), }, | ||
82 | { USB_DEVICE(0x102c, 0x6266), }, | ||
83 | { USB_DEVICE(0x102c, 0x6267), }, | ||
84 | { USB_DEVICE(0x102c, 0x6268), }, | ||
85 | { USB_DEVICE(0x102c, 0x6269), }, | ||
86 | { } | ||
87 | }; | ||
88 | |||
89 | ET61X251_SENSOR_TABLE | ||
90 | |||
91 | /*****************************************************************************/ | ||
92 | |||
93 | enum et61x251_frame_state { | ||
94 | F_UNUSED, | ||
95 | F_QUEUED, | ||
96 | F_GRABBING, | ||
97 | F_DONE, | ||
98 | F_ERROR, | ||
99 | }; | ||
100 | |||
101 | struct et61x251_frame_t { | ||
102 | void* bufmem; | ||
103 | struct v4l2_buffer buf; | ||
104 | enum et61x251_frame_state state; | ||
105 | struct list_head frame; | ||
106 | unsigned long vma_use_count; | ||
107 | }; | ||
108 | |||
109 | enum et61x251_dev_state { | ||
110 | DEV_INITIALIZED = 0x01, | ||
111 | DEV_DISCONNECTED = 0x02, | ||
112 | DEV_MISCONFIGURED = 0x04, | ||
113 | }; | ||
114 | |||
115 | enum et61x251_io_method { | ||
116 | IO_NONE, | ||
117 | IO_READ, | ||
118 | IO_MMAP, | ||
119 | }; | ||
120 | |||
121 | enum et61x251_stream_state { | ||
122 | STREAM_OFF, | ||
123 | STREAM_INTERRUPT, | ||
124 | STREAM_ON, | ||
125 | }; | ||
126 | |||
127 | struct et61x251_sysfs_attr { | ||
128 | u8 reg, i2c_reg; | ||
129 | }; | ||
130 | |||
131 | struct et61x251_module_param { | ||
132 | u8 force_munmap; | ||
133 | u16 frame_timeout; | ||
134 | }; | ||
135 | |||
136 | static DEFINE_MUTEX(et61x251_sysfs_lock); | ||
137 | static DECLARE_RWSEM(et61x251_disconnect); | ||
138 | |||
139 | struct et61x251_device { | ||
140 | struct video_device* v4ldev; | ||
141 | |||
142 | struct et61x251_sensor sensor; | ||
143 | |||
144 | struct usb_device* usbdev; | ||
145 | struct urb* urb[ET61X251_URBS]; | ||
146 | void* transfer_buffer[ET61X251_URBS]; | ||
147 | u8* control_buffer; | ||
148 | |||
149 | struct et61x251_frame_t *frame_current, frame[ET61X251_MAX_FRAMES]; | ||
150 | struct list_head inqueue, outqueue; | ||
151 | u32 frame_count, nbuffers, nreadbuffers; | ||
152 | |||
153 | enum et61x251_io_method io; | ||
154 | enum et61x251_stream_state stream; | ||
155 | |||
156 | struct v4l2_jpegcompression compression; | ||
157 | |||
158 | struct et61x251_sysfs_attr sysfs; | ||
159 | struct et61x251_module_param module_param; | ||
160 | |||
161 | enum et61x251_dev_state state; | ||
162 | u8 users; | ||
163 | |||
164 | struct mutex dev_mutex, fileop_mutex; | ||
165 | spinlock_t queue_lock; | ||
166 | wait_queue_head_t open, wait_frame, wait_stream; | ||
167 | }; | ||
168 | |||
169 | /*****************************************************************************/ | ||
170 | |||
171 | struct et61x251_device* | ||
172 | et61x251_match_id(struct et61x251_device* cam, const struct usb_device_id *id) | ||
173 | { | ||
174 | if (usb_match_id(usb_ifnum_to_if(cam->usbdev, 0), id)) | ||
175 | return cam; | ||
176 | |||
177 | return NULL; | ||
178 | } | ||
179 | |||
180 | |||
181 | void | ||
182 | et61x251_attach_sensor(struct et61x251_device* cam, | ||
183 | struct et61x251_sensor* sensor) | ||
184 | { | ||
185 | memcpy(&cam->sensor, sensor, sizeof(struct et61x251_sensor)); | ||
186 | } | ||
187 | |||
188 | /*****************************************************************************/ | ||
189 | |||
190 | #undef DBG | ||
191 | #undef KDBG | ||
192 | #ifdef ET61X251_DEBUG | ||
193 | # define DBG(level, fmt, args...) \ | ||
194 | do { \ | ||
195 | if (debug >= (level)) { \ | ||
196 | if ((level) == 1) \ | ||
197 | dev_err(&cam->usbdev->dev, fmt "\n", ## args); \ | ||
198 | else if ((level) == 2) \ | ||
199 | dev_info(&cam->usbdev->dev, fmt "\n", ## args); \ | ||
200 | else if ((level) >= 3) \ | ||
201 | dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \ | ||
202 | __FUNCTION__, __LINE__ , ## args); \ | ||
203 | } \ | ||
204 | } while (0) | ||
205 | # define KDBG(level, fmt, args...) \ | ||
206 | do { \ | ||
207 | if (debug >= (level)) { \ | ||
208 | if ((level) == 1 || (level) == 2) \ | ||
209 | pr_info("et61x251: " fmt "\n", ## args); \ | ||
210 | else if ((level) == 3) \ | ||
211 | pr_debug("et61x251: [%s:%d] " fmt "\n", __FUNCTION__, \ | ||
212 | __LINE__ , ## args); \ | ||
213 | } \ | ||
214 | } while (0) | ||
215 | # define V4LDBG(level, name, cmd) \ | ||
216 | do { \ | ||
217 | if (debug >= (level)) \ | ||
218 | v4l_print_ioctl(name, cmd); \ | ||
219 | } while (0) | ||
220 | #else | ||
221 | # define DBG(level, fmt, args...) do {;} while(0) | ||
222 | # define KDBG(level, fmt, args...) do {;} while(0) | ||
223 | # define V4LDBG(level, name, cmd) do {;} while(0) | ||
224 | #endif | ||
225 | |||
226 | #undef PDBG | ||
227 | #define PDBG(fmt, args...) \ | ||
228 | dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \ | ||
229 | __FUNCTION__, __LINE__ , ## args) | ||
230 | |||
231 | #undef PDBGG | ||
232 | #define PDBGG(fmt, args...) do {;} while(0) /* placeholder */ | ||
233 | |||
234 | #endif /* _ET61X251_H_ */ | ||