1
2
3
4
5
6
7
8
9#ifndef __LINUX_USB_OTG_H
10#define __LINUX_USB_OTG_H
11
12#include <linux/notifier.h>
13
14
15enum usb_otg_state {
16 OTG_STATE_UNDEFINED = 0,
17
18
19 OTG_STATE_B_IDLE,
20 OTG_STATE_B_SRP_INIT,
21 OTG_STATE_B_PERIPHERAL,
22
23
24 OTG_STATE_B_WAIT_ACON,
25 OTG_STATE_B_HOST,
26
27
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
38enum usb_xceiv_events {
39 USB_EVENT_NONE,
40 USB_EVENT_VBUS,
41 USB_EVENT_ID,
42 USB_EVENT_CHARGER,
43 USB_EVENT_ENUMERATED,
44};
45
46struct otg_transceiver;
47
48
49
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
56
57
58
59
60
61
62struct otg_transceiver {
63 struct device *dev;
64 const char *label;
65 unsigned int flags;
66
67 u8 default_a;
68 enum usb_otg_state state;
69 enum usb_xceiv_events last_event;
70
71 struct usb_bus *host;
72 struct usb_gadget *gadget;
73
74 struct otg_io_access_ops *io_ops;
75 void __iomem *io_priv;
76
77
78 struct atomic_notifier_head notifier;
79
80
81 u16 port_status;
82 u16 port_change;
83
84
85 int (*init)(struct otg_transceiver *otg);
86 void (*shutdown)(struct otg_transceiver *otg);
87
88
89 int (*set_host)(struct otg_transceiver *otg,
90 struct usb_bus *host);
91
92
93 int (*set_peripheral)(struct otg_transceiver *otg,
94 struct usb_gadget *gadget);
95
96
97 int (*set_power)(struct otg_transceiver *otg,
98 unsigned mA);
99
100
101 int (*set_vbus)(struct otg_transceiver *otg,
102 bool enabled);
103
104
105 int (*set_suspend)(struct otg_transceiver *otg,
106 int suspend);
107
108
109 int (*start_srp)(struct otg_transceiver *otg);
110
111
112 int (*start_hnp)(struct otg_transceiver *otg);
113
114};
115
116
117
118extern int otg_set_transceiver(struct otg_transceiver *);
119
120#if defined(CONFIG_NOP_USB_XCEIV) || (defined(CONFIG_NOP_USB_XCEIV_MODULE) && defined(MODULE))
121
122extern void usb_nop_xceiv_register(void);
123extern void usb_nop_xceiv_unregister(void);
124#else
125static inline void usb_nop_xceiv_register(void)
126{
127}
128
129static inline void usb_nop_xceiv_unregister(void)
130{
131}
132#endif
133
134
135static inline int otg_io_read(struct otg_transceiver *otg, u32 reg)
136{
137 if (otg->io_ops && otg->io_ops->read)
138 return otg->io_ops->read(otg, reg);
139
140 return -EINVAL;
141}
142
143static inline int otg_io_write(struct otg_transceiver *otg, u32 val, u32 reg)
144{
145 if (otg->io_ops && otg->io_ops->write)
146 return otg->io_ops->write(otg, val, reg);
147
148 return -EINVAL;
149}
150
151static inline int
152otg_init(struct otg_transceiver *otg)
153{
154 if (otg->init)
155 return otg->init(otg);
156
157 return 0;
158}
159
160static inline void
161otg_shutdown(struct otg_transceiver *otg)
162{
163 if (otg->shutdown)
164 otg->shutdown(otg);
165}
166
167
168#ifdef CONFIG_USB_OTG_UTILS
169extern struct otg_transceiver *otg_get_transceiver(void);
170extern void otg_put_transceiver(struct otg_transceiver *);
171extern const char *otg_state_string(enum usb_otg_state state);
172#else
173static inline struct otg_transceiver *otg_get_transceiver(void)
174{
175 return NULL;
176}
177
178static inline void otg_put_transceiver(struct otg_transceiver *x)
179{
180}
181
182static inline const char *otg_state_string(enum usb_otg_state state)
183{
184 return NULL;
185}
186#endif
187
188
189static inline int
190otg_start_hnp(struct otg_transceiver *otg)
191{
192 return otg->start_hnp(otg);
193}
194
195
196static inline int
197otg_set_vbus(struct otg_transceiver *otg, bool enabled)
198{
199 return otg->set_vbus(otg, enabled);
200}
201
202
203static inline int
204otg_set_host(struct otg_transceiver *otg, struct usb_bus *host)
205{
206 return otg->set_host(otg, host);
207}
208
209
210
211
212static inline int
213otg_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *periph)
214{
215 return otg->set_peripheral(otg, periph);
216}
217
218static inline int
219otg_set_power(struct otg_transceiver *otg, unsigned mA)
220{
221 return otg->set_power(otg, mA);
222}
223
224
225static inline int
226otg_set_suspend(struct otg_transceiver *otg, int suspend)
227{
228 if (otg->set_suspend != NULL)
229 return otg->set_suspend(otg, suspend);
230 else
231 return 0;
232}
233
234static inline int
235otg_start_srp(struct otg_transceiver *otg)
236{
237 return otg->start_srp(otg);
238}
239
240
241static inline int
242otg_register_notifier(struct otg_transceiver *otg, struct notifier_block *nb)
243{
244 return atomic_notifier_chain_register(&otg->notifier, nb);
245}
246
247static inline void
248otg_unregister_notifier(struct otg_transceiver *otg, struct notifier_block *nb)
249{
250 atomic_notifier_chain_unregister(&otg->notifier, nb);
251}
252
253
254extern int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num);
255
256#endif
257