blob: 69f1b63285323b106491487ed5a1a6105af7339e [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Greg Kroah-Hartman41dceed2008-01-30 15:21:33 -08002/* USB OTG (On The Go) defines */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003/*
Robert P. J. Daydda43a02008-03-07 13:45:32 -05004 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * 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. Daydda43a02008-03-07 13:45:32 -050010#ifndef __LINUX_USB_OTG_H
11#define __LINUX_USB_OTG_H
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
Antoine Tenart48bcc182014-10-30 18:41:15 +010013#include <linux/phy/phy.h>
Venu Byravarasude4217d2012-09-04 14:25:58 +053014#include <linux/usb/phy.h>
Felipe Balbie9a20172009-12-17 13:01:36 +020015
Heikki Krogerus7a8a3a92012-02-13 13:24:04 +020016struct usb_otg {
17 u8 default_a;
18
Antoine Tenart48bcc182014-10-30 18:41:15 +010019 struct phy *phy;
20 /* old usb_phy interface */
Antoine Tenart19c1eac2014-10-30 18:41:14 +010021 struct usb_phy *usb_phy;
Heikki Krogerus7a8a3a92012-02-13 13:24:04 +020022 struct usb_bus *host;
23 struct usb_gadget *gadget;
24
Antoine Tenarte47d9252014-10-30 18:41:13 +010025 enum usb_otg_state state;
26
Heikki Krogerus7a8a3a92012-02-13 13:24:04 +020027 /* 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 Jun6a88bbe2015-07-09 15:18:40 +080045/**
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 */
53struct usb_otg_caps {
54 u16 otg_rev;
55 bool hnp_support;
56 bool srp_support;
57 bool adp_support;
58};
59
Felipe Balbi42c0bf12013-03-07 10:39:57 +020060extern const char *usb_otg_state_string(enum usb_otg_state state);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Robert Jarzmikc2344f12009-01-24 23:54:31 -080062/* Context: can sleep */
Linus Torvalds1da177e2005-04-16 15:20:36 -070063static inline int
Heikki Krogerus6e13c652012-02-13 13:24:20 +020064otg_start_hnp(struct usb_otg *otg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
Heikki Krogerus6e13c652012-02-13 13:24:20 +020066 if (otg && otg->start_hnp)
67 return otg->start_hnp(otg);
Heikki Krogerus7a8a3a92012-02-13 13:24:04 +020068
Heikki Krogerus136ced82012-02-13 13:24:19 +020069 return -ENOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070}
71
Daniel Mack91c8a5a2009-10-15 17:09:34 +030072/* Context: can sleep */
73static inline int
Heikki Krogerus6e13c652012-02-13 13:24:20 +020074otg_set_vbus(struct usb_otg *otg, bool enabled)
Daniel Mack91c8a5a2009-10-15 17:09:34 +030075{
Heikki Krogerus6e13c652012-02-13 13:24:20 +020076 if (otg && otg->set_vbus)
77 return otg->set_vbus(otg, enabled);
Heikki Krogerus7a8a3a92012-02-13 13:24:04 +020078
Heikki Krogerus136ced82012-02-13 13:24:19 +020079 return -ENOTSUPP;
Daniel Mack91c8a5a2009-10-15 17:09:34 +030080}
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82/* for HCDs */
83static inline int
Heikki Krogerus6e13c652012-02-13 13:24:20 +020084otg_set_host(struct usb_otg *otg, struct usb_bus *host)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085{
Heikki Krogerus6e13c652012-02-13 13:24:20 +020086 if (otg && otg->set_host)
87 return otg->set_host(otg, host);
Heikki Krogerus7a8a3a92012-02-13 13:24:04 +020088
Heikki Krogerus136ced82012-02-13 13:24:19 +020089 return -ENOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090}
91
Linus Torvalds1da177e2005-04-16 15:20:36 -070092/* for usb peripheral controller drivers */
Robert Jarzmikc2344f12009-01-24 23:54:31 -080093
94/* Context: can sleep */
Linus Torvalds1da177e2005-04-16 15:20:36 -070095static inline int
Heikki Krogerus6e13c652012-02-13 13:24:20 +020096otg_set_peripheral(struct usb_otg *otg, struct usb_gadget *periph)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097{
Heikki Krogerus6e13c652012-02-13 13:24:20 +020098 if (otg && otg->set_peripheral)
99 return otg->set_peripheral(otg, periph);
Heikki Krogerus7a8a3a92012-02-13 13:24:04 +0200100
Heikki Krogerus136ced82012-02-13 13:24:19 +0200101 return -ENOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102}
103
104static inline int
Heikki Krogerus6e13c652012-02-13 13:24:20 +0200105otg_start_srp(struct usb_otg *otg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106{
Heikki Krogerus6e13c652012-02-13 13:24:20 +0200107 if (otg && otg->start_srp)
108 return otg->start_srp(otg);
Heikki Krogerus7a8a3a92012-02-13 13:24:04 +0200109
Heikki Krogerus136ced82012-02-13 13:24:19 +0200110 return -ENOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111}
112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113/* for OTG controller drivers (and maybe other stuff) */
114extern int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num);
Robert P. J. Daydda43a02008-03-07 13:45:32 -0500115
Michael Grzeschik1c9af652013-06-13 17:59:55 +0300116enum 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 Krogerus06e71142015-09-21 11:14:34 +0300123/**
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 */
130extern enum usb_dr_mode usb_get_dr_mode(struct device *dev);
131
Robert P. J. Daydda43a02008-03-07 13:45:32 -0500132#endif /* __LINUX_USB_OTG_H */