xilinx-csi2rxss.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Driver for Xilinx MIPI CSI-2 Rx Subsystem
  4. *
  5. * Copyright (C) 2016 - 2020 Xilinx, Inc.
  6. *
  7. * Contacts: Vishal Sagar <[email protected]>
  8. *
  9. */
  10. #include <linux/clk.h>
  11. #include <linux/delay.h>
  12. #include <linux/gpio/consumer.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/module.h>
  15. #include <linux/mutex.h>
  16. #include <linux/of.h>
  17. #include <linux/of_irq.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/v4l2-subdev.h>
  20. #include <media/media-entity.h>
  21. #include <media/mipi-csi2.h>
  22. #include <media/v4l2-common.h>
  23. #include <media/v4l2-ctrls.h>
  24. #include <media/v4l2-fwnode.h>
  25. #include <media/v4l2-subdev.h>
  26. #include "xilinx-vip.h"
  27. /* Register register map */
  28. #define XCSI_CCR_OFFSET 0x00
  29. #define XCSI_CCR_SOFTRESET BIT(1)
  30. #define XCSI_CCR_ENABLE BIT(0)
  31. #define XCSI_PCR_OFFSET 0x04
  32. #define XCSI_PCR_MAXLANES_MASK GENMASK(4, 3)
  33. #define XCSI_PCR_ACTLANES_MASK GENMASK(1, 0)
  34. #define XCSI_CSR_OFFSET 0x10
  35. #define XCSI_CSR_PKTCNT GENMASK(31, 16)
  36. #define XCSI_CSR_SPFIFOFULL BIT(3)
  37. #define XCSI_CSR_SPFIFONE BIT(2)
  38. #define XCSI_CSR_SLBF BIT(1)
  39. #define XCSI_CSR_RIPCD BIT(0)
  40. #define XCSI_GIER_OFFSET 0x20
  41. #define XCSI_GIER_GIE BIT(0)
  42. #define XCSI_ISR_OFFSET 0x24
  43. #define XCSI_IER_OFFSET 0x28
  44. #define XCSI_ISR_FR BIT(31)
  45. #define XCSI_ISR_VCXFE BIT(30)
  46. #define XCSI_ISR_WCC BIT(22)
  47. #define XCSI_ISR_ILC BIT(21)
  48. #define XCSI_ISR_SPFIFOF BIT(20)
  49. #define XCSI_ISR_SPFIFONE BIT(19)
  50. #define XCSI_ISR_SLBF BIT(18)
  51. #define XCSI_ISR_STOP BIT(17)
  52. #define XCSI_ISR_SOTERR BIT(13)
  53. #define XCSI_ISR_SOTSYNCERR BIT(12)
  54. #define XCSI_ISR_ECC2BERR BIT(11)
  55. #define XCSI_ISR_ECC1BERR BIT(10)
  56. #define XCSI_ISR_CRCERR BIT(9)
  57. #define XCSI_ISR_DATAIDERR BIT(8)
  58. #define XCSI_ISR_VC3FSYNCERR BIT(7)
  59. #define XCSI_ISR_VC3FLVLERR BIT(6)
  60. #define XCSI_ISR_VC2FSYNCERR BIT(5)
  61. #define XCSI_ISR_VC2FLVLERR BIT(4)
  62. #define XCSI_ISR_VC1FSYNCERR BIT(3)
  63. #define XCSI_ISR_VC1FLVLERR BIT(2)
  64. #define XCSI_ISR_VC0FSYNCERR BIT(1)
  65. #define XCSI_ISR_VC0FLVLERR BIT(0)
  66. #define XCSI_ISR_ALLINTR_MASK (0xc07e3fff)
  67. /*
  68. * Removed VCXFE mask as it doesn't exist in IER
  69. * Removed STOP state irq as this will keep driver in irq handler only
  70. */
  71. #define XCSI_IER_INTR_MASK (XCSI_ISR_ALLINTR_MASK &\
  72. ~(XCSI_ISR_STOP | XCSI_ISR_VCXFE))
  73. #define XCSI_SPKTR_OFFSET 0x30
  74. #define XCSI_SPKTR_DATA GENMASK(23, 8)
  75. #define XCSI_SPKTR_VC GENMASK(7, 6)
  76. #define XCSI_SPKTR_DT GENMASK(5, 0)
  77. #define XCSI_SPKT_FIFO_DEPTH 31
  78. #define XCSI_VCXR_OFFSET 0x34
  79. #define XCSI_VCXR_VCERR GENMASK(23, 0)
  80. #define XCSI_VCXR_FSYNCERR BIT(1)
  81. #define XCSI_VCXR_FLVLERR BIT(0)
  82. #define XCSI_CLKINFR_OFFSET 0x3C
  83. #define XCSI_CLKINFR_STOP BIT(1)
  84. #define XCSI_DLXINFR_OFFSET 0x40
  85. #define XCSI_DLXINFR_STOP BIT(5)
  86. #define XCSI_DLXINFR_SOTERR BIT(1)
  87. #define XCSI_DLXINFR_SOTSYNCERR BIT(0)
  88. #define XCSI_MAXDL_COUNT 0x4
  89. #define XCSI_VCXINF1R_OFFSET 0x60
  90. #define XCSI_VCXINF1R_LINECOUNT GENMASK(31, 16)
  91. #define XCSI_VCXINF1R_LINECOUNT_SHIFT 16
  92. #define XCSI_VCXINF1R_BYTECOUNT GENMASK(15, 0)
  93. #define XCSI_VCXINF2R_OFFSET 0x64
  94. #define XCSI_VCXINF2R_DT GENMASK(5, 0)
  95. #define XCSI_MAXVCX_COUNT 16
  96. /*
  97. * Sink pad connected to sensor source pad.
  98. * Source pad connected to next module like demosaic.
  99. */
  100. #define XCSI_MEDIA_PADS 2
  101. #define XCSI_DEFAULT_WIDTH 1920
  102. #define XCSI_DEFAULT_HEIGHT 1080
  103. #define XCSI_VCX_START 4
  104. #define XCSI_MAX_VC 4
  105. #define XCSI_MAX_VCX 16
  106. #define XCSI_NEXTREG_OFFSET 4
  107. /* There are 2 events frame sync and frame level error per VC */
  108. #define XCSI_VCX_NUM_EVENTS ((XCSI_MAX_VCX - XCSI_MAX_VC) * 2)
  109. /**
  110. * struct xcsi2rxss_event - Event log structure
  111. * @mask: Event mask
  112. * @name: Name of the event
  113. */
  114. struct xcsi2rxss_event {
  115. u32 mask;
  116. const char *name;
  117. };
  118. static const struct xcsi2rxss_event xcsi2rxss_events[] = {
  119. { XCSI_ISR_FR, "Frame Received" },
  120. { XCSI_ISR_VCXFE, "VCX Frame Errors" },
  121. { XCSI_ISR_WCC, "Word Count Errors" },
  122. { XCSI_ISR_ILC, "Invalid Lane Count Error" },
  123. { XCSI_ISR_SPFIFOF, "Short Packet FIFO OverFlow Error" },
  124. { XCSI_ISR_SPFIFONE, "Short Packet FIFO Not Empty" },
  125. { XCSI_ISR_SLBF, "Streamline Buffer Full Error" },
  126. { XCSI_ISR_STOP, "Lane Stop State" },
  127. { XCSI_ISR_SOTERR, "SOT Error" },
  128. { XCSI_ISR_SOTSYNCERR, "SOT Sync Error" },
  129. { XCSI_ISR_ECC2BERR, "2 Bit ECC Unrecoverable Error" },
  130. { XCSI_ISR_ECC1BERR, "1 Bit ECC Recoverable Error" },
  131. { XCSI_ISR_CRCERR, "CRC Error" },
  132. { XCSI_ISR_DATAIDERR, "Data Id Error" },
  133. { XCSI_ISR_VC3FSYNCERR, "Virtual Channel 3 Frame Sync Error" },
  134. { XCSI_ISR_VC3FLVLERR, "Virtual Channel 3 Frame Level Error" },
  135. { XCSI_ISR_VC2FSYNCERR, "Virtual Channel 2 Frame Sync Error" },
  136. { XCSI_ISR_VC2FLVLERR, "Virtual Channel 2 Frame Level Error" },
  137. { XCSI_ISR_VC1FSYNCERR, "Virtual Channel 1 Frame Sync Error" },
  138. { XCSI_ISR_VC1FLVLERR, "Virtual Channel 1 Frame Level Error" },
  139. { XCSI_ISR_VC0FSYNCERR, "Virtual Channel 0 Frame Sync Error" },
  140. { XCSI_ISR_VC0FLVLERR, "Virtual Channel 0 Frame Level Error" }
  141. };
  142. #define XCSI_NUM_EVENTS ARRAY_SIZE(xcsi2rxss_events)
  143. /*
  144. * This table provides a mapping between CSI-2 Data type
  145. * and media bus formats
  146. */
  147. static const u32 xcsi2dt_mbus_lut[][2] = {
  148. { MIPI_CSI2_DT_YUV422_8B, MEDIA_BUS_FMT_UYVY8_1X16 },
  149. { MIPI_CSI2_DT_YUV422_10B, MEDIA_BUS_FMT_UYVY10_1X20 },
  150. { MIPI_CSI2_DT_RGB444, 0 },
  151. { MIPI_CSI2_DT_RGB555, 0 },
  152. { MIPI_CSI2_DT_RGB565, 0 },
  153. { MIPI_CSI2_DT_RGB666, 0 },
  154. { MIPI_CSI2_DT_RGB888, MEDIA_BUS_FMT_RBG888_1X24 },
  155. { MIPI_CSI2_DT_RAW6, 0 },
  156. { MIPI_CSI2_DT_RAW7, 0 },
  157. { MIPI_CSI2_DT_RAW8, MEDIA_BUS_FMT_SRGGB8_1X8 },
  158. { MIPI_CSI2_DT_RAW8, MEDIA_BUS_FMT_SBGGR8_1X8 },
  159. { MIPI_CSI2_DT_RAW8, MEDIA_BUS_FMT_SGBRG8_1X8 },
  160. { MIPI_CSI2_DT_RAW8, MEDIA_BUS_FMT_SGRBG8_1X8 },
  161. { MIPI_CSI2_DT_RAW10, MEDIA_BUS_FMT_SRGGB10_1X10 },
  162. { MIPI_CSI2_DT_RAW10, MEDIA_BUS_FMT_SBGGR10_1X10 },
  163. { MIPI_CSI2_DT_RAW10, MEDIA_BUS_FMT_SGBRG10_1X10 },
  164. { MIPI_CSI2_DT_RAW10, MEDIA_BUS_FMT_SGRBG10_1X10 },
  165. { MIPI_CSI2_DT_RAW12, MEDIA_BUS_FMT_SRGGB12_1X12 },
  166. { MIPI_CSI2_DT_RAW12, MEDIA_BUS_FMT_SBGGR12_1X12 },
  167. { MIPI_CSI2_DT_RAW12, MEDIA_BUS_FMT_SGBRG12_1X12 },
  168. { MIPI_CSI2_DT_RAW12, MEDIA_BUS_FMT_SGRBG12_1X12 },
  169. { MIPI_CSI2_DT_RAW12, MEDIA_BUS_FMT_Y12_1X12 },
  170. { MIPI_CSI2_DT_RAW16, MEDIA_BUS_FMT_SRGGB16_1X16 },
  171. { MIPI_CSI2_DT_RAW16, MEDIA_BUS_FMT_SBGGR16_1X16 },
  172. { MIPI_CSI2_DT_RAW16, MEDIA_BUS_FMT_SGBRG16_1X16 },
  173. { MIPI_CSI2_DT_RAW16, MEDIA_BUS_FMT_SGRBG16_1X16 },
  174. { MIPI_CSI2_DT_RAW20, 0 },
  175. };
  176. /**
  177. * struct xcsi2rxss_state - CSI-2 Rx Subsystem device structure
  178. * @subdev: The v4l2 subdev structure
  179. * @format: Active V4L2 formats on each pad
  180. * @default_format: Default V4L2 format
  181. * @events: counter for events
  182. * @vcx_events: counter for vcx_events
  183. * @dev: Platform structure
  184. * @rsubdev: Remote subdev connected to sink pad
  185. * @rst_gpio: reset to video_aresetn
  186. * @clks: array of clocks
  187. * @iomem: Base address of subsystem
  188. * @max_num_lanes: Maximum number of lanes present
  189. * @datatype: Data type filter
  190. * @lock: mutex for accessing this structure
  191. * @pads: media pads
  192. * @streaming: Flag for storing streaming state
  193. * @enable_active_lanes: If number of active lanes can be modified
  194. * @en_vcx: If more than 4 VC are enabled
  195. *
  196. * This structure contains the device driver related parameters
  197. */
  198. struct xcsi2rxss_state {
  199. struct v4l2_subdev subdev;
  200. struct v4l2_mbus_framefmt format;
  201. struct v4l2_mbus_framefmt default_format;
  202. u32 events[XCSI_NUM_EVENTS];
  203. u32 vcx_events[XCSI_VCX_NUM_EVENTS];
  204. struct device *dev;
  205. struct v4l2_subdev *rsubdev;
  206. struct gpio_desc *rst_gpio;
  207. struct clk_bulk_data *clks;
  208. void __iomem *iomem;
  209. u32 max_num_lanes;
  210. u32 datatype;
  211. /* used to protect access to this struct */
  212. struct mutex lock;
  213. struct media_pad pads[XCSI_MEDIA_PADS];
  214. bool streaming;
  215. bool enable_active_lanes;
  216. bool en_vcx;
  217. };
  218. static const struct clk_bulk_data xcsi2rxss_clks[] = {
  219. { .id = "lite_aclk" },
  220. { .id = "video_aclk" },
  221. };
  222. static inline struct xcsi2rxss_state *
  223. to_xcsi2rxssstate(struct v4l2_subdev *subdev)
  224. {
  225. return container_of(subdev, struct xcsi2rxss_state, subdev);
  226. }
  227. /*
  228. * Register related operations
  229. */
  230. static inline u32 xcsi2rxss_read(struct xcsi2rxss_state *xcsi2rxss, u32 addr)
  231. {
  232. return ioread32(xcsi2rxss->iomem + addr);
  233. }
  234. static inline void xcsi2rxss_write(struct xcsi2rxss_state *xcsi2rxss, u32 addr,
  235. u32 value)
  236. {
  237. iowrite32(value, xcsi2rxss->iomem + addr);
  238. }
  239. static inline void xcsi2rxss_clr(struct xcsi2rxss_state *xcsi2rxss, u32 addr,
  240. u32 clr)
  241. {
  242. xcsi2rxss_write(xcsi2rxss, addr,
  243. xcsi2rxss_read(xcsi2rxss, addr) & ~clr);
  244. }
  245. static inline void xcsi2rxss_set(struct xcsi2rxss_state *xcsi2rxss, u32 addr,
  246. u32 set)
  247. {
  248. xcsi2rxss_write(xcsi2rxss, addr, xcsi2rxss_read(xcsi2rxss, addr) | set);
  249. }
  250. /*
  251. * This function returns the nth mbus for a data type.
  252. * In case of error, mbus code returned is 0.
  253. */
  254. static u32 xcsi2rxss_get_nth_mbus(u32 dt, u32 n)
  255. {
  256. unsigned int i;
  257. for (i = 0; i < ARRAY_SIZE(xcsi2dt_mbus_lut); i++) {
  258. if (xcsi2dt_mbus_lut[i][0] == dt) {
  259. if (n-- == 0)
  260. return xcsi2dt_mbus_lut[i][1];
  261. }
  262. }
  263. return 0;
  264. }
  265. /* This returns the data type for a media bus format else 0 */
  266. static u32 xcsi2rxss_get_dt(u32 mbus)
  267. {
  268. unsigned int i;
  269. for (i = 0; i < ARRAY_SIZE(xcsi2dt_mbus_lut); i++) {
  270. if (xcsi2dt_mbus_lut[i][1] == mbus)
  271. return xcsi2dt_mbus_lut[i][0];
  272. }
  273. return 0;
  274. }
  275. /**
  276. * xcsi2rxss_soft_reset - Does a soft reset of the MIPI CSI-2 Rx Subsystem
  277. * @state: Xilinx CSI-2 Rx Subsystem structure pointer
  278. *
  279. * Core takes less than 100 video clock cycles to reset.
  280. * So a larger timeout value is chosen for margin.
  281. *
  282. * Return: 0 - on success OR -ETIME if reset times out
  283. */
  284. static int xcsi2rxss_soft_reset(struct xcsi2rxss_state *state)
  285. {
  286. u32 timeout = 1000; /* us */
  287. xcsi2rxss_set(state, XCSI_CCR_OFFSET, XCSI_CCR_SOFTRESET);
  288. while (xcsi2rxss_read(state, XCSI_CSR_OFFSET) & XCSI_CSR_RIPCD) {
  289. if (timeout == 0) {
  290. dev_err(state->dev, "soft reset timed out!\n");
  291. return -ETIME;
  292. }
  293. timeout--;
  294. udelay(1);
  295. }
  296. xcsi2rxss_clr(state, XCSI_CCR_OFFSET, XCSI_CCR_SOFTRESET);
  297. return 0;
  298. }
  299. static void xcsi2rxss_hard_reset(struct xcsi2rxss_state *state)
  300. {
  301. if (!state->rst_gpio)
  302. return;
  303. /* minimum of 40 dphy_clk_200M cycles */
  304. gpiod_set_value_cansleep(state->rst_gpio, 1);
  305. usleep_range(1, 2);
  306. gpiod_set_value_cansleep(state->rst_gpio, 0);
  307. }
  308. static void xcsi2rxss_reset_event_counters(struct xcsi2rxss_state *state)
  309. {
  310. unsigned int i;
  311. for (i = 0; i < XCSI_NUM_EVENTS; i++)
  312. state->events[i] = 0;
  313. for (i = 0; i < XCSI_VCX_NUM_EVENTS; i++)
  314. state->vcx_events[i] = 0;
  315. }
  316. /* Print event counters */
  317. static void xcsi2rxss_log_counters(struct xcsi2rxss_state *state)
  318. {
  319. struct device *dev = state->dev;
  320. unsigned int i;
  321. for (i = 0; i < XCSI_NUM_EVENTS; i++) {
  322. if (state->events[i] > 0) {
  323. dev_info(dev, "%s events: %d\n",
  324. xcsi2rxss_events[i].name,
  325. state->events[i]);
  326. }
  327. }
  328. if (state->en_vcx) {
  329. for (i = 0; i < XCSI_VCX_NUM_EVENTS; i++) {
  330. if (state->vcx_events[i] > 0) {
  331. dev_info(dev,
  332. "VC %d Frame %s err vcx events: %d\n",
  333. (i / 2) + XCSI_VCX_START,
  334. i & 1 ? "Sync" : "Level",
  335. state->vcx_events[i]);
  336. }
  337. }
  338. }
  339. }
  340. /**
  341. * xcsi2rxss_log_status - Logs the status of the CSI-2 Receiver
  342. * @sd: Pointer to V4L2 subdevice structure
  343. *
  344. * This function prints the current status of Xilinx MIPI CSI-2
  345. *
  346. * Return: 0 on success
  347. */
  348. static int xcsi2rxss_log_status(struct v4l2_subdev *sd)
  349. {
  350. struct xcsi2rxss_state *xcsi2rxss = to_xcsi2rxssstate(sd);
  351. struct device *dev = xcsi2rxss->dev;
  352. u32 reg, data;
  353. unsigned int i, max_vc;
  354. mutex_lock(&xcsi2rxss->lock);
  355. xcsi2rxss_log_counters(xcsi2rxss);
  356. dev_info(dev, "***** Core Status *****\n");
  357. data = xcsi2rxss_read(xcsi2rxss, XCSI_CSR_OFFSET);
  358. dev_info(dev, "Short Packet FIFO Full = %s\n",
  359. data & XCSI_CSR_SPFIFOFULL ? "true" : "false");
  360. dev_info(dev, "Short Packet FIFO Not Empty = %s\n",
  361. data & XCSI_CSR_SPFIFONE ? "true" : "false");
  362. dev_info(dev, "Stream line buffer full = %s\n",
  363. data & XCSI_CSR_SLBF ? "true" : "false");
  364. dev_info(dev, "Soft reset/Core disable in progress = %s\n",
  365. data & XCSI_CSR_RIPCD ? "true" : "false");
  366. /* Clk & Lane Info */
  367. dev_info(dev, "******** Clock Lane Info *********\n");
  368. data = xcsi2rxss_read(xcsi2rxss, XCSI_CLKINFR_OFFSET);
  369. dev_info(dev, "Clock Lane in Stop State = %s\n",
  370. data & XCSI_CLKINFR_STOP ? "true" : "false");
  371. dev_info(dev, "******** Data Lane Info *********\n");
  372. dev_info(dev, "Lane\tSoT Error\tSoT Sync Error\tStop State\n");
  373. reg = XCSI_DLXINFR_OFFSET;
  374. for (i = 0; i < XCSI_MAXDL_COUNT; i++) {
  375. data = xcsi2rxss_read(xcsi2rxss, reg);
  376. dev_info(dev, "%d\t%s\t\t%s\t\t%s\n", i,
  377. data & XCSI_DLXINFR_SOTERR ? "true" : "false",
  378. data & XCSI_DLXINFR_SOTSYNCERR ? "true" : "false",
  379. data & XCSI_DLXINFR_STOP ? "true" : "false");
  380. reg += XCSI_NEXTREG_OFFSET;
  381. }
  382. /* Virtual Channel Image Information */
  383. dev_info(dev, "********** Virtual Channel Info ************\n");
  384. dev_info(dev, "VC\tLine Count\tByte Count\tData Type\n");
  385. if (xcsi2rxss->en_vcx)
  386. max_vc = XCSI_MAX_VCX;
  387. else
  388. max_vc = XCSI_MAX_VC;
  389. reg = XCSI_VCXINF1R_OFFSET;
  390. for (i = 0; i < max_vc; i++) {
  391. u32 line_count, byte_count, data_type;
  392. /* Get line and byte count from VCXINFR1 Register */
  393. data = xcsi2rxss_read(xcsi2rxss, reg);
  394. byte_count = data & XCSI_VCXINF1R_BYTECOUNT;
  395. line_count = data & XCSI_VCXINF1R_LINECOUNT;
  396. line_count >>= XCSI_VCXINF1R_LINECOUNT_SHIFT;
  397. /* Get data type from VCXINFR2 Register */
  398. reg += XCSI_NEXTREG_OFFSET;
  399. data = xcsi2rxss_read(xcsi2rxss, reg);
  400. data_type = data & XCSI_VCXINF2R_DT;
  401. dev_info(dev, "%d\t%d\t\t%d\t\t0x%x\n", i, line_count,
  402. byte_count, data_type);
  403. /* Move to next pair of VC Info registers */
  404. reg += XCSI_NEXTREG_OFFSET;
  405. }
  406. mutex_unlock(&xcsi2rxss->lock);
  407. return 0;
  408. }
  409. static struct v4l2_subdev *xcsi2rxss_get_remote_subdev(struct media_pad *local)
  410. {
  411. struct media_pad *remote;
  412. remote = media_pad_remote_pad_first(local);
  413. if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
  414. return NULL;
  415. return media_entity_to_v4l2_subdev(remote->entity);
  416. }
  417. static int xcsi2rxss_start_stream(struct xcsi2rxss_state *state)
  418. {
  419. int ret = 0;
  420. /* enable core */
  421. xcsi2rxss_set(state, XCSI_CCR_OFFSET, XCSI_CCR_ENABLE);
  422. ret = xcsi2rxss_soft_reset(state);
  423. if (ret) {
  424. state->streaming = false;
  425. return ret;
  426. }
  427. /* enable interrupts */
  428. xcsi2rxss_clr(state, XCSI_GIER_OFFSET, XCSI_GIER_GIE);
  429. xcsi2rxss_write(state, XCSI_IER_OFFSET, XCSI_IER_INTR_MASK);
  430. xcsi2rxss_set(state, XCSI_GIER_OFFSET, XCSI_GIER_GIE);
  431. state->streaming = true;
  432. state->rsubdev =
  433. xcsi2rxss_get_remote_subdev(&state->pads[XVIP_PAD_SINK]);
  434. ret = v4l2_subdev_call(state->rsubdev, video, s_stream, 1);
  435. if (ret) {
  436. /* disable interrupts */
  437. xcsi2rxss_clr(state, XCSI_IER_OFFSET, XCSI_IER_INTR_MASK);
  438. xcsi2rxss_clr(state, XCSI_GIER_OFFSET, XCSI_GIER_GIE);
  439. /* disable core */
  440. xcsi2rxss_clr(state, XCSI_CCR_OFFSET, XCSI_CCR_ENABLE);
  441. state->streaming = false;
  442. }
  443. return ret;
  444. }
  445. static void xcsi2rxss_stop_stream(struct xcsi2rxss_state *state)
  446. {
  447. v4l2_subdev_call(state->rsubdev, video, s_stream, 0);
  448. /* disable interrupts */
  449. xcsi2rxss_clr(state, XCSI_IER_OFFSET, XCSI_IER_INTR_MASK);
  450. xcsi2rxss_clr(state, XCSI_GIER_OFFSET, XCSI_GIER_GIE);
  451. /* disable core */
  452. xcsi2rxss_clr(state, XCSI_CCR_OFFSET, XCSI_CCR_ENABLE);
  453. state->streaming = false;
  454. }
  455. /**
  456. * xcsi2rxss_irq_handler - Interrupt handler for CSI-2
  457. * @irq: IRQ number
  458. * @data: Pointer to device state
  459. *
  460. * In the interrupt handler, a list of event counters are updated for
  461. * corresponding interrupts. This is useful to get status / debug.
  462. *
  463. * Return: IRQ_HANDLED after handling interrupts
  464. */
  465. static irqreturn_t xcsi2rxss_irq_handler(int irq, void *data)
  466. {
  467. struct xcsi2rxss_state *state = (struct xcsi2rxss_state *)data;
  468. struct device *dev = state->dev;
  469. u32 status;
  470. status = xcsi2rxss_read(state, XCSI_ISR_OFFSET) & XCSI_ISR_ALLINTR_MASK;
  471. xcsi2rxss_write(state, XCSI_ISR_OFFSET, status);
  472. /* Received a short packet */
  473. if (status & XCSI_ISR_SPFIFONE) {
  474. u32 count = 0;
  475. /*
  476. * Drain generic short packet FIFO by reading max 31
  477. * (fifo depth) short packets from fifo or till fifo is empty.
  478. */
  479. for (count = 0; count < XCSI_SPKT_FIFO_DEPTH; ++count) {
  480. u32 spfifostat, spkt;
  481. spkt = xcsi2rxss_read(state, XCSI_SPKTR_OFFSET);
  482. dev_dbg(dev, "Short packet = 0x%08x\n", spkt);
  483. spfifostat = xcsi2rxss_read(state, XCSI_ISR_OFFSET);
  484. spfifostat &= XCSI_ISR_SPFIFONE;
  485. if (!spfifostat)
  486. break;
  487. xcsi2rxss_write(state, XCSI_ISR_OFFSET, spfifostat);
  488. }
  489. }
  490. /* Short packet FIFO overflow */
  491. if (status & XCSI_ISR_SPFIFOF)
  492. dev_dbg_ratelimited(dev, "Short packet FIFO overflowed\n");
  493. /*
  494. * Stream line buffer full
  495. * This means there is a backpressure from downstream IP
  496. */
  497. if (status & XCSI_ISR_SLBF) {
  498. dev_alert_ratelimited(dev, "Stream Line Buffer Full!\n");
  499. /* disable interrupts */
  500. xcsi2rxss_clr(state, XCSI_IER_OFFSET, XCSI_IER_INTR_MASK);
  501. xcsi2rxss_clr(state, XCSI_GIER_OFFSET, XCSI_GIER_GIE);
  502. /* disable core */
  503. xcsi2rxss_clr(state, XCSI_CCR_OFFSET, XCSI_CCR_ENABLE);
  504. /*
  505. * The IP needs to be hard reset before it can be used now.
  506. * This will be done in streamoff.
  507. */
  508. /*
  509. * TODO: Notify the whole pipeline with v4l2_subdev_notify() to
  510. * inform userspace.
  511. */
  512. }
  513. /* Increment event counters */
  514. if (status & XCSI_ISR_ALLINTR_MASK) {
  515. unsigned int i;
  516. for (i = 0; i < XCSI_NUM_EVENTS; i++) {
  517. if (!(status & xcsi2rxss_events[i].mask))
  518. continue;
  519. state->events[i]++;
  520. dev_dbg_ratelimited(dev, "%s: %u\n",
  521. xcsi2rxss_events[i].name,
  522. state->events[i]);
  523. }
  524. if (status & XCSI_ISR_VCXFE && state->en_vcx) {
  525. u32 vcxstatus;
  526. vcxstatus = xcsi2rxss_read(state, XCSI_VCXR_OFFSET);
  527. vcxstatus &= XCSI_VCXR_VCERR;
  528. for (i = 0; i < XCSI_VCX_NUM_EVENTS; i++) {
  529. if (!(vcxstatus & BIT(i)))
  530. continue;
  531. state->vcx_events[i]++;
  532. }
  533. xcsi2rxss_write(state, XCSI_VCXR_OFFSET, vcxstatus);
  534. }
  535. }
  536. return IRQ_HANDLED;
  537. }
  538. /**
  539. * xcsi2rxss_s_stream - It is used to start/stop the streaming.
  540. * @sd: V4L2 Sub device
  541. * @enable: Flag (True / False)
  542. *
  543. * This function controls the start or stop of streaming for the
  544. * Xilinx MIPI CSI-2 Rx Subsystem.
  545. *
  546. * Return: 0 on success, errors otherwise
  547. */
  548. static int xcsi2rxss_s_stream(struct v4l2_subdev *sd, int enable)
  549. {
  550. struct xcsi2rxss_state *xcsi2rxss = to_xcsi2rxssstate(sd);
  551. int ret = 0;
  552. mutex_lock(&xcsi2rxss->lock);
  553. if (enable == xcsi2rxss->streaming)
  554. goto stream_done;
  555. if (enable) {
  556. xcsi2rxss_reset_event_counters(xcsi2rxss);
  557. ret = xcsi2rxss_start_stream(xcsi2rxss);
  558. } else {
  559. xcsi2rxss_stop_stream(xcsi2rxss);
  560. xcsi2rxss_hard_reset(xcsi2rxss);
  561. }
  562. stream_done:
  563. mutex_unlock(&xcsi2rxss->lock);
  564. return ret;
  565. }
  566. static struct v4l2_mbus_framefmt *
  567. __xcsi2rxss_get_pad_format(struct xcsi2rxss_state *xcsi2rxss,
  568. struct v4l2_subdev_state *sd_state,
  569. unsigned int pad, u32 which)
  570. {
  571. switch (which) {
  572. case V4L2_SUBDEV_FORMAT_TRY:
  573. return v4l2_subdev_get_try_format(&xcsi2rxss->subdev,
  574. sd_state, pad);
  575. case V4L2_SUBDEV_FORMAT_ACTIVE:
  576. return &xcsi2rxss->format;
  577. default:
  578. return NULL;
  579. }
  580. }
  581. /**
  582. * xcsi2rxss_init_cfg - Initialise the pad format config to default
  583. * @sd: Pointer to V4L2 Sub device structure
  584. * @sd_state: Pointer to sub device state structure
  585. *
  586. * This function is used to initialize the pad format with the default
  587. * values.
  588. *
  589. * Return: 0 on success
  590. */
  591. static int xcsi2rxss_init_cfg(struct v4l2_subdev *sd,
  592. struct v4l2_subdev_state *sd_state)
  593. {
  594. struct xcsi2rxss_state *xcsi2rxss = to_xcsi2rxssstate(sd);
  595. struct v4l2_mbus_framefmt *format;
  596. unsigned int i;
  597. mutex_lock(&xcsi2rxss->lock);
  598. for (i = 0; i < XCSI_MEDIA_PADS; i++) {
  599. format = v4l2_subdev_get_try_format(sd, sd_state, i);
  600. *format = xcsi2rxss->default_format;
  601. }
  602. mutex_unlock(&xcsi2rxss->lock);
  603. return 0;
  604. }
  605. /**
  606. * xcsi2rxss_get_format - Get the pad format
  607. * @sd: Pointer to V4L2 Sub device structure
  608. * @sd_state: Pointer to sub device state structure
  609. * @fmt: Pointer to pad level media bus format
  610. *
  611. * This function is used to get the pad format information.
  612. *
  613. * Return: 0 on success
  614. */
  615. static int xcsi2rxss_get_format(struct v4l2_subdev *sd,
  616. struct v4l2_subdev_state *sd_state,
  617. struct v4l2_subdev_format *fmt)
  618. {
  619. struct xcsi2rxss_state *xcsi2rxss = to_xcsi2rxssstate(sd);
  620. mutex_lock(&xcsi2rxss->lock);
  621. fmt->format = *__xcsi2rxss_get_pad_format(xcsi2rxss, sd_state,
  622. fmt->pad,
  623. fmt->which);
  624. mutex_unlock(&xcsi2rxss->lock);
  625. return 0;
  626. }
  627. /**
  628. * xcsi2rxss_set_format - This is used to set the pad format
  629. * @sd: Pointer to V4L2 Sub device structure
  630. * @sd_state: Pointer to sub device state structure
  631. * @fmt: Pointer to pad level media bus format
  632. *
  633. * This function is used to set the pad format. Since the pad format is fixed
  634. * in hardware, it can't be modified on run time. So when a format set is
  635. * requested by application, all parameters except the format type is saved
  636. * for the pad and the original pad format is sent back to the application.
  637. *
  638. * Return: 0 on success
  639. */
  640. static int xcsi2rxss_set_format(struct v4l2_subdev *sd,
  641. struct v4l2_subdev_state *sd_state,
  642. struct v4l2_subdev_format *fmt)
  643. {
  644. struct xcsi2rxss_state *xcsi2rxss = to_xcsi2rxssstate(sd);
  645. struct v4l2_mbus_framefmt *__format;
  646. u32 dt;
  647. mutex_lock(&xcsi2rxss->lock);
  648. /*
  649. * Only the format->code parameter matters for CSI as the
  650. * CSI format cannot be changed at runtime.
  651. * Ensure that format to set is copied to over to CSI pad format
  652. */
  653. __format = __xcsi2rxss_get_pad_format(xcsi2rxss, sd_state,
  654. fmt->pad, fmt->which);
  655. /* only sink pad format can be updated */
  656. if (fmt->pad == XVIP_PAD_SOURCE) {
  657. fmt->format = *__format;
  658. mutex_unlock(&xcsi2rxss->lock);
  659. return 0;
  660. }
  661. /*
  662. * RAW8 is supported in all datatypes. So if requested media bus format
  663. * is of RAW8 type, then allow to be set. In case core is configured to
  664. * other RAW, YUV422 8/10 or RGB888, set appropriate media bus format.
  665. */
  666. dt = xcsi2rxss_get_dt(fmt->format.code);
  667. if (dt != xcsi2rxss->datatype && dt != MIPI_CSI2_DT_RAW8) {
  668. dev_dbg(xcsi2rxss->dev, "Unsupported media bus format");
  669. /* set the default format for the data type */
  670. fmt->format.code = xcsi2rxss_get_nth_mbus(xcsi2rxss->datatype,
  671. 0);
  672. }
  673. *__format = fmt->format;
  674. mutex_unlock(&xcsi2rxss->lock);
  675. return 0;
  676. }
  677. /*
  678. * xcsi2rxss_enum_mbus_code - Handle pixel format enumeration
  679. * @sd: pointer to v4l2 subdev structure
  680. * @cfg: V4L2 subdev pad configuration
  681. * @code: pointer to v4l2_subdev_mbus_code_enum structure
  682. *
  683. * Return: -EINVAL or zero on success
  684. */
  685. static int xcsi2rxss_enum_mbus_code(struct v4l2_subdev *sd,
  686. struct v4l2_subdev_state *sd_state,
  687. struct v4l2_subdev_mbus_code_enum *code)
  688. {
  689. struct xcsi2rxss_state *state = to_xcsi2rxssstate(sd);
  690. u32 dt, n;
  691. int ret = 0;
  692. /* RAW8 dt packets are available in all DT configurations */
  693. if (code->index < 4) {
  694. n = code->index;
  695. dt = MIPI_CSI2_DT_RAW8;
  696. } else if (state->datatype != MIPI_CSI2_DT_RAW8) {
  697. n = code->index - 4;
  698. dt = state->datatype;
  699. } else {
  700. return -EINVAL;
  701. }
  702. code->code = xcsi2rxss_get_nth_mbus(dt, n);
  703. if (!code->code)
  704. ret = -EINVAL;
  705. return ret;
  706. }
  707. /* -----------------------------------------------------------------------------
  708. * Media Operations
  709. */
  710. static const struct media_entity_operations xcsi2rxss_media_ops = {
  711. .link_validate = v4l2_subdev_link_validate
  712. };
  713. static const struct v4l2_subdev_core_ops xcsi2rxss_core_ops = {
  714. .log_status = xcsi2rxss_log_status,
  715. };
  716. static const struct v4l2_subdev_video_ops xcsi2rxss_video_ops = {
  717. .s_stream = xcsi2rxss_s_stream
  718. };
  719. static const struct v4l2_subdev_pad_ops xcsi2rxss_pad_ops = {
  720. .init_cfg = xcsi2rxss_init_cfg,
  721. .get_fmt = xcsi2rxss_get_format,
  722. .set_fmt = xcsi2rxss_set_format,
  723. .enum_mbus_code = xcsi2rxss_enum_mbus_code,
  724. .link_validate = v4l2_subdev_link_validate_default,
  725. };
  726. static const struct v4l2_subdev_ops xcsi2rxss_ops = {
  727. .core = &xcsi2rxss_core_ops,
  728. .video = &xcsi2rxss_video_ops,
  729. .pad = &xcsi2rxss_pad_ops
  730. };
  731. static int xcsi2rxss_parse_of(struct xcsi2rxss_state *xcsi2rxss)
  732. {
  733. struct device *dev = xcsi2rxss->dev;
  734. struct device_node *node = dev->of_node;
  735. struct fwnode_handle *ep;
  736. struct v4l2_fwnode_endpoint vep = {
  737. .bus_type = V4L2_MBUS_CSI2_DPHY
  738. };
  739. bool en_csi_v20, vfb;
  740. int ret;
  741. en_csi_v20 = of_property_read_bool(node, "xlnx,en-csi-v2-0");
  742. if (en_csi_v20)
  743. xcsi2rxss->en_vcx = of_property_read_bool(node, "xlnx,en-vcx");
  744. xcsi2rxss->enable_active_lanes =
  745. of_property_read_bool(node, "xlnx,en-active-lanes");
  746. ret = of_property_read_u32(node, "xlnx,csi-pxl-format",
  747. &xcsi2rxss->datatype);
  748. if (ret < 0) {
  749. dev_err(dev, "missing xlnx,csi-pxl-format property\n");
  750. return ret;
  751. }
  752. switch (xcsi2rxss->datatype) {
  753. case MIPI_CSI2_DT_YUV422_8B:
  754. case MIPI_CSI2_DT_RGB444:
  755. case MIPI_CSI2_DT_RGB555:
  756. case MIPI_CSI2_DT_RGB565:
  757. case MIPI_CSI2_DT_RGB666:
  758. case MIPI_CSI2_DT_RGB888:
  759. case MIPI_CSI2_DT_RAW6:
  760. case MIPI_CSI2_DT_RAW7:
  761. case MIPI_CSI2_DT_RAW8:
  762. case MIPI_CSI2_DT_RAW10:
  763. case MIPI_CSI2_DT_RAW12:
  764. case MIPI_CSI2_DT_RAW14:
  765. break;
  766. case MIPI_CSI2_DT_YUV422_10B:
  767. case MIPI_CSI2_DT_RAW16:
  768. case MIPI_CSI2_DT_RAW20:
  769. if (!en_csi_v20) {
  770. ret = -EINVAL;
  771. dev_dbg(dev, "enable csi v2 for this pixel format");
  772. }
  773. break;
  774. default:
  775. ret = -EINVAL;
  776. }
  777. if (ret < 0) {
  778. dev_err(dev, "invalid csi-pxl-format property!\n");
  779. return ret;
  780. }
  781. vfb = of_property_read_bool(node, "xlnx,vfb");
  782. if (!vfb) {
  783. dev_err(dev, "operation without VFB is not supported\n");
  784. return -EINVAL;
  785. }
  786. ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(dev),
  787. XVIP_PAD_SINK, 0,
  788. FWNODE_GRAPH_ENDPOINT_NEXT);
  789. if (!ep) {
  790. dev_err(dev, "no sink port found");
  791. return -EINVAL;
  792. }
  793. ret = v4l2_fwnode_endpoint_parse(ep, &vep);
  794. fwnode_handle_put(ep);
  795. if (ret) {
  796. dev_err(dev, "error parsing sink port");
  797. return ret;
  798. }
  799. dev_dbg(dev, "mipi number lanes = %d\n",
  800. vep.bus.mipi_csi2.num_data_lanes);
  801. xcsi2rxss->max_num_lanes = vep.bus.mipi_csi2.num_data_lanes;
  802. ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(dev),
  803. XVIP_PAD_SOURCE, 0,
  804. FWNODE_GRAPH_ENDPOINT_NEXT);
  805. if (!ep) {
  806. dev_err(dev, "no source port found");
  807. return -EINVAL;
  808. }
  809. fwnode_handle_put(ep);
  810. dev_dbg(dev, "vcx %s, %u data lanes (%s), data type 0x%02x\n",
  811. xcsi2rxss->en_vcx ? "enabled" : "disabled",
  812. xcsi2rxss->max_num_lanes,
  813. xcsi2rxss->enable_active_lanes ? "dynamic" : "static",
  814. xcsi2rxss->datatype);
  815. return 0;
  816. }
  817. static int xcsi2rxss_probe(struct platform_device *pdev)
  818. {
  819. struct v4l2_subdev *subdev;
  820. struct xcsi2rxss_state *xcsi2rxss;
  821. int num_clks = ARRAY_SIZE(xcsi2rxss_clks);
  822. struct device *dev = &pdev->dev;
  823. int irq, ret;
  824. xcsi2rxss = devm_kzalloc(dev, sizeof(*xcsi2rxss), GFP_KERNEL);
  825. if (!xcsi2rxss)
  826. return -ENOMEM;
  827. xcsi2rxss->dev = dev;
  828. xcsi2rxss->clks = devm_kmemdup(dev, xcsi2rxss_clks,
  829. sizeof(xcsi2rxss_clks), GFP_KERNEL);
  830. if (!xcsi2rxss->clks)
  831. return -ENOMEM;
  832. /* Reset GPIO */
  833. xcsi2rxss->rst_gpio = devm_gpiod_get_optional(dev, "video-reset",
  834. GPIOD_OUT_HIGH);
  835. if (IS_ERR(xcsi2rxss->rst_gpio)) {
  836. if (PTR_ERR(xcsi2rxss->rst_gpio) != -EPROBE_DEFER)
  837. dev_err(dev, "Video Reset GPIO not setup in DT");
  838. return PTR_ERR(xcsi2rxss->rst_gpio);
  839. }
  840. ret = xcsi2rxss_parse_of(xcsi2rxss);
  841. if (ret < 0)
  842. return ret;
  843. xcsi2rxss->iomem = devm_platform_ioremap_resource(pdev, 0);
  844. if (IS_ERR(xcsi2rxss->iomem))
  845. return PTR_ERR(xcsi2rxss->iomem);
  846. irq = platform_get_irq(pdev, 0);
  847. if (irq < 0)
  848. return irq;
  849. ret = devm_request_threaded_irq(dev, irq, NULL,
  850. xcsi2rxss_irq_handler, IRQF_ONESHOT,
  851. dev_name(dev), xcsi2rxss);
  852. if (ret) {
  853. dev_err(dev, "Err = %d Interrupt handler reg failed!\n", ret);
  854. return ret;
  855. }
  856. ret = clk_bulk_get(dev, num_clks, xcsi2rxss->clks);
  857. if (ret)
  858. return ret;
  859. /* TODO: Enable/disable clocks at stream on/off time. */
  860. ret = clk_bulk_prepare_enable(num_clks, xcsi2rxss->clks);
  861. if (ret)
  862. goto err_clk_put;
  863. mutex_init(&xcsi2rxss->lock);
  864. xcsi2rxss_hard_reset(xcsi2rxss);
  865. xcsi2rxss_soft_reset(xcsi2rxss);
  866. /* Initialize V4L2 subdevice and media entity */
  867. xcsi2rxss->pads[XVIP_PAD_SINK].flags = MEDIA_PAD_FL_SINK;
  868. xcsi2rxss->pads[XVIP_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE;
  869. /* Initialize the default format */
  870. xcsi2rxss->default_format.code =
  871. xcsi2rxss_get_nth_mbus(xcsi2rxss->datatype, 0);
  872. xcsi2rxss->default_format.field = V4L2_FIELD_NONE;
  873. xcsi2rxss->default_format.colorspace = V4L2_COLORSPACE_SRGB;
  874. xcsi2rxss->default_format.width = XCSI_DEFAULT_WIDTH;
  875. xcsi2rxss->default_format.height = XCSI_DEFAULT_HEIGHT;
  876. xcsi2rxss->format = xcsi2rxss->default_format;
  877. /* Initialize V4L2 subdevice and media entity */
  878. subdev = &xcsi2rxss->subdev;
  879. v4l2_subdev_init(subdev, &xcsi2rxss_ops);
  880. subdev->dev = dev;
  881. strscpy(subdev->name, dev_name(dev), sizeof(subdev->name));
  882. subdev->flags |= V4L2_SUBDEV_FL_HAS_EVENTS | V4L2_SUBDEV_FL_HAS_DEVNODE;
  883. subdev->entity.ops = &xcsi2rxss_media_ops;
  884. v4l2_set_subdevdata(subdev, xcsi2rxss);
  885. ret = media_entity_pads_init(&subdev->entity, XCSI_MEDIA_PADS,
  886. xcsi2rxss->pads);
  887. if (ret < 0)
  888. goto error;
  889. platform_set_drvdata(pdev, xcsi2rxss);
  890. ret = v4l2_async_register_subdev(subdev);
  891. if (ret < 0) {
  892. dev_err(dev, "failed to register subdev\n");
  893. goto error;
  894. }
  895. return 0;
  896. error:
  897. media_entity_cleanup(&subdev->entity);
  898. mutex_destroy(&xcsi2rxss->lock);
  899. clk_bulk_disable_unprepare(num_clks, xcsi2rxss->clks);
  900. err_clk_put:
  901. clk_bulk_put(num_clks, xcsi2rxss->clks);
  902. return ret;
  903. }
  904. static int xcsi2rxss_remove(struct platform_device *pdev)
  905. {
  906. struct xcsi2rxss_state *xcsi2rxss = platform_get_drvdata(pdev);
  907. struct v4l2_subdev *subdev = &xcsi2rxss->subdev;
  908. int num_clks = ARRAY_SIZE(xcsi2rxss_clks);
  909. v4l2_async_unregister_subdev(subdev);
  910. media_entity_cleanup(&subdev->entity);
  911. mutex_destroy(&xcsi2rxss->lock);
  912. clk_bulk_disable_unprepare(num_clks, xcsi2rxss->clks);
  913. clk_bulk_put(num_clks, xcsi2rxss->clks);
  914. return 0;
  915. }
  916. static const struct of_device_id xcsi2rxss_of_id_table[] = {
  917. { .compatible = "xlnx,mipi-csi2-rx-subsystem-5.0", },
  918. { }
  919. };
  920. MODULE_DEVICE_TABLE(of, xcsi2rxss_of_id_table);
  921. static struct platform_driver xcsi2rxss_driver = {
  922. .driver = {
  923. .name = "xilinx-csi2rxss",
  924. .of_match_table = xcsi2rxss_of_id_table,
  925. },
  926. .probe = xcsi2rxss_probe,
  927. .remove = xcsi2rxss_remove,
  928. };
  929. module_platform_driver(xcsi2rxss_driver);
  930. MODULE_AUTHOR("Vishal Sagar <[email protected]>");
  931. MODULE_DESCRIPTION("Xilinx MIPI CSI-2 Rx Subsystem Driver");
  932. MODULE_LICENSE("GPL v2");