mx2_camera.c 43 KB

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