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 <console/console.h>
5 #include <delay.h>
6 #include <soc/clock.h>
7 #include <soc/iomap.h>
8 #include <soc/usb.h>
9 
10 #define CRPORT_TX_OVRD_DRV_LO 0x1002
11 #define CRPORT_RX_OVRD_IN_HI 0x1006
12 #define CRPORT_TX_ALT_BLOCK 0x102d
13 
14 static u32 *const tcsr_usb_sel = (void *)0x1a4000b0;
15 
16 struct usb_qc_phy {
38 };
39 check_member(usb_qc_phy, crport_ack_write, 0x50);
40 
41 static struct usb_qc_phy * const usb_host1_phy = (void *)USB_HOST1_PHY_BASE;
42 static struct usb_qc_phy * const usb_host2_phy = (void *)USB_HOST2_PHY_BASE;
43 
44 struct usb_dwc3 {
45  u32 sbuscfg0;
46  u32 sbuscfg1;
47  u32 txthrcfg;
48  u32 rxthrcfg;
49  u32 ctl;
51  u32 sts;
53  u32 snpsid;
54  u32 gpio;
55  u32 uid;
56  u32 uctl;
58  u64 prtbimap;
59  u8 reserved1[32];
61  u32 dbgltssm;
62  u32 dbglnmcc;
63  u32 dbgbmu;
64  u32 dbglspmux;
65  u32 dbglsp;
70  u8 reserved2[112];
72  u8 reserved3[60];
74  u8 reserved4[60];
76  u8 reserved5[60];
79 };
80 check_member(usb_dwc3, usb3pipectl, 0x1c0);
81 
82 static struct usb_dwc3 * const usb_host1_dwc3 = (void *)USB_HOST1_DWC3_BASE;
83 static struct usb_dwc3 * const usb_host2_dwc3 = (void *)USB_HOST2_DWC3_BASE;
84 
85 static void setup_dwc3(struct usb_dwc3 *dwc3)
86 {
87  write32(&dwc3->usb3pipectl,
88  0x1 << 31 | /* assert PHY soft reset */
89  0x1 << 25 | /* (default) U1/U2 exit fail -> recovery? */
90  0x1 << 24 | /* (default) activate PHY low power states */
91  0x1 << 19 | /* (default) PHY low power delay value */
92  0x1 << 18 | /* (default) activate PHY low power delay */
93  0x1 << 1 | /* (default) Tx deemphasis value */
94  0x1 << 0); /* (default) elastic buffer mode */
95 
96  write32(&dwc3->usb2phycfg,
97  0x1 << 31 | /* assert PHY soft reset */
98  0x9 << 10 | /* (default) PHY clock turnaround 8-bit UTMI+ */
99  0x1 << 8 | /* (default) enable PHY sleep in L1 */
100  0x1 << 6); /* (default) enable PHY suspend */
101 
102  write32(&dwc3->ctl,
103  0x2 << 19 | /* (default) suspend clock scaling */
104  0x1 << 16 | /* retry SS three times before HS downgrade */
105  0x1 << 12 | /* port capability HOST */
106  0x1 << 11 | /* assert core soft reset */
107  0x1 << 10 | /* (default) sync ITP to refclk */
108  0x1 << 2); /* U2 exit after 8us LFPS (instead of 248ns) */
109 
110  write32(&dwc3->uctl,
111  0x32 << 22 | /* (default) reference clock period in ns */
112  0x1 << 15 | /* (default) XHCI compliant device addressing */
113  0x10 << 0); /* (default) devices time out after 32us */
114 
115  udelay(5);
116 
117  clrbits32(&dwc3->ctl, 0x1 << 11); /* deassert core soft reset */
118  clrbits32(&dwc3->usb2phycfg, 0x1 << 31); /* PHY soft reset */
119  clrbits32(&dwc3->usb3pipectl, 0x1 << 31); /* PHY soft reset */
120 }
121 
122 static void setup_phy(struct usb_qc_phy *phy)
123 {
124  write32(&phy->ss_phy_ctrl,
125  0x1 << 24 | /* Indicate VBUS power present */
126  0x1 << 8 | /* Enable USB3 ref clock to prescaler */
127  0x1 << 7 | /* assert SS PHY reset */
128  0x19 << 0); /* (default) reference clock multiplier */
129 
130  write32(&phy->hs_phy_ctrl,
131  0x1 << 26 | /* (default) unclamp DPSE/DMSE VLS */
132  0x1 << 25 | /* (default) select freeclk for utmi_clk */
133  0x1 << 24 | /* (default) unclamp DMSE VLS */
134  0x1 << 21 | /* (default) enable UTMI clock */
135  0x1 << 20 | /* set OTG VBUS as valid */
136  0x1 << 18 | /* use ref clock from core */
137  0x1 << 17 | /* (default) unclamp DPSE VLS */
138  0x1 << 11 | /* force xo/bias/pll to stay on in suspend */
139  0x1 << 9 | /* (default) unclamp IDHV */
140  0x1 << 8 | /* (default) unclamp VLS (again???) */
141  0x1 << 7 | /* (default) unclamp HV VLS */
142  0x7 << 4 | /* select frequency (no idea which one) */
143  0x1 << 1); /* (default) "retention enable" */
144 
145  write32(&phy->ss_phy_param1,
146  0x6e << 20 | /* full TX swing amplitude */
147  0x20 << 14 | /* (default) 6dB TX deemphasis */
148  0x17 << 8 | /* 3.5dB TX deemphasis */
149  0x9 << 3); /* (default) LoS detector level */
150 
151  write32(&phy->general_cfg, 0x1 << 2); /* set XHCI 1.00 compliance */
152 
153  udelay(5);
154  clrbits32(&phy->ss_phy_ctrl, 0x1 << 7); /* deassert SS PHY reset */
155 }
156 
157 static void crport_handshake(void *capture_reg, void *acknowledge_bit, u32 data)
158 {
159  int usec = 100;
160 
161  if (capture_reg)
162  write32(capture_reg, data);
163 
164  write32(acknowledge_bit, 0x1 << 0);
165  while (read32(acknowledge_bit) && --usec)
166  udelay(1);
167 
168  if (!usec)
169  printk(BIOS_ERR, "CRPORT handshake timed out (0x%08x)\n", data);
170 }
171 
172 static void crport_write(struct usb_qc_phy *phy, u16 addr, u16 data)
173 {
175  crport_handshake(&phy->crport_data_in, &phy->crport_cap_data, data);
177 }
178 
179 static void tune_phy(struct usb_qc_phy *phy)
180 {
182  0x1 << 11 | /* Set RX_EQ override? */
183  0x4 << 8 | /* Set RX_EQ to 4? */
184  0x1 << 7); /* Enable RX_EQ override */
186  0x1 << 14 | /* Enable amplitude (override?) */
187  0x17 << 7 | /* Set TX deemphasis to 23 */
188  0x6e << 0); /* Set amplitude to 110 */
190  0x1 << 7); /* ALT block? ("partial RX reset") */
191 }
192 
193 void setup_usb_host1(void)
194 {
195  printk(BIOS_INFO, "Setting up USB HOST1 controller...\n");
196  setbits32(tcsr_usb_sel, 1 << 0); /* Select DWC3 controller */
200 }
201 
202 void setup_usb_host2(void)
203 {
204  printk(BIOS_INFO, "Setting up USB HOST2 controller...\n");
205  setbits32(tcsr_usb_sel, 1 << 1); /* Select DWC3 controller */
209 }
static void write32(void *addr, uint32_t val)
Definition: mmio.h:40
static uint32_t read32(const void *addr)
Definition: mmio.h:22
static u32 addr
Definition: cirrus.c:14
#define printk(level,...)
Definition: stdlib.h:16
#define setbits32(addr, set)
Definition: mmio.h:21
#define clrbits32(addr, clear)
Definition: mmio.h:26
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
#define USB_HOST1_PHY_BASE
Definition: iomap.h:75
#define USB_HOST2_PHY_BASE
Definition: iomap.h:72
#define USB_HOST2_DWC3_BASE
Definition: iomap.h:71
check_member(utmip_ctlr, pmc_wakeup, 0x84c - 0x800)
void setup_usb_host1(void)
Definition: usb.c:274
static void setup_phy(struct usb_qc_phy *phy)
Definition: usb.c:122
static struct usb_dwc3 *const usb_host2_dwc3
Definition: usb.c:83
#define CRPORT_TX_OVRD_DRV_LO
Definition: usb.c:10
void setup_usb_host2(void)
Definition: usb.c:202
static void setup_dwc3(struct usb_dwc3 *dwc3)
Definition: usb.c:85
#define CRPORT_TX_ALT_BLOCK
Definition: usb.c:12
static u32 *const tcsr_usb_sel
Definition: usb.c:14
static void crport_handshake(void *capture_reg, void *acknowledge_bit, u32 data)
Definition: usb.c:157
static void crport_write(struct usb_qc_phy *phy, u16 addr, u16 data)
Definition: usb.c:172
static struct usb_dwc3 *const usb_host1_dwc3
Definition: usb.c:82
#define CRPORT_RX_OVRD_IN_HI
Definition: usb.c:11
static struct usb_qc_phy *const usb_host2_phy
Definition: usb.c:42
static struct usb_qc_phy *const usb_host1_phy
Definition: usb.c:41
static void tune_phy(struct usb_qc_phy *phy)
Definition: usb.c:179
#define USB_HOST1_DWC3_BASE
Definition: usb.c:14
#define NULL
Definition: stddef.h:19
uint64_t u64
Definition: stdint.h:54
uint32_t u32
Definition: stdint.h:51
uint16_t u16
Definition: stdint.h:48
uint8_t u8
Definition: stdint.h:45
Definition: usb.c:9
u32 usb2phycfg
Definition: usb.c:36
u8 reserved4[60]
Definition: usb.c:39
u32 sts
Definition: usb.c:16
u64 prtbimap_fs
Definition: usb.c:34
u64 buserraddr
Definition: usb.c:22
u32 evten
Definition: usb.c:50
u32 dbgfifospace
Definition: usb.c:25
u32 txthrcfg
Definition: usb.c:12
u8 reserved0[4]
Definition: usb.c:52
u32 dbgltssm
Definition: usb.c:26
u8 reserved6[60]
Definition: usb.c:78
u32 dbgbmu
Definition: usb.c:28
u32 sbuscfg1
Definition: usb.c:11
u32 uctl
Definition: usb.c:21
u32 gpio
Definition: usb.c:19
u32 uid
Definition: usb.c:20
u64 prtbimap
Definition: usb.c:23
u32 rxthrcfg
Definition: usb.c:13
u64 prtbimap_hs
Definition: usb.c:33
u32 ctl
Definition: usb.c:14
u32 dbgepinfo1
Definition: usb.c:32
u32 dbglspmux
Definition: usb.c:29
u32 dbglnmcc
Definition: usb.c:27
u32 usb3pipectl
Definition: usb.c:40
u8 reserved5[60]
Definition: usb.c:41
u32 usb2i2cctl
Definition: usb.c:73
u32 dbgepinfo0
Definition: usb.c:31
u8 reserved1[32]
Definition: usb.c:24
u32 dbglsp
Definition: usb.c:30
u32 usb2phyacc
Definition: usb.c:38
u32 snpsid
Definition: usb.c:18
u32 sbuscfg0
Definition: usb.c:10
u8 reserved3[124]
Definition: usb.c:37
u8 reserved2[112]
Definition: usb.c:35
Definition: usb.c:16
u32 crport_cap_addr
Definition: usb.c:34
u32 ram1
Definition: usb.c:20
u32 param_ovrd
Definition: usb.c:22
u32 alt_irq_en
Definition: usb.c:25
u32 crport_ack_write
Definition: usb.c:37
u32 chrg_det_ctrl
Definition: usb.c:23
u32 ss_phy_param2
Definition: usb.c:31
u32 crport_ack_read
Definition: usb.c:36
u32 crport_cap_data
Definition: usb.c:35
u32 ss_phy_ctrl
Definition: usb.c:29
u32 ctrl
Definition: usb.c:18
u32 hs_phy_ctrl
Definition: usb.c:21
u32 ss_phy_param1
Definition: usb.c:30
u32 ipcat
Definition: usb.c:17
u32 dbg_bus
Definition: usb.c:28
u32 hs_phy_irq_stat
Definition: usb.c:26
u32 cgctl
Definition: usb.c:27
u32 general_cfg
Definition: usb.c:19
u32 crport_data_out
Definition: usb.c:33
u32 crport_data_in
Definition: usb.c:32
u32 chrg_det_output
Definition: usb.c:24
void udelay(uint32_t us)
Definition: udelay.c:15