12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
296976c3dSAjay Kumar /* drivers/gpu/drm/exynos/exynos7_drm_decon.c
396976c3dSAjay Kumar *
496976c3dSAjay Kumar * Copyright (C) 2014 Samsung Electronics Co.Ltd
596976c3dSAjay Kumar * Authors:
696976c3dSAjay Kumar * Akshu Agarwal <akshua@gmail.com>
796976c3dSAjay Kumar * Ajay Kumar <ajaykumar.rs@samsung.com>
896976c3dSAjay Kumar */
996976c3dSAjay Kumar
1096976c3dSAjay Kumar #include <linux/clk.h>
1196976c3dSAjay Kumar #include <linux/component.h>
1296976c3dSAjay Kumar #include <linux/kernel.h>
1396976c3dSAjay Kumar #include <linux/of.h>
1496976c3dSAjay Kumar #include <linux/of_address.h>
1596976c3dSAjay Kumar #include <linux/platform_device.h>
1696976c3dSAjay Kumar #include <linux/pm_runtime.h>
1796976c3dSAjay Kumar
1896976c3dSAjay Kumar #include <video/of_display_timing.h>
1996976c3dSAjay Kumar #include <video/of_videomode.h>
2096976c3dSAjay Kumar
212bda34d7SSam Ravnborg #include <drm/drm_fourcc.h>
22720cf96dSVille Syrjälä #include <drm/drm_framebuffer.h>
232bda34d7SSam Ravnborg #include <drm/drm_vblank.h>
242bda34d7SSam Ravnborg #include <drm/exynos_drm.h>
252bda34d7SSam Ravnborg
2696976c3dSAjay Kumar #include "exynos_drm_crtc.h"
2796976c3dSAjay Kumar #include "exynos_drm_drv.h"
280488f50eSMarek Szyprowski #include "exynos_drm_fb.h"
292bda34d7SSam Ravnborg #include "exynos_drm_plane.h"
304f52e550SKrzysztof Kozlowski #include "regs-decon7.h"
3196976c3dSAjay Kumar
3296976c3dSAjay Kumar /*
3396976c3dSAjay Kumar * DECON stands for Display and Enhancement controller.
3496976c3dSAjay Kumar */
3596976c3dSAjay Kumar
3696976c3dSAjay Kumar #define MIN_FB_WIDTH_FOR_16WORD_BURST 128
3796976c3dSAjay Kumar
3896976c3dSAjay Kumar #define WINDOWS_NR 2
3996976c3dSAjay Kumar
4096976c3dSAjay Kumar struct decon_context {
4196976c3dSAjay Kumar struct device *dev;
4296976c3dSAjay Kumar struct drm_device *drm_dev;
4307dc3678SMarek Szyprowski void *dma_priv;
4496976c3dSAjay Kumar struct exynos_drm_crtc *crtc;
457ee14cdcSGustavo Padovan struct exynos_drm_plane planes[WINDOWS_NR];
46fd2d2fc2SMarek Szyprowski struct exynos_drm_plane_config configs[WINDOWS_NR];
4796976c3dSAjay Kumar struct clk *pclk;
4896976c3dSAjay Kumar struct clk *aclk;
4996976c3dSAjay Kumar struct clk *eclk;
5096976c3dSAjay Kumar struct clk *vclk;
5196976c3dSAjay Kumar void __iomem *regs;
5296976c3dSAjay Kumar unsigned long irq_flags;
5396976c3dSAjay Kumar bool i80_if;
5496976c3dSAjay Kumar bool suspended;
5596976c3dSAjay Kumar wait_queue_head_t wait_vsync_queue;
5696976c3dSAjay Kumar atomic_t wait_vsync_event;
5796976c3dSAjay Kumar
582b8376c8SGustavo Padovan struct drm_encoder *encoder;
5996976c3dSAjay Kumar };
6096976c3dSAjay Kumar
6196976c3dSAjay Kumar static const struct of_device_id decon_driver_dt_match[] = {
6296976c3dSAjay Kumar {.compatible = "samsung,exynos7-decon"},
6396976c3dSAjay Kumar {},
6496976c3dSAjay Kumar };
6596976c3dSAjay Kumar MODULE_DEVICE_TABLE(of, decon_driver_dt_match);
6696976c3dSAjay Kumar
67fbbb1e1aSMarek Szyprowski static const uint32_t decon_formats[] = {
68fbbb1e1aSMarek Szyprowski DRM_FORMAT_RGB565,
69fbbb1e1aSMarek Szyprowski DRM_FORMAT_XRGB8888,
70fbbb1e1aSMarek Szyprowski DRM_FORMAT_XBGR8888,
71fbbb1e1aSMarek Szyprowski DRM_FORMAT_RGBX8888,
72fbbb1e1aSMarek Szyprowski DRM_FORMAT_BGRX8888,
73fbbb1e1aSMarek Szyprowski DRM_FORMAT_ARGB8888,
74fbbb1e1aSMarek Szyprowski DRM_FORMAT_ABGR8888,
75fbbb1e1aSMarek Szyprowski DRM_FORMAT_RGBA8888,
76fbbb1e1aSMarek Szyprowski DRM_FORMAT_BGRA8888,
77fbbb1e1aSMarek Szyprowski };
78fbbb1e1aSMarek Szyprowski
79fd2d2fc2SMarek Szyprowski static const enum drm_plane_type decon_win_types[WINDOWS_NR] = {
80fd2d2fc2SMarek Szyprowski DRM_PLANE_TYPE_PRIMARY,
81fd2d2fc2SMarek Szyprowski DRM_PLANE_TYPE_CURSOR,
82fd2d2fc2SMarek Szyprowski };
83fd2d2fc2SMarek Szyprowski
decon_wait_for_vblank(struct exynos_drm_crtc * crtc)8496976c3dSAjay Kumar static void decon_wait_for_vblank(struct exynos_drm_crtc *crtc)
8596976c3dSAjay Kumar {
8696976c3dSAjay Kumar struct decon_context *ctx = crtc->ctx;
8796976c3dSAjay Kumar
8896976c3dSAjay Kumar if (ctx->suspended)
8996976c3dSAjay Kumar return;
9096976c3dSAjay Kumar
9196976c3dSAjay Kumar atomic_set(&ctx->wait_vsync_event, 1);
9296976c3dSAjay Kumar
9396976c3dSAjay Kumar /*
9496976c3dSAjay Kumar * wait for DECON to signal VSYNC interrupt or return after
9596976c3dSAjay Kumar * timeout which is set to 50ms (refresh rate of 20).
9696976c3dSAjay Kumar */
9796976c3dSAjay Kumar if (!wait_event_timeout(ctx->wait_vsync_queue,
9896976c3dSAjay Kumar !atomic_read(&ctx->wait_vsync_event),
9996976c3dSAjay Kumar HZ/20))
1006be90056SInki Dae DRM_DEV_DEBUG_KMS(ctx->dev, "vblank wait timed out.\n");
10196976c3dSAjay Kumar }
10296976c3dSAjay Kumar
decon_clear_channels(struct exynos_drm_crtc * crtc)103fc2e013fSHyungwon Hwang static void decon_clear_channels(struct exynos_drm_crtc *crtc)
10496976c3dSAjay Kumar {
105fc2e013fSHyungwon Hwang struct decon_context *ctx = crtc->ctx;
1065b1d5bc6STobias Jakobi unsigned int win, ch_enabled = 0;
10796976c3dSAjay Kumar
10896976c3dSAjay Kumar /* Check if any channel is enabled. */
10996976c3dSAjay Kumar for (win = 0; win < WINDOWS_NR; win++) {
11096976c3dSAjay Kumar u32 val = readl(ctx->regs + WINCON(win));
11196976c3dSAjay Kumar
11296976c3dSAjay Kumar if (val & WINCONx_ENWIN) {
11396976c3dSAjay Kumar val &= ~WINCONx_ENWIN;
11496976c3dSAjay Kumar writel(val, ctx->regs + WINCON(win));
11596976c3dSAjay Kumar ch_enabled = 1;
11696976c3dSAjay Kumar }
11796976c3dSAjay Kumar }
11896976c3dSAjay Kumar
11996976c3dSAjay Kumar /* Wait for vsync, as disable channel takes effect at next vsync */
120681c801eSGustavo Padovan if (ch_enabled)
12196976c3dSAjay Kumar decon_wait_for_vblank(ctx->crtc);
12296976c3dSAjay Kumar }
12396976c3dSAjay Kumar
decon_ctx_initialize(struct decon_context * ctx,struct drm_device * drm_dev)12496976c3dSAjay Kumar static int decon_ctx_initialize(struct decon_context *ctx,
12596976c3dSAjay Kumar struct drm_device *drm_dev)
12696976c3dSAjay Kumar {
12796976c3dSAjay Kumar ctx->drm_dev = drm_dev;
12896976c3dSAjay Kumar
129eb7a3fc7SJoonyoung Shim decon_clear_channels(ctx->crtc);
130eb7a3fc7SJoonyoung Shim
13107dc3678SMarek Szyprowski return exynos_drm_register_dma(drm_dev, ctx->dev, &ctx->dma_priv);
13296976c3dSAjay Kumar }
13396976c3dSAjay Kumar
decon_ctx_remove(struct decon_context * ctx)13496976c3dSAjay Kumar static void decon_ctx_remove(struct decon_context *ctx)
13596976c3dSAjay Kumar {
13696976c3dSAjay Kumar /* detach this sub driver from iommu mapping if supported. */
13707dc3678SMarek Szyprowski exynos_drm_unregister_dma(ctx->drm_dev, ctx->dev, &ctx->dma_priv);
13896976c3dSAjay Kumar }
13996976c3dSAjay Kumar
decon_calc_clkdiv(struct decon_context * ctx,const struct drm_display_mode * mode)14096976c3dSAjay Kumar static u32 decon_calc_clkdiv(struct decon_context *ctx,
14196976c3dSAjay Kumar const struct drm_display_mode *mode)
14296976c3dSAjay Kumar {
143e2ed1355SVille Syrjälä unsigned long ideal_clk = mode->clock;
14496976c3dSAjay Kumar u32 clkdiv;
14596976c3dSAjay Kumar
14696976c3dSAjay Kumar /* Find the clock divider value that gets us closest to ideal_clk */
14796976c3dSAjay Kumar clkdiv = DIV_ROUND_UP(clk_get_rate(ctx->vclk), ideal_clk);
14896976c3dSAjay Kumar
14996976c3dSAjay Kumar return (clkdiv < 0x100) ? clkdiv : 0xff;
15096976c3dSAjay Kumar }
15196976c3dSAjay Kumar
decon_commit(struct exynos_drm_crtc * crtc)15296976c3dSAjay Kumar static void decon_commit(struct exynos_drm_crtc *crtc)
15396976c3dSAjay Kumar {
15496976c3dSAjay Kumar struct decon_context *ctx = crtc->ctx;
155020e79deSJoonyoung Shim struct drm_display_mode *mode = &crtc->base.state->adjusted_mode;
15696976c3dSAjay Kumar u32 val, clkdiv;
15796976c3dSAjay Kumar
15896976c3dSAjay Kumar if (ctx->suspended)
15996976c3dSAjay Kumar return;
16096976c3dSAjay Kumar
16196976c3dSAjay Kumar /* nothing to do if we haven't set the mode yet */
16296976c3dSAjay Kumar if (mode->htotal == 0 || mode->vtotal == 0)
16396976c3dSAjay Kumar return;
16496976c3dSAjay Kumar
16596976c3dSAjay Kumar if (!ctx->i80_if) {
16696976c3dSAjay Kumar int vsync_len, vbpd, vfpd, hsync_len, hbpd, hfpd;
16796976c3dSAjay Kumar /* setup vertical timing values. */
16896976c3dSAjay Kumar vsync_len = mode->crtc_vsync_end - mode->crtc_vsync_start;
16996976c3dSAjay Kumar vbpd = mode->crtc_vtotal - mode->crtc_vsync_end;
17096976c3dSAjay Kumar vfpd = mode->crtc_vsync_start - mode->crtc_vdisplay;
17196976c3dSAjay Kumar
17296976c3dSAjay Kumar val = VIDTCON0_VBPD(vbpd - 1) | VIDTCON0_VFPD(vfpd - 1);
17396976c3dSAjay Kumar writel(val, ctx->regs + VIDTCON0);
17496976c3dSAjay Kumar
17596976c3dSAjay Kumar val = VIDTCON1_VSPW(vsync_len - 1);
17696976c3dSAjay Kumar writel(val, ctx->regs + VIDTCON1);
17796976c3dSAjay Kumar
17896976c3dSAjay Kumar /* setup horizontal timing values. */
17996976c3dSAjay Kumar hsync_len = mode->crtc_hsync_end - mode->crtc_hsync_start;
18096976c3dSAjay Kumar hbpd = mode->crtc_htotal - mode->crtc_hsync_end;
18196976c3dSAjay Kumar hfpd = mode->crtc_hsync_start - mode->crtc_hdisplay;
18296976c3dSAjay Kumar
18396976c3dSAjay Kumar /* setup horizontal timing values. */
18496976c3dSAjay Kumar val = VIDTCON2_HBPD(hbpd - 1) | VIDTCON2_HFPD(hfpd - 1);
18596976c3dSAjay Kumar writel(val, ctx->regs + VIDTCON2);
18696976c3dSAjay Kumar
18796976c3dSAjay Kumar val = VIDTCON3_HSPW(hsync_len - 1);
18896976c3dSAjay Kumar writel(val, ctx->regs + VIDTCON3);
18996976c3dSAjay Kumar }
19096976c3dSAjay Kumar
19196976c3dSAjay Kumar /* setup horizontal and vertical display size. */
19296976c3dSAjay Kumar val = VIDTCON4_LINEVAL(mode->vdisplay - 1) |
19396976c3dSAjay Kumar VIDTCON4_HOZVAL(mode->hdisplay - 1);
19496976c3dSAjay Kumar writel(val, ctx->regs + VIDTCON4);
19596976c3dSAjay Kumar
19696976c3dSAjay Kumar writel(mode->vdisplay - 1, ctx->regs + LINECNT_OP_THRESHOLD);
19796976c3dSAjay Kumar
19896976c3dSAjay Kumar /*
19996976c3dSAjay Kumar * fields of register with prefix '_F' would be updated
20096976c3dSAjay Kumar * at vsync(same as dma start)
20196976c3dSAjay Kumar */
20296976c3dSAjay Kumar val = VIDCON0_ENVID | VIDCON0_ENVID_F;
20396976c3dSAjay Kumar writel(val, ctx->regs + VIDCON0);
20496976c3dSAjay Kumar
20596976c3dSAjay Kumar clkdiv = decon_calc_clkdiv(ctx, mode);
20696976c3dSAjay Kumar if (clkdiv > 1) {
20796976c3dSAjay Kumar val = VCLKCON1_CLKVAL_NUM_VCLK(clkdiv - 1);
20896976c3dSAjay Kumar writel(val, ctx->regs + VCLKCON1);
20996976c3dSAjay Kumar writel(val, ctx->regs + VCLKCON2);
21096976c3dSAjay Kumar }
21196976c3dSAjay Kumar
21296976c3dSAjay Kumar val = readl(ctx->regs + DECON_UPDATE);
21396976c3dSAjay Kumar val |= DECON_UPDATE_STANDALONE_F;
21496976c3dSAjay Kumar writel(val, ctx->regs + DECON_UPDATE);
21596976c3dSAjay Kumar }
21696976c3dSAjay Kumar
decon_enable_vblank(struct exynos_drm_crtc * crtc)21796976c3dSAjay Kumar static int decon_enable_vblank(struct exynos_drm_crtc *crtc)
21896976c3dSAjay Kumar {
21996976c3dSAjay Kumar struct decon_context *ctx = crtc->ctx;
22096976c3dSAjay Kumar u32 val;
22196976c3dSAjay Kumar
22296976c3dSAjay Kumar if (ctx->suspended)
22396976c3dSAjay Kumar return -EPERM;
22496976c3dSAjay Kumar
22596976c3dSAjay Kumar if (!test_and_set_bit(0, &ctx->irq_flags)) {
22696976c3dSAjay Kumar val = readl(ctx->regs + VIDINTCON0);
22796976c3dSAjay Kumar
22896976c3dSAjay Kumar val |= VIDINTCON0_INT_ENABLE;
22996976c3dSAjay Kumar
23096976c3dSAjay Kumar if (!ctx->i80_if) {
23196976c3dSAjay Kumar val |= VIDINTCON0_INT_FRAME;
23296976c3dSAjay Kumar val &= ~VIDINTCON0_FRAMESEL0_MASK;
23396976c3dSAjay Kumar val |= VIDINTCON0_FRAMESEL0_VSYNC;
23496976c3dSAjay Kumar }
23596976c3dSAjay Kumar
23696976c3dSAjay Kumar writel(val, ctx->regs + VIDINTCON0);
23796976c3dSAjay Kumar }
23896976c3dSAjay Kumar
23996976c3dSAjay Kumar return 0;
24096976c3dSAjay Kumar }
24196976c3dSAjay Kumar
decon_disable_vblank(struct exynos_drm_crtc * crtc)24296976c3dSAjay Kumar static void decon_disable_vblank(struct exynos_drm_crtc *crtc)
24396976c3dSAjay Kumar {
24496976c3dSAjay Kumar struct decon_context *ctx = crtc->ctx;
24596976c3dSAjay Kumar u32 val;
24696976c3dSAjay Kumar
24796976c3dSAjay Kumar if (ctx->suspended)
24896976c3dSAjay Kumar return;
24996976c3dSAjay Kumar
25096976c3dSAjay Kumar if (test_and_clear_bit(0, &ctx->irq_flags)) {
25196976c3dSAjay Kumar val = readl(ctx->regs + VIDINTCON0);
25296976c3dSAjay Kumar
25396976c3dSAjay Kumar val &= ~VIDINTCON0_INT_ENABLE;
25496976c3dSAjay Kumar if (!ctx->i80_if)
25596976c3dSAjay Kumar val &= ~VIDINTCON0_INT_FRAME;
25696976c3dSAjay Kumar
25796976c3dSAjay Kumar writel(val, ctx->regs + VIDINTCON0);
25896976c3dSAjay Kumar }
25996976c3dSAjay Kumar }
26096976c3dSAjay Kumar
decon_win_set_pixfmt(struct decon_context * ctx,unsigned int win,struct drm_framebuffer * fb)2612eeb2e5eSGustavo Padovan static void decon_win_set_pixfmt(struct decon_context *ctx, unsigned int win,
2622eeb2e5eSGustavo Padovan struct drm_framebuffer *fb)
26396976c3dSAjay Kumar {
26496976c3dSAjay Kumar unsigned long val;
2657ee14cdcSGustavo Padovan int padding;
26696976c3dSAjay Kumar
26796976c3dSAjay Kumar val = readl(ctx->regs + WINCON(win));
26896976c3dSAjay Kumar val &= ~WINCONx_BPPMODE_MASK;
26996976c3dSAjay Kumar
270438b74a5SVille Syrjälä switch (fb->format->format) {
27196976c3dSAjay Kumar case DRM_FORMAT_RGB565:
27296976c3dSAjay Kumar val |= WINCONx_BPPMODE_16BPP_565;
27396976c3dSAjay Kumar val |= WINCONx_BURSTLEN_16WORD;
27496976c3dSAjay Kumar break;
27596976c3dSAjay Kumar case DRM_FORMAT_XRGB8888:
27696976c3dSAjay Kumar val |= WINCONx_BPPMODE_24BPP_xRGB;
27796976c3dSAjay Kumar val |= WINCONx_BURSTLEN_16WORD;
27896976c3dSAjay Kumar break;
27996976c3dSAjay Kumar case DRM_FORMAT_XBGR8888:
28096976c3dSAjay Kumar val |= WINCONx_BPPMODE_24BPP_xBGR;
28196976c3dSAjay Kumar val |= WINCONx_BURSTLEN_16WORD;
28296976c3dSAjay Kumar break;
28396976c3dSAjay Kumar case DRM_FORMAT_RGBX8888:
28496976c3dSAjay Kumar val |= WINCONx_BPPMODE_24BPP_RGBx;
28596976c3dSAjay Kumar val |= WINCONx_BURSTLEN_16WORD;
28696976c3dSAjay Kumar break;
28796976c3dSAjay Kumar case DRM_FORMAT_BGRX8888:
28896976c3dSAjay Kumar val |= WINCONx_BPPMODE_24BPP_BGRx;
28996976c3dSAjay Kumar val |= WINCONx_BURSTLEN_16WORD;
29096976c3dSAjay Kumar break;
29196976c3dSAjay Kumar case DRM_FORMAT_ARGB8888:
29296976c3dSAjay Kumar val |= WINCONx_BPPMODE_32BPP_ARGB | WINCONx_BLD_PIX |
29396976c3dSAjay Kumar WINCONx_ALPHA_SEL;
29496976c3dSAjay Kumar val |= WINCONx_BURSTLEN_16WORD;
29596976c3dSAjay Kumar break;
29696976c3dSAjay Kumar case DRM_FORMAT_ABGR8888:
29796976c3dSAjay Kumar val |= WINCONx_BPPMODE_32BPP_ABGR | WINCONx_BLD_PIX |
29896976c3dSAjay Kumar WINCONx_ALPHA_SEL;
29996976c3dSAjay Kumar val |= WINCONx_BURSTLEN_16WORD;
30096976c3dSAjay Kumar break;
30196976c3dSAjay Kumar case DRM_FORMAT_RGBA8888:
30296976c3dSAjay Kumar val |= WINCONx_BPPMODE_32BPP_RGBA | WINCONx_BLD_PIX |
30396976c3dSAjay Kumar WINCONx_ALPHA_SEL;
30496976c3dSAjay Kumar val |= WINCONx_BURSTLEN_16WORD;
30596976c3dSAjay Kumar break;
30696976c3dSAjay Kumar case DRM_FORMAT_BGRA8888:
3075b7b1b7fSTobias Jakobi default:
30896976c3dSAjay Kumar val |= WINCONx_BPPMODE_32BPP_BGRA | WINCONx_BLD_PIX |
30996976c3dSAjay Kumar WINCONx_ALPHA_SEL;
31096976c3dSAjay Kumar val |= WINCONx_BURSTLEN_16WORD;
31196976c3dSAjay Kumar break;
31296976c3dSAjay Kumar }
31396976c3dSAjay Kumar
3146be90056SInki Dae DRM_DEV_DEBUG_KMS(ctx->dev, "cpp = %d\n", fb->format->cpp[0]);
31596976c3dSAjay Kumar
31696976c3dSAjay Kumar /*
31796976c3dSAjay Kumar * In case of exynos, setting dma-burst to 16Word causes permanent
31896976c3dSAjay Kumar * tearing for very small buffers, e.g. cursor buffer. Burst Mode
31996976c3dSAjay Kumar * switching which is based on plane size is not recommended as
32096976c3dSAjay Kumar * plane size varies a lot towards the end of the screen and rapid
32196976c3dSAjay Kumar * movement causes unstable DMA which results into iommu crash/tear.
32296976c3dSAjay Kumar */
32396976c3dSAjay Kumar
324272725c7SVille Syrjälä padding = (fb->pitches[0] / fb->format->cpp[0]) - fb->width;
3252eeb2e5eSGustavo Padovan if (fb->width + padding < MIN_FB_WIDTH_FOR_16WORD_BURST) {
32696976c3dSAjay Kumar val &= ~WINCONx_BURSTLEN_MASK;
32796976c3dSAjay Kumar val |= WINCONx_BURSTLEN_8WORD;
32896976c3dSAjay Kumar }
32996976c3dSAjay Kumar
33096976c3dSAjay Kumar writel(val, ctx->regs + WINCON(win));
33196976c3dSAjay Kumar }
33296976c3dSAjay Kumar
decon_win_set_colkey(struct decon_context * ctx,unsigned int win)33396976c3dSAjay Kumar static void decon_win_set_colkey(struct decon_context *ctx, unsigned int win)
33496976c3dSAjay Kumar {
33596976c3dSAjay Kumar unsigned int keycon0 = 0, keycon1 = 0;
33696976c3dSAjay Kumar
33796976c3dSAjay Kumar keycon0 = ~(WxKEYCON0_KEYBL_EN | WxKEYCON0_KEYEN_F |
33896976c3dSAjay Kumar WxKEYCON0_DIRCON) | WxKEYCON0_COMPKEY(0);
33996976c3dSAjay Kumar
34096976c3dSAjay Kumar keycon1 = WxKEYCON1_COLVAL(0xffffffff);
34196976c3dSAjay Kumar
34296976c3dSAjay Kumar writel(keycon0, ctx->regs + WKEYCON0_BASE(win));
34396976c3dSAjay Kumar writel(keycon1, ctx->regs + WKEYCON1_BASE(win));
34496976c3dSAjay Kumar }
34596976c3dSAjay Kumar
34696976c3dSAjay Kumar /**
34773f6f230SLee Jones * decon_shadow_protect_win() - disable updating values from shadow registers at vsync
34896976c3dSAjay Kumar *
349400fb19dSLee Jones * @ctx: display and enhancement controller context
35096976c3dSAjay Kumar * @win: window to protect registers for
35196976c3dSAjay Kumar * @protect: 1 to protect (disable updates)
35296976c3dSAjay Kumar */
decon_shadow_protect_win(struct decon_context * ctx,unsigned int win,bool protect)35396976c3dSAjay Kumar static void decon_shadow_protect_win(struct decon_context *ctx,
3546e2a3b66SGustavo Padovan unsigned int win, bool protect)
35596976c3dSAjay Kumar {
35696976c3dSAjay Kumar u32 bits, val;
35796976c3dSAjay Kumar
35896976c3dSAjay Kumar bits = SHADOWCON_WINx_PROTECT(win);
35996976c3dSAjay Kumar
36096976c3dSAjay Kumar val = readl(ctx->regs + SHADOWCON);
36196976c3dSAjay Kumar if (protect)
36296976c3dSAjay Kumar val |= bits;
36396976c3dSAjay Kumar else
36496976c3dSAjay Kumar val &= ~bits;
36596976c3dSAjay Kumar writel(val, ctx->regs + SHADOWCON);
36696976c3dSAjay Kumar }
36796976c3dSAjay Kumar
decon_atomic_begin(struct exynos_drm_crtc * crtc)368d29c2c14SMarek Szyprowski static void decon_atomic_begin(struct exynos_drm_crtc *crtc)
369cc5a7b35SHyungwon Hwang {
370cc5a7b35SHyungwon Hwang struct decon_context *ctx = crtc->ctx;
371d29c2c14SMarek Szyprowski int i;
372cc5a7b35SHyungwon Hwang
373cc5a7b35SHyungwon Hwang if (ctx->suspended)
374cc5a7b35SHyungwon Hwang return;
375cc5a7b35SHyungwon Hwang
376d29c2c14SMarek Szyprowski for (i = 0; i < WINDOWS_NR; i++)
377d29c2c14SMarek Szyprowski decon_shadow_protect_win(ctx, i, true);
378cc5a7b35SHyungwon Hwang }
379cc5a7b35SHyungwon Hwang
decon_update_plane(struct exynos_drm_crtc * crtc,struct exynos_drm_plane * plane)3801e1d1393SGustavo Padovan static void decon_update_plane(struct exynos_drm_crtc *crtc,
3811e1d1393SGustavo Padovan struct exynos_drm_plane *plane)
38296976c3dSAjay Kumar {
3830114f404SMarek Szyprowski struct exynos_drm_plane_state *state =
3840114f404SMarek Szyprowski to_exynos_plane_state(plane->base.state);
38596976c3dSAjay Kumar struct decon_context *ctx = crtc->ctx;
3860114f404SMarek Szyprowski struct drm_framebuffer *fb = state->base.fb;
3876e2a3b66SGustavo Padovan int padding;
38896976c3dSAjay Kumar unsigned long val, alpha;
38996976c3dSAjay Kumar unsigned int last_x;
39096976c3dSAjay Kumar unsigned int last_y;
39140bdfb0aSMarek Szyprowski unsigned int win = plane->index;
392ac60944cSTobias Jakobi unsigned int cpp = fb->format->cpp[0];
3930488f50eSMarek Szyprowski unsigned int pitch = fb->pitches[0];
39496976c3dSAjay Kumar
39596976c3dSAjay Kumar if (ctx->suspended)
39696976c3dSAjay Kumar return;
39796976c3dSAjay Kumar
39896976c3dSAjay Kumar /*
39996976c3dSAjay Kumar * SHADOWCON/PRTCON register is used for enabling timing.
40096976c3dSAjay Kumar *
40196976c3dSAjay Kumar * for example, once only width value of a register is set,
40296976c3dSAjay Kumar * if the dma is started then decon hardware could malfunction so
40396976c3dSAjay Kumar * with protect window setting, the register fields with prefix '_F'
40496976c3dSAjay Kumar * wouldn't be updated at vsync also but updated once unprotect window
40596976c3dSAjay Kumar * is set.
40696976c3dSAjay Kumar */
40796976c3dSAjay Kumar
40896976c3dSAjay Kumar /* buffer start address */
4090488f50eSMarek Szyprowski val = (unsigned long)exynos_drm_fb_dma_addr(fb, 0);
41096976c3dSAjay Kumar writel(val, ctx->regs + VIDW_BUF_START(win));
41196976c3dSAjay Kumar
412ac60944cSTobias Jakobi padding = (pitch / cpp) - fb->width;
4137ee14cdcSGustavo Padovan
41496976c3dSAjay Kumar /* buffer size */
4150488f50eSMarek Szyprowski writel(fb->width + padding, ctx->regs + VIDW_WHOLE_X(win));
4160488f50eSMarek Szyprowski writel(fb->height, ctx->regs + VIDW_WHOLE_Y(win));
41796976c3dSAjay Kumar
41896976c3dSAjay Kumar /* offset from the start of the buffer to read */
4190114f404SMarek Szyprowski writel(state->src.x, ctx->regs + VIDW_OFFSET_X(win));
4200114f404SMarek Szyprowski writel(state->src.y, ctx->regs + VIDW_OFFSET_Y(win));
42196976c3dSAjay Kumar
4226be90056SInki Dae DRM_DEV_DEBUG_KMS(ctx->dev, "start addr = 0x%lx\n",
4237ee14cdcSGustavo Padovan (unsigned long)val);
4246be90056SInki Dae DRM_DEV_DEBUG_KMS(ctx->dev, "ovl_width = %d, ovl_height = %d\n",
4250114f404SMarek Szyprowski state->crtc.w, state->crtc.h);
42696976c3dSAjay Kumar
4270114f404SMarek Szyprowski val = VIDOSDxA_TOPLEFT_X(state->crtc.x) |
4280114f404SMarek Szyprowski VIDOSDxA_TOPLEFT_Y(state->crtc.y);
42996976c3dSAjay Kumar writel(val, ctx->regs + VIDOSD_A(win));
43096976c3dSAjay Kumar
4310114f404SMarek Szyprowski last_x = state->crtc.x + state->crtc.w;
43296976c3dSAjay Kumar if (last_x)
43396976c3dSAjay Kumar last_x--;
4340114f404SMarek Szyprowski last_y = state->crtc.y + state->crtc.h;
43596976c3dSAjay Kumar if (last_y)
43696976c3dSAjay Kumar last_y--;
43796976c3dSAjay Kumar
43896976c3dSAjay Kumar val = VIDOSDxB_BOTRIGHT_X(last_x) | VIDOSDxB_BOTRIGHT_Y(last_y);
43996976c3dSAjay Kumar
44096976c3dSAjay Kumar writel(val, ctx->regs + VIDOSD_B(win));
44196976c3dSAjay Kumar
4426be90056SInki Dae DRM_DEV_DEBUG_KMS(ctx->dev, "osd pos: tx = %d, ty = %d, bx = %d, by = %d\n",
4430114f404SMarek Szyprowski state->crtc.x, state->crtc.y, last_x, last_y);
44496976c3dSAjay Kumar
44596976c3dSAjay Kumar /* OSD alpha */
44696976c3dSAjay Kumar alpha = VIDOSDxC_ALPHA0_R_F(0x0) |
44796976c3dSAjay Kumar VIDOSDxC_ALPHA0_G_F(0x0) |
44896976c3dSAjay Kumar VIDOSDxC_ALPHA0_B_F(0x0);
44996976c3dSAjay Kumar
45096976c3dSAjay Kumar writel(alpha, ctx->regs + VIDOSD_C(win));
45196976c3dSAjay Kumar
45296976c3dSAjay Kumar alpha = VIDOSDxD_ALPHA1_R_F(0xff) |
45396976c3dSAjay Kumar VIDOSDxD_ALPHA1_G_F(0xff) |
45496976c3dSAjay Kumar VIDOSDxD_ALPHA1_B_F(0xff);
45596976c3dSAjay Kumar
45696976c3dSAjay Kumar writel(alpha, ctx->regs + VIDOSD_D(win));
45796976c3dSAjay Kumar
4580488f50eSMarek Szyprowski decon_win_set_pixfmt(ctx, win, fb);
45996976c3dSAjay Kumar
46096976c3dSAjay Kumar /* hardware window 0 doesn't support color key. */
46196976c3dSAjay Kumar if (win != 0)
46296976c3dSAjay Kumar decon_win_set_colkey(ctx, win);
46396976c3dSAjay Kumar
46496976c3dSAjay Kumar /* wincon */
46596976c3dSAjay Kumar val = readl(ctx->regs + WINCON(win));
46696976c3dSAjay Kumar val |= WINCONx_TRIPLE_BUF_MODE;
46796976c3dSAjay Kumar val |= WINCONx_ENWIN;
46896976c3dSAjay Kumar writel(val, ctx->regs + WINCON(win));
46996976c3dSAjay Kumar
47096976c3dSAjay Kumar /* Enable DMA channel and unprotect windows */
47196976c3dSAjay Kumar decon_shadow_protect_win(ctx, win, false);
47296976c3dSAjay Kumar
47396976c3dSAjay Kumar val = readl(ctx->regs + DECON_UPDATE);
47496976c3dSAjay Kumar val |= DECON_UPDATE_STANDALONE_F;
47596976c3dSAjay Kumar writel(val, ctx->regs + DECON_UPDATE);
47696976c3dSAjay Kumar }
47796976c3dSAjay Kumar
decon_disable_plane(struct exynos_drm_crtc * crtc,struct exynos_drm_plane * plane)4781e1d1393SGustavo Padovan static void decon_disable_plane(struct exynos_drm_crtc *crtc,
4791e1d1393SGustavo Padovan struct exynos_drm_plane *plane)
48096976c3dSAjay Kumar {
48196976c3dSAjay Kumar struct decon_context *ctx = crtc->ctx;
48240bdfb0aSMarek Szyprowski unsigned int win = plane->index;
48396976c3dSAjay Kumar u32 val;
48496976c3dSAjay Kumar
485c329f667SJoonyoung Shim if (ctx->suspended)
48696976c3dSAjay Kumar return;
48796976c3dSAjay Kumar
48896976c3dSAjay Kumar /* protect windows */
48996976c3dSAjay Kumar decon_shadow_protect_win(ctx, win, true);
49096976c3dSAjay Kumar
49196976c3dSAjay Kumar /* wincon */
49296976c3dSAjay Kumar val = readl(ctx->regs + WINCON(win));
49396976c3dSAjay Kumar val &= ~WINCONx_ENWIN;
49496976c3dSAjay Kumar writel(val, ctx->regs + WINCON(win));
49596976c3dSAjay Kumar
49696976c3dSAjay Kumar val = readl(ctx->regs + DECON_UPDATE);
49796976c3dSAjay Kumar val |= DECON_UPDATE_STANDALONE_F;
49896976c3dSAjay Kumar writel(val, ctx->regs + DECON_UPDATE);
49996976c3dSAjay Kumar }
50096976c3dSAjay Kumar
decon_atomic_flush(struct exynos_drm_crtc * crtc)501d29c2c14SMarek Szyprowski static void decon_atomic_flush(struct exynos_drm_crtc *crtc)
502cc5a7b35SHyungwon Hwang {
503cc5a7b35SHyungwon Hwang struct decon_context *ctx = crtc->ctx;
504d29c2c14SMarek Szyprowski int i;
505cc5a7b35SHyungwon Hwang
506cc5a7b35SHyungwon Hwang if (ctx->suspended)
507cc5a7b35SHyungwon Hwang return;
508cc5a7b35SHyungwon Hwang
509d29c2c14SMarek Szyprowski for (i = 0; i < WINDOWS_NR; i++)
510d29c2c14SMarek Szyprowski decon_shadow_protect_win(ctx, i, false);
511a392276dSAndrzej Hajda exynos_crtc_handle_event(crtc);
512cc5a7b35SHyungwon Hwang }
513cc5a7b35SHyungwon Hwang
decon_init(struct decon_context * ctx)51496976c3dSAjay Kumar static void decon_init(struct decon_context *ctx)
51596976c3dSAjay Kumar {
51696976c3dSAjay Kumar u32 val;
51796976c3dSAjay Kumar
51896976c3dSAjay Kumar writel(VIDCON0_SWRESET, ctx->regs + VIDCON0);
51996976c3dSAjay Kumar
52096976c3dSAjay Kumar val = VIDOUTCON0_DISP_IF_0_ON;
52196976c3dSAjay Kumar if (!ctx->i80_if)
52296976c3dSAjay Kumar val |= VIDOUTCON0_RGBIF;
52396976c3dSAjay Kumar writel(val, ctx->regs + VIDOUTCON0);
52496976c3dSAjay Kumar
52596976c3dSAjay Kumar writel(VCLKCON0_CLKVALUP | VCLKCON0_VCLKFREE, ctx->regs + VCLKCON0);
52696976c3dSAjay Kumar
52796976c3dSAjay Kumar if (!ctx->i80_if)
52896976c3dSAjay Kumar writel(VIDCON1_VCLK_HOLD, ctx->regs + VIDCON1(0));
52996976c3dSAjay Kumar }
53096976c3dSAjay Kumar
decon_atomic_enable(struct exynos_drm_crtc * crtc)53111f95489SInki Dae static void decon_atomic_enable(struct exynos_drm_crtc *crtc)
53296976c3dSAjay Kumar {
5333cecda03SGustavo Padovan struct decon_context *ctx = crtc->ctx;
534445d3bedSInki Dae int ret;
53596976c3dSAjay Kumar
53696976c3dSAjay Kumar if (!ctx->suspended)
5373cecda03SGustavo Padovan return;
53896976c3dSAjay Kumar
539445d3bedSInki Dae ret = pm_runtime_resume_and_get(ctx->dev);
540445d3bedSInki Dae if (ret < 0) {
541445d3bedSInki Dae DRM_DEV_ERROR(ctx->dev, "failed to enable DECON device.\n");
542445d3bedSInki Dae return;
543445d3bedSInki Dae }
54496976c3dSAjay Kumar
54596976c3dSAjay Kumar decon_init(ctx);
54696976c3dSAjay Kumar
54796976c3dSAjay Kumar /* if vblank was enabled status, enable it again. */
5483cecda03SGustavo Padovan if (test_and_clear_bit(0, &ctx->irq_flags))
5493cecda03SGustavo Padovan decon_enable_vblank(ctx->crtc);
55096976c3dSAjay Kumar
551c329f667SJoonyoung Shim decon_commit(ctx->crtc);
552681c801eSGustavo Padovan
553681c801eSGustavo Padovan ctx->suspended = false;
55496976c3dSAjay Kumar }
55596976c3dSAjay Kumar
decon_atomic_disable(struct exynos_drm_crtc * crtc)55611f95489SInki Dae static void decon_atomic_disable(struct exynos_drm_crtc *crtc)
55796976c3dSAjay Kumar {
5583cecda03SGustavo Padovan struct decon_context *ctx = crtc->ctx;
559c329f667SJoonyoung Shim int i;
5603cecda03SGustavo Padovan
56196976c3dSAjay Kumar if (ctx->suspended)
5623cecda03SGustavo Padovan return;
56396976c3dSAjay Kumar
56496976c3dSAjay Kumar /*
56596976c3dSAjay Kumar * We need to make sure that all windows are disabled before we
56696976c3dSAjay Kumar * suspend that connector. Otherwise we might try to scan from
56796976c3dSAjay Kumar * a destroyed buffer later.
56896976c3dSAjay Kumar */
569c329f667SJoonyoung Shim for (i = 0; i < WINDOWS_NR; i++)
5701e1d1393SGustavo Padovan decon_disable_plane(crtc, &ctx->planes[i]);
57196976c3dSAjay Kumar
57296976c3dSAjay Kumar pm_runtime_put_sync(ctx->dev);
57396976c3dSAjay Kumar
57496976c3dSAjay Kumar ctx->suspended = true;
57596976c3dSAjay Kumar }
57696976c3dSAjay Kumar
577f3aaf762SKrzysztof Kozlowski static const struct exynos_drm_crtc_ops decon_crtc_ops = {
57811f95489SInki Dae .atomic_enable = decon_atomic_enable,
57911f95489SInki Dae .atomic_disable = decon_atomic_disable,
58096976c3dSAjay Kumar .enable_vblank = decon_enable_vblank,
58196976c3dSAjay Kumar .disable_vblank = decon_disable_vblank,
582cc5a7b35SHyungwon Hwang .atomic_begin = decon_atomic_begin,
5839cc7610aSGustavo Padovan .update_plane = decon_update_plane,
5849cc7610aSGustavo Padovan .disable_plane = decon_disable_plane,
585cc5a7b35SHyungwon Hwang .atomic_flush = decon_atomic_flush,
58696976c3dSAjay Kumar };
58796976c3dSAjay Kumar
58896976c3dSAjay Kumar
decon_irq_handler(int irq,void * dev_id)58996976c3dSAjay Kumar static irqreturn_t decon_irq_handler(int irq, void *dev_id)
59096976c3dSAjay Kumar {
59196976c3dSAjay Kumar struct decon_context *ctx = (struct decon_context *)dev_id;
59296976c3dSAjay Kumar u32 val, clear_bit;
59396976c3dSAjay Kumar
59496976c3dSAjay Kumar val = readl(ctx->regs + VIDINTCON1);
59596976c3dSAjay Kumar
59696976c3dSAjay Kumar clear_bit = ctx->i80_if ? VIDINTCON1_INT_I80 : VIDINTCON1_INT_FRAME;
59796976c3dSAjay Kumar if (val & clear_bit)
59896976c3dSAjay Kumar writel(clear_bit, ctx->regs + VIDINTCON1);
59996976c3dSAjay Kumar
60096976c3dSAjay Kumar /* check the crtc is detached already from encoder */
6012949390eSAndrzej Hajda if (!ctx->drm_dev)
60296976c3dSAjay Kumar goto out;
60396976c3dSAjay Kumar
60496976c3dSAjay Kumar if (!ctx->i80_if) {
605eafd540aSGustavo Padovan drm_crtc_handle_vblank(&ctx->crtc->base);
60696976c3dSAjay Kumar
60796976c3dSAjay Kumar /* set wait vsync event to zero and wake up queue. */
60896976c3dSAjay Kumar if (atomic_read(&ctx->wait_vsync_event)) {
60996976c3dSAjay Kumar atomic_set(&ctx->wait_vsync_event, 0);
61096976c3dSAjay Kumar wake_up(&ctx->wait_vsync_queue);
61196976c3dSAjay Kumar }
61296976c3dSAjay Kumar }
61396976c3dSAjay Kumar out:
61496976c3dSAjay Kumar return IRQ_HANDLED;
61596976c3dSAjay Kumar }
61696976c3dSAjay Kumar
decon_bind(struct device * dev,struct device * master,void * data)61796976c3dSAjay Kumar static int decon_bind(struct device *dev, struct device *master, void *data)
61896976c3dSAjay Kumar {
61996976c3dSAjay Kumar struct decon_context *ctx = dev_get_drvdata(dev);
62096976c3dSAjay Kumar struct drm_device *drm_dev = data;
6217ee14cdcSGustavo Padovan struct exynos_drm_plane *exynos_plane;
622fd2d2fc2SMarek Szyprowski unsigned int i;
6236e2a3b66SGustavo Padovan int ret;
62496976c3dSAjay Kumar
62596976c3dSAjay Kumar ret = decon_ctx_initialize(ctx, drm_dev);
62696976c3dSAjay Kumar if (ret) {
6276f83d208SInki Dae DRM_DEV_ERROR(dev, "decon_ctx_initialize failed.\n");
62896976c3dSAjay Kumar return ret;
62996976c3dSAjay Kumar }
63096976c3dSAjay Kumar
631fd2d2fc2SMarek Szyprowski for (i = 0; i < WINDOWS_NR; i++) {
632fd2d2fc2SMarek Szyprowski ctx->configs[i].pixel_formats = decon_formats;
633fd2d2fc2SMarek Szyprowski ctx->configs[i].num_pixel_formats = ARRAY_SIZE(decon_formats);
634fd2d2fc2SMarek Szyprowski ctx->configs[i].zpos = i;
635fd2d2fc2SMarek Szyprowski ctx->configs[i].type = decon_win_types[i];
636fd2d2fc2SMarek Szyprowski
63740bdfb0aSMarek Szyprowski ret = exynos_plane_init(drm_dev, &ctx->planes[i], i,
6382c82607bSAndrzej Hajda &ctx->configs[i]);
6397ee14cdcSGustavo Padovan if (ret)
6407ee14cdcSGustavo Padovan return ret;
6417ee14cdcSGustavo Padovan }
6427ee14cdcSGustavo Padovan
6435d3d0995SGustavo Padovan exynos_plane = &ctx->planes[DEFAULT_WIN];
6447ee14cdcSGustavo Padovan ctx->crtc = exynos_drm_crtc_create(drm_dev, &exynos_plane->base,
645d644951cSAndrzej Hajda EXYNOS_DISPLAY_TYPE_LCD, &decon_crtc_ops, ctx);
64696976c3dSAjay Kumar if (IS_ERR(ctx->crtc)) {
64796976c3dSAjay Kumar decon_ctx_remove(ctx);
64896976c3dSAjay Kumar return PTR_ERR(ctx->crtc);
64996976c3dSAjay Kumar }
65096976c3dSAjay Kumar
651cf67cc9aSGustavo Padovan if (ctx->encoder)
652a2986e80SGustavo Padovan exynos_dpi_bind(drm_dev, ctx->encoder);
65396976c3dSAjay Kumar
65496976c3dSAjay Kumar return 0;
65596976c3dSAjay Kumar
65696976c3dSAjay Kumar }
65796976c3dSAjay Kumar
decon_unbind(struct device * dev,struct device * master,void * data)65896976c3dSAjay Kumar static void decon_unbind(struct device *dev, struct device *master,
65996976c3dSAjay Kumar void *data)
66096976c3dSAjay Kumar {
66196976c3dSAjay Kumar struct decon_context *ctx = dev_get_drvdata(dev);
66296976c3dSAjay Kumar
66311f95489SInki Dae decon_atomic_disable(ctx->crtc);
66496976c3dSAjay Kumar
665cf67cc9aSGustavo Padovan if (ctx->encoder)
666cf67cc9aSGustavo Padovan exynos_dpi_remove(ctx->encoder);
66796976c3dSAjay Kumar
66896976c3dSAjay Kumar decon_ctx_remove(ctx);
66996976c3dSAjay Kumar }
67096976c3dSAjay Kumar
67196976c3dSAjay Kumar static const struct component_ops decon_component_ops = {
67296976c3dSAjay Kumar .bind = decon_bind,
67396976c3dSAjay Kumar .unbind = decon_unbind,
67496976c3dSAjay Kumar };
67596976c3dSAjay Kumar
decon_probe(struct platform_device * pdev)67696976c3dSAjay Kumar static int decon_probe(struct platform_device *pdev)
67796976c3dSAjay Kumar {
67896976c3dSAjay Kumar struct device *dev = &pdev->dev;
67996976c3dSAjay Kumar struct decon_context *ctx;
68096976c3dSAjay Kumar struct device_node *i80_if_timings;
68196976c3dSAjay Kumar int ret;
68296976c3dSAjay Kumar
68396976c3dSAjay Kumar if (!dev->of_node)
68496976c3dSAjay Kumar return -ENODEV;
68596976c3dSAjay Kumar
68696976c3dSAjay Kumar ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
68796976c3dSAjay Kumar if (!ctx)
68896976c3dSAjay Kumar return -ENOMEM;
68996976c3dSAjay Kumar
69096976c3dSAjay Kumar ctx->dev = dev;
69196976c3dSAjay Kumar ctx->suspended = true;
69296976c3dSAjay Kumar
69396976c3dSAjay Kumar i80_if_timings = of_get_child_by_name(dev->of_node, "i80-if-timings");
69496976c3dSAjay Kumar if (i80_if_timings)
69596976c3dSAjay Kumar ctx->i80_if = true;
69696976c3dSAjay Kumar of_node_put(i80_if_timings);
69796976c3dSAjay Kumar
69896976c3dSAjay Kumar ctx->regs = of_iomap(dev->of_node, 0);
69986650408SAndrzej Hajda if (!ctx->regs)
70086650408SAndrzej Hajda return -ENOMEM;
70196976c3dSAjay Kumar
70296976c3dSAjay Kumar ctx->pclk = devm_clk_get(dev, "pclk_decon0");
70396976c3dSAjay Kumar if (IS_ERR(ctx->pclk)) {
70496976c3dSAjay Kumar dev_err(dev, "failed to get bus clock pclk\n");
70596976c3dSAjay Kumar ret = PTR_ERR(ctx->pclk);
70696976c3dSAjay Kumar goto err_iounmap;
70796976c3dSAjay Kumar }
70896976c3dSAjay Kumar
70996976c3dSAjay Kumar ctx->aclk = devm_clk_get(dev, "aclk_decon0");
71096976c3dSAjay Kumar if (IS_ERR(ctx->aclk)) {
71196976c3dSAjay Kumar dev_err(dev, "failed to get bus clock aclk\n");
71296976c3dSAjay Kumar ret = PTR_ERR(ctx->aclk);
71396976c3dSAjay Kumar goto err_iounmap;
71496976c3dSAjay Kumar }
71596976c3dSAjay Kumar
71696976c3dSAjay Kumar ctx->eclk = devm_clk_get(dev, "decon0_eclk");
71796976c3dSAjay Kumar if (IS_ERR(ctx->eclk)) {
71896976c3dSAjay Kumar dev_err(dev, "failed to get eclock\n");
71996976c3dSAjay Kumar ret = PTR_ERR(ctx->eclk);
72096976c3dSAjay Kumar goto err_iounmap;
72196976c3dSAjay Kumar }
72296976c3dSAjay Kumar
72396976c3dSAjay Kumar ctx->vclk = devm_clk_get(dev, "decon0_vclk");
72496976c3dSAjay Kumar if (IS_ERR(ctx->vclk)) {
72596976c3dSAjay Kumar dev_err(dev, "failed to get vclock\n");
72696976c3dSAjay Kumar ret = PTR_ERR(ctx->vclk);
72796976c3dSAjay Kumar goto err_iounmap;
72896976c3dSAjay Kumar }
72996976c3dSAjay Kumar
7300d22b031SLad Prabhakar ret = platform_get_irq_byname(pdev, ctx->i80_if ? "lcd_sys" : "vsync");
7310d22b031SLad Prabhakar if (ret < 0)
73296976c3dSAjay Kumar goto err_iounmap;
73396976c3dSAjay Kumar
7340d22b031SLad Prabhakar ret = devm_request_irq(dev, ret, decon_irq_handler, 0, "drm_decon", ctx);
73596976c3dSAjay Kumar if (ret) {
73696976c3dSAjay Kumar dev_err(dev, "irq request failed.\n");
73796976c3dSAjay Kumar goto err_iounmap;
73896976c3dSAjay Kumar }
73996976c3dSAjay Kumar
74096976c3dSAjay Kumar init_waitqueue_head(&ctx->wait_vsync_queue);
74196976c3dSAjay Kumar atomic_set(&ctx->wait_vsync_event, 0);
74296976c3dSAjay Kumar
74396976c3dSAjay Kumar platform_set_drvdata(pdev, ctx);
74496976c3dSAjay Kumar
745cf67cc9aSGustavo Padovan ctx->encoder = exynos_dpi_probe(dev);
746cf67cc9aSGustavo Padovan if (IS_ERR(ctx->encoder)) {
747cf67cc9aSGustavo Padovan ret = PTR_ERR(ctx->encoder);
74896976c3dSAjay Kumar goto err_iounmap;
74996976c3dSAjay Kumar }
75096976c3dSAjay Kumar
75196976c3dSAjay Kumar pm_runtime_enable(dev);
75296976c3dSAjay Kumar
75396976c3dSAjay Kumar ret = component_add(dev, &decon_component_ops);
75496976c3dSAjay Kumar if (ret)
75596976c3dSAjay Kumar goto err_disable_pm_runtime;
75696976c3dSAjay Kumar
75796976c3dSAjay Kumar return ret;
75896976c3dSAjay Kumar
75996976c3dSAjay Kumar err_disable_pm_runtime:
76096976c3dSAjay Kumar pm_runtime_disable(dev);
76196976c3dSAjay Kumar
76296976c3dSAjay Kumar err_iounmap:
76396976c3dSAjay Kumar iounmap(ctx->regs);
76496976c3dSAjay Kumar
76596976c3dSAjay Kumar return ret;
76696976c3dSAjay Kumar }
76796976c3dSAjay Kumar
decon_remove(struct platform_device * pdev)768*4fe7a1ecSUwe Kleine-König static void decon_remove(struct platform_device *pdev)
76996976c3dSAjay Kumar {
77096976c3dSAjay Kumar struct decon_context *ctx = dev_get_drvdata(&pdev->dev);
77196976c3dSAjay Kumar
77296976c3dSAjay Kumar pm_runtime_disable(&pdev->dev);
77396976c3dSAjay Kumar
77496976c3dSAjay Kumar iounmap(ctx->regs);
77596976c3dSAjay Kumar
77696976c3dSAjay Kumar component_del(&pdev->dev, &decon_component_ops);
77796976c3dSAjay Kumar }
77896976c3dSAjay Kumar
exynos7_decon_suspend(struct device * dev)779681c801eSGustavo Padovan static int exynos7_decon_suspend(struct device *dev)
780681c801eSGustavo Padovan {
781681c801eSGustavo Padovan struct decon_context *ctx = dev_get_drvdata(dev);
782681c801eSGustavo Padovan
783681c801eSGustavo Padovan clk_disable_unprepare(ctx->vclk);
784681c801eSGustavo Padovan clk_disable_unprepare(ctx->eclk);
785681c801eSGustavo Padovan clk_disable_unprepare(ctx->aclk);
786681c801eSGustavo Padovan clk_disable_unprepare(ctx->pclk);
787681c801eSGustavo Padovan
788681c801eSGustavo Padovan return 0;
789681c801eSGustavo Padovan }
790681c801eSGustavo Padovan
exynos7_decon_resume(struct device * dev)791681c801eSGustavo Padovan static int exynos7_decon_resume(struct device *dev)
792681c801eSGustavo Padovan {
793681c801eSGustavo Padovan struct decon_context *ctx = dev_get_drvdata(dev);
794681c801eSGustavo Padovan int ret;
795681c801eSGustavo Padovan
796681c801eSGustavo Padovan ret = clk_prepare_enable(ctx->pclk);
797681c801eSGustavo Padovan if (ret < 0) {
7986f83d208SInki Dae DRM_DEV_ERROR(dev, "Failed to prepare_enable the pclk [%d]\n",
7996f83d208SInki Dae ret);
80048b92777SJian Zhang goto err_pclk_enable;
801681c801eSGustavo Padovan }
802681c801eSGustavo Padovan
803681c801eSGustavo Padovan ret = clk_prepare_enable(ctx->aclk);
804681c801eSGustavo Padovan if (ret < 0) {
8056f83d208SInki Dae DRM_DEV_ERROR(dev, "Failed to prepare_enable the aclk [%d]\n",
8066f83d208SInki Dae ret);
80748b92777SJian Zhang goto err_aclk_enable;
808681c801eSGustavo Padovan }
809681c801eSGustavo Padovan
810681c801eSGustavo Padovan ret = clk_prepare_enable(ctx->eclk);
811681c801eSGustavo Padovan if (ret < 0) {
8126f83d208SInki Dae DRM_DEV_ERROR(dev, "Failed to prepare_enable the eclk [%d]\n",
8136f83d208SInki Dae ret);
81448b92777SJian Zhang goto err_eclk_enable;
815681c801eSGustavo Padovan }
816681c801eSGustavo Padovan
817681c801eSGustavo Padovan ret = clk_prepare_enable(ctx->vclk);
818681c801eSGustavo Padovan if (ret < 0) {
8196f83d208SInki Dae DRM_DEV_ERROR(dev, "Failed to prepare_enable the vclk [%d]\n",
8206f83d208SInki Dae ret);
82148b92777SJian Zhang goto err_vclk_enable;
822681c801eSGustavo Padovan }
823681c801eSGustavo Padovan
824681c801eSGustavo Padovan return 0;
82548b92777SJian Zhang
82648b92777SJian Zhang err_vclk_enable:
82748b92777SJian Zhang clk_disable_unprepare(ctx->eclk);
82848b92777SJian Zhang err_eclk_enable:
82948b92777SJian Zhang clk_disable_unprepare(ctx->aclk);
83048b92777SJian Zhang err_aclk_enable:
83148b92777SJian Zhang clk_disable_unprepare(ctx->pclk);
83248b92777SJian Zhang err_pclk_enable:
83348b92777SJian Zhang return ret;
834681c801eSGustavo Padovan }
835681c801eSGustavo Padovan
8361d9e6664SPaul Cercueil static DEFINE_RUNTIME_DEV_PM_OPS(exynos7_decon_pm_ops, exynos7_decon_suspend,
8371d9e6664SPaul Cercueil exynos7_decon_resume, NULL);
838681c801eSGustavo Padovan
83996976c3dSAjay Kumar struct platform_driver decon_driver = {
84096976c3dSAjay Kumar .probe = decon_probe,
841*4fe7a1ecSUwe Kleine-König .remove_new = decon_remove,
84296976c3dSAjay Kumar .driver = {
84396976c3dSAjay Kumar .name = "exynos-decon",
8441d9e6664SPaul Cercueil .pm = pm_ptr(&exynos7_decon_pm_ops),
84596976c3dSAjay Kumar .of_match_table = decon_driver_dt_match,
84696976c3dSAjay Kumar },
84796976c3dSAjay Kumar };
848