30 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
32 #include <linux/input.h>
39 static bool dump_bridge;
47 u8 len = (i2c_data > 0xff) ? 2 : 1;
49 buf[0] = i2c_data & 0xff;
50 buf[1] = (i2c_data >> 8) & 0xff;
53 0x04, 0x40, address, 0, buf, len,
56 PDEBUG(D_CONF,
"Written 0x%x to address 0x%x, status: %d",
57 i2c_data, address, err);
59 return (err < 0) ? err : 0;
69 0x04, 0xc0, address, 0, buf, 1,
74 PDEBUG(D_CONF,
"Reading 0x%x from address 0x%x, status %d",
75 *i2c_data, address, err);
77 return (err < 0) ? err : 0;
84 if (sd->
sensor->i2c_len == 2) {
93 static int stv06xx_write_sensor_finish(
struct sd *
sd)
103 0x04, 0x40, 0x1704, 0, buf, 1,
107 return (err < 0) ? err : 0;
113 struct usb_device *udev = sd->
gspca_dev.dev;
116 PDEBUG(D_CONF,
"I2C: Command buffer contains %d entries", len);
117 for (i = 0; i < len;) {
122 buf[0x10 +
j] = data[2*i+1];
123 PDEBUG(D_CONF,
"I2C: Writing 0x%02x to reg 0x%02x",
124 data[2*i+1], data[2*i]);
126 buf[0x20] = sd->
sensor->i2c_addr;
130 0x04, 0x40, 0x0400, 0, buf,
136 return stv06xx_write_sensor_finish(sd);
142 struct usb_device *udev = sd->
gspca_dev.dev;
145 PDEBUG(D_CONF,
"I2C: Command buffer contains %d entries", len);
147 for (i = 0; i < len;) {
152 buf[0x10 + j * 2] = data[2*i+1];
153 buf[0x10 + j * 2 + 1] = data[2*i+1] >> 8;
154 PDEBUG(D_CONF,
"I2C: Writing 0x%04x to reg 0x%02x",
155 data[2*i+1], data[2*i]);
157 buf[0x20] = sd->
sensor->i2c_addr;
161 0x04, 0x40, 0x0400, 0, buf,
167 return stv06xx_write_sensor_finish(sd);
173 struct usb_device *udev = sd->
gspca_dev.dev;
184 buf[0x20] = sd->
sensor->i2c_addr;
194 pr_err(
"I2C: Read error writing address: %d\n", err);
199 0x04, 0xc0, 0x1410, 0, buf, sd->
sensor->i2c_len,
201 if (sd->
sensor->i2c_len == 2)
202 *value = buf[0] | (buf[1] << 8);
206 PDEBUG(D_CONF,
"I2C: Read 0x%x from address 0x%x, status: %d",
207 *value, address, err);
209 return (err < 0) ? err : 0;
213 static void stv06xx_dump_bridge(
struct sd *sd)
218 pr_info(
"Dumping all stv06xx bridge registers\n");
219 for (i = 0x1400; i < 0x160f; i++) {
222 pr_info(
"Read 0x%x from address 0x%x\n", data, i);
225 pr_info(
"Testing stv06xx bridge registers for writability\n");
226 for (i = 0x1400; i < 0x160f; i++) {
233 pr_info(
"Register 0x%x is read/write\n", i);
234 else if (data != buf)
235 pr_info(
"Register 0x%x is read/write, but only partially\n",
238 pr_info(
"Register 0x%x is read-only\n", i);
247 struct sd *sd = (
struct sd *) gspca_dev;
250 PDEBUG(D_PROBE,
"Initializing camera");
256 err = sd->
sensor->init(sd);
261 return (err < 0) ? err : 0;
265 static int stv06xx_init_controls(
struct gspca_dev *gspca_dev)
267 struct sd *sd = (
struct sd *) gspca_dev;
269 PDEBUG(D_PROBE,
"Initializing controls");
272 return sd->
sensor->init_controls(sd);
276 static int stv06xx_start(
struct gspca_dev *gspca_dev)
278 struct sd *sd = (
struct sd *) gspca_dev;
279 struct usb_host_interface *alt;
281 int err, packet_size;
290 packet_size =
le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
296 err = sd->
sensor->start(sd);
305 PDEBUG(D_STREAM,
"Starting stream failed");
307 PDEBUG(D_STREAM,
"Started streaming");
309 return (err < 0) ? err : 0;
312 static int stv06xx_isoc_init(
struct gspca_dev *gspca_dev)
314 struct usb_host_interface *alt;
315 struct sd *sd = (
struct sd *) gspca_dev;
318 alt = &gspca_dev->
dev->actconfig->intf_cache[0]->altsetting[1];
319 alt->endpoint[0].desc.wMaxPacketSize =
325 static int stv06xx_isoc_nego(
struct gspca_dev *gspca_dev)
327 int ret, packet_size, min_packet_size;
328 struct usb_host_interface *alt;
329 struct sd *sd = (
struct sd *) gspca_dev;
331 alt = &gspca_dev->
dev->actconfig->intf_cache[0]->altsetting[1];
332 packet_size =
le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
334 if (packet_size <= min_packet_size)
338 if (packet_size < min_packet_size)
339 packet_size = min_packet_size;
340 alt->endpoint[0].desc.wMaxPacketSize =
cpu_to_le16(packet_size);
349 static void stv06xx_stopN(
struct gspca_dev *gspca_dev)
352 struct sd *sd = (
struct sd *) gspca_dev;
359 err = sd->
sensor->stop(sd);
363 PDEBUG(D_STREAM,
"Failed to stop stream");
365 PDEBUG(D_STREAM,
"Stopped streaming");
380 static void stv06xx_pkt_scan(
struct gspca_dev *gspca_dev,
384 struct sd *sd = (
struct sd *) gspca_dev;
386 PDEBUG(D_PACK,
"Packet of length %d arrived", len);
394 PDEBUG(D_PACK,
"Packet is smaller than 4 bytes");
399 id = (data[0] << 8) | data[1];
402 chunk_len = (data[2] << 8) | data[3];
403 PDEBUG(D_PACK,
"Chunk id: %x, length: %d",
id, chunk_len);
408 if (len < chunk_len) {
410 " than the specified chunk length");
423 PDEBUG(D_PACK,
"Frame data packet detected");
442 PDEBUG(D_PACK,
"Starting new frame");
453 "non-zero on a SOF");
459 PDEBUG(D_PACK,
"End of frame detected");
467 "non-zero on a EOF");
471 PDEBUG(D_PACK,
"Chunk 0x005 detected");
478 PDEBUG(D_PACK,
"Chunk 0x0100 detected");
483 PDEBUG(D_PACK,
"Chunk 0x42ff detected");
487 PDEBUG(D_PACK,
"Unknown chunk 0x%04x detected",
id);
495 #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
496 static int sd_int_pkt_scan(
struct gspca_dev *gspca_dev,
502 if (len == 1 && data[0] == 0x80) {
503 input_report_key(gspca_dev->input_dev,
KEY_CAMERA, 1);
504 input_sync(gspca_dev->input_dev);
508 if (len == 1 && data[0] == 0x88) {
509 input_report_key(gspca_dev->input_dev,
KEY_CAMERA, 0);
510 input_sync(gspca_dev->input_dev);
518 static int stv06xx_config(
struct gspca_dev *gspca_dev,
524 .config = stv06xx_config,
525 .init = stv06xx_init,
526 .init_controls = stv06xx_init_controls,
527 .start = stv06xx_start,
528 .stopN = stv06xx_stopN,
529 .pkt_scan = stv06xx_pkt_scan,
530 .isoc_init = stv06xx_isoc_init,
531 .isoc_nego = stv06xx_isoc_nego,
532 #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
533 .int_pkt_scan = sd_int_pkt_scan,
538 static int stv06xx_config(
struct gspca_dev *gspca_dev,
541 struct sd *sd = (
struct sd *) gspca_dev;
543 PDEBUG(D_PROBE,
"Configuring camera");
545 sd->
bridge =
id->driver_info;
549 stv06xx_dump_bridge(sd);
552 if (!sd->
sensor->probe(sd))
556 if (!sd->
sensor->probe(sd))
560 if (!sd->
sensor->probe(sd))
564 if (!sd->
sensor->probe(sd))
568 if (!sd->
sensor->probe(sd))
599 PDEBUG(D_PROBE,
"Probing for a stv06xx device");
606 struct gspca_dev *gspca_dev = usb_get_intfdata(intf);
607 struct sd *sd = (
struct sd *) gspca_dev;
609 PDEBUG(D_PROBE,
"Disconnecting the stv06xx device");
616 static struct usb_driver sd_driver = {
618 .id_table = device_table,
620 .disconnect = sd_disconnect,
622 .suspend = gspca_suspend,
623 .resume = gspca_resume,
624 .reset_resume = gspca_resume,