1 /* USB OTG (On The Go) defines */
4 * These APIs may be used between USB controllers. USB device drivers
5 * (for either host or peripheral roles) don't use these calls; they
6 * continue to use just usb_device and usb_gadget.
9 #ifndef __LINUX_USB_PHY_H
10 #define __LINUX_USB_PHY_H
12 #include <linux/notifier.h>
13 #include <linux/usb.h>
16 USB_EVENT_NONE, /* no events or cable disconnected */
17 USB_EVENT_VBUS, /* vbus valid event */
18 USB_EVENT_ID, /* id was grounded */
19 USB_EVENT_CHARGER, /* usb dedicated charger */
20 USB_EVENT_ENUMERATED, /* gadget driver enumerated */
23 /* associate a type with PHY */
25 USB_PHY_TYPE_UNDEFINED,
30 /* OTG defines lots of enumeration states before device reset */
32 OTG_STATE_UNDEFINED = 0,
34 /* single-role peripheral, and dual-role default-b */
37 OTG_STATE_B_PERIPHERAL,
39 /* extra dual-role default-b states */
40 OTG_STATE_B_WAIT_ACON,
43 /* dual-role default-a */
45 OTG_STATE_A_WAIT_VRISE,
46 OTG_STATE_A_WAIT_BCON,
49 OTG_STATE_A_PERIPHERAL,
50 OTG_STATE_A_WAIT_VFALL,
57 /* for transceivers connected thru an ULPI interface, the user must
60 struct usb_phy_io_ops {
61 int (*read)(struct usb_phy *x, u32 reg);
62 int (*write)(struct usb_phy *x, u32 val, u32 reg);
70 enum usb_phy_type type;
71 enum usb_otg_state state;
72 enum usb_phy_events last_event;
76 struct device *io_dev;
77 struct usb_phy_io_ops *io_ops;
78 void __iomem *io_priv;
80 /* for notification of usb_phy_events */
81 struct atomic_notifier_head notifier;
83 /* to pass extra port status to the root hub */
87 /* to support controllers that have multiple transceivers */
88 struct list_head head;
90 /* initialize/shutdown the OTG controller */
91 int (*init)(struct usb_phy *x);
92 void (*shutdown)(struct usb_phy *x);
94 /* enable/disable VBUS */
95 int (*set_vbus)(struct usb_phy *x, int on);
97 /* effective for B devices, ignored for A-peripheral */
98 int (*set_power)(struct usb_phy *x,
101 /* for non-OTG B devices: set transceiver into suspend mode */
102 int (*set_suspend)(struct usb_phy *x,
105 /* notify phy connect status change */
106 int (*notify_connect)(struct usb_phy *x,
107 enum usb_device_speed speed);
108 int (*notify_disconnect)(struct usb_phy *x,
109 enum usb_device_speed speed);
113 * struct usb_phy_bind - represent the binding for the phy
114 * @dev_name: the device name of the device that will bind to the phy
115 * @phy_dev_name: the device name of the phy
116 * @index: used if a single controller uses multiple phys
117 * @phy: reference to the phy
118 * @list: to maintain a linked list of the binding information
120 struct usb_phy_bind {
121 const char *dev_name;
122 const char *phy_dev_name;
125 struct list_head list;
128 /* for board-specific init logic */
129 extern int usb_add_phy(struct usb_phy *, enum usb_phy_type type);
130 extern int usb_add_phy_dev(struct usb_phy *);
131 extern void usb_remove_phy(struct usb_phy *);
133 /* helpers for direct access thru low-level io interface */
134 static inline int usb_phy_io_read(struct usb_phy *x, u32 reg)
136 if (x->io_ops && x->io_ops->read)
137 return x->io_ops->read(x, reg);
142 static inline int usb_phy_io_write(struct usb_phy *x, u32 val, u32 reg)
144 if (x->io_ops && x->io_ops->write)
145 return x->io_ops->write(x, val, reg);
151 usb_phy_init(struct usb_phy *x)
160 usb_phy_shutdown(struct usb_phy *x)
167 usb_phy_vbus_on(struct usb_phy *x)
172 return x->set_vbus(x, true);
176 usb_phy_vbus_off(struct usb_phy *x)
181 return x->set_vbus(x, false);
184 /* for usb host and peripheral controller drivers */
185 #if IS_ENABLED(CONFIG_USB_PHY)
186 extern struct usb_phy *usb_get_phy(enum usb_phy_type type);
187 extern struct usb_phy *devm_usb_get_phy(struct device *dev,
188 enum usb_phy_type type);
189 extern struct usb_phy *usb_get_phy_dev(struct device *dev, u8 index);
190 extern struct usb_phy *devm_usb_get_phy_dev(struct device *dev, u8 index);
191 extern struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
192 const char *phandle, u8 index);
193 extern void usb_put_phy(struct usb_phy *);
194 extern void devm_usb_put_phy(struct device *dev, struct usb_phy *x);
195 extern int usb_bind_phy(const char *dev_name, u8 index,
196 const char *phy_dev_name);
198 static inline struct usb_phy *usb_get_phy(enum usb_phy_type type)
200 return ERR_PTR(-ENXIO);
203 static inline struct usb_phy *devm_usb_get_phy(struct device *dev,
204 enum usb_phy_type type)
206 return ERR_PTR(-ENXIO);
209 static inline struct usb_phy *usb_get_phy_dev(struct device *dev, u8 index)
211 return ERR_PTR(-ENXIO);
214 static inline struct usb_phy *devm_usb_get_phy_dev(struct device *dev, u8 index)
216 return ERR_PTR(-ENXIO);
219 static inline struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
220 const char *phandle, u8 index)
222 return ERR_PTR(-ENXIO);
225 static inline void usb_put_phy(struct usb_phy *x)
229 static inline void devm_usb_put_phy(struct device *dev, struct usb_phy *x)
233 static inline int usb_bind_phy(const char *dev_name, u8 index,
234 const char *phy_dev_name)
241 usb_phy_set_power(struct usb_phy *x, unsigned mA)
243 if (x && x->set_power)
244 return x->set_power(x, mA);
248 /* Context: can sleep */
250 usb_phy_set_suspend(struct usb_phy *x, int suspend)
252 if (x->set_suspend != NULL)
253 return x->set_suspend(x, suspend);
259 usb_phy_notify_connect(struct usb_phy *x, enum usb_device_speed speed)
261 if (x->notify_connect)
262 return x->notify_connect(x, speed);
268 usb_phy_notify_disconnect(struct usb_phy *x, enum usb_device_speed speed)
270 if (x->notify_disconnect)
271 return x->notify_disconnect(x, speed);
278 usb_register_notifier(struct usb_phy *x, struct notifier_block *nb)
280 return atomic_notifier_chain_register(&x->notifier, nb);
284 usb_unregister_notifier(struct usb_phy *x, struct notifier_block *nb)
286 atomic_notifier_chain_unregister(&x->notifier, nb);
289 static inline const char *usb_phy_type_string(enum usb_phy_type type)
292 case USB_PHY_TYPE_USB2:
294 case USB_PHY_TYPE_USB3:
297 return "UNKNOWN PHY TYPE";
300 #endif /* __LINUX_USB_PHY_H */