pac7311.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115
  1. /*
  2. * Pixart PAC7311 library
  3. * Copyright (C) 2005 Thomas Kaiser thomas@kaiser-linux.li
  4. *
  5. * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. /* Some documentation about various registers as determined by trial and error.
  22. When the register addresses differ between the 7202 and the 7311 the 2
  23. different addresses are written as 7302addr/7311addr, when one of the 2
  24. addresses is a - sign that register description is not valid for the
  25. matching IC.
  26. Register page 1:
  27. Address Description
  28. -/0x08 Unknown compressor related, must always be 8 except when not
  29. in 640x480 resolution and page 4 reg 2 <= 3 then set it to 9 !
  30. -/0x1b Auto white balance related, bit 0 is AWB enable (inverted)
  31. bits 345 seem to toggle per color gains on/off (inverted)
  32. 0x78 Global control, bit 6 controls the LED (inverted)
  33. -/0x80 JPEG compression ratio ? Best not touched
  34. Register page 3/4:
  35. Address Description
  36. 0x02 Clock divider 2-63, fps =~ 60 / val. Must be a multiple of 3 on
  37. the 7302, so one of 3, 6, 9, ..., except when between 6 and 12?
  38. -/0x0f Master gain 1-245, low value = high gain
  39. 0x10/- Master gain 0-31
  40. -/0x10 Another gain 0-15, limited influence (1-2x gain I guess)
  41. 0x21 Bitfield: 0-1 unused, 2-3 vflip/hflip, 4-5 unknown, 6-7 unused
  42. -/0x27 Seems to toggle various gains on / off, Setting bit 7 seems to
  43. completely disable the analog amplification block. Set to 0x68
  44. for max gain, 0x14 for minimal gain.
  45. */
  46. #define MODULE_NAME "pac7311"
  47. #include "gspca.h"
  48. MODULE_AUTHOR("Thomas Kaiser thomas@kaiser-linux.li");
  49. MODULE_DESCRIPTION("Pixart PAC7311");
  50. MODULE_LICENSE("GPL");
  51. /* specific webcam descriptor */
  52. struct sd {
  53. struct gspca_dev gspca_dev; /* !! must be the first item */
  54. unsigned char brightness;
  55. unsigned char contrast;
  56. unsigned char colors;
  57. unsigned char gain;
  58. unsigned char exposure;
  59. unsigned char autogain;
  60. __u8 hflip;
  61. __u8 vflip;
  62. __u8 sensor;
  63. #define SENSOR_PAC7302 0
  64. #define SENSOR_PAC7311 1
  65. u8 sof_read;
  66. u8 autogain_ignore_frames;
  67. atomic_t avg_lum;
  68. };
  69. /* V4L2 controls supported by the driver */
  70. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
  71. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
  72. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
  73. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
  74. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
  75. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
  76. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
  77. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
  78. static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
  79. static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val);
  80. static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
  81. static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
  82. static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
  83. static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
  84. static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
  85. static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);
  86. static struct ctrl sd_ctrls[] = {
  87. /* This control is pac7302 only */
  88. #define BRIGHTNESS_IDX 0
  89. {
  90. {
  91. .id = V4L2_CID_BRIGHTNESS,
  92. .type = V4L2_CTRL_TYPE_INTEGER,
  93. .name = "Brightness",
  94. .minimum = 0,
  95. #define BRIGHTNESS_MAX 0x20
  96. .maximum = BRIGHTNESS_MAX,
  97. .step = 1,
  98. #define BRIGHTNESS_DEF 0x10
  99. .default_value = BRIGHTNESS_DEF,
  100. },
  101. .set = sd_setbrightness,
  102. .get = sd_getbrightness,
  103. },
  104. /* This control is for both the 7302 and the 7311 */
  105. {
  106. {
  107. .id = V4L2_CID_CONTRAST,
  108. .type = V4L2_CTRL_TYPE_INTEGER,
  109. .name = "Contrast",
  110. .minimum = 0,
  111. #define CONTRAST_MAX 255
  112. .maximum = CONTRAST_MAX,
  113. .step = 1,
  114. #define CONTRAST_DEF 127
  115. .default_value = CONTRAST_DEF,
  116. },
  117. .set = sd_setcontrast,
  118. .get = sd_getcontrast,
  119. },
  120. /* This control is pac7302 only */
  121. #define SATURATION_IDX 2
  122. {
  123. {
  124. .id = V4L2_CID_SATURATION,
  125. .type = V4L2_CTRL_TYPE_INTEGER,
  126. .name = "Saturation",
  127. .minimum = 0,
  128. #define COLOR_MAX 255
  129. .maximum = COLOR_MAX,
  130. .step = 1,
  131. #define COLOR_DEF 127
  132. .default_value = COLOR_DEF,
  133. },
  134. .set = sd_setcolors,
  135. .get = sd_getcolors,
  136. },
  137. /* All controls below are for both the 7302 and the 7311 */
  138. {
  139. {
  140. .id = V4L2_CID_GAIN,
  141. .type = V4L2_CTRL_TYPE_INTEGER,
  142. .name = "Gain",
  143. .minimum = 0,
  144. #define GAIN_MAX 255
  145. .maximum = GAIN_MAX,
  146. .step = 1,
  147. #define GAIN_DEF 127
  148. #define GAIN_KNEE 255 /* Gain seems to cause little noise on the pac73xx */
  149. .default_value = GAIN_DEF,
  150. },
  151. .set = sd_setgain,
  152. .get = sd_getgain,
  153. },
  154. {
  155. {
  156. .id = V4L2_CID_EXPOSURE,
  157. .type = V4L2_CTRL_TYPE_INTEGER,
  158. .name = "Exposure",
  159. .minimum = 0,
  160. #define EXPOSURE_MAX 255
  161. .maximum = EXPOSURE_MAX,
  162. .step = 1,
  163. #define EXPOSURE_DEF 16 /* 32 ms / 30 fps */
  164. #define EXPOSURE_KNEE 50 /* 100 ms / 10 fps */
  165. .default_value = EXPOSURE_DEF,
  166. },
  167. .set = sd_setexposure,
  168. .get = sd_getexposure,
  169. },
  170. {
  171. {
  172. .id = V4L2_CID_AUTOGAIN,
  173. .type = V4L2_CTRL_TYPE_BOOLEAN,
  174. .name = "Auto Gain",
  175. .minimum = 0,
  176. .maximum = 1,
  177. .step = 1,
  178. #define AUTOGAIN_DEF 1
  179. .default_value = AUTOGAIN_DEF,
  180. },
  181. .set = sd_setautogain,
  182. .get = sd_getautogain,
  183. },
  184. {
  185. {
  186. .id = V4L2_CID_HFLIP,
  187. .type = V4L2_CTRL_TYPE_BOOLEAN,
  188. .name = "Mirror",
  189. .minimum = 0,
  190. .maximum = 1,
  191. .step = 1,
  192. #define HFLIP_DEF 0
  193. .default_value = HFLIP_DEF,
  194. },
  195. .set = sd_sethflip,
  196. .get = sd_gethflip,
  197. },
  198. {
  199. {
  200. .id = V4L2_CID_VFLIP,
  201. .type = V4L2_CTRL_TYPE_BOOLEAN,
  202. .name = "Vflip",
  203. .minimum = 0,
  204. .maximum = 1,
  205. .step = 1,
  206. #define VFLIP_DEF 0
  207. .default_value = VFLIP_DEF,
  208. },
  209. .set = sd_setvflip,
  210. .get = sd_getvflip,
  211. },
  212. };
  213. static const struct v4l2_pix_format vga_mode[] = {
  214. {160, 120, V4L2_PIX_FMT_PJPG, V4L2_FIELD_NONE,
  215. .bytesperline = 160,
  216. .sizeimage = 160 * 120 * 3 / 8 + 590,
  217. .colorspace = V4L2_COLORSPACE_JPEG,
  218. .priv = 2},
  219. {320, 240, V4L2_PIX_FMT_PJPG, V4L2_FIELD_NONE,
  220. .bytesperline = 320,
  221. .sizeimage = 320 * 240 * 3 / 8 + 590,
  222. .colorspace = V4L2_COLORSPACE_JPEG,
  223. .priv = 1},
  224. {640, 480, V4L2_PIX_FMT_PJPG, V4L2_FIELD_NONE,
  225. .bytesperline = 640,
  226. .sizeimage = 640 * 480 * 3 / 8 + 590,
  227. .colorspace = V4L2_COLORSPACE_JPEG,
  228. .priv = 0},
  229. };
  230. /* pac 7302 */
  231. static const __u8 init_7302[] = {
  232. /* index,value */
  233. 0xff, 0x01, /* page 1 */
  234. 0x78, 0x00, /* deactivate */
  235. 0xff, 0x01,
  236. 0x78, 0x40, /* led off */
  237. };
  238. static const __u8 start_7302[] = {
  239. /* index, len, [value]* */
  240. 0xff, 1, 0x00, /* page 0 */
  241. 0x00, 12, 0x01, 0x40, 0x40, 0x40, 0x01, 0xe0, 0x02, 0x80,
  242. 0x00, 0x00, 0x00, 0x00,
  243. 0x0d, 24, 0x03, 0x01, 0x00, 0xb5, 0x07, 0xcb, 0x00, 0x00,
  244. 0x07, 0xc8, 0x00, 0xea, 0x07, 0xcf, 0x07, 0xf7,
  245. 0x07, 0x7e, 0x01, 0x0b, 0x00, 0x00, 0x00, 0x11,
  246. 0x26, 2, 0xaa, 0xaa,
  247. 0x2e, 1, 0x31,
  248. 0x38, 1, 0x01,
  249. 0x3a, 3, 0x14, 0xff, 0x5a,
  250. 0x43, 11, 0x00, 0x0a, 0x18, 0x11, 0x01, 0x2c, 0x88, 0x11,
  251. 0x00, 0x54, 0x11,
  252. 0x55, 1, 0x00,
  253. 0x62, 4, 0x10, 0x1e, 0x1e, 0x18,
  254. 0x6b, 1, 0x00,
  255. 0x6e, 3, 0x08, 0x06, 0x00,
  256. 0x72, 3, 0x00, 0xff, 0x00,
  257. 0x7d, 23, 0x01, 0x01, 0x58, 0x46, 0x50, 0x3c, 0x50, 0x3c,
  258. 0x54, 0x46, 0x54, 0x56, 0x52, 0x50, 0x52, 0x50,
  259. 0x56, 0x64, 0xa4, 0x00, 0xda, 0x00, 0x00,
  260. 0xa2, 10, 0x22, 0x2c, 0x3c, 0x54, 0x69, 0x7c, 0x9c, 0xb9,
  261. 0xd2, 0xeb,
  262. 0xaf, 1, 0x02,
  263. 0xb5, 2, 0x08, 0x08,
  264. 0xb8, 2, 0x08, 0x88,
  265. 0xc4, 4, 0xae, 0x01, 0x04, 0x01,
  266. 0xcc, 1, 0x00,
  267. 0xd1, 11, 0x01, 0x30, 0x49, 0x5e, 0x6f, 0x7f, 0x8e, 0xa9,
  268. 0xc1, 0xd7, 0xec,
  269. 0xdc, 1, 0x01,
  270. 0xff, 1, 0x01, /* page 1 */
  271. 0x12, 3, 0x02, 0x00, 0x01,
  272. 0x3e, 2, 0x00, 0x00,
  273. 0x76, 5, 0x01, 0x20, 0x40, 0x00, 0xf2,
  274. 0x7c, 1, 0x00,
  275. 0x7f, 10, 0x4b, 0x0f, 0x01, 0x2c, 0x02, 0x58, 0x03, 0x20,
  276. 0x02, 0x00,
  277. 0x96, 5, 0x01, 0x10, 0x04, 0x01, 0x04,
  278. 0xc8, 14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00,
  279. 0x07, 0x00, 0x01, 0x07, 0x04, 0x01,
  280. 0xd8, 1, 0x01,
  281. 0xdb, 2, 0x00, 0x01,
  282. 0xde, 7, 0x00, 0x01, 0x04, 0x04, 0x00, 0x00, 0x00,
  283. 0xe6, 4, 0x00, 0x00, 0x00, 0x01,
  284. 0xeb, 1, 0x00,
  285. 0xff, 1, 0x02, /* page 2 */
  286. 0x22, 1, 0x00,
  287. 0xff, 1, 0x03, /* page 3 */
  288. 0x00, 255, /* load the page 3 */
  289. 0x11, 1, 0x01,
  290. 0xff, 1, 0x02, /* page 2 */
  291. 0x13, 1, 0x00,
  292. 0x22, 4, 0x1f, 0xa4, 0xf0, 0x96,
  293. 0x27, 2, 0x14, 0x0c,
  294. 0x2a, 5, 0xc8, 0x00, 0x18, 0x12, 0x22,
  295. 0x64, 8, 0x00, 0x00, 0xf0, 0x01, 0x14, 0x44, 0x44, 0x44,
  296. 0x6e, 1, 0x08,
  297. 0xff, 1, 0x01, /* page 1 */
  298. 0x78, 1, 0x00,
  299. 0, 0 /* end of sequence */
  300. };
  301. /* page 3 - the value 0xaa says skip the index - see reg_w_page() */
  302. static const __u8 page3_7302[] = {
  303. 0x90, 0x40, 0x03, 0x50, 0xc2, 0x01, 0x14, 0x16,
  304. 0x14, 0x12, 0x00, 0x00, 0x00, 0x02, 0x33, 0x00,
  305. 0x0f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  306. 0x00, 0x00, 0x00, 0x47, 0x01, 0xb3, 0x01, 0x00,
  307. 0x00, 0x08, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x21,
  308. 0x00, 0x00, 0x00, 0x54, 0xf4, 0x02, 0x52, 0x54,
  309. 0xa4, 0xb8, 0xe0, 0x2a, 0xf6, 0x00, 0x00, 0x00,
  310. 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  311. 0x00, 0xfc, 0x00, 0xf2, 0x1f, 0x04, 0x00, 0x00,
  312. 0x00, 0x00, 0x00, 0xc0, 0xc0, 0x10, 0x00, 0x00,
  313. 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  314. 0x00, 0x40, 0xff, 0x03, 0x19, 0x00, 0x00, 0x00,
  315. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  316. 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0xc8, 0xc8,
  317. 0xc8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50,
  318. 0x08, 0x10, 0x24, 0x40, 0x00, 0x00, 0x00, 0x00,
  319. 0x01, 0x00, 0x02, 0x47, 0x00, 0x00, 0x00, 0x00,
  320. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  321. 0x00, 0x02, 0xfa, 0x00, 0x64, 0x5a, 0x28, 0x00,
  322. 0x00
  323. };
  324. /* pac 7311 */
  325. static const __u8 init_7311[] = {
  326. 0x78, 0x40, /* Bit_0=start stream, Bit_6=LED */
  327. 0x78, 0x40, /* Bit_0=start stream, Bit_6=LED */
  328. 0x78, 0x44, /* Bit_0=start stream, Bit_6=LED */
  329. 0xff, 0x04,
  330. 0x27, 0x80,
  331. 0x28, 0xca,
  332. 0x29, 0x53,
  333. 0x2a, 0x0e,
  334. 0xff, 0x01,
  335. 0x3e, 0x20,
  336. };
  337. static const __u8 start_7311[] = {
  338. /* index, len, [value]* */
  339. 0xff, 1, 0x01, /* page 1 */
  340. 0x02, 43, 0x48, 0x0a, 0x40, 0x08, 0x00, 0x00, 0x08, 0x00,
  341. 0x06, 0xff, 0x11, 0xff, 0x5a, 0x30, 0x90, 0x4c,
  342. 0x00, 0x07, 0x00, 0x0a, 0x10, 0x00, 0xa0, 0x10,
  343. 0x02, 0x00, 0x00, 0x00, 0x00, 0x0b, 0x01, 0x00,
  344. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  345. 0x00, 0x00, 0x00,
  346. 0x3e, 42, 0x00, 0x00, 0x78, 0x52, 0x4a, 0x52, 0x78, 0x6e,
  347. 0x48, 0x46, 0x48, 0x6e, 0x5f, 0x49, 0x42, 0x49,
  348. 0x5f, 0x5f, 0x49, 0x42, 0x49, 0x5f, 0x6e, 0x48,
  349. 0x46, 0x48, 0x6e, 0x78, 0x52, 0x4a, 0x52, 0x78,
  350. 0x00, 0x00, 0x09, 0x1b, 0x34, 0x49, 0x5c, 0x9b,
  351. 0xd0, 0xff,
  352. 0x78, 6, 0x44, 0x00, 0xf2, 0x01, 0x01, 0x80,
  353. 0x7f, 18, 0x2a, 0x1c, 0x00, 0xc8, 0x02, 0x58, 0x03, 0x84,
  354. 0x12, 0x00, 0x1a, 0x04, 0x08, 0x0c, 0x10, 0x14,
  355. 0x18, 0x20,
  356. 0x96, 3, 0x01, 0x08, 0x04,
  357. 0xa0, 4, 0x44, 0x44, 0x44, 0x04,
  358. 0xf0, 13, 0x01, 0x00, 0x00, 0x00, 0x22, 0x00, 0x20, 0x00,
  359. 0x3f, 0x00, 0x0a, 0x01, 0x00,
  360. 0xff, 1, 0x04, /* page 4 */
  361. 0x00, 254, /* load the page 4 */
  362. 0x11, 1, 0x01,
  363. 0, 0 /* end of sequence */
  364. };
  365. /* page 4 - the value 0xaa says skip the index - see reg_w_page() */
  366. static const __u8 page4_7311[] = {
  367. 0xaa, 0xaa, 0x04, 0x54, 0x07, 0x2b, 0x09, 0x0f,
  368. 0x09, 0x00, 0xaa, 0xaa, 0x07, 0x00, 0x00, 0x62,
  369. 0x08, 0xaa, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
  370. 0x00, 0x00, 0x00, 0x03, 0xa0, 0x01, 0xf4, 0xaa,
  371. 0xaa, 0x00, 0x08, 0xaa, 0x03, 0xaa, 0x00, 0x68,
  372. 0xca, 0x10, 0x06, 0x78, 0x00, 0x00, 0x00, 0x00,
  373. 0x23, 0x28, 0x04, 0x11, 0x00, 0x00
  374. };
  375. static void reg_w_buf(struct gspca_dev *gspca_dev,
  376. __u8 index,
  377. const char *buffer, int len)
  378. {
  379. memcpy(gspca_dev->usb_buf, buffer, len);
  380. usb_control_msg(gspca_dev->dev,
  381. usb_sndctrlpipe(gspca_dev->dev, 0),
  382. 1, /* request */
  383. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  384. 0, /* value */
  385. index, gspca_dev->usb_buf, len,
  386. 500);
  387. }
  388. static void reg_w(struct gspca_dev *gspca_dev,
  389. __u8 index,
  390. __u8 value)
  391. {
  392. gspca_dev->usb_buf[0] = value;
  393. usb_control_msg(gspca_dev->dev,
  394. usb_sndctrlpipe(gspca_dev->dev, 0),
  395. 0, /* request */
  396. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  397. 0, index, gspca_dev->usb_buf, 1,
  398. 500);
  399. }
  400. static void reg_w_seq(struct gspca_dev *gspca_dev,
  401. const __u8 *seq, int len)
  402. {
  403. while (--len >= 0) {
  404. reg_w(gspca_dev, seq[0], seq[1]);
  405. seq += 2;
  406. }
  407. }
  408. /* load the beginning of a page */
  409. static void reg_w_page(struct gspca_dev *gspca_dev,
  410. const __u8 *page, int len)
  411. {
  412. int index;
  413. for (index = 0; index < len; index++) {
  414. if (page[index] == 0xaa) /* skip this index */
  415. continue;
  416. gspca_dev->usb_buf[0] = page[index];
  417. usb_control_msg(gspca_dev->dev,
  418. usb_sndctrlpipe(gspca_dev->dev, 0),
  419. 0, /* request */
  420. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  421. 0, index, gspca_dev->usb_buf, 1,
  422. 500);
  423. }
  424. }
  425. /* output a variable sequence */
  426. static void reg_w_var(struct gspca_dev *gspca_dev,
  427. const __u8 *seq)
  428. {
  429. int index, len;
  430. for (;;) {
  431. index = *seq++;
  432. len = *seq++;
  433. switch (len) {
  434. case 0:
  435. return;
  436. case 254:
  437. reg_w_page(gspca_dev, page4_7311, sizeof page4_7311);
  438. break;
  439. case 255:
  440. reg_w_page(gspca_dev, page3_7302, sizeof page3_7302);
  441. break;
  442. default:
  443. if (len > 64) {
  444. PDEBUG(D_ERR|D_STREAM,
  445. "Incorrect variable sequence");
  446. return;
  447. }
  448. while (len > 0) {
  449. if (len < 8) {
  450. reg_w_buf(gspca_dev, index, seq, len);
  451. seq += len;
  452. break;
  453. }
  454. reg_w_buf(gspca_dev, index, seq, 8);
  455. seq += 8;
  456. index += 8;
  457. len -= 8;
  458. }
  459. }
  460. }
  461. /* not reached */
  462. }
  463. /* this function is called at probe time */
  464. static int sd_config(struct gspca_dev *gspca_dev,
  465. const struct usb_device_id *id)
  466. {
  467. struct sd *sd = (struct sd *) gspca_dev;
  468. struct cam *cam;
  469. cam = &gspca_dev->cam;
  470. sd->sensor = id->driver_info;
  471. if (sd->sensor == SENSOR_PAC7302) {
  472. PDEBUG(D_CONF, "Find Sensor PAC7302");
  473. cam->cam_mode = &vga_mode[2]; /* only 640x480 */
  474. cam->nmodes = 1;
  475. } else {
  476. PDEBUG(D_CONF, "Find Sensor PAC7311");
  477. cam->cam_mode = vga_mode;
  478. cam->nmodes = ARRAY_SIZE(vga_mode);
  479. gspca_dev->ctrl_dis = (1 << BRIGHTNESS_IDX)
  480. | (1 << SATURATION_IDX);
  481. }
  482. sd->brightness = BRIGHTNESS_DEF;
  483. sd->contrast = CONTRAST_DEF;
  484. sd->colors = COLOR_DEF;
  485. sd->gain = GAIN_DEF;
  486. sd->exposure = EXPOSURE_DEF;
  487. sd->autogain = AUTOGAIN_DEF;
  488. sd->hflip = HFLIP_DEF;
  489. sd->vflip = VFLIP_DEF;
  490. return 0;
  491. }
  492. /* This function is used by pac7302 only */
  493. static void setbrightcont(struct gspca_dev *gspca_dev)
  494. {
  495. struct sd *sd = (struct sd *) gspca_dev;
  496. int i, v;
  497. static const __u8 max[10] =
  498. {0x29, 0x33, 0x42, 0x5a, 0x6e, 0x80, 0x9f, 0xbb,
  499. 0xd4, 0xec};
  500. static const __u8 delta[10] =
  501. {0x35, 0x33, 0x33, 0x2f, 0x2a, 0x25, 0x1e, 0x17,
  502. 0x11, 0x0b};
  503. reg_w(gspca_dev, 0xff, 0x00); /* page 0 */
  504. for (i = 0; i < 10; i++) {
  505. v = max[i];
  506. v += (sd->brightness - BRIGHTNESS_MAX)
  507. * 150 / BRIGHTNESS_MAX; /* 200 ? */
  508. v -= delta[i] * sd->contrast / CONTRAST_MAX;
  509. if (v < 0)
  510. v = 0;
  511. else if (v > 0xff)
  512. v = 0xff;
  513. reg_w(gspca_dev, 0xa2 + i, v);
  514. }
  515. reg_w(gspca_dev, 0xdc, 0x01);
  516. }
  517. /* This function is used by pac7311 only */
  518. static void setcontrast(struct gspca_dev *gspca_dev)
  519. {
  520. struct sd *sd = (struct sd *) gspca_dev;
  521. reg_w(gspca_dev, 0xff, 0x04);
  522. reg_w(gspca_dev, 0x10, sd->contrast >> 4);
  523. /* load registers to sensor (Bit 0, auto clear) */
  524. reg_w(gspca_dev, 0x11, 0x01);
  525. }
  526. /* This function is used by pac7302 only */
  527. static void setcolors(struct gspca_dev *gspca_dev)
  528. {
  529. struct sd *sd = (struct sd *) gspca_dev;
  530. int i, v;
  531. static const int a[9] =
  532. {217, -212, 0, -101, 170, -67, -38, -315, 355};
  533. static const int b[9] =
  534. {19, 106, 0, 19, 106, 1, 19, 106, 1};
  535. reg_w(gspca_dev, 0xff, 0x03); /* page 3 */
  536. reg_w(gspca_dev, 0x11, 0x01);
  537. reg_w(gspca_dev, 0xff, 0x00); /* page 0 */
  538. reg_w(gspca_dev, 0xff, 0x00); /* page 0 */
  539. for (i = 0; i < 9; i++) {
  540. v = a[i] * sd->colors / COLOR_MAX + b[i];
  541. reg_w(gspca_dev, 0x0f + 2 * i, (v >> 8) & 0x07);
  542. reg_w(gspca_dev, 0x0f + 2 * i + 1, v);
  543. }
  544. reg_w(gspca_dev, 0xdc, 0x01);
  545. PDEBUG(D_CONF|D_STREAM, "color: %i", sd->colors);
  546. }
  547. static void setgain(struct gspca_dev *gspca_dev)
  548. {
  549. struct sd *sd = (struct sd *) gspca_dev;
  550. if (sd->sensor == SENSOR_PAC7302) {
  551. reg_w(gspca_dev, 0xff, 0x03); /* page 3 */
  552. reg_w(gspca_dev, 0x10, sd->gain >> 3);
  553. } else {
  554. int gain = GAIN_MAX - sd->gain;
  555. if (gain < 1)
  556. gain = 1;
  557. else if (gain > 245)
  558. gain = 245;
  559. reg_w(gspca_dev, 0xff, 0x04); /* page 4 */
  560. reg_w(gspca_dev, 0x0e, 0x00);
  561. reg_w(gspca_dev, 0x0f, gain);
  562. }
  563. /* load registers to sensor (Bit 0, auto clear) */
  564. reg_w(gspca_dev, 0x11, 0x01);
  565. }
  566. static void setexposure(struct gspca_dev *gspca_dev)
  567. {
  568. struct sd *sd = (struct sd *) gspca_dev;
  569. __u8 reg;
  570. /* register 2 of frame 3/4 contains the clock divider configuring the
  571. no fps according to the formula: 60 / reg. sd->exposure is the
  572. desired exposure time in ms. */
  573. reg = 120 * sd->exposure / 1000;
  574. if (reg < 2)
  575. reg = 2;
  576. else if (reg > 63)
  577. reg = 63;
  578. if (sd->sensor == SENSOR_PAC7302) {
  579. /* On the pac7302 reg2 MUST be a multiple of 3, so round it to
  580. the nearest multiple of 3, except when between 6 and 12? */
  581. if (reg < 6 || reg > 12)
  582. reg = ((reg + 1) / 3) * 3;
  583. reg_w(gspca_dev, 0xff, 0x03); /* page 3 */
  584. reg_w(gspca_dev, 0x02, reg);
  585. } else {
  586. reg_w(gspca_dev, 0xff, 0x04); /* page 4 */
  587. reg_w(gspca_dev, 0x02, reg);
  588. /* Page 1 register 8 must always be 0x08 except when not in
  589. 640x480 mode and Page3/4 reg 2 <= 3 then it must be 9 */
  590. reg_w(gspca_dev, 0xff, 0x01);
  591. if (gspca_dev->cam.cam_mode[(int)gspca_dev->curr_mode].priv &&
  592. reg <= 3)
  593. reg_w(gspca_dev, 0x08, 0x09);
  594. else
  595. reg_w(gspca_dev, 0x08, 0x08);
  596. }
  597. /* load registers to sensor (Bit 0, auto clear) */
  598. reg_w(gspca_dev, 0x11, 0x01);
  599. }
  600. static void sethvflip(struct gspca_dev *gspca_dev)
  601. {
  602. struct sd *sd = (struct sd *) gspca_dev;
  603. __u8 data;
  604. if (sd->sensor == SENSOR_PAC7302) {
  605. reg_w(gspca_dev, 0xff, 0x03); /* page 3 */
  606. data = (sd->hflip ? 0x08 : 0x00)
  607. | (sd->vflip ? 0x04 : 0x00);
  608. } else {
  609. reg_w(gspca_dev, 0xff, 0x04); /* page 4 */
  610. data = (sd->hflip ? 0x04 : 0x00)
  611. | (sd->vflip ? 0x08 : 0x00);
  612. }
  613. reg_w(gspca_dev, 0x21, data);
  614. /* load registers to sensor (Bit 0, auto clear) */
  615. reg_w(gspca_dev, 0x11, 0x01);
  616. }
  617. /* this function is called at probe and resume time */
  618. static int sd_init(struct gspca_dev *gspca_dev)
  619. {
  620. struct sd *sd = (struct sd *) gspca_dev;
  621. if (sd->sensor == SENSOR_PAC7302)
  622. reg_w_seq(gspca_dev, init_7302, sizeof init_7302);
  623. else
  624. reg_w_seq(gspca_dev, init_7311, sizeof init_7311);
  625. return 0;
  626. }
  627. static int sd_start(struct gspca_dev *gspca_dev)
  628. {
  629. struct sd *sd = (struct sd *) gspca_dev;
  630. sd->sof_read = 0;
  631. if (sd->sensor == SENSOR_PAC7302) {
  632. reg_w_var(gspca_dev, start_7302);
  633. setbrightcont(gspca_dev);
  634. setcolors(gspca_dev);
  635. } else {
  636. reg_w_var(gspca_dev, start_7311);
  637. setcontrast(gspca_dev);
  638. }
  639. setgain(gspca_dev);
  640. setexposure(gspca_dev);
  641. sethvflip(gspca_dev);
  642. /* set correct resolution */
  643. switch (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) {
  644. case 2: /* 160x120 pac7311 */
  645. reg_w(gspca_dev, 0xff, 0x01);
  646. reg_w(gspca_dev, 0x17, 0x20);
  647. reg_w(gspca_dev, 0x87, 0x10);
  648. break;
  649. case 1: /* 320x240 pac7311 */
  650. reg_w(gspca_dev, 0xff, 0x01);
  651. reg_w(gspca_dev, 0x17, 0x30);
  652. reg_w(gspca_dev, 0x87, 0x11);
  653. break;
  654. case 0: /* 640x480 */
  655. if (sd->sensor == SENSOR_PAC7302)
  656. break;
  657. reg_w(gspca_dev, 0xff, 0x01);
  658. reg_w(gspca_dev, 0x17, 0x00);
  659. reg_w(gspca_dev, 0x87, 0x12);
  660. break;
  661. }
  662. sd->sof_read = 0;
  663. sd->autogain_ignore_frames = 0;
  664. atomic_set(&sd->avg_lum, -1);
  665. /* start stream */
  666. reg_w(gspca_dev, 0xff, 0x01);
  667. if (sd->sensor == SENSOR_PAC7302)
  668. reg_w(gspca_dev, 0x78, 0x01);
  669. else
  670. reg_w(gspca_dev, 0x78, 0x05);
  671. return 0;
  672. }
  673. static void sd_stopN(struct gspca_dev *gspca_dev)
  674. {
  675. struct sd *sd = (struct sd *) gspca_dev;
  676. if (sd->sensor == SENSOR_PAC7302) {
  677. reg_w(gspca_dev, 0xff, 0x01);
  678. reg_w(gspca_dev, 0x78, 0x00);
  679. reg_w(gspca_dev, 0x78, 0x00);
  680. return;
  681. }
  682. reg_w(gspca_dev, 0xff, 0x04);
  683. reg_w(gspca_dev, 0x27, 0x80);
  684. reg_w(gspca_dev, 0x28, 0xca);
  685. reg_w(gspca_dev, 0x29, 0x53);
  686. reg_w(gspca_dev, 0x2a, 0x0e);
  687. reg_w(gspca_dev, 0xff, 0x01);
  688. reg_w(gspca_dev, 0x3e, 0x20);
  689. reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, Bit_6=LED */
  690. reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, Bit_6=LED */
  691. reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, Bit_6=LED */
  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->sensor == SENSOR_PAC7302) {
  700. reg_w(gspca_dev, 0xff, 0x01);
  701. reg_w(gspca_dev, 0x78, 0x40);
  702. }
  703. }
  704. /* Include pac common sof detection functions */
  705. #include "pac_common.h"
  706. static void do_autogain(struct gspca_dev *gspca_dev)
  707. {
  708. struct sd *sd = (struct sd *) gspca_dev;
  709. int avg_lum = atomic_read(&sd->avg_lum);
  710. int desired_lum, deadzone;
  711. if (avg_lum == -1)
  712. return;
  713. if (sd->sensor == SENSOR_PAC7302) {
  714. desired_lum = 270 + sd->brightness * 4;
  715. /* Hack hack, with the 7202 the first exposure step is
  716. pretty large, so if we're about to make the first
  717. exposure increase make the deadzone large to avoid
  718. oscilating */
  719. if (desired_lum > avg_lum && sd->gain == GAIN_DEF &&
  720. sd->exposure > EXPOSURE_DEF &&
  721. sd->exposure < 42)
  722. deadzone = 90;
  723. else
  724. deadzone = 30;
  725. } else {
  726. desired_lum = 200;
  727. deadzone = 20;
  728. }
  729. if (sd->autogain_ignore_frames > 0)
  730. sd->autogain_ignore_frames--;
  731. else if (gspca_auto_gain_n_exposure(gspca_dev, avg_lum, desired_lum,
  732. deadzone, GAIN_KNEE, EXPOSURE_KNEE))
  733. sd->autogain_ignore_frames = PAC_AUTOGAIN_IGNORE_FRAMES;
  734. }
  735. static const unsigned char pac7311_jpeg_header1[] = {
  736. 0xff, 0xd8, 0xff, 0xc0, 0x00, 0x11, 0x08
  737. };
  738. static const unsigned char pac7311_jpeg_header2[] = {
  739. 0x03, 0x01, 0x21, 0x00, 0x02, 0x11, 0x01, 0x03, 0x11, 0x01, 0xff, 0xda,
  740. 0x00, 0x0c, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03, 0x11, 0x00, 0x3f, 0x00
  741. };
  742. /* this function is run at interrupt level */
  743. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  744. struct gspca_frame *frame, /* target */
  745. __u8 *data, /* isoc packet */
  746. int len) /* iso packet length */
  747. {
  748. struct sd *sd = (struct sd *) gspca_dev;
  749. unsigned char *sof;
  750. sof = pac_find_sof(gspca_dev, data, len);
  751. if (sof) {
  752. unsigned char tmpbuf[4];
  753. int n, lum_offset, footer_length;
  754. if (sd->sensor == SENSOR_PAC7302) {
  755. /* 6 bytes after the FF D9 EOF marker a number of lumination
  756. bytes are send corresponding to different parts of the
  757. image, the 14th and 15th byte after the EOF seem to
  758. correspond to the center of the image */
  759. lum_offset = 61 + sizeof pac_sof_marker;
  760. footer_length = 74;
  761. } else {
  762. lum_offset = 24 + sizeof pac_sof_marker;
  763. footer_length = 26;
  764. }
  765. /* Finish decoding current frame */
  766. n = (sof - data) - (footer_length + sizeof pac_sof_marker);
  767. if (n < 0) {
  768. frame->data_end += n;
  769. n = 0;
  770. }
  771. frame = gspca_frame_add(gspca_dev, INTER_PACKET, frame,
  772. data, n);
  773. if (gspca_dev->last_packet_type != DISCARD_PACKET &&
  774. frame->data_end[-2] == 0xff &&
  775. frame->data_end[-1] == 0xd9)
  776. frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
  777. NULL, 0);
  778. n = sof - data;
  779. len -= n;
  780. data = sof;
  781. /* Get average lumination */
  782. if (gspca_dev->last_packet_type == LAST_PACKET &&
  783. n >= lum_offset)
  784. atomic_set(&sd->avg_lum, data[-lum_offset] +
  785. data[-lum_offset + 1]);
  786. else
  787. atomic_set(&sd->avg_lum, -1);
  788. /* Start the new frame with the jpeg header */
  789. gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
  790. pac7311_jpeg_header1, sizeof(pac7311_jpeg_header1));
  791. if (sd->sensor == SENSOR_PAC7302) {
  792. /* The PAC7302 has the image rotated 90 degrees */
  793. tmpbuf[0] = gspca_dev->width >> 8;
  794. tmpbuf[1] = gspca_dev->width & 0xff;
  795. tmpbuf[2] = gspca_dev->height >> 8;
  796. tmpbuf[3] = gspca_dev->height & 0xff;
  797. } else {
  798. tmpbuf[0] = gspca_dev->height >> 8;
  799. tmpbuf[1] = gspca_dev->height & 0xff;
  800. tmpbuf[2] = gspca_dev->width >> 8;
  801. tmpbuf[3] = gspca_dev->width & 0xff;
  802. }
  803. gspca_frame_add(gspca_dev, INTER_PACKET, frame, tmpbuf, 4);
  804. gspca_frame_add(gspca_dev, INTER_PACKET, frame,
  805. pac7311_jpeg_header2, sizeof(pac7311_jpeg_header2));
  806. }
  807. gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
  808. }
  809. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  810. {
  811. struct sd *sd = (struct sd *) gspca_dev;
  812. sd->brightness = val;
  813. if (gspca_dev->streaming)
  814. setbrightcont(gspca_dev);
  815. return 0;
  816. }
  817. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  818. {
  819. struct sd *sd = (struct sd *) gspca_dev;
  820. *val = sd->brightness;
  821. return 0;
  822. }
  823. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  824. {
  825. struct sd *sd = (struct sd *) gspca_dev;
  826. sd->contrast = val;
  827. if (gspca_dev->streaming) {
  828. if (sd->sensor == SENSOR_PAC7302)
  829. setbrightcont(gspca_dev);
  830. else
  831. setcontrast(gspca_dev);
  832. }
  833. return 0;
  834. }
  835. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  836. {
  837. struct sd *sd = (struct sd *) gspca_dev;
  838. *val = sd->contrast;
  839. return 0;
  840. }
  841. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
  842. {
  843. struct sd *sd = (struct sd *) gspca_dev;
  844. sd->colors = val;
  845. if (gspca_dev->streaming)
  846. setcolors(gspca_dev);
  847. return 0;
  848. }
  849. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
  850. {
  851. struct sd *sd = (struct sd *) gspca_dev;
  852. *val = sd->colors;
  853. return 0;
  854. }
  855. static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
  856. {
  857. struct sd *sd = (struct sd *) gspca_dev;
  858. sd->gain = val;
  859. if (gspca_dev->streaming)
  860. setgain(gspca_dev);
  861. return 0;
  862. }
  863. static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
  864. {
  865. struct sd *sd = (struct sd *) gspca_dev;
  866. *val = sd->gain;
  867. return 0;
  868. }
  869. static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
  870. {
  871. struct sd *sd = (struct sd *) gspca_dev;
  872. sd->exposure = val;
  873. if (gspca_dev->streaming)
  874. setexposure(gspca_dev);
  875. return 0;
  876. }
  877. static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
  878. {
  879. struct sd *sd = (struct sd *) gspca_dev;
  880. *val = sd->exposure;
  881. return 0;
  882. }
  883. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
  884. {
  885. struct sd *sd = (struct sd *) gspca_dev;
  886. sd->autogain = val;
  887. /* when switching to autogain set defaults to make sure
  888. we are on a valid point of the autogain gain /
  889. exposure knee graph, and give this change time to
  890. take effect before doing autogain. */
  891. if (sd->autogain) {
  892. sd->exposure = EXPOSURE_DEF;
  893. sd->gain = GAIN_DEF;
  894. if (gspca_dev->streaming) {
  895. sd->autogain_ignore_frames =
  896. PAC_AUTOGAIN_IGNORE_FRAMES;
  897. setexposure(gspca_dev);
  898. setgain(gspca_dev);
  899. }
  900. }
  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. static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val)
  910. {
  911. struct sd *sd = (struct sd *) gspca_dev;
  912. sd->hflip = val;
  913. if (gspca_dev->streaming)
  914. sethvflip(gspca_dev);
  915. return 0;
  916. }
  917. static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val)
  918. {
  919. struct sd *sd = (struct sd *) gspca_dev;
  920. *val = sd->hflip;
  921. return 0;
  922. }
  923. static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
  924. {
  925. struct sd *sd = (struct sd *) gspca_dev;
  926. sd->vflip = val;
  927. if (gspca_dev->streaming)
  928. sethvflip(gspca_dev);
  929. return 0;
  930. }
  931. static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
  932. {
  933. struct sd *sd = (struct sd *) gspca_dev;
  934. *val = sd->vflip;
  935. return 0;
  936. }
  937. /* sub-driver description */
  938. static struct sd_desc sd_desc = {
  939. .name = MODULE_NAME,
  940. .ctrls = sd_ctrls,
  941. .nctrls = ARRAY_SIZE(sd_ctrls),
  942. .config = sd_config,
  943. .init = sd_init,
  944. .start = sd_start,
  945. .stopN = sd_stopN,
  946. .stop0 = sd_stop0,
  947. .pkt_scan = sd_pkt_scan,
  948. .dq_callback = do_autogain,
  949. };
  950. /* -- module initialisation -- */
  951. static __devinitdata struct usb_device_id device_table[] = {
  952. {USB_DEVICE(0x06f8, 0x3009), .driver_info = SENSOR_PAC7302},
  953. {USB_DEVICE(0x093a, 0x2600), .driver_info = SENSOR_PAC7311},
  954. {USB_DEVICE(0x093a, 0x2601), .driver_info = SENSOR_PAC7311},
  955. {USB_DEVICE(0x093a, 0x2603), .driver_info = SENSOR_PAC7311},
  956. {USB_DEVICE(0x093a, 0x2608), .driver_info = SENSOR_PAC7311},
  957. {USB_DEVICE(0x093a, 0x260e), .driver_info = SENSOR_PAC7311},
  958. {USB_DEVICE(0x093a, 0x260f), .driver_info = SENSOR_PAC7311},
  959. {USB_DEVICE(0x093a, 0x2620), .driver_info = SENSOR_PAC7302},
  960. {USB_DEVICE(0x093a, 0x2621), .driver_info = SENSOR_PAC7302},
  961. {USB_DEVICE(0x093a, 0x2622), .driver_info = SENSOR_PAC7302},
  962. {USB_DEVICE(0x093a, 0x2624), .driver_info = SENSOR_PAC7302},
  963. {USB_DEVICE(0x093a, 0x2626), .driver_info = SENSOR_PAC7302},
  964. {USB_DEVICE(0x093a, 0x2629), .driver_info = SENSOR_PAC7302},
  965. {USB_DEVICE(0x093a, 0x262a), .driver_info = SENSOR_PAC7302},
  966. {USB_DEVICE(0x093a, 0x262c), .driver_info = SENSOR_PAC7302},
  967. {}
  968. };
  969. MODULE_DEVICE_TABLE(usb, device_table);
  970. /* -- device connect -- */
  971. static int sd_probe(struct usb_interface *intf,
  972. const struct usb_device_id *id)
  973. {
  974. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  975. THIS_MODULE);
  976. }
  977. static struct usb_driver sd_driver = {
  978. .name = MODULE_NAME,
  979. .id_table = device_table,
  980. .probe = sd_probe,
  981. .disconnect = gspca_disconnect,
  982. #ifdef CONFIG_PM
  983. .suspend = gspca_suspend,
  984. .resume = gspca_resume,
  985. #endif
  986. };
  987. /* -- module insert / remove -- */
  988. static int __init sd_mod_init(void)
  989. {
  990. int ret;
  991. ret = usb_register(&sd_driver);
  992. if (ret < 0)
  993. return ret;
  994. PDEBUG(D_PROBE, "registered");
  995. return 0;
  996. }
  997. static void __exit sd_mod_exit(void)
  998. {
  999. usb_deregister(&sd_driver);
  1000. PDEBUG(D_PROBE, "deregistered");
  1001. }
  1002. module_init(sd_mod_init);
  1003. module_exit(sd_mod_exit);