18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2012 Samsung Electronics Co.Ltd 48c2ecf20Sopenharmony_ci * Authors: 58c2ecf20Sopenharmony_ci * Eunchul Kim <chulspro.kim@samsung.com> 68c2ecf20Sopenharmony_ci * Jinyoung Jeon <jy0.jeon@samsung.com> 78c2ecf20Sopenharmony_ci * Sangmin Lee <lsmin.lee@samsung.com> 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <linux/clk.h> 118c2ecf20Sopenharmony_ci#include <linux/component.h> 128c2ecf20Sopenharmony_ci#include <linux/kernel.h> 138c2ecf20Sopenharmony_ci#include <linux/mfd/syscon.h> 148c2ecf20Sopenharmony_ci#include <linux/of.h> 158c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 168c2ecf20Sopenharmony_ci#include <linux/pm_runtime.h> 178c2ecf20Sopenharmony_ci#include <linux/regmap.h> 188c2ecf20Sopenharmony_ci#include <linux/spinlock.h> 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#include <drm/drm_fourcc.h> 218c2ecf20Sopenharmony_ci#include <drm/drm_print.h> 228c2ecf20Sopenharmony_ci#include <drm/exynos_drm.h> 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci#include "exynos_drm_drv.h" 258c2ecf20Sopenharmony_ci#include "exynos_drm_ipp.h" 268c2ecf20Sopenharmony_ci#include "regs-fimc.h" 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci/* 298c2ecf20Sopenharmony_ci * FIMC stands for Fully Interactive Mobile Camera and 308c2ecf20Sopenharmony_ci * supports image scaler/rotator and input/output DMA operations. 318c2ecf20Sopenharmony_ci * input DMA reads image data from the memory. 328c2ecf20Sopenharmony_ci * output DMA writes image data to memory. 338c2ecf20Sopenharmony_ci * FIMC supports image rotation and image effect functions. 348c2ecf20Sopenharmony_ci */ 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#define FIMC_MAX_DEVS 4 378c2ecf20Sopenharmony_ci#define FIMC_MAX_SRC 2 388c2ecf20Sopenharmony_ci#define FIMC_MAX_DST 32 398c2ecf20Sopenharmony_ci#define FIMC_SHFACTOR 10 408c2ecf20Sopenharmony_ci#define FIMC_BUF_STOP 1 418c2ecf20Sopenharmony_ci#define FIMC_BUF_START 2 428c2ecf20Sopenharmony_ci#define FIMC_WIDTH_ITU_709 1280 438c2ecf20Sopenharmony_ci#define FIMC_AUTOSUSPEND_DELAY 2000 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_cistatic unsigned int fimc_mask = 0xc; 468c2ecf20Sopenharmony_cimodule_param_named(fimc_devs, fimc_mask, uint, 0644); 478c2ecf20Sopenharmony_ciMODULE_PARM_DESC(fimc_devs, "Alias mask for assigning FIMC devices to Exynos DRM"); 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci#define get_fimc_context(dev) dev_get_drvdata(dev) 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_cienum { 528c2ecf20Sopenharmony_ci FIMC_CLK_LCLK, 538c2ecf20Sopenharmony_ci FIMC_CLK_GATE, 548c2ecf20Sopenharmony_ci FIMC_CLK_WB_A, 558c2ecf20Sopenharmony_ci FIMC_CLK_WB_B, 568c2ecf20Sopenharmony_ci FIMC_CLKS_MAX 578c2ecf20Sopenharmony_ci}; 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_cistatic const char * const fimc_clock_names[] = { 608c2ecf20Sopenharmony_ci [FIMC_CLK_LCLK] = "sclk_fimc", 618c2ecf20Sopenharmony_ci [FIMC_CLK_GATE] = "fimc", 628c2ecf20Sopenharmony_ci [FIMC_CLK_WB_A] = "pxl_async0", 638c2ecf20Sopenharmony_ci [FIMC_CLK_WB_B] = "pxl_async1", 648c2ecf20Sopenharmony_ci}; 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci/* 678c2ecf20Sopenharmony_ci * A structure of scaler. 688c2ecf20Sopenharmony_ci * 698c2ecf20Sopenharmony_ci * @range: narrow, wide. 708c2ecf20Sopenharmony_ci * @bypass: unused scaler path. 718c2ecf20Sopenharmony_ci * @up_h: horizontal scale up. 728c2ecf20Sopenharmony_ci * @up_v: vertical scale up. 738c2ecf20Sopenharmony_ci * @hratio: horizontal ratio. 748c2ecf20Sopenharmony_ci * @vratio: vertical ratio. 758c2ecf20Sopenharmony_ci */ 768c2ecf20Sopenharmony_cistruct fimc_scaler { 778c2ecf20Sopenharmony_ci bool range; 788c2ecf20Sopenharmony_ci bool bypass; 798c2ecf20Sopenharmony_ci bool up_h; 808c2ecf20Sopenharmony_ci bool up_v; 818c2ecf20Sopenharmony_ci u32 hratio; 828c2ecf20Sopenharmony_ci u32 vratio; 838c2ecf20Sopenharmony_ci}; 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci/* 868c2ecf20Sopenharmony_ci * A structure of fimc context. 878c2ecf20Sopenharmony_ci * 888c2ecf20Sopenharmony_ci * @regs_res: register resources. 898c2ecf20Sopenharmony_ci * @regs: memory mapped io registers. 908c2ecf20Sopenharmony_ci * @lock: locking of operations. 918c2ecf20Sopenharmony_ci * @clocks: fimc clocks. 928c2ecf20Sopenharmony_ci * @sc: scaler infomations. 938c2ecf20Sopenharmony_ci * @pol: porarity of writeback. 948c2ecf20Sopenharmony_ci * @id: fimc id. 958c2ecf20Sopenharmony_ci * @irq: irq number. 968c2ecf20Sopenharmony_ci */ 978c2ecf20Sopenharmony_cistruct fimc_context { 988c2ecf20Sopenharmony_ci struct exynos_drm_ipp ipp; 998c2ecf20Sopenharmony_ci struct drm_device *drm_dev; 1008c2ecf20Sopenharmony_ci void *dma_priv; 1018c2ecf20Sopenharmony_ci struct device *dev; 1028c2ecf20Sopenharmony_ci struct exynos_drm_ipp_task *task; 1038c2ecf20Sopenharmony_ci struct exynos_drm_ipp_formats *formats; 1048c2ecf20Sopenharmony_ci unsigned int num_formats; 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci struct resource *regs_res; 1078c2ecf20Sopenharmony_ci void __iomem *regs; 1088c2ecf20Sopenharmony_ci spinlock_t lock; 1098c2ecf20Sopenharmony_ci struct clk *clocks[FIMC_CLKS_MAX]; 1108c2ecf20Sopenharmony_ci struct fimc_scaler sc; 1118c2ecf20Sopenharmony_ci int id; 1128c2ecf20Sopenharmony_ci int irq; 1138c2ecf20Sopenharmony_ci}; 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_cistatic u32 fimc_read(struct fimc_context *ctx, u32 reg) 1168c2ecf20Sopenharmony_ci{ 1178c2ecf20Sopenharmony_ci return readl(ctx->regs + reg); 1188c2ecf20Sopenharmony_ci} 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_cistatic void fimc_write(struct fimc_context *ctx, u32 val, u32 reg) 1218c2ecf20Sopenharmony_ci{ 1228c2ecf20Sopenharmony_ci writel(val, ctx->regs + reg); 1238c2ecf20Sopenharmony_ci} 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_cistatic void fimc_set_bits(struct fimc_context *ctx, u32 reg, u32 bits) 1268c2ecf20Sopenharmony_ci{ 1278c2ecf20Sopenharmony_ci void __iomem *r = ctx->regs + reg; 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci writel(readl(r) | bits, r); 1308c2ecf20Sopenharmony_ci} 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_cistatic void fimc_clear_bits(struct fimc_context *ctx, u32 reg, u32 bits) 1338c2ecf20Sopenharmony_ci{ 1348c2ecf20Sopenharmony_ci void __iomem *r = ctx->regs + reg; 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci writel(readl(r) & ~bits, r); 1378c2ecf20Sopenharmony_ci} 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_cistatic void fimc_sw_reset(struct fimc_context *ctx) 1408c2ecf20Sopenharmony_ci{ 1418c2ecf20Sopenharmony_ci u32 cfg; 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci /* stop dma operation */ 1448c2ecf20Sopenharmony_ci cfg = fimc_read(ctx, EXYNOS_CISTATUS); 1458c2ecf20Sopenharmony_ci if (EXYNOS_CISTATUS_GET_ENVID_STATUS(cfg)) 1468c2ecf20Sopenharmony_ci fimc_clear_bits(ctx, EXYNOS_MSCTRL, EXYNOS_MSCTRL_ENVID); 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci fimc_set_bits(ctx, EXYNOS_CISRCFMT, EXYNOS_CISRCFMT_ITU601_8BIT); 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci /* disable image capture */ 1518c2ecf20Sopenharmony_ci fimc_clear_bits(ctx, EXYNOS_CIIMGCPT, 1528c2ecf20Sopenharmony_ci EXYNOS_CIIMGCPT_IMGCPTEN_SC | EXYNOS_CIIMGCPT_IMGCPTEN); 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci /* s/w reset */ 1558c2ecf20Sopenharmony_ci fimc_set_bits(ctx, EXYNOS_CIGCTRL, EXYNOS_CIGCTRL_SWRST); 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci /* s/w reset complete */ 1588c2ecf20Sopenharmony_ci fimc_clear_bits(ctx, EXYNOS_CIGCTRL, EXYNOS_CIGCTRL_SWRST); 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci /* reset sequence */ 1618c2ecf20Sopenharmony_ci fimc_write(ctx, 0x0, EXYNOS_CIFCNTSEQ); 1628c2ecf20Sopenharmony_ci} 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_cistatic void fimc_set_type_ctrl(struct fimc_context *ctx) 1658c2ecf20Sopenharmony_ci{ 1668c2ecf20Sopenharmony_ci u32 cfg; 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_ci cfg = fimc_read(ctx, EXYNOS_CIGCTRL); 1698c2ecf20Sopenharmony_ci cfg &= ~(EXYNOS_CIGCTRL_TESTPATTERN_MASK | 1708c2ecf20Sopenharmony_ci EXYNOS_CIGCTRL_SELCAM_ITU_MASK | 1718c2ecf20Sopenharmony_ci EXYNOS_CIGCTRL_SELCAM_MIPI_MASK | 1728c2ecf20Sopenharmony_ci EXYNOS_CIGCTRL_SELCAM_FIMC_MASK | 1738c2ecf20Sopenharmony_ci EXYNOS_CIGCTRL_SELWB_CAMIF_MASK | 1748c2ecf20Sopenharmony_ci EXYNOS_CIGCTRL_SELWRITEBACK_MASK); 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci cfg |= (EXYNOS_CIGCTRL_SELCAM_ITU_A | 1778c2ecf20Sopenharmony_ci EXYNOS_CIGCTRL_SELWRITEBACK_A | 1788c2ecf20Sopenharmony_ci EXYNOS_CIGCTRL_SELCAM_MIPI_A | 1798c2ecf20Sopenharmony_ci EXYNOS_CIGCTRL_SELCAM_FIMC_ITU); 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CIGCTRL); 1828c2ecf20Sopenharmony_ci} 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_cistatic void fimc_handle_jpeg(struct fimc_context *ctx, bool enable) 1858c2ecf20Sopenharmony_ci{ 1868c2ecf20Sopenharmony_ci u32 cfg; 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci DRM_DEV_DEBUG_KMS(ctx->dev, "enable[%d]\n", enable); 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ci cfg = fimc_read(ctx, EXYNOS_CIGCTRL); 1918c2ecf20Sopenharmony_ci if (enable) 1928c2ecf20Sopenharmony_ci cfg |= EXYNOS_CIGCTRL_CAM_JPEG; 1938c2ecf20Sopenharmony_ci else 1948c2ecf20Sopenharmony_ci cfg &= ~EXYNOS_CIGCTRL_CAM_JPEG; 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CIGCTRL); 1978c2ecf20Sopenharmony_ci} 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_cistatic void fimc_mask_irq(struct fimc_context *ctx, bool enable) 2008c2ecf20Sopenharmony_ci{ 2018c2ecf20Sopenharmony_ci u32 cfg; 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_ci DRM_DEV_DEBUG_KMS(ctx->dev, "enable[%d]\n", enable); 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ci cfg = fimc_read(ctx, EXYNOS_CIGCTRL); 2068c2ecf20Sopenharmony_ci if (enable) { 2078c2ecf20Sopenharmony_ci cfg &= ~EXYNOS_CIGCTRL_IRQ_OVFEN; 2088c2ecf20Sopenharmony_ci cfg |= EXYNOS_CIGCTRL_IRQ_ENABLE | EXYNOS_CIGCTRL_IRQ_LEVEL; 2098c2ecf20Sopenharmony_ci } else 2108c2ecf20Sopenharmony_ci cfg &= ~EXYNOS_CIGCTRL_IRQ_ENABLE; 2118c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CIGCTRL); 2128c2ecf20Sopenharmony_ci} 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_cistatic void fimc_clear_irq(struct fimc_context *ctx) 2158c2ecf20Sopenharmony_ci{ 2168c2ecf20Sopenharmony_ci fimc_set_bits(ctx, EXYNOS_CIGCTRL, EXYNOS_CIGCTRL_IRQ_CLR); 2178c2ecf20Sopenharmony_ci} 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_cistatic bool fimc_check_ovf(struct fimc_context *ctx) 2208c2ecf20Sopenharmony_ci{ 2218c2ecf20Sopenharmony_ci u32 status, flag; 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci status = fimc_read(ctx, EXYNOS_CISTATUS); 2248c2ecf20Sopenharmony_ci flag = EXYNOS_CISTATUS_OVFIY | EXYNOS_CISTATUS_OVFICB | 2258c2ecf20Sopenharmony_ci EXYNOS_CISTATUS_OVFICR; 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ci DRM_DEV_DEBUG_KMS(ctx->dev, "flag[0x%x]\n", flag); 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ci if (status & flag) { 2308c2ecf20Sopenharmony_ci fimc_set_bits(ctx, EXYNOS_CIWDOFST, 2318c2ecf20Sopenharmony_ci EXYNOS_CIWDOFST_CLROVFIY | EXYNOS_CIWDOFST_CLROVFICB | 2328c2ecf20Sopenharmony_ci EXYNOS_CIWDOFST_CLROVFICR); 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ci DRM_DEV_ERROR(ctx->dev, 2358c2ecf20Sopenharmony_ci "occurred overflow at %d, status 0x%x.\n", 2368c2ecf20Sopenharmony_ci ctx->id, status); 2378c2ecf20Sopenharmony_ci return true; 2388c2ecf20Sopenharmony_ci } 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_ci return false; 2418c2ecf20Sopenharmony_ci} 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_cistatic bool fimc_check_frame_end(struct fimc_context *ctx) 2448c2ecf20Sopenharmony_ci{ 2458c2ecf20Sopenharmony_ci u32 cfg; 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_ci cfg = fimc_read(ctx, EXYNOS_CISTATUS); 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_ci DRM_DEV_DEBUG_KMS(ctx->dev, "cfg[0x%x]\n", cfg); 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci if (!(cfg & EXYNOS_CISTATUS_FRAMEEND)) 2528c2ecf20Sopenharmony_ci return false; 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_ci cfg &= ~(EXYNOS_CISTATUS_FRAMEEND); 2558c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CISTATUS); 2568c2ecf20Sopenharmony_ci 2578c2ecf20Sopenharmony_ci return true; 2588c2ecf20Sopenharmony_ci} 2598c2ecf20Sopenharmony_ci 2608c2ecf20Sopenharmony_cistatic int fimc_get_buf_id(struct fimc_context *ctx) 2618c2ecf20Sopenharmony_ci{ 2628c2ecf20Sopenharmony_ci u32 cfg; 2638c2ecf20Sopenharmony_ci int frame_cnt, buf_id; 2648c2ecf20Sopenharmony_ci 2658c2ecf20Sopenharmony_ci cfg = fimc_read(ctx, EXYNOS_CISTATUS2); 2668c2ecf20Sopenharmony_ci frame_cnt = EXYNOS_CISTATUS2_GET_FRAMECOUNT_BEFORE(cfg); 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_ci if (frame_cnt == 0) 2698c2ecf20Sopenharmony_ci frame_cnt = EXYNOS_CISTATUS2_GET_FRAMECOUNT_PRESENT(cfg); 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_ci DRM_DEV_DEBUG_KMS(ctx->dev, "present[%d]before[%d]\n", 2728c2ecf20Sopenharmony_ci EXYNOS_CISTATUS2_GET_FRAMECOUNT_PRESENT(cfg), 2738c2ecf20Sopenharmony_ci EXYNOS_CISTATUS2_GET_FRAMECOUNT_BEFORE(cfg)); 2748c2ecf20Sopenharmony_ci 2758c2ecf20Sopenharmony_ci if (frame_cnt == 0) { 2768c2ecf20Sopenharmony_ci DRM_DEV_ERROR(ctx->dev, "failed to get frame count.\n"); 2778c2ecf20Sopenharmony_ci return -EIO; 2788c2ecf20Sopenharmony_ci } 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_ci buf_id = frame_cnt - 1; 2818c2ecf20Sopenharmony_ci DRM_DEV_DEBUG_KMS(ctx->dev, "buf_id[%d]\n", buf_id); 2828c2ecf20Sopenharmony_ci 2838c2ecf20Sopenharmony_ci return buf_id; 2848c2ecf20Sopenharmony_ci} 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_cistatic void fimc_handle_lastend(struct fimc_context *ctx, bool enable) 2878c2ecf20Sopenharmony_ci{ 2888c2ecf20Sopenharmony_ci u32 cfg; 2898c2ecf20Sopenharmony_ci 2908c2ecf20Sopenharmony_ci DRM_DEV_DEBUG_KMS(ctx->dev, "enable[%d]\n", enable); 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ci cfg = fimc_read(ctx, EXYNOS_CIOCTRL); 2938c2ecf20Sopenharmony_ci if (enable) 2948c2ecf20Sopenharmony_ci cfg |= EXYNOS_CIOCTRL_LASTENDEN; 2958c2ecf20Sopenharmony_ci else 2968c2ecf20Sopenharmony_ci cfg &= ~EXYNOS_CIOCTRL_LASTENDEN; 2978c2ecf20Sopenharmony_ci 2988c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CIOCTRL); 2998c2ecf20Sopenharmony_ci} 3008c2ecf20Sopenharmony_ci 3018c2ecf20Sopenharmony_cistatic void fimc_src_set_fmt_order(struct fimc_context *ctx, u32 fmt) 3028c2ecf20Sopenharmony_ci{ 3038c2ecf20Sopenharmony_ci u32 cfg; 3048c2ecf20Sopenharmony_ci 3058c2ecf20Sopenharmony_ci DRM_DEV_DEBUG_KMS(ctx->dev, "fmt[0x%x]\n", fmt); 3068c2ecf20Sopenharmony_ci 3078c2ecf20Sopenharmony_ci /* RGB */ 3088c2ecf20Sopenharmony_ci cfg = fimc_read(ctx, EXYNOS_CISCCTRL); 3098c2ecf20Sopenharmony_ci cfg &= ~EXYNOS_CISCCTRL_INRGB_FMT_RGB_MASK; 3108c2ecf20Sopenharmony_ci 3118c2ecf20Sopenharmony_ci switch (fmt) { 3128c2ecf20Sopenharmony_ci case DRM_FORMAT_RGB565: 3138c2ecf20Sopenharmony_ci cfg |= EXYNOS_CISCCTRL_INRGB_FMT_RGB565; 3148c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CISCCTRL); 3158c2ecf20Sopenharmony_ci return; 3168c2ecf20Sopenharmony_ci case DRM_FORMAT_RGB888: 3178c2ecf20Sopenharmony_ci case DRM_FORMAT_XRGB8888: 3188c2ecf20Sopenharmony_ci cfg |= EXYNOS_CISCCTRL_INRGB_FMT_RGB888; 3198c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CISCCTRL); 3208c2ecf20Sopenharmony_ci return; 3218c2ecf20Sopenharmony_ci default: 3228c2ecf20Sopenharmony_ci /* bypass */ 3238c2ecf20Sopenharmony_ci break; 3248c2ecf20Sopenharmony_ci } 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_ci /* YUV */ 3278c2ecf20Sopenharmony_ci cfg = fimc_read(ctx, EXYNOS_MSCTRL); 3288c2ecf20Sopenharmony_ci cfg &= ~(EXYNOS_MSCTRL_ORDER2P_SHIFT_MASK | 3298c2ecf20Sopenharmony_ci EXYNOS_MSCTRL_C_INT_IN_2PLANE | 3308c2ecf20Sopenharmony_ci EXYNOS_MSCTRL_ORDER422_YCBYCR); 3318c2ecf20Sopenharmony_ci 3328c2ecf20Sopenharmony_ci switch (fmt) { 3338c2ecf20Sopenharmony_ci case DRM_FORMAT_YUYV: 3348c2ecf20Sopenharmony_ci cfg |= EXYNOS_MSCTRL_ORDER422_YCBYCR; 3358c2ecf20Sopenharmony_ci break; 3368c2ecf20Sopenharmony_ci case DRM_FORMAT_YVYU: 3378c2ecf20Sopenharmony_ci cfg |= EXYNOS_MSCTRL_ORDER422_YCRYCB; 3388c2ecf20Sopenharmony_ci break; 3398c2ecf20Sopenharmony_ci case DRM_FORMAT_UYVY: 3408c2ecf20Sopenharmony_ci cfg |= EXYNOS_MSCTRL_ORDER422_CBYCRY; 3418c2ecf20Sopenharmony_ci break; 3428c2ecf20Sopenharmony_ci case DRM_FORMAT_VYUY: 3438c2ecf20Sopenharmony_ci case DRM_FORMAT_YUV444: 3448c2ecf20Sopenharmony_ci cfg |= EXYNOS_MSCTRL_ORDER422_CRYCBY; 3458c2ecf20Sopenharmony_ci break; 3468c2ecf20Sopenharmony_ci case DRM_FORMAT_NV21: 3478c2ecf20Sopenharmony_ci case DRM_FORMAT_NV61: 3488c2ecf20Sopenharmony_ci cfg |= (EXYNOS_MSCTRL_ORDER2P_LSB_CRCB | 3498c2ecf20Sopenharmony_ci EXYNOS_MSCTRL_C_INT_IN_2PLANE); 3508c2ecf20Sopenharmony_ci break; 3518c2ecf20Sopenharmony_ci case DRM_FORMAT_YUV422: 3528c2ecf20Sopenharmony_ci case DRM_FORMAT_YUV420: 3538c2ecf20Sopenharmony_ci case DRM_FORMAT_YVU420: 3548c2ecf20Sopenharmony_ci cfg |= EXYNOS_MSCTRL_C_INT_IN_3PLANE; 3558c2ecf20Sopenharmony_ci break; 3568c2ecf20Sopenharmony_ci case DRM_FORMAT_NV12: 3578c2ecf20Sopenharmony_ci case DRM_FORMAT_NV16: 3588c2ecf20Sopenharmony_ci cfg |= (EXYNOS_MSCTRL_ORDER2P_LSB_CBCR | 3598c2ecf20Sopenharmony_ci EXYNOS_MSCTRL_C_INT_IN_2PLANE); 3608c2ecf20Sopenharmony_ci break; 3618c2ecf20Sopenharmony_ci } 3628c2ecf20Sopenharmony_ci 3638c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_MSCTRL); 3648c2ecf20Sopenharmony_ci} 3658c2ecf20Sopenharmony_ci 3668c2ecf20Sopenharmony_cistatic void fimc_src_set_fmt(struct fimc_context *ctx, u32 fmt, bool tiled) 3678c2ecf20Sopenharmony_ci{ 3688c2ecf20Sopenharmony_ci u32 cfg; 3698c2ecf20Sopenharmony_ci 3708c2ecf20Sopenharmony_ci DRM_DEV_DEBUG_KMS(ctx->dev, "fmt[0x%x]\n", fmt); 3718c2ecf20Sopenharmony_ci 3728c2ecf20Sopenharmony_ci cfg = fimc_read(ctx, EXYNOS_MSCTRL); 3738c2ecf20Sopenharmony_ci cfg &= ~EXYNOS_MSCTRL_INFORMAT_RGB; 3748c2ecf20Sopenharmony_ci 3758c2ecf20Sopenharmony_ci switch (fmt) { 3768c2ecf20Sopenharmony_ci case DRM_FORMAT_RGB565: 3778c2ecf20Sopenharmony_ci case DRM_FORMAT_RGB888: 3788c2ecf20Sopenharmony_ci case DRM_FORMAT_XRGB8888: 3798c2ecf20Sopenharmony_ci cfg |= EXYNOS_MSCTRL_INFORMAT_RGB; 3808c2ecf20Sopenharmony_ci break; 3818c2ecf20Sopenharmony_ci case DRM_FORMAT_YUV444: 3828c2ecf20Sopenharmony_ci cfg |= EXYNOS_MSCTRL_INFORMAT_YCBCR420; 3838c2ecf20Sopenharmony_ci break; 3848c2ecf20Sopenharmony_ci case DRM_FORMAT_YUYV: 3858c2ecf20Sopenharmony_ci case DRM_FORMAT_YVYU: 3868c2ecf20Sopenharmony_ci case DRM_FORMAT_UYVY: 3878c2ecf20Sopenharmony_ci case DRM_FORMAT_VYUY: 3888c2ecf20Sopenharmony_ci cfg |= EXYNOS_MSCTRL_INFORMAT_YCBCR422_1PLANE; 3898c2ecf20Sopenharmony_ci break; 3908c2ecf20Sopenharmony_ci case DRM_FORMAT_NV16: 3918c2ecf20Sopenharmony_ci case DRM_FORMAT_NV61: 3928c2ecf20Sopenharmony_ci case DRM_FORMAT_YUV422: 3938c2ecf20Sopenharmony_ci cfg |= EXYNOS_MSCTRL_INFORMAT_YCBCR422; 3948c2ecf20Sopenharmony_ci break; 3958c2ecf20Sopenharmony_ci case DRM_FORMAT_YUV420: 3968c2ecf20Sopenharmony_ci case DRM_FORMAT_YVU420: 3978c2ecf20Sopenharmony_ci case DRM_FORMAT_NV12: 3988c2ecf20Sopenharmony_ci case DRM_FORMAT_NV21: 3998c2ecf20Sopenharmony_ci cfg |= EXYNOS_MSCTRL_INFORMAT_YCBCR420; 4008c2ecf20Sopenharmony_ci break; 4018c2ecf20Sopenharmony_ci } 4028c2ecf20Sopenharmony_ci 4038c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_MSCTRL); 4048c2ecf20Sopenharmony_ci 4058c2ecf20Sopenharmony_ci cfg = fimc_read(ctx, EXYNOS_CIDMAPARAM); 4068c2ecf20Sopenharmony_ci cfg &= ~EXYNOS_CIDMAPARAM_R_MODE_MASK; 4078c2ecf20Sopenharmony_ci 4088c2ecf20Sopenharmony_ci if (tiled) 4098c2ecf20Sopenharmony_ci cfg |= EXYNOS_CIDMAPARAM_R_MODE_64X32; 4108c2ecf20Sopenharmony_ci else 4118c2ecf20Sopenharmony_ci cfg |= EXYNOS_CIDMAPARAM_R_MODE_LINEAR; 4128c2ecf20Sopenharmony_ci 4138c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CIDMAPARAM); 4148c2ecf20Sopenharmony_ci 4158c2ecf20Sopenharmony_ci fimc_src_set_fmt_order(ctx, fmt); 4168c2ecf20Sopenharmony_ci} 4178c2ecf20Sopenharmony_ci 4188c2ecf20Sopenharmony_cistatic void fimc_src_set_transf(struct fimc_context *ctx, unsigned int rotation) 4198c2ecf20Sopenharmony_ci{ 4208c2ecf20Sopenharmony_ci unsigned int degree = rotation & DRM_MODE_ROTATE_MASK; 4218c2ecf20Sopenharmony_ci u32 cfg1, cfg2; 4228c2ecf20Sopenharmony_ci 4238c2ecf20Sopenharmony_ci DRM_DEV_DEBUG_KMS(ctx->dev, "rotation[%x]\n", rotation); 4248c2ecf20Sopenharmony_ci 4258c2ecf20Sopenharmony_ci cfg1 = fimc_read(ctx, EXYNOS_MSCTRL); 4268c2ecf20Sopenharmony_ci cfg1 &= ~(EXYNOS_MSCTRL_FLIP_X_MIRROR | 4278c2ecf20Sopenharmony_ci EXYNOS_MSCTRL_FLIP_Y_MIRROR); 4288c2ecf20Sopenharmony_ci 4298c2ecf20Sopenharmony_ci cfg2 = fimc_read(ctx, EXYNOS_CITRGFMT); 4308c2ecf20Sopenharmony_ci cfg2 &= ~EXYNOS_CITRGFMT_INROT90_CLOCKWISE; 4318c2ecf20Sopenharmony_ci 4328c2ecf20Sopenharmony_ci switch (degree) { 4338c2ecf20Sopenharmony_ci case DRM_MODE_ROTATE_0: 4348c2ecf20Sopenharmony_ci if (rotation & DRM_MODE_REFLECT_X) 4358c2ecf20Sopenharmony_ci cfg1 |= EXYNOS_MSCTRL_FLIP_X_MIRROR; 4368c2ecf20Sopenharmony_ci if (rotation & DRM_MODE_REFLECT_Y) 4378c2ecf20Sopenharmony_ci cfg1 |= EXYNOS_MSCTRL_FLIP_Y_MIRROR; 4388c2ecf20Sopenharmony_ci break; 4398c2ecf20Sopenharmony_ci case DRM_MODE_ROTATE_90: 4408c2ecf20Sopenharmony_ci cfg2 |= EXYNOS_CITRGFMT_INROT90_CLOCKWISE; 4418c2ecf20Sopenharmony_ci if (rotation & DRM_MODE_REFLECT_X) 4428c2ecf20Sopenharmony_ci cfg1 |= EXYNOS_MSCTRL_FLIP_X_MIRROR; 4438c2ecf20Sopenharmony_ci if (rotation & DRM_MODE_REFLECT_Y) 4448c2ecf20Sopenharmony_ci cfg1 |= EXYNOS_MSCTRL_FLIP_Y_MIRROR; 4458c2ecf20Sopenharmony_ci break; 4468c2ecf20Sopenharmony_ci case DRM_MODE_ROTATE_180: 4478c2ecf20Sopenharmony_ci cfg1 |= (EXYNOS_MSCTRL_FLIP_X_MIRROR | 4488c2ecf20Sopenharmony_ci EXYNOS_MSCTRL_FLIP_Y_MIRROR); 4498c2ecf20Sopenharmony_ci if (rotation & DRM_MODE_REFLECT_X) 4508c2ecf20Sopenharmony_ci cfg1 &= ~EXYNOS_MSCTRL_FLIP_X_MIRROR; 4518c2ecf20Sopenharmony_ci if (rotation & DRM_MODE_REFLECT_Y) 4528c2ecf20Sopenharmony_ci cfg1 &= ~EXYNOS_MSCTRL_FLIP_Y_MIRROR; 4538c2ecf20Sopenharmony_ci break; 4548c2ecf20Sopenharmony_ci case DRM_MODE_ROTATE_270: 4558c2ecf20Sopenharmony_ci cfg1 |= (EXYNOS_MSCTRL_FLIP_X_MIRROR | 4568c2ecf20Sopenharmony_ci EXYNOS_MSCTRL_FLIP_Y_MIRROR); 4578c2ecf20Sopenharmony_ci cfg2 |= EXYNOS_CITRGFMT_INROT90_CLOCKWISE; 4588c2ecf20Sopenharmony_ci if (rotation & DRM_MODE_REFLECT_X) 4598c2ecf20Sopenharmony_ci cfg1 &= ~EXYNOS_MSCTRL_FLIP_X_MIRROR; 4608c2ecf20Sopenharmony_ci if (rotation & DRM_MODE_REFLECT_Y) 4618c2ecf20Sopenharmony_ci cfg1 &= ~EXYNOS_MSCTRL_FLIP_Y_MIRROR; 4628c2ecf20Sopenharmony_ci break; 4638c2ecf20Sopenharmony_ci } 4648c2ecf20Sopenharmony_ci 4658c2ecf20Sopenharmony_ci fimc_write(ctx, cfg1, EXYNOS_MSCTRL); 4668c2ecf20Sopenharmony_ci fimc_write(ctx, cfg2, EXYNOS_CITRGFMT); 4678c2ecf20Sopenharmony_ci} 4688c2ecf20Sopenharmony_ci 4698c2ecf20Sopenharmony_cistatic void fimc_set_window(struct fimc_context *ctx, 4708c2ecf20Sopenharmony_ci struct exynos_drm_ipp_buffer *buf) 4718c2ecf20Sopenharmony_ci{ 4728c2ecf20Sopenharmony_ci unsigned int real_width = buf->buf.pitch[0] / buf->format->cpp[0]; 4738c2ecf20Sopenharmony_ci u32 cfg, h1, h2, v1, v2; 4748c2ecf20Sopenharmony_ci 4758c2ecf20Sopenharmony_ci /* cropped image */ 4768c2ecf20Sopenharmony_ci h1 = buf->rect.x; 4778c2ecf20Sopenharmony_ci h2 = real_width - buf->rect.w - buf->rect.x; 4788c2ecf20Sopenharmony_ci v1 = buf->rect.y; 4798c2ecf20Sopenharmony_ci v2 = buf->buf.height - buf->rect.h - buf->rect.y; 4808c2ecf20Sopenharmony_ci 4818c2ecf20Sopenharmony_ci DRM_DEV_DEBUG_KMS(ctx->dev, "x[%d]y[%d]w[%d]h[%d]hsize[%d]vsize[%d]\n", 4828c2ecf20Sopenharmony_ci buf->rect.x, buf->rect.y, buf->rect.w, buf->rect.h, 4838c2ecf20Sopenharmony_ci real_width, buf->buf.height); 4848c2ecf20Sopenharmony_ci DRM_DEV_DEBUG_KMS(ctx->dev, "h1[%d]h2[%d]v1[%d]v2[%d]\n", h1, h2, v1, 4858c2ecf20Sopenharmony_ci v2); 4868c2ecf20Sopenharmony_ci 4878c2ecf20Sopenharmony_ci /* 4888c2ecf20Sopenharmony_ci * set window offset 1, 2 size 4898c2ecf20Sopenharmony_ci * check figure 43-21 in user manual 4908c2ecf20Sopenharmony_ci */ 4918c2ecf20Sopenharmony_ci cfg = fimc_read(ctx, EXYNOS_CIWDOFST); 4928c2ecf20Sopenharmony_ci cfg &= ~(EXYNOS_CIWDOFST_WINHOROFST_MASK | 4938c2ecf20Sopenharmony_ci EXYNOS_CIWDOFST_WINVEROFST_MASK); 4948c2ecf20Sopenharmony_ci cfg |= (EXYNOS_CIWDOFST_WINHOROFST(h1) | 4958c2ecf20Sopenharmony_ci EXYNOS_CIWDOFST_WINVEROFST(v1)); 4968c2ecf20Sopenharmony_ci cfg |= EXYNOS_CIWDOFST_WINOFSEN; 4978c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CIWDOFST); 4988c2ecf20Sopenharmony_ci 4998c2ecf20Sopenharmony_ci cfg = (EXYNOS_CIWDOFST2_WINHOROFST2(h2) | 5008c2ecf20Sopenharmony_ci EXYNOS_CIWDOFST2_WINVEROFST2(v2)); 5018c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CIWDOFST2); 5028c2ecf20Sopenharmony_ci} 5038c2ecf20Sopenharmony_ci 5048c2ecf20Sopenharmony_cistatic void fimc_src_set_size(struct fimc_context *ctx, 5058c2ecf20Sopenharmony_ci struct exynos_drm_ipp_buffer *buf) 5068c2ecf20Sopenharmony_ci{ 5078c2ecf20Sopenharmony_ci unsigned int real_width = buf->buf.pitch[0] / buf->format->cpp[0]; 5088c2ecf20Sopenharmony_ci u32 cfg; 5098c2ecf20Sopenharmony_ci 5108c2ecf20Sopenharmony_ci DRM_DEV_DEBUG_KMS(ctx->dev, "hsize[%d]vsize[%d]\n", real_width, 5118c2ecf20Sopenharmony_ci buf->buf.height); 5128c2ecf20Sopenharmony_ci 5138c2ecf20Sopenharmony_ci /* original size */ 5148c2ecf20Sopenharmony_ci cfg = (EXYNOS_ORGISIZE_HORIZONTAL(real_width) | 5158c2ecf20Sopenharmony_ci EXYNOS_ORGISIZE_VERTICAL(buf->buf.height)); 5168c2ecf20Sopenharmony_ci 5178c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_ORGISIZE); 5188c2ecf20Sopenharmony_ci 5198c2ecf20Sopenharmony_ci DRM_DEV_DEBUG_KMS(ctx->dev, "x[%d]y[%d]w[%d]h[%d]\n", buf->rect.x, 5208c2ecf20Sopenharmony_ci buf->rect.y, buf->rect.w, buf->rect.h); 5218c2ecf20Sopenharmony_ci 5228c2ecf20Sopenharmony_ci /* set input DMA image size */ 5238c2ecf20Sopenharmony_ci cfg = fimc_read(ctx, EXYNOS_CIREAL_ISIZE); 5248c2ecf20Sopenharmony_ci cfg &= ~(EXYNOS_CIREAL_ISIZE_HEIGHT_MASK | 5258c2ecf20Sopenharmony_ci EXYNOS_CIREAL_ISIZE_WIDTH_MASK); 5268c2ecf20Sopenharmony_ci cfg |= (EXYNOS_CIREAL_ISIZE_WIDTH(buf->rect.w) | 5278c2ecf20Sopenharmony_ci EXYNOS_CIREAL_ISIZE_HEIGHT(buf->rect.h)); 5288c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CIREAL_ISIZE); 5298c2ecf20Sopenharmony_ci 5308c2ecf20Sopenharmony_ci /* 5318c2ecf20Sopenharmony_ci * set input FIFO image size 5328c2ecf20Sopenharmony_ci * for now, we support only ITU601 8 bit mode 5338c2ecf20Sopenharmony_ci */ 5348c2ecf20Sopenharmony_ci cfg = (EXYNOS_CISRCFMT_ITU601_8BIT | 5358c2ecf20Sopenharmony_ci EXYNOS_CISRCFMT_SOURCEHSIZE(real_width) | 5368c2ecf20Sopenharmony_ci EXYNOS_CISRCFMT_SOURCEVSIZE(buf->buf.height)); 5378c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CISRCFMT); 5388c2ecf20Sopenharmony_ci 5398c2ecf20Sopenharmony_ci /* offset Y(RGB), Cb, Cr */ 5408c2ecf20Sopenharmony_ci cfg = (EXYNOS_CIIYOFF_HORIZONTAL(buf->rect.x) | 5418c2ecf20Sopenharmony_ci EXYNOS_CIIYOFF_VERTICAL(buf->rect.y)); 5428c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CIIYOFF); 5438c2ecf20Sopenharmony_ci cfg = (EXYNOS_CIICBOFF_HORIZONTAL(buf->rect.x) | 5448c2ecf20Sopenharmony_ci EXYNOS_CIICBOFF_VERTICAL(buf->rect.y)); 5458c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CIICBOFF); 5468c2ecf20Sopenharmony_ci cfg = (EXYNOS_CIICROFF_HORIZONTAL(buf->rect.x) | 5478c2ecf20Sopenharmony_ci EXYNOS_CIICROFF_VERTICAL(buf->rect.y)); 5488c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CIICROFF); 5498c2ecf20Sopenharmony_ci 5508c2ecf20Sopenharmony_ci fimc_set_window(ctx, buf); 5518c2ecf20Sopenharmony_ci} 5528c2ecf20Sopenharmony_ci 5538c2ecf20Sopenharmony_cistatic void fimc_src_set_addr(struct fimc_context *ctx, 5548c2ecf20Sopenharmony_ci struct exynos_drm_ipp_buffer *buf) 5558c2ecf20Sopenharmony_ci{ 5568c2ecf20Sopenharmony_ci fimc_write(ctx, buf->dma_addr[0], EXYNOS_CIIYSA(0)); 5578c2ecf20Sopenharmony_ci fimc_write(ctx, buf->dma_addr[1], EXYNOS_CIICBSA(0)); 5588c2ecf20Sopenharmony_ci fimc_write(ctx, buf->dma_addr[2], EXYNOS_CIICRSA(0)); 5598c2ecf20Sopenharmony_ci} 5608c2ecf20Sopenharmony_ci 5618c2ecf20Sopenharmony_cistatic void fimc_dst_set_fmt_order(struct fimc_context *ctx, u32 fmt) 5628c2ecf20Sopenharmony_ci{ 5638c2ecf20Sopenharmony_ci u32 cfg; 5648c2ecf20Sopenharmony_ci 5658c2ecf20Sopenharmony_ci DRM_DEV_DEBUG_KMS(ctx->dev, "fmt[0x%x]\n", fmt); 5668c2ecf20Sopenharmony_ci 5678c2ecf20Sopenharmony_ci /* RGB */ 5688c2ecf20Sopenharmony_ci cfg = fimc_read(ctx, EXYNOS_CISCCTRL); 5698c2ecf20Sopenharmony_ci cfg &= ~EXYNOS_CISCCTRL_OUTRGB_FMT_RGB_MASK; 5708c2ecf20Sopenharmony_ci 5718c2ecf20Sopenharmony_ci switch (fmt) { 5728c2ecf20Sopenharmony_ci case DRM_FORMAT_RGB565: 5738c2ecf20Sopenharmony_ci cfg |= EXYNOS_CISCCTRL_OUTRGB_FMT_RGB565; 5748c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CISCCTRL); 5758c2ecf20Sopenharmony_ci return; 5768c2ecf20Sopenharmony_ci case DRM_FORMAT_RGB888: 5778c2ecf20Sopenharmony_ci cfg |= EXYNOS_CISCCTRL_OUTRGB_FMT_RGB888; 5788c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CISCCTRL); 5798c2ecf20Sopenharmony_ci return; 5808c2ecf20Sopenharmony_ci case DRM_FORMAT_XRGB8888: 5818c2ecf20Sopenharmony_ci cfg |= (EXYNOS_CISCCTRL_OUTRGB_FMT_RGB888 | 5828c2ecf20Sopenharmony_ci EXYNOS_CISCCTRL_EXTRGB_EXTENSION); 5838c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CISCCTRL); 5848c2ecf20Sopenharmony_ci break; 5858c2ecf20Sopenharmony_ci default: 5868c2ecf20Sopenharmony_ci /* bypass */ 5878c2ecf20Sopenharmony_ci break; 5888c2ecf20Sopenharmony_ci } 5898c2ecf20Sopenharmony_ci 5908c2ecf20Sopenharmony_ci /* YUV */ 5918c2ecf20Sopenharmony_ci cfg = fimc_read(ctx, EXYNOS_CIOCTRL); 5928c2ecf20Sopenharmony_ci cfg &= ~(EXYNOS_CIOCTRL_ORDER2P_MASK | 5938c2ecf20Sopenharmony_ci EXYNOS_CIOCTRL_ORDER422_MASK | 5948c2ecf20Sopenharmony_ci EXYNOS_CIOCTRL_YCBCR_PLANE_MASK); 5958c2ecf20Sopenharmony_ci 5968c2ecf20Sopenharmony_ci switch (fmt) { 5978c2ecf20Sopenharmony_ci case DRM_FORMAT_XRGB8888: 5988c2ecf20Sopenharmony_ci cfg |= EXYNOS_CIOCTRL_ALPHA_OUT; 5998c2ecf20Sopenharmony_ci break; 6008c2ecf20Sopenharmony_ci case DRM_FORMAT_YUYV: 6018c2ecf20Sopenharmony_ci cfg |= EXYNOS_CIOCTRL_ORDER422_YCBYCR; 6028c2ecf20Sopenharmony_ci break; 6038c2ecf20Sopenharmony_ci case DRM_FORMAT_YVYU: 6048c2ecf20Sopenharmony_ci cfg |= EXYNOS_CIOCTRL_ORDER422_YCRYCB; 6058c2ecf20Sopenharmony_ci break; 6068c2ecf20Sopenharmony_ci case DRM_FORMAT_UYVY: 6078c2ecf20Sopenharmony_ci cfg |= EXYNOS_CIOCTRL_ORDER422_CBYCRY; 6088c2ecf20Sopenharmony_ci break; 6098c2ecf20Sopenharmony_ci case DRM_FORMAT_VYUY: 6108c2ecf20Sopenharmony_ci cfg |= EXYNOS_CIOCTRL_ORDER422_CRYCBY; 6118c2ecf20Sopenharmony_ci break; 6128c2ecf20Sopenharmony_ci case DRM_FORMAT_NV21: 6138c2ecf20Sopenharmony_ci case DRM_FORMAT_NV61: 6148c2ecf20Sopenharmony_ci cfg |= EXYNOS_CIOCTRL_ORDER2P_LSB_CRCB; 6158c2ecf20Sopenharmony_ci cfg |= EXYNOS_CIOCTRL_YCBCR_2PLANE; 6168c2ecf20Sopenharmony_ci break; 6178c2ecf20Sopenharmony_ci case DRM_FORMAT_YUV422: 6188c2ecf20Sopenharmony_ci case DRM_FORMAT_YUV420: 6198c2ecf20Sopenharmony_ci case DRM_FORMAT_YVU420: 6208c2ecf20Sopenharmony_ci cfg |= EXYNOS_CIOCTRL_YCBCR_3PLANE; 6218c2ecf20Sopenharmony_ci break; 6228c2ecf20Sopenharmony_ci case DRM_FORMAT_NV12: 6238c2ecf20Sopenharmony_ci case DRM_FORMAT_NV16: 6248c2ecf20Sopenharmony_ci cfg |= EXYNOS_CIOCTRL_ORDER2P_LSB_CBCR; 6258c2ecf20Sopenharmony_ci cfg |= EXYNOS_CIOCTRL_YCBCR_2PLANE; 6268c2ecf20Sopenharmony_ci break; 6278c2ecf20Sopenharmony_ci } 6288c2ecf20Sopenharmony_ci 6298c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CIOCTRL); 6308c2ecf20Sopenharmony_ci} 6318c2ecf20Sopenharmony_ci 6328c2ecf20Sopenharmony_cistatic void fimc_dst_set_fmt(struct fimc_context *ctx, u32 fmt, bool tiled) 6338c2ecf20Sopenharmony_ci{ 6348c2ecf20Sopenharmony_ci u32 cfg; 6358c2ecf20Sopenharmony_ci 6368c2ecf20Sopenharmony_ci DRM_DEV_DEBUG_KMS(ctx->dev, "fmt[0x%x]\n", fmt); 6378c2ecf20Sopenharmony_ci 6388c2ecf20Sopenharmony_ci cfg = fimc_read(ctx, EXYNOS_CIEXTEN); 6398c2ecf20Sopenharmony_ci 6408c2ecf20Sopenharmony_ci if (fmt == DRM_FORMAT_AYUV) { 6418c2ecf20Sopenharmony_ci cfg |= EXYNOS_CIEXTEN_YUV444_OUT; 6428c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CIEXTEN); 6438c2ecf20Sopenharmony_ci } else { 6448c2ecf20Sopenharmony_ci cfg &= ~EXYNOS_CIEXTEN_YUV444_OUT; 6458c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CIEXTEN); 6468c2ecf20Sopenharmony_ci 6478c2ecf20Sopenharmony_ci cfg = fimc_read(ctx, EXYNOS_CITRGFMT); 6488c2ecf20Sopenharmony_ci cfg &= ~EXYNOS_CITRGFMT_OUTFORMAT_MASK; 6498c2ecf20Sopenharmony_ci 6508c2ecf20Sopenharmony_ci switch (fmt) { 6518c2ecf20Sopenharmony_ci case DRM_FORMAT_RGB565: 6528c2ecf20Sopenharmony_ci case DRM_FORMAT_RGB888: 6538c2ecf20Sopenharmony_ci case DRM_FORMAT_XRGB8888: 6548c2ecf20Sopenharmony_ci cfg |= EXYNOS_CITRGFMT_OUTFORMAT_RGB; 6558c2ecf20Sopenharmony_ci break; 6568c2ecf20Sopenharmony_ci case DRM_FORMAT_YUYV: 6578c2ecf20Sopenharmony_ci case DRM_FORMAT_YVYU: 6588c2ecf20Sopenharmony_ci case DRM_FORMAT_UYVY: 6598c2ecf20Sopenharmony_ci case DRM_FORMAT_VYUY: 6608c2ecf20Sopenharmony_ci cfg |= EXYNOS_CITRGFMT_OUTFORMAT_YCBCR422_1PLANE; 6618c2ecf20Sopenharmony_ci break; 6628c2ecf20Sopenharmony_ci case DRM_FORMAT_NV16: 6638c2ecf20Sopenharmony_ci case DRM_FORMAT_NV61: 6648c2ecf20Sopenharmony_ci case DRM_FORMAT_YUV422: 6658c2ecf20Sopenharmony_ci cfg |= EXYNOS_CITRGFMT_OUTFORMAT_YCBCR422; 6668c2ecf20Sopenharmony_ci break; 6678c2ecf20Sopenharmony_ci case DRM_FORMAT_YUV420: 6688c2ecf20Sopenharmony_ci case DRM_FORMAT_YVU420: 6698c2ecf20Sopenharmony_ci case DRM_FORMAT_NV12: 6708c2ecf20Sopenharmony_ci case DRM_FORMAT_NV21: 6718c2ecf20Sopenharmony_ci cfg |= EXYNOS_CITRGFMT_OUTFORMAT_YCBCR420; 6728c2ecf20Sopenharmony_ci break; 6738c2ecf20Sopenharmony_ci } 6748c2ecf20Sopenharmony_ci 6758c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CITRGFMT); 6768c2ecf20Sopenharmony_ci } 6778c2ecf20Sopenharmony_ci 6788c2ecf20Sopenharmony_ci cfg = fimc_read(ctx, EXYNOS_CIDMAPARAM); 6798c2ecf20Sopenharmony_ci cfg &= ~EXYNOS_CIDMAPARAM_W_MODE_MASK; 6808c2ecf20Sopenharmony_ci 6818c2ecf20Sopenharmony_ci if (tiled) 6828c2ecf20Sopenharmony_ci cfg |= EXYNOS_CIDMAPARAM_W_MODE_64X32; 6838c2ecf20Sopenharmony_ci else 6848c2ecf20Sopenharmony_ci cfg |= EXYNOS_CIDMAPARAM_W_MODE_LINEAR; 6858c2ecf20Sopenharmony_ci 6868c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CIDMAPARAM); 6878c2ecf20Sopenharmony_ci 6888c2ecf20Sopenharmony_ci fimc_dst_set_fmt_order(ctx, fmt); 6898c2ecf20Sopenharmony_ci} 6908c2ecf20Sopenharmony_ci 6918c2ecf20Sopenharmony_cistatic void fimc_dst_set_transf(struct fimc_context *ctx, unsigned int rotation) 6928c2ecf20Sopenharmony_ci{ 6938c2ecf20Sopenharmony_ci unsigned int degree = rotation & DRM_MODE_ROTATE_MASK; 6948c2ecf20Sopenharmony_ci u32 cfg; 6958c2ecf20Sopenharmony_ci 6968c2ecf20Sopenharmony_ci DRM_DEV_DEBUG_KMS(ctx->dev, "rotation[0x%x]\n", rotation); 6978c2ecf20Sopenharmony_ci 6988c2ecf20Sopenharmony_ci cfg = fimc_read(ctx, EXYNOS_CITRGFMT); 6998c2ecf20Sopenharmony_ci cfg &= ~EXYNOS_CITRGFMT_FLIP_MASK; 7008c2ecf20Sopenharmony_ci cfg &= ~EXYNOS_CITRGFMT_OUTROT90_CLOCKWISE; 7018c2ecf20Sopenharmony_ci 7028c2ecf20Sopenharmony_ci switch (degree) { 7038c2ecf20Sopenharmony_ci case DRM_MODE_ROTATE_0: 7048c2ecf20Sopenharmony_ci if (rotation & DRM_MODE_REFLECT_X) 7058c2ecf20Sopenharmony_ci cfg |= EXYNOS_CITRGFMT_FLIP_X_MIRROR; 7068c2ecf20Sopenharmony_ci if (rotation & DRM_MODE_REFLECT_Y) 7078c2ecf20Sopenharmony_ci cfg |= EXYNOS_CITRGFMT_FLIP_Y_MIRROR; 7088c2ecf20Sopenharmony_ci break; 7098c2ecf20Sopenharmony_ci case DRM_MODE_ROTATE_90: 7108c2ecf20Sopenharmony_ci cfg |= EXYNOS_CITRGFMT_OUTROT90_CLOCKWISE; 7118c2ecf20Sopenharmony_ci if (rotation & DRM_MODE_REFLECT_X) 7128c2ecf20Sopenharmony_ci cfg |= EXYNOS_CITRGFMT_FLIP_X_MIRROR; 7138c2ecf20Sopenharmony_ci if (rotation & DRM_MODE_REFLECT_Y) 7148c2ecf20Sopenharmony_ci cfg |= EXYNOS_CITRGFMT_FLIP_Y_MIRROR; 7158c2ecf20Sopenharmony_ci break; 7168c2ecf20Sopenharmony_ci case DRM_MODE_ROTATE_180: 7178c2ecf20Sopenharmony_ci cfg |= (EXYNOS_CITRGFMT_FLIP_X_MIRROR | 7188c2ecf20Sopenharmony_ci EXYNOS_CITRGFMT_FLIP_Y_MIRROR); 7198c2ecf20Sopenharmony_ci if (rotation & DRM_MODE_REFLECT_X) 7208c2ecf20Sopenharmony_ci cfg &= ~EXYNOS_CITRGFMT_FLIP_X_MIRROR; 7218c2ecf20Sopenharmony_ci if (rotation & DRM_MODE_REFLECT_Y) 7228c2ecf20Sopenharmony_ci cfg &= ~EXYNOS_CITRGFMT_FLIP_Y_MIRROR; 7238c2ecf20Sopenharmony_ci break; 7248c2ecf20Sopenharmony_ci case DRM_MODE_ROTATE_270: 7258c2ecf20Sopenharmony_ci cfg |= (EXYNOS_CITRGFMT_OUTROT90_CLOCKWISE | 7268c2ecf20Sopenharmony_ci EXYNOS_CITRGFMT_FLIP_X_MIRROR | 7278c2ecf20Sopenharmony_ci EXYNOS_CITRGFMT_FLIP_Y_MIRROR); 7288c2ecf20Sopenharmony_ci if (rotation & DRM_MODE_REFLECT_X) 7298c2ecf20Sopenharmony_ci cfg &= ~EXYNOS_CITRGFMT_FLIP_X_MIRROR; 7308c2ecf20Sopenharmony_ci if (rotation & DRM_MODE_REFLECT_Y) 7318c2ecf20Sopenharmony_ci cfg &= ~EXYNOS_CITRGFMT_FLIP_Y_MIRROR; 7328c2ecf20Sopenharmony_ci break; 7338c2ecf20Sopenharmony_ci } 7348c2ecf20Sopenharmony_ci 7358c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CITRGFMT); 7368c2ecf20Sopenharmony_ci} 7378c2ecf20Sopenharmony_ci 7388c2ecf20Sopenharmony_cistatic int fimc_set_prescaler(struct fimc_context *ctx, struct fimc_scaler *sc, 7398c2ecf20Sopenharmony_ci struct drm_exynos_ipp_task_rect *src, 7408c2ecf20Sopenharmony_ci struct drm_exynos_ipp_task_rect *dst) 7418c2ecf20Sopenharmony_ci{ 7428c2ecf20Sopenharmony_ci u32 cfg, cfg_ext, shfactor; 7438c2ecf20Sopenharmony_ci u32 pre_dst_width, pre_dst_height; 7448c2ecf20Sopenharmony_ci u32 hfactor, vfactor; 7458c2ecf20Sopenharmony_ci int ret = 0; 7468c2ecf20Sopenharmony_ci u32 src_w, src_h, dst_w, dst_h; 7478c2ecf20Sopenharmony_ci 7488c2ecf20Sopenharmony_ci cfg_ext = fimc_read(ctx, EXYNOS_CITRGFMT); 7498c2ecf20Sopenharmony_ci if (cfg_ext & EXYNOS_CITRGFMT_INROT90_CLOCKWISE) { 7508c2ecf20Sopenharmony_ci src_w = src->h; 7518c2ecf20Sopenharmony_ci src_h = src->w; 7528c2ecf20Sopenharmony_ci } else { 7538c2ecf20Sopenharmony_ci src_w = src->w; 7548c2ecf20Sopenharmony_ci src_h = src->h; 7558c2ecf20Sopenharmony_ci } 7568c2ecf20Sopenharmony_ci 7578c2ecf20Sopenharmony_ci if (cfg_ext & EXYNOS_CITRGFMT_OUTROT90_CLOCKWISE) { 7588c2ecf20Sopenharmony_ci dst_w = dst->h; 7598c2ecf20Sopenharmony_ci dst_h = dst->w; 7608c2ecf20Sopenharmony_ci } else { 7618c2ecf20Sopenharmony_ci dst_w = dst->w; 7628c2ecf20Sopenharmony_ci dst_h = dst->h; 7638c2ecf20Sopenharmony_ci } 7648c2ecf20Sopenharmony_ci 7658c2ecf20Sopenharmony_ci /* fimc_ippdrv_check_property assures that dividers are not null */ 7668c2ecf20Sopenharmony_ci hfactor = fls(src_w / dst_w / 2); 7678c2ecf20Sopenharmony_ci if (hfactor > FIMC_SHFACTOR / 2) { 7688c2ecf20Sopenharmony_ci dev_err(ctx->dev, "failed to get ratio horizontal.\n"); 7698c2ecf20Sopenharmony_ci return -EINVAL; 7708c2ecf20Sopenharmony_ci } 7718c2ecf20Sopenharmony_ci 7728c2ecf20Sopenharmony_ci vfactor = fls(src_h / dst_h / 2); 7738c2ecf20Sopenharmony_ci if (vfactor > FIMC_SHFACTOR / 2) { 7748c2ecf20Sopenharmony_ci dev_err(ctx->dev, "failed to get ratio vertical.\n"); 7758c2ecf20Sopenharmony_ci return -EINVAL; 7768c2ecf20Sopenharmony_ci } 7778c2ecf20Sopenharmony_ci 7788c2ecf20Sopenharmony_ci pre_dst_width = src_w >> hfactor; 7798c2ecf20Sopenharmony_ci pre_dst_height = src_h >> vfactor; 7808c2ecf20Sopenharmony_ci DRM_DEV_DEBUG_KMS(ctx->dev, "pre_dst_width[%d]pre_dst_height[%d]\n", 7818c2ecf20Sopenharmony_ci pre_dst_width, pre_dst_height); 7828c2ecf20Sopenharmony_ci DRM_DEV_DEBUG_KMS(ctx->dev, "hfactor[%d]vfactor[%d]\n", hfactor, 7838c2ecf20Sopenharmony_ci vfactor); 7848c2ecf20Sopenharmony_ci 7858c2ecf20Sopenharmony_ci sc->hratio = (src_w << 14) / (dst_w << hfactor); 7868c2ecf20Sopenharmony_ci sc->vratio = (src_h << 14) / (dst_h << vfactor); 7878c2ecf20Sopenharmony_ci sc->up_h = (dst_w >= src_w) ? true : false; 7888c2ecf20Sopenharmony_ci sc->up_v = (dst_h >= src_h) ? true : false; 7898c2ecf20Sopenharmony_ci DRM_DEV_DEBUG_KMS(ctx->dev, "hratio[%d]vratio[%d]up_h[%d]up_v[%d]\n", 7908c2ecf20Sopenharmony_ci sc->hratio, sc->vratio, sc->up_h, sc->up_v); 7918c2ecf20Sopenharmony_ci 7928c2ecf20Sopenharmony_ci shfactor = FIMC_SHFACTOR - (hfactor + vfactor); 7938c2ecf20Sopenharmony_ci DRM_DEV_DEBUG_KMS(ctx->dev, "shfactor[%d]\n", shfactor); 7948c2ecf20Sopenharmony_ci 7958c2ecf20Sopenharmony_ci cfg = (EXYNOS_CISCPRERATIO_SHFACTOR(shfactor) | 7968c2ecf20Sopenharmony_ci EXYNOS_CISCPRERATIO_PREHORRATIO(1 << hfactor) | 7978c2ecf20Sopenharmony_ci EXYNOS_CISCPRERATIO_PREVERRATIO(1 << vfactor)); 7988c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CISCPRERATIO); 7998c2ecf20Sopenharmony_ci 8008c2ecf20Sopenharmony_ci cfg = (EXYNOS_CISCPREDST_PREDSTWIDTH(pre_dst_width) | 8018c2ecf20Sopenharmony_ci EXYNOS_CISCPREDST_PREDSTHEIGHT(pre_dst_height)); 8028c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CISCPREDST); 8038c2ecf20Sopenharmony_ci 8048c2ecf20Sopenharmony_ci return ret; 8058c2ecf20Sopenharmony_ci} 8068c2ecf20Sopenharmony_ci 8078c2ecf20Sopenharmony_cistatic void fimc_set_scaler(struct fimc_context *ctx, struct fimc_scaler *sc) 8088c2ecf20Sopenharmony_ci{ 8098c2ecf20Sopenharmony_ci u32 cfg, cfg_ext; 8108c2ecf20Sopenharmony_ci 8118c2ecf20Sopenharmony_ci DRM_DEV_DEBUG_KMS(ctx->dev, "range[%d]bypass[%d]up_h[%d]up_v[%d]\n", 8128c2ecf20Sopenharmony_ci sc->range, sc->bypass, sc->up_h, sc->up_v); 8138c2ecf20Sopenharmony_ci DRM_DEV_DEBUG_KMS(ctx->dev, "hratio[%d]vratio[%d]\n", 8148c2ecf20Sopenharmony_ci sc->hratio, sc->vratio); 8158c2ecf20Sopenharmony_ci 8168c2ecf20Sopenharmony_ci cfg = fimc_read(ctx, EXYNOS_CISCCTRL); 8178c2ecf20Sopenharmony_ci cfg &= ~(EXYNOS_CISCCTRL_SCALERBYPASS | 8188c2ecf20Sopenharmony_ci EXYNOS_CISCCTRL_SCALEUP_H | EXYNOS_CISCCTRL_SCALEUP_V | 8198c2ecf20Sopenharmony_ci EXYNOS_CISCCTRL_MAIN_V_RATIO_MASK | 8208c2ecf20Sopenharmony_ci EXYNOS_CISCCTRL_MAIN_H_RATIO_MASK | 8218c2ecf20Sopenharmony_ci EXYNOS_CISCCTRL_CSCR2Y_WIDE | 8228c2ecf20Sopenharmony_ci EXYNOS_CISCCTRL_CSCY2R_WIDE); 8238c2ecf20Sopenharmony_ci 8248c2ecf20Sopenharmony_ci if (sc->range) 8258c2ecf20Sopenharmony_ci cfg |= (EXYNOS_CISCCTRL_CSCR2Y_WIDE | 8268c2ecf20Sopenharmony_ci EXYNOS_CISCCTRL_CSCY2R_WIDE); 8278c2ecf20Sopenharmony_ci if (sc->bypass) 8288c2ecf20Sopenharmony_ci cfg |= EXYNOS_CISCCTRL_SCALERBYPASS; 8298c2ecf20Sopenharmony_ci if (sc->up_h) 8308c2ecf20Sopenharmony_ci cfg |= EXYNOS_CISCCTRL_SCALEUP_H; 8318c2ecf20Sopenharmony_ci if (sc->up_v) 8328c2ecf20Sopenharmony_ci cfg |= EXYNOS_CISCCTRL_SCALEUP_V; 8338c2ecf20Sopenharmony_ci 8348c2ecf20Sopenharmony_ci cfg |= (EXYNOS_CISCCTRL_MAINHORRATIO((sc->hratio >> 6)) | 8358c2ecf20Sopenharmony_ci EXYNOS_CISCCTRL_MAINVERRATIO((sc->vratio >> 6))); 8368c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CISCCTRL); 8378c2ecf20Sopenharmony_ci 8388c2ecf20Sopenharmony_ci cfg_ext = fimc_read(ctx, EXYNOS_CIEXTEN); 8398c2ecf20Sopenharmony_ci cfg_ext &= ~EXYNOS_CIEXTEN_MAINHORRATIO_EXT_MASK; 8408c2ecf20Sopenharmony_ci cfg_ext &= ~EXYNOS_CIEXTEN_MAINVERRATIO_EXT_MASK; 8418c2ecf20Sopenharmony_ci cfg_ext |= (EXYNOS_CIEXTEN_MAINHORRATIO_EXT(sc->hratio) | 8428c2ecf20Sopenharmony_ci EXYNOS_CIEXTEN_MAINVERRATIO_EXT(sc->vratio)); 8438c2ecf20Sopenharmony_ci fimc_write(ctx, cfg_ext, EXYNOS_CIEXTEN); 8448c2ecf20Sopenharmony_ci} 8458c2ecf20Sopenharmony_ci 8468c2ecf20Sopenharmony_cistatic void fimc_dst_set_size(struct fimc_context *ctx, 8478c2ecf20Sopenharmony_ci struct exynos_drm_ipp_buffer *buf) 8488c2ecf20Sopenharmony_ci{ 8498c2ecf20Sopenharmony_ci unsigned int real_width = buf->buf.pitch[0] / buf->format->cpp[0]; 8508c2ecf20Sopenharmony_ci u32 cfg, cfg_ext; 8518c2ecf20Sopenharmony_ci 8528c2ecf20Sopenharmony_ci DRM_DEV_DEBUG_KMS(ctx->dev, "hsize[%d]vsize[%d]\n", real_width, 8538c2ecf20Sopenharmony_ci buf->buf.height); 8548c2ecf20Sopenharmony_ci 8558c2ecf20Sopenharmony_ci /* original size */ 8568c2ecf20Sopenharmony_ci cfg = (EXYNOS_ORGOSIZE_HORIZONTAL(real_width) | 8578c2ecf20Sopenharmony_ci EXYNOS_ORGOSIZE_VERTICAL(buf->buf.height)); 8588c2ecf20Sopenharmony_ci 8598c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_ORGOSIZE); 8608c2ecf20Sopenharmony_ci 8618c2ecf20Sopenharmony_ci DRM_DEV_DEBUG_KMS(ctx->dev, "x[%d]y[%d]w[%d]h[%d]\n", buf->rect.x, 8628c2ecf20Sopenharmony_ci buf->rect.y, 8638c2ecf20Sopenharmony_ci buf->rect.w, buf->rect.h); 8648c2ecf20Sopenharmony_ci 8658c2ecf20Sopenharmony_ci /* CSC ITU */ 8668c2ecf20Sopenharmony_ci cfg = fimc_read(ctx, EXYNOS_CIGCTRL); 8678c2ecf20Sopenharmony_ci cfg &= ~EXYNOS_CIGCTRL_CSC_MASK; 8688c2ecf20Sopenharmony_ci 8698c2ecf20Sopenharmony_ci if (buf->buf.width >= FIMC_WIDTH_ITU_709) 8708c2ecf20Sopenharmony_ci cfg |= EXYNOS_CIGCTRL_CSC_ITU709; 8718c2ecf20Sopenharmony_ci else 8728c2ecf20Sopenharmony_ci cfg |= EXYNOS_CIGCTRL_CSC_ITU601; 8738c2ecf20Sopenharmony_ci 8748c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CIGCTRL); 8758c2ecf20Sopenharmony_ci 8768c2ecf20Sopenharmony_ci cfg_ext = fimc_read(ctx, EXYNOS_CITRGFMT); 8778c2ecf20Sopenharmony_ci 8788c2ecf20Sopenharmony_ci /* target image size */ 8798c2ecf20Sopenharmony_ci cfg = fimc_read(ctx, EXYNOS_CITRGFMT); 8808c2ecf20Sopenharmony_ci cfg &= ~(EXYNOS_CITRGFMT_TARGETH_MASK | 8818c2ecf20Sopenharmony_ci EXYNOS_CITRGFMT_TARGETV_MASK); 8828c2ecf20Sopenharmony_ci if (cfg_ext & EXYNOS_CITRGFMT_OUTROT90_CLOCKWISE) 8838c2ecf20Sopenharmony_ci cfg |= (EXYNOS_CITRGFMT_TARGETHSIZE(buf->rect.h) | 8848c2ecf20Sopenharmony_ci EXYNOS_CITRGFMT_TARGETVSIZE(buf->rect.w)); 8858c2ecf20Sopenharmony_ci else 8868c2ecf20Sopenharmony_ci cfg |= (EXYNOS_CITRGFMT_TARGETHSIZE(buf->rect.w) | 8878c2ecf20Sopenharmony_ci EXYNOS_CITRGFMT_TARGETVSIZE(buf->rect.h)); 8888c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CITRGFMT); 8898c2ecf20Sopenharmony_ci 8908c2ecf20Sopenharmony_ci /* target area */ 8918c2ecf20Sopenharmony_ci cfg = EXYNOS_CITAREA_TARGET_AREA(buf->rect.w * buf->rect.h); 8928c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CITAREA); 8938c2ecf20Sopenharmony_ci 8948c2ecf20Sopenharmony_ci /* offset Y(RGB), Cb, Cr */ 8958c2ecf20Sopenharmony_ci cfg = (EXYNOS_CIOYOFF_HORIZONTAL(buf->rect.x) | 8968c2ecf20Sopenharmony_ci EXYNOS_CIOYOFF_VERTICAL(buf->rect.y)); 8978c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CIOYOFF); 8988c2ecf20Sopenharmony_ci cfg = (EXYNOS_CIOCBOFF_HORIZONTAL(buf->rect.x) | 8998c2ecf20Sopenharmony_ci EXYNOS_CIOCBOFF_VERTICAL(buf->rect.y)); 9008c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CIOCBOFF); 9018c2ecf20Sopenharmony_ci cfg = (EXYNOS_CIOCROFF_HORIZONTAL(buf->rect.x) | 9028c2ecf20Sopenharmony_ci EXYNOS_CIOCROFF_VERTICAL(buf->rect.y)); 9038c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CIOCROFF); 9048c2ecf20Sopenharmony_ci} 9058c2ecf20Sopenharmony_ci 9068c2ecf20Sopenharmony_cistatic void fimc_dst_set_buf_seq(struct fimc_context *ctx, u32 buf_id, 9078c2ecf20Sopenharmony_ci bool enqueue) 9088c2ecf20Sopenharmony_ci{ 9098c2ecf20Sopenharmony_ci unsigned long flags; 9108c2ecf20Sopenharmony_ci u32 buf_num; 9118c2ecf20Sopenharmony_ci u32 cfg; 9128c2ecf20Sopenharmony_ci 9138c2ecf20Sopenharmony_ci DRM_DEV_DEBUG_KMS(ctx->dev, "buf_id[%d]enqueu[%d]\n", buf_id, enqueue); 9148c2ecf20Sopenharmony_ci 9158c2ecf20Sopenharmony_ci spin_lock_irqsave(&ctx->lock, flags); 9168c2ecf20Sopenharmony_ci 9178c2ecf20Sopenharmony_ci cfg = fimc_read(ctx, EXYNOS_CIFCNTSEQ); 9188c2ecf20Sopenharmony_ci 9198c2ecf20Sopenharmony_ci if (enqueue) 9208c2ecf20Sopenharmony_ci cfg |= (1 << buf_id); 9218c2ecf20Sopenharmony_ci else 9228c2ecf20Sopenharmony_ci cfg &= ~(1 << buf_id); 9238c2ecf20Sopenharmony_ci 9248c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_CIFCNTSEQ); 9258c2ecf20Sopenharmony_ci 9268c2ecf20Sopenharmony_ci buf_num = hweight32(cfg); 9278c2ecf20Sopenharmony_ci 9288c2ecf20Sopenharmony_ci if (enqueue && buf_num >= FIMC_BUF_START) 9298c2ecf20Sopenharmony_ci fimc_mask_irq(ctx, true); 9308c2ecf20Sopenharmony_ci else if (!enqueue && buf_num <= FIMC_BUF_STOP) 9318c2ecf20Sopenharmony_ci fimc_mask_irq(ctx, false); 9328c2ecf20Sopenharmony_ci 9338c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&ctx->lock, flags); 9348c2ecf20Sopenharmony_ci} 9358c2ecf20Sopenharmony_ci 9368c2ecf20Sopenharmony_cistatic void fimc_dst_set_addr(struct fimc_context *ctx, 9378c2ecf20Sopenharmony_ci struct exynos_drm_ipp_buffer *buf) 9388c2ecf20Sopenharmony_ci{ 9398c2ecf20Sopenharmony_ci fimc_write(ctx, buf->dma_addr[0], EXYNOS_CIOYSA(0)); 9408c2ecf20Sopenharmony_ci fimc_write(ctx, buf->dma_addr[1], EXYNOS_CIOCBSA(0)); 9418c2ecf20Sopenharmony_ci fimc_write(ctx, buf->dma_addr[2], EXYNOS_CIOCRSA(0)); 9428c2ecf20Sopenharmony_ci 9438c2ecf20Sopenharmony_ci fimc_dst_set_buf_seq(ctx, 0, true); 9448c2ecf20Sopenharmony_ci} 9458c2ecf20Sopenharmony_ci 9468c2ecf20Sopenharmony_cistatic void fimc_stop(struct fimc_context *ctx); 9478c2ecf20Sopenharmony_ci 9488c2ecf20Sopenharmony_cistatic irqreturn_t fimc_irq_handler(int irq, void *dev_id) 9498c2ecf20Sopenharmony_ci{ 9508c2ecf20Sopenharmony_ci struct fimc_context *ctx = dev_id; 9518c2ecf20Sopenharmony_ci int buf_id; 9528c2ecf20Sopenharmony_ci 9538c2ecf20Sopenharmony_ci DRM_DEV_DEBUG_KMS(ctx->dev, "fimc id[%d]\n", ctx->id); 9548c2ecf20Sopenharmony_ci 9558c2ecf20Sopenharmony_ci fimc_clear_irq(ctx); 9568c2ecf20Sopenharmony_ci if (fimc_check_ovf(ctx)) 9578c2ecf20Sopenharmony_ci return IRQ_NONE; 9588c2ecf20Sopenharmony_ci 9598c2ecf20Sopenharmony_ci if (!fimc_check_frame_end(ctx)) 9608c2ecf20Sopenharmony_ci return IRQ_NONE; 9618c2ecf20Sopenharmony_ci 9628c2ecf20Sopenharmony_ci buf_id = fimc_get_buf_id(ctx); 9638c2ecf20Sopenharmony_ci if (buf_id < 0) 9648c2ecf20Sopenharmony_ci return IRQ_HANDLED; 9658c2ecf20Sopenharmony_ci 9668c2ecf20Sopenharmony_ci DRM_DEV_DEBUG_KMS(ctx->dev, "buf_id[%d]\n", buf_id); 9678c2ecf20Sopenharmony_ci 9688c2ecf20Sopenharmony_ci if (ctx->task) { 9698c2ecf20Sopenharmony_ci struct exynos_drm_ipp_task *task = ctx->task; 9708c2ecf20Sopenharmony_ci 9718c2ecf20Sopenharmony_ci ctx->task = NULL; 9728c2ecf20Sopenharmony_ci pm_runtime_mark_last_busy(ctx->dev); 9738c2ecf20Sopenharmony_ci pm_runtime_put_autosuspend(ctx->dev); 9748c2ecf20Sopenharmony_ci exynos_drm_ipp_task_done(task, 0); 9758c2ecf20Sopenharmony_ci } 9768c2ecf20Sopenharmony_ci 9778c2ecf20Sopenharmony_ci fimc_dst_set_buf_seq(ctx, buf_id, false); 9788c2ecf20Sopenharmony_ci fimc_stop(ctx); 9798c2ecf20Sopenharmony_ci 9808c2ecf20Sopenharmony_ci return IRQ_HANDLED; 9818c2ecf20Sopenharmony_ci} 9828c2ecf20Sopenharmony_ci 9838c2ecf20Sopenharmony_cistatic void fimc_clear_addr(struct fimc_context *ctx) 9848c2ecf20Sopenharmony_ci{ 9858c2ecf20Sopenharmony_ci int i; 9868c2ecf20Sopenharmony_ci 9878c2ecf20Sopenharmony_ci for (i = 0; i < FIMC_MAX_SRC; i++) { 9888c2ecf20Sopenharmony_ci fimc_write(ctx, 0, EXYNOS_CIIYSA(i)); 9898c2ecf20Sopenharmony_ci fimc_write(ctx, 0, EXYNOS_CIICBSA(i)); 9908c2ecf20Sopenharmony_ci fimc_write(ctx, 0, EXYNOS_CIICRSA(i)); 9918c2ecf20Sopenharmony_ci } 9928c2ecf20Sopenharmony_ci 9938c2ecf20Sopenharmony_ci for (i = 0; i < FIMC_MAX_DST; i++) { 9948c2ecf20Sopenharmony_ci fimc_write(ctx, 0, EXYNOS_CIOYSA(i)); 9958c2ecf20Sopenharmony_ci fimc_write(ctx, 0, EXYNOS_CIOCBSA(i)); 9968c2ecf20Sopenharmony_ci fimc_write(ctx, 0, EXYNOS_CIOCRSA(i)); 9978c2ecf20Sopenharmony_ci } 9988c2ecf20Sopenharmony_ci} 9998c2ecf20Sopenharmony_ci 10008c2ecf20Sopenharmony_cistatic void fimc_reset(struct fimc_context *ctx) 10018c2ecf20Sopenharmony_ci{ 10028c2ecf20Sopenharmony_ci /* reset h/w block */ 10038c2ecf20Sopenharmony_ci fimc_sw_reset(ctx); 10048c2ecf20Sopenharmony_ci 10058c2ecf20Sopenharmony_ci /* reset scaler capability */ 10068c2ecf20Sopenharmony_ci memset(&ctx->sc, 0x0, sizeof(ctx->sc)); 10078c2ecf20Sopenharmony_ci 10088c2ecf20Sopenharmony_ci fimc_clear_addr(ctx); 10098c2ecf20Sopenharmony_ci} 10108c2ecf20Sopenharmony_ci 10118c2ecf20Sopenharmony_cistatic void fimc_start(struct fimc_context *ctx) 10128c2ecf20Sopenharmony_ci{ 10138c2ecf20Sopenharmony_ci u32 cfg0, cfg1; 10148c2ecf20Sopenharmony_ci 10158c2ecf20Sopenharmony_ci fimc_mask_irq(ctx, true); 10168c2ecf20Sopenharmony_ci 10178c2ecf20Sopenharmony_ci /* If set true, we can save jpeg about screen */ 10188c2ecf20Sopenharmony_ci fimc_handle_jpeg(ctx, false); 10198c2ecf20Sopenharmony_ci fimc_set_scaler(ctx, &ctx->sc); 10208c2ecf20Sopenharmony_ci 10218c2ecf20Sopenharmony_ci fimc_set_type_ctrl(ctx); 10228c2ecf20Sopenharmony_ci fimc_handle_lastend(ctx, false); 10238c2ecf20Sopenharmony_ci 10248c2ecf20Sopenharmony_ci /* setup dma */ 10258c2ecf20Sopenharmony_ci cfg0 = fimc_read(ctx, EXYNOS_MSCTRL); 10268c2ecf20Sopenharmony_ci cfg0 &= ~EXYNOS_MSCTRL_INPUT_MASK; 10278c2ecf20Sopenharmony_ci cfg0 |= EXYNOS_MSCTRL_INPUT_MEMORY; 10288c2ecf20Sopenharmony_ci fimc_write(ctx, cfg0, EXYNOS_MSCTRL); 10298c2ecf20Sopenharmony_ci 10308c2ecf20Sopenharmony_ci /* Reset status */ 10318c2ecf20Sopenharmony_ci fimc_write(ctx, 0x0, EXYNOS_CISTATUS); 10328c2ecf20Sopenharmony_ci 10338c2ecf20Sopenharmony_ci cfg0 = fimc_read(ctx, EXYNOS_CIIMGCPT); 10348c2ecf20Sopenharmony_ci cfg0 &= ~EXYNOS_CIIMGCPT_IMGCPTEN_SC; 10358c2ecf20Sopenharmony_ci cfg0 |= EXYNOS_CIIMGCPT_IMGCPTEN_SC; 10368c2ecf20Sopenharmony_ci 10378c2ecf20Sopenharmony_ci /* Scaler */ 10388c2ecf20Sopenharmony_ci cfg1 = fimc_read(ctx, EXYNOS_CISCCTRL); 10398c2ecf20Sopenharmony_ci cfg1 &= ~EXYNOS_CISCCTRL_SCAN_MASK; 10408c2ecf20Sopenharmony_ci cfg1 |= (EXYNOS_CISCCTRL_PROGRESSIVE | 10418c2ecf20Sopenharmony_ci EXYNOS_CISCCTRL_SCALERSTART); 10428c2ecf20Sopenharmony_ci 10438c2ecf20Sopenharmony_ci fimc_write(ctx, cfg1, EXYNOS_CISCCTRL); 10448c2ecf20Sopenharmony_ci 10458c2ecf20Sopenharmony_ci /* Enable image capture*/ 10468c2ecf20Sopenharmony_ci cfg0 |= EXYNOS_CIIMGCPT_IMGCPTEN; 10478c2ecf20Sopenharmony_ci fimc_write(ctx, cfg0, EXYNOS_CIIMGCPT); 10488c2ecf20Sopenharmony_ci 10498c2ecf20Sopenharmony_ci /* Disable frame end irq */ 10508c2ecf20Sopenharmony_ci fimc_clear_bits(ctx, EXYNOS_CIGCTRL, EXYNOS_CIGCTRL_IRQ_END_DISABLE); 10518c2ecf20Sopenharmony_ci 10528c2ecf20Sopenharmony_ci fimc_clear_bits(ctx, EXYNOS_CIOCTRL, EXYNOS_CIOCTRL_WEAVE_MASK); 10538c2ecf20Sopenharmony_ci 10548c2ecf20Sopenharmony_ci fimc_set_bits(ctx, EXYNOS_MSCTRL, EXYNOS_MSCTRL_ENVID); 10558c2ecf20Sopenharmony_ci} 10568c2ecf20Sopenharmony_ci 10578c2ecf20Sopenharmony_cistatic void fimc_stop(struct fimc_context *ctx) 10588c2ecf20Sopenharmony_ci{ 10598c2ecf20Sopenharmony_ci u32 cfg; 10608c2ecf20Sopenharmony_ci 10618c2ecf20Sopenharmony_ci /* Source clear */ 10628c2ecf20Sopenharmony_ci cfg = fimc_read(ctx, EXYNOS_MSCTRL); 10638c2ecf20Sopenharmony_ci cfg &= ~EXYNOS_MSCTRL_INPUT_MASK; 10648c2ecf20Sopenharmony_ci cfg &= ~EXYNOS_MSCTRL_ENVID; 10658c2ecf20Sopenharmony_ci fimc_write(ctx, cfg, EXYNOS_MSCTRL); 10668c2ecf20Sopenharmony_ci 10678c2ecf20Sopenharmony_ci fimc_mask_irq(ctx, false); 10688c2ecf20Sopenharmony_ci 10698c2ecf20Sopenharmony_ci /* reset sequence */ 10708c2ecf20Sopenharmony_ci fimc_write(ctx, 0x0, EXYNOS_CIFCNTSEQ); 10718c2ecf20Sopenharmony_ci 10728c2ecf20Sopenharmony_ci /* Scaler disable */ 10738c2ecf20Sopenharmony_ci fimc_clear_bits(ctx, EXYNOS_CISCCTRL, EXYNOS_CISCCTRL_SCALERSTART); 10748c2ecf20Sopenharmony_ci 10758c2ecf20Sopenharmony_ci /* Disable image capture */ 10768c2ecf20Sopenharmony_ci fimc_clear_bits(ctx, EXYNOS_CIIMGCPT, 10778c2ecf20Sopenharmony_ci EXYNOS_CIIMGCPT_IMGCPTEN_SC | EXYNOS_CIIMGCPT_IMGCPTEN); 10788c2ecf20Sopenharmony_ci 10798c2ecf20Sopenharmony_ci /* Enable frame end irq */ 10808c2ecf20Sopenharmony_ci fimc_set_bits(ctx, EXYNOS_CIGCTRL, EXYNOS_CIGCTRL_IRQ_END_DISABLE); 10818c2ecf20Sopenharmony_ci} 10828c2ecf20Sopenharmony_ci 10838c2ecf20Sopenharmony_cistatic int fimc_commit(struct exynos_drm_ipp *ipp, 10848c2ecf20Sopenharmony_ci struct exynos_drm_ipp_task *task) 10858c2ecf20Sopenharmony_ci{ 10868c2ecf20Sopenharmony_ci struct fimc_context *ctx = 10878c2ecf20Sopenharmony_ci container_of(ipp, struct fimc_context, ipp); 10888c2ecf20Sopenharmony_ci 10898c2ecf20Sopenharmony_ci pm_runtime_get_sync(ctx->dev); 10908c2ecf20Sopenharmony_ci ctx->task = task; 10918c2ecf20Sopenharmony_ci 10928c2ecf20Sopenharmony_ci fimc_src_set_fmt(ctx, task->src.buf.fourcc, task->src.buf.modifier); 10938c2ecf20Sopenharmony_ci fimc_src_set_size(ctx, &task->src); 10948c2ecf20Sopenharmony_ci fimc_src_set_transf(ctx, DRM_MODE_ROTATE_0); 10958c2ecf20Sopenharmony_ci fimc_src_set_addr(ctx, &task->src); 10968c2ecf20Sopenharmony_ci fimc_dst_set_fmt(ctx, task->dst.buf.fourcc, task->dst.buf.modifier); 10978c2ecf20Sopenharmony_ci fimc_dst_set_transf(ctx, task->transform.rotation); 10988c2ecf20Sopenharmony_ci fimc_dst_set_size(ctx, &task->dst); 10998c2ecf20Sopenharmony_ci fimc_dst_set_addr(ctx, &task->dst); 11008c2ecf20Sopenharmony_ci fimc_set_prescaler(ctx, &ctx->sc, &task->src.rect, &task->dst.rect); 11018c2ecf20Sopenharmony_ci fimc_start(ctx); 11028c2ecf20Sopenharmony_ci 11038c2ecf20Sopenharmony_ci return 0; 11048c2ecf20Sopenharmony_ci} 11058c2ecf20Sopenharmony_ci 11068c2ecf20Sopenharmony_cistatic void fimc_abort(struct exynos_drm_ipp *ipp, 11078c2ecf20Sopenharmony_ci struct exynos_drm_ipp_task *task) 11088c2ecf20Sopenharmony_ci{ 11098c2ecf20Sopenharmony_ci struct fimc_context *ctx = 11108c2ecf20Sopenharmony_ci container_of(ipp, struct fimc_context, ipp); 11118c2ecf20Sopenharmony_ci 11128c2ecf20Sopenharmony_ci fimc_reset(ctx); 11138c2ecf20Sopenharmony_ci 11148c2ecf20Sopenharmony_ci if (ctx->task) { 11158c2ecf20Sopenharmony_ci struct exynos_drm_ipp_task *task = ctx->task; 11168c2ecf20Sopenharmony_ci 11178c2ecf20Sopenharmony_ci ctx->task = NULL; 11188c2ecf20Sopenharmony_ci pm_runtime_mark_last_busy(ctx->dev); 11198c2ecf20Sopenharmony_ci pm_runtime_put_autosuspend(ctx->dev); 11208c2ecf20Sopenharmony_ci exynos_drm_ipp_task_done(task, -EIO); 11218c2ecf20Sopenharmony_ci } 11228c2ecf20Sopenharmony_ci} 11238c2ecf20Sopenharmony_ci 11248c2ecf20Sopenharmony_cistatic struct exynos_drm_ipp_funcs ipp_funcs = { 11258c2ecf20Sopenharmony_ci .commit = fimc_commit, 11268c2ecf20Sopenharmony_ci .abort = fimc_abort, 11278c2ecf20Sopenharmony_ci}; 11288c2ecf20Sopenharmony_ci 11298c2ecf20Sopenharmony_cistatic int fimc_bind(struct device *dev, struct device *master, void *data) 11308c2ecf20Sopenharmony_ci{ 11318c2ecf20Sopenharmony_ci struct fimc_context *ctx = dev_get_drvdata(dev); 11328c2ecf20Sopenharmony_ci struct drm_device *drm_dev = data; 11338c2ecf20Sopenharmony_ci struct exynos_drm_ipp *ipp = &ctx->ipp; 11348c2ecf20Sopenharmony_ci 11358c2ecf20Sopenharmony_ci ctx->drm_dev = drm_dev; 11368c2ecf20Sopenharmony_ci ipp->drm_dev = drm_dev; 11378c2ecf20Sopenharmony_ci exynos_drm_register_dma(drm_dev, dev, &ctx->dma_priv); 11388c2ecf20Sopenharmony_ci 11398c2ecf20Sopenharmony_ci exynos_drm_ipp_register(dev, ipp, &ipp_funcs, 11408c2ecf20Sopenharmony_ci DRM_EXYNOS_IPP_CAP_CROP | DRM_EXYNOS_IPP_CAP_ROTATE | 11418c2ecf20Sopenharmony_ci DRM_EXYNOS_IPP_CAP_SCALE | DRM_EXYNOS_IPP_CAP_CONVERT, 11428c2ecf20Sopenharmony_ci ctx->formats, ctx->num_formats, "fimc"); 11438c2ecf20Sopenharmony_ci 11448c2ecf20Sopenharmony_ci dev_info(dev, "The exynos fimc has been probed successfully\n"); 11458c2ecf20Sopenharmony_ci 11468c2ecf20Sopenharmony_ci return 0; 11478c2ecf20Sopenharmony_ci} 11488c2ecf20Sopenharmony_ci 11498c2ecf20Sopenharmony_cistatic void fimc_unbind(struct device *dev, struct device *master, 11508c2ecf20Sopenharmony_ci void *data) 11518c2ecf20Sopenharmony_ci{ 11528c2ecf20Sopenharmony_ci struct fimc_context *ctx = dev_get_drvdata(dev); 11538c2ecf20Sopenharmony_ci struct drm_device *drm_dev = data; 11548c2ecf20Sopenharmony_ci struct exynos_drm_ipp *ipp = &ctx->ipp; 11558c2ecf20Sopenharmony_ci 11568c2ecf20Sopenharmony_ci exynos_drm_ipp_unregister(dev, ipp); 11578c2ecf20Sopenharmony_ci exynos_drm_unregister_dma(drm_dev, dev, &ctx->dma_priv); 11588c2ecf20Sopenharmony_ci} 11598c2ecf20Sopenharmony_ci 11608c2ecf20Sopenharmony_cistatic const struct component_ops fimc_component_ops = { 11618c2ecf20Sopenharmony_ci .bind = fimc_bind, 11628c2ecf20Sopenharmony_ci .unbind = fimc_unbind, 11638c2ecf20Sopenharmony_ci}; 11648c2ecf20Sopenharmony_ci 11658c2ecf20Sopenharmony_cistatic void fimc_put_clocks(struct fimc_context *ctx) 11668c2ecf20Sopenharmony_ci{ 11678c2ecf20Sopenharmony_ci int i; 11688c2ecf20Sopenharmony_ci 11698c2ecf20Sopenharmony_ci for (i = 0; i < FIMC_CLKS_MAX; i++) { 11708c2ecf20Sopenharmony_ci if (IS_ERR(ctx->clocks[i])) 11718c2ecf20Sopenharmony_ci continue; 11728c2ecf20Sopenharmony_ci clk_put(ctx->clocks[i]); 11738c2ecf20Sopenharmony_ci ctx->clocks[i] = ERR_PTR(-EINVAL); 11748c2ecf20Sopenharmony_ci } 11758c2ecf20Sopenharmony_ci} 11768c2ecf20Sopenharmony_ci 11778c2ecf20Sopenharmony_cistatic int fimc_setup_clocks(struct fimc_context *ctx) 11788c2ecf20Sopenharmony_ci{ 11798c2ecf20Sopenharmony_ci struct device *fimc_dev = ctx->dev; 11808c2ecf20Sopenharmony_ci struct device *dev; 11818c2ecf20Sopenharmony_ci int ret, i; 11828c2ecf20Sopenharmony_ci 11838c2ecf20Sopenharmony_ci for (i = 0; i < FIMC_CLKS_MAX; i++) 11848c2ecf20Sopenharmony_ci ctx->clocks[i] = ERR_PTR(-EINVAL); 11858c2ecf20Sopenharmony_ci 11868c2ecf20Sopenharmony_ci for (i = 0; i < FIMC_CLKS_MAX; i++) { 11878c2ecf20Sopenharmony_ci if (i == FIMC_CLK_WB_A || i == FIMC_CLK_WB_B) 11888c2ecf20Sopenharmony_ci dev = fimc_dev->parent; 11898c2ecf20Sopenharmony_ci else 11908c2ecf20Sopenharmony_ci dev = fimc_dev; 11918c2ecf20Sopenharmony_ci 11928c2ecf20Sopenharmony_ci ctx->clocks[i] = clk_get(dev, fimc_clock_names[i]); 11938c2ecf20Sopenharmony_ci if (IS_ERR(ctx->clocks[i])) { 11948c2ecf20Sopenharmony_ci ret = PTR_ERR(ctx->clocks[i]); 11958c2ecf20Sopenharmony_ci dev_err(fimc_dev, "failed to get clock: %s\n", 11968c2ecf20Sopenharmony_ci fimc_clock_names[i]); 11978c2ecf20Sopenharmony_ci goto e_clk_free; 11988c2ecf20Sopenharmony_ci } 11998c2ecf20Sopenharmony_ci } 12008c2ecf20Sopenharmony_ci 12018c2ecf20Sopenharmony_ci ret = clk_prepare_enable(ctx->clocks[FIMC_CLK_LCLK]); 12028c2ecf20Sopenharmony_ci if (!ret) 12038c2ecf20Sopenharmony_ci return ret; 12048c2ecf20Sopenharmony_cie_clk_free: 12058c2ecf20Sopenharmony_ci fimc_put_clocks(ctx); 12068c2ecf20Sopenharmony_ci return ret; 12078c2ecf20Sopenharmony_ci} 12088c2ecf20Sopenharmony_ci 12098c2ecf20Sopenharmony_ciint exynos_drm_check_fimc_device(struct device *dev) 12108c2ecf20Sopenharmony_ci{ 12118c2ecf20Sopenharmony_ci int id = of_alias_get_id(dev->of_node, "fimc"); 12128c2ecf20Sopenharmony_ci 12138c2ecf20Sopenharmony_ci if (id >= 0 && (BIT(id) & fimc_mask)) 12148c2ecf20Sopenharmony_ci return 0; 12158c2ecf20Sopenharmony_ci return -ENODEV; 12168c2ecf20Sopenharmony_ci} 12178c2ecf20Sopenharmony_ci 12188c2ecf20Sopenharmony_cistatic const unsigned int fimc_formats[] = { 12198c2ecf20Sopenharmony_ci DRM_FORMAT_XRGB8888, DRM_FORMAT_RGB565, 12208c2ecf20Sopenharmony_ci DRM_FORMAT_NV12, DRM_FORMAT_NV16, DRM_FORMAT_NV21, DRM_FORMAT_NV61, 12218c2ecf20Sopenharmony_ci DRM_FORMAT_UYVY, DRM_FORMAT_VYUY, DRM_FORMAT_YUYV, DRM_FORMAT_YVYU, 12228c2ecf20Sopenharmony_ci DRM_FORMAT_YUV420, DRM_FORMAT_YVU420, DRM_FORMAT_YUV422, 12238c2ecf20Sopenharmony_ci DRM_FORMAT_YUV444, 12248c2ecf20Sopenharmony_ci}; 12258c2ecf20Sopenharmony_ci 12268c2ecf20Sopenharmony_cistatic const unsigned int fimc_tiled_formats[] = { 12278c2ecf20Sopenharmony_ci DRM_FORMAT_NV12, DRM_FORMAT_NV21, 12288c2ecf20Sopenharmony_ci}; 12298c2ecf20Sopenharmony_ci 12308c2ecf20Sopenharmony_cistatic const struct drm_exynos_ipp_limit fimc_4210_limits_v1[] = { 12318c2ecf20Sopenharmony_ci { IPP_SIZE_LIMIT(BUFFER, .h = { 16, 8192, 8 }, .v = { 16, 8192, 2 }) }, 12328c2ecf20Sopenharmony_ci { IPP_SIZE_LIMIT(AREA, .h = { 16, 4224, 2 }, .v = { 16, 0, 2 }) }, 12338c2ecf20Sopenharmony_ci { IPP_SIZE_LIMIT(ROTATED, .h = { 128, 1920 }, .v = { 128, 0 }) }, 12348c2ecf20Sopenharmony_ci { IPP_SCALE_LIMIT(.h = { (1 << 16) / 64, (1 << 16) * 64 }, 12358c2ecf20Sopenharmony_ci .v = { (1 << 16) / 64, (1 << 16) * 64 }) }, 12368c2ecf20Sopenharmony_ci}; 12378c2ecf20Sopenharmony_ci 12388c2ecf20Sopenharmony_cistatic const struct drm_exynos_ipp_limit fimc_4210_limits_v2[] = { 12398c2ecf20Sopenharmony_ci { IPP_SIZE_LIMIT(BUFFER, .h = { 16, 8192, 8 }, .v = { 16, 8192, 2 }) }, 12408c2ecf20Sopenharmony_ci { IPP_SIZE_LIMIT(AREA, .h = { 16, 1920, 2 }, .v = { 16, 0, 2 }) }, 12418c2ecf20Sopenharmony_ci { IPP_SIZE_LIMIT(ROTATED, .h = { 128, 1366 }, .v = { 128, 0 }) }, 12428c2ecf20Sopenharmony_ci { IPP_SCALE_LIMIT(.h = { (1 << 16) / 64, (1 << 16) * 64 }, 12438c2ecf20Sopenharmony_ci .v = { (1 << 16) / 64, (1 << 16) * 64 }) }, 12448c2ecf20Sopenharmony_ci}; 12458c2ecf20Sopenharmony_ci 12468c2ecf20Sopenharmony_cistatic const struct drm_exynos_ipp_limit fimc_4210_limits_tiled_v1[] = { 12478c2ecf20Sopenharmony_ci { IPP_SIZE_LIMIT(BUFFER, .h = { 128, 1920, 128 }, .v = { 32, 1920, 32 }) }, 12488c2ecf20Sopenharmony_ci { IPP_SIZE_LIMIT(AREA, .h = { 128, 1920, 2 }, .v = { 128, 0, 2 }) }, 12498c2ecf20Sopenharmony_ci { IPP_SCALE_LIMIT(.h = { (1 << 16) / 64, (1 << 16) * 64 }, 12508c2ecf20Sopenharmony_ci .v = { (1 << 16) / 64, (1 << 16) * 64 }) }, 12518c2ecf20Sopenharmony_ci}; 12528c2ecf20Sopenharmony_ci 12538c2ecf20Sopenharmony_cistatic const struct drm_exynos_ipp_limit fimc_4210_limits_tiled_v2[] = { 12548c2ecf20Sopenharmony_ci { IPP_SIZE_LIMIT(BUFFER, .h = { 128, 1920, 128 }, .v = { 32, 1920, 32 }) }, 12558c2ecf20Sopenharmony_ci { IPP_SIZE_LIMIT(AREA, .h = { 128, 1366, 2 }, .v = { 128, 0, 2 }) }, 12568c2ecf20Sopenharmony_ci { IPP_SCALE_LIMIT(.h = { (1 << 16) / 64, (1 << 16) * 64 }, 12578c2ecf20Sopenharmony_ci .v = { (1 << 16) / 64, (1 << 16) * 64 }) }, 12588c2ecf20Sopenharmony_ci}; 12598c2ecf20Sopenharmony_ci 12608c2ecf20Sopenharmony_cistatic int fimc_probe(struct platform_device *pdev) 12618c2ecf20Sopenharmony_ci{ 12628c2ecf20Sopenharmony_ci const struct drm_exynos_ipp_limit *limits; 12638c2ecf20Sopenharmony_ci struct exynos_drm_ipp_formats *formats; 12648c2ecf20Sopenharmony_ci struct device *dev = &pdev->dev; 12658c2ecf20Sopenharmony_ci struct fimc_context *ctx; 12668c2ecf20Sopenharmony_ci struct resource *res; 12678c2ecf20Sopenharmony_ci int ret; 12688c2ecf20Sopenharmony_ci int i, j, num_limits, num_formats; 12698c2ecf20Sopenharmony_ci 12708c2ecf20Sopenharmony_ci if (exynos_drm_check_fimc_device(dev) != 0) 12718c2ecf20Sopenharmony_ci return -ENODEV; 12728c2ecf20Sopenharmony_ci 12738c2ecf20Sopenharmony_ci ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); 12748c2ecf20Sopenharmony_ci if (!ctx) 12758c2ecf20Sopenharmony_ci return -ENOMEM; 12768c2ecf20Sopenharmony_ci 12778c2ecf20Sopenharmony_ci ctx->dev = dev; 12788c2ecf20Sopenharmony_ci ctx->id = of_alias_get_id(dev->of_node, "fimc"); 12798c2ecf20Sopenharmony_ci 12808c2ecf20Sopenharmony_ci /* construct formats/limits array */ 12818c2ecf20Sopenharmony_ci num_formats = ARRAY_SIZE(fimc_formats) + ARRAY_SIZE(fimc_tiled_formats); 12828c2ecf20Sopenharmony_ci formats = devm_kcalloc(dev, num_formats, sizeof(*formats), 12838c2ecf20Sopenharmony_ci GFP_KERNEL); 12848c2ecf20Sopenharmony_ci if (!formats) 12858c2ecf20Sopenharmony_ci return -ENOMEM; 12868c2ecf20Sopenharmony_ci 12878c2ecf20Sopenharmony_ci /* linear formats */ 12888c2ecf20Sopenharmony_ci if (ctx->id < 3) { 12898c2ecf20Sopenharmony_ci limits = fimc_4210_limits_v1; 12908c2ecf20Sopenharmony_ci num_limits = ARRAY_SIZE(fimc_4210_limits_v1); 12918c2ecf20Sopenharmony_ci } else { 12928c2ecf20Sopenharmony_ci limits = fimc_4210_limits_v2; 12938c2ecf20Sopenharmony_ci num_limits = ARRAY_SIZE(fimc_4210_limits_v2); 12948c2ecf20Sopenharmony_ci } 12958c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(fimc_formats); i++) { 12968c2ecf20Sopenharmony_ci formats[i].fourcc = fimc_formats[i]; 12978c2ecf20Sopenharmony_ci formats[i].type = DRM_EXYNOS_IPP_FORMAT_SOURCE | 12988c2ecf20Sopenharmony_ci DRM_EXYNOS_IPP_FORMAT_DESTINATION; 12998c2ecf20Sopenharmony_ci formats[i].limits = limits; 13008c2ecf20Sopenharmony_ci formats[i].num_limits = num_limits; 13018c2ecf20Sopenharmony_ci } 13028c2ecf20Sopenharmony_ci 13038c2ecf20Sopenharmony_ci /* tiled formats */ 13048c2ecf20Sopenharmony_ci if (ctx->id < 3) { 13058c2ecf20Sopenharmony_ci limits = fimc_4210_limits_tiled_v1; 13068c2ecf20Sopenharmony_ci num_limits = ARRAY_SIZE(fimc_4210_limits_tiled_v1); 13078c2ecf20Sopenharmony_ci } else { 13088c2ecf20Sopenharmony_ci limits = fimc_4210_limits_tiled_v2; 13098c2ecf20Sopenharmony_ci num_limits = ARRAY_SIZE(fimc_4210_limits_tiled_v2); 13108c2ecf20Sopenharmony_ci } 13118c2ecf20Sopenharmony_ci for (j = i, i = 0; i < ARRAY_SIZE(fimc_tiled_formats); j++, i++) { 13128c2ecf20Sopenharmony_ci formats[j].fourcc = fimc_tiled_formats[i]; 13138c2ecf20Sopenharmony_ci formats[j].modifier = DRM_FORMAT_MOD_SAMSUNG_64_32_TILE; 13148c2ecf20Sopenharmony_ci formats[j].type = DRM_EXYNOS_IPP_FORMAT_SOURCE | 13158c2ecf20Sopenharmony_ci DRM_EXYNOS_IPP_FORMAT_DESTINATION; 13168c2ecf20Sopenharmony_ci formats[j].limits = limits; 13178c2ecf20Sopenharmony_ci formats[j].num_limits = num_limits; 13188c2ecf20Sopenharmony_ci } 13198c2ecf20Sopenharmony_ci 13208c2ecf20Sopenharmony_ci ctx->formats = formats; 13218c2ecf20Sopenharmony_ci ctx->num_formats = num_formats; 13228c2ecf20Sopenharmony_ci 13238c2ecf20Sopenharmony_ci /* resource memory */ 13248c2ecf20Sopenharmony_ci ctx->regs_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 13258c2ecf20Sopenharmony_ci ctx->regs = devm_ioremap_resource(dev, ctx->regs_res); 13268c2ecf20Sopenharmony_ci if (IS_ERR(ctx->regs)) 13278c2ecf20Sopenharmony_ci return PTR_ERR(ctx->regs); 13288c2ecf20Sopenharmony_ci 13298c2ecf20Sopenharmony_ci /* resource irq */ 13308c2ecf20Sopenharmony_ci res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 13318c2ecf20Sopenharmony_ci if (!res) { 13328c2ecf20Sopenharmony_ci dev_err(dev, "failed to request irq resource.\n"); 13338c2ecf20Sopenharmony_ci return -ENOENT; 13348c2ecf20Sopenharmony_ci } 13358c2ecf20Sopenharmony_ci 13368c2ecf20Sopenharmony_ci ret = devm_request_irq(dev, res->start, fimc_irq_handler, 13378c2ecf20Sopenharmony_ci 0, dev_name(dev), ctx); 13388c2ecf20Sopenharmony_ci if (ret < 0) { 13398c2ecf20Sopenharmony_ci dev_err(dev, "failed to request irq.\n"); 13408c2ecf20Sopenharmony_ci return ret; 13418c2ecf20Sopenharmony_ci } 13428c2ecf20Sopenharmony_ci 13438c2ecf20Sopenharmony_ci ret = fimc_setup_clocks(ctx); 13448c2ecf20Sopenharmony_ci if (ret < 0) 13458c2ecf20Sopenharmony_ci return ret; 13468c2ecf20Sopenharmony_ci 13478c2ecf20Sopenharmony_ci spin_lock_init(&ctx->lock); 13488c2ecf20Sopenharmony_ci platform_set_drvdata(pdev, ctx); 13498c2ecf20Sopenharmony_ci 13508c2ecf20Sopenharmony_ci pm_runtime_use_autosuspend(dev); 13518c2ecf20Sopenharmony_ci pm_runtime_set_autosuspend_delay(dev, FIMC_AUTOSUSPEND_DELAY); 13528c2ecf20Sopenharmony_ci pm_runtime_enable(dev); 13538c2ecf20Sopenharmony_ci 13548c2ecf20Sopenharmony_ci ret = component_add(dev, &fimc_component_ops); 13558c2ecf20Sopenharmony_ci if (ret) 13568c2ecf20Sopenharmony_ci goto err_pm_dis; 13578c2ecf20Sopenharmony_ci 13588c2ecf20Sopenharmony_ci dev_info(dev, "drm fimc registered successfully.\n"); 13598c2ecf20Sopenharmony_ci 13608c2ecf20Sopenharmony_ci return 0; 13618c2ecf20Sopenharmony_ci 13628c2ecf20Sopenharmony_cierr_pm_dis: 13638c2ecf20Sopenharmony_ci pm_runtime_dont_use_autosuspend(dev); 13648c2ecf20Sopenharmony_ci pm_runtime_disable(dev); 13658c2ecf20Sopenharmony_ci fimc_put_clocks(ctx); 13668c2ecf20Sopenharmony_ci 13678c2ecf20Sopenharmony_ci return ret; 13688c2ecf20Sopenharmony_ci} 13698c2ecf20Sopenharmony_ci 13708c2ecf20Sopenharmony_cistatic int fimc_remove(struct platform_device *pdev) 13718c2ecf20Sopenharmony_ci{ 13728c2ecf20Sopenharmony_ci struct device *dev = &pdev->dev; 13738c2ecf20Sopenharmony_ci struct fimc_context *ctx = get_fimc_context(dev); 13748c2ecf20Sopenharmony_ci 13758c2ecf20Sopenharmony_ci component_del(dev, &fimc_component_ops); 13768c2ecf20Sopenharmony_ci pm_runtime_dont_use_autosuspend(dev); 13778c2ecf20Sopenharmony_ci pm_runtime_disable(dev); 13788c2ecf20Sopenharmony_ci 13798c2ecf20Sopenharmony_ci fimc_put_clocks(ctx); 13808c2ecf20Sopenharmony_ci 13818c2ecf20Sopenharmony_ci return 0; 13828c2ecf20Sopenharmony_ci} 13838c2ecf20Sopenharmony_ci 13848c2ecf20Sopenharmony_ci#ifdef CONFIG_PM 13858c2ecf20Sopenharmony_cistatic int fimc_runtime_suspend(struct device *dev) 13868c2ecf20Sopenharmony_ci{ 13878c2ecf20Sopenharmony_ci struct fimc_context *ctx = get_fimc_context(dev); 13888c2ecf20Sopenharmony_ci 13898c2ecf20Sopenharmony_ci DRM_DEV_DEBUG_KMS(dev, "id[%d]\n", ctx->id); 13908c2ecf20Sopenharmony_ci clk_disable_unprepare(ctx->clocks[FIMC_CLK_GATE]); 13918c2ecf20Sopenharmony_ci return 0; 13928c2ecf20Sopenharmony_ci} 13938c2ecf20Sopenharmony_ci 13948c2ecf20Sopenharmony_cistatic int fimc_runtime_resume(struct device *dev) 13958c2ecf20Sopenharmony_ci{ 13968c2ecf20Sopenharmony_ci struct fimc_context *ctx = get_fimc_context(dev); 13978c2ecf20Sopenharmony_ci 13988c2ecf20Sopenharmony_ci DRM_DEV_DEBUG_KMS(dev, "id[%d]\n", ctx->id); 13998c2ecf20Sopenharmony_ci return clk_prepare_enable(ctx->clocks[FIMC_CLK_GATE]); 14008c2ecf20Sopenharmony_ci} 14018c2ecf20Sopenharmony_ci#endif 14028c2ecf20Sopenharmony_ci 14038c2ecf20Sopenharmony_cistatic const struct dev_pm_ops fimc_pm_ops = { 14048c2ecf20Sopenharmony_ci SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, 14058c2ecf20Sopenharmony_ci pm_runtime_force_resume) 14068c2ecf20Sopenharmony_ci SET_RUNTIME_PM_OPS(fimc_runtime_suspend, fimc_runtime_resume, NULL) 14078c2ecf20Sopenharmony_ci}; 14088c2ecf20Sopenharmony_ci 14098c2ecf20Sopenharmony_cistatic const struct of_device_id fimc_of_match[] = { 14108c2ecf20Sopenharmony_ci { .compatible = "samsung,exynos4210-fimc" }, 14118c2ecf20Sopenharmony_ci { .compatible = "samsung,exynos4212-fimc" }, 14128c2ecf20Sopenharmony_ci { }, 14138c2ecf20Sopenharmony_ci}; 14148c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, fimc_of_match); 14158c2ecf20Sopenharmony_ci 14168c2ecf20Sopenharmony_cistruct platform_driver fimc_driver = { 14178c2ecf20Sopenharmony_ci .probe = fimc_probe, 14188c2ecf20Sopenharmony_ci .remove = fimc_remove, 14198c2ecf20Sopenharmony_ci .driver = { 14208c2ecf20Sopenharmony_ci .of_match_table = fimc_of_match, 14218c2ecf20Sopenharmony_ci .name = "exynos-drm-fimc", 14228c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 14238c2ecf20Sopenharmony_ci .pm = &fimc_pm_ops, 14248c2ecf20Sopenharmony_ci }, 14258c2ecf20Sopenharmony_ci}; 1426