196976c3dSAjay Kumar /* drivers/gpu/drm/exynos/exynos7_drm_decon.c 296976c3dSAjay Kumar * 396976c3dSAjay Kumar * Copyright (C) 2014 Samsung Electronics Co.Ltd 496976c3dSAjay Kumar * Authors: 596976c3dSAjay Kumar * Akshu Agarwal <akshua@gmail.com> 696976c3dSAjay Kumar * Ajay Kumar <ajaykumar.rs@samsung.com> 796976c3dSAjay Kumar * 896976c3dSAjay Kumar * This program is free software; you can redistribute it and/or modify it 996976c3dSAjay Kumar * under the terms of the GNU General Public License as published by the 1096976c3dSAjay Kumar * Free Software Foundation; either version 2 of the License, or (at your 1196976c3dSAjay Kumar * option) any later version. 1296976c3dSAjay Kumar * 1396976c3dSAjay Kumar */ 1496976c3dSAjay Kumar #include <drm/drmP.h> 1596976c3dSAjay Kumar #include <drm/exynos_drm.h> 1696976c3dSAjay Kumar 1796976c3dSAjay Kumar #include <linux/clk.h> 1896976c3dSAjay Kumar #include <linux/component.h> 1996976c3dSAjay Kumar #include <linux/kernel.h> 2096976c3dSAjay Kumar #include <linux/of.h> 2196976c3dSAjay Kumar #include <linux/of_address.h> 2296976c3dSAjay Kumar #include <linux/of_device.h> 2396976c3dSAjay Kumar #include <linux/platform_device.h> 2496976c3dSAjay Kumar #include <linux/pm_runtime.h> 2596976c3dSAjay Kumar 2696976c3dSAjay Kumar #include <video/of_display_timing.h> 2796976c3dSAjay Kumar #include <video/of_videomode.h> 2896976c3dSAjay Kumar #include <video/exynos7_decon.h> 2996976c3dSAjay Kumar 3096976c3dSAjay Kumar #include "exynos_drm_crtc.h" 317ee14cdcSGustavo Padovan #include "exynos_drm_plane.h" 3296976c3dSAjay Kumar #include "exynos_drm_drv.h" 3396976c3dSAjay Kumar #include "exynos_drm_fbdev.h" 3496976c3dSAjay Kumar #include "exynos_drm_iommu.h" 3596976c3dSAjay Kumar 3696976c3dSAjay Kumar /* 3796976c3dSAjay Kumar * DECON stands for Display and Enhancement controller. 3896976c3dSAjay Kumar */ 3996976c3dSAjay Kumar 4096976c3dSAjay Kumar #define DECON_DEFAULT_FRAMERATE 60 4196976c3dSAjay Kumar #define MIN_FB_WIDTH_FOR_16WORD_BURST 128 4296976c3dSAjay Kumar 4396976c3dSAjay Kumar #define WINDOWS_NR 2 4496976c3dSAjay Kumar 4596976c3dSAjay Kumar struct decon_context { 4696976c3dSAjay Kumar struct device *dev; 4796976c3dSAjay Kumar struct drm_device *drm_dev; 4896976c3dSAjay Kumar struct exynos_drm_crtc *crtc; 497ee14cdcSGustavo Padovan struct exynos_drm_plane planes[WINDOWS_NR]; 5096976c3dSAjay Kumar struct clk *pclk; 5196976c3dSAjay Kumar struct clk *aclk; 5296976c3dSAjay Kumar struct clk *eclk; 5396976c3dSAjay Kumar struct clk *vclk; 5496976c3dSAjay Kumar void __iomem *regs; 5596976c3dSAjay Kumar unsigned int default_win; 5696976c3dSAjay Kumar unsigned long irq_flags; 5796976c3dSAjay Kumar bool i80_if; 5896976c3dSAjay Kumar bool suspended; 5996976c3dSAjay Kumar int pipe; 6096976c3dSAjay Kumar wait_queue_head_t wait_vsync_queue; 6196976c3dSAjay Kumar atomic_t wait_vsync_event; 6296976c3dSAjay Kumar 6396976c3dSAjay Kumar struct exynos_drm_panel_info panel; 64cf67cc9aSGustavo Padovan struct exynos_drm_encoder *encoder; 6596976c3dSAjay Kumar }; 6696976c3dSAjay Kumar 6796976c3dSAjay Kumar static const struct of_device_id decon_driver_dt_match[] = { 6896976c3dSAjay Kumar {.compatible = "samsung,exynos7-decon"}, 6996976c3dSAjay Kumar {}, 7096976c3dSAjay Kumar }; 7196976c3dSAjay Kumar MODULE_DEVICE_TABLE(of, decon_driver_dt_match); 7296976c3dSAjay Kumar 7396976c3dSAjay Kumar static void decon_wait_for_vblank(struct exynos_drm_crtc *crtc) 7496976c3dSAjay Kumar { 7596976c3dSAjay Kumar struct decon_context *ctx = crtc->ctx; 7696976c3dSAjay Kumar 7796976c3dSAjay Kumar if (ctx->suspended) 7896976c3dSAjay Kumar return; 7996976c3dSAjay Kumar 8096976c3dSAjay Kumar atomic_set(&ctx->wait_vsync_event, 1); 8196976c3dSAjay Kumar 8296976c3dSAjay Kumar /* 8396976c3dSAjay Kumar * wait for DECON to signal VSYNC interrupt or return after 8496976c3dSAjay Kumar * timeout which is set to 50ms (refresh rate of 20). 8596976c3dSAjay Kumar */ 8696976c3dSAjay Kumar if (!wait_event_timeout(ctx->wait_vsync_queue, 8796976c3dSAjay Kumar !atomic_read(&ctx->wait_vsync_event), 8896976c3dSAjay Kumar HZ/20)) 8996976c3dSAjay Kumar DRM_DEBUG_KMS("vblank wait timed out.\n"); 9096976c3dSAjay Kumar } 9196976c3dSAjay Kumar 92fc2e013fSHyungwon Hwang static void decon_clear_channels(struct exynos_drm_crtc *crtc) 9396976c3dSAjay Kumar { 94fc2e013fSHyungwon Hwang struct decon_context *ctx = crtc->ctx; 955b1d5bc6STobias Jakobi unsigned int win, ch_enabled = 0; 9696976c3dSAjay Kumar 9796976c3dSAjay Kumar DRM_DEBUG_KMS("%s\n", __FILE__); 9896976c3dSAjay Kumar 9996976c3dSAjay Kumar /* Check if any channel is enabled. */ 10096976c3dSAjay Kumar for (win = 0; win < WINDOWS_NR; win++) { 10196976c3dSAjay Kumar u32 val = readl(ctx->regs + WINCON(win)); 10296976c3dSAjay Kumar 10396976c3dSAjay Kumar if (val & WINCONx_ENWIN) { 10496976c3dSAjay Kumar val &= ~WINCONx_ENWIN; 10596976c3dSAjay Kumar writel(val, ctx->regs + WINCON(win)); 10696976c3dSAjay Kumar ch_enabled = 1; 10796976c3dSAjay Kumar } 10896976c3dSAjay Kumar } 10996976c3dSAjay Kumar 11096976c3dSAjay Kumar /* Wait for vsync, as disable channel takes effect at next vsync */ 11196976c3dSAjay Kumar if (ch_enabled) { 11296976c3dSAjay Kumar unsigned int state = ctx->suspended; 11396976c3dSAjay Kumar 11496976c3dSAjay Kumar ctx->suspended = 0; 11596976c3dSAjay Kumar decon_wait_for_vblank(ctx->crtc); 11696976c3dSAjay Kumar ctx->suspended = state; 11796976c3dSAjay Kumar } 11896976c3dSAjay Kumar } 11996976c3dSAjay Kumar 12096976c3dSAjay Kumar static int decon_ctx_initialize(struct decon_context *ctx, 12196976c3dSAjay Kumar struct drm_device *drm_dev) 12296976c3dSAjay Kumar { 12396976c3dSAjay Kumar struct exynos_drm_private *priv = drm_dev->dev_private; 124fc2e013fSHyungwon Hwang int ret; 12596976c3dSAjay Kumar 12696976c3dSAjay Kumar ctx->drm_dev = drm_dev; 12796976c3dSAjay Kumar ctx->pipe = priv->pipe++; 12896976c3dSAjay Kumar 129eb7a3fc7SJoonyoung Shim decon_clear_channels(ctx->crtc); 130eb7a3fc7SJoonyoung Shim 131eb7a3fc7SJoonyoung Shim ret = drm_iommu_attach_device(drm_dev, ctx->dev); 132fc2e013fSHyungwon Hwang if (ret) 133fc2e013fSHyungwon Hwang priv->pipe--; 13496976c3dSAjay Kumar 13596976c3dSAjay Kumar return ret; 13696976c3dSAjay Kumar } 13796976c3dSAjay Kumar 13896976c3dSAjay Kumar static void decon_ctx_remove(struct decon_context *ctx) 13996976c3dSAjay Kumar { 14096976c3dSAjay Kumar /* detach this sub driver from iommu mapping if supported. */ 14196976c3dSAjay Kumar drm_iommu_detach_device(ctx->drm_dev, ctx->dev); 14296976c3dSAjay Kumar } 14396976c3dSAjay Kumar 14496976c3dSAjay Kumar static u32 decon_calc_clkdiv(struct decon_context *ctx, 14596976c3dSAjay Kumar const struct drm_display_mode *mode) 14696976c3dSAjay Kumar { 14796976c3dSAjay Kumar unsigned long ideal_clk = mode->htotal * mode->vtotal * mode->vrefresh; 14896976c3dSAjay Kumar u32 clkdiv; 14996976c3dSAjay Kumar 15096976c3dSAjay Kumar /* Find the clock divider value that gets us closest to ideal_clk */ 15196976c3dSAjay Kumar clkdiv = DIV_ROUND_UP(clk_get_rate(ctx->vclk), ideal_clk); 15296976c3dSAjay Kumar 15396976c3dSAjay Kumar return (clkdiv < 0x100) ? clkdiv : 0xff; 15496976c3dSAjay Kumar } 15596976c3dSAjay Kumar 15696976c3dSAjay Kumar static bool decon_mode_fixup(struct exynos_drm_crtc *crtc, 15796976c3dSAjay Kumar const struct drm_display_mode *mode, 15896976c3dSAjay Kumar struct drm_display_mode *adjusted_mode) 15996976c3dSAjay Kumar { 16096976c3dSAjay Kumar if (adjusted_mode->vrefresh == 0) 16196976c3dSAjay Kumar adjusted_mode->vrefresh = DECON_DEFAULT_FRAMERATE; 16296976c3dSAjay Kumar 16396976c3dSAjay Kumar return true; 16496976c3dSAjay Kumar } 16596976c3dSAjay Kumar 16696976c3dSAjay Kumar static void decon_commit(struct exynos_drm_crtc *crtc) 16796976c3dSAjay Kumar { 16896976c3dSAjay Kumar struct decon_context *ctx = crtc->ctx; 169020e79deSJoonyoung Shim struct drm_display_mode *mode = &crtc->base.state->adjusted_mode; 17096976c3dSAjay Kumar u32 val, clkdiv; 17196976c3dSAjay Kumar 17296976c3dSAjay Kumar if (ctx->suspended) 17396976c3dSAjay Kumar return; 17496976c3dSAjay Kumar 17596976c3dSAjay Kumar /* nothing to do if we haven't set the mode yet */ 17696976c3dSAjay Kumar if (mode->htotal == 0 || mode->vtotal == 0) 17796976c3dSAjay Kumar return; 17896976c3dSAjay Kumar 17996976c3dSAjay Kumar if (!ctx->i80_if) { 18096976c3dSAjay Kumar int vsync_len, vbpd, vfpd, hsync_len, hbpd, hfpd; 18196976c3dSAjay Kumar /* setup vertical timing values. */ 18296976c3dSAjay Kumar vsync_len = mode->crtc_vsync_end - mode->crtc_vsync_start; 18396976c3dSAjay Kumar vbpd = mode->crtc_vtotal - mode->crtc_vsync_end; 18496976c3dSAjay Kumar vfpd = mode->crtc_vsync_start - mode->crtc_vdisplay; 18596976c3dSAjay Kumar 18696976c3dSAjay Kumar val = VIDTCON0_VBPD(vbpd - 1) | VIDTCON0_VFPD(vfpd - 1); 18796976c3dSAjay Kumar writel(val, ctx->regs + VIDTCON0); 18896976c3dSAjay Kumar 18996976c3dSAjay Kumar val = VIDTCON1_VSPW(vsync_len - 1); 19096976c3dSAjay Kumar writel(val, ctx->regs + VIDTCON1); 19196976c3dSAjay Kumar 19296976c3dSAjay Kumar /* setup horizontal timing values. */ 19396976c3dSAjay Kumar hsync_len = mode->crtc_hsync_end - mode->crtc_hsync_start; 19496976c3dSAjay Kumar hbpd = mode->crtc_htotal - mode->crtc_hsync_end; 19596976c3dSAjay Kumar hfpd = mode->crtc_hsync_start - mode->crtc_hdisplay; 19696976c3dSAjay Kumar 19796976c3dSAjay Kumar /* setup horizontal timing values. */ 19896976c3dSAjay Kumar val = VIDTCON2_HBPD(hbpd - 1) | VIDTCON2_HFPD(hfpd - 1); 19996976c3dSAjay Kumar writel(val, ctx->regs + VIDTCON2); 20096976c3dSAjay Kumar 20196976c3dSAjay Kumar val = VIDTCON3_HSPW(hsync_len - 1); 20296976c3dSAjay Kumar writel(val, ctx->regs + VIDTCON3); 20396976c3dSAjay Kumar } 20496976c3dSAjay Kumar 20596976c3dSAjay Kumar /* setup horizontal and vertical display size. */ 20696976c3dSAjay Kumar val = VIDTCON4_LINEVAL(mode->vdisplay - 1) | 20796976c3dSAjay Kumar VIDTCON4_HOZVAL(mode->hdisplay - 1); 20896976c3dSAjay Kumar writel(val, ctx->regs + VIDTCON4); 20996976c3dSAjay Kumar 21096976c3dSAjay Kumar writel(mode->vdisplay - 1, ctx->regs + LINECNT_OP_THRESHOLD); 21196976c3dSAjay Kumar 21296976c3dSAjay Kumar /* 21396976c3dSAjay Kumar * fields of register with prefix '_F' would be updated 21496976c3dSAjay Kumar * at vsync(same as dma start) 21596976c3dSAjay Kumar */ 21696976c3dSAjay Kumar val = VIDCON0_ENVID | VIDCON0_ENVID_F; 21796976c3dSAjay Kumar writel(val, ctx->regs + VIDCON0); 21896976c3dSAjay Kumar 21996976c3dSAjay Kumar clkdiv = decon_calc_clkdiv(ctx, mode); 22096976c3dSAjay Kumar if (clkdiv > 1) { 22196976c3dSAjay Kumar val = VCLKCON1_CLKVAL_NUM_VCLK(clkdiv - 1); 22296976c3dSAjay Kumar writel(val, ctx->regs + VCLKCON1); 22396976c3dSAjay Kumar writel(val, ctx->regs + VCLKCON2); 22496976c3dSAjay Kumar } 22596976c3dSAjay Kumar 22696976c3dSAjay Kumar val = readl(ctx->regs + DECON_UPDATE); 22796976c3dSAjay Kumar val |= DECON_UPDATE_STANDALONE_F; 22896976c3dSAjay Kumar writel(val, ctx->regs + DECON_UPDATE); 22996976c3dSAjay Kumar } 23096976c3dSAjay Kumar 23196976c3dSAjay Kumar static int decon_enable_vblank(struct exynos_drm_crtc *crtc) 23296976c3dSAjay Kumar { 23396976c3dSAjay Kumar struct decon_context *ctx = crtc->ctx; 23496976c3dSAjay Kumar u32 val; 23596976c3dSAjay Kumar 23696976c3dSAjay Kumar if (ctx->suspended) 23796976c3dSAjay Kumar return -EPERM; 23896976c3dSAjay Kumar 23996976c3dSAjay Kumar if (!test_and_set_bit(0, &ctx->irq_flags)) { 24096976c3dSAjay Kumar val = readl(ctx->regs + VIDINTCON0); 24196976c3dSAjay Kumar 24296976c3dSAjay Kumar val |= VIDINTCON0_INT_ENABLE; 24396976c3dSAjay Kumar 24496976c3dSAjay Kumar if (!ctx->i80_if) { 24596976c3dSAjay Kumar val |= VIDINTCON0_INT_FRAME; 24696976c3dSAjay Kumar val &= ~VIDINTCON0_FRAMESEL0_MASK; 24796976c3dSAjay Kumar val |= VIDINTCON0_FRAMESEL0_VSYNC; 24896976c3dSAjay Kumar } 24996976c3dSAjay Kumar 25096976c3dSAjay Kumar writel(val, ctx->regs + VIDINTCON0); 25196976c3dSAjay Kumar } 25296976c3dSAjay Kumar 25396976c3dSAjay Kumar return 0; 25496976c3dSAjay Kumar } 25596976c3dSAjay Kumar 25696976c3dSAjay Kumar static void decon_disable_vblank(struct exynos_drm_crtc *crtc) 25796976c3dSAjay Kumar { 25896976c3dSAjay Kumar struct decon_context *ctx = crtc->ctx; 25996976c3dSAjay Kumar u32 val; 26096976c3dSAjay Kumar 26196976c3dSAjay Kumar if (ctx->suspended) 26296976c3dSAjay Kumar return; 26396976c3dSAjay Kumar 26496976c3dSAjay Kumar if (test_and_clear_bit(0, &ctx->irq_flags)) { 26596976c3dSAjay Kumar val = readl(ctx->regs + VIDINTCON0); 26696976c3dSAjay Kumar 26796976c3dSAjay Kumar val &= ~VIDINTCON0_INT_ENABLE; 26896976c3dSAjay Kumar if (!ctx->i80_if) 26996976c3dSAjay Kumar val &= ~VIDINTCON0_INT_FRAME; 27096976c3dSAjay Kumar 27196976c3dSAjay Kumar writel(val, ctx->regs + VIDINTCON0); 27296976c3dSAjay Kumar } 27396976c3dSAjay Kumar } 27496976c3dSAjay Kumar 2752eeb2e5eSGustavo Padovan static void decon_win_set_pixfmt(struct decon_context *ctx, unsigned int win, 2762eeb2e5eSGustavo Padovan struct drm_framebuffer *fb) 27796976c3dSAjay Kumar { 27896976c3dSAjay Kumar unsigned long val; 2797ee14cdcSGustavo Padovan int padding; 28096976c3dSAjay Kumar 28196976c3dSAjay Kumar val = readl(ctx->regs + WINCON(win)); 28296976c3dSAjay Kumar val &= ~WINCONx_BPPMODE_MASK; 28396976c3dSAjay Kumar 2842eeb2e5eSGustavo Padovan switch (fb->pixel_format) { 28596976c3dSAjay Kumar case DRM_FORMAT_RGB565: 28696976c3dSAjay Kumar val |= WINCONx_BPPMODE_16BPP_565; 28796976c3dSAjay Kumar val |= WINCONx_BURSTLEN_16WORD; 28896976c3dSAjay Kumar break; 28996976c3dSAjay Kumar case DRM_FORMAT_XRGB8888: 29096976c3dSAjay Kumar val |= WINCONx_BPPMODE_24BPP_xRGB; 29196976c3dSAjay Kumar val |= WINCONx_BURSTLEN_16WORD; 29296976c3dSAjay Kumar break; 29396976c3dSAjay Kumar case DRM_FORMAT_XBGR8888: 29496976c3dSAjay Kumar val |= WINCONx_BPPMODE_24BPP_xBGR; 29596976c3dSAjay Kumar val |= WINCONx_BURSTLEN_16WORD; 29696976c3dSAjay Kumar break; 29796976c3dSAjay Kumar case DRM_FORMAT_RGBX8888: 29896976c3dSAjay Kumar val |= WINCONx_BPPMODE_24BPP_RGBx; 29996976c3dSAjay Kumar val |= WINCONx_BURSTLEN_16WORD; 30096976c3dSAjay Kumar break; 30196976c3dSAjay Kumar case DRM_FORMAT_BGRX8888: 30296976c3dSAjay Kumar val |= WINCONx_BPPMODE_24BPP_BGRx; 30396976c3dSAjay Kumar val |= WINCONx_BURSTLEN_16WORD; 30496976c3dSAjay Kumar break; 30596976c3dSAjay Kumar case DRM_FORMAT_ARGB8888: 30696976c3dSAjay Kumar val |= WINCONx_BPPMODE_32BPP_ARGB | WINCONx_BLD_PIX | 30796976c3dSAjay Kumar WINCONx_ALPHA_SEL; 30896976c3dSAjay Kumar val |= WINCONx_BURSTLEN_16WORD; 30996976c3dSAjay Kumar break; 31096976c3dSAjay Kumar case DRM_FORMAT_ABGR8888: 31196976c3dSAjay Kumar val |= WINCONx_BPPMODE_32BPP_ABGR | WINCONx_BLD_PIX | 31296976c3dSAjay Kumar WINCONx_ALPHA_SEL; 31396976c3dSAjay Kumar val |= WINCONx_BURSTLEN_16WORD; 31496976c3dSAjay Kumar break; 31596976c3dSAjay Kumar case DRM_FORMAT_RGBA8888: 31696976c3dSAjay Kumar val |= WINCONx_BPPMODE_32BPP_RGBA | WINCONx_BLD_PIX | 31796976c3dSAjay Kumar WINCONx_ALPHA_SEL; 31896976c3dSAjay Kumar val |= WINCONx_BURSTLEN_16WORD; 31996976c3dSAjay Kumar break; 32096976c3dSAjay Kumar case DRM_FORMAT_BGRA8888: 32196976c3dSAjay Kumar val |= WINCONx_BPPMODE_32BPP_BGRA | WINCONx_BLD_PIX | 32296976c3dSAjay Kumar WINCONx_ALPHA_SEL; 32396976c3dSAjay Kumar val |= WINCONx_BURSTLEN_16WORD; 32496976c3dSAjay Kumar break; 32596976c3dSAjay Kumar default: 32696976c3dSAjay Kumar DRM_DEBUG_KMS("invalid pixel size so using unpacked 24bpp.\n"); 32796976c3dSAjay Kumar 32896976c3dSAjay Kumar val |= WINCONx_BPPMODE_24BPP_xRGB; 32996976c3dSAjay Kumar val |= WINCONx_BURSTLEN_16WORD; 33096976c3dSAjay Kumar break; 33196976c3dSAjay Kumar } 33296976c3dSAjay Kumar 3332eeb2e5eSGustavo Padovan DRM_DEBUG_KMS("bpp = %d\n", fb->bits_per_pixel); 33496976c3dSAjay Kumar 33596976c3dSAjay Kumar /* 33696976c3dSAjay Kumar * In case of exynos, setting dma-burst to 16Word causes permanent 33796976c3dSAjay Kumar * tearing for very small buffers, e.g. cursor buffer. Burst Mode 33896976c3dSAjay Kumar * switching which is based on plane size is not recommended as 33996976c3dSAjay Kumar * plane size varies a lot towards the end of the screen and rapid 34096976c3dSAjay Kumar * movement causes unstable DMA which results into iommu crash/tear. 34196976c3dSAjay Kumar */ 34296976c3dSAjay Kumar 3432eeb2e5eSGustavo Padovan padding = (fb->pitches[0] / (fb->bits_per_pixel >> 3)) - fb->width; 3442eeb2e5eSGustavo Padovan if (fb->width + padding < MIN_FB_WIDTH_FOR_16WORD_BURST) { 34596976c3dSAjay Kumar val &= ~WINCONx_BURSTLEN_MASK; 34696976c3dSAjay Kumar val |= WINCONx_BURSTLEN_8WORD; 34796976c3dSAjay Kumar } 34896976c3dSAjay Kumar 34996976c3dSAjay Kumar writel(val, ctx->regs + WINCON(win)); 35096976c3dSAjay Kumar } 35196976c3dSAjay Kumar 35296976c3dSAjay Kumar static void decon_win_set_colkey(struct decon_context *ctx, unsigned int win) 35396976c3dSAjay Kumar { 35496976c3dSAjay Kumar unsigned int keycon0 = 0, keycon1 = 0; 35596976c3dSAjay Kumar 35696976c3dSAjay Kumar keycon0 = ~(WxKEYCON0_KEYBL_EN | WxKEYCON0_KEYEN_F | 35796976c3dSAjay Kumar WxKEYCON0_DIRCON) | WxKEYCON0_COMPKEY(0); 35896976c3dSAjay Kumar 35996976c3dSAjay Kumar keycon1 = WxKEYCON1_COLVAL(0xffffffff); 36096976c3dSAjay Kumar 36196976c3dSAjay Kumar writel(keycon0, ctx->regs + WKEYCON0_BASE(win)); 36296976c3dSAjay Kumar writel(keycon1, ctx->regs + WKEYCON1_BASE(win)); 36396976c3dSAjay Kumar } 36496976c3dSAjay Kumar 36596976c3dSAjay Kumar /** 36696976c3dSAjay Kumar * shadow_protect_win() - disable updating values from shadow registers at vsync 36796976c3dSAjay Kumar * 36896976c3dSAjay Kumar * @win: window to protect registers for 36996976c3dSAjay Kumar * @protect: 1 to protect (disable updates) 37096976c3dSAjay Kumar */ 37196976c3dSAjay Kumar static void decon_shadow_protect_win(struct decon_context *ctx, 3726e2a3b66SGustavo Padovan unsigned int win, bool protect) 37396976c3dSAjay Kumar { 37496976c3dSAjay Kumar u32 bits, val; 37596976c3dSAjay Kumar 37696976c3dSAjay Kumar bits = SHADOWCON_WINx_PROTECT(win); 37796976c3dSAjay Kumar 37896976c3dSAjay Kumar val = readl(ctx->regs + SHADOWCON); 37996976c3dSAjay Kumar if (protect) 38096976c3dSAjay Kumar val |= bits; 38196976c3dSAjay Kumar else 38296976c3dSAjay Kumar val &= ~bits; 38396976c3dSAjay Kumar writel(val, ctx->regs + SHADOWCON); 38496976c3dSAjay Kumar } 38596976c3dSAjay Kumar 3861e1d1393SGustavo Padovan static void decon_update_plane(struct exynos_drm_crtc *crtc, 3871e1d1393SGustavo Padovan struct exynos_drm_plane *plane) 38896976c3dSAjay Kumar { 38996976c3dSAjay Kumar struct decon_context *ctx = crtc->ctx; 390020e79deSJoonyoung Shim struct drm_display_mode *mode = &crtc->base.state->adjusted_mode; 3912eeb2e5eSGustavo Padovan struct drm_plane_state *state = plane->base.state; 3926e2a3b66SGustavo Padovan int padding; 39396976c3dSAjay Kumar unsigned long val, alpha; 39496976c3dSAjay Kumar unsigned int last_x; 39596976c3dSAjay Kumar unsigned int last_y; 3961e1d1393SGustavo Padovan unsigned int win = plane->zpos; 3972eeb2e5eSGustavo Padovan unsigned int bpp = state->fb->bits_per_pixel >> 3; 3982eeb2e5eSGustavo Padovan unsigned int pitch = state->fb->pitches[0]; 39996976c3dSAjay Kumar 40096976c3dSAjay Kumar if (ctx->suspended) 40196976c3dSAjay Kumar return; 40296976c3dSAjay Kumar 40396976c3dSAjay Kumar /* 40496976c3dSAjay Kumar * SHADOWCON/PRTCON register is used for enabling timing. 40596976c3dSAjay Kumar * 40696976c3dSAjay Kumar * for example, once only width value of a register is set, 40796976c3dSAjay Kumar * if the dma is started then decon hardware could malfunction so 40896976c3dSAjay Kumar * with protect window setting, the register fields with prefix '_F' 40996976c3dSAjay Kumar * wouldn't be updated at vsync also but updated once unprotect window 41096976c3dSAjay Kumar * is set. 41196976c3dSAjay Kumar */ 41296976c3dSAjay Kumar 41396976c3dSAjay Kumar /* protect windows */ 41496976c3dSAjay Kumar decon_shadow_protect_win(ctx, win, true); 41596976c3dSAjay Kumar 41696976c3dSAjay Kumar /* buffer start address */ 4177ee14cdcSGustavo Padovan val = (unsigned long)plane->dma_addr[0]; 41896976c3dSAjay Kumar writel(val, ctx->regs + VIDW_BUF_START(win)); 41996976c3dSAjay Kumar 4202eeb2e5eSGustavo Padovan padding = (pitch / bpp) - state->fb->width; 4217ee14cdcSGustavo Padovan 42296976c3dSAjay Kumar /* buffer size */ 4232eeb2e5eSGustavo Padovan writel(state->fb->width + padding, ctx->regs + VIDW_WHOLE_X(win)); 4242eeb2e5eSGustavo Padovan writel(state->fb->height, ctx->regs + VIDW_WHOLE_Y(win)); 42596976c3dSAjay Kumar 42696976c3dSAjay Kumar /* offset from the start of the buffer to read */ 427cb8a3db2SJoonyoung Shim writel(plane->src_x, ctx->regs + VIDW_OFFSET_X(win)); 428cb8a3db2SJoonyoung Shim writel(plane->src_y, ctx->regs + VIDW_OFFSET_Y(win)); 42996976c3dSAjay Kumar 43096976c3dSAjay Kumar DRM_DEBUG_KMS("start addr = 0x%lx\n", 4317ee14cdcSGustavo Padovan (unsigned long)val); 43296976c3dSAjay Kumar DRM_DEBUG_KMS("ovl_width = %d, ovl_height = %d\n", 433d88d2463SGustavo Padovan plane->crtc_w, plane->crtc_h); 43496976c3dSAjay Kumar 43596976c3dSAjay Kumar /* 43696976c3dSAjay Kumar * OSD position. 43796976c3dSAjay Kumar * In case the window layout goes of LCD layout, DECON fails. 43896976c3dSAjay Kumar */ 439d88d2463SGustavo Padovan if ((plane->crtc_x + plane->crtc_w) > mode->hdisplay) 440d88d2463SGustavo Padovan plane->crtc_x = mode->hdisplay - plane->crtc_w; 441d88d2463SGustavo Padovan if ((plane->crtc_y + plane->crtc_h) > mode->vdisplay) 442d88d2463SGustavo Padovan plane->crtc_y = mode->vdisplay - plane->crtc_h; 44396976c3dSAjay Kumar 4447ee14cdcSGustavo Padovan val = VIDOSDxA_TOPLEFT_X(plane->crtc_x) | 4457ee14cdcSGustavo Padovan VIDOSDxA_TOPLEFT_Y(plane->crtc_y); 44696976c3dSAjay Kumar writel(val, ctx->regs + VIDOSD_A(win)); 44796976c3dSAjay Kumar 448d88d2463SGustavo Padovan last_x = plane->crtc_x + plane->crtc_w; 44996976c3dSAjay Kumar if (last_x) 45096976c3dSAjay Kumar last_x--; 451d88d2463SGustavo Padovan last_y = plane->crtc_y + plane->crtc_h; 45296976c3dSAjay Kumar if (last_y) 45396976c3dSAjay Kumar last_y--; 45496976c3dSAjay Kumar 45596976c3dSAjay Kumar val = VIDOSDxB_BOTRIGHT_X(last_x) | VIDOSDxB_BOTRIGHT_Y(last_y); 45696976c3dSAjay Kumar 45796976c3dSAjay Kumar writel(val, ctx->regs + VIDOSD_B(win)); 45896976c3dSAjay Kumar 45996976c3dSAjay Kumar DRM_DEBUG_KMS("osd pos: tx = %d, ty = %d, bx = %d, by = %d\n", 4607ee14cdcSGustavo Padovan plane->crtc_x, plane->crtc_y, last_x, last_y); 46196976c3dSAjay Kumar 46296976c3dSAjay Kumar /* OSD alpha */ 46396976c3dSAjay Kumar alpha = VIDOSDxC_ALPHA0_R_F(0x0) | 46496976c3dSAjay Kumar VIDOSDxC_ALPHA0_G_F(0x0) | 46596976c3dSAjay Kumar VIDOSDxC_ALPHA0_B_F(0x0); 46696976c3dSAjay Kumar 46796976c3dSAjay Kumar writel(alpha, ctx->regs + VIDOSD_C(win)); 46896976c3dSAjay Kumar 46996976c3dSAjay Kumar alpha = VIDOSDxD_ALPHA1_R_F(0xff) | 47096976c3dSAjay Kumar VIDOSDxD_ALPHA1_G_F(0xff) | 47196976c3dSAjay Kumar VIDOSDxD_ALPHA1_B_F(0xff); 47296976c3dSAjay Kumar 47396976c3dSAjay Kumar writel(alpha, ctx->regs + VIDOSD_D(win)); 47496976c3dSAjay Kumar 4752eeb2e5eSGustavo Padovan decon_win_set_pixfmt(ctx, win, state->fb); 47696976c3dSAjay Kumar 47796976c3dSAjay Kumar /* hardware window 0 doesn't support color key. */ 47896976c3dSAjay Kumar if (win != 0) 47996976c3dSAjay Kumar decon_win_set_colkey(ctx, win); 48096976c3dSAjay Kumar 48196976c3dSAjay Kumar /* wincon */ 48296976c3dSAjay Kumar val = readl(ctx->regs + WINCON(win)); 48396976c3dSAjay Kumar val |= WINCONx_TRIPLE_BUF_MODE; 48496976c3dSAjay Kumar val |= WINCONx_ENWIN; 48596976c3dSAjay Kumar writel(val, ctx->regs + WINCON(win)); 48696976c3dSAjay Kumar 48796976c3dSAjay Kumar /* Enable DMA channel and unprotect windows */ 48896976c3dSAjay Kumar decon_shadow_protect_win(ctx, win, false); 48996976c3dSAjay Kumar 49096976c3dSAjay Kumar val = readl(ctx->regs + DECON_UPDATE); 49196976c3dSAjay Kumar val |= DECON_UPDATE_STANDALONE_F; 49296976c3dSAjay Kumar writel(val, ctx->regs + DECON_UPDATE); 49396976c3dSAjay Kumar } 49496976c3dSAjay Kumar 4951e1d1393SGustavo Padovan static void decon_disable_plane(struct exynos_drm_crtc *crtc, 4961e1d1393SGustavo Padovan struct exynos_drm_plane *plane) 49796976c3dSAjay Kumar { 49896976c3dSAjay Kumar struct decon_context *ctx = crtc->ctx; 4991e1d1393SGustavo Padovan unsigned int win = plane->zpos; 50096976c3dSAjay Kumar u32 val; 50196976c3dSAjay Kumar 502c329f667SJoonyoung Shim if (ctx->suspended) 50396976c3dSAjay Kumar return; 50496976c3dSAjay Kumar 50596976c3dSAjay Kumar /* protect windows */ 50696976c3dSAjay Kumar decon_shadow_protect_win(ctx, win, true); 50796976c3dSAjay Kumar 50896976c3dSAjay Kumar /* wincon */ 50996976c3dSAjay Kumar val = readl(ctx->regs + WINCON(win)); 51096976c3dSAjay Kumar val &= ~WINCONx_ENWIN; 51196976c3dSAjay Kumar writel(val, ctx->regs + WINCON(win)); 51296976c3dSAjay Kumar 51396976c3dSAjay Kumar /* unprotect windows */ 51496976c3dSAjay Kumar decon_shadow_protect_win(ctx, win, false); 51596976c3dSAjay Kumar 51696976c3dSAjay Kumar val = readl(ctx->regs + DECON_UPDATE); 51796976c3dSAjay Kumar val |= DECON_UPDATE_STANDALONE_F; 51896976c3dSAjay Kumar writel(val, ctx->regs + DECON_UPDATE); 51996976c3dSAjay Kumar } 52096976c3dSAjay Kumar 52196976c3dSAjay Kumar static void decon_init(struct decon_context *ctx) 52296976c3dSAjay Kumar { 52396976c3dSAjay Kumar u32 val; 52496976c3dSAjay Kumar 52596976c3dSAjay Kumar writel(VIDCON0_SWRESET, ctx->regs + VIDCON0); 52696976c3dSAjay Kumar 52796976c3dSAjay Kumar val = VIDOUTCON0_DISP_IF_0_ON; 52896976c3dSAjay Kumar if (!ctx->i80_if) 52996976c3dSAjay Kumar val |= VIDOUTCON0_RGBIF; 53096976c3dSAjay Kumar writel(val, ctx->regs + VIDOUTCON0); 53196976c3dSAjay Kumar 53296976c3dSAjay Kumar writel(VCLKCON0_CLKVALUP | VCLKCON0_VCLKFREE, ctx->regs + VCLKCON0); 53396976c3dSAjay Kumar 53496976c3dSAjay Kumar if (!ctx->i80_if) 53596976c3dSAjay Kumar writel(VIDCON1_VCLK_HOLD, ctx->regs + VIDCON1(0)); 53696976c3dSAjay Kumar } 53796976c3dSAjay Kumar 5383cecda03SGustavo Padovan static void decon_enable(struct exynos_drm_crtc *crtc) 53996976c3dSAjay Kumar { 5403cecda03SGustavo Padovan struct decon_context *ctx = crtc->ctx; 54138000dbbSGustavo Padovan int ret; 54296976c3dSAjay Kumar 54396976c3dSAjay Kumar if (!ctx->suspended) 5443cecda03SGustavo Padovan return; 54596976c3dSAjay Kumar 54696976c3dSAjay Kumar ctx->suspended = false; 54796976c3dSAjay Kumar 54896976c3dSAjay Kumar pm_runtime_get_sync(ctx->dev); 54996976c3dSAjay Kumar 55038000dbbSGustavo Padovan ret = clk_prepare_enable(ctx->pclk); 55138000dbbSGustavo Padovan if (ret < 0) { 55238000dbbSGustavo Padovan DRM_ERROR("Failed to prepare_enable the pclk [%d]\n", ret); 55338000dbbSGustavo Padovan return; 55438000dbbSGustavo Padovan } 55538000dbbSGustavo Padovan 55638000dbbSGustavo Padovan ret = clk_prepare_enable(ctx->aclk); 55738000dbbSGustavo Padovan if (ret < 0) { 55838000dbbSGustavo Padovan DRM_ERROR("Failed to prepare_enable the aclk [%d]\n", ret); 55938000dbbSGustavo Padovan return; 56038000dbbSGustavo Padovan } 56138000dbbSGustavo Padovan 56238000dbbSGustavo Padovan ret = clk_prepare_enable(ctx->eclk); 56338000dbbSGustavo Padovan if (ret < 0) { 56438000dbbSGustavo Padovan DRM_ERROR("Failed to prepare_enable the eclk [%d]\n", ret); 56538000dbbSGustavo Padovan return; 56638000dbbSGustavo Padovan } 56738000dbbSGustavo Padovan 56838000dbbSGustavo Padovan ret = clk_prepare_enable(ctx->vclk); 56938000dbbSGustavo Padovan if (ret < 0) { 57038000dbbSGustavo Padovan DRM_ERROR("Failed to prepare_enable the vclk [%d]\n", ret); 57138000dbbSGustavo Padovan return; 57238000dbbSGustavo Padovan } 57396976c3dSAjay Kumar 57496976c3dSAjay Kumar decon_init(ctx); 57596976c3dSAjay Kumar 57696976c3dSAjay Kumar /* if vblank was enabled status, enable it again. */ 5773cecda03SGustavo Padovan if (test_and_clear_bit(0, &ctx->irq_flags)) 5783cecda03SGustavo Padovan decon_enable_vblank(ctx->crtc); 57996976c3dSAjay Kumar 580c329f667SJoonyoung Shim decon_commit(ctx->crtc); 58196976c3dSAjay Kumar } 58296976c3dSAjay Kumar 5833cecda03SGustavo Padovan static void decon_disable(struct exynos_drm_crtc *crtc) 58496976c3dSAjay Kumar { 5853cecda03SGustavo Padovan struct decon_context *ctx = crtc->ctx; 586c329f667SJoonyoung Shim int i; 5873cecda03SGustavo Padovan 58896976c3dSAjay Kumar if (ctx->suspended) 5893cecda03SGustavo Padovan return; 59096976c3dSAjay Kumar 59196976c3dSAjay Kumar /* 59296976c3dSAjay Kumar * We need to make sure that all windows are disabled before we 59396976c3dSAjay Kumar * suspend that connector. Otherwise we might try to scan from 59496976c3dSAjay Kumar * a destroyed buffer later. 59596976c3dSAjay Kumar */ 596c329f667SJoonyoung Shim for (i = 0; i < WINDOWS_NR; i++) 5971e1d1393SGustavo Padovan decon_disable_plane(crtc, &ctx->planes[i]); 59896976c3dSAjay Kumar 59996976c3dSAjay Kumar clk_disable_unprepare(ctx->vclk); 60096976c3dSAjay Kumar clk_disable_unprepare(ctx->eclk); 60196976c3dSAjay Kumar clk_disable_unprepare(ctx->aclk); 60296976c3dSAjay Kumar clk_disable_unprepare(ctx->pclk); 60396976c3dSAjay Kumar 60496976c3dSAjay Kumar pm_runtime_put_sync(ctx->dev); 60596976c3dSAjay Kumar 60696976c3dSAjay Kumar ctx->suspended = true; 60796976c3dSAjay Kumar } 60896976c3dSAjay Kumar 609f3aaf762SKrzysztof Kozlowski static const struct exynos_drm_crtc_ops decon_crtc_ops = { 6103cecda03SGustavo Padovan .enable = decon_enable, 6113cecda03SGustavo Padovan .disable = decon_disable, 61296976c3dSAjay Kumar .mode_fixup = decon_mode_fixup, 61396976c3dSAjay Kumar .commit = decon_commit, 61496976c3dSAjay Kumar .enable_vblank = decon_enable_vblank, 61596976c3dSAjay Kumar .disable_vblank = decon_disable_vblank, 61696976c3dSAjay Kumar .wait_for_vblank = decon_wait_for_vblank, 6179cc7610aSGustavo Padovan .update_plane = decon_update_plane, 6189cc7610aSGustavo Padovan .disable_plane = decon_disable_plane, 61996976c3dSAjay Kumar }; 62096976c3dSAjay Kumar 62196976c3dSAjay Kumar 62296976c3dSAjay Kumar static irqreturn_t decon_irq_handler(int irq, void *dev_id) 62396976c3dSAjay Kumar { 62496976c3dSAjay Kumar struct decon_context *ctx = (struct decon_context *)dev_id; 62596976c3dSAjay Kumar u32 val, clear_bit; 62696976c3dSAjay Kumar 62796976c3dSAjay Kumar val = readl(ctx->regs + VIDINTCON1); 62896976c3dSAjay Kumar 62996976c3dSAjay Kumar clear_bit = ctx->i80_if ? VIDINTCON1_INT_I80 : VIDINTCON1_INT_FRAME; 63096976c3dSAjay Kumar if (val & clear_bit) 63196976c3dSAjay Kumar writel(clear_bit, ctx->regs + VIDINTCON1); 63296976c3dSAjay Kumar 63396976c3dSAjay Kumar /* check the crtc is detached already from encoder */ 63496976c3dSAjay Kumar if (ctx->pipe < 0 || !ctx->drm_dev) 63596976c3dSAjay Kumar goto out; 63696976c3dSAjay Kumar 63796976c3dSAjay Kumar if (!ctx->i80_if) { 638eafd540aSGustavo Padovan drm_crtc_handle_vblank(&ctx->crtc->base); 639eafd540aSGustavo Padovan exynos_drm_crtc_finish_pageflip(ctx->crtc); 64096976c3dSAjay Kumar 64196976c3dSAjay Kumar /* set wait vsync event to zero and wake up queue. */ 64296976c3dSAjay Kumar if (atomic_read(&ctx->wait_vsync_event)) { 64396976c3dSAjay Kumar atomic_set(&ctx->wait_vsync_event, 0); 64496976c3dSAjay Kumar wake_up(&ctx->wait_vsync_queue); 64596976c3dSAjay Kumar } 64696976c3dSAjay Kumar } 64796976c3dSAjay Kumar out: 64896976c3dSAjay Kumar return IRQ_HANDLED; 64996976c3dSAjay Kumar } 65096976c3dSAjay Kumar 65196976c3dSAjay Kumar static int decon_bind(struct device *dev, struct device *master, void *data) 65296976c3dSAjay Kumar { 65396976c3dSAjay Kumar struct decon_context *ctx = dev_get_drvdata(dev); 65496976c3dSAjay Kumar struct drm_device *drm_dev = data; 6557ee14cdcSGustavo Padovan struct exynos_drm_plane *exynos_plane; 6567ee14cdcSGustavo Padovan enum drm_plane_type type; 6576e2a3b66SGustavo Padovan unsigned int zpos; 6586e2a3b66SGustavo Padovan int ret; 65996976c3dSAjay Kumar 66096976c3dSAjay Kumar ret = decon_ctx_initialize(ctx, drm_dev); 66196976c3dSAjay Kumar if (ret) { 66296976c3dSAjay Kumar DRM_ERROR("decon_ctx_initialize failed.\n"); 66396976c3dSAjay Kumar return ret; 66496976c3dSAjay Kumar } 66596976c3dSAjay Kumar 6667ee14cdcSGustavo Padovan for (zpos = 0; zpos < WINDOWS_NR; zpos++) { 6677ee14cdcSGustavo Padovan type = (zpos == ctx->default_win) ? DRM_PLANE_TYPE_PRIMARY : 6687ee14cdcSGustavo Padovan DRM_PLANE_TYPE_OVERLAY; 6697ee14cdcSGustavo Padovan ret = exynos_plane_init(drm_dev, &ctx->planes[zpos], 6706e2a3b66SGustavo Padovan 1 << ctx->pipe, type, zpos); 6717ee14cdcSGustavo Padovan if (ret) 6727ee14cdcSGustavo Padovan return ret; 6737ee14cdcSGustavo Padovan } 6747ee14cdcSGustavo Padovan 6757ee14cdcSGustavo Padovan exynos_plane = &ctx->planes[ctx->default_win]; 6767ee14cdcSGustavo Padovan ctx->crtc = exynos_drm_crtc_create(drm_dev, &exynos_plane->base, 6777ee14cdcSGustavo Padovan ctx->pipe, EXYNOS_DISPLAY_TYPE_LCD, 67896976c3dSAjay Kumar &decon_crtc_ops, ctx); 67996976c3dSAjay Kumar if (IS_ERR(ctx->crtc)) { 68096976c3dSAjay Kumar decon_ctx_remove(ctx); 68196976c3dSAjay Kumar return PTR_ERR(ctx->crtc); 68296976c3dSAjay Kumar } 68396976c3dSAjay Kumar 684cf67cc9aSGustavo Padovan if (ctx->encoder) 685*a2986e80SGustavo Padovan exynos_dpi_bind(drm_dev, ctx->encoder); 68696976c3dSAjay Kumar 68796976c3dSAjay Kumar return 0; 68896976c3dSAjay Kumar 68996976c3dSAjay Kumar } 69096976c3dSAjay Kumar 69196976c3dSAjay Kumar static void decon_unbind(struct device *dev, struct device *master, 69296976c3dSAjay Kumar void *data) 69396976c3dSAjay Kumar { 69496976c3dSAjay Kumar struct decon_context *ctx = dev_get_drvdata(dev); 69596976c3dSAjay Kumar 6963cecda03SGustavo Padovan decon_disable(ctx->crtc); 69796976c3dSAjay Kumar 698cf67cc9aSGustavo Padovan if (ctx->encoder) 699cf67cc9aSGustavo Padovan exynos_dpi_remove(ctx->encoder); 70096976c3dSAjay Kumar 70196976c3dSAjay Kumar decon_ctx_remove(ctx); 70296976c3dSAjay Kumar } 70396976c3dSAjay Kumar 70496976c3dSAjay Kumar static const struct component_ops decon_component_ops = { 70596976c3dSAjay Kumar .bind = decon_bind, 70696976c3dSAjay Kumar .unbind = decon_unbind, 70796976c3dSAjay Kumar }; 70896976c3dSAjay Kumar 70996976c3dSAjay Kumar static int decon_probe(struct platform_device *pdev) 71096976c3dSAjay Kumar { 71196976c3dSAjay Kumar struct device *dev = &pdev->dev; 71296976c3dSAjay Kumar struct decon_context *ctx; 71396976c3dSAjay Kumar struct device_node *i80_if_timings; 71496976c3dSAjay Kumar struct resource *res; 71596976c3dSAjay Kumar int ret; 71696976c3dSAjay Kumar 71796976c3dSAjay Kumar if (!dev->of_node) 71896976c3dSAjay Kumar return -ENODEV; 71996976c3dSAjay Kumar 72096976c3dSAjay Kumar ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); 72196976c3dSAjay Kumar if (!ctx) 72296976c3dSAjay Kumar return -ENOMEM; 72396976c3dSAjay Kumar 72496976c3dSAjay Kumar ctx->dev = dev; 72596976c3dSAjay Kumar ctx->suspended = true; 72696976c3dSAjay Kumar 72796976c3dSAjay Kumar i80_if_timings = of_get_child_by_name(dev->of_node, "i80-if-timings"); 72896976c3dSAjay Kumar if (i80_if_timings) 72996976c3dSAjay Kumar ctx->i80_if = true; 73096976c3dSAjay Kumar of_node_put(i80_if_timings); 73196976c3dSAjay Kumar 73296976c3dSAjay Kumar ctx->regs = of_iomap(dev->of_node, 0); 73386650408SAndrzej Hajda if (!ctx->regs) 73486650408SAndrzej Hajda return -ENOMEM; 73596976c3dSAjay Kumar 73696976c3dSAjay Kumar ctx->pclk = devm_clk_get(dev, "pclk_decon0"); 73796976c3dSAjay Kumar if (IS_ERR(ctx->pclk)) { 73896976c3dSAjay Kumar dev_err(dev, "failed to get bus clock pclk\n"); 73996976c3dSAjay Kumar ret = PTR_ERR(ctx->pclk); 74096976c3dSAjay Kumar goto err_iounmap; 74196976c3dSAjay Kumar } 74296976c3dSAjay Kumar 74396976c3dSAjay Kumar ctx->aclk = devm_clk_get(dev, "aclk_decon0"); 74496976c3dSAjay Kumar if (IS_ERR(ctx->aclk)) { 74596976c3dSAjay Kumar dev_err(dev, "failed to get bus clock aclk\n"); 74696976c3dSAjay Kumar ret = PTR_ERR(ctx->aclk); 74796976c3dSAjay Kumar goto err_iounmap; 74896976c3dSAjay Kumar } 74996976c3dSAjay Kumar 75096976c3dSAjay Kumar ctx->eclk = devm_clk_get(dev, "decon0_eclk"); 75196976c3dSAjay Kumar if (IS_ERR(ctx->eclk)) { 75296976c3dSAjay Kumar dev_err(dev, "failed to get eclock\n"); 75396976c3dSAjay Kumar ret = PTR_ERR(ctx->eclk); 75496976c3dSAjay Kumar goto err_iounmap; 75596976c3dSAjay Kumar } 75696976c3dSAjay Kumar 75796976c3dSAjay Kumar ctx->vclk = devm_clk_get(dev, "decon0_vclk"); 75896976c3dSAjay Kumar if (IS_ERR(ctx->vclk)) { 75996976c3dSAjay Kumar dev_err(dev, "failed to get vclock\n"); 76096976c3dSAjay Kumar ret = PTR_ERR(ctx->vclk); 76196976c3dSAjay Kumar goto err_iounmap; 76296976c3dSAjay Kumar } 76396976c3dSAjay Kumar 76496976c3dSAjay Kumar res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, 76596976c3dSAjay Kumar ctx->i80_if ? "lcd_sys" : "vsync"); 76696976c3dSAjay Kumar if (!res) { 76796976c3dSAjay Kumar dev_err(dev, "irq request failed.\n"); 76896976c3dSAjay Kumar ret = -ENXIO; 76996976c3dSAjay Kumar goto err_iounmap; 77096976c3dSAjay Kumar } 77196976c3dSAjay Kumar 77296976c3dSAjay Kumar ret = devm_request_irq(dev, res->start, decon_irq_handler, 77396976c3dSAjay Kumar 0, "drm_decon", ctx); 77496976c3dSAjay Kumar if (ret) { 77596976c3dSAjay Kumar dev_err(dev, "irq request failed.\n"); 77696976c3dSAjay Kumar goto err_iounmap; 77796976c3dSAjay Kumar } 77896976c3dSAjay Kumar 77996976c3dSAjay Kumar init_waitqueue_head(&ctx->wait_vsync_queue); 78096976c3dSAjay Kumar atomic_set(&ctx->wait_vsync_event, 0); 78196976c3dSAjay Kumar 78296976c3dSAjay Kumar platform_set_drvdata(pdev, ctx); 78396976c3dSAjay Kumar 784cf67cc9aSGustavo Padovan ctx->encoder = exynos_dpi_probe(dev); 785cf67cc9aSGustavo Padovan if (IS_ERR(ctx->encoder)) { 786cf67cc9aSGustavo Padovan ret = PTR_ERR(ctx->encoder); 78796976c3dSAjay Kumar goto err_iounmap; 78896976c3dSAjay Kumar } 78996976c3dSAjay Kumar 79096976c3dSAjay Kumar pm_runtime_enable(dev); 79196976c3dSAjay Kumar 79296976c3dSAjay Kumar ret = component_add(dev, &decon_component_ops); 79396976c3dSAjay Kumar if (ret) 79496976c3dSAjay Kumar goto err_disable_pm_runtime; 79596976c3dSAjay Kumar 79696976c3dSAjay Kumar return ret; 79796976c3dSAjay Kumar 79896976c3dSAjay Kumar err_disable_pm_runtime: 79996976c3dSAjay Kumar pm_runtime_disable(dev); 80096976c3dSAjay Kumar 80196976c3dSAjay Kumar err_iounmap: 80296976c3dSAjay Kumar iounmap(ctx->regs); 80396976c3dSAjay Kumar 80496976c3dSAjay Kumar return ret; 80596976c3dSAjay Kumar } 80696976c3dSAjay Kumar 80796976c3dSAjay Kumar static int decon_remove(struct platform_device *pdev) 80896976c3dSAjay Kumar { 80996976c3dSAjay Kumar struct decon_context *ctx = dev_get_drvdata(&pdev->dev); 81096976c3dSAjay Kumar 81196976c3dSAjay Kumar pm_runtime_disable(&pdev->dev); 81296976c3dSAjay Kumar 81396976c3dSAjay Kumar iounmap(ctx->regs); 81496976c3dSAjay Kumar 81596976c3dSAjay Kumar component_del(&pdev->dev, &decon_component_ops); 81696976c3dSAjay Kumar 81796976c3dSAjay Kumar return 0; 81896976c3dSAjay Kumar } 81996976c3dSAjay Kumar 82096976c3dSAjay Kumar struct platform_driver decon_driver = { 82196976c3dSAjay Kumar .probe = decon_probe, 82296976c3dSAjay Kumar .remove = decon_remove, 82396976c3dSAjay Kumar .driver = { 82496976c3dSAjay Kumar .name = "exynos-decon", 82596976c3dSAjay Kumar .of_match_table = decon_driver_dt_match, 82696976c3dSAjay Kumar }, 82796976c3dSAjay Kumar }; 828