Debian Codegraph @

src/mainboard/google/smaug/bootblock.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <device/mmio.h>
4 #include <bootblock_common.h>
5 #include <device/i2c_simple.h>
6 #include <soc/addressmap.h>
7 #include <soc/clk_rst.h>
8 #include <soc/clock.h>
9 #include <soc/funitcfg.h>
10 #include <soc/nvidia/tegra/i2c.h>
11 #include <soc/padconfig.h>
12 #include <soc/pmc.h>
13 #include <soc/power.h>
14 #include <soc/spi.h>
15
16 #include "pmic.h"
17
18 /********************** PMIC **********************************/
19 static const struct pad_config pmic_pads[] = {
20 PAD_CFG_SFIO(PWR_I2C_SCL, PINMUX_INPUT_ENABLE, I2CPMU),
21 PAD_CFG_SFIO(PWR_I2C_SDA, PINMUX_INPUT_ENABLE, I2CPMU),
22 };
23
24 /********************** SPI Flash *****************************/
25 static const struct pad_config spiflash_pads[] = {
26 /* QSPI fLash: mosi, miso, clk, cs0, hold, wp */
27 PAD_CFG_SFIO(QSPI_IO0, PINMUX_INPUT_ENABLE | PINMUX_PULL_UP |
28 PINMUX_DRIVE_2X, QSPI),
29 PAD_CFG_SFIO(QSPI_IO1, PINMUX_INPUT_ENABLE | PINMUX_PULL_UP |
30 PINMUX_DRIVE_2X, QSPI),
31 PAD_CFG_SFIO(QSPI_SCK, PINMUX_INPUT_ENABLE | PINMUX_DRIVE_2X, QSPI),
32 PAD_CFG_SFIO(QSPI_CS_N, PINMUX_INPUT_ENABLE | PINMUX_DRIVE_2X, QSPI),
33 PAD_CFG_SFIO(QSPI_IO2, PINMUX_INPUT_ENABLE | PINMUX_PULL_UP |
34 PINMUX_DRIVE_2X, QSPI),
35 PAD_CFG_SFIO(QSPI_IO3, PINMUX_INPUT_ENABLE | PINMUX_PULL_UP |
36 PINMUX_DRIVE_2X, QSPI),
37 };
38
39 /********************* TPM ************************************/
40 static const struct pad_config tpm_pads[] = {
41 PAD_CFG_SFIO(GEN3_I2C_SCL, PINMUX_INPUT_ENABLE, I2C3),
42 PAD_CFG_SFIO(GEN3_I2C_SDA, PINMUX_INPUT_ENABLE, I2C3),
43 };
44
45 /********************* EC *************************************/
46 static const struct pad_config ec_i2c_pads[] = {
47 PAD_CFG_SFIO(GEN2_I2C_SCL, PINMUX_INPUT_ENABLE, I2C2),
48 PAD_CFG_SFIO(GEN2_I2C_SDA, PINMUX_INPUT_ENABLE, I2C2),
49 };
50
51 /********************* Funits *********************************/
52 static const struct funit_cfg funits[] = {
53 /* PMIC on I2C5 (PWR_I2C* pads) at 400kHz. */
54 FUNIT_CFG(I2C5, PLLP, 400, pmic_pads, ARRAY_SIZE(pmic_pads)),
55 /* SPI flash at 24MHz on QSPI controller. */
56 FUNIT_CFG(QSPI, PLLP, 24000, spiflash_pads, ARRAY_SIZE(spiflash_pads)),
57 /* TPM on I2C3 @ 400kHz */
58 FUNIT_CFG(I2C3, PLLP, 400, tpm_pads, ARRAY_SIZE(tpm_pads)),
59 /* EC on I2C2 - pulled to 3.3V @ 100kHz */
60 FUNIT_CFG(I2C2, PLLP, 100, ec_i2c_pads, ARRAY_SIZE(ec_i2c_pads)),
61 };
62
63 /********************* UART ***********************************/
64 static const struct pad_config uart_console_pads[] = {
65 /* UARTA: tx, rx, rts, cts */
66 PAD_CFG_SFIO(UART1_TX, PINMUX_PULL_NONE, UARTA),
67 PAD_CFG_SFIO(UART1_RX, PINMUX_INPUT_ENABLE | PINMUX_PULL_UP, UARTA),
68 PAD_CFG_SFIO(UART1_RTS, PINMUX_PULL_UP, UARTA),
69 PAD_CFG_SFIO(UART1_CTS, PINMUX_PULL_UP, UARTA),
70 };
71
72 void bootblock_mainboard_early_init(void)
73 {
74 soc_configure_pads(uart_console_pads, ARRAY_SIZE(uart_console_pads));
75 }
76
77 static void set_clock_sources(void)
78 {
79 /* UARTA gets PLLP, deactivate CLK_UART_DIV_OVERRIDE */
80 write32(CLK_RST_REG(clk_src_uarta), PLLP << CLK_SOURCE_SHIFT);
81 }
82
83 /********************* PADs ***********************************/
84 static const struct pad_config padcfgs[] = {
85 /* Board build id bits 1:0 */
86 PAD_CFG_GPIO_INPUT(GPIO_PK1, PINMUX_PULL_NONE),
87 PAD_CFG_GPIO_INPUT(GPIO_PK0, PINMUX_PULL_NONE),
88 };
89
90 void bootblock_mainboard_init(void)
91 {
92 set_clock_sources();
93
94 /* Set up the pads required to load romstage. */
95 soc_configure_pads(padcfgs, ARRAY_SIZE(padcfgs));
96 soc_configure_funits(funits, ARRAY_SIZE(funits));
97
98 /* PMIC */
99 i2c_init(I2CPWR_BUS);
100 pmic_init(I2CPWR_BUS);
101
102 /* TPM */
103 i2c_init(I2C3_BUS);
104
105 /* EC */
106 i2c_init(I2C2_BUS);
107
108 /*
109 * Set power detect override for GPIO, audio & sdmmc3 rails.
110 * GPIO rail override is required to put it into 1.8V mode.
111 */
112 pmc_override_pwr_det(PMC_GPIO_RAIL_AO_MASK | PMC_AUDIO_RAIL_AO_MASK |
113 PMC_SDMMC3_RAIL_AO_MASK, PMC_GPIO_RAIL_AO_DISABLE |
114 PMC_AUDIO_RAIL_AO_DISABLE |
115 PMC_SDMMC3_RAIL_AO_DISABLE);
116 }