[PATCH 1/2 v2] usb: dwc2: Make having a phy optional
Jules Maselbas
jmaselbas at kalray.eu
Tue Oct 19 09:16:54 PDT 2021
Hi Daniel,
On Wed, Sep 08, 2021 at 02:58:53PM +0200, Daniel Brát wrote:
> Despite using 'phy_optional_get' to get a 'usb2-phy' inside its probe,
> the driver would fail if it didnt find it. Also, there is no Kconfig
> dependency on 'CONFIG_GENERIC_PHY', so without it defined the phy
> functions are unimplemented and always return -ENOSYS making dwc2 probe
> always fail too.
> The header stub of 'phy_optional_get' was changed to return NULL and
> the dwc2 driver was modified accordingly.
>
> Signed-off-by: Daniel Brát <danek.brat at gmail.com>
> ---
> drivers/usb/dwc2/dwc2.c | 27 +++++++++++++++------------
> include/linux/phy/phy.h | 2 +-
> 2 files changed, 16 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/usb/dwc2/dwc2.c b/drivers/usb/dwc2/dwc2.c
> index 9893977b8..472a0b7d9 100644
> --- a/drivers/usb/dwc2/dwc2.c
> +++ b/drivers/usb/dwc2/dwc2.c
> @@ -73,19 +73,22 @@ static int dwc2_probe(struct device_d *dev)
> goto clk_disable;
>
> dwc2->phy = phy_optional_get(dev, "usb2-phy");
> - if (IS_ERR(dwc2->phy)) {
> - ret = PTR_ERR(dwc2->phy);
> - goto clk_disable;
> + if (dwc2->phy) {
> + if (IS_ERR(dwc2->phy)) {
> + dev_warn(dev, "Couldnt get 'usb2-phy': %s\n",
> + strerror(PTR_ERR(dwc2->phy)));
> + goto phy_bypass;
> + }
> +
> + ret = phy_power_on(dwc2->phy);
> + if (ret)
> + goto clk_disable;
> +
> + ret = phy_init(dwc2->phy);
> + if (ret)
> + goto phy_power_off;
> }
> -
> - ret = phy_power_on(dwc2->phy);
> - if (ret)
> - goto clk_disable;
> -
> - ret = phy_init(dwc2->phy);
> - if (ret)
> - goto phy_power_off;
> -
> +phy_bypass:
> ret = dwc2_check_core_version(dwc2);
> if (ret)
> goto error;
> diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h
> index 679ce6e42..321e546f9 100644
> --- a/include/linux/phy/phy.h
> +++ b/include/linux/phy/phy.h
> @@ -195,7 +195,7 @@ static inline struct phy *phy_get(struct device_d *dev, const char *string)
> static inline struct phy *phy_optional_get(struct device_d *dev,
> const char *string)
> {
> - return ERR_PTR(-ENOSYS);
> + return NULL;
> }
I am interested in getting this modification merged. Beside I don't
think the dwc2 driver modification is needed, as phy_optional_get is
intended to return NULL when no phy are available. For me it makes
sense that NULL could be return by phy_optional_get when the phy
support is not compiled in.
Do you have the time to send a new patch with only this modification ?
Thanks,
Jules
More information about the barebox
mailing list