ov534_9.c 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829
  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. gspca_dbg(gspca_dev, D_USBO, "reg_w [%04x] = %02x\n", 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. gspca_dbg(gspca_dev, D_USBI, "reg_r [%04x] -> %02x\n",
  1099. reg, gspca_dev->usb_buf[0]);
  1100. if (ret < 0) {
  1101. pr_err("reg_r err %d\n", ret);
  1102. gspca_dev->usb_err = ret;
  1103. }
  1104. return gspca_dev->usb_buf[0];
  1105. }
  1106. static int sccb_check_status(struct gspca_dev *gspca_dev)
  1107. {
  1108. u8 data;
  1109. int i;
  1110. for (i = 0; i < 5; i++) {
  1111. msleep(20);
  1112. data = reg_r(gspca_dev, OV534_REG_STATUS);
  1113. switch (data) {
  1114. case 0x00:
  1115. return 1;
  1116. case 0x04:
  1117. return 0;
  1118. case 0x03:
  1119. break;
  1120. default:
  1121. gspca_dbg(gspca_dev, D_USBI|D_USBO,
  1122. "sccb status 0x%02x, attempt %d/5\n",
  1123. data, i + 1);
  1124. }
  1125. }
  1126. return 0;
  1127. }
  1128. static void sccb_write(struct gspca_dev *gspca_dev, u8 reg, u8 val)
  1129. {
  1130. gspca_dbg(gspca_dev, D_USBO, "sccb_write [%02x] = %02x\n", reg, val);
  1131. reg_w_i(gspca_dev, OV534_REG_SUBADDR, reg);
  1132. reg_w_i(gspca_dev, OV534_REG_WRITE, val);
  1133. reg_w_i(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_3);
  1134. if (!sccb_check_status(gspca_dev))
  1135. pr_err("sccb_write failed\n");
  1136. }
  1137. static u8 sccb_read(struct gspca_dev *gspca_dev, u16 reg)
  1138. {
  1139. reg_w(gspca_dev, OV534_REG_SUBADDR, reg);
  1140. reg_w(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_2);
  1141. if (!sccb_check_status(gspca_dev))
  1142. pr_err("sccb_read failed 1\n");
  1143. reg_w(gspca_dev, OV534_REG_OPERATION, OV534_OP_READ_2);
  1144. if (!sccb_check_status(gspca_dev))
  1145. pr_err("sccb_read failed 2\n");
  1146. return reg_r(gspca_dev, OV534_REG_READ);
  1147. }
  1148. /* output a bridge sequence (reg - val) */
  1149. static void reg_w_array(struct gspca_dev *gspca_dev,
  1150. const u8 (*data)[2], int len)
  1151. {
  1152. while (--len >= 0) {
  1153. reg_w(gspca_dev, (*data)[0], (*data)[1]);
  1154. data++;
  1155. }
  1156. }
  1157. /* output a sensor sequence (reg - val) */
  1158. static void sccb_w_array(struct gspca_dev *gspca_dev,
  1159. const u8 (*data)[2], int len)
  1160. {
  1161. while (--len >= 0) {
  1162. if ((*data)[0] != 0xff) {
  1163. sccb_write(gspca_dev, (*data)[0], (*data)[1]);
  1164. } else {
  1165. sccb_read(gspca_dev, (*data)[1]);
  1166. sccb_write(gspca_dev, 0xff, 0x00);
  1167. }
  1168. data++;
  1169. }
  1170. }
  1171. /* Two bits control LED: 0x21 bit 7 and 0x23 bit 7.
  1172. * (direction and output)? */
  1173. static void set_led(struct gspca_dev *gspca_dev, int status)
  1174. {
  1175. u8 data;
  1176. gspca_dbg(gspca_dev, D_CONF, "led status: %d\n", status);
  1177. data = reg_r(gspca_dev, 0x21);
  1178. data |= 0x80;
  1179. reg_w(gspca_dev, 0x21, data);
  1180. data = reg_r(gspca_dev, 0x23);
  1181. if (status)
  1182. data |= 0x80;
  1183. else
  1184. data &= ~0x80;
  1185. reg_w(gspca_dev, 0x23, data);
  1186. if (!status) {
  1187. data = reg_r(gspca_dev, 0x21);
  1188. data &= ~0x80;
  1189. reg_w(gspca_dev, 0x21, data);
  1190. }
  1191. }
  1192. static void setbrightness(struct gspca_dev *gspca_dev, s32 brightness)
  1193. {
  1194. struct sd *sd = (struct sd *) gspca_dev;
  1195. u8 val;
  1196. s8 sval;
  1197. if (sd->sensor == SENSOR_OV562x) {
  1198. sval = brightness;
  1199. val = 0x76;
  1200. val += sval;
  1201. sccb_write(gspca_dev, 0x24, val);
  1202. val = 0x6a;
  1203. val += sval;
  1204. sccb_write(gspca_dev, 0x25, val);
  1205. if (sval < -40)
  1206. val = 0x71;
  1207. else if (sval < 20)
  1208. val = 0x94;
  1209. else
  1210. val = 0xe6;
  1211. sccb_write(gspca_dev, 0x26, val);
  1212. } else {
  1213. val = brightness;
  1214. if (val < 8)
  1215. val = 15 - val; /* f .. 8 */
  1216. else
  1217. val = val - 8; /* 0 .. 7 */
  1218. sccb_write(gspca_dev, 0x55, /* brtn - brightness adjustment */
  1219. 0x0f | (val << 4));
  1220. }
  1221. }
  1222. static void setcontrast(struct gspca_dev *gspca_dev, s32 val)
  1223. {
  1224. sccb_write(gspca_dev, 0x56, /* cnst1 - contrast 1 ctrl coeff */
  1225. val << 4);
  1226. }
  1227. static void setautogain(struct gspca_dev *gspca_dev, s32 autogain)
  1228. {
  1229. u8 val;
  1230. /*fixme: should adjust agc/awb/aec by different controls */
  1231. val = sccb_read(gspca_dev, 0x13); /* com8 */
  1232. sccb_write(gspca_dev, 0xff, 0x00);
  1233. if (autogain)
  1234. val |= 0x05; /* agc & aec */
  1235. else
  1236. val &= 0xfa;
  1237. sccb_write(gspca_dev, 0x13, val);
  1238. }
  1239. static void setexposure(struct gspca_dev *gspca_dev, s32 exposure)
  1240. {
  1241. static const u8 expo[4] = {0x00, 0x25, 0x38, 0x5e};
  1242. u8 val;
  1243. sccb_write(gspca_dev, 0x10, expo[exposure]); /* aec[9:2] */
  1244. val = sccb_read(gspca_dev, 0x13); /* com8 */
  1245. sccb_write(gspca_dev, 0xff, 0x00);
  1246. sccb_write(gspca_dev, 0x13, val);
  1247. val = sccb_read(gspca_dev, 0xa1); /* aech */
  1248. sccb_write(gspca_dev, 0xff, 0x00);
  1249. sccb_write(gspca_dev, 0xa1, val & 0xe0); /* aec[15:10] = 0 */
  1250. }
  1251. static void setsharpness(struct gspca_dev *gspca_dev, s32 val)
  1252. {
  1253. if (val < 0) { /* auto */
  1254. val = sccb_read(gspca_dev, 0x42); /* com17 */
  1255. sccb_write(gspca_dev, 0xff, 0x00);
  1256. sccb_write(gspca_dev, 0x42, val | 0x40);
  1257. /* Edge enhancement strength auto adjust */
  1258. return;
  1259. }
  1260. if (val != 0)
  1261. val = 1 << (val - 1);
  1262. sccb_write(gspca_dev, 0x3f, /* edge - edge enhance. factor */
  1263. val);
  1264. val = sccb_read(gspca_dev, 0x42); /* com17 */
  1265. sccb_write(gspca_dev, 0xff, 0x00);
  1266. sccb_write(gspca_dev, 0x42, val & 0xbf);
  1267. }
  1268. static void setsatur(struct gspca_dev *gspca_dev, s32 val)
  1269. {
  1270. u8 val1, val2, val3;
  1271. static const u8 matrix[5][2] = {
  1272. {0x14, 0x38},
  1273. {0x1e, 0x54},
  1274. {0x28, 0x70},
  1275. {0x32, 0x8c},
  1276. {0x48, 0x90}
  1277. };
  1278. val1 = matrix[val][0];
  1279. val2 = matrix[val][1];
  1280. val3 = val1 + val2;
  1281. sccb_write(gspca_dev, 0x4f, val3); /* matrix coeff */
  1282. sccb_write(gspca_dev, 0x50, val3);
  1283. sccb_write(gspca_dev, 0x51, 0x00);
  1284. sccb_write(gspca_dev, 0x52, val1);
  1285. sccb_write(gspca_dev, 0x53, val2);
  1286. sccb_write(gspca_dev, 0x54, val3);
  1287. sccb_write(gspca_dev, 0x58, 0x1a); /* mtxs - coeff signs */
  1288. val1 = sccb_read(gspca_dev, 0x41); /* com16 */
  1289. sccb_write(gspca_dev, 0xff, 0x00);
  1290. sccb_write(gspca_dev, 0x41, val1);
  1291. }
  1292. static void setlightfreq(struct gspca_dev *gspca_dev, s32 freq)
  1293. {
  1294. u8 val;
  1295. val = sccb_read(gspca_dev, 0x13); /* com8 */
  1296. sccb_write(gspca_dev, 0xff, 0x00);
  1297. if (freq == 0) {
  1298. sccb_write(gspca_dev, 0x13, val & 0xdf);
  1299. return;
  1300. }
  1301. sccb_write(gspca_dev, 0x13, val | 0x20);
  1302. val = sccb_read(gspca_dev, 0x42); /* com17 */
  1303. sccb_write(gspca_dev, 0xff, 0x00);
  1304. if (freq == 1)
  1305. val |= 0x01;
  1306. else
  1307. val &= 0xfe;
  1308. sccb_write(gspca_dev, 0x42, val);
  1309. }
  1310. /* this function is called at probe time */
  1311. static int sd_config(struct gspca_dev *gspca_dev,
  1312. const struct usb_device_id *id)
  1313. {
  1314. return 0;
  1315. }
  1316. /* this function is called at probe and resume time */
  1317. static int sd_init(struct gspca_dev *gspca_dev)
  1318. {
  1319. struct sd *sd = (struct sd *) gspca_dev;
  1320. u16 sensor_id;
  1321. /* reset bridge */
  1322. reg_w(gspca_dev, 0xe7, 0x3a);
  1323. reg_w(gspca_dev, 0xe0, 0x08);
  1324. msleep(100);
  1325. /* initialize the sensor address */
  1326. reg_w(gspca_dev, OV534_REG_ADDRESS, 0x60);
  1327. /* reset sensor */
  1328. sccb_write(gspca_dev, 0x12, 0x80);
  1329. msleep(10);
  1330. /* probe the sensor */
  1331. sccb_read(gspca_dev, 0x0a);
  1332. sensor_id = sccb_read(gspca_dev, 0x0a) << 8;
  1333. sccb_read(gspca_dev, 0x0b);
  1334. sensor_id |= sccb_read(gspca_dev, 0x0b);
  1335. gspca_dbg(gspca_dev, D_PROBE, "Sensor ID: %04x\n", sensor_id);
  1336. /* initialize */
  1337. if ((sensor_id & 0xfff0) == 0x9650) {
  1338. sd->sensor = SENSOR_OV965x;
  1339. gspca_dev->cam.cam_mode = ov965x_mode;
  1340. gspca_dev->cam.nmodes = ARRAY_SIZE(ov965x_mode);
  1341. reg_w_array(gspca_dev, bridge_init,
  1342. ARRAY_SIZE(bridge_init));
  1343. sccb_w_array(gspca_dev, ov965x_init,
  1344. ARRAY_SIZE(ov965x_init));
  1345. reg_w_array(gspca_dev, bridge_init_2,
  1346. ARRAY_SIZE(bridge_init_2));
  1347. sccb_w_array(gspca_dev, ov965x_init_2,
  1348. ARRAY_SIZE(ov965x_init_2));
  1349. reg_w(gspca_dev, 0xe0, 0x00);
  1350. reg_w(gspca_dev, 0xe0, 0x01);
  1351. set_led(gspca_dev, 0);
  1352. reg_w(gspca_dev, 0xe0, 0x00);
  1353. } else if ((sensor_id & 0xfff0) == 0x9710) {
  1354. const char *p;
  1355. int l;
  1356. sd->sensor = SENSOR_OV971x;
  1357. gspca_dev->cam.cam_mode = ov971x_mode;
  1358. gspca_dev->cam.nmodes = ARRAY_SIZE(ov971x_mode);
  1359. gspca_dev->cam.bulk = 1;
  1360. gspca_dev->cam.bulk_size = 16384;
  1361. gspca_dev->cam.bulk_nurbs = 2;
  1362. sccb_w_array(gspca_dev, ov971x_init,
  1363. ARRAY_SIZE(ov971x_init));
  1364. /* set video format on bridge processor */
  1365. /* access bridge processor's video format registers at: 0x00 */
  1366. reg_w(gspca_dev, 0x1c, 0x00);
  1367. /*set register: 0x00 is 'RAW8', 0x40 is 'YUV422' (YUYV?)*/
  1368. reg_w(gspca_dev, 0x1d, 0x00);
  1369. /* Will W. specific stuff
  1370. * set VSYNC to
  1371. * output (0x1f) if first webcam
  1372. * input (0x17) if 2nd or 3rd webcam */
  1373. p = video_device_node_name(&gspca_dev->vdev);
  1374. l = strlen(p) - 1;
  1375. if (p[l] == '0')
  1376. reg_w(gspca_dev, 0x56, 0x1f);
  1377. else
  1378. reg_w(gspca_dev, 0x56, 0x17);
  1379. } else if ((sensor_id & 0xfff0) == 0x5620) {
  1380. sd->sensor = SENSOR_OV562x;
  1381. gspca_dev->cam.cam_mode = ov562x_mode;
  1382. gspca_dev->cam.nmodes = ARRAY_SIZE(ov562x_mode);
  1383. reg_w_array(gspca_dev, ov562x_init,
  1384. ARRAY_SIZE(ov562x_init));
  1385. sccb_w_array(gspca_dev, ov562x_init_2,
  1386. ARRAY_SIZE(ov562x_init_2));
  1387. reg_w(gspca_dev, 0xe0, 0x00);
  1388. } else if ((sensor_id & 0xfff0) == 0x3610) {
  1389. sd->sensor = SENSOR_OV361x;
  1390. gspca_dev->cam.cam_mode = ov361x_mode;
  1391. gspca_dev->cam.nmodes = ARRAY_SIZE(ov361x_mode);
  1392. reg_w(gspca_dev, 0xe7, 0x3a);
  1393. reg_w(gspca_dev, 0xf1, 0x60);
  1394. sccb_write(gspca_dev, 0x12, 0x80);
  1395. } else {
  1396. pr_err("Unknown sensor %04x", sensor_id);
  1397. return -EINVAL;
  1398. }
  1399. return gspca_dev->usb_err;
  1400. }
  1401. static int sd_start_ov361x(struct gspca_dev *gspca_dev)
  1402. {
  1403. sccb_write(gspca_dev, 0x12, 0x80);
  1404. msleep(20);
  1405. switch (gspca_dev->curr_mode % (ov361x_last)) {
  1406. case ov361x_2048:
  1407. reg_w_array(gspca_dev, ov361x_bridge_start_2048,
  1408. ARRAY_SIZE(ov361x_bridge_start_2048));
  1409. sccb_w_array(gspca_dev, ov361x_start_2048,
  1410. ARRAY_SIZE(ov361x_start_2048));
  1411. break;
  1412. case ov361x_1600:
  1413. reg_w_array(gspca_dev, ov361x_bridge_start_1600,
  1414. ARRAY_SIZE(ov361x_bridge_start_1600));
  1415. sccb_w_array(gspca_dev, ov361x_start_1600,
  1416. ARRAY_SIZE(ov361x_start_1600));
  1417. break;
  1418. case ov361x_1024:
  1419. reg_w_array(gspca_dev, ov361x_bridge_start_1024,
  1420. ARRAY_SIZE(ov361x_bridge_start_1024));
  1421. sccb_w_array(gspca_dev, ov361x_start_1024,
  1422. ARRAY_SIZE(ov361x_start_1024));
  1423. break;
  1424. case ov361x_640:
  1425. reg_w_array(gspca_dev, ov361x_bridge_start_640,
  1426. ARRAY_SIZE(ov361x_bridge_start_640));
  1427. sccb_w_array(gspca_dev, ov361x_start_640,
  1428. ARRAY_SIZE(ov361x_start_640));
  1429. break;
  1430. case ov361x_320:
  1431. reg_w_array(gspca_dev, ov361x_bridge_start_320,
  1432. ARRAY_SIZE(ov361x_bridge_start_320));
  1433. sccb_w_array(gspca_dev, ov361x_start_320,
  1434. ARRAY_SIZE(ov361x_start_320));
  1435. break;
  1436. case ov361x_160:
  1437. reg_w_array(gspca_dev, ov361x_bridge_start_160,
  1438. ARRAY_SIZE(ov361x_bridge_start_160));
  1439. sccb_w_array(gspca_dev, ov361x_start_160,
  1440. ARRAY_SIZE(ov361x_start_160));
  1441. break;
  1442. }
  1443. reg_w(gspca_dev, 0xe0, 0x00); /* start transfer */
  1444. return gspca_dev->usb_err;
  1445. }
  1446. static int sd_start(struct gspca_dev *gspca_dev)
  1447. {
  1448. struct sd *sd = (struct sd *) gspca_dev;
  1449. if (sd->sensor == SENSOR_OV971x)
  1450. return gspca_dev->usb_err;
  1451. if (sd->sensor == SENSOR_OV562x)
  1452. return gspca_dev->usb_err;
  1453. if (sd->sensor == SENSOR_OV361x)
  1454. return sd_start_ov361x(gspca_dev);
  1455. switch (gspca_dev->curr_mode) {
  1456. case QVGA_MODE: /* 320x240 */
  1457. sccb_w_array(gspca_dev, ov965x_start_1_vga,
  1458. ARRAY_SIZE(ov965x_start_1_vga));
  1459. reg_w_array(gspca_dev, bridge_start_qvga,
  1460. ARRAY_SIZE(bridge_start_qvga));
  1461. sccb_w_array(gspca_dev, ov965x_start_2_qvga,
  1462. ARRAY_SIZE(ov965x_start_2_qvga));
  1463. break;
  1464. case VGA_MODE: /* 640x480 */
  1465. sccb_w_array(gspca_dev, ov965x_start_1_vga,
  1466. ARRAY_SIZE(ov965x_start_1_vga));
  1467. reg_w_array(gspca_dev, bridge_start_vga,
  1468. ARRAY_SIZE(bridge_start_vga));
  1469. sccb_w_array(gspca_dev, ov965x_start_2_vga,
  1470. ARRAY_SIZE(ov965x_start_2_vga));
  1471. break;
  1472. case SVGA_MODE: /* 800x600 */
  1473. sccb_w_array(gspca_dev, ov965x_start_1_svga,
  1474. ARRAY_SIZE(ov965x_start_1_svga));
  1475. reg_w_array(gspca_dev, bridge_start_svga,
  1476. ARRAY_SIZE(bridge_start_svga));
  1477. sccb_w_array(gspca_dev, ov965x_start_2_svga,
  1478. ARRAY_SIZE(ov965x_start_2_svga));
  1479. break;
  1480. case XGA_MODE: /* 1024x768 */
  1481. sccb_w_array(gspca_dev, ov965x_start_1_xga,
  1482. ARRAY_SIZE(ov965x_start_1_xga));
  1483. reg_w_array(gspca_dev, bridge_start_xga,
  1484. ARRAY_SIZE(bridge_start_xga));
  1485. sccb_w_array(gspca_dev, ov965x_start_2_svga,
  1486. ARRAY_SIZE(ov965x_start_2_svga));
  1487. break;
  1488. default:
  1489. /* case SXGA_MODE: * 1280x1024 */
  1490. sccb_w_array(gspca_dev, ov965x_start_1_sxga,
  1491. ARRAY_SIZE(ov965x_start_1_sxga));
  1492. reg_w_array(gspca_dev, bridge_start_sxga,
  1493. ARRAY_SIZE(bridge_start_sxga));
  1494. sccb_w_array(gspca_dev, ov965x_start_2_sxga,
  1495. ARRAY_SIZE(ov965x_start_2_sxga));
  1496. break;
  1497. }
  1498. reg_w(gspca_dev, 0xe0, 0x00);
  1499. reg_w(gspca_dev, 0xe0, 0x00);
  1500. set_led(gspca_dev, 1);
  1501. return gspca_dev->usb_err;
  1502. }
  1503. static void sd_stopN(struct gspca_dev *gspca_dev)
  1504. {
  1505. if (((struct sd *)gspca_dev)->sensor == SENSOR_OV361x) {
  1506. reg_w(gspca_dev, 0xe0, 0x01); /* stop transfer */
  1507. /* reg_w(gspca_dev, 0x31, 0x09); */
  1508. return;
  1509. }
  1510. reg_w(gspca_dev, 0xe0, 0x01);
  1511. set_led(gspca_dev, 0);
  1512. reg_w(gspca_dev, 0xe0, 0x00);
  1513. }
  1514. /* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */
  1515. #define UVC_STREAM_EOH (1 << 7)
  1516. #define UVC_STREAM_ERR (1 << 6)
  1517. #define UVC_STREAM_STI (1 << 5)
  1518. #define UVC_STREAM_RES (1 << 4)
  1519. #define UVC_STREAM_SCR (1 << 3)
  1520. #define UVC_STREAM_PTS (1 << 2)
  1521. #define UVC_STREAM_EOF (1 << 1)
  1522. #define UVC_STREAM_FID (1 << 0)
  1523. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  1524. u8 *data, int len)
  1525. {
  1526. struct sd *sd = (struct sd *) gspca_dev;
  1527. __u32 this_pts;
  1528. u8 this_fid;
  1529. int remaining_len = len;
  1530. int payload_len;
  1531. payload_len = gspca_dev->cam.bulk ? 2048 : 2040;
  1532. do {
  1533. len = min(remaining_len, payload_len);
  1534. /* Payloads are prefixed with a UVC-style header. We
  1535. consider a frame to start when the FID toggles, or the PTS
  1536. changes. A frame ends when EOF is set, and we've received
  1537. the correct number of bytes. */
  1538. /* Verify UVC header. Header length is always 12 */
  1539. if (data[0] != 12 || len < 12) {
  1540. gspca_dbg(gspca_dev, D_PACK, "bad header\n");
  1541. goto discard;
  1542. }
  1543. /* Check errors */
  1544. if (data[1] & UVC_STREAM_ERR) {
  1545. gspca_dbg(gspca_dev, D_PACK, "payload error\n");
  1546. goto discard;
  1547. }
  1548. /* Extract PTS and FID */
  1549. if (!(data[1] & UVC_STREAM_PTS)) {
  1550. gspca_dbg(gspca_dev, D_PACK, "PTS not present\n");
  1551. goto discard;
  1552. }
  1553. this_pts = (data[5] << 24) | (data[4] << 16)
  1554. | (data[3] << 8) | data[2];
  1555. this_fid = data[1] & UVC_STREAM_FID;
  1556. /* If PTS or FID has changed, start a new frame. */
  1557. if (this_pts != sd->last_pts || this_fid != sd->last_fid) {
  1558. if (gspca_dev->last_packet_type == INTER_PACKET)
  1559. gspca_frame_add(gspca_dev, LAST_PACKET,
  1560. NULL, 0);
  1561. sd->last_pts = this_pts;
  1562. sd->last_fid = this_fid;
  1563. gspca_frame_add(gspca_dev, FIRST_PACKET,
  1564. data + 12, len - 12);
  1565. /* If this packet is marked as EOF, end the frame */
  1566. } else if (data[1] & UVC_STREAM_EOF) {
  1567. sd->last_pts = 0;
  1568. gspca_frame_add(gspca_dev, LAST_PACKET,
  1569. data + 12, len - 12);
  1570. } else {
  1571. /* Add the data from this payload */
  1572. gspca_frame_add(gspca_dev, INTER_PACKET,
  1573. data + 12, len - 12);
  1574. }
  1575. /* Done this payload */
  1576. goto scan_next;
  1577. discard:
  1578. /* Discard data until a new frame starts. */
  1579. gspca_dev->last_packet_type = DISCARD_PACKET;
  1580. scan_next:
  1581. remaining_len -= len;
  1582. data += len;
  1583. } while (remaining_len > 0);
  1584. }
  1585. static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
  1586. {
  1587. struct gspca_dev *gspca_dev =
  1588. container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
  1589. gspca_dev->usb_err = 0;
  1590. if (!gspca_dev->streaming)
  1591. return 0;
  1592. switch (ctrl->id) {
  1593. case V4L2_CID_BRIGHTNESS:
  1594. setbrightness(gspca_dev, ctrl->val);
  1595. break;
  1596. case V4L2_CID_CONTRAST:
  1597. setcontrast(gspca_dev, ctrl->val);
  1598. break;
  1599. case V4L2_CID_SATURATION:
  1600. setsatur(gspca_dev, ctrl->val);
  1601. break;
  1602. case V4L2_CID_POWER_LINE_FREQUENCY:
  1603. setlightfreq(gspca_dev, ctrl->val);
  1604. break;
  1605. case V4L2_CID_SHARPNESS:
  1606. setsharpness(gspca_dev, ctrl->val);
  1607. break;
  1608. case V4L2_CID_AUTOGAIN:
  1609. if (ctrl->is_new)
  1610. setautogain(gspca_dev, ctrl->val);
  1611. if (!ctrl->val && gspca_dev->exposure->is_new)
  1612. setexposure(gspca_dev, gspca_dev->exposure->val);
  1613. break;
  1614. }
  1615. return gspca_dev->usb_err;
  1616. }
  1617. static const struct v4l2_ctrl_ops sd_ctrl_ops = {
  1618. .s_ctrl = sd_s_ctrl,
  1619. };
  1620. static int sd_init_controls(struct gspca_dev *gspca_dev)
  1621. {
  1622. struct sd *sd = (struct sd *)gspca_dev;
  1623. struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
  1624. if (sd->sensor == SENSOR_OV971x)
  1625. return 0;
  1626. if (sd->sensor == SENSOR_OV361x)
  1627. return 0;
  1628. gspca_dev->vdev.ctrl_handler = hdl;
  1629. v4l2_ctrl_handler_init(hdl, 7);
  1630. if (sd->sensor == SENSOR_OV562x) {
  1631. v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1632. V4L2_CID_BRIGHTNESS, -90, 90, 1, 0);
  1633. } else {
  1634. v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1635. V4L2_CID_BRIGHTNESS, 0, 15, 1, 7);
  1636. v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1637. V4L2_CID_CONTRAST, 0, 15, 1, 3);
  1638. v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1639. V4L2_CID_SATURATION, 0, 4, 1, 2);
  1640. /* -1 = auto */
  1641. v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1642. V4L2_CID_SHARPNESS, -1, 4, 1, -1);
  1643. gspca_dev->autogain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1644. V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
  1645. gspca_dev->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  1646. V4L2_CID_EXPOSURE, 0, 3, 1, 0);
  1647. v4l2_ctrl_new_std_menu(hdl, &sd_ctrl_ops,
  1648. V4L2_CID_POWER_LINE_FREQUENCY,
  1649. V4L2_CID_POWER_LINE_FREQUENCY_60HZ, 0, 0);
  1650. v4l2_ctrl_auto_cluster(3, &gspca_dev->autogain, 0, false);
  1651. }
  1652. if (hdl->error) {
  1653. pr_err("Could not initialize controls\n");
  1654. return hdl->error;
  1655. }
  1656. return 0;
  1657. }
  1658. /* sub-driver description */
  1659. static const struct sd_desc sd_desc = {
  1660. .name = MODULE_NAME,
  1661. .config = sd_config,
  1662. .init = sd_init,
  1663. .init_controls = sd_init_controls,
  1664. .start = sd_start,
  1665. .stopN = sd_stopN,
  1666. .pkt_scan = sd_pkt_scan,
  1667. };
  1668. /* -- module initialisation -- */
  1669. static const struct usb_device_id device_table[] = {
  1670. {USB_DEVICE(0x05a9, 0x8065)},
  1671. {USB_DEVICE(0x06f8, 0x3003)},
  1672. {USB_DEVICE(0x05a9, 0x1550)},
  1673. {}
  1674. };
  1675. MODULE_DEVICE_TABLE(usb, device_table);
  1676. /* -- device connect -- */
  1677. static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id)
  1678. {
  1679. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  1680. THIS_MODULE);
  1681. }
  1682. static struct usb_driver sd_driver = {
  1683. .name = MODULE_NAME,
  1684. .id_table = device_table,
  1685. .probe = sd_probe,
  1686. .disconnect = gspca_disconnect,
  1687. #ifdef CONFIG_PM
  1688. .suspend = gspca_suspend,
  1689. .resume = gspca_resume,
  1690. .reset_resume = gspca_resume,
  1691. #endif
  1692. };
  1693. module_usb_driver(sd_driver);