blob: 5d77e51e31811ba1b109fa3360407cb81a874c1a [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Russell King96f60e32012-08-15 13:59:49 +01002/*
3 * Copyright (C) 2012 Russell King
4 * Rewritten from the dovefb driver, and Armada510 manuals.
Russell King96f60e32012-08-15 13:59:49 +01005 */
6#include <linux/clk.h>
Russell Kingd8c96082014-04-22 11:10:15 +01007#include <linux/component.h>
8#include <linux/of_device.h>
9#include <linux/platform_device.h>
Russell King96f60e32012-08-15 13:59:49 +010010#include <drm/drmP.h>
Russell Kingde503dd2018-07-30 11:52:34 +010011#include <drm/drm_atomic.h>
Daniel Vetterfcd70cd2019-01-17 22:03:34 +010012#include <drm/drm_probe_helper.h>
Daniel Vetter3cb9ae42014-10-29 10:03:57 +010013#include <drm/drm_plane_helper.h>
Dave Airliebcd21a42018-01-05 09:43:46 +100014#include <drm/drm_atomic_helper.h>
Russell King96f60e32012-08-15 13:59:49 +010015#include "armada_crtc.h"
16#include "armada_drm.h"
17#include "armada_fb.h"
18#include "armada_gem.h"
19#include "armada_hw.h"
Russell Kingd40af7b2018-07-30 11:52:34 +010020#include "armada_plane.h"
Russell Kingc8a220c2016-05-17 13:51:08 +010021#include "armada_trace.h"
Russell King96f60e32012-08-15 13:59:49 +010022
Russell King96f60e32012-08-15 13:59:49 +010023/*
24 * A note about interlacing. Let's consider HDMI 1920x1080i.
25 * The timing parameters we have from X are:
26 * Hact HsyA HsyI Htot Vact VsyA VsyI Vtot
27 * 1920 2448 2492 2640 1080 1084 1094 1125
28 * Which get translated to:
29 * Hact HsyA HsyI Htot Vact VsyA VsyI Vtot
30 * 1920 2448 2492 2640 540 542 547 562
31 *
32 * This is how it is defined by CEA-861-D - line and pixel numbers are
33 * referenced to the rising edge of VSYNC and HSYNC. Total clocks per
34 * line: 2640. The odd frame, the first active line is at line 21, and
35 * the even frame, the first active line is 584.
36 *
37 * LN: 560 561 562 563 567 568 569
38 * DE: ~~~|____________________________//__________________________
39 * HSYNC: ____|~|_____|~|_____|~|_____|~|_//__|~|_____|~|_____|~|_____
40 * VSYNC: _________________________|~~~~~~//~~~~~~~~~~~~~~~|__________
41 * 22 blanking lines. VSYNC at 1320 (referenced to the HSYNC rising edge).
42 *
43 * LN: 1123 1124 1125 1 5 6 7
44 * DE: ~~~|____________________________//__________________________
45 * HSYNC: ____|~|_____|~|_____|~|_____|~|_//__|~|_____|~|_____|~|_____
46 * VSYNC: ____________________|~~~~~~~~~~~//~~~~~~~~~~|_______________
47 * 23 blanking lines
48 *
49 * The Armada LCD Controller line and pixel numbers are, like X timings,
50 * referenced to the top left of the active frame.
51 *
52 * So, translating these to our LCD controller:
53 * Odd frame, 563 total lines, VSYNC at line 543-548, pixel 1128.
54 * Even frame, 562 total lines, VSYNC at line 542-547, pixel 2448.
55 * Note: Vsync front porch remains constant!
56 *
57 * if (odd_frame) {
58 * vtotal = mode->crtc_vtotal + 1;
59 * vbackporch = mode->crtc_vsync_start - mode->crtc_vdisplay + 1;
60 * vhorizpos = mode->crtc_hsync_start - mode->crtc_htotal / 2
61 * } else {
62 * vtotal = mode->crtc_vtotal;
63 * vbackporch = mode->crtc_vsync_start - mode->crtc_vdisplay;
64 * vhorizpos = mode->crtc_hsync_start;
65 * }
66 * vfrontporch = mode->crtc_vtotal - mode->crtc_vsync_end;
67 *
68 * So, we need to reprogram these registers on each vsync event:
69 * LCD_SPU_V_PORCH, LCD_SPU_ADV_REG, LCD_SPUT_V_H_TOTAL
70 *
71 * Note: we do not use the frame done interrupts because these appear
72 * to happen too early, and lead to jitter on the display (presumably
73 * they occur at the end of the last active line, before the vsync back
74 * porch, which we're reprogramming.)
75 */
76
77void
78armada_drm_crtc_update_regs(struct armada_crtc *dcrtc, struct armada_regs *regs)
79{
80 while (regs->offset != ~0) {
81 void __iomem *reg = dcrtc->base + regs->offset;
82 uint32_t val;
83
84 val = regs->mask;
85 if (val != 0)
86 val &= readl_relaxed(reg);
87 writel_relaxed(val | regs->val, reg);
88 ++regs;
89 }
90}
91
Russell Kinga0f75d22018-07-30 11:52:34 +010092static void armada_drm_crtc_update(struct armada_crtc *dcrtc, bool enable)
Russell King96f60e32012-08-15 13:59:49 +010093{
94 uint32_t dumb_ctrl;
95
96 dumb_ctrl = dcrtc->cfg_dumb_ctrl;
97
Russell Kinga0f75d22018-07-30 11:52:34 +010098 if (enable)
Russell King96f60e32012-08-15 13:59:49 +010099 dumb_ctrl |= CFG_DUMB_ENA;
100
101 /*
102 * When the dumb interface isn't in DUMB24_RGB888_0 mode, it might
103 * be using SPI or GPIO. If we set this to DUMB_BLANK, we will
104 * force LCD_D[23:0] to output blank color, overriding the GPIO or
105 * SPI usage. So leave it as-is unless in DUMB24_RGB888_0 mode.
106 */
Russell Kinga0f75d22018-07-30 11:52:34 +0100107 if (!enable && (dumb_ctrl & DUMB_MASK) == DUMB24_RGB888_0) {
Russell King96f60e32012-08-15 13:59:49 +0100108 dumb_ctrl &= ~DUMB_MASK;
109 dumb_ctrl |= DUMB_BLANK;
110 }
111
Russell King155b8292018-07-30 11:52:34 +0100112 armada_updatel(dumb_ctrl,
113 ~(CFG_INV_CSYNC | CFG_INV_HSYNC | CFG_INV_VSYNC),
114 dcrtc->base + LCD_SPU_DUMB_CTRL);
Russell King96f60e32012-08-15 13:59:49 +0100115}
116
Russell Kingdbb4ca82018-07-30 11:52:34 +0100117static void armada_drm_crtc_queue_state_event(struct drm_crtc *crtc)
118{
119 struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
120 struct drm_pending_vblank_event *event;
121
122 /* If we have an event, we need vblank events enabled */
123 event = xchg(&crtc->state->event, NULL);
124 if (event) {
125 WARN_ON(drm_crtc_vblank_get(crtc) != 0);
126 dcrtc->event = event;
127 }
128}
129
Russell King96f60e32012-08-15 13:59:49 +0100130/* The mode_config.mutex will be held for this call */
Russell King96f60e32012-08-15 13:59:49 +0100131static bool armada_drm_crtc_mode_fixup(struct drm_crtc *crtc,
132 const struct drm_display_mode *mode, struct drm_display_mode *adj)
133{
Russell King96f60e32012-08-15 13:59:49 +0100134 struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
135 int ret;
136
137 /* We can't do interlaced modes if we don't have the SPU_ADV_REG */
Russell King42e62ba2014-04-22 15:24:03 +0100138 if (!dcrtc->variant->has_spu_adv_reg &&
Russell King96f60e32012-08-15 13:59:49 +0100139 adj->flags & DRM_MODE_FLAG_INTERLACE)
140 return false;
141
142 /* Check whether the display mode is possible */
Russell King42e62ba2014-04-22 15:24:03 +0100143 ret = dcrtc->variant->compute_clock(dcrtc, adj, NULL);
Russell King96f60e32012-08-15 13:59:49 +0100144 if (ret)
145 return false;
146
147 return true;
148}
149
Shawn Guo5922a7d2017-02-07 17:16:18 +0800150/* These are locked by dev->vbl_lock */
151static void armada_drm_crtc_disable_irq(struct armada_crtc *dcrtc, u32 mask)
152{
153 if (dcrtc->irq_ena & mask) {
154 dcrtc->irq_ena &= ~mask;
155 writel(dcrtc->irq_ena, dcrtc->base + LCD_SPU_IRQ_ENA);
156 }
157}
158
159static void armada_drm_crtc_enable_irq(struct armada_crtc *dcrtc, u32 mask)
160{
161 if ((dcrtc->irq_ena & mask) != mask) {
162 dcrtc->irq_ena |= mask;
163 writel(dcrtc->irq_ena, dcrtc->base + LCD_SPU_IRQ_ENA);
164 if (readl_relaxed(dcrtc->base + LCD_SPU_IRQ_ISR) & mask)
165 writel(0, dcrtc->base + LCD_SPU_IRQ_ISR);
166 }
167}
168
Russell Kinge5d9ddf2014-04-26 15:19:38 +0100169static void armada_drm_crtc_irq(struct armada_crtc *dcrtc, u32 stat)
Russell King96f60e32012-08-15 13:59:49 +0100170{
Russell Kingdbb4ca82018-07-30 11:52:34 +0100171 struct drm_pending_vblank_event *event;
Russell King96f60e32012-08-15 13:59:49 +0100172 void __iomem *base = dcrtc->base;
173
174 if (stat & DMA_FF_UNDERFLOW)
175 DRM_ERROR("video underflow on crtc %u\n", dcrtc->num);
176 if (stat & GRA_FF_UNDERFLOW)
177 DRM_ERROR("graphics underflow on crtc %u\n", dcrtc->num);
178
179 if (stat & VSYNC_IRQ)
Gustavo Padovan0ac28c52016-07-04 21:04:48 -0300180 drm_crtc_handle_vblank(&dcrtc->crtc);
Russell King96f60e32012-08-15 13:59:49 +0100181
Russell Kinga3f6a182017-07-08 10:16:48 +0100182 spin_lock(&dcrtc->irq_lock);
Russell King96f60e32012-08-15 13:59:49 +0100183 if (stat & GRA_FRAME_IRQ && dcrtc->interlaced) {
184 int i = stat & GRA_FRAME_IRQ0 ? 0 : 1;
185 uint32_t val;
186
187 writel_relaxed(dcrtc->v[i].spu_v_porch, base + LCD_SPU_V_PORCH);
188 writel_relaxed(dcrtc->v[i].spu_v_h_total,
189 base + LCD_SPUT_V_H_TOTAL);
190
191 val = readl_relaxed(base + LCD_SPU_ADV_REG);
192 val &= ~(ADV_VSYNC_L_OFF | ADV_VSYNC_H_OFF | ADV_VSYNCOFFEN);
193 val |= dcrtc->v[i].spu_adv_reg;
Russell King662af0d2013-05-19 10:55:17 +0100194 writel_relaxed(val, base + LCD_SPU_ADV_REG);
Russell King96f60e32012-08-15 13:59:49 +0100195 }
Russell King662af0d2013-05-19 10:55:17 +0100196
Russell King3cb13ac2018-07-30 11:53:06 +0100197 if (stat & dcrtc->irq_ena & DUMB_FRAMEDONE) {
198 if (dcrtc->update_pending) {
199 armada_drm_crtc_update_regs(dcrtc, dcrtc->regs);
200 dcrtc->update_pending = false;
201 }
202 if (dcrtc->cursor_update) {
203 writel_relaxed(dcrtc->cursor_hw_pos,
204 base + LCD_SPU_HWC_OVSA_HPXL_VLN);
205 writel_relaxed(dcrtc->cursor_hw_sz,
206 base + LCD_SPU_HWC_HPXL_VLN);
207 armada_updatel(CFG_HWC_ENA,
208 CFG_HWC_ENA | CFG_HWC_1BITMOD |
209 CFG_HWC_1BITENA,
210 base + LCD_SPU_DMA_CTRL0);
211 dcrtc->cursor_update = false;
212 }
Russell King662af0d2013-05-19 10:55:17 +0100213 armada_drm_crtc_disable_irq(dcrtc, DUMB_FRAMEDONE_ENA);
214 }
Russell King96f60e32012-08-15 13:59:49 +0100215 spin_unlock(&dcrtc->irq_lock);
216
Russell King3cb13ac2018-07-30 11:53:06 +0100217 if (stat & VSYNC_IRQ && !dcrtc->update_pending) {
Russell Kingdbb4ca82018-07-30 11:52:34 +0100218 event = xchg(&dcrtc->event, NULL);
219 if (event) {
220 spin_lock(&dcrtc->crtc.dev->event_lock);
221 drm_crtc_send_vblank_event(&dcrtc->crtc, event);
222 spin_unlock(&dcrtc->crtc.dev->event_lock);
223 drm_crtc_vblank_put(&dcrtc->crtc);
224 }
225 }
Russell King96f60e32012-08-15 13:59:49 +0100226}
227
Russell Kinge5d9ddf2014-04-26 15:19:38 +0100228static irqreturn_t armada_drm_irq(int irq, void *arg)
229{
230 struct armada_crtc *dcrtc = arg;
231 u32 v, stat = readl_relaxed(dcrtc->base + LCD_SPU_IRQ_ISR);
232
233 /*
Russell King92298c12018-06-26 17:06:06 +0100234 * Reading the ISR appears to clear bits provided CLEAN_SPU_IRQ_ISR
235 * is set. Writing has some other effect to acknowledge the IRQ -
236 * without this, we only get a single IRQ.
Russell Kinge5d9ddf2014-04-26 15:19:38 +0100237 */
238 writel_relaxed(0, dcrtc->base + LCD_SPU_IRQ_ISR);
239
Russell Kingc8a220c2016-05-17 13:51:08 +0100240 trace_armada_drm_irq(&dcrtc->crtc, stat);
241
Russell Kinge5d9ddf2014-04-26 15:19:38 +0100242 /* Mask out those interrupts we haven't enabled */
243 v = stat & dcrtc->irq_ena;
244
245 if (v & (VSYNC_IRQ|GRA_FRAME_IRQ|DUMB_FRAMEDONE)) {
246 armada_drm_crtc_irq(dcrtc, stat);
247 return IRQ_HANDLED;
248 }
249 return IRQ_NONE;
250}
251
Russell King96f60e32012-08-15 13:59:49 +0100252/* The mode_config.mutex will be held for this call */
Russell Kingc36045e2018-07-30 11:52:34 +0100253static void armada_drm_crtc_mode_set_nofb(struct drm_crtc *crtc)
Russell King96f60e32012-08-15 13:59:49 +0100254{
Russell Kingc36045e2018-07-30 11:52:34 +0100255 struct drm_display_mode *adj = &crtc->state->adjusted_mode;
Russell King96f60e32012-08-15 13:59:49 +0100256 struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
257 struct armada_regs regs[17];
258 uint32_t lm, rm, tm, bm, val, sclk;
259 unsigned long flags;
260 unsigned i;
Russell Kingc36045e2018-07-30 11:52:34 +0100261 bool interlaced = !!(adj->flags & DRM_MODE_FLAG_INTERLACE);
Russell King96f60e32012-08-15 13:59:49 +0100262
Russell King37af35c2016-08-16 22:09:09 +0100263 i = 0;
Russell King96f60e32012-08-15 13:59:49 +0100264 rm = adj->crtc_hsync_start - adj->crtc_hdisplay;
265 lm = adj->crtc_htotal - adj->crtc_hsync_end;
266 bm = adj->crtc_vsync_start - adj->crtc_vdisplay;
267 tm = adj->crtc_vtotal - adj->crtc_vsync_end;
268
Russell Kinga61c3922018-07-30 11:52:34 +0100269 DRM_DEBUG_KMS("[CRTC:%d:%s] mode " DRM_MODE_FMT "\n",
Shayenne Moura0ed833b2019-01-11 12:44:41 -0200270 crtc->base.id, crtc->name, DRM_MODE_ARG(adj));
Russell Kinga61c3922018-07-30 11:52:34 +0100271 DRM_DEBUG_KMS("lm %d rm %d tm %d bm %d\n", lm, rm, tm, bm);
Russell King96f60e32012-08-15 13:59:49 +0100272
Russell King96f60e32012-08-15 13:59:49 +0100273 /* Now compute the divider for real */
Russell King42e62ba2014-04-22 15:24:03 +0100274 dcrtc->variant->compute_clock(dcrtc, adj, &sclk);
Russell King96f60e32012-08-15 13:59:49 +0100275
Russell King96f60e32012-08-15 13:59:49 +0100276 armada_reg_queue_set(regs, i, sclk, LCD_CFG_SCLK_DIV);
277
278 if (interlaced ^ dcrtc->interlaced) {
279 if (adj->flags & DRM_MODE_FLAG_INTERLACE)
Gustavo Padovanaccbaf62016-06-06 11:41:40 -0300280 drm_crtc_vblank_get(&dcrtc->crtc);
Russell King96f60e32012-08-15 13:59:49 +0100281 else
Gustavo Padovanaccbaf62016-06-06 11:41:40 -0300282 drm_crtc_vblank_put(&dcrtc->crtc);
Russell King96f60e32012-08-15 13:59:49 +0100283 dcrtc->interlaced = interlaced;
284 }
285
286 spin_lock_irqsave(&dcrtc->irq_lock, flags);
287
288 /* Even interlaced/progressive frame */
289 dcrtc->v[1].spu_v_h_total = adj->crtc_vtotal << 16 |
290 adj->crtc_htotal;
291 dcrtc->v[1].spu_v_porch = tm << 16 | bm;
292 val = adj->crtc_hsync_start;
Russell King4e4b3562018-07-30 11:52:34 +0100293 dcrtc->v[1].spu_adv_reg = val << 20 | val | ADV_VSYNCOFFEN;
Russell King96f60e32012-08-15 13:59:49 +0100294
295 if (interlaced) {
296 /* Odd interlaced frame */
Russell King4e4b3562018-07-30 11:52:34 +0100297 val -= adj->crtc_htotal / 2;
298 dcrtc->v[0].spu_adv_reg = val << 20 | val | ADV_VSYNCOFFEN;
Russell King96f60e32012-08-15 13:59:49 +0100299 dcrtc->v[0].spu_v_h_total = dcrtc->v[1].spu_v_h_total +
300 (1 << 16);
301 dcrtc->v[0].spu_v_porch = dcrtc->v[1].spu_v_porch + 1;
Russell King96f60e32012-08-15 13:59:49 +0100302 } else {
303 dcrtc->v[0] = dcrtc->v[1];
304 }
305
306 val = adj->crtc_vdisplay << 16 | adj->crtc_hdisplay;
307
308 armada_reg_queue_set(regs, i, val, LCD_SPU_V_H_ACTIVE);
Russell King96f60e32012-08-15 13:59:49 +0100309 armada_reg_queue_set(regs, i, (lm << 16) | rm, LCD_SPU_H_PORCH);
310 armada_reg_queue_set(regs, i, dcrtc->v[0].spu_v_porch, LCD_SPU_V_PORCH);
311 armada_reg_queue_set(regs, i, dcrtc->v[0].spu_v_h_total,
312 LCD_SPUT_V_H_TOTAL);
313
Russell King4e4b3562018-07-30 11:52:34 +0100314 if (dcrtc->variant->has_spu_adv_reg)
Russell King96f60e32012-08-15 13:59:49 +0100315 armada_reg_queue_mod(regs, i, dcrtc->v[0].spu_adv_reg,
316 ADV_VSYNC_L_OFF | ADV_VSYNC_H_OFF |
317 ADV_VSYNCOFFEN, LCD_SPU_ADV_REG);
318
Russell King96f60e32012-08-15 13:59:49 +0100319 val = adj->flags & DRM_MODE_FLAG_NVSYNC ? CFG_VSYNC_INV : 0;
320 armada_reg_queue_mod(regs, i, val, CFG_VSYNC_INV, LCD_SPU_DMA_CTRL1);
Russell King155b8292018-07-30 11:52:34 +0100321
322 /*
323 * The documentation doesn't indicate what the normal state of
324 * the sync signals are. Sebastian Hesselbart kindly probed
325 * these signals on his board to determine their state.
326 *
327 * The non-inverted state of the sync signals is active high.
328 * Setting these bits makes the appropriate signal active low.
329 */
330 val = 0;
331 if (adj->flags & DRM_MODE_FLAG_NCSYNC)
332 val |= CFG_INV_CSYNC;
333 if (adj->flags & DRM_MODE_FLAG_NHSYNC)
334 val |= CFG_INV_HSYNC;
335 if (adj->flags & DRM_MODE_FLAG_NVSYNC)
336 val |= CFG_INV_VSYNC;
337 armada_reg_queue_mod(regs, i, val, CFG_INV_CSYNC | CFG_INV_HSYNC |
338 CFG_INV_VSYNC, LCD_SPU_DUMB_CTRL);
Russell King96f60e32012-08-15 13:59:49 +0100339 armada_reg_queue_end(regs, i);
340
341 armada_drm_crtc_update_regs(dcrtc, regs);
342 spin_unlock_irqrestore(&dcrtc->irq_lock, flags);
Russell King96f60e32012-08-15 13:59:49 +0100343}
344
Russell Kingc36045e2018-07-30 11:52:34 +0100345static void armada_drm_crtc_atomic_begin(struct drm_crtc *crtc,
346 struct drm_crtc_state *old_crtc_state)
347{
348 struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
Russell Kingc36045e2018-07-30 11:52:34 +0100349
350 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
351
Russell Kingc36045e2018-07-30 11:52:34 +0100352 dcrtc->regs_idx = 0;
353 dcrtc->regs = dcrtc->atomic_regs;
354}
355
356static void armada_drm_crtc_atomic_flush(struct drm_crtc *crtc,
357 struct drm_crtc_state *old_crtc_state)
358{
359 struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
Russell Kingc36045e2018-07-30 11:52:34 +0100360
361 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
362
363 armada_reg_queue_end(dcrtc->regs, dcrtc->regs_idx);
364
Russell Kingdbb4ca82018-07-30 11:52:34 +0100365 /*
366 * If we aren't doing a full modeset, then we need to queue
367 * the event here.
368 */
Russell King3cb13ac2018-07-30 11:53:06 +0100369 if (!drm_atomic_crtc_needs_modeset(crtc->state)) {
370 dcrtc->update_pending = true;
Russell Kingdbb4ca82018-07-30 11:52:34 +0100371 armada_drm_crtc_queue_state_event(crtc);
Russell King3cb13ac2018-07-30 11:53:06 +0100372 spin_lock_irq(&dcrtc->irq_lock);
373 armada_drm_crtc_enable_irq(dcrtc, DUMB_FRAMEDONE_ENA);
374 spin_unlock_irq(&dcrtc->irq_lock);
375 } else {
376 spin_lock_irq(&dcrtc->irq_lock);
377 armada_drm_crtc_update_regs(dcrtc, dcrtc->regs);
378 spin_unlock_irq(&dcrtc->irq_lock);
379 }
Russell Kingc36045e2018-07-30 11:52:34 +0100380}
381
Russell King34e25ed2018-07-30 11:52:34 +0100382static void armada_drm_crtc_atomic_disable(struct drm_crtc *crtc,
383 struct drm_crtc_state *old_state)
384{
385 struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
386 struct drm_pending_vblank_event *event;
Russell King34e25ed2018-07-30 11:52:34 +0100387
388 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
389
Russell King34e25ed2018-07-30 11:52:34 +0100390 drm_crtc_vblank_off(crtc);
391 armada_drm_crtc_update(dcrtc, false);
392
393 if (!crtc->state->active) {
394 /*
395 * This modeset will be leaving the CRTC disabled, so
396 * call the backend to disable upstream clocks etc.
397 */
398 if (dcrtc->variant->disable)
399 dcrtc->variant->disable(dcrtc);
400
401 /*
402 * We will not receive any further vblank events.
403 * Send the flip_done event manually.
404 */
405 event = crtc->state->event;
406 crtc->state->event = NULL;
407 if (event) {
408 spin_lock_irq(&crtc->dev->event_lock);
409 drm_crtc_send_vblank_event(crtc, event);
410 spin_unlock_irq(&crtc->dev->event_lock);
411 }
412 }
413}
414
415static void armada_drm_crtc_atomic_enable(struct drm_crtc *crtc,
416 struct drm_crtc_state *old_state)
417{
418 struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
419
420 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
421
Russell King34e25ed2018-07-30 11:52:34 +0100422 if (!old_state->active) {
423 /*
424 * This modeset is enabling the CRTC after it having
425 * been disabled. Reverse the call to ->disable in
426 * the atomic_disable().
427 */
428 if (dcrtc->variant->enable)
429 dcrtc->variant->enable(dcrtc, &crtc->state->adjusted_mode);
430 }
431 armada_drm_crtc_update(dcrtc, true);
432 drm_crtc_vblank_on(crtc);
433
434 armada_drm_crtc_queue_state_event(crtc);
435}
436
Russell King96f60e32012-08-15 13:59:49 +0100437static const struct drm_crtc_helper_funcs armada_crtc_helper_funcs = {
Russell King96f60e32012-08-15 13:59:49 +0100438 .mode_fixup = armada_drm_crtc_mode_fixup,
Russell Kingc36045e2018-07-30 11:52:34 +0100439 .mode_set_nofb = armada_drm_crtc_mode_set_nofb,
Russell Kingc36045e2018-07-30 11:52:34 +0100440 .atomic_begin = armada_drm_crtc_atomic_begin,
441 .atomic_flush = armada_drm_crtc_atomic_flush,
Russell King34e25ed2018-07-30 11:52:34 +0100442 .atomic_disable = armada_drm_crtc_atomic_disable,
443 .atomic_enable = armada_drm_crtc_atomic_enable,
Russell King96f60e32012-08-15 13:59:49 +0100444};
445
Russell King662af0d2013-05-19 10:55:17 +0100446static void armada_load_cursor_argb(void __iomem *base, uint32_t *pix,
447 unsigned stride, unsigned width, unsigned height)
448{
449 uint32_t addr;
450 unsigned y;
451
452 addr = SRAM_HWC32_RAM1;
453 for (y = 0; y < height; y++) {
454 uint32_t *p = &pix[y * stride];
455 unsigned x;
456
457 for (x = 0; x < width; x++, p++) {
458 uint32_t val = *p;
459
460 val = (val & 0xff00ff00) |
461 (val & 0x000000ff) << 16 |
462 (val & 0x00ff0000) >> 16;
463
464 writel_relaxed(val,
465 base + LCD_SPU_SRAM_WRDAT);
466 writel_relaxed(addr | SRAM_WRITE,
467 base + LCD_SPU_SRAM_CTRL);
Russell Kingc39b0692014-04-07 12:00:17 +0100468 readl_relaxed(base + LCD_SPU_HWC_OVSA_HPXL_VLN);
Russell King662af0d2013-05-19 10:55:17 +0100469 addr += 1;
470 if ((addr & 0x00ff) == 0)
471 addr += 0xf00;
472 if ((addr & 0x30ff) == 0)
473 addr = SRAM_HWC32_RAM2;
474 }
475 }
476}
477
478static void armada_drm_crtc_cursor_tran(void __iomem *base)
479{
480 unsigned addr;
481
482 for (addr = 0; addr < 256; addr++) {
483 /* write the default value */
484 writel_relaxed(0x55555555, base + LCD_SPU_SRAM_WRDAT);
485 writel_relaxed(addr | SRAM_WRITE | SRAM_HWC32_TRAN,
486 base + LCD_SPU_SRAM_CTRL);
487 }
488}
489
490static int armada_drm_crtc_cursor_update(struct armada_crtc *dcrtc, bool reload)
491{
492 uint32_t xoff, xscr, w = dcrtc->cursor_w, s;
493 uint32_t yoff, yscr, h = dcrtc->cursor_h;
494 uint32_t para1;
495
496 /*
497 * Calculate the visible width and height of the cursor,
498 * screen position, and the position in the cursor bitmap.
499 */
500 if (dcrtc->cursor_x < 0) {
501 xoff = -dcrtc->cursor_x;
502 xscr = 0;
503 w -= min(xoff, w);
504 } else if (dcrtc->cursor_x + w > dcrtc->crtc.mode.hdisplay) {
505 xoff = 0;
506 xscr = dcrtc->cursor_x;
507 w = max_t(int, dcrtc->crtc.mode.hdisplay - dcrtc->cursor_x, 0);
508 } else {
509 xoff = 0;
510 xscr = dcrtc->cursor_x;
511 }
512
513 if (dcrtc->cursor_y < 0) {
514 yoff = -dcrtc->cursor_y;
515 yscr = 0;
516 h -= min(yoff, h);
517 } else if (dcrtc->cursor_y + h > dcrtc->crtc.mode.vdisplay) {
518 yoff = 0;
519 yscr = dcrtc->cursor_y;
520 h = max_t(int, dcrtc->crtc.mode.vdisplay - dcrtc->cursor_y, 0);
521 } else {
522 yoff = 0;
523 yscr = dcrtc->cursor_y;
524 }
525
526 /* On interlaced modes, the vertical cursor size must be halved */
527 s = dcrtc->cursor_w;
528 if (dcrtc->interlaced) {
529 s *= 2;
530 yscr /= 2;
531 h /= 2;
532 }
533
534 if (!dcrtc->cursor_obj || !h || !w) {
535 spin_lock_irq(&dcrtc->irq_lock);
Russell King662af0d2013-05-19 10:55:17 +0100536 dcrtc->cursor_update = false;
537 armada_updatel(0, CFG_HWC_ENA, dcrtc->base + LCD_SPU_DMA_CTRL0);
538 spin_unlock_irq(&dcrtc->irq_lock);
539 return 0;
540 }
541
Russell King214612f2017-07-08 10:22:15 +0100542 spin_lock_irq(&dcrtc->irq_lock);
Russell King662af0d2013-05-19 10:55:17 +0100543 para1 = readl_relaxed(dcrtc->base + LCD_SPU_SRAM_PARA1);
544 armada_updatel(CFG_CSB_256x32, CFG_CSB_256x32 | CFG_PDWN256x32,
545 dcrtc->base + LCD_SPU_SRAM_PARA1);
Russell King214612f2017-07-08 10:22:15 +0100546 spin_unlock_irq(&dcrtc->irq_lock);
Russell King662af0d2013-05-19 10:55:17 +0100547
548 /*
549 * Initialize the transparency if the SRAM was powered down.
550 * We must also reload the cursor data as well.
551 */
552 if (!(para1 & CFG_CSB_256x32)) {
553 armada_drm_crtc_cursor_tran(dcrtc->base);
554 reload = true;
555 }
556
557 if (dcrtc->cursor_hw_sz != (h << 16 | w)) {
558 spin_lock_irq(&dcrtc->irq_lock);
Russell King662af0d2013-05-19 10:55:17 +0100559 dcrtc->cursor_update = false;
560 armada_updatel(0, CFG_HWC_ENA, dcrtc->base + LCD_SPU_DMA_CTRL0);
561 spin_unlock_irq(&dcrtc->irq_lock);
562 reload = true;
563 }
564 if (reload) {
565 struct armada_gem_object *obj = dcrtc->cursor_obj;
566 uint32_t *pix;
567 /* Set the top-left corner of the cursor image */
568 pix = obj->addr;
569 pix += yoff * s + xoff;
570 armada_load_cursor_argb(dcrtc->base, pix, s, w, h);
571 }
572
573 /* Reload the cursor position, size and enable in the IRQ handler */
574 spin_lock_irq(&dcrtc->irq_lock);
575 dcrtc->cursor_hw_pos = yscr << 16 | xscr;
576 dcrtc->cursor_hw_sz = h << 16 | w;
577 dcrtc->cursor_update = true;
578 armada_drm_crtc_enable_irq(dcrtc, DUMB_FRAMEDONE_ENA);
579 spin_unlock_irq(&dcrtc->irq_lock);
580
581 return 0;
582}
583
584static void cursor_update(void *data)
585{
586 armada_drm_crtc_cursor_update(data, true);
587}
588
589static int armada_drm_crtc_cursor_set(struct drm_crtc *crtc,
590 struct drm_file *file, uint32_t handle, uint32_t w, uint32_t h)
591{
Russell King662af0d2013-05-19 10:55:17 +0100592 struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
Russell King662af0d2013-05-19 10:55:17 +0100593 struct armada_gem_object *obj = NULL;
594 int ret;
595
596 /* If no cursor support, replicate drm's return value */
Russell King42e62ba2014-04-22 15:24:03 +0100597 if (!dcrtc->variant->has_spu_adv_reg)
Russell King662af0d2013-05-19 10:55:17 +0100598 return -ENXIO;
599
600 if (handle && w > 0 && h > 0) {
601 /* maximum size is 64x32 or 32x64 */
602 if (w > 64 || h > 64 || (w > 32 && h > 32))
603 return -ENOMEM;
604
Chris Wilsona8ad0bd2016-05-09 11:04:54 +0100605 obj = armada_gem_object_lookup(file, handle);
Russell King662af0d2013-05-19 10:55:17 +0100606 if (!obj)
607 return -ENOENT;
608
609 /* Must be a kernel-mapped object */
610 if (!obj->addr) {
Haneen Mohammed4c3cf372017-09-20 12:54:48 -0600611 drm_gem_object_put_unlocked(&obj->obj);
Russell King662af0d2013-05-19 10:55:17 +0100612 return -EINVAL;
613 }
614
615 if (obj->obj.size < w * h * 4) {
616 DRM_ERROR("buffer is too small\n");
Haneen Mohammed4c3cf372017-09-20 12:54:48 -0600617 drm_gem_object_put_unlocked(&obj->obj);
Russell King662af0d2013-05-19 10:55:17 +0100618 return -ENOMEM;
619 }
620 }
621
Russell King662af0d2013-05-19 10:55:17 +0100622 if (dcrtc->cursor_obj) {
623 dcrtc->cursor_obj->update = NULL;
624 dcrtc->cursor_obj->update_data = NULL;
Haneen Mohammed4c3cf372017-09-20 12:54:48 -0600625 drm_gem_object_put_unlocked(&dcrtc->cursor_obj->obj);
Russell King662af0d2013-05-19 10:55:17 +0100626 }
627 dcrtc->cursor_obj = obj;
628 dcrtc->cursor_w = w;
629 dcrtc->cursor_h = h;
630 ret = armada_drm_crtc_cursor_update(dcrtc, true);
631 if (obj) {
632 obj->update_data = dcrtc;
633 obj->update = cursor_update;
634 }
Russell King662af0d2013-05-19 10:55:17 +0100635
636 return ret;
637}
638
639static int armada_drm_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
640{
Russell King662af0d2013-05-19 10:55:17 +0100641 struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
Russell King662af0d2013-05-19 10:55:17 +0100642 int ret;
643
644 /* If no cursor support, replicate drm's return value */
Russell King42e62ba2014-04-22 15:24:03 +0100645 if (!dcrtc->variant->has_spu_adv_reg)
Russell King662af0d2013-05-19 10:55:17 +0100646 return -EFAULT;
647
Russell King662af0d2013-05-19 10:55:17 +0100648 dcrtc->cursor_x = x;
649 dcrtc->cursor_y = y;
650 ret = armada_drm_crtc_cursor_update(dcrtc, false);
Russell King662af0d2013-05-19 10:55:17 +0100651
652 return ret;
653}
654
Russell King96f60e32012-08-15 13:59:49 +0100655static void armada_drm_crtc_destroy(struct drm_crtc *crtc)
656{
657 struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
658 struct armada_private *priv = crtc->dev->dev_private;
659
Russell King662af0d2013-05-19 10:55:17 +0100660 if (dcrtc->cursor_obj)
Haneen Mohammed4c3cf372017-09-20 12:54:48 -0600661 drm_gem_object_put_unlocked(&dcrtc->cursor_obj->obj);
Russell King662af0d2013-05-19 10:55:17 +0100662
Russell King96f60e32012-08-15 13:59:49 +0100663 priv->dcrtc[dcrtc->num] = NULL;
664 drm_crtc_cleanup(&dcrtc->crtc);
665
Russell Kinga0fbb352018-07-30 11:52:34 +0100666 if (dcrtc->variant->disable)
667 dcrtc->variant->disable(dcrtc);
Russell King96f60e32012-08-15 13:59:49 +0100668
Russell Kinge5d9ddf2014-04-26 15:19:38 +0100669 writel_relaxed(0, dcrtc->base + LCD_SPU_IRQ_ENA);
670
Russell King9611cb92014-06-15 11:21:23 +0100671 of_node_put(dcrtc->crtc.port);
672
Russell King96f60e32012-08-15 13:59:49 +0100673 kfree(dcrtc);
674}
675
Shawn Guo5922a7d2017-02-07 17:16:18 +0800676/* These are called under the vbl_lock. */
677static int armada_drm_crtc_enable_vblank(struct drm_crtc *crtc)
678{
679 struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
Russell King92298c12018-06-26 17:06:06 +0100680 unsigned long flags;
Shawn Guo5922a7d2017-02-07 17:16:18 +0800681
Russell King92298c12018-06-26 17:06:06 +0100682 spin_lock_irqsave(&dcrtc->irq_lock, flags);
Shawn Guo5922a7d2017-02-07 17:16:18 +0800683 armada_drm_crtc_enable_irq(dcrtc, VSYNC_IRQ_ENA);
Russell King92298c12018-06-26 17:06:06 +0100684 spin_unlock_irqrestore(&dcrtc->irq_lock, flags);
Shawn Guo5922a7d2017-02-07 17:16:18 +0800685 return 0;
686}
687
688static void armada_drm_crtc_disable_vblank(struct drm_crtc *crtc)
689{
690 struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
Russell King92298c12018-06-26 17:06:06 +0100691 unsigned long flags;
Shawn Guo5922a7d2017-02-07 17:16:18 +0800692
Russell King92298c12018-06-26 17:06:06 +0100693 spin_lock_irqsave(&dcrtc->irq_lock, flags);
Shawn Guo5922a7d2017-02-07 17:16:18 +0800694 armada_drm_crtc_disable_irq(dcrtc, VSYNC_IRQ_ENA);
Russell King92298c12018-06-26 17:06:06 +0100695 spin_unlock_irqrestore(&dcrtc->irq_lock, flags);
Shawn Guo5922a7d2017-02-07 17:16:18 +0800696}
697
Ville Syrjäläa02fb902015-12-15 12:20:59 +0100698static const struct drm_crtc_funcs armada_crtc_funcs = {
Russell Kingc36045e2018-07-30 11:52:34 +0100699 .reset = drm_atomic_helper_crtc_reset,
Russell King662af0d2013-05-19 10:55:17 +0100700 .cursor_set = armada_drm_crtc_cursor_set,
701 .cursor_move = armada_drm_crtc_cursor_move,
Russell King96f60e32012-08-15 13:59:49 +0100702 .destroy = armada_drm_crtc_destroy,
Russell King6d2f8642018-07-30 11:53:06 +0100703 .set_config = drm_atomic_helper_set_config,
Russell King13c94d52018-07-30 11:53:06 +0100704 .page_flip = drm_atomic_helper_page_flip,
Russell Kingc36045e2018-07-30 11:52:34 +0100705 .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
706 .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
Shawn Guo5922a7d2017-02-07 17:16:18 +0800707 .enable_vblank = armada_drm_crtc_enable_vblank,
708 .disable_vblank = armada_drm_crtc_disable_vblank,
Russell King96f60e32012-08-15 13:59:49 +0100709};
710
Russell King0fb29702015-06-06 21:46:53 +0100711static int armada_drm_crtc_create(struct drm_device *drm, struct device *dev,
Russell King9611cb92014-06-15 11:21:23 +0100712 struct resource *res, int irq, const struct armada_variant *variant,
713 struct device_node *port)
Russell King96f60e32012-08-15 13:59:49 +0100714{
Russell Kingd8c96082014-04-22 11:10:15 +0100715 struct armada_private *priv = drm->dev_private;
Russell King96f60e32012-08-15 13:59:49 +0100716 struct armada_crtc *dcrtc;
Russell King82c702c2018-07-30 11:53:06 +0100717 struct drm_plane *primary;
Russell King96f60e32012-08-15 13:59:49 +0100718 void __iomem *base;
719 int ret;
720
Linus Torvaldsa7d7a142014-08-07 17:36:12 -0700721 base = devm_ioremap_resource(dev, res);
Jingoo Hanc9d53c02014-06-11 14:00:05 +0900722 if (IS_ERR(base))
723 return PTR_ERR(base);
Russell King96f60e32012-08-15 13:59:49 +0100724
725 dcrtc = kzalloc(sizeof(*dcrtc), GFP_KERNEL);
726 if (!dcrtc) {
727 DRM_ERROR("failed to allocate Armada crtc\n");
728 return -ENOMEM;
729 }
730
Russell Kingd8c96082014-04-22 11:10:15 +0100731 if (dev != drm->dev)
732 dev_set_drvdata(dev, dcrtc);
733
Russell King42e62ba2014-04-22 15:24:03 +0100734 dcrtc->variant = variant;
Russell King96f60e32012-08-15 13:59:49 +0100735 dcrtc->base = base;
Russell Kingd8c96082014-04-22 11:10:15 +0100736 dcrtc->num = drm->mode_config.num_crtc;
Russell King96f60e32012-08-15 13:59:49 +0100737 dcrtc->clk = ERR_PTR(-EINVAL);
Russell King96f60e32012-08-15 13:59:49 +0100738 dcrtc->cfg_dumb_ctrl = DUMB24_RGB888_0;
739 dcrtc->spu_iopad_ctrl = CFG_VSCALE_LN_EN | CFG_IOPAD_DUMB24;
740 spin_lock_init(&dcrtc->irq_lock);
741 dcrtc->irq_ena = CLEAN_SPU_IRQ_ISR;
Russell King96f60e32012-08-15 13:59:49 +0100742
743 /* Initialize some registers which we don't otherwise set */
744 writel_relaxed(0x00000001, dcrtc->base + LCD_CFG_SCLK_DIV);
745 writel_relaxed(0x00000000, dcrtc->base + LCD_SPU_BLANKCOLOR);
746 writel_relaxed(dcrtc->spu_iopad_ctrl,
747 dcrtc->base + LCD_SPU_IOPAD_CONTROL);
748 writel_relaxed(0x00000000, dcrtc->base + LCD_SPU_SRAM_PARA0);
749 writel_relaxed(CFG_PDWN256x32 | CFG_PDWN256x24 | CFG_PDWN256x8 |
750 CFG_PDWN32x32 | CFG_PDWN16x66 | CFG_PDWN32x66 |
751 CFG_PDWN64x66, dcrtc->base + LCD_SPU_SRAM_PARA1);
752 writel_relaxed(0x2032ff81, dcrtc->base + LCD_SPU_DMA_CTRL1);
Russell Kinge5d9ddf2014-04-26 15:19:38 +0100753 writel_relaxed(dcrtc->irq_ena, dcrtc->base + LCD_SPU_IRQ_ENA);
Russell King92298c12018-06-26 17:06:06 +0100754 readl_relaxed(dcrtc->base + LCD_SPU_IRQ_ISR);
Russell Kinge5d9ddf2014-04-26 15:19:38 +0100755 writel_relaxed(0, dcrtc->base + LCD_SPU_IRQ_ISR);
Russell King96f60e32012-08-15 13:59:49 +0100756
Russell Kinge5d9ddf2014-04-26 15:19:38 +0100757 ret = devm_request_irq(dev, irq, armada_drm_irq, 0, "armada_drm_crtc",
758 dcrtc);
Russell King33cd3c02017-12-08 12:16:22 +0000759 if (ret < 0)
760 goto err_crtc;
Russell King96f60e32012-08-15 13:59:49 +0100761
Russell King42e62ba2014-04-22 15:24:03 +0100762 if (dcrtc->variant->init) {
Russell Kingd8c96082014-04-22 11:10:15 +0100763 ret = dcrtc->variant->init(dcrtc, dev);
Russell King33cd3c02017-12-08 12:16:22 +0000764 if (ret)
765 goto err_crtc;
Russell King96f60e32012-08-15 13:59:49 +0100766 }
767
768 /* Ensure AXI pipeline is enabled */
769 armada_updatel(CFG_ARBFAST_ENA, 0, dcrtc->base + LCD_SPU_DMA_CTRL0);
770
771 priv->dcrtc[dcrtc->num] = dcrtc;
772
Russell King9611cb92014-06-15 11:21:23 +0100773 dcrtc->crtc.port = port;
Russell King1c914ce2015-07-15 18:11:24 +0100774
Russell Kingde323012015-07-15 18:11:24 +0100775 primary = kzalloc(sizeof(*primary), GFP_KERNEL);
Russell King33cd3c02017-12-08 12:16:22 +0000776 if (!primary) {
777 ret = -ENOMEM;
778 goto err_crtc;
779 }
Russell King1c914ce2015-07-15 18:11:24 +0100780
Russell Kingd40af7b2018-07-30 11:52:34 +0100781 ret = armada_drm_primary_plane_init(drm, primary);
Russell Kingde323012015-07-15 18:11:24 +0100782 if (ret) {
783 kfree(primary);
Russell King33cd3c02017-12-08 12:16:22 +0000784 goto err_crtc;
Russell Kingde323012015-07-15 18:11:24 +0100785 }
786
Russell King82c702c2018-07-30 11:53:06 +0100787 ret = drm_crtc_init_with_planes(drm, &dcrtc->crtc, primary, NULL,
Ville Syrjäläf9882872015-12-09 16:19:31 +0200788 &armada_crtc_funcs, NULL);
Russell King1c914ce2015-07-15 18:11:24 +0100789 if (ret)
790 goto err_crtc_init;
791
Russell King96f60e32012-08-15 13:59:49 +0100792 drm_crtc_helper_add(&dcrtc->crtc, &armada_crtc_helper_funcs);
793
Russell Kingd8c96082014-04-22 11:10:15 +0100794 return armada_overlay_plane_create(drm, 1 << dcrtc->num);
Russell King1c914ce2015-07-15 18:11:24 +0100795
796err_crtc_init:
Russell King82c702c2018-07-30 11:53:06 +0100797 primary->funcs->destroy(primary);
Russell King33cd3c02017-12-08 12:16:22 +0000798err_crtc:
799 kfree(dcrtc);
800
Russell King1c914ce2015-07-15 18:11:24 +0100801 return ret;
Russell King96f60e32012-08-15 13:59:49 +0100802}
Russell Kingd8c96082014-04-22 11:10:15 +0100803
804static int
805armada_lcd_bind(struct device *dev, struct device *master, void *data)
806{
807 struct platform_device *pdev = to_platform_device(dev);
808 struct drm_device *drm = data;
809 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
810 int irq = platform_get_irq(pdev, 0);
811 const struct armada_variant *variant;
Russell King9611cb92014-06-15 11:21:23 +0100812 struct device_node *port = NULL;
Russell Kingd8c96082014-04-22 11:10:15 +0100813
814 if (irq < 0)
815 return irq;
816
817 if (!dev->of_node) {
818 const struct platform_device_id *id;
819
820 id = platform_get_device_id(pdev);
821 if (!id)
822 return -ENXIO;
823
824 variant = (const struct armada_variant *)id->driver_data;
825 } else {
826 const struct of_device_id *match;
Russell King9611cb92014-06-15 11:21:23 +0100827 struct device_node *np, *parent = dev->of_node;
Russell Kingd8c96082014-04-22 11:10:15 +0100828
829 match = of_match_device(dev->driver->of_match_table, dev);
830 if (!match)
831 return -ENXIO;
832
Russell King9611cb92014-06-15 11:21:23 +0100833 np = of_get_child_by_name(parent, "ports");
834 if (np)
835 parent = np;
836 port = of_get_child_by_name(parent, "port");
837 of_node_put(np);
838 if (!port) {
Rob Herring4bf99142017-07-18 16:43:04 -0500839 dev_err(dev, "no port node found in %pOF\n", parent);
Russell King9611cb92014-06-15 11:21:23 +0100840 return -ENXIO;
841 }
842
Russell Kingd8c96082014-04-22 11:10:15 +0100843 variant = match->data;
844 }
845
Russell King9611cb92014-06-15 11:21:23 +0100846 return armada_drm_crtc_create(drm, dev, res, irq, variant, port);
Russell Kingd8c96082014-04-22 11:10:15 +0100847}
848
849static void
850armada_lcd_unbind(struct device *dev, struct device *master, void *data)
851{
852 struct armada_crtc *dcrtc = dev_get_drvdata(dev);
853
854 armada_drm_crtc_destroy(&dcrtc->crtc);
855}
856
857static const struct component_ops armada_lcd_ops = {
858 .bind = armada_lcd_bind,
859 .unbind = armada_lcd_unbind,
860};
861
862static int armada_lcd_probe(struct platform_device *pdev)
863{
864 return component_add(&pdev->dev, &armada_lcd_ops);
865}
866
867static int armada_lcd_remove(struct platform_device *pdev)
868{
869 component_del(&pdev->dev, &armada_lcd_ops);
870 return 0;
871}
872
Arvind Yadav85909712017-06-20 10:44:33 +0530873static const struct of_device_id armada_lcd_of_match[] = {
Russell Kingd8c96082014-04-22 11:10:15 +0100874 {
875 .compatible = "marvell,dove-lcd",
876 .data = &armada510_ops,
877 },
878 {}
879};
880MODULE_DEVICE_TABLE(of, armada_lcd_of_match);
881
882static const struct platform_device_id armada_lcd_platform_ids[] = {
883 {
884 .name = "armada-lcd",
885 .driver_data = (unsigned long)&armada510_ops,
886 }, {
887 .name = "armada-510-lcd",
888 .driver_data = (unsigned long)&armada510_ops,
889 },
890 { },
891};
892MODULE_DEVICE_TABLE(platform, armada_lcd_platform_ids);
893
894struct platform_driver armada_lcd_platform_driver = {
895 .probe = armada_lcd_probe,
896 .remove = armada_lcd_remove,
897 .driver = {
898 .name = "armada-lcd",
899 .owner = THIS_MODULE,
900 .of_match_table = armada_lcd_of_match,
901 },
902 .id_table = armada_lcd_platform_ids,
903};