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