2020-04-04 18:51:11 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2018-09-26 07:33:36 +02:00
|
|
|
|
2019-03-03 07:01:05 +01:00
|
|
|
#include <device/mmio.h>
|
2018-09-26 07:33:36 +02:00
|
|
|
#include <console/console.h>
|
|
|
|
#include <soc/addressmap.h>
|
|
|
|
#include <soc/usb.h>
|
|
|
|
#include <timer.h>
|
|
|
|
|
|
|
|
#define USBTAG "[SSUSB] "
|
|
|
|
#define u3p_msg(fmt, arg...) printk(BIOS_INFO, USBTAG fmt, ##arg)
|
|
|
|
#define u3p_err(fmt, arg...) printk(BIOS_ERR, USBTAG fmt, ##arg)
|
|
|
|
|
|
|
|
static struct ssusb_ippc_regs *ippc_regs = (void *)(SSUSB_IPPC_BASE);
|
|
|
|
static struct ssusb_sif_port *phy_ports = (void *)(SSUSB_SIF_BASE);
|
|
|
|
|
|
|
|
static void phy_index_power_on(int index)
|
|
|
|
{
|
|
|
|
struct ssusb_sif_port *phy = phy_ports + index;
|
|
|
|
|
|
|
|
if (!index) {
|
|
|
|
/* Set RG_SSUSB_VUSB10_ON as 1 after VUSB10 ready */
|
2019-12-03 07:03:27 +01:00
|
|
|
setbits32(&phy->u3phya.phya_reg0, P3A_RG_U3_VUSB10_ON);
|
2018-09-26 07:33:36 +02:00
|
|
|
/* Disable power domain ISO */
|
2019-12-03 07:03:27 +01:00
|
|
|
clrbits32(&phy->u2phy.usbphyacr6, PA6_RG_U2_ISO_EN);
|
2018-09-26 07:33:36 +02:00
|
|
|
}
|
|
|
|
/* Switch system IP to USB mode */
|
2019-12-03 07:03:27 +01:00
|
|
|
clrbits32(&phy->u2phy.u2phydtm0, P2C_FORCE_UART_EN);
|
|
|
|
clrbits32(&phy->u2phy.u2phydtm1, P2C_RG_UART_EN);
|
2018-09-26 07:33:36 +02:00
|
|
|
if (!index)
|
2019-12-03 07:03:27 +01:00
|
|
|
clrbits32(&phy->u2phy.u2phyacr4, P2C_U2_GPIO_CTR_MSK);
|
2018-09-26 07:33:36 +02:00
|
|
|
|
|
|
|
/* Disable force settings */
|
2019-12-03 07:03:27 +01:00
|
|
|
clrbits32(&phy->u2phy.u2phydtm0, P2C_FORCE_SUSPENDM |
|
2018-09-26 07:33:36 +02:00
|
|
|
P2C_RG_XCVRSEL | P2C_RG_DATAIN | P2C_DTM0_PART_MASK);
|
|
|
|
|
2019-12-03 07:03:27 +01:00
|
|
|
clrbits32(&phy->u2phy.usbphyacr6, PA6_RG_U2_BC11_SW_EN);
|
2018-09-26 07:33:36 +02:00
|
|
|
/* Improve Rx sensitivity */
|
2019-12-03 07:03:27 +01:00
|
|
|
clrsetbits32(&phy->u2phy.usbphyacr6,
|
2018-09-26 07:33:36 +02:00
|
|
|
PA6_RG_U2_SQTH, PA6_RG_U2_SQTH_VAL(2));
|
|
|
|
|
2019-12-03 07:03:27 +01:00
|
|
|
setbits32(&phy->u2phy.usbphyacr6, PA6_RG_U2_OTG_VBUSCMP_EN);
|
2018-09-26 07:33:36 +02:00
|
|
|
|
2019-12-03 07:03:27 +01:00
|
|
|
clrsetbits32(&phy->u3phya_da.reg0,
|
2018-09-26 07:33:36 +02:00
|
|
|
P3A_RG_XTAL_EXT_EN_U3, P3A_RG_XTAL_EXT_EN_U3_VAL(2));
|
|
|
|
|
2019-12-03 07:03:27 +01:00
|
|
|
clrsetbits32(&phy->u3phya.phya_reg9,
|
2018-09-26 07:33:36 +02:00
|
|
|
P3A_RG_RX_DAC_MUX, P3A_RG_RX_DAC_MUX_VAL(4));
|
|
|
|
|
|
|
|
if (!index)
|
2019-12-03 07:03:27 +01:00
|
|
|
clrbits32(&phy->u2phy.usbphyacr5, PA5_RG_U2_HS_100U_U3_EN);
|
2018-09-26 07:33:36 +02:00
|
|
|
|
2019-12-03 07:03:27 +01:00
|
|
|
clrsetbits32(&phy->u3phya.phya_reg6,
|
2018-09-26 07:33:36 +02:00
|
|
|
P3A_RG_TX_EIDLE_CM, P3A_RG_TX_EIDLE_CM_VAL(0xe));
|
|
|
|
|
2019-12-03 07:03:27 +01:00
|
|
|
clrsetbits32(&phy->u3phyd.phyd_cdr1,
|
2018-09-26 07:33:36 +02:00
|
|
|
P3D_RG_CDR_BIR_LTD0, P3D_RG_CDR_BIR_LTD0_VAL(0xc));
|
2019-12-03 07:03:27 +01:00
|
|
|
clrsetbits32(&phy->u3phyd.phyd_cdr1,
|
2018-09-26 07:33:36 +02:00
|
|
|
P3D_RG_CDR_BIR_LTD1, P3D_RG_CDR_BIR_LTD1_VAL(0x3));
|
|
|
|
|
2019-12-03 07:03:27 +01:00
|
|
|
clrsetbits32(&phy->u2phy.u2phydtm1,
|
2018-09-26 07:33:36 +02:00
|
|
|
P2C_RG_SESSEND, P2C_RG_VBUSVALID | P2C_RG_AVALID);
|
|
|
|
|
|
|
|
/* Set USB 2.0 slew rate value */
|
2019-12-03 07:03:27 +01:00
|
|
|
clrsetbits32(&phy->u2phy.usbphyacr5,
|
2018-09-26 07:33:36 +02:00
|
|
|
PA5_RG_U2_HSTX_SRCTRL, PA5_RG_U2_HSTX_SRCTRL_VAL(4));
|
2019-08-23 06:01:30 +02:00
|
|
|
|
|
|
|
/* Set USB 2.0 disconnect threshold */
|
2019-12-03 07:03:27 +01:00
|
|
|
clrsetbits32(&phy->u2phy.usbphyacr6,
|
2019-08-23 06:01:30 +02:00
|
|
|
PA6_RG_U2_DISCTH, PA6_RG_U2_DISCTH_VAL(15));
|
2018-09-26 07:33:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void u3phy_power_on(void)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < USB_PORT_NUMBER; i++)
|
|
|
|
phy_index_power_on(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int check_ip_clk_status(void)
|
|
|
|
{
|
|
|
|
int u3_port_num;
|
|
|
|
u32 check_bits;
|
|
|
|
u32 sts1, sts2;
|
|
|
|
struct stopwatch sw;
|
|
|
|
|
|
|
|
u3_port_num = CAP_U3_PORT_NUM(read32(&ippc_regs->ip_xhci_cap));
|
|
|
|
|
|
|
|
check_bits = STS1_SYSPLL_STABLE | STS1_REF_RST | STS1_SYS125_RST;
|
|
|
|
check_bits |= (u3_port_num ? STS1_U3_MAC_RST : 0);
|
|
|
|
|
|
|
|
stopwatch_init_usecs_expire(&sw, 50000);
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (stopwatch_expired(&sw)) {
|
2020-02-24 13:26:04 +01:00
|
|
|
u3p_err("USB clocks are not stable!!!\n");
|
2018-09-26 07:33:36 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
sts1 = read32(&ippc_regs->ip_pw_sts1) & check_bits;
|
|
|
|
sts2 = read32(&ippc_regs->ip_pw_sts2) & STS2_U2_MAC_RST;
|
|
|
|
} while ((sts1 != check_bits) || !sts2);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int u3phy_ports_enable(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
u32 value;
|
|
|
|
int u3_port_num;
|
|
|
|
int u2_port_num;
|
|
|
|
|
|
|
|
value = read32(&ippc_regs->ip_xhci_cap);
|
|
|
|
u3_port_num = CAP_U3_PORT_NUM(value);
|
|
|
|
u2_port_num = CAP_U2_PORT_NUM(value);
|
|
|
|
u3p_msg("%s u2p:%d, u3p:%d\n", __func__, u2_port_num, u3_port_num);
|
|
|
|
|
|
|
|
/* Power on host ip */
|
2019-12-03 07:03:27 +01:00
|
|
|
clrbits32(&ippc_regs->ip_pw_ctr1, CTRL1_IP_HOST_PDN);
|
2018-09-26 07:33:36 +02:00
|
|
|
|
|
|
|
/* Power on and enable all u3 ports */
|
|
|
|
for (i = 0; i < u3_port_num; i++) {
|
2019-12-03 07:03:27 +01:00
|
|
|
clrsetbits32(&ippc_regs->u3_ctrl_p[i],
|
2018-09-26 07:33:36 +02:00
|
|
|
CTRL_U3_PORT_PDN | CTRL_U3_PORT_DIS,
|
|
|
|
CTRL_U3_PORT_HOST_SEL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Power on and enable all u2 ports */
|
|
|
|
for (i = 0; i < u2_port_num; i++) {
|
2019-12-03 07:03:27 +01:00
|
|
|
clrsetbits32(&ippc_regs->u2_ctrl_p[i],
|
2018-09-26 07:33:36 +02:00
|
|
|
CTRL_U2_PORT_PDN | CTRL_U2_PORT_DIS,
|
|
|
|
CTRL_U2_PORT_HOST_SEL);
|
|
|
|
}
|
|
|
|
return check_ip_clk_status();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void ssusb_soft_reset(void)
|
|
|
|
{
|
|
|
|
/* Reset whole ip */
|
2019-12-03 07:03:27 +01:00
|
|
|
setbits32(&ippc_regs->ip_pw_ctr0, CTRL0_IP_SW_RST);
|
|
|
|
clrbits32(&ippc_regs->ip_pw_ctr0, CTRL0_IP_SW_RST);
|
2018-09-26 07:33:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
__weak void mtk_usb_prepare(void) { /* do nothing */ }
|
|
|
|
|
|
|
|
void setup_usb_host(void)
|
|
|
|
{
|
|
|
|
u3p_msg("Setting up USB HOST controller...\n");
|
|
|
|
|
|
|
|
mtk_usb_prepare();
|
|
|
|
ssusb_soft_reset();
|
|
|
|
if (u3phy_ports_enable()) {
|
|
|
|
u3p_err("%s fail to enable ports\n", __func__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
u3phy_power_on();
|
|
|
|
u3p_msg("phy power-on done.\n");
|
|
|
|
}
|