1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Cadence USB3 DRD header file.
5 * Copyright (C) 2018-2019 Cadence.
7 * Author: Pawel Laszczak <pawell@cadence.com>
9 #ifndef __LINUX_CDNS3_DRD
10 #define __LINUX_CDNS3_DRD
12 #include <linux/bitops.h>
13 #include <linux/types.h>
14 #include <linux/usb/otg.h>
17 /* DRD register interface for version v1. */
18 struct cdns3_otg_regs {
42 /* DRD register interface for version v0. */
43 struct cdns3_otg_legacy_regs {
62 * Common registers interface for both version of DRD.
64 struct cdns3_otg_common_regs {
73 /* CDNS_RID - bitmasks */
74 #define CDNS_RID(p) ((p) & GENMASK(15, 0))
76 /* CDNS_VID - bitmasks */
77 #define CDNS_DID(p) ((p) & GENMASK(31, 0))
79 /* OTGCMD - bitmasks */
80 /* "Request the bus for Device mode. */
81 #define OTGCMD_DEV_BUS_REQ BIT(0)
82 /* Request the bus for Host mode */
83 #define OTGCMD_HOST_BUS_REQ BIT(1)
84 /* Enable OTG mode. */
85 #define OTGCMD_OTG_EN BIT(2)
86 /* Disable OTG mode */
87 #define OTGCMD_OTG_DIS BIT(3)
88 /*"Configure OTG as A-Device. */
89 #define OTGCMD_A_DEV_EN BIT(4)
90 /*"Configure OTG as A-Device. */
91 #define OTGCMD_A_DEV_DIS BIT(5)
92 /* Drop the bus for Device mod e. */
93 #define OTGCMD_DEV_BUS_DROP BIT(8)
94 /* Drop the bus for Host mode*/
95 #define OTGCMD_HOST_BUS_DROP BIT(9)
96 /* Power Down USBSS-DEV. */
97 #define OTGCMD_DEV_POWER_OFF BIT(11)
98 /* Power Down CDNSXHCI. */
99 #define OTGCMD_HOST_POWER_OFF BIT(12)
101 /* OTGIEN - bitmasks */
102 /* ID change interrupt enable */
103 #define OTGIEN_ID_CHANGE_INT BIT(0)
104 /* Vbusvalid fall detected interrupt enable.*/
105 #define OTGIEN_VBUSVALID_RISE_INT BIT(4)
106 /* Vbusvalid fall detected interrupt enable */
107 #define OTGIEN_VBUSVALID_FALL_INT BIT(5)
109 /* OTGSTS - bitmasks */
111 * Current value of the ID pin. It is only valid when idpullup in
112 * OTGCTRL1_TYPE register is set to '1'.
114 #define OTGSTS_ID_VALUE BIT(0)
115 /* Current value of the vbus_valid */
116 #define OTGSTS_VBUS_VALID BIT(1)
117 /* Current value of the b_sess_vld */
118 #define OTGSTS_SESSION_VALID BIT(2)
119 /*Device mode is active*/
120 #define OTGSTS_DEV_ACTIVE BIT(3)
121 /* Host mode is active. */
122 #define OTGSTS_HOST_ACTIVE BIT(4)
123 /* OTG Controller not ready. */
124 #define OTGSTS_OTG_NRDY_MASK BIT(11)
125 #define OTGSTS_OTG_NRDY(p) ((p) & OTGSTS_OTG_NRDY_MASK)
127 * Value of the strap pins.
128 * 000 - no default configuration
129 * 010 - Controller initiall configured as Host
130 * 100 - Controller initially configured as Device
132 #define OTGSTS_STRAP(p) (((p) & GENMASK(14, 12)) >> 12)
133 #define OTGSTS_STRAP_NO_DEFAULT_CFG 0x00
134 #define OTGSTS_STRAP_HOST_OTG 0x01
135 #define OTGSTS_STRAP_HOST 0x02
136 #define OTGSTS_STRAP_GADGET 0x04
137 /* Host mode is turned on. */
138 #define OTGSTS_XHCI_READY BIT(26)
139 /* "Device mode is turned on .*/
140 #define OTGSTS_DEV_READY BIT(27)
142 /* OTGSTATE- bitmasks */
143 #define OTGSTATE_DEV_STATE_MASK GENMASK(2, 0)
144 #define OTGSTATE_HOST_STATE_MASK GENMASK(5, 3)
145 #define OTGSTATE_HOST_STATE_IDLE 0x0
146 #define OTGSTATE_HOST_STATE_VBUS_FALL 0x7
147 #define OTGSTATE_HOST_STATE(p) (((p) & OTGSTATE_HOST_STATE_MASK) >> 3)
149 /* OTGREFCLK - bitmasks */
150 #define OTGREFCLK_STB_CLK_SWITCH_EN BIT(31)
152 /* OVERRIDE - bitmasks */
153 #define OVERRIDE_IDPULLUP BIT(0)
154 /* Only for CDNS3_CONTROLLER_V0 version */
155 #define OVERRIDE_IDPULLUP_V0 BIT(24)
157 int cdns3_is_host(struct cdns3 *cdns);
158 int cdns3_is_device(struct cdns3 *cdns);
159 int cdns3_get_id(struct cdns3 *cdns);
160 int cdns3_get_vbus(struct cdns3 *cdns);
161 int cdns3_drd_init(struct cdns3 *cdns);
162 int cdns3_drd_exit(struct cdns3 *cdns);
163 int cdns3_drd_update_mode(struct cdns3 *cdns);
164 int cdns3_drd_switch_gadget(struct cdns3 *cdns, int on);
165 int cdns3_drd_switch_host(struct cdns3 *cdns, int on);
167 #endif /* __LINUX_CDNS3_DRD */