Lines Matching +full:1 +full:- +full:sd
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) 2001 Jean-Fredric Clere, Nikolas Zimmermann, Georg Acher
4 * Mark Cave-Ayland, Carlo E Prelz, Dick Streefland
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
29 int stv06xx_write_bridge(struct sd *sd, u16 address, u16 i2c_data) in stv06xx_write_bridge() argument
32 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd; in stv06xx_write_bridge()
33 struct usb_device *udev = sd->gspca_dev.dev; in stv06xx_write_bridge()
34 __u8 *buf = sd->gspca_dev.usb_buf; in stv06xx_write_bridge()
36 u8 len = (i2c_data > 0xff) ? 2 : 1; in stv06xx_write_bridge()
39 buf[1] = (i2c_data >> 8) & 0xff; in stv06xx_write_bridge()
51 int stv06xx_read_bridge(struct sd *sd, u16 address, u8 *i2c_data) in stv06xx_read_bridge() argument
54 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd; in stv06xx_read_bridge()
55 struct usb_device *udev = sd->gspca_dev.dev; in stv06xx_read_bridge()
56 __u8 *buf = sd->gspca_dev.usb_buf; in stv06xx_read_bridge()
59 0x04, 0xc0, address, 0, buf, 1, in stv06xx_read_bridge()
72 int stv06xx_write_sensor(struct sd *sd, u8 address, u16 value) in stv06xx_write_sensor() argument
74 if (sd->sensor->i2c_len == 2) { in stv06xx_write_sensor()
76 return stv06xx_write_sensor_words(sd, data, 1); in stv06xx_write_sensor()
79 return stv06xx_write_sensor_bytes(sd, data, 1); in stv06xx_write_sensor()
83 static int stv06xx_write_sensor_finish(struct sd *sd) in stv06xx_write_sensor_finish() argument
87 if (sd->bridge == BRIDGE_STV610) { in stv06xx_write_sensor_finish()
88 struct usb_device *udev = sd->gspca_dev.dev; in stv06xx_write_sensor_finish()
89 __u8 *buf = sd->gspca_dev.usb_buf; in stv06xx_write_sensor_finish()
93 0x04, 0x40, 0x1704, 0, buf, 1, in stv06xx_write_sensor_finish()
100 int stv06xx_write_sensor_bytes(struct sd *sd, const u8 *data, u8 len) in stv06xx_write_sensor_bytes() argument
103 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd; in stv06xx_write_sensor_bytes()
104 struct usb_device *udev = sd->gspca_dev.dev; in stv06xx_write_sensor_bytes()
105 __u8 *buf = sd->gspca_dev.usb_buf; in stv06xx_write_sensor_bytes()
114 buf[0x10 + j] = data[2*i+1]; in stv06xx_write_sensor_bytes()
116 data[2*i+1], data[2*i]); in stv06xx_write_sensor_bytes()
118 buf[0x20] = sd->sensor->i2c_addr; in stv06xx_write_sensor_bytes()
119 buf[0x21] = j - 1; /* Number of commands to send - 1 */ in stv06xx_write_sensor_bytes()
128 return stv06xx_write_sensor_finish(sd); in stv06xx_write_sensor_bytes()
131 int stv06xx_write_sensor_words(struct sd *sd, const u16 *data, u8 len) in stv06xx_write_sensor_words() argument
134 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd; in stv06xx_write_sensor_words()
135 struct usb_device *udev = sd->gspca_dev.dev; in stv06xx_write_sensor_words()
136 __u8 *buf = sd->gspca_dev.usb_buf; in stv06xx_write_sensor_words()
146 buf[0x10 + j * 2] = data[2*i+1]; in stv06xx_write_sensor_words()
147 buf[0x10 + j * 2 + 1] = data[2*i+1] >> 8; in stv06xx_write_sensor_words()
149 data[2*i+1], data[2*i]); in stv06xx_write_sensor_words()
151 buf[0x20] = sd->sensor->i2c_addr; in stv06xx_write_sensor_words()
152 buf[0x21] = j - 1; /* Number of commands to send - 1 */ in stv06xx_write_sensor_words()
161 return stv06xx_write_sensor_finish(sd); in stv06xx_write_sensor_words()
164 int stv06xx_read_sensor(struct sd *sd, const u8 address, u16 *value) in stv06xx_read_sensor() argument
167 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd; in stv06xx_read_sensor()
168 struct usb_device *udev = sd->gspca_dev.dev; in stv06xx_read_sensor()
169 __u8 *buf = sd->gspca_dev.usb_buf; in stv06xx_read_sensor()
171 err = stv06xx_write_bridge(sd, STV_I2C_FLUSH, sd->sensor->i2c_flush); in stv06xx_read_sensor()
179 buf[0x20] = sd->sensor->i2c_addr; in stv06xx_read_sensor()
194 0x04, 0xc0, 0x1410, 0, buf, sd->sensor->i2c_len, in stv06xx_read_sensor()
196 if (sd->sensor->i2c_len == 2) in stv06xx_read_sensor()
197 *value = buf[0] | (buf[1] << 8); in stv06xx_read_sensor()
208 static void stv06xx_dump_bridge(struct sd *sd) in stv06xx_dump_bridge() argument
215 stv06xx_read_bridge(sd, i, &data); in stv06xx_dump_bridge()
222 stv06xx_read_bridge(sd, i, &data); in stv06xx_dump_bridge()
225 stv06xx_write_bridge(sd, i, 0xff); in stv06xx_dump_bridge()
226 stv06xx_read_bridge(sd, i, &data); in stv06xx_dump_bridge()
233 pr_info("Register 0x%x is read-only\n", i); in stv06xx_dump_bridge()
235 stv06xx_write_bridge(sd, i, buf); in stv06xx_dump_bridge()
242 struct sd *sd = (struct sd *) gspca_dev; in stv06xx_init() local
251 err = sd->sensor->init(sd); in stv06xx_init()
253 if (dump_sensor && sd->sensor->dump) in stv06xx_init()
254 sd->sensor->dump(sd); in stv06xx_init()
262 struct sd *sd = (struct sd *) gspca_dev; in stv06xx_init_controls() local
266 gspca_dev->vdev.ctrl_handler = &gspca_dev->ctrl_handler; in stv06xx_init_controls()
267 return sd->sensor->init_controls(sd); in stv06xx_init_controls()
273 struct sd *sd = (struct sd *) gspca_dev; in stv06xx_start() local
278 intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface); in stv06xx_start()
279 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt); in stv06xx_start()
282 return -EIO; in stv06xx_start()
285 if (alt->desc.bNumEndpoints < 1) in stv06xx_start()
286 return -ENODEV; in stv06xx_start()
288 packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize); in stv06xx_start()
289 err = stv06xx_write_bridge(sd, STV_ISO_SIZE_L, packet_size); in stv06xx_start()
294 err = sd->sensor->start(sd); in stv06xx_start()
299 err = stv06xx_write_bridge(sd, STV_ISO_ENABLE, 1); in stv06xx_start()
314 struct sd *sd = (struct sd *) gspca_dev; in stv06xx_isoc_init() local
316 intfc = gspca_dev->dev->actconfig->intf_cache[0]; in stv06xx_isoc_init()
318 if (intfc->num_altsetting < 2) in stv06xx_isoc_init()
319 return -ENODEV; in stv06xx_isoc_init()
321 alt = &intfc->altsetting[1]; in stv06xx_isoc_init()
323 if (alt->desc.bNumEndpoints < 1) in stv06xx_isoc_init()
324 return -ENODEV; in stv06xx_isoc_init()
327 alt->endpoint[0].desc.wMaxPacketSize = in stv06xx_isoc_init()
328 cpu_to_le16(sd->sensor->max_packet_size[gspca_dev->curr_mode]); in stv06xx_isoc_init()
337 struct sd *sd = (struct sd *) gspca_dev; in stv06xx_isoc_nego() local
343 alt = &gspca_dev->dev->actconfig->intf_cache[0]->altsetting[1]; in stv06xx_isoc_nego()
344 packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize); in stv06xx_isoc_nego()
345 min_packet_size = sd->sensor->min_packet_size[gspca_dev->curr_mode]; in stv06xx_isoc_nego()
347 return -EIO; in stv06xx_isoc_nego()
349 packet_size -= 100; in stv06xx_isoc_nego()
352 alt->endpoint[0].desc.wMaxPacketSize = cpu_to_le16(packet_size); in stv06xx_isoc_nego()
354 ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, 1); in stv06xx_isoc_nego()
356 gspca_err(gspca_dev, "set alt 1 err %d\n", ret); in stv06xx_isoc_nego()
364 struct sd *sd = (struct sd *) gspca_dev; in stv06xx_stopN() local
366 /* stop ISO-streaming */ in stv06xx_stopN()
367 err = stv06xx_write_bridge(sd, STV_ISO_ENABLE, 0); in stv06xx_stopN()
371 err = sd->sensor->stop(sd); in stv06xx_stopN()
383 * 2-bytes identification, followed by 2-bytes that describe the chunk
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
396 struct sd *sd = (struct sd *) gspca_dev; in stv06xx_pkt_scan() local
411 id = (data[0] << 8) | data[1]; in stv06xx_pkt_scan()
419 len -= 4; in stv06xx_pkt_scan()
423 gspca_dev->last_packet_type = DISCARD_PACKET; in stv06xx_pkt_scan()
428 if (sd->bridge == BRIDGE_ST6422 && (id & 0xff00) == 0x0200) in stv06xx_pkt_scan()
437 if (sd->to_skip) { in stv06xx_pkt_scan()
438 int skip = (sd->to_skip < chunk_len) ? in stv06xx_pkt_scan()
439 sd->to_skip : chunk_len; in stv06xx_pkt_scan()
441 len -= skip; in stv06xx_pkt_scan()
442 chunk_len -= skip; in stv06xx_pkt_scan()
443 sd->to_skip -= skip; in stv06xx_pkt_scan()
460 if (sd->bridge == BRIDGE_ST6422) in stv06xx_pkt_scan()
461 sd->to_skip = gspca_dev->pixfmt.width * 4; in stv06xx_pkt_scan()
464 gspca_err(gspca_dev, "Chunk length is non-zero on a SOF\n"); in stv06xx_pkt_scan()
477 gspca_err(gspca_dev, "Chunk length is non-zero on a EOF\n"); in stv06xx_pkt_scan()
490 occurs 2-3 times per USB interrupt */ in stv06xx_pkt_scan()
502 len -= chunk_len; in stv06xx_pkt_scan()
511 int ret = -EINVAL; in sd_int_pkt_scan()
513 if (len == 1 && (data[0] == 0x80 || data[0] == 0x10)) { in sd_int_pkt_scan()
514 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1); in sd_int_pkt_scan()
515 input_sync(gspca_dev->input_dev); in sd_int_pkt_scan()
519 if (len == 1 && (data[0] == 0x88 || data[0] == 0x11)) { in sd_int_pkt_scan()
520 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0); in sd_int_pkt_scan()
521 input_sync(gspca_dev->input_dev); in sd_int_pkt_scan()
534 struct sd *sd = (struct sd *)gspca_dev; in stv06xx_probe_error() local
536 kfree(sd->sensor_priv); in stv06xx_probe_error()
537 sd->sensor_priv = NULL; in stv06xx_probe_error()
540 /* sub-driver description */
561 struct sd *sd = (struct sd *) gspca_dev; in stv06xx_config() local
565 sd->bridge = id->driver_info; in stv06xx_config()
566 gspca_dev->sd_desc = &sd_desc; in stv06xx_config()
569 stv06xx_dump_bridge(sd); in stv06xx_config()
571 sd->sensor = &stv06xx_sensor_st6422; in stv06xx_config()
572 if (!sd->sensor->probe(sd)) in stv06xx_config()
575 sd->sensor = &stv06xx_sensor_vv6410; in stv06xx_config()
576 if (!sd->sensor->probe(sd)) in stv06xx_config()
579 sd->sensor = &stv06xx_sensor_hdcs1x00; in stv06xx_config()
580 if (!sd->sensor->probe(sd)) in stv06xx_config()
583 sd->sensor = &stv06xx_sensor_hdcs1020; in stv06xx_config()
584 if (!sd->sensor->probe(sd)) in stv06xx_config()
587 sd->sensor = &stv06xx_sensor_pb0100; in stv06xx_config()
588 if (!sd->sensor->probe(sd)) in stv06xx_config()
591 sd->sensor = NULL; in stv06xx_config()
592 return -ENODEV; in stv06xx_config()
597 /* -- module initialisation -- */
609 /* -- device connect -- */
613 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd), in sd_probe()
620 struct sd *sd = (struct sd *) gspca_dev; in sd_disconnect() local
621 void *priv = sd->sensor_priv; in sd_disconnect()
624 sd->sensor = NULL; in sd_disconnect()