aboutsummaryrefslogtreecommitdiff
path: root/src/mainboard/google/rush_ryu/mainboard.c
blob: 81c15b47d8f8c3c412438e1f29d0a0e8f101f3e0 (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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/*
 * This file is part of the coreboot project.
 *
 * Copyright 2014 Google 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.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include <arch/mmu.h>
#include <boardid.h>
#include <boot/coreboot_tables.h>
#include <cbmem.h>
#include <delay.h>
#include <device/device.h>
#include <elog.h>
#include <memrange.h>
#include <soc/addressmap.h>
#include <soc/clk_rst.h>
#include <soc/clock.h>
#include <soc/funitcfg.h>
#include <soc/nvidia/tegra/i2c.h>
#include <soc/padconfig.h>
#include <vendorcode/google/chromeos/chromeos.h>
#if IS_ENABLED(CONFIG_CHROMEOS)
#include <vboot_struct.h>
#include <vendorcode/google/chromeos/vboot_handoff.h>
#include <vendorcode/google/chromeos/vboot2/misc.h>
#endif

#include "gpio.h"
#include "pmic.h"

static const struct pad_config mmcpads[] = {
	/* MMC4 (eMMC) */
	PAD_CFG_SFIO(SDMMC4_CLK, PINMUX_INPUT_ENABLE|PINMUX_PULL_DOWN, SDMMC4),
	PAD_CFG_SFIO(SDMMC4_CMD, PINMUX_INPUT_ENABLE|PINMUX_PULL_UP, SDMMC4),
	PAD_CFG_SFIO(SDMMC4_DAT0, PINMUX_INPUT_ENABLE|PINMUX_PULL_UP, SDMMC4),
	PAD_CFG_SFIO(SDMMC4_DAT1, PINMUX_INPUT_ENABLE|PINMUX_PULL_UP, SDMMC4),
	PAD_CFG_SFIO(SDMMC4_DAT2, PINMUX_INPUT_ENABLE|PINMUX_PULL_UP, SDMMC4),
	PAD_CFG_SFIO(SDMMC4_DAT3, PINMUX_INPUT_ENABLE|PINMUX_PULL_UP, SDMMC4),
	PAD_CFG_SFIO(SDMMC4_DAT4, PINMUX_INPUT_ENABLE|PINMUX_PULL_UP, SDMMC4),
	PAD_CFG_SFIO(SDMMC4_DAT5, PINMUX_INPUT_ENABLE|PINMUX_PULL_UP, SDMMC4),
	PAD_CFG_SFIO(SDMMC4_DAT6, PINMUX_INPUT_ENABLE|PINMUX_PULL_UP, SDMMC4),
	PAD_CFG_SFIO(SDMMC4_DAT7, PINMUX_INPUT_ENABLE|PINMUX_PULL_UP, SDMMC4),
};

static const struct pad_config audio_codec_pads[] = {
	/* H1 is CODEC_RST_L and R2(ROW2) is AUDIO_ENABLE */
	PAD_CFG_GPIO_OUT1(GPIO_PH1, PINMUX_PULL_DOWN),
	PAD_CFG_GPIO_OUT1(KB_ROW2, PINMUX_PULL_DOWN),
};

static const struct funit_cfg funits[] = {
	/* MMC on SDMMC4 controller at 48MHz. */
	FUNIT_CFG(SDMMC4, PLLP, 48000, mmcpads, ARRAY_SIZE(mmcpads)),
	/* I2C6 for audio, temp sensor, etc. Enable codec via GPIOs/muxes */
	FUNIT_CFG(I2C6, PLLP, 400, audio_codec_pads, ARRAY_SIZE(audio_codec_pads)),
	FUNIT_CFG_USB(USBD),
};

/* HACK: For proto boards before proto3, we want to disable ec sw sync */
static void fix_ec_sw_sync(void)
{
#if IS_ENABLED(CONFIG_CHROMEOS)
	struct vboot_handoff *vh;

	if (board_id() >= BOARD_ID_PROTO_3)
		return;

	vh = cbmem_find(CBMEM_ID_VBOOT_HANDOFF);

	if (vh == NULL) {
		printk(BIOS_ERR, "No vboot handoff struct found\n");
		return;
	}

	VbSharedDataHeader *vb_sd = (VbSharedDataHeader *)vh->shared_data;
	vb_sd->flags &= ~VBSD_EC_SOFTWARE_SYNC;
#endif
}

static const struct pad_config lcd_gpio_padcfgs[] = {
	/* LCD_EN */
	PAD_CFG_GPIO_OUT0(GPIO_PH5, PINMUX_PULL_UP),
	/* LCD_RST_L */
	PAD_CFG_GPIO_OUT0(GPIO_PH3, PINMUX_PULL_UP),
	/* EN_VDD_LCD */
	PAD_CFG_GPIO_OUT0(GPIO_PBB6, PINMUX_PULL_NONE),
	/* EN_VDD18_LCD */
	PAD_CFG_GPIO_OUT0(DVFS_PWM, PINMUX_PULL_DOWN),
};

