spca561.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201
  1. /*
  2. * Sunplus spca561 subdriver
  3. *
  4. * Copyright (C) 2004 Michel Xhaard mxhaard@magic.fr
  5. *
  6. * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #define MODULE_NAME "spca561"
  23. #include "gspca.h"
  24. MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
  25. MODULE_DESCRIPTION("GSPCA/SPCA561 USB Camera Driver");
  26. MODULE_LICENSE("GPL");
  27. /* specific webcam descriptor */
  28. struct sd {
  29. struct gspca_dev gspca_dev; /* !! must be the first item */
  30. __u16 contrast; /* rev72a only */
  31. #define CONTRAST_MIN 0x0000
  32. #define CONTRAST_DEF 0x2000
  33. #define CONTRAST_MAX 0x3fff
  34. __u16 exposure; /* rev12a only */
  35. #define EXPOSURE_MIN 0
  36. #define EXPOSURE_DEF 200
  37. #define EXPOSURE_MAX 762
  38. __u8 brightness; /* rev72a only */
  39. #define BRIGHTNESS_MIN 0
  40. #define BRIGHTNESS_DEF 32
  41. #define BRIGHTNESS_MAX 63
  42. __u8 white; /* rev12a only */
  43. #define WHITE_MIN 1
  44. #define WHITE_DEF 0x40
  45. #define WHITE_MAX 0x7f
  46. __u8 autogain;
  47. #define AUTOGAIN_MIN 0
  48. #define AUTOGAIN_DEF 1
  49. #define AUTOGAIN_MAX 1
  50. __u8 gain; /* rev12a only */
  51. #define GAIN_MIN 0x0
  52. #define GAIN_DEF 0x24
  53. #define GAIN_MAX 0x24
  54. #define EXPO12A_DEF 3
  55. __u8 expo12a; /* expo/gain? for rev 12a */
  56. __u8 chip_revision;
  57. #define Rev012A 0
  58. #define Rev072A 1
  59. signed char ag_cnt;
  60. #define AG_CNT_START 13
  61. };
  62. static struct v4l2_pix_format sif_mode[] = {
  63. {160, 120, V4L2_PIX_FMT_SGBRG8, V4L2_FIELD_NONE,
  64. .bytesperline = 160,
  65. .sizeimage = 160 * 120,
  66. .colorspace = V4L2_COLORSPACE_SRGB,
  67. .priv = 3},
  68. {176, 144, V4L2_PIX_FMT_SGBRG8, V4L2_FIELD_NONE,
  69. .bytesperline = 176,
  70. .sizeimage = 176 * 144,
  71. .colorspace = V4L2_COLORSPACE_SRGB,
  72. .priv = 2},
  73. {320, 240, V4L2_PIX_FMT_SPCA561, V4L2_FIELD_NONE,
  74. .bytesperline = 320,
  75. .sizeimage = 320 * 240 * 4 / 8,
  76. .colorspace = V4L2_COLORSPACE_SRGB,
  77. .priv = 1},
  78. {352, 288, V4L2_PIX_FMT_SPCA561, V4L2_FIELD_NONE,
  79. .bytesperline = 352,
  80. .sizeimage = 352 * 288 * 4 / 8,
  81. .colorspace = V4L2_COLORSPACE_SRGB,
  82. .priv = 0},
  83. };
  84. /*
  85. * Initialization data
  86. * I'm not very sure how to split initialization from open data
  87. * chunks. For now, we'll consider everything as initialization
  88. */
  89. /* Frame packet header offsets for the spca561 */
  90. #define SPCA561_OFFSET_SNAP 1
  91. #define SPCA561_OFFSET_TYPE 2
  92. #define SPCA561_OFFSET_COMPRESS 3
  93. #define SPCA561_OFFSET_FRAMSEQ 4
  94. #define SPCA561_OFFSET_GPIO 5
  95. #define SPCA561_OFFSET_USBBUFF 6
  96. #define SPCA561_OFFSET_WIN2GRAVE 7
  97. #define SPCA561_OFFSET_WIN2RAVE 8
  98. #define SPCA561_OFFSET_WIN2BAVE 9
  99. #define SPCA561_OFFSET_WIN2GBAVE 10
  100. #define SPCA561_OFFSET_WIN1GRAVE 11
  101. #define SPCA561_OFFSET_WIN1RAVE 12
  102. #define SPCA561_OFFSET_WIN1BAVE 13
  103. #define SPCA561_OFFSET_WIN1GBAVE 14
  104. #define SPCA561_OFFSET_FREQ 15
  105. #define SPCA561_OFFSET_VSYNC 16
  106. #define SPCA561_OFFSET_DATA 1
  107. #define SPCA561_INDEX_I2C_BASE 0x8800
  108. #define SPCA561_SNAPBIT 0x20
  109. #define SPCA561_SNAPCTRL 0x40
  110. static void reg_w_val(struct usb_device *dev, __u16 index, __u8 value)
  111. {
  112. int ret;
  113. ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
  114. 0, /* request */
  115. USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  116. value, index, NULL, 0, 500);
  117. PDEBUG(D_USBO, "reg write: 0x%02x:0x%02x", index, value);
  118. if (ret < 0)
  119. PDEBUG(D_ERR, "reg write: error %d", ret);
  120. }
  121. static void write_vector(struct gspca_dev *gspca_dev,
  122. const __u16 data[][2])
  123. {
  124. struct usb_device *dev = gspca_dev->dev;
  125. int i;
  126. i = 0;
  127. while (data[i][1] != 0) {
  128. reg_w_val(dev, data[i][1], data[i][0]);
  129. i++;
  130. }
  131. }
  132. /* read 'len' bytes to gspca_dev->usb_buf */
  133. static void reg_r(struct gspca_dev *gspca_dev,
  134. __u16 index, __u16 length)
  135. {
  136. usb_control_msg(gspca_dev->dev,
  137. usb_rcvctrlpipe(gspca_dev->dev, 0),
  138. 0, /* request */
  139. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  140. 0, /* value */
  141. index, gspca_dev->usb_buf, length, 500);
  142. }
  143. static void reg_w_buf(struct gspca_dev *gspca_dev,
  144. __u16 index, const __u8 *buffer, __u16 len)
  145. {
  146. memcpy(gspca_dev->usb_buf, buffer, len);
  147. usb_control_msg(gspca_dev->dev,
  148. usb_sndctrlpipe(gspca_dev->dev, 0),
  149. 0, /* request */
  150. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  151. 0, /* value */
  152. index, gspca_dev->usb_buf, len, 500);
  153. }
  154. static void i2c_write(struct gspca_dev *gspca_dev, __u16 valeur, __u16 reg)
  155. {
  156. int retry = 60;
  157. __u8 DataLow;
  158. __u8 DataHight;
  159. DataLow = valeur;
  160. DataHight = valeur >> 8;
  161. reg_w_val(gspca_dev->dev, 0x8801, reg);
  162. reg_w_val(gspca_dev->dev, 0x8805, DataLow);
  163. reg_w_val(gspca_dev->dev, 0x8800, DataHight);
  164. while (retry--) {
  165. reg_r(gspca_dev, 0x8803, 1);
  166. if (!gspca_dev->usb_buf[0])
  167. break;
  168. }
  169. }
  170. static int i2c_read(struct gspca_dev *gspca_dev, __u16 reg, __u8 mode)
  171. {
  172. int retry = 60;
  173. __u8 value;
  174. __u8 vallsb;
  175. reg_w_val(gspca_dev->dev, 0x8804, 0x92);
  176. reg_w_val(gspca_dev->dev, 0x8801, reg);
  177. reg_w_val(gspca_dev->dev, 0x8802, (mode | 0x01));
  178. while (retry--) {
  179. reg_r(gspca_dev, 0x8803, 1);
  180. if (!gspca_dev->usb_buf)
  181. break;
  182. }
  183. if (retry == 0)
  184. return -1;
  185. reg_r(gspca_dev, 0x8800, 1);
  186. value = gspca_dev->usb_buf[0];
  187. reg_r(gspca_dev, 0x8805, 1);
  188. vallsb = gspca_dev->usb_buf[0];
  189. return ((int) value << 8) | vallsb;
  190. }
  191. static const __u16 spca561_init_data[][2] = {
  192. {0x0000, 0x8114}, /* Software GPIO output data */
  193. {0x0001, 0x8114}, /* Software GPIO output data */
  194. {0x0000, 0x8112}, /* Some kind of reset */
  195. {0x0003, 0x8701}, /* PCLK clock delay adjustment */
  196. {0x0001, 0x8703}, /* HSYNC from cmos inverted */
  197. {0x0011, 0x8118}, /* Enable and conf sensor */
  198. {0x0001, 0x8118}, /* Conf sensor */
  199. {0x0092, 0x8804}, /* I know nothing about these */
  200. {0x0010, 0x8802}, /* 0x88xx registers, so I won't */
  201. /***************/
  202. {0x000d, 0x8805}, /* sensor default setting */
  203. {0x0001, 0x8801}, /* 1 <- 0x0d */
  204. {0x0000, 0x8800},
  205. {0x0018, 0x8805},
  206. {0x0002, 0x8801}, /* 2 <- 0x18 */
  207. {0x0000, 0x8800},
  208. {0x0065, 0x8805},
  209. {0x0004, 0x8801}, /* 4 <- 0x01 0x65 */
  210. {0x0001, 0x8800},
  211. {0x0021, 0x8805},
  212. {0x0005, 0x8801}, /* 5 <- 0x21 */
  213. {0x0000, 0x8800},
  214. {0x00aa, 0x8805},
  215. {0x0007, 0x8801}, /* 7 <- 0xaa */
  216. {0x0000, 0x8800},
  217. {0x0004, 0x8805},
  218. {0x0020, 0x8801}, /* 0x20 <- 0x15 0x04 */
  219. {0x0015, 0x8800},
  220. {0x0002, 0x8805},
  221. {0x0039, 0x8801}, /* 0x39 <- 0x02 */
  222. {0x0000, 0x8800},
  223. {0x0010, 0x8805},
  224. {0x0035, 0x8801}, /* 0x35 <- 0x10 */
  225. {0x0000, 0x8800},
  226. {0x0049, 0x8805},
  227. {0x0009, 0x8801}, /* 0x09 <- 0x10 0x49 */
  228. {0x0010, 0x8800},
  229. {0x000b, 0x8805},
  230. {0x0028, 0x8801}, /* 0x28 <- 0x0b */
  231. {0x0000, 0x8800},
  232. {0x000f, 0x8805},
  233. {0x003b, 0x8801}, /* 0x3b <- 0x0f */
  234. {0x0000, 0x8800},
  235. {0x0000, 0x8805},
  236. {0x003c, 0x8801}, /* 0x3c <- 0x00 */
  237. {0x0000, 0x8800},
  238. /***************/
  239. {0x0018, 0x8601}, /* Pixel/line selection for color separation */
  240. {0x0000, 0x8602}, /* Optical black level for user setting */
  241. {0x0060, 0x8604}, /* Optical black horizontal offset */
  242. {0x0002, 0x8605}, /* Optical black vertical offset */
  243. {0x0000, 0x8603}, /* Non-automatic optical black level */
  244. {0x0002, 0x865b}, /* Horizontal offset for valid pixels */
  245. {0x0000, 0x865f}, /* Vertical valid pixels window (x2) */
  246. {0x00b0, 0x865d}, /* Horizontal valid pixels window (x2) */
  247. {0x0090, 0x865e}, /* Vertical valid lines window (x2) */
  248. {0x00e0, 0x8406}, /* Memory buffer threshold */
  249. {0x0000, 0x8660}, /* Compensation memory stuff */
  250. {0x0002, 0x8201}, /* Output address for r/w serial EEPROM */
  251. {0x0008, 0x8200}, /* Clear valid bit for serial EEPROM */
  252. {0x0001, 0x8200}, /* OprMode to be executed by hardware */
  253. {0x0007, 0x8201}, /* Output address for r/w serial EEPROM */
  254. {0x0008, 0x8200}, /* Clear valid bit for serial EEPROM */
  255. {0x0001, 0x8200}, /* OprMode to be executed by hardware */
  256. {0x0010, 0x8660}, /* Compensation memory stuff */
  257. {0x0018, 0x8660}, /* Compensation memory stuff */
  258. {0x0004, 0x8611}, /* R offset for white balance */
  259. {0x0004, 0x8612}, /* Gr offset for white balance */
  260. {0x0007, 0x8613}, /* B offset for white balance */
  261. {0x0000, 0x8614}, /* Gb offset for white balance */
  262. {0x008c, 0x8651}, /* R gain for white balance */
  263. {0x008c, 0x8652}, /* Gr gain for white balance */
  264. {0x00b5, 0x8653}, /* B gain for white balance */
  265. {0x008c, 0x8654}, /* Gb gain for white balance */
  266. {0x0002, 0x8502}, /* Maximum average bit rate stuff */
  267. {0x0011, 0x8802},
  268. {0x0087, 0x8700}, /* Set master clock (96Mhz????) */
  269. {0x0081, 0x8702}, /* Master clock output enable */
  270. {0x0000, 0x8500}, /* Set image type (352x288 no compression) */
  271. /* Originally was 0x0010 (352x288 compression) */
  272. {0x0002, 0x865b}, /* Horizontal offset for valid pixels */
  273. {0x0003, 0x865c}, /* Vertical offset for valid lines */
  274. /***************//* sensor active */
  275. {0x0003, 0x8801}, /* 0x03 <- 0x01 0x21 //289 */
  276. {0x0021, 0x8805},
  277. {0x0001, 0x8800},
  278. {0x0004, 0x8801}, /* 0x04 <- 0x01 0x65 //357 */
  279. {0x0065, 0x8805},
  280. {0x0001, 0x8800},
  281. {0x0005, 0x8801}, /* 0x05 <- 0x2f */
  282. {0x002f, 0x8805},
  283. {0x0000, 0x8800},
  284. {0x0006, 0x8801}, /* 0x06 <- 0 */
  285. {0x0000, 0x8805},
  286. {0x0000, 0x8800},
  287. {0x000a, 0x8801}, /* 0x0a <- 2 */
  288. {0x0002, 0x8805},
  289. {0x0000, 0x8800},
  290. {0x0009, 0x8801}, /* 0x09 <- 0x1061 */
  291. {0x0061, 0x8805},
  292. {0x0010, 0x8800},
  293. {0x0035, 0x8801}, /* 0x35 <-0x14 */
  294. {0x0014, 0x8805},
  295. {0x0000, 0x8800},
  296. {0x0030, 0x8112}, /* ISO and drop packet enable */
  297. {0x0000, 0x8112}, /* Some kind of reset ???? */
  298. {0x0009, 0x8118}, /* Enable sensor and set standby */
  299. {0x0000, 0x8114}, /* Software GPIO output data */
  300. {0x0000, 0x8114}, /* Software GPIO output data */
  301. {0x0001, 0x8114}, /* Software GPIO output data */
  302. {0x0000, 0x8112}, /* Some kind of reset ??? */
  303. {0x0003, 0x8701},
  304. {0x0001, 0x8703},
  305. {0x0011, 0x8118},
  306. {0x0001, 0x8118},
  307. /***************/
  308. {0x0092, 0x8804},
  309. {0x0010, 0x8802},
  310. {0x000d, 0x8805},
  311. {0x0001, 0x8801},
  312. {0x0000, 0x8800},
  313. {0x0018, 0x8805},
  314. {0x0002, 0x8801},
  315. {0x0000, 0x8800},
  316. {0x0065, 0x8805},
  317. {0x0004, 0x8801},
  318. {0x0001, 0x8800},
  319. {0x0021, 0x8805},
  320. {0x0005, 0x8801},
  321. {0x0000, 0x8800},
  322. {0x00aa, 0x8805},
  323. {0x0007, 0x8801}, /* mode 0xaa */
  324. {0x0000, 0x8800},
  325. {0x0004, 0x8805},
  326. {0x0020, 0x8801},
  327. {0x0015, 0x8800}, /* mode 0x0415 */
  328. {0x0002, 0x8805},
  329. {0x0039, 0x8801},
  330. {0x0000, 0x8800},
  331. {0x0010, 0x8805},
  332. {0x0035, 0x8801},
  333. {0x0000, 0x8800},
  334. {0x0049, 0x8805},
  335. {0x0009, 0x8801},
  336. {0x0010, 0x8800},
  337. {0x000b, 0x8805},
  338. {0x0028, 0x8801},
  339. {0x0000, 0x8800},
  340. {0x000f, 0x8805},
  341. {0x003b, 0x8801},
  342. {0x0000, 0x8800},
  343. {0x0000, 0x8805},
  344. {0x003c, 0x8801},
  345. {0x0000, 0x8800},
  346. {0x0002, 0x8502},
  347. {0x0039, 0x8801},
  348. {0x0000, 0x8805},
  349. {0x0000, 0x8800},
  350. {0x0087, 0x8700}, /* overwrite by start */
  351. {0x0081, 0x8702},
  352. {0x0000, 0x8500},
  353. /* {0x0010, 0x8500}, -- Previous line was this */
  354. {0x0002, 0x865b},
  355. {0x0003, 0x865c},
  356. /***************/
  357. {0x0003, 0x8801}, /* 0x121-> 289 */
  358. {0x0021, 0x8805},
  359. {0x0001, 0x8800},
  360. {0x0004, 0x8801}, /* 0x165 -> 357 */
  361. {0x0065, 0x8805},
  362. {0x0001, 0x8800},
  363. {0x0005, 0x8801}, /* 0x2f //blanking control colonne */
  364. {0x002f, 0x8805},
  365. {0x0000, 0x8800},
  366. {0x0006, 0x8801}, /* 0x00 //blanking mode row */
  367. {0x0000, 0x8805},
  368. {0x0000, 0x8800},
  369. {0x000a, 0x8801}, /* 0x01 //0x02 */
  370. {0x0001, 0x8805},
  371. {0x0000, 0x8800},
  372. {0x0009, 0x8801}, /* 0x1061 - setexposure times && pixel clock
  373. * 0001 0 | 000 0110 0001 */
  374. {0x0061, 0x8805}, /* 61 31 */
  375. {0x0008, 0x8800}, /* 08 */
  376. {0x0035, 0x8801}, /* 0x14 - set gain general */
  377. {0x001f, 0x8805}, /* 0x14 */
  378. {0x0000, 0x8800},
  379. {0x000e, 0x8112}, /* white balance - was 30 */
  380. {}
  381. };
  382. /******************** QC Express etch2 stuff ********************/
  383. static const __u16 Pb100_1map8300[][2] = {
  384. /* reg, value */
  385. {0x8320, 0x3304},
  386. {0x8303, 0x0125}, /* image area */
  387. {0x8304, 0x0169},
  388. {0x8328, 0x000b},
  389. {0x833c, 0x0001}, /*fixme: win:07*/
  390. {0x832f, 0x1904}, /*fixme: was 0419*/
  391. {0x8307, 0x00aa},
  392. {0x8301, 0x0003},
  393. {0x8302, 0x000e},
  394. {}
  395. };
  396. static const __u16 Pb100_2map8300[][2] = {
  397. /* reg, value */
  398. {0x8339, 0x0000},
  399. {0x8307, 0x00aa},
  400. {}
  401. };
  402. static const __u16 spca561_161rev12A_data1[][2] = {
  403. {0x29, 0x8118}, /* white balance - was 21 */
  404. {0x08, 0x8114}, /* white balance - was 01 */
  405. {0x0e, 0x8112}, /* white balance - was 00 */
  406. {0x00, 0x8102}, /* white balance - new */
  407. {0x92, 0x8804},
  408. {0x04, 0x8802}, /* windows uses 08 */
  409. {}
  410. };
  411. static const __u16 spca561_161rev12A_data2[][2] = {
  412. {0x21, 0x8118},
  413. {0x10, 0x8500},
  414. {0x07, 0x8601},
  415. {0x07, 0x8602},
  416. {0x04, 0x8501},
  417. {0x21, 0x8118},
  418. {0x07, 0x8201}, /* windows uses 02 */
  419. {0x08, 0x8200},
  420. {0x01, 0x8200},
  421. {0x00, 0x8114},
  422. {0x01, 0x8114}, /* windows uses 00 */
  423. {0x90, 0x8604},
  424. {0x00, 0x8605},
  425. {0xb0, 0x8603},
  426. /* sensor gains */
  427. {0x07, 0x8601}, /* white balance - new */
  428. {0x07, 0x8602}, /* white balance - new */
  429. {0x00, 0x8610}, /* *red */
  430. {0x00, 0x8611}, /* 3f *green */
  431. {0x00, 0x8612}, /* green *blue */
  432. {0x00, 0x8613}, /* blue *green */
  433. {0x43, 0x8614}, /* green *red - white balance - was 0x35 */
  434. {0x40, 0x8615}, /* 40 *green - white balance - was 0x35 */
  435. {0x71, 0x8616}, /* 7a *blue - white balance - was 0x35 */
  436. {0x40, 0x8617}, /* 40 *green - white balance - was 0x35 */
  437. {0x0c, 0x8620}, /* 0c */
  438. {0xc8, 0x8631}, /* c8 */
  439. {0xc8, 0x8634}, /* c8 */
  440. {0x23, 0x8635}, /* 23 */
  441. {0x1f, 0x8636}, /* 1f */
  442. {0xdd, 0x8637}, /* dd */
  443. {0xe1, 0x8638}, /* e1 */
  444. {0x1d, 0x8639}, /* 1d */
  445. {0x21, 0x863a}, /* 21 */
  446. {0xe3, 0x863b}, /* e3 */
  447. {0xdf, 0x863c}, /* df */
  448. {0xf0, 0x8505},
  449. {0x32, 0x850a},
  450. /* {0x99, 0x8700}, * - white balance - new (removed) */
  451. {}
  452. };
  453. static void sensor_mapwrite(struct gspca_dev *gspca_dev,
  454. const __u16 sensormap[][2])
  455. {
  456. int i = 0;
  457. __u8 usbval[2];
  458. while (sensormap[i][0]) {
  459. usbval[0] = sensormap[i][1];
  460. usbval[1] = sensormap[i][1] >> 8;
  461. reg_w_buf(gspca_dev, sensormap[i][0], usbval, 2);
  462. i++;
  463. }
  464. }
  465. static void init_161rev12A(struct gspca_dev *gspca_dev)
  466. {
  467. /* sensor_reset(gspca_dev); (not in win) */
  468. write_vector(gspca_dev, spca561_161rev12A_data1);
  469. sensor_mapwrite(gspca_dev, Pb100_1map8300);
  470. /*fixme: should be in sd_start*/
  471. write_vector(gspca_dev, spca561_161rev12A_data2);
  472. sensor_mapwrite(gspca_dev, Pb100_2map8300);
  473. }
  474. /* this function is called at probe time */
  475. static int sd_config(struct gspca_dev *gspca_dev,
  476. const struct usb_device_id *id)
  477. {
  478. struct sd *sd = (struct sd *) gspca_dev;
  479. struct cam *cam;
  480. __u16 vendor, product;
  481. __u8 data1, data2;
  482. /* Read frm global register the USB product and vendor IDs, just to
  483. * prove that we can communicate with the device. This works, which
  484. * confirms at we are communicating properly and that the device
  485. * is a 561. */
  486. reg_r(gspca_dev, 0x8104, 1);
  487. data1 = gspca_dev->usb_buf[0];
  488. reg_r(gspca_dev, 0x8105, 1);
  489. data2 = gspca_dev->usb_buf[0];
  490. vendor = (data2 << 8) | data1;
  491. reg_r(gspca_dev, 0x8106, 1);
  492. data1 = gspca_dev->usb_buf[0];
  493. reg_r(gspca_dev, 0x8107, 1);
  494. data2 = gspca_dev->usb_buf[0];
  495. product = (data2 << 8) | data1;
  496. if (vendor != id->idVendor || product != id->idProduct) {
  497. PDEBUG(D_PROBE, "Bad vendor / product from device");
  498. return -EINVAL;
  499. }
  500. cam = &gspca_dev->cam;
  501. cam->epaddr = 0x01;
  502. gspca_dev->nbalt = 7 + 1; /* choose alternate 7 first */
  503. cam->cam_mode = sif_mode;
  504. cam->nmodes = ARRAY_SIZE(sif_mode);
  505. sd->chip_revision = id->driver_info;
  506. sd->brightness = BRIGHTNESS_DEF;
  507. sd->contrast = CONTRAST_DEF;
  508. sd->white = WHITE_DEF;
  509. sd->exposure = EXPOSURE_DEF;
  510. sd->autogain = AUTOGAIN_DEF;
  511. sd->gain = GAIN_DEF;
  512. sd->expo12a = EXPO12A_DEF;
  513. return 0;
  514. }
  515. /* this function is called at probe and resume time */
  516. static int sd_init_12a(struct gspca_dev *gspca_dev)
  517. {
  518. PDEBUG(D_STREAM, "Chip revision: 012a");
  519. init_161rev12A(gspca_dev);
  520. return 0;
  521. }
  522. static int sd_init_72a(struct gspca_dev *gspca_dev)
  523. {
  524. PDEBUG(D_STREAM, "Chip revision: 072a");
  525. write_vector(gspca_dev, spca561_init_data);
  526. return 0;
  527. }
  528. static void setcontrast(struct gspca_dev *gspca_dev)
  529. {
  530. struct sd *sd = (struct sd *) gspca_dev;
  531. struct usb_device *dev = gspca_dev->dev;
  532. __u8 lowb;
  533. switch (sd->chip_revision) {
  534. case Rev072A:
  535. lowb = sd->contrast >> 8;
  536. reg_w_val(dev, 0x8651, lowb);
  537. reg_w_val(dev, 0x8652, lowb);
  538. reg_w_val(dev, 0x8653, lowb);
  539. reg_w_val(dev, 0x8654, lowb);
  540. break;
  541. default: {
  542. /* case Rev012A: { */
  543. static const __u8 Reg8391[] =
  544. { 0x92, 0x30, 0x20, 0x00, 0x0c, 0x00, 0x00, 0x00 };
  545. reg_w_buf(gspca_dev, 0x8391, Reg8391, 8);
  546. reg_w_buf(gspca_dev, 0x8390, Reg8391, 8);
  547. break;
  548. }
  549. }
  550. }
  551. /* rev12a only */
  552. static void setwhite(struct gspca_dev *gspca_dev)
  553. {
  554. struct sd *sd = (struct sd *) gspca_dev;
  555. __u16 white;
  556. __u8 reg8614, reg8616;
  557. white = sd->white;
  558. /* try to emulate MS-win as possible */
  559. reg8616 = 0x90 - white * 5 / 8;
  560. reg_w_val(gspca_dev->dev, 0x8616, reg8616);
  561. reg8614 = 0x20 + white * 3 / 8;
  562. reg_w_val(gspca_dev->dev, 0x8614, reg8614);
  563. }
  564. /* rev 12a only */
  565. static void setexposure(struct gspca_dev *gspca_dev)
  566. {
  567. struct sd *sd = (struct sd *) gspca_dev;
  568. int expo;
  569. __u8 data[2];
  570. expo = sd->exposure + 0x20a8; /* from test */
  571. data[0] = expo;
  572. data[1] = expo >> 8;
  573. reg_w_buf(gspca_dev, 0x8309, data, 2);
  574. }
  575. /* rev 12a only */
  576. static void setgain(struct gspca_dev *gspca_dev)
  577. {
  578. struct sd *sd = (struct sd *) gspca_dev;
  579. __u8 data[2];
  580. data[0] = sd->gain;
  581. data[1] = 0;
  582. reg_w_buf(gspca_dev, 0x8335, data, 2);
  583. }
  584. static void setautogain(struct gspca_dev *gspca_dev)
  585. {
  586. struct sd *sd = (struct sd *) gspca_dev;
  587. if (sd->autogain)
  588. sd->ag_cnt = AG_CNT_START;
  589. else
  590. sd->ag_cnt = -1;
  591. }
  592. static void sd_start_12a(struct gspca_dev *gspca_dev)
  593. {
  594. struct usb_device *dev = gspca_dev->dev;
  595. int Clck;
  596. __u8 Reg8307[] = { 0xaa, 0x00 };
  597. int mode;
  598. mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
  599. switch (mode) {
  600. case 0:
  601. case 1:
  602. Clck = 0x8a;
  603. break;
  604. case 2:
  605. Clck = 0x85;
  606. break;
  607. default:
  608. Clck = 0x83;
  609. break;
  610. }
  611. if (mode <= 1) {
  612. /* Use compression on 320x240 and above */
  613. reg_w_val(dev, 0x8500, 0x10 | mode);
  614. } else {
  615. /* I couldn't get the compression to work below 320x240
  616. * Fortunately at these resolutions the bandwidth
  617. * is sufficient to push raw frames at ~20fps */
  618. reg_w_val(dev, 0x8500, mode);
  619. } /* -- qq@kuku.eu.org */
  620. reg_w_buf(gspca_dev, 0x8307, Reg8307, 2);
  621. reg_w_val(gspca_dev->dev, 0x8700, Clck);
  622. /* 0x8f 0x85 0x27 clock */
  623. reg_w_val(gspca_dev->dev, 0x8112, 0x1e | 0x20);
  624. reg_w_val(gspca_dev->dev, 0x850b, 0x03);
  625. setcontrast(gspca_dev);
  626. setwhite(gspca_dev);
  627. setautogain(gspca_dev);
  628. }
  629. static void sd_start_72a(struct gspca_dev *gspca_dev)
  630. {
  631. struct usb_device *dev = gspca_dev->dev;
  632. int Clck;
  633. int mode;
  634. mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
  635. switch (mode) {
  636. default:
  637. /* case 0:
  638. case 1: */
  639. Clck = 0x25;
  640. break;
  641. case 2:
  642. Clck = 0x22;
  643. break;
  644. case 3:
  645. Clck = 0x21;
  646. break;
  647. }
  648. reg_w_val(dev, 0x8500, mode); /* mode */
  649. reg_w_val(dev, 0x8700, Clck); /* 0x27 clock */
  650. reg_w_val(dev, 0x8112, 0x10 | 0x20);
  651. setautogain(gspca_dev);
  652. }
  653. static void sd_stopN(struct gspca_dev *gspca_dev)
  654. {
  655. struct sd *sd = (struct sd *) gspca_dev;
  656. if (sd->chip_revision == Rev012A) {
  657. reg_w_val(gspca_dev->dev, 0x8112, 0x0e);
  658. } else {
  659. reg_w_val(gspca_dev->dev, 0x8112, 0x20);
  660. /* reg_w_val(gspca_dev->dev, 0x8102, 0x00); ?? */
  661. }
  662. }
  663. static void sd_stop0(struct gspca_dev *gspca_dev)
  664. {
  665. struct sd *sd = (struct sd *) gspca_dev;
  666. if (sd->chip_revision == Rev012A) {
  667. reg_w_val(gspca_dev->dev, 0x8118, 0x29);
  668. reg_w_val(gspca_dev->dev, 0x8114, 0x08);
  669. }
  670. /* reg_w_val(gspca_dev->dev, 0x8114, 0); */
  671. }
  672. static void do_autogain(struct gspca_dev *gspca_dev)
  673. {
  674. struct sd *sd = (struct sd *) gspca_dev;
  675. int expotimes;
  676. int pixelclk;
  677. int gainG;
  678. __u8 R, Gr, Gb, B;
  679. int y;
  680. __u8 luma_mean = 110;
  681. __u8 luma_delta = 20;
  682. __u8 spring = 4;
  683. __u8 reg8339[2];
  684. if (sd->ag_cnt < 0)
  685. return;
  686. if (--sd->ag_cnt >= 0)
  687. return;
  688. sd->ag_cnt = AG_CNT_START;
  689. switch (sd->chip_revision) {
  690. case Rev072A:
  691. reg_r(gspca_dev, 0x8621, 1);
  692. Gr = gspca_dev->usb_buf[0];
  693. reg_r(gspca_dev, 0x8622, 1);
  694. R = gspca_dev->usb_buf[0];
  695. reg_r(gspca_dev, 0x8623, 1);
  696. B = gspca_dev->usb_buf[0];
  697. reg_r(gspca_dev, 0x8624, 1);
  698. Gb = gspca_dev->usb_buf[0];
  699. y = (77 * R + 75 * (Gr + Gb) + 29 * B) >> 8;
  700. /* u= (128*B-(43*(Gr+Gb+R))) >> 8; */
  701. /* v= (128*R-(53*(Gr+Gb))-21*B) >> 8; */
  702. /* PDEBUG(D_CONF,"reading Y %d U %d V %d ",y,u,v); */
  703. if (y < luma_mean - luma_delta ||
  704. y > luma_mean + luma_delta) {
  705. expotimes = i2c_read(gspca_dev, 0x09, 0x10);
  706. pixelclk = 0x0800;
  707. expotimes = expotimes & 0x07ff;
  708. /* PDEBUG(D_PACK,
  709. "Exposition Times 0x%03X Clock 0x%04X ",
  710. expotimes,pixelclk); */
  711. gainG = i2c_read(gspca_dev, 0x35, 0x10);
  712. /* PDEBUG(D_PACK,
  713. "reading Gain register %d", gainG); */
  714. expotimes += (luma_mean - y) >> spring;
  715. gainG += (luma_mean - y) / 50;
  716. /* PDEBUG(D_PACK,
  717. "compute expotimes %d gain %d",
  718. expotimes,gainG); */
  719. if (gainG > 0x3f)
  720. gainG = 0x3f;
  721. else if (gainG < 4)
  722. gainG = 3;
  723. i2c_write(gspca_dev, gainG, 0x35);
  724. if (expotimes >= 0x0256)
  725. expotimes = 0x0256;
  726. else if (expotimes < 4)
  727. expotimes = 3;
  728. i2c_write(gspca_dev, expotimes | pixelclk, 0x09);
  729. }
  730. break;
  731. case Rev012A:
  732. reg_r(gspca_dev, 0x8330, 2);
  733. if (gspca_dev->usb_buf[1] > 0x08) {
  734. reg8339[0] = ++sd->expo12a;
  735. reg8339[1] = 0;
  736. reg_w_buf(gspca_dev, 0x8339, reg8339, 2);
  737. } else if (gspca_dev->usb_buf[1] < 0x02) {
  738. reg8339[0] = --sd->expo12a;
  739. reg8339[1] = 0;
  740. reg_w_buf(gspca_dev, 0x8339, reg8339, 2);
  741. }
  742. break;
  743. }
  744. }
  745. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  746. struct gspca_frame *frame, /* target */
  747. __u8 *data, /* isoc packet */
  748. int len) /* iso packet length */
  749. {
  750. switch (data[0]) {
  751. case 0: /* start of frame */
  752. frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
  753. data, 0);
  754. data += SPCA561_OFFSET_DATA;
  755. len -= SPCA561_OFFSET_DATA;
  756. if (data[1] & 0x10) {
  757. /* compressed bayer */
  758. gspca_frame_add(gspca_dev, FIRST_PACKET,
  759. frame, data, len);
  760. } else {
  761. /* raw bayer (with a header, which we skip) */
  762. data += 20;
  763. len -= 20;
  764. gspca_frame_add(gspca_dev, FIRST_PACKET,
  765. frame, data, len);
  766. }
  767. return;
  768. case 0xff: /* drop */
  769. /* gspca_dev->last_packet_type = DISCARD_PACKET; */
  770. return;
  771. }
  772. data++;
  773. len--;
  774. gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
  775. }
  776. /* rev 72a only */
  777. static void setbrightness(struct gspca_dev *gspca_dev)
  778. {
  779. struct sd *sd = (struct sd *) gspca_dev;
  780. __u8 value;
  781. value = sd->brightness;
  782. reg_w_val(gspca_dev->dev, 0x8611, value);
  783. reg_w_val(gspca_dev->dev, 0x8612, value);
  784. reg_w_val(gspca_dev->dev, 0x8613, value);
  785. reg_w_val(gspca_dev->dev, 0x8614, value);
  786. }
  787. static void getbrightness(struct gspca_dev *gspca_dev)
  788. {
  789. struct sd *sd = (struct sd *) gspca_dev;
  790. __u16 tot;
  791. tot = 0;
  792. reg_r(gspca_dev, 0x8611, 1);
  793. tot += gspca_dev->usb_buf[0];
  794. reg_r(gspca_dev, 0x8612, 1);
  795. tot += gspca_dev->usb_buf[0];
  796. reg_r(gspca_dev, 0x8613, 1);
  797. tot += gspca_dev->usb_buf[0];
  798. reg_r(gspca_dev, 0x8614, 1);
  799. tot += gspca_dev->usb_buf[0];
  800. sd->brightness = tot >> 2;
  801. }
  802. /* rev72a only */
  803. static void getcontrast(struct gspca_dev *gspca_dev)
  804. {
  805. struct sd *sd = (struct sd *) gspca_dev;
  806. __u16 tot;
  807. tot = 0;
  808. reg_r(gspca_dev, 0x8651, 1);
  809. tot += gspca_dev->usb_buf[0];
  810. reg_r(gspca_dev, 0x8652, 1);
  811. tot += gspca_dev->usb_buf[0];
  812. reg_r(gspca_dev, 0x8653, 1);
  813. tot += gspca_dev->usb_buf[0];
  814. reg_r(gspca_dev, 0x8654, 1);
  815. tot += gspca_dev->usb_buf[0];
  816. sd->contrast = tot << 6;
  817. PDEBUG(D_CONF, "get contrast %d", sd->contrast);
  818. }
  819. /* rev 72a only */
  820. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  821. {
  822. struct sd *sd = (struct sd *) gspca_dev;
  823. sd->brightness = val;
  824. if (gspca_dev->streaming)
  825. setbrightness(gspca_dev);
  826. return 0;
  827. }
  828. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  829. {
  830. struct sd *sd = (struct sd *) gspca_dev;
  831. getbrightness(gspca_dev);
  832. *val = sd->brightness;
  833. return 0;
  834. }
  835. /* rev 72a only */
  836. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  837. {
  838. struct sd *sd = (struct sd *) gspca_dev;
  839. sd->contrast = val;
  840. if (gspca_dev->streaming)
  841. setcontrast(gspca_dev);
  842. return 0;
  843. }
  844. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  845. {
  846. struct sd *sd = (struct sd *) gspca_dev;
  847. getcontrast(gspca_dev);
  848. *val = sd->contrast;
  849. return 0;
  850. }
  851. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
  852. {
  853. struct sd *sd = (struct sd *) gspca_dev;
  854. sd->autogain = val;
  855. if (gspca_dev->streaming)
  856. setautogain(gspca_dev);
  857. return 0;
  858. }
  859. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
  860. {
  861. struct sd *sd = (struct sd *) gspca_dev;
  862. *val = sd->autogain;
  863. return 0;
  864. }
  865. /* rev12a only */
  866. static int sd_setwhite(struct gspca_dev *gspca_dev, __s32 val)
  867. {
  868. struct sd *sd = (struct sd *) gspca_dev;
  869. sd->white = val;
  870. if (gspca_dev->streaming)
  871. setwhite(gspca_dev);
  872. return 0;
  873. }
  874. static int sd_getwhite(struct gspca_dev *gspca_dev, __s32 *val)
  875. {
  876. struct sd *sd = (struct sd *) gspca_dev;
  877. *val = sd->white;
  878. return 0;
  879. }
  880. /* rev12a only */
  881. static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
  882. {
  883. struct sd *sd = (struct sd *) gspca_dev;
  884. sd->exposure = val;
  885. if (gspca_dev->streaming)
  886. setexposure(gspca_dev);
  887. return 0;
  888. }
  889. static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
  890. {
  891. struct sd *sd = (struct sd *) gspca_dev;
  892. *val = sd->exposure;
  893. return 0;
  894. }
  895. /* rev12a only */
  896. static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
  897. {
  898. struct sd *sd = (struct sd *) gspca_dev;
  899. sd->gain = val;
  900. if (gspca_dev->streaming)
  901. setgain(gspca_dev);
  902. return 0;
  903. }
  904. static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
  905. {
  906. struct sd *sd = (struct sd *) gspca_dev;
  907. *val = sd->gain;
  908. return 0;
  909. }
  910. /* control tables */
  911. static struct ctrl sd_ctrls_12a[] = {
  912. {
  913. {
  914. .id = V4L2_CID_DO_WHITE_BALANCE,
  915. .type = V4L2_CTRL_TYPE_INTEGER,
  916. .name = "While Balance",
  917. .minimum = WHITE_MIN,
  918. .maximum = WHITE_MAX,
  919. .step = 1,
  920. .default_value = WHITE_DEF,
  921. },
  922. .set = sd_setwhite,
  923. .get = sd_getwhite,
  924. },
  925. {
  926. {
  927. .id = V4L2_CID_EXPOSURE,
  928. .type = V4L2_CTRL_TYPE_INTEGER,
  929. .name = "Exposure",
  930. .minimum = EXPOSURE_MIN,
  931. .maximum = EXPOSURE_MAX,
  932. .step = 1,
  933. .default_value = EXPOSURE_DEF,
  934. },
  935. .set = sd_setexposure,
  936. .get = sd_getexposure,
  937. },
  938. {
  939. {
  940. .id = V4L2_CID_AUTOGAIN,
  941. .type = V4L2_CTRL_TYPE_BOOLEAN,
  942. .name = "Auto Gain",
  943. .minimum = AUTOGAIN_MIN,
  944. .maximum = AUTOGAIN_MAX,
  945. .step = 1,
  946. .default_value = AUTOGAIN_DEF,
  947. },
  948. .set = sd_setautogain,
  949. .get = sd_getautogain,
  950. },
  951. {
  952. {
  953. .id = V4L2_CID_GAIN,
  954. .type = V4L2_CTRL_TYPE_INTEGER,
  955. .name = "Gain",
  956. .minimum = GAIN_MIN,
  957. .maximum = GAIN_MAX,
  958. .step = 1,
  959. .default_value = GAIN_DEF,
  960. },
  961. .set = sd_setgain,
  962. .get = sd_getgain,
  963. },
  964. };
  965. static struct ctrl sd_ctrls_72a[] = {
  966. {
  967. {
  968. .id = V4L2_CID_BRIGHTNESS,
  969. .type = V4L2_CTRL_TYPE_INTEGER,
  970. .name = "Brightness",
  971. .minimum = BRIGHTNESS_MIN,
  972. .maximum = BRIGHTNESS_MAX,
  973. .step = 1,
  974. .default_value = BRIGHTNESS_DEF,
  975. },
  976. .set = sd_setbrightness,
  977. .get = sd_getbrightness,
  978. },
  979. {
  980. {
  981. .id = V4L2_CID_CONTRAST,
  982. .type = V4L2_CTRL_TYPE_INTEGER,
  983. .name = "Contrast",
  984. .minimum = CONTRAST_MIN,
  985. .maximum = CONTRAST_MAX,
  986. .step = 1,
  987. .default_value = CONTRAST_DEF,
  988. },
  989. .set = sd_setcontrast,
  990. .get = sd_getcontrast,
  991. },
  992. {
  993. {
  994. .id = V4L2_CID_AUTOGAIN,
  995. .type = V4L2_CTRL_TYPE_BOOLEAN,
  996. .name = "Auto Gain",
  997. .minimum = AUTOGAIN_MIN,
  998. .maximum = AUTOGAIN_MAX,
  999. .step = 1,
  1000. .default_value = AUTOGAIN_DEF,
  1001. },
  1002. .set = sd_setautogain,
  1003. .get = sd_getautogain,
  1004. },
  1005. };
  1006. /* sub-driver description */
  1007. static const struct sd_desc sd_desc_12a = {
  1008. .name = MODULE_NAME,
  1009. .ctrls = sd_ctrls_12a,
  1010. .nctrls = ARRAY_SIZE(sd_ctrls_12a),
  1011. .config = sd_config,
  1012. .init = sd_init_12a,
  1013. .start = sd_start_12a,
  1014. .stopN = sd_stopN,
  1015. .stop0 = sd_stop0,
  1016. .pkt_scan = sd_pkt_scan,
  1017. /* .dq_callback = do_autogain, * fixme */
  1018. };
  1019. static const struct sd_desc sd_desc_72a = {
  1020. .name = MODULE_NAME,
  1021. .ctrls = sd_ctrls_72a,
  1022. .nctrls = ARRAY_SIZE(sd_ctrls_72a),
  1023. .config = sd_config,
  1024. .init = sd_init_72a,
  1025. .start = sd_start_72a,
  1026. .stopN = sd_stopN,
  1027. .stop0 = sd_stop0,
  1028. .pkt_scan = sd_pkt_scan,
  1029. .dq_callback = do_autogain,
  1030. };
  1031. static const struct sd_desc *sd_desc[2] = {
  1032. &sd_desc_12a,
  1033. &sd_desc_72a
  1034. };
  1035. /* -- module initialisation -- */
  1036. static const __devinitdata struct usb_device_id device_table[] = {
  1037. {USB_DEVICE(0x041e, 0x401a), .driver_info = Rev072A},
  1038. {USB_DEVICE(0x041e, 0x403b), .driver_info = Rev012A},
  1039. {USB_DEVICE(0x0458, 0x7004), .driver_info = Rev072A},
  1040. {USB_DEVICE(0x046d, 0x0928), .driver_info = Rev012A},
  1041. {USB_DEVICE(0x046d, 0x0929), .driver_info = Rev012A},
  1042. {USB_DEVICE(0x046d, 0x092a), .driver_info = Rev012A},
  1043. {USB_DEVICE(0x046d, 0x092b), .driver_info = Rev012A},
  1044. {USB_DEVICE(0x046d, 0x092c), .driver_info = Rev012A},
  1045. {USB_DEVICE(0x046d, 0x092d), .driver_info = Rev012A},
  1046. {USB_DEVICE(0x046d, 0x092e), .driver_info = Rev012A},
  1047. {USB_DEVICE(0x046d, 0x092f), .driver_info = Rev012A},
  1048. {USB_DEVICE(0x04fc, 0x0561), .driver_info = Rev072A},
  1049. {USB_DEVICE(0x060b, 0xa001), .driver_info = Rev072A},
  1050. {USB_DEVICE(0x10fd, 0x7e50), .driver_info = Rev072A},
  1051. {USB_DEVICE(0xabcd, 0xcdee), .driver_info = Rev072A},
  1052. {}
  1053. };
  1054. MODULE_DEVICE_TABLE(usb, device_table);
  1055. /* -- device connect -- */
  1056. static int sd_probe(struct usb_interface *intf,
  1057. const struct usb_device_id *id)
  1058. {
  1059. return gspca_dev_probe(intf, id,
  1060. sd_desc[id->driver_info],
  1061. sizeof(struct sd),
  1062. THIS_MODULE);
  1063. }
  1064. static struct usb_driver sd_driver = {
  1065. .name = MODULE_NAME,
  1066. .id_table = device_table,
  1067. .probe = sd_probe,
  1068. .disconnect = gspca_disconnect,
  1069. #ifdef CONFIG_PM
  1070. .suspend = gspca_suspend,
  1071. .resume = gspca_resume,
  1072. #endif
  1073. };
  1074. /* -- module insert / remove -- */
  1075. static int __init sd_mod_init(void)
  1076. {
  1077. if (usb_register(&sd_driver) < 0)
  1078. return -1;
  1079. PDEBUG(D_PROBE, "registered");
  1080. return 0;
  1081. }
  1082. static void __exit sd_mod_exit(void)
  1083. {
  1084. usb_deregister(&sd_driver);
  1085. PDEBUG(D_PROBE, "deregistered");
  1086. }
  1087. module_init(sd_mod_init);
  1088. module_exit(sd_mod_exit);