coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
qmpv4_usb_phy.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <timer.h>
4 #include <soc/usb/qmp_usb_phy.h>
5 #include <soc/addressmap.h>
6 
7 
8 /* Only for QMP V4 PHY - QSERDES COM registers */
10  u8 _reserved1[16];
22  u8 _reserved2[8];
29  u8 _reserved3[4];
31  u8 _reserved4[16];
38  u8 _reserved6[8];
40  u8 _reserved7[8];
49  u8 _reserved8[4];
51  u8 _reserved9[4];
58  u8 _reserved10[8];
61  u8 _reserved11[24];
67  u8 _reserved12[52];
70  u8 _reserved13[12];
73  u8 _reserved14[4];
85 };
86 
87 check_member(usb3_phy_qserdes_com_reg_layout, com_ssc_en_center, 0x010);
92 check_member(usb3_phy_qserdes_com_reg_layout, com_bias_en_clkbuflr_en, 0x044);
94 check_member(usb3_phy_qserdes_com_reg_layout, com_cp_ctrl_mode0, 0x074);
95 check_member(usb3_phy_qserdes_com_reg_layout, com_sysclk_en_sel, 0x094);
96 check_member(usb3_phy_qserdes_com_reg_layout, com_resetsm_ctrl2, 0x0a0);
97 check_member(usb3_phy_qserdes_com_reg_layout, com_dec_start_mode0, 0x0bc);
98 check_member(usb3_phy_qserdes_com_reg_layout, com_div_frac_start1_mode0, 0x0cc);
99 check_member(usb3_phy_qserdes_com_reg_layout, com_integloop_gain0_mode0, 0x0ec);
102 check_member(usb3_phy_qserdes_com_reg_layout, com_coreclk_div_mode0, 0x168);
104 check_member(usb3_phy_qserdes_com_reg_layout, com_svs_mode_clk_sel, 0x184);
105 check_member(usb3_phy_qserdes_com_reg_layout, com_bin_vcocal_hsclk_sel, 0x1bc);
106 
107 /* Only for QMP V4 PHY - TX registers */
109  u8 _reserved1[52];
114  u8 _reserved2[64];
116  u8 _reserved3[20];
118  u8 _reserved4[100];
120 };
121 check_member(usb3_phy_qserdes_tx_reg_layout, tx_res_code_lane_offset_tx, 0x03c);
122 check_member(usb3_phy_qserdes_tx_reg_layout, tx_res_code_lane_offset_rx, 0x040);
124 check_member(usb3_phy_qserdes_tx_reg_layout, tx_rcv_detect_lvl_2, 0x09c);
126 
127 /* Only for QMP V4 PHY - RX registers */
129  u8 _reserved1[20];
131  u8 _reserved2[24];
134  u8 _reserved3[4];
138  u8 _reserved4[4];
145  u8 _reserved5[112];
149  u8 _reserved6[12];
155  u8 _reserved7[16];
157  u8 _reserved8[8];
178 };
179 
181 check_member(usb3_phy_qserdes_rx_reg_layout, rx_ucdr_fastlock_fo_gain, 0x030);
182 check_member(usb3_phy_qserdes_rx_reg_layout, rx_vga_cal_cntrl1, 0x0d4);
183 check_member(usb3_phy_qserdes_rx_reg_layout, rx_rx_equ_adaptor_cntrl2, 0x0ec);
184 check_member(usb3_phy_qserdes_rx_reg_layout, rx_rx_equ_adaptor_cntrl3, 0x0f0);
185 check_member(usb3_phy_qserdes_rx_reg_layout, rx_rx_equ_adaptor_cntrl4, 0x0f4);
189 
190 /* Only for QMP V4 PHY - PCS registers */
195  u8 _reserved1[40];
198  u8 _reserved2[124];
202  u8 _reserved3[8];
205  u8 _reserved4[168];
207  u8 _reserved5[36];
209  u8 _reserved6[12];
212  u8 _reserved7[8];
214  u8 _reserved8[8];
216  u8 _reserved9[12];
218  u8 _reserved10[296];
222 };
223 
224 check_member(usb3_phy_pcs_reg_layout, pcs_lock_detect_config1, 0x0c4);
225 check_member(usb3_phy_pcs_reg_layout, pcs_lock_detect_config2, 0x0c8);
226 check_member(usb3_phy_pcs_reg_layout, pcs_lock_detect_config6, 0x0d8);
227 check_member(usb3_phy_pcs_reg_layout, pcs_pcs_tx_rx_config, 0x1d0);
228 check_member(usb3_phy_pcs_reg_layout, pcs_eq_config5, 0x1ec);
229 check_member(usb3_phy_pcs_reg_layout, pcs_usb3_lfps_det_high_count_val, 0x318);
230 check_member(usb3_phy_pcs_reg_layout, pcs_usb3_rxeqtraining_dfe_time_s2, 0x338);
231 
239  (void *)QMP_PHY_PCS_REG_BASE;
240 static const struct qmp_phy_init_tbl qmp_v4_usb3_serdes_tbl[] = {
281 };
282 
283 static const struct qmp_phy_init_tbl qmp_v4_usb3_tx_tbl[] = {
291 };
292 
293 static const struct qmp_phy_init_tbl qmp_v4_usb3_rx_tbl[] = {
332 };
333 
334 static const struct qmp_phy_init_tbl qmp_v4_usb3_pcs_tbl[] = {
345  {&pcs_reg_layout->pcs_eq_config1, 0x4b},
346  {&pcs_reg_layout->pcs_eq_config5, 0x10},
349 };
350 
353  .serdes_tbl_num = ARRAY_SIZE(qmp_v4_usb3_serdes_tbl),
354  .tx_tbl = qmp_v4_usb3_tx_tbl,
355  .tx_tbl_num = ARRAY_SIZE(qmp_v4_usb3_tx_tbl),
356  .rx_tbl = qmp_v4_usb3_rx_tbl,
357  .rx_tbl_num = ARRAY_SIZE(qmp_v4_usb3_rx_tbl),
358  .pcs_tbl = qmp_v4_usb3_pcs_tbl,
359  .pcs_tbl_num = ARRAY_SIZE(qmp_v4_usb3_pcs_tbl),
360  .qmp_pcs_reg = (void *)QMP_PHY_PCS_REG_BASE,
361 };
362 
363 static void qcom_qmp_phy_configure(const struct qmp_phy_init_tbl tbl[],
364  int num)
365 {
366  int i;
367  const struct qmp_phy_init_tbl *t = tbl;
368 
369  if (!t)
370  return;
371 
372  for (i = 0; i < num; i++, t++)
373  write32(t->address, t->val);
374 }
375 
376 void ss_qmp_phy_init(void)
377 {
378  struct ss_usb_phy_reg *ss_phy_reg;
379 
380  ss_phy_reg = &qmp_v4_usb_phy;
381 
382  /* power up USB3 PHY */
383  write32(&ss_phy_reg->qmp_pcs_reg->pcs_power_down_control, 0x01);
384 
385  /* Serdes configuration */
387  ss_phy_reg->serdes_tbl_num);
388  /* Tx, Rx, and PCS configurations */
389  qcom_qmp_phy_configure(ss_phy_reg->tx_tbl, ss_phy_reg->tx_tbl_num);
390  qcom_qmp_phy_configure(ss_phy_reg->rx_tbl, ss_phy_reg->rx_tbl_num);
391  qcom_qmp_phy_configure(ss_phy_reg->pcs_tbl, ss_phy_reg->pcs_tbl_num);
392 
393  /* perform software reset of PCS/Serdes */
394  write32(&ss_phy_reg->qmp_pcs_reg->pcs_sw_reset, 0x00);
395  /* start PCS/Serdes to operation mode */
396  write32(&ss_phy_reg->qmp_pcs_reg->pcs_start_control, 0x03);
397 
398  /*
399  * Wait for PHY initialization to be done
400  * PCS_STATUS: wait for 1ms for PHY STATUS;
401  * SW can continuously check for PHYSTATUS = 1.b0.
402  */
403  long lock_us = wait_us(10000,
404  !(read32(&ss_phy_reg->qmp_pcs_reg->pcs_ready_status) &
406  if (!lock_us)
407  printk(BIOS_ERR, "QMP PHY PLL LOCK fails:\n");
408  else
409  printk(BIOS_DEBUG, "QMP PHY initialized and locked in %ldus\n",
410  lock_us);
411 }
static void write32(void *addr, uint32_t val)
Definition: mmio.h:40
static uint32_t read32(const void *addr)
Definition: mmio.h:22
#define ARRAY_SIZE(a)
Definition: helpers.h:12
#define printk(level,...)
Definition: stdlib.h:16
#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
#define USB3_PCS_PHYSTATUS
Definition: qmp_usb_phy.h:7
struct ss_usb_phy_reg qmp_v4_usb_phy
static struct usb3_phy_qserdes_com_reg_layout *const qserdes_com_reg_layout
static void qcom_qmp_phy_configure(const struct qmp_phy_init_tbl tbl[], int num)
static const struct qmp_phy_init_tbl qmp_v4_usb3_tx_tbl[]
static const struct qmp_phy_init_tbl qmp_v4_usb3_rx_tbl[]
void ss_qmp_phy_init(void)
static const struct qmp_phy_init_tbl qmp_v4_usb3_serdes_tbl[]
check_member(usb3_phy_qserdes_com_reg_layout, com_ssc_en_center, 0x010)
static const struct qmp_phy_init_tbl qmp_v4_usb3_pcs_tbl[]
static struct usb3_phy_pcs_reg_layout *const pcs_reg_layout
static struct usb3_phy_qserdes_tx_reg_layout *const qserdes_tx_reg_layout
static struct usb3_phy_qserdes_rx_reg_layout *const qserdes_rx_reg_layout
#define QMP_PHY_QSERDES_RX_REG_BASE
Definition: addressmap.h:45
#define QMP_PHY_PCS_REG_BASE
Definition: addressmap.h:46
#define QMP_PHY_QSERDES_COM_REG_BASE
Definition: addressmap.h:43
#define QMP_PHY_QSERDES_TX_REG_BASE
Definition: addressmap.h:44
uint32_t u32
Definition: stdint.h:51
uint8_t u8
Definition: stdint.h:45
struct usb3_phy_pcs_reg_layout * qmp_pcs_reg
Definition: qmp_usb_phy.h:28
const struct qmp_phy_init_tbl * rx_tbl
Definition: qmp_usb_phy.h:22
const struct qmp_phy_init_tbl * serdes_tbl
Definition: qmp_usb_phy.h:16
const struct qmp_phy_init_tbl * tx_tbl
Definition: qmp_usb_phy.h:19
const struct qmp_phy_init_tbl * pcs_tbl
Definition: qmp_usb_phy.h:25