xref: /openbmc/linux/drivers/media/usb/gspca/spca506.c (revision 174cd4b1)
1 /*
2  * SPCA506 chip based cameras function
3  * M Xhaard 15/04/2004 based on different work Mark Taylor and others
4  * and my own snoopy file on a pv-321c donate by a german compagny
5  *                "Firma Frank Gmbh" from  Saarbruecken
6  *
7  * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  */
19 
20 #define MODULE_NAME "spca506"
21 
22 #include "gspca.h"
23 
24 MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
25 MODULE_DESCRIPTION("GSPCA/SPCA506 USB Camera Driver");
26 MODULE_LICENSE("GPL");
27 
28 /* specific webcam descriptor */
29 struct sd {
30 	struct gspca_dev gspca_dev;	/* !! must be the first item */
31 
32 	char norme;
33 	char channel;
34 };
35 
36 static const struct v4l2_pix_format vga_mode[] = {
37 	{160, 120, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
38 		.bytesperline = 160,
39 		.sizeimage = 160 * 120 * 3 / 2,
40 		.colorspace = V4L2_COLORSPACE_SRGB,
41 		.priv = 5},
42 	{176, 144, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
43 		.bytesperline = 176,
44 		.sizeimage = 176 * 144 * 3 / 2,
45 		.colorspace = V4L2_COLORSPACE_SRGB,
46 		.priv = 4},
47 	{320, 240, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
48 		.bytesperline = 320,
49 		.sizeimage = 320 * 240 * 3 / 2,
50 		.colorspace = V4L2_COLORSPACE_SRGB,
51 		.priv = 2},
52 	{352, 288, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
53 		.bytesperline = 352,
54 		.sizeimage = 352 * 288 * 3 / 2,
55 		.colorspace = V4L2_COLORSPACE_SRGB,
56 		.priv = 1},
57 	{640, 480, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
58 		.bytesperline = 640,
59 		.sizeimage = 640 * 480 * 3 / 2,
60 		.colorspace = V4L2_COLORSPACE_SRGB,
61 		.priv = 0},
62 };
63 
64 #define SPCA50X_OFFSET_DATA 10
65 
66 #define SAA7113_bright 0x0a	/* defaults 0x80 */
67 #define SAA7113_contrast 0x0b	/* defaults 0x47 */
68 #define SAA7113_saturation 0x0c	/* defaults 0x40 */
69 #define SAA7113_hue 0x0d	/* defaults 0x00 */
70 #define SAA7113_I2C_BASE_WRITE 0x4a
71 
72 /* read 'len' bytes to gspca_dev->usb_buf */
73 static void reg_r(struct gspca_dev *gspca_dev,
74 		  __u16 req,
75 		  __u16 index,
76 		  __u16 length)
77 {
78 	usb_control_msg(gspca_dev->dev,
79 			usb_rcvctrlpipe(gspca_dev->dev, 0),
80 			req,
81 			USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
82 			0,		/* value */
83 			index, gspca_dev->usb_buf, length,
84 			500);
85 }
86 
87 static void reg_w(struct usb_device *dev,
88 		  __u16 req,
89 		  __u16 value,
90 		  __u16 index)
91 {
92 	usb_control_msg(dev,
93 			usb_sndctrlpipe(dev, 0),
94 			req,
95 			USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
96 			value, index,
97 			NULL, 0, 500);
98 }
99 
100 static void spca506_Initi2c(struct gspca_dev *gspca_dev)
101 {
102 	reg_w(gspca_dev->dev, 0x07, SAA7113_I2C_BASE_WRITE, 0x0004);
103 }
104 
105 static void spca506_WriteI2c(struct gspca_dev *gspca_dev, __u16 valeur,
106 			     __u16 reg)
107 {
108 	int retry = 60;
109 
110 	reg_w(gspca_dev->dev, 0x07, reg, 0x0001);
111 	reg_w(gspca_dev->dev, 0x07, valeur, 0x0000);
112 	while (retry--) {
113 		reg_r(gspca_dev, 0x07, 0x0003, 2);
114 		if ((gspca_dev->usb_buf[0] | gspca_dev->usb_buf[1]) == 0x00)
115 			break;
116 	}
117 }
118 
119 static void spca506_SetNormeInput(struct gspca_dev *gspca_dev,
120 				 __u16 norme,
121 				 __u16 channel)
122 {
123 	struct sd *sd = (struct sd *) gspca_dev;
124 /* fixme: check if channel == 0..3 and 6..9 (8 values) */
125 	__u8 setbit0 = 0x00;
126 	__u8 setbit1 = 0x00;
127 	__u8 videomask = 0x00;
128 
129 	PDEBUG(D_STREAM, "** Open Set Norme **");
130 	spca506_Initi2c(gspca_dev);
131 	/* NTSC bit0 -> 1(525 l) PAL SECAM bit0 -> 0 (625 l) */
132 	/* Composite channel bit1 -> 1 S-video bit 1 -> 0 */
133 	/* and exclude SAA7113 reserved channel set default 0 otherwise */
134 	if (norme & V4L2_STD_NTSC)
135 		setbit0 = 0x01;
136 	if (channel == 4 || channel == 5 || channel > 9)
137 		channel = 0;
138 	if (channel < 4)
139 		setbit1 = 0x02;
140 	videomask = (0x48 | setbit0 | setbit1);
141 	reg_w(gspca_dev->dev, 0x08, videomask, 0x0000);
142 	spca506_WriteI2c(gspca_dev, (0xc0 | (channel & 0x0F)), 0x02);
143 
144 	if (norme & V4L2_STD_NTSC)
145 		spca506_WriteI2c(gspca_dev, 0x33, 0x0e);
146 					/* Chrominance Control NTSC N */
147 	else if (norme & V4L2_STD_SECAM)
148 		spca506_WriteI2c(gspca_dev, 0x53, 0x0e);
149 					/* Chrominance Control SECAM */
150 	else
151 		spca506_WriteI2c(gspca_dev, 0x03, 0x0e);
152 					/* Chrominance Control PAL BGHIV */
153 
154 	sd->norme = norme;
155 	sd->channel = channel;
156 	PDEBUG(D_STREAM, "Set Video Byte to 0x%2x", videomask);
157 	PDEBUG(D_STREAM, "Set Norme: %08x Channel %d", norme, channel);
158 }
159 
160 static void spca506_GetNormeInput(struct gspca_dev *gspca_dev,
161 				  __u16 *norme, __u16 *channel)
162 {
163 	struct sd *sd = (struct sd *) gspca_dev;
164 
165 	/* Read the register is not so good value change so
166 	   we use your own copy in spca50x struct */
167 	*norme = sd->norme;
168 	*channel = sd->channel;
169 	PDEBUG(D_STREAM, "Get Norme: %d Channel %d", *norme, *channel);
170 }
171 
172 static void spca506_Setsize(struct gspca_dev *gspca_dev, __u16 code,
173 			    __u16 xmult, __u16 ymult)
174 {
175 	struct usb_device *dev = gspca_dev->dev;
176 
177 	PDEBUG(D_STREAM, "** SetSize **");
178 	reg_w(dev, 0x04, (0x18 | (code & 0x07)), 0x0000);
179 	/* Soft snap 0x40 Hard 0x41 */
180 	reg_w(dev, 0x04, 0x41, 0x0001);
181 	reg_w(dev, 0x04, 0x00, 0x0002);
182 	/* reserved */
183 	reg_w(dev, 0x04, 0x00, 0x0003);
184 
185 	/* reserved */
186 	reg_w(dev, 0x04, 0x00, 0x0004);
187 	/* reserved */
188 	reg_w(dev, 0x04, 0x01, 0x0005);
189 	/* reserced */
190 	reg_w(dev, 0x04, xmult, 0x0006);
191 	/* reserved */
192 	reg_w(dev, 0x04, ymult, 0x0007);
193 	/* compression 1 */
194 	reg_w(dev, 0x04, 0x00, 0x0008);
195 	/* T=64 -> 2 */
196 	reg_w(dev, 0x04, 0x00, 0x0009);
197 	/* threshold2D */
198 	reg_w(dev, 0x04, 0x21, 0x000a);
199 	/* quantization */
200 	reg_w(dev, 0x04, 0x00, 0x000b);
201 }
202 
203 /* this function is called at probe time */
204 static int sd_config(struct gspca_dev *gspca_dev,
205 			const struct usb_device_id *id)
206 {
207 	struct cam *cam;
208 
209 	cam = &gspca_dev->cam;
210 	cam->cam_mode = vga_mode;
211 	cam->nmodes = ARRAY_SIZE(vga_mode);
212 	return 0;
213 }
214 
215 /* this function is called at probe and resume time */
216 static int sd_init(struct gspca_dev *gspca_dev)
217 {
218 	struct usb_device *dev = gspca_dev->dev;
219 
220 	reg_w(dev, 0x03, 0x00, 0x0004);
221 	reg_w(dev, 0x03, 0xFF, 0x0003);
222 	reg_w(dev, 0x03, 0x00, 0x0000);
223 	reg_w(dev, 0x03, 0x1c, 0x0001);
224 	reg_w(dev, 0x03, 0x18, 0x0001);
225 	/* Init on PAL and composite input0 */
226 	spca506_SetNormeInput(gspca_dev, 0, 0);
227 	reg_w(dev, 0x03, 0x1c, 0x0001);
228 	reg_w(dev, 0x03, 0x18, 0x0001);
229 	reg_w(dev, 0x05, 0x00, 0x0000);
230 	reg_w(dev, 0x05, 0xef, 0x0001);
231 	reg_w(dev, 0x05, 0x00, 0x00c1);
232 	reg_w(dev, 0x05, 0x00, 0x00c2);
233 	reg_w(dev, 0x06, 0x18, 0x0002);
234 	reg_w(dev, 0x06, 0xf5, 0x0011);
235 	reg_w(dev, 0x06, 0x02, 0x0012);
236 	reg_w(dev, 0x06, 0xfb, 0x0013);
237 	reg_w(dev, 0x06, 0x00, 0x0014);
238 	reg_w(dev, 0x06, 0xa4, 0x0051);
239 	reg_w(dev, 0x06, 0x40, 0x0052);
240 	reg_w(dev, 0x06, 0x71, 0x0053);
241 	reg_w(dev, 0x06, 0x40, 0x0054);
242 	/************************************************/
243 	reg_w(dev, 0x03, 0x00, 0x0004);
244 	reg_w(dev, 0x03, 0x00, 0x0003);
245 	reg_w(dev, 0x03, 0x00, 0x0004);
246 	reg_w(dev, 0x03, 0xFF, 0x0003);
247 	reg_w(dev, 0x02, 0x00, 0x0000);
248 	reg_w(dev, 0x03, 0x60, 0x0000);
249 	reg_w(dev, 0x03, 0x18, 0x0001);
250 	/* for a better reading mx :)	  */
251 	/*sdca506_WriteI2c(value,register) */
252 	spca506_Initi2c(gspca_dev);
253 	spca506_WriteI2c(gspca_dev, 0x08, 0x01);
254 	spca506_WriteI2c(gspca_dev, 0xc0, 0x02);
255 						/* input composite video */
256 	spca506_WriteI2c(gspca_dev, 0x33, 0x03);
257 	spca506_WriteI2c(gspca_dev, 0x00, 0x04);
258 	spca506_WriteI2c(gspca_dev, 0x00, 0x05);
259 	spca506_WriteI2c(gspca_dev, 0x0d, 0x06);
260 	spca506_WriteI2c(gspca_dev, 0xf0, 0x07);
261 	spca506_WriteI2c(gspca_dev, 0x98, 0x08);
262 	spca506_WriteI2c(gspca_dev, 0x03, 0x09);
263 	spca506_WriteI2c(gspca_dev, 0x80, 0x0a);
264 	spca506_WriteI2c(gspca_dev, 0x47, 0x0b);
265 	spca506_WriteI2c(gspca_dev, 0x48, 0x0c);
266 	spca506_WriteI2c(gspca_dev, 0x00, 0x0d);
267 	spca506_WriteI2c(gspca_dev, 0x03, 0x0e);	/* Chroma Pal adjust */
268 	spca506_WriteI2c(gspca_dev, 0x2a, 0x0f);
269 	spca506_WriteI2c(gspca_dev, 0x00, 0x10);
270 	spca506_WriteI2c(gspca_dev, 0x0c, 0x11);
271 	spca506_WriteI2c(gspca_dev, 0xb8, 0x12);
272 	spca506_WriteI2c(gspca_dev, 0x01, 0x13);
273 	spca506_WriteI2c(gspca_dev, 0x00, 0x14);
274 	spca506_WriteI2c(gspca_dev, 0x00, 0x15);
275 	spca506_WriteI2c(gspca_dev, 0x00, 0x16);
276 	spca506_WriteI2c(gspca_dev, 0x00, 0x17);
277 	spca506_WriteI2c(gspca_dev, 0x00, 0x18);
278 	spca506_WriteI2c(gspca_dev, 0x00, 0x19);
279 	spca506_WriteI2c(gspca_dev, 0x00, 0x1a);
280 	spca506_WriteI2c(gspca_dev, 0x00, 0x1b);
281 	spca506_WriteI2c(gspca_dev, 0x00, 0x1c);
282 	spca506_WriteI2c(gspca_dev, 0x00, 0x1d);
283 	spca506_WriteI2c(gspca_dev, 0x00, 0x1e);
284 	spca506_WriteI2c(gspca_dev, 0xa1, 0x1f);
285 	spca506_WriteI2c(gspca_dev, 0x02, 0x40);
286 	spca506_WriteI2c(gspca_dev, 0xff, 0x41);
287 	spca506_WriteI2c(gspca_dev, 0xff, 0x42);
288 	spca506_WriteI2c(gspca_dev, 0xff, 0x43);
289 	spca506_WriteI2c(gspca_dev, 0xff, 0x44);
290 	spca506_WriteI2c(gspca_dev, 0xff, 0x45);
291 	spca506_WriteI2c(gspca_dev, 0xff, 0x46);
292 	spca506_WriteI2c(gspca_dev, 0xff, 0x47);
293 	spca506_WriteI2c(gspca_dev, 0xff, 0x48);
294 	spca506_WriteI2c(gspca_dev, 0xff, 0x49);
295 	spca506_WriteI2c(gspca_dev, 0xff, 0x4a);
296 	spca506_WriteI2c(gspca_dev, 0xff, 0x4b);
297 	spca506_WriteI2c(gspca_dev, 0xff, 0x4c);
298 	spca506_WriteI2c(gspca_dev, 0xff, 0x4d);
299 	spca506_WriteI2c(gspca_dev, 0xff, 0x4e);
300 	spca506_WriteI2c(gspca_dev, 0xff, 0x4f);
301 	spca506_WriteI2c(gspca_dev, 0xff, 0x50);
302 	spca506_WriteI2c(gspca_dev, 0xff, 0x51);
303 	spca506_WriteI2c(gspca_dev, 0xff, 0x52);
304 	spca506_WriteI2c(gspca_dev, 0xff, 0x53);
305 	spca506_WriteI2c(gspca_dev, 0xff, 0x54);
306 	spca506_WriteI2c(gspca_dev, 0xff, 0x55);
307 	spca506_WriteI2c(gspca_dev, 0xff, 0x56);
308 	spca506_WriteI2c(gspca_dev, 0xff, 0x57);
309 	spca506_WriteI2c(gspca_dev, 0x00, 0x58);
310 	spca506_WriteI2c(gspca_dev, 0x54, 0x59);
311 	spca506_WriteI2c(gspca_dev, 0x07, 0x5a);
312 	spca506_WriteI2c(gspca_dev, 0x83, 0x5b);
313 	spca506_WriteI2c(gspca_dev, 0x00, 0x5c);
314 	spca506_WriteI2c(gspca_dev, 0x00, 0x5d);
315 	spca506_WriteI2c(gspca_dev, 0x00, 0x5e);
316 	spca506_WriteI2c(gspca_dev, 0x00, 0x5f);
317 	spca506_WriteI2c(gspca_dev, 0x00, 0x60);
318 	spca506_WriteI2c(gspca_dev, 0x05, 0x61);
319 	spca506_WriteI2c(gspca_dev, 0x9f, 0x62);
320 	PDEBUG(D_STREAM, "** Close Init *");
321 	return 0;
322 }
323 
324 static int sd_start(struct gspca_dev *gspca_dev)
325 {
326 	struct usb_device *dev = gspca_dev->dev;
327 	__u16 norme;
328 	__u16 channel;
329 
330 	/**************************************/
331 	reg_w(dev, 0x03, 0x00, 0x0004);
332 	reg_w(dev, 0x03, 0x00, 0x0003);
333 	reg_w(dev, 0x03, 0x00, 0x0004);
334 	reg_w(dev, 0x03, 0xFF, 0x0003);
335 	reg_w(dev, 0x02, 0x00, 0x0000);
336 	reg_w(dev, 0x03, 0x60, 0x0000);
337 	reg_w(dev, 0x03, 0x18, 0x0001);
338 
339 	/*sdca506_WriteI2c(value,register) */
340 	spca506_Initi2c(gspca_dev);
341 	spca506_WriteI2c(gspca_dev, 0x08, 0x01);	/* Increment Delay */
342 /*	spca506_WriteI2c(gspca_dev, 0xc0, 0x02); * Analog Input Control 1 */
343 	spca506_WriteI2c(gspca_dev, 0x33, 0x03);
344 						/* Analog Input Control 2 */
345 	spca506_WriteI2c(gspca_dev, 0x00, 0x04);
346 						/* Analog Input Control 3 */
347 	spca506_WriteI2c(gspca_dev, 0x00, 0x05);
348 						/* Analog Input Control 4 */
349 	spca506_WriteI2c(gspca_dev, 0x0d, 0x06);
350 					/* Horizontal Sync Start 0xe9-0x0d */
351 	spca506_WriteI2c(gspca_dev, 0xf0, 0x07);
352 					/* Horizontal Sync Stop  0x0d-0xf0 */
353 
354 	spca506_WriteI2c(gspca_dev, 0x98, 0x08);	/* Sync Control */
355 /*		Defaults value			*/
356 	spca506_WriteI2c(gspca_dev, 0x03, 0x09);	/* Luminance Control */
357 	spca506_WriteI2c(gspca_dev, 0x80, 0x0a);
358 						/* Luminance Brightness */
359 	spca506_WriteI2c(gspca_dev, 0x47, 0x0b);	/* Luminance Contrast */
360 	spca506_WriteI2c(gspca_dev, 0x48, 0x0c);
361 						/* Chrominance Saturation */
362 	spca506_WriteI2c(gspca_dev, 0x00, 0x0d);
363 						/* Chrominance Hue Control */
364 	spca506_WriteI2c(gspca_dev, 0x2a, 0x0f);
365 						/* Chrominance Gain Control */
366 	/**************************************/
367 	spca506_WriteI2c(gspca_dev, 0x00, 0x10);
368 						/* Format/Delay Control */
369 	spca506_WriteI2c(gspca_dev, 0x0c, 0x11);	/* Output Control 1 */
370 	spca506_WriteI2c(gspca_dev, 0xb8, 0x12);	/* Output Control 2 */
371 	spca506_WriteI2c(gspca_dev, 0x01, 0x13);	/* Output Control 3 */
372 	spca506_WriteI2c(gspca_dev, 0x00, 0x14);	/* reserved */
373 	spca506_WriteI2c(gspca_dev, 0x00, 0x15);	/* VGATE START */
374 	spca506_WriteI2c(gspca_dev, 0x00, 0x16);	/* VGATE STOP */
375 	spca506_WriteI2c(gspca_dev, 0x00, 0x17);    /* VGATE Control (MSB) */
376 	spca506_WriteI2c(gspca_dev, 0x00, 0x18);
377 	spca506_WriteI2c(gspca_dev, 0x00, 0x19);
378 	spca506_WriteI2c(gspca_dev, 0x00, 0x1a);
379 	spca506_WriteI2c(gspca_dev, 0x00, 0x1b);
380 	spca506_WriteI2c(gspca_dev, 0x00, 0x1c);
381 	spca506_WriteI2c(gspca_dev, 0x00, 0x1d);
382 	spca506_WriteI2c(gspca_dev, 0x00, 0x1e);
383 	spca506_WriteI2c(gspca_dev, 0xa1, 0x1f);
384 	spca506_WriteI2c(gspca_dev, 0x02, 0x40);
385 	spca506_WriteI2c(gspca_dev, 0xff, 0x41);
386 	spca506_WriteI2c(gspca_dev, 0xff, 0x42);
387 	spca506_WriteI2c(gspca_dev, 0xff, 0x43);
388 	spca506_WriteI2c(gspca_dev, 0xff, 0x44);
389 	spca506_WriteI2c(gspca_dev, 0xff, 0x45);
390 	spca506_WriteI2c(gspca_dev, 0xff, 0x46);
391 	spca506_WriteI2c(gspca_dev, 0xff, 0x47);
392 	spca506_WriteI2c(gspca_dev, 0xff, 0x48);
393 	spca506_WriteI2c(gspca_dev, 0xff, 0x49);
394 	spca506_WriteI2c(gspca_dev, 0xff, 0x4a);
395 	spca506_WriteI2c(gspca_dev, 0xff, 0x4b);
396 	spca506_WriteI2c(gspca_dev, 0xff, 0x4c);
397 	spca506_WriteI2c(gspca_dev, 0xff, 0x4d);
398 	spca506_WriteI2c(gspca_dev, 0xff, 0x4e);
399 	spca506_WriteI2c(gspca_dev, 0xff, 0x4f);
400 	spca506_WriteI2c(gspca_dev, 0xff, 0x50);
401 	spca506_WriteI2c(gspca_dev, 0xff, 0x51);
402 	spca506_WriteI2c(gspca_dev, 0xff, 0x52);
403 	spca506_WriteI2c(gspca_dev, 0xff, 0x53);
404 	spca506_WriteI2c(gspca_dev, 0xff, 0x54);
405 	spca506_WriteI2c(gspca_dev, 0xff, 0x55);
406 	spca506_WriteI2c(gspca_dev, 0xff, 0x56);
407 	spca506_WriteI2c(gspca_dev, 0xff, 0x57);
408 	spca506_WriteI2c(gspca_dev, 0x00, 0x58);
409 	spca506_WriteI2c(gspca_dev, 0x54, 0x59);
410 	spca506_WriteI2c(gspca_dev, 0x07, 0x5a);
411 	spca506_WriteI2c(gspca_dev, 0x83, 0x5b);
412 	spca506_WriteI2c(gspca_dev, 0x00, 0x5c);
413 	spca506_WriteI2c(gspca_dev, 0x00, 0x5d);
414 	spca506_WriteI2c(gspca_dev, 0x00, 0x5e);
415 	spca506_WriteI2c(gspca_dev, 0x00, 0x5f);
416 	spca506_WriteI2c(gspca_dev, 0x00, 0x60);
417 	spca506_WriteI2c(gspca_dev, 0x05, 0x61);
418 	spca506_WriteI2c(gspca_dev, 0x9f, 0x62);
419 	/**************************************/
420 	reg_w(dev, 0x05, 0x00, 0x0003);
421 	reg_w(dev, 0x05, 0x00, 0x0004);
422 	reg_w(dev, 0x03, 0x10, 0x0001);
423 	reg_w(dev, 0x03, 0x78, 0x0000);
424 	switch (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) {
425 	case 0:
426 		spca506_Setsize(gspca_dev, 0, 0x10, 0x10);
427 		break;
428 	case 1:
429 		spca506_Setsize(gspca_dev, 1, 0x1a, 0x1a);
430 		break;
431 	case 2:
432 		spca506_Setsize(gspca_dev, 2, 0x1c, 0x1c);
433 		break;
434 	case 4:
435 		spca506_Setsize(gspca_dev, 4, 0x34, 0x34);
436 		break;
437 	default:
438 /*	case 5: */
439 		spca506_Setsize(gspca_dev, 5, 0x40, 0x40);
440 		break;
441 	}
442 
443 	/* compress setting and size */
444 	/* set i2c luma */
445 	reg_w(dev, 0x02, 0x01, 0x0000);
446 	reg_w(dev, 0x03, 0x12, 0x0000);
447 	reg_r(gspca_dev, 0x04, 0x0001, 2);
448 	PDEBUG(D_STREAM, "webcam started");
449 	spca506_GetNormeInput(gspca_dev, &norme, &channel);
450 	spca506_SetNormeInput(gspca_dev, norme, channel);
451 	return 0;
452 }
453 
454 static void sd_stopN(struct gspca_dev *gspca_dev)
455 {
456 	struct usb_device *dev = gspca_dev->dev;
457 
458 	reg_w(dev, 0x02, 0x00, 0x0000);
459 	reg_w(dev, 0x03, 0x00, 0x0004);
460 	reg_w(dev, 0x03, 0x00, 0x0003);
461 }
462 
463 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
464 			u8 *data,			/* isoc packet */
465 			int len)			/* iso packet length */
466 {
467 	switch (data[0]) {
468 	case 0:				/* start of frame */
469 		gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
470 		data += SPCA50X_OFFSET_DATA;
471 		len -= SPCA50X_OFFSET_DATA;
472 		gspca_frame_add(gspca_dev, FIRST_PACKET, data, len);
473 		break;
474 	case 0xff:			/* drop */
475 /*		gspca_dev->last_packet_type = DISCARD_PACKET; */
476 		break;
477 	default:
478 		data += 1;
479 		len -= 1;
480 		gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
481 		break;
482 	}
483 }
484 
485 static void setbrightness(struct gspca_dev *gspca_dev, s32 val)
486 {
487 	spca506_Initi2c(gspca_dev);
488 	spca506_WriteI2c(gspca_dev, val, SAA7113_bright);
489 	spca506_WriteI2c(gspca_dev, 0x01, 0x09);
490 }
491 
492 static void setcontrast(struct gspca_dev *gspca_dev, s32 val)
493 {
494 	spca506_Initi2c(gspca_dev);
495 	spca506_WriteI2c(gspca_dev, val, SAA7113_contrast);
496 	spca506_WriteI2c(gspca_dev, 0x01, 0x09);
497 }
498 
499 static void setcolors(struct gspca_dev *gspca_dev, s32 val)
500 {
501 	spca506_Initi2c(gspca_dev);
502 	spca506_WriteI2c(gspca_dev, val, SAA7113_saturation);
503 	spca506_WriteI2c(gspca_dev, 0x01, 0x09);
504 }
505 
506 static void sethue(struct gspca_dev *gspca_dev, s32 val)
507 {
508 	spca506_Initi2c(gspca_dev);
509 	spca506_WriteI2c(gspca_dev, val, SAA7113_hue);
510 	spca506_WriteI2c(gspca_dev, 0x01, 0x09);
511 }
512 
513 static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
514 {
515 	struct gspca_dev *gspca_dev =
516 		container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
517 
518 	gspca_dev->usb_err = 0;
519 
520 	if (!gspca_dev->streaming)
521 		return 0;
522 
523 	switch (ctrl->id) {
524 	case V4L2_CID_BRIGHTNESS:
525 		setbrightness(gspca_dev, ctrl->val);
526 		break;
527 	case V4L2_CID_CONTRAST:
528 		setcontrast(gspca_dev, ctrl->val);
529 		break;
530 	case V4L2_CID_SATURATION:
531 		setcolors(gspca_dev, ctrl->val);
532 		break;
533 	case V4L2_CID_HUE:
534 		sethue(gspca_dev, ctrl->val);
535 		break;
536 	}
537 	return gspca_dev->usb_err;
538 }
539 
540 static const struct v4l2_ctrl_ops sd_ctrl_ops = {
541 	.s_ctrl = sd_s_ctrl,
542 };
543 
544 static int sd_init_controls(struct gspca_dev *gspca_dev)
545 {
546 	struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
547 
548 	gspca_dev->vdev.ctrl_handler = hdl;
549 	v4l2_ctrl_handler_init(hdl, 4);
550 	v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
551 			V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
552 	v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
553 			V4L2_CID_CONTRAST, 0, 255, 1, 0x47);
554 	v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
555 			V4L2_CID_SATURATION, 0, 255, 1, 0x40);
556 	v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
557 			V4L2_CID_HUE, 0, 255, 1, 0);
558 
559 	if (hdl->error) {
560 		pr_err("Could not initialize controls\n");
561 		return hdl->error;
562 	}
563 	return 0;
564 }
565 
566 /* sub-driver description */
567 static const struct sd_desc sd_desc = {
568 	.name = MODULE_NAME,
569 	.config = sd_config,
570 	.init = sd_init,
571 	.init_controls = sd_init_controls,
572 	.start = sd_start,
573 	.stopN = sd_stopN,
574 	.pkt_scan = sd_pkt_scan,
575 };
576 
577 /* -- module initialisation -- */
578 static const struct usb_device_id device_table[] = {
579 	{USB_DEVICE(0x06e1, 0xa190)},
580 /*	{USB_DEVICE(0x0733, 0x0430)}, FIXME: may be IntelPCCameraPro BRIDGE_SPCA505 */
581 	{USB_DEVICE(0x0734, 0x043b)},
582 	{USB_DEVICE(0x99fa, 0x8988)},
583 	{}
584 };
585 MODULE_DEVICE_TABLE(usb, device_table);
586 
587 /* -- device connect -- */
588 static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id)
589 {
590 	return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
591 				THIS_MODULE);
592 }
593 
594 static struct usb_driver sd_driver = {
595 	.name = MODULE_NAME,
596 	.id_table = device_table,
597 	.probe = sd_probe,
598 	.disconnect = gspca_disconnect,
599 #ifdef CONFIG_PM
600 	.suspend = gspca_suspend,
601 	.resume = gspca_resume,
602 	.reset_resume = gspca_resume,
603 #endif
604 };
605 
606 module_usb_driver(sd_driver);
607