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> |
Russell King | de503dd | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 14 | #include <drm/drm_atomic.h> |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 15 | #include <drm/drm_crtc_helper.h> |
Daniel Vetter | 3cb9ae4 | 2014-10-29 10:03:57 +0100 | [diff] [blame] | 16 | #include <drm/drm_plane_helper.h> |
Dave Airlie | bcd21a4 | 2018-01-05 09:43:46 +1000 | [diff] [blame] | 17 | #include <drm/drm_atomic_helper.h> |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 18 | #include "armada_crtc.h" |
| 19 | #include "armada_drm.h" |
| 20 | #include "armada_fb.h" |
| 21 | #include "armada_gem.h" |
| 22 | #include "armada_hw.h" |
Russell King | d40af7b | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 23 | #include "armada_plane.h" |
Russell King | c8a220c | 2016-05-17 13:51:08 +0100 | [diff] [blame] | 24 | #include "armada_trace.h" |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 25 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 26 | /* |
| 27 | * A note about interlacing. Let's consider HDMI 1920x1080i. |
| 28 | * The timing parameters we have from X are: |
| 29 | * Hact HsyA HsyI Htot Vact VsyA VsyI Vtot |
| 30 | * 1920 2448 2492 2640 1080 1084 1094 1125 |
| 31 | * Which get translated to: |
| 32 | * Hact HsyA HsyI Htot Vact VsyA VsyI Vtot |
| 33 | * 1920 2448 2492 2640 540 542 547 562 |
| 34 | * |
| 35 | * This is how it is defined by CEA-861-D - line and pixel numbers are |
| 36 | * referenced to the rising edge of VSYNC and HSYNC. Total clocks per |
| 37 | * line: 2640. The odd frame, the first active line is at line 21, and |
| 38 | * the even frame, the first active line is 584. |
| 39 | * |
| 40 | * LN: 560 561 562 563 567 568 569 |
| 41 | * DE: ~~~|____________________________//__________________________ |
| 42 | * HSYNC: ____|~|_____|~|_____|~|_____|~|_//__|~|_____|~|_____|~|_____ |
| 43 | * VSYNC: _________________________|~~~~~~//~~~~~~~~~~~~~~~|__________ |
| 44 | * 22 blanking lines. VSYNC at 1320 (referenced to the HSYNC rising edge). |
| 45 | * |
| 46 | * LN: 1123 1124 1125 1 5 6 7 |
| 47 | * DE: ~~~|____________________________//__________________________ |
| 48 | * HSYNC: ____|~|_____|~|_____|~|_____|~|_//__|~|_____|~|_____|~|_____ |
| 49 | * VSYNC: ____________________|~~~~~~~~~~~//~~~~~~~~~~|_______________ |
| 50 | * 23 blanking lines |
| 51 | * |
| 52 | * The Armada LCD Controller line and pixel numbers are, like X timings, |
| 53 | * referenced to the top left of the active frame. |
| 54 | * |
| 55 | * So, translating these to our LCD controller: |
| 56 | * Odd frame, 563 total lines, VSYNC at line 543-548, pixel 1128. |
| 57 | * Even frame, 562 total lines, VSYNC at line 542-547, pixel 2448. |
| 58 | * Note: Vsync front porch remains constant! |
| 59 | * |
| 60 | * if (odd_frame) { |
| 61 | * vtotal = mode->crtc_vtotal + 1; |
| 62 | * vbackporch = mode->crtc_vsync_start - mode->crtc_vdisplay + 1; |
| 63 | * vhorizpos = mode->crtc_hsync_start - mode->crtc_htotal / 2 |
| 64 | * } else { |
| 65 | * vtotal = mode->crtc_vtotal; |
| 66 | * vbackporch = mode->crtc_vsync_start - mode->crtc_vdisplay; |
| 67 | * vhorizpos = mode->crtc_hsync_start; |
| 68 | * } |
| 69 | * vfrontporch = mode->crtc_vtotal - mode->crtc_vsync_end; |
| 70 | * |
| 71 | * So, we need to reprogram these registers on each vsync event: |
| 72 | * LCD_SPU_V_PORCH, LCD_SPU_ADV_REG, LCD_SPUT_V_H_TOTAL |
| 73 | * |
| 74 | * Note: we do not use the frame done interrupts because these appear |
| 75 | * to happen too early, and lead to jitter on the display (presumably |
| 76 | * they occur at the end of the last active line, before the vsync back |
| 77 | * porch, which we're reprogramming.) |
| 78 | */ |
| 79 | |
| 80 | void |
| 81 | armada_drm_crtc_update_regs(struct armada_crtc *dcrtc, struct armada_regs *regs) |
| 82 | { |
| 83 | while (regs->offset != ~0) { |
| 84 | void __iomem *reg = dcrtc->base + regs->offset; |
| 85 | uint32_t val; |
| 86 | |
| 87 | val = regs->mask; |
| 88 | if (val != 0) |
| 89 | val &= readl_relaxed(reg); |
| 90 | writel_relaxed(val | regs->val, reg); |
| 91 | ++regs; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | #define dpms_blanked(dpms) ((dpms) != DRM_MODE_DPMS_ON) |
| 96 | |
| 97 | static void armada_drm_crtc_update(struct armada_crtc *dcrtc) |
| 98 | { |
| 99 | uint32_t dumb_ctrl; |
| 100 | |
| 101 | dumb_ctrl = dcrtc->cfg_dumb_ctrl; |
| 102 | |
| 103 | if (!dpms_blanked(dcrtc->dpms)) |
| 104 | dumb_ctrl |= CFG_DUMB_ENA; |
| 105 | |
| 106 | /* |
| 107 | * When the dumb interface isn't in DUMB24_RGB888_0 mode, it might |
| 108 | * be using SPI or GPIO. If we set this to DUMB_BLANK, we will |
| 109 | * force LCD_D[23:0] to output blank color, overriding the GPIO or |
| 110 | * SPI usage. So leave it as-is unless in DUMB24_RGB888_0 mode. |
| 111 | */ |
| 112 | if (dpms_blanked(dcrtc->dpms) && |
| 113 | (dumb_ctrl & DUMB_MASK) == DUMB24_RGB888_0) { |
| 114 | dumb_ctrl &= ~DUMB_MASK; |
| 115 | dumb_ctrl |= DUMB_BLANK; |
| 116 | } |
| 117 | |
Russell King | 155b829 | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 118 | armada_updatel(dumb_ctrl, |
| 119 | ~(CFG_INV_CSYNC | CFG_INV_HSYNC | CFG_INV_VSYNC), |
| 120 | dcrtc->base + LCD_SPU_DUMB_CTRL); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 121 | } |
| 122 | |
Russell King | 2839d45 | 2017-07-07 15:56:20 +0100 | [diff] [blame] | 123 | static void armada_drm_plane_work_call(struct armada_crtc *dcrtc, |
| 124 | struct armada_plane_work *work, |
| 125 | void (*fn)(struct armada_crtc *, struct armada_plane_work *)) |
| 126 | { |
| 127 | struct armada_plane *dplane = drm_to_armada_plane(work->plane); |
Russell King | d924155 | 2017-07-08 10:22:25 +0100 | [diff] [blame] | 128 | struct drm_pending_vblank_event *event; |
| 129 | struct drm_framebuffer *fb; |
Russell King | 2839d45 | 2017-07-07 15:56:20 +0100 | [diff] [blame] | 130 | |
| 131 | if (fn) |
| 132 | fn(dcrtc, work); |
| 133 | drm_crtc_vblank_put(&dcrtc->crtc); |
| 134 | |
Russell King | d924155 | 2017-07-08 10:22:25 +0100 | [diff] [blame] | 135 | event = work->event; |
| 136 | fb = work->old_fb; |
Russell King | eb19be5 | 2017-07-08 10:16:53 +0100 | [diff] [blame] | 137 | if (event || fb) { |
| 138 | struct drm_device *dev = dcrtc->crtc.dev; |
| 139 | unsigned long flags; |
| 140 | |
| 141 | spin_lock_irqsave(&dev->event_lock, flags); |
| 142 | if (event) |
| 143 | drm_crtc_send_vblank_event(&dcrtc->crtc, event); |
| 144 | if (fb) |
| 145 | __armada_drm_queue_unref_work(dev, fb); |
| 146 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 147 | } |
Russell King | b972a80 | 2017-07-08 10:16:52 +0100 | [diff] [blame] | 148 | |
Russell King | d924155 | 2017-07-08 10:22:25 +0100 | [diff] [blame] | 149 | if (work->need_kfree) |
| 150 | kfree(work); |
| 151 | |
Russell King | 2839d45 | 2017-07-07 15:56:20 +0100 | [diff] [blame] | 152 | wake_up(&dplane->frame_wait); |
| 153 | } |
| 154 | |
Russell King | 4b5dda8 | 2015-08-06 16:37:18 +0100 | [diff] [blame] | 155 | static void armada_drm_plane_work_run(struct armada_crtc *dcrtc, |
Russell King | ec6fb15 | 2016-07-25 15:16:11 +0100 | [diff] [blame] | 156 | struct drm_plane *plane) |
Russell King | 4b5dda8 | 2015-08-06 16:37:18 +0100 | [diff] [blame] | 157 | { |
Russell King | ec6fb15 | 2016-07-25 15:16:11 +0100 | [diff] [blame] | 158 | struct armada_plane *dplane = drm_to_armada_plane(plane); |
| 159 | struct armada_plane_work *work = xchg(&dplane->work, NULL); |
Russell King | 4b5dda8 | 2015-08-06 16:37:18 +0100 | [diff] [blame] | 160 | |
| 161 | /* Handle any pending frame work. */ |
Russell King | 2839d45 | 2017-07-07 15:56:20 +0100 | [diff] [blame] | 162 | if (work) |
| 163 | armada_drm_plane_work_call(dcrtc, work, work->fn); |
Russell King | 4b5dda8 | 2015-08-06 16:37:18 +0100 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | int armada_drm_plane_work_queue(struct armada_crtc *dcrtc, |
Russell King | eaab013 | 2017-07-07 15:55:53 +0100 | [diff] [blame] | 167 | struct armada_plane_work *work) |
Russell King | 4b5dda8 | 2015-08-06 16:37:18 +0100 | [diff] [blame] | 168 | { |
Russell King | eaab013 | 2017-07-07 15:55:53 +0100 | [diff] [blame] | 169 | struct armada_plane *plane = drm_to_armada_plane(work->plane); |
Russell King | 4b5dda8 | 2015-08-06 16:37:18 +0100 | [diff] [blame] | 170 | int ret; |
| 171 | |
Gustavo Padovan | accbaf6 | 2016-06-06 11:41:40 -0300 | [diff] [blame] | 172 | ret = drm_crtc_vblank_get(&dcrtc->crtc); |
Russell King | c93dfdc | 2017-07-08 10:22:23 +0100 | [diff] [blame] | 173 | if (ret) |
Russell King | 4b5dda8 | 2015-08-06 16:37:18 +0100 | [diff] [blame] | 174 | return ret; |
Russell King | 4b5dda8 | 2015-08-06 16:37:18 +0100 | [diff] [blame] | 175 | |
| 176 | ret = cmpxchg(&plane->work, NULL, work) ? -EBUSY : 0; |
| 177 | if (ret) |
Gustavo Padovan | accbaf6 | 2016-06-06 11:41:40 -0300 | [diff] [blame] | 178 | drm_crtc_vblank_put(&dcrtc->crtc); |
Russell King | 4b5dda8 | 2015-08-06 16:37:18 +0100 | [diff] [blame] | 179 | |
| 180 | return ret; |
| 181 | } |
| 182 | |
| 183 | int armada_drm_plane_work_wait(struct armada_plane *plane, long timeout) |
| 184 | { |
| 185 | return wait_event_timeout(plane->frame_wait, !plane->work, timeout); |
| 186 | } |
| 187 | |
Russell King | d3b8421 | 2017-07-07 15:55:40 +0100 | [diff] [blame] | 188 | void armada_drm_plane_work_cancel(struct armada_crtc *dcrtc, |
| 189 | struct armada_plane *dplane) |
Russell King | 7c8f7e1 | 2015-06-29 17:52:16 +0100 | [diff] [blame] | 190 | { |
Russell King | d3b8421 | 2017-07-07 15:55:40 +0100 | [diff] [blame] | 191 | struct armada_plane_work *work = xchg(&dplane->work, NULL); |
Russell King | 7c8f7e1 | 2015-06-29 17:52:16 +0100 | [diff] [blame] | 192 | |
Russell King | 4a8506d | 2015-08-07 09:33:05 +0100 | [diff] [blame] | 193 | if (work) |
Russell King | 2839d45 | 2017-07-07 15:56:20 +0100 | [diff] [blame] | 194 | armada_drm_plane_work_call(dcrtc, work, work->cancel); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 195 | } |
| 196 | |
Russell King | 709ffd8 | 2015-07-15 18:09:38 +0100 | [diff] [blame] | 197 | static void armada_drm_crtc_complete_frame_work(struct armada_crtc *dcrtc, |
Russell King | 65724a1 | 2017-07-07 15:56:24 +0100 | [diff] [blame] | 198 | struct armada_plane_work *work) |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 199 | { |
Russell King | 709ffd8 | 2015-07-15 18:09:38 +0100 | [diff] [blame] | 200 | unsigned long flags; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 201 | |
Russell King | 709ffd8 | 2015-07-15 18:09:38 +0100 | [diff] [blame] | 202 | spin_lock_irqsave(&dcrtc->irq_lock, flags); |
Russell King | eaa6627 | 2017-07-08 10:22:10 +0100 | [diff] [blame] | 203 | armada_drm_crtc_update_regs(dcrtc, work->regs); |
Russell King | 709ffd8 | 2015-07-15 18:09:38 +0100 | [diff] [blame] | 204 | spin_unlock_irqrestore(&dcrtc->irq_lock, flags); |
Russell King | 65724a1 | 2017-07-07 15:56:24 +0100 | [diff] [blame] | 205 | } |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 206 | |
Russell King | eaa6627 | 2017-07-08 10:22:10 +0100 | [diff] [blame] | 207 | static struct armada_plane_work * |
| 208 | armada_drm_crtc_alloc_plane_work(struct drm_plane *plane) |
Russell King | 901bb88 | 2017-07-07 15:55:45 +0100 | [diff] [blame] | 209 | { |
Russell King | eaa6627 | 2017-07-08 10:22:10 +0100 | [diff] [blame] | 210 | struct armada_plane_work *work; |
Russell King | 901bb88 | 2017-07-07 15:55:45 +0100 | [diff] [blame] | 211 | int i = 0; |
| 212 | |
| 213 | work = kzalloc(sizeof(*work), GFP_KERNEL); |
| 214 | if (!work) |
| 215 | return NULL; |
| 216 | |
Russell King | eaa6627 | 2017-07-08 10:22:10 +0100 | [diff] [blame] | 217 | work->plane = plane; |
| 218 | work->fn = armada_drm_crtc_complete_frame_work; |
Russell King | d924155 | 2017-07-08 10:22:25 +0100 | [diff] [blame] | 219 | work->need_kfree = true; |
Russell King | 901bb88 | 2017-07-07 15:55:45 +0100 | [diff] [blame] | 220 | armada_reg_queue_end(work->regs, i); |
| 221 | |
| 222 | return work; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 223 | } |
| 224 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 225 | static void armada_drm_vblank_off(struct armada_crtc *dcrtc) |
| 226 | { |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 227 | /* |
| 228 | * Tell the DRM core that vblank IRQs aren't going to happen for |
| 229 | * a while. This cleans up any pending vblank events for us. |
| 230 | */ |
Russell King | 178e561 | 2014-10-11 23:57:04 +0100 | [diff] [blame] | 231 | drm_crtc_vblank_off(&dcrtc->crtc); |
Russell King | ec6fb15 | 2016-07-25 15:16:11 +0100 | [diff] [blame] | 232 | armada_drm_plane_work_run(dcrtc, dcrtc->crtc.primary); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 233 | } |
| 234 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 235 | /* The mode_config.mutex will be held for this call */ |
| 236 | static void armada_drm_crtc_dpms(struct drm_crtc *crtc, int dpms) |
| 237 | { |
| 238 | struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); |
| 239 | |
Russell King | ea908ba | 2016-10-04 22:19:57 +0100 | [diff] [blame] | 240 | if (dpms_blanked(dcrtc->dpms) != dpms_blanked(dpms)) { |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 241 | if (dpms_blanked(dpms)) |
| 242 | armada_drm_vblank_off(dcrtc); |
Russell King | ea908ba | 2016-10-04 22:19:57 +0100 | [diff] [blame] | 243 | else if (!IS_ERR(dcrtc->clk)) |
| 244 | WARN_ON(clk_prepare_enable(dcrtc->clk)); |
| 245 | dcrtc->dpms = dpms; |
| 246 | armada_drm_crtc_update(dcrtc); |
| 247 | if (!dpms_blanked(dpms)) |
Russell King | 178e561 | 2014-10-11 23:57:04 +0100 | [diff] [blame] | 248 | drm_crtc_vblank_on(&dcrtc->crtc); |
Russell King | ea908ba | 2016-10-04 22:19:57 +0100 | [diff] [blame] | 249 | else if (!IS_ERR(dcrtc->clk)) |
| 250 | clk_disable_unprepare(dcrtc->clk); |
| 251 | } else if (dcrtc->dpms != dpms) { |
| 252 | dcrtc->dpms = dpms; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 253 | } |
| 254 | } |
| 255 | |
| 256 | /* |
| 257 | * Prepare for a mode set. Turn off overlay to ensure that we don't end |
| 258 | * up with the overlay size being bigger than the active screen size. |
| 259 | * We rely upon X refreshing this state after the mode set has completed. |
| 260 | * |
| 261 | * The mode_config.mutex will be held for this call |
| 262 | */ |
| 263 | static void armada_drm_crtc_prepare(struct drm_crtc *crtc) |
| 264 | { |
| 265 | struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); |
| 266 | struct drm_plane *plane; |
| 267 | |
| 268 | /* |
| 269 | * If we have an overlay plane associated with this CRTC, disable |
| 270 | * it before the modeset to avoid its coordinates being outside |
Russell King | f8e1406 | 2015-06-29 17:52:42 +0100 | [diff] [blame] | 271 | * the new mode parameters. |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 272 | */ |
| 273 | plane = dcrtc->plane; |
Russell King | 890ca8d | 2017-07-08 10:22:27 +0100 | [diff] [blame] | 274 | if (plane) { |
Russell King | f8e1406 | 2015-06-29 17:52:42 +0100 | [diff] [blame] | 275 | drm_plane_force_disable(plane); |
Russell King | 890ca8d | 2017-07-08 10:22:27 +0100 | [diff] [blame] | 276 | WARN_ON(!armada_drm_plane_work_wait(drm_to_armada_plane(plane), |
| 277 | HZ)); |
| 278 | } |
Russell King | f9a13bb | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 279 | |
| 280 | /* Wait for pending flips to complete */ |
| 281 | armada_drm_plane_work_wait(drm_to_armada_plane(dcrtc->crtc.primary), |
| 282 | MAX_SCHEDULE_TIMEOUT); |
| 283 | |
| 284 | drm_crtc_vblank_off(crtc); |
| 285 | |
Russell King | 155b829 | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 286 | armada_updatel(0, CFG_DUMB_ENA, dcrtc->base + LCD_SPU_DUMB_CTRL); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | /* The mode_config.mutex will be held for this call */ |
| 290 | static void armada_drm_crtc_commit(struct drm_crtc *crtc) |
| 291 | { |
| 292 | struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); |
| 293 | |
Russell King | f9a13bb | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 294 | dcrtc->dpms = DRM_MODE_DPMS_ON; |
| 295 | armada_drm_crtc_update(dcrtc); |
| 296 | drm_crtc_vblank_on(crtc); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | /* The mode_config.mutex will be held for this call */ |
| 300 | static bool armada_drm_crtc_mode_fixup(struct drm_crtc *crtc, |
| 301 | const struct drm_display_mode *mode, struct drm_display_mode *adj) |
| 302 | { |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 303 | struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); |
| 304 | int ret; |
| 305 | |
| 306 | /* 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] | 307 | if (!dcrtc->variant->has_spu_adv_reg && |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 308 | adj->flags & DRM_MODE_FLAG_INTERLACE) |
| 309 | return false; |
| 310 | |
| 311 | /* Check whether the display mode is possible */ |
Russell King | 42e62ba | 2014-04-22 15:24:03 +0100 | [diff] [blame] | 312 | ret = dcrtc->variant->compute_clock(dcrtc, adj, NULL); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 313 | if (ret) |
| 314 | return false; |
| 315 | |
| 316 | return true; |
| 317 | } |
| 318 | |
Shawn Guo | 5922a7d | 2017-02-07 17:16:18 +0800 | [diff] [blame] | 319 | /* These are locked by dev->vbl_lock */ |
| 320 | static void armada_drm_crtc_disable_irq(struct armada_crtc *dcrtc, u32 mask) |
| 321 | { |
| 322 | if (dcrtc->irq_ena & mask) { |
| 323 | dcrtc->irq_ena &= ~mask; |
| 324 | writel(dcrtc->irq_ena, dcrtc->base + LCD_SPU_IRQ_ENA); |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | static void armada_drm_crtc_enable_irq(struct armada_crtc *dcrtc, u32 mask) |
| 329 | { |
| 330 | if ((dcrtc->irq_ena & mask) != mask) { |
| 331 | dcrtc->irq_ena |= mask; |
| 332 | writel(dcrtc->irq_ena, dcrtc->base + LCD_SPU_IRQ_ENA); |
| 333 | if (readl_relaxed(dcrtc->base + LCD_SPU_IRQ_ISR) & mask) |
| 334 | writel(0, dcrtc->base + LCD_SPU_IRQ_ISR); |
| 335 | } |
| 336 | } |
| 337 | |
Russell King | e5d9ddf | 2014-04-26 15:19:38 +0100 | [diff] [blame] | 338 | static void armada_drm_crtc_irq(struct armada_crtc *dcrtc, u32 stat) |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 339 | { |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 340 | void __iomem *base = dcrtc->base; |
Russell King | 4a8506d | 2015-08-07 09:33:05 +0100 | [diff] [blame] | 341 | struct drm_plane *ovl_plane; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 342 | |
| 343 | if (stat & DMA_FF_UNDERFLOW) |
| 344 | DRM_ERROR("video underflow on crtc %u\n", dcrtc->num); |
| 345 | if (stat & GRA_FF_UNDERFLOW) |
| 346 | DRM_ERROR("graphics underflow on crtc %u\n", dcrtc->num); |
| 347 | |
| 348 | if (stat & VSYNC_IRQ) |
Gustavo Padovan | 0ac28c5 | 2016-07-04 21:04:48 -0300 | [diff] [blame] | 349 | drm_crtc_handle_vblank(&dcrtc->crtc); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 350 | |
Russell King | 4a8506d | 2015-08-07 09:33:05 +0100 | [diff] [blame] | 351 | ovl_plane = dcrtc->plane; |
Russell King | ec6fb15 | 2016-07-25 15:16:11 +0100 | [diff] [blame] | 352 | if (ovl_plane) |
| 353 | armada_drm_plane_work_run(dcrtc, ovl_plane); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 354 | |
Russell King | a3f6a18 | 2017-07-08 10:16:48 +0100 | [diff] [blame] | 355 | spin_lock(&dcrtc->irq_lock); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 356 | if (stat & GRA_FRAME_IRQ && dcrtc->interlaced) { |
| 357 | int i = stat & GRA_FRAME_IRQ0 ? 0 : 1; |
| 358 | uint32_t val; |
| 359 | |
| 360 | writel_relaxed(dcrtc->v[i].spu_v_porch, base + LCD_SPU_V_PORCH); |
| 361 | writel_relaxed(dcrtc->v[i].spu_v_h_total, |
| 362 | base + LCD_SPUT_V_H_TOTAL); |
| 363 | |
| 364 | val = readl_relaxed(base + LCD_SPU_ADV_REG); |
| 365 | val &= ~(ADV_VSYNC_L_OFF | ADV_VSYNC_H_OFF | ADV_VSYNCOFFEN); |
| 366 | val |= dcrtc->v[i].spu_adv_reg; |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 367 | writel_relaxed(val, base + LCD_SPU_ADV_REG); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 368 | } |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 369 | |
| 370 | if (stat & DUMB_FRAMEDONE && dcrtc->cursor_update) { |
| 371 | writel_relaxed(dcrtc->cursor_hw_pos, |
| 372 | base + LCD_SPU_HWC_OVSA_HPXL_VLN); |
| 373 | writel_relaxed(dcrtc->cursor_hw_sz, |
| 374 | base + LCD_SPU_HWC_HPXL_VLN); |
| 375 | armada_updatel(CFG_HWC_ENA, |
| 376 | CFG_HWC_ENA | CFG_HWC_1BITMOD | CFG_HWC_1BITENA, |
| 377 | base + LCD_SPU_DMA_CTRL0); |
| 378 | dcrtc->cursor_update = false; |
| 379 | armada_drm_crtc_disable_irq(dcrtc, DUMB_FRAMEDONE_ENA); |
| 380 | } |
| 381 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 382 | spin_unlock(&dcrtc->irq_lock); |
| 383 | |
Russell King | ec6fb15 | 2016-07-25 15:16:11 +0100 | [diff] [blame] | 384 | if (stat & GRA_FRAME_IRQ) |
| 385 | armada_drm_plane_work_run(dcrtc, dcrtc->crtc.primary); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 386 | } |
| 387 | |
Russell King | e5d9ddf | 2014-04-26 15:19:38 +0100 | [diff] [blame] | 388 | static irqreturn_t armada_drm_irq(int irq, void *arg) |
| 389 | { |
| 390 | struct armada_crtc *dcrtc = arg; |
| 391 | u32 v, stat = readl_relaxed(dcrtc->base + LCD_SPU_IRQ_ISR); |
| 392 | |
| 393 | /* |
Russell King | 92298c1 | 2018-06-26 17:06:06 +0100 | [diff] [blame] | 394 | * Reading the ISR appears to clear bits provided CLEAN_SPU_IRQ_ISR |
| 395 | * is set. Writing has some other effect to acknowledge the IRQ - |
| 396 | * without this, we only get a single IRQ. |
Russell King | e5d9ddf | 2014-04-26 15:19:38 +0100 | [diff] [blame] | 397 | */ |
| 398 | writel_relaxed(0, dcrtc->base + LCD_SPU_IRQ_ISR); |
| 399 | |
Russell King | c8a220c | 2016-05-17 13:51:08 +0100 | [diff] [blame] | 400 | trace_armada_drm_irq(&dcrtc->crtc, stat); |
| 401 | |
Russell King | e5d9ddf | 2014-04-26 15:19:38 +0100 | [diff] [blame] | 402 | /* Mask out those interrupts we haven't enabled */ |
| 403 | v = stat & dcrtc->irq_ena; |
| 404 | |
| 405 | if (v & (VSYNC_IRQ|GRA_FRAME_IRQ|DUMB_FRAMEDONE)) { |
| 406 | armada_drm_crtc_irq(dcrtc, stat); |
| 407 | return IRQ_HANDLED; |
| 408 | } |
| 409 | return IRQ_NONE; |
| 410 | } |
| 411 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 412 | /* The mode_config.mutex will be held for this call */ |
Russell King | c36045e | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 413 | static void armada_drm_crtc_mode_set_nofb(struct drm_crtc *crtc) |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 414 | { |
Russell King | c36045e | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 415 | struct drm_display_mode *adj = &crtc->state->adjusted_mode; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 416 | struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); |
| 417 | struct armada_regs regs[17]; |
| 418 | uint32_t lm, rm, tm, bm, val, sclk; |
| 419 | unsigned long flags; |
| 420 | unsigned i; |
Russell King | c36045e | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 421 | bool interlaced = !!(adj->flags & DRM_MODE_FLAG_INTERLACE); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 422 | |
Russell King | 37af35c | 2016-08-16 22:09:09 +0100 | [diff] [blame] | 423 | i = 0; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 424 | rm = adj->crtc_hsync_start - adj->crtc_hdisplay; |
| 425 | lm = adj->crtc_htotal - adj->crtc_hsync_end; |
| 426 | bm = adj->crtc_vsync_start - adj->crtc_vdisplay; |
| 427 | tm = adj->crtc_vtotal - adj->crtc_vsync_end; |
| 428 | |
Russell King | a61c392 | 2018-07-30 11:52:34 +0100 | [diff] [blame^] | 429 | DRM_DEBUG_KMS("[CRTC:%d:%s] mode " DRM_MODE_FMT "\n", |
| 430 | crtc->base.id, crtc->name, |
| 431 | adj->base.id, adj->name, adj->vrefresh, adj->clock, |
| 432 | adj->crtc_hdisplay, adj->crtc_hsync_start, |
| 433 | adj->crtc_hsync_end, adj->crtc_htotal, |
| 434 | adj->crtc_vdisplay, adj->crtc_vsync_start, |
| 435 | adj->crtc_vsync_end, adj->crtc_vtotal, |
| 436 | adj->type, adj->flags); |
| 437 | DRM_DEBUG_KMS("lm %d rm %d tm %d bm %d\n", lm, rm, tm, bm); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 438 | |
Russell King | e0ac5e9 | 2015-06-29 18:01:38 +0100 | [diff] [blame] | 439 | /* |
| 440 | * If we are blanked, we would have disabled the clock. Re-enable |
| 441 | * it so that compute_clock() does the right thing. |
| 442 | */ |
| 443 | if (!IS_ERR(dcrtc->clk) && dpms_blanked(dcrtc->dpms)) |
| 444 | WARN_ON(clk_prepare_enable(dcrtc->clk)); |
| 445 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 446 | /* Now compute the divider for real */ |
Russell King | 42e62ba | 2014-04-22 15:24:03 +0100 | [diff] [blame] | 447 | dcrtc->variant->compute_clock(dcrtc, adj, &sclk); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 448 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 449 | armada_reg_queue_set(regs, i, sclk, LCD_CFG_SCLK_DIV); |
| 450 | |
| 451 | if (interlaced ^ dcrtc->interlaced) { |
| 452 | if (adj->flags & DRM_MODE_FLAG_INTERLACE) |
Gustavo Padovan | accbaf6 | 2016-06-06 11:41:40 -0300 | [diff] [blame] | 453 | drm_crtc_vblank_get(&dcrtc->crtc); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 454 | else |
Gustavo Padovan | accbaf6 | 2016-06-06 11:41:40 -0300 | [diff] [blame] | 455 | drm_crtc_vblank_put(&dcrtc->crtc); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 456 | dcrtc->interlaced = interlaced; |
| 457 | } |
| 458 | |
| 459 | spin_lock_irqsave(&dcrtc->irq_lock, flags); |
| 460 | |
| 461 | /* Even interlaced/progressive frame */ |
| 462 | dcrtc->v[1].spu_v_h_total = adj->crtc_vtotal << 16 | |
| 463 | adj->crtc_htotal; |
| 464 | dcrtc->v[1].spu_v_porch = tm << 16 | bm; |
| 465 | val = adj->crtc_hsync_start; |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 466 | dcrtc->v[1].spu_adv_reg = val << 20 | val | ADV_VSYNCOFFEN | |
Russell King | 42e62ba | 2014-04-22 15:24:03 +0100 | [diff] [blame] | 467 | dcrtc->variant->spu_adv_reg; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 468 | |
| 469 | if (interlaced) { |
| 470 | /* Odd interlaced frame */ |
| 471 | dcrtc->v[0].spu_v_h_total = dcrtc->v[1].spu_v_h_total + |
| 472 | (1 << 16); |
| 473 | dcrtc->v[0].spu_v_porch = dcrtc->v[1].spu_v_porch + 1; |
| 474 | val = adj->crtc_hsync_start - adj->crtc_htotal / 2; |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 475 | dcrtc->v[0].spu_adv_reg = val << 20 | val | ADV_VSYNCOFFEN | |
Russell King | 42e62ba | 2014-04-22 15:24:03 +0100 | [diff] [blame] | 476 | dcrtc->variant->spu_adv_reg; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 477 | } else { |
| 478 | dcrtc->v[0] = dcrtc->v[1]; |
| 479 | } |
| 480 | |
| 481 | val = adj->crtc_vdisplay << 16 | adj->crtc_hdisplay; |
| 482 | |
| 483 | armada_reg_queue_set(regs, i, val, LCD_SPU_V_H_ACTIVE); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 484 | armada_reg_queue_set(regs, i, (lm << 16) | rm, LCD_SPU_H_PORCH); |
| 485 | armada_reg_queue_set(regs, i, dcrtc->v[0].spu_v_porch, LCD_SPU_V_PORCH); |
| 486 | armada_reg_queue_set(regs, i, dcrtc->v[0].spu_v_h_total, |
| 487 | LCD_SPUT_V_H_TOTAL); |
| 488 | |
Russell King | 42e62ba | 2014-04-22 15:24:03 +0100 | [diff] [blame] | 489 | if (dcrtc->variant->has_spu_adv_reg) { |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 490 | armada_reg_queue_mod(regs, i, dcrtc->v[0].spu_adv_reg, |
| 491 | ADV_VSYNC_L_OFF | ADV_VSYNC_H_OFF | |
| 492 | ADV_VSYNCOFFEN, LCD_SPU_ADV_REG); |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 493 | } |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 494 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 495 | val = adj->flags & DRM_MODE_FLAG_NVSYNC ? CFG_VSYNC_INV : 0; |
| 496 | armada_reg_queue_mod(regs, i, val, CFG_VSYNC_INV, LCD_SPU_DMA_CTRL1); |
Russell King | 155b829 | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 497 | |
| 498 | /* |
| 499 | * The documentation doesn't indicate what the normal state of |
| 500 | * the sync signals are. Sebastian Hesselbart kindly probed |
| 501 | * these signals on his board to determine their state. |
| 502 | * |
| 503 | * The non-inverted state of the sync signals is active high. |
| 504 | * Setting these bits makes the appropriate signal active low. |
| 505 | */ |
| 506 | val = 0; |
| 507 | if (adj->flags & DRM_MODE_FLAG_NCSYNC) |
| 508 | val |= CFG_INV_CSYNC; |
| 509 | if (adj->flags & DRM_MODE_FLAG_NHSYNC) |
| 510 | val |= CFG_INV_HSYNC; |
| 511 | if (adj->flags & DRM_MODE_FLAG_NVSYNC) |
| 512 | val |= CFG_INV_VSYNC; |
| 513 | armada_reg_queue_mod(regs, i, val, CFG_INV_CSYNC | CFG_INV_HSYNC | |
| 514 | CFG_INV_VSYNC, LCD_SPU_DUMB_CTRL); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 515 | armada_reg_queue_end(regs, i); |
| 516 | |
| 517 | armada_drm_crtc_update_regs(dcrtc, regs); |
| 518 | spin_unlock_irqrestore(&dcrtc->irq_lock, flags); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 519 | } |
| 520 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 521 | /* The mode_config.mutex will be held for this call */ |
| 522 | static void armada_drm_crtc_disable(struct drm_crtc *crtc) |
| 523 | { |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 524 | armada_drm_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); |
Russell King | 28b3043 | 2017-07-08 10:16:40 +0100 | [diff] [blame] | 525 | |
| 526 | /* Disable our primary plane when we disable the CRTC. */ |
| 527 | crtc->primary->funcs->disable_plane(crtc->primary, NULL); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 528 | } |
| 529 | |
Russell King | c36045e | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 530 | static void armada_drm_crtc_atomic_begin(struct drm_crtc *crtc, |
| 531 | struct drm_crtc_state *old_crtc_state) |
| 532 | { |
| 533 | struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); |
| 534 | struct armada_plane *dplane; |
| 535 | |
| 536 | DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name); |
| 537 | |
| 538 | /* Wait 100ms for any plane works to complete */ |
| 539 | dplane = drm_to_armada_plane(crtc->primary); |
| 540 | if (WARN_ON(armada_drm_plane_work_wait(dplane, HZ / 10) == 0)) |
| 541 | armada_drm_plane_work_cancel(dcrtc, dplane); |
| 542 | |
| 543 | dcrtc->regs_idx = 0; |
| 544 | dcrtc->regs = dcrtc->atomic_regs; |
| 545 | } |
| 546 | |
| 547 | static void armada_drm_crtc_atomic_flush(struct drm_crtc *crtc, |
| 548 | struct drm_crtc_state *old_crtc_state) |
| 549 | { |
| 550 | struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); |
| 551 | unsigned long flags; |
| 552 | |
| 553 | DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name); |
| 554 | |
| 555 | armada_reg_queue_end(dcrtc->regs, dcrtc->regs_idx); |
| 556 | |
| 557 | spin_lock_irqsave(&dcrtc->irq_lock, flags); |
| 558 | armada_drm_crtc_update_regs(dcrtc, dcrtc->regs); |
| 559 | spin_unlock_irqrestore(&dcrtc->irq_lock, flags); |
| 560 | } |
| 561 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 562 | static const struct drm_crtc_helper_funcs armada_crtc_helper_funcs = { |
| 563 | .dpms = armada_drm_crtc_dpms, |
| 564 | .prepare = armada_drm_crtc_prepare, |
| 565 | .commit = armada_drm_crtc_commit, |
| 566 | .mode_fixup = armada_drm_crtc_mode_fixup, |
Russell King | c36045e | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 567 | .mode_set = drm_helper_crtc_mode_set, |
| 568 | .mode_set_nofb = armada_drm_crtc_mode_set_nofb, |
| 569 | .mode_set_base = drm_helper_crtc_mode_set_base, |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 570 | .disable = armada_drm_crtc_disable, |
Russell King | c36045e | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 571 | .atomic_begin = armada_drm_crtc_atomic_begin, |
| 572 | .atomic_flush = armada_drm_crtc_atomic_flush, |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 573 | }; |
| 574 | |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 575 | static void armada_load_cursor_argb(void __iomem *base, uint32_t *pix, |
| 576 | unsigned stride, unsigned width, unsigned height) |
| 577 | { |
| 578 | uint32_t addr; |
| 579 | unsigned y; |
| 580 | |
| 581 | addr = SRAM_HWC32_RAM1; |
| 582 | for (y = 0; y < height; y++) { |
| 583 | uint32_t *p = &pix[y * stride]; |
| 584 | unsigned x; |
| 585 | |
| 586 | for (x = 0; x < width; x++, p++) { |
| 587 | uint32_t val = *p; |
| 588 | |
| 589 | val = (val & 0xff00ff00) | |
| 590 | (val & 0x000000ff) << 16 | |
| 591 | (val & 0x00ff0000) >> 16; |
| 592 | |
| 593 | writel_relaxed(val, |
| 594 | base + LCD_SPU_SRAM_WRDAT); |
| 595 | writel_relaxed(addr | SRAM_WRITE, |
| 596 | base + LCD_SPU_SRAM_CTRL); |
Russell King | c39b069 | 2014-04-07 12:00:17 +0100 | [diff] [blame] | 597 | readl_relaxed(base + LCD_SPU_HWC_OVSA_HPXL_VLN); |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 598 | addr += 1; |
| 599 | if ((addr & 0x00ff) == 0) |
| 600 | addr += 0xf00; |
| 601 | if ((addr & 0x30ff) == 0) |
| 602 | addr = SRAM_HWC32_RAM2; |
| 603 | } |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | static void armada_drm_crtc_cursor_tran(void __iomem *base) |
| 608 | { |
| 609 | unsigned addr; |
| 610 | |
| 611 | for (addr = 0; addr < 256; addr++) { |
| 612 | /* write the default value */ |
| 613 | writel_relaxed(0x55555555, base + LCD_SPU_SRAM_WRDAT); |
| 614 | writel_relaxed(addr | SRAM_WRITE | SRAM_HWC32_TRAN, |
| 615 | base + LCD_SPU_SRAM_CTRL); |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | static int armada_drm_crtc_cursor_update(struct armada_crtc *dcrtc, bool reload) |
| 620 | { |
| 621 | uint32_t xoff, xscr, w = dcrtc->cursor_w, s; |
| 622 | uint32_t yoff, yscr, h = dcrtc->cursor_h; |
| 623 | uint32_t para1; |
| 624 | |
| 625 | /* |
| 626 | * Calculate the visible width and height of the cursor, |
| 627 | * screen position, and the position in the cursor bitmap. |
| 628 | */ |
| 629 | if (dcrtc->cursor_x < 0) { |
| 630 | xoff = -dcrtc->cursor_x; |
| 631 | xscr = 0; |
| 632 | w -= min(xoff, w); |
| 633 | } else if (dcrtc->cursor_x + w > dcrtc->crtc.mode.hdisplay) { |
| 634 | xoff = 0; |
| 635 | xscr = dcrtc->cursor_x; |
| 636 | w = max_t(int, dcrtc->crtc.mode.hdisplay - dcrtc->cursor_x, 0); |
| 637 | } else { |
| 638 | xoff = 0; |
| 639 | xscr = dcrtc->cursor_x; |
| 640 | } |
| 641 | |
| 642 | if (dcrtc->cursor_y < 0) { |
| 643 | yoff = -dcrtc->cursor_y; |
| 644 | yscr = 0; |
| 645 | h -= min(yoff, h); |
| 646 | } else if (dcrtc->cursor_y + h > dcrtc->crtc.mode.vdisplay) { |
| 647 | yoff = 0; |
| 648 | yscr = dcrtc->cursor_y; |
| 649 | h = max_t(int, dcrtc->crtc.mode.vdisplay - dcrtc->cursor_y, 0); |
| 650 | } else { |
| 651 | yoff = 0; |
| 652 | yscr = dcrtc->cursor_y; |
| 653 | } |
| 654 | |
| 655 | /* On interlaced modes, the vertical cursor size must be halved */ |
| 656 | s = dcrtc->cursor_w; |
| 657 | if (dcrtc->interlaced) { |
| 658 | s *= 2; |
| 659 | yscr /= 2; |
| 660 | h /= 2; |
| 661 | } |
| 662 | |
| 663 | if (!dcrtc->cursor_obj || !h || !w) { |
| 664 | spin_lock_irq(&dcrtc->irq_lock); |
| 665 | armada_drm_crtc_disable_irq(dcrtc, DUMB_FRAMEDONE_ENA); |
| 666 | dcrtc->cursor_update = false; |
| 667 | armada_updatel(0, CFG_HWC_ENA, dcrtc->base + LCD_SPU_DMA_CTRL0); |
| 668 | spin_unlock_irq(&dcrtc->irq_lock); |
| 669 | return 0; |
| 670 | } |
| 671 | |
Russell King | 214612f | 2017-07-08 10:22:15 +0100 | [diff] [blame] | 672 | spin_lock_irq(&dcrtc->irq_lock); |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 673 | para1 = readl_relaxed(dcrtc->base + LCD_SPU_SRAM_PARA1); |
| 674 | armada_updatel(CFG_CSB_256x32, CFG_CSB_256x32 | CFG_PDWN256x32, |
| 675 | dcrtc->base + LCD_SPU_SRAM_PARA1); |
Russell King | 214612f | 2017-07-08 10:22:15 +0100 | [diff] [blame] | 676 | spin_unlock_irq(&dcrtc->irq_lock); |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 677 | |
| 678 | /* |
| 679 | * Initialize the transparency if the SRAM was powered down. |
| 680 | * We must also reload the cursor data as well. |
| 681 | */ |
| 682 | if (!(para1 & CFG_CSB_256x32)) { |
| 683 | armada_drm_crtc_cursor_tran(dcrtc->base); |
| 684 | reload = true; |
| 685 | } |
| 686 | |
| 687 | if (dcrtc->cursor_hw_sz != (h << 16 | w)) { |
| 688 | spin_lock_irq(&dcrtc->irq_lock); |
| 689 | armada_drm_crtc_disable_irq(dcrtc, DUMB_FRAMEDONE_ENA); |
| 690 | dcrtc->cursor_update = false; |
| 691 | armada_updatel(0, CFG_HWC_ENA, dcrtc->base + LCD_SPU_DMA_CTRL0); |
| 692 | spin_unlock_irq(&dcrtc->irq_lock); |
| 693 | reload = true; |
| 694 | } |
| 695 | if (reload) { |
| 696 | struct armada_gem_object *obj = dcrtc->cursor_obj; |
| 697 | uint32_t *pix; |
| 698 | /* Set the top-left corner of the cursor image */ |
| 699 | pix = obj->addr; |
| 700 | pix += yoff * s + xoff; |
| 701 | armada_load_cursor_argb(dcrtc->base, pix, s, w, h); |
| 702 | } |
| 703 | |
| 704 | /* Reload the cursor position, size and enable in the IRQ handler */ |
| 705 | spin_lock_irq(&dcrtc->irq_lock); |
| 706 | dcrtc->cursor_hw_pos = yscr << 16 | xscr; |
| 707 | dcrtc->cursor_hw_sz = h << 16 | w; |
| 708 | dcrtc->cursor_update = true; |
| 709 | armada_drm_crtc_enable_irq(dcrtc, DUMB_FRAMEDONE_ENA); |
| 710 | spin_unlock_irq(&dcrtc->irq_lock); |
| 711 | |
| 712 | return 0; |
| 713 | } |
| 714 | |
| 715 | static void cursor_update(void *data) |
| 716 | { |
| 717 | armada_drm_crtc_cursor_update(data, true); |
| 718 | } |
| 719 | |
| 720 | static int armada_drm_crtc_cursor_set(struct drm_crtc *crtc, |
| 721 | struct drm_file *file, uint32_t handle, uint32_t w, uint32_t h) |
| 722 | { |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 723 | struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 724 | struct armada_gem_object *obj = NULL; |
| 725 | int ret; |
| 726 | |
| 727 | /* If no cursor support, replicate drm's return value */ |
Russell King | 42e62ba | 2014-04-22 15:24:03 +0100 | [diff] [blame] | 728 | if (!dcrtc->variant->has_spu_adv_reg) |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 729 | return -ENXIO; |
| 730 | |
| 731 | if (handle && w > 0 && h > 0) { |
| 732 | /* maximum size is 64x32 or 32x64 */ |
| 733 | if (w > 64 || h > 64 || (w > 32 && h > 32)) |
| 734 | return -ENOMEM; |
| 735 | |
Chris Wilson | a8ad0bd | 2016-05-09 11:04:54 +0100 | [diff] [blame] | 736 | obj = armada_gem_object_lookup(file, handle); |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 737 | if (!obj) |
| 738 | return -ENOENT; |
| 739 | |
| 740 | /* Must be a kernel-mapped object */ |
| 741 | if (!obj->addr) { |
Haneen Mohammed | 4c3cf37 | 2017-09-20 12:54:48 -0600 | [diff] [blame] | 742 | drm_gem_object_put_unlocked(&obj->obj); |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 743 | return -EINVAL; |
| 744 | } |
| 745 | |
| 746 | if (obj->obj.size < w * h * 4) { |
| 747 | DRM_ERROR("buffer is too small\n"); |
Haneen Mohammed | 4c3cf37 | 2017-09-20 12:54:48 -0600 | [diff] [blame] | 748 | drm_gem_object_put_unlocked(&obj->obj); |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 749 | return -ENOMEM; |
| 750 | } |
| 751 | } |
| 752 | |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 753 | if (dcrtc->cursor_obj) { |
| 754 | dcrtc->cursor_obj->update = NULL; |
| 755 | dcrtc->cursor_obj->update_data = NULL; |
Haneen Mohammed | 4c3cf37 | 2017-09-20 12:54:48 -0600 | [diff] [blame] | 756 | drm_gem_object_put_unlocked(&dcrtc->cursor_obj->obj); |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 757 | } |
| 758 | dcrtc->cursor_obj = obj; |
| 759 | dcrtc->cursor_w = w; |
| 760 | dcrtc->cursor_h = h; |
| 761 | ret = armada_drm_crtc_cursor_update(dcrtc, true); |
| 762 | if (obj) { |
| 763 | obj->update_data = dcrtc; |
| 764 | obj->update = cursor_update; |
| 765 | } |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 766 | |
| 767 | return ret; |
| 768 | } |
| 769 | |
| 770 | static int armada_drm_crtc_cursor_move(struct drm_crtc *crtc, int x, int y) |
| 771 | { |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 772 | struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 773 | int ret; |
| 774 | |
| 775 | /* If no cursor support, replicate drm's return value */ |
Russell King | 42e62ba | 2014-04-22 15:24:03 +0100 | [diff] [blame] | 776 | if (!dcrtc->variant->has_spu_adv_reg) |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 777 | return -EFAULT; |
| 778 | |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 779 | dcrtc->cursor_x = x; |
| 780 | dcrtc->cursor_y = y; |
| 781 | ret = armada_drm_crtc_cursor_update(dcrtc, false); |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 782 | |
| 783 | return ret; |
| 784 | } |
| 785 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 786 | static void armada_drm_crtc_destroy(struct drm_crtc *crtc) |
| 787 | { |
| 788 | struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); |
| 789 | struct armada_private *priv = crtc->dev->dev_private; |
| 790 | |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 791 | if (dcrtc->cursor_obj) |
Haneen Mohammed | 4c3cf37 | 2017-09-20 12:54:48 -0600 | [diff] [blame] | 792 | drm_gem_object_put_unlocked(&dcrtc->cursor_obj->obj); |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 793 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 794 | priv->dcrtc[dcrtc->num] = NULL; |
| 795 | drm_crtc_cleanup(&dcrtc->crtc); |
| 796 | |
| 797 | if (!IS_ERR(dcrtc->clk)) |
| 798 | clk_disable_unprepare(dcrtc->clk); |
| 799 | |
Russell King | e5d9ddf | 2014-04-26 15:19:38 +0100 | [diff] [blame] | 800 | writel_relaxed(0, dcrtc->base + LCD_SPU_IRQ_ENA); |
| 801 | |
Russell King | 9611cb9 | 2014-06-15 11:21:23 +0100 | [diff] [blame] | 802 | of_node_put(dcrtc->crtc.port); |
| 803 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 804 | kfree(dcrtc); |
| 805 | } |
| 806 | |
| 807 | /* |
| 808 | * The mode_config lock is held here, to prevent races between this |
| 809 | * and a mode_set. |
| 810 | */ |
| 811 | static int armada_drm_crtc_page_flip(struct drm_crtc *crtc, |
Russell King | de503dd | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 812 | struct drm_framebuffer *fb, struct drm_pending_vblank_event *event, |
| 813 | uint32_t page_flip_flags, struct drm_modeset_acquire_ctx *ctx) |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 814 | { |
| 815 | struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); |
Russell King | de503dd | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 816 | struct drm_plane *plane = crtc->primary; |
| 817 | const struct drm_plane_helper_funcs *plane_funcs; |
| 818 | struct drm_plane_state *state; |
Russell King | eaa6627 | 2017-07-08 10:22:10 +0100 | [diff] [blame] | 819 | struct armada_plane_work *work; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 820 | int ret; |
| 821 | |
Russell King | de503dd | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 822 | /* Construct new state for the primary plane */ |
| 823 | state = drm_atomic_helper_plane_duplicate_state(plane); |
| 824 | if (!state) |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 825 | return -ENOMEM; |
| 826 | |
Russell King | de503dd | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 827 | drm_atomic_set_fb_for_plane(state, fb); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 828 | |
Russell King | de503dd | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 829 | work = armada_drm_crtc_alloc_plane_work(plane); |
| 830 | if (!work) { |
| 831 | ret = -ENOMEM; |
| 832 | goto put_state; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 833 | } |
| 834 | |
Russell King | de503dd | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 835 | /* Make sure we can get vblank interrupts */ |
| 836 | ret = drm_crtc_vblank_get(crtc); |
| 837 | if (ret) |
| 838 | goto put_work; |
| 839 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 840 | /* |
Russell King | de503dd | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 841 | * If we have another work pending, we can't process this flip. |
| 842 | * The modeset locks protect us from another user queuing a work |
| 843 | * while we're setting up. |
Russell King | c36045e | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 844 | */ |
Russell King | de503dd | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 845 | if (drm_to_armada_plane(plane)->work) { |
| 846 | ret = -EBUSY; |
| 847 | goto put_vblank; |
| 848 | } |
| 849 | |
| 850 | work->event = event; |
| 851 | work->old_fb = plane->state->fb; |
| 852 | |
| 853 | /* |
| 854 | * Hold a ref on the new fb while it's being displayed by the |
| 855 | * hardware. The old fb refcount will be released in the worker. |
| 856 | */ |
| 857 | drm_framebuffer_get(state->fb); |
| 858 | |
| 859 | /* Point of no return */ |
| 860 | swap(plane->state, state); |
| 861 | |
| 862 | dcrtc->regs_idx = 0; |
| 863 | dcrtc->regs = work->regs; |
| 864 | |
| 865 | plane_funcs = plane->helper_private; |
| 866 | plane_funcs->atomic_update(plane, state); |
| 867 | armada_reg_queue_end(dcrtc->regs, dcrtc->regs_idx); |
| 868 | |
| 869 | /* Queue the work - this should never fail */ |
| 870 | WARN_ON(armada_drm_plane_work_queue(dcrtc, work)); |
| 871 | work = NULL; |
Russell King | c36045e | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 872 | |
| 873 | /* |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 874 | * Finally, if the display is blanked, we won't receive an |
| 875 | * interrupt, so complete it now. |
| 876 | */ |
Russell King | 4b5dda8 | 2015-08-06 16:37:18 +0100 | [diff] [blame] | 877 | if (dpms_blanked(dcrtc->dpms)) |
Russell King | de503dd | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 878 | armada_drm_plane_work_run(dcrtc, plane); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 879 | |
Russell King | de503dd | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 880 | put_vblank: |
| 881 | drm_crtc_vblank_put(crtc); |
| 882 | put_work: |
| 883 | kfree(work); |
| 884 | put_state: |
| 885 | drm_atomic_helper_plane_destroy_state(plane, state); |
| 886 | return ret; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 887 | } |
| 888 | |
Shawn Guo | 5922a7d | 2017-02-07 17:16:18 +0800 | [diff] [blame] | 889 | /* These are called under the vbl_lock. */ |
| 890 | static int armada_drm_crtc_enable_vblank(struct drm_crtc *crtc) |
| 891 | { |
| 892 | struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); |
Russell King | 92298c1 | 2018-06-26 17:06:06 +0100 | [diff] [blame] | 893 | unsigned long flags; |
Shawn Guo | 5922a7d | 2017-02-07 17:16:18 +0800 | [diff] [blame] | 894 | |
Russell King | 92298c1 | 2018-06-26 17:06:06 +0100 | [diff] [blame] | 895 | spin_lock_irqsave(&dcrtc->irq_lock, flags); |
Shawn Guo | 5922a7d | 2017-02-07 17:16:18 +0800 | [diff] [blame] | 896 | armada_drm_crtc_enable_irq(dcrtc, VSYNC_IRQ_ENA); |
Russell King | 92298c1 | 2018-06-26 17:06:06 +0100 | [diff] [blame] | 897 | spin_unlock_irqrestore(&dcrtc->irq_lock, flags); |
Shawn Guo | 5922a7d | 2017-02-07 17:16:18 +0800 | [diff] [blame] | 898 | return 0; |
| 899 | } |
| 900 | |
| 901 | static void armada_drm_crtc_disable_vblank(struct drm_crtc *crtc) |
| 902 | { |
| 903 | struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); |
Russell King | 92298c1 | 2018-06-26 17:06:06 +0100 | [diff] [blame] | 904 | unsigned long flags; |
Shawn Guo | 5922a7d | 2017-02-07 17:16:18 +0800 | [diff] [blame] | 905 | |
Russell King | 92298c1 | 2018-06-26 17:06:06 +0100 | [diff] [blame] | 906 | spin_lock_irqsave(&dcrtc->irq_lock, flags); |
Shawn Guo | 5922a7d | 2017-02-07 17:16:18 +0800 | [diff] [blame] | 907 | armada_drm_crtc_disable_irq(dcrtc, VSYNC_IRQ_ENA); |
Russell King | 92298c1 | 2018-06-26 17:06:06 +0100 | [diff] [blame] | 908 | spin_unlock_irqrestore(&dcrtc->irq_lock, flags); |
Shawn Guo | 5922a7d | 2017-02-07 17:16:18 +0800 | [diff] [blame] | 909 | } |
| 910 | |
Ville Syrjälä | a02fb90 | 2015-12-15 12:20:59 +0100 | [diff] [blame] | 911 | static const struct drm_crtc_funcs armada_crtc_funcs = { |
Russell King | c36045e | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 912 | .reset = drm_atomic_helper_crtc_reset, |
Russell King | 662af0d | 2013-05-19 10:55:17 +0100 | [diff] [blame] | 913 | .cursor_set = armada_drm_crtc_cursor_set, |
| 914 | .cursor_move = armada_drm_crtc_cursor_move, |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 915 | .destroy = armada_drm_crtc_destroy, |
| 916 | .set_config = drm_crtc_helper_set_config, |
| 917 | .page_flip = armada_drm_crtc_page_flip, |
Russell King | c36045e | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 918 | .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state, |
| 919 | .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, |
Shawn Guo | 5922a7d | 2017-02-07 17:16:18 +0800 | [diff] [blame] | 920 | .enable_vblank = armada_drm_crtc_enable_vblank, |
| 921 | .disable_vblank = armada_drm_crtc_disable_vblank, |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 922 | }; |
| 923 | |
Russell King | 0fb2970 | 2015-06-06 21:46:53 +0100 | [diff] [blame] | 924 | 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] | 925 | struct resource *res, int irq, const struct armada_variant *variant, |
| 926 | struct device_node *port) |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 927 | { |
Russell King | d8c9608 | 2014-04-22 11:10:15 +0100 | [diff] [blame] | 928 | struct armada_private *priv = drm->dev_private; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 929 | struct armada_crtc *dcrtc; |
Russell King | de32301 | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 930 | struct armada_plane *primary; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 931 | void __iomem *base; |
| 932 | int ret; |
| 933 | |
Linus Torvalds | a7d7a14 | 2014-08-07 17:36:12 -0700 | [diff] [blame] | 934 | base = devm_ioremap_resource(dev, res); |
Jingoo Han | c9d53c0 | 2014-06-11 14:00:05 +0900 | [diff] [blame] | 935 | if (IS_ERR(base)) |
| 936 | return PTR_ERR(base); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 937 | |
| 938 | dcrtc = kzalloc(sizeof(*dcrtc), GFP_KERNEL); |
| 939 | if (!dcrtc) { |
| 940 | DRM_ERROR("failed to allocate Armada crtc\n"); |
| 941 | return -ENOMEM; |
| 942 | } |
| 943 | |
Russell King | d8c9608 | 2014-04-22 11:10:15 +0100 | [diff] [blame] | 944 | if (dev != drm->dev) |
| 945 | dev_set_drvdata(dev, dcrtc); |
| 946 | |
Russell King | 42e62ba | 2014-04-22 15:24:03 +0100 | [diff] [blame] | 947 | dcrtc->variant = variant; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 948 | dcrtc->base = base; |
Russell King | d8c9608 | 2014-04-22 11:10:15 +0100 | [diff] [blame] | 949 | dcrtc->num = drm->mode_config.num_crtc; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 950 | dcrtc->clk = ERR_PTR(-EINVAL); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 951 | dcrtc->cfg_dumb_ctrl = DUMB24_RGB888_0; |
| 952 | dcrtc->spu_iopad_ctrl = CFG_VSCALE_LN_EN | CFG_IOPAD_DUMB24; |
| 953 | spin_lock_init(&dcrtc->irq_lock); |
| 954 | dcrtc->irq_ena = CLEAN_SPU_IRQ_ISR; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 955 | |
| 956 | /* Initialize some registers which we don't otherwise set */ |
| 957 | writel_relaxed(0x00000001, dcrtc->base + LCD_CFG_SCLK_DIV); |
| 958 | writel_relaxed(0x00000000, dcrtc->base + LCD_SPU_BLANKCOLOR); |
| 959 | writel_relaxed(dcrtc->spu_iopad_ctrl, |
| 960 | dcrtc->base + LCD_SPU_IOPAD_CONTROL); |
| 961 | writel_relaxed(0x00000000, dcrtc->base + LCD_SPU_SRAM_PARA0); |
| 962 | writel_relaxed(CFG_PDWN256x32 | CFG_PDWN256x24 | CFG_PDWN256x8 | |
| 963 | CFG_PDWN32x32 | CFG_PDWN16x66 | CFG_PDWN32x66 | |
| 964 | CFG_PDWN64x66, dcrtc->base + LCD_SPU_SRAM_PARA1); |
| 965 | writel_relaxed(0x2032ff81, dcrtc->base + LCD_SPU_DMA_CTRL1); |
Russell King | e5d9ddf | 2014-04-26 15:19:38 +0100 | [diff] [blame] | 966 | writel_relaxed(dcrtc->irq_ena, dcrtc->base + LCD_SPU_IRQ_ENA); |
Russell King | 92298c1 | 2018-06-26 17:06:06 +0100 | [diff] [blame] | 967 | readl_relaxed(dcrtc->base + LCD_SPU_IRQ_ISR); |
Russell King | e5d9ddf | 2014-04-26 15:19:38 +0100 | [diff] [blame] | 968 | writel_relaxed(0, dcrtc->base + LCD_SPU_IRQ_ISR); |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 969 | |
Russell King | e5d9ddf | 2014-04-26 15:19:38 +0100 | [diff] [blame] | 970 | ret = devm_request_irq(dev, irq, armada_drm_irq, 0, "armada_drm_crtc", |
| 971 | dcrtc); |
Russell King | 33cd3c0 | 2017-12-08 12:16:22 +0000 | [diff] [blame] | 972 | if (ret < 0) |
| 973 | goto err_crtc; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 974 | |
Russell King | 42e62ba | 2014-04-22 15:24:03 +0100 | [diff] [blame] | 975 | if (dcrtc->variant->init) { |
Russell King | d8c9608 | 2014-04-22 11:10:15 +0100 | [diff] [blame] | 976 | ret = dcrtc->variant->init(dcrtc, dev); |
Russell King | 33cd3c0 | 2017-12-08 12:16:22 +0000 | [diff] [blame] | 977 | if (ret) |
| 978 | goto err_crtc; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | /* Ensure AXI pipeline is enabled */ |
| 982 | armada_updatel(CFG_ARBFAST_ENA, 0, dcrtc->base + LCD_SPU_DMA_CTRL0); |
| 983 | |
| 984 | priv->dcrtc[dcrtc->num] = dcrtc; |
| 985 | |
Russell King | 9611cb9 | 2014-06-15 11:21:23 +0100 | [diff] [blame] | 986 | dcrtc->crtc.port = port; |
Russell King | 1c914ce | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 987 | |
Russell King | de32301 | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 988 | primary = kzalloc(sizeof(*primary), GFP_KERNEL); |
Russell King | 33cd3c0 | 2017-12-08 12:16:22 +0000 | [diff] [blame] | 989 | if (!primary) { |
| 990 | ret = -ENOMEM; |
| 991 | goto err_crtc; |
| 992 | } |
Russell King | 1c914ce | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 993 | |
Russell King | d40af7b | 2018-07-30 11:52:34 +0100 | [diff] [blame] | 994 | ret = armada_drm_primary_plane_init(drm, primary); |
Russell King | de32301 | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 995 | if (ret) { |
| 996 | kfree(primary); |
Russell King | 33cd3c0 | 2017-12-08 12:16:22 +0000 | [diff] [blame] | 997 | goto err_crtc; |
Russell King | de32301 | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | 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] | 1001 | &armada_crtc_funcs, NULL); |
Russell King | 1c914ce | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 1002 | if (ret) |
| 1003 | goto err_crtc_init; |
| 1004 | |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 1005 | drm_crtc_helper_add(&dcrtc->crtc, &armada_crtc_helper_funcs); |
| 1006 | |
Russell King | d8c9608 | 2014-04-22 11:10:15 +0100 | [diff] [blame] | 1007 | return armada_overlay_plane_create(drm, 1 << dcrtc->num); |
Russell King | 1c914ce | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 1008 | |
| 1009 | err_crtc_init: |
Russell King | de32301 | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 1010 | primary->base.funcs->destroy(&primary->base); |
Russell King | 33cd3c0 | 2017-12-08 12:16:22 +0000 | [diff] [blame] | 1011 | err_crtc: |
| 1012 | kfree(dcrtc); |
| 1013 | |
Russell King | 1c914ce | 2015-07-15 18:11:24 +0100 | [diff] [blame] | 1014 | return ret; |
Russell King | 96f60e3 | 2012-08-15 13:59:49 +0100 | [diff] [blame] | 1015 | } |
Russell King | d8c9608 | 2014-04-22 11:10:15 +0100 | [diff] [blame] | 1016 | |
| 1017 | static int |
| 1018 | armada_lcd_bind(struct device *dev, struct device *master, void *data) |
| 1019 | { |
| 1020 | struct platform_device *pdev = to_platform_device(dev); |
| 1021 | struct drm_device *drm = data; |
| 1022 | struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1023 | int irq = platform_get_irq(pdev, 0); |
| 1024 | const struct armada_variant *variant; |
Russell King | 9611cb9 | 2014-06-15 11:21:23 +0100 | [diff] [blame] | 1025 | struct device_node *port = NULL; |
Russell King | d8c9608 | 2014-04-22 11:10:15 +0100 | [diff] [blame] | 1026 | |
| 1027 | if (irq < 0) |
| 1028 | return irq; |
| 1029 | |
| 1030 | if (!dev->of_node) { |
| 1031 | const struct platform_device_id *id; |
| 1032 | |
| 1033 | id = platform_get_device_id(pdev); |
| 1034 | if (!id) |
| 1035 | return -ENXIO; |
| 1036 | |
| 1037 | variant = (const struct armada_variant *)id->driver_data; |
| 1038 | } else { |
| 1039 | const struct of_device_id *match; |
Russell King | 9611cb9 | 2014-06-15 11:21:23 +0100 | [diff] [blame] | 1040 | struct device_node *np, *parent = dev->of_node; |
Russell King | d8c9608 | 2014-04-22 11:10:15 +0100 | [diff] [blame] | 1041 | |
| 1042 | match = of_match_device(dev->driver->of_match_table, dev); |
| 1043 | if (!match) |
| 1044 | return -ENXIO; |
| 1045 | |
Russell King | 9611cb9 | 2014-06-15 11:21:23 +0100 | [diff] [blame] | 1046 | np = of_get_child_by_name(parent, "ports"); |
| 1047 | if (np) |
| 1048 | parent = np; |
| 1049 | port = of_get_child_by_name(parent, "port"); |
| 1050 | of_node_put(np); |
| 1051 | if (!port) { |
Rob Herring | 4bf9914 | 2017-07-18 16:43:04 -0500 | [diff] [blame] | 1052 | dev_err(dev, "no port node found in %pOF\n", parent); |
Russell King | 9611cb9 | 2014-06-15 11:21:23 +0100 | [diff] [blame] | 1053 | return -ENXIO; |
| 1054 | } |
| 1055 | |
Russell King | d8c9608 | 2014-04-22 11:10:15 +0100 | [diff] [blame] | 1056 | variant = match->data; |
| 1057 | } |
| 1058 | |
Russell King | 9611cb9 | 2014-06-15 11:21:23 +0100 | [diff] [blame] | 1059 | return armada_drm_crtc_create(drm, dev, res, irq, variant, port); |
Russell King | d8c9608 | 2014-04-22 11:10:15 +0100 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | static void |
| 1063 | armada_lcd_unbind(struct device *dev, struct device *master, void *data) |
| 1064 | { |
| 1065 | struct armada_crtc *dcrtc = dev_get_drvdata(dev); |
| 1066 | |
| 1067 | armada_drm_crtc_destroy(&dcrtc->crtc); |
| 1068 | } |
| 1069 | |
| 1070 | static const struct component_ops armada_lcd_ops = { |
| 1071 | .bind = armada_lcd_bind, |
| 1072 | .unbind = armada_lcd_unbind, |
| 1073 | }; |
| 1074 | |
| 1075 | static int armada_lcd_probe(struct platform_device *pdev) |
| 1076 | { |
| 1077 | return component_add(&pdev->dev, &armada_lcd_ops); |
| 1078 | } |
| 1079 | |
| 1080 | static int armada_lcd_remove(struct platform_device *pdev) |
| 1081 | { |
| 1082 | component_del(&pdev->dev, &armada_lcd_ops); |
| 1083 | return 0; |
| 1084 | } |
| 1085 | |
Arvind Yadav | 8590971 | 2017-06-20 10:44:33 +0530 | [diff] [blame] | 1086 | static const struct of_device_id armada_lcd_of_match[] = { |
Russell King | d8c9608 | 2014-04-22 11:10:15 +0100 | [diff] [blame] | 1087 | { |
| 1088 | .compatible = "marvell,dove-lcd", |
| 1089 | .data = &armada510_ops, |
| 1090 | }, |
| 1091 | {} |
| 1092 | }; |
| 1093 | MODULE_DEVICE_TABLE(of, armada_lcd_of_match); |
| 1094 | |
| 1095 | static const struct platform_device_id armada_lcd_platform_ids[] = { |
| 1096 | { |
| 1097 | .name = "armada-lcd", |
| 1098 | .driver_data = (unsigned long)&armada510_ops, |
| 1099 | }, { |
| 1100 | .name = "armada-510-lcd", |
| 1101 | .driver_data = (unsigned long)&armada510_ops, |
| 1102 | }, |
| 1103 | { }, |
| 1104 | }; |
| 1105 | MODULE_DEVICE_TABLE(platform, armada_lcd_platform_ids); |
| 1106 | |
| 1107 | struct platform_driver armada_lcd_platform_driver = { |
| 1108 | .probe = armada_lcd_probe, |
| 1109 | .remove = armada_lcd_remove, |
| 1110 | .driver = { |
| 1111 | .name = "armada-lcd", |
| 1112 | .owner = THIS_MODULE, |
| 1113 | .of_match_table = armada_lcd_of_match, |
| 1114 | }, |
| 1115 | .id_table = armada_lcd_platform_ids, |
| 1116 | }; |