2019-05-27 14:55:06 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2016-08-19 02:23:01 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Marek Vasut <marex@denx.de>
|
|
|
|
*
|
|
|
|
* This code is based on drivers/video/fbdev/mxsfb.c :
|
|
|
|
* Copyright (C) 2010 Juergen Beisert, Pengutronix
|
|
|
|
* Copyright (C) 2008-2009 Freescale Semiconductor, Inc. All Rights Reserved.
|
|
|
|
* Copyright (C) 2008 Embedded Alley Solutions, Inc All Rights Reserved.
|
|
|
|
*/
|
|
|
|
|
2019-06-30 14:18:54 +08:00
|
|
|
#include <linux/clk.h>
|
2020-07-27 10:06:43 +08:00
|
|
|
#include <linux/io.h>
|
2019-06-30 14:18:54 +08:00
|
|
|
#include <linux/iopoll.h>
|
2020-07-27 10:06:43 +08:00
|
|
|
#include <linux/pm_runtime.h>
|
2020-07-27 10:06:41 +08:00
|
|
|
#include <linux/spinlock.h>
|
2019-06-30 14:18:54 +08:00
|
|
|
|
2020-07-27 10:06:43 +08:00
|
|
|
#include <drm/drm_atomic.h>
|
|
|
|
#include <drm/drm_atomic_helper.h>
|
2020-07-27 10:06:41 +08:00
|
|
|
#include <drm/drm_bridge.h>
|
2016-08-19 02:23:01 +08:00
|
|
|
#include <drm/drm_crtc.h>
|
2020-07-27 10:06:43 +08:00
|
|
|
#include <drm/drm_encoder.h>
|
2016-08-19 02:23:01 +08:00
|
|
|
#include <drm/drm_fb_cma_helper.h>
|
2020-07-27 10:06:41 +08:00
|
|
|
#include <drm/drm_fourcc.h>
|
2016-08-19 02:23:01 +08:00
|
|
|
#include <drm/drm_gem_cma_helper.h>
|
2020-11-21 05:13:06 +08:00
|
|
|
#include <drm/drm_gem_framebuffer_helper.h>
|
2020-07-27 10:06:43 +08:00
|
|
|
#include <drm/drm_plane.h>
|
|
|
|
#include <drm/drm_plane_helper.h>
|
2019-06-30 14:18:54 +08:00
|
|
|
#include <drm/drm_vblank.h>
|
2016-08-19 02:23:01 +08:00
|
|
|
|
|
|
|
#include "mxsfb_drv.h"
|
|
|
|
#include "mxsfb_regs.h"
|
|
|
|
|
2017-05-06 02:01:41 +08:00
|
|
|
/* 1 second delay should be plenty of time for block reset */
|
|
|
|
#define RESET_TIMEOUT 1000000
|
|
|
|
|
2020-07-27 10:06:43 +08:00
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* CRTC
|
|
|
|
*/
|
|
|
|
|
2016-08-19 02:23:01 +08:00
|
|
|
static u32 set_hsync_pulse_width(struct mxsfb_drm_private *mxsfb, u32 val)
|
|
|
|
{
|
|
|
|
return (val & mxsfb->devdata->hs_wdth_mask) <<
|
|
|
|
mxsfb->devdata->hs_wdth_shift;
|
|
|
|
}
|
|
|
|
|
2020-07-27 10:06:52 +08:00
|
|
|
/*
|
|
|
|
* Setup the MXSFB registers for decoding the pixels out of the framebuffer and
|
|
|
|
* outputting them on the bus.
|
|
|
|
*/
|
|
|
|
static void mxsfb_set_formats(struct mxsfb_drm_private *mxsfb)
|
2016-08-19 02:23:01 +08:00
|
|
|
{
|
2020-07-27 10:06:43 +08:00
|
|
|
struct drm_device *drm = mxsfb->drm;
|
|
|
|
const u32 format = mxsfb->crtc.primary->state->fb->format->format;
|
2020-07-27 10:06:52 +08:00
|
|
|
u32 bus_format = MEDIA_BUS_FMT_RGB888_1X24;
|
2016-08-19 02:23:01 +08:00
|
|
|
u32 ctrl, ctrl1;
|
|
|
|
|
2020-07-27 10:06:52 +08:00
|
|
|
if (mxsfb->connector->display_info.num_bus_formats)
|
|
|
|
bus_format = mxsfb->connector->display_info.bus_formats[0];
|
|
|
|
|
|
|
|
DRM_DEV_DEBUG_DRIVER(drm->dev, "Using bus_format: 0x%08X\n",
|
|
|
|
bus_format);
|
|
|
|
|
2016-08-19 02:23:01 +08:00
|
|
|
ctrl = CTRL_BYPASS_COUNT | CTRL_MASTER;
|
|
|
|
|
|
|
|
/* CTRL1 contains IRQ config and status bits, preserve those. */
|
|
|
|
ctrl1 = readl(mxsfb->base + LCDC_CTRL1);
|
|
|
|
ctrl1 &= CTRL1_CUR_FRAME_DONE_IRQ_EN | CTRL1_CUR_FRAME_DONE_IRQ;
|
|
|
|
|
|
|
|
switch (format) {
|
|
|
|
case DRM_FORMAT_RGB565:
|
|
|
|
dev_dbg(drm->dev, "Setting up RGB565 mode\n");
|
2020-07-27 10:06:37 +08:00
|
|
|
ctrl |= CTRL_WORD_LENGTH_16;
|
2016-08-19 02:23:01 +08:00
|
|
|
ctrl1 |= CTRL1_SET_BYTE_PACKAGING(0xf);
|
|
|
|
break;
|
|
|
|
case DRM_FORMAT_XRGB8888:
|
|
|
|
dev_dbg(drm->dev, "Setting up XRGB8888 mode\n");
|
2020-07-27 10:06:37 +08:00
|
|
|
ctrl |= CTRL_WORD_LENGTH_24;
|
2016-08-19 02:23:01 +08:00
|
|
|
/* Do not use packed pixels = one pixel per word instead. */
|
|
|
|
ctrl1 |= CTRL1_SET_BYTE_PACKAGING(0x7);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-12-15 09:28:41 +08:00
|
|
|
switch (bus_format) {
|
|
|
|
case MEDIA_BUS_FMT_RGB565_1X16:
|
2020-07-27 10:06:52 +08:00
|
|
|
ctrl |= CTRL_BUS_WIDTH_16;
|
2016-12-15 09:28:41 +08:00
|
|
|
break;
|
|
|
|
case MEDIA_BUS_FMT_RGB666_1X18:
|
2020-07-27 10:06:52 +08:00
|
|
|
ctrl |= CTRL_BUS_WIDTH_18;
|
2016-12-15 09:28:41 +08:00
|
|
|
break;
|
|
|
|
case MEDIA_BUS_FMT_RGB888_1X24:
|
2020-07-27 10:06:52 +08:00
|
|
|
ctrl |= CTRL_BUS_WIDTH_24;
|
2016-12-15 09:28:41 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dev_err(drm->dev, "Unknown media bus format %d\n", bus_format);
|
|
|
|
break;
|
|
|
|
}
|
2020-07-27 10:06:52 +08:00
|
|
|
|
|
|
|
writel(ctrl1, mxsfb->base + LCDC_CTRL1);
|
|
|
|
writel(ctrl, mxsfb->base + LCDC_CTRL);
|
2016-12-15 09:28:41 +08:00
|
|
|
}
|
|
|
|
|
2016-08-19 02:23:01 +08:00
|
|
|
static void mxsfb_enable_controller(struct mxsfb_drm_private *mxsfb)
|
|
|
|
{
|
|
|
|
u32 reg;
|
|
|
|
|
|
|
|
if (mxsfb->clk_disp_axi)
|
|
|
|
clk_prepare_enable(mxsfb->clk_disp_axi);
|
|
|
|
clk_prepare_enable(mxsfb->clk);
|
|
|
|
|
|
|
|
/* If it was disabled, re-enable the mode again */
|
|
|
|
writel(CTRL_DOTCLK_MODE, mxsfb->base + LCDC_CTRL + REG_SET);
|
|
|
|
|
|
|
|
/* Enable the SYNC signals first, then the DMA engine */
|
|
|
|
reg = readl(mxsfb->base + LCDC_VDCTRL4);
|
|
|
|
reg |= VDCTRL4_SYNC_SIGNALS_ON;
|
|
|
|
writel(reg, mxsfb->base + LCDC_VDCTRL4);
|
|
|
|
|
|
|
|
writel(CTRL_RUN, mxsfb->base + LCDC_CTRL + REG_SET);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mxsfb_disable_controller(struct mxsfb_drm_private *mxsfb)
|
|
|
|
{
|
|
|
|
u32 reg;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Even if we disable the controller here, it will still continue
|
|
|
|
* until its FIFOs are running out of data
|
|
|
|
*/
|
|
|
|
writel(CTRL_DOTCLK_MODE, mxsfb->base + LCDC_CTRL + REG_CLR);
|
|
|
|
|
|
|
|
readl_poll_timeout(mxsfb->base + LCDC_CTRL, reg, !(reg & CTRL_RUN),
|
|
|
|
0, 1000);
|
|
|
|
|
|
|
|
reg = readl(mxsfb->base + LCDC_VDCTRL4);
|
|
|
|
reg &= ~VDCTRL4_SYNC_SIGNALS_ON;
|
|
|
|
writel(reg, mxsfb->base + LCDC_VDCTRL4);
|
|
|
|
|
|
|
|
clk_disable_unprepare(mxsfb->clk);
|
|
|
|
if (mxsfb->clk_disp_axi)
|
|
|
|
clk_disable_unprepare(mxsfb->clk_disp_axi);
|
|
|
|
}
|
|
|
|
|
2017-05-06 02:01:41 +08:00
|
|
|
/*
|
|
|
|
* Clear the bit and poll it cleared. This is usually called with
|
|
|
|
* a reset address and mask being either SFTRST(bit 31) or CLKGATE
|
|
|
|
* (bit 30).
|
|
|
|
*/
|
|
|
|
static int clear_poll_bit(void __iomem *addr, u32 mask)
|
|
|
|
{
|
|
|
|
u32 reg;
|
|
|
|
|
2020-07-27 10:06:40 +08:00
|
|
|
writel(mask, addr + REG_CLR);
|
2017-05-06 02:01:41 +08:00
|
|
|
return readl_poll_timeout(addr, reg, !(reg & mask), 0, RESET_TIMEOUT);
|
|
|
|
}
|
|
|
|
|
2020-07-27 10:06:38 +08:00
|
|
|
static int mxsfb_reset_block(struct mxsfb_drm_private *mxsfb)
|
2017-05-06 02:01:41 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2020-07-27 10:06:40 +08:00
|
|
|
ret = clear_poll_bit(mxsfb->base + LCDC_CTRL, CTRL_SFTRST);
|
2017-05-06 02:01:41 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2020-07-27 10:06:40 +08:00
|
|
|
writel(CTRL_CLKGATE, mxsfb->base + LCDC_CTRL + REG_CLR);
|
2017-05-06 02:01:41 +08:00
|
|
|
|
2020-07-27 10:06:40 +08:00
|
|
|
ret = clear_poll_bit(mxsfb->base + LCDC_CTRL, CTRL_SFTRST);
|
2017-05-06 02:01:41 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2020-07-27 10:06:40 +08:00
|
|
|
return clear_poll_bit(mxsfb->base + LCDC_CTRL, CTRL_CLKGATE);
|
2017-05-06 02:01:41 +08:00
|
|
|
}
|
|
|
|
|
2020-07-27 10:06:54 +08:00
|
|
|
static dma_addr_t mxsfb_get_fb_paddr(struct drm_plane *plane)
|
2018-09-17 21:42:12 +08:00
|
|
|
{
|
2020-07-27 10:06:54 +08:00
|
|
|
struct drm_framebuffer *fb = plane->state->fb;
|
2018-09-17 21:42:12 +08:00
|
|
|
struct drm_gem_cma_object *gem;
|
|
|
|
|
|
|
|
if (!fb)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
gem = drm_fb_cma_get_gem_obj(fb, 0);
|
|
|
|
if (!gem)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return gem->paddr;
|
|
|
|
}
|
|
|
|
|
2016-08-19 02:23:01 +08:00
|
|
|
static void mxsfb_crtc_mode_set_nofb(struct mxsfb_drm_private *mxsfb)
|
|
|
|
{
|
2020-07-27 10:06:43 +08:00
|
|
|
struct drm_device *drm = mxsfb->crtc.dev;
|
|
|
|
struct drm_display_mode *m = &mxsfb->crtc.state->adjusted_mode;
|
2019-08-29 19:30:03 +08:00
|
|
|
u32 bus_flags = mxsfb->connector->display_info.bus_flags;
|
2016-08-19 02:23:01 +08:00
|
|
|
u32 vdctrl0, vsync_pulse_len, hsync_pulse_len;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It seems, you can't re-program the controller if it is still
|
|
|
|
* running. This may lead to shifted pictures (FIFO issue?), so
|
|
|
|
* first stop the controller and drain its FIFOs.
|
|
|
|
*/
|
|
|
|
|
2017-05-06 02:01:41 +08:00
|
|
|
/* Mandatory eLCDIF reset as per the Reference Manual */
|
2020-07-27 10:06:38 +08:00
|
|
|
err = mxsfb_reset_block(mxsfb);
|
2017-05-06 02:01:41 +08:00
|
|
|
if (err)
|
|
|
|
return;
|
|
|
|
|
2016-08-19 02:23:01 +08:00
|
|
|
/* Clear the FIFOs */
|
|
|
|
writel(CTRL1_FIFO_CLEAR, mxsfb->base + LCDC_CTRL1 + REG_SET);
|
|
|
|
|
2020-07-27 10:06:54 +08:00
|
|
|
if (mxsfb->devdata->has_overlay)
|
|
|
|
writel(0, mxsfb->base + LCDC_AS_CTRL);
|
|
|
|
|
2020-07-27 10:06:52 +08:00
|
|
|
mxsfb_set_formats(mxsfb);
|
2016-08-19 02:23:01 +08:00
|
|
|
|
|
|
|
clk_set_rate(mxsfb->clk, m->crtc_clock * 1000);
|
|
|
|
|
2019-08-29 19:30:03 +08:00
|
|
|
if (mxsfb->bridge && mxsfb->bridge->timings)
|
|
|
|
bus_flags = mxsfb->bridge->timings->input_bus_flags;
|
|
|
|
|
2019-08-29 19:30:02 +08:00
|
|
|
DRM_DEV_DEBUG_DRIVER(drm->dev, "Pixel clock: %dkHz (actual: %dkHz)\n",
|
|
|
|
m->crtc_clock,
|
|
|
|
(int)(clk_get_rate(mxsfb->clk) / 1000));
|
|
|
|
DRM_DEV_DEBUG_DRIVER(drm->dev, "Connector bus_flags: 0x%08X\n",
|
|
|
|
bus_flags);
|
|
|
|
DRM_DEV_DEBUG_DRIVER(drm->dev, "Mode flags: 0x%08X\n", m->flags);
|
|
|
|
|
2016-08-19 02:23:01 +08:00
|
|
|
writel(TRANSFER_COUNT_SET_VCOUNT(m->crtc_vdisplay) |
|
|
|
|
TRANSFER_COUNT_SET_HCOUNT(m->crtc_hdisplay),
|
|
|
|
mxsfb->base + mxsfb->devdata->transfer_count);
|
|
|
|
|
|
|
|
vsync_pulse_len = m->crtc_vsync_end - m->crtc_vsync_start;
|
|
|
|
|
|
|
|
vdctrl0 = VDCTRL0_ENABLE_PRESENT | /* Always in DOTCLOCK mode */
|
|
|
|
VDCTRL0_VSYNC_PERIOD_UNIT |
|
|
|
|
VDCTRL0_VSYNC_PULSE_WIDTH_UNIT |
|
|
|
|
VDCTRL0_SET_VSYNC_PULSE_WIDTH(vsync_pulse_len);
|
|
|
|
if (m->flags & DRM_MODE_FLAG_PHSYNC)
|
|
|
|
vdctrl0 |= VDCTRL0_HSYNC_ACT_HIGH;
|
|
|
|
if (m->flags & DRM_MODE_FLAG_PVSYNC)
|
|
|
|
vdctrl0 |= VDCTRL0_VSYNC_ACT_HIGH;
|
2016-12-15 04:48:09 +08:00
|
|
|
/* Make sure Data Enable is high active by default */
|
|
|
|
if (!(bus_flags & DRM_BUS_FLAG_DE_LOW))
|
2016-08-19 02:23:01 +08:00
|
|
|
vdctrl0 |= VDCTRL0_ENABLE_ACT_HIGH;
|
2016-12-15 04:48:09 +08:00
|
|
|
/*
|
2018-09-22 20:02:42 +08:00
|
|
|
* DRM_BUS_FLAG_PIXDATA_DRIVE_ defines are controller centric,
|
2016-12-15 04:48:09 +08:00
|
|
|
* controllers VDCTRL0_DOTCLK is display centric.
|
|
|
|
* Drive on positive edge -> display samples on falling edge
|
2018-09-22 20:02:42 +08:00
|
|
|
* DRM_BUS_FLAG_PIXDATA_DRIVE_POSEDGE -> VDCTRL0_DOTCLK_ACT_FALLING
|
2016-12-15 04:48:09 +08:00
|
|
|
*/
|
2018-09-22 20:02:42 +08:00
|
|
|
if (bus_flags & DRM_BUS_FLAG_PIXDATA_DRIVE_POSEDGE)
|
2016-08-19 02:23:01 +08:00
|
|
|
vdctrl0 |= VDCTRL0_DOTCLK_ACT_FALLING;
|
|
|
|
|
|
|
|
writel(vdctrl0, mxsfb->base + LCDC_VDCTRL0);
|
|
|
|
|
|
|
|
/* Frame length in lines. */
|
|
|
|
writel(m->crtc_vtotal, mxsfb->base + LCDC_VDCTRL1);
|
|
|
|
|
|
|
|
/* Line length in units of clocks or pixels. */
|
|
|
|
hsync_pulse_len = m->crtc_hsync_end - m->crtc_hsync_start;
|
|
|
|
writel(set_hsync_pulse_width(mxsfb, hsync_pulse_len) |
|
|
|
|
VDCTRL2_SET_HSYNC_PERIOD(m->crtc_htotal),
|
|
|
|
mxsfb->base + LCDC_VDCTRL2);
|
|
|
|
|
2017-02-03 05:26:38 +08:00
|
|
|
writel(SET_HOR_WAIT_CNT(m->crtc_htotal - m->crtc_hsync_start) |
|
|
|
|
SET_VERT_WAIT_CNT(m->crtc_vtotal - m->crtc_vsync_start),
|
2016-08-19 02:23:01 +08:00
|
|
|
mxsfb->base + LCDC_VDCTRL3);
|
|
|
|
|
|
|
|
writel(SET_DOTCLK_H_VALID_DATA_CNT(m->hdisplay),
|
|
|
|
mxsfb->base + LCDC_VDCTRL4);
|
|
|
|
}
|
|
|
|
|
2020-07-27 10:06:43 +08:00
|
|
|
static int mxsfb_crtc_atomic_check(struct drm_crtc *crtc,
|
drm/atomic: Pass the full state to CRTC atomic_check
The current atomic helpers have either their object state being passed as
an argument or the full atomic state.
The former is the pattern that was done at first, before switching to the
latter for new hooks or when it was needed.
Let's start convert all the remaining helpers to provide a consistent
interface, starting with the CRTC's atomic_check.
The conversion was done using the coccinelle script below,
built tested on all the drivers and actually tested on vc4.
virtual report
@@
struct drm_crtc_helper_funcs *FUNCS;
struct drm_crtc *crtc;
struct drm_crtc_state *crtc_state;
identifier dev, state;
identifier ret, f;
@@
f(struct drm_device *dev, struct drm_atomic_state *state)
{
<...
- ret = FUNCS->atomic_check(crtc, crtc_state);
+ ret = FUNCS->atomic_check(crtc, state);
...>
}
@@
identifier crtc, new_state;
@@
struct drm_crtc_helper_funcs {
...
- int (*atomic_check)(struct drm_crtc *crtc, struct drm_crtc_state *new_state);
+ int (*atomic_check)(struct drm_crtc *crtc, struct drm_atomic_state *state);
...
}
@ crtc_atomic_func @
identifier helpers;
identifier func;
@@
static struct drm_crtc_helper_funcs helpers = {
...,
.atomic_check = func,
...,
};
@ ignores_new_state @
identifier crtc_atomic_func.func;
identifier crtc, new_state;
@@
int func(struct drm_crtc *crtc,
struct drm_crtc_state *new_state)
{
... when != new_state
}
@ adds_new_state depends on crtc_atomic_func && !ignores_new_state @
identifier crtc_atomic_func.func;
identifier crtc, new_state;
@@
int func(struct drm_crtc *crtc, struct drm_crtc_state *new_state)
{
+ struct drm_crtc_state *new_state = drm_atomic_get_new_crtc_state(state, crtc);
...
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
expression E;
type T;
@@
int func(...)
{
...
- T state = E;
+ T crtc_state = E;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
type T;
@@
int func(...)
{
...
- T state;
+ T crtc_state;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
identifier new_state;
identifier crtc;
@@
int func(struct drm_crtc *crtc,
- struct drm_crtc_state *new_state
+ struct drm_atomic_state *state
)
{ ... }
@@
identifier new_state;
identifier crtc;
@@
int vmw_du_crtc_atomic_check(struct drm_crtc *crtc,
- struct drm_crtc_state *new_state
+ struct drm_atomic_state *state
)
{
+ struct drm_crtc_state *new_state = drm_atomic_get_new_crtc_state(state, crtc);
...
}
@@
identifier new_state;
identifier crtc;
@@
int vmw_du_crtc_atomic_check(struct drm_crtc *crtc,
- struct drm_crtc_state *new_state
+ struct drm_atomic_state *state
);
@ include depends on adds_new_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_new_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20201028123222.1732139-1-maxime@cerno.tech
2020-10-28 20:32:21 +08:00
|
|
|
struct drm_atomic_state *state)
|
2016-08-19 02:23:01 +08:00
|
|
|
{
|
drm/atomic: Pass the full state to CRTC atomic_check
The current atomic helpers have either their object state being passed as
an argument or the full atomic state.
The former is the pattern that was done at first, before switching to the
latter for new hooks or when it was needed.
Let's start convert all the remaining helpers to provide a consistent
interface, starting with the CRTC's atomic_check.
The conversion was done using the coccinelle script below,
built tested on all the drivers and actually tested on vc4.
virtual report
@@
struct drm_crtc_helper_funcs *FUNCS;
struct drm_crtc *crtc;
struct drm_crtc_state *crtc_state;
identifier dev, state;
identifier ret, f;
@@
f(struct drm_device *dev, struct drm_atomic_state *state)
{
<...
- ret = FUNCS->atomic_check(crtc, crtc_state);
+ ret = FUNCS->atomic_check(crtc, state);
...>
}
@@
identifier crtc, new_state;
@@
struct drm_crtc_helper_funcs {
...
- int (*atomic_check)(struct drm_crtc *crtc, struct drm_crtc_state *new_state);
+ int (*atomic_check)(struct drm_crtc *crtc, struct drm_atomic_state *state);
...
}
@ crtc_atomic_func @
identifier helpers;
identifier func;
@@
static struct drm_crtc_helper_funcs helpers = {
...,
.atomic_check = func,
...,
};
@ ignores_new_state @
identifier crtc_atomic_func.func;
identifier crtc, new_state;
@@
int func(struct drm_crtc *crtc,
struct drm_crtc_state *new_state)
{
... when != new_state
}
@ adds_new_state depends on crtc_atomic_func && !ignores_new_state @
identifier crtc_atomic_func.func;
identifier crtc, new_state;
@@
int func(struct drm_crtc *crtc, struct drm_crtc_state *new_state)
{
+ struct drm_crtc_state *new_state = drm_atomic_get_new_crtc_state(state, crtc);
...
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
expression E;
type T;
@@
int func(...)
{
...
- T state = E;
+ T crtc_state = E;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
type T;
@@
int func(...)
{
...
- T state;
+ T crtc_state;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
identifier new_state;
identifier crtc;
@@
int func(struct drm_crtc *crtc,
- struct drm_crtc_state *new_state
+ struct drm_atomic_state *state
)
{ ... }
@@
identifier new_state;
identifier crtc;
@@
int vmw_du_crtc_atomic_check(struct drm_crtc *crtc,
- struct drm_crtc_state *new_state
+ struct drm_atomic_state *state
)
{
+ struct drm_crtc_state *new_state = drm_atomic_get_new_crtc_state(state, crtc);
...
}
@@
identifier new_state;
identifier crtc;
@@
int vmw_du_crtc_atomic_check(struct drm_crtc *crtc,
- struct drm_crtc_state *new_state
+ struct drm_atomic_state *state
);
@ include depends on adds_new_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_new_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20201028123222.1732139-1-maxime@cerno.tech
2020-10-28 20:32:21 +08:00
|
|
|
struct drm_crtc_state *crtc_state = drm_atomic_get_new_crtc_state(state,
|
|
|
|
crtc);
|
|
|
|
bool has_primary = crtc_state->plane_mask &
|
2020-07-27 10:06:43 +08:00
|
|
|
drm_plane_mask(crtc->primary);
|
|
|
|
|
|
|
|
/* The primary plane has to be enabled when the CRTC is active. */
|
drm/atomic: Pass the full state to CRTC atomic_check
The current atomic helpers have either their object state being passed as
an argument or the full atomic state.
The former is the pattern that was done at first, before switching to the
latter for new hooks or when it was needed.
Let's start convert all the remaining helpers to provide a consistent
interface, starting with the CRTC's atomic_check.
The conversion was done using the coccinelle script below,
built tested on all the drivers and actually tested on vc4.
virtual report
@@
struct drm_crtc_helper_funcs *FUNCS;
struct drm_crtc *crtc;
struct drm_crtc_state *crtc_state;
identifier dev, state;
identifier ret, f;
@@
f(struct drm_device *dev, struct drm_atomic_state *state)
{
<...
- ret = FUNCS->atomic_check(crtc, crtc_state);
+ ret = FUNCS->atomic_check(crtc, state);
...>
}
@@
identifier crtc, new_state;
@@
struct drm_crtc_helper_funcs {
...
- int (*atomic_check)(struct drm_crtc *crtc, struct drm_crtc_state *new_state);
+ int (*atomic_check)(struct drm_crtc *crtc, struct drm_atomic_state *state);
...
}
@ crtc_atomic_func @
identifier helpers;
identifier func;
@@
static struct drm_crtc_helper_funcs helpers = {
...,
.atomic_check = func,
...,
};
@ ignores_new_state @
identifier crtc_atomic_func.func;
identifier crtc, new_state;
@@
int func(struct drm_crtc *crtc,
struct drm_crtc_state *new_state)
{
... when != new_state
}
@ adds_new_state depends on crtc_atomic_func && !ignores_new_state @
identifier crtc_atomic_func.func;
identifier crtc, new_state;
@@
int func(struct drm_crtc *crtc, struct drm_crtc_state *new_state)
{
+ struct drm_crtc_state *new_state = drm_atomic_get_new_crtc_state(state, crtc);
...
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
expression E;
type T;
@@
int func(...)
{
...
- T state = E;
+ T crtc_state = E;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
type T;
@@
int func(...)
{
...
- T state;
+ T crtc_state;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
identifier new_state;
identifier crtc;
@@
int func(struct drm_crtc *crtc,
- struct drm_crtc_state *new_state
+ struct drm_atomic_state *state
)
{ ... }
@@
identifier new_state;
identifier crtc;
@@
int vmw_du_crtc_atomic_check(struct drm_crtc *crtc,
- struct drm_crtc_state *new_state
+ struct drm_atomic_state *state
)
{
+ struct drm_crtc_state *new_state = drm_atomic_get_new_crtc_state(state, crtc);
...
}
@@
identifier new_state;
identifier crtc;
@@
int vmw_du_crtc_atomic_check(struct drm_crtc *crtc,
- struct drm_crtc_state *new_state
+ struct drm_atomic_state *state
);
@ include depends on adds_new_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_new_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20201028123222.1732139-1-maxime@cerno.tech
2020-10-28 20:32:21 +08:00
|
|
|
if (crtc_state->active && !has_primary)
|
2020-07-27 10:06:43 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* TODO: Is this needed ? */
|
2020-11-02 21:38:34 +08:00
|
|
|
return drm_atomic_add_affected_planes(state, crtc);
|
2020-07-27 10:06:43 +08:00
|
|
|
}
|
|
|
|
|
2020-07-27 10:06:44 +08:00
|
|
|
static void mxsfb_crtc_atomic_flush(struct drm_crtc *crtc,
|
drm/atomic: Pass the full state to CRTC atomic begin and flush
The current atomic helpers have either their object state being passed as
an argument or the full atomic state.
The former is the pattern that was done at first, before switching to the
latter for new hooks or when it was needed.
Let's start convert all the remaining helpers to provide a consistent
interface, starting with the CRTC's atomic_begin and atomic_flush.
The conversion was done using the coccinelle script below, built tested on
all the drivers and actually tested on vc4.
virtual report
@@
struct drm_crtc_helper_funcs *FUNCS;
identifier old_crtc_state, old_state;
identifier crtc;
identifier f;
@@
f(struct drm_crtc_state *old_crtc_state)
{
...
struct drm_atomic_state *old_state = old_crtc_state->state;
<...
- FUNCS->atomic_begin(crtc, old_crtc_state);
+ FUNCS->atomic_begin(crtc, old_state);
...>
}
@@
struct drm_crtc_helper_funcs *FUNCS;
identifier old_crtc_state, old_state;
identifier crtc;
identifier f;
@@
f(struct drm_crtc_state *old_crtc_state)
{
...
struct drm_atomic_state *old_state = old_crtc_state->state;
<...
- FUNCS->atomic_flush(crtc, old_crtc_state);
+ FUNCS->atomic_flush(crtc, old_state);
...>
}
@@
struct drm_crtc_helper_funcs *FUNCS;
struct drm_crtc *crtc;
struct drm_crtc_state *crtc_state;
identifier dev, state;
identifier f;
@@
f(struct drm_device *dev, struct drm_atomic_state *state, ...)
{
<...
- FUNCS->atomic_begin(crtc, crtc_state);
+ FUNCS->atomic_begin(crtc, state);
...>
}
@@
struct drm_crtc_helper_funcs *FUNCS;
struct drm_crtc *crtc;
struct drm_crtc_state *crtc_state;
identifier dev, state;
identifier f;
@@
f(struct drm_device *dev, struct drm_atomic_state *state, ...)
{
<...
- FUNCS->atomic_flush(crtc, crtc_state);
+ FUNCS->atomic_flush(crtc, state);
...>
}
@@
identifier crtc, old_state;
@@
struct drm_crtc_helper_funcs {
...
- void (*atomic_begin)(struct drm_crtc *crtc, struct drm_crtc_state *old_state);
+ void (*atomic_begin)(struct drm_crtc *crtc, struct drm_atomic_state *state);
...
- void (*atomic_flush)(struct drm_crtc *crtc, struct drm_crtc_state *old_state);
+ void (*atomic_flush)(struct drm_crtc *crtc, struct drm_atomic_state *state);
...
}
@ crtc_atomic_func @
identifier helpers;
identifier func;
@@
(
static struct drm_crtc_helper_funcs helpers = {
...,
.atomic_begin = func,
...,
};
|
static struct drm_crtc_helper_funcs helpers = {
...,
.atomic_flush = func,
...,
};
)
@ ignores_old_state @
identifier crtc_atomic_func.func;
identifier crtc, old_state;
@@
void func(struct drm_crtc *crtc,
struct drm_crtc_state *old_state)
{
... when != old_state
}
@ adds_old_state depends on crtc_atomic_func && !ignores_old_state @
identifier crtc_atomic_func.func;
identifier crtc, old_state;
@@
void func(struct drm_crtc *crtc, struct drm_crtc_state *old_state)
{
+ struct drm_crtc_state *old_state = drm_atomic_get_old_crtc_state(state, crtc);
...
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
expression E;
type T;
@@
void func(...)
{
...
- T state = E;
+ T crtc_state = E;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
type T;
@@
void func(...)
{
...
- T state;
+ T crtc_state;
<+...
- state
+ crtc_state
...+>
}
@@
identifier old_state;
identifier crtc;
@@
void vc4_hvs_atomic_flush(struct drm_crtc *crtc,
- struct drm_crtc_state *old_state
+ struct drm_atomic_state *state
)
{
+ struct drm_crtc_state *old_state = drm_atomic_get_old_crtc_state(state, crtc);
...
}
@@
identifier old_state;
identifier crtc;
@@
void vc4_hvs_atomic_flush(struct drm_crtc *crtc,
- struct drm_crtc_state *old_state
+ struct drm_atomic_state *state
);
@@
identifier old_state;
identifier crtc;
@@
void vmw_du_crtc_atomic_begin(struct drm_crtc *crtc,
- struct drm_crtc_state *old_state
+ struct drm_atomic_state *state
)
{
...
}
@@
identifier old_state;
identifier crtc;
@@
void vmw_du_crtc_atomic_begin(struct drm_crtc *crtc,
- struct drm_crtc_state *old_state
+ struct drm_atomic_state *state
);
@@
identifier old_state;
identifier crtc;
@@
void vmw_du_crtc_atomic_flush(struct drm_crtc *crtc,
- struct drm_crtc_state *old_state
+ struct drm_atomic_state *state
)
{
...
}
@@
identifier old_state;
identifier crtc;
@@
void vmw_du_crtc_atomic_flush(struct drm_crtc *crtc,
- struct drm_crtc_state *old_state
+ struct drm_atomic_state *state
);
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
identifier old_state;
identifier crtc;
@@
void func(struct drm_crtc *crtc,
- struct drm_crtc_state *old_state
+ struct drm_atomic_state *state
)
{ ... }
@ include depends on adds_old_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_old_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20201028123222.1732139-2-maxime@cerno.tech
2020-10-28 20:32:22 +08:00
|
|
|
struct drm_atomic_state *state)
|
2020-07-27 10:06:44 +08:00
|
|
|
{
|
|
|
|
struct drm_pending_vblank_event *event;
|
|
|
|
|
|
|
|
event = crtc->state->event;
|
|
|
|
crtc->state->event = NULL;
|
|
|
|
|
|
|
|
if (!event)
|
|
|
|
return;
|
|
|
|
|
|
|
|
spin_lock_irq(&crtc->dev->event_lock);
|
|
|
|
if (drm_crtc_vblank_get(crtc) == 0)
|
|
|
|
drm_crtc_arm_vblank_event(crtc, event);
|
|
|
|
else
|
|
|
|
drm_crtc_send_vblank_event(crtc, event);
|
|
|
|
spin_unlock_irq(&crtc->dev->event_lock);
|
|
|
|
}
|
|
|
|
|
2020-07-27 10:06:43 +08:00
|
|
|
static void mxsfb_crtc_atomic_enable(struct drm_crtc *crtc,
|
drm/atomic: Pass the full state to CRTC atomic enable/disable
If the CRTC driver ever needs to access the full DRM state, it can't do so
at atomic_enable / atomic_disable time since drm_atomic_helper_swap_state
will have cleared the pointer from the struct drm_crtc_state to the struct
drm_atomic_state before calling those hooks.
In order to allow that, let's pass the full DRM state to atomic_enable and
atomic_disable. The conversion was done using the coccinelle script below,
built tested on all the drivers and actually tested on vc4.
virtual report
@@
struct drm_crtc_helper_funcs *FUNCS;
identifier dev, state;
identifier crtc, crtc_state;
@@
disable_outputs(struct drm_device *dev, struct drm_atomic_state *state)
{
<...
- FUNCS->atomic_disable(crtc, crtc_state);
+ FUNCS->atomic_disable(crtc, state);
...>
}
@@
struct drm_crtc_helper_funcs *FUNCS;
identifier dev, state;
identifier crtc, crtc_state;
@@
drm_atomic_helper_commit_modeset_enables(struct drm_device *dev, struct drm_atomic_state *state)
{
<...
- FUNCS->atomic_enable(crtc, crtc_state);
+ FUNCS->atomic_enable(crtc, state);
...>
}
@@
identifier crtc, old_state;
@@
struct drm_crtc_helper_funcs {
...
- void (*atomic_enable)(struct drm_crtc *crtc, struct drm_crtc_state *old_state);
+ void (*atomic_enable)(struct drm_crtc *crtc, struct drm_atomic_state *state);
...
- void (*atomic_disable)(struct drm_crtc *crtc, struct drm_crtc_state *old_state);
+ void (*atomic_disable)(struct drm_crtc *crtc, struct drm_atomic_state *state);
...
}
@ crtc_atomic_func @
identifier helpers;
identifier func;
@@
(
static struct drm_crtc_helper_funcs helpers = {
...,
.atomic_enable = func,
...,
};
|
static struct drm_crtc_helper_funcs helpers = {
...,
.atomic_disable = func,
...,
};
)
@ ignores_old_state @
identifier crtc_atomic_func.func;
identifier crtc, old_state;
@@
void func(struct drm_crtc *crtc,
struct drm_crtc_state *old_state)
{
... when != old_state
}
@ adds_old_state depends on crtc_atomic_func && !ignores_old_state @
identifier crtc_atomic_func.func;
identifier crtc, old_state;
@@
void func(struct drm_crtc *crtc, struct drm_crtc_state *old_state)
{
+ struct drm_crtc_state *old_state = drm_atomic_get_old_crtc_state(state, crtc);
...
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
expression E;
type T;
@@
void func(...)
{
...
- T state = E;
+ T crtc_state = E;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
type T;
@@
void func(...)
{
...
- T state;
+ T crtc_state;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
identifier old_state;
identifier crtc;
@@
void func(struct drm_crtc *crtc,
- struct drm_crtc_state *old_state
+ struct drm_atomic_state *state
)
{ ... }
@ include depends on adds_old_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_old_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/845aa10ef171fc0ea060495efef142a0c13f7870.1602161031.git-series.maxime@cerno.tech
2020-10-08 20:44:08 +08:00
|
|
|
struct drm_atomic_state *state)
|
2020-07-27 10:06:43 +08:00
|
|
|
{
|
|
|
|
struct mxsfb_drm_private *mxsfb = to_mxsfb_drm_private(crtc->dev);
|
|
|
|
struct drm_device *drm = mxsfb->drm;
|
2018-09-17 21:42:12 +08:00
|
|
|
dma_addr_t paddr;
|
|
|
|
|
2020-07-27 10:06:43 +08:00
|
|
|
pm_runtime_get_sync(drm->dev);
|
2018-09-17 21:42:11 +08:00
|
|
|
mxsfb_enable_axi_clk(mxsfb);
|
2020-07-27 10:06:46 +08:00
|
|
|
|
|
|
|
drm_crtc_vblank_on(crtc);
|
|
|
|
|
2016-08-19 02:23:01 +08:00
|
|
|
mxsfb_crtc_mode_set_nofb(mxsfb);
|
2018-09-17 21:42:12 +08:00
|
|
|
|
|
|
|
/* Write cur_buf as well to avoid an initial corrupt frame */
|
2020-07-27 10:06:54 +08:00
|
|
|
paddr = mxsfb_get_fb_paddr(crtc->primary);
|
2018-09-17 21:42:12 +08:00
|
|
|
if (paddr) {
|
|
|
|
writel(paddr, mxsfb->base + mxsfb->devdata->cur_buf);
|
|
|
|
writel(paddr, mxsfb->base + mxsfb->devdata->next_buf);
|
|
|
|
}
|
|
|
|
|
2016-08-19 02:23:01 +08:00
|
|
|
mxsfb_enable_controller(mxsfb);
|
|
|
|
}
|
|
|
|
|
2020-07-27 10:06:43 +08:00
|
|
|
static void mxsfb_crtc_atomic_disable(struct drm_crtc *crtc,
|
drm/atomic: Pass the full state to CRTC atomic enable/disable
If the CRTC driver ever needs to access the full DRM state, it can't do so
at atomic_enable / atomic_disable time since drm_atomic_helper_swap_state
will have cleared the pointer from the struct drm_crtc_state to the struct
drm_atomic_state before calling those hooks.
In order to allow that, let's pass the full DRM state to atomic_enable and
atomic_disable. The conversion was done using the coccinelle script below,
built tested on all the drivers and actually tested on vc4.
virtual report
@@
struct drm_crtc_helper_funcs *FUNCS;
identifier dev, state;
identifier crtc, crtc_state;
@@
disable_outputs(struct drm_device *dev, struct drm_atomic_state *state)
{
<...
- FUNCS->atomic_disable(crtc, crtc_state);
+ FUNCS->atomic_disable(crtc, state);
...>
}
@@
struct drm_crtc_helper_funcs *FUNCS;
identifier dev, state;
identifier crtc, crtc_state;
@@
drm_atomic_helper_commit_modeset_enables(struct drm_device *dev, struct drm_atomic_state *state)
{
<...
- FUNCS->atomic_enable(crtc, crtc_state);
+ FUNCS->atomic_enable(crtc, state);
...>
}
@@
identifier crtc, old_state;
@@
struct drm_crtc_helper_funcs {
...
- void (*atomic_enable)(struct drm_crtc *crtc, struct drm_crtc_state *old_state);
+ void (*atomic_enable)(struct drm_crtc *crtc, struct drm_atomic_state *state);
...
- void (*atomic_disable)(struct drm_crtc *crtc, struct drm_crtc_state *old_state);
+ void (*atomic_disable)(struct drm_crtc *crtc, struct drm_atomic_state *state);
...
}
@ crtc_atomic_func @
identifier helpers;
identifier func;
@@
(
static struct drm_crtc_helper_funcs helpers = {
...,
.atomic_enable = func,
...,
};
|
static struct drm_crtc_helper_funcs helpers = {
...,
.atomic_disable = func,
...,
};
)
@ ignores_old_state @
identifier crtc_atomic_func.func;
identifier crtc, old_state;
@@
void func(struct drm_crtc *crtc,
struct drm_crtc_state *old_state)
{
... when != old_state
}
@ adds_old_state depends on crtc_atomic_func && !ignores_old_state @
identifier crtc_atomic_func.func;
identifier crtc, old_state;
@@
void func(struct drm_crtc *crtc, struct drm_crtc_state *old_state)
{
+ struct drm_crtc_state *old_state = drm_atomic_get_old_crtc_state(state, crtc);
...
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
expression E;
type T;
@@
void func(...)
{
...
- T state = E;
+ T crtc_state = E;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
type T;
@@
void func(...)
{
...
- T state;
+ T crtc_state;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
identifier old_state;
identifier crtc;
@@
void func(struct drm_crtc *crtc,
- struct drm_crtc_state *old_state
+ struct drm_atomic_state *state
)
{ ... }
@ include depends on adds_old_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_old_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/845aa10ef171fc0ea060495efef142a0c13f7870.1602161031.git-series.maxime@cerno.tech
2020-10-08 20:44:08 +08:00
|
|
|
struct drm_atomic_state *state)
|
2016-08-19 02:23:01 +08:00
|
|
|
{
|
2020-07-27 10:06:43 +08:00
|
|
|
struct mxsfb_drm_private *mxsfb = to_mxsfb_drm_private(crtc->dev);
|
|
|
|
struct drm_device *drm = mxsfb->drm;
|
|
|
|
struct drm_pending_vblank_event *event;
|
|
|
|
|
2016-08-19 02:23:01 +08:00
|
|
|
mxsfb_disable_controller(mxsfb);
|
2020-07-27 10:06:43 +08:00
|
|
|
|
|
|
|
spin_lock_irq(&drm->event_lock);
|
|
|
|
event = crtc->state->event;
|
|
|
|
if (event) {
|
|
|
|
crtc->state->event = NULL;
|
|
|
|
drm_crtc_send_vblank_event(crtc, event);
|
|
|
|
}
|
|
|
|
spin_unlock_irq(&drm->event_lock);
|
2020-07-27 10:06:45 +08:00
|
|
|
|
2020-07-27 10:06:46 +08:00
|
|
|
drm_crtc_vblank_off(crtc);
|
|
|
|
|
2020-07-27 10:06:45 +08:00
|
|
|
mxsfb_disable_axi_clk(mxsfb);
|
|
|
|
pm_runtime_put_sync(drm->dev);
|
2020-07-27 10:06:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mxsfb_crtc_enable_vblank(struct drm_crtc *crtc)
|
|
|
|
{
|
|
|
|
struct mxsfb_drm_private *mxsfb = to_mxsfb_drm_private(crtc->dev);
|
|
|
|
|
|
|
|
/* Clear and enable VBLANK IRQ */
|
|
|
|
writel(CTRL1_CUR_FRAME_DONE_IRQ, mxsfb->base + LCDC_CTRL1 + REG_CLR);
|
|
|
|
writel(CTRL1_CUR_FRAME_DONE_IRQ_EN, mxsfb->base + LCDC_CTRL1 + REG_SET);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mxsfb_crtc_disable_vblank(struct drm_crtc *crtc)
|
|
|
|
{
|
|
|
|
struct mxsfb_drm_private *mxsfb = to_mxsfb_drm_private(crtc->dev);
|
|
|
|
|
|
|
|
/* Disable and clear VBLANK IRQ */
|
|
|
|
writel(CTRL1_CUR_FRAME_DONE_IRQ_EN, mxsfb->base + LCDC_CTRL1 + REG_CLR);
|
|
|
|
writel(CTRL1_CUR_FRAME_DONE_IRQ, mxsfb->base + LCDC_CTRL1 + REG_CLR);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct drm_crtc_helper_funcs mxsfb_crtc_helper_funcs = {
|
|
|
|
.atomic_check = mxsfb_crtc_atomic_check,
|
2020-07-27 10:06:44 +08:00
|
|
|
.atomic_flush = mxsfb_crtc_atomic_flush,
|
2020-07-27 10:06:43 +08:00
|
|
|
.atomic_enable = mxsfb_crtc_atomic_enable,
|
|
|
|
.atomic_disable = mxsfb_crtc_atomic_disable,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct drm_crtc_funcs mxsfb_crtc_funcs = {
|
|
|
|
.reset = drm_atomic_helper_crtc_reset,
|
|
|
|
.destroy = drm_crtc_cleanup,
|
|
|
|
.set_config = drm_atomic_helper_set_config,
|
|
|
|
.page_flip = drm_atomic_helper_page_flip,
|
|
|
|
.atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
|
|
|
|
.atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
|
|
|
|
.enable_vblank = mxsfb_crtc_enable_vblank,
|
|
|
|
.disable_vblank = mxsfb_crtc_disable_vblank,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* Encoder
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const struct drm_encoder_funcs mxsfb_encoder_funcs = {
|
|
|
|
.destroy = drm_encoder_cleanup,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* Planes
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int mxsfb_plane_atomic_check(struct drm_plane *plane,
|
|
|
|
struct drm_plane_state *plane_state)
|
|
|
|
{
|
|
|
|
struct mxsfb_drm_private *mxsfb = to_mxsfb_drm_private(plane->dev);
|
|
|
|
struct drm_crtc_state *crtc_state;
|
|
|
|
|
|
|
|
crtc_state = drm_atomic_get_new_crtc_state(plane_state->state,
|
|
|
|
&mxsfb->crtc);
|
|
|
|
|
|
|
|
return drm_atomic_helper_check_plane_state(plane_state, crtc_state,
|
|
|
|
DRM_PLANE_HELPER_NO_SCALING,
|
|
|
|
DRM_PLANE_HELPER_NO_SCALING,
|
|
|
|
false, true);
|
2016-08-19 02:23:01 +08:00
|
|
|
}
|
|
|
|
|
2020-07-27 10:06:54 +08:00
|
|
|
static void mxsfb_plane_primary_atomic_update(struct drm_plane *plane,
|
|
|
|
struct drm_plane_state *old_pstate)
|
2016-08-19 02:23:01 +08:00
|
|
|
{
|
2020-07-27 10:06:43 +08:00
|
|
|
struct mxsfb_drm_private *mxsfb = to_mxsfb_drm_private(plane->dev);
|
2018-09-17 21:42:12 +08:00
|
|
|
dma_addr_t paddr;
|
2016-08-19 02:23:01 +08:00
|
|
|
|
2020-07-27 10:06:54 +08:00
|
|
|
paddr = mxsfb_get_fb_paddr(plane);
|
2020-07-27 10:06:45 +08:00
|
|
|
if (paddr)
|
2018-09-17 21:42:12 +08:00
|
|
|
writel(paddr, mxsfb->base + mxsfb->devdata->next_buf);
|
2016-08-19 02:23:01 +08:00
|
|
|
}
|
2020-07-27 10:06:43 +08:00
|
|
|
|
2020-07-27 10:06:54 +08:00
|
|
|
static void mxsfb_plane_overlay_atomic_update(struct drm_plane *plane,
|
|
|
|
struct drm_plane_state *old_pstate)
|
|
|
|
{
|
|
|
|
struct mxsfb_drm_private *mxsfb = to_mxsfb_drm_private(plane->dev);
|
|
|
|
struct drm_plane_state *state = plane->state;
|
|
|
|
dma_addr_t paddr;
|
|
|
|
u32 ctrl;
|
|
|
|
|
|
|
|
paddr = mxsfb_get_fb_paddr(plane);
|
|
|
|
if (!paddr) {
|
|
|
|
writel(0, mxsfb->base + LCDC_AS_CTRL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* HACK: The hardware seems to output 64 bytes of data of unknown
|
|
|
|
* origin, and then to proceed with the framebuffer. Until the reason
|
|
|
|
* is understood, live with the 16 initial invalid pixels on the first
|
|
|
|
* line and start 64 bytes within the framebuffer.
|
|
|
|
*/
|
|
|
|
paddr += 64;
|
|
|
|
|
|
|
|
writel(paddr, mxsfb->base + LCDC_AS_NEXT_BUF);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the plane was previously disabled, write LCDC_AS_BUF as well to
|
|
|
|
* provide the first buffer.
|
|
|
|
*/
|
|
|
|
if (!old_pstate->fb)
|
|
|
|
writel(paddr, mxsfb->base + LCDC_AS_BUF);
|
|
|
|
|
|
|
|
ctrl = AS_CTRL_AS_ENABLE | AS_CTRL_ALPHA(255);
|
|
|
|
|
|
|
|
switch (state->fb->format->format) {
|
|
|
|
case DRM_FORMAT_XRGB4444:
|
|
|
|
ctrl |= AS_CTRL_FORMAT_RGB444 | AS_CTRL_ALPHA_CTRL_OVERRIDE;
|
|
|
|
break;
|
|
|
|
case DRM_FORMAT_ARGB4444:
|
|
|
|
ctrl |= AS_CTRL_FORMAT_ARGB4444 | AS_CTRL_ALPHA_CTRL_EMBEDDED;
|
|
|
|
break;
|
|
|
|
case DRM_FORMAT_XRGB1555:
|
|
|
|
ctrl |= AS_CTRL_FORMAT_RGB555 | AS_CTRL_ALPHA_CTRL_OVERRIDE;
|
|
|
|
break;
|
|
|
|
case DRM_FORMAT_ARGB1555:
|
|
|
|
ctrl |= AS_CTRL_FORMAT_ARGB1555 | AS_CTRL_ALPHA_CTRL_EMBEDDED;
|
|
|
|
break;
|
|
|
|
case DRM_FORMAT_RGB565:
|
|
|
|
ctrl |= AS_CTRL_FORMAT_RGB565 | AS_CTRL_ALPHA_CTRL_OVERRIDE;
|
|
|
|
break;
|
|
|
|
case DRM_FORMAT_XRGB8888:
|
|
|
|
ctrl |= AS_CTRL_FORMAT_RGB888 | AS_CTRL_ALPHA_CTRL_OVERRIDE;
|
|
|
|
break;
|
|
|
|
case DRM_FORMAT_ARGB8888:
|
|
|
|
ctrl |= AS_CTRL_FORMAT_ARGB8888 | AS_CTRL_ALPHA_CTRL_EMBEDDED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
writel(ctrl, mxsfb->base + LCDC_AS_CTRL);
|
|
|
|
}
|
|
|
|
|
2020-11-09 05:00:01 +08:00
|
|
|
static bool mxsfb_format_mod_supported(struct drm_plane *plane,
|
|
|
|
uint32_t format,
|
|
|
|
uint64_t modifier)
|
|
|
|
{
|
|
|
|
return modifier == DRM_FORMAT_MOD_LINEAR;
|
|
|
|
}
|
|
|
|
|
2020-07-27 10:06:54 +08:00
|
|
|
static const struct drm_plane_helper_funcs mxsfb_plane_primary_helper_funcs = {
|
2020-11-21 05:13:06 +08:00
|
|
|
.prepare_fb = drm_gem_fb_prepare_fb,
|
2020-07-27 10:06:54 +08:00
|
|
|
.atomic_check = mxsfb_plane_atomic_check,
|
|
|
|
.atomic_update = mxsfb_plane_primary_atomic_update,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct drm_plane_helper_funcs mxsfb_plane_overlay_helper_funcs = {
|
2020-11-21 05:13:06 +08:00
|
|
|
.prepare_fb = drm_gem_fb_prepare_fb,
|
2020-07-27 10:06:43 +08:00
|
|
|
.atomic_check = mxsfb_plane_atomic_check,
|
2020-07-27 10:06:54 +08:00
|
|
|
.atomic_update = mxsfb_plane_overlay_atomic_update,
|
2020-07-27 10:06:43 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct drm_plane_funcs mxsfb_plane_funcs = {
|
2020-11-09 05:00:01 +08:00
|
|
|
.format_mod_supported = mxsfb_format_mod_supported,
|
2020-07-27 10:06:43 +08:00
|
|
|
.update_plane = drm_atomic_helper_update_plane,
|
|
|
|
.disable_plane = drm_atomic_helper_disable_plane,
|
|
|
|
.destroy = drm_plane_cleanup,
|
|
|
|
.reset = drm_atomic_helper_plane_reset,
|
|
|
|
.atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
|
|
|
|
.atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
|
|
|
|
};
|
|
|
|
|
2020-07-27 10:06:54 +08:00
|
|
|
static const uint32_t mxsfb_primary_plane_formats[] = {
|
|
|
|
DRM_FORMAT_RGB565,
|
|
|
|
DRM_FORMAT_XRGB8888,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const uint32_t mxsfb_overlay_plane_formats[] = {
|
|
|
|
DRM_FORMAT_XRGB4444,
|
|
|
|
DRM_FORMAT_ARGB4444,
|
|
|
|
DRM_FORMAT_XRGB1555,
|
|
|
|
DRM_FORMAT_ARGB1555,
|
|
|
|
DRM_FORMAT_RGB565,
|
2020-07-27 10:06:43 +08:00
|
|
|
DRM_FORMAT_XRGB8888,
|
2020-07-27 10:06:54 +08:00
|
|
|
DRM_FORMAT_ARGB8888,
|
2020-07-27 10:06:43 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static const uint64_t mxsfb_modifiers[] = {
|
|
|
|
DRM_FORMAT_MOD_LINEAR,
|
|
|
|
DRM_FORMAT_MOD_INVALID
|
|
|
|
};
|
|
|
|
|
2020-07-27 10:06:54 +08:00
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* Initialization
|
|
|
|
*/
|
|
|
|
|
2020-07-27 10:06:43 +08:00
|
|
|
int mxsfb_kms_init(struct mxsfb_drm_private *mxsfb)
|
|
|
|
{
|
|
|
|
struct drm_encoder *encoder = &mxsfb->encoder;
|
|
|
|
struct drm_crtc *crtc = &mxsfb->crtc;
|
|
|
|
int ret;
|
|
|
|
|
2020-07-27 10:06:54 +08:00
|
|
|
drm_plane_helper_add(&mxsfb->planes.primary,
|
|
|
|
&mxsfb_plane_primary_helper_funcs);
|
|
|
|
ret = drm_universal_plane_init(mxsfb->drm, &mxsfb->planes.primary, 1,
|
|
|
|
&mxsfb_plane_funcs,
|
|
|
|
mxsfb_primary_plane_formats,
|
|
|
|
ARRAY_SIZE(mxsfb_primary_plane_formats),
|
2020-07-27 10:06:43 +08:00
|
|
|
mxsfb_modifiers, DRM_PLANE_TYPE_PRIMARY,
|
|
|
|
NULL);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2020-07-27 10:06:54 +08:00
|
|
|
if (mxsfb->devdata->has_overlay) {
|
|
|
|
drm_plane_helper_add(&mxsfb->planes.overlay,
|
|
|
|
&mxsfb_plane_overlay_helper_funcs);
|
|
|
|
ret = drm_universal_plane_init(mxsfb->drm,
|
|
|
|
&mxsfb->planes.overlay, 1,
|
|
|
|
&mxsfb_plane_funcs,
|
|
|
|
mxsfb_overlay_plane_formats,
|
|
|
|
ARRAY_SIZE(mxsfb_overlay_plane_formats),
|
|
|
|
mxsfb_modifiers, DRM_PLANE_TYPE_OVERLAY,
|
|
|
|
NULL);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-07-27 10:06:43 +08:00
|
|
|
drm_crtc_helper_add(crtc, &mxsfb_crtc_helper_funcs);
|
2020-07-27 10:06:54 +08:00
|
|
|
ret = drm_crtc_init_with_planes(mxsfb->drm, crtc,
|
|
|
|
&mxsfb->planes.primary, NULL,
|
2020-07-27 10:06:43 +08:00
|
|
|
&mxsfb_crtc_funcs, NULL);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
encoder->possible_crtcs = drm_crtc_mask(crtc);
|
|
|
|
return drm_encoder_init(mxsfb->drm, encoder, &mxsfb_encoder_funcs,
|
|
|
|
DRM_MODE_ENCODER_NONE, NULL);
|
|
|
|
}
|