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/videodev2.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/v4l2-device.h>
37#include <media/ovcamchip.h>
38
39#include "w9968cf_vpp.h"
40
41
42
43
44
45
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.34-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 enum w9968cf_model_id id;
199
200 struct v4l2_device v4l2_dev;
201 struct video_device* v4ldev;
202 struct list_head v4llist;
203
204 struct usb_device* usbdev;
205 struct urb* urb[W9968CF_URBS];
206 void* transfer_buffer[W9968CF_URBS];
207 u16* control_buffer;
208 u16* data_buffer;
209
210 struct w9968cf_frame_t frame[W9968CF_MAX_BUFFERS];
211 struct w9968cf_frame_t frame_tmp;
212 struct w9968cf_frame_t frame_vpp;
213 struct w9968cf_frame_t* frame_current;
214 struct w9968cf_frame_t* requested_frame[W9968CF_MAX_BUFFERS];
215
216 u8 max_buffers,
217 force_palette,
218 force_rgb,
219 double_buffer,
220 clamping,
221 filter_type,
222 capture,
223 largeview,
224 decompression,
225 upscaling;
226
227 struct video_picture picture;
228 struct video_window window;
229
230 u16 hw_depth,
231 hw_palette,
232 hw_width,
233 hw_height,
234 hs_polarity,
235 vs_polarity,
236 start_cropx,
237 start_cropy;
238
239 enum w9968cf_vpp_flag vpp_flag;
240
241 u8 nbuffers,
242 altsetting,
243 disconnected,
244 misconfigured,
245 users,
246 streaming;
247
248 u8 sensor_initialized;
249
250
251 int sensor,
252 monochrome;
253 u16 maxwidth,
254 maxheight,
255 minwidth,
256 minheight;
257 u8 auto_brt,
258 auto_exp,
259 backlight,
260 mirror,
261 lightfreq,
262 bandfilt;
263 s8 clockdiv;
264
265
266 struct i2c_adapter i2c_adapter;
267 struct v4l2_subdev *sensor_sd;
268
269
270 struct mutex dev_mutex,
271 fileop_mutex;
272 spinlock_t urb_lock,
273 flist_lock;
274 wait_queue_head_t open, wait_queue;
275
276 char command[16];
277};
278
279static inline struct w9968cf_device *to_cam(struct v4l2_device *v4l2_dev)
280{
281 return container_of(v4l2_dev, struct w9968cf_device, v4l2_dev);
282}
283
284
285
286
287
288
289#undef DBG
290#undef KDBG
291#ifdef W9968CF_DEBUG
292
293# define DBG(level, fmt, args...) \
294{ \
295 if ( ((specific_debug) && (debug == (level))) || \
296 ((!specific_debug) && (debug >= (level))) ) { \
297 if ((level) == 1) \
298 v4l2_err(&cam->v4l2_dev, fmt "\n", ## args); \
299 else if ((level) == 2 || (level) == 3) \
300 v4l2_info(&cam->v4l2_dev, fmt "\n", ## args); \
301 else if ((level) == 4) \
302 v4l2_warn(&cam->v4l2_dev, fmt "\n", ## args); \
303 else if ((level) >= 5) \
304 v4l2_info(&cam->v4l2_dev, "[%s:%d] " fmt "\n", \
305 __func__, __LINE__ , ## args); \
306 } \
307}
308
309# define KDBG(level, fmt, args...) \
310{ \
311 if ( ((specific_debug) && (debug == (level))) || \
312 ((!specific_debug) && (debug >= (level))) ) { \
313 if ((level) >= 1 && (level) <= 4) \
314 pr_info("w9968cf: " fmt "\n", ## args); \
315 else if ((level) >= 5) \
316 pr_debug("w9968cf: [%s:%d] " fmt "\n", __func__, \
317 __LINE__ , ## args); \
318 } \
319}
320#else
321
322# define DBG(level, fmt, args...) do {;} while(0);
323# define KDBG(level, fmt, args...) do {;} while(0);
324#endif
325
326#undef PDBG
327#define PDBG(fmt, args...) \
328v4l2_info(&cam->v4l2_dev, "[%s:%d] " fmt "\n", __func__, __LINE__ , ## args);
329
330#undef PDBGG
331#define PDBGG(fmt, args...) do {;} while(0);
332
333#endif
334