blob: fef0972c814672ec04f8b3d60b269a2d9ad8f46b [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
12/* OTG defines lots of enumeration states before device reset */
13enum usb_otg_state {
14 OTG_STATE_UNDEFINED = 0,
15
16 /* single-role peripheral, and dual-role default-b */
17 OTG_STATE_B_IDLE,
18 OTG_STATE_B_SRP_INIT,
19 OTG_STATE_B_PERIPHERAL,
20
21 /* extra dual-role default-b states */
22 OTG_STATE_B_WAIT_ACON,
23 OTG_STATE_B_HOST,
24
25 /* dual-role default-a */
26 OTG_STATE_A_IDLE,
27 OTG_STATE_A_WAIT_VRISE,
28 OTG_STATE_A_WAIT_BCON,
29 OTG_STATE_A_HOST,
30 OTG_STATE_A_SUSPEND,
31 OTG_STATE_A_PERIPHERAL,
32 OTG_STATE_A_WAIT_VFALL,
33 OTG_STATE_A_VBUS_ERR,
34};
35
Daniel Mack91c8a5a2009-10-15 17:09:34 +030036#define USB_OTG_PULLUP_ID (1 << 0)
37#define USB_OTG_PULLDOWN_DP (1 << 1)
38#define USB_OTG_PULLDOWN_DM (1 << 2)
39#define USB_OTG_EXT_VBUS_INDICATOR (1 << 3)
40#define USB_OTG_DRV_VBUS (1 << 4)
41#define USB_OTG_DRV_VBUS_EXT (1 << 5)
42
43struct otg_transceiver;
44
45/* for transceivers connected thru an ULPI interface, the user must
46 * provide access ops
47 */
48struct otg_io_access_ops {
49 int (*read)(struct otg_transceiver *otg, u32 reg);
50 int (*write)(struct otg_transceiver *otg, u32 val, u32 reg);
51};
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053/*
54 * the otg driver needs to interact with both device side and host side
55 * usb controllers. it decides which controller is active at a given
56 * moment, using the transceiver, ID signal, HNP and sometimes static
57 * configuration information (including "board isn't wired for otg").
58 */
59struct otg_transceiver {
60 struct device *dev;
61 const char *label;
Daniel Mack91c8a5a2009-10-15 17:09:34 +030062 unsigned int flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64 u8 default_a;
65 enum usb_otg_state state;
66
67 struct usb_bus *host;
68 struct usb_gadget *gadget;
69
Daniel Mack91c8a5a2009-10-15 17:09:34 +030070 struct otg_io_access_ops *io_ops;
71 void __iomem *io_priv;
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 /* to pass extra port status to the root hub */
74 u16 port_status;
75 u16 port_change;
76
Daniel Mack91c8a5a2009-10-15 17:09:34 +030077 /* initialize/shutdown the OTG controller */
78 int (*init)(struct otg_transceiver *otg);
79 void (*shutdown)(struct otg_transceiver *otg);
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 /* bind/unbind the host controller */
David Brownell3a16f7b2006-06-29 12:27:23 -070082 int (*set_host)(struct otg_transceiver *otg,
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 struct usb_bus *host);
84
85 /* bind/unbind the peripheral controller */
86 int (*set_peripheral)(struct otg_transceiver *otg,
87 struct usb_gadget *gadget);
88
89 /* effective for B devices, ignored for A-peripheral */
90 int (*set_power)(struct otg_transceiver *otg,
91 unsigned mA);
92
Daniel Mack91c8a5a2009-10-15 17:09:34 +030093 /* effective for A-peripheral, ignored for B devices */
94 int (*set_vbus)(struct otg_transceiver *otg,
95 bool enabled);
96
Juha Yrj?l?4e671852005-10-16 15:47:04 -070097 /* for non-OTG B devices: set transceiver into suspend mode */
98 int (*set_suspend)(struct otg_transceiver *otg,
99 int suspend);
100
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 /* for B devices only: start session with A-Host */
102 int (*start_srp)(struct otg_transceiver *otg);
103
104 /* start or continue HNP role switch */
105 int (*start_hnp)(struct otg_transceiver *otg);
106
107};
108
109
110/* for board-specific init logic */
111extern int otg_set_transceiver(struct otg_transceiver *);
David Brownellcc835e32009-03-31 12:28:31 -0700112
Maulik Mankad224e1542010-02-17 14:09:29 -0800113#if defined(CONFIG_NOP_USB_XCEIV) || defined(CONFIG_NOP_USB_XCEIV_MODULE)
David Brownellcc835e32009-03-31 12:28:31 -0700114/* sometimes transceivers are accessed only through e.g. ULPI */
Ajay Kumar Guptaf6d92a02009-02-06 17:32:35 +0530115extern void usb_nop_xceiv_register(void);
116extern void usb_nop_xceiv_unregister(void);
Maulik Mankad224e1542010-02-17 14:09:29 -0800117#else
118static inline void usb_nop_xceiv_register(void)
119{
120}
121
122static inline void usb_nop_xceiv_unregister(void)
123{
124}
125#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
Daniel Mack91c8a5a2009-10-15 17:09:34 +0300127/* helpers for direct access thru low-level io interface */
128static inline int otg_io_read(struct otg_transceiver *otg, u32 reg)
129{
130 if (otg->io_ops && otg->io_ops->read)
131 return otg->io_ops->read(otg, reg);
132
133 return -EINVAL;
134}
135
136static inline int otg_io_write(struct otg_transceiver *otg, u32 reg, u32 val)
137{
138 if (otg->io_ops && otg->io_ops->write)
139 return otg->io_ops->write(otg, reg, val);
140
141 return -EINVAL;
142}
143
144static inline int
145otg_init(struct otg_transceiver *otg)
146{
147 if (otg->init)
148 return otg->init(otg);
149
150 return 0;
151}
152
153static inline void
154otg_shutdown(struct otg_transceiver *otg)
155{
156 if (otg->shutdown)
157 otg->shutdown(otg);
158}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
160/* for usb host and peripheral controller drivers */
161extern struct otg_transceiver *otg_get_transceiver(void);
Philipp Zabel68144e02008-11-24 12:01:17 -0800162extern void otg_put_transceiver(struct otg_transceiver *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
Robert Jarzmikc2344f12009-01-24 23:54:31 -0800164/* Context: can sleep */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165static inline int
166otg_start_hnp(struct otg_transceiver *otg)
167{
168 return otg->start_hnp(otg);
169}
170
Daniel Mack91c8a5a2009-10-15 17:09:34 +0300171/* Context: can sleep */
172static inline int
173otg_set_vbus(struct otg_transceiver *otg, bool enabled)
174{
175 return otg->set_vbus(otg, enabled);
176}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
178/* for HCDs */
179static inline int
180otg_set_host(struct otg_transceiver *otg, struct usb_bus *host)
181{
182 return otg->set_host(otg, host);
183}
184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185/* for usb peripheral controller drivers */
Robert Jarzmikc2344f12009-01-24 23:54:31 -0800186
187/* Context: can sleep */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188static inline int
189otg_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *periph)
190{
191 return otg->set_peripheral(otg, periph);
192}
193
194static inline int
195otg_set_power(struct otg_transceiver *otg, unsigned mA)
196{
197 return otg->set_power(otg, mA);
198}
199
Robert Jarzmikc2344f12009-01-24 23:54:31 -0800200/* Context: can sleep */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201static inline int
Juha Yrj?l?4e671852005-10-16 15:47:04 -0700202otg_set_suspend(struct otg_transceiver *otg, int suspend)
203{
204 if (otg->set_suspend != NULL)
205 return otg->set_suspend(otg, suspend);
206 else
207 return 0;
208}
209
210static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211otg_start_srp(struct otg_transceiver *otg)
212{
213 return otg->start_srp(otg);
214}
215
216
217/* for OTG controller drivers (and maybe other stuff) */
218extern int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num);
Robert P. J. Daydda43a02008-03-07 13:45:32 -0500219
220#endif /* __LINUX_USB_OTG_H */