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 MIN_FB_WIDTH_FOR_16WORD_BURST 128 4196976c3dSAjay Kumar 4296976c3dSAjay Kumar #define WINDOWS_NR 2 4396976c3dSAjay Kumar 4496976c3dSAjay Kumar struct decon_context { 4596976c3dSAjay Kumar struct device *dev; 4696976c3dSAjay Kumar struct drm_device *drm_dev; 4796976c3dSAjay Kumar struct exynos_drm_crtc *crtc; 487ee14cdcSGustavo Padovan struct exynos_drm_plane planes[WINDOWS_NR]; 4996976c3dSAjay Kumar struct clk *pclk; 5096976c3dSAjay Kumar struct clk *aclk; 5196976c3dSAjay Kumar struct clk *eclk; 5296976c3dSAjay Kumar struct clk *vclk; 5396976c3dSAjay Kumar void __iomem *regs; 5496976c3dSAjay Kumar unsigned long irq_flags; 5596976c3dSAjay Kumar bool i80_if; 5696976c3dSAjay Kumar bool suspended; 5796976c3dSAjay Kumar int pipe; 5896976c3dSAjay Kumar wait_queue_head_t wait_vsync_queue; 5996976c3dSAjay Kumar atomic_t wait_vsync_event; 6096976c3dSAjay Kumar 6196976c3dSAjay Kumar struct exynos_drm_panel_info panel; 622b8376c8SGustavo Padovan struct drm_encoder *encoder; 6396976c3dSAjay Kumar }; 6496976c3dSAjay Kumar 6596976c3dSAjay Kumar static const struct of_device_id decon_driver_dt_match[] = { 6696976c3dSAjay Kumar {.compatible = "samsung,exynos7-decon"}, 6796976c3dSAjay Kumar {}, 6896976c3dSAjay Kumar }; 6996976c3dSAjay Kumar MODULE_DEVICE_TABLE(of, decon_driver_dt_match); 7096976c3dSAjay Kumar 71fbbb1e1aSMarek Szyprowski static const uint32_t decon_formats[] = { 72fbbb1e1aSMarek Szyprowski DRM_FORMAT_RGB565, 73fbbb1e1aSMarek Szyprowski DRM_FORMAT_XRGB8888, 74fbbb1e1aSMarek Szyprowski DRM_FORMAT_XBGR8888, 75fbbb1e1aSMarek Szyprowski DRM_FORMAT_RGBX8888, 76fbbb1e1aSMarek Szyprowski DRM_FORMAT_BGRX8888, 77fbbb1e1aSMarek Szyprowski DRM_FORMAT_ARGB8888, 78fbbb1e1aSMarek Szyprowski DRM_FORMAT_ABGR8888, 79fbbb1e1aSMarek Szyprowski DRM_FORMAT_RGBA8888, 80fbbb1e1aSMarek Szyprowski DRM_FORMAT_BGRA8888, 81fbbb1e1aSMarek Szyprowski }; 82fbbb1e1aSMarek Szyprowski 8396976c3dSAjay Kumar static void decon_wait_for_vblank(struct exynos_drm_crtc *crtc) 8496976c3dSAjay Kumar { 8596976c3dSAjay Kumar struct decon_context *ctx = crtc->ctx; 8696976c3dSAjay Kumar 8796976c3dSAjay Kumar if (ctx->suspended) 8896976c3dSAjay Kumar return; 8996976c3dSAjay Kumar 9096976c3dSAjay Kumar atomic_set(&ctx->wait_vsync_event, 1); 9196976c3dSAjay Kumar 9296976c3dSAjay Kumar /* 9396976c3dSAjay Kumar * wait for DECON to signal VSYNC interrupt or return after 9496976c3dSAjay Kumar * timeout which is set to 50ms (refresh rate of 20). 9596976c3dSAjay Kumar */ 9696976c3dSAjay Kumar if (!wait_event_timeout(ctx->wait_vsync_queue, 9796976c3dSAjay Kumar !atomic_read(&ctx->wait_vsync_event), 9896976c3dSAjay Kumar HZ/20)) 9996976c3dSAjay Kumar DRM_DEBUG_KMS("vblank wait timed out.\n"); 10096976c3dSAjay Kumar } 10196976c3dSAjay Kumar 102fc2e013fSHyungwon Hwang static void decon_clear_channels(struct exynos_drm_crtc *crtc) 10396976c3dSAjay Kumar { 104fc2e013fSHyungwon Hwang struct decon_context *ctx = crtc->ctx; 1055b1d5bc6STobias Jakobi unsigned int win, ch_enabled = 0; 10696976c3dSAjay Kumar 10796976c3dSAjay Kumar DRM_DEBUG_KMS("%s\n", __FILE__); 10896976c3dSAjay Kumar 10996976c3dSAjay Kumar /* Check if any channel is enabled. */ 11096976c3dSAjay Kumar for (win = 0; win < WINDOWS_NR; win++) { 11196976c3dSAjay Kumar u32 val = readl(ctx->regs + WINCON(win)); 11296976c3dSAjay Kumar 11396976c3dSAjay Kumar if (val & WINCONx_ENWIN) { 11496976c3dSAjay Kumar val &= ~WINCONx_ENWIN; 11596976c3dSAjay Kumar writel(val, ctx->regs + WINCON(win)); 11696976c3dSAjay Kumar ch_enabled = 1; 11796976c3dSAjay Kumar } 11896976c3dSAjay Kumar } 11996976c3dSAjay Kumar 12096976c3dSAjay Kumar /* Wait for vsync, as disable channel takes effect at next vsync */ 12196976c3dSAjay Kumar if (ch_enabled) { 12296976c3dSAjay Kumar unsigned int state = ctx->suspended; 12396976c3dSAjay Kumar 12496976c3dSAjay Kumar ctx->suspended = 0; 12596976c3dSAjay Kumar decon_wait_for_vblank(ctx->crtc); 12696976c3dSAjay Kumar ctx->suspended = state; 12796976c3dSAjay Kumar } 12896976c3dSAjay Kumar } 12996976c3dSAjay Kumar 13096976c3dSAjay Kumar static int decon_ctx_initialize(struct decon_context *ctx, 13196976c3dSAjay Kumar struct drm_device *drm_dev) 13296976c3dSAjay Kumar { 13396976c3dSAjay Kumar struct exynos_drm_private *priv = drm_dev->dev_private; 134fc2e013fSHyungwon Hwang int ret; 13596976c3dSAjay Kumar 13696976c3dSAjay Kumar ctx->drm_dev = drm_dev; 13796976c3dSAjay Kumar ctx->pipe = priv->pipe++; 13896976c3dSAjay Kumar 139eb7a3fc7SJoonyoung Shim decon_clear_channels(ctx->crtc); 140eb7a3fc7SJoonyoung Shim 141eb7a3fc7SJoonyoung Shim ret = drm_iommu_attach_device(drm_dev, ctx->dev); 142fc2e013fSHyungwon Hwang if (ret) 143fc2e013fSHyungwon Hwang priv->pipe--; 14496976c3dSAjay Kumar 14596976c3dSAjay Kumar return ret; 14696976c3dSAjay Kumar } 14796976c3dSAjay Kumar 14896976c3dSAjay Kumar static void decon_ctx_remove(struct decon_context *ctx) 14996976c3dSAjay Kumar { 15096976c3dSAjay Kumar /* detach this sub driver from iommu mapping if supported. */ 15196976c3dSAjay Kumar drm_iommu_detach_device(ctx->drm_dev, ctx->dev); 15296976c3dSAjay Kumar } 15396976c3dSAjay Kumar 15496976c3dSAjay Kumar static u32 decon_calc_clkdiv(struct decon_context *ctx, 15596976c3dSAjay Kumar const struct drm_display_mode *mode) 15696976c3dSAjay Kumar { 15796976c3dSAjay Kumar unsigned long ideal_clk = mode->htotal * mode->vtotal * mode->vrefresh; 15896976c3dSAjay Kumar u32 clkdiv; 15996976c3dSAjay Kumar 16096976c3dSAjay Kumar /* Find the clock divider value that gets us closest to ideal_clk */ 16196976c3dSAjay Kumar clkdiv = DIV_ROUND_UP(clk_get_rate(ctx->vclk), ideal_clk); 16296976c3dSAjay Kumar 16396976c3dSAjay Kumar return (clkdiv < 0x100) ? clkdiv : 0xff; 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 386cc5a7b35SHyungwon Hwang static void decon_atomic_begin(struct exynos_drm_crtc *crtc, 387cc5a7b35SHyungwon Hwang struct exynos_drm_plane *plane) 388cc5a7b35SHyungwon Hwang { 389cc5a7b35SHyungwon Hwang struct decon_context *ctx = crtc->ctx; 390cc5a7b35SHyungwon Hwang 391cc5a7b35SHyungwon Hwang if (ctx->suspended) 392cc5a7b35SHyungwon Hwang return; 393cc5a7b35SHyungwon Hwang 394cc5a7b35SHyungwon Hwang decon_shadow_protect_win(ctx, plane->zpos, true); 395cc5a7b35SHyungwon Hwang } 396cc5a7b35SHyungwon Hwang 3971e1d1393SGustavo Padovan static void decon_update_plane(struct exynos_drm_crtc *crtc, 3981e1d1393SGustavo Padovan struct exynos_drm_plane *plane) 39996976c3dSAjay Kumar { 40096976c3dSAjay Kumar struct decon_context *ctx = crtc->ctx; 401020e79deSJoonyoung Shim struct drm_display_mode *mode = &crtc->base.state->adjusted_mode; 4022eeb2e5eSGustavo Padovan struct drm_plane_state *state = plane->base.state; 4036e2a3b66SGustavo Padovan int padding; 40496976c3dSAjay Kumar unsigned long val, alpha; 40596976c3dSAjay Kumar unsigned int last_x; 40696976c3dSAjay Kumar unsigned int last_y; 4071e1d1393SGustavo Padovan unsigned int win = plane->zpos; 4082eeb2e5eSGustavo Padovan unsigned int bpp = state->fb->bits_per_pixel >> 3; 4092eeb2e5eSGustavo Padovan unsigned int pitch = state->fb->pitches[0]; 41096976c3dSAjay Kumar 41196976c3dSAjay Kumar if (ctx->suspended) 41296976c3dSAjay Kumar return; 41396976c3dSAjay Kumar 41496976c3dSAjay Kumar /* 41596976c3dSAjay Kumar * SHADOWCON/PRTCON register is used for enabling timing. 41696976c3dSAjay Kumar * 41796976c3dSAjay Kumar * for example, once only width value of a register is set, 41896976c3dSAjay Kumar * if the dma is started then decon hardware could malfunction so 41996976c3dSAjay Kumar * with protect window setting, the register fields with prefix '_F' 42096976c3dSAjay Kumar * wouldn't be updated at vsync also but updated once unprotect window 42196976c3dSAjay Kumar * is set. 42296976c3dSAjay Kumar */ 42396976c3dSAjay Kumar 42496976c3dSAjay Kumar /* buffer start address */ 4257ee14cdcSGustavo Padovan val = (unsigned long)plane->dma_addr[0]; 42696976c3dSAjay Kumar writel(val, ctx->regs + VIDW_BUF_START(win)); 42796976c3dSAjay Kumar 4282eeb2e5eSGustavo Padovan padding = (pitch / bpp) - state->fb->width; 4297ee14cdcSGustavo Padovan 43096976c3dSAjay Kumar /* buffer size */ 4312eeb2e5eSGustavo Padovan writel(state->fb->width + padding, ctx->regs + VIDW_WHOLE_X(win)); 4322eeb2e5eSGustavo Padovan writel(state->fb->height, ctx->regs + VIDW_WHOLE_Y(win)); 43396976c3dSAjay Kumar 43496976c3dSAjay Kumar /* offset from the start of the buffer to read */ 435cb8a3db2SJoonyoung Shim writel(plane->src_x, ctx->regs + VIDW_OFFSET_X(win)); 436cb8a3db2SJoonyoung Shim writel(plane->src_y, ctx->regs + VIDW_OFFSET_Y(win)); 43796976c3dSAjay Kumar 43896976c3dSAjay Kumar DRM_DEBUG_KMS("start addr = 0x%lx\n", 4397ee14cdcSGustavo Padovan (unsigned long)val); 44096976c3dSAjay Kumar DRM_DEBUG_KMS("ovl_width = %d, ovl_height = %d\n", 441d88d2463SGustavo Padovan plane->crtc_w, plane->crtc_h); 44296976c3dSAjay Kumar 44396976c3dSAjay Kumar /* 44496976c3dSAjay Kumar * OSD position. 44596976c3dSAjay Kumar * In case the window layout goes of LCD layout, DECON fails. 44696976c3dSAjay Kumar */ 447d88d2463SGustavo Padovan if ((plane->crtc_x + plane->crtc_w) > mode->hdisplay) 448d88d2463SGustavo Padovan plane->crtc_x = mode->hdisplay - plane->crtc_w; 449d88d2463SGustavo Padovan if ((plane->crtc_y + plane->crtc_h) > mode->vdisplay) 450d88d2463SGustavo Padovan plane->crtc_y = mode->vdisplay - plane->crtc_h; 45196976c3dSAjay Kumar 4527ee14cdcSGustavo Padovan val = VIDOSDxA_TOPLEFT_X(plane->crtc_x) | 4537ee14cdcSGustavo Padovan VIDOSDxA_TOPLEFT_Y(plane->crtc_y); 45496976c3dSAjay Kumar writel(val, ctx->regs + VIDOSD_A(win)); 45596976c3dSAjay Kumar 456d88d2463SGustavo Padovan last_x = plane->crtc_x + plane->crtc_w; 45796976c3dSAjay Kumar if (last_x) 45896976c3dSAjay Kumar last_x--; 459d88d2463SGustavo Padovan last_y = plane->crtc_y + plane->crtc_h; 46096976c3dSAjay Kumar if (last_y) 46196976c3dSAjay Kumar last_y--; 46296976c3dSAjay Kumar 46396976c3dSAjay Kumar val = VIDOSDxB_BOTRIGHT_X(last_x) | VIDOSDxB_BOTRIGHT_Y(last_y); 46496976c3dSAjay Kumar 46596976c3dSAjay Kumar writel(val, ctx->regs + VIDOSD_B(win)); 46696976c3dSAjay Kumar 46796976c3dSAjay Kumar DRM_DEBUG_KMS("osd pos: tx = %d, ty = %d, bx = %d, by = %d\n", 4687ee14cdcSGustavo Padovan plane->crtc_x, plane->crtc_y, last_x, last_y); 46996976c3dSAjay Kumar 47096976c3dSAjay Kumar /* OSD alpha */ 47196976c3dSAjay Kumar alpha = VIDOSDxC_ALPHA0_R_F(0x0) | 47296976c3dSAjay Kumar VIDOSDxC_ALPHA0_G_F(0x0) | 47396976c3dSAjay Kumar VIDOSDxC_ALPHA0_B_F(0x0); 47496976c3dSAjay Kumar 47596976c3dSAjay Kumar writel(alpha, ctx->regs + VIDOSD_C(win)); 47696976c3dSAjay Kumar 47796976c3dSAjay Kumar alpha = VIDOSDxD_ALPHA1_R_F(0xff) | 47896976c3dSAjay Kumar VIDOSDxD_ALPHA1_G_F(0xff) | 47996976c3dSAjay Kumar VIDOSDxD_ALPHA1_B_F(0xff); 48096976c3dSAjay Kumar 48196976c3dSAjay Kumar writel(alpha, ctx->regs + VIDOSD_D(win)); 48296976c3dSAjay Kumar 4832eeb2e5eSGustavo Padovan decon_win_set_pixfmt(ctx, win, state->fb); 48496976c3dSAjay Kumar 48596976c3dSAjay Kumar /* hardware window 0 doesn't support color key. */ 48696976c3dSAjay Kumar if (win != 0) 48796976c3dSAjay Kumar decon_win_set_colkey(ctx, win); 48896976c3dSAjay Kumar 48996976c3dSAjay Kumar /* wincon */ 49096976c3dSAjay Kumar val = readl(ctx->regs + WINCON(win)); 49196976c3dSAjay Kumar val |= WINCONx_TRIPLE_BUF_MODE; 49296976c3dSAjay Kumar val |= WINCONx_ENWIN; 49396976c3dSAjay Kumar writel(val, ctx->regs + WINCON(win)); 49496976c3dSAjay Kumar 49596976c3dSAjay Kumar /* Enable DMA channel and unprotect windows */ 49696976c3dSAjay Kumar decon_shadow_protect_win(ctx, win, false); 49796976c3dSAjay Kumar 49896976c3dSAjay Kumar val = readl(ctx->regs + DECON_UPDATE); 49996976c3dSAjay Kumar val |= DECON_UPDATE_STANDALONE_F; 50096976c3dSAjay Kumar writel(val, ctx->regs + DECON_UPDATE); 50196976c3dSAjay Kumar } 50296976c3dSAjay Kumar 5031e1d1393SGustavo Padovan static void decon_disable_plane(struct exynos_drm_crtc *crtc, 5041e1d1393SGustavo Padovan struct exynos_drm_plane *plane) 50596976c3dSAjay Kumar { 50696976c3dSAjay Kumar struct decon_context *ctx = crtc->ctx; 5071e1d1393SGustavo Padovan unsigned int win = plane->zpos; 50896976c3dSAjay Kumar u32 val; 50996976c3dSAjay Kumar 510c329f667SJoonyoung Shim if (ctx->suspended) 51196976c3dSAjay Kumar return; 51296976c3dSAjay Kumar 51396976c3dSAjay Kumar /* protect windows */ 51496976c3dSAjay Kumar decon_shadow_protect_win(ctx, win, true); 51596976c3dSAjay Kumar 51696976c3dSAjay Kumar /* wincon */ 51796976c3dSAjay Kumar val = readl(ctx->regs + WINCON(win)); 51896976c3dSAjay Kumar val &= ~WINCONx_ENWIN; 51996976c3dSAjay Kumar writel(val, ctx->regs + WINCON(win)); 52096976c3dSAjay Kumar 52196976c3dSAjay Kumar val = readl(ctx->regs + DECON_UPDATE); 52296976c3dSAjay Kumar val |= DECON_UPDATE_STANDALONE_F; 52396976c3dSAjay Kumar writel(val, ctx->regs + DECON_UPDATE); 52496976c3dSAjay Kumar } 52596976c3dSAjay Kumar 526cc5a7b35SHyungwon Hwang static void decon_atomic_flush(struct exynos_drm_crtc *crtc, 527cc5a7b35SHyungwon Hwang struct exynos_drm_plane *plane) 528cc5a7b35SHyungwon Hwang { 529cc5a7b35SHyungwon Hwang struct decon_context *ctx = crtc->ctx; 530cc5a7b35SHyungwon Hwang 531cc5a7b35SHyungwon Hwang if (ctx->suspended) 532cc5a7b35SHyungwon Hwang return; 533cc5a7b35SHyungwon Hwang 534cc5a7b35SHyungwon Hwang decon_shadow_protect_win(ctx, plane->zpos, false); 535cc5a7b35SHyungwon Hwang } 536cc5a7b35SHyungwon Hwang 53796976c3dSAjay Kumar static void decon_init(struct decon_context *ctx) 53896976c3dSAjay Kumar { 53996976c3dSAjay Kumar u32 val; 54096976c3dSAjay Kumar 54196976c3dSAjay Kumar writel(VIDCON0_SWRESET, ctx->regs + VIDCON0); 54296976c3dSAjay Kumar 54396976c3dSAjay Kumar val = VIDOUTCON0_DISP_IF_0_ON; 54496976c3dSAjay Kumar if (!ctx->i80_if) 54596976c3dSAjay Kumar val |= VIDOUTCON0_RGBIF; 54696976c3dSAjay Kumar writel(val, ctx->regs + VIDOUTCON0); 54796976c3dSAjay Kumar 54896976c3dSAjay Kumar writel(VCLKCON0_CLKVALUP | VCLKCON0_VCLKFREE, ctx->regs + VCLKCON0); 54996976c3dSAjay Kumar 55096976c3dSAjay Kumar if (!ctx->i80_if) 55196976c3dSAjay Kumar writel(VIDCON1_VCLK_HOLD, ctx->regs + VIDCON1(0)); 55296976c3dSAjay Kumar } 55396976c3dSAjay Kumar 5543cecda03SGustavo Padovan static void decon_enable(struct exynos_drm_crtc *crtc) 55596976c3dSAjay Kumar { 5563cecda03SGustavo Padovan struct decon_context *ctx = crtc->ctx; 55738000dbbSGustavo Padovan int ret; 55896976c3dSAjay Kumar 55996976c3dSAjay Kumar if (!ctx->suspended) 5603cecda03SGustavo Padovan return; 56196976c3dSAjay Kumar 56296976c3dSAjay Kumar ctx->suspended = false; 56396976c3dSAjay Kumar 56496976c3dSAjay Kumar pm_runtime_get_sync(ctx->dev); 56596976c3dSAjay Kumar 56638000dbbSGustavo Padovan ret = clk_prepare_enable(ctx->pclk); 56738000dbbSGustavo Padovan if (ret < 0) { 56838000dbbSGustavo Padovan DRM_ERROR("Failed to prepare_enable the pclk [%d]\n", ret); 56938000dbbSGustavo Padovan return; 57038000dbbSGustavo Padovan } 57138000dbbSGustavo Padovan 57238000dbbSGustavo Padovan ret = clk_prepare_enable(ctx->aclk); 57338000dbbSGustavo Padovan if (ret < 0) { 57438000dbbSGustavo Padovan DRM_ERROR("Failed to prepare_enable the aclk [%d]\n", ret); 57538000dbbSGustavo Padovan return; 57638000dbbSGustavo Padovan } 57738000dbbSGustavo Padovan 57838000dbbSGustavo Padovan ret = clk_prepare_enable(ctx->eclk); 57938000dbbSGustavo Padovan if (ret < 0) { 58038000dbbSGustavo Padovan DRM_ERROR("Failed to prepare_enable the eclk [%d]\n", ret); 58138000dbbSGustavo Padovan return; 58238000dbbSGustavo Padovan } 58338000dbbSGustavo Padovan 58438000dbbSGustavo Padovan ret = clk_prepare_enable(ctx->vclk); 58538000dbbSGustavo Padovan if (ret < 0) { 58638000dbbSGustavo Padovan DRM_ERROR("Failed to prepare_enable the vclk [%d]\n", ret); 58738000dbbSGustavo Padovan return; 58838000dbbSGustavo Padovan } 58996976c3dSAjay Kumar 59096976c3dSAjay Kumar decon_init(ctx); 59196976c3dSAjay Kumar 59296976c3dSAjay Kumar /* if vblank was enabled status, enable it again. */ 5933cecda03SGustavo Padovan if (test_and_clear_bit(0, &ctx->irq_flags)) 5943cecda03SGustavo Padovan decon_enable_vblank(ctx->crtc); 59596976c3dSAjay Kumar 596c329f667SJoonyoung Shim decon_commit(ctx->crtc); 59796976c3dSAjay Kumar } 59896976c3dSAjay Kumar 5993cecda03SGustavo Padovan static void decon_disable(struct exynos_drm_crtc *crtc) 60096976c3dSAjay Kumar { 6013cecda03SGustavo Padovan struct decon_context *ctx = crtc->ctx; 602c329f667SJoonyoung Shim int i; 6033cecda03SGustavo Padovan 60496976c3dSAjay Kumar if (ctx->suspended) 6053cecda03SGustavo Padovan return; 60696976c3dSAjay Kumar 60796976c3dSAjay Kumar /* 60896976c3dSAjay Kumar * We need to make sure that all windows are disabled before we 60996976c3dSAjay Kumar * suspend that connector. Otherwise we might try to scan from 61096976c3dSAjay Kumar * a destroyed buffer later. 61196976c3dSAjay Kumar */ 612c329f667SJoonyoung Shim for (i = 0; i < WINDOWS_NR; i++) 6131e1d1393SGustavo Padovan decon_disable_plane(crtc, &ctx->planes[i]); 61496976c3dSAjay Kumar 61596976c3dSAjay Kumar clk_disable_unprepare(ctx->vclk); 61696976c3dSAjay Kumar clk_disable_unprepare(ctx->eclk); 61796976c3dSAjay Kumar clk_disable_unprepare(ctx->aclk); 61896976c3dSAjay Kumar clk_disable_unprepare(ctx->pclk); 61996976c3dSAjay Kumar 62096976c3dSAjay Kumar pm_runtime_put_sync(ctx->dev); 62196976c3dSAjay Kumar 62296976c3dSAjay Kumar ctx->suspended = true; 62396976c3dSAjay Kumar } 62496976c3dSAjay Kumar 625f3aaf762SKrzysztof Kozlowski static const struct exynos_drm_crtc_ops decon_crtc_ops = { 6263cecda03SGustavo Padovan .enable = decon_enable, 6273cecda03SGustavo Padovan .disable = decon_disable, 62896976c3dSAjay Kumar .commit = decon_commit, 62996976c3dSAjay Kumar .enable_vblank = decon_enable_vblank, 63096976c3dSAjay Kumar .disable_vblank = decon_disable_vblank, 63196976c3dSAjay Kumar .wait_for_vblank = decon_wait_for_vblank, 632cc5a7b35SHyungwon Hwang .atomic_begin = decon_atomic_begin, 6339cc7610aSGustavo Padovan .update_plane = decon_update_plane, 6349cc7610aSGustavo Padovan .disable_plane = decon_disable_plane, 635cc5a7b35SHyungwon Hwang .atomic_flush = decon_atomic_flush, 63696976c3dSAjay Kumar }; 63796976c3dSAjay Kumar 63896976c3dSAjay Kumar 63996976c3dSAjay Kumar static irqreturn_t decon_irq_handler(int irq, void *dev_id) 64096976c3dSAjay Kumar { 64196976c3dSAjay Kumar struct decon_context *ctx = (struct decon_context *)dev_id; 64296976c3dSAjay Kumar u32 val, clear_bit; 643822f6dfdSGustavo Padovan int win; 64496976c3dSAjay Kumar 64596976c3dSAjay Kumar val = readl(ctx->regs + VIDINTCON1); 64696976c3dSAjay Kumar 64796976c3dSAjay Kumar clear_bit = ctx->i80_if ? VIDINTCON1_INT_I80 : VIDINTCON1_INT_FRAME; 64896976c3dSAjay Kumar if (val & clear_bit) 64996976c3dSAjay Kumar writel(clear_bit, ctx->regs + VIDINTCON1); 65096976c3dSAjay Kumar 65196976c3dSAjay Kumar /* check the crtc is detached already from encoder */ 65296976c3dSAjay Kumar if (ctx->pipe < 0 || !ctx->drm_dev) 65396976c3dSAjay Kumar goto out; 65496976c3dSAjay Kumar 65596976c3dSAjay Kumar if (!ctx->i80_if) { 656eafd540aSGustavo Padovan drm_crtc_handle_vblank(&ctx->crtc->base); 657822f6dfdSGustavo Padovan for (win = 0 ; win < WINDOWS_NR ; win++) { 658822f6dfdSGustavo Padovan struct exynos_drm_plane *plane = &ctx->planes[win]; 659822f6dfdSGustavo Padovan 660822f6dfdSGustavo Padovan if (!plane->pending_fb) 661822f6dfdSGustavo Padovan continue; 662822f6dfdSGustavo Padovan 663822f6dfdSGustavo Padovan exynos_drm_crtc_finish_update(ctx->crtc, plane); 664822f6dfdSGustavo Padovan } 66596976c3dSAjay Kumar 66696976c3dSAjay Kumar /* set wait vsync event to zero and wake up queue. */ 66796976c3dSAjay Kumar if (atomic_read(&ctx->wait_vsync_event)) { 66896976c3dSAjay Kumar atomic_set(&ctx->wait_vsync_event, 0); 66996976c3dSAjay Kumar wake_up(&ctx->wait_vsync_queue); 67096976c3dSAjay Kumar } 67196976c3dSAjay Kumar } 67296976c3dSAjay Kumar out: 67396976c3dSAjay Kumar return IRQ_HANDLED; 67496976c3dSAjay Kumar } 67596976c3dSAjay Kumar 67696976c3dSAjay Kumar static int decon_bind(struct device *dev, struct device *master, void *data) 67796976c3dSAjay Kumar { 67896976c3dSAjay Kumar struct decon_context *ctx = dev_get_drvdata(dev); 67996976c3dSAjay Kumar struct drm_device *drm_dev = data; 6807ee14cdcSGustavo Padovan struct exynos_drm_plane *exynos_plane; 6817ee14cdcSGustavo Padovan enum drm_plane_type type; 6826e2a3b66SGustavo Padovan unsigned int zpos; 6836e2a3b66SGustavo Padovan int ret; 68496976c3dSAjay Kumar 68596976c3dSAjay Kumar ret = decon_ctx_initialize(ctx, drm_dev); 68696976c3dSAjay Kumar if (ret) { 68796976c3dSAjay Kumar DRM_ERROR("decon_ctx_initialize failed.\n"); 68896976c3dSAjay Kumar return ret; 68996976c3dSAjay Kumar } 69096976c3dSAjay Kumar 6917ee14cdcSGustavo Padovan for (zpos = 0; zpos < WINDOWS_NR; zpos++) { 692*5d3d0995SGustavo Padovan type = (zpos == DEFAULT_WIN) ? DRM_PLANE_TYPE_PRIMARY : 6937ee14cdcSGustavo Padovan DRM_PLANE_TYPE_OVERLAY; 6947ee14cdcSGustavo Padovan ret = exynos_plane_init(drm_dev, &ctx->planes[zpos], 695fbbb1e1aSMarek Szyprowski 1 << ctx->pipe, type, decon_formats, 696fbbb1e1aSMarek Szyprowski ARRAY_SIZE(decon_formats), zpos); 6977ee14cdcSGustavo Padovan if (ret) 6987ee14cdcSGustavo Padovan return ret; 6997ee14cdcSGustavo Padovan } 7007ee14cdcSGustavo Padovan 701*5d3d0995SGustavo Padovan exynos_plane = &ctx->planes[DEFAULT_WIN]; 7027ee14cdcSGustavo Padovan ctx->crtc = exynos_drm_crtc_create(drm_dev, &exynos_plane->base, 7037ee14cdcSGustavo Padovan ctx->pipe, EXYNOS_DISPLAY_TYPE_LCD, 70496976c3dSAjay Kumar &decon_crtc_ops, ctx); 70596976c3dSAjay Kumar if (IS_ERR(ctx->crtc)) { 70696976c3dSAjay Kumar decon_ctx_remove(ctx); 70796976c3dSAjay Kumar return PTR_ERR(ctx->crtc); 70896976c3dSAjay Kumar } 70996976c3dSAjay Kumar 710cf67cc9aSGustavo Padovan if (ctx->encoder) 711a2986e80SGustavo Padovan exynos_dpi_bind(drm_dev, ctx->encoder); 71296976c3dSAjay Kumar 71396976c3dSAjay Kumar return 0; 71496976c3dSAjay Kumar 71596976c3dSAjay Kumar } 71696976c3dSAjay Kumar 71796976c3dSAjay Kumar static void decon_unbind(struct device *dev, struct device *master, 71896976c3dSAjay Kumar void *data) 71996976c3dSAjay Kumar { 72096976c3dSAjay Kumar struct decon_context *ctx = dev_get_drvdata(dev); 72196976c3dSAjay Kumar 7223cecda03SGustavo Padovan decon_disable(ctx->crtc); 72396976c3dSAjay Kumar 724cf67cc9aSGustavo Padovan if (ctx->encoder) 725cf67cc9aSGustavo Padovan exynos_dpi_remove(ctx->encoder); 72696976c3dSAjay Kumar 72796976c3dSAjay Kumar decon_ctx_remove(ctx); 72896976c3dSAjay Kumar } 72996976c3dSAjay Kumar 73096976c3dSAjay Kumar static const struct component_ops decon_component_ops = { 73196976c3dSAjay Kumar .bind = decon_bind, 73296976c3dSAjay Kumar .unbind = decon_unbind, 73396976c3dSAjay Kumar }; 73496976c3dSAjay Kumar 73596976c3dSAjay Kumar static int decon_probe(struct platform_device *pdev) 73696976c3dSAjay Kumar { 73796976c3dSAjay Kumar struct device *dev = &pdev->dev; 73896976c3dSAjay Kumar struct decon_context *ctx; 73996976c3dSAjay Kumar struct device_node *i80_if_timings; 74096976c3dSAjay Kumar struct resource *res; 74196976c3dSAjay Kumar int ret; 74296976c3dSAjay Kumar 74396976c3dSAjay Kumar if (!dev->of_node) 74496976c3dSAjay Kumar return -ENODEV; 74596976c3dSAjay Kumar 74696976c3dSAjay Kumar ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); 74796976c3dSAjay Kumar if (!ctx) 74896976c3dSAjay Kumar return -ENOMEM; 74996976c3dSAjay Kumar 75096976c3dSAjay Kumar ctx->dev = dev; 75196976c3dSAjay Kumar ctx->suspended = true; 75296976c3dSAjay Kumar 75396976c3dSAjay Kumar i80_if_timings = of_get_child_by_name(dev->of_node, "i80-if-timings"); 75496976c3dSAjay Kumar if (i80_if_timings) 75596976c3dSAjay Kumar ctx->i80_if = true; 75696976c3dSAjay Kumar of_node_put(i80_if_timings); 75796976c3dSAjay Kumar 75896976c3dSAjay Kumar ctx->regs = of_iomap(dev->of_node, 0); 75986650408SAndrzej Hajda if (!ctx->regs) 76086650408SAndrzej Hajda return -ENOMEM; 76196976c3dSAjay Kumar 76296976c3dSAjay Kumar ctx->pclk = devm_clk_get(dev, "pclk_decon0"); 76396976c3dSAjay Kumar if (IS_ERR(ctx->pclk)) { 76496976c3dSAjay Kumar dev_err(dev, "failed to get bus clock pclk\n"); 76596976c3dSAjay Kumar ret = PTR_ERR(ctx->pclk); 76696976c3dSAjay Kumar goto err_iounmap; 76796976c3dSAjay Kumar } 76896976c3dSAjay Kumar 76996976c3dSAjay Kumar ctx->aclk = devm_clk_get(dev, "aclk_decon0"); 77096976c3dSAjay Kumar if (IS_ERR(ctx->aclk)) { 77196976c3dSAjay Kumar dev_err(dev, "failed to get bus clock aclk\n"); 77296976c3dSAjay Kumar ret = PTR_ERR(ctx->aclk); 77396976c3dSAjay Kumar goto err_iounmap; 77496976c3dSAjay Kumar } 77596976c3dSAjay Kumar 77696976c3dSAjay Kumar ctx->eclk = devm_clk_get(dev, "decon0_eclk"); 77796976c3dSAjay Kumar if (IS_ERR(ctx->eclk)) { 77896976c3dSAjay Kumar dev_err(dev, "failed to get eclock\n"); 77996976c3dSAjay Kumar ret = PTR_ERR(ctx->eclk); 78096976c3dSAjay Kumar goto err_iounmap; 78196976c3dSAjay Kumar } 78296976c3dSAjay Kumar 78396976c3dSAjay Kumar ctx->vclk = devm_clk_get(dev, "decon0_vclk"); 78496976c3dSAjay Kumar if (IS_ERR(ctx->vclk)) { 78596976c3dSAjay Kumar dev_err(dev, "failed to get vclock\n"); 78696976c3dSAjay Kumar ret = PTR_ERR(ctx->vclk); 78796976c3dSAjay Kumar goto err_iounmap; 78896976c3dSAjay Kumar } 78996976c3dSAjay Kumar 79096976c3dSAjay Kumar res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, 79196976c3dSAjay Kumar ctx->i80_if ? "lcd_sys" : "vsync"); 79296976c3dSAjay Kumar if (!res) { 79396976c3dSAjay Kumar dev_err(dev, "irq request failed.\n"); 79496976c3dSAjay Kumar ret = -ENXIO; 79596976c3dSAjay Kumar goto err_iounmap; 79696976c3dSAjay Kumar } 79796976c3dSAjay Kumar 79896976c3dSAjay Kumar ret = devm_request_irq(dev, res->start, decon_irq_handler, 79996976c3dSAjay Kumar 0, "drm_decon", ctx); 80096976c3dSAjay Kumar if (ret) { 80196976c3dSAjay Kumar dev_err(dev, "irq request failed.\n"); 80296976c3dSAjay Kumar goto err_iounmap; 80396976c3dSAjay Kumar } 80496976c3dSAjay Kumar 80596976c3dSAjay Kumar init_waitqueue_head(&ctx->wait_vsync_queue); 80696976c3dSAjay Kumar atomic_set(&ctx->wait_vsync_event, 0); 80796976c3dSAjay Kumar 80896976c3dSAjay Kumar platform_set_drvdata(pdev, ctx); 80996976c3dSAjay Kumar 810cf67cc9aSGustavo Padovan ctx->encoder = exynos_dpi_probe(dev); 811cf67cc9aSGustavo Padovan if (IS_ERR(ctx->encoder)) { 812cf67cc9aSGustavo Padovan ret = PTR_ERR(ctx->encoder); 81396976c3dSAjay Kumar goto err_iounmap; 81496976c3dSAjay Kumar } 81596976c3dSAjay Kumar 81696976c3dSAjay Kumar pm_runtime_enable(dev); 81796976c3dSAjay Kumar 81896976c3dSAjay Kumar ret = component_add(dev, &decon_component_ops); 81996976c3dSAjay Kumar if (ret) 82096976c3dSAjay Kumar goto err_disable_pm_runtime; 82196976c3dSAjay Kumar 82296976c3dSAjay Kumar return ret; 82396976c3dSAjay Kumar 82496976c3dSAjay Kumar err_disable_pm_runtime: 82596976c3dSAjay Kumar pm_runtime_disable(dev); 82696976c3dSAjay Kumar 82796976c3dSAjay Kumar err_iounmap: 82896976c3dSAjay Kumar iounmap(ctx->regs); 82996976c3dSAjay Kumar 83096976c3dSAjay Kumar return ret; 83196976c3dSAjay Kumar } 83296976c3dSAjay Kumar 83396976c3dSAjay Kumar static int decon_remove(struct platform_device *pdev) 83496976c3dSAjay Kumar { 83596976c3dSAjay Kumar struct decon_context *ctx = dev_get_drvdata(&pdev->dev); 83696976c3dSAjay Kumar 83796976c3dSAjay Kumar pm_runtime_disable(&pdev->dev); 83896976c3dSAjay Kumar 83996976c3dSAjay Kumar iounmap(ctx->regs); 84096976c3dSAjay Kumar 84196976c3dSAjay Kumar component_del(&pdev->dev, &decon_component_ops); 84296976c3dSAjay Kumar 84396976c3dSAjay Kumar return 0; 84496976c3dSAjay Kumar } 84596976c3dSAjay Kumar 84696976c3dSAjay Kumar struct platform_driver decon_driver = { 84796976c3dSAjay Kumar .probe = decon_probe, 84896976c3dSAjay Kumar .remove = decon_remove, 84996976c3dSAjay Kumar .driver = { 85096976c3dSAjay Kumar .name = "exynos-decon", 85196976c3dSAjay Kumar .of_match_table = decon_driver_dt_match, 85296976c3dSAjay Kumar }, 85396976c3dSAjay Kumar }; 854