stv06xx.c 16 KB

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