ov490.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * OmniVision OV490 Camera Driver
  4. *
  5. * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
  6. * Author: Nikhil Devshatwar <nikhil.nd@ti.com>
  7. */
  8. #include <linux/delay.h>
  9. #include <linux/i2c.h>
  10. #include <linux/gpio.h>
  11. #include <linux/init.h>
  12. #include <linux/module.h>
  13. #include <linux/regmap.h>
  14. #include <linux/slab.h>
  15. #include <linux/v4l2-mediabus.h>
  16. #include <linux/videodev2.h>
  17. #include <linux/mutex.h>
  18. #include <linux/delay.h>
  19. #include <media/soc_camera.h>
  20. #include <media/v4l2-async.h>
  21. #include <media/v4l2-common.h>
  22. #include <linux/gpio/consumer.h>
  23. #include <linux/of.h>
  24. #include <linux/of_device.h>
  25. #include <linux/of_graph.h>
  26. #include <media/v4l2-fwnode.h>
  27. #include <media/v4l2-event.h>
  28. #include <media/v4l2-subdev.h>
  29. /* Register definitions */
  30. #define OV490_PID 0x300a
  31. #define OV490_VER 0x300b
  32. #define OV490_BANK_HIGH 0xfffd
  33. #define OV490_BANK_LOW 0xfffe
  34. #define OV490_MIPI_TX_LANE_CTRL2 0x8029202D
  35. #define OV490_MIPI_TX_LANE_CTRL0 0x80292015
  36. #define OV490_SC_RESET1 0x80800011
  37. #define OV490_FW_VER_HIGH 0x80800102
  38. #define OV490_FW_VER_LOW 0x80800103
  39. #define OV490_IMAGE0_CTRL 0x8082000a
  40. #define OV490_IMAGE0_BYTE_INVERT BIT(7)
  41. #define OV490_IMAGE0_BYTE_SEQUENCE GEN_MASK(6, 4)
  42. #define OV490_IMAGE0_BYTE_SEQUENCE_1 BIT(4)
  43. #define OV490_IMAGE0_FORMAT_SELECT GEN_MASK(3, 0)
  44. #define OV490_IMAGE0_FORMAT_PURE_RAW12 0x0
  45. #define OV490_IMAGE0_FORMAT_3X12_RAW 0x2
  46. #define OV490_IMAGE0_FORMAT_2X12_RAW 0x3
  47. #define OV490_IMAGE0_FORMAT_20_COMBINED_RAW 0x4
  48. #define OV490_IMAGE0_FORMAT_16_COMPRESSED_RAW 0x5
  49. #define OV490_IMAGE0_FORMAT_12_COMPRESSED_RAW 0x6
  50. #define OV490_IMAGE0_FORMAT_2X12_COMPRESSED_RAW 0x7
  51. #define OV490_IMAGE0_FORMAT_12_SELECTED_RAW 0x8
  52. #define OV490_IMAGE0_FORMAT_12_YUV422 0xf
  53. /* IDs */
  54. #define OV490_VERSION_REG 0x0490
  55. #define OV490_VERSION(pid, ver) (((pid) << 8) | ((ver) & 0xff))
  56. #define OV490_MAX_WIDTH 1280
  57. #define OV490_MAX_HEIGHT 800
  58. #define MAX_NUM_GPIOS 10
  59. /* Host Command Flow */
  60. #define OV490_STATUS_ADDR (0x80195ffc)
  61. #define OV490_HOST_CMD_PARA_ADDR (0x80195000)
  62. #define OV490_HOST_CMD_RESULT_ADDR (0x80195000)
  63. #define OV490_HOST_INT_ADDR (0x808000c0)
  64. #define OV490_STATUS_FINISH (0x99)
  65. #define OV490_STATUS_ERROR (0x55)
  66. /* Host Command List */
  67. #define OV490_CMD_BRIGHTNESS_SET (0xf1)
  68. #define OV490_CMD_SATURATION_SET (0xf3)
  69. #define OV490_CMD_HUE_SET (0xf5)
  70. #define OV490_CMD_FRAMERATE_SET (0xf7)
  71. #define OV490_CMD_GAMMA_SET (0xf9)
  72. #define OV490_CMD_SHARPNESS_SET (0xfb)
  73. #define OV490_CMD_CONTRAST_SET (0xfd)
  74. #define OV490_CMD_GROUPWRITE_SET (0xe1)
  75. #define OV490_CMD_STREAMING_CTRL (0xe2)
  76. #define OV490_CMD_CONTEXT_SWITCH_CONFIG (0xe3)
  77. #define OV490_CMD_CONTEXT_SWITCH_CTRL (0xe4)
  78. #define OV490_CMD_MULT_CMD (0xe5)
  79. #define OV490_CMD_GPIO_SET (0xe6)
  80. #define OV490_CMD_GPIO_GET (0xe7)
  81. #define OV490_CMD_FORMAT_SET (0xe8)
  82. #define OV490_CMD_TEMP_GET (0xe9)
  83. #define OV490_CMD_EXPOSURE_GAIN_SET (0xea)
  84. #define OV490_CMD_AWBGAIN_SET (0xeb)
  85. #define OV490_CMD_DENOISE_SET (0xec)
  86. #define OV490_CMD_TONECURVE_SET (0xed)
  87. #define OV490_CMD_COMB_WEIGHT_SET (0xee)
  88. #define OV490_CMD_AEC_WEIGHT_SET (0xd2)
  89. #define OV490_CMD_AWB_ROI_SET (0xd3)
  90. #define OV490_CMD_TONEMAPPING_ROI_SET (0xd4)
  91. #define OV490_CMD_STAT_ROI_SET (0xd5)
  92. #define OV490_CMD_TESTPATTERN_SET (0xd6)
  93. #define OV490_CMD_MTF_SET (0xd7)
  94. #define OV490_CMD_LENC_SET (0xd8)
  95. #define OV490_CMD_BLC_SET (0xd9)
  96. #define OV490_CMD_GROUPWRITE_LAUNCH (0xda)
  97. #define OV490_CMD_EMBLINE_CTRL (0xdb)
  98. #define OV490_CMD_MIRRFLIP_CTRL (0xdc)
  99. #define OV490_CMD_EXTRA_VTS_SET (0xde)
  100. #define OV490_CMD_SNR_REG_ACCESS (0xc1)
  101. #define OV490_CMD_POSTAWBGAIN_SET (0xc2)
  102. #define OV490_CMD_CROP_SET (0xc3)
  103. #define OV490_CMD_FRAMESYNC (0xc4)
  104. #define OV490_CMD_BANDING_SET (0xc5)
  105. #define OV490_CMD_TOPEMB_SET (0xc7)
  106. #define OV490_CMD_FWREG_ACCESS (0x35)
  107. #define OV490_CMD_FADE_CTRL (0x37)
  108. #define OV490_CMD_INIT_CTRL (0x39)
  109. #define OV490_CMD_RESET_CTRL (0x3a)
  110. /*
  111. * = fvco / pixel_width * num_lanes
  112. * = 804,000,000 / 16 bits * 4 lanes
  113. */
  114. #define OV490_PIXEL_RATE_PER_LANE 50250000
  115. static u8 ov490_init_param[] = {
  116. 0x31, /* [3:0]input port, [7:4] input format */
  117. 0x01, /* [3:0]output port, [7:4] output format */
  118. 0x05, /* in width: 1288 */
  119. 0x08,
  120. 0x04, /* in height:1080 */
  121. 0x40,
  122. 0x05, /* out width: 1288 */
  123. 0x08,
  124. 0x04, /* out height:1080 */
  125. 0x40,
  126. 0x00,
  127. };
  128. struct ov490_color_format {
  129. u32 code;
  130. u32 colorspace;
  131. };
  132. struct ov490_priv {
  133. struct v4l2_subdev subdev;
  134. struct v4l2_async_subdev asd;
  135. const struct ov490_color_format *cfmt;
  136. int width;
  137. int height;
  138. int num_lanes;
  139. struct regmap *regmap;
  140. struct gpio_descs *mux_gpios;
  141. struct v4l2_ctrl_handler handler;
  142. struct v4l2_ctrl *pixel_rate;
  143. };
  144. /* Main access control */
  145. DEFINE_MUTEX(ov490_lock);
  146. static int ov490_init_gpios(struct i2c_client *client);
  147. /*
  148. * supported color format list
  149. */
  150. static const struct ov490_color_format ov490_cfmts[] = {
  151. {
  152. .code = MEDIA_BUS_FMT_YUYV8_2X8,
  153. .colorspace = V4L2_COLORSPACE_SMPTE170M,
  154. },
  155. };
  156. static struct ov490_priv *to_ov490(const struct i2c_client *client)
  157. {
  158. return container_of(i2c_get_clientdata(client), struct ov490_priv,
  159. subdev);
  160. }
  161. static struct v4l2_subdev *ctrl_to_sd(struct v4l2_ctrl *ctrl)
  162. {
  163. return &container_of(ctrl->handler, struct ov490_priv, handler)->subdev;
  164. }
  165. static int ov490_reg_write32(struct regmap *map, u32 reg, u8 val)
  166. {
  167. u8 bank_high = (reg >> 24) & 0xff;
  168. u8 bank_low = (reg >> 16) & 0xff;
  169. u16 reg_addr = reg & 0xffff;
  170. int ret = 0;
  171. /* For writing a register with 32 bit address, First set the bank
  172. * address by writing to two BANK address registers. Then access
  173. * the register using 16LSB bits.
  174. */
  175. ret = regmap_write(map, OV490_BANK_HIGH, bank_high);
  176. if (!ret)
  177. ret = regmap_write(map, OV490_BANK_LOW, bank_low);
  178. if (!ret)
  179. ret = regmap_write(map, reg_addr, val);
  180. return ret;
  181. }
  182. static int ov490_reg_read32(struct regmap *map, u32 reg, u8 *val)
  183. {
  184. u8 bank_high = (reg >> 24) & 0xff;
  185. u8 bank_low = (reg >> 16) & 0xff;
  186. u16 reg_addr = reg & 0xffff;
  187. int ret = 0;
  188. u32 tval = 0;
  189. /*
  190. * For reading a register with 32 bit address, First set the bank
  191. * address by writing to two BANK address registers. Then access
  192. * the register using 16LSB bits.
  193. */
  194. ret = regmap_write(map, OV490_BANK_HIGH, bank_high);
  195. if (!ret)
  196. ret = regmap_write(map, OV490_BANK_LOW, bank_low);
  197. if (!ret)
  198. ret = regmap_read(map, reg_addr, &tval);
  199. *val = (u8)tval;
  200. return ret;
  201. }
  202. static int ov490_host_control_set(struct regmap *map, u8 host_cmd,
  203. u8 *param, u16 number)
  204. {
  205. int i, ret;
  206. u8 status = 0;
  207. /* Host reset OV490_status_register */
  208. ret = ov490_reg_write32(map, OV490_STATUS_ADDR, 0);
  209. if (ret)
  210. return ret;
  211. for (i = 0; i < number; i++) {
  212. ret = ov490_reg_write32(map, OV490_HOST_CMD_PARA_ADDR + i,
  213. *(param + i));
  214. if (ret)
  215. return ret;
  216. }
  217. ret = ov490_reg_write32(map, OV490_HOST_INT_ADDR, host_cmd);
  218. if (ret)
  219. return ret;
  220. for (i = 500; i && status != OV490_STATUS_FINISH; i--) {
  221. ret = ov490_reg_read32(map, OV490_STATUS_ADDR, &status);
  222. if (ret)
  223. return ret;
  224. usleep_range(500, 1000);
  225. }
  226. if (!i)
  227. return -ETIMEDOUT;
  228. return 0;
  229. }
  230. static int __maybe_unused ov490_host_control_get(struct regmap *map,
  231. u8 host_cmd, u8 *param,
  232. u16 number)
  233. {
  234. int i, ret;
  235. u8 status = 0;
  236. /* Host reset OV490_status_register */
  237. ret = ov490_reg_write32(map, OV490_STATUS_ADDR, 0);
  238. if (ret)
  239. return ret;
  240. ret = ov490_reg_write32(map, OV490_HOST_INT_ADDR, host_cmd);
  241. if (ret)
  242. return ret;
  243. for (i = 500; i && status != OV490_STATUS_FINISH; i--) {
  244. ret = ov490_reg_read32(map, OV490_STATUS_ADDR, &status);
  245. if (ret)
  246. return ret;
  247. usleep_range(500, 1000);
  248. }
  249. if (!i)
  250. return -ETIMEDOUT;
  251. for (i = 0; i < number; i++) {
  252. ret = ov490_reg_read32(map, OV490_HOST_CMD_PARA_ADDR + i,
  253. (param + i));
  254. if (ret)
  255. return ret;
  256. }
  257. return 0;
  258. }
  259. static int ov490_get_fw_version(struct regmap *map, u16 *id)
  260. {
  261. u8 hi, lo;
  262. int ret;
  263. ret = ov490_reg_read32(map, OV490_FW_VER_HIGH, &hi);
  264. if (ret)
  265. return ret;
  266. ret = ov490_reg_read32(map, OV490_FW_VER_LOW, &lo);
  267. if (ret)
  268. return ret;
  269. *id = hi << 8 | lo;
  270. return 0;
  271. }
  272. /* Start/Stop streaming from the device */
  273. static int ov490_s_stream(struct v4l2_subdev *sd, int enable)
  274. {
  275. struct i2c_client *client = v4l2_get_subdevdata(sd);
  276. struct ov490_priv *priv = to_ov490(client);
  277. struct regmap *map = priv->regmap;
  278. int ret, val;
  279. u8 streaming;
  280. mutex_lock(&ov490_lock);
  281. ret = ov490_init_gpios(client);
  282. if (ret) {
  283. dev_err(&client->dev, "Failed to request gpios");
  284. goto unlock;
  285. }
  286. if (!enable) {
  287. streaming = 0;
  288. /* Stop Streaming */
  289. ret = ov490_host_control_set(map, OV490_CMD_STREAMING_CTRL,
  290. &streaming, 1);
  291. if (ret)
  292. goto unlock;
  293. ret = ov490_reg_write32(map, OV490_MIPI_TX_LANE_CTRL0, 0xa0);
  294. if (ret)
  295. goto unlock;
  296. /* Put MIPI_TX in reset */
  297. ret = ov490_reg_write32(map, OV490_SC_RESET1, 0x80);
  298. goto unlock;
  299. }
  300. /* Take MIPI_TX out of reset */
  301. ret = ov490_reg_write32(map, OV490_SC_RESET1, 0x00);
  302. if (ret)
  303. goto unlock;
  304. ret = ov490_reg_write32(map, OV490_MIPI_TX_LANE_CTRL0, 0x80);
  305. if (ret)
  306. goto unlock;
  307. /* Initialize slave */
  308. ret = ov490_host_control_set(map, OV490_CMD_INIT_CTRL, ov490_init_param,
  309. ARRAY_SIZE(ov490_init_param));
  310. if (ret)
  311. goto unlock;
  312. ret = ov490_reg_write32(map, OV490_IMAGE0_CTRL,
  313. OV490_IMAGE0_BYTE_INVERT |
  314. OV490_IMAGE0_BYTE_SEQUENCE_1 |
  315. OV490_IMAGE0_FORMAT_3X12_RAW);
  316. if (ret)
  317. goto unlock;
  318. /* Set number of data lane to use */
  319. val = priv->num_lanes == 2 ? 0x03 : priv->num_lanes == 4 ? 0x0F : 0x0F;
  320. ret = ov490_reg_write32(map, OV490_MIPI_TX_LANE_CTRL2, val);
  321. if (ret)
  322. goto unlock;
  323. /* Start Streaming */
  324. streaming = 0x1;
  325. ret = ov490_host_control_set(map, OV490_CMD_STREAMING_CTRL,
  326. &streaming, 1);
  327. unlock:
  328. mutex_unlock(&ov490_lock);
  329. return ret;
  330. }
  331. static int ov490_get_fmt(struct v4l2_subdev *sd,
  332. struct v4l2_subdev_pad_config *cfg,
  333. struct v4l2_subdev_format *fmt)
  334. {
  335. struct i2c_client *client = v4l2_get_subdevdata(sd);
  336. struct ov490_priv *priv = to_ov490(client);
  337. struct v4l2_mbus_framefmt *mf = &fmt->format;
  338. mf->width = priv->width;
  339. mf->height = priv->height;
  340. mf->code = priv->cfmt->code;
  341. mf->colorspace = priv->cfmt->colorspace;
  342. mf->field = V4L2_FIELD_NONE;
  343. return 0;
  344. }
  345. /* Fixed format - no configurability */
  346. static int ov490_set_fmt(struct v4l2_subdev *sd,
  347. struct v4l2_subdev_pad_config *cfg,
  348. struct v4l2_subdev_format *fmt)
  349. {
  350. struct i2c_client *client = v4l2_get_subdevdata(sd);
  351. struct ov490_priv *priv = to_ov490(client);
  352. struct v4l2_mbus_framefmt *mf = &fmt->format;
  353. mf->width = priv->width;
  354. mf->height = priv->height;
  355. mf->code = priv->cfmt->code;
  356. mf->colorspace = priv->cfmt->colorspace;
  357. mf->field = V4L2_FIELD_NONE;
  358. return 0;
  359. }
  360. static int ov490_enum_code(struct v4l2_subdev *sd,
  361. struct v4l2_subdev_pad_config *cfg,
  362. struct v4l2_subdev_mbus_code_enum *code)
  363. {
  364. if (code->index >= ARRAY_SIZE(ov490_cfmts))
  365. return -EINVAL;
  366. code->code = ov490_cfmts[code->index].code;
  367. return 0;
  368. }
  369. static int ov490_enum_size(struct v4l2_subdev *sd,
  370. struct v4l2_subdev_pad_config *cfg,
  371. struct v4l2_subdev_frame_size_enum *fse)
  372. {
  373. int cam_width[] = { OV490_MAX_WIDTH };
  374. int cam_height[] = { OV490_MAX_HEIGHT };
  375. if (fse->index >= ARRAY_SIZE(cam_width))
  376. return -EINVAL;
  377. fse->min_width = cam_width[fse->index];
  378. fse->max_width = fse->min_width;
  379. fse->min_height = cam_height[fse->index];
  380. fse->max_height = fse->min_height;
  381. return 0;
  382. }
  383. static int ov490_s_ctrl(struct v4l2_ctrl *ctrl)
  384. {
  385. struct v4l2_subdev *sd = ctrl_to_sd(ctrl);
  386. struct i2c_client *client = v4l2_get_subdevdata(sd);
  387. /* If the board has programmable pixel clock, set it here */
  388. if (ctrl->id == V4L2_CID_PIXEL_RATE)
  389. dev_info(&client->dev, "Pixel rate set to %d\n",
  390. ctrl->val);
  391. return 0;
  392. }
  393. static int ov490_init_gpios(struct i2c_client *client)
  394. {
  395. struct ov490_priv *priv = to_ov490(client);
  396. int ret = 0;
  397. /* Request the gpio lines and set the values
  398. * then release them so that other drivers can use them
  399. * This allows changing common board muxes which are
  400. * controlled by multiple drivers
  401. */
  402. priv->mux_gpios = gpiod_get_array(&client->dev, "mux", GPIOD_OUT_HIGH);
  403. if (IS_ERR(priv->mux_gpios))
  404. goto done;
  405. gpiod_put_array(priv->mux_gpios);
  406. done:
  407. return ret;
  408. }
  409. static int ov490_video_probe(struct i2c_client *client)
  410. {
  411. struct ov490_priv *priv = i2c_get_clientdata(client);
  412. u32 pid, ver;
  413. int ret;
  414. u16 version;
  415. /* check and show product ID and manufacturer ID */
  416. ret = regmap_read(priv->regmap, OV490_PID, &pid);
  417. if (ret)
  418. return ret;
  419. ret = regmap_read(priv->regmap, OV490_VER, &ver);
  420. if (ret)
  421. return ret;
  422. if (OV490_VERSION(pid, ver) != OV490_VERSION_REG) {
  423. dev_err(&client->dev, "Product ID error %02x:%02x\n", pid, ver);
  424. return -ENODEV;
  425. }
  426. dev_info(&client->dev, "ov490 Product ID %02x Manufacturer ID %02x\n",
  427. pid, ver);
  428. ret = ov490_get_fw_version(priv->regmap, &version);
  429. if (ret)
  430. return ret;
  431. dev_info(&client->dev, "ov490 Firmware ID 0x%04x\n", version);
  432. return 0;
  433. }
  434. static const struct v4l2_subdev_video_ops ov490_video_ops = {
  435. .s_stream = ov490_s_stream,
  436. };
  437. static const struct v4l2_subdev_core_ops ov490_core_ops = {
  438. .log_status = v4l2_ctrl_subdev_log_status,
  439. .subscribe_event = v4l2_ctrl_subdev_subscribe_event,
  440. .unsubscribe_event = v4l2_event_subdev_unsubscribe,
  441. };
  442. static const struct v4l2_subdev_pad_ops ov490_pad_ops = {
  443. .enum_mbus_code = ov490_enum_code,
  444. .enum_frame_size = ov490_enum_size,
  445. .get_fmt = ov490_get_fmt,
  446. .set_fmt = ov490_set_fmt,
  447. };
  448. static const struct v4l2_subdev_ops ov490_subdev_ops = {
  449. .video = &ov490_video_ops,
  450. .core = &ov490_core_ops,
  451. .pad = &ov490_pad_ops,
  452. };
  453. static const struct v4l2_ctrl_ops ov490_ctrl_ops = {
  454. .s_ctrl = ov490_s_ctrl,
  455. };
  456. static const struct regmap_config ov490_regmap_config = {
  457. .reg_bits = 16,
  458. .val_bits = 8,
  459. };
  460. /*
  461. * i2c_driver function
  462. */
  463. static int ov490_of_probe(struct i2c_client *client,
  464. struct device_node *node)
  465. {
  466. struct ov490_priv *priv = to_ov490(client);
  467. struct v4l2_fwnode_endpoint endpoint = {};
  468. struct device_node *ep;
  469. int num_lanes = 0;
  470. ep = of_graph_get_next_endpoint(node, NULL);
  471. if (ep) {
  472. v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep), &endpoint);
  473. if (endpoint.bus_type == V4L2_MBUS_CSI2) {
  474. num_lanes = endpoint.bus.mipi_csi2.num_data_lanes;
  475. if (num_lanes == 2 || num_lanes == 4)
  476. priv->num_lanes = num_lanes;
  477. } else {
  478. dev_err(&client->dev, "Endpoint bus is not CSI bus!");
  479. }
  480. }
  481. dev_info(&client->dev, "Using %d data lanes\n", priv->num_lanes);
  482. return 0;
  483. }
  484. static int ov490_probe(struct i2c_client *client,
  485. const struct i2c_device_id *did)
  486. {
  487. struct device_node *node = client->dev.of_node;
  488. struct v4l2_ctrl_handler *hdl;
  489. struct ov490_priv *priv;
  490. struct v4l2_subdev *sd;
  491. int ret = 0;
  492. priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL);
  493. if (!priv)
  494. return -ENOMEM;
  495. i2c_set_clientdata(client, priv);
  496. priv->num_lanes = 4;
  497. priv->cfmt = &ov490_cfmts[0];
  498. priv->width = OV490_MAX_WIDTH;
  499. priv->height = OV490_MAX_HEIGHT;
  500. priv->regmap = devm_regmap_init_i2c(client, &ov490_regmap_config);
  501. if (IS_ERR(priv->regmap))
  502. return PTR_ERR(priv->regmap);
  503. ret = ov490_video_probe(client);
  504. if (ret)
  505. goto err;
  506. ret = ov490_of_probe(client, node);
  507. if (ret)
  508. goto err;
  509. sd = &priv->subdev;
  510. v4l2_i2c_subdev_init(sd, client, &ov490_subdev_ops);
  511. hdl = &priv->handler;
  512. sd->ctrl_handler = hdl;
  513. v4l2_ctrl_handler_init(hdl, 1);
  514. priv->pixel_rate =
  515. v4l2_ctrl_new_std(hdl, &ov490_ctrl_ops,
  516. V4L2_CID_PIXEL_RATE, 1, INT_MAX, 1,
  517. OV490_PIXEL_RATE_PER_LANE * priv->num_lanes);
  518. if (hdl->error) {
  519. dev_err(&client->dev, "Failed to add controls");
  520. ret = hdl->error;
  521. goto err;
  522. }
  523. ret = ov490_init_gpios(client);
  524. if (ret) {
  525. dev_err(&client->dev, "Failed to request gpios");
  526. goto err;
  527. }
  528. sd->dev = &client->dev;
  529. ret = v4l2_async_register_subdev(sd);
  530. err:
  531. return ret;
  532. }
  533. static int ov490_remove(struct i2c_client *client)
  534. {
  535. struct ov490_priv *priv = i2c_get_clientdata(client);
  536. v4l2_device_unregister_subdev(&priv->subdev);
  537. v4l2_ctrl_handler_free(&priv->handler);
  538. return 0;
  539. }
  540. static const struct i2c_device_id ov490_id[] = {
  541. { "ov490", 0 },
  542. { }
  543. };
  544. MODULE_DEVICE_TABLE(i2c, ov490_id);
  545. static const struct of_device_id ov490_dt_id[] = {
  546. {
  547. .compatible = "ovti,ov490",
  548. },
  549. {
  550. }
  551. };
  552. MODULE_DEVICE_TABLE(of, ov490_dt_id);
  553. static struct i2c_driver ov490_i2c_driver = {
  554. .driver = {
  555. .name = "ov490",
  556. .of_match_table = ov490_dt_id,
  557. },
  558. .probe = ov490_probe,
  559. .remove = ov490_remove,
  560. .id_table = ov490_id,
  561. };
  562. module_i2c_driver(ov490_i2c_driver);
  563. MODULE_DESCRIPTION("SoC Camera driver for OmniVision OV490");
  564. MODULE_AUTHOR("Nikhil Devshatwar <nikhil.nd@ti.com>");
  565. MODULE_LICENSE("GPL v2");