drm: mxsfb: Add optional DPI output bus-width configuration

LCDIF programs LCD_DATABUS_WIDTH from the selected media bus format. The
format reported by the downstream panel or bridge describes the display
input, but it does not describe how the LCDIF data pins are physically
wired on the board.

These can differ. For example, a 16-bit LCDIF bus can be connected to a
24-bit display by wiring the available color bits to the corresponding
display inputs. In that case, using the display's 24-bit format to
configure LCDIF selects the wrong data-bus mode and changes the assignment
of color bits on the LCD_DATA pins.

Read the optional bus-width endpoint property from the LCDIF output port
and use it to select the media bus format used to configure LCDIF. This
allows the LCDIF bus mode to describe the physical interface
independently of the downstream display format.

When the property is absent, continue using the format reported by the
downstream display device, preserving the previous behavior. The
devicetree binding restricts bus-width to 16, 18 or 24; any other value
means the devicetree is broken, so fail the probe instead of silently
falling back to the previous behavior.

Signed-off-by: Francesco Dolcini <francesco.dolcini@toradex.com>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
Tested-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
Link: https://patch.msgid.link/20260917140042.118181-3-francesco@dolcini.it
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
This commit is contained in:
Francesco Dolcini 2026-09-17 16:00:37 +02:00 committed by Luca Ceresoli
parent 54d28d79d9
commit aafd4205a7
3 changed files with 57 additions and 0 deletions

View File

@ -12,7 +12,10 @@
#include <linux/clk.h>
#include <linux/dma-mapping.h>
#include <linux/io.h>
#include <linux/media-bus-format.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_graph.h>
#include <linux/platform_device.h>
#include <linux/property.h>
#include <linux/pm_runtime.h>
@ -207,11 +210,41 @@ static void mxsfb_irq_uninstall(struct drm_device *dev)
free_irq(mxsfb->irq, dev);
}
static int mxsfb_of_bus_fmt(const struct device_node *ep, u32 *bus_format)
{
u32 bus_width;
int ret;
ret = of_property_read_u32(ep, "bus-width", &bus_width);
if (ret == -EINVAL)
return 0;
if (ret)
return ret;
switch (bus_width) {
case 16:
*bus_format = MEDIA_BUS_FMT_RGB565_1X16;
break;
case 18:
*bus_format = MEDIA_BUS_FMT_RGB666_1X18;
break;
case 24:
*bus_format = MEDIA_BUS_FMT_RGB888_1X24;
break;
default:
return -EINVAL;
}
return 0;
}
static int mxsfb_load(struct drm_device *drm,
const struct mxsfb_devdata *devdata)
{
struct platform_device *pdev = to_platform_device(drm->dev);
struct device_node *np = pdev->dev.of_node;
struct mxsfb_drm_private *mxsfb;
struct device_node *ep;
int ret;
mxsfb = devm_kzalloc(&pdev->dev, sizeof(*mxsfb), GFP_KERNEL);
@ -238,6 +271,16 @@ static int mxsfb_load(struct drm_device *drm,
if (IS_ERR(mxsfb->clk_disp_axi))
mxsfb->clk_disp_axi = NULL;
ep = of_graph_get_next_endpoint(np, NULL);
if (ep) {
ret = mxsfb_of_bus_fmt(ep, &mxsfb->bus_format);
of_node_put(ep);
if (ret) {
dev_err(drm->dev, "Invalid bus-width endpoint property\n");
return ret;
}
}
ret = dma_set_mask_and_coherent(drm->dev, DMA_BIT_MASK(32));
if (ret)
return ret;

View File

@ -46,6 +46,8 @@ struct mxsfb_drm_private {
struct drm_connector *connector;
struct drm_bridge *bridge;
u32 bus_format;
bool crc_active;
};

View File

@ -386,6 +386,18 @@ static void mxsfb_crtc_atomic_enable(struct drm_crtc *crtc,
if (!bus_format)
bus_format = MEDIA_BUS_FMT_RGB888_1X24;
/*
* Prefer the bus format derived from the OF graph endpoint "bus-width"
* property when available. Otherwise, use the bus format reported by
* the downstream bridge or panel.
*
* This supports mismatched display and interface bus widths, such as
* a 24-bit panel connected through an 18-bit interface or an 18-bit
* panel connected through a 24-bit interface.
*/
if (mxsfb->bus_format)
bus_format = mxsfb->bus_format;
mxsfb_crtc_mode_set_nofb(mxsfb, bridge_state, bus_format);
/* Write cur_buf as well to avoid an initial corrupt frame */