From fd646142866561b7c22178e4fd297daf2954b7b1 Mon Sep 17 00:00:00 2001 From: Grier Johnson Date: Fri, 4 Dec 2026 14:18:38 -0700 Subject: [PATCH] drm/simpledrm: Support 10.5-inch iPad Pro 2 and 48/30/24 Hz H9G cadences Extend the A10X (T8011) H9G boot-scanout cadence switcher in simpledrm: 1. Add the 10.5-inch iPad Pro 2 panel (J207/J208, 1668x2224, htotal 1756, 1227 lines per subframe, 517107 kHz pixel clock) alongside the 12.9-inch iPad Pro 2 panel (J120/J121, 2048x2732, htotal 2088, 1497 lines per subframe, 750001 kHz). Both share t8011-pro2.dtsi, which already links framebuffer0 to h9g_display. 2. Expose the lower ProMotion scanout cadences via H9G_EXTRA_SUBFRAMES in addition to 120 Hz (0 extra) and the preferred 60 Hz boot cadence (2 extra): 48 Hz (3 extra), 30 Hz (6 extra), and 24 Hz (8 extra), while keeping 60 Hz as the default preferred mode and restoring the boot cadence on teardown. 3. Guard H9G register programming in simpledrm_atomic_enable() with drm_dev_enter()/drm_dev_exit() so queued nonblocking atomic commits cannot touch H9G MMIO after unplug, and add a .shutdown callback that unplugs DRM and restores the boot cadence so kexec from an alternate cadence hands off at 60 Hz. Verified live on J207 (iPad Pro 10.5-inch, Wi-Fi): - Hardware timing registers confirmed (0x1802c=0x08b00684, 0x18030=0x003e0012, 0x18034=0x00020008, 0x18708=1227, 0x1870c=0x200) - Measured refresh rates via H9G_EXTRA_SUBFRAMES counter: sf=2 -> 60.00 Hz, sf=3 -> 48.00 Hz, sf=6 -> 29.99 Hz, sf=8 -> 24.00 Hz - Visually verified clean/flicker-free at 24 Hz with Firefox and shell UI - Settled idle power on 500 mA desktop USB (bl=400, schedutil): dropping from 60 Hz to 24 Hz saves ~105 mA (~410 mW), lifting net battery current from +25/+36 mA to +131/+132 mA charging. Assisted-by: LLM Signed-off-by: Grier Johnson --- drivers/gpu/drm/sysfb/simpledrm.c | 139 ++++++++++++++++++++++++------ 1 file changed, 115 insertions(+), 24 deletions(-) diff --git a/drivers/gpu/drm/sysfb/simpledrm.c b/drivers/gpu/drm/sysfb/simpledrm.c index 487318811d44fe..b34230a7cbe4d6 100644 --- a/drivers/gpu/drm/sysfb/simpledrm.c +++ b/drivers/gpu/drm/sysfb/simpledrm.c @@ -226,10 +226,12 @@ static int simplefb_get_panel_height_mm_of(struct drm_device *dev, * Simple Framebuffer device */ +#define H9G_NUM_EXTRA_MODES 4 + struct simpledrm_device { struct drm_sysfb_device sysfb; void __iomem *h9g; - struct drm_display_mode h9g_fast_mode; + struct drm_display_mode h9g_modes[H9G_NUM_EXTRA_MODES]; u16 h9g_boot_subframes; /* clocks */ @@ -582,6 +584,32 @@ static int simpledrm_device_attach_genpd(struct simpledrm_device *sdev) #define H9G_SUBFRAME_LINES 0x18708 #define H9G_ACTIVE_SUBFRAMES 0x1870c #define H9G_EXTRA_SUBFRAMES_WRITE 0x98050 +#define H9G_ACTIVE_SUBFRAME_COUNT 2 +#define H9G_BOOT_SUBFRAMES 2 + +struct simpledrm_h9g_panel { + u16 hdisplay; + u16 vdisplay; + u16 htotal; + u16 subframe_lines; + u32 clock; +}; + +static const struct simpledrm_h9g_panel simpledrm_h9g_panels[] = { + /* 12.9-inch iPad Pro 2 (J120/J121) */ + { 2048, 2732, 2088, 1497, 750001 }, + /* 10.5-inch iPad Pro 2 (J207/J208) */ + { 1668, 2224, 1756, 1227, 517107 }, +}; + +/* + * Extra blank subframes inserted after the 2 active scanout subframes on a + * fixed 240 Hz subframe clock: 0 -> 120 Hz, 2 (boot) -> 60 Hz, 3 -> 48 Hz, + * 6 -> 30 Hz, 8 -> 24 Hz. + */ +static const u16 simpledrm_h9g_extra_subframes[H9G_NUM_EXTRA_MODES] = { + 0, 3, 6, 8, +}; static bool simpledrm_h9g_write(struct simpledrm_device *sdev, u16 subframes) { @@ -600,18 +628,53 @@ static void simpledrm_h9g_restore(void *data) drm_err(&sdev->sysfb.dev, "failed to restore H9G boot cadence\n"); } +static const struct simpledrm_h9g_panel * +simpledrm_h9g_find_panel(const struct drm_display_mode *mode) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(simpledrm_h9g_panels); i++) { + if (mode->hdisplay == simpledrm_h9g_panels[i].hdisplay && + mode->vdisplay == simpledrm_h9g_panels[i].vdisplay) + return &simpledrm_h9g_panels[i]; + } + return NULL; +} + +static bool simpledrm_h9g_mode_subframes(const struct simpledrm_device *sdev, + const struct drm_display_mode *mode, + u16 *subframes) +{ + unsigned int i; + + if (drm_mode_equal(mode, &sdev->sysfb.fb_mode)) { + *subframes = sdev->h9g_boot_subframes; + return true; + } + for (i = 0; i < ARRAY_SIZE(sdev->h9g_modes); i++) { + if (drm_mode_equal(mode, &sdev->h9g_modes[i])) { + *subframes = simpledrm_h9g_extra_subframes[i]; + return true; + } + } + return false; +} + static void simpledrm_h9g_init(struct simpledrm_device *sdev) { struct drm_sysfb_device *sysfb = &sdev->sysfb; struct device *dev = sysfb->dev.dev; + const struct simpledrm_h9g_panel *panel; struct device_node *display; struct resource res; void __iomem *regs; + unsigned int i; u16 subframes; int ret = -ENODEV; - /* The 12.9-inch iPad Pro 2 panel behind an A10X H9G display pipe */ - if (sysfb->fb_mode.hdisplay != 2048 || sysfb->fb_mode.vdisplay != 2732) + /* iPad Pro 2 (12.9-inch or 10.5-inch) panel behind an A10X H9G pipe */ + panel = simpledrm_h9g_find_panel(&sysfb->fb_mode); + if (!panel) return; display = of_parse_phandle(dev->of_node, "display", 0); if (!display) @@ -628,9 +691,9 @@ static void simpledrm_h9g_init(struct simpledrm_device *sdev) /* Adopt only the boot scanout with the firmware processor stopped. */ if (readl(regs + H9G_M3_CONTROL) != 3 || readl(regs + H9G_MODE) != 1 || readl(regs + H9G_IRQ_ENABLE) || readl(regs + H9G_OUTPUT_ENABLE) || - readl(regs + H9G_SUBFRAME_LINES) != 1497 || + readl(regs + H9G_SUBFRAME_LINES) != panel->subframe_lines || readl(regs + H9G_ACTIVE_SUBFRAMES) != 0x200 || - subframes != 2) + subframes != H9G_BOOT_SUBFRAMES) return; sdev->h9g = regs; @@ -640,12 +703,17 @@ static void simpledrm_h9g_init(struct simpledrm_device *sdev) return; } - /* The boot link runs at the same pixel clock for both cadences. */ - sysfb->fb_mode.clock = 750001; - sysfb->fb_mode.htotal = 2088; - sysfb->fb_mode.vtotal = 5988; - sdev->h9g_fast_mode = sysfb->fb_mode; - sdev->h9g_fast_mode.vtotal = 2994; + /* The boot link runs at the same pixel clock for every cadence. */ + sysfb->fb_mode.clock = panel->clock; + sysfb->fb_mode.htotal = panel->htotal; + sysfb->fb_mode.vtotal = (H9G_ACTIVE_SUBFRAME_COUNT + subframes) * + panel->subframe_lines; + for (i = 0; i < ARRAY_SIZE(sdev->h9g_modes); i++) { + sdev->h9g_modes[i] = sysfb->fb_mode; + sdev->h9g_modes[i].vtotal = (H9G_ACTIVE_SUBFRAME_COUNT + + simpledrm_h9g_extra_subframes[i]) * + panel->subframe_lines; + } } static enum drm_mode_status simpledrm_mode_valid(struct drm_crtc *crtc, @@ -653,8 +721,9 @@ static enum drm_mode_status simpledrm_mode_valid(struct drm_crtc *crtc, { struct drm_sysfb_device *sysfb = to_drm_sysfb_device(crtc->dev); struct simpledrm_device *sdev = container_of(sysfb, struct simpledrm_device, sysfb); + u16 subframes; - if (drm_mode_equal(mode, &sysfb->fb_mode) || drm_mode_equal(mode, &sdev->h9g_fast_mode)) + if (simpledrm_h9g_mode_subframes(sdev, mode, &subframes)) return MODE_OK; return MODE_BAD; } @@ -664,28 +733,37 @@ static void simpledrm_atomic_enable(struct drm_crtc *crtc, struct drm_atomic_com struct drm_sysfb_device *sysfb = to_drm_sysfb_device(crtc->dev); struct simpledrm_device *sdev = container_of(sysfb, struct simpledrm_device, sysfb); const struct drm_crtc_state *new_state = drm_atomic_get_new_crtc_state(state, crtc); - u16 subframes; + u16 subframes = sdev->h9g_boot_subframes; + int idx; - subframes = drm_mode_equal(&new_state->mode, &sdev->h9g_fast_mode) ? - 0 : sdev->h9g_boot_subframes; + if (!drm_dev_enter(crtc->dev, &idx)) + return; + + simpledrm_h9g_mode_subframes(sdev, &new_state->mode, &subframes); if (!simpledrm_h9g_write(sdev, subframes)) drm_err(crtc->dev, "failed to set H9G extra subframes to %u\n", subframes); + + drm_dev_exit(idx); } static int simpledrm_get_modes(struct drm_connector *connector) { struct drm_sysfb_device *sysfb = to_drm_sysfb_device(connector->dev); struct simpledrm_device *sdev = container_of(sysfb, struct simpledrm_device, sysfb); - struct drm_display_mode *fast; + struct drm_display_mode *mode; + unsigned int i; int count = drm_sysfb_connector_helper_get_modes(connector); - fast = drm_mode_duplicate(connector->dev, &sdev->h9g_fast_mode); - if (!fast) - return count; - fast->type = DRM_MODE_TYPE_DRIVER; - drm_mode_set_name(fast); - drm_mode_probed_add(connector, fast); - return count + 1; + for (i = 0; i < ARRAY_SIZE(sdev->h9g_modes); i++) { + mode = drm_mode_duplicate(connector->dev, &sdev->h9g_modes[i]); + if (!mode) + continue; + mode->type = DRM_MODE_TYPE_DRIVER; + drm_mode_set_name(mode); + drm_mode_probed_add(connector, mode); + count++; + } + return count; } static const u64 simpledrm_primary_plane_format_modifiers[] = { @@ -705,7 +783,7 @@ static const struct drm_crtc_helper_funcs simpledrm_crtc_helper_funcs = { DRM_SYSFB_CRTC_HELPER_FUNCS, }; -/* Only a display with an adopted H9G boot scanout offers its 120 Hz mode. */ +/* Only a display with an adopted H9G boot scanout offers alternate cadences. */ static const struct drm_crtc_helper_funcs simpledrm_h9g_crtc_helper_funcs = { .mode_valid = simpledrm_mode_valid, .atomic_check = drm_sysfb_crtc_helper_atomic_check, @@ -1096,6 +1174,18 @@ static void simpledrm_remove(struct platform_device *pdev) drm_dev_unplug(dev); } +static void simpledrm_shutdown(struct platform_device *pdev) +{ + struct simpledrm_device *sdev = platform_get_drvdata(pdev); + struct drm_device *dev = &sdev->sysfb.dev; + + if (!sdev->h9g) + return; + + drm_dev_unplug(dev); + simpledrm_h9g_restore(sdev); +} + static const struct of_device_id simpledrm_of_match_table[] = { { .compatible = "simple-framebuffer", }, { }, @@ -1110,6 +1200,7 @@ static struct platform_driver simpledrm_platform_driver = { }, .probe = simpledrm_probe, .remove = simpledrm_remove, + .shutdown = simpledrm_shutdown, }; module_platform_driver(simpledrm_platform_driver);