Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 1 | /* drivers/gpu/drm/exynos5433_drm_decon.c |
| 2 | * |
| 3 | * Copyright (C) 2015 Samsung Electronics Co.Ltd |
| 4 | * Authors: |
| 5 | * Joonyoung Shim <jy0922.shim@samsung.com> |
| 6 | * Hyungwon Hwang <human.hwang@samsung.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundationr |
| 11 | */ |
| 12 | |
| 13 | #include <linux/platform_device.h> |
| 14 | #include <linux/clk.h> |
| 15 | #include <linux/component.h> |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 16 | #include <linux/of_device.h> |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 17 | #include <linux/of_gpio.h> |
| 18 | #include <linux/pm_runtime.h> |
| 19 | |
| 20 | #include <video/exynos5433_decon.h> |
| 21 | |
| 22 | #include "exynos_drm_drv.h" |
| 23 | #include "exynos_drm_crtc.h" |
Marek Szyprowski | 0488f50 | 2015-11-30 14:53:21 +0100 | [diff] [blame] | 24 | #include "exynos_drm_fb.h" |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 25 | #include "exynos_drm_plane.h" |
| 26 | #include "exynos_drm_iommu.h" |
| 27 | |
| 28 | #define WINDOWS_NR 3 |
| 29 | #define MIN_FB_WIDTH_FOR_16WORD_BURST 128 |
| 30 | |
Inki Dae | 9ac26de | 2016-04-18 17:59:01 +0900 | [diff] [blame] | 31 | #define IFTYPE_I80 (1 << 0) |
| 32 | #define I80_HW_TRG (1 << 1) |
| 33 | #define IFTYPE_HDMI (1 << 2) |
| 34 | |
Andrzej Hajda | 4f54f21c | 2015-10-20 11:22:34 +0200 | [diff] [blame] | 35 | static const char * const decon_clks_name[] = { |
| 36 | "pclk", |
| 37 | "aclk_decon", |
| 38 | "aclk_smmu_decon0x", |
| 39 | "aclk_xiu_decon0x", |
| 40 | "pclk_smmu_decon0x", |
| 41 | "sclk_decon_vclk", |
| 42 | "sclk_decon_eclk", |
| 43 | }; |
| 44 | |
Andrzej Hajda | 7b6bb6e | 2015-10-20 11:22:38 +0200 | [diff] [blame] | 45 | enum decon_flag_bits { |
| 46 | BIT_CLKS_ENABLED, |
| 47 | BIT_IRQS_ENABLED, |
| 48 | BIT_WIN_UPDATED, |
| 49 | BIT_SUSPENDED |
| 50 | }; |
| 51 | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 52 | struct decon_context { |
| 53 | struct device *dev; |
| 54 | struct drm_device *drm_dev; |
| 55 | struct exynos_drm_crtc *crtc; |
| 56 | struct exynos_drm_plane planes[WINDOWS_NR]; |
Marek Szyprowski | fd2d2fc | 2015-11-30 14:53:25 +0100 | [diff] [blame] | 57 | struct exynos_drm_plane_config configs[WINDOWS_NR]; |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 58 | void __iomem *addr; |
Andrzej Hajda | 4f54f21c | 2015-10-20 11:22:34 +0200 | [diff] [blame] | 59 | struct clk *clks[ARRAY_SIZE(decon_clks_name)]; |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 60 | int pipe; |
Andrzej Hajda | 7b6bb6e | 2015-10-20 11:22:38 +0200 | [diff] [blame] | 61 | unsigned long flags; |
Inki Dae | 9ac26de | 2016-04-18 17:59:01 +0900 | [diff] [blame] | 62 | unsigned long out_type; |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 63 | int first_win; |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 64 | }; |
| 65 | |
Marek Szyprowski | fbbb1e1 | 2015-08-31 00:53:57 +0900 | [diff] [blame] | 66 | static const uint32_t decon_formats[] = { |
| 67 | DRM_FORMAT_XRGB1555, |
| 68 | DRM_FORMAT_RGB565, |
| 69 | DRM_FORMAT_XRGB8888, |
| 70 | DRM_FORMAT_ARGB8888, |
| 71 | }; |
| 72 | |
Marek Szyprowski | fd2d2fc | 2015-11-30 14:53:25 +0100 | [diff] [blame] | 73 | static const enum drm_plane_type decon_win_types[WINDOWS_NR] = { |
| 74 | DRM_PLANE_TYPE_PRIMARY, |
| 75 | DRM_PLANE_TYPE_OVERLAY, |
| 76 | DRM_PLANE_TYPE_CURSOR, |
| 77 | }; |
| 78 | |
Andrzej Hajda | b219207 | 2015-10-20 11:22:37 +0200 | [diff] [blame] | 79 | static inline void decon_set_bits(struct decon_context *ctx, u32 reg, u32 mask, |
| 80 | u32 val) |
| 81 | { |
| 82 | val = (val & mask) | (readl(ctx->addr + reg) & ~mask); |
| 83 | writel(val, ctx->addr + reg); |
| 84 | } |
| 85 | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 86 | static int decon_enable_vblank(struct exynos_drm_crtc *crtc) |
| 87 | { |
| 88 | struct decon_context *ctx = crtc->ctx; |
| 89 | u32 val; |
| 90 | |
Andrzej Hajda | 7b6bb6e | 2015-10-20 11:22:38 +0200 | [diff] [blame] | 91 | if (test_bit(BIT_SUSPENDED, &ctx->flags)) |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 92 | return -EPERM; |
| 93 | |
Marek Szyprowski | f3fb3d8 | 2016-02-03 13:42:54 +0100 | [diff] [blame] | 94 | if (!test_and_set_bit(BIT_IRQS_ENABLED, &ctx->flags)) { |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 95 | val = VIDINTCON0_INTEN; |
Inki Dae | 9ac26de | 2016-04-18 17:59:01 +0900 | [diff] [blame] | 96 | if (ctx->out_type & IFTYPE_I80) |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 97 | val |= VIDINTCON0_FRAMEDONE; |
| 98 | else |
| 99 | val |= VIDINTCON0_INTFRMEN; |
| 100 | |
| 101 | writel(val, ctx->addr + DECON_VIDINTCON0); |
| 102 | } |
| 103 | |
| 104 | return 0; |
| 105 | } |
| 106 | |
| 107 | static void decon_disable_vblank(struct exynos_drm_crtc *crtc) |
| 108 | { |
| 109 | struct decon_context *ctx = crtc->ctx; |
| 110 | |
Andrzej Hajda | 7b6bb6e | 2015-10-20 11:22:38 +0200 | [diff] [blame] | 111 | if (test_bit(BIT_SUSPENDED, &ctx->flags)) |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 112 | return; |
| 113 | |
Andrzej Hajda | 7b6bb6e | 2015-10-20 11:22:38 +0200 | [diff] [blame] | 114 | if (test_and_clear_bit(BIT_IRQS_ENABLED, &ctx->flags)) |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 115 | writel(0, ctx->addr + DECON_VIDINTCON0); |
| 116 | } |
| 117 | |
| 118 | static void decon_setup_trigger(struct decon_context *ctx) |
| 119 | { |
Inki Dae | 9ac26de | 2016-04-18 17:59:01 +0900 | [diff] [blame] | 120 | u32 val = !(ctx->out_type & I80_HW_TRG) |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 121 | ? TRIGCON_TRIGEN_PER_F | TRIGCON_TRIGEN_F | |
| 122 | TRIGCON_TE_AUTO_MASK | TRIGCON_SWTRIGEN |
| 123 | : TRIGCON_TRIGEN_PER_F | TRIGCON_TRIGEN_F | |
Inki Dae | b5bf0f1 | 2016-04-12 09:59:11 +0900 | [diff] [blame] | 124 | TRIGCON_HWTRIGMASK | TRIGCON_HWTRIGEN; |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 125 | writel(val, ctx->addr + DECON_TRIGCON); |
| 126 | } |
| 127 | |
| 128 | static void decon_commit(struct exynos_drm_crtc *crtc) |
| 129 | { |
| 130 | struct decon_context *ctx = crtc->ctx; |
Andrzej Hajda | 85de275 | 2015-10-20 11:22:36 +0200 | [diff] [blame] | 131 | struct drm_display_mode *m = &crtc->base.mode; |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 132 | u32 val; |
| 133 | |
Andrzej Hajda | 7b6bb6e | 2015-10-20 11:22:38 +0200 | [diff] [blame] | 134 | if (test_bit(BIT_SUSPENDED, &ctx->flags)) |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 135 | return; |
| 136 | |
Inki Dae | 9ac26de | 2016-04-18 17:59:01 +0900 | [diff] [blame] | 137 | if (ctx->out_type & IFTYPE_HDMI) { |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 138 | m->crtc_hsync_start = m->crtc_hdisplay + 10; |
| 139 | m->crtc_hsync_end = m->crtc_htotal - 92; |
| 140 | m->crtc_vsync_start = m->crtc_vdisplay + 1; |
| 141 | m->crtc_vsync_end = m->crtc_vsync_start + 1; |
| 142 | } |
| 143 | |
| 144 | decon_set_bits(ctx, DECON_VIDCON0, VIDCON0_ENVID, 0); |
| 145 | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 146 | /* enable clock gate */ |
| 147 | val = CMU_CLKGAGE_MODE_SFR_F | CMU_CLKGAGE_MODE_MEM_F; |
| 148 | writel(val, ctx->addr + DECON_CMU); |
| 149 | |
Andrzej Hajda | dd65a68 | 2016-04-29 15:42:49 +0200 | [diff] [blame] | 150 | if (ctx->out_type & (IFTYPE_I80 | I80_HW_TRG)) |
| 151 | decon_setup_trigger(ctx); |
| 152 | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 153 | /* lcd on and use command if */ |
| 154 | val = VIDOUT_LCD_ON; |
Inki Dae | 9ac26de | 2016-04-18 17:59:01 +0900 | [diff] [blame] | 155 | if (ctx->out_type & IFTYPE_I80) { |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 156 | val |= VIDOUT_COMMAND_IF; |
Inki Dae | 9ac26de | 2016-04-18 17:59:01 +0900 | [diff] [blame] | 157 | } else { |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 158 | val |= VIDOUT_RGB_IF; |
Inki Dae | 9ac26de | 2016-04-18 17:59:01 +0900 | [diff] [blame] | 159 | } |
| 160 | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 161 | writel(val, ctx->addr + DECON_VIDOUTCON0); |
| 162 | |
Andrzej Hajda | 85de275 | 2015-10-20 11:22:36 +0200 | [diff] [blame] | 163 | val = VIDTCON2_LINEVAL(m->vdisplay - 1) | |
| 164 | VIDTCON2_HOZVAL(m->hdisplay - 1); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 165 | writel(val, ctx->addr + DECON_VIDTCON2); |
| 166 | |
Inki Dae | 9ac26de | 2016-04-18 17:59:01 +0900 | [diff] [blame] | 167 | if (!(ctx->out_type & IFTYPE_I80)) { |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 168 | val = VIDTCON00_VBPD_F( |
Andrzej Hajda | 85de275 | 2015-10-20 11:22:36 +0200 | [diff] [blame] | 169 | m->crtc_vtotal - m->crtc_vsync_end - 1) | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 170 | VIDTCON00_VFPD_F( |
Andrzej Hajda | 85de275 | 2015-10-20 11:22:36 +0200 | [diff] [blame] | 171 | m->crtc_vsync_start - m->crtc_vdisplay - 1); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 172 | writel(val, ctx->addr + DECON_VIDTCON00); |
| 173 | |
| 174 | val = VIDTCON01_VSPW_F( |
Andrzej Hajda | 85de275 | 2015-10-20 11:22:36 +0200 | [diff] [blame] | 175 | m->crtc_vsync_end - m->crtc_vsync_start - 1); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 176 | writel(val, ctx->addr + DECON_VIDTCON01); |
| 177 | |
| 178 | val = VIDTCON10_HBPD_F( |
Andrzej Hajda | 85de275 | 2015-10-20 11:22:36 +0200 | [diff] [blame] | 179 | m->crtc_htotal - m->crtc_hsync_end - 1) | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 180 | VIDTCON10_HFPD_F( |
Andrzej Hajda | 85de275 | 2015-10-20 11:22:36 +0200 | [diff] [blame] | 181 | m->crtc_hsync_start - m->crtc_hdisplay - 1); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 182 | writel(val, ctx->addr + DECON_VIDTCON10); |
| 183 | |
| 184 | val = VIDTCON11_HSPW_F( |
Andrzej Hajda | 85de275 | 2015-10-20 11:22:36 +0200 | [diff] [blame] | 185 | m->crtc_hsync_end - m->crtc_hsync_start - 1); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 186 | writel(val, ctx->addr + DECON_VIDTCON11); |
| 187 | } |
| 188 | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 189 | /* enable output and display signal */ |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 190 | decon_set_bits(ctx, DECON_VIDCON0, VIDCON0_ENVID | VIDCON0_ENVID_F, ~0); |
Andrzej Hajda | 92ead49 | 2016-03-23 14:15:16 +0100 | [diff] [blame] | 191 | |
| 192 | decon_set_bits(ctx, DECON_UPDATE, STANDALONE_UPDATE_F, ~0); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 193 | } |
| 194 | |
Gustavo Padovan | 2eeb2e5 | 2015-08-03 14:40:44 +0900 | [diff] [blame] | 195 | static void decon_win_set_pixfmt(struct decon_context *ctx, unsigned int win, |
| 196 | struct drm_framebuffer *fb) |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 197 | { |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 198 | unsigned long val; |
| 199 | |
| 200 | val = readl(ctx->addr + DECON_WINCONx(win)); |
| 201 | val &= ~WINCONx_BPPMODE_MASK; |
| 202 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 203 | switch (fb->format->format) { |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 204 | case DRM_FORMAT_XRGB1555: |
| 205 | val |= WINCONx_BPPMODE_16BPP_I1555; |
| 206 | val |= WINCONx_HAWSWP_F; |
| 207 | val |= WINCONx_BURSTLEN_16WORD; |
| 208 | break; |
| 209 | case DRM_FORMAT_RGB565: |
| 210 | val |= WINCONx_BPPMODE_16BPP_565; |
| 211 | val |= WINCONx_HAWSWP_F; |
| 212 | val |= WINCONx_BURSTLEN_16WORD; |
| 213 | break; |
| 214 | case DRM_FORMAT_XRGB8888: |
| 215 | val |= WINCONx_BPPMODE_24BPP_888; |
| 216 | val |= WINCONx_WSWP_F; |
| 217 | val |= WINCONx_BURSTLEN_16WORD; |
| 218 | break; |
| 219 | case DRM_FORMAT_ARGB8888: |
| 220 | val |= WINCONx_BPPMODE_32BPP_A8888; |
| 221 | val |= WINCONx_WSWP_F | WINCONx_BLD_PIX_F | WINCONx_ALPHA_SEL_F; |
| 222 | val |= WINCONx_BURSTLEN_16WORD; |
| 223 | break; |
| 224 | default: |
| 225 | DRM_ERROR("Proper pixel format is not set\n"); |
| 226 | return; |
| 227 | } |
| 228 | |
Ville Syrjälä | 272725c | 2016-12-14 23:32:20 +0200 | [diff] [blame] | 229 | DRM_DEBUG_KMS("bpp = %u\n", fb->format->cpp[0] * 8); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 230 | |
| 231 | /* |
| 232 | * In case of exynos, setting dma-burst to 16Word causes permanent |
| 233 | * tearing for very small buffers, e.g. cursor buffer. Burst Mode |
| 234 | * switching which is based on plane size is not recommended as |
| 235 | * plane size varies a lot towards the end of the screen and rapid |
| 236 | * movement causes unstable DMA which results into iommu crash/tear. |
| 237 | */ |
| 238 | |
Gustavo Padovan | 2eeb2e5 | 2015-08-03 14:40:44 +0900 | [diff] [blame] | 239 | if (fb->width < MIN_FB_WIDTH_FOR_16WORD_BURST) { |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 240 | val &= ~WINCONx_BURSTLEN_MASK; |
| 241 | val |= WINCONx_BURSTLEN_8WORD; |
| 242 | } |
| 243 | |
| 244 | writel(val, ctx->addr + DECON_WINCONx(win)); |
| 245 | } |
| 246 | |
| 247 | static void decon_shadow_protect_win(struct decon_context *ctx, int win, |
| 248 | bool protect) |
| 249 | { |
Andrzej Hajda | b219207 | 2015-10-20 11:22:37 +0200 | [diff] [blame] | 250 | decon_set_bits(ctx, DECON_SHADOWCON, SHADOWCON_Wx_PROTECT(win), |
| 251 | protect ? ~0 : 0); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 252 | } |
| 253 | |
Marek Szyprowski | d29c2c1 | 2016-01-05 13:52:51 +0100 | [diff] [blame] | 254 | static void decon_atomic_begin(struct exynos_drm_crtc *crtc) |
Hyungwon Hwang | cc5a7b3 | 2015-08-27 18:21:14 +0900 | [diff] [blame] | 255 | { |
| 256 | struct decon_context *ctx = crtc->ctx; |
Marek Szyprowski | d29c2c1 | 2016-01-05 13:52:51 +0100 | [diff] [blame] | 257 | int i; |
Hyungwon Hwang | cc5a7b3 | 2015-08-27 18:21:14 +0900 | [diff] [blame] | 258 | |
Andrzej Hajda | 7b6bb6e | 2015-10-20 11:22:38 +0200 | [diff] [blame] | 259 | if (test_bit(BIT_SUSPENDED, &ctx->flags)) |
Hyungwon Hwang | cc5a7b3 | 2015-08-27 18:21:14 +0900 | [diff] [blame] | 260 | return; |
| 261 | |
Marek Szyprowski | d29c2c1 | 2016-01-05 13:52:51 +0100 | [diff] [blame] | 262 | for (i = ctx->first_win; i < WINDOWS_NR; i++) |
| 263 | decon_shadow_protect_win(ctx, i, true); |
Hyungwon Hwang | cc5a7b3 | 2015-08-27 18:21:14 +0900 | [diff] [blame] | 264 | } |
| 265 | |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 266 | #define BIT_VAL(x, e, s) (((x) & ((1 << ((e) - (s) + 1)) - 1)) << (s)) |
| 267 | #define COORDINATE_X(x) BIT_VAL((x), 23, 12) |
| 268 | #define COORDINATE_Y(x) BIT_VAL((x), 11, 0) |
| 269 | |
Gustavo Padovan | 1e1d139 | 2015-08-03 14:39:36 +0900 | [diff] [blame] | 270 | static void decon_update_plane(struct exynos_drm_crtc *crtc, |
| 271 | struct exynos_drm_plane *plane) |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 272 | { |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 273 | struct exynos_drm_plane_state *state = |
| 274 | to_exynos_plane_state(plane->base.state); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 275 | struct decon_context *ctx = crtc->ctx; |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 276 | struct drm_framebuffer *fb = state->base.fb; |
Marek Szyprowski | 40bdfb0 | 2015-12-16 13:21:42 +0100 | [diff] [blame] | 277 | unsigned int win = plane->index; |
Ville Syrjälä | 272725c | 2016-12-14 23:32:20 +0200 | [diff] [blame] | 278 | unsigned int bpp = fb->format->cpp[0]; |
Marek Szyprowski | 0488f50 | 2015-11-30 14:53:21 +0100 | [diff] [blame] | 279 | unsigned int pitch = fb->pitches[0]; |
| 280 | dma_addr_t dma_addr = exynos_drm_fb_dma_addr(fb, 0); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 281 | u32 val; |
| 282 | |
Andrzej Hajda | 7b6bb6e | 2015-10-20 11:22:38 +0200 | [diff] [blame] | 283 | if (test_bit(BIT_SUSPENDED, &ctx->flags)) |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 284 | return; |
| 285 | |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 286 | val = COORDINATE_X(state->crtc.x) | COORDINATE_Y(state->crtc.y); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 287 | writel(val, ctx->addr + DECON_VIDOSDxA(win)); |
| 288 | |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 289 | val = COORDINATE_X(state->crtc.x + state->crtc.w - 1) | |
| 290 | COORDINATE_Y(state->crtc.y + state->crtc.h - 1); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 291 | writel(val, ctx->addr + DECON_VIDOSDxB(win)); |
| 292 | |
| 293 | val = VIDOSD_Wx_ALPHA_R_F(0x0) | VIDOSD_Wx_ALPHA_G_F(0x0) | |
| 294 | VIDOSD_Wx_ALPHA_B_F(0x0); |
| 295 | writel(val, ctx->addr + DECON_VIDOSDxC(win)); |
| 296 | |
| 297 | val = VIDOSD_Wx_ALPHA_R_F(0x0) | VIDOSD_Wx_ALPHA_G_F(0x0) | |
| 298 | VIDOSD_Wx_ALPHA_B_F(0x0); |
| 299 | writel(val, ctx->addr + DECON_VIDOSDxD(win)); |
| 300 | |
Marek Szyprowski | 0488f50 | 2015-11-30 14:53:21 +0100 | [diff] [blame] | 301 | writel(dma_addr, ctx->addr + DECON_VIDW0xADD0B0(win)); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 302 | |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 303 | val = dma_addr + pitch * state->src.h; |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 304 | writel(val, ctx->addr + DECON_VIDW0xADD1B0(win)); |
| 305 | |
Inki Dae | 9ac26de | 2016-04-18 17:59:01 +0900 | [diff] [blame] | 306 | if (!(ctx->out_type & IFTYPE_HDMI)) |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 307 | val = BIT_VAL(pitch - state->crtc.w * bpp, 27, 14) |
| 308 | | BIT_VAL(state->crtc.w * bpp, 13, 0); |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 309 | else |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 310 | val = BIT_VAL(pitch - state->crtc.w * bpp, 29, 15) |
| 311 | | BIT_VAL(state->crtc.w * bpp, 14, 0); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 312 | writel(val, ctx->addr + DECON_VIDW0xADD2(win)); |
| 313 | |
Marek Szyprowski | 0488f50 | 2015-11-30 14:53:21 +0100 | [diff] [blame] | 314 | decon_win_set_pixfmt(ctx, win, fb); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 315 | |
| 316 | /* window enable */ |
Andrzej Hajda | b219207 | 2015-10-20 11:22:37 +0200 | [diff] [blame] | 317 | decon_set_bits(ctx, DECON_WINCONx(win), WINCONx_ENWIN_F, ~0); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 318 | } |
| 319 | |
Gustavo Padovan | 1e1d139 | 2015-08-03 14:39:36 +0900 | [diff] [blame] | 320 | static void decon_disable_plane(struct exynos_drm_crtc *crtc, |
| 321 | struct exynos_drm_plane *plane) |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 322 | { |
| 323 | struct decon_context *ctx = crtc->ctx; |
Marek Szyprowski | 40bdfb0 | 2015-12-16 13:21:42 +0100 | [diff] [blame] | 324 | unsigned int win = plane->index; |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 325 | |
Andrzej Hajda | 7b6bb6e | 2015-10-20 11:22:38 +0200 | [diff] [blame] | 326 | if (test_bit(BIT_SUSPENDED, &ctx->flags)) |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 327 | return; |
| 328 | |
Andrzej Hajda | b219207 | 2015-10-20 11:22:37 +0200 | [diff] [blame] | 329 | decon_set_bits(ctx, DECON_WINCONx(win), WINCONx_ENWIN_F, 0); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 330 | } |
| 331 | |
Marek Szyprowski | d29c2c1 | 2016-01-05 13:52:51 +0100 | [diff] [blame] | 332 | static void decon_atomic_flush(struct exynos_drm_crtc *crtc) |
Hyungwon Hwang | cc5a7b3 | 2015-08-27 18:21:14 +0900 | [diff] [blame] | 333 | { |
| 334 | struct decon_context *ctx = crtc->ctx; |
Marek Szyprowski | d29c2c1 | 2016-01-05 13:52:51 +0100 | [diff] [blame] | 335 | int i; |
Hyungwon Hwang | cc5a7b3 | 2015-08-27 18:21:14 +0900 | [diff] [blame] | 336 | |
Andrzej Hajda | 7b6bb6e | 2015-10-20 11:22:38 +0200 | [diff] [blame] | 337 | if (test_bit(BIT_SUSPENDED, &ctx->flags)) |
Hyungwon Hwang | cc5a7b3 | 2015-08-27 18:21:14 +0900 | [diff] [blame] | 338 | return; |
| 339 | |
Marek Szyprowski | d29c2c1 | 2016-01-05 13:52:51 +0100 | [diff] [blame] | 340 | for (i = ctx->first_win; i < WINDOWS_NR; i++) |
| 341 | decon_shadow_protect_win(ctx, i, false); |
Hyungwon Hwang | cc5a7b3 | 2015-08-27 18:21:14 +0900 | [diff] [blame] | 342 | |
Andrzej Hajda | 92ead49 | 2016-03-23 14:15:16 +0100 | [diff] [blame] | 343 | /* standalone update */ |
| 344 | decon_set_bits(ctx, DECON_UPDATE, STANDALONE_UPDATE_F, ~0); |
| 345 | |
Inki Dae | 9ac26de | 2016-04-18 17:59:01 +0900 | [diff] [blame] | 346 | if (ctx->out_type & IFTYPE_I80) |
Andrzej Hajda | 7b6bb6e | 2015-10-20 11:22:38 +0200 | [diff] [blame] | 347 | set_bit(BIT_WIN_UPDATED, &ctx->flags); |
Hyungwon Hwang | cc5a7b3 | 2015-08-27 18:21:14 +0900 | [diff] [blame] | 348 | } |
| 349 | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 350 | static void decon_swreset(struct decon_context *ctx) |
| 351 | { |
| 352 | unsigned int tries; |
| 353 | |
| 354 | writel(0, ctx->addr + DECON_VIDCON0); |
| 355 | for (tries = 2000; tries; --tries) { |
| 356 | if (~readl(ctx->addr + DECON_VIDCON0) & VIDCON0_STOP_STATUS) |
| 357 | break; |
| 358 | udelay(10); |
| 359 | } |
| 360 | |
| 361 | WARN(tries == 0, "failed to disable DECON\n"); |
| 362 | |
| 363 | writel(VIDCON0_SWRESET, ctx->addr + DECON_VIDCON0); |
| 364 | for (tries = 2000; tries; --tries) { |
| 365 | if (~readl(ctx->addr + DECON_VIDCON0) & VIDCON0_SWRESET) |
| 366 | break; |
| 367 | udelay(10); |
| 368 | } |
| 369 | |
| 370 | WARN(tries == 0, "failed to software reset DECON\n"); |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 371 | |
Inki Dae | 9ac26de | 2016-04-18 17:59:01 +0900 | [diff] [blame] | 372 | if (!(ctx->out_type & IFTYPE_HDMI)) |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 373 | return; |
| 374 | |
| 375 | writel(VIDCON0_CLKVALUP | VIDCON0_VLCKFREE, ctx->addr + DECON_VIDCON0); |
| 376 | decon_set_bits(ctx, DECON_CMU, |
| 377 | CMU_CLKGAGE_MODE_SFR_F | CMU_CLKGAGE_MODE_MEM_F, ~0); |
| 378 | writel(VIDCON1_VCLK_RUN_VDEN_DISABLE, ctx->addr + DECON_VIDCON1); |
| 379 | writel(CRCCTRL_CRCEN | CRCCTRL_CRCSTART_F | CRCCTRL_CRCCLKEN, |
| 380 | ctx->addr + DECON_CRCCTRL); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | static void decon_enable(struct exynos_drm_crtc *crtc) |
| 384 | { |
| 385 | struct decon_context *ctx = crtc->ctx; |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 386 | |
Andrzej Hajda | 7b6bb6e | 2015-10-20 11:22:38 +0200 | [diff] [blame] | 387 | if (!test_and_clear_bit(BIT_SUSPENDED, &ctx->flags)) |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 388 | return; |
| 389 | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 390 | pm_runtime_get_sync(ctx->dev); |
| 391 | |
Andrzej Hajda | c60230e | 2016-03-23 14:26:00 +0100 | [diff] [blame] | 392 | exynos_drm_pipe_clk_enable(crtc, true); |
| 393 | |
Andrzej Hajda | 7b6bb6e | 2015-10-20 11:22:38 +0200 | [diff] [blame] | 394 | set_bit(BIT_CLKS_ENABLED, &ctx->flags); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 395 | |
Andrzej Hajda | e87b3c6 | 2016-03-23 14:15:17 +0100 | [diff] [blame] | 396 | decon_swreset(ctx); |
| 397 | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 398 | /* if vblank was enabled status, enable it again. */ |
Andrzej Hajda | 7b6bb6e | 2015-10-20 11:22:38 +0200 | [diff] [blame] | 399 | if (test_and_clear_bit(BIT_IRQS_ENABLED, &ctx->flags)) |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 400 | decon_enable_vblank(ctx->crtc); |
| 401 | |
| 402 | decon_commit(ctx->crtc); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | static void decon_disable(struct exynos_drm_crtc *crtc) |
| 406 | { |
| 407 | struct decon_context *ctx = crtc->ctx; |
| 408 | int i; |
| 409 | |
Andrzej Hajda | 7b6bb6e | 2015-10-20 11:22:38 +0200 | [diff] [blame] | 410 | if (test_bit(BIT_SUSPENDED, &ctx->flags)) |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 411 | return; |
| 412 | |
| 413 | /* |
| 414 | * We need to make sure that all windows are disabled before we |
| 415 | * suspend that connector. Otherwise we might try to scan from |
| 416 | * a destroyed buffer later. |
| 417 | */ |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 418 | for (i = ctx->first_win; i < WINDOWS_NR; i++) |
Gustavo Padovan | 1e1d139 | 2015-08-03 14:39:36 +0900 | [diff] [blame] | 419 | decon_disable_plane(crtc, &ctx->planes[i]); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 420 | |
| 421 | decon_swreset(ctx); |
| 422 | |
Andrzej Hajda | 7b6bb6e | 2015-10-20 11:22:38 +0200 | [diff] [blame] | 423 | clear_bit(BIT_CLKS_ENABLED, &ctx->flags); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 424 | |
Andrzej Hajda | c60230e | 2016-03-23 14:26:00 +0100 | [diff] [blame] | 425 | exynos_drm_pipe_clk_enable(crtc, false); |
| 426 | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 427 | pm_runtime_put_sync(ctx->dev); |
| 428 | |
Andrzej Hajda | 7b6bb6e | 2015-10-20 11:22:38 +0200 | [diff] [blame] | 429 | set_bit(BIT_SUSPENDED, &ctx->flags); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 430 | } |
| 431 | |
Andrzej Hajda | 9844d6e | 2016-02-11 12:55:46 +0100 | [diff] [blame] | 432 | static void decon_te_irq_handler(struct exynos_drm_crtc *crtc) |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 433 | { |
| 434 | struct decon_context *ctx = crtc->ctx; |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 435 | |
Andrzej Hajda | 3f4c8e5 | 2016-04-29 15:42:48 +0200 | [diff] [blame] | 436 | if (!test_bit(BIT_CLKS_ENABLED, &ctx->flags) || |
| 437 | (ctx->out_type & I80_HW_TRG)) |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 438 | return; |
| 439 | |
Andrzej Hajda | 7b6bb6e | 2015-10-20 11:22:38 +0200 | [diff] [blame] | 440 | if (test_and_clear_bit(BIT_WIN_UPDATED, &ctx->flags)) |
Andrzej Hajda | b219207 | 2015-10-20 11:22:37 +0200 | [diff] [blame] | 441 | decon_set_bits(ctx, DECON_TRIGCON, TRIGCON_SWTRIGCMD, ~0); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | static void decon_clear_channels(struct exynos_drm_crtc *crtc) |
| 445 | { |
| 446 | struct decon_context *ctx = crtc->ctx; |
| 447 | int win, i, ret; |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 448 | |
| 449 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 450 | |
| 451 | for (i = 0; i < ARRAY_SIZE(decon_clks_name); i++) { |
| 452 | ret = clk_prepare_enable(ctx->clks[i]); |
| 453 | if (ret < 0) |
| 454 | goto err; |
| 455 | } |
| 456 | |
| 457 | for (win = 0; win < WINDOWS_NR; win++) { |
Andrzej Hajda | b219207 | 2015-10-20 11:22:37 +0200 | [diff] [blame] | 458 | decon_shadow_protect_win(ctx, win, true); |
| 459 | decon_set_bits(ctx, DECON_WINCONx(win), WINCONx_ENWIN_F, 0); |
| 460 | decon_shadow_protect_win(ctx, win, false); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 461 | } |
Andrzej Hajda | 92ead49 | 2016-03-23 14:15:16 +0100 | [diff] [blame] | 462 | |
| 463 | decon_set_bits(ctx, DECON_UPDATE, STANDALONE_UPDATE_F, ~0); |
| 464 | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 465 | /* TODO: wait for possible vsync */ |
| 466 | msleep(50); |
| 467 | |
| 468 | err: |
| 469 | while (--i >= 0) |
| 470 | clk_disable_unprepare(ctx->clks[i]); |
| 471 | } |
| 472 | |
Bhumika Goyal | fc36ec7 | 2017-01-09 23:24:53 +0530 | [diff] [blame^] | 473 | static const struct exynos_drm_crtc_ops decon_crtc_ops = { |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 474 | .enable = decon_enable, |
| 475 | .disable = decon_disable, |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 476 | .enable_vblank = decon_enable_vblank, |
| 477 | .disable_vblank = decon_disable_vblank, |
Hyungwon Hwang | cc5a7b3 | 2015-08-27 18:21:14 +0900 | [diff] [blame] | 478 | .atomic_begin = decon_atomic_begin, |
Gustavo Padovan | 9cc7610 | 2015-08-03 14:38:05 +0900 | [diff] [blame] | 479 | .update_plane = decon_update_plane, |
| 480 | .disable_plane = decon_disable_plane, |
Hyungwon Hwang | cc5a7b3 | 2015-08-27 18:21:14 +0900 | [diff] [blame] | 481 | .atomic_flush = decon_atomic_flush, |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 482 | .te_handler = decon_te_irq_handler, |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 483 | }; |
| 484 | |
| 485 | static int decon_bind(struct device *dev, struct device *master, void *data) |
| 486 | { |
| 487 | struct decon_context *ctx = dev_get_drvdata(dev); |
| 488 | struct drm_device *drm_dev = data; |
| 489 | struct exynos_drm_private *priv = drm_dev->dev_private; |
| 490 | struct exynos_drm_plane *exynos_plane; |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 491 | enum exynos_drm_output_type out_type; |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 492 | unsigned int win; |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 493 | int ret; |
| 494 | |
| 495 | ctx->drm_dev = drm_dev; |
| 496 | ctx->pipe = priv->pipe++; |
| 497 | |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 498 | for (win = ctx->first_win; win < WINDOWS_NR; win++) { |
| 499 | int tmp = (win == ctx->first_win) ? 0 : win; |
| 500 | |
Marek Szyprowski | fd2d2fc | 2015-11-30 14:53:25 +0100 | [diff] [blame] | 501 | ctx->configs[win].pixel_formats = decon_formats; |
| 502 | ctx->configs[win].num_pixel_formats = ARRAY_SIZE(decon_formats); |
| 503 | ctx->configs[win].zpos = win; |
| 504 | ctx->configs[win].type = decon_win_types[tmp]; |
| 505 | |
Marek Szyprowski | 40bdfb0 | 2015-12-16 13:21:42 +0100 | [diff] [blame] | 506 | ret = exynos_plane_init(drm_dev, &ctx->planes[win], win, |
Marek Szyprowski | fd2d2fc | 2015-11-30 14:53:25 +0100 | [diff] [blame] | 507 | 1 << ctx->pipe, &ctx->configs[win]); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 508 | if (ret) |
| 509 | return ret; |
| 510 | } |
| 511 | |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 512 | exynos_plane = &ctx->planes[ctx->first_win]; |
Inki Dae | 9ac26de | 2016-04-18 17:59:01 +0900 | [diff] [blame] | 513 | out_type = (ctx->out_type & IFTYPE_HDMI) ? EXYNOS_DISPLAY_TYPE_HDMI |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 514 | : EXYNOS_DISPLAY_TYPE_LCD; |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 515 | ctx->crtc = exynos_drm_crtc_create(drm_dev, &exynos_plane->base, |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 516 | ctx->pipe, out_type, |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 517 | &decon_crtc_ops, ctx); |
| 518 | if (IS_ERR(ctx->crtc)) { |
| 519 | ret = PTR_ERR(ctx->crtc); |
| 520 | goto err; |
| 521 | } |
| 522 | |
Joonyoung Shim | eb7a3fc | 2015-07-02 21:49:39 +0900 | [diff] [blame] | 523 | decon_clear_channels(ctx->crtc); |
| 524 | |
| 525 | ret = drm_iommu_attach_device(drm_dev, dev); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 526 | if (ret) |
| 527 | goto err; |
| 528 | |
| 529 | return ret; |
| 530 | err: |
| 531 | priv->pipe--; |
| 532 | return ret; |
| 533 | } |
| 534 | |
| 535 | static void decon_unbind(struct device *dev, struct device *master, void *data) |
| 536 | { |
| 537 | struct decon_context *ctx = dev_get_drvdata(dev); |
| 538 | |
| 539 | decon_disable(ctx->crtc); |
| 540 | |
| 541 | /* detach this sub driver from iommu mapping if supported. */ |
Joonyoung Shim | bf56608 | 2015-07-02 21:49:38 +0900 | [diff] [blame] | 542 | drm_iommu_detach_device(ctx->drm_dev, ctx->dev); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | static const struct component_ops decon_component_ops = { |
| 546 | .bind = decon_bind, |
| 547 | .unbind = decon_unbind, |
| 548 | }; |
| 549 | |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 550 | static irqreturn_t decon_irq_handler(int irq, void *dev_id) |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 551 | { |
| 552 | struct decon_context *ctx = dev_id; |
| 553 | u32 val; |
| 554 | |
Andrzej Hajda | 7b6bb6e | 2015-10-20 11:22:38 +0200 | [diff] [blame] | 555 | if (!test_bit(BIT_CLKS_ENABLED, &ctx->flags)) |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 556 | goto out; |
| 557 | |
| 558 | val = readl(ctx->addr + DECON_VIDINTCON1); |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 559 | val &= VIDINTCON1_INTFRMDONEPEND | VIDINTCON1_INTFRMPEND; |
| 560 | |
| 561 | if (val) { |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 562 | writel(val, ctx->addr + DECON_VIDINTCON1); |
Andrzej Hajda | b0bb3d0 | 2016-04-29 15:42:47 +0200 | [diff] [blame] | 563 | drm_crtc_handle_vblank(&ctx->crtc->base); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | out: |
| 567 | return IRQ_HANDLED; |
| 568 | } |
| 569 | |
Gustavo Padovan | ebf3fd4 | 2015-11-02 20:54:55 +0900 | [diff] [blame] | 570 | #ifdef CONFIG_PM |
| 571 | static int exynos5433_decon_suspend(struct device *dev) |
| 572 | { |
| 573 | struct decon_context *ctx = dev_get_drvdata(dev); |
Andrzej Hajda | 92c96ff | 2016-02-11 12:25:04 +0100 | [diff] [blame] | 574 | int i = ARRAY_SIZE(decon_clks_name); |
Gustavo Padovan | ebf3fd4 | 2015-11-02 20:54:55 +0900 | [diff] [blame] | 575 | |
Andrzej Hajda | 92c96ff | 2016-02-11 12:25:04 +0100 | [diff] [blame] | 576 | while (--i >= 0) |
Gustavo Padovan | ebf3fd4 | 2015-11-02 20:54:55 +0900 | [diff] [blame] | 577 | clk_disable_unprepare(ctx->clks[i]); |
| 578 | |
| 579 | return 0; |
| 580 | } |
| 581 | |
| 582 | static int exynos5433_decon_resume(struct device *dev) |
| 583 | { |
| 584 | struct decon_context *ctx = dev_get_drvdata(dev); |
| 585 | int i, ret; |
| 586 | |
| 587 | for (i = 0; i < ARRAY_SIZE(decon_clks_name); i++) { |
| 588 | ret = clk_prepare_enable(ctx->clks[i]); |
| 589 | if (ret < 0) |
| 590 | goto err; |
| 591 | } |
| 592 | |
| 593 | return 0; |
| 594 | |
| 595 | err: |
| 596 | while (--i >= 0) |
| 597 | clk_disable_unprepare(ctx->clks[i]); |
| 598 | |
| 599 | return ret; |
| 600 | } |
| 601 | #endif |
| 602 | |
| 603 | static const struct dev_pm_ops exynos5433_decon_pm_ops = { |
| 604 | SET_RUNTIME_PM_OPS(exynos5433_decon_suspend, exynos5433_decon_resume, |
| 605 | NULL) |
| 606 | }; |
| 607 | |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 608 | static const struct of_device_id exynos5433_decon_driver_dt_match[] = { |
| 609 | { |
| 610 | .compatible = "samsung,exynos5433-decon", |
Inki Dae | 9ac26de | 2016-04-18 17:59:01 +0900 | [diff] [blame] | 611 | .data = (void *)I80_HW_TRG |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 612 | }, |
| 613 | { |
| 614 | .compatible = "samsung,exynos5433-decon-tv", |
Inki Dae | 9ac26de | 2016-04-18 17:59:01 +0900 | [diff] [blame] | 615 | .data = (void *)(I80_HW_TRG | IFTYPE_HDMI) |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 616 | }, |
| 617 | {}, |
| 618 | }; |
| 619 | MODULE_DEVICE_TABLE(of, exynos5433_decon_driver_dt_match); |
| 620 | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 621 | static int exynos5433_decon_probe(struct platform_device *pdev) |
| 622 | { |
| 623 | struct device *dev = &pdev->dev; |
| 624 | struct decon_context *ctx; |
| 625 | struct resource *res; |
| 626 | int ret; |
| 627 | int i; |
| 628 | |
| 629 | ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); |
| 630 | if (!ctx) |
| 631 | return -ENOMEM; |
| 632 | |
Andrzej Hajda | 7b6bb6e | 2015-10-20 11:22:38 +0200 | [diff] [blame] | 633 | __set_bit(BIT_SUSPENDED, &ctx->flags); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 634 | ctx->dev = dev; |
Inki Dae | 9ac26de | 2016-04-18 17:59:01 +0900 | [diff] [blame] | 635 | ctx->out_type = (unsigned long)of_device_get_match_data(dev); |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 636 | |
Inki Dae | 9ac26de | 2016-04-18 17:59:01 +0900 | [diff] [blame] | 637 | if (ctx->out_type & IFTYPE_HDMI) { |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 638 | ctx->first_win = 1; |
Inki Dae | 9ac26de | 2016-04-18 17:59:01 +0900 | [diff] [blame] | 639 | } else if (of_get_child_by_name(dev->of_node, "i80-if-timings")) { |
Andrzej Hajda | dd65a68 | 2016-04-29 15:42:49 +0200 | [diff] [blame] | 640 | ctx->out_type |= IFTYPE_I80; |
Inki Dae | 9ac26de | 2016-04-18 17:59:01 +0900 | [diff] [blame] | 641 | } |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 642 | |
| 643 | for (i = 0; i < ARRAY_SIZE(decon_clks_name); i++) { |
| 644 | struct clk *clk; |
| 645 | |
| 646 | clk = devm_clk_get(ctx->dev, decon_clks_name[i]); |
| 647 | if (IS_ERR(clk)) |
| 648 | return PTR_ERR(clk); |
| 649 | |
| 650 | ctx->clks[i] = clk; |
| 651 | } |
| 652 | |
| 653 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 654 | if (!res) { |
| 655 | dev_err(dev, "cannot find IO resource\n"); |
| 656 | return -ENXIO; |
| 657 | } |
| 658 | |
| 659 | ctx->addr = devm_ioremap_resource(dev, res); |
| 660 | if (IS_ERR(ctx->addr)) { |
| 661 | dev_err(dev, "ioremap failed\n"); |
| 662 | return PTR_ERR(ctx->addr); |
| 663 | } |
| 664 | |
| 665 | res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, |
Inki Dae | 9ac26de | 2016-04-18 17:59:01 +0900 | [diff] [blame] | 666 | (ctx->out_type & IFTYPE_I80) ? "lcd_sys" : "vsync"); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 667 | if (!res) { |
| 668 | dev_err(dev, "cannot find IRQ resource\n"); |
| 669 | return -ENXIO; |
| 670 | } |
| 671 | |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 672 | ret = devm_request_irq(dev, res->start, decon_irq_handler, 0, |
| 673 | "drm_decon", ctx); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 674 | if (ret < 0) { |
| 675 | dev_err(dev, "lcd_sys irq request failed\n"); |
| 676 | return ret; |
| 677 | } |
| 678 | |
| 679 | platform_set_drvdata(pdev, ctx); |
| 680 | |
| 681 | pm_runtime_enable(dev); |
| 682 | |
| 683 | ret = component_add(dev, &decon_component_ops); |
| 684 | if (ret) |
| 685 | goto err_disable_pm_runtime; |
| 686 | |
| 687 | return 0; |
| 688 | |
| 689 | err_disable_pm_runtime: |
| 690 | pm_runtime_disable(dev); |
| 691 | |
| 692 | return ret; |
| 693 | } |
| 694 | |
| 695 | static int exynos5433_decon_remove(struct platform_device *pdev) |
| 696 | { |
| 697 | pm_runtime_disable(&pdev->dev); |
| 698 | |
| 699 | component_del(&pdev->dev, &decon_component_ops); |
| 700 | |
| 701 | return 0; |
| 702 | } |
| 703 | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 704 | struct platform_driver exynos5433_decon_driver = { |
| 705 | .probe = exynos5433_decon_probe, |
| 706 | .remove = exynos5433_decon_remove, |
| 707 | .driver = { |
| 708 | .name = "exynos5433-decon", |
Gustavo Padovan | ebf3fd4 | 2015-11-02 20:54:55 +0900 | [diff] [blame] | 709 | .pm = &exynos5433_decon_pm_ops, |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 710 | .of_match_table = exynos5433_decon_driver_dt_match, |
| 711 | }, |
| 712 | }; |