drm/mcde: replace struct drm_simple_display_pipe with regular atomic helpers

Convert MCDE to explicit plane, CRTC and encoder objects.

Handle pending page-flip events from the CRTC atomic flush path using the
commit-local CRTC state, and avoid manual connector/encoder attachment
before the connector has been created by the bridge path.

Signed-off-by: Ze Huang <ze.huang@oss.qualcomm.com>
Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patch.msgid.link/20260727-drm-simple-kms-removal-v3-3-cd5dc89858c6@oss.qualcomm.com
This commit is contained in:
Ze Huang 2026-07-27 03:45:16 +08:00 committed by Thomas Zimmermann
parent fccd486a7e
commit 8bc1946ab3
3 changed files with 184 additions and 103 deletions

View File

@ -10,6 +10,7 @@
#include <linux/regulator/consumer.h>
#include <linux/media-bus-format.h>
#include <drm/drm_atomic_helper.h>
#include <drm/drm_device.h>
#include <drm/drm_fb_dma_helper.h>
#include <drm/drm_fourcc.h>
@ -18,7 +19,6 @@
#include <drm/drm_gem_dma_helper.h>
#include <drm/drm_mipi_dsi.h>
#include <drm/drm_print.h>
#include <drm/drm_simple_kms_helper.h>
#include <drm/drm_bridge.h>
#include <drm/drm_vblank.h>
#include <video/mipi_display.h>
@ -132,7 +132,7 @@ void mcde_display_irq(struct mcde *mcde)
writel(mispp, mcde->regs + MCDE_RISPP);
if (vblank)
drm_crtc_handle_vblank(&mcde->pipe.crtc);
drm_crtc_handle_vblank(&mcde->crtc);
if (misovl)
dev_info(mcde->dev, "some stray overlay IRQ %08x\n", misovl);
@ -157,40 +157,59 @@ void mcde_display_disable_irqs(struct mcde *mcde)
writel(0xFFFFFFFF, mcde->regs + MCDE_RISCHNL);
}
static int mcde_display_check(struct drm_simple_display_pipe *pipe,
struct drm_plane_state *pstate,
struct drm_crtc_state *cstate)
static int mcde_plane_helper_atomic_check(struct drm_plane *plane,
struct drm_atomic_commit *commit)
{
const struct drm_display_mode *mode = &cstate->mode;
struct drm_framebuffer *old_fb = pipe->plane.state->fb;
struct drm_plane_state *pstate = drm_atomic_get_new_plane_state(commit, plane);
struct drm_plane_state *old_pstate = drm_atomic_get_old_plane_state(commit, plane);
struct drm_crtc_state *cstate = NULL;
const struct drm_display_mode *mode;
struct drm_framebuffer *old_fb = old_pstate->fb;
struct drm_framebuffer *fb = pstate->fb;
int ret;
if (fb) {
u32 offset = drm_fb_dma_get_gem_addr(fb, pstate, 0);
/* FB base address must be dword aligned. */
if (offset & 3) {
DRM_DEBUG_KMS("FB not 32-bit aligned\n");
return -EINVAL;
}
/*
* There's no pitch register, the mode's hdisplay
* controls this.
*/
if (fb->pitches[0] != mode->hdisplay * fb->format->cpp[0]) {
DRM_DEBUG_KMS("can't handle pitches\n");
return -EINVAL;
}
/*
* We can't change the FB format in a flicker-free
* manner (and only update it during CRTC enable).
*/
if (old_fb && old_fb->format != fb->format)
cstate->mode_changed = true;
if (pstate->crtc) {
cstate = drm_atomic_get_crtc_state(commit, pstate->crtc);
if (IS_ERR(cstate))
return PTR_ERR(cstate);
}
ret = drm_atomic_helper_check_plane_state(pstate, cstate,
DRM_PLANE_NO_SCALING,
DRM_PLANE_NO_SCALING,
false, false);
if (ret)
return ret;
if (!pstate->visible || !fb)
return 0;
mode = &cstate->mode;
u32 offset = drm_fb_dma_get_gem_addr(fb, pstate, 0);
/* FB base address must be dword aligned. */
if (offset & 3) {
DRM_DEBUG_KMS("FB not 32-bit aligned\n");
return -EINVAL;
}
/*
* There's no pitch register, the mode's hdisplay
* controls this.
*/
if (fb->pitches[0] != mode->hdisplay * fb->format->cpp[0]) {
DRM_DEBUG_KMS("can't handle pitches\n");
return -EINVAL;
}
/*
* We can't change the FB format in a flicker-free
* manner (and only update it during CRTC enable).
*/
if (old_fb && old_fb->format != fb->format)
cstate->mode_changed = true;
return 0;
}
@ -1149,16 +1168,15 @@ static void mcde_setup_dsi(struct mcde *mcde, const struct drm_display_mode *mod
*dsi_formatter_frame = formatter_frame;
}
static void mcde_display_enable(struct drm_simple_display_pipe *pipe,
struct drm_crtc_state *cstate,
struct drm_plane_state *plane_state)
static void mcde_crtc_helper_atomic_enable(struct drm_crtc *crtc,
struct drm_atomic_commit *commit)
{
struct drm_crtc *crtc = &pipe->crtc;
struct drm_plane *plane = &pipe->plane;
struct drm_device *drm = crtc->dev;
struct mcde *mcde = to_mcde(drm);
struct drm_crtc_state *cstate = drm_atomic_get_new_crtc_state(commit, crtc);
struct drm_plane_state *plane_state = drm_atomic_get_new_plane_state(commit, &mcde->plane);
const struct drm_display_mode *mode = &cstate->mode;
struct drm_framebuffer *fb = plane->state->fb;
struct drm_framebuffer *fb = plane_state->fb;
u32 format = fb->format->format;
int dsi_pkt_size;
int fifo_wtrmrk;
@ -1298,9 +1316,10 @@ static void mcde_display_enable(struct drm_simple_display_pipe *pipe,
dev_info(drm->dev, "MCDE display is enabled\n");
}
static void mcde_display_disable(struct drm_simple_display_pipe *pipe)
static void mcde_crtc_helper_atomic_disable(struct drm_crtc *crtc,
struct drm_atomic_commit *commit)
{
struct drm_crtc *crtc = &pipe->crtc;
struct drm_crtc_state *cstate = drm_atomic_get_new_crtc_state(commit, crtc);
struct drm_device *drm = crtc->dev;
struct mcde *mcde = to_mcde(drm);
struct drm_pending_vblank_event *event;
@ -1318,9 +1337,9 @@ static void mcde_display_disable(struct drm_simple_display_pipe *pipe)
mcde_dsi_disable(mcde->bridge);
}
event = crtc->state->event;
event = cstate->event;
if (event) {
crtc->state->event = NULL;
cstate->event = NULL;
spin_lock_irq(&crtc->dev->event_lock);
drm_crtc_send_vblank_event(crtc, event);
@ -1381,44 +1400,13 @@ static void mcde_set_extsrc(struct mcde *mcde, u32 buffer_address)
writel(buffer_address + mcde->stride, mcde->regs + MCDE_EXTSRCXA1);
}
static void mcde_display_update(struct drm_simple_display_pipe *pipe,
struct drm_plane_state *old_pstate)
static void mcde_plane_helper_atomic_update(struct drm_plane *plane,
struct drm_atomic_commit *commit)
{
struct drm_crtc *crtc = &pipe->crtc;
struct drm_device *drm = crtc->dev;
struct mcde *mcde = to_mcde(drm);
struct drm_pending_vblank_event *event = crtc->state->event;
struct drm_plane *plane = &pipe->plane;
struct drm_plane_state *pstate = plane->state;
struct drm_plane_state *pstate = drm_atomic_get_new_plane_state(commit, plane);
struct mcde *mcde = to_mcde(plane->dev);
struct drm_framebuffer *fb = pstate->fb;
/*
* Handle any pending event first, we need to arm the vblank
* interrupt before sending any update to the display so we don't
* miss the interrupt.
*/
if (event) {
crtc->state->event = NULL;
spin_lock_irq(&crtc->dev->event_lock);
/*
* Hardware must be on before we can arm any vblank event,
* this is not a scanout controller where there is always
* some periodic update going on, it is completely frozen
* until we get an update. If MCDE output isn't yet enabled,
* we just send a vblank dummy event back.
*/
if (crtc->state->active && drm_crtc_vblank_get(crtc) == 0) {
dev_dbg(mcde->dev, "arm vblank event\n");
drm_crtc_arm_vblank_event(crtc, event);
} else {
dev_dbg(mcde->dev, "insert fake vblank event\n");
drm_crtc_send_vblank_event(crtc, event);
}
spin_unlock_irq(&crtc->dev->event_lock);
}
/*
* We do not start sending framebuffer updates before the
* display is enabled. Update events will however be dispatched
@ -1427,12 +1415,6 @@ static void mcde_display_update(struct drm_simple_display_pipe *pipe,
if (fb) {
mcde_set_extsrc(mcde, drm_fb_dma_get_gem_addr(fb, pstate, 0));
dev_info_once(mcde->dev, "first update of display contents\n");
/*
* Usually the flow is already active, unless we are in
* oneshot mode, then we need to kick the flow right here.
*/
if (mcde->flow_active == 0)
mcde_start_flow(mcde);
} else {
/*
* If an update is receieved before the MCDE is enabled
@ -1443,9 +1425,47 @@ static void mcde_display_update(struct drm_simple_display_pipe *pipe,
}
}
static int mcde_display_enable_vblank(struct drm_simple_display_pipe *pipe)
static void mcde_crtc_helper_atomic_flush(struct drm_crtc *crtc,
struct drm_atomic_commit *commit)
{
struct mcde *mcde = to_mcde(crtc->dev);
struct drm_plane_state *plane_state = drm_atomic_get_new_plane_state(commit, &mcde->plane);
struct drm_crtc_state *crtc_state = drm_atomic_get_new_crtc_state(commit, crtc);
struct drm_pending_vblank_event *event = crtc_state->event;
/*
* Handle any pending event first, we need to arm the vblank
* interrupt before sending any update to the display so we don't
* miss the interrupt.
*/
if (event) {
crtc_state->event = NULL;
spin_lock_irq(&crtc->dev->event_lock);
/*
* Hardware must be on before we can arm any vblank event,
* this is not a scanout controller where there is always
* some periodic update going on, it is completely frozen
* until we get an update. If MCDE output isn't yet enabled,
* we just send a vblank dummy event back.
*/
if (crtc_state->active && drm_crtc_vblank_get(crtc) == 0) {
dev_dbg(mcde->dev, "arm vblank event\n");
drm_crtc_arm_vblank_event(crtc, event);
} else {
dev_dbg(mcde->dev, "insert fake vblank event\n");
drm_crtc_send_vblank_event(crtc, event);
}
spin_unlock_irq(&crtc->dev->event_lock);
}
if (crtc_state->active && plane_state && plane_state->fb && mcde->flow_active == 0)
mcde_start_flow(mcde);
}
static int mcde_crtc_enable_vblank(struct drm_crtc *crtc)
{
struct drm_crtc *crtc = &pipe->crtc;
struct drm_device *drm = crtc->dev;
struct mcde *mcde = to_mcde(drm);
u32 val;
@ -1462,9 +1482,8 @@ static int mcde_display_enable_vblank(struct drm_simple_display_pipe *pipe)
return 0;
}
static void mcde_display_disable_vblank(struct drm_simple_display_pipe *pipe)
static void mcde_crtc_disable_vblank(struct drm_crtc *crtc)
{
struct drm_crtc *crtc = &pipe->crtc;
struct drm_device *drm = crtc->dev;
struct mcde *mcde = to_mcde(drm);
@ -1474,13 +1493,55 @@ static void mcde_display_disable_vblank(struct drm_simple_display_pipe *pipe)
writel(0xFFFFFFFF, mcde->regs + MCDE_RISPP);
}
static struct drm_simple_display_pipe_funcs mcde_display_funcs = {
.check = mcde_display_check,
.enable = mcde_display_enable,
.disable = mcde_display_disable,
.update = mcde_display_update,
.enable_vblank = mcde_display_enable_vblank,
.disable_vblank = mcde_display_disable_vblank,
static int mcde_crtc_helper_atomic_check(struct drm_crtc *crtc, struct drm_atomic_commit *commit)
{
struct drm_crtc_state *crtc_state = drm_atomic_get_new_crtc_state(commit, crtc);
int ret;
if (crtc_state->enable) {
ret = drm_atomic_helper_check_crtc_primary_plane(crtc_state);
if (ret)
return ret;
}
return drm_atomic_add_affected_planes(commit, crtc);
}
static const struct drm_crtc_funcs mcde_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 = mcde_crtc_enable_vblank,
.disable_vblank = mcde_crtc_disable_vblank,
};
static const struct drm_crtc_helper_funcs mcde_crtc_helper_funcs = {
.atomic_check = mcde_crtc_helper_atomic_check,
.atomic_enable = mcde_crtc_helper_atomic_enable,
.atomic_disable = mcde_crtc_helper_atomic_disable,
.atomic_flush = mcde_crtc_helper_atomic_flush,
};
static const struct drm_plane_funcs mcde_plane_funcs = {
.update_plane = drm_atomic_helper_update_plane,
.disable_plane = drm_atomic_helper_disable_plane,
.reset = drm_atomic_helper_plane_reset,
.destroy = drm_plane_cleanup,
.atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
.atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
};
static const struct drm_plane_helper_funcs mcde_plane_helper_funcs = {
.prepare_fb = drm_gem_plane_helper_prepare_fb,
.atomic_check = mcde_plane_helper_atomic_check,
.atomic_update = mcde_plane_helper_atomic_update,
};
static const struct drm_encoder_funcs mcde_encoder_funcs = {
.destroy = drm_encoder_cleanup,
};
int mcde_display_init(struct drm_device *drm)
@ -1510,14 +1571,29 @@ int mcde_display_init(struct drm_device *drm)
if (ret)
return ret;
ret = drm_simple_display_pipe_init(drm, &mcde->pipe,
&mcde_display_funcs,
formats, ARRAY_SIZE(formats),
NULL,
mcde->connector);
ret = drm_universal_plane_init(drm, &mcde->plane, 0,
&mcde_plane_funcs,
formats, ARRAY_SIZE(formats),
NULL, DRM_PLANE_TYPE_PRIMARY, NULL);
if (ret)
return ret;
drm_plane_helper_add(&mcde->plane, &mcde_plane_helper_funcs);
ret = drm_crtc_init_with_planes(drm, &mcde->crtc, &mcde->plane,
NULL, &mcde_crtc_funcs, NULL);
if (ret)
return ret;
drm_crtc_helper_add(&mcde->crtc, &mcde_crtc_helper_funcs);
ret = drm_encoder_init(drm, &mcde->encoder, &mcde_encoder_funcs,
DRM_MODE_ENCODER_NONE, NULL);
if (ret)
return ret;
mcde->encoder.possible_crtcs = drm_crtc_mask(&mcde->crtc);
return 0;
}
EXPORT_SYMBOL_GPL(mcde_display_init);

View File

@ -4,7 +4,7 @@
* Parts of this file were based on the MCDE driver by Marcus Lorentzon
* (C) ST-Ericsson SA 2013
*/
#include <drm/drm_simple_kms_helper.h>
#include <drm/drm_encoder.h>
#ifndef _MCDE_DRM_H_
#define _MCDE_DRM_H_
@ -72,7 +72,9 @@ struct mcde {
struct drm_panel *panel;
struct drm_bridge *bridge;
struct drm_connector *connector;
struct drm_simple_display_pipe pipe;
struct drm_plane plane;
struct drm_crtc crtc;
struct drm_encoder encoder;
struct mipi_dsi_device *mdsi;
bool dpi_output;
s16 stride;
@ -95,7 +97,11 @@ struct mcde {
struct regulator *vana;
};
#define to_mcde(dev) container_of(dev, struct mcde, drm)
static inline struct mcde *to_mcde(struct drm_device *dev)
{
return container_of(dev, struct mcde, drm);
}
static inline bool mcde_flow_is_video(struct mcde *mcde)
{

View File

@ -187,8 +187,7 @@ static int mcde_modeset_init(struct drm_device *drm)
}
/* Attach the bridge. */
ret = drm_simple_display_pipe_attach_bridge(&mcde->pipe,
mcde->bridge);
ret = drm_bridge_attach(&mcde->encoder, mcde->bridge, NULL, 0);
if (ret) {
dev_err(drm->dev, "failed to attach display output bridge\n");
return ret;