ov13858.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815
  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 OV13858_REG_VALUE_08BIT 1
  10. #define OV13858_REG_VALUE_16BIT 2
  11. #define OV13858_REG_VALUE_24BIT 3
  12. #define OV13858_REG_MODE_SELECT 0x0100
  13. #define OV13858_MODE_STANDBY 0x00
  14. #define OV13858_MODE_STREAMING 0x01
  15. #define OV13858_REG_SOFTWARE_RST 0x0103
  16. #define OV13858_SOFTWARE_RST 0x01
  17. /* PLL1 generates PCLK and MIPI_PHY_CLK */
  18. #define OV13858_REG_PLL1_CTRL_0 0x0300
  19. #define OV13858_REG_PLL1_CTRL_1 0x0301
  20. #define OV13858_REG_PLL1_CTRL_2 0x0302
  21. #define OV13858_REG_PLL1_CTRL_3 0x0303
  22. #define OV13858_REG_PLL1_CTRL_4 0x0304
  23. #define OV13858_REG_PLL1_CTRL_5 0x0305
  24. /* PLL2 generates DAC_CLK, SCLK and SRAM_CLK */
  25. #define OV13858_REG_PLL2_CTRL_B 0x030b
  26. #define OV13858_REG_PLL2_CTRL_C 0x030c
  27. #define OV13858_REG_PLL2_CTRL_D 0x030d
  28. #define OV13858_REG_PLL2_CTRL_E 0x030e
  29. #define OV13858_REG_PLL2_CTRL_F 0x030f
  30. #define OV13858_REG_PLL2_CTRL_12 0x0312
  31. #define OV13858_REG_MIPI_SC_CTRL0 0x3016
  32. #define OV13858_REG_MIPI_SC_CTRL1 0x3022
  33. /* Chip ID */
  34. #define OV13858_REG_CHIP_ID 0x300a
  35. #define OV13858_CHIP_ID 0x00d855
  36. /* V_TIMING internal */
  37. #define OV13858_REG_VTS 0x380e
  38. #define OV13858_VTS_30FPS 0x0c8e /* 30 fps */
  39. #define OV13858_VTS_60FPS 0x0648 /* 60 fps */
  40. #define OV13858_VTS_MAX 0x7fff
  41. /* HBLANK control - read only */
  42. #define OV13858_PPL_270MHZ 2244
  43. #define OV13858_PPL_540MHZ 4488
  44. /* Exposure control */
  45. #define OV13858_REG_EXPOSURE 0x3500
  46. #define OV13858_EXPOSURE_MIN 4
  47. #define OV13858_EXPOSURE_STEP 1
  48. #define OV13858_EXPOSURE_DEFAULT 0x640
  49. /* Analog gain control */
  50. #define OV13858_REG_ANALOG_GAIN 0x3508
  51. #define OV13858_ANA_GAIN_MIN 0
  52. #define OV13858_ANA_GAIN_MAX 0x1fff
  53. #define OV13858_ANA_GAIN_STEP 1
  54. #define OV13858_ANA_GAIN_DEFAULT 0x80
  55. /* Digital gain control */
  56. #define OV13858_REG_B_MWB_GAIN 0x5100
  57. #define OV13858_REG_G_MWB_GAIN 0x5102
  58. #define OV13858_REG_R_MWB_GAIN 0x5104
  59. #define OV13858_DGTL_GAIN_MIN 0
  60. #define OV13858_DGTL_GAIN_MAX 16384 /* Max = 16 X */
  61. #define OV13858_DGTL_GAIN_DEFAULT 1024 /* Default gain = 1 X */
  62. #define OV13858_DGTL_GAIN_STEP 1 /* Each step = 1/1024 */
  63. /* Test Pattern Control */
  64. #define OV13858_REG_TEST_PATTERN 0x4503
  65. #define OV13858_TEST_PATTERN_ENABLE BIT(7)
  66. #define OV13858_TEST_PATTERN_MASK 0xfc
  67. /* Number of frames to skip */
  68. #define OV13858_NUM_OF_SKIP_FRAMES 2
  69. struct ov13858_reg {
  70. u16 address;
  71. u8 val;
  72. };
  73. struct ov13858_reg_list {
  74. u32 num_of_regs;
  75. const struct ov13858_reg *regs;
  76. };
  77. /* Link frequency config */
  78. struct ov13858_link_freq_config {
  79. u32 pixels_per_line;
  80. /* PLL registers for this link frequency */
  81. struct ov13858_reg_list reg_list;
  82. };
  83. /* Mode : resolution and related config&values */
  84. struct ov13858_mode {
  85. /* Frame width */
  86. u32 width;
  87. /* Frame height */
  88. u32 height;
  89. /* V-timing */
  90. u32 vts_def;
  91. u32 vts_min;
  92. /* Index of Link frequency config to be used */
  93. u32 link_freq_index;
  94. /* Default register values */
  95. struct ov13858_reg_list reg_list;
  96. };
  97. /* 4224x3136 needs 1080Mbps/lane, 4 lanes */
  98. static const struct ov13858_reg mipi_data_rate_1080mbps[] = {
  99. /* PLL1 registers */
  100. {OV13858_REG_PLL1_CTRL_0, 0x07},
  101. {OV13858_REG_PLL1_CTRL_1, 0x01},
  102. {OV13858_REG_PLL1_CTRL_2, 0xc2},
  103. {OV13858_REG_PLL1_CTRL_3, 0x00},
  104. {OV13858_REG_PLL1_CTRL_4, 0x00},
  105. {OV13858_REG_PLL1_CTRL_5, 0x01},
  106. /* PLL2 registers */
  107. {OV13858_REG_PLL2_CTRL_B, 0x05},
  108. {OV13858_REG_PLL2_CTRL_C, 0x01},
  109. {OV13858_REG_PLL2_CTRL_D, 0x0e},
  110. {OV13858_REG_PLL2_CTRL_E, 0x05},
  111. {OV13858_REG_PLL2_CTRL_F, 0x01},
  112. {OV13858_REG_PLL2_CTRL_12, 0x01},
  113. {OV13858_REG_MIPI_SC_CTRL0, 0x72},
  114. {OV13858_REG_MIPI_SC_CTRL1, 0x01},
  115. };
  116. /*
  117. * 2112x1568, 2112x1188, 1056x784 need 540Mbps/lane,
  118. * 4 lanes
  119. */
  120. static const struct ov13858_reg mipi_data_rate_540mbps[] = {
  121. /* PLL1 registers */
  122. {OV13858_REG_PLL1_CTRL_0, 0x07},
  123. {OV13858_REG_PLL1_CTRL_1, 0x01},
  124. {OV13858_REG_PLL1_CTRL_2, 0xc2},
  125. {OV13858_REG_PLL1_CTRL_3, 0x01},
  126. {OV13858_REG_PLL1_CTRL_4, 0x00},
  127. {OV13858_REG_PLL1_CTRL_5, 0x01},
  128. /* PLL2 registers */
  129. {OV13858_REG_PLL2_CTRL_B, 0x05},
  130. {OV13858_REG_PLL2_CTRL_C, 0x01},
  131. {OV13858_REG_PLL2_CTRL_D, 0x0e},
  132. {OV13858_REG_PLL2_CTRL_E, 0x05},
  133. {OV13858_REG_PLL2_CTRL_F, 0x01},
  134. {OV13858_REG_PLL2_CTRL_12, 0x01},
  135. {OV13858_REG_MIPI_SC_CTRL0, 0x72},
  136. {OV13858_REG_MIPI_SC_CTRL1, 0x01},
  137. };
  138. static const struct ov13858_reg mode_4224x3136_regs[] = {
  139. {0x3013, 0x32},
  140. {0x301b, 0xf0},
  141. {0x301f, 0xd0},
  142. {0x3106, 0x15},
  143. {0x3107, 0x23},
  144. {0x350a, 0x00},
  145. {0x350e, 0x00},
  146. {0x3510, 0x00},
  147. {0x3511, 0x02},
  148. {0x3512, 0x00},
  149. {0x3600, 0x2b},
  150. {0x3601, 0x52},
  151. {0x3602, 0x60},
  152. {0x3612, 0x05},
  153. {0x3613, 0xa4},
  154. {0x3620, 0x80},
  155. {0x3621, 0x10},
  156. {0x3622, 0x30},
  157. {0x3624, 0x1c},
  158. {0x3640, 0x10},
  159. {0x3641, 0x70},
  160. {0x3660, 0x04},
  161. {0x3661, 0x80},
  162. {0x3662, 0x12},
  163. {0x3664, 0x73},
  164. {0x3665, 0xa7},
  165. {0x366e, 0xff},
  166. {0x366f, 0xf4},
  167. {0x3674, 0x00},
  168. {0x3679, 0x0c},
  169. {0x367f, 0x01},
  170. {0x3680, 0x0c},
  171. {0x3681, 0x50},
  172. {0x3682, 0x50},
  173. {0x3683, 0xa9},
  174. {0x3684, 0xa9},
  175. {0x3709, 0x5f},
  176. {0x3714, 0x24},
  177. {0x371a, 0x3e},
  178. {0x3737, 0x04},
  179. {0x3738, 0xcc},
  180. {0x3739, 0x12},
  181. {0x373d, 0x26},
  182. {0x3764, 0x20},
  183. {0x3765, 0x20},
  184. {0x37a1, 0x36},
  185. {0x37a8, 0x3b},
  186. {0x37ab, 0x31},
  187. {0x37c2, 0x04},
  188. {0x37c3, 0xf1},
  189. {0x37c5, 0x00},
  190. {0x37d8, 0x03},
  191. {0x37d9, 0x0c},
  192. {0x37da, 0xc2},
  193. {0x37dc, 0x02},
  194. {0x37e0, 0x00},
  195. {0x37e1, 0x0a},
  196. {0x37e2, 0x14},
  197. {0x37e3, 0x04},
  198. {0x37e4, 0x2a},
  199. {0x37e5, 0x03},
  200. {0x37e6, 0x04},
  201. {0x3800, 0x00},
  202. {0x3801, 0x00},
  203. {0x3802, 0x00},
  204. {0x3803, 0x08},
  205. {0x3804, 0x10},
  206. {0x3805, 0x9f},
  207. {0x3806, 0x0c},
  208. {0x3807, 0x57},
  209. {0x3808, 0x10},
  210. {0x3809, 0x80},
  211. {0x380a, 0x0c},
  212. {0x380b, 0x40},
  213. {0x380c, 0x04},
  214. {0x380d, 0x62},
  215. {0x380e, 0x0c},
  216. {0x380f, 0x8e},
  217. {0x3811, 0x04},
  218. {0x3813, 0x05},
  219. {0x3814, 0x01},
  220. {0x3815, 0x01},
  221. {0x3816, 0x01},
  222. {0x3817, 0x01},
  223. {0x3820, 0xa8},
  224. {0x3821, 0x00},
  225. {0x3822, 0xc2},
  226. {0x3823, 0x18},
  227. {0x3826, 0x11},
  228. {0x3827, 0x1c},
  229. {0x3829, 0x03},
  230. {0x3832, 0x00},
  231. {0x3c80, 0x00},
  232. {0x3c87, 0x01},
  233. {0x3c8c, 0x19},
  234. {0x3c8d, 0x1c},
  235. {0x3c90, 0x00},
  236. {0x3c91, 0x00},
  237. {0x3c92, 0x00},
  238. {0x3c93, 0x00},
  239. {0x3c94, 0x40},
  240. {0x3c95, 0x54},
  241. {0x3c96, 0x34},
  242. {0x3c97, 0x04},
  243. {0x3c98, 0x00},
  244. {0x3d8c, 0x73},
  245. {0x3d8d, 0xc0},
  246. {0x3f00, 0x0b},
  247. {0x3f03, 0x00},
  248. {0x4001, 0xe0},
  249. {0x4008, 0x00},
  250. {0x4009, 0x0f},
  251. {0x4011, 0xf0},
  252. {0x4017, 0x08},
  253. {0x4050, 0x04},
  254. {0x4051, 0x0b},
  255. {0x4052, 0x00},
  256. {0x4053, 0x80},
  257. {0x4054, 0x00},
  258. {0x4055, 0x80},
  259. {0x4056, 0x00},
  260. {0x4057, 0x80},
  261. {0x4058, 0x00},
  262. {0x4059, 0x80},
  263. {0x405e, 0x20},
  264. {0x4500, 0x07},
  265. {0x4503, 0x00},
  266. {0x450a, 0x04},
  267. {0x4809, 0x04},
  268. {0x480c, 0x12},
  269. {0x481f, 0x30},
  270. {0x4833, 0x10},
  271. {0x4837, 0x0e},
  272. {0x4902, 0x01},
  273. {0x4d00, 0x03},
  274. {0x4d01, 0xc9},
  275. {0x4d02, 0xbc},
  276. {0x4d03, 0xd7},
  277. {0x4d04, 0xf0},
  278. {0x4d05, 0xa2},
  279. {0x5000, 0xfd},
  280. {0x5001, 0x01},
  281. {0x5040, 0x39},
  282. {0x5041, 0x10},
  283. {0x5042, 0x10},
  284. {0x5043, 0x84},
  285. {0x5044, 0x62},
  286. {0x5180, 0x00},
  287. {0x5181, 0x10},
  288. {0x5182, 0x02},
  289. {0x5183, 0x0f},
  290. {0x5200, 0x1b},
  291. {0x520b, 0x07},
  292. {0x520c, 0x0f},
  293. {0x5300, 0x04},
  294. {0x5301, 0x0c},
  295. {0x5302, 0x0c},
  296. {0x5303, 0x0f},
  297. {0x5304, 0x00},
  298. {0x5305, 0x70},
  299. {0x5306, 0x00},
  300. {0x5307, 0x80},
  301. {0x5308, 0x00},
  302. {0x5309, 0xa5},
  303. {0x530a, 0x00},
  304. {0x530b, 0xd3},
  305. {0x530c, 0x00},
  306. {0x530d, 0xf0},
  307. {0x530e, 0x01},
  308. {0x530f, 0x10},
  309. {0x5310, 0x01},
  310. {0x5311, 0x20},
  311. {0x5312, 0x01},
  312. {0x5313, 0x20},
  313. {0x5314, 0x01},
  314. {0x5315, 0x20},
  315. {0x5316, 0x08},
  316. {0x5317, 0x08},
  317. {0x5318, 0x10},
  318. {0x5319, 0x88},
  319. {0x531a, 0x88},
  320. {0x531b, 0xa9},
  321. {0x531c, 0xaa},
  322. {0x531d, 0x0a},
  323. {0x5405, 0x02},
  324. {0x5406, 0x67},
  325. {0x5407, 0x01},
  326. {0x5408, 0x4a},
  327. };
  328. static const struct ov13858_reg mode_2112x1568_regs[] = {
  329. {0x3013, 0x32},
  330. {0x301b, 0xf0},
  331. {0x301f, 0xd0},
  332. {0x3106, 0x15},
  333. {0x3107, 0x23},
  334. {0x350a, 0x00},
  335. {0x350e, 0x00},
  336. {0x3510, 0x00},
  337. {0x3511, 0x02},
  338. {0x3512, 0x00},
  339. {0x3600, 0x2b},
  340. {0x3601, 0x52},
  341. {0x3602, 0x60},
  342. {0x3612, 0x05},
  343. {0x3613, 0xa4},
  344. {0x3620, 0x80},
  345. {0x3621, 0x10},
  346. {0x3622, 0x30},
  347. {0x3624, 0x1c},
  348. {0x3640, 0x10},
  349. {0x3641, 0x70},
  350. {0x3660, 0x04},
  351. {0x3661, 0x80},
  352. {0x3662, 0x10},
  353. {0x3664, 0x73},
  354. {0x3665, 0xa7},
  355. {0x366e, 0xff},
  356. {0x366f, 0xf4},
  357. {0x3674, 0x00},
  358. {0x3679, 0x0c},
  359. {0x367f, 0x01},
  360. {0x3680, 0x0c},
  361. {0x3681, 0x50},
  362. {0x3682, 0x50},
  363. {0x3683, 0xa9},
  364. {0x3684, 0xa9},
  365. {0x3709, 0x5f},
  366. {0x3714, 0x28},
  367. {0x371a, 0x3e},
  368. {0x3737, 0x08},
  369. {0x3738, 0xcc},
  370. {0x3739, 0x20},
  371. {0x373d, 0x26},
  372. {0x3764, 0x20},
  373. {0x3765, 0x20},
  374. {0x37a1, 0x36},
  375. {0x37a8, 0x3b},
  376. {0x37ab, 0x31},
  377. {0x37c2, 0x14},
  378. {0x37c3, 0xf1},
  379. {0x37c5, 0x00},
  380. {0x37d8, 0x03},
  381. {0x37d9, 0x0c},
  382. {0x37da, 0xc2},
  383. {0x37dc, 0x02},
  384. {0x37e0, 0x00},
  385. {0x37e1, 0x0a},
  386. {0x37e2, 0x14},
  387. {0x37e3, 0x08},
  388. {0x37e4, 0x38},
  389. {0x37e5, 0x03},
  390. {0x37e6, 0x08},
  391. {0x3800, 0x00},
  392. {0x3801, 0x00},
  393. {0x3802, 0x00},
  394. {0x3803, 0x00},
  395. {0x3804, 0x10},
  396. {0x3805, 0x9f},
  397. {0x3806, 0x0c},
  398. {0x3807, 0x5f},
  399. {0x3808, 0x08},
  400. {0x3809, 0x40},
  401. {0x380a, 0x06},
  402. {0x380b, 0x20},
  403. {0x380c, 0x04},
  404. {0x380d, 0x62},
  405. {0x380e, 0x0c},
  406. {0x380f, 0x8e},
  407. {0x3811, 0x04},
  408. {0x3813, 0x05},
  409. {0x3814, 0x03},
  410. {0x3815, 0x01},
  411. {0x3816, 0x03},
  412. {0x3817, 0x01},
  413. {0x3820, 0xab},
  414. {0x3821, 0x00},
  415. {0x3822, 0xc2},
  416. {0x3823, 0x18},
  417. {0x3826, 0x04},
  418. {0x3827, 0x90},
  419. {0x3829, 0x07},
  420. {0x3832, 0x00},
  421. {0x3c80, 0x00},
  422. {0x3c87, 0x01},
  423. {0x3c8c, 0x19},
  424. {0x3c8d, 0x1c},
  425. {0x3c90, 0x00},
  426. {0x3c91, 0x00},
  427. {0x3c92, 0x00},
  428. {0x3c93, 0x00},
  429. {0x3c94, 0x40},
  430. {0x3c95, 0x54},
  431. {0x3c96, 0x34},
  432. {0x3c97, 0x04},
  433. {0x3c98, 0x00},
  434. {0x3d8c, 0x73},
  435. {0x3d8d, 0xc0},
  436. {0x3f00, 0x0b},
  437. {0x3f03, 0x00},
  438. {0x4001, 0xe0},
  439. {0x4008, 0x00},
  440. {0x4009, 0x0d},
  441. {0x4011, 0xf0},
  442. {0x4017, 0x08},
  443. {0x4050, 0x04},
  444. {0x4051, 0x0b},
  445. {0x4052, 0x00},
  446. {0x4053, 0x80},
  447. {0x4054, 0x00},
  448. {0x4055, 0x80},
  449. {0x4056, 0x00},
  450. {0x4057, 0x80},
  451. {0x4058, 0x00},
  452. {0x4059, 0x80},
  453. {0x405e, 0x20},
  454. {0x4500, 0x07},
  455. {0x4503, 0x00},
  456. {0x450a, 0x04},
  457. {0x4809, 0x04},
  458. {0x480c, 0x12},
  459. {0x481f, 0x30},
  460. {0x4833, 0x10},
  461. {0x4837, 0x1c},
  462. {0x4902, 0x01},
  463. {0x4d00, 0x03},
  464. {0x4d01, 0xc9},
  465. {0x4d02, 0xbc},
  466. {0x4d03, 0xd7},
  467. {0x4d04, 0xf0},
  468. {0x4d05, 0xa2},
  469. {0x5000, 0xfd},
  470. {0x5001, 0x01},
  471. {0x5040, 0x39},
  472. {0x5041, 0x10},
  473. {0x5042, 0x10},
  474. {0x5043, 0x84},
  475. {0x5044, 0x62},
  476. {0x5180, 0x00},
  477. {0x5181, 0x10},
  478. {0x5182, 0x02},
  479. {0x5183, 0x0f},
  480. {0x5200, 0x1b},
  481. {0x520b, 0x07},
  482. {0x520c, 0x0f},
  483. {0x5300, 0x04},
  484. {0x5301, 0x0c},
  485. {0x5302, 0x0c},
  486. {0x5303, 0x0f},
  487. {0x5304, 0x00},
  488. {0x5305, 0x70},
  489. {0x5306, 0x00},
  490. {0x5307, 0x80},
  491. {0x5308, 0x00},
  492. {0x5309, 0xa5},
  493. {0x530a, 0x00},
  494. {0x530b, 0xd3},
  495. {0x530c, 0x00},
  496. {0x530d, 0xf0},
  497. {0x530e, 0x01},
  498. {0x530f, 0x10},
  499. {0x5310, 0x01},
  500. {0x5311, 0x20},
  501. {0x5312, 0x01},
  502. {0x5313, 0x20},
  503. {0x5314, 0x01},
  504. {0x5315, 0x20},
  505. {0x5316, 0x08},
  506. {0x5317, 0x08},
  507. {0x5318, 0x10},
  508. {0x5319, 0x88},
  509. {0x531a, 0x88},
  510. {0x531b, 0xa9},
  511. {0x531c, 0xaa},
  512. {0x531d, 0x0a},
  513. {0x5405, 0x02},
  514. {0x5406, 0x67},
  515. {0x5407, 0x01},
  516. {0x5408, 0x4a},
  517. };
  518. static const struct ov13858_reg mode_2112x1188_regs[] = {
  519. {0x3013, 0x32},
  520. {0x301b, 0xf0},
  521. {0x301f, 0xd0},
  522. {0x3106, 0x15},
  523. {0x3107, 0x23},
  524. {0x350a, 0x00},
  525. {0x350e, 0x00},
  526. {0x3510, 0x00},
  527. {0x3511, 0x02},
  528. {0x3512, 0x00},
  529. {0x3600, 0x2b},
  530. {0x3601, 0x52},
  531. {0x3602, 0x60},
  532. {0x3612, 0x05},
  533. {0x3613, 0xa4},
  534. {0x3620, 0x80},
  535. {0x3621, 0x10},
  536. {0x3622, 0x30},
  537. {0x3624, 0x1c},
  538. {0x3640, 0x10},
  539. {0x3641, 0x70},
  540. {0x3660, 0x04},
  541. {0x3661, 0x80},
  542. {0x3662, 0x10},
  543. {0x3664, 0x73},
  544. {0x3665, 0xa7},
  545. {0x366e, 0xff},
  546. {0x366f, 0xf4},
  547. {0x3674, 0x00},
  548. {0x3679, 0x0c},
  549. {0x367f, 0x01},
  550. {0x3680, 0x0c},
  551. {0x3681, 0x50},
  552. {0x3682, 0x50},
  553. {0x3683, 0xa9},
  554. {0x3684, 0xa9},
  555. {0x3709, 0x5f},
  556. {0x3714, 0x28},
  557. {0x371a, 0x3e},
  558. {0x3737, 0x08},
  559. {0x3738, 0xcc},
  560. {0x3739, 0x20},
  561. {0x373d, 0x26},
  562. {0x3764, 0x20},
  563. {0x3765, 0x20},
  564. {0x37a1, 0x36},
  565. {0x37a8, 0x3b},
  566. {0x37ab, 0x31},
  567. {0x37c2, 0x14},
  568. {0x37c3, 0xf1},
  569. {0x37c5, 0x00},
  570. {0x37d8, 0x03},
  571. {0x37d9, 0x0c},
  572. {0x37da, 0xc2},
  573. {0x37dc, 0x02},
  574. {0x37e0, 0x00},
  575. {0x37e1, 0x0a},
  576. {0x37e2, 0x14},
  577. {0x37e3, 0x08},
  578. {0x37e4, 0x38},
  579. {0x37e5, 0x03},
  580. {0x37e6, 0x08},
  581. {0x3800, 0x00},
  582. {0x3801, 0x00},
  583. {0x3802, 0x01},
  584. {0x3803, 0x84},
  585. {0x3804, 0x10},
  586. {0x3805, 0x9f},
  587. {0x3806, 0x0a},
  588. {0x3807, 0xd3},
  589. {0x3808, 0x08},
  590. {0x3809, 0x40},
  591. {0x380a, 0x04},
  592. {0x380b, 0xa4},
  593. {0x380c, 0x04},
  594. {0x380d, 0x62},
  595. {0x380e, 0x0c},
  596. {0x380f, 0x8e},
  597. {0x3811, 0x08},
  598. {0x3813, 0x03},
  599. {0x3814, 0x03},
  600. {0x3815, 0x01},
  601. {0x3816, 0x03},
  602. {0x3817, 0x01},
  603. {0x3820, 0xab},
  604. {0x3821, 0x00},
  605. {0x3822, 0xc2},
  606. {0x3823, 0x18},
  607. {0x3826, 0x04},
  608. {0x3827, 0x90},
  609. {0x3829, 0x07},
  610. {0x3832, 0x00},
  611. {0x3c80, 0x00},
  612. {0x3c87, 0x01},
  613. {0x3c8c, 0x19},
  614. {0x3c8d, 0x1c},
  615. {0x3c90, 0x00},
  616. {0x3c91, 0x00},
  617. {0x3c92, 0x00},
  618. {0x3c93, 0x00},
  619. {0x3c94, 0x40},
  620. {0x3c95, 0x54},
  621. {0x3c96, 0x34},
  622. {0x3c97, 0x04},
  623. {0x3c98, 0x00},
  624. {0x3d8c, 0x73},
  625. {0x3d8d, 0xc0},
  626. {0x3f00, 0x0b},
  627. {0x3f03, 0x00},
  628. {0x4001, 0xe0},
  629. {0x4008, 0x00},
  630. {0x4009, 0x0d},
  631. {0x4011, 0xf0},
  632. {0x4017, 0x08},
  633. {0x4050, 0x04},
  634. {0x4051, 0x0b},
  635. {0x4052, 0x00},
  636. {0x4053, 0x80},
  637. {0x4054, 0x00},
  638. {0x4055, 0x80},
  639. {0x4056, 0x00},
  640. {0x4057, 0x80},
  641. {0x4058, 0x00},
  642. {0x4059, 0x80},
  643. {0x405e, 0x20},
  644. {0x4500, 0x07},
  645. {0x4503, 0x00},
  646. {0x450a, 0x04},
  647. {0x4809, 0x04},
  648. {0x480c, 0x12},
  649. {0x481f, 0x30},
  650. {0x4833, 0x10},
  651. {0x4837, 0x1c},
  652. {0x4902, 0x01},
  653. {0x4d00, 0x03},
  654. {0x4d01, 0xc9},
  655. {0x4d02, 0xbc},
  656. {0x4d03, 0xd7},
  657. {0x4d04, 0xf0},
  658. {0x4d05, 0xa2},
  659. {0x5000, 0xfd},
  660. {0x5001, 0x01},
  661. {0x5040, 0x39},
  662. {0x5041, 0x10},
  663. {0x5042, 0x10},
  664. {0x5043, 0x84},
  665. {0x5044, 0x62},
  666. {0x5180, 0x00},
  667. {0x5181, 0x10},
  668. {0x5182, 0x02},
  669. {0x5183, 0x0f},
  670. {0x5200, 0x1b},
  671. {0x520b, 0x07},
  672. {0x520c, 0x0f},
  673. {0x5300, 0x04},
  674. {0x5301, 0x0c},
  675. {0x5302, 0x0c},
  676. {0x5303, 0x0f},
  677. {0x5304, 0x00},
  678. {0x5305, 0x70},
  679. {0x5306, 0x00},
  680. {0x5307, 0x80},
  681. {0x5308, 0x00},
  682. {0x5309, 0xa5},
  683. {0x530a, 0x00},
  684. {0x530b, 0xd3},
  685. {0x530c, 0x00},
  686. {0x530d, 0xf0},
  687. {0x530e, 0x01},
  688. {0x530f, 0x10},
  689. {0x5310, 0x01},
  690. {0x5311, 0x20},
  691. {0x5312, 0x01},
  692. {0x5313, 0x20},
  693. {0x5314, 0x01},
  694. {0x5315, 0x20},
  695. {0x5316, 0x08},
  696. {0x5317, 0x08},
  697. {0x5318, 0x10},
  698. {0x5319, 0x88},
  699. {0x531a, 0x88},
  700. {0x531b, 0xa9},
  701. {0x531c, 0xaa},
  702. {0x531d, 0x0a},
  703. {0x5405, 0x02},
  704. {0x5406, 0x67},
  705. {0x5407, 0x01},
  706. {0x5408, 0x4a},
  707. };
  708. static const struct ov13858_reg mode_1056x784_regs[] = {
  709. {0x3013, 0x32},
  710. {0x301b, 0xf0},
  711. {0x301f, 0xd0},
  712. {0x3106, 0x15},
  713. {0x3107, 0x23},
  714. {0x350a, 0x00},
  715. {0x350e, 0x00},
  716. {0x3510, 0x00},
  717. {0x3511, 0x02},
  718. {0x3512, 0x00},
  719. {0x3600, 0x2b},
  720. {0x3601, 0x52},
  721. {0x3602, 0x60},
  722. {0x3612, 0x05},
  723. {0x3613, 0xa4},
  724. {0x3620, 0x80},
  725. {0x3621, 0x10},
  726. {0x3622, 0x30},
  727. {0x3624, 0x1c},
  728. {0x3640, 0x10},
  729. {0x3641, 0x70},
  730. {0x3660, 0x04},
  731. {0x3661, 0x80},
  732. {0x3662, 0x08},
  733. {0x3664, 0x73},
  734. {0x3665, 0xa7},
  735. {0x366e, 0xff},
  736. {0x366f, 0xf4},
  737. {0x3674, 0x00},
  738. {0x3679, 0x0c},
  739. {0x367f, 0x01},
  740. {0x3680, 0x0c},
  741. {0x3681, 0x50},
  742. {0x3682, 0x50},
  743. {0x3683, 0xa9},
  744. {0x3684, 0xa9},
  745. {0x3709, 0x5f},
  746. {0x3714, 0x30},
  747. {0x371a, 0x3e},
  748. {0x3737, 0x08},
  749. {0x3738, 0xcc},
  750. {0x3739, 0x20},
  751. {0x373d, 0x26},
  752. {0x3764, 0x20},
  753. {0x3765, 0x20},
  754. {0x37a1, 0x36},
  755. {0x37a8, 0x3b},
  756. {0x37ab, 0x31},
  757. {0x37c2, 0x2c},
  758. {0x37c3, 0xf1},
  759. {0x37c5, 0x00},
  760. {0x37d8, 0x03},
  761. {0x37d9, 0x06},
  762. {0x37da, 0xc2},
  763. {0x37dc, 0x02},
  764. {0x37e0, 0x00},
  765. {0x37e1, 0x0a},
  766. {0x37e2, 0x14},
  767. {0x37e3, 0x08},
  768. {0x37e4, 0x36},
  769. {0x37e5, 0x03},
  770. {0x37e6, 0x08},
  771. {0x3800, 0x00},
  772. {0x3801, 0x00},
  773. {0x3802, 0x00},
  774. {0x3803, 0x00},
  775. {0x3804, 0x10},
  776. {0x3805, 0x9f},
  777. {0x3806, 0x0c},
  778. {0x3807, 0x5f},
  779. {0x3808, 0x04},
  780. {0x3809, 0x20},
  781. {0x380a, 0x03},
  782. {0x380b, 0x10},
  783. {0x380c, 0x04},
  784. {0x380d, 0x62},
  785. {0x380e, 0x0c},
  786. {0x380f, 0x8e},
  787. {0x3811, 0x04},
  788. {0x3813, 0x05},
  789. {0x3814, 0x07},
  790. {0x3815, 0x01},
  791. {0x3816, 0x07},
  792. {0x3817, 0x01},
  793. {0x3820, 0xac},
  794. {0x3821, 0x00},
  795. {0x3822, 0xc2},
  796. {0x3823, 0x18},
  797. {0x3826, 0x04},
  798. {0x3827, 0x48},
  799. {0x3829, 0x03},
  800. {0x3832, 0x00},
  801. {0x3c80, 0x00},
  802. {0x3c87, 0x01},
  803. {0x3c8c, 0x19},
  804. {0x3c8d, 0x1c},
  805. {0x3c90, 0x00},
  806. {0x3c91, 0x00},
  807. {0x3c92, 0x00},
  808. {0x3c93, 0x00},
  809. {0x3c94, 0x40},
  810. {0x3c95, 0x54},
  811. {0x3c96, 0x34},
  812. {0x3c97, 0x04},
  813. {0x3c98, 0x00},
  814. {0x3d8c, 0x73},
  815. {0x3d8d, 0xc0},
  816. {0x3f00, 0x0b},
  817. {0x3f03, 0x00},
  818. {0x4001, 0xe0},
  819. {0x4008, 0x00},
  820. {0x4009, 0x05},
  821. {0x4011, 0xf0},
  822. {0x4017, 0x08},
  823. {0x4050, 0x02},
  824. {0x4051, 0x05},
  825. {0x4052, 0x00},
  826. {0x4053, 0x80},
  827. {0x4054, 0x00},
  828. {0x4055, 0x80},
  829. {0x4056, 0x00},
  830. {0x4057, 0x80},
  831. {0x4058, 0x00},
  832. {0x4059, 0x80},
  833. {0x405e, 0x20},
  834. {0x4500, 0x07},
  835. {0x4503, 0x00},
  836. {0x450a, 0x04},
  837. {0x4809, 0x04},
  838. {0x480c, 0x12},
  839. {0x481f, 0x30},
  840. {0x4833, 0x10},
  841. {0x4837, 0x1e},
  842. {0x4902, 0x02},
  843. {0x4d00, 0x03},
  844. {0x4d01, 0xc9},
  845. {0x4d02, 0xbc},
  846. {0x4d03, 0xd7},
  847. {0x4d04, 0xf0},
  848. {0x4d05, 0xa2},
  849. {0x5000, 0xfd},
  850. {0x5001, 0x01},
  851. {0x5040, 0x39},
  852. {0x5041, 0x10},
  853. {0x5042, 0x10},
  854. {0x5043, 0x84},
  855. {0x5044, 0x62},
  856. {0x5180, 0x00},
  857. {0x5181, 0x10},
  858. {0x5182, 0x02},
  859. {0x5183, 0x0f},
  860. {0x5200, 0x1b},
  861. {0x520b, 0x07},
  862. {0x520c, 0x0f},
  863. {0x5300, 0x04},
  864. {0x5301, 0x0c},
  865. {0x5302, 0x0c},
  866. {0x5303, 0x0f},
  867. {0x5304, 0x00},
  868. {0x5305, 0x70},
  869. {0x5306, 0x00},
  870. {0x5307, 0x80},
  871. {0x5308, 0x00},
  872. {0x5309, 0xa5},
  873. {0x530a, 0x00},
  874. {0x530b, 0xd3},
  875. {0x530c, 0x00},
  876. {0x530d, 0xf0},
  877. {0x530e, 0x01},
  878. {0x530f, 0x10},
  879. {0x5310, 0x01},
  880. {0x5311, 0x20},
  881. {0x5312, 0x01},
  882. {0x5313, 0x20},
  883. {0x5314, 0x01},
  884. {0x5315, 0x20},
  885. {0x5316, 0x08},
  886. {0x5317, 0x08},
  887. {0x5318, 0x10},
  888. {0x5319, 0x88},
  889. {0x531a, 0x88},
  890. {0x531b, 0xa9},
  891. {0x531c, 0xaa},
  892. {0x531d, 0x0a},
  893. {0x5405, 0x02},
  894. {0x5406, 0x67},
  895. {0x5407, 0x01},
  896. {0x5408, 0x4a},
  897. };
  898. static const char * const ov13858_test_pattern_menu[] = {
  899. "Disabled",
  900. "Vertical Color Bar Type 1",
  901. "Vertical Color Bar Type 2",
  902. "Vertical Color Bar Type 3",
  903. "Vertical Color Bar Type 4"
  904. };
  905. /* Configurations for supported link frequencies */
  906. #define OV13858_NUM_OF_LINK_FREQS 2
  907. #define OV13858_LINK_FREQ_540MHZ 540000000ULL
  908. #define OV13858_LINK_FREQ_270MHZ 270000000ULL
  909. #define OV13858_LINK_FREQ_INDEX_0 0
  910. #define OV13858_LINK_FREQ_INDEX_1 1
  911. /*
  912. * pixel_rate = link_freq * data-rate * nr_of_lanes / bits_per_sample
  913. * data rate => double data rate; number of lanes => 4; bits per pixel => 10
  914. */
  915. static u64 link_freq_to_pixel_rate(u64 f)
  916. {
  917. f *= 2 * 4;
  918. do_div(f, 10);
  919. return f;
  920. }
  921. /* Menu items for LINK_FREQ V4L2 control */
  922. static const s64 link_freq_menu_items[OV13858_NUM_OF_LINK_FREQS] = {
  923. OV13858_LINK_FREQ_540MHZ,
  924. OV13858_LINK_FREQ_270MHZ
  925. };
  926. /* Link frequency configs */
  927. static const struct ov13858_link_freq_config
  928. link_freq_configs[OV13858_NUM_OF_LINK_FREQS] = {
  929. {
  930. .pixels_per_line = OV13858_PPL_540MHZ,
  931. .reg_list = {
  932. .num_of_regs = ARRAY_SIZE(mipi_data_rate_1080mbps),
  933. .regs = mipi_data_rate_1080mbps,
  934. }
  935. },
  936. {
  937. .pixels_per_line = OV13858_PPL_270MHZ,
  938. .reg_list = {
  939. .num_of_regs = ARRAY_SIZE(mipi_data_rate_540mbps),
  940. .regs = mipi_data_rate_540mbps,
  941. }
  942. }
  943. };
  944. /* Mode configs */
  945. static const struct ov13858_mode supported_modes[] = {
  946. {
  947. .width = 4224,
  948. .height = 3136,
  949. .vts_def = OV13858_VTS_30FPS,
  950. .vts_min = OV13858_VTS_30FPS,
  951. .reg_list = {
  952. .num_of_regs = ARRAY_SIZE(mode_4224x3136_regs),
  953. .regs = mode_4224x3136_regs,
  954. },
  955. .link_freq_index = OV13858_LINK_FREQ_INDEX_0,
  956. },
  957. {
  958. .width = 2112,
  959. .height = 1568,
  960. .vts_def = OV13858_VTS_30FPS,
  961. .vts_min = 1608,
  962. .reg_list = {
  963. .num_of_regs = ARRAY_SIZE(mode_2112x1568_regs),
  964. .regs = mode_2112x1568_regs,
  965. },
  966. .link_freq_index = OV13858_LINK_FREQ_INDEX_1,
  967. },
  968. {
  969. .width = 2112,
  970. .height = 1188,
  971. .vts_def = OV13858_VTS_30FPS,
  972. .vts_min = 1608,
  973. .reg_list = {
  974. .num_of_regs = ARRAY_SIZE(mode_2112x1188_regs),
  975. .regs = mode_2112x1188_regs,
  976. },
  977. .link_freq_index = OV13858_LINK_FREQ_INDEX_1,
  978. },
  979. {
  980. .width = 1056,
  981. .height = 784,
  982. .vts_def = OV13858_VTS_30FPS,
  983. .vts_min = 804,
  984. .reg_list = {
  985. .num_of_regs = ARRAY_SIZE(mode_1056x784_regs),
  986. .regs = mode_1056x784_regs,
  987. },
  988. .link_freq_index = OV13858_LINK_FREQ_INDEX_1,
  989. }
  990. };
  991. struct ov13858 {
  992. struct v4l2_subdev sd;
  993. struct media_pad pad;
  994. struct v4l2_ctrl_handler ctrl_handler;
  995. /* V4L2 Controls */
  996. struct v4l2_ctrl *link_freq;
  997. struct v4l2_ctrl *pixel_rate;
  998. struct v4l2_ctrl *vblank;
  999. struct v4l2_ctrl *hblank;
  1000. struct v4l2_ctrl *exposure;
  1001. /* Current mode */
  1002. const struct ov13858_mode *cur_mode;
  1003. /* Mutex for serialized access */
  1004. struct mutex mutex;
  1005. /* Streaming on/off */
  1006. bool streaming;
  1007. };
  1008. #define to_ov13858(_sd) container_of(_sd, struct ov13858, sd)
  1009. /* Read registers up to 4 at a time */
  1010. static int ov13858_read_reg(struct ov13858 *ov13858, u16 reg, u32 len,
  1011. u32 *val)
  1012. {
  1013. struct i2c_client *client = v4l2_get_subdevdata(&ov13858->sd);
  1014. struct i2c_msg msgs[2];
  1015. u8 *data_be_p;
  1016. int ret;
  1017. __be32 data_be = 0;
  1018. __be16 reg_addr_be = cpu_to_be16(reg);
  1019. if (len > 4)
  1020. return -EINVAL;
  1021. data_be_p = (u8 *)&data_be;
  1022. /* Write register address */
  1023. msgs[0].addr = client->addr;
  1024. msgs[0].flags = 0;
  1025. msgs[0].len = 2;
  1026. msgs[0].buf = (u8 *)&reg_addr_be;
  1027. /* Read data from register */
  1028. msgs[1].addr = client->addr;
  1029. msgs[1].flags = I2C_M_RD;
  1030. msgs[1].len = len;
  1031. msgs[1].buf = &data_be_p[4 - len];
  1032. ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
  1033. if (ret != ARRAY_SIZE(msgs))
  1034. return -EIO;
  1035. *val = be32_to_cpu(data_be);
  1036. return 0;
  1037. }
  1038. /* Write registers up to 4 at a time */
  1039. static int ov13858_write_reg(struct ov13858 *ov13858, u16 reg, u32 len,
  1040. u32 __val)
  1041. {
  1042. struct i2c_client *client = v4l2_get_subdevdata(&ov13858->sd);
  1043. int buf_i, val_i;
  1044. u8 buf[6], *val_p;
  1045. __be32 val;
  1046. if (len > 4)
  1047. return -EINVAL;
  1048. buf[0] = reg >> 8;
  1049. buf[1] = reg & 0xff;
  1050. val = cpu_to_be32(__val);
  1051. val_p = (u8 *)&val;
  1052. buf_i = 2;
  1053. val_i = 4 - len;
  1054. while (val_i < 4)
  1055. buf[buf_i++] = val_p[val_i++];
  1056. if (i2c_master_send(client, buf, len + 2) != len + 2)
  1057. return -EIO;
  1058. return 0;
  1059. }
  1060. /* Write a list of registers */
  1061. static int ov13858_write_regs(struct ov13858 *ov13858,
  1062. const struct ov13858_reg *regs, u32 len)
  1063. {
  1064. struct i2c_client *client = v4l2_get_subdevdata(&ov13858->sd);
  1065. int ret;
  1066. u32 i;
  1067. for (i = 0; i < len; i++) {
  1068. ret = ov13858_write_reg(ov13858, regs[i].address, 1,
  1069. regs[i].val);
  1070. if (ret) {
  1071. dev_err_ratelimited(
  1072. &client->dev,
  1073. "Failed to write reg 0x%4.4x. error = %d\n",
  1074. regs[i].address, ret);
  1075. return ret;
  1076. }
  1077. }
  1078. return 0;
  1079. }
  1080. static int ov13858_write_reg_list(struct ov13858 *ov13858,
  1081. const struct ov13858_reg_list *r_list)
  1082. {
  1083. return ov13858_write_regs(ov13858, r_list->regs, r_list->num_of_regs);
  1084. }
  1085. /* Open sub-device */
  1086. static int ov13858_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
  1087. {
  1088. struct ov13858 *ov13858 = to_ov13858(sd);
  1089. struct v4l2_mbus_framefmt *try_fmt = v4l2_subdev_get_try_format(sd,
  1090. fh->pad,
  1091. 0);
  1092. mutex_lock(&ov13858->mutex);
  1093. /* Initialize try_fmt */
  1094. try_fmt->width = ov13858->cur_mode->width;
  1095. try_fmt->height = ov13858->cur_mode->height;
  1096. try_fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10;
  1097. try_fmt->field = V4L2_FIELD_NONE;
  1098. /* No crop or compose */
  1099. mutex_unlock(&ov13858->mutex);
  1100. return 0;
  1101. }
  1102. static int ov13858_update_digital_gain(struct ov13858 *ov13858, u32 d_gain)
  1103. {
  1104. int ret;
  1105. ret = ov13858_write_reg(ov13858, OV13858_REG_B_MWB_GAIN,
  1106. OV13858_REG_VALUE_16BIT, d_gain);
  1107. if (ret)
  1108. return ret;
  1109. ret = ov13858_write_reg(ov13858, OV13858_REG_G_MWB_GAIN,
  1110. OV13858_REG_VALUE_16BIT, d_gain);
  1111. if (ret)
  1112. return ret;
  1113. ret = ov13858_write_reg(ov13858, OV13858_REG_R_MWB_GAIN,
  1114. OV13858_REG_VALUE_16BIT, d_gain);
  1115. return ret;
  1116. }
  1117. static int ov13858_enable_test_pattern(struct ov13858 *ov13858, u32 pattern)
  1118. {
  1119. int ret;
  1120. u32 val;
  1121. ret = ov13858_read_reg(ov13858, OV13858_REG_TEST_PATTERN,
  1122. OV13858_REG_VALUE_08BIT, &val);
  1123. if (ret)
  1124. return ret;
  1125. if (pattern) {
  1126. val &= OV13858_TEST_PATTERN_MASK;
  1127. val |= (pattern - 1) | OV13858_TEST_PATTERN_ENABLE;
  1128. } else {
  1129. val &= ~OV13858_TEST_PATTERN_ENABLE;
  1130. }
  1131. return ov13858_write_reg(ov13858, OV13858_REG_TEST_PATTERN,
  1132. OV13858_REG_VALUE_08BIT, val);
  1133. }
  1134. static int ov13858_set_ctrl(struct v4l2_ctrl *ctrl)
  1135. {
  1136. struct ov13858 *ov13858 = container_of(ctrl->handler,
  1137. struct ov13858, ctrl_handler);
  1138. struct i2c_client *client = v4l2_get_subdevdata(&ov13858->sd);
  1139. s64 max;
  1140. int ret;
  1141. /* Propagate change of current control to all related controls */
  1142. switch (ctrl->id) {
  1143. case V4L2_CID_VBLANK:
  1144. /* Update max exposure while meeting expected vblanking */
  1145. max = ov13858->cur_mode->height + ctrl->val - 8;
  1146. __v4l2_ctrl_modify_range(ov13858->exposure,
  1147. ov13858->exposure->minimum,
  1148. max, ov13858->exposure->step, max);
  1149. break;
  1150. };
  1151. /*
  1152. * Applying V4L2 control value only happens
  1153. * when power is up for streaming
  1154. */
  1155. if (!pm_runtime_get_if_in_use(&client->dev))
  1156. return 0;
  1157. ret = 0;
  1158. switch (ctrl->id) {
  1159. case V4L2_CID_ANALOGUE_GAIN:
  1160. ret = ov13858_write_reg(ov13858, OV13858_REG_ANALOG_GAIN,
  1161. OV13858_REG_VALUE_16BIT, ctrl->val);
  1162. break;
  1163. case V4L2_CID_DIGITAL_GAIN:
  1164. ret = ov13858_update_digital_gain(ov13858, ctrl->val);
  1165. break;
  1166. case V4L2_CID_EXPOSURE:
  1167. ret = ov13858_write_reg(ov13858, OV13858_REG_EXPOSURE,
  1168. OV13858_REG_VALUE_24BIT,
  1169. ctrl->val << 4);
  1170. break;
  1171. case V4L2_CID_VBLANK:
  1172. /* Update VTS that meets expected vertical blanking */
  1173. ret = ov13858_write_reg(ov13858, OV13858_REG_VTS,
  1174. OV13858_REG_VALUE_16BIT,
  1175. ov13858->cur_mode->height
  1176. + ctrl->val);
  1177. break;
  1178. case V4L2_CID_TEST_PATTERN:
  1179. ret = ov13858_enable_test_pattern(ov13858, ctrl->val);
  1180. break;
  1181. default:
  1182. dev_info(&client->dev,
  1183. "ctrl(id:0x%x,val:0x%x) is not handled\n",
  1184. ctrl->id, ctrl->val);
  1185. break;
  1186. };
  1187. pm_runtime_put(&client->dev);
  1188. return ret;
  1189. }
  1190. static const struct v4l2_ctrl_ops ov13858_ctrl_ops = {
  1191. .s_ctrl = ov13858_set_ctrl,
  1192. };
  1193. static int ov13858_enum_mbus_code(struct v4l2_subdev *sd,
  1194. struct v4l2_subdev_pad_config *cfg,
  1195. struct v4l2_subdev_mbus_code_enum *code)
  1196. {
  1197. /* Only one bayer order(GRBG) is supported */
  1198. if (code->index > 0)
  1199. return -EINVAL;
  1200. code->code = MEDIA_BUS_FMT_SGRBG10_1X10;
  1201. return 0;
  1202. }
  1203. static int ov13858_enum_frame_size(struct v4l2_subdev *sd,
  1204. struct v4l2_subdev_pad_config *cfg,
  1205. struct v4l2_subdev_frame_size_enum *fse)
  1206. {
  1207. if (fse->index >= ARRAY_SIZE(supported_modes))
  1208. return -EINVAL;
  1209. if (fse->code != MEDIA_BUS_FMT_SGRBG10_1X10)
  1210. return -EINVAL;
  1211. fse->min_width = supported_modes[fse->index].width;
  1212. fse->max_width = fse->min_width;
  1213. fse->min_height = supported_modes[fse->index].height;
  1214. fse->max_height = fse->min_height;
  1215. return 0;
  1216. }
  1217. static void ov13858_update_pad_format(const struct ov13858_mode *mode,
  1218. struct v4l2_subdev_format *fmt)
  1219. {
  1220. fmt->format.width = mode->width;
  1221. fmt->format.height = mode->height;
  1222. fmt->format.code = MEDIA_BUS_FMT_SGRBG10_1X10;
  1223. fmt->format.field = V4L2_FIELD_NONE;
  1224. }
  1225. static int ov13858_do_get_pad_format(struct ov13858 *ov13858,
  1226. struct v4l2_subdev_pad_config *cfg,
  1227. struct v4l2_subdev_format *fmt)
  1228. {
  1229. struct v4l2_mbus_framefmt *framefmt;
  1230. struct v4l2_subdev *sd = &ov13858->sd;
  1231. if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
  1232. framefmt = v4l2_subdev_get_try_format(sd, cfg, fmt->pad);
  1233. fmt->format = *framefmt;
  1234. } else {
  1235. ov13858_update_pad_format(ov13858->cur_mode, fmt);
  1236. }
  1237. return 0;
  1238. }
  1239. static int ov13858_get_pad_format(struct v4l2_subdev *sd,
  1240. struct v4l2_subdev_pad_config *cfg,
  1241. struct v4l2_subdev_format *fmt)
  1242. {
  1243. struct ov13858 *ov13858 = to_ov13858(sd);
  1244. int ret;
  1245. mutex_lock(&ov13858->mutex);
  1246. ret = ov13858_do_get_pad_format(ov13858, cfg, fmt);
  1247. mutex_unlock(&ov13858->mutex);
  1248. return ret;
  1249. }
  1250. static int
  1251. ov13858_set_pad_format(struct v4l2_subdev *sd,
  1252. struct v4l2_subdev_pad_config *cfg,
  1253. struct v4l2_subdev_format *fmt)
  1254. {
  1255. struct ov13858 *ov13858 = to_ov13858(sd);
  1256. const struct ov13858_mode *mode;
  1257. struct v4l2_mbus_framefmt *framefmt;
  1258. s32 vblank_def;
  1259. s32 vblank_min;
  1260. s64 h_blank;
  1261. s64 pixel_rate;
  1262. s64 link_freq;
  1263. mutex_lock(&ov13858->mutex);
  1264. /* Only one raw bayer(GRBG) order is supported */
  1265. if (fmt->format.code != MEDIA_BUS_FMT_SGRBG10_1X10)
  1266. fmt->format.code = MEDIA_BUS_FMT_SGRBG10_1X10;
  1267. mode = v4l2_find_nearest_size(supported_modes,
  1268. ARRAY_SIZE(supported_modes),
  1269. width, height,
  1270. fmt->format.width, fmt->format.height);
  1271. ov13858_update_pad_format(mode, fmt);
  1272. if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
  1273. framefmt = v4l2_subdev_get_try_format(sd, cfg, fmt->pad);
  1274. *framefmt = fmt->format;
  1275. } else {
  1276. ov13858->cur_mode = mode;
  1277. __v4l2_ctrl_s_ctrl(ov13858->link_freq, mode->link_freq_index);
  1278. link_freq = link_freq_menu_items[mode->link_freq_index];
  1279. pixel_rate = link_freq_to_pixel_rate(link_freq);
  1280. __v4l2_ctrl_s_ctrl_int64(ov13858->pixel_rate, pixel_rate);
  1281. /* Update limits and set FPS to default */
  1282. vblank_def = ov13858->cur_mode->vts_def -
  1283. ov13858->cur_mode->height;
  1284. vblank_min = ov13858->cur_mode->vts_min -
  1285. ov13858->cur_mode->height;
  1286. __v4l2_ctrl_modify_range(
  1287. ov13858->vblank, vblank_min,
  1288. OV13858_VTS_MAX - ov13858->cur_mode->height, 1,
  1289. vblank_def);
  1290. __v4l2_ctrl_s_ctrl(ov13858->vblank, vblank_def);
  1291. h_blank =
  1292. link_freq_configs[mode->link_freq_index].pixels_per_line
  1293. - ov13858->cur_mode->width;
  1294. __v4l2_ctrl_modify_range(ov13858->hblank, h_blank,
  1295. h_blank, 1, h_blank);
  1296. }
  1297. mutex_unlock(&ov13858->mutex);
  1298. return 0;
  1299. }
  1300. static int ov13858_get_skip_frames(struct v4l2_subdev *sd, u32 *frames)
  1301. {
  1302. *frames = OV13858_NUM_OF_SKIP_FRAMES;
  1303. return 0;
  1304. }
  1305. /* Start streaming */
  1306. static int ov13858_start_streaming(struct ov13858 *ov13858)
  1307. {
  1308. struct i2c_client *client = v4l2_get_subdevdata(&ov13858->sd);
  1309. const struct ov13858_reg_list *reg_list;
  1310. int ret, link_freq_index;
  1311. /* Get out of from software reset */
  1312. ret = ov13858_write_reg(ov13858, OV13858_REG_SOFTWARE_RST,
  1313. OV13858_REG_VALUE_08BIT, OV13858_SOFTWARE_RST);
  1314. if (ret) {
  1315. dev_err(&client->dev, "%s failed to set powerup registers\n",
  1316. __func__);
  1317. return ret;
  1318. }
  1319. /* Setup PLL */
  1320. link_freq_index = ov13858->cur_mode->link_freq_index;
  1321. reg_list = &link_freq_configs[link_freq_index].reg_list;
  1322. ret = ov13858_write_reg_list(ov13858, reg_list);
  1323. if (ret) {
  1324. dev_err(&client->dev, "%s failed to set plls\n", __func__);
  1325. return ret;
  1326. }
  1327. /* Apply default values of current mode */
  1328. reg_list = &ov13858->cur_mode->reg_list;
  1329. ret = ov13858_write_reg_list(ov13858, reg_list);
  1330. if (ret) {
  1331. dev_err(&client->dev, "%s failed to set mode\n", __func__);
  1332. return ret;
  1333. }
  1334. /* Apply customized values from user */
  1335. ret = __v4l2_ctrl_handler_setup(ov13858->sd.ctrl_handler);
  1336. if (ret)
  1337. return ret;
  1338. return ov13858_write_reg(ov13858, OV13858_REG_MODE_SELECT,
  1339. OV13858_REG_VALUE_08BIT,
  1340. OV13858_MODE_STREAMING);
  1341. }
  1342. /* Stop streaming */
  1343. static int ov13858_stop_streaming(struct ov13858 *ov13858)
  1344. {
  1345. return ov13858_write_reg(ov13858, OV13858_REG_MODE_SELECT,
  1346. OV13858_REG_VALUE_08BIT, OV13858_MODE_STANDBY);
  1347. }
  1348. static int ov13858_set_stream(struct v4l2_subdev *sd, int enable)
  1349. {
  1350. struct ov13858 *ov13858 = to_ov13858(sd);
  1351. struct i2c_client *client = v4l2_get_subdevdata(sd);
  1352. int ret = 0;
  1353. mutex_lock(&ov13858->mutex);
  1354. if (ov13858->streaming == enable) {
  1355. mutex_unlock(&ov13858->mutex);
  1356. return 0;
  1357. }
  1358. if (enable) {
  1359. ret = pm_runtime_get_sync(&client->dev);
  1360. if (ret < 0) {
  1361. pm_runtime_put_noidle(&client->dev);
  1362. goto err_unlock;
  1363. }
  1364. /*
  1365. * Apply default & customized values
  1366. * and then start streaming.
  1367. */
  1368. ret = ov13858_start_streaming(ov13858);
  1369. if (ret)
  1370. goto err_rpm_put;
  1371. } else {
  1372. ov13858_stop_streaming(ov13858);
  1373. pm_runtime_put(&client->dev);
  1374. }
  1375. ov13858->streaming = enable;
  1376. mutex_unlock(&ov13858->mutex);
  1377. return ret;
  1378. err_rpm_put:
  1379. pm_runtime_put(&client->dev);
  1380. err_unlock:
  1381. mutex_unlock(&ov13858->mutex);
  1382. return ret;
  1383. }
  1384. static int __maybe_unused ov13858_suspend(struct device *dev)
  1385. {
  1386. struct i2c_client *client = to_i2c_client(dev);
  1387. struct v4l2_subdev *sd = i2c_get_clientdata(client);
  1388. struct ov13858 *ov13858 = to_ov13858(sd);
  1389. if (ov13858->streaming)
  1390. ov13858_stop_streaming(ov13858);
  1391. return 0;
  1392. }
  1393. static int __maybe_unused ov13858_resume(struct device *dev)
  1394. {
  1395. struct i2c_client *client = to_i2c_client(dev);
  1396. struct v4l2_subdev *sd = i2c_get_clientdata(client);
  1397. struct ov13858 *ov13858 = to_ov13858(sd);
  1398. int ret;
  1399. if (ov13858->streaming) {
  1400. ret = ov13858_start_streaming(ov13858);
  1401. if (ret)
  1402. goto error;
  1403. }
  1404. return 0;
  1405. error:
  1406. ov13858_stop_streaming(ov13858);
  1407. ov13858->streaming = false;
  1408. return ret;
  1409. }
  1410. /* Verify chip ID */
  1411. static int ov13858_identify_module(struct ov13858 *ov13858)
  1412. {
  1413. struct i2c_client *client = v4l2_get_subdevdata(&ov13858->sd);
  1414. int ret;
  1415. u32 val;
  1416. ret = ov13858_read_reg(ov13858, OV13858_REG_CHIP_ID,
  1417. OV13858_REG_VALUE_24BIT, &val);
  1418. if (ret)
  1419. return ret;
  1420. if (val != OV13858_CHIP_ID) {
  1421. dev_err(&client->dev, "chip id mismatch: %x!=%x\n",
  1422. OV13858_CHIP_ID, val);
  1423. return -EIO;
  1424. }
  1425. return 0;
  1426. }
  1427. static const struct v4l2_subdev_video_ops ov13858_video_ops = {
  1428. .s_stream = ov13858_set_stream,
  1429. };
  1430. static const struct v4l2_subdev_pad_ops ov13858_pad_ops = {
  1431. .enum_mbus_code = ov13858_enum_mbus_code,
  1432. .get_fmt = ov13858_get_pad_format,
  1433. .set_fmt = ov13858_set_pad_format,
  1434. .enum_frame_size = ov13858_enum_frame_size,
  1435. };
  1436. static const struct v4l2_subdev_sensor_ops ov13858_sensor_ops = {
  1437. .g_skip_frames = ov13858_get_skip_frames,
  1438. };
  1439. static const struct v4l2_subdev_ops ov13858_subdev_ops = {
  1440. .video = &ov13858_video_ops,
  1441. .pad = &ov13858_pad_ops,
  1442. .sensor = &ov13858_sensor_ops,
  1443. };
  1444. static const struct media_entity_operations ov13858_subdev_entity_ops = {
  1445. .link_validate = v4l2_subdev_link_validate,
  1446. };
  1447. static const struct v4l2_subdev_internal_ops ov13858_internal_ops = {
  1448. .open = ov13858_open,
  1449. };
  1450. /* Initialize control handlers */
  1451. static int ov13858_init_controls(struct ov13858 *ov13858)
  1452. {
  1453. struct i2c_client *client = v4l2_get_subdevdata(&ov13858->sd);
  1454. struct v4l2_ctrl_handler *ctrl_hdlr;
  1455. s64 exposure_max;
  1456. s64 vblank_def;
  1457. s64 vblank_min;
  1458. s64 hblank;
  1459. s64 pixel_rate_min;
  1460. s64 pixel_rate_max;
  1461. const struct ov13858_mode *mode;
  1462. int ret;
  1463. ctrl_hdlr = &ov13858->ctrl_handler;
  1464. ret = v4l2_ctrl_handler_init(ctrl_hdlr, 8);
  1465. if (ret)
  1466. return ret;
  1467. mutex_init(&ov13858->mutex);
  1468. ctrl_hdlr->lock = &ov13858->mutex;
  1469. ov13858->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr,
  1470. &ov13858_ctrl_ops,
  1471. V4L2_CID_LINK_FREQ,
  1472. OV13858_NUM_OF_LINK_FREQS - 1,
  1473. 0,
  1474. link_freq_menu_items);
  1475. if (ov13858->link_freq)
  1476. ov13858->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
  1477. pixel_rate_max = link_freq_to_pixel_rate(link_freq_menu_items[0]);
  1478. pixel_rate_min = link_freq_to_pixel_rate(link_freq_menu_items[1]);
  1479. /* By default, PIXEL_RATE is read only */
  1480. ov13858->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &ov13858_ctrl_ops,
  1481. V4L2_CID_PIXEL_RATE,
  1482. pixel_rate_min, pixel_rate_max,
  1483. 1, pixel_rate_max);
  1484. mode = ov13858->cur_mode;
  1485. vblank_def = mode->vts_def - mode->height;
  1486. vblank_min = mode->vts_min - mode->height;
  1487. ov13858->vblank = v4l2_ctrl_new_std(
  1488. ctrl_hdlr, &ov13858_ctrl_ops, V4L2_CID_VBLANK,
  1489. vblank_min, OV13858_VTS_MAX - mode->height, 1,
  1490. vblank_def);
  1491. hblank = link_freq_configs[mode->link_freq_index].pixels_per_line -
  1492. mode->width;
  1493. ov13858->hblank = v4l2_ctrl_new_std(
  1494. ctrl_hdlr, &ov13858_ctrl_ops, V4L2_CID_HBLANK,
  1495. hblank, hblank, 1, hblank);
  1496. if (ov13858->hblank)
  1497. ov13858->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
  1498. exposure_max = mode->vts_def - 8;
  1499. ov13858->exposure = v4l2_ctrl_new_std(
  1500. ctrl_hdlr, &ov13858_ctrl_ops,
  1501. V4L2_CID_EXPOSURE, OV13858_EXPOSURE_MIN,
  1502. exposure_max, OV13858_EXPOSURE_STEP,
  1503. OV13858_EXPOSURE_DEFAULT);
  1504. v4l2_ctrl_new_std(ctrl_hdlr, &ov13858_ctrl_ops, V4L2_CID_ANALOGUE_GAIN,
  1505. OV13858_ANA_GAIN_MIN, OV13858_ANA_GAIN_MAX,
  1506. OV13858_ANA_GAIN_STEP, OV13858_ANA_GAIN_DEFAULT);
  1507. /* Digital gain */
  1508. v4l2_ctrl_new_std(ctrl_hdlr, &ov13858_ctrl_ops, V4L2_CID_DIGITAL_GAIN,
  1509. OV13858_DGTL_GAIN_MIN, OV13858_DGTL_GAIN_MAX,
  1510. OV13858_DGTL_GAIN_STEP, OV13858_DGTL_GAIN_DEFAULT);
  1511. v4l2_ctrl_new_std_menu_items(ctrl_hdlr, &ov13858_ctrl_ops,
  1512. V4L2_CID_TEST_PATTERN,
  1513. ARRAY_SIZE(ov13858_test_pattern_menu) - 1,
  1514. 0, 0, ov13858_test_pattern_menu);
  1515. if (ctrl_hdlr->error) {
  1516. ret = ctrl_hdlr->error;
  1517. dev_err(&client->dev, "%s control init failed (%d)\n",
  1518. __func__, ret);
  1519. goto error;
  1520. }
  1521. ov13858->sd.ctrl_handler = ctrl_hdlr;
  1522. return 0;
  1523. error:
  1524. v4l2_ctrl_handler_free(ctrl_hdlr);
  1525. mutex_destroy(&ov13858->mutex);
  1526. return ret;
  1527. }
  1528. static void ov13858_free_controls(struct ov13858 *ov13858)
  1529. {
  1530. v4l2_ctrl_handler_free(ov13858->sd.ctrl_handler);
  1531. mutex_destroy(&ov13858->mutex);
  1532. }
  1533. static int ov13858_probe(struct i2c_client *client,
  1534. const struct i2c_device_id *devid)
  1535. {
  1536. struct ov13858 *ov13858;
  1537. int ret;
  1538. u32 val = 0;
  1539. device_property_read_u32(&client->dev, "clock-frequency", &val);
  1540. if (val != 19200000)
  1541. return -EINVAL;
  1542. ov13858 = devm_kzalloc(&client->dev, sizeof(*ov13858), GFP_KERNEL);
  1543. if (!ov13858)
  1544. return -ENOMEM;
  1545. /* Initialize subdev */
  1546. v4l2_i2c_subdev_init(&ov13858->sd, client, &ov13858_subdev_ops);
  1547. /* Check module identity */
  1548. ret = ov13858_identify_module(ov13858);
  1549. if (ret) {
  1550. dev_err(&client->dev, "failed to find sensor: %d\n", ret);
  1551. return ret;
  1552. }
  1553. /* Set default mode to max resolution */
  1554. ov13858->cur_mode = &supported_modes[0];
  1555. ret = ov13858_init_controls(ov13858);
  1556. if (ret)
  1557. return ret;
  1558. /* Initialize subdev */
  1559. ov13858->sd.internal_ops = &ov13858_internal_ops;
  1560. ov13858->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
  1561. ov13858->sd.entity.ops = &ov13858_subdev_entity_ops;
  1562. ov13858->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
  1563. /* Initialize source pad */
  1564. ov13858->pad.flags = MEDIA_PAD_FL_SOURCE;
  1565. ret = media_entity_pads_init(&ov13858->sd.entity, 1, &ov13858->pad);
  1566. if (ret) {
  1567. dev_err(&client->dev, "%s failed:%d\n", __func__, ret);
  1568. goto error_handler_free;
  1569. }
  1570. ret = v4l2_async_register_subdev_sensor_common(&ov13858->sd);
  1571. if (ret < 0)
  1572. goto error_media_entity;
  1573. /*
  1574. * Device is already turned on by i2c-core with ACPI domain PM.
  1575. * Enable runtime PM and turn off the device.
  1576. */
  1577. pm_runtime_get_noresume(&client->dev);
  1578. pm_runtime_set_active(&client->dev);
  1579. pm_runtime_enable(&client->dev);
  1580. pm_runtime_put(&client->dev);
  1581. return 0;
  1582. error_media_entity:
  1583. media_entity_cleanup(&ov13858->sd.entity);
  1584. error_handler_free:
  1585. ov13858_free_controls(ov13858);
  1586. dev_err(&client->dev, "%s failed:%d\n", __func__, ret);
  1587. return ret;
  1588. }
  1589. static int ov13858_remove(struct i2c_client *client)
  1590. {
  1591. struct v4l2_subdev *sd = i2c_get_clientdata(client);
  1592. struct ov13858 *ov13858 = to_ov13858(sd);
  1593. v4l2_async_unregister_subdev(sd);
  1594. media_entity_cleanup(&sd->entity);
  1595. ov13858_free_controls(ov13858);
  1596. /*
  1597. * Disable runtime PM but keep the device turned on.
  1598. * i2c-core with ACPI domain PM will turn off the device.
  1599. */
  1600. pm_runtime_get_sync(&client->dev);
  1601. pm_runtime_disable(&client->dev);
  1602. pm_runtime_set_suspended(&client->dev);
  1603. pm_runtime_put_noidle(&client->dev);
  1604. return 0;
  1605. }
  1606. static const struct i2c_device_id ov13858_id_table[] = {
  1607. {"ov13858", 0},
  1608. {},
  1609. };
  1610. MODULE_DEVICE_TABLE(i2c, ov13858_id_table);
  1611. static const struct dev_pm_ops ov13858_pm_ops = {
  1612. SET_SYSTEM_SLEEP_PM_OPS(ov13858_suspend, ov13858_resume)
  1613. };
  1614. #ifdef CONFIG_ACPI
  1615. static const struct acpi_device_id ov13858_acpi_ids[] = {
  1616. {"OVTID858"},
  1617. { /* sentinel */ }
  1618. };
  1619. MODULE_DEVICE_TABLE(acpi, ov13858_acpi_ids);
  1620. #endif
  1621. static struct i2c_driver ov13858_i2c_driver = {
  1622. .driver = {
  1623. .name = "ov13858",
  1624. .pm = &ov13858_pm_ops,
  1625. .acpi_match_table = ACPI_PTR(ov13858_acpi_ids),
  1626. },
  1627. .probe = ov13858_probe,
  1628. .remove = ov13858_remove,
  1629. .id_table = ov13858_id_table,
  1630. };
  1631. module_i2c_driver(ov13858_i2c_driver);
  1632. MODULE_AUTHOR("Kan, Chris <chris.kan@intel.com>");
  1633. MODULE_AUTHOR("Rapolu, Chiranjeevi <chiranjeevi.rapolu@intel.com>");
  1634. MODULE_AUTHOR("Yang, Hyungwoo <hyungwoo.yang@intel.com>");
  1635. MODULE_DESCRIPTION("Omnivision ov13858 sensor driver");
  1636. MODULE_LICENSE("GPL v2");