spca561.c 30 KB

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