[PATCH v2] phy: phy-imx8mq-usb: add vbus regulator support
Marek Vasut
marex at denx.de
Mon Jul 10 18:33:11 CEST 2023
On 7/10/23 17:58, Tim Harvey wrote:
> On Mon, Jul 10, 2023 at 8:44 AM Marek Vasut <marex at denx.de> wrote:
>>
>> On 7/10/23 17:26, Tim Harvey wrote:
>>> On Sat, Jul 8, 2023 at 1:55 PM Marek Vasut <marex at denx.de> wrote:
>>>>
>>>> On 6/9/23 19:28, Tim Harvey wrote:
>>>>> Add support for enabling and disabling vbus-supply regulator found
>>>>> on several imx8mp boards in the usb3_phy0 and usb3_phy1 nodes.
>>>>>
>>>>> Signed-off-by: Tim Harvey <tharvey at gateworks.com>
>>>>> Reviewed-by: Adam Ford <aford173 at gmail.com>
>>>>> ---
>>>>> 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 | 32 ++++++++++++++++++++++++++++++--
>>>>> 1 file changed, 30 insertions(+), 2 deletions(-)
>>>>>
>>>>> diff --git a/drivers/phy/phy-imx8mq-usb.c b/drivers/phy/phy-imx8mq-usb.c
>>>>> index 69f01de55538..53099436b04b 100644
>>>>> --- a/drivers/phy/phy-imx8mq-usb.c
>>>>> +++ b/drivers/phy/phy-imx8mq-usb.c
>>>>> @@ -14,6 +14,7 @@
>>>>> #include <linux/delay.h>
>>>>> #include <linux/err.h>
>>>>> #include <clk.h>
>>>>> +#include <power/regulator.h>
>>>>>
>>>>> #define PHY_CTRL0 0x0
>>>>> #define PHY_CTRL0_REF_SSP_EN BIT(2)
>>>>> @@ -81,6 +82,7 @@ struct imx8mq_usb_phy {
>>>>> #endif
>>>>> void __iomem *base;
>>>>> enum imx8mpq_phy_type type;
>>>>
>>>> Shouldn't this be in #if CONFIG_IS_ENABLED(DM_REGULATOR) ?
>>>>
>>>>> + struct udevice *vbus_supply;
>>>
>>> Hi Marek,
>>>
>>> No, the usage of it is within an 'if (CONFIG_IS_ENABLED(DM_REGULATOR)
>>> && imx_phy->vbus_supply)' statement
>>
>> Except if this is not ifdef'd out, the structure is larger for no good
>> reason if DM_REGULATOR is DISABLED.
>
> ok, I see your point.
>
>>
>>>>> };
>>>>>
>>>>> static const struct udevice_id imx8mq_usb_phy_of_match[] = {
>>>>> @@ -172,10 +174,10 @@ static int imx8mq_usb_phy_power_on(struct phy *usb_phy)
>>>>> {
>>>>> struct udevice *dev = usb_phy->dev;
>>>>> struct imx8mq_usb_phy *imx_phy = dev_get_priv(dev);
>>>>> + __maybe_unused int ret;
>>>>> u32 value;
>>>>>
>>>>> #if CONFIG_IS_ENABLED(CLK)
>>>>> - int ret;
>>>>> ret = clk_enable(&imx_phy->phy_clk);
>>>>> if (ret) {
>>>>> printf("Failed to enable usb phy clock\n");
>>>>> @@ -183,6 +185,14 @@ static int imx8mq_usb_phy_power_on(struct phy *usb_phy)
>>>>> }
>>>>> #endif
>>>>>
>>>>> + if (CONFIG_IS_ENABLED(DM_REGULATOR) && imx_phy->vbus_supply) {
>>>>> + ret = regulator_set_enable(imx_phy->vbus_supply, true);
>>>>> + if (ret) {
>>>>> + pr_err("Failed to enable VBUS regulator: %d\n", ret);
>>>>
>>>> You do need to disable clock enabled above.
>>>
>>> it does get disabled in imx8mq_usb_phy_power_off()
>>
>> If that called if power_on returns -ERRNO ?
>
> sorry, I don't quite understand.
>
> Are you asking me to add a regulator disable in a remove function to
> make sure it's disabled if removed or are you saying that I shouldn't
> return the error from regulator_set_enable from
> imx8mq_usb_phy_power_on?
Actually, neither. There is clk_enable() a bit higher up in this
power_on function. You need to stop the clock if this
regulator_set_enable() return -ERRNO.
>>>> This likely needs a fail path with "err: ... return ret;"
>>>
>>> there are no further conditional return paths in this function.
>>
>> I suspect there should be.
>
> again, I don't understand. The only thing remaining in this function
> is disable rx term override below so I don't see the point in adding a
> goto around that if that is what you are suggesting.
>
> I don't really know what 'rx term override' is either... perhaps the
> regulator_set_enable should go after that?
Its only a matter of disabling the clock if the regulator enable fails
and we bail out, that's all. Does it make sense now ?
More information about the U-Boot
mailing list