Greg Kroah-Hartman | 41dceed | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 1 | /* USB OTG (On The Go) defines */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Robert P. J. Day | dda43a0 | 2008-03-07 13:45:32 -0500 | [diff] [blame] | 3 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * These APIs may be used between USB controllers. USB device drivers |
| 5 | * (for either host or peripheral roles) don't use these calls; they |
| 6 | * continue to use just usb_device and usb_gadget. |
| 7 | */ |
| 8 | |
Robert P. J. Day | dda43a0 | 2008-03-07 13:45:32 -0500 | [diff] [blame] | 9 | #ifndef __LINUX_USB_OTG_H |
| 10 | #define __LINUX_USB_OTG_H |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
Felipe Balbi | e9a2017 | 2009-12-17 13:01:36 +0200 | [diff] [blame] | 12 | #include <linux/notifier.h> |
| 13 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | /* OTG defines lots of enumeration states before device reset */ |
| 15 | enum usb_otg_state { |
| 16 | OTG_STATE_UNDEFINED = 0, |
| 17 | |
| 18 | /* single-role peripheral, and dual-role default-b */ |
| 19 | OTG_STATE_B_IDLE, |
| 20 | OTG_STATE_B_SRP_INIT, |
| 21 | OTG_STATE_B_PERIPHERAL, |
| 22 | |
| 23 | /* extra dual-role default-b states */ |
| 24 | OTG_STATE_B_WAIT_ACON, |
| 25 | OTG_STATE_B_HOST, |
| 26 | |
| 27 | /* dual-role default-a */ |
| 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 | |
Felipe Balbi | e9a2017 | 2009-12-17 13:01:36 +0200 | [diff] [blame] | 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 | |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 46 | struct usb_phy; |
Daniel Mack | 91c8a5a | 2009-10-15 17:09:34 +0300 | [diff] [blame] | 47 | |
| 48 | /* for transceivers connected thru an ULPI interface, the user must |
| 49 | * provide access ops |
| 50 | */ |
| 51 | struct otg_io_access_ops { |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 52 | int (*read)(struct usb_phy *x, u32 reg); |
| 53 | int (*write)(struct usb_phy *x, u32 val, u32 reg); |
Daniel Mack | 91c8a5a | 2009-10-15 17:09:34 +0300 | [diff] [blame] | 54 | }; |
| 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | /* |
| 57 | * 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 |
| 59 | * moment, using the transceiver, ID signal, HNP and sometimes static |
| 60 | * configuration information (including "board isn't wired for otg"). |
| 61 | */ |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 62 | struct usb_phy { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | struct device *dev; |
| 64 | const char *label; |
Daniel Mack | 91c8a5a | 2009-10-15 17:09:34 +0300 | [diff] [blame] | 65 | unsigned int flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
| 67 | u8 default_a; |
| 68 | enum usb_otg_state state; |
Hema HK | 647b2d9 | 2011-02-17 12:06:09 +0530 | [diff] [blame] | 69 | enum usb_xceiv_events last_event; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
| 71 | struct usb_bus *host; |
| 72 | struct usb_gadget *gadget; |
| 73 | |
Daniel Mack | 91c8a5a | 2009-10-15 17:09:34 +0300 | [diff] [blame] | 74 | struct otg_io_access_ops *io_ops; |
| 75 | void __iomem *io_priv; |
| 76 | |
Felipe Balbi | e9a2017 | 2009-12-17 13:01:36 +0200 | [diff] [blame] | 77 | /* for notification of usb_xceiv_events */ |
Felipe Balbi | cccad6d | 2010-09-29 10:55:49 +0300 | [diff] [blame] | 78 | struct atomic_notifier_head notifier; |
Felipe Balbi | e9a2017 | 2009-12-17 13:01:36 +0200 | [diff] [blame] | 79 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | /* to pass extra port status to the root hub */ |
| 81 | u16 port_status; |
| 82 | u16 port_change; |
| 83 | |
Daniel Mack | 91c8a5a | 2009-10-15 17:09:34 +0300 | [diff] [blame] | 84 | /* initialize/shutdown the OTG controller */ |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 85 | int (*init)(struct usb_phy *x); |
| 86 | void (*shutdown)(struct usb_phy *x); |
Daniel Mack | 91c8a5a | 2009-10-15 17:09:34 +0300 | [diff] [blame] | 87 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | /* bind/unbind the host controller */ |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 89 | int (*set_host)(struct usb_phy *x, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | struct usb_bus *host); |
| 91 | |
| 92 | /* bind/unbind the peripheral controller */ |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 93 | int (*set_peripheral)(struct usb_phy *x, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | struct usb_gadget *gadget); |
| 95 | |
| 96 | /* effective for B devices, ignored for A-peripheral */ |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 97 | int (*set_power)(struct usb_phy *x, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | unsigned mA); |
| 99 | |
Daniel Mack | 91c8a5a | 2009-10-15 17:09:34 +0300 | [diff] [blame] | 100 | /* effective for A-peripheral, ignored for B devices */ |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 101 | int (*set_vbus)(struct usb_phy *x, |
Daniel Mack | 91c8a5a | 2009-10-15 17:09:34 +0300 | [diff] [blame] | 102 | bool enabled); |
| 103 | |
Juha Yrj?l? | 4e67185 | 2005-10-16 15:47:04 -0700 | [diff] [blame] | 104 | /* for non-OTG B devices: set transceiver into suspend mode */ |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 105 | int (*set_suspend)(struct usb_phy *x, |
Juha Yrj?l? | 4e67185 | 2005-10-16 15:47:04 -0700 | [diff] [blame] | 106 | int suspend); |
| 107 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | /* for B devices only: start session with A-Host */ |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 109 | int (*start_srp)(struct usb_phy *x); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
| 111 | /* start or continue HNP role switch */ |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 112 | int (*start_hnp)(struct usb_phy *x); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
| 114 | }; |
| 115 | |
| 116 | |
| 117 | /* for board-specific init logic */ |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 118 | extern int otg_set_transceiver(struct usb_phy *); |
David Brownell | cc835e3 | 2009-03-31 12:28:31 -0700 | [diff] [blame] | 119 | |
Guennadi Liakhovetski | 352a337 | 2010-12-09 22:46:29 +0100 | [diff] [blame] | 120 | #if defined(CONFIG_NOP_USB_XCEIV) || (defined(CONFIG_NOP_USB_XCEIV_MODULE) && defined(MODULE)) |
David Brownell | cc835e3 | 2009-03-31 12:28:31 -0700 | [diff] [blame] | 121 | /* sometimes transceivers are accessed only through e.g. ULPI */ |
Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 122 | extern void usb_nop_xceiv_register(void); |
| 123 | extern void usb_nop_xceiv_unregister(void); |
Maulik Mankad | 224e154 | 2010-02-17 14:09:29 -0800 | [diff] [blame] | 124 | #else |
| 125 | static inline void usb_nop_xceiv_register(void) |
| 126 | { |
| 127 | } |
| 128 | |
| 129 | static inline void usb_nop_xceiv_unregister(void) |
| 130 | { |
| 131 | } |
| 132 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
Daniel Mack | 91c8a5a | 2009-10-15 17:09:34 +0300 | [diff] [blame] | 134 | /* helpers for direct access thru low-level io interface */ |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 135 | static inline int otg_io_read(struct usb_phy *x, u32 reg) |
Daniel Mack | 91c8a5a | 2009-10-15 17:09:34 +0300 | [diff] [blame] | 136 | { |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 137 | if (x->io_ops && x->io_ops->read) |
| 138 | return x->io_ops->read(x, reg); |
Daniel Mack | 91c8a5a | 2009-10-15 17:09:34 +0300 | [diff] [blame] | 139 | |
| 140 | return -EINVAL; |
| 141 | } |
| 142 | |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 143 | static inline int otg_io_write(struct usb_phy *x, u32 val, u32 reg) |
Daniel Mack | 91c8a5a | 2009-10-15 17:09:34 +0300 | [diff] [blame] | 144 | { |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 145 | if (x->io_ops && x->io_ops->write) |
| 146 | return x->io_ops->write(x, val, reg); |
Daniel Mack | 91c8a5a | 2009-10-15 17:09:34 +0300 | [diff] [blame] | 147 | |
| 148 | return -EINVAL; |
| 149 | } |
| 150 | |
| 151 | static inline int |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 152 | otg_init(struct usb_phy *x) |
Daniel Mack | 91c8a5a | 2009-10-15 17:09:34 +0300 | [diff] [blame] | 153 | { |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 154 | if (x->init) |
| 155 | return x->init(x); |
Daniel Mack | 91c8a5a | 2009-10-15 17:09:34 +0300 | [diff] [blame] | 156 | |
| 157 | return 0; |
| 158 | } |
| 159 | |
| 160 | static inline void |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 161 | otg_shutdown(struct usb_phy *x) |
Daniel Mack | 91c8a5a | 2009-10-15 17:09:34 +0300 | [diff] [blame] | 162 | { |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 163 | if (x->shutdown) |
| 164 | x->shutdown(x); |
Daniel Mack | 91c8a5a | 2009-10-15 17:09:34 +0300 | [diff] [blame] | 165 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | |
| 167 | /* for usb host and peripheral controller drivers */ |
Grazvydas Ignotas | 748eee0 | 2010-09-27 15:17:18 +0300 | [diff] [blame] | 168 | #ifdef CONFIG_USB_OTG_UTILS |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 169 | extern struct usb_phy *otg_get_transceiver(void); |
| 170 | extern void otg_put_transceiver(struct usb_phy *); |
Anatolij Gustschin | 3df0045 | 2011-05-05 12:11:21 +0200 | [diff] [blame] | 171 | extern const char *otg_state_string(enum usb_otg_state state); |
Grazvydas Ignotas | 748eee0 | 2010-09-27 15:17:18 +0300 | [diff] [blame] | 172 | #else |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 173 | static inline struct usb_phy *otg_get_transceiver(void) |
Grazvydas Ignotas | 748eee0 | 2010-09-27 15:17:18 +0300 | [diff] [blame] | 174 | { |
| 175 | return NULL; |
| 176 | } |
| 177 | |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 178 | static inline void otg_put_transceiver(struct usb_phy *x) |
Grazvydas Ignotas | 748eee0 | 2010-09-27 15:17:18 +0300 | [diff] [blame] | 179 | { |
| 180 | } |
Anatolij Gustschin | 3df0045 | 2011-05-05 12:11:21 +0200 | [diff] [blame] | 181 | |
| 182 | static inline const char *otg_state_string(enum usb_otg_state state) |
| 183 | { |
| 184 | return NULL; |
| 185 | } |
Grazvydas Ignotas | 748eee0 | 2010-09-27 15:17:18 +0300 | [diff] [blame] | 186 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
Robert Jarzmik | c2344f1 | 2009-01-24 23:54:31 -0800 | [diff] [blame] | 188 | /* Context: can sleep */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | static inline int |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 190 | otg_start_hnp(struct usb_phy *x) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | { |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 192 | return x->start_hnp(x); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Daniel Mack | 91c8a5a | 2009-10-15 17:09:34 +0300 | [diff] [blame] | 195 | /* Context: can sleep */ |
| 196 | static inline int |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 197 | otg_set_vbus(struct usb_phy *x, bool enabled) |
Daniel Mack | 91c8a5a | 2009-10-15 17:09:34 +0300 | [diff] [blame] | 198 | { |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 199 | return x->set_vbus(x, enabled); |
Daniel Mack | 91c8a5a | 2009-10-15 17:09:34 +0300 | [diff] [blame] | 200 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
| 202 | /* for HCDs */ |
| 203 | static inline int |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 204 | otg_set_host(struct usb_phy *x, struct usb_bus *host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | { |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 206 | return x->set_host(x, host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | /* for usb peripheral controller drivers */ |
Robert Jarzmik | c2344f1 | 2009-01-24 23:54:31 -0800 | [diff] [blame] | 210 | |
| 211 | /* Context: can sleep */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | static inline int |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 213 | otg_set_peripheral(struct usb_phy *x, struct usb_gadget *periph) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | { |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 215 | return x->set_peripheral(x, periph); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | static inline int |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 219 | otg_set_power(struct usb_phy *x, unsigned mA) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | { |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 221 | return x->set_power(x, mA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Robert Jarzmik | c2344f1 | 2009-01-24 23:54:31 -0800 | [diff] [blame] | 224 | /* Context: can sleep */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | static inline int |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 226 | otg_set_suspend(struct usb_phy *x, int suspend) |
Juha Yrj?l? | 4e67185 | 2005-10-16 15:47:04 -0700 | [diff] [blame] | 227 | { |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 228 | if (x->set_suspend != NULL) |
| 229 | return x->set_suspend(x, suspend); |
Juha Yrj?l? | 4e67185 | 2005-10-16 15:47:04 -0700 | [diff] [blame] | 230 | else |
| 231 | return 0; |
| 232 | } |
| 233 | |
| 234 | static inline int |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 235 | otg_start_srp(struct usb_phy *x) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | { |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 237 | return x->start_srp(x); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Felipe Balbi | e9a2017 | 2009-12-17 13:01:36 +0200 | [diff] [blame] | 240 | /* notifiers */ |
| 241 | static inline int |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 242 | otg_register_notifier(struct usb_phy *x, struct notifier_block *nb) |
Felipe Balbi | e9a2017 | 2009-12-17 13:01:36 +0200 | [diff] [blame] | 243 | { |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 244 | return atomic_notifier_chain_register(&x->notifier, nb); |
Felipe Balbi | e9a2017 | 2009-12-17 13:01:36 +0200 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | static inline void |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 248 | otg_unregister_notifier(struct usb_phy *x, struct notifier_block *nb) |
Felipe Balbi | e9a2017 | 2009-12-17 13:01:36 +0200 | [diff] [blame] | 249 | { |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame^] | 250 | atomic_notifier_chain_unregister(&x->notifier, nb); |
Felipe Balbi | e9a2017 | 2009-12-17 13:01:36 +0200 | [diff] [blame] | 251 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
| 253 | /* for OTG controller drivers (and maybe other stuff) */ |
| 254 | extern int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num); |
Robert P. J. Day | dda43a0 | 2008-03-07 13:45:32 -0500 | [diff] [blame] | 255 | |
| 256 | #endif /* __LINUX_USB_OTG_H */ |