1
2
3
4
5
6
7
8
9 #ifndef __LINUX_CDNS3_DRD
10 #define __LINUX_CDNS3_DRD
11
12 #include <linux/usb/otg.h>
13 #include <linux/phy/phy.h>
14 #include "core.h"
15
16
17 struct cdns3_otg_regs {
18 __le32 did;
19 __le32 rid;
20 __le32 capabilities;
21 __le32 reserved1;
22 __le32 cmd;
23 __le32 sts;
24 __le32 state;
25 __le32 reserved2;
26 __le32 ien;
27 __le32 ivect;
28 __le32 refclk;
29 __le32 tmr;
30 __le32 reserved3[4];
31 __le32 simulate;
32 __le32 override;
33 __le32 susp_ctrl;
34 __le32 reserved4;
35 __le32 anasts;
36 __le32 adp_ramp_time;
37 __le32 ctrl1;
38 __le32 ctrl2;
39 };
40
41
42 struct cdns3_otg_legacy_regs {
43 __le32 cmd;
44 __le32 sts;
45 __le32 state;
46 __le32 refclk;
47 __le32 ien;
48 __le32 ivect;
49 __le32 reserved1[3];
50 __le32 tmr;
51 __le32 reserved2[2];
52 __le32 version;
53 __le32 capabilities;
54 __le32 reserved3[2];
55 __le32 simulate;
56 __le32 reserved4[5];
57 __le32 ctrl1;
58 };
59
60
61
62
63 struct cdns3_otg_common_regs {
64 __le32 cmd;
65 __le32 sts;
66 __le32 state;
67 __le32 different1;
68 __le32 ien;
69 __le32 ivect;
70 };
71
72
73 #define CDNS_RID(p) ((p) & GENMASK(15, 0))
74
75
76 #define CDNS_DID(p) ((p) & GENMASK(31, 0))
77
78
79
80 #define OTGCMD_DEV_BUS_REQ BIT(0)
81
82 #define OTGCMD_HOST_BUS_REQ BIT(1)
83
84 #define OTGCMD_OTG_EN BIT(2)
85
86 #define OTGCMD_OTG_DIS BIT(3)
87
88 #define OTGCMD_A_DEV_EN BIT(4)
89
90 #define OTGCMD_A_DEV_DIS BIT(5)
91
92 #define OTGCMD_DEV_BUS_DROP BIT(8)
93
94 #define OTGCMD_HOST_BUS_DROP BIT(9)
95
96 #define OTGCMD_DEV_POWER_OFF BIT(11)
97
98 #define OTGCMD_HOST_POWER_OFF BIT(12)
99
100
101
102 #define OTGIEN_ID_CHANGE_INT BIT(0)
103
104 #define OTGIEN_VBUSVALID_RISE_INT BIT(4)
105
106 #define OTGIEN_VBUSVALID_FALL_INT BIT(5)
107
108
109
110
111
112
113 #define OTGSTS_ID_VALUE BIT(0)
114
115 #define OTGSTS_VBUS_VALID BIT(1)
116
117 #define OTGSTS_SESSION_VALID BIT(2)
118
119 #define OTGSTS_DEV_ACTIVE BIT(3)
120
121 #define OTGSTS_HOST_ACTIVE BIT(4)
122
123 #define OTGSTS_OTG_NRDY_MASK BIT(11)
124 #define OTGSTS_OTG_NRDY(p) ((p) & OTGSTS_OTG_NRDY_MASK)
125
126
127
128
129
130
131 #define OTGSTS_STRAP(p) (((p) & GENMASK(14, 12)) >> 12)
132 #define OTGSTS_STRAP_NO_DEFAULT_CFG 0x00
133 #define OTGSTS_STRAP_HOST_OTG 0x01
134 #define OTGSTS_STRAP_HOST 0x02
135 #define OTGSTS_STRAP_GADGET 0x04
136
137 #define OTGSTS_XHCI_READY BIT(26)
138
139 #define OTGSTS_DEV_READY BIT(27)
140
141
142 #define OTGSTATE_DEV_STATE_MASK GENMASK(2, 0)
143 #define OTGSTATE_HOST_STATE_MASK GENMASK(5, 3)
144 #define OTGSTATE_HOST_STATE_IDLE 0x0
145 #define OTGSTATE_HOST_STATE_VBUS_FALL 0x7
146 #define OTGSTATE_HOST_STATE(p) (((p) & OTGSTATE_HOST_STATE_MASK) >> 3)
147
148
149 #define OTGREFCLK_STB_CLK_SWITCH_EN BIT(31)
150
151
152 #define OVERRIDE_IDPULLUP BIT(0)
153
154 #define OVERRIDE_IDPULLUP_V0 BIT(24)
155
156 int cdns3_is_host(struct cdns3 *cdns);
157 int cdns3_is_device(struct cdns3 *cdns);
158 int cdns3_get_id(struct cdns3 *cdns);
159 int cdns3_get_vbus(struct cdns3 *cdns);
160 int cdns3_drd_init(struct cdns3 *cdns);
161 int cdns3_drd_exit(struct cdns3 *cdns);
162 int cdns3_drd_update_mode(struct cdns3 *cdns);
163 int cdns3_drd_switch_gadget(struct cdns3 *cdns, int on);
164 int cdns3_drd_switch_host(struct cdns3 *cdns, int on);
165 int cdns3_set_mode(struct cdns3 *cdns, enum usb_dr_mode mode);
166
167 #endif