spca561.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247
  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_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 void 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. }
  667. static void sd_start_72a(struct gspca_dev *gspca_dev)
  668. {
  669. struct usb_device *dev = gspca_dev->dev;
  670. int Clck;
  671. int mode;
  672. mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
  673. switch (mode) {
  674. default:
  675. /* case 0:
  676. case 1: */
  677. Clck = 0x25;
  678. break;
  679. case 2:
  680. Clck = 0x22;
  681. break;
  682. case 3:
  683. Clck = 0x21;
  684. break;
  685. }
  686. reg_w_val(dev, 0x8500, mode); /* mode */
  687. reg_w_val(dev, 0x8700, Clck); /* 0x27 clock */
  688. reg_w_val(dev, 0x8112, 0x10 | 0x20);
  689. setautogain(gspca_dev);
  690. }
  691. static void sd_stopN(struct gspca_dev *gspca_dev)
  692. {
  693. struct sd *sd = (struct sd *) gspca_dev;
  694. if (sd->chip_revision == Rev012A) {
  695. reg_w_val(gspca_dev->dev, 0x8112, 0x0e);
  696. } else {
  697. reg_w_val(gspca_dev->dev, 0x8112, 0x20);
  698. /* reg_w_val(gspca_dev->dev, 0x8102, 0x00); ?? */
  699. }
  700. }
  701. static void sd_stop0(struct gspca_dev *gspca_dev)
  702. {
  703. struct sd *sd = (struct sd *) gspca_dev;
  704. if (sd->chip_revision == Rev012A) {
  705. reg_w_val(gspca_dev->dev, 0x8118, 0x29);
  706. reg_w_val(gspca_dev->dev, 0x8114, 0x08);
  707. }
  708. /* reg_w_val(gspca_dev->dev, 0x8114, 0); */
  709. }
  710. static void do_autogain(struct gspca_dev *gspca_dev)
  711. {
  712. struct sd *sd = (struct sd *) gspca_dev;
  713. int expotimes;
  714. int pixelclk;
  715. int gainG;
  716. __u8 R, Gr, Gb, B;
  717. int y;
  718. __u8 luma_mean = 110;
  719. __u8 luma_delta = 20;
  720. __u8 spring = 4;
  721. __u8 reg8339[2];
  722. if (sd->ag_cnt < 0)
  723. return;
  724. if (--sd->ag_cnt >= 0)
  725. return;
  726. sd->ag_cnt = AG_CNT_START;
  727. switch (sd->chip_revision) {
  728. case Rev072A:
  729. reg_r(gspca_dev, 0x8621, 1);
  730. Gr = gspca_dev->usb_buf[0];
  731. reg_r(gspca_dev, 0x8622, 1);
  732. R = gspca_dev->usb_buf[0];
  733. reg_r(gspca_dev, 0x8623, 1);
  734. B = gspca_dev->usb_buf[0];
  735. reg_r(gspca_dev, 0x8624, 1);
  736. Gb = gspca_dev->usb_buf[0];
  737. y = (77 * R + 75 * (Gr + Gb) + 29 * B) >> 8;
  738. /* u= (128*B-(43*(Gr+Gb+R))) >> 8; */
  739. /* v= (128*R-(53*(Gr+Gb))-21*B) >> 8; */
  740. /* PDEBUG(D_CONF,"reading Y %d U %d V %d ",y,u,v); */
  741. if (y < luma_mean - luma_delta ||
  742. y > luma_mean + luma_delta) {
  743. expotimes = i2c_read(gspca_dev, 0x09, 0x10);
  744. pixelclk = 0x0800;
  745. expotimes = expotimes & 0x07ff;
  746. /* PDEBUG(D_PACK,
  747. "Exposition Times 0x%03X Clock 0x%04X ",
  748. expotimes,pixelclk); */
  749. gainG = i2c_read(gspca_dev, 0x35, 0x10);
  750. /* PDEBUG(D_PACK,
  751. "reading Gain register %d", gainG); */
  752. expotimes += (luma_mean - y) >> spring;
  753. gainG += (luma_mean - y) / 50;
  754. /* PDEBUG(D_PACK,
  755. "compute expotimes %d gain %d",
  756. expotimes,gainG); */
  757. if (gainG > 0x3f)
  758. gainG = 0x3f;
  759. else if (gainG < 4)
  760. gainG = 3;
  761. i2c_write(gspca_dev, gainG, 0x35);
  762. if (expotimes >= 0x0256)
  763. expotimes = 0x0256;
  764. else if (expotimes < 4)
  765. expotimes = 3;
  766. i2c_write(gspca_dev, expotimes | pixelclk, 0x09);
  767. }
  768. break;
  769. case Rev012A:
  770. reg_r(gspca_dev, 0x8330, 2);
  771. if (gspca_dev->usb_buf[1] > 0x08) {
  772. reg8339[0] = ++sd->expo12a;
  773. reg8339[1] = 0;
  774. reg_w_buf(gspca_dev, 0x8339, reg8339, 2);
  775. } else if (gspca_dev->usb_buf[1] < 0x02) {
  776. reg8339[0] = --sd->expo12a;
  777. reg8339[1] = 0;
  778. reg_w_buf(gspca_dev, 0x8339, reg8339, 2);
  779. }
  780. break;
  781. }
  782. }
  783. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  784. struct gspca_frame *frame, /* target */
  785. __u8 *data, /* isoc packet */
  786. int len) /* iso packet length */
  787. {
  788. struct sd *sd = (struct sd *) gspca_dev;
  789. switch (data[0]) {
  790. case 0: /* start of frame */
  791. frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
  792. data, 0);
  793. data += SPCA561_OFFSET_DATA;
  794. len -= SPCA561_OFFSET_DATA;
  795. if (data[1] & 0x10) {
  796. /* compressed bayer */
  797. gspca_frame_add(gspca_dev, FIRST_PACKET,
  798. frame, data, len);
  799. } else {
  800. /* raw bayer (with a header, which we skip) */
  801. if (sd->chip_revision == Rev012A) {
  802. data += 20;
  803. len -= 20;
  804. } else {
  805. data += 16;
  806. len -= 16;
  807. }
  808. gspca_frame_add(gspca_dev, FIRST_PACKET,
  809. frame, data, len);
  810. }
  811. return;
  812. case 0xff: /* drop */
  813. /* gspca_dev->last_packet_type = DISCARD_PACKET; */
  814. return;
  815. }
  816. data++;
  817. len--;
  818. gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
  819. }
  820. /* rev 72a only */
  821. static void setbrightness(struct gspca_dev *gspca_dev)
  822. {
  823. struct sd *sd = (struct sd *) gspca_dev;
  824. __u8 value;
  825. value = sd->brightness;
  826. reg_w_val(gspca_dev->dev, 0x8611, value);
  827. reg_w_val(gspca_dev->dev, 0x8612, value);
  828. reg_w_val(gspca_dev->dev, 0x8613, value);
  829. reg_w_val(gspca_dev->dev, 0x8614, value);
  830. }
  831. static void getbrightness(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, 0x8611, 1);
  837. tot += gspca_dev->usb_buf[0];
  838. reg_r(gspca_dev, 0x8612, 1);
  839. tot += gspca_dev->usb_buf[0];
  840. reg_r(gspca_dev, 0x8613, 1);
  841. tot += gspca_dev->usb_buf[0];
  842. reg_r(gspca_dev, 0x8614, 1);
  843. tot += gspca_dev->usb_buf[0];
  844. sd->brightness = tot >> 2;
  845. }
  846. /* rev72a only */
  847. static void getcontrast(struct gspca_dev *gspca_dev)
  848. {
  849. struct sd *sd = (struct sd *) gspca_dev;
  850. __u16 tot;
  851. tot = 0;
  852. reg_r(gspca_dev, 0x8651, 1);
  853. tot += gspca_dev->usb_buf[0];
  854. reg_r(gspca_dev, 0x8652, 1);
  855. tot += gspca_dev->usb_buf[0];
  856. reg_r(gspca_dev, 0x8653, 1);
  857. tot += gspca_dev->usb_buf[0];
  858. reg_r(gspca_dev, 0x8654, 1);
  859. tot += gspca_dev->usb_buf[0];
  860. sd->contrast = tot << 6;
  861. PDEBUG(D_CONF, "get contrast %d", sd->contrast);
  862. }
  863. /* rev 72a only */
  864. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  865. {
  866. struct sd *sd = (struct sd *) gspca_dev;
  867. sd->brightness = val;
  868. if (gspca_dev->streaming)
  869. setbrightness(gspca_dev);
  870. return 0;
  871. }
  872. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  873. {
  874. struct sd *sd = (struct sd *) gspca_dev;
  875. getbrightness(gspca_dev);
  876. *val = sd->brightness;
  877. return 0;
  878. }
  879. /* rev 72a only */
  880. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  881. {
  882. struct sd *sd = (struct sd *) gspca_dev;
  883. sd->contrast = val;
  884. if (gspca_dev->streaming)
  885. setcontrast(gspca_dev);
  886. return 0;
  887. }
  888. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  889. {
  890. struct sd *sd = (struct sd *) gspca_dev;
  891. getcontrast(gspca_dev);
  892. *val = sd->contrast;
  893. return 0;
  894. }
  895. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
  896. {
  897. struct sd *sd = (struct sd *) gspca_dev;
  898. sd->autogain = val;
  899. if (gspca_dev->streaming)
  900. setautogain(gspca_dev);
  901. return 0;
  902. }
  903. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
  904. {
  905. struct sd *sd = (struct sd *) gspca_dev;
  906. *val = sd->autogain;
  907. return 0;
  908. }
  909. /* rev12a only */
  910. static int sd_setwhite(struct gspca_dev *gspca_dev, __s32 val)
  911. {
  912. struct sd *sd = (struct sd *) gspca_dev;
  913. sd->white = val;
  914. if (gspca_dev->streaming)
  915. setwhite(gspca_dev);
  916. return 0;
  917. }
  918. static int sd_getwhite(struct gspca_dev *gspca_dev, __s32 *val)
  919. {
  920. struct sd *sd = (struct sd *) gspca_dev;
  921. *val = sd->white;
  922. return 0;
  923. }
  924. /* rev12a only */
  925. static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
  926. {
  927. struct sd *sd = (struct sd *) gspca_dev;
  928. sd->exposure = val;
  929. if (gspca_dev->streaming)
  930. setexposure(gspca_dev);
  931. return 0;
  932. }
  933. static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
  934. {
  935. struct sd *sd = (struct sd *) gspca_dev;
  936. *val = sd->exposure;
  937. return 0;
  938. }
  939. /* rev12a only */
  940. static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
  941. {
  942. struct sd *sd = (struct sd *) gspca_dev;
  943. sd->gain = val;
  944. if (gspca_dev->streaming)
  945. setgain(gspca_dev);
  946. return 0;
  947. }
  948. static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
  949. {
  950. struct sd *sd = (struct sd *) gspca_dev;
  951. *val = sd->gain;
  952. return 0;
  953. }
  954. /* control tables */
  955. static struct ctrl sd_ctrls_12a[] = {
  956. {
  957. {
  958. .id = V4L2_CID_DO_WHITE_BALANCE,
  959. .type = V4L2_CTRL_TYPE_INTEGER,
  960. .name = "While Balance",
  961. .minimum = WHITE_MIN,
  962. .maximum = WHITE_MAX,
  963. .step = 1,
  964. .default_value = WHITE_DEF,
  965. },
  966. .set = sd_setwhite,
  967. .get = sd_getwhite,
  968. },
  969. {
  970. {
  971. .id = V4L2_CID_EXPOSURE,
  972. .type = V4L2_CTRL_TYPE_INTEGER,
  973. .name = "Exposure",
  974. .minimum = EXPOSURE_MIN,
  975. .maximum = EXPOSURE_MAX,
  976. .step = 1,
  977. .default_value = EXPOSURE_DEF,
  978. },
  979. .set = sd_setexposure,
  980. .get = sd_getexposure,
  981. },
  982. {
  983. {
  984. .id = V4L2_CID_AUTOGAIN,
  985. .type = V4L2_CTRL_TYPE_BOOLEAN,
  986. .name = "Auto Gain",
  987. .minimum = AUTOGAIN_MIN,
  988. .maximum = AUTOGAIN_MAX,
  989. .step = 1,
  990. .default_value = AUTOGAIN_DEF,
  991. },
  992. .set = sd_setautogain,
  993. .get = sd_getautogain,
  994. },
  995. {
  996. {
  997. .id = V4L2_CID_GAIN,
  998. .type = V4L2_CTRL_TYPE_INTEGER,
  999. .name = "Gain",
  1000. .minimum = GAIN_MIN,
  1001. .maximum = GAIN_MAX,
  1002. .step = 1,
  1003. .default_value = GAIN_DEF,
  1004. },
  1005. .set = sd_setgain,
  1006. .get = sd_getgain,
  1007. },
  1008. };
  1009. static struct ctrl sd_ctrls_72a[] = {
  1010. {
  1011. {
  1012. .id = V4L2_CID_BRIGHTNESS,
  1013. .type = V4L2_CTRL_TYPE_INTEGER,
  1014. .name = "Brightness",
  1015. .minimum = BRIGHTNESS_MIN,
  1016. .maximum = BRIGHTNESS_MAX,
  1017. .step = 1,
  1018. .default_value = BRIGHTNESS_DEF,
  1019. },
  1020. .set = sd_setbrightness,
  1021. .get = sd_getbrightness,
  1022. },
  1023. {
  1024. {
  1025. .id = V4L2_CID_CONTRAST,
  1026. .type = V4L2_CTRL_TYPE_INTEGER,
  1027. .name = "Contrast",
  1028. .minimum = CONTRAST_MIN,
  1029. .maximum = CONTRAST_MAX,
  1030. .step = 1,
  1031. .default_value = CONTRAST_DEF,
  1032. },
  1033. .set = sd_setcontrast,
  1034. .get = sd_getcontrast,
  1035. },
  1036. {
  1037. {
  1038. .id = V4L2_CID_AUTOGAIN,
  1039. .type = V4L2_CTRL_TYPE_BOOLEAN,
  1040. .name = "Auto Gain",
  1041. .minimum = AUTOGAIN_MIN,
  1042. .maximum = AUTOGAIN_MAX,
  1043. .step = 1,
  1044. .default_value = AUTOGAIN_DEF,
  1045. },
  1046. .set = sd_setautogain,
  1047. .get = sd_getautogain,
  1048. },
  1049. };
  1050. /* sub-driver description */
  1051. static const struct sd_desc sd_desc_12a = {
  1052. .name = MODULE_NAME,
  1053. .ctrls = sd_ctrls_12a,
  1054. .nctrls = ARRAY_SIZE(sd_ctrls_12a),
  1055. .config = sd_config,
  1056. .init = sd_init_12a,
  1057. .start = sd_start_12a,
  1058. .stopN = sd_stopN,
  1059. .stop0 = sd_stop0,
  1060. .pkt_scan = sd_pkt_scan,
  1061. /* .dq_callback = do_autogain, * fixme */
  1062. };
  1063. static const struct sd_desc sd_desc_72a = {
  1064. .name = MODULE_NAME,
  1065. .ctrls = sd_ctrls_72a,
  1066. .nctrls = ARRAY_SIZE(sd_ctrls_72a),
  1067. .config = sd_config,
  1068. .init = sd_init_72a,
  1069. .start = sd_start_72a,
  1070. .stopN = sd_stopN,
  1071. .stop0 = sd_stop0,
  1072. .pkt_scan = sd_pkt_scan,
  1073. .dq_callback = do_autogain,
  1074. };
  1075. static const struct sd_desc *sd_desc[2] = {
  1076. &sd_desc_12a,
  1077. &sd_desc_72a
  1078. };
  1079. /* -- module initialisation -- */
  1080. static const __devinitdata struct usb_device_id device_table[] = {
  1081. {USB_DEVICE(0x041e, 0x401a), .driver_info = Rev072A},
  1082. {USB_DEVICE(0x041e, 0x403b), .driver_info = Rev012A},
  1083. {USB_DEVICE(0x0458, 0x7004), .driver_info = Rev072A},
  1084. {USB_DEVICE(0x046d, 0x0928), .driver_info = Rev012A},
  1085. {USB_DEVICE(0x046d, 0x0929), .driver_info = Rev012A},
  1086. {USB_DEVICE(0x046d, 0x092a), .driver_info = Rev012A},
  1087. {USB_DEVICE(0x046d, 0x092b), .driver_info = Rev012A},
  1088. {USB_DEVICE(0x046d, 0x092c), .driver_info = Rev012A},
  1089. {USB_DEVICE(0x046d, 0x092d), .driver_info = Rev012A},
  1090. {USB_DEVICE(0x046d, 0x092e), .driver_info = Rev012A},
  1091. {USB_DEVICE(0x046d, 0x092f), .driver_info = Rev012A},
  1092. {USB_DEVICE(0x04fc, 0x0561), .driver_info = Rev072A},
  1093. {USB_DEVICE(0x060b, 0xa001), .driver_info = Rev072A},
  1094. {USB_DEVICE(0x10fd, 0x7e50), .driver_info = Rev072A},
  1095. {USB_DEVICE(0xabcd, 0xcdee), .driver_info = Rev072A},
  1096. {}
  1097. };
  1098. MODULE_DEVICE_TABLE(usb, device_table);
  1099. /* -- device connect -- */
  1100. static int sd_probe(struct usb_interface *intf,
  1101. const struct usb_device_id *id)
  1102. {
  1103. return gspca_dev_probe(intf, id,
  1104. sd_desc[id->driver_info],
  1105. sizeof(struct sd),
  1106. THIS_MODULE);
  1107. }
  1108. static struct usb_driver sd_driver = {
  1109. .name = MODULE_NAME,
  1110. .id_table = device_table,
  1111. .probe = sd_probe,
  1112. .disconnect = gspca_disconnect,
  1113. #ifdef CONFIG_PM
  1114. .suspend = gspca_suspend,
  1115. .resume = gspca_resume,
  1116. #endif
  1117. };
  1118. /* -- module insert / remove -- */
  1119. static int __init sd_mod_init(void)
  1120. {
  1121. if (usb_register(&sd_driver) < 0)
  1122. return -1;
  1123. PDEBUG(D_PROBE, "registered");
  1124. return 0;
  1125. }
  1126. static void __exit sd_mod_exit(void)
  1127. {
  1128. usb_deregister(&sd_driver);
  1129. PDEBUG(D_PROBE, "deregistered");
  1130. }
  1131. module_init(sd_mod_init);
  1132. module_exit(sd_mod_exit);