coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
bootblock.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <device/mmio.h>
4 #include <bootblock_common.h>
5 #include <delay.h>
6 #include <soc/grf.h>
7 #include <gpio.h>
8 #include <soc/clock.h>
9 #include <soc/i2c.h>
10 #include <soc/pwm.h>
11 #include <soc/spi.h>
12 #include <vendorcode/google/chromeos/chromeos.h>
13 
14 #include "board.h"
15 #include "pwm_regulator.h"
16 
18 {
19  /* Configure all programmable IO voltage domains (3D/4A and 2A/2B) early
20  so that we know we can use our GPIOs reliably in following code. */
21  write32(&rk3399_grf->io_vsel, RK_SETBITS(1 << 1 | 1 << 0));
22  /* On Scarlet-based boards, the 4C/4D domain is 1.8V (on others 3.0V) */
23  if (CONFIG(GRU_BASEBOARD_SCARLET))
25 
26  /* Reconfigure GPIO1 from dynamic voltage selection through GPIO0_B1 to
27  hardcoded 1.8V, and change that pin to a normal GPIO. The TRM says
28  this is already the power-on reset, but we all know that TRMs lie. */
29  write32(&rk3399_pmugrf->soc_con0, RK_SETBITS(1 << 9 | 1 << 8));
31 
32  /* Enable rails powering GPIO blocks, among other things. */
34  if (!CONFIG(GRU_BASEBOARD_SCARLET))
35  gpio_output(GPIO_P15V_EN, 1); /* Scarlet: EC-controlled */
36 
37  if (CONFIG(CONSOLE_SERIAL)) {
38  _Static_assert(CONFIG_CONSOLE_SERIAL_UART_ADDRESS == UART2_BASE,
39  "CONSOLE_SERIAL_UART should be UART2");
40 
41  /* iomux: select gpio4c[4:3] as uart2 dbg port */
43 
44  /* grf soc_con7[11:10] use for uart2 select */
46  }
47 }
48 
49 static void configure_spi_flash(void)
50 {
51  gpio_input(GPIO(1, A, 7)); /* SPI1_MISO remove pull-up */
52  gpio_input(GPIO(1, B, 0)); /* SPI1_MOSI remove pull-up */
53  gpio_input(GPIO(1, B, 1)); /* SPI1_CLK remove pull-up */
54  gpio_input(GPIO(1, B, 2)); /* SPI1_CS remove pull-up */
55 
56  rockchip_spi_init(CONFIG_BOOT_DEVICE_SPI_FLASH_BUS, 33*MHz);
57  rockchip_spi_set_sample_delay(CONFIG_BOOT_DEVICE_SPI_FLASH_BUS, 5);
58 
61 }
62 
63 static void configure_ec(void)
64 {
65  gpio_input(GPIO(2, C, 4)); /* SPI5_MISO remove pull-up */
66  gpio_input(GPIO(2, C, 5)); /* SPI5_MOSI remove pull-up */
67  gpio_input(GPIO(2, C, 6)); /* SPI5_CLK remove pull-up */
68  gpio_input_pullup(GPIO(2, C, 7)); /* SPI5_CS confirm pull-up */
69 
70  rockchip_spi_init(CONFIG_EC_GOOGLE_CHROMEEC_SPI_BUS, 3093750);
71 
73 }
74 
75 static void configure_tpm(void)
76 {
77  if (CONFIG(GRU_HAS_TPM2)) {
78  rockchip_spi_init(CONFIG_DRIVER_TPM_SPI_BUS, 1500*KHz);
79 
80  if (CONFIG(GRU_BASEBOARD_SCARLET)) {
81  gpio_input(GPIO(2, B, 1)); /* SPI2_MISO no-pull */
82  gpio_input(GPIO(2, B, 2)); /* SPI2_MOSI no-pull */
83  gpio_input(GPIO(2, B, 3)); /* SPI2_CLK no-pull */
84  gpio_input_pullup(GPIO(2, B, 4)); /* SPI2_CS */
86  } else {
87  gpio_input(GPIO(3, A, 4)); /* SPI0_MISO no-pull */
88  gpio_input(GPIO(3, A, 5)); /* SPI0_MOSI no-pull */
89  gpio_input(GPIO(3, A, 6)); /* SPI0_CLK no-pull */
90  gpio_input_pullup(GPIO(3, A, 7)); /* SPI0_CS */
92  }
93 
95  } else {
96  gpio_input(GPIO(1, B, 7)); /* I2C0_SDA remove pull-up */
97  gpio_input(GPIO(1, C, 0)); /* I2C0_SCL remove pull-up */
98 
99  i2c_init(0, 400*KHz);
100 
103  }
104 }
105 
106 static void speed_up_boot_cpu(void)
107 {
109 
110  udelay(200);
111 
113 }
114 
116 {
118 
120  reboot_from_watchdog();
121 
123  configure_ec();
124  configure_tpm();
125 
127 }
static void write32(void *addr, uint32_t val)
Definition: mmio.h:40
#define MHz
Definition: helpers.h:80
#define KHz
Definition: helpers.h:79
@ GPIO
Definition: chip.h:84
@ CONFIG
Definition: dsi_common.h:201
void setup_chromeos_gpios(void)
Definition: chromeos.c:10
#define GPIO_P15V_EN
Definition: board.h:30
#define GPIO_P30V_EN
Definition: board.h:32
#define GPIO_TPM_IRQ
Definition: board.h:35
void gpio_input(gpio_t gpio)
Definition: gpio.c:189
void gpio_output(gpio_t gpio, int value)
Definition: gpio.c:194
void gpio_input_pullup(gpio_t gpio)
Definition: gpio.c:184
__weak void bootblock_mainboard_init(void)
Definition: bootblock.c:19
__weak void bootblock_mainboard_early_init(void)
Definition: bootblock.c:16
static void configure_spi_flash(void)
Definition: bootblock.c:49
static void configure_ec(void)
Definition: bootblock.c:63
static void speed_up_boot_cpu(void)
Definition: bootblock.c:106
static void configure_tpm(void)
Definition: bootblock.c:75
_Static_assert(sizeof(hls_t)==HLS_SIZE, "HLS_SIZE must equal to sizeof(hls_t)")
@ IRQ_TYPE_EDGE_RISING
Definition: gpio_common.h:55
void pwm_regulator_configure(enum pwm_regulator pwm, int millivolt)
Definition: pwm_regulator.c:60
@ PWM_REGULATOR_LIT
Definition: pwm_regulator.h:9
#define IOMUX_SPI0
Definition: grf.h:190
#define IOMUX_I2C0_SDA
Definition: grf.h:344
#define UART2C_SEL
Definition: grf.h:325
#define IOMUX_UART2C
Definition: grf.h:331
#define IOMUX_SPI5
Definition: grf.h:339
#define IOMUX_I2C0_SCL
Definition: grf.h:343
#define IOMUX_SPI1_CSCLKTX
Definition: grf.h:335
#define IOMUX_SPI1_RX
Definition: grf.h:334
static struct rk3399_pmugrf_regs *const rk3399_pmugrf
Definition: grf.h:320
static struct rk3399_grf_regs *const rk3399_grf
Definition: grf.h:319
#define IOMUX_SPI2
Definition: grf.h:337
#define RK_CLRBITS(clr)
Definition: soc.h:10
#define RK_SETBITS(set)
Definition: soc.h:9
void i2c_init(unsigned int bus)
Definition: i2c.c:198
void gpio_input_irq(gpio_t gpio, enum gpio_irq_type type, uint32_t pull)
Definition: gpio.c:65
@ GPIO_PULLUP
Definition: gpio.h:63
void rockchip_spi_set_sample_delay(unsigned int bus, unsigned int delay_ns)
Definition: spi.c:122
void rockchip_spi_init(unsigned int bus, unsigned int speed_hz)
Definition: spi.c:84
void rkclk_configure_cpu(enum apll_frequencies apll_freq)
Definition: clock.c:309
int rkclk_was_watchdog_reset(void)
Definition: clock.c:652
#define UART2_BASE
Definition: addressmap.h:45
@ APLL_1512_MHZ
Definition: clock.h:87
@ CPU_CLUSTER_LITTLE
Definition: clock.h:92
u32 iomux_spi0
Definition: grf.h:118
u32 iomux_uart2c
Definition: grf.h:139
u32 io_vsel
Definition: grf.h:172
u32 iomux_spi2
Definition: grf.h:108
u32 soc_con7
Definition: grf.h:161
u32 iomux_spi5
Definition: grf.h:113
u32 iomux_i2c0_scl
Definition: grf.h:211
u32 gpio0b_iomux
Definition: grf.h:196
u32 iomux_i2c0_sda
Definition: grf.h:206
u32 spi1_csclktx
Definition: grf.h:204
void udelay(uint32_t us)
Definition: udelay.c:15