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 | |
Antoine Tenart | 48bcc18 | 2014-10-30 18:41:15 +0100 | [diff] [blame^] | 12 | #include <linux/phy/phy.h> |
Venu Byravarasu | de4217d | 2012-09-04 14:25:58 +0530 | [diff] [blame] | 13 | #include <linux/usb/phy.h> |
Felipe Balbi | e9a2017 | 2009-12-17 13:01:36 +0200 | [diff] [blame] | 14 | |
Heikki Krogerus | 7a8a3a9 | 2012-02-13 13:24:04 +0200 | [diff] [blame] | 15 | struct usb_otg { |
| 16 | u8 default_a; |
| 17 | |
Antoine Tenart | 48bcc18 | 2014-10-30 18:41:15 +0100 | [diff] [blame^] | 18 | struct phy *phy; |
| 19 | /* old usb_phy interface */ |
Antoine Tenart | 19c1eac | 2014-10-30 18:41:14 +0100 | [diff] [blame] | 20 | struct usb_phy *usb_phy; |
Heikki Krogerus | 7a8a3a9 | 2012-02-13 13:24:04 +0200 | [diff] [blame] | 21 | struct usb_bus *host; |
| 22 | struct usb_gadget *gadget; |
| 23 | |
Antoine Tenart | e47d925 | 2014-10-30 18:41:13 +0100 | [diff] [blame] | 24 | enum usb_otg_state state; |
| 25 | |
Heikki Krogerus | 7a8a3a9 | 2012-02-13 13:24:04 +0200 | [diff] [blame] | 26 | /* bind/unbind the host controller */ |
| 27 | int (*set_host)(struct usb_otg *otg, struct usb_bus *host); |
| 28 | |
| 29 | /* bind/unbind the peripheral controller */ |
| 30 | int (*set_peripheral)(struct usb_otg *otg, |
| 31 | struct usb_gadget *gadget); |
| 32 | |
| 33 | /* effective for A-peripheral, ignored for B devices */ |
| 34 | int (*set_vbus)(struct usb_otg *otg, bool enabled); |
| 35 | |
| 36 | /* for B devices only: start session with A-Host */ |
| 37 | int (*start_srp)(struct usb_otg *otg); |
| 38 | |
| 39 | /* start or continue HNP role switch */ |
| 40 | int (*start_hnp)(struct usb_otg *otg); |
| 41 | |
| 42 | }; |
| 43 | |
Felipe Balbi | 42c0bf1 | 2013-03-07 10:39:57 +0200 | [diff] [blame] | 44 | extern const char *usb_otg_state_string(enum usb_otg_state state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Robert Jarzmik | c2344f1 | 2009-01-24 23:54:31 -0800 | [diff] [blame] | 46 | /* Context: can sleep */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | static inline int |
Heikki Krogerus | 6e13c65 | 2012-02-13 13:24:20 +0200 | [diff] [blame] | 48 | otg_start_hnp(struct usb_otg *otg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | { |
Heikki Krogerus | 6e13c65 | 2012-02-13 13:24:20 +0200 | [diff] [blame] | 50 | if (otg && otg->start_hnp) |
| 51 | return otg->start_hnp(otg); |
Heikki Krogerus | 7a8a3a9 | 2012-02-13 13:24:04 +0200 | [diff] [blame] | 52 | |
Heikki Krogerus | 136ced8 | 2012-02-13 13:24:19 +0200 | [diff] [blame] | 53 | return -ENOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Daniel Mack | 91c8a5a | 2009-10-15 17:09:34 +0300 | [diff] [blame] | 56 | /* Context: can sleep */ |
| 57 | static inline int |
Heikki Krogerus | 6e13c65 | 2012-02-13 13:24:20 +0200 | [diff] [blame] | 58 | otg_set_vbus(struct usb_otg *otg, bool enabled) |
Daniel Mack | 91c8a5a | 2009-10-15 17:09:34 +0300 | [diff] [blame] | 59 | { |
Heikki Krogerus | 6e13c65 | 2012-02-13 13:24:20 +0200 | [diff] [blame] | 60 | if (otg && otg->set_vbus) |
| 61 | return otg->set_vbus(otg, enabled); |
Heikki Krogerus | 7a8a3a9 | 2012-02-13 13:24:04 +0200 | [diff] [blame] | 62 | |
Heikki Krogerus | 136ced8 | 2012-02-13 13:24:19 +0200 | [diff] [blame] | 63 | return -ENOTSUPP; |
Daniel Mack | 91c8a5a | 2009-10-15 17:09:34 +0300 | [diff] [blame] | 64 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
| 66 | /* for HCDs */ |
| 67 | static inline int |
Heikki Krogerus | 6e13c65 | 2012-02-13 13:24:20 +0200 | [diff] [blame] | 68 | otg_set_host(struct usb_otg *otg, struct usb_bus *host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | { |
Heikki Krogerus | 6e13c65 | 2012-02-13 13:24:20 +0200 | [diff] [blame] | 70 | if (otg && otg->set_host) |
| 71 | return otg->set_host(otg, host); |
Heikki Krogerus | 7a8a3a9 | 2012-02-13 13:24:04 +0200 | [diff] [blame] | 72 | |
Heikki Krogerus | 136ced8 | 2012-02-13 13:24:19 +0200 | [diff] [blame] | 73 | return -ENOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | } |
| 75 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | /* for usb peripheral controller drivers */ |
Robert Jarzmik | c2344f1 | 2009-01-24 23:54:31 -0800 | [diff] [blame] | 77 | |
| 78 | /* Context: can sleep */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | static inline int |
Heikki Krogerus | 6e13c65 | 2012-02-13 13:24:20 +0200 | [diff] [blame] | 80 | otg_set_peripheral(struct usb_otg *otg, struct usb_gadget *periph) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | { |
Heikki Krogerus | 6e13c65 | 2012-02-13 13:24:20 +0200 | [diff] [blame] | 82 | if (otg && otg->set_peripheral) |
| 83 | return otg->set_peripheral(otg, periph); |
Heikki Krogerus | 7a8a3a9 | 2012-02-13 13:24:04 +0200 | [diff] [blame] | 84 | |
Heikki Krogerus | 136ced8 | 2012-02-13 13:24:19 +0200 | [diff] [blame] | 85 | return -ENOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | static inline int |
Heikki Krogerus | 6e13c65 | 2012-02-13 13:24:20 +0200 | [diff] [blame] | 89 | otg_start_srp(struct usb_otg *otg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | { |
Heikki Krogerus | 6e13c65 | 2012-02-13 13:24:20 +0200 | [diff] [blame] | 91 | if (otg && otg->start_srp) |
| 92 | return otg->start_srp(otg); |
Heikki Krogerus | 7a8a3a9 | 2012-02-13 13:24:04 +0200 | [diff] [blame] | 93 | |
Heikki Krogerus | 136ced8 | 2012-02-13 13:24:19 +0200 | [diff] [blame] | 94 | return -ENOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | /* for OTG controller drivers (and maybe other stuff) */ |
| 98 | 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] | 99 | |
Michael Grzeschik | 1c9af65 | 2013-06-13 17:59:55 +0300 | [diff] [blame] | 100 | enum usb_dr_mode { |
| 101 | USB_DR_MODE_UNKNOWN, |
| 102 | USB_DR_MODE_HOST, |
| 103 | USB_DR_MODE_PERIPHERAL, |
| 104 | USB_DR_MODE_OTG, |
| 105 | }; |
| 106 | |
Robert P. J. Day | dda43a0 | 2008-03-07 13:45:32 -0500 | [diff] [blame] | 107 | #endif /* __LINUX_USB_OTG_H */ |