Mathew King | 2e2fc7a | 2020-12-08 11:33:58 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
Mathew King | 156be2d | 2021-03-19 11:39:14 -0600 | [diff] [blame] | 3 | #include <amdblocks/acpimmio.h> |
Martin Roth | 53435ea | 2021-06-25 15:28:43 -0600 | [diff] [blame] | 4 | #include <amdblocks/espi.h> |
Raul E Rangel | abbb5b5 | 2021-08-19 11:43:29 -0600 | [diff] [blame] | 5 | #include <amdblocks/lpc.h> |
Mathew King | 2e2fc7a | 2020-12-08 11:33:58 -0700 | [diff] [blame] | 6 | #include <bootblock_common.h> |
| 7 | #include <baseboard/variants.h> |
Mathew King | 156be2d | 2021-03-19 11:39:14 -0600 | [diff] [blame] | 8 | #include <console/console.h> |
Martin Roth | 324cea9 | 2021-05-03 16:21:11 -0600 | [diff] [blame] | 9 | #include <delay.h> |
Mathew King | 156be2d | 2021-03-19 11:39:14 -0600 | [diff] [blame] | 10 | #include <device/pci_ops.h> |
Raul E Rangel | abbb5b5 | 2021-08-19 11:43:29 -0600 | [diff] [blame] | 11 | #include <soc/lpc.h> |
Mathew King | 156be2d | 2021-03-19 11:39:14 -0600 | [diff] [blame] | 12 | #include <soc/pci_devs.h> |
Raul E Rangel | abbb5b5 | 2021-08-19 11:43:29 -0600 | [diff] [blame] | 13 | #include <soc/southbridge.h> |
Martin Roth | 324cea9 | 2021-05-03 16:21:11 -0600 | [diff] [blame] | 14 | #include <timer.h> |
| 15 | |
| 16 | #define FC350_PCIE_INIT_DELAY_US (20 * USECS_PER_MSEC) |
| 17 | struct stopwatch pcie_init_timeout_sw; |
Mathew King | 2e2fc7a | 2020-12-08 11:33:58 -0700 | [diff] [blame] | 18 | |
Martin Roth | 53435ea | 2021-06-25 15:28:43 -0600 | [diff] [blame] | 19 | void mb_set_up_early_espi(void) |
| 20 | { |
| 21 | /* |
| 22 | * We don't need to initialize all of the GPIOs that are done |
| 23 | * in bootblock_mainboard_early_init(), but we need to release |
| 24 | * the EC eSPI reset and do the rest of the configuration. |
| 25 | * |
| 26 | * This will not be present in the normal boot flow. |
| 27 | */ |
| 28 | bootblock_mainboard_early_init(); |
| 29 | } |
| 30 | |
Mathew King | 2e2fc7a | 2020-12-08 11:33:58 -0700 | [diff] [blame] | 31 | void bootblock_mainboard_early_init(void) |
| 32 | { |
Mathew King | 156be2d | 2021-03-19 11:39:14 -0600 | [diff] [blame] | 33 | uint32_t dword; |
Martin Roth | 324cea9 | 2021-05-03 16:21:11 -0600 | [diff] [blame] | 34 | size_t base_num_gpios, override_num_gpios; |
| 35 | const struct soc_amd_gpio *base_gpios, *override_gpios; |
Mathew King | 10dd775 | 2021-01-26 16:08:14 -0700 | [diff] [blame] | 36 | |
Felix Held | a30ad9f | 2021-10-14 21:58:03 +0200 | [diff] [blame] | 37 | /* Beware that the bit definitions for LPC_LDRQ0_PU_EN and LPC_LDRQ0_PD_EN are swapped |
| 38 | on Picasso and older compared to Renoir/Cezanne and newer */ |
Raul E Rangel | abbb5b5 | 2021-08-19 11:43:29 -0600 | [diff] [blame] | 39 | dword = pci_read_config32(SOC_LPC_DEV, LPC_MISC_CONTROL_BITS); |
Felix Held | 0cd81c3 | 2021-09-30 18:01:18 +0200 | [diff] [blame] | 40 | dword &= ~(LPC_LDRQ0_PU_EN | LPC_LDRQ1_EN | LPC_LDRQ0_EN); |
Raul E Rangel | abbb5b5 | 2021-08-19 11:43:29 -0600 | [diff] [blame] | 41 | dword |= LPC_LDRQ0_PD_EN; |
| 42 | pci_write_config32(SOC_LPC_DEV, LPC_MISC_CONTROL_BITS, dword); |
| 43 | |
Felix Held | 718a3cb | 2021-10-12 21:39:47 +0200 | [diff] [blame] | 44 | /* |
| 45 | * All LPC decodes need to be cleared before we can configure the LPC pads as secondary |
| 46 | * eSPI interface that gets used for the EC communication. This is already done by |
| 47 | * lpc_disable_decodes that gets called before this function. |
| 48 | */ |
Mathew King | 156be2d | 2021-03-19 11:39:14 -0600 | [diff] [blame] | 49 | |
Martin Roth | 40d2c04 | 2021-08-31 17:56:38 -0600 | [diff] [blame] | 50 | if (CONFIG(VBOOT_STARTS_BEFORE_BOOTBLOCK)) |
| 51 | return; |
| 52 | |
| 53 | base_gpios = variant_early_gpio_table(&base_num_gpios); |
| 54 | override_gpios = variant_early_override_gpio_table(&override_num_gpios); |
| 55 | |
| 56 | gpio_configure_pads_with_override(base_gpios, base_num_gpios, |
| 57 | override_gpios, override_num_gpios); |
| 58 | |
| 59 | /* Set a timer to make sure there's enough delay for |
| 60 | * the Fibocom 350 PCIe init |
| 61 | */ |
| 62 | stopwatch_init_usecs_expire(&pcie_init_timeout_sw, FC350_PCIE_INIT_DELAY_US); |
Felix Held | 8b17cb8 | 2021-10-01 20:59:25 +0200 | [diff] [blame] | 63 | |
| 64 | /* Early eSPI interface configuration */ |
Martin Roth | 40d2c04 | 2021-08-31 17:56:38 -0600 | [diff] [blame] | 65 | |
Felix Held | f9014bb | 2021-11-03 05:20:53 +0100 | [diff] [blame^] | 66 | /* Use SPI2 pins for eSPI */ |
Raul E Rangel | abbb5b5 | 2021-08-19 11:43:29 -0600 | [diff] [blame] | 67 | dword = pm_read32(PM_SPI_PAD_PU_PD); |
| 68 | dword |= PM_ESPI_CS_USE_DATA2; |
| 69 | pm_write32(PM_SPI_PAD_PU_PD, dword); |
Mathew King | 156be2d | 2021-03-19 11:39:14 -0600 | [diff] [blame] | 70 | |
Felix Held | c3a9e53 | 2021-09-30 20:46:15 +0200 | [diff] [blame] | 71 | /* Switch the pads that can be used as either LPC or secondary eSPI to 1.8V mode */ |
Raul E Rangel | abbb5b5 | 2021-08-19 11:43:29 -0600 | [diff] [blame] | 72 | dword = pm_read32(PM_ACPI_CONF); |
| 73 | dword |= PM_ACPI_S5_LPC_PIN_MODE | PM_ACPI_S5_LPC_PIN_MODE_SEL; |
| 74 | pm_write32(PM_ACPI_CONF, dword); |
Martin Roth | 455e07e | 2021-05-20 17:22:28 -0600 | [diff] [blame] | 75 | } |
Mathew King | 156be2d | 2021-03-19 11:39:14 -0600 | [diff] [blame] | 76 | |
Martin Roth | 455e07e | 2021-05-20 17:22:28 -0600 | [diff] [blame] | 77 | void bootblock_mainboard_init(void) |
| 78 | { |
Martin Roth | 324cea9 | 2021-05-03 16:21:11 -0600 | [diff] [blame] | 79 | size_t base_num_gpios, override_num_gpios; |
| 80 | const struct soc_amd_gpio *base_gpios, *override_gpios; |
| 81 | int i = 0; |
| 82 | |
| 83 | /* Make sure that at least 20ms has elapsed since enabling WWAN power |
| 84 | * in bootblock_mainboard_early_init. |
| 85 | * This is only applicable if verstage is not in the PSP and the board |
| 86 | * is using the fibocom 350 WLAN card, so this typically will not be hit. |
| 87 | */ |
| 88 | if (!CONFIG(VBOOT_STARTS_BEFORE_BOOTBLOCK) && variant_has_pcie_wwan()) { |
| 89 | while (!stopwatch_expired(&pcie_init_timeout_sw)) { |
| 90 | mdelay(1); |
| 91 | i++; |
| 92 | }; |
| 93 | if (i) |
| 94 | printk(BIOS_DEBUG, "Delayed %d ms for PCIe\n", i); |
| 95 | } |
| 96 | |
| 97 | base_gpios = variant_bootblock_gpio_table(&base_num_gpios); |
| 98 | override_gpios = variant_bootblock_override_gpio_table(&override_num_gpios); |
| 99 | |
| 100 | gpio_configure_pads_with_override(base_gpios, base_num_gpios, override_gpios, |
| 101 | override_num_gpios); |
| 102 | |
| 103 | /* FPMCU check needs to happen after EC initialization for FW_CONFIG bits */ |
Ivy Jian | 49df72a | 2021-04-08 13:37:47 +0800 | [diff] [blame] | 104 | if (variant_has_fpmcu()) |
| 105 | variant_fpmcu_reset(); |
Mathew King | 2e2fc7a | 2020-12-08 11:33:58 -0700 | [diff] [blame] | 106 | } |