renesas-ceu.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * V4L2 Driver for Renesas Capture Engine Unit (CEU) interface
  4. * Copyright (C) 2017-2018 Jacopo Mondi <jacopo+renesas@jmondi.org>
  5. *
  6. * Based on soc-camera driver "soc_camera/sh_mobile_ceu_camera.c"
  7. * Copyright (C) 2008 Magnus Damm
  8. *
  9. * Based on V4L2 Driver for PXA camera host - "pxa_camera.c",
  10. * Copyright (C) 2006, Sascha Hauer, Pengutronix
  11. * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
  12. */
  13. #include <linux/delay.h>
  14. #include <linux/device.h>
  15. #include <linux/dma-mapping.h>
  16. #include <linux/err.h>
  17. #include <linux/errno.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/io.h>
  20. #include <linux/kernel.h>
  21. #include <linux/mm.h>
  22. #include <linux/module.h>
  23. #include <linux/of.h>
  24. #include <linux/of_device.h>
  25. #include <linux/of_graph.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/pm_runtime.h>
  28. #include <linux/slab.h>
  29. #include <linux/time.h>
  30. #include <linux/videodev2.h>
  31. #include <media/v4l2-async.h>
  32. #include <media/v4l2-common.h>
  33. #include <media/v4l2-ctrls.h>
  34. #include <media/v4l2-dev.h>
  35. #include <media/v4l2-device.h>
  36. #include <media/v4l2-event.h>
  37. #include <media/v4l2-fwnode.h>
  38. #include <media/v4l2-image-sizes.h>
  39. #include <media/v4l2-ioctl.h>
  40. #include <media/v4l2-mediabus.h>
  41. #include <media/videobuf2-dma-contig.h>
  42. #include <media/drv-intf/renesas-ceu.h>
  43. #define DRIVER_NAME "renesas-ceu"
  44. /* CEU registers offsets and masks. */
  45. #define CEU_CAPSR 0x00 /* Capture start register */
  46. #define CEU_CAPCR 0x04 /* Capture control register */
  47. #define CEU_CAMCR 0x08 /* Capture interface control register */
  48. #define CEU_CAMOR 0x10 /* Capture interface offset register */
  49. #define CEU_CAPWR 0x14 /* Capture interface width register */
  50. #define CEU_CAIFR 0x18 /* Capture interface input format register */
  51. #define CEU_CRCNTR 0x28 /* CEU register control register */
  52. #define CEU_CRCMPR 0x2c /* CEU register forcible control register */
  53. #define CEU_CFLCR 0x30 /* Capture filter control register */
  54. #define CEU_CFSZR 0x34 /* Capture filter size clip register */
  55. #define CEU_CDWDR 0x38 /* Capture destination width register */
  56. #define CEU_CDAYR 0x3c /* Capture data address Y register */
  57. #define CEU_CDACR 0x40 /* Capture data address C register */
  58. #define CEU_CFWCR 0x5c /* Firewall operation control register */
  59. #define CEU_CDOCR 0x64 /* Capture data output control register */
  60. #define CEU_CEIER 0x70 /* Capture event interrupt enable register */
  61. #define CEU_CETCR 0x74 /* Capture event flag clear register */
  62. #define CEU_CSTSR 0x7c /* Capture status register */
  63. #define CEU_CSRTR 0x80 /* Capture software reset register */
  64. /* Data synchronous fetch mode. */
  65. #define CEU_CAMCR_JPEG BIT(4)
  66. /* Input components ordering: CEU_CAMCR.DTARY field. */
  67. #define CEU_CAMCR_DTARY_8_UYVY (0x00 << 8)
  68. #define CEU_CAMCR_DTARY_8_VYUY (0x01 << 8)
  69. #define CEU_CAMCR_DTARY_8_YUYV (0x02 << 8)
  70. #define CEU_CAMCR_DTARY_8_YVYU (0x03 << 8)
  71. /* TODO: input components ordering for 16 bits input. */
  72. /* Bus transfer MTU. */
  73. #define CEU_CAPCR_BUS_WIDTH256 (0x3 << 20)
  74. /* Bus width configuration. */
  75. #define CEU_CAMCR_DTIF_16BITS BIT(12)
  76. /* No downsampling to planar YUV420 in image fetch mode. */
  77. #define CEU_CDOCR_NO_DOWSAMPLE BIT(4)
  78. /* Swap all input data in 8-bit, 16-bits and 32-bits units (Figure 46.45). */
  79. #define CEU_CDOCR_SWAP_ENDIANNESS (7)
  80. /* Capture reset and enable bits. */
  81. #define CEU_CAPSR_CPKIL BIT(16)
  82. #define CEU_CAPSR_CE BIT(0)
  83. /* CEU operating flag bit. */
  84. #define CEU_CAPCR_CTNCP BIT(16)
  85. #define CEU_CSTRST_CPTON BIT(0)
  86. /* Platform specific IRQ source flags. */
  87. #define CEU_CETCR_ALL_IRQS_RZ 0x397f313
  88. #define CEU_CETCR_ALL_IRQS_SH4 0x3d7f313
  89. /* Prohibited register access interrupt bit. */
  90. #define CEU_CETCR_IGRW BIT(4)
  91. /* One-frame capture end interrupt. */
  92. #define CEU_CEIER_CPE BIT(0)
  93. /* VBP error. */
  94. #define CEU_CEIER_VBP BIT(20)
  95. #define CEU_CEIER_MASK (CEU_CEIER_CPE | CEU_CEIER_VBP)
  96. #define CEU_MAX_WIDTH 2560
  97. #define CEU_MAX_HEIGHT 1920
  98. #define CEU_MAX_BPL 8188
  99. #define CEU_W_MAX(w) ((w) < CEU_MAX_WIDTH ? (w) : CEU_MAX_WIDTH)
  100. #define CEU_H_MAX(h) ((h) < CEU_MAX_HEIGHT ? (h) : CEU_MAX_HEIGHT)
  101. /*
  102. * ceu_bus_fmt - describe a 8-bits yuyv format the sensor can produce
  103. *
  104. * @mbus_code: bus format code
  105. * @fmt_order: CEU_CAMCR.DTARY ordering of input components (Y, Cb, Cr)
  106. * @fmt_order_swap: swapped CEU_CAMCR.DTARY ordering of input components
  107. * (Y, Cr, Cb)
  108. * @swapped: does Cr appear before Cb?
  109. * @bps: number of bits sent over bus for each sample
  110. * @bpp: number of bits per pixels unit
  111. */
  112. struct ceu_mbus_fmt {
  113. u32 mbus_code;
  114. u32 fmt_order;
  115. u32 fmt_order_swap;
  116. bool swapped;
  117. u8 bps;
  118. u8 bpp;
  119. };
  120. /*
  121. * ceu_buffer - Link vb2 buffer to the list of available buffers.
  122. */
  123. struct ceu_buffer {
  124. struct vb2_v4l2_buffer vb;
  125. struct list_head queue;
  126. };
  127. static inline struct ceu_buffer *vb2_to_ceu(struct vb2_v4l2_buffer *vbuf)
  128. {
  129. return container_of(vbuf, struct ceu_buffer, vb);
  130. }
  131. /*
  132. * ceu_subdev - Wraps v4l2 sub-device and provides async subdevice.
  133. */
  134. struct ceu_subdev {
  135. struct v4l2_subdev *v4l2_sd;
  136. struct v4l2_async_subdev asd;
  137. /* per-subdevice mbus configuration options */
  138. unsigned int mbus_flags;
  139. struct ceu_mbus_fmt mbus_fmt;
  140. };
  141. static struct ceu_subdev *to_ceu_subdev(struct v4l2_async_subdev *asd)
  142. {
  143. return container_of(asd, struct ceu_subdev, asd);
  144. }
  145. /*
  146. * ceu_device - CEU device instance
  147. */
  148. struct ceu_device {
  149. struct device *dev;
  150. struct video_device vdev;
  151. struct v4l2_device v4l2_dev;
  152. /* subdevices descriptors */
  153. struct ceu_subdev *subdevs;
  154. /* the subdevice currently in use */
  155. struct ceu_subdev *sd;
  156. unsigned int sd_index;
  157. unsigned int num_sd;
  158. /* platform specific mask with all IRQ sources flagged */
  159. u32 irq_mask;
  160. /* currently configured field and pixel format */
  161. enum v4l2_field field;
  162. struct v4l2_pix_format_mplane v4l2_pix;
  163. /* async subdev notification helpers */
  164. struct v4l2_async_notifier notifier;
  165. /* pointers to "struct ceu_subdevice -> asd" */
  166. struct v4l2_async_subdev **asds;
  167. /* vb2 queue, capture buffer list and active buffer pointer */
  168. struct vb2_queue vb2_vq;
  169. struct list_head capture;
  170. struct vb2_v4l2_buffer *active;
  171. unsigned int sequence;
  172. /* mlock - lock access to interface reset and vb2 queue */
  173. struct mutex mlock;
  174. /* lock - lock access to capture buffer queue and active buffer */
  175. spinlock_t lock;
  176. /* base - CEU memory base address */
  177. void __iomem *base;
  178. };
  179. static inline struct ceu_device *v4l2_to_ceu(struct v4l2_device *v4l2_dev)
  180. {
  181. return container_of(v4l2_dev, struct ceu_device, v4l2_dev);
  182. }
  183. /* --- CEU memory output formats --- */
  184. /*
  185. * ceu_fmt - describe a memory output format supported by CEU interface.
  186. *
  187. * @fourcc: memory layout fourcc format code
  188. * @bpp: number of bits for each pixel stored in memory
  189. */
  190. struct ceu_fmt {
  191. u32 fourcc;
  192. u32 bpp;
  193. };
  194. /*
  195. * ceu_format_list - List of supported memory output formats
  196. *
  197. * If sensor provides any YUYV bus format, all the following planar memory
  198. * formats are available thanks to CEU re-ordering and sub-sampling
  199. * capabilities.
  200. */
  201. static const struct ceu_fmt ceu_fmt_list[] = {
  202. {
  203. .fourcc = V4L2_PIX_FMT_NV16,
  204. .bpp = 16,
  205. },
  206. {
  207. .fourcc = V4L2_PIX_FMT_NV61,
  208. .bpp = 16,
  209. },
  210. {
  211. .fourcc = V4L2_PIX_FMT_NV12,
  212. .bpp = 12,
  213. },
  214. {
  215. .fourcc = V4L2_PIX_FMT_NV21,
  216. .bpp = 12,
  217. },
  218. {
  219. .fourcc = V4L2_PIX_FMT_YUYV,
  220. .bpp = 16,
  221. },
  222. {
  223. .fourcc = V4L2_PIX_FMT_UYVY,
  224. .bpp = 16,
  225. },
  226. {
  227. .fourcc = V4L2_PIX_FMT_YVYU,
  228. .bpp = 16,
  229. },
  230. {
  231. .fourcc = V4L2_PIX_FMT_VYUY,
  232. .bpp = 16,
  233. },
  234. };
  235. static const struct ceu_fmt *get_ceu_fmt_from_fourcc(unsigned int fourcc)
  236. {
  237. const struct ceu_fmt *fmt = &ceu_fmt_list[0];
  238. unsigned int i;
  239. for (i = 0; i < ARRAY_SIZE(ceu_fmt_list); i++, fmt++)
  240. if (fmt->fourcc == fourcc)
  241. return fmt;
  242. return NULL;
  243. }
  244. static bool ceu_fmt_mplane(struct v4l2_pix_format_mplane *pix)
  245. {
  246. switch (pix->pixelformat) {
  247. case V4L2_PIX_FMT_YUYV:
  248. case V4L2_PIX_FMT_UYVY:
  249. case V4L2_PIX_FMT_YVYU:
  250. case V4L2_PIX_FMT_VYUY:
  251. return false;
  252. case V4L2_PIX_FMT_NV16:
  253. case V4L2_PIX_FMT_NV61:
  254. case V4L2_PIX_FMT_NV12:
  255. case V4L2_PIX_FMT_NV21:
  256. return true;
  257. default:
  258. return false;
  259. }
  260. }
  261. /* --- CEU HW operations --- */
  262. static void ceu_write(struct ceu_device *priv, unsigned int reg_offs, u32 data)
  263. {
  264. iowrite32(data, priv->base + reg_offs);
  265. }
  266. static u32 ceu_read(struct ceu_device *priv, unsigned int reg_offs)
  267. {
  268. return ioread32(priv->base + reg_offs);
  269. }
  270. /*
  271. * ceu_soft_reset() - Software reset the CEU interface.
  272. * @ceu_device: CEU device.
  273. *
  274. * Returns 0 for success, -EIO for error.
  275. */
  276. static int ceu_soft_reset(struct ceu_device *ceudev)
  277. {
  278. unsigned int i;
  279. ceu_write(ceudev, CEU_CAPSR, CEU_CAPSR_CPKIL);
  280. for (i = 0; i < 100; i++) {
  281. if (!(ceu_read(ceudev, CEU_CSTSR) & CEU_CSTRST_CPTON))
  282. break;
  283. udelay(1);
  284. }
  285. if (i == 100) {
  286. dev_err(ceudev->dev, "soft reset time out\n");
  287. return -EIO;
  288. }
  289. for (i = 0; i < 100; i++) {
  290. if (!(ceu_read(ceudev, CEU_CAPSR) & CEU_CAPSR_CPKIL))
  291. return 0;
  292. udelay(1);
  293. }
  294. /* If we get here, CEU has not reset properly. */
  295. return -EIO;
  296. }
  297. /* --- CEU Capture Operations --- */
  298. /*
  299. * ceu_hw_config() - Configure CEU interface registers.
  300. */
  301. static int ceu_hw_config(struct ceu_device *ceudev)
  302. {
  303. u32 camcr, cdocr, cfzsr, cdwdr, capwr;
  304. struct v4l2_pix_format_mplane *pix = &ceudev->v4l2_pix;
  305. struct ceu_subdev *ceu_sd = ceudev->sd;
  306. struct ceu_mbus_fmt *mbus_fmt = &ceu_sd->mbus_fmt;
  307. unsigned int mbus_flags = ceu_sd->mbus_flags;
  308. /* Start configuring CEU registers */
  309. ceu_write(ceudev, CEU_CAIFR, 0);
  310. ceu_write(ceudev, CEU_CFWCR, 0);
  311. ceu_write(ceudev, CEU_CRCNTR, 0);
  312. ceu_write(ceudev, CEU_CRCMPR, 0);
  313. /* Set the frame capture period for both image capture and data sync. */
  314. capwr = (pix->height << 16) | pix->width * mbus_fmt->bpp / 8;
  315. /*
  316. * Swap input data endianness by default.
  317. * In data fetch mode bytes are received in chunks of 8 bytes.
  318. * D0, D1, D2, D3, D4, D5, D6, D7 (D0 received first)
  319. * The data is however by default written to memory in reverse order:
  320. * D7, D6, D5, D4, D3, D2, D1, D0 (D7 written to lowest byte)
  321. *
  322. * Use CEU_CDOCR[2:0] to swap data ordering.
  323. */
  324. cdocr = CEU_CDOCR_SWAP_ENDIANNESS;
  325. /*
  326. * Configure CAMCR and CDOCR:
  327. * match input components ordering with memory output format and
  328. * handle downsampling to YUV420.
  329. *
  330. * If the memory output planar format is 'swapped' (Cr before Cb) and
  331. * input format is not, use the swapped version of CAMCR.DTARY.
  332. *
  333. * If the memory output planar format is not 'swapped' (Cb before Cr)
  334. * and input format is, use the swapped version of CAMCR.DTARY.
  335. *
  336. * CEU by default downsample to planar YUV420 (CDCOR[4] = 0).
  337. * If output is planar YUV422 set CDOCR[4] = 1
  338. *
  339. * No downsample for data fetch sync mode.
  340. */
  341. switch (pix->pixelformat) {
  342. /* Data fetch sync mode */
  343. case V4L2_PIX_FMT_YUYV:
  344. case V4L2_PIX_FMT_YVYU:
  345. case V4L2_PIX_FMT_UYVY:
  346. case V4L2_PIX_FMT_VYUY:
  347. camcr = CEU_CAMCR_JPEG;
  348. cdocr |= CEU_CDOCR_NO_DOWSAMPLE;
  349. cfzsr = (pix->height << 16) | pix->width;
  350. cdwdr = pix->plane_fmt[0].bytesperline;
  351. break;
  352. /* Non-swapped planar image capture mode. */
  353. case V4L2_PIX_FMT_NV16:
  354. cdocr |= CEU_CDOCR_NO_DOWSAMPLE;
  355. /* fall-through */
  356. case V4L2_PIX_FMT_NV12:
  357. if (mbus_fmt->swapped)
  358. camcr = mbus_fmt->fmt_order_swap;
  359. else
  360. camcr = mbus_fmt->fmt_order;
  361. cfzsr = (pix->height << 16) | pix->width;
  362. cdwdr = pix->width;
  363. break;
  364. /* Swapped planar image capture mode. */
  365. case V4L2_PIX_FMT_NV61:
  366. cdocr |= CEU_CDOCR_NO_DOWSAMPLE;
  367. /* fall-through */
  368. case V4L2_PIX_FMT_NV21:
  369. if (mbus_fmt->swapped)
  370. camcr = mbus_fmt->fmt_order;
  371. else
  372. camcr = mbus_fmt->fmt_order_swap;
  373. cfzsr = (pix->height << 16) | pix->width;
  374. cdwdr = pix->width;
  375. break;
  376. default:
  377. return -EINVAL;
  378. }
  379. camcr |= mbus_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW ? 1 << 1 : 0;
  380. camcr |= mbus_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW ? 1 << 0 : 0;
  381. /* TODO: handle 16 bit bus width with DTIF bit in CAMCR */
  382. ceu_write(ceudev, CEU_CAMCR, camcr);
  383. ceu_write(ceudev, CEU_CDOCR, cdocr);
  384. ceu_write(ceudev, CEU_CAPCR, CEU_CAPCR_BUS_WIDTH256);
  385. /*
  386. * TODO: make CAMOR offsets configurable.
  387. * CAMOR wants to know the number of blanks between a VS/HS signal
  388. * and valid data. This value should actually come from the sensor...
  389. */
  390. ceu_write(ceudev, CEU_CAMOR, 0);
  391. /* TODO: 16 bit bus width require re-calculation of cdwdr and cfzsr */
  392. ceu_write(ceudev, CEU_CAPWR, capwr);
  393. ceu_write(ceudev, CEU_CFSZR, cfzsr);
  394. ceu_write(ceudev, CEU_CDWDR, cdwdr);
  395. return 0;
  396. }
  397. /*
  398. * ceu_capture() - Trigger start of a capture sequence.
  399. *
  400. * Program the CEU DMA registers with addresses where to transfer image data.
  401. */
  402. static int ceu_capture(struct ceu_device *ceudev)
  403. {
  404. struct v4l2_pix_format_mplane *pix = &ceudev->v4l2_pix;
  405. dma_addr_t phys_addr_top;
  406. phys_addr_top =
  407. vb2_dma_contig_plane_dma_addr(&ceudev->active->vb2_buf, 0);
  408. ceu_write(ceudev, CEU_CDAYR, phys_addr_top);
  409. /* Ignore CbCr plane for non multi-planar image formats. */
  410. if (ceu_fmt_mplane(pix)) {
  411. phys_addr_top =
  412. vb2_dma_contig_plane_dma_addr(&ceudev->active->vb2_buf,
  413. 1);
  414. ceu_write(ceudev, CEU_CDACR, phys_addr_top);
  415. }
  416. /*
  417. * Trigger new capture start: once for each frame, as we work in
  418. * one-frame capture mode.
  419. */
  420. ceu_write(ceudev, CEU_CAPSR, CEU_CAPSR_CE);
  421. return 0;
  422. }
  423. static irqreturn_t ceu_irq(int irq, void *data)
  424. {
  425. struct ceu_device *ceudev = data;
  426. struct vb2_v4l2_buffer *vbuf;
  427. struct ceu_buffer *buf;
  428. u32 status;
  429. /* Clean interrupt status. */
  430. status = ceu_read(ceudev, CEU_CETCR);
  431. ceu_write(ceudev, CEU_CETCR, ~ceudev->irq_mask);
  432. /* Unexpected interrupt. */
  433. if (!(status & CEU_CEIER_MASK))
  434. return IRQ_NONE;
  435. spin_lock(&ceudev->lock);
  436. /* Stale interrupt from a released buffer, ignore it. */
  437. vbuf = ceudev->active;
  438. if (!vbuf) {
  439. spin_unlock(&ceudev->lock);
  440. return IRQ_HANDLED;
  441. }
  442. /*
  443. * When a VBP interrupt occurs, no capture end interrupt will occur
  444. * and the image of that frame is not captured correctly.
  445. */
  446. if (status & CEU_CEIER_VBP) {
  447. dev_err(ceudev->dev, "VBP interrupt: abort capture\n");
  448. goto error_irq_out;
  449. }
  450. /* Prepare to return the 'previous' buffer. */
  451. vbuf->vb2_buf.timestamp = ktime_get_ns();
  452. vbuf->sequence = ceudev->sequence++;
  453. vbuf->field = ceudev->field;
  454. /* Prepare a new 'active' buffer and trigger a new capture. */
  455. if (!list_empty(&ceudev->capture)) {
  456. buf = list_first_entry(&ceudev->capture, struct ceu_buffer,
  457. queue);
  458. list_del(&buf->queue);
  459. ceudev->active = &buf->vb;
  460. ceu_capture(ceudev);
  461. }
  462. /* Return the 'previous' buffer. */
  463. vb2_buffer_done(&vbuf->vb2_buf, VB2_BUF_STATE_DONE);
  464. spin_unlock(&ceudev->lock);
  465. return IRQ_HANDLED;
  466. error_irq_out:
  467. /* Return the 'previous' buffer and all queued ones. */
  468. vb2_buffer_done(&vbuf->vb2_buf, VB2_BUF_STATE_ERROR);
  469. list_for_each_entry(buf, &ceudev->capture, queue)
  470. vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
  471. spin_unlock(&ceudev->lock);
  472. return IRQ_HANDLED;
  473. }
  474. /* --- CEU Videobuf2 operations --- */
  475. static void ceu_update_plane_sizes(struct v4l2_plane_pix_format *plane,
  476. unsigned int bpl, unsigned int szimage)
  477. {
  478. memset(plane, 0, sizeof(*plane));
  479. plane->sizeimage = szimage;
  480. if (plane->bytesperline < bpl || plane->bytesperline > CEU_MAX_BPL)
  481. plane->bytesperline = bpl;
  482. }
  483. /*
  484. * ceu_calc_plane_sizes() - Fill per-plane 'struct v4l2_plane_pix_format'
  485. * information according to the currently configured
  486. * pixel format.
  487. * @ceu_device: CEU device.
  488. * @ceu_fmt: Active image format.
  489. * @pix: Pixel format information (store line width and image sizes)
  490. */
  491. static void ceu_calc_plane_sizes(struct ceu_device *ceudev,
  492. const struct ceu_fmt *ceu_fmt,
  493. struct v4l2_pix_format_mplane *pix)
  494. {
  495. unsigned int bpl, szimage;
  496. switch (pix->pixelformat) {
  497. case V4L2_PIX_FMT_YUYV:
  498. case V4L2_PIX_FMT_UYVY:
  499. case V4L2_PIX_FMT_YVYU:
  500. case V4L2_PIX_FMT_VYUY:
  501. pix->num_planes = 1;
  502. bpl = pix->width * ceu_fmt->bpp / 8;
  503. szimage = pix->height * bpl;
  504. ceu_update_plane_sizes(&pix->plane_fmt[0], bpl, szimage);
  505. break;
  506. case V4L2_PIX_FMT_NV12:
  507. case V4L2_PIX_FMT_NV21:
  508. pix->num_planes = 2;
  509. bpl = pix->width;
  510. szimage = pix->height * pix->width;
  511. ceu_update_plane_sizes(&pix->plane_fmt[0], bpl, szimage);
  512. ceu_update_plane_sizes(&pix->plane_fmt[1], bpl, szimage / 2);
  513. break;
  514. case V4L2_PIX_FMT_NV16:
  515. case V4L2_PIX_FMT_NV61:
  516. default:
  517. pix->num_planes = 2;
  518. bpl = pix->width;
  519. szimage = pix->height * pix->width;
  520. ceu_update_plane_sizes(&pix->plane_fmt[0], bpl, szimage);
  521. ceu_update_plane_sizes(&pix->plane_fmt[1], bpl, szimage);
  522. break;
  523. }
  524. }
  525. /*
  526. * ceu_vb2_setup() - is called to check whether the driver can accept the
  527. * requested number of buffers and to fill in plane sizes
  528. * for the current frame format, if required.
  529. */
  530. static int ceu_vb2_setup(struct vb2_queue *vq, unsigned int *count,
  531. unsigned int *num_planes, unsigned int sizes[],
  532. struct device *alloc_devs[])
  533. {
  534. struct ceu_device *ceudev = vb2_get_drv_priv(vq);
  535. struct v4l2_pix_format_mplane *pix = &ceudev->v4l2_pix;
  536. unsigned int i;
  537. /* num_planes is set: just check plane sizes. */
  538. if (*num_planes) {
  539. for (i = 0; i < pix->num_planes; i++)
  540. if (sizes[i] < pix->plane_fmt[i].sizeimage)
  541. return -EINVAL;
  542. return 0;
  543. }
  544. /* num_planes not set: called from REQBUFS, just set plane sizes. */
  545. *num_planes = pix->num_planes;
  546. for (i = 0; i < pix->num_planes; i++)
  547. sizes[i] = pix->plane_fmt[i].sizeimage;
  548. return 0;
  549. }
  550. static void ceu_vb2_queue(struct vb2_buffer *vb)
  551. {
  552. struct ceu_device *ceudev = vb2_get_drv_priv(vb->vb2_queue);
  553. struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
  554. struct ceu_buffer *buf = vb2_to_ceu(vbuf);
  555. unsigned long irqflags;
  556. spin_lock_irqsave(&ceudev->lock, irqflags);
  557. list_add_tail(&buf->queue, &ceudev->capture);
  558. spin_unlock_irqrestore(&ceudev->lock, irqflags);
  559. }
  560. static int ceu_vb2_prepare(struct vb2_buffer *vb)
  561. {
  562. struct ceu_device *ceudev = vb2_get_drv_priv(vb->vb2_queue);
  563. struct v4l2_pix_format_mplane *pix = &ceudev->v4l2_pix;
  564. unsigned int i;
  565. for (i = 0; i < pix->num_planes; i++) {
  566. if (vb2_plane_size(vb, i) < pix->plane_fmt[i].sizeimage) {
  567. dev_err(ceudev->dev,
  568. "Plane size too small (%lu < %u)\n",
  569. vb2_plane_size(vb, i),
  570. pix->plane_fmt[i].sizeimage);
  571. return -EINVAL;
  572. }
  573. vb2_set_plane_payload(vb, i, pix->plane_fmt[i].sizeimage);
  574. }
  575. return 0;
  576. }
  577. static int ceu_start_streaming(struct vb2_queue *vq, unsigned int count)
  578. {
  579. struct ceu_device *ceudev = vb2_get_drv_priv(vq);
  580. struct v4l2_subdev *v4l2_sd = ceudev->sd->v4l2_sd;
  581. struct ceu_buffer *buf;
  582. unsigned long irqflags;
  583. int ret;
  584. /* Program the CEU interface according to the CEU image format. */
  585. ret = ceu_hw_config(ceudev);
  586. if (ret)
  587. goto error_return_bufs;
  588. ret = v4l2_subdev_call(v4l2_sd, video, s_stream, 1);
  589. if (ret && ret != -ENOIOCTLCMD) {
  590. dev_dbg(ceudev->dev,
  591. "Subdevice failed to start streaming: %d\n", ret);
  592. goto error_return_bufs;
  593. }
  594. spin_lock_irqsave(&ceudev->lock, irqflags);
  595. ceudev->sequence = 0;
  596. /* Grab the first available buffer and trigger the first capture. */
  597. buf = list_first_entry(&ceudev->capture, struct ceu_buffer,
  598. queue);
  599. if (!buf) {
  600. spin_unlock_irqrestore(&ceudev->lock, irqflags);
  601. dev_dbg(ceudev->dev,
  602. "No buffer available for capture.\n");
  603. goto error_stop_sensor;
  604. }
  605. list_del(&buf->queue);
  606. ceudev->active = &buf->vb;
  607. /* Clean and program interrupts for first capture. */
  608. ceu_write(ceudev, CEU_CETCR, ~ceudev->irq_mask);
  609. ceu_write(ceudev, CEU_CEIER, CEU_CEIER_MASK);
  610. ceu_capture(ceudev);
  611. spin_unlock_irqrestore(&ceudev->lock, irqflags);
  612. return 0;
  613. error_stop_sensor:
  614. v4l2_subdev_call(v4l2_sd, video, s_stream, 0);
  615. error_return_bufs:
  616. spin_lock_irqsave(&ceudev->lock, irqflags);
  617. list_for_each_entry(buf, &ceudev->capture, queue)
  618. vb2_buffer_done(&ceudev->active->vb2_buf,
  619. VB2_BUF_STATE_QUEUED);
  620. ceudev->active = NULL;
  621. spin_unlock_irqrestore(&ceudev->lock, irqflags);
  622. return ret;
  623. }
  624. static void ceu_stop_streaming(struct vb2_queue *vq)
  625. {
  626. struct ceu_device *ceudev = vb2_get_drv_priv(vq);
  627. struct v4l2_subdev *v4l2_sd = ceudev->sd->v4l2_sd;
  628. struct ceu_buffer *buf;
  629. unsigned long irqflags;
  630. /* Clean and disable interrupt sources. */
  631. ceu_write(ceudev, CEU_CETCR,
  632. ceu_read(ceudev, CEU_CETCR) & ceudev->irq_mask);
  633. ceu_write(ceudev, CEU_CEIER, CEU_CEIER_MASK);
  634. v4l2_subdev_call(v4l2_sd, video, s_stream, 0);
  635. spin_lock_irqsave(&ceudev->lock, irqflags);
  636. if (ceudev->active) {
  637. vb2_buffer_done(&ceudev->active->vb2_buf,
  638. VB2_BUF_STATE_ERROR);
  639. ceudev->active = NULL;
  640. }
  641. /* Release all queued buffers. */
  642. list_for_each_entry(buf, &ceudev->capture, queue)
  643. vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
  644. INIT_LIST_HEAD(&ceudev->capture);
  645. spin_unlock_irqrestore(&ceudev->lock, irqflags);
  646. ceu_soft_reset(ceudev);
  647. }
  648. static const struct vb2_ops ceu_vb2_ops = {
  649. .queue_setup = ceu_vb2_setup,
  650. .buf_queue = ceu_vb2_queue,
  651. .buf_prepare = ceu_vb2_prepare,
  652. .wait_prepare = vb2_ops_wait_prepare,
  653. .wait_finish = vb2_ops_wait_finish,
  654. .start_streaming = ceu_start_streaming,
  655. .stop_streaming = ceu_stop_streaming,
  656. };
  657. /* --- CEU image formats handling --- */
  658. /*
  659. * __ceu_try_fmt() - test format on CEU and sensor
  660. * @ceudev: The CEU device.
  661. * @v4l2_fmt: format to test.
  662. * @sd_mbus_code: the media bus code accepted by the subdevice; output param.
  663. *
  664. * Returns 0 for success, < 0 for errors.
  665. */
  666. static int __ceu_try_fmt(struct ceu_device *ceudev, struct v4l2_format *v4l2_fmt,
  667. u32 *sd_mbus_code)
  668. {
  669. struct ceu_subdev *ceu_sd = ceudev->sd;
  670. struct v4l2_pix_format_mplane *pix = &v4l2_fmt->fmt.pix_mp;
  671. struct v4l2_subdev *v4l2_sd = ceu_sd->v4l2_sd;
  672. struct v4l2_subdev_pad_config pad_cfg;
  673. const struct ceu_fmt *ceu_fmt;
  674. u32 mbus_code_old;
  675. u32 mbus_code;
  676. int ret;
  677. /*
  678. * Set format on sensor sub device: bus format used to produce memory
  679. * format is selected depending on YUV component ordering or
  680. * at initialization time.
  681. */
  682. struct v4l2_subdev_format sd_format = {
  683. .which = V4L2_SUBDEV_FORMAT_TRY,
  684. };
  685. mbus_code_old = ceu_sd->mbus_fmt.mbus_code;
  686. switch (pix->pixelformat) {
  687. case V4L2_PIX_FMT_YUYV:
  688. mbus_code = MEDIA_BUS_FMT_YUYV8_2X8;
  689. break;
  690. case V4L2_PIX_FMT_UYVY:
  691. mbus_code = MEDIA_BUS_FMT_UYVY8_2X8;
  692. break;
  693. case V4L2_PIX_FMT_YVYU:
  694. mbus_code = MEDIA_BUS_FMT_YVYU8_2X8;
  695. break;
  696. case V4L2_PIX_FMT_VYUY:
  697. mbus_code = MEDIA_BUS_FMT_VYUY8_2X8;
  698. break;
  699. case V4L2_PIX_FMT_NV16:
  700. case V4L2_PIX_FMT_NV61:
  701. case V4L2_PIX_FMT_NV12:
  702. case V4L2_PIX_FMT_NV21:
  703. mbus_code = ceu_sd->mbus_fmt.mbus_code;
  704. break;
  705. default:
  706. pix->pixelformat = V4L2_PIX_FMT_NV16;
  707. mbus_code = ceu_sd->mbus_fmt.mbus_code;
  708. break;
  709. }
  710. ceu_fmt = get_ceu_fmt_from_fourcc(pix->pixelformat);
  711. /* CFSZR requires height and width to be 4-pixel aligned. */
  712. v4l_bound_align_image(&pix->width, 2, CEU_MAX_WIDTH, 4,
  713. &pix->height, 4, CEU_MAX_HEIGHT, 4, 0);
  714. v4l2_fill_mbus_format_mplane(&sd_format.format, pix);
  715. /*
  716. * Try with the mbus_code matching YUYV components ordering first,
  717. * if that one fails, fallback to default selected at initialization
  718. * time.
  719. */
  720. sd_format.format.code = mbus_code;
  721. ret = v4l2_subdev_call(v4l2_sd, pad, set_fmt, &pad_cfg, &sd_format);
  722. if (ret) {
  723. if (ret == -EINVAL) {
  724. /* fallback */
  725. sd_format.format.code = mbus_code_old;
  726. ret = v4l2_subdev_call(v4l2_sd, pad, set_fmt,
  727. &pad_cfg, &sd_format);
  728. }
  729. if (ret)
  730. return ret;
  731. }
  732. /* Apply size returned by sensor as the CEU can't scale. */
  733. v4l2_fill_pix_format_mplane(pix, &sd_format.format);
  734. /* Calculate per-plane sizes based on image format. */
  735. ceu_calc_plane_sizes(ceudev, ceu_fmt, pix);
  736. /* Report to caller the configured mbus format. */
  737. *sd_mbus_code = sd_format.format.code;
  738. return 0;
  739. }
  740. /*
  741. * ceu_try_fmt() - Wrapper for __ceu_try_fmt; discard configured mbus_fmt
  742. */
  743. static int ceu_try_fmt(struct ceu_device *ceudev, struct v4l2_format *v4l2_fmt)
  744. {
  745. u32 mbus_code;
  746. return __ceu_try_fmt(ceudev, v4l2_fmt, &mbus_code);
  747. }
  748. /*
  749. * ceu_set_fmt() - Apply the supplied format to both sensor and CEU
  750. */
  751. static int ceu_set_fmt(struct ceu_device *ceudev, struct v4l2_format *v4l2_fmt)
  752. {
  753. struct ceu_subdev *ceu_sd = ceudev->sd;
  754. struct v4l2_subdev *v4l2_sd = ceu_sd->v4l2_sd;
  755. u32 mbus_code;
  756. int ret;
  757. /*
  758. * Set format on sensor sub device: bus format used to produce memory
  759. * format is selected at initialization time.
  760. */
  761. struct v4l2_subdev_format format = {
  762. .which = V4L2_SUBDEV_FORMAT_ACTIVE,
  763. };
  764. ret = __ceu_try_fmt(ceudev, v4l2_fmt, &mbus_code);
  765. if (ret)
  766. return ret;
  767. format.format.code = mbus_code;
  768. v4l2_fill_mbus_format_mplane(&format.format, &v4l2_fmt->fmt.pix_mp);
  769. ret = v4l2_subdev_call(v4l2_sd, pad, set_fmt, NULL, &format);
  770. if (ret)
  771. return ret;
  772. ceudev->v4l2_pix = v4l2_fmt->fmt.pix_mp;
  773. ceudev->field = V4L2_FIELD_NONE;
  774. return 0;
  775. }
  776. /*
  777. * ceu_set_default_fmt() - Apply default NV16 memory output format with VGA
  778. * sizes.
  779. */
  780. static int ceu_set_default_fmt(struct ceu_device *ceudev)
  781. {
  782. int ret;
  783. struct v4l2_format v4l2_fmt = {
  784. .type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
  785. .fmt.pix_mp = {
  786. .width = VGA_WIDTH,
  787. .height = VGA_HEIGHT,
  788. .field = V4L2_FIELD_NONE,
  789. .pixelformat = V4L2_PIX_FMT_NV16,
  790. .num_planes = 2,
  791. .plane_fmt = {
  792. [0] = {
  793. .sizeimage = VGA_WIDTH * VGA_HEIGHT * 2,
  794. .bytesperline = VGA_WIDTH * 2,
  795. },
  796. [1] = {
  797. .sizeimage = VGA_WIDTH * VGA_HEIGHT * 2,
  798. .bytesperline = VGA_WIDTH * 2,
  799. },
  800. },
  801. },
  802. };
  803. ret = ceu_try_fmt(ceudev, &v4l2_fmt);
  804. if (ret)
  805. return ret;
  806. ceudev->v4l2_pix = v4l2_fmt.fmt.pix_mp;
  807. ceudev->field = V4L2_FIELD_NONE;
  808. return 0;
  809. }
  810. /*
  811. * ceu_init_mbus_fmt() - Query sensor for supported formats and initialize
  812. * CEU media bus format used to produce memory formats.
  813. *
  814. * Find out if sensor can produce a permutation of 8-bits YUYV bus format.
  815. * From a single 8-bits YUYV bus format the CEU can produce several memory
  816. * output formats:
  817. * - NV[12|21|16|61] through image fetch mode;
  818. * - YUYV422 if sensor provides YUYV422
  819. *
  820. * TODO: Other YUYV422 permutations through data fetch sync mode and DTARY
  821. * TODO: Binary data (eg. JPEG) and raw formats through data fetch sync mode
  822. */
  823. static int ceu_init_mbus_fmt(struct ceu_device *ceudev)
  824. {
  825. struct ceu_subdev *ceu_sd = ceudev->sd;
  826. struct ceu_mbus_fmt *mbus_fmt = &ceu_sd->mbus_fmt;
  827. struct v4l2_subdev *v4l2_sd = ceu_sd->v4l2_sd;
  828. bool yuyv_bus_fmt = false;
  829. struct v4l2_subdev_mbus_code_enum sd_mbus_fmt = {
  830. .which = V4L2_SUBDEV_FORMAT_ACTIVE,
  831. .index = 0,
  832. };
  833. /* Find out if sensor can produce any permutation of 8-bits YUYV422. */
  834. while (!yuyv_bus_fmt &&
  835. !v4l2_subdev_call(v4l2_sd, pad, enum_mbus_code,
  836. NULL, &sd_mbus_fmt)) {
  837. switch (sd_mbus_fmt.code) {
  838. case MEDIA_BUS_FMT_YUYV8_2X8:
  839. case MEDIA_BUS_FMT_YVYU8_2X8:
  840. case MEDIA_BUS_FMT_UYVY8_2X8:
  841. case MEDIA_BUS_FMT_VYUY8_2X8:
  842. yuyv_bus_fmt = true;
  843. break;
  844. default:
  845. /*
  846. * Only support 8-bits YUYV bus formats at the moment;
  847. *
  848. * TODO: add support for binary formats (data sync
  849. * fetch mode).
  850. */
  851. break;
  852. }
  853. sd_mbus_fmt.index++;
  854. }
  855. if (!yuyv_bus_fmt)
  856. return -ENXIO;
  857. /*
  858. * Save the first encountered YUYV format as "mbus_fmt" and use it
  859. * to output all planar YUV422 and YUV420 (NV*) formats to memory as
  860. * well as for data synch fetch mode (YUYV - YVYU etc. ).
  861. */
  862. mbus_fmt->mbus_code = sd_mbus_fmt.code;
  863. mbus_fmt->bps = 8;
  864. /* Annotate the selected bus format components ordering. */
  865. switch (sd_mbus_fmt.code) {
  866. case MEDIA_BUS_FMT_YUYV8_2X8:
  867. mbus_fmt->fmt_order = CEU_CAMCR_DTARY_8_YUYV;
  868. mbus_fmt->fmt_order_swap = CEU_CAMCR_DTARY_8_YVYU;
  869. mbus_fmt->swapped = false;
  870. mbus_fmt->bpp = 16;
  871. break;
  872. case MEDIA_BUS_FMT_YVYU8_2X8:
  873. mbus_fmt->fmt_order = CEU_CAMCR_DTARY_8_YVYU;
  874. mbus_fmt->fmt_order_swap = CEU_CAMCR_DTARY_8_YUYV;
  875. mbus_fmt->swapped = true;
  876. mbus_fmt->bpp = 16;
  877. break;
  878. case MEDIA_BUS_FMT_UYVY8_2X8:
  879. mbus_fmt->fmt_order = CEU_CAMCR_DTARY_8_UYVY;
  880. mbus_fmt->fmt_order_swap = CEU_CAMCR_DTARY_8_VYUY;
  881. mbus_fmt->swapped = false;
  882. mbus_fmt->bpp = 16;
  883. break;
  884. case MEDIA_BUS_FMT_VYUY8_2X8:
  885. mbus_fmt->fmt_order = CEU_CAMCR_DTARY_8_VYUY;
  886. mbus_fmt->fmt_order_swap = CEU_CAMCR_DTARY_8_UYVY;
  887. mbus_fmt->swapped = true;
  888. mbus_fmt->bpp = 16;
  889. break;
  890. }
  891. return 0;
  892. }
  893. /* --- Runtime PM Handlers --- */
  894. /*
  895. * ceu_runtime_resume() - soft-reset the interface and turn sensor power on.
  896. */
  897. static int __maybe_unused ceu_runtime_resume(struct device *dev)
  898. {
  899. struct ceu_device *ceudev = dev_get_drvdata(dev);
  900. struct v4l2_subdev *v4l2_sd = ceudev->sd->v4l2_sd;
  901. v4l2_subdev_call(v4l2_sd, core, s_power, 1);
  902. ceu_soft_reset(ceudev);
  903. return 0;
  904. }
  905. /*
  906. * ceu_runtime_suspend() - disable capture and interrupts and soft-reset.
  907. * Turn sensor power off.
  908. */
  909. static int __maybe_unused ceu_runtime_suspend(struct device *dev)
  910. {
  911. struct ceu_device *ceudev = dev_get_drvdata(dev);
  912. struct v4l2_subdev *v4l2_sd = ceudev->sd->v4l2_sd;
  913. v4l2_subdev_call(v4l2_sd, core, s_power, 0);
  914. ceu_write(ceudev, CEU_CEIER, 0);
  915. ceu_soft_reset(ceudev);
  916. return 0;
  917. }
  918. /* --- File Operations --- */
  919. static int ceu_open(struct file *file)
  920. {
  921. struct ceu_device *ceudev = video_drvdata(file);
  922. int ret;
  923. ret = v4l2_fh_open(file);
  924. if (ret)
  925. return ret;
  926. mutex_lock(&ceudev->mlock);
  927. /* Causes soft-reset and sensor power on on first open */
  928. pm_runtime_get_sync(ceudev->dev);
  929. mutex_unlock(&ceudev->mlock);
  930. return 0;
  931. }
  932. static int ceu_release(struct file *file)
  933. {
  934. struct ceu_device *ceudev = video_drvdata(file);
  935. vb2_fop_release(file);
  936. mutex_lock(&ceudev->mlock);
  937. /* Causes soft-reset and sensor power down on last close */
  938. pm_runtime_put(ceudev->dev);
  939. mutex_unlock(&ceudev->mlock);
  940. return 0;
  941. }
  942. static const struct v4l2_file_operations ceu_fops = {
  943. .owner = THIS_MODULE,
  944. .open = ceu_open,
  945. .release = ceu_release,
  946. .unlocked_ioctl = video_ioctl2,
  947. .mmap = vb2_fop_mmap,
  948. .poll = vb2_fop_poll,
  949. };
  950. /* --- Video Device IOCTLs --- */
  951. static int ceu_querycap(struct file *file, void *priv,
  952. struct v4l2_capability *cap)
  953. {
  954. struct ceu_device *ceudev = video_drvdata(file);
  955. strlcpy(cap->card, "Renesas CEU", sizeof(cap->card));
  956. strlcpy(cap->driver, DRIVER_NAME, sizeof(cap->driver));
  957. snprintf(cap->bus_info, sizeof(cap->bus_info),
  958. "platform:renesas-ceu-%s", dev_name(ceudev->dev));
  959. return 0;
  960. }
  961. static int ceu_enum_fmt_vid_cap(struct file *file, void *priv,
  962. struct v4l2_fmtdesc *f)
  963. {
  964. const struct ceu_fmt *fmt;
  965. if (f->index >= ARRAY_SIZE(ceu_fmt_list))
  966. return -EINVAL;
  967. fmt = &ceu_fmt_list[f->index];
  968. f->pixelformat = fmt->fourcc;
  969. return 0;
  970. }
  971. static int ceu_try_fmt_vid_cap(struct file *file, void *priv,
  972. struct v4l2_format *f)
  973. {
  974. struct ceu_device *ceudev = video_drvdata(file);
  975. return ceu_try_fmt(ceudev, f);
  976. }
  977. static int ceu_s_fmt_vid_cap(struct file *file, void *priv,
  978. struct v4l2_format *f)
  979. {
  980. struct ceu_device *ceudev = video_drvdata(file);
  981. if (vb2_is_streaming(&ceudev->vb2_vq))
  982. return -EBUSY;
  983. return ceu_set_fmt(ceudev, f);
  984. }
  985. static int ceu_g_fmt_vid_cap(struct file *file, void *priv,
  986. struct v4l2_format *f)
  987. {
  988. struct ceu_device *ceudev = video_drvdata(file);
  989. f->fmt.pix_mp = ceudev->v4l2_pix;
  990. return 0;
  991. }
  992. static int ceu_enum_input(struct file *file, void *priv,
  993. struct v4l2_input *inp)
  994. {
  995. struct ceu_device *ceudev = video_drvdata(file);
  996. struct ceu_subdev *ceusd;
  997. if (inp->index >= ceudev->num_sd)
  998. return -EINVAL;
  999. ceusd = &ceudev->subdevs[inp->index];
  1000. inp->type = V4L2_INPUT_TYPE_CAMERA;
  1001. inp->std = 0;
  1002. snprintf(inp->name, sizeof(inp->name), "Camera%u: %s",
  1003. inp->index, ceusd->v4l2_sd->name);
  1004. return 0;
  1005. }
  1006. static int ceu_g_input(struct file *file, void *priv, unsigned int *i)
  1007. {
  1008. struct ceu_device *ceudev = video_drvdata(file);
  1009. *i = ceudev->sd_index;
  1010. return 0;
  1011. }
  1012. static int ceu_s_input(struct file *file, void *priv, unsigned int i)
  1013. {
  1014. struct ceu_device *ceudev = video_drvdata(file);
  1015. struct ceu_subdev *ceu_sd_old;
  1016. int ret;
  1017. if (i >= ceudev->num_sd)
  1018. return -EINVAL;
  1019. if (vb2_is_streaming(&ceudev->vb2_vq))
  1020. return -EBUSY;
  1021. if (i == ceudev->sd_index)
  1022. return 0;
  1023. ceu_sd_old = ceudev->sd;
  1024. ceudev->sd = &ceudev->subdevs[i];
  1025. /*
  1026. * Make sure we can generate output image formats and apply
  1027. * default one.
  1028. */
  1029. ret = ceu_init_mbus_fmt(ceudev);
  1030. if (ret) {
  1031. ceudev->sd = ceu_sd_old;
  1032. return -EINVAL;
  1033. }
  1034. ret = ceu_set_default_fmt(ceudev);
  1035. if (ret) {
  1036. ceudev->sd = ceu_sd_old;
  1037. return -EINVAL;
  1038. }
  1039. /* Now that we're sure we can use the sensor, power off the old one. */
  1040. v4l2_subdev_call(ceu_sd_old->v4l2_sd, core, s_power, 0);
  1041. v4l2_subdev_call(ceudev->sd->v4l2_sd, core, s_power, 1);
  1042. ceudev->sd_index = i;
  1043. return 0;
  1044. }
  1045. static int ceu_g_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
  1046. {
  1047. struct ceu_device *ceudev = video_drvdata(file);
  1048. return v4l2_g_parm_cap(video_devdata(file), ceudev->sd->v4l2_sd, a);
  1049. }
  1050. static int ceu_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
  1051. {
  1052. struct ceu_device *ceudev = video_drvdata(file);
  1053. return v4l2_s_parm_cap(video_devdata(file), ceudev->sd->v4l2_sd, a);
  1054. }
  1055. static int ceu_enum_framesizes(struct file *file, void *fh,
  1056. struct v4l2_frmsizeenum *fsize)
  1057. {
  1058. struct ceu_device *ceudev = video_drvdata(file);
  1059. struct ceu_subdev *ceu_sd = ceudev->sd;
  1060. const struct ceu_fmt *ceu_fmt;
  1061. struct v4l2_subdev *v4l2_sd = ceu_sd->v4l2_sd;
  1062. int ret;
  1063. struct v4l2_subdev_frame_size_enum fse = {
  1064. .code = ceu_sd->mbus_fmt.mbus_code,
  1065. .index = fsize->index,
  1066. .which = V4L2_SUBDEV_FORMAT_ACTIVE,
  1067. };
  1068. /* Just check if user supplied pixel format is supported. */
  1069. ceu_fmt = get_ceu_fmt_from_fourcc(fsize->pixel_format);
  1070. if (!ceu_fmt)
  1071. return -EINVAL;
  1072. ret = v4l2_subdev_call(v4l2_sd, pad, enum_frame_size,
  1073. NULL, &fse);
  1074. if (ret)
  1075. return ret;
  1076. fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
  1077. fsize->discrete.width = CEU_W_MAX(fse.max_width);
  1078. fsize->discrete.height = CEU_H_MAX(fse.max_height);
  1079. return 0;
  1080. }
  1081. static int ceu_enum_frameintervals(struct file *file, void *fh,
  1082. struct v4l2_frmivalenum *fival)
  1083. {
  1084. struct ceu_device *ceudev = video_drvdata(file);
  1085. struct ceu_subdev *ceu_sd = ceudev->sd;
  1086. const struct ceu_fmt *ceu_fmt;
  1087. struct v4l2_subdev *v4l2_sd = ceu_sd->v4l2_sd;
  1088. int ret;
  1089. struct v4l2_subdev_frame_interval_enum fie = {
  1090. .code = ceu_sd->mbus_fmt.mbus_code,
  1091. .index = fival->index,
  1092. .width = fival->width,
  1093. .height = fival->height,
  1094. .which = V4L2_SUBDEV_FORMAT_ACTIVE,
  1095. };
  1096. /* Just check if user supplied pixel format is supported. */
  1097. ceu_fmt = get_ceu_fmt_from_fourcc(fival->pixel_format);
  1098. if (!ceu_fmt)
  1099. return -EINVAL;
  1100. ret = v4l2_subdev_call(v4l2_sd, pad, enum_frame_interval, NULL,
  1101. &fie);
  1102. if (ret)
  1103. return ret;
  1104. fival->type = V4L2_FRMIVAL_TYPE_DISCRETE;
  1105. fival->discrete = fie.interval;
  1106. return 0;
  1107. }
  1108. static const struct v4l2_ioctl_ops ceu_ioctl_ops = {
  1109. .vidioc_querycap = ceu_querycap,
  1110. .vidioc_enum_fmt_vid_cap_mplane = ceu_enum_fmt_vid_cap,
  1111. .vidioc_try_fmt_vid_cap_mplane = ceu_try_fmt_vid_cap,
  1112. .vidioc_s_fmt_vid_cap_mplane = ceu_s_fmt_vid_cap,
  1113. .vidioc_g_fmt_vid_cap_mplane = ceu_g_fmt_vid_cap,
  1114. .vidioc_enum_input = ceu_enum_input,
  1115. .vidioc_g_input = ceu_g_input,
  1116. .vidioc_s_input = ceu_s_input,
  1117. .vidioc_reqbufs = vb2_ioctl_reqbufs,
  1118. .vidioc_querybuf = vb2_ioctl_querybuf,
  1119. .vidioc_qbuf = vb2_ioctl_qbuf,
  1120. .vidioc_expbuf = vb2_ioctl_expbuf,
  1121. .vidioc_dqbuf = vb2_ioctl_dqbuf,
  1122. .vidioc_create_bufs = vb2_ioctl_create_bufs,
  1123. .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
  1124. .vidioc_streamon = vb2_ioctl_streamon,
  1125. .vidioc_streamoff = vb2_ioctl_streamoff,
  1126. .vidioc_g_parm = ceu_g_parm,
  1127. .vidioc_s_parm = ceu_s_parm,
  1128. .vidioc_enum_framesizes = ceu_enum_framesizes,
  1129. .vidioc_enum_frameintervals = ceu_enum_frameintervals,
  1130. .vidioc_log_status = v4l2_ctrl_log_status,
  1131. .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
  1132. .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
  1133. };
  1134. /*
  1135. * ceu_vdev_release() - release CEU video device memory when last reference
  1136. * to this driver is closed
  1137. */
  1138. static void ceu_vdev_release(struct video_device *vdev)
  1139. {
  1140. struct ceu_device *ceudev = video_get_drvdata(vdev);
  1141. kfree(ceudev);
  1142. }
  1143. static int ceu_notify_bound(struct v4l2_async_notifier *notifier,
  1144. struct v4l2_subdev *v4l2_sd,
  1145. struct v4l2_async_subdev *asd)
  1146. {
  1147. struct v4l2_device *v4l2_dev = notifier->v4l2_dev;
  1148. struct ceu_device *ceudev = v4l2_to_ceu(v4l2_dev);
  1149. struct ceu_subdev *ceu_sd = to_ceu_subdev(asd);
  1150. ceu_sd->v4l2_sd = v4l2_sd;
  1151. ceudev->num_sd++;
  1152. return 0;
  1153. }
  1154. static int ceu_notify_complete(struct v4l2_async_notifier *notifier)
  1155. {
  1156. struct v4l2_device *v4l2_dev = notifier->v4l2_dev;
  1157. struct ceu_device *ceudev = v4l2_to_ceu(v4l2_dev);
  1158. struct video_device *vdev = &ceudev->vdev;
  1159. struct vb2_queue *q = &ceudev->vb2_vq;
  1160. struct v4l2_subdev *v4l2_sd;
  1161. int ret;
  1162. /* Initialize vb2 queue. */
  1163. q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
  1164. q->io_modes = VB2_MMAP | VB2_DMABUF;
  1165. q->drv_priv = ceudev;
  1166. q->ops = &ceu_vb2_ops;
  1167. q->mem_ops = &vb2_dma_contig_memops;
  1168. q->buf_struct_size = sizeof(struct ceu_buffer);
  1169. q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
  1170. q->min_buffers_needed = 2;
  1171. q->lock = &ceudev->mlock;
  1172. q->dev = ceudev->v4l2_dev.dev;
  1173. ret = vb2_queue_init(q);
  1174. if (ret)
  1175. return ret;
  1176. /*
  1177. * Make sure at least one sensor is primary and use it to initialize
  1178. * ceu formats.
  1179. */
  1180. if (!ceudev->sd) {
  1181. ceudev->sd = &ceudev->subdevs[0];
  1182. ceudev->sd_index = 0;
  1183. }
  1184. v4l2_sd = ceudev->sd->v4l2_sd;
  1185. ret = ceu_init_mbus_fmt(ceudev);
  1186. if (ret)
  1187. return ret;
  1188. ret = ceu_set_default_fmt(ceudev);
  1189. if (ret)
  1190. return ret;
  1191. /* Register the video device. */
  1192. strlcpy(vdev->name, DRIVER_NAME, sizeof(vdev->name));
  1193. vdev->v4l2_dev = v4l2_dev;
  1194. vdev->lock = &ceudev->mlock;
  1195. vdev->queue = &ceudev->vb2_vq;
  1196. vdev->ctrl_handler = v4l2_sd->ctrl_handler;
  1197. vdev->fops = &ceu_fops;
  1198. vdev->ioctl_ops = &ceu_ioctl_ops;
  1199. vdev->release = ceu_vdev_release;
  1200. vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE_MPLANE |
  1201. V4L2_CAP_STREAMING;
  1202. video_set_drvdata(vdev, ceudev);
  1203. ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
  1204. if (ret < 0) {
  1205. v4l2_err(vdev->v4l2_dev,
  1206. "video_register_device failed: %d\n", ret);
  1207. return ret;
  1208. }
  1209. return 0;
  1210. }
  1211. static const struct v4l2_async_notifier_operations ceu_notify_ops = {
  1212. .bound = ceu_notify_bound,
  1213. .complete = ceu_notify_complete,
  1214. };
  1215. /*
  1216. * ceu_init_async_subdevs() - Initialize CEU subdevices and async_subdevs in
  1217. * ceu device. Both DT and platform data parsing use
  1218. * this routine.
  1219. *
  1220. * Returns 0 for success, -ENOMEM for failure.
  1221. */
  1222. static int ceu_init_async_subdevs(struct ceu_device *ceudev, unsigned int n_sd)
  1223. {
  1224. /* Reserve memory for 'n_sd' ceu_subdev descriptors. */
  1225. ceudev->subdevs = devm_kcalloc(ceudev->dev, n_sd,
  1226. sizeof(*ceudev->subdevs), GFP_KERNEL);
  1227. if (!ceudev->subdevs)
  1228. return -ENOMEM;
  1229. /*
  1230. * Reserve memory for 'n_sd' pointers to async_subdevices.
  1231. * ceudev->asds members will point to &ceu_subdev.asd
  1232. */
  1233. ceudev->asds = devm_kcalloc(ceudev->dev, n_sd,
  1234. sizeof(*ceudev->asds), GFP_KERNEL);
  1235. if (!ceudev->asds)
  1236. return -ENOMEM;
  1237. ceudev->sd = NULL;
  1238. ceudev->sd_index = 0;
  1239. ceudev->num_sd = 0;
  1240. return 0;
  1241. }
  1242. /*
  1243. * ceu_parse_platform_data() - Initialize async_subdevices using platform
  1244. * device provided data.
  1245. */
  1246. static int ceu_parse_platform_data(struct ceu_device *ceudev,
  1247. const struct ceu_platform_data *pdata)
  1248. {
  1249. const struct ceu_async_subdev *async_sd;
  1250. struct ceu_subdev *ceu_sd;
  1251. unsigned int i;
  1252. int ret;
  1253. if (pdata->num_subdevs == 0)
  1254. return -ENODEV;
  1255. ret = ceu_init_async_subdevs(ceudev, pdata->num_subdevs);
  1256. if (ret)
  1257. return ret;
  1258. for (i = 0; i < pdata->num_subdevs; i++) {
  1259. /* Setup the ceu subdevice and the async subdevice. */
  1260. async_sd = &pdata->subdevs[i];
  1261. ceu_sd = &ceudev->subdevs[i];
  1262. INIT_LIST_HEAD(&ceu_sd->asd.list);
  1263. ceu_sd->mbus_flags = async_sd->flags;
  1264. ceu_sd->asd.match_type = V4L2_ASYNC_MATCH_I2C;
  1265. ceu_sd->asd.match.i2c.adapter_id = async_sd->i2c_adapter_id;
  1266. ceu_sd->asd.match.i2c.address = async_sd->i2c_address;
  1267. ceudev->asds[i] = &ceu_sd->asd;
  1268. }
  1269. return pdata->num_subdevs;
  1270. }
  1271. /*
  1272. * ceu_parse_dt() - Initialize async_subdevs parsing device tree graph.
  1273. */
  1274. static int ceu_parse_dt(struct ceu_device *ceudev)
  1275. {
  1276. struct device_node *of = ceudev->dev->of_node;
  1277. struct v4l2_fwnode_endpoint fw_ep;
  1278. struct ceu_subdev *ceu_sd;
  1279. struct device_node *ep;
  1280. unsigned int i;
  1281. int num_ep;
  1282. int ret;
  1283. num_ep = of_graph_get_endpoint_count(of);
  1284. if (!num_ep)
  1285. return -ENODEV;
  1286. ret = ceu_init_async_subdevs(ceudev, num_ep);
  1287. if (ret)
  1288. return ret;
  1289. for (i = 0; i < num_ep; i++) {
  1290. ep = of_graph_get_endpoint_by_regs(of, 0, i);
  1291. if (!ep) {
  1292. dev_err(ceudev->dev,
  1293. "No subdevice connected on endpoint %u.\n", i);
  1294. ret = -ENODEV;
  1295. goto error_put_node;
  1296. }
  1297. ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep), &fw_ep);
  1298. if (ret) {
  1299. dev_err(ceudev->dev,
  1300. "Unable to parse endpoint #%u.\n", i);
  1301. goto error_put_node;
  1302. }
  1303. if (fw_ep.bus_type != V4L2_MBUS_PARALLEL) {
  1304. dev_err(ceudev->dev,
  1305. "Only parallel input supported.\n");
  1306. ret = -EINVAL;
  1307. goto error_put_node;
  1308. }
  1309. /* Setup the ceu subdevice and the async subdevice. */
  1310. ceu_sd = &ceudev->subdevs[i];
  1311. INIT_LIST_HEAD(&ceu_sd->asd.list);
  1312. ceu_sd->mbus_flags = fw_ep.bus.parallel.flags;
  1313. ceu_sd->asd.match_type = V4L2_ASYNC_MATCH_FWNODE;
  1314. ceu_sd->asd.match.fwnode =
  1315. fwnode_graph_get_remote_port_parent(
  1316. of_fwnode_handle(ep));
  1317. ceudev->asds[i] = &ceu_sd->asd;
  1318. of_node_put(ep);
  1319. }
  1320. return num_ep;
  1321. error_put_node:
  1322. of_node_put(ep);
  1323. return ret;
  1324. }
  1325. /*
  1326. * struct ceu_data - Platform specific CEU data
  1327. * @irq_mask: CETCR mask with all interrupt sources enabled. The mask differs
  1328. * between SH4 and RZ platforms.
  1329. */
  1330. struct ceu_data {
  1331. u32 irq_mask;
  1332. };
  1333. static const struct ceu_data ceu_data_rz = {
  1334. .irq_mask = CEU_CETCR_ALL_IRQS_RZ,
  1335. };
  1336. static const struct ceu_data ceu_data_sh4 = {
  1337. .irq_mask = CEU_CETCR_ALL_IRQS_SH4,
  1338. };
  1339. #if IS_ENABLED(CONFIG_OF)
  1340. static const struct of_device_id ceu_of_match[] = {
  1341. { .compatible = "renesas,r7s72100-ceu", .data = &ceu_data_rz },
  1342. { .compatible = "renesas,r8a7740-ceu", .data = &ceu_data_rz },
  1343. { }
  1344. };
  1345. MODULE_DEVICE_TABLE(of, ceu_of_match);
  1346. #endif
  1347. static int ceu_probe(struct platform_device *pdev)
  1348. {
  1349. struct device *dev = &pdev->dev;
  1350. const struct ceu_data *ceu_data;
  1351. struct ceu_device *ceudev;
  1352. struct resource *res;
  1353. unsigned int irq;
  1354. int num_subdevs;
  1355. int ret;
  1356. ceudev = kzalloc(sizeof(*ceudev), GFP_KERNEL);
  1357. if (!ceudev)
  1358. return -ENOMEM;
  1359. platform_set_drvdata(pdev, ceudev);
  1360. ceudev->dev = dev;
  1361. INIT_LIST_HEAD(&ceudev->capture);
  1362. spin_lock_init(&ceudev->lock);
  1363. mutex_init(&ceudev->mlock);
  1364. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1365. ceudev->base = devm_ioremap_resource(dev, res);
  1366. if (IS_ERR(ceudev->base)) {
  1367. ret = PTR_ERR(ceudev->base);
  1368. goto error_free_ceudev;
  1369. }
  1370. ret = platform_get_irq(pdev, 0);
  1371. if (ret < 0) {
  1372. dev_err(dev, "Failed to get irq: %d\n", ret);
  1373. goto error_free_ceudev;
  1374. }
  1375. irq = ret;
  1376. ret = devm_request_irq(dev, irq, ceu_irq,
  1377. 0, dev_name(dev), ceudev);
  1378. if (ret) {
  1379. dev_err(&pdev->dev, "Unable to request CEU interrupt.\n");
  1380. goto error_free_ceudev;
  1381. }
  1382. pm_runtime_enable(dev);
  1383. ret = v4l2_device_register(dev, &ceudev->v4l2_dev);
  1384. if (ret)
  1385. goto error_pm_disable;
  1386. if (IS_ENABLED(CONFIG_OF) && dev->of_node) {
  1387. ceu_data = of_match_device(ceu_of_match, dev)->data;
  1388. num_subdevs = ceu_parse_dt(ceudev);
  1389. } else if (dev->platform_data) {
  1390. /* Assume SH4 if booting with platform data. */
  1391. ceu_data = &ceu_data_sh4;
  1392. num_subdevs = ceu_parse_platform_data(ceudev,
  1393. dev->platform_data);
  1394. } else {
  1395. num_subdevs = -EINVAL;
  1396. }
  1397. if (num_subdevs < 0) {
  1398. ret = num_subdevs;
  1399. goto error_v4l2_unregister;
  1400. }
  1401. ceudev->irq_mask = ceu_data->irq_mask;
  1402. ceudev->notifier.v4l2_dev = &ceudev->v4l2_dev;
  1403. ceudev->notifier.subdevs = ceudev->asds;
  1404. ceudev->notifier.num_subdevs = num_subdevs;
  1405. ceudev->notifier.ops = &ceu_notify_ops;
  1406. ret = v4l2_async_notifier_register(&ceudev->v4l2_dev,
  1407. &ceudev->notifier);
  1408. if (ret)
  1409. goto error_v4l2_unregister;
  1410. dev_info(dev, "Renesas Capture Engine Unit %s\n", dev_name(dev));
  1411. return 0;
  1412. error_v4l2_unregister:
  1413. v4l2_device_unregister(&ceudev->v4l2_dev);
  1414. error_pm_disable:
  1415. pm_runtime_disable(dev);
  1416. error_free_ceudev:
  1417. kfree(ceudev);
  1418. return ret;
  1419. }
  1420. static int ceu_remove(struct platform_device *pdev)
  1421. {
  1422. struct ceu_device *ceudev = platform_get_drvdata(pdev);
  1423. pm_runtime_disable(ceudev->dev);
  1424. v4l2_async_notifier_unregister(&ceudev->notifier);
  1425. v4l2_device_unregister(&ceudev->v4l2_dev);
  1426. video_unregister_device(&ceudev->vdev);
  1427. return 0;
  1428. }
  1429. static const struct dev_pm_ops ceu_pm_ops = {
  1430. SET_RUNTIME_PM_OPS(ceu_runtime_suspend,
  1431. ceu_runtime_resume,
  1432. NULL)
  1433. };
  1434. static struct platform_driver ceu_driver = {
  1435. .driver = {
  1436. .name = DRIVER_NAME,
  1437. .pm = &ceu_pm_ops,
  1438. .of_match_table = of_match_ptr(ceu_of_match),
  1439. },
  1440. .probe = ceu_probe,
  1441. .remove = ceu_remove,
  1442. };
  1443. module_platform_driver(ceu_driver);
  1444. MODULE_DESCRIPTION("Renesas CEU camera driver");
  1445. MODULE_AUTHOR("Jacopo Mondi <jacopo+renesas@jmondi.org>");
  1446. MODULE_LICENSE("GPL v2");