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" 330488f50eSMarek Szyprowski #include "exynos_drm_fb.h" 3496976c3dSAjay Kumar #include "exynos_drm_fbdev.h" 3596976c3dSAjay Kumar #include "exynos_drm_iommu.h" 3696976c3dSAjay Kumar 3796976c3dSAjay Kumar /* 3896976c3dSAjay Kumar * DECON stands for Display and Enhancement controller. 3996976c3dSAjay Kumar */ 4096976c3dSAjay Kumar 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]; 50fd2d2fc2SMarek Szyprowski struct exynos_drm_plane_config configs[WINDOWS_NR]; 5196976c3dSAjay Kumar struct clk *pclk; 5296976c3dSAjay Kumar struct clk *aclk; 5396976c3dSAjay Kumar struct clk *eclk; 5496976c3dSAjay Kumar struct clk *vclk; 5596976c3dSAjay Kumar void __iomem *regs; 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; 642b8376c8SGustavo Padovan struct 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 73fbbb1e1aSMarek Szyprowski static const uint32_t decon_formats[] = { 74fbbb1e1aSMarek Szyprowski DRM_FORMAT_RGB565, 75fbbb1e1aSMarek Szyprowski DRM_FORMAT_XRGB8888, 76fbbb1e1aSMarek Szyprowski DRM_FORMAT_XBGR8888, 77fbbb1e1aSMarek Szyprowski DRM_FORMAT_RGBX8888, 78fbbb1e1aSMarek Szyprowski DRM_FORMAT_BGRX8888, 79fbbb1e1aSMarek Szyprowski DRM_FORMAT_ARGB8888, 80fbbb1e1aSMarek Szyprowski DRM_FORMAT_ABGR8888, 81fbbb1e1aSMarek Szyprowski DRM_FORMAT_RGBA8888, 82fbbb1e1aSMarek Szyprowski DRM_FORMAT_BGRA8888, 83fbbb1e1aSMarek Szyprowski }; 84fbbb1e1aSMarek Szyprowski 85fd2d2fc2SMarek Szyprowski static const enum drm_plane_type decon_win_types[WINDOWS_NR] = { 86fd2d2fc2SMarek Szyprowski DRM_PLANE_TYPE_PRIMARY, 87fd2d2fc2SMarek Szyprowski DRM_PLANE_TYPE_CURSOR, 88fd2d2fc2SMarek Szyprowski }; 89fd2d2fc2SMarek Szyprowski 9096976c3dSAjay Kumar static void decon_wait_for_vblank(struct exynos_drm_crtc *crtc) 9196976c3dSAjay Kumar { 9296976c3dSAjay Kumar struct decon_context *ctx = crtc->ctx; 9396976c3dSAjay Kumar 9496976c3dSAjay Kumar if (ctx->suspended) 9596976c3dSAjay Kumar return; 9696976c3dSAjay Kumar 9796976c3dSAjay Kumar atomic_set(&ctx->wait_vsync_event, 1); 9896976c3dSAjay Kumar 9996976c3dSAjay Kumar /* 10096976c3dSAjay Kumar * wait for DECON to signal VSYNC interrupt or return after 10196976c3dSAjay Kumar * timeout which is set to 50ms (refresh rate of 20). 10296976c3dSAjay Kumar */ 10396976c3dSAjay Kumar if (!wait_event_timeout(ctx->wait_vsync_queue, 10496976c3dSAjay Kumar !atomic_read(&ctx->wait_vsync_event), 10596976c3dSAjay Kumar HZ/20)) 10696976c3dSAjay Kumar DRM_DEBUG_KMS("vblank wait timed out.\n"); 10796976c3dSAjay Kumar } 10896976c3dSAjay Kumar 109fc2e013fSHyungwon Hwang static void decon_clear_channels(struct exynos_drm_crtc *crtc) 11096976c3dSAjay Kumar { 111fc2e013fSHyungwon Hwang struct decon_context *ctx = crtc->ctx; 1125b1d5bc6STobias Jakobi unsigned int win, ch_enabled = 0; 11396976c3dSAjay Kumar 11496976c3dSAjay Kumar DRM_DEBUG_KMS("%s\n", __FILE__); 11596976c3dSAjay Kumar 11696976c3dSAjay Kumar /* Check if any channel is enabled. */ 11796976c3dSAjay Kumar for (win = 0; win < WINDOWS_NR; win++) { 11896976c3dSAjay Kumar u32 val = readl(ctx->regs + WINCON(win)); 11996976c3dSAjay Kumar 12096976c3dSAjay Kumar if (val & WINCONx_ENWIN) { 12196976c3dSAjay Kumar val &= ~WINCONx_ENWIN; 12296976c3dSAjay Kumar writel(val, ctx->regs + WINCON(win)); 12396976c3dSAjay Kumar ch_enabled = 1; 12496976c3dSAjay Kumar } 12596976c3dSAjay Kumar } 12696976c3dSAjay Kumar 12796976c3dSAjay Kumar /* Wait for vsync, as disable channel takes effect at next vsync */ 128681c801eSGustavo Padovan if (ch_enabled) 12996976c3dSAjay Kumar decon_wait_for_vblank(ctx->crtc); 13096976c3dSAjay Kumar } 13196976c3dSAjay Kumar 13296976c3dSAjay Kumar static int decon_ctx_initialize(struct decon_context *ctx, 13396976c3dSAjay Kumar struct drm_device *drm_dev) 13496976c3dSAjay Kumar { 13596976c3dSAjay Kumar struct exynos_drm_private *priv = drm_dev->dev_private; 136fc2e013fSHyungwon Hwang int ret; 13796976c3dSAjay Kumar 13896976c3dSAjay Kumar ctx->drm_dev = drm_dev; 13996976c3dSAjay Kumar ctx->pipe = priv->pipe++; 14096976c3dSAjay Kumar 141eb7a3fc7SJoonyoung Shim decon_clear_channels(ctx->crtc); 142eb7a3fc7SJoonyoung Shim 143eb7a3fc7SJoonyoung Shim ret = drm_iommu_attach_device(drm_dev, ctx->dev); 144fc2e013fSHyungwon Hwang if (ret) 145fc2e013fSHyungwon Hwang priv->pipe--; 14696976c3dSAjay Kumar 14796976c3dSAjay Kumar return ret; 14896976c3dSAjay Kumar } 14996976c3dSAjay Kumar 15096976c3dSAjay Kumar static void decon_ctx_remove(struct decon_context *ctx) 15196976c3dSAjay Kumar { 15296976c3dSAjay Kumar /* detach this sub driver from iommu mapping if supported. */ 15396976c3dSAjay Kumar drm_iommu_detach_device(ctx->drm_dev, ctx->dev); 15496976c3dSAjay Kumar } 15596976c3dSAjay Kumar 15696976c3dSAjay Kumar static u32 decon_calc_clkdiv(struct decon_context *ctx, 15796976c3dSAjay Kumar const struct drm_display_mode *mode) 15896976c3dSAjay Kumar { 15996976c3dSAjay Kumar unsigned long ideal_clk = mode->htotal * mode->vtotal * mode->vrefresh; 16096976c3dSAjay Kumar u32 clkdiv; 16196976c3dSAjay Kumar 16296976c3dSAjay Kumar /* Find the clock divider value that gets us closest to ideal_clk */ 16396976c3dSAjay Kumar clkdiv = DIV_ROUND_UP(clk_get_rate(ctx->vclk), ideal_clk); 16496976c3dSAjay Kumar 16596976c3dSAjay Kumar return (clkdiv < 0x100) ? clkdiv : 0xff; 16696976c3dSAjay Kumar } 16796976c3dSAjay Kumar 16896976c3dSAjay Kumar static void decon_commit(struct exynos_drm_crtc *crtc) 16996976c3dSAjay Kumar { 17096976c3dSAjay Kumar struct decon_context *ctx = crtc->ctx; 171020e79deSJoonyoung Shim struct drm_display_mode *mode = &crtc->base.state->adjusted_mode; 17296976c3dSAjay Kumar u32 val, clkdiv; 17396976c3dSAjay Kumar 17496976c3dSAjay Kumar if (ctx->suspended) 17596976c3dSAjay Kumar return; 17696976c3dSAjay Kumar 17796976c3dSAjay Kumar /* nothing to do if we haven't set the mode yet */ 17896976c3dSAjay Kumar if (mode->htotal == 0 || mode->vtotal == 0) 17996976c3dSAjay Kumar return; 18096976c3dSAjay Kumar 18196976c3dSAjay Kumar if (!ctx->i80_if) { 18296976c3dSAjay Kumar int vsync_len, vbpd, vfpd, hsync_len, hbpd, hfpd; 18396976c3dSAjay Kumar /* setup vertical timing values. */ 18496976c3dSAjay Kumar vsync_len = mode->crtc_vsync_end - mode->crtc_vsync_start; 18596976c3dSAjay Kumar vbpd = mode->crtc_vtotal - mode->crtc_vsync_end; 18696976c3dSAjay Kumar vfpd = mode->crtc_vsync_start - mode->crtc_vdisplay; 18796976c3dSAjay Kumar 18896976c3dSAjay Kumar val = VIDTCON0_VBPD(vbpd - 1) | VIDTCON0_VFPD(vfpd - 1); 18996976c3dSAjay Kumar writel(val, ctx->regs + VIDTCON0); 19096976c3dSAjay Kumar 19196976c3dSAjay Kumar val = VIDTCON1_VSPW(vsync_len - 1); 19296976c3dSAjay Kumar writel(val, ctx->regs + VIDTCON1); 19396976c3dSAjay Kumar 19496976c3dSAjay Kumar /* setup horizontal timing values. */ 19596976c3dSAjay Kumar hsync_len = mode->crtc_hsync_end - mode->crtc_hsync_start; 19696976c3dSAjay Kumar hbpd = mode->crtc_htotal - mode->crtc_hsync_end; 19796976c3dSAjay Kumar hfpd = mode->crtc_hsync_start - mode->crtc_hdisplay; 19896976c3dSAjay Kumar 19996976c3dSAjay Kumar /* setup horizontal timing values. */ 20096976c3dSAjay Kumar val = VIDTCON2_HBPD(hbpd - 1) | VIDTCON2_HFPD(hfpd - 1); 20196976c3dSAjay Kumar writel(val, ctx->regs + VIDTCON2); 20296976c3dSAjay Kumar 20396976c3dSAjay Kumar val = VIDTCON3_HSPW(hsync_len - 1); 20496976c3dSAjay Kumar writel(val, ctx->regs + VIDTCON3); 20596976c3dSAjay Kumar } 20696976c3dSAjay Kumar 20796976c3dSAjay Kumar /* setup horizontal and vertical display size. */ 20896976c3dSAjay Kumar val = VIDTCON4_LINEVAL(mode->vdisplay - 1) | 20996976c3dSAjay Kumar VIDTCON4_HOZVAL(mode->hdisplay - 1); 21096976c3dSAjay Kumar writel(val, ctx->regs + VIDTCON4); 21196976c3dSAjay Kumar 21296976c3dSAjay Kumar writel(mode->vdisplay - 1, ctx->regs + LINECNT_OP_THRESHOLD); 21396976c3dSAjay Kumar 21496976c3dSAjay Kumar /* 21596976c3dSAjay Kumar * fields of register with prefix '_F' would be updated 21696976c3dSAjay Kumar * at vsync(same as dma start) 21796976c3dSAjay Kumar */ 21896976c3dSAjay Kumar val = VIDCON0_ENVID | VIDCON0_ENVID_F; 21996976c3dSAjay Kumar writel(val, ctx->regs + VIDCON0); 22096976c3dSAjay Kumar 22196976c3dSAjay Kumar clkdiv = decon_calc_clkdiv(ctx, mode); 22296976c3dSAjay Kumar if (clkdiv > 1) { 22396976c3dSAjay Kumar val = VCLKCON1_CLKVAL_NUM_VCLK(clkdiv - 1); 22496976c3dSAjay Kumar writel(val, ctx->regs + VCLKCON1); 22596976c3dSAjay Kumar writel(val, ctx->regs + VCLKCON2); 22696976c3dSAjay Kumar } 22796976c3dSAjay Kumar 22896976c3dSAjay Kumar val = readl(ctx->regs + DECON_UPDATE); 22996976c3dSAjay Kumar val |= DECON_UPDATE_STANDALONE_F; 23096976c3dSAjay Kumar writel(val, ctx->regs + DECON_UPDATE); 23196976c3dSAjay Kumar } 23296976c3dSAjay Kumar 23396976c3dSAjay Kumar static int decon_enable_vblank(struct exynos_drm_crtc *crtc) 23496976c3dSAjay Kumar { 23596976c3dSAjay Kumar struct decon_context *ctx = crtc->ctx; 23696976c3dSAjay Kumar u32 val; 23796976c3dSAjay Kumar 23896976c3dSAjay Kumar if (ctx->suspended) 23996976c3dSAjay Kumar return -EPERM; 24096976c3dSAjay Kumar 24196976c3dSAjay Kumar if (!test_and_set_bit(0, &ctx->irq_flags)) { 24296976c3dSAjay Kumar val = readl(ctx->regs + VIDINTCON0); 24396976c3dSAjay Kumar 24496976c3dSAjay Kumar val |= VIDINTCON0_INT_ENABLE; 24596976c3dSAjay Kumar 24696976c3dSAjay Kumar if (!ctx->i80_if) { 24796976c3dSAjay Kumar val |= VIDINTCON0_INT_FRAME; 24896976c3dSAjay Kumar val &= ~VIDINTCON0_FRAMESEL0_MASK; 24996976c3dSAjay Kumar val |= VIDINTCON0_FRAMESEL0_VSYNC; 25096976c3dSAjay Kumar } 25196976c3dSAjay Kumar 25296976c3dSAjay Kumar writel(val, ctx->regs + VIDINTCON0); 25396976c3dSAjay Kumar } 25496976c3dSAjay Kumar 25596976c3dSAjay Kumar return 0; 25696976c3dSAjay Kumar } 25796976c3dSAjay Kumar 25896976c3dSAjay Kumar static void decon_disable_vblank(struct exynos_drm_crtc *crtc) 25996976c3dSAjay Kumar { 26096976c3dSAjay Kumar struct decon_context *ctx = crtc->ctx; 26196976c3dSAjay Kumar u32 val; 26296976c3dSAjay Kumar 26396976c3dSAjay Kumar if (ctx->suspended) 26496976c3dSAjay Kumar return; 26596976c3dSAjay Kumar 26696976c3dSAjay Kumar if (test_and_clear_bit(0, &ctx->irq_flags)) { 26796976c3dSAjay Kumar val = readl(ctx->regs + VIDINTCON0); 26896976c3dSAjay Kumar 26996976c3dSAjay Kumar val &= ~VIDINTCON0_INT_ENABLE; 27096976c3dSAjay Kumar if (!ctx->i80_if) 27196976c3dSAjay Kumar val &= ~VIDINTCON0_INT_FRAME; 27296976c3dSAjay Kumar 27396976c3dSAjay Kumar writel(val, ctx->regs + VIDINTCON0); 27496976c3dSAjay Kumar } 27596976c3dSAjay Kumar } 27696976c3dSAjay Kumar 2772eeb2e5eSGustavo Padovan static void decon_win_set_pixfmt(struct decon_context *ctx, unsigned int win, 2782eeb2e5eSGustavo Padovan struct drm_framebuffer *fb) 27996976c3dSAjay Kumar { 28096976c3dSAjay Kumar unsigned long val; 2817ee14cdcSGustavo Padovan int padding; 28296976c3dSAjay Kumar 28396976c3dSAjay Kumar val = readl(ctx->regs + WINCON(win)); 28496976c3dSAjay Kumar val &= ~WINCONx_BPPMODE_MASK; 28596976c3dSAjay Kumar 2862eeb2e5eSGustavo Padovan switch (fb->pixel_format) { 28796976c3dSAjay Kumar case DRM_FORMAT_RGB565: 28896976c3dSAjay Kumar val |= WINCONx_BPPMODE_16BPP_565; 28996976c3dSAjay Kumar val |= WINCONx_BURSTLEN_16WORD; 29096976c3dSAjay Kumar break; 29196976c3dSAjay Kumar case DRM_FORMAT_XRGB8888: 29296976c3dSAjay Kumar val |= WINCONx_BPPMODE_24BPP_xRGB; 29396976c3dSAjay Kumar val |= WINCONx_BURSTLEN_16WORD; 29496976c3dSAjay Kumar break; 29596976c3dSAjay Kumar case DRM_FORMAT_XBGR8888: 29696976c3dSAjay Kumar val |= WINCONx_BPPMODE_24BPP_xBGR; 29796976c3dSAjay Kumar val |= WINCONx_BURSTLEN_16WORD; 29896976c3dSAjay Kumar break; 29996976c3dSAjay Kumar case DRM_FORMAT_RGBX8888: 30096976c3dSAjay Kumar val |= WINCONx_BPPMODE_24BPP_RGBx; 30196976c3dSAjay Kumar val |= WINCONx_BURSTLEN_16WORD; 30296976c3dSAjay Kumar break; 30396976c3dSAjay Kumar case DRM_FORMAT_BGRX8888: 30496976c3dSAjay Kumar val |= WINCONx_BPPMODE_24BPP_BGRx; 30596976c3dSAjay Kumar val |= WINCONx_BURSTLEN_16WORD; 30696976c3dSAjay Kumar break; 30796976c3dSAjay Kumar case DRM_FORMAT_ARGB8888: 30896976c3dSAjay Kumar val |= WINCONx_BPPMODE_32BPP_ARGB | WINCONx_BLD_PIX | 30996976c3dSAjay Kumar WINCONx_ALPHA_SEL; 31096976c3dSAjay Kumar val |= WINCONx_BURSTLEN_16WORD; 31196976c3dSAjay Kumar break; 31296976c3dSAjay Kumar case DRM_FORMAT_ABGR8888: 31396976c3dSAjay Kumar val |= WINCONx_BPPMODE_32BPP_ABGR | WINCONx_BLD_PIX | 31496976c3dSAjay Kumar WINCONx_ALPHA_SEL; 31596976c3dSAjay Kumar val |= WINCONx_BURSTLEN_16WORD; 31696976c3dSAjay Kumar break; 31796976c3dSAjay Kumar case DRM_FORMAT_RGBA8888: 31896976c3dSAjay Kumar val |= WINCONx_BPPMODE_32BPP_RGBA | WINCONx_BLD_PIX | 31996976c3dSAjay Kumar WINCONx_ALPHA_SEL; 32096976c3dSAjay Kumar val |= WINCONx_BURSTLEN_16WORD; 32196976c3dSAjay Kumar break; 32296976c3dSAjay Kumar case DRM_FORMAT_BGRA8888: 32396976c3dSAjay Kumar val |= WINCONx_BPPMODE_32BPP_BGRA | WINCONx_BLD_PIX | 32496976c3dSAjay Kumar WINCONx_ALPHA_SEL; 32596976c3dSAjay Kumar val |= WINCONx_BURSTLEN_16WORD; 32696976c3dSAjay Kumar break; 32796976c3dSAjay Kumar default: 32896976c3dSAjay Kumar DRM_DEBUG_KMS("invalid pixel size so using unpacked 24bpp.\n"); 32996976c3dSAjay Kumar 33096976c3dSAjay Kumar val |= WINCONx_BPPMODE_24BPP_xRGB; 33196976c3dSAjay Kumar val |= WINCONx_BURSTLEN_16WORD; 33296976c3dSAjay Kumar break; 33396976c3dSAjay Kumar } 33496976c3dSAjay Kumar 3352eeb2e5eSGustavo Padovan DRM_DEBUG_KMS("bpp = %d\n", fb->bits_per_pixel); 33696976c3dSAjay Kumar 33796976c3dSAjay Kumar /* 33896976c3dSAjay Kumar * In case of exynos, setting dma-burst to 16Word causes permanent 33996976c3dSAjay Kumar * tearing for very small buffers, e.g. cursor buffer. Burst Mode 34096976c3dSAjay Kumar * switching which is based on plane size is not recommended as 34196976c3dSAjay Kumar * plane size varies a lot towards the end of the screen and rapid 34296976c3dSAjay Kumar * movement causes unstable DMA which results into iommu crash/tear. 34396976c3dSAjay Kumar */ 34496976c3dSAjay Kumar 3452eeb2e5eSGustavo Padovan padding = (fb->pitches[0] / (fb->bits_per_pixel >> 3)) - fb->width; 3462eeb2e5eSGustavo Padovan if (fb->width + padding < MIN_FB_WIDTH_FOR_16WORD_BURST) { 34796976c3dSAjay Kumar val &= ~WINCONx_BURSTLEN_MASK; 34896976c3dSAjay Kumar val |= WINCONx_BURSTLEN_8WORD; 34996976c3dSAjay Kumar } 35096976c3dSAjay Kumar 35196976c3dSAjay Kumar writel(val, ctx->regs + WINCON(win)); 35296976c3dSAjay Kumar } 35396976c3dSAjay Kumar 35496976c3dSAjay Kumar static void decon_win_set_colkey(struct decon_context *ctx, unsigned int win) 35596976c3dSAjay Kumar { 35696976c3dSAjay Kumar unsigned int keycon0 = 0, keycon1 = 0; 35796976c3dSAjay Kumar 35896976c3dSAjay Kumar keycon0 = ~(WxKEYCON0_KEYBL_EN | WxKEYCON0_KEYEN_F | 35996976c3dSAjay Kumar WxKEYCON0_DIRCON) | WxKEYCON0_COMPKEY(0); 36096976c3dSAjay Kumar 36196976c3dSAjay Kumar keycon1 = WxKEYCON1_COLVAL(0xffffffff); 36296976c3dSAjay Kumar 36396976c3dSAjay Kumar writel(keycon0, ctx->regs + WKEYCON0_BASE(win)); 36496976c3dSAjay Kumar writel(keycon1, ctx->regs + WKEYCON1_BASE(win)); 36596976c3dSAjay Kumar } 36696976c3dSAjay Kumar 36796976c3dSAjay Kumar /** 36896976c3dSAjay Kumar * shadow_protect_win() - disable updating values from shadow registers at vsync 36996976c3dSAjay Kumar * 37096976c3dSAjay Kumar * @win: window to protect registers for 37196976c3dSAjay Kumar * @protect: 1 to protect (disable updates) 37296976c3dSAjay Kumar */ 37396976c3dSAjay Kumar static void decon_shadow_protect_win(struct decon_context *ctx, 3746e2a3b66SGustavo Padovan unsigned int win, bool protect) 37596976c3dSAjay Kumar { 37696976c3dSAjay Kumar u32 bits, val; 37796976c3dSAjay Kumar 37896976c3dSAjay Kumar bits = SHADOWCON_WINx_PROTECT(win); 37996976c3dSAjay Kumar 38096976c3dSAjay Kumar val = readl(ctx->regs + SHADOWCON); 38196976c3dSAjay Kumar if (protect) 38296976c3dSAjay Kumar val |= bits; 38396976c3dSAjay Kumar else 38496976c3dSAjay Kumar val &= ~bits; 38596976c3dSAjay Kumar writel(val, ctx->regs + SHADOWCON); 38696976c3dSAjay Kumar } 38796976c3dSAjay Kumar 388cc5a7b35SHyungwon Hwang static void decon_atomic_begin(struct exynos_drm_crtc *crtc, 389cc5a7b35SHyungwon Hwang struct exynos_drm_plane *plane) 390cc5a7b35SHyungwon Hwang { 391cc5a7b35SHyungwon Hwang struct decon_context *ctx = crtc->ctx; 392cc5a7b35SHyungwon Hwang 393cc5a7b35SHyungwon Hwang if (ctx->suspended) 394cc5a7b35SHyungwon Hwang return; 395cc5a7b35SHyungwon Hwang 396*40bdfb0aSMarek Szyprowski decon_shadow_protect_win(ctx, plane->index, true); 397cc5a7b35SHyungwon Hwang } 398cc5a7b35SHyungwon Hwang 3991e1d1393SGustavo Padovan static void decon_update_plane(struct exynos_drm_crtc *crtc, 4001e1d1393SGustavo Padovan struct exynos_drm_plane *plane) 40196976c3dSAjay Kumar { 4020114f404SMarek Szyprowski struct exynos_drm_plane_state *state = 4030114f404SMarek Szyprowski to_exynos_plane_state(plane->base.state); 40496976c3dSAjay Kumar struct decon_context *ctx = crtc->ctx; 4050114f404SMarek Szyprowski struct drm_framebuffer *fb = state->base.fb; 4066e2a3b66SGustavo Padovan int padding; 40796976c3dSAjay Kumar unsigned long val, alpha; 40896976c3dSAjay Kumar unsigned int last_x; 40996976c3dSAjay Kumar unsigned int last_y; 410*40bdfb0aSMarek Szyprowski unsigned int win = plane->index; 4110488f50eSMarek Szyprowski unsigned int bpp = fb->bits_per_pixel >> 3; 4120488f50eSMarek Szyprowski unsigned int pitch = fb->pitches[0]; 41396976c3dSAjay Kumar 41496976c3dSAjay Kumar if (ctx->suspended) 41596976c3dSAjay Kumar return; 41696976c3dSAjay Kumar 41796976c3dSAjay Kumar /* 41896976c3dSAjay Kumar * SHADOWCON/PRTCON register is used for enabling timing. 41996976c3dSAjay Kumar * 42096976c3dSAjay Kumar * for example, once only width value of a register is set, 42196976c3dSAjay Kumar * if the dma is started then decon hardware could malfunction so 42296976c3dSAjay Kumar * with protect window setting, the register fields with prefix '_F' 42396976c3dSAjay Kumar * wouldn't be updated at vsync also but updated once unprotect window 42496976c3dSAjay Kumar * is set. 42596976c3dSAjay Kumar */ 42696976c3dSAjay Kumar 42796976c3dSAjay Kumar /* buffer start address */ 4280488f50eSMarek Szyprowski val = (unsigned long)exynos_drm_fb_dma_addr(fb, 0); 42996976c3dSAjay Kumar writel(val, ctx->regs + VIDW_BUF_START(win)); 43096976c3dSAjay Kumar 4310488f50eSMarek Szyprowski padding = (pitch / bpp) - fb->width; 4327ee14cdcSGustavo Padovan 43396976c3dSAjay Kumar /* buffer size */ 4340488f50eSMarek Szyprowski writel(fb->width + padding, ctx->regs + VIDW_WHOLE_X(win)); 4350488f50eSMarek Szyprowski writel(fb->height, ctx->regs + VIDW_WHOLE_Y(win)); 43696976c3dSAjay Kumar 43796976c3dSAjay Kumar /* offset from the start of the buffer to read */ 4380114f404SMarek Szyprowski writel(state->src.x, ctx->regs + VIDW_OFFSET_X(win)); 4390114f404SMarek Szyprowski writel(state->src.y, ctx->regs + VIDW_OFFSET_Y(win)); 44096976c3dSAjay Kumar 44196976c3dSAjay Kumar DRM_DEBUG_KMS("start addr = 0x%lx\n", 4427ee14cdcSGustavo Padovan (unsigned long)val); 44396976c3dSAjay Kumar DRM_DEBUG_KMS("ovl_width = %d, ovl_height = %d\n", 4440114f404SMarek Szyprowski state->crtc.w, state->crtc.h); 44596976c3dSAjay Kumar 4460114f404SMarek Szyprowski val = VIDOSDxA_TOPLEFT_X(state->crtc.x) | 4470114f404SMarek Szyprowski VIDOSDxA_TOPLEFT_Y(state->crtc.y); 44896976c3dSAjay Kumar writel(val, ctx->regs + VIDOSD_A(win)); 44996976c3dSAjay Kumar 4500114f404SMarek Szyprowski last_x = state->crtc.x + state->crtc.w; 45196976c3dSAjay Kumar if (last_x) 45296976c3dSAjay Kumar last_x--; 4530114f404SMarek Szyprowski last_y = state->crtc.y + state->crtc.h; 45496976c3dSAjay Kumar if (last_y) 45596976c3dSAjay Kumar last_y--; 45696976c3dSAjay Kumar 45796976c3dSAjay Kumar val = VIDOSDxB_BOTRIGHT_X(last_x) | VIDOSDxB_BOTRIGHT_Y(last_y); 45896976c3dSAjay Kumar 45996976c3dSAjay Kumar writel(val, ctx->regs + VIDOSD_B(win)); 46096976c3dSAjay Kumar 46196976c3dSAjay Kumar DRM_DEBUG_KMS("osd pos: tx = %d, ty = %d, bx = %d, by = %d\n", 4620114f404SMarek Szyprowski state->crtc.x, state->crtc.y, last_x, last_y); 46396976c3dSAjay Kumar 46496976c3dSAjay Kumar /* OSD alpha */ 46596976c3dSAjay Kumar alpha = VIDOSDxC_ALPHA0_R_F(0x0) | 46696976c3dSAjay Kumar VIDOSDxC_ALPHA0_G_F(0x0) | 46796976c3dSAjay Kumar VIDOSDxC_ALPHA0_B_F(0x0); 46896976c3dSAjay Kumar 46996976c3dSAjay Kumar writel(alpha, ctx->regs + VIDOSD_C(win)); 47096976c3dSAjay Kumar 47196976c3dSAjay Kumar alpha = VIDOSDxD_ALPHA1_R_F(0xff) | 47296976c3dSAjay Kumar VIDOSDxD_ALPHA1_G_F(0xff) | 47396976c3dSAjay Kumar VIDOSDxD_ALPHA1_B_F(0xff); 47496976c3dSAjay Kumar 47596976c3dSAjay Kumar writel(alpha, ctx->regs + VIDOSD_D(win)); 47696976c3dSAjay Kumar 4770488f50eSMarek Szyprowski decon_win_set_pixfmt(ctx, win, fb); 47896976c3dSAjay Kumar 47996976c3dSAjay Kumar /* hardware window 0 doesn't support color key. */ 48096976c3dSAjay Kumar if (win != 0) 48196976c3dSAjay Kumar decon_win_set_colkey(ctx, win); 48296976c3dSAjay Kumar 48396976c3dSAjay Kumar /* wincon */ 48496976c3dSAjay Kumar val = readl(ctx->regs + WINCON(win)); 48596976c3dSAjay Kumar val |= WINCONx_TRIPLE_BUF_MODE; 48696976c3dSAjay Kumar val |= WINCONx_ENWIN; 48796976c3dSAjay Kumar writel(val, ctx->regs + WINCON(win)); 48896976c3dSAjay Kumar 48996976c3dSAjay Kumar /* Enable DMA channel and unprotect windows */ 49096976c3dSAjay Kumar decon_shadow_protect_win(ctx, win, false); 49196976c3dSAjay Kumar 49296976c3dSAjay Kumar val = readl(ctx->regs + DECON_UPDATE); 49396976c3dSAjay Kumar val |= DECON_UPDATE_STANDALONE_F; 49496976c3dSAjay Kumar writel(val, ctx->regs + DECON_UPDATE); 49596976c3dSAjay Kumar } 49696976c3dSAjay Kumar 4971e1d1393SGustavo Padovan static void decon_disable_plane(struct exynos_drm_crtc *crtc, 4981e1d1393SGustavo Padovan struct exynos_drm_plane *plane) 49996976c3dSAjay Kumar { 50096976c3dSAjay Kumar struct decon_context *ctx = crtc->ctx; 501*40bdfb0aSMarek Szyprowski unsigned int win = plane->index; 50296976c3dSAjay Kumar u32 val; 50396976c3dSAjay Kumar 504c329f667SJoonyoung Shim if (ctx->suspended) 50596976c3dSAjay Kumar return; 50696976c3dSAjay Kumar 50796976c3dSAjay Kumar /* protect windows */ 50896976c3dSAjay Kumar decon_shadow_protect_win(ctx, win, true); 50996976c3dSAjay Kumar 51096976c3dSAjay Kumar /* wincon */ 51196976c3dSAjay Kumar val = readl(ctx->regs + WINCON(win)); 51296976c3dSAjay Kumar val &= ~WINCONx_ENWIN; 51396976c3dSAjay Kumar writel(val, ctx->regs + WINCON(win)); 51496976c3dSAjay Kumar 51596976c3dSAjay Kumar val = readl(ctx->regs + DECON_UPDATE); 51696976c3dSAjay Kumar val |= DECON_UPDATE_STANDALONE_F; 51796976c3dSAjay Kumar writel(val, ctx->regs + DECON_UPDATE); 51896976c3dSAjay Kumar } 51996976c3dSAjay Kumar 520cc5a7b35SHyungwon Hwang static void decon_atomic_flush(struct exynos_drm_crtc *crtc, 521cc5a7b35SHyungwon Hwang struct exynos_drm_plane *plane) 522cc5a7b35SHyungwon Hwang { 523cc5a7b35SHyungwon Hwang struct decon_context *ctx = crtc->ctx; 524cc5a7b35SHyungwon Hwang 525cc5a7b35SHyungwon Hwang if (ctx->suspended) 526cc5a7b35SHyungwon Hwang return; 527cc5a7b35SHyungwon Hwang 528*40bdfb0aSMarek Szyprowski decon_shadow_protect_win(ctx, plane->index, false); 529cc5a7b35SHyungwon Hwang } 530cc5a7b35SHyungwon Hwang 53196976c3dSAjay Kumar static void decon_init(struct decon_context *ctx) 53296976c3dSAjay Kumar { 53396976c3dSAjay Kumar u32 val; 53496976c3dSAjay Kumar 53596976c3dSAjay Kumar writel(VIDCON0_SWRESET, ctx->regs + VIDCON0); 53696976c3dSAjay Kumar 53796976c3dSAjay Kumar val = VIDOUTCON0_DISP_IF_0_ON; 53896976c3dSAjay Kumar if (!ctx->i80_if) 53996976c3dSAjay Kumar val |= VIDOUTCON0_RGBIF; 54096976c3dSAjay Kumar writel(val, ctx->regs + VIDOUTCON0); 54196976c3dSAjay Kumar 54296976c3dSAjay Kumar writel(VCLKCON0_CLKVALUP | VCLKCON0_VCLKFREE, ctx->regs + VCLKCON0); 54396976c3dSAjay Kumar 54496976c3dSAjay Kumar if (!ctx->i80_if) 54596976c3dSAjay Kumar writel(VIDCON1_VCLK_HOLD, ctx->regs + VIDCON1(0)); 54696976c3dSAjay Kumar } 54796976c3dSAjay Kumar 5483cecda03SGustavo Padovan static void decon_enable(struct exynos_drm_crtc *crtc) 54996976c3dSAjay Kumar { 5503cecda03SGustavo Padovan struct decon_context *ctx = crtc->ctx; 55196976c3dSAjay Kumar 55296976c3dSAjay Kumar if (!ctx->suspended) 5533cecda03SGustavo Padovan return; 55496976c3dSAjay Kumar 55596976c3dSAjay Kumar pm_runtime_get_sync(ctx->dev); 55696976c3dSAjay Kumar 55796976c3dSAjay Kumar decon_init(ctx); 55896976c3dSAjay Kumar 55996976c3dSAjay Kumar /* if vblank was enabled status, enable it again. */ 5603cecda03SGustavo Padovan if (test_and_clear_bit(0, &ctx->irq_flags)) 5613cecda03SGustavo Padovan decon_enable_vblank(ctx->crtc); 56296976c3dSAjay Kumar 563c329f667SJoonyoung Shim decon_commit(ctx->crtc); 564681c801eSGustavo Padovan 565681c801eSGustavo Padovan ctx->suspended = false; 56696976c3dSAjay Kumar } 56796976c3dSAjay Kumar 5683cecda03SGustavo Padovan static void decon_disable(struct exynos_drm_crtc *crtc) 56996976c3dSAjay Kumar { 5703cecda03SGustavo Padovan struct decon_context *ctx = crtc->ctx; 571c329f667SJoonyoung Shim int i; 5723cecda03SGustavo Padovan 57396976c3dSAjay Kumar if (ctx->suspended) 5743cecda03SGustavo Padovan return; 57596976c3dSAjay Kumar 57696976c3dSAjay Kumar /* 57796976c3dSAjay Kumar * We need to make sure that all windows are disabled before we 57896976c3dSAjay Kumar * suspend that connector. Otherwise we might try to scan from 57996976c3dSAjay Kumar * a destroyed buffer later. 58096976c3dSAjay Kumar */ 581c329f667SJoonyoung Shim for (i = 0; i < WINDOWS_NR; i++) 5821e1d1393SGustavo Padovan decon_disable_plane(crtc, &ctx->planes[i]); 58396976c3dSAjay Kumar 58496976c3dSAjay Kumar pm_runtime_put_sync(ctx->dev); 58596976c3dSAjay Kumar 58696976c3dSAjay Kumar ctx->suspended = true; 58796976c3dSAjay Kumar } 58896976c3dSAjay Kumar 589f3aaf762SKrzysztof Kozlowski static const struct exynos_drm_crtc_ops decon_crtc_ops = { 5903cecda03SGustavo Padovan .enable = decon_enable, 5913cecda03SGustavo Padovan .disable = decon_disable, 59296976c3dSAjay Kumar .commit = decon_commit, 59396976c3dSAjay Kumar .enable_vblank = decon_enable_vblank, 59496976c3dSAjay Kumar .disable_vblank = decon_disable_vblank, 59596976c3dSAjay Kumar .wait_for_vblank = decon_wait_for_vblank, 596cc5a7b35SHyungwon Hwang .atomic_begin = decon_atomic_begin, 5979cc7610aSGustavo Padovan .update_plane = decon_update_plane, 5989cc7610aSGustavo Padovan .disable_plane = decon_disable_plane, 599cc5a7b35SHyungwon Hwang .atomic_flush = decon_atomic_flush, 60096976c3dSAjay Kumar }; 60196976c3dSAjay Kumar 60296976c3dSAjay Kumar 60396976c3dSAjay Kumar static irqreturn_t decon_irq_handler(int irq, void *dev_id) 60496976c3dSAjay Kumar { 60596976c3dSAjay Kumar struct decon_context *ctx = (struct decon_context *)dev_id; 60696976c3dSAjay Kumar u32 val, clear_bit; 607822f6dfdSGustavo Padovan int win; 60896976c3dSAjay Kumar 60996976c3dSAjay Kumar val = readl(ctx->regs + VIDINTCON1); 61096976c3dSAjay Kumar 61196976c3dSAjay Kumar clear_bit = ctx->i80_if ? VIDINTCON1_INT_I80 : VIDINTCON1_INT_FRAME; 61296976c3dSAjay Kumar if (val & clear_bit) 61396976c3dSAjay Kumar writel(clear_bit, ctx->regs + VIDINTCON1); 61496976c3dSAjay Kumar 61596976c3dSAjay Kumar /* check the crtc is detached already from encoder */ 61696976c3dSAjay Kumar if (ctx->pipe < 0 || !ctx->drm_dev) 61796976c3dSAjay Kumar goto out; 61896976c3dSAjay Kumar 61996976c3dSAjay Kumar if (!ctx->i80_if) { 620eafd540aSGustavo Padovan drm_crtc_handle_vblank(&ctx->crtc->base); 621822f6dfdSGustavo Padovan for (win = 0 ; win < WINDOWS_NR ; win++) { 622822f6dfdSGustavo Padovan struct exynos_drm_plane *plane = &ctx->planes[win]; 623822f6dfdSGustavo Padovan 624822f6dfdSGustavo Padovan if (!plane->pending_fb) 625822f6dfdSGustavo Padovan continue; 626822f6dfdSGustavo Padovan 627822f6dfdSGustavo Padovan exynos_drm_crtc_finish_update(ctx->crtc, plane); 628822f6dfdSGustavo Padovan } 62996976c3dSAjay Kumar 63096976c3dSAjay Kumar /* set wait vsync event to zero and wake up queue. */ 63196976c3dSAjay Kumar if (atomic_read(&ctx->wait_vsync_event)) { 63296976c3dSAjay Kumar atomic_set(&ctx->wait_vsync_event, 0); 63396976c3dSAjay Kumar wake_up(&ctx->wait_vsync_queue); 63496976c3dSAjay Kumar } 63596976c3dSAjay Kumar } 63696976c3dSAjay Kumar out: 63796976c3dSAjay Kumar return IRQ_HANDLED; 63896976c3dSAjay Kumar } 63996976c3dSAjay Kumar 64096976c3dSAjay Kumar static int decon_bind(struct device *dev, struct device *master, void *data) 64196976c3dSAjay Kumar { 64296976c3dSAjay Kumar struct decon_context *ctx = dev_get_drvdata(dev); 64396976c3dSAjay Kumar struct drm_device *drm_dev = data; 6447ee14cdcSGustavo Padovan struct exynos_drm_plane *exynos_plane; 645fd2d2fc2SMarek Szyprowski unsigned int i; 6466e2a3b66SGustavo Padovan int ret; 64796976c3dSAjay Kumar 64896976c3dSAjay Kumar ret = decon_ctx_initialize(ctx, drm_dev); 64996976c3dSAjay Kumar if (ret) { 65096976c3dSAjay Kumar DRM_ERROR("decon_ctx_initialize failed.\n"); 65196976c3dSAjay Kumar return ret; 65296976c3dSAjay Kumar } 65396976c3dSAjay Kumar 654fd2d2fc2SMarek Szyprowski for (i = 0; i < WINDOWS_NR; i++) { 655fd2d2fc2SMarek Szyprowski ctx->configs[i].pixel_formats = decon_formats; 656fd2d2fc2SMarek Szyprowski ctx->configs[i].num_pixel_formats = ARRAY_SIZE(decon_formats); 657fd2d2fc2SMarek Szyprowski ctx->configs[i].zpos = i; 658fd2d2fc2SMarek Szyprowski ctx->configs[i].type = decon_win_types[i]; 659fd2d2fc2SMarek Szyprowski 660*40bdfb0aSMarek Szyprowski ret = exynos_plane_init(drm_dev, &ctx->planes[i], i, 661fd2d2fc2SMarek Szyprowski 1 << ctx->pipe, &ctx->configs[i]); 6627ee14cdcSGustavo Padovan if (ret) 6637ee14cdcSGustavo Padovan return ret; 6647ee14cdcSGustavo Padovan } 6657ee14cdcSGustavo Padovan 6665d3d0995SGustavo Padovan exynos_plane = &ctx->planes[DEFAULT_WIN]; 6677ee14cdcSGustavo Padovan ctx->crtc = exynos_drm_crtc_create(drm_dev, &exynos_plane->base, 6687ee14cdcSGustavo Padovan ctx->pipe, EXYNOS_DISPLAY_TYPE_LCD, 66996976c3dSAjay Kumar &decon_crtc_ops, ctx); 67096976c3dSAjay Kumar if (IS_ERR(ctx->crtc)) { 67196976c3dSAjay Kumar decon_ctx_remove(ctx); 67296976c3dSAjay Kumar return PTR_ERR(ctx->crtc); 67396976c3dSAjay Kumar } 67496976c3dSAjay Kumar 675cf67cc9aSGustavo Padovan if (ctx->encoder) 676a2986e80SGustavo Padovan exynos_dpi_bind(drm_dev, ctx->encoder); 67796976c3dSAjay Kumar 67896976c3dSAjay Kumar return 0; 67996976c3dSAjay Kumar 68096976c3dSAjay Kumar } 68196976c3dSAjay Kumar 68296976c3dSAjay Kumar static void decon_unbind(struct device *dev, struct device *master, 68396976c3dSAjay Kumar void *data) 68496976c3dSAjay Kumar { 68596976c3dSAjay Kumar struct decon_context *ctx = dev_get_drvdata(dev); 68696976c3dSAjay Kumar 6873cecda03SGustavo Padovan decon_disable(ctx->crtc); 68896976c3dSAjay Kumar 689cf67cc9aSGustavo Padovan if (ctx->encoder) 690cf67cc9aSGustavo Padovan exynos_dpi_remove(ctx->encoder); 69196976c3dSAjay Kumar 69296976c3dSAjay Kumar decon_ctx_remove(ctx); 69396976c3dSAjay Kumar } 69496976c3dSAjay Kumar 69596976c3dSAjay Kumar static const struct component_ops decon_component_ops = { 69696976c3dSAjay Kumar .bind = decon_bind, 69796976c3dSAjay Kumar .unbind = decon_unbind, 69896976c3dSAjay Kumar }; 69996976c3dSAjay Kumar 70096976c3dSAjay Kumar static int decon_probe(struct platform_device *pdev) 70196976c3dSAjay Kumar { 70296976c3dSAjay Kumar struct device *dev = &pdev->dev; 70396976c3dSAjay Kumar struct decon_context *ctx; 70496976c3dSAjay Kumar struct device_node *i80_if_timings; 70596976c3dSAjay Kumar struct resource *res; 70696976c3dSAjay Kumar int ret; 70796976c3dSAjay Kumar 70896976c3dSAjay Kumar if (!dev->of_node) 70996976c3dSAjay Kumar return -ENODEV; 71096976c3dSAjay Kumar 71196976c3dSAjay Kumar ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); 71296976c3dSAjay Kumar if (!ctx) 71396976c3dSAjay Kumar return -ENOMEM; 71496976c3dSAjay Kumar 71596976c3dSAjay Kumar ctx->dev = dev; 71696976c3dSAjay Kumar ctx->suspended = true; 71796976c3dSAjay Kumar 71896976c3dSAjay Kumar i80_if_timings = of_get_child_by_name(dev->of_node, "i80-if-timings"); 71996976c3dSAjay Kumar if (i80_if_timings) 72096976c3dSAjay Kumar ctx->i80_if = true; 72196976c3dSAjay Kumar of_node_put(i80_if_timings); 72296976c3dSAjay Kumar 72396976c3dSAjay Kumar ctx->regs = of_iomap(dev->of_node, 0); 72486650408SAndrzej Hajda if (!ctx->regs) 72586650408SAndrzej Hajda return -ENOMEM; 72696976c3dSAjay Kumar 72796976c3dSAjay Kumar ctx->pclk = devm_clk_get(dev, "pclk_decon0"); 72896976c3dSAjay Kumar if (IS_ERR(ctx->pclk)) { 72996976c3dSAjay Kumar dev_err(dev, "failed to get bus clock pclk\n"); 73096976c3dSAjay Kumar ret = PTR_ERR(ctx->pclk); 73196976c3dSAjay Kumar goto err_iounmap; 73296976c3dSAjay Kumar } 73396976c3dSAjay Kumar 73496976c3dSAjay Kumar ctx->aclk = devm_clk_get(dev, "aclk_decon0"); 73596976c3dSAjay Kumar if (IS_ERR(ctx->aclk)) { 73696976c3dSAjay Kumar dev_err(dev, "failed to get bus clock aclk\n"); 73796976c3dSAjay Kumar ret = PTR_ERR(ctx->aclk); 73896976c3dSAjay Kumar goto err_iounmap; 73996976c3dSAjay Kumar } 74096976c3dSAjay Kumar 74196976c3dSAjay Kumar ctx->eclk = devm_clk_get(dev, "decon0_eclk"); 74296976c3dSAjay Kumar if (IS_ERR(ctx->eclk)) { 74396976c3dSAjay Kumar dev_err(dev, "failed to get eclock\n"); 74496976c3dSAjay Kumar ret = PTR_ERR(ctx->eclk); 74596976c3dSAjay Kumar goto err_iounmap; 74696976c3dSAjay Kumar } 74796976c3dSAjay Kumar 74896976c3dSAjay Kumar ctx->vclk = devm_clk_get(dev, "decon0_vclk"); 74996976c3dSAjay Kumar if (IS_ERR(ctx->vclk)) { 75096976c3dSAjay Kumar dev_err(dev, "failed to get vclock\n"); 75196976c3dSAjay Kumar ret = PTR_ERR(ctx->vclk); 75296976c3dSAjay Kumar goto err_iounmap; 75396976c3dSAjay Kumar } 75496976c3dSAjay Kumar 75596976c3dSAjay Kumar res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, 75696976c3dSAjay Kumar ctx->i80_if ? "lcd_sys" : "vsync"); 75796976c3dSAjay Kumar if (!res) { 75896976c3dSAjay Kumar dev_err(dev, "irq request failed.\n"); 75996976c3dSAjay Kumar ret = -ENXIO; 76096976c3dSAjay Kumar goto err_iounmap; 76196976c3dSAjay Kumar } 76296976c3dSAjay Kumar 76396976c3dSAjay Kumar ret = devm_request_irq(dev, res->start, decon_irq_handler, 76496976c3dSAjay Kumar 0, "drm_decon", ctx); 76596976c3dSAjay Kumar if (ret) { 76696976c3dSAjay Kumar dev_err(dev, "irq request failed.\n"); 76796976c3dSAjay Kumar goto err_iounmap; 76896976c3dSAjay Kumar } 76996976c3dSAjay Kumar 77096976c3dSAjay Kumar init_waitqueue_head(&ctx->wait_vsync_queue); 77196976c3dSAjay Kumar atomic_set(&ctx->wait_vsync_event, 0); 77296976c3dSAjay Kumar 77396976c3dSAjay Kumar platform_set_drvdata(pdev, ctx); 77496976c3dSAjay Kumar 775cf67cc9aSGustavo Padovan ctx->encoder = exynos_dpi_probe(dev); 776cf67cc9aSGustavo Padovan if (IS_ERR(ctx->encoder)) { 777cf67cc9aSGustavo Padovan ret = PTR_ERR(ctx->encoder); 77896976c3dSAjay Kumar goto err_iounmap; 77996976c3dSAjay Kumar } 78096976c3dSAjay Kumar 78196976c3dSAjay Kumar pm_runtime_enable(dev); 78296976c3dSAjay Kumar 78396976c3dSAjay Kumar ret = component_add(dev, &decon_component_ops); 78496976c3dSAjay Kumar if (ret) 78596976c3dSAjay Kumar goto err_disable_pm_runtime; 78696976c3dSAjay Kumar 78796976c3dSAjay Kumar return ret; 78896976c3dSAjay Kumar 78996976c3dSAjay Kumar err_disable_pm_runtime: 79096976c3dSAjay Kumar pm_runtime_disable(dev); 79196976c3dSAjay Kumar 79296976c3dSAjay Kumar err_iounmap: 79396976c3dSAjay Kumar iounmap(ctx->regs); 79496976c3dSAjay Kumar 79596976c3dSAjay Kumar return ret; 79696976c3dSAjay Kumar } 79796976c3dSAjay Kumar 79896976c3dSAjay Kumar static int decon_remove(struct platform_device *pdev) 79996976c3dSAjay Kumar { 80096976c3dSAjay Kumar struct decon_context *ctx = dev_get_drvdata(&pdev->dev); 80196976c3dSAjay Kumar 80296976c3dSAjay Kumar pm_runtime_disable(&pdev->dev); 80396976c3dSAjay Kumar 80496976c3dSAjay Kumar iounmap(ctx->regs); 80596976c3dSAjay Kumar 80696976c3dSAjay Kumar component_del(&pdev->dev, &decon_component_ops); 80796976c3dSAjay Kumar 80896976c3dSAjay Kumar return 0; 80996976c3dSAjay Kumar } 81096976c3dSAjay Kumar 811681c801eSGustavo Padovan #ifdef CONFIG_PM 812681c801eSGustavo Padovan static int exynos7_decon_suspend(struct device *dev) 813681c801eSGustavo Padovan { 814681c801eSGustavo Padovan struct decon_context *ctx = dev_get_drvdata(dev); 815681c801eSGustavo Padovan 816681c801eSGustavo Padovan clk_disable_unprepare(ctx->vclk); 817681c801eSGustavo Padovan clk_disable_unprepare(ctx->eclk); 818681c801eSGustavo Padovan clk_disable_unprepare(ctx->aclk); 819681c801eSGustavo Padovan clk_disable_unprepare(ctx->pclk); 820681c801eSGustavo Padovan 821681c801eSGustavo Padovan return 0; 822681c801eSGustavo Padovan } 823681c801eSGustavo Padovan 824681c801eSGustavo Padovan static int exynos7_decon_resume(struct device *dev) 825681c801eSGustavo Padovan { 826681c801eSGustavo Padovan struct decon_context *ctx = dev_get_drvdata(dev); 827681c801eSGustavo Padovan int ret; 828681c801eSGustavo Padovan 829681c801eSGustavo Padovan ret = clk_prepare_enable(ctx->pclk); 830681c801eSGustavo Padovan if (ret < 0) { 831681c801eSGustavo Padovan DRM_ERROR("Failed to prepare_enable the pclk [%d]\n", ret); 832681c801eSGustavo Padovan return ret; 833681c801eSGustavo Padovan } 834681c801eSGustavo Padovan 835681c801eSGustavo Padovan ret = clk_prepare_enable(ctx->aclk); 836681c801eSGustavo Padovan if (ret < 0) { 837681c801eSGustavo Padovan DRM_ERROR("Failed to prepare_enable the aclk [%d]\n", ret); 838681c801eSGustavo Padovan return ret; 839681c801eSGustavo Padovan } 840681c801eSGustavo Padovan 841681c801eSGustavo Padovan ret = clk_prepare_enable(ctx->eclk); 842681c801eSGustavo Padovan if (ret < 0) { 843681c801eSGustavo Padovan DRM_ERROR("Failed to prepare_enable the eclk [%d]\n", ret); 844681c801eSGustavo Padovan return ret; 845681c801eSGustavo Padovan } 846681c801eSGustavo Padovan 847681c801eSGustavo Padovan ret = clk_prepare_enable(ctx->vclk); 848681c801eSGustavo Padovan if (ret < 0) { 849681c801eSGustavo Padovan DRM_ERROR("Failed to prepare_enable the vclk [%d]\n", ret); 850681c801eSGustavo Padovan return ret; 851681c801eSGustavo Padovan } 852681c801eSGustavo Padovan 853681c801eSGustavo Padovan return 0; 854681c801eSGustavo Padovan } 855681c801eSGustavo Padovan #endif 856681c801eSGustavo Padovan 857681c801eSGustavo Padovan static const struct dev_pm_ops exynos7_decon_pm_ops = { 858681c801eSGustavo Padovan SET_RUNTIME_PM_OPS(exynos7_decon_suspend, exynos7_decon_resume, 859681c801eSGustavo Padovan NULL) 860681c801eSGustavo Padovan }; 861681c801eSGustavo Padovan 86296976c3dSAjay Kumar struct platform_driver decon_driver = { 86396976c3dSAjay Kumar .probe = decon_probe, 86496976c3dSAjay Kumar .remove = decon_remove, 86596976c3dSAjay Kumar .driver = { 86696976c3dSAjay Kumar .name = "exynos-decon", 867681c801eSGustavo Padovan .pm = &exynos7_decon_pm_ops, 86896976c3dSAjay Kumar .of_match_table = decon_driver_dt_match, 86996976c3dSAjay Kumar }, 87096976c3dSAjay Kumar }; 871