mx2_camera.c 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638
  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. 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_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 struct v4l2_format *fmt,
  416. unsigned int *count, unsigned int *num_planes,
  417. unsigned int sizes[], void *alloc_ctxs[])
  418. {
  419. struct soc_camera_device *icd = soc_camera_from_vb2q(vq);
  420. struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
  421. struct mx2_camera_dev *pcdev = ici->priv;
  422. dev_dbg(icd->parent, "count=%d, size=%d\n", *count, sizes[0]);
  423. /* TODO: support for VIDIOC_CREATE_BUFS not ready */
  424. if (fmt != NULL)
  425. return -ENOTTY;
  426. alloc_ctxs[0] = pcdev->alloc_ctx;
  427. sizes[0] = icd->sizeimage;
  428. if (0 == *count)
  429. *count = 32;
  430. if (!*num_planes &&
  431. sizes[0] * *count > MAX_VIDEO_MEM * 1024 * 1024)
  432. *count = (MAX_VIDEO_MEM * 1024 * 1024) / sizes[0];
  433. *num_planes = 1;
  434. return 0;
  435. }
  436. static int mx2_videobuf_prepare(struct vb2_buffer *vb)
  437. {
  438. struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue);
  439. int ret = 0;
  440. dev_dbg(icd->parent, "%s (vb=0x%p) 0x%p %lu\n", __func__,
  441. vb, vb2_plane_vaddr(vb, 0), vb2_get_plane_payload(vb, 0));
  442. #ifdef DEBUG
  443. /*
  444. * This can be useful if you want to see if we actually fill
  445. * the buffer with something
  446. */
  447. memset((void *)vb2_plane_vaddr(vb, 0),
  448. 0xaa, vb2_get_plane_payload(vb, 0));
  449. #endif
  450. vb2_set_plane_payload(vb, 0, icd->sizeimage);
  451. if (vb2_plane_vaddr(vb, 0) &&
  452. vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0)) {
  453. ret = -EINVAL;
  454. goto out;
  455. }
  456. return 0;
  457. out:
  458. return ret;
  459. }
  460. static void mx2_videobuf_queue(struct vb2_buffer *vb)
  461. {
  462. struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue);
  463. struct soc_camera_host *ici =
  464. to_soc_camera_host(icd->parent);
  465. struct mx2_camera_dev *pcdev = ici->priv;
  466. struct mx2_buffer *buf = container_of(vb, struct mx2_buffer, vb);
  467. unsigned long flags;
  468. dev_dbg(icd->parent, "%s (vb=0x%p) 0x%p %lu\n", __func__,
  469. vb, vb2_plane_vaddr(vb, 0), vb2_get_plane_payload(vb, 0));
  470. spin_lock_irqsave(&pcdev->lock, flags);
  471. list_add_tail(&buf->internal.queue, &pcdev->capture);
  472. spin_unlock_irqrestore(&pcdev->lock, flags);
  473. }
  474. static void mx27_camera_emma_buf_init(struct soc_camera_device *icd,
  475. int bytesperline)
  476. {
  477. struct soc_camera_host *ici =
  478. to_soc_camera_host(icd->parent);
  479. struct mx2_camera_dev *pcdev = ici->priv;
  480. struct mx2_fmt_cfg *prp = pcdev->emma_prp;
  481. writel((pcdev->s_width << 16) | pcdev->s_height,
  482. pcdev->base_emma + PRP_SRC_FRAME_SIZE);
  483. writel(prp->cfg.src_pixel,
  484. pcdev->base_emma + PRP_SRC_PIXEL_FORMAT_CNTL);
  485. if (prp->cfg.channel == 1) {
  486. writel((icd->user_width << 16) | icd->user_height,
  487. pcdev->base_emma + PRP_CH1_OUT_IMAGE_SIZE);
  488. writel(bytesperline,
  489. pcdev->base_emma + PRP_DEST_CH1_LINE_STRIDE);
  490. writel(prp->cfg.ch1_pixel,
  491. pcdev->base_emma + PRP_CH1_PIXEL_FORMAT_CNTL);
  492. } else { /* channel 2 */
  493. writel((icd->user_width << 16) | icd->user_height,
  494. pcdev->base_emma + PRP_CH2_OUT_IMAGE_SIZE);
  495. }
  496. /* Enable interrupts */
  497. writel(prp->cfg.irq_flags, pcdev->base_emma + PRP_INTR_CNTL);
  498. }
  499. static void mx2_prp_resize_commit(struct mx2_camera_dev *pcdev)
  500. {
  501. int dir;
  502. for (dir = RESIZE_DIR_H; dir <= RESIZE_DIR_V; dir++) {
  503. unsigned char *s = pcdev->resizing[dir].s;
  504. int len = pcdev->resizing[dir].len;
  505. unsigned int coeff[2] = {0, 0};
  506. unsigned int valid = 0;
  507. int i;
  508. if (len == 0)
  509. continue;
  510. for (i = RESIZE_NUM_MAX - 1; i >= 0; i--) {
  511. int j;
  512. j = i > 9 ? 1 : 0;
  513. coeff[j] = (coeff[j] << BC_COEF) |
  514. (s[i] & (SZ_COEF - 1));
  515. if (i == 5 || i == 15)
  516. coeff[j] <<= 1;
  517. valid = (valid << 1) | (s[i] >> BC_COEF);
  518. }
  519. valid |= PRP_RZ_VALID_TBL_LEN(len);
  520. if (pcdev->resizing[dir].algo == RESIZE_ALGO_BILINEAR)
  521. valid |= PRP_RZ_VALID_BILINEAR;
  522. if (pcdev->emma_prp->cfg.channel == 1) {
  523. if (dir == RESIZE_DIR_H) {
  524. writel(coeff[0], pcdev->base_emma +
  525. PRP_CH1_RZ_HORI_COEF1);
  526. writel(coeff[1], pcdev->base_emma +
  527. PRP_CH1_RZ_HORI_COEF2);
  528. writel(valid, pcdev->base_emma +
  529. PRP_CH1_RZ_HORI_VALID);
  530. } else {
  531. writel(coeff[0], pcdev->base_emma +
  532. PRP_CH1_RZ_VERT_COEF1);
  533. writel(coeff[1], pcdev->base_emma +
  534. PRP_CH1_RZ_VERT_COEF2);
  535. writel(valid, pcdev->base_emma +
  536. PRP_CH1_RZ_VERT_VALID);
  537. }
  538. } else {
  539. if (dir == RESIZE_DIR_H) {
  540. writel(coeff[0], pcdev->base_emma +
  541. PRP_CH2_RZ_HORI_COEF1);
  542. writel(coeff[1], pcdev->base_emma +
  543. PRP_CH2_RZ_HORI_COEF2);
  544. writel(valid, pcdev->base_emma +
  545. PRP_CH2_RZ_HORI_VALID);
  546. } else {
  547. writel(coeff[0], pcdev->base_emma +
  548. PRP_CH2_RZ_VERT_COEF1);
  549. writel(coeff[1], pcdev->base_emma +
  550. PRP_CH2_RZ_VERT_COEF2);
  551. writel(valid, pcdev->base_emma +
  552. PRP_CH2_RZ_VERT_VALID);
  553. }
  554. }
  555. }
  556. }
  557. static int mx2_start_streaming(struct vb2_queue *q, unsigned int count)
  558. {
  559. struct soc_camera_device *icd = soc_camera_from_vb2q(q);
  560. struct soc_camera_host *ici =
  561. to_soc_camera_host(icd->parent);
  562. struct mx2_camera_dev *pcdev = ici->priv;
  563. struct mx2_fmt_cfg *prp = pcdev->emma_prp;
  564. struct vb2_buffer *vb;
  565. struct mx2_buffer *buf;
  566. unsigned long phys;
  567. int bytesperline;
  568. unsigned long flags;
  569. if (count < 2)
  570. return -ENOBUFS;
  571. spin_lock_irqsave(&pcdev->lock, flags);
  572. buf = list_first_entry(&pcdev->capture, struct mx2_buffer,
  573. internal.queue);
  574. buf->internal.bufnum = 0;
  575. vb = &buf->vb;
  576. phys = vb2_dma_contig_plane_dma_addr(vb, 0);
  577. mx27_update_emma_buf(pcdev, phys, buf->internal.bufnum);
  578. list_move_tail(pcdev->capture.next, &pcdev->active_bufs);
  579. buf = list_first_entry(&pcdev->capture, struct mx2_buffer,
  580. internal.queue);
  581. buf->internal.bufnum = 1;
  582. vb = &buf->vb;
  583. phys = vb2_dma_contig_plane_dma_addr(vb, 0);
  584. mx27_update_emma_buf(pcdev, phys, buf->internal.bufnum);
  585. list_move_tail(pcdev->capture.next, &pcdev->active_bufs);
  586. bytesperline = soc_mbus_bytes_per_line(icd->user_width,
  587. icd->current_fmt->host_fmt);
  588. if (bytesperline < 0) {
  589. spin_unlock_irqrestore(&pcdev->lock, flags);
  590. return bytesperline;
  591. }
  592. /*
  593. * I didn't manage to properly enable/disable the prp
  594. * on a per frame basis during running transfers,
  595. * thus we allocate a buffer here and use it to
  596. * discard frames when no buffer is available.
  597. * Feel free to work on this ;)
  598. */
  599. pcdev->discard_size = icd->user_height * bytesperline;
  600. pcdev->discard_buffer = dma_alloc_coherent(ici->v4l2_dev.dev,
  601. pcdev->discard_size,
  602. &pcdev->discard_buffer_dma, GFP_ATOMIC);
  603. if (!pcdev->discard_buffer) {
  604. spin_unlock_irqrestore(&pcdev->lock, flags);
  605. return -ENOMEM;
  606. }
  607. pcdev->buf_discard[0].discard = true;
  608. list_add_tail(&pcdev->buf_discard[0].queue,
  609. &pcdev->discard);
  610. pcdev->buf_discard[1].discard = true;
  611. list_add_tail(&pcdev->buf_discard[1].queue,
  612. &pcdev->discard);
  613. mx2_prp_resize_commit(pcdev);
  614. mx27_camera_emma_buf_init(icd, bytesperline);
  615. if (prp->cfg.channel == 1) {
  616. writel(PRP_CNTL_CH1EN |
  617. PRP_CNTL_CSIEN |
  618. prp->cfg.in_fmt |
  619. prp->cfg.out_fmt |
  620. PRP_CNTL_CH1_LEN |
  621. PRP_CNTL_CH1BYP |
  622. PRP_CNTL_CH1_TSKIP(0) |
  623. PRP_CNTL_IN_TSKIP(0),
  624. pcdev->base_emma + PRP_CNTL);
  625. } else {
  626. writel(PRP_CNTL_CH2EN |
  627. PRP_CNTL_CSIEN |
  628. prp->cfg.in_fmt |
  629. prp->cfg.out_fmt |
  630. PRP_CNTL_CH2_LEN |
  631. PRP_CNTL_CH2_TSKIP(0) |
  632. PRP_CNTL_IN_TSKIP(0),
  633. pcdev->base_emma + PRP_CNTL);
  634. }
  635. spin_unlock_irqrestore(&pcdev->lock, flags);
  636. return 0;
  637. }
  638. static void mx2_stop_streaming(struct vb2_queue *q)
  639. {
  640. struct soc_camera_device *icd = soc_camera_from_vb2q(q);
  641. struct soc_camera_host *ici =
  642. to_soc_camera_host(icd->parent);
  643. struct mx2_camera_dev *pcdev = ici->priv;
  644. struct mx2_fmt_cfg *prp = pcdev->emma_prp;
  645. unsigned long flags;
  646. void *b;
  647. u32 cntl;
  648. spin_lock_irqsave(&pcdev->lock, flags);
  649. cntl = readl(pcdev->base_emma + PRP_CNTL);
  650. if (prp->cfg.channel == 1) {
  651. writel(cntl & ~PRP_CNTL_CH1EN,
  652. pcdev->base_emma + PRP_CNTL);
  653. } else {
  654. writel(cntl & ~PRP_CNTL_CH2EN,
  655. pcdev->base_emma + PRP_CNTL);
  656. }
  657. INIT_LIST_HEAD(&pcdev->capture);
  658. INIT_LIST_HEAD(&pcdev->active_bufs);
  659. INIT_LIST_HEAD(&pcdev->discard);
  660. b = pcdev->discard_buffer;
  661. pcdev->discard_buffer = NULL;
  662. spin_unlock_irqrestore(&pcdev->lock, flags);
  663. dma_free_coherent(ici->v4l2_dev.dev,
  664. pcdev->discard_size, b, pcdev->discard_buffer_dma);
  665. }
  666. static struct vb2_ops mx2_videobuf_ops = {
  667. .queue_setup = mx2_videobuf_setup,
  668. .buf_prepare = mx2_videobuf_prepare,
  669. .buf_queue = mx2_videobuf_queue,
  670. .start_streaming = mx2_start_streaming,
  671. .stop_streaming = mx2_stop_streaming,
  672. };
  673. static int mx2_camera_init_videobuf(struct vb2_queue *q,
  674. struct soc_camera_device *icd)
  675. {
  676. q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  677. q->io_modes = VB2_MMAP | VB2_USERPTR;
  678. q->drv_priv = icd;
  679. q->ops = &mx2_videobuf_ops;
  680. q->mem_ops = &vb2_dma_contig_memops;
  681. q->buf_struct_size = sizeof(struct mx2_buffer);
  682. q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
  683. return vb2_queue_init(q);
  684. }
  685. #define MX2_BUS_FLAGS (V4L2_MBUS_MASTER | \
  686. V4L2_MBUS_VSYNC_ACTIVE_HIGH | \
  687. V4L2_MBUS_VSYNC_ACTIVE_LOW | \
  688. V4L2_MBUS_HSYNC_ACTIVE_HIGH | \
  689. V4L2_MBUS_HSYNC_ACTIVE_LOW | \
  690. V4L2_MBUS_PCLK_SAMPLE_RISING | \
  691. V4L2_MBUS_PCLK_SAMPLE_FALLING | \
  692. V4L2_MBUS_DATA_ACTIVE_HIGH | \
  693. V4L2_MBUS_DATA_ACTIVE_LOW)
  694. static int mx27_camera_emma_prp_reset(struct mx2_camera_dev *pcdev)
  695. {
  696. int count = 0;
  697. readl(pcdev->base_emma + PRP_CNTL);
  698. writel(PRP_CNTL_SWRST, pcdev->base_emma + PRP_CNTL);
  699. while (count++ < 100) {
  700. if (!(readl(pcdev->base_emma + PRP_CNTL) & PRP_CNTL_SWRST))
  701. return 0;
  702. barrier();
  703. udelay(1);
  704. }
  705. return -ETIMEDOUT;
  706. }
  707. static int mx2_camera_set_bus_param(struct soc_camera_device *icd)
  708. {
  709. struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
  710. struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
  711. struct mx2_camera_dev *pcdev = ici->priv;
  712. struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,};
  713. unsigned long common_flags;
  714. int ret;
  715. int bytesperline;
  716. u32 csicr1 = pcdev->csicr1;
  717. ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg);
  718. if (!ret) {
  719. common_flags = soc_mbus_config_compatible(&cfg, MX2_BUS_FLAGS);
  720. if (!common_flags) {
  721. dev_warn(icd->parent,
  722. "Flags incompatible: camera 0x%x, host 0x%x\n",
  723. cfg.flags, MX2_BUS_FLAGS);
  724. return -EINVAL;
  725. }
  726. } else if (ret != -ENOIOCTLCMD) {
  727. return ret;
  728. } else {
  729. common_flags = MX2_BUS_FLAGS;
  730. }
  731. if ((common_flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) &&
  732. (common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)) {
  733. if (pcdev->platform_flags & MX2_CAMERA_HSYNC_HIGH)
  734. common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_LOW;
  735. else
  736. common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_HIGH;
  737. }
  738. if ((common_flags & V4L2_MBUS_PCLK_SAMPLE_RISING) &&
  739. (common_flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)) {
  740. if (pcdev->platform_flags & MX2_CAMERA_PCLK_SAMPLE_RISING)
  741. common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_FALLING;
  742. else
  743. common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_RISING;
  744. }
  745. cfg.flags = common_flags;
  746. ret = v4l2_subdev_call(sd, video, s_mbus_config, &cfg);
  747. if (ret < 0 && ret != -ENOIOCTLCMD) {
  748. dev_dbg(icd->parent, "camera s_mbus_config(0x%lx) returned %d\n",
  749. common_flags, ret);
  750. return ret;
  751. }
  752. csicr1 = (csicr1 & ~CSICR1_FMT_MASK) | pcdev->emma_prp->cfg.csicr1;
  753. if (common_flags & V4L2_MBUS_PCLK_SAMPLE_RISING)
  754. csicr1 |= CSICR1_REDGE;
  755. if (common_flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH)
  756. csicr1 |= CSICR1_SOF_POL;
  757. if (common_flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH)
  758. csicr1 |= CSICR1_HSYNC_POL;
  759. if (pcdev->platform_flags & MX2_CAMERA_EXT_VSYNC)
  760. csicr1 |= CSICR1_EXT_VSYNC;
  761. if (pcdev->platform_flags & MX2_CAMERA_CCIR)
  762. csicr1 |= CSICR1_CCIR_EN;
  763. if (pcdev->platform_flags & MX2_CAMERA_CCIR_INTERLACE)
  764. csicr1 |= CSICR1_CCIR_MODE;
  765. if (pcdev->platform_flags & MX2_CAMERA_GATED_CLOCK)
  766. csicr1 |= CSICR1_GCLK_MODE;
  767. if (pcdev->platform_flags & MX2_CAMERA_INV_DATA)
  768. csicr1 |= CSICR1_INV_DATA;
  769. pcdev->csicr1 = csicr1;
  770. bytesperline = soc_mbus_bytes_per_line(icd->user_width,
  771. icd->current_fmt->host_fmt);
  772. if (bytesperline < 0)
  773. return bytesperline;
  774. ret = mx27_camera_emma_prp_reset(pcdev);
  775. if (ret)
  776. return ret;
  777. writel(pcdev->csicr1, pcdev->base_csi + CSICR1);
  778. return 0;
  779. }
  780. static int mx2_camera_set_crop(struct soc_camera_device *icd,
  781. const struct v4l2_crop *a)
  782. {
  783. struct v4l2_crop a_writable = *a;
  784. struct v4l2_rect *rect = &a_writable.c;
  785. struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
  786. struct v4l2_subdev_format fmt = {
  787. .which = V4L2_SUBDEV_FORMAT_ACTIVE,
  788. };
  789. struct v4l2_mbus_framefmt *mf = &fmt.format;
  790. int ret;
  791. soc_camera_limit_side(&rect->left, &rect->width, 0, 2, 4096);
  792. soc_camera_limit_side(&rect->top, &rect->height, 0, 2, 4096);
  793. ret = v4l2_subdev_call(sd, video, s_crop, a);
  794. if (ret < 0)
  795. return ret;
  796. /* The capture device might have changed its output */
  797. ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &fmt);
  798. if (ret < 0)
  799. return ret;
  800. dev_dbg(icd->parent, "Sensor cropped %dx%d\n",
  801. mf->width, mf->height);
  802. icd->user_width = mf->width;
  803. icd->user_height = mf->height;
  804. return ret;
  805. }
  806. static int mx2_camera_get_formats(struct soc_camera_device *icd,
  807. unsigned int idx,
  808. struct soc_camera_format_xlate *xlate)
  809. {
  810. struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
  811. const struct soc_mbus_pixelfmt *fmt;
  812. struct device *dev = icd->parent;
  813. struct v4l2_subdev_mbus_code_enum code = {
  814. .which = V4L2_SUBDEV_FORMAT_ACTIVE,
  815. .index = idx,
  816. };
  817. int ret, formats = 0;
  818. ret = v4l2_subdev_call(sd, pad, enum_mbus_code, NULL, &code);
  819. if (ret < 0)
  820. /* no more formats */
  821. return 0;
  822. fmt = soc_mbus_get_fmtdesc(code.code);
  823. if (!fmt) {
  824. dev_err(dev, "Invalid format code #%u: %d\n", idx, code.code);
  825. return 0;
  826. }
  827. if (code.code == MEDIA_BUS_FMT_YUYV8_2X8 ||
  828. code.code == MEDIA_BUS_FMT_UYVY8_2X8) {
  829. formats++;
  830. if (xlate) {
  831. /*
  832. * CH2 can output YUV420 which is a standard format in
  833. * soc_mediabus.c
  834. */
  835. xlate->host_fmt =
  836. soc_mbus_get_fmtdesc(MEDIA_BUS_FMT_YUYV8_1_5X8);
  837. xlate->code = code.code;
  838. dev_dbg(dev, "Providing host format %s for sensor code %d\n",
  839. xlate->host_fmt->name, code.code);
  840. xlate++;
  841. }
  842. }
  843. if (code.code == MEDIA_BUS_FMT_UYVY8_2X8) {
  844. formats++;
  845. if (xlate) {
  846. xlate->host_fmt =
  847. soc_mbus_get_fmtdesc(MEDIA_BUS_FMT_YUYV8_2X8);
  848. xlate->code = code.code;
  849. dev_dbg(dev, "Providing host format %s for sensor code %d\n",
  850. xlate->host_fmt->name, code.code);
  851. xlate++;
  852. }
  853. }
  854. /* Generic pass-trough */
  855. formats++;
  856. if (xlate) {
  857. xlate->host_fmt = fmt;
  858. xlate->code = code.code;
  859. xlate++;
  860. }
  861. return formats;
  862. }
  863. static int mx2_emmaprp_resize(struct mx2_camera_dev *pcdev,
  864. struct v4l2_mbus_framefmt *mf_in,
  865. struct v4l2_pix_format *pix_out, bool apply)
  866. {
  867. unsigned int num, den;
  868. unsigned long m;
  869. int i, dir;
  870. for (dir = RESIZE_DIR_H; dir <= RESIZE_DIR_V; dir++) {
  871. struct emma_prp_resize tmprsz;
  872. unsigned char *s = tmprsz.s;
  873. int len = 0;
  874. int in, out;
  875. if (dir == RESIZE_DIR_H) {
  876. in = mf_in->width;
  877. out = pix_out->width;
  878. } else {
  879. in = mf_in->height;
  880. out = pix_out->height;
  881. }
  882. if (in < out)
  883. return -EINVAL;
  884. else if (in == out)
  885. continue;
  886. /* Calculate ratio */
  887. m = gcd(in, out);
  888. num = in / m;
  889. den = out / m;
  890. if (num > RESIZE_NUM_MAX)
  891. return -EINVAL;
  892. if ((num >= 2 * den) && (den == 1) &&
  893. (num < 9) && (!(num & 0x01))) {
  894. int sum = 0;
  895. int j;
  896. /* Average scaling for >= 2:1 ratios */
  897. /* Support can be added for num >=9 and odd values */
  898. tmprsz.algo = RESIZE_ALGO_AVERAGING;
  899. len = num;
  900. for (i = 0; i < (len / 2); i++)
  901. s[i] = 8;
  902. do {
  903. for (i = 0; i < (len / 2); i++) {
  904. s[i] = s[i] >> 1;
  905. sum = 0;
  906. for (j = 0; j < (len / 2); j++)
  907. sum += s[j];
  908. if (sum == 4)
  909. break;
  910. }
  911. } while (sum != 4);
  912. for (i = (len / 2); i < len; i++)
  913. s[i] = s[len - i - 1];
  914. s[len - 1] |= SZ_COEF;
  915. } else {
  916. /* bilinear scaling for < 2:1 ratios */
  917. int v; /* overflow counter */
  918. int coeff, nxt; /* table output */
  919. int in_pos_inc = 2 * den;
  920. int out_pos = num;
  921. int out_pos_inc = 2 * num;
  922. int init_carry = num - den;
  923. int carry = init_carry;
  924. tmprsz.algo = RESIZE_ALGO_BILINEAR;
  925. v = den + in_pos_inc;
  926. do {
  927. coeff = v - out_pos;
  928. out_pos += out_pos_inc;
  929. carry += out_pos_inc;
  930. for (nxt = 0; v < out_pos; nxt++) {
  931. v += in_pos_inc;
  932. carry -= in_pos_inc;
  933. }
  934. if (len > RESIZE_NUM_MAX)
  935. return -EINVAL;
  936. coeff = ((coeff << BC_COEF) +
  937. (in_pos_inc >> 1)) / in_pos_inc;
  938. if (coeff >= (SZ_COEF - 1))
  939. coeff--;
  940. coeff |= SZ_COEF;
  941. s[len] = (unsigned char)coeff;
  942. len++;
  943. for (i = 1; i < nxt; i++) {
  944. if (len >= RESIZE_NUM_MAX)
  945. return -EINVAL;
  946. s[len] = 0;
  947. len++;
  948. }
  949. } while (carry != init_carry);
  950. }
  951. tmprsz.len = len;
  952. if (dir == RESIZE_DIR_H)
  953. mf_in->width = pix_out->width;
  954. else
  955. mf_in->height = pix_out->height;
  956. if (apply)
  957. memcpy(&pcdev->resizing[dir], &tmprsz, sizeof(tmprsz));
  958. }
  959. return 0;
  960. }
  961. static int mx2_camera_set_fmt(struct soc_camera_device *icd,
  962. struct v4l2_format *f)
  963. {
  964. struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
  965. struct mx2_camera_dev *pcdev = ici->priv;
  966. struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
  967. const struct soc_camera_format_xlate *xlate;
  968. struct v4l2_pix_format *pix = &f->fmt.pix;
  969. struct v4l2_subdev_format format = {
  970. .which = V4L2_SUBDEV_FORMAT_ACTIVE,
  971. };
  972. struct v4l2_mbus_framefmt *mf = &format.format;
  973. int ret;
  974. dev_dbg(icd->parent, "%s: requested params: width = %d, height = %d\n",
  975. __func__, pix->width, pix->height);
  976. xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat);
  977. if (!xlate) {
  978. dev_warn(icd->parent, "Format %x not found\n",
  979. pix->pixelformat);
  980. return -EINVAL;
  981. }
  982. mf->width = pix->width;
  983. mf->height = pix->height;
  984. mf->field = pix->field;
  985. mf->colorspace = pix->colorspace;
  986. mf->code = xlate->code;
  987. ret = v4l2_subdev_call(sd, pad, set_fmt, NULL, &format);
  988. if (ret < 0 && ret != -ENOIOCTLCMD)
  989. return ret;
  990. /* Store width and height returned by the sensor for resizing */
  991. pcdev->s_width = mf->width;
  992. pcdev->s_height = mf->height;
  993. dev_dbg(icd->parent, "%s: sensor params: width = %d, height = %d\n",
  994. __func__, pcdev->s_width, pcdev->s_height);
  995. pcdev->emma_prp = mx27_emma_prp_get_format(xlate->code,
  996. xlate->host_fmt->fourcc);
  997. memset(pcdev->resizing, 0, sizeof(pcdev->resizing));
  998. if ((mf->width != pix->width || mf->height != pix->height) &&
  999. pcdev->emma_prp->cfg.in_fmt == PRP_CNTL_DATA_IN_YUV422) {
  1000. if (mx2_emmaprp_resize(pcdev, mf, pix, true) < 0)
  1001. dev_dbg(icd->parent, "%s: can't resize\n", __func__);
  1002. }
  1003. if (mf->code != xlate->code)
  1004. return -EINVAL;
  1005. pix->width = mf->width;
  1006. pix->height = mf->height;
  1007. pix->field = mf->field;
  1008. pix->colorspace = mf->colorspace;
  1009. icd->current_fmt = xlate;
  1010. dev_dbg(icd->parent, "%s: returned params: width = %d, height = %d\n",
  1011. __func__, pix->width, pix->height);
  1012. return 0;
  1013. }
  1014. static int mx2_camera_try_fmt(struct soc_camera_device *icd,
  1015. struct v4l2_format *f)
  1016. {
  1017. struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
  1018. const struct soc_camera_format_xlate *xlate;
  1019. struct v4l2_pix_format *pix = &f->fmt.pix;
  1020. struct v4l2_subdev_pad_config pad_cfg;
  1021. struct v4l2_subdev_format format = {
  1022. .which = V4L2_SUBDEV_FORMAT_TRY,
  1023. };
  1024. struct v4l2_mbus_framefmt *mf = &format.format;
  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, pad, set_fmt, &pad_cfg, &format);
  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->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
  1087. cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
  1088. return 0;
  1089. }
  1090. static unsigned int mx2_camera_poll(struct file *file, poll_table *pt)
  1091. {
  1092. struct soc_camera_device *icd = file->private_data;
  1093. return vb2_poll(&icd->vb2_vidq, file, pt);
  1094. }
  1095. static struct soc_camera_host_ops mx2_soc_camera_host_ops = {
  1096. .owner = THIS_MODULE,
  1097. .add = mx2_camera_add_device,
  1098. .remove = mx2_camera_remove_device,
  1099. .clock_start = mx2_camera_clock_start,
  1100. .clock_stop = mx2_camera_clock_stop,
  1101. .set_fmt = mx2_camera_set_fmt,
  1102. .set_crop = mx2_camera_set_crop,
  1103. .get_formats = mx2_camera_get_formats,
  1104. .try_fmt = mx2_camera_try_fmt,
  1105. .init_videobuf2 = mx2_camera_init_videobuf,
  1106. .poll = mx2_camera_poll,
  1107. .querycap = mx2_camera_querycap,
  1108. .set_bus_param = mx2_camera_set_bus_param,
  1109. };
  1110. static void mx27_camera_frame_done_emma(struct mx2_camera_dev *pcdev,
  1111. int bufnum, bool err)
  1112. {
  1113. #ifdef DEBUG
  1114. struct mx2_fmt_cfg *prp = pcdev->emma_prp;
  1115. #endif
  1116. struct mx2_buf_internal *ibuf;
  1117. struct mx2_buffer *buf;
  1118. struct vb2_buffer *vb;
  1119. unsigned long phys;
  1120. ibuf = list_first_entry(&pcdev->active_bufs, struct mx2_buf_internal,
  1121. queue);
  1122. BUG_ON(ibuf->bufnum != bufnum);
  1123. if (ibuf->discard) {
  1124. /*
  1125. * Discard buffer must not be returned to user space.
  1126. * Just return it to the discard queue.
  1127. */
  1128. list_move_tail(pcdev->active_bufs.next, &pcdev->discard);
  1129. } else {
  1130. buf = mx2_ibuf_to_buf(ibuf);
  1131. vb = &buf->vb;
  1132. #ifdef DEBUG
  1133. phys = vb2_dma_contig_plane_dma_addr(vb, 0);
  1134. if (prp->cfg.channel == 1) {
  1135. if (readl(pcdev->base_emma + PRP_DEST_RGB1_PTR +
  1136. 4 * bufnum) != phys) {
  1137. dev_err(pcdev->dev, "%lx != %x\n", phys,
  1138. readl(pcdev->base_emma +
  1139. PRP_DEST_RGB1_PTR + 4 * bufnum));
  1140. }
  1141. } else {
  1142. if (readl(pcdev->base_emma + PRP_DEST_Y_PTR -
  1143. 0x14 * bufnum) != phys) {
  1144. dev_err(pcdev->dev, "%lx != %x\n", phys,
  1145. readl(pcdev->base_emma +
  1146. PRP_DEST_Y_PTR - 0x14 * bufnum));
  1147. }
  1148. }
  1149. #endif
  1150. dev_dbg(pcdev->dev, "%s (vb=0x%p) 0x%p %lu\n", __func__, vb,
  1151. vb2_plane_vaddr(vb, 0),
  1152. vb2_get_plane_payload(vb, 0));
  1153. list_del_init(&buf->internal.queue);
  1154. v4l2_get_timestamp(&vb->v4l2_buf.timestamp);
  1155. vb->v4l2_buf.sequence = pcdev->frame_count;
  1156. if (err)
  1157. vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
  1158. else
  1159. vb2_buffer_done(vb, VB2_BUF_STATE_DONE);
  1160. }
  1161. pcdev->frame_count++;
  1162. if (list_empty(&pcdev->capture)) {
  1163. if (list_empty(&pcdev->discard)) {
  1164. dev_warn(pcdev->dev, "%s: trying to access empty discard list\n",
  1165. __func__);
  1166. return;
  1167. }
  1168. ibuf = list_first_entry(&pcdev->discard,
  1169. struct mx2_buf_internal, queue);
  1170. ibuf->bufnum = bufnum;
  1171. list_move_tail(pcdev->discard.next, &pcdev->active_bufs);
  1172. mx27_update_emma_buf(pcdev, pcdev->discard_buffer_dma, bufnum);
  1173. return;
  1174. }
  1175. buf = list_first_entry(&pcdev->capture, struct mx2_buffer,
  1176. internal.queue);
  1177. buf->internal.bufnum = bufnum;
  1178. list_move_tail(pcdev->capture.next, &pcdev->active_bufs);
  1179. vb = &buf->vb;
  1180. phys = vb2_dma_contig_plane_dma_addr(vb, 0);
  1181. mx27_update_emma_buf(pcdev, phys, bufnum);
  1182. }
  1183. static irqreturn_t mx27_camera_emma_irq(int irq_emma, void *data)
  1184. {
  1185. struct mx2_camera_dev *pcdev = data;
  1186. unsigned int status = readl(pcdev->base_emma + PRP_INTRSTATUS);
  1187. struct mx2_buf_internal *ibuf;
  1188. spin_lock(&pcdev->lock);
  1189. if (list_empty(&pcdev->active_bufs)) {
  1190. dev_warn(pcdev->dev, "%s: called while active list is empty\n",
  1191. __func__);
  1192. if (!status) {
  1193. spin_unlock(&pcdev->lock);
  1194. return IRQ_NONE;
  1195. }
  1196. }
  1197. if (status & (1 << 7)) { /* overflow */
  1198. u32 cntl = readl(pcdev->base_emma + PRP_CNTL);
  1199. writel(cntl & ~(PRP_CNTL_CH1EN | PRP_CNTL_CH2EN),
  1200. pcdev->base_emma + PRP_CNTL);
  1201. writel(cntl, pcdev->base_emma + PRP_CNTL);
  1202. ibuf = list_first_entry(&pcdev->active_bufs,
  1203. struct mx2_buf_internal, queue);
  1204. mx27_camera_frame_done_emma(pcdev,
  1205. ibuf->bufnum, true);
  1206. status &= ~(1 << 7);
  1207. } else if (((status & (3 << 5)) == (3 << 5)) ||
  1208. ((status & (3 << 3)) == (3 << 3))) {
  1209. /*
  1210. * Both buffers have triggered, process the one we're expecting
  1211. * to first
  1212. */
  1213. ibuf = list_first_entry(&pcdev->active_bufs,
  1214. struct mx2_buf_internal, queue);
  1215. mx27_camera_frame_done_emma(pcdev, ibuf->bufnum, false);
  1216. status &= ~(1 << (6 - ibuf->bufnum)); /* mark processed */
  1217. } else if ((status & (1 << 6)) || (status & (1 << 4))) {
  1218. mx27_camera_frame_done_emma(pcdev, 0, false);
  1219. } else if ((status & (1 << 5)) || (status & (1 << 3))) {
  1220. mx27_camera_frame_done_emma(pcdev, 1, false);
  1221. }
  1222. spin_unlock(&pcdev->lock);
  1223. writel(status, pcdev->base_emma + PRP_INTRSTATUS);
  1224. return IRQ_HANDLED;
  1225. }
  1226. static int mx27_camera_emma_init(struct platform_device *pdev)
  1227. {
  1228. struct mx2_camera_dev *pcdev = platform_get_drvdata(pdev);
  1229. struct resource *res_emma;
  1230. int irq_emma;
  1231. int err = 0;
  1232. res_emma = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  1233. irq_emma = platform_get_irq(pdev, 1);
  1234. if (!res_emma || !irq_emma) {
  1235. dev_err(pcdev->dev, "no EMMA resources\n");
  1236. err = -ENODEV;
  1237. goto out;
  1238. }
  1239. pcdev->base_emma = devm_ioremap_resource(pcdev->dev, res_emma);
  1240. if (IS_ERR(pcdev->base_emma)) {
  1241. err = PTR_ERR(pcdev->base_emma);
  1242. goto out;
  1243. }
  1244. err = devm_request_irq(pcdev->dev, irq_emma, mx27_camera_emma_irq, 0,
  1245. MX2_CAM_DRV_NAME, pcdev);
  1246. if (err) {
  1247. dev_err(pcdev->dev, "Camera EMMA interrupt register failed\n");
  1248. goto out;
  1249. }
  1250. pcdev->clk_emma_ipg = devm_clk_get(pcdev->dev, "emma-ipg");
  1251. if (IS_ERR(pcdev->clk_emma_ipg)) {
  1252. err = PTR_ERR(pcdev->clk_emma_ipg);
  1253. goto out;
  1254. }
  1255. clk_prepare_enable(pcdev->clk_emma_ipg);
  1256. pcdev->clk_emma_ahb = devm_clk_get(pcdev->dev, "emma-ahb");
  1257. if (IS_ERR(pcdev->clk_emma_ahb)) {
  1258. err = PTR_ERR(pcdev->clk_emma_ahb);
  1259. goto exit_clk_emma_ipg;
  1260. }
  1261. clk_prepare_enable(pcdev->clk_emma_ahb);
  1262. err = mx27_camera_emma_prp_reset(pcdev);
  1263. if (err)
  1264. goto exit_clk_emma_ahb;
  1265. return err;
  1266. exit_clk_emma_ahb:
  1267. clk_disable_unprepare(pcdev->clk_emma_ahb);
  1268. exit_clk_emma_ipg:
  1269. clk_disable_unprepare(pcdev->clk_emma_ipg);
  1270. out:
  1271. return err;
  1272. }
  1273. static int mx2_camera_probe(struct platform_device *pdev)
  1274. {
  1275. struct mx2_camera_dev *pcdev;
  1276. struct resource *res_csi;
  1277. int irq_csi;
  1278. int err = 0;
  1279. dev_dbg(&pdev->dev, "initialising\n");
  1280. res_csi = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1281. irq_csi = platform_get_irq(pdev, 0);
  1282. if (res_csi == NULL || irq_csi < 0) {
  1283. dev_err(&pdev->dev, "Missing platform resources data\n");
  1284. err = -ENODEV;
  1285. goto exit;
  1286. }
  1287. pcdev = devm_kzalloc(&pdev->dev, sizeof(*pcdev), GFP_KERNEL);
  1288. if (!pcdev) {
  1289. dev_err(&pdev->dev, "Could not allocate pcdev\n");
  1290. err = -ENOMEM;
  1291. goto exit;
  1292. }
  1293. pcdev->clk_csi_ahb = devm_clk_get(&pdev->dev, "ahb");
  1294. if (IS_ERR(pcdev->clk_csi_ahb)) {
  1295. dev_err(&pdev->dev, "Could not get csi ahb clock\n");
  1296. err = PTR_ERR(pcdev->clk_csi_ahb);
  1297. goto exit;
  1298. }
  1299. pcdev->clk_csi_per = devm_clk_get(&pdev->dev, "per");
  1300. if (IS_ERR(pcdev->clk_csi_per)) {
  1301. dev_err(&pdev->dev, "Could not get csi per clock\n");
  1302. err = PTR_ERR(pcdev->clk_csi_per);
  1303. goto exit;
  1304. }
  1305. pcdev->pdata = pdev->dev.platform_data;
  1306. if (pcdev->pdata) {
  1307. long rate;
  1308. pcdev->platform_flags = pcdev->pdata->flags;
  1309. rate = clk_round_rate(pcdev->clk_csi_per,
  1310. pcdev->pdata->clk * 2);
  1311. if (rate <= 0) {
  1312. err = -ENODEV;
  1313. goto exit;
  1314. }
  1315. err = clk_set_rate(pcdev->clk_csi_per, rate);
  1316. if (err < 0)
  1317. goto exit;
  1318. }
  1319. INIT_LIST_HEAD(&pcdev->capture);
  1320. INIT_LIST_HEAD(&pcdev->active_bufs);
  1321. INIT_LIST_HEAD(&pcdev->discard);
  1322. spin_lock_init(&pcdev->lock);
  1323. pcdev->base_csi = devm_ioremap_resource(&pdev->dev, res_csi);
  1324. if (IS_ERR(pcdev->base_csi)) {
  1325. err = PTR_ERR(pcdev->base_csi);
  1326. goto exit;
  1327. }
  1328. pcdev->dev = &pdev->dev;
  1329. platform_set_drvdata(pdev, pcdev);
  1330. err = mx27_camera_emma_init(pdev);
  1331. if (err)
  1332. goto exit;
  1333. /*
  1334. * We're done with drvdata here. Clear the pointer so that
  1335. * v4l2 core can start using drvdata on its purpose.
  1336. */
  1337. platform_set_drvdata(pdev, NULL);
  1338. pcdev->soc_host.drv_name = MX2_CAM_DRV_NAME,
  1339. pcdev->soc_host.ops = &mx2_soc_camera_host_ops,
  1340. pcdev->soc_host.priv = pcdev;
  1341. pcdev->soc_host.v4l2_dev.dev = &pdev->dev;
  1342. pcdev->soc_host.nr = pdev->id;
  1343. pcdev->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev);
  1344. if (IS_ERR(pcdev->alloc_ctx)) {
  1345. err = PTR_ERR(pcdev->alloc_ctx);
  1346. goto eallocctx;
  1347. }
  1348. err = soc_camera_host_register(&pcdev->soc_host);
  1349. if (err)
  1350. goto exit_free_emma;
  1351. dev_info(&pdev->dev, "MX2 Camera (CSI) driver probed, clock frequency: %ld\n",
  1352. clk_get_rate(pcdev->clk_csi_per));
  1353. return 0;
  1354. exit_free_emma:
  1355. vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx);
  1356. eallocctx:
  1357. clk_disable_unprepare(pcdev->clk_emma_ipg);
  1358. clk_disable_unprepare(pcdev->clk_emma_ahb);
  1359. exit:
  1360. return err;
  1361. }
  1362. static int mx2_camera_remove(struct platform_device *pdev)
  1363. {
  1364. struct soc_camera_host *soc_host = to_soc_camera_host(&pdev->dev);
  1365. struct mx2_camera_dev *pcdev = container_of(soc_host,
  1366. struct mx2_camera_dev, soc_host);
  1367. soc_camera_host_unregister(&pcdev->soc_host);
  1368. vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx);
  1369. clk_disable_unprepare(pcdev->clk_emma_ipg);
  1370. clk_disable_unprepare(pcdev->clk_emma_ahb);
  1371. dev_info(&pdev->dev, "MX2 Camera driver unloaded\n");
  1372. return 0;
  1373. }
  1374. static struct platform_driver mx2_camera_driver = {
  1375. .driver = {
  1376. .name = MX2_CAM_DRV_NAME,
  1377. },
  1378. .id_table = mx2_camera_devtype,
  1379. .remove = mx2_camera_remove,
  1380. };
  1381. module_platform_driver_probe(mx2_camera_driver, mx2_camera_probe);
  1382. MODULE_DESCRIPTION("i.MX27 SoC Camera Host driver");
  1383. MODULE_AUTHOR("Sascha Hauer <sha@pengutronix.de>");
  1384. MODULE_LICENSE("GPL");
  1385. MODULE_VERSION(MX2_CAM_VERSION);