From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 26EB2606A31A for ; Wed, 2 Dec 2026 05:59:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jKPEPWoy Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7FA8010E1B1; Wed, 2 Dec 2026 05:59:52 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 175BB10E1B1 for ; Wed, 2 Dec 2026 05:59:46 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id B4B2940A2B; Wed, 2 Dec 2026 05:59:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85C8B1F00893; Wed, 2 Dec 2026 05:59:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796191185; bh=g/x9onwEe5Igox87nh0o6IQ4QJpJnSjGCypI3or3hRc=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=jKPEPWoyfarl+t7EXKJGhUtf+Wyb6Bw6iU78DWzaZ4AzshEt7lMqAlt1ScutBaA52 Zv7qSJnfXkPqHc+KIkx65josPkecVk4GZhflnI4jUzbiEITV/Zt1kpdMbIloqtRtzv sZj51ho21nv2lc35yQUcac66XF+pK9d7nadfbjHVXj5mF5458HG9jMDzbiXwUPgzcY SVGTfny3W/wwAkYAikke5S5cYL9j3IZBhkWkV6GANC3tmBZs96LxjJaqo5c2NxC7Lf m8Y1/bSq5EknJzFLZiHsiVn4Tzy3jpqHGp0fQQGXiof5uPlRZ8UHhQg/URS1xyex8C pitpIt1XnA8lw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v5] drm/bridge: cdns-mhdp8546: Add suspend resume support to the bridge driver To: "Abhash Kumar Jha" Cc: dri-devel@lists.freedesktop.org In-Reply-To: <20261202054207.4042368-1-a-kumar2@ti.com> References: <20261202054207.4042368-1-a-kumar2@ti.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 05:59:45 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "dri-devel" X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: 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 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/driver= s/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)); > } > =20 > +static int cdns_mhdp_resume(struct device *dev) > +{ > + struct cdns_mhdp_device *mhdp =3D dev_get_drvdata(dev); > + unsigned int keep_alive, keep_alive_inc; > + unsigned long rate; > + int ret; > + > + ret =3D clk_prepare_enable(mhdp->clk); > + if (ret) > + return ret; > + > + rate =3D 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 =3D phy_init(mhdp->phy); > + if (ret) { > + dev_err(mhdp->dev, "Failed to initialize PHY: %d\n", ret); > + goto disable_clk; > + } > + ret =3D 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 !=3D 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 =3D=3D -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 load= ed > + * again. > + */ > + keep_alive =3D readl(mhdp->regs + CDNS_KEEP_ALIVE) & CDNS_KEEP_ALIVE_MA= SK; > + ret =3D readl_poll_timeout(mhdp->regs + CDNS_KEEP_ALIVE, keep_alive_inc, > + (keep_alive_inc & CDNS_KEEP_ALIVE_MASK) !=3D keep_alive, > + 2000, 2 * CDNS_KEEP_ALIVE_TIMEOUT); > + if (ret) { > + ret =3D cdns_mhdp_load_firmware(mhdp); > + if (ret) > + goto phy_off; > + > + ret =3D wait_event_timeout(mhdp->fw_load_wq, > + mhdp->hw_state =3D=3D MHDP_HW_READY, > + msecs_to_jiffies(1000)); > + if (ret =3D=3D 0) { > + dev_err(mhdp->dev, "%s: Timeout waiting for fw loading\n", > + __func__); > + ret =3D -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 =3D=3D 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->cl= k) a second time during devres release. > + > +static int cdns_mhdp_suspend(struct device *dev) > +{ > + struct cdns_mhdp_device *mhdp =3D dev_get_drvdata(dev); > + unsigned long timeout =3D msecs_to_jiffies(100); > + int ret; > + > + ret =3D wait_event_timeout(mhdp->fw_load_wq, > + mhdp->hw_state =3D=3D MHDP_HW_READY, > + timeout); > + if (ret =3D=3D 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 =3D 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 =3D MHDP_HW_READY wait_event_timeout(..., mhdp->hw_state =3D=3D 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 =3D true even when no CRTC is active (mhdp->bridge_enabled =3D=3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202054207.4042= 368-1-a-kumar2@ti.com?part=3D1