diff options
Diffstat (limited to 'include/linux/usb/otg.h')
-rw-r--r-- | include/linux/usb/otg.h | 164 |
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 | ||
38 | enum usb_xceiv_events { | 38 | enum 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 | ||
46 | struct otg_transceiver; | 46 | struct 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 | */ |
51 | struct otg_io_access_ops { | 51 | struct 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 | |||
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 | |||
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 | */ |
62 | struct otg_transceiver { | 87 | struct 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 */ |
118 | extern int otg_set_transceiver(struct otg_transceiver *); | 123 | extern 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 */ |
135 | static inline int otg_io_read(struct otg_transceiver *otg, u32 reg) | 140 | static 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 | ||
143 | static inline int otg_io_write(struct otg_transceiver *otg, u32 val, u32 reg) | 148 | static 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 | ||
151 | static inline int | 156 | static inline int |
152 | otg_init(struct otg_transceiver *otg) | 157 | usb_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 | ||
160 | static inline void | 165 | static inline void |
161 | otg_shutdown(struct otg_transceiver *otg) | 166 | usb_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 |
169 | extern struct otg_transceiver *otg_get_transceiver(void); | 174 | extern struct usb_phy *usb_get_transceiver(void); |
170 | extern void otg_put_transceiver(struct otg_transceiver *); | 175 | extern void usb_put_transceiver(struct usb_phy *); |
171 | extern const char *otg_state_string(enum usb_otg_state state); | 176 | extern const char *otg_state_string(enum usb_otg_state state); |
172 | #else | 177 | #else |
173 | static inline struct otg_transceiver *otg_get_transceiver(void) | 178 | static inline struct usb_phy *usb_get_transceiver(void) |
174 | { | 179 | { |
175 | return NULL; | 180 | return NULL; |
176 | } | 181 | } |
177 | 182 | ||
178 | static inline void otg_put_transceiver(struct otg_transceiver *x) | 183 | static 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 */ |
189 | static inline int | 194 | static inline int |
190 | otg_start_hnp(struct otg_transceiver *otg) | 195 | otg_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 */ |
196 | static inline int | 204 | static inline int |
197 | otg_set_vbus(struct otg_transceiver *otg, bool enabled) | 205 | otg_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 */ |
203 | static inline int | 214 | static inline int |
204 | otg_set_host(struct otg_transceiver *otg, struct usb_bus *host) | 215 | otg_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 */ |
212 | static inline int | 226 | static inline int |
213 | otg_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *periph) | 227 | otg_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 | ||
218 | static inline int | 235 | static inline int |
219 | otg_set_power(struct otg_transceiver *otg, unsigned mA) | 236 | usb_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 */ |
225 | static inline int | 244 | static inline int |
226 | otg_set_suspend(struct otg_transceiver *otg, int suspend) | 245 | usb_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 | ||
234 | static inline int | 253 | static inline int |
235 | otg_start_srp(struct otg_transceiver *otg) | 254 | otg_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 */ |
241 | static inline int | 263 | static inline int |
242 | otg_register_notifier(struct otg_transceiver *otg, struct notifier_block *nb) | 264 | usb_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 | ||
247 | static inline void | 269 | static inline void |
248 | otg_unregister_notifier(struct otg_transceiver *otg, struct notifier_block *nb) | 270 | usb_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) */ |