coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
qusb_phy.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <soc/usb/qusb_phy.h>
4 #include <soc/efuse.h>
5 #include <timer.h>
6 #include <soc/usb/usb_common.h>
7 
8 static struct qfprom_corr * const qfprom_corr_efuse = (void *)QFPROM_BASE;
9 
10 struct hs_usb_phy_reg qusb_phy = {
11  .phy_pll = (void *)QUSB_PRIM_PHY_BASE,
12 
14 
15  .efuse_offset = 25,
16 };
17 
19 {
20  /* Override preemphasis value */
23 
24  /* Override BIAS_CTRL_2 to reduce the TX swing overshooting. */
27 
28  /* Override IMP_RES_OFFSET value */
31 }
32 
33 /*
34  * Fetches HS Tx tuning value from efuse register and sets the
35  * QUSB2PHY_PORT_TUNE1/2 register.
36  * For error case, skip setting the value and use the default value.
37  */
38 
40 {
41  /*
42  * Efuse registers 3 bit value specifies tuning for HSTX
43  * output current in TUNE1 Register. Hence Extract 3 bits from
44  * EFUSE at correct position.
45  */
46 
47  const int efuse_bits = 3;
48  int bit_pos = hs_phy_reg->efuse_offset;
49 
50  u32 bit_mask = (1 << efuse_bits) - 1;
51  u32 tune_val =
53  & bit_mask;
54  /*
55  * if efuse reg is updated (i.e non-zero) then use it to program
56  * tune parameters.
57  */
58  if (tune_val)
60  PORT_TUNE1_MASK, tune_val << 4);
61 }
62 
63 static void tune_phy(struct hs_usb_phy_reg *hs_phy_reg)
64 {
66  /* IMP_CTRL1: Control the impedance reduction */
68  /* IMP_CTRL2: Impedance offset/mapping slope */
71  /*
72  * TUNE1: Sets HS Impedance to approx 45 ohms
73  * then override with efuse value.
74  */
76  /* TUNE2: Tuning for HS Disconnect Level */
78  /* TUNE3: Tune squelch range */
80  /* TUNE4: Sets EOP_DLY(Squelch rising edge to linestate falling edge) */
83 
84  if (hs_phy_reg->board_data) {
85  /* Override board specific PHY tuning values */
87 
88  /* Set efuse value for tuning the PHY */
90  }
91 }
92 
94 {
95  struct hs_usb_phy_reg *hs_phy_reg;
96 
98 
99  hs_phy_reg->board_data = (struct usb_board_data *) board_data;
100 
101  /* PWR_CTRL: set the power down bit to disable the PHY */
102 
104 
119 
121 
122  /* PWR_CTRL1: Clear the power down bit to enable the PHY */
124 
127 
128  /*
129  * DEBUG_STAT5: wait for 160uS for PLL lock;
130  * vstatus[0] changes from 0 to 1.
131  */
132  long lock_us = wait_us(160, read32(&hs_phy_reg->phy_dig->debug_stat5) &
134  if (!lock_us)
135  printk(BIOS_ERR, "QUSB PHY PLL LOCK fails\n");
136  else
137  printk(BIOS_DEBUG, "QUSB PHY initialized and locked in %ldus\n",
138  lock_us);
139 }
static void write32(void *addr, uint32_t val)
Definition: mmio.h:40
static uint32_t read32(const void *addr)
Definition: mmio.h:22
#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 wait_us(timeout_us, condition)
Definition: timer.h:198
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
void hs_usb_phy_init(void *board_data)
Definition: qusb_phy.c:93
static void qusb2_phy_override_phy_params(struct hs_usb_phy_reg *hs_phy_reg)
Definition: qusb_phy.c:18
static void qusb2_phy_set_tune_param(struct hs_usb_phy_reg *hs_phy_reg)
Definition: qusb_phy.c:39
static struct qfprom_corr *const qfprom_corr_efuse
Definition: qusb_phy.c:8
static void tune_phy(struct hs_usb_phy_reg *hs_phy_reg)
Definition: qusb_phy.c:63
struct hs_usb_phy_reg qusb_phy
Definition: qusb_phy.c:10
#define QUSB_PRIM_PHY_DIG_BASE
Definition: qusb_phy.h:38
#define QUSB2PHY_PORT_TUNE3
Definition: qusb_phy.h:30
#define QUSB2PHY_PORT_TUNE2
Definition: qusb_phy.h:29
#define VSTATUS_PLL_LOCK_STATUS_MASK
Definition: qusb_phy.h:15
#define QUSB2PHY_PLL_LOCK_DELAY
Definition: qusb_phy.h:21
#define PORT_TUNE1_MASK
Definition: qusb_phy.h:6
#define QUSB2PHY_PLL_CMODE
Definition: qusb_phy.h:20
#define QUSB2PHY_PLL_BIAS_CONTROL_2
Definition: qusb_phy.h:24
#define QUSB2PHY_IMP_CTRL2
Definition: qusb_phy.h:27
#define QUSB2PHY_PLL_DIGITAL_TIMERS_TWO
Definition: qusb_phy.h:22
#define QUSB2PHY_PORT_TUNE1
Definition: qusb_phy.h:28
#define QUSB2PHY_PLL_BIAS_CONTROL_1
Definition: qusb_phy.h:23
#define POWER_DOWN
Definition: qusb_phy.h:9
#define QUSB2PHY_PORT_TUNE4
Definition: qusb_phy.h:31
#define QUSB_PRIM_PHY_BASE
Definition: qusb_phy.h:37
#define QUSB2PHY_PORT_TUNE5
Definition: qusb_phy.h:32
#define QUSB2PHY_PWR_CTRL2
Definition: qusb_phy.h:25
#define QFPROM_BASE
Definition: qusb_phy.h:36
#define QUSB2PHY_IMP_CTRL1
Definition: qusb_phy.h:26
#define QUSB2PHY_PLL_ANALOG_CONTROLS_TWO
Definition: qusb_phy.h:18
#define QUSB2PHY_PLL_CLOCK_INVERTERS
Definition: qusb_phy.h:19
#define DEBUG_CTRL2_MUX_PLL_LOCK_STATUS
Definition: qusb_phy.h:12
struct hs_usb_phy_reg * hs_phy_reg
Definition: snps_usb_phy.c:34
uint32_t u32
Definition: stdint.h:51
struct usb_board_data * board_data
Definition: qusb_phy.h:94
struct usb_qusb_phy_dig * phy_dig
Definition: qusb_phy.h:93
struct usb_qusb_phy_pll * phy_pll
Definition: qusb_phy.h:92
u32 efuse_offset
Definition: qusb_phy.h:95
USB EFUSE registers.
Definition: efuse.h:9
u32 qusb_hstx_trim_lsb
Definition: efuse.h:11
u32 pll_bias_control_2
Definition: qusb_phy.h:44
u32 port_tune1
Definition: qusb_phy.h:46
u32 analog_controls_two
Definition: qusb_phy.h:74
u32 clock_inverters
Definition: qusb_phy.h:82