xref: /openbmc/linux/drivers/media/usb/gspca/spca506.c (revision 58e16d792a6a8c6b750f637a4649967fcac853dc)
1*fd9871f7SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
20c0d06caSMauro Carvalho Chehab /*
30c0d06caSMauro Carvalho Chehab  * SPCA506 chip based cameras function
40c0d06caSMauro Carvalho Chehab  * M Xhaard 15/04/2004 based on different work Mark Taylor and others
50c0d06caSMauro Carvalho Chehab  * and my own snoopy file on a pv-321c donate by a german compagny
60c0d06caSMauro Carvalho Chehab  *                "Firma Frank Gmbh" from  Saarbruecken
70c0d06caSMauro Carvalho Chehab  *
80c0d06caSMauro Carvalho Chehab  * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
90c0d06caSMauro Carvalho Chehab  */
100c0d06caSMauro Carvalho Chehab 
110c0d06caSMauro Carvalho Chehab #define MODULE_NAME "spca506"
120c0d06caSMauro Carvalho Chehab 
130c0d06caSMauro Carvalho Chehab #include "gspca.h"
140c0d06caSMauro Carvalho Chehab 
150c0d06caSMauro Carvalho Chehab MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
160c0d06caSMauro Carvalho Chehab MODULE_DESCRIPTION("GSPCA/SPCA506 USB Camera Driver");
170c0d06caSMauro Carvalho Chehab MODULE_LICENSE("GPL");
180c0d06caSMauro Carvalho Chehab 
190c0d06caSMauro Carvalho Chehab /* specific webcam descriptor */
200c0d06caSMauro Carvalho Chehab struct sd {
210c0d06caSMauro Carvalho Chehab 	struct gspca_dev gspca_dev;	/* !! must be the first item */
220c0d06caSMauro Carvalho Chehab 
230c0d06caSMauro Carvalho Chehab 	char norme;
240c0d06caSMauro Carvalho Chehab 	char channel;
250c0d06caSMauro Carvalho Chehab };
260c0d06caSMauro Carvalho Chehab 
270c0d06caSMauro Carvalho Chehab static const struct v4l2_pix_format vga_mode[] = {
280c0d06caSMauro Carvalho Chehab 	{160, 120, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
290c0d06caSMauro Carvalho Chehab 		.bytesperline = 160,
300c0d06caSMauro Carvalho Chehab 		.sizeimage = 160 * 120 * 3 / 2,
310c0d06caSMauro Carvalho Chehab 		.colorspace = V4L2_COLORSPACE_SRGB,
320c0d06caSMauro Carvalho Chehab 		.priv = 5},
330c0d06caSMauro Carvalho Chehab 	{176, 144, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
340c0d06caSMauro Carvalho Chehab 		.bytesperline = 176,
350c0d06caSMauro Carvalho Chehab 		.sizeimage = 176 * 144 * 3 / 2,
360c0d06caSMauro Carvalho Chehab 		.colorspace = V4L2_COLORSPACE_SRGB,
370c0d06caSMauro Carvalho Chehab 		.priv = 4},
380c0d06caSMauro Carvalho Chehab 	{320, 240, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
390c0d06caSMauro Carvalho Chehab 		.bytesperline = 320,
400c0d06caSMauro Carvalho Chehab 		.sizeimage = 320 * 240 * 3 / 2,
410c0d06caSMauro Carvalho Chehab 		.colorspace = V4L2_COLORSPACE_SRGB,
420c0d06caSMauro Carvalho Chehab 		.priv = 2},
430c0d06caSMauro Carvalho Chehab 	{352, 288, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
440c0d06caSMauro Carvalho Chehab 		.bytesperline = 352,
450c0d06caSMauro Carvalho Chehab 		.sizeimage = 352 * 288 * 3 / 2,
460c0d06caSMauro Carvalho Chehab 		.colorspace = V4L2_COLORSPACE_SRGB,
470c0d06caSMauro Carvalho Chehab 		.priv = 1},
480c0d06caSMauro Carvalho Chehab 	{640, 480, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
490c0d06caSMauro Carvalho Chehab 		.bytesperline = 640,
500c0d06caSMauro Carvalho Chehab 		.sizeimage = 640 * 480 * 3 / 2,
510c0d06caSMauro Carvalho Chehab 		.colorspace = V4L2_COLORSPACE_SRGB,
520c0d06caSMauro Carvalho Chehab 		.priv = 0},
530c0d06caSMauro Carvalho Chehab };
540c0d06caSMauro Carvalho Chehab 
550c0d06caSMauro Carvalho Chehab #define SPCA50X_OFFSET_DATA 10
560c0d06caSMauro Carvalho Chehab 
570c0d06caSMauro Carvalho Chehab #define SAA7113_bright 0x0a	/* defaults 0x80 */
580c0d06caSMauro Carvalho Chehab #define SAA7113_contrast 0x0b	/* defaults 0x47 */
590c0d06caSMauro Carvalho Chehab #define SAA7113_saturation 0x0c	/* defaults 0x40 */
600c0d06caSMauro Carvalho Chehab #define SAA7113_hue 0x0d	/* defaults 0x00 */
610c0d06caSMauro Carvalho Chehab #define SAA7113_I2C_BASE_WRITE 0x4a
620c0d06caSMauro Carvalho Chehab 
630c0d06caSMauro Carvalho Chehab /* read 'len' bytes to gspca_dev->usb_buf */
reg_r(struct gspca_dev * gspca_dev,__u16 req,__u16 index,__u16 length)640c0d06caSMauro Carvalho Chehab static void reg_r(struct gspca_dev *gspca_dev,
650c0d06caSMauro Carvalho Chehab 		  __u16 req,
660c0d06caSMauro Carvalho Chehab 		  __u16 index,
670c0d06caSMauro Carvalho Chehab 		  __u16 length)
680c0d06caSMauro Carvalho Chehab {
690c0d06caSMauro Carvalho Chehab 	usb_control_msg(gspca_dev->dev,
700c0d06caSMauro Carvalho Chehab 			usb_rcvctrlpipe(gspca_dev->dev, 0),
710c0d06caSMauro Carvalho Chehab 			req,
720c0d06caSMauro Carvalho Chehab 			USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
730c0d06caSMauro Carvalho Chehab 			0,		/* value */
740c0d06caSMauro Carvalho Chehab 			index, gspca_dev->usb_buf, length,
750c0d06caSMauro Carvalho Chehab 			500);
760c0d06caSMauro Carvalho Chehab }
770c0d06caSMauro Carvalho Chehab 
reg_w(struct usb_device * dev,__u16 req,__u16 value,__u16 index)780c0d06caSMauro Carvalho Chehab static void reg_w(struct usb_device *dev,
790c0d06caSMauro Carvalho Chehab 		  __u16 req,
800c0d06caSMauro Carvalho Chehab 		  __u16 value,
810c0d06caSMauro Carvalho Chehab 		  __u16 index)
820c0d06caSMauro Carvalho Chehab {
830c0d06caSMauro Carvalho Chehab 	usb_control_msg(dev,
840c0d06caSMauro Carvalho Chehab 			usb_sndctrlpipe(dev, 0),
850c0d06caSMauro Carvalho Chehab 			req,
860c0d06caSMauro Carvalho Chehab 			USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
870c0d06caSMauro Carvalho Chehab 			value, index,
880c0d06caSMauro Carvalho Chehab 			NULL, 0, 500);
890c0d06caSMauro Carvalho Chehab }
900c0d06caSMauro Carvalho Chehab 
spca506_Initi2c(struct gspca_dev * gspca_dev)910c0d06caSMauro Carvalho Chehab static void spca506_Initi2c(struct gspca_dev *gspca_dev)
920c0d06caSMauro Carvalho Chehab {
930c0d06caSMauro Carvalho Chehab 	reg_w(gspca_dev->dev, 0x07, SAA7113_I2C_BASE_WRITE, 0x0004);
940c0d06caSMauro Carvalho Chehab }
950c0d06caSMauro Carvalho Chehab 
spca506_WriteI2c(struct gspca_dev * gspca_dev,__u16 valeur,__u16 reg)960c0d06caSMauro Carvalho Chehab static void spca506_WriteI2c(struct gspca_dev *gspca_dev, __u16 valeur,
970c0d06caSMauro Carvalho Chehab 			     __u16 reg)
980c0d06caSMauro Carvalho Chehab {
990c0d06caSMauro Carvalho Chehab 	int retry = 60;
1000c0d06caSMauro Carvalho Chehab 
1010c0d06caSMauro Carvalho Chehab 	reg_w(gspca_dev->dev, 0x07, reg, 0x0001);
1020c0d06caSMauro Carvalho Chehab 	reg_w(gspca_dev->dev, 0x07, valeur, 0x0000);
1030c0d06caSMauro Carvalho Chehab 	while (retry--) {
1040c0d06caSMauro Carvalho Chehab 		reg_r(gspca_dev, 0x07, 0x0003, 2);
1050c0d06caSMauro Carvalho Chehab 		if ((gspca_dev->usb_buf[0] | gspca_dev->usb_buf[1]) == 0x00)
1060c0d06caSMauro Carvalho Chehab 			break;
1070c0d06caSMauro Carvalho Chehab 	}
1080c0d06caSMauro Carvalho Chehab }
1090c0d06caSMauro Carvalho Chehab 
spca506_SetNormeInput(struct gspca_dev * gspca_dev,__u16 norme,__u16 channel)1100c0d06caSMauro Carvalho Chehab static void spca506_SetNormeInput(struct gspca_dev *gspca_dev,
1110c0d06caSMauro Carvalho Chehab 				 __u16 norme,
1120c0d06caSMauro Carvalho Chehab 				 __u16 channel)
1130c0d06caSMauro Carvalho Chehab {
1140c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
1150c0d06caSMauro Carvalho Chehab /* fixme: check if channel == 0..3 and 6..9 (8 values) */
1160c0d06caSMauro Carvalho Chehab 	__u8 setbit0 = 0x00;
1170c0d06caSMauro Carvalho Chehab 	__u8 setbit1 = 0x00;
1180c0d06caSMauro Carvalho Chehab 	__u8 videomask = 0x00;
1190c0d06caSMauro Carvalho Chehab 
12037d5efb0SJoe Perches 	gspca_dbg(gspca_dev, D_STREAM, "** Open Set Norme **\n");
1210c0d06caSMauro Carvalho Chehab 	spca506_Initi2c(gspca_dev);
1220c0d06caSMauro Carvalho Chehab 	/* NTSC bit0 -> 1(525 l) PAL SECAM bit0 -> 0 (625 l) */
1230c0d06caSMauro Carvalho Chehab 	/* Composite channel bit1 -> 1 S-video bit 1 -> 0 */
1240c0d06caSMauro Carvalho Chehab 	/* and exclude SAA7113 reserved channel set default 0 otherwise */
1250c0d06caSMauro Carvalho Chehab 	if (norme & V4L2_STD_NTSC)
1260c0d06caSMauro Carvalho Chehab 		setbit0 = 0x01;
1270c0d06caSMauro Carvalho Chehab 	if (channel == 4 || channel == 5 || channel > 9)
1280c0d06caSMauro Carvalho Chehab 		channel = 0;
1290c0d06caSMauro Carvalho Chehab 	if (channel < 4)
1300c0d06caSMauro Carvalho Chehab 		setbit1 = 0x02;
1310c0d06caSMauro Carvalho Chehab 	videomask = (0x48 | setbit0 | setbit1);
1320c0d06caSMauro Carvalho Chehab 	reg_w(gspca_dev->dev, 0x08, videomask, 0x0000);
1330c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, (0xc0 | (channel & 0x0F)), 0x02);
1340c0d06caSMauro Carvalho Chehab 
1350c0d06caSMauro Carvalho Chehab 	if (norme & V4L2_STD_NTSC)
1360c0d06caSMauro Carvalho Chehab 		spca506_WriteI2c(gspca_dev, 0x33, 0x0e);
1370c0d06caSMauro Carvalho Chehab 					/* Chrominance Control NTSC N */
1380c0d06caSMauro Carvalho Chehab 	else if (norme & V4L2_STD_SECAM)
1390c0d06caSMauro Carvalho Chehab 		spca506_WriteI2c(gspca_dev, 0x53, 0x0e);
1400c0d06caSMauro Carvalho Chehab 					/* Chrominance Control SECAM */
1410c0d06caSMauro Carvalho Chehab 	else
1420c0d06caSMauro Carvalho Chehab 		spca506_WriteI2c(gspca_dev, 0x03, 0x0e);
1430c0d06caSMauro Carvalho Chehab 					/* Chrominance Control PAL BGHIV */
1440c0d06caSMauro Carvalho Chehab 
1450c0d06caSMauro Carvalho Chehab 	sd->norme = norme;
1460c0d06caSMauro Carvalho Chehab 	sd->channel = channel;
14737d5efb0SJoe Perches 	gspca_dbg(gspca_dev, D_STREAM, "Set Video Byte to 0x%2x\n", videomask);
14837d5efb0SJoe Perches 	gspca_dbg(gspca_dev, D_STREAM, "Set Norme: %08x Channel %d",
14937d5efb0SJoe Perches 		  norme, channel);
1500c0d06caSMauro Carvalho Chehab }
1510c0d06caSMauro Carvalho Chehab 
spca506_GetNormeInput(struct gspca_dev * gspca_dev,__u16 * norme,__u16 * channel)1520c0d06caSMauro Carvalho Chehab static void spca506_GetNormeInput(struct gspca_dev *gspca_dev,
1530c0d06caSMauro Carvalho Chehab 				  __u16 *norme, __u16 *channel)
1540c0d06caSMauro Carvalho Chehab {
1550c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
1560c0d06caSMauro Carvalho Chehab 
1570c0d06caSMauro Carvalho Chehab 	/* Read the register is not so good value change so
1580c0d06caSMauro Carvalho Chehab 	   we use your own copy in spca50x struct */
1590c0d06caSMauro Carvalho Chehab 	*norme = sd->norme;
1600c0d06caSMauro Carvalho Chehab 	*channel = sd->channel;
16137d5efb0SJoe Perches 	gspca_dbg(gspca_dev, D_STREAM, "Get Norme: %d Channel %d\n",
16237d5efb0SJoe Perches 		  *norme, *channel);
1630c0d06caSMauro Carvalho Chehab }
1640c0d06caSMauro Carvalho Chehab 
spca506_Setsize(struct gspca_dev * gspca_dev,__u16 code,__u16 xmult,__u16 ymult)1650c0d06caSMauro Carvalho Chehab static void spca506_Setsize(struct gspca_dev *gspca_dev, __u16 code,
1660c0d06caSMauro Carvalho Chehab 			    __u16 xmult, __u16 ymult)
1670c0d06caSMauro Carvalho Chehab {
1680c0d06caSMauro Carvalho Chehab 	struct usb_device *dev = gspca_dev->dev;
1690c0d06caSMauro Carvalho Chehab 
17037d5efb0SJoe Perches 	gspca_dbg(gspca_dev, D_STREAM, "** SetSize **\n");
1710c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x04, (0x18 | (code & 0x07)), 0x0000);
1720c0d06caSMauro Carvalho Chehab 	/* Soft snap 0x40 Hard 0x41 */
1730c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x04, 0x41, 0x0001);
1740c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x04, 0x00, 0x0002);
1750c0d06caSMauro Carvalho Chehab 	/* reserved */
1760c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x04, 0x00, 0x0003);
1770c0d06caSMauro Carvalho Chehab 
1780c0d06caSMauro Carvalho Chehab 	/* reserved */
1790c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x04, 0x00, 0x0004);
1800c0d06caSMauro Carvalho Chehab 	/* reserved */
1810c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x04, 0x01, 0x0005);
1820c0d06caSMauro Carvalho Chehab 	/* reserced */
1830c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x04, xmult, 0x0006);
1840c0d06caSMauro Carvalho Chehab 	/* reserved */
1850c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x04, ymult, 0x0007);
1860c0d06caSMauro Carvalho Chehab 	/* compression 1 */
1870c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x04, 0x00, 0x0008);
1880c0d06caSMauro Carvalho Chehab 	/* T=64 -> 2 */
1890c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x04, 0x00, 0x0009);
1900c0d06caSMauro Carvalho Chehab 	/* threshold2D */
1910c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x04, 0x21, 0x000a);
1920c0d06caSMauro Carvalho Chehab 	/* quantization */
1930c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x04, 0x00, 0x000b);
1940c0d06caSMauro Carvalho Chehab }
1950c0d06caSMauro Carvalho Chehab 
1960c0d06caSMauro Carvalho Chehab /* this function is called at probe time */
sd_config(struct gspca_dev * gspca_dev,const struct usb_device_id * id)1970c0d06caSMauro Carvalho Chehab static int sd_config(struct gspca_dev *gspca_dev,
1980c0d06caSMauro Carvalho Chehab 			const struct usb_device_id *id)
1990c0d06caSMauro Carvalho Chehab {
2000c0d06caSMauro Carvalho Chehab 	struct cam *cam;
2010c0d06caSMauro Carvalho Chehab 
2020c0d06caSMauro Carvalho Chehab 	cam = &gspca_dev->cam;
2030c0d06caSMauro Carvalho Chehab 	cam->cam_mode = vga_mode;
2040c0d06caSMauro Carvalho Chehab 	cam->nmodes = ARRAY_SIZE(vga_mode);
2050c0d06caSMauro Carvalho Chehab 	return 0;
2060c0d06caSMauro Carvalho Chehab }
2070c0d06caSMauro Carvalho Chehab 
2080c0d06caSMauro Carvalho Chehab /* this function is called at probe and resume time */
sd_init(struct gspca_dev * gspca_dev)2090c0d06caSMauro Carvalho Chehab static int sd_init(struct gspca_dev *gspca_dev)
2100c0d06caSMauro Carvalho Chehab {
2110c0d06caSMauro Carvalho Chehab 	struct usb_device *dev = gspca_dev->dev;
2120c0d06caSMauro Carvalho Chehab 
2130c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x03, 0x00, 0x0004);
2140c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x03, 0xFF, 0x0003);
2150c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x03, 0x00, 0x0000);
2160c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x03, 0x1c, 0x0001);
2170c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x03, 0x18, 0x0001);
2180c0d06caSMauro Carvalho Chehab 	/* Init on PAL and composite input0 */
2190c0d06caSMauro Carvalho Chehab 	spca506_SetNormeInput(gspca_dev, 0, 0);
2200c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x03, 0x1c, 0x0001);
2210c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x03, 0x18, 0x0001);
2220c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x05, 0x00, 0x0000);
2230c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x05, 0xef, 0x0001);
2240c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x05, 0x00, 0x00c1);
2250c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x05, 0x00, 0x00c2);
2260c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x06, 0x18, 0x0002);
2270c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x06, 0xf5, 0x0011);
2280c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x06, 0x02, 0x0012);
2290c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x06, 0xfb, 0x0013);
2300c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x06, 0x00, 0x0014);
2310c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x06, 0xa4, 0x0051);
2320c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x06, 0x40, 0x0052);
2330c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x06, 0x71, 0x0053);
2340c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x06, 0x40, 0x0054);
2350c0d06caSMauro Carvalho Chehab 	/************************************************/
2360c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x03, 0x00, 0x0004);
2370c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x03, 0x00, 0x0003);
2380c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x03, 0x00, 0x0004);
2390c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x03, 0xFF, 0x0003);
2400c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x02, 0x00, 0x0000);
2410c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x03, 0x60, 0x0000);
2420c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x03, 0x18, 0x0001);
2430c0d06caSMauro Carvalho Chehab 	/* for a better reading mx :)	  */
2440c0d06caSMauro Carvalho Chehab 	/*sdca506_WriteI2c(value,register) */
2450c0d06caSMauro Carvalho Chehab 	spca506_Initi2c(gspca_dev);
2460c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x08, 0x01);
2470c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xc0, 0x02);
2480c0d06caSMauro Carvalho Chehab 						/* input composite video */
2490c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x33, 0x03);
2500c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x04);
2510c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x05);
2520c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x0d, 0x06);
2530c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xf0, 0x07);
2540c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x98, 0x08);
2550c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x03, 0x09);
2560c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x80, 0x0a);
2570c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x47, 0x0b);
2580c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x48, 0x0c);
2590c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x0d);
2600c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x03, 0x0e);	/* Chroma Pal adjust */
2610c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x2a, 0x0f);
2620c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x10);
2630c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x0c, 0x11);
2640c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xb8, 0x12);
2650c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x01, 0x13);
2660c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x14);
2670c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x15);
2680c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x16);
2690c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x17);
2700c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x18);
2710c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x19);
2720c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x1a);
2730c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x1b);
2740c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x1c);
2750c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x1d);
2760c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x1e);
2770c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xa1, 0x1f);
2780c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x02, 0x40);
2790c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x41);
2800c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x42);
2810c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x43);
2820c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x44);
2830c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x45);
2840c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x46);
2850c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x47);
2860c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x48);
2870c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x49);
2880c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x4a);
2890c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x4b);
2900c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x4c);
2910c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x4d);
2920c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x4e);
2930c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x4f);
2940c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x50);
2950c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x51);
2960c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x52);
2970c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x53);
2980c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x54);
2990c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x55);
3000c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x56);
3010c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x57);
3020c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x58);
3030c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x54, 0x59);
3040c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x07, 0x5a);
3050c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x83, 0x5b);
3060c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x5c);
3070c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x5d);
3080c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x5e);
3090c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x5f);
3100c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x60);
3110c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x05, 0x61);
3120c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x9f, 0x62);
31337d5efb0SJoe Perches 	gspca_dbg(gspca_dev, D_STREAM, "** Close Init *\n");
3140c0d06caSMauro Carvalho Chehab 	return 0;
3150c0d06caSMauro Carvalho Chehab }
3160c0d06caSMauro Carvalho Chehab 
sd_start(struct gspca_dev * gspca_dev)3170c0d06caSMauro Carvalho Chehab static int sd_start(struct gspca_dev *gspca_dev)
3180c0d06caSMauro Carvalho Chehab {
3190c0d06caSMauro Carvalho Chehab 	struct usb_device *dev = gspca_dev->dev;
3200c0d06caSMauro Carvalho Chehab 	__u16 norme;
3210c0d06caSMauro Carvalho Chehab 	__u16 channel;
3220c0d06caSMauro Carvalho Chehab 
3230c0d06caSMauro Carvalho Chehab 	/**************************************/
3240c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x03, 0x00, 0x0004);
3250c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x03, 0x00, 0x0003);
3260c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x03, 0x00, 0x0004);
3270c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x03, 0xFF, 0x0003);
3280c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x02, 0x00, 0x0000);
3290c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x03, 0x60, 0x0000);
3300c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x03, 0x18, 0x0001);
3310c0d06caSMauro Carvalho Chehab 
3320c0d06caSMauro Carvalho Chehab 	/*sdca506_WriteI2c(value,register) */
3330c0d06caSMauro Carvalho Chehab 	spca506_Initi2c(gspca_dev);
3340c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x08, 0x01);	/* Increment Delay */
3350c0d06caSMauro Carvalho Chehab /*	spca506_WriteI2c(gspca_dev, 0xc0, 0x02); * Analog Input Control 1 */
3360c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x33, 0x03);
3370c0d06caSMauro Carvalho Chehab 						/* Analog Input Control 2 */
3380c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x04);
3390c0d06caSMauro Carvalho Chehab 						/* Analog Input Control 3 */
3400c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x05);
3410c0d06caSMauro Carvalho Chehab 						/* Analog Input Control 4 */
3420c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x0d, 0x06);
3430c0d06caSMauro Carvalho Chehab 					/* Horizontal Sync Start 0xe9-0x0d */
3440c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xf0, 0x07);
3450c0d06caSMauro Carvalho Chehab 					/* Horizontal Sync Stop  0x0d-0xf0 */
3460c0d06caSMauro Carvalho Chehab 
3470c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x98, 0x08);	/* Sync Control */
3480c0d06caSMauro Carvalho Chehab /*		Defaults value			*/
3490c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x03, 0x09);	/* Luminance Control */
3500c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x80, 0x0a);
3510c0d06caSMauro Carvalho Chehab 						/* Luminance Brightness */
3520c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x47, 0x0b);	/* Luminance Contrast */
3530c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x48, 0x0c);
3540c0d06caSMauro Carvalho Chehab 						/* Chrominance Saturation */
3550c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x0d);
3560c0d06caSMauro Carvalho Chehab 						/* Chrominance Hue Control */
3570c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x2a, 0x0f);
3580c0d06caSMauro Carvalho Chehab 						/* Chrominance Gain Control */
3590c0d06caSMauro Carvalho Chehab 	/**************************************/
3600c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x10);
3610c0d06caSMauro Carvalho Chehab 						/* Format/Delay Control */
3620c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x0c, 0x11);	/* Output Control 1 */
3630c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xb8, 0x12);	/* Output Control 2 */
3640c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x01, 0x13);	/* Output Control 3 */
3650c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x14);	/* reserved */
3660c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x15);	/* VGATE START */
3670c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x16);	/* VGATE STOP */
3680c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x17);    /* VGATE Control (MSB) */
3690c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x18);
3700c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x19);
3710c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x1a);
3720c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x1b);
3730c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x1c);
3740c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x1d);
3750c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x1e);
3760c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xa1, 0x1f);
3770c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x02, 0x40);
3780c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x41);
3790c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x42);
3800c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x43);
3810c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x44);
3820c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x45);
3830c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x46);
3840c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x47);
3850c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x48);
3860c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x49);
3870c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x4a);
3880c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x4b);
3890c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x4c);
3900c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x4d);
3910c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x4e);
3920c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x4f);
3930c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x50);
3940c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x51);
3950c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x52);
3960c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x53);
3970c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x54);
3980c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x55);
3990c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x56);
4000c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0xff, 0x57);
4010c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x58);
4020c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x54, 0x59);
4030c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x07, 0x5a);
4040c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x83, 0x5b);
4050c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x5c);
4060c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x5d);
4070c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x5e);
4080c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x5f);
4090c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x00, 0x60);
4100c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x05, 0x61);
4110c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x9f, 0x62);
4120c0d06caSMauro Carvalho Chehab 	/**************************************/
4130c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x05, 0x00, 0x0003);
4140c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x05, 0x00, 0x0004);
4150c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x03, 0x10, 0x0001);
4160c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x03, 0x78, 0x0000);
4170c0d06caSMauro Carvalho Chehab 	switch (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) {
4180c0d06caSMauro Carvalho Chehab 	case 0:
4190c0d06caSMauro Carvalho Chehab 		spca506_Setsize(gspca_dev, 0, 0x10, 0x10);
4200c0d06caSMauro Carvalho Chehab 		break;
4210c0d06caSMauro Carvalho Chehab 	case 1:
4220c0d06caSMauro Carvalho Chehab 		spca506_Setsize(gspca_dev, 1, 0x1a, 0x1a);
4230c0d06caSMauro Carvalho Chehab 		break;
4240c0d06caSMauro Carvalho Chehab 	case 2:
4250c0d06caSMauro Carvalho Chehab 		spca506_Setsize(gspca_dev, 2, 0x1c, 0x1c);
4260c0d06caSMauro Carvalho Chehab 		break;
4270c0d06caSMauro Carvalho Chehab 	case 4:
4280c0d06caSMauro Carvalho Chehab 		spca506_Setsize(gspca_dev, 4, 0x34, 0x34);
4290c0d06caSMauro Carvalho Chehab 		break;
4300c0d06caSMauro Carvalho Chehab 	default:
4310c0d06caSMauro Carvalho Chehab /*	case 5: */
4320c0d06caSMauro Carvalho Chehab 		spca506_Setsize(gspca_dev, 5, 0x40, 0x40);
4330c0d06caSMauro Carvalho Chehab 		break;
4340c0d06caSMauro Carvalho Chehab 	}
4350c0d06caSMauro Carvalho Chehab 
4360c0d06caSMauro Carvalho Chehab 	/* compress setting and size */
4370c0d06caSMauro Carvalho Chehab 	/* set i2c luma */
4380c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x02, 0x01, 0x0000);
4390c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x03, 0x12, 0x0000);
4400c0d06caSMauro Carvalho Chehab 	reg_r(gspca_dev, 0x04, 0x0001, 2);
44137d5efb0SJoe Perches 	gspca_dbg(gspca_dev, D_STREAM, "webcam started\n");
4420c0d06caSMauro Carvalho Chehab 	spca506_GetNormeInput(gspca_dev, &norme, &channel);
4430c0d06caSMauro Carvalho Chehab 	spca506_SetNormeInput(gspca_dev, norme, channel);
4440c0d06caSMauro Carvalho Chehab 	return 0;
4450c0d06caSMauro Carvalho Chehab }
4460c0d06caSMauro Carvalho Chehab 
sd_stopN(struct gspca_dev * gspca_dev)4470c0d06caSMauro Carvalho Chehab static void sd_stopN(struct gspca_dev *gspca_dev)
4480c0d06caSMauro Carvalho Chehab {
4490c0d06caSMauro Carvalho Chehab 	struct usb_device *dev = gspca_dev->dev;
4500c0d06caSMauro Carvalho Chehab 
4510c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x02, 0x00, 0x0000);
4520c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x03, 0x00, 0x0004);
4530c0d06caSMauro Carvalho Chehab 	reg_w(dev, 0x03, 0x00, 0x0003);
4540c0d06caSMauro Carvalho Chehab }
4550c0d06caSMauro Carvalho Chehab 
sd_pkt_scan(struct gspca_dev * gspca_dev,u8 * data,int len)4560c0d06caSMauro Carvalho Chehab static void sd_pkt_scan(struct gspca_dev *gspca_dev,
4570c0d06caSMauro Carvalho Chehab 			u8 *data,			/* isoc packet */
4580c0d06caSMauro Carvalho Chehab 			int len)			/* iso packet length */
4590c0d06caSMauro Carvalho Chehab {
4600c0d06caSMauro Carvalho Chehab 	switch (data[0]) {
4610c0d06caSMauro Carvalho Chehab 	case 0:				/* start of frame */
4620c0d06caSMauro Carvalho Chehab 		gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
4630c0d06caSMauro Carvalho Chehab 		data += SPCA50X_OFFSET_DATA;
4640c0d06caSMauro Carvalho Chehab 		len -= SPCA50X_OFFSET_DATA;
4650c0d06caSMauro Carvalho Chehab 		gspca_frame_add(gspca_dev, FIRST_PACKET, data, len);
4660c0d06caSMauro Carvalho Chehab 		break;
4670c0d06caSMauro Carvalho Chehab 	case 0xff:			/* drop */
4680c0d06caSMauro Carvalho Chehab /*		gspca_dev->last_packet_type = DISCARD_PACKET; */
4690c0d06caSMauro Carvalho Chehab 		break;
4700c0d06caSMauro Carvalho Chehab 	default:
4710c0d06caSMauro Carvalho Chehab 		data += 1;
4720c0d06caSMauro Carvalho Chehab 		len -= 1;
4730c0d06caSMauro Carvalho Chehab 		gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
4740c0d06caSMauro Carvalho Chehab 		break;
4750c0d06caSMauro Carvalho Chehab 	}
4760c0d06caSMauro Carvalho Chehab }
4770c0d06caSMauro Carvalho Chehab 
setbrightness(struct gspca_dev * gspca_dev,s32 val)4780c0d06caSMauro Carvalho Chehab static void setbrightness(struct gspca_dev *gspca_dev, s32 val)
4790c0d06caSMauro Carvalho Chehab {
4800c0d06caSMauro Carvalho Chehab 	spca506_Initi2c(gspca_dev);
4810c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, val, SAA7113_bright);
4820c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x01, 0x09);
4830c0d06caSMauro Carvalho Chehab }
4840c0d06caSMauro Carvalho Chehab 
setcontrast(struct gspca_dev * gspca_dev,s32 val)4850c0d06caSMauro Carvalho Chehab static void setcontrast(struct gspca_dev *gspca_dev, s32 val)
4860c0d06caSMauro Carvalho Chehab {
4870c0d06caSMauro Carvalho Chehab 	spca506_Initi2c(gspca_dev);
4880c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, val, SAA7113_contrast);
4890c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x01, 0x09);
4900c0d06caSMauro Carvalho Chehab }
4910c0d06caSMauro Carvalho Chehab 
setcolors(struct gspca_dev * gspca_dev,s32 val)4920c0d06caSMauro Carvalho Chehab static void setcolors(struct gspca_dev *gspca_dev, s32 val)
4930c0d06caSMauro Carvalho Chehab {
4940c0d06caSMauro Carvalho Chehab 	spca506_Initi2c(gspca_dev);
4950c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, val, SAA7113_saturation);
4960c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x01, 0x09);
4970c0d06caSMauro Carvalho Chehab }
4980c0d06caSMauro Carvalho Chehab 
sethue(struct gspca_dev * gspca_dev,s32 val)4990c0d06caSMauro Carvalho Chehab static void sethue(struct gspca_dev *gspca_dev, s32 val)
5000c0d06caSMauro Carvalho Chehab {
5010c0d06caSMauro Carvalho Chehab 	spca506_Initi2c(gspca_dev);
5020c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, val, SAA7113_hue);
5030c0d06caSMauro Carvalho Chehab 	spca506_WriteI2c(gspca_dev, 0x01, 0x09);
5040c0d06caSMauro Carvalho Chehab }
5050c0d06caSMauro Carvalho Chehab 
sd_s_ctrl(struct v4l2_ctrl * ctrl)5060c0d06caSMauro Carvalho Chehab static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
5070c0d06caSMauro Carvalho Chehab {
5080c0d06caSMauro Carvalho Chehab 	struct gspca_dev *gspca_dev =
5090c0d06caSMauro Carvalho Chehab 		container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
5100c0d06caSMauro Carvalho Chehab 
5110c0d06caSMauro Carvalho Chehab 	gspca_dev->usb_err = 0;
5120c0d06caSMauro Carvalho Chehab 
5130c0d06caSMauro Carvalho Chehab 	if (!gspca_dev->streaming)
5140c0d06caSMauro Carvalho Chehab 		return 0;
5150c0d06caSMauro Carvalho Chehab 
5160c0d06caSMauro Carvalho Chehab 	switch (ctrl->id) {
5170c0d06caSMauro Carvalho Chehab 	case V4L2_CID_BRIGHTNESS:
5180c0d06caSMauro Carvalho Chehab 		setbrightness(gspca_dev, ctrl->val);
5190c0d06caSMauro Carvalho Chehab 		break;
5200c0d06caSMauro Carvalho Chehab 	case V4L2_CID_CONTRAST:
5210c0d06caSMauro Carvalho Chehab 		setcontrast(gspca_dev, ctrl->val);
5220c0d06caSMauro Carvalho Chehab 		break;
5230c0d06caSMauro Carvalho Chehab 	case V4L2_CID_SATURATION:
5240c0d06caSMauro Carvalho Chehab 		setcolors(gspca_dev, ctrl->val);
5250c0d06caSMauro Carvalho Chehab 		break;
5260c0d06caSMauro Carvalho Chehab 	case V4L2_CID_HUE:
5270c0d06caSMauro Carvalho Chehab 		sethue(gspca_dev, ctrl->val);
5280c0d06caSMauro Carvalho Chehab 		break;
5290c0d06caSMauro Carvalho Chehab 	}
5300c0d06caSMauro Carvalho Chehab 	return gspca_dev->usb_err;
5310c0d06caSMauro Carvalho Chehab }
5320c0d06caSMauro Carvalho Chehab 
5330c0d06caSMauro Carvalho Chehab static const struct v4l2_ctrl_ops sd_ctrl_ops = {
5340c0d06caSMauro Carvalho Chehab 	.s_ctrl = sd_s_ctrl,
5350c0d06caSMauro Carvalho Chehab };
5360c0d06caSMauro Carvalho Chehab 
sd_init_controls(struct gspca_dev * gspca_dev)5370c0d06caSMauro Carvalho Chehab static int sd_init_controls(struct gspca_dev *gspca_dev)
5380c0d06caSMauro Carvalho Chehab {
5390c0d06caSMauro Carvalho Chehab 	struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
5400c0d06caSMauro Carvalho Chehab 
5410c0d06caSMauro Carvalho Chehab 	gspca_dev->vdev.ctrl_handler = hdl;
5420c0d06caSMauro Carvalho Chehab 	v4l2_ctrl_handler_init(hdl, 4);
5430c0d06caSMauro Carvalho Chehab 	v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
5440c0d06caSMauro Carvalho Chehab 			V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
5450c0d06caSMauro Carvalho Chehab 	v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
5460c0d06caSMauro Carvalho Chehab 			V4L2_CID_CONTRAST, 0, 255, 1, 0x47);
5470c0d06caSMauro Carvalho Chehab 	v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
5480c0d06caSMauro Carvalho Chehab 			V4L2_CID_SATURATION, 0, 255, 1, 0x40);
5490c0d06caSMauro Carvalho Chehab 	v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
5500c0d06caSMauro Carvalho Chehab 			V4L2_CID_HUE, 0, 255, 1, 0);
5510c0d06caSMauro Carvalho Chehab 
5520c0d06caSMauro Carvalho Chehab 	if (hdl->error) {
5530c0d06caSMauro Carvalho Chehab 		pr_err("Could not initialize controls\n");
5540c0d06caSMauro Carvalho Chehab 		return hdl->error;
5550c0d06caSMauro Carvalho Chehab 	}
5560c0d06caSMauro Carvalho Chehab 	return 0;
5570c0d06caSMauro Carvalho Chehab }
5580c0d06caSMauro Carvalho Chehab 
5590c0d06caSMauro Carvalho Chehab /* sub-driver description */
5600c0d06caSMauro Carvalho Chehab static const struct sd_desc sd_desc = {
5610c0d06caSMauro Carvalho Chehab 	.name = MODULE_NAME,
5620c0d06caSMauro Carvalho Chehab 	.config = sd_config,
5630c0d06caSMauro Carvalho Chehab 	.init = sd_init,
5640c0d06caSMauro Carvalho Chehab 	.init_controls = sd_init_controls,
5650c0d06caSMauro Carvalho Chehab 	.start = sd_start,
5660c0d06caSMauro Carvalho Chehab 	.stopN = sd_stopN,
5670c0d06caSMauro Carvalho Chehab 	.pkt_scan = sd_pkt_scan,
5680c0d06caSMauro Carvalho Chehab };
5690c0d06caSMauro Carvalho Chehab 
5700c0d06caSMauro Carvalho Chehab /* -- module initialisation -- */
57179e8c7beSMauro Carvalho Chehab static const struct usb_device_id device_table[] = {
5720c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0x06e1, 0xa190)},
5730889e4a1SMauro Carvalho Chehab /*	{USB_DEVICE(0x0733, 0x0430)}, FIXME: may be IntelPCCameraPro BRIDGE_SPCA505 */
5740c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0x0734, 0x043b)},
5750c0d06caSMauro Carvalho Chehab 	{USB_DEVICE(0x99fa, 0x8988)},
5760c0d06caSMauro Carvalho Chehab 	{}
5770c0d06caSMauro Carvalho Chehab };
5780c0d06caSMauro Carvalho Chehab MODULE_DEVICE_TABLE(usb, device_table);
5790c0d06caSMauro Carvalho Chehab 
5800c0d06caSMauro Carvalho Chehab /* -- device connect -- */
sd_probe(struct usb_interface * intf,const struct usb_device_id * id)5814c62e976SGreg Kroah-Hartman static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id)
5820c0d06caSMauro Carvalho Chehab {
5830c0d06caSMauro Carvalho Chehab 	return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
5840c0d06caSMauro Carvalho Chehab 				THIS_MODULE);
5850c0d06caSMauro Carvalho Chehab }
5860c0d06caSMauro Carvalho Chehab 
5870c0d06caSMauro Carvalho Chehab static struct usb_driver sd_driver = {
5880c0d06caSMauro Carvalho Chehab 	.name = MODULE_NAME,
5890c0d06caSMauro Carvalho Chehab 	.id_table = device_table,
5900c0d06caSMauro Carvalho Chehab 	.probe = sd_probe,
5910c0d06caSMauro Carvalho Chehab 	.disconnect = gspca_disconnect,
5920c0d06caSMauro Carvalho Chehab #ifdef CONFIG_PM
5930c0d06caSMauro Carvalho Chehab 	.suspend = gspca_suspend,
5940c0d06caSMauro Carvalho Chehab 	.resume = gspca_resume,
5950c0d06caSMauro Carvalho Chehab 	.reset_resume = gspca_resume,
5960c0d06caSMauro Carvalho Chehab #endif
5970c0d06caSMauro Carvalho Chehab };
5980c0d06caSMauro Carvalho Chehab 
5990c0d06caSMauro Carvalho Chehab module_usb_driver(sd_driver);
600