xref: /OK3568_Linux_fs/kernel/drivers/media/usb/gspca/sn9c2028.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-or-later
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * SN9C2028 library
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (C) 2009 Theodore Kilgore <kilgota@auburn.edu>
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun #define MODULE_NAME "sn9c2028"
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #include "gspca.h"
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun MODULE_AUTHOR("Theodore Kilgore");
15*4882a593Smuzhiyun MODULE_DESCRIPTION("Sonix SN9C2028 USB Camera Driver");
16*4882a593Smuzhiyun MODULE_LICENSE("GPL");
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun /* specific webcam descriptor */
19*4882a593Smuzhiyun struct sd {
20*4882a593Smuzhiyun 	struct gspca_dev gspca_dev;  /* !! must be the first item */
21*4882a593Smuzhiyun 	u8 sof_read;
22*4882a593Smuzhiyun 	u16 model;
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun #define MIN_AVG_LUM 8500
25*4882a593Smuzhiyun #define MAX_AVG_LUM 10000
26*4882a593Smuzhiyun 	int avg_lum;
27*4882a593Smuzhiyun 	u8 avg_lum_l;
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun 	struct { /* autogain and gain control cluster */
30*4882a593Smuzhiyun 		struct v4l2_ctrl *autogain;
31*4882a593Smuzhiyun 		struct v4l2_ctrl *gain;
32*4882a593Smuzhiyun 	};
33*4882a593Smuzhiyun };
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun struct init_command {
36*4882a593Smuzhiyun 	unsigned char instruction[6];
37*4882a593Smuzhiyun 	unsigned char to_read; /* length to read. 0 means no reply requested */
38*4882a593Smuzhiyun };
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun /* How to change the resolution of any of the VGA cams is unknown */
41*4882a593Smuzhiyun static const struct v4l2_pix_format vga_mode[] = {
42*4882a593Smuzhiyun 	{640, 480, V4L2_PIX_FMT_SN9C2028, V4L2_FIELD_NONE,
43*4882a593Smuzhiyun 		.bytesperline = 640,
44*4882a593Smuzhiyun 		.sizeimage = 640 * 480 * 3 / 4,
45*4882a593Smuzhiyun 		.colorspace = V4L2_COLORSPACE_SRGB,
46*4882a593Smuzhiyun 		.priv = 0},
47*4882a593Smuzhiyun };
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun /* No way to change the resolution of the CIF cams is known */
50*4882a593Smuzhiyun static const struct v4l2_pix_format cif_mode[] = {
51*4882a593Smuzhiyun 	{352, 288, V4L2_PIX_FMT_SN9C2028, V4L2_FIELD_NONE,
52*4882a593Smuzhiyun 		.bytesperline = 352,
53*4882a593Smuzhiyun 		.sizeimage = 352 * 288 * 3 / 4,
54*4882a593Smuzhiyun 		.colorspace = V4L2_COLORSPACE_SRGB,
55*4882a593Smuzhiyun 		.priv = 0},
56*4882a593Smuzhiyun };
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun /* the bytes to write are in gspca_dev->usb_buf */
sn9c2028_command(struct gspca_dev * gspca_dev,u8 * command)59*4882a593Smuzhiyun static int sn9c2028_command(struct gspca_dev *gspca_dev, u8 *command)
60*4882a593Smuzhiyun {
61*4882a593Smuzhiyun 	int rc;
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun 	gspca_dbg(gspca_dev, D_USBO, "sending command %02x%02x%02x%02x%02x%02x\n",
64*4882a593Smuzhiyun 		  command[0], command[1], command[2],
65*4882a593Smuzhiyun 		  command[3], command[4], command[5]);
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun 	memcpy(gspca_dev->usb_buf, command, 6);
68*4882a593Smuzhiyun 	rc = usb_control_msg(gspca_dev->dev,
69*4882a593Smuzhiyun 			usb_sndctrlpipe(gspca_dev->dev, 0),
70*4882a593Smuzhiyun 			USB_REQ_GET_CONFIGURATION,
71*4882a593Smuzhiyun 			USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
72*4882a593Smuzhiyun 			2, 0, gspca_dev->usb_buf, 6, 500);
73*4882a593Smuzhiyun 	if (rc < 0) {
74*4882a593Smuzhiyun 		pr_err("command write [%02x] error %d\n",
75*4882a593Smuzhiyun 		       gspca_dev->usb_buf[0], rc);
76*4882a593Smuzhiyun 		return rc;
77*4882a593Smuzhiyun 	}
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun 	return 0;
80*4882a593Smuzhiyun }
81*4882a593Smuzhiyun 
sn9c2028_read1(struct gspca_dev * gspca_dev)82*4882a593Smuzhiyun static int sn9c2028_read1(struct gspca_dev *gspca_dev)
83*4882a593Smuzhiyun {
84*4882a593Smuzhiyun 	int rc;
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun 	rc = usb_control_msg(gspca_dev->dev,
87*4882a593Smuzhiyun 			usb_rcvctrlpipe(gspca_dev->dev, 0),
88*4882a593Smuzhiyun 			USB_REQ_GET_STATUS,
89*4882a593Smuzhiyun 			USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
90*4882a593Smuzhiyun 			1, 0, gspca_dev->usb_buf, 1, 500);
91*4882a593Smuzhiyun 	if (rc != 1) {
92*4882a593Smuzhiyun 		pr_err("read1 error %d\n", rc);
93*4882a593Smuzhiyun 		return (rc < 0) ? rc : -EIO;
94*4882a593Smuzhiyun 	}
95*4882a593Smuzhiyun 	gspca_dbg(gspca_dev, D_USBI, "read1 response %02x\n",
96*4882a593Smuzhiyun 		  gspca_dev->usb_buf[0]);
97*4882a593Smuzhiyun 	return gspca_dev->usb_buf[0];
98*4882a593Smuzhiyun }
99*4882a593Smuzhiyun 
sn9c2028_read4(struct gspca_dev * gspca_dev,u8 * reading)100*4882a593Smuzhiyun static int sn9c2028_read4(struct gspca_dev *gspca_dev, u8 *reading)
101*4882a593Smuzhiyun {
102*4882a593Smuzhiyun 	int rc;
103*4882a593Smuzhiyun 	rc = usb_control_msg(gspca_dev->dev,
104*4882a593Smuzhiyun 			usb_rcvctrlpipe(gspca_dev->dev, 0),
105*4882a593Smuzhiyun 			USB_REQ_GET_STATUS,
106*4882a593Smuzhiyun 			USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
107*4882a593Smuzhiyun 			4, 0, gspca_dev->usb_buf, 4, 500);
108*4882a593Smuzhiyun 	if (rc != 4) {
109*4882a593Smuzhiyun 		pr_err("read4 error %d\n", rc);
110*4882a593Smuzhiyun 		return (rc < 0) ? rc : -EIO;
111*4882a593Smuzhiyun 	}
112*4882a593Smuzhiyun 	memcpy(reading, gspca_dev->usb_buf, 4);
113*4882a593Smuzhiyun 	gspca_dbg(gspca_dev, D_USBI, "read4 response %02x%02x%02x%02x\n",
114*4882a593Smuzhiyun 		  reading[0], reading[1], reading[2], reading[3]);
115*4882a593Smuzhiyun 	return rc;
116*4882a593Smuzhiyun }
117*4882a593Smuzhiyun 
sn9c2028_long_command(struct gspca_dev * gspca_dev,u8 * command)118*4882a593Smuzhiyun static int sn9c2028_long_command(struct gspca_dev *gspca_dev, u8 *command)
119*4882a593Smuzhiyun {
120*4882a593Smuzhiyun 	int i, status;
121*4882a593Smuzhiyun 	__u8 reading[4];
122*4882a593Smuzhiyun 
123*4882a593Smuzhiyun 	status = sn9c2028_command(gspca_dev, command);
124*4882a593Smuzhiyun 	if (status < 0)
125*4882a593Smuzhiyun 		return status;
126*4882a593Smuzhiyun 
127*4882a593Smuzhiyun 	status = -1;
128*4882a593Smuzhiyun 	for (i = 0; i < 256 && status < 2; i++)
129*4882a593Smuzhiyun 		status = sn9c2028_read1(gspca_dev);
130*4882a593Smuzhiyun 	if (status < 0) {
131*4882a593Smuzhiyun 		pr_err("long command status read error %d\n", status);
132*4882a593Smuzhiyun 		return status;
133*4882a593Smuzhiyun 	}
134*4882a593Smuzhiyun 
135*4882a593Smuzhiyun 	memset(reading, 0, 4);
136*4882a593Smuzhiyun 	status = sn9c2028_read4(gspca_dev, reading);
137*4882a593Smuzhiyun 	if (status < 0)
138*4882a593Smuzhiyun 		return status;
139*4882a593Smuzhiyun 
140*4882a593Smuzhiyun 	/* in general, the first byte of the response is the first byte of
141*4882a593Smuzhiyun 	 * the command, or'ed with 8 */
142*4882a593Smuzhiyun 	status = sn9c2028_read1(gspca_dev);
143*4882a593Smuzhiyun 	if (status < 0)
144*4882a593Smuzhiyun 		return status;
145*4882a593Smuzhiyun 
146*4882a593Smuzhiyun 	return 0;
147*4882a593Smuzhiyun }
148*4882a593Smuzhiyun 
sn9c2028_short_command(struct gspca_dev * gspca_dev,u8 * command)149*4882a593Smuzhiyun static int sn9c2028_short_command(struct gspca_dev *gspca_dev, u8 *command)
150*4882a593Smuzhiyun {
151*4882a593Smuzhiyun 	int err_code;
152*4882a593Smuzhiyun 
153*4882a593Smuzhiyun 	err_code = sn9c2028_command(gspca_dev, command);
154*4882a593Smuzhiyun 	if (err_code < 0)
155*4882a593Smuzhiyun 		return err_code;
156*4882a593Smuzhiyun 
157*4882a593Smuzhiyun 	err_code = sn9c2028_read1(gspca_dev);
158*4882a593Smuzhiyun 	if (err_code < 0)
159*4882a593Smuzhiyun 		return err_code;
160*4882a593Smuzhiyun 
161*4882a593Smuzhiyun 	return 0;
162*4882a593Smuzhiyun }
163*4882a593Smuzhiyun 
164*4882a593Smuzhiyun /* this function is called at probe time */
sd_config(struct gspca_dev * gspca_dev,const struct usb_device_id * id)165*4882a593Smuzhiyun static int sd_config(struct gspca_dev *gspca_dev,
166*4882a593Smuzhiyun 		     const struct usb_device_id *id)
167*4882a593Smuzhiyun {
168*4882a593Smuzhiyun 	struct sd *sd = (struct sd *) gspca_dev;
169*4882a593Smuzhiyun 	struct cam *cam = &gspca_dev->cam;
170*4882a593Smuzhiyun 
171*4882a593Smuzhiyun 	gspca_dbg(gspca_dev, D_PROBE, "SN9C2028 camera detected (vid/pid 0x%04X:0x%04X)\n",
172*4882a593Smuzhiyun 		  id->idVendor, id->idProduct);
173*4882a593Smuzhiyun 
174*4882a593Smuzhiyun 	sd->model = id->idProduct;
175*4882a593Smuzhiyun 
176*4882a593Smuzhiyun 	switch (sd->model) {
177*4882a593Smuzhiyun 	case 0x7005:
178*4882a593Smuzhiyun 		gspca_dbg(gspca_dev, D_PROBE, "Genius Smart 300 camera\n");
179*4882a593Smuzhiyun 		break;
180*4882a593Smuzhiyun 	case 0x7003:
181*4882a593Smuzhiyun 		gspca_dbg(gspca_dev, D_PROBE, "Genius Videocam Live v2\n");
182*4882a593Smuzhiyun 		break;
183*4882a593Smuzhiyun 	case 0x8000:
184*4882a593Smuzhiyun 		gspca_dbg(gspca_dev, D_PROBE, "DC31VC\n");
185*4882a593Smuzhiyun 		break;
186*4882a593Smuzhiyun 	case 0x8001:
187*4882a593Smuzhiyun 		gspca_dbg(gspca_dev, D_PROBE, "Spy camera\n");
188*4882a593Smuzhiyun 		break;
189*4882a593Smuzhiyun 	case 0x8003:
190*4882a593Smuzhiyun 		gspca_dbg(gspca_dev, D_PROBE, "CIF camera\n");
191*4882a593Smuzhiyun 		break;
192*4882a593Smuzhiyun 	case 0x8008:
193*4882a593Smuzhiyun 		gspca_dbg(gspca_dev, D_PROBE, "Mini-Shotz ms-350 camera\n");
194*4882a593Smuzhiyun 		break;
195*4882a593Smuzhiyun 	case 0x800a:
196*4882a593Smuzhiyun 		gspca_dbg(gspca_dev, D_PROBE, "Vivitar 3350b type camera\n");
197*4882a593Smuzhiyun 		cam->input_flags = V4L2_IN_ST_VFLIP | V4L2_IN_ST_HFLIP;
198*4882a593Smuzhiyun 		break;
199*4882a593Smuzhiyun 	}
200*4882a593Smuzhiyun 
201*4882a593Smuzhiyun 	switch (sd->model) {
202*4882a593Smuzhiyun 	case 0x8000:
203*4882a593Smuzhiyun 	case 0x8001:
204*4882a593Smuzhiyun 	case 0x8003:
205*4882a593Smuzhiyun 		cam->cam_mode = cif_mode;
206*4882a593Smuzhiyun 		cam->nmodes = ARRAY_SIZE(cif_mode);
207*4882a593Smuzhiyun 		break;
208*4882a593Smuzhiyun 	default:
209*4882a593Smuzhiyun 		cam->cam_mode = vga_mode;
210*4882a593Smuzhiyun 		cam->nmodes = ARRAY_SIZE(vga_mode);
211*4882a593Smuzhiyun 	}
212*4882a593Smuzhiyun 	return 0;
213*4882a593Smuzhiyun }
214*4882a593Smuzhiyun 
215*4882a593Smuzhiyun /* this function is called at probe and resume time */
sd_init(struct gspca_dev * gspca_dev)216*4882a593Smuzhiyun static int sd_init(struct gspca_dev *gspca_dev)
217*4882a593Smuzhiyun {
218*4882a593Smuzhiyun 	int status;
219*4882a593Smuzhiyun 
220*4882a593Smuzhiyun 	sn9c2028_read1(gspca_dev);
221*4882a593Smuzhiyun 	sn9c2028_read1(gspca_dev);
222*4882a593Smuzhiyun 	status = sn9c2028_read1(gspca_dev);
223*4882a593Smuzhiyun 
224*4882a593Smuzhiyun 	return (status < 0) ? status : 0;
225*4882a593Smuzhiyun }
226*4882a593Smuzhiyun 
run_start_commands(struct gspca_dev * gspca_dev,struct init_command * cam_commands,int n)227*4882a593Smuzhiyun static int run_start_commands(struct gspca_dev *gspca_dev,
228*4882a593Smuzhiyun 			      struct init_command *cam_commands, int n)
229*4882a593Smuzhiyun {
230*4882a593Smuzhiyun 	int i, err_code = -1;
231*4882a593Smuzhiyun 
232*4882a593Smuzhiyun 	for (i = 0; i < n; i++) {
233*4882a593Smuzhiyun 		switch (cam_commands[i].to_read) {
234*4882a593Smuzhiyun 		case 4:
235*4882a593Smuzhiyun 			err_code = sn9c2028_long_command(gspca_dev,
236*4882a593Smuzhiyun 					cam_commands[i].instruction);
237*4882a593Smuzhiyun 			break;
238*4882a593Smuzhiyun 		case 1:
239*4882a593Smuzhiyun 			err_code = sn9c2028_short_command(gspca_dev,
240*4882a593Smuzhiyun 					cam_commands[i].instruction);
241*4882a593Smuzhiyun 			break;
242*4882a593Smuzhiyun 		case 0:
243*4882a593Smuzhiyun 			err_code = sn9c2028_command(gspca_dev,
244*4882a593Smuzhiyun 					cam_commands[i].instruction);
245*4882a593Smuzhiyun 			break;
246*4882a593Smuzhiyun 		}
247*4882a593Smuzhiyun 		if (err_code < 0)
248*4882a593Smuzhiyun 			return err_code;
249*4882a593Smuzhiyun 	}
250*4882a593Smuzhiyun 	return 0;
251*4882a593Smuzhiyun }
252*4882a593Smuzhiyun 
set_gain(struct gspca_dev * gspca_dev,s32 g)253*4882a593Smuzhiyun static void set_gain(struct gspca_dev *gspca_dev, s32 g)
254*4882a593Smuzhiyun {
255*4882a593Smuzhiyun 	struct sd *sd = (struct sd *) gspca_dev;
256*4882a593Smuzhiyun 
257*4882a593Smuzhiyun 	struct init_command genius_vcam_live_gain_cmds[] = {
258*4882a593Smuzhiyun 		{{0x1d, 0x25, 0x10 /* This byte is gain */,
259*4882a593Smuzhiyun 		  0x20, 0xab, 0x00}, 0},
260*4882a593Smuzhiyun 	};
261*4882a593Smuzhiyun 	if (!gspca_dev->streaming)
262*4882a593Smuzhiyun 		return;
263*4882a593Smuzhiyun 
264*4882a593Smuzhiyun 	switch (sd->model) {
265*4882a593Smuzhiyun 	case 0x7003:
266*4882a593Smuzhiyun 		genius_vcam_live_gain_cmds[0].instruction[2] = g;
267*4882a593Smuzhiyun 		run_start_commands(gspca_dev, genius_vcam_live_gain_cmds,
268*4882a593Smuzhiyun 				   ARRAY_SIZE(genius_vcam_live_gain_cmds));
269*4882a593Smuzhiyun 		break;
270*4882a593Smuzhiyun 	default:
271*4882a593Smuzhiyun 		break;
272*4882a593Smuzhiyun 	}
273*4882a593Smuzhiyun }
274*4882a593Smuzhiyun 
sd_s_ctrl(struct v4l2_ctrl * ctrl)275*4882a593Smuzhiyun static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
276*4882a593Smuzhiyun {
277*4882a593Smuzhiyun 	struct gspca_dev *gspca_dev =
278*4882a593Smuzhiyun 		container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
279*4882a593Smuzhiyun 	struct sd *sd = (struct sd *)gspca_dev;
280*4882a593Smuzhiyun 
281*4882a593Smuzhiyun 	gspca_dev->usb_err = 0;
282*4882a593Smuzhiyun 
283*4882a593Smuzhiyun 	if (!gspca_dev->streaming)
284*4882a593Smuzhiyun 		return 0;
285*4882a593Smuzhiyun 
286*4882a593Smuzhiyun 	switch (ctrl->id) {
287*4882a593Smuzhiyun 	/* standalone gain control */
288*4882a593Smuzhiyun 	case V4L2_CID_GAIN:
289*4882a593Smuzhiyun 		set_gain(gspca_dev, ctrl->val);
290*4882a593Smuzhiyun 		break;
291*4882a593Smuzhiyun 	/* autogain */
292*4882a593Smuzhiyun 	case V4L2_CID_AUTOGAIN:
293*4882a593Smuzhiyun 		set_gain(gspca_dev, sd->gain->val);
294*4882a593Smuzhiyun 		break;
295*4882a593Smuzhiyun 	}
296*4882a593Smuzhiyun 	return gspca_dev->usb_err;
297*4882a593Smuzhiyun }
298*4882a593Smuzhiyun 
299*4882a593Smuzhiyun static const struct v4l2_ctrl_ops sd_ctrl_ops = {
300*4882a593Smuzhiyun 	.s_ctrl = sd_s_ctrl,
301*4882a593Smuzhiyun };
302*4882a593Smuzhiyun 
303*4882a593Smuzhiyun 
sd_init_controls(struct gspca_dev * gspca_dev)304*4882a593Smuzhiyun static int sd_init_controls(struct gspca_dev *gspca_dev)
305*4882a593Smuzhiyun {
306*4882a593Smuzhiyun 	struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
307*4882a593Smuzhiyun 	struct sd *sd = (struct sd *)gspca_dev;
308*4882a593Smuzhiyun 
309*4882a593Smuzhiyun 	gspca_dev->vdev.ctrl_handler = hdl;
310*4882a593Smuzhiyun 	v4l2_ctrl_handler_init(hdl, 2);
311*4882a593Smuzhiyun 
312*4882a593Smuzhiyun 	switch (sd->model) {
313*4882a593Smuzhiyun 	case 0x7003:
314*4882a593Smuzhiyun 		sd->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
315*4882a593Smuzhiyun 			V4L2_CID_GAIN, 0, 20, 1, 0);
316*4882a593Smuzhiyun 		sd->autogain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
317*4882a593Smuzhiyun 			V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
318*4882a593Smuzhiyun 		break;
319*4882a593Smuzhiyun 	default:
320*4882a593Smuzhiyun 		break;
321*4882a593Smuzhiyun 	}
322*4882a593Smuzhiyun 
323*4882a593Smuzhiyun 	return 0;
324*4882a593Smuzhiyun }
start_spy_cam(struct gspca_dev * gspca_dev)325*4882a593Smuzhiyun static int start_spy_cam(struct gspca_dev *gspca_dev)
326*4882a593Smuzhiyun {
327*4882a593Smuzhiyun 	struct init_command spy_start_commands[] = {
328*4882a593Smuzhiyun 		{{0x0c, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
329*4882a593Smuzhiyun 		{{0x13, 0x20, 0x01, 0x00, 0x00, 0x00}, 4},
330*4882a593Smuzhiyun 		{{0x13, 0x21, 0x01, 0x00, 0x00, 0x00}, 4},
331*4882a593Smuzhiyun 		{{0x13, 0x22, 0x01, 0x04, 0x00, 0x00}, 4},
332*4882a593Smuzhiyun 		{{0x13, 0x23, 0x01, 0x03, 0x00, 0x00}, 4},
333*4882a593Smuzhiyun 		{{0x13, 0x24, 0x01, 0x00, 0x00, 0x00}, 4},
334*4882a593Smuzhiyun 		{{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 4}, /* width  352 */
335*4882a593Smuzhiyun 		{{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 4}, /* height 288 */
336*4882a593Smuzhiyun 		/* {{0x13, 0x27, 0x01, 0x28, 0x00, 0x00}, 4}, */
337*4882a593Smuzhiyun 		{{0x13, 0x27, 0x01, 0x68, 0x00, 0x00}, 4},
338*4882a593Smuzhiyun 		{{0x13, 0x28, 0x01, 0x09, 0x00, 0x00}, 4}, /* red gain ?*/
339*4882a593Smuzhiyun 		/* {{0x13, 0x28, 0x01, 0x00, 0x00, 0x00}, 4}, */
340*4882a593Smuzhiyun 		{{0x13, 0x29, 0x01, 0x00, 0x00, 0x00}, 4},
341*4882a593Smuzhiyun 		/* {{0x13, 0x29, 0x01, 0x0c, 0x00, 0x00}, 4}, */
342*4882a593Smuzhiyun 		{{0x13, 0x2a, 0x01, 0x00, 0x00, 0x00}, 4},
343*4882a593Smuzhiyun 		{{0x13, 0x2b, 0x01, 0x00, 0x00, 0x00}, 4},
344*4882a593Smuzhiyun 		/* {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4}, */
345*4882a593Smuzhiyun 		{{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
346*4882a593Smuzhiyun 		{{0x13, 0x2d, 0x01, 0x02, 0x00, 0x00}, 4},
347*4882a593Smuzhiyun 		/* {{0x13, 0x2e, 0x01, 0x09, 0x00, 0x00}, 4}, */
348*4882a593Smuzhiyun 		{{0x13, 0x2e, 0x01, 0x09, 0x00, 0x00}, 4},
349*4882a593Smuzhiyun 		{{0x13, 0x2f, 0x01, 0x07, 0x00, 0x00}, 4},
350*4882a593Smuzhiyun 		{{0x12, 0x34, 0x01, 0x00, 0x00, 0x00}, 4},
351*4882a593Smuzhiyun 		{{0x13, 0x34, 0x01, 0xa1, 0x00, 0x00}, 4},
352*4882a593Smuzhiyun 		{{0x13, 0x35, 0x01, 0x00, 0x00, 0x00}, 4},
353*4882a593Smuzhiyun 		{{0x11, 0x02, 0x06, 0x00, 0x00, 0x00}, 4},
354*4882a593Smuzhiyun 		{{0x11, 0x03, 0x13, 0x00, 0x00, 0x00}, 4}, /*don't mess with*/
355*4882a593Smuzhiyun 		/*{{0x11, 0x04, 0x06, 0x00, 0x00, 0x00}, 4}, observed */
356*4882a593Smuzhiyun 		{{0x11, 0x04, 0x00, 0x00, 0x00, 0x00}, 4}, /* brighter */
357*4882a593Smuzhiyun 		/*{{0x11, 0x05, 0x65, 0x00, 0x00, 0x00}, 4}, observed */
358*4882a593Smuzhiyun 		{{0x11, 0x05, 0x00, 0x00, 0x00, 0x00}, 4}, /* brighter */
359*4882a593Smuzhiyun 		{{0x11, 0x06, 0xb1, 0x00, 0x00, 0x00}, 4}, /* observed */
360*4882a593Smuzhiyun 		{{0x11, 0x07, 0x00, 0x00, 0x00, 0x00}, 4},
361*4882a593Smuzhiyun 		/*{{0x11, 0x08, 0x06, 0x00, 0x00, 0x00}, 4}, observed */
362*4882a593Smuzhiyun 		{{0x11, 0x08, 0x0b, 0x00, 0x00, 0x00}, 4},
363*4882a593Smuzhiyun 		{{0x11, 0x09, 0x01, 0x00, 0x00, 0x00}, 4},
364*4882a593Smuzhiyun 		{{0x11, 0x0a, 0x01, 0x00, 0x00, 0x00}, 4},
365*4882a593Smuzhiyun 		{{0x11, 0x0b, 0x01, 0x00, 0x00, 0x00}, 4},
366*4882a593Smuzhiyun 		{{0x11, 0x0c, 0x01, 0x00, 0x00, 0x00}, 4},
367*4882a593Smuzhiyun 		{{0x11, 0x0d, 0x00, 0x00, 0x00, 0x00}, 4},
368*4882a593Smuzhiyun 		{{0x11, 0x0e, 0x04, 0x00, 0x00, 0x00}, 4},
369*4882a593Smuzhiyun 		/* {{0x11, 0x0f, 0x00, 0x00, 0x00, 0x00}, 4}, */
370*4882a593Smuzhiyun 		/* brightness or gain. 0 is default. 4 is good
371*4882a593Smuzhiyun 		 * indoors at night with incandescent lighting */
372*4882a593Smuzhiyun 		{{0x11, 0x0f, 0x04, 0x00, 0x00, 0x00}, 4},
373*4882a593Smuzhiyun 		{{0x11, 0x10, 0x06, 0x00, 0x00, 0x00}, 4}, /*hstart or hoffs*/
374*4882a593Smuzhiyun 		{{0x11, 0x11, 0x06, 0x00, 0x00, 0x00}, 4},
375*4882a593Smuzhiyun 		{{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4},
376*4882a593Smuzhiyun 		{{0x11, 0x14, 0x02, 0x00, 0x00, 0x00}, 4},
377*4882a593Smuzhiyun 		{{0x11, 0x13, 0x01, 0x00, 0x00, 0x00}, 4},
378*4882a593Smuzhiyun 		/* {{0x1b, 0x02, 0x06, 0x00, 0x00, 0x00}, 1}, observed */
379*4882a593Smuzhiyun 		{{0x1b, 0x02, 0x11, 0x00, 0x00, 0x00}, 1}, /* brighter */
380*4882a593Smuzhiyun 		/* {{0x1b, 0x13, 0x01, 0x00, 0x00, 0x00}, 1}, observed */
381*4882a593Smuzhiyun 		{{0x1b, 0x13, 0x11, 0x00, 0x00, 0x00}, 1},
382*4882a593Smuzhiyun 		{{0x20, 0x34, 0xa1, 0x00, 0x00, 0x00}, 1}, /* compresses */
383*4882a593Smuzhiyun 		/* Camera should start to capture now. */
384*4882a593Smuzhiyun 	};
385*4882a593Smuzhiyun 
386*4882a593Smuzhiyun 	return run_start_commands(gspca_dev, spy_start_commands,
387*4882a593Smuzhiyun 				  ARRAY_SIZE(spy_start_commands));
388*4882a593Smuzhiyun }
389*4882a593Smuzhiyun 
start_cif_cam(struct gspca_dev * gspca_dev)390*4882a593Smuzhiyun static int start_cif_cam(struct gspca_dev *gspca_dev)
391*4882a593Smuzhiyun {
392*4882a593Smuzhiyun 	struct init_command cif_start_commands[] = {
393*4882a593Smuzhiyun 		{{0x0c, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
394*4882a593Smuzhiyun 		/* The entire sequence below seems redundant */
395*4882a593Smuzhiyun 		/* {{0x13, 0x20, 0x01, 0x00, 0x00, 0x00}, 4},
396*4882a593Smuzhiyun 		{{0x13, 0x21, 0x01, 0x00, 0x00, 0x00}, 4},
397*4882a593Smuzhiyun 		{{0x13, 0x22, 0x01, 0x06, 0x00, 0x00}, 4},
398*4882a593Smuzhiyun 		{{0x13, 0x23, 0x01, 0x02, 0x00, 0x00}, 4},
399*4882a593Smuzhiyun 		{{0x13, 0x24, 0x01, 0x00, 0x00, 0x00}, 4},
400*4882a593Smuzhiyun 		{{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 4}, width?
401*4882a593Smuzhiyun 		{{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 4}, height?
402*4882a593Smuzhiyun 		{{0x13, 0x27, 0x01, 0x68, 0x00, 0x00}, 4}, subsample?
403*4882a593Smuzhiyun 		{{0x13, 0x28, 0x01, 0x00, 0x00, 0x00}, 4},
404*4882a593Smuzhiyun 		{{0x13, 0x29, 0x01, 0x20, 0x00, 0x00}, 4},
405*4882a593Smuzhiyun 		{{0x13, 0x2a, 0x01, 0x00, 0x00, 0x00}, 4},
406*4882a593Smuzhiyun 		{{0x13, 0x2b, 0x01, 0x00, 0x00, 0x00}, 4},
407*4882a593Smuzhiyun 		{{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
408*4882a593Smuzhiyun 		{{0x13, 0x2d, 0x01, 0x03, 0x00, 0x00}, 4},
409*4882a593Smuzhiyun 		{{0x13, 0x2e, 0x01, 0x0f, 0x00, 0x00}, 4},
410*4882a593Smuzhiyun 		{{0x13, 0x2f, 0x01, 0x0c, 0x00, 0x00}, 4},
411*4882a593Smuzhiyun 		{{0x12, 0x34, 0x01, 0x00, 0x00, 0x00}, 4},
412*4882a593Smuzhiyun 		{{0x13, 0x34, 0x01, 0xa1, 0x00, 0x00}, 4},
413*4882a593Smuzhiyun 		{{0x13, 0x35, 0x01, 0x00, 0x00, 0x00}, 4},*/
414*4882a593Smuzhiyun 		{{0x1b, 0x21, 0x00, 0x00, 0x00, 0x00}, 1},
415*4882a593Smuzhiyun 		{{0x1b, 0x17, 0x00, 0x00, 0x00, 0x00}, 1},
416*4882a593Smuzhiyun 		{{0x1b, 0x19, 0x00, 0x00, 0x00, 0x00}, 1},
417*4882a593Smuzhiyun 		{{0x1b, 0x02, 0x06, 0x00, 0x00, 0x00}, 1},
418*4882a593Smuzhiyun 		{{0x1b, 0x03, 0x5a, 0x00, 0x00, 0x00}, 1},
419*4882a593Smuzhiyun 		{{0x1b, 0x04, 0x27, 0x00, 0x00, 0x00}, 1},
420*4882a593Smuzhiyun 		{{0x1b, 0x05, 0x01, 0x00, 0x00, 0x00}, 1},
421*4882a593Smuzhiyun 		{{0x1b, 0x12, 0x14, 0x00, 0x00, 0x00}, 1},
422*4882a593Smuzhiyun 		{{0x1b, 0x13, 0x00, 0x00, 0x00, 0x00}, 1},
423*4882a593Smuzhiyun 		{{0x1b, 0x14, 0x00, 0x00, 0x00, 0x00}, 1},
424*4882a593Smuzhiyun 		{{0x1b, 0x15, 0x00, 0x00, 0x00, 0x00}, 1},
425*4882a593Smuzhiyun 		{{0x1b, 0x16, 0x00, 0x00, 0x00, 0x00}, 1},
426*4882a593Smuzhiyun 		{{0x1b, 0x77, 0xa2, 0x00, 0x00, 0x00}, 1},
427*4882a593Smuzhiyun 		{{0x1b, 0x06, 0x0f, 0x00, 0x00, 0x00}, 1},
428*4882a593Smuzhiyun 		{{0x1b, 0x07, 0x14, 0x00, 0x00, 0x00}, 1},
429*4882a593Smuzhiyun 		{{0x1b, 0x08, 0x0f, 0x00, 0x00, 0x00}, 1},
430*4882a593Smuzhiyun 		{{0x1b, 0x09, 0x10, 0x00, 0x00, 0x00}, 1},
431*4882a593Smuzhiyun 		{{0x1b, 0x0e, 0x00, 0x00, 0x00, 0x00}, 1},
432*4882a593Smuzhiyun 		{{0x1b, 0x0f, 0x00, 0x00, 0x00, 0x00}, 1},
433*4882a593Smuzhiyun 		{{0x1b, 0x12, 0x07, 0x00, 0x00, 0x00}, 1},
434*4882a593Smuzhiyun 		{{0x1b, 0x10, 0x1f, 0x00, 0x00, 0x00}, 1},
435*4882a593Smuzhiyun 		{{0x1b, 0x11, 0x01, 0x00, 0x00, 0x00}, 1},
436*4882a593Smuzhiyun 		{{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 1}, /* width/8 */
437*4882a593Smuzhiyun 		{{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 1}, /* height/8 */
438*4882a593Smuzhiyun 		/* {{0x13, 0x27, 0x01, 0x68, 0x00, 0x00}, 4}, subsample?
439*4882a593Smuzhiyun 		 * {{0x13, 0x28, 0x01, 0x1e, 0x00, 0x00}, 4}, does nothing
440*4882a593Smuzhiyun 		 * {{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4}, */
441*4882a593Smuzhiyun 		/* {{0x13, 0x29, 0x01, 0x22, 0x00, 0x00}, 4},
442*4882a593Smuzhiyun 		 * causes subsampling
443*4882a593Smuzhiyun 		 * but not a change in the resolution setting! */
444*4882a593Smuzhiyun 		{{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
445*4882a593Smuzhiyun 		{{0x13, 0x2d, 0x01, 0x01, 0x00, 0x00}, 4},
446*4882a593Smuzhiyun 		{{0x13, 0x2e, 0x01, 0x08, 0x00, 0x00}, 4},
447*4882a593Smuzhiyun 		{{0x13, 0x2f, 0x01, 0x06, 0x00, 0x00}, 4},
448*4882a593Smuzhiyun 		{{0x13, 0x28, 0x01, 0x00, 0x00, 0x00}, 4},
449*4882a593Smuzhiyun 		{{0x1b, 0x04, 0x6d, 0x00, 0x00, 0x00}, 1},
450*4882a593Smuzhiyun 		{{0x1b, 0x05, 0x03, 0x00, 0x00, 0x00}, 1},
451*4882a593Smuzhiyun 		{{0x20, 0x36, 0x06, 0x00, 0x00, 0x00}, 1},
452*4882a593Smuzhiyun 		{{0x1b, 0x0e, 0x01, 0x00, 0x00, 0x00}, 1},
453*4882a593Smuzhiyun 		{{0x12, 0x27, 0x01, 0x00, 0x00, 0x00}, 4},
454*4882a593Smuzhiyun 		{{0x1b, 0x0f, 0x00, 0x00, 0x00, 0x00}, 1},
455*4882a593Smuzhiyun 		{{0x20, 0x36, 0x05, 0x00, 0x00, 0x00}, 1},
456*4882a593Smuzhiyun 		{{0x1b, 0x10, 0x0f, 0x00, 0x00, 0x00}, 1},
457*4882a593Smuzhiyun 		{{0x1b, 0x02, 0x06, 0x00, 0x00, 0x00}, 1},
458*4882a593Smuzhiyun 		{{0x1b, 0x11, 0x01, 0x00, 0x00, 0x00}, 1},
459*4882a593Smuzhiyun 		{{0x20, 0x34, 0xa1, 0x00, 0x00, 0x00}, 1},/* use compression */
460*4882a593Smuzhiyun 		/* Camera should start to capture now. */
461*4882a593Smuzhiyun 	};
462*4882a593Smuzhiyun 
463*4882a593Smuzhiyun 	return run_start_commands(gspca_dev, cif_start_commands,
464*4882a593Smuzhiyun 				  ARRAY_SIZE(cif_start_commands));
465*4882a593Smuzhiyun }
466*4882a593Smuzhiyun 
start_ms350_cam(struct gspca_dev * gspca_dev)467*4882a593Smuzhiyun static int start_ms350_cam(struct gspca_dev *gspca_dev)
468*4882a593Smuzhiyun {
469*4882a593Smuzhiyun 	struct init_command ms350_start_commands[] = {
470*4882a593Smuzhiyun 		{{0x0c, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
471*4882a593Smuzhiyun 		{{0x16, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
472*4882a593Smuzhiyun 		{{0x13, 0x20, 0x01, 0x00, 0x00, 0x00}, 4},
473*4882a593Smuzhiyun 		{{0x13, 0x21, 0x01, 0x00, 0x00, 0x00}, 4},
474*4882a593Smuzhiyun 		{{0x13, 0x22, 0x01, 0x04, 0x00, 0x00}, 4},
475*4882a593Smuzhiyun 		{{0x13, 0x23, 0x01, 0x03, 0x00, 0x00}, 4},
476*4882a593Smuzhiyun 		{{0x13, 0x24, 0x01, 0x00, 0x00, 0x00}, 4},
477*4882a593Smuzhiyun 		{{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 4},
478*4882a593Smuzhiyun 		{{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 4},
479*4882a593Smuzhiyun 		{{0x13, 0x27, 0x01, 0x28, 0x00, 0x00}, 4},
480*4882a593Smuzhiyun 		{{0x13, 0x28, 0x01, 0x09, 0x00, 0x00}, 4},
481*4882a593Smuzhiyun 		{{0x13, 0x29, 0x01, 0x00, 0x00, 0x00}, 4},
482*4882a593Smuzhiyun 		{{0x13, 0x2a, 0x01, 0x00, 0x00, 0x00}, 4},
483*4882a593Smuzhiyun 		{{0x13, 0x2b, 0x01, 0x00, 0x00, 0x00}, 4},
484*4882a593Smuzhiyun 		{{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
485*4882a593Smuzhiyun 		{{0x13, 0x2d, 0x01, 0x03, 0x00, 0x00}, 4},
486*4882a593Smuzhiyun 		{{0x13, 0x2e, 0x01, 0x0f, 0x00, 0x00}, 4},
487*4882a593Smuzhiyun 		{{0x13, 0x2f, 0x01, 0x0c, 0x00, 0x00}, 4},
488*4882a593Smuzhiyun 		{{0x12, 0x34, 0x01, 0x00, 0x00, 0x00}, 4},
489*4882a593Smuzhiyun 		{{0x13, 0x34, 0x01, 0xa1, 0x00, 0x00}, 4},
490*4882a593Smuzhiyun 		{{0x13, 0x35, 0x01, 0x00, 0x00, 0x00}, 4},
491*4882a593Smuzhiyun 		{{0x11, 0x00, 0x01, 0x00, 0x00, 0x00}, 4},
492*4882a593Smuzhiyun 		{{0x11, 0x01, 0x70, 0x00, 0x00, 0x00}, 4},
493*4882a593Smuzhiyun 		{{0x11, 0x02, 0x05, 0x00, 0x00, 0x00}, 4},
494*4882a593Smuzhiyun 		{{0x11, 0x03, 0x5d, 0x00, 0x00, 0x00}, 4},
495*4882a593Smuzhiyun 		{{0x11, 0x04, 0x07, 0x00, 0x00, 0x00}, 4},
496*4882a593Smuzhiyun 		{{0x11, 0x05, 0x25, 0x00, 0x00, 0x00}, 4},
497*4882a593Smuzhiyun 		{{0x11, 0x06, 0x00, 0x00, 0x00, 0x00}, 4},
498*4882a593Smuzhiyun 		{{0x11, 0x07, 0x09, 0x00, 0x00, 0x00}, 4},
499*4882a593Smuzhiyun 		{{0x11, 0x08, 0x01, 0x00, 0x00, 0x00}, 4},
500*4882a593Smuzhiyun 		{{0x11, 0x09, 0x00, 0x00, 0x00, 0x00}, 4},
501*4882a593Smuzhiyun 		{{0x11, 0x0a, 0x00, 0x00, 0x00, 0x00}, 4},
502*4882a593Smuzhiyun 		{{0x11, 0x0b, 0x01, 0x00, 0x00, 0x00}, 4},
503*4882a593Smuzhiyun 		{{0x11, 0x0c, 0x00, 0x00, 0x00, 0x00}, 4},
504*4882a593Smuzhiyun 		{{0x11, 0x0d, 0x0c, 0x00, 0x00, 0x00}, 4},
505*4882a593Smuzhiyun 		{{0x11, 0x0e, 0x01, 0x00, 0x00, 0x00}, 4},
506*4882a593Smuzhiyun 		{{0x11, 0x0f, 0x00, 0x00, 0x00, 0x00}, 4},
507*4882a593Smuzhiyun 		{{0x11, 0x10, 0x00, 0x00, 0x00, 0x00}, 4},
508*4882a593Smuzhiyun 		{{0x11, 0x11, 0x00, 0x00, 0x00, 0x00}, 4},
509*4882a593Smuzhiyun 		{{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4},
510*4882a593Smuzhiyun 		{{0x11, 0x13, 0x63, 0x00, 0x00, 0x00}, 4},
511*4882a593Smuzhiyun 		{{0x11, 0x15, 0x70, 0x00, 0x00, 0x00}, 4},
512*4882a593Smuzhiyun 		{{0x11, 0x18, 0x00, 0x00, 0x00, 0x00}, 4},
513*4882a593Smuzhiyun 		{{0x11, 0x11, 0x01, 0x00, 0x00, 0x00}, 4},
514*4882a593Smuzhiyun 		{{0x13, 0x25, 0x01, 0x28, 0x00, 0x00}, 4}, /* width  */
515*4882a593Smuzhiyun 		{{0x13, 0x26, 0x01, 0x1e, 0x00, 0x00}, 4}, /* height */
516*4882a593Smuzhiyun 		{{0x13, 0x28, 0x01, 0x09, 0x00, 0x00}, 4}, /* vstart? */
517*4882a593Smuzhiyun 		{{0x13, 0x27, 0x01, 0x28, 0x00, 0x00}, 4},
518*4882a593Smuzhiyun 		{{0x13, 0x29, 0x01, 0x40, 0x00, 0x00}, 4}, /* hstart? */
519*4882a593Smuzhiyun 		{{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
520*4882a593Smuzhiyun 		{{0x13, 0x2d, 0x01, 0x03, 0x00, 0x00}, 4},
521*4882a593Smuzhiyun 		{{0x13, 0x2e, 0x01, 0x0f, 0x00, 0x00}, 4},
522*4882a593Smuzhiyun 		{{0x13, 0x2f, 0x01, 0x0c, 0x00, 0x00}, 4},
523*4882a593Smuzhiyun 		{{0x1b, 0x02, 0x05, 0x00, 0x00, 0x00}, 1},
524*4882a593Smuzhiyun 		{{0x1b, 0x11, 0x01, 0x00, 0x00, 0x00}, 1},
525*4882a593Smuzhiyun 		{{0x20, 0x18, 0x00, 0x00, 0x00, 0x00}, 1},
526*4882a593Smuzhiyun 		{{0x1b, 0x02, 0x0a, 0x00, 0x00, 0x00}, 1},
527*4882a593Smuzhiyun 		{{0x1b, 0x11, 0x01, 0x00, 0x00, 0x00}, 0},
528*4882a593Smuzhiyun 		/* Camera should start to capture now. */
529*4882a593Smuzhiyun 	};
530*4882a593Smuzhiyun 
531*4882a593Smuzhiyun 	return run_start_commands(gspca_dev, ms350_start_commands,
532*4882a593Smuzhiyun 				  ARRAY_SIZE(ms350_start_commands));
533*4882a593Smuzhiyun }
534*4882a593Smuzhiyun 
start_genius_cam(struct gspca_dev * gspca_dev)535*4882a593Smuzhiyun static int start_genius_cam(struct gspca_dev *gspca_dev)
536*4882a593Smuzhiyun {
537*4882a593Smuzhiyun 	struct init_command genius_start_commands[] = {
538*4882a593Smuzhiyun 		{{0x0c, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
539*4882a593Smuzhiyun 		{{0x16, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
540*4882a593Smuzhiyun 		{{0x10, 0x00, 0x00, 0x00, 0x00, 0x00}, 4},
541*4882a593Smuzhiyun 		{{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 4},
542*4882a593Smuzhiyun 		{{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 4},
543*4882a593Smuzhiyun 		/* "preliminary" width and height settings */
544*4882a593Smuzhiyun 		{{0x13, 0x28, 0x01, 0x0e, 0x00, 0x00}, 4},
545*4882a593Smuzhiyun 		{{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4},
546*4882a593Smuzhiyun 		{{0x13, 0x29, 0x01, 0x22, 0x00, 0x00}, 4},
547*4882a593Smuzhiyun 		{{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
548*4882a593Smuzhiyun 		{{0x13, 0x2d, 0x01, 0x02, 0x00, 0x00}, 4},
549*4882a593Smuzhiyun 		{{0x13, 0x2e, 0x01, 0x09, 0x00, 0x00}, 4},
550*4882a593Smuzhiyun 		{{0x13, 0x2f, 0x01, 0x07, 0x00, 0x00}, 4},
551*4882a593Smuzhiyun 		{{0x11, 0x20, 0x00, 0x00, 0x00, 0x00}, 4},
552*4882a593Smuzhiyun 		{{0x11, 0x21, 0x2d, 0x00, 0x00, 0x00}, 4},
553*4882a593Smuzhiyun 		{{0x11, 0x22, 0x00, 0x00, 0x00, 0x00}, 4},
554*4882a593Smuzhiyun 		{{0x11, 0x23, 0x03, 0x00, 0x00, 0x00}, 4},
555*4882a593Smuzhiyun 		{{0x11, 0x10, 0x00, 0x00, 0x00, 0x00}, 4},
556*4882a593Smuzhiyun 		{{0x11, 0x11, 0x64, 0x00, 0x00, 0x00}, 4},
557*4882a593Smuzhiyun 		{{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4},
558*4882a593Smuzhiyun 		{{0x11, 0x13, 0x91, 0x00, 0x00, 0x00}, 4},
559*4882a593Smuzhiyun 		{{0x11, 0x14, 0x01, 0x00, 0x00, 0x00}, 4},
560*4882a593Smuzhiyun 		{{0x11, 0x15, 0x20, 0x00, 0x00, 0x00}, 4},
561*4882a593Smuzhiyun 		{{0x11, 0x16, 0x01, 0x00, 0x00, 0x00}, 4},
562*4882a593Smuzhiyun 		{{0x11, 0x17, 0x60, 0x00, 0x00, 0x00}, 4},
563*4882a593Smuzhiyun 		{{0x11, 0x20, 0x00, 0x00, 0x00, 0x00}, 4},
564*4882a593Smuzhiyun 		{{0x11, 0x21, 0x2d, 0x00, 0x00, 0x00}, 4},
565*4882a593Smuzhiyun 		{{0x11, 0x22, 0x00, 0x00, 0x00, 0x00}, 4},
566*4882a593Smuzhiyun 		{{0x11, 0x23, 0x03, 0x00, 0x00, 0x00}, 4},
567*4882a593Smuzhiyun 		{{0x11, 0x25, 0x00, 0x00, 0x00, 0x00}, 4},
568*4882a593Smuzhiyun 		{{0x11, 0x26, 0x02, 0x00, 0x00, 0x00}, 4},
569*4882a593Smuzhiyun 		{{0x11, 0x27, 0x88, 0x00, 0x00, 0x00}, 4},
570*4882a593Smuzhiyun 		{{0x11, 0x30, 0x38, 0x00, 0x00, 0x00}, 4},
571*4882a593Smuzhiyun 		{{0x11, 0x31, 0x2a, 0x00, 0x00, 0x00}, 4},
572*4882a593Smuzhiyun 		{{0x11, 0x32, 0x2a, 0x00, 0x00, 0x00}, 4},
573*4882a593Smuzhiyun 		{{0x11, 0x33, 0x2a, 0x00, 0x00, 0x00}, 4},
574*4882a593Smuzhiyun 		{{0x11, 0x34, 0x02, 0x00, 0x00, 0x00}, 4},
575*4882a593Smuzhiyun 		{{0x11, 0x5b, 0x0a, 0x00, 0x00, 0x00}, 4},
576*4882a593Smuzhiyun 		{{0x13, 0x25, 0x01, 0x28, 0x00, 0x00}, 4}, /* real width */
577*4882a593Smuzhiyun 		{{0x13, 0x26, 0x01, 0x1e, 0x00, 0x00}, 4}, /* real height */
578*4882a593Smuzhiyun 		{{0x13, 0x28, 0x01, 0x0e, 0x00, 0x00}, 4},
579*4882a593Smuzhiyun 		{{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4},
580*4882a593Smuzhiyun 		{{0x13, 0x29, 0x01, 0x62, 0x00, 0x00}, 4},
581*4882a593Smuzhiyun 		{{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
582*4882a593Smuzhiyun 		{{0x13, 0x2d, 0x01, 0x03, 0x00, 0x00}, 4},
583*4882a593Smuzhiyun 		{{0x13, 0x2e, 0x01, 0x0f, 0x00, 0x00}, 4},
584*4882a593Smuzhiyun 		{{0x13, 0x2f, 0x01, 0x0c, 0x00, 0x00}, 4},
585*4882a593Smuzhiyun 		{{0x11, 0x20, 0x00, 0x00, 0x00, 0x00}, 4},
586*4882a593Smuzhiyun 		{{0x11, 0x21, 0x2a, 0x00, 0x00, 0x00}, 4},
587*4882a593Smuzhiyun 		{{0x11, 0x22, 0x00, 0x00, 0x00, 0x00}, 4},
588*4882a593Smuzhiyun 		{{0x11, 0x23, 0x28, 0x00, 0x00, 0x00}, 4},
589*4882a593Smuzhiyun 		{{0x11, 0x10, 0x00, 0x00, 0x00, 0x00}, 4},
590*4882a593Smuzhiyun 		{{0x11, 0x11, 0x04, 0x00, 0x00, 0x00}, 4},
591*4882a593Smuzhiyun 		{{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4},
592*4882a593Smuzhiyun 		{{0x11, 0x13, 0x03, 0x00, 0x00, 0x00}, 4},
593*4882a593Smuzhiyun 		{{0x11, 0x14, 0x01, 0x00, 0x00, 0x00}, 4},
594*4882a593Smuzhiyun 		{{0x11, 0x15, 0xe0, 0x00, 0x00, 0x00}, 4},
595*4882a593Smuzhiyun 		{{0x11, 0x16, 0x02, 0x00, 0x00, 0x00}, 4},
596*4882a593Smuzhiyun 		{{0x11, 0x17, 0x80, 0x00, 0x00, 0x00}, 4},
597*4882a593Smuzhiyun 		{{0x1c, 0x20, 0x00, 0x2a, 0x00, 0x00}, 1},
598*4882a593Smuzhiyun 		{{0x1c, 0x20, 0x00, 0x2a, 0x00, 0x00}, 1},
599*4882a593Smuzhiyun 		{{0x20, 0x34, 0xa1, 0x00, 0x00, 0x00}, 0}
600*4882a593Smuzhiyun 		/* Camera should start to capture now. */
601*4882a593Smuzhiyun 	};
602*4882a593Smuzhiyun 
603*4882a593Smuzhiyun 	return run_start_commands(gspca_dev, genius_start_commands,
604*4882a593Smuzhiyun 				  ARRAY_SIZE(genius_start_commands));
605*4882a593Smuzhiyun }
606*4882a593Smuzhiyun 
start_genius_videocam_live(struct gspca_dev * gspca_dev)607*4882a593Smuzhiyun static int start_genius_videocam_live(struct gspca_dev *gspca_dev)
608*4882a593Smuzhiyun {
609*4882a593Smuzhiyun 	int r;
610*4882a593Smuzhiyun 	struct sd *sd = (struct sd *) gspca_dev;
611*4882a593Smuzhiyun 	struct init_command genius_vcam_live_start_commands[] = {
612*4882a593Smuzhiyun 		{{0x0c, 0x01, 0x00, 0x00, 0x00, 0x00}, 0},
613*4882a593Smuzhiyun 		{{0x16, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
614*4882a593Smuzhiyun 		{{0x10, 0x00, 0x00, 0x00, 0x00, 0x00}, 4},
615*4882a593Smuzhiyun 		{{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 4},
616*4882a593Smuzhiyun 		{{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 4},
617*4882a593Smuzhiyun 
618*4882a593Smuzhiyun 		{{0x13, 0x28, 0x01, 0x0e, 0x00, 0x00}, 4},
619*4882a593Smuzhiyun 		{{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4},
620*4882a593Smuzhiyun 		{{0x13, 0x29, 0x01, 0x22, 0x00, 0x00}, 4},
621*4882a593Smuzhiyun 		{{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
622*4882a593Smuzhiyun 		{{0x13, 0x2d, 0x01, 0x02, 0x00, 0x00}, 4},
623*4882a593Smuzhiyun 		{{0x13, 0x2e, 0x01, 0x09, 0x00, 0x00}, 4},
624*4882a593Smuzhiyun 		{{0x13, 0x2f, 0x01, 0x07, 0x00, 0x00}, 4},
625*4882a593Smuzhiyun 		{{0x11, 0x20, 0x00, 0x00, 0x00, 0x00}, 4},
626*4882a593Smuzhiyun 		{{0x11, 0x21, 0x2d, 0x00, 0x00, 0x00}, 4},
627*4882a593Smuzhiyun 		{{0x11, 0x22, 0x00, 0x00, 0x00, 0x00}, 4},
628*4882a593Smuzhiyun 		{{0x11, 0x23, 0x03, 0x00, 0x00, 0x00}, 4},
629*4882a593Smuzhiyun 		{{0x11, 0x10, 0x00, 0x00, 0x00, 0x00}, 4},
630*4882a593Smuzhiyun 		{{0x11, 0x11, 0x64, 0x00, 0x00, 0x00}, 4},
631*4882a593Smuzhiyun 		{{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4},
632*4882a593Smuzhiyun 		{{0x11, 0x13, 0x91, 0x00, 0x00, 0x00}, 4},
633*4882a593Smuzhiyun 		{{0x11, 0x14, 0x01, 0x00, 0x00, 0x00}, 4},
634*4882a593Smuzhiyun 		{{0x11, 0x15, 0x20, 0x00, 0x00, 0x00}, 4},
635*4882a593Smuzhiyun 		{{0x11, 0x16, 0x01, 0x00, 0x00, 0x00}, 4},
636*4882a593Smuzhiyun 		{{0x11, 0x17, 0x60, 0x00, 0x00, 0x00}, 4},
637*4882a593Smuzhiyun 		{{0x1c, 0x20, 0x00, 0x2d, 0x00, 0x00}, 4},
638*4882a593Smuzhiyun 		{{0x13, 0x20, 0x01, 0x00, 0x00, 0x00}, 4},
639*4882a593Smuzhiyun 		{{0x13, 0x21, 0x01, 0x00, 0x00, 0x00}, 4},
640*4882a593Smuzhiyun 		{{0x13, 0x22, 0x01, 0x00, 0x00, 0x00}, 4},
641*4882a593Smuzhiyun 		{{0x13, 0x23, 0x01, 0x01, 0x00, 0x00}, 4},
642*4882a593Smuzhiyun 		{{0x13, 0x24, 0x01, 0x00, 0x00, 0x00}, 4},
643*4882a593Smuzhiyun 		{{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 4},
644*4882a593Smuzhiyun 		{{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 4},
645*4882a593Smuzhiyun 		{{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4},
646*4882a593Smuzhiyun 		{{0x13, 0x28, 0x01, 0x0e, 0x00, 0x00}, 4},
647*4882a593Smuzhiyun 		{{0x13, 0x29, 0x01, 0x22, 0x00, 0x00}, 4},
648*4882a593Smuzhiyun 		{{0x13, 0x2a, 0x01, 0x00, 0x00, 0x00}, 4},
649*4882a593Smuzhiyun 		{{0x13, 0x2b, 0x01, 0x00, 0x00, 0x00}, 4},
650*4882a593Smuzhiyun 		{{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
651*4882a593Smuzhiyun 		{{0x13, 0x2d, 0x01, 0x02, 0x00, 0x00}, 4},
652*4882a593Smuzhiyun 		{{0x13, 0x2e, 0x01, 0x09, 0x00, 0x00}, 4},
653*4882a593Smuzhiyun 		{{0x13, 0x2f, 0x01, 0x07, 0x00, 0x00}, 4},
654*4882a593Smuzhiyun 		{{0x12, 0x34, 0x01, 0x00, 0x00, 0x00}, 4},
655*4882a593Smuzhiyun 		{{0x13, 0x34, 0x01, 0xa1, 0x00, 0x00}, 4},
656*4882a593Smuzhiyun 		{{0x13, 0x35, 0x01, 0x00, 0x00, 0x00}, 4},
657*4882a593Smuzhiyun 		{{0x11, 0x01, 0x04, 0x00, 0x00, 0x00}, 4},
658*4882a593Smuzhiyun 		{{0x11, 0x02, 0x92, 0x00, 0x00, 0x00}, 4},
659*4882a593Smuzhiyun 		{{0x11, 0x10, 0x00, 0x00, 0x00, 0x00}, 4},
660*4882a593Smuzhiyun 		{{0x11, 0x11, 0x64, 0x00, 0x00, 0x00}, 4},
661*4882a593Smuzhiyun 		{{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4},
662*4882a593Smuzhiyun 		{{0x11, 0x13, 0x91, 0x00, 0x00, 0x00}, 4},
663*4882a593Smuzhiyun 		{{0x11, 0x14, 0x01, 0x00, 0x00, 0x00}, 4},
664*4882a593Smuzhiyun 		{{0x11, 0x15, 0x20, 0x00, 0x00, 0x00}, 4},
665*4882a593Smuzhiyun 		{{0x11, 0x16, 0x01, 0x00, 0x00, 0x00}, 4},
666*4882a593Smuzhiyun 		{{0x11, 0x17, 0x60, 0x00, 0x00, 0x00}, 4},
667*4882a593Smuzhiyun 		{{0x11, 0x20, 0x00, 0x00, 0x00, 0x00}, 4},
668*4882a593Smuzhiyun 		{{0x11, 0x21, 0x2d, 0x00, 0x00, 0x00}, 4},
669*4882a593Smuzhiyun 		{{0x11, 0x22, 0x00, 0x00, 0x00, 0x00}, 4},
670*4882a593Smuzhiyun 		{{0x11, 0x23, 0x03, 0x00, 0x00, 0x00}, 4},
671*4882a593Smuzhiyun 		{{0x11, 0x25, 0x00, 0x00, 0x00, 0x00}, 4},
672*4882a593Smuzhiyun 		{{0x11, 0x26, 0x02, 0x00, 0x00, 0x00}, 4},
673*4882a593Smuzhiyun 		{{0x11, 0x27, 0x88, 0x00, 0x00, 0x00}, 4},
674*4882a593Smuzhiyun 		{{0x11, 0x30, 0x38, 0x00, 0x00, 0x00}, 4},
675*4882a593Smuzhiyun 		{{0x11, 0x31, 0x2a, 0x00, 0x00, 0x00}, 4},
676*4882a593Smuzhiyun 		{{0x11, 0x32, 0x2a, 0x00, 0x00, 0x00}, 4},
677*4882a593Smuzhiyun 		{{0x11, 0x33, 0x2a, 0x00, 0x00, 0x00}, 4},
678*4882a593Smuzhiyun 		{{0x11, 0x34, 0x02, 0x00, 0x00, 0x00}, 4},
679*4882a593Smuzhiyun 		{{0x11, 0x5b, 0x0a, 0x00, 0x00, 0x00}, 4},
680*4882a593Smuzhiyun 		{{0x13, 0x25, 0x01, 0x28, 0x00, 0x00}, 4},
681*4882a593Smuzhiyun 		{{0x13, 0x26, 0x01, 0x1e, 0x00, 0x00}, 4},
682*4882a593Smuzhiyun 		{{0x13, 0x28, 0x01, 0x0e, 0x00, 0x00}, 4},
683*4882a593Smuzhiyun 		{{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4},
684*4882a593Smuzhiyun 		{{0x13, 0x29, 0x01, 0x62, 0x00, 0x00}, 4},
685*4882a593Smuzhiyun 		{{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
686*4882a593Smuzhiyun 		{{0x13, 0x2d, 0x01, 0x03, 0x00, 0x00}, 4},
687*4882a593Smuzhiyun 		{{0x13, 0x2e, 0x01, 0x0f, 0x00, 0x00}, 4},
688*4882a593Smuzhiyun 		{{0x13, 0x2f, 0x01, 0x0c, 0x00, 0x00}, 4},
689*4882a593Smuzhiyun 		{{0x11, 0x20, 0x00, 0x00, 0x00, 0x00}, 4},
690*4882a593Smuzhiyun 		{{0x11, 0x21, 0x2a, 0x00, 0x00, 0x00}, 4},
691*4882a593Smuzhiyun 		{{0x11, 0x22, 0x00, 0x00, 0x00, 0x00}, 4},
692*4882a593Smuzhiyun 		{{0x11, 0x23, 0x28, 0x00, 0x00, 0x00}, 4},
693*4882a593Smuzhiyun 		{{0x11, 0x10, 0x00, 0x00, 0x00, 0x00}, 4},
694*4882a593Smuzhiyun 		{{0x11, 0x11, 0x04, 0x00, 0x00, 0x00}, 4},
695*4882a593Smuzhiyun 		{{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4},
696*4882a593Smuzhiyun 		{{0x11, 0x13, 0x03, 0x00, 0x00, 0x00}, 4},
697*4882a593Smuzhiyun 		{{0x11, 0x14, 0x01, 0x00, 0x00, 0x00}, 4},
698*4882a593Smuzhiyun 		{{0x11, 0x15, 0xe0, 0x00, 0x00, 0x00}, 4},
699*4882a593Smuzhiyun 		{{0x11, 0x16, 0x02, 0x00, 0x00, 0x00}, 4},
700*4882a593Smuzhiyun 		{{0x11, 0x17, 0x80, 0x00, 0x00, 0x00}, 4},
701*4882a593Smuzhiyun 		{{0x1c, 0x20, 0x00, 0x2a, 0x00, 0x00}, 1},
702*4882a593Smuzhiyun 		{{0x20, 0x34, 0xa1, 0x00, 0x00, 0x00}, 0},
703*4882a593Smuzhiyun 		/* Camera should start to capture now. */
704*4882a593Smuzhiyun 		{{0x12, 0x27, 0x01, 0x00, 0x00, 0x00}, 0},
705*4882a593Smuzhiyun 		{{0x1b, 0x32, 0x26, 0x00, 0x00, 0x00}, 0},
706*4882a593Smuzhiyun 		{{0x1d, 0x25, 0x10, 0x20, 0xab, 0x00}, 0},
707*4882a593Smuzhiyun 	};
708*4882a593Smuzhiyun 
709*4882a593Smuzhiyun 	r = run_start_commands(gspca_dev, genius_vcam_live_start_commands,
710*4882a593Smuzhiyun 				  ARRAY_SIZE(genius_vcam_live_start_commands));
711*4882a593Smuzhiyun 	if (r < 0)
712*4882a593Smuzhiyun 		return r;
713*4882a593Smuzhiyun 
714*4882a593Smuzhiyun 	if (sd->gain)
715*4882a593Smuzhiyun 		set_gain(gspca_dev, v4l2_ctrl_g_ctrl(sd->gain));
716*4882a593Smuzhiyun 
717*4882a593Smuzhiyun 	return r;
718*4882a593Smuzhiyun }
719*4882a593Smuzhiyun 
start_vivitar_cam(struct gspca_dev * gspca_dev)720*4882a593Smuzhiyun static int start_vivitar_cam(struct gspca_dev *gspca_dev)
721*4882a593Smuzhiyun {
722*4882a593Smuzhiyun 	struct init_command vivitar_start_commands[] = {
723*4882a593Smuzhiyun 		{{0x0c, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
724*4882a593Smuzhiyun 		{{0x13, 0x20, 0x01, 0x00, 0x00, 0x00}, 4},
725*4882a593Smuzhiyun 		{{0x13, 0x21, 0x01, 0x00, 0x00, 0x00}, 4},
726*4882a593Smuzhiyun 		{{0x13, 0x22, 0x01, 0x01, 0x00, 0x00}, 4},
727*4882a593Smuzhiyun 		{{0x13, 0x23, 0x01, 0x01, 0x00, 0x00}, 4},
728*4882a593Smuzhiyun 		{{0x13, 0x24, 0x01, 0x00, 0x00, 0x00}, 4},
729*4882a593Smuzhiyun 		{{0x13, 0x25, 0x01, 0x28, 0x00, 0x00}, 4},
730*4882a593Smuzhiyun 		{{0x13, 0x26, 0x01, 0x1e, 0x00, 0x00}, 4},
731*4882a593Smuzhiyun 		{{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4},
732*4882a593Smuzhiyun 		{{0x13, 0x28, 0x01, 0x0a, 0x00, 0x00}, 4},
733*4882a593Smuzhiyun 		/*
734*4882a593Smuzhiyun 		 * Above is changed from OEM 0x0b. Fixes Bayer tiling.
735*4882a593Smuzhiyun 		 * Presumably gives a vertical shift of one row.
736*4882a593Smuzhiyun 		 */
737*4882a593Smuzhiyun 		{{0x13, 0x29, 0x01, 0x20, 0x00, 0x00}, 4},
738*4882a593Smuzhiyun 		/* Above seems to do horizontal shift. */
739*4882a593Smuzhiyun 		{{0x13, 0x2a, 0x01, 0x00, 0x00, 0x00}, 4},
740*4882a593Smuzhiyun 		{{0x13, 0x2b, 0x01, 0x00, 0x00, 0x00}, 4},
741*4882a593Smuzhiyun 		{{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
742*4882a593Smuzhiyun 		{{0x13, 0x2d, 0x01, 0x03, 0x00, 0x00}, 4},
743*4882a593Smuzhiyun 		{{0x13, 0x2e, 0x01, 0x0f, 0x00, 0x00}, 4},
744*4882a593Smuzhiyun 		{{0x13, 0x2f, 0x01, 0x0c, 0x00, 0x00}, 4},
745*4882a593Smuzhiyun 		/* Above three commands seem to relate to brightness. */
746*4882a593Smuzhiyun 		{{0x12, 0x34, 0x01, 0x00, 0x00, 0x00}, 4},
747*4882a593Smuzhiyun 		{{0x13, 0x34, 0x01, 0xa1, 0x00, 0x00}, 4},
748*4882a593Smuzhiyun 		{{0x13, 0x35, 0x01, 0x00, 0x00, 0x00}, 4},
749*4882a593Smuzhiyun 		{{0x1b, 0x12, 0x80, 0x00, 0x00, 0x00}, 1},
750*4882a593Smuzhiyun 		{{0x1b, 0x01, 0x77, 0x00, 0x00, 0x00}, 1},
751*4882a593Smuzhiyun 		{{0x1b, 0x02, 0x3a, 0x00, 0x00, 0x00}, 1},
752*4882a593Smuzhiyun 		{{0x1b, 0x12, 0x78, 0x00, 0x00, 0x00}, 1},
753*4882a593Smuzhiyun 		{{0x1b, 0x13, 0x00, 0x00, 0x00, 0x00}, 1},
754*4882a593Smuzhiyun 		{{0x1b, 0x14, 0x80, 0x00, 0x00, 0x00}, 1},
755*4882a593Smuzhiyun 		{{0x1b, 0x15, 0x34, 0x00, 0x00, 0x00}, 1},
756*4882a593Smuzhiyun 		{{0x1b, 0x1b, 0x04, 0x00, 0x00, 0x00}, 1},
757*4882a593Smuzhiyun 		{{0x1b, 0x20, 0x44, 0x00, 0x00, 0x00}, 1},
758*4882a593Smuzhiyun 		{{0x1b, 0x23, 0xee, 0x00, 0x00, 0x00}, 1},
759*4882a593Smuzhiyun 		{{0x1b, 0x26, 0xa0, 0x00, 0x00, 0x00}, 1},
760*4882a593Smuzhiyun 		{{0x1b, 0x27, 0x9a, 0x00, 0x00, 0x00}, 1},
761*4882a593Smuzhiyun 		{{0x1b, 0x28, 0xa0, 0x00, 0x00, 0x00}, 1},
762*4882a593Smuzhiyun 		{{0x1b, 0x29, 0x30, 0x00, 0x00, 0x00}, 1},
763*4882a593Smuzhiyun 		{{0x1b, 0x2a, 0x80, 0x00, 0x00, 0x00}, 1},
764*4882a593Smuzhiyun 		{{0x1b, 0x2b, 0x00, 0x00, 0x00, 0x00}, 1},
765*4882a593Smuzhiyun 		{{0x1b, 0x2f, 0x3d, 0x00, 0x00, 0x00}, 1},
766*4882a593Smuzhiyun 		{{0x1b, 0x30, 0x24, 0x00, 0x00, 0x00}, 1},
767*4882a593Smuzhiyun 		{{0x1b, 0x32, 0x86, 0x00, 0x00, 0x00}, 1},
768*4882a593Smuzhiyun 		{{0x1b, 0x60, 0xa9, 0x00, 0x00, 0x00}, 1},
769*4882a593Smuzhiyun 		{{0x1b, 0x61, 0x42, 0x00, 0x00, 0x00}, 1},
770*4882a593Smuzhiyun 		{{0x1b, 0x65, 0x00, 0x00, 0x00, 0x00}, 1},
771*4882a593Smuzhiyun 		{{0x1b, 0x69, 0x38, 0x00, 0x00, 0x00}, 1},
772*4882a593Smuzhiyun 		{{0x1b, 0x6f, 0x88, 0x00, 0x00, 0x00}, 1},
773*4882a593Smuzhiyun 		{{0x1b, 0x70, 0x0b, 0x00, 0x00, 0x00}, 1},
774*4882a593Smuzhiyun 		{{0x1b, 0x71, 0x00, 0x00, 0x00, 0x00}, 1},
775*4882a593Smuzhiyun 		{{0x1b, 0x74, 0x21, 0x00, 0x00, 0x00}, 1},
776*4882a593Smuzhiyun 		{{0x1b, 0x75, 0x86, 0x00, 0x00, 0x00}, 1},
777*4882a593Smuzhiyun 		{{0x1b, 0x76, 0x00, 0x00, 0x00, 0x00}, 1},
778*4882a593Smuzhiyun 		{{0x1b, 0x7d, 0xf3, 0x00, 0x00, 0x00}, 1},
779*4882a593Smuzhiyun 		{{0x1b, 0x17, 0x1c, 0x00, 0x00, 0x00}, 1},
780*4882a593Smuzhiyun 		{{0x1b, 0x18, 0xc0, 0x00, 0x00, 0x00}, 1},
781*4882a593Smuzhiyun 		{{0x1b, 0x19, 0x05, 0x00, 0x00, 0x00}, 1},
782*4882a593Smuzhiyun 		{{0x1b, 0x1a, 0xf6, 0x00, 0x00, 0x00}, 1},
783*4882a593Smuzhiyun 		/* {{0x13, 0x25, 0x01, 0x28, 0x00, 0x00}, 4},
784*4882a593Smuzhiyun 		{{0x13, 0x26, 0x01, 0x1e, 0x00, 0x00}, 4},
785*4882a593Smuzhiyun 		{{0x13, 0x28, 0x01, 0x0b, 0x00, 0x00}, 4}, */
786*4882a593Smuzhiyun 		{{0x20, 0x36, 0x06, 0x00, 0x00, 0x00}, 1},
787*4882a593Smuzhiyun 		{{0x1b, 0x10, 0x26, 0x00, 0x00, 0x00}, 1},
788*4882a593Smuzhiyun 		{{0x12, 0x27, 0x01, 0x00, 0x00, 0x00}, 4},
789*4882a593Smuzhiyun 		{{0x1b, 0x76, 0x03, 0x00, 0x00, 0x00}, 1},
790*4882a593Smuzhiyun 		{{0x20, 0x36, 0x05, 0x00, 0x00, 0x00}, 1},
791*4882a593Smuzhiyun 		{{0x1b, 0x00, 0x3f, 0x00, 0x00, 0x00}, 1},
792*4882a593Smuzhiyun 		/* Above is brightness; OEM driver setting is 0x10 */
793*4882a593Smuzhiyun 		{{0x12, 0x27, 0x01, 0x00, 0x00, 0x00}, 4},
794*4882a593Smuzhiyun 		{{0x20, 0x29, 0x30, 0x00, 0x00, 0x00}, 1},
795*4882a593Smuzhiyun 		{{0x20, 0x34, 0xa1, 0x00, 0x00, 0x00}, 1}
796*4882a593Smuzhiyun 	};
797*4882a593Smuzhiyun 
798*4882a593Smuzhiyun 	return run_start_commands(gspca_dev, vivitar_start_commands,
799*4882a593Smuzhiyun 				  ARRAY_SIZE(vivitar_start_commands));
800*4882a593Smuzhiyun }
801*4882a593Smuzhiyun 
sd_start(struct gspca_dev * gspca_dev)802*4882a593Smuzhiyun static int sd_start(struct gspca_dev *gspca_dev)
803*4882a593Smuzhiyun {
804*4882a593Smuzhiyun 	struct sd *sd = (struct sd *) gspca_dev;
805*4882a593Smuzhiyun 	int err_code;
806*4882a593Smuzhiyun 
807*4882a593Smuzhiyun 	sd->sof_read = 0;
808*4882a593Smuzhiyun 
809*4882a593Smuzhiyun 	switch (sd->model) {
810*4882a593Smuzhiyun 	case 0x7005:
811*4882a593Smuzhiyun 		err_code = start_genius_cam(gspca_dev);
812*4882a593Smuzhiyun 		break;
813*4882a593Smuzhiyun 	case 0x7003:
814*4882a593Smuzhiyun 		err_code = start_genius_videocam_live(gspca_dev);
815*4882a593Smuzhiyun 		break;
816*4882a593Smuzhiyun 	case 0x8001:
817*4882a593Smuzhiyun 		err_code = start_spy_cam(gspca_dev);
818*4882a593Smuzhiyun 		break;
819*4882a593Smuzhiyun 	case 0x8003:
820*4882a593Smuzhiyun 		err_code = start_cif_cam(gspca_dev);
821*4882a593Smuzhiyun 		break;
822*4882a593Smuzhiyun 	case 0x8008:
823*4882a593Smuzhiyun 		err_code = start_ms350_cam(gspca_dev);
824*4882a593Smuzhiyun 		break;
825*4882a593Smuzhiyun 	case 0x800a:
826*4882a593Smuzhiyun 		err_code = start_vivitar_cam(gspca_dev);
827*4882a593Smuzhiyun 		break;
828*4882a593Smuzhiyun 	default:
829*4882a593Smuzhiyun 		pr_err("Starting unknown camera, please report this\n");
830*4882a593Smuzhiyun 		return -ENXIO;
831*4882a593Smuzhiyun 	}
832*4882a593Smuzhiyun 
833*4882a593Smuzhiyun 	sd->avg_lum = -1;
834*4882a593Smuzhiyun 
835*4882a593Smuzhiyun 	return err_code;
836*4882a593Smuzhiyun }
837*4882a593Smuzhiyun 
sd_stopN(struct gspca_dev * gspca_dev)838*4882a593Smuzhiyun static void sd_stopN(struct gspca_dev *gspca_dev)
839*4882a593Smuzhiyun {
840*4882a593Smuzhiyun 	int result;
841*4882a593Smuzhiyun 	__u8 data[6];
842*4882a593Smuzhiyun 
843*4882a593Smuzhiyun 	result = sn9c2028_read1(gspca_dev);
844*4882a593Smuzhiyun 	if (result < 0)
845*4882a593Smuzhiyun 		gspca_err(gspca_dev, "Camera Stop read failed\n");
846*4882a593Smuzhiyun 
847*4882a593Smuzhiyun 	memset(data, 0, 6);
848*4882a593Smuzhiyun 	data[0] = 0x14;
849*4882a593Smuzhiyun 	result = sn9c2028_command(gspca_dev, data);
850*4882a593Smuzhiyun 	if (result < 0)
851*4882a593Smuzhiyun 		gspca_err(gspca_dev, "Camera Stop command failed\n");
852*4882a593Smuzhiyun }
853*4882a593Smuzhiyun 
do_autogain(struct gspca_dev * gspca_dev,int avg_lum)854*4882a593Smuzhiyun static void do_autogain(struct gspca_dev *gspca_dev, int avg_lum)
855*4882a593Smuzhiyun {
856*4882a593Smuzhiyun 	struct sd *sd = (struct sd *) gspca_dev;
857*4882a593Smuzhiyun 	s32 cur_gain = v4l2_ctrl_g_ctrl(sd->gain);
858*4882a593Smuzhiyun 
859*4882a593Smuzhiyun 	if (avg_lum == -1)
860*4882a593Smuzhiyun 		return;
861*4882a593Smuzhiyun 
862*4882a593Smuzhiyun 	if (avg_lum < MIN_AVG_LUM) {
863*4882a593Smuzhiyun 		if (cur_gain == sd->gain->maximum)
864*4882a593Smuzhiyun 			return;
865*4882a593Smuzhiyun 		cur_gain++;
866*4882a593Smuzhiyun 		v4l2_ctrl_s_ctrl(sd->gain, cur_gain);
867*4882a593Smuzhiyun 	}
868*4882a593Smuzhiyun 	if (avg_lum > MAX_AVG_LUM) {
869*4882a593Smuzhiyun 		if (cur_gain == sd->gain->minimum)
870*4882a593Smuzhiyun 			return;
871*4882a593Smuzhiyun 		cur_gain--;
872*4882a593Smuzhiyun 		v4l2_ctrl_s_ctrl(sd->gain, cur_gain);
873*4882a593Smuzhiyun 	}
874*4882a593Smuzhiyun 
875*4882a593Smuzhiyun }
876*4882a593Smuzhiyun 
sd_dqcallback(struct gspca_dev * gspca_dev)877*4882a593Smuzhiyun static void sd_dqcallback(struct gspca_dev *gspca_dev)
878*4882a593Smuzhiyun {
879*4882a593Smuzhiyun 	struct sd *sd = (struct sd *) gspca_dev;
880*4882a593Smuzhiyun 
881*4882a593Smuzhiyun 	if (sd->autogain == NULL || !v4l2_ctrl_g_ctrl(sd->autogain))
882*4882a593Smuzhiyun 		return;
883*4882a593Smuzhiyun 
884*4882a593Smuzhiyun 	do_autogain(gspca_dev, sd->avg_lum);
885*4882a593Smuzhiyun }
886*4882a593Smuzhiyun 
887*4882a593Smuzhiyun /* Include sn9c2028 sof detection functions */
888*4882a593Smuzhiyun #include "sn9c2028.h"
889*4882a593Smuzhiyun 
sd_pkt_scan(struct gspca_dev * gspca_dev,__u8 * data,int len)890*4882a593Smuzhiyun static void sd_pkt_scan(struct gspca_dev *gspca_dev,
891*4882a593Smuzhiyun 			__u8 *data,			/* isoc packet */
892*4882a593Smuzhiyun 			int len)			/* iso packet length */
893*4882a593Smuzhiyun {
894*4882a593Smuzhiyun 	unsigned char *sof;
895*4882a593Smuzhiyun 
896*4882a593Smuzhiyun 	sof = sn9c2028_find_sof(gspca_dev, data, len);
897*4882a593Smuzhiyun 	if (sof) {
898*4882a593Smuzhiyun 		int n;
899*4882a593Smuzhiyun 
900*4882a593Smuzhiyun 		/* finish decoding current frame */
901*4882a593Smuzhiyun 		n = sof - data;
902*4882a593Smuzhiyun 		if (n > sizeof sn9c2028_sof_marker)
903*4882a593Smuzhiyun 			n -= sizeof sn9c2028_sof_marker;
904*4882a593Smuzhiyun 		else
905*4882a593Smuzhiyun 			n = 0;
906*4882a593Smuzhiyun 		gspca_frame_add(gspca_dev, LAST_PACKET, data, n);
907*4882a593Smuzhiyun 		/* Start next frame. */
908*4882a593Smuzhiyun 		gspca_frame_add(gspca_dev, FIRST_PACKET,
909*4882a593Smuzhiyun 			sn9c2028_sof_marker, sizeof sn9c2028_sof_marker);
910*4882a593Smuzhiyun 		len -= sof - data;
911*4882a593Smuzhiyun 		data = sof;
912*4882a593Smuzhiyun 	}
913*4882a593Smuzhiyun 	gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
914*4882a593Smuzhiyun }
915*4882a593Smuzhiyun 
916*4882a593Smuzhiyun /* sub-driver description */
917*4882a593Smuzhiyun static const struct sd_desc sd_desc = {
918*4882a593Smuzhiyun 	.name = MODULE_NAME,
919*4882a593Smuzhiyun 	.config = sd_config,
920*4882a593Smuzhiyun 	.init = sd_init,
921*4882a593Smuzhiyun 	.init_controls = sd_init_controls,
922*4882a593Smuzhiyun 	.start = sd_start,
923*4882a593Smuzhiyun 	.stopN = sd_stopN,
924*4882a593Smuzhiyun 	.dq_callback = sd_dqcallback,
925*4882a593Smuzhiyun 	.pkt_scan = sd_pkt_scan,
926*4882a593Smuzhiyun };
927*4882a593Smuzhiyun 
928*4882a593Smuzhiyun /* -- module initialisation -- */
929*4882a593Smuzhiyun static const struct usb_device_id device_table[] = {
930*4882a593Smuzhiyun 	{USB_DEVICE(0x0458, 0x7005)}, /* Genius Smart 300, version 2 */
931*4882a593Smuzhiyun 	{USB_DEVICE(0x0458, 0x7003)}, /* Genius Videocam Live v2  */
932*4882a593Smuzhiyun 	/* The Genius Smart is untested. I can't find an owner ! */
933*4882a593Smuzhiyun 	/* {USB_DEVICE(0x0c45, 0x8000)}, DC31VC, Don't know this camera */
934*4882a593Smuzhiyun 	{USB_DEVICE(0x0c45, 0x8001)}, /* Wild Planet digital spy cam */
935*4882a593Smuzhiyun 	{USB_DEVICE(0x0c45, 0x8003)}, /* Several small CIF cameras */
936*4882a593Smuzhiyun 	/* {USB_DEVICE(0x0c45, 0x8006)}, Unknown VGA camera */
937*4882a593Smuzhiyun 	{USB_DEVICE(0x0c45, 0x8008)}, /* Mini-Shotz ms-350 */
938*4882a593Smuzhiyun 	{USB_DEVICE(0x0c45, 0x800a)}, /* Vivicam 3350B */
939*4882a593Smuzhiyun 	{}
940*4882a593Smuzhiyun };
941*4882a593Smuzhiyun MODULE_DEVICE_TABLE(usb, device_table);
942*4882a593Smuzhiyun 
943*4882a593Smuzhiyun /* -- device connect -- */
sd_probe(struct usb_interface * intf,const struct usb_device_id * id)944*4882a593Smuzhiyun static int sd_probe(struct usb_interface *intf,
945*4882a593Smuzhiyun 			const struct usb_device_id *id)
946*4882a593Smuzhiyun {
947*4882a593Smuzhiyun 	return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
948*4882a593Smuzhiyun 			       THIS_MODULE);
949*4882a593Smuzhiyun }
950*4882a593Smuzhiyun 
951*4882a593Smuzhiyun static struct usb_driver sd_driver = {
952*4882a593Smuzhiyun 	.name = MODULE_NAME,
953*4882a593Smuzhiyun 	.id_table = device_table,
954*4882a593Smuzhiyun 	.probe = sd_probe,
955*4882a593Smuzhiyun 	.disconnect = gspca_disconnect,
956*4882a593Smuzhiyun #ifdef CONFIG_PM
957*4882a593Smuzhiyun 	.suspend = gspca_suspend,
958*4882a593Smuzhiyun 	.resume = gspca_resume,
959*4882a593Smuzhiyun 	.reset_resume = gspca_resume,
960*4882a593Smuzhiyun #endif
961*4882a593Smuzhiyun };
962*4882a593Smuzhiyun 
963*4882a593Smuzhiyun module_usb_driver(sd_driver);
964