diff options
Diffstat (limited to 'include/linux/usb/otg.h')
-rw-r--r-- | include/linux/usb/otg.h | 103 |
1 files changed, 102 insertions, 1 deletions
diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h index 2443c0e7a80c..f8302d036a76 100644 --- a/include/linux/usb/otg.h +++ b/include/linux/usb/otg.h | |||
@@ -9,6 +9,8 @@ | |||
9 | #ifndef __LINUX_USB_OTG_H | 9 | #ifndef __LINUX_USB_OTG_H |
10 | #define __LINUX_USB_OTG_H | 10 | #define __LINUX_USB_OTG_H |
11 | 11 | ||
12 | #include <linux/notifier.h> | ||
13 | |||
12 | /* OTG defines lots of enumeration states before device reset */ | 14 | /* OTG defines lots of enumeration states before device reset */ |
13 | enum usb_otg_state { | 15 | enum usb_otg_state { |
14 | OTG_STATE_UNDEFINED = 0, | 16 | OTG_STATE_UNDEFINED = 0, |
@@ -33,6 +35,31 @@ enum usb_otg_state { | |||
33 | OTG_STATE_A_VBUS_ERR, | 35 | OTG_STATE_A_VBUS_ERR, |
34 | }; | 36 | }; |
35 | 37 | ||
38 | enum usb_xceiv_events { | ||
39 | USB_EVENT_NONE, /* no events or cable disconnected */ | ||
40 | USB_EVENT_VBUS, /* vbus valid event */ | ||
41 | USB_EVENT_ID, /* id was grounded */ | ||
42 | USB_EVENT_CHARGER, /* usb dedicated charger */ | ||
43 | USB_EVENT_ENUMERATED, /* gadget driver enumerated */ | ||
44 | }; | ||
45 | |||
46 | #define USB_OTG_PULLUP_ID (1 << 0) | ||
47 | #define USB_OTG_PULLDOWN_DP (1 << 1) | ||
48 | #define USB_OTG_PULLDOWN_DM (1 << 2) | ||
49 | #define USB_OTG_EXT_VBUS_INDICATOR (1 << 3) | ||
50 | #define USB_OTG_DRV_VBUS (1 << 4) | ||
51 | #define USB_OTG_DRV_VBUS_EXT (1 << 5) | ||
52 | |||
53 | struct otg_transceiver; | ||
54 | |||
55 | /* for transceivers connected thru an ULPI interface, the user must | ||
56 | * provide access ops | ||
57 | */ | ||
58 | struct otg_io_access_ops { | ||
59 | int (*read)(struct otg_transceiver *otg, u32 reg); | ||
60 | int (*write)(struct otg_transceiver *otg, u32 val, u32 reg); | ||
61 | }; | ||
62 | |||
36 | /* | 63 | /* |
37 | * the otg driver needs to interact with both device side and host side | 64 | * the otg driver needs to interact with both device side and host side |
38 | * usb controllers. it decides which controller is active at a given | 65 | * usb controllers. it decides which controller is active at a given |
@@ -42,6 +69,7 @@ enum usb_otg_state { | |||
42 | struct otg_transceiver { | 69 | struct otg_transceiver { |
43 | struct device *dev; | 70 | struct device *dev; |
44 | const char *label; | 71 | const char *label; |
72 | unsigned int flags; | ||
45 | 73 | ||
46 | u8 default_a; | 74 | u8 default_a; |
47 | enum usb_otg_state state; | 75 | enum usb_otg_state state; |
@@ -49,10 +77,20 @@ struct otg_transceiver { | |||
49 | struct usb_bus *host; | 77 | struct usb_bus *host; |
50 | struct usb_gadget *gadget; | 78 | struct usb_gadget *gadget; |
51 | 79 | ||
80 | struct otg_io_access_ops *io_ops; | ||
81 | void __iomem *io_priv; | ||
82 | |||
83 | /* for notification of usb_xceiv_events */ | ||
84 | struct blocking_notifier_head notifier; | ||
85 | |||
52 | /* to pass extra port status to the root hub */ | 86 | /* to pass extra port status to the root hub */ |
53 | u16 port_status; | 87 | u16 port_status; |
54 | u16 port_change; | 88 | u16 port_change; |
55 | 89 | ||
90 | /* initialize/shutdown the OTG controller */ | ||
91 | int (*init)(struct otg_transceiver *otg); | ||
92 | void (*shutdown)(struct otg_transceiver *otg); | ||
93 | |||
56 | /* bind/unbind the host controller */ | 94 | /* bind/unbind the host controller */ |
57 | int (*set_host)(struct otg_transceiver *otg, | 95 | int (*set_host)(struct otg_transceiver *otg, |
58 | struct usb_bus *host); | 96 | struct usb_bus *host); |
@@ -65,6 +103,10 @@ struct otg_transceiver { | |||
65 | int (*set_power)(struct otg_transceiver *otg, | 103 | int (*set_power)(struct otg_transceiver *otg, |
66 | unsigned mA); | 104 | unsigned mA); |
67 | 105 | ||
106 | /* effective for A-peripheral, ignored for B devices */ | ||
107 | int (*set_vbus)(struct otg_transceiver *otg, | ||
108 | bool enabled); | ||
109 | |||
68 | /* for non-OTG B devices: set transceiver into suspend mode */ | 110 | /* for non-OTG B devices: set transceiver into suspend mode */ |
69 | int (*set_suspend)(struct otg_transceiver *otg, | 111 | int (*set_suspend)(struct otg_transceiver *otg, |
70 | int suspend); | 112 | int suspend); |
@@ -81,10 +123,52 @@ struct otg_transceiver { | |||
81 | /* for board-specific init logic */ | 123 | /* for board-specific init logic */ |
82 | extern int otg_set_transceiver(struct otg_transceiver *); | 124 | extern int otg_set_transceiver(struct otg_transceiver *); |
83 | 125 | ||
126 | #if defined(CONFIG_NOP_USB_XCEIV) || defined(CONFIG_NOP_USB_XCEIV_MODULE) | ||
84 | /* sometimes transceivers are accessed only through e.g. ULPI */ | 127 | /* sometimes transceivers are accessed only through e.g. ULPI */ |
85 | extern void usb_nop_xceiv_register(void); | 128 | extern void usb_nop_xceiv_register(void); |
86 | extern void usb_nop_xceiv_unregister(void); | 129 | extern void usb_nop_xceiv_unregister(void); |
130 | #else | ||
131 | static inline void usb_nop_xceiv_register(void) | ||
132 | { | ||
133 | } | ||
134 | |||
135 | static inline void usb_nop_xceiv_unregister(void) | ||
136 | { | ||
137 | } | ||
138 | #endif | ||
87 | 139 | ||
140 | /* helpers for direct access thru low-level io interface */ | ||
141 | static inline int otg_io_read(struct otg_transceiver *otg, u32 reg) | ||
142 | { | ||
143 | if (otg->io_ops && otg->io_ops->read) | ||
144 | return otg->io_ops->read(otg, reg); | ||
145 | |||
146 | return -EINVAL; | ||
147 | } | ||
148 | |||
149 | static inline int otg_io_write(struct otg_transceiver *otg, u32 reg, u32 val) | ||
150 | { | ||
151 | if (otg->io_ops && otg->io_ops->write) | ||
152 | return otg->io_ops->write(otg, reg, val); | ||
153 | |||
154 | return -EINVAL; | ||
155 | } | ||
156 | |||
157 | static inline int | ||
158 | otg_init(struct otg_transceiver *otg) | ||
159 | { | ||
160 | if (otg->init) | ||
161 | return otg->init(otg); | ||
162 | |||
163 | return 0; | ||
164 | } | ||
165 | |||
166 | static inline void | ||
167 | otg_shutdown(struct otg_transceiver *otg) | ||
168 | { | ||
169 | if (otg->shutdown) | ||
170 | otg->shutdown(otg); | ||
171 | } | ||
88 | 172 | ||
89 | /* for usb host and peripheral controller drivers */ | 173 | /* for usb host and peripheral controller drivers */ |
90 | extern struct otg_transceiver *otg_get_transceiver(void); | 174 | extern struct otg_transceiver *otg_get_transceiver(void); |
@@ -97,6 +181,12 @@ otg_start_hnp(struct otg_transceiver *otg) | |||
97 | return otg->start_hnp(otg); | 181 | return otg->start_hnp(otg); |
98 | } | 182 | } |
99 | 183 | ||
184 | /* Context: can sleep */ | ||
185 | static inline int | ||
186 | otg_set_vbus(struct otg_transceiver *otg, bool enabled) | ||
187 | { | ||
188 | return otg->set_vbus(otg, enabled); | ||
189 | } | ||
100 | 190 | ||
101 | /* for HCDs */ | 191 | /* for HCDs */ |
102 | static inline int | 192 | static inline int |
@@ -105,7 +195,6 @@ otg_set_host(struct otg_transceiver *otg, struct usb_bus *host) | |||
105 | return otg->set_host(otg, host); | 195 | return otg->set_host(otg, host); |
106 | } | 196 | } |
107 | 197 | ||
108 | |||
109 | /* for usb peripheral controller drivers */ | 198 | /* for usb peripheral controller drivers */ |
110 | 199 | ||
111 | /* Context: can sleep */ | 200 | /* Context: can sleep */ |
@@ -137,6 +226,18 @@ otg_start_srp(struct otg_transceiver *otg) | |||
137 | return otg->start_srp(otg); | 226 | return otg->start_srp(otg); |
138 | } | 227 | } |
139 | 228 | ||
229 | /* notifiers */ | ||
230 | static inline int | ||
231 | otg_register_notifier(struct otg_transceiver *otg, struct notifier_block *nb) | ||
232 | { | ||
233 | return blocking_notifier_chain_register(&otg->notifier, nb); | ||
234 | } | ||
235 | |||
236 | static inline void | ||
237 | otg_unregister_notifier(struct otg_transceiver *otg, struct notifier_block *nb) | ||
238 | { | ||
239 | blocking_notifier_chain_unregister(&otg->notifier, nb); | ||
240 | } | ||
140 | 241 | ||
141 | /* for OTG controller drivers (and maybe other stuff) */ | 242 | /* for OTG controller drivers (and maybe other stuff) */ |
142 | extern int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num); | 243 | extern int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num); |