| 1 |
|
| 2 |
|
| 3 |
#include <console/console.h> |
| 4 |
#include <device/mmio.h> |
| 5 |
#include <soc/usb/usb.h> |
| 6 |
#include <soc/addressmap.h> |
| 7 |
#include <soc/clock.h> |
| 8 |
#include <delay.h> |
| 9 |
#include <gpio.h> |
| 10 |
|
| 11 |
struct usb_dwc3 { |
| 12 |
u32 sbuscfg0; |
| 13 |
u32 sbuscfg1; |
| 14 |
u32 txthrcfg; |
| 15 |
u32 rxthrcfg; |
| 16 |
u32 ctl; |
| 17 |
u32 pmsts; |
| 18 |
u32 sts; |
| 19 |
u32 uctl1; |
| 20 |
u32 snpsid; |
| 21 |
u32 gpio; |
| 22 |
u32 uid; |
| 23 |
u32 uctl; |
| 24 |
u64 buserraddr; |
| 25 |
u64 prtbimap; |
| 26 |
u8 reserved1[32]; |
| 27 |
u32 dbgfifospace; |
| 28 |
u32 dbgltssm; |
| 29 |
u32 dbglnmcc; |
| 30 |
u32 dbgbmu; |
| 31 |
u32 dbglspmux; |
| 32 |
u32 dbglsp; |
| 33 |
u32 dbgepinfo0; |
| 34 |
u32 dbgepinfo1; |
| 35 |
u64 prtbimap_hs; |
| 36 |
u64 prtbimap_fs; |
| 37 |
u8 reserved2[112]; |
| 38 |
u32 usb2phycfg; |
| 39 |
u32 usb2phycfg_mp1; |
| 40 |
u8 reserved3[120]; |
| 41 |
u32 usb2phyacc; |
| 42 |
u8 reserved4[60]; |
| 43 |
u32 usb3pipectl; |
| 44 |
u32 usb3pipectl_mp1; |
| 45 |
u8 reserved5[56]; |
| 46 |
}; |
| 47 |
check_member(usb_dwc3, usb2phycfg_mp1, 0x104); |
| 48 |
check_member(usb_dwc3, usb3pipectl_mp1, 0x1c4); |
| 49 |
|
| 50 |
struct usb_dwc3_cfg { |
| 51 |
struct usb_dwc3 *usb_host_dwc3; |
| 52 |
u32 *usb3_bcr; |
| 53 |
u32 *qusb2phy_bcr; |
| 54 |
u32 *qusb2phy1_bcr; |
| 55 |
u32 *gcc_usb3phy_bcr_reg; |
| 56 |
u32 *gcc_qmpphy_bcr_reg; |
| 57 |
u32 *gcc_usb3phy1_bcr_reg; |
| 58 |
u32 *gcc_qmpphy1_bcr_reg; |
| 59 |
u32 *qusb2secphy_bcr; |
| 60 |
u32 *gcc_usb3secphy_bcr_reg; |
| 61 |
u32 *gcc_qmpsecphy_bcr_reg; |
| 62 |
}; |
| 63 |
|
| 64 |
static struct usb_dwc3_cfg usb_port0 = { |
| 65 |
.usb_host_dwc3 = (void *)USB_HOST_DWC3_BASE, |
| 66 |
.usb3_bcr = &gcc->gcc_usb30_mp_bcr, |
| 67 |
.qusb2phy_bcr = &gcc->qusb2phy_hs0_mp_bcr, |
| 68 |
.gcc_usb3phy_bcr_reg = &gcc->usb3uniphy_phy_mp0_bcr, |
| 69 |
.gcc_qmpphy_bcr_reg = &gcc->usb3_uniphy_mp0_bcr, |
| 70 |
.qusb2phy1_bcr = &gcc->qusb2phy_hs1_mp_bcr, |
| 71 |
.gcc_usb3phy1_bcr_reg = &gcc->usb3uniphy_phy_mp1_bcr, |
| 72 |
.gcc_qmpphy1_bcr_reg = &gcc->usb3_uniphy_mp1_bcr, |
| 73 |
}; |
| 74 |
|
| 75 |
bool hs_speed_only = false; |
| 76 |
u32 *usb3_general_cfg_addr = (void *)USB_HOST_DWC3_GENERAL_CFG_ADDR; |
| 77 |
|
| 78 |
|
| 79 |
void enable_clock_tcsr(void) |
| 80 |
{ |
| 81 |
write32(TCSR_GCC_CXO_1_REFGEN_BIAS_SEL__SEL_REFGEN_ADDR, 0x00000001); |
| 82 |
write32(TCSR_GCC_CXO_0_REFGEN_BIAS_SEL__SEL_REFGEN_ADDR, 0x00000001); |
| 83 |
|
| 84 |
write32(TCSR_QREFS_CXO_0_RPT3_CONFIG_ADDR, 0x3); |
| 85 |
write32(TCSR_QREFS_CXO_0_RPT4_CONFIG_ADDR, 0x3); |
| 86 |
write32(TCSR_QREFS_CXO_1_RPT0_CONFIG_ADDR, 0x3); |
| 87 |
write32(TCSR_QREFS_CXO_1_RX3_CONFIG_ADDR, 0x3); |
| 88 |
write32(TCSR_QREFS_CXO_1_RX0_CONFIG_ADDR, 0x3); |
| 89 |
write32(TCSR_QREFS_CXO_0_RX3_CONFIG_ADDR, 0x3); |
| 90 |
write32(TCSR_QREFS_CXO_0_RX4_CONFIG_ADDR, 0x3); |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
int32_t qcom_enable_usb_clk(void) |
| 97 |
{ |
| 98 |
int32_t ret, clk, gdsc; |
| 99 |
|
| 100 |
|
| 101 |
for (gdsc = USB30_MP_GDSC; gdsc < MAX_USB_GDSC; gdsc++) { |
| 102 |
ret = clock_enable_usb_gdsc(gdsc); |
| 103 |
if (ret) { |
| 104 |
printk(BIOS_ERR, "Failed to enable USB GDSC %d\n", gdsc); |
| 105 |
return ret; |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
clock_configure_usb(); |
| 110 |
|
| 111 |
if (usb_clock_configure_mux(USB3_PHY_PIPE_0, USB_PHY_XO_SRC_SEL)) { |
| 112 |
printk(BIOS_ERR, "%s(): USB3 PHY PIPE 0 clock enable failed\n", __func__); |
| 113 |
return -1; |
| 114 |
} |
| 115 |
if (usb_clock_configure_mux(USB3_PHY_PIPE_1, USB_PHY_XO_SRC_SEL)) { |
| 116 |
printk(BIOS_ERR, "%s(): USB3 PHY PIPE 0 clock enable failed\n", __func__); |
| 117 |
return -1; |
| 118 |
} |
| 119 |
|
| 120 |
for (clk = USB30_MP_MASTER_CBCR; clk < USB_CLK_COUNT; clk++) { |
| 121 |
ret = usb_clock_enable(clk); |
| 122 |
if (ret) { |
| 123 |
printk(BIOS_ERR, "Failed to enable %d clock\n", clk); |
| 124 |
return ret; |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
write32(TCSR_GCC_USB3_MP0_CLKREF_EN_ADDR, USB3_CLKREF_ENABLE_VALUE); |
| 129 |
write32(TCSR_GCC_USB3_MP1_CLKREF_EN_ADDR, USB3_CLKREF_ENABLE_VALUE); |
| 130 |
|
| 131 |
|
| 132 |
if (usb_clock_configure_mux(USB3_PHY_PIPE_0, USB_PHY_PIPE_SRC_SEL)) { |
| 133 |
printk(BIOS_ERR, "%s(): USB3 PHY PIPE 1 clock enable failed\n", __func__); |
| 134 |
return -1; |
| 135 |
} |
| 136 |
|
| 137 |
if (usb_clock_configure_mux(USB3_PHY_PIPE_1, USB_PHY_PIPE_SRC_SEL)) { |
| 138 |
printk(BIOS_ERR, "%s(): USB3 PHY PIPE 1 clock enable failed\n", __func__); |
| 139 |
return -1; |
| 140 |
} |
| 141 |
|
| 142 |
return ret; |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
static void setup_dwc3(struct usb_dwc3 *dwc3) |
| 152 |
{ |
| 153 |
u32 *reg = usb3_general_cfg_addr; |
| 154 |
if (hs_speed_only) { |
| 155 |
|
| 156 |
setbits32(reg, UTMI_CLK_DIS_0); |
| 157 |
udelay(10); |
| 158 |
|
| 159 |
|
| 160 |
setbits32(reg, UTMI_CLK_SEL_0); |
| 161 |
|
| 162 |
|
| 163 |
setbits32(reg, PIPE3_PHYSTATUS_SW_0); |
| 164 |
|
| 165 |
|
| 166 |
clrbits32(reg, PIPE3_SET_PHYSTATUS_SW_0); |
| 167 |
udelay(10); |
| 168 |
|
| 169 |
|
| 170 |
clrbits32(reg, UTMI_CLK_DIS_0); |
| 171 |
} else { |
| 172 |
|
| 173 |
clrsetbits32(&dwc3->usb3pipectl, |
| 174 |
DWC3_GUSB3PIPECTL_DELAYP1TRANS, |
| 175 |
DWC3_GUSB3PIPECTL_UX_EXIT_IN_PX); |
| 176 |
|
| 177 |
clrsetbits32(&dwc3->usb3pipectl_mp1, |
| 178 |
DWC3_GUSB3PIPECTL_DELAYP1TRANS, |
| 179 |
DWC3_GUSB3PIPECTL_UX_EXIT_IN_PX); |
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
clrsetbits32(&dwc3->usb2phycfg, |
| 188 |
(DWC3_GUSB2PHYCFG_USB2TRDTIM_MASK | |
| 189 |
DWC3_GUSB2PHYCFG_PHYIF_MASK | |
| 190 |
DWC3_GUSB2PHYCFG_ENBLSLPM_MASK), |
| 191 |
(DWC3_GUSB2PHYCFG_PHYIF(UTMI_PHYIF_8_BIT) | |
| 192 |
DWC3_GUSB2PHYCFG_USBTRDTIM(USBTRDTIM_UTMI_8_BIT))); |
| 193 |
|
| 194 |
clrsetbits32(&dwc3->usb2phycfg_mp1, |
| 195 |
(DWC3_GUSB2PHYCFG_USB2TRDTIM_MASK | |
| 196 |
DWC3_GUSB2PHYCFG_PHYIF_MASK | |
| 197 |
DWC3_GUSB2PHYCFG_ENBLSLPM_MASK), |
| 198 |
(DWC3_GUSB2PHYCFG_PHYIF(UTMI_PHYIF_8_BIT) | |
| 199 |
DWC3_GUSB2PHYCFG_USBTRDTIM(USBTRDTIM_UTMI_8_BIT))); |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
setbits32(USB3_MP_CGCTL_REG_ADDR, USB3_MP_DBM_FSM_EN_BIT); |
| 205 |
|
| 206 |
clrsetbits32(&dwc3->ctl, (DWC3_GCTL_SCALEDOWN_MASK | |
| 207 |
DWC3_GCTL_DISSCRAMBLE), |
| 208 |
DWC3_GCTL_U2EXIT_LFPS | DWC3_GCTL_DSBLCLKGTNG); |
| 209 |
|
| 210 |
|
| 211 |
setbits32(&dwc3->usb3pipectl, |
| 212 |
(DWC3_GUSB3PIPECTL_P3EXSIGP2| |
| 213 |
DWC3_GUSB3PIPECTL_UX_EXIT_IN_PX)); |
| 214 |
|
| 215 |
setbits32(&dwc3->usb3pipectl_mp1, |
| 216 |
(DWC3_GUSB3PIPECTL_P3EXSIGP2| |
| 217 |
DWC3_GUSB3PIPECTL_UX_EXIT_IN_PX)); |
| 218 |
|
| 219 |
|
| 220 |
clrsetbits32(USB3_MP_LINK_REGS_0_LU3LFPSRXTIM_ADDR, |
| 221 |
LFPS_RSP_RX_CLK_CLR_MASK, LFPS_RSP_RX_CLK_SET_MASK); |
| 222 |
|
| 223 |
clrsetbits32(USB3_MP_LINK_REGS_1_LU3LFPSRXTIM_ADDR, |
| 224 |
LFPS_RSP_RX_CLK_CLR_MASK, LFPS_RSP_RX_CLK_SET_MASK); |
| 225 |
|
| 226 |
clrsetbits32(&dwc3->uctl1, |
| 227 |
DWC3_GUCTL1_CLR_MASK, |
| 228 |
DWC3_GUCTL1_SET_MASK); |
| 229 |
|
| 230 |
clrbits32(USB3_MP_GUSB2PHYCFG_REGS_0_ADDR, GUSB2PHYCFG_ENBLSLPM_BIT); |
| 231 |
|
| 232 |
clrbits32(USB3_MP_GUSB2PHYCFG_REGS_1_ADDR, GUSB2PHYCFG_ENBLSLPM_BIT); |
| 233 |
|
| 234 |
|
| 235 |
clrsetbits32(&dwc3->ctl, (DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG)), |
| 236 |
DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_HOST)); |
| 237 |
printk(BIOS_SPEW, "Configure USB in Host mode\n"); |
| 238 |
|
| 239 |
setbits32(USB3_MP_PORTSC_20_REGS_0_ADDR, USB3_PORTSC_WCE_BIT); |
| 240 |
|
| 241 |
setbits32(USB3_MP_PORTSC_20_REGS_1_ADDR, USB3_PORTSC_WCE_BIT); |
| 242 |
|
| 243 |
setbits32(USB3_MP_PORTSC_30_REGS_0_ADDR, USB3_PORTSC_WCE_BIT); |
| 244 |
|
| 245 |
setbits32(USB3_MP_PORTSC_30_REGS_1_ADDR, USB3_PORTSC_WCE_BIT); |
| 246 |
|
| 247 |
} |
| 248 |
|
| 249 |
|
| 250 |
static void setup_usb_host(struct usb_dwc3_cfg *dwc3) |
| 251 |
{ |
| 252 |
|
| 253 |
qcom_enable_usb_clk(); |
| 254 |
|
| 255 |
enable_clock_tcsr(); |
| 256 |
|
| 257 |
|
| 258 |
clock_reset_bcr(dwc3->usb3_bcr, 1); |
| 259 |
udelay(10); |
| 260 |
clock_reset_bcr(dwc3->usb3_bcr, 0); |
| 261 |
udelay(10); |
| 262 |
|
| 263 |
|
| 264 |
gpio_output(GPIO(6), 0x1); |
| 265 |
|
| 266 |
|
| 267 |
gpio_output(GPIO(184), 0x1); |
| 268 |
|
| 269 |
|
| 270 |
clock_reset_bcr(dwc3->qusb2phy_bcr, 1); |
| 271 |
clock_reset_bcr(dwc3->qusb2phy1_bcr, 1); |
| 272 |
udelay(10); |
| 273 |
clock_reset_bcr(dwc3->qusb2phy_bcr, 0); |
| 274 |
clock_reset_bcr(dwc3->qusb2phy1_bcr, 0); |
| 275 |
|
| 276 |
|
| 277 |
hs_usb_phy_init(0); |
| 278 |
hs_usb_phy_init(1); |
| 279 |
|
| 280 |
|
| 281 |
usb_clock_reset(USB3_MP_PHY_PIPE_0_CBCR, 1); |
| 282 |
usb_clock_reset(USB3_MP_PHY_PIPE_1_CBCR, 1); |
| 283 |
udelay(10); |
| 284 |
|
| 285 |
usb_clock_reset(USB30_MP_MASTER_CBCR, 1); |
| 286 |
usb_clock_reset(USB30_MP_MASTER_CBCR, 0); |
| 287 |
udelay(10); |
| 288 |
|
| 289 |
clock_reset_bcr(dwc3->gcc_usb3phy_bcr_reg, 1); |
| 290 |
clock_reset_bcr(dwc3->gcc_qmpphy_bcr_reg, 1); |
| 291 |
|
| 292 |
clock_reset_bcr(dwc3->gcc_usb3phy1_bcr_reg, 1); |
| 293 |
clock_reset_bcr(dwc3->gcc_qmpphy1_bcr_reg, 1); |
| 294 |
udelay(10); |
| 295 |
|
| 296 |
clock_reset_bcr(dwc3->gcc_usb3phy_bcr_reg, 0); |
| 297 |
clock_reset_bcr(dwc3->gcc_qmpphy_bcr_reg, 0); |
| 298 |
|
| 299 |
clock_reset_bcr(dwc3->gcc_usb3phy1_bcr_reg, 0); |
| 300 |
clock_reset_bcr(dwc3->gcc_qmpphy1_bcr_reg, 0); |
| 301 |
udelay(10); |
| 302 |
|
| 303 |
usb_clock_reset(USB3_MP_PHY_PIPE_0_CBCR, 0); |
| 304 |
usb_clock_reset(USB3_MP_PHY_PIPE_1_CBCR, 0); |
| 305 |
|
| 306 |
|
| 307 |
bool ret0 = ss_qmp_phy_init(0); |
| 308 |
bool ret1 = ss_qmp_phy_init(1); |
| 309 |
|
| 310 |
|
| 311 |
if (!ret0 || !ret1) |
| 312 |
hs_speed_only = true; |
| 313 |
|
| 314 |
setup_dwc3(dwc3->usb_host_dwc3); |
| 315 |
|
| 316 |
printk(BIOS_INFO, "DWC3 and PHY setup finished\n"); |
| 317 |
} |
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
void setup_usb_host0(void) |
| 324 |
{ |
| 325 |
printk(BIOS_INFO, "Setting up USB HOST0 controller.\n"); |
| 326 |
setup_usb_host(&usb_port0); |
| 327 |
} |