Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 74E58EB64DD for ; Wed, 12 Jul 2023 21:59:50 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7363886AD9; Wed, 12 Jul 2023 23:59:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=konsulko.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=konsulko.com header.i=@konsulko.com header.b="exYnFtlX"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3060986ADE; Wed, 12 Jul 2023 23:59:47 +0200 (CEST) Received: from mail-yw1-x1131.google.com (mail-yw1-x1131.google.com [IPv6:2607:f8b0:4864:20::1131]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 2F5A686AB8 for ; Wed, 12 Jul 2023 23:59:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=konsulko.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=trini@konsulko.com Received: by mail-yw1-x1131.google.com with SMTP id 00721157ae682-579d5d89b41so83283027b3.2 for ; Wed, 12 Jul 2023 14:59:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; t=1689199183; x=1691791183; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=T1wW/QoZ2rM+0DNIDuyOniIY8PNAD+C5GztRQ1H0HGQ=; b=exYnFtlXw7DJwpA8kCyvpAT5K4nOzLEQVPbfA/6nwAVr8E1mUn9ecy53nuFhE35DxJ RvYP0wfwddWfvnsOlILatkumzAMSGZyhWf+934MHRct134iZa5CiuHbVUfP3AArESzC3 ij77VCi38HepEj/YyW9jaV9YJjcPdor9oDprE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689199183; x=1691791183; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=T1wW/QoZ2rM+0DNIDuyOniIY8PNAD+C5GztRQ1H0HGQ=; b=Btr66y+p/dEn6c8IHG8/ZTYVA1Zufg8R/lNqfQTCECmz4c32OuBXCQfgULLYZTzWMm fWl71w1/WaISZEPZSgWQ2BsKYRSGNSXuY3M2aLnD5e5CnlwBE/DF78tDW5ub3GfpVxpj 5OU5Yy1PwMiJG24mP0njJ+Ze+Lgiu38BZ9vCupx2w+G4vNd5eCuPOm4t+WdZcUYDCPYx X7f4pKPzZrY3UFpem5MI0s0PZbUn11TCrKhsrr82koBLSPSF4GNYjog3K3knBy5vyDCU k7/53XB+Q/W/e4rtpRbpIhfXKNggMtS29dLvFFPTkDs0ivD885dAJzTPQeJdzp5o2NXB nh2Q== X-Gm-Message-State: ABy/qLYw2KVpYCcKDbG1blW283X3+IZ97o70iZmwpe2bP2a7JpD0FiQz LDUIczuFui+q2eD3lEVExhCs4A== X-Google-Smtp-Source: APBJJlGK8ZDJVwrrmro+E6UzhqN7l90NkDkbD5S4zOXSNApELDgZt5Z7Re/qG6Rbpfx4dpzAgaiXTw== X-Received: by 2002:a0d:c784:0:b0:56f:ff88:2e43 with SMTP id j126-20020a0dc784000000b0056fff882e43mr18869149ywd.27.1689199182811; Wed, 12 Jul 2023 14:59:42 -0700 (PDT) Received: from bill-the-cat (2603-6081-7b00-6400-616f-f5d3-9cfa-22fc.res6.spectrum.com. [2603:6081:7b00:6400:616f:f5d3:9cfa:22fc]) by smtp.gmail.com with ESMTPSA id r14-20020a81c30e000000b00576cd8f9770sm1385920ywk.146.2023.07.12.14.59.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 14:59:42 -0700 (PDT) Date: Wed, 12 Jul 2023 17:59:40 -0400 From: Tom Rini To: Marek Vasut Cc: Tim Harvey , Stefano Babic , Simon Glass , u-boot@lists.denx.de, Fabio Estevam , Adam Ford , Martyn Welch , Marcel Ziswiler , "NXP i . MX U-Boot Team" Subject: Re: [PATCH v4] phy: phy-imx8mq-usb: add vbus regulator support Message-ID: <20230712215940.GK2066889@bill-the-cat> References: <20230710224932.1996810-1-tharvey@gateworks.com> <5528fd1b-22f8-efef-f05a-56da34601a64@denx.de> <26c2df20-5f74-40da-b23e-0e15ae61b937@denx.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="IDkudY8O7gBEJd6/" Content-Disposition: inline In-Reply-To: X-Clacks-Overhead: GNU Terry Pratchett X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean --IDkudY8O7gBEJd6/ Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jul 12, 2023 at 11:40:37PM +0200, Marek Vasut wrote: > On 7/12/23 20:30, Tim Harvey wrote: > > On Wed, Jul 12, 2023 at 10:25=E2=80=AFAM Marek Vasut wr= ote: > > >=20 > > > On 7/12/23 18:29, Tim Harvey wrote: > > > > On Wed, Jul 12, 2023 at 8:10=E2=80=AFAM Tim Harvey wrote: > > > > >=20 > > > > > On Wed, Jul 12, 2023 at 2:15=E2=80=AFAM Marek Vasut wrote: > > > > > >=20 > > > > > > On 7/11/23 22:13, Tim Harvey wrote: > > > > > > > On Mon, Jul 10, 2023 at 4:18=E2=80=AFPM Marek Vasut wrote: > > > > > > > >=20 > > > > > > > > On 7/11/23 00:49, Tim Harvey wrote: > > > > > > > > > Add support for enabling and disabling vbus-supply regula= tor found > > > > > > > > > on several imx8mp boards in the usb3_phy0 and usb3_phy1 n= odes. > > > > > > > > >=20 > > > > > > > > > Signed-off-by: Tim Harvey > > > > > > > > > Reviewed-by: Adam Ford > > > > > > > > > Reviewed-by: Marek Vasut > > > > > > > > > --- > > > > > > > > > v4: > > > > > > > > > - use regulator_set_enable_if_allowed to handle regu= lator reference counting > > > > > > > > > errors > > > > > > > > > - added Marek's rb tag > > > > > > > > >=20 > > > > > > > > > v3: > > > > > > > > > - change pr_err to dev_err > > > > > > > > > - add #if CONFIG_IS_ENABLED around vbus_supply in st= ruct > > > > > > > > > - add fail path to disable clock if regulator enable= failed > > > > > > > > >=20 > > > > > > > > > v2: > > > > > > > > > - protect ret with __maybe_unused in case CONFIG_CLK= and > > > > > > > > > CONFIG_DM_REGULATOR not defined > > > > > > > > > - add error prints on failures > > > > > > > > > - add Adam's rb tag > > > > > > > > > --- > > > > > > > > > drivers/phy/phy-imx8mq-usb.c | 39 ++++++++++++++++++= ++++++++++++++++-- > > > > > > > > > 1 file changed, 37 insertions(+), 2 deletions(-) > > > > > > > > >=20 > > > > > > > > > diff --git a/drivers/phy/phy-imx8mq-usb.c b/drivers/phy/p= hy-imx8mq-usb.c > > > > > > > > > index 69f01de55538..6cbcb2338cfe 100644 > > > > > > > > > --- a/drivers/phy/phy-imx8mq-usb.c > > > > > > > > > +++ b/drivers/phy/phy-imx8mq-usb.c > > > > > > > > > @@ -14,6 +14,8 @@ > > > > > > > > > #include > > > > > > > > > #include > > > > > > > > > #include > > > > > > > > > +#include > > > > > > > > > +#include > > > > > > > > >=20 > > > > > > > > > #define PHY_CTRL0 0x0 > > > > > > > > > #define PHY_CTRL0_REF_SSP_EN BIT(2) > > > > > > > > > @@ -81,6 +83,9 @@ struct imx8mq_usb_phy { > > > > > > > > > #endif > > > > > > > > > void __iomem *base; > > > > > > > > > enum imx8mpq_phy_type type; > > > > > > > > > +#if CONFIG_IS_ENABLED(DM_REGULATOR) > > > > > > > > > + struct udevice *vbus_supply; > > > > > > > > > +#endif > > > > > > > > > }; > > > > > > > > >=20 > > > > > > > > > static const struct udevice_id imx8mq_usb_phy_of_mat= ch[] =3D { > > > > > > > > > @@ -172,10 +177,10 @@ static int imx8mq_usb_phy_power_on(= struct phy *usb_phy) > > > > > > > > > { > > > > > > > > > struct udevice *dev =3D usb_phy->dev; > > > > > > > > > struct imx8mq_usb_phy *imx_phy =3D dev_get_priv(= dev); > > > > > > > > > + __maybe_unused int ret; > > > > > > > > > u32 value; > > > > > > > > >=20 > > > > > > > > > #if CONFIG_IS_ENABLED(CLK) > > > > > > > > > - int ret; > > > > > > > > > ret =3D clk_enable(&imx_phy->phy_clk); > > > > > > > > > if (ret) { > > > > > > > > > printf("Failed to enable usb phy clock\n= "); > > > > > > > > > @@ -183,18 +188,31 @@ static int imx8mq_usb_phy_power_on(= struct phy *usb_phy) > > > > > > > > > } > > > > > > > > > #endif > > > > > > > > >=20 > > > > > > > > > + if (CONFIG_IS_ENABLED(DM_REGULATOR) && imx_phy->vbu= s_supply) { > > > > > > > > > + ret =3D regulator_set_enable_if_allowed(imx= _phy->vbus_supply, true); > > > > > > > > > + if (ret && ret !=3D -ENOSYS) { > > > > > > > > > + dev_err(dev, "Failed to enable VBUS= regulator: %d\n", ret); > > > > > > > > > + goto err; > > > > > > > > > + } > > > > > > > > > + } > > > > > > > > > + > > > > > > > > > /* Disable rx term override */ > > > > > > > > > value =3D readl(imx_phy->base + PHY_CTRL6); > > > > > > > > > value &=3D ~PHY_CTRL6_RXTERM_OVERRIDE_SEL; > > > > > > > > > writel(value, imx_phy->base + PHY_CTRL6); > > > > > > > > >=20 > > > > > > > > > return 0; > > > > > > > > > + > > > > > > > > > +err: > > > > > > > > > + clk_disable(&imx_phy->phy_clk); > > > > > > > > > + return ret; > > > > > > > > > } > > > > > > > > >=20 > > > > > > > > > static int imx8mq_usb_phy_power_off(struct phy *usb_= phy) > > > > > > > > > { > > > > > > > > > struct udevice *dev =3D usb_phy->dev; > > > > > > > > > struct imx8mq_usb_phy *imx_phy =3D dev_get_priv(= dev); > > > > > > > > > + __maybe_unused int ret; > > > > > > > > > u32 value; > > > > > > > > >=20 > > > > > > > > > /* Override rx term to be 0 */ > > > > > > > > > @@ -206,6 +224,14 @@ static int imx8mq_usb_phy_power_off(= struct phy *usb_phy) > > > > > > > > > clk_disable(&imx_phy->phy_clk); > > > > > > > > > #endif > > > > > > > > >=20 > > > > > > > > > + if (CONFIG_IS_ENABLED(DM_REGULATOR) && imx_phy->vbu= s_supply) { > > > > > > > > > + ret =3D regulator_set_enable_if_allowed(imx= _phy->vbus_supply, false); > > > > > > > > > + if (ret && ret !=3D -ENOSYS) { > > > > > > > > > + dev_err(dev, "Failed to disable VBU= S regulator: %d\n", ret); > > > > > > > > > + return ret; > > > > > > > > > + } > > > > > > > > > + } > > > > > > > > > + > > > > > > > > > return 0; > > > > > > > > > } > > > > > > > > >=20 > > > > > > > > > @@ -224,6 +250,7 @@ struct phy_ops imx8mq_usb_phy_ops =3D= { > > > > > > > > > int imx8mq_usb_phy_probe(struct udevice *dev) > > > > > > > > > { > > > > > > > > > struct imx8mq_usb_phy *priv =3D dev_get_priv(dev= ); > > > > > > > > > + __maybe_unused int ret; > > > > > > > > >=20 > > > > > > > > > priv->type =3D dev_get_driver_data(dev); > > > > > > > > > priv->base =3D dev_read_addr_ptr(dev); > > > > > > > > > @@ -232,7 +259,6 @@ int imx8mq_usb_phy_probe(struct udevi= ce *dev) > > > > > > > > > return -EINVAL; > > > > > > > > >=20 > > > > > > > > > #if CONFIG_IS_ENABLED(CLK) > > > > > > > > > - int ret; > > > > > > > >=20 > > > > > > > > I _think_ if you were to convert this #if CONFIG...() to if > > > > > > > > (CONFIG...()), you would be able to drop the __maybe_unused= . Separate > > > > > > > > conversion patch would be better though. > > > > > > >=20 > > > > > > > Hi Marek, > > > > > >=20 > > > > > > Hi, > > > > > >=20 > > > > > > > Yes, I thought about that as well and felt it should be a sep= arate > > > > > > > followup cleanup patch. > > > > > >=20 > > > > > > Can you please send such a follow up patch ? > > > > > >=20 > > > > >=20 > > > > > Yes, I'll send a follow-up today. It looks like Stefano is picking > > > > > this up from the imx tree... is that where it should be picked up= or > > > > > should this be through you and the usb tree? > > > > >=20 > > > >=20 > > > > Marek, > > > >=20 > > > > It seems Stefano picked up my v2 version of this patch in his > > > > master/next tree he's working on right now [1]. > > >=20 > > > Likely this patch should be dropped from imx tree. > >=20 > > Stefano, > >=20 > > please drop from your imx/next tree: commit e445a1d7ffbd ("phy: > > phy-imx8mq-usb: add vbus regulator support"). Marek will take this > > through the usb tree when it's ready as it looks like I need a v5. > >=20 > > >=20 > > > > Also, I noticed my v4 patch here fails building if DM_REGULATOR is > > > > disabled. You can't wrap the struct members with macro's to save sp= ace > > > > if you're doing runtime comparisons. > > > >=20 > > > > For example: > > > >=20 > > > > struct imx8mq_usb_phy { > > > > #if CONFIG_IS_ENABLED(CLK) > > > > struct clk phy_clk; > > > > #endif > > > > void __iomem *base; > > > > enum imx8mpq_phy_type type; > > > > #if CONFIG_IS_ENABLED(DM_REGULATOR) > > > > struct udevice *vbus_supply; > > > > #endif > > > > }; > > > >=20 > > > > if (CONFIG_IS_ENABLED(DM_REGULATOR) && imx_phy->vbus_supp= ly) { > > > > ret =3D > > > > regulator_set_enable_if_allowed(imx_phy->vbus_supply, true); > > > > if (ret && ret !=3D -ENOSYS) { > > > > dev_err(dev, "Failed to enable VBUS regul= ator: > > > > %d\n", ret); > > > > goto err; > > > > } > > > > } > > > >=20 > > > > This fails if DM_REGULATOR is not enabled. Similarly I would assume > > > > the '#if CONFIG_IS_ENABLED(CLK)' is incorrect as well but I can't > > > > build for my board without CLK defined to prove it. > > > >=20 > > > > So I'm not quite sure how to proceed at this time. > > > >=20 > > > > Should I post a followup after Stefano's tree is ready for pull and > > > > merged that does the following? > > > > - change pr_err to dev_err (from my v3) > > > > - add fail path to disable clock if regulator enabled failed (from = my v3) > > > > - cleanup the clk code (remove #if CONFIG_IS_ENABLED(CLK) around clk > > > > struct member and use 'if (CONFIG_IS_ENABLED(CLK))' > > >=20 > > > Does #ifdef work for the structure members ? I think it should do the= trick. > >=20 > > Marek, > >=20 > > Wrapping vbus_supply with '#ifdef CONFIG_DM_REGULATOR' doesn't help. > > If you want to use the pattern 'if (CONFIG_IS_ENABLED(foo))' then that > > code gets compiled in and executed at runtime thus anything it's > > referencing needs to be there. > >=20 > > Is there a board using drivers/phy/phy-imx8mq-usb.c that doesn't > > require CLK? If so, I think you'll find that even before my patch > > disabling CLK will cause 'phy_clk' member not found issues due to: > > struct imx8mq_usb_phy { > > #if CONFIG_IS_ENABLED(CLK) > > struct clk phy_clk; > > #endif > > void __iomem *base; > > enum imx8mpq_phy_type type; > > }; > >=20 > > static int imx8mq_usb_phy_power_on(struct phy *usb_phy) > > { > > struct udevice *dev =3D usb_phy->dev; > > struct imx8mq_usb_phy *imx_phy =3D dev_get_priv(dev); > > u32 value; > >=20 > > #if CONFIG_IS_ENABLED(CLK) > > int ret; > > ret =3D clk_enable(&imx_phy->phy_clk); > > if (ret) { > > printf("Failed to enable usb phy clock\n"); > > return ret; > > } > > #endif > >=20 > > /* Disable rx term override */ > > value =3D readl(imx_phy->base + PHY_CTRL6); > > value &=3D ~PHY_CTRL6_RXTERM_OVERRIDE_SEL; > > writel(value, imx_phy->base + PHY_CTRL6); > >=20 > > return 0; > > } > >=20 > > Personally, I find all of the CONFIG_IS_ENABLED stuff pretty > > confusing. I'm not sure who the expert is on those constructs... > > perhaps Simon or Tom? >=20 > Tom, yeah. >=20 > But then , if there is no board which does disable CLK or PHY, then ... j= ust > "depends" on those in Kconfig and zap all the if CONFIG ... goo and probl= em > solved even better ? Yes, that would be good. I think using moveconfig.py (which is badly named at this point, yes) and the --find option should show if there's boards which do use that code but don't also enable all of those other options, and so we could move this to Kconfig depends and not have non-obvious failures. --=20 Tom --IDkudY8O7gBEJd6/ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQGzBAABCgAdFiEEGjx/cOCPqxcHgJu/FHw5/5Y0tywFAmSvIkUACgkQFHw5/5Y0 tywvvAwAjUtCXtU0EBoQE1idyoiXUM1RXjEjICO0pVthqLVelpgEH2LqnoxtzMZZ E8hn4HQoIjvdpFBS2igl5C+xzQGCOclM4n2obU68VK38BmzOXfKsG2B+lQQD3SMJ +l3rIPYScGfVPRKHHo0+3V4dDbjhRcg7jBFwSrGfiog0d/20F0NzYP8btnw8IqpU KeaWYaL7FBqpVnOG/piUgfwNhIGdNmZ6Ln1vo27iIANo1pk6/UjYQ5gQYcqeBXEt MRLaOCho52Chq3zr0cTIvDmmt83/gDvYNgKobvsLZ4wjSV1f/WMUbkfOJYn64j83 el5jXLKVLEGr2itehu+2r8YgdXofCi5rioky/R2V0et6z08M9Vos21SFdvP4yDG+ 7h00kLs/PiHQl3AQ6VT1kyJCGP2b4QJmziQ9AI5xuvxf2/x4Mik7PQ9owYnUQTqd ajKlxkMUsdUlgGVaZ8kF3dmfzZQCT9Tk91nB3X9I7dieW97JHyk6OjTFX9c/LELV iStHsSJr =z3Jj -----END PGP SIGNATURE----- --IDkudY8O7gBEJd6/--