196f60e37SRussell King /* 296f60e37SRussell King * Copyright (C) 2012 Russell King 396f60e37SRussell King * Rewritten from the dovefb driver, and Armada510 manuals. 496f60e37SRussell King * 596f60e37SRussell King * This program is free software; you can redistribute it and/or modify 696f60e37SRussell King * it under the terms of the GNU General Public License version 2 as 796f60e37SRussell King * published by the Free Software Foundation. 896f60e37SRussell King */ 996f60e37SRussell King #include <linux/clk.h> 10d8c96083SRussell King #include <linux/component.h> 11d8c96083SRussell King #include <linux/of_device.h> 12d8c96083SRussell King #include <linux/platform_device.h> 1396f60e37SRussell King #include <drm/drmP.h> 1496f60e37SRussell King #include <drm/drm_crtc_helper.h> 153cb9ae4fSDaniel Vetter #include <drm/drm_plane_helper.h> 16bcd21a47SDave Airlie #include <drm/drm_atomic_helper.h> 1796f60e37SRussell King #include "armada_crtc.h" 1896f60e37SRussell King #include "armada_drm.h" 1996f60e37SRussell King #include "armada_fb.h" 2096f60e37SRussell King #include "armada_gem.h" 2196f60e37SRussell King #include "armada_hw.h" 22c8a220c6SRussell King #include "armada_trace.h" 2396f60e37SRussell King 2496f60e37SRussell King enum csc_mode { 2596f60e37SRussell King CSC_AUTO = 0, 2696f60e37SRussell King CSC_YUV_CCIR601 = 1, 2796f60e37SRussell King CSC_YUV_CCIR709 = 2, 2896f60e37SRussell King CSC_RGB_COMPUTER = 1, 2996f60e37SRussell King CSC_RGB_STUDIO = 2, 3096f60e37SRussell King }; 3196f60e37SRussell King 321c914cecSRussell King static const uint32_t armada_primary_formats[] = { 331c914cecSRussell King DRM_FORMAT_UYVY, 341c914cecSRussell King DRM_FORMAT_YUYV, 351c914cecSRussell King DRM_FORMAT_VYUY, 361c914cecSRussell King DRM_FORMAT_YVYU, 371c914cecSRussell King DRM_FORMAT_ARGB8888, 381c914cecSRussell King DRM_FORMAT_ABGR8888, 391c914cecSRussell King DRM_FORMAT_XRGB8888, 401c914cecSRussell King DRM_FORMAT_XBGR8888, 411c914cecSRussell King DRM_FORMAT_RGB888, 421c914cecSRussell King DRM_FORMAT_BGR888, 431c914cecSRussell King DRM_FORMAT_ARGB1555, 441c914cecSRussell King DRM_FORMAT_ABGR1555, 451c914cecSRussell King DRM_FORMAT_RGB565, 461c914cecSRussell King DRM_FORMAT_BGR565, 471c914cecSRussell King }; 481c914cecSRussell King 4996f60e37SRussell King /* 5096f60e37SRussell King * A note about interlacing. Let's consider HDMI 1920x1080i. 5196f60e37SRussell King * The timing parameters we have from X are: 5296f60e37SRussell King * Hact HsyA HsyI Htot Vact VsyA VsyI Vtot 5396f60e37SRussell King * 1920 2448 2492 2640 1080 1084 1094 1125 5496f60e37SRussell King * Which get translated to: 5596f60e37SRussell King * Hact HsyA HsyI Htot Vact VsyA VsyI Vtot 5696f60e37SRussell King * 1920 2448 2492 2640 540 542 547 562 5796f60e37SRussell King * 5896f60e37SRussell King * This is how it is defined by CEA-861-D - line and pixel numbers are 5996f60e37SRussell King * referenced to the rising edge of VSYNC and HSYNC. Total clocks per 6096f60e37SRussell King * line: 2640. The odd frame, the first active line is at line 21, and 6196f60e37SRussell King * the even frame, the first active line is 584. 6296f60e37SRussell King * 6396f60e37SRussell King * LN: 560 561 562 563 567 568 569 6496f60e37SRussell King * DE: ~~~|____________________________//__________________________ 6596f60e37SRussell King * HSYNC: ____|~|_____|~|_____|~|_____|~|_//__|~|_____|~|_____|~|_____ 6696f60e37SRussell King * VSYNC: _________________________|~~~~~~//~~~~~~~~~~~~~~~|__________ 6796f60e37SRussell King * 22 blanking lines. VSYNC at 1320 (referenced to the HSYNC rising edge). 6896f60e37SRussell King * 6996f60e37SRussell King * LN: 1123 1124 1125 1 5 6 7 7096f60e37SRussell King * DE: ~~~|____________________________//__________________________ 7196f60e37SRussell King * HSYNC: ____|~|_____|~|_____|~|_____|~|_//__|~|_____|~|_____|~|_____ 7296f60e37SRussell King * VSYNC: ____________________|~~~~~~~~~~~//~~~~~~~~~~|_______________ 7396f60e37SRussell King * 23 blanking lines 7496f60e37SRussell King * 7596f60e37SRussell King * The Armada LCD Controller line and pixel numbers are, like X timings, 7696f60e37SRussell King * referenced to the top left of the active frame. 7796f60e37SRussell King * 7896f60e37SRussell King * So, translating these to our LCD controller: 7996f60e37SRussell King * Odd frame, 563 total lines, VSYNC at line 543-548, pixel 1128. 8096f60e37SRussell King * Even frame, 562 total lines, VSYNC at line 542-547, pixel 2448. 8196f60e37SRussell King * Note: Vsync front porch remains constant! 8296f60e37SRussell King * 8396f60e37SRussell King * if (odd_frame) { 8496f60e37SRussell King * vtotal = mode->crtc_vtotal + 1; 8596f60e37SRussell King * vbackporch = mode->crtc_vsync_start - mode->crtc_vdisplay + 1; 8696f60e37SRussell King * vhorizpos = mode->crtc_hsync_start - mode->crtc_htotal / 2 8796f60e37SRussell King * } else { 8896f60e37SRussell King * vtotal = mode->crtc_vtotal; 8996f60e37SRussell King * vbackporch = mode->crtc_vsync_start - mode->crtc_vdisplay; 9096f60e37SRussell King * vhorizpos = mode->crtc_hsync_start; 9196f60e37SRussell King * } 9296f60e37SRussell King * vfrontporch = mode->crtc_vtotal - mode->crtc_vsync_end; 9396f60e37SRussell King * 9496f60e37SRussell King * So, we need to reprogram these registers on each vsync event: 9596f60e37SRussell King * LCD_SPU_V_PORCH, LCD_SPU_ADV_REG, LCD_SPUT_V_H_TOTAL 9696f60e37SRussell King * 9796f60e37SRussell King * Note: we do not use the frame done interrupts because these appear 9896f60e37SRussell King * to happen too early, and lead to jitter on the display (presumably 9996f60e37SRussell King * they occur at the end of the last active line, before the vsync back 10096f60e37SRussell King * porch, which we're reprogramming.) 10196f60e37SRussell King */ 10296f60e37SRussell King 10396f60e37SRussell King void 10496f60e37SRussell King armada_drm_crtc_update_regs(struct armada_crtc *dcrtc, struct armada_regs *regs) 10596f60e37SRussell King { 10696f60e37SRussell King while (regs->offset != ~0) { 10796f60e37SRussell King void __iomem *reg = dcrtc->base + regs->offset; 10896f60e37SRussell King uint32_t val; 10996f60e37SRussell King 11096f60e37SRussell King val = regs->mask; 11196f60e37SRussell King if (val != 0) 11296f60e37SRussell King val &= readl_relaxed(reg); 11396f60e37SRussell King writel_relaxed(val | regs->val, reg); 11496f60e37SRussell King ++regs; 11596f60e37SRussell King } 11696f60e37SRussell King } 11796f60e37SRussell King 11896f60e37SRussell King #define dpms_blanked(dpms) ((dpms) != DRM_MODE_DPMS_ON) 11996f60e37SRussell King 12096f60e37SRussell King static void armada_drm_crtc_update(struct armada_crtc *dcrtc) 12196f60e37SRussell King { 12296f60e37SRussell King uint32_t dumb_ctrl; 12396f60e37SRussell King 12496f60e37SRussell King dumb_ctrl = dcrtc->cfg_dumb_ctrl; 12596f60e37SRussell King 12696f60e37SRussell King if (!dpms_blanked(dcrtc->dpms)) 12796f60e37SRussell King dumb_ctrl |= CFG_DUMB_ENA; 12896f60e37SRussell King 12996f60e37SRussell King /* 13096f60e37SRussell King * When the dumb interface isn't in DUMB24_RGB888_0 mode, it might 13196f60e37SRussell King * be using SPI or GPIO. If we set this to DUMB_BLANK, we will 13296f60e37SRussell King * force LCD_D[23:0] to output blank color, overriding the GPIO or 13396f60e37SRussell King * SPI usage. So leave it as-is unless in DUMB24_RGB888_0 mode. 13496f60e37SRussell King */ 13596f60e37SRussell King if (dpms_blanked(dcrtc->dpms) && 13696f60e37SRussell King (dumb_ctrl & DUMB_MASK) == DUMB24_RGB888_0) { 13796f60e37SRussell King dumb_ctrl &= ~DUMB_MASK; 13896f60e37SRussell King dumb_ctrl |= DUMB_BLANK; 13996f60e37SRussell King } 14096f60e37SRussell King 14196f60e37SRussell King /* 14296f60e37SRussell King * The documentation doesn't indicate what the normal state of 14396f60e37SRussell King * the sync signals are. Sebastian Hesselbart kindly probed 14496f60e37SRussell King * these signals on his board to determine their state. 14596f60e37SRussell King * 14696f60e37SRussell King * The non-inverted state of the sync signals is active high. 14796f60e37SRussell King * Setting these bits makes the appropriate signal active low. 14896f60e37SRussell King */ 14996f60e37SRussell King if (dcrtc->crtc.mode.flags & DRM_MODE_FLAG_NCSYNC) 15096f60e37SRussell King dumb_ctrl |= CFG_INV_CSYNC; 15196f60e37SRussell King if (dcrtc->crtc.mode.flags & DRM_MODE_FLAG_NHSYNC) 15296f60e37SRussell King dumb_ctrl |= CFG_INV_HSYNC; 15396f60e37SRussell King if (dcrtc->crtc.mode.flags & DRM_MODE_FLAG_NVSYNC) 15496f60e37SRussell King dumb_ctrl |= CFG_INV_VSYNC; 15596f60e37SRussell King 15696f60e37SRussell King if (dcrtc->dumb_ctrl != dumb_ctrl) { 15796f60e37SRussell King dcrtc->dumb_ctrl = dumb_ctrl; 15896f60e37SRussell King writel_relaxed(dumb_ctrl, dcrtc->base + LCD_SPU_DUMB_CTRL); 15996f60e37SRussell King } 16096f60e37SRussell King } 16196f60e37SRussell King 162f0b24871SRussell King void armada_drm_plane_calc_addrs(u32 *addrs, struct drm_framebuffer *fb, 163f0b24871SRussell King int x, int y) 164f0b24871SRussell King { 165d6a48965SRussell King const struct drm_format_info *format = fb->format; 166d6a48965SRussell King unsigned int num_planes = format->num_planes; 167f0b24871SRussell King u32 addr = drm_fb_obj(fb)->dev_addr; 168f0b24871SRussell King int i; 169f0b24871SRussell King 170f0b24871SRussell King if (num_planes > 3) 171f0b24871SRussell King num_planes = 3; 172f0b24871SRussell King 173de0ea9adSRussell King addrs[0] = addr + fb->offsets[0] + y * fb->pitches[0] + 174de0ea9adSRussell King x * format->cpp[0]; 175de0ea9adSRussell King 176de0ea9adSRussell King y /= format->vsub; 177de0ea9adSRussell King x /= format->hsub; 178de0ea9adSRussell King 179de0ea9adSRussell King for (i = 1; i < num_planes; i++) 180f0b24871SRussell King addrs[i] = addr + fb->offsets[i] + y * fb->pitches[i] + 181d6a48965SRussell King x * format->cpp[i]; 182f0b24871SRussell King for (; i < 3; i++) 183f0b24871SRussell King addrs[i] = 0; 184f0b24871SRussell King } 185f0b24871SRussell King 18696f60e37SRussell King static unsigned armada_drm_crtc_calc_fb(struct drm_framebuffer *fb, 18796f60e37SRussell King int x, int y, struct armada_regs *regs, bool interlaced) 18896f60e37SRussell King { 18996f60e37SRussell King unsigned pitch = fb->pitches[0]; 190f0b24871SRussell King u32 addrs[3], addr_odd, addr_even; 19196f60e37SRussell King unsigned i = 0; 19296f60e37SRussell King 19396f60e37SRussell King DRM_DEBUG_DRIVER("pitch %u x %d y %d bpp %d\n", 194272725c7SVille Syrjälä pitch, x, y, fb->format->cpp[0] * 8); 19596f60e37SRussell King 196f0b24871SRussell King armada_drm_plane_calc_addrs(addrs, fb, x, y); 197f0b24871SRussell King 198f0b24871SRussell King addr_odd = addr_even = addrs[0]; 19996f60e37SRussell King 20096f60e37SRussell King if (interlaced) { 20196f60e37SRussell King addr_even += pitch; 20296f60e37SRussell King pitch *= 2; 20396f60e37SRussell King } 20496f60e37SRussell King 20596f60e37SRussell King /* write offset, base, and pitch */ 20696f60e37SRussell King armada_reg_queue_set(regs, i, addr_odd, LCD_CFG_GRA_START_ADDR0); 20796f60e37SRussell King armada_reg_queue_set(regs, i, addr_even, LCD_CFG_GRA_START_ADDR1); 20896f60e37SRussell King armada_reg_queue_mod(regs, i, pitch, 0xffff, LCD_CFG_GRA_PITCH); 20996f60e37SRussell King 21096f60e37SRussell King return i; 21196f60e37SRussell King } 21296f60e37SRussell King 2132839d45cSRussell King static void armada_drm_plane_work_call(struct armada_crtc *dcrtc, 2142839d45cSRussell King struct armada_plane_work *work, 2152839d45cSRussell King void (*fn)(struct armada_crtc *, struct armada_plane_work *)) 2162839d45cSRussell King { 2172839d45cSRussell King struct armada_plane *dplane = drm_to_armada_plane(work->plane); 218d924155dSRussell King struct drm_pending_vblank_event *event; 219d924155dSRussell King struct drm_framebuffer *fb; 2202839d45cSRussell King 2212839d45cSRussell King if (fn) 2222839d45cSRussell King fn(dcrtc, work); 2232839d45cSRussell King drm_crtc_vblank_put(&dcrtc->crtc); 2242839d45cSRussell King 225d924155dSRussell King event = work->event; 226d924155dSRussell King fb = work->old_fb; 227eb19be5bSRussell King if (event || fb) { 228eb19be5bSRussell King struct drm_device *dev = dcrtc->crtc.dev; 229eb19be5bSRussell King unsigned long flags; 230eb19be5bSRussell King 231eb19be5bSRussell King spin_lock_irqsave(&dev->event_lock, flags); 232eb19be5bSRussell King if (event) 233eb19be5bSRussell King drm_crtc_send_vblank_event(&dcrtc->crtc, event); 234b972a80fSRussell King if (fb) 235eb19be5bSRussell King __armada_drm_queue_unref_work(dev, fb); 236eb19be5bSRussell King spin_unlock_irqrestore(&dev->event_lock, flags); 237eb19be5bSRussell King } 238b972a80fSRussell King 239d924155dSRussell King if (work->need_kfree) 240d924155dSRussell King kfree(work); 241d924155dSRussell King 2422839d45cSRussell King wake_up(&dplane->frame_wait); 2432839d45cSRussell King } 2442839d45cSRussell King 2454b5dda82SRussell King static void armada_drm_plane_work_run(struct armada_crtc *dcrtc, 246ec6fb159SRussell King struct drm_plane *plane) 2474b5dda82SRussell King { 248ec6fb159SRussell King struct armada_plane *dplane = drm_to_armada_plane(plane); 249ec6fb159SRussell King struct armada_plane_work *work = xchg(&dplane->work, NULL); 2504b5dda82SRussell King 2514b5dda82SRussell King /* Handle any pending frame work. */ 2522839d45cSRussell King if (work) 2532839d45cSRussell King armada_drm_plane_work_call(dcrtc, work, work->fn); 2544b5dda82SRussell King } 2554b5dda82SRussell King 2564b5dda82SRussell King int armada_drm_plane_work_queue(struct armada_crtc *dcrtc, 257eaab0130SRussell King struct armada_plane_work *work) 2584b5dda82SRussell King { 259eaab0130SRussell King struct armada_plane *plane = drm_to_armada_plane(work->plane); 2604b5dda82SRussell King int ret; 2614b5dda82SRussell King 262accbaf6eSGustavo Padovan ret = drm_crtc_vblank_get(&dcrtc->crtc); 263c93dfdcdSRussell King if (ret) 2644b5dda82SRussell King return ret; 2654b5dda82SRussell King 2664b5dda82SRussell King ret = cmpxchg(&plane->work, NULL, work) ? -EBUSY : 0; 2674b5dda82SRussell King if (ret) 268accbaf6eSGustavo Padovan drm_crtc_vblank_put(&dcrtc->crtc); 2694b5dda82SRussell King 2704b5dda82SRussell King return ret; 2714b5dda82SRussell King } 2724b5dda82SRussell King 2734b5dda82SRussell King int armada_drm_plane_work_wait(struct armada_plane *plane, long timeout) 2744b5dda82SRussell King { 2754b5dda82SRussell King return wait_event_timeout(plane->frame_wait, !plane->work, timeout); 2764b5dda82SRussell King } 2774b5dda82SRussell King 278d3b84215SRussell King void armada_drm_plane_work_cancel(struct armada_crtc *dcrtc, 279d3b84215SRussell King struct armada_plane *dplane) 2807c8f7e1aSRussell King { 281d3b84215SRussell King struct armada_plane_work *work = xchg(&dplane->work, NULL); 2827c8f7e1aSRussell King 2834a8506d2SRussell King if (work) 2842839d45cSRussell King armada_drm_plane_work_call(dcrtc, work, work->cancel); 28596f60e37SRussell King } 28696f60e37SRussell King 287709ffd82SRussell King static void armada_drm_crtc_complete_frame_work(struct armada_crtc *dcrtc, 28865724a19SRussell King struct armada_plane_work *work) 28996f60e37SRussell King { 290709ffd82SRussell King unsigned long flags; 29196f60e37SRussell King 292709ffd82SRussell King spin_lock_irqsave(&dcrtc->irq_lock, flags); 293eaa66279SRussell King armada_drm_crtc_update_regs(dcrtc, work->regs); 294709ffd82SRussell King spin_unlock_irqrestore(&dcrtc->irq_lock, flags); 295709ffd82SRussell King } 29696f60e37SRussell King 297890ca8dfSRussell King static void armada_drm_crtc_complete_disable_work(struct armada_crtc *dcrtc, 298890ca8dfSRussell King struct armada_plane_work *work) 299890ca8dfSRussell King { 300890ca8dfSRussell King unsigned long flags; 301890ca8dfSRussell King 302890ca8dfSRussell King if (dcrtc->plane == work->plane) 303890ca8dfSRussell King dcrtc->plane = NULL; 304890ca8dfSRussell King 305890ca8dfSRussell King spin_lock_irqsave(&dcrtc->irq_lock, flags); 306890ca8dfSRussell King armada_drm_crtc_update_regs(dcrtc, work->regs); 307890ca8dfSRussell King spin_unlock_irqrestore(&dcrtc->irq_lock, flags); 308890ca8dfSRussell King } 309890ca8dfSRussell King 310eaa66279SRussell King static struct armada_plane_work * 311eaa66279SRussell King armada_drm_crtc_alloc_plane_work(struct drm_plane *plane) 312901bb889SRussell King { 313eaa66279SRussell King struct armada_plane_work *work; 314901bb889SRussell King int i = 0; 315901bb889SRussell King 316901bb889SRussell King work = kzalloc(sizeof(*work), GFP_KERNEL); 317901bb889SRussell King if (!work) 318901bb889SRussell King return NULL; 319901bb889SRussell King 320eaa66279SRussell King work->plane = plane; 321eaa66279SRussell King work->fn = armada_drm_crtc_complete_frame_work; 322d924155dSRussell King work->need_kfree = true; 323901bb889SRussell King armada_reg_queue_end(work->regs, i); 324901bb889SRussell King 325901bb889SRussell King return work; 32696f60e37SRussell King } 32796f60e37SRussell King 32896f60e37SRussell King static void armada_drm_vblank_off(struct armada_crtc *dcrtc) 32996f60e37SRussell King { 33096f60e37SRussell King /* 33196f60e37SRussell King * Tell the DRM core that vblank IRQs aren't going to happen for 33296f60e37SRussell King * a while. This cleans up any pending vblank events for us. 33396f60e37SRussell King */ 334178e561fSRussell King drm_crtc_vblank_off(&dcrtc->crtc); 335ec6fb159SRussell King armada_drm_plane_work_run(dcrtc, dcrtc->crtc.primary); 33696f60e37SRussell King } 33796f60e37SRussell King 33896f60e37SRussell King /* The mode_config.mutex will be held for this call */ 33996f60e37SRussell King static void armada_drm_crtc_dpms(struct drm_crtc *crtc, int dpms) 34096f60e37SRussell King { 34196f60e37SRussell King struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); 34296f60e37SRussell King 343ea908ba8SRussell King if (dpms_blanked(dcrtc->dpms) != dpms_blanked(dpms)) { 34496f60e37SRussell King if (dpms_blanked(dpms)) 34596f60e37SRussell King armada_drm_vblank_off(dcrtc); 346ea908ba8SRussell King else if (!IS_ERR(dcrtc->clk)) 347ea908ba8SRussell King WARN_ON(clk_prepare_enable(dcrtc->clk)); 348ea908ba8SRussell King dcrtc->dpms = dpms; 349ea908ba8SRussell King armada_drm_crtc_update(dcrtc); 350ea908ba8SRussell King if (!dpms_blanked(dpms)) 351178e561fSRussell King drm_crtc_vblank_on(&dcrtc->crtc); 352ea908ba8SRussell King else if (!IS_ERR(dcrtc->clk)) 353ea908ba8SRussell King clk_disable_unprepare(dcrtc->clk); 354ea908ba8SRussell King } else if (dcrtc->dpms != dpms) { 355ea908ba8SRussell King dcrtc->dpms = dpms; 35696f60e37SRussell King } 35796f60e37SRussell King } 35896f60e37SRussell King 35996f60e37SRussell King /* 36096f60e37SRussell King * Prepare for a mode set. Turn off overlay to ensure that we don't end 36196f60e37SRussell King * up with the overlay size being bigger than the active screen size. 36296f60e37SRussell King * We rely upon X refreshing this state after the mode set has completed. 36396f60e37SRussell King * 36496f60e37SRussell King * The mode_config.mutex will be held for this call 36596f60e37SRussell King */ 36696f60e37SRussell King static void armada_drm_crtc_prepare(struct drm_crtc *crtc) 36796f60e37SRussell King { 36896f60e37SRussell King struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); 36996f60e37SRussell King struct drm_plane *plane; 370f9a13bb3SRussell King u32 val; 37196f60e37SRussell King 37296f60e37SRussell King /* 37396f60e37SRussell King * If we have an overlay plane associated with this CRTC, disable 37496f60e37SRussell King * it before the modeset to avoid its coordinates being outside 375f8e14069SRussell King * the new mode parameters. 37696f60e37SRussell King */ 37796f60e37SRussell King plane = dcrtc->plane; 378890ca8dfSRussell King if (plane) { 379f8e14069SRussell King drm_plane_force_disable(plane); 380890ca8dfSRussell King WARN_ON(!armada_drm_plane_work_wait(drm_to_armada_plane(plane), 381890ca8dfSRussell King HZ)); 382890ca8dfSRussell King } 383f9a13bb3SRussell King 384f9a13bb3SRussell King /* Wait for pending flips to complete */ 385f9a13bb3SRussell King armada_drm_plane_work_wait(drm_to_armada_plane(dcrtc->crtc.primary), 386f9a13bb3SRussell King MAX_SCHEDULE_TIMEOUT); 387f9a13bb3SRussell King 388f9a13bb3SRussell King drm_crtc_vblank_off(crtc); 389f9a13bb3SRussell King 390f9a13bb3SRussell King val = dcrtc->dumb_ctrl & ~CFG_DUMB_ENA; 391f9a13bb3SRussell King if (val != dcrtc->dumb_ctrl) { 392f9a13bb3SRussell King dcrtc->dumb_ctrl = val; 393f9a13bb3SRussell King writel_relaxed(val, dcrtc->base + LCD_SPU_DUMB_CTRL); 394f9a13bb3SRussell King } 39596f60e37SRussell King } 39696f60e37SRussell King 39796f60e37SRussell King /* The mode_config.mutex will be held for this call */ 39896f60e37SRussell King static void armada_drm_crtc_commit(struct drm_crtc *crtc) 39996f60e37SRussell King { 40096f60e37SRussell King struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); 40196f60e37SRussell King 40296f60e37SRussell King dcrtc->dpms = DRM_MODE_DPMS_ON; 40396f60e37SRussell King armada_drm_crtc_update(dcrtc); 404f9a13bb3SRussell King drm_crtc_vblank_on(crtc); 40596f60e37SRussell King } 40696f60e37SRussell King 40796f60e37SRussell King /* The mode_config.mutex will be held for this call */ 40896f60e37SRussell King static bool armada_drm_crtc_mode_fixup(struct drm_crtc *crtc, 40996f60e37SRussell King const struct drm_display_mode *mode, struct drm_display_mode *adj) 41096f60e37SRussell King { 41196f60e37SRussell King struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); 41296f60e37SRussell King int ret; 41396f60e37SRussell King 41496f60e37SRussell King /* We can't do interlaced modes if we don't have the SPU_ADV_REG */ 41542e62ba7SRussell King if (!dcrtc->variant->has_spu_adv_reg && 41696f60e37SRussell King adj->flags & DRM_MODE_FLAG_INTERLACE) 41796f60e37SRussell King return false; 41896f60e37SRussell King 41996f60e37SRussell King /* Check whether the display mode is possible */ 42042e62ba7SRussell King ret = dcrtc->variant->compute_clock(dcrtc, adj, NULL); 42196f60e37SRussell King if (ret) 42296f60e37SRussell King return false; 42396f60e37SRussell King 42496f60e37SRussell King return true; 42596f60e37SRussell King } 42696f60e37SRussell King 4275922a7d0SShawn Guo /* These are locked by dev->vbl_lock */ 4285922a7d0SShawn Guo static void armada_drm_crtc_disable_irq(struct armada_crtc *dcrtc, u32 mask) 4295922a7d0SShawn Guo { 4305922a7d0SShawn Guo if (dcrtc->irq_ena & mask) { 4315922a7d0SShawn Guo dcrtc->irq_ena &= ~mask; 4325922a7d0SShawn Guo writel(dcrtc->irq_ena, dcrtc->base + LCD_SPU_IRQ_ENA); 4335922a7d0SShawn Guo } 4345922a7d0SShawn Guo } 4355922a7d0SShawn Guo 4365922a7d0SShawn Guo static void armada_drm_crtc_enable_irq(struct armada_crtc *dcrtc, u32 mask) 4375922a7d0SShawn Guo { 4385922a7d0SShawn Guo if ((dcrtc->irq_ena & mask) != mask) { 4395922a7d0SShawn Guo dcrtc->irq_ena |= mask; 4405922a7d0SShawn Guo writel(dcrtc->irq_ena, dcrtc->base + LCD_SPU_IRQ_ENA); 4415922a7d0SShawn Guo if (readl_relaxed(dcrtc->base + LCD_SPU_IRQ_ISR) & mask) 4425922a7d0SShawn Guo writel(0, dcrtc->base + LCD_SPU_IRQ_ISR); 4435922a7d0SShawn Guo } 4445922a7d0SShawn Guo } 4455922a7d0SShawn Guo 446e5d9ddfbSRussell King static void armada_drm_crtc_irq(struct armada_crtc *dcrtc, u32 stat) 44796f60e37SRussell King { 44896f60e37SRussell King void __iomem *base = dcrtc->base; 4494a8506d2SRussell King struct drm_plane *ovl_plane; 45096f60e37SRussell King 45196f60e37SRussell King if (stat & DMA_FF_UNDERFLOW) 45296f60e37SRussell King DRM_ERROR("video underflow on crtc %u\n", dcrtc->num); 45396f60e37SRussell King if (stat & GRA_FF_UNDERFLOW) 45496f60e37SRussell King DRM_ERROR("graphics underflow on crtc %u\n", dcrtc->num); 45596f60e37SRussell King 45696f60e37SRussell King if (stat & VSYNC_IRQ) 4570ac28c57SGustavo Padovan drm_crtc_handle_vblank(&dcrtc->crtc); 45896f60e37SRussell King 4594a8506d2SRussell King ovl_plane = dcrtc->plane; 460ec6fb159SRussell King if (ovl_plane) 461ec6fb159SRussell King armada_drm_plane_work_run(dcrtc, ovl_plane); 46296f60e37SRussell King 463a3f6a18fSRussell King spin_lock(&dcrtc->irq_lock); 46496f60e37SRussell King if (stat & GRA_FRAME_IRQ && dcrtc->interlaced) { 46596f60e37SRussell King int i = stat & GRA_FRAME_IRQ0 ? 0 : 1; 46696f60e37SRussell King uint32_t val; 46796f60e37SRussell King 46896f60e37SRussell King writel_relaxed(dcrtc->v[i].spu_v_porch, base + LCD_SPU_V_PORCH); 46996f60e37SRussell King writel_relaxed(dcrtc->v[i].spu_v_h_total, 47096f60e37SRussell King base + LCD_SPUT_V_H_TOTAL); 47196f60e37SRussell King 47296f60e37SRussell King val = readl_relaxed(base + LCD_SPU_ADV_REG); 47396f60e37SRussell King val &= ~(ADV_VSYNC_L_OFF | ADV_VSYNC_H_OFF | ADV_VSYNCOFFEN); 47496f60e37SRussell King val |= dcrtc->v[i].spu_adv_reg; 475662af0d8SRussell King writel_relaxed(val, base + LCD_SPU_ADV_REG); 47696f60e37SRussell King } 477662af0d8SRussell King 478662af0d8SRussell King if (stat & DUMB_FRAMEDONE && dcrtc->cursor_update) { 479662af0d8SRussell King writel_relaxed(dcrtc->cursor_hw_pos, 480662af0d8SRussell King base + LCD_SPU_HWC_OVSA_HPXL_VLN); 481662af0d8SRussell King writel_relaxed(dcrtc->cursor_hw_sz, 482662af0d8SRussell King base + LCD_SPU_HWC_HPXL_VLN); 483662af0d8SRussell King armada_updatel(CFG_HWC_ENA, 484662af0d8SRussell King CFG_HWC_ENA | CFG_HWC_1BITMOD | CFG_HWC_1BITENA, 485662af0d8SRussell King base + LCD_SPU_DMA_CTRL0); 486662af0d8SRussell King dcrtc->cursor_update = false; 487662af0d8SRussell King armada_drm_crtc_disable_irq(dcrtc, DUMB_FRAMEDONE_ENA); 488662af0d8SRussell King } 489662af0d8SRussell King 49096f60e37SRussell King spin_unlock(&dcrtc->irq_lock); 49196f60e37SRussell King 492ec6fb159SRussell King if (stat & GRA_FRAME_IRQ) 493ec6fb159SRussell King armada_drm_plane_work_run(dcrtc, dcrtc->crtc.primary); 49496f60e37SRussell King } 49596f60e37SRussell King 496e5d9ddfbSRussell King static irqreturn_t armada_drm_irq(int irq, void *arg) 497e5d9ddfbSRussell King { 498e5d9ddfbSRussell King struct armada_crtc *dcrtc = arg; 499e5d9ddfbSRussell King u32 v, stat = readl_relaxed(dcrtc->base + LCD_SPU_IRQ_ISR); 500e5d9ddfbSRussell King 501e5d9ddfbSRussell King /* 50292298c1cSRussell King * Reading the ISR appears to clear bits provided CLEAN_SPU_IRQ_ISR 50392298c1cSRussell King * is set. Writing has some other effect to acknowledge the IRQ - 50492298c1cSRussell King * without this, we only get a single IRQ. 505e5d9ddfbSRussell King */ 506e5d9ddfbSRussell King writel_relaxed(0, dcrtc->base + LCD_SPU_IRQ_ISR); 507e5d9ddfbSRussell King 508c8a220c6SRussell King trace_armada_drm_irq(&dcrtc->crtc, stat); 509c8a220c6SRussell King 510e5d9ddfbSRussell King /* Mask out those interrupts we haven't enabled */ 511e5d9ddfbSRussell King v = stat & dcrtc->irq_ena; 512e5d9ddfbSRussell King 513e5d9ddfbSRussell King if (v & (VSYNC_IRQ|GRA_FRAME_IRQ|DUMB_FRAMEDONE)) { 514e5d9ddfbSRussell King armada_drm_crtc_irq(dcrtc, stat); 515e5d9ddfbSRussell King return IRQ_HANDLED; 516e5d9ddfbSRussell King } 517e5d9ddfbSRussell King return IRQ_NONE; 518e5d9ddfbSRussell King } 519e5d9ddfbSRussell King 52096f60e37SRussell King static uint32_t armada_drm_crtc_calculate_csc(struct armada_crtc *dcrtc) 52196f60e37SRussell King { 52296f60e37SRussell King struct drm_display_mode *adj = &dcrtc->crtc.mode; 52396f60e37SRussell King uint32_t val = 0; 52496f60e37SRussell King 52596f60e37SRussell King if (dcrtc->csc_yuv_mode == CSC_YUV_CCIR709) 52696f60e37SRussell King val |= CFG_CSC_YUV_CCIR709; 52796f60e37SRussell King if (dcrtc->csc_rgb_mode == CSC_RGB_STUDIO) 52896f60e37SRussell King val |= CFG_CSC_RGB_STUDIO; 52996f60e37SRussell King 53096f60e37SRussell King /* 53196f60e37SRussell King * In auto mode, set the colorimetry, based upon the HDMI spec. 53296f60e37SRussell King * 1280x720p, 1920x1080p and 1920x1080i use ITU709, others use 53396f60e37SRussell King * ITU601. It may be more appropriate to set this depending on 53496f60e37SRussell King * the source - but what if the graphic frame is YUV and the 53596f60e37SRussell King * video frame is RGB? 53696f60e37SRussell King */ 53796f60e37SRussell King if ((adj->hdisplay == 1280 && adj->vdisplay == 720 && 53896f60e37SRussell King !(adj->flags & DRM_MODE_FLAG_INTERLACE)) || 53996f60e37SRussell King (adj->hdisplay == 1920 && adj->vdisplay == 1080)) { 54096f60e37SRussell King if (dcrtc->csc_yuv_mode == CSC_AUTO) 54196f60e37SRussell King val |= CFG_CSC_YUV_CCIR709; 54296f60e37SRussell King } 54396f60e37SRussell King 54496f60e37SRussell King /* 54596f60e37SRussell King * We assume we're connected to a TV-like device, so the YUV->RGB 54696f60e37SRussell King * conversion should produce a limited range. We should set this 54796f60e37SRussell King * depending on the connectors attached to this CRTC, and what 54896f60e37SRussell King * kind of device they report being connected. 54996f60e37SRussell King */ 55096f60e37SRussell King if (dcrtc->csc_rgb_mode == CSC_AUTO) 55196f60e37SRussell King val |= CFG_CSC_RGB_STUDIO; 55296f60e37SRussell King 55396f60e37SRussell King return val; 55496f60e37SRussell King } 55596f60e37SRussell King 55696f60e37SRussell King /* The mode_config.mutex will be held for this call */ 557*c36045e1SRussell King static void armada_drm_crtc_mode_set_nofb(struct drm_crtc *crtc) 55896f60e37SRussell King { 559*c36045e1SRussell King struct drm_display_mode *adj = &crtc->state->adjusted_mode; 56096f60e37SRussell King struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); 56196f60e37SRussell King struct armada_regs regs[17]; 56296f60e37SRussell King uint32_t lm, rm, tm, bm, val, sclk; 56396f60e37SRussell King unsigned long flags; 56496f60e37SRussell King unsigned i; 565*c36045e1SRussell King bool interlaced = !!(adj->flags & DRM_MODE_FLAG_INTERLACE); 56696f60e37SRussell King 56737af35c7SRussell King i = 0; 56896f60e37SRussell King rm = adj->crtc_hsync_start - adj->crtc_hdisplay; 56996f60e37SRussell King lm = adj->crtc_htotal - adj->crtc_hsync_end; 57096f60e37SRussell King bm = adj->crtc_vsync_start - adj->crtc_vdisplay; 57196f60e37SRussell King tm = adj->crtc_vtotal - adj->crtc_vsync_end; 57296f60e37SRussell King 57396f60e37SRussell King DRM_DEBUG_DRIVER("H: %d %d %d %d lm %d rm %d\n", 57496f60e37SRussell King adj->crtc_hdisplay, 57596f60e37SRussell King adj->crtc_hsync_start, 57696f60e37SRussell King adj->crtc_hsync_end, 57796f60e37SRussell King adj->crtc_htotal, lm, rm); 57896f60e37SRussell King DRM_DEBUG_DRIVER("V: %d %d %d %d tm %d bm %d\n", 57996f60e37SRussell King adj->crtc_vdisplay, 58096f60e37SRussell King adj->crtc_vsync_start, 58196f60e37SRussell King adj->crtc_vsync_end, 58296f60e37SRussell King adj->crtc_vtotal, tm, bm); 58396f60e37SRussell King 584e0ac5e9bSRussell King /* 585e0ac5e9bSRussell King * If we are blanked, we would have disabled the clock. Re-enable 586e0ac5e9bSRussell King * it so that compute_clock() does the right thing. 587e0ac5e9bSRussell King */ 588e0ac5e9bSRussell King if (!IS_ERR(dcrtc->clk) && dpms_blanked(dcrtc->dpms)) 589e0ac5e9bSRussell King WARN_ON(clk_prepare_enable(dcrtc->clk)); 590e0ac5e9bSRussell King 59196f60e37SRussell King /* Now compute the divider for real */ 59242e62ba7SRussell King dcrtc->variant->compute_clock(dcrtc, adj, &sclk); 59396f60e37SRussell King 59496f60e37SRussell King armada_reg_queue_set(regs, i, sclk, LCD_CFG_SCLK_DIV); 59596f60e37SRussell King 59696f60e37SRussell King if (interlaced ^ dcrtc->interlaced) { 59796f60e37SRussell King if (adj->flags & DRM_MODE_FLAG_INTERLACE) 598accbaf6eSGustavo Padovan drm_crtc_vblank_get(&dcrtc->crtc); 59996f60e37SRussell King else 600accbaf6eSGustavo Padovan drm_crtc_vblank_put(&dcrtc->crtc); 60196f60e37SRussell King dcrtc->interlaced = interlaced; 60296f60e37SRussell King } 60396f60e37SRussell King 60496f60e37SRussell King spin_lock_irqsave(&dcrtc->irq_lock, flags); 60596f60e37SRussell King 60696f60e37SRussell King /* Even interlaced/progressive frame */ 60796f60e37SRussell King dcrtc->v[1].spu_v_h_total = adj->crtc_vtotal << 16 | 60896f60e37SRussell King adj->crtc_htotal; 60996f60e37SRussell King dcrtc->v[1].spu_v_porch = tm << 16 | bm; 61096f60e37SRussell King val = adj->crtc_hsync_start; 611662af0d8SRussell King dcrtc->v[1].spu_adv_reg = val << 20 | val | ADV_VSYNCOFFEN | 61242e62ba7SRussell King dcrtc->variant->spu_adv_reg; 61396f60e37SRussell King 61496f60e37SRussell King if (interlaced) { 61596f60e37SRussell King /* Odd interlaced frame */ 61696f60e37SRussell King dcrtc->v[0].spu_v_h_total = dcrtc->v[1].spu_v_h_total + 61796f60e37SRussell King (1 << 16); 61896f60e37SRussell King dcrtc->v[0].spu_v_porch = dcrtc->v[1].spu_v_porch + 1; 61996f60e37SRussell King val = adj->crtc_hsync_start - adj->crtc_htotal / 2; 620662af0d8SRussell King dcrtc->v[0].spu_adv_reg = val << 20 | val | ADV_VSYNCOFFEN | 62142e62ba7SRussell King dcrtc->variant->spu_adv_reg; 62296f60e37SRussell King } else { 62396f60e37SRussell King dcrtc->v[0] = dcrtc->v[1]; 62496f60e37SRussell King } 62596f60e37SRussell King 62696f60e37SRussell King val = adj->crtc_vdisplay << 16 | adj->crtc_hdisplay; 62796f60e37SRussell King 62896f60e37SRussell King armada_reg_queue_set(regs, i, val, LCD_SPU_V_H_ACTIVE); 62996f60e37SRussell King armada_reg_queue_set(regs, i, (lm << 16) | rm, LCD_SPU_H_PORCH); 63096f60e37SRussell King armada_reg_queue_set(regs, i, dcrtc->v[0].spu_v_porch, LCD_SPU_V_PORCH); 63196f60e37SRussell King armada_reg_queue_set(regs, i, dcrtc->v[0].spu_v_h_total, 63296f60e37SRussell King LCD_SPUT_V_H_TOTAL); 63396f60e37SRussell King 63442e62ba7SRussell King if (dcrtc->variant->has_spu_adv_reg) { 63596f60e37SRussell King armada_reg_queue_mod(regs, i, dcrtc->v[0].spu_adv_reg, 63696f60e37SRussell King ADV_VSYNC_L_OFF | ADV_VSYNC_H_OFF | 63796f60e37SRussell King ADV_VSYNCOFFEN, LCD_SPU_ADV_REG); 638662af0d8SRussell King } 63996f60e37SRussell King 64096f60e37SRussell King val = adj->flags & DRM_MODE_FLAG_NVSYNC ? CFG_VSYNC_INV : 0; 64196f60e37SRussell King armada_reg_queue_mod(regs, i, val, CFG_VSYNC_INV, LCD_SPU_DMA_CTRL1); 64296f60e37SRussell King 64396f60e37SRussell King val = dcrtc->spu_iopad_ctrl | armada_drm_crtc_calculate_csc(dcrtc); 64496f60e37SRussell King armada_reg_queue_set(regs, i, val, LCD_SPU_IOPAD_CONTROL); 64596f60e37SRussell King armada_reg_queue_end(regs, i); 64696f60e37SRussell King 64796f60e37SRussell King armada_drm_crtc_update_regs(dcrtc, regs); 64896f60e37SRussell King spin_unlock_irqrestore(&dcrtc->irq_lock, flags); 64996f60e37SRussell King } 65096f60e37SRussell King 65196f60e37SRussell King /* The mode_config.mutex will be held for this call */ 65296f60e37SRussell King static void armada_drm_crtc_disable(struct drm_crtc *crtc) 65396f60e37SRussell King { 65496f60e37SRussell King armada_drm_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); 65528b30433SRussell King 65628b30433SRussell King /* Disable our primary plane when we disable the CRTC. */ 65728b30433SRussell King crtc->primary->funcs->disable_plane(crtc->primary, NULL); 65896f60e37SRussell King } 65996f60e37SRussell King 660*c36045e1SRussell King static void armada_drm_crtc_atomic_begin(struct drm_crtc *crtc, 661*c36045e1SRussell King struct drm_crtc_state *old_crtc_state) 662*c36045e1SRussell King { 663*c36045e1SRussell King struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); 664*c36045e1SRussell King struct armada_plane *dplane; 665*c36045e1SRussell King 666*c36045e1SRussell King DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name); 667*c36045e1SRussell King 668*c36045e1SRussell King /* Wait 100ms for any plane works to complete */ 669*c36045e1SRussell King dplane = drm_to_armada_plane(crtc->primary); 670*c36045e1SRussell King if (WARN_ON(armada_drm_plane_work_wait(dplane, HZ / 10) == 0)) 671*c36045e1SRussell King armada_drm_plane_work_cancel(dcrtc, dplane); 672*c36045e1SRussell King 673*c36045e1SRussell King dcrtc->regs_idx = 0; 674*c36045e1SRussell King dcrtc->regs = dcrtc->atomic_regs; 675*c36045e1SRussell King } 676*c36045e1SRussell King 677*c36045e1SRussell King static void armada_drm_crtc_atomic_flush(struct drm_crtc *crtc, 678*c36045e1SRussell King struct drm_crtc_state *old_crtc_state) 679*c36045e1SRussell King { 680*c36045e1SRussell King struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); 681*c36045e1SRussell King unsigned long flags; 682*c36045e1SRussell King 683*c36045e1SRussell King DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name); 684*c36045e1SRussell King 685*c36045e1SRussell King armada_reg_queue_end(dcrtc->regs, dcrtc->regs_idx); 686*c36045e1SRussell King 687*c36045e1SRussell King spin_lock_irqsave(&dcrtc->irq_lock, flags); 688*c36045e1SRussell King armada_drm_crtc_update_regs(dcrtc, dcrtc->regs); 689*c36045e1SRussell King spin_unlock_irqrestore(&dcrtc->irq_lock, flags); 690*c36045e1SRussell King } 691*c36045e1SRussell King 69296f60e37SRussell King static const struct drm_crtc_helper_funcs armada_crtc_helper_funcs = { 69396f60e37SRussell King .dpms = armada_drm_crtc_dpms, 69496f60e37SRussell King .prepare = armada_drm_crtc_prepare, 69596f60e37SRussell King .commit = armada_drm_crtc_commit, 69696f60e37SRussell King .mode_fixup = armada_drm_crtc_mode_fixup, 697*c36045e1SRussell King .mode_set = drm_helper_crtc_mode_set, 698*c36045e1SRussell King .mode_set_nofb = armada_drm_crtc_mode_set_nofb, 699*c36045e1SRussell King .mode_set_base = drm_helper_crtc_mode_set_base, 70096f60e37SRussell King .disable = armada_drm_crtc_disable, 701*c36045e1SRussell King .atomic_begin = armada_drm_crtc_atomic_begin, 702*c36045e1SRussell King .atomic_flush = armada_drm_crtc_atomic_flush, 70396f60e37SRussell King }; 70496f60e37SRussell King 705662af0d8SRussell King static void armada_load_cursor_argb(void __iomem *base, uint32_t *pix, 706662af0d8SRussell King unsigned stride, unsigned width, unsigned height) 707662af0d8SRussell King { 708662af0d8SRussell King uint32_t addr; 709662af0d8SRussell King unsigned y; 710662af0d8SRussell King 711662af0d8SRussell King addr = SRAM_HWC32_RAM1; 712662af0d8SRussell King for (y = 0; y < height; y++) { 713662af0d8SRussell King uint32_t *p = &pix[y * stride]; 714662af0d8SRussell King unsigned x; 715662af0d8SRussell King 716662af0d8SRussell King for (x = 0; x < width; x++, p++) { 717662af0d8SRussell King uint32_t val = *p; 718662af0d8SRussell King 719662af0d8SRussell King val = (val & 0xff00ff00) | 720662af0d8SRussell King (val & 0x000000ff) << 16 | 721662af0d8SRussell King (val & 0x00ff0000) >> 16; 722662af0d8SRussell King 723662af0d8SRussell King writel_relaxed(val, 724662af0d8SRussell King base + LCD_SPU_SRAM_WRDAT); 725662af0d8SRussell King writel_relaxed(addr | SRAM_WRITE, 726662af0d8SRussell King base + LCD_SPU_SRAM_CTRL); 727c39b0695SRussell King readl_relaxed(base + LCD_SPU_HWC_OVSA_HPXL_VLN); 728662af0d8SRussell King addr += 1; 729662af0d8SRussell King if ((addr & 0x00ff) == 0) 730662af0d8SRussell King addr += 0xf00; 731662af0d8SRussell King if ((addr & 0x30ff) == 0) 732662af0d8SRussell King addr = SRAM_HWC32_RAM2; 733662af0d8SRussell King } 734662af0d8SRussell King } 735662af0d8SRussell King } 736662af0d8SRussell King 737662af0d8SRussell King static void armada_drm_crtc_cursor_tran(void __iomem *base) 738662af0d8SRussell King { 739662af0d8SRussell King unsigned addr; 740662af0d8SRussell King 741662af0d8SRussell King for (addr = 0; addr < 256; addr++) { 742662af0d8SRussell King /* write the default value */ 743662af0d8SRussell King writel_relaxed(0x55555555, base + LCD_SPU_SRAM_WRDAT); 744662af0d8SRussell King writel_relaxed(addr | SRAM_WRITE | SRAM_HWC32_TRAN, 745662af0d8SRussell King base + LCD_SPU_SRAM_CTRL); 746662af0d8SRussell King } 747662af0d8SRussell King } 748662af0d8SRussell King 749662af0d8SRussell King static int armada_drm_crtc_cursor_update(struct armada_crtc *dcrtc, bool reload) 750662af0d8SRussell King { 751662af0d8SRussell King uint32_t xoff, xscr, w = dcrtc->cursor_w, s; 752662af0d8SRussell King uint32_t yoff, yscr, h = dcrtc->cursor_h; 753662af0d8SRussell King uint32_t para1; 754662af0d8SRussell King 755662af0d8SRussell King /* 756662af0d8SRussell King * Calculate the visible width and height of the cursor, 757662af0d8SRussell King * screen position, and the position in the cursor bitmap. 758662af0d8SRussell King */ 759662af0d8SRussell King if (dcrtc->cursor_x < 0) { 760662af0d8SRussell King xoff = -dcrtc->cursor_x; 761662af0d8SRussell King xscr = 0; 762662af0d8SRussell King w -= min(xoff, w); 763662af0d8SRussell King } else if (dcrtc->cursor_x + w > dcrtc->crtc.mode.hdisplay) { 764662af0d8SRussell King xoff = 0; 765662af0d8SRussell King xscr = dcrtc->cursor_x; 766662af0d8SRussell King w = max_t(int, dcrtc->crtc.mode.hdisplay - dcrtc->cursor_x, 0); 767662af0d8SRussell King } else { 768662af0d8SRussell King xoff = 0; 769662af0d8SRussell King xscr = dcrtc->cursor_x; 770662af0d8SRussell King } 771662af0d8SRussell King 772662af0d8SRussell King if (dcrtc->cursor_y < 0) { 773662af0d8SRussell King yoff = -dcrtc->cursor_y; 774662af0d8SRussell King yscr = 0; 775662af0d8SRussell King h -= min(yoff, h); 776662af0d8SRussell King } else if (dcrtc->cursor_y + h > dcrtc->crtc.mode.vdisplay) { 777662af0d8SRussell King yoff = 0; 778662af0d8SRussell King yscr = dcrtc->cursor_y; 779662af0d8SRussell King h = max_t(int, dcrtc->crtc.mode.vdisplay - dcrtc->cursor_y, 0); 780662af0d8SRussell King } else { 781662af0d8SRussell King yoff = 0; 782662af0d8SRussell King yscr = dcrtc->cursor_y; 783662af0d8SRussell King } 784662af0d8SRussell King 785662af0d8SRussell King /* On interlaced modes, the vertical cursor size must be halved */ 786662af0d8SRussell King s = dcrtc->cursor_w; 787662af0d8SRussell King if (dcrtc->interlaced) { 788662af0d8SRussell King s *= 2; 789662af0d8SRussell King yscr /= 2; 790662af0d8SRussell King h /= 2; 791662af0d8SRussell King } 792662af0d8SRussell King 793662af0d8SRussell King if (!dcrtc->cursor_obj || !h || !w) { 794662af0d8SRussell King spin_lock_irq(&dcrtc->irq_lock); 795662af0d8SRussell King armada_drm_crtc_disable_irq(dcrtc, DUMB_FRAMEDONE_ENA); 796662af0d8SRussell King dcrtc->cursor_update = false; 797662af0d8SRussell King armada_updatel(0, CFG_HWC_ENA, dcrtc->base + LCD_SPU_DMA_CTRL0); 798662af0d8SRussell King spin_unlock_irq(&dcrtc->irq_lock); 799662af0d8SRussell King return 0; 800662af0d8SRussell King } 801662af0d8SRussell King 802214612f9SRussell King spin_lock_irq(&dcrtc->irq_lock); 803662af0d8SRussell King para1 = readl_relaxed(dcrtc->base + LCD_SPU_SRAM_PARA1); 804662af0d8SRussell King armada_updatel(CFG_CSB_256x32, CFG_CSB_256x32 | CFG_PDWN256x32, 805662af0d8SRussell King dcrtc->base + LCD_SPU_SRAM_PARA1); 806214612f9SRussell King spin_unlock_irq(&dcrtc->irq_lock); 807662af0d8SRussell King 808662af0d8SRussell King /* 809662af0d8SRussell King * Initialize the transparency if the SRAM was powered down. 810662af0d8SRussell King * We must also reload the cursor data as well. 811662af0d8SRussell King */ 812662af0d8SRussell King if (!(para1 & CFG_CSB_256x32)) { 813662af0d8SRussell King armada_drm_crtc_cursor_tran(dcrtc->base); 814662af0d8SRussell King reload = true; 815662af0d8SRussell King } 816662af0d8SRussell King 817662af0d8SRussell King if (dcrtc->cursor_hw_sz != (h << 16 | w)) { 818662af0d8SRussell King spin_lock_irq(&dcrtc->irq_lock); 819662af0d8SRussell King armada_drm_crtc_disable_irq(dcrtc, DUMB_FRAMEDONE_ENA); 820662af0d8SRussell King dcrtc->cursor_update = false; 821662af0d8SRussell King armada_updatel(0, CFG_HWC_ENA, dcrtc->base + LCD_SPU_DMA_CTRL0); 822662af0d8SRussell King spin_unlock_irq(&dcrtc->irq_lock); 823662af0d8SRussell King reload = true; 824662af0d8SRussell King } 825662af0d8SRussell King if (reload) { 826662af0d8SRussell King struct armada_gem_object *obj = dcrtc->cursor_obj; 827662af0d8SRussell King uint32_t *pix; 828662af0d8SRussell King /* Set the top-left corner of the cursor image */ 829662af0d8SRussell King pix = obj->addr; 830662af0d8SRussell King pix += yoff * s + xoff; 831662af0d8SRussell King armada_load_cursor_argb(dcrtc->base, pix, s, w, h); 832662af0d8SRussell King } 833662af0d8SRussell King 834662af0d8SRussell King /* Reload the cursor position, size and enable in the IRQ handler */ 835662af0d8SRussell King spin_lock_irq(&dcrtc->irq_lock); 836662af0d8SRussell King dcrtc->cursor_hw_pos = yscr << 16 | xscr; 837662af0d8SRussell King dcrtc->cursor_hw_sz = h << 16 | w; 838662af0d8SRussell King dcrtc->cursor_update = true; 839662af0d8SRussell King armada_drm_crtc_enable_irq(dcrtc, DUMB_FRAMEDONE_ENA); 840662af0d8SRussell King spin_unlock_irq(&dcrtc->irq_lock); 841662af0d8SRussell King 842662af0d8SRussell King return 0; 843662af0d8SRussell King } 844662af0d8SRussell King 845662af0d8SRussell King static void cursor_update(void *data) 846662af0d8SRussell King { 847662af0d8SRussell King armada_drm_crtc_cursor_update(data, true); 848662af0d8SRussell King } 849662af0d8SRussell King 850662af0d8SRussell King static int armada_drm_crtc_cursor_set(struct drm_crtc *crtc, 851662af0d8SRussell King struct drm_file *file, uint32_t handle, uint32_t w, uint32_t h) 852662af0d8SRussell King { 853662af0d8SRussell King struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); 854662af0d8SRussell King struct armada_gem_object *obj = NULL; 855662af0d8SRussell King int ret; 856662af0d8SRussell King 857662af0d8SRussell King /* If no cursor support, replicate drm's return value */ 85842e62ba7SRussell King if (!dcrtc->variant->has_spu_adv_reg) 859662af0d8SRussell King return -ENXIO; 860662af0d8SRussell King 861662af0d8SRussell King if (handle && w > 0 && h > 0) { 862662af0d8SRussell King /* maximum size is 64x32 or 32x64 */ 863662af0d8SRussell King if (w > 64 || h > 64 || (w > 32 && h > 32)) 864662af0d8SRussell King return -ENOMEM; 865662af0d8SRussell King 866a8ad0bd8SChris Wilson obj = armada_gem_object_lookup(file, handle); 867662af0d8SRussell King if (!obj) 868662af0d8SRussell King return -ENOENT; 869662af0d8SRussell King 870662af0d8SRussell King /* Must be a kernel-mapped object */ 871662af0d8SRussell King if (!obj->addr) { 8724c3cf375SHaneen Mohammed drm_gem_object_put_unlocked(&obj->obj); 873662af0d8SRussell King return -EINVAL; 874662af0d8SRussell King } 875662af0d8SRussell King 876662af0d8SRussell King if (obj->obj.size < w * h * 4) { 877662af0d8SRussell King DRM_ERROR("buffer is too small\n"); 8784c3cf375SHaneen Mohammed drm_gem_object_put_unlocked(&obj->obj); 879662af0d8SRussell King return -ENOMEM; 880662af0d8SRussell King } 881662af0d8SRussell King } 882662af0d8SRussell King 883662af0d8SRussell King if (dcrtc->cursor_obj) { 884662af0d8SRussell King dcrtc->cursor_obj->update = NULL; 885662af0d8SRussell King dcrtc->cursor_obj->update_data = NULL; 8864c3cf375SHaneen Mohammed drm_gem_object_put_unlocked(&dcrtc->cursor_obj->obj); 887662af0d8SRussell King } 888662af0d8SRussell King dcrtc->cursor_obj = obj; 889662af0d8SRussell King dcrtc->cursor_w = w; 890662af0d8SRussell King dcrtc->cursor_h = h; 891662af0d8SRussell King ret = armada_drm_crtc_cursor_update(dcrtc, true); 892662af0d8SRussell King if (obj) { 893662af0d8SRussell King obj->update_data = dcrtc; 894662af0d8SRussell King obj->update = cursor_update; 895662af0d8SRussell King } 896662af0d8SRussell King 897662af0d8SRussell King return ret; 898662af0d8SRussell King } 899662af0d8SRussell King 900662af0d8SRussell King static int armada_drm_crtc_cursor_move(struct drm_crtc *crtc, int x, int y) 901662af0d8SRussell King { 902662af0d8SRussell King struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); 903662af0d8SRussell King int ret; 904662af0d8SRussell King 905662af0d8SRussell King /* If no cursor support, replicate drm's return value */ 90642e62ba7SRussell King if (!dcrtc->variant->has_spu_adv_reg) 907662af0d8SRussell King return -EFAULT; 908662af0d8SRussell King 909662af0d8SRussell King dcrtc->cursor_x = x; 910662af0d8SRussell King dcrtc->cursor_y = y; 911662af0d8SRussell King ret = armada_drm_crtc_cursor_update(dcrtc, false); 912662af0d8SRussell King 913662af0d8SRussell King return ret; 914662af0d8SRussell King } 915662af0d8SRussell King 91696f60e37SRussell King static void armada_drm_crtc_destroy(struct drm_crtc *crtc) 91796f60e37SRussell King { 91896f60e37SRussell King struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); 91996f60e37SRussell King struct armada_private *priv = crtc->dev->dev_private; 92096f60e37SRussell King 921662af0d8SRussell King if (dcrtc->cursor_obj) 9224c3cf375SHaneen Mohammed drm_gem_object_put_unlocked(&dcrtc->cursor_obj->obj); 923662af0d8SRussell King 92496f60e37SRussell King priv->dcrtc[dcrtc->num] = NULL; 92596f60e37SRussell King drm_crtc_cleanup(&dcrtc->crtc); 92696f60e37SRussell King 92796f60e37SRussell King if (!IS_ERR(dcrtc->clk)) 92896f60e37SRussell King clk_disable_unprepare(dcrtc->clk); 92996f60e37SRussell King 930e5d9ddfbSRussell King writel_relaxed(0, dcrtc->base + LCD_SPU_IRQ_ENA); 931e5d9ddfbSRussell King 9329611cb93SRussell King of_node_put(dcrtc->crtc.port); 9339611cb93SRussell King 93496f60e37SRussell King kfree(dcrtc); 93596f60e37SRussell King } 93696f60e37SRussell King 93796f60e37SRussell King /* 93896f60e37SRussell King * The mode_config lock is held here, to prevent races between this 93996f60e37SRussell King * and a mode_set. 94096f60e37SRussell King */ 94196f60e37SRussell King static int armada_drm_crtc_page_flip(struct drm_crtc *crtc, 94241292b1fSDaniel Vetter struct drm_framebuffer *fb, struct drm_pending_vblank_event *event, uint32_t page_flip_flags, 94341292b1fSDaniel Vetter struct drm_modeset_acquire_ctx *ctx) 94496f60e37SRussell King { 94596f60e37SRussell King struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); 946eaa66279SRussell King struct armada_plane_work *work; 94796f60e37SRussell King unsigned i; 94896f60e37SRussell King int ret; 94996f60e37SRussell King 950eaa66279SRussell King work = armada_drm_crtc_alloc_plane_work(dcrtc->crtc.primary); 95196f60e37SRussell King if (!work) 95296f60e37SRussell King return -ENOMEM; 95396f60e37SRussell King 95496f60e37SRussell King work->event = event; 955f4510a27SMatt Roper work->old_fb = dcrtc->crtc.primary->fb; 95696f60e37SRussell King 95796f60e37SRussell King i = armada_drm_crtc_calc_fb(fb, crtc->x, crtc->y, work->regs, 95896f60e37SRussell King dcrtc->interlaced); 95996f60e37SRussell King armada_reg_queue_end(work->regs, i); 96096f60e37SRussell King 96196f60e37SRussell King /* 962c5488307SRussell King * Ensure that we hold a reference on the new framebuffer. 963c5488307SRussell King * This has to match the behaviour in mode_set. 96496f60e37SRussell King */ 965a52ff2a5SHaneen Mohammed drm_framebuffer_get(fb); 96696f60e37SRussell King 967eaa66279SRussell King ret = armada_drm_plane_work_queue(dcrtc, work); 96896f60e37SRussell King if (ret) { 969c5488307SRussell King /* Undo our reference above */ 970a52ff2a5SHaneen Mohammed drm_framebuffer_put(fb); 97196f60e37SRussell King kfree(work); 97296f60e37SRussell King return ret; 97396f60e37SRussell King } 97496f60e37SRussell King 97596f60e37SRussell King /* 976*c36045e1SRussell King * We are in transition to atomic modeset: update the atomic modeset 977*c36045e1SRussell King * state with the new framebuffer to keep the state consistent. 978*c36045e1SRussell King */ 979*c36045e1SRussell King drm_framebuffer_assign(&dcrtc->crtc.primary->state->fb, fb); 980*c36045e1SRussell King 981*c36045e1SRussell King /* 98296f60e37SRussell King * Finally, if the display is blanked, we won't receive an 98396f60e37SRussell King * interrupt, so complete it now. 98496f60e37SRussell King */ 9854b5dda82SRussell King if (dpms_blanked(dcrtc->dpms)) 986ec6fb159SRussell King armada_drm_plane_work_run(dcrtc, dcrtc->crtc.primary); 98796f60e37SRussell King 98896f60e37SRussell King return 0; 98996f60e37SRussell King } 99096f60e37SRussell King 99196f60e37SRussell King static int 99296f60e37SRussell King armada_drm_crtc_set_property(struct drm_crtc *crtc, 99396f60e37SRussell King struct drm_property *property, uint64_t val) 99496f60e37SRussell King { 99596f60e37SRussell King struct armada_private *priv = crtc->dev->dev_private; 99696f60e37SRussell King struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); 99796f60e37SRussell King bool update_csc = false; 99896f60e37SRussell King 99996f60e37SRussell King if (property == priv->csc_yuv_prop) { 100096f60e37SRussell King dcrtc->csc_yuv_mode = val; 100196f60e37SRussell King update_csc = true; 100296f60e37SRussell King } else if (property == priv->csc_rgb_prop) { 100396f60e37SRussell King dcrtc->csc_rgb_mode = val; 100496f60e37SRussell King update_csc = true; 100596f60e37SRussell King } 100696f60e37SRussell King 100796f60e37SRussell King if (update_csc) { 100896f60e37SRussell King uint32_t val; 100996f60e37SRussell King 101096f60e37SRussell King val = dcrtc->spu_iopad_ctrl | 101196f60e37SRussell King armada_drm_crtc_calculate_csc(dcrtc); 101296f60e37SRussell King writel_relaxed(val, dcrtc->base + LCD_SPU_IOPAD_CONTROL); 101396f60e37SRussell King } 101496f60e37SRussell King 101596f60e37SRussell King return 0; 101696f60e37SRussell King } 101796f60e37SRussell King 10185922a7d0SShawn Guo /* These are called under the vbl_lock. */ 10195922a7d0SShawn Guo static int armada_drm_crtc_enable_vblank(struct drm_crtc *crtc) 10205922a7d0SShawn Guo { 10215922a7d0SShawn Guo struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); 102292298c1cSRussell King unsigned long flags; 10235922a7d0SShawn Guo 102492298c1cSRussell King spin_lock_irqsave(&dcrtc->irq_lock, flags); 10255922a7d0SShawn Guo armada_drm_crtc_enable_irq(dcrtc, VSYNC_IRQ_ENA); 102692298c1cSRussell King spin_unlock_irqrestore(&dcrtc->irq_lock, flags); 10275922a7d0SShawn Guo return 0; 10285922a7d0SShawn Guo } 10295922a7d0SShawn Guo 10305922a7d0SShawn Guo static void armada_drm_crtc_disable_vblank(struct drm_crtc *crtc) 10315922a7d0SShawn Guo { 10325922a7d0SShawn Guo struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); 103392298c1cSRussell King unsigned long flags; 10345922a7d0SShawn Guo 103592298c1cSRussell King spin_lock_irqsave(&dcrtc->irq_lock, flags); 10365922a7d0SShawn Guo armada_drm_crtc_disable_irq(dcrtc, VSYNC_IRQ_ENA); 103792298c1cSRussell King spin_unlock_irqrestore(&dcrtc->irq_lock, flags); 10385922a7d0SShawn Guo } 10395922a7d0SShawn Guo 1040a02fb90aSVille Syrjälä static const struct drm_crtc_funcs armada_crtc_funcs = { 1041*c36045e1SRussell King .reset = drm_atomic_helper_crtc_reset, 1042662af0d8SRussell King .cursor_set = armada_drm_crtc_cursor_set, 1043662af0d8SRussell King .cursor_move = armada_drm_crtc_cursor_move, 104496f60e37SRussell King .destroy = armada_drm_crtc_destroy, 104596f60e37SRussell King .set_config = drm_crtc_helper_set_config, 104696f60e37SRussell King .page_flip = armada_drm_crtc_page_flip, 104796f60e37SRussell King .set_property = armada_drm_crtc_set_property, 1048*c36045e1SRussell King .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state, 1049*c36045e1SRussell King .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, 10505922a7d0SShawn Guo .enable_vblank = armada_drm_crtc_enable_vblank, 10515922a7d0SShawn Guo .disable_vblank = armada_drm_crtc_disable_vblank, 105296f60e37SRussell King }; 105396f60e37SRussell King 1054*c36045e1SRussell King static int armada_drm_plane_prepare_fb(struct drm_plane *plane, 1055*c36045e1SRussell King struct drm_plane_state *state) 1056*c36045e1SRussell King { 1057*c36045e1SRussell King DRM_DEBUG_KMS("[PLANE:%d:%s] [FB:%d]\n", 1058*c36045e1SRussell King plane->base.id, plane->name, 1059*c36045e1SRussell King state->fb ? state->fb->base.id : 0); 1060*c36045e1SRussell King 1061*c36045e1SRussell King /* 1062*c36045e1SRussell King * Take a reference on the new framebuffer - we want to 1063*c36045e1SRussell King * hold on to it while the hardware is displaying it. 1064*c36045e1SRussell King */ 1065*c36045e1SRussell King if (state->fb) 1066*c36045e1SRussell King drm_framebuffer_get(state->fb); 1067*c36045e1SRussell King return 0; 1068*c36045e1SRussell King } 1069*c36045e1SRussell King 1070*c36045e1SRussell King static void armada_drm_plane_cleanup_fb(struct drm_plane *plane, 1071*c36045e1SRussell King struct drm_plane_state *old_state) 1072*c36045e1SRussell King { 1073*c36045e1SRussell King DRM_DEBUG_KMS("[PLANE:%d:%s] [FB:%d]\n", 1074*c36045e1SRussell King plane->base.id, plane->name, 1075*c36045e1SRussell King old_state->fb ? old_state->fb->base.id : 0); 1076*c36045e1SRussell King 1077*c36045e1SRussell King if (old_state->fb) 1078*c36045e1SRussell King drm_framebuffer_put(old_state->fb); 1079*c36045e1SRussell King } 1080*c36045e1SRussell King 1081*c36045e1SRussell King static int armada_drm_plane_atomic_check(struct drm_plane *plane, 1082*c36045e1SRussell King struct drm_plane_state *state) 1083*c36045e1SRussell King { 1084*c36045e1SRussell King if (state->fb && !WARN_ON(!state->crtc)) { 1085*c36045e1SRussell King struct drm_crtc *crtc = state->crtc; 1086*c36045e1SRussell King struct drm_crtc_state crtc_state = { 1087*c36045e1SRussell King .crtc = crtc, 1088*c36045e1SRussell King .enable = crtc->enabled, 1089*c36045e1SRussell King .mode = crtc->mode, 1090*c36045e1SRussell King }; 1091*c36045e1SRussell King 1092*c36045e1SRussell King return drm_atomic_helper_check_plane_state(state, &crtc_state, 1093*c36045e1SRussell King 0, INT_MAX, 1094*c36045e1SRussell King true, false); 1095*c36045e1SRussell King } else { 1096*c36045e1SRussell King state->visible = false; 1097*c36045e1SRussell King } 1098*c36045e1SRussell King return 0; 1099*c36045e1SRussell King } 1100*c36045e1SRussell King 1101ecf25d23SRussell King static unsigned int armada_drm_primary_update_state( 1102ecf25d23SRussell King struct drm_plane_state *state, struct armada_regs *regs) 1103950bc137SRussell King { 1104950bc137SRussell King struct armada_plane *dplane = drm_to_armada_plane(state->plane); 1105950bc137SRussell King struct armada_crtc *dcrtc = drm_to_armada_crtc(state->crtc); 1106950bc137SRussell King struct armada_framebuffer *dfb = drm_fb_to_armada_fb(state->fb); 1107950bc137SRussell King bool was_disabled; 1108950bc137SRussell King unsigned int idx = 0; 1109950bc137SRussell King u32 val; 1110950bc137SRussell King 1111950bc137SRussell King val = CFG_GRA_FMT(dfb->fmt) | CFG_GRA_MOD(dfb->mod); 1112950bc137SRussell King if (dfb->fmt > CFG_420) 1113950bc137SRussell King val |= CFG_PALETTE_ENA; 1114950bc137SRussell King if (state->visible) 1115950bc137SRussell King val |= CFG_GRA_ENA; 1116950bc137SRussell King if (drm_rect_width(&state->src) >> 16 != drm_rect_width(&state->dst)) 1117950bc137SRussell King val |= CFG_GRA_HSMOOTH; 1118ecf25d23SRussell King if (dcrtc->interlaced) 1119ecf25d23SRussell King val |= CFG_GRA_FTOGGLE; 1120950bc137SRussell King 1121950bc137SRussell King was_disabled = !(dplane->state.ctrl0 & CFG_GRA_ENA); 1122950bc137SRussell King if (was_disabled) 1123950bc137SRussell King armada_reg_queue_mod(regs, idx, 1124950bc137SRussell King 0, CFG_PDWN64x66, LCD_SPU_SRAM_PARA1); 1125950bc137SRussell King 1126950bc137SRussell King dplane->state.ctrl0 = val; 11270239520eSRussell King dplane->state.src_hw = armada_rect_hw_fp(&state->src); 11280239520eSRussell King dplane->state.dst_hw = armada_rect_hw(&state->dst); 11290239520eSRussell King dplane->state.dst_yx = armada_rect_yx(&state->dst); 1130950bc137SRussell King 1131ecf25d23SRussell King idx += armada_drm_crtc_calc_fb(&dfb->fb, state->src.x1 >> 16, 1132ecf25d23SRussell King state->src.y1 >> 16, regs + idx, 1133950bc137SRussell King dcrtc->interlaced); 1134ecf25d23SRussell King armada_reg_queue_set(regs, idx, dplane->state.dst_yx, 1135ecf25d23SRussell King LCD_SPU_GRA_OVSA_HPXL_VLN); 1136ecf25d23SRussell King armada_reg_queue_set(regs, idx, dplane->state.src_hw, 1137ecf25d23SRussell King LCD_SPU_GRA_HPXL_VLN); 1138ecf25d23SRussell King armada_reg_queue_set(regs, idx, dplane->state.dst_hw, 1139ecf25d23SRussell King LCD_SPU_GZM_HPXL_VLN); 1140ecf25d23SRussell King armada_reg_queue_mod(regs, idx, dplane->state.ctrl0, CFG_GRAFORMAT | 1141ecf25d23SRussell King CFG_GRA_MOD(CFG_SWAPRB | CFG_SWAPUV | 1142ecf25d23SRussell King CFG_SWAPYU | CFG_YUV2RGB) | 1143ecf25d23SRussell King CFG_PALETTE_ENA | CFG_GRA_FTOGGLE | 1144ecf25d23SRussell King CFG_GRA_HSMOOTH | CFG_GRA_ENA, 1145ecf25d23SRussell King LCD_SPU_DMA_CTRL0); 1146950bc137SRussell King 1147950bc137SRussell King dplane->state.vsync_update = !was_disabled; 1148950bc137SRussell King dplane->state.changed = true; 1149ecf25d23SRussell King 1150ecf25d23SRussell King return idx; 1151950bc137SRussell King } 1152950bc137SRussell King 1153*c36045e1SRussell King static void armada_drm_primary_plane_atomic_update(struct drm_plane *plane, 1154*c36045e1SRussell King struct drm_plane_state *old_state) 1155*c36045e1SRussell King { 1156*c36045e1SRussell King struct drm_plane_state *state = plane->state; 1157*c36045e1SRussell King struct armada_crtc *dcrtc; 1158*c36045e1SRussell King struct armada_regs *regs; 1159*c36045e1SRussell King 1160*c36045e1SRussell King DRM_DEBUG_KMS("[PLANE:%d:%s]\n", plane->base.id, plane->name); 1161*c36045e1SRussell King 1162*c36045e1SRussell King if (!state->fb || WARN_ON(!state->crtc)) 1163*c36045e1SRussell King return; 1164*c36045e1SRussell King 1165*c36045e1SRussell King DRM_DEBUG_KMS("[PLANE:%d:%s] is on [CRTC:%d:%s] with [FB:%d] visible %u->%u\n", 1166*c36045e1SRussell King plane->base.id, plane->name, 1167*c36045e1SRussell King state->crtc->base.id, state->crtc->name, 1168*c36045e1SRussell King state->fb->base.id, 1169*c36045e1SRussell King old_state->visible, state->visible); 1170*c36045e1SRussell King 1171*c36045e1SRussell King dcrtc = drm_to_armada_crtc(state->crtc); 1172*c36045e1SRussell King regs = dcrtc->regs + dcrtc->regs_idx; 1173*c36045e1SRussell King 1174*c36045e1SRussell King dcrtc->regs_idx += armada_drm_primary_update_state(state, regs); 1175*c36045e1SRussell King } 1176*c36045e1SRussell King 1177*c36045e1SRussell King static void armada_drm_primary_plane_atomic_disable(struct drm_plane *plane, 1178*c36045e1SRussell King struct drm_plane_state *old_state) 1179950bc137SRussell King { 1180950bc137SRussell King struct armada_plane *dplane = drm_to_armada_plane(plane); 1181*c36045e1SRussell King struct armada_crtc *dcrtc; 1182*c36045e1SRussell King struct armada_regs *regs; 1183*c36045e1SRussell King unsigned int idx = 0; 1184*c36045e1SRussell King 1185*c36045e1SRussell King DRM_DEBUG_KMS("[PLANE:%d:%s]\n", plane->base.id, plane->name); 1186*c36045e1SRussell King 1187*c36045e1SRussell King if (!old_state->crtc) 1188*c36045e1SRussell King return; 1189*c36045e1SRussell King 1190*c36045e1SRussell King DRM_DEBUG_KMS("[PLANE:%d:%s] was on [CRTC:%d:%s] with [FB:%d]\n", 1191*c36045e1SRussell King plane->base.id, plane->name, 1192*c36045e1SRussell King old_state->crtc->base.id, old_state->crtc->name, 1193*c36045e1SRussell King old_state->fb->base.id); 1194*c36045e1SRussell King 1195*c36045e1SRussell King dplane->state.ctrl0 &= ~CFG_GRA_ENA; 1196*c36045e1SRussell King 1197*c36045e1SRussell King dcrtc = drm_to_armada_crtc(old_state->crtc); 1198*c36045e1SRussell King regs = dcrtc->regs + dcrtc->regs_idx; 1199*c36045e1SRussell King 1200*c36045e1SRussell King /* Disable plane and power down most RAMs and FIFOs */ 1201*c36045e1SRussell King armada_reg_queue_mod(regs, idx, 0, CFG_GRA_ENA, LCD_SPU_DMA_CTRL0); 1202*c36045e1SRussell King armada_reg_queue_mod(regs, idx, CFG_PDWN256x32 | CFG_PDWN256x24 | 1203*c36045e1SRussell King CFG_PDWN256x8 | CFG_PDWN32x32 | CFG_PDWN64x66, 1204*c36045e1SRussell King 0, LCD_SPU_SRAM_PARA1); 1205*c36045e1SRussell King 1206*c36045e1SRussell King dcrtc->regs_idx += idx; 1207*c36045e1SRussell King } 1208*c36045e1SRussell King 1209*c36045e1SRussell King static const struct drm_plane_helper_funcs armada_primary_plane_helper_funcs = { 1210*c36045e1SRussell King .prepare_fb = armada_drm_plane_prepare_fb, 1211*c36045e1SRussell King .cleanup_fb = armada_drm_plane_cleanup_fb, 1212*c36045e1SRussell King .atomic_check = armada_drm_plane_atomic_check, 1213*c36045e1SRussell King .atomic_update = armada_drm_primary_plane_atomic_update, 1214*c36045e1SRussell King .atomic_disable = armada_drm_primary_plane_atomic_disable, 121557270b81SVille Syrjälä }; 1216cfd1b63aSRussell King 1217f1f1bffcSRussell King int armada_drm_plane_disable(struct drm_plane *plane, 1218f1f1bffcSRussell King struct drm_modeset_acquire_ctx *ctx) 121928b30433SRussell King { 122028b30433SRussell King struct armada_plane *dplane = drm_to_armada_plane(plane); 1221f1f1bffcSRussell King struct armada_crtc *dcrtc; 1222890ca8dfSRussell King struct armada_plane_work *work; 1223890ca8dfSRussell King unsigned int idx = 0; 1224d76dcc72SRussell King u32 sram_para1, enable_mask; 122528b30433SRussell King 1226f1f1bffcSRussell King if (!plane->crtc) 1227f1f1bffcSRussell King return 0; 1228f1f1bffcSRussell King 122928b30433SRussell King /* 1230890ca8dfSRussell King * Arrange to power down most RAMs and FIFOs if this is the primary 1231890ca8dfSRussell King * plane, otherwise just the YUV FIFOs for the overlay plane. 123228b30433SRussell King */ 123328b30433SRussell King if (plane->type == DRM_PLANE_TYPE_PRIMARY) { 123428b30433SRussell King sram_para1 = CFG_PDWN256x32 | CFG_PDWN256x24 | CFG_PDWN256x8 | 123528b30433SRussell King CFG_PDWN32x32 | CFG_PDWN64x66; 1236d76dcc72SRussell King enable_mask = CFG_GRA_ENA; 123728b30433SRussell King } else { 123828b30433SRussell King sram_para1 = CFG_PDWN16x66 | CFG_PDWN32x66; 1239d76dcc72SRussell King enable_mask = CFG_DMA_ENA; 124028b30433SRussell King } 124128b30433SRussell King 1242d76dcc72SRussell King dplane->state.ctrl0 &= ~enable_mask; 1243d76dcc72SRussell King 1244f1f1bffcSRussell King dcrtc = drm_to_armada_crtc(plane->crtc); 1245f1f1bffcSRussell King 1246890ca8dfSRussell King /* 1247890ca8dfSRussell King * Try to disable the plane and drop our ref on the framebuffer 1248890ca8dfSRussell King * at the next frame update. If we fail for any reason, disable 1249890ca8dfSRussell King * the plane immediately. 1250890ca8dfSRussell King */ 1251890ca8dfSRussell King work = &dplane->works[dplane->next_work]; 1252890ca8dfSRussell King work->fn = armada_drm_crtc_complete_disable_work; 1253890ca8dfSRussell King work->cancel = armada_drm_crtc_complete_disable_work; 1254890ca8dfSRussell King work->old_fb = plane->fb; 1255890ca8dfSRussell King 1256890ca8dfSRussell King armada_reg_queue_mod(work->regs, idx, 1257890ca8dfSRussell King 0, enable_mask, LCD_SPU_DMA_CTRL0); 1258890ca8dfSRussell King armada_reg_queue_mod(work->regs, idx, 1259890ca8dfSRussell King sram_para1, 0, LCD_SPU_SRAM_PARA1); 1260890ca8dfSRussell King armada_reg_queue_end(work->regs, idx); 1261890ca8dfSRussell King 126228b30433SRussell King /* Wait for any preceding work to complete, but don't wedge */ 126328b30433SRussell King if (WARN_ON(!armada_drm_plane_work_wait(dplane, HZ))) 126428b30433SRussell King armada_drm_plane_work_cancel(dcrtc, dplane); 126528b30433SRussell King 1266890ca8dfSRussell King if (armada_drm_plane_work_queue(dcrtc, work)) { 1267890ca8dfSRussell King work->fn(dcrtc, work); 1268890ca8dfSRussell King if (work->old_fb) 1269890ca8dfSRussell King drm_framebuffer_unreference(work->old_fb); 1270890ca8dfSRussell King } 1271890ca8dfSRussell King 1272890ca8dfSRussell King dplane->next_work = !dplane->next_work; 127328b30433SRussell King 127428b30433SRussell King return 0; 127528b30433SRussell King } 127628b30433SRussell King 1277de32301bSRussell King static const struct drm_plane_funcs armada_primary_plane_funcs = { 1278*c36045e1SRussell King .update_plane = drm_plane_helper_update, 1279*c36045e1SRussell King .disable_plane = drm_plane_helper_disable, 1280de32301bSRussell King .destroy = drm_primary_helper_destroy, 1281*c36045e1SRussell King .reset = drm_atomic_helper_plane_reset, 1282*c36045e1SRussell King .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, 1283*c36045e1SRussell King .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, 1284de32301bSRussell King }; 1285de32301bSRussell King 12865740d27fSRussell King int armada_drm_plane_init(struct armada_plane *plane) 12875740d27fSRussell King { 1288d924155dSRussell King unsigned int i; 1289d924155dSRussell King 1290d924155dSRussell King for (i = 0; i < ARRAY_SIZE(plane->works); i++) 1291d924155dSRussell King plane->works[i].plane = &plane->base; 1292d924155dSRussell King 12935740d27fSRussell King init_waitqueue_head(&plane->frame_wait); 12945740d27fSRussell King 12955740d27fSRussell King return 0; 12965740d27fSRussell King } 12975740d27fSRussell King 1298aaaf2f12SArvind Yadav static const struct drm_prop_enum_list armada_drm_csc_yuv_enum_list[] = { 129996f60e37SRussell King { CSC_AUTO, "Auto" }, 130096f60e37SRussell King { CSC_YUV_CCIR601, "CCIR601" }, 130196f60e37SRussell King { CSC_YUV_CCIR709, "CCIR709" }, 130296f60e37SRussell King }; 130396f60e37SRussell King 1304aaaf2f12SArvind Yadav static const struct drm_prop_enum_list armada_drm_csc_rgb_enum_list[] = { 130596f60e37SRussell King { CSC_AUTO, "Auto" }, 130696f60e37SRussell King { CSC_RGB_COMPUTER, "Computer system" }, 130796f60e37SRussell King { CSC_RGB_STUDIO, "Studio" }, 130896f60e37SRussell King }; 130996f60e37SRussell King 131096f60e37SRussell King static int armada_drm_crtc_create_properties(struct drm_device *dev) 131196f60e37SRussell King { 131296f60e37SRussell King struct armada_private *priv = dev->dev_private; 131396f60e37SRussell King 131496f60e37SRussell King if (priv->csc_yuv_prop) 131596f60e37SRussell King return 0; 131696f60e37SRussell King 131796f60e37SRussell King priv->csc_yuv_prop = drm_property_create_enum(dev, 0, 131896f60e37SRussell King "CSC_YUV", armada_drm_csc_yuv_enum_list, 131996f60e37SRussell King ARRAY_SIZE(armada_drm_csc_yuv_enum_list)); 132096f60e37SRussell King priv->csc_rgb_prop = drm_property_create_enum(dev, 0, 132196f60e37SRussell King "CSC_RGB", armada_drm_csc_rgb_enum_list, 132296f60e37SRussell King ARRAY_SIZE(armada_drm_csc_rgb_enum_list)); 132396f60e37SRussell King 132496f60e37SRussell King if (!priv->csc_yuv_prop || !priv->csc_rgb_prop) 132596f60e37SRussell King return -ENOMEM; 132696f60e37SRussell King 132796f60e37SRussell King return 0; 132896f60e37SRussell King } 132996f60e37SRussell King 13300fb2970bSRussell King static int armada_drm_crtc_create(struct drm_device *drm, struct device *dev, 13319611cb93SRussell King struct resource *res, int irq, const struct armada_variant *variant, 13329611cb93SRussell King struct device_node *port) 133396f60e37SRussell King { 1334d8c96083SRussell King struct armada_private *priv = drm->dev_private; 133596f60e37SRussell King struct armada_crtc *dcrtc; 1336de32301bSRussell King struct armada_plane *primary; 133796f60e37SRussell King void __iomem *base; 133896f60e37SRussell King int ret; 133996f60e37SRussell King 1340d8c96083SRussell King ret = armada_drm_crtc_create_properties(drm); 134196f60e37SRussell King if (ret) 134296f60e37SRussell King return ret; 134396f60e37SRussell King 1344a7d7a143SLinus Torvalds base = devm_ioremap_resource(dev, res); 1345c9d53c0fSJingoo Han if (IS_ERR(base)) 1346c9d53c0fSJingoo Han return PTR_ERR(base); 134796f60e37SRussell King 134896f60e37SRussell King dcrtc = kzalloc(sizeof(*dcrtc), GFP_KERNEL); 134996f60e37SRussell King if (!dcrtc) { 135096f60e37SRussell King DRM_ERROR("failed to allocate Armada crtc\n"); 135196f60e37SRussell King return -ENOMEM; 135296f60e37SRussell King } 135396f60e37SRussell King 1354d8c96083SRussell King if (dev != drm->dev) 1355d8c96083SRussell King dev_set_drvdata(dev, dcrtc); 1356d8c96083SRussell King 135742e62ba7SRussell King dcrtc->variant = variant; 135896f60e37SRussell King dcrtc->base = base; 1359d8c96083SRussell King dcrtc->num = drm->mode_config.num_crtc; 136096f60e37SRussell King dcrtc->clk = ERR_PTR(-EINVAL); 136196f60e37SRussell King dcrtc->csc_yuv_mode = CSC_AUTO; 136296f60e37SRussell King dcrtc->csc_rgb_mode = CSC_AUTO; 136396f60e37SRussell King dcrtc->cfg_dumb_ctrl = DUMB24_RGB888_0; 136496f60e37SRussell King dcrtc->spu_iopad_ctrl = CFG_VSCALE_LN_EN | CFG_IOPAD_DUMB24; 136596f60e37SRussell King spin_lock_init(&dcrtc->irq_lock); 136696f60e37SRussell King dcrtc->irq_ena = CLEAN_SPU_IRQ_ISR; 136796f60e37SRussell King 136896f60e37SRussell King /* Initialize some registers which we don't otherwise set */ 136996f60e37SRussell King writel_relaxed(0x00000001, dcrtc->base + LCD_CFG_SCLK_DIV); 137096f60e37SRussell King writel_relaxed(0x00000000, dcrtc->base + LCD_SPU_BLANKCOLOR); 137196f60e37SRussell King writel_relaxed(dcrtc->spu_iopad_ctrl, 137296f60e37SRussell King dcrtc->base + LCD_SPU_IOPAD_CONTROL); 137396f60e37SRussell King writel_relaxed(0x00000000, dcrtc->base + LCD_SPU_SRAM_PARA0); 137496f60e37SRussell King writel_relaxed(CFG_PDWN256x32 | CFG_PDWN256x24 | CFG_PDWN256x8 | 137596f60e37SRussell King CFG_PDWN32x32 | CFG_PDWN16x66 | CFG_PDWN32x66 | 137696f60e37SRussell King CFG_PDWN64x66, dcrtc->base + LCD_SPU_SRAM_PARA1); 137796f60e37SRussell King writel_relaxed(0x2032ff81, dcrtc->base + LCD_SPU_DMA_CTRL1); 1378e5d9ddfbSRussell King writel_relaxed(dcrtc->irq_ena, dcrtc->base + LCD_SPU_IRQ_ENA); 137992298c1cSRussell King readl_relaxed(dcrtc->base + LCD_SPU_IRQ_ISR); 1380e5d9ddfbSRussell King writel_relaxed(0, dcrtc->base + LCD_SPU_IRQ_ISR); 138196f60e37SRussell King 1382e5d9ddfbSRussell King ret = devm_request_irq(dev, irq, armada_drm_irq, 0, "armada_drm_crtc", 1383e5d9ddfbSRussell King dcrtc); 138433cd3c07SRussell King if (ret < 0) 138533cd3c07SRussell King goto err_crtc; 138696f60e37SRussell King 138742e62ba7SRussell King if (dcrtc->variant->init) { 1388d8c96083SRussell King ret = dcrtc->variant->init(dcrtc, dev); 138933cd3c07SRussell King if (ret) 139033cd3c07SRussell King goto err_crtc; 139196f60e37SRussell King } 139296f60e37SRussell King 139396f60e37SRussell King /* Ensure AXI pipeline is enabled */ 139496f60e37SRussell King armada_updatel(CFG_ARBFAST_ENA, 0, dcrtc->base + LCD_SPU_DMA_CTRL0); 139596f60e37SRussell King 139696f60e37SRussell King priv->dcrtc[dcrtc->num] = dcrtc; 139796f60e37SRussell King 13989611cb93SRussell King dcrtc->crtc.port = port; 13991c914cecSRussell King 1400de32301bSRussell King primary = kzalloc(sizeof(*primary), GFP_KERNEL); 140133cd3c07SRussell King if (!primary) { 140233cd3c07SRussell King ret = -ENOMEM; 140333cd3c07SRussell King goto err_crtc; 140433cd3c07SRussell King } 14051c914cecSRussell King 14065740d27fSRussell King ret = armada_drm_plane_init(primary); 14075740d27fSRussell King if (ret) { 14085740d27fSRussell King kfree(primary); 140933cd3c07SRussell King goto err_crtc; 14105740d27fSRussell King } 14115740d27fSRussell King 1412*c36045e1SRussell King drm_plane_helper_add(&primary->base, 1413*c36045e1SRussell King &armada_primary_plane_helper_funcs); 1414*c36045e1SRussell King 1415de32301bSRussell King ret = drm_universal_plane_init(drm, &primary->base, 0, 1416de32301bSRussell King &armada_primary_plane_funcs, 1417de32301bSRussell King armada_primary_formats, 1418de32301bSRussell King ARRAY_SIZE(armada_primary_formats), 1419e6fc3b68SBen Widawsky NULL, 1420b0b3b795SVille Syrjälä DRM_PLANE_TYPE_PRIMARY, NULL); 1421de32301bSRussell King if (ret) { 1422de32301bSRussell King kfree(primary); 142333cd3c07SRussell King goto err_crtc; 1424de32301bSRussell King } 1425de32301bSRussell King 1426de32301bSRussell King ret = drm_crtc_init_with_planes(drm, &dcrtc->crtc, &primary->base, NULL, 1427f9882876SVille Syrjälä &armada_crtc_funcs, NULL); 14281c914cecSRussell King if (ret) 14291c914cecSRussell King goto err_crtc_init; 14301c914cecSRussell King 143196f60e37SRussell King drm_crtc_helper_add(&dcrtc->crtc, &armada_crtc_helper_funcs); 143296f60e37SRussell King 143396f60e37SRussell King drm_object_attach_property(&dcrtc->crtc.base, priv->csc_yuv_prop, 143496f60e37SRussell King dcrtc->csc_yuv_mode); 143596f60e37SRussell King drm_object_attach_property(&dcrtc->crtc.base, priv->csc_rgb_prop, 143696f60e37SRussell King dcrtc->csc_rgb_mode); 143796f60e37SRussell King 1438d8c96083SRussell King return armada_overlay_plane_create(drm, 1 << dcrtc->num); 14391c914cecSRussell King 14401c914cecSRussell King err_crtc_init: 1441de32301bSRussell King primary->base.funcs->destroy(&primary->base); 144233cd3c07SRussell King err_crtc: 144333cd3c07SRussell King kfree(dcrtc); 144433cd3c07SRussell King 14451c914cecSRussell King return ret; 144696f60e37SRussell King } 1447d8c96083SRussell King 1448d8c96083SRussell King static int 1449d8c96083SRussell King armada_lcd_bind(struct device *dev, struct device *master, void *data) 1450d8c96083SRussell King { 1451d8c96083SRussell King struct platform_device *pdev = to_platform_device(dev); 1452d8c96083SRussell King struct drm_device *drm = data; 1453d8c96083SRussell King struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1454d8c96083SRussell King int irq = platform_get_irq(pdev, 0); 1455d8c96083SRussell King const struct armada_variant *variant; 14569611cb93SRussell King struct device_node *port = NULL; 1457d8c96083SRussell King 1458d8c96083SRussell King if (irq < 0) 1459d8c96083SRussell King return irq; 1460d8c96083SRussell King 1461d8c96083SRussell King if (!dev->of_node) { 1462d8c96083SRussell King const struct platform_device_id *id; 1463d8c96083SRussell King 1464d8c96083SRussell King id = platform_get_device_id(pdev); 1465d8c96083SRussell King if (!id) 1466d8c96083SRussell King return -ENXIO; 1467d8c96083SRussell King 1468d8c96083SRussell King variant = (const struct armada_variant *)id->driver_data; 1469d8c96083SRussell King } else { 1470d8c96083SRussell King const struct of_device_id *match; 14719611cb93SRussell King struct device_node *np, *parent = dev->of_node; 1472d8c96083SRussell King 1473d8c96083SRussell King match = of_match_device(dev->driver->of_match_table, dev); 1474d8c96083SRussell King if (!match) 1475d8c96083SRussell King return -ENXIO; 1476d8c96083SRussell King 14779611cb93SRussell King np = of_get_child_by_name(parent, "ports"); 14789611cb93SRussell King if (np) 14799611cb93SRussell King parent = np; 14809611cb93SRussell King port = of_get_child_by_name(parent, "port"); 14819611cb93SRussell King of_node_put(np); 14829611cb93SRussell King if (!port) { 14834bf99144SRob Herring dev_err(dev, "no port node found in %pOF\n", parent); 14849611cb93SRussell King return -ENXIO; 14859611cb93SRussell King } 14869611cb93SRussell King 1487d8c96083SRussell King variant = match->data; 1488d8c96083SRussell King } 1489d8c96083SRussell King 14909611cb93SRussell King return armada_drm_crtc_create(drm, dev, res, irq, variant, port); 1491d8c96083SRussell King } 1492d8c96083SRussell King 1493d8c96083SRussell King static void 1494d8c96083SRussell King armada_lcd_unbind(struct device *dev, struct device *master, void *data) 1495d8c96083SRussell King { 1496d8c96083SRussell King struct armada_crtc *dcrtc = dev_get_drvdata(dev); 1497d8c96083SRussell King 1498d8c96083SRussell King armada_drm_crtc_destroy(&dcrtc->crtc); 1499d8c96083SRussell King } 1500d8c96083SRussell King 1501d8c96083SRussell King static const struct component_ops armada_lcd_ops = { 1502d8c96083SRussell King .bind = armada_lcd_bind, 1503d8c96083SRussell King .unbind = armada_lcd_unbind, 1504d8c96083SRussell King }; 1505d8c96083SRussell King 1506d8c96083SRussell King static int armada_lcd_probe(struct platform_device *pdev) 1507d8c96083SRussell King { 1508d8c96083SRussell King return component_add(&pdev->dev, &armada_lcd_ops); 1509d8c96083SRussell King } 1510d8c96083SRussell King 1511d8c96083SRussell King static int armada_lcd_remove(struct platform_device *pdev) 1512d8c96083SRussell King { 1513d8c96083SRussell King component_del(&pdev->dev, &armada_lcd_ops); 1514d8c96083SRussell King return 0; 1515d8c96083SRussell King } 1516d8c96083SRussell King 151785909716SArvind Yadav static const struct of_device_id armada_lcd_of_match[] = { 1518d8c96083SRussell King { 1519d8c96083SRussell King .compatible = "marvell,dove-lcd", 1520d8c96083SRussell King .data = &armada510_ops, 1521d8c96083SRussell King }, 1522d8c96083SRussell King {} 1523d8c96083SRussell King }; 1524d8c96083SRussell King MODULE_DEVICE_TABLE(of, armada_lcd_of_match); 1525d8c96083SRussell King 1526d8c96083SRussell King static const struct platform_device_id armada_lcd_platform_ids[] = { 1527d8c96083SRussell King { 1528d8c96083SRussell King .name = "armada-lcd", 1529d8c96083SRussell King .driver_data = (unsigned long)&armada510_ops, 1530d8c96083SRussell King }, { 1531d8c96083SRussell King .name = "armada-510-lcd", 1532d8c96083SRussell King .driver_data = (unsigned long)&armada510_ops, 1533d8c96083SRussell King }, 1534d8c96083SRussell King { }, 1535d8c96083SRussell King }; 1536d8c96083SRussell King MODULE_DEVICE_TABLE(platform, armada_lcd_platform_ids); 1537d8c96083SRussell King 1538d8c96083SRussell King struct platform_driver armada_lcd_platform_driver = { 1539d8c96083SRussell King .probe = armada_lcd_probe, 1540d8c96083SRussell King .remove = armada_lcd_remove, 1541d8c96083SRussell King .driver = { 1542d8c96083SRussell King .name = "armada-lcd", 1543d8c96083SRussell King .owner = THIS_MODULE, 1544d8c96083SRussell King .of_match_table = armada_lcd_of_match, 1545d8c96083SRussell King }, 1546d8c96083SRussell King .id_table = armada_lcd_platform_ids, 1547d8c96083SRussell King }; 1548