ov534.c 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812
  1. /*
  2. * ov534 gspca driver
  3. *
  4. * Copyright (C) 2008 Antonio Ospite <ospite@studenti.unina.it>
  5. * Copyright (C) 2008 Jim Paris <jim@jtan.com>
  6. * Copyright (C) 2009 Jean-Francois Moine http://moinejf.free.fr
  7. *
  8. * Based on a prototype written by Mark Ferrell <majortrips@gmail.com>
  9. * USB protocol reverse engineered by Jim Paris <jim@jtan.com>
  10. * https://jim.sh/svn/jim/devl/playstation/ps3/eye/test/
  11. *
  12. * PS3 Eye camera enhanced by Richard Kaswy http://kaswy.free.fr
  13. * PS3 Eye camera, brightness, contrast, hue, AWB control added
  14. * by Max Thrun <bear24rw@gmail.com>
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 2 of the License, or
  19. * any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  29. */
  30. #define MODULE_NAME "ov534"
  31. #include "gspca.h"
  32. #define OV534_REG_ADDRESS 0xf1 /* sensor address */
  33. #define OV534_REG_SUBADDR 0xf2
  34. #define OV534_REG_WRITE 0xf3
  35. #define OV534_REG_READ 0xf4
  36. #define OV534_REG_OPERATION 0xf5
  37. #define OV534_REG_STATUS 0xf6
  38. #define OV534_OP_WRITE_3 0x37
  39. #define OV534_OP_WRITE_2 0x33
  40. #define OV534_OP_READ_2 0xf9
  41. #define CTRL_TIMEOUT 500
  42. MODULE_AUTHOR("Antonio Ospite <ospite@studenti.unina.it>");
  43. MODULE_DESCRIPTION("GSPCA/OV534 USB Camera Driver");
  44. MODULE_LICENSE("GPL");
  45. /* specific webcam descriptor */
  46. struct sd {
  47. struct gspca_dev gspca_dev; /* !! must be the first item */
  48. __u32 last_pts;
  49. u16 last_fid;
  50. u8 frame_rate;
  51. u8 brightness;
  52. u8 contrast;
  53. u8 gain;
  54. u8 exposure;
  55. u8 redblc;
  56. u8 blueblc;
  57. u8 hue;
  58. u8 autogain;
  59. u8 awb;
  60. u8 sharpness;
  61. u8 hflip;
  62. u8 vflip;
  63. u8 sensor;
  64. #define SENSOR_OV772X 0
  65. #define SENSOR_OV965X 1
  66. };
  67. /* V4L2 controls supported by the driver */
  68. static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
  69. static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
  70. static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
  71. static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);
  72. static int sd_setredblc(struct gspca_dev *gspca_dev, __s32 val);
  73. static int sd_getredblc(struct gspca_dev *gspca_dev, __s32 *val);
  74. static int sd_setblueblc(struct gspca_dev *gspca_dev, __s32 val);
  75. static int sd_getblueblc(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_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
  79. static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
  80. static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
  81. static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val);
  82. static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
  83. static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
  84. static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val);
  85. static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val);
  86. static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val);
  87. static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val);
  88. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
  89. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
  90. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
  91. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
  92. static struct ctrl sd_ctrls_ov772x[] = {
  93. {
  94. {
  95. .id = V4L2_CID_BRIGHTNESS,
  96. .type = V4L2_CTRL_TYPE_INTEGER,
  97. .name = "Brightness",
  98. .minimum = 0,
  99. .maximum = 255,
  100. .step = 1,
  101. #define BRIGHTNESS_DEF 20
  102. .default_value = BRIGHTNESS_DEF,
  103. },
  104. .set = sd_setbrightness,
  105. .get = sd_getbrightness,
  106. },
  107. {
  108. {
  109. .id = V4L2_CID_CONTRAST,
  110. .type = V4L2_CTRL_TYPE_INTEGER,
  111. .name = "Contrast",
  112. .minimum = 0,
  113. .maximum = 255,
  114. .step = 1,
  115. #define CONTRAST_DEF 37
  116. .default_value = CONTRAST_DEF,
  117. },
  118. .set = sd_setcontrast,
  119. .get = sd_getcontrast,
  120. },
  121. {
  122. {
  123. .id = V4L2_CID_GAIN,
  124. .type = V4L2_CTRL_TYPE_INTEGER,
  125. .name = "Main Gain",
  126. .minimum = 0,
  127. .maximum = 63,
  128. .step = 1,
  129. #define GAIN_DEF 20
  130. .default_value = GAIN_DEF,
  131. },
  132. .set = sd_setgain,
  133. .get = sd_getgain,
  134. },
  135. {
  136. {
  137. .id = V4L2_CID_EXPOSURE,
  138. .type = V4L2_CTRL_TYPE_INTEGER,
  139. .name = "Exposure",
  140. .minimum = 0,
  141. .maximum = 255,
  142. .step = 1,
  143. #define EXPO_DEF 120
  144. .default_value = EXPO_DEF,
  145. },
  146. .set = sd_setexposure,
  147. .get = sd_getexposure,
  148. },
  149. {
  150. {
  151. .id = V4L2_CID_RED_BALANCE,
  152. .type = V4L2_CTRL_TYPE_INTEGER,
  153. .name = "Red Balance",
  154. .minimum = 0,
  155. .maximum = 255,
  156. .step = 1,
  157. #define RED_BALANCE_DEF 128
  158. .default_value = RED_BALANCE_DEF,
  159. },
  160. .set = sd_setredblc,
  161. .get = sd_getredblc,
  162. },
  163. {
  164. {
  165. .id = V4L2_CID_BLUE_BALANCE,
  166. .type = V4L2_CTRL_TYPE_INTEGER,
  167. .name = "Blue Balance",
  168. .minimum = 0,
  169. .maximum = 255,
  170. .step = 1,
  171. #define BLUE_BALANCE_DEF 128
  172. .default_value = BLUE_BALANCE_DEF,
  173. },
  174. .set = sd_setblueblc,
  175. .get = sd_getblueblc,
  176. },
  177. {
  178. {
  179. .id = V4L2_CID_HUE,
  180. .type = V4L2_CTRL_TYPE_INTEGER,
  181. .name = "Hue",
  182. .minimum = 0,
  183. .maximum = 255,
  184. .step = 1,
  185. #define HUE_DEF 143
  186. .default_value = HUE_DEF,
  187. },
  188. .set = sd_sethue,
  189. .get = sd_gethue,
  190. },
  191. {
  192. {
  193. .id = V4L2_CID_AUTOGAIN,
  194. .type = V4L2_CTRL_TYPE_BOOLEAN,
  195. .name = "Autogain",
  196. .minimum = 0,
  197. .maximum = 1,
  198. .step = 1,
  199. #define AUTOGAIN_DEF 0
  200. .default_value = AUTOGAIN_DEF,
  201. },
  202. .set = sd_setautogain,
  203. .get = sd_getautogain,
  204. },
  205. {
  206. {
  207. .id = V4L2_CID_AUTO_WHITE_BALANCE,
  208. .type = V4L2_CTRL_TYPE_BOOLEAN,
  209. .name = "Auto White Balance",
  210. .minimum = 0,
  211. .maximum = 1,
  212. .step = 1,
  213. #define AWB_DEF 0
  214. .default_value = AWB_DEF,
  215. },
  216. .set = sd_setawb,
  217. .get = sd_getawb,
  218. },
  219. {
  220. {
  221. .id = V4L2_CID_SHARPNESS,
  222. .type = V4L2_CTRL_TYPE_INTEGER,
  223. .name = "Sharpness",
  224. .minimum = 0,
  225. .maximum = 63,
  226. .step = 1,
  227. #define SHARPNESS_DEF 0
  228. .default_value = SHARPNESS_DEF,
  229. },
  230. .set = sd_setsharpness,
  231. .get = sd_getsharpness,
  232. },
  233. {
  234. {
  235. .id = V4L2_CID_HFLIP,
  236. .type = V4L2_CTRL_TYPE_BOOLEAN,
  237. .name = "HFlip",
  238. .minimum = 0,
  239. .maximum = 1,
  240. .step = 1,
  241. #define HFLIP_DEF 0
  242. .default_value = HFLIP_DEF,
  243. },
  244. .set = sd_sethflip,
  245. .get = sd_gethflip,
  246. },
  247. {
  248. {
  249. .id = V4L2_CID_VFLIP,
  250. .type = V4L2_CTRL_TYPE_BOOLEAN,
  251. .name = "VFlip",
  252. .minimum = 0,
  253. .maximum = 1,
  254. .step = 1,
  255. #define VFLIP_DEF 0
  256. .default_value = VFLIP_DEF,
  257. },
  258. .set = sd_setvflip,
  259. .get = sd_getvflip,
  260. },
  261. };
  262. static struct ctrl sd_ctrls_ov965x[] = {
  263. };
  264. static const struct v4l2_pix_format vga_yuyv_mode[] = {
  265. {320, 240, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
  266. .bytesperline = 320 * 2,
  267. .sizeimage = 320 * 240 * 2,
  268. .colorspace = V4L2_COLORSPACE_SRGB,
  269. .priv = 1},
  270. {640, 480, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
  271. .bytesperline = 640 * 2,
  272. .sizeimage = 640 * 480 * 2,
  273. .colorspace = V4L2_COLORSPACE_SRGB,
  274. .priv = 0},
  275. };
  276. static const struct v4l2_pix_format vga_jpeg_mode[] = {
  277. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  278. .bytesperline = 320,
  279. .sizeimage = 320 * 240 * 3 / 8 + 590,
  280. .colorspace = V4L2_COLORSPACE_JPEG,
  281. .priv = 1},
  282. {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  283. .bytesperline = 640,
  284. .sizeimage = 640 * 480 * 3 / 8 + 590,
  285. .colorspace = V4L2_COLORSPACE_JPEG,
  286. .priv = 0},
  287. };
  288. static const u8 bridge_init_ov772x[][2] = {
  289. { 0xc2, 0x0c },
  290. { 0x88, 0xf8 },
  291. { 0xc3, 0x69 },
  292. { 0x89, 0xff },
  293. { 0x76, 0x03 },
  294. { 0x92, 0x01 },
  295. { 0x93, 0x18 },
  296. { 0x94, 0x10 },
  297. { 0x95, 0x10 },
  298. { 0xe2, 0x00 },
  299. { 0xe7, 0x3e },
  300. { 0x96, 0x00 },
  301. { 0x97, 0x20 },
  302. { 0x97, 0x20 },
  303. { 0x97, 0x20 },
  304. { 0x97, 0x0a },
  305. { 0x97, 0x3f },
  306. { 0x97, 0x4a },
  307. { 0x97, 0x20 },
  308. { 0x97, 0x15 },
  309. { 0x97, 0x0b },
  310. { 0x8e, 0x40 },
  311. { 0x1f, 0x81 },
  312. { 0x34, 0x05 },
  313. { 0xe3, 0x04 },
  314. { 0x88, 0x00 },
  315. { 0x89, 0x00 },
  316. { 0x76, 0x00 },
  317. { 0xe7, 0x2e },
  318. { 0x31, 0xf9 },
  319. { 0x25, 0x42 },
  320. { 0x21, 0xf0 },
  321. { 0x1c, 0x00 },
  322. { 0x1d, 0x40 },
  323. { 0x1d, 0x02 }, /* payload size 0x0200 * 4 = 2048 bytes */
  324. { 0x1d, 0x00 }, /* payload size */
  325. { 0x1d, 0x02 }, /* frame size 0x025800 * 4 = 614400 */
  326. { 0x1d, 0x58 }, /* frame size */
  327. { 0x1d, 0x00 }, /* frame size */
  328. { 0x1c, 0x0a },
  329. { 0x1d, 0x08 }, /* turn on UVC header */
  330. { 0x1d, 0x0e }, /* .. */
  331. { 0x8d, 0x1c },
  332. { 0x8e, 0x80 },
  333. { 0xe5, 0x04 },
  334. { 0xc0, 0x50 },
  335. { 0xc1, 0x3c },
  336. { 0xc2, 0x0c },
  337. };
  338. static const u8 sensor_init_ov772x[][2] = {
  339. { 0x12, 0x80 },
  340. { 0x11, 0x01 },
  341. /*fixme: better have a delay?*/
  342. { 0x11, 0x01 },
  343. { 0x11, 0x01 },
  344. { 0x11, 0x01 },
  345. { 0x11, 0x01 },
  346. { 0x11, 0x01 },
  347. { 0x11, 0x01 },
  348. { 0x11, 0x01 },
  349. { 0x11, 0x01 },
  350. { 0x11, 0x01 },
  351. { 0x11, 0x01 },
  352. { 0x3d, 0x03 },
  353. { 0x17, 0x26 },
  354. { 0x18, 0xa0 },
  355. { 0x19, 0x07 },
  356. { 0x1a, 0xf0 },
  357. { 0x32, 0x00 },
  358. { 0x29, 0xa0 },
  359. { 0x2c, 0xf0 },
  360. { 0x65, 0x20 },
  361. { 0x11, 0x01 },
  362. { 0x42, 0x7f },
  363. { 0x63, 0xaa }, /* AWB - was e0 */
  364. { 0x64, 0xff },
  365. { 0x66, 0x00 },
  366. { 0x13, 0xf0 }, /* com8 */
  367. { 0x0d, 0x41 },
  368. { 0x0f, 0xc5 },
  369. { 0x14, 0x11 },
  370. { 0x22, 0x7f },
  371. { 0x23, 0x03 },
  372. { 0x24, 0x40 },
  373. { 0x25, 0x30 },
  374. { 0x26, 0xa1 },
  375. { 0x2a, 0x00 },
  376. { 0x2b, 0x00 },
  377. { 0x6b, 0xaa },
  378. { 0x13, 0xff }, /* AWB */
  379. { 0x90, 0x05 },
  380. { 0x91, 0x01 },
  381. { 0x92, 0x03 },
  382. { 0x93, 0x00 },
  383. { 0x94, 0x60 },
  384. { 0x95, 0x3c },
  385. { 0x96, 0x24 },
  386. { 0x97, 0x1e },
  387. { 0x98, 0x62 },
  388. { 0x99, 0x80 },
  389. { 0x9a, 0x1e },
  390. { 0x9b, 0x08 },
  391. { 0x9c, 0x20 },
  392. { 0x9e, 0x81 },
  393. { 0xa6, 0x04 },
  394. { 0x7e, 0x0c },
  395. { 0x7f, 0x16 },
  396. { 0x80, 0x2a },
  397. { 0x81, 0x4e },
  398. { 0x82, 0x61 },
  399. { 0x83, 0x6f },
  400. { 0x84, 0x7b },
  401. { 0x85, 0x86 },
  402. { 0x86, 0x8e },
  403. { 0x87, 0x97 },
  404. { 0x88, 0xa4 },
  405. { 0x89, 0xaf },
  406. { 0x8a, 0xc5 },
  407. { 0x8b, 0xd7 },
  408. { 0x8c, 0xe8 },
  409. { 0x8d, 0x20 },
  410. { 0x0c, 0x90 },
  411. { 0x2b, 0x00 },
  412. { 0x22, 0x7f },
  413. { 0x23, 0x03 },
  414. { 0x11, 0x01 },
  415. { 0x0c, 0xd0 },
  416. { 0x64, 0xff },
  417. { 0x0d, 0x41 },
  418. { 0x14, 0x41 },
  419. { 0x0e, 0xcd },
  420. { 0xac, 0xbf },
  421. { 0x8e, 0x00 }, /* De-noise threshold */
  422. { 0x0c, 0xd0 }
  423. };
  424. static const u8 bridge_start_ov772x_vga[][2] = {
  425. {0x1c, 0x00},
  426. {0x1d, 0x40},
  427. {0x1d, 0x02},
  428. {0x1d, 0x00},
  429. {0x1d, 0x02},
  430. {0x1d, 0x58},
  431. {0x1d, 0x00},
  432. {0xc0, 0x50},
  433. {0xc1, 0x3c},
  434. };
  435. static const u8 sensor_start_ov772x_vga[][2] = {
  436. {0x12, 0x00},
  437. {0x17, 0x26},
  438. {0x18, 0xa0},
  439. {0x19, 0x07},
  440. {0x1a, 0xf0},
  441. {0x29, 0xa0},
  442. {0x2c, 0xf0},
  443. {0x65, 0x20},
  444. };
  445. static const u8 bridge_start_ov772x_qvga[][2] = {
  446. {0x1c, 0x00},
  447. {0x1d, 0x40},
  448. {0x1d, 0x02},
  449. {0x1d, 0x00},
  450. {0x1d, 0x01},
  451. {0x1d, 0x4b},
  452. {0x1d, 0x00},
  453. {0xc0, 0x28},
  454. {0xc1, 0x1e},
  455. };
  456. static const u8 sensor_start_ov772x_qvga[][2] = {
  457. {0x12, 0x40},
  458. {0x17, 0x3f},
  459. {0x18, 0x50},
  460. {0x19, 0x03},
  461. {0x1a, 0x78},
  462. {0x29, 0x50},
  463. {0x2c, 0x78},
  464. {0x65, 0x2f},
  465. };
  466. static const u8 bridge_init_ov965x[][2] = {
  467. {0x88, 0xf8},
  468. {0x89, 0xff},
  469. {0x76, 0x03},
  470. {0x92, 0x03},
  471. {0x95, 0x10},
  472. {0xe2, 0x00},
  473. {0xe7, 0x3e},
  474. {0x8d, 0x1c},
  475. {0x8e, 0x00},
  476. {0x8f, 0x00},
  477. {0x1f, 0x00},
  478. {0xc3, 0xf9},
  479. {0x89, 0xff},
  480. {0x88, 0xf8},
  481. {0x76, 0x03},
  482. {0x92, 0x01},
  483. {0x93, 0x18},
  484. {0x1c, 0x0a},
  485. {0x1d, 0x48},
  486. {0xc0, 0x50},
  487. {0xc1, 0x3c},
  488. {0x34, 0x05},
  489. {0xc2, 0x0c},
  490. {0xc3, 0xf9},
  491. {0x34, 0x05},
  492. {0xe7, 0x2e},
  493. {0x31, 0xf9},
  494. {0x35, 0x02},
  495. {0xd9, 0x10},
  496. {0x25, 0x42},
  497. {0x94, 0x11},
  498. };
  499. static const u8 sensor_init_ov965x[][2] = {
  500. {0x12, 0x80}, /* com7 - SSCB reset */
  501. {0x00, 0x00}, /* gain */
  502. {0x01, 0x80}, /* blue */
  503. {0x02, 0x80}, /* red */
  504. {0x03, 0x1b}, /* vref */
  505. {0x04, 0x03}, /* com1 - exposure low bits */
  506. {0x0b, 0x57}, /* ver */
  507. {0x0e, 0x61}, /* com5 */
  508. {0x0f, 0x42}, /* com6 */
  509. {0x11, 0x00}, /* clkrc */
  510. {0x12, 0x02}, /* com7 - 15fps VGA YUYV */
  511. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  512. {0x14, 0x28}, /* com9 */
  513. {0x16, 0x24}, /* reg16 */
  514. {0x17, 0x1d}, /* hstart*/
  515. {0x18, 0xbd}, /* hstop */
  516. {0x19, 0x01}, /* vstrt */
  517. {0x1a, 0x81}, /* vstop*/
  518. {0x1e, 0x04}, /* mvfp */
  519. {0x24, 0x3c}, /* aew */
  520. {0x25, 0x36}, /* aeb */
  521. {0x26, 0x71}, /* vpt */
  522. {0x27, 0x08}, /* bbias */
  523. {0x28, 0x08}, /* gbbias */
  524. {0x29, 0x15}, /* gr com */
  525. {0x2a, 0x00}, /* exhch */
  526. {0x2b, 0x00}, /* exhcl */
  527. {0x2c, 0x08}, /* rbias */
  528. {0x32, 0xff}, /* href */
  529. {0x33, 0x00}, /* chlf */
  530. {0x34, 0x3f}, /* aref1 */
  531. {0x35, 0x00}, /* aref2 */
  532. {0x36, 0xf8}, /* aref3 */
  533. {0x38, 0x72}, /* adc2 */
  534. {0x39, 0x57}, /* aref4 */
  535. {0x3a, 0x80}, /* tslb - yuyv */
  536. {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
  537. {0x3d, 0x99}, /* com13 */
  538. {0x3f, 0xc1}, /* edge */
  539. {0x40, 0xc0}, /* com15 */
  540. {0x41, 0x40}, /* com16 */
  541. {0x42, 0xc0}, /* com17 */
  542. {0x43, 0x0a}, /* rsvd */
  543. {0x44, 0xf0},
  544. {0x45, 0x46},
  545. {0x46, 0x62},
  546. {0x47, 0x2a},
  547. {0x48, 0x3c},
  548. {0x4a, 0xfc},
  549. {0x4b, 0xfc},
  550. {0x4c, 0x7f},
  551. {0x4d, 0x7f},
  552. {0x4e, 0x7f},
  553. {0x4f, 0x98}, /* matrix */
  554. {0x50, 0x98},
  555. {0x51, 0x00},
  556. {0x52, 0x28},
  557. {0x53, 0x70},
  558. {0x54, 0x98},
  559. {0x58, 0x1a}, /* matrix coef sign */
  560. {0x59, 0x85}, /* AWB control */
  561. {0x5a, 0xa9},
  562. {0x5b, 0x64},
  563. {0x5c, 0x84},
  564. {0x5d, 0x53},
  565. {0x5e, 0x0e},
  566. {0x5f, 0xf0}, /* AWB blue limit */
  567. {0x60, 0xf0}, /* AWB red limit */
  568. {0x61, 0xf0}, /* AWB green limit */
  569. {0x62, 0x00}, /* lcc1 */
  570. {0x63, 0x00}, /* lcc2 */
  571. {0x64, 0x02}, /* lcc3 */
  572. {0x65, 0x16}, /* lcc4 */
  573. {0x66, 0x01}, /* lcc5 */
  574. {0x69, 0x02}, /* hv */
  575. {0x6b, 0x5a}, /* dbvl */
  576. {0x6c, 0x04},
  577. {0x6d, 0x55},
  578. {0x6e, 0x00},
  579. {0x6f, 0x9d},
  580. {0x70, 0x21}, /* dnsth */
  581. {0x71, 0x78},
  582. {0x72, 0x00}, /* poidx */
  583. {0x73, 0x01}, /* pckdv */
  584. {0x74, 0x3a}, /* xindx */
  585. {0x75, 0x35}, /* yindx */
  586. {0x76, 0x01},
  587. {0x77, 0x02},
  588. {0x7a, 0x12}, /* gamma curve */
  589. {0x7b, 0x08},
  590. {0x7c, 0x16},
  591. {0x7d, 0x30},
  592. {0x7e, 0x5e},
  593. {0x7f, 0x72},
  594. {0x80, 0x82},
  595. {0x81, 0x8e},
  596. {0x82, 0x9a},
  597. {0x83, 0xa4},
  598. {0x84, 0xac},
  599. {0x85, 0xb8},
  600. {0x86, 0xc3},
  601. {0x87, 0xd6},
  602. {0x88, 0xe6},
  603. {0x89, 0xf2},
  604. {0x8a, 0x03},
  605. {0x8c, 0x89}, /* com19 */
  606. {0x14, 0x28}, /* com9 */
  607. {0x90, 0x7d},
  608. {0x91, 0x7b},
  609. {0x9d, 0x03}, /* lcc6 */
  610. {0x9e, 0x04}, /* lcc7 */
  611. {0x9f, 0x7a},
  612. {0xa0, 0x79},
  613. {0xa1, 0x40}, /* aechm */
  614. {0xa4, 0x50}, /* com21 */
  615. {0xa5, 0x68}, /* com26 */
  616. {0xa6, 0x4a}, /* AWB green */
  617. {0xa8, 0xc1}, /* refa8 */
  618. {0xa9, 0xef}, /* refa9 */
  619. {0xaa, 0x92},
  620. {0xab, 0x04},
  621. {0xac, 0x80}, /* black level control */
  622. {0xad, 0x80},
  623. {0xae, 0x80},
  624. {0xaf, 0x80},
  625. {0xb2, 0xf2},
  626. {0xb3, 0x20},
  627. {0xb4, 0x20}, /* ctrlb4 */
  628. {0xb5, 0x00},
  629. {0xb6, 0xaf},
  630. {0xbb, 0xae},
  631. {0xbc, 0x7f}, /* ADC channel offsets */
  632. {0xdb, 0x7f},
  633. {0xbe, 0x7f},
  634. {0xbf, 0x7f},
  635. {0xc0, 0xe2},
  636. {0xc1, 0xc0},
  637. {0xc2, 0x01},
  638. {0xc3, 0x4e},
  639. {0xc6, 0x85},
  640. {0xc7, 0x80}, /* com24 */
  641. {0xc9, 0xe0},
  642. {0xca, 0xe8},
  643. {0xcb, 0xf0},
  644. {0xcc, 0xd8},
  645. {0xcd, 0xf1},
  646. {0x4f, 0x98},
  647. {0x50, 0x98},
  648. {0x51, 0x00},
  649. {0x52, 0x28},
  650. {0x53, 0x70},
  651. {0x54, 0x98},
  652. {0x58, 0x1a},
  653. {0xff, 0x41}, /* read 41, write ff 00 */
  654. {0x41, 0x40}, /* com16 */
  655. {0xc5, 0x03}, /* 60 Hz banding filter */
  656. {0x6a, 0x02}, /* 50 Hz banding filter */
  657. {0x12, 0x62}, /* com7 - 30fps VGA YUV */
  658. {0x36, 0xfa}, /* aref3 */
  659. {0x69, 0x0a}, /* hv */
  660. {0x8c, 0x89}, /* com22 */
  661. {0x14, 0x28}, /* com9 */
  662. {0x3e, 0x0c},
  663. {0x41, 0x40}, /* com16 */
  664. {0x72, 0x00},
  665. {0x73, 0x00},
  666. {0x74, 0x3a},
  667. {0x75, 0x35},
  668. {0x76, 0x01},
  669. {0xc7, 0x80},
  670. {0x03, 0x12}, /* vref */
  671. {0x17, 0x16}, /* hstart */
  672. {0x18, 0x02}, /* hstop */
  673. {0x19, 0x01}, /* vstrt */
  674. {0x1a, 0x3d}, /* vstop */
  675. {0x32, 0xff}, /* href */
  676. {0xc0, 0xaa},
  677. };
  678. static const u8 bridge_init_ov965x_2[][2] = {
  679. {0x94, 0xaa},
  680. {0xf1, 0x60},
  681. {0xe5, 0x04},
  682. {0xc0, 0x50},
  683. {0xc1, 0x3c},
  684. {0x8c, 0x00},
  685. {0x8d, 0x1c},
  686. {0x34, 0x05},
  687. {0xc2, 0x0c},
  688. {0xc3, 0xf9},
  689. {0xda, 0x01},
  690. {0x50, 0x00},
  691. {0x51, 0xa0},
  692. {0x52, 0x3c},
  693. {0x53, 0x00},
  694. {0x54, 0x00},
  695. {0x55, 0x00}, /* brightness */
  696. {0x57, 0x00}, /* contrast 2 */
  697. {0x5c, 0x00},
  698. {0x5a, 0xa0},
  699. {0x5b, 0x78},
  700. {0x35, 0x02},
  701. {0xd9, 0x10},
  702. {0x94, 0x11},
  703. };
  704. static const u8 sensor_init_ov965x_2[][2] = {
  705. {0x3b, 0xc4},
  706. {0x1e, 0x04}, /* mvfp */
  707. {0x13, 0xe0}, /* com8 */
  708. {0x00, 0x00}, /* gain */
  709. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  710. {0x11, 0x03}, /* clkrc */
  711. {0x6b, 0x5a}, /* dblv */
  712. {0x6a, 0x05},
  713. {0xc5, 0x07},
  714. {0xa2, 0x4b},
  715. {0xa3, 0x3e},
  716. {0x2d, 0x00},
  717. {0xff, 0x42}, /* read 42, write ff 00 */
  718. {0x42, 0xc0},
  719. {0x2d, 0x00},
  720. {0xff, 0x42}, /* read 42, write ff 00 */
  721. {0x42, 0xc1},
  722. {0x3f, 0x01},
  723. {0xff, 0x42}, /* read 42, write ff 00 */
  724. {0x42, 0xc1},
  725. {0x4f, 0x98},
  726. {0x50, 0x98},
  727. {0x51, 0x00},
  728. {0x52, 0x28},
  729. {0x53, 0x70},
  730. {0x54, 0x98},
  731. {0x58, 0x1a},
  732. {0xff, 0x41}, /* read 41, write ff 00 */
  733. {0x41, 0x40}, /* com16 */
  734. {0x56, 0x40},
  735. {0x55, 0x8f},
  736. {0x10, 0x25}, /* aech - exposure high bits */
  737. {0xff, 0x13}, /* read 13, write ff 00 */
  738. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  739. };
  740. static const u8 sensor_start_ov965x[][2] = {
  741. {0x12, 0x62}, /* com7 - 30fps VGA YUV */
  742. {0x36, 0xfa}, /* aref3 */
  743. {0x69, 0x0a}, /* hv */
  744. {0x8c, 0x89}, /* com22 */
  745. {0x14, 0x28}, /* com9 */
  746. {0x3e, 0x0c}, /* com14 */
  747. {0x41, 0x40}, /* com16 */
  748. {0x72, 0x00},
  749. {0x73, 0x00},
  750. {0x74, 0x3a},
  751. {0x75, 0x35},
  752. {0x76, 0x01},
  753. {0xc7, 0x80}, /* com24 */
  754. {0x03, 0x12}, /* vref */
  755. {0x17, 0x16}, /* hstart */
  756. {0x18, 0x02}, /* hstop */
  757. {0x19, 0x01}, /* vstrt */
  758. {0x1a, 0x3d}, /* vstop */
  759. {0x32, 0xff}, /* href */
  760. {0xc0, 0xaa},
  761. {}
  762. };
  763. static const u8 bridge_start_ov965x[][2] = {
  764. {0x94, 0xaa},
  765. {0xf1, 0x60},
  766. {0xe5, 0x04},
  767. {0xc0, 0x50},
  768. {0xc1, 0x3c},
  769. {0x8c, 0x00},
  770. {0x8d, 0x1c},
  771. {0x34, 0x05},
  772. {}
  773. };
  774. static const u8 bridge_start_ov965x_vga[][2] = {
  775. {0xc2, 0x0c},
  776. {0xc3, 0xf9},
  777. {0xda, 0x01},
  778. {0x50, 0x00},
  779. {0x51, 0xa0},
  780. {0x52, 0x3c},
  781. {0x53, 0x00},
  782. {0x54, 0x00},
  783. {0x55, 0x00},
  784. {0x57, 0x00},
  785. {0x5c, 0x00},
  786. {0x5a, 0xa0},
  787. {0x5b, 0x78},
  788. {0x35, 0x02},
  789. {0xd9, 0x10},
  790. {0x94, 0x11},
  791. {}
  792. };
  793. static const u8 bridge_start_ov965x_cif[][2] = {
  794. {0xc2, 0x4c},
  795. {0xc3, 0xf9},
  796. {0xda, 0x00},
  797. {0x50, 0x00},
  798. {0x51, 0xa0},
  799. {0x52, 0x78},
  800. {0x53, 0x00},
  801. {0x54, 0x00},
  802. {0x55, 0x00},
  803. {0x57, 0x00},
  804. {0x5c, 0x00},
  805. {0x5a, 0x50},
  806. {0x5b, 0x3c},
  807. {0x35, 0x02},
  808. {0xd9, 0x10},
  809. {0x94, 0x11},
  810. {}
  811. };
  812. static const u8 sensor_start_ov965x_vga[][2] = {
  813. {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
  814. {0x1e, 0x04}, /* mvfp */
  815. {0x13, 0xe0}, /* com8 */
  816. {0x00, 0x00},
  817. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  818. {0x11, 0x03}, /* clkrc */
  819. {0x6b, 0x5a}, /* dblv */
  820. {0x6a, 0x05}, /* 50 Hz banding filter */
  821. {0xc5, 0x07}, /* 60 Hz banding filter */
  822. {0xa2, 0x4b}, /* bd50 */
  823. {0xa3, 0x3e}, /* bd60 */
  824. {0x2d, 0x00}, /* advfl */
  825. {}
  826. };
  827. static const u8 sensor_start_ov965x_cif[][2] = {
  828. {0x3b, 0xe4}, /* com11 - night mode 1/4 frame rate */
  829. {0x1e, 0x04}, /* mvfp */
  830. {0x13, 0xe0}, /* com8 */
  831. {0x00, 0x00},
  832. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  833. {0x11, 0x01}, /* clkrc */
  834. {0x6b, 0x5a}, /* dblv */
  835. {0x6a, 0x02}, /* 50 Hz banding filter */
  836. {0xc5, 0x03}, /* 60 Hz banding filter */
  837. {0xa2, 0x96}, /* bd50 */
  838. {0xa3, 0x7d}, /* bd60 */
  839. {0xff, 0x13}, /* read 13, write ff 00 */
  840. {0x13, 0xe7},
  841. {0x3a, 0x80}, /* tslb - yuyv */
  842. {}
  843. };
  844. static const u8 sensor_start_ov965x_2[][2] = {
  845. {0xff, 0x42}, /* read 42, write ff 00 */
  846. {0x42, 0xc1}, /* com17 - 50 Hz filter */
  847. {}
  848. };
  849. static void ov534_reg_write(struct gspca_dev *gspca_dev, u16 reg, u8 val)
  850. {
  851. struct usb_device *udev = gspca_dev->dev;
  852. int ret;
  853. PDEBUG(D_USBO, "reg=0x%04x, val=0%02x", reg, val);
  854. gspca_dev->usb_buf[0] = val;
  855. ret = usb_control_msg(udev,
  856. usb_sndctrlpipe(udev, 0),
  857. 0x01,
  858. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  859. 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
  860. if (ret < 0)
  861. PDEBUG(D_ERR, "write failed");
  862. }
  863. static u8 ov534_reg_read(struct gspca_dev *gspca_dev, u16 reg)
  864. {
  865. struct usb_device *udev = gspca_dev->dev;
  866. int ret;
  867. ret = usb_control_msg(udev,
  868. usb_rcvctrlpipe(udev, 0),
  869. 0x01,
  870. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  871. 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
  872. PDEBUG(D_USBI, "reg=0x%04x, data=0x%02x", reg, gspca_dev->usb_buf[0]);
  873. if (ret < 0)
  874. PDEBUG(D_ERR, "read failed");
  875. return gspca_dev->usb_buf[0];
  876. }
  877. /* Two bits control LED: 0x21 bit 7 and 0x23 bit 7.
  878. * (direction and output)? */
  879. static void ov534_set_led(struct gspca_dev *gspca_dev, int status)
  880. {
  881. u8 data;
  882. PDEBUG(D_CONF, "led status: %d", status);
  883. data = ov534_reg_read(gspca_dev, 0x21);
  884. data |= 0x80;
  885. ov534_reg_write(gspca_dev, 0x21, data);
  886. data = ov534_reg_read(gspca_dev, 0x23);
  887. if (status)
  888. data |= 0x80;
  889. else
  890. data &= ~0x80;
  891. ov534_reg_write(gspca_dev, 0x23, data);
  892. if (!status) {
  893. data = ov534_reg_read(gspca_dev, 0x21);
  894. data &= ~0x80;
  895. ov534_reg_write(gspca_dev, 0x21, data);
  896. }
  897. }
  898. static int sccb_check_status(struct gspca_dev *gspca_dev)
  899. {
  900. u8 data;
  901. int i;
  902. for (i = 0; i < 5; i++) {
  903. data = ov534_reg_read(gspca_dev, OV534_REG_STATUS);
  904. switch (data) {
  905. case 0x00:
  906. return 1;
  907. case 0x04:
  908. return 0;
  909. case 0x03:
  910. break;
  911. default:
  912. PDEBUG(D_ERR, "sccb status 0x%02x, attempt %d/5",
  913. data, i + 1);
  914. }
  915. }
  916. return 0;
  917. }
  918. static void sccb_reg_write(struct gspca_dev *gspca_dev, u8 reg, u8 val)
  919. {
  920. PDEBUG(D_USBO, "reg: 0x%02x, val: 0x%02x", reg, val);
  921. ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg);
  922. ov534_reg_write(gspca_dev, OV534_REG_WRITE, val);
  923. ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_3);
  924. if (!sccb_check_status(gspca_dev))
  925. PDEBUG(D_ERR, "sccb_reg_write failed");
  926. }
  927. static u8 sccb_reg_read(struct gspca_dev *gspca_dev, u16 reg)
  928. {
  929. ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg);
  930. ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_2);
  931. if (!sccb_check_status(gspca_dev))
  932. PDEBUG(D_ERR, "sccb_reg_read failed 1");
  933. ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_READ_2);
  934. if (!sccb_check_status(gspca_dev))
  935. PDEBUG(D_ERR, "sccb_reg_read failed 2");
  936. return ov534_reg_read(gspca_dev, OV534_REG_READ);
  937. }
  938. /* output a bridge sequence (reg - val) */
  939. static void reg_w_array(struct gspca_dev *gspca_dev,
  940. const u8 (*data)[2], int len)
  941. {
  942. while (--len >= 0) {
  943. ov534_reg_write(gspca_dev, (*data)[0], (*data)[1]);
  944. data++;
  945. }
  946. }
  947. /* output a sensor sequence (reg - val) */
  948. static void sccb_w_array(struct gspca_dev *gspca_dev,
  949. const u8 (*data)[2], int len)
  950. {
  951. while (--len >= 0) {
  952. if ((*data)[0] != 0xff) {
  953. sccb_reg_write(gspca_dev, (*data)[0], (*data)[1]);
  954. } else {
  955. sccb_reg_read(gspca_dev, (*data)[1]);
  956. sccb_reg_write(gspca_dev, 0xff, 0x00);
  957. }
  958. data++;
  959. }
  960. }
  961. /* ov772x specific controls */
  962. static void set_frame_rate(struct gspca_dev *gspca_dev)
  963. {
  964. struct sd *sd = (struct sd *) gspca_dev;
  965. int i;
  966. struct rate_s {
  967. u8 fps;
  968. u8 r11;
  969. u8 r0d;
  970. u8 re5;
  971. };
  972. const struct rate_s *r;
  973. static const struct rate_s rate_0[] = { /* 640x480 */
  974. {60, 0x01, 0xc1, 0x04},
  975. {50, 0x01, 0x41, 0x02},
  976. {40, 0x02, 0xc1, 0x04},
  977. {30, 0x04, 0x81, 0x02},
  978. {15, 0x03, 0x41, 0x04},
  979. };
  980. static const struct rate_s rate_1[] = { /* 320x240 */
  981. {125, 0x02, 0x81, 0x02},
  982. {100, 0x02, 0xc1, 0x04},
  983. {75, 0x03, 0xc1, 0x04},
  984. {60, 0x04, 0xc1, 0x04},
  985. {50, 0x02, 0x41, 0x04},
  986. {40, 0x03, 0x41, 0x04},
  987. {30, 0x04, 0x41, 0x04},
  988. };
  989. if (gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv == 0) {
  990. r = rate_0;
  991. i = ARRAY_SIZE(rate_0);
  992. } else {
  993. r = rate_1;
  994. i = ARRAY_SIZE(rate_1);
  995. }
  996. while (--i > 0) {
  997. if (sd->frame_rate >= r->fps)
  998. break;
  999. r++;
  1000. }
  1001. sccb_reg_write(gspca_dev, 0x11, r->r11);
  1002. sccb_reg_write(gspca_dev, 0x0d, r->r0d);
  1003. ov534_reg_write(gspca_dev, 0xe5, r->re5);
  1004. PDEBUG(D_PROBE, "frame_rate: %d", r->fps);
  1005. }
  1006. static void setbrightness(struct gspca_dev *gspca_dev)
  1007. {
  1008. struct sd *sd = (struct sd *) gspca_dev;
  1009. sccb_reg_write(gspca_dev, 0x9B, sd->brightness);
  1010. }
  1011. static void setcontrast(struct gspca_dev *gspca_dev)
  1012. {
  1013. struct sd *sd = (struct sd *) gspca_dev;
  1014. sccb_reg_write(gspca_dev, 0x9C, sd->contrast);
  1015. }
  1016. static void setgain(struct gspca_dev *gspca_dev)
  1017. {
  1018. struct sd *sd = (struct sd *) gspca_dev;
  1019. u8 val;
  1020. val = sd->gain;
  1021. switch (val & 0x30) {
  1022. case 0x00:
  1023. val &= 0x0f;
  1024. break;
  1025. case 0x10:
  1026. val &= 0x0f;
  1027. val |= 0x30;
  1028. break;
  1029. case 0x20:
  1030. val &= 0x0f;
  1031. val |= 0x70;
  1032. break;
  1033. default:
  1034. /* case 0x30: */
  1035. val &= 0x0f;
  1036. val |= 0xf0;
  1037. break;
  1038. }
  1039. sccb_reg_write(gspca_dev, 0x00, val);
  1040. }
  1041. static void setexposure(struct gspca_dev *gspca_dev)
  1042. {
  1043. struct sd *sd = (struct sd *) gspca_dev;
  1044. u8 val;
  1045. val = sd->exposure;
  1046. sccb_reg_write(gspca_dev, 0x08, val >> 7);
  1047. sccb_reg_write(gspca_dev, 0x10, val << 1);
  1048. }
  1049. static void setredblc(struct gspca_dev *gspca_dev)
  1050. {
  1051. struct sd *sd = (struct sd *) gspca_dev;
  1052. sccb_reg_write(gspca_dev, 0x43, sd->redblc);
  1053. }
  1054. static void setblueblc(struct gspca_dev *gspca_dev)
  1055. {
  1056. struct sd *sd = (struct sd *) gspca_dev;
  1057. sccb_reg_write(gspca_dev, 0x42, sd->blueblc);
  1058. }
  1059. static void sethue(struct gspca_dev *gspca_dev)
  1060. {
  1061. struct sd *sd = (struct sd *) gspca_dev;
  1062. sccb_reg_write(gspca_dev, 0x01, sd->hue);
  1063. }
  1064. static void setautogain(struct gspca_dev *gspca_dev)
  1065. {
  1066. struct sd *sd = (struct sd *) gspca_dev;
  1067. if (sd->autogain) {
  1068. sccb_reg_write(gspca_dev, 0x13, 0xf7); /* AGC,AEC,AWB ON */
  1069. sccb_reg_write(gspca_dev, 0x64,
  1070. sccb_reg_read(gspca_dev, 0x64) | 0x03);
  1071. } else {
  1072. sccb_reg_write(gspca_dev, 0x13, 0xf0); /* AGC,AEC,AWB OFF */
  1073. sccb_reg_write(gspca_dev, 0x64,
  1074. sccb_reg_read(gspca_dev, 0x64) & 0xfc);
  1075. }
  1076. }
  1077. static void setawb(struct gspca_dev *gspca_dev)
  1078. {
  1079. struct sd *sd = (struct sd *) gspca_dev;
  1080. if (sd->awb)
  1081. sccb_reg_write(gspca_dev, 0x63, 0xe0); /* AWB on */
  1082. else
  1083. sccb_reg_write(gspca_dev, 0x63, 0xaa); /* AWB off */
  1084. }
  1085. static void setsharpness(struct gspca_dev *gspca_dev)
  1086. {
  1087. struct sd *sd = (struct sd *) gspca_dev;
  1088. u8 val;
  1089. val = sd->sharpness;
  1090. sccb_reg_write(gspca_dev, 0x91, val); /* vga noise */
  1091. sccb_reg_write(gspca_dev, 0x8e, val); /* qvga noise */
  1092. }
  1093. static void sethflip(struct gspca_dev *gspca_dev)
  1094. {
  1095. struct sd *sd = (struct sd *) gspca_dev;
  1096. if (sd->hflip == 0)
  1097. sccb_reg_write(gspca_dev, 0x0c,
  1098. sccb_reg_read(gspca_dev, 0x0c) | 0x40);
  1099. else
  1100. sccb_reg_write(gspca_dev, 0x0c,
  1101. sccb_reg_read(gspca_dev, 0x0c) & 0xbf);
  1102. }
  1103. static void setvflip(struct gspca_dev *gspca_dev)
  1104. {
  1105. struct sd *sd = (struct sd *) gspca_dev;
  1106. if (sd->vflip == 0)
  1107. sccb_reg_write(gspca_dev, 0x0c,
  1108. sccb_reg_read(gspca_dev, 0x0c) | 0x80);
  1109. else
  1110. sccb_reg_write(gspca_dev, 0x0c,
  1111. sccb_reg_read(gspca_dev, 0x0c) & 0x7f);
  1112. }
  1113. /* this function is called at probe time */
  1114. static int sd_config(struct gspca_dev *gspca_dev,
  1115. const struct usb_device_id *id)
  1116. {
  1117. struct sd *sd = (struct sd *) gspca_dev;
  1118. struct cam *cam;
  1119. sd->sensor = id->driver_info;
  1120. cam = &gspca_dev->cam;
  1121. if (sd->sensor == SENSOR_OV772X) {
  1122. cam->cam_mode = vga_yuyv_mode;
  1123. cam->nmodes = ARRAY_SIZE(vga_yuyv_mode);
  1124. cam->bulk = 1;
  1125. cam->bulk_size = 16384;
  1126. cam->bulk_nurbs = 2;
  1127. } else { /* ov965x */
  1128. cam->cam_mode = vga_jpeg_mode;
  1129. cam->nmodes = ARRAY_SIZE(vga_jpeg_mode);
  1130. }
  1131. sd->frame_rate = 30;
  1132. sd->brightness = BRIGHTNESS_DEF;
  1133. sd->contrast = CONTRAST_DEF;
  1134. sd->gain = GAIN_DEF;
  1135. sd->exposure = EXPO_DEF;
  1136. sd->redblc = RED_BALANCE_DEF;
  1137. sd->blueblc = BLUE_BALANCE_DEF;
  1138. sd->hue = HUE_DEF;
  1139. #if AUTOGAIN_DEF != 0
  1140. sd->autogain = AUTOGAIN_DEF;
  1141. #endif
  1142. #if AWB_DEF != 0
  1143. sd->awb = AWB_DEF
  1144. #endif
  1145. sd->sharpness = SHARPNESS_DEF;
  1146. #if HFLIP_DEF != 0
  1147. sd->hflip = HFLIP_DEF;
  1148. #endif
  1149. #if VFLIP_DEF != 0
  1150. sd->vflip = VFLIP_DEF;
  1151. #endif
  1152. return 0;
  1153. }
  1154. /* this function is called at probe and resume time */
  1155. static int sd_init(struct gspca_dev *gspca_dev)
  1156. {
  1157. struct sd *sd = (struct sd *) gspca_dev;
  1158. u16 sensor_id;
  1159. static const u8 sensor_addr[2] = {
  1160. 0x42, /* 0 SENSOR_OV772X */
  1161. 0x60, /* 1 SENSOR_OV965X */
  1162. };
  1163. /* reset bridge */
  1164. ov534_reg_write(gspca_dev, 0xe7, 0x3a);
  1165. ov534_reg_write(gspca_dev, 0xe0, 0x08);
  1166. msleep(100);
  1167. /* initialize the sensor address */
  1168. ov534_reg_write(gspca_dev, OV534_REG_ADDRESS,
  1169. sensor_addr[sd->sensor]);
  1170. /* reset sensor */
  1171. sccb_reg_write(gspca_dev, 0x12, 0x80);
  1172. msleep(10);
  1173. /* probe the sensor */
  1174. sccb_reg_read(gspca_dev, 0x0a);
  1175. sensor_id = sccb_reg_read(gspca_dev, 0x0a) << 8;
  1176. sccb_reg_read(gspca_dev, 0x0b);
  1177. sensor_id |= sccb_reg_read(gspca_dev, 0x0b);
  1178. PDEBUG(D_PROBE, "Sensor ID: %04x", sensor_id);
  1179. /* initialize */
  1180. switch (sd->sensor) {
  1181. case SENSOR_OV772X:
  1182. reg_w_array(gspca_dev, bridge_init_ov772x,
  1183. ARRAY_SIZE(bridge_init_ov772x));
  1184. ov534_set_led(gspca_dev, 1);
  1185. sccb_w_array(gspca_dev, sensor_init_ov772x,
  1186. ARRAY_SIZE(sensor_init_ov772x));
  1187. ov534_reg_write(gspca_dev, 0xe0, 0x09);
  1188. ov534_set_led(gspca_dev, 0);
  1189. set_frame_rate(gspca_dev);
  1190. break;
  1191. default:
  1192. /* case SENSOR_OV965X: */
  1193. reg_w_array(gspca_dev, bridge_init_ov965x,
  1194. ARRAY_SIZE(bridge_init_ov965x));
  1195. sccb_w_array(gspca_dev, sensor_init_ov965x,
  1196. ARRAY_SIZE(sensor_init_ov965x));
  1197. reg_w_array(gspca_dev, bridge_init_ov965x_2,
  1198. ARRAY_SIZE(bridge_init_ov965x_2));
  1199. sccb_w_array(gspca_dev, sensor_init_ov965x_2,
  1200. ARRAY_SIZE(sensor_init_ov965x_2));
  1201. ov534_reg_write(gspca_dev, 0xe0, 0x00);
  1202. ov534_reg_write(gspca_dev, 0xe0, 0x01);
  1203. ov534_set_led(gspca_dev, 0);
  1204. ov534_reg_write(gspca_dev, 0xe0, 0x00);
  1205. }
  1206. return 0;
  1207. }
  1208. static int sd_start_ov772x(struct gspca_dev *gspca_dev)
  1209. {
  1210. int mode;
  1211. mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
  1212. if (mode != 0) { /* 320x240 */
  1213. reg_w_array(gspca_dev, bridge_start_ov772x_qvga,
  1214. ARRAY_SIZE(bridge_start_ov772x_qvga));
  1215. sccb_w_array(gspca_dev, sensor_start_ov772x_qvga,
  1216. ARRAY_SIZE(sensor_start_ov772x_qvga));
  1217. } else { /* 640x480 */
  1218. reg_w_array(gspca_dev, bridge_start_ov772x_vga,
  1219. ARRAY_SIZE(bridge_start_ov772x_vga));
  1220. sccb_w_array(gspca_dev, sensor_start_ov772x_vga,
  1221. ARRAY_SIZE(sensor_start_ov772x_vga));
  1222. }
  1223. set_frame_rate(gspca_dev);
  1224. setautogain(gspca_dev);
  1225. setawb(gspca_dev);
  1226. setgain(gspca_dev);
  1227. setredblc(gspca_dev);
  1228. setblueblc(gspca_dev);
  1229. sethue(gspca_dev);
  1230. setexposure(gspca_dev);
  1231. setbrightness(gspca_dev);
  1232. setcontrast(gspca_dev);
  1233. setsharpness(gspca_dev);
  1234. setvflip(gspca_dev);
  1235. sethflip(gspca_dev);
  1236. ov534_set_led(gspca_dev, 1);
  1237. ov534_reg_write(gspca_dev, 0xe0, 0x00);
  1238. return 0;
  1239. }
  1240. static int sd_start_ov965x(struct gspca_dev *gspca_dev)
  1241. {
  1242. int mode;
  1243. sccb_w_array(gspca_dev, sensor_start_ov965x,
  1244. ARRAY_SIZE(sensor_start_ov965x));
  1245. reg_w_array(gspca_dev, bridge_start_ov965x,
  1246. ARRAY_SIZE(bridge_start_ov965x));
  1247. mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
  1248. if (mode != 0) { /* 320x240 */
  1249. reg_w_array(gspca_dev, bridge_start_ov965x_cif,
  1250. ARRAY_SIZE(bridge_start_ov965x_cif));
  1251. sccb_w_array(gspca_dev, sensor_start_ov965x_cif,
  1252. ARRAY_SIZE(sensor_start_ov965x_cif));
  1253. } else { /* 640x480 */
  1254. reg_w_array(gspca_dev, bridge_start_ov965x_vga,
  1255. ARRAY_SIZE(bridge_start_ov965x_vga));
  1256. sccb_w_array(gspca_dev, sensor_start_ov965x_vga,
  1257. ARRAY_SIZE(sensor_start_ov965x_vga));
  1258. }
  1259. sccb_w_array(gspca_dev, sensor_start_ov965x_2,
  1260. ARRAY_SIZE(sensor_start_ov965x_2));
  1261. ov534_reg_write(gspca_dev, 0xe0, 0x00);
  1262. ov534_reg_write(gspca_dev, 0xe0, 0x00);
  1263. ov534_set_led(gspca_dev, 1);
  1264. return 0;
  1265. }
  1266. static void sd_stopN_ov772x(struct gspca_dev *gspca_dev)
  1267. {
  1268. ov534_reg_write(gspca_dev, 0xe0, 0x09);
  1269. ov534_set_led(gspca_dev, 0);
  1270. }
  1271. static void sd_stopN_ov965x(struct gspca_dev *gspca_dev)
  1272. {
  1273. ov534_reg_write(gspca_dev, 0xe0, 0x01);
  1274. ov534_set_led(gspca_dev, 0);
  1275. ov534_reg_write(gspca_dev, 0xe0, 0x00);
  1276. }
  1277. /* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */
  1278. #define UVC_STREAM_EOH (1 << 7)
  1279. #define UVC_STREAM_ERR (1 << 6)
  1280. #define UVC_STREAM_STI (1 << 5)
  1281. #define UVC_STREAM_RES (1 << 4)
  1282. #define UVC_STREAM_SCR (1 << 3)
  1283. #define UVC_STREAM_PTS (1 << 2)
  1284. #define UVC_STREAM_EOF (1 << 1)
  1285. #define UVC_STREAM_FID (1 << 0)
  1286. static void sd_pkt_scan(struct gspca_dev *gspca_dev, struct gspca_frame *frame,
  1287. __u8 *data, int len)
  1288. {
  1289. struct sd *sd = (struct sd *) gspca_dev;
  1290. __u32 this_pts;
  1291. u16 this_fid;
  1292. int remaining_len = len;
  1293. int payload_len;
  1294. payload_len = gspca_dev->cam.bulk ? 2048 : 2040;
  1295. do {
  1296. len = min(remaining_len, payload_len);
  1297. /* Payloads are prefixed with a UVC-style header. We
  1298. consider a frame to start when the FID toggles, or the PTS
  1299. changes. A frame ends when EOF is set, and we've received
  1300. the correct number of bytes. */
  1301. /* Verify UVC header. Header length is always 12 */
  1302. if (data[0] != 12 || len < 12) {
  1303. PDEBUG(D_PACK, "bad header");
  1304. goto discard;
  1305. }
  1306. /* Check errors */
  1307. if (data[1] & UVC_STREAM_ERR) {
  1308. PDEBUG(D_PACK, "payload error");
  1309. goto discard;
  1310. }
  1311. /* Extract PTS and FID */
  1312. if (!(data[1] & UVC_STREAM_PTS)) {
  1313. PDEBUG(D_PACK, "PTS not present");
  1314. goto discard;
  1315. }
  1316. this_pts = (data[5] << 24) | (data[4] << 16)
  1317. | (data[3] << 8) | data[2];
  1318. this_fid = (data[1] & UVC_STREAM_FID) ? 1 : 0;
  1319. /* If PTS or FID has changed, start a new frame. */
  1320. if (this_pts != sd->last_pts || this_fid != sd->last_fid) {
  1321. if (gspca_dev->last_packet_type == INTER_PACKET)
  1322. frame = gspca_frame_add(gspca_dev,
  1323. LAST_PACKET, frame,
  1324. NULL, 0);
  1325. sd->last_pts = this_pts;
  1326. sd->last_fid = this_fid;
  1327. gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
  1328. data + 12, len - 12);
  1329. /* If this packet is marked as EOF, end the frame */
  1330. } else if (data[1] & UVC_STREAM_EOF) {
  1331. sd->last_pts = 0;
  1332. frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
  1333. data + 12, len - 12);
  1334. } else {
  1335. /* Add the data from this payload */
  1336. gspca_frame_add(gspca_dev, INTER_PACKET, frame,
  1337. data + 12, len - 12);
  1338. }
  1339. /* Done this payload */
  1340. goto scan_next;
  1341. discard:
  1342. /* Discard data until a new frame starts. */
  1343. gspca_frame_add(gspca_dev, DISCARD_PACKET, frame, NULL, 0);
  1344. scan_next:
  1345. remaining_len -= len;
  1346. data += len;
  1347. } while (remaining_len > 0);
  1348. }
  1349. /* ov772x controls */
  1350. static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
  1351. {
  1352. struct sd *sd = (struct sd *) gspca_dev;
  1353. sd->gain = val;
  1354. if (gspca_dev->streaming)
  1355. setgain(gspca_dev);
  1356. return 0;
  1357. }
  1358. static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
  1359. {
  1360. struct sd *sd = (struct sd *) gspca_dev;
  1361. *val = sd->gain;
  1362. return 0;
  1363. }
  1364. static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
  1365. {
  1366. struct sd *sd = (struct sd *) gspca_dev;
  1367. sd->exposure = val;
  1368. if (gspca_dev->streaming)
  1369. setexposure(gspca_dev);
  1370. return 0;
  1371. }
  1372. static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
  1373. {
  1374. struct sd *sd = (struct sd *) gspca_dev;
  1375. *val = sd->exposure;
  1376. return 0;
  1377. }
  1378. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  1379. {
  1380. struct sd *sd = (struct sd *) gspca_dev;
  1381. sd->brightness = val;
  1382. if (gspca_dev->streaming)
  1383. setbrightness(gspca_dev);
  1384. return 0;
  1385. }
  1386. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  1387. {
  1388. struct sd *sd = (struct sd *) gspca_dev;
  1389. *val = sd->brightness;
  1390. return 0;
  1391. }
  1392. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  1393. {
  1394. struct sd *sd = (struct sd *) gspca_dev;
  1395. sd->contrast = val;
  1396. if (gspca_dev->streaming)
  1397. setcontrast(gspca_dev);
  1398. return 0;
  1399. }
  1400. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  1401. {
  1402. struct sd *sd = (struct sd *) gspca_dev;
  1403. *val = sd->contrast;
  1404. return 0;
  1405. }
  1406. static int sd_setredblc(struct gspca_dev *gspca_dev, __s32 val)
  1407. {
  1408. struct sd *sd = (struct sd *) gspca_dev;
  1409. sd->redblc = val;
  1410. if (gspca_dev->streaming)
  1411. setredblc(gspca_dev);
  1412. return 0;
  1413. }
  1414. static int sd_getredblc(struct gspca_dev *gspca_dev, __s32 *val)
  1415. {
  1416. struct sd *sd = (struct sd *) gspca_dev;
  1417. *val = sd->redblc;
  1418. return 0;
  1419. }
  1420. static int sd_setblueblc(struct gspca_dev *gspca_dev, __s32 val)
  1421. {
  1422. struct sd *sd = (struct sd *) gspca_dev;
  1423. sd->blueblc = val;
  1424. if (gspca_dev->streaming)
  1425. setblueblc(gspca_dev);
  1426. return 0;
  1427. }
  1428. static int sd_getblueblc(struct gspca_dev *gspca_dev, __s32 *val)
  1429. {
  1430. struct sd *sd = (struct sd *) gspca_dev;
  1431. *val = sd->blueblc;
  1432. return 0;
  1433. }
  1434. static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val)
  1435. {
  1436. struct sd *sd = (struct sd *) gspca_dev;
  1437. sd->hue = val;
  1438. if (gspca_dev->streaming)
  1439. sethue(gspca_dev);
  1440. return 0;
  1441. }
  1442. static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val)
  1443. {
  1444. struct sd *sd = (struct sd *) gspca_dev;
  1445. *val = sd->hue;
  1446. return 0;
  1447. }
  1448. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
  1449. {
  1450. struct sd *sd = (struct sd *) gspca_dev;
  1451. sd->autogain = val;
  1452. if (gspca_dev->streaming)
  1453. setautogain(gspca_dev);
  1454. return 0;
  1455. }
  1456. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
  1457. {
  1458. struct sd *sd = (struct sd *) gspca_dev;
  1459. *val = sd->autogain;
  1460. return 0;
  1461. }
  1462. static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val)
  1463. {
  1464. struct sd *sd = (struct sd *) gspca_dev;
  1465. sd->awb = val;
  1466. if (gspca_dev->streaming)
  1467. setawb(gspca_dev);
  1468. return 0;
  1469. }
  1470. static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val)
  1471. {
  1472. struct sd *sd = (struct sd *) gspca_dev;
  1473. *val = sd->awb;
  1474. return 0;
  1475. }
  1476. static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
  1477. {
  1478. struct sd *sd = (struct sd *) gspca_dev;
  1479. sd->sharpness = val;
  1480. if (gspca_dev->streaming)
  1481. setsharpness(gspca_dev);
  1482. return 0;
  1483. }
  1484. static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
  1485. {
  1486. struct sd *sd = (struct sd *) gspca_dev;
  1487. *val = sd->sharpness;
  1488. return 0;
  1489. }
  1490. static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val)
  1491. {
  1492. struct sd *sd = (struct sd *) gspca_dev;
  1493. sd->hflip = val;
  1494. if (gspca_dev->streaming)
  1495. sethflip(gspca_dev);
  1496. return 0;
  1497. }
  1498. static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val)
  1499. {
  1500. struct sd *sd = (struct sd *) gspca_dev;
  1501. *val = sd->hflip;
  1502. return 0;
  1503. }
  1504. static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
  1505. {
  1506. struct sd *sd = (struct sd *) gspca_dev;
  1507. sd->vflip = val;
  1508. if (gspca_dev->streaming)
  1509. setvflip(gspca_dev);
  1510. return 0;
  1511. }
  1512. static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
  1513. {
  1514. struct sd *sd = (struct sd *) gspca_dev;
  1515. *val = sd->vflip;
  1516. return 0;
  1517. }
  1518. /* get stream parameters (framerate) */
  1519. static int sd_get_streamparm(struct gspca_dev *gspca_dev,
  1520. struct v4l2_streamparm *parm)
  1521. {
  1522. struct v4l2_captureparm *cp = &parm->parm.capture;
  1523. struct v4l2_fract *tpf = &cp->timeperframe;
  1524. struct sd *sd = (struct sd *) gspca_dev;
  1525. if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1526. return -EINVAL;
  1527. cp->capability |= V4L2_CAP_TIMEPERFRAME;
  1528. tpf->numerator = 1;
  1529. tpf->denominator = sd->frame_rate;
  1530. return 0;
  1531. }
  1532. /* set stream parameters (framerate) */
  1533. static int sd_set_streamparm(struct gspca_dev *gspca_dev,
  1534. struct v4l2_streamparm *parm)
  1535. {
  1536. struct v4l2_captureparm *cp = &parm->parm.capture;
  1537. struct v4l2_fract *tpf = &cp->timeperframe;
  1538. struct sd *sd = (struct sd *) gspca_dev;
  1539. if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1540. return -EINVAL;
  1541. /* Set requested framerate */
  1542. sd->frame_rate = tpf->denominator / tpf->numerator;
  1543. if (gspca_dev->streaming && sd->sensor == SENSOR_OV772X)
  1544. set_frame_rate(gspca_dev);
  1545. /* Return the actual framerate */
  1546. tpf->numerator = 1;
  1547. tpf->denominator = sd->frame_rate;
  1548. return 0;
  1549. }
  1550. /* sub-driver description */
  1551. static const struct sd_desc sd_desc_ov772x = {
  1552. .name = MODULE_NAME,
  1553. .ctrls = sd_ctrls_ov772x,
  1554. .nctrls = ARRAY_SIZE(sd_ctrls_ov772x),
  1555. .config = sd_config,
  1556. .init = sd_init,
  1557. .start = sd_start_ov772x,
  1558. .stopN = sd_stopN_ov772x,
  1559. .pkt_scan = sd_pkt_scan,
  1560. .get_streamparm = sd_get_streamparm,
  1561. .set_streamparm = sd_set_streamparm,
  1562. };
  1563. static const struct sd_desc sd_desc_ov965x = {
  1564. .name = MODULE_NAME,
  1565. .ctrls = sd_ctrls_ov965x,
  1566. .nctrls = ARRAY_SIZE(sd_ctrls_ov965x),
  1567. .config = sd_config,
  1568. .init = sd_init,
  1569. .start = sd_start_ov965x,
  1570. .stopN = sd_stopN_ov965x,
  1571. .pkt_scan = sd_pkt_scan,
  1572. .get_streamparm = sd_get_streamparm,
  1573. .set_streamparm = sd_set_streamparm,
  1574. };
  1575. /* -- module initialisation -- */
  1576. static const __devinitdata struct usb_device_id device_table[] = {
  1577. {USB_DEVICE(0x06f8, 0x3003), .driver_info = SENSOR_OV965X},
  1578. {USB_DEVICE(0x1415, 0x2000), .driver_info = SENSOR_OV772X},
  1579. {}
  1580. };
  1581. MODULE_DEVICE_TABLE(usb, device_table);
  1582. /* -- device connect -- */
  1583. static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id)
  1584. {
  1585. return gspca_dev_probe(intf, id,
  1586. id->driver_info == SENSOR_OV772X
  1587. ? &sd_desc_ov772x
  1588. : &sd_desc_ov965x,
  1589. sizeof(struct sd),
  1590. THIS_MODULE);
  1591. }
  1592. static struct usb_driver sd_driver = {
  1593. .name = MODULE_NAME,
  1594. .id_table = device_table,
  1595. .probe = sd_probe,
  1596. .disconnect = gspca_disconnect,
  1597. #ifdef CONFIG_PM
  1598. .suspend = gspca_suspend,
  1599. .resume = gspca_resume,
  1600. #endif
  1601. };
  1602. /* -- module insert / remove -- */
  1603. static int __init sd_mod_init(void)
  1604. {
  1605. int ret;
  1606. ret = usb_register(&sd_driver);
  1607. if (ret < 0)
  1608. return ret;
  1609. PDEBUG(D_PROBE, "registered");
  1610. return 0;
  1611. }
  1612. static void __exit sd_mod_exit(void)
  1613. {
  1614. usb_deregister(&sd_driver);
  1615. PDEBUG(D_PROBE, "deregistered");
  1616. }
  1617. module_init(sd_mod_init);
  1618. module_exit(sd_mod_exit);