blob: 67929df86df5df44ffb3db4fd89ad0a317a6c3cd [file] [log] [blame]
Greg Kroah-Hartman41dceed2008-01-30 15:21:33 -08001/* USB OTG (On The Go) defines */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Robert P. J. Daydda43a02008-03-07 13:45:32 -05003 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * 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. Daydda43a02008-03-07 13:45:32 -05009#ifndef __LINUX_USB_OTG_H
10#define __LINUX_USB_OTG_H
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Antoine Tenart48bcc182014-10-30 18:41:15 +010012#include <linux/phy/phy.h>
Venu Byravarasude4217d2012-09-04 14:25:58 +053013#include <linux/usb/phy.h>
Felipe Balbie9a20172009-12-17 13:01:36 +020014
Heikki Krogerus7a8a3a92012-02-13 13:24:04 +020015struct usb_otg {
16 u8 default_a;
17
Antoine Tenart48bcc182014-10-30 18:41:15 +010018 struct phy *phy;
19 /* old usb_phy interface */
Antoine Tenart19c1eac2014-10-30 18:41:14 +010020 struct usb_phy *usb_phy;
Heikki Krogerus7a8a3a92012-02-13 13:24:04 +020021 struct usb_bus *host;
22 struct usb_gadget *gadget;
23
Antoine Tenarte47d9252014-10-30 18:41:13 +010024 enum usb_otg_state state;
25
Heikki Krogerus7a8a3a92012-02-13 13:24:04 +020026 /* 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
Li Jun6a88bbe2015-07-09 15:18:40 +080044/**
45 * struct usb_otg_caps - describes the otg capabilities of the device
46 * @otg_rev: The OTG revision number the device is compliant with, it's
47 * in binary-coded decimal (i.e. 2.0 is 0200H).
48 * @hnp_support: Indicates if the device supports HNP.
49 * @srp_support: Indicates if the device supports SRP.
50 * @adp_support: Indicates if the device supports ADP.
51 */
52struct usb_otg_caps {
53 u16 otg_rev;
54 bool hnp_support;
55 bool srp_support;
56 bool adp_support;
57};
58
Felipe Balbi42c0bf12013-03-07 10:39:57 +020059extern const char *usb_otg_state_string(enum usb_otg_state state);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Robert Jarzmikc2344f12009-01-24 23:54:31 -080061/* Context: can sleep */
Linus Torvalds1da177e2005-04-16 15:20:36 -070062static inline int
Heikki Krogerus6e13c652012-02-13 13:24:20 +020063otg_start_hnp(struct usb_otg *otg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064{
Heikki Krogerus6e13c652012-02-13 13:24:20 +020065 if (otg && otg->start_hnp)
66 return otg->start_hnp(otg);
Heikki Krogerus7a8a3a92012-02-13 13:24:04 +020067
Heikki Krogerus136ced82012-02-13 13:24:19 +020068 return -ENOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069}
70
Daniel Mack91c8a5a2009-10-15 17:09:34 +030071/* Context: can sleep */
72static inline int
Heikki Krogerus6e13c652012-02-13 13:24:20 +020073otg_set_vbus(struct usb_otg *otg, bool enabled)
Daniel Mack91c8a5a2009-10-15 17:09:34 +030074{
Heikki Krogerus6e13c652012-02-13 13:24:20 +020075 if (otg && otg->set_vbus)
76 return otg->set_vbus(otg, enabled);
Heikki Krogerus7a8a3a92012-02-13 13:24:04 +020077
Heikki Krogerus136ced82012-02-13 13:24:19 +020078 return -ENOTSUPP;
Daniel Mack91c8a5a2009-10-15 17:09:34 +030079}
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
81/* for HCDs */
82static inline int
Heikki Krogerus6e13c652012-02-13 13:24:20 +020083otg_set_host(struct usb_otg *otg, struct usb_bus *host)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084{
Heikki Krogerus6e13c652012-02-13 13:24:20 +020085 if (otg && otg->set_host)
86 return otg->set_host(otg, host);
Heikki Krogerus7a8a3a92012-02-13 13:24:04 +020087
Heikki Krogerus136ced82012-02-13 13:24:19 +020088 return -ENOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089}
90
Linus Torvalds1da177e2005-04-16 15:20:36 -070091/* for usb peripheral controller drivers */
Robert Jarzmikc2344f12009-01-24 23:54:31 -080092
93/* Context: can sleep */
Linus Torvalds1da177e2005-04-16 15:20:36 -070094static inline int
Heikki Krogerus6e13c652012-02-13 13:24:20 +020095otg_set_peripheral(struct usb_otg *otg, struct usb_gadget *periph)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096{
Heikki Krogerus6e13c652012-02-13 13:24:20 +020097 if (otg && otg->set_peripheral)
98 return otg->set_peripheral(otg, periph);
Heikki Krogerus7a8a3a92012-02-13 13:24:04 +020099
Heikki Krogerus136ced82012-02-13 13:24:19 +0200100 return -ENOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101}
102
103static inline int
Heikki Krogerus6e13c652012-02-13 13:24:20 +0200104otg_start_srp(struct usb_otg *otg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105{
Heikki Krogerus6e13c652012-02-13 13:24:20 +0200106 if (otg && otg->start_srp)
107 return otg->start_srp(otg);
Heikki Krogerus7a8a3a92012-02-13 13:24:04 +0200108
Heikki Krogerus136ced82012-02-13 13:24:19 +0200109 return -ENOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110}
111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112/* for OTG controller drivers (and maybe other stuff) */
113extern int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num);
Robert P. J. Daydda43a02008-03-07 13:45:32 -0500114
Michael Grzeschik1c9af652013-06-13 17:59:55 +0300115enum usb_dr_mode {
116 USB_DR_MODE_UNKNOWN,
117 USB_DR_MODE_HOST,
118 USB_DR_MODE_PERIPHERAL,
119 USB_DR_MODE_OTG,
120};
121
Heikki Krogerus06e71142015-09-21 11:14:34 +0300122/**
123 * usb_get_dr_mode - Get dual role mode for given device
124 * @dev: Pointer to the given device
125 *
126 * The function gets phy interface string from property 'dr_mode',
127 * and returns the correspondig enum usb_dr_mode
128 */
129extern enum usb_dr_mode usb_get_dr_mode(struct device *dev);
130
Robert P. J. Daydda43a02008-03-07 13:45:32 -0500131#endif /* __LINUX_USB_OTG_H */