ov5670.c 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (c) 2017 Intel Corporation.
  3. #include <linux/acpi.h>
  4. #include <linux/i2c.h>
  5. #include <linux/module.h>
  6. #include <linux/pm_runtime.h>
  7. #include <media/v4l2-ctrls.h>
  8. #include <media/v4l2-device.h>
  9. #define OV5670_REG_CHIP_ID 0x300a
  10. #define OV5670_CHIP_ID 0x005670
  11. #define OV5670_REG_MODE_SELECT 0x0100
  12. #define OV5670_MODE_STANDBY 0x00
  13. #define OV5670_MODE_STREAMING 0x01
  14. #define OV5670_REG_SOFTWARE_RST 0x0103
  15. #define OV5670_SOFTWARE_RST 0x01
  16. /* vertical-timings from sensor */
  17. #define OV5670_REG_VTS 0x380e
  18. #define OV5670_VTS_30FPS 0x0808 /* default for 30 fps */
  19. #define OV5670_VTS_MAX 0xffff
  20. /* horizontal-timings from sensor */
  21. #define OV5670_REG_HTS 0x380c
  22. /*
  23. * Pixels-per-line(PPL) = Time-per-line * pixel-rate
  24. * In OV5670, Time-per-line = HTS/SCLK.
  25. * HTS is fixed for all resolutions, not recommended to change.
  26. */
  27. #define OV5670_FIXED_PPL 2724 /* Pixels per line */
  28. /* Exposure controls from sensor */
  29. #define OV5670_REG_EXPOSURE 0x3500
  30. #define OV5670_EXPOSURE_MIN 4
  31. #define OV5670_EXPOSURE_STEP 1
  32. /* Analog gain controls from sensor */
  33. #define OV5670_REG_ANALOG_GAIN 0x3508
  34. #define ANALOG_GAIN_MIN 0
  35. #define ANALOG_GAIN_MAX 8191
  36. #define ANALOG_GAIN_STEP 1
  37. #define ANALOG_GAIN_DEFAULT 128
  38. /* Digital gain controls from sensor */
  39. #define OV5670_REG_R_DGTL_GAIN 0x5032
  40. #define OV5670_REG_G_DGTL_GAIN 0x5034
  41. #define OV5670_REG_B_DGTL_GAIN 0x5036
  42. #define OV5670_DGTL_GAIN_MIN 0
  43. #define OV5670_DGTL_GAIN_MAX 4095
  44. #define OV5670_DGTL_GAIN_STEP 1
  45. #define OV5670_DGTL_GAIN_DEFAULT 1024
  46. /* Test Pattern Control */
  47. #define OV5670_REG_TEST_PATTERN 0x4303
  48. #define OV5670_TEST_PATTERN_ENABLE BIT(3)
  49. #define OV5670_REG_TEST_PATTERN_CTRL 0x4320
  50. #define OV5670_REG_VALUE_08BIT 1
  51. #define OV5670_REG_VALUE_16BIT 2
  52. #define OV5670_REG_VALUE_24BIT 3
  53. /* Initial number of frames to skip to avoid possible garbage */
  54. #define OV5670_NUM_OF_SKIP_FRAMES 2
  55. struct ov5670_reg {
  56. u16 address;
  57. u8 val;
  58. };
  59. struct ov5670_reg_list {
  60. u32 num_of_regs;
  61. const struct ov5670_reg *regs;
  62. };
  63. struct ov5670_link_freq_config {
  64. u32 pixel_rate;
  65. const struct ov5670_reg_list reg_list;
  66. };
  67. struct ov5670_mode {
  68. /* Frame width in pixels */
  69. u32 width;
  70. /* Frame height in pixels */
  71. u32 height;
  72. /* Default vertical timining size */
  73. u32 vts_def;
  74. /* Min vertical timining size */
  75. u32 vts_min;
  76. /* Link frequency needed for this resolution */
  77. u32 link_freq_index;
  78. /* Sensor register settings for this resolution */
  79. const struct ov5670_reg_list reg_list;
  80. };
  81. static const struct ov5670_reg mipi_data_rate_840mbps[] = {
  82. {0x0300, 0x04},
  83. {0x0301, 0x00},
  84. {0x0302, 0x84},
  85. {0x0303, 0x00},
  86. {0x0304, 0x03},
  87. {0x0305, 0x01},
  88. {0x0306, 0x01},
  89. {0x030a, 0x00},
  90. {0x030b, 0x00},
  91. {0x030c, 0x00},
  92. {0x030d, 0x26},
  93. {0x030e, 0x00},
  94. {0x030f, 0x06},
  95. {0x0312, 0x01},
  96. {0x3031, 0x0a},
  97. };
  98. static const struct ov5670_reg mode_2592x1944_regs[] = {
  99. {0x3000, 0x00},
  100. {0x3002, 0x21},
  101. {0x3005, 0xf0},
  102. {0x3007, 0x00},
  103. {0x3015, 0x0f},
  104. {0x3018, 0x32},
  105. {0x301a, 0xf0},
  106. {0x301b, 0xf0},
  107. {0x301c, 0xf0},
  108. {0x301d, 0xf0},
  109. {0x301e, 0xf0},
  110. {0x3030, 0x00},
  111. {0x3031, 0x0a},
  112. {0x303c, 0xff},
  113. {0x303e, 0xff},
  114. {0x3040, 0xf0},
  115. {0x3041, 0x00},
  116. {0x3042, 0xf0},
  117. {0x3106, 0x11},
  118. {0x3500, 0x00},
  119. {0x3501, 0x80},
  120. {0x3502, 0x00},
  121. {0x3503, 0x04},
  122. {0x3504, 0x03},
  123. {0x3505, 0x83},
  124. {0x3508, 0x04},
  125. {0x3509, 0x00},
  126. {0x350e, 0x04},
  127. {0x350f, 0x00},
  128. {0x3510, 0x00},
  129. {0x3511, 0x02},
  130. {0x3512, 0x00},
  131. {0x3601, 0xc8},
  132. {0x3610, 0x88},
  133. {0x3612, 0x48},
  134. {0x3614, 0x5b},
  135. {0x3615, 0x96},
  136. {0x3621, 0xd0},
  137. {0x3622, 0x00},
  138. {0x3623, 0x00},
  139. {0x3633, 0x13},
  140. {0x3634, 0x13},
  141. {0x3635, 0x13},
  142. {0x3636, 0x13},
  143. {0x3645, 0x13},
  144. {0x3646, 0x82},
  145. {0x3650, 0x00},
  146. {0x3652, 0xff},
  147. {0x3655, 0x20},
  148. {0x3656, 0xff},
  149. {0x365a, 0xff},
  150. {0x365e, 0xff},
  151. {0x3668, 0x00},
  152. {0x366a, 0x07},
  153. {0x366e, 0x10},
  154. {0x366d, 0x00},
  155. {0x366f, 0x80},
  156. {0x3700, 0x28},
  157. {0x3701, 0x10},
  158. {0x3702, 0x3a},
  159. {0x3703, 0x19},
  160. {0x3704, 0x10},
  161. {0x3705, 0x00},
  162. {0x3706, 0x66},
  163. {0x3707, 0x08},
  164. {0x3708, 0x34},
  165. {0x3709, 0x40},
  166. {0x370a, 0x01},
  167. {0x370b, 0x1b},
  168. {0x3714, 0x24},
  169. {0x371a, 0x3e},
  170. {0x3733, 0x00},
  171. {0x3734, 0x00},
  172. {0x373a, 0x05},
  173. {0x373b, 0x06},
  174. {0x373c, 0x0a},
  175. {0x373f, 0xa0},
  176. {0x3755, 0x00},
  177. {0x3758, 0x00},
  178. {0x375b, 0x0e},
  179. {0x3766, 0x5f},
  180. {0x3768, 0x00},
  181. {0x3769, 0x22},
  182. {0x3773, 0x08},
  183. {0x3774, 0x1f},
  184. {0x3776, 0x06},
  185. {0x37a0, 0x88},
  186. {0x37a1, 0x5c},
  187. {0x37a7, 0x88},
  188. {0x37a8, 0x70},
  189. {0x37aa, 0x88},
  190. {0x37ab, 0x48},
  191. {0x37b3, 0x66},
  192. {0x37c2, 0x04},
  193. {0x37c5, 0x00},
  194. {0x37c8, 0x00},
  195. {0x3800, 0x00},
  196. {0x3801, 0x0c},
  197. {0x3802, 0x00},
  198. {0x3803, 0x04},
  199. {0x3804, 0x0a},
  200. {0x3805, 0x33},
  201. {0x3806, 0x07},
  202. {0x3807, 0xa3},
  203. {0x3808, 0x0a},
  204. {0x3809, 0x20},
  205. {0x380a, 0x07},
  206. {0x380b, 0x98},
  207. {0x380c, 0x06},
  208. {0x380d, 0x90},
  209. {0x380e, 0x08},
  210. {0x380f, 0x08},
  211. {0x3811, 0x04},
  212. {0x3813, 0x02},
  213. {0x3814, 0x01},
  214. {0x3815, 0x01},
  215. {0x3816, 0x00},
  216. {0x3817, 0x00},
  217. {0x3818, 0x00},
  218. {0x3819, 0x00},
  219. {0x3820, 0x84},
  220. {0x3821, 0x46},
  221. {0x3822, 0x48},
  222. {0x3826, 0x00},
  223. {0x3827, 0x08},
  224. {0x382a, 0x01},
  225. {0x382b, 0x01},
  226. {0x3830, 0x08},
  227. {0x3836, 0x02},
  228. {0x3837, 0x00},
  229. {0x3838, 0x10},
  230. {0x3841, 0xff},
  231. {0x3846, 0x48},
  232. {0x3861, 0x00},
  233. {0x3862, 0x04},
  234. {0x3863, 0x06},
  235. {0x3a11, 0x01},
  236. {0x3a12, 0x78},
  237. {0x3b00, 0x00},
  238. {0x3b02, 0x00},
  239. {0x3b03, 0x00},
  240. {0x3b04, 0x00},
  241. {0x3b05, 0x00},
  242. {0x3c00, 0x89},
  243. {0x3c01, 0xab},
  244. {0x3c02, 0x01},
  245. {0x3c03, 0x00},
  246. {0x3c04, 0x00},
  247. {0x3c05, 0x03},
  248. {0x3c06, 0x00},
  249. {0x3c07, 0x05},
  250. {0x3c0c, 0x00},
  251. {0x3c0d, 0x00},
  252. {0x3c0e, 0x00},
  253. {0x3c0f, 0x00},
  254. {0x3c40, 0x00},
  255. {0x3c41, 0xa3},
  256. {0x3c43, 0x7d},
  257. {0x3c45, 0xd7},
  258. {0x3c47, 0xfc},
  259. {0x3c50, 0x05},
  260. {0x3c52, 0xaa},
  261. {0x3c54, 0x71},
  262. {0x3c56, 0x80},
  263. {0x3d85, 0x17},
  264. {0x3f03, 0x00},
  265. {0x3f0a, 0x00},
  266. {0x3f0b, 0x00},
  267. {0x4001, 0x60},
  268. {0x4009, 0x0d},
  269. {0x4020, 0x00},
  270. {0x4021, 0x00},
  271. {0x4022, 0x00},
  272. {0x4023, 0x00},
  273. {0x4024, 0x00},
  274. {0x4025, 0x00},
  275. {0x4026, 0x00},
  276. {0x4027, 0x00},
  277. {0x4028, 0x00},
  278. {0x4029, 0x00},
  279. {0x402a, 0x00},
  280. {0x402b, 0x00},
  281. {0x402c, 0x00},
  282. {0x402d, 0x00},
  283. {0x402e, 0x00},
  284. {0x402f, 0x00},
  285. {0x4040, 0x00},
  286. {0x4041, 0x03},
  287. {0x4042, 0x00},
  288. {0x4043, 0x7A},
  289. {0x4044, 0x00},
  290. {0x4045, 0x7A},
  291. {0x4046, 0x00},
  292. {0x4047, 0x7A},
  293. {0x4048, 0x00},
  294. {0x4049, 0x7A},
  295. {0x4307, 0x30},
  296. {0x4500, 0x58},
  297. {0x4501, 0x04},
  298. {0x4502, 0x40},
  299. {0x4503, 0x10},
  300. {0x4508, 0xaa},
  301. {0x4509, 0xaa},
  302. {0x450a, 0x00},
  303. {0x450b, 0x00},
  304. {0x4600, 0x01},
  305. {0x4601, 0x03},
  306. {0x4700, 0xa4},
  307. {0x4800, 0x4c},
  308. {0x4816, 0x53},
  309. {0x481f, 0x40},
  310. {0x4837, 0x13},
  311. {0x5000, 0x56},
  312. {0x5001, 0x01},
  313. {0x5002, 0x28},
  314. {0x5004, 0x0c},
  315. {0x5006, 0x0c},
  316. {0x5007, 0xe0},
  317. {0x5008, 0x01},
  318. {0x5009, 0xb0},
  319. {0x5901, 0x00},
  320. {0x5a01, 0x00},
  321. {0x5a03, 0x00},
  322. {0x5a04, 0x0c},
  323. {0x5a05, 0xe0},
  324. {0x5a06, 0x09},
  325. {0x5a07, 0xb0},
  326. {0x5a08, 0x06},
  327. {0x5e00, 0x00},
  328. {0x3734, 0x40},
  329. {0x5b00, 0x01},
  330. {0x5b01, 0x10},
  331. {0x5b02, 0x01},
  332. {0x5b03, 0xdb},
  333. {0x3d8c, 0x71},
  334. {0x3d8d, 0xea},
  335. {0x4017, 0x08},
  336. {0x3618, 0x2a},
  337. {0x5780, 0x3e},
  338. {0x5781, 0x0f},
  339. {0x5782, 0x44},
  340. {0x5783, 0x02},
  341. {0x5784, 0x01},
  342. {0x5785, 0x01},
  343. {0x5786, 0x00},
  344. {0x5787, 0x04},
  345. {0x5788, 0x02},
  346. {0x5789, 0x0f},
  347. {0x578a, 0xfd},
  348. {0x578b, 0xf5},
  349. {0x578c, 0xf5},
  350. {0x578d, 0x03},
  351. {0x578e, 0x08},
  352. {0x578f, 0x0c},
  353. {0x5790, 0x08},
  354. {0x5791, 0x06},
  355. {0x5792, 0x00},
  356. {0x5793, 0x52},
  357. {0x5794, 0xa3},
  358. {0x3503, 0x00},
  359. {0x5045, 0x05},
  360. {0x4003, 0x40},
  361. {0x5048, 0x40}
  362. };
  363. static const struct ov5670_reg mode_1296x972_regs[] = {
  364. {0x3000, 0x00},
  365. {0x3002, 0x21},
  366. {0x3005, 0xf0},
  367. {0x3007, 0x00},
  368. {0x3015, 0x0f},
  369. {0x3018, 0x32},
  370. {0x301a, 0xf0},
  371. {0x301b, 0xf0},
  372. {0x301c, 0xf0},
  373. {0x301d, 0xf0},
  374. {0x301e, 0xf0},
  375. {0x3030, 0x00},
  376. {0x3031, 0x0a},
  377. {0x303c, 0xff},
  378. {0x303e, 0xff},
  379. {0x3040, 0xf0},
  380. {0x3041, 0x00},
  381. {0x3042, 0xf0},
  382. {0x3106, 0x11},
  383. {0x3500, 0x00},
  384. {0x3501, 0x80},
  385. {0x3502, 0x00},
  386. {0x3503, 0x04},
  387. {0x3504, 0x03},
  388. {0x3505, 0x83},
  389. {0x3508, 0x07},
  390. {0x3509, 0x80},
  391. {0x350e, 0x04},
  392. {0x350f, 0x00},
  393. {0x3510, 0x00},
  394. {0x3511, 0x02},
  395. {0x3512, 0x00},
  396. {0x3601, 0xc8},
  397. {0x3610, 0x88},
  398. {0x3612, 0x48},
  399. {0x3614, 0x5b},
  400. {0x3615, 0x96},
  401. {0x3621, 0xd0},
  402. {0x3622, 0x00},
  403. {0x3623, 0x00},
  404. {0x3633, 0x13},
  405. {0x3634, 0x13},
  406. {0x3635, 0x13},
  407. {0x3636, 0x13},
  408. {0x3645, 0x13},
  409. {0x3646, 0x82},
  410. {0x3650, 0x00},
  411. {0x3652, 0xff},
  412. {0x3655, 0x20},
  413. {0x3656, 0xff},
  414. {0x365a, 0xff},
  415. {0x365e, 0xff},
  416. {0x3668, 0x00},
  417. {0x366a, 0x07},
  418. {0x366e, 0x08},
  419. {0x366d, 0x00},
  420. {0x366f, 0x80},
  421. {0x3700, 0x28},
  422. {0x3701, 0x10},
  423. {0x3702, 0x3a},
  424. {0x3703, 0x19},
  425. {0x3704, 0x10},
  426. {0x3705, 0x00},
  427. {0x3706, 0x66},
  428. {0x3707, 0x08},
  429. {0x3708, 0x34},
  430. {0x3709, 0x40},
  431. {0x370a, 0x01},
  432. {0x370b, 0x1b},
  433. {0x3714, 0x24},
  434. {0x371a, 0x3e},
  435. {0x3733, 0x00},
  436. {0x3734, 0x00},
  437. {0x373a, 0x05},
  438. {0x373b, 0x06},
  439. {0x373c, 0x0a},
  440. {0x373f, 0xa0},
  441. {0x3755, 0x00},
  442. {0x3758, 0x00},
  443. {0x375b, 0x0e},
  444. {0x3766, 0x5f},
  445. {0x3768, 0x00},
  446. {0x3769, 0x22},
  447. {0x3773, 0x08},
  448. {0x3774, 0x1f},
  449. {0x3776, 0x06},
  450. {0x37a0, 0x88},
  451. {0x37a1, 0x5c},
  452. {0x37a7, 0x88},
  453. {0x37a8, 0x70},
  454. {0x37aa, 0x88},
  455. {0x37ab, 0x48},
  456. {0x37b3, 0x66},
  457. {0x37c2, 0x04},
  458. {0x37c5, 0x00},
  459. {0x37c8, 0x00},
  460. {0x3800, 0x00},
  461. {0x3801, 0x0c},
  462. {0x3802, 0x00},
  463. {0x3803, 0x04},
  464. {0x3804, 0x0a},
  465. {0x3805, 0x33},
  466. {0x3806, 0x07},
  467. {0x3807, 0xa3},
  468. {0x3808, 0x05},
  469. {0x3809, 0x10},
  470. {0x380a, 0x03},
  471. {0x380b, 0xcc},
  472. {0x380c, 0x06},
  473. {0x380d, 0x90},
  474. {0x380e, 0x08},
  475. {0x380f, 0x08},
  476. {0x3811, 0x04},
  477. {0x3813, 0x04},
  478. {0x3814, 0x03},
  479. {0x3815, 0x01},
  480. {0x3816, 0x00},
  481. {0x3817, 0x00},
  482. {0x3818, 0x00},
  483. {0x3819, 0x00},
  484. {0x3820, 0x94},
  485. {0x3821, 0x47},
  486. {0x3822, 0x48},
  487. {0x3826, 0x00},
  488. {0x3827, 0x08},
  489. {0x382a, 0x03},
  490. {0x382b, 0x01},
  491. {0x3830, 0x08},
  492. {0x3836, 0x02},
  493. {0x3837, 0x00},
  494. {0x3838, 0x10},
  495. {0x3841, 0xff},
  496. {0x3846, 0x48},
  497. {0x3861, 0x00},
  498. {0x3862, 0x04},
  499. {0x3863, 0x06},
  500. {0x3a11, 0x01},
  501. {0x3a12, 0x78},
  502. {0x3b00, 0x00},
  503. {0x3b02, 0x00},
  504. {0x3b03, 0x00},
  505. {0x3b04, 0x00},
  506. {0x3b05, 0x00},
  507. {0x3c00, 0x89},
  508. {0x3c01, 0xab},
  509. {0x3c02, 0x01},
  510. {0x3c03, 0x00},
  511. {0x3c04, 0x00},
  512. {0x3c05, 0x03},
  513. {0x3c06, 0x00},
  514. {0x3c07, 0x05},
  515. {0x3c0c, 0x00},
  516. {0x3c0d, 0x00},
  517. {0x3c0e, 0x00},
  518. {0x3c0f, 0x00},
  519. {0x3c40, 0x00},
  520. {0x3c41, 0xa3},
  521. {0x3c43, 0x7d},
  522. {0x3c45, 0xd7},
  523. {0x3c47, 0xfc},
  524. {0x3c50, 0x05},
  525. {0x3c52, 0xaa},
  526. {0x3c54, 0x71},
  527. {0x3c56, 0x80},
  528. {0x3d85, 0x17},
  529. {0x3f03, 0x00},
  530. {0x3f0a, 0x00},
  531. {0x3f0b, 0x00},
  532. {0x4001, 0x60},
  533. {0x4009, 0x05},
  534. {0x4020, 0x00},
  535. {0x4021, 0x00},
  536. {0x4022, 0x00},
  537. {0x4023, 0x00},
  538. {0x4024, 0x00},
  539. {0x4025, 0x00},
  540. {0x4026, 0x00},
  541. {0x4027, 0x00},
  542. {0x4028, 0x00},
  543. {0x4029, 0x00},
  544. {0x402a, 0x00},
  545. {0x402b, 0x00},
  546. {0x402c, 0x00},
  547. {0x402d, 0x00},
  548. {0x402e, 0x00},
  549. {0x402f, 0x00},
  550. {0x4040, 0x00},
  551. {0x4041, 0x03},
  552. {0x4042, 0x00},
  553. {0x4043, 0x7A},
  554. {0x4044, 0x00},
  555. {0x4045, 0x7A},
  556. {0x4046, 0x00},
  557. {0x4047, 0x7A},
  558. {0x4048, 0x00},
  559. {0x4049, 0x7A},
  560. {0x4307, 0x30},
  561. {0x4500, 0x58},
  562. {0x4501, 0x04},
  563. {0x4502, 0x48},
  564. {0x4503, 0x10},
  565. {0x4508, 0x55},
  566. {0x4509, 0x55},
  567. {0x450a, 0x00},
  568. {0x450b, 0x00},
  569. {0x4600, 0x00},
  570. {0x4601, 0x81},
  571. {0x4700, 0xa4},
  572. {0x4800, 0x4c},
  573. {0x4816, 0x53},
  574. {0x481f, 0x40},
  575. {0x4837, 0x13},
  576. {0x5000, 0x56},
  577. {0x5001, 0x01},
  578. {0x5002, 0x28},
  579. {0x5004, 0x0c},
  580. {0x5006, 0x0c},
  581. {0x5007, 0xe0},
  582. {0x5008, 0x01},
  583. {0x5009, 0xb0},
  584. {0x5901, 0x00},
  585. {0x5a01, 0x00},
  586. {0x5a03, 0x00},
  587. {0x5a04, 0x0c},
  588. {0x5a05, 0xe0},
  589. {0x5a06, 0x09},
  590. {0x5a07, 0xb0},
  591. {0x5a08, 0x06},
  592. {0x5e00, 0x00},
  593. {0x3734, 0x40},
  594. {0x5b00, 0x01},
  595. {0x5b01, 0x10},
  596. {0x5b02, 0x01},
  597. {0x5b03, 0xdb},
  598. {0x3d8c, 0x71},
  599. {0x3d8d, 0xea},
  600. {0x4017, 0x10},
  601. {0x3618, 0x2a},
  602. {0x5780, 0x3e},
  603. {0x5781, 0x0f},
  604. {0x5782, 0x44},
  605. {0x5783, 0x02},
  606. {0x5784, 0x01},
  607. {0x5785, 0x01},
  608. {0x5786, 0x00},
  609. {0x5787, 0x04},
  610. {0x5788, 0x02},
  611. {0x5789, 0x0f},
  612. {0x578a, 0xfd},
  613. {0x578b, 0xf5},
  614. {0x578c, 0xf5},
  615. {0x578d, 0x03},
  616. {0x578e, 0x08},
  617. {0x578f, 0x0c},
  618. {0x5790, 0x08},
  619. {0x5791, 0x04},
  620. {0x5792, 0x00},
  621. {0x5793, 0x52},
  622. {0x5794, 0xa3},
  623. {0x3503, 0x00},
  624. {0x5045, 0x05},
  625. {0x4003, 0x40},
  626. {0x5048, 0x40}
  627. };
  628. static const struct ov5670_reg mode_648x486_regs[] = {
  629. {0x3000, 0x00},
  630. {0x3002, 0x21},
  631. {0x3005, 0xf0},
  632. {0x3007, 0x00},
  633. {0x3015, 0x0f},
  634. {0x3018, 0x32},
  635. {0x301a, 0xf0},
  636. {0x301b, 0xf0},
  637. {0x301c, 0xf0},
  638. {0x301d, 0xf0},
  639. {0x301e, 0xf0},
  640. {0x3030, 0x00},
  641. {0x3031, 0x0a},
  642. {0x303c, 0xff},
  643. {0x303e, 0xff},
  644. {0x3040, 0xf0},
  645. {0x3041, 0x00},
  646. {0x3042, 0xf0},
  647. {0x3106, 0x11},
  648. {0x3500, 0x00},
  649. {0x3501, 0x80},
  650. {0x3502, 0x00},
  651. {0x3503, 0x04},
  652. {0x3504, 0x03},
  653. {0x3505, 0x83},
  654. {0x3508, 0x04},
  655. {0x3509, 0x00},
  656. {0x350e, 0x04},
  657. {0x350f, 0x00},
  658. {0x3510, 0x00},
  659. {0x3511, 0x02},
  660. {0x3512, 0x00},
  661. {0x3601, 0xc8},
  662. {0x3610, 0x88},
  663. {0x3612, 0x48},
  664. {0x3614, 0x5b},
  665. {0x3615, 0x96},
  666. {0x3621, 0xd0},
  667. {0x3622, 0x00},
  668. {0x3623, 0x04},
  669. {0x3633, 0x13},
  670. {0x3634, 0x13},
  671. {0x3635, 0x13},
  672. {0x3636, 0x13},
  673. {0x3645, 0x13},
  674. {0x3646, 0x82},
  675. {0x3650, 0x00},
  676. {0x3652, 0xff},
  677. {0x3655, 0x20},
  678. {0x3656, 0xff},
  679. {0x365a, 0xff},
  680. {0x365e, 0xff},
  681. {0x3668, 0x00},
  682. {0x366a, 0x07},
  683. {0x366e, 0x08},
  684. {0x366d, 0x00},
  685. {0x366f, 0x80},
  686. {0x3700, 0x28},
  687. {0x3701, 0x10},
  688. {0x3702, 0x3a},
  689. {0x3703, 0x19},
  690. {0x3704, 0x10},
  691. {0x3705, 0x00},
  692. {0x3706, 0x66},
  693. {0x3707, 0x08},
  694. {0x3708, 0x34},
  695. {0x3709, 0x40},
  696. {0x370a, 0x01},
  697. {0x370b, 0x1b},
  698. {0x3714, 0x24},
  699. {0x371a, 0x3e},
  700. {0x3733, 0x00},
  701. {0x3734, 0x00},
  702. {0x373a, 0x05},
  703. {0x373b, 0x06},
  704. {0x373c, 0x0a},
  705. {0x373f, 0xa0},
  706. {0x3755, 0x00},
  707. {0x3758, 0x00},
  708. {0x375b, 0x0e},
  709. {0x3766, 0x5f},
  710. {0x3768, 0x00},
  711. {0x3769, 0x22},
  712. {0x3773, 0x08},
  713. {0x3774, 0x1f},
  714. {0x3776, 0x06},
  715. {0x37a0, 0x88},
  716. {0x37a1, 0x5c},
  717. {0x37a7, 0x88},
  718. {0x37a8, 0x70},
  719. {0x37aa, 0x88},
  720. {0x37ab, 0x48},
  721. {0x37b3, 0x66},
  722. {0x37c2, 0x04},
  723. {0x37c5, 0x00},
  724. {0x37c8, 0x00},
  725. {0x3800, 0x00},
  726. {0x3801, 0x0c},
  727. {0x3802, 0x00},
  728. {0x3803, 0x04},
  729. {0x3804, 0x0a},
  730. {0x3805, 0x33},
  731. {0x3806, 0x07},
  732. {0x3807, 0xa3},
  733. {0x3808, 0x02},
  734. {0x3809, 0x88},
  735. {0x380a, 0x01},
  736. {0x380b, 0xe6},
  737. {0x380c, 0x06},
  738. {0x380d, 0x90},
  739. {0x380e, 0x08},
  740. {0x380f, 0x08},
  741. {0x3811, 0x04},
  742. {0x3813, 0x02},
  743. {0x3814, 0x07},
  744. {0x3815, 0x01},
  745. {0x3816, 0x00},
  746. {0x3817, 0x00},
  747. {0x3818, 0x00},
  748. {0x3819, 0x00},
  749. {0x3820, 0x94},
  750. {0x3821, 0xc6},
  751. {0x3822, 0x48},
  752. {0x3826, 0x00},
  753. {0x3827, 0x08},
  754. {0x382a, 0x07},
  755. {0x382b, 0x01},
  756. {0x3830, 0x08},
  757. {0x3836, 0x02},
  758. {0x3837, 0x00},
  759. {0x3838, 0x10},
  760. {0x3841, 0xff},
  761. {0x3846, 0x48},
  762. {0x3861, 0x00},
  763. {0x3862, 0x04},
  764. {0x3863, 0x06},
  765. {0x3a11, 0x01},
  766. {0x3a12, 0x78},
  767. {0x3b00, 0x00},
  768. {0x3b02, 0x00},
  769. {0x3b03, 0x00},
  770. {0x3b04, 0x00},
  771. {0x3b05, 0x00},
  772. {0x3c00, 0x89},
  773. {0x3c01, 0xab},
  774. {0x3c02, 0x01},
  775. {0x3c03, 0x00},
  776. {0x3c04, 0x00},
  777. {0x3c05, 0x03},
  778. {0x3c06, 0x00},
  779. {0x3c07, 0x05},
  780. {0x3c0c, 0x00},
  781. {0x3c0d, 0x00},
  782. {0x3c0e, 0x00},
  783. {0x3c0f, 0x00},
  784. {0x3c40, 0x00},
  785. {0x3c41, 0xa3},
  786. {0x3c43, 0x7d},
  787. {0x3c45, 0xd7},
  788. {0x3c47, 0xfc},
  789. {0x3c50, 0x05},
  790. {0x3c52, 0xaa},
  791. {0x3c54, 0x71},
  792. {0x3c56, 0x80},
  793. {0x3d85, 0x17},
  794. {0x3f03, 0x00},
  795. {0x3f0a, 0x00},
  796. {0x3f0b, 0x00},
  797. {0x4001, 0x60},
  798. {0x4009, 0x05},
  799. {0x4020, 0x00},
  800. {0x4021, 0x00},
  801. {0x4022, 0x00},
  802. {0x4023, 0x00},
  803. {0x4024, 0x00},
  804. {0x4025, 0x00},
  805. {0x4026, 0x00},
  806. {0x4027, 0x00},
  807. {0x4028, 0x00},
  808. {0x4029, 0x00},
  809. {0x402a, 0x00},
  810. {0x402b, 0x00},
  811. {0x402c, 0x00},
  812. {0x402d, 0x00},
  813. {0x402e, 0x00},
  814. {0x402f, 0x00},
  815. {0x4040, 0x00},
  816. {0x4041, 0x03},
  817. {0x4042, 0x00},
  818. {0x4043, 0x7A},
  819. {0x4044, 0x00},
  820. {0x4045, 0x7A},
  821. {0x4046, 0x00},
  822. {0x4047, 0x7A},
  823. {0x4048, 0x00},
  824. {0x4049, 0x7A},
  825. {0x4307, 0x30},
  826. {0x4500, 0x58},
  827. {0x4501, 0x04},
  828. {0x4502, 0x40},
  829. {0x4503, 0x10},
  830. {0x4508, 0x55},
  831. {0x4509, 0x55},
  832. {0x450a, 0x02},
  833. {0x450b, 0x00},
  834. {0x4600, 0x00},
  835. {0x4601, 0x40},
  836. {0x4700, 0xa4},
  837. {0x4800, 0x4c},
  838. {0x4816, 0x53},
  839. {0x481f, 0x40},
  840. {0x4837, 0x13},
  841. {0x5000, 0x56},
  842. {0x5001, 0x01},
  843. {0x5002, 0x28},
  844. {0x5004, 0x0c},
  845. {0x5006, 0x0c},
  846. {0x5007, 0xe0},
  847. {0x5008, 0x01},
  848. {0x5009, 0xb0},
  849. {0x5901, 0x00},
  850. {0x5a01, 0x00},
  851. {0x5a03, 0x00},
  852. {0x5a04, 0x0c},
  853. {0x5a05, 0xe0},
  854. {0x5a06, 0x09},
  855. {0x5a07, 0xb0},
  856. {0x5a08, 0x06},
  857. {0x5e00, 0x00},
  858. {0x3734, 0x40},
  859. {0x5b00, 0x01},
  860. {0x5b01, 0x10},
  861. {0x5b02, 0x01},
  862. {0x5b03, 0xdb},
  863. {0x3d8c, 0x71},
  864. {0x3d8d, 0xea},
  865. {0x4017, 0x10},
  866. {0x3618, 0x2a},
  867. {0x5780, 0x3e},
  868. {0x5781, 0x0f},
  869. {0x5782, 0x44},
  870. {0x5783, 0x02},
  871. {0x5784, 0x01},
  872. {0x5785, 0x01},
  873. {0x5786, 0x00},
  874. {0x5787, 0x04},
  875. {0x5788, 0x02},
  876. {0x5789, 0x0f},
  877. {0x578a, 0xfd},
  878. {0x578b, 0xf5},
  879. {0x578c, 0xf5},
  880. {0x578d, 0x03},
  881. {0x578e, 0x08},
  882. {0x578f, 0x0c},
  883. {0x5790, 0x08},
  884. {0x5791, 0x06},
  885. {0x5792, 0x00},
  886. {0x5793, 0x52},
  887. {0x5794, 0xa3},
  888. {0x3503, 0x00},
  889. {0x5045, 0x05},
  890. {0x4003, 0x40},
  891. {0x5048, 0x40}
  892. };
  893. static const struct ov5670_reg mode_2560x1440_regs[] = {
  894. {0x3000, 0x00},
  895. {0x3002, 0x21},
  896. {0x3005, 0xf0},
  897. {0x3007, 0x00},
  898. {0x3015, 0x0f},
  899. {0x3018, 0x32},
  900. {0x301a, 0xf0},
  901. {0x301b, 0xf0},
  902. {0x301c, 0xf0},
  903. {0x301d, 0xf0},
  904. {0x301e, 0xf0},
  905. {0x3030, 0x00},
  906. {0x3031, 0x0a},
  907. {0x303c, 0xff},
  908. {0x303e, 0xff},
  909. {0x3040, 0xf0},
  910. {0x3041, 0x00},
  911. {0x3042, 0xf0},
  912. {0x3106, 0x11},
  913. {0x3500, 0x00},
  914. {0x3501, 0x80},
  915. {0x3502, 0x00},
  916. {0x3503, 0x04},
  917. {0x3504, 0x03},
  918. {0x3505, 0x83},
  919. {0x3508, 0x04},
  920. {0x3509, 0x00},
  921. {0x350e, 0x04},
  922. {0x350f, 0x00},
  923. {0x3510, 0x00},
  924. {0x3511, 0x02},
  925. {0x3512, 0x00},
  926. {0x3601, 0xc8},
  927. {0x3610, 0x88},
  928. {0x3612, 0x48},
  929. {0x3614, 0x5b},
  930. {0x3615, 0x96},
  931. {0x3621, 0xd0},
  932. {0x3622, 0x00},
  933. {0x3623, 0x00},
  934. {0x3633, 0x13},
  935. {0x3634, 0x13},
  936. {0x3635, 0x13},
  937. {0x3636, 0x13},
  938. {0x3645, 0x13},
  939. {0x3646, 0x82},
  940. {0x3650, 0x00},
  941. {0x3652, 0xff},
  942. {0x3655, 0x20},
  943. {0x3656, 0xff},
  944. {0x365a, 0xff},
  945. {0x365e, 0xff},
  946. {0x3668, 0x00},
  947. {0x366a, 0x07},
  948. {0x366e, 0x10},
  949. {0x366d, 0x00},
  950. {0x366f, 0x80},
  951. {0x3700, 0x28},
  952. {0x3701, 0x10},
  953. {0x3702, 0x3a},
  954. {0x3703, 0x19},
  955. {0x3704, 0x10},
  956. {0x3705, 0x00},
  957. {0x3706, 0x66},
  958. {0x3707, 0x08},
  959. {0x3708, 0x34},
  960. {0x3709, 0x40},
  961. {0x370a, 0x01},
  962. {0x370b, 0x1b},
  963. {0x3714, 0x24},
  964. {0x371a, 0x3e},
  965. {0x3733, 0x00},
  966. {0x3734, 0x00},
  967. {0x373a, 0x05},
  968. {0x373b, 0x06},
  969. {0x373c, 0x0a},
  970. {0x373f, 0xa0},
  971. {0x3755, 0x00},
  972. {0x3758, 0x00},
  973. {0x375b, 0x0e},
  974. {0x3766, 0x5f},
  975. {0x3768, 0x00},
  976. {0x3769, 0x22},
  977. {0x3773, 0x08},
  978. {0x3774, 0x1f},
  979. {0x3776, 0x06},
  980. {0x37a0, 0x88},
  981. {0x37a1, 0x5c},
  982. {0x37a7, 0x88},
  983. {0x37a8, 0x70},
  984. {0x37aa, 0x88},
  985. {0x37ab, 0x48},
  986. {0x37b3, 0x66},
  987. {0x37c2, 0x04},
  988. {0x37c5, 0x00},
  989. {0x37c8, 0x00},
  990. {0x3800, 0x00},
  991. {0x3801, 0x0c},
  992. {0x3802, 0x00},
  993. {0x3803, 0x04},
  994. {0x3804, 0x0a},
  995. {0x3805, 0x33},
  996. {0x3806, 0x07},
  997. {0x3807, 0xa3},
  998. {0x3808, 0x0a},
  999. {0x3809, 0x00},
  1000. {0x380a, 0x05},
  1001. {0x380b, 0xa0},
  1002. {0x380c, 0x06},
  1003. {0x380d, 0x90},
  1004. {0x380e, 0x08},
  1005. {0x380f, 0x08},
  1006. {0x3811, 0x04},
  1007. {0x3813, 0x02},
  1008. {0x3814, 0x01},
  1009. {0x3815, 0x01},
  1010. {0x3816, 0x00},
  1011. {0x3817, 0x00},
  1012. {0x3818, 0x00},
  1013. {0x3819, 0x00},
  1014. {0x3820, 0x84},
  1015. {0x3821, 0x46},
  1016. {0x3822, 0x48},
  1017. {0x3826, 0x00},
  1018. {0x3827, 0x08},
  1019. {0x382a, 0x01},
  1020. {0x382b, 0x01},
  1021. {0x3830, 0x08},
  1022. {0x3836, 0x02},
  1023. {0x3837, 0x00},
  1024. {0x3838, 0x10},
  1025. {0x3841, 0xff},
  1026. {0x3846, 0x48},
  1027. {0x3861, 0x00},
  1028. {0x3862, 0x04},
  1029. {0x3863, 0x06},
  1030. {0x3a11, 0x01},
  1031. {0x3a12, 0x78},
  1032. {0x3b00, 0x00},
  1033. {0x3b02, 0x00},
  1034. {0x3b03, 0x00},
  1035. {0x3b04, 0x00},
  1036. {0x3b05, 0x00},
  1037. {0x3c00, 0x89},
  1038. {0x3c01, 0xab},
  1039. {0x3c02, 0x01},
  1040. {0x3c03, 0x00},
  1041. {0x3c04, 0x00},
  1042. {0x3c05, 0x03},
  1043. {0x3c06, 0x00},
  1044. {0x3c07, 0x05},
  1045. {0x3c0c, 0x00},
  1046. {0x3c0d, 0x00},
  1047. {0x3c0e, 0x00},
  1048. {0x3c0f, 0x00},
  1049. {0x3c40, 0x00},
  1050. {0x3c41, 0xa3},
  1051. {0x3c43, 0x7d},
  1052. {0x3c45, 0xd7},
  1053. {0x3c47, 0xfc},
  1054. {0x3c50, 0x05},
  1055. {0x3c52, 0xaa},
  1056. {0x3c54, 0x71},
  1057. {0x3c56, 0x80},
  1058. {0x3d85, 0x17},
  1059. {0x3f03, 0x00},
  1060. {0x3f0a, 0x00},
  1061. {0x3f0b, 0x00},
  1062. {0x4001, 0x60},
  1063. {0x4009, 0x0d},
  1064. {0x4020, 0x00},
  1065. {0x4021, 0x00},
  1066. {0x4022, 0x00},
  1067. {0x4023, 0x00},
  1068. {0x4024, 0x00},
  1069. {0x4025, 0x00},
  1070. {0x4026, 0x00},
  1071. {0x4027, 0x00},
  1072. {0x4028, 0x00},
  1073. {0x4029, 0x00},
  1074. {0x402a, 0x00},
  1075. {0x402b, 0x00},
  1076. {0x402c, 0x00},
  1077. {0x402d, 0x00},
  1078. {0x402e, 0x00},
  1079. {0x402f, 0x00},
  1080. {0x4040, 0x00},
  1081. {0x4041, 0x03},
  1082. {0x4042, 0x00},
  1083. {0x4043, 0x7A},
  1084. {0x4044, 0x00},
  1085. {0x4045, 0x7A},
  1086. {0x4046, 0x00},
  1087. {0x4047, 0x7A},
  1088. {0x4048, 0x00},
  1089. {0x4049, 0x7A},
  1090. {0x4307, 0x30},
  1091. {0x4500, 0x58},
  1092. {0x4501, 0x04},
  1093. {0x4502, 0x40},
  1094. {0x4503, 0x10},
  1095. {0x4508, 0xaa},
  1096. {0x4509, 0xaa},
  1097. {0x450a, 0x00},
  1098. {0x450b, 0x00},
  1099. {0x4600, 0x01},
  1100. {0x4601, 0x00},
  1101. {0x4700, 0xa4},
  1102. {0x4800, 0x4c},
  1103. {0x4816, 0x53},
  1104. {0x481f, 0x40},
  1105. {0x4837, 0x13},
  1106. {0x5000, 0x56},
  1107. {0x5001, 0x01},
  1108. {0x5002, 0x28},
  1109. {0x5004, 0x0c},
  1110. {0x5006, 0x0c},
  1111. {0x5007, 0xe0},
  1112. {0x5008, 0x01},
  1113. {0x5009, 0xb0},
  1114. {0x5901, 0x00},
  1115. {0x5a01, 0x00},
  1116. {0x5a03, 0x00},
  1117. {0x5a04, 0x0c},
  1118. {0x5a05, 0xe0},
  1119. {0x5a06, 0x09},
  1120. {0x5a07, 0xb0},
  1121. {0x5a08, 0x06},
  1122. {0x5e00, 0x00},
  1123. {0x3734, 0x40},
  1124. {0x5b00, 0x01},
  1125. {0x5b01, 0x10},
  1126. {0x5b02, 0x01},
  1127. {0x5b03, 0xdb},
  1128. {0x3d8c, 0x71},
  1129. {0x3d8d, 0xea},
  1130. {0x4017, 0x08},
  1131. {0x3618, 0x2a},
  1132. {0x5780, 0x3e},
  1133. {0x5781, 0x0f},
  1134. {0x5782, 0x44},
  1135. {0x5783, 0x02},
  1136. {0x5784, 0x01},
  1137. {0x5785, 0x01},
  1138. {0x5786, 0x00},
  1139. {0x5787, 0x04},
  1140. {0x5788, 0x02},
  1141. {0x5789, 0x0f},
  1142. {0x578a, 0xfd},
  1143. {0x578b, 0xf5},
  1144. {0x578c, 0xf5},
  1145. {0x578d, 0x03},
  1146. {0x578e, 0x08},
  1147. {0x578f, 0x0c},
  1148. {0x5790, 0x08},
  1149. {0x5791, 0x06},
  1150. {0x5792, 0x00},
  1151. {0x5793, 0x52},
  1152. {0x5794, 0xa3},
  1153. {0x5045, 0x05},
  1154. {0x4003, 0x40},
  1155. {0x5048, 0x40}
  1156. };
  1157. static const struct ov5670_reg mode_1280x720_regs[] = {
  1158. {0x3000, 0x00},
  1159. {0x3002, 0x21},
  1160. {0x3005, 0xf0},
  1161. {0x3007, 0x00},
  1162. {0x3015, 0x0f},
  1163. {0x3018, 0x32},
  1164. {0x301a, 0xf0},
  1165. {0x301b, 0xf0},
  1166. {0x301c, 0xf0},
  1167. {0x301d, 0xf0},
  1168. {0x301e, 0xf0},
  1169. {0x3030, 0x00},
  1170. {0x3031, 0x0a},
  1171. {0x303c, 0xff},
  1172. {0x303e, 0xff},
  1173. {0x3040, 0xf0},
  1174. {0x3041, 0x00},
  1175. {0x3042, 0xf0},
  1176. {0x3106, 0x11},
  1177. {0x3500, 0x00},
  1178. {0x3501, 0x80},
  1179. {0x3502, 0x00},
  1180. {0x3503, 0x04},
  1181. {0x3504, 0x03},
  1182. {0x3505, 0x83},
  1183. {0x3508, 0x04},
  1184. {0x3509, 0x00},
  1185. {0x350e, 0x04},
  1186. {0x350f, 0x00},
  1187. {0x3510, 0x00},
  1188. {0x3511, 0x02},
  1189. {0x3512, 0x00},
  1190. {0x3601, 0xc8},
  1191. {0x3610, 0x88},
  1192. {0x3612, 0x48},
  1193. {0x3614, 0x5b},
  1194. {0x3615, 0x96},
  1195. {0x3621, 0xd0},
  1196. {0x3622, 0x00},
  1197. {0x3623, 0x00},
  1198. {0x3633, 0x13},
  1199. {0x3634, 0x13},
  1200. {0x3635, 0x13},
  1201. {0x3636, 0x13},
  1202. {0x3645, 0x13},
  1203. {0x3646, 0x82},
  1204. {0x3650, 0x00},
  1205. {0x3652, 0xff},
  1206. {0x3655, 0x20},
  1207. {0x3656, 0xff},
  1208. {0x365a, 0xff},
  1209. {0x365e, 0xff},
  1210. {0x3668, 0x00},
  1211. {0x366a, 0x07},
  1212. {0x366e, 0x08},
  1213. {0x366d, 0x00},
  1214. {0x366f, 0x80},
  1215. {0x3700, 0x28},
  1216. {0x3701, 0x10},
  1217. {0x3702, 0x3a},
  1218. {0x3703, 0x19},
  1219. {0x3704, 0x10},
  1220. {0x3705, 0x00},
  1221. {0x3706, 0x66},
  1222. {0x3707, 0x08},
  1223. {0x3708, 0x34},
  1224. {0x3709, 0x40},
  1225. {0x370a, 0x01},
  1226. {0x370b, 0x1b},
  1227. {0x3714, 0x24},
  1228. {0x371a, 0x3e},
  1229. {0x3733, 0x00},
  1230. {0x3734, 0x00},
  1231. {0x373a, 0x05},
  1232. {0x373b, 0x06},
  1233. {0x373c, 0x0a},
  1234. {0x373f, 0xa0},
  1235. {0x3755, 0x00},
  1236. {0x3758, 0x00},
  1237. {0x375b, 0x0e},
  1238. {0x3766, 0x5f},
  1239. {0x3768, 0x00},
  1240. {0x3769, 0x22},
  1241. {0x3773, 0x08},
  1242. {0x3774, 0x1f},
  1243. {0x3776, 0x06},
  1244. {0x37a0, 0x88},
  1245. {0x37a1, 0x5c},
  1246. {0x37a7, 0x88},
  1247. {0x37a8, 0x70},
  1248. {0x37aa, 0x88},
  1249. {0x37ab, 0x48},
  1250. {0x37b3, 0x66},
  1251. {0x37c2, 0x04},
  1252. {0x37c5, 0x00},
  1253. {0x37c8, 0x00},
  1254. {0x3800, 0x00},
  1255. {0x3801, 0x0c},
  1256. {0x3802, 0x00},
  1257. {0x3803, 0x04},
  1258. {0x3804, 0x0a},
  1259. {0x3805, 0x33},
  1260. {0x3806, 0x07},
  1261. {0x3807, 0xa3},
  1262. {0x3808, 0x05},
  1263. {0x3809, 0x00},
  1264. {0x380a, 0x02},
  1265. {0x380b, 0xd0},
  1266. {0x380c, 0x06},
  1267. {0x380d, 0x90},
  1268. {0x380e, 0x08},
  1269. {0x380f, 0x08},
  1270. {0x3811, 0x04},
  1271. {0x3813, 0x02},
  1272. {0x3814, 0x03},
  1273. {0x3815, 0x01},
  1274. {0x3816, 0x00},
  1275. {0x3817, 0x00},
  1276. {0x3818, 0x00},
  1277. {0x3819, 0x00},
  1278. {0x3820, 0x94},
  1279. {0x3821, 0x47},
  1280. {0x3822, 0x48},
  1281. {0x3826, 0x00},
  1282. {0x3827, 0x08},
  1283. {0x382a, 0x03},
  1284. {0x382b, 0x01},
  1285. {0x3830, 0x08},
  1286. {0x3836, 0x02},
  1287. {0x3837, 0x00},
  1288. {0x3838, 0x10},
  1289. {0x3841, 0xff},
  1290. {0x3846, 0x48},
  1291. {0x3861, 0x00},
  1292. {0x3862, 0x04},
  1293. {0x3863, 0x06},
  1294. {0x3a11, 0x01},
  1295. {0x3a12, 0x78},
  1296. {0x3b00, 0x00},
  1297. {0x3b02, 0x00},
  1298. {0x3b03, 0x00},
  1299. {0x3b04, 0x00},
  1300. {0x3b05, 0x00},
  1301. {0x3c00, 0x89},
  1302. {0x3c01, 0xab},
  1303. {0x3c02, 0x01},
  1304. {0x3c03, 0x00},
  1305. {0x3c04, 0x00},
  1306. {0x3c05, 0x03},
  1307. {0x3c06, 0x00},
  1308. {0x3c07, 0x05},
  1309. {0x3c0c, 0x00},
  1310. {0x3c0d, 0x00},
  1311. {0x3c0e, 0x00},
  1312. {0x3c0f, 0x00},
  1313. {0x3c40, 0x00},
  1314. {0x3c41, 0xa3},
  1315. {0x3c43, 0x7d},
  1316. {0x3c45, 0xd7},
  1317. {0x3c47, 0xfc},
  1318. {0x3c50, 0x05},
  1319. {0x3c52, 0xaa},
  1320. {0x3c54, 0x71},
  1321. {0x3c56, 0x80},
  1322. {0x3d85, 0x17},
  1323. {0x3f03, 0x00},
  1324. {0x3f0a, 0x00},
  1325. {0x3f0b, 0x00},
  1326. {0x4001, 0x60},
  1327. {0x4009, 0x05},
  1328. {0x4020, 0x00},
  1329. {0x4021, 0x00},
  1330. {0x4022, 0x00},
  1331. {0x4023, 0x00},
  1332. {0x4024, 0x00},
  1333. {0x4025, 0x00},
  1334. {0x4026, 0x00},
  1335. {0x4027, 0x00},
  1336. {0x4028, 0x00},
  1337. {0x4029, 0x00},
  1338. {0x402a, 0x00},
  1339. {0x402b, 0x00},
  1340. {0x402c, 0x00},
  1341. {0x402d, 0x00},
  1342. {0x402e, 0x00},
  1343. {0x402f, 0x00},
  1344. {0x4040, 0x00},
  1345. {0x4041, 0x03},
  1346. {0x4042, 0x00},
  1347. {0x4043, 0x7A},
  1348. {0x4044, 0x00},
  1349. {0x4045, 0x7A},
  1350. {0x4046, 0x00},
  1351. {0x4047, 0x7A},
  1352. {0x4048, 0x00},
  1353. {0x4049, 0x7A},
  1354. {0x4307, 0x30},
  1355. {0x4500, 0x58},
  1356. {0x4501, 0x04},
  1357. {0x4502, 0x48},
  1358. {0x4503, 0x10},
  1359. {0x4508, 0x55},
  1360. {0x4509, 0x55},
  1361. {0x450a, 0x00},
  1362. {0x450b, 0x00},
  1363. {0x4600, 0x00},
  1364. {0x4601, 0x80},
  1365. {0x4700, 0xa4},
  1366. {0x4800, 0x4c},
  1367. {0x4816, 0x53},
  1368. {0x481f, 0x40},
  1369. {0x4837, 0x13},
  1370. {0x5000, 0x56},
  1371. {0x5001, 0x01},
  1372. {0x5002, 0x28},
  1373. {0x5004, 0x0c},
  1374. {0x5006, 0x0c},
  1375. {0x5007, 0xe0},
  1376. {0x5008, 0x01},
  1377. {0x5009, 0xb0},
  1378. {0x5901, 0x00},
  1379. {0x5a01, 0x00},
  1380. {0x5a03, 0x00},
  1381. {0x5a04, 0x0c},
  1382. {0x5a05, 0xe0},
  1383. {0x5a06, 0x09},
  1384. {0x5a07, 0xb0},
  1385. {0x5a08, 0x06},
  1386. {0x5e00, 0x00},
  1387. {0x3734, 0x40},
  1388. {0x5b00, 0x01},
  1389. {0x5b01, 0x10},
  1390. {0x5b02, 0x01},
  1391. {0x5b03, 0xdb},
  1392. {0x3d8c, 0x71},
  1393. {0x3d8d, 0xea},
  1394. {0x4017, 0x10},
  1395. {0x3618, 0x2a},
  1396. {0x5780, 0x3e},
  1397. {0x5781, 0x0f},
  1398. {0x5782, 0x44},
  1399. {0x5783, 0x02},
  1400. {0x5784, 0x01},
  1401. {0x5785, 0x01},
  1402. {0x5786, 0x00},
  1403. {0x5787, 0x04},
  1404. {0x5788, 0x02},
  1405. {0x5789, 0x0f},
  1406. {0x578a, 0xfd},
  1407. {0x578b, 0xf5},
  1408. {0x578c, 0xf5},
  1409. {0x578d, 0x03},
  1410. {0x578e, 0x08},
  1411. {0x578f, 0x0c},
  1412. {0x5790, 0x08},
  1413. {0x5791, 0x06},
  1414. {0x5792, 0x00},
  1415. {0x5793, 0x52},
  1416. {0x5794, 0xa3},
  1417. {0x3503, 0x00},
  1418. {0x5045, 0x05},
  1419. {0x4003, 0x40},
  1420. {0x5048, 0x40}
  1421. };
  1422. static const struct ov5670_reg mode_640x360_regs[] = {
  1423. {0x3000, 0x00},
  1424. {0x3002, 0x21},
  1425. {0x3005, 0xf0},
  1426. {0x3007, 0x00},
  1427. {0x3015, 0x0f},
  1428. {0x3018, 0x32},
  1429. {0x301a, 0xf0},
  1430. {0x301b, 0xf0},
  1431. {0x301c, 0xf0},
  1432. {0x301d, 0xf0},
  1433. {0x301e, 0xf0},
  1434. {0x3030, 0x00},
  1435. {0x3031, 0x0a},
  1436. {0x303c, 0xff},
  1437. {0x303e, 0xff},
  1438. {0x3040, 0xf0},
  1439. {0x3041, 0x00},
  1440. {0x3042, 0xf0},
  1441. {0x3106, 0x11},
  1442. {0x3500, 0x00},
  1443. {0x3501, 0x80},
  1444. {0x3502, 0x00},
  1445. {0x3503, 0x04},
  1446. {0x3504, 0x03},
  1447. {0x3505, 0x83},
  1448. {0x3508, 0x04},
  1449. {0x3509, 0x00},
  1450. {0x350e, 0x04},
  1451. {0x350f, 0x00},
  1452. {0x3510, 0x00},
  1453. {0x3511, 0x02},
  1454. {0x3512, 0x00},
  1455. {0x3601, 0xc8},
  1456. {0x3610, 0x88},
  1457. {0x3612, 0x48},
  1458. {0x3614, 0x5b},
  1459. {0x3615, 0x96},
  1460. {0x3621, 0xd0},
  1461. {0x3622, 0x00},
  1462. {0x3623, 0x04},
  1463. {0x3633, 0x13},
  1464. {0x3634, 0x13},
  1465. {0x3635, 0x13},
  1466. {0x3636, 0x13},
  1467. {0x3645, 0x13},
  1468. {0x3646, 0x82},
  1469. {0x3650, 0x00},
  1470. {0x3652, 0xff},
  1471. {0x3655, 0x20},
  1472. {0x3656, 0xff},
  1473. {0x365a, 0xff},
  1474. {0x365e, 0xff},
  1475. {0x3668, 0x00},
  1476. {0x366a, 0x07},
  1477. {0x366e, 0x08},
  1478. {0x366d, 0x00},
  1479. {0x366f, 0x80},
  1480. {0x3700, 0x28},
  1481. {0x3701, 0x10},
  1482. {0x3702, 0x3a},
  1483. {0x3703, 0x19},
  1484. {0x3704, 0x10},
  1485. {0x3705, 0x00},
  1486. {0x3706, 0x66},
  1487. {0x3707, 0x08},
  1488. {0x3708, 0x34},
  1489. {0x3709, 0x40},
  1490. {0x370a, 0x01},
  1491. {0x370b, 0x1b},
  1492. {0x3714, 0x24},
  1493. {0x371a, 0x3e},
  1494. {0x3733, 0x00},
  1495. {0x3734, 0x00},
  1496. {0x373a, 0x05},
  1497. {0x373b, 0x06},
  1498. {0x373c, 0x0a},
  1499. {0x373f, 0xa0},
  1500. {0x3755, 0x00},
  1501. {0x3758, 0x00},
  1502. {0x375b, 0x0e},
  1503. {0x3766, 0x5f},
  1504. {0x3768, 0x00},
  1505. {0x3769, 0x22},
  1506. {0x3773, 0x08},
  1507. {0x3774, 0x1f},
  1508. {0x3776, 0x06},
  1509. {0x37a0, 0x88},
  1510. {0x37a1, 0x5c},
  1511. {0x37a7, 0x88},
  1512. {0x37a8, 0x70},
  1513. {0x37aa, 0x88},
  1514. {0x37ab, 0x48},
  1515. {0x37b3, 0x66},
  1516. {0x37c2, 0x04},
  1517. {0x37c5, 0x00},
  1518. {0x37c8, 0x00},
  1519. {0x3800, 0x00},
  1520. {0x3801, 0x0c},
  1521. {0x3802, 0x00},
  1522. {0x3803, 0x04},
  1523. {0x3804, 0x0a},
  1524. {0x3805, 0x33},
  1525. {0x3806, 0x07},
  1526. {0x3807, 0xa3},
  1527. {0x3808, 0x02},
  1528. {0x3809, 0x80},
  1529. {0x380a, 0x01},
  1530. {0x380b, 0x68},
  1531. {0x380c, 0x06},
  1532. {0x380d, 0x90},
  1533. {0x380e, 0x08},
  1534. {0x380f, 0x08},
  1535. {0x3811, 0x04},
  1536. {0x3813, 0x02},
  1537. {0x3814, 0x07},
  1538. {0x3815, 0x01},
  1539. {0x3816, 0x00},
  1540. {0x3817, 0x00},
  1541. {0x3818, 0x00},
  1542. {0x3819, 0x00},
  1543. {0x3820, 0x94},
  1544. {0x3821, 0xc6},
  1545. {0x3822, 0x48},
  1546. {0x3826, 0x00},
  1547. {0x3827, 0x08},
  1548. {0x382a, 0x07},
  1549. {0x382b, 0x01},
  1550. {0x3830, 0x08},
  1551. {0x3836, 0x02},
  1552. {0x3837, 0x00},
  1553. {0x3838, 0x10},
  1554. {0x3841, 0xff},
  1555. {0x3846, 0x48},
  1556. {0x3861, 0x00},
  1557. {0x3862, 0x04},
  1558. {0x3863, 0x06},
  1559. {0x3a11, 0x01},
  1560. {0x3a12, 0x78},
  1561. {0x3b00, 0x00},
  1562. {0x3b02, 0x00},
  1563. {0x3b03, 0x00},
  1564. {0x3b04, 0x00},
  1565. {0x3b05, 0x00},
  1566. {0x3c00, 0x89},
  1567. {0x3c01, 0xab},
  1568. {0x3c02, 0x01},
  1569. {0x3c03, 0x00},
  1570. {0x3c04, 0x00},
  1571. {0x3c05, 0x03},
  1572. {0x3c06, 0x00},
  1573. {0x3c07, 0x05},
  1574. {0x3c0c, 0x00},
  1575. {0x3c0d, 0x00},
  1576. {0x3c0e, 0x00},
  1577. {0x3c0f, 0x00},
  1578. {0x3c40, 0x00},
  1579. {0x3c41, 0xa3},
  1580. {0x3c43, 0x7d},
  1581. {0x3c45, 0xd7},
  1582. {0x3c47, 0xfc},
  1583. {0x3c50, 0x05},
  1584. {0x3c52, 0xaa},
  1585. {0x3c54, 0x71},
  1586. {0x3c56, 0x80},
  1587. {0x3d85, 0x17},
  1588. {0x3f03, 0x00},
  1589. {0x3f0a, 0x00},
  1590. {0x3f0b, 0x00},
  1591. {0x4001, 0x60},
  1592. {0x4009, 0x05},
  1593. {0x4020, 0x00},
  1594. {0x4021, 0x00},
  1595. {0x4022, 0x00},
  1596. {0x4023, 0x00},
  1597. {0x4024, 0x00},
  1598. {0x4025, 0x00},
  1599. {0x4026, 0x00},
  1600. {0x4027, 0x00},
  1601. {0x4028, 0x00},
  1602. {0x4029, 0x00},
  1603. {0x402a, 0x00},
  1604. {0x402b, 0x00},
  1605. {0x402c, 0x00},
  1606. {0x402d, 0x00},
  1607. {0x402e, 0x00},
  1608. {0x402f, 0x00},
  1609. {0x4040, 0x00},
  1610. {0x4041, 0x03},
  1611. {0x4042, 0x00},
  1612. {0x4043, 0x7A},
  1613. {0x4044, 0x00},
  1614. {0x4045, 0x7A},
  1615. {0x4046, 0x00},
  1616. {0x4047, 0x7A},
  1617. {0x4048, 0x00},
  1618. {0x4049, 0x7A},
  1619. {0x4307, 0x30},
  1620. {0x4500, 0x58},
  1621. {0x4501, 0x04},
  1622. {0x4502, 0x40},
  1623. {0x4503, 0x10},
  1624. {0x4508, 0x55},
  1625. {0x4509, 0x55},
  1626. {0x450a, 0x02},
  1627. {0x450b, 0x00},
  1628. {0x4600, 0x00},
  1629. {0x4601, 0x40},
  1630. {0x4700, 0xa4},
  1631. {0x4800, 0x4c},
  1632. {0x4816, 0x53},
  1633. {0x481f, 0x40},
  1634. {0x4837, 0x13},
  1635. {0x5000, 0x56},
  1636. {0x5001, 0x01},
  1637. {0x5002, 0x28},
  1638. {0x5004, 0x0c},
  1639. {0x5006, 0x0c},
  1640. {0x5007, 0xe0},
  1641. {0x5008, 0x01},
  1642. {0x5009, 0xb0},
  1643. {0x5901, 0x00},
  1644. {0x5a01, 0x00},
  1645. {0x5a03, 0x00},
  1646. {0x5a04, 0x0c},
  1647. {0x5a05, 0xe0},
  1648. {0x5a06, 0x09},
  1649. {0x5a07, 0xb0},
  1650. {0x5a08, 0x06},
  1651. {0x5e00, 0x00},
  1652. {0x3734, 0x40},
  1653. {0x5b00, 0x01},
  1654. {0x5b01, 0x10},
  1655. {0x5b02, 0x01},
  1656. {0x5b03, 0xdb},
  1657. {0x3d8c, 0x71},
  1658. {0x3d8d, 0xea},
  1659. {0x4017, 0x10},
  1660. {0x3618, 0x2a},
  1661. {0x5780, 0x3e},
  1662. {0x5781, 0x0f},
  1663. {0x5782, 0x44},
  1664. {0x5783, 0x02},
  1665. {0x5784, 0x01},
  1666. {0x5785, 0x01},
  1667. {0x5786, 0x00},
  1668. {0x5787, 0x04},
  1669. {0x5788, 0x02},
  1670. {0x5789, 0x0f},
  1671. {0x578a, 0xfd},
  1672. {0x578b, 0xf5},
  1673. {0x578c, 0xf5},
  1674. {0x578d, 0x03},
  1675. {0x578e, 0x08},
  1676. {0x578f, 0x0c},
  1677. {0x5790, 0x08},
  1678. {0x5791, 0x06},
  1679. {0x5792, 0x00},
  1680. {0x5793, 0x52},
  1681. {0x5794, 0xa3},
  1682. {0x3503, 0x00},
  1683. {0x5045, 0x05},
  1684. {0x4003, 0x40},
  1685. {0x5048, 0x40}
  1686. };
  1687. static const char * const ov5670_test_pattern_menu[] = {
  1688. "Disabled",
  1689. "Vertical Color Bar Type 1",
  1690. };
  1691. /* Supported link frequencies */
  1692. #define OV5670_LINK_FREQ_422MHZ 422400000
  1693. #define OV5670_LINK_FREQ_422MHZ_INDEX 0
  1694. static const struct ov5670_link_freq_config link_freq_configs[] = {
  1695. {
  1696. /* pixel_rate = link_freq * 2 * nr_of_lanes / bits_per_sample */
  1697. .pixel_rate = (OV5670_LINK_FREQ_422MHZ * 2 * 2) / 10,
  1698. .reg_list = {
  1699. .num_of_regs = ARRAY_SIZE(mipi_data_rate_840mbps),
  1700. .regs = mipi_data_rate_840mbps,
  1701. }
  1702. }
  1703. };
  1704. static const s64 link_freq_menu_items[] = {
  1705. OV5670_LINK_FREQ_422MHZ
  1706. };
  1707. /*
  1708. * OV5670 sensor supports following resolutions with full FOV:
  1709. * 4:3 ==> {2592x1944, 1296x972, 648x486}
  1710. * 16:9 ==> {2560x1440, 1280x720, 640x360}
  1711. */
  1712. static const struct ov5670_mode supported_modes[] = {
  1713. {
  1714. .width = 2592,
  1715. .height = 1944,
  1716. .vts_def = OV5670_VTS_30FPS,
  1717. .vts_min = OV5670_VTS_30FPS,
  1718. .reg_list = {
  1719. .num_of_regs = ARRAY_SIZE(mode_2592x1944_regs),
  1720. .regs = mode_2592x1944_regs,
  1721. },
  1722. .link_freq_index = OV5670_LINK_FREQ_422MHZ_INDEX,
  1723. },
  1724. {
  1725. .width = 1296,
  1726. .height = 972,
  1727. .vts_def = OV5670_VTS_30FPS,
  1728. .vts_min = 996,
  1729. .reg_list = {
  1730. .num_of_regs = ARRAY_SIZE(mode_1296x972_regs),
  1731. .regs = mode_1296x972_regs,
  1732. },
  1733. .link_freq_index = OV5670_LINK_FREQ_422MHZ_INDEX,
  1734. },
  1735. {
  1736. .width = 648,
  1737. .height = 486,
  1738. .vts_def = OV5670_VTS_30FPS,
  1739. .vts_min = 516,
  1740. .reg_list = {
  1741. .num_of_regs = ARRAY_SIZE(mode_648x486_regs),
  1742. .regs = mode_648x486_regs,
  1743. },
  1744. .link_freq_index = OV5670_LINK_FREQ_422MHZ_INDEX,
  1745. },
  1746. {
  1747. .width = 2560,
  1748. .height = 1440,
  1749. .vts_def = OV5670_VTS_30FPS,
  1750. .vts_min = OV5670_VTS_30FPS,
  1751. .reg_list = {
  1752. .num_of_regs = ARRAY_SIZE(mode_2560x1440_regs),
  1753. .regs = mode_2560x1440_regs,
  1754. },
  1755. .link_freq_index = OV5670_LINK_FREQ_422MHZ_INDEX,
  1756. },
  1757. {
  1758. .width = 1280,
  1759. .height = 720,
  1760. .vts_def = OV5670_VTS_30FPS,
  1761. .vts_min = 1020,
  1762. .reg_list = {
  1763. .num_of_regs = ARRAY_SIZE(mode_1280x720_regs),
  1764. .regs = mode_1280x720_regs,
  1765. },
  1766. .link_freq_index = OV5670_LINK_FREQ_422MHZ_INDEX,
  1767. },
  1768. {
  1769. .width = 640,
  1770. .height = 360,
  1771. .vts_def = OV5670_VTS_30FPS,
  1772. .vts_min = 510,
  1773. .reg_list = {
  1774. .num_of_regs = ARRAY_SIZE(mode_640x360_regs),
  1775. .regs = mode_640x360_regs,
  1776. },
  1777. .link_freq_index = OV5670_LINK_FREQ_422MHZ_INDEX,
  1778. }
  1779. };
  1780. struct ov5670 {
  1781. struct v4l2_subdev sd;
  1782. struct media_pad pad;
  1783. struct v4l2_ctrl_handler ctrl_handler;
  1784. /* V4L2 Controls */
  1785. struct v4l2_ctrl *link_freq;
  1786. struct v4l2_ctrl *pixel_rate;
  1787. struct v4l2_ctrl *vblank;
  1788. struct v4l2_ctrl *hblank;
  1789. struct v4l2_ctrl *exposure;
  1790. /* Current mode */
  1791. const struct ov5670_mode *cur_mode;
  1792. /* To serialize asynchronus callbacks */
  1793. struct mutex mutex;
  1794. /* Streaming on/off */
  1795. bool streaming;
  1796. };
  1797. #define to_ov5670(_sd) container_of(_sd, struct ov5670, sd)
  1798. /* Read registers up to 4 at a time */
  1799. static int ov5670_read_reg(struct ov5670 *ov5670, u16 reg, unsigned int len,
  1800. u32 *val)
  1801. {
  1802. struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
  1803. struct i2c_msg msgs[2];
  1804. u8 *data_be_p;
  1805. __be32 data_be = 0;
  1806. __be16 reg_addr_be = cpu_to_be16(reg);
  1807. int ret;
  1808. if (len > 4)
  1809. return -EINVAL;
  1810. data_be_p = (u8 *)&data_be;
  1811. /* Write register address */
  1812. msgs[0].addr = client->addr;
  1813. msgs[0].flags = 0;
  1814. msgs[0].len = 2;
  1815. msgs[0].buf = (u8 *)&reg_addr_be;
  1816. /* Read data from register */
  1817. msgs[1].addr = client->addr;
  1818. msgs[1].flags = I2C_M_RD;
  1819. msgs[1].len = len;
  1820. msgs[1].buf = &data_be_p[4 - len];
  1821. ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
  1822. if (ret != ARRAY_SIZE(msgs))
  1823. return -EIO;
  1824. *val = be32_to_cpu(data_be);
  1825. return 0;
  1826. }
  1827. /* Write registers up to 4 at a time */
  1828. static int ov5670_write_reg(struct ov5670 *ov5670, u16 reg, unsigned int len,
  1829. u32 val)
  1830. {
  1831. struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
  1832. int buf_i;
  1833. int val_i;
  1834. u8 buf[6];
  1835. u8 *val_p;
  1836. __be32 tmp;
  1837. if (len > 4)
  1838. return -EINVAL;
  1839. buf[0] = reg >> 8;
  1840. buf[1] = reg & 0xff;
  1841. tmp = cpu_to_be32(val);
  1842. val_p = (u8 *)&tmp;
  1843. buf_i = 2;
  1844. val_i = 4 - len;
  1845. while (val_i < 4)
  1846. buf[buf_i++] = val_p[val_i++];
  1847. if (i2c_master_send(client, buf, len + 2) != len + 2)
  1848. return -EIO;
  1849. return 0;
  1850. }
  1851. /* Write a list of registers */
  1852. static int ov5670_write_regs(struct ov5670 *ov5670,
  1853. const struct ov5670_reg *regs, unsigned int len)
  1854. {
  1855. struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
  1856. unsigned int i;
  1857. int ret;
  1858. for (i = 0; i < len; i++) {
  1859. ret = ov5670_write_reg(ov5670, regs[i].address, 1, regs[i].val);
  1860. if (ret) {
  1861. dev_err_ratelimited(
  1862. &client->dev,
  1863. "Failed to write reg 0x%4.4x. error = %d\n",
  1864. regs[i].address, ret);
  1865. return ret;
  1866. }
  1867. }
  1868. return 0;
  1869. }
  1870. static int ov5670_write_reg_list(struct ov5670 *ov5670,
  1871. const struct ov5670_reg_list *r_list)
  1872. {
  1873. return ov5670_write_regs(ov5670, r_list->regs, r_list->num_of_regs);
  1874. }
  1875. /* Open sub-device */
  1876. static int ov5670_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
  1877. {
  1878. struct ov5670 *ov5670 = to_ov5670(sd);
  1879. struct v4l2_mbus_framefmt *try_fmt =
  1880. v4l2_subdev_get_try_format(sd, fh->pad, 0);
  1881. mutex_lock(&ov5670->mutex);
  1882. /* Initialize try_fmt */
  1883. try_fmt->width = ov5670->cur_mode->width;
  1884. try_fmt->height = ov5670->cur_mode->height;
  1885. try_fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10;
  1886. try_fmt->field = V4L2_FIELD_NONE;
  1887. /* No crop or compose */
  1888. mutex_unlock(&ov5670->mutex);
  1889. return 0;
  1890. }
  1891. static int ov5670_update_digital_gain(struct ov5670 *ov5670, u32 d_gain)
  1892. {
  1893. int ret;
  1894. ret = ov5670_write_reg(ov5670, OV5670_REG_R_DGTL_GAIN,
  1895. OV5670_REG_VALUE_16BIT, d_gain);
  1896. if (ret)
  1897. return ret;
  1898. ret = ov5670_write_reg(ov5670, OV5670_REG_G_DGTL_GAIN,
  1899. OV5670_REG_VALUE_16BIT, d_gain);
  1900. if (ret)
  1901. return ret;
  1902. return ov5670_write_reg(ov5670, OV5670_REG_B_DGTL_GAIN,
  1903. OV5670_REG_VALUE_16BIT, d_gain);
  1904. }
  1905. static int ov5670_enable_test_pattern(struct ov5670 *ov5670, u32 pattern)
  1906. {
  1907. u32 val;
  1908. int ret;
  1909. /* Set the bayer order that we support */
  1910. ret = ov5670_write_reg(ov5670, OV5670_REG_TEST_PATTERN_CTRL,
  1911. OV5670_REG_VALUE_08BIT, 0);
  1912. if (ret)
  1913. return ret;
  1914. ret = ov5670_read_reg(ov5670, OV5670_REG_TEST_PATTERN,
  1915. OV5670_REG_VALUE_08BIT, &val);
  1916. if (ret)
  1917. return ret;
  1918. if (pattern)
  1919. val |= OV5670_TEST_PATTERN_ENABLE;
  1920. else
  1921. val &= ~OV5670_TEST_PATTERN_ENABLE;
  1922. return ov5670_write_reg(ov5670, OV5670_REG_TEST_PATTERN,
  1923. OV5670_REG_VALUE_08BIT, val);
  1924. }
  1925. /* Initialize control handlers */
  1926. static int ov5670_set_ctrl(struct v4l2_ctrl *ctrl)
  1927. {
  1928. struct ov5670 *ov5670 = container_of(ctrl->handler,
  1929. struct ov5670, ctrl_handler);
  1930. struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
  1931. s64 max;
  1932. int ret = 0;
  1933. /* Propagate change of current control to all related controls */
  1934. switch (ctrl->id) {
  1935. case V4L2_CID_VBLANK:
  1936. /* Update max exposure while meeting expected vblanking */
  1937. max = ov5670->cur_mode->height + ctrl->val - 8;
  1938. __v4l2_ctrl_modify_range(ov5670->exposure,
  1939. ov5670->exposure->minimum, max,
  1940. ov5670->exposure->step, max);
  1941. break;
  1942. }
  1943. /* V4L2 controls values will be applied only when power is already up */
  1944. if (pm_runtime_get_if_in_use(&client->dev) <= 0)
  1945. return 0;
  1946. switch (ctrl->id) {
  1947. case V4L2_CID_ANALOGUE_GAIN:
  1948. ret = ov5670_write_reg(ov5670, OV5670_REG_ANALOG_GAIN,
  1949. OV5670_REG_VALUE_16BIT, ctrl->val);
  1950. break;
  1951. case V4L2_CID_DIGITAL_GAIN:
  1952. ret = ov5670_update_digital_gain(ov5670, ctrl->val);
  1953. break;
  1954. case V4L2_CID_EXPOSURE:
  1955. /* 4 least significant bits of expsoure are fractional part */
  1956. ret = ov5670_write_reg(ov5670, OV5670_REG_EXPOSURE,
  1957. OV5670_REG_VALUE_24BIT, ctrl->val << 4);
  1958. break;
  1959. case V4L2_CID_VBLANK:
  1960. /* Update VTS that meets expected vertical blanking */
  1961. ret = ov5670_write_reg(ov5670, OV5670_REG_VTS,
  1962. OV5670_REG_VALUE_16BIT,
  1963. ov5670->cur_mode->height + ctrl->val);
  1964. break;
  1965. case V4L2_CID_TEST_PATTERN:
  1966. ret = ov5670_enable_test_pattern(ov5670, ctrl->val);
  1967. break;
  1968. default:
  1969. dev_info(&client->dev, "%s Unhandled id:0x%x, val:0x%x\n",
  1970. __func__, ctrl->id, ctrl->val);
  1971. break;
  1972. }
  1973. pm_runtime_put(&client->dev);
  1974. return ret;
  1975. }
  1976. static const struct v4l2_ctrl_ops ov5670_ctrl_ops = {
  1977. .s_ctrl = ov5670_set_ctrl,
  1978. };
  1979. /* Initialize control handlers */
  1980. static int ov5670_init_controls(struct ov5670 *ov5670)
  1981. {
  1982. struct v4l2_ctrl_handler *ctrl_hdlr;
  1983. s64 vblank_max;
  1984. s64 vblank_def;
  1985. s64 vblank_min;
  1986. s64 exposure_max;
  1987. int ret;
  1988. ctrl_hdlr = &ov5670->ctrl_handler;
  1989. ret = v4l2_ctrl_handler_init(ctrl_hdlr, 8);
  1990. if (ret)
  1991. return ret;
  1992. ctrl_hdlr->lock = &ov5670->mutex;
  1993. ov5670->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr,
  1994. &ov5670_ctrl_ops,
  1995. V4L2_CID_LINK_FREQ,
  1996. 0, 0, link_freq_menu_items);
  1997. if (ov5670->link_freq)
  1998. ov5670->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
  1999. /* By default, V4L2_CID_PIXEL_RATE is read only */
  2000. ov5670->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops,
  2001. V4L2_CID_PIXEL_RATE, 0,
  2002. link_freq_configs[0].pixel_rate,
  2003. 1,
  2004. link_freq_configs[0].pixel_rate);
  2005. vblank_max = OV5670_VTS_MAX - ov5670->cur_mode->height;
  2006. vblank_def = ov5670->cur_mode->vts_def - ov5670->cur_mode->height;
  2007. vblank_min = ov5670->cur_mode->vts_min - ov5670->cur_mode->height;
  2008. ov5670->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops,
  2009. V4L2_CID_VBLANK, vblank_min,
  2010. vblank_max, 1, vblank_def);
  2011. ov5670->hblank = v4l2_ctrl_new_std(
  2012. ctrl_hdlr, &ov5670_ctrl_ops, V4L2_CID_HBLANK,
  2013. OV5670_FIXED_PPL - ov5670->cur_mode->width,
  2014. OV5670_FIXED_PPL - ov5670->cur_mode->width, 1,
  2015. OV5670_FIXED_PPL - ov5670->cur_mode->width);
  2016. if (ov5670->hblank)
  2017. ov5670->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
  2018. /* Get min, max, step, default from sensor */
  2019. v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops, V4L2_CID_ANALOGUE_GAIN,
  2020. ANALOG_GAIN_MIN, ANALOG_GAIN_MAX, ANALOG_GAIN_STEP,
  2021. ANALOG_GAIN_DEFAULT);
  2022. /* Digital gain */
  2023. v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops, V4L2_CID_DIGITAL_GAIN,
  2024. OV5670_DGTL_GAIN_MIN, OV5670_DGTL_GAIN_MAX,
  2025. OV5670_DGTL_GAIN_STEP, OV5670_DGTL_GAIN_DEFAULT);
  2026. /* Get min, max, step, default from sensor */
  2027. exposure_max = ov5670->cur_mode->vts_def - 8;
  2028. ov5670->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops,
  2029. V4L2_CID_EXPOSURE,
  2030. OV5670_EXPOSURE_MIN,
  2031. exposure_max, OV5670_EXPOSURE_STEP,
  2032. exposure_max);
  2033. v4l2_ctrl_new_std_menu_items(ctrl_hdlr, &ov5670_ctrl_ops,
  2034. V4L2_CID_TEST_PATTERN,
  2035. ARRAY_SIZE(ov5670_test_pattern_menu) - 1,
  2036. 0, 0, ov5670_test_pattern_menu);
  2037. if (ctrl_hdlr->error) {
  2038. ret = ctrl_hdlr->error;
  2039. goto error;
  2040. }
  2041. ov5670->sd.ctrl_handler = ctrl_hdlr;
  2042. return 0;
  2043. error:
  2044. v4l2_ctrl_handler_free(ctrl_hdlr);
  2045. return ret;
  2046. }
  2047. static int ov5670_enum_mbus_code(struct v4l2_subdev *sd,
  2048. struct v4l2_subdev_pad_config *cfg,
  2049. struct v4l2_subdev_mbus_code_enum *code)
  2050. {
  2051. /* Only one bayer order GRBG is supported */
  2052. if (code->index > 0)
  2053. return -EINVAL;
  2054. code->code = MEDIA_BUS_FMT_SGRBG10_1X10;
  2055. return 0;
  2056. }
  2057. static int ov5670_enum_frame_size(struct v4l2_subdev *sd,
  2058. struct v4l2_subdev_pad_config *cfg,
  2059. struct v4l2_subdev_frame_size_enum *fse)
  2060. {
  2061. if (fse->index >= ARRAY_SIZE(supported_modes))
  2062. return -EINVAL;
  2063. if (fse->code != MEDIA_BUS_FMT_SGRBG10_1X10)
  2064. return -EINVAL;
  2065. fse->min_width = supported_modes[fse->index].width;
  2066. fse->max_width = fse->min_width;
  2067. fse->min_height = supported_modes[fse->index].height;
  2068. fse->max_height = fse->min_height;
  2069. return 0;
  2070. }
  2071. static void ov5670_update_pad_format(const struct ov5670_mode *mode,
  2072. struct v4l2_subdev_format *fmt)
  2073. {
  2074. fmt->format.width = mode->width;
  2075. fmt->format.height = mode->height;
  2076. fmt->format.code = MEDIA_BUS_FMT_SGRBG10_1X10;
  2077. fmt->format.field = V4L2_FIELD_NONE;
  2078. }
  2079. static int ov5670_do_get_pad_format(struct ov5670 *ov5670,
  2080. struct v4l2_subdev_pad_config *cfg,
  2081. struct v4l2_subdev_format *fmt)
  2082. {
  2083. if (fmt->which == V4L2_SUBDEV_FORMAT_TRY)
  2084. fmt->format = *v4l2_subdev_get_try_format(&ov5670->sd, cfg,
  2085. fmt->pad);
  2086. else
  2087. ov5670_update_pad_format(ov5670->cur_mode, fmt);
  2088. return 0;
  2089. }
  2090. static int ov5670_get_pad_format(struct v4l2_subdev *sd,
  2091. struct v4l2_subdev_pad_config *cfg,
  2092. struct v4l2_subdev_format *fmt)
  2093. {
  2094. struct ov5670 *ov5670 = to_ov5670(sd);
  2095. int ret;
  2096. mutex_lock(&ov5670->mutex);
  2097. ret = ov5670_do_get_pad_format(ov5670, cfg, fmt);
  2098. mutex_unlock(&ov5670->mutex);
  2099. return ret;
  2100. }
  2101. static int ov5670_set_pad_format(struct v4l2_subdev *sd,
  2102. struct v4l2_subdev_pad_config *cfg,
  2103. struct v4l2_subdev_format *fmt)
  2104. {
  2105. struct ov5670 *ov5670 = to_ov5670(sd);
  2106. const struct ov5670_mode *mode;
  2107. s32 vblank_def;
  2108. s32 h_blank;
  2109. mutex_lock(&ov5670->mutex);
  2110. fmt->format.code = MEDIA_BUS_FMT_SGRBG10_1X10;
  2111. mode = v4l2_find_nearest_size(supported_modes,
  2112. ARRAY_SIZE(supported_modes),
  2113. width, height,
  2114. fmt->format.width, fmt->format.height);
  2115. ov5670_update_pad_format(mode, fmt);
  2116. if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
  2117. *v4l2_subdev_get_try_format(sd, cfg, fmt->pad) = fmt->format;
  2118. } else {
  2119. ov5670->cur_mode = mode;
  2120. __v4l2_ctrl_s_ctrl(ov5670->link_freq, mode->link_freq_index);
  2121. __v4l2_ctrl_s_ctrl_int64(
  2122. ov5670->pixel_rate,
  2123. link_freq_configs[mode->link_freq_index].pixel_rate);
  2124. /* Update limits and set FPS to default */
  2125. vblank_def = ov5670->cur_mode->vts_def -
  2126. ov5670->cur_mode->height;
  2127. __v4l2_ctrl_modify_range(
  2128. ov5670->vblank,
  2129. ov5670->cur_mode->vts_min - ov5670->cur_mode->height,
  2130. OV5670_VTS_MAX - ov5670->cur_mode->height, 1,
  2131. vblank_def);
  2132. __v4l2_ctrl_s_ctrl(ov5670->vblank, vblank_def);
  2133. h_blank = OV5670_FIXED_PPL - ov5670->cur_mode->width;
  2134. __v4l2_ctrl_modify_range(ov5670->hblank, h_blank, h_blank, 1,
  2135. h_blank);
  2136. }
  2137. mutex_unlock(&ov5670->mutex);
  2138. return 0;
  2139. }
  2140. static int ov5670_get_skip_frames(struct v4l2_subdev *sd, u32 *frames)
  2141. {
  2142. *frames = OV5670_NUM_OF_SKIP_FRAMES;
  2143. return 0;
  2144. }
  2145. /* Prepare streaming by writing default values and customized values */
  2146. static int ov5670_start_streaming(struct ov5670 *ov5670)
  2147. {
  2148. struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
  2149. const struct ov5670_reg_list *reg_list;
  2150. int link_freq_index;
  2151. int ret;
  2152. /* Get out of from software reset */
  2153. ret = ov5670_write_reg(ov5670, OV5670_REG_SOFTWARE_RST,
  2154. OV5670_REG_VALUE_08BIT, OV5670_SOFTWARE_RST);
  2155. if (ret) {
  2156. dev_err(&client->dev, "%s failed to set powerup registers\n",
  2157. __func__);
  2158. return ret;
  2159. }
  2160. /* Setup PLL */
  2161. link_freq_index = ov5670->cur_mode->link_freq_index;
  2162. reg_list = &link_freq_configs[link_freq_index].reg_list;
  2163. ret = ov5670_write_reg_list(ov5670, reg_list);
  2164. if (ret) {
  2165. dev_err(&client->dev, "%s failed to set plls\n", __func__);
  2166. return ret;
  2167. }
  2168. /* Apply default values of current mode */
  2169. reg_list = &ov5670->cur_mode->reg_list;
  2170. ret = ov5670_write_reg_list(ov5670, reg_list);
  2171. if (ret) {
  2172. dev_err(&client->dev, "%s failed to set mode\n", __func__);
  2173. return ret;
  2174. }
  2175. ret = __v4l2_ctrl_handler_setup(ov5670->sd.ctrl_handler);
  2176. if (ret)
  2177. return ret;
  2178. /* Write stream on list */
  2179. ret = ov5670_write_reg(ov5670, OV5670_REG_MODE_SELECT,
  2180. OV5670_REG_VALUE_08BIT, OV5670_MODE_STREAMING);
  2181. if (ret) {
  2182. dev_err(&client->dev, "%s failed to set stream\n", __func__);
  2183. return ret;
  2184. }
  2185. return 0;
  2186. }
  2187. static int ov5670_stop_streaming(struct ov5670 *ov5670)
  2188. {
  2189. struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
  2190. int ret;
  2191. ret = ov5670_write_reg(ov5670, OV5670_REG_MODE_SELECT,
  2192. OV5670_REG_VALUE_08BIT, OV5670_MODE_STANDBY);
  2193. if (ret)
  2194. dev_err(&client->dev, "%s failed to set stream\n", __func__);
  2195. /* Return success even if it was an error, as there is nothing the
  2196. * caller can do about it.
  2197. */
  2198. return 0;
  2199. }
  2200. static int ov5670_set_stream(struct v4l2_subdev *sd, int enable)
  2201. {
  2202. struct ov5670 *ov5670 = to_ov5670(sd);
  2203. struct i2c_client *client = v4l2_get_subdevdata(sd);
  2204. int ret = 0;
  2205. mutex_lock(&ov5670->mutex);
  2206. if (ov5670->streaming == enable)
  2207. goto unlock_and_return;
  2208. if (enable) {
  2209. ret = pm_runtime_get_sync(&client->dev);
  2210. if (ret < 0) {
  2211. pm_runtime_put_noidle(&client->dev);
  2212. goto unlock_and_return;
  2213. }
  2214. ret = ov5670_start_streaming(ov5670);
  2215. if (ret)
  2216. goto error;
  2217. } else {
  2218. ret = ov5670_stop_streaming(ov5670);
  2219. pm_runtime_put(&client->dev);
  2220. }
  2221. ov5670->streaming = enable;
  2222. goto unlock_and_return;
  2223. error:
  2224. pm_runtime_put(&client->dev);
  2225. unlock_and_return:
  2226. mutex_unlock(&ov5670->mutex);
  2227. return ret;
  2228. }
  2229. static int __maybe_unused ov5670_suspend(struct device *dev)
  2230. {
  2231. struct i2c_client *client = to_i2c_client(dev);
  2232. struct v4l2_subdev *sd = i2c_get_clientdata(client);
  2233. struct ov5670 *ov5670 = to_ov5670(sd);
  2234. if (ov5670->streaming)
  2235. ov5670_stop_streaming(ov5670);
  2236. return 0;
  2237. }
  2238. static int __maybe_unused ov5670_resume(struct device *dev)
  2239. {
  2240. struct i2c_client *client = to_i2c_client(dev);
  2241. struct v4l2_subdev *sd = i2c_get_clientdata(client);
  2242. struct ov5670 *ov5670 = to_ov5670(sd);
  2243. int ret;
  2244. if (ov5670->streaming) {
  2245. ret = ov5670_start_streaming(ov5670);
  2246. if (ret) {
  2247. ov5670_stop_streaming(ov5670);
  2248. return ret;
  2249. }
  2250. }
  2251. return 0;
  2252. }
  2253. /* Verify chip ID */
  2254. static int ov5670_identify_module(struct ov5670 *ov5670)
  2255. {
  2256. struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
  2257. int ret;
  2258. u32 val;
  2259. ret = ov5670_read_reg(ov5670, OV5670_REG_CHIP_ID,
  2260. OV5670_REG_VALUE_24BIT, &val);
  2261. if (ret)
  2262. return ret;
  2263. if (val != OV5670_CHIP_ID) {
  2264. dev_err(&client->dev, "chip id mismatch: %x!=%x\n",
  2265. OV5670_CHIP_ID, val);
  2266. return -ENXIO;
  2267. }
  2268. return 0;
  2269. }
  2270. static const struct v4l2_subdev_video_ops ov5670_video_ops = {
  2271. .s_stream = ov5670_set_stream,
  2272. };
  2273. static const struct v4l2_subdev_pad_ops ov5670_pad_ops = {
  2274. .enum_mbus_code = ov5670_enum_mbus_code,
  2275. .get_fmt = ov5670_get_pad_format,
  2276. .set_fmt = ov5670_set_pad_format,
  2277. .enum_frame_size = ov5670_enum_frame_size,
  2278. };
  2279. static const struct v4l2_subdev_sensor_ops ov5670_sensor_ops = {
  2280. .g_skip_frames = ov5670_get_skip_frames,
  2281. };
  2282. static const struct v4l2_subdev_ops ov5670_subdev_ops = {
  2283. .video = &ov5670_video_ops,
  2284. .pad = &ov5670_pad_ops,
  2285. .sensor = &ov5670_sensor_ops,
  2286. };
  2287. static const struct media_entity_operations ov5670_subdev_entity_ops = {
  2288. .link_validate = v4l2_subdev_link_validate,
  2289. };
  2290. static const struct v4l2_subdev_internal_ops ov5670_internal_ops = {
  2291. .open = ov5670_open,
  2292. };
  2293. static int ov5670_probe(struct i2c_client *client)
  2294. {
  2295. struct ov5670 *ov5670;
  2296. const char *err_msg;
  2297. u32 input_clk = 0;
  2298. int ret;
  2299. device_property_read_u32(&client->dev, "clock-frequency", &input_clk);
  2300. if (input_clk != 19200000)
  2301. return -EINVAL;
  2302. ov5670 = devm_kzalloc(&client->dev, sizeof(*ov5670), GFP_KERNEL);
  2303. if (!ov5670) {
  2304. ret = -ENOMEM;
  2305. err_msg = "devm_kzalloc() error";
  2306. goto error_print;
  2307. }
  2308. /* Initialize subdev */
  2309. v4l2_i2c_subdev_init(&ov5670->sd, client, &ov5670_subdev_ops);
  2310. /* Check module identity */
  2311. ret = ov5670_identify_module(ov5670);
  2312. if (ret) {
  2313. err_msg = "ov5670_identify_module() error";
  2314. goto error_print;
  2315. }
  2316. mutex_init(&ov5670->mutex);
  2317. /* Set default mode to max resolution */
  2318. ov5670->cur_mode = &supported_modes[0];
  2319. ret = ov5670_init_controls(ov5670);
  2320. if (ret) {
  2321. err_msg = "ov5670_init_controls() error";
  2322. goto error_mutex_destroy;
  2323. }
  2324. ov5670->sd.internal_ops = &ov5670_internal_ops;
  2325. ov5670->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
  2326. ov5670->sd.entity.ops = &ov5670_subdev_entity_ops;
  2327. ov5670->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
  2328. /* Source pad initialization */
  2329. ov5670->pad.flags = MEDIA_PAD_FL_SOURCE;
  2330. ret = media_entity_pads_init(&ov5670->sd.entity, 1, &ov5670->pad);
  2331. if (ret) {
  2332. err_msg = "media_entity_pads_init() error";
  2333. goto error_handler_free;
  2334. }
  2335. /* Async register for subdev */
  2336. ret = v4l2_async_register_subdev_sensor_common(&ov5670->sd);
  2337. if (ret < 0) {
  2338. err_msg = "v4l2_async_register_subdev() error";
  2339. goto error_entity_cleanup;
  2340. }
  2341. ov5670->streaming = false;
  2342. /*
  2343. * Device is already turned on by i2c-core with ACPI domain PM.
  2344. * Enable runtime PM and turn off the device.
  2345. */
  2346. pm_runtime_get_noresume(&client->dev);
  2347. pm_runtime_set_active(&client->dev);
  2348. pm_runtime_enable(&client->dev);
  2349. pm_runtime_put(&client->dev);
  2350. return 0;
  2351. error_entity_cleanup:
  2352. media_entity_cleanup(&ov5670->sd.entity);
  2353. error_handler_free:
  2354. v4l2_ctrl_handler_free(ov5670->sd.ctrl_handler);
  2355. error_mutex_destroy:
  2356. mutex_destroy(&ov5670->mutex);
  2357. error_print:
  2358. dev_err(&client->dev, "%s: %s %d\n", __func__, err_msg, ret);
  2359. return ret;
  2360. }
  2361. static int ov5670_remove(struct i2c_client *client)
  2362. {
  2363. struct v4l2_subdev *sd = i2c_get_clientdata(client);
  2364. struct ov5670 *ov5670 = to_ov5670(sd);
  2365. v4l2_async_unregister_subdev(sd);
  2366. media_entity_cleanup(&sd->entity);
  2367. v4l2_ctrl_handler_free(sd->ctrl_handler);
  2368. mutex_destroy(&ov5670->mutex);
  2369. /*
  2370. * Disable runtime PM but keep the device turned on.
  2371. * i2c-core with ACPI domain PM will turn off the device.
  2372. */
  2373. pm_runtime_get_sync(&client->dev);
  2374. pm_runtime_disable(&client->dev);
  2375. pm_runtime_set_suspended(&client->dev);
  2376. pm_runtime_put_noidle(&client->dev);
  2377. return 0;
  2378. }
  2379. static const struct dev_pm_ops ov5670_pm_ops = {
  2380. SET_SYSTEM_SLEEP_PM_OPS(ov5670_suspend, ov5670_resume)
  2381. };
  2382. #ifdef CONFIG_ACPI
  2383. static const struct acpi_device_id ov5670_acpi_ids[] = {
  2384. {"INT3479"},
  2385. { /* sentinel */ }
  2386. };
  2387. MODULE_DEVICE_TABLE(acpi, ov5670_acpi_ids);
  2388. #endif
  2389. static struct i2c_driver ov5670_i2c_driver = {
  2390. .driver = {
  2391. .name = "ov5670",
  2392. .pm = &ov5670_pm_ops,
  2393. .acpi_match_table = ACPI_PTR(ov5670_acpi_ids),
  2394. },
  2395. .probe_new = ov5670_probe,
  2396. .remove = ov5670_remove,
  2397. };
  2398. module_i2c_driver(ov5670_i2c_driver);
  2399. MODULE_AUTHOR("Rapolu, Chiranjeevi <chiranjeevi.rapolu@intel.com>");
  2400. MODULE_AUTHOR("Yang, Hyungwoo <hyungwoo.yang@intel.com>");
  2401. MODULE_DESCRIPTION("Omnivision ov5670 sensor driver");
  2402. MODULE_LICENSE("GPL v2");