ov5670.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580
  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))
  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,
  2002. link_freq_configs[0].pixel_rate,
  2003. link_freq_configs[0].pixel_rate,
  2004. 1,
  2005. link_freq_configs[0].pixel_rate);
  2006. vblank_max = OV5670_VTS_MAX - ov5670->cur_mode->height;
  2007. vblank_def = ov5670->cur_mode->vts_def - ov5670->cur_mode->height;
  2008. vblank_min = ov5670->cur_mode->vts_min - ov5670->cur_mode->height;
  2009. ov5670->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops,
  2010. V4L2_CID_VBLANK, vblank_min,
  2011. vblank_max, 1, vblank_def);
  2012. ov5670->hblank = v4l2_ctrl_new_std(
  2013. ctrl_hdlr, &ov5670_ctrl_ops, V4L2_CID_HBLANK,
  2014. OV5670_FIXED_PPL - ov5670->cur_mode->width,
  2015. OV5670_FIXED_PPL - ov5670->cur_mode->width, 1,
  2016. OV5670_FIXED_PPL - ov5670->cur_mode->width);
  2017. if (ov5670->hblank)
  2018. ov5670->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
  2019. /* Get min, max, step, default from sensor */
  2020. v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops, V4L2_CID_ANALOGUE_GAIN,
  2021. ANALOG_GAIN_MIN, ANALOG_GAIN_MAX, ANALOG_GAIN_STEP,
  2022. ANALOG_GAIN_DEFAULT);
  2023. /* Digital gain */
  2024. v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops, V4L2_CID_DIGITAL_GAIN,
  2025. OV5670_DGTL_GAIN_MIN, OV5670_DGTL_GAIN_MAX,
  2026. OV5670_DGTL_GAIN_STEP, OV5670_DGTL_GAIN_DEFAULT);
  2027. /* Get min, max, step, default from sensor */
  2028. exposure_max = ov5670->cur_mode->vts_def - 8;
  2029. ov5670->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops,
  2030. V4L2_CID_EXPOSURE,
  2031. OV5670_EXPOSURE_MIN,
  2032. exposure_max, OV5670_EXPOSURE_STEP,
  2033. exposure_max);
  2034. v4l2_ctrl_new_std_menu_items(ctrl_hdlr, &ov5670_ctrl_ops,
  2035. V4L2_CID_TEST_PATTERN,
  2036. ARRAY_SIZE(ov5670_test_pattern_menu) - 1,
  2037. 0, 0, ov5670_test_pattern_menu);
  2038. if (ctrl_hdlr->error) {
  2039. ret = ctrl_hdlr->error;
  2040. goto error;
  2041. }
  2042. ov5670->sd.ctrl_handler = ctrl_hdlr;
  2043. return 0;
  2044. error:
  2045. v4l2_ctrl_handler_free(ctrl_hdlr);
  2046. return ret;
  2047. }
  2048. static int ov5670_enum_mbus_code(struct v4l2_subdev *sd,
  2049. struct v4l2_subdev_pad_config *cfg,
  2050. struct v4l2_subdev_mbus_code_enum *code)
  2051. {
  2052. /* Only one bayer order GRBG is supported */
  2053. if (code->index > 0)
  2054. return -EINVAL;
  2055. code->code = MEDIA_BUS_FMT_SGRBG10_1X10;
  2056. return 0;
  2057. }
  2058. static int ov5670_enum_frame_size(struct v4l2_subdev *sd,
  2059. struct v4l2_subdev_pad_config *cfg,
  2060. struct v4l2_subdev_frame_size_enum *fse)
  2061. {
  2062. if (fse->index >= ARRAY_SIZE(supported_modes))
  2063. return -EINVAL;
  2064. if (fse->code != MEDIA_BUS_FMT_SGRBG10_1X10)
  2065. return -EINVAL;
  2066. fse->min_width = supported_modes[fse->index].width;
  2067. fse->max_width = fse->min_width;
  2068. fse->min_height = supported_modes[fse->index].height;
  2069. fse->max_height = fse->min_height;
  2070. return 0;
  2071. }
  2072. static void ov5670_update_pad_format(const struct ov5670_mode *mode,
  2073. struct v4l2_subdev_format *fmt)
  2074. {
  2075. fmt->format.width = mode->width;
  2076. fmt->format.height = mode->height;
  2077. fmt->format.code = MEDIA_BUS_FMT_SGRBG10_1X10;
  2078. fmt->format.field = V4L2_FIELD_NONE;
  2079. }
  2080. static int ov5670_do_get_pad_format(struct ov5670 *ov5670,
  2081. struct v4l2_subdev_pad_config *cfg,
  2082. struct v4l2_subdev_format *fmt)
  2083. {
  2084. if (fmt->which == V4L2_SUBDEV_FORMAT_TRY)
  2085. fmt->format = *v4l2_subdev_get_try_format(&ov5670->sd, cfg,
  2086. fmt->pad);
  2087. else
  2088. ov5670_update_pad_format(ov5670->cur_mode, fmt);
  2089. return 0;
  2090. }
  2091. static int ov5670_get_pad_format(struct v4l2_subdev *sd,
  2092. struct v4l2_subdev_pad_config *cfg,
  2093. struct v4l2_subdev_format *fmt)
  2094. {
  2095. struct ov5670 *ov5670 = to_ov5670(sd);
  2096. int ret;
  2097. mutex_lock(&ov5670->mutex);
  2098. ret = ov5670_do_get_pad_format(ov5670, cfg, fmt);
  2099. mutex_unlock(&ov5670->mutex);
  2100. return ret;
  2101. }
  2102. static int ov5670_set_pad_format(struct v4l2_subdev *sd,
  2103. struct v4l2_subdev_pad_config *cfg,
  2104. struct v4l2_subdev_format *fmt)
  2105. {
  2106. struct ov5670 *ov5670 = to_ov5670(sd);
  2107. const struct ov5670_mode *mode;
  2108. s32 vblank_def;
  2109. s32 h_blank;
  2110. mutex_lock(&ov5670->mutex);
  2111. fmt->format.code = MEDIA_BUS_FMT_SGRBG10_1X10;
  2112. mode = v4l2_find_nearest_size(supported_modes,
  2113. ARRAY_SIZE(supported_modes),
  2114. width, height,
  2115. fmt->format.width, fmt->format.height);
  2116. ov5670_update_pad_format(mode, fmt);
  2117. if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
  2118. *v4l2_subdev_get_try_format(sd, cfg, fmt->pad) = fmt->format;
  2119. } else {
  2120. ov5670->cur_mode = mode;
  2121. __v4l2_ctrl_s_ctrl(ov5670->link_freq, mode->link_freq_index);
  2122. __v4l2_ctrl_s_ctrl_int64(
  2123. ov5670->pixel_rate,
  2124. link_freq_configs[mode->link_freq_index].pixel_rate);
  2125. /* Update limits and set FPS to default */
  2126. vblank_def = ov5670->cur_mode->vts_def -
  2127. ov5670->cur_mode->height;
  2128. __v4l2_ctrl_modify_range(
  2129. ov5670->vblank,
  2130. ov5670->cur_mode->vts_min - ov5670->cur_mode->height,
  2131. OV5670_VTS_MAX - ov5670->cur_mode->height, 1,
  2132. vblank_def);
  2133. __v4l2_ctrl_s_ctrl(ov5670->vblank, vblank_def);
  2134. h_blank = OV5670_FIXED_PPL - ov5670->cur_mode->width;
  2135. __v4l2_ctrl_modify_range(ov5670->hblank, h_blank, h_blank, 1,
  2136. h_blank);
  2137. }
  2138. mutex_unlock(&ov5670->mutex);
  2139. return 0;
  2140. }
  2141. static int ov5670_get_skip_frames(struct v4l2_subdev *sd, u32 *frames)
  2142. {
  2143. *frames = OV5670_NUM_OF_SKIP_FRAMES;
  2144. return 0;
  2145. }
  2146. /* Prepare streaming by writing default values and customized values */
  2147. static int ov5670_start_streaming(struct ov5670 *ov5670)
  2148. {
  2149. struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
  2150. const struct ov5670_reg_list *reg_list;
  2151. int link_freq_index;
  2152. int ret;
  2153. /* Get out of from software reset */
  2154. ret = ov5670_write_reg(ov5670, OV5670_REG_SOFTWARE_RST,
  2155. OV5670_REG_VALUE_08BIT, OV5670_SOFTWARE_RST);
  2156. if (ret) {
  2157. dev_err(&client->dev, "%s failed to set powerup registers\n",
  2158. __func__);
  2159. return ret;
  2160. }
  2161. /* Setup PLL */
  2162. link_freq_index = ov5670->cur_mode->link_freq_index;
  2163. reg_list = &link_freq_configs[link_freq_index].reg_list;
  2164. ret = ov5670_write_reg_list(ov5670, reg_list);
  2165. if (ret) {
  2166. dev_err(&client->dev, "%s failed to set plls\n", __func__);
  2167. return ret;
  2168. }
  2169. /* Apply default values of current mode */
  2170. reg_list = &ov5670->cur_mode->reg_list;
  2171. ret = ov5670_write_reg_list(ov5670, reg_list);
  2172. if (ret) {
  2173. dev_err(&client->dev, "%s failed to set mode\n", __func__);
  2174. return ret;
  2175. }
  2176. ret = __v4l2_ctrl_handler_setup(ov5670->sd.ctrl_handler);
  2177. if (ret)
  2178. return ret;
  2179. /* Write stream on list */
  2180. ret = ov5670_write_reg(ov5670, OV5670_REG_MODE_SELECT,
  2181. OV5670_REG_VALUE_08BIT, OV5670_MODE_STREAMING);
  2182. if (ret) {
  2183. dev_err(&client->dev, "%s failed to set stream\n", __func__);
  2184. return ret;
  2185. }
  2186. return 0;
  2187. }
  2188. static int ov5670_stop_streaming(struct ov5670 *ov5670)
  2189. {
  2190. struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
  2191. int ret;
  2192. ret = ov5670_write_reg(ov5670, OV5670_REG_MODE_SELECT,
  2193. OV5670_REG_VALUE_08BIT, OV5670_MODE_STANDBY);
  2194. if (ret)
  2195. dev_err(&client->dev, "%s failed to set stream\n", __func__);
  2196. /* Return success even if it was an error, as there is nothing the
  2197. * caller can do about it.
  2198. */
  2199. return 0;
  2200. }
  2201. static int ov5670_set_stream(struct v4l2_subdev *sd, int enable)
  2202. {
  2203. struct ov5670 *ov5670 = to_ov5670(sd);
  2204. struct i2c_client *client = v4l2_get_subdevdata(sd);
  2205. int ret = 0;
  2206. mutex_lock(&ov5670->mutex);
  2207. if (ov5670->streaming == enable)
  2208. goto unlock_and_return;
  2209. if (enable) {
  2210. ret = pm_runtime_get_sync(&client->dev);
  2211. if (ret < 0) {
  2212. pm_runtime_put_noidle(&client->dev);
  2213. goto unlock_and_return;
  2214. }
  2215. ret = ov5670_start_streaming(ov5670);
  2216. if (ret)
  2217. goto error;
  2218. } else {
  2219. ret = ov5670_stop_streaming(ov5670);
  2220. pm_runtime_put(&client->dev);
  2221. }
  2222. ov5670->streaming = enable;
  2223. goto unlock_and_return;
  2224. error:
  2225. pm_runtime_put(&client->dev);
  2226. unlock_and_return:
  2227. mutex_unlock(&ov5670->mutex);
  2228. return ret;
  2229. }
  2230. static int __maybe_unused ov5670_suspend(struct device *dev)
  2231. {
  2232. struct i2c_client *client = to_i2c_client(dev);
  2233. struct v4l2_subdev *sd = i2c_get_clientdata(client);
  2234. struct ov5670 *ov5670 = to_ov5670(sd);
  2235. if (ov5670->streaming)
  2236. ov5670_stop_streaming(ov5670);
  2237. return 0;
  2238. }
  2239. static int __maybe_unused ov5670_resume(struct device *dev)
  2240. {
  2241. struct i2c_client *client = to_i2c_client(dev);
  2242. struct v4l2_subdev *sd = i2c_get_clientdata(client);
  2243. struct ov5670 *ov5670 = to_ov5670(sd);
  2244. int ret;
  2245. if (ov5670->streaming) {
  2246. ret = ov5670_start_streaming(ov5670);
  2247. if (ret) {
  2248. ov5670_stop_streaming(ov5670);
  2249. return ret;
  2250. }
  2251. }
  2252. return 0;
  2253. }
  2254. /* Verify chip ID */
  2255. static int ov5670_identify_module(struct ov5670 *ov5670)
  2256. {
  2257. struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd);
  2258. int ret;
  2259. u32 val;
  2260. ret = ov5670_read_reg(ov5670, OV5670_REG_CHIP_ID,
  2261. OV5670_REG_VALUE_24BIT, &val);
  2262. if (ret)
  2263. return ret;
  2264. if (val != OV5670_CHIP_ID) {
  2265. dev_err(&client->dev, "chip id mismatch: %x!=%x\n",
  2266. OV5670_CHIP_ID, val);
  2267. return -ENXIO;
  2268. }
  2269. return 0;
  2270. }
  2271. static const struct v4l2_subdev_video_ops ov5670_video_ops = {
  2272. .s_stream = ov5670_set_stream,
  2273. };
  2274. static const struct v4l2_subdev_pad_ops ov5670_pad_ops = {
  2275. .enum_mbus_code = ov5670_enum_mbus_code,
  2276. .get_fmt = ov5670_get_pad_format,
  2277. .set_fmt = ov5670_set_pad_format,
  2278. .enum_frame_size = ov5670_enum_frame_size,
  2279. };
  2280. static const struct v4l2_subdev_sensor_ops ov5670_sensor_ops = {
  2281. .g_skip_frames = ov5670_get_skip_frames,
  2282. };
  2283. static const struct v4l2_subdev_ops ov5670_subdev_ops = {
  2284. .video = &ov5670_video_ops,
  2285. .pad = &ov5670_pad_ops,
  2286. .sensor = &ov5670_sensor_ops,
  2287. };
  2288. static const struct media_entity_operations ov5670_subdev_entity_ops = {
  2289. .link_validate = v4l2_subdev_link_validate,
  2290. };
  2291. static const struct v4l2_subdev_internal_ops ov5670_internal_ops = {
  2292. .open = ov5670_open,
  2293. };
  2294. static int ov5670_probe(struct i2c_client *client)
  2295. {
  2296. struct ov5670 *ov5670;
  2297. const char *err_msg;
  2298. u32 input_clk = 0;
  2299. int ret;
  2300. device_property_read_u32(&client->dev, "clock-frequency", &input_clk);
  2301. if (input_clk != 19200000)
  2302. return -EINVAL;
  2303. ov5670 = devm_kzalloc(&client->dev, sizeof(*ov5670), GFP_KERNEL);
  2304. if (!ov5670) {
  2305. ret = -ENOMEM;
  2306. err_msg = "devm_kzalloc() error";
  2307. goto error_print;
  2308. }
  2309. /* Initialize subdev */
  2310. v4l2_i2c_subdev_init(&ov5670->sd, client, &ov5670_subdev_ops);
  2311. /* Check module identity */
  2312. ret = ov5670_identify_module(ov5670);
  2313. if (ret) {
  2314. err_msg = "ov5670_identify_module() error";
  2315. goto error_print;
  2316. }
  2317. mutex_init(&ov5670->mutex);
  2318. /* Set default mode to max resolution */
  2319. ov5670->cur_mode = &supported_modes[0];
  2320. ret = ov5670_init_controls(ov5670);
  2321. if (ret) {
  2322. err_msg = "ov5670_init_controls() error";
  2323. goto error_mutex_destroy;
  2324. }
  2325. ov5670->sd.internal_ops = &ov5670_internal_ops;
  2326. ov5670->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
  2327. ov5670->sd.entity.ops = &ov5670_subdev_entity_ops;
  2328. ov5670->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
  2329. /* Source pad initialization */
  2330. ov5670->pad.flags = MEDIA_PAD_FL_SOURCE;
  2331. ret = media_entity_pads_init(&ov5670->sd.entity, 1, &ov5670->pad);
  2332. if (ret) {
  2333. err_msg = "media_entity_pads_init() error";
  2334. goto error_handler_free;
  2335. }
  2336. /* Async register for subdev */
  2337. ret = v4l2_async_register_subdev_sensor_common(&ov5670->sd);
  2338. if (ret < 0) {
  2339. err_msg = "v4l2_async_register_subdev() error";
  2340. goto error_entity_cleanup;
  2341. }
  2342. ov5670->streaming = false;
  2343. /*
  2344. * Device is already turned on by i2c-core with ACPI domain PM.
  2345. * Enable runtime PM and turn off the device.
  2346. */
  2347. pm_runtime_get_noresume(&client->dev);
  2348. pm_runtime_set_active(&client->dev);
  2349. pm_runtime_enable(&client->dev);
  2350. pm_runtime_put(&client->dev);
  2351. return 0;
  2352. error_entity_cleanup:
  2353. media_entity_cleanup(&ov5670->sd.entity);
  2354. error_handler_free:
  2355. v4l2_ctrl_handler_free(ov5670->sd.ctrl_handler);
  2356. error_mutex_destroy:
  2357. mutex_destroy(&ov5670->mutex);
  2358. error_print:
  2359. dev_err(&client->dev, "%s: %s %d\n", __func__, err_msg, ret);
  2360. return ret;
  2361. }
  2362. static int ov5670_remove(struct i2c_client *client)
  2363. {
  2364. struct v4l2_subdev *sd = i2c_get_clientdata(client);
  2365. struct ov5670 *ov5670 = to_ov5670(sd);
  2366. v4l2_async_unregister_subdev(sd);
  2367. media_entity_cleanup(&sd->entity);
  2368. v4l2_ctrl_handler_free(sd->ctrl_handler);
  2369. mutex_destroy(&ov5670->mutex);
  2370. /*
  2371. * Disable runtime PM but keep the device turned on.
  2372. * i2c-core with ACPI domain PM will turn off the device.
  2373. */
  2374. pm_runtime_get_sync(&client->dev);
  2375. pm_runtime_disable(&client->dev);
  2376. pm_runtime_set_suspended(&client->dev);
  2377. pm_runtime_put_noidle(&client->dev);
  2378. return 0;
  2379. }
  2380. static const struct dev_pm_ops ov5670_pm_ops = {
  2381. SET_SYSTEM_SLEEP_PM_OPS(ov5670_suspend, ov5670_resume)
  2382. };
  2383. #ifdef CONFIG_ACPI
  2384. static const struct acpi_device_id ov5670_acpi_ids[] = {
  2385. {"INT3479"},
  2386. { /* sentinel */ }
  2387. };
  2388. MODULE_DEVICE_TABLE(acpi, ov5670_acpi_ids);
  2389. #endif
  2390. static struct i2c_driver ov5670_i2c_driver = {
  2391. .driver = {
  2392. .name = "ov5670",
  2393. .pm = &ov5670_pm_ops,
  2394. .acpi_match_table = ACPI_PTR(ov5670_acpi_ids),
  2395. },
  2396. .probe_new = ov5670_probe,
  2397. .remove = ov5670_remove,
  2398. };
  2399. module_i2c_driver(ov5670_i2c_driver);
  2400. MODULE_AUTHOR("Rapolu, Chiranjeevi <chiranjeevi.rapolu@intel.com>");
  2401. MODULE_AUTHOR("Yang, Hyungwoo <hyungwoo.yang@intel.com>");
  2402. MODULE_DESCRIPTION("Omnivision ov5670 sensor driver");
  2403. MODULE_LICENSE("GPL v2");