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 B0009C001B0 for ; Wed, 12 Jul 2023 20:04:04 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1504886A82; Wed, 12 Jul 2023 22:04:02 +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="ngClRK5J"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6118686A0B; Wed, 12 Jul 2023 22:04:00 +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 B0E0186B0D for ; Wed, 12 Jul 2023 22:03:57 +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-5701eaf0d04so80696097b3.2 for ; Wed, 12 Jul 2023 13:03:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; t=1689192231; x=1691784231; 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=dvgZZc7D1YHLLY+vIuMX4w0U/+ZlfYGMsyX8O3q+EPs=; b=ngClRK5JUdB60tjrJ/JffOkr4NvJwawATKzxb8P/rSfvKlUsq/w7IIX3Ymta/YbI1w zt02U1yVochTw19KfUCtLEJJH/TFraiX7ii9xg4q4C/ex0puqs0Ca3Vj94p4tYXjI8qk /9QimjcaU+WRy2AyZ1dcMsiERxs6ByVZInnxA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689192231; x=1691784231; 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=dvgZZc7D1YHLLY+vIuMX4w0U/+ZlfYGMsyX8O3q+EPs=; b=jIIpJbEPznnrYIAkBWDqs3FzaSJUSEyVyX4FPxWg1rDwqv19XjLw0GijkLZog/W6fh 87Pu7Tx8sDb6khdzSO/jLrw7GaRw4eJSjU0dcOdKRPXLLjkWwZLXvPrOpwOD+Apt9tqI 4laCqBqUqi+azkclLRwZfVW765btxp5XorMCh4hgWZWCSdJDBDuTs4Jb4PX1DGJMWl5B BuN9zbMz3nP1O7sDiWIUCFx3rdwdwJseZmsVHSBrHjYDk50i8L/bwkNjsSdPR8RMAW5v lW12+3Zb2jm0lwEIOdOBJf1aHSn+9D4pOlthhHv08M/x8oskoGJ3c1bFaOiovkWj+Fth 71Bg== X-Gm-Message-State: ABy/qLagTyXbuYghEvi7jKtt0AZjR8nm9R3yToMLBCi2n4+A9LVxSQZC Mh1oSWH+lL+NFChEyJHARK6EcQ== X-Google-Smtp-Source: APBJJlHfy0cpHshFEfwLxBO/VpIvVaEu9ad1QeWo+HLh75FLMWtKvn7TCHDNtGu7c5yO0+gE5UGhgA== X-Received: by 2002:a81:a104:0:b0:57a:8de8:58d9 with SMTP id y4-20020a81a104000000b0057a8de858d9mr7963449ywg.33.1689192231306; Wed, 12 Jul 2023 13:03:51 -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 x206-20020a817cd7000000b0057a8dd7f707sm1362007ywc.2.2023.07.12.13.03.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 13:03:50 -0700 (PDT) Date: Wed, 12 Jul 2023 16:03:49 -0400 From: Tom Rini To: Tim Harvey Cc: Marek Vasut , 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: <20230712200349.GF2066889@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="X7XptoA52FWMWiL9" 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 --X7XptoA52FWMWiL9 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jul 12, 2023 at 11:30:58AM -0700, Tim Harvey wrote: > On Wed, Jul 12, 2023 at 10:25=E2=80=AFAM Marek Vasut wrot= e: > > > > On 7/12/23 18:29, Tim Harvey wrote: > > > On Wed, Jul 12, 2023 at 8:10=E2=80=AFAM Tim Harvey wrote: > > >> > > >> On Wed, Jul 12, 2023 at 2:15=E2=80=AFAM Marek Vasut = wrote: > > >>> > > >>> On 7/11/23 22:13, Tim Harvey wrote: > > >>>> On Mon, Jul 10, 2023 at 4:18=E2=80=AFPM Marek Vasut wrote: > > >>>>> > > >>>>> On 7/11/23 00:49, Tim Harvey wrote: > > >>>>>> Add support for enabling and disabling vbus-supply regulator fou= nd > > >>>>>> on several imx8mp boards in the usb3_phy0 and usb3_phy1 nodes. > > >>>>>> > > >>>>>> Signed-off-by: Tim Harvey > > >>>>>> Reviewed-by: Adam Ford > > >>>>>> Reviewed-by: Marek Vasut > > >>>>>> --- > > >>>>>> v4: > > >>>>>> - use regulator_set_enable_if_allowed to handle regulator re= ference counting > > >>>>>> errors > > >>>>>> - added Marek's rb tag > > >>>>>> > > >>>>>> v3: > > >>>>>> - change pr_err to dev_err > > >>>>>> - add #if CONFIG_IS_ENABLED around vbus_supply in struct > > >>>>>> - add fail path to disable clock if regulator enable failed > > >>>>>> > > >>>>>> 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(-) > > >>>>>> > > >>>>>> diff --git a/drivers/phy/phy-imx8mq-usb.c b/drivers/phy/phy-imx8= mq-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 > > >>>>>> > > >>>>>> #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 > > >>>>>> }; > > >>>>>> > > >>>>>> static const struct udevice_id imx8mq_usb_phy_of_match[] =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; > > >>>>>> > > >>>>>> #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 > > >>>>>> > > >>>>>> + if (CONFIG_IS_ENABLED(DM_REGULATOR) && imx_phy->vbus_suppl= y) { > > >>>>>> + ret =3D regulator_set_enable_if_allowed(imx_phy->v= bus_supply, true); > > >>>>>> + if (ret && ret !=3D -ENOSYS) { > > >>>>>> + dev_err(dev, "Failed to enable VBUS regula= tor: %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); > > >>>>>> > > >>>>>> return 0; > > >>>>>> + > > >>>>>> +err: > > >>>>>> + clk_disable(&imx_phy->phy_clk); > > >>>>>> + return ret; > > >>>>>> } > > >>>>>> > > >>>>>> 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; > > >>>>>> > > >>>>>> /* 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 > > >>>>>> > > >>>>>> + if (CONFIG_IS_ENABLED(DM_REGULATOR) && imx_phy->vbus_suppl= y) { > > >>>>>> + ret =3D regulator_set_enable_if_allowed(imx_phy->v= bus_supply, false); > > >>>>>> + if (ret && ret !=3D -ENOSYS) { > > >>>>>> + dev_err(dev, "Failed to disable VBUS regul= ator: %d\n", ret); > > >>>>>> + return ret; > > >>>>>> + } > > >>>>>> + } > > >>>>>> + > > >>>>>> return 0; > > >>>>>> } > > >>>>>> > > >>>>>> @@ -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; > > >>>>>> > > >>>>>> 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 udevice *dev) > > >>>>>> return -EINVAL; > > >>>>>> > > >>>>>> #if CONFIG_IS_ENABLED(CLK) > > >>>>>> - int ret; > > >>>>> > > >>>>> I _think_ if you were to convert this #if CONFIG...() to if > > >>>>> (CONFIG...()), you would be able to drop the __maybe_unused . Sep= arate > > >>>>> conversion patch would be better though. > > >>>> > > >>>> Hi Marek, > > >>> > > >>> Hi, > > >>> > > >>>> Yes, I thought about that as well and felt it should be a separate > > >>>> followup cleanup patch. > > >>> > > >>> Can you please send such a follow up patch ? > > >>> > > >> > > >> 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? > > >> > > > > > > Marek, > > > > > > It seems Stefano picked up my v2 version of this patch in his > > > master/next tree he's working on right now [1]. > > > > 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 > > > > > 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 space > > > if you're doing runtime comparisons. > > > > > > For example: > > > > > > 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 > > > }; > > > > > > if (CONFIG_IS_ENABLED(DM_REGULATOR) && imx_phy->vbus_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 regulato= r: > > > %d\n", ret); > > > goto err; > > > } > > > } > > > > > > 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. > > > > > > So I'm not quite sure how to proceed at this time. > > > > > > 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))' > > > > Does #ifdef work for the structure members ? I think it should do the t= rick. >=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? I find that if (MACRO(CONFIG_FOO)) stuff isn't always super helpful, no. I know Simon disagrees but problems like the above crop up quite often as you cannot use them when structs are involved unless we always include everything in the struct, which also isn't always possible. --=20 Tom --X7XptoA52FWMWiL9 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQGzBAABCgAdFiEEGjx/cOCPqxcHgJu/FHw5/5Y0tywFAmSvBx4ACgkQFHw5/5Y0 tyyytgv/U+UccIKKboN+NmSHAWop6V0qo+SD5oDEN5L7BBmUoQBHcKfplP7NuWJG 2UAKNkGHghTDLO0TSsL7IIiaUjFExjs853FBvbA7WWi92P5HnG25APWWoWov2nR+ kMBD3XRwopTyb2o4nWC7FaY9h7007BAHLrj7L6yYPSZTyWbBg8PzTSMyS4z86D9u 7xA/nAgT7vIy0Vqg+vMxqkFiOGm2BmDGxO/nFeBo/2MeZQnz0LxvUrr9AT9n6/4x Eg3Z7onyAhW0YQxt0/0m6bNwKD6nU+CMcPC6Q3E7MN3Yz5Btuj/dp2+RyBJ/cdtv 1rJtFxJcqY9LDNPvau1ztxUk2HteW8WgbFfN/ELGHbdV3dvn15ZM8mA6e897ObgC ohcc8T/UETWQbpDSBX1FcrrwtFLcp9PmsTpmOVITFxVoiksth1G7qWGe/cOUEhOE UNYLBZl6+wY1w32w3vJdevnyfU91GCstryLxMQu4hBGm98jSyThk0xWsvP7QP/MB 8GiVOTQJ =M8ln -----END PGP SIGNATURE----- --X7XptoA52FWMWiL9--