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