Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Russell King |
| 3 | * Rewritten from the dovefb driver, and Armada510 manuals. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation. |
| 8 | */ |
| 9 | #include <linux/clk.h> |
Russell King | d8c9608 | 2014-04-22 11:10:15 +0100 | [diff] [blame] | 10 | #include <linux/component.h> |
| 11 | #include <linux/of_device.h> |
| 12 | #include <linux/platform_device.h> |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 13 | #include <drm/drmP.h> |
| 14 | #include <drm/drm_crtc_helper.h> |
Daniel Vetter | 3cb9ae4 | 2014-10-29 10:03:57 +0100 | [diff] [blame] | 15 | #include <drm/drm_plane_helper.h> |
Dave Airlie | bcd21a4 | 2018-01-05 09:43:46 +1000 | [diff] [blame] | 16 | #include <drm/drm_atomic_helper.h> |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 17 | #include "armada_crtc.h" |
| 18 | #include "armada_drm.h" |
| 19 | #include "armada_fb.h" |
| 20 | #include "armada_gem.h" |
| 21 | #include "armada_hw.h" |
Russell King | c8a220c | 2016-05-17 13:51:08 +0100 | [diff] [blame] | 22 | #include "armada_trace.h" |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 23 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 24 | enum csc_mode { |
| 25 | CSC_AUTO = 0, |
| 26 | CSC_YUV_CCIR601 = 1, |
| 27 | CSC_YUV_CCIR709 = 2, |
| 28 | CSC_RGB_COMPUTER = 1, |
| 29 | CSC_RGB_STUDIO = 2, |
| 30 | }; |
| 31 | |
Russell King | 1c914ce | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 32 | static const uint32_t armada_primary_formats[] = { |
| 33 | DRM_FORMAT_UYVY, |
| 34 | DRM_FORMAT_YUYV, |
| 35 | DRM_FORMAT_VYUY, |
| 36 | DRM_FORMAT_YVYU, |
| 37 | DRM_FORMAT_ARGB8888, |
| 38 | DRM_FORMAT_ABGR8888, |
| 39 | DRM_FORMAT_XRGB8888, |
| 40 | DRM_FORMAT_XBGR8888, |
| 41 | DRM_FORMAT_RGB888, |
| 42 | DRM_FORMAT_BGR888, |
| 43 | DRM_FORMAT_ARGB1555, |
| 44 | DRM_FORMAT_ABGR1555, |
| 45 | DRM_FORMAT_RGB565, |
| 46 | DRM_FORMAT_BGR565, |
| 47 | }; |
| 48 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 49 | /* |
| 50 | * A note about interlacing. Let's consider HDMI 1920x1080i. |
| 51 | * The timing parameters we have from X are: |
| 52 | * Hact HsyA HsyI Htot Vact VsyA VsyI Vtot |
| 53 | * 1920 2448 2492 2640 1080 1084 1094 1125 |
| 54 | * Which get translated to: |
| 55 | * Hact HsyA HsyI Htot Vact VsyA VsyI Vtot |
| 56 | * 1920 2448 2492 2640 540 542 547 562 |
| 57 | * |
| 58 | * This is how it is defined by CEA-861-D - line and pixel numbers are |
| 59 | * referenced to the rising edge of VSYNC and HSYNC. Total clocks per |
| 60 | * line: 2640. The odd frame, the first active line is at line 21, and |
| 61 | * the even frame, the first active line is 584. |
| 62 | * |
| 63 | * LN: 560 561 562 563 567 568 569 |
| 64 | * DE: ~~~|____________________________//__________________________ |
| 65 | * HSYNC: ____|~|_____|~|_____|~|_____|~|_//__|~|_____|~|_____|~|_____ |
| 66 | * VSYNC: _________________________|~~~~~~//~~~~~~~~~~~~~~~|__________ |
| 67 | * 22 blanking lines. VSYNC at 1320 (referenced to the HSYNC rising edge). |
| 68 | * |
| 69 | * LN: 1123 1124 1125 1 5 6 7 |
| 70 | * DE: ~~~|____________________________//__________________________ |
| 71 | * HSYNC: ____|~|_____|~|_____|~|_____|~|_//__|~|_____|~|_____|~|_____ |
| 72 | * VSYNC: ____________________|~~~~~~~~~~~//~~~~~~~~~~|_______________ |
| 73 | * 23 blanking lines |
| 74 | * |
| 75 | * The Armada LCD Controller line and pixel numbers are, like X timings, |
| 76 | * referenced to the top left of the active frame. |
| 77 | * |
| 78 | * So, translating these to our LCD controller: |
| 79 | * Odd frame, 563 total lines, VSYNC at line 543-548, pixel 1128. |
| 80 | * Even frame, 562 total lines, VSYNC at line 542-547, pixel 2448. |
| 81 | * Note: Vsync front porch remains constant! |
| 82 | * |
| 83 | * if (odd_frame) { |
| 84 | * vtotal = mode->crtc_vtotal + 1; |
| 85 | * vbackporch = mode->crtc_vsync_start - mode->crtc_vdisplay + 1; |
| 86 | * vhorizpos = mode->crtc_hsync_start - mode->crtc_htotal / 2 |
| 87 | * } else { |
| 88 | * vtotal = mode->crtc_vtotal; |
| 89 | * vbackporch = mode->crtc_vsync_start - mode->crtc_vdisplay; |
| 90 | * vhorizpos = mode->crtc_hsync_start; |
| 91 | * } |
| 92 | * vfrontporch = mode->crtc_vtotal - mode->crtc_vsync_end; |
| 93 | * |
| 94 | * So, we need to reprogram these registers on each vsync event: |
| 95 | * LCD_SPU_V_PORCH, LCD_SPU_ADV_REG, LCD_SPUT_V_H_TOTAL |
| 96 | * |
| 97 | * Note: we do not use the frame done interrupts because these appear |
| 98 | * to happen too early, and lead to jitter on the display (presumably |
| 99 | * they occur at the end of the last active line, before the vsync back |
| 100 | * porch, which we're reprogramming.) |
| 101 | */ |
| 102 | |
| 103 | void |
| 104 | armada_drm_crtc_update_regs(struct armada_crtc *dcrtc, struct armada_regs *regs) |
| 105 | { |
| 106 | while (regs->offset != ~0) { |
| 107 | void __iomem *reg = dcrtc->base + regs->offset; |
| 108 | uint32_t val; |
| 109 | |
| 110 | val = regs->mask; |
| 111 | if (val != 0) |
| 112 | val &= readl_relaxed(reg); |
| 113 | writel_relaxed(val | regs->val, reg); |
| 114 | ++regs; |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | #define dpms_blanked(dpms) ((dpms) != DRM_MODE_DPMS_ON) |
| 119 | |
| 120 | static void armada_drm_crtc_update(struct armada_crtc *dcrtc) |
| 121 | { |
| 122 | uint32_t dumb_ctrl; |
| 123 | |
| 124 | dumb_ctrl = dcrtc->cfg_dumb_ctrl; |
| 125 | |
| 126 | if (!dpms_blanked(dcrtc->dpms)) |
| 127 | dumb_ctrl |= CFG_DUMB_ENA; |
| 128 | |
| 129 | /* |
| 130 | * When the dumb interface isn't in DUMB24_RGB888_0 mode, it might |
| 131 | * be using SPI or GPIO. If we set this to DUMB_BLANK, we will |
| 132 | * force LCD_D[23:0] to output blank color, overriding the GPIO or |
| 133 | * SPI usage. So leave it as-is unless in DUMB24_RGB888_0 mode. |
| 134 | */ |
| 135 | if (dpms_blanked(dcrtc->dpms) && |
| 136 | (dumb_ctrl & DUMB_MASK) == DUMB24_RGB888_0) { |
| 137 | dumb_ctrl &= ~DUMB_MASK; |
| 138 | dumb_ctrl |= DUMB_BLANK; |
| 139 | } |
| 140 | |
| 141 | /* |
| 142 | * The documentation doesn't indicate what the normal state of |
| 143 | * the sync signals are. Sebastian Hesselbart kindly probed |
| 144 | * these signals on his board to determine their state. |
| 145 | * |
| 146 | * The non-inverted state of the sync signals is active high. |
| 147 | * Setting these bits makes the appropriate signal active low. |
| 148 | */ |
| 149 | if (dcrtc->crtc.mode.flags & DRM_MODE_FLAG_NCSYNC) |
| 150 | dumb_ctrl |= CFG_INV_CSYNC; |
| 151 | if (dcrtc->crtc.mode.flags & DRM_MODE_FLAG_NHSYNC) |
| 152 | dumb_ctrl |= CFG_INV_HSYNC; |
| 153 | if (dcrtc->crtc.mode.flags & DRM_MODE_FLAG_NVSYNC) |
| 154 | dumb_ctrl |= CFG_INV_VSYNC; |
| 155 | |
| 156 | if (dcrtc->dumb_ctrl != dumb_ctrl) { |
| 157 | dcrtc->dumb_ctrl = dumb_ctrl; |
| 158 | writel_relaxed(dumb_ctrl, dcrtc->base + LCD_SPU_DUMB_CTRL); |
| 159 | } |
| 160 | } |
| 161 | |
Russell King | f0b2487 | 2016-08-16 22:09:11 +0100 | [diff] [blame] | 162 | void armada_drm_plane_calc_addrs(u32 *addrs, struct drm_framebuffer *fb, |
| 163 | int x, int y) |
| 164 | { |
Russell King | d6a4896 | 2017-12-08 12:16:22 +0000 | [diff] [blame] | 165 | const struct drm_format_info *format = fb->format; |
| 166 | unsigned int num_planes = format->num_planes; |
Russell King | f0b2487 | 2016-08-16 22:09:11 +0100 | [diff] [blame] | 167 | u32 addr = drm_fb_obj(fb)->dev_addr; |
Russell King | f0b2487 | 2016-08-16 22:09:11 +0100 | [diff] [blame] | 168 | int i; |
| 169 | |
| 170 | if (num_planes > 3) |
| 171 | num_planes = 3; |
| 172 | |
Russell King | de0ea9a | 2017-12-08 12:16:22 +0000 | [diff] [blame] | 173 | addrs[0] = addr + fb->offsets[0] + y * fb->pitches[0] + |
| 174 | x * format->cpp[0]; |
| 175 | |
| 176 | y /= format->vsub; |
| 177 | x /= format->hsub; |
| 178 | |
| 179 | for (i = 1; i < num_planes; i++) |
Russell King | f0b2487 | 2016-08-16 22:09:11 +0100 | [diff] [blame] | 180 | addrs[i] = addr + fb->offsets[i] + y * fb->pitches[i] + |
Russell King | d6a4896 | 2017-12-08 12:16:22 +0000 | [diff] [blame] | 181 | x * format->cpp[i]; |
Russell King | f0b2487 | 2016-08-16 22:09:11 +0100 | [diff] [blame] | 182 | for (; i < 3; i++) |
| 183 | addrs[i] = 0; |
| 184 | } |
| 185 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 186 | static unsigned armada_drm_crtc_calc_fb(struct drm_framebuffer *fb, |
| 187 | int x, int y, struct armada_regs *regs, bool interlaced) |
| 188 | { |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 189 | unsigned pitch = fb->pitches[0]; |
Russell King | f0b2487 | 2016-08-16 22:09:11 +0100 | [diff] [blame] | 190 | u32 addrs[3], addr_odd, addr_even; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 191 | unsigned i = 0; |
| 192 | |
| 193 | DRM_DEBUG_DRIVER("pitch %u x %d y %d bpp %d\n", |
Ville Syrjälä | 272725c | 2016-12-14 23:32:20 +0200 | [diff] [blame] | 194 | pitch, x, y, fb->format->cpp[0] * 8); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 195 | |
Russell King | f0b2487 | 2016-08-16 22:09:11 +0100 | [diff] [blame] | 196 | armada_drm_plane_calc_addrs(addrs, fb, x, y); |
| 197 | |
| 198 | addr_odd = addr_even = addrs[0]; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 199 | |
| 200 | if (interlaced) { |
| 201 | addr_even += pitch; |
| 202 | pitch *= 2; |
| 203 | } |
| 204 | |
| 205 | /* write offset, base, and pitch */ |
| 206 | armada_reg_queue_set(regs, i, addr_odd, LCD_CFG_GRA_START_ADDR0); |
| 207 | armada_reg_queue_set(regs, i, addr_even, LCD_CFG_GRA_START_ADDR1); |
| 208 | armada_reg_queue_mod(regs, i, pitch, 0xffff, LCD_CFG_GRA_PITCH); |
| 209 | |
| 210 | return i; |
| 211 | } |
| 212 | |
Russell King | 2839d45 | 2017-07-07 15:56:20 +0100 | [diff] [blame] | 213 | static void armada_drm_plane_work_call(struct armada_crtc *dcrtc, |
| 214 | struct armada_plane_work *work, |
| 215 | void (*fn)(struct armada_crtc *, struct armada_plane_work *)) |
| 216 | { |
| 217 | struct armada_plane *dplane = drm_to_armada_plane(work->plane); |
Russell King | d924155 | 2017-07-08 10:22:25 +0100 | [diff] [blame] | 218 | struct drm_pending_vblank_event *event; |
| 219 | struct drm_framebuffer *fb; |
Russell King | 2839d45 | 2017-07-07 15:56:20 +0100 | [diff] [blame] | 220 | |
| 221 | if (fn) |
| 222 | fn(dcrtc, work); |
| 223 | drm_crtc_vblank_put(&dcrtc->crtc); |
| 224 | |
Russell King | d924155 | 2017-07-08 10:22:25 +0100 | [diff] [blame] | 225 | event = work->event; |
| 226 | fb = work->old_fb; |
Russell King | eb19be5 | 2017-07-08 10:16:53 +0100 | [diff] [blame] | 227 | if (event || fb) { |
| 228 | struct drm_device *dev = dcrtc->crtc.dev; |
| 229 | unsigned long flags; |
| 230 | |
| 231 | spin_lock_irqsave(&dev->event_lock, flags); |
| 232 | if (event) |
| 233 | drm_crtc_send_vblank_event(&dcrtc->crtc, event); |
| 234 | if (fb) |
| 235 | __armada_drm_queue_unref_work(dev, fb); |
| 236 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 237 | } |
Russell King | b972a80 | 2017-07-08 10:16:52 +0100 | [diff] [blame] | 238 | |
Russell King | d924155 | 2017-07-08 10:22:25 +0100 | [diff] [blame] | 239 | if (work->need_kfree) |
| 240 | kfree(work); |
| 241 | |
Russell King | 2839d45 | 2017-07-07 15:56:20 +0100 | [diff] [blame] | 242 | wake_up(&dplane->frame_wait); |
| 243 | } |
| 244 | |
Russell King | 4b5dda8 | 2015-08-06 16:37:18 +0100 | [diff] [blame] | 245 | static void armada_drm_plane_work_run(struct armada_crtc *dcrtc, |
Russell King | ec6fb15 | 2016-07-25 15:16:11 +0100 | [diff] [blame] | 246 | struct drm_plane *plane) |
Russell King | 4b5dda8 | 2015-08-06 16:37:18 +0100 | [diff] [blame] | 247 | { |
Russell King | ec6fb15 | 2016-07-25 15:16:11 +0100 | [diff] [blame] | 248 | struct armada_plane *dplane = drm_to_armada_plane(plane); |
| 249 | struct armada_plane_work *work = xchg(&dplane->work, NULL); |
Russell King | 4b5dda8 | 2015-08-06 16:37:18 +0100 | [diff] [blame] | 250 | |
| 251 | /* Handle any pending frame work. */ |
Russell King | 2839d45 | 2017-07-07 15:56:20 +0100 | [diff] [blame] | 252 | if (work) |
| 253 | armada_drm_plane_work_call(dcrtc, work, work->fn); |
Russell King | 4b5dda8 | 2015-08-06 16:37:18 +0100 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | int armada_drm_plane_work_queue(struct armada_crtc *dcrtc, |
Russell King | eaab013 | 2017-07-07 15:55:53 +0100 | [diff] [blame] | 257 | struct armada_plane_work *work) |
Russell King | 4b5dda8 | 2015-08-06 16:37:18 +0100 | [diff] [blame] | 258 | { |
Russell King | eaab013 | 2017-07-07 15:55:53 +0100 | [diff] [blame] | 259 | struct armada_plane *plane = drm_to_armada_plane(work->plane); |
Russell King | 4b5dda8 | 2015-08-06 16:37:18 +0100 | [diff] [blame] | 260 | int ret; |
| 261 | |
Gustavo Padovan | accbaf6 | 2016-06-06 11:41:40 -0300 | [diff] [blame] | 262 | ret = drm_crtc_vblank_get(&dcrtc->crtc); |
Russell King | c93dfdc | 2017-07-08 10:22:23 +0100 | [diff] [blame] | 263 | if (ret) |
Russell King | 4b5dda8 | 2015-08-06 16:37:18 +0100 | [diff] [blame] | 264 | return ret; |
Russell King | 4b5dda8 | 2015-08-06 16:37:18 +0100 | [diff] [blame] | 265 | |
| 266 | ret = cmpxchg(&plane->work, NULL, work) ? -EBUSY : 0; |
| 267 | if (ret) |
Gustavo Padovan | accbaf6 | 2016-06-06 11:41:40 -0300 | [diff] [blame] | 268 | drm_crtc_vblank_put(&dcrtc->crtc); |
Russell King | 4b5dda8 | 2015-08-06 16:37:18 +0100 | [diff] [blame] | 269 | |
| 270 | return ret; |
| 271 | } |
| 272 | |
| 273 | int armada_drm_plane_work_wait(struct armada_plane *plane, long timeout) |
| 274 | { |
| 275 | return wait_event_timeout(plane->frame_wait, !plane->work, timeout); |
| 276 | } |
| 277 | |
Russell King | d3b8421 | 2017-07-07 15:55:40 +0100 | [diff] [blame] | 278 | void armada_drm_plane_work_cancel(struct armada_crtc *dcrtc, |
| 279 | struct armada_plane *dplane) |
Russell King | 7c8f7e1 | 2015-06-29 17:52:16 +0100 | [diff] [blame] | 280 | { |
Russell King | d3b8421 | 2017-07-07 15:55:40 +0100 | [diff] [blame] | 281 | struct armada_plane_work *work = xchg(&dplane->work, NULL); |
Russell King | 7c8f7e1 | 2015-06-29 17:52:16 +0100 | [diff] [blame] | 282 | |
Russell King | 4a8506d | 2015-08-07 09:33:05 +0100 | [diff] [blame] | 283 | if (work) |
Russell King | 2839d45 | 2017-07-07 15:56:20 +0100 | [diff] [blame] | 284 | armada_drm_plane_work_call(dcrtc, work, work->cancel); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 285 | } |
| 286 | |
Russell King | 709ffd8 | 2015-07-15 18:09:38 +0100 | [diff] [blame] | 287 | static void armada_drm_crtc_complete_frame_work(struct armada_crtc *dcrtc, |
Russell King | 65724a1 | 2017-07-07 15:56:24 +0100 | [diff] [blame] | 288 | struct armada_plane_work *work) |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 289 | { |
Russell King | 709ffd8 | 2015-07-15 18:09:38 +0100 | [diff] [blame] | 290 | unsigned long flags; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 291 | |
Russell King | 709ffd8 | 2015-07-15 18:09:38 +0100 | [diff] [blame] | 292 | spin_lock_irqsave(&dcrtc->irq_lock, flags); |
Russell King | eaa6627 | 2017-07-08 10:22:10 +0100 | [diff] [blame] | 293 | armada_drm_crtc_update_regs(dcrtc, work->regs); |
Russell King | 709ffd8 | 2015-07-15 18:09:38 +0100 | [diff] [blame] | 294 | spin_unlock_irqrestore(&dcrtc->irq_lock, flags); |
Russell King | 65724a1 | 2017-07-07 15:56:24 +0100 | [diff] [blame] | 295 | } |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 296 | |
Russell King | 890ca8d | 2017-07-08 10:22:27 +0100 | [diff] [blame] | 297 | static void armada_drm_crtc_complete_disable_work(struct armada_crtc *dcrtc, |
| 298 | struct armada_plane_work *work) |
| 299 | { |
| 300 | unsigned long flags; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 301 | |
Russell King | 890ca8d | 2017-07-08 10:22:27 +0100 | [diff] [blame] | 302 | if (dcrtc->plane == work->plane) |
| 303 | dcrtc->plane = NULL; |
| 304 | |
| 305 | spin_lock_irqsave(&dcrtc->irq_lock, flags); |
| 306 | armada_drm_crtc_update_regs(dcrtc, work->regs); |
| 307 | spin_unlock_irqrestore(&dcrtc->irq_lock, flags); |
| 308 | } |
| 309 | |
Russell King | eaa6627 | 2017-07-08 10:22:10 +0100 | [diff] [blame] | 310 | static struct armada_plane_work * |
| 311 | armada_drm_crtc_alloc_plane_work(struct drm_plane *plane) |
Russell King | 901bb88 | 2017-07-07 15:55:45 +0100 | [diff] [blame] | 312 | { |
Russell King | eaa6627 | 2017-07-08 10:22:10 +0100 | [diff] [blame] | 313 | struct armada_plane_work *work; |
Russell King | 901bb88 | 2017-07-07 15:55:45 +0100 | [diff] [blame] | 314 | int i = 0; |
| 315 | |
| 316 | work = kzalloc(sizeof(*work), GFP_KERNEL); |
| 317 | if (!work) |
| 318 | return NULL; |
| 319 | |
Russell King | eaa6627 | 2017-07-08 10:22:10 +0100 | [diff] [blame] | 320 | work->plane = plane; |
| 321 | work->fn = armada_drm_crtc_complete_frame_work; |
Russell King | d924155 | 2017-07-08 10:22:25 +0100 | [diff] [blame] | 322 | work->need_kfree = true; |
Russell King | 901bb88 | 2017-07-07 15:55:45 +0100 | [diff] [blame] | 323 | armada_reg_queue_end(work->regs, i); |
| 324 | |
| 325 | return work; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 326 | } |
| 327 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 328 | static void armada_drm_vblank_off(struct armada_crtc *dcrtc) |
| 329 | { |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 330 | /* |
| 331 | * Tell the DRM core that vblank IRQs aren't going to happen for |
| 332 | * a while. This cleans up any pending vblank events for us. |
| 333 | */ |
Russell King | 178e561 | 2014-10-11 23:57:04 +0100 | [diff] [blame] | 334 | drm_crtc_vblank_off(&dcrtc->crtc); |
Russell King | ec6fb15 | 2016-07-25 15:16:11 +0100 | [diff] [blame] | 335 | armada_drm_plane_work_run(dcrtc, dcrtc->crtc.primary); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 336 | } |
| 337 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 338 | /* The mode_config.mutex will be held for this call */ |
| 339 | static void armada_drm_crtc_dpms(struct drm_crtc *crtc, int dpms) |
| 340 | { |
| 341 | struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); |
| 342 | |
Russell King | ea908ba | 2016-10-04 22:19:57 +0100 | [diff] [blame] | 343 | if (dpms_blanked(dcrtc->dpms) != dpms_blanked(dpms)) { |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 344 | if (dpms_blanked(dpms)) |
| 345 | armada_drm_vblank_off(dcrtc); |
Russell King | ea908ba | 2016-10-04 22:19:57 +0100 | [diff] [blame] | 346 | else if (!IS_ERR(dcrtc->clk)) |
| 347 | WARN_ON(clk_prepare_enable(dcrtc->clk)); |
| 348 | dcrtc->dpms = dpms; |
| 349 | armada_drm_crtc_update(dcrtc); |
| 350 | if (!dpms_blanked(dpms)) |
Russell King | 178e561 | 2014-10-11 23:57:04 +0100 | [diff] [blame] | 351 | drm_crtc_vblank_on(&dcrtc->crtc); |
Russell King | ea908ba | 2016-10-04 22:19:57 +0100 | [diff] [blame] | 352 | else if (!IS_ERR(dcrtc->clk)) |
| 353 | clk_disable_unprepare(dcrtc->clk); |
| 354 | } else if (dcrtc->dpms != dpms) { |
| 355 | dcrtc->dpms = dpms; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 356 | } |
| 357 | } |
| 358 | |
| 359 | /* |
| 360 | * Prepare for a mode set. Turn off overlay to ensure that we don't end |
| 361 | * up with the overlay size being bigger than the active screen size. |
| 362 | * We rely upon X refreshing this state after the mode set has completed. |
| 363 | * |
| 364 | * The mode_config.mutex will be held for this call |
| 365 | */ |
| 366 | static void armada_drm_crtc_prepare(struct drm_crtc *crtc) |
| 367 | { |
| 368 | struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); |
| 369 | struct drm_plane *plane; |
Russell King | f9a13bb | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 370 | u32 val; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 371 | |
| 372 | /* |
| 373 | * If we have an overlay plane associated with this CRTC, disable |
| 374 | * it before the modeset to avoid its coordinates being outside |
Russell King | f8e1406 | 2015-06-29 17:52:42 +0100 | [diff] [blame] | 375 | * the new mode parameters. |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 376 | */ |
| 377 | plane = dcrtc->plane; |
Russell King | 890ca8d | 2017-07-08 10:22:27 +0100 | [diff] [blame] | 378 | if (plane) { |
Russell King | f8e1406 | 2015-06-29 17:52:42 +0100 | [diff] [blame] | 379 | drm_plane_force_disable(plane); |
Russell King | 890ca8d | 2017-07-08 10:22:27 +0100 | [diff] [blame] | 380 | WARN_ON(!armada_drm_plane_work_wait(drm_to_armada_plane(plane), |
| 381 | HZ)); |
| 382 | } |
Russell King | f9a13bb | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 383 | |
| 384 | /* Wait for pending flips to complete */ |
| 385 | armada_drm_plane_work_wait(drm_to_armada_plane(dcrtc->crtc.primary), |
| 386 | MAX_SCHEDULE_TIMEOUT); |
| 387 | |
| 388 | drm_crtc_vblank_off(crtc); |
| 389 | |
| 390 | val = dcrtc->dumb_ctrl & ~CFG_DUMB_ENA; |
| 391 | if (val != dcrtc->dumb_ctrl) { |
| 392 | dcrtc->dumb_ctrl = val; |
| 393 | writel_relaxed(val, dcrtc->base + LCD_SPU_DUMB_CTRL); |
| 394 | } |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | /* The mode_config.mutex will be held for this call */ |
| 398 | static void armada_drm_crtc_commit(struct drm_crtc *crtc) |
| 399 | { |
| 400 | struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); |
| 401 | |
Russell King | f9a13bb | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 402 | dcrtc->dpms = DRM_MODE_DPMS_ON; |
| 403 | armada_drm_crtc_update(dcrtc); |
| 404 | drm_crtc_vblank_on(crtc); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | /* The mode_config.mutex will be held for this call */ |
| 408 | static bool armada_drm_crtc_mode_fixup(struct drm_crtc *crtc, |
| 409 | const struct drm_display_mode *mode, struct drm_display_mode *adj) |
| 410 | { |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 411 | struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); |
| 412 | int ret; |
| 413 | |
| 414 | /* We can't do interlaced modes if we don't have the SPU_ADV_REG */ |
Russell King | 42e62ba | 2014-04-22 15:24:03 +0100 | [diff] [blame] | 415 | if (!dcrtc->variant->has_spu_adv_reg && |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 416 | adj->flags & DRM_MODE_FLAG_INTERLACE) |
| 417 | return false; |
| 418 | |
| 419 | /* Check whether the display mode is possible */ |
Russell King | 42e62ba | 2014-04-22 15:24:03 +0100 | [diff] [blame] | 420 | ret = dcrtc->variant->compute_clock(dcrtc, adj, NULL); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 421 | if (ret) |
| 422 | return false; |
| 423 | |
| 424 | return true; |
| 425 | } |
| 426 | |
Shawn Guo | 5922a7d | 2017-02-07 17:16:18 +0800 | [diff] [blame] | 427 | /* These are locked by dev->vbl_lock */ |
| 428 | static void armada_drm_crtc_disable_irq(struct armada_crtc *dcrtc, u32 mask) |
| 429 | { |
| 430 | if (dcrtc->irq_ena & mask) { |
| 431 | dcrtc->irq_ena &= ~mask; |
| 432 | writel(dcrtc->irq_ena, dcrtc->base + LCD_SPU_IRQ_ENA); |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | static void armada_drm_crtc_enable_irq(struct armada_crtc *dcrtc, u32 mask) |
| 437 | { |
| 438 | if ((dcrtc->irq_ena & mask) != mask) { |
| 439 | dcrtc->irq_ena |= mask; |
| 440 | writel(dcrtc->irq_ena, dcrtc->base + LCD_SPU_IRQ_ENA); |
| 441 | if (readl_relaxed(dcrtc->base + LCD_SPU_IRQ_ISR) & mask) |
| 442 | writel(0, dcrtc->base + LCD_SPU_IRQ_ISR); |
| 443 | } |
| 444 | } |
| 445 | |
Russell King | e5d9ddf | 2014-04-26 15:19:38 +0100 | [diff] [blame] | 446 | static void armada_drm_crtc_irq(struct armada_crtc *dcrtc, u32 stat) |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 447 | { |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 448 | void __iomem *base = dcrtc->base; |
Russell King | 4a8506d | 2015-08-07 09:33:05 +0100 | [diff] [blame] | 449 | struct drm_plane *ovl_plane; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 450 | |
| 451 | if (stat & DMA_FF_UNDERFLOW) |
| 452 | DRM_ERROR("video underflow on crtc %u\n", dcrtc->num); |
| 453 | if (stat & GRA_FF_UNDERFLOW) |
| 454 | DRM_ERROR("graphics underflow on crtc %u\n", dcrtc->num); |
| 455 | |
| 456 | if (stat & VSYNC_IRQ) |
Gustavo Padovan | 0ac28c5 | 2016-07-04 21:04:48 -0300 | [diff] [blame] | 457 | drm_crtc_handle_vblank(&dcrtc->crtc); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 458 | |
Russell King | 4a8506d | 2015-08-07 09:33:05 +0100 | [diff] [blame] | 459 | ovl_plane = dcrtc->plane; |
Russell King | ec6fb15 | 2016-07-25 15:16:11 +0100 | [diff] [blame] | 460 | if (ovl_plane) |
| 461 | armada_drm_plane_work_run(dcrtc, ovl_plane); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 462 | |
Russell King | a3f6a18 | 2017-07-08 10:16:48 +0100 | [diff] [blame] | 463 | spin_lock(&dcrtc->irq_lock); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 464 | if (stat & GRA_FRAME_IRQ && dcrtc->interlaced) { |
| 465 | int i = stat & GRA_FRAME_IRQ0 ? 0 : 1; |
| 466 | uint32_t val; |
| 467 | |
| 468 | writel_relaxed(dcrtc->v[i].spu_v_porch, base + LCD_SPU_V_PORCH); |
| 469 | writel_relaxed(dcrtc->v[i].spu_v_h_total, |
| 470 | base + LCD_SPUT_V_H_TOTAL); |
| 471 | |
| 472 | val = readl_relaxed(base + LCD_SPU_ADV_REG); |
| 473 | val &= ~(ADV_VSYNC_L_OFF | ADV_VSYNC_H_OFF | ADV_VSYNCOFFEN); |
| 474 | val |= dcrtc->v[i].spu_adv_reg; |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 475 | writel_relaxed(val, base + LCD_SPU_ADV_REG); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 476 | } |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 477 | |
| 478 | if (stat & DUMB_FRAMEDONE && dcrtc->cursor_update) { |
| 479 | writel_relaxed(dcrtc->cursor_hw_pos, |
| 480 | base + LCD_SPU_HWC_OVSA_HPXL_VLN); |
| 481 | writel_relaxed(dcrtc->cursor_hw_sz, |
| 482 | base + LCD_SPU_HWC_HPXL_VLN); |
| 483 | armada_updatel(CFG_HWC_ENA, |
| 484 | CFG_HWC_ENA | CFG_HWC_1BITMOD | CFG_HWC_1BITENA, |
| 485 | base + LCD_SPU_DMA_CTRL0); |
| 486 | dcrtc->cursor_update = false; |
| 487 | armada_drm_crtc_disable_irq(dcrtc, DUMB_FRAMEDONE_ENA); |
| 488 | } |
| 489 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 490 | spin_unlock(&dcrtc->irq_lock); |
| 491 | |
Russell King | ec6fb15 | 2016-07-25 15:16:11 +0100 | [diff] [blame] | 492 | if (stat & GRA_FRAME_IRQ) |
| 493 | armada_drm_plane_work_run(dcrtc, dcrtc->crtc.primary); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 494 | } |
| 495 | |
Russell King | e5d9ddf | 2014-04-26 15:19:38 +0100 | [diff] [blame] | 496 | static irqreturn_t armada_drm_irq(int irq, void *arg) |
| 497 | { |
| 498 | struct armada_crtc *dcrtc = arg; |
| 499 | u32 v, stat = readl_relaxed(dcrtc->base + LCD_SPU_IRQ_ISR); |
| 500 | |
| 501 | /* |
Russell King | 92298c1 | 2018-06-26 17:06:06 +0100 | [diff] [blame] | 502 | * Reading the ISR appears to clear bits provided CLEAN_SPU_IRQ_ISR |
| 503 | * is set. Writing has some other effect to acknowledge the IRQ - |
| 504 | * without this, we only get a single IRQ. |
Russell King | e5d9ddf | 2014-04-26 15:19:38 +0100 | [diff] [blame] | 505 | */ |
| 506 | writel_relaxed(0, dcrtc->base + LCD_SPU_IRQ_ISR); |
| 507 | |
Russell King | c8a220c | 2016-05-17 13:51:08 +0100 | [diff] [blame] | 508 | trace_armada_drm_irq(&dcrtc->crtc, stat); |
| 509 | |
Russell King | e5d9ddf | 2014-04-26 15:19:38 +0100 | [diff] [blame] | 510 | /* Mask out those interrupts we haven't enabled */ |
| 511 | v = stat & dcrtc->irq_ena; |
| 512 | |
| 513 | if (v & (VSYNC_IRQ|GRA_FRAME_IRQ|DUMB_FRAMEDONE)) { |
| 514 | armada_drm_crtc_irq(dcrtc, stat); |
| 515 | return IRQ_HANDLED; |
| 516 | } |
| 517 | return IRQ_NONE; |
| 518 | } |
| 519 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 520 | static uint32_t armada_drm_crtc_calculate_csc(struct armada_crtc *dcrtc) |
| 521 | { |
| 522 | struct drm_display_mode *adj = &dcrtc->crtc.mode; |
| 523 | uint32_t val = 0; |
| 524 | |
| 525 | if (dcrtc->csc_yuv_mode == CSC_YUV_CCIR709) |
| 526 | val |= CFG_CSC_YUV_CCIR709; |
| 527 | if (dcrtc->csc_rgb_mode == CSC_RGB_STUDIO) |
| 528 | val |= CFG_CSC_RGB_STUDIO; |
| 529 | |
| 530 | /* |
| 531 | * In auto mode, set the colorimetry, based upon the HDMI spec. |
| 532 | * 1280x720p, 1920x1080p and 1920x1080i use ITU709, others use |
| 533 | * ITU601. It may be more appropriate to set this depending on |
| 534 | * the source - but what if the graphic frame is YUV and the |
| 535 | * video frame is RGB? |
| 536 | */ |
| 537 | if ((adj->hdisplay == 1280 && adj->vdisplay == 720 && |
| 538 | !(adj->flags & DRM_MODE_FLAG_INTERLACE)) || |
| 539 | (adj->hdisplay == 1920 && adj->vdisplay == 1080)) { |
| 540 | if (dcrtc->csc_yuv_mode == CSC_AUTO) |
| 541 | val |= CFG_CSC_YUV_CCIR709; |
| 542 | } |
| 543 | |
| 544 | /* |
| 545 | * We assume we're connected to a TV-like device, so the YUV->RGB |
| 546 | * conversion should produce a limited range. We should set this |
| 547 | * depending on the connectors attached to this CRTC, and what |
| 548 | * kind of device they report being connected. |
| 549 | */ |
| 550 | if (dcrtc->csc_rgb_mode == CSC_AUTO) |
| 551 | val |= CFG_CSC_RGB_STUDIO; |
| 552 | |
| 553 | return val; |
| 554 | } |
| 555 | |
| 556 | /* The mode_config.mutex will be held for this call */ |
Russell King | c36045e | 2018-07-30 11:52:34 +0100 | [diff] [blame^] | 557 | static void armada_drm_crtc_mode_set_nofb(struct drm_crtc *crtc) |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 558 | { |
Russell King | c36045e | 2018-07-30 11:52:34 +0100 | [diff] [blame^] | 559 | struct drm_display_mode *adj = &crtc->state->adjusted_mode; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 560 | struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); |
| 561 | struct armada_regs regs[17]; |
| 562 | uint32_t lm, rm, tm, bm, val, sclk; |
| 563 | unsigned long flags; |
| 564 | unsigned i; |
Russell King | c36045e | 2018-07-30 11:52:34 +0100 | [diff] [blame^] | 565 | bool interlaced = !!(adj->flags & DRM_MODE_FLAG_INTERLACE); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 566 | |
Russell King | 37af35c | 2016-08-16 22:09:09 +0100 | [diff] [blame] | 567 | i = 0; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 568 | rm = adj->crtc_hsync_start - adj->crtc_hdisplay; |
| 569 | lm = adj->crtc_htotal - adj->crtc_hsync_end; |
| 570 | bm = adj->crtc_vsync_start - adj->crtc_vdisplay; |
| 571 | tm = adj->crtc_vtotal - adj->crtc_vsync_end; |
| 572 | |
| 573 | DRM_DEBUG_DRIVER("H: %d %d %d %d lm %d rm %d\n", |
| 574 | adj->crtc_hdisplay, |
| 575 | adj->crtc_hsync_start, |
| 576 | adj->crtc_hsync_end, |
| 577 | adj->crtc_htotal, lm, rm); |
| 578 | DRM_DEBUG_DRIVER("V: %d %d %d %d tm %d bm %d\n", |
| 579 | adj->crtc_vdisplay, |
| 580 | adj->crtc_vsync_start, |
| 581 | adj->crtc_vsync_end, |
| 582 | adj->crtc_vtotal, tm, bm); |
| 583 | |
Russell King | e0ac5e9 | 2015-06-29 18:01:38 +0100 | [diff] [blame] | 584 | /* |
| 585 | * If we are blanked, we would have disabled the clock. Re-enable |
| 586 | * it so that compute_clock() does the right thing. |
| 587 | */ |
| 588 | if (!IS_ERR(dcrtc->clk) && dpms_blanked(dcrtc->dpms)) |
| 589 | WARN_ON(clk_prepare_enable(dcrtc->clk)); |
| 590 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 591 | /* Now compute the divider for real */ |
Russell King | 42e62ba | 2014-04-22 15:24:03 +0100 | [diff] [blame] | 592 | dcrtc->variant->compute_clock(dcrtc, adj, &sclk); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 593 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 594 | armada_reg_queue_set(regs, i, sclk, LCD_CFG_SCLK_DIV); |
| 595 | |
| 596 | if (interlaced ^ dcrtc->interlaced) { |
| 597 | if (adj->flags & DRM_MODE_FLAG_INTERLACE) |
Gustavo Padovan | accbaf6 | 2016-06-06 11:41:40 -0300 | [diff] [blame] | 598 | drm_crtc_vblank_get(&dcrtc->crtc); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 599 | else |
Gustavo Padovan | accbaf6 | 2016-06-06 11:41:40 -0300 | [diff] [blame] | 600 | drm_crtc_vblank_put(&dcrtc->crtc); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 601 | dcrtc->interlaced = interlaced; |
| 602 | } |
| 603 | |
| 604 | spin_lock_irqsave(&dcrtc->irq_lock, flags); |
| 605 | |
| 606 | /* Even interlaced/progressive frame */ |
| 607 | dcrtc->v[1].spu_v_h_total = adj->crtc_vtotal << 16 | |
| 608 | adj->crtc_htotal; |
| 609 | dcrtc->v[1].spu_v_porch = tm << 16 | bm; |
| 610 | val = adj->crtc_hsync_start; |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 611 | dcrtc->v[1].spu_adv_reg = val << 20 | val | ADV_VSYNCOFFEN | |
Russell King | 42e62ba | 2014-04-22 15:24:03 +0100 | [diff] [blame] | 612 | dcrtc->variant->spu_adv_reg; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 613 | |
| 614 | if (interlaced) { |
| 615 | /* Odd interlaced frame */ |
| 616 | dcrtc->v[0].spu_v_h_total = dcrtc->v[1].spu_v_h_total + |
| 617 | (1 << 16); |
| 618 | dcrtc->v[0].spu_v_porch = dcrtc->v[1].spu_v_porch + 1; |
| 619 | val = adj->crtc_hsync_start - adj->crtc_htotal / 2; |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 620 | dcrtc->v[0].spu_adv_reg = val << 20 | val | ADV_VSYNCOFFEN | |
Russell King | 42e62ba | 2014-04-22 15:24:03 +0100 | [diff] [blame] | 621 | dcrtc->variant->spu_adv_reg; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 622 | } else { |
| 623 | dcrtc->v[0] = dcrtc->v[1]; |
| 624 | } |
| 625 | |
| 626 | val = adj->crtc_vdisplay << 16 | adj->crtc_hdisplay; |
| 627 | |
| 628 | armada_reg_queue_set(regs, i, val, LCD_SPU_V_H_ACTIVE); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 629 | armada_reg_queue_set(regs, i, (lm << 16) | rm, LCD_SPU_H_PORCH); |
| 630 | armada_reg_queue_set(regs, i, dcrtc->v[0].spu_v_porch, LCD_SPU_V_PORCH); |
| 631 | armada_reg_queue_set(regs, i, dcrtc->v[0].spu_v_h_total, |
| 632 | LCD_SPUT_V_H_TOTAL); |
| 633 | |
Russell King | 42e62ba | 2014-04-22 15:24:03 +0100 | [diff] [blame] | 634 | if (dcrtc->variant->has_spu_adv_reg) { |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 635 | armada_reg_queue_mod(regs, i, dcrtc->v[0].spu_adv_reg, |
| 636 | ADV_VSYNC_L_OFF | ADV_VSYNC_H_OFF | |
| 637 | ADV_VSYNCOFFEN, LCD_SPU_ADV_REG); |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 638 | } |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 639 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 640 | val = adj->flags & DRM_MODE_FLAG_NVSYNC ? CFG_VSYNC_INV : 0; |
| 641 | armada_reg_queue_mod(regs, i, val, CFG_VSYNC_INV, LCD_SPU_DMA_CTRL1); |
| 642 | |
| 643 | val = dcrtc->spu_iopad_ctrl | armada_drm_crtc_calculate_csc(dcrtc); |
| 644 | armada_reg_queue_set(regs, i, val, LCD_SPU_IOPAD_CONTROL); |
| 645 | armada_reg_queue_end(regs, i); |
| 646 | |
| 647 | armada_drm_crtc_update_regs(dcrtc, regs); |
| 648 | spin_unlock_irqrestore(&dcrtc->irq_lock, flags); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 649 | } |
| 650 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 651 | /* The mode_config.mutex will be held for this call */ |
| 652 | static void armada_drm_crtc_disable(struct drm_crtc *crtc) |
| 653 | { |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 654 | armada_drm_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); |
Russell King | 28b3043 | 2017-07-08 10:16:40 +0100 | [diff] [blame] | 655 | |
| 656 | /* Disable our primary plane when we disable the CRTC. */ |
| 657 | crtc->primary->funcs->disable_plane(crtc->primary, NULL); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 658 | } |
| 659 | |
Russell King | c36045e | 2018-07-30 11:52:34 +0100 | [diff] [blame^] | 660 | static void armada_drm_crtc_atomic_begin(struct drm_crtc *crtc, |
| 661 | struct drm_crtc_state *old_crtc_state) |
| 662 | { |
| 663 | struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); |
| 664 | struct armada_plane *dplane; |
| 665 | |
| 666 | DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name); |
| 667 | |
| 668 | /* Wait 100ms for any plane works to complete */ |
| 669 | dplane = drm_to_armada_plane(crtc->primary); |
| 670 | if (WARN_ON(armada_drm_plane_work_wait(dplane, HZ / 10) == 0)) |
| 671 | armada_drm_plane_work_cancel(dcrtc, dplane); |
| 672 | |
| 673 | dcrtc->regs_idx = 0; |
| 674 | dcrtc->regs = dcrtc->atomic_regs; |
| 675 | } |
| 676 | |
| 677 | static void armada_drm_crtc_atomic_flush(struct drm_crtc *crtc, |
| 678 | struct drm_crtc_state *old_crtc_state) |
| 679 | { |
| 680 | struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); |
| 681 | unsigned long flags; |
| 682 | |
| 683 | DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name); |
| 684 | |
| 685 | armada_reg_queue_end(dcrtc->regs, dcrtc->regs_idx); |
| 686 | |
| 687 | spin_lock_irqsave(&dcrtc->irq_lock, flags); |
| 688 | armada_drm_crtc_update_regs(dcrtc, dcrtc->regs); |
| 689 | spin_unlock_irqrestore(&dcrtc->irq_lock, flags); |
| 690 | } |
| 691 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 692 | static const struct drm_crtc_helper_funcs armada_crtc_helper_funcs = { |
| 693 | .dpms = armada_drm_crtc_dpms, |
| 694 | .prepare = armada_drm_crtc_prepare, |
| 695 | .commit = armada_drm_crtc_commit, |
| 696 | .mode_fixup = armada_drm_crtc_mode_fixup, |
Russell King | c36045e | 2018-07-30 11:52:34 +0100 | [diff] [blame^] | 697 | .mode_set = drm_helper_crtc_mode_set, |
| 698 | .mode_set_nofb = armada_drm_crtc_mode_set_nofb, |
| 699 | .mode_set_base = drm_helper_crtc_mode_set_base, |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 700 | .disable = armada_drm_crtc_disable, |
Russell King | c36045e | 2018-07-30 11:52:34 +0100 | [diff] [blame^] | 701 | .atomic_begin = armada_drm_crtc_atomic_begin, |
| 702 | .atomic_flush = armada_drm_crtc_atomic_flush, |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 703 | }; |
| 704 | |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 705 | static void armada_load_cursor_argb(void __iomem *base, uint32_t *pix, |
| 706 | unsigned stride, unsigned width, unsigned height) |
| 707 | { |
| 708 | uint32_t addr; |
| 709 | unsigned y; |
| 710 | |
| 711 | addr = SRAM_HWC32_RAM1; |
| 712 | for (y = 0; y < height; y++) { |
| 713 | uint32_t *p = &pix[y * stride]; |
| 714 | unsigned x; |
| 715 | |
| 716 | for (x = 0; x < width; x++, p++) { |
| 717 | uint32_t val = *p; |
| 718 | |
| 719 | val = (val & 0xff00ff00) | |
| 720 | (val & 0x000000ff) << 16 | |
| 721 | (val & 0x00ff0000) >> 16; |
| 722 | |
| 723 | writel_relaxed(val, |
| 724 | base + LCD_SPU_SRAM_WRDAT); |
| 725 | writel_relaxed(addr | SRAM_WRITE, |
| 726 | base + LCD_SPU_SRAM_CTRL); |
Russell King | c39b069 | 2014-04-07 12:00:17 +0100 | [diff] [blame] | 727 | readl_relaxed(base + LCD_SPU_HWC_OVSA_HPXL_VLN); |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 728 | addr += 1; |
| 729 | if ((addr & 0x00ff) == 0) |
| 730 | addr += 0xf00; |
| 731 | if ((addr & 0x30ff) == 0) |
| 732 | addr = SRAM_HWC32_RAM2; |
| 733 | } |
| 734 | } |
| 735 | } |
| 736 | |
| 737 | static void armada_drm_crtc_cursor_tran(void __iomem *base) |
| 738 | { |
| 739 | unsigned addr; |
| 740 | |
| 741 | for (addr = 0; addr < 256; addr++) { |
| 742 | /* write the default value */ |
| 743 | writel_relaxed(0x55555555, base + LCD_SPU_SRAM_WRDAT); |
| 744 | writel_relaxed(addr | SRAM_WRITE | SRAM_HWC32_TRAN, |
| 745 | base + LCD_SPU_SRAM_CTRL); |
| 746 | } |
| 747 | } |
| 748 | |
| 749 | static int armada_drm_crtc_cursor_update(struct armada_crtc *dcrtc, bool reload) |
| 750 | { |
| 751 | uint32_t xoff, xscr, w = dcrtc->cursor_w, s; |
| 752 | uint32_t yoff, yscr, h = dcrtc->cursor_h; |
| 753 | uint32_t para1; |
| 754 | |
| 755 | /* |
| 756 | * Calculate the visible width and height of the cursor, |
| 757 | * screen position, and the position in the cursor bitmap. |
| 758 | */ |
| 759 | if (dcrtc->cursor_x < 0) { |
| 760 | xoff = -dcrtc->cursor_x; |
| 761 | xscr = 0; |
| 762 | w -= min(xoff, w); |
| 763 | } else if (dcrtc->cursor_x + w > dcrtc->crtc.mode.hdisplay) { |
| 764 | xoff = 0; |
| 765 | xscr = dcrtc->cursor_x; |
| 766 | w = max_t(int, dcrtc->crtc.mode.hdisplay - dcrtc->cursor_x, 0); |
| 767 | } else { |
| 768 | xoff = 0; |
| 769 | xscr = dcrtc->cursor_x; |
| 770 | } |
| 771 | |
| 772 | if (dcrtc->cursor_y < 0) { |
| 773 | yoff = -dcrtc->cursor_y; |
| 774 | yscr = 0; |
| 775 | h -= min(yoff, h); |
| 776 | } else if (dcrtc->cursor_y + h > dcrtc->crtc.mode.vdisplay) { |
| 777 | yoff = 0; |
| 778 | yscr = dcrtc->cursor_y; |
| 779 | h = max_t(int, dcrtc->crtc.mode.vdisplay - dcrtc->cursor_y, 0); |
| 780 | } else { |
| 781 | yoff = 0; |
| 782 | yscr = dcrtc->cursor_y; |
| 783 | } |
| 784 | |
| 785 | /* On interlaced modes, the vertical cursor size must be halved */ |
| 786 | s = dcrtc->cursor_w; |
| 787 | if (dcrtc->interlaced) { |
| 788 | s *= 2; |
| 789 | yscr /= 2; |
| 790 | h /= 2; |
| 791 | } |
| 792 | |
| 793 | if (!dcrtc->cursor_obj || !h || !w) { |
| 794 | spin_lock_irq(&dcrtc->irq_lock); |
| 795 | armada_drm_crtc_disable_irq(dcrtc, DUMB_FRAMEDONE_ENA); |
| 796 | dcrtc->cursor_update = false; |
| 797 | armada_updatel(0, CFG_HWC_ENA, dcrtc->base + LCD_SPU_DMA_CTRL0); |
| 798 | spin_unlock_irq(&dcrtc->irq_lock); |
| 799 | return 0; |
| 800 | } |
| 801 | |
Russell King | 214612f | 2017-07-08 10:22:15 +0100 | [diff] [blame] | 802 | spin_lock_irq(&dcrtc->irq_lock); |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 803 | para1 = readl_relaxed(dcrtc->base + LCD_SPU_SRAM_PARA1); |
| 804 | armada_updatel(CFG_CSB_256x32, CFG_CSB_256x32 | CFG_PDWN256x32, |
| 805 | dcrtc->base + LCD_SPU_SRAM_PARA1); |
Russell King | 214612f | 2017-07-08 10:22:15 +0100 | [diff] [blame] | 806 | spin_unlock_irq(&dcrtc->irq_lock); |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 807 | |
| 808 | /* |
| 809 | * Initialize the transparency if the SRAM was powered down. |
| 810 | * We must also reload the cursor data as well. |
| 811 | */ |
| 812 | if (!(para1 & CFG_CSB_256x32)) { |
| 813 | armada_drm_crtc_cursor_tran(dcrtc->base); |
| 814 | reload = true; |
| 815 | } |
| 816 | |
| 817 | if (dcrtc->cursor_hw_sz != (h << 16 | w)) { |
| 818 | spin_lock_irq(&dcrtc->irq_lock); |
| 819 | armada_drm_crtc_disable_irq(dcrtc, DUMB_FRAMEDONE_ENA); |
| 820 | dcrtc->cursor_update = false; |
| 821 | armada_updatel(0, CFG_HWC_ENA, dcrtc->base + LCD_SPU_DMA_CTRL0); |
| 822 | spin_unlock_irq(&dcrtc->irq_lock); |
| 823 | reload = true; |
| 824 | } |
| 825 | if (reload) { |
| 826 | struct armada_gem_object *obj = dcrtc->cursor_obj; |
| 827 | uint32_t *pix; |
| 828 | /* Set the top-left corner of the cursor image */ |
| 829 | pix = obj->addr; |
| 830 | pix += yoff * s + xoff; |
| 831 | armada_load_cursor_argb(dcrtc->base, pix, s, w, h); |
| 832 | } |
| 833 | |
| 834 | /* Reload the cursor position, size and enable in the IRQ handler */ |
| 835 | spin_lock_irq(&dcrtc->irq_lock); |
| 836 | dcrtc->cursor_hw_pos = yscr << 16 | xscr; |
| 837 | dcrtc->cursor_hw_sz = h << 16 | w; |
| 838 | dcrtc->cursor_update = true; |
| 839 | armada_drm_crtc_enable_irq(dcrtc, DUMB_FRAMEDONE_ENA); |
| 840 | spin_unlock_irq(&dcrtc->irq_lock); |
| 841 | |
| 842 | return 0; |
| 843 | } |
| 844 | |
| 845 | static void cursor_update(void *data) |
| 846 | { |
| 847 | armada_drm_crtc_cursor_update(data, true); |
| 848 | } |
| 849 | |
| 850 | static int armada_drm_crtc_cursor_set(struct drm_crtc *crtc, |
| 851 | struct drm_file *file, uint32_t handle, uint32_t w, uint32_t h) |
| 852 | { |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 853 | struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 854 | struct armada_gem_object *obj = NULL; |
| 855 | int ret; |
| 856 | |
| 857 | /* If no cursor support, replicate drm's return value */ |
Russell King | 42e62ba | 2014-04-22 15:24:03 +0100 | [diff] [blame] | 858 | if (!dcrtc->variant->has_spu_adv_reg) |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 859 | return -ENXIO; |
| 860 | |
| 861 | if (handle && w > 0 && h > 0) { |
| 862 | /* maximum size is 64x32 or 32x64 */ |
| 863 | if (w > 64 || h > 64 || (w > 32 && h > 32)) |
| 864 | return -ENOMEM; |
| 865 | |
Chris Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 866 | obj = armada_gem_object_lookup(file, handle); |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 867 | if (!obj) |
| 868 | return -ENOENT; |
| 869 | |
| 870 | /* Must be a kernel-mapped object */ |
| 871 | if (!obj->addr) { |
Haneen Mohammed | 4c3cf37 | 2017-09-20 12:54:48 -0600 | [diff] [blame] | 872 | drm_gem_object_put_unlocked(&obj->obj); |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 873 | return -EINVAL; |
| 874 | } |
| 875 | |
| 876 | if (obj->obj.size < w * h * 4) { |
| 877 | DRM_ERROR("buffer is too small\n"); |
Haneen Mohammed | 4c3cf37 | 2017-09-20 12:54:48 -0600 | [diff] [blame] | 878 | drm_gem_object_put_unlocked(&obj->obj); |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 879 | return -ENOMEM; |
| 880 | } |
| 881 | } |
| 882 | |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 883 | if (dcrtc->cursor_obj) { |
| 884 | dcrtc->cursor_obj->update = NULL; |
| 885 | dcrtc->cursor_obj->update_data = NULL; |
Haneen Mohammed | 4c3cf37 | 2017-09-20 12:54:48 -0600 | [diff] [blame] | 886 | drm_gem_object_put_unlocked(&dcrtc->cursor_obj->obj); |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 887 | } |
| 888 | dcrtc->cursor_obj = obj; |
| 889 | dcrtc->cursor_w = w; |
| 890 | dcrtc->cursor_h = h; |
| 891 | ret = armada_drm_crtc_cursor_update(dcrtc, true); |
| 892 | if (obj) { |
| 893 | obj->update_data = dcrtc; |
| 894 | obj->update = cursor_update; |
| 895 | } |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 896 | |
| 897 | return ret; |
| 898 | } |
| 899 | |
| 900 | static int armada_drm_crtc_cursor_move(struct drm_crtc *crtc, int x, int y) |
| 901 | { |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 902 | struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 903 | int ret; |
| 904 | |
| 905 | /* If no cursor support, replicate drm's return value */ |
Russell King | 42e62ba | 2014-04-22 15:24:03 +0100 | [diff] [blame] | 906 | if (!dcrtc->variant->has_spu_adv_reg) |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 907 | return -EFAULT; |
| 908 | |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 909 | dcrtc->cursor_x = x; |
| 910 | dcrtc->cursor_y = y; |
| 911 | ret = armada_drm_crtc_cursor_update(dcrtc, false); |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 912 | |
| 913 | return ret; |
| 914 | } |
| 915 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 916 | static void armada_drm_crtc_destroy(struct drm_crtc *crtc) |
| 917 | { |
| 918 | struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); |
| 919 | struct armada_private *priv = crtc->dev->dev_private; |
| 920 | |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 921 | if (dcrtc->cursor_obj) |
Haneen Mohammed | 4c3cf37 | 2017-09-20 12:54:48 -0600 | [diff] [blame] | 922 | drm_gem_object_put_unlocked(&dcrtc->cursor_obj->obj); |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 923 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 924 | priv->dcrtc[dcrtc->num] = NULL; |
| 925 | drm_crtc_cleanup(&dcrtc->crtc); |
| 926 | |
| 927 | if (!IS_ERR(dcrtc->clk)) |
| 928 | clk_disable_unprepare(dcrtc->clk); |
| 929 | |
Russell King | e5d9ddf | 2014-04-26 15:19:38 +0100 | [diff] [blame] | 930 | writel_relaxed(0, dcrtc->base + LCD_SPU_IRQ_ENA); |
| 931 | |
Russell King | 9611cb9 | 2014-06-15 11:21:23 +0100 | [diff] [blame] | 932 | of_node_put(dcrtc->crtc.port); |
| 933 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 934 | kfree(dcrtc); |
| 935 | } |
| 936 | |
| 937 | /* |
| 938 | * The mode_config lock is held here, to prevent races between this |
| 939 | * and a mode_set. |
| 940 | */ |
| 941 | static int armada_drm_crtc_page_flip(struct drm_crtc *crtc, |
Daniel Vetter | 41292b1f | 2017-03-22 22:50:50 +0100 | [diff] [blame] | 942 | struct drm_framebuffer *fb, struct drm_pending_vblank_event *event, uint32_t page_flip_flags, |
| 943 | struct drm_modeset_acquire_ctx *ctx) |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 944 | { |
| 945 | struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); |
Russell King | eaa6627 | 2017-07-08 10:22:10 +0100 | [diff] [blame] | 946 | struct armada_plane_work *work; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 947 | unsigned i; |
| 948 | int ret; |
| 949 | |
Russell King | eaa6627 | 2017-07-08 10:22:10 +0100 | [diff] [blame] | 950 | work = armada_drm_crtc_alloc_plane_work(dcrtc->crtc.primary); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 951 | if (!work) |
| 952 | return -ENOMEM; |
| 953 | |
| 954 | work->event = event; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 955 | work->old_fb = dcrtc->crtc.primary->fb; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 956 | |
| 957 | i = armada_drm_crtc_calc_fb(fb, crtc->x, crtc->y, work->regs, |
| 958 | dcrtc->interlaced); |
| 959 | armada_reg_queue_end(work->regs, i); |
| 960 | |
| 961 | /* |
Russell King | c548830 | 2014-10-11 23:53:35 +0100 | [diff] [blame] | 962 | * Ensure that we hold a reference on the new framebuffer. |
| 963 | * This has to match the behaviour in mode_set. |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 964 | */ |
Haneen Mohammed | a52ff2a | 2017-09-20 12:57:16 -0600 | [diff] [blame] | 965 | drm_framebuffer_get(fb); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 966 | |
Russell King | eaa6627 | 2017-07-08 10:22:10 +0100 | [diff] [blame] | 967 | ret = armada_drm_plane_work_queue(dcrtc, work); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 968 | if (ret) { |
Russell King | c548830 | 2014-10-11 23:53:35 +0100 | [diff] [blame] | 969 | /* Undo our reference above */ |
Haneen Mohammed | a52ff2a | 2017-09-20 12:57:16 -0600 | [diff] [blame] | 970 | drm_framebuffer_put(fb); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 971 | kfree(work); |
| 972 | return ret; |
| 973 | } |
| 974 | |
| 975 | /* |
Russell King | c36045e | 2018-07-30 11:52:34 +0100 | [diff] [blame^] | 976 | * We are in transition to atomic modeset: update the atomic modeset |
| 977 | * state with the new framebuffer to keep the state consistent. |
| 978 | */ |
| 979 | drm_framebuffer_assign(&dcrtc->crtc.primary->state->fb, fb); |
| 980 | |
| 981 | /* |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 982 | * Finally, if the display is blanked, we won't receive an |
| 983 | * interrupt, so complete it now. |
| 984 | */ |
Russell King | 4b5dda8 | 2015-08-06 16:37:18 +0100 | [diff] [blame] | 985 | if (dpms_blanked(dcrtc->dpms)) |
Russell King | ec6fb15 | 2016-07-25 15:16:11 +0100 | [diff] [blame] | 986 | armada_drm_plane_work_run(dcrtc, dcrtc->crtc.primary); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 987 | |
| 988 | return 0; |
| 989 | } |
| 990 | |
| 991 | static int |
| 992 | armada_drm_crtc_set_property(struct drm_crtc *crtc, |
| 993 | struct drm_property *property, uint64_t val) |
| 994 | { |
| 995 | struct armada_private *priv = crtc->dev->dev_private; |
| 996 | struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); |
| 997 | bool update_csc = false; |
| 998 | |
| 999 | if (property == priv->csc_yuv_prop) { |
| 1000 | dcrtc->csc_yuv_mode = val; |
| 1001 | update_csc = true; |
| 1002 | } else if (property == priv->csc_rgb_prop) { |
| 1003 | dcrtc->csc_rgb_mode = val; |
| 1004 | update_csc = true; |
| 1005 | } |
| 1006 | |
| 1007 | if (update_csc) { |
| 1008 | uint32_t val; |
| 1009 | |
| 1010 | val = dcrtc->spu_iopad_ctrl | |
| 1011 | armada_drm_crtc_calculate_csc(dcrtc); |
| 1012 | writel_relaxed(val, dcrtc->base + LCD_SPU_IOPAD_CONTROL); |
| 1013 | } |
| 1014 | |
| 1015 | return 0; |
| 1016 | } |
| 1017 | |
Shawn Guo | 5922a7d | 2017-02-07 17:16:18 +0800 | [diff] [blame] | 1018 | /* These are called under the vbl_lock. */ |
| 1019 | static int armada_drm_crtc_enable_vblank(struct drm_crtc *crtc) |
| 1020 | { |
| 1021 | struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); |
Russell King | 92298c1 | 2018-06-26 17:06:06 +0100 | [diff] [blame] | 1022 | unsigned long flags; |
Shawn Guo | 5922a7d | 2017-02-07 17:16:18 +0800 | [diff] [blame] | 1023 | |
Russell King | 92298c1 | 2018-06-26 17:06:06 +0100 | [diff] [blame] | 1024 | spin_lock_irqsave(&dcrtc->irq_lock, flags); |
Shawn Guo | 5922a7d | 2017-02-07 17:16:18 +0800 | [diff] [blame] | 1025 | armada_drm_crtc_enable_irq(dcrtc, VSYNC_IRQ_ENA); |
Russell King | 92298c1 | 2018-06-26 17:06:06 +0100 | [diff] [blame] | 1026 | spin_unlock_irqrestore(&dcrtc->irq_lock, flags); |
Shawn Guo | 5922a7d | 2017-02-07 17:16:18 +0800 | [diff] [blame] | 1027 | return 0; |
| 1028 | } |
| 1029 | |
| 1030 | static void armada_drm_crtc_disable_vblank(struct drm_crtc *crtc) |
| 1031 | { |
| 1032 | struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); |
Russell King | 92298c1 | 2018-06-26 17:06:06 +0100 | [diff] [blame] | 1033 | unsigned long flags; |
Shawn Guo | 5922a7d | 2017-02-07 17:16:18 +0800 | [diff] [blame] | 1034 | |
Russell King | 92298c1 | 2018-06-26 17:06:06 +0100 | [diff] [blame] | 1035 | spin_lock_irqsave(&dcrtc->irq_lock, flags); |
Shawn Guo | 5922a7d | 2017-02-07 17:16:18 +0800 | [diff] [blame] | 1036 | armada_drm_crtc_disable_irq(dcrtc, VSYNC_IRQ_ENA); |
Russell King | 92298c1 | 2018-06-26 17:06:06 +0100 | [diff] [blame] | 1037 | spin_unlock_irqrestore(&dcrtc->irq_lock, flags); |
Shawn Guo | 5922a7d | 2017-02-07 17:16:18 +0800 | [diff] [blame] | 1038 | } |
| 1039 | |
Ville Syrjälä | a02fb90 | 2015-12-15 12:20:59 +0100 | [diff] [blame] | 1040 | static const struct drm_crtc_funcs armada_crtc_funcs = { |
Russell King | c36045e | 2018-07-30 11:52:34 +0100 | [diff] [blame^] | 1041 | .reset = drm_atomic_helper_crtc_reset, |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 1042 | .cursor_set = armada_drm_crtc_cursor_set, |
| 1043 | .cursor_move = armada_drm_crtc_cursor_move, |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 1044 | .destroy = armada_drm_crtc_destroy, |
| 1045 | .set_config = drm_crtc_helper_set_config, |
| 1046 | .page_flip = armada_drm_crtc_page_flip, |
| 1047 | .set_property = armada_drm_crtc_set_property, |
Russell King | c36045e | 2018-07-30 11:52:34 +0100 | [diff] [blame^] | 1048 | .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state, |
| 1049 | .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, |
Shawn Guo | 5922a7d | 2017-02-07 17:16:18 +0800 | [diff] [blame] | 1050 | .enable_vblank = armada_drm_crtc_enable_vblank, |
| 1051 | .disable_vblank = armada_drm_crtc_disable_vblank, |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 1052 | }; |
| 1053 | |
Russell King | c36045e | 2018-07-30 11:52:34 +0100 | [diff] [blame^] | 1054 | static int armada_drm_plane_prepare_fb(struct drm_plane *plane, |
| 1055 | struct drm_plane_state *state) |
| 1056 | { |
| 1057 | DRM_DEBUG_KMS("[PLANE:%d:%s] [FB:%d]\n", |
| 1058 | plane->base.id, plane->name, |
| 1059 | state->fb ? state->fb->base.id : 0); |
| 1060 | |
| 1061 | /* |
| 1062 | * Take a reference on the new framebuffer - we want to |
| 1063 | * hold on to it while the hardware is displaying it. |
| 1064 | */ |
| 1065 | if (state->fb) |
| 1066 | drm_framebuffer_get(state->fb); |
| 1067 | return 0; |
| 1068 | } |
| 1069 | |
| 1070 | static void armada_drm_plane_cleanup_fb(struct drm_plane *plane, |
| 1071 | struct drm_plane_state *old_state) |
| 1072 | { |
| 1073 | DRM_DEBUG_KMS("[PLANE:%d:%s] [FB:%d]\n", |
| 1074 | plane->base.id, plane->name, |
| 1075 | old_state->fb ? old_state->fb->base.id : 0); |
| 1076 | |
| 1077 | if (old_state->fb) |
| 1078 | drm_framebuffer_put(old_state->fb); |
| 1079 | } |
| 1080 | |
| 1081 | static int armada_drm_plane_atomic_check(struct drm_plane *plane, |
| 1082 | struct drm_plane_state *state) |
| 1083 | { |
| 1084 | if (state->fb && !WARN_ON(!state->crtc)) { |
| 1085 | struct drm_crtc *crtc = state->crtc; |
| 1086 | struct drm_crtc_state crtc_state = { |
| 1087 | .crtc = crtc, |
| 1088 | .enable = crtc->enabled, |
| 1089 | .mode = crtc->mode, |
| 1090 | }; |
| 1091 | |
| 1092 | return drm_atomic_helper_check_plane_state(state, &crtc_state, |
| 1093 | 0, INT_MAX, |
| 1094 | true, false); |
| 1095 | } else { |
| 1096 | state->visible = false; |
| 1097 | } |
| 1098 | return 0; |
| 1099 | } |
| 1100 | |
Russell King | ecf25d2 | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 1101 | static unsigned int armada_drm_primary_update_state( |
| 1102 | struct drm_plane_state *state, struct armada_regs *regs) |
Russell King | 950bc13 | 2017-07-08 10:22:37 +0100 | [diff] [blame] | 1103 | { |
| 1104 | struct armada_plane *dplane = drm_to_armada_plane(state->plane); |
| 1105 | struct armada_crtc *dcrtc = drm_to_armada_crtc(state->crtc); |
| 1106 | struct armada_framebuffer *dfb = drm_fb_to_armada_fb(state->fb); |
| 1107 | bool was_disabled; |
| 1108 | unsigned int idx = 0; |
| 1109 | u32 val; |
| 1110 | |
| 1111 | val = CFG_GRA_FMT(dfb->fmt) | CFG_GRA_MOD(dfb->mod); |
| 1112 | if (dfb->fmt > CFG_420) |
| 1113 | val |= CFG_PALETTE_ENA; |
| 1114 | if (state->visible) |
| 1115 | val |= CFG_GRA_ENA; |
| 1116 | if (drm_rect_width(&state->src) >> 16 != drm_rect_width(&state->dst)) |
| 1117 | val |= CFG_GRA_HSMOOTH; |
Russell King | ecf25d2 | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 1118 | if (dcrtc->interlaced) |
| 1119 | val |= CFG_GRA_FTOGGLE; |
Russell King | 950bc13 | 2017-07-08 10:22:37 +0100 | [diff] [blame] | 1120 | |
| 1121 | was_disabled = !(dplane->state.ctrl0 & CFG_GRA_ENA); |
| 1122 | if (was_disabled) |
| 1123 | armada_reg_queue_mod(regs, idx, |
| 1124 | 0, CFG_PDWN64x66, LCD_SPU_SRAM_PARA1); |
| 1125 | |
| 1126 | dplane->state.ctrl0 = val; |
Russell King | 0239520 | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 1127 | dplane->state.src_hw = armada_rect_hw_fp(&state->src); |
| 1128 | dplane->state.dst_hw = armada_rect_hw(&state->dst); |
| 1129 | dplane->state.dst_yx = armada_rect_yx(&state->dst); |
Russell King | 950bc13 | 2017-07-08 10:22:37 +0100 | [diff] [blame] | 1130 | |
Russell King | ecf25d2 | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 1131 | idx += armada_drm_crtc_calc_fb(&dfb->fb, state->src.x1 >> 16, |
| 1132 | state->src.y1 >> 16, regs + idx, |
| 1133 | dcrtc->interlaced); |
| 1134 | armada_reg_queue_set(regs, idx, dplane->state.dst_yx, |
| 1135 | LCD_SPU_GRA_OVSA_HPXL_VLN); |
| 1136 | armada_reg_queue_set(regs, idx, dplane->state.src_hw, |
| 1137 | LCD_SPU_GRA_HPXL_VLN); |
| 1138 | armada_reg_queue_set(regs, idx, dplane->state.dst_hw, |
| 1139 | LCD_SPU_GZM_HPXL_VLN); |
| 1140 | armada_reg_queue_mod(regs, idx, dplane->state.ctrl0, CFG_GRAFORMAT | |
| 1141 | CFG_GRA_MOD(CFG_SWAPRB | CFG_SWAPUV | |
| 1142 | CFG_SWAPYU | CFG_YUV2RGB) | |
| 1143 | CFG_PALETTE_ENA | CFG_GRA_FTOGGLE | |
| 1144 | CFG_GRA_HSMOOTH | CFG_GRA_ENA, |
| 1145 | LCD_SPU_DMA_CTRL0); |
Russell King | 950bc13 | 2017-07-08 10:22:37 +0100 | [diff] [blame] | 1146 | |
| 1147 | dplane->state.vsync_update = !was_disabled; |
| 1148 | dplane->state.changed = true; |
Russell King | ecf25d2 | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 1149 | |
| 1150 | return idx; |
Russell King | 950bc13 | 2017-07-08 10:22:37 +0100 | [diff] [blame] | 1151 | } |
| 1152 | |
Russell King | c36045e | 2018-07-30 11:52:34 +0100 | [diff] [blame^] | 1153 | static void armada_drm_primary_plane_atomic_update(struct drm_plane *plane, |
| 1154 | struct drm_plane_state *old_state) |
| 1155 | { |
| 1156 | struct drm_plane_state *state = plane->state; |
| 1157 | struct armada_crtc *dcrtc; |
| 1158 | struct armada_regs *regs; |
| 1159 | |
| 1160 | DRM_DEBUG_KMS("[PLANE:%d:%s]\n", plane->base.id, plane->name); |
| 1161 | |
| 1162 | if (!state->fb || WARN_ON(!state->crtc)) |
| 1163 | return; |
| 1164 | |
| 1165 | DRM_DEBUG_KMS("[PLANE:%d:%s] is on [CRTC:%d:%s] with [FB:%d] visible %u->%u\n", |
| 1166 | plane->base.id, plane->name, |
| 1167 | state->crtc->base.id, state->crtc->name, |
| 1168 | state->fb->base.id, |
| 1169 | old_state->visible, state->visible); |
| 1170 | |
| 1171 | dcrtc = drm_to_armada_crtc(state->crtc); |
| 1172 | regs = dcrtc->regs + dcrtc->regs_idx; |
| 1173 | |
| 1174 | dcrtc->regs_idx += armada_drm_primary_update_state(state, regs); |
| 1175 | } |
| 1176 | |
| 1177 | static void armada_drm_primary_plane_atomic_disable(struct drm_plane *plane, |
| 1178 | struct drm_plane_state *old_state) |
Russell King | 950bc13 | 2017-07-08 10:22:37 +0100 | [diff] [blame] | 1179 | { |
| 1180 | struct armada_plane *dplane = drm_to_armada_plane(plane); |
Russell King | c36045e | 2018-07-30 11:52:34 +0100 | [diff] [blame^] | 1181 | struct armada_crtc *dcrtc; |
| 1182 | struct armada_regs *regs; |
| 1183 | unsigned int idx = 0; |
Russell King | 950bc13 | 2017-07-08 10:22:37 +0100 | [diff] [blame] | 1184 | |
Russell King | c36045e | 2018-07-30 11:52:34 +0100 | [diff] [blame^] | 1185 | DRM_DEBUG_KMS("[PLANE:%d:%s]\n", plane->base.id, plane->name); |
Russell King | 950bc13 | 2017-07-08 10:22:37 +0100 | [diff] [blame] | 1186 | |
Russell King | c36045e | 2018-07-30 11:52:34 +0100 | [diff] [blame^] | 1187 | if (!old_state->crtc) |
| 1188 | return; |
Russell King | 950bc13 | 2017-07-08 10:22:37 +0100 | [diff] [blame] | 1189 | |
Russell King | c36045e | 2018-07-30 11:52:34 +0100 | [diff] [blame^] | 1190 | DRM_DEBUG_KMS("[PLANE:%d:%s] was on [CRTC:%d:%s] with [FB:%d]\n", |
| 1191 | plane->base.id, plane->name, |
| 1192 | old_state->crtc->base.id, old_state->crtc->name, |
| 1193 | old_state->fb->base.id); |
Russell King | 950bc13 | 2017-07-08 10:22:37 +0100 | [diff] [blame] | 1194 | |
Russell King | c36045e | 2018-07-30 11:52:34 +0100 | [diff] [blame^] | 1195 | dplane->state.ctrl0 &= ~CFG_GRA_ENA; |
Russell King | 950bc13 | 2017-07-08 10:22:37 +0100 | [diff] [blame] | 1196 | |
Russell King | c36045e | 2018-07-30 11:52:34 +0100 | [diff] [blame^] | 1197 | dcrtc = drm_to_armada_crtc(old_state->crtc); |
| 1198 | regs = dcrtc->regs + dcrtc->regs_idx; |
Russell King | 950bc13 | 2017-07-08 10:22:37 +0100 | [diff] [blame] | 1199 | |
Russell King | c36045e | 2018-07-30 11:52:34 +0100 | [diff] [blame^] | 1200 | /* Disable plane and power down most RAMs and FIFOs */ |
| 1201 | armada_reg_queue_mod(regs, idx, 0, CFG_GRA_ENA, LCD_SPU_DMA_CTRL0); |
| 1202 | armada_reg_queue_mod(regs, idx, CFG_PDWN256x32 | CFG_PDWN256x24 | |
| 1203 | CFG_PDWN256x8 | CFG_PDWN32x32 | CFG_PDWN64x66, |
| 1204 | 0, LCD_SPU_SRAM_PARA1); |
Russell King | 950bc13 | 2017-07-08 10:22:37 +0100 | [diff] [blame] | 1205 | |
Russell King | c36045e | 2018-07-30 11:52:34 +0100 | [diff] [blame^] | 1206 | dcrtc->regs_idx += idx; |
Russell King | 950bc13 | 2017-07-08 10:22:37 +0100 | [diff] [blame] | 1207 | } |
| 1208 | |
Russell King | c36045e | 2018-07-30 11:52:34 +0100 | [diff] [blame^] | 1209 | static const struct drm_plane_helper_funcs armada_primary_plane_helper_funcs = { |
| 1210 | .prepare_fb = armada_drm_plane_prepare_fb, |
| 1211 | .cleanup_fb = armada_drm_plane_cleanup_fb, |
| 1212 | .atomic_check = armada_drm_plane_atomic_check, |
| 1213 | .atomic_update = armada_drm_primary_plane_atomic_update, |
| 1214 | .atomic_disable = armada_drm_primary_plane_atomic_disable, |
| 1215 | }; |
Russell King | cfd1b63 | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 1216 | |
Russell King | f1f1bffc | 2017-07-08 10:16:42 +0100 | [diff] [blame] | 1217 | int armada_drm_plane_disable(struct drm_plane *plane, |
| 1218 | struct drm_modeset_acquire_ctx *ctx) |
Russell King | 28b3043 | 2017-07-08 10:16:40 +0100 | [diff] [blame] | 1219 | { |
| 1220 | struct armada_plane *dplane = drm_to_armada_plane(plane); |
Russell King | f1f1bffc | 2017-07-08 10:16:42 +0100 | [diff] [blame] | 1221 | struct armada_crtc *dcrtc; |
Russell King | 890ca8d | 2017-07-08 10:22:27 +0100 | [diff] [blame] | 1222 | struct armada_plane_work *work; |
| 1223 | unsigned int idx = 0; |
Russell King | d76dcc7 | 2017-07-08 10:16:47 +0100 | [diff] [blame] | 1224 | u32 sram_para1, enable_mask; |
Russell King | 28b3043 | 2017-07-08 10:16:40 +0100 | [diff] [blame] | 1225 | |
Russell King | f1f1bffc | 2017-07-08 10:16:42 +0100 | [diff] [blame] | 1226 | if (!plane->crtc) |
| 1227 | return 0; |
| 1228 | |
Russell King | 28b3043 | 2017-07-08 10:16:40 +0100 | [diff] [blame] | 1229 | /* |
Russell King | 890ca8d | 2017-07-08 10:22:27 +0100 | [diff] [blame] | 1230 | * Arrange to power down most RAMs and FIFOs if this is the primary |
| 1231 | * plane, otherwise just the YUV FIFOs for the overlay plane. |
Russell King | 28b3043 | 2017-07-08 10:16:40 +0100 | [diff] [blame] | 1232 | */ |
Russell King | 28b3043 | 2017-07-08 10:16:40 +0100 | [diff] [blame] | 1233 | if (plane->type == DRM_PLANE_TYPE_PRIMARY) { |
| 1234 | sram_para1 = CFG_PDWN256x32 | CFG_PDWN256x24 | CFG_PDWN256x8 | |
| 1235 | CFG_PDWN32x32 | CFG_PDWN64x66; |
Russell King | d76dcc7 | 2017-07-08 10:16:47 +0100 | [diff] [blame] | 1236 | enable_mask = CFG_GRA_ENA; |
Russell King | 28b3043 | 2017-07-08 10:16:40 +0100 | [diff] [blame] | 1237 | } else { |
Russell King | 28b3043 | 2017-07-08 10:16:40 +0100 | [diff] [blame] | 1238 | sram_para1 = CFG_PDWN16x66 | CFG_PDWN32x66; |
Russell King | d76dcc7 | 2017-07-08 10:16:47 +0100 | [diff] [blame] | 1239 | enable_mask = CFG_DMA_ENA; |
Russell King | 28b3043 | 2017-07-08 10:16:40 +0100 | [diff] [blame] | 1240 | } |
| 1241 | |
Russell King | d76dcc7 | 2017-07-08 10:16:47 +0100 | [diff] [blame] | 1242 | dplane->state.ctrl0 &= ~enable_mask; |
| 1243 | |
Russell King | f1f1bffc | 2017-07-08 10:16:42 +0100 | [diff] [blame] | 1244 | dcrtc = drm_to_armada_crtc(plane->crtc); |
| 1245 | |
Russell King | 890ca8d | 2017-07-08 10:22:27 +0100 | [diff] [blame] | 1246 | /* |
| 1247 | * Try to disable the plane and drop our ref on the framebuffer |
| 1248 | * at the next frame update. If we fail for any reason, disable |
| 1249 | * the plane immediately. |
| 1250 | */ |
| 1251 | work = &dplane->works[dplane->next_work]; |
| 1252 | work->fn = armada_drm_crtc_complete_disable_work; |
| 1253 | work->cancel = armada_drm_crtc_complete_disable_work; |
| 1254 | work->old_fb = plane->fb; |
| 1255 | |
| 1256 | armada_reg_queue_mod(work->regs, idx, |
| 1257 | 0, enable_mask, LCD_SPU_DMA_CTRL0); |
| 1258 | armada_reg_queue_mod(work->regs, idx, |
| 1259 | sram_para1, 0, LCD_SPU_SRAM_PARA1); |
| 1260 | armada_reg_queue_end(work->regs, idx); |
| 1261 | |
Russell King | 28b3043 | 2017-07-08 10:16:40 +0100 | [diff] [blame] | 1262 | /* Wait for any preceding work to complete, but don't wedge */ |
| 1263 | if (WARN_ON(!armada_drm_plane_work_wait(dplane, HZ))) |
| 1264 | armada_drm_plane_work_cancel(dcrtc, dplane); |
| 1265 | |
Russell King | 890ca8d | 2017-07-08 10:22:27 +0100 | [diff] [blame] | 1266 | if (armada_drm_plane_work_queue(dcrtc, work)) { |
| 1267 | work->fn(dcrtc, work); |
| 1268 | if (work->old_fb) |
| 1269 | drm_framebuffer_unreference(work->old_fb); |
| 1270 | } |
| 1271 | |
| 1272 | dplane->next_work = !dplane->next_work; |
Russell King | 28b3043 | 2017-07-08 10:16:40 +0100 | [diff] [blame] | 1273 | |
Russell King | 28b3043 | 2017-07-08 10:16:40 +0100 | [diff] [blame] | 1274 | return 0; |
| 1275 | } |
| 1276 | |
Russell King | de32301 | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 1277 | static const struct drm_plane_funcs armada_primary_plane_funcs = { |
Russell King | c36045e | 2018-07-30 11:52:34 +0100 | [diff] [blame^] | 1278 | .update_plane = drm_plane_helper_update, |
| 1279 | .disable_plane = drm_plane_helper_disable, |
Russell King | de32301 | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 1280 | .destroy = drm_primary_helper_destroy, |
Russell King | c36045e | 2018-07-30 11:52:34 +0100 | [diff] [blame^] | 1281 | .reset = drm_atomic_helper_plane_reset, |
| 1282 | .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, |
| 1283 | .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, |
Russell King | de32301 | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 1284 | }; |
| 1285 | |
Russell King | 5740d27 | 2015-07-15 18:11:25 +0100 | [diff] [blame] | 1286 | int armada_drm_plane_init(struct armada_plane *plane) |
| 1287 | { |
Russell King | d924155 | 2017-07-08 10:22:25 +0100 | [diff] [blame] | 1288 | unsigned int i; |
| 1289 | |
| 1290 | for (i = 0; i < ARRAY_SIZE(plane->works); i++) |
| 1291 | plane->works[i].plane = &plane->base; |
| 1292 | |
Russell King | 5740d27 | 2015-07-15 18:11:25 +0100 | [diff] [blame] | 1293 | init_waitqueue_head(&plane->frame_wait); |
| 1294 | |
| 1295 | return 0; |
| 1296 | } |
| 1297 | |
Arvind Yadav | aaaf2f1 | 2017-07-01 15:30:15 +0530 | [diff] [blame] | 1298 | static const struct drm_prop_enum_list armada_drm_csc_yuv_enum_list[] = { |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 1299 | { CSC_AUTO, "Auto" }, |
| 1300 | { CSC_YUV_CCIR601, "CCIR601" }, |
| 1301 | { CSC_YUV_CCIR709, "CCIR709" }, |
| 1302 | }; |
| 1303 | |
Arvind Yadav | aaaf2f1 | 2017-07-01 15:30:15 +0530 | [diff] [blame] | 1304 | static const struct drm_prop_enum_list armada_drm_csc_rgb_enum_list[] = { |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 1305 | { CSC_AUTO, "Auto" }, |
| 1306 | { CSC_RGB_COMPUTER, "Computer system" }, |
| 1307 | { CSC_RGB_STUDIO, "Studio" }, |
| 1308 | }; |
| 1309 | |
| 1310 | static int armada_drm_crtc_create_properties(struct drm_device *dev) |
| 1311 | { |
| 1312 | struct armada_private *priv = dev->dev_private; |
| 1313 | |
| 1314 | if (priv->csc_yuv_prop) |
| 1315 | return 0; |
| 1316 | |
| 1317 | priv->csc_yuv_prop = drm_property_create_enum(dev, 0, |
| 1318 | "CSC_YUV", armada_drm_csc_yuv_enum_list, |
| 1319 | ARRAY_SIZE(armada_drm_csc_yuv_enum_list)); |
| 1320 | priv->csc_rgb_prop = drm_property_create_enum(dev, 0, |
| 1321 | "CSC_RGB", armada_drm_csc_rgb_enum_list, |
| 1322 | ARRAY_SIZE(armada_drm_csc_rgb_enum_list)); |
| 1323 | |
| 1324 | if (!priv->csc_yuv_prop || !priv->csc_rgb_prop) |
| 1325 | return -ENOMEM; |
| 1326 | |
| 1327 | return 0; |
| 1328 | } |
| 1329 | |
Russell King | 0fb2970 | 2015-06-06 21:46:53 +0100 | [diff] [blame] | 1330 | static int armada_drm_crtc_create(struct drm_device *drm, struct device *dev, |
Russell King | 9611cb9 | 2014-06-15 11:21:23 +0100 | [diff] [blame] | 1331 | struct resource *res, int irq, const struct armada_variant *variant, |
| 1332 | struct device_node *port) |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 1333 | { |
Russell King | d8c9608 | 2014-04-22 11:10:15 +0100 | [diff] [blame] | 1334 | struct armada_private *priv = drm->dev_private; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 1335 | struct armada_crtc *dcrtc; |
Russell King | de32301 | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 1336 | struct armada_plane *primary; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 1337 | void __iomem *base; |
| 1338 | int ret; |
| 1339 | |
Russell King | d8c9608 | 2014-04-22 11:10:15 +0100 | [diff] [blame] | 1340 | ret = armada_drm_crtc_create_properties(drm); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 1341 | if (ret) |
| 1342 | return ret; |
| 1343 | |
Linus Torvalds | a7d7a14 | 2014-08-07 17:36:12 -0700 | [diff] [blame] | 1344 | base = devm_ioremap_resource(dev, res); |
Jingoo Han | c9d53c0 | 2014-06-11 14:00:05 +0900 | [diff] [blame] | 1345 | if (IS_ERR(base)) |
| 1346 | return PTR_ERR(base); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 1347 | |
| 1348 | dcrtc = kzalloc(sizeof(*dcrtc), GFP_KERNEL); |
| 1349 | if (!dcrtc) { |
| 1350 | DRM_ERROR("failed to allocate Armada crtc\n"); |
| 1351 | return -ENOMEM; |
| 1352 | } |
| 1353 | |
Russell King | d8c9608 | 2014-04-22 11:10:15 +0100 | [diff] [blame] | 1354 | if (dev != drm->dev) |
| 1355 | dev_set_drvdata(dev, dcrtc); |
| 1356 | |
Russell King | 42e62ba | 2014-04-22 15:24:03 +0100 | [diff] [blame] | 1357 | dcrtc->variant = variant; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 1358 | dcrtc->base = base; |
Russell King | d8c9608 | 2014-04-22 11:10:15 +0100 | [diff] [blame] | 1359 | dcrtc->num = drm->mode_config.num_crtc; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 1360 | dcrtc->clk = ERR_PTR(-EINVAL); |
| 1361 | dcrtc->csc_yuv_mode = CSC_AUTO; |
| 1362 | dcrtc->csc_rgb_mode = CSC_AUTO; |
| 1363 | dcrtc->cfg_dumb_ctrl = DUMB24_RGB888_0; |
| 1364 | dcrtc->spu_iopad_ctrl = CFG_VSCALE_LN_EN | CFG_IOPAD_DUMB24; |
| 1365 | spin_lock_init(&dcrtc->irq_lock); |
| 1366 | dcrtc->irq_ena = CLEAN_SPU_IRQ_ISR; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 1367 | |
| 1368 | /* Initialize some registers which we don't otherwise set */ |
| 1369 | writel_relaxed(0x00000001, dcrtc->base + LCD_CFG_SCLK_DIV); |
| 1370 | writel_relaxed(0x00000000, dcrtc->base + LCD_SPU_BLANKCOLOR); |
| 1371 | writel_relaxed(dcrtc->spu_iopad_ctrl, |
| 1372 | dcrtc->base + LCD_SPU_IOPAD_CONTROL); |
| 1373 | writel_relaxed(0x00000000, dcrtc->base + LCD_SPU_SRAM_PARA0); |
| 1374 | writel_relaxed(CFG_PDWN256x32 | CFG_PDWN256x24 | CFG_PDWN256x8 | |
| 1375 | CFG_PDWN32x32 | CFG_PDWN16x66 | CFG_PDWN32x66 | |
| 1376 | CFG_PDWN64x66, dcrtc->base + LCD_SPU_SRAM_PARA1); |
| 1377 | writel_relaxed(0x2032ff81, dcrtc->base + LCD_SPU_DMA_CTRL1); |
Russell King | e5d9ddf | 2014-04-26 15:19:38 +0100 | [diff] [blame] | 1378 | writel_relaxed(dcrtc->irq_ena, dcrtc->base + LCD_SPU_IRQ_ENA); |
Russell King | 92298c1 | 2018-06-26 17:06:06 +0100 | [diff] [blame] | 1379 | readl_relaxed(dcrtc->base + LCD_SPU_IRQ_ISR); |
Russell King | e5d9ddf | 2014-04-26 15:19:38 +0100 | [diff] [blame] | 1380 | writel_relaxed(0, dcrtc->base + LCD_SPU_IRQ_ISR); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 1381 | |
Russell King | e5d9ddf | 2014-04-26 15:19:38 +0100 | [diff] [blame] | 1382 | ret = devm_request_irq(dev, irq, armada_drm_irq, 0, "armada_drm_crtc", |
| 1383 | dcrtc); |
Russell King | 33cd3c0 | 2017-12-08 12:16:22 +0000 | [diff] [blame] | 1384 | if (ret < 0) |
| 1385 | goto err_crtc; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 1386 | |
Russell King | 42e62ba | 2014-04-22 15:24:03 +0100 | [diff] [blame] | 1387 | if (dcrtc->variant->init) { |
Russell King | d8c9608 | 2014-04-22 11:10:15 +0100 | [diff] [blame] | 1388 | ret = dcrtc->variant->init(dcrtc, dev); |
Russell King | 33cd3c0 | 2017-12-08 12:16:22 +0000 | [diff] [blame] | 1389 | if (ret) |
| 1390 | goto err_crtc; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 1391 | } |
| 1392 | |
| 1393 | /* Ensure AXI pipeline is enabled */ |
| 1394 | armada_updatel(CFG_ARBFAST_ENA, 0, dcrtc->base + LCD_SPU_DMA_CTRL0); |
| 1395 | |
| 1396 | priv->dcrtc[dcrtc->num] = dcrtc; |
| 1397 | |
Russell King | 9611cb9 | 2014-06-15 11:21:23 +0100 | [diff] [blame] | 1398 | dcrtc->crtc.port = port; |
Russell King | 1c914ce | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 1399 | |
Russell King | de32301 | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 1400 | primary = kzalloc(sizeof(*primary), GFP_KERNEL); |
Russell King | 33cd3c0 | 2017-12-08 12:16:22 +0000 | [diff] [blame] | 1401 | if (!primary) { |
| 1402 | ret = -ENOMEM; |
| 1403 | goto err_crtc; |
| 1404 | } |
Russell King | 1c914ce | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 1405 | |
Russell King | 5740d27 | 2015-07-15 18:11:25 +0100 | [diff] [blame] | 1406 | ret = armada_drm_plane_init(primary); |
| 1407 | if (ret) { |
| 1408 | kfree(primary); |
Russell King | 33cd3c0 | 2017-12-08 12:16:22 +0000 | [diff] [blame] | 1409 | goto err_crtc; |
Russell King | 5740d27 | 2015-07-15 18:11:25 +0100 | [diff] [blame] | 1410 | } |
| 1411 | |
Russell King | c36045e | 2018-07-30 11:52:34 +0100 | [diff] [blame^] | 1412 | drm_plane_helper_add(&primary->base, |
| 1413 | &armada_primary_plane_helper_funcs); |
| 1414 | |
Russell King | de32301 | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 1415 | ret = drm_universal_plane_init(drm, &primary->base, 0, |
| 1416 | &armada_primary_plane_funcs, |
| 1417 | armada_primary_formats, |
| 1418 | ARRAY_SIZE(armada_primary_formats), |
Ben Widawsky | e6fc3b6 | 2017-07-23 20:46:38 -0700 | [diff] [blame] | 1419 | NULL, |
Ville Syrjälä | b0b3b79 | 2015-12-09 16:19:55 +0200 | [diff] [blame] | 1420 | DRM_PLANE_TYPE_PRIMARY, NULL); |
Russell King | de32301 | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 1421 | if (ret) { |
| 1422 | kfree(primary); |
Russell King | 33cd3c0 | 2017-12-08 12:16:22 +0000 | [diff] [blame] | 1423 | goto err_crtc; |
Russell King | de32301 | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 1424 | } |
| 1425 | |
| 1426 | ret = drm_crtc_init_with_planes(drm, &dcrtc->crtc, &primary->base, NULL, |
Ville Syrjälä | f988287 | 2015-12-09 16:19:31 +0200 | [diff] [blame] | 1427 | &armada_crtc_funcs, NULL); |
Russell King | 1c914ce | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 1428 | if (ret) |
| 1429 | goto err_crtc_init; |
| 1430 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 1431 | drm_crtc_helper_add(&dcrtc->crtc, &armada_crtc_helper_funcs); |
| 1432 | |
| 1433 | drm_object_attach_property(&dcrtc->crtc.base, priv->csc_yuv_prop, |
| 1434 | dcrtc->csc_yuv_mode); |
| 1435 | drm_object_attach_property(&dcrtc->crtc.base, priv->csc_rgb_prop, |
| 1436 | dcrtc->csc_rgb_mode); |
| 1437 | |
Russell King | d8c9608 | 2014-04-22 11:10:15 +0100 | [diff] [blame] | 1438 | return armada_overlay_plane_create(drm, 1 << dcrtc->num); |
Russell King | 1c914ce | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 1439 | |
| 1440 | err_crtc_init: |
Russell King | de32301 | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 1441 | primary->base.funcs->destroy(&primary->base); |
Russell King | 33cd3c0 | 2017-12-08 12:16:22 +0000 | [diff] [blame] | 1442 | err_crtc: |
| 1443 | kfree(dcrtc); |
| 1444 | |
Russell King | 1c914ce | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 1445 | return ret; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 1446 | } |
Russell King | d8c9608 | 2014-04-22 11:10:15 +0100 | [diff] [blame] | 1447 | |
| 1448 | static int |
| 1449 | armada_lcd_bind(struct device *dev, struct device *master, void *data) |
| 1450 | { |
| 1451 | struct platform_device *pdev = to_platform_device(dev); |
| 1452 | struct drm_device *drm = data; |
| 1453 | struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1454 | int irq = platform_get_irq(pdev, 0); |
| 1455 | const struct armada_variant *variant; |
Russell King | 9611cb9 | 2014-06-15 11:21:23 +0100 | [diff] [blame] | 1456 | struct device_node *port = NULL; |
Russell King | d8c9608 | 2014-04-22 11:10:15 +0100 | [diff] [blame] | 1457 | |
| 1458 | if (irq < 0) |
| 1459 | return irq; |
| 1460 | |
| 1461 | if (!dev->of_node) { |
| 1462 | const struct platform_device_id *id; |
| 1463 | |
| 1464 | id = platform_get_device_id(pdev); |
| 1465 | if (!id) |
| 1466 | return -ENXIO; |
| 1467 | |
| 1468 | variant = (const struct armada_variant *)id->driver_data; |
| 1469 | } else { |
| 1470 | const struct of_device_id *match; |
Russell King | 9611cb9 | 2014-06-15 11:21:23 +0100 | [diff] [blame] | 1471 | struct device_node *np, *parent = dev->of_node; |
Russell King | d8c9608 | 2014-04-22 11:10:15 +0100 | [diff] [blame] | 1472 | |
| 1473 | match = of_match_device(dev->driver->of_match_table, dev); |
| 1474 | if (!match) |
| 1475 | return -ENXIO; |
| 1476 | |
Russell King | 9611cb9 | 2014-06-15 11:21:23 +0100 | [diff] [blame] | 1477 | np = of_get_child_by_name(parent, "ports"); |
| 1478 | if (np) |
| 1479 | parent = np; |
| 1480 | port = of_get_child_by_name(parent, "port"); |
| 1481 | of_node_put(np); |
| 1482 | if (!port) { |
Rob Herring | 4bf9914 | 2017-07-18 16:43:04 -0500 | [diff] [blame] | 1483 | dev_err(dev, "no port node found in %pOF\n", parent); |
Russell King | 9611cb9 | 2014-06-15 11:21:23 +0100 | [diff] [blame] | 1484 | return -ENXIO; |
| 1485 | } |
| 1486 | |
Russell King | d8c9608 | 2014-04-22 11:10:15 +0100 | [diff] [blame] | 1487 | variant = match->data; |
| 1488 | } |
| 1489 | |
Russell King | 9611cb9 | 2014-06-15 11:21:23 +0100 | [diff] [blame] | 1490 | return armada_drm_crtc_create(drm, dev, res, irq, variant, port); |
Russell King | d8c9608 | 2014-04-22 11:10:15 +0100 | [diff] [blame] | 1491 | } |
| 1492 | |
| 1493 | static void |
| 1494 | armada_lcd_unbind(struct device *dev, struct device *master, void *data) |
| 1495 | { |
| 1496 | struct armada_crtc *dcrtc = dev_get_drvdata(dev); |
| 1497 | |
| 1498 | armada_drm_crtc_destroy(&dcrtc->crtc); |
| 1499 | } |
| 1500 | |
| 1501 | static const struct component_ops armada_lcd_ops = { |
| 1502 | .bind = armada_lcd_bind, |
| 1503 | .unbind = armada_lcd_unbind, |
| 1504 | }; |
| 1505 | |
| 1506 | static int armada_lcd_probe(struct platform_device *pdev) |
| 1507 | { |
| 1508 | return component_add(&pdev->dev, &armada_lcd_ops); |
| 1509 | } |
| 1510 | |
| 1511 | static int armada_lcd_remove(struct platform_device *pdev) |
| 1512 | { |
| 1513 | component_del(&pdev->dev, &armada_lcd_ops); |
| 1514 | return 0; |
| 1515 | } |
| 1516 | |
Arvind Yadav | 8590971 | 2017-06-20 10:44:33 +0530 | [diff] [blame] | 1517 | static const struct of_device_id armada_lcd_of_match[] = { |
Russell King | d8c9608 | 2014-04-22 11:10:15 +0100 | [diff] [blame] | 1518 | { |
| 1519 | .compatible = "marvell,dove-lcd", |
| 1520 | .data = &armada510_ops, |
| 1521 | }, |
| 1522 | {} |
| 1523 | }; |
| 1524 | MODULE_DEVICE_TABLE(of, armada_lcd_of_match); |
| 1525 | |
| 1526 | static const struct platform_device_id armada_lcd_platform_ids[] = { |
| 1527 | { |
| 1528 | .name = "armada-lcd", |
| 1529 | .driver_data = (unsigned long)&armada510_ops, |
| 1530 | }, { |
| 1531 | .name = "armada-510-lcd", |
| 1532 | .driver_data = (unsigned long)&armada510_ops, |
| 1533 | }, |
| 1534 | { }, |
| 1535 | }; |
| 1536 | MODULE_DEVICE_TABLE(platform, armada_lcd_platform_ids); |
| 1537 | |
| 1538 | struct platform_driver armada_lcd_platform_driver = { |
| 1539 | .probe = armada_lcd_probe, |
| 1540 | .remove = armada_lcd_remove, |
| 1541 | .driver = { |
| 1542 | .name = "armada-lcd", |
| 1543 | .owner = THIS_MODULE, |
| 1544 | .of_match_table = armada_lcd_of_match, |
| 1545 | }, |
| 1546 | .id_table = armada_lcd_platform_ids, |
| 1547 | }; |