diff options
author | Heikki Krogerus <heikki.krogerus@linux.intel.com> | 2012-02-13 06:24:04 -0500 |
---|---|---|
committer | Felipe Balbi <balbi@ti.com> | 2012-02-13 06:35:06 -0500 |
commit | 7a8a3a9bec7432eedcb32b54a3940d0593246060 (patch) | |
tree | 6b1e604271f9f733d5414d1f3e54d53c67a2feaa /include/linux/usb | |
parent | de07e18c00c403d5076a5a697d83fe3ced73bc30 (diff) |
usb: otg: Separate otg members from usb_phy
Introducing struct otg and collecting otg specific members
to it from struct usb_phy. There are no changes to
struct usb_phy at this stage. This also renames
transceiver specific functions, and offers aliases for the
old otg ones.
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Marek Vasut <marek.vasut@gmail.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'include/linux/usb')
-rw-r--r-- | include/linux/usb/otg.h | 96 |
1 files changed, 79 insertions, 17 deletions
diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h index 723a000146f8..5c1cfbc73555 100644 --- a/include/linux/usb/otg.h +++ b/include/linux/usb/otg.h | |||
@@ -48,11 +48,36 @@ struct usb_phy; | |||
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 | */ |
51 | struct otg_io_access_ops { | 51 | struct usb_phy_io_ops { |
52 | int (*read)(struct usb_phy *x, u32 reg); | 52 | int (*read)(struct usb_phy *x, u32 reg); |
53 | int (*write)(struct usb_phy *x, u32 val, u32 reg); | 53 | int (*write)(struct usb_phy *x, u32 val, u32 reg); |
54 | }; | 54 | }; |
55 | 55 | ||
56 | struct 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 | |||
79 | }; | ||
80 | |||
56 | /* | 81 | /* |
57 | * the otg driver needs to interact with both device side and host side | 82 | * 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 | 83 | * usb controllers. it decides which controller is active at a given |
@@ -68,11 +93,13 @@ struct usb_phy { | |||
68 | enum usb_otg_state state; | 93 | enum usb_otg_state state; |
69 | enum usb_phy_events last_event; | 94 | enum usb_phy_events last_event; |
70 | 95 | ||
96 | struct usb_otg *otg; | ||
97 | |||
71 | struct usb_bus *host; | 98 | struct usb_bus *host; |
72 | struct usb_gadget *gadget; | 99 | struct usb_gadget *gadget; |
73 | 100 | ||
74 | struct otg_io_access_ops *io_ops; | 101 | struct usb_phy_io_ops *io_ops; |
75 | void __iomem *io_priv; | 102 | void __iomem *io_priv; |
76 | 103 | ||
77 | /* for notification of usb_phy_events */ | 104 | /* for notification of usb_phy_events */ |
78 | struct atomic_notifier_head notifier; | 105 | struct atomic_notifier_head notifier; |
@@ -115,7 +142,7 @@ struct usb_phy { | |||
115 | 142 | ||
116 | 143 | ||
117 | /* for board-specific init logic */ | 144 | /* for board-specific init logic */ |
118 | extern int otg_set_transceiver(struct usb_phy *); | 145 | extern int usb_set_transceiver(struct usb_phy *); |
119 | 146 | ||
120 | #if defined(CONFIG_NOP_USB_XCEIV) || (defined(CONFIG_NOP_USB_XCEIV_MODULE) && defined(MODULE)) | 147 | #if defined(CONFIG_NOP_USB_XCEIV) || (defined(CONFIG_NOP_USB_XCEIV_MODULE) && defined(MODULE)) |
121 | /* sometimes transceivers are accessed only through e.g. ULPI */ | 148 | /* sometimes transceivers are accessed only through e.g. ULPI */ |
@@ -132,7 +159,7 @@ static inline void usb_nop_xceiv_unregister(void) | |||
132 | #endif | 159 | #endif |
133 | 160 | ||
134 | /* helpers for direct access thru low-level io interface */ | 161 | /* helpers for direct access thru low-level io interface */ |
135 | static inline int otg_io_read(struct usb_phy *x, u32 reg) | 162 | static inline int usb_phy_io_read(struct usb_phy *x, u32 reg) |
136 | { | 163 | { |
137 | if (x->io_ops && x->io_ops->read) | 164 | if (x->io_ops && x->io_ops->read) |
138 | return x->io_ops->read(x, reg); | 165 | return x->io_ops->read(x, reg); |
@@ -140,7 +167,7 @@ static inline int otg_io_read(struct usb_phy *x, u32 reg) | |||
140 | return -EINVAL; | 167 | return -EINVAL; |
141 | } | 168 | } |
142 | 169 | ||
143 | static inline int otg_io_write(struct usb_phy *x, u32 val, u32 reg) | 170 | static inline int usb_phy_io_write(struct usb_phy *x, u32 val, u32 reg) |
144 | { | 171 | { |
145 | if (x->io_ops && x->io_ops->write) | 172 | if (x->io_ops && x->io_ops->write) |
146 | return x->io_ops->write(x, val, reg); | 173 | return x->io_ops->write(x, val, reg); |
@@ -149,7 +176,7 @@ static inline int otg_io_write(struct usb_phy *x, u32 val, u32 reg) | |||
149 | } | 176 | } |
150 | 177 | ||
151 | static inline int | 178 | static inline int |
152 | otg_init(struct usb_phy *x) | 179 | usb_phy_init(struct usb_phy *x) |
153 | { | 180 | { |
154 | if (x->init) | 181 | if (x->init) |
155 | return x->init(x); | 182 | return x->init(x); |
@@ -158,7 +185,7 @@ otg_init(struct usb_phy *x) | |||
158 | } | 185 | } |
159 | 186 | ||
160 | static inline void | 187 | static inline void |
161 | otg_shutdown(struct usb_phy *x) | 188 | usb_phy_shutdown(struct usb_phy *x) |
162 | { | 189 | { |
163 | if (x->shutdown) | 190 | if (x->shutdown) |
164 | x->shutdown(x); | 191 | x->shutdown(x); |
@@ -166,16 +193,16 @@ otg_shutdown(struct usb_phy *x) | |||
166 | 193 | ||
167 | /* for usb host and peripheral controller drivers */ | 194 | /* for usb host and peripheral controller drivers */ |
168 | #ifdef CONFIG_USB_OTG_UTILS | 195 | #ifdef CONFIG_USB_OTG_UTILS |
169 | extern struct usb_phy *otg_get_transceiver(void); | 196 | extern struct usb_phy *usb_get_transceiver(void); |
170 | extern void otg_put_transceiver(struct usb_phy *); | 197 | extern void usb_put_transceiver(struct usb_phy *); |
171 | extern const char *otg_state_string(enum usb_otg_state state); | 198 | extern const char *otg_state_string(enum usb_otg_state state); |
172 | #else | 199 | #else |
173 | static inline struct usb_phy *otg_get_transceiver(void) | 200 | static inline struct usb_phy *usb_get_transceiver(void) |
174 | { | 201 | { |
175 | return NULL; | 202 | return NULL; |
176 | } | 203 | } |
177 | 204 | ||
178 | static inline void otg_put_transceiver(struct usb_phy *x) | 205 | static inline void usb_put_transceiver(struct usb_phy *x) |
179 | { | 206 | { |
180 | } | 207 | } |
181 | 208 | ||
@@ -189,6 +216,9 @@ static inline const char *otg_state_string(enum usb_otg_state state) | |||
189 | static inline int | 216 | static inline int |
190 | otg_start_hnp(struct usb_phy *x) | 217 | otg_start_hnp(struct usb_phy *x) |
191 | { | 218 | { |
219 | if (x->otg && x->otg->start_hnp) | ||
220 | return x->otg->start_hnp(x->otg); | ||
221 | |||
192 | return x->start_hnp(x); | 222 | return x->start_hnp(x); |
193 | } | 223 | } |
194 | 224 | ||
@@ -196,6 +226,9 @@ otg_start_hnp(struct usb_phy *x) | |||
196 | static inline int | 226 | static inline int |
197 | otg_set_vbus(struct usb_phy *x, bool enabled) | 227 | otg_set_vbus(struct usb_phy *x, bool enabled) |
198 | { | 228 | { |
229 | if (x->otg && x->otg->set_vbus) | ||
230 | return x->otg->set_vbus(x->otg, enabled); | ||
231 | |||
199 | return x->set_vbus(x, enabled); | 232 | return x->set_vbus(x, enabled); |
200 | } | 233 | } |
201 | 234 | ||
@@ -203,6 +236,9 @@ otg_set_vbus(struct usb_phy *x, bool enabled) | |||
203 | static inline int | 236 | static inline int |
204 | otg_set_host(struct usb_phy *x, struct usb_bus *host) | 237 | otg_set_host(struct usb_phy *x, struct usb_bus *host) |
205 | { | 238 | { |
239 | if (x->otg && x->otg->set_host) | ||
240 | return x->otg->set_host(x->otg, host); | ||
241 | |||
206 | return x->set_host(x, host); | 242 | return x->set_host(x, host); |
207 | } | 243 | } |
208 | 244 | ||
@@ -212,18 +248,23 @@ otg_set_host(struct usb_phy *x, struct usb_bus *host) | |||
212 | static inline int | 248 | static inline int |
213 | otg_set_peripheral(struct usb_phy *x, struct usb_gadget *periph) | 249 | otg_set_peripheral(struct usb_phy *x, struct usb_gadget *periph) |
214 | { | 250 | { |
251 | if (x->otg && x->otg->set_peripheral) | ||
252 | return x->otg->set_peripheral(x->otg, periph); | ||
253 | |||
215 | return x->set_peripheral(x, periph); | 254 | return x->set_peripheral(x, periph); |
216 | } | 255 | } |
217 | 256 | ||
218 | static inline int | 257 | static inline int |
219 | otg_set_power(struct usb_phy *x, unsigned mA) | 258 | usb_phy_set_power(struct usb_phy *x, unsigned mA) |
220 | { | 259 | { |
221 | return x->set_power(x, mA); | 260 | if (x && x->set_power) |
261 | return x->set_power(x, mA); | ||
262 | return 0; | ||
222 | } | 263 | } |
223 | 264 | ||
224 | /* Context: can sleep */ | 265 | /* Context: can sleep */ |
225 | static inline int | 266 | static inline int |
226 | otg_set_suspend(struct usb_phy *x, int suspend) | 267 | usb_phy_set_suspend(struct usb_phy *x, int suspend) |
227 | { | 268 | { |
228 | if (x->set_suspend != NULL) | 269 | if (x->set_suspend != NULL) |
229 | return x->set_suspend(x, suspend); | 270 | return x->set_suspend(x, suspend); |
@@ -234,18 +275,21 @@ otg_set_suspend(struct usb_phy *x, int suspend) | |||
234 | static inline int | 275 | static inline int |
235 | otg_start_srp(struct usb_phy *x) | 276 | otg_start_srp(struct usb_phy *x) |
236 | { | 277 | { |
278 | if (x->otg && x->otg->start_srp) | ||
279 | return x->otg->start_srp(x->otg); | ||
280 | |||
237 | return x->start_srp(x); | 281 | return x->start_srp(x); |
238 | } | 282 | } |
239 | 283 | ||
240 | /* notifiers */ | 284 | /* notifiers */ |
241 | static inline int | 285 | static inline int |
242 | otg_register_notifier(struct usb_phy *x, struct notifier_block *nb) | 286 | usb_register_notifier(struct usb_phy *x, struct notifier_block *nb) |
243 | { | 287 | { |
244 | return atomic_notifier_chain_register(&x->notifier, nb); | 288 | return atomic_notifier_chain_register(&x->notifier, nb); |
245 | } | 289 | } |
246 | 290 | ||
247 | static inline void | 291 | static inline void |
248 | otg_unregister_notifier(struct usb_phy *x, struct notifier_block *nb) | 292 | usb_unregister_notifier(struct usb_phy *x, struct notifier_block *nb) |
249 | { | 293 | { |
250 | atomic_notifier_chain_unregister(&x->notifier, nb); | 294 | atomic_notifier_chain_unregister(&x->notifier, nb); |
251 | } | 295 | } |
@@ -253,4 +297,22 @@ otg_unregister_notifier(struct usb_phy *x, struct notifier_block *nb) | |||
253 | /* for OTG controller drivers (and maybe other stuff) */ | 297 | /* for OTG controller drivers (and maybe other stuff) */ |
254 | extern int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num); | 298 | extern int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num); |
255 | 299 | ||
300 | /* Temporary aliases for transceiver functions */ | ||
301 | #define otg_set_transceiver(x) usb_set_transceiver(x) | ||
302 | #define otg_get_transceiver() usb_get_transceiver() | ||
303 | #define otg_put_transceiver(x) usb_put_transceiver(x) | ||
304 | |||
305 | #define otg_io_read(x, a) usb_phy_io_read(x, a) | ||
306 | #define otg_io_write(x, a, b) usb_phy_io_write(x, a, b) | ||
307 | |||
308 | #define otg_init(x) usb_phy_init(x) | ||
309 | #define otg_shutdown(x) usb_phy_shutdown(x) | ||
310 | #define otg_set_power(x, a) usb_phy_set_power(x, a) | ||
311 | #define otg_set_suspend(x, a) usb_phy_set_suspend(x, a) | ||
312 | |||
313 | #define otg_register_notifier(x, a) usb_register_notifier(x, a) | ||
314 | #define otg_unregister_notifier(x, a) usb_unregiser_notifier(x, a) | ||
315 | |||
316 | #define otg_io_access_ops usb_phy_io_ops | ||
317 | |||
256 | #endif /* __LINUX_USB_OTG_H */ | 318 | #endif /* __LINUX_USB_OTG_H */ |