1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#ifndef _W9968CF_H_
22#define _W9968CF_H_
23
24#include <linux/videodev.h>
25#include <linux/usb.h>
26#include <linux/i2c.h>
27#include <linux/device.h>
28#include <linux/spinlock.h>
29#include <linux/list.h>
30#include <linux/wait.h>
31#include <linux/param.h>
32#include <linux/types.h>
33#include <linux/rwsem.h>
34#include <linux/mutex.h>
35
36#include <media/ovcamchip.h>
37
38#include "w9968cf_vpp.h"
39
40
41
42
43
44
45#define W9968CF_OVMOD_LOAD 1
46#define W9968CF_VPPMOD_LOAD 1
47
48
49#define W9968CF_DEBUG
50
51
52#define W9968CF_DEBUG_LEVEL 2
53#define W9968CF_SPECIFIC_DEBUG 0
54
55#define W9968CF_MAX_DEVICES 32
56#define W9968CF_SIMCAMS W9968CF_MAX_DEVICES
57
58#define W9968CF_MAX_BUFFERS 32
59#define W9968CF_BUFFERS 2
60
61
62static const u16 wMaxPacketSize[] = {1023, 959, 895, 831, 767, 703, 639, 575,
63 511, 447, 383, 319, 255, 191, 127, 63};
64#define W9968CF_PACKET_SIZE 1023
65#define W9968CF_MIN_PACKET_SIZE 63
66#define W9968CF_ISO_PACKETS 5
67#define W9968CF_USB_CTRL_TIMEOUT 1000
68#define W9968CF_URBS 2
69
70#define W9968CF_I2C_BUS_DELAY 4
71#define W9968CF_I2C_RW_RETRIES 15
72
73
74struct w9968cf_format {
75 const u16 palette;
76 const u16 depth;
77 const u8 compression;
78};
79
80static const struct w9968cf_format w9968cf_formatlist[] = {
81 { VIDEO_PALETTE_UYVY, 16, 0 },
82 { VIDEO_PALETTE_YUV422P, 16, 1 },
83 { VIDEO_PALETTE_YUV420P, 12, 1 },
84 { VIDEO_PALETTE_YUV420, 12, 1 },
85 { VIDEO_PALETTE_YUYV, 16, 0 },
86 { VIDEO_PALETTE_YUV422, 16, 0 },
87 { VIDEO_PALETTE_GREY, 8, 0 },
88 { VIDEO_PALETTE_RGB555, 16, 0 },
89 { VIDEO_PALETTE_RGB565, 16, 0 },
90 { VIDEO_PALETTE_RGB24, 24, 0 },
91 { VIDEO_PALETTE_RGB32, 32, 0 },
92 { 0, 0, 0 }
93};
94
95#define W9968CF_DECOMPRESSION 2
96#define W9968CF_PALETTE_DECOMP_OFF VIDEO_PALETTE_UYVY
97#define W9968CF_PALETTE_DECOMP_FORCE VIDEO_PALETTE_YUV420P
98#define W9968CF_PALETTE_DECOMP_ON VIDEO_PALETTE_UYVY
99
100#define W9968CF_FORCE_RGB 0
101
102#define W9968CF_MAX_WIDTH 800
103#define W9968CF_MAX_HEIGHT 600
104#define W9968CF_WIDTH 320
105#define W9968CF_HEIGHT 240
106
107#define W9968CF_CLAMPING 0
108#define W9968CF_FILTER_TYPE 0
109#define W9968CF_DOUBLE_BUFFER 1
110#define W9968CF_LARGEVIEW 1
111#define W9968CF_UPSCALING 0
112
113#define W9968CF_MONOCHROME 0
114#define W9968CF_BRIGHTNESS 31000
115#define W9968CF_HUE 32768
116#define W9968CF_COLOUR 32768
117#define W9968CF_CONTRAST 50000
118#define W9968CF_WHITENESS 32768
119
120#define W9968CF_AUTOBRIGHT 0
121#define W9968CF_AUTOEXP 1
122#define W9968CF_LIGHTFREQ 50
123#define W9968CF_BANDINGFILTER 0
124#define W9968CF_BACKLIGHT 0
125#define W9968CF_MIRROR 0
126
127#define W9968CF_CLOCKDIV -1
128#define W9968CF_DEF_CLOCKDIVISOR 0
129
130
131
132
133
134
135#define W9968CF_MODULE_NAME "V4L driver for W996[87]CF JPEG USB " \
136 "Dual Mode Camera Chip"
137#define W9968CF_MODULE_VERSION "1:1.33-basic"
138#define W9968CF_MODULE_AUTHOR "(C) 2002-2004 Luca Risolia"
139#define W9968CF_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>"
140#define W9968CF_MODULE_LICENSE "GPL"
141
142static const struct usb_device_id winbond_id_table[] = {
143 {
144
145 USB_DEVICE(0x041e, 0x4003),
146 .driver_info = (unsigned long)"w9968cf",
147 },
148 {
149
150 USB_DEVICE(0x1046, 0x9967),
151 .driver_info = (unsigned long)"w9968cf",
152 },
153 { }
154};
155
156
157enum w9968cf_model_id {
158 W9968CF_MOD_GENERIC = 1,
159 W9968CF_MOD_CLVBWGP = 11,
160 W9968CF_MOD_ADPVDMA = 21,
161 W9986CF_MOD_AAU = 31,
162 W9968CF_MOD_CLVBWG = 34,
163 W9968CF_MOD_LL = 37,
164 W9968CF_MOD_EEEMC = 40,
165 W9968CF_MOD_OOE = 42,
166 W9968CF_MOD_ODPVDMPC = 43,
167 W9968CF_MOD_PDPII = 46,
168 W9968CF_MOD_PDP480 = 49,
169};
170
171enum w9968cf_frame_status {
172 F_READY,
173 F_GRABBING,
174 F_ERROR,
175 F_UNUSED
176};
177
178struct w9968cf_frame_t {
179 void* buffer;
180 unsigned long size;
181 u32 length;
182 int number;
183 enum w9968cf_frame_status status;
184 struct w9968cf_frame_t* next;
185 u8 queued;
186};
187
188enum w9968cf_vpp_flag {
189 VPP_NONE = 0x00,
190 VPP_UPSCALE = 0x01,
191 VPP_SWAP_YUV_BYTES = 0x02,
192 VPP_DECOMPRESSION = 0x04,
193 VPP_UYVY_TO_RGBX = 0x08,
194};
195
196
197struct w9968cf_device {
198 struct device dev;
199
200 enum w9968cf_model_id id;
201
202 struct video_device* v4ldev;
203 struct list_head v4llist;
204
205 struct usb_device* usbdev;
206 struct urb* urb[W9968CF_URBS];
207 void* transfer_buffer[W9968CF_URBS];
208 u16* control_buffer;
209 u16* data_buffer;
210
211 struct w9968cf_frame_t frame[W9968CF_MAX_BUFFERS];
212 struct w9968cf_frame_t frame_tmp;
213 struct w9968cf_frame_t frame_vpp;
214 struct w9968cf_frame_t* frame_current;
215 struct w9968cf_frame_t* requested_frame[W9968CF_MAX_BUFFERS];
216
217 u8 max_buffers,
218 force_palette,
219 force_rgb,
220 double_buffer,
221 clamping,
222 filter_type,
223 capture,
224 largeview,
225 decompression,
226 upscaling;
227
228 struct video_picture picture;
229 struct video_window window;
230
231 u16 hw_depth,
232 hw_palette,
233 hw_width,
234 hw_height,
235 hs_polarity,
236 vs_polarity,
237 start_cropx,
238 start_cropy;
239
240 enum w9968cf_vpp_flag vpp_flag;
241
242 u8 nbuffers,
243 altsetting,
244 disconnected,
245 misconfigured,
246 users,
247 streaming;
248
249 u8 sensor_initialized;
250
251
252 int sensor,
253 monochrome;
254 u16 maxwidth,
255 maxheight,
256 minwidth,
257 minheight;
258 u8 auto_brt,
259 auto_exp,
260 backlight,
261 mirror,
262 lightfreq,
263 bandfilt;
264 s8 clockdiv;
265
266
267 struct i2c_adapter i2c_adapter;
268 struct i2c_client* sensor_client;
269
270
271 struct mutex dev_mutex,
272 fileop_mutex;
273 spinlock_t urb_lock,
274 flist_lock;
275 wait_queue_head_t open, wait_queue;
276
277 char command[16];
278};
279
280
281
282
283
284
285#undef DBG
286#undef KDBG
287#ifdef W9968CF_DEBUG
288
289# define DBG(level, fmt, args...) \
290{ \
291 if ( ((specific_debug) && (debug == (level))) || \
292 ((!specific_debug) && (debug >= (level))) ) { \
293 if ((level) == 1) \
294 dev_err(&cam->dev, fmt "\n", ## args); \
295 else if ((level) == 2 || (level) == 3) \
296 dev_info(&cam->dev, fmt "\n", ## args); \
297 else if ((level) == 4) \
298 dev_warn(&cam->dev, fmt "\n", ## args); \
299 else if ((level) >= 5) \
300 dev_info(&cam->dev, "[%s:%d] " fmt "\n", \
301 __FUNCTION__, __LINE__ , ## args); \
302 } \
303}
304
305# define KDBG(level, fmt, args...) \
306{ \
307 if ( ((specific_debug) && (debug == (level))) || \
308 ((!specific_debug) && (debug >= (level))) ) { \
309 if ((level) >= 1 && (level) <= 4) \
310 pr_info("w9968cf: " fmt "\n", ## args); \
311 else if ((level) >= 5) \
312 pr_debug("w9968cf: [%s:%d] " fmt "\n", __FUNCTION__, \
313 __LINE__ , ## args); \
314 } \
315}
316#else
317
318# define DBG(level, fmt, args...) do {;} while(0);
319# define KDBG(level, fmt, args...) do {;} while(0);
320#endif
321
322#undef PDBG
323#define PDBG(fmt, args...) \
324dev_info(&cam->dev, "[%s:%d] " fmt "\n", __FUNCTION__, __LINE__ , ## args);
325
326#undef PDBGG
327#define PDBGG(fmt, args...) do {;} while(0);
328
329#endif
330