spca561.c 31 KB

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