spca561.c 31 KB

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