blob: c330fac4a04834bdf74c431c5a0929465ece22ae [file] [log] [blame]
Yidi Lin3d7b6062015-07-31 17:10:40 +08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2015 MediaTek Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Yidi Lin3d7b6062015-07-31 17:10:40 +080014 */
15
16#include <arch/cache.h>
17#include <arch/io.h>
18#include <boardid.h>
19#include <boot/coreboot_tables.h>
Koro Chen9733ba52015-07-31 17:11:04 +080020#include <delay.h>
Yidi Lin3d7b6062015-07-31 17:10:40 +080021#include <device/device.h>
22
CC Ma72980b12015-09-15 17:33:38 +080023#include <elog.h>
Koro Chen9733ba52015-07-31 17:11:04 +080024#include <gpio.h>
Jimmy Huang27eba672015-07-31 17:11:00 +080025#include <soc/bl31_plat_params.h>
jun.gaof059e972015-12-17 16:59:55 +080026#include <soc/i2c.h>
Koro Chen9733ba52015-07-31 17:11:04 +080027#include <soc/mt6391.h>
28#include <soc/mtcmos.h>
29#include <soc/pinmux.h>
30#include <soc/pll.h>
Ben Loka7379402015-07-31 17:11:11 +080031#include <soc/usb.h>
CC Ma72980b12015-09-15 17:33:38 +080032#include <vendorcode/google/chromeos/chromeos.h>
Koro Chen9733ba52015-07-31 17:11:04 +080033
Jimmy Huang27eba672015-07-31 17:11:00 +080034static void register_da9212_to_bl31(void)
35{
36#if IS_ENABLED(CONFIG_ARM64_USE_ARM_TRUSTED_FIRMWARE)
37 static struct bl31_da9212_param param_da9212 = {
38 .h = {
39 .type = PARAM_CLUSTER1_DA9212,
40 },
41 .i2c_bus = 1,
42 .ic_en = {
43 .type = PARAM_GPIO_SOC,
44 .polarity = PARAM_GPIO_ACTIVE_HIGH,
45 .index = PAD_UCTS2,
46 },
47 .en_a = {
48 .type = PARAM_GPIO_MT6391,
49 .polarity = PARAM_GPIO_ACTIVE_HIGH,
50 .index = MT6391_KP_ROW4,
51 },
52 .en_b = {
53 .type = PARAM_GPIO_NONE,
54 },
55 };
56 register_bl31_param(&param_da9212.h);
jun.gaof059e972015-12-17 16:59:55 +080057
58 /* Init i2c bus Timing register for da9212 */
59 mtk_i2c_bus_init(param_da9212.i2c_bus);
Jimmy Huang27eba672015-07-31 17:11:00 +080060#endif
61}
62
63static void register_mt6311_to_bl31(void)
64{
65#if IS_ENABLED(CONFIG_ARM64_USE_ARM_TRUSTED_FIRMWARE)
66 static struct bl31_mt6311_param param_mt6311 = {
67 .h = {
68 .type = PARAM_CLUSTER1_MT6311,
69 },
70 .i2c_bus = 1,
71 };
72 register_bl31_param(&param_mt6311.h);
jun.gaof059e972015-12-17 16:59:55 +080073
74 /* Init i2c bus Timing register for mt6311 */
75 mtk_i2c_bus_init(param_mt6311.i2c_bus);
Jimmy Huang27eba672015-07-31 17:11:00 +080076#endif
77}
78
79static void configure_bl31(void)
80{
81 switch (board_id()) {
82 case 2:
83 register_da9212_to_bl31();
84 break;
85 default:
86 /* rev-3 and rev-4 use mt6311 as external buck */
87 register_mt6311_to_bl31();
88 break;
89 }
90}
91
Koro Chen9733ba52015-07-31 17:11:04 +080092static void configure_audio(void)
93{
94 mtcmos_audio_power_on();
95
96 /* regulator for codecs */
97 switch (board_id()) {
98 case 0:
99 /* vgp1 set to 1.22V */
100 mt6391_configure_ldo(LDO_VCAMD, LDO_1P22);
101 /* vgp4 set to 1.8V */
102 mt6391_configure_ldo(LDO_VGP4, LDO_1P8);
103 break;
104 default:
105 /* board from Rev1 */
106 /* vgp1 set to 1.8V */
107 mt6391_configure_ldo(LDO_VCAMD, LDO_1P8);
108 /* delay 1ms for realtek's power sequence request */
109 mdelay(1);
110 /* vcama set to 1.8V */
111 mt6391_configure_ldo(LDO_VCAMA, LDO_1P8);
112 break;
113 }
114
115 /* reset ALC5676 */
116 gpio_output(PAD_LCM_RST, 1);
117
118 /* SoC I2S */
119 gpio_set_mode(PAD_I2S0_LRCK, PAD_I2S0_LRCK_FUNC_I2S1_WS);
120 gpio_set_mode(PAD_I2S0_BCK, PAD_I2S0_BCK_FUNC_I2S1_BCK);
121 gpio_set_mode(PAD_I2S0_MCK, PAD_I2S0_MCK_FUNC_I2S1_MCK);
122 gpio_set_mode(PAD_I2S0_DATA0, PAD_I2S0_DATA0_FUNC_I2S1_DO_1);
123 gpio_set_mode(PAD_I2S0_DATA1, PAD_I2S0_DATA1_FUNC_I2S2_DI_2);
124
125 /* codec ext MCLK ON */
126 mt6391_gpio_output(MT6391_KP_COL4, 1);
127 mt6391_gpio_output(MT6391_KP_COL5, 1);
128
jun.gaof059e972015-12-17 16:59:55 +0800129 /* Init i2c bus Timing register for audio codecs */
130 mtk_i2c_bus_init(0);
131
Koro Chen9733ba52015-07-31 17:11:04 +0800132 /* set I2S clock to 48KHz */
133 mt_pll_set_aud_div(48 * KHz);
134}
135
Ben Loka7379402015-07-31 17:11:11 +0800136static void configure_usb(void)
137{
138 setup_usb_host();
139
140 if (board_id() > 3)
141 gpio_output(PAD_CM2MCLK, 1);
142}
143
YH Huang1fcee362015-07-31 17:11:07 +0800144/* Setup backlight control pins as output pin and power-off by default */
145static void configure_backlight(void)
146{
Yidi Lin0443ecc2015-12-28 16:40:54 +0800147 /* Configure PANEL_LCD_POWER_EN */
YH Huang1fcee362015-07-31 17:11:07 +0800148 switch (board_id()) {
YH Huang1fcee362015-07-31 17:11:07 +0800149 case 1:
150 case 2:
YH Huang1fcee362015-07-31 17:11:07 +0800151 break;
152 case 3:
Yidi Lin0443ecc2015-12-28 16:40:54 +0800153 gpio_output(PAD_UCTS2, 0);
YH Huang1fcee362015-07-31 17:11:07 +0800154 break;
155 case 4:
Yidi Lin0443ecc2015-12-28 16:40:54 +0800156 gpio_output(PAD_SRCLKENAI, 0);
157 break;
YH Huang1fcee362015-07-31 17:11:07 +0800158 default:
Yidi Lin0443ecc2015-12-28 16:40:54 +0800159 gpio_output(PAD_UTXD2, 0);
YH Huang1fcee362015-07-31 17:11:07 +0800160 break;
161 }
Yidi Lin0443ecc2015-12-28 16:40:54 +0800162
163 gpio_output(PAD_DISP_PWM0, 0); /* DISP_PWM0 */
164 gpio_output(PAD_PCM_TX, 0); /* PANEL_POWER_EN */
YH Huang1fcee362015-07-31 17:11:07 +0800165}
166
Yidi Lin3d7b6062015-07-31 17:10:40 +0800167static void mainboard_init(device_t dev)
168{
Ben Loka7379402015-07-31 17:11:11 +0800169 /* TP_SHIFT_EN: Enables the level shifter for I2C bus 4 (TPAD), which
170 * also contains the PS8640 eDP brige and the USB hub.
171 */
172 mt6391_gpio_output(MT6391_KP_ROW2, 1);
173
Yidi Linb9b2c6f2015-11-13 16:21:48 +0800174 /* Config SD card detection pin */
175 gpio_input(PAD_EINT1); /* SD_DET */
176
Koro Chen9733ba52015-07-31 17:11:04 +0800177 configure_audio();
YH Huang1fcee362015-07-31 17:11:07 +0800178 configure_backlight();
Ben Loka7379402015-07-31 17:11:11 +0800179 configure_usb();
Jimmy Huang27eba672015-07-31 17:11:00 +0800180 configure_bl31();
CC Ma72980b12015-09-15 17:33:38 +0800181
182 elog_init();
183 elog_add_boot_reason();
Yidi Lin3d7b6062015-07-31 17:10:40 +0800184}
185
186static void mainboard_enable(device_t dev)
187{
188 dev->ops->init = &mainboard_init;
189}
190
191struct chip_operations mainboard_ops = {
192 .name = "oak",
193 .enable_dev = mainboard_enable,
194};