static void configure_display_clocks(void)
{
	u32 lclks = CLK_L_HOST1X | CLK_L_DISP1;	/* dc */
	u32 hclks = CLK_H_MIPI_CAL | CLK_H_DSI; /* mipi phy, mipi-dsi a */
	u32 uclks = CLK_U_DSIB;			/* mipi-dsi b */
	u32 xclks = CLK_X_CLK72MHZ;		/* clk src of mipi_cal */

	clock_enable_clear_reset(lclks, hclks, uclks, 0, 0, xclks);

	/* Give clocks time to stabilize. */
	udelay(IO_STABILIZATION_DELAY);
}

static int enable_lcd_vdd(void)
{
	uint8_t data;

	/* Set 1.20V to power AVDD_DSI_CSI */
	pmic_write_reg(I2CPWR_BUS, TI65913_LDO5_VOLTAGE,
			VSEL_1200, 1);
	pmic_write_reg(I2CPWR_BUS, TI65913_LDO5_CTRL,
			TI65913_MODE_ACTIVE_ON, 1);
	/* wait for 100ms */
	mdelay(100);

	/*
	 * Enable VDD_LCD
	 *
	 * Use different GPIO based on board id
	 */
	switch (board_id()) {
	case BOARD_ID_PROTO_0:
		/* Select PMIC GPIO_6's primary function */
		pmic_read_reg(I2CPWR_BUS, TI65913_PAD2, &data);
		pmic_write_reg(I2CPWR_BUS, TI65913_PAD2,
				 PAD2_GPIO_6_PRIMARY(data), 0);

		/* Set PMIC_GPIO_6 as output */
		pmic_read_reg(I2CPWR_BUS, TI65913_GPIO_DATA_DIR, &data);
		pmic_write_reg(I2CPWR_BUS, TI65913_GPIO_DATA_DIR,
				TI65913_GPIO_6_OUTPUT, 0);

		/* Set PMIC_GPIO_6 output high */
		pmic_read_reg(I2CPWR_BUS, TI65913_GPIO_DATA_OUT, &data);
		pmic_write_reg(I2CPWR_BUS, TI65913_GPIO_DATA_OUT,
				TI65913_GPIO_6_HIGH, 1);
		break;
	case BOARD_ID_PROTO_1:
	case BOARD_ID_PROTO_3:
		gpio_set(EN_VDD_LCD, 1);
		break;
	default: /* unknown board */
		return -1;
	}
	/* wait for 2ms */
	mdelay(2);

	/* Enable PP1800_LCDIO to panel */
	gpio_set(EN_VDD18_LCD, 1);
	/* wait for 1ms */
	mdelay(1);

	/* Set panel EN and RST signals */
	gpio_set(LCD_EN, 1);		/* enable */
	/* wait for min 10ms */
	mdelay(10);
	gpio_set(LCD_RST_L, 1);		/* clear reset */
	/* wait for min 3ms */
	mdelay(3);

	return 0;
}

static int configure_display_blocks(void)
{
	/* set and enable panel related vdd */
	if (enable_lcd_vdd())
		return -1;

	/* enable display related clocks */
	configure_display_clocks();

	return 0;
}

/* Audio init: clocks and enables/resets */
static void setup_audio(void)
{
	/* External peripheral 1: audio codec (RT5677) using 12MHz CLK1 */
	clock_configure_source(extperiph1, CLK_M, 12000);

	/*
	* We need 1.5MHz for I2S1. So, we use CLK_M. CLK_DIVIDER macro
	* returns a divisor (0xe) a little bit off from the ideal value (0xd),
	* but it's good enough for beeps.
	*/
	clock_configure_source(i2s1, CLK_M, 1500);

	clock_external_output(1);	/* For external RT5677 audio codec. */

	/*
	* Confirmed by NVIDIA hardware team, we need to take ALL audio devices
	* connected to AHUB (AUDIO, APBIF, I2S, DAM, AMX, ADX, SPDIF, AFC) out
	* of reset and clock-enabled, otherwise reading AHUB devices (in our
	* case, I2S/APBIF/AUDIO<XBAR>) will hang.
	*/
	clock_enable_audio();
}

static void mainboard_init(device_t dev)
{
	soc_configure_funits(funits, ARRAY_SIZE(funits));

	/* I2C6 bus (audio, etc.) */
	soc_configure_i2c6pad();
	i2c_init(I2C6_BUS);

	setup_audio();

	elog_init();
	elog_add_boot_reason();

	fix_ec_sw_sync();

	/* configure panel gpio pads */
	soc_configure_pads(lcd_gpio_padcfgs, ARRAY_SIZE(lcd_gpio_padcfgs));

	/* if panel needs to bringup */
	if (!vboot_skip_display_init())
		configure_display_blocks();
}

static void mainboard_enable(device_t dev)
{
	dev->ops->init = &mainboard_init;
}

struct chip_operations mainboard_ops = {
	.name   = "rush_ryu",
	.enable_dev = mainboard_enable,
};