blob: a1a1e7a73ec9bb443f2bafc3ce043d43267ff634 [file] [log] [blame]
Greg Kroah-Hartman41dceed2008-01-30 15:21:33 -08001/* USB OTG (On The Go) defines */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Robert P. J. Daydda43a02008-03-07 13:45:32 -05003 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * 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
Robert P. J. Daydda43a02008-03-07 13:45:32 -05009#ifndef __LINUX_USB_OTG_H
10#define __LINUX_USB_OTG_H
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Felipe Balbie9a20172009-12-17 13:01:36 +020012#include <linux/notifier.h>
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014/* OTG defines lots of enumeration states before device reset */
15enum usb_otg_state {
16 OTG_STATE_UNDEFINED = 0,
17
18 /* single-role peripheral, and dual-role default-b */
19 OTG_STATE_B_IDLE,
20 OTG_STATE_B_SRP_INIT,
21 OTG_STATE_B_PERIPHERAL,
22
23 /* extra dual-role default-b states */
24 OTG_STATE_B_WAIT_ACON,
25 OTG_STATE_B_HOST,
26
27 /* dual-role default-a */
28 OTG_STATE_A_IDLE,
29 OTG_STATE_A_WAIT_VRISE,
30 OTG_STATE_A_WAIT_BCON,
31 OTG_STATE_A_HOST,
32 OTG_STATE_A_SUSPEND,
33 OTG_STATE_A_PERIPHERAL,
34 OTG_STATE_A_WAIT_VFALL,
35 OTG_STATE_A_VBUS_ERR,
36};
37
Felipe Balbie9a20172009-12-17 13:01:36 +020038enum usb_xceiv_events {
39 USB_EVENT_NONE, /* no events or cable disconnected */
40 USB_EVENT_VBUS, /* vbus valid event */
41 USB_EVENT_ID, /* id was grounded */
42 USB_EVENT_CHARGER, /* usb dedicated charger */
43 USB_EVENT_ENUMERATED, /* gadget driver enumerated */
44};
45
Daniel Mack91c8a5a2009-10-15 17:09:34 +030046struct otg_transceiver;
47
48/* for transceivers connected thru an ULPI interface, the user must
49 * provide access ops
50 */
51struct otg_io_access_ops {
52 int (*read)(struct otg_transceiver *otg, u32 reg);
53 int (*write)(struct otg_transceiver *otg, u32 val, u32 reg);
54};
55
Linus Torvalds1da177e2005-04-16 15:20:36 -070056/*
57 * the otg driver needs to interact with both device side and host side
58 * usb controllers. it decides which controller is active at a given
59 * moment, using the transceiver, ID signal, HNP and sometimes static
60 * configuration information (including "board isn't wired for otg").
61 */
62struct otg_transceiver {
63 struct device *dev;
64 const char *label;
Daniel Mack91c8a5a2009-10-15 17:09:34 +030065 unsigned int flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67 u8 default_a;
68 enum usb_otg_state state;
69
70 struct usb_bus *host;
71 struct usb_gadget *gadget;
72
Daniel Mack91c8a5a2009-10-15 17:09:34 +030073 struct otg_io_access_ops *io_ops;
74 void __iomem *io_priv;
75
Felipe Balbie9a20172009-12-17 13:01:36 +020076 /* for notification of usb_xceiv_events */
77 struct blocking_notifier_head notifier;
78
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 /* to pass extra port status to the root hub */
80 u16 port_status;
81 u16 port_change;
82
Daniel Mack91c8a5a2009-10-15 17:09:34 +030083 /* initialize/shutdown the OTG controller */
84 int (*init)(struct otg_transceiver *otg);
85 void (*shutdown)(struct otg_transceiver *otg);
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 /* bind/unbind the host controller */
David Brownell3a16f7b2006-06-29 12:27:23 -070088 int (*set_host)(struct otg_transceiver *otg,
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 struct usb_bus *host);
90
91 /* bind/unbind the peripheral controller */
92 int (*set_peripheral)(struct otg_transceiver *otg,
93 struct usb_gadget *gadget);
94
95 /* effective for B devices, ignored for A-peripheral */
96 int (*set_power)(struct otg_transceiver *otg,
97 unsigned mA);
98
Daniel Mack91c8a5a2009-10-15 17:09:34 +030099 /* effective for A-peripheral, ignored for B devices */
100 int (*set_vbus)(struct otg_transceiver *otg,
101 bool enabled);
102
Juha Yrj?l?4e671852005-10-16 15:47:04 -0700103 /* for non-OTG B devices: set transceiver into suspend mode */
104 int (*set_suspend)(struct otg_transceiver *otg,
105 int suspend);
106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 /* for B devices only: start session with A-Host */
108 int (*start_srp)(struct otg_transceiver *otg);
109
110 /* start or continue HNP role switch */
111 int (*start_hnp)(struct otg_transceiver *otg);
112
113};
114
115
116/* for board-specific init logic */
117extern int otg_set_transceiver(struct otg_transceiver *);
David Brownellcc835e32009-03-31 12:28:31 -0700118
Guennadi Liakhovetski352a3372010-12-09 22:46:29 +0100119#if defined(CONFIG_NOP_USB_XCEIV) || (defined(CONFIG_NOP_USB_XCEIV_MODULE) && defined(MODULE))
David Brownellcc835e32009-03-31 12:28:31 -0700120/* sometimes transceivers are accessed only through e.g. ULPI */
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +0530121extern void usb_nop_xceiv_register(void);
122extern void usb_nop_xceiv_unregister(void);
Maulik Mankad224e1542010-02-17 14:09:29 -0800123#else
124static inline void usb_nop_xceiv_register(void)
125{
126}
127
128static inline void usb_nop_xceiv_unregister(void)
129{
130}
131#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
Daniel Mack91c8a5a2009-10-15 17:09:34 +0300133/* helpers for direct access thru low-level io interface */
134static inline int otg_io_read(struct otg_transceiver *otg, u32 reg)
135{
136 if (otg->io_ops && otg->io_ops->read)
137 return otg->io_ops->read(otg, reg);
138
139 return -EINVAL;
140}
141
Igor Grinberg6e1c3b42010-05-27 09:32:13 +0300142static inline int otg_io_write(struct otg_transceiver *otg, u32 val, u32 reg)
Daniel Mack91c8a5a2009-10-15 17:09:34 +0300143{
144 if (otg->io_ops && otg->io_ops->write)
Igor Grinberg6e1c3b42010-05-27 09:32:13 +0300145 return otg->io_ops->write(otg, val, reg);
Daniel Mack91c8a5a2009-10-15 17:09:34 +0300146
147 return -EINVAL;
148}
149
150static inline int
151otg_init(struct otg_transceiver *otg)
152{
153 if (otg->init)
154 return otg->init(otg);
155
156 return 0;
157}
158
159static inline void
160otg_shutdown(struct otg_transceiver *otg)
161{
162 if (otg->shutdown)
163 otg->shutdown(otg);
164}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
166/* for usb host and peripheral controller drivers */
Grazvydas Ignotas748eee02010-09-27 15:17:18 +0300167#ifdef CONFIG_USB_OTG_UTILS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168extern struct otg_transceiver *otg_get_transceiver(void);
Philipp Zabel68144e02008-11-24 12:01:17 -0800169extern void otg_put_transceiver(struct otg_transceiver *);
Grazvydas Ignotas748eee02010-09-27 15:17:18 +0300170#else
171static inline struct otg_transceiver *otg_get_transceiver(void)
172{
173 return NULL;
174}
175
176static inline void otg_put_transceiver(struct otg_transceiver *x)
177{
178}
179#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
Robert Jarzmikc2344f12009-01-24 23:54:31 -0800181/* Context: can sleep */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182static inline int
183otg_start_hnp(struct otg_transceiver *otg)
184{
185 return otg->start_hnp(otg);
186}
187
Daniel Mack91c8a5a2009-10-15 17:09:34 +0300188/* Context: can sleep */
189static inline int
190otg_set_vbus(struct otg_transceiver *otg, bool enabled)
191{
192 return otg->set_vbus(otg, enabled);
193}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
195/* for HCDs */
196static inline int
197otg_set_host(struct otg_transceiver *otg, struct usb_bus *host)
198{
199 return otg->set_host(otg, host);
200}
201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202/* for usb peripheral controller drivers */
Robert Jarzmikc2344f12009-01-24 23:54:31 -0800203
204/* Context: can sleep */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205static inline int
206otg_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *periph)
207{
208 return otg->set_peripheral(otg, periph);
209}
210
211static inline int
212otg_set_power(struct otg_transceiver *otg, unsigned mA)
213{
214 return otg->set_power(otg, mA);
215}
216
Robert Jarzmikc2344f12009-01-24 23:54:31 -0800217/* Context: can sleep */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218static inline int
Juha Yrj?l?4e671852005-10-16 15:47:04 -0700219otg_set_suspend(struct otg_transceiver *otg, int suspend)
220{
221 if (otg->set_suspend != NULL)
222 return otg->set_suspend(otg, suspend);
223 else
224 return 0;
225}
226
227static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228otg_start_srp(struct otg_transceiver *otg)
229{
230 return otg->start_srp(otg);
231}
232
Felipe Balbie9a20172009-12-17 13:01:36 +0200233/* notifiers */
234static inline int
235otg_register_notifier(struct otg_transceiver *otg, struct notifier_block *nb)
236{
237 return blocking_notifier_chain_register(&otg->notifier, nb);
238}
239
240static inline void
241otg_unregister_notifier(struct otg_transceiver *otg, struct notifier_block *nb)
242{
243 blocking_notifier_chain_unregister(&otg->notifier, nb);
244}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
246/* for OTG controller drivers (and maybe other stuff) */
247extern int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num);
Robert P. J. Daydda43a02008-03-07 13:45:32 -0500248
249#endif /* __LINUX_USB_OTG_H */