ov8856.c 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (c) 2019 Intel Corporation.
  3. #include <asm/unaligned.h>
  4. #include <linux/acpi.h>
  5. #include <linux/clk.h>
  6. #include <linux/delay.h>
  7. #include <linux/gpio/consumer.h>
  8. #include <linux/i2c.h>
  9. #include <linux/module.h>
  10. #include <linux/pm_runtime.h>
  11. #include <linux/regulator/consumer.h>
  12. #include <media/v4l2-ctrls.h>
  13. #include <media/v4l2-device.h>
  14. #include <media/v4l2-fwnode.h>
  15. #define OV8856_REG_VALUE_08BIT 1
  16. #define OV8856_REG_VALUE_16BIT 2
  17. #define OV8856_REG_VALUE_24BIT 3
  18. #define OV8856_SCLK 144000000ULL
  19. #define OV8856_XVCLK_19_2 19200000
  20. #define OV8856_DATA_LANES 4
  21. #define OV8856_RGB_DEPTH 10
  22. #define OV8856_REG_CHIP_ID 0x300a
  23. #define OV8856_CHIP_ID 0x00885a
  24. #define OV8856_REG_MODE_SELECT 0x0100
  25. #define OV8856_MODE_STANDBY 0x00
  26. #define OV8856_MODE_STREAMING 0x01
  27. /* module revisions */
  28. #define OV8856_2A_MODULE 0x01
  29. #define OV8856_1B_MODULE 0x02
  30. /* the OTP read-out buffer is at 0x7000 and 0xf is the offset
  31. * of the byte in the OTP that means the module revision
  32. */
  33. #define OV8856_MODULE_REVISION 0x700f
  34. #define OV8856_OTP_MODE_CTRL 0x3d84
  35. #define OV8856_OTP_LOAD_CTRL 0x3d81
  36. #define OV8856_OTP_MODE_AUTO 0x00
  37. #define OV8856_OTP_LOAD_CTRL_ENABLE BIT(0)
  38. /* vertical-timings from sensor */
  39. #define OV8856_REG_VTS 0x380e
  40. #define OV8856_VTS_MAX 0x7fff
  41. /* horizontal-timings from sensor */
  42. #define OV8856_REG_HTS 0x380c
  43. /* Exposure controls from sensor */
  44. #define OV8856_REG_EXPOSURE 0x3500
  45. #define OV8856_EXPOSURE_MIN 6
  46. #define OV8856_EXPOSURE_MAX_MARGIN 6
  47. #define OV8856_EXPOSURE_STEP 1
  48. /* Analog gain controls from sensor */
  49. #define OV8856_REG_ANALOG_GAIN 0x3508
  50. #define OV8856_ANAL_GAIN_MIN 128
  51. #define OV8856_ANAL_GAIN_MAX 2047
  52. #define OV8856_ANAL_GAIN_STEP 1
  53. /* Digital gain controls from sensor */
  54. #define OV8856_REG_DIGITAL_GAIN 0x350a
  55. #define OV8856_REG_MWB_R_GAIN 0x5019
  56. #define OV8856_REG_MWB_G_GAIN 0x501b
  57. #define OV8856_REG_MWB_B_GAIN 0x501d
  58. #define OV8856_DGTL_GAIN_MIN 0
  59. #define OV8856_DGTL_GAIN_MAX 4095
  60. #define OV8856_DGTL_GAIN_STEP 1
  61. #define OV8856_DGTL_GAIN_DEFAULT 1024
  62. /* Test Pattern Control */
  63. #define OV8856_REG_TEST_PATTERN 0x5e00
  64. #define OV8856_TEST_PATTERN_ENABLE BIT(7)
  65. #define OV8856_TEST_PATTERN_BAR_SHIFT 2
  66. #define NUM_REGS 7
  67. #define NUM_MODE_REGS 187
  68. #define NUM_MODE_REGS_2 200
  69. /* Flip Mirror Controls from sensor */
  70. #define OV8856_REG_FORMAT1 0x3820
  71. #define OV8856_REG_FORMAT2 0x3821
  72. #define OV8856_REG_FORMAT1_OP_1 BIT(1)
  73. #define OV8856_REG_FORMAT1_OP_2 BIT(2)
  74. #define OV8856_REG_FORMAT1_OP_3 BIT(6)
  75. #define OV8856_REG_FORMAT2_OP_1 BIT(1)
  76. #define OV8856_REG_FORMAT2_OP_2 BIT(2)
  77. #define OV8856_REG_FORMAT2_OP_3 BIT(6)
  78. #define OV8856_REG_FLIP_OPT_1 0x376b
  79. #define OV8856_REG_FLIP_OPT_2 0x5001
  80. #define OV8856_REG_FLIP_OPT_3 0x502e
  81. #define OV8856_REG_MIRROR_OPT_1 0x5004
  82. #define OV8856_REG_FLIP_OP_0 BIT(0)
  83. #define OV8856_REG_FLIP_OP_1 BIT(1)
  84. #define OV8856_REG_FLIP_OP_2 BIT(2)
  85. #define OV8856_REG_MIRROR_OP_1 BIT(1)
  86. #define OV8856_REG_MIRROR_OP_2 BIT(2)
  87. #define to_ov8856(_sd) container_of(_sd, struct ov8856, sd)
  88. static const char * const ov8856_supply_names[] = {
  89. "dovdd", /* Digital I/O power */
  90. "avdd", /* Analog power */
  91. "dvdd", /* Digital core power */
  92. };
  93. enum {
  94. OV8856_MEDIA_BUS_FMT_SBGGR10_1X10,
  95. OV8856_MEDIA_BUS_FMT_SGRBG10_1X10,
  96. };
  97. struct ov8856_reg {
  98. u16 address;
  99. u8 val;
  100. };
  101. struct ov8856_reg_list {
  102. u32 num_of_regs;
  103. const struct ov8856_reg *regs;
  104. };
  105. struct ov8856_link_freq_config {
  106. const struct ov8856_reg_list reg_list;
  107. };
  108. struct ov8856_mode {
  109. /* Frame width in pixels */
  110. u32 width;
  111. /* Frame height in pixels */
  112. u32 height;
  113. /* Horizontal timining size */
  114. u32 hts;
  115. /* Default vertical timining size */
  116. u32 vts_def;
  117. /* Min vertical timining size */
  118. u32 vts_min;
  119. /* Link frequency needed for this resolution */
  120. u32 link_freq_index;
  121. /* Sensor register settings for this resolution */
  122. const struct ov8856_reg_list reg_list;
  123. /* Number of data lanes */
  124. u8 data_lanes;
  125. /* Default MEDIA_BUS_FMT for this mode */
  126. u32 default_mbus_index;
  127. };
  128. struct ov8856_mipi_data_rates {
  129. const struct ov8856_reg regs_0[NUM_REGS];
  130. const struct ov8856_reg regs_1[NUM_REGS];
  131. };
  132. static const struct ov8856_mipi_data_rates mipi_data_rate_lane_2 = {
  133. //mipi_data_rate_1440mbps
  134. {
  135. {0x0103, 0x01},
  136. {0x0100, 0x00},
  137. {0x0302, 0x43},
  138. {0x0303, 0x00},
  139. {0x030b, 0x02},
  140. {0x030d, 0x4b},
  141. {0x031e, 0x0c}
  142. },
  143. //mipi_data_rate_720mbps
  144. {
  145. {0x0103, 0x01},
  146. {0x0100, 0x00},
  147. {0x0302, 0x4b},
  148. {0x0303, 0x01},
  149. {0x030b, 0x02},
  150. {0x030d, 0x4b},
  151. {0x031e, 0x0c}
  152. }
  153. };
  154. static const struct ov8856_mipi_data_rates mipi_data_rate_lane_4 = {
  155. //mipi_data_rate_720mbps
  156. {
  157. {0x0103, 0x01},
  158. {0x0100, 0x00},
  159. {0x0302, 0x4b},
  160. {0x0303, 0x01},
  161. {0x030b, 0x02},
  162. {0x030d, 0x4b},
  163. {0x031e, 0x0c}
  164. },
  165. //mipi_data_rate_360mbps
  166. {
  167. {0x0103, 0x01},
  168. {0x0100, 0x00},
  169. {0x0302, 0x4b},
  170. {0x0303, 0x03},
  171. {0x030b, 0x02},
  172. {0x030d, 0x4b},
  173. {0x031e, 0x0c}
  174. }
  175. };
  176. static const struct ov8856_reg lane_2_mode_3280x2464[] = {
  177. /* 3280x2464 resolution */
  178. {0x3000, 0x20},
  179. {0x3003, 0x08},
  180. {0x300e, 0x20},
  181. {0x3010, 0x00},
  182. {0x3015, 0x84},
  183. {0x3018, 0x32},
  184. {0x3021, 0x23},
  185. {0x3033, 0x24},
  186. {0x3500, 0x00},
  187. {0x3501, 0x9a},
  188. {0x3502, 0x20},
  189. {0x3503, 0x08},
  190. {0x3505, 0x83},
  191. {0x3508, 0x01},
  192. {0x3509, 0x80},
  193. {0x350c, 0x00},
  194. {0x350d, 0x80},
  195. {0x350e, 0x04},
  196. {0x350f, 0x00},
  197. {0x3510, 0x00},
  198. {0x3511, 0x02},
  199. {0x3512, 0x00},
  200. {0x3600, 0x72},
  201. {0x3601, 0x40},
  202. {0x3602, 0x30},
  203. {0x3610, 0xc5},
  204. {0x3611, 0x58},
  205. {0x3612, 0x5c},
  206. {0x3613, 0xca},
  207. {0x3614, 0x50},
  208. {0x3628, 0xff},
  209. {0x3629, 0xff},
  210. {0x362a, 0xff},
  211. {0x3633, 0x10},
  212. {0x3634, 0x10},
  213. {0x3635, 0x10},
  214. {0x3636, 0x10},
  215. {0x3663, 0x08},
  216. {0x3669, 0x34},
  217. {0x366e, 0x10},
  218. {0x3706, 0x86},
  219. {0x370b, 0x7e},
  220. {0x3714, 0x23},
  221. {0x3730, 0x12},
  222. {0x3733, 0x10},
  223. {0x3764, 0x00},
  224. {0x3765, 0x00},
  225. {0x3769, 0x62},
  226. {0x376a, 0x2a},
  227. {0x376b, 0x30},
  228. {0x3780, 0x00},
  229. {0x3781, 0x24},
  230. {0x3782, 0x00},
  231. {0x3783, 0x23},
  232. {0x3798, 0x2f},
  233. {0x37a1, 0x60},
  234. {0x37a8, 0x6a},
  235. {0x37ab, 0x3f},
  236. {0x37c2, 0x04},
  237. {0x37c3, 0xf1},
  238. {0x37c9, 0x80},
  239. {0x37cb, 0x16},
  240. {0x37cc, 0x16},
  241. {0x37cd, 0x16},
  242. {0x37ce, 0x16},
  243. {0x3800, 0x00},
  244. {0x3801, 0x00},
  245. {0x3802, 0x00},
  246. {0x3803, 0x06},
  247. {0x3804, 0x0c},
  248. {0x3805, 0xdf},
  249. {0x3806, 0x09},
  250. {0x3807, 0xa7},
  251. {0x3808, 0x0c},
  252. {0x3809, 0xd0},
  253. {0x380a, 0x09},
  254. {0x380b, 0xa0},
  255. {0x380c, 0x07},
  256. {0x380d, 0x88},
  257. {0x380e, 0x09},
  258. {0x380f, 0xb8},
  259. {0x3810, 0x00},
  260. {0x3811, 0x00},
  261. {0x3812, 0x00},
  262. {0x3813, 0x01},
  263. {0x3814, 0x01},
  264. {0x3815, 0x01},
  265. {0x3816, 0x00},
  266. {0x3817, 0x00},
  267. {0x3818, 0x00},
  268. {0x3819, 0x00},
  269. {0x3820, 0x80},
  270. {0x3821, 0x46},
  271. {0x382a, 0x01},
  272. {0x382b, 0x01},
  273. {0x3830, 0x06},
  274. {0x3836, 0x02},
  275. {0x3837, 0x10},
  276. {0x3862, 0x04},
  277. {0x3863, 0x08},
  278. {0x3cc0, 0x33},
  279. {0x3d85, 0x14},
  280. {0x3d8c, 0x73},
  281. {0x3d8d, 0xde},
  282. {0x4001, 0xe0},
  283. {0x4003, 0x40},
  284. {0x4008, 0x00},
  285. {0x4009, 0x0b},
  286. {0x400a, 0x00},
  287. {0x400b, 0x84},
  288. {0x400f, 0x80},
  289. {0x4010, 0xf0},
  290. {0x4011, 0xff},
  291. {0x4012, 0x02},
  292. {0x4013, 0x01},
  293. {0x4014, 0x01},
  294. {0x4015, 0x01},
  295. {0x4042, 0x00},
  296. {0x4043, 0x80},
  297. {0x4044, 0x00},
  298. {0x4045, 0x80},
  299. {0x4046, 0x00},
  300. {0x4047, 0x80},
  301. {0x4048, 0x00},
  302. {0x4049, 0x80},
  303. {0x4041, 0x03},
  304. {0x404c, 0x20},
  305. {0x404d, 0x00},
  306. {0x404e, 0x20},
  307. {0x4203, 0x80},
  308. {0x4307, 0x30},
  309. {0x4317, 0x00},
  310. {0x4503, 0x08},
  311. {0x4601, 0x80},
  312. {0x4800, 0x44},
  313. {0x4816, 0x53},
  314. {0x481b, 0x58},
  315. {0x481f, 0x27},
  316. {0x4837, 0x0c},
  317. {0x483c, 0x0f},
  318. {0x484b, 0x05},
  319. {0x5000, 0x57},
  320. {0x5001, 0x0a},
  321. {0x5004, 0x06},
  322. {0x502e, 0x03},
  323. {0x5030, 0x41},
  324. {0x5795, 0x02},
  325. {0x5796, 0x20},
  326. {0x5797, 0x20},
  327. {0x5798, 0xd5},
  328. {0x5799, 0xd5},
  329. {0x579a, 0x00},
  330. {0x579b, 0x50},
  331. {0x579c, 0x00},
  332. {0x579d, 0x2c},
  333. {0x579e, 0x0c},
  334. {0x579f, 0x40},
  335. {0x57a0, 0x09},
  336. {0x57a1, 0x40},
  337. {0x5780, 0x14},
  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, 0x04},
  355. {0x5792, 0x00},
  356. {0x5793, 0x52},
  357. {0x5794, 0xa3},
  358. {0x59f8, 0x3d},
  359. {0x5a08, 0x02},
  360. {0x5b00, 0x02},
  361. {0x5b01, 0x10},
  362. {0x5b02, 0x03},
  363. {0x5b03, 0xcf},
  364. {0x5b05, 0x6c},
  365. {0x5e00, 0x00}
  366. };
  367. static const struct ov8856_reg lane_2_mode_1640x1232[] = {
  368. /* 1640x1232 resolution */
  369. {0x3000, 0x20},
  370. {0x3003, 0x08},
  371. {0x300e, 0x20},
  372. {0x3010, 0x00},
  373. {0x3015, 0x84},
  374. {0x3018, 0x32},
  375. {0x3021, 0x23},
  376. {0x3033, 0x24},
  377. {0x3500, 0x00},
  378. {0x3501, 0x4c},
  379. {0x3502, 0xe0},
  380. {0x3503, 0x08},
  381. {0x3505, 0x83},
  382. {0x3508, 0x01},
  383. {0x3509, 0x80},
  384. {0x350c, 0x00},
  385. {0x350d, 0x80},
  386. {0x350e, 0x04},
  387. {0x350f, 0x00},
  388. {0x3510, 0x00},
  389. {0x3511, 0x02},
  390. {0x3512, 0x00},
  391. {0x3600, 0x72},
  392. {0x3601, 0x40},
  393. {0x3602, 0x30},
  394. {0x3610, 0xc5},
  395. {0x3611, 0x58},
  396. {0x3612, 0x5c},
  397. {0x3613, 0xca},
  398. {0x3614, 0x50},
  399. {0x3628, 0xff},
  400. {0x3629, 0xff},
  401. {0x362a, 0xff},
  402. {0x3633, 0x10},
  403. {0x3634, 0x10},
  404. {0x3635, 0x10},
  405. {0x3636, 0x10},
  406. {0x3663, 0x08},
  407. {0x3669, 0x34},
  408. {0x366e, 0x08},
  409. {0x3706, 0x86},
  410. {0x370b, 0x7e},
  411. {0x3714, 0x27},
  412. {0x3730, 0x12},
  413. {0x3733, 0x10},
  414. {0x3764, 0x00},
  415. {0x3765, 0x00},
  416. {0x3769, 0x62},
  417. {0x376a, 0x2a},
  418. {0x376b, 0x30},
  419. {0x3780, 0x00},
  420. {0x3781, 0x24},
  421. {0x3782, 0x00},
  422. {0x3783, 0x23},
  423. {0x3798, 0x2f},
  424. {0x37a1, 0x60},
  425. {0x37a8, 0x6a},
  426. {0x37ab, 0x3f},
  427. {0x37c2, 0x14},
  428. {0x37c3, 0xf1},
  429. {0x37c9, 0x80},
  430. {0x37cb, 0x16},
  431. {0x37cc, 0x16},
  432. {0x37cd, 0x16},
  433. {0x37ce, 0x16},
  434. {0x3800, 0x00},
  435. {0x3801, 0x00},
  436. {0x3802, 0x00},
  437. {0x3803, 0x00},
  438. {0x3804, 0x0c},
  439. {0x3805, 0xdf},
  440. {0x3806, 0x09},
  441. {0x3807, 0xaf},
  442. {0x3808, 0x06},
  443. {0x3809, 0x68},
  444. {0x380a, 0x04},
  445. {0x380b, 0xd0},
  446. {0x380c, 0x0c},
  447. {0x380d, 0x60},
  448. {0x380e, 0x05},
  449. {0x380f, 0xea},
  450. {0x3810, 0x00},
  451. {0x3811, 0x04},
  452. {0x3812, 0x00},
  453. {0x3813, 0x05},
  454. {0x3814, 0x03},
  455. {0x3815, 0x01},
  456. {0x3816, 0x00},
  457. {0x3817, 0x00},
  458. {0x3818, 0x00},
  459. {0x3819, 0x00},
  460. {0x3820, 0x90},
  461. {0x3821, 0x67},
  462. {0x382a, 0x03},
  463. {0x382b, 0x01},
  464. {0x3830, 0x06},
  465. {0x3836, 0x02},
  466. {0x3837, 0x10},
  467. {0x3862, 0x04},
  468. {0x3863, 0x08},
  469. {0x3cc0, 0x33},
  470. {0x3d85, 0x14},
  471. {0x3d8c, 0x73},
  472. {0x3d8d, 0xde},
  473. {0x4001, 0xe0},
  474. {0x4003, 0x40},
  475. {0x4008, 0x00},
  476. {0x4009, 0x05},
  477. {0x400a, 0x00},
  478. {0x400b, 0x84},
  479. {0x400f, 0x80},
  480. {0x4010, 0xf0},
  481. {0x4011, 0xff},
  482. {0x4012, 0x02},
  483. {0x4013, 0x01},
  484. {0x4014, 0x01},
  485. {0x4015, 0x01},
  486. {0x4042, 0x00},
  487. {0x4043, 0x80},
  488. {0x4044, 0x00},
  489. {0x4045, 0x80},
  490. {0x4046, 0x00},
  491. {0x4047, 0x80},
  492. {0x4048, 0x00},
  493. {0x4049, 0x80},
  494. {0x4041, 0x03},
  495. {0x404c, 0x20},
  496. {0x404d, 0x00},
  497. {0x404e, 0x20},
  498. {0x4203, 0x80},
  499. {0x4307, 0x30},
  500. {0x4317, 0x00},
  501. {0x4503, 0x08},
  502. {0x4601, 0x80},
  503. {0x4800, 0x44},
  504. {0x4816, 0x53},
  505. {0x481b, 0x58},
  506. {0x481f, 0x27},
  507. {0x4837, 0x16},
  508. {0x483c, 0x0f},
  509. {0x484b, 0x05},
  510. {0x5000, 0x57},
  511. {0x5001, 0x0a},
  512. {0x5004, 0x06},
  513. {0x502e, 0x03},
  514. {0x5030, 0x41},
  515. {0x5795, 0x00},
  516. {0x5796, 0x10},
  517. {0x5797, 0x10},
  518. {0x5798, 0x73},
  519. {0x5799, 0x73},
  520. {0x579a, 0x00},
  521. {0x579b, 0x28},
  522. {0x579c, 0x00},
  523. {0x579d, 0x16},
  524. {0x579e, 0x06},
  525. {0x579f, 0x20},
  526. {0x57a0, 0x04},
  527. {0x57a1, 0xa0},
  528. {0x5780, 0x14},
  529. {0x5781, 0x0f},
  530. {0x5782, 0x44},
  531. {0x5783, 0x02},
  532. {0x5784, 0x01},
  533. {0x5785, 0x01},
  534. {0x5786, 0x00},
  535. {0x5787, 0x04},
  536. {0x5788, 0x02},
  537. {0x5789, 0x0f},
  538. {0x578a, 0xfd},
  539. {0x578b, 0xf5},
  540. {0x578c, 0xf5},
  541. {0x578d, 0x03},
  542. {0x578e, 0x08},
  543. {0x578f, 0x0c},
  544. {0x5790, 0x08},
  545. {0x5791, 0x04},
  546. {0x5792, 0x00},
  547. {0x5793, 0x52},
  548. {0x5794, 0xa3},
  549. {0x59f8, 0x3d},
  550. {0x5a08, 0x02},
  551. {0x5b00, 0x02},
  552. {0x5b01, 0x10},
  553. {0x5b02, 0x03},
  554. {0x5b03, 0xcf},
  555. {0x5b05, 0x6c},
  556. {0x5e00, 0x00}
  557. };
  558. static const struct ov8856_reg lane_4_mode_3280x2464[] = {
  559. /* 3280x2464 resolution */
  560. {0x3000, 0x20},
  561. {0x3003, 0x08},
  562. {0x300e, 0x20},
  563. {0x3010, 0x00},
  564. {0x3015, 0x84},
  565. {0x3018, 0x72},
  566. {0x3021, 0x23},
  567. {0x3033, 0x24},
  568. {0x3500, 0x00},
  569. {0x3501, 0x9a},
  570. {0x3502, 0x20},
  571. {0x3503, 0x08},
  572. {0x3505, 0x83},
  573. {0x3508, 0x01},
  574. {0x3509, 0x80},
  575. {0x350c, 0x00},
  576. {0x350d, 0x80},
  577. {0x350e, 0x04},
  578. {0x350f, 0x00},
  579. {0x3510, 0x00},
  580. {0x3511, 0x02},
  581. {0x3512, 0x00},
  582. {0x3600, 0x72},
  583. {0x3601, 0x40},
  584. {0x3602, 0x30},
  585. {0x3610, 0xc5},
  586. {0x3611, 0x58},
  587. {0x3612, 0x5c},
  588. {0x3613, 0xca},
  589. {0x3614, 0x20},
  590. {0x3628, 0xff},
  591. {0x3629, 0xff},
  592. {0x362a, 0xff},
  593. {0x3633, 0x10},
  594. {0x3634, 0x10},
  595. {0x3635, 0x10},
  596. {0x3636, 0x10},
  597. {0x3663, 0x08},
  598. {0x3669, 0x34},
  599. {0x366e, 0x10},
  600. {0x3706, 0x86},
  601. {0x370b, 0x7e},
  602. {0x3714, 0x23},
  603. {0x3730, 0x12},
  604. {0x3733, 0x10},
  605. {0x3764, 0x00},
  606. {0x3765, 0x00},
  607. {0x3769, 0x62},
  608. {0x376a, 0x2a},
  609. {0x376b, 0x30},
  610. {0x3780, 0x00},
  611. {0x3781, 0x24},
  612. {0x3782, 0x00},
  613. {0x3783, 0x23},
  614. {0x3798, 0x2f},
  615. {0x37a1, 0x60},
  616. {0x37a8, 0x6a},
  617. {0x37ab, 0x3f},
  618. {0x37c2, 0x04},
  619. {0x37c3, 0xf1},
  620. {0x37c9, 0x80},
  621. {0x37cb, 0x16},
  622. {0x37cc, 0x16},
  623. {0x37cd, 0x16},
  624. {0x37ce, 0x16},
  625. {0x3800, 0x00},
  626. {0x3801, 0x00},
  627. {0x3802, 0x00},
  628. {0x3803, 0x06},
  629. {0x3804, 0x0c},
  630. {0x3805, 0xdf},
  631. {0x3806, 0x09},
  632. {0x3807, 0xa7},
  633. {0x3808, 0x0c},
  634. {0x3809, 0xd0},
  635. {0x380a, 0x09},
  636. {0x380b, 0xa0},
  637. {0x380c, 0x07},
  638. {0x380d, 0x88},
  639. {0x380e, 0x09},
  640. {0x380f, 0xb8},
  641. {0x3810, 0x00},
  642. {0x3811, 0x00},
  643. {0x3812, 0x00},
  644. {0x3813, 0x01},
  645. {0x3814, 0x01},
  646. {0x3815, 0x01},
  647. {0x3816, 0x00},
  648. {0x3817, 0x00},
  649. {0x3818, 0x00},
  650. {0x3819, 0x10},
  651. {0x3820, 0x80},
  652. {0x3821, 0x46},
  653. {0x382a, 0x01},
  654. {0x382b, 0x01},
  655. {0x3830, 0x06},
  656. {0x3836, 0x02},
  657. {0x3862, 0x04},
  658. {0x3863, 0x08},
  659. {0x3cc0, 0x33},
  660. {0x3d85, 0x17},
  661. {0x3d8c, 0x73},
  662. {0x3d8d, 0xde},
  663. {0x4001, 0xe0},
  664. {0x4003, 0x40},
  665. {0x4008, 0x00},
  666. {0x4009, 0x0b},
  667. {0x400a, 0x00},
  668. {0x400b, 0x84},
  669. {0x400f, 0x80},
  670. {0x4010, 0xf0},
  671. {0x4011, 0xff},
  672. {0x4012, 0x02},
  673. {0x4013, 0x01},
  674. {0x4014, 0x01},
  675. {0x4015, 0x01},
  676. {0x4042, 0x00},
  677. {0x4043, 0x80},
  678. {0x4044, 0x00},
  679. {0x4045, 0x80},
  680. {0x4046, 0x00},
  681. {0x4047, 0x80},
  682. {0x4048, 0x00},
  683. {0x4049, 0x80},
  684. {0x4041, 0x03},
  685. {0x404c, 0x20},
  686. {0x404d, 0x00},
  687. {0x404e, 0x20},
  688. {0x4203, 0x80},
  689. {0x4307, 0x30},
  690. {0x4317, 0x00},
  691. {0x4503, 0x08},
  692. {0x4601, 0x80},
  693. {0x4800, 0x44},
  694. {0x4816, 0x53},
  695. {0x481b, 0x58},
  696. {0x481f, 0x27},
  697. {0x4837, 0x16},
  698. {0x483c, 0x0f},
  699. {0x484b, 0x05},
  700. {0x5000, 0x57},
  701. {0x5001, 0x0a},
  702. {0x5004, 0x06},
  703. {0x502e, 0x03},
  704. {0x5030, 0x41},
  705. {0x5780, 0x14},
  706. {0x5781, 0x0f},
  707. {0x5782, 0x44},
  708. {0x5783, 0x02},
  709. {0x5784, 0x01},
  710. {0x5785, 0x01},
  711. {0x5786, 0x00},
  712. {0x5787, 0x04},
  713. {0x5788, 0x02},
  714. {0x5789, 0x0f},
  715. {0x578a, 0xfd},
  716. {0x578b, 0xf5},
  717. {0x578c, 0xf5},
  718. {0x578d, 0x03},
  719. {0x578e, 0x08},
  720. {0x578f, 0x0c},
  721. {0x5790, 0x08},
  722. {0x5791, 0x04},
  723. {0x5792, 0x00},
  724. {0x5793, 0x52},
  725. {0x5794, 0xa3},
  726. {0x5795, 0x02},
  727. {0x5796, 0x20},
  728. {0x5797, 0x20},
  729. {0x5798, 0xd5},
  730. {0x5799, 0xd5},
  731. {0x579a, 0x00},
  732. {0x579b, 0x50},
  733. {0x579c, 0x00},
  734. {0x579d, 0x2c},
  735. {0x579e, 0x0c},
  736. {0x579f, 0x40},
  737. {0x57a0, 0x09},
  738. {0x57a1, 0x40},
  739. {0x59f8, 0x3d},
  740. {0x5a08, 0x02},
  741. {0x5b00, 0x02},
  742. {0x5b01, 0x10},
  743. {0x5b02, 0x03},
  744. {0x5b03, 0xcf},
  745. {0x5b05, 0x6c},
  746. {0x5e00, 0x00}
  747. };
  748. static const struct ov8856_reg lane_4_mode_1640x1232[] = {
  749. /* 1640x1232 resolution */
  750. {0x3000, 0x20},
  751. {0x3003, 0x08},
  752. {0x300e, 0x20},
  753. {0x3010, 0x00},
  754. {0x3015, 0x84},
  755. {0x3018, 0x72},
  756. {0x3021, 0x23},
  757. {0x3033, 0x24},
  758. {0x3500, 0x00},
  759. {0x3501, 0x4c},
  760. {0x3502, 0xe0},
  761. {0x3503, 0x08},
  762. {0x3505, 0x83},
  763. {0x3508, 0x01},
  764. {0x3509, 0x80},
  765. {0x350c, 0x00},
  766. {0x350d, 0x80},
  767. {0x350e, 0x04},
  768. {0x350f, 0x00},
  769. {0x3510, 0x00},
  770. {0x3511, 0x02},
  771. {0x3512, 0x00},
  772. {0x3600, 0x72},
  773. {0x3601, 0x40},
  774. {0x3602, 0x30},
  775. {0x3610, 0xc5},
  776. {0x3611, 0x58},
  777. {0x3612, 0x5c},
  778. {0x3613, 0xca},
  779. {0x3614, 0x20},
  780. {0x3628, 0xff},
  781. {0x3629, 0xff},
  782. {0x362a, 0xff},
  783. {0x3633, 0x10},
  784. {0x3634, 0x10},
  785. {0x3635, 0x10},
  786. {0x3636, 0x10},
  787. {0x3663, 0x08},
  788. {0x3669, 0x34},
  789. {0x366e, 0x08},
  790. {0x3706, 0x86},
  791. {0x370b, 0x7e},
  792. {0x3714, 0x27},
  793. {0x3730, 0x12},
  794. {0x3733, 0x10},
  795. {0x3764, 0x00},
  796. {0x3765, 0x00},
  797. {0x3769, 0x62},
  798. {0x376a, 0x2a},
  799. {0x376b, 0x30},
  800. {0x3780, 0x00},
  801. {0x3781, 0x24},
  802. {0x3782, 0x00},
  803. {0x3783, 0x23},
  804. {0x3798, 0x2f},
  805. {0x37a1, 0x60},
  806. {0x37a8, 0x6a},
  807. {0x37ab, 0x3f},
  808. {0x37c2, 0x14},
  809. {0x37c3, 0xf1},
  810. {0x37c9, 0x80},
  811. {0x37cb, 0x16},
  812. {0x37cc, 0x16},
  813. {0x37cd, 0x16},
  814. {0x37ce, 0x16},
  815. {0x3800, 0x00},
  816. {0x3801, 0x00},
  817. {0x3802, 0x00},
  818. {0x3803, 0x00},
  819. {0x3804, 0x0c},
  820. {0x3805, 0xdf},
  821. {0x3806, 0x09},
  822. {0x3807, 0xaf},
  823. {0x3808, 0x06},
  824. {0x3809, 0x68},
  825. {0x380a, 0x04},
  826. {0x380b, 0xd0},
  827. {0x380c, 0x0e},
  828. {0x380d, 0xec},
  829. {0x380e, 0x04},
  830. {0x380f, 0xe8},
  831. {0x3810, 0x00},
  832. {0x3811, 0x04},
  833. {0x3812, 0x00},
  834. {0x3813, 0x05},
  835. {0x3814, 0x03},
  836. {0x3815, 0x01},
  837. {0x3816, 0x00},
  838. {0x3817, 0x00},
  839. {0x3818, 0x00},
  840. {0x3819, 0x10},
  841. {0x3820, 0x90},
  842. {0x3821, 0x67},
  843. {0x382a, 0x03},
  844. {0x382b, 0x01},
  845. {0x3830, 0x06},
  846. {0x3836, 0x02},
  847. {0x3862, 0x04},
  848. {0x3863, 0x08},
  849. {0x3cc0, 0x33},
  850. {0x3d85, 0x17},
  851. {0x3d8c, 0x73},
  852. {0x3d8d, 0xde},
  853. {0x4001, 0xe0},
  854. {0x4003, 0x40},
  855. {0x4008, 0x00},
  856. {0x4009, 0x05},
  857. {0x400a, 0x00},
  858. {0x400b, 0x84},
  859. {0x400f, 0x80},
  860. {0x4010, 0xf0},
  861. {0x4011, 0xff},
  862. {0x4012, 0x02},
  863. {0x4013, 0x01},
  864. {0x4014, 0x01},
  865. {0x4015, 0x01},
  866. {0x4042, 0x00},
  867. {0x4043, 0x80},
  868. {0x4044, 0x00},
  869. {0x4045, 0x80},
  870. {0x4046, 0x00},
  871. {0x4047, 0x80},
  872. {0x4048, 0x00},
  873. {0x4049, 0x80},
  874. {0x4041, 0x03},
  875. {0x404c, 0x20},
  876. {0x404d, 0x00},
  877. {0x404e, 0x20},
  878. {0x4203, 0x80},
  879. {0x4307, 0x30},
  880. {0x4317, 0x00},
  881. {0x4503, 0x08},
  882. {0x4601, 0x80},
  883. {0x4800, 0x44},
  884. {0x4816, 0x53},
  885. {0x481b, 0x58},
  886. {0x481f, 0x27},
  887. {0x4837, 0x16},
  888. {0x483c, 0x0f},
  889. {0x484b, 0x05},
  890. {0x5000, 0x57},
  891. {0x5001, 0x0a},
  892. {0x5004, 0x06},
  893. {0x502e, 0x03},
  894. {0x5030, 0x41},
  895. {0x5780, 0x14},
  896. {0x5781, 0x0f},
  897. {0x5782, 0x44},
  898. {0x5783, 0x02},
  899. {0x5784, 0x01},
  900. {0x5785, 0x01},
  901. {0x5786, 0x00},
  902. {0x5787, 0x04},
  903. {0x5788, 0x02},
  904. {0x5789, 0x0f},
  905. {0x578a, 0xfd},
  906. {0x578b, 0xf5},
  907. {0x578c, 0xf5},
  908. {0x578d, 0x03},
  909. {0x578e, 0x08},
  910. {0x578f, 0x0c},
  911. {0x5790, 0x08},
  912. {0x5791, 0x04},
  913. {0x5792, 0x00},
  914. {0x5793, 0x52},
  915. {0x5794, 0xa3},
  916. {0x5795, 0x00},
  917. {0x5796, 0x10},
  918. {0x5797, 0x10},
  919. {0x5798, 0x73},
  920. {0x5799, 0x73},
  921. {0x579a, 0x00},
  922. {0x579b, 0x28},
  923. {0x579c, 0x00},
  924. {0x579d, 0x16},
  925. {0x579e, 0x06},
  926. {0x579f, 0x20},
  927. {0x57a0, 0x04},
  928. {0x57a1, 0xa0},
  929. {0x59f8, 0x3d},
  930. {0x5a08, 0x02},
  931. {0x5b00, 0x02},
  932. {0x5b01, 0x10},
  933. {0x5b02, 0x03},
  934. {0x5b03, 0xcf},
  935. {0x5b05, 0x6c},
  936. {0x5e00, 0x00}
  937. };
  938. static const struct ov8856_reg lane_4_mode_3264x2448[] = {
  939. /* 3264x2448 resolution */
  940. {0x0103, 0x01},
  941. {0x0302, 0x3c},
  942. {0x0303, 0x01},
  943. {0x031e, 0x0c},
  944. {0x3000, 0x20},
  945. {0x3003, 0x08},
  946. {0x300e, 0x20},
  947. {0x3010, 0x00},
  948. {0x3015, 0x84},
  949. {0x3018, 0x72},
  950. {0x3021, 0x23},
  951. {0x3033, 0x24},
  952. {0x3500, 0x00},
  953. {0x3501, 0x9a},
  954. {0x3502, 0x20},
  955. {0x3503, 0x08},
  956. {0x3505, 0x83},
  957. {0x3508, 0x01},
  958. {0x3509, 0x80},
  959. {0x350c, 0x00},
  960. {0x350d, 0x80},
  961. {0x350e, 0x04},
  962. {0x350f, 0x00},
  963. {0x3510, 0x00},
  964. {0x3511, 0x02},
  965. {0x3512, 0x00},
  966. {0x3600, 0x72},
  967. {0x3601, 0x40},
  968. {0x3602, 0x30},
  969. {0x3610, 0xc5},
  970. {0x3611, 0x58},
  971. {0x3612, 0x5c},
  972. {0x3613, 0xca},
  973. {0x3614, 0x60},
  974. {0x3628, 0xff},
  975. {0x3629, 0xff},
  976. {0x362a, 0xff},
  977. {0x3633, 0x10},
  978. {0x3634, 0x10},
  979. {0x3635, 0x10},
  980. {0x3636, 0x10},
  981. {0x3663, 0x08},
  982. {0x3669, 0x34},
  983. {0x366d, 0x00},
  984. {0x366e, 0x10},
  985. {0x3706, 0x86},
  986. {0x370b, 0x7e},
  987. {0x3714, 0x23},
  988. {0x3730, 0x12},
  989. {0x3733, 0x10},
  990. {0x3764, 0x00},
  991. {0x3765, 0x00},
  992. {0x3769, 0x62},
  993. {0x376a, 0x2a},
  994. {0x376b, 0x30},
  995. {0x3780, 0x00},
  996. {0x3781, 0x24},
  997. {0x3782, 0x00},
  998. {0x3783, 0x23},
  999. {0x3798, 0x2f},
  1000. {0x37a1, 0x60},
  1001. {0x37a8, 0x6a},
  1002. {0x37ab, 0x3f},
  1003. {0x37c2, 0x04},
  1004. {0x37c3, 0xf1},
  1005. {0x37c9, 0x80},
  1006. {0x37cb, 0x16},
  1007. {0x37cc, 0x16},
  1008. {0x37cd, 0x16},
  1009. {0x37ce, 0x16},
  1010. {0x3800, 0x00},
  1011. {0x3801, 0x00},
  1012. {0x3802, 0x00},
  1013. {0x3803, 0x0c},
  1014. {0x3804, 0x0c},
  1015. {0x3805, 0xdf},
  1016. {0x3806, 0x09},
  1017. {0x3807, 0xa3},
  1018. {0x3808, 0x0c},
  1019. {0x3809, 0xc0},
  1020. {0x380a, 0x09},
  1021. {0x380b, 0x90},
  1022. {0x380c, 0x07},
  1023. {0x380d, 0x8c},
  1024. {0x380e, 0x09},
  1025. {0x380f, 0xb2},
  1026. {0x3810, 0x00},
  1027. {0x3811, 0x04},
  1028. {0x3812, 0x00},
  1029. {0x3813, 0x02},
  1030. {0x3814, 0x01},
  1031. {0x3815, 0x01},
  1032. {0x3816, 0x00},
  1033. {0x3817, 0x00},
  1034. {0x3818, 0x00},
  1035. {0x3819, 0x10},
  1036. {0x3820, 0x80},
  1037. {0x3821, 0x46},
  1038. {0x382a, 0x01},
  1039. {0x382b, 0x01},
  1040. {0x3830, 0x06},
  1041. {0x3836, 0x02},
  1042. {0x3862, 0x04},
  1043. {0x3863, 0x08},
  1044. {0x3cc0, 0x33},
  1045. {0x3d85, 0x17},
  1046. {0x3d8c, 0x73},
  1047. {0x3d8d, 0xde},
  1048. {0x4001, 0xe0},
  1049. {0x4003, 0x40},
  1050. {0x4008, 0x00},
  1051. {0x4009, 0x0b},
  1052. {0x400a, 0x00},
  1053. {0x400b, 0x84},
  1054. {0x400f, 0x80},
  1055. {0x4010, 0xf0},
  1056. {0x4011, 0xff},
  1057. {0x4012, 0x02},
  1058. {0x4013, 0x01},
  1059. {0x4014, 0x01},
  1060. {0x4015, 0x01},
  1061. {0x4042, 0x00},
  1062. {0x4043, 0x80},
  1063. {0x4044, 0x00},
  1064. {0x4045, 0x80},
  1065. {0x4046, 0x00},
  1066. {0x4047, 0x80},
  1067. {0x4048, 0x00},
  1068. {0x4049, 0x80},
  1069. {0x4041, 0x03},
  1070. {0x404c, 0x20},
  1071. {0x404d, 0x00},
  1072. {0x404e, 0x20},
  1073. {0x4203, 0x80},
  1074. {0x4307, 0x30},
  1075. {0x4317, 0x00},
  1076. {0x4502, 0x50},
  1077. {0x4503, 0x08},
  1078. {0x4601, 0x80},
  1079. {0x4800, 0x44},
  1080. {0x4816, 0x53},
  1081. {0x481b, 0x50},
  1082. {0x481f, 0x27},
  1083. {0x4823, 0x3c},
  1084. {0x482b, 0x00},
  1085. {0x4831, 0x66},
  1086. {0x4837, 0x16},
  1087. {0x483c, 0x0f},
  1088. {0x484b, 0x05},
  1089. {0x5000, 0x77},
  1090. {0x5001, 0x0a},
  1091. {0x5003, 0xc8},
  1092. {0x5004, 0x04},
  1093. {0x5006, 0x00},
  1094. {0x5007, 0x00},
  1095. {0x502e, 0x03},
  1096. {0x5030, 0x41},
  1097. {0x5780, 0x14},
  1098. {0x5781, 0x0f},
  1099. {0x5782, 0x44},
  1100. {0x5783, 0x02},
  1101. {0x5784, 0x01},
  1102. {0x5785, 0x01},
  1103. {0x5786, 0x00},
  1104. {0x5787, 0x04},
  1105. {0x5788, 0x02},
  1106. {0x5789, 0x0f},
  1107. {0x578a, 0xfd},
  1108. {0x578b, 0xf5},
  1109. {0x578c, 0xf5},
  1110. {0x578d, 0x03},
  1111. {0x578e, 0x08},
  1112. {0x578f, 0x0c},
  1113. {0x5790, 0x08},
  1114. {0x5791, 0x04},
  1115. {0x5792, 0x00},
  1116. {0x5793, 0x52},
  1117. {0x5794, 0xa3},
  1118. {0x5795, 0x02},
  1119. {0x5796, 0x20},
  1120. {0x5797, 0x20},
  1121. {0x5798, 0xd5},
  1122. {0x5799, 0xd5},
  1123. {0x579a, 0x00},
  1124. {0x579b, 0x50},
  1125. {0x579c, 0x00},
  1126. {0x579d, 0x2c},
  1127. {0x579e, 0x0c},
  1128. {0x579f, 0x40},
  1129. {0x57a0, 0x09},
  1130. {0x57a1, 0x40},
  1131. {0x59f8, 0x3d},
  1132. {0x5a08, 0x02},
  1133. {0x5b00, 0x02},
  1134. {0x5b01, 0x10},
  1135. {0x5b02, 0x03},
  1136. {0x5b03, 0xcf},
  1137. {0x5b05, 0x6c},
  1138. {0x5e00, 0x00},
  1139. {0x5e10, 0xfc}
  1140. };
  1141. static const struct ov8856_reg lane_4_mode_1632x1224[] = {
  1142. /* 1632x1224 resolution */
  1143. {0x0103, 0x01},
  1144. {0x0302, 0x3c},
  1145. {0x0303, 0x01},
  1146. {0x031e, 0x0c},
  1147. {0x3000, 0x20},
  1148. {0x3003, 0x08},
  1149. {0x300e, 0x20},
  1150. {0x3010, 0x00},
  1151. {0x3015, 0x84},
  1152. {0x3018, 0x72},
  1153. {0x3021, 0x23},
  1154. {0x3033, 0x24},
  1155. {0x3500, 0x00},
  1156. {0x3501, 0x4c},
  1157. {0x3502, 0xe0},
  1158. {0x3503, 0x08},
  1159. {0x3505, 0x83},
  1160. {0x3508, 0x01},
  1161. {0x3509, 0x80},
  1162. {0x350c, 0x00},
  1163. {0x350d, 0x80},
  1164. {0x350e, 0x04},
  1165. {0x350f, 0x00},
  1166. {0x3510, 0x00},
  1167. {0x3511, 0x02},
  1168. {0x3512, 0x00},
  1169. {0x3600, 0x72},
  1170. {0x3601, 0x40},
  1171. {0x3602, 0x30},
  1172. {0x3610, 0xc5},
  1173. {0x3611, 0x58},
  1174. {0x3612, 0x5c},
  1175. {0x3613, 0xca},
  1176. {0x3614, 0x60},
  1177. {0x3628, 0xff},
  1178. {0x3629, 0xff},
  1179. {0x362a, 0xff},
  1180. {0x3633, 0x10},
  1181. {0x3634, 0x10},
  1182. {0x3635, 0x10},
  1183. {0x3636, 0x10},
  1184. {0x3663, 0x08},
  1185. {0x3669, 0x34},
  1186. {0x366d, 0x00},
  1187. {0x366e, 0x08},
  1188. {0x3706, 0x86},
  1189. {0x370b, 0x7e},
  1190. {0x3714, 0x27},
  1191. {0x3730, 0x12},
  1192. {0x3733, 0x10},
  1193. {0x3764, 0x00},
  1194. {0x3765, 0x00},
  1195. {0x3769, 0x62},
  1196. {0x376a, 0x2a},
  1197. {0x376b, 0x30},
  1198. {0x3780, 0x00},
  1199. {0x3781, 0x24},
  1200. {0x3782, 0x00},
  1201. {0x3783, 0x23},
  1202. {0x3798, 0x2f},
  1203. {0x37a1, 0x60},
  1204. {0x37a8, 0x6a},
  1205. {0x37ab, 0x3f},
  1206. {0x37c2, 0x14},
  1207. {0x37c3, 0xf1},
  1208. {0x37c9, 0x80},
  1209. {0x37cb, 0x16},
  1210. {0x37cc, 0x16},
  1211. {0x37cd, 0x16},
  1212. {0x37ce, 0x16},
  1213. {0x3800, 0x00},
  1214. {0x3801, 0x00},
  1215. {0x3802, 0x00},
  1216. {0x3803, 0x0c},
  1217. {0x3804, 0x0c},
  1218. {0x3805, 0xdf},
  1219. {0x3806, 0x09},
  1220. {0x3807, 0xa3},
  1221. {0x3808, 0x06},
  1222. {0x3809, 0x60},
  1223. {0x380a, 0x04},
  1224. {0x380b, 0xc8},
  1225. {0x380c, 0x07},
  1226. {0x380d, 0x8c},
  1227. {0x380e, 0x09},
  1228. {0x380f, 0xb2},
  1229. {0x3810, 0x00},
  1230. {0x3811, 0x02},
  1231. {0x3812, 0x00},
  1232. {0x3813, 0x02},
  1233. {0x3814, 0x03},
  1234. {0x3815, 0x01},
  1235. {0x3816, 0x00},
  1236. {0x3817, 0x00},
  1237. {0x3818, 0x00},
  1238. {0x3819, 0x10},
  1239. {0x3820, 0x80},
  1240. {0x3821, 0x47},
  1241. {0x382a, 0x03},
  1242. {0x382b, 0x01},
  1243. {0x3830, 0x06},
  1244. {0x3836, 0x02},
  1245. {0x3862, 0x04},
  1246. {0x3863, 0x08},
  1247. {0x3cc0, 0x33},
  1248. {0x3d85, 0x17},
  1249. {0x3d8c, 0x73},
  1250. {0x3d8d, 0xde},
  1251. {0x4001, 0xe0},
  1252. {0x4003, 0x40},
  1253. {0x4008, 0x00},
  1254. {0x4009, 0x05},
  1255. {0x400a, 0x00},
  1256. {0x400b, 0x84},
  1257. {0x400f, 0x80},
  1258. {0x4010, 0xf0},
  1259. {0x4011, 0xff},
  1260. {0x4012, 0x02},
  1261. {0x4013, 0x01},
  1262. {0x4014, 0x01},
  1263. {0x4015, 0x01},
  1264. {0x4042, 0x00},
  1265. {0x4043, 0x80},
  1266. {0x4044, 0x00},
  1267. {0x4045, 0x80},
  1268. {0x4046, 0x00},
  1269. {0x4047, 0x80},
  1270. {0x4048, 0x00},
  1271. {0x4049, 0x80},
  1272. {0x4041, 0x03},
  1273. {0x404c, 0x20},
  1274. {0x404d, 0x00},
  1275. {0x404e, 0x20},
  1276. {0x4203, 0x80},
  1277. {0x4307, 0x30},
  1278. {0x4317, 0x00},
  1279. {0x4502, 0x50},
  1280. {0x4503, 0x08},
  1281. {0x4601, 0x80},
  1282. {0x4800, 0x44},
  1283. {0x4816, 0x53},
  1284. {0x481b, 0x50},
  1285. {0x481f, 0x27},
  1286. {0x4823, 0x3c},
  1287. {0x482b, 0x00},
  1288. {0x4831, 0x66},
  1289. {0x4837, 0x16},
  1290. {0x483c, 0x0f},
  1291. {0x484b, 0x05},
  1292. {0x5000, 0x77},
  1293. {0x5001, 0x0a},
  1294. {0x5003, 0xc8},
  1295. {0x5004, 0x04},
  1296. {0x5006, 0x00},
  1297. {0x5007, 0x00},
  1298. {0x502e, 0x03},
  1299. {0x5030, 0x41},
  1300. {0x5795, 0x00},
  1301. {0x5796, 0x10},
  1302. {0x5797, 0x10},
  1303. {0x5798, 0x73},
  1304. {0x5799, 0x73},
  1305. {0x579a, 0x00},
  1306. {0x579b, 0x28},
  1307. {0x579c, 0x00},
  1308. {0x579d, 0x16},
  1309. {0x579e, 0x06},
  1310. {0x579f, 0x20},
  1311. {0x57a0, 0x04},
  1312. {0x57a1, 0xa0},
  1313. {0x5780, 0x14},
  1314. {0x5781, 0x0f},
  1315. {0x5782, 0x44},
  1316. {0x5783, 0x02},
  1317. {0x5784, 0x01},
  1318. {0x5785, 0x01},
  1319. {0x5786, 0x00},
  1320. {0x5787, 0x04},
  1321. {0x5788, 0x02},
  1322. {0x5789, 0x0f},
  1323. {0x578a, 0xfd},
  1324. {0x578b, 0xf5},
  1325. {0x578c, 0xf5},
  1326. {0x578d, 0x03},
  1327. {0x578e, 0x08},
  1328. {0x578f, 0x0c},
  1329. {0x5790, 0x08},
  1330. {0x5791, 0x04},
  1331. {0x5792, 0x00},
  1332. {0x5793, 0x52},
  1333. {0x5794, 0xa3},
  1334. {0x59f8, 0x3d},
  1335. {0x5a08, 0x02},
  1336. {0x5b00, 0x02},
  1337. {0x5b01, 0x10},
  1338. {0x5b02, 0x03},
  1339. {0x5b03, 0xcf},
  1340. {0x5b05, 0x6c},
  1341. {0x5e00, 0x00},
  1342. {0x5e10, 0xfc}
  1343. };
  1344. static const struct ov8856_reg mipi_data_mbus_sbggr10_1x10[] = {
  1345. {0x3813, 0x02},
  1346. };
  1347. static const struct ov8856_reg mipi_data_mbus_sgrbg10_1x10[] = {
  1348. {0x3813, 0x01},
  1349. };
  1350. static const u32 ov8856_mbus_codes[] = {
  1351. MEDIA_BUS_FMT_SBGGR10_1X10,
  1352. MEDIA_BUS_FMT_SGRBG10_1X10
  1353. };
  1354. static const char * const ov8856_test_pattern_menu[] = {
  1355. "Disabled",
  1356. "Standard Color Bar",
  1357. "Top-Bottom Darker Color Bar",
  1358. "Right-Left Darker Color Bar",
  1359. "Bottom-Top Darker Color Bar"
  1360. };
  1361. static const struct ov8856_reg_list bayer_offset_configs[] = {
  1362. [OV8856_MEDIA_BUS_FMT_SBGGR10_1X10] = {
  1363. .num_of_regs = ARRAY_SIZE(mipi_data_mbus_sbggr10_1x10),
  1364. .regs = mipi_data_mbus_sbggr10_1x10,
  1365. },
  1366. [OV8856_MEDIA_BUS_FMT_SGRBG10_1X10] = {
  1367. .num_of_regs = ARRAY_SIZE(mipi_data_mbus_sgrbg10_1x10),
  1368. .regs = mipi_data_mbus_sgrbg10_1x10,
  1369. }
  1370. };
  1371. struct ov8856 {
  1372. struct v4l2_subdev sd;
  1373. struct media_pad pad;
  1374. struct v4l2_ctrl_handler ctrl_handler;
  1375. struct clk *xvclk;
  1376. struct gpio_desc *reset_gpio;
  1377. struct regulator_bulk_data supplies[ARRAY_SIZE(ov8856_supply_names)];
  1378. /* V4L2 Controls */
  1379. struct v4l2_ctrl *link_freq;
  1380. struct v4l2_ctrl *pixel_rate;
  1381. struct v4l2_ctrl *vblank;
  1382. struct v4l2_ctrl *hblank;
  1383. struct v4l2_ctrl *exposure;
  1384. /* Current mode */
  1385. const struct ov8856_mode *cur_mode;
  1386. /* Application specified mbus format */
  1387. u32 cur_mbus_index;
  1388. /* To serialize asynchronus callbacks */
  1389. struct mutex mutex;
  1390. /* Streaming on/off */
  1391. bool streaming;
  1392. /* lanes index */
  1393. u8 nlanes;
  1394. const struct ov8856_lane_cfg *priv_lane;
  1395. u8 modes_size;
  1396. /* True if the device has been identified */
  1397. bool identified;
  1398. };
  1399. struct ov8856_lane_cfg {
  1400. const s64 link_freq_menu_items[2];
  1401. const struct ov8856_link_freq_config link_freq_configs[2];
  1402. const struct ov8856_mode supported_modes[4];
  1403. };
  1404. static const struct ov8856_lane_cfg lane_cfg_2 = {
  1405. {
  1406. 720000000,
  1407. 360000000,
  1408. },
  1409. {{
  1410. .reg_list = {
  1411. .num_of_regs =
  1412. ARRAY_SIZE(mipi_data_rate_lane_2.regs_0),
  1413. .regs = mipi_data_rate_lane_2.regs_0,
  1414. }
  1415. },
  1416. {
  1417. .reg_list = {
  1418. .num_of_regs =
  1419. ARRAY_SIZE(mipi_data_rate_lane_2.regs_1),
  1420. .regs = mipi_data_rate_lane_2.regs_1,
  1421. }
  1422. }},
  1423. {{
  1424. .width = 3280,
  1425. .height = 2464,
  1426. .hts = 1928,
  1427. .vts_def = 2488,
  1428. .vts_min = 2488,
  1429. .reg_list = {
  1430. .num_of_regs =
  1431. ARRAY_SIZE(lane_2_mode_3280x2464),
  1432. .regs = lane_2_mode_3280x2464,
  1433. },
  1434. .link_freq_index = 0,
  1435. .data_lanes = 2,
  1436. .default_mbus_index = OV8856_MEDIA_BUS_FMT_SGRBG10_1X10,
  1437. },
  1438. {
  1439. .width = 1640,
  1440. .height = 1232,
  1441. .hts = 3168,
  1442. .vts_def = 1514,
  1443. .vts_min = 1514,
  1444. .reg_list = {
  1445. .num_of_regs =
  1446. ARRAY_SIZE(lane_2_mode_1640x1232),
  1447. .regs = lane_2_mode_1640x1232,
  1448. },
  1449. .link_freq_index = 1,
  1450. .data_lanes = 2,
  1451. .default_mbus_index = OV8856_MEDIA_BUS_FMT_SGRBG10_1X10,
  1452. }}
  1453. };
  1454. static const struct ov8856_lane_cfg lane_cfg_4 = {
  1455. {
  1456. 360000000,
  1457. 180000000,
  1458. },
  1459. {{
  1460. .reg_list = {
  1461. .num_of_regs =
  1462. ARRAY_SIZE(mipi_data_rate_lane_4.regs_0),
  1463. .regs = mipi_data_rate_lane_4.regs_0,
  1464. }
  1465. },
  1466. {
  1467. .reg_list = {
  1468. .num_of_regs =
  1469. ARRAY_SIZE(mipi_data_rate_lane_4.regs_1),
  1470. .regs = mipi_data_rate_lane_4.regs_1,
  1471. }
  1472. }},
  1473. {{
  1474. .width = 3280,
  1475. .height = 2464,
  1476. .hts = 1928,
  1477. .vts_def = 2488,
  1478. .vts_min = 2488,
  1479. .reg_list = {
  1480. .num_of_regs =
  1481. ARRAY_SIZE(lane_4_mode_3280x2464),
  1482. .regs = lane_4_mode_3280x2464,
  1483. },
  1484. .link_freq_index = 0,
  1485. .data_lanes = 4,
  1486. .default_mbus_index = OV8856_MEDIA_BUS_FMT_SGRBG10_1X10,
  1487. },
  1488. {
  1489. .width = 1640,
  1490. .height = 1232,
  1491. .hts = 3820,
  1492. .vts_def = 1256,
  1493. .vts_min = 1256,
  1494. .reg_list = {
  1495. .num_of_regs =
  1496. ARRAY_SIZE(lane_4_mode_1640x1232),
  1497. .regs = lane_4_mode_1640x1232,
  1498. },
  1499. .link_freq_index = 1,
  1500. .data_lanes = 4,
  1501. .default_mbus_index = OV8856_MEDIA_BUS_FMT_SGRBG10_1X10,
  1502. },
  1503. {
  1504. .width = 3264,
  1505. .height = 2448,
  1506. .hts = 1932,
  1507. .vts_def = 2482,
  1508. .vts_min = 2482,
  1509. .reg_list = {
  1510. .num_of_regs =
  1511. ARRAY_SIZE(lane_4_mode_3264x2448),
  1512. .regs = lane_4_mode_3264x2448,
  1513. },
  1514. .link_freq_index = 0,
  1515. .data_lanes = 4,
  1516. .default_mbus_index = OV8856_MEDIA_BUS_FMT_SBGGR10_1X10,
  1517. },
  1518. {
  1519. .width = 1632,
  1520. .height = 1224,
  1521. .hts = 1932,
  1522. .vts_def = 2482,
  1523. .vts_min = 2482,
  1524. .reg_list = {
  1525. .num_of_regs =
  1526. ARRAY_SIZE(lane_4_mode_1632x1224),
  1527. .regs = lane_4_mode_1632x1224,
  1528. },
  1529. .link_freq_index = 1,
  1530. .data_lanes = 4,
  1531. .default_mbus_index = OV8856_MEDIA_BUS_FMT_SBGGR10_1X10,
  1532. }}
  1533. };
  1534. static unsigned int ov8856_modes_num(const struct ov8856 *ov8856)
  1535. {
  1536. unsigned int i, count = 0;
  1537. for (i = 0; i < ARRAY_SIZE(ov8856->priv_lane->supported_modes); i++) {
  1538. if (ov8856->priv_lane->supported_modes[i].width == 0)
  1539. break;
  1540. count++;
  1541. }
  1542. return count;
  1543. }
  1544. static u64 to_rate(const s64 *link_freq_menu_items,
  1545. u32 f_index, u8 nlanes)
  1546. {
  1547. u64 pixel_rate = link_freq_menu_items[f_index] * 2 * nlanes;
  1548. do_div(pixel_rate, OV8856_RGB_DEPTH);
  1549. return pixel_rate;
  1550. }
  1551. static u64 to_pixels_per_line(const s64 *link_freq_menu_items, u32 hts,
  1552. u32 f_index, u8 nlanes)
  1553. {
  1554. u64 ppl = hts * to_rate(link_freq_menu_items, f_index, nlanes);
  1555. do_div(ppl, OV8856_SCLK);
  1556. return ppl;
  1557. }
  1558. static int ov8856_read_reg(struct ov8856 *ov8856, u16 reg, u16 len, u32 *val)
  1559. {
  1560. struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd);
  1561. struct i2c_msg msgs[2];
  1562. u8 addr_buf[2];
  1563. u8 data_buf[4] = {0};
  1564. int ret;
  1565. if (len > 4)
  1566. return -EINVAL;
  1567. put_unaligned_be16(reg, addr_buf);
  1568. msgs[0].addr = client->addr;
  1569. msgs[0].flags = 0;
  1570. msgs[0].len = sizeof(addr_buf);
  1571. msgs[0].buf = addr_buf;
  1572. msgs[1].addr = client->addr;
  1573. msgs[1].flags = I2C_M_RD;
  1574. msgs[1].len = len;
  1575. msgs[1].buf = &data_buf[4 - len];
  1576. ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
  1577. if (ret != ARRAY_SIZE(msgs))
  1578. return -EIO;
  1579. *val = get_unaligned_be32(data_buf);
  1580. return 0;
  1581. }
  1582. static int ov8856_write_reg(struct ov8856 *ov8856, u16 reg, u16 len, u32 val)
  1583. {
  1584. struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd);
  1585. u8 buf[6];
  1586. if (len > 4)
  1587. return -EINVAL;
  1588. put_unaligned_be16(reg, buf);
  1589. put_unaligned_be32(val << 8 * (4 - len), buf + 2);
  1590. if (i2c_master_send(client, buf, len + 2) != len + 2)
  1591. return -EIO;
  1592. return 0;
  1593. }
  1594. static int ov8856_write_reg_list(struct ov8856 *ov8856,
  1595. const struct ov8856_reg_list *r_list)
  1596. {
  1597. struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd);
  1598. unsigned int i;
  1599. int ret;
  1600. for (i = 0; i < r_list->num_of_regs; i++) {
  1601. ret = ov8856_write_reg(ov8856, r_list->regs[i].address, 1,
  1602. r_list->regs[i].val);
  1603. if (ret) {
  1604. dev_err_ratelimited(&client->dev,
  1605. "failed to write reg 0x%4.4x. error = %d",
  1606. r_list->regs[i].address, ret);
  1607. return ret;
  1608. }
  1609. }
  1610. return 0;
  1611. }
  1612. static int ov8856_identify_module(struct ov8856 *ov8856)
  1613. {
  1614. struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd);
  1615. int ret;
  1616. u32 val;
  1617. if (ov8856->identified)
  1618. return 0;
  1619. ret = ov8856_read_reg(ov8856, OV8856_REG_CHIP_ID,
  1620. OV8856_REG_VALUE_24BIT, &val);
  1621. if (ret)
  1622. return ret;
  1623. if (val != OV8856_CHIP_ID) {
  1624. dev_err(&client->dev, "chip id mismatch: %x!=%x",
  1625. OV8856_CHIP_ID, val);
  1626. return -ENXIO;
  1627. }
  1628. ov8856->identified = true;
  1629. return 0;
  1630. }
  1631. static int ov8856_update_digital_gain(struct ov8856 *ov8856, u32 d_gain)
  1632. {
  1633. return ov8856_write_reg(ov8856, OV8856_REG_DIGITAL_GAIN,
  1634. OV8856_REG_VALUE_16BIT, d_gain);
  1635. }
  1636. static int ov8856_test_pattern(struct ov8856 *ov8856, u32 pattern)
  1637. {
  1638. if (pattern)
  1639. pattern = (pattern - 1) << OV8856_TEST_PATTERN_BAR_SHIFT |
  1640. OV8856_TEST_PATTERN_ENABLE;
  1641. return ov8856_write_reg(ov8856, OV8856_REG_TEST_PATTERN,
  1642. OV8856_REG_VALUE_08BIT, pattern);
  1643. }
  1644. static int ov8856_set_ctrl_hflip(struct ov8856 *ov8856, u32 ctrl_val)
  1645. {
  1646. int ret;
  1647. u32 val;
  1648. ret = ov8856_read_reg(ov8856, OV8856_REG_MIRROR_OPT_1,
  1649. OV8856_REG_VALUE_08BIT, &val);
  1650. if (ret)
  1651. return ret;
  1652. ret = ov8856_write_reg(ov8856, OV8856_REG_MIRROR_OPT_1,
  1653. OV8856_REG_VALUE_08BIT,
  1654. ctrl_val ? val & ~OV8856_REG_MIRROR_OP_2 :
  1655. val | OV8856_REG_MIRROR_OP_2);
  1656. if (ret)
  1657. return ret;
  1658. ret = ov8856_read_reg(ov8856, OV8856_REG_FORMAT2,
  1659. OV8856_REG_VALUE_08BIT, &val);
  1660. if (ret)
  1661. return ret;
  1662. return ov8856_write_reg(ov8856, OV8856_REG_FORMAT2,
  1663. OV8856_REG_VALUE_08BIT,
  1664. ctrl_val ? val & ~OV8856_REG_FORMAT2_OP_1 &
  1665. ~OV8856_REG_FORMAT2_OP_2 &
  1666. ~OV8856_REG_FORMAT2_OP_3 :
  1667. val | OV8856_REG_FORMAT2_OP_1 |
  1668. OV8856_REG_FORMAT2_OP_2 |
  1669. OV8856_REG_FORMAT2_OP_3);
  1670. }
  1671. static int ov8856_set_ctrl_vflip(struct ov8856 *ov8856, u8 ctrl_val)
  1672. {
  1673. int ret;
  1674. u32 val;
  1675. ret = ov8856_read_reg(ov8856, OV8856_REG_FLIP_OPT_1,
  1676. OV8856_REG_VALUE_08BIT, &val);
  1677. if (ret)
  1678. return ret;
  1679. ret = ov8856_write_reg(ov8856, OV8856_REG_FLIP_OPT_1,
  1680. OV8856_REG_VALUE_08BIT,
  1681. ctrl_val ? val | OV8856_REG_FLIP_OP_1 |
  1682. OV8856_REG_FLIP_OP_2 :
  1683. val & ~OV8856_REG_FLIP_OP_1 &
  1684. ~OV8856_REG_FLIP_OP_2);
  1685. ret = ov8856_read_reg(ov8856, OV8856_REG_FLIP_OPT_2,
  1686. OV8856_REG_VALUE_08BIT, &val);
  1687. if (ret)
  1688. return ret;
  1689. ret = ov8856_write_reg(ov8856, OV8856_REG_FLIP_OPT_2,
  1690. OV8856_REG_VALUE_08BIT,
  1691. ctrl_val ? val | OV8856_REG_FLIP_OP_2 :
  1692. val & ~OV8856_REG_FLIP_OP_2);
  1693. ret = ov8856_read_reg(ov8856, OV8856_REG_FLIP_OPT_3,
  1694. OV8856_REG_VALUE_08BIT, &val);
  1695. if (ret)
  1696. return ret;
  1697. ret = ov8856_write_reg(ov8856, OV8856_REG_FLIP_OPT_3,
  1698. OV8856_REG_VALUE_08BIT,
  1699. ctrl_val ? val & ~OV8856_REG_FLIP_OP_0 &
  1700. ~OV8856_REG_FLIP_OP_1 :
  1701. val | OV8856_REG_FLIP_OP_0 |
  1702. OV8856_REG_FLIP_OP_1);
  1703. ret = ov8856_read_reg(ov8856, OV8856_REG_FORMAT1,
  1704. OV8856_REG_VALUE_08BIT, &val);
  1705. if (ret)
  1706. return ret;
  1707. return ov8856_write_reg(ov8856, OV8856_REG_FORMAT1,
  1708. OV8856_REG_VALUE_08BIT,
  1709. ctrl_val ? val | OV8856_REG_FORMAT1_OP_1 |
  1710. OV8856_REG_FORMAT1_OP_3 |
  1711. OV8856_REG_FORMAT1_OP_2 :
  1712. val & ~OV8856_REG_FORMAT1_OP_1 &
  1713. ~OV8856_REG_FORMAT1_OP_3 &
  1714. ~OV8856_REG_FORMAT1_OP_2);
  1715. }
  1716. static int ov8856_set_ctrl(struct v4l2_ctrl *ctrl)
  1717. {
  1718. struct ov8856 *ov8856 = container_of(ctrl->handler,
  1719. struct ov8856, ctrl_handler);
  1720. struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd);
  1721. s64 exposure_max;
  1722. int ret = 0;
  1723. /* Propagate change of current control to all related controls */
  1724. if (ctrl->id == V4L2_CID_VBLANK) {
  1725. /* Update max exposure while meeting expected vblanking */
  1726. exposure_max = ov8856->cur_mode->height + ctrl->val -
  1727. OV8856_EXPOSURE_MAX_MARGIN;
  1728. __v4l2_ctrl_modify_range(ov8856->exposure,
  1729. ov8856->exposure->minimum,
  1730. exposure_max, ov8856->exposure->step,
  1731. exposure_max);
  1732. }
  1733. /* V4L2 controls values will be applied only when power is already up */
  1734. if (!pm_runtime_get_if_in_use(&client->dev))
  1735. return 0;
  1736. switch (ctrl->id) {
  1737. case V4L2_CID_ANALOGUE_GAIN:
  1738. ret = ov8856_write_reg(ov8856, OV8856_REG_ANALOG_GAIN,
  1739. OV8856_REG_VALUE_16BIT, ctrl->val);
  1740. break;
  1741. case V4L2_CID_DIGITAL_GAIN:
  1742. ret = ov8856_update_digital_gain(ov8856, ctrl->val);
  1743. break;
  1744. case V4L2_CID_EXPOSURE:
  1745. /* 4 least significant bits of expsoure are fractional part */
  1746. ret = ov8856_write_reg(ov8856, OV8856_REG_EXPOSURE,
  1747. OV8856_REG_VALUE_24BIT, ctrl->val << 4);
  1748. break;
  1749. case V4L2_CID_VBLANK:
  1750. ret = ov8856_write_reg(ov8856, OV8856_REG_VTS,
  1751. OV8856_REG_VALUE_16BIT,
  1752. ov8856->cur_mode->height + ctrl->val);
  1753. break;
  1754. case V4L2_CID_TEST_PATTERN:
  1755. ret = ov8856_test_pattern(ov8856, ctrl->val);
  1756. break;
  1757. case V4L2_CID_HFLIP:
  1758. ret = ov8856_set_ctrl_hflip(ov8856, ctrl->val);
  1759. break;
  1760. case V4L2_CID_VFLIP:
  1761. ret = ov8856_set_ctrl_vflip(ov8856, ctrl->val);
  1762. break;
  1763. default:
  1764. ret = -EINVAL;
  1765. break;
  1766. }
  1767. pm_runtime_put(&client->dev);
  1768. return ret;
  1769. }
  1770. static const struct v4l2_ctrl_ops ov8856_ctrl_ops = {
  1771. .s_ctrl = ov8856_set_ctrl,
  1772. };
  1773. static int ov8856_init_controls(struct ov8856 *ov8856)
  1774. {
  1775. struct v4l2_ctrl_handler *ctrl_hdlr;
  1776. s64 exposure_max, h_blank;
  1777. int ret;
  1778. ctrl_hdlr = &ov8856->ctrl_handler;
  1779. ret = v4l2_ctrl_handler_init(ctrl_hdlr, 8);
  1780. if (ret)
  1781. return ret;
  1782. ctrl_hdlr->lock = &ov8856->mutex;
  1783. ov8856->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr, &ov8856_ctrl_ops,
  1784. V4L2_CID_LINK_FREQ,
  1785. ARRAY_SIZE
  1786. (ov8856->priv_lane->link_freq_menu_items)
  1787. - 1,
  1788. 0, ov8856->priv_lane->link_freq_menu_items);
  1789. if (ov8856->link_freq)
  1790. ov8856->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
  1791. ov8856->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops,
  1792. V4L2_CID_PIXEL_RATE, 0,
  1793. to_rate(ov8856->priv_lane->link_freq_menu_items,
  1794. 0,
  1795. ov8856->cur_mode->data_lanes), 1,
  1796. to_rate(ov8856->priv_lane->link_freq_menu_items,
  1797. 0,
  1798. ov8856->cur_mode->data_lanes));
  1799. ov8856->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops,
  1800. V4L2_CID_VBLANK,
  1801. ov8856->cur_mode->vts_min - ov8856->cur_mode->height,
  1802. OV8856_VTS_MAX - ov8856->cur_mode->height, 1,
  1803. ov8856->cur_mode->vts_def -
  1804. ov8856->cur_mode->height);
  1805. h_blank = to_pixels_per_line(ov8856->priv_lane->link_freq_menu_items,
  1806. ov8856->cur_mode->hts,
  1807. ov8856->cur_mode->link_freq_index,
  1808. ov8856->cur_mode->data_lanes) -
  1809. ov8856->cur_mode->width;
  1810. ov8856->hblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops,
  1811. V4L2_CID_HBLANK, h_blank, h_blank, 1,
  1812. h_blank);
  1813. if (ov8856->hblank)
  1814. ov8856->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
  1815. v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops, V4L2_CID_ANALOGUE_GAIN,
  1816. OV8856_ANAL_GAIN_MIN, OV8856_ANAL_GAIN_MAX,
  1817. OV8856_ANAL_GAIN_STEP, OV8856_ANAL_GAIN_MIN);
  1818. v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops, V4L2_CID_DIGITAL_GAIN,
  1819. OV8856_DGTL_GAIN_MIN, OV8856_DGTL_GAIN_MAX,
  1820. OV8856_DGTL_GAIN_STEP, OV8856_DGTL_GAIN_DEFAULT);
  1821. exposure_max = ov8856->cur_mode->vts_def - OV8856_EXPOSURE_MAX_MARGIN;
  1822. ov8856->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops,
  1823. V4L2_CID_EXPOSURE,
  1824. OV8856_EXPOSURE_MIN, exposure_max,
  1825. OV8856_EXPOSURE_STEP,
  1826. exposure_max);
  1827. v4l2_ctrl_new_std_menu_items(ctrl_hdlr, &ov8856_ctrl_ops,
  1828. V4L2_CID_TEST_PATTERN,
  1829. ARRAY_SIZE(ov8856_test_pattern_menu) - 1,
  1830. 0, 0, ov8856_test_pattern_menu);
  1831. v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops,
  1832. V4L2_CID_HFLIP, 0, 1, 1, 0);
  1833. v4l2_ctrl_new_std(ctrl_hdlr, &ov8856_ctrl_ops,
  1834. V4L2_CID_VFLIP, 0, 1, 1, 0);
  1835. if (ctrl_hdlr->error)
  1836. return ctrl_hdlr->error;
  1837. ov8856->sd.ctrl_handler = ctrl_hdlr;
  1838. return 0;
  1839. }
  1840. static void ov8856_update_pad_format(struct ov8856 *ov8856,
  1841. const struct ov8856_mode *mode,
  1842. struct v4l2_mbus_framefmt *fmt)
  1843. {
  1844. int index;
  1845. fmt->width = mode->width;
  1846. fmt->height = mode->height;
  1847. for (index = 0; index < ARRAY_SIZE(ov8856_mbus_codes); ++index)
  1848. if (ov8856_mbus_codes[index] == fmt->code)
  1849. break;
  1850. if (index == ARRAY_SIZE(ov8856_mbus_codes))
  1851. index = mode->default_mbus_index;
  1852. fmt->code = ov8856_mbus_codes[index];
  1853. ov8856->cur_mbus_index = index;
  1854. fmt->field = V4L2_FIELD_NONE;
  1855. }
  1856. static int ov8856_start_streaming(struct ov8856 *ov8856)
  1857. {
  1858. struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd);
  1859. const struct ov8856_reg_list *reg_list;
  1860. int link_freq_index, ret;
  1861. ret = ov8856_identify_module(ov8856);
  1862. if (ret)
  1863. return ret;
  1864. link_freq_index = ov8856->cur_mode->link_freq_index;
  1865. reg_list = &ov8856->priv_lane->link_freq_configs[link_freq_index].reg_list;
  1866. ret = ov8856_write_reg_list(ov8856, reg_list);
  1867. if (ret) {
  1868. dev_err(&client->dev, "failed to set plls");
  1869. return ret;
  1870. }
  1871. reg_list = &ov8856->cur_mode->reg_list;
  1872. ret = ov8856_write_reg_list(ov8856, reg_list);
  1873. if (ret) {
  1874. dev_err(&client->dev, "failed to set mode");
  1875. return ret;
  1876. }
  1877. reg_list = &bayer_offset_configs[ov8856->cur_mbus_index];
  1878. ret = ov8856_write_reg_list(ov8856, reg_list);
  1879. if (ret) {
  1880. dev_err(&client->dev, "failed to set mbus format");
  1881. return ret;
  1882. }
  1883. ret = __v4l2_ctrl_handler_setup(ov8856->sd.ctrl_handler);
  1884. if (ret)
  1885. return ret;
  1886. ret = ov8856_write_reg(ov8856, OV8856_REG_MODE_SELECT,
  1887. OV8856_REG_VALUE_08BIT, OV8856_MODE_STREAMING);
  1888. if (ret) {
  1889. dev_err(&client->dev, "failed to set stream");
  1890. return ret;
  1891. }
  1892. return 0;
  1893. }
  1894. static void ov8856_stop_streaming(struct ov8856 *ov8856)
  1895. {
  1896. struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd);
  1897. if (ov8856_write_reg(ov8856, OV8856_REG_MODE_SELECT,
  1898. OV8856_REG_VALUE_08BIT, OV8856_MODE_STANDBY))
  1899. dev_err(&client->dev, "failed to set stream");
  1900. }
  1901. static int ov8856_set_stream(struct v4l2_subdev *sd, int enable)
  1902. {
  1903. struct ov8856 *ov8856 = to_ov8856(sd);
  1904. struct i2c_client *client = v4l2_get_subdevdata(sd);
  1905. int ret = 0;
  1906. if (ov8856->streaming == enable)
  1907. return 0;
  1908. mutex_lock(&ov8856->mutex);
  1909. if (enable) {
  1910. ret = pm_runtime_resume_and_get(&client->dev);
  1911. if (ret < 0) {
  1912. mutex_unlock(&ov8856->mutex);
  1913. return ret;
  1914. }
  1915. ret = ov8856_start_streaming(ov8856);
  1916. if (ret) {
  1917. enable = 0;
  1918. ov8856_stop_streaming(ov8856);
  1919. pm_runtime_put(&client->dev);
  1920. }
  1921. } else {
  1922. ov8856_stop_streaming(ov8856);
  1923. pm_runtime_put(&client->dev);
  1924. }
  1925. ov8856->streaming = enable;
  1926. mutex_unlock(&ov8856->mutex);
  1927. return ret;
  1928. }
  1929. static int __ov8856_power_on(struct ov8856 *ov8856)
  1930. {
  1931. struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd);
  1932. int ret;
  1933. if (is_acpi_node(dev_fwnode(&client->dev)))
  1934. return 0;
  1935. ret = clk_prepare_enable(ov8856->xvclk);
  1936. if (ret < 0) {
  1937. dev_err(&client->dev, "failed to enable xvclk\n");
  1938. return ret;
  1939. }
  1940. if (ov8856->reset_gpio) {
  1941. gpiod_set_value_cansleep(ov8856->reset_gpio, 1);
  1942. usleep_range(1000, 2000);
  1943. }
  1944. ret = regulator_bulk_enable(ARRAY_SIZE(ov8856_supply_names),
  1945. ov8856->supplies);
  1946. if (ret < 0) {
  1947. dev_err(&client->dev, "failed to enable regulators\n");
  1948. goto disable_clk;
  1949. }
  1950. gpiod_set_value_cansleep(ov8856->reset_gpio, 0);
  1951. usleep_range(1500, 1800);
  1952. return 0;
  1953. disable_clk:
  1954. gpiod_set_value_cansleep(ov8856->reset_gpio, 1);
  1955. clk_disable_unprepare(ov8856->xvclk);
  1956. return ret;
  1957. }
  1958. static void __ov8856_power_off(struct ov8856 *ov8856)
  1959. {
  1960. struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd);
  1961. if (is_acpi_node(dev_fwnode(&client->dev)))
  1962. return;
  1963. gpiod_set_value_cansleep(ov8856->reset_gpio, 1);
  1964. regulator_bulk_disable(ARRAY_SIZE(ov8856_supply_names),
  1965. ov8856->supplies);
  1966. clk_disable_unprepare(ov8856->xvclk);
  1967. }
  1968. static int __maybe_unused ov8856_suspend(struct device *dev)
  1969. {
  1970. struct v4l2_subdev *sd = dev_get_drvdata(dev);
  1971. struct ov8856 *ov8856 = to_ov8856(sd);
  1972. mutex_lock(&ov8856->mutex);
  1973. if (ov8856->streaming)
  1974. ov8856_stop_streaming(ov8856);
  1975. __ov8856_power_off(ov8856);
  1976. mutex_unlock(&ov8856->mutex);
  1977. return 0;
  1978. }
  1979. static int __maybe_unused ov8856_resume(struct device *dev)
  1980. {
  1981. struct v4l2_subdev *sd = dev_get_drvdata(dev);
  1982. struct ov8856 *ov8856 = to_ov8856(sd);
  1983. int ret;
  1984. mutex_lock(&ov8856->mutex);
  1985. __ov8856_power_on(ov8856);
  1986. if (ov8856->streaming) {
  1987. ret = ov8856_start_streaming(ov8856);
  1988. if (ret) {
  1989. ov8856->streaming = false;
  1990. ov8856_stop_streaming(ov8856);
  1991. mutex_unlock(&ov8856->mutex);
  1992. return ret;
  1993. }
  1994. }
  1995. mutex_unlock(&ov8856->mutex);
  1996. return 0;
  1997. }
  1998. static int ov8856_set_format(struct v4l2_subdev *sd,
  1999. struct v4l2_subdev_state *sd_state,
  2000. struct v4l2_subdev_format *fmt)
  2001. {
  2002. struct ov8856 *ov8856 = to_ov8856(sd);
  2003. const struct ov8856_mode *mode;
  2004. s32 vblank_def, h_blank;
  2005. mode = v4l2_find_nearest_size(ov8856->priv_lane->supported_modes,
  2006. ov8856->modes_size,
  2007. width, height, fmt->format.width,
  2008. fmt->format.height);
  2009. mutex_lock(&ov8856->mutex);
  2010. ov8856_update_pad_format(ov8856, mode, &fmt->format);
  2011. if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
  2012. *v4l2_subdev_get_try_format(sd, sd_state, fmt->pad) = fmt->format;
  2013. } else {
  2014. ov8856->cur_mode = mode;
  2015. __v4l2_ctrl_s_ctrl(ov8856->link_freq, mode->link_freq_index);
  2016. __v4l2_ctrl_s_ctrl_int64(ov8856->pixel_rate,
  2017. to_rate(ov8856->priv_lane->link_freq_menu_items,
  2018. mode->link_freq_index,
  2019. ov8856->cur_mode->data_lanes));
  2020. /* Update limits and set FPS to default */
  2021. vblank_def = mode->vts_def - mode->height;
  2022. __v4l2_ctrl_modify_range(ov8856->vblank,
  2023. mode->vts_min - mode->height,
  2024. OV8856_VTS_MAX - mode->height, 1,
  2025. vblank_def);
  2026. __v4l2_ctrl_s_ctrl(ov8856->vblank, vblank_def);
  2027. h_blank = to_pixels_per_line(ov8856->priv_lane->link_freq_menu_items,
  2028. mode->hts,
  2029. mode->link_freq_index,
  2030. ov8856->cur_mode->data_lanes)
  2031. - mode->width;
  2032. __v4l2_ctrl_modify_range(ov8856->hblank, h_blank, h_blank, 1,
  2033. h_blank);
  2034. }
  2035. mutex_unlock(&ov8856->mutex);
  2036. return 0;
  2037. }
  2038. static int ov8856_get_format(struct v4l2_subdev *sd,
  2039. struct v4l2_subdev_state *sd_state,
  2040. struct v4l2_subdev_format *fmt)
  2041. {
  2042. struct ov8856 *ov8856 = to_ov8856(sd);
  2043. mutex_lock(&ov8856->mutex);
  2044. if (fmt->which == V4L2_SUBDEV_FORMAT_TRY)
  2045. fmt->format = *v4l2_subdev_get_try_format(&ov8856->sd,
  2046. sd_state,
  2047. fmt->pad);
  2048. else
  2049. ov8856_update_pad_format(ov8856, ov8856->cur_mode, &fmt->format);
  2050. mutex_unlock(&ov8856->mutex);
  2051. return 0;
  2052. }
  2053. static int ov8856_enum_mbus_code(struct v4l2_subdev *sd,
  2054. struct v4l2_subdev_state *sd_state,
  2055. struct v4l2_subdev_mbus_code_enum *code)
  2056. {
  2057. if (code->index >= ARRAY_SIZE(ov8856_mbus_codes))
  2058. return -EINVAL;
  2059. code->code = ov8856_mbus_codes[code->index];
  2060. return 0;
  2061. }
  2062. static int ov8856_enum_frame_size(struct v4l2_subdev *sd,
  2063. struct v4l2_subdev_state *sd_state,
  2064. struct v4l2_subdev_frame_size_enum *fse)
  2065. {
  2066. struct ov8856 *ov8856 = to_ov8856(sd);
  2067. int index;
  2068. if (fse->index >= ov8856->modes_size)
  2069. return -EINVAL;
  2070. for (index = 0; index < ARRAY_SIZE(ov8856_mbus_codes); ++index)
  2071. if (fse->code == ov8856_mbus_codes[index])
  2072. break;
  2073. if (index == ARRAY_SIZE(ov8856_mbus_codes))
  2074. return -EINVAL;
  2075. fse->min_width = ov8856->priv_lane->supported_modes[fse->index].width;
  2076. fse->max_width = fse->min_width;
  2077. fse->min_height = ov8856->priv_lane->supported_modes[fse->index].height;
  2078. fse->max_height = fse->min_height;
  2079. return 0;
  2080. }
  2081. static int ov8856_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
  2082. {
  2083. struct ov8856 *ov8856 = to_ov8856(sd);
  2084. mutex_lock(&ov8856->mutex);
  2085. ov8856_update_pad_format(ov8856, &ov8856->priv_lane->supported_modes[0],
  2086. v4l2_subdev_get_try_format(sd, fh->state, 0));
  2087. mutex_unlock(&ov8856->mutex);
  2088. return 0;
  2089. }
  2090. static const struct v4l2_subdev_video_ops ov8856_video_ops = {
  2091. .s_stream = ov8856_set_stream,
  2092. };
  2093. static const struct v4l2_subdev_pad_ops ov8856_pad_ops = {
  2094. .set_fmt = ov8856_set_format,
  2095. .get_fmt = ov8856_get_format,
  2096. .enum_mbus_code = ov8856_enum_mbus_code,
  2097. .enum_frame_size = ov8856_enum_frame_size,
  2098. };
  2099. static const struct v4l2_subdev_ops ov8856_subdev_ops = {
  2100. .video = &ov8856_video_ops,
  2101. .pad = &ov8856_pad_ops,
  2102. };
  2103. static const struct media_entity_operations ov8856_subdev_entity_ops = {
  2104. .link_validate = v4l2_subdev_link_validate,
  2105. };
  2106. static const struct v4l2_subdev_internal_ops ov8856_internal_ops = {
  2107. .open = ov8856_open,
  2108. };
  2109. static int ov8856_get_hwcfg(struct ov8856 *ov8856, struct device *dev)
  2110. {
  2111. struct fwnode_handle *ep;
  2112. struct fwnode_handle *fwnode = dev_fwnode(dev);
  2113. struct v4l2_fwnode_endpoint bus_cfg = {
  2114. .bus_type = V4L2_MBUS_CSI2_DPHY
  2115. };
  2116. u32 xvclk_rate;
  2117. int ret;
  2118. unsigned int i, j;
  2119. if (!fwnode)
  2120. return -ENXIO;
  2121. ret = fwnode_property_read_u32(fwnode, "clock-frequency", &xvclk_rate);
  2122. if (ret)
  2123. return ret;
  2124. if (!is_acpi_node(fwnode)) {
  2125. ov8856->xvclk = devm_clk_get(dev, "xvclk");
  2126. if (IS_ERR(ov8856->xvclk)) {
  2127. dev_err(dev, "could not get xvclk clock (%pe)\n",
  2128. ov8856->xvclk);
  2129. return PTR_ERR(ov8856->xvclk);
  2130. }
  2131. clk_set_rate(ov8856->xvclk, xvclk_rate);
  2132. xvclk_rate = clk_get_rate(ov8856->xvclk);
  2133. ov8856->reset_gpio = devm_gpiod_get_optional(dev, "reset",
  2134. GPIOD_OUT_LOW);
  2135. if (IS_ERR(ov8856->reset_gpio))
  2136. return PTR_ERR(ov8856->reset_gpio);
  2137. for (i = 0; i < ARRAY_SIZE(ov8856_supply_names); i++)
  2138. ov8856->supplies[i].supply = ov8856_supply_names[i];
  2139. ret = devm_regulator_bulk_get(dev,
  2140. ARRAY_SIZE(ov8856_supply_names),
  2141. ov8856->supplies);
  2142. if (ret)
  2143. return ret;
  2144. }
  2145. if (xvclk_rate != OV8856_XVCLK_19_2)
  2146. dev_warn(dev, "external clock rate %u is unsupported",
  2147. xvclk_rate);
  2148. ep = fwnode_graph_get_next_endpoint(fwnode, NULL);
  2149. if (!ep)
  2150. return -ENXIO;
  2151. ret = v4l2_fwnode_endpoint_alloc_parse(ep, &bus_cfg);
  2152. fwnode_handle_put(ep);
  2153. if (ret)
  2154. return ret;
  2155. /* Get number of data lanes */
  2156. if (bus_cfg.bus.mipi_csi2.num_data_lanes != 2 &&
  2157. bus_cfg.bus.mipi_csi2.num_data_lanes != 4) {
  2158. dev_err(dev, "number of CSI2 data lanes %d is not supported",
  2159. bus_cfg.bus.mipi_csi2.num_data_lanes);
  2160. ret = -EINVAL;
  2161. goto check_hwcfg_error;
  2162. }
  2163. dev_dbg(dev, "Using %u data lanes\n", ov8856->cur_mode->data_lanes);
  2164. if (bus_cfg.bus.mipi_csi2.num_data_lanes == 2)
  2165. ov8856->priv_lane = &lane_cfg_2;
  2166. else
  2167. ov8856->priv_lane = &lane_cfg_4;
  2168. ov8856->modes_size = ov8856_modes_num(ov8856);
  2169. if (!bus_cfg.nr_of_link_frequencies) {
  2170. dev_err(dev, "no link frequencies defined");
  2171. ret = -EINVAL;
  2172. goto check_hwcfg_error;
  2173. }
  2174. for (i = 0; i < ARRAY_SIZE(ov8856->priv_lane->link_freq_menu_items); i++) {
  2175. for (j = 0; j < bus_cfg.nr_of_link_frequencies; j++) {
  2176. if (ov8856->priv_lane->link_freq_menu_items[i] ==
  2177. bus_cfg.link_frequencies[j])
  2178. break;
  2179. }
  2180. if (j == bus_cfg.nr_of_link_frequencies) {
  2181. dev_err(dev, "no link frequency %lld supported",
  2182. ov8856->priv_lane->link_freq_menu_items[i]);
  2183. ret = -EINVAL;
  2184. goto check_hwcfg_error;
  2185. }
  2186. }
  2187. check_hwcfg_error:
  2188. v4l2_fwnode_endpoint_free(&bus_cfg);
  2189. return ret;
  2190. }
  2191. static void ov8856_remove(struct i2c_client *client)
  2192. {
  2193. struct v4l2_subdev *sd = i2c_get_clientdata(client);
  2194. struct ov8856 *ov8856 = to_ov8856(sd);
  2195. v4l2_async_unregister_subdev(sd);
  2196. media_entity_cleanup(&sd->entity);
  2197. v4l2_ctrl_handler_free(sd->ctrl_handler);
  2198. pm_runtime_disable(&client->dev);
  2199. mutex_destroy(&ov8856->mutex);
  2200. __ov8856_power_off(ov8856);
  2201. }
  2202. static int ov8856_probe(struct i2c_client *client)
  2203. {
  2204. struct ov8856 *ov8856;
  2205. int ret;
  2206. bool full_power;
  2207. ov8856 = devm_kzalloc(&client->dev, sizeof(*ov8856), GFP_KERNEL);
  2208. if (!ov8856)
  2209. return -ENOMEM;
  2210. ret = ov8856_get_hwcfg(ov8856, &client->dev);
  2211. if (ret) {
  2212. dev_err(&client->dev, "failed to get HW configuration: %d",
  2213. ret);
  2214. return ret;
  2215. }
  2216. v4l2_i2c_subdev_init(&ov8856->sd, client, &ov8856_subdev_ops);
  2217. full_power = acpi_dev_state_d0(&client->dev);
  2218. if (full_power) {
  2219. ret = __ov8856_power_on(ov8856);
  2220. if (ret) {
  2221. dev_err(&client->dev, "failed to power on\n");
  2222. return ret;
  2223. }
  2224. ret = ov8856_identify_module(ov8856);
  2225. if (ret) {
  2226. dev_err(&client->dev, "failed to find sensor: %d", ret);
  2227. goto probe_power_off;
  2228. }
  2229. }
  2230. mutex_init(&ov8856->mutex);
  2231. ov8856->cur_mode = &ov8856->priv_lane->supported_modes[0];
  2232. ov8856->cur_mbus_index = ov8856->cur_mode->default_mbus_index;
  2233. ret = ov8856_init_controls(ov8856);
  2234. if (ret) {
  2235. dev_err(&client->dev, "failed to init controls: %d", ret);
  2236. goto probe_error_v4l2_ctrl_handler_free;
  2237. }
  2238. ov8856->sd.internal_ops = &ov8856_internal_ops;
  2239. ov8856->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
  2240. ov8856->sd.entity.ops = &ov8856_subdev_entity_ops;
  2241. ov8856->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
  2242. ov8856->pad.flags = MEDIA_PAD_FL_SOURCE;
  2243. ret = media_entity_pads_init(&ov8856->sd.entity, 1, &ov8856->pad);
  2244. if (ret) {
  2245. dev_err(&client->dev, "failed to init entity pads: %d", ret);
  2246. goto probe_error_v4l2_ctrl_handler_free;
  2247. }
  2248. ret = v4l2_async_register_subdev_sensor(&ov8856->sd);
  2249. if (ret < 0) {
  2250. dev_err(&client->dev, "failed to register V4L2 subdev: %d",
  2251. ret);
  2252. goto probe_error_media_entity_cleanup;
  2253. }
  2254. /* Set the device's state to active if it's in D0 state. */
  2255. if (full_power)
  2256. pm_runtime_set_active(&client->dev);
  2257. pm_runtime_enable(&client->dev);
  2258. pm_runtime_idle(&client->dev);
  2259. return 0;
  2260. probe_error_media_entity_cleanup:
  2261. media_entity_cleanup(&ov8856->sd.entity);
  2262. probe_error_v4l2_ctrl_handler_free:
  2263. v4l2_ctrl_handler_free(ov8856->sd.ctrl_handler);
  2264. mutex_destroy(&ov8856->mutex);
  2265. probe_power_off:
  2266. __ov8856_power_off(ov8856);
  2267. return ret;
  2268. }
  2269. static const struct dev_pm_ops ov8856_pm_ops = {
  2270. SET_SYSTEM_SLEEP_PM_OPS(ov8856_suspend, ov8856_resume)
  2271. };
  2272. #ifdef CONFIG_ACPI
  2273. static const struct acpi_device_id ov8856_acpi_ids[] = {
  2274. {"OVTI8856"},
  2275. {}
  2276. };
  2277. MODULE_DEVICE_TABLE(acpi, ov8856_acpi_ids);
  2278. #endif
  2279. static const struct of_device_id ov8856_of_match[] = {
  2280. { .compatible = "ovti,ov8856" },
  2281. { /* sentinel */ }
  2282. };
  2283. MODULE_DEVICE_TABLE(of, ov8856_of_match);
  2284. static struct i2c_driver ov8856_i2c_driver = {
  2285. .driver = {
  2286. .name = "ov8856",
  2287. .pm = &ov8856_pm_ops,
  2288. .acpi_match_table = ACPI_PTR(ov8856_acpi_ids),
  2289. .of_match_table = ov8856_of_match,
  2290. },
  2291. .probe_new = ov8856_probe,
  2292. .remove = ov8856_remove,
  2293. .flags = I2C_DRV_ACPI_WAIVE_D0_PROBE,
  2294. };
  2295. module_i2c_driver(ov8856_i2c_driver);
  2296. MODULE_AUTHOR("Ben Kao <[email protected]>");
  2297. MODULE_DESCRIPTION("OmniVision OV8856 sensor driver");
  2298. MODULE_LICENSE("GPL v2");