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>
15 USB_EVENT_NONE, /* no events or cable disconnected */
16 USB_EVENT_VBUS, /* vbus valid event */
17 USB_EVENT_ID, /* id was grounded */
18 USB_EVENT_CHARGER, /* usb dedicated charger */
19 USB_EVENT_ENUMERATED, /* gadget driver enumerated */
22 /* associate a type with PHY */
24 USB_PHY_TYPE_UNDEFINED,
29 /* OTG defines lots of enumeration states before device reset */
31 OTG_STATE_UNDEFINED = 0,
33 /* single-role peripheral, and dual-role default-b */
36 OTG_STATE_B_PERIPHERAL,
38 /* extra dual-role default-b states */
39 OTG_STATE_B_WAIT_ACON,
42 /* dual-role default-a */
44 OTG_STATE_A_WAIT_VRISE,
45 OTG_STATE_A_WAIT_BCON,
48 OTG_STATE_A_PERIPHERAL,
49 OTG_STATE_A_WAIT_VFALL,
56 /* for transceivers connected thru an ULPI interface, the user must
59 struct usb_phy_io_ops {
60 int (*read)(struct usb_phy *x, u32 reg);
61 int (*write)(struct usb_phy *x, u32 val, u32 reg);
69 enum usb_phy_type type;
70 enum usb_otg_state state;
71 enum usb_phy_events last_event;
75 struct device *io_dev;
76 struct usb_phy_io_ops *io_ops;
77 void __iomem *io_priv;
79 /* for notification of usb_phy_events */
80 struct atomic_notifier_head notifier;
82 /* to pass extra port status to the root hub */
86 /* to support controllers that have multiple transceivers */
87 struct list_head head;
89 /* initialize/shutdown the OTG controller */
90 int (*init)(struct usb_phy *x);
91 void (*shutdown)(struct usb_phy *x);
93 /* effective for B devices, ignored for A-peripheral */
94 int (*set_power)(struct usb_phy *x,
97 /* for non-OTG B devices: set transceiver into suspend mode */
98 int (*set_suspend)(struct usb_phy *x,
101 /* notify phy connect status change */
102 int (*notify_connect)(struct usb_phy *x, int port);
103 int (*notify_disconnect)(struct usb_phy *x, int port);
107 /* for board-specific init logic */
108 extern int usb_add_phy(struct usb_phy *, enum usb_phy_type type);
109 extern void usb_remove_phy(struct usb_phy *);
111 /* helpers for direct access thru low-level io interface */
112 static inline int usb_phy_io_read(struct usb_phy *x, u32 reg)
114 if (x->io_ops && x->io_ops->read)
115 return x->io_ops->read(x, reg);
120 static inline int usb_phy_io_write(struct usb_phy *x, u32 val, u32 reg)
122 if (x->io_ops && x->io_ops->write)
123 return x->io_ops->write(x, val, reg);
129 usb_phy_init(struct usb_phy *x)
138 usb_phy_shutdown(struct usb_phy *x)
144 /* for usb host and peripheral controller drivers */
145 #ifdef CONFIG_USB_OTG_UTILS
146 extern struct usb_phy *usb_get_phy(enum usb_phy_type type);
147 extern struct usb_phy *devm_usb_get_phy(struct device *dev,
148 enum usb_phy_type type);
149 extern void usb_put_phy(struct usb_phy *);
150 extern void devm_usb_put_phy(struct device *dev, struct usb_phy *x);
152 static inline struct usb_phy *usb_get_phy(enum usb_phy_type type)
157 static inline struct usb_phy *devm_usb_get_phy(struct device *dev,
158 enum usb_phy_type type)
163 static inline void usb_put_phy(struct usb_phy *x)
167 static inline void devm_usb_put_phy(struct device *dev, struct usb_phy *x)
174 usb_phy_set_power(struct usb_phy *x, unsigned mA)
176 if (x && x->set_power)
177 return x->set_power(x, mA);
181 /* Context: can sleep */
183 usb_phy_set_suspend(struct usb_phy *x, int suspend)
185 if (x->set_suspend != NULL)
186 return x->set_suspend(x, suspend);
192 usb_phy_notify_connect(struct usb_phy *x, int port)
194 if (x->notify_connect)
195 return x->notify_connect(x, port);
201 usb_phy_notify_disconnect(struct usb_phy *x, int port)
203 if (x->notify_disconnect)
204 return x->notify_disconnect(x, port);
211 usb_register_notifier(struct usb_phy *x, struct notifier_block *nb)
213 return atomic_notifier_chain_register(&x->notifier, nb);
217 usb_unregister_notifier(struct usb_phy *x, struct notifier_block *nb)
219 atomic_notifier_chain_unregister(&x->notifier, nb);
222 static inline const char *usb_phy_type_string(enum usb_phy_type type)
225 case USB_PHY_TYPE_USB2:
227 case USB_PHY_TYPE_USB3:
230 return "UNKNOWN PHY TYPE";
233 #endif /* __LINUX_USB_PHY_H */