usb: musb: omap: add usb_phy_init in omap2430_musb_init
[deliverable/linux.git] / include / linux / usb / phy.h
CommitLineData
de4217d9
VB
1/* USB OTG (On The Go) defines */
2/*
3 *
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.
7 */
8
9#ifndef __LINUX_USB_PHY_H
10#define __LINUX_USB_PHY_H
11
12#include <linux/notifier.h>
ac96511b 13#include <linux/usb.h>
de4217d9
VB
14
15enum usb_phy_events {
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 */
21};
22
23/* associate a type with PHY */
24enum usb_phy_type {
25 USB_PHY_TYPE_UNDEFINED,
26 USB_PHY_TYPE_USB2,
27 USB_PHY_TYPE_USB3,
28};
29
a4c3ddec
VB
30/* OTG defines lots of enumeration states before device reset */
31enum usb_otg_state {
32 OTG_STATE_UNDEFINED = 0,
33
34 /* single-role peripheral, and dual-role default-b */
35 OTG_STATE_B_IDLE,
36 OTG_STATE_B_SRP_INIT,
37 OTG_STATE_B_PERIPHERAL,
38
39 /* extra dual-role default-b states */
40 OTG_STATE_B_WAIT_ACON,
41 OTG_STATE_B_HOST,
42
43 /* dual-role default-a */
44 OTG_STATE_A_IDLE,
45 OTG_STATE_A_WAIT_VRISE,
46 OTG_STATE_A_WAIT_BCON,
47 OTG_STATE_A_HOST,
48 OTG_STATE_A_SUSPEND,
49 OTG_STATE_A_PERIPHERAL,
50 OTG_STATE_A_WAIT_VFALL,
51 OTG_STATE_A_VBUS_ERR,
52};
53
de4217d9
VB
54struct usb_phy;
55struct usb_otg;
56
57/* for transceivers connected thru an ULPI interface, the user must
58 * provide access ops
59 */
60struct usb_phy_io_ops {
61 int (*read)(struct usb_phy *x, u32 reg);
62 int (*write)(struct usb_phy *x, u32 val, u32 reg);
63};
64
65struct usb_phy {
66 struct device *dev;
67 const char *label;
68 unsigned int flags;
69
70 enum usb_phy_type type;
a4c3ddec 71 enum usb_otg_state state;
de4217d9
VB
72 enum usb_phy_events last_event;
73
74 struct usb_otg *otg;
75
76 struct device *io_dev;
77 struct usb_phy_io_ops *io_ops;
78 void __iomem *io_priv;
79
80 /* for notification of usb_phy_events */
81 struct atomic_notifier_head notifier;
82
83 /* to pass extra port status to the root hub */
84 u16 port_status;
85 u16 port_change;
86
87 /* to support controllers that have multiple transceivers */
88 struct list_head head;
89
90 /* initialize/shutdown the OTG controller */
91 int (*init)(struct usb_phy *x);
92 void (*shutdown)(struct usb_phy *x);
93
b774212e
FB
94 /* enable/disable VBUS */
95 int (*set_vbus)(struct usb_phy *x, int on);
96
de4217d9
VB
97 /* effective for B devices, ignored for A-peripheral */
98 int (*set_power)(struct usb_phy *x,
99 unsigned mA);
100
101 /* for non-OTG B devices: set transceiver into suspend mode */
102 int (*set_suspend)(struct usb_phy *x,
103 int suspend);
104
105 /* notify phy connect status change */
ac96511b
PC
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);
de4217d9
VB
110};
111
b4a83e4d
KVA
112/**
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
119 */
120struct usb_phy_bind {
121 const char *dev_name;
122 const char *phy_dev_name;
123 u8 index;
124 struct usb_phy *phy;
125 struct list_head list;
126};
de4217d9
VB
127
128/* for board-specific init logic */
129extern int usb_add_phy(struct usb_phy *, enum usb_phy_type type);
0fa4fab4 130extern int usb_add_phy_dev(struct usb_phy *);
de4217d9
VB
131extern void usb_remove_phy(struct usb_phy *);
132
133/* helpers for direct access thru low-level io interface */
134static inline int usb_phy_io_read(struct usb_phy *x, u32 reg)
135{
136 if (x->io_ops && x->io_ops->read)
137 return x->io_ops->read(x, reg);
138
139 return -EINVAL;
140}
141
142static inline int usb_phy_io_write(struct usb_phy *x, u32 val, u32 reg)
143{
144 if (x->io_ops && x->io_ops->write)
145 return x->io_ops->write(x, val, reg);
146
147 return -EINVAL;
148}
149
150static inline int
151usb_phy_init(struct usb_phy *x)
152{
153 if (x->init)
154 return x->init(x);
155
156 return 0;
157}
158
159static inline void
160usb_phy_shutdown(struct usb_phy *x)
161{
162 if (x->shutdown)
163 x->shutdown(x);
164}
165
b774212e
FB
166static inline int
167usb_phy_vbus_on(struct usb_phy *x)
168{
169 if (!x->set_vbus)
170 return 0;
171
172 return x->set_vbus(x, true);
173}
174
175static inline int
176usb_phy_vbus_off(struct usb_phy *x)
177{
178 if (!x->set_vbus)
179 return 0;
180
181 return x->set_vbus(x, false);
182}
183
de4217d9 184/* for usb host and peripheral controller drivers */
edc7cb2e 185#if IS_ENABLED(CONFIG_USB_PHY)
de4217d9
VB
186extern struct usb_phy *usb_get_phy(enum usb_phy_type type);
187extern struct usb_phy *devm_usb_get_phy(struct device *dev,
188 enum usb_phy_type type);
0fa4fab4
KVA
189extern struct usb_phy *usb_get_phy_dev(struct device *dev, u8 index);
190extern struct usb_phy *devm_usb_get_phy_dev(struct device *dev, u8 index);
5d3c28b5
KVA
191extern struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
192 const char *phandle, u8 index);
de4217d9
VB
193extern void usb_put_phy(struct usb_phy *);
194extern void devm_usb_put_phy(struct device *dev, struct usb_phy *x);
b4a83e4d
KVA
195extern int usb_bind_phy(const char *dev_name, u8 index,
196 const char *phy_dev_name);
de4217d9
VB
197#else
198static inline struct usb_phy *usb_get_phy(enum usb_phy_type type)
199{
200 return NULL;
201}
202
203static inline struct usb_phy *devm_usb_get_phy(struct device *dev,
204 enum usb_phy_type type)
205{
206 return NULL;
207}
208
0fa4fab4
KVA
209static inline struct usb_phy *usb_get_phy_dev(struct device *dev, u8 index)
210{
211 return NULL;
212}
213
214static inline struct usb_phy *devm_usb_get_phy_dev(struct device *dev, u8 index)
215{
216 return NULL;
217}
218
5d3c28b5
KVA
219static inline struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
220 const char *phandle, u8 index)
221{
222 return NULL;
223}
224
de4217d9
VB
225static inline void usb_put_phy(struct usb_phy *x)
226{
227}
228
229static inline void devm_usb_put_phy(struct device *dev, struct usb_phy *x)
230{
231}
232
b4a83e4d
KVA
233static inline int usb_bind_phy(const char *dev_name, u8 index,
234 const char *phy_dev_name)
235{
236 return -EOPNOTSUPP;
237}
de4217d9
VB
238#endif
239
240static inline int
241usb_phy_set_power(struct usb_phy *x, unsigned mA)
242{
243 if (x && x->set_power)
244 return x->set_power(x, mA);
245 return 0;
246}
247
248/* Context: can sleep */
249static inline int
250usb_phy_set_suspend(struct usb_phy *x, int suspend)
251{
252 if (x->set_suspend != NULL)
253 return x->set_suspend(x, suspend);
254 else
255 return 0;
256}
257
258static inline int
ac96511b 259usb_phy_notify_connect(struct usb_phy *x, enum usb_device_speed speed)
de4217d9
VB
260{
261 if (x->notify_connect)
ac96511b 262 return x->notify_connect(x, speed);
de4217d9
VB
263 else
264 return 0;
265}
266
267static inline int
ac96511b 268usb_phy_notify_disconnect(struct usb_phy *x, enum usb_device_speed speed)
de4217d9
VB
269{
270 if (x->notify_disconnect)
ac96511b 271 return x->notify_disconnect(x, speed);
de4217d9
VB
272 else
273 return 0;
274}
275
276/* notifiers */
277static inline int
278usb_register_notifier(struct usb_phy *x, struct notifier_block *nb)
279{
280 return atomic_notifier_chain_register(&x->notifier, nb);
281}
282
283static inline void
284usb_unregister_notifier(struct usb_phy *x, struct notifier_block *nb)
285{
286 atomic_notifier_chain_unregister(&x->notifier, nb);
287}
288
289static inline const char *usb_phy_type_string(enum usb_phy_type type)
290{
291 switch (type) {
292 case USB_PHY_TYPE_USB2:
293 return "USB2 PHY";
294 case USB_PHY_TYPE_USB3:
295 return "USB3 PHY";
296 default:
297 return "UNKNOWN PHY TYPE";
298 }
299}
300#endif /* __LINUX_USB_PHY_H */
This page took 0.089865 seconds and 5 git commands to generate.