Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Greg Kroah-Hartman | 41dceed | 2008-01-30 15:21:33 -0800 | [diff] [blame] | 2 | /* USB OTG (On The Go) defines */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | /* |
Robert P. J. Day | dda43a0 | 2008-03-07 13:45:32 -0500 | [diff] [blame] | 4 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * These APIs may be used between USB controllers. USB device drivers |
| 6 | * (for either host or peripheral roles) don't use these calls; they |
| 7 | * continue to use just usb_device and usb_gadget. |
| 8 | */ |
| 9 | |
Robert P. J. Day | dda43a0 | 2008-03-07 13:45:32 -0500 | [diff] [blame] | 10 | #ifndef __LINUX_USB_OTG_H |
| 11 | #define __LINUX_USB_OTG_H |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | |
Antoine Tenart | 48bcc18 | 2014-10-30 18:41:15 +0100 | [diff] [blame] | 13 | #include <linux/phy/phy.h> |
Venu Byravarasu | de4217d | 2012-09-04 14:25:58 +0530 | [diff] [blame] | 14 | #include <linux/usb/phy.h> |
Felipe Balbi | e9a2017 | 2009-12-17 13:01:36 +0200 | [diff] [blame] | 15 | |
Heikki Krogerus | 7a8a3a9 | 2012-02-13 13:24:04 +0200 | [diff] [blame] | 16 | struct usb_otg { |
| 17 | u8 default_a; |
| 18 | |
Antoine Tenart | 48bcc18 | 2014-10-30 18:41:15 +0100 | [diff] [blame] | 19 | struct phy *phy; |
| 20 | /* old usb_phy interface */ |
Antoine Tenart | 19c1eac | 2014-10-30 18:41:14 +0100 | [diff] [blame] | 21 | struct usb_phy *usb_phy; |
Heikki Krogerus | 7a8a3a9 | 2012-02-13 13:24:04 +0200 | [diff] [blame] | 22 | struct usb_bus *host; |
| 23 | struct usb_gadget *gadget; |
| 24 | |
Antoine Tenart | e47d925 | 2014-10-30 18:41:13 +0100 | [diff] [blame] | 25 | enum usb_otg_state state; |
| 26 | |
Heikki Krogerus | 7a8a3a9 | 2012-02-13 13:24:04 +0200 | [diff] [blame] | 27 | /* bind/unbind the host controller */ |
| 28 | int (*set_host)(struct usb_otg *otg, struct usb_bus *host); |
| 29 | |
| 30 | /* bind/unbind the peripheral controller */ |
| 31 | int (*set_peripheral)(struct usb_otg *otg, |
| 32 | struct usb_gadget *gadget); |
| 33 | |
| 34 | /* effective for A-peripheral, ignored for B devices */ |
| 35 | int (*set_vbus)(struct usb_otg *otg, bool enabled); |
| 36 | |
| 37 | /* for B devices only: start session with A-Host */ |
| 38 | int (*start_srp)(struct usb_otg *otg); |
| 39 | |
| 40 | /* start or continue HNP role switch */ |
| 41 | int (*start_hnp)(struct usb_otg *otg); |
| 42 | |
| 43 | }; |
| 44 | |
Li Jun | 6a88bbe | 2015-07-09 15:18:40 +0800 | [diff] [blame] | 45 | /** |
| 46 | * struct usb_otg_caps - describes the otg capabilities of the device |
| 47 | * @otg_rev: The OTG revision number the device is compliant with, it's |
| 48 | * in binary-coded decimal (i.e. 2.0 is 0200H). |
| 49 | * @hnp_support: Indicates if the device supports HNP. |
| 50 | * @srp_support: Indicates if the device supports SRP. |
| 51 | * @adp_support: Indicates if the device supports ADP. |
| 52 | */ |
| 53 | struct usb_otg_caps { |
| 54 | u16 otg_rev; |
| 55 | bool hnp_support; |
| 56 | bool srp_support; |
| 57 | bool adp_support; |
| 58 | }; |
| 59 | |
Felipe Balbi | 42c0bf1 | 2013-03-07 10:39:57 +0200 | [diff] [blame] | 60 | extern const char *usb_otg_state_string(enum usb_otg_state state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Robert Jarzmik | c2344f1 | 2009-01-24 23:54:31 -0800 | [diff] [blame] | 62 | /* Context: can sleep */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | static inline int |
Heikki Krogerus | 6e13c65 | 2012-02-13 13:24:20 +0200 | [diff] [blame] | 64 | otg_start_hnp(struct usb_otg *otg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | { |
Heikki Krogerus | 6e13c65 | 2012-02-13 13:24:20 +0200 | [diff] [blame] | 66 | if (otg && otg->start_hnp) |
| 67 | return otg->start_hnp(otg); |
Heikki Krogerus | 7a8a3a9 | 2012-02-13 13:24:04 +0200 | [diff] [blame] | 68 | |
Heikki Krogerus | 136ced8 | 2012-02-13 13:24:19 +0200 | [diff] [blame] | 69 | return -ENOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Daniel Mack | 91c8a5a | 2009-10-15 17:09:34 +0300 | [diff] [blame] | 72 | /* Context: can sleep */ |
| 73 | static inline int |
Heikki Krogerus | 6e13c65 | 2012-02-13 13:24:20 +0200 | [diff] [blame] | 74 | otg_set_vbus(struct usb_otg *otg, bool enabled) |
Daniel Mack | 91c8a5a | 2009-10-15 17:09:34 +0300 | [diff] [blame] | 75 | { |
Heikki Krogerus | 6e13c65 | 2012-02-13 13:24:20 +0200 | [diff] [blame] | 76 | if (otg && otg->set_vbus) |
| 77 | return otg->set_vbus(otg, enabled); |
Heikki Krogerus | 7a8a3a9 | 2012-02-13 13:24:04 +0200 | [diff] [blame] | 78 | |
Heikki Krogerus | 136ced8 | 2012-02-13 13:24:19 +0200 | [diff] [blame] | 79 | return -ENOTSUPP; |
Daniel Mack | 91c8a5a | 2009-10-15 17:09:34 +0300 | [diff] [blame] | 80 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
| 82 | /* for HCDs */ |
| 83 | static inline int |
Heikki Krogerus | 6e13c65 | 2012-02-13 13:24:20 +0200 | [diff] [blame] | 84 | otg_set_host(struct usb_otg *otg, struct usb_bus *host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | { |
Heikki Krogerus | 6e13c65 | 2012-02-13 13:24:20 +0200 | [diff] [blame] | 86 | if (otg && otg->set_host) |
| 87 | return otg->set_host(otg, host); |
Heikki Krogerus | 7a8a3a9 | 2012-02-13 13:24:04 +0200 | [diff] [blame] | 88 | |
Heikki Krogerus | 136ced8 | 2012-02-13 13:24:19 +0200 | [diff] [blame] | 89 | return -ENOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | /* for usb peripheral controller drivers */ |
Robert Jarzmik | c2344f1 | 2009-01-24 23:54:31 -0800 | [diff] [blame] | 93 | |
| 94 | /* Context: can sleep */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | static inline int |
Heikki Krogerus | 6e13c65 | 2012-02-13 13:24:20 +0200 | [diff] [blame] | 96 | otg_set_peripheral(struct usb_otg *otg, struct usb_gadget *periph) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | { |
Heikki Krogerus | 6e13c65 | 2012-02-13 13:24:20 +0200 | [diff] [blame] | 98 | if (otg && otg->set_peripheral) |
| 99 | return otg->set_peripheral(otg, periph); |
Heikki Krogerus | 7a8a3a9 | 2012-02-13 13:24:04 +0200 | [diff] [blame] | 100 | |
Heikki Krogerus | 136ced8 | 2012-02-13 13:24:19 +0200 | [diff] [blame] | 101 | return -ENOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | static inline int |
Heikki Krogerus | 6e13c65 | 2012-02-13 13:24:20 +0200 | [diff] [blame] | 105 | otg_start_srp(struct usb_otg *otg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | { |
Heikki Krogerus | 6e13c65 | 2012-02-13 13:24:20 +0200 | [diff] [blame] | 107 | if (otg && otg->start_srp) |
| 108 | return otg->start_srp(otg); |
Heikki Krogerus | 7a8a3a9 | 2012-02-13 13:24:04 +0200 | [diff] [blame] | 109 | |
Heikki Krogerus | 136ced8 | 2012-02-13 13:24:19 +0200 | [diff] [blame] | 110 | return -ENOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | /* for OTG controller drivers (and maybe other stuff) */ |
| 114 | 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] | 115 | |
Michael Grzeschik | 1c9af65 | 2013-06-13 17:59:55 +0300 | [diff] [blame] | 116 | enum usb_dr_mode { |
| 117 | USB_DR_MODE_UNKNOWN, |
| 118 | USB_DR_MODE_HOST, |
| 119 | USB_DR_MODE_PERIPHERAL, |
| 120 | USB_DR_MODE_OTG, |
| 121 | }; |
| 122 | |
Heikki Krogerus | 06e7114 | 2015-09-21 11:14:34 +0300 | [diff] [blame] | 123 | /** |
| 124 | * usb_get_dr_mode - Get dual role mode for given device |
| 125 | * @dev: Pointer to the given device |
| 126 | * |
| 127 | * The function gets phy interface string from property 'dr_mode', |
| 128 | * and returns the correspondig enum usb_dr_mode |
| 129 | */ |
| 130 | extern enum usb_dr_mode usb_get_dr_mode(struct device *dev); |
| 131 | |
Robert P. J. Day | dda43a0 | 2008-03-07 13:45:32 -0500 | [diff] [blame] | 132 | #endif /* __LINUX_USB_OTG_H */ |