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 | 30b8913 | 2017-08-24 15:33:50 +0200 | [diff] [blame] | 16 | #include <linux/iopoll.h> |
Andrzej Hajda | b93c2e8 | 2017-02-01 15:35:07 +0900 | [diff] [blame] | 17 | #include <linux/mfd/syscon.h> |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 18 | #include <linux/of_device.h> |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 19 | #include <linux/of_gpio.h> |
| 20 | #include <linux/pm_runtime.h> |
Andrzej Hajda | b93c2e8 | 2017-02-01 15:35:07 +0900 | [diff] [blame] | 21 | #include <linux/regmap.h> |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 22 | |
| 23 | #include <video/exynos5433_decon.h> |
| 24 | |
| 25 | #include "exynos_drm_drv.h" |
| 26 | #include "exynos_drm_crtc.h" |
Marek Szyprowski | 0488f50 | 2015-11-30 14:53:21 +0100 | [diff] [blame] | 27 | #include "exynos_drm_fb.h" |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 28 | #include "exynos_drm_plane.h" |
| 29 | #include "exynos_drm_iommu.h" |
| 30 | |
Andrzej Hajda | b93c2e8 | 2017-02-01 15:35:07 +0900 | [diff] [blame] | 31 | #define DSD_CFG_MUX 0x1004 |
| 32 | #define DSD_CFG_MUX_TE_UNMASK_GLOBAL BIT(13) |
| 33 | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 34 | #define WINDOWS_NR 3 |
| 35 | #define MIN_FB_WIDTH_FOR_16WORD_BURST 128 |
| 36 | |
Andrzej Hajda | 461e60e | 2017-08-24 15:33:57 +0200 | [diff] [blame] | 37 | #define I80_HW_TRG (1 << 0) |
| 38 | #define IFTYPE_HDMI (1 << 1) |
Inki Dae | 9ac26de | 2016-04-18 17:59:01 +0900 | [diff] [blame] | 39 | |
Andrzej Hajda | 4f54f21c | 2015-10-20 11:22:34 +0200 | [diff] [blame] | 40 | static const char * const decon_clks_name[] = { |
| 41 | "pclk", |
| 42 | "aclk_decon", |
| 43 | "aclk_smmu_decon0x", |
| 44 | "aclk_xiu_decon0x", |
| 45 | "pclk_smmu_decon0x", |
| 46 | "sclk_decon_vclk", |
| 47 | "sclk_decon_eclk", |
| 48 | }; |
| 49 | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 50 | struct decon_context { |
| 51 | struct device *dev; |
| 52 | struct drm_device *drm_dev; |
| 53 | struct exynos_drm_crtc *crtc; |
| 54 | struct exynos_drm_plane planes[WINDOWS_NR]; |
Marek Szyprowski | fd2d2fc | 2015-11-30 14:53:25 +0100 | [diff] [blame] | 55 | struct exynos_drm_plane_config configs[WINDOWS_NR]; |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 56 | void __iomem *addr; |
Andrzej Hajda | b93c2e8 | 2017-02-01 15:35:07 +0900 | [diff] [blame] | 57 | struct regmap *sysreg; |
Andrzej Hajda | 4f54f21c | 2015-10-20 11:22:34 +0200 | [diff] [blame] | 58 | struct clk *clks[ARRAY_SIZE(decon_clks_name)]; |
Andrzej Hajda | b37d53a | 2017-04-05 09:28:32 +0200 | [diff] [blame] | 59 | unsigned int irq; |
Andrzej Hajda | 34c3db6 | 2017-08-24 15:33:55 +0200 | [diff] [blame] | 60 | unsigned int irq_vsync; |
| 61 | unsigned int irq_lcd_sys; |
Andrzej Hajda | b37d53a | 2017-04-05 09:28:32 +0200 | [diff] [blame] | 62 | unsigned int te_irq; |
Inki Dae | 9ac26de | 2016-04-18 17:59:01 +0900 | [diff] [blame] | 63 | unsigned long out_type; |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 64 | int first_win; |
Andrzej Hajda | 7348833 | 2017-03-14 09:27:57 +0100 | [diff] [blame] | 65 | spinlock_t vblank_lock; |
| 66 | u32 frame_id; |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 67 | }; |
| 68 | |
Marek Szyprowski | fbbb1e1 | 2015-08-31 00:53:57 +0900 | [diff] [blame] | 69 | static const uint32_t decon_formats[] = { |
| 70 | DRM_FORMAT_XRGB1555, |
| 71 | DRM_FORMAT_RGB565, |
| 72 | DRM_FORMAT_XRGB8888, |
| 73 | DRM_FORMAT_ARGB8888, |
| 74 | }; |
| 75 | |
Marek Szyprowski | fd2d2fc | 2015-11-30 14:53:25 +0100 | [diff] [blame] | 76 | static const enum drm_plane_type decon_win_types[WINDOWS_NR] = { |
| 77 | DRM_PLANE_TYPE_PRIMARY, |
| 78 | DRM_PLANE_TYPE_OVERLAY, |
| 79 | DRM_PLANE_TYPE_CURSOR, |
| 80 | }; |
| 81 | |
Andrzej Hajda | b219207 | 2015-10-20 11:22:37 +0200 | [diff] [blame] | 82 | static inline void decon_set_bits(struct decon_context *ctx, u32 reg, u32 mask, |
| 83 | u32 val) |
| 84 | { |
| 85 | val = (val & mask) | (readl(ctx->addr + reg) & ~mask); |
| 86 | writel(val, ctx->addr + reg); |
| 87 | } |
| 88 | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 89 | static int decon_enable_vblank(struct exynos_drm_crtc *crtc) |
| 90 | { |
| 91 | struct decon_context *ctx = crtc->ctx; |
| 92 | u32 val; |
| 93 | |
Andrzej Hajda | 3ba8084 | 2017-03-15 15:41:09 +0100 | [diff] [blame] | 94 | val = VIDINTCON0_INTEN; |
Andrzej Hajda | 461e60e | 2017-08-24 15:33:57 +0200 | [diff] [blame] | 95 | if (crtc->i80_mode) |
Andrzej Hajda | 3ba8084 | 2017-03-15 15:41:09 +0100 | [diff] [blame] | 96 | val |= VIDINTCON0_FRAMEDONE; |
| 97 | else |
| 98 | val |= VIDINTCON0_INTFRMEN | VIDINTCON0_FRAMESEL_FP; |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 99 | |
Andrzej Hajda | 3ba8084 | 2017-03-15 15:41:09 +0100 | [diff] [blame] | 100 | writel(val, ctx->addr + DECON_VIDINTCON0); |
Andrzej Hajda | b37d53a | 2017-04-05 09:28:32 +0200 | [diff] [blame] | 101 | |
| 102 | enable_irq(ctx->irq); |
| 103 | if (!(ctx->out_type & I80_HW_TRG)) |
| 104 | enable_irq(ctx->te_irq); |
| 105 | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | static void decon_disable_vblank(struct exynos_drm_crtc *crtc) |
| 110 | { |
| 111 | struct decon_context *ctx = crtc->ctx; |
| 112 | |
Andrzej Hajda | b37d53a | 2017-04-05 09:28:32 +0200 | [diff] [blame] | 113 | if (!(ctx->out_type & I80_HW_TRG)) |
| 114 | disable_irq_nosync(ctx->te_irq); |
| 115 | disable_irq_nosync(ctx->irq); |
| 116 | |
Andrzej Hajda | 3ba8084 | 2017-03-15 15:41:09 +0100 | [diff] [blame] | 117 | writel(0, ctx->addr + DECON_VIDINTCON0); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 118 | } |
| 119 | |
Andrzej Hajda | 7348833 | 2017-03-14 09:27:57 +0100 | [diff] [blame] | 120 | /* return number of starts/ends of frame transmissions since reset */ |
| 121 | static u32 decon_get_frame_count(struct decon_context *ctx, bool end) |
| 122 | { |
| 123 | u32 frm, pfrm, status, cnt = 2; |
| 124 | |
| 125 | /* To get consistent result repeat read until frame id is stable. |
| 126 | * Usually the loop will be executed once, in rare cases when the loop |
| 127 | * is executed at frame change time 2nd pass will be needed. |
| 128 | */ |
| 129 | frm = readl(ctx->addr + DECON_CRFMID); |
| 130 | do { |
| 131 | status = readl(ctx->addr + DECON_VIDCON1); |
| 132 | pfrm = frm; |
| 133 | frm = readl(ctx->addr + DECON_CRFMID); |
| 134 | } while (frm != pfrm && --cnt); |
| 135 | |
| 136 | /* CRFMID is incremented on BPORCH in case of I80 and on VSYNC in case |
| 137 | * of RGB, it should be taken into account. |
| 138 | */ |
| 139 | if (!frm) |
| 140 | return 0; |
| 141 | |
| 142 | switch (status & (VIDCON1_VSTATUS_MASK | VIDCON1_I80_ACTIVE)) { |
| 143 | case VIDCON1_VSTATUS_VS: |
Andrzej Hajda | 461e60e | 2017-08-24 15:33:57 +0200 | [diff] [blame] | 144 | if (!(ctx->crtc->i80_mode)) |
Andrzej Hajda | 7348833 | 2017-03-14 09:27:57 +0100 | [diff] [blame] | 145 | --frm; |
| 146 | break; |
| 147 | case VIDCON1_VSTATUS_BP: |
| 148 | --frm; |
| 149 | break; |
| 150 | case VIDCON1_I80_ACTIVE: |
| 151 | case VIDCON1_VSTATUS_AC: |
| 152 | if (end) |
| 153 | --frm; |
| 154 | break; |
| 155 | default: |
| 156 | break; |
| 157 | } |
| 158 | |
| 159 | return frm; |
| 160 | } |
| 161 | |
Andrzej Hajda | 0586feb | 2017-03-15 15:41:02 +0100 | [diff] [blame] | 162 | static u32 decon_get_vblank_counter(struct exynos_drm_crtc *crtc) |
| 163 | { |
| 164 | struct decon_context *ctx = crtc->ctx; |
| 165 | |
Andrzej Hajda | 0586feb | 2017-03-15 15:41:02 +0100 | [diff] [blame] | 166 | return decon_get_frame_count(ctx, false); |
| 167 | } |
| 168 | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 169 | static void decon_setup_trigger(struct decon_context *ctx) |
| 170 | { |
Andrzej Hajda | 461e60e | 2017-08-24 15:33:57 +0200 | [diff] [blame] | 171 | if (!ctx->crtc->i80_mode && !(ctx->out_type & I80_HW_TRG)) |
Andrzej Hajda | b93c2e8 | 2017-02-01 15:35:07 +0900 | [diff] [blame] | 172 | return; |
| 173 | |
| 174 | if (!(ctx->out_type & I80_HW_TRG)) { |
Andrzej Hajda | f07d9c2 | 2017-03-14 09:28:00 +0100 | [diff] [blame] | 175 | writel(TRIGCON_TRIGEN_PER_F | TRIGCON_TRIGEN_F | |
| 176 | TRIGCON_TE_AUTO_MASK | TRIGCON_SWTRIGEN, |
Andrzej Hajda | b93c2e8 | 2017-02-01 15:35:07 +0900 | [diff] [blame] | 177 | ctx->addr + DECON_TRIGCON); |
| 178 | return; |
| 179 | } |
| 180 | |
| 181 | writel(TRIGCON_TRIGEN_PER_F | TRIGCON_TRIGEN_F | TRIGCON_HWTRIGMASK |
| 182 | | TRIGCON_HWTRIGEN, ctx->addr + DECON_TRIGCON); |
| 183 | |
| 184 | if (regmap_update_bits(ctx->sysreg, DSD_CFG_MUX, |
| 185 | DSD_CFG_MUX_TE_UNMASK_GLOBAL, ~0)) |
| 186 | DRM_ERROR("Cannot update sysreg.\n"); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | static void decon_commit(struct exynos_drm_crtc *crtc) |
| 190 | { |
| 191 | struct decon_context *ctx = crtc->ctx; |
Andrzej Hajda | 85de275 | 2015-10-20 11:22:36 +0200 | [diff] [blame] | 192 | struct drm_display_mode *m = &crtc->base.mode; |
Andrzej Hajda | 5aa6c9a | 2017-01-20 07:52:23 +0100 | [diff] [blame] | 193 | bool interlaced = false; |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 194 | u32 val; |
| 195 | |
Inki Dae | 9ac26de | 2016-04-18 17:59:01 +0900 | [diff] [blame] | 196 | if (ctx->out_type & IFTYPE_HDMI) { |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 197 | m->crtc_hsync_start = m->crtc_hdisplay + 10; |
| 198 | m->crtc_hsync_end = m->crtc_htotal - 92; |
| 199 | m->crtc_vsync_start = m->crtc_vdisplay + 1; |
| 200 | m->crtc_vsync_end = m->crtc_vsync_start + 1; |
Andrzej Hajda | 5aa6c9a | 2017-01-20 07:52:23 +0100 | [diff] [blame] | 201 | if (m->flags & DRM_MODE_FLAG_INTERLACE) |
| 202 | interlaced = true; |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 203 | } |
| 204 | |
Andrzej Hajda | b93c2e8 | 2017-02-01 15:35:07 +0900 | [diff] [blame] | 205 | decon_setup_trigger(ctx); |
Andrzej Hajda | dd65a68 | 2016-04-29 15:42:49 +0200 | [diff] [blame] | 206 | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 207 | /* lcd on and use command if */ |
| 208 | val = VIDOUT_LCD_ON; |
Andrzej Hajda | 5aa6c9a | 2017-01-20 07:52:23 +0100 | [diff] [blame] | 209 | if (interlaced) |
| 210 | val |= VIDOUT_INTERLACE_EN_F; |
Andrzej Hajda | 461e60e | 2017-08-24 15:33:57 +0200 | [diff] [blame] | 211 | if (crtc->i80_mode) { |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 212 | val |= VIDOUT_COMMAND_IF; |
Inki Dae | 9ac26de | 2016-04-18 17:59:01 +0900 | [diff] [blame] | 213 | } else { |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 214 | val |= VIDOUT_RGB_IF; |
Inki Dae | 9ac26de | 2016-04-18 17:59:01 +0900 | [diff] [blame] | 215 | } |
| 216 | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 217 | writel(val, ctx->addr + DECON_VIDOUTCON0); |
| 218 | |
Andrzej Hajda | 5aa6c9a | 2017-01-20 07:52:23 +0100 | [diff] [blame] | 219 | if (interlaced) |
| 220 | val = VIDTCON2_LINEVAL(m->vdisplay / 2 - 1) | |
| 221 | VIDTCON2_HOZVAL(m->hdisplay - 1); |
| 222 | else |
| 223 | val = VIDTCON2_LINEVAL(m->vdisplay - 1) | |
| 224 | VIDTCON2_HOZVAL(m->hdisplay - 1); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 225 | writel(val, ctx->addr + DECON_VIDTCON2); |
| 226 | |
Andrzej Hajda | 461e60e | 2017-08-24 15:33:57 +0200 | [diff] [blame] | 227 | if (!crtc->i80_mode) { |
Andrzej Hajda | 5aa6c9a | 2017-01-20 07:52:23 +0100 | [diff] [blame] | 228 | int vbp = m->crtc_vtotal - m->crtc_vsync_end; |
| 229 | int vfp = m->crtc_vsync_start - m->crtc_vdisplay; |
| 230 | |
| 231 | if (interlaced) |
| 232 | vbp = vbp / 2 - 1; |
| 233 | val = VIDTCON00_VBPD_F(vbp - 1) | VIDTCON00_VFPD_F(vfp - 1); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 234 | writel(val, ctx->addr + DECON_VIDTCON00); |
| 235 | |
| 236 | val = VIDTCON01_VSPW_F( |
Andrzej Hajda | 85de275 | 2015-10-20 11:22:36 +0200 | [diff] [blame] | 237 | m->crtc_vsync_end - m->crtc_vsync_start - 1); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 238 | writel(val, ctx->addr + DECON_VIDTCON01); |
| 239 | |
| 240 | val = VIDTCON10_HBPD_F( |
Andrzej Hajda | 85de275 | 2015-10-20 11:22:36 +0200 | [diff] [blame] | 241 | m->crtc_htotal - m->crtc_hsync_end - 1) | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 242 | VIDTCON10_HFPD_F( |
Andrzej Hajda | 85de275 | 2015-10-20 11:22:36 +0200 | [diff] [blame] | 243 | m->crtc_hsync_start - m->crtc_hdisplay - 1); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 244 | writel(val, ctx->addr + DECON_VIDTCON10); |
| 245 | |
| 246 | val = VIDTCON11_HSPW_F( |
Andrzej Hajda | 85de275 | 2015-10-20 11:22:36 +0200 | [diff] [blame] | 247 | m->crtc_hsync_end - m->crtc_hsync_start - 1); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 248 | writel(val, ctx->addr + DECON_VIDTCON11); |
| 249 | } |
| 250 | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 251 | /* enable output and display signal */ |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 252 | decon_set_bits(ctx, DECON_VIDCON0, VIDCON0_ENVID | VIDCON0_ENVID_F, ~0); |
Andrzej Hajda | 92ead49 | 2016-03-23 14:15:16 +0100 | [diff] [blame] | 253 | |
| 254 | decon_set_bits(ctx, DECON_UPDATE, STANDALONE_UPDATE_F, ~0); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 255 | } |
| 256 | |
Gustavo Padovan | 2eeb2e5 | 2015-08-03 14:40:44 +0900 | [diff] [blame] | 257 | static void decon_win_set_pixfmt(struct decon_context *ctx, unsigned int win, |
| 258 | struct drm_framebuffer *fb) |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 259 | { |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 260 | unsigned long val; |
| 261 | |
| 262 | val = readl(ctx->addr + DECON_WINCONx(win)); |
| 263 | val &= ~WINCONx_BPPMODE_MASK; |
| 264 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 265 | switch (fb->format->format) { |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 266 | case DRM_FORMAT_XRGB1555: |
| 267 | val |= WINCONx_BPPMODE_16BPP_I1555; |
| 268 | val |= WINCONx_HAWSWP_F; |
| 269 | val |= WINCONx_BURSTLEN_16WORD; |
| 270 | break; |
| 271 | case DRM_FORMAT_RGB565: |
| 272 | val |= WINCONx_BPPMODE_16BPP_565; |
| 273 | val |= WINCONx_HAWSWP_F; |
| 274 | val |= WINCONx_BURSTLEN_16WORD; |
| 275 | break; |
| 276 | case DRM_FORMAT_XRGB8888: |
| 277 | val |= WINCONx_BPPMODE_24BPP_888; |
| 278 | val |= WINCONx_WSWP_F; |
| 279 | val |= WINCONx_BURSTLEN_16WORD; |
| 280 | break; |
| 281 | case DRM_FORMAT_ARGB8888: |
| 282 | val |= WINCONx_BPPMODE_32BPP_A8888; |
| 283 | val |= WINCONx_WSWP_F | WINCONx_BLD_PIX_F | WINCONx_ALPHA_SEL_F; |
| 284 | val |= WINCONx_BURSTLEN_16WORD; |
| 285 | break; |
| 286 | default: |
| 287 | DRM_ERROR("Proper pixel format is not set\n"); |
| 288 | return; |
| 289 | } |
| 290 | |
Tobias Jakobi | ac60944 | 2017-08-22 16:19:43 +0200 | [diff] [blame^] | 291 | DRM_DEBUG_KMS("cpp = %u\n", fb->format->cpp[0]); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 292 | |
| 293 | /* |
| 294 | * In case of exynos, setting dma-burst to 16Word causes permanent |
| 295 | * tearing for very small buffers, e.g. cursor buffer. Burst Mode |
| 296 | * switching which is based on plane size is not recommended as |
| 297 | * plane size varies a lot towards the end of the screen and rapid |
| 298 | * movement causes unstable DMA which results into iommu crash/tear. |
| 299 | */ |
| 300 | |
Gustavo Padovan | 2eeb2e5 | 2015-08-03 14:40:44 +0900 | [diff] [blame] | 301 | if (fb->width < MIN_FB_WIDTH_FOR_16WORD_BURST) { |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 302 | val &= ~WINCONx_BURSTLEN_MASK; |
| 303 | val |= WINCONx_BURSTLEN_8WORD; |
| 304 | } |
| 305 | |
| 306 | writel(val, ctx->addr + DECON_WINCONx(win)); |
| 307 | } |
| 308 | |
Andrzej Hajda | b2adc53 | 2017-03-15 15:41:10 +0100 | [diff] [blame] | 309 | static void decon_shadow_protect(struct decon_context *ctx, bool protect) |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 310 | { |
Andrzej Hajda | b2adc53 | 2017-03-15 15:41:10 +0100 | [diff] [blame] | 311 | decon_set_bits(ctx, DECON_SHADOWCON, SHADOWCON_PROTECT_MASK, |
Andrzej Hajda | b219207 | 2015-10-20 11:22:37 +0200 | [diff] [blame] | 312 | protect ? ~0 : 0); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 313 | } |
| 314 | |
Marek Szyprowski | d29c2c1 | 2016-01-05 13:52:51 +0100 | [diff] [blame] | 315 | static void decon_atomic_begin(struct exynos_drm_crtc *crtc) |
Hyungwon Hwang | cc5a7b3 | 2015-08-27 18:21:14 +0900 | [diff] [blame] | 316 | { |
| 317 | struct decon_context *ctx = crtc->ctx; |
| 318 | |
Andrzej Hajda | b2adc53 | 2017-03-15 15:41:10 +0100 | [diff] [blame] | 319 | decon_shadow_protect(ctx, true); |
Hyungwon Hwang | cc5a7b3 | 2015-08-27 18:21:14 +0900 | [diff] [blame] | 320 | } |
| 321 | |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 322 | #define BIT_VAL(x, e, s) (((x) & ((1 << ((e) - (s) + 1)) - 1)) << (s)) |
| 323 | #define COORDINATE_X(x) BIT_VAL((x), 23, 12) |
| 324 | #define COORDINATE_Y(x) BIT_VAL((x), 11, 0) |
| 325 | |
Gustavo Padovan | 1e1d139 | 2015-08-03 14:39:36 +0900 | [diff] [blame] | 326 | static void decon_update_plane(struct exynos_drm_crtc *crtc, |
| 327 | struct exynos_drm_plane *plane) |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 328 | { |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 329 | struct exynos_drm_plane_state *state = |
| 330 | to_exynos_plane_state(plane->base.state); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 331 | struct decon_context *ctx = crtc->ctx; |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 332 | struct drm_framebuffer *fb = state->base.fb; |
Marek Szyprowski | 40bdfb0 | 2015-12-16 13:21:42 +0100 | [diff] [blame] | 333 | unsigned int win = plane->index; |
Tobias Jakobi | ac60944 | 2017-08-22 16:19:43 +0200 | [diff] [blame^] | 334 | unsigned int cpp = fb->format->cpp[0]; |
Marek Szyprowski | 0488f50 | 2015-11-30 14:53:21 +0100 | [diff] [blame] | 335 | unsigned int pitch = fb->pitches[0]; |
| 336 | dma_addr_t dma_addr = exynos_drm_fb_dma_addr(fb, 0); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 337 | u32 val; |
| 338 | |
Andrzej Hajda | 5aa6c9a | 2017-01-20 07:52:23 +0100 | [diff] [blame] | 339 | if (crtc->base.mode.flags & DRM_MODE_FLAG_INTERLACE) { |
| 340 | val = COORDINATE_X(state->crtc.x) | |
| 341 | COORDINATE_Y(state->crtc.y / 2); |
| 342 | writel(val, ctx->addr + DECON_VIDOSDxA(win)); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 343 | |
Andrzej Hajda | 5aa6c9a | 2017-01-20 07:52:23 +0100 | [diff] [blame] | 344 | val = COORDINATE_X(state->crtc.x + state->crtc.w - 1) | |
| 345 | COORDINATE_Y((state->crtc.y + state->crtc.h) / 2 - 1); |
| 346 | writel(val, ctx->addr + DECON_VIDOSDxB(win)); |
| 347 | } else { |
| 348 | val = COORDINATE_X(state->crtc.x) | COORDINATE_Y(state->crtc.y); |
| 349 | writel(val, ctx->addr + DECON_VIDOSDxA(win)); |
| 350 | |
| 351 | val = COORDINATE_X(state->crtc.x + state->crtc.w - 1) | |
| 352 | COORDINATE_Y(state->crtc.y + state->crtc.h - 1); |
| 353 | writel(val, ctx->addr + DECON_VIDOSDxB(win)); |
| 354 | } |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 355 | |
| 356 | val = VIDOSD_Wx_ALPHA_R_F(0x0) | VIDOSD_Wx_ALPHA_G_F(0x0) | |
| 357 | VIDOSD_Wx_ALPHA_B_F(0x0); |
| 358 | writel(val, ctx->addr + DECON_VIDOSDxC(win)); |
| 359 | |
| 360 | val = VIDOSD_Wx_ALPHA_R_F(0x0) | VIDOSD_Wx_ALPHA_G_F(0x0) | |
| 361 | VIDOSD_Wx_ALPHA_B_F(0x0); |
| 362 | writel(val, ctx->addr + DECON_VIDOSDxD(win)); |
| 363 | |
Marek Szyprowski | 0488f50 | 2015-11-30 14:53:21 +0100 | [diff] [blame] | 364 | writel(dma_addr, ctx->addr + DECON_VIDW0xADD0B0(win)); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 365 | |
Marek Szyprowski | 0114f40 | 2015-11-30 14:53:22 +0100 | [diff] [blame] | 366 | val = dma_addr + pitch * state->src.h; |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 367 | writel(val, ctx->addr + DECON_VIDW0xADD1B0(win)); |
| 368 | |
Inki Dae | 9ac26de | 2016-04-18 17:59:01 +0900 | [diff] [blame] | 369 | if (!(ctx->out_type & IFTYPE_HDMI)) |
Tobias Jakobi | ac60944 | 2017-08-22 16:19:43 +0200 | [diff] [blame^] | 370 | val = BIT_VAL(pitch - state->crtc.w * cpp, 27, 14) |
| 371 | | BIT_VAL(state->crtc.w * cpp, 13, 0); |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 372 | else |
Tobias Jakobi | ac60944 | 2017-08-22 16:19:43 +0200 | [diff] [blame^] | 373 | val = BIT_VAL(pitch - state->crtc.w * cpp, 29, 15) |
| 374 | | BIT_VAL(state->crtc.w * cpp, 14, 0); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 375 | writel(val, ctx->addr + DECON_VIDW0xADD2(win)); |
| 376 | |
Marek Szyprowski | 0488f50 | 2015-11-30 14:53:21 +0100 | [diff] [blame] | 377 | decon_win_set_pixfmt(ctx, win, fb); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 378 | |
| 379 | /* window enable */ |
Andrzej Hajda | b219207 | 2015-10-20 11:22:37 +0200 | [diff] [blame] | 380 | decon_set_bits(ctx, DECON_WINCONx(win), WINCONx_ENWIN_F, ~0); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 381 | } |
| 382 | |
Gustavo Padovan | 1e1d139 | 2015-08-03 14:39:36 +0900 | [diff] [blame] | 383 | static void decon_disable_plane(struct exynos_drm_crtc *crtc, |
| 384 | struct exynos_drm_plane *plane) |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 385 | { |
| 386 | struct decon_context *ctx = crtc->ctx; |
Marek Szyprowski | 40bdfb0 | 2015-12-16 13:21:42 +0100 | [diff] [blame] | 387 | unsigned int win = plane->index; |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 388 | |
Andrzej Hajda | b219207 | 2015-10-20 11:22:37 +0200 | [diff] [blame] | 389 | decon_set_bits(ctx, DECON_WINCONx(win), WINCONx_ENWIN_F, 0); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 390 | } |
| 391 | |
Marek Szyprowski | d29c2c1 | 2016-01-05 13:52:51 +0100 | [diff] [blame] | 392 | static void decon_atomic_flush(struct exynos_drm_crtc *crtc) |
Hyungwon Hwang | cc5a7b3 | 2015-08-27 18:21:14 +0900 | [diff] [blame] | 393 | { |
| 394 | struct decon_context *ctx = crtc->ctx; |
Andrzej Hajda | 7348833 | 2017-03-14 09:27:57 +0100 | [diff] [blame] | 395 | unsigned long flags; |
Hyungwon Hwang | cc5a7b3 | 2015-08-27 18:21:14 +0900 | [diff] [blame] | 396 | |
Andrzej Hajda | 7348833 | 2017-03-14 09:27:57 +0100 | [diff] [blame] | 397 | spin_lock_irqsave(&ctx->vblank_lock, flags); |
| 398 | |
Andrzej Hajda | b2adc53 | 2017-03-15 15:41:10 +0100 | [diff] [blame] | 399 | decon_shadow_protect(ctx, false); |
Hyungwon Hwang | cc5a7b3 | 2015-08-27 18:21:14 +0900 | [diff] [blame] | 400 | |
Andrzej Hajda | f8172eb3 | 2017-03-15 15:41:08 +0100 | [diff] [blame] | 401 | decon_set_bits(ctx, DECON_UPDATE, STANDALONE_UPDATE_F, ~0); |
Andrzej Hajda | 92ead49 | 2016-03-23 14:15:16 +0100 | [diff] [blame] | 402 | |
Andrzej Hajda | 7348833 | 2017-03-14 09:27:57 +0100 | [diff] [blame] | 403 | ctx->frame_id = decon_get_frame_count(ctx, true); |
| 404 | |
Andrzej Hajda | a392276 | 2017-03-14 09:27:56 +0100 | [diff] [blame] | 405 | exynos_crtc_handle_event(crtc); |
Andrzej Hajda | 7348833 | 2017-03-14 09:27:57 +0100 | [diff] [blame] | 406 | |
| 407 | spin_unlock_irqrestore(&ctx->vblank_lock, flags); |
Hyungwon Hwang | cc5a7b3 | 2015-08-27 18:21:14 +0900 | [diff] [blame] | 408 | } |
| 409 | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 410 | static void decon_swreset(struct decon_context *ctx) |
| 411 | { |
Andrzej Hajda | 7348833 | 2017-03-14 09:27:57 +0100 | [diff] [blame] | 412 | unsigned long flags; |
Andrzej Hajda | 30b8913 | 2017-08-24 15:33:50 +0200 | [diff] [blame] | 413 | u32 val; |
| 414 | int ret; |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 415 | |
| 416 | writel(0, ctx->addr + DECON_VIDCON0); |
Andrzej Hajda | 30b8913 | 2017-08-24 15:33:50 +0200 | [diff] [blame] | 417 | readl_poll_timeout(ctx->addr + DECON_VIDCON0, val, |
| 418 | ~val & VIDCON0_STOP_STATUS, 12, 20000); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 419 | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 420 | writel(VIDCON0_SWRESET, ctx->addr + DECON_VIDCON0); |
Andrzej Hajda | 30b8913 | 2017-08-24 15:33:50 +0200 | [diff] [blame] | 421 | ret = readl_poll_timeout(ctx->addr + DECON_VIDCON0, val, |
| 422 | ~val & VIDCON0_SWRESET, 12, 20000); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 423 | |
Andrzej Hajda | 30b8913 | 2017-08-24 15:33:50 +0200 | [diff] [blame] | 424 | WARN(ret < 0, "failed to software reset DECON\n"); |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 425 | |
Andrzej Hajda | 7348833 | 2017-03-14 09:27:57 +0100 | [diff] [blame] | 426 | spin_lock_irqsave(&ctx->vblank_lock, flags); |
| 427 | ctx->frame_id = 0; |
| 428 | spin_unlock_irqrestore(&ctx->vblank_lock, flags); |
| 429 | |
Inki Dae | 9ac26de | 2016-04-18 17:59:01 +0900 | [diff] [blame] | 430 | if (!(ctx->out_type & IFTYPE_HDMI)) |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 431 | return; |
| 432 | |
| 433 | writel(VIDCON0_CLKVALUP | VIDCON0_VLCKFREE, ctx->addr + DECON_VIDCON0); |
| 434 | decon_set_bits(ctx, DECON_CMU, |
| 435 | CMU_CLKGAGE_MODE_SFR_F | CMU_CLKGAGE_MODE_MEM_F, ~0); |
| 436 | writel(VIDCON1_VCLK_RUN_VDEN_DISABLE, ctx->addr + DECON_VIDCON1); |
| 437 | writel(CRCCTRL_CRCEN | CRCCTRL_CRCSTART_F | CRCCTRL_CRCCLKEN, |
| 438 | ctx->addr + DECON_CRCCTRL); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | static void decon_enable(struct exynos_drm_crtc *crtc) |
| 442 | { |
| 443 | struct decon_context *ctx = crtc->ctx; |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 444 | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 445 | pm_runtime_get_sync(ctx->dev); |
| 446 | |
Andrzej Hajda | c60230e | 2016-03-23 14:26:00 +0100 | [diff] [blame] | 447 | exynos_drm_pipe_clk_enable(crtc, true); |
| 448 | |
Andrzej Hajda | e87b3c6 | 2016-03-23 14:15:17 +0100 | [diff] [blame] | 449 | decon_swreset(ctx); |
| 450 | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 451 | decon_commit(ctx->crtc); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | static void decon_disable(struct exynos_drm_crtc *crtc) |
| 455 | { |
| 456 | struct decon_context *ctx = crtc->ctx; |
| 457 | int i; |
| 458 | |
Andrzej Hajda | b37d53a | 2017-04-05 09:28:32 +0200 | [diff] [blame] | 459 | if (!(ctx->out_type & I80_HW_TRG)) |
| 460 | synchronize_irq(ctx->te_irq); |
| 461 | synchronize_irq(ctx->irq); |
| 462 | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 463 | /* |
| 464 | * We need to make sure that all windows are disabled before we |
| 465 | * suspend that connector. Otherwise we might try to scan from |
| 466 | * a destroyed buffer later. |
| 467 | */ |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 468 | for (i = ctx->first_win; i < WINDOWS_NR; i++) |
Gustavo Padovan | 1e1d139 | 2015-08-03 14:39:36 +0900 | [diff] [blame] | 469 | decon_disable_plane(crtc, &ctx->planes[i]); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 470 | |
| 471 | decon_swreset(ctx); |
| 472 | |
Andrzej Hajda | c60230e | 2016-03-23 14:26:00 +0100 | [diff] [blame] | 473 | exynos_drm_pipe_clk_enable(crtc, false); |
| 474 | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 475 | pm_runtime_put_sync(ctx->dev); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 476 | } |
| 477 | |
Andrzej Hajda | b37d53a | 2017-04-05 09:28:32 +0200 | [diff] [blame] | 478 | static irqreturn_t decon_te_irq_handler(int irq, void *dev_id) |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 479 | { |
Andrzej Hajda | b37d53a | 2017-04-05 09:28:32 +0200 | [diff] [blame] | 480 | struct decon_context *ctx = dev_id; |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 481 | |
Andrzej Hajda | 358eccc0 | 2017-04-05 09:28:33 +0200 | [diff] [blame] | 482 | decon_set_bits(ctx, DECON_TRIGCON, TRIGCON_SWTRIGCMD, ~0); |
Andrzej Hajda | b37d53a | 2017-04-05 09:28:32 +0200 | [diff] [blame] | 483 | |
| 484 | return IRQ_HANDLED; |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | static void decon_clear_channels(struct exynos_drm_crtc *crtc) |
| 488 | { |
| 489 | struct decon_context *ctx = crtc->ctx; |
| 490 | int win, i, ret; |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 491 | |
| 492 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 493 | |
| 494 | for (i = 0; i < ARRAY_SIZE(decon_clks_name); i++) { |
| 495 | ret = clk_prepare_enable(ctx->clks[i]); |
| 496 | if (ret < 0) |
| 497 | goto err; |
| 498 | } |
| 499 | |
Andrzej Hajda | b2adc53 | 2017-03-15 15:41:10 +0100 | [diff] [blame] | 500 | decon_shadow_protect(ctx, true); |
| 501 | for (win = 0; win < WINDOWS_NR; win++) |
Andrzej Hajda | b219207 | 2015-10-20 11:22:37 +0200 | [diff] [blame] | 502 | decon_set_bits(ctx, DECON_WINCONx(win), WINCONx_ENWIN_F, 0); |
Andrzej Hajda | b2adc53 | 2017-03-15 15:41:10 +0100 | [diff] [blame] | 503 | decon_shadow_protect(ctx, false); |
Andrzej Hajda | 92ead49 | 2016-03-23 14:15:16 +0100 | [diff] [blame] | 504 | |
| 505 | decon_set_bits(ctx, DECON_UPDATE, STANDALONE_UPDATE_F, ~0); |
| 506 | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 507 | /* TODO: wait for possible vsync */ |
| 508 | msleep(50); |
| 509 | |
| 510 | err: |
| 511 | while (--i >= 0) |
| 512 | clk_disable_unprepare(ctx->clks[i]); |
| 513 | } |
| 514 | |
Andrzej Hajda | 461e60e | 2017-08-24 15:33:57 +0200 | [diff] [blame] | 515 | static enum drm_mode_status decon_mode_valid(struct exynos_drm_crtc *crtc, |
| 516 | const struct drm_display_mode *mode) |
| 517 | { |
| 518 | struct decon_context *ctx = crtc->ctx; |
| 519 | |
| 520 | ctx->irq = crtc->i80_mode ? ctx->irq_lcd_sys : ctx->irq_vsync; |
| 521 | |
| 522 | if (ctx->irq) |
| 523 | return MODE_OK; |
| 524 | |
| 525 | dev_info(ctx->dev, "Sink requires %s mode, but appropriate interrupt is not provided.\n", |
| 526 | crtc->i80_mode ? "command" : "video"); |
| 527 | |
| 528 | return MODE_BAD; |
| 529 | } |
| 530 | |
Bhumika Goyal | fc36ec7 | 2017-01-09 23:24:53 +0530 | [diff] [blame] | 531 | static const struct exynos_drm_crtc_ops decon_crtc_ops = { |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 532 | .enable = decon_enable, |
| 533 | .disable = decon_disable, |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 534 | .enable_vblank = decon_enable_vblank, |
| 535 | .disable_vblank = decon_disable_vblank, |
Andrzej Hajda | 0586feb | 2017-03-15 15:41:02 +0100 | [diff] [blame] | 536 | .get_vblank_counter = decon_get_vblank_counter, |
Hyungwon Hwang | cc5a7b3 | 2015-08-27 18:21:14 +0900 | [diff] [blame] | 537 | .atomic_begin = decon_atomic_begin, |
Gustavo Padovan | 9cc7610 | 2015-08-03 14:38:05 +0900 | [diff] [blame] | 538 | .update_plane = decon_update_plane, |
| 539 | .disable_plane = decon_disable_plane, |
Andrzej Hajda | 461e60e | 2017-08-24 15:33:57 +0200 | [diff] [blame] | 540 | .mode_valid = decon_mode_valid, |
Hyungwon Hwang | cc5a7b3 | 2015-08-27 18:21:14 +0900 | [diff] [blame] | 541 | .atomic_flush = decon_atomic_flush, |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 542 | }; |
| 543 | |
| 544 | static int decon_bind(struct device *dev, struct device *master, void *data) |
| 545 | { |
| 546 | struct decon_context *ctx = dev_get_drvdata(dev); |
| 547 | struct drm_device *drm_dev = data; |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 548 | struct exynos_drm_plane *exynos_plane; |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 549 | enum exynos_drm_output_type out_type; |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 550 | unsigned int win; |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 551 | int ret; |
| 552 | |
| 553 | ctx->drm_dev = drm_dev; |
Andrzej Hajda | 0586feb | 2017-03-15 15:41:02 +0100 | [diff] [blame] | 554 | drm_dev->max_vblank_count = 0xffffffff; |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 555 | |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 556 | for (win = ctx->first_win; win < WINDOWS_NR; win++) { |
| 557 | int tmp = (win == ctx->first_win) ? 0 : win; |
| 558 | |
Marek Szyprowski | fd2d2fc | 2015-11-30 14:53:25 +0100 | [diff] [blame] | 559 | ctx->configs[win].pixel_formats = decon_formats; |
| 560 | ctx->configs[win].num_pixel_formats = ARRAY_SIZE(decon_formats); |
| 561 | ctx->configs[win].zpos = win; |
| 562 | ctx->configs[win].type = decon_win_types[tmp]; |
| 563 | |
Marek Szyprowski | 40bdfb0 | 2015-12-16 13:21:42 +0100 | [diff] [blame] | 564 | ret = exynos_plane_init(drm_dev, &ctx->planes[win], win, |
Andrzej Hajda | 2c82607 | 2017-03-15 15:41:05 +0100 | [diff] [blame] | 565 | &ctx->configs[win]); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 566 | if (ret) |
| 567 | return ret; |
| 568 | } |
| 569 | |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 570 | exynos_plane = &ctx->planes[ctx->first_win]; |
Inki Dae | 9ac26de | 2016-04-18 17:59:01 +0900 | [diff] [blame] | 571 | out_type = (ctx->out_type & IFTYPE_HDMI) ? EXYNOS_DISPLAY_TYPE_HDMI |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 572 | : EXYNOS_DISPLAY_TYPE_LCD; |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 573 | ctx->crtc = exynos_drm_crtc_create(drm_dev, &exynos_plane->base, |
Andrzej Hajda | d644951 | 2017-05-29 10:05:25 +0900 | [diff] [blame] | 574 | out_type, &decon_crtc_ops, ctx); |
Andrzej Hajda | f44d3d2 | 2017-03-15 15:41:04 +0100 | [diff] [blame] | 575 | if (IS_ERR(ctx->crtc)) |
| 576 | return PTR_ERR(ctx->crtc); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 577 | |
Joonyoung Shim | eb7a3fc | 2015-07-02 21:49:39 +0900 | [diff] [blame] | 578 | decon_clear_channels(ctx->crtc); |
| 579 | |
Andrzej Hajda | f44d3d2 | 2017-03-15 15:41:04 +0100 | [diff] [blame] | 580 | return drm_iommu_attach_device(drm_dev, dev); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | static void decon_unbind(struct device *dev, struct device *master, void *data) |
| 584 | { |
| 585 | struct decon_context *ctx = dev_get_drvdata(dev); |
| 586 | |
| 587 | decon_disable(ctx->crtc); |
| 588 | |
| 589 | /* detach this sub driver from iommu mapping if supported. */ |
Joonyoung Shim | bf56608 | 2015-07-02 21:49:38 +0900 | [diff] [blame] | 590 | drm_iommu_detach_device(ctx->drm_dev, ctx->dev); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | static const struct component_ops decon_component_ops = { |
| 594 | .bind = decon_bind, |
| 595 | .unbind = decon_unbind, |
| 596 | }; |
| 597 | |
Andrzej Hajda | 7348833 | 2017-03-14 09:27:57 +0100 | [diff] [blame] | 598 | static void decon_handle_vblank(struct decon_context *ctx) |
| 599 | { |
| 600 | u32 frm; |
| 601 | |
| 602 | spin_lock(&ctx->vblank_lock); |
| 603 | |
| 604 | frm = decon_get_frame_count(ctx, true); |
| 605 | |
| 606 | if (frm != ctx->frame_id) { |
| 607 | /* handle only if incremented, take care of wrap-around */ |
| 608 | if ((s32)(frm - ctx->frame_id) > 0) |
| 609 | drm_crtc_handle_vblank(&ctx->crtc->base); |
| 610 | ctx->frame_id = frm; |
| 611 | } |
| 612 | |
| 613 | spin_unlock(&ctx->vblank_lock); |
| 614 | } |
| 615 | |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 616 | static irqreturn_t decon_irq_handler(int irq, void *dev_id) |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 617 | { |
| 618 | struct decon_context *ctx = dev_id; |
| 619 | u32 val; |
| 620 | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 621 | val = readl(ctx->addr + DECON_VIDINTCON1); |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 622 | val &= VIDINTCON1_INTFRMDONEPEND | VIDINTCON1_INTFRMPEND; |
| 623 | |
| 624 | if (val) { |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 625 | writel(val, ctx->addr + DECON_VIDINTCON1); |
Andrzej Hajda | 1514d50 | 2017-01-20 07:52:24 +0100 | [diff] [blame] | 626 | if (ctx->out_type & IFTYPE_HDMI) { |
| 627 | val = readl(ctx->addr + DECON_VIDOUTCON0); |
| 628 | val &= VIDOUT_INTERLACE_EN_F | VIDOUT_INTERLACE_FIELD_F; |
| 629 | if (val == |
| 630 | (VIDOUT_INTERLACE_EN_F | VIDOUT_INTERLACE_FIELD_F)) |
| 631 | return IRQ_HANDLED; |
| 632 | } |
Andrzej Hajda | 7348833 | 2017-03-14 09:27:57 +0100 | [diff] [blame] | 633 | decon_handle_vblank(ctx); |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 634 | } |
| 635 | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 636 | return IRQ_HANDLED; |
| 637 | } |
| 638 | |
Gustavo Padovan | ebf3fd4 | 2015-11-02 20:54:55 +0900 | [diff] [blame] | 639 | #ifdef CONFIG_PM |
| 640 | static int exynos5433_decon_suspend(struct device *dev) |
| 641 | { |
| 642 | struct decon_context *ctx = dev_get_drvdata(dev); |
Andrzej Hajda | 92c96ff | 2016-02-11 12:25:04 +0100 | [diff] [blame] | 643 | int i = ARRAY_SIZE(decon_clks_name); |
Gustavo Padovan | ebf3fd4 | 2015-11-02 20:54:55 +0900 | [diff] [blame] | 644 | |
Andrzej Hajda | 92c96ff | 2016-02-11 12:25:04 +0100 | [diff] [blame] | 645 | while (--i >= 0) |
Gustavo Padovan | ebf3fd4 | 2015-11-02 20:54:55 +0900 | [diff] [blame] | 646 | clk_disable_unprepare(ctx->clks[i]); |
| 647 | |
| 648 | return 0; |
| 649 | } |
| 650 | |
| 651 | static int exynos5433_decon_resume(struct device *dev) |
| 652 | { |
| 653 | struct decon_context *ctx = dev_get_drvdata(dev); |
| 654 | int i, ret; |
| 655 | |
| 656 | for (i = 0; i < ARRAY_SIZE(decon_clks_name); i++) { |
| 657 | ret = clk_prepare_enable(ctx->clks[i]); |
| 658 | if (ret < 0) |
| 659 | goto err; |
| 660 | } |
| 661 | |
| 662 | return 0; |
| 663 | |
| 664 | err: |
| 665 | while (--i >= 0) |
| 666 | clk_disable_unprepare(ctx->clks[i]); |
| 667 | |
| 668 | return ret; |
| 669 | } |
| 670 | #endif |
| 671 | |
| 672 | static const struct dev_pm_ops exynos5433_decon_pm_ops = { |
| 673 | SET_RUNTIME_PM_OPS(exynos5433_decon_suspend, exynos5433_decon_resume, |
| 674 | NULL) |
| 675 | }; |
| 676 | |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 677 | static const struct of_device_id exynos5433_decon_driver_dt_match[] = { |
| 678 | { |
| 679 | .compatible = "samsung,exynos5433-decon", |
Inki Dae | 9ac26de | 2016-04-18 17:59:01 +0900 | [diff] [blame] | 680 | .data = (void *)I80_HW_TRG |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 681 | }, |
| 682 | { |
| 683 | .compatible = "samsung,exynos5433-decon-tv", |
Inki Dae | 9ac26de | 2016-04-18 17:59:01 +0900 | [diff] [blame] | 684 | .data = (void *)(I80_HW_TRG | IFTYPE_HDMI) |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 685 | }, |
| 686 | {}, |
| 687 | }; |
| 688 | MODULE_DEVICE_TABLE(of, exynos5433_decon_driver_dt_match); |
| 689 | |
Andrzej Hajda | b37d53a | 2017-04-05 09:28:32 +0200 | [diff] [blame] | 690 | static int decon_conf_irq(struct decon_context *ctx, const char *name, |
Andrzej Hajda | 34c3db6 | 2017-08-24 15:33:55 +0200 | [diff] [blame] | 691 | irq_handler_t handler, unsigned long int flags) |
Andrzej Hajda | b37d53a | 2017-04-05 09:28:32 +0200 | [diff] [blame] | 692 | { |
| 693 | struct platform_device *pdev = to_platform_device(ctx->dev); |
| 694 | int ret, irq = platform_get_irq_byname(pdev, name); |
| 695 | |
| 696 | if (irq < 0) { |
Andrzej Hajda | 34c3db6 | 2017-08-24 15:33:55 +0200 | [diff] [blame] | 697 | switch (irq) { |
| 698 | case -EPROBE_DEFER: |
Andrzej Hajda | b37d53a | 2017-04-05 09:28:32 +0200 | [diff] [blame] | 699 | return irq; |
Andrzej Hajda | 34c3db6 | 2017-08-24 15:33:55 +0200 | [diff] [blame] | 700 | case -ENODATA: |
| 701 | case -ENXIO: |
| 702 | return 0; |
| 703 | default: |
| 704 | dev_err(ctx->dev, "IRQ %s get failed, %d\n", name, irq); |
| 705 | return irq; |
| 706 | } |
Andrzej Hajda | b37d53a | 2017-04-05 09:28:32 +0200 | [diff] [blame] | 707 | } |
| 708 | irq_set_status_flags(irq, IRQ_NOAUTOEN); |
| 709 | ret = devm_request_irq(ctx->dev, irq, handler, flags, "drm_decon", ctx); |
| 710 | if (ret < 0) { |
| 711 | dev_err(ctx->dev, "IRQ %s request failed\n", name); |
| 712 | return ret; |
| 713 | } |
| 714 | |
| 715 | return irq; |
| 716 | } |
| 717 | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 718 | static int exynos5433_decon_probe(struct platform_device *pdev) |
| 719 | { |
| 720 | struct device *dev = &pdev->dev; |
| 721 | struct decon_context *ctx; |
| 722 | struct resource *res; |
| 723 | int ret; |
| 724 | int i; |
| 725 | |
| 726 | ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); |
| 727 | if (!ctx) |
| 728 | return -ENOMEM; |
| 729 | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 730 | ctx->dev = dev; |
Inki Dae | 9ac26de | 2016-04-18 17:59:01 +0900 | [diff] [blame] | 731 | ctx->out_type = (unsigned long)of_device_get_match_data(dev); |
Andrzej Hajda | 7348833 | 2017-03-14 09:27:57 +0100 | [diff] [blame] | 732 | spin_lock_init(&ctx->vblank_lock); |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 733 | |
Andrzej Hajda | 461e60e | 2017-08-24 15:33:57 +0200 | [diff] [blame] | 734 | if (ctx->out_type & IFTYPE_HDMI) |
Andrzej Hajda | b818283 | 2015-10-20 18:22:41 +0900 | [diff] [blame] | 735 | ctx->first_win = 1; |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 736 | |
| 737 | for (i = 0; i < ARRAY_SIZE(decon_clks_name); i++) { |
| 738 | struct clk *clk; |
| 739 | |
| 740 | clk = devm_clk_get(ctx->dev, decon_clks_name[i]); |
| 741 | if (IS_ERR(clk)) |
| 742 | return PTR_ERR(clk); |
| 743 | |
| 744 | ctx->clks[i] = clk; |
| 745 | } |
| 746 | |
| 747 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 748 | if (!res) { |
| 749 | dev_err(dev, "cannot find IO resource\n"); |
| 750 | return -ENXIO; |
| 751 | } |
| 752 | |
| 753 | ctx->addr = devm_ioremap_resource(dev, res); |
| 754 | if (IS_ERR(ctx->addr)) { |
| 755 | dev_err(dev, "ioremap failed\n"); |
| 756 | return PTR_ERR(ctx->addr); |
| 757 | } |
| 758 | |
Andrzej Hajda | 34c3db6 | 2017-08-24 15:33:55 +0200 | [diff] [blame] | 759 | ret = decon_conf_irq(ctx, "vsync", decon_irq_handler, 0); |
| 760 | if (ret < 0) |
| 761 | return ret; |
| 762 | ctx->irq_vsync = ret; |
Andrzej Hajda | b37d53a | 2017-04-05 09:28:32 +0200 | [diff] [blame] | 763 | |
Andrzej Hajda | 34c3db6 | 2017-08-24 15:33:55 +0200 | [diff] [blame] | 764 | ret = decon_conf_irq(ctx, "lcd_sys", decon_irq_handler, 0); |
| 765 | if (ret < 0) |
| 766 | return ret; |
| 767 | ctx->irq_lcd_sys = ret; |
| 768 | |
Andrzej Hajda | 34c3db6 | 2017-08-24 15:33:55 +0200 | [diff] [blame] | 769 | ret = decon_conf_irq(ctx, "te", decon_te_irq_handler, |
| 770 | IRQF_TRIGGER_RISING); |
| 771 | if (ret < 0) |
Andrzej Hajda | b37d53a | 2017-04-05 09:28:32 +0200 | [diff] [blame] | 772 | return ret; |
Andrzej Hajda | 34c3db6 | 2017-08-24 15:33:55 +0200 | [diff] [blame] | 773 | if (ret) { |
| 774 | ctx->te_irq = ret; |
| 775 | ctx->out_type &= ~I80_HW_TRG; |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 776 | } |
| 777 | |
Andrzej Hajda | b37d53a | 2017-04-05 09:28:32 +0200 | [diff] [blame] | 778 | if (ctx->out_type & I80_HW_TRG) { |
| 779 | ctx->sysreg = syscon_regmap_lookup_by_phandle(dev->of_node, |
| 780 | "samsung,disp-sysreg"); |
| 781 | if (IS_ERR(ctx->sysreg)) { |
| 782 | dev_err(dev, "failed to get system register\n"); |
| 783 | return PTR_ERR(ctx->sysreg); |
| 784 | } |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | platform_set_drvdata(pdev, ctx); |
| 788 | |
| 789 | pm_runtime_enable(dev); |
| 790 | |
| 791 | ret = component_add(dev, &decon_component_ops); |
| 792 | if (ret) |
| 793 | goto err_disable_pm_runtime; |
| 794 | |
| 795 | return 0; |
| 796 | |
| 797 | err_disable_pm_runtime: |
| 798 | pm_runtime_disable(dev); |
| 799 | |
| 800 | return ret; |
| 801 | } |
| 802 | |
| 803 | static int exynos5433_decon_remove(struct platform_device *pdev) |
| 804 | { |
| 805 | pm_runtime_disable(&pdev->dev); |
| 806 | |
| 807 | component_del(&pdev->dev, &decon_component_ops); |
| 808 | |
| 809 | return 0; |
| 810 | } |
| 811 | |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 812 | struct platform_driver exynos5433_decon_driver = { |
| 813 | .probe = exynos5433_decon_probe, |
| 814 | .remove = exynos5433_decon_remove, |
| 815 | .driver = { |
| 816 | .name = "exynos5433-decon", |
Gustavo Padovan | ebf3fd4 | 2015-11-02 20:54:55 +0900 | [diff] [blame] | 817 | .pm = &exynos5433_decon_pm_ops, |
Joonyoung Shim | c8466a9 | 2015-06-12 21:59:00 +0900 | [diff] [blame] | 818 | .of_match_table = exynos5433_decon_driver_dt_match, |
| 819 | }, |
| 820 | }; |