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>
15 enum usb_phy_interface
{
16 USBPHY_INTERFACE_MODE_UNKNOWN
,
17 USBPHY_INTERFACE_MODE_UTMI
,
18 USBPHY_INTERFACE_MODE_UTMIW
,
19 USBPHY_INTERFACE_MODE_ULPI
,
20 USBPHY_INTERFACE_MODE_SERIAL
,
21 USBPHY_INTERFACE_MODE_HSIC
,
25 USB_EVENT_NONE
, /* no events or cable disconnected */
26 USB_EVENT_VBUS
, /* vbus valid event */
27 USB_EVENT_ID
, /* id was grounded */
28 USB_EVENT_CHARGER
, /* usb dedicated charger */
29 USB_EVENT_ENUMERATED
, /* gadget driver enumerated */
32 /* associate a type with PHY */
34 USB_PHY_TYPE_UNDEFINED
,
39 /* OTG defines lots of enumeration states before device reset */
41 OTG_STATE_UNDEFINED
= 0,
43 /* single-role peripheral, and dual-role default-b */
46 OTG_STATE_B_PERIPHERAL
,
48 /* extra dual-role default-b states */
49 OTG_STATE_B_WAIT_ACON
,
52 /* dual-role default-a */
54 OTG_STATE_A_WAIT_VRISE
,
55 OTG_STATE_A_WAIT_BCON
,
58 OTG_STATE_A_PERIPHERAL
,
59 OTG_STATE_A_WAIT_VFALL
,
66 /* for phys connected thru an ULPI interface, the user must
69 struct usb_phy_io_ops
{
70 int (*read
)(struct usb_phy
*x
, u32 reg
);
71 int (*write
)(struct usb_phy
*x
, u32 val
, u32 reg
);
79 enum usb_phy_type type
;
80 enum usb_phy_events last_event
;
84 struct device
*io_dev
;
85 struct usb_phy_io_ops
*io_ops
;
86 void __iomem
*io_priv
;
88 /* for notification of usb_phy_events */
89 struct atomic_notifier_head notifier
;
91 /* to pass extra port status to the root hub */
95 /* to support controllers that have multiple phys */
96 struct list_head head
;
98 /* initialize/shutdown the phy */
99 int (*init
)(struct usb_phy
*x
);
100 void (*shutdown
)(struct usb_phy
*x
);
102 /* enable/disable VBUS */
103 int (*set_vbus
)(struct usb_phy
*x
, int on
);
105 /* effective for B devices, ignored for A-peripheral */
106 int (*set_power
)(struct usb_phy
*x
,
109 /* Set phy into suspend mode */
110 int (*set_suspend
)(struct usb_phy
*x
,
114 * Set wakeup enable for PHY, in that case, the PHY can be
115 * woken up from suspend status due to external events,
116 * like vbus change, dp/dm change and id.
118 int (*set_wakeup
)(struct usb_phy
*x
, bool enabled
);
120 /* notify phy connect status change */
121 int (*notify_connect
)(struct usb_phy
*x
,
122 enum usb_device_speed speed
);
123 int (*notify_disconnect
)(struct usb_phy
*x
,
124 enum usb_device_speed speed
);
128 * struct usb_phy_bind - represent the binding for the phy
129 * @dev_name: the device name of the device that will bind to the phy
130 * @phy_dev_name: the device name of the phy
131 * @index: used if a single controller uses multiple phys
132 * @phy: reference to the phy
133 * @list: to maintain a linked list of the binding information
135 struct usb_phy_bind
{
136 const char *dev_name
;
137 const char *phy_dev_name
;
140 struct list_head list
;
143 /* for board-specific init logic */
144 extern int usb_add_phy(struct usb_phy
*, enum usb_phy_type type
);
145 extern int usb_add_phy_dev(struct usb_phy
*);
146 extern void usb_remove_phy(struct usb_phy
*);
148 /* helpers for direct access thru low-level io interface */
149 static inline int usb_phy_io_read(struct usb_phy
*x
, u32 reg
)
151 if (x
&& x
->io_ops
&& x
->io_ops
->read
)
152 return x
->io_ops
->read(x
, reg
);
157 static inline int usb_phy_io_write(struct usb_phy
*x
, u32 val
, u32 reg
)
159 if (x
&& x
->io_ops
&& x
->io_ops
->write
)
160 return x
->io_ops
->write(x
, val
, reg
);
166 usb_phy_init(struct usb_phy
*x
)
175 usb_phy_shutdown(struct usb_phy
*x
)
177 if (x
&& x
->shutdown
)
182 usb_phy_vbus_on(struct usb_phy
*x
)
184 if (!x
|| !x
->set_vbus
)
187 return x
->set_vbus(x
, true);
191 usb_phy_vbus_off(struct usb_phy
*x
)
193 if (!x
|| !x
->set_vbus
)
196 return x
->set_vbus(x
, false);
199 /* for usb host and peripheral controller drivers */
200 #if IS_ENABLED(CONFIG_USB_PHY)
201 extern struct usb_phy
*usb_get_phy(enum usb_phy_type type
);
202 extern struct usb_phy
*devm_usb_get_phy(struct device
*dev
,
203 enum usb_phy_type type
);
204 extern struct usb_phy
*usb_get_phy_dev(struct device
*dev
, u8 index
);
205 extern struct usb_phy
*devm_usb_get_phy_dev(struct device
*dev
, u8 index
);
206 extern struct usb_phy
*devm_usb_get_phy_by_phandle(struct device
*dev
,
207 const char *phandle
, u8 index
);
208 extern struct usb_phy
*devm_usb_get_phy_by_node(struct device
*dev
,
209 struct device_node
*node
, struct notifier_block
*nb
);
210 extern void usb_put_phy(struct usb_phy
*);
211 extern void devm_usb_put_phy(struct device
*dev
, struct usb_phy
*x
);
212 extern int usb_bind_phy(const char *dev_name
, u8 index
,
213 const char *phy_dev_name
);
214 extern void usb_phy_set_event(struct usb_phy
*x
, unsigned long event
);
216 static inline struct usb_phy
*usb_get_phy(enum usb_phy_type type
)
218 return ERR_PTR(-ENXIO
);
221 static inline struct usb_phy
*devm_usb_get_phy(struct device
*dev
,
222 enum usb_phy_type type
)
224 return ERR_PTR(-ENXIO
);
227 static inline struct usb_phy
*usb_get_phy_dev(struct device
*dev
, u8 index
)
229 return ERR_PTR(-ENXIO
);
232 static inline struct usb_phy
*devm_usb_get_phy_dev(struct device
*dev
, u8 index
)
234 return ERR_PTR(-ENXIO
);
237 static inline struct usb_phy
*devm_usb_get_phy_by_phandle(struct device
*dev
,
238 const char *phandle
, u8 index
)
240 return ERR_PTR(-ENXIO
);
243 static inline struct usb_phy
*devm_usb_get_phy_by_node(struct device
*dev
,
244 struct device_node
*node
, struct notifier_block
*nb
)
246 return ERR_PTR(-ENXIO
);
249 static inline void usb_put_phy(struct usb_phy
*x
)
253 static inline void devm_usb_put_phy(struct device
*dev
, struct usb_phy
*x
)
257 static inline int usb_bind_phy(const char *dev_name
, u8 index
,
258 const char *phy_dev_name
)
263 static inline void usb_phy_set_event(struct usb_phy
*x
, unsigned long event
)
269 usb_phy_set_power(struct usb_phy
*x
, unsigned mA
)
271 if (x
&& x
->set_power
)
272 return x
->set_power(x
, mA
);
276 /* Context: can sleep */
278 usb_phy_set_suspend(struct usb_phy
*x
, int suspend
)
280 if (x
&& x
->set_suspend
!= NULL
)
281 return x
->set_suspend(x
, suspend
);
287 usb_phy_set_wakeup(struct usb_phy
*x
, bool enabled
)
289 if (x
&& x
->set_wakeup
)
290 return x
->set_wakeup(x
, enabled
);
296 usb_phy_notify_connect(struct usb_phy
*x
, enum usb_device_speed speed
)
298 if (x
&& x
->notify_connect
)
299 return x
->notify_connect(x
, speed
);
305 usb_phy_notify_disconnect(struct usb_phy
*x
, enum usb_device_speed speed
)
307 if (x
&& x
->notify_disconnect
)
308 return x
->notify_disconnect(x
, speed
);
315 usb_register_notifier(struct usb_phy
*x
, struct notifier_block
*nb
)
317 return atomic_notifier_chain_register(&x
->notifier
, nb
);
321 usb_unregister_notifier(struct usb_phy
*x
, struct notifier_block
*nb
)
323 atomic_notifier_chain_unregister(&x
->notifier
, nb
);
326 static inline const char *usb_phy_type_string(enum usb_phy_type type
)
329 case USB_PHY_TYPE_USB2
:
331 case USB_PHY_TYPE_USB3
:
334 return "UNKNOWN PHY TYPE";
337 #endif /* __LINUX_USB_PHY_H */