sh_mobile_ceu_camera.c 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300
  1. /*
  2. * V4L2 Driver for SuperH Mobile CEU interface
  3. *
  4. * Copyright (C) 2008 Magnus Damm
  5. *
  6. * Based on V4L2 Driver for PXA camera host - "pxa_camera.c",
  7. *
  8. * Copyright (C) 2006, Sascha Hauer, Pengutronix
  9. * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. */
  16. #include <linux/init.h>
  17. #include <linux/module.h>
  18. #include <linux/io.h>
  19. #include <linux/completion.h>
  20. #include <linux/delay.h>
  21. #include <linux/dma-mapping.h>
  22. #include <linux/errno.h>
  23. #include <linux/fs.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/kernel.h>
  26. #include <linux/mm.h>
  27. #include <linux/moduleparam.h>
  28. #include <linux/time.h>
  29. #include <linux/slab.h>
  30. #include <linux/device.h>
  31. #include <linux/platform_device.h>
  32. #include <linux/videodev2.h>
  33. #include <linux/pm_runtime.h>
  34. #include <linux/sched.h>
  35. #include <media/v4l2-common.h>
  36. #include <media/v4l2-dev.h>
  37. #include <media/soc_camera.h>
  38. #include <media/sh_mobile_ceu.h>
  39. #include <media/sh_mobile_csi2.h>
  40. #include <media/videobuf2-dma-contig.h>
  41. #include <media/v4l2-mediabus.h>
  42. #include <media/soc_mediabus.h>
  43. /* register offsets for sh7722 / sh7723 */
  44. #define CAPSR 0x00 /* Capture start register */
  45. #define CAPCR 0x04 /* Capture control register */
  46. #define CAMCR 0x08 /* Capture interface control register */
  47. #define CMCYR 0x0c /* Capture interface cycle register */
  48. #define CAMOR 0x10 /* Capture interface offset register */
  49. #define CAPWR 0x14 /* Capture interface width register */
  50. #define CAIFR 0x18 /* Capture interface input format register */
  51. #define CSTCR 0x20 /* Camera strobe control register (<= sh7722) */
  52. #define CSECR 0x24 /* Camera strobe emission count register (<= sh7722) */
  53. #define CRCNTR 0x28 /* CEU register control register */
  54. #define CRCMPR 0x2c /* CEU register forcible control register */
  55. #define CFLCR 0x30 /* Capture filter control register */
  56. #define CFSZR 0x34 /* Capture filter size clip register */
  57. #define CDWDR 0x38 /* Capture destination width register */
  58. #define CDAYR 0x3c /* Capture data address Y register */
  59. #define CDACR 0x40 /* Capture data address C register */
  60. #define CDBYR 0x44 /* Capture data bottom-field address Y register */
  61. #define CDBCR 0x48 /* Capture data bottom-field address C register */
  62. #define CBDSR 0x4c /* Capture bundle destination size register */
  63. #define CFWCR 0x5c /* Firewall operation control register */
  64. #define CLFCR 0x60 /* Capture low-pass filter control register */
  65. #define CDOCR 0x64 /* Capture data output control register */
  66. #define CDDCR 0x68 /* Capture data complexity level register */
  67. #define CDDAR 0x6c /* Capture data complexity level address register */
  68. #define CEIER 0x70 /* Capture event interrupt enable register */
  69. #define CETCR 0x74 /* Capture event flag clear register */
  70. #define CSTSR 0x7c /* Capture status register */
  71. #define CSRTR 0x80 /* Capture software reset register */
  72. #define CDSSR 0x84 /* Capture data size register */
  73. #define CDAYR2 0x90 /* Capture data address Y register 2 */
  74. #define CDACR2 0x94 /* Capture data address C register 2 */
  75. #define CDBYR2 0x98 /* Capture data bottom-field address Y register 2 */
  76. #define CDBCR2 0x9c /* Capture data bottom-field address C register 2 */
  77. #undef DEBUG_GEOMETRY
  78. #ifdef DEBUG_GEOMETRY
  79. #define dev_geo dev_info
  80. #else
  81. #define dev_geo dev_dbg
  82. #endif
  83. /* per video frame buffer */
  84. struct sh_mobile_ceu_buffer {
  85. struct vb2_buffer vb; /* v4l buffer must be first */
  86. struct list_head queue;
  87. };
  88. struct sh_mobile_ceu_dev {
  89. struct soc_camera_host ici;
  90. struct soc_camera_device *icd;
  91. struct platform_device *csi2_pdev;
  92. unsigned int irq;
  93. void __iomem *base;
  94. size_t video_limit;
  95. size_t buf_total;
  96. spinlock_t lock; /* Protects video buffer lists */
  97. struct list_head capture;
  98. struct vb2_buffer *active;
  99. struct vb2_alloc_ctx *alloc_ctx;
  100. struct sh_mobile_ceu_info *pdata;
  101. struct completion complete;
  102. u32 cflcr;
  103. enum v4l2_field field;
  104. int sequence;
  105. unsigned int image_mode:1;
  106. unsigned int is_16bit:1;
  107. unsigned int frozen:1;
  108. };
  109. struct sh_mobile_ceu_cam {
  110. /* CEU offsets within the camera output, before the CEU scaler */
  111. unsigned int ceu_left;
  112. unsigned int ceu_top;
  113. /* Client output, as seen by the CEU */
  114. unsigned int width;
  115. unsigned int height;
  116. /*
  117. * User window from S_CROP / G_CROP, produced by client cropping and
  118. * scaling, CEU scaling and CEU cropping, mapped back onto the client
  119. * input window
  120. */
  121. struct v4l2_rect subrect;
  122. /* Camera cropping rectangle */
  123. struct v4l2_rect rect;
  124. const struct soc_mbus_pixelfmt *extra_fmt;
  125. enum v4l2_mbus_pixelcode code;
  126. };
  127. static struct sh_mobile_ceu_buffer *to_ceu_vb(struct vb2_buffer *vb)
  128. {
  129. return container_of(vb, struct sh_mobile_ceu_buffer, vb);
  130. }
  131. static void ceu_write(struct sh_mobile_ceu_dev *priv,
  132. unsigned long reg_offs, u32 data)
  133. {
  134. iowrite32(data, priv->base + reg_offs);
  135. }
  136. static u32 ceu_read(struct sh_mobile_ceu_dev *priv, unsigned long reg_offs)
  137. {
  138. return ioread32(priv->base + reg_offs);
  139. }
  140. static int sh_mobile_ceu_soft_reset(struct sh_mobile_ceu_dev *pcdev)
  141. {
  142. int i, success = 0;
  143. struct soc_camera_device *icd = pcdev->icd;
  144. ceu_write(pcdev, CAPSR, 1 << 16); /* reset */
  145. /* wait CSTSR.CPTON bit */
  146. for (i = 0; i < 1000; i++) {
  147. if (!(ceu_read(pcdev, CSTSR) & 1)) {
  148. success++;
  149. break;
  150. }
  151. udelay(1);
  152. }
  153. /* wait CAPSR.CPKIL bit */
  154. for (i = 0; i < 1000; i++) {
  155. if (!(ceu_read(pcdev, CAPSR) & (1 << 16))) {
  156. success++;
  157. break;
  158. }
  159. udelay(1);
  160. }
  161. if (2 != success) {
  162. dev_warn(icd->pdev, "soft reset time out\n");
  163. return -EIO;
  164. }
  165. return 0;
  166. }
  167. /*
  168. * Videobuf operations
  169. */
  170. /*
  171. * .queue_setup() is called to check, whether the driver can accept the
  172. * requested number of buffers and to fill in plane sizes
  173. * for the current frame format if required
  174. */
  175. static int sh_mobile_ceu_videobuf_setup(struct vb2_queue *vq,
  176. const struct v4l2_format *fmt,
  177. unsigned int *count, unsigned int *num_planes,
  178. unsigned int sizes[], void *alloc_ctxs[])
  179. {
  180. struct soc_camera_device *icd = container_of(vq, struct soc_camera_device, vb2_vidq);
  181. struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
  182. struct sh_mobile_ceu_dev *pcdev = ici->priv;
  183. int bytes_per_line;
  184. unsigned int height;
  185. if (fmt) {
  186. const struct soc_camera_format_xlate *xlate = soc_camera_xlate_by_fourcc(icd,
  187. fmt->fmt.pix.pixelformat);
  188. if (!xlate)
  189. return -EINVAL;
  190. bytes_per_line = soc_mbus_bytes_per_line(fmt->fmt.pix.width,
  191. xlate->host_fmt);
  192. height = fmt->fmt.pix.height;
  193. } else {
  194. /* Called from VIDIOC_REQBUFS or in compatibility mode */
  195. bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
  196. icd->current_fmt->host_fmt);
  197. height = icd->user_height;
  198. }
  199. if (bytes_per_line < 0)
  200. return bytes_per_line;
  201. sizes[0] = bytes_per_line * height;
  202. alloc_ctxs[0] = pcdev->alloc_ctx;
  203. if (!vq->num_buffers)
  204. pcdev->sequence = 0;
  205. if (!*count)
  206. *count = 2;
  207. /* If *num_planes != 0, we have already verified *count. */
  208. if (pcdev->video_limit && !*num_planes) {
  209. size_t size = PAGE_ALIGN(sizes[0]) * *count;
  210. if (size + pcdev->buf_total > pcdev->video_limit)
  211. *count = (pcdev->video_limit - pcdev->buf_total) /
  212. PAGE_ALIGN(sizes[0]);
  213. }
  214. *num_planes = 1;
  215. dev_dbg(icd->parent, "count=%d, size=%u\n", *count, sizes[0]);
  216. return 0;
  217. }
  218. #define CEU_CETCR_MAGIC 0x0317f313 /* acknowledge magical interrupt sources */
  219. #define CEU_CETCR_IGRW (1 << 4) /* prohibited register access interrupt bit */
  220. #define CEU_CEIER_CPEIE (1 << 0) /* one-frame capture end interrupt */
  221. #define CEU_CEIER_VBP (1 << 20) /* vbp error */
  222. #define CEU_CAPCR_CTNCP (1 << 16) /* continuous capture mode (if set) */
  223. #define CEU_CEIER_MASK (CEU_CEIER_CPEIE | CEU_CEIER_VBP)
  224. /*
  225. * return value doesn't reflex the success/failure to queue the new buffer,
  226. * but rather the status of the previous buffer.
  227. */
  228. static int sh_mobile_ceu_capture(struct sh_mobile_ceu_dev *pcdev)
  229. {
  230. struct soc_camera_device *icd = pcdev->icd;
  231. dma_addr_t phys_addr_top, phys_addr_bottom;
  232. unsigned long top1, top2;
  233. unsigned long bottom1, bottom2;
  234. u32 status;
  235. bool planar;
  236. int ret = 0;
  237. /*
  238. * The hardware is _very_ picky about this sequence. Especially
  239. * the CEU_CETCR_MAGIC value. It seems like we need to acknowledge
  240. * several not-so-well documented interrupt sources in CETCR.
  241. */
  242. ceu_write(pcdev, CEIER, ceu_read(pcdev, CEIER) & ~CEU_CEIER_MASK);
  243. status = ceu_read(pcdev, CETCR);
  244. ceu_write(pcdev, CETCR, ~status & CEU_CETCR_MAGIC);
  245. if (!pcdev->frozen)
  246. ceu_write(pcdev, CEIER, ceu_read(pcdev, CEIER) | CEU_CEIER_MASK);
  247. ceu_write(pcdev, CAPCR, ceu_read(pcdev, CAPCR) & ~CEU_CAPCR_CTNCP);
  248. ceu_write(pcdev, CETCR, CEU_CETCR_MAGIC ^ CEU_CETCR_IGRW);
  249. /*
  250. * When a VBP interrupt occurs, a capture end interrupt does not occur
  251. * and the image of that frame is not captured correctly. So, soft reset
  252. * is needed here.
  253. */
  254. if (status & CEU_CEIER_VBP) {
  255. sh_mobile_ceu_soft_reset(pcdev);
  256. ret = -EIO;
  257. }
  258. if (pcdev->frozen) {
  259. complete(&pcdev->complete);
  260. return ret;
  261. }
  262. if (!pcdev->active)
  263. return ret;
  264. if (V4L2_FIELD_INTERLACED_BT == pcdev->field) {
  265. top1 = CDBYR;
  266. top2 = CDBCR;
  267. bottom1 = CDAYR;
  268. bottom2 = CDACR;
  269. } else {
  270. top1 = CDAYR;
  271. top2 = CDACR;
  272. bottom1 = CDBYR;
  273. bottom2 = CDBCR;
  274. }
  275. phys_addr_top = vb2_dma_contig_plane_dma_addr(pcdev->active, 0);
  276. switch (icd->current_fmt->host_fmt->fourcc) {
  277. case V4L2_PIX_FMT_NV12:
  278. case V4L2_PIX_FMT_NV21:
  279. case V4L2_PIX_FMT_NV16:
  280. case V4L2_PIX_FMT_NV61:
  281. planar = true;
  282. break;
  283. default:
  284. planar = false;
  285. }
  286. ceu_write(pcdev, top1, phys_addr_top);
  287. if (V4L2_FIELD_NONE != pcdev->field) {
  288. if (planar)
  289. phys_addr_bottom = phys_addr_top + icd->user_width;
  290. else
  291. phys_addr_bottom = phys_addr_top +
  292. soc_mbus_bytes_per_line(icd->user_width,
  293. icd->current_fmt->host_fmt);
  294. ceu_write(pcdev, bottom1, phys_addr_bottom);
  295. }
  296. if (planar) {
  297. phys_addr_top += icd->user_width *
  298. icd->user_height;
  299. ceu_write(pcdev, top2, phys_addr_top);
  300. if (V4L2_FIELD_NONE != pcdev->field) {
  301. phys_addr_bottom = phys_addr_top + icd->user_width;
  302. ceu_write(pcdev, bottom2, phys_addr_bottom);
  303. }
  304. }
  305. ceu_write(pcdev, CAPSR, 0x1); /* start capture */
  306. return ret;
  307. }
  308. static int sh_mobile_ceu_videobuf_prepare(struct vb2_buffer *vb)
  309. {
  310. struct sh_mobile_ceu_buffer *buf = to_ceu_vb(vb);
  311. /* Added list head initialization on alloc */
  312. WARN(!list_empty(&buf->queue), "Buffer %p on queue!\n", vb);
  313. return 0;
  314. }
  315. static void sh_mobile_ceu_videobuf_queue(struct vb2_buffer *vb)
  316. {
  317. struct soc_camera_device *icd = container_of(vb->vb2_queue, struct soc_camera_device, vb2_vidq);
  318. struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
  319. struct sh_mobile_ceu_dev *pcdev = ici->priv;
  320. struct sh_mobile_ceu_buffer *buf = to_ceu_vb(vb);
  321. unsigned long size;
  322. int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
  323. icd->current_fmt->host_fmt);
  324. if (bytes_per_line < 0)
  325. goto error;
  326. size = icd->user_height * bytes_per_line;
  327. if (vb2_plane_size(vb, 0) < size) {
  328. dev_err(icd->parent, "Buffer #%d too small (%lu < %lu)\n",
  329. vb->v4l2_buf.index, vb2_plane_size(vb, 0), size);
  330. goto error;
  331. }
  332. vb2_set_plane_payload(vb, 0, size);
  333. dev_dbg(icd->parent, "%s (vb=0x%p) 0x%p %lu\n", __func__,
  334. vb, vb2_plane_vaddr(vb, 0), vb2_get_plane_payload(vb, 0));
  335. #ifdef DEBUG
  336. /*
  337. * This can be useful if you want to see if we actually fill
  338. * the buffer with something
  339. */
  340. if (vb2_plane_vaddr(vb, 0))
  341. memset(vb2_plane_vaddr(vb, 0), 0xaa, vb2_get_plane_payload(vb, 0));
  342. #endif
  343. spin_lock_irq(&pcdev->lock);
  344. list_add_tail(&buf->queue, &pcdev->capture);
  345. if (!pcdev->active) {
  346. /*
  347. * Because there were no active buffer at this moment,
  348. * we are not interested in the return value of
  349. * sh_mobile_ceu_capture here.
  350. */
  351. pcdev->active = vb;
  352. sh_mobile_ceu_capture(pcdev);
  353. }
  354. spin_unlock_irq(&pcdev->lock);
  355. return;
  356. error:
  357. vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
  358. }
  359. static void sh_mobile_ceu_videobuf_release(struct vb2_buffer *vb)
  360. {
  361. struct soc_camera_device *icd = container_of(vb->vb2_queue, struct soc_camera_device, vb2_vidq);
  362. struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
  363. struct sh_mobile_ceu_buffer *buf = to_ceu_vb(vb);
  364. struct sh_mobile_ceu_dev *pcdev = ici->priv;
  365. spin_lock_irq(&pcdev->lock);
  366. if (pcdev->active == vb) {
  367. /* disable capture (release DMA buffer), reset */
  368. ceu_write(pcdev, CAPSR, 1 << 16);
  369. pcdev->active = NULL;
  370. }
  371. /*
  372. * Doesn't hurt also if the list is empty, but it hurts, if queuing the
  373. * buffer failed, and .buf_init() hasn't been called
  374. */
  375. if (buf->queue.next)
  376. list_del_init(&buf->queue);
  377. pcdev->buf_total -= PAGE_ALIGN(vb2_plane_size(vb, 0));
  378. dev_dbg(icd->parent, "%s() %zu bytes buffers\n", __func__,
  379. pcdev->buf_total);
  380. spin_unlock_irq(&pcdev->lock);
  381. }
  382. static int sh_mobile_ceu_videobuf_init(struct vb2_buffer *vb)
  383. {
  384. struct soc_camera_device *icd = container_of(vb->vb2_queue, struct soc_camera_device, vb2_vidq);
  385. struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
  386. struct sh_mobile_ceu_dev *pcdev = ici->priv;
  387. pcdev->buf_total += PAGE_ALIGN(vb2_plane_size(vb, 0));
  388. dev_dbg(icd->parent, "%s() %zu bytes buffers\n", __func__,
  389. pcdev->buf_total);
  390. /* This is for locking debugging only */
  391. INIT_LIST_HEAD(&to_ceu_vb(vb)->queue);
  392. return 0;
  393. }
  394. static int sh_mobile_ceu_stop_streaming(struct vb2_queue *q)
  395. {
  396. struct soc_camera_device *icd = container_of(q, struct soc_camera_device, vb2_vidq);
  397. struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
  398. struct sh_mobile_ceu_dev *pcdev = ici->priv;
  399. struct list_head *buf_head, *tmp;
  400. spin_lock_irq(&pcdev->lock);
  401. pcdev->active = NULL;
  402. list_for_each_safe(buf_head, tmp, &pcdev->capture)
  403. list_del_init(buf_head);
  404. spin_unlock_irq(&pcdev->lock);
  405. return sh_mobile_ceu_soft_reset(pcdev);
  406. }
  407. static struct vb2_ops sh_mobile_ceu_videobuf_ops = {
  408. .queue_setup = sh_mobile_ceu_videobuf_setup,
  409. .buf_prepare = sh_mobile_ceu_videobuf_prepare,
  410. .buf_queue = sh_mobile_ceu_videobuf_queue,
  411. .buf_cleanup = sh_mobile_ceu_videobuf_release,
  412. .buf_init = sh_mobile_ceu_videobuf_init,
  413. .wait_prepare = soc_camera_unlock,
  414. .wait_finish = soc_camera_lock,
  415. .stop_streaming = sh_mobile_ceu_stop_streaming,
  416. };
  417. static irqreturn_t sh_mobile_ceu_irq(int irq, void *data)
  418. {
  419. struct sh_mobile_ceu_dev *pcdev = data;
  420. struct vb2_buffer *vb;
  421. int ret;
  422. spin_lock(&pcdev->lock);
  423. vb = pcdev->active;
  424. if (!vb)
  425. /* Stale interrupt from a released buffer */
  426. goto out;
  427. list_del_init(&to_ceu_vb(vb)->queue);
  428. if (!list_empty(&pcdev->capture))
  429. pcdev->active = &list_entry(pcdev->capture.next,
  430. struct sh_mobile_ceu_buffer, queue)->vb;
  431. else
  432. pcdev->active = NULL;
  433. ret = sh_mobile_ceu_capture(pcdev);
  434. do_gettimeofday(&vb->v4l2_buf.timestamp);
  435. if (!ret) {
  436. vb->v4l2_buf.field = pcdev->field;
  437. vb->v4l2_buf.sequence = pcdev->sequence++;
  438. }
  439. vb2_buffer_done(vb, ret < 0 ? VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
  440. out:
  441. spin_unlock(&pcdev->lock);
  442. return IRQ_HANDLED;
  443. }
  444. static struct v4l2_subdev *find_csi2(struct sh_mobile_ceu_dev *pcdev)
  445. {
  446. struct v4l2_subdev *sd;
  447. if (!pcdev->csi2_pdev)
  448. return NULL;
  449. v4l2_device_for_each_subdev(sd, &pcdev->ici.v4l2_dev)
  450. if (&pcdev->csi2_pdev->dev == v4l2_get_subdevdata(sd))
  451. return sd;
  452. return NULL;
  453. }
  454. /* Called with .video_lock held */
  455. static int sh_mobile_ceu_add_device(struct soc_camera_device *icd)
  456. {
  457. struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
  458. struct sh_mobile_ceu_dev *pcdev = ici->priv;
  459. struct v4l2_subdev *csi2_sd;
  460. int ret;
  461. if (pcdev->icd)
  462. return -EBUSY;
  463. dev_info(icd->parent,
  464. "SuperH Mobile CEU driver attached to camera %d\n",
  465. icd->devnum);
  466. pm_runtime_get_sync(ici->v4l2_dev.dev);
  467. pcdev->buf_total = 0;
  468. ret = sh_mobile_ceu_soft_reset(pcdev);
  469. csi2_sd = find_csi2(pcdev);
  470. if (csi2_sd) {
  471. csi2_sd->grp_id = soc_camera_grp_id(icd);
  472. v4l2_set_subdev_hostdata(csi2_sd, icd);
  473. }
  474. ret = v4l2_subdev_call(csi2_sd, core, s_power, 1);
  475. if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV) {
  476. pm_runtime_put_sync(ici->v4l2_dev.dev);
  477. return ret;
  478. }
  479. /*
  480. * -ENODEV is special: either csi2_sd == NULL or the CSI-2 driver
  481. * has not found this soc-camera device among its clients
  482. */
  483. if (ret == -ENODEV && csi2_sd)
  484. csi2_sd->grp_id = 0;
  485. pcdev->icd = icd;
  486. return 0;
  487. }
  488. /* Called with .video_lock held */
  489. static void sh_mobile_ceu_remove_device(struct soc_camera_device *icd)
  490. {
  491. struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
  492. struct sh_mobile_ceu_dev *pcdev = ici->priv;
  493. struct v4l2_subdev *csi2_sd = find_csi2(pcdev);
  494. BUG_ON(icd != pcdev->icd);
  495. v4l2_subdev_call(csi2_sd, core, s_power, 0);
  496. if (csi2_sd)
  497. csi2_sd->grp_id = 0;
  498. /* disable capture, disable interrupts */
  499. ceu_write(pcdev, CEIER, 0);
  500. sh_mobile_ceu_soft_reset(pcdev);
  501. /* make sure active buffer is canceled */
  502. spin_lock_irq(&pcdev->lock);
  503. if (pcdev->active) {
  504. list_del_init(&to_ceu_vb(pcdev->active)->queue);
  505. vb2_buffer_done(pcdev->active, VB2_BUF_STATE_ERROR);
  506. pcdev->active = NULL;
  507. }
  508. spin_unlock_irq(&pcdev->lock);
  509. pm_runtime_put_sync(ici->v4l2_dev.dev);
  510. dev_info(icd->parent,
  511. "SuperH Mobile CEU driver detached from camera %d\n",
  512. icd->devnum);
  513. pcdev->icd = NULL;
  514. }
  515. /*
  516. * See chapter 29.4.12 "Capture Filter Control Register (CFLCR)"
  517. * in SH7722 Hardware Manual
  518. */
  519. static unsigned int size_dst(unsigned int src, unsigned int scale)
  520. {
  521. unsigned int mant_pre = scale >> 12;
  522. if (!src || !scale)
  523. return src;
  524. return ((mant_pre + 2 * (src - 1)) / (2 * mant_pre) - 1) *
  525. mant_pre * 4096 / scale + 1;
  526. }
  527. static u16 calc_scale(unsigned int src, unsigned int *dst)
  528. {
  529. u16 scale;
  530. if (src == *dst)
  531. return 0;
  532. scale = (src * 4096 / *dst) & ~7;
  533. while (scale > 4096 && size_dst(src, scale) < *dst)
  534. scale -= 8;
  535. *dst = size_dst(src, scale);
  536. return scale;
  537. }
  538. /* rect is guaranteed to not exceed the scaled camera rectangle */
  539. static void sh_mobile_ceu_set_rect(struct soc_camera_device *icd)
  540. {
  541. struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
  542. struct sh_mobile_ceu_cam *cam = icd->host_priv;
  543. struct sh_mobile_ceu_dev *pcdev = ici->priv;
  544. unsigned int height, width, cdwdr_width, in_width, in_height;
  545. unsigned int left_offset, top_offset;
  546. u32 camor;
  547. dev_geo(icd->parent, "Crop %ux%u@%u:%u\n",
  548. icd->user_width, icd->user_height, cam->ceu_left, cam->ceu_top);
  549. left_offset = cam->ceu_left;
  550. top_offset = cam->ceu_top;
  551. WARN_ON(icd->user_width & 3 || icd->user_height & 3);
  552. width = icd->user_width;
  553. if (pcdev->image_mode) {
  554. in_width = cam->width;
  555. if (!pcdev->is_16bit) {
  556. in_width *= 2;
  557. left_offset *= 2;
  558. }
  559. cdwdr_width = width;
  560. } else {
  561. int bytes_per_line = soc_mbus_bytes_per_line(width,
  562. icd->current_fmt->host_fmt);
  563. unsigned int w_factor;
  564. switch (icd->current_fmt->host_fmt->packing) {
  565. case SOC_MBUS_PACKING_2X8_PADHI:
  566. w_factor = 2;
  567. break;
  568. default:
  569. w_factor = 1;
  570. }
  571. in_width = cam->width * w_factor;
  572. left_offset *= w_factor;
  573. if (bytes_per_line < 0)
  574. cdwdr_width = width;
  575. else
  576. cdwdr_width = bytes_per_line;
  577. }
  578. height = icd->user_height;
  579. in_height = cam->height;
  580. if (V4L2_FIELD_NONE != pcdev->field) {
  581. height = (height / 2) & ~3;
  582. in_height /= 2;
  583. top_offset /= 2;
  584. cdwdr_width *= 2;
  585. }
  586. /* CSI2 special configuration */
  587. if (pcdev->pdata->csi2) {
  588. in_width = ((in_width - 2) * 2);
  589. left_offset *= 2;
  590. }
  591. /* Set CAMOR, CAPWR, CFSZR, take care of CDWDR */
  592. camor = left_offset | (top_offset << 16);
  593. dev_geo(icd->parent,
  594. "CAMOR 0x%x, CAPWR 0x%x, CFSZR 0x%x, CDWDR 0x%x\n", camor,
  595. (in_height << 16) | in_width, (height << 16) | width,
  596. cdwdr_width);
  597. ceu_write(pcdev, CAMOR, camor);
  598. ceu_write(pcdev, CAPWR, (in_height << 16) | in_width);
  599. /* CFSZR clipping is applied _after_ the scaling filter (CFLCR) */
  600. ceu_write(pcdev, CFSZR, (height << 16) | width);
  601. ceu_write(pcdev, CDWDR, cdwdr_width);
  602. }
  603. static u32 capture_save_reset(struct sh_mobile_ceu_dev *pcdev)
  604. {
  605. u32 capsr = ceu_read(pcdev, CAPSR);
  606. ceu_write(pcdev, CAPSR, 1 << 16); /* reset, stop capture */
  607. return capsr;
  608. }
  609. static void capture_restore(struct sh_mobile_ceu_dev *pcdev, u32 capsr)
  610. {
  611. unsigned long timeout = jiffies + 10 * HZ;
  612. /*
  613. * Wait until the end of the current frame. It can take a long time,
  614. * but if it has been aborted by a CAPSR reset, it shoule exit sooner.
  615. */
  616. while ((ceu_read(pcdev, CSTSR) & 1) && time_before(jiffies, timeout))
  617. msleep(1);
  618. if (time_after(jiffies, timeout)) {
  619. dev_err(pcdev->ici.v4l2_dev.dev,
  620. "Timeout waiting for frame end! Interface problem?\n");
  621. return;
  622. }
  623. /* Wait until reset clears, this shall not hang... */
  624. while (ceu_read(pcdev, CAPSR) & (1 << 16))
  625. udelay(10);
  626. /* Anything to restore? */
  627. if (capsr & ~(1 << 16))
  628. ceu_write(pcdev, CAPSR, capsr);
  629. }
  630. /* Find the bus subdevice driver, e.g., CSI2 */
  631. static struct v4l2_subdev *find_bus_subdev(struct sh_mobile_ceu_dev *pcdev,
  632. struct soc_camera_device *icd)
  633. {
  634. if (pcdev->csi2_pdev) {
  635. struct v4l2_subdev *csi2_sd = find_csi2(pcdev);
  636. if (csi2_sd && csi2_sd->grp_id == soc_camera_grp_id(icd))
  637. return csi2_sd;
  638. }
  639. return soc_camera_to_subdev(icd);
  640. }
  641. #define CEU_BUS_FLAGS (V4L2_MBUS_MASTER | \
  642. V4L2_MBUS_PCLK_SAMPLE_RISING | \
  643. V4L2_MBUS_HSYNC_ACTIVE_HIGH | \
  644. V4L2_MBUS_HSYNC_ACTIVE_LOW | \
  645. V4L2_MBUS_VSYNC_ACTIVE_HIGH | \
  646. V4L2_MBUS_VSYNC_ACTIVE_LOW | \
  647. V4L2_MBUS_DATA_ACTIVE_HIGH)
  648. /* Capture is not running, no interrupts, no locking needed */
  649. static int sh_mobile_ceu_set_bus_param(struct soc_camera_device *icd)
  650. {
  651. struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
  652. struct sh_mobile_ceu_dev *pcdev = ici->priv;
  653. struct v4l2_subdev *sd = find_bus_subdev(pcdev, icd);
  654. struct sh_mobile_ceu_cam *cam = icd->host_priv;
  655. struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,};
  656. unsigned long value, common_flags = CEU_BUS_FLAGS;
  657. u32 capsr = capture_save_reset(pcdev);
  658. unsigned int yuv_lineskip;
  659. int ret;
  660. /*
  661. * If the client doesn't implement g_mbus_config, we just use our
  662. * platform data
  663. */
  664. ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg);
  665. if (!ret) {
  666. common_flags = soc_mbus_config_compatible(&cfg,
  667. common_flags);
  668. if (!common_flags)
  669. return -EINVAL;
  670. } else if (ret != -ENOIOCTLCMD) {
  671. return ret;
  672. }
  673. /* Make choises, based on platform preferences */
  674. if ((common_flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) &&
  675. (common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)) {
  676. if (pcdev->pdata->flags & SH_CEU_FLAG_HSYNC_LOW)
  677. common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_HIGH;
  678. else
  679. common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_LOW;
  680. }
  681. if ((common_flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) &&
  682. (common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)) {
  683. if (pcdev->pdata->flags & SH_CEU_FLAG_VSYNC_LOW)
  684. common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_HIGH;
  685. else
  686. common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_LOW;
  687. }
  688. cfg.flags = common_flags;
  689. ret = v4l2_subdev_call(sd, video, s_mbus_config, &cfg);
  690. if (ret < 0 && ret != -ENOIOCTLCMD)
  691. return ret;
  692. if (icd->current_fmt->host_fmt->bits_per_sample > 8)
  693. pcdev->is_16bit = 1;
  694. else
  695. pcdev->is_16bit = 0;
  696. ceu_write(pcdev, CRCNTR, 0);
  697. ceu_write(pcdev, CRCMPR, 0);
  698. value = 0x00000010; /* data fetch by default */
  699. yuv_lineskip = 0x10;
  700. switch (icd->current_fmt->host_fmt->fourcc) {
  701. case V4L2_PIX_FMT_NV12:
  702. case V4L2_PIX_FMT_NV21:
  703. /* convert 4:2:2 -> 4:2:0 */
  704. yuv_lineskip = 0; /* skip for NV12/21, no skip for NV16/61 */
  705. /* fall-through */
  706. case V4L2_PIX_FMT_NV16:
  707. case V4L2_PIX_FMT_NV61:
  708. switch (cam->code) {
  709. case V4L2_MBUS_FMT_UYVY8_2X8:
  710. value = 0x00000000; /* Cb0, Y0, Cr0, Y1 */
  711. break;
  712. case V4L2_MBUS_FMT_VYUY8_2X8:
  713. value = 0x00000100; /* Cr0, Y0, Cb0, Y1 */
  714. break;
  715. case V4L2_MBUS_FMT_YUYV8_2X8:
  716. value = 0x00000200; /* Y0, Cb0, Y1, Cr0 */
  717. break;
  718. case V4L2_MBUS_FMT_YVYU8_2X8:
  719. value = 0x00000300; /* Y0, Cr0, Y1, Cb0 */
  720. break;
  721. default:
  722. BUG();
  723. }
  724. }
  725. if (icd->current_fmt->host_fmt->fourcc == V4L2_PIX_FMT_NV21 ||
  726. icd->current_fmt->host_fmt->fourcc == V4L2_PIX_FMT_NV61)
  727. value ^= 0x00000100; /* swap U, V to change from NV1x->NVx1 */
  728. value |= common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW ? 1 << 1 : 0;
  729. value |= common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW ? 1 << 0 : 0;
  730. value |= pcdev->is_16bit ? 1 << 12 : 0;
  731. /* CSI2 mode */
  732. if (pcdev->pdata->csi2)
  733. value |= 3 << 12;
  734. ceu_write(pcdev, CAMCR, value);
  735. ceu_write(pcdev, CAPCR, 0x00300000);
  736. switch (pcdev->field) {
  737. case V4L2_FIELD_INTERLACED_TB:
  738. value = 0x101;
  739. break;
  740. case V4L2_FIELD_INTERLACED_BT:
  741. value = 0x102;
  742. break;
  743. default:
  744. value = 0;
  745. break;
  746. }
  747. ceu_write(pcdev, CAIFR, value);
  748. sh_mobile_ceu_set_rect(icd);
  749. mdelay(1);
  750. dev_geo(icd->parent, "CFLCR 0x%x\n", pcdev->cflcr);
  751. ceu_write(pcdev, CFLCR, pcdev->cflcr);
  752. /*
  753. * A few words about byte order (observed in Big Endian mode)
  754. *
  755. * In data fetch mode bytes are received in chunks of 8 bytes.
  756. * D0, D1, D2, D3, D4, D5, D6, D7 (D0 received first)
  757. *
  758. * The data is however by default written to memory in reverse order:
  759. * D7, D6, D5, D4, D3, D2, D1, D0 (D7 written to lowest byte)
  760. *
  761. * The lowest three bits of CDOCR allows us to do swapping,
  762. * using 7 we swap the data bytes to match the incoming order:
  763. * D0, D1, D2, D3, D4, D5, D6, D7
  764. */
  765. value = 0x00000007 | yuv_lineskip;
  766. ceu_write(pcdev, CDOCR, value);
  767. ceu_write(pcdev, CFWCR, 0); /* keep "datafetch firewall" disabled */
  768. capture_restore(pcdev, capsr);
  769. /* not in bundle mode: skip CBDSR, CDAYR2, CDACR2, CDBYR2, CDBCR2 */
  770. return 0;
  771. }
  772. static int sh_mobile_ceu_try_bus_param(struct soc_camera_device *icd,
  773. unsigned char buswidth)
  774. {
  775. struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
  776. struct sh_mobile_ceu_dev *pcdev = ici->priv;
  777. struct v4l2_subdev *sd = find_bus_subdev(pcdev, icd);
  778. unsigned long common_flags = CEU_BUS_FLAGS;
  779. struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,};
  780. int ret;
  781. ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg);
  782. if (!ret)
  783. common_flags = soc_mbus_config_compatible(&cfg,
  784. common_flags);
  785. else if (ret != -ENOIOCTLCMD)
  786. return ret;
  787. if (!common_flags || buswidth > 16)
  788. return -EINVAL;
  789. return 0;
  790. }
  791. static const struct soc_mbus_pixelfmt sh_mobile_ceu_formats[] = {
  792. {
  793. .fourcc = V4L2_PIX_FMT_NV12,
  794. .name = "NV12",
  795. .bits_per_sample = 8,
  796. .packing = SOC_MBUS_PACKING_1_5X8,
  797. .order = SOC_MBUS_ORDER_LE,
  798. }, {
  799. .fourcc = V4L2_PIX_FMT_NV21,
  800. .name = "NV21",
  801. .bits_per_sample = 8,
  802. .packing = SOC_MBUS_PACKING_1_5X8,
  803. .order = SOC_MBUS_ORDER_LE,
  804. }, {
  805. .fourcc = V4L2_PIX_FMT_NV16,
  806. .name = "NV16",
  807. .bits_per_sample = 8,
  808. .packing = SOC_MBUS_PACKING_2X8_PADHI,
  809. .order = SOC_MBUS_ORDER_LE,
  810. }, {
  811. .fourcc = V4L2_PIX_FMT_NV61,
  812. .name = "NV61",
  813. .bits_per_sample = 8,
  814. .packing = SOC_MBUS_PACKING_2X8_PADHI,
  815. .order = SOC_MBUS_ORDER_LE,
  816. },
  817. };
  818. /* This will be corrected as we get more formats */
  819. static bool sh_mobile_ceu_packing_supported(const struct soc_mbus_pixelfmt *fmt)
  820. {
  821. return fmt->packing == SOC_MBUS_PACKING_NONE ||
  822. (fmt->bits_per_sample == 8 &&
  823. fmt->packing == SOC_MBUS_PACKING_1_5X8) ||
  824. (fmt->bits_per_sample == 8 &&
  825. fmt->packing == SOC_MBUS_PACKING_2X8_PADHI) ||
  826. (fmt->bits_per_sample > 8 &&
  827. fmt->packing == SOC_MBUS_PACKING_EXTEND16);
  828. }
  829. static int client_g_rect(struct v4l2_subdev *sd, struct v4l2_rect *rect);
  830. static struct soc_camera_device *ctrl_to_icd(struct v4l2_ctrl *ctrl)
  831. {
  832. return container_of(ctrl->handler, struct soc_camera_device,
  833. ctrl_handler);
  834. }
  835. static int sh_mobile_ceu_s_ctrl(struct v4l2_ctrl *ctrl)
  836. {
  837. struct soc_camera_device *icd = ctrl_to_icd(ctrl);
  838. struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
  839. struct sh_mobile_ceu_dev *pcdev = ici->priv;
  840. switch (ctrl->id) {
  841. case V4L2_CID_SHARPNESS:
  842. switch (icd->current_fmt->host_fmt->fourcc) {
  843. case V4L2_PIX_FMT_NV12:
  844. case V4L2_PIX_FMT_NV21:
  845. case V4L2_PIX_FMT_NV16:
  846. case V4L2_PIX_FMT_NV61:
  847. ceu_write(pcdev, CLFCR, !ctrl->val);
  848. return 0;
  849. }
  850. break;
  851. }
  852. return -EINVAL;
  853. }
  854. static const struct v4l2_ctrl_ops sh_mobile_ceu_ctrl_ops = {
  855. .s_ctrl = sh_mobile_ceu_s_ctrl,
  856. };
  857. static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, unsigned int idx,
  858. struct soc_camera_format_xlate *xlate)
  859. {
  860. struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
  861. struct device *dev = icd->parent;
  862. struct soc_camera_host *ici = to_soc_camera_host(dev);
  863. struct sh_mobile_ceu_dev *pcdev = ici->priv;
  864. int ret, k, n;
  865. int formats = 0;
  866. struct sh_mobile_ceu_cam *cam;
  867. enum v4l2_mbus_pixelcode code;
  868. const struct soc_mbus_pixelfmt *fmt;
  869. ret = v4l2_subdev_call(sd, video, enum_mbus_fmt, idx, &code);
  870. if (ret < 0)
  871. /* No more formats */
  872. return 0;
  873. fmt = soc_mbus_get_fmtdesc(code);
  874. if (!fmt) {
  875. dev_warn(dev, "unsupported format code #%u: %d\n", idx, code);
  876. return 0;
  877. }
  878. if (!pcdev->pdata->csi2) {
  879. /* Are there any restrictions in the CSI-2 case? */
  880. ret = sh_mobile_ceu_try_bus_param(icd, fmt->bits_per_sample);
  881. if (ret < 0)
  882. return 0;
  883. }
  884. if (!icd->host_priv) {
  885. struct v4l2_mbus_framefmt mf;
  886. struct v4l2_rect rect;
  887. int shift = 0;
  888. /* Add our control */
  889. v4l2_ctrl_new_std(&icd->ctrl_handler, &sh_mobile_ceu_ctrl_ops,
  890. V4L2_CID_SHARPNESS, 0, 1, 1, 0);
  891. if (icd->ctrl_handler.error)
  892. return icd->ctrl_handler.error;
  893. /* FIXME: subwindow is lost between close / open */
  894. /* Cache current client geometry */
  895. ret = client_g_rect(sd, &rect);
  896. if (ret < 0)
  897. return ret;
  898. /* First time */
  899. ret = v4l2_subdev_call(sd, video, g_mbus_fmt, &mf);
  900. if (ret < 0)
  901. return ret;
  902. while ((mf.width > 2560 || mf.height > 1920) && shift < 4) {
  903. /* Try 2560x1920, 1280x960, 640x480, 320x240 */
  904. mf.width = 2560 >> shift;
  905. mf.height = 1920 >> shift;
  906. ret = v4l2_device_call_until_err(sd->v4l2_dev,
  907. soc_camera_grp_id(icd), video,
  908. s_mbus_fmt, &mf);
  909. if (ret < 0)
  910. return ret;
  911. shift++;
  912. }
  913. if (shift == 4) {
  914. dev_err(dev, "Failed to configure the client below %ux%x\n",
  915. mf.width, mf.height);
  916. return -EIO;
  917. }
  918. dev_geo(dev, "camera fmt %ux%u\n", mf.width, mf.height);
  919. cam = kzalloc(sizeof(*cam), GFP_KERNEL);
  920. if (!cam)
  921. return -ENOMEM;
  922. /* We are called with current camera crop, initialise subrect with it */
  923. cam->rect = rect;
  924. cam->subrect = rect;
  925. cam->width = mf.width;
  926. cam->height = mf.height;
  927. icd->host_priv = cam;
  928. } else {
  929. cam = icd->host_priv;
  930. }
  931. /* Beginning of a pass */
  932. if (!idx)
  933. cam->extra_fmt = NULL;
  934. switch (code) {
  935. case V4L2_MBUS_FMT_UYVY8_2X8:
  936. case V4L2_MBUS_FMT_VYUY8_2X8:
  937. case V4L2_MBUS_FMT_YUYV8_2X8:
  938. case V4L2_MBUS_FMT_YVYU8_2X8:
  939. if (cam->extra_fmt)
  940. break;
  941. /*
  942. * Our case is simple so far: for any of the above four camera
  943. * formats we add all our four synthesized NV* formats, so,
  944. * just marking the device with a single flag suffices. If
  945. * the format generation rules are more complex, you would have
  946. * to actually hang your already added / counted formats onto
  947. * the host_priv pointer and check whether the format you're
  948. * going to add now is already there.
  949. */
  950. cam->extra_fmt = sh_mobile_ceu_formats;
  951. n = ARRAY_SIZE(sh_mobile_ceu_formats);
  952. formats += n;
  953. for (k = 0; xlate && k < n; k++) {
  954. xlate->host_fmt = &sh_mobile_ceu_formats[k];
  955. xlate->code = code;
  956. xlate++;
  957. dev_dbg(dev, "Providing format %s using code %d\n",
  958. sh_mobile_ceu_formats[k].name, code);
  959. }
  960. break;
  961. default:
  962. if (!sh_mobile_ceu_packing_supported(fmt))
  963. return 0;
  964. }
  965. /* Generic pass-through */
  966. formats++;
  967. if (xlate) {
  968. xlate->host_fmt = fmt;
  969. xlate->code = code;
  970. xlate++;
  971. dev_dbg(dev, "Providing format %s in pass-through mode\n",
  972. fmt->name);
  973. }
  974. return formats;
  975. }
  976. static void sh_mobile_ceu_put_formats(struct soc_camera_device *icd)
  977. {
  978. kfree(icd->host_priv);
  979. icd->host_priv = NULL;
  980. }
  981. /* Check if any dimension of r1 is smaller than respective one of r2 */
  982. static bool is_smaller(struct v4l2_rect *r1, struct v4l2_rect *r2)
  983. {
  984. return r1->width < r2->width || r1->height < r2->height;
  985. }
  986. /* Check if r1 fails to cover r2 */
  987. static bool is_inside(struct v4l2_rect *r1, struct v4l2_rect *r2)
  988. {
  989. return r1->left > r2->left || r1->top > r2->top ||
  990. r1->left + r1->width < r2->left + r2->width ||
  991. r1->top + r1->height < r2->top + r2->height;
  992. }
  993. static unsigned int scale_down(unsigned int size, unsigned int scale)
  994. {
  995. return (size * 4096 + scale / 2) / scale;
  996. }
  997. static unsigned int calc_generic_scale(unsigned int input, unsigned int output)
  998. {
  999. return (input * 4096 + output / 2) / output;
  1000. }
  1001. /* Get and store current client crop */
  1002. static int client_g_rect(struct v4l2_subdev *sd, struct v4l2_rect *rect)
  1003. {
  1004. struct v4l2_crop crop;
  1005. struct v4l2_cropcap cap;
  1006. int ret;
  1007. crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  1008. ret = v4l2_subdev_call(sd, video, g_crop, &crop);
  1009. if (!ret) {
  1010. *rect = crop.c;
  1011. return ret;
  1012. }
  1013. /* Camera driver doesn't support .g_crop(), assume default rectangle */
  1014. cap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  1015. ret = v4l2_subdev_call(sd, video, cropcap, &cap);
  1016. if (!ret)
  1017. *rect = cap.defrect;
  1018. return ret;
  1019. }
  1020. /* Client crop has changed, update our sub-rectangle to remain within the area */
  1021. static void update_subrect(struct sh_mobile_ceu_cam *cam)
  1022. {
  1023. struct v4l2_rect *rect = &cam->rect, *subrect = &cam->subrect;
  1024. if (rect->width < subrect->width)
  1025. subrect->width = rect->width;
  1026. if (rect->height < subrect->height)
  1027. subrect->height = rect->height;
  1028. if (rect->left > subrect->left)
  1029. subrect->left = rect->left;
  1030. else if (rect->left + rect->width >
  1031. subrect->left + subrect->width)
  1032. subrect->left = rect->left + rect->width -
  1033. subrect->width;
  1034. if (rect->top > subrect->top)
  1035. subrect->top = rect->top;
  1036. else if (rect->top + rect->height >
  1037. subrect->top + subrect->height)
  1038. subrect->top = rect->top + rect->height -
  1039. subrect->height;
  1040. }
  1041. /*
  1042. * The common for both scaling and cropping iterative approach is:
  1043. * 1. try if the client can produce exactly what requested by the user
  1044. * 2. if (1) failed, try to double the client image until we get one big enough
  1045. * 3. if (2) failed, try to request the maximum image
  1046. */
  1047. static int client_s_crop(struct soc_camera_device *icd, struct v4l2_crop *crop,
  1048. struct v4l2_crop *cam_crop)
  1049. {
  1050. struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
  1051. struct v4l2_rect *rect = &crop->c, *cam_rect = &cam_crop->c;
  1052. struct device *dev = sd->v4l2_dev->dev;
  1053. struct sh_mobile_ceu_cam *cam = icd->host_priv;
  1054. struct v4l2_cropcap cap;
  1055. int ret;
  1056. unsigned int width, height;
  1057. v4l2_subdev_call(sd, video, s_crop, crop);
  1058. ret = client_g_rect(sd, cam_rect);
  1059. if (ret < 0)
  1060. return ret;
  1061. /*
  1062. * Now cam_crop contains the current camera input rectangle, and it must
  1063. * be within camera cropcap bounds
  1064. */
  1065. if (!memcmp(rect, cam_rect, sizeof(*rect))) {
  1066. /* Even if camera S_CROP failed, but camera rectangle matches */
  1067. dev_dbg(dev, "Camera S_CROP successful for %dx%d@%d:%d\n",
  1068. rect->width, rect->height, rect->left, rect->top);
  1069. cam->rect = *cam_rect;
  1070. return 0;
  1071. }
  1072. /* Try to fix cropping, that camera hasn't managed to set */
  1073. dev_geo(dev, "Fix camera S_CROP for %dx%d@%d:%d to %dx%d@%d:%d\n",
  1074. cam_rect->width, cam_rect->height,
  1075. cam_rect->left, cam_rect->top,
  1076. rect->width, rect->height, rect->left, rect->top);
  1077. /* We need sensor maximum rectangle */
  1078. ret = v4l2_subdev_call(sd, video, cropcap, &cap);
  1079. if (ret < 0)
  1080. return ret;
  1081. /* Put user requested rectangle within sensor bounds */
  1082. soc_camera_limit_side(&rect->left, &rect->width, cap.bounds.left, 2,
  1083. cap.bounds.width);
  1084. soc_camera_limit_side(&rect->top, &rect->height, cap.bounds.top, 4,
  1085. cap.bounds.height);
  1086. /*
  1087. * Popular special case - some cameras can only handle fixed sizes like
  1088. * QVGA, VGA,... Take care to avoid infinite loop.
  1089. */
  1090. width = max(cam_rect->width, 2);
  1091. height = max(cam_rect->height, 2);
  1092. /*
  1093. * Loop as long as sensor is not covering the requested rectangle and
  1094. * is still within its bounds
  1095. */
  1096. while (!ret && (is_smaller(cam_rect, rect) ||
  1097. is_inside(cam_rect, rect)) &&
  1098. (cap.bounds.width > width || cap.bounds.height > height)) {
  1099. width *= 2;
  1100. height *= 2;
  1101. cam_rect->width = width;
  1102. cam_rect->height = height;
  1103. /*
  1104. * We do not know what capabilities the camera has to set up
  1105. * left and top borders. We could try to be smarter in iterating
  1106. * them, e.g., if camera current left is to the right of the
  1107. * target left, set it to the middle point between the current
  1108. * left and minimum left. But that would add too much
  1109. * complexity: we would have to iterate each border separately.
  1110. * Instead we just drop to the left and top bounds.
  1111. */
  1112. if (cam_rect->left > rect->left)
  1113. cam_rect->left = cap.bounds.left;
  1114. if (cam_rect->left + cam_rect->width < rect->left + rect->width)
  1115. cam_rect->width = rect->left + rect->width -
  1116. cam_rect->left;
  1117. if (cam_rect->top > rect->top)
  1118. cam_rect->top = cap.bounds.top;
  1119. if (cam_rect->top + cam_rect->height < rect->top + rect->height)
  1120. cam_rect->height = rect->top + rect->height -
  1121. cam_rect->top;
  1122. v4l2_subdev_call(sd, video, s_crop, cam_crop);
  1123. ret = client_g_rect(sd, cam_rect);
  1124. dev_geo(dev, "Camera S_CROP %d for %dx%d@%d:%d\n", ret,
  1125. cam_rect->width, cam_rect->height,
  1126. cam_rect->left, cam_rect->top);
  1127. }
  1128. /* S_CROP must not modify the rectangle */
  1129. if (is_smaller(cam_rect, rect) || is_inside(cam_rect, rect)) {
  1130. /*
  1131. * The camera failed to configure a suitable cropping,
  1132. * we cannot use the current rectangle, set to max
  1133. */
  1134. *cam_rect = cap.bounds;
  1135. v4l2_subdev_call(sd, video, s_crop, cam_crop);
  1136. ret = client_g_rect(sd, cam_rect);
  1137. dev_geo(dev, "Camera S_CROP %d for max %dx%d@%d:%d\n", ret,
  1138. cam_rect->width, cam_rect->height,
  1139. cam_rect->left, cam_rect->top);
  1140. }
  1141. if (!ret) {
  1142. cam->rect = *cam_rect;
  1143. update_subrect(cam);
  1144. }
  1145. return ret;
  1146. }
  1147. /* Iterative s_mbus_fmt, also updates cached client crop on success */
  1148. static int client_s_fmt(struct soc_camera_device *icd,
  1149. struct v4l2_mbus_framefmt *mf, bool ceu_can_scale)
  1150. {
  1151. struct sh_mobile_ceu_cam *cam = icd->host_priv;
  1152. struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
  1153. struct device *dev = icd->parent;
  1154. unsigned int width = mf->width, height = mf->height, tmp_w, tmp_h;
  1155. unsigned int max_width, max_height;
  1156. struct v4l2_cropcap cap;
  1157. bool ceu_1to1;
  1158. int ret;
  1159. ret = v4l2_device_call_until_err(sd->v4l2_dev,
  1160. soc_camera_grp_id(icd), video,
  1161. s_mbus_fmt, mf);
  1162. if (ret < 0)
  1163. return ret;
  1164. dev_geo(dev, "camera scaled to %ux%u\n", mf->width, mf->height);
  1165. if (width == mf->width && height == mf->height) {
  1166. /* Perfect! The client has done it all. */
  1167. ceu_1to1 = true;
  1168. goto update_cache;
  1169. }
  1170. ceu_1to1 = false;
  1171. if (!ceu_can_scale)
  1172. goto update_cache;
  1173. cap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  1174. ret = v4l2_subdev_call(sd, video, cropcap, &cap);
  1175. if (ret < 0)
  1176. return ret;
  1177. max_width = min(cap.bounds.width, 2560);
  1178. max_height = min(cap.bounds.height, 1920);
  1179. /* Camera set a format, but geometry is not precise, try to improve */
  1180. tmp_w = mf->width;
  1181. tmp_h = mf->height;
  1182. /* width <= max_width && height <= max_height - guaranteed by try_fmt */
  1183. while ((width > tmp_w || height > tmp_h) &&
  1184. tmp_w < max_width && tmp_h < max_height) {
  1185. tmp_w = min(2 * tmp_w, max_width);
  1186. tmp_h = min(2 * tmp_h, max_height);
  1187. mf->width = tmp_w;
  1188. mf->height = tmp_h;
  1189. ret = v4l2_device_call_until_err(sd->v4l2_dev,
  1190. soc_camera_grp_id(icd), video,
  1191. s_mbus_fmt, mf);
  1192. dev_geo(dev, "Camera scaled to %ux%u\n",
  1193. mf->width, mf->height);
  1194. if (ret < 0) {
  1195. /* This shouldn't happen */
  1196. dev_err(dev, "Client failed to set format: %d\n", ret);
  1197. return ret;
  1198. }
  1199. }
  1200. update_cache:
  1201. /* Update cache */
  1202. ret = client_g_rect(sd, &cam->rect);
  1203. if (ret < 0)
  1204. return ret;
  1205. if (ceu_1to1)
  1206. cam->subrect = cam->rect;
  1207. else
  1208. update_subrect(cam);
  1209. return 0;
  1210. }
  1211. /**
  1212. * @width - on output: user width, mapped back to input
  1213. * @height - on output: user height, mapped back to input
  1214. * @mf - in- / output camera output window
  1215. */
  1216. static int client_scale(struct soc_camera_device *icd,
  1217. struct v4l2_mbus_framefmt *mf,
  1218. unsigned int *width, unsigned int *height,
  1219. bool ceu_can_scale)
  1220. {
  1221. struct sh_mobile_ceu_cam *cam = icd->host_priv;
  1222. struct device *dev = icd->parent;
  1223. struct v4l2_mbus_framefmt mf_tmp = *mf;
  1224. unsigned int scale_h, scale_v;
  1225. int ret;
  1226. /*
  1227. * 5. Apply iterative camera S_FMT for camera user window (also updates
  1228. * client crop cache and the imaginary sub-rectangle).
  1229. */
  1230. ret = client_s_fmt(icd, &mf_tmp, ceu_can_scale);
  1231. if (ret < 0)
  1232. return ret;
  1233. dev_geo(dev, "5: camera scaled to %ux%u\n",
  1234. mf_tmp.width, mf_tmp.height);
  1235. /* 6. Retrieve camera output window (g_fmt) */
  1236. /* unneeded - it is already in "mf_tmp" */
  1237. /* 7. Calculate new client scales. */
  1238. scale_h = calc_generic_scale(cam->rect.width, mf_tmp.width);
  1239. scale_v = calc_generic_scale(cam->rect.height, mf_tmp.height);
  1240. mf->width = mf_tmp.width;
  1241. mf->height = mf_tmp.height;
  1242. mf->colorspace = mf_tmp.colorspace;
  1243. /*
  1244. * 8. Calculate new CEU crop - apply camera scales to previously
  1245. * updated "effective" crop.
  1246. */
  1247. *width = scale_down(cam->subrect.width, scale_h);
  1248. *height = scale_down(cam->subrect.height, scale_v);
  1249. dev_geo(dev, "8: new client sub-window %ux%u\n", *width, *height);
  1250. return 0;
  1251. }
  1252. /*
  1253. * CEU can scale and crop, but we don't want to waste bandwidth and kill the
  1254. * framerate by always requesting the maximum image from the client. See
  1255. * Documentation/video4linux/sh_mobile_ceu_camera.txt for a description of
  1256. * scaling and cropping algorithms and for the meaning of referenced here steps.
  1257. */
  1258. static int sh_mobile_ceu_set_crop(struct soc_camera_device *icd,
  1259. struct v4l2_crop *a)
  1260. {
  1261. struct v4l2_rect *rect = &a->c;
  1262. struct device *dev = icd->parent;
  1263. struct soc_camera_host *ici = to_soc_camera_host(dev);
  1264. struct sh_mobile_ceu_dev *pcdev = ici->priv;
  1265. struct v4l2_crop cam_crop;
  1266. struct sh_mobile_ceu_cam *cam = icd->host_priv;
  1267. struct v4l2_rect *cam_rect = &cam_crop.c;
  1268. struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
  1269. struct v4l2_mbus_framefmt mf;
  1270. unsigned int scale_cam_h, scale_cam_v, scale_ceu_h, scale_ceu_v,
  1271. out_width, out_height;
  1272. int interm_width, interm_height;
  1273. u32 capsr, cflcr;
  1274. int ret;
  1275. dev_geo(dev, "S_CROP(%ux%u@%u:%u)\n", rect->width, rect->height,
  1276. rect->left, rect->top);
  1277. /* During camera cropping its output window can change too, stop CEU */
  1278. capsr = capture_save_reset(pcdev);
  1279. dev_dbg(dev, "CAPSR 0x%x, CFLCR 0x%x\n", capsr, pcdev->cflcr);
  1280. /*
  1281. * 1. - 2. Apply iterative camera S_CROP for new input window, read back
  1282. * actual camera rectangle.
  1283. */
  1284. ret = client_s_crop(icd, a, &cam_crop);
  1285. if (ret < 0)
  1286. return ret;
  1287. dev_geo(dev, "1-2: camera cropped to %ux%u@%u:%u\n",
  1288. cam_rect->width, cam_rect->height,
  1289. cam_rect->left, cam_rect->top);
  1290. /* On success cam_crop contains current camera crop */
  1291. /* 3. Retrieve camera output window */
  1292. ret = v4l2_subdev_call(sd, video, g_mbus_fmt, &mf);
  1293. if (ret < 0)
  1294. return ret;
  1295. if (mf.width > 2560 || mf.height > 1920)
  1296. return -EINVAL;
  1297. /* 4. Calculate camera scales */
  1298. scale_cam_h = calc_generic_scale(cam_rect->width, mf.width);
  1299. scale_cam_v = calc_generic_scale(cam_rect->height, mf.height);
  1300. /* Calculate intermediate window */
  1301. interm_width = scale_down(rect->width, scale_cam_h);
  1302. interm_height = scale_down(rect->height, scale_cam_v);
  1303. if (interm_width < icd->user_width) {
  1304. u32 new_scale_h;
  1305. new_scale_h = calc_generic_scale(rect->width, icd->user_width);
  1306. mf.width = scale_down(cam_rect->width, new_scale_h);
  1307. }
  1308. if (interm_height < icd->user_height) {
  1309. u32 new_scale_v;
  1310. new_scale_v = calc_generic_scale(rect->height, icd->user_height);
  1311. mf.height = scale_down(cam_rect->height, new_scale_v);
  1312. }
  1313. if (interm_width < icd->user_width || interm_height < icd->user_height) {
  1314. ret = v4l2_device_call_until_err(sd->v4l2_dev,
  1315. soc_camera_grp_id(icd), video,
  1316. s_mbus_fmt, &mf);
  1317. if (ret < 0)
  1318. return ret;
  1319. dev_geo(dev, "New camera output %ux%u\n", mf.width, mf.height);
  1320. scale_cam_h = calc_generic_scale(cam_rect->width, mf.width);
  1321. scale_cam_v = calc_generic_scale(cam_rect->height, mf.height);
  1322. interm_width = scale_down(rect->width, scale_cam_h);
  1323. interm_height = scale_down(rect->height, scale_cam_v);
  1324. }
  1325. /* Cache camera output window */
  1326. cam->width = mf.width;
  1327. cam->height = mf.height;
  1328. if (pcdev->image_mode) {
  1329. out_width = min(interm_width, icd->user_width);
  1330. out_height = min(interm_height, icd->user_height);
  1331. } else {
  1332. out_width = interm_width;
  1333. out_height = interm_height;
  1334. }
  1335. /*
  1336. * 5. Calculate CEU scales from camera scales from results of (5) and
  1337. * the user window
  1338. */
  1339. scale_ceu_h = calc_scale(interm_width, &out_width);
  1340. scale_ceu_v = calc_scale(interm_height, &out_height);
  1341. dev_geo(dev, "5: CEU scales %u:%u\n", scale_ceu_h, scale_ceu_v);
  1342. /* Apply CEU scales. */
  1343. cflcr = scale_ceu_h | (scale_ceu_v << 16);
  1344. if (cflcr != pcdev->cflcr) {
  1345. pcdev->cflcr = cflcr;
  1346. ceu_write(pcdev, CFLCR, cflcr);
  1347. }
  1348. icd->user_width = out_width & ~3;
  1349. icd->user_height = out_height & ~3;
  1350. /* Offsets are applied at the CEU scaling filter input */
  1351. cam->ceu_left = scale_down(rect->left - cam_rect->left, scale_cam_h) & ~1;
  1352. cam->ceu_top = scale_down(rect->top - cam_rect->top, scale_cam_v) & ~1;
  1353. /* 6. Use CEU cropping to crop to the new window. */
  1354. sh_mobile_ceu_set_rect(icd);
  1355. cam->subrect = *rect;
  1356. dev_geo(dev, "6: CEU cropped to %ux%u@%u:%u\n",
  1357. icd->user_width, icd->user_height,
  1358. cam->ceu_left, cam->ceu_top);
  1359. /* Restore capture. The CE bit can be cleared by the hardware */
  1360. if (pcdev->active)
  1361. capsr |= 1;
  1362. capture_restore(pcdev, capsr);
  1363. /* Even if only camera cropping succeeded */
  1364. return ret;
  1365. }
  1366. static int sh_mobile_ceu_get_crop(struct soc_camera_device *icd,
  1367. struct v4l2_crop *a)
  1368. {
  1369. struct sh_mobile_ceu_cam *cam = icd->host_priv;
  1370. a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  1371. a->c = cam->subrect;
  1372. return 0;
  1373. }
  1374. /*
  1375. * Calculate real client output window by applying new scales to the current
  1376. * client crop. New scales are calculated from the requested output format and
  1377. * CEU crop, mapped backed onto the client input (subrect).
  1378. */
  1379. static void calculate_client_output(struct soc_camera_device *icd,
  1380. const struct v4l2_pix_format *pix, struct v4l2_mbus_framefmt *mf)
  1381. {
  1382. struct sh_mobile_ceu_cam *cam = icd->host_priv;
  1383. struct device *dev = icd->parent;
  1384. struct v4l2_rect *cam_subrect = &cam->subrect;
  1385. unsigned int scale_v, scale_h;
  1386. if (cam_subrect->width == cam->rect.width &&
  1387. cam_subrect->height == cam->rect.height) {
  1388. /* No sub-cropping */
  1389. mf->width = pix->width;
  1390. mf->height = pix->height;
  1391. return;
  1392. }
  1393. /* 1.-2. Current camera scales and subwin - cached. */
  1394. dev_geo(dev, "2: subwin %ux%u@%u:%u\n",
  1395. cam_subrect->width, cam_subrect->height,
  1396. cam_subrect->left, cam_subrect->top);
  1397. /*
  1398. * 3. Calculate new combined scales from input sub-window to requested
  1399. * user window.
  1400. */
  1401. /*
  1402. * TODO: CEU cannot scale images larger than VGA to smaller than SubQCIF
  1403. * (128x96) or larger than VGA
  1404. */
  1405. scale_h = calc_generic_scale(cam_subrect->width, pix->width);
  1406. scale_v = calc_generic_scale(cam_subrect->height, pix->height);
  1407. dev_geo(dev, "3: scales %u:%u\n", scale_h, scale_v);
  1408. /*
  1409. * 4. Calculate desired client output window by applying combined scales
  1410. * to client (real) input window.
  1411. */
  1412. mf->width = scale_down(cam->rect.width, scale_h);
  1413. mf->height = scale_down(cam->rect.height, scale_v);
  1414. }
  1415. /* Similar to set_crop multistage iterative algorithm */
  1416. static int sh_mobile_ceu_set_fmt(struct soc_camera_device *icd,
  1417. struct v4l2_format *f)
  1418. {
  1419. struct device *dev = icd->parent;
  1420. struct soc_camera_host *ici = to_soc_camera_host(dev);
  1421. struct sh_mobile_ceu_dev *pcdev = ici->priv;
  1422. struct sh_mobile_ceu_cam *cam = icd->host_priv;
  1423. struct v4l2_pix_format *pix = &f->fmt.pix;
  1424. struct v4l2_mbus_framefmt mf;
  1425. __u32 pixfmt = pix->pixelformat;
  1426. const struct soc_camera_format_xlate *xlate;
  1427. /* Keep Compiler Happy */
  1428. unsigned int ceu_sub_width = 0, ceu_sub_height = 0;
  1429. u16 scale_v, scale_h;
  1430. int ret;
  1431. bool image_mode;
  1432. enum v4l2_field field;
  1433. switch (pix->field) {
  1434. default:
  1435. pix->field = V4L2_FIELD_NONE;
  1436. /* fall-through */
  1437. case V4L2_FIELD_INTERLACED_TB:
  1438. case V4L2_FIELD_INTERLACED_BT:
  1439. case V4L2_FIELD_NONE:
  1440. field = pix->field;
  1441. break;
  1442. case V4L2_FIELD_INTERLACED:
  1443. field = V4L2_FIELD_INTERLACED_TB;
  1444. break;
  1445. }
  1446. xlate = soc_camera_xlate_by_fourcc(icd, pixfmt);
  1447. if (!xlate) {
  1448. dev_warn(dev, "Format %x not found\n", pixfmt);
  1449. return -EINVAL;
  1450. }
  1451. /* 1.-4. Calculate desired client output geometry */
  1452. calculate_client_output(icd, pix, &mf);
  1453. mf.field = pix->field;
  1454. mf.colorspace = pix->colorspace;
  1455. mf.code = xlate->code;
  1456. switch (pixfmt) {
  1457. case V4L2_PIX_FMT_NV12:
  1458. case V4L2_PIX_FMT_NV21:
  1459. case V4L2_PIX_FMT_NV16:
  1460. case V4L2_PIX_FMT_NV61:
  1461. image_mode = true;
  1462. break;
  1463. default:
  1464. image_mode = false;
  1465. }
  1466. dev_geo(dev, "S_FMT(pix=0x%x, fld 0x%x, code 0x%x, %ux%u)\n", pixfmt, mf.field, mf.code,
  1467. pix->width, pix->height);
  1468. dev_geo(dev, "4: request camera output %ux%u\n", mf.width, mf.height);
  1469. /* 5. - 9. */
  1470. ret = client_scale(icd, &mf, &ceu_sub_width, &ceu_sub_height,
  1471. image_mode && V4L2_FIELD_NONE == field);
  1472. dev_geo(dev, "5-9: client scale return %d\n", ret);
  1473. /* Done with the camera. Now see if we can improve the result */
  1474. dev_geo(dev, "fmt %ux%u, requested %ux%u\n",
  1475. mf.width, mf.height, pix->width, pix->height);
  1476. if (ret < 0)
  1477. return ret;
  1478. if (mf.code != xlate->code)
  1479. return -EINVAL;
  1480. /* 9. Prepare CEU crop */
  1481. cam->width = mf.width;
  1482. cam->height = mf.height;
  1483. /* 10. Use CEU scaling to scale to the requested user window. */
  1484. /* We cannot scale up */
  1485. if (pix->width > ceu_sub_width)
  1486. ceu_sub_width = pix->width;
  1487. if (pix->height > ceu_sub_height)
  1488. ceu_sub_height = pix->height;
  1489. pix->colorspace = mf.colorspace;
  1490. if (image_mode) {
  1491. /* Scale pix->{width x height} down to width x height */
  1492. scale_h = calc_scale(ceu_sub_width, &pix->width);
  1493. scale_v = calc_scale(ceu_sub_height, &pix->height);
  1494. } else {
  1495. pix->width = ceu_sub_width;
  1496. pix->height = ceu_sub_height;
  1497. scale_h = 0;
  1498. scale_v = 0;
  1499. }
  1500. pcdev->cflcr = scale_h | (scale_v << 16);
  1501. /*
  1502. * We have calculated CFLCR, the actual configuration will be performed
  1503. * in sh_mobile_ceu_set_bus_param()
  1504. */
  1505. dev_geo(dev, "10: W: %u : 0x%x = %u, H: %u : 0x%x = %u\n",
  1506. ceu_sub_width, scale_h, pix->width,
  1507. ceu_sub_height, scale_v, pix->height);
  1508. cam->code = xlate->code;
  1509. icd->current_fmt = xlate;
  1510. pcdev->field = field;
  1511. pcdev->image_mode = image_mode;
  1512. /* CFSZR requirement */
  1513. pix->width &= ~3;
  1514. pix->height &= ~3;
  1515. return 0;
  1516. }
  1517. static int sh_mobile_ceu_try_fmt(struct soc_camera_device *icd,
  1518. struct v4l2_format *f)
  1519. {
  1520. const struct soc_camera_format_xlate *xlate;
  1521. struct v4l2_pix_format *pix = &f->fmt.pix;
  1522. struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
  1523. struct v4l2_mbus_framefmt mf;
  1524. __u32 pixfmt = pix->pixelformat;
  1525. int width, height;
  1526. int ret;
  1527. dev_geo(icd->parent, "TRY_FMT(pix=0x%x, %ux%u)\n",
  1528. pixfmt, pix->width, pix->height);
  1529. xlate = soc_camera_xlate_by_fourcc(icd, pixfmt);
  1530. if (!xlate) {
  1531. dev_warn(icd->parent, "Format %x not found\n", pixfmt);
  1532. return -EINVAL;
  1533. }
  1534. /* FIXME: calculate using depth and bus width */
  1535. /* CFSZR requires height and width to be 4-pixel aligned */
  1536. v4l_bound_align_image(&pix->width, 2, 2560, 2,
  1537. &pix->height, 4, 1920, 2, 0);
  1538. width = pix->width;
  1539. height = pix->height;
  1540. /* limit to sensor capabilities */
  1541. mf.width = pix->width;
  1542. mf.height = pix->height;
  1543. mf.field = pix->field;
  1544. mf.code = xlate->code;
  1545. mf.colorspace = pix->colorspace;
  1546. ret = v4l2_device_call_until_err(sd->v4l2_dev, soc_camera_grp_id(icd),
  1547. video, try_mbus_fmt, &mf);
  1548. if (ret < 0)
  1549. return ret;
  1550. pix->width = mf.width;
  1551. pix->height = mf.height;
  1552. pix->field = mf.field;
  1553. pix->colorspace = mf.colorspace;
  1554. switch (pixfmt) {
  1555. case V4L2_PIX_FMT_NV12:
  1556. case V4L2_PIX_FMT_NV21:
  1557. case V4L2_PIX_FMT_NV16:
  1558. case V4L2_PIX_FMT_NV61:
  1559. /* FIXME: check against rect_max after converting soc-camera */
  1560. /* We can scale precisely, need a bigger image from camera */
  1561. if (pix->width < width || pix->height < height) {
  1562. /*
  1563. * We presume, the sensor behaves sanely, i.e., if
  1564. * requested a bigger rectangle, it will not return a
  1565. * smaller one.
  1566. */
  1567. mf.width = 2560;
  1568. mf.height = 1920;
  1569. ret = v4l2_device_call_until_err(sd->v4l2_dev,
  1570. soc_camera_grp_id(icd), video,
  1571. try_mbus_fmt, &mf);
  1572. if (ret < 0) {
  1573. /* Shouldn't actually happen... */
  1574. dev_err(icd->parent,
  1575. "FIXME: client try_fmt() = %d\n", ret);
  1576. return ret;
  1577. }
  1578. }
  1579. /* We will scale exactly */
  1580. if (mf.width > width)
  1581. pix->width = width;
  1582. if (mf.height > height)
  1583. pix->height = height;
  1584. }
  1585. pix->width &= ~3;
  1586. pix->height &= ~3;
  1587. dev_geo(icd->parent, "%s(): return %d, fmt 0x%x, %ux%u\n",
  1588. __func__, ret, pix->pixelformat, pix->width, pix->height);
  1589. return ret;
  1590. }
  1591. static int sh_mobile_ceu_set_livecrop(struct soc_camera_device *icd,
  1592. struct v4l2_crop *a)
  1593. {
  1594. struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
  1595. struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
  1596. struct sh_mobile_ceu_dev *pcdev = ici->priv;
  1597. u32 out_width = icd->user_width, out_height = icd->user_height;
  1598. int ret;
  1599. /* Freeze queue */
  1600. pcdev->frozen = 1;
  1601. /* Wait for frame */
  1602. ret = wait_for_completion_interruptible(&pcdev->complete);
  1603. /* Stop the client */
  1604. ret = v4l2_subdev_call(sd, video, s_stream, 0);
  1605. if (ret < 0)
  1606. dev_warn(icd->parent,
  1607. "Client failed to stop the stream: %d\n", ret);
  1608. else
  1609. /* Do the crop, if it fails, there's nothing more we can do */
  1610. sh_mobile_ceu_set_crop(icd, a);
  1611. dev_geo(icd->parent, "Output after crop: %ux%u\n", icd->user_width, icd->user_height);
  1612. if (icd->user_width != out_width || icd->user_height != out_height) {
  1613. struct v4l2_format f = {
  1614. .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
  1615. .fmt.pix = {
  1616. .width = out_width,
  1617. .height = out_height,
  1618. .pixelformat = icd->current_fmt->host_fmt->fourcc,
  1619. .field = pcdev->field,
  1620. .colorspace = icd->colorspace,
  1621. },
  1622. };
  1623. ret = sh_mobile_ceu_set_fmt(icd, &f);
  1624. if (!ret && (out_width != f.fmt.pix.width ||
  1625. out_height != f.fmt.pix.height))
  1626. ret = -EINVAL;
  1627. if (!ret) {
  1628. icd->user_width = out_width & ~3;
  1629. icd->user_height = out_height & ~3;
  1630. ret = sh_mobile_ceu_set_bus_param(icd);
  1631. }
  1632. }
  1633. /* Thaw the queue */
  1634. pcdev->frozen = 0;
  1635. spin_lock_irq(&pcdev->lock);
  1636. sh_mobile_ceu_capture(pcdev);
  1637. spin_unlock_irq(&pcdev->lock);
  1638. /* Start the client */
  1639. ret = v4l2_subdev_call(sd, video, s_stream, 1);
  1640. return ret;
  1641. }
  1642. static unsigned int sh_mobile_ceu_poll(struct file *file, poll_table *pt)
  1643. {
  1644. struct soc_camera_device *icd = file->private_data;
  1645. return vb2_poll(&icd->vb2_vidq, file, pt);
  1646. }
  1647. static int sh_mobile_ceu_querycap(struct soc_camera_host *ici,
  1648. struct v4l2_capability *cap)
  1649. {
  1650. strlcpy(cap->card, "SuperH_Mobile_CEU", sizeof(cap->card));
  1651. cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
  1652. return 0;
  1653. }
  1654. static int sh_mobile_ceu_init_videobuf(struct vb2_queue *q,
  1655. struct soc_camera_device *icd)
  1656. {
  1657. q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  1658. q->io_modes = VB2_MMAP | VB2_USERPTR;
  1659. q->drv_priv = icd;
  1660. q->ops = &sh_mobile_ceu_videobuf_ops;
  1661. q->mem_ops = &vb2_dma_contig_memops;
  1662. q->buf_struct_size = sizeof(struct sh_mobile_ceu_buffer);
  1663. return vb2_queue_init(q);
  1664. }
  1665. static struct soc_camera_host_ops sh_mobile_ceu_host_ops = {
  1666. .owner = THIS_MODULE,
  1667. .add = sh_mobile_ceu_add_device,
  1668. .remove = sh_mobile_ceu_remove_device,
  1669. .get_formats = sh_mobile_ceu_get_formats,
  1670. .put_formats = sh_mobile_ceu_put_formats,
  1671. .get_crop = sh_mobile_ceu_get_crop,
  1672. .set_crop = sh_mobile_ceu_set_crop,
  1673. .set_livecrop = sh_mobile_ceu_set_livecrop,
  1674. .set_fmt = sh_mobile_ceu_set_fmt,
  1675. .try_fmt = sh_mobile_ceu_try_fmt,
  1676. .poll = sh_mobile_ceu_poll,
  1677. .querycap = sh_mobile_ceu_querycap,
  1678. .set_bus_param = sh_mobile_ceu_set_bus_param,
  1679. .init_videobuf2 = sh_mobile_ceu_init_videobuf,
  1680. };
  1681. struct bus_wait {
  1682. struct notifier_block notifier;
  1683. struct completion completion;
  1684. struct device *dev;
  1685. };
  1686. static int bus_notify(struct notifier_block *nb,
  1687. unsigned long action, void *data)
  1688. {
  1689. struct device *dev = data;
  1690. struct bus_wait *wait = container_of(nb, struct bus_wait, notifier);
  1691. if (wait->dev != dev)
  1692. return NOTIFY_DONE;
  1693. switch (action) {
  1694. case BUS_NOTIFY_UNBOUND_DRIVER:
  1695. /* Protect from module unloading */
  1696. wait_for_completion(&wait->completion);
  1697. return NOTIFY_OK;
  1698. }
  1699. return NOTIFY_DONE;
  1700. }
  1701. static int __devinit sh_mobile_ceu_probe(struct platform_device *pdev)
  1702. {
  1703. struct sh_mobile_ceu_dev *pcdev;
  1704. struct resource *res;
  1705. void __iomem *base;
  1706. unsigned int irq;
  1707. int err = 0;
  1708. struct bus_wait wait = {
  1709. .completion = COMPLETION_INITIALIZER_ONSTACK(wait.completion),
  1710. .notifier.notifier_call = bus_notify,
  1711. };
  1712. struct sh_mobile_ceu_companion *csi2;
  1713. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1714. irq = platform_get_irq(pdev, 0);
  1715. if (!res || (int)irq <= 0) {
  1716. dev_err(&pdev->dev, "Not enough CEU platform resources.\n");
  1717. err = -ENODEV;
  1718. goto exit;
  1719. }
  1720. pcdev = kzalloc(sizeof(*pcdev), GFP_KERNEL);
  1721. if (!pcdev) {
  1722. dev_err(&pdev->dev, "Could not allocate pcdev\n");
  1723. err = -ENOMEM;
  1724. goto exit;
  1725. }
  1726. INIT_LIST_HEAD(&pcdev->capture);
  1727. spin_lock_init(&pcdev->lock);
  1728. init_completion(&pcdev->complete);
  1729. pcdev->pdata = pdev->dev.platform_data;
  1730. if (!pcdev->pdata) {
  1731. err = -EINVAL;
  1732. dev_err(&pdev->dev, "CEU platform data not set.\n");
  1733. goto exit_kfree;
  1734. }
  1735. base = ioremap_nocache(res->start, resource_size(res));
  1736. if (!base) {
  1737. err = -ENXIO;
  1738. dev_err(&pdev->dev, "Unable to ioremap CEU registers.\n");
  1739. goto exit_kfree;
  1740. }
  1741. pcdev->irq = irq;
  1742. pcdev->base = base;
  1743. pcdev->video_limit = 0; /* only enabled if second resource exists */
  1744. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  1745. if (res) {
  1746. err = dma_declare_coherent_memory(&pdev->dev, res->start,
  1747. res->start,
  1748. resource_size(res),
  1749. DMA_MEMORY_MAP |
  1750. DMA_MEMORY_EXCLUSIVE);
  1751. if (!err) {
  1752. dev_err(&pdev->dev, "Unable to declare CEU memory.\n");
  1753. err = -ENXIO;
  1754. goto exit_iounmap;
  1755. }
  1756. pcdev->video_limit = resource_size(res);
  1757. }
  1758. /* request irq */
  1759. err = request_irq(pcdev->irq, sh_mobile_ceu_irq, IRQF_DISABLED,
  1760. dev_name(&pdev->dev), pcdev);
  1761. if (err) {
  1762. dev_err(&pdev->dev, "Unable to register CEU interrupt.\n");
  1763. goto exit_release_mem;
  1764. }
  1765. pm_suspend_ignore_children(&pdev->dev, true);
  1766. pm_runtime_enable(&pdev->dev);
  1767. pm_runtime_resume(&pdev->dev);
  1768. pcdev->ici.priv = pcdev;
  1769. pcdev->ici.v4l2_dev.dev = &pdev->dev;
  1770. pcdev->ici.nr = pdev->id;
  1771. pcdev->ici.drv_name = dev_name(&pdev->dev);
  1772. pcdev->ici.ops = &sh_mobile_ceu_host_ops;
  1773. pcdev->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev);
  1774. if (IS_ERR(pcdev->alloc_ctx)) {
  1775. err = PTR_ERR(pcdev->alloc_ctx);
  1776. goto exit_free_clk;
  1777. }
  1778. err = soc_camera_host_register(&pcdev->ici);
  1779. if (err)
  1780. goto exit_free_ctx;
  1781. /* CSI2 interfacing */
  1782. csi2 = pcdev->pdata->csi2;
  1783. if (csi2) {
  1784. struct platform_device *csi2_pdev =
  1785. platform_device_alloc("sh-mobile-csi2", csi2->id);
  1786. struct sh_csi2_pdata *csi2_pdata = csi2->platform_data;
  1787. if (!csi2_pdev) {
  1788. err = -ENOMEM;
  1789. goto exit_host_unregister;
  1790. }
  1791. pcdev->csi2_pdev = csi2_pdev;
  1792. err = platform_device_add_data(csi2_pdev, csi2_pdata, sizeof(*csi2_pdata));
  1793. if (err < 0)
  1794. goto exit_pdev_put;
  1795. csi2_pdata = csi2_pdev->dev.platform_data;
  1796. csi2_pdata->v4l2_dev = &pcdev->ici.v4l2_dev;
  1797. csi2_pdev->resource = csi2->resource;
  1798. csi2_pdev->num_resources = csi2->num_resources;
  1799. err = platform_device_add(csi2_pdev);
  1800. if (err < 0)
  1801. goto exit_pdev_put;
  1802. wait.dev = &csi2_pdev->dev;
  1803. err = bus_register_notifier(&platform_bus_type, &wait.notifier);
  1804. if (err < 0)
  1805. goto exit_pdev_unregister;
  1806. /*
  1807. * From this point the driver module will not unload, until
  1808. * we complete the completion.
  1809. */
  1810. if (!csi2_pdev->dev.driver) {
  1811. complete(&wait.completion);
  1812. /* Either too late, or probing failed */
  1813. bus_unregister_notifier(&platform_bus_type, &wait.notifier);
  1814. err = -ENXIO;
  1815. goto exit_pdev_unregister;
  1816. }
  1817. /*
  1818. * The module is still loaded, in the worst case it is hanging
  1819. * in device release on our completion. So, _now_ dereferencing
  1820. * the "owner" is safe!
  1821. */
  1822. err = try_module_get(csi2_pdev->dev.driver->owner);
  1823. /* Let notifier complete, if it has been locked */
  1824. complete(&wait.completion);
  1825. bus_unregister_notifier(&platform_bus_type, &wait.notifier);
  1826. if (!err) {
  1827. err = -ENODEV;
  1828. goto exit_pdev_unregister;
  1829. }
  1830. }
  1831. return 0;
  1832. exit_pdev_unregister:
  1833. platform_device_del(pcdev->csi2_pdev);
  1834. exit_pdev_put:
  1835. pcdev->csi2_pdev->resource = NULL;
  1836. platform_device_put(pcdev->csi2_pdev);
  1837. exit_host_unregister:
  1838. soc_camera_host_unregister(&pcdev->ici);
  1839. exit_free_ctx:
  1840. vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx);
  1841. exit_free_clk:
  1842. pm_runtime_disable(&pdev->dev);
  1843. free_irq(pcdev->irq, pcdev);
  1844. exit_release_mem:
  1845. if (platform_get_resource(pdev, IORESOURCE_MEM, 1))
  1846. dma_release_declared_memory(&pdev->dev);
  1847. exit_iounmap:
  1848. iounmap(base);
  1849. exit_kfree:
  1850. kfree(pcdev);
  1851. exit:
  1852. return err;
  1853. }
  1854. static int __devexit sh_mobile_ceu_remove(struct platform_device *pdev)
  1855. {
  1856. struct soc_camera_host *soc_host = to_soc_camera_host(&pdev->dev);
  1857. struct sh_mobile_ceu_dev *pcdev = container_of(soc_host,
  1858. struct sh_mobile_ceu_dev, ici);
  1859. struct platform_device *csi2_pdev = pcdev->csi2_pdev;
  1860. soc_camera_host_unregister(soc_host);
  1861. pm_runtime_disable(&pdev->dev);
  1862. free_irq(pcdev->irq, pcdev);
  1863. if (platform_get_resource(pdev, IORESOURCE_MEM, 1))
  1864. dma_release_declared_memory(&pdev->dev);
  1865. iounmap(pcdev->base);
  1866. vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx);
  1867. if (csi2_pdev && csi2_pdev->dev.driver) {
  1868. struct module *csi2_drv = csi2_pdev->dev.driver->owner;
  1869. platform_device_del(csi2_pdev);
  1870. csi2_pdev->resource = NULL;
  1871. platform_device_put(csi2_pdev);
  1872. module_put(csi2_drv);
  1873. }
  1874. kfree(pcdev);
  1875. return 0;
  1876. }
  1877. static int sh_mobile_ceu_runtime_nop(struct device *dev)
  1878. {
  1879. /* Runtime PM callback shared between ->runtime_suspend()
  1880. * and ->runtime_resume(). Simply returns success.
  1881. *
  1882. * This driver re-initializes all registers after
  1883. * pm_runtime_get_sync() anyway so there is no need
  1884. * to save and restore registers here.
  1885. */
  1886. return 0;
  1887. }
  1888. static const struct dev_pm_ops sh_mobile_ceu_dev_pm_ops = {
  1889. .runtime_suspend = sh_mobile_ceu_runtime_nop,
  1890. .runtime_resume = sh_mobile_ceu_runtime_nop,
  1891. };
  1892. static struct platform_driver sh_mobile_ceu_driver = {
  1893. .driver = {
  1894. .name = "sh_mobile_ceu",
  1895. .pm = &sh_mobile_ceu_dev_pm_ops,
  1896. },
  1897. .probe = sh_mobile_ceu_probe,
  1898. .remove = __devexit_p(sh_mobile_ceu_remove),
  1899. };
  1900. static int __init sh_mobile_ceu_init(void)
  1901. {
  1902. /* Whatever return code */
  1903. request_module("sh_mobile_csi2");
  1904. return platform_driver_register(&sh_mobile_ceu_driver);
  1905. }
  1906. static void __exit sh_mobile_ceu_exit(void)
  1907. {
  1908. platform_driver_unregister(&sh_mobile_ceu_driver);
  1909. }
  1910. module_init(sh_mobile_ceu_init);
  1911. module_exit(sh_mobile_ceu_exit);
  1912. MODULE_DESCRIPTION("SuperH Mobile CEU driver");
  1913. MODULE_AUTHOR("Magnus Damm");
  1914. MODULE_LICENSE("GPL");
  1915. MODULE_VERSION("0.0.6");
  1916. MODULE_ALIAS("platform:sh_mobile_ceu");