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