* [RFC PATCH 0/4] drm/tilcdc: Implement state readout
@ 2026-11-16 14:27 Màxim Pedraza Padilla
2026-11-16 14:27 ` [RFC PATCH 1/4] drm/bridge: Add atomic_sro_install_state hook Màxim Pedraza Padilla
` (4 more replies)
0 siblings, 5 replies; 27+ messages in thread
From: Màxim Pedraza Padilla @ 2026-11-16 14:27 UTC (permalink / raw)
To: Maxime Ripard
Cc: Neil Armstrong, Jessica Zhang, Jyri Sarha, Tomi Valkeinen,
Uwe Kleine-König, Andrzej Hajda, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Luca Ceresoli,
Maarten Lankhorst, Thomas Zimmermann, David Airlie,
Simona Vetter, dri-devel, linux-kernel
Hi Maxime,
Following your suggestion in the boot logo thread ("just implement readout
then"), this implements hardware state readout for tilcdc on top of your
v7:
https://lore.kernel.org/r/20261029-drm-state-readout-v7-0-25e5163d75c3@kernel.org
The goal is that the kernel takes over the display as U-Boot left it, so
the boot logo stays on screen with no blanking or flicker until userspace
replaces it.
Patch 1 adds an atomic_sro_install_state hook to bridges, and patch 2 uses
it in the panel bridge, which also reads out the connector and bridge
state: without that, the core discards the readout of any driver behind a
panel. Patch 3 is the tilcdc readout itself: CRTC mode from the raster
timings, primary plane with a non-GEM framebuffer (as tidss does), encoder
and hw_reset. Patch 4 keeps panel-simple from turning the panel off at
probe by driving its enable GPIO low.
For the backlight, pwm-tiecap needs a .get_state(), otherwise pwm_bl sees
the PWM disabled and sets duty 0 until the panel is enabled. I sent that
one separately to Uwe and linux-pwm:
https://lore.kernel.org/r/20261116142251.1296742-1-maximpedraza@gmail.com
Tested on an AM335x board (Fides T075, out-of-tree DT) with U-Boot
leaving an 800x480 RGB565 logo:
- The logo stays on screen, untouched, from U-Boot to userspace, with the
backlight on all along.
- The U-Boot mode doesn't match the one in the DT (16.94 MHz pixel clock
and slightly different timings), so the first commit with the panel
mode does a full modeset, as expected.
- First commits from userspace: a framebuffer flip without modeset, a full
modeset to the panel mode, and ACTIVE=0 then 1. No WARN or oops.
- With drm.atomic_readout=0 the old behaviour comes back: the raster stops
and the first commit does a full modeset.
- Without video set up by U-Boot nothing is adopted and the normal path is
taken.
- The SGX530 driver and a Qt EGLFS application take over from the adopted
logo without visible glitches.
The DT needs a reserved-memory node for the U-Boot framebuffer, and
ti,no-reset-on-init on the GPIO banks (and on the PWMSS) so that ti-sysc
doesn't reset the panel enable and backlight lines.
The backlight needs some care. With the PWM configured by the bootloader
and the pin muxed to it, the handover is seamless. If the bootloader drives
the backlight some other way, for instance with the pin as a plain GPIO and
the PWM stopped, the light goes off when the kernel muxes the pin to the
PWM, until the panel is enabled. The bootloader has to leave the backlight
in the state the kernel will read back.
After each commit, the comparison still reports some mismatches. As far as
I can tell they come from the core rather than from tilcdc, but I'd
appreciate your view:
- connector_mask and encoder_mask, on a commit that only changes the
framebuffer: the connector is not part of the commit, so it's not read
back.
- mode_blob, after a modeset: the memcmp() includes the mode type, and
DRM_MODE_TYPE_PREFERRED can't be read from the hardware.
- With ACTIVE=0: crtc, fb, enable, best_encoder and the bridge bus_cfg.
The readout sees the raster stopped and can't tell enable=1/active=0
from disabled.
Thanks,
Màxim
Màxim Pedraza Padilla (4):
drm/bridge: Add atomic_sro_install_state hook
drm/panel: Implement state readout in the panel bridge
drm/tilcdc: Implement state readout support
drm/panel: simple: Keep the enable GPIO as left by the bootloader
drivers/gpu/drm/drm_bridge.c | 12 ++
drivers/gpu/drm/drm_panel.c | 92 ++++++++++++-
drivers/gpu/drm/panel/panel-simple.c | 4 +-
drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 173 ++++++++++++++++++++++++
drivers/gpu/drm/tilcdc/tilcdc_drv.c | 22 ++-
drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 29 +++-
drivers/gpu/drm/tilcdc/tilcdc_plane.c | 106 +++++++++++++++
include/drm/drm_bridge.h | 12 ++
8 files changed, 442 insertions(+), 8 deletions(-)
base-commit: cf5d8e390e2ac2cfa24a50645efdbb9f0eebe65f
prerequisite-patch-id: dd600a02afa073bedc54e8b973d6bfdad7594dcf
prerequisite-patch-id: cb32051331d83506b8e6fd512f93595724905a9f
prerequisite-patch-id: 72acc5f5b50b767484ff995256e7fb155c05f6eb
prerequisite-patch-id: 20859bdf469e990a0d7dae3498bc90452afac2b6
prerequisite-patch-id: ca629fbb440fc4bddbf5594161eb44aadacbffdc
prerequisite-patch-id: 1a6e113d6f412d798052a924269a7dc876d91ded
prerequisite-patch-id: 8eacf9b84574fe303134a78ce9c3fcc4ec1c8dbf
prerequisite-patch-id: be45e01b10b8b0050199e379d51d80866c9bd60f
prerequisite-patch-id: 0ab25f681f68659f8a0e4f0da80fdf70952dcf8d
prerequisite-patch-id: cd456ec3d0c297910f46bbc02fdf105dc1881528
prerequisite-patch-id: 8f0adc84c688489feb0cba21f1f2292be4229095
prerequisite-patch-id: 86ba5aa9cdc784c0b7f1a63beb76925ef26a51f4
prerequisite-patch-id: 797d3d2c63a2772528c850d5058e11d064e13b81
prerequisite-patch-id: a1f2f5aa788a1615c521496408c8380bb076a906
prerequisite-patch-id: c9f90931b72f402916621991a8a8abf6f4b5ffb5
prerequisite-patch-id: e0e184d52d20bd622b3752ea73516698bedf554f
prerequisite-patch-id: 9779c50d8b08c7d2ac14017fe2825d148350e434
prerequisite-patch-id: 2dfe6357a636b3662dbd8db80bc29bd36a0329ad
prerequisite-patch-id: 704fb943477b1a761312b0ec16e9291cad7c9769
prerequisite-patch-id: 0409704173cb408067b9e69071c0af7efe299492
prerequisite-patch-id: 455ce6bd7b211ef9c772ba06efefdffd27058a87
prerequisite-patch-id: 5ed7b0ed4e054ecbd8c84e622dbac0f42d60e4a6
prerequisite-patch-id: 563c77055b805b0d640cd8517627a8c491bce385
prerequisite-patch-id: ad8a0534dbcf96480f5020f50fd68d5b78c5fac5
prerequisite-patch-id: 8fe899b77403121b41514f93b859b5e4528a79d9
prerequisite-patch-id: 4fafee08b92675ea8a6f7fb5e27ff5a769325208
prerequisite-patch-id: d7abc61edebf4b3a87d94806301a99db4e28c036
prerequisite-patch-id: 615c6d4def91d820c55f9f05afb0086734c770fa
prerequisite-patch-id: 67a600dbc806b7426a5f48b11413d3716d4729e5
prerequisite-patch-id: 86db1a90ea3b2e47a0e082b33d4f9ee5c79782e4
prerequisite-patch-id: dffc8a4bbcf134bf21a86cd197deefe5143b7210
prerequisite-patch-id: d1dea459f43a2541077a882c3282b806a7dd5ecc
prerequisite-patch-id: 0c8a54b1f9bf053b817e949eb82538e7a0630d01
prerequisite-patch-id: 4582389780efd509f9713da8c161f497f2d89bc8
--
2.39.5
^ permalink raw reply [flat|nested] 27+ messages in thread* [RFC PATCH 1/4] drm/bridge: Add atomic_sro_install_state hook 2026-11-16 14:27 [RFC PATCH 0/4] drm/tilcdc: Implement state readout Màxim Pedraza Padilla @ 2026-11-16 14:27 ` Màxim Pedraza Padilla 2026-11-16 16:58 ` Maxime Ripard 2026-11-16 14:27 ` [RFC PATCH 2/4] drm/panel: Implement state readout in the panel bridge Màxim Pedraza Padilla ` (3 subsequent siblings) 4 siblings, 1 reply; 27+ messages in thread From: Màxim Pedraza Padilla @ 2026-11-16 14:27 UTC (permalink / raw) To: Maxime Ripard Cc: Neil Armstrong, Jessica Zhang, Jyri Sarha, Tomi Valkeinen, Uwe Kleine-König, Andrzej Hajda, Robert Foss, Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Luca Ceresoli, Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel, linux-kernel The state readout core lets private objects take the resources needed to keep the hardware running when the state read out becomes current, but bridges have no way to use it. A panel left on by the firmware, for one, would stay marked as disabled. Add a bridge hook and call it from the bridge private object. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Màxim Pedraza Padilla <maximpedraza@gmail.com> --- drivers/gpu/drm/drm_bridge.c | 12 ++++++++++++ include/drm/drm_bridge.h | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c index 45a34bbb8f14..cdfd6d44c8d5 100644 --- a/drivers/gpu/drm/drm_bridge.c +++ b/drivers/gpu/drm/drm_bridge.c @@ -629,6 +629,17 @@ drm_bridge_atomic_readout_priv_state(struct drm_private_obj *obj, return 0; } +static void +drm_bridge_atomic_install_priv_state(struct drm_private_obj *obj, + struct drm_private_state *state) +{ + struct drm_bridge *bridge = drm_priv_to_bridge(obj); + + if (bridge->funcs->atomic_sro_install_state) + bridge->funcs->atomic_sro_install_state(bridge, + drm_priv_to_bridge_state(state)); +} + static bool drm_bridge_atomic_compare_priv_state(struct drm_private_obj *obj, struct drm_printer *p, struct drm_private_state *a, @@ -674,6 +685,7 @@ static const struct drm_private_state_funcs drm_bridge_priv_state_funcs = { static const struct drm_private_state_funcs drm_bridge_priv_state_funcs_with_sro = { .atomic_sro_compare_state = drm_bridge_atomic_compare_priv_state, .atomic_sro_readout_state = drm_bridge_atomic_readout_priv_state, + .atomic_sro_install_state = drm_bridge_atomic_install_priv_state, .atomic_create_state = drm_bridge_atomic_create_priv_state, .atomic_duplicate_state = drm_bridge_atomic_duplicate_priv_state, .atomic_destroy_state = drm_bridge_atomic_destroy_priv_state, diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h index b73f3424ed62..630af5b3fcf2 100644 --- a/include/drm/drm_bridge.h +++ b/include/drm/drm_bridge.h @@ -967,6 +967,18 @@ struct drm_bridge_funcs { struct drm_atomic_sro_state *state, struct drm_connector_state *conn_state); + /** + * @atomic_sro_install_state: + * + * This optional hook is called when the state read out from the + * hardware becomes the current state of the bridge, once the CRTCs + * and planes have been installed. It gives the bridge a chance to + * take the resources needed to keep the hardware running. It can't + * fail. + */ + void (*atomic_sro_install_state)(struct drm_bridge *bridge, + struct drm_bridge_state *state); + /** * @debugfs_init: * -- 2.39.5 ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [RFC PATCH 1/4] drm/bridge: Add atomic_sro_install_state hook 2026-11-16 14:27 ` [RFC PATCH 1/4] drm/bridge: Add atomic_sro_install_state hook Màxim Pedraza Padilla @ 2026-11-16 16:58 ` Maxime Ripard 0 siblings, 0 replies; 27+ messages in thread From: Maxime Ripard @ 2026-11-16 16:58 UTC (permalink / raw) To: Màxim Pedraza Padilla Cc: Neil Armstrong, Jessica Zhang, Jyri Sarha, Tomi Valkeinen, Uwe Kleine-König, Andrzej Hajda, Robert Foss, Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Luca Ceresoli, Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel, linux-kernel [-- Attachment #1: Type: text/plain, Size: 826 bytes --] On Mon, Nov 16, 2026 at 03:27:04PM +0100, Màxim Pedraza Padilla wrote: > The state readout core lets private objects take the resources needed to > keep the hardware running when the state read out becomes current, but > bridges have no way to use it. A panel left on by the firmware, for one, > would stay marked as disabled. > > Add a bridge hook and call it from the bridge private object. > > Assisted-by: Claude:claude-opus-5-5 > Signed-off-by: Màxim Pedraza Padilla <maximpedraza@gmail.com> It's something that was pointed out by sashiko here: https://lore.kernel.org/all/sashiko-outbox-201494@kernel.org/ I've fixed it locally and I'm also passing the connector and CRTC state to have the same prototype than readout_state and remove some boiler plate. It should be equivalent though. Maxime [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 273 bytes --] ^ permalink raw reply [flat|nested] 27+ messages in thread
* [RFC PATCH 2/4] drm/panel: Implement state readout in the panel bridge 2026-11-16 14:27 [RFC PATCH 0/4] drm/tilcdc: Implement state readout Màxim Pedraza Padilla 2026-11-16 14:27 ` [RFC PATCH 1/4] drm/bridge: Add atomic_sro_install_state hook Màxim Pedraza Padilla @ 2026-11-16 14:27 ` Màxim Pedraza Padilla 2026-11-16 16:59 ` Maxime Ripard 2026-11-16 14:27 ` [RFC PATCH 3/4] drm/tilcdc: Implement state readout support Màxim Pedraza Padilla ` (2 subsequent siblings) 4 siblings, 1 reply; 27+ messages in thread From: Màxim Pedraza Padilla @ 2026-11-16 14:27 UTC (permalink / raw) To: Maxime Ripard Cc: Neil Armstrong, Jessica Zhang, Jyri Sarha, Tomi Valkeinen, Uwe Kleine-König, Andrzej Hajda, Robert Foss, Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Luca Ceresoli, Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel, linux-kernel The state readout core gives up if a private object doesn't implement readout, so a driver using a panel bridge can't adopt the firmware state, even if it implements readout itself. A panel has no state to read back: it's part of the pipeline if the CRTC feeding its encoder is active. Implement the connector and bridge readout on that assumption, relying on the encoder's atomic_sro_get_current_crtc hook, and fill the bus configuration with what the commit negotiation would give. When the state is installed, prepare and enable the panel, since nothing else would until the first modeset. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Màxim Pedraza Padilla <maximpedraza@gmail.com> --- drivers/gpu/drm/drm_panel.c | 92 ++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_panel.c b/drivers/gpu/drm/drm_panel.c index c00529bfb706..7cee228f798b 100644 --- a/drivers/gpu/drm/drm_panel.c +++ b/drivers/gpu/drm/drm_panel.c @@ -9,10 +9,14 @@ #include <linux/debugfs.h> #include <linux/err.h> #include <linux/export.h> +#include <linux/media-bus-format.h> #include <linux/module.h> #include <linux/of.h> +#include <drm/drm_atomic.h> #include <drm/drm_atomic_helper.h> +#include <drm/drm_atomic_state_readout.h> +#include <drm/drm_atomic_state_readout_helper.h> #include <drm/drm_bridge.h> #include <drm/drm_connector.h> #include <drm/drm_crtc.h> @@ -216,6 +220,88 @@ static void panel_bridge_debugfs_init(struct drm_bridge *bridge, panel->funcs->debugfs_init(panel, root); } +/* + * A panel has no state to read back: it's part of the pipeline if the CRTC + * feeding its encoder is active. + */ +static int panel_bridge_connector_readout(struct drm_bridge *bridge, + struct drm_atomic_sro_state *state, + struct drm_connector_state *conn_state) +{ + struct drm_connector *connector = conn_state->connector; + struct drm_encoder *encoder = bridge->encoder; + struct drm_crtc_state *crtc_state; + struct drm_crtc *crtc; + + if (!encoder->funcs || !encoder->funcs->atomic_sro_get_current_crtc) + return -ENODEV; + + crtc = encoder->funcs->atomic_sro_get_current_crtc(encoder); + if (!crtc) + return -ENODEV; + + crtc_state = drm_atomic_sro_get_crtc_state(state, crtc); + if (!crtc_state) + return -ENODEV; + + if (!crtc_state->active) + return 0; + + crtc_state->encoder_mask |= drm_encoder_mask(encoder); + crtc_state->connector_mask |= drm_connector_mask(connector); + + /* Released by __drm_atomic_helper_connector_destroy_state(). */ + drm_connector_get(connector); + conn_state->crtc = crtc; + conn_state->best_encoder = encoder; + + return 0; +} + +/* + * Same result as the bus format negotiation of a commit, which doesn't run + * during readout: the panel asks for its first format and flags, and passes + * them on through drm_atomic_helper_bridge_propagate_bus_fmt(). + */ +static int panel_bridge_readout_state(struct drm_bridge *bridge, + struct drm_atomic_sro_state *state, + struct drm_bridge_state *bridge_state, + struct drm_crtc_state *crtc_state, + struct drm_connector_state *conn_state) +{ + const struct drm_display_info *di = &conn_state->connector->display_info; + u32 format = di->num_bus_formats ? di->bus_formats[0] : MEDIA_BUS_FMT_FIXED; + + bridge_state->input_bus_cfg.format = format; + bridge_state->input_bus_cfg.flags = di->bus_flags; + bridge_state->output_bus_cfg.format = format; + bridge_state->output_bus_cfg.flags = di->bus_flags; + + return 0; +} + +/* + * The firmware left the pipeline running, so the panel is taken as part of it. + * Without this it would stay off until the first modeset. + */ +static void panel_bridge_install_state(struct drm_bridge *bridge, + struct drm_bridge_state *state) +{ + struct drm_panel *panel = drm_bridge_to_panel(bridge); + struct drm_encoder *encoder = bridge->encoder; + struct drm_crtc *crtc; + + if (!encoder->funcs || !encoder->funcs->atomic_sro_get_current_crtc) + return; + + crtc = encoder->funcs->atomic_sro_get_current_crtc(encoder); + if (!crtc || !crtc->state->active) + return; + + drm_panel_prepare(panel); + drm_panel_enable(panel); +} + static const struct drm_bridge_funcs panel_bridge_bridge_funcs = { .attach = panel_bridge_attach, .detach = panel_bridge_detach, @@ -228,6 +314,10 @@ static const struct drm_bridge_funcs panel_bridge_bridge_funcs = { .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state, .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state, .atomic_get_input_bus_fmts = drm_atomic_helper_bridge_propagate_bus_fmt, + .atomic_sro_readout_state = panel_bridge_readout_state, + .atomic_sro_compare_state = drm_atomic_helper_bridge_compare_state, + .atomic_sro_connector_readout = panel_bridge_connector_readout, + .atomic_sro_install_state = panel_bridge_install_state, .debugfs_init = panel_bridge_debugfs_init, }; @@ -600,7 +690,7 @@ void drm_panel_add(struct drm_panel *panel) mutex_unlock(&panel_lock); panel->bridge.of_node = panel->dev->of_node; - panel->bridge.ops = DRM_BRIDGE_OP_MODES; + panel->bridge.ops = DRM_BRIDGE_OP_MODES | DRM_BRIDGE_OP_CONNECTOR_HW_READOUT; panel->bridge.type = panel->connector_type; panel->bridge.pre_enable_prev_first = panel->prepare_prev_first; -- 2.39.5 ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [RFC PATCH 2/4] drm/panel: Implement state readout in the panel bridge 2026-11-16 14:27 ` [RFC PATCH 2/4] drm/panel: Implement state readout in the panel bridge Màxim Pedraza Padilla @ 2026-11-16 16:59 ` Maxime Ripard 0 siblings, 0 replies; 27+ messages in thread From: Maxime Ripard @ 2026-11-16 16:59 UTC (permalink / raw) To: Màxim Pedraza Padilla Cc: Neil Armstrong, Jessica Zhang, Jyri Sarha, Tomi Valkeinen, Uwe Kleine-König, Andrzej Hajda, Robert Foss, Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Luca Ceresoli, Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel, linux-kernel [-- Attachment #1: Type: text/plain, Size: 943 bytes --] On Mon, Nov 16, 2026 at 03:27:05PM +0100, Màxim Pedraza Padilla wrote: > The state readout core gives up if a private object doesn't implement > readout, so a driver using a panel bridge can't adopt the firmware state, > even if it implements readout itself. > > A panel has no state to read back: it's part of the pipeline if the CRTC > feeding its encoder is active. Implement the connector and bridge readout > on that assumption, relying on the encoder's > atomic_sro_get_current_crtc hook, and fill the bus configuration with what > the commit negotiation would give. > > When the state is installed, prepare and enable the panel, since nothing > else would until the first modeset. > > Assisted-by: Claude:claude-opus-5-5 > Signed-off-by: Màxim Pedraza Padilla <maximpedraza@gmail.com> That one looks super similar to https://lore.kernel.org/all/20261106-drm-state-readout-v8-38-cbe78624e1bc@kernel.org/ Maxime [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 273 bytes --] ^ permalink raw reply [flat|nested] 27+ messages in thread
* [RFC PATCH 3/4] drm/tilcdc: Implement state readout support 2026-11-16 14:27 [RFC PATCH 0/4] drm/tilcdc: Implement state readout Màxim Pedraza Padilla 2026-11-16 14:27 ` [RFC PATCH 1/4] drm/bridge: Add atomic_sro_install_state hook Màxim Pedraza Padilla 2026-11-16 14:27 ` [RFC PATCH 2/4] drm/panel: Implement state readout in the panel bridge Màxim Pedraza Padilla @ 2026-11-16 14:27 ` Màxim Pedraza Padilla 2026-11-16 17:12 ` Maxime Ripard 2026-11-16 14:27 ` [RFC PATCH 4/4] drm/panel: simple: Keep the enable GPIO as left by the bootloader Màxim Pedraza Padilla 2026-11-16 16:50 ` [RFC PATCH 0/4] drm/tilcdc: Implement state readout Maxime Ripard 4 siblings, 1 reply; 27+ messages in thread From: Màxim Pedraza Padilla @ 2026-11-16 14:27 UTC (permalink / raw) To: Maxime Ripard Cc: Neil Armstrong, Jessica Zhang, Jyri Sarha, Tomi Valkeinen, Uwe Kleine-König, Andrzej Hajda, Robert Foss, Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Luca Ceresoli, Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel, linux-kernel Reconstruct the display mode from the LCDC raster registers and read out the primary plane, to build the initial KMS state from what the bootloader left scanning out instead of resetting the controller. A splash drawn before Linux takes over stays on screen, and the first commit replaces it, with no modeset if it keeps the mode. The registers don't record everything: - The channel order isn't stored, so RGB is reported for the adopted framebuffer. It doesn't change what's on screen. - tilcdc_crtc_mode_fixup() is undone to get the requested mode, but a positive sync can't be told from a mode that doesn't specify it. Such a mode will be reported as different by the post-commit comparison. If the raster isn't running there's nothing to adopt, and the CRTC and the plane are read out as disabled. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Màxim Pedraza Padilla <maximpedraza@gmail.com> --- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 173 ++++++++++++++++++++++++ drivers/gpu/drm/tilcdc/tilcdc_drv.c | 22 ++- drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 29 +++- drivers/gpu/drm/tilcdc/tilcdc_plane.c | 106 +++++++++++++++ 4 files changed, 325 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c index f619b7a6e70d..d5c34763bd96 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c @@ -4,6 +4,7 @@ * Author: Rob Clark <robdclark@gmail.com> */ +#include <linux/clk.h> #include <linux/delay.h> #include <linux/dma-mapping.h> #include <linux/of_graph.h> @@ -11,6 +12,8 @@ #include <drm/drm_atomic.h> #include <drm/drm_atomic_helper.h> +#include <drm/drm_atomic_state_readout_helper.h> +#include <drm/drm_atomic_uapi.h> #include <drm/drm_crtc.h> #include <drm/drm_fb_dma_helper.h> #include <drm/drm_fourcc.h> @@ -711,10 +714,180 @@ static void tilcdc_crtc_hw_reset(struct drm_crtc *crtc) pm_runtime_put_sync(dev->dev); } +/* + * Reconstruct the adjusted mode from the LCDC raster registers. This is the + * inverse of the register programming done in tilcdc_crtc_set_mode(): the + * horizontal front/back porch and sync width are stored as (value - 1), the + * pixels-per-line and lines-per-panel as (value - 1) as well, while the + * vertical front/back porch are stored verbatim. On the V2 controller a few + * high order bits live in RASTER_TIMING_2. + * + * tilcdc_crtc_mode_fixup() always sets a HSYNC polarity and the skew, so they + * can be told from the registers. A positive VSYNC can't be told from a mode + * that doesn't specify it: the latter is assumed. + */ +static int tilcdc_crtc_readout_mode(struct drm_crtc *crtc, + struct drm_display_mode *mode) +{ + struct drm_device *dev = crtc->dev; + struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(dev); + u32 t0, t1, t2, ctrl; + u32 ppl, hsw, hfp, hbp; + u32 lpp, vsw, vfp, vbp; + unsigned long clk_rate; + unsigned int clkdiv; + + t0 = tilcdc_read(dev, LCDC_RASTER_TIMING_0_REG); + t1 = tilcdc_read(dev, LCDC_RASTER_TIMING_1_REG); + t2 = tilcdc_read(dev, LCDC_RASTER_TIMING_2_REG); + ctrl = tilcdc_read(dev, LCDC_CTRL_REG); + + /* Horizontal fields, low bits in TIMING_0, V2 high bits in TIMING_2. */ + ppl = (t0 >> 4) & 0x3f; + hsw = (t0 >> 10) & 0x3f; + hfp = (t0 >> 16) & 0xff; + hbp = (t0 >> 24) & 0xff; + if (priv->rev == 2) { + ppl |= ((t0 >> 3) & 0x1) << 6; + hsw |= ((t2 >> 27) & 0xf) << 6; + hfp |= (t2 & 0x3) << 8; + hbp |= ((t2 >> 4) & 0x3) << 8; + } + mode->hdisplay = (ppl + 1) << 4; + hsw += 1; + hfp += 1; + hbp += 1; + + /* Vertical fields, LPP high bit in TIMING_2 on V2. */ + lpp = t1 & 0x3ff; + if (priv->rev == 2 && (t2 & LCDC_LPP_B10)) + lpp |= 0x400; + vsw = ((t1 >> 10) & 0x3f) + 1; + vfp = (t1 >> 16) & 0xff; + vbp = (t1 >> 24) & 0xff; + mode->vdisplay = lpp + 1; + + mode->hsync_start = mode->hdisplay + hfp; + mode->hsync_end = mode->hsync_start + hsw; + mode->htotal = mode->hsync_end + hbp; + + mode->vsync_start = mode->vdisplay + vfp; + mode->vsync_end = mode->vsync_start + vsw; + mode->vtotal = mode->vsync_end + vbp; + + /* Pixel clock is the functional clock divided by the CTRL divisor. */ + clkdiv = (ctrl & LCDC_CLK_DIVISOR_MASK) >> 8; + clk_rate = clk_get_rate(priv->clk); + if (!clkdiv || !clk_rate) + return -EINVAL; + mode->clock = (clk_rate / clkdiv) / 1000; + + mode->flags |= t2 & LCDC_INVERT_HSYNC ? DRM_MODE_FLAG_NHSYNC : + DRM_MODE_FLAG_PHSYNC; + if (t2 & LCDC_INVERT_VSYNC) + mode->flags |= DRM_MODE_FLAG_NVSYNC; + + mode->hskew = hsw; + mode->flags |= DRM_MODE_FLAG_HSKEW; + + mode->type |= DRM_MODE_TYPE_DRIVER; + drm_mode_set_name(mode); + drm_mode_set_crtcinfo(mode, 0); + + return 0; +} + +static int tilcdc_crtc_readout_state(struct drm_crtc *crtc, + struct drm_atomic_sro_state *state, + struct drm_crtc_state *crtc_state) +{ + struct drm_device *dev = crtc->dev; + struct drm_display_mode adjusted = {}, mode; + int ret; + + pm_runtime_get_sync(dev->dev); + + /* Nothing to adopt unless the bootloader left the raster running. */ + if (!(tilcdc_read(dev, LCDC_RASTER_CTRL_REG) & LCDC_RASTER_ENABLE)) + goto out; + + ret = tilcdc_crtc_readout_mode(crtc, &adjusted); + if (ret) + goto err; + + /* Undo tilcdc_crtc_mode_fixup(). */ + drm_mode_copy(&mode, &adjusted); + mode.hskew = 0; + mode.flags &= ~(DRM_MODE_FLAG_HSKEW | DRM_MODE_FLAG_NHSYNC | + DRM_MODE_FLAG_PHSYNC); + if (adjusted.flags & DRM_MODE_FLAG_PHSYNC) + mode.flags |= DRM_MODE_FLAG_NHSYNC; + + ret = drm_atomic_set_mode_for_crtc(crtc_state, &mode); + if (WARN_ON(ret)) + goto err; + + drm_mode_copy(&crtc_state->adjusted_mode, &adjusted); + + crtc_state->active = true; + crtc_state->enable = true; + + /* The active plane is filled in by tilcdc_plane_readout_state(). */ + +out: + pm_runtime_put_sync(dev->dev); + return 0; + +err: + pm_runtime_put_sync(dev->dev); + return ret; +} + +static void tilcdc_crtc_install_state(struct drm_crtc *crtc, + struct drm_crtc_state *crtc_state) +{ + struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); + struct drm_device *dev = crtc->dev; + struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(dev); + + if (!crtc_state->active) + return; + + /* + * The display is already scanning out the bootloader's image. Do what + * tilcdc_crtc_enable() and tilcdc_crtc_set_mode() would have done, + * without touching the raster: keep the controller powered, enable its + * interrupts and fill in the software state derived from the mode. A + * commit that doesn't change the mode relies on it, since no modeset + * will update it: set_scanout() uses crtc->mode for the DMA ceiling. + */ + pm_runtime_get_sync(dev->dev); + + mutex_lock(&tilcdc_crtc->enable_lock); + + drm_mode_copy(&crtc->mode, &crtc_state->mode); + drm_mode_copy(&crtc->hwmode, &crtc_state->adjusted_mode); + crtc->enabled = true; + tilcdc_crtc->hvtotal_us = tilcdc_mode_hvtotal(&crtc->hwmode); + tilcdc_crtc->lcd_fck_rate = clk_get_rate(priv->clk); + tilcdc_crtc->last_vblank = ktime_get(); + + tilcdc_crtc_enable_irqs(dev); + + drm_calc_timestamping_constants(crtc, &crtc->hwmode); + drm_crtc_vblank_on(crtc); + + tilcdc_crtc->enabled = true; + mutex_unlock(&tilcdc_crtc->enable_lock); +} + static const struct drm_crtc_funcs tilcdc_crtc_funcs = { .set_config = drm_atomic_helper_set_config, .page_flip = drm_atomic_helper_page_flip, .atomic_create_state = drm_atomic_helper_crtc_create_state, + .atomic_sro_readout_state = tilcdc_crtc_readout_state, + .atomic_sro_install_state = tilcdc_crtc_install_state, + .atomic_sro_compare_state = drm_atomic_helper_crtc_compare_state, .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state, .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, .enable_vblank = tilcdc_crtc_enable_vblank, diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.c b/drivers/gpu/drm/tilcdc/tilcdc_drv.c index 1d6c9a423a41..ab88632919fa 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_drv.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.c @@ -12,6 +12,8 @@ #include <drm/clients/drm_client_setup.h> #include <drm/drm_atomic_helper.h> +#include <drm/drm_atomic_state_readout.h> +#include <drm/drm_atomic_state_readout_helper.h> #include <drm/drm_debugfs.h> #include <drm/drm_drv.h> #include <drm/drm_fbdev_dma.h> @@ -75,6 +77,12 @@ static const struct drm_mode_config_funcs mode_config_funcs = { .fb_create = drm_gem_fb_create, .atomic_check = tilcdc_atomic_check, .atomic_commit = drm_atomic_helper_commit, + .atomic_sro_readout_state = drm_atomic_helper_sro_readout_state, + .hw_reset = drm_mode_config_helper_hw_reset, +}; + +static const struct drm_mode_config_helper_funcs mode_config_helper_funcs = { + .atomic_sro_build_state = drm_atomic_helper_sro_build_state, }; static void modeset_init(struct drm_device *dev) @@ -86,6 +94,7 @@ static void modeset_init(struct drm_device *dev) dev->mode_config.max_width = priv->max_width; dev->mode_config.max_height = 2048; dev->mode_config.funcs = &mode_config_funcs; + dev->mode_config.helper_private = &mode_config_helper_funcs; } #ifdef CONFIG_CPU_FREQ @@ -422,10 +431,19 @@ static int tilcdc_pdev_probe(struct platform_device *pdev) goto unregister_cpufreq_notif; } - drm_mode_config_reset(ddev); - drm_kms_helper_poll_init(ddev); + /* + * Build the initial state from whatever the bootloader left running, + * instead of resetting the controller, so a splash drawn before Linux + * takes over is adopted rather than blanked. + */ + ret = drm_mode_config_create_initial_state(ddev); + if (ret) { + drm_err(ddev, "failed to create initial state: %d\n", ret); + goto stop_poll; + } + ret = drm_dev_register(ddev, 0); if (ret) goto stop_poll; diff --git a/drivers/gpu/drm/tilcdc/tilcdc_encoder.c b/drivers/gpu/drm/tilcdc/tilcdc_encoder.c index ac4b5beb2dd5..b3fe18f69f17 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_encoder.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_encoder.c @@ -9,12 +9,34 @@ #include <drm/drm_atomic_helper.h> #include <drm/drm_bridge.h> #include <drm/drm_bridge_connector.h> +#include <drm/drm_crtc.h> +#include <drm/drm_encoder.h> #include <drm/drm_of.h> -#include <drm/drm_simple_kms_helper.h> #include "tilcdc_drv.h" #include "tilcdc_encoder.h" +/* + * State readout needs to know which CRTC drives this encoder so the connector + * can be tied back to it. tilcdc has a single CRTC, so return the one the + * encoder was made possible for. + */ +static struct drm_crtc * +tilcdc_encoder_get_current_crtc(struct drm_encoder *encoder) +{ + struct drm_crtc *crtc; + + drm_for_each_crtc(crtc, encoder->dev) + if (encoder->possible_crtcs == drm_crtc_mask(crtc)) + return crtc; + + return NULL; +} + +static const struct drm_encoder_funcs tilcdc_encoder_funcs = { + .atomic_sro_get_current_crtc = tilcdc_encoder_get_current_crtc, +}; + static int tilcdc_attach_bridge(struct drm_device *ddev, struct drm_bridge *bridge) { @@ -51,8 +73,9 @@ int tilcdc_encoder_create(struct drm_device *ddev) else if (IS_ERR(bridge)) return PTR_ERR(bridge); - encoder = drmm_simple_encoder_alloc(ddev, struct tilcdc_encoder, - base, DRM_MODE_ENCODER_NONE); + encoder = drmm_encoder_alloc(ddev, struct tilcdc_encoder, base, + &tilcdc_encoder_funcs, + DRM_MODE_ENCODER_NONE, NULL); if (IS_ERR(encoder)) { drm_err(ddev, "drm_encoder_init() failed %pe\n", encoder); return PTR_ERR(encoder); diff --git a/drivers/gpu/drm/tilcdc/tilcdc_plane.c b/drivers/gpu/drm/tilcdc/tilcdc_plane.c index eb0a5562421f..63d936d8cfc6 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_plane.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_plane.c @@ -4,17 +4,123 @@ * Author: Jyri Sarha <jsarha@ti.com> */ +#include <linux/pm_runtime.h> + #include <drm/drm_atomic.h> #include <drm/drm_atomic_helper.h> +#include <drm/drm_atomic_state_readout.h> +#include <drm/drm_atomic_state_readout_helper.h> +#include <drm/drm_crtc.h> #include <drm/drm_fourcc.h> #include <drm/drm_framebuffer.h> +#include <drm/drm_gem_framebuffer_helper.h> #include "tilcdc_drv.h" +#include "tilcdc_regs.h" + +static const struct drm_framebuffer_funcs tilcdc_plane_readout_fb_funcs = { + .destroy = drm_gem_fb_destroy, +}; + +/* + * The RASTER_CTRL format bits only encode the pixel depth, not the channel + * order, so the RGB/BGR ambiguity is resolved in favour of the RGB variant. + * The panel wiring decides the actual order, so this only affects the format + * reported for the adopted framebuffer. + */ +static u32 tilcdc_plane_readout_format(struct drm_device *dev) +{ + u32 ctrl = tilcdc_read(dev, LCDC_RASTER_CTRL_REG); + + if (!(ctrl & LCDC_V2_TFT_24BPP_MODE)) + return DRM_FORMAT_RGB565; + if (ctrl & LCDC_V2_TFT_24BPP_UNPACK) + return DRM_FORMAT_XRGB8888; + return DRM_FORMAT_RGB888; +} + +static int tilcdc_plane_atomic_readout_state(struct drm_plane *plane, + struct drm_atomic_sro_state *state, + struct drm_plane_state *plane_state) +{ + struct drm_device *dev = plane->dev; + const struct drm_format_info *info; + struct drm_crtc_state *crtc_state; + struct drm_framebuffer *fb; + struct drm_crtc *crtc; + unsigned int w, h; + int ret; + + pm_runtime_get_sync(dev->dev); + + if (!(tilcdc_read(dev, LCDC_RASTER_CTRL_REG) & LCDC_RASTER_ENABLE)) + goto out; + + if (dev->num_crtcs != 1) { + ret = -EINVAL; + goto err; + } + crtc = list_first_entry(&dev->mode_config.crtc_list, struct drm_crtc, + head); + + crtc_state = drm_atomic_sro_get_crtc_state(state, crtc); + if (!crtc_state) { + ret = -ENODEV; + goto err; + } + + /* The tilcdc primary plane always covers the whole active area. */ + w = crtc_state->adjusted_mode.hdisplay; + h = crtc_state->adjusted_mode.vdisplay; + + info = drm_format_info(tilcdc_plane_readout_format(dev)); + if (!info) { + ret = -EINVAL; + goto err; + } + + fb = kzalloc_obj(*fb); + if (!fb) { + ret = -ENOMEM; + goto err; + } + fb->dev = dev; + fb->format = info; + fb->width = w; + fb->height = h; + fb->pitches[0] = w * (drm_format_info_bpp(info, 0) / 8); + fb->offsets[0] = 0; + + ret = drm_framebuffer_init(dev, fb, &tilcdc_plane_readout_fb_funcs); + if (ret) { + kfree(fb); + goto err; + } + + plane_state->fb = fb; + plane_state->crtc = crtc; + plane_state->src_w = w << 16; + plane_state->src_h = h << 16; + plane_state->crtc_w = w; + plane_state->crtc_h = h; + + crtc_state->plane_mask |= drm_plane_mask(plane); + +out: + pm_runtime_put_sync(dev->dev); + return 0; + +err: + pm_runtime_put_sync(dev->dev); + return ret; +} static const struct drm_plane_funcs tilcdc_plane_funcs = { .update_plane = drm_atomic_helper_update_plane, .disable_plane = drm_atomic_helper_disable_plane, .atomic_create_state = drm_atomic_helper_plane_create_state, + .atomic_sro_readout_state = tilcdc_plane_atomic_readout_state, + .atomic_sro_compare_state = drm_atomic_helper_plane_compare_state, .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, }; -- 2.39.5 ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [RFC PATCH 3/4] drm/tilcdc: Implement state readout support 2026-11-16 14:27 ` [RFC PATCH 3/4] drm/tilcdc: Implement state readout support Màxim Pedraza Padilla @ 2026-11-16 17:12 ` Maxime Ripard 2026-11-18 21:21 ` Màxim Pedraza Padilla 0 siblings, 1 reply; 27+ messages in thread From: Maxime Ripard @ 2026-11-16 17:12 UTC (permalink / raw) To: Màxim Pedraza Padilla Cc: Neil Armstrong, Jessica Zhang, Jyri Sarha, Tomi Valkeinen, Uwe Kleine-König, Andrzej Hajda, Robert Foss, Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Luca Ceresoli, Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel, linux-kernel [-- Attachment #1: Type: text/plain, Size: 17575 bytes --] On Mon, Nov 16, 2026 at 03:27:06PM +0100, Màxim Pedraza Padilla wrote: > Reconstruct the display mode from the LCDC raster registers and read out > the primary plane, to build the initial KMS state from what the bootloader > left scanning out instead of resetting the controller. A splash drawn > before Linux takes over stays on screen, and the first commit replaces it, > with no modeset if it keeps the mode. > > The registers don't record everything: > - The channel order isn't stored, so RGB is reported for the adopted > framebuffer. It doesn't change what's on screen. You mean RGB vs BGR? It's not available anywhere in a register? > - tilcdc_crtc_mode_fixup() is undone to get the requested mode, but a > positive sync can't be told from a mode that doesn't specify it. Such a > mode will be reported as different by the post-commit comparison. That's suprising as well, the polairity of signals is typically stored somewhere in a register. > > If the raster isn't running there's nothing to adopt, and the CRTC and the > plane are read out as disabled. > > Assisted-by: Claude:claude-opus-5-5 > Signed-off-by: Màxim Pedraza Padilla <maximpedraza@gmail.com> > --- > drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 173 ++++++++++++++++++++++++ > drivers/gpu/drm/tilcdc/tilcdc_drv.c | 22 ++- > drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 29 +++- > drivers/gpu/drm/tilcdc/tilcdc_plane.c | 106 +++++++++++++++ > 4 files changed, 325 insertions(+), 5 deletions(-) > > diff --git a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c > index f619b7a6e70d..d5c34763bd96 100644 > --- a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c > +++ b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c > @@ -4,6 +4,7 @@ > * Author: Rob Clark <robdclark@gmail.com> > */ > > +#include <linux/clk.h> > #include <linux/delay.h> > #include <linux/dma-mapping.h> > #include <linux/of_graph.h> > @@ -11,6 +12,8 @@ > > #include <drm/drm_atomic.h> > #include <drm/drm_atomic_helper.h> > +#include <drm/drm_atomic_state_readout_helper.h> > +#include <drm/drm_atomic_uapi.h> > #include <drm/drm_crtc.h> > #include <drm/drm_fb_dma_helper.h> > #include <drm/drm_fourcc.h> > @@ -711,10 +714,180 @@ static void tilcdc_crtc_hw_reset(struct drm_crtc *crtc) > pm_runtime_put_sync(dev->dev); > } > > +/* > + * Reconstruct the adjusted mode from the LCDC raster registers. This is the > + * inverse of the register programming done in tilcdc_crtc_set_mode(): the > + * horizontal front/back porch and sync width are stored as (value - 1), the > + * pixels-per-line and lines-per-panel as (value - 1) as well, while the > + * vertical front/back porch are stored verbatim. On the V2 controller a few > + * high order bits live in RASTER_TIMING_2. > + * > + * tilcdc_crtc_mode_fixup() always sets a HSYNC polarity and the skew, so they > + * can be told from the registers. A positive VSYNC can't be told from a mode > + * that doesn't specify it: the latter is assumed. > + */ > +static int tilcdc_crtc_readout_mode(struct drm_crtc *crtc, > + struct drm_display_mode *mode) > +{ > + struct drm_device *dev = crtc->dev; > + struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(dev); > + u32 t0, t1, t2, ctrl; > + u32 ppl, hsw, hfp, hbp; > + u32 lpp, vsw, vfp, vbp; > + unsigned long clk_rate; > + unsigned int clkdiv; > + > + t0 = tilcdc_read(dev, LCDC_RASTER_TIMING_0_REG); > + t1 = tilcdc_read(dev, LCDC_RASTER_TIMING_1_REG); > + t2 = tilcdc_read(dev, LCDC_RASTER_TIMING_2_REG); > + ctrl = tilcdc_read(dev, LCDC_CTRL_REG); > + > + /* Horizontal fields, low bits in TIMING_0, V2 high bits in TIMING_2. */ > + ppl = (t0 >> 4) & 0x3f; > + hsw = (t0 >> 10) & 0x3f; > + hfp = (t0 >> 16) & 0xff; > + hbp = (t0 >> 24) & 0xff; > + if (priv->rev == 2) { > + ppl |= ((t0 >> 3) & 0x1) << 6; > + hsw |= ((t2 >> 27) & 0xf) << 6; > + hfp |= (t2 & 0x3) << 8; > + hbp |= ((t2 >> 4) & 0x3) << 8; > + } > + mode->hdisplay = (ppl + 1) << 4; > + hsw += 1; > + hfp += 1; > + hbp += 1; > + > + /* Vertical fields, LPP high bit in TIMING_2 on V2. */ > + lpp = t1 & 0x3ff; > + if (priv->rev == 2 && (t2 & LCDC_LPP_B10)) > + lpp |= 0x400; > + vsw = ((t1 >> 10) & 0x3f) + 1; > + vfp = (t1 >> 16) & 0xff; > + vbp = (t1 >> 24) & 0xff; > + mode->vdisplay = lpp + 1; > + > + mode->hsync_start = mode->hdisplay + hfp; > + mode->hsync_end = mode->hsync_start + hsw; > + mode->htotal = mode->hsync_end + hbp; > + > + mode->vsync_start = mode->vdisplay + vfp; > + mode->vsync_end = mode->vsync_start + vsw; > + mode->vtotal = mode->vsync_end + vbp; > + > + /* Pixel clock is the functional clock divided by the CTRL divisor. */ > + clkdiv = (ctrl & LCDC_CLK_DIVISOR_MASK) >> 8; > + clk_rate = clk_get_rate(priv->clk); > + if (!clkdiv || !clk_rate) > + return -EINVAL; > + mode->clock = (clk_rate / clkdiv) / 1000; You need to give some leeway there. It's unlikely you'll ever going to be an exact match for the mode being used due to clock rounding. tilcdc_crtc_set_clk allows for a 5% (I think?) difference for example. We handle that in tidss by looking for the closest rate match and see if it falls into the specified tolerance (dispc_find_closest_refresh_rate_from_clk). I always thought of it as something that could be turned into a helper, and it's what you should be using here. > + mode->flags |= t2 & LCDC_INVERT_HSYNC ? DRM_MODE_FLAG_NHSYNC : > + DRM_MODE_FLAG_PHSYNC; > + if (t2 & LCDC_INVERT_VSYNC) > + mode->flags |= DRM_MODE_FLAG_NVSYNC; > + > + mode->hskew = hsw; > + mode->flags |= DRM_MODE_FLAG_HSKEW; > + > + mode->type |= DRM_MODE_TYPE_DRIVER; > + drm_mode_set_name(mode); > + drm_mode_set_crtcinfo(mode, 0); > + > + return 0; > +} > + > +static int tilcdc_crtc_readout_state(struct drm_crtc *crtc, > + struct drm_atomic_sro_state *state, > + struct drm_crtc_state *crtc_state) > +{ > + struct drm_device *dev = crtc->dev; > + struct drm_display_mode adjusted = {}, mode; > + int ret; > + > + pm_runtime_get_sync(dev->dev); > + > + /* Nothing to adopt unless the bootloader left the raster running. */ > + if (!(tilcdc_read(dev, LCDC_RASTER_CTRL_REG) & LCDC_RASTER_ENABLE)) > + goto out; > + > + ret = tilcdc_crtc_readout_mode(crtc, &adjusted); > + if (ret) > + goto err; > + > + /* Undo tilcdc_crtc_mode_fixup(). */ > + drm_mode_copy(&mode, &adjusted); > + mode.hskew = 0; > + mode.flags &= ~(DRM_MODE_FLAG_HSKEW | DRM_MODE_FLAG_NHSYNC | > + DRM_MODE_FLAG_PHSYNC); > + if (adjusted.flags & DRM_MODE_FLAG_PHSYNC) > + mode.flags |= DRM_MODE_FLAG_NHSYNC; > + > + ret = drm_atomic_set_mode_for_crtc(crtc_state, &mode); > + if (WARN_ON(ret)) > + goto err; > + > + drm_mode_copy(&crtc_state->adjusted_mode, &adjusted); The adjusted_mode handling should be fixed with v8 as well. > + crtc_state->active = true; > + crtc_state->enable = true; > + > + /* The active plane is filled in by tilcdc_plane_readout_state(). */ > + > +out: > + pm_runtime_put_sync(dev->dev); > + return 0; > + > +err: > + pm_runtime_put_sync(dev->dev); > + return ret; > +} > + > +static void tilcdc_crtc_install_state(struct drm_crtc *crtc, > + struct drm_crtc_state *crtc_state) > +{ > + struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); > + struct drm_device *dev = crtc->dev; > + struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(dev); > + > + if (!crtc_state->active) > + return; > + > + /* > + * The display is already scanning out the bootloader's image. Do what > + * tilcdc_crtc_enable() and tilcdc_crtc_set_mode() would have done, > + * without touching the raster: keep the controller powered, enable its > + * interrupts and fill in the software state derived from the mode. A > + * commit that doesn't change the mode relies on it, since no modeset > + * will update it: set_scanout() uses crtc->mode for the DMA ceiling. > + */ > + pm_runtime_get_sync(dev->dev); > + > + mutex_lock(&tilcdc_crtc->enable_lock); > + > + drm_mode_copy(&crtc->mode, &crtc_state->mode); > + drm_mode_copy(&crtc->hwmode, &crtc_state->adjusted_mode); > + crtc->enabled = true; > + tilcdc_crtc->hvtotal_us = tilcdc_mode_hvtotal(&crtc->hwmode); > + tilcdc_crtc->lcd_fck_rate = clk_get_rate(priv->clk); > + tilcdc_crtc->last_vblank = ktime_get(); > + > + tilcdc_crtc_enable_irqs(dev); > + > + drm_calc_timestamping_constants(crtc, &crtc->hwmode); > + drm_crtc_vblank_on(crtc); > + > + tilcdc_crtc->enabled = true; > + mutex_unlock(&tilcdc_crtc->enable_lock); > +} > + > static const struct drm_crtc_funcs tilcdc_crtc_funcs = { > .set_config = drm_atomic_helper_set_config, > .page_flip = drm_atomic_helper_page_flip, > .atomic_create_state = drm_atomic_helper_crtc_create_state, > + .atomic_sro_readout_state = tilcdc_crtc_readout_state, > + .atomic_sro_install_state = tilcdc_crtc_install_state, > + .atomic_sro_compare_state = drm_atomic_helper_crtc_compare_state, > .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state, > .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, > .enable_vblank = tilcdc_crtc_enable_vblank, > diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.c b/drivers/gpu/drm/tilcdc/tilcdc_drv.c > index 1d6c9a423a41..ab88632919fa 100644 > --- a/drivers/gpu/drm/tilcdc/tilcdc_drv.c > +++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.c > @@ -12,6 +12,8 @@ > > #include <drm/clients/drm_client_setup.h> > #include <drm/drm_atomic_helper.h> > +#include <drm/drm_atomic_state_readout.h> > +#include <drm/drm_atomic_state_readout_helper.h> > #include <drm/drm_debugfs.h> > #include <drm/drm_drv.h> > #include <drm/drm_fbdev_dma.h> > @@ -75,6 +77,12 @@ static const struct drm_mode_config_funcs mode_config_funcs = { > .fb_create = drm_gem_fb_create, > .atomic_check = tilcdc_atomic_check, > .atomic_commit = drm_atomic_helper_commit, > + .atomic_sro_readout_state = drm_atomic_helper_sro_readout_state, > + .hw_reset = drm_mode_config_helper_hw_reset, > +}; > + > +static const struct drm_mode_config_helper_funcs mode_config_helper_funcs = { > + .atomic_sro_build_state = drm_atomic_helper_sro_build_state, > }; > > static void modeset_init(struct drm_device *dev) > @@ -86,6 +94,7 @@ static void modeset_init(struct drm_device *dev) > dev->mode_config.max_width = priv->max_width; > dev->mode_config.max_height = 2048; > dev->mode_config.funcs = &mode_config_funcs; > + dev->mode_config.helper_private = &mode_config_helper_funcs; > } > > #ifdef CONFIG_CPU_FREQ > @@ -422,10 +431,19 @@ static int tilcdc_pdev_probe(struct platform_device *pdev) > goto unregister_cpufreq_notif; > } > > - drm_mode_config_reset(ddev); > - > drm_kms_helper_poll_init(ddev); > > + /* > + * Build the initial state from whatever the bootloader left running, > + * instead of resetting the controller, so a splash drawn before Linux > + * takes over is adopted rather than blanked. > + */ > + ret = drm_mode_config_create_initial_state(ddev); > + if (ret) { > + drm_err(ddev, "failed to create initial state: %d\n", ret); > + goto stop_poll; > + } > + That part is https://lore.kernel.org/all/20261116-drm-no-more-config-reset-v2-43-0bb471f4d1e0@kernel.org/ with hw_reset that sashiko pointed out It should really be there, but there's a circular dependency at the moment between these two series that I'm not quite sure how to solve. Hopefully, we will be able to merge the tidss create_initial_state conversion and break that circular dependency. Maxime > ret = drm_dev_register(ddev, 0); > if (ret) > goto stop_poll; > diff --git a/drivers/gpu/drm/tilcdc/tilcdc_encoder.c b/drivers/gpu/drm/tilcdc/tilcdc_encoder.c > index ac4b5beb2dd5..b3fe18f69f17 100644 > --- a/drivers/gpu/drm/tilcdc/tilcdc_encoder.c > +++ b/drivers/gpu/drm/tilcdc/tilcdc_encoder.c > @@ -9,12 +9,34 @@ > #include <drm/drm_atomic_helper.h> > #include <drm/drm_bridge.h> > #include <drm/drm_bridge_connector.h> > +#include <drm/drm_crtc.h> > +#include <drm/drm_encoder.h> > #include <drm/drm_of.h> > -#include <drm/drm_simple_kms_helper.h> > > #include "tilcdc_drv.h" > #include "tilcdc_encoder.h" > > +/* > + * State readout needs to know which CRTC drives this encoder so the connector > + * can be tied back to it. tilcdc has a single CRTC, so return the one the > + * encoder was made possible for. > + */ > +static struct drm_crtc * > +tilcdc_encoder_get_current_crtc(struct drm_encoder *encoder) > +{ > + struct drm_crtc *crtc; > + > + drm_for_each_crtc(crtc, encoder->dev) > + if (encoder->possible_crtcs == drm_crtc_mask(crtc)) > + return crtc; > + > + return NULL; > +} > + > +static const struct drm_encoder_funcs tilcdc_encoder_funcs = { > + .atomic_sro_get_current_crtc = tilcdc_encoder_get_current_crtc, > +}; > + > static > int tilcdc_attach_bridge(struct drm_device *ddev, struct drm_bridge *bridge) > { > @@ -51,8 +73,9 @@ int tilcdc_encoder_create(struct drm_device *ddev) > else if (IS_ERR(bridge)) > return PTR_ERR(bridge); > > - encoder = drmm_simple_encoder_alloc(ddev, struct tilcdc_encoder, > - base, DRM_MODE_ENCODER_NONE); > + encoder = drmm_encoder_alloc(ddev, struct tilcdc_encoder, base, > + &tilcdc_encoder_funcs, > + DRM_MODE_ENCODER_NONE, NULL); > if (IS_ERR(encoder)) { > drm_err(ddev, "drm_encoder_init() failed %pe\n", encoder); > return PTR_ERR(encoder); > diff --git a/drivers/gpu/drm/tilcdc/tilcdc_plane.c b/drivers/gpu/drm/tilcdc/tilcdc_plane.c > index eb0a5562421f..63d936d8cfc6 100644 > --- a/drivers/gpu/drm/tilcdc/tilcdc_plane.c > +++ b/drivers/gpu/drm/tilcdc/tilcdc_plane.c > @@ -4,17 +4,123 @@ > * Author: Jyri Sarha <jsarha@ti.com> > */ > > +#include <linux/pm_runtime.h> > + > #include <drm/drm_atomic.h> > #include <drm/drm_atomic_helper.h> > +#include <drm/drm_atomic_state_readout.h> > +#include <drm/drm_atomic_state_readout_helper.h> > +#include <drm/drm_crtc.h> > #include <drm/drm_fourcc.h> > #include <drm/drm_framebuffer.h> > +#include <drm/drm_gem_framebuffer_helper.h> > > #include "tilcdc_drv.h" > +#include "tilcdc_regs.h" > + > +static const struct drm_framebuffer_funcs tilcdc_plane_readout_fb_funcs = { > + .destroy = drm_gem_fb_destroy, > +}; > + > +/* > + * The RASTER_CTRL format bits only encode the pixel depth, not the channel > + * order, so the RGB/BGR ambiguity is resolved in favour of the RGB variant. > + * The panel wiring decides the actual order, so this only affects the format > + * reported for the adopted framebuffer. > + */ > +static u32 tilcdc_plane_readout_format(struct drm_device *dev) > +{ > + u32 ctrl = tilcdc_read(dev, LCDC_RASTER_CTRL_REG); > + > + if (!(ctrl & LCDC_V2_TFT_24BPP_MODE)) > + return DRM_FORMAT_RGB565; > + if (ctrl & LCDC_V2_TFT_24BPP_UNPACK) > + return DRM_FORMAT_XRGB8888; > + return DRM_FORMAT_RGB888; > +} > + > +static int tilcdc_plane_atomic_readout_state(struct drm_plane *plane, > + struct drm_atomic_sro_state *state, > + struct drm_plane_state *plane_state) > +{ > + struct drm_device *dev = plane->dev; > + const struct drm_format_info *info; > + struct drm_crtc_state *crtc_state; > + struct drm_framebuffer *fb; > + struct drm_crtc *crtc; > + unsigned int w, h; > + int ret; > + > + pm_runtime_get_sync(dev->dev); > + > + if (!(tilcdc_read(dev, LCDC_RASTER_CTRL_REG) & LCDC_RASTER_ENABLE)) > + goto out; > + > + if (dev->num_crtcs != 1) { > + ret = -EINVAL; > + goto err; > + } > + crtc = list_first_entry(&dev->mode_config.crtc_list, struct drm_crtc, > + head); > + > + crtc_state = drm_atomic_sro_get_crtc_state(state, crtc); > + if (!crtc_state) { > + ret = -ENODEV; > + goto err; > + } > + > + /* The tilcdc primary plane always covers the whole active area. */ > + w = crtc_state->adjusted_mode.hdisplay; > + h = crtc_state->adjusted_mode.vdisplay; > + > + info = drm_format_info(tilcdc_plane_readout_format(dev)); > + if (!info) { > + ret = -EINVAL; > + goto err; > + } > + > + fb = kzalloc_obj(*fb); > + if (!fb) { > + ret = -ENOMEM; > + goto err; > + } > + fb->dev = dev; > + fb->format = info; > + fb->width = w; > + fb->height = h; > + fb->pitches[0] = w * (drm_format_info_bpp(info, 0) / 8); > + fb->offsets[0] = 0; > + > + ret = drm_framebuffer_init(dev, fb, &tilcdc_plane_readout_fb_funcs); > + if (ret) { > + kfree(fb); > + goto err; > + } > + > + plane_state->fb = fb; > + plane_state->crtc = crtc; > + plane_state->src_w = w << 16; > + plane_state->src_h = h << 16; > + plane_state->crtc_w = w; > + plane_state->crtc_h = h; > + > + crtc_state->plane_mask |= drm_plane_mask(plane); > + > +out: > + pm_runtime_put_sync(dev->dev); > + return 0; > + > +err: > + pm_runtime_put_sync(dev->dev); > + return ret; > +} > > static const struct drm_plane_funcs tilcdc_plane_funcs = { > .update_plane = drm_atomic_helper_update_plane, > .disable_plane = drm_atomic_helper_disable_plane, > .atomic_create_state = drm_atomic_helper_plane_create_state, > + .atomic_sro_readout_state = tilcdc_plane_atomic_readout_state, > + .atomic_sro_compare_state = drm_atomic_helper_plane_compare_state, > .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, > .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, > }; > -- > 2.39.5 > [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 269 bytes --] ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [RFC PATCH 3/4] drm/tilcdc: Implement state readout support 2026-11-16 17:12 ` Maxime Ripard @ 2026-11-18 21:21 ` Màxim Pedraza Padilla 2026-11-20 14:01 ` Maxime Ripard 2026-11-24 14:11 ` Màxim Pedraza Padilla 0 siblings, 2 replies; 27+ messages in thread From: Màxim Pedraza Padilla @ 2026-11-18 21:21 UTC (permalink / raw) To: Maxime Ripard Cc: Neil Armstrong, Jessica Zhang, Jyri Sarha, Tomi Valkeinen, Uwe Kleine-König, Andrzej Hajda, Robert Foss, Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Luca Ceresoli, Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel, linux-kernel On Mon, Nov 16, 2026 at 06:12:50PM +0100, Maxime Ripard wrote: > > - The channel order isn't stored, so RGB is reported for the adopted > > framebuffer. It doesn't change what's on screen. > > You mean RGB vs BGR? It's not available anywhere in a register? Right, there's no swap bit in the LCDC. The order comes from the board wiring, which the DT describes with blue-and-red-wiring, and the driver already uses it to pick the format list. I'll use that in the readout instead of always reporting RGB. > > - tilcdc_crtc_mode_fixup() is undone to get the requested mode, but a > > positive sync can't be told from a mode that doesn't specify it. > > That's suprising as well, the polairity of signals is typically stored > somewhere in a register. It is, in RASTER_TIMING_2 (INVERT_HSYNC and INVERT_VSYNC), so the actual polarity is read back fine. What's lost is the difference between a mode that asks for DRM_MODE_FLAG_PHSYNC and one with no polarity flag at all: both end up with the same register value, and the readout can only pick one of them. I'll reword the commit message. > You need to give some leeway there. It's unlikely you'll ever going to > be an exact match for the mode being used due to clock rounding. > [...] > We handle that in tidss by looking for the closest rate match and see if > it falls into the specified tolerance > (dispc_find_closest_refresh_rate_from_clk). I always thought of it as > something that could be turned into a helper, and it's what you should > be using here. Makes sense, I'll use the same approach in tilcdc, and see if it can be turned into a common helper along the way. > That part is > https://lore.kernel.org/all/20261116-drm-no-more-config-reset-v2-43-0bb471f4d1e0@kernel.org/ > with hw_reset that sashiko pointed out Ok, I'll drop it from my patch and base on top of that one. Thanks, Màxim ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [RFC PATCH 3/4] drm/tilcdc: Implement state readout support 2026-11-18 21:21 ` Màxim Pedraza Padilla @ 2026-11-20 14:01 ` Maxime Ripard 2026-11-23 10:55 ` Màxim Pedraza Padilla 2026-11-24 14:11 ` Màxim Pedraza Padilla 1 sibling, 1 reply; 27+ messages in thread From: Maxime Ripard @ 2026-11-20 14:01 UTC (permalink / raw) To: Màxim Pedraza Padilla Cc: Neil Armstrong, Jessica Zhang, Jyri Sarha, Tomi Valkeinen, Uwe Kleine-König, Andrzej Hajda, Robert Foss, Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Luca Ceresoli, Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel, linux-kernel [-- Attachment #1: Type: text/plain, Size: 876 bytes --] On Wed, Nov 18, 2026 at 10:21:14PM +0100, Màxim Pedraza Padilla wrote: > On Mon, Nov 16, 2026 at 06:12:50PM +0100, Maxime Ripard wrote: > > > - tilcdc_crtc_mode_fixup() is undone to get the requested mode, but a > > > positive sync can't be told from a mode that doesn't specify it. > > > > That's suprising as well, the polairity of signals is typically stored > > somewhere in a register. > > It is, in RASTER_TIMING_2 (INVERT_HSYNC and INVERT_VSYNC), so the actual > polarity is read back fine. What's lost is the difference between a mode > that asks for DRM_MODE_FLAG_PHSYNC and one with no polarity flag at all: > both end up with the same register value, and the readout can only pick > one of them. I'll reword the commit message. I think the real solution in this case is to fix the panel to report its polarity properly. Thanks again, Maxime [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 273 bytes --] ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [RFC PATCH 3/4] drm/tilcdc: Implement state readout support 2026-11-20 14:01 ` Maxime Ripard @ 2026-11-23 10:55 ` Màxim Pedraza Padilla 0 siblings, 0 replies; 27+ messages in thread From: Màxim Pedraza Padilla @ 2026-11-23 10:55 UTC (permalink / raw) To: Maxime Ripard Cc: Neil Armstrong, Jessica Zhang, Jyri Sarha, Tomi Valkeinen, Uwe Kleine-König, Andrzej Hajda, Robert Foss, Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Luca Ceresoli, Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel, linux-kernel On Fri, Nov 20, 2026 at 03:01:50PM +0100, Maxime Ripard wrote: > I think the real solution in this case is to fix the panel to report its > polarity properly. Agreed. The panel datasheet specifies negative HSYNC and VSYNC, and the timings in this board's DT didn't say so. U-Boot programs both as active low (IHS and IVS set in RASTER_TIMING_2). Adding vsync-active = <0> works as expected. hsync-active = <0> doesn't, though: tilcdc_crtc_mode_fixup() flips the HSYNC polarity of the adjusted mode, so DRM_MODE_FLAG_NHSYNC ends up with IHS cleared, i.e. an active high HSYNC pin according to the AM335x TRM (SPRUH73L, table 13-26). With no HSYNC flag at all the pin is active low, matching both the panel and U-Boot, and the readout matches the DT mode. The fixup comment says the LCDC aligns VS on the second edge of HS, but I couldn't find anything about it in the TRM. Do you know if it's still needed? If it is, I guess the readout should keep undoing it; if not, a fix there would let the DT describe the panel as it is. Thanks, Màxim ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [RFC PATCH 3/4] drm/tilcdc: Implement state readout support 2026-11-18 21:21 ` Màxim Pedraza Padilla 2026-11-20 14:01 ` Maxime Ripard @ 2026-11-24 14:11 ` Màxim Pedraza Padilla 2026-11-24 14:38 ` Tomi Valkeinen 2026-11-25 10:07 ` Maxime Ripard 1 sibling, 2 replies; 27+ messages in thread From: Màxim Pedraza Padilla @ 2026-11-24 14:11 UTC (permalink / raw) To: Maxime Ripard Cc: Neil Armstrong, Jessica Zhang, Jyri Sarha, Tomi Valkeinen, Uwe Kleine-König, Andrzej Hajda, Robert Foss, Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Luca Ceresoli, Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel, linux-kernel On Wed, Nov 18, 2026 at 10:21:14PM +0100, Màxim Pedraza Padilla wrote: > Makes sense, I'll use the same approach in tilcdc, and see if it can be > turned into a common helper along the way. A follow-up on this one, now that I've rebased on v9. I ended up doing it differently, so I'd rather explain why before sending the next version. The tidss approach rounds the clock to the closest standard refresh rate. Panels driven by tilcdc often don't use one: with the timings from its datasheet, the panel on this board runs at 56.8 Hz (33.3 MHz), which would be read back as 60 Hz and 35.19 MHz. The adopted mode would then never match the panel mode, even with U-Boot programming exactly the same one. So the readout keeps the actual rate (rounded to the nearest kHz), and tilcdc's CRTC compare hook accepts a 1% difference on the pixel clock before calling drm_atomic_helper_crtc_compare_state(). That's what the leeway is needed for: tilcdc_crtc_set_clk() only gets as close as the clock tree allows. I checked it with modesets at 20 pixel clocks between 16.9 and 45 MHz: the PLL misses some of them by up to 0.015%, which the exact comparison reported as mismatches, and they all pass now. Testing on v9 also found a bug in my readout: re-enabling the CRTC (ACTIVE=0 then 1) with the adopted framebuffer crashed in set_scanout(), since it has no GEM object. It now keeps the DMA address the bootloader programmed. The rest of the comments are addressed as discussed: the format follows blue-and-red-wiring, the panel describes its polarity in the DT, and the initial state comes from your no-more-config-reset patch. With v9 all the comparison warnings I reported are gone. I'll send the next version on top of v9 and that patch. Thanks, Màxim ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [RFC PATCH 3/4] drm/tilcdc: Implement state readout support 2026-11-24 14:11 ` Màxim Pedraza Padilla @ 2026-11-24 14:38 ` Tomi Valkeinen 2026-11-25 10:11 ` Maxime Ripard 2026-11-25 10:15 ` Màxim Pedraza Padilla 2026-11-25 10:07 ` Maxime Ripard 1 sibling, 2 replies; 27+ messages in thread From: Tomi Valkeinen @ 2026-11-24 14:38 UTC (permalink / raw) To: Màxim Pedraza Padilla, Maxime Ripard Cc: Neil Armstrong, Jessica Zhang, Jyri Sarha, Uwe Kleine-König, Andrzej Hajda, Robert Foss, Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Luca Ceresoli, Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel, linux-kernel Hi, On 24/11/2026 16:11, Màxim Pedraza Padilla wrote: > On Wed, Nov 18, 2026 at 10:21:14PM +0100, Màxim Pedraza Padilla wrote: >> Makes sense, I'll use the same approach in tilcdc, and see if it can be >> turned into a common helper along the way. > > A follow-up on this one, now that I've rebased on v9. I ended up doing > it differently, so I'd rather explain why before sending the next > version. > > The tidss approach rounds the clock to the closest standard refresh rate. > Panels driven by tilcdc often don't use one: with the timings from its > datasheet, the panel on this board runs at 56.8 Hz (33.3 MHz), which would > be read back as 60 Hz and 35.19 MHz. The adopted mode would then never > match the panel mode, even with U-Boot programming exactly the same one. I felt that approach was a bit odd (and if I recall right, failed with my OLDI panel), and in my tidss version I just used the clock rate directly from the clk_get_rate() (see dispc_vp_readout_mode): https://git.kernel.org/pub/scm/linux/kernel/git/tomba/linux.git/commit/?h=ti/boot-splash-v8.5&id=b08e04d7ff284234aebd048982c98cc5368affa8 Tomi ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [RFC PATCH 3/4] drm/tilcdc: Implement state readout support 2026-11-24 14:38 ` Tomi Valkeinen @ 2026-11-25 10:11 ` Maxime Ripard 2026-11-25 11:43 ` Tomi Valkeinen 2026-11-25 10:15 ` Màxim Pedraza Padilla 1 sibling, 1 reply; 27+ messages in thread From: Maxime Ripard @ 2026-11-25 10:11 UTC (permalink / raw) To: Tomi Valkeinen Cc: Màxim Pedraza Padilla, Neil Armstrong, Jessica Zhang, Jyri Sarha, Uwe Kleine-König, Andrzej Hajda, Robert Foss, Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Luca Ceresoli, Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel, linux-kernel [-- Attachment #1: Type: text/plain, Size: 1588 bytes --] On Tue, Nov 24, 2026 at 04:38:43PM +0200, Tomi Valkeinen wrote: > Hi, > > On 24/11/2026 16:11, Màxim Pedraza Padilla wrote: > > On Wed, Nov 18, 2026 at 10:21:14PM +0100, Màxim Pedraza Padilla wrote: > > > Makes sense, I'll use the same approach in tilcdc, and see if it can be > > > turned into a common helper along the way. > > > > A follow-up on this one, now that I've rebased on v9. I ended up doing > > it differently, so I'd rather explain why before sending the next > > version. > > > > The tidss approach rounds the clock to the closest standard refresh rate. > > Panels driven by tilcdc often don't use one: with the timings from its > > datasheet, the panel on this board runs at 56.8 Hz (33.3 MHz), which would > > be read back as 60 Hz and 35.19 MHz. The adopted mode would then never > > match the panel mode, even with U-Boot programming exactly the same one. > > I felt that approach was a bit odd (and if I recall right, failed with my > OLDI panel), and in my tidss version I just used the clock rate directly > from the clk_get_rate() (see dispc_vp_readout_mode): The problem is that you're losing information when setting the clock. Especially for panels where you don't really have an established set of pixel clocks, the clock is very likely to not be able to give the exact frequency you asked for. So when you're reading the clock frequency, the mode you're reading and the one you'd set at first modeset will not necessarily match, so you need to take that difference into account and try to get back on your feet. Maxime [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 273 bytes --] ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [RFC PATCH 3/4] drm/tilcdc: Implement state readout support 2026-11-25 10:11 ` Maxime Ripard @ 2026-11-25 11:43 ` Tomi Valkeinen 2026-11-25 12:21 ` Maxime Ripard 0 siblings, 1 reply; 27+ messages in thread From: Tomi Valkeinen @ 2026-11-25 11:43 UTC (permalink / raw) To: Maxime Ripard Cc: Màxim Pedraza Padilla, Neil Armstrong, Jessica Zhang, Jyri Sarha, Uwe Kleine-König, Andrzej Hajda, Robert Foss, Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Luca Ceresoli, Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel, linux-kernel Hi, On 25/11/2026 12:11, Maxime Ripard wrote: > On Tue, Nov 24, 2026 at 04:38:43PM +0200, Tomi Valkeinen wrote: >> Hi, >> >> On 24/11/2026 16:11, Màxim Pedraza Padilla wrote: >>> On Wed, Nov 18, 2026 at 10:21:14PM +0100, Màxim Pedraza Padilla wrote: >>>> Makes sense, I'll use the same approach in tilcdc, and see if it can be >>>> turned into a common helper along the way. >>> >>> A follow-up on this one, now that I've rebased on v9. I ended up doing >>> it differently, so I'd rather explain why before sending the next >>> version. >>> >>> The tidss approach rounds the clock to the closest standard refresh rate. >>> Panels driven by tilcdc often don't use one: with the timings from its >>> datasheet, the panel on this board runs at 56.8 Hz (33.3 MHz), which would >>> be read back as 60 Hz and 35.19 MHz. The adopted mode would then never >>> match the panel mode, even with U-Boot programming exactly the same one. >> >> I felt that approach was a bit odd (and if I recall right, failed with my >> OLDI panel), and in my tidss version I just used the clock rate directly >> from the clk_get_rate() (see dispc_vp_readout_mode): > > The problem is that you're losing information when setting the clock. > Especially for panels where you don't really have an established set of > pixel clocks, the clock is very likely to not be able to give the exact > frequency you asked for. > > So when you're reading the clock frequency, the mode you're reading and > the one you'd set at first modeset will not necessarily match, so you > need to take that difference into account and try to get back on your > feet. If I understand correctly, your code in tidss is trying to guess the pclk rate in (say) the simple-panel driver via assuming the refresh rate is one of the standard ones? I don't think that works... Even if the target refresh rate in the panel driver is close to (or exactly) those standard ones, it won't be the same clock rate except by luck. And u-boot may have a different PLL calculation, or different pclk in its dtso. I think the u-boot part should be fixed just by "fix your bootloader": if you want SRO to work, make your bootloader use the same videomode (including pclk) as the kernel. But even then it won't work. If the simple panel states pclk as 150.274 MHz, it will cause the HW to set 150.0 MHz, and the SRO in this series will calculate 150.124675 MHz. This will cause a full modeset, and also the SRO check will given an error. So... First, I think at least in the adjusted_mode we should have the real pclk. The SRO check should pass only an equals check there. For mode's pclk, I think setting the actual pclk makes sense, at least more than guessing it. Or could we, at that stage, see what modes the connector advertises, and pick a clock from there? If we can't get the pclks from the connector, the mode->clock won't match, and we should either skip checking that in the SRO checks, or have plenty of tolerance. I think it still leads to a full modeset, but can the driver check if setting the mode->clock would results in the current pclk, and somehow abort the full modeset? Tomi ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [RFC PATCH 3/4] drm/tilcdc: Implement state readout support 2026-11-25 11:43 ` Tomi Valkeinen @ 2026-11-25 12:21 ` Maxime Ripard 2026-11-25 14:55 ` Tomi Valkeinen 0 siblings, 1 reply; 27+ messages in thread From: Maxime Ripard @ 2026-11-25 12:21 UTC (permalink / raw) To: Tomi Valkeinen Cc: Màxim Pedraza Padilla, Neil Armstrong, Jessica Zhang, Jyri Sarha, Uwe Kleine-König, Andrzej Hajda, Robert Foss, Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Luca Ceresoli, Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel, linux-kernel [-- Attachment #1: Type: text/plain, Size: 5111 bytes --] On Wed, Nov 25, 2026 at 01:43:55PM +0200, Tomi Valkeinen wrote: > Hi, > > On 25/11/2026 12:11, Maxime Ripard wrote: > > On Tue, Nov 24, 2026 at 04:38:43PM +0200, Tomi Valkeinen wrote: > > > Hi, > > > > > > On 24/11/2026 16:11, Màxim Pedraza Padilla wrote: > > > > On Wed, Nov 18, 2026 at 10:21:14PM +0100, Màxim Pedraza Padilla wrote: > > > > > Makes sense, I'll use the same approach in tilcdc, and see if it can be > > > > > turned into a common helper along the way. > > > > > > > > A follow-up on this one, now that I've rebased on v9. I ended up doing > > > > it differently, so I'd rather explain why before sending the next > > > > version. > > > > > > > > The tidss approach rounds the clock to the closest standard refresh rate. > > > > Panels driven by tilcdc often don't use one: with the timings from its > > > > datasheet, the panel on this board runs at 56.8 Hz (33.3 MHz), which would > > > > be read back as 60 Hz and 35.19 MHz. The adopted mode would then never > > > > match the panel mode, even with U-Boot programming exactly the same one. > > > > > > I felt that approach was a bit odd (and if I recall right, failed with my > > > OLDI panel), and in my tidss version I just used the clock rate directly > > > from the clk_get_rate() (see dispc_vp_readout_mode): > > > > The problem is that you're losing information when setting the clock. > > Especially for panels where you don't really have an established set of > > pixel clocks, the clock is very likely to not be able to give the exact > > frequency you asked for. > > > > So when you're reading the clock frequency, the mode you're reading and > > the one you'd set at first modeset will not necessarily match, so you > > need to take that difference into account and try to get back on your > > feet. > > If I understand correctly, your code in tidss is trying to guess the pclk > rate in (say) the simple-panel driver via assuming the refresh rate is one > of the standard ones? Yes, and I have yet to see a panel that would have a refresh rate that isn't one of the standard ones. > I don't think that works... Even if the target refresh rate in the panel > driver is close to (or exactly) those standard ones, it won't be the same > clock rate except by luck. And u-boot may have a different PLL calculation, > or different pclk in its dtso. > > I think the u-boot part should be fixed just by "fix your bootloader": if > you want SRO to work, make your bootloader use the same videomode (including > pclk) as the kernel. > > But even then it won't work. If the simple panel states pclk as 150.274 MHz, > it will cause the HW to set 150.0 MHz, and the SRO in this series will > calculate 150.124675 MHz. This will cause a full modeset, and also the SRO > check will given an error. Not really, because it will try to match the closest, and then try to keep that within a defined tolerance. So, in your example, if the expected pclk is 150.274MHz, and what's programmed in hardware is 150MHz (which also is the closest pick we can find), then it will be happy with 150MHz. And let's turn this around: what happens if your expected pclk is 150.274MHz, and the actual rate programmed by u-boot is, say, 124MHz? Should we do a modeset then? It's also a matter of consistency within the framework. The framework expects the "ideal" mode everywhere. How is the pclk actually programmed isn't tracked anywhere. So, if you have a regular modeset, we'd have mode and adjusted_mode have the "ideal" pclk, but in the case of SRO we'd have the actual one, possibly forever? > So... First, I think at least in the adjusted_mode we should have the real > pclk. You can't have that. The closest you'd have would be calling clk_round_rate() at atomic_check, but you have no guarantee that it's actually going to be the same rate by the time you call clk_set_rate(). Either way, assuming we would do that, it would give you adjusted_mode. You'd still need mode, and mode is what is shown to userspace. > The SRO check should pass only an equals check there. For mode's pclk, > I think setting the actual pclk makes sense, at least more than guessing it. > Or could we, at that stage, see what modes the connector advertises, and > pick a clock from there? It's difficult, because then you assume that A) the bootloader will have used a mode reported by the monitor and B) crtcs need to be readout before connectors. > If we can't get the pclks from the connector, the mode->clock won't match, > and we should either skip checking that in the SRO checks, or have plenty of > tolerance. tidss has 5% of tolerance when most of the drivers have .5%. How much do you need? > I think it still leads to a full modeset, but can the driver check if > setting the mode->clock would results in the current pclk, and somehow > abort the full modeset? I'd rather discuss an actual bug here. Do you have a case you can share where the logic we currently have doesn't work and is not an instance of poor panel timings? Maxime [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 273 bytes --] ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [RFC PATCH 3/4] drm/tilcdc: Implement state readout support 2026-11-25 12:21 ` Maxime Ripard @ 2026-11-25 14:55 ` Tomi Valkeinen 2026-11-27 16:11 ` Maxime Ripard 0 siblings, 1 reply; 27+ messages in thread From: Tomi Valkeinen @ 2026-11-25 14:55 UTC (permalink / raw) To: Maxime Ripard Cc: Màxim Pedraza Padilla, Neil Armstrong, Jessica Zhang, Jyri Sarha, Uwe Kleine-König, Andrzej Hajda, Robert Foss, Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Luca Ceresoli, Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel, linux-kernel Hi, On 25/11/2026 14:21, Maxime Ripard wrote: > On Wed, Nov 25, 2026 at 01:43:55PM +0200, Tomi Valkeinen wrote: >> Hi, >> >> On 25/11/2026 12:11, Maxime Ripard wrote: >>> On Tue, Nov 24, 2026 at 04:38:43PM +0200, Tomi Valkeinen wrote: >>>> Hi, >>>> >>>> On 24/11/2026 16:11, Màxim Pedraza Padilla wrote: >>>>> On Wed, Nov 18, 2026 at 10:21:14PM +0100, Màxim Pedraza Padilla wrote: >>>>>> Makes sense, I'll use the same approach in tilcdc, and see if it can be >>>>>> turned into a common helper along the way. >>>>> >>>>> A follow-up on this one, now that I've rebased on v9. I ended up doing >>>>> it differently, so I'd rather explain why before sending the next >>>>> version. >>>>> >>>>> The tidss approach rounds the clock to the closest standard refresh rate. >>>>> Panels driven by tilcdc often don't use one: with the timings from its >>>>> datasheet, the panel on this board runs at 56.8 Hz (33.3 MHz), which would >>>>> be read back as 60 Hz and 35.19 MHz. The adopted mode would then never >>>>> match the panel mode, even with U-Boot programming exactly the same one. >>>> >>>> I felt that approach was a bit odd (and if I recall right, failed with my >>>> OLDI panel), and in my tidss version I just used the clock rate directly >>>> from the clk_get_rate() (see dispc_vp_readout_mode): >>> >>> The problem is that you're losing information when setting the clock. >>> Especially for panels where you don't really have an established set of >>> pixel clocks, the clock is very likely to not be able to give the exact >>> frequency you asked for. >>> >>> So when you're reading the clock frequency, the mode you're reading and >>> the one you'd set at first modeset will not necessarily match, so you >>> need to take that difference into account and try to get back on your >>> feet. >> >> If I understand correctly, your code in tidss is trying to guess the pclk >> rate in (say) the simple-panel driver via assuming the refresh rate is one >> of the standard ones? > > Yes, and I have yet to see a panel that would have a refresh rate that > isn't one of the standard ones. They often have quite wide ranges, and don't define clear nominal timings and refresh rate. But I agree, almost always one can have a 60Hz timing with them. That doesn't mean our panel/bridge drivers would define such neat clocks. In my experience, the panel's timings are often based on X, which probably is something that happened to work on one platform, and was good enough. Those can be fixed to result timings close to the 60 Hz, but then we risk breaking the panel for some platforms. Bridge drivers can also adjust the adjusted_mode's clock when they have special needs (DSI). >> I don't think that works... Even if the target refresh rate in the panel >> driver is close to (or exactly) those standard ones, it won't be the same >> clock rate except by luck. And u-boot may have a different PLL calculation, >> or different pclk in its dtso. >> >> I think the u-boot part should be fixed just by "fix your bootloader": if >> you want SRO to work, make your bootloader use the same videomode (including >> pclk) as the kernel. >> >> But even then it won't work. If the simple panel states pclk as 150.274 MHz, >> it will cause the HW to set 150.0 MHz, and the SRO in this series will >> calculate 150.124675 MHz. This will cause a full modeset, and also the SRO >> check will given an error. > > Not really, because it will try to match the closest, and then try to > keep that within a defined tolerance. So, in your example, if the > expected pclk is 150.274MHz, and what's programmed in hardware is 150MHz > (which also is the closest pick we can find), then it will be happy with > 150MHz. What will be happy? *ERROR* crtc-0 configuration mismatch in mode expected "1920x1200": 60 150274 1920 1952 2004 2028 1200 1224 1232 1235 0x48 0x0, got "1920x1200": 60 150124 1920 1952 2004 2028 1200 1224 1232 1235 0x40 0x5 > And let's turn this around: what happens if your expected pclk is > 150.274MHz, and the actual rate programmed by u-boot is, say, 124MHz? > > Should we do a modeset then? If clk_set_rate(150274000) results in pclk of 124MHz, then it's the correct mode, no modeset needed. There are cases like that, but I'm fine with not targeting them at least initially. > It's also a matter of consistency within the framework. The framework > expects the "ideal" mode everywhere. How is the pclk actually programmed > isn't tracked anywhere. So, if you have a regular modeset, we'd have > mode and adjusted_mode have the "ideal" pclk, but in the case of SRO > we'd have the actual one, possibly forever? With regular modeset, we'd have the ideal pclk in mode, and the real pclk in adjusted_mode, right? My worry is that we'll not be able to guess the ideal pclk very well. Maybe that can be solved with fixing the panel drivers when we encounter non-ideal timings, and having a clear rule that the provided timings have to result in a "normal" refresh rate, even if the platform has to adjust them when applying. >> So... First, I think at least in the adjusted_mode we should have the real >> pclk. > > You can't have that. The closest you'd have would be calling > clk_round_rate() at atomic_check, but you have no guarantee that it's > actually going to be the same rate by the time you call clk_set_rate(). Why is that? Can't we do the clk_round_rate in SRO? The SRO state has the adjusted timings, doesn't it? Yes, I guess clk_round_rate() there and clk_set_rate() later might result in different rates in theory, but can that happen in practice? If the clock is being kept on, it's unlikely that its parent clocks would change. So it's not immediately clear to me when this could happen. > Either way, assuming we would do that, it would give you adjusted_mode. > You'd still need mode, and mode is what is shown to userspace. Yes. >> The SRO check should pass only an equals check there. For mode's pclk, >> I think setting the actual pclk makes sense, at least more than guessing it. >> Or could we, at that stage, see what modes the connector advertises, and >> pick a clock from there? > > It's difficult, because then you assume that A) the bootloader will have > used a mode reported by the monitor and B) crtcs need to be readout > before connectors. Isn't A) needed anyway for fully working SRO and smooth transition to the userspace app's display? The userspace's modeset will most likely use the preferred mode from the display, and if that's different than the bootloader's it will then cause a full modeset. Or how do apps usually work? Do they try to get the current mode from the crtc, and use that, even if it's not the connector's advertised default mode? >> If we can't get the pclks from the connector, the mode->clock won't match, >> and we should either skip checking that in the SRO checks, or have plenty of >> tolerance. > > tidss has 5% of tolerance when most of the drivers have .5%. How much do > you need? I was referring to the SRO code, which currently gives errors if the modes don't match exactly. >> I think it still leads to a full modeset, but can the driver check if >> setting the mode->clock would results in the current pclk, and somehow >> abort the full modeset? > > I'd rather discuss an actual bug here. Do you have a case you can share > where the logic we currently have doesn't work and is not an instance of > poor panel timings? It's the case with the OLDI panel. You should be able to test it with AM62-SK even without an actual panel, just load the k3-am625-sk-microtips-mf101hie-panel.dtbo. Ah, actually, there's the touchscreen in the dtbo, so you may need to disable that in the dtso. Although I guess even if it's enabled, you'll just possibly see an error from the touch driver, and it doesn't affect the display. So even if you don't have bootloader that enabled the OLDI panel, you should see the configuration mismatch errors. Tomi ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [RFC PATCH 3/4] drm/tilcdc: Implement state readout support 2026-11-25 14:55 ` Tomi Valkeinen @ 2026-11-27 16:11 ` Maxime Ripard 2026-11-27 17:39 ` Tomi Valkeinen 0 siblings, 1 reply; 27+ messages in thread From: Maxime Ripard @ 2026-11-27 16:11 UTC (permalink / raw) To: Tomi Valkeinen Cc: Màxim Pedraza Padilla, Neil Armstrong, Jessica Zhang, Jyri Sarha, Uwe Kleine-König, Andrzej Hajda, Robert Foss, Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Luca Ceresoli, Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel, linux-kernel [-- Attachment #1: Type: text/plain, Size: 11753 bytes --] On Wed, Nov 25, 2026 at 04:55:51PM +0200, Tomi Valkeinen wrote: > Hi, > > On 25/11/2026 14:21, Maxime Ripard wrote: > > On Wed, Nov 25, 2026 at 01:43:55PM +0200, Tomi Valkeinen wrote: > > > Hi, > > > > > > On 25/11/2026 12:11, Maxime Ripard wrote: > > > > On Tue, Nov 24, 2026 at 04:38:43PM +0200, Tomi Valkeinen wrote: > > > > > Hi, > > > > > > > > > > On 24/11/2026 16:11, Màxim Pedraza Padilla wrote: > > > > > > On Wed, Nov 18, 2026 at 10:21:14PM +0100, Màxim Pedraza Padilla wrote: > > > > > > > Makes sense, I'll use the same approach in tilcdc, and see if it can be > > > > > > > turned into a common helper along the way. > > > > > > > > > > > > A follow-up on this one, now that I've rebased on v9. I ended up doing > > > > > > it differently, so I'd rather explain why before sending the next > > > > > > version. > > > > > > > > > > > > The tidss approach rounds the clock to the closest standard refresh rate. > > > > > > Panels driven by tilcdc often don't use one: with the timings from its > > > > > > datasheet, the panel on this board runs at 56.8 Hz (33.3 MHz), which would > > > > > > be read back as 60 Hz and 35.19 MHz. The adopted mode would then never > > > > > > match the panel mode, even with U-Boot programming exactly the same one. > > > > > > > > > > I felt that approach was a bit odd (and if I recall right, failed with my > > > > > OLDI panel), and in my tidss version I just used the clock rate directly > > > > > from the clk_get_rate() (see dispc_vp_readout_mode): > > > > > > > > The problem is that you're losing information when setting the clock. > > > > Especially for panels where you don't really have an established set of > > > > pixel clocks, the clock is very likely to not be able to give the exact > > > > frequency you asked for. > > > > > > > > So when you're reading the clock frequency, the mode you're reading and > > > > the one you'd set at first modeset will not necessarily match, so you > > > > need to take that difference into account and try to get back on your > > > > feet. > > > > > > If I understand correctly, your code in tidss is trying to guess the pclk > > > rate in (say) the simple-panel driver via assuming the refresh rate is one > > > of the standard ones? > > > > Yes, and I have yet to see a panel that would have a refresh rate that > > isn't one of the standard ones. > > They often have quite wide ranges, and don't define clear nominal timings > and refresh rate. But I agree, almost always one can have a 60Hz timing with > them. > > That doesn't mean our panel/bridge drivers would define such neat clocks. In > my experience, the panel's timings are often based on X, which probably is > something that happened to work on one platform, and was good enough. Those > can be fixed to result timings close to the 60 Hz, but then we risk breaking > the panel for some platforms. I don't think we should accomodate those. If the pixel clock is not properly defined, then we need to fix the panel. And if some panel drivers make some controllers to setup something wrong, then we need to fix the controller too. And it's not like having an off pixel clock is harmless, at the very least it means that the vblank interrupts don't get send at their expected frequency anymore. It would sound like a much better solution to me to have something that takes a display_timing and adjust the blanking periods and / or the porches within their acceptable range to make sure we always have the right refresh rate despite having a rounded clock. > Bridge drivers can also adjust the adjusted_mode's clock when they have > special needs (DSI). > > > > I don't think that works... Even if the target refresh rate in the panel > > > driver is close to (or exactly) those standard ones, it won't be the same > > > clock rate except by luck. And u-boot may have a different PLL calculation, > > > or different pclk in its dtso. > > > > > > I think the u-boot part should be fixed just by "fix your bootloader": if > > > you want SRO to work, make your bootloader use the same videomode (including > > > pclk) as the kernel. > > > > > > But even then it won't work. If the simple panel states pclk as 150.274 MHz, > > > it will cause the HW to set 150.0 MHz, and the SRO in this series will > > > calculate 150.124675 MHz. This will cause a full modeset, and also the SRO > > > check will given an error. > > > > Not really, because it will try to match the closest, and then try to > > keep that within a defined tolerance. So, in your example, if the > > expected pclk is 150.274MHz, and what's programmed in hardware is 150MHz > > (which also is the closest pick we can find), then it will be happy with > > 150MHz. > > What will be happy? > > *ERROR* crtc-0 configuration mismatch in mode expected "1920x1200": 60 > 150274 1920 1952 2004 2028 1200 1224 1232 1235 0x48 0x0, got "1920x1200": 60 > 150124 1920 1952 2004 2028 1200 1224 1232 1235 0x40 0x5 Can you share more about what is going on here? What frequency is setup by U-Boot? is happening only for the first modeset, or all the others? Is the rounding of the clock similar between u-boot and the kernel? > > And let's turn this around: what happens if your expected pclk is > > 150.274MHz, and the actual rate programmed by u-boot is, say, 124MHz? > > > > Should we do a modeset then? > > If clk_set_rate(150274000) results in pclk of 124MHz, then it's the correct > mode, no modeset needed. There are cases like that, but I'm fine with not > targeting them at least initially. No it's not the correct mode, it's completely off, a bootloader bug, and the best thing the kernel needs to be doing is go through a new modeset to fix it. > > It's also a matter of consistency within the framework. The framework > > expects the "ideal" mode everywhere. How is the pclk actually programmed > > isn't tracked anywhere. So, if you have a regular modeset, we'd have > > mode and adjusted_mode have the "ideal" pclk, but in the case of SRO > > we'd have the actual one, possibly forever? > > With regular modeset, we'd have the ideal pclk in mode, and the real pclk in > adjusted_mode, right? Except that you have no way to make sure that the clock in adjusted_mode is going to be the "real" one. > My worry is that we'll not be able to guess the ideal pclk very well. Maybe > that can be solved with fixing the panel drivers when we encounter non-ideal > timings, and having a clear rule that the provided timings have to result in > a "normal" refresh rate, even if the platform has to adjust them when > applying. Time will tell I guess, but I'd rather keep that in the back of our heads as a last resort than admit defeat from the get-go :) Because, yes, I do believe a lot of drivers are broken and it's an opportunity to find and fix them. > > > So... First, I think at least in the adjusted_mode we should have the real > > > pclk. > > > > You can't have that. The closest you'd have would be calling > > clk_round_rate() at atomic_check, but you have no guarantee that it's > > actually going to be the same rate by the time you call clk_set_rate(). > > Why is that? Because clk_round_rate() depends on the current context for that clock: its parent rates, the ranges the other users have requested, etc. Between atomic_check and atomic_commit, that context might have change and you might have a different result. > Can't we do the clk_round_rate in SRO? The SRO state has the adjusted > timings, doesn't it? I'm not really concerned about SRO, I'm concerned about everything after it: the mode we expose to userspace, the consistency between an SRO state and a committed state, etc. > Yes, I guess clk_round_rate() there and clk_set_rate() later might result in > different rates in theory, but can that happen in practice? If the clock is > being kept on, it's unlikely that its parent clocks would change. On some platforms, maybe. On others it's absolutely the case. That's why we have clk_set_rate_exclusive(), and why https://lore.kernel.org/linux-clk/20260327-clk-scaling-v8-0-86cd0aba3c5f@redhat.com/ is a thing. > So it's not immediately clear to me when this could happen. Even from a purely software PoV, if you have two users, and one calls clk_round_rate for 42MHz which isn't rounded, and then the second does a clk_set_max_rate(40MHz), then clk_round_rate will now return 40MHz. > > Either way, assuming we would do that, it would give you adjusted_mode. > > You'd still need mode, and mode is what is shown to userspace. > > Yes. > > > > The SRO check should pass only an equals check there. For mode's pclk, > > > I think setting the actual pclk makes sense, at least more than guessing it. > > > Or could we, at that stage, see what modes the connector advertises, and > > > pick a clock from there? > > > > It's difficult, because then you assume that A) the bootloader will have > > used a mode reported by the monitor and B) crtcs need to be readout > > before connectors. > > Isn't A) needed anyway for fully working SRO and smooth transition to the > userspace app's display? The userspace's modeset will most likely use the > preferred mode from the display, and if that's different than the > bootloader's it will then cause a full modeset. It's a reasonable assumption at first, but my point was more about "What happens if it isn't?" Also, once SRO works, I would expect the splash screen, plymouth, and so on to revert the logic and go for something like "if it's enabled, use that, otherwise use the preferred mode and do a modeset". > Or how do apps usually work? Do they try to get the current mode from the > crtc, and use that, even if it's not the connector's advertised default > mode? > > > > If we can't get the pclks from the connector, the mode->clock won't match, > > > and we should either skip checking that in the SRO checks, or have plenty of > > > tolerance. > > > > tidss has 5% of tolerance when most of the drivers have .5%. How much do > > you need? > > I was referring to the SRO code, which currently gives errors if the modes > don't match exactly. Which isn't true? There are warnings, and we're literally discussing a function that does introduce a tolerance when trying to match the modes. Let's turn this around. I think we both agree that matching exactly won't work. I guess it wouldn't be hard to agree that a panel running at half the refresh rate, with different polarities, or with different timings shouldn't be considered a match. So my question is: where do you want to draw the line? > > > I think it still leads to a full modeset, but can the driver check if > > > setting the mode->clock would results in the current pclk, and somehow > > > abort the full modeset? > > > > I'd rather discuss an actual bug here. Do you have a case you can share > > where the logic we currently have doesn't work and is not an instance of > > poor panel timings? > > It's the case with the OLDI panel. You should be able to test it with > AM62-SK even without an actual panel, just load the > k3-am625-sk-microtips-mf101hie-panel.dtbo. Ah, actually, there's the > touchscreen in the dtbo, so you may need to disable that in the dtso. > Although I guess even if it's enabled, you'll just possibly see an error > from the touch driver, and it doesn't affect the display. > > So even if you don't have bootloader that enabled the OLDI panel, you should > see the configuration mismatch errors. But it wouldn't have enabled the clock at the right rate though, right? Maxime [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 273 bytes --] ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [RFC PATCH 3/4] drm/tilcdc: Implement state readout support 2026-11-27 16:11 ` Maxime Ripard @ 2026-11-27 17:39 ` Tomi Valkeinen 0 siblings, 0 replies; 27+ messages in thread From: Tomi Valkeinen @ 2026-11-27 17:39 UTC (permalink / raw) To: Maxime Ripard Cc: Màxim Pedraza Padilla, Neil Armstrong, Jessica Zhang, Jyri Sarha, Uwe Kleine-König, Andrzej Hajda, Robert Foss, Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Luca Ceresoli, Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel, linux-kernel Hi, On 27/11/2026 18:11, Maxime Ripard wrote: > On Wed, Nov 25, 2026 at 04:55:51PM +0200, Tomi Valkeinen wrote: >> Hi, >> >> On 25/11/2026 14:21, Maxime Ripard wrote: >>> On Wed, Nov 25, 2026 at 01:43:55PM +0200, Tomi Valkeinen wrote: >>>> Hi, >>>> >>>> On 25/11/2026 12:11, Maxime Ripard wrote: >>>>> On Tue, Nov 24, 2026 at 04:38:43PM +0200, Tomi Valkeinen wrote: >>>>>> Hi, >>>>>> >>>>>> On 24/11/2026 16:11, Màxim Pedraza Padilla wrote: >>>>>>> On Wed, Nov 18, 2026 at 10:21:14PM +0100, Màxim Pedraza Padilla wrote: >>>>>>>> Makes sense, I'll use the same approach in tilcdc, and see if it can be >>>>>>>> turned into a common helper along the way. >>>>>>> >>>>>>> A follow-up on this one, now that I've rebased on v9. I ended up doing >>>>>>> it differently, so I'd rather explain why before sending the next >>>>>>> version. >>>>>>> >>>>>>> The tidss approach rounds the clock to the closest standard refresh rate. >>>>>>> Panels driven by tilcdc often don't use one: with the timings from its >>>>>>> datasheet, the panel on this board runs at 56.8 Hz (33.3 MHz), which would >>>>>>> be read back as 60 Hz and 35.19 MHz. The adopted mode would then never >>>>>>> match the panel mode, even with U-Boot programming exactly the same one. >>>>>> >>>>>> I felt that approach was a bit odd (and if I recall right, failed with my >>>>>> OLDI panel), and in my tidss version I just used the clock rate directly >>>>>> from the clk_get_rate() (see dispc_vp_readout_mode): >>>>> >>>>> The problem is that you're losing information when setting the clock. >>>>> Especially for panels where you don't really have an established set of >>>>> pixel clocks, the clock is very likely to not be able to give the exact >>>>> frequency you asked for. >>>>> >>>>> So when you're reading the clock frequency, the mode you're reading and >>>>> the one you'd set at first modeset will not necessarily match, so you >>>>> need to take that difference into account and try to get back on your >>>>> feet. >>>> >>>> If I understand correctly, your code in tidss is trying to guess the pclk >>>> rate in (say) the simple-panel driver via assuming the refresh rate is one >>>> of the standard ones? >>> >>> Yes, and I have yet to see a panel that would have a refresh rate that >>> isn't one of the standard ones. >> >> They often have quite wide ranges, and don't define clear nominal timings >> and refresh rate. But I agree, almost always one can have a 60Hz timing with >> them. >> >> That doesn't mean our panel/bridge drivers would define such neat clocks. In >> my experience, the panel's timings are often based on X, which probably is >> something that happened to work on one platform, and was good enough. Those >> can be fixed to result timings close to the 60 Hz, but then we risk breaking >> the panel for some platforms. > > I don't think we should accomodate those. If the pixel clock is not > properly defined, then we need to fix the panel. And if some panel > drivers make some controllers to setup something wrong, then we need to > fix the controller too. > > And it's not like having an off pixel clock is harmless, at the very > least it means that the vblank interrupts don't get send at their > expected frequency anymore. > > It would sound like a much better solution to me to have something that > takes a display_timing and adjust the blanking periods and / or the > porches within their acceptable range to make sure we always have the > right refresh rate despite having a rounded clock. In my experience, changes to the blanking & porches will break the display much more easily than changing the clock. In any case, I'm not against the idea of calculating ideal pclk here, and fixing the panel drivers. But I am saying that it may not be so easy as it may feel =). >> Bridge drivers can also adjust the adjusted_mode's clock when they have >> special needs (DSI). >> >>>> I don't think that works... Even if the target refresh rate in the panel >>>> driver is close to (or exactly) those standard ones, it won't be the same >>>> clock rate except by luck. And u-boot may have a different PLL calculation, >>>> or different pclk in its dtso. >>>> >>>> I think the u-boot part should be fixed just by "fix your bootloader": if >>>> you want SRO to work, make your bootloader use the same videomode (including >>>> pclk) as the kernel. >>>> >>>> But even then it won't work. If the simple panel states pclk as 150.274 MHz, >>>> it will cause the HW to set 150.0 MHz, and the SRO in this series will >>>> calculate 150.124675 MHz. This will cause a full modeset, and also the SRO >>>> check will given an error. >>> >>> Not really, because it will try to match the closest, and then try to >>> keep that within a defined tolerance. So, in your example, if the >>> expected pclk is 150.274MHz, and what's programmed in hardware is 150MHz >>> (which also is the closest pick we can find), then it will be happy with >>> 150MHz. >> >> What will be happy? >> >> *ERROR* crtc-0 configuration mismatch in mode expected "1920x1200": 60 >> 150274 1920 1952 2004 2028 1200 1224 1232 1235 0x48 0x0, got "1920x1200": 60 >> 150124 1920 1952 2004 2028 1200 1224 1232 1235 0x40 0x5 > > Can you share more about what is going on here? What frequency is setup > by U-Boot? is happening only for the first modeset, or all the others? > Is the rounding of the clock similar between u-boot and the kernel? This is with AM62-SK and OLDI. It's the example I gave. This happens with every modeset, as the panel driver has a different clock than what the SRO comes up with. But I think your point is that the panel driver has to be fixed, so that it uses 150.124 MHz clock, which is the one the SRO will come up with. Even then, I'm not sure if it'll work. If the clock is supposed to be 60 Hz exact, but the actual clock in the HW is low enough, won't SRO then think it's 60 * 1000/1001, which results in a different ideal clock? >>> And let's turn this around: what happens if your expected pclk is >>> 150.274MHz, and the actual rate programmed by u-boot is, say, 124MHz? >>> >>> Should we do a modeset then? >> >> If clk_set_rate(150274000) results in pclk of 124MHz, then it's the correct >> mode, no modeset needed. There are cases like that, but I'm fine with not >> targeting them at least initially. > > No it's not the correct mode, it's completely off, a bootloader bug, and > the best thing the kernel needs to be doing is go through a new modeset > to fix it. It's either that or no display at all. The numbers were invented, but on some platforms the clock rates can be very coarse, especially on higher clocks. That's the origin of the 5% tolerance you've complained about. K3 DSS doesn't need it as the PLL is quite ok, but OMAP DSS definitely has very coarse clock rates (on some OMAP versions). That said, maybe those SoCs are not our prime targets here. But, again, the point is, this may not be so easy to get right in a general sense as it may sound. >>> It's also a matter of consistency within the framework. The framework >>> expects the "ideal" mode everywhere. How is the pclk actually programmed >>> isn't tracked anywhere. So, if you have a regular modeset, we'd have >>> mode and adjusted_mode have the "ideal" pclk, but in the case of SRO >>> we'd have the actual one, possibly forever? >> >> With regular modeset, we'd have the ideal pclk in mode, and the real pclk in >> adjusted_mode, right? > > Except that you have no way to make sure that the clock in adjusted_mode > is going to be the "real" one. Indeed, for some reason I thought the drivers read it back. But it's just an adjusted target clock. >> My worry is that we'll not be able to guess the ideal pclk very well. Maybe >> that can be solved with fixing the panel drivers when we encounter non-ideal >> timings, and having a clear rule that the provided timings have to result in >> a "normal" refresh rate, even if the platform has to adjust them when >> applying. > > Time will tell I guess, but I'd rather keep that in the back of our > heads as a last resort than admit defeat from the get-go :) Because, > yes, I do believe a lot of drivers are broken and it's an opportunity to > find and fix them. > >>>> So... First, I think at least in the adjusted_mode we should have the real >>>> pclk. >>> >>> You can't have that. The closest you'd have would be calling >>> clk_round_rate() at atomic_check, but you have no guarantee that it's >>> actually going to be the same rate by the time you call clk_set_rate(). >> >> Why is that? > > Because clk_round_rate() depends on the current context for that clock: > its parent rates, the ranges the other users have requested, etc. > Between atomic_check and atomic_commit, that context might have change > and you might have a different result. > >> Can't we do the clk_round_rate in SRO? The SRO state has the adjusted >> timings, doesn't it? > > I'm not really concerned about SRO, I'm concerned about everything after > it: the mode we expose to userspace, the consistency between an SRO > state and a committed state, etc. > >> Yes, I guess clk_round_rate() there and clk_set_rate() later might result in >> different rates in theory, but can that happen in practice? If the clock is >> being kept on, it's unlikely that its parent clocks would change. > > On some platforms, maybe. On others it's absolutely the case. That's why > we have clk_set_rate_exclusive(), and why > https://lore.kernel.org/linux-clk/20260327-clk-scaling-v8-0-86cd0aba3c5f@redhat.com/ > is a thing. But is that an actual problem here? The main use case here is keeping the display unchanged from bootloader to the first userspace modeset. If the clock is changed while the bootsplash is being shown, the use case is already broken. >> So it's not immediately clear to me when this could happen. > > Even from a purely software PoV, if you have two users, and one calls > clk_round_rate for 42MHz which isn't rounded, and then the second does a > clk_set_max_rate(40MHz), then clk_round_rate will now return 40MHz. > >>> Either way, assuming we would do that, it would give you adjusted_mode. >>> You'd still need mode, and mode is what is shown to userspace. >> >> Yes. >> >>>> The SRO check should pass only an equals check there. For mode's pclk, >>>> I think setting the actual pclk makes sense, at least more than guessing it. >>>> Or could we, at that stage, see what modes the connector advertises, and >>>> pick a clock from there? >>> >>> It's difficult, because then you assume that A) the bootloader will have >>> used a mode reported by the monitor and B) crtcs need to be readout >>> before connectors. >> >> Isn't A) needed anyway for fully working SRO and smooth transition to the >> userspace app's display? The userspace's modeset will most likely use the >> preferred mode from the display, and if that's different than the >> bootloader's it will then cause a full modeset. > > It's a reasonable assumption at first, but my point was more about "What > happens if it isn't?" My assumption is that for bootsplash and SRO to work, bootloader and kernel must work correctly together, they have to do things just right (e.g. the clock config has to be the same, including clock tree, etc). That said, it's great if we can make this work more generally too =). > Also, once SRO works, I would expect the splash screen, plymouth, and so > on to revert the logic and go for something like "if it's enabled, use > that, otherwise use the preferred mode and do a modeset". Ok, that changes the case a bit, and allows a bit more leeway. But... If we do that, isn't it the same or better to just use the HW clock rate as the mode clock? Then the userspace sees the "real" mode. Then again, now that I think about it, userspace doesn't see that for normal modesetting either, does it... It just knows the mode it's trying to set. So a DRM app can never know what the real refresh rate is, except measuring vblanks? >> Or how do apps usually work? Do they try to get the current mode from the >> crtc, and use that, even if it's not the connector's advertised default >> mode? >> >>>> If we can't get the pclks from the connector, the mode->clock won't match, >>>> and we should either skip checking that in the SRO checks, or have plenty of >>>> tolerance. >>> >>> tidss has 5% of tolerance when most of the drivers have .5%. How much do >>> you need? >> >> I was referring to the SRO code, which currently gives errors if the modes >> don't match exactly. > > Which isn't true? There are warnings, and we're literally discussing a Well, the warnings say "*ERROR*" =). > function that does introduce a tolerance when trying to match the modes. > > Let's turn this around. I think we both agree that matching exactly > won't work. I guess it wouldn't be hard to agree that a panel running at > half the refresh rate, with different polarities, or with different > timings shouldn't be considered a match. I'm not sure about that. Depends =). We can never recreate the original mode from the HW registers fully, but I think on some platforms it will be further away than on some. The clock is the prime example. Without display PLL, the pixel clock rates can be quite far away. > So my question is: where do you want to draw the line? I'm fine with the ideal mode calculations with some kind of small tolerance. We can initially target platforms that have adequate hardware. But I feel that this could eventually have to be a platform specific thing, unless SoCs without good video PLLs are a thing from the distant past. Perhaps we can worry about them if we get there. In any case, if SRO is more an opt-in than enabled by default, we're safe. >>>> I think it still leads to a full modeset, but can the driver check if >>>> setting the mode->clock would results in the current pclk, and somehow >>>> abort the full modeset? >>> >>> I'd rather discuss an actual bug here. Do you have a case you can share >>> where the logic we currently have doesn't work and is not an instance of >>> poor panel timings? >> >> It's the case with the OLDI panel. You should be able to test it with >> AM62-SK even without an actual panel, just load the >> k3-am625-sk-microtips-mf101hie-panel.dtbo. Ah, actually, there's the >> touchscreen in the dtbo, so you may need to disable that in the dtso. >> Although I guess even if it's enabled, you'll just possibly see an error >> from the touch driver, and it doesn't affect the display. >> >> So even if you don't have bootloader that enabled the OLDI panel, you should >> see the configuration mismatch errors. > > But it wouldn't have enabled the clock at the right rate though, right? No, it wouldn't have OLDI enabled at all (nor the clocks), but you can still test as you'll see the warnings in normal modesetting if the SRO comparison doesn't match. So a normal modeset with panel's clock at e.g. 150.274 MHz, triggers the SRO, which comes up with 150.124 MHz, and the check fails. Tomi ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [RFC PATCH 3/4] drm/tilcdc: Implement state readout support 2026-11-24 14:38 ` Tomi Valkeinen 2026-11-25 10:11 ` Maxime Ripard @ 2026-11-25 10:15 ` Màxim Pedraza Padilla 2026-11-25 11:53 ` Tomi Valkeinen 1 sibling, 1 reply; 27+ messages in thread From: Màxim Pedraza Padilla @ 2026-11-25 10:15 UTC (permalink / raw) To: Tomi Valkeinen Cc: Maxime Ripard, Neil Armstrong, Jessica Zhang, Jyri Sarha, Uwe Kleine-König, Andrzej Hajda, Robert Foss, Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Luca Ceresoli, Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel, linux-kernel On Tue, Nov 24, 2026 at 04:38:43PM +0200, Tomi Valkeinen wrote: > I felt that approach was a bit odd (and if I recall right, failed with > my OLDI panel), and in my tidss version I just used the clock rate > directly from the clk_get_rate() (see dispc_vp_readout_mode): Thanks, good to know I'm not the only one it didn't work for. v2 does the same: the functional clock rate divided by the LCDC divider, rounded to the nearest kHz. What I added is a 1% tolerance on the pixel clock in tilcdc's CRTC compare hook. When tilcdc_crtc_set_clk() can't get the exact rate, the clock read back after a commit differs from the mode by a few kHz: here, asking for 16941 kHz gets 16940.69 kHz from the display PLL. Out of 20 pixel clocks between 16.9 and 45 MHz, four were off by up to 0.015% and the exact comparison reported them as mismatches. Since you know tilcdc: do you know why tilcdc_crtc_mode_fixup() flips the HSYNC polarity? Its comment says the LCDC aligns VS on the second edge of HS, but I couldn't find that in the AM335x TRM, where IHS directly sets the polarity of the HSYNC pin. As it is, a panel needing an active low HSYNC has to leave hsync-active out of its DT timings. Thanks, Màxim ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [RFC PATCH 3/4] drm/tilcdc: Implement state readout support 2026-11-25 10:15 ` Màxim Pedraza Padilla @ 2026-11-25 11:53 ` Tomi Valkeinen 2026-11-25 13:36 ` Màxim Pedraza Padilla 0 siblings, 1 reply; 27+ messages in thread From: Tomi Valkeinen @ 2026-11-25 11:53 UTC (permalink / raw) To: Màxim Pedraza Padilla Cc: Maxime Ripard, Neil Armstrong, Jessica Zhang, Jyri Sarha, Uwe Kleine-König, Andrzej Hajda, Robert Foss, Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Luca Ceresoli, Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel, linux-kernel Hi, On 25/11/2026 12:15, Màxim Pedraza Padilla wrote: > On Tue, Nov 24, 2026 at 04:38:43PM +0200, Tomi Valkeinen wrote: >> I felt that approach was a bit odd (and if I recall right, failed with >> my OLDI panel), and in my tidss version I just used the clock rate >> directly from the clk_get_rate() (see dispc_vp_readout_mode): > > Thanks, good to know I'm not the only one it didn't work for. v2 does the > same: the functional clock rate divided by the LCDC divider, rounded to > the nearest kHz. > > What I added is a 1% tolerance on the pixel clock in tilcdc's CRTC > compare hook. When tilcdc_crtc_set_clk() can't get the exact rate, the > clock read back after a commit differs from the mode by a few kHz: here, > asking for 16941 kHz gets 16940.69 kHz from the display PLL. Out of 20 > pixel clocks between 16.9 and 45 MHz, four were off by up to 0.015% and > the exact comparison reported them as mismatches. > > Since you know tilcdc: do you know why tilcdc_crtc_mode_fixup() flips the > HSYNC polarity? Its comment says the LCDC aligns VS on the second edge of > HS, but I couldn't find that in the AM335x TRM, where IHS directly sets > the polarity of the HSYNC pin. As it is, a panel needing an active low > HSYNC has to leave hsync-active out of its DT timings. Sorry, I don't remember. It's been quite a while, and that part wasn't my code. The original commit says: + * We use adjusted_mode, to fixup sync by aligning both rising + * edges and add HSKEW offset to let the slave encoder fix it up. which sounds like the encoder (I think at that time there was really just a single encoder used) supports hskew, so the encoder then adjusted the syncs horizontally, and also used the correct polarities. You could have a look at the old kernel sources. If I had to guess, the hack helps on some particular panel/encoder. And breaks some other. If you remove the hack, you get it the other way around =). Tomi ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [RFC PATCH 3/4] drm/tilcdc: Implement state readout support 2026-11-25 11:53 ` Tomi Valkeinen @ 2026-11-25 13:36 ` Màxim Pedraza Padilla 0 siblings, 0 replies; 27+ messages in thread From: Màxim Pedraza Padilla @ 2026-11-25 13:36 UTC (permalink / raw) To: Tomi Valkeinen Cc: Maxime Ripard, Neil Armstrong, Jessica Zhang, Jyri Sarha, Uwe Kleine-König, Andrzej Hajda, Robert Foss, Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Luca Ceresoli, Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel, linux-kernel On Wed, Nov 25, 2026 at 01:53:23PM +0200, Tomi Valkeinen wrote: > If I had to guess, the hack helps on some particular panel/encoder. And > breaks some other. If you remove the hack, you get it the other way > around =). Thanks a lot for digging into it, that's useful context. I'll leave the hack alone then: the readout just undoes it, and on this board the panel DT leaves hsync-active out, so the pin ends up active low as the panel expects. I'll have a look at the old sources if it ever becomes a problem. Thanks, Màxim ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [RFC PATCH 3/4] drm/tilcdc: Implement state readout support 2026-11-24 14:11 ` Màxim Pedraza Padilla 2026-11-24 14:38 ` Tomi Valkeinen @ 2026-11-25 10:07 ` Maxime Ripard 2026-11-25 13:31 ` Màxim Pedraza Padilla 1 sibling, 1 reply; 27+ messages in thread From: Maxime Ripard @ 2026-11-25 10:07 UTC (permalink / raw) To: Màxim Pedraza Padilla Cc: Neil Armstrong, Jessica Zhang, Jyri Sarha, Tomi Valkeinen, Uwe Kleine-König, Andrzej Hajda, Robert Foss, Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Luca Ceresoli, Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel, linux-kernel [-- Attachment #1: Type: text/plain, Size: 1847 bytes --] On Tue, Nov 24, 2026 at 03:11:19PM +0100, Màxim Pedraza Padilla wrote: > On Wed, Nov 18, 2026 at 10:21:14PM +0100, Màxim Pedraza Padilla wrote: > > Makes sense, I'll use the same approach in tilcdc, and see if it can be > > turned into a common helper along the way. > > A follow-up on this one, now that I've rebased on v9. I ended up doing > it differently, so I'd rather explain why before sending the next > version. > > The tidss approach rounds the clock to the closest standard refresh rate. > Panels driven by tilcdc often don't use one: with the timings from its > datasheet, the panel on this board runs at 56.8 Hz (33.3 MHz), which would > be read back as 60 Hz and 35.19 MHz. The adopted mode would then never > match the panel mode, even with U-Boot programming exactly the same one. This is *very* surprising. Do you have the datasheet available somewhere? > So the readout keeps the actual rate (rounded to the nearest kHz), and > tilcdc's CRTC compare hook accepts a 1% difference on the pixel clock > before calling drm_atomic_helper_crtc_compare_state(). That's what the > leeway is needed for: tilcdc_crtc_set_clk() only gets as close as the > clock tree allows. I checked it with modesets at 20 pixel clocks between > 16.9 and 45 MHz: the PLL misses some of them by up to 0.015%, which the > exact comparison reported as mismatches, and they all pass now. Yes, that's why we need the above mentionned helper, and more generally why a lot of drivers allow some deviation from the clock. > Testing on v9 also found a bug in my readout: re-enabling the CRTC > (ACTIVE=0 then 1) with the adopted framebuffer crashed in set_scanout(), > since it has no GEM object. It now keeps the DMA address the bootloader > programmed. It should be fixed in v10, I'm now creating a gem object. Maxime [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 273 bytes --] ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [RFC PATCH 3/4] drm/tilcdc: Implement state readout support 2026-11-25 10:07 ` Maxime Ripard @ 2026-11-25 13:31 ` Màxim Pedraza Padilla 2026-11-27 9:53 ` Maxime Ripard 0 siblings, 1 reply; 27+ messages in thread From: Màxim Pedraza Padilla @ 2026-11-25 13:31 UTC (permalink / raw) To: Maxime Ripard Cc: Neil Armstrong, Jessica Zhang, Jyri Sarha, Tomi Valkeinen, Uwe Kleine-König, Andrzej Hajda, Robert Foss, Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Luca Ceresoli, Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel, linux-kernel On Wed, Nov 25, 2026 at 11:07:17AM +0100, Maxime Ripard wrote: > > The tidss approach rounds the clock to the closest standard refresh rate. > > Panels driven by tilcdc often don't use one: with the timings from its > > datasheet, the panel on this board runs at 56.8 Hz (33.3 MHz), which would > > be read back as 60 Hz and 35.19 MHz. The adopted mode would then never > > match the panel mode, even with U-Boot programming exactly the same one. > > This is *very* surprising. Do you have the datasheet available somewhere? You were right to be surprised, I got it wrong, sorry. The datasheet counts the sync pulse within the back porch: a line is 1056 clocks (800 + 46 + 210) and a frame 525 lines (480 + 23 + 22), so 60.06 Hz at 33.3 MHz. The board DT added the sync lengths on top of the porches, hence the 56.8 Hz. The bootloader had the same mistake, and also ran the panel at 16.94 MHz. With the timings fixed, and the bootloader programming the same mode as the kernel, the readout adopts exactly the DT mode (33300 kHz, 60 Hz), and the first commit from userspace with that mode doesn't need a modeset at all. > > So the readout keeps the actual rate (rounded to the nearest kHz), and > > tilcdc's CRTC compare hook accepts a 1% difference on the pixel clock > > before calling drm_atomic_helper_crtc_compare_state(). [...] > > Yes, that's why we need the above mentionned helper, and more generally > why a lot of drivers allow some deviation from the clock. If it helps, I can write that helper: dispc_find_closest_refresh_rate_from_clk() turned into a DRM helper, with the tolerance as a parameter since drivers want different ones (5% for tidss, 0.5% for most). Something like: int drm_mode_set_clock_from_rate(struct drm_display_mode *mode, unsigned long rate, unsigned int tolerance); with the tolerance in per mille, so 0.5% can be expressed. It would fill mode->clock with the ideal clock of the closest standard refresh rate, or return an error if none is close enough. tidss would then use it, and so would tilcdc instead of its own compare hook. I'm also fine with you folding it into your series if you'd rather do it yourself, just let me know. > > Testing on v9 also found a bug in my readout: re-enabling the CRTC > > (ACTIVE=0 then 1) with the adopted framebuffer crashed in set_scanout(), > > since it has no GEM object. It now keeps the DMA address the bootloader > > programmed. > > It should be fixed in v10, I'm now creating a gem object. Great, I'll drop it when rebasing on v10. Thanks, Màxim ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [RFC PATCH 3/4] drm/tilcdc: Implement state readout support 2026-11-25 13:31 ` Màxim Pedraza Padilla @ 2026-11-27 9:53 ` Maxime Ripard 0 siblings, 0 replies; 27+ messages in thread From: Maxime Ripard @ 2026-11-27 9:53 UTC (permalink / raw) To: Màxim Pedraza Padilla Cc: Neil Armstrong, Jessica Zhang, Jyri Sarha, Tomi Valkeinen, Uwe Kleine-König, Andrzej Hajda, Robert Foss, Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Luca Ceresoli, Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel, linux-kernel [-- Attachment #1: Type: text/plain, Size: 2472 bytes --] Hi, On Wed, Nov 25, 2026 at 02:31:49PM +0100, Màxim Pedraza Padilla wrote: > On Wed, Nov 25, 2026 at 11:07:17AM +0100, Maxime Ripard wrote: > > > The tidss approach rounds the clock to the closest standard refresh rate. > > > Panels driven by tilcdc often don't use one: with the timings from its > > > datasheet, the panel on this board runs at 56.8 Hz (33.3 MHz), which would > > > be read back as 60 Hz and 35.19 MHz. The adopted mode would then never > > > match the panel mode, even with U-Boot programming exactly the same one. > > > > This is *very* surprising. Do you have the datasheet available somewhere? > > You were right to be surprised, I got it wrong, sorry. The datasheet > counts the sync pulse within the back porch: a line is 1056 clocks > (800 + 46 + 210) and a frame 525 lines (480 + 23 + 22), so 60.06 Hz at > 33.3 MHz. The board DT added the sync lengths on top of the porches, > hence the 56.8 Hz. The bootloader had the same mistake, and also ran the > panel at 16.94 MHz. > > With the timings fixed, and the bootloader programming the same mode as > the kernel, the readout adopts exactly the DT mode (33300 kHz, 60 Hz), > and the first commit from userspace with that mode doesn't need a > modeset at all. Awesome :) > > > So the readout keeps the actual rate (rounded to the nearest kHz), and > > > tilcdc's CRTC compare hook accepts a 1% difference on the pixel clock > > > before calling drm_atomic_helper_crtc_compare_state(). [...] > > > > Yes, that's why we need the above mentionned helper, and more generally > > why a lot of drivers allow some deviation from the clock. > > If it helps, I can write that helper: dispc_find_closest_refresh_rate_from_clk() > turned into a DRM helper, with the tolerance as a parameter since drivers > want different ones (5% for tidss, 0.5% for most). Something like: > > int drm_mode_set_clock_from_rate(struct drm_display_mode *mode, > unsigned long rate, > unsigned int tolerance); > > with the tolerance in per mille, so 0.5% can be expressed. It would fill > mode->clock with the ideal clock of the closest standard refresh rate, or > return an error if none is close enough. tidss would then use it, and so > would tilcdc instead of its own compare hook. I'm also fine with you > folding it into your series if you'd rather do it yourself, just let me > know. This is part of v10 now, together with some unit tests. Maxime [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 273 bytes --] ^ permalink raw reply [flat|nested] 27+ messages in thread
* [RFC PATCH 4/4] drm/panel: simple: Keep the enable GPIO as left by the bootloader 2026-11-16 14:27 [RFC PATCH 0/4] drm/tilcdc: Implement state readout Màxim Pedraza Padilla ` (2 preceding siblings ...) 2026-11-16 14:27 ` [RFC PATCH 3/4] drm/tilcdc: Implement state readout support Màxim Pedraza Padilla @ 2026-11-16 14:27 ` Màxim Pedraza Padilla 2026-11-16 16:50 ` [RFC PATCH 0/4] drm/tilcdc: Implement state readout Maxime Ripard 4 siblings, 0 replies; 27+ messages in thread From: Màxim Pedraza Padilla @ 2026-11-16 14:27 UTC (permalink / raw) To: Maxime Ripard Cc: Neil Armstrong, Jessica Zhang, Jyri Sarha, Tomi Valkeinen, Uwe Kleine-König, Andrzej Hajda, Robert Foss, Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Luca Ceresoli, Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel, linux-kernel The enable GPIO is requested as output low at probe, which turns the panel off and blanks a splash screen the bootloader left on it, even when the display state is read out and kept. Request it with GPIOD_ASIS instead, and set it as output when the panel is powered up, since it may still be an input if the bootloader didn't touch it. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Màxim Pedraza Padilla <maximpedraza@gmail.com> --- drivers/gpu/drm/panel/panel-simple.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/panel/panel-simple.c b/drivers/gpu/drm/panel/panel-simple.c index a944c34642dc..9d2aa4d16f97 100644 --- a/drivers/gpu/drm/panel/panel-simple.c +++ b/drivers/gpu/drm/panel/panel-simple.c @@ -341,7 +341,7 @@ static int panel_simple_resume(struct device *dev) return err; } - gpiod_set_value_cansleep(p->enable_gpio, 1); + gpiod_direction_output(p->enable_gpio, 1); if (p->desc->delay.prepare) msleep(p->desc->delay.prepare); @@ -688,7 +688,7 @@ static struct panel_simple *panel_simple_probe(struct device *dev) return ERR_CAST(panel->supply); panel->enable_gpio = devm_gpiod_get_optional(dev, "enable", - GPIOD_OUT_LOW); + GPIOD_ASIS); if (IS_ERR(panel->enable_gpio)) return dev_err_cast_probe(dev, panel->enable_gpio, "failed to request GPIO\n"); -- 2.39.5 ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [RFC PATCH 0/4] drm/tilcdc: Implement state readout 2026-11-16 14:27 [RFC PATCH 0/4] drm/tilcdc: Implement state readout Màxim Pedraza Padilla ` (3 preceding siblings ...) 2026-11-16 14:27 ` [RFC PATCH 4/4] drm/panel: simple: Keep the enable GPIO as left by the bootloader Màxim Pedraza Padilla @ 2026-11-16 16:50 ` Maxime Ripard 2026-11-18 21:21 ` Màxim Pedraza Padilla 4 siblings, 1 reply; 27+ messages in thread From: Maxime Ripard @ 2026-11-16 16:50 UTC (permalink / raw) To: Màxim Pedraza Padilla Cc: Neil Armstrong, Jessica Zhang, Jyri Sarha, Tomi Valkeinen, Uwe Kleine-König, Andrzej Hajda, Robert Foss, Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Luca Ceresoli, Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel, linux-kernel [-- Attachment #1: Type: text/plain, Size: 3962 bytes --] On Mon, Nov 16, 2026 at 03:27:03PM +0100, Màxim Pedraza Padilla wrote: > Hi Maxime, > > Following your suggestion in the boot logo thread ("just implement readout > then"), this implements hardware state readout for tilcdc on top of your > v7: > > https://lore.kernel.org/r/20261029-drm-state-readout-v7-0-25e5163d75c3@kernel.org Awesome, thanks a lot for that. I was working on sending v9 today, so it's a nice timing :) There's some redundancy with some work I sent since v7, but it looks pretty ok. > The goal is that the kernel takes over the display as U-Boot left it, so > the boot logo stays on screen with no blanking or flicker until userspace > replaces it. > > Patch 1 adds an atomic_sro_install_state hook to bridges, and patch 2 uses > it in the panel bridge, which also reads out the connector and bridge > state: without that, the core discards the readout of any driver behind a > panel. Patch 3 is the tilcdc readout itself: CRTC mode from the raster > timings, primary plane with a non-GEM framebuffer (as tidss does), encoder > and hw_reset. Patch 4 keeps panel-simple from turning the panel off at > probe by driving its enable GPIO low. > > For the backlight, pwm-tiecap needs a .get_state(), otherwise pwm_bl sees > the PWM disabled and sets duty 0 until the panel is enabled. I sent that > one separately to Uwe and linux-pwm: > > https://lore.kernel.org/r/20261116142251.1296742-1-maximpedraza@gmail.com > > Tested on an AM335x board (Fides T075, out-of-tree DT) with U-Boot > leaving an 800x480 RGB565 logo: > - The logo stays on screen, untouched, from U-Boot to userspace, with the > backlight on all along. > - The U-Boot mode doesn't match the one in the DT (16.94 MHz pixel clock > and slightly different timings), so the first commit with the panel > mode does a full modeset, as expected. I'm not quite sure I understand what you meant here. If it does a full modeset, I would expect to see some flicker? > - First commits from userspace: a framebuffer flip without modeset, a full > modeset to the panel mode, and ACTIVE=0 then 1. No WARN or oops. > - With drm.atomic_readout=0 the old behaviour comes back: the raster stops > and the first commit does a full modeset. > - Without video set up by U-Boot nothing is adopted and the normal path is > taken. > - The SGX530 driver and a Qt EGLFS application take over from the adopted > logo without visible glitches. > > The DT needs a reserved-memory node for the U-Boot framebuffer, and > ti,no-reset-on-init on the GPIO banks (and on the PWMSS) so that ti-sysc > doesn't reset the panel enable and backlight lines. > > The backlight needs some care. With the PWM configured by the bootloader > and the pin muxed to it, the handover is seamless. If the bootloader drives > the backlight some other way, for instance with the pin as a plain GPIO and > the PWM stopped, the light goes off when the kernel muxes the pin to the > PWM, until the panel is enabled. The bootloader has to leave the backlight > in the state the kernel will read back. > > After each commit, the comparison still reports some mismatches. As far as > I can tell they come from the core rather than from tilcdc, but I'd > appreciate your view: > - connector_mask and encoder_mask, on a commit that only changes the > framebuffer: the connector is not part of the commit, so it's not read > back. Yeah, that's because I wasn't supporting partial pipeline updates in v7. It should be fixed in v8 onwards. > - mode_blob, after a modeset: the memcmp() includes the mode type, and > DRM_MODE_TYPE_PREFERRED can't be read from the hardware. Same thing here. > - With ACTIVE=0: crtc, fb, enable, best_encoder and the bridge bus_cfg. > The readout sees the raster stopped and can't tell enable=1/active=0 > from disabled. Ditto. I'll review each patches individually Thanks! Maxime [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 273 bytes --] ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [RFC PATCH 0/4] drm/tilcdc: Implement state readout 2026-11-16 16:50 ` [RFC PATCH 0/4] drm/tilcdc: Implement state readout Maxime Ripard @ 2026-11-18 21:21 ` Màxim Pedraza Padilla 0 siblings, 0 replies; 27+ messages in thread From: Màxim Pedraza Padilla @ 2026-11-18 21:21 UTC (permalink / raw) To: Maxime Ripard Cc: Neil Armstrong, Jessica Zhang, Jyri Sarha, Tomi Valkeinen, Uwe Kleine-König, Andrzej Hajda, Robert Foss, Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Luca Ceresoli, Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel, linux-kernel On Mon, Nov 16, 2026 at 05:50:31PM +0100, Maxime Ripard wrote: > Awesome, thanks a lot for that. I was working on sending v9 today, so > it's a nice timing :) > > There's some redundancy with some work I sent since v7, but it looks > pretty ok. Thanks! I based this on v7 and missed that v8 already covers patches 1 and 2 (the install hook fix and the panel bridge readout), so I'll drop them and rebase the tilcdc part on top of v9. > > - The U-Boot mode doesn't match the one in the DT (16.94 MHz pixel clock > > and slightly different timings), so the first commit with the panel > > mode does a full modeset, as expected. > > I'm not quite sure I understand what you meant here. If it does a full > modeset, I would expect to see some flicker? Sorry, that was unclear. Nothing happens at boot: the kernel keeps the U-Boot mode and the logo stays untouched. The modeset only happens when userspace does its first commit with the mode from the DT, which is also when the logo gets replaced. On this panel the switch is clean, even on a slow-motion video, but other panels may show a glitch. The real fix is for U-Boot to program the same mode as the DT, and then that commit doesn't need a modeset at all. > Yeah, that's because I wasn't supporting partial pipeline updates in v7. > It should be fixed in v8 onwards. Great, I'll check the comparison again on v9. Thanks, Màxim ^ permalink raw reply [flat|nested] 27+ messages in thread
end of thread, other threads:[~2026-11-27 17:39 UTC | newest] Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2026-11-16 14:27 [RFC PATCH 0/4] drm/tilcdc: Implement state readout Màxim Pedraza Padilla 2026-11-16 14:27 ` [RFC PATCH 1/4] drm/bridge: Add atomic_sro_install_state hook Màxim Pedraza Padilla 2026-11-16 16:58 ` Maxime Ripard 2026-11-16 14:27 ` [RFC PATCH 2/4] drm/panel: Implement state readout in the panel bridge Màxim Pedraza Padilla 2026-11-16 16:59 ` Maxime Ripard 2026-11-16 14:27 ` [RFC PATCH 3/4] drm/tilcdc: Implement state readout support Màxim Pedraza Padilla 2026-11-16 17:12 ` Maxime Ripard 2026-11-18 21:21 ` Màxim Pedraza Padilla 2026-11-20 14:01 ` Maxime Ripard 2026-11-23 10:55 ` Màxim Pedraza Padilla 2026-11-24 14:11 ` Màxim Pedraza Padilla 2026-11-24 14:38 ` Tomi Valkeinen 2026-11-25 10:11 ` Maxime Ripard 2026-11-25 11:43 ` Tomi Valkeinen 2026-11-25 12:21 ` Maxime Ripard 2026-11-25 14:55 ` Tomi Valkeinen 2026-11-27 16:11 ` Maxime Ripard 2026-11-27 17:39 ` Tomi Valkeinen 2026-11-25 10:15 ` Màxim Pedraza Padilla 2026-11-25 11:53 ` Tomi Valkeinen 2026-11-25 13:36 ` Màxim Pedraza Padilla 2026-11-25 10:07 ` Maxime Ripard 2026-11-25 13:31 ` Màxim Pedraza Padilla 2026-11-27 9:53 ` Maxime Ripard 2026-11-16 14:27 ` [RFC PATCH 4/4] drm/panel: simple: Keep the enable GPIO as left by the bootloader Màxim Pedraza Padilla 2026-11-16 16:50 ` [RFC PATCH 0/4] drm/tilcdc: Implement state readout Maxime Ripard 2026-11-18 21:21 ` Màxim Pedraza Padilla
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®