blob: f7435aae3df8c8f47f3e90ab3a45dd5ed49a8e5f [file] [log] [blame]
Felix Held187f59a2020-12-08 02:25:05 +01001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <amdblocks/acpimmio.h>
4#include <amdblocks/espi.h>
Karthikeyan Ramasubramanian0dbea482021-03-08 23:23:50 -07005#include <amdblocks/i2c.h>
Felix Held187f59a2020-12-08 02:25:05 +01006#include <amdblocks/lpc.h>
Felix Heldbbb8c042021-04-13 19:36:53 +02007#include <amdblocks/pmlib.h>
Felix Held187f59a2020-12-08 02:25:05 +01008#include <amdblocks/smbus.h>
9#include <amdblocks/spi.h>
Felix Held187f59a2020-12-08 02:25:05 +010010#include <soc/i2c.h>
11#include <soc/southbridge.h>
12#include <soc/uart.h>
13#include <types.h>
14
Karthikeyan Ramasubramanian0dbea482021-03-08 23:23:50 -070015#include "chip.h"
16
Felix Held916cd502021-08-04 17:22:36 +020017/* Table to switch SCL pins to outputs to initially reset the I2C peripherals */
Karthikeyan Ramasubramanian0dbea482021-03-08 23:23:50 -070018static const struct soc_i2c_scl_pin i2c_scl_pins[] = {
Felix Held7bbde762021-09-08 00:37:30 +020019 I2C_RESET_SCL_PIN(I2C2_SCL_PIN, GPIO_I2C2_SCL),
20 I2C_RESET_SCL_PIN(I2C3_SCL_PIN, GPIO_I2C3_SCL),
Karthikeyan Ramasubramanian0dbea482021-03-08 23:23:50 -070021 /* I2C4 is a peripheral device only */
22};
23
Felix Held187f59a2020-12-08 02:25:05 +010024static void lpc_configure_decodes(void)
25{
26 if (CONFIG(POST_IO) && (CONFIG_POST_IO_PORT == 0x80))
27 lpc_enable_port80();
28}
29
Karthikeyan Ramasubramanian0dbea482021-03-08 23:23:50 -070030static void reset_i2c_peripherals(void)
31{
32 const struct soc_amd_picasso_config *cfg = config_of_soc();
33 struct soc_i2c_peripheral_reset_info reset_info;
34
35 reset_info.i2c_scl_reset_mask = cfg->i2c_scl_reset & GPIO_I2C_MASK;
36 reset_info.i2c_scl = i2c_scl_pins;
37 reset_info.num_pins = ARRAY_SIZE(i2c_scl_pins);
38 sb_reset_i2c_peripherals(&reset_info);
39}
40
Felix Held187f59a2020-12-08 02:25:05 +010041/* Before console init */
42void fch_pre_init(void)
43{
Felix Held425e73d2021-09-20 16:31:33 +020044 /* Enable_acpimmio_decode_pm04 to enable the ACPIMMIO decode which is needed to access
45 the GPIO registers. */
46 enable_acpimmio_decode_pm04();
Karthikeyan Ramasubramanian2d17ea42021-10-05 13:57:30 -060047 /* Setup SPI base by calling lpc_early_init before setting up eSPI. */
Felix Held187f59a2020-12-08 02:25:05 +010048 lpc_early_init();
Felix Held4e379a22021-10-14 21:43:11 +020049
50 /* Setup eSPI to enable port80 routing if the board is using eSPI and the eSPI
51 interface hasn't already been set up in verstage on PSP */
52 if (CONFIG(SOC_AMD_COMMON_BLOCK_USE_ESPI) && !CONFIG(VBOOT_STARTS_BEFORE_BOOTBLOCK))
53 configure_espi_with_mb_hook();
Felix Held187f59a2020-12-08 02:25:05 +010054
55 if (!CONFIG(SOC_AMD_COMMON_BLOCK_USE_ESPI))
56 lpc_configure_decodes();
57
58 fch_spi_early_init();
Felix Held187f59a2020-12-08 02:25:05 +010059 fch_smbus_init();
60 fch_enable_cf9_io();
61 fch_enable_legacy_io();
62 enable_aoac_devices();
Karthikeyan Ramasubramanian0dbea482021-03-08 23:23:50 -070063 reset_i2c_peripherals();
Felix Held187f59a2020-12-08 02:25:05 +010064
65 /*
66 * On reset Range_0 defaults to enabled. We want to start with a clean
67 * slate to not have things unexpectedly enabled.
68 */
69 clear_uart_legacy_config();
70
Felix Held0dfaf332020-12-09 16:25:18 +010071 if (CONFIG(AMD_SOC_CONSOLE_UART))
Felix Held187f59a2020-12-08 02:25:05 +010072 set_uart_config(CONFIG_UART_FOR_CONSOLE);
Felix Held27b295b2021-03-25 01:20:41 +010073
74 /* disable the keyboard reset function before mainboard GPIO setup */
75 if (CONFIG(DISABLE_KEYBOARD_RESET_PIN))
76 fch_disable_kb_rst();
Felix Held187f59a2020-12-08 02:25:05 +010077}
78
79/* After console init */
80void fch_early_init(void)
81{
Felix Heldbbb8c042021-04-13 19:36:53 +020082 pm_set_power_failure_state();
Felix Held187f59a2020-12-08 02:25:05 +010083 fch_print_pmxc0_status();
84 i2c_soc_early_init();
Martin Rothfd078d82021-08-11 13:27:45 -060085 show_spi_speeds_and_modes();
Felix Held187f59a2020-12-08 02:25:05 +010086
87 if (CONFIG(DISABLE_SPI_FLASH_ROM_SHARING))
88 lpc_disable_spi_rom_sharing();
Felix Held187f59a2020-12-08 02:25:05 +010089}