spca561.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249
  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 1
  36. #define EXPOSURE_DEF 200
  37. #define EXPOSURE_MAX (4095 - 900) /* see set_exposure */
  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_DIR_OUT | 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. do {
  201. reg_r(gspca_dev, 0x8803, 1);
  202. if (!gspca_dev->usb_buf[0])
  203. break;
  204. } while (--retry);
  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. int clock_divider;
  597. __u8 data[2];
  598. /* Register 0x8309 controls exposure for the spca561,
  599. the basic exposure setting goes from 1-2047, where 1 is completely
  600. dark and 2047 is very bright. It not only influences exposure but
  601. also the framerate (to allow for longer exposure) from 1 - 300 it
  602. only raises the exposure time then from 300 - 600 it halves the
  603. framerate to be able to further raise the exposure time and for every
  604. 300 more it halves the framerate again. This allows for a maximum
  605. exposure time of circa 0.2 - 0.25 seconds (30 / (2000/3000) fps).
  606. Sometimes this is not enough, the 1-2047 uses bits 0-10, bits 11-12
  607. configure a divider for the base framerate which us used at the
  608. exposure setting of 1-300. These bits configure the base framerate
  609. according to the following formula: fps = 60 / (value + 2) */
  610. if (sd->exposure < 2048) {
  611. expo = sd->exposure;
  612. clock_divider = 0;
  613. } else {
  614. /* Add 900 to make the 0 setting of the second part of the
  615. exposure equal to the 2047 setting of the first part. */
  616. expo = (sd->exposure - 2048) + 900;
  617. clock_divider = 3;
  618. }
  619. expo |= clock_divider << 11;
  620. data[0] = expo;
  621. data[1] = expo >> 8;
  622. reg_w_buf(gspca_dev, 0x8309, data, 2);
  623. }
  624. /* rev 12a only */
  625. static void setgain(struct gspca_dev *gspca_dev)
  626. {
  627. struct sd *sd = (struct sd *) gspca_dev;
  628. __u8 data[2];
  629. data[0] = sd->gain;
  630. data[1] = 0;
  631. reg_w_buf(gspca_dev, 0x8335, data, 2);
  632. }
  633. static void setautogain(struct gspca_dev *gspca_dev)
  634. {
  635. struct sd *sd = (struct sd *) gspca_dev;
  636. if (sd->autogain)
  637. sd->ag_cnt = AG_CNT_START;
  638. else
  639. sd->ag_cnt = -1;
  640. }
  641. static int sd_start_12a(struct gspca_dev *gspca_dev)
  642. {
  643. struct usb_device *dev = gspca_dev->dev;
  644. int Clck = 0x8a; /* lower 0x8X values lead to fps > 30 */
  645. __u8 Reg8307[] = { 0xaa, 0x00 };
  646. int mode;
  647. mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
  648. if (mode <= 1) {
  649. /* Use compression on 320x240 and above */
  650. reg_w_val(dev, 0x8500, 0x10 | mode);
  651. } else {
  652. /* I couldn't get the compression to work below 320x240
  653. * Fortunately at these resolutions the bandwidth
  654. * is sufficient to push raw frames at ~20fps */
  655. reg_w_val(dev, 0x8500, mode);
  656. } /* -- qq@kuku.eu.org */
  657. reg_w_buf(gspca_dev, 0x8307, Reg8307, 2);
  658. reg_w_val(gspca_dev->dev, 0x8700, Clck);
  659. /* 0x8f 0x85 0x27 clock */
  660. reg_w_val(gspca_dev->dev, 0x8112, 0x1e | 0x20);
  661. reg_w_val(gspca_dev->dev, 0x850b, 0x03);
  662. setcontrast(gspca_dev);
  663. setwhite(gspca_dev);
  664. setautogain(gspca_dev);
  665. setexposure(gspca_dev);
  666. return 0;
  667. }
  668. static int sd_start_72a(struct gspca_dev *gspca_dev)
  669. {
  670. struct usb_device *dev = gspca_dev->dev;
  671. int Clck;
  672. int mode;
  673. mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
  674. switch (mode) {
  675. default:
  676. /* case 0:
  677. case 1: */
  678. Clck = 0x25;
  679. break;
  680. case 2:
  681. Clck = 0x22;
  682. break;
  683. case 3:
  684. Clck = 0x21;
  685. break;
  686. }
  687. reg_w_val(dev, 0x8500, mode); /* mode */
  688. reg_w_val(dev, 0x8700, Clck); /* 0x27 clock */
  689. reg_w_val(dev, 0x8112, 0x10 | 0x20);
  690. setautogain(gspca_dev);
  691. return 0;
  692. }
  693. static void sd_stopN(struct gspca_dev *gspca_dev)
  694. {
  695. struct sd *sd = (struct sd *) gspca_dev;
  696. if (sd->chip_revision == Rev012A) {
  697. reg_w_val(gspca_dev->dev, 0x8112, 0x0e);
  698. } else {
  699. reg_w_val(gspca_dev->dev, 0x8112, 0x20);
  700. /* reg_w_val(gspca_dev->dev, 0x8102, 0x00); ?? */
  701. }
  702. }
  703. static void sd_stop0(struct gspca_dev *gspca_dev)
  704. {
  705. struct sd *sd = (struct sd *) gspca_dev;
  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. __u8 reg8339[2];
  724. if (sd->ag_cnt < 0)
  725. return;
  726. if (--sd->ag_cnt >= 0)
  727. return;
  728. sd->ag_cnt = AG_CNT_START;
  729. switch (sd->chip_revision) {
  730. case Rev072A:
  731. reg_r(gspca_dev, 0x8621, 1);
  732. Gr = gspca_dev->usb_buf[0];
  733. reg_r(gspca_dev, 0x8622, 1);
  734. R = gspca_dev->usb_buf[0];
  735. reg_r(gspca_dev, 0x8623, 1);
  736. B = gspca_dev->usb_buf[0];
  737. reg_r(gspca_dev, 0x8624, 1);
  738. Gb = gspca_dev->usb_buf[0];
  739. y = (77 * R + 75 * (Gr + Gb) + 29 * B) >> 8;
  740. /* u= (128*B-(43*(Gr+Gb+R))) >> 8; */
  741. /* v= (128*R-(53*(Gr+Gb))-21*B) >> 8; */
  742. /* PDEBUG(D_CONF,"reading Y %d U %d V %d ",y,u,v); */
  743. if (y < luma_mean - luma_delta ||
  744. y > luma_mean + luma_delta) {
  745. expotimes = i2c_read(gspca_dev, 0x09, 0x10);
  746. pixelclk = 0x0800;
  747. expotimes = expotimes & 0x07ff;
  748. /* PDEBUG(D_PACK,
  749. "Exposition Times 0x%03X Clock 0x%04X ",
  750. expotimes,pixelclk); */
  751. gainG = i2c_read(gspca_dev, 0x35, 0x10);
  752. /* PDEBUG(D_PACK,
  753. "reading Gain register %d", gainG); */
  754. expotimes += (luma_mean - y) >> spring;
  755. gainG += (luma_mean - y) / 50;
  756. /* PDEBUG(D_PACK,
  757. "compute expotimes %d gain %d",
  758. expotimes,gainG); */
  759. if (gainG > 0x3f)
  760. gainG = 0x3f;
  761. else if (gainG < 4)
  762. gainG = 3;
  763. i2c_write(gspca_dev, gainG, 0x35);
  764. if (expotimes >= 0x0256)
  765. expotimes = 0x0256;
  766. else if (expotimes < 4)
  767. expotimes = 3;
  768. i2c_write(gspca_dev, expotimes | pixelclk, 0x09);
  769. }
  770. break;
  771. case Rev012A:
  772. reg_r(gspca_dev, 0x8330, 2);
  773. if (gspca_dev->usb_buf[1] > 0x08) {
  774. reg8339[0] = ++sd->expo12a;
  775. reg8339[1] = 0;
  776. reg_w_buf(gspca_dev, 0x8339, reg8339, 2);
  777. } else if (gspca_dev->usb_buf[1] < 0x02) {
  778. reg8339[0] = --sd->expo12a;
  779. reg8339[1] = 0;
  780. reg_w_buf(gspca_dev, 0x8339, reg8339, 2);
  781. }
  782. break;
  783. }
  784. }
  785. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  786. struct gspca_frame *frame, /* target */
  787. __u8 *data, /* isoc packet */
  788. int len) /* iso packet length */
  789. {
  790. struct sd *sd = (struct sd *) gspca_dev;
  791. switch (data[0]) {
  792. case 0: /* start of frame */
  793. frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
  794. data, 0);
  795. data += SPCA561_OFFSET_DATA;
  796. len -= SPCA561_OFFSET_DATA;
  797. if (data[1] & 0x10) {
  798. /* compressed bayer */
  799. gspca_frame_add(gspca_dev, FIRST_PACKET,
  800. frame, data, len);
  801. } else {
  802. /* raw bayer (with a header, which we skip) */
  803. if (sd->chip_revision == Rev012A) {
  804. data += 20;
  805. len -= 20;
  806. } else {
  807. data += 16;
  808. len -= 16;
  809. }
  810. gspca_frame_add(gspca_dev, FIRST_PACKET,
  811. frame, data, len);
  812. }
  813. return;
  814. case 0xff: /* drop */
  815. /* gspca_dev->last_packet_type = DISCARD_PACKET; */
  816. return;
  817. }
  818. data++;
  819. len--;
  820. gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
  821. }
  822. /* rev 72a only */
  823. static void setbrightness(struct gspca_dev *gspca_dev)
  824. {
  825. struct sd *sd = (struct sd *) gspca_dev;
  826. __u8 value;
  827. value = sd->brightness;
  828. reg_w_val(gspca_dev->dev, 0x8611, value);
  829. reg_w_val(gspca_dev->dev, 0x8612, value);
  830. reg_w_val(gspca_dev->dev, 0x8613, value);
  831. reg_w_val(gspca_dev->dev, 0x8614, value);
  832. }
  833. static void getbrightness(struct gspca_dev *gspca_dev)
  834. {
  835. struct sd *sd = (struct sd *) gspca_dev;
  836. __u16 tot;
  837. tot = 0;
  838. reg_r(gspca_dev, 0x8611, 1);
  839. tot += gspca_dev->usb_buf[0];
  840. reg_r(gspca_dev, 0x8612, 1);
  841. tot += gspca_dev->usb_buf[0];
  842. reg_r(gspca_dev, 0x8613, 1);
  843. tot += gspca_dev->usb_buf[0];
  844. reg_r(gspca_dev, 0x8614, 1);
  845. tot += gspca_dev->usb_buf[0];
  846. sd->brightness = tot >> 2;
  847. }
  848. /* rev72a only */
  849. static void getcontrast(struct gspca_dev *gspca_dev)
  850. {
  851. struct sd *sd = (struct sd *) gspca_dev;
  852. __u16 tot;
  853. tot = 0;
  854. reg_r(gspca_dev, 0x8651, 1);
  855. tot += gspca_dev->usb_buf[0];
  856. reg_r(gspca_dev, 0x8652, 1);
  857. tot += gspca_dev->usb_buf[0];
  858. reg_r(gspca_dev, 0x8653, 1);
  859. tot += gspca_dev->usb_buf[0];
  860. reg_r(gspca_dev, 0x8654, 1);
  861. tot += gspca_dev->usb_buf[0];
  862. sd->contrast = tot << 6;
  863. PDEBUG(D_CONF, "get contrast %d", sd->contrast);
  864. }
  865. /* rev 72a only */
  866. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  867. {
  868. struct sd *sd = (struct sd *) gspca_dev;
  869. sd->brightness = val;
  870. if (gspca_dev->streaming)
  871. setbrightness(gspca_dev);
  872. return 0;
  873. }
  874. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  875. {
  876. struct sd *sd = (struct sd *) gspca_dev;
  877. getbrightness(gspca_dev);
  878. *val = sd->brightness;
  879. return 0;
  880. }
  881. /* rev 72a only */
  882. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  883. {
  884. struct sd *sd = (struct sd *) gspca_dev;
  885. sd->contrast = val;
  886. if (gspca_dev->streaming)
  887. setcontrast(gspca_dev);
  888. return 0;
  889. }
  890. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  891. {
  892. struct sd *sd = (struct sd *) gspca_dev;
  893. getcontrast(gspca_dev);
  894. *val = sd->contrast;
  895. return 0;
  896. }
  897. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
  898. {
  899. struct sd *sd = (struct sd *) gspca_dev;
  900. sd->autogain = val;
  901. if (gspca_dev->streaming)
  902. setautogain(gspca_dev);
  903. return 0;
  904. }
  905. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
  906. {
  907. struct sd *sd = (struct sd *) gspca_dev;
  908. *val = sd->autogain;
  909. return 0;
  910. }
  911. /* rev12a only */
  912. static int sd_setwhite(struct gspca_dev *gspca_dev, __s32 val)
  913. {
  914. struct sd *sd = (struct sd *) gspca_dev;
  915. sd->white = val;
  916. if (gspca_dev->streaming)
  917. setwhite(gspca_dev);
  918. return 0;
  919. }
  920. static int sd_getwhite(struct gspca_dev *gspca_dev, __s32 *val)
  921. {
  922. struct sd *sd = (struct sd *) gspca_dev;
  923. *val = sd->white;
  924. return 0;
  925. }
  926. /* rev12a only */
  927. static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
  928. {
  929. struct sd *sd = (struct sd *) gspca_dev;
  930. sd->exposure = val;
  931. if (gspca_dev->streaming)
  932. setexposure(gspca_dev);
  933. return 0;
  934. }
  935. static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
  936. {
  937. struct sd *sd = (struct sd *) gspca_dev;
  938. *val = sd->exposure;
  939. return 0;
  940. }
  941. /* rev12a only */
  942. static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
  943. {
  944. struct sd *sd = (struct sd *) gspca_dev;
  945. sd->gain = val;
  946. if (gspca_dev->streaming)
  947. setgain(gspca_dev);
  948. return 0;
  949. }
  950. static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
  951. {
  952. struct sd *sd = (struct sd *) gspca_dev;
  953. *val = sd->gain;
  954. return 0;
  955. }
  956. /* control tables */
  957. static struct ctrl sd_ctrls_12a[] = {
  958. {
  959. {
  960. .id = V4L2_CID_DO_WHITE_BALANCE,
  961. .type = V4L2_CTRL_TYPE_INTEGER,
  962. .name = "White Balance",
  963. .minimum = WHITE_MIN,
  964. .maximum = WHITE_MAX,
  965. .step = 1,
  966. .default_value = WHITE_DEF,
  967. },
  968. .set = sd_setwhite,
  969. .get = sd_getwhite,
  970. },
  971. {
  972. {
  973. .id = V4L2_CID_EXPOSURE,
  974. .type = V4L2_CTRL_TYPE_INTEGER,
  975. .name = "Exposure",
  976. .minimum = EXPOSURE_MIN,
  977. .maximum = EXPOSURE_MAX,
  978. .step = 1,
  979. .default_value = EXPOSURE_DEF,
  980. },
  981. .set = sd_setexposure,
  982. .get = sd_getexposure,
  983. },
  984. {
  985. {
  986. .id = V4L2_CID_AUTOGAIN,
  987. .type = V4L2_CTRL_TYPE_BOOLEAN,
  988. .name = "Auto Gain",
  989. .minimum = AUTOGAIN_MIN,
  990. .maximum = AUTOGAIN_MAX,
  991. .step = 1,
  992. .default_value = AUTOGAIN_DEF,
  993. },
  994. .set = sd_setautogain,
  995. .get = sd_getautogain,
  996. },
  997. {
  998. {
  999. .id = V4L2_CID_GAIN,
  1000. .type = V4L2_CTRL_TYPE_INTEGER,
  1001. .name = "Gain",
  1002. .minimum = GAIN_MIN,
  1003. .maximum = GAIN_MAX,
  1004. .step = 1,
  1005. .default_value = GAIN_DEF,
  1006. },
  1007. .set = sd_setgain,
  1008. .get = sd_getgain,
  1009. },
  1010. };
  1011. static struct ctrl sd_ctrls_72a[] = {
  1012. {
  1013. {
  1014. .id = V4L2_CID_BRIGHTNESS,
  1015. .type = V4L2_CTRL_TYPE_INTEGER,
  1016. .name = "Brightness",
  1017. .minimum = BRIGHTNESS_MIN,
  1018. .maximum = BRIGHTNESS_MAX,
  1019. .step = 1,
  1020. .default_value = BRIGHTNESS_DEF,
  1021. },
  1022. .set = sd_setbrightness,
  1023. .get = sd_getbrightness,
  1024. },
  1025. {
  1026. {
  1027. .id = V4L2_CID_CONTRAST,
  1028. .type = V4L2_CTRL_TYPE_INTEGER,
  1029. .name = "Contrast",
  1030. .minimum = CONTRAST_MIN,
  1031. .maximum = CONTRAST_MAX,
  1032. .step = 1,
  1033. .default_value = CONTRAST_DEF,
  1034. },
  1035. .set = sd_setcontrast,
  1036. .get = sd_getcontrast,
  1037. },
  1038. {
  1039. {
  1040. .id = V4L2_CID_AUTOGAIN,
  1041. .type = V4L2_CTRL_TYPE_BOOLEAN,
  1042. .name = "Auto Gain",
  1043. .minimum = AUTOGAIN_MIN,
  1044. .maximum = AUTOGAIN_MAX,
  1045. .step = 1,
  1046. .default_value = AUTOGAIN_DEF,
  1047. },
  1048. .set = sd_setautogain,
  1049. .get = sd_getautogain,
  1050. },
  1051. };
  1052. /* sub-driver description */
  1053. static const struct sd_desc sd_desc_12a = {
  1054. .name = MODULE_NAME,
  1055. .ctrls = sd_ctrls_12a,
  1056. .nctrls = ARRAY_SIZE(sd_ctrls_12a),
  1057. .config = sd_config,
  1058. .init = sd_init_12a,
  1059. .start = sd_start_12a,
  1060. .stopN = sd_stopN,
  1061. .stop0 = sd_stop0,
  1062. .pkt_scan = sd_pkt_scan,
  1063. /* .dq_callback = do_autogain, * fixme */
  1064. };
  1065. static const struct sd_desc sd_desc_72a = {
  1066. .name = MODULE_NAME,
  1067. .ctrls = sd_ctrls_72a,
  1068. .nctrls = ARRAY_SIZE(sd_ctrls_72a),
  1069. .config = sd_config,
  1070. .init = sd_init_72a,
  1071. .start = sd_start_72a,
  1072. .stopN = sd_stopN,
  1073. .stop0 = sd_stop0,
  1074. .pkt_scan = sd_pkt_scan,
  1075. .dq_callback = do_autogain,
  1076. };
  1077. static const struct sd_desc *sd_desc[2] = {
  1078. &sd_desc_12a,
  1079. &sd_desc_72a
  1080. };
  1081. /* -- module initialisation -- */
  1082. static const __devinitdata struct usb_device_id device_table[] = {
  1083. {USB_DEVICE(0x041e, 0x401a), .driver_info = Rev072A},
  1084. {USB_DEVICE(0x041e, 0x403b), .driver_info = Rev012A},
  1085. {USB_DEVICE(0x0458, 0x7004), .driver_info = Rev072A},
  1086. {USB_DEVICE(0x046d, 0x0928), .driver_info = Rev012A},
  1087. {USB_DEVICE(0x046d, 0x0929), .driver_info = Rev012A},
  1088. {USB_DEVICE(0x046d, 0x092a), .driver_info = Rev012A},
  1089. {USB_DEVICE(0x046d, 0x092b), .driver_info = Rev012A},
  1090. {USB_DEVICE(0x046d, 0x092c), .driver_info = Rev012A},
  1091. {USB_DEVICE(0x046d, 0x092d), .driver_info = Rev012A},
  1092. {USB_DEVICE(0x046d, 0x092e), .driver_info = Rev012A},
  1093. {USB_DEVICE(0x046d, 0x092f), .driver_info = Rev012A},
  1094. {USB_DEVICE(0x04fc, 0x0561), .driver_info = Rev072A},
  1095. {USB_DEVICE(0x060b, 0xa001), .driver_info = Rev072A},
  1096. {USB_DEVICE(0x10fd, 0x7e50), .driver_info = Rev072A},
  1097. {USB_DEVICE(0xabcd, 0xcdee), .driver_info = Rev072A},
  1098. {}
  1099. };
  1100. MODULE_DEVICE_TABLE(usb, device_table);
  1101. /* -- device connect -- */
  1102. static int sd_probe(struct usb_interface *intf,
  1103. const struct usb_device_id *id)
  1104. {
  1105. return gspca_dev_probe(intf, id,
  1106. sd_desc[id->driver_info],
  1107. sizeof(struct sd),
  1108. THIS_MODULE);
  1109. }
  1110. static struct usb_driver sd_driver = {
  1111. .name = MODULE_NAME,
  1112. .id_table = device_table,
  1113. .probe = sd_probe,
  1114. .disconnect = gspca_disconnect,
  1115. #ifdef CONFIG_PM
  1116. .suspend = gspca_suspend,
  1117. .resume = gspca_resume,
  1118. #endif
  1119. };
  1120. /* -- module insert / remove -- */
  1121. static int __init sd_mod_init(void)
  1122. {
  1123. if (usb_register(&sd_driver) < 0)
  1124. return -1;
  1125. PDEBUG(D_PROBE, "registered");
  1126. return 0;
  1127. }
  1128. static void __exit sd_mod_exit(void)
  1129. {
  1130. usb_deregister(&sd_driver);
  1131. PDEBUG(D_PROBE, "deregistered");
  1132. }
  1133. module_init(sd_mod_init);
  1134. module_exit(sd_mod_exit);