coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
usb.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <device/mmio.h>
4 #include <assert.h>
5 #include <console/console.h>
6 #include <soc/clock.h>
7 #include <soc/grf.h>
8 #include <soc/soc.h>
9 #include <soc/usb.h>
10 
11 /* SuperSpeed over Type-C is hard. We don't care about speed in firmware: just
12  * gate off the SuperSpeed lines to have an unimpaired USB 2.0 connection. */
13 static void isolate_tcphy(struct rk3399_tcphy *tcphy)
14 {
15  write32(&tcphy->isolation_ctrl,
27 }
28 
29 static void tcphy_cfg_24m(struct rk3399_tcphy *tcphy)
30 {
31  u32 i;
32 
33  /* cmn_ref_clk_sel = 3, select the 24Mhz for clk parent
34  * cmn_psm_clk_dig_div = 2, set the clk division to 2 */
35  write32(&tcphy->pma_cmn_ctrl1, 2 << 10 | 3 << 4);
36  for (i = 0; i < 4; i++) {
37  /* The following PHY configuration assumes a
38  * 24 MHz reference clock */
39  write32(&tcphy->lane[i].xcvr_diag_lane_fcm_en_mgn, 0x90);
40  write32(&tcphy->lane[i].tx_rcvdet_en_tmr, 0x960);
41  write32(&tcphy->lane[i].tx_rcvdet_st_tmr, 0x30);
42  }
43 
46 }
47 
48 static void tcphy_phy_init(struct rk3399_tcphy *tcphy)
49 {
50  u32 i;
51 
52  tcphy_cfg_24m(tcphy);
53 
54  for (i = 0; i < 4; i++) {
55  /* Enable transmitter reset pull down override for all lanes*/
56  write32(&tcphy->lane[i].tx_diag_tx_drv, 0x2000);
57  /* Disable transmitter low current mode, disable TX
58  * driver common mode, disable TX post-emphasis*/
59  write32(&tcphy->lane[i].tx_psc_a2, 0x0000);
60  }
61 
62  isolate_tcphy(tcphy);
63 }
64 
65 static void reset_dwc3(struct rockchip_usb_dwc3 *dwc3)
66 {
67  /* Before Resetting PHY, put Core in Reset */
69  /* Assert USB3 PHY reset */
71  /* Assert USB2 PHY reset */
73 }
74 
75 static void setup_dwc3(struct rockchip_usb_dwc3 *dwc3)
76 {
77  u32 usb2phycfg = read32(&dwc3->usb2phycfg);
78  u32 ctl = read32(&dwc3->ctl);
79 
80  /* Ensure reset_dwc3() has been called before this. */
82 
83  /* Clear USB3 PHY reset (oddly enough, this is really necessary). */
85 
86  /* Clear USB2 PHY and core reset. */
87  usb2phycfg &= ~DWC3_GUSB2PHYCFG_PHYSOFTRST;
89 
90  /* We are hard-coding DWC3 core to Host Mode */
91  ctl &= ~DWC3_GCTL_PRTCAP_MASK;
92  ctl |= DWC3_GCTL_PRTCAP_HOST;
93 
94  /*
95  * Configure USB phy interface of DWC3 core.
96  * For Rockchip rk3399 SOC DWC3 core:
97  * 1. Clear U2_FREECLK_EXITS.
98  * 2. Select UTMI+ PHY with 16-bit interface.
99  * 3. Set USBTRDTIM to the corresponding value
100  * according to the UTMI+ PHY interface.
101  */
102  usb2phycfg &= ~(DWC3_GUSB2PHYCFG_U2_FREECLK_EXISTS |
105  usb2phycfg |= DWC3_GUSB2PHYCFG_PHYIF(1) |
107 
108  write32(&dwc3->usb2phycfg, usb2phycfg);
109  write32(&dwc3->ctl, ctl);
110 }
111 
112 void reset_usb_otg0(void)
113 {
114  printk(BIOS_DEBUG, "Starting DWC3 and TCPHY reset for USB OTG0\n");
115 
116  /* Keep whole USB OTG0 controller in reset, then
117  * configure controller to work in USB 2.0 only mode. */
118  write32(&cru_ptr->softrst_con[18], RK_SETBITS(1 << 5));
119  write32(&rk3399_grf->usb3otg0_con1, RK_CLRSETBITS(0xf << 12, 1 << 0));
120  write32(&cru_ptr->softrst_con[18], RK_CLRBITS(1 << 5));
121 
123 
124  /* Clear TCPHY0 reset */
125  write32(&cru_ptr->softrst_con[9], RK_CLRBITS(1 << 5));
126 
128 }
129 
130 void reset_usb_otg1(void)
131 {
132  printk(BIOS_DEBUG, "Starting DWC3 and TCPHY reset for USB OTG1\n");
133 
134  /* Keep whole USB OTG1 controller in reset, then
135  * configure controller to work in USB 2.0 only mode. */
136  write32(&cru_ptr->softrst_con[18], RK_SETBITS(1 << 6));
137  write32(&rk3399_grf->usb3otg1_con1, RK_CLRSETBITS(0xf << 12, 1 << 0));
138  write32(&cru_ptr->softrst_con[18], RK_CLRBITS(1 << 6));
139 
141 
142  /* Clear TCPHY1 reset */
143  write32(&cru_ptr->softrst_con[9], RK_CLRBITS(1 << 13));
144 
146 }
147 
148 void setup_usb_otg0(void)
149 {
150  /* Clear pipe reset */
151  write32(&cru_ptr->softrst_con[9], RK_CLRBITS(1 << 4));
152 
154  printk(BIOS_DEBUG, "DWC3 and TCPHY setup for USB OTG0 finished\n");
155 }
156 
157 void setup_usb_otg1(void)
158 {
159  /* Clear pipe reset */
160  write32(&cru_ptr->softrst_con[9], RK_CLRBITS(1 << 12));
161 
163  printk(BIOS_DEBUG, "DWC3 and TCPHY setup for USB OTG1 finished\n");
164 }
static void write32(void *addr, uint32_t val)
Definition: mmio.h:40
static uint32_t read32(const void *addr)
Definition: mmio.h:22
#define assert(statement)
Definition: assert.h:74
#define printk(level,...)
Definition: stdlib.h:16
#define setbits32(addr, set)
Definition: mmio.h:21
#define clrsetbits32(addr, clear, set)
Definition: mmio.h:16
#define clrbits32(addr, clear)
Definition: mmio.h:26
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define DWC3_GUSB2PHYCFG_USB2TRDTIM_MASK
Definition: usb_common.h:19
#define DWC3_GCTL_PRTCAP_HOST
Definition: usb_common.h:15
#define DWC3_GUSB2PHYCFG_USBTRDTIM(n)
Definition: usb_common.h:18
#define DWC3_GUSB2PHYCFG_PHYIF(n)
Definition: usb_common.h:20
#define DWC3_GUSB2PHYCFG_PHYIF_MASK
Definition: usb_common.h:21
static struct rk3399_grf_regs *const rk3399_grf
Definition: grf.h:319
#define RK_CLRBITS(clr)
Definition: soc.h:10
#define RK_SETBITS(set)
Definition: soc.h:9
#define RK_CLRSETBITS(clr, set)
Definition: soc.h:8
#define DWC3_GUSB2PHYCFG_PHYSOFTRST
Definition: usb.c:48
#define DWC3_GUSB3PIPECTL_PHYSOFTRST
Definition: usb.c:38
#define DWC3_GCTL_CORESOFTRESET
Definition: usb.c:40
static struct rk3288_cru_reg *const cru_ptr
Definition: clock.c:50
#define TCPHY_ISOLATION_CTRL_LN_EN(ln)
Definition: usb.h:104
static struct rk3399_tcphy *const rockchip_usb_otg0_phy
Definition: usb.h:132
static struct rockchip_usb_dwc3 *const rockchip_usb_otg1_dwc3
Definition: usb.h:98
#define DWC3_GUSB2PHYCFG_U2_FREECLK_EXISTS
Definition: usb.h:39
static struct rk3399_tcphy *const rockchip_usb_otg1_phy
Definition: usb.h:134
#define USBTRDTIM_UTMI_16_BIT
Definition: usb.h:46
#define TCPHY_ISOLATION_CTRL_EN
Definition: usb.h:101
static struct rockchip_usb_dwc3 *const rockchip_usb_otg0_dwc3
Definition: usb.h:96
#define TCPHY_ISOLATION_CTRL_CMN_EN
Definition: usb.h:102
#define TCPHY_CMN_HSCLK_PLL_CONFIG
Definition: usb.h:105
#define DWC3_GCTL_PRTCAP_MASK
Definition: usb.h:22
#define TCPHY_CMN_HSCLK_PLL_MASK
Definition: usb.h:106
#define TCPHY_ISOLATION_CTRL_MODE_SEL
Definition: usb.h:103
static void tcphy_cfg_24m(struct rk3399_tcphy *tcphy)
Definition: usb.c:29
static void reset_dwc3(struct rockchip_usb_dwc3 *dwc3)
Definition: usb.c:65
static void setup_dwc3(struct rockchip_usb_dwc3 *dwc3)
Definition: usb.c:75
static void isolate_tcphy(struct rk3399_tcphy *tcphy)
Definition: usb.c:13
void setup_usb_otg0(void)
Definition: usb.c:148
void reset_usb_otg1(void)
Definition: usb.c:130
void setup_usb_otg1(void)
Definition: usb.c:157
void reset_usb_otg0(void)
Definition: usb.c:112
static void tcphy_phy_init(struct rk3399_tcphy *tcphy)
Definition: usb.c:48
uint32_t u32
Definition: stdint.h:51
u32 usb3otg1_con1
Definition: grf.h:26
u32 usb3otg0_con1
Definition: grf.h:23
uint32_t tx_rcvdet_st_tmr
Definition: usb.h:119
uint32_t tx_diag_tx_drv
Definition: usb.h:121
uint32_t cmn_diag_hsclk_sel
Definition: usb.h:110
uint32_t xcvr_diag_lane_fcm_en_mgn
Definition: usb.h:114
uint32_t isolation_ctrl
Definition: usb.h:127
uint32_t tx_rcvdet_en_tmr
Definition: usb.h:118
uint32_t pma_cmn_ctrl1
Definition: usb.h:125
struct rk3399_tcphy::@1524 lane[4]
uint32_t tx_psc_a2
Definition: usb.h:116
uint32_t usb2phycfg
Definition: usb.h:86
uint32_t usb3pipectl
Definition: usb.h:92
uint32_t ctl
Definition: usb.h:57