blob: 187b2ef953d2235247cb5b4577d5dfc5b5d37773 [file] [log] [blame]
Mathew King2e2fc7a2020-12-08 11:33:58 -07001/* SPDX-License-Identifier: GPL-2.0-only */
2
Mathew King156be2d2021-03-19 11:39:14 -06003#include <amdblocks/acpimmio.h>
Martin Roth53435ea2021-06-25 15:28:43 -06004#include <amdblocks/espi.h>
Raul E Rangelabbb5b52021-08-19 11:43:29 -06005#include <amdblocks/lpc.h>
Mathew King2e2fc7a2020-12-08 11:33:58 -07006#include <bootblock_common.h>
7#include <baseboard/variants.h>
Mathew King156be2d2021-03-19 11:39:14 -06008#include <console/console.h>
Martin Roth324cea92021-05-03 16:21:11 -06009#include <delay.h>
Mathew King156be2d2021-03-19 11:39:14 -060010#include <device/pci_ops.h>
Raul E Rangelabbb5b52021-08-19 11:43:29 -060011#include <soc/lpc.h>
Mathew King156be2d2021-03-19 11:39:14 -060012#include <soc/pci_devs.h>
Raul E Rangelabbb5b52021-08-19 11:43:29 -060013#include <soc/southbridge.h>
Martin Roth324cea92021-05-03 16:21:11 -060014#include <timer.h>
15
16#define FC350_PCIE_INIT_DELAY_US (20 * USECS_PER_MSEC)
17struct stopwatch pcie_init_timeout_sw;
Mathew King2e2fc7a2020-12-08 11:33:58 -070018
Martin Roth53435ea2021-06-25 15:28:43 -060019void 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 King2e2fc7a2020-12-08 11:33:58 -070031void bootblock_mainboard_early_init(void)
32{
Mathew King156be2d2021-03-19 11:39:14 -060033 uint32_t dword;
Martin Roth324cea92021-05-03 16:21:11 -060034 size_t base_num_gpios, override_num_gpios;
35 const struct soc_amd_gpio *base_gpios, *override_gpios;
Mathew King10dd7752021-01-26 16:08:14 -070036
Felix Helda30ad9f2021-10-14 21:58:03 +020037 /* 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 Rangelabbb5b52021-08-19 11:43:29 -060039 dword = pci_read_config32(SOC_LPC_DEV, LPC_MISC_CONTROL_BITS);
Felix Held0cd81c32021-09-30 18:01:18 +020040 dword &= ~(LPC_LDRQ0_PU_EN | LPC_LDRQ1_EN | LPC_LDRQ0_EN);
Raul E Rangelabbb5b52021-08-19 11:43:29 -060041 dword |= LPC_LDRQ0_PD_EN;
42 pci_write_config32(SOC_LPC_DEV, LPC_MISC_CONTROL_BITS, dword);
43
Felix Held718a3cb2021-10-12 21:39:47 +020044 /*
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 King156be2d2021-03-19 11:39:14 -060049
Martin Roth40d2c042021-08-31 17:56:38 -060050 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 Held8b17cb82021-10-01 20:59:25 +020063
64 /* Early eSPI interface configuration */
Martin Roth40d2c042021-08-31 17:56:38 -060065
Felix Heldf9014bb2021-11-03 05:20:53 +010066 /* Use SPI2 pins for eSPI */
Raul E Rangelabbb5b52021-08-19 11:43:29 -060067 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 King156be2d2021-03-19 11:39:14 -060070
Felix Heldc3a9e532021-09-30 20:46:15 +020071 /* Switch the pads that can be used as either LPC or secondary eSPI to 1.8V mode */
Raul E Rangelabbb5b52021-08-19 11:43:29 -060072 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 Roth455e07e2021-05-20 17:22:28 -060075}
Mathew King156be2d2021-03-19 11:39:14 -060076
Martin Roth455e07e2021-05-20 17:22:28 -060077void bootblock_mainboard_init(void)
78{
Martin Roth324cea92021-05-03 16:21:11 -060079 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 Jian49df72a2021-04-08 13:37:47 +0800104 if (variant_has_fpmcu())
105 variant_fpmcu_reset();
Mathew King2e2fc7a2020-12-08 11:33:58 -0700106}