ov5670.c 57 KB

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