ov534_9.c 41 KB

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