* [RFC PATCH v3 0/2] drm/tilcdc: Implement state readout @ 2026-12-01 9:26 Màxim Pedraza Padilla 2026-12-01 9:26 ` [RFC PATCH v3 1/2] drm/tilcdc: Implement state readout support Màxim Pedraza Padilla 2026-12-01 9:26 ` [RFC PATCH v3 2/2] drm/panel: simple: Keep the enable GPIO as left by the bootloader Màxim Pedraza Padilla 0 siblings, 2 replies; 5+ messages in thread From: Màxim Pedraza Padilla @ 2026-12-01 9:26 UTC (permalink / raw) To: Maxime Ripard Cc: Neil Armstrong, Jessica Zhang, Jyri Sarha, Tomi Valkeinen, Maarten Lankhorst, Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel, linux-kernel Hi, This implements hardware state readout for tilcdc, so that the kernel takes over the display as the bootloader left it and a boot logo stays on screen, with no blanking or flicker, until userspace replaces it. It applies on top of Maxime's state readout series v10 and his patch switching tilcdc to drm_mode_config_create_initial_state(), from the no-more-config-reset series: https://lore.kernel.org/r/20261127-drm-state-readout-v10-0-0259582d45a8@kernel.org https://lore.kernel.org/r/20261116-drm-no-more-config-reset-v2-43-0bb471f4d1e0@kernel.org Patch 1 is the tilcdc readout itself. Patch 2 keeps panel-simple from turning the panel off at probe by driving its enable GPIO low. For the backlight, the pwm-tiecap .get_state() is now in Uwe's pwm/for-next. Tested on an AM335x board (out-of-tree DT) with U-Boot leaving an 800x480 RGB565 logo, programmed with the panel mode from the DT at exactly 60 Hz (33.264 MHz): - The logo stays on screen, untouched, from U-Boot to userspace, and the mode is read back exactly, with no state comparison warning and no WARN or oops. - First commits from userspace: a framebuffer flip without modeset, a commit with the panel mode that doesn't trigger a modeset, and ACTIVE=0 then 1, which scans the adopted framebuffer out again. - The SGX530 driver and a Qt EGLFS application take over from the adopted logo without a modeset. - Without video set up by U-Boot nothing is adopted, and the first commit does a regular modeset. - Suspend and resume with pm_test=devices bring the adopted logo back. This needs a tilcdc fix sent separately, unrelated to this series: https://lore.kernel.org/r/20261201091036.230021-1-maximpedraza@gmail.com About the pixel clock, now read back with drm_atomic_helper_sro_find_refresh_from_clk(): modesets at 20 pixel clocks between 16.9 and 45 MHz give no warning, except at 33.3 and 33.333 MHz, close to but not exactly 60 Hz. The readout reports them as 33.264 MHz and the state comparison complains about the mode clock. With a DT mode at an exact standard rate, as on this board, there's no such mismatch. The DT needs a reserved-memory node for the U-Boot framebuffer, and ti,no-reset-on-init on the GPIO banks and the PWMSS so that ti-sysc doesn't reset the panel enable and backlight lines. The panel timings must describe the VSYNC polarity, and a panel needing an active low HSYNC has to leave hsync-active out, because of tilcdc_crtc_mode_fixup(). Changes in v3: - Rebase on v10. - Read the pixel clock back with drm_atomic_helper_sro_find_refresh_from_clk(), and drop the custom state comparison with a 1% pixel clock tolerance. - Back the adopted framebuffer with a GEM object from drm_atomic_helper_sro_create_gem_dma_object(), since v10 drops framebuffers without one. - Initialize the adopted mode with drm_mode_init(), and shut the adopted CRTC down if the probe fails after the readout (sashiko). - Link to v2: https://lore.kernel.org/r/20261124141908.443764-1-maximpedraza@gmail.com Thanks, Màxim Màxim Pedraza Padilla (2): drm/tilcdc: Implement state readout support drm/panel: simple: Keep the enable GPIO as left by the bootloader drivers/gpu/drm/panel/panel-simple.c | 4 +- drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 182 ++++++++++++++++++++++++ drivers/gpu/drm/tilcdc/tilcdc_drv.c | 12 ++ drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 29 +++- drivers/gpu/drm/tilcdc/tilcdc_plane.c | 133 +++++++++++++++++ 5 files changed, 355 insertions(+), 5 deletions(-) base-commit: 5ce32a0c94a827ff44ee60898c28060714dcff75 prerequisite-message-id: <20261127-drm-state-readout-v10-0-0259582d45a8@kernel.org> prerequisite-message-id: <20261116-drm-no-more-config-reset-v2-43-0bb471f4d1e0@kernel.org> prerequisite-patch-id: 0b49abc230751bbc8235b4f23e5b2f5bc154f807 prerequisite-patch-id: cb32051331d83506b8e6fd512f93595724905a9f prerequisite-patch-id: 72acc5f5b50b767484ff995256e7fb155c05f6eb prerequisite-patch-id: cf8b32c78f343143906b208946b82c5975cad22f prerequisite-patch-id: 1a6e113d6f412d798052a924269a7dc876d91ded prerequisite-patch-id: 81f93bf511a83182db2358e0779ab6f455cd4f8a prerequisite-patch-id: e55453981968570dc5994174f615f0996ad7adf0 prerequisite-patch-id: e89c26a662f6fa1996675b0e40e27be09fce9ddf prerequisite-patch-id: 8d11298411f0ac5aac955e01a94ec127d29dbdc1 prerequisite-patch-id: 91a42599fcc7bdb50016e3e91352ac7b5d14bdc3 prerequisite-patch-id: 3459ea8c4e46c2e87bce3a79af06e19bd24c5f0a prerequisite-patch-id: 2b97b25f6be119eac52a1bb726b9a8cd9c8a17e9 prerequisite-patch-id: 2dfe6357a636b3662dbd8db80bc29bd36a0329ad prerequisite-patch-id: a6261679a50cb9f18f0a47d8f519939e1a414acb prerequisite-patch-id: d4425072933d272b80572f5309851afcbac6f984 prerequisite-patch-id: dd9a285884e7f3bb96e4950f6f473f7ed18a865b prerequisite-patch-id: fa9e31271f79e3e9103135bc2e8efd252e18af99 prerequisite-patch-id: 563c77055b805b0d640cd8517627a8c491bce385 prerequisite-patch-id: c15cdbb845bbd252a037d410f806a910c0831917 prerequisite-patch-id: e3362ce0dbcc48a39f1cc14de6098d8ac68431c7 prerequisite-patch-id: 4fafee08b92675ea8a6f7fb5e27ff5a769325208 prerequisite-patch-id: 6c0369731a723fdef00863dfb1d083ecf4de5d10 prerequisite-patch-id: c2ac26af16bce3d138ec2946ddaa0e57d53b529a prerequisite-patch-id: 1830e22c10c8af8a7c9884d3a91c3a35dfa68543 prerequisite-patch-id: 52f7fe449e4812a1aef27bd1182e537002e1f9b4 prerequisite-patch-id: 0889a5c6a812cf2cc675ac64d66c8a241dad9b05 prerequisite-patch-id: ab15a09bb9e176330cd6f9991e841513315f07dc prerequisite-patch-id: 402669fd5f97dfc3c3577a104cd8fdb14462cc90 prerequisite-patch-id: e0eb2c02c507fffa786135636227a5cda60f9d3d prerequisite-patch-id: 19ae36e5a132726669496c36f11d22ab2cd677da prerequisite-patch-id: 0c8a54b1f9bf053b817e949eb82538e7a0630d01 prerequisite-patch-id: ed873cdcbb8a12ab5ea8b33878dd5112d5e284d5 prerequisite-patch-id: 76b67bf5eab8683095aa758a46efbcb4f0be297b prerequisite-patch-id: b878fee755a682f5af5f89b74f0ef2cd4eeb9ff8 prerequisite-patch-id: 4de5c8ffb89150dc1475f0ad8eb5ba05102d7022 prerequisite-patch-id: b41f34105087422cbb9386e311033b486a66859d prerequisite-patch-id: 9e54b77c687ec32b156c2af70d62c2ac24859478 -- 2.39.5 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [RFC PATCH v3 1/2] drm/tilcdc: Implement state readout support 2026-12-01 9:26 [RFC PATCH v3 0/2] drm/tilcdc: Implement state readout Màxim Pedraza Padilla @ 2026-12-01 9:26 ` Màxim Pedraza Padilla 2026-12-01 9:54 ` sashiko-bot 2026-12-01 9:26 ` [RFC PATCH v3 2/2] drm/panel: simple: Keep the enable GPIO as left by the bootloader Màxim Pedraza Padilla 1 sibling, 1 reply; 5+ messages in thread From: Màxim Pedraza Padilla @ 2026-12-01 9:26 UTC (permalink / raw) To: Maxime Ripard Cc: Neil Armstrong, Jessica Zhang, Jyri Sarha, Tomi Valkeinen, 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. Some of the state needs interpreting: - The pixel clock is the functional clock rate divided by the LCDC divider. Since the clock tree rarely gives the exact rate a mode asks for, it is matched against the standard refresh rates with drm_atomic_helper_sro_find_refresh_from_clk(), and the mode gets the pixel clock of the matching one. If none matches, nothing is adopted. - The registers only encode the pixel size, not the channel order. The order that displays correctly depends on the panel wiring, described by blue-and-red-wiring, which already selects the formats the driver exposes: the adopted framebuffer gets the one with that pixel size. - tilcdc_crtc_mode_fixup() flips the HSYNC polarity of the adjusted mode, and the readout undoes it. A mode with DRM_MODE_FLAG_PHSYNC and one with no HSYNC flag program the same registers, so the latter is reported. The adopted framebuffer is backed by a GEM object created with drm_atomic_helper_sro_create_gem_dma_object() from the DMA address the bootloader programmed, so that it can be scanned out again after the CRTC is disabled and re-enabled. 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 | 182 ++++++++++++++++++++++++ drivers/gpu/drm/tilcdc/tilcdc_drv.c | 12 ++ drivers/gpu/drm/tilcdc/tilcdc_encoder.c | 29 +++- drivers/gpu/drm/tilcdc/tilcdc_plane.c | 133 +++++++++++++++++ 4 files changed, 353 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c index f619b7a6e70d..1647b8af7dbb 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,189 @@ 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; + + /* + * The pixel clock is the functional clock divided by the CTRL divisor. + * Match the functional clock against the standard refresh rates for a + * line clkdiv times longer, which is the same as matching the pixel + * clock, and report the pixel clock of the matching standard mode. + */ + clkdiv = (ctrl & LCDC_CLK_DIVISOR_MASK) >> 8; + if (!clkdiv) + return -EINVAL; + if (!drm_atomic_helper_sro_find_refresh_from_clk(dev, priv->clk, + mode->htotal * clkdiv, + mode->vtotal, &clk_rate)) + return -EINVAL; + mode->clock = DIV_ROUND_CLOSEST(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_init(&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; + drm_mode_set_crtcinfo(&mode, 0); + + 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 da718d9cb1d6..09623c33906c 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,13 @@ 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, + .atomic_sro_install_state = drm_atomic_helper_sro_install_state, }; static void modeset_init(struct drm_device *dev) @@ -86,6 +95,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 @@ -438,6 +448,8 @@ static int tilcdc_pdev_probe(struct platform_device *pdev) stop_poll: drm_kms_helper_poll_fini(ddev); + /* A CRTC adopted from the bootloader holds a runtime PM reference */ + tilcdc_crtc_shutdown(priv->crtc); tilcdc_irq_uninstall(ddev); unregister_cpufreq_notif: #ifdef CONFIG_CPU_FREQ 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..59ae4e074c74 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_plane.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_plane.c @@ -4,17 +4,150 @@ * 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_dma_helper.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 size, not the channel + * order. The order that displays correctly depends on how the panel is wired + * (blue-and-red-wiring), which already selects the formats the driver + * exposes, so report the one with the size read back. + */ +static const struct drm_format_info * +tilcdc_plane_readout_format(struct drm_device *dev) +{ + struct tilcdc_drm_private *priv = ddev_to_tilcdc_priv(dev); + u32 ctrl = tilcdc_read(dev, LCDC_RASTER_CTRL_REG); + const struct drm_format_info *info; + unsigned int cpp, i; + + if (!(ctrl & LCDC_V2_TFT_24BPP_MODE)) + cpp = 2; + else if (ctrl & LCDC_V2_TFT_24BPP_UNPACK) + cpp = 4; + else + cpp = 3; + + for (i = 0; i < priv->num_pixelformats; i++) { + info = drm_format_info(priv->pixelformats[i]); + if (info->cpp[0] == cpp) + return info; + } + + return NULL; +} + +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_gem_dma_object *dma_obj; + struct drm_framebuffer *fb; + dma_addr_t dma_addr; + 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 = 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; + + dma_addr = tilcdc_read(dev, LCDC_DMA_FB_BASE_ADDR_0_REG); + dma_obj = drm_atomic_helper_sro_create_gem_dma_object(dev, dma_addr, + (size_t)fb->pitches[0] * h); + if (IS_ERR(dma_obj)) { + kfree(fb); + ret = PTR_ERR(dma_obj); + goto err; + } + fb->obj[0] = &dma_obj->base; + + ret = drm_framebuffer_init(dev, fb, &tilcdc_plane_readout_fb_funcs); + if (ret) { + drm_gem_object_put(fb->obj[0]); + 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 related [flat|nested] 5+ messages in thread
* Re: [RFC PATCH v3 1/2] drm/tilcdc: Implement state readout support 2026-12-01 9:26 ` [RFC PATCH v3 1/2] drm/tilcdc: Implement state readout support Màxim Pedraza Padilla @ 2026-12-01 9:54 ` sashiko-bot 0 siblings, 0 replies; 5+ messages in thread From: sashiko-bot @ 2026-12-01 9:54 UTC (permalink / raw) To: Màxim Pedraza Padilla; +Cc: dri-devel Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [High] drm/tilcdc: build failure due to missing DRM atomic state readout infrastructure - [High] drm/tilcdc: missing tilcdc_crtc_shutdown() before teardown in tilcdc_pdev_remove() - [High] drm/tilcdc: tilcdc_encoder_get_current_crtc() returns CRTC when raster is off - [Medium] drm/tilcdc: unlocked last_vblank write and early IRQ enable in install_state() -- commit 6a2dac26c5f1471aa8cf7784667f51df160cd3ba Author: Màxim Pedraza Padilla <maximpedraza@gmail.com> drm/tilcdc: Implement state readout support This commit adds atomic state readout callbacks to reconstruct the initial CRTC, encoder, and primary plane KMS state from the LCDC raster registers when the bootloader leaves the display controller running. > diff --git a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c > index f619b7a6e70d9..1647b8af7dbbb 100644 > --- a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c > +++ b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c [ ... ] > +static void tilcdc_crtc_install_state(struct drm_crtc *crtc, > + struct drm_crtc_state *crtc_state) > +{ [ ... ] > + 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); > +} [Severity: Medium] Can tilcdc_crtc_irq() race with tilcdc_crtc_install_state() here? Because tilcdc_irq_install() has already registered the interrupt handler and the hardware raster is already running, enabling LCDC interrupts before drm_calc_timestamping_constants(), drm_crtc_vblank_on(), and tilcdc_crtc->enabled = true allows an immediate interrupt to run against partially initialized vblank state. Also, unlike tilcdc_crtc_enable(), tilcdc_crtc->last_vblank is written without holding tilcdc_crtc->irq_lock (which can tear the 64-bit ktime_t on 32-bit ARM if an end-of-frame interrupt was left enabled by the bootloader). [ ... ] > diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.c b/drivers/gpu/drm/tilcdc/tilcdc_drv.c > index 1d6c9a423a410..3d8e12878f94d 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,13 @@ 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, > + .atomic_sro_install_state = drm_atomic_helper_sro_install_state, > }; [Severity: High] Are the prerequisite DRM atomic state readout patches missing from this tree? drm/drm_atomic_state_readout.h and drm/drm_atomic_state_readout_helper.h do not exist in include/drm/, and the .atomic_sro_* and .hw_reset vtable fields, struct drm_atomic_sro_state, and drm_atomic_helper_sro_*() helpers referenced across tilcdc_drv.c, tilcdc_crtc.c, tilcdc_encoder.c, and tilcdc_plane.c are undeclared, breaking the build when CONFIG_DRM_TILCDC is enabled. In addition, tilcdc_pdev_probe() still calls drm_mode_config_reset(ddev), which unconditionally calls tilcdc_crtc_hw_reset() and turns the raster off instead of performing state readout. [ ... ] > @@ -436,6 +446,8 @@ static int tilcdc_pdev_probe(struct platform_device *pdev) > > stop_poll: > drm_kms_helper_poll_fini(ddev); > + /* A CRTC adopted from the bootloader holds a runtime PM reference */ > + tilcdc_crtc_shutdown(priv->crtc); > tilcdc_irq_uninstall(ddev); > unregister_cpufreq_notif: > #ifdef CONFIG_CPU_FREQ [Severity: High] Does tilcdc_pdev_remove() also need to shut down the CRTC before uninstalling the IRQ and disabling runtime PM? drivers/gpu/drm/tilcdc/tilcdc_drv.c:tilcdc_pdev_remove() { drm_dev_unregister(ddev); drm_kms_helper_poll_fini(ddev); tilcdc_irq_uninstall(ddev); ... pm_runtime_disable(&pdev->dev); clk_put(priv->clk); destroy_workqueue(priv->wq); } tilcdc_crtc_destroy() is registered via drmm_add_action_or_reset(), so it only runs when devres releases devm_drm_dev_alloc() after tilcdc_pdev_remove() returns. When the driver is unbound while an adopted (or active) CRTC is enabled, tilcdc_crtc_destroy() -> tilcdc_crtc_shutdown() will access LCDC registers after runtime PM is disabled and priv->clk is put, wait 500 ms for a frame-done IRQ that was already uninstalled, call pm_runtime_put_sync() after pm_runtime_disable(), and call flush_workqueue(priv->wq) after destroy_workqueue(priv->wq). > diff --git a/drivers/gpu/drm/tilcdc/tilcdc_encoder.c b/drivers/gpu/drm/tilcdc/tilcdc_encoder.c > index ac4b5beb2dd58..b3fe18f69f174 100644 > --- a/drivers/gpu/drm/tilcdc/tilcdc_encoder.c > +++ b/drivers/gpu/drm/tilcdc/tilcdc_encoder.c [ ... ] > +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; > +} [Severity: High] Does tilcdc_encoder_get_current_crtc() return the CRTC even when the LCDC raster is disabled? When LCDC_RASTER_ENABLE is not set in LCDC_RASTER_CTRL_REG, tilcdc_crtc_readout_state() and tilcdc_plane_atomic_readout_state() leave the CRTC and primary plane disabled, but tilcdc_encoder_get_current_crtc() still returns the CRTC, linking the encoder and connector to a disabled CRTC (crtc_state->enable == false with a non-zero connector_mask). Also, in tilcdc_plane_atomic_readout_state(), checking !crtc_state->active instead of re-reading LCDC_RASTER_CTRL_REG would avoid reading crtc_state->adjusted_mode if CRTC readout left the CRTC inactive. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261201092651.240295-1-maximpedraza@gmail.com?part=1 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [RFC PATCH v3 2/2] drm/panel: simple: Keep the enable GPIO as left by the bootloader 2026-12-01 9:26 [RFC PATCH v3 0/2] drm/tilcdc: Implement state readout Màxim Pedraza Padilla 2026-12-01 9:26 ` [RFC PATCH v3 1/2] drm/tilcdc: Implement state readout support Màxim Pedraza Padilla @ 2026-12-01 9:26 ` Màxim Pedraza Padilla 2026-12-01 9:40 ` sashiko-bot 1 sibling, 1 reply; 5+ messages in thread From: Màxim Pedraza Padilla @ 2026-12-01 9:26 UTC (permalink / raw) To: Maxime Ripard Cc: Neil Armstrong, Jessica Zhang, Jyri Sarha, Tomi Valkeinen, 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 fe93f59c1d8e..01db22159149 100644 --- a/drivers/gpu/drm/panel/panel-simple.c +++ b/drivers/gpu/drm/panel/panel-simple.c @@ -336,7 +336,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); @@ -664,7 +664,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 related [flat|nested] 5+ messages in thread
* Re: [RFC PATCH v3 2/2] drm/panel: simple: Keep the enable GPIO as left by the bootloader 2026-12-01 9:26 ` [RFC PATCH v3 2/2] drm/panel: simple: Keep the enable GPIO as left by the bootloader Màxim Pedraza Padilla @ 2026-12-01 9:40 ` sashiko-bot 0 siblings, 0 replies; 5+ messages in thread From: sashiko-bot @ 2026-12-01 9:40 UTC (permalink / raw) To: Màxim Pedraza Padilla; +Cc: dri-devel Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] drm/panel: simple: enable_gpio state desync in panel_simple_probe() -- commit 29ec10355f1c521cad78cbabc080604b3d619f74 Author: Màxim Pedraza Padilla <maximpedraza@gmail.com> drm/panel: simple: Keep the enable GPIO as left by the bootloader This commit requests the panel enable GPIO with GPIOD_ASIS at probe time and configures it as an output in panel_simple_resume(). > diff --git a/drivers/gpu/drm/panel/panel-simple.c b/drivers/gpu/drm/panel/panel-simple.c > index fe93f59c1d8ee..01db221591494 100644 > --- a/drivers/gpu/drm/panel/panel-simple.c > +++ b/drivers/gpu/drm/panel/panel-simple.c [ ... ] > @@ -664,7 +664,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"); [Severity: High] Does requesting panel->enable_gpio with GPIOD_ASIS leave the physical GPIO state out of sync with panel->base.prepared, runtime PM, and panel->supply? When the bootloader leaves the panel enabled and the display state is kept without a full modeset, drm_panel_prepare() does not run, so the device starts in RPM_SUSPENDED with panel->base.prepared == false and no regulator reference on panel->supply. If panel->ddc is present, panel_simple_get_modes() calls pm_runtime_get_sync() followed by pm_runtime_put_autosuspend(); because panel_simple_prepare() never took a persistent runtime PM reference, the device autosuspends 1000 ms later and panel_simple_suspend() drives enable_gpio low and disables panel->supply while the display is scanning out. If panel->ddc is absent, panel_simple_resume() never runs at all, so late_initcall_sync can disable an unused boot-on panel->supply, and a subsequent disable or shutdown returns early from drm_panel_unprepare() because panel->base.prepared is false, leaving enable_gpio asserted when the display is turned off. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261201092651.240295-1-maximpedraza@gmail.com?part=2 ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-12-01 9:54 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-12-01 9:26 [RFC PATCH v3 0/2] drm/tilcdc: Implement state readout Màxim Pedraza Padilla 2026-12-01 9:26 ` [RFC PATCH v3 1/2] drm/tilcdc: Implement state readout support Màxim Pedraza Padilla 2026-12-01 9:54 ` sashiko-bot 2026-12-01 9:26 ` [RFC PATCH v3 2/2] drm/panel: simple: Keep the enable GPIO as left by the bootloader Màxim Pedraza Padilla 2026-12-01 9:40 ` sashiko-bot
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox