Thank you for your contribution! Sashiko AI review found 6 potential issues to consider: - [High] drm/bridge: cdns-mhdp8546: unbalanced phy_power_off() and phy_power_on() - [High] drm/bridge: cdns-mhdp8546: stale link_up state across suspend and resume - [High] drm/bridge: cdns-mhdp8546: uncanceled async fw load on resume timeout - [Medium] drm/bridge: cdns-mhdp8546: HPD work in cdns_mhdp_resume() drops HPD events - [Medium] drm/bridge: cdns-mhdp8546: double clk and phy teardown after failed resume - [Low] drm/bridge: cdns-mhdp8546: unlocked HPD disable in cdns_mhdp_suspend() --
commit dc5fd446a2b779e0075a3701545188c489993730 Author: Abhash Kumar Jha <[email protected]> drm/bridge: cdns-mhdp8546: Add suspend resume support to the bridge driver This commit adds system suspend and resume callbacks to the cdns-mhdp8546 bridge driver, managing the PHY, clock, HPD interrupts, and firmware state across power transitions. > diff --git a/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c > b/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c > index f47717bd10798..7ee0434627f01 100644 > --- a/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c > +++ b/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c [ ... ] > @@ -2258,6 +2257,143 @@ static void cdns_mhdp_hpd_work(struct work_struct > *work) > drm_bridge_hpd_notify(&mhdp->bridge, cdns_mhdp_detect(mhdp)); > } > > +static int cdns_mhdp_resume(struct device *dev) > +{ > + struct cdns_mhdp_device *mhdp = dev_get_drvdata(dev); > + unsigned int keep_alive, keep_alive_inc; > + unsigned long rate; > + int ret; > + > + ret = clk_prepare_enable(mhdp->clk); > + if (ret) > + return ret; > + > + rate = clk_get_rate(mhdp->clk); > + writel(rate % 1000000, mhdp->regs + CDNS_SW_CLK_L); > + writel(rate / 1000000, mhdp->regs + CDNS_SW_CLK_H); > + writel(~0, mhdp->regs + CDNS_APB_INT_MASK); > + > + ret = phy_init(mhdp->phy); > + if (ret) { > + dev_err(mhdp->dev, "Failed to initialize PHY: %d\n", ret); > + goto disable_clk; > + } > + ret = phy_power_on(mhdp->phy); > + if (ret < 0) { > + dev_err(mhdp->dev, "Failed to power on PHY: %d\n", ret); > + goto phy_exit; > + } [Severity: High] Are phy_power_off() in cdns_mhdp_suspend() and phy_power_on() here balanced with probe and remove? cdns_mhdp_probe() only calls phy_init(mhdp->phy) and never calls phy_power_on(mhdp->phy), leaving mhdp->phy->power_count at 0. On the first suspend, phy_power_off(mhdp->phy) sees power_count != 1, skips phy->ops->power_off(), underflows power_count to -1, and performs an unbalanced runtime PM put on the PHY device. On resume, phy_power_on(mhdp->phy) sees power_count == -1 instead of 0, so it skips phy->ops->power_on() and only increments power_count back to 0. > + > + /* > + * The KEEP_ALIVE register is incremented at every scheduler loop of the > + * firmware. If it changes between reads, the firmware is still running > + * (e.g. the suspend was aborted) and only needs to be activated. If it > + * does not change, the bridge lost power and the firmware must be > loaded > + * again. > + */ > + keep_alive = readl(mhdp->regs + CDNS_KEEP_ALIVE) & CDNS_KEEP_ALIVE_MASK; > + ret = readl_poll_timeout(mhdp->regs + CDNS_KEEP_ALIVE, keep_alive_inc, > + (keep_alive_inc & CDNS_KEEP_ALIVE_MASK) != > keep_alive, > + 2000, 2 * CDNS_KEEP_ALIVE_TIMEOUT); > + if (ret) { > + ret = cdns_mhdp_load_firmware(mhdp); > + if (ret) > + goto phy_off; > + > + ret = wait_event_timeout(mhdp->fw_load_wq, > + mhdp->hw_state == MHDP_HW_READY, > + msecs_to_jiffies(1000)); > + if (ret == 0) { > + dev_err(mhdp->dev, "%s: Timeout waiting for fw > loading\n", > + __func__); > + ret = -ETIMEDOUT; > + goto phy_off; > + } [Severity: High] If wait_event_timeout() times out here, can cdns_mhdp_fw_cb() still run after the error path disables mhdp->clk? cdns_mhdp_load_firmware() queues cdns_mhdp_fw_cb() asynchronously via request_firmware_nowait(), and jumping to phy_off does not cancel or wait for that work before calling clk_disable_unprepare(mhdp->clk): CPU0 CPU1 (kworker) cdns_mhdp_resume() cdns_mhdp_load_firmware() request_firmware_nowait(...) wait_event_timeout(..., 1000ms) /* times out */ goto phy_off; ... clk_disable_unprepare(mhdp->clk) cdns_mhdp_fw_cb() cdns_mhdp_fw_activate() writel(..., CDNS_APB_CTRL) memcpy_toio(..., CDNS_MHDP_IMEM, ...) <-- MMIO access with clk disabled In addition, if cdns_mhdp_fw_cb() fails (for example when !fw or cdns_mhdp_fw_activate() returns an error), it returns without waking mhdp->fw_load_wq, forcing cdns_mhdp_resume() to stall for the full 1000 ms timeout. [ ... ] > + /* > + * A hpd interrupt while suspended is lost. Schedule the HPD work > + * to re-read the sink state and notify DRM of any change. > + */ > + spin_lock(&mhdp->start_lock); > + if (mhdp->bridge_attached) > + schedule_work(&mhdp->hpd_work); > + spin_unlock(&mhdp->start_lock); [Severity: Medium] Can scheduling mhdp->hpd_work in .resume_early drop hotplug events that occurred while the system was suspended? During system suspend, the display driver's .suspend hook runs drm_mode_config_helper_suspend() -> drm_kms_helper_poll_disable(), which calls drm_bridge_hpd_disable() and clears mhdp->bridge.hpd_cb to NULL. Because cdns_mhdp_pm_ops uses LATE_SYSTEM_SLEEP_PM_OPS(), cdns_mhdp_resume() runs in .resume_early, before the display driver's .resume hook calls drm_kms_helper_poll_enable() to restore mhdp->bridge.hpd_cb. If mhdp->hpd_work runs before drm_kms_helper_poll_enable(), cdns_mhdp_update_link_status() consumes the firmware HPD events and updates mhdp->plugged, and drm_bridge_hpd_notify() sees bridge->hpd_cb == NULL and drops the notification. When drm_bridge_hpd_enable() later runs at the end of drm_mode_config_helper_resume(), cdns_mhdp_bridge_hpd_enable() only unmasks CDNS_APB_INT_MASK_SW_EVENT_INT without re-notifying DRM. > + > + return 0; > + > +phy_off: > + phy_power_off(mhdp->phy); > +phy_exit: > + phy_exit(mhdp->phy); > +disable_clk: > + clk_disable_unprepare(mhdp->clk); > + > + return ret; > +} [Severity: Medium] If cdns_mhdp_resume() fails, does unwinding mhdp->phy and mhdp->clk cause a double disable when the driver is later unbound? mhdp->clk is acquired with devm_clk_get_enabled() in cdns_mhdp_probe(), and cdns_mhdp_remove() unconditionally calls phy_exit(mhdp->phy). If cdns_mhdp_resume() fails and leaves mhdp->phy exited and mhdp->clk disabled, later bridge detach or driver removal accesses CDNS_APB_INT_MASK in cdns_mhdp_detach() with the clock disabled, calls phy_exit(mhdp->phy) a second time in cdns_mhdp_remove(), and calls clk_disable_unprepare(mhdp->clk) a second time during devres release. > + > +static int cdns_mhdp_suspend(struct device *dev) > +{ > + struct cdns_mhdp_device *mhdp = dev_get_drvdata(dev); > + unsigned long timeout = msecs_to_jiffies(100); > + int ret; > + > + ret = wait_event_timeout(mhdp->fw_load_wq, > + mhdp->hw_state == MHDP_HW_READY, > + timeout); > + if (ret == 0) { > + dev_err(mhdp->dev, "%s: Timeout waiting for fw loading\n", > __func__); > + return -ETIMEDOUT; > + } > + > + /* > + * Mask HPD interrupt so that hpd_work cannot be queued again > + * once it is cancelled and the clock is gone. > + */ > + cdns_mhdp_bridge_hpd_disable(&mhdp->bridge); [Severity: Low] Should cdns_mhdp_bridge_hpd_disable() be called under mhdp->start_lock? In cdns_mhdp_fw_activate(), mhdp->hw_state = MHDP_HW_READY is set before cdns_mhdp_bridge_hpd_enable() unmasks CDNS_APB_INT_MASK_SW_EVENT_INT under mhdp->start_lock: CPU0 CPU1 cdns_mhdp_fw_activate() cdns_mhdp_suspend() spin_lock(&mhdp->start_lock) mhdp->hw_state = MHDP_HW_READY wait_event_timeout(..., mhdp->hw_state == MHDP_HW_READY, ...) cdns_mhdp_bridge_hpd_disable() /* masks SW_EVENT_INT */ cdns_mhdp_bridge_hpd_enable() /* unmasks SW_EVENT_INT */ <-- HPD IRQ left enabled in suspend spin_unlock(&mhdp->start_lock) [ ... ] > + phy_power_off(mhdp->phy); > + phy_exit(mhdp->phy); > + clk_disable_unprepare(mhdp->clk); > + > + return 0; > +} [Severity: High] Does suspending while a sink is connected but the bridge is not actively streaming leave mhdp->link_up stale across suspend and resume? When a DisplayPort sink is plugged in, cdns_mhdp_update_link_status() calls cdns_mhdp_link_up(), which configures the PHY, trains the link, and sets mhdp->link_up = true even when no CRTC is active (mhdp->bridge_enabled == false). If the system suspends while mhdp->bridge_enabled is false (for example when the screen is blanked), cdns_mhdp_atomic_disable() is not called, so cdns_mhdp_suspend() powers down the PHY and clock while mhdp->link_up remains true. After resume, both cdns_mhdp_update_link_status() and cdns_mhdp_atomic_enable() check !mhdp->link_up and skip cdns_mhdp_link_up(), leaving the PHY unconfigured and the DisplayPort link untrained when video output is enabled. -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=1
