aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/usb/otg.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/usb/otg.h')
-rw-r--r--include/linux/usb/otg.h164
1 files changed, 93 insertions, 71 deletions
diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h
index d87f44f5b04e..f67810f8f21b 100644
--- a/include/linux/usb/otg.h
+++ b/include/linux/usb/otg.h
@@ -35,7 +35,7 @@ enum usb_otg_state {
35 OTG_STATE_A_VBUS_ERR, 35 OTG_STATE_A_VBUS_ERR,
36}; 36};
37 37
38enum usb_xceiv_events { 38enum usb_phy_events {
39 USB_EVENT_NONE, /* no events or cable disconnected */ 39 USB_EVENT_NONE, /* no events or cable disconnected */
40 USB_EVENT_VBUS, /* vbus valid event */ 40 USB_EVENT_VBUS, /* vbus valid event */
41 USB_EVENT_ID, /* id was grounded */ 41 USB_EVENT_ID, /* id was grounded */
@@ -43,14 +43,39 @@ enum usb_xceiv_events {
43 USB_EVENT_ENUMERATED, /* gadget driver enumerated */ 43 USB_EVENT_ENUMERATED, /* gadget driver enumerated */
44}; 44};
45 45
46struct otg_transceiver; 46struct usb_phy;
47 47
48/* for transceivers connected thru an ULPI interface, the user must 48/* for transceivers connected thru an ULPI interface, the user must
49 * provide access ops 49 * provide access ops
50 */ 50 */
51struct otg_io_access_ops { 51struct usb_phy_io_ops {
52 int (*read)(struct otg_transceiver *otg, u32 reg); 52 int (*read)(struct usb_phy *x, u32 reg);
53 int (*write)(struct otg_transceiver *otg, u32 val, u32 reg); 53 int (*write)(struct usb_phy *x, u32 val, u32 reg);
54};
55
56struct usb_otg {
57 u8 default_a;
58
59 struct usb_phy *phy;
60 struct usb_bus *host;
61 struct usb_gadget *gadget;
62
63 /* bind/unbind the host controller */
64 int (*set_host)(struct usb_otg *otg, struct usb_bus *host);
65
66 /* bind/unbind the peripheral controller */
67 int (*set_peripheral)(struct usb_otg *otg,
68 struct usb_gadget *gadget);
69
70 /* effective for A-peripheral, ignored for B devices */
71 int (*set_vbus)(struct usb_otg *otg, bool enabled);
72
73 /* for B devices only: start session with A-Host */
74 int (*start_srp)(struct usb_otg *otg);
75
76 /* start or continue HNP role switch */
77 int (*start_hnp)(struct usb_otg *otg);
78
54}; 79};
55 80
56/* 81/*
@@ -59,22 +84,20 @@ struct otg_io_access_ops {
59 * moment, using the transceiver, ID signal, HNP and sometimes static 84 * moment, using the transceiver, ID signal, HNP and sometimes static
60 * configuration information (including "board isn't wired for otg"). 85 * configuration information (including "board isn't wired for otg").
61 */ 86 */
62struct otg_transceiver { 87struct usb_phy {
63 struct device *dev; 88 struct device *dev;
64 const char *label; 89 const char *label;
65 unsigned int flags; 90 unsigned int flags;
66 91
67 u8 default_a;
68 enum usb_otg_state state; 92 enum usb_otg_state state;
69 enum usb_xceiv_events last_event; 93 enum usb_phy_events last_event;
70 94
71 struct usb_bus *host; 95 struct usb_otg *otg;
72 struct usb_gadget *gadget;
73 96
74 struct otg_io_access_ops *io_ops; 97 struct usb_phy_io_ops *io_ops;
75 void __iomem *io_priv; 98 void __iomem *io_priv;
76 99
77 /* for notification of usb_xceiv_events */ 100 /* for notification of usb_phy_events */
78 struct atomic_notifier_head notifier; 101 struct atomic_notifier_head notifier;
79 102
80 /* to pass extra port status to the root hub */ 103 /* to pass extra port status to the root hub */
@@ -82,40 +105,22 @@ struct otg_transceiver {
82 u16 port_change; 105 u16 port_change;
83 106
84 /* initialize/shutdown the OTG controller */ 107 /* initialize/shutdown the OTG controller */
85 int (*init)(struct otg_transceiver *otg); 108 int (*init)(struct usb_phy *x);
86 void (*shutdown)(struct otg_transceiver *otg); 109 void (*shutdown)(struct usb_phy *x);
87
88 /* bind/unbind the host controller */
89 int (*set_host)(struct otg_transceiver *otg,
90 struct usb_bus *host);
91
92 /* bind/unbind the peripheral controller */
93 int (*set_peripheral)(struct otg_transceiver *otg,
94 struct usb_gadget *gadget);
95 110
96 /* effective for B devices, ignored for A-peripheral */ 111 /* effective for B devices, ignored for A-peripheral */
97 int (*set_power)(struct otg_transceiver *otg, 112 int (*set_power)(struct usb_phy *x,
98 unsigned mA); 113 unsigned mA);
99 114
100 /* effective for A-peripheral, ignored for B devices */
101 int (*set_vbus)(struct otg_transceiver *otg,
102 bool enabled);
103
104 /* for non-OTG B devices: set transceiver into suspend mode */ 115 /* for non-OTG B devices: set transceiver into suspend mode */
105 int (*set_suspend)(struct otg_transceiver *otg, 116 int (*set_suspend)(struct usb_phy *x,
106 int suspend); 117 int suspend);
107 118
108 /* for B devices only: start session with A-Host */
109 int (*start_srp)(struct otg_transceiver *otg);
110
111 /* start or continue HNP role switch */
112 int (*start_hnp)(struct otg_transceiver *otg);
113
114}; 119};
115 120
116 121
117/* for board-specific init logic */ 122/* for board-specific init logic */
118extern int otg_set_transceiver(struct otg_transceiver *); 123extern int usb_set_transceiver(struct usb_phy *);
119 124
120#if defined(CONFIG_NOP_USB_XCEIV) || (defined(CONFIG_NOP_USB_XCEIV_MODULE) && defined(MODULE)) 125#if defined(CONFIG_NOP_USB_XCEIV) || (defined(CONFIG_NOP_USB_XCEIV_MODULE) && defined(MODULE))
121/* sometimes transceivers are accessed only through e.g. ULPI */ 126/* sometimes transceivers are accessed only through e.g. ULPI */
@@ -132,50 +137,50 @@ static inline void usb_nop_xceiv_unregister(void)
132#endif 137#endif
133 138
134/* helpers for direct access thru low-level io interface */ 139/* helpers for direct access thru low-level io interface */
135static inline int otg_io_read(struct otg_transceiver *otg, u32 reg) 140static inline int usb_phy_io_read(struct usb_phy *x, u32 reg)
136{ 141{
137 if (otg->io_ops && otg->io_ops->read) 142 if (x->io_ops && x->io_ops->read)
138 return otg->io_ops->read(otg, reg); 143 return x->io_ops->read(x, reg);
139 144
140 return -EINVAL; 145 return -EINVAL;
141} 146}
142 147
143static inline int otg_io_write(struct otg_transceiver *otg, u32 val, u32 reg) 148static inline int usb_phy_io_write(struct usb_phy *x, u32 val, u32 reg)
144{ 149{
145 if (otg->io_ops && otg->io_ops->write) 150 if (x->io_ops && x->io_ops->write)
146 return otg->io_ops->write(otg, val, reg); 151 return x->io_ops->write(x, val, reg);
147 152
148 return -EINVAL; 153 return -EINVAL;
149} 154}
150 155
151static inline int 156static inline int
152otg_init(struct otg_transceiver *otg) 157usb_phy_init(struct usb_phy *x)
153{ 158{
154 if (otg->init) 159 if (x->init)
155 return otg->init(otg); 160 return x->init(x);
156 161
157 return 0; 162 return 0;
158} 163}
159 164
160static inline void 165static inline void
161otg_shutdown(struct otg_transceiver *otg) 166usb_phy_shutdown(struct usb_phy *x)
162{ 167{
163 if (otg->shutdown) 168 if (x->shutdown)
164 otg->shutdown(otg); 169 x->shutdown(x);
165} 170}
166 171
167/* for usb host and peripheral controller drivers */ 172/* for usb host and peripheral controller drivers */
168#ifdef CONFIG_USB_OTG_UTILS 173#ifdef CONFIG_USB_OTG_UTILS
169extern struct otg_transceiver *otg_get_transceiver(void); 174extern struct usb_phy *usb_get_transceiver(void);
170extern void otg_put_transceiver(struct otg_transceiver *); 175extern void usb_put_transceiver(struct usb_phy *);
171extern const char *otg_state_string(enum usb_otg_state state); 176extern const char *otg_state_string(enum usb_otg_state state);
172#else 177#else
173static inline struct otg_transceiver *otg_get_transceiver(void) 178static inline struct usb_phy *usb_get_transceiver(void)
174{ 179{
175 return NULL; 180 return NULL;
176} 181}
177 182
178static inline void otg_put_transceiver(struct otg_transceiver *x) 183static inline void usb_put_transceiver(struct usb_phy *x)
179{ 184{
180} 185}
181 186
@@ -187,67 +192,84 @@ static inline const char *otg_state_string(enum usb_otg_state state)
187 192
188/* Context: can sleep */ 193/* Context: can sleep */
189static inline int 194static inline int
190otg_start_hnp(struct otg_transceiver *otg) 195otg_start_hnp(struct usb_otg *otg)
191{ 196{
192 return otg->start_hnp(otg); 197 if (otg && otg->start_hnp)
198 return otg->start_hnp(otg);
199
200 return -ENOTSUPP;
193} 201}
194 202
195/* Context: can sleep */ 203/* Context: can sleep */
196static inline int 204static inline int
197otg_set_vbus(struct otg_transceiver *otg, bool enabled) 205otg_set_vbus(struct usb_otg *otg, bool enabled)
198{ 206{
199 return otg->set_vbus(otg, enabled); 207 if (otg && otg->set_vbus)
208 return otg->set_vbus(otg, enabled);
209
210 return -ENOTSUPP;
200} 211}
201 212
202/* for HCDs */ 213/* for HCDs */
203static inline int 214static inline int
204otg_set_host(struct otg_transceiver *otg, struct usb_bus *host) 215otg_set_host(struct usb_otg *otg, struct usb_bus *host)
205{ 216{
206 return otg->set_host(otg, host); 217 if (otg && otg->set_host)
218 return otg->set_host(otg, host);
219
220 return -ENOTSUPP;
207} 221}
208 222
209/* for usb peripheral controller drivers */ 223/* for usb peripheral controller drivers */
210 224
211/* Context: can sleep */ 225/* Context: can sleep */
212static inline int 226static inline int
213otg_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *periph) 227otg_set_peripheral(struct usb_otg *otg, struct usb_gadget *periph)
214{ 228{
215 return otg->set_peripheral(otg, periph); 229 if (otg && otg->set_peripheral)
230 return otg->set_peripheral(otg, periph);
231
232 return -ENOTSUPP;
216} 233}
217 234
218static inline int 235static inline int
219otg_set_power(struct otg_transceiver *otg, unsigned mA) 236usb_phy_set_power(struct usb_phy *x, unsigned mA)
220{ 237{
221 return otg->set_power(otg, mA); 238 if (x && x->set_power)
239 return x->set_power(x, mA);
240 return 0;
222} 241}
223 242
224/* Context: can sleep */ 243/* Context: can sleep */
225static inline int 244static inline int
226otg_set_suspend(struct otg_transceiver *otg, int suspend) 245usb_phy_set_suspend(struct usb_phy *x, int suspend)
227{ 246{
228 if (otg->set_suspend != NULL) 247 if (x->set_suspend != NULL)
229 return otg->set_suspend(otg, suspend); 248 return x->set_suspend(x, suspend);
230 else 249 else
231 return 0; 250 return 0;
232} 251}
233 252
234static inline int 253static inline int
235otg_start_srp(struct otg_transceiver *otg) 254otg_start_srp(struct usb_otg *otg)
236{ 255{
237 return otg->start_srp(otg); 256 if (otg && otg->start_srp)
257 return otg->start_srp(otg);
258
259 return -ENOTSUPP;
238} 260}
239 261
240/* notifiers */ 262/* notifiers */
241static inline int 263static inline int
242otg_register_notifier(struct otg_transceiver *otg, struct notifier_block *nb) 264usb_register_notifier(struct usb_phy *x, struct notifier_block *nb)
243{ 265{
244 return atomic_notifier_chain_register(&otg->notifier, nb); 266 return atomic_notifier_chain_register(&x->notifier, nb);
245} 267}
246 268
247static inline void 269static inline void
248otg_unregister_notifier(struct otg_transceiver *otg, struct notifier_block *nb) 270usb_unregister_notifier(struct usb_phy *x, struct notifier_block *nb)
249{ 271{
250 atomic_notifier_chain_unregister(&otg->notifier, nb); 272 atomic_notifier_chain_unregister(&x->notifier, nb);
251} 273}
252 274
253/* for OTG controller drivers (and maybe other stuff) */ 275/* for OTG controller drivers (and maybe other stuff) */