blob: 2a1b5c971ac6abf572fe540a80d68cfe40e628e4 [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>
10#include <console/console.h>
11#include <soc/i2c.h>
12#include <soc/southbridge.h>
13#include <soc/uart.h>
14#include <types.h>
15
Karthikeyan Ramasubramanian0dbea482021-03-08 23:23:50 -070016#include "chip.h"
17
Felix Held916cd502021-08-04 17:22:36 +020018/* Table to switch SCL pins to outputs to initially reset the I2C peripherals */
Karthikeyan Ramasubramanian0dbea482021-03-08 23:23:50 -070019static const struct soc_i2c_scl_pin i2c_scl_pins[] = {
Felix Held7bbde762021-09-08 00:37:30 +020020 I2C_RESET_SCL_PIN(I2C2_SCL_PIN, GPIO_I2C2_SCL),
21 I2C_RESET_SCL_PIN(I2C3_SCL_PIN, GPIO_I2C3_SCL),
Karthikeyan Ramasubramanian0dbea482021-03-08 23:23:50 -070022 /* I2C4 is a peripheral device only */
23};
24
Felix Held187f59a2020-12-08 02:25:05 +010025static void lpc_configure_decodes(void)
26{
27 if (CONFIG(POST_IO) && (CONFIG_POST_IO_PORT == 0x80))
28 lpc_enable_port80();
29}
30
Karthikeyan Ramasubramanian0dbea482021-03-08 23:23:50 -070031static void reset_i2c_peripherals(void)
32{
33 const struct soc_amd_picasso_config *cfg = config_of_soc();
34 struct soc_i2c_peripheral_reset_info reset_info;
35
36 reset_info.i2c_scl_reset_mask = cfg->i2c_scl_reset & GPIO_I2C_MASK;
37 reset_info.i2c_scl = i2c_scl_pins;
38 reset_info.num_pins = ARRAY_SIZE(i2c_scl_pins);
39 sb_reset_i2c_peripherals(&reset_info);
40}
41
Felix Held187f59a2020-12-08 02:25:05 +010042/* Before console init */
43void fch_pre_init(void)
44{
Felix Held425e73d2021-09-20 16:31:33 +020045 /* Enable_acpimmio_decode_pm04 to enable the ACPIMMIO decode which is needed to access
46 the GPIO registers. */
47 enable_acpimmio_decode_pm04();
Karthikeyan Ramasubramanian2d17ea42021-10-05 13:57:30 -060048 /* Setup SPI base by calling lpc_early_init before setting up eSPI. */
Felix Held187f59a2020-12-08 02:25:05 +010049 lpc_early_init();
Felix Held4e379a22021-10-14 21:43:11 +020050
51 /* Setup eSPI to enable port80 routing if the board is using eSPI and the eSPI
52 interface hasn't already been set up in verstage on PSP */
53 if (CONFIG(SOC_AMD_COMMON_BLOCK_USE_ESPI) && !CONFIG(VBOOT_STARTS_BEFORE_BOOTBLOCK))
54 configure_espi_with_mb_hook();
Felix Held187f59a2020-12-08 02:25:05 +010055
56 if (!CONFIG(SOC_AMD_COMMON_BLOCK_USE_ESPI))
57 lpc_configure_decodes();
58
59 fch_spi_early_init();
Felix Held187f59a2020-12-08 02:25:05 +010060 fch_smbus_init();
61 fch_enable_cf9_io();
62 fch_enable_legacy_io();
63 enable_aoac_devices();
Karthikeyan Ramasubramanian0dbea482021-03-08 23:23:50 -070064 reset_i2c_peripherals();
Felix Held187f59a2020-12-08 02:25:05 +010065
66 /*
67 * On reset Range_0 defaults to enabled. We want to start with a clean
68 * slate to not have things unexpectedly enabled.
69 */
70 clear_uart_legacy_config();
71
Felix Held0dfaf332020-12-09 16:25:18 +010072 if (CONFIG(AMD_SOC_CONSOLE_UART))
Felix Held187f59a2020-12-08 02:25:05 +010073 set_uart_config(CONFIG_UART_FOR_CONSOLE);
Felix Held27b295b2021-03-25 01:20:41 +010074
75 /* disable the keyboard reset function before mainboard GPIO setup */
76 if (CONFIG(DISABLE_KEYBOARD_RESET_PIN))
77 fch_disable_kb_rst();
Felix Held187f59a2020-12-08 02:25:05 +010078}
79
80/* After console init */
81void fch_early_init(void)
82{
Felix Heldbbb8c042021-04-13 19:36:53 +020083 pm_set_power_failure_state();
Felix Held187f59a2020-12-08 02:25:05 +010084 fch_print_pmxc0_status();
85 i2c_soc_early_init();
Martin Rothfd078d82021-08-11 13:27:45 -060086 show_spi_speeds_and_modes();
Felix Held187f59a2020-12-08 02:25:05 +010087
88 if (CONFIG(DISABLE_SPI_FLASH_ROM_SHARING))
89 lpc_disable_spi_rom_sharing();
Felix Held187f59a2020-12-08 02:25:05 +010090}