og01a1b.c 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (c) 2022 Intel Corporation.
  3. #include <linux/acpi.h>
  4. #include <linux/clk.h>
  5. #include <linux/delay.h>
  6. #include <linux/gpio/consumer.h>
  7. #include <linux/i2c.h>
  8. #include <linux/module.h>
  9. #include <linux/pm_runtime.h>
  10. #include <linux/regulator/consumer.h>
  11. #include <linux/unaligned.h>
  12. #include <media/v4l2-ctrls.h>
  13. #include <media/v4l2-device.h>
  14. #include <media/v4l2-fwnode.h>
  15. #define OG01A1B_REG_VALUE_08BIT 1
  16. #define OG01A1B_REG_VALUE_16BIT 2
  17. #define OG01A1B_REG_VALUE_24BIT 3
  18. #define OG01A1B_LINK_FREQ_500MHZ 500000000ULL
  19. #define OG01A1B_SCLK 120000000LL
  20. #define OG01A1B_MCLK 19200000
  21. #define OG01A1B_DATA_LANES 2
  22. #define OG01A1B_RGB_DEPTH 10
  23. #define OG01A1B_REG_CHIP_ID 0x300a
  24. #define OG01A1B_CHIP_ID 0x470141
  25. #define OG01A1B_REG_MODE_SELECT 0x0100
  26. #define OG01A1B_MODE_STANDBY 0x00
  27. #define OG01A1B_MODE_STREAMING 0x01
  28. /* vertical-timings from sensor */
  29. #define OG01A1B_REG_VTS 0x380e
  30. #define OG01A1B_VTS_120FPS 0x0498
  31. #define OG01A1B_VTS_120FPS_MIN 0x0498
  32. #define OG01A1B_VTS_MAX 0x7fff
  33. /* horizontal-timings from sensor */
  34. #define OG01A1B_REG_HTS 0x380c
  35. /* Exposure controls from sensor */
  36. #define OG01A1B_REG_EXPOSURE 0x3501
  37. #define OG01A1B_EXPOSURE_MIN 1
  38. #define OG01A1B_EXPOSURE_MAX_MARGIN 14
  39. #define OG01A1B_EXPOSURE_STEP 1
  40. /* Analog gain controls from sensor */
  41. #define OG01A1B_REG_ANALOG_GAIN 0x3508
  42. #define OG01A1B_ANAL_GAIN_MIN 16
  43. #define OG01A1B_ANAL_GAIN_MAX 248 /* Max = 15.5x */
  44. #define OG01A1B_ANAL_GAIN_STEP 1
  45. /* Digital gain controls from sensor */
  46. #define OG01A1B_REG_DIG_GAIN 0x350a
  47. #define OG01A1B_DGTL_GAIN_MIN 1024
  48. #define OG01A1B_DGTL_GAIN_MAX 16384 /* Max = 16x */
  49. #define OG01A1B_DGTL_GAIN_STEP 1
  50. #define OG01A1B_DGTL_GAIN_DEFAULT 1024
  51. /* Group Access */
  52. #define OG01A1B_REG_GROUP_ACCESS 0x3208
  53. #define OG01A1B_GROUP_HOLD_START 0x0
  54. #define OG01A1B_GROUP_HOLD_END 0x10
  55. #define OG01A1B_GROUP_HOLD_LAUNCH 0xa0
  56. /* Test Pattern Control */
  57. #define OG01A1B_REG_TEST_PATTERN 0x5100
  58. #define OG01A1B_TEST_PATTERN_ENABLE BIT(7)
  59. #define OG01A1B_TEST_PATTERN_BAR_SHIFT 2
  60. #define to_og01a1b(_sd) container_of(_sd, struct og01a1b, sd)
  61. enum {
  62. OG01A1B_LINK_FREQ_1000MBPS,
  63. };
  64. struct og01a1b_reg {
  65. u16 address;
  66. u8 val;
  67. };
  68. struct og01a1b_reg_list {
  69. u32 num_of_regs;
  70. const struct og01a1b_reg *regs;
  71. };
  72. struct og01a1b_link_freq_config {
  73. const struct og01a1b_reg_list reg_list;
  74. };
  75. struct og01a1b_mode {
  76. /* Frame width in pixels */
  77. u32 width;
  78. /* Frame height in pixels */
  79. u32 height;
  80. /* Horizontal timining size */
  81. u32 hts;
  82. /* Default vertical timining size */
  83. u32 vts_def;
  84. /* Min vertical timining size */
  85. u32 vts_min;
  86. /* Link frequency needed for this resolution */
  87. u32 link_freq_index;
  88. /* Sensor register settings for this resolution */
  89. const struct og01a1b_reg_list reg_list;
  90. };
  91. static const struct og01a1b_reg mipi_data_rate_1000mbps[] = {
  92. {0x0103, 0x01},
  93. {0x0303, 0x02},
  94. {0x0304, 0x00},
  95. {0x0305, 0xd2},
  96. {0x0323, 0x02},
  97. {0x0324, 0x01},
  98. {0x0325, 0x77},
  99. };
  100. static const struct og01a1b_reg mode_1280x1024_regs[] = {
  101. {0x0300, 0x0a},
  102. {0x0301, 0x29},
  103. {0x0302, 0x31},
  104. {0x0303, 0x02},
  105. {0x0304, 0x00},
  106. {0x0305, 0xd2},
  107. {0x0306, 0x00},
  108. {0x0307, 0x01},
  109. {0x0308, 0x02},
  110. {0x0309, 0x00},
  111. {0x0310, 0x00},
  112. {0x0311, 0x00},
  113. {0x0312, 0x07},
  114. {0x0313, 0x00},
  115. {0x0314, 0x00},
  116. {0x0315, 0x00},
  117. {0x0320, 0x02},
  118. {0x0321, 0x01},
  119. {0x0322, 0x01},
  120. {0x0323, 0x02},
  121. {0x0324, 0x01},
  122. {0x0325, 0x77},
  123. {0x0326, 0xce},
  124. {0x0327, 0x04},
  125. {0x0329, 0x02},
  126. {0x032a, 0x04},
  127. {0x032b, 0x04},
  128. {0x032c, 0x02},
  129. {0x032d, 0x01},
  130. {0x032e, 0x00},
  131. {0x300d, 0x02},
  132. {0x300e, 0x04},
  133. {0x3021, 0x08},
  134. {0x301e, 0x03},
  135. {0x3103, 0x00},
  136. {0x3106, 0x08},
  137. {0x3107, 0x40},
  138. {0x3216, 0x01},
  139. {0x3217, 0x00},
  140. {0x3218, 0xc0},
  141. {0x3219, 0x55},
  142. {0x3500, 0x00},
  143. {0x3501, 0x04},
  144. {0x3502, 0x8a},
  145. {0x3506, 0x01},
  146. {0x3507, 0x72},
  147. {0x3508, 0x01},
  148. {0x3509, 0x00},
  149. {0x350a, 0x01},
  150. {0x350b, 0x00},
  151. {0x350c, 0x00},
  152. {0x3541, 0x00},
  153. {0x3542, 0x40},
  154. {0x3605, 0xe0},
  155. {0x3606, 0x41},
  156. {0x3614, 0x20},
  157. {0x3620, 0x0b},
  158. {0x3630, 0x07},
  159. {0x3636, 0xa0},
  160. {0x3637, 0xf9},
  161. {0x3638, 0x09},
  162. {0x3639, 0x38},
  163. {0x363f, 0x09},
  164. {0x3640, 0x17},
  165. {0x3662, 0x04},
  166. {0x3665, 0x80},
  167. {0x3670, 0x68},
  168. {0x3674, 0x00},
  169. {0x3677, 0x3f},
  170. {0x3679, 0x00},
  171. {0x369f, 0x19},
  172. {0x36a0, 0x03},
  173. {0x36a2, 0x19},
  174. {0x36a3, 0x03},
  175. {0x370d, 0x66},
  176. {0x370f, 0x00},
  177. {0x3710, 0x03},
  178. {0x3715, 0x03},
  179. {0x3716, 0x03},
  180. {0x3717, 0x06},
  181. {0x3733, 0x00},
  182. {0x3778, 0x00},
  183. {0x37a8, 0x0f},
  184. {0x37a9, 0x01},
  185. {0x37aa, 0x07},
  186. {0x37bd, 0x1c},
  187. {0x37c1, 0x2f},
  188. {0x37c3, 0x09},
  189. {0x37c8, 0x1d},
  190. {0x37ca, 0x30},
  191. {0x37df, 0x00},
  192. {0x3800, 0x00},
  193. {0x3801, 0x00},
  194. {0x3802, 0x00},
  195. {0x3803, 0x00},
  196. {0x3804, 0x05},
  197. {0x3805, 0x0f},
  198. {0x3806, 0x04},
  199. {0x3807, 0x0f},
  200. {0x3808, 0x05},
  201. {0x3809, 0x00},
  202. {0x380a, 0x04},
  203. {0x380b, 0x00},
  204. {0x380c, 0x03},
  205. {0x380d, 0x50},
  206. {0x380e, 0x04},
  207. {0x380f, 0x98},
  208. {0x3810, 0x00},
  209. {0x3811, 0x08},
  210. {0x3812, 0x00},
  211. {0x3813, 0x08},
  212. {0x3814, 0x11},
  213. {0x3815, 0x11},
  214. {0x3820, 0x40},
  215. {0x3821, 0x04},
  216. {0x3826, 0x00},
  217. {0x3827, 0x00},
  218. {0x382a, 0x08},
  219. {0x382b, 0x52},
  220. {0x382d, 0xba},
  221. {0x383d, 0x14},
  222. {0x384a, 0xa2},
  223. {0x3866, 0x0e},
  224. {0x3867, 0x07},
  225. {0x3884, 0x00},
  226. {0x3885, 0x08},
  227. {0x3893, 0x68},
  228. {0x3894, 0x2a},
  229. {0x3898, 0x00},
  230. {0x3899, 0x31},
  231. {0x389a, 0x04},
  232. {0x389b, 0x00},
  233. {0x389c, 0x0b},
  234. {0x389d, 0xad},
  235. {0x389f, 0x08},
  236. {0x38a0, 0x00},
  237. {0x38a1, 0x00},
  238. {0x38a8, 0x70},
  239. {0x38ac, 0xea},
  240. {0x38b2, 0x00},
  241. {0x38b3, 0x08},
  242. {0x38bc, 0x20},
  243. {0x38c4, 0x0c},
  244. {0x38c5, 0x3a},
  245. {0x38c7, 0x3a},
  246. {0x38e1, 0xc0},
  247. {0x38ec, 0x3c},
  248. {0x38f0, 0x09},
  249. {0x38f1, 0x6f},
  250. {0x38fe, 0x3c},
  251. {0x391e, 0x00},
  252. {0x391f, 0x00},
  253. {0x3920, 0xa5},
  254. {0x3921, 0x00},
  255. {0x3922, 0x00},
  256. {0x3923, 0x00},
  257. {0x3924, 0x05},
  258. {0x3925, 0x00},
  259. {0x3926, 0x00},
  260. {0x3927, 0x00},
  261. {0x3928, 0x1a},
  262. {0x3929, 0x01},
  263. {0x392a, 0xb4},
  264. {0x392b, 0x00},
  265. {0x392c, 0x10},
  266. {0x392f, 0x40},
  267. {0x4000, 0xcf},
  268. {0x4003, 0x40},
  269. {0x4008, 0x00},
  270. {0x4009, 0x07},
  271. {0x400a, 0x02},
  272. {0x400b, 0x54},
  273. {0x400c, 0x00},
  274. {0x400d, 0x07},
  275. {0x4010, 0xc0},
  276. {0x4012, 0x02},
  277. {0x4014, 0x04},
  278. {0x4015, 0x04},
  279. {0x4017, 0x02},
  280. {0x4042, 0x01},
  281. {0x4306, 0x04},
  282. {0x4307, 0x12},
  283. {0x4509, 0x00},
  284. {0x450b, 0x83},
  285. {0x4604, 0x68},
  286. {0x4608, 0x0a},
  287. {0x4700, 0x06},
  288. {0x4800, 0x64},
  289. {0x481b, 0x3c},
  290. {0x4825, 0x32},
  291. {0x4833, 0x18},
  292. {0x4837, 0x0f},
  293. {0x4850, 0x40},
  294. {0x4860, 0x00},
  295. {0x4861, 0xec},
  296. {0x4864, 0x00},
  297. {0x4883, 0x00},
  298. {0x4888, 0x90},
  299. {0x4889, 0x05},
  300. {0x488b, 0x04},
  301. {0x4f00, 0x04},
  302. {0x4f10, 0x04},
  303. {0x4f21, 0x01},
  304. {0x4f22, 0x40},
  305. {0x4f23, 0x44},
  306. {0x4f24, 0x51},
  307. {0x4f25, 0x41},
  308. {0x5000, 0x1f},
  309. {0x500a, 0x00},
  310. {0x5100, 0x00},
  311. {0x5111, 0x20},
  312. {0x3020, 0x20},
  313. {0x3613, 0x03},
  314. {0x38c9, 0x02},
  315. {0x5304, 0x01},
  316. {0x3620, 0x08},
  317. {0x3639, 0x58},
  318. {0x363a, 0x10},
  319. {0x3674, 0x04},
  320. {0x3780, 0xff},
  321. {0x3781, 0xff},
  322. {0x3782, 0x00},
  323. {0x3783, 0x01},
  324. {0x3798, 0xa3},
  325. {0x37aa, 0x10},
  326. {0x38a8, 0xf0},
  327. {0x38c4, 0x09},
  328. {0x38c5, 0xb0},
  329. {0x38df, 0x80},
  330. {0x38ff, 0x05},
  331. {0x4010, 0xf1},
  332. {0x4011, 0x70},
  333. {0x3667, 0x80},
  334. {0x4d00, 0x4a},
  335. {0x4d01, 0x18},
  336. {0x4d02, 0xbb},
  337. {0x4d03, 0xde},
  338. {0x4d04, 0x93},
  339. {0x4d05, 0xff},
  340. {0x4d09, 0x0a},
  341. {0x37aa, 0x16},
  342. {0x3606, 0x42},
  343. {0x3605, 0x00},
  344. {0x36a2, 0x17},
  345. {0x300d, 0x0a},
  346. {0x4d00, 0x4d},
  347. {0x4d01, 0x95},
  348. {0x3d8C, 0x70},
  349. {0x3d8d, 0xE9},
  350. {0x5300, 0x00},
  351. {0x5301, 0x10},
  352. {0x5302, 0x00},
  353. {0x5303, 0xE3},
  354. {0x3d88, 0x00},
  355. {0x3d89, 0x10},
  356. {0x3d8a, 0x00},
  357. {0x3d8b, 0xE3},
  358. {0x4f22, 0x00},
  359. };
  360. static const char * const og01a1b_test_pattern_menu[] = {
  361. "Disabled",
  362. "Standard Color Bar",
  363. "Top-Bottom Darker Color Bar",
  364. "Right-Left Darker Color Bar",
  365. "Bottom-Top Darker Color Bar"
  366. };
  367. static const s64 link_freq_menu_items[] = {
  368. OG01A1B_LINK_FREQ_500MHZ,
  369. };
  370. static const struct og01a1b_link_freq_config link_freq_configs[] = {
  371. [OG01A1B_LINK_FREQ_1000MBPS] = {
  372. .reg_list = {
  373. .num_of_regs = ARRAY_SIZE(mipi_data_rate_1000mbps),
  374. .regs = mipi_data_rate_1000mbps,
  375. }
  376. }
  377. };
  378. static const struct og01a1b_mode supported_modes[] = {
  379. {
  380. .width = 1280,
  381. .height = 1024,
  382. .hts = 848,
  383. .vts_def = OG01A1B_VTS_120FPS,
  384. .vts_min = OG01A1B_VTS_120FPS_MIN,
  385. .reg_list = {
  386. .num_of_regs = ARRAY_SIZE(mode_1280x1024_regs),
  387. .regs = mode_1280x1024_regs,
  388. },
  389. .link_freq_index = OG01A1B_LINK_FREQ_1000MBPS,
  390. },
  391. };
  392. struct og01a1b {
  393. struct device *dev;
  394. struct clk *xvclk;
  395. struct gpio_desc *reset_gpio;
  396. struct regulator *avdd;
  397. struct regulator *dovdd;
  398. struct regulator *dvdd;
  399. struct v4l2_subdev sd;
  400. struct media_pad pad;
  401. struct v4l2_ctrl_handler ctrl_handler;
  402. /* V4L2 Controls */
  403. struct v4l2_ctrl *link_freq;
  404. struct v4l2_ctrl *pixel_rate;
  405. struct v4l2_ctrl *vblank;
  406. struct v4l2_ctrl *hblank;
  407. struct v4l2_ctrl *exposure;
  408. /* Current mode */
  409. const struct og01a1b_mode *cur_mode;
  410. /* To serialize asynchronus callbacks */
  411. struct mutex mutex;
  412. };
  413. static u64 to_pixel_rate(u32 f_index)
  414. {
  415. u64 pixel_rate = link_freq_menu_items[f_index] * 2 * OG01A1B_DATA_LANES;
  416. do_div(pixel_rate, OG01A1B_RGB_DEPTH);
  417. return pixel_rate;
  418. }
  419. static u64 to_pixels_per_line(u32 hts, u32 f_index)
  420. {
  421. u64 ppl = hts * to_pixel_rate(f_index);
  422. do_div(ppl, OG01A1B_SCLK);
  423. return ppl;
  424. }
  425. static int og01a1b_read_reg(struct og01a1b *og01a1b, u16 reg, u16 len, u32 *val)
  426. {
  427. struct i2c_client *client = v4l2_get_subdevdata(&og01a1b->sd);
  428. struct i2c_msg msgs[2];
  429. u8 addr_buf[2];
  430. u8 data_buf[4] = {0};
  431. int ret;
  432. if (len > 4)
  433. return -EINVAL;
  434. put_unaligned_be16(reg, addr_buf);
  435. msgs[0].addr = client->addr;
  436. msgs[0].flags = 0;
  437. msgs[0].len = sizeof(addr_buf);
  438. msgs[0].buf = addr_buf;
  439. msgs[1].addr = client->addr;
  440. msgs[1].flags = I2C_M_RD;
  441. msgs[1].len = len;
  442. msgs[1].buf = &data_buf[4 - len];
  443. ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
  444. if (ret != ARRAY_SIZE(msgs))
  445. return -EIO;
  446. *val = get_unaligned_be32(data_buf);
  447. return 0;
  448. }
  449. static int og01a1b_write_reg(struct og01a1b *og01a1b, u16 reg, u16 len, u32 val)
  450. {
  451. struct i2c_client *client = v4l2_get_subdevdata(&og01a1b->sd);
  452. u8 buf[6];
  453. if (len > 4)
  454. return -EINVAL;
  455. put_unaligned_be16(reg, buf);
  456. put_unaligned_be32(val << 8 * (4 - len), buf + 2);
  457. if (i2c_master_send(client, buf, len + 2) != len + 2)
  458. return -EIO;
  459. return 0;
  460. }
  461. static int og01a1b_write_reg_list(struct og01a1b *og01a1b,
  462. const struct og01a1b_reg_list *r_list)
  463. {
  464. unsigned int i;
  465. int ret;
  466. for (i = 0; i < r_list->num_of_regs; i++) {
  467. ret = og01a1b_write_reg(og01a1b, r_list->regs[i].address, 1,
  468. r_list->regs[i].val);
  469. if (ret) {
  470. dev_err_ratelimited(og01a1b->dev,
  471. "failed to write reg 0x%4.4x. error = %d",
  472. r_list->regs[i].address, ret);
  473. return ret;
  474. }
  475. }
  476. return 0;
  477. }
  478. static int og01a1b_test_pattern(struct og01a1b *og01a1b, u32 pattern)
  479. {
  480. if (pattern)
  481. pattern = (pattern - 1) << OG01A1B_TEST_PATTERN_BAR_SHIFT |
  482. OG01A1B_TEST_PATTERN_ENABLE;
  483. return og01a1b_write_reg(og01a1b, OG01A1B_REG_TEST_PATTERN,
  484. OG01A1B_REG_VALUE_08BIT, pattern);
  485. }
  486. static int og01a1b_set_ctrl(struct v4l2_ctrl *ctrl)
  487. {
  488. struct og01a1b *og01a1b = container_of(ctrl->handler,
  489. struct og01a1b, ctrl_handler);
  490. s64 exposure_max;
  491. int ret = 0;
  492. /* Propagate change of current control to all related controls */
  493. if (ctrl->id == V4L2_CID_VBLANK) {
  494. /* Update max exposure while meeting expected vblanking */
  495. exposure_max = og01a1b->cur_mode->height + ctrl->val -
  496. OG01A1B_EXPOSURE_MAX_MARGIN;
  497. __v4l2_ctrl_modify_range(og01a1b->exposure,
  498. og01a1b->exposure->minimum,
  499. exposure_max, og01a1b->exposure->step,
  500. exposure_max);
  501. }
  502. /* V4L2 controls values will be applied only when power is already up */
  503. if (!pm_runtime_get_if_in_use(og01a1b->dev))
  504. return 0;
  505. switch (ctrl->id) {
  506. case V4L2_CID_ANALOGUE_GAIN:
  507. ret = og01a1b_write_reg(og01a1b, OG01A1B_REG_ANALOG_GAIN,
  508. OG01A1B_REG_VALUE_16BIT,
  509. ctrl->val << 4);
  510. break;
  511. case V4L2_CID_DIGITAL_GAIN:
  512. ret = og01a1b_write_reg(og01a1b, OG01A1B_REG_DIG_GAIN,
  513. OG01A1B_REG_VALUE_24BIT,
  514. ctrl->val << 6);
  515. break;
  516. case V4L2_CID_EXPOSURE:
  517. ret = og01a1b_write_reg(og01a1b, OG01A1B_REG_EXPOSURE,
  518. OG01A1B_REG_VALUE_16BIT, ctrl->val);
  519. break;
  520. case V4L2_CID_VBLANK:
  521. ret = og01a1b_write_reg(og01a1b, OG01A1B_REG_VTS,
  522. OG01A1B_REG_VALUE_16BIT,
  523. og01a1b->cur_mode->height + ctrl->val);
  524. break;
  525. case V4L2_CID_TEST_PATTERN:
  526. ret = og01a1b_test_pattern(og01a1b, ctrl->val);
  527. break;
  528. default:
  529. ret = -EINVAL;
  530. break;
  531. }
  532. pm_runtime_put(og01a1b->dev);
  533. return ret;
  534. }
  535. static const struct v4l2_ctrl_ops og01a1b_ctrl_ops = {
  536. .s_ctrl = og01a1b_set_ctrl,
  537. };
  538. static int og01a1b_init_controls(struct og01a1b *og01a1b)
  539. {
  540. struct v4l2_ctrl_handler *ctrl_hdlr;
  541. s64 exposure_max, h_blank;
  542. int ret;
  543. ctrl_hdlr = &og01a1b->ctrl_handler;
  544. ret = v4l2_ctrl_handler_init(ctrl_hdlr, 8);
  545. if (ret)
  546. return ret;
  547. ctrl_hdlr->lock = &og01a1b->mutex;
  548. og01a1b->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr,
  549. &og01a1b_ctrl_ops,
  550. V4L2_CID_LINK_FREQ,
  551. ARRAY_SIZE
  552. (link_freq_menu_items) - 1,
  553. 0, link_freq_menu_items);
  554. if (og01a1b->link_freq)
  555. og01a1b->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
  556. og01a1b->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &og01a1b_ctrl_ops,
  557. V4L2_CID_PIXEL_RATE, 0,
  558. to_pixel_rate
  559. (OG01A1B_LINK_FREQ_1000MBPS),
  560. 1,
  561. to_pixel_rate
  562. (OG01A1B_LINK_FREQ_1000MBPS));
  563. og01a1b->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &og01a1b_ctrl_ops,
  564. V4L2_CID_VBLANK,
  565. og01a1b->cur_mode->vts_min -
  566. og01a1b->cur_mode->height,
  567. OG01A1B_VTS_MAX -
  568. og01a1b->cur_mode->height, 1,
  569. og01a1b->cur_mode->vts_def -
  570. og01a1b->cur_mode->height);
  571. h_blank = to_pixels_per_line(og01a1b->cur_mode->hts,
  572. og01a1b->cur_mode->link_freq_index) -
  573. og01a1b->cur_mode->width;
  574. og01a1b->hblank = v4l2_ctrl_new_std(ctrl_hdlr, &og01a1b_ctrl_ops,
  575. V4L2_CID_HBLANK, h_blank, h_blank,
  576. 1, h_blank);
  577. if (og01a1b->hblank)
  578. og01a1b->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
  579. v4l2_ctrl_new_std(ctrl_hdlr, &og01a1b_ctrl_ops, V4L2_CID_ANALOGUE_GAIN,
  580. OG01A1B_ANAL_GAIN_MIN, OG01A1B_ANAL_GAIN_MAX,
  581. OG01A1B_ANAL_GAIN_STEP, OG01A1B_ANAL_GAIN_MIN);
  582. v4l2_ctrl_new_std(ctrl_hdlr, &og01a1b_ctrl_ops, V4L2_CID_DIGITAL_GAIN,
  583. OG01A1B_DGTL_GAIN_MIN, OG01A1B_DGTL_GAIN_MAX,
  584. OG01A1B_DGTL_GAIN_STEP, OG01A1B_DGTL_GAIN_DEFAULT);
  585. exposure_max = (og01a1b->cur_mode->vts_def -
  586. OG01A1B_EXPOSURE_MAX_MARGIN);
  587. og01a1b->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &og01a1b_ctrl_ops,
  588. V4L2_CID_EXPOSURE,
  589. OG01A1B_EXPOSURE_MIN,
  590. exposure_max,
  591. OG01A1B_EXPOSURE_STEP,
  592. exposure_max);
  593. v4l2_ctrl_new_std_menu_items(ctrl_hdlr, &og01a1b_ctrl_ops,
  594. V4L2_CID_TEST_PATTERN,
  595. ARRAY_SIZE(og01a1b_test_pattern_menu) - 1,
  596. 0, 0, og01a1b_test_pattern_menu);
  597. if (ctrl_hdlr->error)
  598. return ctrl_hdlr->error;
  599. og01a1b->sd.ctrl_handler = ctrl_hdlr;
  600. return 0;
  601. }
  602. static void og01a1b_update_pad_format(const struct og01a1b_mode *mode,
  603. struct v4l2_mbus_framefmt *fmt)
  604. {
  605. fmt->width = mode->width;
  606. fmt->height = mode->height;
  607. fmt->code = MEDIA_BUS_FMT_Y10_1X10;
  608. fmt->field = V4L2_FIELD_NONE;
  609. }
  610. static int og01a1b_start_streaming(struct og01a1b *og01a1b)
  611. {
  612. const struct og01a1b_reg_list *reg_list;
  613. int link_freq_index, ret;
  614. link_freq_index = og01a1b->cur_mode->link_freq_index;
  615. reg_list = &link_freq_configs[link_freq_index].reg_list;
  616. ret = og01a1b_write_reg_list(og01a1b, reg_list);
  617. if (ret) {
  618. dev_err(og01a1b->dev, "failed to set plls");
  619. return ret;
  620. }
  621. reg_list = &og01a1b->cur_mode->reg_list;
  622. ret = og01a1b_write_reg_list(og01a1b, reg_list);
  623. if (ret) {
  624. dev_err(og01a1b->dev, "failed to set mode");
  625. return ret;
  626. }
  627. ret = __v4l2_ctrl_handler_setup(og01a1b->sd.ctrl_handler);
  628. if (ret)
  629. return ret;
  630. ret = og01a1b_write_reg(og01a1b, OG01A1B_REG_MODE_SELECT,
  631. OG01A1B_REG_VALUE_08BIT,
  632. OG01A1B_MODE_STREAMING);
  633. if (ret) {
  634. dev_err(og01a1b->dev, "failed to set stream");
  635. return ret;
  636. }
  637. return 0;
  638. }
  639. static void og01a1b_stop_streaming(struct og01a1b *og01a1b)
  640. {
  641. if (og01a1b_write_reg(og01a1b, OG01A1B_REG_MODE_SELECT,
  642. OG01A1B_REG_VALUE_08BIT, OG01A1B_MODE_STANDBY))
  643. dev_err(og01a1b->dev, "failed to set stream");
  644. }
  645. static int og01a1b_set_stream(struct v4l2_subdev *sd, int enable)
  646. {
  647. struct og01a1b *og01a1b = to_og01a1b(sd);
  648. int ret = 0;
  649. mutex_lock(&og01a1b->mutex);
  650. if (enable) {
  651. ret = pm_runtime_resume_and_get(og01a1b->dev);
  652. if (ret) {
  653. mutex_unlock(&og01a1b->mutex);
  654. return ret;
  655. }
  656. ret = og01a1b_start_streaming(og01a1b);
  657. if (ret) {
  658. enable = 0;
  659. og01a1b_stop_streaming(og01a1b);
  660. pm_runtime_put(og01a1b->dev);
  661. }
  662. } else {
  663. og01a1b_stop_streaming(og01a1b);
  664. pm_runtime_put(og01a1b->dev);
  665. }
  666. mutex_unlock(&og01a1b->mutex);
  667. return ret;
  668. }
  669. static int og01a1b_set_format(struct v4l2_subdev *sd,
  670. struct v4l2_subdev_state *sd_state,
  671. struct v4l2_subdev_format *fmt)
  672. {
  673. struct og01a1b *og01a1b = to_og01a1b(sd);
  674. const struct og01a1b_mode *mode;
  675. s32 vblank_def, h_blank;
  676. mode = v4l2_find_nearest_size(supported_modes,
  677. ARRAY_SIZE(supported_modes), width,
  678. height, fmt->format.width,
  679. fmt->format.height);
  680. mutex_lock(&og01a1b->mutex);
  681. og01a1b_update_pad_format(mode, &fmt->format);
  682. if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
  683. *v4l2_subdev_state_get_format(sd_state, fmt->pad) = fmt->format;
  684. } else {
  685. og01a1b->cur_mode = mode;
  686. __v4l2_ctrl_s_ctrl(og01a1b->link_freq, mode->link_freq_index);
  687. __v4l2_ctrl_s_ctrl_int64(og01a1b->pixel_rate,
  688. to_pixel_rate(mode->link_freq_index));
  689. /* Update limits and set FPS to default */
  690. vblank_def = mode->vts_def - mode->height;
  691. __v4l2_ctrl_modify_range(og01a1b->vblank,
  692. mode->vts_min - mode->height,
  693. OG01A1B_VTS_MAX - mode->height, 1,
  694. vblank_def);
  695. __v4l2_ctrl_s_ctrl(og01a1b->vblank, vblank_def);
  696. h_blank = to_pixels_per_line(mode->hts, mode->link_freq_index) -
  697. mode->width;
  698. __v4l2_ctrl_modify_range(og01a1b->hblank, h_blank, h_blank, 1,
  699. h_blank);
  700. }
  701. mutex_unlock(&og01a1b->mutex);
  702. return 0;
  703. }
  704. static int og01a1b_get_format(struct v4l2_subdev *sd,
  705. struct v4l2_subdev_state *sd_state,
  706. struct v4l2_subdev_format *fmt)
  707. {
  708. struct og01a1b *og01a1b = to_og01a1b(sd);
  709. mutex_lock(&og01a1b->mutex);
  710. if (fmt->which == V4L2_SUBDEV_FORMAT_TRY)
  711. fmt->format = *v4l2_subdev_state_get_format(sd_state,
  712. fmt->pad);
  713. else
  714. og01a1b_update_pad_format(og01a1b->cur_mode, &fmt->format);
  715. mutex_unlock(&og01a1b->mutex);
  716. return 0;
  717. }
  718. static int og01a1b_enum_mbus_code(struct v4l2_subdev *sd,
  719. struct v4l2_subdev_state *sd_state,
  720. struct v4l2_subdev_mbus_code_enum *code)
  721. {
  722. if (code->index > 0)
  723. return -EINVAL;
  724. code->code = MEDIA_BUS_FMT_Y10_1X10;
  725. return 0;
  726. }
  727. static int og01a1b_enum_frame_size(struct v4l2_subdev *sd,
  728. struct v4l2_subdev_state *sd_state,
  729. struct v4l2_subdev_frame_size_enum *fse)
  730. {
  731. if (fse->index >= ARRAY_SIZE(supported_modes))
  732. return -EINVAL;
  733. if (fse->code != MEDIA_BUS_FMT_Y10_1X10)
  734. return -EINVAL;
  735. fse->min_width = supported_modes[fse->index].width;
  736. fse->max_width = fse->min_width;
  737. fse->min_height = supported_modes[fse->index].height;
  738. fse->max_height = fse->min_height;
  739. return 0;
  740. }
  741. static int og01a1b_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
  742. {
  743. struct og01a1b *og01a1b = to_og01a1b(sd);
  744. mutex_lock(&og01a1b->mutex);
  745. og01a1b_update_pad_format(&supported_modes[0],
  746. v4l2_subdev_state_get_format(fh->state, 0));
  747. mutex_unlock(&og01a1b->mutex);
  748. return 0;
  749. }
  750. static const struct v4l2_subdev_video_ops og01a1b_video_ops = {
  751. .s_stream = og01a1b_set_stream,
  752. };
  753. static const struct v4l2_subdev_pad_ops og01a1b_pad_ops = {
  754. .set_fmt = og01a1b_set_format,
  755. .get_fmt = og01a1b_get_format,
  756. .enum_mbus_code = og01a1b_enum_mbus_code,
  757. .enum_frame_size = og01a1b_enum_frame_size,
  758. };
  759. static const struct v4l2_subdev_ops og01a1b_subdev_ops = {
  760. .video = &og01a1b_video_ops,
  761. .pad = &og01a1b_pad_ops,
  762. };
  763. static const struct media_entity_operations og01a1b_subdev_entity_ops = {
  764. .link_validate = v4l2_subdev_link_validate,
  765. };
  766. static const struct v4l2_subdev_internal_ops og01a1b_internal_ops = {
  767. .open = og01a1b_open,
  768. };
  769. static int og01a1b_identify_module(struct og01a1b *og01a1b)
  770. {
  771. int ret;
  772. u32 val;
  773. ret = og01a1b_read_reg(og01a1b, OG01A1B_REG_CHIP_ID,
  774. OG01A1B_REG_VALUE_24BIT, &val);
  775. if (ret)
  776. return ret;
  777. if (val != OG01A1B_CHIP_ID) {
  778. dev_err(og01a1b->dev, "chip id mismatch: %x!=%x",
  779. OG01A1B_CHIP_ID, val);
  780. return -ENXIO;
  781. }
  782. return 0;
  783. }
  784. static int og01a1b_check_hwcfg(struct og01a1b *og01a1b)
  785. {
  786. struct device *dev = og01a1b->dev;
  787. struct fwnode_handle *ep;
  788. struct fwnode_handle *fwnode = dev_fwnode(dev);
  789. struct v4l2_fwnode_endpoint bus_cfg = {
  790. .bus_type = V4L2_MBUS_CSI2_DPHY
  791. };
  792. int ret;
  793. unsigned int i, j;
  794. if (!fwnode)
  795. return -ENXIO;
  796. ep = fwnode_graph_get_next_endpoint(fwnode, NULL);
  797. if (!ep)
  798. return -ENXIO;
  799. ret = v4l2_fwnode_endpoint_alloc_parse(ep, &bus_cfg);
  800. fwnode_handle_put(ep);
  801. if (ret)
  802. return ret;
  803. if (bus_cfg.bus.mipi_csi2.num_data_lanes != OG01A1B_DATA_LANES) {
  804. dev_err(dev, "number of CSI2 data lanes %d is not supported",
  805. bus_cfg.bus.mipi_csi2.num_data_lanes);
  806. ret = -EINVAL;
  807. goto check_hwcfg_error;
  808. }
  809. if (!bus_cfg.nr_of_link_frequencies) {
  810. dev_err(dev, "no link frequencies defined");
  811. ret = -EINVAL;
  812. goto check_hwcfg_error;
  813. }
  814. for (i = 0; i < ARRAY_SIZE(link_freq_menu_items); i++) {
  815. for (j = 0; j < bus_cfg.nr_of_link_frequencies; j++) {
  816. if (link_freq_menu_items[i] ==
  817. bus_cfg.link_frequencies[j])
  818. break;
  819. }
  820. if (j == bus_cfg.nr_of_link_frequencies) {
  821. dev_err(dev, "no link frequency %lld supported",
  822. link_freq_menu_items[i]);
  823. ret = -EINVAL;
  824. goto check_hwcfg_error;
  825. }
  826. }
  827. check_hwcfg_error:
  828. v4l2_fwnode_endpoint_free(&bus_cfg);
  829. return ret;
  830. }
  831. /* Power/clock management functions */
  832. static int og01a1b_power_on(struct device *dev)
  833. {
  834. unsigned long delay = DIV_ROUND_UP(8192UL * USEC_PER_SEC, OG01A1B_MCLK);
  835. struct v4l2_subdev *sd = dev_get_drvdata(dev);
  836. struct og01a1b *og01a1b = to_og01a1b(sd);
  837. int ret;
  838. if (og01a1b->avdd) {
  839. ret = regulator_enable(og01a1b->avdd);
  840. if (ret)
  841. return ret;
  842. }
  843. if (og01a1b->dovdd) {
  844. ret = regulator_enable(og01a1b->dovdd);
  845. if (ret)
  846. goto avdd_disable;
  847. }
  848. if (og01a1b->dvdd) {
  849. ret = regulator_enable(og01a1b->dvdd);
  850. if (ret)
  851. goto dovdd_disable;
  852. }
  853. ret = clk_prepare_enable(og01a1b->xvclk);
  854. if (ret)
  855. goto dvdd_disable;
  856. gpiod_set_value_cansleep(og01a1b->reset_gpio, 0);
  857. if (og01a1b->reset_gpio)
  858. usleep_range(5 * USEC_PER_MSEC, 6 * USEC_PER_MSEC);
  859. else if (og01a1b->xvclk)
  860. usleep_range(delay, 2 * delay);
  861. return 0;
  862. dvdd_disable:
  863. if (og01a1b->dvdd)
  864. regulator_disable(og01a1b->dvdd);
  865. dovdd_disable:
  866. if (og01a1b->dovdd)
  867. regulator_disable(og01a1b->dovdd);
  868. avdd_disable:
  869. if (og01a1b->avdd)
  870. regulator_disable(og01a1b->avdd);
  871. return ret;
  872. }
  873. static int og01a1b_power_off(struct device *dev)
  874. {
  875. unsigned long delay = DIV_ROUND_UP(512 * USEC_PER_SEC, OG01A1B_MCLK);
  876. struct v4l2_subdev *sd = dev_get_drvdata(dev);
  877. struct og01a1b *og01a1b = to_og01a1b(sd);
  878. if (og01a1b->xvclk)
  879. usleep_range(delay, 2 * delay);
  880. clk_disable_unprepare(og01a1b->xvclk);
  881. gpiod_set_value_cansleep(og01a1b->reset_gpio, 1);
  882. if (og01a1b->dvdd)
  883. regulator_disable(og01a1b->dvdd);
  884. if (og01a1b->dovdd)
  885. regulator_disable(og01a1b->dovdd);
  886. if (og01a1b->avdd)
  887. regulator_disable(og01a1b->avdd);
  888. return 0;
  889. }
  890. static void og01a1b_remove(struct i2c_client *client)
  891. {
  892. struct v4l2_subdev *sd = i2c_get_clientdata(client);
  893. struct og01a1b *og01a1b = to_og01a1b(sd);
  894. v4l2_async_unregister_subdev(sd);
  895. media_entity_cleanup(&sd->entity);
  896. v4l2_ctrl_handler_free(sd->ctrl_handler);
  897. pm_runtime_disable(og01a1b->dev);
  898. mutex_destroy(&og01a1b->mutex);
  899. }
  900. static int og01a1b_probe(struct i2c_client *client)
  901. {
  902. struct og01a1b *og01a1b;
  903. unsigned long freq;
  904. int ret;
  905. og01a1b = devm_kzalloc(&client->dev, sizeof(*og01a1b), GFP_KERNEL);
  906. if (!og01a1b)
  907. return -ENOMEM;
  908. og01a1b->dev = &client->dev;
  909. v4l2_i2c_subdev_init(&og01a1b->sd, client, &og01a1b_subdev_ops);
  910. og01a1b->xvclk = devm_v4l2_sensor_clk_get(og01a1b->dev, NULL);
  911. if (IS_ERR(og01a1b->xvclk))
  912. return dev_err_probe(og01a1b->dev, PTR_ERR(og01a1b->xvclk),
  913. "failed to get xvclk clock\n");
  914. freq = clk_get_rate(og01a1b->xvclk);
  915. if (freq != OG01A1B_MCLK)
  916. return dev_err_probe(og01a1b->dev, -EINVAL,
  917. "external clock %lu is not supported",
  918. freq);
  919. ret = og01a1b_check_hwcfg(og01a1b);
  920. if (ret) {
  921. dev_err(og01a1b->dev, "failed to check HW configuration: %d",
  922. ret);
  923. return ret;
  924. }
  925. og01a1b->reset_gpio = devm_gpiod_get_optional(og01a1b->dev, "reset",
  926. GPIOD_OUT_LOW);
  927. if (IS_ERR(og01a1b->reset_gpio)) {
  928. dev_err(og01a1b->dev, "cannot get reset GPIO\n");
  929. return PTR_ERR(og01a1b->reset_gpio);
  930. }
  931. og01a1b->avdd = devm_regulator_get_optional(og01a1b->dev, "avdd");
  932. if (IS_ERR(og01a1b->avdd)) {
  933. ret = PTR_ERR(og01a1b->avdd);
  934. if (ret != -ENODEV) {
  935. dev_err_probe(og01a1b->dev, ret,
  936. "Failed to get 'avdd' regulator\n");
  937. return ret;
  938. }
  939. og01a1b->avdd = NULL;
  940. }
  941. og01a1b->dovdd = devm_regulator_get_optional(og01a1b->dev, "dovdd");
  942. if (IS_ERR(og01a1b->dovdd)) {
  943. ret = PTR_ERR(og01a1b->dovdd);
  944. if (ret != -ENODEV) {
  945. dev_err_probe(og01a1b->dev, ret,
  946. "Failed to get 'dovdd' regulator\n");
  947. return ret;
  948. }
  949. og01a1b->dovdd = NULL;
  950. }
  951. og01a1b->dvdd = devm_regulator_get_optional(og01a1b->dev, "dvdd");
  952. if (IS_ERR(og01a1b->dvdd)) {
  953. ret = PTR_ERR(og01a1b->dvdd);
  954. if (ret != -ENODEV) {
  955. dev_err_probe(og01a1b->dev, ret,
  956. "Failed to get 'dvdd' regulator\n");
  957. return ret;
  958. }
  959. og01a1b->dvdd = NULL;
  960. }
  961. /* The sensor must be powered on to read the CHIP_ID register */
  962. ret = og01a1b_power_on(og01a1b->dev);
  963. if (ret)
  964. return ret;
  965. ret = og01a1b_identify_module(og01a1b);
  966. if (ret) {
  967. dev_err(og01a1b->dev, "failed to find sensor: %d", ret);
  968. goto power_off;
  969. }
  970. mutex_init(&og01a1b->mutex);
  971. og01a1b->cur_mode = &supported_modes[0];
  972. ret = og01a1b_init_controls(og01a1b);
  973. if (ret) {
  974. dev_err(og01a1b->dev, "failed to init controls: %d", ret);
  975. goto probe_error_v4l2_ctrl_handler_free;
  976. }
  977. og01a1b->sd.internal_ops = &og01a1b_internal_ops;
  978. og01a1b->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
  979. og01a1b->sd.entity.ops = &og01a1b_subdev_entity_ops;
  980. og01a1b->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
  981. og01a1b->pad.flags = MEDIA_PAD_FL_SOURCE;
  982. ret = media_entity_pads_init(&og01a1b->sd.entity, 1, &og01a1b->pad);
  983. if (ret) {
  984. dev_err(og01a1b->dev, "failed to init entity pads: %d", ret);
  985. goto probe_error_v4l2_ctrl_handler_free;
  986. }
  987. ret = v4l2_async_register_subdev_sensor(&og01a1b->sd);
  988. if (ret < 0) {
  989. dev_err(og01a1b->dev, "failed to register V4L2 subdev: %d",
  990. ret);
  991. goto probe_error_media_entity_cleanup;
  992. }
  993. /* Enable runtime PM and turn off the device */
  994. pm_runtime_set_active(og01a1b->dev);
  995. pm_runtime_enable(og01a1b->dev);
  996. pm_runtime_idle(og01a1b->dev);
  997. return 0;
  998. probe_error_media_entity_cleanup:
  999. media_entity_cleanup(&og01a1b->sd.entity);
  1000. probe_error_v4l2_ctrl_handler_free:
  1001. v4l2_ctrl_handler_free(og01a1b->sd.ctrl_handler);
  1002. mutex_destroy(&og01a1b->mutex);
  1003. power_off:
  1004. og01a1b_power_off(og01a1b->dev);
  1005. return ret;
  1006. }
  1007. static const struct dev_pm_ops og01a1b_pm_ops = {
  1008. SET_RUNTIME_PM_OPS(og01a1b_power_off, og01a1b_power_on, NULL)
  1009. };
  1010. #ifdef CONFIG_ACPI
  1011. static const struct acpi_device_id og01a1b_acpi_ids[] = {
  1012. {"OVTI01AC"},
  1013. {}
  1014. };
  1015. MODULE_DEVICE_TABLE(acpi, og01a1b_acpi_ids);
  1016. #endif
  1017. static const struct of_device_id og01a1b_of_match[] = {
  1018. { .compatible = "ovti,og01a1b" },
  1019. { /* sentinel */ }
  1020. };
  1021. MODULE_DEVICE_TABLE(of, og01a1b_of_match);
  1022. static struct i2c_driver og01a1b_i2c_driver = {
  1023. .driver = {
  1024. .name = "og01a1b",
  1025. .pm = &og01a1b_pm_ops,
  1026. .acpi_match_table = ACPI_PTR(og01a1b_acpi_ids),
  1027. .of_match_table = og01a1b_of_match,
  1028. },
  1029. .probe = og01a1b_probe,
  1030. .remove = og01a1b_remove,
  1031. };
  1032. module_i2c_driver(og01a1b_i2c_driver);
  1033. MODULE_AUTHOR("Shawn Tu");
  1034. MODULE_DESCRIPTION("OmniVision OG01A1B sensor driver");
  1035. MODULE_LICENSE("GPL v2");