Re: [PATCH v8 10/12] drm/tegra: rgb: Parameterize configuration based on bus flags
From: Mikko Perttunen
Date: Fri Nov 27 2026 - 07:35:16 EST
On Friday, November 27, 2026 6:21 PM Svyatoslav Ryhel wrote:
> пт, 27 лист. 2026 р. о 08:22 Mikko Perttunen <mperttunen@xxxxxxxxxx> пише:
> >
> > On Sunday, November 22, 2026 5:18 PM Svyatoslav Ryhel wrote:
> > > Parameterize configuration based on bus flags passed from the bridge or
> > > panel. The list of supported flags includes now pixel clock polarity,
> > > display enable (DE) polarity, and data alignment.
> > >
> > > Signed-off-by: Svyatoslav Ryhel <clamor95@xxxxxxxxx>
> > > ---
> > > drivers/gpu/drm/tegra/rgb.c | 39 +++++++++++++++++++++++++++++++++----
> > > 1 file changed, 35 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/drivers/gpu/drm/tegra/rgb.c b/drivers/gpu/drm/tegra/rgb.c
> > > index d48d498068ac8..faecd6f94359f 100644
> > > --- a/drivers/gpu/drm/tegra/rgb.c
> > > +++ b/drivers/gpu/drm/tegra/rgb.c
> > > @@ -5,6 +5,7 @@
> > > */
> > >
> > > #include <linux/clk.h>
> > > +#include <linux/media-bus-format.h>
> > > #include <linux/of.h>
> > >
> > > #include <drm/drm_atomic_helper.h>
> > > @@ -106,6 +107,7 @@ static void tegra_rgb_encoder_enable(struct drm_encoder *encoder,
> > > struct tegra_output *output = encoder_to_output(encoder);
> > > struct tegra_rgb *rgb = to_rgb(output);
> > > struct drm_connector_state *conn_state;
> > > + struct drm_bridge_state *bridge_state;
> > > struct drm_crtc_state *crtc_state;
> > > struct drm_connector *connector;
> > > struct drm_display_mode *mode;
> > > @@ -117,12 +119,21 @@ static void tegra_rgb_encoder_enable(struct drm_encoder *encoder,
> > > crtc_state = drm_atomic_get_new_crtc_state(state, conn_state->crtc);
> > > mode = &crtc_state->adjusted_mode;
> > >
> > > + /* Get but flags from the bridge state. */
> >
> > s/but/bus/
> >
> > > + bridge_state = drm_atomic_get_new_bridge_state(state, output->bridge);
> > > + if (bridge_state)
> > > + bus_flags = bridge_state->input_bus_cfg.flags;
> > > + else
> > > + bus_flags = DRM_BUS_FLAG_PIXDATA_SAMPLE_NEGEDGE |
> > > + DRM_BUS_FLAG_DE_HIGH |
> > > + DRM_BUS_FLAG_DATA_MSB_TO_LSB;
> > > +
> > > tegra_dc_write_regs(rgb->dc, rgb_enable, ARRAY_SIZE(rgb_enable));
> > >
> > > value = DE_SELECT_ACTIVE | DE_CONTROL_NORMAL;
> > > tegra_dc_writel(rgb->dc, value, DC_DISP_DATA_ENABLE_OPTIONS);
> > >
> > > - /* configure H- and V-sync signal polarities */
> > > + /* configure H- and V-sync and pixel clock signal polarities */
> > > value = tegra_dc_readl(rgb->dc, DC_COM_PIN_OUTPUT_POLARITY(1));
> > >
> > > if (mode->flags & DRM_MODE_FLAG_NHSYNC)
> > > @@ -135,11 +146,31 @@ static void tegra_rgb_encoder_enable(struct drm_encoder *encoder,
> > > else
> > > value &= ~LVS_OUTPUT_POLARITY_LOW;
> > >
> > > + if (bus_flags & DRM_BUS_FLAG_PIXDATA_SAMPLE_POSEDGE)
> > > + value &= ~BIT(PIN_LSC0);
> > > + else
> > > + value |= BIT(PIN_LSC0);
> >
> > I think this is the wrong way around: SAMPLE_POSEDGE means that the
> > pixel data is sampled on a rising edge. That is, it should be driven on
> > the low edge so it's ready for sampling in time for the rising edge.
> >
> > LSC0_OUTPUT_POLARITY says that the value "LOW" (a bit confusingly, 1)
> > corresponds to a data transition on the falling edge, i.e. sampling on
> > the rising edge.
> >
> > Section 31.9.6 states this a bit more clearly: "an active low pixel
> > clock means that the data changes on the falling edge of the clock, to
> > be latched on the rising edge".
> >
>
> DRM_BUS_FLAG_PIXDATA_SAMPLE_POSEDGE = DRM_BUS_FLAG_PIXDATA_DRIVE_NEGEDGE
>
> Should I replace with DRM_BUS_FLAG_PIXDATA_DRIVE_NEGEDGE?
No -- with the current code, let's say
DRM_BUS_FLAG_PIXDATA_SAMPLE_POSEDGE is set. I.e. the panel tells us that
it will be sampling pixel data on the positive (rising) edge.
LSC0_OUTPUT_POLARITY will be set to 0. The TRM documents the value 0 as
"active high", and "means that rising edge coincides with data
transition". That is, the display controller will change the output pin
state to color data on the rising edge. So the SoC pins will change
state at the rising edge, and the panel will sample at the rising edge.
But the pins will take some time to take their new values, so this might
not work or could be unreliable depending on all kinds of timing
factors. So if the panel is sampling as the rising edge, the SoC should
be driving the pins at the falling edge, that way there is time for the
pins to settle before the panel samples them.
So the value written to LSC0_OUTPUT_POLARITY should be the opposite of
what it's now. If that breaks the panel, either it's reporting the
incorrect DRM_BUS_FLAG_PIXDATA_SAMPLE_* value or something else is
incorrect.
>
> > > +
> > > tegra_dc_writel(rgb->dc, value, DC_COM_PIN_OUTPUT_POLARITY(1));
> > >
> > > - /* XXX: parameterize? */
> > > - value = DISP_DATA_FORMAT_DF1P1C | DISP_ALIGNMENT_MSB |
> > > - DISP_ORDER_RED_BLUE;
> > > + /* configure DE signal polarities */
> > > + value = tegra_dc_readl(rgb->dc, DC_COM_PIN_OUTPUT_POLARITY(3));
> > > +
> > > + if (bus_flags & DRM_BUS_FLAG_DE_LOW)
> > > + value |= BIT(PIN_LSPI);
> > > + else
> > > + value &= ~BIT(PIN_LSPI);
> > > +
> > > + tegra_dc_writel(rgb->dc, value, DC_COM_PIN_OUTPUT_POLARITY(3));
> > > +
> > > + /* configure DATA order and alignment */
> > > + value = DISP_DATA_FORMAT_DF1P1C | DISP_ORDER_RED_BLUE;
> > > +
> > > + if (bus_flags & DRM_BUS_FLAG_DATA_LSB_TO_MSB)
> > > + value |= DISP_ALIGNMENT_LSB;
> > > + else
> > > + value &= ~DISP_ALIGNMENT_LSB;
> >
> > DRM_BUS_FLAG_DATA_LSB_TO_MSB does not seem the correct thing to check
> > here. According to the TRM, DISP_ALIGNMENT doesn't swap between LSB/MSB
> > bit ordering in a classical way, instead:
> >
> > // DISP_DATA_ALIGNMENT = 0 (MSB)
> > LD[23:0] = {R[1:0], G[1:0], B[1:0],
> > R[7:2], G[7:2], B[7:2]};
> >
> > // DISP_DATA_ALIGNMENT = 1 (LSB)
> > LD[23:0] = {R[7:0], G[7:0], B[7:0]};
> >
> > I suppose MSB is more natural for 18-bit panels and LSB for 24-bit
> > panels depending on the layout. So the correct value depends on how the
> > panel is wired to the SoC on the board. Hence, I think we should
> > describe this with a new property in device tree under rgb/dbi or
> > endpoint node. Something like 'nvidia,rgb888-wiring' for LSB? And
> > document that this means the above kind of wiring - not all RGB888
> > panels use it.
> >
>
> Ugh, why is this so confusing...
>
> > > +
> > > tegra_dc_writel(rgb->dc, value, DC_DISP_DISP_INTERFACE_CONTROL);
> > >
> > > tegra_dc_commit(rgb->dc);
> > > --
> > > 2.53.0
> > >