spca561.c 31 KB

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