spca561.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212
  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. cam->epaddr = 0x01;
  498. gspca_dev->nbalt = 7 + 1; /* choose alternate 7 first */
  499. sd->chip_revision = id->driver_info;
  500. if (sd->chip_revision == Rev012A) {
  501. cam->cam_mode = sif_012a_mode;
  502. cam->nmodes = ARRAY_SIZE(sif_012a_mode);
  503. } else {
  504. cam->cam_mode = sif_072a_mode;
  505. cam->nmodes = ARRAY_SIZE(sif_072a_mode);
  506. }
  507. sd->brightness = BRIGHTNESS_DEF;
  508. sd->contrast = CONTRAST_DEF;
  509. sd->white = WHITE_DEF;
  510. sd->exposure = EXPOSURE_DEF;
  511. sd->autogain = AUTOGAIN_DEF;
  512. sd->gain = GAIN_DEF;
  513. sd->expo12a = EXPO12A_DEF;
  514. return 0;
  515. }
  516. /* this function is called at probe and resume time */
  517. static int sd_init_12a(struct gspca_dev *gspca_dev)
  518. {
  519. PDEBUG(D_STREAM, "Chip revision: 012a");
  520. init_161rev12A(gspca_dev);
  521. return 0;
  522. }
  523. static int sd_init_72a(struct gspca_dev *gspca_dev)
  524. {
  525. PDEBUG(D_STREAM, "Chip revision: 072a");
  526. write_vector(gspca_dev, rev72a_init_data1);
  527. write_sensor_72a(gspca_dev, rev72a_init_sensor1);
  528. write_vector(gspca_dev, rev72a_init_data2);
  529. write_sensor_72a(gspca_dev, rev72a_init_sensor2);
  530. write_vector(gspca_dev, rev72a_init_data3);
  531. return 0;
  532. }
  533. /* rev 72a only */
  534. static void setbrightness(struct gspca_dev *gspca_dev)
  535. {
  536. struct sd *sd = (struct sd *) gspca_dev;
  537. struct usb_device *dev = gspca_dev->dev;
  538. __u8 value;
  539. value = sd->brightness;
  540. /* offsets for white balance */
  541. reg_w_val(dev, 0x8611, value); /* R */
  542. reg_w_val(dev, 0x8612, value); /* Gr */
  543. reg_w_val(dev, 0x8613, value); /* B */
  544. reg_w_val(dev, 0x8614, value); /* Gb */
  545. }
  546. static void setwhite(struct gspca_dev *gspca_dev)
  547. {
  548. struct sd *sd = (struct sd *) gspca_dev;
  549. __u16 white;
  550. __u8 blue, red;
  551. __u16 reg;
  552. /* try to emulate MS-win as possible */
  553. white = sd->white;
  554. red = 0x20 + white * 3 / 8;
  555. blue = 0x90 - white * 5 / 8;
  556. if (sd->chip_revision == Rev012A) {
  557. reg = 0x8614;
  558. } else {
  559. reg = 0x8651;
  560. red += sd->contrast - 0x20;
  561. blue += sd->contrast - 0x20;
  562. }
  563. reg_w_val(gspca_dev->dev, reg, red);
  564. reg_w_val(gspca_dev->dev, reg + 2, blue);
  565. }
  566. static void setcontrast(struct gspca_dev *gspca_dev)
  567. {
  568. struct sd *sd = (struct sd *) gspca_dev;
  569. struct usb_device *dev = gspca_dev->dev;
  570. __u8 value;
  571. if (sd->chip_revision != Rev072A)
  572. return;
  573. value = sd->contrast + 0x20;
  574. /* gains for white balance */
  575. setwhite(gspca_dev);
  576. /* reg_w_val(dev, 0x8651, value); * R - done by setwhite */
  577. reg_w_val(dev, 0x8652, value); /* Gr */
  578. /* reg_w_val(dev, 0x8653, value); * B - done by setwhite */
  579. reg_w_val(dev, 0x8654, value); /* Gb */
  580. }
  581. /* rev 12a only */
  582. static void setexposure(struct gspca_dev *gspca_dev)
  583. {
  584. struct sd *sd = (struct sd *) gspca_dev;
  585. int expo;
  586. int clock_divider;
  587. /* Register 0x8309 controls exposure for the spca561,
  588. the basic exposure setting goes from 1-2047, where 1 is completely
  589. dark and 2047 is very bright. It not only influences exposure but
  590. also the framerate (to allow for longer exposure) from 1 - 300 it
  591. only raises the exposure time then from 300 - 600 it halves the
  592. framerate to be able to further raise the exposure time and for every
  593. 300 more it halves the framerate again. This allows for a maximum
  594. exposure time of circa 0.2 - 0.25 seconds (30 / (2000/3000) fps).
  595. Sometimes this is not enough, the 1-2047 uses bits 0-10, bits 11-12
  596. configure a divider for the base framerate which us used at the
  597. exposure setting of 1-300. These bits configure the base framerate
  598. according to the following formula: fps = 60 / (value + 2) */
  599. if (sd->exposure < 2048) {
  600. expo = sd->exposure;
  601. clock_divider = 0;
  602. } else {
  603. /* Add 900 to make the 0 setting of the second part of the
  604. exposure equal to the 2047 setting of the first part. */
  605. expo = (sd->exposure - 2048) + 900;
  606. clock_divider = 3;
  607. }
  608. expo |= clock_divider << 11;
  609. gspca_dev->usb_buf[0] = expo;
  610. gspca_dev->usb_buf[1] = expo >> 8;
  611. reg_w_buf(gspca_dev, 0x8309, 2);
  612. }
  613. /* rev 12a only */
  614. static void setgain(struct gspca_dev *gspca_dev)
  615. {
  616. struct sd *sd = (struct sd *) gspca_dev;
  617. gspca_dev->usb_buf[0] = sd->gain;
  618. gspca_dev->usb_buf[1] = 0;
  619. reg_w_buf(gspca_dev, 0x8335, 2);
  620. }
  621. static void setautogain(struct gspca_dev *gspca_dev)
  622. {
  623. struct sd *sd = (struct sd *) gspca_dev;
  624. if (sd->autogain)
  625. sd->ag_cnt = AG_CNT_START;
  626. else
  627. sd->ag_cnt = -1;
  628. }
  629. static int sd_start_12a(struct gspca_dev *gspca_dev)
  630. {
  631. struct usb_device *dev = gspca_dev->dev;
  632. int mode;
  633. static const __u8 Reg8391[8] =
  634. {0x92, 0x30, 0x20, 0x00, 0x0c, 0x00, 0x00, 0x00};
  635. mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
  636. if (mode <= 1) {
  637. /* Use compression on 320x240 and above */
  638. reg_w_val(dev, 0x8500, 0x10 | mode);
  639. } else {
  640. /* I couldn't get the compression to work below 320x240
  641. * Fortunately at these resolutions the bandwidth
  642. * is sufficient to push raw frames at ~20fps */
  643. reg_w_val(dev, 0x8500, mode);
  644. } /* -- qq@kuku.eu.org */
  645. gspca_dev->usb_buf[0] = 0xaa;
  646. gspca_dev->usb_buf[1] = 0x00;
  647. reg_w_buf(gspca_dev, 0x8307, 2);
  648. /* clock - lower 0x8X values lead to fps > 30 */
  649. reg_w_val(gspca_dev->dev, 0x8700, 0x8a);
  650. /* 0x8f 0x85 0x27 clock */
  651. reg_w_val(gspca_dev->dev, 0x8112, 0x1e | 0x20);
  652. reg_w_val(gspca_dev->dev, 0x850b, 0x03);
  653. memcpy(gspca_dev->usb_buf, Reg8391, 8);
  654. reg_w_buf(gspca_dev, 0x8391, 8);
  655. reg_w_buf(gspca_dev, 0x8390, 8);
  656. setwhite(gspca_dev);
  657. setautogain(gspca_dev);
  658. /* setgain(gspca_dev); */
  659. setexposure(gspca_dev);
  660. return 0;
  661. }
  662. static int sd_start_72a(struct gspca_dev *gspca_dev)
  663. {
  664. struct usb_device *dev = gspca_dev->dev;
  665. int Clck;
  666. int mode;
  667. mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
  668. switch (mode) {
  669. default:
  670. /* case 0:
  671. case 1: */
  672. Clck = 0x25;
  673. break;
  674. case 2:
  675. Clck = 0x22;
  676. break;
  677. case 3:
  678. Clck = 0x21;
  679. break;
  680. }
  681. reg_w_val(dev, 0x8500, mode); /* mode */
  682. reg_w_val(dev, 0x8700, Clck); /* 0x27 clock */
  683. reg_w_val(dev, 0x8112, 0x10 | 0x20);
  684. setcontrast(gspca_dev);
  685. /* setbrightness(gspca_dev); * fixme: bad values */
  686. setwhite(gspca_dev);
  687. setautogain(gspca_dev);
  688. return 0;
  689. }
  690. static void sd_stopN(struct gspca_dev *gspca_dev)
  691. {
  692. struct sd *sd = (struct sd *) gspca_dev;
  693. if (sd->chip_revision == Rev012A) {
  694. reg_w_val(gspca_dev->dev, 0x8112, 0x0e);
  695. } else {
  696. reg_w_val(gspca_dev->dev, 0x8112, 0x20);
  697. /* reg_w_val(gspca_dev->dev, 0x8102, 0x00); ?? */
  698. }
  699. }
  700. /* called on streamoff with alt 0 and on disconnect */
  701. static void sd_stop0(struct gspca_dev *gspca_dev)
  702. {
  703. struct sd *sd = (struct sd *) gspca_dev;
  704. if (!gspca_dev->present)
  705. return;
  706. if (sd->chip_revision == Rev012A) {
  707. reg_w_val(gspca_dev->dev, 0x8118, 0x29);
  708. reg_w_val(gspca_dev->dev, 0x8114, 0x08);
  709. }
  710. /* reg_w_val(gspca_dev->dev, 0x8114, 0); */
  711. }
  712. static void do_autogain(struct gspca_dev *gspca_dev)
  713. {
  714. struct sd *sd = (struct sd *) gspca_dev;
  715. int expotimes;
  716. int pixelclk;
  717. int gainG;
  718. __u8 R, Gr, Gb, B;
  719. int y;
  720. __u8 luma_mean = 110;
  721. __u8 luma_delta = 20;
  722. __u8 spring = 4;
  723. if (sd->ag_cnt < 0)
  724. return;
  725. if (--sd->ag_cnt >= 0)
  726. return;
  727. sd->ag_cnt = AG_CNT_START;
  728. switch (sd->chip_revision) {
  729. case Rev072A:
  730. reg_r(gspca_dev, 0x8621, 1);
  731. Gr = gspca_dev->usb_buf[0];
  732. reg_r(gspca_dev, 0x8622, 1);
  733. R = gspca_dev->usb_buf[0];
  734. reg_r(gspca_dev, 0x8623, 1);
  735. B = gspca_dev->usb_buf[0];
  736. reg_r(gspca_dev, 0x8624, 1);
  737. Gb = gspca_dev->usb_buf[0];
  738. y = (77 * R + 75 * (Gr + Gb) + 29 * B) >> 8;
  739. /* u= (128*B-(43*(Gr+Gb+R))) >> 8; */
  740. /* v= (128*R-(53*(Gr+Gb))-21*B) >> 8; */
  741. /* PDEBUG(D_CONF,"reading Y %d U %d V %d ",y,u,v); */
  742. if (y < luma_mean - luma_delta ||
  743. y > luma_mean + luma_delta) {
  744. expotimes = i2c_read(gspca_dev, 0x09, 0x10);
  745. pixelclk = 0x0800;
  746. expotimes = expotimes & 0x07ff;
  747. /* PDEBUG(D_PACK,
  748. "Exposition Times 0x%03X Clock 0x%04X ",
  749. expotimes,pixelclk); */
  750. gainG = i2c_read(gspca_dev, 0x35, 0x10);
  751. /* PDEBUG(D_PACK,
  752. "reading Gain register %d", gainG); */
  753. expotimes += (luma_mean - y) >> spring;
  754. gainG += (luma_mean - y) / 50;
  755. /* PDEBUG(D_PACK,
  756. "compute expotimes %d gain %d",
  757. expotimes,gainG); */
  758. if (gainG > 0x3f)
  759. gainG = 0x3f;
  760. else if (gainG < 3)
  761. gainG = 3;
  762. i2c_write(gspca_dev, gainG, 0x35);
  763. if (expotimes > 0x0256)
  764. expotimes = 0x0256;
  765. else if (expotimes < 3)
  766. expotimes = 3;
  767. i2c_write(gspca_dev, expotimes | pixelclk, 0x09);
  768. }
  769. break;
  770. case Rev012A:
  771. reg_r(gspca_dev, 0x8330, 2);
  772. if (gspca_dev->usb_buf[1] > 0x08) {
  773. gspca_dev->usb_buf[0] = ++sd->expo12a;
  774. gspca_dev->usb_buf[1] = 0;
  775. reg_w_buf(gspca_dev, 0x8339, 2);
  776. } else if (gspca_dev->usb_buf[1] < 0x02) {
  777. gspca_dev->usb_buf[0] = --sd->expo12a;
  778. gspca_dev->usb_buf[1] = 0;
  779. reg_w_buf(gspca_dev, 0x8339, 2);
  780. }
  781. break;
  782. }
  783. }
  784. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  785. struct gspca_frame *frame, /* target */
  786. __u8 *data, /* isoc packet */
  787. int len) /* iso packet length */
  788. {
  789. struct sd *sd = (struct sd *) gspca_dev;
  790. switch (data[0]) { /* sequence number */
  791. case 0: /* start of frame */
  792. frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
  793. data, 0);
  794. data += SPCA561_OFFSET_DATA;
  795. len -= SPCA561_OFFSET_DATA;
  796. if (data[1] & 0x10) {
  797. /* compressed bayer */
  798. gspca_frame_add(gspca_dev, FIRST_PACKET,
  799. frame, data, len);
  800. } else {
  801. /* raw bayer (with a header, which we skip) */
  802. if (sd->chip_revision == Rev012A) {
  803. data += 20;
  804. len -= 20;
  805. } else {
  806. data += 16;
  807. len -= 16;
  808. }
  809. gspca_frame_add(gspca_dev, FIRST_PACKET,
  810. frame, data, len);
  811. }
  812. return;
  813. case 0xff: /* drop (empty mpackets) */
  814. return;
  815. }
  816. data++;
  817. len--;
  818. gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
  819. }
  820. /* rev 72a only */
  821. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  822. {
  823. struct sd *sd = (struct sd *) gspca_dev;
  824. sd->brightness = val;
  825. if (gspca_dev->streaming)
  826. setbrightness(gspca_dev);
  827. return 0;
  828. }
  829. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  830. {
  831. struct sd *sd = (struct sd *) 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. *val = sd->contrast;
  848. return 0;
  849. }
  850. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
  851. {
  852. struct sd *sd = (struct sd *) gspca_dev;
  853. sd->autogain = val;
  854. if (gspca_dev->streaming)
  855. setautogain(gspca_dev);
  856. return 0;
  857. }
  858. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
  859. {
  860. struct sd *sd = (struct sd *) gspca_dev;
  861. *val = sd->autogain;
  862. return 0;
  863. }
  864. static int sd_setwhite(struct gspca_dev *gspca_dev, __s32 val)
  865. {
  866. struct sd *sd = (struct sd *) gspca_dev;
  867. sd->white = val;
  868. if (gspca_dev->streaming)
  869. setwhite(gspca_dev);
  870. return 0;
  871. }
  872. static int sd_getwhite(struct gspca_dev *gspca_dev, __s32 *val)
  873. {
  874. struct sd *sd = (struct sd *) gspca_dev;
  875. *val = sd->white;
  876. return 0;
  877. }
  878. /* rev12a only */
  879. static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
  880. {
  881. struct sd *sd = (struct sd *) gspca_dev;
  882. sd->exposure = val;
  883. if (gspca_dev->streaming)
  884. setexposure(gspca_dev);
  885. return 0;
  886. }
  887. static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
  888. {
  889. struct sd *sd = (struct sd *) gspca_dev;
  890. *val = sd->exposure;
  891. return 0;
  892. }
  893. /* rev12a only */
  894. static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
  895. {
  896. struct sd *sd = (struct sd *) gspca_dev;
  897. sd->gain = val;
  898. if (gspca_dev->streaming)
  899. setgain(gspca_dev);
  900. return 0;
  901. }
  902. static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
  903. {
  904. struct sd *sd = (struct sd *) gspca_dev;
  905. *val = sd->gain;
  906. return 0;
  907. }
  908. /* control tables */
  909. static struct ctrl sd_ctrls_12a[] = {
  910. {
  911. {
  912. .id = V4L2_CID_DO_WHITE_BALANCE,
  913. .type = V4L2_CTRL_TYPE_INTEGER,
  914. .name = "White Balance",
  915. .minimum = WHITE_MIN,
  916. .maximum = WHITE_MAX,
  917. .step = 1,
  918. .default_value = WHITE_DEF,
  919. },
  920. .set = sd_setwhite,
  921. .get = sd_getwhite,
  922. },
  923. {
  924. {
  925. .id = V4L2_CID_EXPOSURE,
  926. .type = V4L2_CTRL_TYPE_INTEGER,
  927. .name = "Exposure",
  928. .minimum = EXPOSURE_MIN,
  929. .maximum = EXPOSURE_MAX,
  930. .step = 1,
  931. .default_value = EXPOSURE_DEF,
  932. },
  933. .set = sd_setexposure,
  934. .get = sd_getexposure,
  935. },
  936. {
  937. {
  938. .id = V4L2_CID_AUTOGAIN,
  939. .type = V4L2_CTRL_TYPE_BOOLEAN,
  940. .name = "Auto Gain",
  941. .minimum = AUTOGAIN_MIN,
  942. .maximum = AUTOGAIN_MAX,
  943. .step = 1,
  944. .default_value = AUTOGAIN_DEF,
  945. },
  946. .set = sd_setautogain,
  947. .get = sd_getautogain,
  948. },
  949. {
  950. {
  951. .id = V4L2_CID_GAIN,
  952. .type = V4L2_CTRL_TYPE_INTEGER,
  953. .name = "Gain",
  954. .minimum = GAIN_MIN,
  955. .maximum = GAIN_MAX,
  956. .step = 1,
  957. .default_value = GAIN_DEF,
  958. },
  959. .set = sd_setgain,
  960. .get = sd_getgain,
  961. },
  962. };
  963. static struct ctrl sd_ctrls_72a[] = {
  964. {
  965. {
  966. .id = V4L2_CID_DO_WHITE_BALANCE,
  967. .type = V4L2_CTRL_TYPE_INTEGER,
  968. .name = "White Balance",
  969. .minimum = WHITE_MIN,
  970. .maximum = WHITE_MAX,
  971. .step = 1,
  972. .default_value = WHITE_DEF,
  973. },
  974. .set = sd_setwhite,
  975. .get = sd_getwhite,
  976. },
  977. {
  978. {
  979. .id = V4L2_CID_BRIGHTNESS,
  980. .type = V4L2_CTRL_TYPE_INTEGER,
  981. .name = "Brightness",
  982. .minimum = BRIGHTNESS_MIN,
  983. .maximum = BRIGHTNESS_MAX,
  984. .step = 1,
  985. .default_value = BRIGHTNESS_DEF,
  986. },
  987. .set = sd_setbrightness,
  988. .get = sd_getbrightness,
  989. },
  990. {
  991. {
  992. .id = V4L2_CID_CONTRAST,
  993. .type = V4L2_CTRL_TYPE_INTEGER,
  994. .name = "Contrast",
  995. .minimum = CONTRAST_MIN,
  996. .maximum = CONTRAST_MAX,
  997. .step = 1,
  998. .default_value = CONTRAST_DEF,
  999. },
  1000. .set = sd_setcontrast,
  1001. .get = sd_getcontrast,
  1002. },
  1003. {
  1004. {
  1005. .id = V4L2_CID_AUTOGAIN,
  1006. .type = V4L2_CTRL_TYPE_BOOLEAN,
  1007. .name = "Auto Gain",
  1008. .minimum = AUTOGAIN_MIN,
  1009. .maximum = AUTOGAIN_MAX,
  1010. .step = 1,
  1011. .default_value = AUTOGAIN_DEF,
  1012. },
  1013. .set = sd_setautogain,
  1014. .get = sd_getautogain,
  1015. },
  1016. };
  1017. /* sub-driver description */
  1018. static const struct sd_desc sd_desc_12a = {
  1019. .name = MODULE_NAME,
  1020. .ctrls = sd_ctrls_12a,
  1021. .nctrls = ARRAY_SIZE(sd_ctrls_12a),
  1022. .config = sd_config,
  1023. .init = sd_init_12a,
  1024. .start = sd_start_12a,
  1025. .stopN = sd_stopN,
  1026. .stop0 = sd_stop0,
  1027. .pkt_scan = sd_pkt_scan,
  1028. /* .dq_callback = do_autogain, * fixme */
  1029. };
  1030. static const struct sd_desc sd_desc_72a = {
  1031. .name = MODULE_NAME,
  1032. .ctrls = sd_ctrls_72a,
  1033. .nctrls = ARRAY_SIZE(sd_ctrls_72a),
  1034. .config = sd_config,
  1035. .init = sd_init_72a,
  1036. .start = sd_start_72a,
  1037. .stopN = sd_stopN,
  1038. .stop0 = sd_stop0,
  1039. .pkt_scan = sd_pkt_scan,
  1040. .dq_callback = do_autogain,
  1041. };
  1042. static const struct sd_desc *sd_desc[2] = {
  1043. &sd_desc_12a,
  1044. &sd_desc_72a
  1045. };
  1046. /* -- module initialisation -- */
  1047. static const __devinitdata struct usb_device_id device_table[] = {
  1048. {USB_DEVICE(0x041e, 0x401a), .driver_info = Rev072A},
  1049. {USB_DEVICE(0x041e, 0x403b), .driver_info = Rev012A},
  1050. {USB_DEVICE(0x0458, 0x7004), .driver_info = Rev072A},
  1051. {USB_DEVICE(0x046d, 0x0928), .driver_info = Rev012A},
  1052. {USB_DEVICE(0x046d, 0x0929), .driver_info = Rev012A},
  1053. {USB_DEVICE(0x046d, 0x092a), .driver_info = Rev012A},
  1054. {USB_DEVICE(0x046d, 0x092b), .driver_info = Rev012A},
  1055. {USB_DEVICE(0x046d, 0x092c), .driver_info = Rev012A},
  1056. {USB_DEVICE(0x046d, 0x092d), .driver_info = Rev012A},
  1057. {USB_DEVICE(0x046d, 0x092e), .driver_info = Rev012A},
  1058. {USB_DEVICE(0x046d, 0x092f), .driver_info = Rev012A},
  1059. {USB_DEVICE(0x04fc, 0x0561), .driver_info = Rev072A},
  1060. {USB_DEVICE(0x060b, 0xa001), .driver_info = Rev072A},
  1061. {USB_DEVICE(0x10fd, 0x7e50), .driver_info = Rev072A},
  1062. {USB_DEVICE(0xabcd, 0xcdee), .driver_info = Rev072A},
  1063. {}
  1064. };
  1065. MODULE_DEVICE_TABLE(usb, device_table);
  1066. /* -- device connect -- */
  1067. static int sd_probe(struct usb_interface *intf,
  1068. const struct usb_device_id *id)
  1069. {
  1070. return gspca_dev_probe(intf, id,
  1071. sd_desc[id->driver_info],
  1072. sizeof(struct sd),
  1073. THIS_MODULE);
  1074. }
  1075. static struct usb_driver sd_driver = {
  1076. .name = MODULE_NAME,
  1077. .id_table = device_table,
  1078. .probe = sd_probe,
  1079. .disconnect = gspca_disconnect,
  1080. #ifdef CONFIG_PM
  1081. .suspend = gspca_suspend,
  1082. .resume = gspca_resume,
  1083. #endif
  1084. };
  1085. /* -- module insert / remove -- */
  1086. static int __init sd_mod_init(void)
  1087. {
  1088. if (usb_register(&sd_driver) < 0)
  1089. return -1;
  1090. PDEBUG(D_PROBE, "registered");
  1091. return 0;
  1092. }
  1093. static void __exit sd_mod_exit(void)
  1094. {
  1095. usb_deregister(&sd_driver);
  1096. PDEBUG(D_PROBE, "deregistered");
  1097. }
  1098. module_init(sd_mod_init);
  1099. module_exit(sd_mod_exit);