1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2012 Samsung Electronics Co.Ltd
5 * Eunchul Kim <chulspro.kim@samsung.com>
6 * Jinyoung Jeon <jy0.jeon@samsung.com>
7 * Sangmin Lee <lsmin.lee@samsung.com>
10 #include <linux/clk.h>
11 #include <linux/component.h>
12 #include <linux/kernel.h>
13 #include <linux/mfd/syscon.h>
15 #include <linux/platform_device.h>
16 #include <linux/pm_runtime.h>
17 #include <linux/regmap.h>
18 #include <linux/spinlock.h>
20 #include <drm/exynos_drm.h>
22 #include "exynos_drm_drv.h"
23 #include "exynos_drm_ipp.h"
24 #include "regs-fimc.h"
27 * FIMC stands for Fully Interactive Mobile Camera and
28 * supports image scaler/rotator and input/output DMA operations.
29 * input DMA reads image data from the memory.
30 * output DMA writes image data to memory.
31 * FIMC supports image rotation and image effect functions.
34 #define FIMC_MAX_DEVS 4
35 #define FIMC_MAX_SRC 2
36 #define FIMC_MAX_DST 32
37 #define FIMC_SHFACTOR 10
38 #define FIMC_BUF_STOP 1
39 #define FIMC_BUF_START 2
40 #define FIMC_WIDTH_ITU_709 1280
41 #define FIMC_AUTOSUSPEND_DELAY 2000
43 static unsigned int fimc_mask = 0xc;
44 module_param_named(fimc_devs, fimc_mask, uint, 0644);
45 MODULE_PARM_DESC(fimc_devs, "Alias mask for assigning FIMC devices to Exynos DRM");
47 #define get_fimc_context(dev) dev_get_drvdata(dev)
57 static const char * const fimc_clock_names[] = {
58 [FIMC_CLK_LCLK] = "sclk_fimc",
59 [FIMC_CLK_GATE] = "fimc",
60 [FIMC_CLK_WB_A] = "pxl_async0",
61 [FIMC_CLK_WB_B] = "pxl_async1",
65 * A structure of scaler.
67 * @range: narrow, wide.
68 * @bypass: unused scaler path.
69 * @up_h: horizontal scale up.
70 * @up_v: vertical scale up.
71 * @hratio: horizontal ratio.
72 * @vratio: vertical ratio.
84 * A structure of fimc context.
86 * @regs_res: register resources.
87 * @regs: memory mapped io registers.
88 * @lock: locking of operations.
89 * @clocks: fimc clocks.
90 * @sc: scaler infomations.
91 * @pol: porarity of writeback.
96 struct exynos_drm_ipp ipp;
97 struct drm_device *drm_dev;
99 struct exynos_drm_ipp_task *task;
100 struct exynos_drm_ipp_formats *formats;
101 unsigned int num_formats;
103 struct resource *regs_res;
106 struct clk *clocks[FIMC_CLKS_MAX];
107 struct fimc_scaler sc;
112 static u32 fimc_read(struct fimc_context *ctx, u32 reg)
114 return readl(ctx->regs + reg);
117 static void fimc_write(struct fimc_context *ctx, u32 val, u32 reg)
119 writel(val, ctx->regs + reg);
122 static void fimc_set_bits(struct fimc_context *ctx, u32 reg, u32 bits)
124 void __iomem *r = ctx->regs + reg;
126 writel(readl(r) | bits, r);
129 static void fimc_clear_bits(struct fimc_context *ctx, u32 reg, u32 bits)
131 void __iomem *r = ctx->regs + reg;
133 writel(readl(r) & ~bits, r);
136 static void fimc_sw_reset(struct fimc_context *ctx)
140 /* stop dma operation */
141 cfg = fimc_read(ctx, EXYNOS_CISTATUS);
142 if (EXYNOS_CISTATUS_GET_ENVID_STATUS(cfg))
143 fimc_clear_bits(ctx, EXYNOS_MSCTRL, EXYNOS_MSCTRL_ENVID);
145 fimc_set_bits(ctx, EXYNOS_CISRCFMT, EXYNOS_CISRCFMT_ITU601_8BIT);
147 /* disable image capture */
148 fimc_clear_bits(ctx, EXYNOS_CIIMGCPT,
149 EXYNOS_CIIMGCPT_IMGCPTEN_SC | EXYNOS_CIIMGCPT_IMGCPTEN);
152 fimc_set_bits(ctx, EXYNOS_CIGCTRL, EXYNOS_CIGCTRL_SWRST);
154 /* s/w reset complete */
155 fimc_clear_bits(ctx, EXYNOS_CIGCTRL, EXYNOS_CIGCTRL_SWRST);
158 fimc_write(ctx, 0x0, EXYNOS_CIFCNTSEQ);
161 static void fimc_set_type_ctrl(struct fimc_context *ctx)
165 cfg = fimc_read(ctx, EXYNOS_CIGCTRL);
166 cfg &= ~(EXYNOS_CIGCTRL_TESTPATTERN_MASK |
167 EXYNOS_CIGCTRL_SELCAM_ITU_MASK |
168 EXYNOS_CIGCTRL_SELCAM_MIPI_MASK |
169 EXYNOS_CIGCTRL_SELCAM_FIMC_MASK |
170 EXYNOS_CIGCTRL_SELWB_CAMIF_MASK |
171 EXYNOS_CIGCTRL_SELWRITEBACK_MASK);
173 cfg |= (EXYNOS_CIGCTRL_SELCAM_ITU_A |
174 EXYNOS_CIGCTRL_SELWRITEBACK_A |
175 EXYNOS_CIGCTRL_SELCAM_MIPI_A |
176 EXYNOS_CIGCTRL_SELCAM_FIMC_ITU);
178 fimc_write(ctx, cfg, EXYNOS_CIGCTRL);
181 static void fimc_handle_jpeg(struct fimc_context *ctx, bool enable)
185 DRM_DEV_DEBUG_KMS(ctx->dev, "enable[%d]\n", enable);
187 cfg = fimc_read(ctx, EXYNOS_CIGCTRL);
189 cfg |= EXYNOS_CIGCTRL_CAM_JPEG;
191 cfg &= ~EXYNOS_CIGCTRL_CAM_JPEG;
193 fimc_write(ctx, cfg, EXYNOS_CIGCTRL);
196 static void fimc_mask_irq(struct fimc_context *ctx, bool enable)
200 DRM_DEV_DEBUG_KMS(ctx->dev, "enable[%d]\n", enable);
202 cfg = fimc_read(ctx, EXYNOS_CIGCTRL);
204 cfg &= ~EXYNOS_CIGCTRL_IRQ_OVFEN;
205 cfg |= EXYNOS_CIGCTRL_IRQ_ENABLE | EXYNOS_CIGCTRL_IRQ_LEVEL;
207 cfg &= ~EXYNOS_CIGCTRL_IRQ_ENABLE;
208 fimc_write(ctx, cfg, EXYNOS_CIGCTRL);
211 static void fimc_clear_irq(struct fimc_context *ctx)
213 fimc_set_bits(ctx, EXYNOS_CIGCTRL, EXYNOS_CIGCTRL_IRQ_CLR);
216 static bool fimc_check_ovf(struct fimc_context *ctx)
220 status = fimc_read(ctx, EXYNOS_CISTATUS);
221 flag = EXYNOS_CISTATUS_OVFIY | EXYNOS_CISTATUS_OVFICB |
222 EXYNOS_CISTATUS_OVFICR;
224 DRM_DEV_DEBUG_KMS(ctx->dev, "flag[0x%x]\n", flag);
227 fimc_set_bits(ctx, EXYNOS_CIWDOFST,
228 EXYNOS_CIWDOFST_CLROVFIY | EXYNOS_CIWDOFST_CLROVFICB |
229 EXYNOS_CIWDOFST_CLROVFICR);
231 DRM_DEV_ERROR(ctx->dev,
232 "occurred overflow at %d, status 0x%x.\n",
240 static bool fimc_check_frame_end(struct fimc_context *ctx)
244 cfg = fimc_read(ctx, EXYNOS_CISTATUS);
246 DRM_DEV_DEBUG_KMS(ctx->dev, "cfg[0x%x]\n", cfg);
248 if (!(cfg & EXYNOS_CISTATUS_FRAMEEND))
251 cfg &= ~(EXYNOS_CISTATUS_FRAMEEND);
252 fimc_write(ctx, cfg, EXYNOS_CISTATUS);
257 static int fimc_get_buf_id(struct fimc_context *ctx)
260 int frame_cnt, buf_id;
262 cfg = fimc_read(ctx, EXYNOS_CISTATUS2);
263 frame_cnt = EXYNOS_CISTATUS2_GET_FRAMECOUNT_BEFORE(cfg);
266 frame_cnt = EXYNOS_CISTATUS2_GET_FRAMECOUNT_PRESENT(cfg);
268 DRM_DEV_DEBUG_KMS(ctx->dev, "present[%d]before[%d]\n",
269 EXYNOS_CISTATUS2_GET_FRAMECOUNT_PRESENT(cfg),
270 EXYNOS_CISTATUS2_GET_FRAMECOUNT_BEFORE(cfg));
272 if (frame_cnt == 0) {
273 DRM_DEV_ERROR(ctx->dev, "failed to get frame count.\n");
277 buf_id = frame_cnt - 1;
278 DRM_DEV_DEBUG_KMS(ctx->dev, "buf_id[%d]\n", buf_id);
283 static void fimc_handle_lastend(struct fimc_context *ctx, bool enable)
287 DRM_DEV_DEBUG_KMS(ctx->dev, "enable[%d]\n", enable);
289 cfg = fimc_read(ctx, EXYNOS_CIOCTRL);
291 cfg |= EXYNOS_CIOCTRL_LASTENDEN;
293 cfg &= ~EXYNOS_CIOCTRL_LASTENDEN;
295 fimc_write(ctx, cfg, EXYNOS_CIOCTRL);
298 static void fimc_src_set_fmt_order(struct fimc_context *ctx, u32 fmt)
302 DRM_DEV_DEBUG_KMS(ctx->dev, "fmt[0x%x]\n", fmt);
305 cfg = fimc_read(ctx, EXYNOS_CISCCTRL);
306 cfg &= ~EXYNOS_CISCCTRL_INRGB_FMT_RGB_MASK;
309 case DRM_FORMAT_RGB565:
310 cfg |= EXYNOS_CISCCTRL_INRGB_FMT_RGB565;
311 fimc_write(ctx, cfg, EXYNOS_CISCCTRL);
313 case DRM_FORMAT_RGB888:
314 case DRM_FORMAT_XRGB8888:
315 cfg |= EXYNOS_CISCCTRL_INRGB_FMT_RGB888;
316 fimc_write(ctx, cfg, EXYNOS_CISCCTRL);
324 cfg = fimc_read(ctx, EXYNOS_MSCTRL);
325 cfg &= ~(EXYNOS_MSCTRL_ORDER2P_SHIFT_MASK |
326 EXYNOS_MSCTRL_C_INT_IN_2PLANE |
327 EXYNOS_MSCTRL_ORDER422_YCBYCR);
330 case DRM_FORMAT_YUYV:
331 cfg |= EXYNOS_MSCTRL_ORDER422_YCBYCR;
333 case DRM_FORMAT_YVYU:
334 cfg |= EXYNOS_MSCTRL_ORDER422_YCRYCB;
336 case DRM_FORMAT_UYVY:
337 cfg |= EXYNOS_MSCTRL_ORDER422_CBYCRY;
339 case DRM_FORMAT_VYUY:
340 case DRM_FORMAT_YUV444:
341 cfg |= EXYNOS_MSCTRL_ORDER422_CRYCBY;
343 case DRM_FORMAT_NV21:
344 case DRM_FORMAT_NV61:
345 cfg |= (EXYNOS_MSCTRL_ORDER2P_LSB_CRCB |
346 EXYNOS_MSCTRL_C_INT_IN_2PLANE);
348 case DRM_FORMAT_YUV422:
349 case DRM_FORMAT_YUV420:
350 case DRM_FORMAT_YVU420:
351 cfg |= EXYNOS_MSCTRL_C_INT_IN_3PLANE;
353 case DRM_FORMAT_NV12:
354 case DRM_FORMAT_NV16:
355 cfg |= (EXYNOS_MSCTRL_ORDER2P_LSB_CBCR |
356 EXYNOS_MSCTRL_C_INT_IN_2PLANE);
360 fimc_write(ctx, cfg, EXYNOS_MSCTRL);
363 static void fimc_src_set_fmt(struct fimc_context *ctx, u32 fmt, bool tiled)
367 DRM_DEV_DEBUG_KMS(ctx->dev, "fmt[0x%x]\n", fmt);
369 cfg = fimc_read(ctx, EXYNOS_MSCTRL);
370 cfg &= ~EXYNOS_MSCTRL_INFORMAT_RGB;
373 case DRM_FORMAT_RGB565:
374 case DRM_FORMAT_RGB888:
375 case DRM_FORMAT_XRGB8888:
376 cfg |= EXYNOS_MSCTRL_INFORMAT_RGB;
378 case DRM_FORMAT_YUV444:
379 cfg |= EXYNOS_MSCTRL_INFORMAT_YCBCR420;
381 case DRM_FORMAT_YUYV:
382 case DRM_FORMAT_YVYU:
383 case DRM_FORMAT_UYVY:
384 case DRM_FORMAT_VYUY:
385 cfg |= EXYNOS_MSCTRL_INFORMAT_YCBCR422_1PLANE;
387 case DRM_FORMAT_NV16:
388 case DRM_FORMAT_NV61:
389 case DRM_FORMAT_YUV422:
390 cfg |= EXYNOS_MSCTRL_INFORMAT_YCBCR422;
392 case DRM_FORMAT_YUV420:
393 case DRM_FORMAT_YVU420:
394 case DRM_FORMAT_NV12:
395 case DRM_FORMAT_NV21:
396 cfg |= EXYNOS_MSCTRL_INFORMAT_YCBCR420;
400 fimc_write(ctx, cfg, EXYNOS_MSCTRL);
402 cfg = fimc_read(ctx, EXYNOS_CIDMAPARAM);
403 cfg &= ~EXYNOS_CIDMAPARAM_R_MODE_MASK;
406 cfg |= EXYNOS_CIDMAPARAM_R_MODE_64X32;
408 cfg |= EXYNOS_CIDMAPARAM_R_MODE_LINEAR;
410 fimc_write(ctx, cfg, EXYNOS_CIDMAPARAM);
412 fimc_src_set_fmt_order(ctx, fmt);
415 static void fimc_src_set_transf(struct fimc_context *ctx, unsigned int rotation)
417 unsigned int degree = rotation & DRM_MODE_ROTATE_MASK;
420 DRM_DEV_DEBUG_KMS(ctx->dev, "rotation[%x]\n", rotation);
422 cfg1 = fimc_read(ctx, EXYNOS_MSCTRL);
423 cfg1 &= ~(EXYNOS_MSCTRL_FLIP_X_MIRROR |
424 EXYNOS_MSCTRL_FLIP_Y_MIRROR);
426 cfg2 = fimc_read(ctx, EXYNOS_CITRGFMT);
427 cfg2 &= ~EXYNOS_CITRGFMT_INROT90_CLOCKWISE;
430 case DRM_MODE_ROTATE_0:
431 if (rotation & DRM_MODE_REFLECT_X)
432 cfg1 |= EXYNOS_MSCTRL_FLIP_X_MIRROR;
433 if (rotation & DRM_MODE_REFLECT_Y)
434 cfg1 |= EXYNOS_MSCTRL_FLIP_Y_MIRROR;
436 case DRM_MODE_ROTATE_90:
437 cfg2 |= EXYNOS_CITRGFMT_INROT90_CLOCKWISE;
438 if (rotation & DRM_MODE_REFLECT_X)
439 cfg1 |= EXYNOS_MSCTRL_FLIP_X_MIRROR;
440 if (rotation & DRM_MODE_REFLECT_Y)
441 cfg1 |= EXYNOS_MSCTRL_FLIP_Y_MIRROR;
443 case DRM_MODE_ROTATE_180:
444 cfg1 |= (EXYNOS_MSCTRL_FLIP_X_MIRROR |
445 EXYNOS_MSCTRL_FLIP_Y_MIRROR);
446 if (rotation & DRM_MODE_REFLECT_X)
447 cfg1 &= ~EXYNOS_MSCTRL_FLIP_X_MIRROR;
448 if (rotation & DRM_MODE_REFLECT_Y)
449 cfg1 &= ~EXYNOS_MSCTRL_FLIP_Y_MIRROR;
451 case DRM_MODE_ROTATE_270:
452 cfg1 |= (EXYNOS_MSCTRL_FLIP_X_MIRROR |
453 EXYNOS_MSCTRL_FLIP_Y_MIRROR);
454 cfg2 |= EXYNOS_CITRGFMT_INROT90_CLOCKWISE;
455 if (rotation & DRM_MODE_REFLECT_X)
456 cfg1 &= ~EXYNOS_MSCTRL_FLIP_X_MIRROR;
457 if (rotation & DRM_MODE_REFLECT_Y)
458 cfg1 &= ~EXYNOS_MSCTRL_FLIP_Y_MIRROR;
462 fimc_write(ctx, cfg1, EXYNOS_MSCTRL);
463 fimc_write(ctx, cfg2, EXYNOS_CITRGFMT);
466 static void fimc_set_window(struct fimc_context *ctx,
467 struct exynos_drm_ipp_buffer *buf)
469 unsigned int real_width = buf->buf.pitch[0] / buf->format->cpp[0];
470 u32 cfg, h1, h2, v1, v2;
474 h2 = real_width - buf->rect.w - buf->rect.x;
476 v2 = buf->buf.height - buf->rect.h - buf->rect.y;
478 DRM_DEV_DEBUG_KMS(ctx->dev, "x[%d]y[%d]w[%d]h[%d]hsize[%d]vsize[%d]\n",
479 buf->rect.x, buf->rect.y, buf->rect.w, buf->rect.h,
480 real_width, buf->buf.height);
481 DRM_DEV_DEBUG_KMS(ctx->dev, "h1[%d]h2[%d]v1[%d]v2[%d]\n", h1, h2, v1,
485 * set window offset 1, 2 size
486 * check figure 43-21 in user manual
488 cfg = fimc_read(ctx, EXYNOS_CIWDOFST);
489 cfg &= ~(EXYNOS_CIWDOFST_WINHOROFST_MASK |
490 EXYNOS_CIWDOFST_WINVEROFST_MASK);
491 cfg |= (EXYNOS_CIWDOFST_WINHOROFST(h1) |
492 EXYNOS_CIWDOFST_WINVEROFST(v1));
493 cfg |= EXYNOS_CIWDOFST_WINOFSEN;
494 fimc_write(ctx, cfg, EXYNOS_CIWDOFST);
496 cfg = (EXYNOS_CIWDOFST2_WINHOROFST2(h2) |
497 EXYNOS_CIWDOFST2_WINVEROFST2(v2));
498 fimc_write(ctx, cfg, EXYNOS_CIWDOFST2);
501 static void fimc_src_set_size(struct fimc_context *ctx,
502 struct exynos_drm_ipp_buffer *buf)
504 unsigned int real_width = buf->buf.pitch[0] / buf->format->cpp[0];
507 DRM_DEV_DEBUG_KMS(ctx->dev, "hsize[%d]vsize[%d]\n", real_width,
511 cfg = (EXYNOS_ORGISIZE_HORIZONTAL(real_width) |
512 EXYNOS_ORGISIZE_VERTICAL(buf->buf.height));
514 fimc_write(ctx, cfg, EXYNOS_ORGISIZE);
516 DRM_DEV_DEBUG_KMS(ctx->dev, "x[%d]y[%d]w[%d]h[%d]\n", buf->rect.x,
517 buf->rect.y, buf->rect.w, buf->rect.h);
519 /* set input DMA image size */
520 cfg = fimc_read(ctx, EXYNOS_CIREAL_ISIZE);
521 cfg &= ~(EXYNOS_CIREAL_ISIZE_HEIGHT_MASK |
522 EXYNOS_CIREAL_ISIZE_WIDTH_MASK);
523 cfg |= (EXYNOS_CIREAL_ISIZE_WIDTH(buf->rect.w) |
524 EXYNOS_CIREAL_ISIZE_HEIGHT(buf->rect.h));
525 fimc_write(ctx, cfg, EXYNOS_CIREAL_ISIZE);
528 * set input FIFO image size
529 * for now, we support only ITU601 8 bit mode
531 cfg = (EXYNOS_CISRCFMT_ITU601_8BIT |
532 EXYNOS_CISRCFMT_SOURCEHSIZE(real_width) |
533 EXYNOS_CISRCFMT_SOURCEVSIZE(buf->buf.height));
534 fimc_write(ctx, cfg, EXYNOS_CISRCFMT);
536 /* offset Y(RGB), Cb, Cr */
537 cfg = (EXYNOS_CIIYOFF_HORIZONTAL(buf->rect.x) |
538 EXYNOS_CIIYOFF_VERTICAL(buf->rect.y));
539 fimc_write(ctx, cfg, EXYNOS_CIIYOFF);
540 cfg = (EXYNOS_CIICBOFF_HORIZONTAL(buf->rect.x) |
541 EXYNOS_CIICBOFF_VERTICAL(buf->rect.y));
542 fimc_write(ctx, cfg, EXYNOS_CIICBOFF);
543 cfg = (EXYNOS_CIICROFF_HORIZONTAL(buf->rect.x) |
544 EXYNOS_CIICROFF_VERTICAL(buf->rect.y));
545 fimc_write(ctx, cfg, EXYNOS_CIICROFF);
547 fimc_set_window(ctx, buf);
550 static void fimc_src_set_addr(struct fimc_context *ctx,
551 struct exynos_drm_ipp_buffer *buf)
553 fimc_write(ctx, buf->dma_addr[0], EXYNOS_CIIYSA(0));
554 fimc_write(ctx, buf->dma_addr[1], EXYNOS_CIICBSA(0));
555 fimc_write(ctx, buf->dma_addr[2], EXYNOS_CIICRSA(0));
558 static void fimc_dst_set_fmt_order(struct fimc_context *ctx, u32 fmt)
562 DRM_DEV_DEBUG_KMS(ctx->dev, "fmt[0x%x]\n", fmt);
565 cfg = fimc_read(ctx, EXYNOS_CISCCTRL);
566 cfg &= ~EXYNOS_CISCCTRL_OUTRGB_FMT_RGB_MASK;
569 case DRM_FORMAT_RGB565:
570 cfg |= EXYNOS_CISCCTRL_OUTRGB_FMT_RGB565;
571 fimc_write(ctx, cfg, EXYNOS_CISCCTRL);
573 case DRM_FORMAT_RGB888:
574 cfg |= EXYNOS_CISCCTRL_OUTRGB_FMT_RGB888;
575 fimc_write(ctx, cfg, EXYNOS_CISCCTRL);
577 case DRM_FORMAT_XRGB8888:
578 cfg |= (EXYNOS_CISCCTRL_OUTRGB_FMT_RGB888 |
579 EXYNOS_CISCCTRL_EXTRGB_EXTENSION);
580 fimc_write(ctx, cfg, EXYNOS_CISCCTRL);
588 cfg = fimc_read(ctx, EXYNOS_CIOCTRL);
589 cfg &= ~(EXYNOS_CIOCTRL_ORDER2P_MASK |
590 EXYNOS_CIOCTRL_ORDER422_MASK |
591 EXYNOS_CIOCTRL_YCBCR_PLANE_MASK);
594 case DRM_FORMAT_XRGB8888:
595 cfg |= EXYNOS_CIOCTRL_ALPHA_OUT;
597 case DRM_FORMAT_YUYV:
598 cfg |= EXYNOS_CIOCTRL_ORDER422_YCBYCR;
600 case DRM_FORMAT_YVYU:
601 cfg |= EXYNOS_CIOCTRL_ORDER422_YCRYCB;
603 case DRM_FORMAT_UYVY:
604 cfg |= EXYNOS_CIOCTRL_ORDER422_CBYCRY;
606 case DRM_FORMAT_VYUY:
607 cfg |= EXYNOS_CIOCTRL_ORDER422_CRYCBY;
609 case DRM_FORMAT_NV21:
610 case DRM_FORMAT_NV61:
611 cfg |= EXYNOS_CIOCTRL_ORDER2P_LSB_CRCB;
612 cfg |= EXYNOS_CIOCTRL_YCBCR_2PLANE;
614 case DRM_FORMAT_YUV422:
615 case DRM_FORMAT_YUV420:
616 case DRM_FORMAT_YVU420:
617 cfg |= EXYNOS_CIOCTRL_YCBCR_3PLANE;
619 case DRM_FORMAT_NV12:
620 case DRM_FORMAT_NV16:
621 cfg |= EXYNOS_CIOCTRL_ORDER2P_LSB_CBCR;
622 cfg |= EXYNOS_CIOCTRL_YCBCR_2PLANE;
626 fimc_write(ctx, cfg, EXYNOS_CIOCTRL);
629 static void fimc_dst_set_fmt(struct fimc_context *ctx, u32 fmt, bool tiled)
633 DRM_DEV_DEBUG_KMS(ctx->dev, "fmt[0x%x]\n", fmt);
635 cfg = fimc_read(ctx, EXYNOS_CIEXTEN);
637 if (fmt == DRM_FORMAT_AYUV) {
638 cfg |= EXYNOS_CIEXTEN_YUV444_OUT;
639 fimc_write(ctx, cfg, EXYNOS_CIEXTEN);
641 cfg &= ~EXYNOS_CIEXTEN_YUV444_OUT;
642 fimc_write(ctx, cfg, EXYNOS_CIEXTEN);
644 cfg = fimc_read(ctx, EXYNOS_CITRGFMT);
645 cfg &= ~EXYNOS_CITRGFMT_OUTFORMAT_MASK;
648 case DRM_FORMAT_RGB565:
649 case DRM_FORMAT_RGB888:
650 case DRM_FORMAT_XRGB8888:
651 cfg |= EXYNOS_CITRGFMT_OUTFORMAT_RGB;
653 case DRM_FORMAT_YUYV:
654 case DRM_FORMAT_YVYU:
655 case DRM_FORMAT_UYVY:
656 case DRM_FORMAT_VYUY:
657 cfg |= EXYNOS_CITRGFMT_OUTFORMAT_YCBCR422_1PLANE;
659 case DRM_FORMAT_NV16:
660 case DRM_FORMAT_NV61:
661 case DRM_FORMAT_YUV422:
662 cfg |= EXYNOS_CITRGFMT_OUTFORMAT_YCBCR422;
664 case DRM_FORMAT_YUV420:
665 case DRM_FORMAT_YVU420:
666 case DRM_FORMAT_NV12:
667 case DRM_FORMAT_NV21:
668 cfg |= EXYNOS_CITRGFMT_OUTFORMAT_YCBCR420;
672 fimc_write(ctx, cfg, EXYNOS_CITRGFMT);
675 cfg = fimc_read(ctx, EXYNOS_CIDMAPARAM);
676 cfg &= ~EXYNOS_CIDMAPARAM_W_MODE_MASK;
679 cfg |= EXYNOS_CIDMAPARAM_W_MODE_64X32;
681 cfg |= EXYNOS_CIDMAPARAM_W_MODE_LINEAR;
683 fimc_write(ctx, cfg, EXYNOS_CIDMAPARAM);
685 fimc_dst_set_fmt_order(ctx, fmt);
688 static void fimc_dst_set_transf(struct fimc_context *ctx, unsigned int rotation)
690 unsigned int degree = rotation & DRM_MODE_ROTATE_MASK;
693 DRM_DEV_DEBUG_KMS(ctx->dev, "rotation[0x%x]\n", rotation);
695 cfg = fimc_read(ctx, EXYNOS_CITRGFMT);
696 cfg &= ~EXYNOS_CITRGFMT_FLIP_MASK;
697 cfg &= ~EXYNOS_CITRGFMT_OUTROT90_CLOCKWISE;
700 case DRM_MODE_ROTATE_0:
701 if (rotation & DRM_MODE_REFLECT_X)
702 cfg |= EXYNOS_CITRGFMT_FLIP_X_MIRROR;
703 if (rotation & DRM_MODE_REFLECT_Y)
704 cfg |= EXYNOS_CITRGFMT_FLIP_Y_MIRROR;
706 case DRM_MODE_ROTATE_90:
707 cfg |= EXYNOS_CITRGFMT_OUTROT90_CLOCKWISE;
708 if (rotation & DRM_MODE_REFLECT_X)
709 cfg |= EXYNOS_CITRGFMT_FLIP_X_MIRROR;
710 if (rotation & DRM_MODE_REFLECT_Y)
711 cfg |= EXYNOS_CITRGFMT_FLIP_Y_MIRROR;
713 case DRM_MODE_ROTATE_180:
714 cfg |= (EXYNOS_CITRGFMT_FLIP_X_MIRROR |
715 EXYNOS_CITRGFMT_FLIP_Y_MIRROR);
716 if (rotation & DRM_MODE_REFLECT_X)
717 cfg &= ~EXYNOS_CITRGFMT_FLIP_X_MIRROR;
718 if (rotation & DRM_MODE_REFLECT_Y)
719 cfg &= ~EXYNOS_CITRGFMT_FLIP_Y_MIRROR;
721 case DRM_MODE_ROTATE_270:
722 cfg |= (EXYNOS_CITRGFMT_OUTROT90_CLOCKWISE |
723 EXYNOS_CITRGFMT_FLIP_X_MIRROR |
724 EXYNOS_CITRGFMT_FLIP_Y_MIRROR);
725 if (rotation & DRM_MODE_REFLECT_X)
726 cfg &= ~EXYNOS_CITRGFMT_FLIP_X_MIRROR;
727 if (rotation & DRM_MODE_REFLECT_Y)
728 cfg &= ~EXYNOS_CITRGFMT_FLIP_Y_MIRROR;
732 fimc_write(ctx, cfg, EXYNOS_CITRGFMT);
735 static int fimc_set_prescaler(struct fimc_context *ctx, struct fimc_scaler *sc,
736 struct drm_exynos_ipp_task_rect *src,
737 struct drm_exynos_ipp_task_rect *dst)
739 u32 cfg, cfg_ext, shfactor;
740 u32 pre_dst_width, pre_dst_height;
741 u32 hfactor, vfactor;
743 u32 src_w, src_h, dst_w, dst_h;
745 cfg_ext = fimc_read(ctx, EXYNOS_CITRGFMT);
746 if (cfg_ext & EXYNOS_CITRGFMT_INROT90_CLOCKWISE) {
754 if (cfg_ext & EXYNOS_CITRGFMT_OUTROT90_CLOCKWISE) {
762 /* fimc_ippdrv_check_property assures that dividers are not null */
763 hfactor = fls(src_w / dst_w / 2);
764 if (hfactor > FIMC_SHFACTOR / 2) {
765 dev_err(ctx->dev, "failed to get ratio horizontal.\n");
769 vfactor = fls(src_h / dst_h / 2);
770 if (vfactor > FIMC_SHFACTOR / 2) {
771 dev_err(ctx->dev, "failed to get ratio vertical.\n");
775 pre_dst_width = src_w >> hfactor;
776 pre_dst_height = src_h >> vfactor;
777 DRM_DEV_DEBUG_KMS(ctx->dev, "pre_dst_width[%d]pre_dst_height[%d]\n",
778 pre_dst_width, pre_dst_height);
779 DRM_DEV_DEBUG_KMS(ctx->dev, "hfactor[%d]vfactor[%d]\n", hfactor,
782 sc->hratio = (src_w << 14) / (dst_w << hfactor);
783 sc->vratio = (src_h << 14) / (dst_h << vfactor);
784 sc->up_h = (dst_w >= src_w) ? true : false;
785 sc->up_v = (dst_h >= src_h) ? true : false;
786 DRM_DEV_DEBUG_KMS(ctx->dev, "hratio[%d]vratio[%d]up_h[%d]up_v[%d]\n",
787 sc->hratio, sc->vratio, sc->up_h, sc->up_v);
789 shfactor = FIMC_SHFACTOR - (hfactor + vfactor);
790 DRM_DEV_DEBUG_KMS(ctx->dev, "shfactor[%d]\n", shfactor);
792 cfg = (EXYNOS_CISCPRERATIO_SHFACTOR(shfactor) |
793 EXYNOS_CISCPRERATIO_PREHORRATIO(1 << hfactor) |
794 EXYNOS_CISCPRERATIO_PREVERRATIO(1 << vfactor));
795 fimc_write(ctx, cfg, EXYNOS_CISCPRERATIO);
797 cfg = (EXYNOS_CISCPREDST_PREDSTWIDTH(pre_dst_width) |
798 EXYNOS_CISCPREDST_PREDSTHEIGHT(pre_dst_height));
799 fimc_write(ctx, cfg, EXYNOS_CISCPREDST);
804 static void fimc_set_scaler(struct fimc_context *ctx, struct fimc_scaler *sc)
808 DRM_DEV_DEBUG_KMS(ctx->dev, "range[%d]bypass[%d]up_h[%d]up_v[%d]\n",
809 sc->range, sc->bypass, sc->up_h, sc->up_v);
810 DRM_DEV_DEBUG_KMS(ctx->dev, "hratio[%d]vratio[%d]\n",
811 sc->hratio, sc->vratio);
813 cfg = fimc_read(ctx, EXYNOS_CISCCTRL);
814 cfg &= ~(EXYNOS_CISCCTRL_SCALERBYPASS |
815 EXYNOS_CISCCTRL_SCALEUP_H | EXYNOS_CISCCTRL_SCALEUP_V |
816 EXYNOS_CISCCTRL_MAIN_V_RATIO_MASK |
817 EXYNOS_CISCCTRL_MAIN_H_RATIO_MASK |
818 EXYNOS_CISCCTRL_CSCR2Y_WIDE |
819 EXYNOS_CISCCTRL_CSCY2R_WIDE);
822 cfg |= (EXYNOS_CISCCTRL_CSCR2Y_WIDE |
823 EXYNOS_CISCCTRL_CSCY2R_WIDE);
825 cfg |= EXYNOS_CISCCTRL_SCALERBYPASS;
827 cfg |= EXYNOS_CISCCTRL_SCALEUP_H;
829 cfg |= EXYNOS_CISCCTRL_SCALEUP_V;
831 cfg |= (EXYNOS_CISCCTRL_MAINHORRATIO((sc->hratio >> 6)) |
832 EXYNOS_CISCCTRL_MAINVERRATIO((sc->vratio >> 6)));
833 fimc_write(ctx, cfg, EXYNOS_CISCCTRL);
835 cfg_ext = fimc_read(ctx, EXYNOS_CIEXTEN);
836 cfg_ext &= ~EXYNOS_CIEXTEN_MAINHORRATIO_EXT_MASK;
837 cfg_ext &= ~EXYNOS_CIEXTEN_MAINVERRATIO_EXT_MASK;
838 cfg_ext |= (EXYNOS_CIEXTEN_MAINHORRATIO_EXT(sc->hratio) |
839 EXYNOS_CIEXTEN_MAINVERRATIO_EXT(sc->vratio));
840 fimc_write(ctx, cfg_ext, EXYNOS_CIEXTEN);
843 static void fimc_dst_set_size(struct fimc_context *ctx,
844 struct exynos_drm_ipp_buffer *buf)
846 unsigned int real_width = buf->buf.pitch[0] / buf->format->cpp[0];
849 DRM_DEV_DEBUG_KMS(ctx->dev, "hsize[%d]vsize[%d]\n", real_width,
853 cfg = (EXYNOS_ORGOSIZE_HORIZONTAL(real_width) |
854 EXYNOS_ORGOSIZE_VERTICAL(buf->buf.height));
856 fimc_write(ctx, cfg, EXYNOS_ORGOSIZE);
858 DRM_DEV_DEBUG_KMS(ctx->dev, "x[%d]y[%d]w[%d]h[%d]\n", buf->rect.x,
860 buf->rect.w, buf->rect.h);
863 cfg = fimc_read(ctx, EXYNOS_CIGCTRL);
864 cfg &= ~EXYNOS_CIGCTRL_CSC_MASK;
866 if (buf->buf.width >= FIMC_WIDTH_ITU_709)
867 cfg |= EXYNOS_CIGCTRL_CSC_ITU709;
869 cfg |= EXYNOS_CIGCTRL_CSC_ITU601;
871 fimc_write(ctx, cfg, EXYNOS_CIGCTRL);
873 cfg_ext = fimc_read(ctx, EXYNOS_CITRGFMT);
875 /* target image size */
876 cfg = fimc_read(ctx, EXYNOS_CITRGFMT);
877 cfg &= ~(EXYNOS_CITRGFMT_TARGETH_MASK |
878 EXYNOS_CITRGFMT_TARGETV_MASK);
879 if (cfg_ext & EXYNOS_CITRGFMT_OUTROT90_CLOCKWISE)
880 cfg |= (EXYNOS_CITRGFMT_TARGETHSIZE(buf->rect.h) |
881 EXYNOS_CITRGFMT_TARGETVSIZE(buf->rect.w));
883 cfg |= (EXYNOS_CITRGFMT_TARGETHSIZE(buf->rect.w) |
884 EXYNOS_CITRGFMT_TARGETVSIZE(buf->rect.h));
885 fimc_write(ctx, cfg, EXYNOS_CITRGFMT);
888 cfg = EXYNOS_CITAREA_TARGET_AREA(buf->rect.w * buf->rect.h);
889 fimc_write(ctx, cfg, EXYNOS_CITAREA);
891 /* offset Y(RGB), Cb, Cr */
892 cfg = (EXYNOS_CIOYOFF_HORIZONTAL(buf->rect.x) |
893 EXYNOS_CIOYOFF_VERTICAL(buf->rect.y));
894 fimc_write(ctx, cfg, EXYNOS_CIOYOFF);
895 cfg = (EXYNOS_CIOCBOFF_HORIZONTAL(buf->rect.x) |
896 EXYNOS_CIOCBOFF_VERTICAL(buf->rect.y));
897 fimc_write(ctx, cfg, EXYNOS_CIOCBOFF);
898 cfg = (EXYNOS_CIOCROFF_HORIZONTAL(buf->rect.x) |
899 EXYNOS_CIOCROFF_VERTICAL(buf->rect.y));
900 fimc_write(ctx, cfg, EXYNOS_CIOCROFF);
903 static void fimc_dst_set_buf_seq(struct fimc_context *ctx, u32 buf_id,
910 DRM_DEV_DEBUG_KMS(ctx->dev, "buf_id[%d]enqueu[%d]\n", buf_id, enqueue);
912 spin_lock_irqsave(&ctx->lock, flags);
914 cfg = fimc_read(ctx, EXYNOS_CIFCNTSEQ);
917 cfg |= (1 << buf_id);
919 cfg &= ~(1 << buf_id);
921 fimc_write(ctx, cfg, EXYNOS_CIFCNTSEQ);
923 buf_num = hweight32(cfg);
925 if (enqueue && buf_num >= FIMC_BUF_START)
926 fimc_mask_irq(ctx, true);
927 else if (!enqueue && buf_num <= FIMC_BUF_STOP)
928 fimc_mask_irq(ctx, false);
930 spin_unlock_irqrestore(&ctx->lock, flags);
933 static void fimc_dst_set_addr(struct fimc_context *ctx,
934 struct exynos_drm_ipp_buffer *buf)
936 fimc_write(ctx, buf->dma_addr[0], EXYNOS_CIOYSA(0));
937 fimc_write(ctx, buf->dma_addr[1], EXYNOS_CIOCBSA(0));
938 fimc_write(ctx, buf->dma_addr[2], EXYNOS_CIOCRSA(0));
940 fimc_dst_set_buf_seq(ctx, 0, true);
943 static void fimc_stop(struct fimc_context *ctx);
945 static irqreturn_t fimc_irq_handler(int irq, void *dev_id)
947 struct fimc_context *ctx = dev_id;
950 DRM_DEV_DEBUG_KMS(ctx->dev, "fimc id[%d]\n", ctx->id);
953 if (fimc_check_ovf(ctx))
956 if (!fimc_check_frame_end(ctx))
959 buf_id = fimc_get_buf_id(ctx);
963 DRM_DEV_DEBUG_KMS(ctx->dev, "buf_id[%d]\n", buf_id);
966 struct exynos_drm_ipp_task *task = ctx->task;
969 pm_runtime_mark_last_busy(ctx->dev);
970 pm_runtime_put_autosuspend(ctx->dev);
971 exynos_drm_ipp_task_done(task, 0);
974 fimc_dst_set_buf_seq(ctx, buf_id, false);
980 static void fimc_clear_addr(struct fimc_context *ctx)
984 for (i = 0; i < FIMC_MAX_SRC; i++) {
985 fimc_write(ctx, 0, EXYNOS_CIIYSA(i));
986 fimc_write(ctx, 0, EXYNOS_CIICBSA(i));
987 fimc_write(ctx, 0, EXYNOS_CIICRSA(i));
990 for (i = 0; i < FIMC_MAX_DST; i++) {
991 fimc_write(ctx, 0, EXYNOS_CIOYSA(i));
992 fimc_write(ctx, 0, EXYNOS_CIOCBSA(i));
993 fimc_write(ctx, 0, EXYNOS_CIOCRSA(i));
997 static void fimc_reset(struct fimc_context *ctx)
999 /* reset h/w block */
1002 /* reset scaler capability */
1003 memset(&ctx->sc, 0x0, sizeof(ctx->sc));
1005 fimc_clear_addr(ctx);
1008 static void fimc_start(struct fimc_context *ctx)
1012 fimc_mask_irq(ctx, true);
1014 /* If set true, we can save jpeg about screen */
1015 fimc_handle_jpeg(ctx, false);
1016 fimc_set_scaler(ctx, &ctx->sc);
1018 fimc_set_type_ctrl(ctx);
1019 fimc_handle_lastend(ctx, false);
1022 cfg0 = fimc_read(ctx, EXYNOS_MSCTRL);
1023 cfg0 &= ~EXYNOS_MSCTRL_INPUT_MASK;
1024 cfg0 |= EXYNOS_MSCTRL_INPUT_MEMORY;
1025 fimc_write(ctx, cfg0, EXYNOS_MSCTRL);
1028 fimc_write(ctx, 0x0, EXYNOS_CISTATUS);
1030 cfg0 = fimc_read(ctx, EXYNOS_CIIMGCPT);
1031 cfg0 &= ~EXYNOS_CIIMGCPT_IMGCPTEN_SC;
1032 cfg0 |= EXYNOS_CIIMGCPT_IMGCPTEN_SC;
1035 cfg1 = fimc_read(ctx, EXYNOS_CISCCTRL);
1036 cfg1 &= ~EXYNOS_CISCCTRL_SCAN_MASK;
1037 cfg1 |= (EXYNOS_CISCCTRL_PROGRESSIVE |
1038 EXYNOS_CISCCTRL_SCALERSTART);
1040 fimc_write(ctx, cfg1, EXYNOS_CISCCTRL);
1042 /* Enable image capture*/
1043 cfg0 |= EXYNOS_CIIMGCPT_IMGCPTEN;
1044 fimc_write(ctx, cfg0, EXYNOS_CIIMGCPT);
1046 /* Disable frame end irq */
1047 fimc_clear_bits(ctx, EXYNOS_CIGCTRL, EXYNOS_CIGCTRL_IRQ_END_DISABLE);
1049 fimc_clear_bits(ctx, EXYNOS_CIOCTRL, EXYNOS_CIOCTRL_WEAVE_MASK);
1051 fimc_set_bits(ctx, EXYNOS_MSCTRL, EXYNOS_MSCTRL_ENVID);
1054 static void fimc_stop(struct fimc_context *ctx)
1059 cfg = fimc_read(ctx, EXYNOS_MSCTRL);
1060 cfg &= ~EXYNOS_MSCTRL_INPUT_MASK;
1061 cfg &= ~EXYNOS_MSCTRL_ENVID;
1062 fimc_write(ctx, cfg, EXYNOS_MSCTRL);
1064 fimc_mask_irq(ctx, false);
1066 /* reset sequence */
1067 fimc_write(ctx, 0x0, EXYNOS_CIFCNTSEQ);
1069 /* Scaler disable */
1070 fimc_clear_bits(ctx, EXYNOS_CISCCTRL, EXYNOS_CISCCTRL_SCALERSTART);
1072 /* Disable image capture */
1073 fimc_clear_bits(ctx, EXYNOS_CIIMGCPT,
1074 EXYNOS_CIIMGCPT_IMGCPTEN_SC | EXYNOS_CIIMGCPT_IMGCPTEN);
1076 /* Enable frame end irq */
1077 fimc_set_bits(ctx, EXYNOS_CIGCTRL, EXYNOS_CIGCTRL_IRQ_END_DISABLE);
1080 static int fimc_commit(struct exynos_drm_ipp *ipp,
1081 struct exynos_drm_ipp_task *task)
1083 struct fimc_context *ctx =
1084 container_of(ipp, struct fimc_context, ipp);
1086 pm_runtime_get_sync(ctx->dev);
1089 fimc_src_set_fmt(ctx, task->src.buf.fourcc, task->src.buf.modifier);
1090 fimc_src_set_size(ctx, &task->src);
1091 fimc_src_set_transf(ctx, DRM_MODE_ROTATE_0);
1092 fimc_src_set_addr(ctx, &task->src);
1093 fimc_dst_set_fmt(ctx, task->dst.buf.fourcc, task->dst.buf.modifier);
1094 fimc_dst_set_transf(ctx, task->transform.rotation);
1095 fimc_dst_set_size(ctx, &task->dst);
1096 fimc_dst_set_addr(ctx, &task->dst);
1097 fimc_set_prescaler(ctx, &ctx->sc, &task->src.rect, &task->dst.rect);
1103 static void fimc_abort(struct exynos_drm_ipp *ipp,
1104 struct exynos_drm_ipp_task *task)
1106 struct fimc_context *ctx =
1107 container_of(ipp, struct fimc_context, ipp);
1112 struct exynos_drm_ipp_task *task = ctx->task;
1115 pm_runtime_mark_last_busy(ctx->dev);
1116 pm_runtime_put_autosuspend(ctx->dev);
1117 exynos_drm_ipp_task_done(task, -EIO);
1121 static struct exynos_drm_ipp_funcs ipp_funcs = {
1122 .commit = fimc_commit,
1123 .abort = fimc_abort,
1126 static int fimc_bind(struct device *dev, struct device *master, void *data)
1128 struct fimc_context *ctx = dev_get_drvdata(dev);
1129 struct drm_device *drm_dev = data;
1130 struct exynos_drm_ipp *ipp = &ctx->ipp;
1132 ctx->drm_dev = drm_dev;
1133 ipp->drm_dev = drm_dev;
1134 exynos_drm_register_dma(drm_dev, dev);
1136 exynos_drm_ipp_register(dev, ipp, &ipp_funcs,
1137 DRM_EXYNOS_IPP_CAP_CROP | DRM_EXYNOS_IPP_CAP_ROTATE |
1138 DRM_EXYNOS_IPP_CAP_SCALE | DRM_EXYNOS_IPP_CAP_CONVERT,
1139 ctx->formats, ctx->num_formats, "fimc");
1141 dev_info(dev, "The exynos fimc has been probed successfully\n");
1146 static void fimc_unbind(struct device *dev, struct device *master,
1149 struct fimc_context *ctx = dev_get_drvdata(dev);
1150 struct drm_device *drm_dev = data;
1151 struct exynos_drm_ipp *ipp = &ctx->ipp;
1153 exynos_drm_ipp_unregister(dev, ipp);
1154 exynos_drm_unregister_dma(drm_dev, dev);
1157 static const struct component_ops fimc_component_ops = {
1159 .unbind = fimc_unbind,
1162 static void fimc_put_clocks(struct fimc_context *ctx)
1166 for (i = 0; i < FIMC_CLKS_MAX; i++) {
1167 if (IS_ERR(ctx->clocks[i]))
1169 clk_put(ctx->clocks[i]);
1170 ctx->clocks[i] = ERR_PTR(-EINVAL);
1174 static int fimc_setup_clocks(struct fimc_context *ctx)
1176 struct device *fimc_dev = ctx->dev;
1180 for (i = 0; i < FIMC_CLKS_MAX; i++)
1181 ctx->clocks[i] = ERR_PTR(-EINVAL);
1183 for (i = 0; i < FIMC_CLKS_MAX; i++) {
1184 if (i == FIMC_CLK_WB_A || i == FIMC_CLK_WB_B)
1185 dev = fimc_dev->parent;
1189 ctx->clocks[i] = clk_get(dev, fimc_clock_names[i]);
1190 if (IS_ERR(ctx->clocks[i])) {
1191 ret = PTR_ERR(ctx->clocks[i]);
1192 dev_err(fimc_dev, "failed to get clock: %s\n",
1193 fimc_clock_names[i]);
1198 ret = clk_prepare_enable(ctx->clocks[FIMC_CLK_LCLK]);
1202 fimc_put_clocks(ctx);
1206 int exynos_drm_check_fimc_device(struct device *dev)
1208 int id = of_alias_get_id(dev->of_node, "fimc");
1210 if (id >= 0 && (BIT(id) & fimc_mask))
1215 static const unsigned int fimc_formats[] = {
1216 DRM_FORMAT_XRGB8888, DRM_FORMAT_RGB565,
1217 DRM_FORMAT_NV12, DRM_FORMAT_NV16, DRM_FORMAT_NV21, DRM_FORMAT_NV61,
1218 DRM_FORMAT_UYVY, DRM_FORMAT_VYUY, DRM_FORMAT_YUYV, DRM_FORMAT_YVYU,
1219 DRM_FORMAT_YUV420, DRM_FORMAT_YVU420, DRM_FORMAT_YUV422,
1223 static const unsigned int fimc_tiled_formats[] = {
1224 DRM_FORMAT_NV12, DRM_FORMAT_NV21,
1227 static const struct drm_exynos_ipp_limit fimc_4210_limits_v1[] = {
1228 { IPP_SIZE_LIMIT(BUFFER, .h = { 16, 8192, 8 }, .v = { 16, 8192, 2 }) },
1229 { IPP_SIZE_LIMIT(AREA, .h = { 16, 4224, 2 }, .v = { 16, 0, 2 }) },
1230 { IPP_SIZE_LIMIT(ROTATED, .h = { 128, 1920 }, .v = { 128, 0 }) },
1231 { IPP_SCALE_LIMIT(.h = { (1 << 16) / 64, (1 << 16) * 64 },
1232 .v = { (1 << 16) / 64, (1 << 16) * 64 }) },
1235 static const struct drm_exynos_ipp_limit fimc_4210_limits_v2[] = {
1236 { IPP_SIZE_LIMIT(BUFFER, .h = { 16, 8192, 8 }, .v = { 16, 8192, 2 }) },
1237 { IPP_SIZE_LIMIT(AREA, .h = { 16, 1920, 2 }, .v = { 16, 0, 2 }) },
1238 { IPP_SIZE_LIMIT(ROTATED, .h = { 128, 1366 }, .v = { 128, 0 }) },
1239 { IPP_SCALE_LIMIT(.h = { (1 << 16) / 64, (1 << 16) * 64 },
1240 .v = { (1 << 16) / 64, (1 << 16) * 64 }) },
1243 static const struct drm_exynos_ipp_limit fimc_4210_limits_tiled_v1[] = {
1244 { IPP_SIZE_LIMIT(BUFFER, .h = { 128, 1920, 128 }, .v = { 32, 1920, 32 }) },
1245 { IPP_SIZE_LIMIT(AREA, .h = { 128, 1920, 2 }, .v = { 128, 0, 2 }) },
1246 { IPP_SCALE_LIMIT(.h = { (1 << 16) / 64, (1 << 16) * 64 },
1247 .v = { (1 << 16) / 64, (1 << 16) * 64 }) },
1250 static const struct drm_exynos_ipp_limit fimc_4210_limits_tiled_v2[] = {
1251 { IPP_SIZE_LIMIT(BUFFER, .h = { 128, 1920, 128 }, .v = { 32, 1920, 32 }) },
1252 { IPP_SIZE_LIMIT(AREA, .h = { 128, 1366, 2 }, .v = { 128, 0, 2 }) },
1253 { IPP_SCALE_LIMIT(.h = { (1 << 16) / 64, (1 << 16) * 64 },
1254 .v = { (1 << 16) / 64, (1 << 16) * 64 }) },
1257 static int fimc_probe(struct platform_device *pdev)
1259 const struct drm_exynos_ipp_limit *limits;
1260 struct exynos_drm_ipp_formats *formats;
1261 struct device *dev = &pdev->dev;
1262 struct fimc_context *ctx;
1263 struct resource *res;
1265 int i, j, num_limits, num_formats;
1267 if (exynos_drm_check_fimc_device(dev) != 0)
1270 ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
1275 ctx->id = of_alias_get_id(dev->of_node, "fimc");
1277 /* construct formats/limits array */
1278 num_formats = ARRAY_SIZE(fimc_formats) + ARRAY_SIZE(fimc_tiled_formats);
1279 formats = devm_kcalloc(dev, num_formats, sizeof(*formats),
1284 /* linear formats */
1286 limits = fimc_4210_limits_v1;
1287 num_limits = ARRAY_SIZE(fimc_4210_limits_v1);
1289 limits = fimc_4210_limits_v2;
1290 num_limits = ARRAY_SIZE(fimc_4210_limits_v2);
1292 for (i = 0; i < ARRAY_SIZE(fimc_formats); i++) {
1293 formats[i].fourcc = fimc_formats[i];
1294 formats[i].type = DRM_EXYNOS_IPP_FORMAT_SOURCE |
1295 DRM_EXYNOS_IPP_FORMAT_DESTINATION;
1296 formats[i].limits = limits;
1297 formats[i].num_limits = num_limits;
1302 limits = fimc_4210_limits_tiled_v1;
1303 num_limits = ARRAY_SIZE(fimc_4210_limits_tiled_v1);
1305 limits = fimc_4210_limits_tiled_v2;
1306 num_limits = ARRAY_SIZE(fimc_4210_limits_tiled_v2);
1308 for (j = i, i = 0; i < ARRAY_SIZE(fimc_tiled_formats); j++, i++) {
1309 formats[j].fourcc = fimc_tiled_formats[i];
1310 formats[j].modifier = DRM_FORMAT_MOD_SAMSUNG_64_32_TILE;
1311 formats[j].type = DRM_EXYNOS_IPP_FORMAT_SOURCE |
1312 DRM_EXYNOS_IPP_FORMAT_DESTINATION;
1313 formats[j].limits = limits;
1314 formats[j].num_limits = num_limits;
1317 ctx->formats = formats;
1318 ctx->num_formats = num_formats;
1320 /* resource memory */
1321 ctx->regs_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1322 ctx->regs = devm_ioremap_resource(dev, ctx->regs_res);
1323 if (IS_ERR(ctx->regs))
1324 return PTR_ERR(ctx->regs);
1327 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1329 dev_err(dev, "failed to request irq resource.\n");
1333 ret = devm_request_irq(dev, res->start, fimc_irq_handler,
1334 0, dev_name(dev), ctx);
1336 dev_err(dev, "failed to request irq.\n");
1340 ret = fimc_setup_clocks(ctx);
1344 spin_lock_init(&ctx->lock);
1345 platform_set_drvdata(pdev, ctx);
1347 pm_runtime_use_autosuspend(dev);
1348 pm_runtime_set_autosuspend_delay(dev, FIMC_AUTOSUSPEND_DELAY);
1349 pm_runtime_enable(dev);
1351 ret = component_add(dev, &fimc_component_ops);
1355 dev_info(dev, "drm fimc registered successfully.\n");
1360 pm_runtime_dont_use_autosuspend(dev);
1361 pm_runtime_disable(dev);
1362 fimc_put_clocks(ctx);
1367 static int fimc_remove(struct platform_device *pdev)
1369 struct device *dev = &pdev->dev;
1370 struct fimc_context *ctx = get_fimc_context(dev);
1372 component_del(dev, &fimc_component_ops);
1373 pm_runtime_dont_use_autosuspend(dev);
1374 pm_runtime_disable(dev);
1376 fimc_put_clocks(ctx);
1382 static int fimc_runtime_suspend(struct device *dev)
1384 struct fimc_context *ctx = get_fimc_context(dev);
1386 DRM_DEV_DEBUG_KMS(dev, "id[%d]\n", ctx->id);
1387 clk_disable_unprepare(ctx->clocks[FIMC_CLK_GATE]);
1391 static int fimc_runtime_resume(struct device *dev)
1393 struct fimc_context *ctx = get_fimc_context(dev);
1395 DRM_DEV_DEBUG_KMS(dev, "id[%d]\n", ctx->id);
1396 return clk_prepare_enable(ctx->clocks[FIMC_CLK_GATE]);
1400 static const struct dev_pm_ops fimc_pm_ops = {
1401 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
1402 pm_runtime_force_resume)
1403 SET_RUNTIME_PM_OPS(fimc_runtime_suspend, fimc_runtime_resume, NULL)
1406 static const struct of_device_id fimc_of_match[] = {
1407 { .compatible = "samsung,exynos4210-fimc" },
1408 { .compatible = "samsung,exynos4212-fimc" },
1411 MODULE_DEVICE_TABLE(of, fimc_of_match);
1413 struct platform_driver fimc_driver = {
1414 .probe = fimc_probe,
1415 .remove = fimc_remove,
1417 .of_match_table = fimc_of_match,
1418 .name = "exynos-drm-fimc",
1419 .owner = THIS_MODULE,