blob: 88fc16062e77085c25f019d5dc20f5af9ea67f2f [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>
13
14enum usb_phy_events {
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 */
20};
21
22/* associate a type with PHY */
23enum usb_phy_type {
24 USB_PHY_TYPE_UNDEFINED,
25 USB_PHY_TYPE_USB2,
26 USB_PHY_TYPE_USB3,
27};
28
29struct usb_phy;
30struct usb_otg;
31
32/* for transceivers connected thru an ULPI interface, the user must
33 * provide access ops
34 */
35struct usb_phy_io_ops {
36 int (*read)(struct usb_phy *x, u32 reg);
37 int (*write)(struct usb_phy *x, u32 val, u32 reg);
38};
39
40struct usb_phy {
41 struct device *dev;
42 const char *label;
43 unsigned int flags;
44
45 enum usb_phy_type type;
46 enum usb_phy_events last_event;
47
48 struct usb_otg *otg;
49
50 struct device *io_dev;
51 struct usb_phy_io_ops *io_ops;
52 void __iomem *io_priv;
53
54 /* for notification of usb_phy_events */
55 struct atomic_notifier_head notifier;
56
57 /* to pass extra port status to the root hub */
58 u16 port_status;
59 u16 port_change;
60
61 /* to support controllers that have multiple transceivers */
62 struct list_head head;
63
64 /* initialize/shutdown the OTG controller */
65 int (*init)(struct usb_phy *x);
66 void (*shutdown)(struct usb_phy *x);
67
68 /* effective for B devices, ignored for A-peripheral */
69 int (*set_power)(struct usb_phy *x,
70 unsigned mA);
71
72 /* for non-OTG B devices: set transceiver into suspend mode */
73 int (*set_suspend)(struct usb_phy *x,
74 int suspend);
75
76 /* notify phy connect status change */
77 int (*notify_connect)(struct usb_phy *x, int port);
78 int (*notify_disconnect)(struct usb_phy *x, int port);
79};
80
81
82/* for board-specific init logic */
83extern int usb_add_phy(struct usb_phy *, enum usb_phy_type type);
84extern void usb_remove_phy(struct usb_phy *);
85
86/* helpers for direct access thru low-level io interface */
87static inline int usb_phy_io_read(struct usb_phy *x, u32 reg)
88{
89 if (x->io_ops && x->io_ops->read)
90 return x->io_ops->read(x, reg);
91
92 return -EINVAL;
93}
94
95static inline int usb_phy_io_write(struct usb_phy *x, u32 val, u32 reg)
96{
97 if (x->io_ops && x->io_ops->write)
98 return x->io_ops->write(x, val, reg);
99
100 return -EINVAL;
101}
102
103static inline int
104usb_phy_init(struct usb_phy *x)
105{
106 if (x->init)
107 return x->init(x);
108
109 return 0;
110}
111
112static inline void
113usb_phy_shutdown(struct usb_phy *x)
114{
115 if (x->shutdown)
116 x->shutdown(x);
117}
118
119/* for usb host and peripheral controller drivers */
120#ifdef CONFIG_USB_OTG_UTILS
121extern struct usb_phy *usb_get_phy(enum usb_phy_type type);
122extern struct usb_phy *devm_usb_get_phy(struct device *dev,
123 enum usb_phy_type type);
124extern void usb_put_phy(struct usb_phy *);
125extern void devm_usb_put_phy(struct device *dev, struct usb_phy *x);
126#else
127static inline struct usb_phy *usb_get_phy(enum usb_phy_type type)
128{
129 return NULL;
130}
131
132static inline struct usb_phy *devm_usb_get_phy(struct device *dev,
133 enum usb_phy_type type)
134{
135 return NULL;
136}
137
138static inline void usb_put_phy(struct usb_phy *x)
139{
140}
141
142static inline void devm_usb_put_phy(struct device *dev, struct usb_phy *x)
143{
144}
145
146#endif
147
148static inline int
149usb_phy_set_power(struct usb_phy *x, unsigned mA)
150{
151 if (x && x->set_power)
152 return x->set_power(x, mA);
153 return 0;
154}
155
156/* Context: can sleep */
157static inline int
158usb_phy_set_suspend(struct usb_phy *x, int suspend)
159{
160 if (x->set_suspend != NULL)
161 return x->set_suspend(x, suspend);
162 else
163 return 0;
164}
165
166static inline int
167usb_phy_notify_connect(struct usb_phy *x, int port)
168{
169 if (x->notify_connect)
170 return x->notify_connect(x, port);
171 else
172 return 0;
173}
174
175static inline int
176usb_phy_notify_disconnect(struct usb_phy *x, int port)
177{
178 if (x->notify_disconnect)
179 return x->notify_disconnect(x, port);
180 else
181 return 0;
182}
183
184/* notifiers */
185static inline int
186usb_register_notifier(struct usb_phy *x, struct notifier_block *nb)
187{
188 return atomic_notifier_chain_register(&x->notifier, nb);
189}
190
191static inline void
192usb_unregister_notifier(struct usb_phy *x, struct notifier_block *nb)
193{
194 atomic_notifier_chain_unregister(&x->notifier, nb);
195}
196
197static inline const char *usb_phy_type_string(enum usb_phy_type type)
198{
199 switch (type) {
200 case USB_PHY_TYPE_USB2:
201 return "USB2 PHY";
202 case USB_PHY_TYPE_USB3:
203 return "USB3 PHY";
204 default:
205 return "UNKNOWN PHY TYPE";
206 }
207}
208#endif /* __LINUX_USB_PHY_H */