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