The resynced DWC3 core includes linux/usb/phy.h and uses struct usb_phy,
usb_phy_init(), usb_phy_shutdown(), usb_phy_set_power() and
usb_phy_set_suspend(). u-boot has none of them.

Add a cut down version of include/linux/usb/phy.h from Linux v6.16. Only
the parts the DWC3 core needs are here.

usb_phy_set_suspend() is a stub that returns 0. u-boot never suspends
the controller, so there is nothing to do.

Linux calls usb_phy_set_charger_current() from usb_phy_set_power().
u-boot has no charger framework, so the call is left as a comment. It
marks where the call goes if someone adds one later.

Co-developed-by: Jerome Forissier <[email protected]>
Signed-off-by: Jerome Forissier <[email protected]>
Co-developed-by: Jens Wiklander <[email protected]>
Signed-off-by: Jens Wiklander <[email protected]>
Signed-off-by: Anders Roxell <[email protected]>
---
 include/linux/usb/phy.h | 56 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h
index 14b2c7eb2e63..afda7870e21e 100644
--- a/include/linux/usb/phy.h
+++ b/include/linux/usb/phy.h
@@ -21,6 +21,13 @@ enum usb_phy_interface {
        USBPHY_INTERFACE_MODE_HSIC,
 };
 
+/* associate a type with PHY */
+enum usb_phy_type {
+       USB_PHY_TYPE_UNDEFINED,
+       USB_PHY_TYPE_USB2,
+       USB_PHY_TYPE_USB3,
+};
+
 #if CONFIG_IS_ENABLED(DM_USB)
 /**
  * usb_get_phy_mode - Get phy mode for given device_node
@@ -37,4 +44,53 @@ static inline enum usb_phy_interface usb_get_phy_mode(ofnode 
node)
 }
 #endif
 
+struct usb_phy {
+       struct device           *dev;
+
+       /* initialize/shutdown the phy */
+       int     (*init)(struct usb_phy *x);
+       void    (*shutdown)(struct usb_phy *x);
+
+       /* enable/disable VBUS */
+       int     (*set_vbus)(struct usb_phy *x, int on);
+
+       /* effective for B devices, ignored for A-peripheral */
+       int     (*set_power)(struct usb_phy *x,
+                            unsigned int mA);
+};
+
+static inline int
+usb_phy_init(struct usb_phy *x)
+{
+       if (x && x->init)
+               return x->init(x);
+
+       return 0;
+}
+
+static inline void
+usb_phy_shutdown(struct usb_phy *x)
+{
+       if (x && x->shutdown)
+               x->shutdown(x);
+}
+
+static inline int
+usb_phy_set_power(struct usb_phy *x, unsigned int mA)
+{
+       if (!x)
+               return 0;
+
+       /* TODO usb_phy_set_charger_current(x, mA); */
+
+       if (x->set_power)
+               return x->set_power(x, mA);
+       return 0;
+}
+
+static inline int
+usb_phy_set_suspend(struct usb_phy *x, int suspend)
+{
+       return 0;
+}
 #endif /* __LINUX_USB_PHY_H */
-- 
2.53.0

Reply via email to