fimc-core.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309
  1. /*
  2. * Samsung S5P/EXYNOS4 SoC series FIMC (CAMIF) driver
  3. *
  4. * Copyright (C) 2010-2012 Samsung Electronics Co., Ltd.
  5. * Sylwester Nawrocki <s.nawrocki@samsung.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published
  9. * by the Free Software Foundation, either version 2 of the License,
  10. * or (at your option) any later version.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/kernel.h>
  14. #include <linux/types.h>
  15. #include <linux/errno.h>
  16. #include <linux/bug.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/device.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/pm_runtime.h>
  21. #include <linux/list.h>
  22. #include <linux/mfd/syscon.h>
  23. #include <linux/io.h>
  24. #include <linux/of.h>
  25. #include <linux/of_device.h>
  26. #include <linux/slab.h>
  27. #include <linux/clk.h>
  28. #include <media/v4l2-ioctl.h>
  29. #include <media/videobuf2-v4l2.h>
  30. #include <media/videobuf2-dma-contig.h>
  31. #include "fimc-core.h"
  32. #include "fimc-reg.h"
  33. #include "media-dev.h"
  34. static char *fimc_clocks[MAX_FIMC_CLOCKS] = {
  35. "sclk_fimc", "fimc"
  36. };
  37. static struct fimc_fmt fimc_formats[] = {
  38. {
  39. .name = "RGB565",
  40. .fourcc = V4L2_PIX_FMT_RGB565,
  41. .depth = { 16 },
  42. .color = FIMC_FMT_RGB565,
  43. .memplanes = 1,
  44. .colplanes = 1,
  45. .flags = FMT_FLAGS_M2M,
  46. }, {
  47. .name = "BGR666",
  48. .fourcc = V4L2_PIX_FMT_BGR666,
  49. .depth = { 32 },
  50. .color = FIMC_FMT_RGB666,
  51. .memplanes = 1,
  52. .colplanes = 1,
  53. .flags = FMT_FLAGS_M2M,
  54. }, {
  55. .name = "BGRA8888, 32 bpp",
  56. .fourcc = V4L2_PIX_FMT_BGR32,
  57. .depth = { 32 },
  58. .color = FIMC_FMT_RGB888,
  59. .memplanes = 1,
  60. .colplanes = 1,
  61. .flags = FMT_FLAGS_M2M | FMT_HAS_ALPHA,
  62. }, {
  63. .name = "ARGB1555",
  64. .fourcc = V4L2_PIX_FMT_RGB555,
  65. .depth = { 16 },
  66. .color = FIMC_FMT_RGB555,
  67. .memplanes = 1,
  68. .colplanes = 1,
  69. .flags = FMT_FLAGS_M2M_OUT | FMT_HAS_ALPHA,
  70. }, {
  71. .name = "ARGB4444",
  72. .fourcc = V4L2_PIX_FMT_RGB444,
  73. .depth = { 16 },
  74. .color = FIMC_FMT_RGB444,
  75. .memplanes = 1,
  76. .colplanes = 1,
  77. .flags = FMT_FLAGS_M2M_OUT | FMT_HAS_ALPHA,
  78. }, {
  79. .name = "YUV 4:4:4",
  80. .mbus_code = MEDIA_BUS_FMT_YUV10_1X30,
  81. .flags = FMT_FLAGS_WRITEBACK,
  82. }, {
  83. .name = "YUV 4:2:2 packed, YCbYCr",
  84. .fourcc = V4L2_PIX_FMT_YUYV,
  85. .depth = { 16 },
  86. .color = FIMC_FMT_YCBYCR422,
  87. .memplanes = 1,
  88. .colplanes = 1,
  89. .mbus_code = MEDIA_BUS_FMT_YUYV8_2X8,
  90. .flags = FMT_FLAGS_M2M | FMT_FLAGS_CAM,
  91. }, {
  92. .name = "YUV 4:2:2 packed, CbYCrY",
  93. .fourcc = V4L2_PIX_FMT_UYVY,
  94. .depth = { 16 },
  95. .color = FIMC_FMT_CBYCRY422,
  96. .memplanes = 1,
  97. .colplanes = 1,
  98. .mbus_code = MEDIA_BUS_FMT_UYVY8_2X8,
  99. .flags = FMT_FLAGS_M2M | FMT_FLAGS_CAM,
  100. }, {
  101. .name = "YUV 4:2:2 packed, CrYCbY",
  102. .fourcc = V4L2_PIX_FMT_VYUY,
  103. .depth = { 16 },
  104. .color = FIMC_FMT_CRYCBY422,
  105. .memplanes = 1,
  106. .colplanes = 1,
  107. .mbus_code = MEDIA_BUS_FMT_VYUY8_2X8,
  108. .flags = FMT_FLAGS_M2M | FMT_FLAGS_CAM,
  109. }, {
  110. .name = "YUV 4:2:2 packed, YCrYCb",
  111. .fourcc = V4L2_PIX_FMT_YVYU,
  112. .depth = { 16 },
  113. .color = FIMC_FMT_YCRYCB422,
  114. .memplanes = 1,
  115. .colplanes = 1,
  116. .mbus_code = MEDIA_BUS_FMT_YVYU8_2X8,
  117. .flags = FMT_FLAGS_M2M | FMT_FLAGS_CAM,
  118. }, {
  119. .name = "YUV 4:2:2 planar, Y/Cb/Cr",
  120. .fourcc = V4L2_PIX_FMT_YUV422P,
  121. .depth = { 16 },
  122. .color = FIMC_FMT_YCBYCR422,
  123. .memplanes = 1,
  124. .colplanes = 3,
  125. .flags = FMT_FLAGS_M2M,
  126. }, {
  127. .name = "YUV 4:2:2 planar, Y/CbCr",
  128. .fourcc = V4L2_PIX_FMT_NV16,
  129. .depth = { 16 },
  130. .color = FIMC_FMT_YCBYCR422,
  131. .memplanes = 1,
  132. .colplanes = 2,
  133. .flags = FMT_FLAGS_M2M,
  134. }, {
  135. .name = "YUV 4:2:2 planar, Y/CrCb",
  136. .fourcc = V4L2_PIX_FMT_NV61,
  137. .depth = { 16 },
  138. .color = FIMC_FMT_YCRYCB422,
  139. .memplanes = 1,
  140. .colplanes = 2,
  141. .flags = FMT_FLAGS_M2M,
  142. }, {
  143. .name = "YUV 4:2:0 planar, YCbCr",
  144. .fourcc = V4L2_PIX_FMT_YUV420,
  145. .depth = { 12 },
  146. .color = FIMC_FMT_YCBCR420,
  147. .memplanes = 1,
  148. .colplanes = 3,
  149. .flags = FMT_FLAGS_M2M,
  150. }, {
  151. .name = "YUV 4:2:0 planar, Y/CbCr",
  152. .fourcc = V4L2_PIX_FMT_NV12,
  153. .depth = { 12 },
  154. .color = FIMC_FMT_YCBCR420,
  155. .memplanes = 1,
  156. .colplanes = 2,
  157. .flags = FMT_FLAGS_M2M,
  158. }, {
  159. .name = "YUV 4:2:0 non-contig. 2p, Y/CbCr",
  160. .fourcc = V4L2_PIX_FMT_NV12M,
  161. .color = FIMC_FMT_YCBCR420,
  162. .depth = { 8, 4 },
  163. .memplanes = 2,
  164. .colplanes = 2,
  165. .flags = FMT_FLAGS_M2M,
  166. }, {
  167. .name = "YUV 4:2:0 non-contig. 3p, Y/Cb/Cr",
  168. .fourcc = V4L2_PIX_FMT_YUV420M,
  169. .color = FIMC_FMT_YCBCR420,
  170. .depth = { 8, 2, 2 },
  171. .memplanes = 3,
  172. .colplanes = 3,
  173. .flags = FMT_FLAGS_M2M,
  174. }, {
  175. .name = "YUV 4:2:0 non-contig. 2p, tiled",
  176. .fourcc = V4L2_PIX_FMT_NV12MT,
  177. .color = FIMC_FMT_YCBCR420,
  178. .depth = { 8, 4 },
  179. .memplanes = 2,
  180. .colplanes = 2,
  181. .flags = FMT_FLAGS_M2M,
  182. }, {
  183. .name = "JPEG encoded data",
  184. .fourcc = V4L2_PIX_FMT_JPEG,
  185. .color = FIMC_FMT_JPEG,
  186. .depth = { 8 },
  187. .memplanes = 1,
  188. .colplanes = 1,
  189. .mbus_code = MEDIA_BUS_FMT_JPEG_1X8,
  190. .flags = FMT_FLAGS_CAM | FMT_FLAGS_COMPRESSED,
  191. }, {
  192. .name = "S5C73MX interleaved UYVY/JPEG",
  193. .fourcc = V4L2_PIX_FMT_S5C_UYVY_JPG,
  194. .color = FIMC_FMT_YUYV_JPEG,
  195. .depth = { 8 },
  196. .memplanes = 2,
  197. .colplanes = 1,
  198. .mdataplanes = 0x2, /* plane 1 holds frame meta data */
  199. .mbus_code = MEDIA_BUS_FMT_S5C_UYVY_JPEG_1X8,
  200. .flags = FMT_FLAGS_CAM | FMT_FLAGS_COMPRESSED,
  201. },
  202. };
  203. struct fimc_fmt *fimc_get_format(unsigned int index)
  204. {
  205. if (index >= ARRAY_SIZE(fimc_formats))
  206. return NULL;
  207. return &fimc_formats[index];
  208. }
  209. int fimc_check_scaler_ratio(struct fimc_ctx *ctx, int sw, int sh,
  210. int dw, int dh, int rotation)
  211. {
  212. if (rotation == 90 || rotation == 270)
  213. swap(dw, dh);
  214. if (!ctx->scaler.enabled)
  215. return (sw == dw && sh == dh) ? 0 : -EINVAL;
  216. if ((sw >= SCALER_MAX_HRATIO * dw) || (sh >= SCALER_MAX_VRATIO * dh))
  217. return -EINVAL;
  218. return 0;
  219. }
  220. static int fimc_get_scaler_factor(u32 src, u32 tar, u32 *ratio, u32 *shift)
  221. {
  222. u32 sh = 6;
  223. if (src >= 64 * tar)
  224. return -EINVAL;
  225. while (sh--) {
  226. u32 tmp = 1 << sh;
  227. if (src >= tar * tmp) {
  228. *shift = sh, *ratio = tmp;
  229. return 0;
  230. }
  231. }
  232. *shift = 0, *ratio = 1;
  233. return 0;
  234. }
  235. int fimc_set_scaler_info(struct fimc_ctx *ctx)
  236. {
  237. const struct fimc_variant *variant = ctx->fimc_dev->variant;
  238. struct device *dev = &ctx->fimc_dev->pdev->dev;
  239. struct fimc_scaler *sc = &ctx->scaler;
  240. struct fimc_frame *s_frame = &ctx->s_frame;
  241. struct fimc_frame *d_frame = &ctx->d_frame;
  242. int tx, ty, sx, sy;
  243. int ret;
  244. if (ctx->rotation == 90 || ctx->rotation == 270) {
  245. ty = d_frame->width;
  246. tx = d_frame->height;
  247. } else {
  248. tx = d_frame->width;
  249. ty = d_frame->height;
  250. }
  251. if (tx <= 0 || ty <= 0) {
  252. dev_err(dev, "Invalid target size: %dx%d\n", tx, ty);
  253. return -EINVAL;
  254. }
  255. sx = s_frame->width;
  256. sy = s_frame->height;
  257. if (sx <= 0 || sy <= 0) {
  258. dev_err(dev, "Invalid source size: %dx%d\n", sx, sy);
  259. return -EINVAL;
  260. }
  261. sc->real_width = sx;
  262. sc->real_height = sy;
  263. ret = fimc_get_scaler_factor(sx, tx, &sc->pre_hratio, &sc->hfactor);
  264. if (ret)
  265. return ret;
  266. ret = fimc_get_scaler_factor(sy, ty, &sc->pre_vratio, &sc->vfactor);
  267. if (ret)
  268. return ret;
  269. sc->pre_dst_width = sx / sc->pre_hratio;
  270. sc->pre_dst_height = sy / sc->pre_vratio;
  271. if (variant->has_mainscaler_ext) {
  272. sc->main_hratio = (sx << 14) / (tx << sc->hfactor);
  273. sc->main_vratio = (sy << 14) / (ty << sc->vfactor);
  274. } else {
  275. sc->main_hratio = (sx << 8) / (tx << sc->hfactor);
  276. sc->main_vratio = (sy << 8) / (ty << sc->vfactor);
  277. }
  278. sc->scaleup_h = (tx >= sx) ? 1 : 0;
  279. sc->scaleup_v = (ty >= sy) ? 1 : 0;
  280. /* check to see if input and output size/format differ */
  281. if (s_frame->fmt->color == d_frame->fmt->color
  282. && s_frame->width == d_frame->width
  283. && s_frame->height == d_frame->height)
  284. sc->copy_mode = 1;
  285. else
  286. sc->copy_mode = 0;
  287. return 0;
  288. }
  289. static irqreturn_t fimc_irq_handler(int irq, void *priv)
  290. {
  291. struct fimc_dev *fimc = priv;
  292. struct fimc_ctx *ctx;
  293. fimc_hw_clear_irq(fimc);
  294. spin_lock(&fimc->slock);
  295. if (test_and_clear_bit(ST_M2M_PEND, &fimc->state)) {
  296. if (test_and_clear_bit(ST_M2M_SUSPENDING, &fimc->state)) {
  297. set_bit(ST_M2M_SUSPENDED, &fimc->state);
  298. wake_up(&fimc->irq_queue);
  299. goto out;
  300. }
  301. ctx = v4l2_m2m_get_curr_priv(fimc->m2m.m2m_dev);
  302. if (ctx != NULL) {
  303. spin_unlock(&fimc->slock);
  304. fimc_m2m_job_finish(ctx, VB2_BUF_STATE_DONE);
  305. if (ctx->state & FIMC_CTX_SHUT) {
  306. ctx->state &= ~FIMC_CTX_SHUT;
  307. wake_up(&fimc->irq_queue);
  308. }
  309. return IRQ_HANDLED;
  310. }
  311. } else if (test_bit(ST_CAPT_PEND, &fimc->state)) {
  312. int last_buf = test_bit(ST_CAPT_JPEG, &fimc->state) &&
  313. fimc->vid_cap.reqbufs_count == 1;
  314. fimc_capture_irq_handler(fimc, !last_buf);
  315. }
  316. out:
  317. spin_unlock(&fimc->slock);
  318. return IRQ_HANDLED;
  319. }
  320. /* The color format (colplanes, memplanes) must be already configured. */
  321. int fimc_prepare_addr(struct fimc_ctx *ctx, struct vb2_buffer *vb,
  322. struct fimc_frame *frame, struct fimc_addr *paddr)
  323. {
  324. int ret = 0;
  325. u32 pix_size;
  326. if (vb == NULL || frame == NULL)
  327. return -EINVAL;
  328. pix_size = frame->width * frame->height;
  329. dbg("memplanes= %d, colplanes= %d, pix_size= %d",
  330. frame->fmt->memplanes, frame->fmt->colplanes, pix_size);
  331. paddr->y = vb2_dma_contig_plane_dma_addr(vb, 0);
  332. if (frame->fmt->memplanes == 1) {
  333. switch (frame->fmt->colplanes) {
  334. case 1:
  335. paddr->cb = 0;
  336. paddr->cr = 0;
  337. break;
  338. case 2:
  339. /* decompose Y into Y/Cb */
  340. paddr->cb = (u32)(paddr->y + pix_size);
  341. paddr->cr = 0;
  342. break;
  343. case 3:
  344. paddr->cb = (u32)(paddr->y + pix_size);
  345. /* decompose Y into Y/Cb/Cr */
  346. if (FIMC_FMT_YCBCR420 == frame->fmt->color)
  347. paddr->cr = (u32)(paddr->cb
  348. + (pix_size >> 2));
  349. else /* 422 */
  350. paddr->cr = (u32)(paddr->cb
  351. + (pix_size >> 1));
  352. break;
  353. default:
  354. return -EINVAL;
  355. }
  356. } else if (!frame->fmt->mdataplanes) {
  357. if (frame->fmt->memplanes >= 2)
  358. paddr->cb = vb2_dma_contig_plane_dma_addr(vb, 1);
  359. if (frame->fmt->memplanes == 3)
  360. paddr->cr = vb2_dma_contig_plane_dma_addr(vb, 2);
  361. }
  362. dbg("PHYS_ADDR: y= 0x%X cb= 0x%X cr= 0x%X ret= %d",
  363. paddr->y, paddr->cb, paddr->cr, ret);
  364. return ret;
  365. }
  366. /* Set order for 1 and 2 plane YCBCR 4:2:2 formats. */
  367. void fimc_set_yuv_order(struct fimc_ctx *ctx)
  368. {
  369. /* The one only mode supported in SoC. */
  370. ctx->in_order_2p = FIMC_REG_CIOCTRL_ORDER422_2P_LSB_CRCB;
  371. ctx->out_order_2p = FIMC_REG_CIOCTRL_ORDER422_2P_LSB_CRCB;
  372. /* Set order for 1 plane input formats. */
  373. switch (ctx->s_frame.fmt->color) {
  374. case FIMC_FMT_YCRYCB422:
  375. ctx->in_order_1p = FIMC_REG_MSCTRL_ORDER422_YCRYCB;
  376. break;
  377. case FIMC_FMT_CBYCRY422:
  378. ctx->in_order_1p = FIMC_REG_MSCTRL_ORDER422_CBYCRY;
  379. break;
  380. case FIMC_FMT_CRYCBY422:
  381. ctx->in_order_1p = FIMC_REG_MSCTRL_ORDER422_CRYCBY;
  382. break;
  383. case FIMC_FMT_YCBYCR422:
  384. default:
  385. ctx->in_order_1p = FIMC_REG_MSCTRL_ORDER422_YCBYCR;
  386. break;
  387. }
  388. dbg("ctx->in_order_1p= %d", ctx->in_order_1p);
  389. switch (ctx->d_frame.fmt->color) {
  390. case FIMC_FMT_YCRYCB422:
  391. ctx->out_order_1p = FIMC_REG_CIOCTRL_ORDER422_YCRYCB;
  392. break;
  393. case FIMC_FMT_CBYCRY422:
  394. ctx->out_order_1p = FIMC_REG_CIOCTRL_ORDER422_CBYCRY;
  395. break;
  396. case FIMC_FMT_CRYCBY422:
  397. ctx->out_order_1p = FIMC_REG_CIOCTRL_ORDER422_CRYCBY;
  398. break;
  399. case FIMC_FMT_YCBYCR422:
  400. default:
  401. ctx->out_order_1p = FIMC_REG_CIOCTRL_ORDER422_YCBYCR;
  402. break;
  403. }
  404. dbg("ctx->out_order_1p= %d", ctx->out_order_1p);
  405. }
  406. void fimc_prepare_dma_offset(struct fimc_ctx *ctx, struct fimc_frame *f)
  407. {
  408. bool pix_hoff = ctx->fimc_dev->drv_data->dma_pix_hoff;
  409. u32 i, depth = 0;
  410. for (i = 0; i < f->fmt->memplanes; i++)
  411. depth += f->fmt->depth[i];
  412. f->dma_offset.y_h = f->offs_h;
  413. if (!pix_hoff)
  414. f->dma_offset.y_h *= (depth >> 3);
  415. f->dma_offset.y_v = f->offs_v;
  416. f->dma_offset.cb_h = f->offs_h;
  417. f->dma_offset.cb_v = f->offs_v;
  418. f->dma_offset.cr_h = f->offs_h;
  419. f->dma_offset.cr_v = f->offs_v;
  420. if (!pix_hoff) {
  421. if (f->fmt->colplanes == 3) {
  422. f->dma_offset.cb_h >>= 1;
  423. f->dma_offset.cr_h >>= 1;
  424. }
  425. if (f->fmt->color == FIMC_FMT_YCBCR420) {
  426. f->dma_offset.cb_v >>= 1;
  427. f->dma_offset.cr_v >>= 1;
  428. }
  429. }
  430. dbg("in_offset: color= %d, y_h= %d, y_v= %d",
  431. f->fmt->color, f->dma_offset.y_h, f->dma_offset.y_v);
  432. }
  433. static int fimc_set_color_effect(struct fimc_ctx *ctx, enum v4l2_colorfx colorfx)
  434. {
  435. struct fimc_effect *effect = &ctx->effect;
  436. switch (colorfx) {
  437. case V4L2_COLORFX_NONE:
  438. effect->type = FIMC_REG_CIIMGEFF_FIN_BYPASS;
  439. break;
  440. case V4L2_COLORFX_BW:
  441. effect->type = FIMC_REG_CIIMGEFF_FIN_ARBITRARY;
  442. effect->pat_cb = 128;
  443. effect->pat_cr = 128;
  444. break;
  445. case V4L2_COLORFX_SEPIA:
  446. effect->type = FIMC_REG_CIIMGEFF_FIN_ARBITRARY;
  447. effect->pat_cb = 115;
  448. effect->pat_cr = 145;
  449. break;
  450. case V4L2_COLORFX_NEGATIVE:
  451. effect->type = FIMC_REG_CIIMGEFF_FIN_NEGATIVE;
  452. break;
  453. case V4L2_COLORFX_EMBOSS:
  454. effect->type = FIMC_REG_CIIMGEFF_FIN_EMBOSSING;
  455. break;
  456. case V4L2_COLORFX_ART_FREEZE:
  457. effect->type = FIMC_REG_CIIMGEFF_FIN_ARTFREEZE;
  458. break;
  459. case V4L2_COLORFX_SILHOUETTE:
  460. effect->type = FIMC_REG_CIIMGEFF_FIN_SILHOUETTE;
  461. break;
  462. case V4L2_COLORFX_SET_CBCR:
  463. effect->type = FIMC_REG_CIIMGEFF_FIN_ARBITRARY;
  464. effect->pat_cb = ctx->ctrls.colorfx_cbcr->val >> 8;
  465. effect->pat_cr = ctx->ctrls.colorfx_cbcr->val & 0xff;
  466. break;
  467. default:
  468. return -EINVAL;
  469. }
  470. return 0;
  471. }
  472. /*
  473. * V4L2 controls handling
  474. */
  475. #define ctrl_to_ctx(__ctrl) \
  476. container_of((__ctrl)->handler, struct fimc_ctx, ctrls.handler)
  477. static int __fimc_s_ctrl(struct fimc_ctx *ctx, struct v4l2_ctrl *ctrl)
  478. {
  479. struct fimc_dev *fimc = ctx->fimc_dev;
  480. const struct fimc_variant *variant = fimc->variant;
  481. int ret = 0;
  482. if (ctrl->flags & V4L2_CTRL_FLAG_INACTIVE)
  483. return 0;
  484. switch (ctrl->id) {
  485. case V4L2_CID_HFLIP:
  486. ctx->hflip = ctrl->val;
  487. break;
  488. case V4L2_CID_VFLIP:
  489. ctx->vflip = ctrl->val;
  490. break;
  491. case V4L2_CID_ROTATE:
  492. if (fimc_capture_pending(fimc)) {
  493. ret = fimc_check_scaler_ratio(ctx, ctx->s_frame.width,
  494. ctx->s_frame.height, ctx->d_frame.width,
  495. ctx->d_frame.height, ctrl->val);
  496. if (ret)
  497. return -EINVAL;
  498. }
  499. if ((ctrl->val == 90 || ctrl->val == 270) &&
  500. !variant->has_out_rot)
  501. return -EINVAL;
  502. ctx->rotation = ctrl->val;
  503. break;
  504. case V4L2_CID_ALPHA_COMPONENT:
  505. ctx->d_frame.alpha = ctrl->val;
  506. break;
  507. case V4L2_CID_COLORFX:
  508. ret = fimc_set_color_effect(ctx, ctrl->val);
  509. if (ret)
  510. return ret;
  511. break;
  512. }
  513. ctx->state |= FIMC_PARAMS;
  514. set_bit(ST_CAPT_APPLY_CFG, &fimc->state);
  515. return 0;
  516. }
  517. static int fimc_s_ctrl(struct v4l2_ctrl *ctrl)
  518. {
  519. struct fimc_ctx *ctx = ctrl_to_ctx(ctrl);
  520. unsigned long flags;
  521. int ret;
  522. spin_lock_irqsave(&ctx->fimc_dev->slock, flags);
  523. ret = __fimc_s_ctrl(ctx, ctrl);
  524. spin_unlock_irqrestore(&ctx->fimc_dev->slock, flags);
  525. return ret;
  526. }
  527. static const struct v4l2_ctrl_ops fimc_ctrl_ops = {
  528. .s_ctrl = fimc_s_ctrl,
  529. };
  530. int fimc_ctrls_create(struct fimc_ctx *ctx)
  531. {
  532. unsigned int max_alpha = fimc_get_alpha_mask(ctx->d_frame.fmt);
  533. struct fimc_ctrls *ctrls = &ctx->ctrls;
  534. struct v4l2_ctrl_handler *handler = &ctrls->handler;
  535. if (ctx->ctrls.ready)
  536. return 0;
  537. v4l2_ctrl_handler_init(handler, 6);
  538. ctrls->rotate = v4l2_ctrl_new_std(handler, &fimc_ctrl_ops,
  539. V4L2_CID_ROTATE, 0, 270, 90, 0);
  540. ctrls->hflip = v4l2_ctrl_new_std(handler, &fimc_ctrl_ops,
  541. V4L2_CID_HFLIP, 0, 1, 1, 0);
  542. ctrls->vflip = v4l2_ctrl_new_std(handler, &fimc_ctrl_ops,
  543. V4L2_CID_VFLIP, 0, 1, 1, 0);
  544. if (ctx->fimc_dev->drv_data->alpha_color)
  545. ctrls->alpha = v4l2_ctrl_new_std(handler, &fimc_ctrl_ops,
  546. V4L2_CID_ALPHA_COMPONENT,
  547. 0, max_alpha, 1, 0);
  548. else
  549. ctrls->alpha = NULL;
  550. ctrls->colorfx = v4l2_ctrl_new_std_menu(handler, &fimc_ctrl_ops,
  551. V4L2_CID_COLORFX, V4L2_COLORFX_SET_CBCR,
  552. ~0x983f, V4L2_COLORFX_NONE);
  553. ctrls->colorfx_cbcr = v4l2_ctrl_new_std(handler, &fimc_ctrl_ops,
  554. V4L2_CID_COLORFX_CBCR, 0, 0xffff, 1, 0);
  555. ctx->effect.type = FIMC_REG_CIIMGEFF_FIN_BYPASS;
  556. if (!handler->error) {
  557. v4l2_ctrl_cluster(2, &ctrls->colorfx);
  558. ctrls->ready = true;
  559. }
  560. return handler->error;
  561. }
  562. void fimc_ctrls_delete(struct fimc_ctx *ctx)
  563. {
  564. struct fimc_ctrls *ctrls = &ctx->ctrls;
  565. if (ctrls->ready) {
  566. v4l2_ctrl_handler_free(&ctrls->handler);
  567. ctrls->ready = false;
  568. ctrls->alpha = NULL;
  569. }
  570. }
  571. void fimc_ctrls_activate(struct fimc_ctx *ctx, bool active)
  572. {
  573. unsigned int has_alpha = ctx->d_frame.fmt->flags & FMT_HAS_ALPHA;
  574. struct fimc_ctrls *ctrls = &ctx->ctrls;
  575. if (!ctrls->ready)
  576. return;
  577. mutex_lock(ctrls->handler.lock);
  578. v4l2_ctrl_activate(ctrls->rotate, active);
  579. v4l2_ctrl_activate(ctrls->hflip, active);
  580. v4l2_ctrl_activate(ctrls->vflip, active);
  581. v4l2_ctrl_activate(ctrls->colorfx, active);
  582. if (ctrls->alpha)
  583. v4l2_ctrl_activate(ctrls->alpha, active && has_alpha);
  584. if (active) {
  585. fimc_set_color_effect(ctx, ctrls->colorfx->cur.val);
  586. ctx->rotation = ctrls->rotate->val;
  587. ctx->hflip = ctrls->hflip->val;
  588. ctx->vflip = ctrls->vflip->val;
  589. } else {
  590. ctx->effect.type = FIMC_REG_CIIMGEFF_FIN_BYPASS;
  591. ctx->rotation = 0;
  592. ctx->hflip = 0;
  593. ctx->vflip = 0;
  594. }
  595. mutex_unlock(ctrls->handler.lock);
  596. }
  597. /* Update maximum value of the alpha color control */
  598. void fimc_alpha_ctrl_update(struct fimc_ctx *ctx)
  599. {
  600. struct fimc_dev *fimc = ctx->fimc_dev;
  601. struct v4l2_ctrl *ctrl = ctx->ctrls.alpha;
  602. if (ctrl == NULL || !fimc->drv_data->alpha_color)
  603. return;
  604. v4l2_ctrl_lock(ctrl);
  605. ctrl->maximum = fimc_get_alpha_mask(ctx->d_frame.fmt);
  606. if (ctrl->cur.val > ctrl->maximum)
  607. ctrl->cur.val = ctrl->maximum;
  608. v4l2_ctrl_unlock(ctrl);
  609. }
  610. void __fimc_get_format(struct fimc_frame *frame, struct v4l2_format *f)
  611. {
  612. struct v4l2_pix_format_mplane *pixm = &f->fmt.pix_mp;
  613. int i;
  614. pixm->width = frame->o_width;
  615. pixm->height = frame->o_height;
  616. pixm->field = V4L2_FIELD_NONE;
  617. pixm->pixelformat = frame->fmt->fourcc;
  618. pixm->colorspace = V4L2_COLORSPACE_JPEG;
  619. pixm->num_planes = frame->fmt->memplanes;
  620. for (i = 0; i < pixm->num_planes; ++i) {
  621. pixm->plane_fmt[i].bytesperline = frame->bytesperline[i];
  622. pixm->plane_fmt[i].sizeimage = frame->payload[i];
  623. }
  624. }
  625. /**
  626. * fimc_adjust_mplane_format - adjust bytesperline/sizeimage for each plane
  627. * @fmt: fimc pixel format description (input)
  628. * @width: requested pixel width
  629. * @height: requested pixel height
  630. * @pix: multi-plane format to adjust
  631. */
  632. void fimc_adjust_mplane_format(struct fimc_fmt *fmt, u32 width, u32 height,
  633. struct v4l2_pix_format_mplane *pix)
  634. {
  635. u32 bytesperline = 0;
  636. int i;
  637. pix->colorspace = V4L2_COLORSPACE_JPEG;
  638. pix->field = V4L2_FIELD_NONE;
  639. pix->num_planes = fmt->memplanes;
  640. pix->pixelformat = fmt->fourcc;
  641. pix->height = height;
  642. pix->width = width;
  643. for (i = 0; i < pix->num_planes; ++i) {
  644. struct v4l2_plane_pix_format *plane_fmt = &pix->plane_fmt[i];
  645. u32 bpl = plane_fmt->bytesperline;
  646. if (fmt->colplanes > 1 && (bpl == 0 || bpl < pix->width))
  647. bpl = pix->width; /* Planar */
  648. if (fmt->colplanes == 1 && /* Packed */
  649. (bpl == 0 || ((bpl * 8) / fmt->depth[i]) < pix->width))
  650. bpl = (pix->width * fmt->depth[0]) / 8;
  651. /*
  652. * Currently bytesperline for each plane is same, except
  653. * V4L2_PIX_FMT_YUV420M format. This calculation may need
  654. * to be changed when other multi-planar formats are added
  655. * to the fimc_formats[] array.
  656. */
  657. if (i == 0)
  658. bytesperline = bpl;
  659. else if (i == 1 && fmt->memplanes == 3)
  660. bytesperline /= 2;
  661. plane_fmt->bytesperline = bytesperline;
  662. plane_fmt->sizeimage = max((pix->width * pix->height *
  663. fmt->depth[i]) / 8, plane_fmt->sizeimage);
  664. }
  665. }
  666. /**
  667. * fimc_find_format - lookup fimc color format by fourcc or media bus format
  668. * @pixelformat: fourcc to match, ignored if null
  669. * @mbus_code: media bus code to match, ignored if null
  670. * @mask: the color flags to match
  671. * @index: offset in the fimc_formats array, ignored if negative
  672. */
  673. struct fimc_fmt *fimc_find_format(const u32 *pixelformat, const u32 *mbus_code,
  674. unsigned int mask, int index)
  675. {
  676. struct fimc_fmt *fmt, *def_fmt = NULL;
  677. unsigned int i;
  678. int id = 0;
  679. if (index >= (int)ARRAY_SIZE(fimc_formats))
  680. return NULL;
  681. for (i = 0; i < ARRAY_SIZE(fimc_formats); ++i) {
  682. fmt = &fimc_formats[i];
  683. if (!(fmt->flags & mask))
  684. continue;
  685. if (pixelformat && fmt->fourcc == *pixelformat)
  686. return fmt;
  687. if (mbus_code && fmt->mbus_code == *mbus_code)
  688. return fmt;
  689. if (index == id)
  690. def_fmt = fmt;
  691. id++;
  692. }
  693. return def_fmt;
  694. }
  695. static void fimc_clk_put(struct fimc_dev *fimc)
  696. {
  697. int i;
  698. for (i = 0; i < MAX_FIMC_CLOCKS; i++) {
  699. if (IS_ERR(fimc->clock[i]))
  700. continue;
  701. clk_unprepare(fimc->clock[i]);
  702. clk_put(fimc->clock[i]);
  703. fimc->clock[i] = ERR_PTR(-EINVAL);
  704. }
  705. }
  706. static int fimc_clk_get(struct fimc_dev *fimc)
  707. {
  708. int i, ret;
  709. for (i = 0; i < MAX_FIMC_CLOCKS; i++)
  710. fimc->clock[i] = ERR_PTR(-EINVAL);
  711. for (i = 0; i < MAX_FIMC_CLOCKS; i++) {
  712. fimc->clock[i] = clk_get(&fimc->pdev->dev, fimc_clocks[i]);
  713. if (IS_ERR(fimc->clock[i])) {
  714. ret = PTR_ERR(fimc->clock[i]);
  715. goto err;
  716. }
  717. ret = clk_prepare(fimc->clock[i]);
  718. if (ret < 0) {
  719. clk_put(fimc->clock[i]);
  720. fimc->clock[i] = ERR_PTR(-EINVAL);
  721. goto err;
  722. }
  723. }
  724. return 0;
  725. err:
  726. fimc_clk_put(fimc);
  727. dev_err(&fimc->pdev->dev, "failed to get clock: %s\n",
  728. fimc_clocks[i]);
  729. return -ENXIO;
  730. }
  731. #ifdef CONFIG_PM
  732. static int fimc_m2m_suspend(struct fimc_dev *fimc)
  733. {
  734. unsigned long flags;
  735. int timeout;
  736. spin_lock_irqsave(&fimc->slock, flags);
  737. if (!fimc_m2m_pending(fimc)) {
  738. spin_unlock_irqrestore(&fimc->slock, flags);
  739. return 0;
  740. }
  741. clear_bit(ST_M2M_SUSPENDED, &fimc->state);
  742. set_bit(ST_M2M_SUSPENDING, &fimc->state);
  743. spin_unlock_irqrestore(&fimc->slock, flags);
  744. timeout = wait_event_timeout(fimc->irq_queue,
  745. test_bit(ST_M2M_SUSPENDED, &fimc->state),
  746. FIMC_SHUTDOWN_TIMEOUT);
  747. clear_bit(ST_M2M_SUSPENDING, &fimc->state);
  748. return timeout == 0 ? -EAGAIN : 0;
  749. }
  750. static int fimc_m2m_resume(struct fimc_dev *fimc)
  751. {
  752. struct fimc_ctx *ctx;
  753. unsigned long flags;
  754. spin_lock_irqsave(&fimc->slock, flags);
  755. /* Clear for full H/W setup in first run after resume */
  756. ctx = fimc->m2m.ctx;
  757. fimc->m2m.ctx = NULL;
  758. spin_unlock_irqrestore(&fimc->slock, flags);
  759. if (test_and_clear_bit(ST_M2M_SUSPENDED, &fimc->state))
  760. fimc_m2m_job_finish(ctx, VB2_BUF_STATE_ERROR);
  761. return 0;
  762. }
  763. #endif /* CONFIG_PM */
  764. static const struct of_device_id fimc_of_match[];
  765. static int fimc_parse_dt(struct fimc_dev *fimc, u32 *clk_freq)
  766. {
  767. struct device *dev = &fimc->pdev->dev;
  768. struct device_node *node = dev->of_node;
  769. const struct of_device_id *of_id;
  770. struct fimc_variant *v;
  771. struct fimc_pix_limit *lim;
  772. u32 args[FIMC_PIX_LIMITS_MAX];
  773. int ret;
  774. if (of_property_read_bool(node, "samsung,lcd-wb"))
  775. return -ENODEV;
  776. v = devm_kzalloc(dev, sizeof(*v) + sizeof(*lim), GFP_KERNEL);
  777. if (!v)
  778. return -ENOMEM;
  779. of_id = of_match_node(fimc_of_match, node);
  780. if (!of_id)
  781. return -EINVAL;
  782. fimc->drv_data = of_id->data;
  783. ret = of_property_read_u32_array(node, "samsung,pix-limits",
  784. args, FIMC_PIX_LIMITS_MAX);
  785. if (ret < 0)
  786. return ret;
  787. lim = (struct fimc_pix_limit *)&v[1];
  788. lim->scaler_en_w = args[0];
  789. lim->scaler_dis_w = args[1];
  790. lim->out_rot_en_w = args[2];
  791. lim->out_rot_dis_w = args[3];
  792. v->pix_limit = lim;
  793. ret = of_property_read_u32_array(node, "samsung,min-pix-sizes",
  794. args, 2);
  795. v->min_inp_pixsize = ret ? FIMC_DEF_MIN_SIZE : args[0];
  796. v->min_out_pixsize = ret ? FIMC_DEF_MIN_SIZE : args[1];
  797. ret = of_property_read_u32_array(node, "samsung,min-pix-alignment",
  798. args, 2);
  799. v->min_vsize_align = ret ? FIMC_DEF_HEIGHT_ALIGN : args[0];
  800. v->hor_offs_align = ret ? FIMC_DEF_HOR_OFFS_ALIGN : args[1];
  801. ret = of_property_read_u32(node, "samsung,rotators", &args[1]);
  802. v->has_inp_rot = ret ? 1 : args[1] & 0x01;
  803. v->has_out_rot = ret ? 1 : args[1] & 0x10;
  804. v->has_mainscaler_ext = of_property_read_bool(node,
  805. "samsung,mainscaler-ext");
  806. v->has_isp_wb = of_property_read_bool(node, "samsung,isp-wb");
  807. v->has_cam_if = of_property_read_bool(node, "samsung,cam-if");
  808. of_property_read_u32(node, "clock-frequency", clk_freq);
  809. fimc->id = of_alias_get_id(node, "fimc");
  810. fimc->variant = v;
  811. return 0;
  812. }
  813. static int fimc_probe(struct platform_device *pdev)
  814. {
  815. struct device *dev = &pdev->dev;
  816. u32 lclk_freq = 0;
  817. struct fimc_dev *fimc;
  818. struct resource *res;
  819. int ret = 0;
  820. fimc = devm_kzalloc(dev, sizeof(*fimc), GFP_KERNEL);
  821. if (!fimc)
  822. return -ENOMEM;
  823. fimc->pdev = pdev;
  824. if (dev->of_node) {
  825. ret = fimc_parse_dt(fimc, &lclk_freq);
  826. if (ret < 0)
  827. return ret;
  828. } else {
  829. fimc->drv_data = fimc_get_drvdata(pdev);
  830. fimc->id = pdev->id;
  831. }
  832. if (!fimc->drv_data || fimc->id >= fimc->drv_data->num_entities ||
  833. fimc->id < 0) {
  834. dev_err(dev, "Invalid driver data or device id (%d)\n",
  835. fimc->id);
  836. return -EINVAL;
  837. }
  838. if (!dev->of_node)
  839. fimc->variant = fimc->drv_data->variant[fimc->id];
  840. init_waitqueue_head(&fimc->irq_queue);
  841. spin_lock_init(&fimc->slock);
  842. mutex_init(&fimc->lock);
  843. fimc->sysreg = fimc_get_sysreg_regmap(dev->of_node);
  844. if (IS_ERR(fimc->sysreg))
  845. return PTR_ERR(fimc->sysreg);
  846. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  847. fimc->regs = devm_ioremap_resource(dev, res);
  848. if (IS_ERR(fimc->regs))
  849. return PTR_ERR(fimc->regs);
  850. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  851. if (res == NULL) {
  852. dev_err(dev, "Failed to get IRQ resource\n");
  853. return -ENXIO;
  854. }
  855. ret = fimc_clk_get(fimc);
  856. if (ret)
  857. return ret;
  858. if (lclk_freq == 0)
  859. lclk_freq = fimc->drv_data->lclk_frequency;
  860. ret = clk_set_rate(fimc->clock[CLK_BUS], lclk_freq);
  861. if (ret < 0)
  862. return ret;
  863. ret = clk_enable(fimc->clock[CLK_BUS]);
  864. if (ret < 0)
  865. return ret;
  866. ret = devm_request_irq(dev, res->start, fimc_irq_handler,
  867. 0, dev_name(dev), fimc);
  868. if (ret < 0) {
  869. dev_err(dev, "failed to install irq (%d)\n", ret);
  870. goto err_sclk;
  871. }
  872. ret = fimc_initialize_capture_subdev(fimc);
  873. if (ret < 0)
  874. goto err_sclk;
  875. platform_set_drvdata(pdev, fimc);
  876. pm_runtime_enable(dev);
  877. if (!pm_runtime_enabled(dev)) {
  878. ret = clk_enable(fimc->clock[CLK_GATE]);
  879. if (ret < 0)
  880. goto err_sd;
  881. }
  882. /* Initialize contiguous memory allocator */
  883. fimc->alloc_ctx = vb2_dma_contig_init_ctx(dev);
  884. if (IS_ERR(fimc->alloc_ctx)) {
  885. ret = PTR_ERR(fimc->alloc_ctx);
  886. goto err_gclk;
  887. }
  888. dev_dbg(dev, "FIMC.%d registered successfully\n", fimc->id);
  889. return 0;
  890. err_gclk:
  891. if (!pm_runtime_enabled(dev))
  892. clk_disable(fimc->clock[CLK_GATE]);
  893. err_sd:
  894. fimc_unregister_capture_subdev(fimc);
  895. err_sclk:
  896. clk_disable(fimc->clock[CLK_BUS]);
  897. fimc_clk_put(fimc);
  898. return ret;
  899. }
  900. #ifdef CONFIG_PM
  901. static int fimc_runtime_resume(struct device *dev)
  902. {
  903. struct fimc_dev *fimc = dev_get_drvdata(dev);
  904. dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state);
  905. /* Enable clocks and perform basic initialization */
  906. clk_enable(fimc->clock[CLK_GATE]);
  907. fimc_hw_reset(fimc);
  908. /* Resume the capture or mem-to-mem device */
  909. if (fimc_capture_busy(fimc))
  910. return fimc_capture_resume(fimc);
  911. return fimc_m2m_resume(fimc);
  912. }
  913. static int fimc_runtime_suspend(struct device *dev)
  914. {
  915. struct fimc_dev *fimc = dev_get_drvdata(dev);
  916. int ret = 0;
  917. if (fimc_capture_busy(fimc))
  918. ret = fimc_capture_suspend(fimc);
  919. else
  920. ret = fimc_m2m_suspend(fimc);
  921. if (!ret)
  922. clk_disable(fimc->clock[CLK_GATE]);
  923. dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state);
  924. return ret;
  925. }
  926. #endif
  927. #ifdef CONFIG_PM_SLEEP
  928. static int fimc_resume(struct device *dev)
  929. {
  930. struct fimc_dev *fimc = dev_get_drvdata(dev);
  931. unsigned long flags;
  932. dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state);
  933. /* Do not resume if the device was idle before system suspend */
  934. spin_lock_irqsave(&fimc->slock, flags);
  935. if (!test_and_clear_bit(ST_LPM, &fimc->state) ||
  936. (!fimc_m2m_active(fimc) && !fimc_capture_busy(fimc))) {
  937. spin_unlock_irqrestore(&fimc->slock, flags);
  938. return 0;
  939. }
  940. fimc_hw_reset(fimc);
  941. spin_unlock_irqrestore(&fimc->slock, flags);
  942. if (fimc_capture_busy(fimc))
  943. return fimc_capture_resume(fimc);
  944. return fimc_m2m_resume(fimc);
  945. }
  946. static int fimc_suspend(struct device *dev)
  947. {
  948. struct fimc_dev *fimc = dev_get_drvdata(dev);
  949. dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state);
  950. if (test_and_set_bit(ST_LPM, &fimc->state))
  951. return 0;
  952. if (fimc_capture_busy(fimc))
  953. return fimc_capture_suspend(fimc);
  954. return fimc_m2m_suspend(fimc);
  955. }
  956. #endif /* CONFIG_PM_SLEEP */
  957. static int fimc_remove(struct platform_device *pdev)
  958. {
  959. struct fimc_dev *fimc = platform_get_drvdata(pdev);
  960. pm_runtime_disable(&pdev->dev);
  961. if (!pm_runtime_status_suspended(&pdev->dev))
  962. clk_disable(fimc->clock[CLK_GATE]);
  963. pm_runtime_set_suspended(&pdev->dev);
  964. fimc_unregister_capture_subdev(fimc);
  965. vb2_dma_contig_cleanup_ctx(fimc->alloc_ctx);
  966. clk_disable(fimc->clock[CLK_BUS]);
  967. fimc_clk_put(fimc);
  968. dev_info(&pdev->dev, "driver unloaded\n");
  969. return 0;
  970. }
  971. /* Image pixel limits, similar across several FIMC HW revisions. */
  972. static const struct fimc_pix_limit s5p_pix_limit[4] = {
  973. [0] = {
  974. .scaler_en_w = 3264,
  975. .scaler_dis_w = 8192,
  976. .out_rot_en_w = 1920,
  977. .out_rot_dis_w = 4224,
  978. },
  979. [1] = {
  980. .scaler_en_w = 4224,
  981. .scaler_dis_w = 8192,
  982. .out_rot_en_w = 1920,
  983. .out_rot_dis_w = 4224,
  984. },
  985. [2] = {
  986. .scaler_en_w = 1920,
  987. .scaler_dis_w = 8192,
  988. .out_rot_en_w = 1280,
  989. .out_rot_dis_w = 1920,
  990. },
  991. };
  992. static const struct fimc_variant fimc0_variant_s5p = {
  993. .has_inp_rot = 1,
  994. .has_out_rot = 1,
  995. .has_cam_if = 1,
  996. .min_inp_pixsize = 16,
  997. .min_out_pixsize = 16,
  998. .hor_offs_align = 8,
  999. .min_vsize_align = 16,
  1000. .pix_limit = &s5p_pix_limit[0],
  1001. };
  1002. static const struct fimc_variant fimc2_variant_s5p = {
  1003. .has_cam_if = 1,
  1004. .min_inp_pixsize = 16,
  1005. .min_out_pixsize = 16,
  1006. .hor_offs_align = 8,
  1007. .min_vsize_align = 16,
  1008. .pix_limit = &s5p_pix_limit[1],
  1009. };
  1010. static const struct fimc_variant fimc0_variant_s5pv210 = {
  1011. .has_inp_rot = 1,
  1012. .has_out_rot = 1,
  1013. .has_cam_if = 1,
  1014. .min_inp_pixsize = 16,
  1015. .min_out_pixsize = 16,
  1016. .hor_offs_align = 8,
  1017. .min_vsize_align = 16,
  1018. .pix_limit = &s5p_pix_limit[1],
  1019. };
  1020. static const struct fimc_variant fimc1_variant_s5pv210 = {
  1021. .has_inp_rot = 1,
  1022. .has_out_rot = 1,
  1023. .has_cam_if = 1,
  1024. .has_mainscaler_ext = 1,
  1025. .min_inp_pixsize = 16,
  1026. .min_out_pixsize = 16,
  1027. .hor_offs_align = 1,
  1028. .min_vsize_align = 1,
  1029. .pix_limit = &s5p_pix_limit[2],
  1030. };
  1031. static const struct fimc_variant fimc2_variant_s5pv210 = {
  1032. .has_cam_if = 1,
  1033. .min_inp_pixsize = 16,
  1034. .min_out_pixsize = 16,
  1035. .hor_offs_align = 8,
  1036. .min_vsize_align = 16,
  1037. .pix_limit = &s5p_pix_limit[2],
  1038. };
  1039. /* S5PC100 */
  1040. static const struct fimc_drvdata fimc_drvdata_s5p = {
  1041. .variant = {
  1042. [0] = &fimc0_variant_s5p,
  1043. [1] = &fimc0_variant_s5p,
  1044. [2] = &fimc2_variant_s5p,
  1045. },
  1046. .num_entities = 3,
  1047. .lclk_frequency = 133000000UL,
  1048. .out_buf_count = 4,
  1049. };
  1050. /* S5PV210, S5PC110 */
  1051. static const struct fimc_drvdata fimc_drvdata_s5pv210 = {
  1052. .variant = {
  1053. [0] = &fimc0_variant_s5pv210,
  1054. [1] = &fimc1_variant_s5pv210,
  1055. [2] = &fimc2_variant_s5pv210,
  1056. },
  1057. .num_entities = 3,
  1058. .lclk_frequency = 166000000UL,
  1059. .out_buf_count = 4,
  1060. .dma_pix_hoff = 1,
  1061. };
  1062. /* EXYNOS4210, S5PV310, S5PC210 */
  1063. static const struct fimc_drvdata fimc_drvdata_exynos4210 = {
  1064. .num_entities = 4,
  1065. .lclk_frequency = 166000000UL,
  1066. .dma_pix_hoff = 1,
  1067. .cistatus2 = 1,
  1068. .alpha_color = 1,
  1069. .out_buf_count = 32,
  1070. };
  1071. /* EXYNOS4212, EXYNOS4412 */
  1072. static const struct fimc_drvdata fimc_drvdata_exynos4x12 = {
  1073. .num_entities = 4,
  1074. .lclk_frequency = 166000000UL,
  1075. .dma_pix_hoff = 1,
  1076. .cistatus2 = 1,
  1077. .alpha_color = 1,
  1078. .out_buf_count = 32,
  1079. };
  1080. static const struct platform_device_id fimc_driver_ids[] = {
  1081. {
  1082. .name = "s5p-fimc",
  1083. .driver_data = (unsigned long)&fimc_drvdata_s5p,
  1084. }, {
  1085. .name = "s5pv210-fimc",
  1086. .driver_data = (unsigned long)&fimc_drvdata_s5pv210,
  1087. }, {
  1088. .name = "exynos4-fimc",
  1089. .driver_data = (unsigned long)&fimc_drvdata_exynos4210,
  1090. }, {
  1091. .name = "exynos4x12-fimc",
  1092. .driver_data = (unsigned long)&fimc_drvdata_exynos4x12,
  1093. },
  1094. { },
  1095. };
  1096. static const struct of_device_id fimc_of_match[] = {
  1097. {
  1098. .compatible = "samsung,s5pv210-fimc",
  1099. .data = &fimc_drvdata_s5pv210,
  1100. }, {
  1101. .compatible = "samsung,exynos4210-fimc",
  1102. .data = &fimc_drvdata_exynos4210,
  1103. }, {
  1104. .compatible = "samsung,exynos4212-fimc",
  1105. .data = &fimc_drvdata_exynos4x12,
  1106. },
  1107. { /* sentinel */ },
  1108. };
  1109. static const struct dev_pm_ops fimc_pm_ops = {
  1110. SET_SYSTEM_SLEEP_PM_OPS(fimc_suspend, fimc_resume)
  1111. SET_RUNTIME_PM_OPS(fimc_runtime_suspend, fimc_runtime_resume, NULL)
  1112. };
  1113. static struct platform_driver fimc_driver = {
  1114. .probe = fimc_probe,
  1115. .remove = fimc_remove,
  1116. .id_table = fimc_driver_ids,
  1117. .driver = {
  1118. .of_match_table = fimc_of_match,
  1119. .name = FIMC_DRIVER_NAME,
  1120. .pm = &fimc_pm_ops,
  1121. }
  1122. };
  1123. int __init fimc_register_driver(void)
  1124. {
  1125. return platform_driver_register(&fimc_driver);
  1126. }
  1127. void __exit fimc_unregister_driver(void)
  1128. {
  1129. platform_driver_unregister(&fimc_driver);
  1130. }