| 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 |  | 
| Daniel Mack | 91c8a5a | 2009-10-15 17:09:34 +0300 | [diff] [blame] | 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 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | /* | 
|  | 64 | * the otg driver needs to interact with both device side and host side | 
|  | 65 | * usb controllers.  it decides which controller is active at a given | 
|  | 66 | * moment, using the transceiver, ID signal, HNP and sometimes static | 
|  | 67 | * configuration information (including "board isn't wired for otg"). | 
|  | 68 | */ | 
|  | 69 | struct otg_transceiver { | 
|  | 70 | struct device		*dev; | 
|  | 71 | const char		*label; | 
| Daniel Mack | 91c8a5a | 2009-10-15 17:09:34 +0300 | [diff] [blame] | 72 | unsigned int		 flags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 |  | 
|  | 74 | u8			default_a; | 
|  | 75 | enum usb_otg_state	state; | 
|  | 76 |  | 
|  | 77 | struct usb_bus		*host; | 
|  | 78 | struct usb_gadget	*gadget; | 
|  | 79 |  | 
| Daniel Mack | 91c8a5a | 2009-10-15 17:09:34 +0300 | [diff] [blame] | 80 | struct otg_io_access_ops	*io_ops; | 
|  | 81 | void __iomem			*io_priv; | 
|  | 82 |  | 
| Felipe Balbi | e9a2017 | 2009-12-17 13:01:36 +0200 | [diff] [blame] | 83 | /* for notification of usb_xceiv_events */ | 
|  | 84 | struct blocking_notifier_head	notifier; | 
|  | 85 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | /* to pass extra port status to the root hub */ | 
|  | 87 | u16			port_status; | 
|  | 88 | u16			port_change; | 
|  | 89 |  | 
| Daniel Mack | 91c8a5a | 2009-10-15 17:09:34 +0300 | [diff] [blame] | 90 | /* initialize/shutdown the OTG controller */ | 
|  | 91 | int	(*init)(struct otg_transceiver *otg); | 
|  | 92 | void	(*shutdown)(struct otg_transceiver *otg); | 
|  | 93 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | /* bind/unbind the host controller */ | 
| David Brownell | 3a16f7b | 2006-06-29 12:27:23 -0700 | [diff] [blame] | 95 | int	(*set_host)(struct otg_transceiver *otg, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | struct usb_bus *host); | 
|  | 97 |  | 
|  | 98 | /* bind/unbind the peripheral controller */ | 
|  | 99 | int	(*set_peripheral)(struct otg_transceiver *otg, | 
|  | 100 | struct usb_gadget *gadget); | 
|  | 101 |  | 
|  | 102 | /* effective for B devices, ignored for A-peripheral */ | 
|  | 103 | int	(*set_power)(struct otg_transceiver *otg, | 
|  | 104 | unsigned mA); | 
|  | 105 |  | 
| Daniel Mack | 91c8a5a | 2009-10-15 17:09:34 +0300 | [diff] [blame] | 106 | /* effective for A-peripheral, ignored for B devices */ | 
|  | 107 | int	(*set_vbus)(struct otg_transceiver *otg, | 
|  | 108 | bool enabled); | 
|  | 109 |  | 
| Juha Yrj?l? | 4e67185 | 2005-10-16 15:47:04 -0700 | [diff] [blame] | 110 | /* for non-OTG B devices: set transceiver into suspend mode */ | 
|  | 111 | int	(*set_suspend)(struct otg_transceiver *otg, | 
|  | 112 | int suspend); | 
|  | 113 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | /* for B devices only:  start session with A-Host */ | 
|  | 115 | int	(*start_srp)(struct otg_transceiver *otg); | 
|  | 116 |  | 
|  | 117 | /* start or continue HNP role switch */ | 
|  | 118 | int	(*start_hnp)(struct otg_transceiver *otg); | 
|  | 119 |  | 
|  | 120 | }; | 
|  | 121 |  | 
|  | 122 |  | 
|  | 123 | /* for board-specific init logic */ | 
|  | 124 | extern int otg_set_transceiver(struct otg_transceiver *); | 
| David Brownell | cc835e3 | 2009-03-31 12:28:31 -0700 | [diff] [blame] | 125 |  | 
| Maulik Mankad | 224e154 | 2010-02-17 14:09:29 -0800 | [diff] [blame] | 126 | #if defined(CONFIG_NOP_USB_XCEIV) || defined(CONFIG_NOP_USB_XCEIV_MODULE) | 
| David Brownell | cc835e3 | 2009-03-31 12:28:31 -0700 | [diff] [blame] | 127 | /* sometimes transceivers are accessed only through e.g. ULPI */ | 
| Ajay Kumar Gupta | f6d92a0 | 2009-02-06 17:32:35 +0530 | [diff] [blame] | 128 | extern void usb_nop_xceiv_register(void); | 
|  | 129 | extern void usb_nop_xceiv_unregister(void); | 
| Maulik Mankad | 224e154 | 2010-02-17 14:09:29 -0800 | [diff] [blame] | 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 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 |  | 
| Daniel Mack | 91c8a5a | 2009-10-15 17:09:34 +0300 | [diff] [blame] | 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 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 |  | 
|  | 173 | /* for usb host and peripheral controller drivers */ | 
|  | 174 | extern struct otg_transceiver *otg_get_transceiver(void); | 
| Philipp Zabel | 68144e0 | 2008-11-24 12:01:17 -0800 | [diff] [blame] | 175 | extern void otg_put_transceiver(struct otg_transceiver *); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 |  | 
| Robert Jarzmik | c2344f1 | 2009-01-24 23:54:31 -0800 | [diff] [blame] | 177 | /* Context: can sleep */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | static inline int | 
|  | 179 | otg_start_hnp(struct otg_transceiver *otg) | 
|  | 180 | { | 
|  | 181 | return otg->start_hnp(otg); | 
|  | 182 | } | 
|  | 183 |  | 
| Daniel Mack | 91c8a5a | 2009-10-15 17:09:34 +0300 | [diff] [blame] | 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 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 |  | 
|  | 191 | /* for HCDs */ | 
|  | 192 | static inline int | 
|  | 193 | otg_set_host(struct otg_transceiver *otg, struct usb_bus *host) | 
|  | 194 | { | 
|  | 195 | return otg->set_host(otg, host); | 
|  | 196 | } | 
|  | 197 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | /* for usb peripheral controller drivers */ | 
| Robert Jarzmik | c2344f1 | 2009-01-24 23:54:31 -0800 | [diff] [blame] | 199 |  | 
|  | 200 | /* Context: can sleep */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | static inline int | 
|  | 202 | otg_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *periph) | 
|  | 203 | { | 
|  | 204 | return otg->set_peripheral(otg, periph); | 
|  | 205 | } | 
|  | 206 |  | 
|  | 207 | static inline int | 
|  | 208 | otg_set_power(struct otg_transceiver *otg, unsigned mA) | 
|  | 209 | { | 
|  | 210 | return otg->set_power(otg, mA); | 
|  | 211 | } | 
|  | 212 |  | 
| Robert Jarzmik | c2344f1 | 2009-01-24 23:54:31 -0800 | [diff] [blame] | 213 | /* Context: can sleep */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | static inline int | 
| Juha Yrj?l? | 4e67185 | 2005-10-16 15:47:04 -0700 | [diff] [blame] | 215 | otg_set_suspend(struct otg_transceiver *otg, int suspend) | 
|  | 216 | { | 
|  | 217 | if (otg->set_suspend != NULL) | 
|  | 218 | return otg->set_suspend(otg, suspend); | 
|  | 219 | else | 
|  | 220 | return 0; | 
|  | 221 | } | 
|  | 222 |  | 
|  | 223 | static inline int | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | otg_start_srp(struct otg_transceiver *otg) | 
|  | 225 | { | 
|  | 226 | return otg->start_srp(otg); | 
|  | 227 | } | 
|  | 228 |  | 
| Felipe Balbi | e9a2017 | 2009-12-17 13:01:36 +0200 | [diff] [blame] | 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 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 |  | 
|  | 242 | /* for OTG controller drivers (and maybe other stuff) */ | 
|  | 243 | 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] | 244 |  | 
|  | 245 | #endif /* __LINUX_USB_OTG_H */ |