Debian Codegraph @

src/soc/amd/picasso/fsp_s_params.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <assert.h>
4 #include <amdblocks/ioapic.h>
5 #include <amdblocks/vbt.h>
6 #include <device/pci.h>
7 #include <soc/iomap.h>
8 #include <soc/pci_devs.h>
9 #include <soc/platform_descriptors.h>
10 #include <soc/soc_util.h>
11 #include <static.h>
12 #include <fsp/api.h>
13 #include "chip.h"
14
15 static void fsps_update_emmc_config(FSP_S_CONFIG *scfg,
16 const struct soc_amd_picasso_config *cfg)
17 {
18 int val = SD_DISABLE;
19
20 switch (cfg->emmc_config.timing) {
21 case SD_EMMC_DISABLE:
22 val = SD_DISABLE;
23 break;
24 case SD_EMMC_SD_LOW_SPEED:
25 val = SD_LOW_SPEED;
26 break;
27 case SD_EMMC_SD_HIGH_SPEED:
28 val = SD_HIGH_SPEED;
29 break;
30 case SD_EMMC_SD_UHS_I_SDR_50:
31 val = SD_UHS_I_SDR_50;
32 break;
33 case SD_EMMC_SD_UHS_I_DDR_50:
34 val = SD_UHS_I_DDR_50;
35 break;
36 case SD_EMMC_SD_UHS_I_SDR_104:
37 val = SD_UHS_I_SDR_104;
38 break;
39 case SD_EMMC_EMMC_SDR_26:
40 val = EMMC_SDR_26;
41 break;
42 case SD_EMMC_EMMC_SDR_52:
43 val = EMMC_SDR_52;
44 break;
45 case SD_EMMC_EMMC_DDR_104:
46 val = EMMC_DDR_104;
47 break;
48 case SD_EMMC_EMMC_HS200:
49 val = EMMC_HS200;
50 break;
51 case SD_EMMC_EMMC_HS400:
52 val = EMMC_HS400;
53 break;
54 case SD_EMMC_EMMC_HS300:
55 val = EMMC_HS300;
56 break;
57 default:
58 break;
59 }
60
61 /* Make sure that the FSP knows that the EMMC controller should be disabled when the
62 corresponding MMIO device is disabled */
63 if (!is_dev_enabled(DEV_PTR(emmc)))
64 val = SD_DISABLE;
65
66 scfg->emmc0_mode = val;
67 scfg->emmc0_sdr104_hs400_driver_strength =
68 cfg->emmc_config.sdr104_hs400_driver_strength;
69 scfg->emmc0_ddr50_driver_strength = cfg->emmc_config.ddr50_driver_strength;
70 scfg->emmc0_sdr50_driver_strength = cfg->emmc_config.sdr50_driver_strength;
71 scfg->emmc0_init_khz_preset = cfg->emmc_config.init_khz_preset;
72 }
73
74 static void fill_dxio_descriptors(FSP_S_CONFIG *scfg,
75 const fsp_dxio_descriptor *descs, size_t num)
76 {
77 size_t i;
78
79 ASSERT_MSG(num <= FSPS_UPD_DXIO_DESCRIPTOR_COUNT,
80 "Too many DXIO descriptors provided.");
81
82 for (i = 0; i < num; i++) {
83 memcpy(scfg->dxio_descriptor[i], &descs[i], sizeof(scfg->dxio_descriptor[0]));
84 }
85 }
86
87 static void fill_ddi_descriptors(FSP_S_CONFIG *scfg,
88 const fsp_ddi_descriptor *descs, size_t num)
89 {
90 size_t i;
91
92 ASSERT_MSG(num <= FSPS_UPD_DDI_DESCRIPTOR_COUNT,
93 "Too many DDI descriptors provided.");
94
95 for (i = 0; i < num; i++) {
96 memcpy(&scfg->ddi_descriptor[i], &descs[i], sizeof(scfg->ddi_descriptor[0]));
97 }
98 }
99
100 static void fsp_fill_pcie_ddi_descriptors(FSP_S_CONFIG *scfg)
101 {
102 const fsp_dxio_descriptor *fsp_dxio = NULL;
103 const fsp_ddi_descriptor *fsp_ddi = NULL;
104 size_t num_dxio = 0;
105 size_t num_ddi = 0;
106
107 mainboard_get_dxio_ddi_descriptors(&fsp_dxio, &num_dxio,
108 &fsp_ddi, &num_ddi);
109 fill_dxio_descriptors(scfg, fsp_dxio, num_dxio);
110 fill_ddi_descriptors(scfg, fsp_ddi, num_ddi);
111 }
112
113 static void fsp_usb_oem_customization(FSP_S_CONFIG *scfg,
114 const struct soc_amd_picasso_config *cfg)
115 {
116 size_t i;
117
118 ASSERT(FSPS_UPD_USB2_PORT_COUNT == USB_PORT_COUNT);
119 /* each OC mapping in xhci_oc_pin_select is 4 bit per USB port */
120 ASSERT(2 * sizeof(scfg->xhci_oc_pin_select) >= USB_PORT_COUNT);
121
122 scfg->fch_usb_3_port_force_gen1 = cfg->usb3_port_force_gen1.usb3_port_force_gen1_en;
123
124 if (cfg->has_usb2_phy_tune_params) {
125 for (i = 0; i < FSPS_UPD_USB2_PORT_COUNT; i++) {
126 memcpy(scfg->fch_usb_2_port_phy_tune[i],
127 &cfg->usb_2_port_tune_params[i],
128 sizeof(scfg->fch_usb_2_port_phy_tune[0]));
129 }
130 }
131
132 /* lowest nibble of xhci_oc_pin_select corresponds to OC mapping of first USB port */
133 for (i = 0; i < USB_PORT_COUNT; i++) {
134 scfg->xhci_oc_pin_select &= ~(0xf << (i * 4));
135 scfg->xhci_oc_pin_select |=
136 (cfg->usb_port_overcurrent_pin[i] & 0xf) << (i * 4);
137 }
138
139 if ((get_silicon_type() == SILICON_RV2) && cfg->usb3_phy_override) {
140 scfg->usb_3_phy_enable = cfg->usb3_phy_override;
141 for (i = 0; i < FSPS_UPD_RV2_USB3_PORT_COUNT; i++) {
142 memcpy(scfg->usb_3_port_phy_tune[i],
143 &cfg->usb3_phy_tune_params[i],
144 sizeof(scfg->usb_3_port_phy_tune[0]));
145 }
146 scfg->usb_3_rx_vref_ctrl = cfg->usb3_rx_vref_ctrl;
147 scfg->usb_3_rx_vref_ctrl_en = cfg->usb3_rx_vref_ctrl_en;
148 scfg->usb_3_tx_vboost_lvl = cfg->usb_3_tx_vboost_lvl;
149 scfg->usb_3_tx_vboost_lvl_en = cfg->usb_3_tx_vboost_lvl_en;
150 scfg->usb_3_rx_vref_ctrl_x = cfg->usb_3_rx_vref_ctrl_x;
151 scfg->usb_3_rx_vref_ctrl_en_x = cfg->usb_3_rx_vref_ctrl_en_x;
152 scfg->usb_3_tx_vboost_lvl_x = cfg->usb_3_tx_vboost_lvl_x;
153 scfg->usb_3_tx_vboost_lvl_en_x = cfg->usb_3_tx_vboost_lvl_en_x;
154 }
155 }
156
157 static void fsp_assign_ioapic_upds(FSP_S_CONFIG *scfg)
158 {
159 scfg->gnb_ioapic_base = GNB_IO_APIC_ADDR;
160 scfg->gnb_ioapic_id = GNB_IOAPIC_ID;
161 scfg->fch_ioapic_id = FCH_IOAPIC_ID;
162 }
163
164 static void fsp_edp_tuning_upds(FSP_S_CONFIG *scfg,
165 const struct soc_amd_picasso_config *cfg)
166 {
167 if (cfg->edp_phy_override & ENABLE_EDP_TUNINGSET) {
168 scfg->edp_phy_override = cfg->edp_phy_override;
169 scfg->edp_physel = cfg->edp_physel;
170 scfg->edp_dp_vs_pemph_level = cfg->edp_tuningset.dp_vs_pemph_level;
171 scfg->edp_margin_deemph = cfg->edp_tuningset.margin_deemph;
172 scfg->edp_deemph_6db_4 = cfg->edp_tuningset.deemph_6db4;
173 scfg->edp_boost_adj = cfg->edp_tuningset.boostadj;
174 }
175 if (cfg->edp_pwr_adjust_enable) {
176 scfg->pwron_digon_to_de = cfg->pwron_digon_to_de;
177 scfg->pwron_de_to_varybl = cfg->pwron_de_to_varybl;
178 scfg->pwrdown_varybloff_to_de = cfg->pwrdown_varybloff_to_de;
179 scfg->pwrdown_de_to_digoff = cfg->pwrdown_de_to_digoff;
180 scfg->pwroff_delay = cfg->pwroff_delay;
181 scfg->pwron_varybl_to_blon = cfg->pwron_varybl_to_blon;
182 scfg->pwrdown_bloff_to_varybloff = cfg->pwrdown_bloff_to_varybloff;
183 scfg->min_allowed_bl_level = cfg->min_allowed_bl_level;
184 }
185 }
186
187 static void fsp_assign_vbios_upds(FSP_S_CONFIG *scfg)
188 {
189 /*
190 * The VBIOS contains the ATOMBIOS tables that will be modified as
191 * part of FSP GOP init. We can delay loading of the VBIOS until
192 * before FSP notify AFTER_PCI_ENUM.
193 */
194 scfg->vbios_buffer_addr = (uintptr_t)vbt_get();
195 }
196
197 void platform_fsp_silicon_init_params_cb(FSPS_UPD *supd)
198 {
199 const struct soc_amd_picasso_config *cfg;
200 FSP_S_CONFIG *scfg = &supd->FspsConfig;
201
202 cfg = config_of_soc();
203 fsps_update_emmc_config(scfg, cfg);
204 fsp_fill_pcie_ddi_descriptors(scfg);
205 fsp_assign_ioapic_upds(scfg);
206 fsp_usb_oem_customization(scfg, cfg);
207 fsp_edp_tuning_upds(scfg, cfg);
208 fsp_assign_vbios_upds(scfg);
209 }