• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2001 Jean-Fredric Clere, Nikolas Zimmermann, Georg Acher
4  *		      Mark Cave-Ayland, Carlo E Prelz, Dick Streefland
5  * Copyright (c) 2002, 2003 Tuukka Toivonen
6  * Copyright (c) 2008 Erik Andrén
7  *
8  * P/N 861037:      Sensor HDCS1000        ASIC STV0600
9  * P/N 861050-0010: Sensor HDCS1000        ASIC STV0600
10  * P/N 861050-0020: Sensor Photobit PB100  ASIC STV0600-1 - QuickCam Express
11  * P/N 861055:      Sensor ST VV6410       ASIC STV0610   - LEGO cam
12  * P/N 861075-0040: Sensor HDCS1000        ASIC
13  * P/N 961179-0700: Sensor ST VV6410       ASIC STV0602   - Dexxa WebCam USB
14  * P/N 861040-0000: Sensor ST VV6410       ASIC STV0610   - QuickCam Web
15  */
16 
17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18 
19 #include <linux/input.h>
20 #include "stv06xx_sensor.h"
21 
22 MODULE_AUTHOR("Erik Andrén");
23 MODULE_DESCRIPTION("STV06XX USB Camera Driver");
24 MODULE_LICENSE("GPL");
25 
26 static bool dump_bridge;
27 static bool dump_sensor;
28 
stv06xx_write_bridge(struct sd * sd,u16 address,u16 i2c_data)29 int stv06xx_write_bridge(struct sd *sd, u16 address, u16 i2c_data)
30 {
31 	int err;
32 	struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
33 	struct usb_device *udev = sd->gspca_dev.dev;
34 	__u8 *buf = sd->gspca_dev.usb_buf;
35 
36 	u8 len = (i2c_data > 0xff) ? 2 : 1;
37 
38 	buf[0] = i2c_data & 0xff;
39 	buf[1] = (i2c_data >> 8) & 0xff;
40 
41 	err = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
42 			      0x04, 0x40, address, 0, buf, len,
43 			      STV06XX_URB_MSG_TIMEOUT);
44 
45 	gspca_dbg(gspca_dev, D_CONF, "Written 0x%x to address 0x%x, status: %d\n",
46 		  i2c_data, address, err);
47 
48 	return (err < 0) ? err : 0;
49 }
50 
stv06xx_read_bridge(struct sd * sd,u16 address,u8 * i2c_data)51 int stv06xx_read_bridge(struct sd *sd, u16 address, u8 *i2c_data)
52 {
53 	int err;
54 	struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
55 	struct usb_device *udev = sd->gspca_dev.dev;
56 	__u8 *buf = sd->gspca_dev.usb_buf;
57 
58 	err = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
59 			      0x04, 0xc0, address, 0, buf, 1,
60 			      STV06XX_URB_MSG_TIMEOUT);
61 
62 	*i2c_data = buf[0];
63 
64 	gspca_dbg(gspca_dev, D_CONF, "Reading 0x%x from address 0x%x, status %d\n",
65 		  *i2c_data, address, err);
66 
67 	return (err < 0) ? err : 0;
68 }
69 
70 /* Wraps the normal write sensor bytes / words functions for writing a
71    single value */
stv06xx_write_sensor(struct sd * sd,u8 address,u16 value)72 int stv06xx_write_sensor(struct sd *sd, u8 address, u16 value)
73 {
74 	if (sd->sensor->i2c_len == 2) {
75 		u16 data[2] = { address, value };
76 		return stv06xx_write_sensor_words(sd, data, 1);
77 	} else {
78 		u8 data[2] = { address, value };
79 		return stv06xx_write_sensor_bytes(sd, data, 1);
80 	}
81 }
82 
stv06xx_write_sensor_finish(struct sd * sd)83 static int stv06xx_write_sensor_finish(struct sd *sd)
84 {
85 	int err = 0;
86 
87 	if (sd->bridge == BRIDGE_STV610) {
88 		struct usb_device *udev = sd->gspca_dev.dev;
89 		__u8 *buf = sd->gspca_dev.usb_buf;
90 
91 		buf[0] = 0;
92 		err = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
93 				      0x04, 0x40, 0x1704, 0, buf, 1,
94 				      STV06XX_URB_MSG_TIMEOUT);
95 	}
96 
97 	return (err < 0) ? err : 0;
98 }
99 
stv06xx_write_sensor_bytes(struct sd * sd,const u8 * data,u8 len)100 int stv06xx_write_sensor_bytes(struct sd *sd, const u8 *data, u8 len)
101 {
102 	int err, i, j;
103 	struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
104 	struct usb_device *udev = sd->gspca_dev.dev;
105 	__u8 *buf = sd->gspca_dev.usb_buf;
106 
107 	gspca_dbg(gspca_dev, D_CONF, "I2C: Command buffer contains %d entries\n",
108 		  len);
109 	for (i = 0; i < len;) {
110 		/* Build the command buffer */
111 		memset(buf, 0, I2C_BUFFER_LENGTH);
112 		for (j = 0; j < I2C_MAX_BYTES && i < len; j++, i++) {
113 			buf[j] = data[2*i];
114 			buf[0x10 + j] = data[2*i+1];
115 			gspca_dbg(gspca_dev, D_CONF, "I2C: Writing 0x%02x to reg 0x%02x\n",
116 				  data[2*i+1], data[2*i]);
117 		}
118 		buf[0x20] = sd->sensor->i2c_addr;
119 		buf[0x21] = j - 1; /* Number of commands to send - 1 */
120 		buf[0x22] = I2C_WRITE_CMD;
121 		err = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
122 				      0x04, 0x40, 0x0400, 0, buf,
123 				      I2C_BUFFER_LENGTH,
124 				      STV06XX_URB_MSG_TIMEOUT);
125 		if (err < 0)
126 			return err;
127 	}
128 	return stv06xx_write_sensor_finish(sd);
129 }
130 
stv06xx_write_sensor_words(struct sd * sd,const u16 * data,u8 len)131 int stv06xx_write_sensor_words(struct sd *sd, const u16 *data, u8 len)
132 {
133 	int err, i, j;
134 	struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
135 	struct usb_device *udev = sd->gspca_dev.dev;
136 	__u8 *buf = sd->gspca_dev.usb_buf;
137 
138 	gspca_dbg(gspca_dev, D_CONF, "I2C: Command buffer contains %d entries\n",
139 		  len);
140 
141 	for (i = 0; i < len;) {
142 		/* Build the command buffer */
143 		memset(buf, 0, I2C_BUFFER_LENGTH);
144 		for (j = 0; j < I2C_MAX_WORDS && i < len; j++, i++) {
145 			buf[j] = data[2*i];
146 			buf[0x10 + j * 2] = data[2*i+1];
147 			buf[0x10 + j * 2 + 1] = data[2*i+1] >> 8;
148 			gspca_dbg(gspca_dev, D_CONF, "I2C: Writing 0x%04x to reg 0x%02x\n",
149 				  data[2*i+1], data[2*i]);
150 		}
151 		buf[0x20] = sd->sensor->i2c_addr;
152 		buf[0x21] = j - 1; /* Number of commands to send - 1 */
153 		buf[0x22] = I2C_WRITE_CMD;
154 		err = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
155 				0x04, 0x40, 0x0400, 0, buf,
156 				I2C_BUFFER_LENGTH,
157 				STV06XX_URB_MSG_TIMEOUT);
158 		if (err < 0)
159 			return err;
160 	}
161 	return stv06xx_write_sensor_finish(sd);
162 }
163 
stv06xx_read_sensor(struct sd * sd,const u8 address,u16 * value)164 int stv06xx_read_sensor(struct sd *sd, const u8 address, u16 *value)
165 {
166 	int err;
167 	struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
168 	struct usb_device *udev = sd->gspca_dev.dev;
169 	__u8 *buf = sd->gspca_dev.usb_buf;
170 
171 	err = stv06xx_write_bridge(sd, STV_I2C_FLUSH, sd->sensor->i2c_flush);
172 	if (err < 0)
173 		return err;
174 
175 	/* Clear mem */
176 	memset(buf, 0, I2C_BUFFER_LENGTH);
177 
178 	buf[0] = address;
179 	buf[0x20] = sd->sensor->i2c_addr;
180 	buf[0x21] = 0;
181 
182 	/* Read I2C register */
183 	buf[0x22] = I2C_READ_CMD;
184 
185 	err = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
186 			      0x04, 0x40, 0x1400, 0, buf, I2C_BUFFER_LENGTH,
187 			      STV06XX_URB_MSG_TIMEOUT);
188 	if (err < 0) {
189 		pr_err("I2C: Read error writing address: %d\n", err);
190 		return err;
191 	}
192 
193 	err = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
194 			      0x04, 0xc0, 0x1410, 0, buf, sd->sensor->i2c_len,
195 			      STV06XX_URB_MSG_TIMEOUT);
196 	if (sd->sensor->i2c_len == 2)
197 		*value = buf[0] | (buf[1] << 8);
198 	else
199 		*value = buf[0];
200 
201 	gspca_dbg(gspca_dev, D_CONF, "I2C: Read 0x%x from address 0x%x, status: %d\n",
202 		  *value, address, err);
203 
204 	return (err < 0) ? err : 0;
205 }
206 
207 /* Dumps all bridge registers */
stv06xx_dump_bridge(struct sd * sd)208 static void stv06xx_dump_bridge(struct sd *sd)
209 {
210 	int i;
211 	u8 data, buf;
212 
213 	pr_info("Dumping all stv06xx bridge registers\n");
214 	for (i = 0x1400; i < 0x160f; i++) {
215 		stv06xx_read_bridge(sd, i, &data);
216 
217 		pr_info("Read 0x%x from address 0x%x\n", data, i);
218 	}
219 
220 	pr_info("Testing stv06xx bridge registers for writability\n");
221 	for (i = 0x1400; i < 0x160f; i++) {
222 		stv06xx_read_bridge(sd, i, &data);
223 		buf = data;
224 
225 		stv06xx_write_bridge(sd, i, 0xff);
226 		stv06xx_read_bridge(sd, i, &data);
227 		if (data == 0xff)
228 			pr_info("Register 0x%x is read/write\n", i);
229 		else if (data != buf)
230 			pr_info("Register 0x%x is read/write, but only partially\n",
231 				i);
232 		else
233 			pr_info("Register 0x%x is read-only\n", i);
234 
235 		stv06xx_write_bridge(sd, i, buf);
236 	}
237 }
238 
239 /* this function is called at probe and resume time */
stv06xx_init(struct gspca_dev * gspca_dev)240 static int stv06xx_init(struct gspca_dev *gspca_dev)
241 {
242 	struct sd *sd = (struct sd *) gspca_dev;
243 	int err;
244 
245 	gspca_dbg(gspca_dev, D_PROBE, "Initializing camera\n");
246 
247 	/* Let the usb init settle for a bit
248 	   before performing the initialization */
249 	msleep(250);
250 
251 	err = sd->sensor->init(sd);
252 
253 	if (dump_sensor && sd->sensor->dump)
254 		sd->sensor->dump(sd);
255 
256 	return (err < 0) ? err : 0;
257 }
258 
259 /* this function is called at probe time */
stv06xx_init_controls(struct gspca_dev * gspca_dev)260 static int stv06xx_init_controls(struct gspca_dev *gspca_dev)
261 {
262 	struct sd *sd = (struct sd *) gspca_dev;
263 
264 	gspca_dbg(gspca_dev, D_PROBE, "Initializing controls\n");
265 
266 	gspca_dev->vdev.ctrl_handler = &gspca_dev->ctrl_handler;
267 	return sd->sensor->init_controls(sd);
268 }
269 
270 /* Start the camera */
stv06xx_start(struct gspca_dev * gspca_dev)271 static int stv06xx_start(struct gspca_dev *gspca_dev)
272 {
273 	struct sd *sd = (struct sd *) gspca_dev;
274 	struct usb_host_interface *alt;
275 	struct usb_interface *intf;
276 	int err, packet_size;
277 
278 	intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface);
279 	alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
280 	if (!alt) {
281 		gspca_err(gspca_dev, "Couldn't get altsetting\n");
282 		return -EIO;
283 	}
284 
285 	if (alt->desc.bNumEndpoints < 1)
286 		return -ENODEV;
287 
288 	packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
289 	err = stv06xx_write_bridge(sd, STV_ISO_SIZE_L, packet_size);
290 	if (err < 0)
291 		return err;
292 
293 	/* Prepare the sensor for start */
294 	err = sd->sensor->start(sd);
295 	if (err < 0)
296 		goto out;
297 
298 	/* Start isochronous streaming */
299 	err = stv06xx_write_bridge(sd, STV_ISO_ENABLE, 1);
300 
301 out:
302 	if (err < 0)
303 		gspca_dbg(gspca_dev, D_STREAM, "Starting stream failed\n");
304 	else
305 		gspca_dbg(gspca_dev, D_STREAM, "Started streaming\n");
306 
307 	return (err < 0) ? err : 0;
308 }
309 
stv06xx_isoc_init(struct gspca_dev * gspca_dev)310 static int stv06xx_isoc_init(struct gspca_dev *gspca_dev)
311 {
312 	struct usb_interface_cache *intfc;
313 	struct usb_host_interface *alt;
314 	struct sd *sd = (struct sd *) gspca_dev;
315 
316 	intfc = gspca_dev->dev->actconfig->intf_cache[0];
317 
318 	if (intfc->num_altsetting < 2)
319 		return -ENODEV;
320 
321 	alt = &intfc->altsetting[1];
322 
323 	if (alt->desc.bNumEndpoints < 1)
324 		return -ENODEV;
325 
326 	/* Start isoc bandwidth "negotiation" at max isoc bandwidth */
327 	alt->endpoint[0].desc.wMaxPacketSize =
328 		cpu_to_le16(sd->sensor->max_packet_size[gspca_dev->curr_mode]);
329 
330 	return 0;
331 }
332 
stv06xx_isoc_nego(struct gspca_dev * gspca_dev)333 static int stv06xx_isoc_nego(struct gspca_dev *gspca_dev)
334 {
335 	int ret, packet_size, min_packet_size;
336 	struct usb_host_interface *alt;
337 	struct sd *sd = (struct sd *) gspca_dev;
338 
339 	/*
340 	 * Existence of altsetting and endpoint was verified in
341 	 * stv06xx_isoc_init()
342 	 */
343 	alt = &gspca_dev->dev->actconfig->intf_cache[0]->altsetting[1];
344 	packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
345 	min_packet_size = sd->sensor->min_packet_size[gspca_dev->curr_mode];
346 	if (packet_size <= min_packet_size)
347 		return -EIO;
348 
349 	packet_size -= 100;
350 	if (packet_size < min_packet_size)
351 		packet_size = min_packet_size;
352 	alt->endpoint[0].desc.wMaxPacketSize = cpu_to_le16(packet_size);
353 
354 	ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, 1);
355 	if (ret < 0)
356 		gspca_err(gspca_dev, "set alt 1 err %d\n", ret);
357 
358 	return ret;
359 }
360 
stv06xx_stopN(struct gspca_dev * gspca_dev)361 static void stv06xx_stopN(struct gspca_dev *gspca_dev)
362 {
363 	int err;
364 	struct sd *sd = (struct sd *) gspca_dev;
365 
366 	/* stop ISO-streaming */
367 	err = stv06xx_write_bridge(sd, STV_ISO_ENABLE, 0);
368 	if (err < 0)
369 		goto out;
370 
371 	err = sd->sensor->stop(sd);
372 
373 out:
374 	if (err < 0)
375 		gspca_dbg(gspca_dev, D_STREAM, "Failed to stop stream\n");
376 	else
377 		gspca_dbg(gspca_dev, D_STREAM, "Stopped streaming\n");
378 }
379 
380 /*
381  * Analyse an USB packet of the data stream and store it appropriately.
382  * Each packet contains an integral number of chunks. Each chunk has
383  * 2-bytes identification, followed by 2-bytes that describe the chunk
384  * length. Known/guessed chunk identifications are:
385  * 8001/8005/C001/C005 - Begin new frame
386  * 8002/8006/C002/C006 - End frame
387  * 0200/4200           - Contains actual image data, bayer or compressed
388  * 0005                - 11 bytes of unknown data
389  * 0100                - 2 bytes of unknown data
390  * The 0005 and 0100 chunks seem to appear only in compressed stream.
391  */
stv06xx_pkt_scan(struct gspca_dev * gspca_dev,u8 * data,int len)392 static void stv06xx_pkt_scan(struct gspca_dev *gspca_dev,
393 			u8 *data,			/* isoc packet */
394 			int len)			/* iso packet length */
395 {
396 	struct sd *sd = (struct sd *) gspca_dev;
397 
398 	gspca_dbg(gspca_dev, D_PACK, "Packet of length %d arrived\n", len);
399 
400 	/* A packet may contain several frames
401 	   loop until the whole packet is reached */
402 	while (len) {
403 		int id, chunk_len;
404 
405 		if (len < 4) {
406 			gspca_dbg(gspca_dev, D_PACK, "Packet is smaller than 4 bytes\n");
407 			return;
408 		}
409 
410 		/* Capture the id */
411 		id = (data[0] << 8) | data[1];
412 
413 		/* Capture the chunk length */
414 		chunk_len = (data[2] << 8) | data[3];
415 		gspca_dbg(gspca_dev, D_PACK, "Chunk id: %x, length: %d\n",
416 			  id, chunk_len);
417 
418 		data += 4;
419 		len -= 4;
420 
421 		if (len < chunk_len) {
422 			gspca_err(gspca_dev, "URB packet length is smaller than the specified chunk length\n");
423 			gspca_dev->last_packet_type = DISCARD_PACKET;
424 			return;
425 		}
426 
427 		/* First byte seem to be 02=data 2nd byte is unknown??? */
428 		if (sd->bridge == BRIDGE_ST6422 && (id & 0xff00) == 0x0200)
429 			goto frame_data;
430 
431 		switch (id) {
432 		case 0x0200:
433 		case 0x4200:
434 frame_data:
435 			gspca_dbg(gspca_dev, D_PACK, "Frame data packet detected\n");
436 
437 			if (sd->to_skip) {
438 				int skip = (sd->to_skip < chunk_len) ?
439 					    sd->to_skip : chunk_len;
440 				data += skip;
441 				len -= skip;
442 				chunk_len -= skip;
443 				sd->to_skip -= skip;
444 			}
445 
446 			gspca_frame_add(gspca_dev, INTER_PACKET,
447 					data, chunk_len);
448 			break;
449 
450 		case 0x8001:
451 		case 0x8005:
452 		case 0xc001:
453 		case 0xc005:
454 			gspca_dbg(gspca_dev, D_PACK, "Starting new frame\n");
455 
456 			/* Create a new frame, chunk length should be zero */
457 			gspca_frame_add(gspca_dev, FIRST_PACKET,
458 					NULL, 0);
459 
460 			if (sd->bridge == BRIDGE_ST6422)
461 				sd->to_skip = gspca_dev->pixfmt.width * 4;
462 
463 			if (chunk_len)
464 				gspca_err(gspca_dev, "Chunk length is non-zero on a SOF\n");
465 			break;
466 
467 		case 0x8002:
468 		case 0x8006:
469 		case 0xc002:
470 			gspca_dbg(gspca_dev, D_PACK, "End of frame detected\n");
471 
472 			/* Complete the last frame (if any) */
473 			gspca_frame_add(gspca_dev, LAST_PACKET,
474 					NULL, 0);
475 
476 			if (chunk_len)
477 				gspca_err(gspca_dev, "Chunk length is non-zero on a EOF\n");
478 			break;
479 
480 		case 0x0005:
481 			gspca_dbg(gspca_dev, D_PACK, "Chunk 0x005 detected\n");
482 			/* Unknown chunk with 11 bytes of data,
483 			   occurs just before end of each frame
484 			   in compressed mode */
485 			break;
486 
487 		case 0x0100:
488 			gspca_dbg(gspca_dev, D_PACK, "Chunk 0x0100 detected\n");
489 			/* Unknown chunk with 2 bytes of data,
490 			   occurs 2-3 times per USB interrupt */
491 			break;
492 		case 0x42ff:
493 			gspca_dbg(gspca_dev, D_PACK, "Chunk 0x42ff detected\n");
494 			/* Special chunk seen sometimes on the ST6422 */
495 			break;
496 		default:
497 			gspca_dbg(gspca_dev, D_PACK, "Unknown chunk 0x%04x detected\n",
498 				  id);
499 			/* Unknown chunk */
500 		}
501 		data    += chunk_len;
502 		len     -= chunk_len;
503 	}
504 }
505 
506 #if IS_ENABLED(CONFIG_INPUT)
sd_int_pkt_scan(struct gspca_dev * gspca_dev,u8 * data,int len)507 static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
508 			u8 *data,		/* interrupt packet data */
509 			int len)		/* interrupt packet length */
510 {
511 	int ret = -EINVAL;
512 
513 	if (len == 1 && (data[0] == 0x80 || data[0] == 0x10)) {
514 		input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1);
515 		input_sync(gspca_dev->input_dev);
516 		ret = 0;
517 	}
518 
519 	if (len == 1 && (data[0] == 0x88 || data[0] == 0x11)) {
520 		input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
521 		input_sync(gspca_dev->input_dev);
522 		ret = 0;
523 	}
524 
525 	return ret;
526 }
527 #endif
528 
529 static int stv06xx_config(struct gspca_dev *gspca_dev,
530 			  const struct usb_device_id *id);
531 
stv06xx_probe_error(struct gspca_dev * gspca_dev)532 static void stv06xx_probe_error(struct gspca_dev *gspca_dev)
533 {
534 	struct sd *sd = (struct sd *)gspca_dev;
535 
536 	kfree(sd->sensor_priv);
537 	sd->sensor_priv = NULL;
538 }
539 
540 /* sub-driver description */
541 static const struct sd_desc sd_desc = {
542 	.name = MODULE_NAME,
543 	.config = stv06xx_config,
544 	.init = stv06xx_init,
545 	.init_controls = stv06xx_init_controls,
546 	.probe_error = stv06xx_probe_error,
547 	.start = stv06xx_start,
548 	.stopN = stv06xx_stopN,
549 	.pkt_scan = stv06xx_pkt_scan,
550 	.isoc_init = stv06xx_isoc_init,
551 	.isoc_nego = stv06xx_isoc_nego,
552 #if IS_ENABLED(CONFIG_INPUT)
553 	.int_pkt_scan = sd_int_pkt_scan,
554 #endif
555 };
556 
557 /* This function is called at probe time */
stv06xx_config(struct gspca_dev * gspca_dev,const struct usb_device_id * id)558 static int stv06xx_config(struct gspca_dev *gspca_dev,
559 			  const struct usb_device_id *id)
560 {
561 	struct sd *sd = (struct sd *) gspca_dev;
562 
563 	gspca_dbg(gspca_dev, D_PROBE, "Configuring camera\n");
564 
565 	sd->bridge = id->driver_info;
566 	gspca_dev->sd_desc = &sd_desc;
567 
568 	if (dump_bridge)
569 		stv06xx_dump_bridge(sd);
570 
571 	sd->sensor = &stv06xx_sensor_st6422;
572 	if (!sd->sensor->probe(sd))
573 		return 0;
574 
575 	sd->sensor = &stv06xx_sensor_vv6410;
576 	if (!sd->sensor->probe(sd))
577 		return 0;
578 
579 	sd->sensor = &stv06xx_sensor_hdcs1x00;
580 	if (!sd->sensor->probe(sd))
581 		return 0;
582 
583 	sd->sensor = &stv06xx_sensor_hdcs1020;
584 	if (!sd->sensor->probe(sd))
585 		return 0;
586 
587 	sd->sensor = &stv06xx_sensor_pb0100;
588 	if (!sd->sensor->probe(sd))
589 		return 0;
590 
591 	sd->sensor = NULL;
592 	return -ENODEV;
593 }
594 
595 
596 
597 /* -- module initialisation -- */
598 static const struct usb_device_id device_table[] = {
599 	{USB_DEVICE(0x046d, 0x0840), .driver_info = BRIDGE_STV600 },	/* QuickCam Express */
600 	{USB_DEVICE(0x046d, 0x0850), .driver_info = BRIDGE_STV610 },	/* LEGO cam / QuickCam Web */
601 	{USB_DEVICE(0x046d, 0x0870), .driver_info = BRIDGE_STV602 },	/* Dexxa WebCam USB */
602 	{USB_DEVICE(0x046D, 0x08F0), .driver_info = BRIDGE_ST6422 },	/* QuickCam Messenger */
603 	{USB_DEVICE(0x046D, 0x08F5), .driver_info = BRIDGE_ST6422 },	/* QuickCam Communicate */
604 	{USB_DEVICE(0x046D, 0x08F6), .driver_info = BRIDGE_ST6422 },	/* QuickCam Messenger (new) */
605 	{}
606 };
607 MODULE_DEVICE_TABLE(usb, device_table);
608 
609 /* -- device connect -- */
sd_probe(struct usb_interface * intf,const struct usb_device_id * id)610 static int sd_probe(struct usb_interface *intf,
611 			const struct usb_device_id *id)
612 {
613 	return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
614 			       THIS_MODULE);
615 }
616 
sd_disconnect(struct usb_interface * intf)617 static void sd_disconnect(struct usb_interface *intf)
618 {
619 	struct gspca_dev *gspca_dev = usb_get_intfdata(intf);
620 	struct sd *sd = (struct sd *) gspca_dev;
621 	void *priv = sd->sensor_priv;
622 	gspca_dbg(gspca_dev, D_PROBE, "Disconnecting the stv06xx device\n");
623 
624 	sd->sensor = NULL;
625 	gspca_disconnect(intf);
626 	kfree(priv);
627 }
628 
629 static struct usb_driver sd_driver = {
630 	.name = MODULE_NAME,
631 	.id_table = device_table,
632 	.probe = sd_probe,
633 	.disconnect = sd_disconnect,
634 #ifdef CONFIG_PM
635 	.suspend = gspca_suspend,
636 	.resume = gspca_resume,
637 	.reset_resume = gspca_resume,
638 #endif
639 };
640 
641 module_usb_driver(sd_driver);
642 
643 module_param(dump_bridge, bool, S_IRUGO | S_IWUSR);
644 MODULE_PARM_DESC(dump_bridge, "Dumps all usb bridge registers at startup");
645 
646 module_param(dump_sensor, bool, S_IRUGO | S_IWUSR);
647 MODULE_PARM_DESC(dump_sensor, "Dumps all sensor registers at startup");
648