19 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30 static bool dump_bridge;
34 {USB_DEVICE(0x0402, 0x5602)},
49 0x8100 + address, buf,
53 PDEBUG(D_CONF,
"Reading bridge register 0x%x containing 0x%x",
58 return (err < 0) ? err : 0;
68 PDEBUG(D_CONF,
"Writing bridge register 0x%x with 0x%x",
71 memcpy(buf, bridge_urb_skeleton,
72 sizeof(bridge_urb_skeleton));
83 return (err < 0) ? err : 0;
86 static int m5602_wait_for_i2c(
struct sd *
sd)
102 if (!len || len > sd->
sensor->i2c_regW)
105 err = m5602_wait_for_i2c(sd);
110 sd->
sensor->i2c_slave_id);
122 if (sd->
sensor->i2c_regW == 1) {
132 for (i = 0; (i < len) && !err; i++) {
133 err = m5602_wait_for_i2c(sd);
139 PDEBUG(D_CONF,
"Reading sensor register "
140 "0x%x containing 0x%x ", address, *i2c_data);
154 if (len > sd->
sensor->i2c_regW || !len)
157 memcpy(buf, sensor_urb_skeleton,
158 sizeof(sensor_urb_skeleton));
160 buf[11] = sd->
sensor->i2c_slave_id;
167 for (i = 0; i < len; i++) {
168 memcpy(p, sensor_urb_skeleton + 16, 4);
171 PDEBUG(D_CONF,
"Writing sensor register 0x%x with 0x%x",
172 address, i2c_data[i]);
176 memcpy(p, sensor_urb_skeleton + 20, 4);
186 return (err < 0) ? err : 0;
191 static void m5602_dump_bridge(
struct sd *sd)
194 for (i = 0; i < 0x80; i++) {
195 unsigned char val = 0;
197 pr_info(
"ALi m5602 address 0x%x contains 0x%x\n", i, val);
199 pr_info(
"Warning: The ALi m5602 webcam probably won't work until it's power cycled\n");
202 static int m5602_probe_sensor(
struct sd *sd)
206 if (!sd->
sensor->probe(sd))
211 if (!sd->
sensor->probe(sd))
216 if (!sd->
sensor->probe(sd))
221 if (!sd->
sensor->probe(sd))
226 if (!sd->
sensor->probe(sd))
231 if (!sd->
sensor->probe(sd))
235 pr_info(
"Failed to find a sensor\n");
245 struct sd *sd = (
struct sd *) gspca_dev;
248 PDEBUG(D_CONF,
"Initializing ALi m5602 webcam");
250 err = sd->
sensor->init(sd);
255 static int m5602_start_transfer(
struct gspca_dev *gspca_dev)
257 struct sd *sd = (
struct sd *) gspca_dev;
262 const u8 buffer[4] = {0x13, 0xf9, 0x0f, 0x01};
267 memcpy(buf, buffer,
sizeof(buffer));
269 usb_sndctrlpipe(gspca_dev->
dev, 0),
270 0x04, 0x40, 0x19, 0x0000, buf,
273 PDEBUG(D_STREAM,
"Transfer started");
274 return (err < 0) ? err : 0;
277 static void m5602_urb_complete(
struct gspca_dev *gspca_dev,
280 struct sd *sd = (
struct sd *) gspca_dev;
283 PDEBUG(D_PACK,
"Packet is less than 6 bytes");
288 if (data[0] == 0xff && data[4] == 0xff && data[5] == 0xff &&
290 PDEBUG(D_FRAM,
"Frame delimiter detected");
305 PDEBUG(D_FRAM,
"Starting new frame %d",
316 if (cur_frame_len + len <= gspca_dev->frsz) {
317 PDEBUG(D_FRAM,
"Continuing frame %d copying %d bytes",
325 gspca_dev->
frsz - cur_frame_len);
330 static void m5602_stop_transfer(
struct gspca_dev *gspca_dev)
332 struct sd *sd = (
struct sd *) gspca_dev;
342 .config = m5602_configure,
344 .start = m5602_start_transfer,
345 .stopN = m5602_stop_transfer,
346 .pkt_scan = m5602_urb_complete
350 static int m5602_configure(
struct gspca_dev *gspca_dev,
353 struct sd *sd = (
struct sd *) gspca_dev;
357 cam = &gspca_dev->
cam;
361 m5602_dump_bridge(sd);
364 err = m5602_probe_sensor(sd);
387 struct gspca_dev *gspca_dev = usb_get_intfdata(intf);
388 struct sd *sd = (
struct sd *) gspca_dev;
390 if (sd->
sensor->disconnect)
391 sd->
sensor->disconnect(sd);
396 static struct usb_driver sd_driver = {
398 .id_table = m5602_table,
399 .probe = m5602_probe,
401 .suspend = gspca_suspend,
402 .resume = gspca_resume,
403 .reset_resume = gspca_resume,
405 .disconnect = m5602_disconnect
415 "forces detection of a sensor, "
416 "1 = OV9650, 2 = S5K83A, 3 = S5K4AA, "
417 "4 = MT9M111, 5 = PO1030, 6 = OV7660");
424 "at startup providing a sensor is found");