mx2_camera.c 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652
  1. /*
  2. * V4L2 Driver for i.MX27 camera host
  3. *
  4. * Copyright (C) 2008, Sascha Hauer, Pengutronix
  5. * Copyright (C) 2010, Baruch Siach, Orex Computed Radiography
  6. * Copyright (C) 2012, Javier Martin, Vista Silicon S.L.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. */
  13. #include <linux/init.h>
  14. #include <linux/module.h>
  15. #include <linux/io.h>
  16. #include <linux/delay.h>
  17. #include <linux/slab.h>
  18. #include <linux/dma-mapping.h>
  19. #include <linux/errno.h>
  20. #include <linux/fs.h>
  21. #include <linux/gcd.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/kernel.h>
  24. #include <linux/math64.h>
  25. #include <linux/mm.h>
  26. #include <linux/moduleparam.h>
  27. #include <linux/time.h>
  28. #include <linux/device.h>
  29. #include <linux/platform_device.h>
  30. #include <linux/clk.h>
  31. #include <media/v4l2-common.h>
  32. #include <media/v4l2-dev.h>
  33. #include <media/videobuf2-core.h>
  34. #include <media/videobuf2-dma-contig.h>
  35. #include <media/soc_camera.h>
  36. #include <media/soc_mediabus.h>
  37. #include <linux/videodev2.h>
  38. #include <linux/platform_data/camera-mx2.h>
  39. #include <asm/dma.h>
  40. #define MX2_CAM_DRV_NAME "mx2-camera"
  41. #define MX2_CAM_VERSION "0.0.6"
  42. #define MX2_CAM_DRIVER_DESCRIPTION "i.MX2x_Camera"
  43. /* reset values */
  44. #define CSICR1_RESET_VAL 0x40000800
  45. #define CSICR2_RESET_VAL 0x0
  46. #define CSICR3_RESET_VAL 0x0
  47. /* csi control reg 1 */
  48. #define CSICR1_SWAP16_EN (1 << 31)
  49. #define CSICR1_EXT_VSYNC (1 << 30)
  50. #define CSICR1_EOF_INTEN (1 << 29)
  51. #define CSICR1_PRP_IF_EN (1 << 28)
  52. #define CSICR1_CCIR_MODE (1 << 27)
  53. #define CSICR1_COF_INTEN (1 << 26)
  54. #define CSICR1_SF_OR_INTEN (1 << 25)
  55. #define CSICR1_RF_OR_INTEN (1 << 24)
  56. #define CSICR1_STATFF_LEVEL (3 << 22)
  57. #define CSICR1_STATFF_INTEN (1 << 21)
  58. #define CSICR1_RXFF_LEVEL(l) (((l) & 3) << 19)
  59. #define CSICR1_RXFF_INTEN (1 << 18)
  60. #define CSICR1_SOF_POL (1 << 17)
  61. #define CSICR1_SOF_INTEN (1 << 16)
  62. #define CSICR1_MCLKDIV(d) (((d) & 0xF) << 12)
  63. #define CSICR1_HSYNC_POL (1 << 11)
  64. #define CSICR1_CCIR_EN (1 << 10)
  65. #define CSICR1_MCLKEN (1 << 9)
  66. #define CSICR1_FCC (1 << 8)
  67. #define CSICR1_PACK_DIR (1 << 7)
  68. #define CSICR1_CLR_STATFIFO (1 << 6)
  69. #define CSICR1_CLR_RXFIFO (1 << 5)
  70. #define CSICR1_GCLK_MODE (1 << 4)
  71. #define CSICR1_INV_DATA (1 << 3)
  72. #define CSICR1_INV_PCLK (1 << 2)
  73. #define CSICR1_REDGE (1 << 1)
  74. #define CSICR1_FMT_MASK (CSICR1_PACK_DIR | CSICR1_SWAP16_EN)
  75. #define SHIFT_STATFF_LEVEL 22
  76. #define SHIFT_RXFF_LEVEL 19
  77. #define SHIFT_MCLKDIV 12
  78. #define SHIFT_FRMCNT 16
  79. #define CSICR1 0x00
  80. #define CSICR2 0x04
  81. #define CSISR 0x08
  82. #define CSISTATFIFO 0x0c
  83. #define CSIRFIFO 0x10
  84. #define CSIRXCNT 0x14
  85. #define CSICR3 0x1c
  86. #define CSIDMASA_STATFIFO 0x20
  87. #define CSIDMATA_STATFIFO 0x24
  88. #define CSIDMASA_FB1 0x28
  89. #define CSIDMASA_FB2 0x2c
  90. #define CSIFBUF_PARA 0x30
  91. #define CSIIMAG_PARA 0x34
  92. /* EMMA PrP */
  93. #define PRP_CNTL 0x00
  94. #define PRP_INTR_CNTL 0x04
  95. #define PRP_INTRSTATUS 0x08
  96. #define PRP_SOURCE_Y_PTR 0x0c
  97. #define PRP_SOURCE_CB_PTR 0x10
  98. #define PRP_SOURCE_CR_PTR 0x14
  99. #define PRP_DEST_RGB1_PTR 0x18
  100. #define PRP_DEST_RGB2_PTR 0x1c
  101. #define PRP_DEST_Y_PTR 0x20
  102. #define PRP_DEST_CB_PTR 0x24
  103. #define PRP_DEST_CR_PTR 0x28
  104. #define PRP_SRC_FRAME_SIZE 0x2c
  105. #define PRP_DEST_CH1_LINE_STRIDE 0x30
  106. #define PRP_SRC_PIXEL_FORMAT_CNTL 0x34
  107. #define PRP_CH1_PIXEL_FORMAT_CNTL 0x38
  108. #define PRP_CH1_OUT_IMAGE_SIZE 0x3c
  109. #define PRP_CH2_OUT_IMAGE_SIZE 0x40
  110. #define PRP_SRC_LINE_STRIDE 0x44
  111. #define PRP_CSC_COEF_012 0x48
  112. #define PRP_CSC_COEF_345 0x4c
  113. #define PRP_CSC_COEF_678 0x50
  114. #define PRP_CH1_RZ_HORI_COEF1 0x54
  115. #define PRP_CH1_RZ_HORI_COEF2 0x58
  116. #define PRP_CH1_RZ_HORI_VALID 0x5c
  117. #define PRP_CH1_RZ_VERT_COEF1 0x60
  118. #define PRP_CH1_RZ_VERT_COEF2 0x64
  119. #define PRP_CH1_RZ_VERT_VALID 0x68
  120. #define PRP_CH2_RZ_HORI_COEF1 0x6c
  121. #define PRP_CH2_RZ_HORI_COEF2 0x70
  122. #define PRP_CH2_RZ_HORI_VALID 0x74
  123. #define PRP_CH2_RZ_VERT_COEF1 0x78
  124. #define PRP_CH2_RZ_VERT_COEF2 0x7c
  125. #define PRP_CH2_RZ_VERT_VALID 0x80
  126. #define PRP_CNTL_CH1EN (1 << 0)
  127. #define PRP_CNTL_CH2EN (1 << 1)
  128. #define PRP_CNTL_CSIEN (1 << 2)
  129. #define PRP_CNTL_DATA_IN_YUV420 (0 << 3)
  130. #define PRP_CNTL_DATA_IN_YUV422 (1 << 3)
  131. #define PRP_CNTL_DATA_IN_RGB16 (2 << 3)
  132. #define PRP_CNTL_DATA_IN_RGB32 (3 << 3)
  133. #define PRP_CNTL_CH1_OUT_RGB8 (0 << 5)
  134. #define PRP_CNTL_CH1_OUT_RGB16 (1 << 5)
  135. #define PRP_CNTL_CH1_OUT_RGB32 (2 << 5)
  136. #define PRP_CNTL_CH1_OUT_YUV422 (3 << 5)
  137. #define PRP_CNTL_CH2_OUT_YUV420 (0 << 7)
  138. #define PRP_CNTL_CH2_OUT_YUV422 (1 << 7)
  139. #define PRP_CNTL_CH2_OUT_YUV444 (2 << 7)
  140. #define PRP_CNTL_CH1_LEN (1 << 9)
  141. #define PRP_CNTL_CH2_LEN (1 << 10)
  142. #define PRP_CNTL_SKIP_FRAME (1 << 11)
  143. #define PRP_CNTL_SWRST (1 << 12)
  144. #define PRP_CNTL_CLKEN (1 << 13)
  145. #define PRP_CNTL_WEN (1 << 14)
  146. #define PRP_CNTL_CH1BYP (1 << 15)
  147. #define PRP_CNTL_IN_TSKIP(x) ((x) << 16)
  148. #define PRP_CNTL_CH1_TSKIP(x) ((x) << 19)
  149. #define PRP_CNTL_CH2_TSKIP(x) ((x) << 22)
  150. #define PRP_CNTL_INPUT_FIFO_LEVEL(x) ((x) << 25)
  151. #define PRP_CNTL_RZ_FIFO_LEVEL(x) ((x) << 27)
  152. #define PRP_CNTL_CH2B1EN (1 << 29)
  153. #define PRP_CNTL_CH2B2EN (1 << 30)
  154. #define PRP_CNTL_CH2FEN (1 << 31)
  155. /* IRQ Enable and status register */
  156. #define PRP_INTR_RDERR (1 << 0)
  157. #define PRP_INTR_CH1WERR (1 << 1)
  158. #define PRP_INTR_CH2WERR (1 << 2)
  159. #define PRP_INTR_CH1FC (1 << 3)
  160. #define PRP_INTR_CH2FC (1 << 5)
  161. #define PRP_INTR_LBOVF (1 << 7)
  162. #define PRP_INTR_CH2OVF (1 << 8)
  163. /* Resizing registers */
  164. #define PRP_RZ_VALID_TBL_LEN(x) ((x) << 24)
  165. #define PRP_RZ_VALID_BILINEAR (1 << 31)
  166. #define MAX_VIDEO_MEM 16
  167. #define RESIZE_NUM_MIN 1
  168. #define RESIZE_NUM_MAX 20
  169. #define BC_COEF 3
  170. #define SZ_COEF (1 << BC_COEF)
  171. #define RESIZE_DIR_H 0
  172. #define RESIZE_DIR_V 1
  173. #define RESIZE_ALGO_BILINEAR 0
  174. #define RESIZE_ALGO_AVERAGING 1
  175. struct mx2_prp_cfg {
  176. int channel;
  177. u32 in_fmt;
  178. u32 out_fmt;
  179. u32 src_pixel;
  180. u32 ch1_pixel;
  181. u32 irq_flags;
  182. u32 csicr1;
  183. };
  184. /* prp resizing parameters */
  185. struct emma_prp_resize {
  186. int algo; /* type of algorithm used */
  187. int len; /* number of coefficients */
  188. unsigned char s[RESIZE_NUM_MAX]; /* table of coefficients */
  189. };
  190. /* prp configuration for a client-host fmt pair */
  191. struct mx2_fmt_cfg {
  192. enum v4l2_mbus_pixelcode in_fmt;
  193. u32 out_fmt;
  194. struct mx2_prp_cfg cfg;
  195. };
  196. enum mx2_buffer_state {
  197. MX2_STATE_QUEUED,
  198. MX2_STATE_ACTIVE,
  199. MX2_STATE_DONE,
  200. };
  201. struct mx2_buf_internal {
  202. struct list_head queue;
  203. int bufnum;
  204. bool discard;
  205. };
  206. /* buffer for one video frame */
  207. struct mx2_buffer {
  208. /* common v4l buffer stuff -- must be first */
  209. struct vb2_buffer vb;
  210. enum mx2_buffer_state state;
  211. struct mx2_buf_internal internal;
  212. };
  213. enum mx2_camera_type {
  214. IMX27_CAMERA,
  215. };
  216. struct mx2_camera_dev {
  217. struct device *dev;
  218. struct soc_camera_host soc_host;
  219. struct soc_camera_device *icd;
  220. struct clk *clk_emma_ahb, *clk_emma_ipg;
  221. struct clk *clk_csi_ahb, *clk_csi_per;
  222. void __iomem *base_csi, *base_emma;
  223. struct mx2_camera_platform_data *pdata;
  224. unsigned long platform_flags;
  225. struct list_head capture;
  226. struct list_head active_bufs;
  227. struct list_head discard;
  228. spinlock_t lock;
  229. int dma;
  230. struct mx2_buffer *active;
  231. struct mx2_buffer *fb1_active;
  232. struct mx2_buffer *fb2_active;
  233. u32 csicr1;
  234. enum mx2_camera_type devtype;
  235. struct mx2_buf_internal buf_discard[2];
  236. void *discard_buffer;
  237. dma_addr_t discard_buffer_dma;
  238. size_t discard_size;
  239. struct mx2_fmt_cfg *emma_prp;
  240. struct emma_prp_resize resizing[2];
  241. unsigned int s_width, s_height;
  242. u32 frame_count;
  243. struct vb2_alloc_ctx *alloc_ctx;
  244. };
  245. static struct platform_device_id mx2_camera_devtype[] = {
  246. {
  247. .name = "imx27-camera",
  248. .driver_data = IMX27_CAMERA,
  249. }, {
  250. /* sentinel */
  251. }
  252. };
  253. MODULE_DEVICE_TABLE(platform, mx2_camera_devtype);
  254. static struct mx2_buffer *mx2_ibuf_to_buf(struct mx2_buf_internal *int_buf)
  255. {
  256. return container_of(int_buf, struct mx2_buffer, internal);
  257. }
  258. static struct mx2_fmt_cfg mx27_emma_prp_table[] = {
  259. /*
  260. * This is a generic configuration which is valid for most
  261. * prp input-output format combinations.
  262. * We set the incomming and outgoing pixelformat to a
  263. * 16 Bit wide format and adjust the bytesperline
  264. * accordingly. With this configuration the inputdata
  265. * will not be changed by the emma and could be any type
  266. * of 16 Bit Pixelformat.
  267. */
  268. {
  269. .in_fmt = 0,
  270. .out_fmt = 0,
  271. .cfg = {
  272. .channel = 1,
  273. .in_fmt = PRP_CNTL_DATA_IN_RGB16,
  274. .out_fmt = PRP_CNTL_CH1_OUT_RGB16,
  275. .src_pixel = 0x2ca00565, /* RGB565 */
  276. .ch1_pixel = 0x2ca00565, /* RGB565 */
  277. .irq_flags = PRP_INTR_RDERR | PRP_INTR_CH1WERR |
  278. PRP_INTR_CH1FC | PRP_INTR_LBOVF,
  279. .csicr1 = 0,
  280. }
  281. },
  282. {
  283. .in_fmt = V4L2_MBUS_FMT_UYVY8_2X8,
  284. .out_fmt = V4L2_PIX_FMT_YUYV,
  285. .cfg = {
  286. .channel = 1,
  287. .in_fmt = PRP_CNTL_DATA_IN_YUV422,
  288. .out_fmt = PRP_CNTL_CH1_OUT_YUV422,
  289. .src_pixel = 0x22000888, /* YUV422 (YUYV) */
  290. .ch1_pixel = 0x62000888, /* YUV422 (YUYV) */
  291. .irq_flags = PRP_INTR_RDERR | PRP_INTR_CH1WERR |
  292. PRP_INTR_CH1FC | PRP_INTR_LBOVF,
  293. .csicr1 = CSICR1_SWAP16_EN,
  294. }
  295. },
  296. {
  297. .in_fmt = V4L2_MBUS_FMT_YUYV8_2X8,
  298. .out_fmt = V4L2_PIX_FMT_YUYV,
  299. .cfg = {
  300. .channel = 1,
  301. .in_fmt = PRP_CNTL_DATA_IN_YUV422,
  302. .out_fmt = PRP_CNTL_CH1_OUT_YUV422,
  303. .src_pixel = 0x22000888, /* YUV422 (YUYV) */
  304. .ch1_pixel = 0x62000888, /* YUV422 (YUYV) */
  305. .irq_flags = PRP_INTR_RDERR | PRP_INTR_CH1WERR |
  306. PRP_INTR_CH1FC | PRP_INTR_LBOVF,
  307. .csicr1 = CSICR1_PACK_DIR,
  308. }
  309. },
  310. {
  311. .in_fmt = V4L2_MBUS_FMT_YUYV8_2X8,
  312. .out_fmt = V4L2_PIX_FMT_YUV420,
  313. .cfg = {
  314. .channel = 2,
  315. .in_fmt = PRP_CNTL_DATA_IN_YUV422,
  316. .out_fmt = PRP_CNTL_CH2_OUT_YUV420,
  317. .src_pixel = 0x22000888, /* YUV422 (YUYV) */
  318. .irq_flags = PRP_INTR_RDERR | PRP_INTR_CH2WERR |
  319. PRP_INTR_CH2FC | PRP_INTR_LBOVF |
  320. PRP_INTR_CH2OVF,
  321. .csicr1 = CSICR1_PACK_DIR,
  322. }
  323. },
  324. {
  325. .in_fmt = V4L2_MBUS_FMT_UYVY8_2X8,
  326. .out_fmt = V4L2_PIX_FMT_YUV420,
  327. .cfg = {
  328. .channel = 2,
  329. .in_fmt = PRP_CNTL_DATA_IN_YUV422,
  330. .out_fmt = PRP_CNTL_CH2_OUT_YUV420,
  331. .src_pixel = 0x22000888, /* YUV422 (YUYV) */
  332. .irq_flags = PRP_INTR_RDERR | PRP_INTR_CH2WERR |
  333. PRP_INTR_CH2FC | PRP_INTR_LBOVF |
  334. PRP_INTR_CH2OVF,
  335. .csicr1 = CSICR1_SWAP16_EN,
  336. }
  337. },
  338. };
  339. static struct mx2_fmt_cfg *mx27_emma_prp_get_format(
  340. enum v4l2_mbus_pixelcode in_fmt,
  341. u32 out_fmt)
  342. {
  343. int i;
  344. for (i = 1; i < ARRAY_SIZE(mx27_emma_prp_table); i++)
  345. if ((mx27_emma_prp_table[i].in_fmt == in_fmt) &&
  346. (mx27_emma_prp_table[i].out_fmt == out_fmt)) {
  347. return &mx27_emma_prp_table[i];
  348. }
  349. /* If no match return the most generic configuration */
  350. return &mx27_emma_prp_table[0];
  351. };
  352. static void mx27_update_emma_buf(struct mx2_camera_dev *pcdev,
  353. unsigned long phys, int bufnum)
  354. {
  355. struct mx2_fmt_cfg *prp = pcdev->emma_prp;
  356. if (prp->cfg.channel == 1) {
  357. writel(phys, pcdev->base_emma +
  358. PRP_DEST_RGB1_PTR + 4 * bufnum);
  359. } else {
  360. writel(phys, pcdev->base_emma +
  361. PRP_DEST_Y_PTR - 0x14 * bufnum);
  362. if (prp->out_fmt == V4L2_PIX_FMT_YUV420) {
  363. u32 imgsize = pcdev->icd->user_height *
  364. pcdev->icd->user_width;
  365. writel(phys + imgsize, pcdev->base_emma +
  366. PRP_DEST_CB_PTR - 0x14 * bufnum);
  367. writel(phys + ((5 * imgsize) / 4), pcdev->base_emma +
  368. PRP_DEST_CR_PTR - 0x14 * bufnum);
  369. }
  370. }
  371. }
  372. static void mx2_camera_deactivate(struct mx2_camera_dev *pcdev)
  373. {
  374. clk_disable_unprepare(pcdev->clk_csi_ahb);
  375. clk_disable_unprepare(pcdev->clk_csi_per);
  376. writel(0, pcdev->base_csi + CSICR1);
  377. writel(0, pcdev->base_emma + PRP_CNTL);
  378. }
  379. /*
  380. * The following two functions absolutely depend on the fact, that
  381. * there can be only one camera on mx2 camera sensor interface
  382. */
  383. static int mx2_camera_add_device(struct soc_camera_device *icd)
  384. {
  385. struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
  386. struct mx2_camera_dev *pcdev = ici->priv;
  387. int ret;
  388. u32 csicr1;
  389. if (pcdev->icd)
  390. return -EBUSY;
  391. ret = clk_prepare_enable(pcdev->clk_csi_ahb);
  392. if (ret < 0)
  393. return ret;
  394. ret = clk_prepare_enable(pcdev->clk_csi_per);
  395. if (ret < 0)
  396. goto exit_csi_ahb;
  397. csicr1 = CSICR1_MCLKEN | CSICR1_PRP_IF_EN | CSICR1_FCC |
  398. CSICR1_RXFF_LEVEL(0);
  399. pcdev->csicr1 = csicr1;
  400. writel(pcdev->csicr1, pcdev->base_csi + CSICR1);
  401. pcdev->icd = icd;
  402. pcdev->frame_count = 0;
  403. dev_info(icd->parent, "Camera driver attached to camera %d\n",
  404. icd->devnum);
  405. return 0;
  406. exit_csi_ahb:
  407. clk_disable_unprepare(pcdev->clk_csi_ahb);
  408. return ret;
  409. }
  410. static void mx2_camera_remove_device(struct soc_camera_device *icd)
  411. {
  412. struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
  413. struct mx2_camera_dev *pcdev = ici->priv;
  414. BUG_ON(icd != pcdev->icd);
  415. dev_info(icd->parent, "Camera driver detached from camera %d\n",
  416. icd->devnum);
  417. mx2_camera_deactivate(pcdev);
  418. pcdev->icd = NULL;
  419. }
  420. /*
  421. * Videobuf operations
  422. */
  423. static int mx2_videobuf_setup(struct vb2_queue *vq,
  424. const struct v4l2_format *fmt,
  425. unsigned int *count, unsigned int *num_planes,
  426. unsigned int sizes[], void *alloc_ctxs[])
  427. {
  428. struct soc_camera_device *icd = soc_camera_from_vb2q(vq);
  429. struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
  430. struct mx2_camera_dev *pcdev = ici->priv;
  431. dev_dbg(icd->parent, "count=%d, size=%d\n", *count, sizes[0]);
  432. /* TODO: support for VIDIOC_CREATE_BUFS not ready */
  433. if (fmt != NULL)
  434. return -ENOTTY;
  435. alloc_ctxs[0] = pcdev->alloc_ctx;
  436. sizes[0] = icd->sizeimage;
  437. if (0 == *count)
  438. *count = 32;
  439. if (!*num_planes &&
  440. sizes[0] * *count > MAX_VIDEO_MEM * 1024 * 1024)
  441. *count = (MAX_VIDEO_MEM * 1024 * 1024) / sizes[0];
  442. *num_planes = 1;
  443. return 0;
  444. }
  445. static int mx2_videobuf_prepare(struct vb2_buffer *vb)
  446. {
  447. struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue);
  448. int ret = 0;
  449. dev_dbg(icd->parent, "%s (vb=0x%p) 0x%p %lu\n", __func__,
  450. vb, vb2_plane_vaddr(vb, 0), vb2_get_plane_payload(vb, 0));
  451. #ifdef DEBUG
  452. /*
  453. * This can be useful if you want to see if we actually fill
  454. * the buffer with something
  455. */
  456. memset((void *)vb2_plane_vaddr(vb, 0),
  457. 0xaa, vb2_get_plane_payload(vb, 0));
  458. #endif
  459. vb2_set_plane_payload(vb, 0, icd->sizeimage);
  460. if (vb2_plane_vaddr(vb, 0) &&
  461. vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0)) {
  462. ret = -EINVAL;
  463. goto out;
  464. }
  465. return 0;
  466. out:
  467. return ret;
  468. }
  469. static void mx2_videobuf_queue(struct vb2_buffer *vb)
  470. {
  471. struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue);
  472. struct soc_camera_host *ici =
  473. to_soc_camera_host(icd->parent);
  474. struct mx2_camera_dev *pcdev = ici->priv;
  475. struct mx2_buffer *buf = container_of(vb, struct mx2_buffer, vb);
  476. unsigned long flags;
  477. dev_dbg(icd->parent, "%s (vb=0x%p) 0x%p %lu\n", __func__,
  478. vb, vb2_plane_vaddr(vb, 0), vb2_get_plane_payload(vb, 0));
  479. spin_lock_irqsave(&pcdev->lock, flags);
  480. buf->state = MX2_STATE_QUEUED;
  481. list_add_tail(&buf->internal.queue, &pcdev->capture);
  482. spin_unlock_irqrestore(&pcdev->lock, flags);
  483. }
  484. static void mx27_camera_emma_buf_init(struct soc_camera_device *icd,
  485. int bytesperline)
  486. {
  487. struct soc_camera_host *ici =
  488. to_soc_camera_host(icd->parent);
  489. struct mx2_camera_dev *pcdev = ici->priv;
  490. struct mx2_fmt_cfg *prp = pcdev->emma_prp;
  491. writel((pcdev->s_width << 16) | pcdev->s_height,
  492. pcdev->base_emma + PRP_SRC_FRAME_SIZE);
  493. writel(prp->cfg.src_pixel,
  494. pcdev->base_emma + PRP_SRC_PIXEL_FORMAT_CNTL);
  495. if (prp->cfg.channel == 1) {
  496. writel((icd->user_width << 16) | icd->user_height,
  497. pcdev->base_emma + PRP_CH1_OUT_IMAGE_SIZE);
  498. writel(bytesperline,
  499. pcdev->base_emma + PRP_DEST_CH1_LINE_STRIDE);
  500. writel(prp->cfg.ch1_pixel,
  501. pcdev->base_emma + PRP_CH1_PIXEL_FORMAT_CNTL);
  502. } else { /* channel 2 */
  503. writel((icd->user_width << 16) | icd->user_height,
  504. pcdev->base_emma + PRP_CH2_OUT_IMAGE_SIZE);
  505. }
  506. /* Enable interrupts */
  507. writel(prp->cfg.irq_flags, pcdev->base_emma + PRP_INTR_CNTL);
  508. }
  509. static void mx2_prp_resize_commit(struct mx2_camera_dev *pcdev)
  510. {
  511. int dir;
  512. for (dir = RESIZE_DIR_H; dir <= RESIZE_DIR_V; dir++) {
  513. unsigned char *s = pcdev->resizing[dir].s;
  514. int len = pcdev->resizing[dir].len;
  515. unsigned int coeff[2] = {0, 0};
  516. unsigned int valid = 0;
  517. int i;
  518. if (len == 0)
  519. continue;
  520. for (i = RESIZE_NUM_MAX - 1; i >= 0; i--) {
  521. int j;
  522. j = i > 9 ? 1 : 0;
  523. coeff[j] = (coeff[j] << BC_COEF) |
  524. (s[i] & (SZ_COEF - 1));
  525. if (i == 5 || i == 15)
  526. coeff[j] <<= 1;
  527. valid = (valid << 1) | (s[i] >> BC_COEF);
  528. }
  529. valid |= PRP_RZ_VALID_TBL_LEN(len);
  530. if (pcdev->resizing[dir].algo == RESIZE_ALGO_BILINEAR)
  531. valid |= PRP_RZ_VALID_BILINEAR;
  532. if (pcdev->emma_prp->cfg.channel == 1) {
  533. if (dir == RESIZE_DIR_H) {
  534. writel(coeff[0], pcdev->base_emma +
  535. PRP_CH1_RZ_HORI_COEF1);
  536. writel(coeff[1], pcdev->base_emma +
  537. PRP_CH1_RZ_HORI_COEF2);
  538. writel(valid, pcdev->base_emma +
  539. PRP_CH1_RZ_HORI_VALID);
  540. } else {
  541. writel(coeff[0], pcdev->base_emma +
  542. PRP_CH1_RZ_VERT_COEF1);
  543. writel(coeff[1], pcdev->base_emma +
  544. PRP_CH1_RZ_VERT_COEF2);
  545. writel(valid, pcdev->base_emma +
  546. PRP_CH1_RZ_VERT_VALID);
  547. }
  548. } else {
  549. if (dir == RESIZE_DIR_H) {
  550. writel(coeff[0], pcdev->base_emma +
  551. PRP_CH2_RZ_HORI_COEF1);
  552. writel(coeff[1], pcdev->base_emma +
  553. PRP_CH2_RZ_HORI_COEF2);
  554. writel(valid, pcdev->base_emma +
  555. PRP_CH2_RZ_HORI_VALID);
  556. } else {
  557. writel(coeff[0], pcdev->base_emma +
  558. PRP_CH2_RZ_VERT_COEF1);
  559. writel(coeff[1], pcdev->base_emma +
  560. PRP_CH2_RZ_VERT_COEF2);
  561. writel(valid, pcdev->base_emma +
  562. PRP_CH2_RZ_VERT_VALID);
  563. }
  564. }
  565. }
  566. }
  567. static int mx2_start_streaming(struct vb2_queue *q, unsigned int count)
  568. {
  569. struct soc_camera_device *icd = soc_camera_from_vb2q(q);
  570. struct soc_camera_host *ici =
  571. to_soc_camera_host(icd->parent);
  572. struct mx2_camera_dev *pcdev = ici->priv;
  573. struct mx2_fmt_cfg *prp = pcdev->emma_prp;
  574. struct vb2_buffer *vb;
  575. struct mx2_buffer *buf;
  576. unsigned long phys;
  577. int bytesperline;
  578. unsigned long flags;
  579. if (count < 2)
  580. return -EINVAL;
  581. spin_lock_irqsave(&pcdev->lock, flags);
  582. buf = list_first_entry(&pcdev->capture, struct mx2_buffer,
  583. internal.queue);
  584. buf->internal.bufnum = 0;
  585. vb = &buf->vb;
  586. buf->state = MX2_STATE_ACTIVE;
  587. phys = vb2_dma_contig_plane_dma_addr(vb, 0);
  588. mx27_update_emma_buf(pcdev, phys, buf->internal.bufnum);
  589. list_move_tail(pcdev->capture.next, &pcdev->active_bufs);
  590. buf = list_first_entry(&pcdev->capture, struct mx2_buffer,
  591. internal.queue);
  592. buf->internal.bufnum = 1;
  593. vb = &buf->vb;
  594. buf->state = MX2_STATE_ACTIVE;
  595. phys = vb2_dma_contig_plane_dma_addr(vb, 0);
  596. mx27_update_emma_buf(pcdev, phys, buf->internal.bufnum);
  597. list_move_tail(pcdev->capture.next, &pcdev->active_bufs);
  598. bytesperline = soc_mbus_bytes_per_line(icd->user_width,
  599. icd->current_fmt->host_fmt);
  600. if (bytesperline < 0) {
  601. spin_unlock_irqrestore(&pcdev->lock, flags);
  602. return bytesperline;
  603. }
  604. /*
  605. * I didn't manage to properly enable/disable the prp
  606. * on a per frame basis during running transfers,
  607. * thus we allocate a buffer here and use it to
  608. * discard frames when no buffer is available.
  609. * Feel free to work on this ;)
  610. */
  611. pcdev->discard_size = icd->user_height * bytesperline;
  612. pcdev->discard_buffer = dma_alloc_coherent(ici->v4l2_dev.dev,
  613. pcdev->discard_size,
  614. &pcdev->discard_buffer_dma, GFP_ATOMIC);
  615. if (!pcdev->discard_buffer) {
  616. spin_unlock_irqrestore(&pcdev->lock, flags);
  617. return -ENOMEM;
  618. }
  619. pcdev->buf_discard[0].discard = true;
  620. list_add_tail(&pcdev->buf_discard[0].queue,
  621. &pcdev->discard);
  622. pcdev->buf_discard[1].discard = true;
  623. list_add_tail(&pcdev->buf_discard[1].queue,
  624. &pcdev->discard);
  625. mx2_prp_resize_commit(pcdev);
  626. mx27_camera_emma_buf_init(icd, bytesperline);
  627. if (prp->cfg.channel == 1) {
  628. writel(PRP_CNTL_CH1EN |
  629. PRP_CNTL_CSIEN |
  630. prp->cfg.in_fmt |
  631. prp->cfg.out_fmt |
  632. PRP_CNTL_CH1_LEN |
  633. PRP_CNTL_CH1BYP |
  634. PRP_CNTL_CH1_TSKIP(0) |
  635. PRP_CNTL_IN_TSKIP(0),
  636. pcdev->base_emma + PRP_CNTL);
  637. } else {
  638. writel(PRP_CNTL_CH2EN |
  639. PRP_CNTL_CSIEN |
  640. prp->cfg.in_fmt |
  641. prp->cfg.out_fmt |
  642. PRP_CNTL_CH2_LEN |
  643. PRP_CNTL_CH2_TSKIP(0) |
  644. PRP_CNTL_IN_TSKIP(0),
  645. pcdev->base_emma + PRP_CNTL);
  646. }
  647. spin_unlock_irqrestore(&pcdev->lock, flags);
  648. return 0;
  649. }
  650. static int mx2_stop_streaming(struct vb2_queue *q)
  651. {
  652. struct soc_camera_device *icd = soc_camera_from_vb2q(q);
  653. struct soc_camera_host *ici =
  654. to_soc_camera_host(icd->parent);
  655. struct mx2_camera_dev *pcdev = ici->priv;
  656. struct mx2_fmt_cfg *prp = pcdev->emma_prp;
  657. unsigned long flags;
  658. void *b;
  659. u32 cntl;
  660. spin_lock_irqsave(&pcdev->lock, flags);
  661. cntl = readl(pcdev->base_emma + PRP_CNTL);
  662. if (prp->cfg.channel == 1) {
  663. writel(cntl & ~PRP_CNTL_CH1EN,
  664. pcdev->base_emma + PRP_CNTL);
  665. } else {
  666. writel(cntl & ~PRP_CNTL_CH2EN,
  667. pcdev->base_emma + PRP_CNTL);
  668. }
  669. INIT_LIST_HEAD(&pcdev->capture);
  670. INIT_LIST_HEAD(&pcdev->active_bufs);
  671. INIT_LIST_HEAD(&pcdev->discard);
  672. b = pcdev->discard_buffer;
  673. pcdev->discard_buffer = NULL;
  674. spin_unlock_irqrestore(&pcdev->lock, flags);
  675. dma_free_coherent(ici->v4l2_dev.dev,
  676. pcdev->discard_size, b, pcdev->discard_buffer_dma);
  677. return 0;
  678. }
  679. static struct vb2_ops mx2_videobuf_ops = {
  680. .queue_setup = mx2_videobuf_setup,
  681. .buf_prepare = mx2_videobuf_prepare,
  682. .buf_queue = mx2_videobuf_queue,
  683. .start_streaming = mx2_start_streaming,
  684. .stop_streaming = mx2_stop_streaming,
  685. };
  686. static int mx2_camera_init_videobuf(struct vb2_queue *q,
  687. struct soc_camera_device *icd)
  688. {
  689. q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  690. q->io_modes = VB2_MMAP | VB2_USERPTR;
  691. q->drv_priv = icd;
  692. q->ops = &mx2_videobuf_ops;
  693. q->mem_ops = &vb2_dma_contig_memops;
  694. q->buf_struct_size = sizeof(struct mx2_buffer);
  695. return vb2_queue_init(q);
  696. }
  697. #define MX2_BUS_FLAGS (V4L2_MBUS_MASTER | \
  698. V4L2_MBUS_VSYNC_ACTIVE_HIGH | \
  699. V4L2_MBUS_VSYNC_ACTIVE_LOW | \
  700. V4L2_MBUS_HSYNC_ACTIVE_HIGH | \
  701. V4L2_MBUS_HSYNC_ACTIVE_LOW | \
  702. V4L2_MBUS_PCLK_SAMPLE_RISING | \
  703. V4L2_MBUS_PCLK_SAMPLE_FALLING | \
  704. V4L2_MBUS_DATA_ACTIVE_HIGH | \
  705. V4L2_MBUS_DATA_ACTIVE_LOW)
  706. static int mx27_camera_emma_prp_reset(struct mx2_camera_dev *pcdev)
  707. {
  708. u32 cntl;
  709. int count = 0;
  710. cntl = readl(pcdev->base_emma + PRP_CNTL);
  711. writel(PRP_CNTL_SWRST, pcdev->base_emma + PRP_CNTL);
  712. while (count++ < 100) {
  713. if (!(readl(pcdev->base_emma + PRP_CNTL) & PRP_CNTL_SWRST))
  714. return 0;
  715. barrier();
  716. udelay(1);
  717. }
  718. return -ETIMEDOUT;
  719. }
  720. static int mx2_camera_set_bus_param(struct soc_camera_device *icd)
  721. {
  722. struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
  723. struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
  724. struct mx2_camera_dev *pcdev = ici->priv;
  725. struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,};
  726. unsigned long common_flags;
  727. int ret;
  728. int bytesperline;
  729. u32 csicr1 = pcdev->csicr1;
  730. ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg);
  731. if (!ret) {
  732. common_flags = soc_mbus_config_compatible(&cfg, MX2_BUS_FLAGS);
  733. if (!common_flags) {
  734. dev_warn(icd->parent,
  735. "Flags incompatible: camera 0x%x, host 0x%x\n",
  736. cfg.flags, MX2_BUS_FLAGS);
  737. return -EINVAL;
  738. }
  739. } else if (ret != -ENOIOCTLCMD) {
  740. return ret;
  741. } else {
  742. common_flags = MX2_BUS_FLAGS;
  743. }
  744. if ((common_flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) &&
  745. (common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)) {
  746. if (pcdev->platform_flags & MX2_CAMERA_HSYNC_HIGH)
  747. common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_LOW;
  748. else
  749. common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_HIGH;
  750. }
  751. if ((common_flags & V4L2_MBUS_PCLK_SAMPLE_RISING) &&
  752. (common_flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)) {
  753. if (pcdev->platform_flags & MX2_CAMERA_PCLK_SAMPLE_RISING)
  754. common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_FALLING;
  755. else
  756. common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_RISING;
  757. }
  758. cfg.flags = common_flags;
  759. ret = v4l2_subdev_call(sd, video, s_mbus_config, &cfg);
  760. if (ret < 0 && ret != -ENOIOCTLCMD) {
  761. dev_dbg(icd->parent, "camera s_mbus_config(0x%lx) returned %d\n",
  762. common_flags, ret);
  763. return ret;
  764. }
  765. csicr1 = (csicr1 & ~CSICR1_FMT_MASK) | pcdev->emma_prp->cfg.csicr1;
  766. if (common_flags & V4L2_MBUS_PCLK_SAMPLE_RISING)
  767. csicr1 |= CSICR1_REDGE;
  768. if (common_flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH)
  769. csicr1 |= CSICR1_SOF_POL;
  770. if (common_flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH)
  771. csicr1 |= CSICR1_HSYNC_POL;
  772. if (pcdev->platform_flags & MX2_CAMERA_EXT_VSYNC)
  773. csicr1 |= CSICR1_EXT_VSYNC;
  774. if (pcdev->platform_flags & MX2_CAMERA_CCIR)
  775. csicr1 |= CSICR1_CCIR_EN;
  776. if (pcdev->platform_flags & MX2_CAMERA_CCIR_INTERLACE)
  777. csicr1 |= CSICR1_CCIR_MODE;
  778. if (pcdev->platform_flags & MX2_CAMERA_GATED_CLOCK)
  779. csicr1 |= CSICR1_GCLK_MODE;
  780. if (pcdev->platform_flags & MX2_CAMERA_INV_DATA)
  781. csicr1 |= CSICR1_INV_DATA;
  782. pcdev->csicr1 = csicr1;
  783. bytesperline = soc_mbus_bytes_per_line(icd->user_width,
  784. icd->current_fmt->host_fmt);
  785. if (bytesperline < 0)
  786. return bytesperline;
  787. ret = mx27_camera_emma_prp_reset(pcdev);
  788. if (ret)
  789. return ret;
  790. writel(pcdev->csicr1, pcdev->base_csi + CSICR1);
  791. return 0;
  792. }
  793. static int mx2_camera_set_crop(struct soc_camera_device *icd,
  794. const struct v4l2_crop *a)
  795. {
  796. struct v4l2_crop a_writable = *a;
  797. struct v4l2_rect *rect = &a_writable.c;
  798. struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
  799. struct v4l2_mbus_framefmt mf;
  800. int ret;
  801. soc_camera_limit_side(&rect->left, &rect->width, 0, 2, 4096);
  802. soc_camera_limit_side(&rect->top, &rect->height, 0, 2, 4096);
  803. ret = v4l2_subdev_call(sd, video, s_crop, a);
  804. if (ret < 0)
  805. return ret;
  806. /* The capture device might have changed its output */
  807. ret = v4l2_subdev_call(sd, video, g_mbus_fmt, &mf);
  808. if (ret < 0)
  809. return ret;
  810. dev_dbg(icd->parent, "Sensor cropped %dx%d\n",
  811. mf.width, mf.height);
  812. icd->user_width = mf.width;
  813. icd->user_height = mf.height;
  814. return ret;
  815. }
  816. static int mx2_camera_get_formats(struct soc_camera_device *icd,
  817. unsigned int idx,
  818. struct soc_camera_format_xlate *xlate)
  819. {
  820. struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
  821. const struct soc_mbus_pixelfmt *fmt;
  822. struct device *dev = icd->parent;
  823. enum v4l2_mbus_pixelcode code;
  824. int ret, formats = 0;
  825. ret = v4l2_subdev_call(sd, video, enum_mbus_fmt, idx, &code);
  826. if (ret < 0)
  827. /* no more formats */
  828. return 0;
  829. fmt = soc_mbus_get_fmtdesc(code);
  830. if (!fmt) {
  831. dev_err(dev, "Invalid format code #%u: %d\n", idx, code);
  832. return 0;
  833. }
  834. if (code == V4L2_MBUS_FMT_YUYV8_2X8 ||
  835. code == V4L2_MBUS_FMT_UYVY8_2X8) {
  836. formats++;
  837. if (xlate) {
  838. /*
  839. * CH2 can output YUV420 which is a standard format in
  840. * soc_mediabus.c
  841. */
  842. xlate->host_fmt =
  843. soc_mbus_get_fmtdesc(V4L2_MBUS_FMT_YUYV8_1_5X8);
  844. xlate->code = code;
  845. dev_dbg(dev, "Providing host format %s for sensor code %d\n",
  846. xlate->host_fmt->name, code);
  847. xlate++;
  848. }
  849. }
  850. if (code == V4L2_MBUS_FMT_UYVY8_2X8) {
  851. formats++;
  852. if (xlate) {
  853. xlate->host_fmt =
  854. soc_mbus_get_fmtdesc(V4L2_MBUS_FMT_YUYV8_2X8);
  855. xlate->code = code;
  856. dev_dbg(dev, "Providing host format %s for sensor code %d\n",
  857. xlate->host_fmt->name, code);
  858. xlate++;
  859. }
  860. }
  861. /* Generic pass-trough */
  862. formats++;
  863. if (xlate) {
  864. xlate->host_fmt = fmt;
  865. xlate->code = code;
  866. xlate++;
  867. }
  868. return formats;
  869. }
  870. static int mx2_emmaprp_resize(struct mx2_camera_dev *pcdev,
  871. struct v4l2_mbus_framefmt *mf_in,
  872. struct v4l2_pix_format *pix_out, bool apply)
  873. {
  874. int num, den;
  875. unsigned long m;
  876. int i, dir;
  877. for (dir = RESIZE_DIR_H; dir <= RESIZE_DIR_V; dir++) {
  878. struct emma_prp_resize tmprsz;
  879. unsigned char *s = tmprsz.s;
  880. int len = 0;
  881. int in, out;
  882. if (dir == RESIZE_DIR_H) {
  883. in = mf_in->width;
  884. out = pix_out->width;
  885. } else {
  886. in = mf_in->height;
  887. out = pix_out->height;
  888. }
  889. if (in < out)
  890. return -EINVAL;
  891. else if (in == out)
  892. continue;
  893. /* Calculate ratio */
  894. m = gcd(in, out);
  895. num = in / m;
  896. den = out / m;
  897. if (num > RESIZE_NUM_MAX)
  898. return -EINVAL;
  899. if ((num >= 2 * den) && (den == 1) &&
  900. (num < 9) && (!(num & 0x01))) {
  901. int sum = 0;
  902. int j;
  903. /* Average scaling for >= 2:1 ratios */
  904. /* Support can be added for num >=9 and odd values */
  905. tmprsz.algo = RESIZE_ALGO_AVERAGING;
  906. len = num;
  907. for (i = 0; i < (len / 2); i++)
  908. s[i] = 8;
  909. do {
  910. for (i = 0; i < (len / 2); i++) {
  911. s[i] = s[i] >> 1;
  912. sum = 0;
  913. for (j = 0; j < (len / 2); j++)
  914. sum += s[j];
  915. if (sum == 4)
  916. break;
  917. }
  918. } while (sum != 4);
  919. for (i = (len / 2); i < len; i++)
  920. s[i] = s[len - i - 1];
  921. s[len - 1] |= SZ_COEF;
  922. } else {
  923. /* bilinear scaling for < 2:1 ratios */
  924. int v; /* overflow counter */
  925. int coeff, nxt; /* table output */
  926. int in_pos_inc = 2 * den;
  927. int out_pos = num;
  928. int out_pos_inc = 2 * num;
  929. int init_carry = num - den;
  930. int carry = init_carry;
  931. tmprsz.algo = RESIZE_ALGO_BILINEAR;
  932. v = den + in_pos_inc;
  933. do {
  934. coeff = v - out_pos;
  935. out_pos += out_pos_inc;
  936. carry += out_pos_inc;
  937. for (nxt = 0; v < out_pos; nxt++) {
  938. v += in_pos_inc;
  939. carry -= in_pos_inc;
  940. }
  941. if (len > RESIZE_NUM_MAX)
  942. return -EINVAL;
  943. coeff = ((coeff << BC_COEF) +
  944. (in_pos_inc >> 1)) / in_pos_inc;
  945. if (coeff >= (SZ_COEF - 1))
  946. coeff--;
  947. coeff |= SZ_COEF;
  948. s[len] = (unsigned char)coeff;
  949. len++;
  950. for (i = 1; i < nxt; i++) {
  951. if (len >= RESIZE_NUM_MAX)
  952. return -EINVAL;
  953. s[len] = 0;
  954. len++;
  955. }
  956. } while (carry != init_carry);
  957. }
  958. tmprsz.len = len;
  959. if (dir == RESIZE_DIR_H)
  960. mf_in->width = pix_out->width;
  961. else
  962. mf_in->height = pix_out->height;
  963. if (apply)
  964. memcpy(&pcdev->resizing[dir], &tmprsz, sizeof(tmprsz));
  965. }
  966. return 0;
  967. }
  968. static int mx2_camera_set_fmt(struct soc_camera_device *icd,
  969. struct v4l2_format *f)
  970. {
  971. struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
  972. struct mx2_camera_dev *pcdev = ici->priv;
  973. struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
  974. const struct soc_camera_format_xlate *xlate;
  975. struct v4l2_pix_format *pix = &f->fmt.pix;
  976. struct v4l2_mbus_framefmt mf;
  977. int ret;
  978. dev_dbg(icd->parent, "%s: requested params: width = %d, height = %d\n",
  979. __func__, pix->width, pix->height);
  980. xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat);
  981. if (!xlate) {
  982. dev_warn(icd->parent, "Format %x not found\n",
  983. pix->pixelformat);
  984. return -EINVAL;
  985. }
  986. mf.width = pix->width;
  987. mf.height = pix->height;
  988. mf.field = pix->field;
  989. mf.colorspace = pix->colorspace;
  990. mf.code = xlate->code;
  991. ret = v4l2_subdev_call(sd, video, s_mbus_fmt, &mf);
  992. if (ret < 0 && ret != -ENOIOCTLCMD)
  993. return ret;
  994. /* Store width and height returned by the sensor for resizing */
  995. pcdev->s_width = mf.width;
  996. pcdev->s_height = mf.height;
  997. dev_dbg(icd->parent, "%s: sensor params: width = %d, height = %d\n",
  998. __func__, pcdev->s_width, pcdev->s_height);
  999. pcdev->emma_prp = mx27_emma_prp_get_format(xlate->code,
  1000. xlate->host_fmt->fourcc);
  1001. memset(pcdev->resizing, 0, sizeof(pcdev->resizing));
  1002. if ((mf.width != pix->width || mf.height != pix->height) &&
  1003. pcdev->emma_prp->cfg.in_fmt == PRP_CNTL_DATA_IN_YUV422) {
  1004. if (mx2_emmaprp_resize(pcdev, &mf, pix, true) < 0)
  1005. dev_dbg(icd->parent, "%s: can't resize\n", __func__);
  1006. }
  1007. if (mf.code != xlate->code)
  1008. return -EINVAL;
  1009. pix->width = mf.width;
  1010. pix->height = mf.height;
  1011. pix->field = mf.field;
  1012. pix->colorspace = mf.colorspace;
  1013. icd->current_fmt = xlate;
  1014. dev_dbg(icd->parent, "%s: returned params: width = %d, height = %d\n",
  1015. __func__, pix->width, pix->height);
  1016. return 0;
  1017. }
  1018. static int mx2_camera_try_fmt(struct soc_camera_device *icd,
  1019. struct v4l2_format *f)
  1020. {
  1021. struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
  1022. const struct soc_camera_format_xlate *xlate;
  1023. struct v4l2_pix_format *pix = &f->fmt.pix;
  1024. struct v4l2_mbus_framefmt mf;
  1025. __u32 pixfmt = pix->pixelformat;
  1026. struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
  1027. struct mx2_camera_dev *pcdev = ici->priv;
  1028. struct mx2_fmt_cfg *emma_prp;
  1029. int ret;
  1030. dev_dbg(icd->parent, "%s: requested params: width = %d, height = %d\n",
  1031. __func__, pix->width, pix->height);
  1032. xlate = soc_camera_xlate_by_fourcc(icd, pixfmt);
  1033. if (pixfmt && !xlate) {
  1034. dev_warn(icd->parent, "Format %x not found\n", pixfmt);
  1035. return -EINVAL;
  1036. }
  1037. /*
  1038. * limit to MX27 hardware capabilities: width must be a multiple of 8 as
  1039. * requested by the CSI. (Table 39-2 in the i.MX27 Reference Manual).
  1040. */
  1041. pix->width &= ~0x7;
  1042. /* limit to sensor capabilities */
  1043. mf.width = pix->width;
  1044. mf.height = pix->height;
  1045. mf.field = pix->field;
  1046. mf.colorspace = pix->colorspace;
  1047. mf.code = xlate->code;
  1048. ret = v4l2_subdev_call(sd, video, try_mbus_fmt, &mf);
  1049. if (ret < 0)
  1050. return ret;
  1051. dev_dbg(icd->parent, "%s: sensor params: width = %d, height = %d\n",
  1052. __func__, pcdev->s_width, pcdev->s_height);
  1053. /* If the sensor does not support image size try PrP resizing */
  1054. emma_prp = mx27_emma_prp_get_format(xlate->code,
  1055. xlate->host_fmt->fourcc);
  1056. if ((mf.width != pix->width || mf.height != pix->height) &&
  1057. emma_prp->cfg.in_fmt == PRP_CNTL_DATA_IN_YUV422) {
  1058. if (mx2_emmaprp_resize(pcdev, &mf, pix, false) < 0)
  1059. dev_dbg(icd->parent, "%s: can't resize\n", __func__);
  1060. }
  1061. if (mf.field == V4L2_FIELD_ANY)
  1062. mf.field = V4L2_FIELD_NONE;
  1063. /*
  1064. * Driver supports interlaced images provided they have
  1065. * both fields so that they can be processed as if they
  1066. * were progressive.
  1067. */
  1068. if (mf.field != V4L2_FIELD_NONE && !V4L2_FIELD_HAS_BOTH(mf.field)) {
  1069. dev_err(icd->parent, "Field type %d unsupported.\n",
  1070. mf.field);
  1071. return -EINVAL;
  1072. }
  1073. pix->width = mf.width;
  1074. pix->height = mf.height;
  1075. pix->field = mf.field;
  1076. pix->colorspace = mf.colorspace;
  1077. dev_dbg(icd->parent, "%s: returned params: width = %d, height = %d\n",
  1078. __func__, pix->width, pix->height);
  1079. return 0;
  1080. }
  1081. static int mx2_camera_querycap(struct soc_camera_host *ici,
  1082. struct v4l2_capability *cap)
  1083. {
  1084. /* cap->name is set by the friendly caller:-> */
  1085. strlcpy(cap->card, MX2_CAM_DRIVER_DESCRIPTION, sizeof(cap->card));
  1086. cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
  1087. return 0;
  1088. }
  1089. static unsigned int mx2_camera_poll(struct file *file, poll_table *pt)
  1090. {
  1091. struct soc_camera_device *icd = file->private_data;
  1092. return vb2_poll(&icd->vb2_vidq, file, pt);
  1093. }
  1094. static struct soc_camera_host_ops mx2_soc_camera_host_ops = {
  1095. .owner = THIS_MODULE,
  1096. .add = mx2_camera_add_device,
  1097. .remove = mx2_camera_remove_device,
  1098. .set_fmt = mx2_camera_set_fmt,
  1099. .set_crop = mx2_camera_set_crop,
  1100. .get_formats = mx2_camera_get_formats,
  1101. .try_fmt = mx2_camera_try_fmt,
  1102. .init_videobuf2 = mx2_camera_init_videobuf,
  1103. .poll = mx2_camera_poll,
  1104. .querycap = mx2_camera_querycap,
  1105. .set_bus_param = mx2_camera_set_bus_param,
  1106. };
  1107. static void mx27_camera_frame_done_emma(struct mx2_camera_dev *pcdev,
  1108. int bufnum, bool err)
  1109. {
  1110. #ifdef DEBUG
  1111. struct mx2_fmt_cfg *prp = pcdev->emma_prp;
  1112. #endif
  1113. struct mx2_buf_internal *ibuf;
  1114. struct mx2_buffer *buf;
  1115. struct vb2_buffer *vb;
  1116. unsigned long phys;
  1117. ibuf = list_first_entry(&pcdev->active_bufs, struct mx2_buf_internal,
  1118. queue);
  1119. BUG_ON(ibuf->bufnum != bufnum);
  1120. if (ibuf->discard) {
  1121. /*
  1122. * Discard buffer must not be returned to user space.
  1123. * Just return it to the discard queue.
  1124. */
  1125. list_move_tail(pcdev->active_bufs.next, &pcdev->discard);
  1126. } else {
  1127. buf = mx2_ibuf_to_buf(ibuf);
  1128. vb = &buf->vb;
  1129. #ifdef DEBUG
  1130. phys = vb2_dma_contig_plane_dma_addr(vb, 0);
  1131. if (prp->cfg.channel == 1) {
  1132. if (readl(pcdev->base_emma + PRP_DEST_RGB1_PTR +
  1133. 4 * bufnum) != phys) {
  1134. dev_err(pcdev->dev, "%lx != %x\n", phys,
  1135. readl(pcdev->base_emma +
  1136. PRP_DEST_RGB1_PTR + 4 * bufnum));
  1137. }
  1138. } else {
  1139. if (readl(pcdev->base_emma + PRP_DEST_Y_PTR -
  1140. 0x14 * bufnum) != phys) {
  1141. dev_err(pcdev->dev, "%lx != %x\n", phys,
  1142. readl(pcdev->base_emma +
  1143. PRP_DEST_Y_PTR - 0x14 * bufnum));
  1144. }
  1145. }
  1146. #endif
  1147. dev_dbg(pcdev->dev, "%s (vb=0x%p) 0x%p %lu\n", __func__, vb,
  1148. vb2_plane_vaddr(vb, 0),
  1149. vb2_get_plane_payload(vb, 0));
  1150. list_del_init(&buf->internal.queue);
  1151. v4l2_get_timestamp(&vb->v4l2_buf.timestamp);
  1152. vb->v4l2_buf.sequence = pcdev->frame_count;
  1153. if (err)
  1154. vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
  1155. else
  1156. vb2_buffer_done(vb, VB2_BUF_STATE_DONE);
  1157. }
  1158. pcdev->frame_count++;
  1159. if (list_empty(&pcdev->capture)) {
  1160. if (list_empty(&pcdev->discard)) {
  1161. dev_warn(pcdev->dev, "%s: trying to access empty discard list\n",
  1162. __func__);
  1163. return;
  1164. }
  1165. ibuf = list_first_entry(&pcdev->discard,
  1166. struct mx2_buf_internal, queue);
  1167. ibuf->bufnum = bufnum;
  1168. list_move_tail(pcdev->discard.next, &pcdev->active_bufs);
  1169. mx27_update_emma_buf(pcdev, pcdev->discard_buffer_dma, bufnum);
  1170. return;
  1171. }
  1172. buf = list_first_entry(&pcdev->capture, struct mx2_buffer,
  1173. internal.queue);
  1174. buf->internal.bufnum = bufnum;
  1175. list_move_tail(pcdev->capture.next, &pcdev->active_bufs);
  1176. vb = &buf->vb;
  1177. buf->state = MX2_STATE_ACTIVE;
  1178. phys = vb2_dma_contig_plane_dma_addr(vb, 0);
  1179. mx27_update_emma_buf(pcdev, phys, bufnum);
  1180. }
  1181. static irqreturn_t mx27_camera_emma_irq(int irq_emma, void *data)
  1182. {
  1183. struct mx2_camera_dev *pcdev = data;
  1184. unsigned int status = readl(pcdev->base_emma + PRP_INTRSTATUS);
  1185. struct mx2_buf_internal *ibuf;
  1186. spin_lock(&pcdev->lock);
  1187. if (list_empty(&pcdev->active_bufs)) {
  1188. dev_warn(pcdev->dev, "%s: called while active list is empty\n",
  1189. __func__);
  1190. if (!status) {
  1191. spin_unlock(&pcdev->lock);
  1192. return IRQ_NONE;
  1193. }
  1194. }
  1195. if (status & (1 << 7)) { /* overflow */
  1196. u32 cntl = readl(pcdev->base_emma + PRP_CNTL);
  1197. writel(cntl & ~(PRP_CNTL_CH1EN | PRP_CNTL_CH2EN),
  1198. pcdev->base_emma + PRP_CNTL);
  1199. writel(cntl, pcdev->base_emma + PRP_CNTL);
  1200. ibuf = list_first_entry(&pcdev->active_bufs,
  1201. struct mx2_buf_internal, queue);
  1202. mx27_camera_frame_done_emma(pcdev,
  1203. ibuf->bufnum, true);
  1204. status &= ~(1 << 7);
  1205. } else if (((status & (3 << 5)) == (3 << 5)) ||
  1206. ((status & (3 << 3)) == (3 << 3))) {
  1207. /*
  1208. * Both buffers have triggered, process the one we're expecting
  1209. * to first
  1210. */
  1211. ibuf = list_first_entry(&pcdev->active_bufs,
  1212. struct mx2_buf_internal, queue);
  1213. mx27_camera_frame_done_emma(pcdev, ibuf->bufnum, false);
  1214. status &= ~(1 << (6 - ibuf->bufnum)); /* mark processed */
  1215. } else if ((status & (1 << 6)) || (status & (1 << 4))) {
  1216. mx27_camera_frame_done_emma(pcdev, 0, false);
  1217. } else if ((status & (1 << 5)) || (status & (1 << 3))) {
  1218. mx27_camera_frame_done_emma(pcdev, 1, false);
  1219. }
  1220. spin_unlock(&pcdev->lock);
  1221. writel(status, pcdev->base_emma + PRP_INTRSTATUS);
  1222. return IRQ_HANDLED;
  1223. }
  1224. static int __devinit mx27_camera_emma_init(struct platform_device *pdev)
  1225. {
  1226. struct mx2_camera_dev *pcdev = platform_get_drvdata(pdev);
  1227. struct resource *res_emma;
  1228. int irq_emma;
  1229. int err = 0;
  1230. res_emma = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  1231. irq_emma = platform_get_irq(pdev, 1);
  1232. if (!res_emma || !irq_emma) {
  1233. dev_err(pcdev->dev, "no EMMA resources\n");
  1234. err = -ENODEV;
  1235. goto out;
  1236. }
  1237. pcdev->base_emma = devm_request_and_ioremap(pcdev->dev, res_emma);
  1238. if (!pcdev->base_emma) {
  1239. err = -EADDRNOTAVAIL;
  1240. goto out;
  1241. }
  1242. err = devm_request_irq(pcdev->dev, irq_emma, mx27_camera_emma_irq, 0,
  1243. MX2_CAM_DRV_NAME, pcdev);
  1244. if (err) {
  1245. dev_err(pcdev->dev, "Camera EMMA interrupt register failed \n");
  1246. goto out;
  1247. }
  1248. pcdev->clk_emma_ipg = devm_clk_get(pcdev->dev, "emma-ipg");
  1249. if (IS_ERR(pcdev->clk_emma_ipg)) {
  1250. err = PTR_ERR(pcdev->clk_emma_ipg);
  1251. goto out;
  1252. }
  1253. clk_prepare_enable(pcdev->clk_emma_ipg);
  1254. pcdev->clk_emma_ahb = devm_clk_get(pcdev->dev, "emma-ahb");
  1255. if (IS_ERR(pcdev->clk_emma_ahb)) {
  1256. err = PTR_ERR(pcdev->clk_emma_ahb);
  1257. goto exit_clk_emma_ipg;
  1258. }
  1259. clk_prepare_enable(pcdev->clk_emma_ahb);
  1260. err = mx27_camera_emma_prp_reset(pcdev);
  1261. if (err)
  1262. goto exit_clk_emma_ahb;
  1263. return err;
  1264. exit_clk_emma_ahb:
  1265. clk_disable_unprepare(pcdev->clk_emma_ahb);
  1266. exit_clk_emma_ipg:
  1267. clk_disable_unprepare(pcdev->clk_emma_ipg);
  1268. out:
  1269. return err;
  1270. }
  1271. static int __devinit mx2_camera_probe(struct platform_device *pdev)
  1272. {
  1273. struct mx2_camera_dev *pcdev;
  1274. struct resource *res_csi;
  1275. int irq_csi;
  1276. int err = 0;
  1277. dev_dbg(&pdev->dev, "initialising\n");
  1278. res_csi = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1279. irq_csi = platform_get_irq(pdev, 0);
  1280. if (res_csi == NULL || irq_csi < 0) {
  1281. dev_err(&pdev->dev, "Missing platform resources data\n");
  1282. err = -ENODEV;
  1283. goto exit;
  1284. }
  1285. pcdev = devm_kzalloc(&pdev->dev, sizeof(*pcdev), GFP_KERNEL);
  1286. if (!pcdev) {
  1287. dev_err(&pdev->dev, "Could not allocate pcdev\n");
  1288. err = -ENOMEM;
  1289. goto exit;
  1290. }
  1291. pcdev->clk_csi_ahb = devm_clk_get(&pdev->dev, "ahb");
  1292. if (IS_ERR(pcdev->clk_csi_ahb)) {
  1293. dev_err(&pdev->dev, "Could not get csi ahb clock\n");
  1294. err = PTR_ERR(pcdev->clk_csi_ahb);
  1295. goto exit;
  1296. }
  1297. pcdev->clk_csi_per = devm_clk_get(&pdev->dev, "per");
  1298. if (IS_ERR(pcdev->clk_csi_per)) {
  1299. dev_err(&pdev->dev, "Could not get csi per clock\n");
  1300. err = PTR_ERR(pcdev->clk_csi_per);
  1301. goto exit;
  1302. }
  1303. pcdev->pdata = pdev->dev.platform_data;
  1304. if (pcdev->pdata) {
  1305. long rate;
  1306. pcdev->platform_flags = pcdev->pdata->flags;
  1307. rate = clk_round_rate(pcdev->clk_csi_per,
  1308. pcdev->pdata->clk * 2);
  1309. if (rate <= 0) {
  1310. err = -ENODEV;
  1311. goto exit;
  1312. }
  1313. err = clk_set_rate(pcdev->clk_csi_per, rate);
  1314. if (err < 0)
  1315. goto exit;
  1316. }
  1317. INIT_LIST_HEAD(&pcdev->capture);
  1318. INIT_LIST_HEAD(&pcdev->active_bufs);
  1319. INIT_LIST_HEAD(&pcdev->discard);
  1320. spin_lock_init(&pcdev->lock);
  1321. pcdev->base_csi = devm_request_and_ioremap(&pdev->dev, res_csi);
  1322. if (!pcdev->base_csi) {
  1323. err = -EADDRNOTAVAIL;
  1324. goto exit;
  1325. }
  1326. pcdev->dev = &pdev->dev;
  1327. platform_set_drvdata(pdev, pcdev);
  1328. err = mx27_camera_emma_init(pdev);
  1329. if (err)
  1330. goto exit;
  1331. /*
  1332. * We're done with drvdata here. Clear the pointer so that
  1333. * v4l2 core can start using drvdata on its purpose.
  1334. */
  1335. platform_set_drvdata(pdev, NULL);
  1336. pcdev->soc_host.drv_name = MX2_CAM_DRV_NAME,
  1337. pcdev->soc_host.ops = &mx2_soc_camera_host_ops,
  1338. pcdev->soc_host.priv = pcdev;
  1339. pcdev->soc_host.v4l2_dev.dev = &pdev->dev;
  1340. pcdev->soc_host.nr = pdev->id;
  1341. pcdev->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev);
  1342. if (IS_ERR(pcdev->alloc_ctx)) {
  1343. err = PTR_ERR(pcdev->alloc_ctx);
  1344. goto eallocctx;
  1345. }
  1346. err = soc_camera_host_register(&pcdev->soc_host);
  1347. if (err)
  1348. goto exit_free_emma;
  1349. dev_info(&pdev->dev, "MX2 Camera (CSI) driver probed, clock frequency: %ld\n",
  1350. clk_get_rate(pcdev->clk_csi_per));
  1351. return 0;
  1352. exit_free_emma:
  1353. vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx);
  1354. eallocctx:
  1355. clk_disable_unprepare(pcdev->clk_emma_ipg);
  1356. clk_disable_unprepare(pcdev->clk_emma_ahb);
  1357. exit:
  1358. return err;
  1359. }
  1360. static int __devexit mx2_camera_remove(struct platform_device *pdev)
  1361. {
  1362. struct soc_camera_host *soc_host = to_soc_camera_host(&pdev->dev);
  1363. struct mx2_camera_dev *pcdev = container_of(soc_host,
  1364. struct mx2_camera_dev, soc_host);
  1365. soc_camera_host_unregister(&pcdev->soc_host);
  1366. vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx);
  1367. clk_disable_unprepare(pcdev->clk_emma_ipg);
  1368. clk_disable_unprepare(pcdev->clk_emma_ahb);
  1369. dev_info(&pdev->dev, "MX2 Camera driver unloaded\n");
  1370. return 0;
  1371. }
  1372. static struct platform_driver mx2_camera_driver = {
  1373. .driver = {
  1374. .name = MX2_CAM_DRV_NAME,
  1375. },
  1376. .id_table = mx2_camera_devtype,
  1377. .remove = __devexit_p(mx2_camera_remove),
  1378. };
  1379. static int __init mx2_camera_init(void)
  1380. {
  1381. return platform_driver_probe(&mx2_camera_driver, &mx2_camera_probe);
  1382. }
  1383. static void __exit mx2_camera_exit(void)
  1384. {
  1385. return platform_driver_unregister(&mx2_camera_driver);
  1386. }
  1387. module_init(mx2_camera_init);
  1388. module_exit(mx2_camera_exit);
  1389. MODULE_DESCRIPTION("i.MX27 SoC Camera Host driver");
  1390. MODULE_AUTHOR("Sascha Hauer <sha@pengutronix.de>");
  1391. MODULE_LICENSE("GPL");
  1392. MODULE_VERSION(MX2_CAM_VERSION);