microchip-sama7g5-isc.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Microchip eXtended Image Sensor Controller (XISC) driver
  4. *
  5. * Copyright (C) 2019-2021 Microchip Technology, Inc. and its subsidiaries
  6. *
  7. * Author: Eugen Hristev <eugen.hristev@microchip.com>
  8. *
  9. * Sensor-->PFE-->DPC-->WB-->CFA-->CC-->GAM-->VHXS-->CSC-->CBHS-->SUB-->RLP-->DMA-->HIS
  10. *
  11. * ISC video pipeline integrates the following submodules:
  12. * PFE: Parallel Front End to sample the camera sensor input stream
  13. * DPC: Defective Pixel Correction with black offset correction, green disparity
  14. * correction and defective pixel correction (3 modules total)
  15. * WB: Programmable white balance in the Bayer domain
  16. * CFA: Color filter array interpolation module
  17. * CC: Programmable color correction
  18. * GAM: Gamma correction
  19. *VHXS: Vertical and Horizontal Scaler
  20. * CSC: Programmable color space conversion
  21. *CBHS: Contrast Brightness Hue and Saturation control
  22. * SUB: This module performs YCbCr444 to YCbCr420 chrominance subsampling
  23. * RLP: This module performs rounding, range limiting
  24. * and packing of the incoming data
  25. * DMA: This module performs DMA master accesses to write frames to external RAM
  26. * HIS: Histogram module performs statistic counters on the frames
  27. */
  28. #include <linux/clk.h>
  29. #include <linux/clkdev.h>
  30. #include <linux/clk-provider.h>
  31. #include <linux/delay.h>
  32. #include <linux/interrupt.h>
  33. #include <linux/math64.h>
  34. #include <linux/module.h>
  35. #include <linux/of.h>
  36. #include <linux/of_graph.h>
  37. #include <linux/platform_device.h>
  38. #include <linux/pm_runtime.h>
  39. #include <linux/regmap.h>
  40. #include <linux/videodev2.h>
  41. #include <media/v4l2-ctrls.h>
  42. #include <media/v4l2-device.h>
  43. #include <media/v4l2-event.h>
  44. #include <media/v4l2-image-sizes.h>
  45. #include <media/v4l2-ioctl.h>
  46. #include <media/v4l2-fwnode.h>
  47. #include <media/v4l2-subdev.h>
  48. #include <media/videobuf2-dma-contig.h>
  49. #include "microchip-isc-regs.h"
  50. #include "microchip-isc.h"
  51. #define ISC_SAMA7G5_MAX_SUPPORT_WIDTH 3264
  52. #define ISC_SAMA7G5_MAX_SUPPORT_HEIGHT 2464
  53. #define ISC_SAMA7G5_PIPELINE \
  54. (WB_ENABLE | CFA_ENABLE | CC_ENABLE | GAM_ENABLES | CSC_ENABLE | \
  55. CBC_ENABLE | SUB422_ENABLE | SUB420_ENABLE)
  56. /* This is a list of the formats that the ISC can *output* */
  57. static const struct isc_format sama7g5_controller_formats[] = {
  58. {
  59. .fourcc = V4L2_PIX_FMT_ARGB444,
  60. }, {
  61. .fourcc = V4L2_PIX_FMT_ARGB555,
  62. }, {
  63. .fourcc = V4L2_PIX_FMT_RGB565,
  64. }, {
  65. .fourcc = V4L2_PIX_FMT_ABGR32,
  66. }, {
  67. .fourcc = V4L2_PIX_FMT_XBGR32,
  68. }, {
  69. .fourcc = V4L2_PIX_FMT_YUV420,
  70. }, {
  71. .fourcc = V4L2_PIX_FMT_UYVY,
  72. }, {
  73. .fourcc = V4L2_PIX_FMT_VYUY,
  74. }, {
  75. .fourcc = V4L2_PIX_FMT_YUYV,
  76. }, {
  77. .fourcc = V4L2_PIX_FMT_YUV422P,
  78. }, {
  79. .fourcc = V4L2_PIX_FMT_GREY,
  80. }, {
  81. .fourcc = V4L2_PIX_FMT_Y10,
  82. }, {
  83. .fourcc = V4L2_PIX_FMT_Y16,
  84. }, {
  85. .fourcc = V4L2_PIX_FMT_SBGGR8,
  86. .raw = true,
  87. }, {
  88. .fourcc = V4L2_PIX_FMT_SGBRG8,
  89. .raw = true,
  90. }, {
  91. .fourcc = V4L2_PIX_FMT_SGRBG8,
  92. .raw = true,
  93. }, {
  94. .fourcc = V4L2_PIX_FMT_SRGGB8,
  95. .raw = true,
  96. }, {
  97. .fourcc = V4L2_PIX_FMT_SBGGR10,
  98. .raw = true,
  99. }, {
  100. .fourcc = V4L2_PIX_FMT_SGBRG10,
  101. .raw = true,
  102. }, {
  103. .fourcc = V4L2_PIX_FMT_SGRBG10,
  104. .raw = true,
  105. }, {
  106. .fourcc = V4L2_PIX_FMT_SRGGB10,
  107. .raw = true,
  108. }, {
  109. .fourcc = V4L2_PIX_FMT_SBGGR12,
  110. .raw = true,
  111. }, {
  112. .fourcc = V4L2_PIX_FMT_SGBRG12,
  113. .raw = true,
  114. }, {
  115. .fourcc = V4L2_PIX_FMT_SGRBG12,
  116. .raw = true,
  117. }, {
  118. .fourcc = V4L2_PIX_FMT_SRGGB12,
  119. .raw = true,
  120. },
  121. };
  122. /* This is a list of formats that the ISC can receive as *input* */
  123. static struct isc_format sama7g5_formats_list[] = {
  124. {
  125. .fourcc = V4L2_PIX_FMT_SBGGR8,
  126. .mbus_code = MEDIA_BUS_FMT_SBGGR8_1X8,
  127. .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_EIGHT,
  128. .cfa_baycfg = ISC_BAY_CFG_BGBG,
  129. },
  130. {
  131. .fourcc = V4L2_PIX_FMT_SGBRG8,
  132. .mbus_code = MEDIA_BUS_FMT_SGBRG8_1X8,
  133. .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_EIGHT,
  134. .cfa_baycfg = ISC_BAY_CFG_GBGB,
  135. },
  136. {
  137. .fourcc = V4L2_PIX_FMT_SGRBG8,
  138. .mbus_code = MEDIA_BUS_FMT_SGRBG8_1X8,
  139. .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_EIGHT,
  140. .cfa_baycfg = ISC_BAY_CFG_GRGR,
  141. },
  142. {
  143. .fourcc = V4L2_PIX_FMT_SRGGB8,
  144. .mbus_code = MEDIA_BUS_FMT_SRGGB8_1X8,
  145. .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_EIGHT,
  146. .cfa_baycfg = ISC_BAY_CFG_RGRG,
  147. },
  148. {
  149. .fourcc = V4L2_PIX_FMT_SBGGR10,
  150. .mbus_code = MEDIA_BUS_FMT_SBGGR10_1X10,
  151. .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TEN,
  152. .cfa_baycfg = ISC_BAY_CFG_RGRG,
  153. },
  154. {
  155. .fourcc = V4L2_PIX_FMT_SGBRG10,
  156. .mbus_code = MEDIA_BUS_FMT_SGBRG10_1X10,
  157. .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TEN,
  158. .cfa_baycfg = ISC_BAY_CFG_GBGB,
  159. },
  160. {
  161. .fourcc = V4L2_PIX_FMT_SGRBG10,
  162. .mbus_code = MEDIA_BUS_FMT_SGRBG10_1X10,
  163. .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TEN,
  164. .cfa_baycfg = ISC_BAY_CFG_GRGR,
  165. },
  166. {
  167. .fourcc = V4L2_PIX_FMT_SRGGB10,
  168. .mbus_code = MEDIA_BUS_FMT_SRGGB10_1X10,
  169. .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TEN,
  170. .cfa_baycfg = ISC_BAY_CFG_RGRG,
  171. },
  172. {
  173. .fourcc = V4L2_PIX_FMT_SBGGR12,
  174. .mbus_code = MEDIA_BUS_FMT_SBGGR12_1X12,
  175. .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TWELVE,
  176. .cfa_baycfg = ISC_BAY_CFG_BGBG,
  177. },
  178. {
  179. .fourcc = V4L2_PIX_FMT_SGBRG12,
  180. .mbus_code = MEDIA_BUS_FMT_SGBRG12_1X12,
  181. .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TWELVE,
  182. .cfa_baycfg = ISC_BAY_CFG_GBGB,
  183. },
  184. {
  185. .fourcc = V4L2_PIX_FMT_SGRBG12,
  186. .mbus_code = MEDIA_BUS_FMT_SGRBG12_1X12,
  187. .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TWELVE,
  188. .cfa_baycfg = ISC_BAY_CFG_GRGR,
  189. },
  190. {
  191. .fourcc = V4L2_PIX_FMT_SRGGB12,
  192. .mbus_code = MEDIA_BUS_FMT_SRGGB12_1X12,
  193. .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TWELVE,
  194. .cfa_baycfg = ISC_BAY_CFG_RGRG,
  195. },
  196. {
  197. .fourcc = V4L2_PIX_FMT_GREY,
  198. .mbus_code = MEDIA_BUS_FMT_Y8_1X8,
  199. .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_EIGHT,
  200. },
  201. {
  202. .fourcc = V4L2_PIX_FMT_YUYV,
  203. .mbus_code = MEDIA_BUS_FMT_YUYV8_2X8,
  204. .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_EIGHT,
  205. },
  206. {
  207. .fourcc = V4L2_PIX_FMT_UYVY,
  208. .mbus_code = MEDIA_BUS_FMT_UYVY8_2X8,
  209. .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_EIGHT,
  210. },
  211. {
  212. .fourcc = V4L2_PIX_FMT_RGB565,
  213. .mbus_code = MEDIA_BUS_FMT_RGB565_2X8_LE,
  214. .pfe_cfg0_bps = ISC_PFE_CFG0_BPS_EIGHT,
  215. },
  216. {
  217. .fourcc = V4L2_PIX_FMT_Y10,
  218. .mbus_code = MEDIA_BUS_FMT_Y10_1X10,
  219. .pfe_cfg0_bps = ISC_PFG_CFG0_BPS_TEN,
  220. },
  221. };
  222. static void isc_sama7g5_config_csc(struct isc_device *isc)
  223. {
  224. struct regmap *regmap = isc->regmap;
  225. /* Convert RGB to YUV */
  226. regmap_write(regmap, ISC_CSC_YR_YG + isc->offsets.csc,
  227. 0x42 | (0x81 << 16));
  228. regmap_write(regmap, ISC_CSC_YB_OY + isc->offsets.csc,
  229. 0x19 | (0x10 << 16));
  230. regmap_write(regmap, ISC_CSC_CBR_CBG + isc->offsets.csc,
  231. 0xFDA | (0xFB6 << 16));
  232. regmap_write(regmap, ISC_CSC_CBB_OCB + isc->offsets.csc,
  233. 0x70 | (0x80 << 16));
  234. regmap_write(regmap, ISC_CSC_CRR_CRG + isc->offsets.csc,
  235. 0x70 | (0xFA2 << 16));
  236. regmap_write(regmap, ISC_CSC_CRB_OCR + isc->offsets.csc,
  237. 0xFEE | (0x80 << 16));
  238. }
  239. static void isc_sama7g5_config_cbc(struct isc_device *isc)
  240. {
  241. struct regmap *regmap = isc->regmap;
  242. /* Configure what is set via v4l2 ctrls */
  243. regmap_write(regmap, ISC_CBC_BRIGHT + isc->offsets.cbc, isc->ctrls.brightness);
  244. regmap_write(regmap, ISC_CBC_CONTRAST + isc->offsets.cbc, isc->ctrls.contrast);
  245. /* Configure Hue and Saturation as neutral midpoint */
  246. regmap_write(regmap, ISC_CBCHS_HUE, 0);
  247. regmap_write(regmap, ISC_CBCHS_SAT, (1 << 4));
  248. }
  249. static void isc_sama7g5_config_cc(struct isc_device *isc)
  250. {
  251. struct regmap *regmap = isc->regmap;
  252. /* Configure each register at the neutral fixed point 1.0 or 0.0 */
  253. regmap_write(regmap, ISC_CC_RR_RG, (1 << 8));
  254. regmap_write(regmap, ISC_CC_RB_OR, 0);
  255. regmap_write(regmap, ISC_CC_GR_GG, (1 << 8) << 16);
  256. regmap_write(regmap, ISC_CC_GB_OG, 0);
  257. regmap_write(regmap, ISC_CC_BR_BG, 0);
  258. regmap_write(regmap, ISC_CC_BB_OB, (1 << 8));
  259. }
  260. static void isc_sama7g5_config_ctrls(struct isc_device *isc,
  261. const struct v4l2_ctrl_ops *ops)
  262. {
  263. struct isc_ctrls *ctrls = &isc->ctrls;
  264. struct v4l2_ctrl_handler *hdl = &ctrls->handler;
  265. ctrls->contrast = 16;
  266. v4l2_ctrl_new_std(hdl, ops, V4L2_CID_CONTRAST, -2048, 2047, 1, 16);
  267. }
  268. static void isc_sama7g5_config_dpc(struct isc_device *isc)
  269. {
  270. u32 bay_cfg = isc->config.sd_format->cfa_baycfg;
  271. struct regmap *regmap = isc->regmap;
  272. regmap_update_bits(regmap, ISC_DPC_CFG, ISC_DPC_CFG_BLOFF_MASK,
  273. (64 << ISC_DPC_CFG_BLOFF_SHIFT));
  274. regmap_update_bits(regmap, ISC_DPC_CFG, ISC_DPC_CFG_BAYCFG_MASK,
  275. (bay_cfg << ISC_DPC_CFG_BAYCFG_SHIFT));
  276. }
  277. static void isc_sama7g5_config_gam(struct isc_device *isc)
  278. {
  279. struct regmap *regmap = isc->regmap;
  280. regmap_update_bits(regmap, ISC_GAM_CTRL, ISC_GAM_CTRL_BIPART,
  281. ISC_GAM_CTRL_BIPART);
  282. }
  283. static void isc_sama7g5_config_rlp(struct isc_device *isc)
  284. {
  285. struct regmap *regmap = isc->regmap;
  286. u32 rlp_mode = isc->config.rlp_cfg_mode;
  287. regmap_update_bits(regmap, ISC_RLP_CFG + isc->offsets.rlp,
  288. ISC_RLP_CFG_MODE_MASK | ISC_RLP_CFG_LSH |
  289. ISC_RLP_CFG_YMODE_MASK, rlp_mode);
  290. }
  291. static void isc_sama7g5_adapt_pipeline(struct isc_device *isc)
  292. {
  293. isc->try_config.bits_pipeline &= ISC_SAMA7G5_PIPELINE;
  294. }
  295. /* Gamma table with gamma 1/2.2 */
  296. static const u32 isc_sama7g5_gamma_table[][GAMMA_ENTRIES] = {
  297. /* index 0 --> gamma bipartite */
  298. {
  299. 0x980, 0x4c0320, 0x650260, 0x7801e0, 0x8701a0, 0x940180,
  300. 0xa00160, 0xab0120, 0xb40120, 0xbd0120, 0xc60100, 0xce0100,
  301. 0xd600e0, 0xdd00e0, 0xe400e0, 0xeb00c0, 0xf100c0, 0xf700c0,
  302. 0xfd00c0, 0x10300a0, 0x10800c0, 0x10e00a0, 0x11300a0, 0x11800a0,
  303. 0x11d00a0, 0x12200a0, 0x12700a0, 0x12c0080, 0x13000a0, 0x1350080,
  304. 0x13900a0, 0x13e0080, 0x1420076, 0x17d0062, 0x1ae0054, 0x1d8004a,
  305. 0x1fd0044, 0x21f003e, 0x23e003a, 0x25b0036, 0x2760032, 0x28f0030,
  306. 0x2a7002e, 0x2be002c, 0x2d4002c, 0x2ea0028, 0x2fe0028, 0x3120026,
  307. 0x3250024, 0x3370024, 0x3490022, 0x35a0022, 0x36b0020, 0x37b0020,
  308. 0x38b0020, 0x39b001e, 0x3aa001e, 0x3b9001c, 0x3c7001c, 0x3d5001c,
  309. 0x3e3001c, 0x3f1001c, 0x3ff001a, 0x40c001a },
  310. };
  311. static int xisc_parse_dt(struct device *dev, struct isc_device *isc)
  312. {
  313. struct device_node *np = dev->of_node;
  314. struct device_node *epn;
  315. struct isc_subdev_entity *subdev_entity;
  316. unsigned int flags;
  317. bool mipi_mode;
  318. INIT_LIST_HEAD(&isc->subdev_entities);
  319. mipi_mode = of_property_read_bool(np, "microchip,mipi-mode");
  320. for_each_endpoint_of_node(np, epn) {
  321. struct v4l2_fwnode_endpoint v4l2_epn = { .bus_type = 0 };
  322. int ret;
  323. ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(epn),
  324. &v4l2_epn);
  325. if (ret) {
  326. of_node_put(epn);
  327. dev_err(dev, "Could not parse the endpoint\n");
  328. return -EINVAL;
  329. }
  330. subdev_entity = devm_kzalloc(dev, sizeof(*subdev_entity),
  331. GFP_KERNEL);
  332. if (!subdev_entity) {
  333. of_node_put(epn);
  334. return -ENOMEM;
  335. }
  336. subdev_entity->epn = epn;
  337. flags = v4l2_epn.bus.parallel.flags;
  338. if (flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)
  339. subdev_entity->pfe_cfg0 = ISC_PFE_CFG0_HPOL_LOW;
  340. if (flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)
  341. subdev_entity->pfe_cfg0 |= ISC_PFE_CFG0_VPOL_LOW;
  342. if (flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)
  343. subdev_entity->pfe_cfg0 |= ISC_PFE_CFG0_PPOL_LOW;
  344. if (v4l2_epn.bus_type == V4L2_MBUS_BT656)
  345. subdev_entity->pfe_cfg0 |= ISC_PFE_CFG0_CCIR_CRC |
  346. ISC_PFE_CFG0_CCIR656;
  347. if (mipi_mode)
  348. subdev_entity->pfe_cfg0 |= ISC_PFE_CFG0_MIPI;
  349. list_add_tail(&subdev_entity->list, &isc->subdev_entities);
  350. }
  351. return 0;
  352. }
  353. static int microchip_xisc_probe(struct platform_device *pdev)
  354. {
  355. struct device *dev = &pdev->dev;
  356. struct isc_device *isc;
  357. void __iomem *io_base;
  358. struct isc_subdev_entity *subdev_entity;
  359. int irq;
  360. int ret;
  361. u32 ver;
  362. isc = devm_kzalloc(dev, sizeof(*isc), GFP_KERNEL);
  363. if (!isc)
  364. return -ENOMEM;
  365. platform_set_drvdata(pdev, isc);
  366. isc->dev = dev;
  367. io_base = devm_platform_ioremap_resource(pdev, 0);
  368. if (IS_ERR(io_base))
  369. return PTR_ERR(io_base);
  370. isc->regmap = devm_regmap_init_mmio(dev, io_base, &microchip_isc_regmap_config);
  371. if (IS_ERR(isc->regmap)) {
  372. ret = PTR_ERR(isc->regmap);
  373. dev_err(dev, "failed to init register map: %d\n", ret);
  374. return ret;
  375. }
  376. irq = platform_get_irq(pdev, 0);
  377. if (irq < 0)
  378. return irq;
  379. ret = devm_request_irq(dev, irq, microchip_isc_interrupt, 0,
  380. "microchip-sama7g5-xisc", isc);
  381. if (ret < 0) {
  382. dev_err(dev, "can't register ISR for IRQ %u (ret=%i)\n",
  383. irq, ret);
  384. return ret;
  385. }
  386. isc->gamma_table = isc_sama7g5_gamma_table;
  387. isc->gamma_max = 0;
  388. isc->max_width = ISC_SAMA7G5_MAX_SUPPORT_WIDTH;
  389. isc->max_height = ISC_SAMA7G5_MAX_SUPPORT_HEIGHT;
  390. isc->config_dpc = isc_sama7g5_config_dpc;
  391. isc->config_csc = isc_sama7g5_config_csc;
  392. isc->config_cbc = isc_sama7g5_config_cbc;
  393. isc->config_cc = isc_sama7g5_config_cc;
  394. isc->config_gam = isc_sama7g5_config_gam;
  395. isc->config_rlp = isc_sama7g5_config_rlp;
  396. isc->config_ctrls = isc_sama7g5_config_ctrls;
  397. isc->adapt_pipeline = isc_sama7g5_adapt_pipeline;
  398. isc->offsets.csc = ISC_SAMA7G5_CSC_OFFSET;
  399. isc->offsets.cbc = ISC_SAMA7G5_CBC_OFFSET;
  400. isc->offsets.sub422 = ISC_SAMA7G5_SUB422_OFFSET;
  401. isc->offsets.sub420 = ISC_SAMA7G5_SUB420_OFFSET;
  402. isc->offsets.rlp = ISC_SAMA7G5_RLP_OFFSET;
  403. isc->offsets.his = ISC_SAMA7G5_HIS_OFFSET;
  404. isc->offsets.dma = ISC_SAMA7G5_DMA_OFFSET;
  405. isc->offsets.version = ISC_SAMA7G5_VERSION_OFFSET;
  406. isc->offsets.his_entry = ISC_SAMA7G5_HIS_ENTRY_OFFSET;
  407. isc->controller_formats = sama7g5_controller_formats;
  408. isc->controller_formats_size = ARRAY_SIZE(sama7g5_controller_formats);
  409. isc->formats_list = sama7g5_formats_list;
  410. isc->formats_list_size = ARRAY_SIZE(sama7g5_formats_list);
  411. /* sama7g5-isc RAM access port is full AXI4 - 32 bits per beat */
  412. isc->dcfg = ISC_DCFG_YMBSIZE_BEATS32 | ISC_DCFG_CMBSIZE_BEATS32;
  413. /* sama7g5-isc : ISPCK does not exist, ISC is clocked by MCK */
  414. isc->ispck_required = false;
  415. ret = microchip_isc_pipeline_init(isc);
  416. if (ret)
  417. return ret;
  418. isc->hclock = devm_clk_get(dev, "hclock");
  419. if (IS_ERR(isc->hclock)) {
  420. ret = PTR_ERR(isc->hclock);
  421. dev_err(dev, "failed to get hclock: %d\n", ret);
  422. return ret;
  423. }
  424. ret = clk_prepare_enable(isc->hclock);
  425. if (ret) {
  426. dev_err(dev, "failed to enable hclock: %d\n", ret);
  427. return ret;
  428. }
  429. ret = microchip_isc_clk_init(isc);
  430. if (ret) {
  431. dev_err(dev, "failed to init isc clock: %d\n", ret);
  432. goto unprepare_hclk;
  433. }
  434. ret = v4l2_device_register(dev, &isc->v4l2_dev);
  435. if (ret) {
  436. dev_err(dev, "unable to register v4l2 device.\n");
  437. goto unprepare_hclk;
  438. }
  439. ret = xisc_parse_dt(dev, isc);
  440. if (ret) {
  441. dev_err(dev, "fail to parse device tree\n");
  442. goto unregister_v4l2_device;
  443. }
  444. if (list_empty(&isc->subdev_entities)) {
  445. dev_err(dev, "no subdev found\n");
  446. ret = -ENODEV;
  447. goto unregister_v4l2_device;
  448. }
  449. list_for_each_entry(subdev_entity, &isc->subdev_entities, list) {
  450. struct v4l2_async_connection *asd;
  451. struct fwnode_handle *fwnode =
  452. of_fwnode_handle(subdev_entity->epn);
  453. v4l2_async_nf_init(&subdev_entity->notifier, &isc->v4l2_dev);
  454. asd = v4l2_async_nf_add_fwnode_remote(&subdev_entity->notifier,
  455. fwnode,
  456. struct v4l2_async_connection);
  457. of_node_put(subdev_entity->epn);
  458. subdev_entity->epn = NULL;
  459. if (IS_ERR(asd)) {
  460. ret = PTR_ERR(asd);
  461. goto cleanup_subdev;
  462. }
  463. subdev_entity->notifier.ops = &microchip_isc_async_ops;
  464. ret = v4l2_async_nf_register(&subdev_entity->notifier);
  465. if (ret) {
  466. dev_err(dev, "fail to register async notifier\n");
  467. goto cleanup_subdev;
  468. }
  469. if (video_is_registered(&isc->video_dev))
  470. break;
  471. }
  472. regmap_read(isc->regmap, ISC_VERSION + isc->offsets.version, &ver);
  473. ret = isc_mc_init(isc, ver);
  474. if (ret < 0)
  475. goto isc_probe_mc_init_err;
  476. pm_runtime_set_active(dev);
  477. pm_runtime_enable(dev);
  478. pm_request_idle(dev);
  479. dev_info(dev, "Microchip XISC version %x\n", ver);
  480. return 0;
  481. isc_probe_mc_init_err:
  482. isc_mc_cleanup(isc);
  483. cleanup_subdev:
  484. microchip_isc_subdev_cleanup(isc);
  485. unregister_v4l2_device:
  486. v4l2_device_unregister(&isc->v4l2_dev);
  487. unprepare_hclk:
  488. clk_disable_unprepare(isc->hclock);
  489. microchip_isc_clk_cleanup(isc);
  490. return ret;
  491. }
  492. static void microchip_xisc_remove(struct platform_device *pdev)
  493. {
  494. struct isc_device *isc = platform_get_drvdata(pdev);
  495. pm_runtime_disable(&pdev->dev);
  496. isc_mc_cleanup(isc);
  497. microchip_isc_subdev_cleanup(isc);
  498. v4l2_device_unregister(&isc->v4l2_dev);
  499. clk_disable_unprepare(isc->hclock);
  500. microchip_isc_clk_cleanup(isc);
  501. }
  502. static int __maybe_unused xisc_runtime_suspend(struct device *dev)
  503. {
  504. struct isc_device *isc = dev_get_drvdata(dev);
  505. clk_disable_unprepare(isc->hclock);
  506. return 0;
  507. }
  508. static int __maybe_unused xisc_runtime_resume(struct device *dev)
  509. {
  510. struct isc_device *isc = dev_get_drvdata(dev);
  511. int ret;
  512. ret = clk_prepare_enable(isc->hclock);
  513. if (ret)
  514. return ret;
  515. return ret;
  516. }
  517. static const struct dev_pm_ops microchip_xisc_dev_pm_ops = {
  518. SET_RUNTIME_PM_OPS(xisc_runtime_suspend, xisc_runtime_resume, NULL)
  519. };
  520. #if IS_ENABLED(CONFIG_OF)
  521. static const struct of_device_id microchip_xisc_of_match[] = {
  522. { .compatible = "microchip,sama7g5-isc" },
  523. { }
  524. };
  525. MODULE_DEVICE_TABLE(of, microchip_xisc_of_match);
  526. #endif
  527. static struct platform_driver microchip_xisc_driver = {
  528. .probe = microchip_xisc_probe,
  529. .remove_new = microchip_xisc_remove,
  530. .driver = {
  531. .name = "microchip-sama7g5-xisc",
  532. .pm = &microchip_xisc_dev_pm_ops,
  533. .of_match_table = of_match_ptr(microchip_xisc_of_match),
  534. },
  535. };
  536. module_platform_driver(microchip_xisc_driver);
  537. MODULE_AUTHOR("Eugen Hristev <eugen.hristev@microchip.com>");
  538. MODULE_DESCRIPTION("The V4L2 driver for Microchip-XISC");
  539. MODULE_LICENSE("GPL v2");