blob: a812ed5a169165743c6ada4fdc0102d69fce42a7 [file] [log] [blame]
Venu Byravarasude4217d2012-09-04 14:25:58 +05301/* 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>
Peter Chenac965112012-11-09 09:44:44 +080013#include <linux/usb.h>
Venu Byravarasude4217d2012-09-04 14:25:58 +053014
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
Venu Byravarasua4c3dde2012-09-06 10:42:15 +053030/* 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
Venu Byravarasude4217d2012-09-04 14:25:58 +053054struct 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;
Venu Byravarasua4c3dde2012-09-06 10:42:15 +053071 enum usb_otg_state state;
Venu Byravarasude4217d2012-09-04 14:25:58 +053072 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
94 /* effective for B devices, ignored for A-peripheral */
95 int (*set_power)(struct usb_phy *x,
96 unsigned mA);
97
98 /* for non-OTG B devices: set transceiver into suspend mode */
99 int (*set_suspend)(struct usb_phy *x,
100 int suspend);
101
102 /* notify phy connect status change */
Peter Chenac965112012-11-09 09:44:44 +0800103 int (*notify_connect)(struct usb_phy *x,
104 enum usb_device_speed speed);
105 int (*notify_disconnect)(struct usb_phy *x,
106 enum usb_device_speed speed);
Venu Byravarasude4217d2012-09-04 14:25:58 +0530107};
108
Kishon Vijay Abraham Ib4a83e42013-01-25 08:03:21 +0530109/**
110 * struct usb_phy_bind - represent the binding for the phy
111 * @dev_name: the device name of the device that will bind to the phy
112 * @phy_dev_name: the device name of the phy
113 * @index: used if a single controller uses multiple phys
114 * @phy: reference to the phy
115 * @list: to maintain a linked list of the binding information
116 */
117struct usb_phy_bind {
118 const char *dev_name;
119 const char *phy_dev_name;
120 u8 index;
121 struct usb_phy *phy;
122 struct list_head list;
123};
Venu Byravarasude4217d2012-09-04 14:25:58 +0530124
125/* for board-specific init logic */
126extern int usb_add_phy(struct usb_phy *, enum usb_phy_type type);
127extern void usb_remove_phy(struct usb_phy *);
128
129/* helpers for direct access thru low-level io interface */
130static inline int usb_phy_io_read(struct usb_phy *x, u32 reg)
131{
132 if (x->io_ops && x->io_ops->read)
133 return x->io_ops->read(x, reg);
134
135 return -EINVAL;
136}
137
138static inline int usb_phy_io_write(struct usb_phy *x, u32 val, u32 reg)
139{
140 if (x->io_ops && x->io_ops->write)
141 return x->io_ops->write(x, val, reg);
142
143 return -EINVAL;
144}
145
146static inline int
147usb_phy_init(struct usb_phy *x)
148{
149 if (x->init)
150 return x->init(x);
151
152 return 0;
153}
154
155static inline void
156usb_phy_shutdown(struct usb_phy *x)
157{
158 if (x->shutdown)
159 x->shutdown(x);
160}
161
162/* for usb host and peripheral controller drivers */
163#ifdef CONFIG_USB_OTG_UTILS
164extern struct usb_phy *usb_get_phy(enum usb_phy_type type);
165extern struct usb_phy *devm_usb_get_phy(struct device *dev,
166 enum usb_phy_type type);
167extern void usb_put_phy(struct usb_phy *);
168extern void devm_usb_put_phy(struct device *dev, struct usb_phy *x);
Kishon Vijay Abraham Ib4a83e42013-01-25 08:03:21 +0530169extern int usb_bind_phy(const char *dev_name, u8 index,
170 const char *phy_dev_name);
Venu Byravarasude4217d2012-09-04 14:25:58 +0530171#else
172static inline struct usb_phy *usb_get_phy(enum usb_phy_type type)
173{
174 return NULL;
175}
176
177static inline struct usb_phy *devm_usb_get_phy(struct device *dev,
178 enum usb_phy_type type)
179{
180 return NULL;
181}
182
183static inline void usb_put_phy(struct usb_phy *x)
184{
185}
186
187static inline void devm_usb_put_phy(struct device *dev, struct usb_phy *x)
188{
189}
190
Kishon Vijay Abraham Ib4a83e42013-01-25 08:03:21 +0530191static inline int usb_bind_phy(const char *dev_name, u8 index,
192 const char *phy_dev_name)
193{
194 return -EOPNOTSUPP;
195}
Venu Byravarasude4217d2012-09-04 14:25:58 +0530196#endif
197
198static inline int
199usb_phy_set_power(struct usb_phy *x, unsigned mA)
200{
201 if (x && x->set_power)
202 return x->set_power(x, mA);
203 return 0;
204}
205
206/* Context: can sleep */
207static inline int
208usb_phy_set_suspend(struct usb_phy *x, int suspend)
209{
210 if (x->set_suspend != NULL)
211 return x->set_suspend(x, suspend);
212 else
213 return 0;
214}
215
216static inline int
Peter Chenac965112012-11-09 09:44:44 +0800217usb_phy_notify_connect(struct usb_phy *x, enum usb_device_speed speed)
Venu Byravarasude4217d2012-09-04 14:25:58 +0530218{
219 if (x->notify_connect)
Peter Chenac965112012-11-09 09:44:44 +0800220 return x->notify_connect(x, speed);
Venu Byravarasude4217d2012-09-04 14:25:58 +0530221 else
222 return 0;
223}
224
225static inline int
Peter Chenac965112012-11-09 09:44:44 +0800226usb_phy_notify_disconnect(struct usb_phy *x, enum usb_device_speed speed)
Venu Byravarasude4217d2012-09-04 14:25:58 +0530227{
228 if (x->notify_disconnect)
Peter Chenac965112012-11-09 09:44:44 +0800229 return x->notify_disconnect(x, speed);
Venu Byravarasude4217d2012-09-04 14:25:58 +0530230 else
231 return 0;
232}
233
234/* notifiers */
235static inline int
236usb_register_notifier(struct usb_phy *x, struct notifier_block *nb)
237{
238 return atomic_notifier_chain_register(&x->notifier, nb);
239}
240
241static inline void
242usb_unregister_notifier(struct usb_phy *x, struct notifier_block *nb)
243{
244 atomic_notifier_chain_unregister(&x->notifier, nb);
245}
246
247static inline const char *usb_phy_type_string(enum usb_phy_type type)
248{
249 switch (type) {
250 case USB_PHY_TYPE_USB2:
251 return "USB2 PHY";
252 case USB_PHY_TYPE_USB3:
253 return "USB3 PHY";
254 default:
255 return "UNKNOWN PHY TYPE";
256 }
257}
258#endif /* __LINUX_USB_PHY_H */