Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 1 | /* drivers/gpu/drm/exynos/exynos7_drm_decon.c |
| 2 | * |
| 3 | * Copyright (C) 2014 Samsung Electronics Co.Ltd |
| 4 | * Authors: |
| 5 | * Akshu Agarwal <akshua@gmail.com> |
| 6 | * Ajay Kumar <ajaykumar.rs@samsung.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License as published by the |
| 10 | * Free Software Foundation; either version 2 of the License, or (at your |
| 11 | * option) any later version. |
| 12 | * |
| 13 | */ |
| 14 | #include <drm/drmP.h> |
| 15 | #include <drm/exynos_drm.h> |
| 16 | |
| 17 | #include <linux/clk.h> |
| 18 | #include <linux/component.h> |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/of.h> |
| 21 | #include <linux/of_address.h> |
| 22 | #include <linux/of_device.h> |
| 23 | #include <linux/platform_device.h> |
| 24 | #include <linux/pm_runtime.h> |
| 25 | |
| 26 | #include <video/of_display_timing.h> |
| 27 | #include <video/of_videomode.h> |
| 28 | #include <video/exynos7_decon.h> |
| 29 | |
| 30 | #include "exynos_drm_crtc.h" |
Gustavo Padovan | 7ee14cd | 2015-04-03 21:03:40 +0900 | [diff] [blame] | 31 | #include "exynos_drm_plane.h" |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 32 | #include "exynos_drm_drv.h" |
Marek Szyprowski | 0488f50 | 2015-11-30 14:53:21 +0100 | [diff] [blame] | 33 | #include "exynos_drm_fb.h" |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 34 | #include "exynos_drm_fbdev.h" |
| 35 | #include "exynos_drm_iommu.h" |
| 36 | |
| 37 | /* |
| 38 | * DECON stands for Display and Enhancement controller. |
| 39 | */ |
| 40 | |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 41 | #define MIN_FB_WIDTH_FOR_16WORD_BURST 128 |
| 42 | |
| 43 | #define WINDOWS_NR 2 |
| 44 | |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 45 | struct decon_context { |
| 46 | struct device *dev; |
| 47 | struct drm_device *drm_dev; |
| 48 | struct exynos_drm_crtc *crtc; |
Gustavo Padovan | 7ee14cd | 2015-04-03 21:03:40 +0900 | [diff] [blame] | 49 | struct exynos_drm_plane planes[WINDOWS_NR]; |
Marek Szyprowski | fd2d2fc | 2015-11-30 14:53:25 +0100 | [diff] [blame] | 50 | struct exynos_drm_plane_config configs[WINDOWS_NR]; |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 51 | struct clk *pclk; |
| 52 | struct clk *aclk; |
| 53 | struct clk *eclk; |
| 54 | struct clk *vclk; |
| 55 | void __iomem *regs; |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 56 | unsigned long irq_flags; |
| 57 | bool i80_if; |
| 58 | bool suspended; |
| 59 | int pipe; |
| 60 | wait_queue_head_t wait_vsync_queue; |
| 61 | atomic_t wait_vsync_event; |
| 62 | |
| 63 | struct exynos_drm_panel_info panel; |
Gustavo Padovan | 2b8376c | 2015-08-15 12:14:08 -0300 | [diff] [blame] | 64 | struct drm_encoder *encoder; |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | static const struct of_device_id decon_driver_dt_match[] = { |
| 68 | {.compatible = "samsung,exynos7-decon"}, |
| 69 | {}, |
| 70 | }; |
| 71 | MODULE_DEVICE_TABLE(of, decon_driver_dt_match); |
| 72 | |
Marek Szyprowski | fbbb1e1 | 2015-08-31 00:53:57 +0900 | [diff] [blame] | 73 | static const uint32_t decon_formats[] = { |
| 74 | DRM_FORMAT_RGB565, |
| 75 | DRM_FORMAT_XRGB8888, |
| 76 | DRM_FORMAT_XBGR8888, |
| 77 | DRM_FORMAT_RGBX8888, |
| 78 | DRM_FORMAT_BGRX8888, |
| 79 | DRM_FORMAT_ARGB8888, |
| 80 | DRM_FORMAT_ABGR8888, |
| 81 | DRM_FORMAT_RGBA8888, |
| 82 | DRM_FORMAT_BGRA8888, |
| 83 | }; |
| 84 | |
Marek Szyprowski | fd2d2fc | 2015-11-30 14:53:25 +0100 | [diff] [blame] | 85 | static const enum drm_plane_type decon_win_types[WINDOWS_NR] = { |
| 86 | DRM_PLANE_TYPE_PRIMARY, |
| 87 | DRM_PLANE_TYPE_CURSOR, |
| 88 | }; |
| 89 | |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 90 | static void decon_wait_for_vblank(struct exynos_drm_crtc *crtc) |
| 91 | { |
| 92 | struct decon_context *ctx = crtc->ctx; |
| 93 | |
| 94 | if (ctx->suspended) |
| 95 | return; |
| 96 | |
| 97 | atomic_set(&ctx->wait_vsync_event, 1); |
| 98 | |
| 99 | /* |
| 100 | * wait for DECON to signal VSYNC interrupt or return after |
| 101 | * timeout which is set to 50ms (refresh rate of 20). |
| 102 | */ |
| 103 | if (!wait_event_timeout(ctx->wait_vsync_queue, |
| 104 | !atomic_read(&ctx->wait_vsync_event), |
| 105 | HZ/20)) |
| 106 | DRM_DEBUG_KMS("vblank wait timed out.\n"); |
| 107 | } |
| 108 | |
Hyungwon Hwang | fc2e013 | 2015-06-22 19:05:04 +0900 | [diff] [blame] | 109 | static void decon_clear_channels(struct exynos_drm_crtc *crtc) |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 110 | { |
Hyungwon Hwang | fc2e013 | 2015-06-22 19:05:04 +0900 | [diff] [blame] | 111 | struct decon_context *ctx = crtc->ctx; |
Tobias Jakobi | 5b1d5bc | 2015-05-06 14:10:22 +0200 | [diff] [blame] | 112 | unsigned int win, ch_enabled = 0; |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 113 | |
| 114 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 115 | |
| 116 | /* Check if any channel is enabled. */ |
| 117 | for (win = 0; win < WINDOWS_NR; win++) { |
| 118 | u32 val = readl(ctx->regs + WINCON(win)); |
| 119 | |
| 120 | if (val & WINCONx_ENWIN) { |
| 121 | val &= ~WINCONx_ENWIN; |
| 122 | writel(val, ctx->regs + WINCON(win)); |
| 123 | ch_enabled = 1; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | /* Wait for vsync, as disable channel takes effect at next vsync */ |
Gustavo Padovan | 681c801 | 2015-11-02 20:58:02 +0900 | [diff] [blame] | 128 | if (ch_enabled) |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 129 | decon_wait_for_vblank(ctx->crtc); |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | static int decon_ctx_initialize(struct decon_context *ctx, |
| 133 | struct drm_device *drm_dev) |
| 134 | { |
| 135 | struct exynos_drm_private *priv = drm_dev->dev_private; |
Hyungwon Hwang | fc2e013 | 2015-06-22 19:05:04 +0900 | [diff] [blame] | 136 | int ret; |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 137 | |
| 138 | ctx->drm_dev = drm_dev; |
| 139 | ctx->pipe = priv->pipe++; |
| 140 | |
Joonyoung Shim | eb7a3fc | 2015-07-02 21:49:39 +0900 | [diff] [blame] | 141 | decon_clear_channels(ctx->crtc); |
| 142 | |
| 143 | ret = drm_iommu_attach_device(drm_dev, ctx->dev); |
Hyungwon Hwang | fc2e013 | 2015-06-22 19:05:04 +0900 | [diff] [blame] | 144 | if (ret) |
| 145 | priv->pipe--; |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 146 | |
Hyungwon Hwang | fc2e013 | 2015-06-22 19:05:04 +0900 | [diff] [blame] | 147 | return ret; |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | static void decon_ctx_remove(struct decon_context *ctx) |
| 151 | { |
| 152 | /* detach this sub driver from iommu mapping if supported. */ |
Joonyoung Shim | bf56608 | 2015-07-02 21:49:38 +0900 | [diff] [blame] | 153 | drm_iommu_detach_device(ctx->drm_dev, ctx->dev); |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | static u32 decon_calc_clkdiv(struct decon_context *ctx, |
| 157 | const struct drm_display_mode *mode) |
| 158 | { |
| 159 | unsigned long ideal_clk = mode->htotal * mode->vtotal * mode->vrefresh; |
| 160 | u32 clkdiv; |
| 161 | |
| 162 | /* Find the clock divider value that gets us closest to ideal_clk */ |
| 163 | clkdiv = DIV_ROUND_UP(clk_get_rate(ctx->vclk), ideal_clk); |
| 164 | |
| 165 | return (clkdiv < 0x100) ? clkdiv : 0xff; |
| 166 | } |
| 167 | |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 168 | static void decon_commit(struct exynos_drm_crtc *crtc) |
| 169 | { |
| 170 | struct decon_context *ctx = crtc->ctx; |
Joonyoung Shim | 020e79d | 2015-06-02 21:04:42 +0900 | [diff] [blame] | 171 | struct drm_display_mode *mode = &crtc->base.state->adjusted_mode; |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 172 | u32 val, clkdiv; |
| 173 | |
| 174 | if (ctx->suspended) |
| 175 | return; |
| 176 | |
| 177 | /* nothing to do if we haven't set the mode yet */ |
| 178 | if (mode->htotal == 0 || mode->vtotal == 0) |
| 179 | return; |
| 180 | |
| 181 | if (!ctx->i80_if) { |
| 182 | int vsync_len, vbpd, vfpd, hsync_len, hbpd, hfpd; |
| 183 | /* setup vertical timing values. */ |
| 184 | vsync_len = mode->crtc_vsync_end - mode->crtc_vsync_start; |
| 185 | vbpd = mode->crtc_vtotal - mode->crtc_vsync_end; |
| 186 | vfpd = mode->crtc_vsync_start - mode->crtc_vdisplay; |
| 187 | |
| 188 | val = VIDTCON0_VBPD(vbpd - 1) | VIDTCON0_VFPD(vfpd - 1); |
| 189 | writel(val, ctx->regs + VIDTCON0); |
| 190 | |
| 191 | val = VIDTCON1_VSPW(vsync_len - 1); |
| 192 | writel(val, ctx->regs + VIDTCON1); |
| 193 | |
| 194 | /* setup horizontal timing values. */ |
| 195 | hsync_len = mode->crtc_hsync_end - mode->crtc_hsync_start; |
| 196 | hbpd = mode->crtc_htotal - mode->crtc_hsync_end; |
| 197 | hfpd = mode->crtc_hsync_start - mode->crtc_hdisplay; |
| 198 | |
| 199 | /* setup horizontal timing values. */ |
| 200 | val = VIDTCON2_HBPD(hbpd - 1) | VIDTCON2_HFPD(hfpd - 1); |
| 201 | writel(val, ctx->regs + VIDTCON2); |
| 202 | |
| 203 | val = VIDTCON3_HSPW(hsync_len - 1); |
| 204 | writel(val, ctx->regs + VIDTCON3); |
| 205 | } |
| 206 | |
| 207 | /* setup horizontal and vertical display size. */ |
| 208 | val = VIDTCON4_LINEVAL(mode->vdisplay - 1) | |
| 209 | VIDTCON4_HOZVAL(mode->hdisplay - 1); |
| 210 | writel(val, ctx->regs + VIDTCON4); |
| 211 | |
| 212 | writel(mode->vdisplay - 1, ctx->regs + LINECNT_OP_THRESHOLD); |
| 213 | |
| 214 | /* |
| 215 | * fields of register with prefix '_F' would be updated |
| 216 | * at vsync(same as dma start) |
| 217 | */ |
| 218 | val = VIDCON0_ENVID | VIDCON0_ENVID_F; |
| 219 | writel(val, ctx->regs + VIDCON0); |
| 220 | |
| 221 | clkdiv = decon_calc_clkdiv(ctx, mode); |
| 222 | if (clkdiv > 1) { |
| 223 | val = VCLKCON1_CLKVAL_NUM_VCLK(clkdiv - 1); |
| 224 | writel(val, ctx->regs + VCLKCON1); |
| 225 | writel(val, ctx->regs + VCLKCON2); |
| 226 | } |
| 227 | |
| 228 | val = readl(ctx->regs + DECON_UPDATE); |
| 229 | val |= DECON_UPDATE_STANDALONE_F; |
| 230 | writel(val, ctx->regs + DECON_UPDATE); |
| 231 | } |
| 232 | |
| 233 | static int decon_enable_vblank(struct exynos_drm_crtc *crtc) |
| 234 | { |
| 235 | struct decon_context *ctx = crtc->ctx; |
| 236 | u32 val; |
| 237 | |
| 238 | if (ctx->suspended) |
| 239 | return -EPERM; |
| 240 | |
| 241 | if (!test_and_set_bit(0, &ctx->irq_flags)) { |
| 242 | val = readl(ctx->regs + VIDINTCON0); |
| 243 | |
| 244 | val |= VIDINTCON0_INT_ENABLE; |
| 245 | |
| 246 | if (!ctx->i80_if) { |
| 247 | val |= VIDINTCON0_INT_FRAME; |
| 248 | val &= ~VIDINTCON0_FRAMESEL0_MASK; |
| 249 | val |= VIDINTCON0_FRAMESEL0_VSYNC; |
| 250 | } |
| 251 | |
| 252 | writel(val, ctx->regs + VIDINTCON0); |
| 253 | } |
| 254 | |
| 255 | return 0; |
| 256 | } |
| 257 | |
| 258 | static void decon_disable_vblank(struct exynos_drm_crtc *crtc) |
| 259 | { |
| 260 | struct decon_context *ctx = crtc->ctx; |
| 261 | u32 val; |
| 262 | |
| 263 | if (ctx->suspended) |
| 264 | return; |
| 265 | |
| 266 | if (test_and_clear_bit(0, &ctx->irq_flags)) { |
| 267 | val = readl(ctx->regs + VIDINTCON0); |
| 268 | |
| 269 | val &= ~VIDINTCON0_INT_ENABLE; |
| 270 | if (!ctx->i80_if) |
| 271 | val &= ~VIDINTCON0_INT_FRAME; |
| 272 | |
| 273 | writel(val, ctx->regs + VIDINTCON0); |
| 274 | } |
| 275 | } |
| 276 | |
Gustavo Padovan | 2eeb2e5 | 2015-08-03 14:40:44 +0900 | [diff] [blame] | 277 | static void decon_win_set_pixfmt(struct decon_context *ctx, unsigned int win, |
| 278 | struct drm_framebuffer *fb) |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 279 | { |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 280 | unsigned long val; |
Gustavo Padovan | 7ee14cd | 2015-04-03 21:03:40 +0900 | [diff] [blame] | 281 | int padding; |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 282 | |
| 283 | val = readl(ctx->regs + WINCON(win)); |
| 284 | val &= ~WINCONx_BPPMODE_MASK; |
| 285 | |
Gustavo Padovan | 2eeb2e5 | 2015-08-03 14:40:44 +0900 | [diff] [blame] | 286 | switch (fb->pixel_format) { |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 287 | case DRM_FORMAT_RGB565: |
| 288 | val |= WINCONx_BPPMODE_16BPP_565; |
| 289 | val |= WINCONx_BURSTLEN_16WORD; |
| 290 | break; |
| 291 | case DRM_FORMAT_XRGB8888: |
| 292 | val |= WINCONx_BPPMODE_24BPP_xRGB; |
| 293 | val |= WINCONx_BURSTLEN_16WORD; |
| 294 | break; |
| 295 | case DRM_FORMAT_XBGR8888: |
| 296 | val |= WINCONx_BPPMODE_24BPP_xBGR; |
| 297 | val |= WINCONx_BURSTLEN_16WORD; |
| 298 | break; |
| 299 | case DRM_FORMAT_RGBX8888: |
| 300 | val |= WINCONx_BPPMODE_24BPP_RGBx; |
| 301 | val |= WINCONx_BURSTLEN_16WORD; |
| 302 | break; |
| 303 | case DRM_FORMAT_BGRX8888: |
| 304 | val |= WINCONx_BPPMODE_24BPP_BGRx; |
| 305 | val |= WINCONx_BURSTLEN_16WORD; |
| 306 | break; |
| 307 | case DRM_FORMAT_ARGB8888: |
| 308 | val |= WINCONx_BPPMODE_32BPP_ARGB | WINCONx_BLD_PIX | |
| 309 | WINCONx_ALPHA_SEL; |
| 310 | val |= WINCONx_BURSTLEN_16WORD; |
| 311 | break; |
| 312 | case DRM_FORMAT_ABGR8888: |
| 313 | val |= WINCONx_BPPMODE_32BPP_ABGR | WINCONx_BLD_PIX | |
| 314 | WINCONx_ALPHA_SEL; |
| 315 | val |= WINCONx_BURSTLEN_16WORD; |
| 316 | break; |
| 317 | case DRM_FORMAT_RGBA8888: |
| 318 | val |= WINCONx_BPPMODE_32BPP_RGBA | WINCONx_BLD_PIX | |
| 319 | WINCONx_ALPHA_SEL; |
| 320 | val |= WINCONx_BURSTLEN_16WORD; |
| 321 | break; |
| 322 | case DRM_FORMAT_BGRA8888: |
| 323 | val |= WINCONx_BPPMODE_32BPP_BGRA | WINCONx_BLD_PIX | |
| 324 | WINCONx_ALPHA_SEL; |
| 325 | val |= WINCONx_BURSTLEN_16WORD; |
| 326 | break; |
| 327 | default: |
| 328 | DRM_DEBUG_KMS("invalid pixel size so using unpacked 24bpp.\n"); |
| 329 | |
| 330 | val |= WINCONx_BPPMODE_24BPP_xRGB; |
| 331 | val |= WINCONx_BURSTLEN_16WORD; |
| 332 | break; |
| 333 | } |
| 334 | |
Gustavo Padovan | 2eeb2e5 | 2015-08-03 14:40:44 +0900 | [diff] [blame] | 335 | DRM_DEBUG_KMS("bpp = %d\n", fb->bits_per_pixel); |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 336 | |
| 337 | /* |
| 338 | * In case of exynos, setting dma-burst to 16Word causes permanent |
| 339 | * tearing for very small buffers, e.g. cursor buffer. Burst Mode |
| 340 | * switching which is based on plane size is not recommended as |
| 341 | * plane size varies a lot towards the end of the screen and rapid |
| 342 | * movement causes unstable DMA which results into iommu crash/tear. |
| 343 | */ |
| 344 | |
Gustavo Padovan | 2eeb2e5 | 2015-08-03 14:40:44 +0900 | [diff] [blame] | 345 | padding = (fb->pitches[0] / (fb->bits_per_pixel >> 3)) - fb->width; |
| 346 | if (fb->width + padding < MIN_FB_WIDTH_FOR_16WORD_BURST) { |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 347 | val &= ~WINCONx_BURSTLEN_MASK; |
| 348 | val |= WINCONx_BURSTLEN_8WORD; |
| 349 | } |
| 350 | |
| 351 | writel(val, ctx->regs + WINCON(win)); |
| 352 | } |
| 353 | |
| 354 | static void decon_win_set_colkey(struct decon_context *ctx, unsigned int win) |
| 355 | { |
| 356 | unsigned int keycon0 = 0, keycon1 = 0; |
| 357 | |
| 358 | keycon0 = ~(WxKEYCON0_KEYBL_EN | WxKEYCON0_KEYEN_F | |
| 359 | WxKEYCON0_DIRCON) | WxKEYCON0_COMPKEY(0); |
| 360 | |
| 361 | keycon1 = WxKEYCON1_COLVAL(0xffffffff); |
| 362 | |
| 363 | writel(keycon0, ctx->regs + WKEYCON0_BASE(win)); |
| 364 | writel(keycon1, ctx->regs + WKEYCON1_BASE(win)); |
| 365 | } |
| 366 | |
| 367 | /** |
| 368 | * shadow_protect_win() - disable updating values from shadow registers at vsync |
| 369 | * |
| 370 | * @win: window to protect registers for |
| 371 | * @protect: 1 to protect (disable updates) |
| 372 | */ |
| 373 | static void decon_shadow_protect_win(struct decon_context *ctx, |
Gustavo Padovan | 6e2a3b6 | 2015-04-03 21:05:52 +0900 | [diff] [blame] | 374 | unsigned int win, bool protect) |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 375 | { |
| 376 | u32 bits, val; |
| 377 | |
| 378 | bits = SHADOWCON_WINx_PROTECT(win); |
| 379 | |
| 380 | val = readl(ctx->regs + SHADOWCON); |
| 381 | if (protect) |
| 382 | val |= bits; |
| 383 | else |
| 384 | val &= ~bits; |
| 385 | writel(val, ctx->regs + SHADOWCON); |
| 386 | } |
| 387 | |
Marek Szyprowski | d29c2c1 | 2016-01-05 13:52:51 +0100 | [diff] [blame] | 388 | static void decon_atomic_begin(struct exynos_drm_crtc *crtc) |
Hyungwon Hwang | cc5a7b3 | 2015-08-27 18:21:14 +0900 | [diff] [blame] | 389 | { |
| 390 | struct decon_context *ctx = crtc->ctx; |
Marek Szyprowski | d29c2c1 | 2016-01-05 13:52:51 +0100 | [diff] [blame] | 391 | int i; |
Hyungwon Hwang | cc5a7b3 | 2015-08-27 18:21:14 +0900 | [diff] [blame] | 392 | |
| 393 | if (ctx->suspended) |
| 394 | return; |
| 395 | |
Marek Szyprowski | d29c2c1 | 2016-01-05 13:52:51 +0100 | [diff] [blame] | 396 | for (i = 0; i < WINDOWS_NR; i++) |
| 397 | decon_shadow_protect_win(ctx, i, true); |
Hyungwon Hwang | cc5a7b3 | 2015-08-27 18:21:14 +0900 | [diff] [blame] | 398 | } |
| 399 | |
Gustavo Padovan | 1e1d139 | 2015-08-03 14:39:36 +0900 | [diff] [blame] | 400 | static void decon_update_plane(struct exynos_drm_crtc *crtc, |
| 401 | struct exynos_drm_plane *plane) |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 402 | { |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 403 | struct exynos_drm_plane_state *state = |
| 404 | to_exynos_plane_state(plane->base.state); |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 405 | struct decon_context *ctx = crtc->ctx; |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 406 | struct drm_framebuffer *fb = state->base.fb; |
Gustavo Padovan | 6e2a3b6 | 2015-04-03 21:05:52 +0900 | [diff] [blame] | 407 | int padding; |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 408 | unsigned long val, alpha; |
| 409 | unsigned int last_x; |
| 410 | unsigned int last_y; |
Marek Szyprowski | 40bdfb0 | 2015-12-16 13:21:42 +0100 | [diff] [blame] | 411 | unsigned int win = plane->index; |
Marek Szyprowski | 0488f50 | 2015-11-30 14:53:21 +0100 | [diff] [blame] | 412 | unsigned int bpp = fb->bits_per_pixel >> 3; |
| 413 | unsigned int pitch = fb->pitches[0]; |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 414 | |
| 415 | if (ctx->suspended) |
| 416 | return; |
| 417 | |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 418 | /* |
| 419 | * SHADOWCON/PRTCON register is used for enabling timing. |
| 420 | * |
| 421 | * for example, once only width value of a register is set, |
| 422 | * if the dma is started then decon hardware could malfunction so |
| 423 | * with protect window setting, the register fields with prefix '_F' |
| 424 | * wouldn't be updated at vsync also but updated once unprotect window |
| 425 | * is set. |
| 426 | */ |
| 427 | |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 428 | /* buffer start address */ |
Marek Szyprowski | 0488f50 | 2015-11-30 14:53:21 +0100 | [diff] [blame] | 429 | val = (unsigned long)exynos_drm_fb_dma_addr(fb, 0); |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 430 | writel(val, ctx->regs + VIDW_BUF_START(win)); |
| 431 | |
Marek Szyprowski | 0488f50 | 2015-11-30 14:53:21 +0100 | [diff] [blame] | 432 | padding = (pitch / bpp) - fb->width; |
Gustavo Padovan | 7ee14cd | 2015-04-03 21:03:40 +0900 | [diff] [blame] | 433 | |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 434 | /* buffer size */ |
Marek Szyprowski | 0488f50 | 2015-11-30 14:53:21 +0100 | [diff] [blame] | 435 | writel(fb->width + padding, ctx->regs + VIDW_WHOLE_X(win)); |
| 436 | writel(fb->height, ctx->regs + VIDW_WHOLE_Y(win)); |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 437 | |
| 438 | /* offset from the start of the buffer to read */ |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 439 | writel(state->src.x, ctx->regs + VIDW_OFFSET_X(win)); |
| 440 | writel(state->src.y, ctx->regs + VIDW_OFFSET_Y(win)); |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 441 | |
| 442 | DRM_DEBUG_KMS("start addr = 0x%lx\n", |
Gustavo Padovan | 7ee14cd | 2015-04-03 21:03:40 +0900 | [diff] [blame] | 443 | (unsigned long)val); |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 444 | DRM_DEBUG_KMS("ovl_width = %d, ovl_height = %d\n", |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 445 | state->crtc.w, state->crtc.h); |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 446 | |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 447 | val = VIDOSDxA_TOPLEFT_X(state->crtc.x) | |
| 448 | VIDOSDxA_TOPLEFT_Y(state->crtc.y); |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 449 | writel(val, ctx->regs + VIDOSD_A(win)); |
| 450 | |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 451 | last_x = state->crtc.x + state->crtc.w; |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 452 | if (last_x) |
| 453 | last_x--; |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 454 | last_y = state->crtc.y + state->crtc.h; |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 455 | if (last_y) |
| 456 | last_y--; |
| 457 | |
| 458 | val = VIDOSDxB_BOTRIGHT_X(last_x) | VIDOSDxB_BOTRIGHT_Y(last_y); |
| 459 | |
| 460 | writel(val, ctx->regs + VIDOSD_B(win)); |
| 461 | |
| 462 | DRM_DEBUG_KMS("osd pos: tx = %d, ty = %d, bx = %d, by = %d\n", |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 463 | state->crtc.x, state->crtc.y, last_x, last_y); |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 464 | |
| 465 | /* OSD alpha */ |
| 466 | alpha = VIDOSDxC_ALPHA0_R_F(0x0) | |
| 467 | VIDOSDxC_ALPHA0_G_F(0x0) | |
| 468 | VIDOSDxC_ALPHA0_B_F(0x0); |
| 469 | |
| 470 | writel(alpha, ctx->regs + VIDOSD_C(win)); |
| 471 | |
| 472 | alpha = VIDOSDxD_ALPHA1_R_F(0xff) | |
| 473 | VIDOSDxD_ALPHA1_G_F(0xff) | |
| 474 | VIDOSDxD_ALPHA1_B_F(0xff); |
| 475 | |
| 476 | writel(alpha, ctx->regs + VIDOSD_D(win)); |
| 477 | |
Marek Szyprowski | 0488f50 | 2015-11-30 14:53:21 +0100 | [diff] [blame] | 478 | decon_win_set_pixfmt(ctx, win, fb); |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 479 | |
| 480 | /* hardware window 0 doesn't support color key. */ |
| 481 | if (win != 0) |
| 482 | decon_win_set_colkey(ctx, win); |
| 483 | |
| 484 | /* wincon */ |
| 485 | val = readl(ctx->regs + WINCON(win)); |
| 486 | val |= WINCONx_TRIPLE_BUF_MODE; |
| 487 | val |= WINCONx_ENWIN; |
| 488 | writel(val, ctx->regs + WINCON(win)); |
| 489 | |
| 490 | /* Enable DMA channel and unprotect windows */ |
| 491 | decon_shadow_protect_win(ctx, win, false); |
| 492 | |
| 493 | val = readl(ctx->regs + DECON_UPDATE); |
| 494 | val |= DECON_UPDATE_STANDALONE_F; |
| 495 | writel(val, ctx->regs + DECON_UPDATE); |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 496 | } |
| 497 | |
Gustavo Padovan | 1e1d139 | 2015-08-03 14:39:36 +0900 | [diff] [blame] | 498 | static void decon_disable_plane(struct exynos_drm_crtc *crtc, |
| 499 | struct exynos_drm_plane *plane) |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 500 | { |
| 501 | struct decon_context *ctx = crtc->ctx; |
Marek Szyprowski | 40bdfb0 | 2015-12-16 13:21:42 +0100 | [diff] [blame] | 502 | unsigned int win = plane->index; |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 503 | u32 val; |
| 504 | |
Joonyoung Shim | c329f66 | 2015-06-12 20:34:28 +0900 | [diff] [blame] | 505 | if (ctx->suspended) |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 506 | return; |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 507 | |
| 508 | /* protect windows */ |
| 509 | decon_shadow_protect_win(ctx, win, true); |
| 510 | |
| 511 | /* wincon */ |
| 512 | val = readl(ctx->regs + WINCON(win)); |
| 513 | val &= ~WINCONx_ENWIN; |
| 514 | writel(val, ctx->regs + WINCON(win)); |
| 515 | |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 516 | val = readl(ctx->regs + DECON_UPDATE); |
| 517 | val |= DECON_UPDATE_STANDALONE_F; |
| 518 | writel(val, ctx->regs + DECON_UPDATE); |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 519 | } |
| 520 | |
Marek Szyprowski | d29c2c1 | 2016-01-05 13:52:51 +0100 | [diff] [blame] | 521 | static void decon_atomic_flush(struct exynos_drm_crtc *crtc) |
Hyungwon Hwang | cc5a7b3 | 2015-08-27 18:21:14 +0900 | [diff] [blame] | 522 | { |
| 523 | struct decon_context *ctx = crtc->ctx; |
Marek Szyprowski | d29c2c1 | 2016-01-05 13:52:51 +0100 | [diff] [blame] | 524 | int i; |
Hyungwon Hwang | cc5a7b3 | 2015-08-27 18:21:14 +0900 | [diff] [blame] | 525 | |
| 526 | if (ctx->suspended) |
| 527 | return; |
| 528 | |
Marek Szyprowski | d29c2c1 | 2016-01-05 13:52:51 +0100 | [diff] [blame] | 529 | for (i = 0; i < WINDOWS_NR; i++) |
| 530 | decon_shadow_protect_win(ctx, i, false); |
Hyungwon Hwang | cc5a7b3 | 2015-08-27 18:21:14 +0900 | [diff] [blame] | 531 | } |
| 532 | |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 533 | static void decon_init(struct decon_context *ctx) |
| 534 | { |
| 535 | u32 val; |
| 536 | |
| 537 | writel(VIDCON0_SWRESET, ctx->regs + VIDCON0); |
| 538 | |
| 539 | val = VIDOUTCON0_DISP_IF_0_ON; |
| 540 | if (!ctx->i80_if) |
| 541 | val |= VIDOUTCON0_RGBIF; |
| 542 | writel(val, ctx->regs + VIDOUTCON0); |
| 543 | |
| 544 | writel(VCLKCON0_CLKVALUP | VCLKCON0_VCLKFREE, ctx->regs + VCLKCON0); |
| 545 | |
| 546 | if (!ctx->i80_if) |
| 547 | writel(VIDCON1_VCLK_HOLD, ctx->regs + VIDCON1(0)); |
| 548 | } |
| 549 | |
Gustavo Padovan | 3cecda0 | 2015-06-01 12:04:55 -0300 | [diff] [blame] | 550 | static void decon_enable(struct exynos_drm_crtc *crtc) |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 551 | { |
Gustavo Padovan | 3cecda0 | 2015-06-01 12:04:55 -0300 | [diff] [blame] | 552 | struct decon_context *ctx = crtc->ctx; |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 553 | |
| 554 | if (!ctx->suspended) |
Gustavo Padovan | 3cecda0 | 2015-06-01 12:04:55 -0300 | [diff] [blame] | 555 | return; |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 556 | |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 557 | pm_runtime_get_sync(ctx->dev); |
| 558 | |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 559 | decon_init(ctx); |
| 560 | |
| 561 | /* if vblank was enabled status, enable it again. */ |
Gustavo Padovan | 3cecda0 | 2015-06-01 12:04:55 -0300 | [diff] [blame] | 562 | if (test_and_clear_bit(0, &ctx->irq_flags)) |
| 563 | decon_enable_vblank(ctx->crtc); |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 564 | |
Joonyoung Shim | c329f66 | 2015-06-12 20:34:28 +0900 | [diff] [blame] | 565 | decon_commit(ctx->crtc); |
Gustavo Padovan | 681c801 | 2015-11-02 20:58:02 +0900 | [diff] [blame] | 566 | |
| 567 | ctx->suspended = false; |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 568 | } |
| 569 | |
Gustavo Padovan | 3cecda0 | 2015-06-01 12:04:55 -0300 | [diff] [blame] | 570 | static void decon_disable(struct exynos_drm_crtc *crtc) |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 571 | { |
Gustavo Padovan | 3cecda0 | 2015-06-01 12:04:55 -0300 | [diff] [blame] | 572 | struct decon_context *ctx = crtc->ctx; |
Joonyoung Shim | c329f66 | 2015-06-12 20:34:28 +0900 | [diff] [blame] | 573 | int i; |
Gustavo Padovan | 3cecda0 | 2015-06-01 12:04:55 -0300 | [diff] [blame] | 574 | |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 575 | if (ctx->suspended) |
Gustavo Padovan | 3cecda0 | 2015-06-01 12:04:55 -0300 | [diff] [blame] | 576 | return; |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 577 | |
| 578 | /* |
| 579 | * We need to make sure that all windows are disabled before we |
| 580 | * suspend that connector. Otherwise we might try to scan from |
| 581 | * a destroyed buffer later. |
| 582 | */ |
Joonyoung Shim | c329f66 | 2015-06-12 20:34:28 +0900 | [diff] [blame] | 583 | for (i = 0; i < WINDOWS_NR; i++) |
Gustavo Padovan | 1e1d139 | 2015-08-03 14:39:36 +0900 | [diff] [blame] | 584 | decon_disable_plane(crtc, &ctx->planes[i]); |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 585 | |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 586 | pm_runtime_put_sync(ctx->dev); |
| 587 | |
| 588 | ctx->suspended = true; |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 589 | } |
| 590 | |
Krzysztof Kozlowski | f3aaf76 | 2015-05-07 09:04:45 +0900 | [diff] [blame] | 591 | static const struct exynos_drm_crtc_ops decon_crtc_ops = { |
Gustavo Padovan | 3cecda0 | 2015-06-01 12:04:55 -0300 | [diff] [blame] | 592 | .enable = decon_enable, |
| 593 | .disable = decon_disable, |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 594 | .commit = decon_commit, |
| 595 | .enable_vblank = decon_enable_vblank, |
| 596 | .disable_vblank = decon_disable_vblank, |
| 597 | .wait_for_vblank = decon_wait_for_vblank, |
Hyungwon Hwang | cc5a7b3 | 2015-08-27 18:21:14 +0900 | [diff] [blame] | 598 | .atomic_begin = decon_atomic_begin, |
Gustavo Padovan | 9cc7610 | 2015-08-03 14:38:05 +0900 | [diff] [blame] | 599 | .update_plane = decon_update_plane, |
| 600 | .disable_plane = decon_disable_plane, |
Hyungwon Hwang | cc5a7b3 | 2015-08-27 18:21:14 +0900 | [diff] [blame] | 601 | .atomic_flush = decon_atomic_flush, |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 602 | }; |
| 603 | |
| 604 | |
| 605 | static irqreturn_t decon_irq_handler(int irq, void *dev_id) |
| 606 | { |
| 607 | struct decon_context *ctx = (struct decon_context *)dev_id; |
| 608 | u32 val, clear_bit; |
Gustavo Padovan | 822f6df | 2015-08-15 13:26:14 -0300 | [diff] [blame] | 609 | int win; |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 610 | |
| 611 | val = readl(ctx->regs + VIDINTCON1); |
| 612 | |
| 613 | clear_bit = ctx->i80_if ? VIDINTCON1_INT_I80 : VIDINTCON1_INT_FRAME; |
| 614 | if (val & clear_bit) |
| 615 | writel(clear_bit, ctx->regs + VIDINTCON1); |
| 616 | |
| 617 | /* check the crtc is detached already from encoder */ |
| 618 | if (ctx->pipe < 0 || !ctx->drm_dev) |
| 619 | goto out; |
| 620 | |
| 621 | if (!ctx->i80_if) { |
Gustavo Padovan | eafd540 | 2015-07-16 12:23:32 -0300 | [diff] [blame] | 622 | drm_crtc_handle_vblank(&ctx->crtc->base); |
Gustavo Padovan | 822f6df | 2015-08-15 13:26:14 -0300 | [diff] [blame] | 623 | for (win = 0 ; win < WINDOWS_NR ; win++) { |
| 624 | struct exynos_drm_plane *plane = &ctx->planes[win]; |
| 625 | |
| 626 | if (!plane->pending_fb) |
| 627 | continue; |
| 628 | |
| 629 | exynos_drm_crtc_finish_update(ctx->crtc, plane); |
| 630 | } |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 631 | |
| 632 | /* set wait vsync event to zero and wake up queue. */ |
| 633 | if (atomic_read(&ctx->wait_vsync_event)) { |
| 634 | atomic_set(&ctx->wait_vsync_event, 0); |
| 635 | wake_up(&ctx->wait_vsync_queue); |
| 636 | } |
| 637 | } |
| 638 | out: |
| 639 | return IRQ_HANDLED; |
| 640 | } |
| 641 | |
| 642 | static int decon_bind(struct device *dev, struct device *master, void *data) |
| 643 | { |
| 644 | struct decon_context *ctx = dev_get_drvdata(dev); |
| 645 | struct drm_device *drm_dev = data; |
Gustavo Padovan | 7ee14cd | 2015-04-03 21:03:40 +0900 | [diff] [blame] | 646 | struct exynos_drm_plane *exynos_plane; |
Marek Szyprowski | fd2d2fc | 2015-11-30 14:53:25 +0100 | [diff] [blame] | 647 | unsigned int i; |
Gustavo Padovan | 6e2a3b6 | 2015-04-03 21:05:52 +0900 | [diff] [blame] | 648 | int ret; |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 649 | |
| 650 | ret = decon_ctx_initialize(ctx, drm_dev); |
| 651 | if (ret) { |
| 652 | DRM_ERROR("decon_ctx_initialize failed.\n"); |
| 653 | return ret; |
| 654 | } |
| 655 | |
Marek Szyprowski | fd2d2fc | 2015-11-30 14:53:25 +0100 | [diff] [blame] | 656 | for (i = 0; i < WINDOWS_NR; i++) { |
| 657 | ctx->configs[i].pixel_formats = decon_formats; |
| 658 | ctx->configs[i].num_pixel_formats = ARRAY_SIZE(decon_formats); |
| 659 | ctx->configs[i].zpos = i; |
| 660 | ctx->configs[i].type = decon_win_types[i]; |
| 661 | |
Marek Szyprowski | 40bdfb0 | 2015-12-16 13:21:42 +0100 | [diff] [blame] | 662 | ret = exynos_plane_init(drm_dev, &ctx->planes[i], i, |
Marek Szyprowski | fd2d2fc | 2015-11-30 14:53:25 +0100 | [diff] [blame] | 663 | 1 << ctx->pipe, &ctx->configs[i]); |
Gustavo Padovan | 7ee14cd | 2015-04-03 21:03:40 +0900 | [diff] [blame] | 664 | if (ret) |
| 665 | return ret; |
| 666 | } |
| 667 | |
Gustavo Padovan | 5d3d099 | 2015-10-12 22:07:48 +0900 | [diff] [blame] | 668 | exynos_plane = &ctx->planes[DEFAULT_WIN]; |
Gustavo Padovan | 7ee14cd | 2015-04-03 21:03:40 +0900 | [diff] [blame] | 669 | ctx->crtc = exynos_drm_crtc_create(drm_dev, &exynos_plane->base, |
| 670 | ctx->pipe, EXYNOS_DISPLAY_TYPE_LCD, |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 671 | &decon_crtc_ops, ctx); |
| 672 | if (IS_ERR(ctx->crtc)) { |
| 673 | decon_ctx_remove(ctx); |
| 674 | return PTR_ERR(ctx->crtc); |
| 675 | } |
| 676 | |
Gustavo Padovan | cf67cc9 | 2015-08-11 17:38:06 +0900 | [diff] [blame] | 677 | if (ctx->encoder) |
Gustavo Padovan | a2986e8 | 2015-08-05 20:24:20 -0300 | [diff] [blame] | 678 | exynos_dpi_bind(drm_dev, ctx->encoder); |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 679 | |
| 680 | return 0; |
| 681 | |
| 682 | } |
| 683 | |
| 684 | static void decon_unbind(struct device *dev, struct device *master, |
| 685 | void *data) |
| 686 | { |
| 687 | struct decon_context *ctx = dev_get_drvdata(dev); |
| 688 | |
Gustavo Padovan | 3cecda0 | 2015-06-01 12:04:55 -0300 | [diff] [blame] | 689 | decon_disable(ctx->crtc); |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 690 | |
Gustavo Padovan | cf67cc9 | 2015-08-11 17:38:06 +0900 | [diff] [blame] | 691 | if (ctx->encoder) |
| 692 | exynos_dpi_remove(ctx->encoder); |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 693 | |
| 694 | decon_ctx_remove(ctx); |
| 695 | } |
| 696 | |
| 697 | static const struct component_ops decon_component_ops = { |
| 698 | .bind = decon_bind, |
| 699 | .unbind = decon_unbind, |
| 700 | }; |
| 701 | |
| 702 | static int decon_probe(struct platform_device *pdev) |
| 703 | { |
| 704 | struct device *dev = &pdev->dev; |
| 705 | struct decon_context *ctx; |
| 706 | struct device_node *i80_if_timings; |
| 707 | struct resource *res; |
| 708 | int ret; |
| 709 | |
| 710 | if (!dev->of_node) |
| 711 | return -ENODEV; |
| 712 | |
| 713 | ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); |
| 714 | if (!ctx) |
| 715 | return -ENOMEM; |
| 716 | |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 717 | ctx->dev = dev; |
| 718 | ctx->suspended = true; |
| 719 | |
| 720 | i80_if_timings = of_get_child_by_name(dev->of_node, "i80-if-timings"); |
| 721 | if (i80_if_timings) |
| 722 | ctx->i80_if = true; |
| 723 | of_node_put(i80_if_timings); |
| 724 | |
| 725 | ctx->regs = of_iomap(dev->of_node, 0); |
Andrzej Hajda | 8665040 | 2015-06-11 23:23:37 +0900 | [diff] [blame] | 726 | if (!ctx->regs) |
| 727 | return -ENOMEM; |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 728 | |
| 729 | ctx->pclk = devm_clk_get(dev, "pclk_decon0"); |
| 730 | if (IS_ERR(ctx->pclk)) { |
| 731 | dev_err(dev, "failed to get bus clock pclk\n"); |
| 732 | ret = PTR_ERR(ctx->pclk); |
| 733 | goto err_iounmap; |
| 734 | } |
| 735 | |
| 736 | ctx->aclk = devm_clk_get(dev, "aclk_decon0"); |
| 737 | if (IS_ERR(ctx->aclk)) { |
| 738 | dev_err(dev, "failed to get bus clock aclk\n"); |
| 739 | ret = PTR_ERR(ctx->aclk); |
| 740 | goto err_iounmap; |
| 741 | } |
| 742 | |
| 743 | ctx->eclk = devm_clk_get(dev, "decon0_eclk"); |
| 744 | if (IS_ERR(ctx->eclk)) { |
| 745 | dev_err(dev, "failed to get eclock\n"); |
| 746 | ret = PTR_ERR(ctx->eclk); |
| 747 | goto err_iounmap; |
| 748 | } |
| 749 | |
| 750 | ctx->vclk = devm_clk_get(dev, "decon0_vclk"); |
| 751 | if (IS_ERR(ctx->vclk)) { |
| 752 | dev_err(dev, "failed to get vclock\n"); |
| 753 | ret = PTR_ERR(ctx->vclk); |
| 754 | goto err_iounmap; |
| 755 | } |
| 756 | |
| 757 | res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, |
| 758 | ctx->i80_if ? "lcd_sys" : "vsync"); |
| 759 | if (!res) { |
| 760 | dev_err(dev, "irq request failed.\n"); |
| 761 | ret = -ENXIO; |
| 762 | goto err_iounmap; |
| 763 | } |
| 764 | |
| 765 | ret = devm_request_irq(dev, res->start, decon_irq_handler, |
| 766 | 0, "drm_decon", ctx); |
| 767 | if (ret) { |
| 768 | dev_err(dev, "irq request failed.\n"); |
| 769 | goto err_iounmap; |
| 770 | } |
| 771 | |
| 772 | init_waitqueue_head(&ctx->wait_vsync_queue); |
| 773 | atomic_set(&ctx->wait_vsync_event, 0); |
| 774 | |
| 775 | platform_set_drvdata(pdev, ctx); |
| 776 | |
Gustavo Padovan | cf67cc9 | 2015-08-11 17:38:06 +0900 | [diff] [blame] | 777 | ctx->encoder = exynos_dpi_probe(dev); |
| 778 | if (IS_ERR(ctx->encoder)) { |
| 779 | ret = PTR_ERR(ctx->encoder); |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 780 | goto err_iounmap; |
| 781 | } |
| 782 | |
| 783 | pm_runtime_enable(dev); |
| 784 | |
| 785 | ret = component_add(dev, &decon_component_ops); |
| 786 | if (ret) |
| 787 | goto err_disable_pm_runtime; |
| 788 | |
| 789 | return ret; |
| 790 | |
| 791 | err_disable_pm_runtime: |
| 792 | pm_runtime_disable(dev); |
| 793 | |
| 794 | err_iounmap: |
| 795 | iounmap(ctx->regs); |
| 796 | |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 797 | return ret; |
| 798 | } |
| 799 | |
| 800 | static int decon_remove(struct platform_device *pdev) |
| 801 | { |
| 802 | struct decon_context *ctx = dev_get_drvdata(&pdev->dev); |
| 803 | |
| 804 | pm_runtime_disable(&pdev->dev); |
| 805 | |
| 806 | iounmap(ctx->regs); |
| 807 | |
| 808 | component_del(&pdev->dev, &decon_component_ops); |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 809 | |
| 810 | return 0; |
| 811 | } |
| 812 | |
Gustavo Padovan | 681c801 | 2015-11-02 20:58:02 +0900 | [diff] [blame] | 813 | #ifdef CONFIG_PM |
| 814 | static int exynos7_decon_suspend(struct device *dev) |
| 815 | { |
| 816 | struct decon_context *ctx = dev_get_drvdata(dev); |
| 817 | |
| 818 | clk_disable_unprepare(ctx->vclk); |
| 819 | clk_disable_unprepare(ctx->eclk); |
| 820 | clk_disable_unprepare(ctx->aclk); |
| 821 | clk_disable_unprepare(ctx->pclk); |
| 822 | |
| 823 | return 0; |
| 824 | } |
| 825 | |
| 826 | static int exynos7_decon_resume(struct device *dev) |
| 827 | { |
| 828 | struct decon_context *ctx = dev_get_drvdata(dev); |
| 829 | int ret; |
| 830 | |
| 831 | ret = clk_prepare_enable(ctx->pclk); |
| 832 | if (ret < 0) { |
| 833 | DRM_ERROR("Failed to prepare_enable the pclk [%d]\n", ret); |
| 834 | return ret; |
| 835 | } |
| 836 | |
| 837 | ret = clk_prepare_enable(ctx->aclk); |
| 838 | if (ret < 0) { |
| 839 | DRM_ERROR("Failed to prepare_enable the aclk [%d]\n", ret); |
| 840 | return ret; |
| 841 | } |
| 842 | |
| 843 | ret = clk_prepare_enable(ctx->eclk); |
| 844 | if (ret < 0) { |
| 845 | DRM_ERROR("Failed to prepare_enable the eclk [%d]\n", ret); |
| 846 | return ret; |
| 847 | } |
| 848 | |
| 849 | ret = clk_prepare_enable(ctx->vclk); |
| 850 | if (ret < 0) { |
| 851 | DRM_ERROR("Failed to prepare_enable the vclk [%d]\n", ret); |
| 852 | return ret; |
| 853 | } |
| 854 | |
| 855 | return 0; |
| 856 | } |
| 857 | #endif |
| 858 | |
| 859 | static const struct dev_pm_ops exynos7_decon_pm_ops = { |
| 860 | SET_RUNTIME_PM_OPS(exynos7_decon_suspend, exynos7_decon_resume, |
| 861 | NULL) |
| 862 | }; |
| 863 | |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 864 | struct platform_driver decon_driver = { |
| 865 | .probe = decon_probe, |
| 866 | .remove = decon_remove, |
| 867 | .driver = { |
| 868 | .name = "exynos-decon", |
Gustavo Padovan | 681c801 | 2015-11-02 20:58:02 +0900 | [diff] [blame] | 869 | .pm = &exynos7_decon_pm_ops, |
Ajay Kumar | 96976c3 | 2015-02-05 21:24:04 +0530 | [diff] [blame] | 870 | .of_match_table = decon_driver_dt_match, |
| 871 | }, |
| 872 | }; |