Commit c62a7b9c authored by Liu Ying's avatar Liu Ying Committed by Marek Vasut

drm: lcdif: Check consistent bus format and flags across first bridges

The single LCDIF embedded in i.MX93 SoC may drive multiple displays
simultaneously.  Check bus format and flags across first bridges in
->atomic_check() to ensure they are consistent.  This is a preparation
for adding i.MX93 LCDIF support.
Acked-by: default avatarAlexander Stein <alexander.stein@ew.tq-group.com>
Tested-by: default avatarAlexander Stein <alexander.stein@ew.tq-group.com>
Reviewed-by: default avatarMarek Vasut <marex@denx.de>
Signed-off-by: default avatarLiu Ying <victor.liu@nxp.com>
Signed-off-by: default avatarMarek Vasut <marex@denx.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20230510092450.4024730-5-victor.liu@nxp.com
parent 5befcdca
......@@ -52,8 +52,6 @@ static int lcdif_attach_bridge(struct lcdif_drm_private *lcdif)
if (ret)
return dev_err_probe(drm->dev, ret, "Failed to attach bridge\n");
lcdif->bridge = bridge;
return 0;
}
......
......@@ -31,7 +31,6 @@ struct lcdif_drm_private {
} planes;
struct drm_crtc crtc;
struct drm_encoder encoder;
struct drm_bridge *bridge;
};
static inline struct lcdif_drm_private *
......
......@@ -17,6 +17,7 @@
#include <drm/drm_atomic_helper.h>
#include <drm/drm_bridge.h>
#include <drm/drm_color_mgmt.h>
#include <drm/drm_connector.h>
#include <drm/drm_crtc.h>
#include <drm/drm_encoder.h>
#include <drm/drm_fb_dma_helper.h>
......@@ -424,15 +425,19 @@ static int lcdif_crtc_atomic_check(struct drm_crtc *crtc,
struct drm_atomic_state *state)
{
struct drm_device *drm = crtc->dev;
struct lcdif_drm_private *lcdif = to_lcdif_drm_private(drm);
struct drm_crtc_state *crtc_state = drm_atomic_get_new_crtc_state(state,
crtc);
struct lcdif_crtc_state *lcdif_crtc_state = to_lcdif_crtc_state(crtc_state);
bool has_primary = crtc_state->plane_mask &
drm_plane_mask(crtc->primary);
struct drm_connector_state *connector_state;
struct drm_connector *connector;
struct drm_encoder *encoder;
struct drm_bridge_state *bridge_state;
struct drm_bridge *bridge = lcdif->bridge;
int ret;
struct drm_bridge *bridge;
u32 bus_format, bus_flags;
bool format_set = false, flags_set = false;
int ret, i;
/* The primary plane has to be enabled when the CRTC is active. */
if (crtc_state->active && !has_primary)
......@@ -442,29 +447,58 @@ static int lcdif_crtc_atomic_check(struct drm_crtc *crtc,
if (ret)
return ret;
bridge_state = drm_atomic_get_new_bridge_state(state, bridge);
if (!bridge_state)
lcdif_crtc_state->bus_format = MEDIA_BUS_FMT_FIXED;
else
lcdif_crtc_state->bus_format = bridge_state->input_bus_cfg.format;
if (lcdif_crtc_state->bus_format == MEDIA_BUS_FMT_FIXED) {
dev_warn_once(drm->dev,
"Bridge does not provide bus format, assuming MEDIA_BUS_FMT_RGB888_1X24.\n"
"Please fix bridge driver by handling atomic_get_input_bus_fmts.\n");
lcdif_crtc_state->bus_format = MEDIA_BUS_FMT_RGB888_1X24;
} else if (!lcdif_crtc_state->bus_format) {
/* If all else fails, default to RGB888_1X24 */
lcdif_crtc_state->bus_format = MEDIA_BUS_FMT_RGB888_1X24;
/* Try to find consistent bus format and flags across first bridges. */
for_each_new_connector_in_state(state, connector, connector_state, i) {
if (!connector_state->crtc)
continue;
encoder = connector_state->best_encoder;
bridge = drm_bridge_chain_get_first_bridge(encoder);
if (!bridge)
continue;
bridge_state = drm_atomic_get_new_bridge_state(state, bridge);
if (!bridge_state)
bus_format = MEDIA_BUS_FMT_FIXED;
else
bus_format = bridge_state->input_bus_cfg.format;
if (bus_format == MEDIA_BUS_FMT_FIXED) {
dev_warn(drm->dev,
"[ENCODER:%d:%s]'s bridge does not provide bus format, assuming MEDIA_BUS_FMT_RGB888_1X24.\n"
"Please fix bridge driver by handling atomic_get_input_bus_fmts.\n",
encoder->base.id, encoder->name);
bus_format = MEDIA_BUS_FMT_RGB888_1X24;
} else if (!bus_format) {
/* If all else fails, default to RGB888_1X24 */
bus_format = MEDIA_BUS_FMT_RGB888_1X24;
}
if (!format_set) {
lcdif_crtc_state->bus_format = bus_format;
format_set = true;
} else if (lcdif_crtc_state->bus_format != bus_format) {
DRM_DEV_DEBUG_DRIVER(drm->dev, "inconsistent bus format\n");
return -EINVAL;
}
if (bridge->timings)
bus_flags = bridge->timings->input_bus_flags;
else if (bridge_state)
bus_flags = bridge_state->input_bus_cfg.flags;
else
bus_flags = 0;
if (!flags_set) {
lcdif_crtc_state->bus_flags = bus_flags;
flags_set = true;
} else if (lcdif_crtc_state->bus_flags != bus_flags) {
DRM_DEV_DEBUG_DRIVER(drm->dev, "inconsistent bus flags\n");
return -EINVAL;
}
}
if (bridge->timings)
lcdif_crtc_state->bus_flags = bridge->timings->input_bus_flags;
else if (bridge_state)
lcdif_crtc_state->bus_flags = bridge_state->input_bus_cfg.flags;
else
lcdif_crtc_state->bus_flags = 0;
return 0;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment