Loading...
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Cadence USB3 and USBSSP DRD header file.
4 *
5 * Copyright (C) 2018-2020 Cadence.
6 *
7 * Author: Pawel Laszczak <pawell@cadence.com>
8 */
9#ifndef __LINUX_CDNS3_DRD
10#define __LINUX_CDNS3_DRD
11
12#include <linux/usb/otg.h>
13#include "core.h"
14
15/* DRD register interface for version v1 of cdns3 driver. */
16struct cdns3_otg_regs {
17 __le32 did;
18 __le32 rid;
19 __le32 capabilities;
20 __le32 reserved1;
21 __le32 cmd;
22 __le32 sts;
23 __le32 state;
24 __le32 reserved2;
25 __le32 ien;
26 __le32 ivect;
27 __le32 refclk;
28 __le32 tmr;
29 __le32 reserved3[4];
30 __le32 simulate;
31 __le32 override;
32 __le32 susp_ctrl;
33 __le32 phyrst_cfg;
34 __le32 anasts;
35 __le32 adp_ramp_time;
36 __le32 ctrl1;
37 __le32 ctrl2;
38};
39
40/* DRD register interface for version v0 of cdns3 driver. */
41struct cdns3_otg_legacy_regs {
42 __le32 cmd;
43 __le32 sts;
44 __le32 state;
45 __le32 refclk;
46 __le32 ien;
47 __le32 ivect;
48 __le32 reserved1[3];
49 __le32 tmr;
50 __le32 reserved2[2];
51 __le32 version;
52 __le32 capabilities;
53 __le32 reserved3[2];
54 __le32 simulate;
55 __le32 reserved4[5];
56 __le32 ctrl1;
57};
58
59/* DRD register interface for cdnsp driver */
60struct cdnsp_otg_regs {
61 __le32 did;
62 __le32 rid;
63 __le32 cfgs1;
64 __le32 cfgs2;
65 __le32 cmd;
66 __le32 sts;
67 __le32 state;
68 __le32 ien;
69 __le32 ivect;
70 __le32 tmr;
71 __le32 simulate;
72 __le32 adpbc_sts;
73 __le32 adp_ramp_time;
74 __le32 adpbc_ctrl1;
75 __le32 adpbc_ctrl2;
76 __le32 override;
77 __le32 vbusvalid_dbnc_cfg;
78 __le32 sessvalid_dbnc_cfg;
79 __le32 susp_timing_ctrl;
80};
81
82#define OTG_CDNSP_DID 0x0004034E
83
84/*
85 * Common registers interface for both CDNS3 and CDNSP version of DRD.
86 */
87struct cdns_otg_common_regs {
88 __le32 cmd;
89 __le32 sts;
90 __le32 state;
91};
92
93/*
94 * Interrupt related registers. This registers are mapped in different
95 * location for CDNSP controller.
96 */
97struct cdns_otg_irq_regs {
98 __le32 ien;
99 __le32 ivect;
100};
101
102/* CDNS_RID - bitmasks */
103#define CDNS_RID(p) ((p) & GENMASK(15, 0))
104
105/* CDNS_VID - bitmasks */
106#define CDNS_DID(p) ((p) & GENMASK(31, 0))
107
108/* OTGCMD - bitmasks */
109/* "Request the bus for Device mode. */
110#define OTGCMD_DEV_BUS_REQ BIT(0)
111/* Request the bus for Host mode */
112#define OTGCMD_HOST_BUS_REQ BIT(1)
113/* Enable OTG mode. */
114#define OTGCMD_OTG_EN BIT(2)
115/* Disable OTG mode */
116#define OTGCMD_OTG_DIS BIT(3)
117/*"Configure OTG as A-Device. */
118#define OTGCMD_A_DEV_EN BIT(4)
119/*"Configure OTG as A-Device. */
120#define OTGCMD_A_DEV_DIS BIT(5)
121/* Drop the bus for Device mod e. */
122#define OTGCMD_DEV_BUS_DROP BIT(8)
123/* Drop the bus for Host mode*/
124#define OTGCMD_HOST_BUS_DROP BIT(9)
125/* Power Down USBSS-DEV - only for CDNS3.*/
126#define OTGCMD_DEV_POWER_OFF BIT(11)
127/* Power Down CDNSXHCI - only for CDNS3. */
128#define OTGCMD_HOST_POWER_OFF BIT(12)
129
130/* OTGIEN - bitmasks */
131/* ID change interrupt enable */
132#define OTGIEN_ID_CHANGE_INT BIT(0)
133/* Vbusvalid fall detected interrupt enable.*/
134#define OTGIEN_VBUSVALID_RISE_INT BIT(4)
135/* Vbusvalid fall detected interrupt enable */
136#define OTGIEN_VBUSVALID_FALL_INT BIT(5)
137
138/* OTGSTS - bitmasks */
139/*
140 * Current value of the ID pin. It is only valid when idpullup in
141 * OTGCTRL1_TYPE register is set to '1'.
142 */
143#define OTGSTS_ID_VALUE BIT(0)
144/* Current value of the vbus_valid */
145#define OTGSTS_VBUS_VALID BIT(1)
146/* Current value of the b_sess_vld */
147#define OTGSTS_SESSION_VALID BIT(2)
148/*Device mode is active*/
149#define OTGSTS_DEV_ACTIVE BIT(3)
150/* Host mode is active. */
151#define OTGSTS_HOST_ACTIVE BIT(4)
152/* OTG Controller not ready. */
153#define OTGSTS_OTG_NRDY_MASK BIT(11)
154#define OTGSTS_OTG_NRDY(p) ((p) & OTGSTS_OTG_NRDY_MASK)
155/*
156 * Value of the strap pins for:
157 * CDNS3:
158 * 000 - no default configuration
159 * 010 - Controller initiall configured as Host
160 * 100 - Controller initially configured as Device
161 * CDNSP:
162 * 000 - No default configuration.
163 * 010 - Controller initiall configured as Host.
164 * 100 - Controller initially configured as Device.
165 */
166#define OTGSTS_STRAP(p) (((p) & GENMASK(14, 12)) >> 12)
167#define OTGSTS_STRAP_NO_DEFAULT_CFG 0x00
168#define OTGSTS_STRAP_HOST_OTG 0x01
169#define OTGSTS_STRAP_HOST 0x02
170#define OTGSTS_STRAP_GADGET 0x04
171#define OTGSTS_CDNSP_STRAP_HOST 0x01
172#define OTGSTS_CDNSP_STRAP_GADGET 0x02
173
174/* Host mode is turned on. */
175#define OTGSTS_CDNS3_XHCI_READY BIT(26)
176#define OTGSTS_CDNSP_XHCI_READY BIT(27)
177
178/* "Device mode is turned on .*/
179#define OTGSTS_CDNS3_DEV_READY BIT(27)
180#define OTGSTS_CDNSP_DEV_READY BIT(26)
181
182/* OTGSTATE- bitmasks */
183#define OTGSTATE_DEV_STATE_MASK GENMASK(2, 0)
184#define OTGSTATE_HOST_STATE_MASK GENMASK(5, 3)
185#define OTGSTATE_HOST_STATE_IDLE 0x0
186#define OTGSTATE_HOST_STATE_VBUS_FALL 0x7
187#define OTGSTATE_HOST_STATE(p) (((p) & OTGSTATE_HOST_STATE_MASK) >> 3)
188
189/* OTGREFCLK - bitmasks */
190#define OTGREFCLK_STB_CLK_SWITCH_EN BIT(31)
191
192/* OVERRIDE - bitmasks */
193#define OVERRIDE_IDPULLUP BIT(0)
194/* Only for CDNS3_CONTROLLER_V0 version */
195#define OVERRIDE_IDPULLUP_V0 BIT(24)
196/* Vbusvalid/Sesvalid override select. */
197#define OVERRIDE_SESS_VLD_SEL BIT(10)
198
199/* PHYRST_CFG - bitmasks */
200#define PHYRST_CFG_PHYRST_A_ENABLE BIT(0)
201
202#define CDNS3_ID_PERIPHERAL 1
203#define CDNS3_ID_HOST 0
204
205bool cdns_is_host(struct cdns *cdns);
206bool cdns_is_device(struct cdns *cdns);
207int cdns_get_id(struct cdns *cdns);
208int cdns_get_vbus(struct cdns *cdns);
209void cdns_clear_vbus(struct cdns *cdns);
210void cdns_set_vbus(struct cdns *cdns);
211int cdns_drd_init(struct cdns *cdns);
212int cdns_drd_exit(struct cdns *cdns);
213int cdns_drd_update_mode(struct cdns *cdns);
214int cdns_drd_gadget_on(struct cdns *cdns);
215void cdns_drd_gadget_off(struct cdns *cdns);
216int cdns_drd_host_on(struct cdns *cdns);
217void cdns_drd_host_off(struct cdns *cdns);
218bool cdns_power_is_lost(struct cdns *cdns);
219#endif /* __LINUX_CDNS3_DRD */
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Cadence USB3 DRD header file.
4 *
5 * Copyright (C) 2018-2019 Cadence.
6 *
7 * Author: Pawel Laszczak <pawell@cadence.com>
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/* DRD register interface for version v1. */
17struct 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/* DRD register interface for version v0. */
42struct 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 * Common registers interface for both version of DRD.
62 */
63struct 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/* CDNS_RID - bitmasks */
73#define CDNS_RID(p) ((p) & GENMASK(15, 0))
74
75/* CDNS_VID - bitmasks */
76#define CDNS_DID(p) ((p) & GENMASK(31, 0))
77
78/* OTGCMD - bitmasks */
79/* "Request the bus for Device mode. */
80#define OTGCMD_DEV_BUS_REQ BIT(0)
81/* Request the bus for Host mode */
82#define OTGCMD_HOST_BUS_REQ BIT(1)
83/* Enable OTG mode. */
84#define OTGCMD_OTG_EN BIT(2)
85/* Disable OTG mode */
86#define OTGCMD_OTG_DIS BIT(3)
87/*"Configure OTG as A-Device. */
88#define OTGCMD_A_DEV_EN BIT(4)
89/*"Configure OTG as A-Device. */
90#define OTGCMD_A_DEV_DIS BIT(5)
91/* Drop the bus for Device mod e. */
92#define OTGCMD_DEV_BUS_DROP BIT(8)
93/* Drop the bus for Host mode*/
94#define OTGCMD_HOST_BUS_DROP BIT(9)
95/* Power Down USBSS-DEV. */
96#define OTGCMD_DEV_POWER_OFF BIT(11)
97/* Power Down CDNSXHCI. */
98#define OTGCMD_HOST_POWER_OFF BIT(12)
99
100/* OTGIEN - bitmasks */
101/* ID change interrupt enable */
102#define OTGIEN_ID_CHANGE_INT BIT(0)
103/* Vbusvalid fall detected interrupt enable.*/
104#define OTGIEN_VBUSVALID_RISE_INT BIT(4)
105/* Vbusvalid fall detected interrupt enable */
106#define OTGIEN_VBUSVALID_FALL_INT BIT(5)
107
108/* OTGSTS - bitmasks */
109/*
110 * Current value of the ID pin. It is only valid when idpullup in
111 * OTGCTRL1_TYPE register is set to '1'.
112 */
113#define OTGSTS_ID_VALUE BIT(0)
114/* Current value of the vbus_valid */
115#define OTGSTS_VBUS_VALID BIT(1)
116/* Current value of the b_sess_vld */
117#define OTGSTS_SESSION_VALID BIT(2)
118/*Device mode is active*/
119#define OTGSTS_DEV_ACTIVE BIT(3)
120/* Host mode is active. */
121#define OTGSTS_HOST_ACTIVE BIT(4)
122/* OTG Controller not ready. */
123#define OTGSTS_OTG_NRDY_MASK BIT(11)
124#define OTGSTS_OTG_NRDY(p) ((p) & OTGSTS_OTG_NRDY_MASK)
125/*
126 * Value of the strap pins.
127 * 000 - no default configuration
128 * 010 - Controller initiall configured as Host
129 * 100 - Controller initially configured as Device
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/* Host mode is turned on. */
137#define OTGSTS_XHCI_READY BIT(26)
138/* "Device mode is turned on .*/
139#define OTGSTS_DEV_READY BIT(27)
140
141/* OTGSTATE- bitmasks */
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/* OTGREFCLK - bitmasks */
149#define OTGREFCLK_STB_CLK_SWITCH_EN BIT(31)
150
151/* OVERRIDE - bitmasks */
152#define OVERRIDE_IDPULLUP BIT(0)
153/* Only for CDNS3_CONTROLLER_V0 version */
154#define OVERRIDE_IDPULLUP_V0 BIT(24)
155
156int cdns3_is_host(struct cdns3 *cdns);
157int cdns3_is_device(struct cdns3 *cdns);
158int cdns3_get_id(struct cdns3 *cdns);
159int cdns3_get_vbus(struct cdns3 *cdns);
160int cdns3_drd_init(struct cdns3 *cdns);
161int cdns3_drd_exit(struct cdns3 *cdns);
162int cdns3_drd_update_mode(struct cdns3 *cdns);
163int cdns3_drd_switch_gadget(struct cdns3 *cdns, int on);
164int cdns3_drd_switch_host(struct cdns3 *cdns, int on);
165int cdns3_set_mode(struct cdns3 *cdns, enum usb_dr_mode mode);
166
167#endif /* __LINUX_CDNS3_DRD */