mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Marco Felsch <m.felsch@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH] pmdomain: imx8mp-blk-ctrl: fix adb handshake handling
Date: Wed,  3 Apr 2024 17:31:51 +0200	[thread overview]
Message-ID: <20240403153151.2859387-1-m.felsch@pengutronix.de> (raw)

Fix powering the DWC3 USB subsystem which is part of the HSIO BLKCTRL.
Currently we enable the USB clocks and the USB module clock within the
HSIO BLKCTRL. The later get stuck during the first call of
imx8mp_blk_ctrl_power_on() since the parent GPCv2 device is not powered
yet.

Fix this by porting the Linux imx8mp_blk_ctrl::power_nb notifier_block
logic. The Linux driver enable/disable the USB module to propagate the
ADB handshake instead of powering it permanently. The logic is executed
after the parent GPCv2 power domain is powered so we can access the HSIO
BLKCTRL registers.

Fixes: 5cb41f0b62dc ("pmdomain: imx: add i.MX8MP HSIO blk-ctrl driver")
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 drivers/pmdomain/imx/imx8mp-blk-ctrl.c | 28 ++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/drivers/pmdomain/imx/imx8mp-blk-ctrl.c b/drivers/pmdomain/imx/imx8mp-blk-ctrl.c
index 38de9d88a139..b71a4a793761 100644
--- a/drivers/pmdomain/imx/imx8mp-blk-ctrl.c
+++ b/drivers/pmdomain/imx/imx8mp-blk-ctrl.c
@@ -192,20 +192,34 @@ static void imx8mp_hsio_blk_ctrl_power_off(struct imx8mp_blk_ctrl *bc,
 	}
 }
 
-static int imx8mp_hsio_enable_usb_clk(struct imx8mp_blk_ctrl *bc)
+static int imx8mp_hsio_propagate_adb_handshake(struct imx8mp_blk_ctrl *bc)
 {
 	int ret;
 	struct clk_bulk_data *usb_clk = bc->domains[IMX8MP_HSIOBLK_PD_USB].clks;
 	int num_clks = bc->domains[IMX8MP_HSIOBLK_PD_USB].data->num_clks;
+	static int once;
 
+	if (once)
+		return 0;
+
+	/*
+	 * enable USB clock for a moment for the power-on ADB handshake
+	 * to proceed
+	 */
 	ret = clk_bulk_prepare_enable(num_clks, usb_clk);
 	if (ret)
 		return ret;
 
 	regmap_set_bits(bc->regmap, GPR_REG0, USB_CLOCK_MODULE_EN);
 
-	return 0;
+	udelay(5);
+
+	regmap_clear_bits(bc->regmap, GPR_REG0, USB_CLOCK_MODULE_EN);
+	clk_bulk_disable_unprepare(num_clks, usb_clk);
 
+	once++;
+
+	return 0;
 }
 
 static const struct imx8mp_blk_ctrl_domain_data imx8mp_hsio_domain_data[] = {
@@ -251,10 +265,6 @@ static int imx8mp_blk_ctrl_power_on(struct generic_pm_domain *genpd)
 	struct imx8mp_blk_ctrl *bc = domain->bc;
 	int ret;
 
-	ret = imx8mp_hsio_enable_usb_clk(bc);
-	if (ret)
-		return ret;
-
 	/* make sure bus domain is awake */
 	ret = pm_runtime_resume_and_get_genpd(bc->bus_power_dev);
 	if (ret < 0) {
@@ -262,6 +272,12 @@ static int imx8mp_blk_ctrl_power_on(struct generic_pm_domain *genpd)
 		return ret;
 	}
 
+	ret = imx8mp_hsio_propagate_adb_handshake(bc);
+	if (ret) {
+		dev_err(bc->dev, "failed to propagate adb handshake\n");
+		goto bus_put;
+	}
+
 	/* enable upstream clocks */
 	ret = clk_bulk_prepare_enable(data->num_clks, domain->clks);
 	if (ret) {
-- 
2.39.2




             reply	other threads:[~2024-04-03 15:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-03 15:31 Marco Felsch [this message]
2024-04-03 16:03 ` Ahmad Fatoum
2024-04-04 13:41 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240403153151.2859387-1-m.felsch@pengutronix.de \
    --to=m.felsch@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox