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