Aaron Durbin | 89e51e6 | 2020-04-09 14:16:55 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Aaron Durbin | 89e51e6 | 2020-04-09 14:16:55 -0600 | [diff] [blame] | 2 | |
Felix Held | a319ac3 | 2020-07-14 00:52:14 +0200 | [diff] [blame] | 3 | #include <assert.h> |
Felix Held | 604ffa6 | 2021-02-12 00:43:20 +0100 | [diff] [blame] | 4 | #include <amdblocks/ioapic.h> |
Aaron Durbin | 89e51e6 | 2020-04-09 14:16:55 -0600 | [diff] [blame] | 5 | #include <device/pci.h> |
Marshall Dawson | 39c64b0 | 2020-09-04 12:07:27 -0600 | [diff] [blame] | 6 | #include <soc/iomap.h> |
Aaron Durbin | 89e51e6 | 2020-04-09 14:16:55 -0600 | [diff] [blame] | 7 | #include <soc/pci_devs.h> |
| 8 | #include <soc/platform_descriptors.h> |
Chris Wang | 68d68f1 | 2021-02-03 04:32:06 +0800 | [diff] [blame] | 9 | #include <soc/soc_util.h> |
Aaron Durbin | 89e51e6 | 2020-04-09 14:16:55 -0600 | [diff] [blame] | 10 | #include <fsp/api.h> |
| 11 | #include "chip.h" |
Nikolai Vyssotski | b606953 | 2021-03-11 19:29:20 -0600 | [diff] [blame] | 12 | #include <device/pci.h> |
Aaron Durbin | 89e51e6 | 2020-04-09 14:16:55 -0600 | [diff] [blame] | 13 | |
Aaron Durbin | 806ea46 | 2020-04-11 10:06:37 -0600 | [diff] [blame] | 14 | static void fsps_update_emmc_config(FSP_S_CONFIG *scfg, |
| 15 | const struct soc_amd_picasso_config *cfg) |
| 16 | { |
| 17 | int val = SD_DISABLE; |
| 18 | |
Raul E Rangel | 7c79d83 | 2020-09-03 14:30:33 -0600 | [diff] [blame] | 19 | switch (cfg->emmc_config.timing) { |
Aaron Durbin | 806ea46 | 2020-04-11 10:06:37 -0600 | [diff] [blame] | 20 | case SD_EMMC_DISABLE: |
| 21 | val = SD_DISABLE; |
| 22 | break; |
| 23 | case SD_EMMC_SD_LOW_SPEED: |
| 24 | val = SD_LOW_SPEED; |
| 25 | break; |
| 26 | case SD_EMMC_SD_HIGH_SPEED: |
| 27 | val = SD_HIGH_SPEED; |
| 28 | break; |
| 29 | case SD_EMMC_SD_UHS_I_SDR_50: |
| 30 | val = SD_UHS_I_SDR_50; |
| 31 | break; |
| 32 | case SD_EMMC_SD_UHS_I_DDR_50: |
| 33 | val = SD_UHS_I_DDR_50; |
| 34 | break; |
| 35 | case SD_EMMC_SD_UHS_I_SDR_104: |
| 36 | val = SD_UHS_I_SDR_104; |
| 37 | break; |
| 38 | case SD_EMMC_EMMC_SDR_26: |
| 39 | val = EMMC_SDR_26; |
| 40 | break; |
| 41 | case SD_EMMC_EMMC_SDR_52: |
| 42 | val = EMMC_SDR_52; |
| 43 | break; |
Raul E Rangel | f56b784 | 2020-12-04 10:29:56 -0700 | [diff] [blame] | 44 | case SD_EMMC_EMMC_DDR_104: |
| 45 | val = EMMC_DDR_104; |
Aaron Durbin | 806ea46 | 2020-04-11 10:06:37 -0600 | [diff] [blame] | 46 | break; |
| 47 | case SD_EMMC_EMMC_HS200: |
| 48 | val = EMMC_HS200; |
| 49 | break; |
| 50 | case SD_EMMC_EMMC_HS400: |
| 51 | val = EMMC_HS400; |
| 52 | break; |
| 53 | case SD_EMMC_EMMC_HS300: |
| 54 | val = EMMC_HS300; |
| 55 | break; |
| 56 | default: |
| 57 | break; |
| 58 | } |
| 59 | |
| 60 | scfg->emmc0_mode = val; |
Raul E Rangel | 96c704a | 2020-09-23 12:10:02 -0600 | [diff] [blame] | 61 | scfg->emmc0_sdr104_hs400_driver_strength = |
| 62 | cfg->emmc_config.sdr104_hs400_driver_strength; |
| 63 | scfg->emmc0_ddr50_driver_strength = cfg->emmc_config.ddr50_driver_strength; |
| 64 | scfg->emmc0_sdr50_driver_strength = cfg->emmc_config.sdr50_driver_strength; |
| 65 | scfg->emmc0_init_khz_preset = cfg->emmc_config.init_khz_preset; |
Aaron Durbin | 806ea46 | 2020-04-11 10:06:37 -0600 | [diff] [blame] | 66 | } |
| 67 | |
Felix Held | 86db2c7 | 2020-07-21 17:09:31 +0200 | [diff] [blame] | 68 | static void fill_dxio_descriptors(FSP_S_CONFIG *scfg, |
| 69 | const fsp_dxio_descriptor *descs, size_t num) |
Aaron Durbin | 89e51e6 | 2020-04-09 14:16:55 -0600 | [diff] [blame] | 70 | { |
| 71 | size_t i; |
Aaron Durbin | 89e51e6 | 2020-04-09 14:16:55 -0600 | [diff] [blame] | 72 | |
Felix Held | a319ac3 | 2020-07-14 00:52:14 +0200 | [diff] [blame] | 73 | ASSERT_MSG(num <= FSPS_UPD_DXIO_DESCRIPTOR_COUNT, |
| 74 | "Too many DXIO descriptors provided."); |
| 75 | |
Aaron Durbin | 89e51e6 | 2020-04-09 14:16:55 -0600 | [diff] [blame] | 76 | for (i = 0; i < num; i++) { |
Felix Held | f06d7d7 | 2020-07-14 00:23:11 +0200 | [diff] [blame] | 77 | memcpy(scfg->dxio_descriptor[i], &descs[i], sizeof(scfg->dxio_descriptor[0])); |
Aaron Durbin | 89e51e6 | 2020-04-09 14:16:55 -0600 | [diff] [blame] | 78 | } |
| 79 | } |
| 80 | |
| 81 | static void fill_ddi_descriptors(FSP_S_CONFIG *scfg, |
Felix Held | ca428c3 | 2020-06-10 19:05:45 +0200 | [diff] [blame] | 82 | const fsp_ddi_descriptor *descs, size_t num) |
Aaron Durbin | 89e51e6 | 2020-04-09 14:16:55 -0600 | [diff] [blame] | 83 | { |
| 84 | size_t i; |
Aaron Durbin | 89e51e6 | 2020-04-09 14:16:55 -0600 | [diff] [blame] | 85 | |
Felix Held | a319ac3 | 2020-07-14 00:52:14 +0200 | [diff] [blame] | 86 | ASSERT_MSG(num <= FSPS_UPD_DDI_DESCRIPTOR_COUNT, |
| 87 | "Too many DDI descriptors provided."); |
| 88 | |
Aaron Durbin | 89e51e6 | 2020-04-09 14:16:55 -0600 | [diff] [blame] | 89 | for (i = 0; i < num; i++) { |
Felix Held | f06d7d7 | 2020-07-14 00:23:11 +0200 | [diff] [blame] | 90 | memcpy(&scfg->ddi_descriptor[i], &descs[i], sizeof(scfg->ddi_descriptor[0])); |
Aaron Durbin | 89e51e6 | 2020-04-09 14:16:55 -0600 | [diff] [blame] | 91 | } |
| 92 | } |
Felix Held | 7f107b4 | 2020-07-23 19:23:17 +0200 | [diff] [blame] | 93 | |
Aaron Durbin | 89e51e6 | 2020-04-09 14:16:55 -0600 | [diff] [blame] | 94 | static void fsp_fill_pcie_ddi_descriptors(FSP_S_CONFIG *scfg) |
| 95 | { |
Felix Held | 86db2c7 | 2020-07-21 17:09:31 +0200 | [diff] [blame] | 96 | const fsp_dxio_descriptor *fsp_dxio; |
Felix Held | ca428c3 | 2020-06-10 19:05:45 +0200 | [diff] [blame] | 97 | const fsp_ddi_descriptor *fsp_ddi; |
Felix Held | 86db2c7 | 2020-07-21 17:09:31 +0200 | [diff] [blame] | 98 | size_t num_dxio; |
Aaron Durbin | 89e51e6 | 2020-04-09 14:16:55 -0600 | [diff] [blame] | 99 | size_t num_ddi; |
| 100 | |
Felix Held | 86db2c7 | 2020-07-21 17:09:31 +0200 | [diff] [blame] | 101 | mainboard_get_dxio_ddi_descriptors(&fsp_dxio, &num_dxio, |
Aaron Durbin | 89e51e6 | 2020-04-09 14:16:55 -0600 | [diff] [blame] | 102 | &fsp_ddi, &num_ddi); |
Felix Held | 86db2c7 | 2020-07-21 17:09:31 +0200 | [diff] [blame] | 103 | fill_dxio_descriptors(scfg, fsp_dxio, num_dxio); |
Aaron Durbin | 89e51e6 | 2020-04-09 14:16:55 -0600 | [diff] [blame] | 104 | fill_ddi_descriptors(scfg, fsp_ddi, num_ddi); |
| 105 | } |
| 106 | |
Chris Wang | ab3947a | 2020-05-28 21:16:34 +0800 | [diff] [blame] | 107 | static void fsp_usb_oem_customization(FSP_S_CONFIG *scfg, |
| 108 | const struct soc_amd_picasso_config *cfg) |
| 109 | { |
Felix Held | bcb3d03 | 2020-07-24 19:10:03 +0200 | [diff] [blame] | 110 | size_t i; |
| 111 | |
Felix Held | 3a7389e | 2020-07-23 18:22:30 +0200 | [diff] [blame] | 112 | ASSERT(FSPS_UPD_USB2_PORT_COUNT == USB_PORT_COUNT); |
Felix Held | bcb3d03 | 2020-07-24 19:10:03 +0200 | [diff] [blame] | 113 | /* each OC mapping in xhci_oc_pin_select is 4 bit per USB port */ |
| 114 | ASSERT(2 * sizeof(scfg->xhci_oc_pin_select) >= USB_PORT_COUNT); |
Chris Wang | 04dfc26 | 2020-05-19 14:46:35 +0800 | [diff] [blame] | 115 | |
Chris Wang | 3f92902 | 2020-09-14 17:03:06 +0800 | [diff] [blame] | 116 | scfg->fch_usb_3_port_force_gen1 = cfg->usb3_port_force_gen1.usb3_port_force_gen1_en; |
Chris Wang | 04dfc26 | 2020-05-19 14:46:35 +0800 | [diff] [blame] | 117 | |
Felix Held | 1d0154c | 2020-07-23 19:37:42 +0200 | [diff] [blame] | 118 | if (cfg->has_usb2_phy_tune_params) { |
Felix Held | bcb3d03 | 2020-07-24 19:10:03 +0200 | [diff] [blame] | 119 | for (i = 0; i < FSPS_UPD_USB2_PORT_COUNT; i++) { |
Felix Held | 3a7389e | 2020-07-23 18:22:30 +0200 | [diff] [blame] | 120 | memcpy(scfg->fch_usb_2_port_phy_tune[i], |
| 121 | &cfg->usb_2_port_tune_params[i], |
| 122 | sizeof(scfg->fch_usb_2_port_phy_tune[0])); |
| 123 | } |
Felix Held | 1d0154c | 2020-07-23 19:37:42 +0200 | [diff] [blame] | 124 | } |
Felix Held | bcb3d03 | 2020-07-24 19:10:03 +0200 | [diff] [blame] | 125 | |
| 126 | /* lowest nibble of xhci_oc_pin_select corresponds to OC mapping of first USB port */ |
| 127 | for (i = 0; i < USB_PORT_COUNT; i++) { |
| 128 | scfg->xhci_oc_pin_select &= ~(0xf << (i * 4)); |
| 129 | scfg->xhci_oc_pin_select |= |
| 130 | (cfg->usb_port_overcurrent_pin[i] & 0xf) << (i * 4); |
| 131 | } |
Chris Wang | 68d68f1 | 2021-02-03 04:32:06 +0800 | [diff] [blame] | 132 | |
| 133 | if ((get_silicon_type() == SILICON_RV2) && cfg->usb3_phy_override) { |
| 134 | scfg->usb_3_phy_enable = cfg->usb3_phy_override; |
| 135 | for (i = 0; i < FSPS_UPD_RV2_USB3_PORT_COUNT; i++) { |
| 136 | memcpy(scfg->usb_3_port_phy_tune[i], |
| 137 | &cfg->usb3_phy_tune_params[i], |
| 138 | sizeof(scfg->usb_3_port_phy_tune[0])); |
| 139 | } |
| 140 | scfg->usb_3_rx_vref_ctrl = cfg->usb3_rx_vref_ctrl; |
| 141 | scfg->usb_3_rx_vref_ctrl_en = cfg->usb3_rx_vref_ctrl_en; |
| 142 | scfg->usb_3_tx_vboost_lvl = cfg->usb_3_tx_vboost_lvl; |
| 143 | scfg->usb_3_tx_vboost_lvl_en = cfg->usb_3_tx_vboost_lvl_en; |
| 144 | scfg->usb_3_rx_vref_ctrl_x = cfg->usb_3_rx_vref_ctrl_x; |
| 145 | scfg->usb_3_rx_vref_ctrl_en_x = cfg->usb_3_rx_vref_ctrl_en_x; |
| 146 | scfg->usb_3_tx_vboost_lvl_x = cfg->usb_3_tx_vboost_lvl_x; |
| 147 | scfg->usb_3_tx_vboost_lvl_en_x = cfg->usb_3_tx_vboost_lvl_en_x; |
| 148 | } |
Chris Wang | ab3947a | 2020-05-28 21:16:34 +0800 | [diff] [blame] | 149 | } |
| 150 | |
Marshall Dawson | 39c64b0 | 2020-09-04 12:07:27 -0600 | [diff] [blame] | 151 | static void fsp_assign_ioapic_upds(FSP_S_CONFIG *scfg) |
| 152 | { |
Marshall Dawson | 39c64b0 | 2020-09-04 12:07:27 -0600 | [diff] [blame] | 153 | scfg->gnb_ioapic_base = GNB_IO_APIC_ADDR; |
Felix Held | 604ffa6 | 2021-02-12 00:43:20 +0100 | [diff] [blame] | 154 | scfg->gnb_ioapic_id = GNB_IOAPIC_ID; |
| 155 | scfg->fch_ioapic_id = FCH_IOAPIC_ID; |
Marshall Dawson | 39c64b0 | 2020-09-04 12:07:27 -0600 | [diff] [blame] | 156 | } |
| 157 | |
Chris Wang | 4e66d93 | 2020-12-18 14:58:56 +0800 | [diff] [blame] | 158 | static void fsp_edp_tuning_upds(FSP_S_CONFIG *scfg, |
| 159 | const struct soc_amd_picasso_config *cfg) |
| 160 | { |
Chris Wang | 4c4a360 | 2021-02-02 13:04:33 +0800 | [diff] [blame] | 161 | if (cfg->edp_phy_override & ENABLE_EDP_TUNINGSET) { |
| 162 | scfg->edp_phy_override = cfg->edp_phy_override; |
| 163 | scfg->edp_physel = cfg->edp_physel; |
| 164 | scfg->edp_dp_vs_pemph_level = cfg->edp_tuningset.dp_vs_pemph_level; |
| 165 | scfg->edp_margin_deemph = cfg->edp_tuningset.margin_deemph; |
| 166 | scfg->edp_deemph_6db_4 = cfg->edp_tuningset.deemph_6db4; |
| 167 | scfg->edp_boost_adj = cfg->edp_tuningset.boostadj; |
Chris Wang | 4e66d93 | 2020-12-18 14:58:56 +0800 | [diff] [blame] | 168 | } |
Chris Wang | 3ec3cb8 | 2020-12-23 04:29:57 +0800 | [diff] [blame] | 169 | if (cfg->edp_pwr_adjust_enable) { |
| 170 | scfg->pwron_digon_to_de = cfg->pwron_digon_to_de; |
| 171 | scfg->pwron_de_to_varybl = cfg->pwron_de_to_varybl; |
| 172 | scfg->pwrdown_varybloff_to_de = cfg->pwrdown_varybloff_to_de; |
| 173 | scfg->pwrdown_de_to_digoff = cfg->pwrdown_de_to_digoff; |
| 174 | scfg->pwroff_delay = cfg->pwroff_delay; |
| 175 | scfg->pwron_varybl_to_blon = cfg->pwron_varybl_to_blon; |
| 176 | scfg->pwrdown_bloff_to_varybloff = cfg->pwrdown_bloff_to_varybloff; |
| 177 | scfg->min_allowed_bl_level = cfg->min_allowed_bl_level; |
| 178 | } |
Nikolai Vyssotski | 2d24146 | 2021-02-11 20:08:22 -0600 | [diff] [blame] | 179 | } |
Chris Wang | 3ec3cb8 | 2020-12-23 04:29:57 +0800 | [diff] [blame] | 180 | |
Nikolai Vyssotski | 2d24146 | 2021-02-11 20:08:22 -0600 | [diff] [blame] | 181 | static void fsp_assign_vbios_upds(FSP_S_CONFIG *scfg) |
| 182 | { |
Nikolai Vyssotski | b606953 | 2021-03-11 19:29:20 -0600 | [diff] [blame] | 183 | scfg->vbios_buffer_addr = CONFIG(RUN_FSP_GOP) ? PCI_VGA_RAM_IMAGE_START : 0; |
Chris Wang | 4e66d93 | 2020-12-18 14:58:56 +0800 | [diff] [blame] | 184 | } |
| 185 | |
Aaron Durbin | 89e51e6 | 2020-04-09 14:16:55 -0600 | [diff] [blame] | 186 | void platform_fsp_silicon_init_params_cb(FSPS_UPD *supd) |
| 187 | { |
Aaron Durbin | 806ea46 | 2020-04-11 10:06:37 -0600 | [diff] [blame] | 188 | const struct soc_amd_picasso_config *cfg; |
Aaron Durbin | 89e51e6 | 2020-04-09 14:16:55 -0600 | [diff] [blame] | 189 | FSP_S_CONFIG *scfg = &supd->FspsConfig; |
| 190 | |
Aaron Durbin | 806ea46 | 2020-04-11 10:06:37 -0600 | [diff] [blame] | 191 | cfg = config_of_soc(); |
| 192 | fsps_update_emmc_config(scfg, cfg); |
Aaron Durbin | 89e51e6 | 2020-04-09 14:16:55 -0600 | [diff] [blame] | 193 | fsp_fill_pcie_ddi_descriptors(scfg); |
Marshall Dawson | 39c64b0 | 2020-09-04 12:07:27 -0600 | [diff] [blame] | 194 | fsp_assign_ioapic_upds(scfg); |
Chris Wang | ab3947a | 2020-05-28 21:16:34 +0800 | [diff] [blame] | 195 | fsp_usb_oem_customization(scfg, cfg); |
Chris Wang | 4e66d93 | 2020-12-18 14:58:56 +0800 | [diff] [blame] | 196 | fsp_edp_tuning_upds(scfg, cfg); |
Nikolai Vyssotski | 2d24146 | 2021-02-11 20:08:22 -0600 | [diff] [blame] | 197 | fsp_assign_vbios_upds(scfg); |
Aaron Durbin | 89e51e6 | 2020-04-09 14:16:55 -0600 | [diff] [blame] | 198 | } |