ov534_9.c 41 KB

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