0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef __LINUX_CDNS3_DRD
0010 #define __LINUX_CDNS3_DRD
0011
0012 #include <linux/usb/otg.h>
0013 #include "core.h"
0014
0015
0016 struct cdns3_otg_regs {
0017 __le32 did;
0018 __le32 rid;
0019 __le32 capabilities;
0020 __le32 reserved1;
0021 __le32 cmd;
0022 __le32 sts;
0023 __le32 state;
0024 __le32 reserved2;
0025 __le32 ien;
0026 __le32 ivect;
0027 __le32 refclk;
0028 __le32 tmr;
0029 __le32 reserved3[4];
0030 __le32 simulate;
0031 __le32 override;
0032 __le32 susp_ctrl;
0033 __le32 phyrst_cfg;
0034 __le32 anasts;
0035 __le32 adp_ramp_time;
0036 __le32 ctrl1;
0037 __le32 ctrl2;
0038 };
0039
0040
0041 struct cdns3_otg_legacy_regs {
0042 __le32 cmd;
0043 __le32 sts;
0044 __le32 state;
0045 __le32 refclk;
0046 __le32 ien;
0047 __le32 ivect;
0048 __le32 reserved1[3];
0049 __le32 tmr;
0050 __le32 reserved2[2];
0051 __le32 version;
0052 __le32 capabilities;
0053 __le32 reserved3[2];
0054 __le32 simulate;
0055 __le32 reserved4[5];
0056 __le32 ctrl1;
0057 };
0058
0059
0060 struct cdnsp_otg_regs {
0061 __le32 did;
0062 __le32 rid;
0063 __le32 cfgs1;
0064 __le32 cfgs2;
0065 __le32 cmd;
0066 __le32 sts;
0067 __le32 state;
0068 __le32 ien;
0069 __le32 ivect;
0070 __le32 tmr;
0071 __le32 simulate;
0072 __le32 adpbc_sts;
0073 __le32 adp_ramp_time;
0074 __le32 adpbc_ctrl1;
0075 __le32 adpbc_ctrl2;
0076 __le32 override;
0077 __le32 vbusvalid_dbnc_cfg;
0078 __le32 sessvalid_dbnc_cfg;
0079 __le32 susp_timing_ctrl;
0080 };
0081
0082 #define OTG_CDNSP_DID 0x0004034E
0083
0084
0085
0086
0087 struct cdns_otg_common_regs {
0088 __le32 cmd;
0089 __le32 sts;
0090 __le32 state;
0091 };
0092
0093
0094
0095
0096
0097 struct cdns_otg_irq_regs {
0098 __le32 ien;
0099 __le32 ivect;
0100 };
0101
0102
0103 #define CDNS_RID(p) ((p) & GENMASK(15, 0))
0104
0105
0106 #define CDNS_DID(p) ((p) & GENMASK(31, 0))
0107
0108
0109
0110 #define OTGCMD_DEV_BUS_REQ BIT(0)
0111
0112 #define OTGCMD_HOST_BUS_REQ BIT(1)
0113
0114 #define OTGCMD_OTG_EN BIT(2)
0115
0116 #define OTGCMD_OTG_DIS BIT(3)
0117
0118 #define OTGCMD_A_DEV_EN BIT(4)
0119
0120 #define OTGCMD_A_DEV_DIS BIT(5)
0121
0122 #define OTGCMD_DEV_BUS_DROP BIT(8)
0123
0124 #define OTGCMD_HOST_BUS_DROP BIT(9)
0125
0126 #define OTGCMD_DEV_POWER_OFF BIT(11)
0127
0128 #define OTGCMD_HOST_POWER_OFF BIT(12)
0129
0130
0131
0132 #define OTGIEN_ID_CHANGE_INT BIT(0)
0133
0134 #define OTGIEN_VBUSVALID_RISE_INT BIT(4)
0135
0136 #define OTGIEN_VBUSVALID_FALL_INT BIT(5)
0137
0138
0139
0140
0141
0142
0143 #define OTGSTS_ID_VALUE BIT(0)
0144
0145 #define OTGSTS_VBUS_VALID BIT(1)
0146
0147 #define OTGSTS_SESSION_VALID BIT(2)
0148
0149 #define OTGSTS_DEV_ACTIVE BIT(3)
0150
0151 #define OTGSTS_HOST_ACTIVE BIT(4)
0152
0153 #define OTGSTS_OTG_NRDY_MASK BIT(11)
0154 #define OTGSTS_OTG_NRDY(p) ((p) & OTGSTS_OTG_NRDY_MASK)
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166 #define OTGSTS_STRAP(p) (((p) & GENMASK(14, 12)) >> 12)
0167 #define OTGSTS_STRAP_NO_DEFAULT_CFG 0x00
0168 #define OTGSTS_STRAP_HOST_OTG 0x01
0169 #define OTGSTS_STRAP_HOST 0x02
0170 #define OTGSTS_STRAP_GADGET 0x04
0171 #define OTGSTS_CDNSP_STRAP_HOST 0x01
0172 #define OTGSTS_CDNSP_STRAP_GADGET 0x02
0173
0174
0175 #define OTGSTS_CDNS3_XHCI_READY BIT(26)
0176 #define OTGSTS_CDNSP_XHCI_READY BIT(27)
0177
0178
0179 #define OTGSTS_CDNS3_DEV_READY BIT(27)
0180 #define OTGSTS_CDNSP_DEV_READY BIT(26)
0181
0182
0183 #define OTGSTATE_DEV_STATE_MASK GENMASK(2, 0)
0184 #define OTGSTATE_HOST_STATE_MASK GENMASK(5, 3)
0185 #define OTGSTATE_HOST_STATE_IDLE 0x0
0186 #define OTGSTATE_HOST_STATE_VBUS_FALL 0x7
0187 #define OTGSTATE_HOST_STATE(p) (((p) & OTGSTATE_HOST_STATE_MASK) >> 3)
0188
0189
0190 #define OTGREFCLK_STB_CLK_SWITCH_EN BIT(31)
0191
0192
0193 #define OVERRIDE_IDPULLUP BIT(0)
0194
0195 #define OVERRIDE_IDPULLUP_V0 BIT(24)
0196
0197 #define OVERRIDE_SESS_VLD_SEL BIT(10)
0198
0199
0200 #define PHYRST_CFG_PHYRST_A_ENABLE BIT(0)
0201
0202 #define CDNS3_ID_PERIPHERAL 1
0203 #define CDNS3_ID_HOST 0
0204
0205 bool cdns_is_host(struct cdns *cdns);
0206 bool cdns_is_device(struct cdns *cdns);
0207 int cdns_get_id(struct cdns *cdns);
0208 int cdns_get_vbus(struct cdns *cdns);
0209 void cdns_clear_vbus(struct cdns *cdns);
0210 void cdns_set_vbus(struct cdns *cdns);
0211 int cdns_drd_init(struct cdns *cdns);
0212 int cdns_drd_exit(struct cdns *cdns);
0213 int cdns_drd_update_mode(struct cdns *cdns);
0214 int cdns_drd_gadget_on(struct cdns *cdns);
0215 void cdns_drd_gadget_off(struct cdns *cdns);
0216 int cdns_drd_host_on(struct cdns *cdns);
0217 void cdns_drd_host_off(struct cdns *cdns);
0218 bool cdns_power_is_lost(struct cdns *cdns);
0219 #endif