1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
296f60e37SRussell King /*
396f60e37SRussell King * Copyright (C) 2012 Russell King
496f60e37SRussell King * Rewritten from the dovefb driver, and Armada510 manuals.
596f60e37SRussell King */
625e28ef2SSam Ravnborg
796f60e37SRussell King #include <linux/clk.h>
8d8c96083SRussell King #include <linux/component.h>
925e28ef2SSam Ravnborg #include <linux/module.h>
10d8c96083SRussell King #include <linux/of_device.h>
11d8c96083SRussell King #include <linux/platform_device.h>
1225e28ef2SSam Ravnborg
13de503ddfSRussell King #include <drm/drm_atomic.h>
14bcd21a47SDave Airlie #include <drm/drm_atomic_helper.h>
1525e28ef2SSam Ravnborg #include <drm/drm_probe_helper.h>
1625e28ef2SSam Ravnborg #include <drm/drm_vblank.h>
1725e28ef2SSam Ravnborg
1896f60e37SRussell King #include "armada_crtc.h"
1996f60e37SRussell King #include "armada_drm.h"
2096f60e37SRussell King #include "armada_fb.h"
2196f60e37SRussell King #include "armada_gem.h"
2296f60e37SRussell King #include "armada_hw.h"
23d40af7b1SRussell King #include "armada_plane.h"
24c8a220c6SRussell King #include "armada_trace.h"
2596f60e37SRussell King
2696f60e37SRussell King /*
2796f60e37SRussell King * A note about interlacing. Let's consider HDMI 1920x1080i.
2896f60e37SRussell King * The timing parameters we have from X are:
2996f60e37SRussell King * Hact HsyA HsyI Htot Vact VsyA VsyI Vtot
3096f60e37SRussell King * 1920 2448 2492 2640 1080 1084 1094 1125
3196f60e37SRussell King * Which get translated to:
3296f60e37SRussell King * Hact HsyA HsyI Htot Vact VsyA VsyI Vtot
3396f60e37SRussell King * 1920 2448 2492 2640 540 542 547 562
3496f60e37SRussell King *
3596f60e37SRussell King * This is how it is defined by CEA-861-D - line and pixel numbers are
3696f60e37SRussell King * referenced to the rising edge of VSYNC and HSYNC. Total clocks per
3796f60e37SRussell King * line: 2640. The odd frame, the first active line is at line 21, and
3896f60e37SRussell King * the even frame, the first active line is 584.
3996f60e37SRussell King *
4096f60e37SRussell King * LN: 560 561 562 563 567 568 569
4196f60e37SRussell King * DE: ~~~|____________________________//__________________________
4296f60e37SRussell King * HSYNC: ____|~|_____|~|_____|~|_____|~|_//__|~|_____|~|_____|~|_____
4396f60e37SRussell King * VSYNC: _________________________|~~~~~~//~~~~~~~~~~~~~~~|__________
4496f60e37SRussell King * 22 blanking lines. VSYNC at 1320 (referenced to the HSYNC rising edge).
4596f60e37SRussell King *
4696f60e37SRussell King * LN: 1123 1124 1125 1 5 6 7
4796f60e37SRussell King * DE: ~~~|____________________________//__________________________
4896f60e37SRussell King * HSYNC: ____|~|_____|~|_____|~|_____|~|_//__|~|_____|~|_____|~|_____
4996f60e37SRussell King * VSYNC: ____________________|~~~~~~~~~~~//~~~~~~~~~~|_______________
5096f60e37SRussell King * 23 blanking lines
5196f60e37SRussell King *
5296f60e37SRussell King * The Armada LCD Controller line and pixel numbers are, like X timings,
5396f60e37SRussell King * referenced to the top left of the active frame.
5496f60e37SRussell King *
5596f60e37SRussell King * So, translating these to our LCD controller:
5696f60e37SRussell King * Odd frame, 563 total lines, VSYNC at line 543-548, pixel 1128.
5796f60e37SRussell King * Even frame, 562 total lines, VSYNC at line 542-547, pixel 2448.
5896f60e37SRussell King * Note: Vsync front porch remains constant!
5996f60e37SRussell King *
6096f60e37SRussell King * if (odd_frame) {
6196f60e37SRussell King * vtotal = mode->crtc_vtotal + 1;
6296f60e37SRussell King * vbackporch = mode->crtc_vsync_start - mode->crtc_vdisplay + 1;
6396f60e37SRussell King * vhorizpos = mode->crtc_hsync_start - mode->crtc_htotal / 2
6496f60e37SRussell King * } else {
6596f60e37SRussell King * vtotal = mode->crtc_vtotal;
6696f60e37SRussell King * vbackporch = mode->crtc_vsync_start - mode->crtc_vdisplay;
6796f60e37SRussell King * vhorizpos = mode->crtc_hsync_start;
6896f60e37SRussell King * }
6996f60e37SRussell King * vfrontporch = mode->crtc_vtotal - mode->crtc_vsync_end;
7096f60e37SRussell King *
7196f60e37SRussell King * So, we need to reprogram these registers on each vsync event:
7296f60e37SRussell King * LCD_SPU_V_PORCH, LCD_SPU_ADV_REG, LCD_SPUT_V_H_TOTAL
7396f60e37SRussell King *
7496f60e37SRussell King * Note: we do not use the frame done interrupts because these appear
7596f60e37SRussell King * to happen too early, and lead to jitter on the display (presumably
7696f60e37SRussell King * they occur at the end of the last active line, before the vsync back
7796f60e37SRussell King * porch, which we're reprogramming.)
7896f60e37SRussell King */
7996f60e37SRussell King
8096f60e37SRussell King void
armada_drm_crtc_update_regs(struct armada_crtc * dcrtc,struct armada_regs * regs)8196f60e37SRussell King armada_drm_crtc_update_regs(struct armada_crtc *dcrtc, struct armada_regs *regs)
8296f60e37SRussell King {
8396f60e37SRussell King while (regs->offset != ~0) {
8496f60e37SRussell King void __iomem *reg = dcrtc->base + regs->offset;
8596f60e37SRussell King uint32_t val;
8696f60e37SRussell King
8796f60e37SRussell King val = regs->mask;
8896f60e37SRussell King if (val != 0)
8996f60e37SRussell King val &= readl_relaxed(reg);
9096f60e37SRussell King writel_relaxed(val | regs->val, reg);
9196f60e37SRussell King ++regs;
9296f60e37SRussell King }
9396f60e37SRussell King }
9496f60e37SRussell King
armada_drm_crtc_update(struct armada_crtc * dcrtc,bool enable)95a0f75d24SRussell King static void armada_drm_crtc_update(struct armada_crtc *dcrtc, bool enable)
9696f60e37SRussell King {
9796f60e37SRussell King uint32_t dumb_ctrl;
9896f60e37SRussell King
9996f60e37SRussell King dumb_ctrl = dcrtc->cfg_dumb_ctrl;
10096f60e37SRussell King
101a0f75d24SRussell King if (enable)
10296f60e37SRussell King dumb_ctrl |= CFG_DUMB_ENA;
10396f60e37SRussell King
10496f60e37SRussell King /*
10596f60e37SRussell King * When the dumb interface isn't in DUMB24_RGB888_0 mode, it might
10696f60e37SRussell King * be using SPI or GPIO. If we set this to DUMB_BLANK, we will
10796f60e37SRussell King * force LCD_D[23:0] to output blank color, overriding the GPIO or
10896f60e37SRussell King * SPI usage. So leave it as-is unless in DUMB24_RGB888_0 mode.
10996f60e37SRussell King */
110a0f75d24SRussell King if (!enable && (dumb_ctrl & DUMB_MASK) == DUMB24_RGB888_0) {
11196f60e37SRussell King dumb_ctrl &= ~DUMB_MASK;
11296f60e37SRussell King dumb_ctrl |= DUMB_BLANK;
11396f60e37SRussell King }
11496f60e37SRussell King
115155b8290SRussell King armada_updatel(dumb_ctrl,
116155b8290SRussell King ~(CFG_INV_CSYNC | CFG_INV_HSYNC | CFG_INV_VSYNC),
117155b8290SRussell King dcrtc->base + LCD_SPU_DUMB_CTRL);
11896f60e37SRussell King }
11996f60e37SRussell King
armada_drm_crtc_queue_state_event(struct drm_crtc * crtc)120dbb4ca8aSRussell King static void armada_drm_crtc_queue_state_event(struct drm_crtc *crtc)
121dbb4ca8aSRussell King {
122dbb4ca8aSRussell King struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
123dbb4ca8aSRussell King struct drm_pending_vblank_event *event;
124dbb4ca8aSRussell King
125dbb4ca8aSRussell King /* If we have an event, we need vblank events enabled */
126dbb4ca8aSRussell King event = xchg(&crtc->state->event, NULL);
127dbb4ca8aSRussell King if (event) {
128dbb4ca8aSRussell King WARN_ON(drm_crtc_vblank_get(crtc) != 0);
129dbb4ca8aSRussell King dcrtc->event = event;
130dbb4ca8aSRussell King }
131dbb4ca8aSRussell King }
132dbb4ca8aSRussell King
armada_drm_update_gamma(struct drm_crtc * crtc)133d0d765deSRussell King static void armada_drm_update_gamma(struct drm_crtc *crtc)
134d0d765deSRussell King {
135d0d765deSRussell King struct drm_property_blob *blob = crtc->state->gamma_lut;
136d0d765deSRussell King void __iomem *base = drm_to_armada_crtc(crtc)->base;
137d0d765deSRussell King int i;
138d0d765deSRussell King
139d0d765deSRussell King if (blob) {
140d0d765deSRussell King struct drm_color_lut *lut = blob->data;
141d0d765deSRussell King
142d0d765deSRussell King armada_updatel(CFG_CSB_256x8, CFG_CSB_256x8 | CFG_PDWN256x8,
143d0d765deSRussell King base + LCD_SPU_SRAM_PARA1);
144d0d765deSRussell King
145d0d765deSRussell King for (i = 0; i < 256; i++) {
146d0d765deSRussell King writel_relaxed(drm_color_lut_extract(lut[i].red, 8),
147d0d765deSRussell King base + LCD_SPU_SRAM_WRDAT);
148d0d765deSRussell King writel_relaxed(i | SRAM_WRITE | SRAM_GAMMA_YR,
149d0d765deSRussell King base + LCD_SPU_SRAM_CTRL);
150d0d765deSRussell King readl_relaxed(base + LCD_SPU_HWC_OVSA_HPXL_VLN);
151d0d765deSRussell King writel_relaxed(drm_color_lut_extract(lut[i].green, 8),
152d0d765deSRussell King base + LCD_SPU_SRAM_WRDAT);
153d0d765deSRussell King writel_relaxed(i | SRAM_WRITE | SRAM_GAMMA_UG,
154d0d765deSRussell King base + LCD_SPU_SRAM_CTRL);
155d0d765deSRussell King readl_relaxed(base + LCD_SPU_HWC_OVSA_HPXL_VLN);
156d0d765deSRussell King writel_relaxed(drm_color_lut_extract(lut[i].blue, 8),
157d0d765deSRussell King base + LCD_SPU_SRAM_WRDAT);
158d0d765deSRussell King writel_relaxed(i | SRAM_WRITE | SRAM_GAMMA_VB,
159d0d765deSRussell King base + LCD_SPU_SRAM_CTRL);
160d0d765deSRussell King readl_relaxed(base + LCD_SPU_HWC_OVSA_HPXL_VLN);
161d0d765deSRussell King }
162d0d765deSRussell King armada_updatel(CFG_GAMMA_ENA, CFG_GAMMA_ENA,
163d0d765deSRussell King base + LCD_SPU_DMA_CTRL0);
164d0d765deSRussell King } else {
165d0d765deSRussell King armada_updatel(0, CFG_GAMMA_ENA, base + LCD_SPU_DMA_CTRL0);
166d0d765deSRussell King armada_updatel(CFG_PDWN256x8, CFG_CSB_256x8 | CFG_PDWN256x8,
167d0d765deSRussell King base + LCD_SPU_SRAM_PARA1);
168d0d765deSRussell King }
169d0d765deSRussell King }
170d0d765deSRussell King
armada_drm_crtc_mode_valid(struct drm_crtc * crtc,const struct drm_display_mode * mode)1717f07ce0fSRussell King static enum drm_mode_status armada_drm_crtc_mode_valid(struct drm_crtc *crtc,
1727f07ce0fSRussell King const struct drm_display_mode *mode)
1737f07ce0fSRussell King {
174d880fa66SRussell King struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
175d880fa66SRussell King
1767f07ce0fSRussell King if (mode->vscan > 1)
1777f07ce0fSRussell King return MODE_NO_VSCAN;
1787f07ce0fSRussell King
1797f07ce0fSRussell King if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
1807f07ce0fSRussell King return MODE_NO_DBLESCAN;
1817f07ce0fSRussell King
1827f07ce0fSRussell King if (mode->flags & DRM_MODE_FLAG_HSKEW)
1837f07ce0fSRussell King return MODE_H_ILLEGAL;
1847f07ce0fSRussell King
185d880fa66SRussell King /* We can't do interlaced modes if we don't have the SPU_ADV_REG */
186d880fa66SRussell King if (!dcrtc->variant->has_spu_adv_reg &&
187d880fa66SRussell King mode->flags & DRM_MODE_FLAG_INTERLACE)
188d880fa66SRussell King return MODE_NO_INTERLACE;
189d880fa66SRussell King
1907f07ce0fSRussell King if (mode->flags & (DRM_MODE_FLAG_BCAST | DRM_MODE_FLAG_PIXMUX |
1917f07ce0fSRussell King DRM_MODE_FLAG_CLKDIV2))
1927f07ce0fSRussell King return MODE_BAD;
1937f07ce0fSRussell King
1947f07ce0fSRussell King return MODE_OK;
1957f07ce0fSRussell King }
1967f07ce0fSRussell King
19796f60e37SRussell King /* The mode_config.mutex will be held for this call */
armada_drm_crtc_mode_fixup(struct drm_crtc * crtc,const struct drm_display_mode * mode,struct drm_display_mode * adj)19896f60e37SRussell King static bool armada_drm_crtc_mode_fixup(struct drm_crtc *crtc,
19996f60e37SRussell King const struct drm_display_mode *mode, struct drm_display_mode *adj)
20096f60e37SRussell King {
20196f60e37SRussell King struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
20296f60e37SRussell King int ret;
20396f60e37SRussell King
204f79d7c95SRussell King /*
205f79d7c95SRussell King * Set CRTC modesetting parameters for the adjusted mode. This is
206f79d7c95SRussell King * applied after the connectors, bridges, and encoders have fixed up
207f79d7c95SRussell King * this mode, as described above drm_atomic_helper_check_modeset().
208f79d7c95SRussell King */
209f79d7c95SRussell King drm_mode_set_crtcinfo(adj, CRTC_INTERLACE_HALVE_V);
210f79d7c95SRussell King
211d880fa66SRussell King /*
212d880fa66SRussell King * Validate the adjusted mode in case an encoder/bridge has set
213d880fa66SRussell King * something we don't support.
214d880fa66SRussell King */
215d880fa66SRussell King if (armada_drm_crtc_mode_valid(crtc, adj) != MODE_OK)
21696f60e37SRussell King return false;
21796f60e37SRussell King
21896f60e37SRussell King /* Check whether the display mode is possible */
21942e62ba7SRussell King ret = dcrtc->variant->compute_clock(dcrtc, adj, NULL);
22096f60e37SRussell King if (ret)
22196f60e37SRussell King return false;
22296f60e37SRussell King
22396f60e37SRussell King return true;
22496f60e37SRussell King }
22596f60e37SRussell King
2265922a7d0SShawn Guo /* These are locked by dev->vbl_lock */
armada_drm_crtc_disable_irq(struct armada_crtc * dcrtc,u32 mask)2275922a7d0SShawn Guo static void armada_drm_crtc_disable_irq(struct armada_crtc *dcrtc, u32 mask)
2285922a7d0SShawn Guo {
2295922a7d0SShawn Guo if (dcrtc->irq_ena & mask) {
2305922a7d0SShawn Guo dcrtc->irq_ena &= ~mask;
2315922a7d0SShawn Guo writel(dcrtc->irq_ena, dcrtc->base + LCD_SPU_IRQ_ENA);
2325922a7d0SShawn Guo }
2335922a7d0SShawn Guo }
2345922a7d0SShawn Guo
armada_drm_crtc_enable_irq(struct armada_crtc * dcrtc,u32 mask)2355922a7d0SShawn Guo static void armada_drm_crtc_enable_irq(struct armada_crtc *dcrtc, u32 mask)
2365922a7d0SShawn Guo {
2375922a7d0SShawn Guo if ((dcrtc->irq_ena & mask) != mask) {
2385922a7d0SShawn Guo dcrtc->irq_ena |= mask;
2395922a7d0SShawn Guo writel(dcrtc->irq_ena, dcrtc->base + LCD_SPU_IRQ_ENA);
2405922a7d0SShawn Guo if (readl_relaxed(dcrtc->base + LCD_SPU_IRQ_ISR) & mask)
2415922a7d0SShawn Guo writel(0, dcrtc->base + LCD_SPU_IRQ_ISR);
2425922a7d0SShawn Guo }
2435922a7d0SShawn Guo }
2445922a7d0SShawn Guo
armada_drm_crtc_irq(struct armada_crtc * dcrtc,u32 stat)245e5d9ddfbSRussell King static void armada_drm_crtc_irq(struct armada_crtc *dcrtc, u32 stat)
24696f60e37SRussell King {
247dbb4ca8aSRussell King struct drm_pending_vblank_event *event;
24896f60e37SRussell King void __iomem *base = dcrtc->base;
24996f60e37SRussell King
25096f60e37SRussell King if (stat & DMA_FF_UNDERFLOW)
25196f60e37SRussell King DRM_ERROR("video underflow on crtc %u\n", dcrtc->num);
25296f60e37SRussell King if (stat & GRA_FF_UNDERFLOW)
25396f60e37SRussell King DRM_ERROR("graphics underflow on crtc %u\n", dcrtc->num);
25496f60e37SRussell King
25596f60e37SRussell King if (stat & VSYNC_IRQ)
2560ac28c57SGustavo Padovan drm_crtc_handle_vblank(&dcrtc->crtc);
25796f60e37SRussell King
258a3f6a18fSRussell King spin_lock(&dcrtc->irq_lock);
25996f60e37SRussell King if (stat & GRA_FRAME_IRQ && dcrtc->interlaced) {
26096f60e37SRussell King int i = stat & GRA_FRAME_IRQ0 ? 0 : 1;
26196f60e37SRussell King uint32_t val;
26296f60e37SRussell King
26396f60e37SRussell King writel_relaxed(dcrtc->v[i].spu_v_porch, base + LCD_SPU_V_PORCH);
26496f60e37SRussell King writel_relaxed(dcrtc->v[i].spu_v_h_total,
26596f60e37SRussell King base + LCD_SPUT_V_H_TOTAL);
26696f60e37SRussell King
26796f60e37SRussell King val = readl_relaxed(base + LCD_SPU_ADV_REG);
26896f60e37SRussell King val &= ~(ADV_VSYNC_L_OFF | ADV_VSYNC_H_OFF | ADV_VSYNCOFFEN);
26996f60e37SRussell King val |= dcrtc->v[i].spu_adv_reg;
270662af0d8SRussell King writel_relaxed(val, base + LCD_SPU_ADV_REG);
27196f60e37SRussell King }
272662af0d8SRussell King
2733cb13ac9SRussell King if (stat & dcrtc->irq_ena & DUMB_FRAMEDONE) {
2743cb13ac9SRussell King if (dcrtc->update_pending) {
2753cb13ac9SRussell King armada_drm_crtc_update_regs(dcrtc, dcrtc->regs);
2763cb13ac9SRussell King dcrtc->update_pending = false;
2773cb13ac9SRussell King }
2783cb13ac9SRussell King if (dcrtc->cursor_update) {
279662af0d8SRussell King writel_relaxed(dcrtc->cursor_hw_pos,
280662af0d8SRussell King base + LCD_SPU_HWC_OVSA_HPXL_VLN);
281662af0d8SRussell King writel_relaxed(dcrtc->cursor_hw_sz,
282662af0d8SRussell King base + LCD_SPU_HWC_HPXL_VLN);
283662af0d8SRussell King armada_updatel(CFG_HWC_ENA,
2843cb13ac9SRussell King CFG_HWC_ENA | CFG_HWC_1BITMOD |
2853cb13ac9SRussell King CFG_HWC_1BITENA,
286662af0d8SRussell King base + LCD_SPU_DMA_CTRL0);
287662af0d8SRussell King dcrtc->cursor_update = false;
2883cb13ac9SRussell King }
289662af0d8SRussell King armada_drm_crtc_disable_irq(dcrtc, DUMB_FRAMEDONE_ENA);
290662af0d8SRussell King }
29196f60e37SRussell King spin_unlock(&dcrtc->irq_lock);
29296f60e37SRussell King
2933cb13ac9SRussell King if (stat & VSYNC_IRQ && !dcrtc->update_pending) {
294dbb4ca8aSRussell King event = xchg(&dcrtc->event, NULL);
295dbb4ca8aSRussell King if (event) {
296dbb4ca8aSRussell King spin_lock(&dcrtc->crtc.dev->event_lock);
297dbb4ca8aSRussell King drm_crtc_send_vblank_event(&dcrtc->crtc, event);
298dbb4ca8aSRussell King spin_unlock(&dcrtc->crtc.dev->event_lock);
299dbb4ca8aSRussell King drm_crtc_vblank_put(&dcrtc->crtc);
300dbb4ca8aSRussell King }
301dbb4ca8aSRussell King }
30296f60e37SRussell King }
30396f60e37SRussell King
armada_drm_irq(int irq,void * arg)304e5d9ddfbSRussell King static irqreturn_t armada_drm_irq(int irq, void *arg)
305e5d9ddfbSRussell King {
306e5d9ddfbSRussell King struct armada_crtc *dcrtc = arg;
307e5d9ddfbSRussell King u32 v, stat = readl_relaxed(dcrtc->base + LCD_SPU_IRQ_ISR);
308e5d9ddfbSRussell King
309e5d9ddfbSRussell King /*
31092298c1cSRussell King * Reading the ISR appears to clear bits provided CLEAN_SPU_IRQ_ISR
31192298c1cSRussell King * is set. Writing has some other effect to acknowledge the IRQ -
31292298c1cSRussell King * without this, we only get a single IRQ.
313e5d9ddfbSRussell King */
314e5d9ddfbSRussell King writel_relaxed(0, dcrtc->base + LCD_SPU_IRQ_ISR);
315e5d9ddfbSRussell King
316c8a220c6SRussell King trace_armada_drm_irq(&dcrtc->crtc, stat);
317c8a220c6SRussell King
318e5d9ddfbSRussell King /* Mask out those interrupts we haven't enabled */
319e5d9ddfbSRussell King v = stat & dcrtc->irq_ena;
320e5d9ddfbSRussell King
321e5d9ddfbSRussell King if (v & (VSYNC_IRQ|GRA_FRAME_IRQ|DUMB_FRAMEDONE)) {
322e5d9ddfbSRussell King armada_drm_crtc_irq(dcrtc, stat);
323e5d9ddfbSRussell King return IRQ_HANDLED;
324e5d9ddfbSRussell King }
325e5d9ddfbSRussell King return IRQ_NONE;
326e5d9ddfbSRussell King }
327e5d9ddfbSRussell King
32896f60e37SRussell King /* The mode_config.mutex will be held for this call */
armada_drm_crtc_mode_set_nofb(struct drm_crtc * crtc)329c36045e1SRussell King static void armada_drm_crtc_mode_set_nofb(struct drm_crtc *crtc)
33096f60e37SRussell King {
331c36045e1SRussell King struct drm_display_mode *adj = &crtc->state->adjusted_mode;
33296f60e37SRussell King struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
33396f60e37SRussell King struct armada_regs regs[17];
33496f60e37SRussell King uint32_t lm, rm, tm, bm, val, sclk;
33596f60e37SRussell King unsigned long flags;
33696f60e37SRussell King unsigned i;
337c36045e1SRussell King bool interlaced = !!(adj->flags & DRM_MODE_FLAG_INTERLACE);
33896f60e37SRussell King
33937af35c7SRussell King i = 0;
34096f60e37SRussell King rm = adj->crtc_hsync_start - adj->crtc_hdisplay;
34196f60e37SRussell King lm = adj->crtc_htotal - adj->crtc_hsync_end;
34296f60e37SRussell King bm = adj->crtc_vsync_start - adj->crtc_vdisplay;
34396f60e37SRussell King tm = adj->crtc_vtotal - adj->crtc_vsync_end;
34496f60e37SRussell King
345a61c3922SRussell King DRM_DEBUG_KMS("[CRTC:%d:%s] mode " DRM_MODE_FMT "\n",
3460ed833baSShayenne Moura crtc->base.id, crtc->name, DRM_MODE_ARG(adj));
347a61c3922SRussell King DRM_DEBUG_KMS("lm %d rm %d tm %d bm %d\n", lm, rm, tm, bm);
34896f60e37SRussell King
34996f60e37SRussell King /* Now compute the divider for real */
35042e62ba7SRussell King dcrtc->variant->compute_clock(dcrtc, adj, &sclk);
35196f60e37SRussell King
35296f60e37SRussell King armada_reg_queue_set(regs, i, sclk, LCD_CFG_SCLK_DIV);
35396f60e37SRussell King
35496f60e37SRussell King spin_lock_irqsave(&dcrtc->irq_lock, flags);
35596f60e37SRussell King
356768f719aSRussell King dcrtc->interlaced = interlaced;
35796f60e37SRussell King /* Even interlaced/progressive frame */
35896f60e37SRussell King dcrtc->v[1].spu_v_h_total = adj->crtc_vtotal << 16 |
35996f60e37SRussell King adj->crtc_htotal;
36096f60e37SRussell King dcrtc->v[1].spu_v_porch = tm << 16 | bm;
36196f60e37SRussell King val = adj->crtc_hsync_start;
3624e4b3563SRussell King dcrtc->v[1].spu_adv_reg = val << 20 | val | ADV_VSYNCOFFEN;
36396f60e37SRussell King
36496f60e37SRussell King if (interlaced) {
36596f60e37SRussell King /* Odd interlaced frame */
3664e4b3563SRussell King val -= adj->crtc_htotal / 2;
3674e4b3563SRussell King dcrtc->v[0].spu_adv_reg = val << 20 | val | ADV_VSYNCOFFEN;
36896f60e37SRussell King dcrtc->v[0].spu_v_h_total = dcrtc->v[1].spu_v_h_total +
36996f60e37SRussell King (1 << 16);
37096f60e37SRussell King dcrtc->v[0].spu_v_porch = dcrtc->v[1].spu_v_porch + 1;
37196f60e37SRussell King } else {
37296f60e37SRussell King dcrtc->v[0] = dcrtc->v[1];
37396f60e37SRussell King }
37496f60e37SRussell King
37596f60e37SRussell King val = adj->crtc_vdisplay << 16 | adj->crtc_hdisplay;
37696f60e37SRussell King
37796f60e37SRussell King armada_reg_queue_set(regs, i, val, LCD_SPU_V_H_ACTIVE);
37896f60e37SRussell King armada_reg_queue_set(regs, i, (lm << 16) | rm, LCD_SPU_H_PORCH);
37996f60e37SRussell King armada_reg_queue_set(regs, i, dcrtc->v[0].spu_v_porch, LCD_SPU_V_PORCH);
38096f60e37SRussell King armada_reg_queue_set(regs, i, dcrtc->v[0].spu_v_h_total,
38196f60e37SRussell King LCD_SPUT_V_H_TOTAL);
38296f60e37SRussell King
3834e4b3563SRussell King if (dcrtc->variant->has_spu_adv_reg)
38496f60e37SRussell King armada_reg_queue_mod(regs, i, dcrtc->v[0].spu_adv_reg,
38596f60e37SRussell King ADV_VSYNC_L_OFF | ADV_VSYNC_H_OFF |
38696f60e37SRussell King ADV_VSYNCOFFEN, LCD_SPU_ADV_REG);
38796f60e37SRussell King
38896f60e37SRussell King val = adj->flags & DRM_MODE_FLAG_NVSYNC ? CFG_VSYNC_INV : 0;
38996f60e37SRussell King armada_reg_queue_mod(regs, i, val, CFG_VSYNC_INV, LCD_SPU_DMA_CTRL1);
390155b8290SRussell King
391155b8290SRussell King /*
392155b8290SRussell King * The documentation doesn't indicate what the normal state of
393155b8290SRussell King * the sync signals are. Sebastian Hesselbart kindly probed
394155b8290SRussell King * these signals on his board to determine their state.
395155b8290SRussell King *
396155b8290SRussell King * The non-inverted state of the sync signals is active high.
397155b8290SRussell King * Setting these bits makes the appropriate signal active low.
398155b8290SRussell King */
399155b8290SRussell King val = 0;
400155b8290SRussell King if (adj->flags & DRM_MODE_FLAG_NCSYNC)
401155b8290SRussell King val |= CFG_INV_CSYNC;
402155b8290SRussell King if (adj->flags & DRM_MODE_FLAG_NHSYNC)
403155b8290SRussell King val |= CFG_INV_HSYNC;
404155b8290SRussell King if (adj->flags & DRM_MODE_FLAG_NVSYNC)
405155b8290SRussell King val |= CFG_INV_VSYNC;
406155b8290SRussell King armada_reg_queue_mod(regs, i, val, CFG_INV_CSYNC | CFG_INV_HSYNC |
407155b8290SRussell King CFG_INV_VSYNC, LCD_SPU_DUMB_CTRL);
40896f60e37SRussell King armada_reg_queue_end(regs, i);
40996f60e37SRussell King
41096f60e37SRussell King armada_drm_crtc_update_regs(dcrtc, regs);
41196f60e37SRussell King spin_unlock_irqrestore(&dcrtc->irq_lock, flags);
41296f60e37SRussell King }
41396f60e37SRussell King
armada_drm_crtc_atomic_check(struct drm_crtc * crtc,struct drm_atomic_state * state)414d0d765deSRussell King static int armada_drm_crtc_atomic_check(struct drm_crtc *crtc,
41529b77ad7SMaxime Ripard struct drm_atomic_state *state)
416d0d765deSRussell King {
41729b77ad7SMaxime Ripard struct drm_crtc_state *crtc_state = drm_atomic_get_new_crtc_state(state,
41829b77ad7SMaxime Ripard crtc);
419d0d765deSRussell King DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
420d0d765deSRussell King
42129b77ad7SMaxime Ripard if (crtc_state->gamma_lut && drm_color_lut_size(crtc_state->gamma_lut) != 256)
422d0d765deSRussell King return -EINVAL;
423d0d765deSRussell King
42429b77ad7SMaxime Ripard if (crtc_state->color_mgmt_changed)
42529b77ad7SMaxime Ripard crtc_state->planes_changed = true;
426d0d765deSRussell King
427d0d765deSRussell King return 0;
428d0d765deSRussell King }
429d0d765deSRussell King
armada_drm_crtc_atomic_begin(struct drm_crtc * crtc,struct drm_atomic_state * state)430c36045e1SRussell King static void armada_drm_crtc_atomic_begin(struct drm_crtc *crtc,
431f6ebe9f9SMaxime Ripard struct drm_atomic_state *state)
432c36045e1SRussell King {
433*253f28b6SMaxime Ripard struct drm_crtc_state *crtc_state = drm_atomic_get_new_crtc_state(state,
434*253f28b6SMaxime Ripard crtc);
435c36045e1SRussell King struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
436c36045e1SRussell King
437c36045e1SRussell King DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
438c36045e1SRussell King
439*253f28b6SMaxime Ripard if (crtc_state->color_mgmt_changed)
440d0d765deSRussell King armada_drm_update_gamma(crtc);
441d0d765deSRussell King
442c36045e1SRussell King dcrtc->regs_idx = 0;
443c36045e1SRussell King dcrtc->regs = dcrtc->atomic_regs;
444c36045e1SRussell King }
445c36045e1SRussell King
armada_drm_crtc_atomic_flush(struct drm_crtc * crtc,struct drm_atomic_state * state)446c36045e1SRussell King static void armada_drm_crtc_atomic_flush(struct drm_crtc *crtc,
447f6ebe9f9SMaxime Ripard struct drm_atomic_state *state)
448c36045e1SRussell King {
449*253f28b6SMaxime Ripard struct drm_crtc_state *crtc_state = drm_atomic_get_new_crtc_state(state,
450*253f28b6SMaxime Ripard crtc);
451c36045e1SRussell King struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
452c36045e1SRussell King
453c36045e1SRussell King DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
454c36045e1SRussell King
455c36045e1SRussell King armada_reg_queue_end(dcrtc->regs, dcrtc->regs_idx);
456c36045e1SRussell King
457dbb4ca8aSRussell King /*
458dbb4ca8aSRussell King * If we aren't doing a full modeset, then we need to queue
459dbb4ca8aSRussell King * the event here.
460dbb4ca8aSRussell King */
461*253f28b6SMaxime Ripard if (!drm_atomic_crtc_needs_modeset(crtc_state)) {
4623cb13ac9SRussell King dcrtc->update_pending = true;
463dbb4ca8aSRussell King armada_drm_crtc_queue_state_event(crtc);
4643cb13ac9SRussell King spin_lock_irq(&dcrtc->irq_lock);
4653cb13ac9SRussell King armada_drm_crtc_enable_irq(dcrtc, DUMB_FRAMEDONE_ENA);
4663cb13ac9SRussell King spin_unlock_irq(&dcrtc->irq_lock);
4673cb13ac9SRussell King } else {
4683cb13ac9SRussell King spin_lock_irq(&dcrtc->irq_lock);
4693cb13ac9SRussell King armada_drm_crtc_update_regs(dcrtc, dcrtc->regs);
4703cb13ac9SRussell King spin_unlock_irq(&dcrtc->irq_lock);
4713cb13ac9SRussell King }
472c36045e1SRussell King }
473c36045e1SRussell King
armada_drm_crtc_atomic_disable(struct drm_crtc * crtc,struct drm_atomic_state * state)47434e25ed6SRussell King static void armada_drm_crtc_atomic_disable(struct drm_crtc *crtc,
475351f950dSMaxime Ripard struct drm_atomic_state *state)
47634e25ed6SRussell King {
477351f950dSMaxime Ripard struct drm_crtc_state *old_state = drm_atomic_get_old_crtc_state(state,
478351f950dSMaxime Ripard crtc);
47934e25ed6SRussell King struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
48034e25ed6SRussell King struct drm_pending_vblank_event *event;
48134e25ed6SRussell King
48234e25ed6SRussell King DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
48334e25ed6SRussell King
484768f719aSRussell King if (old_state->adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
485768f719aSRussell King drm_crtc_vblank_put(crtc);
486768f719aSRussell King
48734e25ed6SRussell King drm_crtc_vblank_off(crtc);
48834e25ed6SRussell King armada_drm_crtc_update(dcrtc, false);
48934e25ed6SRussell King
49034e25ed6SRussell King if (!crtc->state->active) {
49134e25ed6SRussell King /*
49234e25ed6SRussell King * This modeset will be leaving the CRTC disabled, so
49334e25ed6SRussell King * call the backend to disable upstream clocks etc.
49434e25ed6SRussell King */
49534e25ed6SRussell King if (dcrtc->variant->disable)
49634e25ed6SRussell King dcrtc->variant->disable(dcrtc);
49734e25ed6SRussell King
49834e25ed6SRussell King /*
49934e25ed6SRussell King * We will not receive any further vblank events.
50034e25ed6SRussell King * Send the flip_done event manually.
50134e25ed6SRussell King */
50234e25ed6SRussell King event = crtc->state->event;
50334e25ed6SRussell King crtc->state->event = NULL;
50434e25ed6SRussell King if (event) {
50534e25ed6SRussell King spin_lock_irq(&crtc->dev->event_lock);
50634e25ed6SRussell King drm_crtc_send_vblank_event(crtc, event);
50734e25ed6SRussell King spin_unlock_irq(&crtc->dev->event_lock);
50834e25ed6SRussell King }
50934e25ed6SRussell King }
51034e25ed6SRussell King }
51134e25ed6SRussell King
armada_drm_crtc_atomic_enable(struct drm_crtc * crtc,struct drm_atomic_state * state)51234e25ed6SRussell King static void armada_drm_crtc_atomic_enable(struct drm_crtc *crtc,
513351f950dSMaxime Ripard struct drm_atomic_state *state)
51434e25ed6SRussell King {
515351f950dSMaxime Ripard struct drm_crtc_state *old_state = drm_atomic_get_old_crtc_state(state,
516351f950dSMaxime Ripard crtc);
51734e25ed6SRussell King struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
51834e25ed6SRussell King
51934e25ed6SRussell King DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
52034e25ed6SRussell King
52134e25ed6SRussell King if (!old_state->active) {
52234e25ed6SRussell King /*
52334e25ed6SRussell King * This modeset is enabling the CRTC after it having
52434e25ed6SRussell King * been disabled. Reverse the call to ->disable in
52534e25ed6SRussell King * the atomic_disable().
52634e25ed6SRussell King */
52734e25ed6SRussell King if (dcrtc->variant->enable)
52834e25ed6SRussell King dcrtc->variant->enable(dcrtc, &crtc->state->adjusted_mode);
52934e25ed6SRussell King }
53034e25ed6SRussell King armada_drm_crtc_update(dcrtc, true);
53134e25ed6SRussell King drm_crtc_vblank_on(crtc);
53234e25ed6SRussell King
533768f719aSRussell King if (crtc->state->adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
534768f719aSRussell King WARN_ON(drm_crtc_vblank_get(crtc));
535768f719aSRussell King
53634e25ed6SRussell King armada_drm_crtc_queue_state_event(crtc);
53734e25ed6SRussell King }
53834e25ed6SRussell King
53996f60e37SRussell King static const struct drm_crtc_helper_funcs armada_crtc_helper_funcs = {
5407f07ce0fSRussell King .mode_valid = armada_drm_crtc_mode_valid,
54196f60e37SRussell King .mode_fixup = armada_drm_crtc_mode_fixup,
542c36045e1SRussell King .mode_set_nofb = armada_drm_crtc_mode_set_nofb,
543d0d765deSRussell King .atomic_check = armada_drm_crtc_atomic_check,
544c36045e1SRussell King .atomic_begin = armada_drm_crtc_atomic_begin,
545c36045e1SRussell King .atomic_flush = armada_drm_crtc_atomic_flush,
54634e25ed6SRussell King .atomic_disable = armada_drm_crtc_atomic_disable,
54734e25ed6SRussell King .atomic_enable = armada_drm_crtc_atomic_enable,
54896f60e37SRussell King };
54996f60e37SRussell King
armada_load_cursor_argb(void __iomem * base,uint32_t * pix,unsigned stride,unsigned width,unsigned height)550662af0d8SRussell King static void armada_load_cursor_argb(void __iomem *base, uint32_t *pix,
551662af0d8SRussell King unsigned stride, unsigned width, unsigned height)
552662af0d8SRussell King {
553662af0d8SRussell King uint32_t addr;
554662af0d8SRussell King unsigned y;
555662af0d8SRussell King
556662af0d8SRussell King addr = SRAM_HWC32_RAM1;
557662af0d8SRussell King for (y = 0; y < height; y++) {
558662af0d8SRussell King uint32_t *p = &pix[y * stride];
559662af0d8SRussell King unsigned x;
560662af0d8SRussell King
561662af0d8SRussell King for (x = 0; x < width; x++, p++) {
562662af0d8SRussell King uint32_t val = *p;
563662af0d8SRussell King
5645d32b660SRussell King /*
5655d32b660SRussell King * In "ARGB888" (HWC32) mode, writing to the SRAM
5665d32b660SRussell King * requires these bits to contain:
5675d32b660SRussell King * 31:24 = alpha 23:16 = blue 15:8 = green 7:0 = red
5685d32b660SRussell King * So, it's actually ABGR8888. This is independent
5695d32b660SRussell King * of the SWAPRB bits in DMA control register 0.
5705d32b660SRussell King */
571662af0d8SRussell King val = (val & 0xff00ff00) |
572662af0d8SRussell King (val & 0x000000ff) << 16 |
573662af0d8SRussell King (val & 0x00ff0000) >> 16;
574662af0d8SRussell King
575662af0d8SRussell King writel_relaxed(val,
576662af0d8SRussell King base + LCD_SPU_SRAM_WRDAT);
577662af0d8SRussell King writel_relaxed(addr | SRAM_WRITE,
578662af0d8SRussell King base + LCD_SPU_SRAM_CTRL);
579c39b0695SRussell King readl_relaxed(base + LCD_SPU_HWC_OVSA_HPXL_VLN);
580662af0d8SRussell King addr += 1;
581662af0d8SRussell King if ((addr & 0x00ff) == 0)
582662af0d8SRussell King addr += 0xf00;
583662af0d8SRussell King if ((addr & 0x30ff) == 0)
584662af0d8SRussell King addr = SRAM_HWC32_RAM2;
585662af0d8SRussell King }
586662af0d8SRussell King }
587662af0d8SRussell King }
588662af0d8SRussell King
armada_drm_crtc_cursor_tran(void __iomem * base)589662af0d8SRussell King static void armada_drm_crtc_cursor_tran(void __iomem *base)
590662af0d8SRussell King {
591662af0d8SRussell King unsigned addr;
592662af0d8SRussell King
593662af0d8SRussell King for (addr = 0; addr < 256; addr++) {
594662af0d8SRussell King /* write the default value */
595662af0d8SRussell King writel_relaxed(0x55555555, base + LCD_SPU_SRAM_WRDAT);
596662af0d8SRussell King writel_relaxed(addr | SRAM_WRITE | SRAM_HWC32_TRAN,
597662af0d8SRussell King base + LCD_SPU_SRAM_CTRL);
598662af0d8SRussell King }
599662af0d8SRussell King }
600662af0d8SRussell King
armada_drm_crtc_cursor_update(struct armada_crtc * dcrtc,bool reload)601662af0d8SRussell King static int armada_drm_crtc_cursor_update(struct armada_crtc *dcrtc, bool reload)
602662af0d8SRussell King {
603662af0d8SRussell King uint32_t xoff, xscr, w = dcrtc->cursor_w, s;
604662af0d8SRussell King uint32_t yoff, yscr, h = dcrtc->cursor_h;
605662af0d8SRussell King uint32_t para1;
606662af0d8SRussell King
607662af0d8SRussell King /*
608662af0d8SRussell King * Calculate the visible width and height of the cursor,
609662af0d8SRussell King * screen position, and the position in the cursor bitmap.
610662af0d8SRussell King */
611662af0d8SRussell King if (dcrtc->cursor_x < 0) {
612662af0d8SRussell King xoff = -dcrtc->cursor_x;
613662af0d8SRussell King xscr = 0;
614662af0d8SRussell King w -= min(xoff, w);
615662af0d8SRussell King } else if (dcrtc->cursor_x + w > dcrtc->crtc.mode.hdisplay) {
616662af0d8SRussell King xoff = 0;
617662af0d8SRussell King xscr = dcrtc->cursor_x;
618662af0d8SRussell King w = max_t(int, dcrtc->crtc.mode.hdisplay - dcrtc->cursor_x, 0);
619662af0d8SRussell King } else {
620662af0d8SRussell King xoff = 0;
621662af0d8SRussell King xscr = dcrtc->cursor_x;
622662af0d8SRussell King }
623662af0d8SRussell King
624662af0d8SRussell King if (dcrtc->cursor_y < 0) {
625662af0d8SRussell King yoff = -dcrtc->cursor_y;
626662af0d8SRussell King yscr = 0;
627662af0d8SRussell King h -= min(yoff, h);
628662af0d8SRussell King } else if (dcrtc->cursor_y + h > dcrtc->crtc.mode.vdisplay) {
629662af0d8SRussell King yoff = 0;
630662af0d8SRussell King yscr = dcrtc->cursor_y;
631662af0d8SRussell King h = max_t(int, dcrtc->crtc.mode.vdisplay - dcrtc->cursor_y, 0);
632662af0d8SRussell King } else {
633662af0d8SRussell King yoff = 0;
634662af0d8SRussell King yscr = dcrtc->cursor_y;
635662af0d8SRussell King }
636662af0d8SRussell King
637662af0d8SRussell King /* On interlaced modes, the vertical cursor size must be halved */
638662af0d8SRussell King s = dcrtc->cursor_w;
639662af0d8SRussell King if (dcrtc->interlaced) {
640662af0d8SRussell King s *= 2;
641662af0d8SRussell King yscr /= 2;
642662af0d8SRussell King h /= 2;
643662af0d8SRussell King }
644662af0d8SRussell King
645662af0d8SRussell King if (!dcrtc->cursor_obj || !h || !w) {
646662af0d8SRussell King spin_lock_irq(&dcrtc->irq_lock);
647662af0d8SRussell King dcrtc->cursor_update = false;
648662af0d8SRussell King armada_updatel(0, CFG_HWC_ENA, dcrtc->base + LCD_SPU_DMA_CTRL0);
649662af0d8SRussell King spin_unlock_irq(&dcrtc->irq_lock);
650662af0d8SRussell King return 0;
651662af0d8SRussell King }
652662af0d8SRussell King
653214612f9SRussell King spin_lock_irq(&dcrtc->irq_lock);
654662af0d8SRussell King para1 = readl_relaxed(dcrtc->base + LCD_SPU_SRAM_PARA1);
655662af0d8SRussell King armada_updatel(CFG_CSB_256x32, CFG_CSB_256x32 | CFG_PDWN256x32,
656662af0d8SRussell King dcrtc->base + LCD_SPU_SRAM_PARA1);
657214612f9SRussell King spin_unlock_irq(&dcrtc->irq_lock);
658662af0d8SRussell King
659662af0d8SRussell King /*
660662af0d8SRussell King * Initialize the transparency if the SRAM was powered down.
661662af0d8SRussell King * We must also reload the cursor data as well.
662662af0d8SRussell King */
663662af0d8SRussell King if (!(para1 & CFG_CSB_256x32)) {
664662af0d8SRussell King armada_drm_crtc_cursor_tran(dcrtc->base);
665662af0d8SRussell King reload = true;
666662af0d8SRussell King }
667662af0d8SRussell King
668662af0d8SRussell King if (dcrtc->cursor_hw_sz != (h << 16 | w)) {
669662af0d8SRussell King spin_lock_irq(&dcrtc->irq_lock);
670662af0d8SRussell King dcrtc->cursor_update = false;
671662af0d8SRussell King armada_updatel(0, CFG_HWC_ENA, dcrtc->base + LCD_SPU_DMA_CTRL0);
672662af0d8SRussell King spin_unlock_irq(&dcrtc->irq_lock);
673662af0d8SRussell King reload = true;
674662af0d8SRussell King }
675662af0d8SRussell King if (reload) {
676662af0d8SRussell King struct armada_gem_object *obj = dcrtc->cursor_obj;
677662af0d8SRussell King uint32_t *pix;
678662af0d8SRussell King /* Set the top-left corner of the cursor image */
679662af0d8SRussell King pix = obj->addr;
680662af0d8SRussell King pix += yoff * s + xoff;
681662af0d8SRussell King armada_load_cursor_argb(dcrtc->base, pix, s, w, h);
682662af0d8SRussell King }
683662af0d8SRussell King
684662af0d8SRussell King /* Reload the cursor position, size and enable in the IRQ handler */
685662af0d8SRussell King spin_lock_irq(&dcrtc->irq_lock);
686662af0d8SRussell King dcrtc->cursor_hw_pos = yscr << 16 | xscr;
687662af0d8SRussell King dcrtc->cursor_hw_sz = h << 16 | w;
688662af0d8SRussell King dcrtc->cursor_update = true;
689662af0d8SRussell King armada_drm_crtc_enable_irq(dcrtc, DUMB_FRAMEDONE_ENA);
690662af0d8SRussell King spin_unlock_irq(&dcrtc->irq_lock);
691662af0d8SRussell King
692662af0d8SRussell King return 0;
693662af0d8SRussell King }
694662af0d8SRussell King
cursor_update(void * data)695662af0d8SRussell King static void cursor_update(void *data)
696662af0d8SRussell King {
697662af0d8SRussell King armada_drm_crtc_cursor_update(data, true);
698662af0d8SRussell King }
699662af0d8SRussell King
armada_drm_crtc_cursor_set(struct drm_crtc * crtc,struct drm_file * file,uint32_t handle,uint32_t w,uint32_t h)700662af0d8SRussell King static int armada_drm_crtc_cursor_set(struct drm_crtc *crtc,
701662af0d8SRussell King struct drm_file *file, uint32_t handle, uint32_t w, uint32_t h)
702662af0d8SRussell King {
703662af0d8SRussell King struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
704662af0d8SRussell King struct armada_gem_object *obj = NULL;
705662af0d8SRussell King int ret;
706662af0d8SRussell King
707662af0d8SRussell King /* If no cursor support, replicate drm's return value */
70842e62ba7SRussell King if (!dcrtc->variant->has_spu_adv_reg)
709662af0d8SRussell King return -ENXIO;
710662af0d8SRussell King
711662af0d8SRussell King if (handle && w > 0 && h > 0) {
712662af0d8SRussell King /* maximum size is 64x32 or 32x64 */
713662af0d8SRussell King if (w > 64 || h > 64 || (w > 32 && h > 32))
714662af0d8SRussell King return -ENOMEM;
715662af0d8SRussell King
716a8ad0bd8SChris Wilson obj = armada_gem_object_lookup(file, handle);
717662af0d8SRussell King if (!obj)
718662af0d8SRussell King return -ENOENT;
719662af0d8SRussell King
720662af0d8SRussell King /* Must be a kernel-mapped object */
721662af0d8SRussell King if (!obj->addr) {
722dda156cfSEmil Velikov drm_gem_object_put(&obj->obj);
723662af0d8SRussell King return -EINVAL;
724662af0d8SRussell King }
725662af0d8SRussell King
726662af0d8SRussell King if (obj->obj.size < w * h * 4) {
727662af0d8SRussell King DRM_ERROR("buffer is too small\n");
728dda156cfSEmil Velikov drm_gem_object_put(&obj->obj);
729662af0d8SRussell King return -ENOMEM;
730662af0d8SRussell King }
731662af0d8SRussell King }
732662af0d8SRussell King
733662af0d8SRussell King if (dcrtc->cursor_obj) {
734662af0d8SRussell King dcrtc->cursor_obj->update = NULL;
735662af0d8SRussell King dcrtc->cursor_obj->update_data = NULL;
736dda156cfSEmil Velikov drm_gem_object_put(&dcrtc->cursor_obj->obj);
737662af0d8SRussell King }
738662af0d8SRussell King dcrtc->cursor_obj = obj;
739662af0d8SRussell King dcrtc->cursor_w = w;
740662af0d8SRussell King dcrtc->cursor_h = h;
741662af0d8SRussell King ret = armada_drm_crtc_cursor_update(dcrtc, true);
742662af0d8SRussell King if (obj) {
743662af0d8SRussell King obj->update_data = dcrtc;
744662af0d8SRussell King obj->update = cursor_update;
745662af0d8SRussell King }
746662af0d8SRussell King
747662af0d8SRussell King return ret;
748662af0d8SRussell King }
749662af0d8SRussell King
armada_drm_crtc_cursor_move(struct drm_crtc * crtc,int x,int y)750662af0d8SRussell King static int armada_drm_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
751662af0d8SRussell King {
752662af0d8SRussell King struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
753662af0d8SRussell King int ret;
754662af0d8SRussell King
755662af0d8SRussell King /* If no cursor support, replicate drm's return value */
75642e62ba7SRussell King if (!dcrtc->variant->has_spu_adv_reg)
757662af0d8SRussell King return -EFAULT;
758662af0d8SRussell King
759662af0d8SRussell King dcrtc->cursor_x = x;
760662af0d8SRussell King dcrtc->cursor_y = y;
761662af0d8SRussell King ret = armada_drm_crtc_cursor_update(dcrtc, false);
762662af0d8SRussell King
763662af0d8SRussell King return ret;
764662af0d8SRussell King }
765662af0d8SRussell King
armada_drm_crtc_destroy(struct drm_crtc * crtc)76696f60e37SRussell King static void armada_drm_crtc_destroy(struct drm_crtc *crtc)
76796f60e37SRussell King {
76896f60e37SRussell King struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
769dad75a52SDaniel Vetter struct armada_private *priv = drm_to_armada_dev(crtc->dev);
77096f60e37SRussell King
771662af0d8SRussell King if (dcrtc->cursor_obj)
772dda156cfSEmil Velikov drm_gem_object_put(&dcrtc->cursor_obj->obj);
773662af0d8SRussell King
77496f60e37SRussell King priv->dcrtc[dcrtc->num] = NULL;
77596f60e37SRussell King drm_crtc_cleanup(&dcrtc->crtc);
77696f60e37SRussell King
777a0fbb35eSRussell King if (dcrtc->variant->disable)
778a0fbb35eSRussell King dcrtc->variant->disable(dcrtc);
77996f60e37SRussell King
780e5d9ddfbSRussell King writel_relaxed(0, dcrtc->base + LCD_SPU_IRQ_ENA);
781e5d9ddfbSRussell King
7829611cb93SRussell King of_node_put(dcrtc->crtc.port);
7839611cb93SRussell King
78496f60e37SRussell King kfree(dcrtc);
78596f60e37SRussell King }
78696f60e37SRussell King
armada_drm_crtc_late_register(struct drm_crtc * crtc)78706734cb0SRussell King static int armada_drm_crtc_late_register(struct drm_crtc *crtc)
78806734cb0SRussell King {
78906734cb0SRussell King if (IS_ENABLED(CONFIG_DEBUG_FS))
79006734cb0SRussell King armada_drm_crtc_debugfs_init(drm_to_armada_crtc(crtc));
79106734cb0SRussell King
79206734cb0SRussell King return 0;
79306734cb0SRussell King }
79406734cb0SRussell King
7955922a7d0SShawn Guo /* These are called under the vbl_lock. */
armada_drm_crtc_enable_vblank(struct drm_crtc * crtc)7965922a7d0SShawn Guo static int armada_drm_crtc_enable_vblank(struct drm_crtc *crtc)
7975922a7d0SShawn Guo {
7985922a7d0SShawn Guo struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
79992298c1cSRussell King unsigned long flags;
8005922a7d0SShawn Guo
80192298c1cSRussell King spin_lock_irqsave(&dcrtc->irq_lock, flags);
8025922a7d0SShawn Guo armada_drm_crtc_enable_irq(dcrtc, VSYNC_IRQ_ENA);
80392298c1cSRussell King spin_unlock_irqrestore(&dcrtc->irq_lock, flags);
8045922a7d0SShawn Guo return 0;
8055922a7d0SShawn Guo }
8065922a7d0SShawn Guo
armada_drm_crtc_disable_vblank(struct drm_crtc * crtc)8075922a7d0SShawn Guo static void armada_drm_crtc_disable_vblank(struct drm_crtc *crtc)
8085922a7d0SShawn Guo {
8095922a7d0SShawn Guo struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
81092298c1cSRussell King unsigned long flags;
8115922a7d0SShawn Guo
81292298c1cSRussell King spin_lock_irqsave(&dcrtc->irq_lock, flags);
8135922a7d0SShawn Guo armada_drm_crtc_disable_irq(dcrtc, VSYNC_IRQ_ENA);
81492298c1cSRussell King spin_unlock_irqrestore(&dcrtc->irq_lock, flags);
8155922a7d0SShawn Guo }
8165922a7d0SShawn Guo
817a02fb90aSVille Syrjälä static const struct drm_crtc_funcs armada_crtc_funcs = {
818c36045e1SRussell King .reset = drm_atomic_helper_crtc_reset,
819662af0d8SRussell King .cursor_set = armada_drm_crtc_cursor_set,
820662af0d8SRussell King .cursor_move = armada_drm_crtc_cursor_move,
82196f60e37SRussell King .destroy = armada_drm_crtc_destroy,
8226d2f864fSRussell King .set_config = drm_atomic_helper_set_config,
82313c94d53SRussell King .page_flip = drm_atomic_helper_page_flip,
824c36045e1SRussell King .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
825c36045e1SRussell King .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
82606734cb0SRussell King .late_register = armada_drm_crtc_late_register,
8275922a7d0SShawn Guo .enable_vblank = armada_drm_crtc_enable_vblank,
8285922a7d0SShawn Guo .disable_vblank = armada_drm_crtc_disable_vblank,
82996f60e37SRussell King };
83096f60e37SRussell King
armada_crtc_select_clock(struct armada_crtc * dcrtc,struct armada_clk_result * res,const struct armada_clocking_params * params,struct clk * clks[],size_t num_clks,unsigned long desired_khz)8311ba246f2SRussell King int armada_crtc_select_clock(struct armada_crtc *dcrtc,
8321ba246f2SRussell King struct armada_clk_result *res,
8331ba246f2SRussell King const struct armada_clocking_params *params,
8341ba246f2SRussell King struct clk *clks[], size_t num_clks,
8351ba246f2SRussell King unsigned long desired_khz)
8361ba246f2SRussell King {
8371ba246f2SRussell King unsigned long desired_hz = desired_khz * 1000;
8381ba246f2SRussell King unsigned long desired_clk_hz; // requested clk input
8391ba246f2SRussell King unsigned long real_clk_hz; // actual clk input
8401ba246f2SRussell King unsigned long real_hz; // actual pixel clk
8411ba246f2SRussell King unsigned long permillage;
8421ba246f2SRussell King struct clk *clk;
8431ba246f2SRussell King u32 div;
8441ba246f2SRussell King int i;
8451ba246f2SRussell King
8461ba246f2SRussell King DRM_DEBUG_KMS("[CRTC:%u:%s] desired clock=%luHz\n",
8471ba246f2SRussell King dcrtc->crtc.base.id, dcrtc->crtc.name, desired_hz);
8481ba246f2SRussell King
8491ba246f2SRussell King for (i = 0; i < num_clks; i++) {
8501ba246f2SRussell King clk = clks[i];
8511ba246f2SRussell King if (!clk)
8521ba246f2SRussell King continue;
8531ba246f2SRussell King
8541ba246f2SRussell King if (params->settable & BIT(i)) {
8551ba246f2SRussell King real_clk_hz = clk_round_rate(clk, desired_hz);
8561ba246f2SRussell King desired_clk_hz = desired_hz;
8571ba246f2SRussell King } else {
8581ba246f2SRussell King real_clk_hz = clk_get_rate(clk);
8591ba246f2SRussell King desired_clk_hz = real_clk_hz;
8601ba246f2SRussell King }
8611ba246f2SRussell King
8621ba246f2SRussell King /* If the clock can do exactly the desired rate, we're done */
8631ba246f2SRussell King if (real_clk_hz == desired_hz) {
8641ba246f2SRussell King real_hz = real_clk_hz;
8651ba246f2SRussell King div = 1;
8661ba246f2SRussell King goto found;
8671ba246f2SRussell King }
8681ba246f2SRussell King
8691ba246f2SRussell King /* Calculate the divider - if invalid, we can't do this rate */
8701ba246f2SRussell King div = DIV_ROUND_CLOSEST(real_clk_hz, desired_hz);
8711ba246f2SRussell King if (div == 0 || div > params->div_max)
8721ba246f2SRussell King continue;
8731ba246f2SRussell King
8741ba246f2SRussell King /* Calculate the actual rate - HDMI requires -0.6%..+0.5% */
8751ba246f2SRussell King real_hz = DIV_ROUND_CLOSEST(real_clk_hz, div);
8761ba246f2SRussell King
8771ba246f2SRussell King DRM_DEBUG_KMS("[CRTC:%u:%s] clk=%u %luHz div=%u real=%luHz\n",
8781ba246f2SRussell King dcrtc->crtc.base.id, dcrtc->crtc.name,
8791ba246f2SRussell King i, real_clk_hz, div, real_hz);
8801ba246f2SRussell King
8811ba246f2SRussell King /* Avoid repeated division */
8821ba246f2SRussell King if (real_hz < desired_hz) {
8831ba246f2SRussell King permillage = real_hz / desired_khz;
8841ba246f2SRussell King if (permillage < params->permillage_min)
8851ba246f2SRussell King continue;
8861ba246f2SRussell King } else {
8871ba246f2SRussell King permillage = DIV_ROUND_UP(real_hz, desired_khz);
8881ba246f2SRussell King if (permillage > params->permillage_max)
8891ba246f2SRussell King continue;
8901ba246f2SRussell King }
8911ba246f2SRussell King goto found;
8921ba246f2SRussell King }
8931ba246f2SRussell King
8941ba246f2SRussell King return -ERANGE;
8951ba246f2SRussell King
8961ba246f2SRussell King found:
8971ba246f2SRussell King DRM_DEBUG_KMS("[CRTC:%u:%s] selected clk=%u %luHz div=%u real=%luHz\n",
8981ba246f2SRussell King dcrtc->crtc.base.id, dcrtc->crtc.name,
8991ba246f2SRussell King i, real_clk_hz, div, real_hz);
9001ba246f2SRussell King
9011ba246f2SRussell King res->desired_clk_hz = desired_clk_hz;
9021ba246f2SRussell King res->clk = clk;
9031ba246f2SRussell King res->div = div;
9041ba246f2SRussell King
9051ba246f2SRussell King return i;
9061ba246f2SRussell King }
9071ba246f2SRussell King
armada_drm_crtc_create(struct drm_device * drm,struct device * dev,struct resource * res,int irq,const struct armada_variant * variant,struct device_node * port)9080fb2970bSRussell King static int armada_drm_crtc_create(struct drm_device *drm, struct device *dev,
9099611cb93SRussell King struct resource *res, int irq, const struct armada_variant *variant,
9109611cb93SRussell King struct device_node *port)
91196f60e37SRussell King {
912dad75a52SDaniel Vetter struct armada_private *priv = drm_to_armada_dev(drm);
91396f60e37SRussell King struct armada_crtc *dcrtc;
91482c702cbSRussell King struct drm_plane *primary;
91596f60e37SRussell King void __iomem *base;
91696f60e37SRussell King int ret;
91796f60e37SRussell King
918a7d7a143SLinus Torvalds base = devm_ioremap_resource(dev, res);
919c9d53c0fSJingoo Han if (IS_ERR(base))
920c9d53c0fSJingoo Han return PTR_ERR(base);
92196f60e37SRussell King
92296f60e37SRussell King dcrtc = kzalloc(sizeof(*dcrtc), GFP_KERNEL);
92396f60e37SRussell King if (!dcrtc) {
92496f60e37SRussell King DRM_ERROR("failed to allocate Armada crtc\n");
92596f60e37SRussell King return -ENOMEM;
92696f60e37SRussell King }
92796f60e37SRussell King
928d8c96083SRussell King if (dev != drm->dev)
929d8c96083SRussell King dev_set_drvdata(dev, dcrtc);
930d8c96083SRussell King
93142e62ba7SRussell King dcrtc->variant = variant;
93296f60e37SRussell King dcrtc->base = base;
933d8c96083SRussell King dcrtc->num = drm->mode_config.num_crtc;
93496f60e37SRussell King dcrtc->cfg_dumb_ctrl = DUMB24_RGB888_0;
93596f60e37SRussell King dcrtc->spu_iopad_ctrl = CFG_VSCALE_LN_EN | CFG_IOPAD_DUMB24;
93696f60e37SRussell King spin_lock_init(&dcrtc->irq_lock);
93796f60e37SRussell King dcrtc->irq_ena = CLEAN_SPU_IRQ_ISR;
93896f60e37SRussell King
93996f60e37SRussell King /* Initialize some registers which we don't otherwise set */
94096f60e37SRussell King writel_relaxed(0x00000001, dcrtc->base + LCD_CFG_SCLK_DIV);
94196f60e37SRussell King writel_relaxed(0x00000000, dcrtc->base + LCD_SPU_BLANKCOLOR);
94296f60e37SRussell King writel_relaxed(dcrtc->spu_iopad_ctrl,
94396f60e37SRussell King dcrtc->base + LCD_SPU_IOPAD_CONTROL);
94496f60e37SRussell King writel_relaxed(0x00000000, dcrtc->base + LCD_SPU_SRAM_PARA0);
94596f60e37SRussell King writel_relaxed(CFG_PDWN256x32 | CFG_PDWN256x24 | CFG_PDWN256x8 |
94696f60e37SRussell King CFG_PDWN32x32 | CFG_PDWN16x66 | CFG_PDWN32x66 |
94796f60e37SRussell King CFG_PDWN64x66, dcrtc->base + LCD_SPU_SRAM_PARA1);
94896f60e37SRussell King writel_relaxed(0x2032ff81, dcrtc->base + LCD_SPU_DMA_CTRL1);
949e5d9ddfbSRussell King writel_relaxed(dcrtc->irq_ena, dcrtc->base + LCD_SPU_IRQ_ENA);
95092298c1cSRussell King readl_relaxed(dcrtc->base + LCD_SPU_IRQ_ISR);
951e5d9ddfbSRussell King writel_relaxed(0, dcrtc->base + LCD_SPU_IRQ_ISR);
95296f60e37SRussell King
953e5d9ddfbSRussell King ret = devm_request_irq(dev, irq, armada_drm_irq, 0, "armada_drm_crtc",
954e5d9ddfbSRussell King dcrtc);
95533cd3c07SRussell King if (ret < 0)
95633cd3c07SRussell King goto err_crtc;
95796f60e37SRussell King
95842e62ba7SRussell King if (dcrtc->variant->init) {
959d8c96083SRussell King ret = dcrtc->variant->init(dcrtc, dev);
96033cd3c07SRussell King if (ret)
96133cd3c07SRussell King goto err_crtc;
96296f60e37SRussell King }
96396f60e37SRussell King
96496f60e37SRussell King /* Ensure AXI pipeline is enabled */
96596f60e37SRussell King armada_updatel(CFG_ARBFAST_ENA, 0, dcrtc->base + LCD_SPU_DMA_CTRL0);
96696f60e37SRussell King
96796f60e37SRussell King priv->dcrtc[dcrtc->num] = dcrtc;
96896f60e37SRussell King
9699611cb93SRussell King dcrtc->crtc.port = port;
9701c914cecSRussell King
971de32301bSRussell King primary = kzalloc(sizeof(*primary), GFP_KERNEL);
97233cd3c07SRussell King if (!primary) {
97333cd3c07SRussell King ret = -ENOMEM;
97433cd3c07SRussell King goto err_crtc;
97533cd3c07SRussell King }
9761c914cecSRussell King
977d40af7b1SRussell King ret = armada_drm_primary_plane_init(drm, primary);
978de32301bSRussell King if (ret) {
979de32301bSRussell King kfree(primary);
98033cd3c07SRussell King goto err_crtc;
981de32301bSRussell King }
982de32301bSRussell King
98382c702cbSRussell King ret = drm_crtc_init_with_planes(drm, &dcrtc->crtc, primary, NULL,
984f9882876SVille Syrjälä &armada_crtc_funcs, NULL);
9851c914cecSRussell King if (ret)
9861c914cecSRussell King goto err_crtc_init;
9871c914cecSRussell King
98896f60e37SRussell King drm_crtc_helper_add(&dcrtc->crtc, &armada_crtc_helper_funcs);
98996f60e37SRussell King
990d0d765deSRussell King ret = drm_mode_crtc_set_gamma_size(&dcrtc->crtc, 256);
991d0d765deSRussell King if (ret)
992d0d765deSRussell King return ret;
993d0d765deSRussell King
994d0d765deSRussell King drm_crtc_enable_color_mgmt(&dcrtc->crtc, 0, false, 256);
995d0d765deSRussell King
996d8c96083SRussell King return armada_overlay_plane_create(drm, 1 << dcrtc->num);
9971c914cecSRussell King
9981c914cecSRussell King err_crtc_init:
99982c702cbSRussell King primary->funcs->destroy(primary);
100033cd3c07SRussell King err_crtc:
100133cd3c07SRussell King kfree(dcrtc);
100233cd3c07SRussell King
10031c914cecSRussell King return ret;
100496f60e37SRussell King }
1005d8c96083SRussell King
1006d8c96083SRussell King static int
armada_lcd_bind(struct device * dev,struct device * master,void * data)1007d8c96083SRussell King armada_lcd_bind(struct device *dev, struct device *master, void *data)
1008d8c96083SRussell King {
1009d8c96083SRussell King struct platform_device *pdev = to_platform_device(dev);
1010d8c96083SRussell King struct drm_device *drm = data;
1011d8c96083SRussell King struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1012d8c96083SRussell King int irq = platform_get_irq(pdev, 0);
1013d8c96083SRussell King const struct armada_variant *variant;
10149611cb93SRussell King struct device_node *port = NULL;
1015d8c96083SRussell King
1016d8c96083SRussell King if (irq < 0)
1017d8c96083SRussell King return irq;
1018d8c96083SRussell King
1019d8c96083SRussell King if (!dev->of_node) {
1020d8c96083SRussell King const struct platform_device_id *id;
1021d8c96083SRussell King
1022d8c96083SRussell King id = platform_get_device_id(pdev);
1023d8c96083SRussell King if (!id)
1024d8c96083SRussell King return -ENXIO;
1025d8c96083SRussell King
1026d8c96083SRussell King variant = (const struct armada_variant *)id->driver_data;
1027d8c96083SRussell King } else {
1028d8c96083SRussell King const struct of_device_id *match;
10299611cb93SRussell King struct device_node *np, *parent = dev->of_node;
1030d8c96083SRussell King
1031d8c96083SRussell King match = of_match_device(dev->driver->of_match_table, dev);
1032d8c96083SRussell King if (!match)
1033d8c96083SRussell King return -ENXIO;
1034d8c96083SRussell King
10359611cb93SRussell King np = of_get_child_by_name(parent, "ports");
10369611cb93SRussell King if (np)
10379611cb93SRussell King parent = np;
10389611cb93SRussell King port = of_get_child_by_name(parent, "port");
10399611cb93SRussell King of_node_put(np);
10409611cb93SRussell King if (!port) {
10414bf99144SRob Herring dev_err(dev, "no port node found in %pOF\n", parent);
10429611cb93SRussell King return -ENXIO;
10439611cb93SRussell King }
10449611cb93SRussell King
1045d8c96083SRussell King variant = match->data;
1046d8c96083SRussell King }
1047d8c96083SRussell King
10489611cb93SRussell King return armada_drm_crtc_create(drm, dev, res, irq, variant, port);
1049d8c96083SRussell King }
1050d8c96083SRussell King
1051d8c96083SRussell King static void
armada_lcd_unbind(struct device * dev,struct device * master,void * data)1052d8c96083SRussell King armada_lcd_unbind(struct device *dev, struct device *master, void *data)
1053d8c96083SRussell King {
1054d8c96083SRussell King struct armada_crtc *dcrtc = dev_get_drvdata(dev);
1055d8c96083SRussell King
1056d8c96083SRussell King armada_drm_crtc_destroy(&dcrtc->crtc);
1057d8c96083SRussell King }
1058d8c96083SRussell King
1059d8c96083SRussell King static const struct component_ops armada_lcd_ops = {
1060d8c96083SRussell King .bind = armada_lcd_bind,
1061d8c96083SRussell King .unbind = armada_lcd_unbind,
1062d8c96083SRussell King };
1063d8c96083SRussell King
armada_lcd_probe(struct platform_device * pdev)1064d8c96083SRussell King static int armada_lcd_probe(struct platform_device *pdev)
1065d8c96083SRussell King {
1066d8c96083SRussell King return component_add(&pdev->dev, &armada_lcd_ops);
1067d8c96083SRussell King }
1068d8c96083SRussell King
armada_lcd_remove(struct platform_device * pdev)1069d8c96083SRussell King static int armada_lcd_remove(struct platform_device *pdev)
1070d8c96083SRussell King {
1071d8c96083SRussell King component_del(&pdev->dev, &armada_lcd_ops);
1072d8c96083SRussell King return 0;
1073d8c96083SRussell King }
1074d8c96083SRussell King
107585909716SArvind Yadav static const struct of_device_id armada_lcd_of_match[] = {
1076d8c96083SRussell King {
1077d8c96083SRussell King .compatible = "marvell,dove-lcd",
1078d8c96083SRussell King .data = &armada510_ops,
1079d8c96083SRussell King },
1080d8c96083SRussell King {}
1081d8c96083SRussell King };
1082d8c96083SRussell King MODULE_DEVICE_TABLE(of, armada_lcd_of_match);
1083d8c96083SRussell King
1084d8c96083SRussell King static const struct platform_device_id armada_lcd_platform_ids[] = {
1085d8c96083SRussell King {
1086d8c96083SRussell King .name = "armada-lcd",
1087d8c96083SRussell King .driver_data = (unsigned long)&armada510_ops,
1088d8c96083SRussell King }, {
1089d8c96083SRussell King .name = "armada-510-lcd",
1090d8c96083SRussell King .driver_data = (unsigned long)&armada510_ops,
1091d8c96083SRussell King },
1092d8c96083SRussell King { },
1093d8c96083SRussell King };
1094d8c96083SRussell King MODULE_DEVICE_TABLE(platform, armada_lcd_platform_ids);
1095d8c96083SRussell King
1096d8c96083SRussell King struct platform_driver armada_lcd_platform_driver = {
1097d8c96083SRussell King .probe = armada_lcd_probe,
1098d8c96083SRussell King .remove = armada_lcd_remove,
1099d8c96083SRussell King .driver = {
1100d8c96083SRussell King .name = "armada-lcd",
1101d8c96083SRussell King .owner = THIS_MODULE,
1102d8c96083SRussell King .of_match_table = armada_lcd_of_match,
1103d8c96083SRussell King },
1104d8c96083SRussell King .id_table = armada_lcd_platform_ids,
1105d8c96083SRussell King };
1106