Skip to content

Commit 91c8a5a

Browse files
Daniel Mackgregkh
authored andcommitted
USB OTG: add support for ulpi connected external transceivers
This adds support for OTG transceivers directly connected to the ULPI interface. In particular, the following details are added - a struct for low level io functions (read/write) - a priv field to be used as 'viewport' by low level access functions - an (*init) and (*shutdown) callbacks, along with static inline helpers - a (*set_vbus) callback to switch the port power on and off - a flags field for per-transceiver settings - some defines for the flags bitmask to configure platform specific details Signed-off-by: Daniel Mack <daniel@caiaq.de> Cc: Heikki Krogerus <ext-heikki.krogerus@nokia.com> Cc: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent c3f22d9 commit 91c8a5a

1 file changed

Lines changed: 67 additions & 1 deletion

File tree

‎include/linux/usb/otg.h‎

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,23 @@ enum usb_otg_state {
3333
OTG_STATE_A_VBUS_ERR,
3434
};
3535

36+
#define USB_OTG_PULLUP_ID (1 << 0)
37+
#define USB_OTG_PULLDOWN_DP (1 << 1)
38+
#define USB_OTG_PULLDOWN_DM (1 << 2)
39+
#define USB_OTG_EXT_VBUS_INDICATOR (1 << 3)
40+
#define USB_OTG_DRV_VBUS (1 << 4)
41+
#define USB_OTG_DRV_VBUS_EXT (1 << 5)
42+
43+
struct otg_transceiver;
44+
45+
/* for transceivers connected thru an ULPI interface, the user must
46+
* provide access ops
47+
*/
48+
struct otg_io_access_ops {
49+
int (*read)(struct otg_transceiver *otg, u32 reg);
50+
int (*write)(struct otg_transceiver *otg, u32 val, u32 reg);
51+
};
52+
3653
/*
3754
* the otg driver needs to interact with both device side and host side
3855
* usb controllers. it decides which controller is active at a given
@@ -42,17 +59,25 @@ enum usb_otg_state {
4259
struct otg_transceiver {
4360
struct device *dev;
4461
const char *label;
62+
unsigned int flags;
4563

4664
u8 default_a;
4765
enum usb_otg_state state;
4866

4967
struct usb_bus *host;
5068
struct usb_gadget *gadget;
5169

70+
struct otg_io_access_ops *io_ops;
71+
void __iomem *io_priv;
72+
5273
/* to pass extra port status to the root hub */
5374
u16 port_status;
5475
u16 port_change;
5576

77+
/* initialize/shutdown the OTG controller */
78+
int (*init)(struct otg_transceiver *otg);
79+
void (*shutdown)(struct otg_transceiver *otg);
80+
5681
/* bind/unbind the host controller */
5782
int (*set_host)(struct otg_transceiver *otg,
5883
struct usb_bus *host);
@@ -65,6 +90,10 @@ struct otg_transceiver {
6590
int (*set_power)(struct otg_transceiver *otg,
6691
unsigned mA);
6792

93+
/* effective for A-peripheral, ignored for B devices */
94+
int (*set_vbus)(struct otg_transceiver *otg,
95+
bool enabled);
96+
6897
/* for non-OTG B devices: set transceiver into suspend mode */
6998
int (*set_suspend)(struct otg_transceiver *otg,
7099
int suspend);
@@ -85,6 +114,38 @@ extern int otg_set_transceiver(struct otg_transceiver *);
85114
extern void usb_nop_xceiv_register(void);
86115
extern void usb_nop_xceiv_unregister(void);
87116

117+
/* helpers for direct access thru low-level io interface */
118+
static inline int otg_io_read(struct otg_transceiver *otg, u32 reg)
119+
{
120+
if (otg->io_ops && otg->io_ops->read)
121+
return otg->io_ops->read(otg, reg);
122+
123+
return -EINVAL;
124+
}
125+
126+
static inline int otg_io_write(struct otg_transceiver *otg, u32 reg, u32 val)
127+
{
128+
if (otg->io_ops && otg->io_ops->write)
129+
return otg->io_ops->write(otg, reg, val);
130+
131+
return -EINVAL;
132+
}
133+
134+
static inline int
135+
otg_init(struct otg_transceiver *otg)
136+
{
137+
if (otg->init)
138+
return otg->init(otg);
139+
140+
return 0;
141+
}
142+
143+
static inline void
144+
otg_shutdown(struct otg_transceiver *otg)
145+
{
146+
if (otg->shutdown)
147+
otg->shutdown(otg);
148+
}
88149

89150
/* for usb host and peripheral controller drivers */
90151
extern struct otg_transceiver *otg_get_transceiver(void);
@@ -97,6 +158,12 @@ otg_start_hnp(struct otg_transceiver *otg)
97158
return otg->start_hnp(otg);
98159
}
99160

161+
/* Context: can sleep */
162+
static inline int
163+
otg_set_vbus(struct otg_transceiver *otg, bool enabled)
164+
{
165+
return otg->set_vbus(otg, enabled);
166+
}
100167

101168
/* for HCDs */
102169
static inline int
@@ -105,7 +172,6 @@ otg_set_host(struct otg_transceiver *otg, struct usb_bus *host)
105172
return otg->set_host(otg, host);
106173
}
107174

108-
109175
/* for usb peripheral controller drivers */
110176

111177
/* Context: can sleep */

0 commit comments

Comments
 (0)