fimc-core.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  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. u32 sizeimage;
  647. if (fmt->colplanes > 1 && (bpl == 0 || bpl < pix->width))
  648. bpl = pix->width; /* Planar */
  649. if (fmt->colplanes == 1 && /* Packed */
  650. (bpl == 0 || ((bpl * 8) / fmt->depth[i]) < pix->width))
  651. bpl = (pix->width * fmt->depth[0]) / 8;
  652. /*
  653. * Currently bytesperline for each plane is same, except
  654. * V4L2_PIX_FMT_YUV420M format. This calculation may need
  655. * to be changed when other multi-planar formats are added
  656. * to the fimc_formats[] array.
  657. */
  658. if (i == 0)
  659. bytesperline = bpl;
  660. else if (i == 1 && fmt->memplanes == 3)
  661. bytesperline /= 2;
  662. plane_fmt->bytesperline = bytesperline;
  663. sizeimage = pix->width * pix->height * fmt->depth[i] / 8;
  664. /* Ensure full last row for tiled formats */
  665. if (tiled_fmt(fmt)) {
  666. /* 64 * 32 * plane_fmt->bytesperline / 64 */
  667. u32 row_size = plane_fmt->bytesperline * 32;
  668. sizeimage = roundup(sizeimage, row_size);
  669. }
  670. plane_fmt->sizeimage = max(sizeimage, plane_fmt->sizeimage);
  671. }
  672. }
  673. /**
  674. * fimc_find_format - lookup fimc color format by fourcc or media bus format
  675. * @pixelformat: fourcc to match, ignored if null
  676. * @mbus_code: media bus code to match, ignored if null
  677. * @mask: the color flags to match
  678. * @index: offset in the fimc_formats array, ignored if negative
  679. */
  680. struct fimc_fmt *fimc_find_format(const u32 *pixelformat, const u32 *mbus_code,
  681. unsigned int mask, int index)
  682. {
  683. struct fimc_fmt *fmt, *def_fmt = NULL;
  684. unsigned int i;
  685. int id = 0;
  686. if (index >= (int)ARRAY_SIZE(fimc_formats))
  687. return NULL;
  688. for (i = 0; i < ARRAY_SIZE(fimc_formats); ++i) {
  689. fmt = &fimc_formats[i];
  690. if (!(fmt->flags & mask))
  691. continue;
  692. if (pixelformat && fmt->fourcc == *pixelformat)
  693. return fmt;
  694. if (mbus_code && fmt->mbus_code == *mbus_code)
  695. return fmt;
  696. if (index == id)
  697. def_fmt = fmt;
  698. id++;
  699. }
  700. return def_fmt;
  701. }
  702. static void fimc_clk_put(struct fimc_dev *fimc)
  703. {
  704. int i;
  705. for (i = 0; i < MAX_FIMC_CLOCKS; i++) {
  706. if (IS_ERR(fimc->clock[i]))
  707. continue;
  708. clk_unprepare(fimc->clock[i]);
  709. clk_put(fimc->clock[i]);
  710. fimc->clock[i] = ERR_PTR(-EINVAL);
  711. }
  712. }
  713. static int fimc_clk_get(struct fimc_dev *fimc)
  714. {
  715. int i, ret;
  716. for (i = 0; i < MAX_FIMC_CLOCKS; i++)
  717. fimc->clock[i] = ERR_PTR(-EINVAL);
  718. for (i = 0; i < MAX_FIMC_CLOCKS; i++) {
  719. fimc->clock[i] = clk_get(&fimc->pdev->dev, fimc_clocks[i]);
  720. if (IS_ERR(fimc->clock[i])) {
  721. ret = PTR_ERR(fimc->clock[i]);
  722. goto err;
  723. }
  724. ret = clk_prepare(fimc->clock[i]);
  725. if (ret < 0) {
  726. clk_put(fimc->clock[i]);
  727. fimc->clock[i] = ERR_PTR(-EINVAL);
  728. goto err;
  729. }
  730. }
  731. return 0;
  732. err:
  733. fimc_clk_put(fimc);
  734. dev_err(&fimc->pdev->dev, "failed to get clock: %s\n",
  735. fimc_clocks[i]);
  736. return -ENXIO;
  737. }
  738. #ifdef CONFIG_PM
  739. static int fimc_m2m_suspend(struct fimc_dev *fimc)
  740. {
  741. unsigned long flags;
  742. int timeout;
  743. spin_lock_irqsave(&fimc->slock, flags);
  744. if (!fimc_m2m_pending(fimc)) {
  745. spin_unlock_irqrestore(&fimc->slock, flags);
  746. return 0;
  747. }
  748. clear_bit(ST_M2M_SUSPENDED, &fimc->state);
  749. set_bit(ST_M2M_SUSPENDING, &fimc->state);
  750. spin_unlock_irqrestore(&fimc->slock, flags);
  751. timeout = wait_event_timeout(fimc->irq_queue,
  752. test_bit(ST_M2M_SUSPENDED, &fimc->state),
  753. FIMC_SHUTDOWN_TIMEOUT);
  754. clear_bit(ST_M2M_SUSPENDING, &fimc->state);
  755. return timeout == 0 ? -EAGAIN : 0;
  756. }
  757. static int fimc_m2m_resume(struct fimc_dev *fimc)
  758. {
  759. struct fimc_ctx *ctx;
  760. unsigned long flags;
  761. spin_lock_irqsave(&fimc->slock, flags);
  762. /* Clear for full H/W setup in first run after resume */
  763. ctx = fimc->m2m.ctx;
  764. fimc->m2m.ctx = NULL;
  765. spin_unlock_irqrestore(&fimc->slock, flags);
  766. if (test_and_clear_bit(ST_M2M_SUSPENDED, &fimc->state))
  767. fimc_m2m_job_finish(ctx, VB2_BUF_STATE_ERROR);
  768. return 0;
  769. }
  770. #endif /* CONFIG_PM */
  771. static const struct of_device_id fimc_of_match[];
  772. static int fimc_parse_dt(struct fimc_dev *fimc, u32 *clk_freq)
  773. {
  774. struct device *dev = &fimc->pdev->dev;
  775. struct device_node *node = dev->of_node;
  776. const struct of_device_id *of_id;
  777. struct fimc_variant *v;
  778. struct fimc_pix_limit *lim;
  779. u32 args[FIMC_PIX_LIMITS_MAX];
  780. int ret;
  781. if (of_property_read_bool(node, "samsung,lcd-wb"))
  782. return -ENODEV;
  783. v = devm_kzalloc(dev, sizeof(*v) + sizeof(*lim), GFP_KERNEL);
  784. if (!v)
  785. return -ENOMEM;
  786. of_id = of_match_node(fimc_of_match, node);
  787. if (!of_id)
  788. return -EINVAL;
  789. fimc->drv_data = of_id->data;
  790. ret = of_property_read_u32_array(node, "samsung,pix-limits",
  791. args, FIMC_PIX_LIMITS_MAX);
  792. if (ret < 0)
  793. return ret;
  794. lim = (struct fimc_pix_limit *)&v[1];
  795. lim->scaler_en_w = args[0];
  796. lim->scaler_dis_w = args[1];
  797. lim->out_rot_en_w = args[2];
  798. lim->out_rot_dis_w = args[3];
  799. v->pix_limit = lim;
  800. ret = of_property_read_u32_array(node, "samsung,min-pix-sizes",
  801. args, 2);
  802. v->min_inp_pixsize = ret ? FIMC_DEF_MIN_SIZE : args[0];
  803. v->min_out_pixsize = ret ? FIMC_DEF_MIN_SIZE : args[1];
  804. ret = of_property_read_u32_array(node, "samsung,min-pix-alignment",
  805. args, 2);
  806. v->min_vsize_align = ret ? FIMC_DEF_HEIGHT_ALIGN : args[0];
  807. v->hor_offs_align = ret ? FIMC_DEF_HOR_OFFS_ALIGN : args[1];
  808. ret = of_property_read_u32(node, "samsung,rotators", &args[1]);
  809. v->has_inp_rot = ret ? 1 : args[1] & 0x01;
  810. v->has_out_rot = ret ? 1 : args[1] & 0x10;
  811. v->has_mainscaler_ext = of_property_read_bool(node,
  812. "samsung,mainscaler-ext");
  813. v->has_isp_wb = of_property_read_bool(node, "samsung,isp-wb");
  814. v->has_cam_if = of_property_read_bool(node, "samsung,cam-if");
  815. of_property_read_u32(node, "clock-frequency", clk_freq);
  816. fimc->id = of_alias_get_id(node, "fimc");
  817. fimc->variant = v;
  818. return 0;
  819. }
  820. static int fimc_probe(struct platform_device *pdev)
  821. {
  822. struct device *dev = &pdev->dev;
  823. u32 lclk_freq = 0;
  824. struct fimc_dev *fimc;
  825. struct resource *res;
  826. int ret = 0;
  827. fimc = devm_kzalloc(dev, sizeof(*fimc), GFP_KERNEL);
  828. if (!fimc)
  829. return -ENOMEM;
  830. fimc->pdev = pdev;
  831. if (dev->of_node) {
  832. ret = fimc_parse_dt(fimc, &lclk_freq);
  833. if (ret < 0)
  834. return ret;
  835. } else {
  836. fimc->drv_data = fimc_get_drvdata(pdev);
  837. fimc->id = pdev->id;
  838. }
  839. if (!fimc->drv_data || fimc->id >= fimc->drv_data->num_entities ||
  840. fimc->id < 0) {
  841. dev_err(dev, "Invalid driver data or device id (%d)\n",
  842. fimc->id);
  843. return -EINVAL;
  844. }
  845. if (!dev->of_node)
  846. fimc->variant = fimc->drv_data->variant[fimc->id];
  847. init_waitqueue_head(&fimc->irq_queue);
  848. spin_lock_init(&fimc->slock);
  849. mutex_init(&fimc->lock);
  850. fimc->sysreg = fimc_get_sysreg_regmap(dev->of_node);
  851. if (IS_ERR(fimc->sysreg))
  852. return PTR_ERR(fimc->sysreg);
  853. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  854. fimc->regs = devm_ioremap_resource(dev, res);
  855. if (IS_ERR(fimc->regs))
  856. return PTR_ERR(fimc->regs);
  857. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  858. if (res == NULL) {
  859. dev_err(dev, "Failed to get IRQ resource\n");
  860. return -ENXIO;
  861. }
  862. ret = fimc_clk_get(fimc);
  863. if (ret)
  864. return ret;
  865. if (lclk_freq == 0)
  866. lclk_freq = fimc->drv_data->lclk_frequency;
  867. ret = clk_set_rate(fimc->clock[CLK_BUS], lclk_freq);
  868. if (ret < 0)
  869. return ret;
  870. ret = clk_enable(fimc->clock[CLK_BUS]);
  871. if (ret < 0)
  872. return ret;
  873. ret = devm_request_irq(dev, res->start, fimc_irq_handler,
  874. 0, dev_name(dev), fimc);
  875. if (ret < 0) {
  876. dev_err(dev, "failed to install irq (%d)\n", ret);
  877. goto err_sclk;
  878. }
  879. ret = fimc_initialize_capture_subdev(fimc);
  880. if (ret < 0)
  881. goto err_sclk;
  882. platform_set_drvdata(pdev, fimc);
  883. pm_runtime_enable(dev);
  884. if (!pm_runtime_enabled(dev)) {
  885. ret = clk_enable(fimc->clock[CLK_GATE]);
  886. if (ret < 0)
  887. goto err_sd;
  888. }
  889. vb2_dma_contig_set_max_seg_size(dev, DMA_BIT_MASK(32));
  890. dev_dbg(dev, "FIMC.%d registered successfully\n", fimc->id);
  891. return 0;
  892. err_sd:
  893. fimc_unregister_capture_subdev(fimc);
  894. err_sclk:
  895. clk_disable(fimc->clock[CLK_BUS]);
  896. fimc_clk_put(fimc);
  897. return ret;
  898. }
  899. #ifdef CONFIG_PM
  900. static int fimc_runtime_resume(struct device *dev)
  901. {
  902. struct fimc_dev *fimc = dev_get_drvdata(dev);
  903. dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state);
  904. /* Enable clocks and perform basic initialization */
  905. clk_enable(fimc->clock[CLK_GATE]);
  906. fimc_hw_reset(fimc);
  907. /* Resume the capture or mem-to-mem device */
  908. if (fimc_capture_busy(fimc))
  909. return fimc_capture_resume(fimc);
  910. return fimc_m2m_resume(fimc);
  911. }
  912. static int fimc_runtime_suspend(struct device *dev)
  913. {
  914. struct fimc_dev *fimc = dev_get_drvdata(dev);
  915. int ret = 0;
  916. if (fimc_capture_busy(fimc))
  917. ret = fimc_capture_suspend(fimc);
  918. else
  919. ret = fimc_m2m_suspend(fimc);
  920. if (!ret)
  921. clk_disable(fimc->clock[CLK_GATE]);
  922. dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state);
  923. return ret;
  924. }
  925. #endif
  926. #ifdef CONFIG_PM_SLEEP
  927. static int fimc_resume(struct device *dev)
  928. {
  929. struct fimc_dev *fimc = dev_get_drvdata(dev);
  930. unsigned long flags;
  931. dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state);
  932. /* Do not resume if the device was idle before system suspend */
  933. spin_lock_irqsave(&fimc->slock, flags);
  934. if (!test_and_clear_bit(ST_LPM, &fimc->state) ||
  935. (!fimc_m2m_active(fimc) && !fimc_capture_busy(fimc))) {
  936. spin_unlock_irqrestore(&fimc->slock, flags);
  937. return 0;
  938. }
  939. fimc_hw_reset(fimc);
  940. spin_unlock_irqrestore(&fimc->slock, flags);
  941. if (fimc_capture_busy(fimc))
  942. return fimc_capture_resume(fimc);
  943. return fimc_m2m_resume(fimc);
  944. }
  945. static int fimc_suspend(struct device *dev)
  946. {
  947. struct fimc_dev *fimc = dev_get_drvdata(dev);
  948. dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state);
  949. if (test_and_set_bit(ST_LPM, &fimc->state))
  950. return 0;
  951. if (fimc_capture_busy(fimc))
  952. return fimc_capture_suspend(fimc);
  953. return fimc_m2m_suspend(fimc);
  954. }
  955. #endif /* CONFIG_PM_SLEEP */
  956. static int fimc_remove(struct platform_device *pdev)
  957. {
  958. struct fimc_dev *fimc = platform_get_drvdata(pdev);
  959. pm_runtime_disable(&pdev->dev);
  960. if (!pm_runtime_status_suspended(&pdev->dev))
  961. clk_disable(fimc->clock[CLK_GATE]);
  962. pm_runtime_set_suspended(&pdev->dev);
  963. fimc_unregister_capture_subdev(fimc);
  964. vb2_dma_contig_clear_max_seg_size(&pdev->dev);
  965. clk_disable(fimc->clock[CLK_BUS]);
  966. fimc_clk_put(fimc);
  967. dev_info(&pdev->dev, "driver unloaded\n");
  968. return 0;
  969. }
  970. /* Image pixel limits, similar across several FIMC HW revisions. */
  971. static const struct fimc_pix_limit s5p_pix_limit[4] = {
  972. [0] = {
  973. .scaler_en_w = 3264,
  974. .scaler_dis_w = 8192,
  975. .out_rot_en_w = 1920,
  976. .out_rot_dis_w = 4224,
  977. },
  978. [1] = {
  979. .scaler_en_w = 4224,
  980. .scaler_dis_w = 8192,
  981. .out_rot_en_w = 1920,
  982. .out_rot_dis_w = 4224,
  983. },
  984. [2] = {
  985. .scaler_en_w = 1920,
  986. .scaler_dis_w = 8192,
  987. .out_rot_en_w = 1280,
  988. .out_rot_dis_w = 1920,
  989. },
  990. };
  991. static const struct fimc_variant fimc0_variant_s5pv210 = {
  992. .has_inp_rot = 1,
  993. .has_out_rot = 1,
  994. .has_cam_if = 1,
  995. .min_inp_pixsize = 16,
  996. .min_out_pixsize = 16,
  997. .hor_offs_align = 8,
  998. .min_vsize_align = 16,
  999. .pix_limit = &s5p_pix_limit[1],
  1000. };
  1001. static const struct fimc_variant fimc1_variant_s5pv210 = {
  1002. .has_inp_rot = 1,
  1003. .has_out_rot = 1,
  1004. .has_cam_if = 1,
  1005. .has_mainscaler_ext = 1,
  1006. .min_inp_pixsize = 16,
  1007. .min_out_pixsize = 16,
  1008. .hor_offs_align = 1,
  1009. .min_vsize_align = 1,
  1010. .pix_limit = &s5p_pix_limit[2],
  1011. };
  1012. static const struct fimc_variant fimc2_variant_s5pv210 = {
  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[2],
  1019. };
  1020. /* S5PV210, S5PC110 */
  1021. static const struct fimc_drvdata fimc_drvdata_s5pv210 = {
  1022. .variant = {
  1023. [0] = &fimc0_variant_s5pv210,
  1024. [1] = &fimc1_variant_s5pv210,
  1025. [2] = &fimc2_variant_s5pv210,
  1026. },
  1027. .num_entities = 3,
  1028. .lclk_frequency = 166000000UL,
  1029. .out_buf_count = 4,
  1030. .dma_pix_hoff = 1,
  1031. };
  1032. /* EXYNOS4210, S5PV310, S5PC210 */
  1033. static const struct fimc_drvdata fimc_drvdata_exynos4210 = {
  1034. .num_entities = 4,
  1035. .lclk_frequency = 166000000UL,
  1036. .dma_pix_hoff = 1,
  1037. .cistatus2 = 1,
  1038. .alpha_color = 1,
  1039. .out_buf_count = 32,
  1040. };
  1041. /* EXYNOS4212, EXYNOS4412 */
  1042. static const struct fimc_drvdata fimc_drvdata_exynos4x12 = {
  1043. .num_entities = 4,
  1044. .lclk_frequency = 166000000UL,
  1045. .dma_pix_hoff = 1,
  1046. .cistatus2 = 1,
  1047. .alpha_color = 1,
  1048. .out_buf_count = 32,
  1049. };
  1050. static const struct of_device_id fimc_of_match[] = {
  1051. {
  1052. .compatible = "samsung,s5pv210-fimc",
  1053. .data = &fimc_drvdata_s5pv210,
  1054. }, {
  1055. .compatible = "samsung,exynos4210-fimc",
  1056. .data = &fimc_drvdata_exynos4210,
  1057. }, {
  1058. .compatible = "samsung,exynos4212-fimc",
  1059. .data = &fimc_drvdata_exynos4x12,
  1060. },
  1061. { /* sentinel */ },
  1062. };
  1063. static const struct dev_pm_ops fimc_pm_ops = {
  1064. SET_SYSTEM_SLEEP_PM_OPS(fimc_suspend, fimc_resume)
  1065. SET_RUNTIME_PM_OPS(fimc_runtime_suspend, fimc_runtime_resume, NULL)
  1066. };
  1067. static struct platform_driver fimc_driver = {
  1068. .probe = fimc_probe,
  1069. .remove = fimc_remove,
  1070. .driver = {
  1071. .of_match_table = fimc_of_match,
  1072. .name = FIMC_DRIVER_NAME,
  1073. .pm = &fimc_pm_ops,
  1074. }
  1075. };
  1076. int __init fimc_register_driver(void)
  1077. {
  1078. return platform_driver_register(&fimc_driver);
  1079. }
  1080. void __exit fimc_unregister_driver(void)
  1081. {
  1082. platform_driver_unregister(&fimc_driver);
  1083. }