summaryrefslogtreecommitdiff
path: root/src/mainboard/google/gru/bootblock.c
blob: c5ab28a7b0ee740d17c2af5e4097c663b599d78d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
 * This file is part of the coreboot project.
 *
 * Copyright 2016 Rockchip Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

#include <arch/io.h>
#include <bootblock_common.h>
#include <console/console.h>
#include <delay.h>
#include <soc/grf.h>
#include <gpio.h>
#include <soc/clock.h>
#include <soc/i2c.h>
#include <soc/pwm.h>
#include <soc/spi.h>
#include <vendorcode/google/chromeos/chromeos.h>

#include "board.h"
#include "pwm_regulator.h"

void bootblock_mainboard_early_init(void)
{
	/* Let gpio2ab io domains works at 1.8V.
	 *
	 * If io_vsel[0] == 0(default value), gpio2ab io domains is 3.0V
	 * powerd by APIO2_VDD, otherwise, 1.8V supplied by APIO2_VDDPST.
	 * But from the schematic of kevin rev0, the APIO2_VDD and
	 * APIO2_VDDPST both are 1.8V(intentionally?).
	 *
	 * So, by default, CPU1_SDIO_PWREN(GPIO2_A2) can't output 3.0V
	 * because the supply is 1.8V.
	 * Let ask GPIO2_A2 output 1.8V to make GPIO interal logic happy.
	 */
	write32(&rk3399_grf->io_vsel, RK_SETBITS(1 << 0));

	/* Scarlet gpio4cd iodomain is 1.8V */
	if (IS_ENABLED(CONFIG_BOARD_GOOGLE_SCARLET))
		write32(&rk3399_grf->io_vsel, RK_SETBITS(1 << 3));

	if (!IS_ENABLED(CONFIG_BOARD_GOOGLE_SCARLET)) {
		/* Enable rails powering GPIO blocks, among other things.
		   These are EC-controlled on Scarlet and already on. */
		gpio_output(GPIO_P15V_EN, 1);
		gpio_output(GPIO_P30V_EN, 1);
	}

#if IS_ENABLED(CONFIG_DRIVERS_UART)
	_Static_assert(CONFIG_CONSOLE_SERIAL_UART_ADDRESS == UART2_BASE,
		       "CONSOLE_SERIAL_UART should be UART2");

	/* iomux: select gpio4c[4:3] as uart2 dbg port */
	write32(&rk3399_grf->iomux_uart2c, IOMUX_UART2C);

	/* grf soc_con7[11:10] use for uart2 select */
	write32(&rk3399_grf->soc_con7, UART2C_SEL);
#endif
}

static void configure_spi_flash(void)
{
	gpio_input(GPIO(1, A, 7));	/* SPI1_MISO remove pull-up */
	gpio_input(GPIO(1, B, 0));	/* SPI1_MOSI remove pull-up */
	gpio_input(GPIO(1, B, 1));	/* SPI1_CLK remove pull-up */
	gpio_input(GPIO(1, B, 2));	/* SPI1_CS remove pull-up */

	rockchip_spi_init(CONFIG_BOOT_DEVICE_SPI_FLASH_BUS, 33*MHz);
	rockchip_spi_set_sample_delay(CONFIG_BOOT_DEVICE_SPI_FLASH_BUS, 5);

	write32(&rk3399_pmugrf->spi1_rxd, IOMUX_SPI1_RX);
	write32(&rk3399_pmugrf->spi1_csclktx, IOMUX_SPI1_CSCLKTX);
}

static void configure_ec(void)
{
	gpio_input(GPIO(2, C, 4));	/* SPI5_MISO remove pull-up */
	gpio_input(GPIO(2, C, 5));	/* SPI5_MOSI remove pull-up */
	gpio_input(GPIO(2, C, 6));	/* SPI5_CLK remove pull-up */
	gpio_input_pullup(GPIO(2, C, 7));	/* SPI5_CS confirm pull-up */

	rockchip_spi_init(CONFIG_EC_GOOGLE_CHROMEEC_SPI_BUS, 3093750);

	write32(&rk3399_grf->iomux_spi5, IOMUX_SPI5);
}

static void configure_tpm(void)
{
	if (IS_ENABLED(CONFIG_GRU_HAS_TPM2)) {
		rockchip_spi_init(CONFIG_DRIVER_TPM_SPI_BUS, 1500*KHz);

		if (IS_ENABLED(CONFIG_BOARD_GOOGLE_SCARLET)) {
			gpio_input(GPIO(2, B, 1));	/* SPI2_MISO no-pull */
			gpio_input(GPIO(2, B, 2));	/* SPI2_MOSI no-pull */
			gpio_input(GPIO(2, B, 3));	/* SPI2_CLK no-pull */
			gpio_input_pullup(GPIO(2, B, 4));	/* SPI2_CS */
			write32(&rk3399_grf->iomux_spi2, IOMUX_SPI2);
		} else {
			gpio_input(GPIO(3, A, 4));	/* SPI0_MISO no-pull */
			gpio_input(GPIO(3, A, 5));	/* SPI0_MOSI no-pull */
			gpio_input(GPIO(3, A, 6));	/* SPI0_CLK no-pull */
			gpio_input_pullup(GPIO(3, A, 7));	/* SPI0_CS */
			write32(&rk3399_grf->iomux_spi0, IOMUX_SPI0);
		}

		gpio_input_irq(GPIO_TPM_IRQ, IRQ_TYPE_EDGE_RISING);
	} else {
		gpio_input(GPIO(1, B, 7));	/* I2C0_SDA remove pull-up */
		gpio_input(GPIO(1, C, 0));	/* I2C0_SCL remove pull-up */

		i2c_init(0, 400*KHz);

		write32(&rk3399_pmugrf->iomux_i2c0_scl, IOMUX_I2C0_SCL);
		write32(&rk3399_pmugrf->iomux_i2c0_sda, IOMUX_I2C0_SDA);
	}
}

static void speed_up_boot_cpu(void)
{
	pwm_regulator_configure(PWM_REGULATOR_LIT, 1150);

	udelay(200);

	rkclk_configure_cpu(APLL_1512_MHZ, CPU_CLUSTER_LITTLE);
}

void bootblock_mainboard_init(void)
{
	speed_up_boot_cpu();

	if (rkclk_was_watchdog_reset())
		reboot_from_watchdog();

	configure_spi_flash();
	configure_ec();
	configure_tpm();

	setup_chromeos_gpios();
}