blob: 4208730d674bcbc9904ce7fe47d4ee6b7cd66f9f [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>
henryc.chen316ded82016-03-11 14:55:30 +080025#include <soc/da9212.h>
jun.gaof059e972015-12-17 16:59:55 +080026#include <soc/i2c.h>
henryc.chen316ded82016-03-11 14:55:30 +080027#include <soc/mt6311.h>
Koro Chen9733ba52015-07-31 17:11:04 +080028#include <soc/mt6391.h>
29#include <soc/mtcmos.h>
30#include <soc/pinmux.h>
31#include <soc/pll.h>
Ben Loka7379402015-07-31 17:11:11 +080032#include <soc/usb.h>
CC Ma72980b12015-09-15 17:33:38 +080033#include <vendorcode/google/chromeos/chromeos.h>
Koro Chen9733ba52015-07-31 17:11:04 +080034
henryc.chen316ded82016-03-11 14:55:30 +080035enum {
36 CODEC_I2C_BUS = 0,
37 EXT_BUCK_I2C_BUS = 1,
38};
39
40static void configure_ext_buck(void)
Jimmy Huang27eba672015-07-31 17:11:00 +080041{
henryc.chen316ded82016-03-11 14:55:30 +080042 mtk_i2c_bus_init(EXT_BUCK_I2C_BUS);
jun.gaof059e972015-12-17 16:59:55 +080043
Jimmy Huang27eba672015-07-31 17:11:00 +080044 switch (board_id()) {
henryc.chen70b30442015-12-23 11:45:29 +080045 case 3:
46 case 4:
Jimmy Huang27eba672015-07-31 17:11:00 +080047 /* rev-3 and rev-4 use mt6311 as external buck */
henryc.chen316ded82016-03-11 14:55:30 +080048 gpio_output(PAD_EINT15, 1);
49 udelay(500);
50 mt6311_probe(EXT_BUCK_I2C_BUS);
Jimmy Huang27eba672015-07-31 17:11:00 +080051 break;
henryc.chen70b30442015-12-23 11:45:29 +080052 case 2:
53 default:
54 /* rev-2 and rev-5 use da9212 as external buck */
henryc.chen316ded82016-03-11 14:55:30 +080055 mt6391_gpio_output(MT6391_KP_ROW3, 1); /* DA9212_IC_EN */
56 mt6391_gpio_output(MT6391_KP_ROW4, 1); /* DA9212_EN_A */
57 udelay(500); /* add 500us delay for powering on da9212 */
58 da9212_probe(EXT_BUCK_I2C_BUS);
henryc.chen70b30442015-12-23 11:45:29 +080059 break;
Jimmy Huang27eba672015-07-31 17:11:00 +080060 }
61}
62
Koro Chen9733ba52015-07-31 17:11:04 +080063static void configure_audio(void)
64{
65 mtcmos_audio_power_on();
66
Koro Chen603cb852015-12-30 17:50:56 +080067 /* vgp1 set to 1.8V */
68 mt6391_configure_ldo(LDO_VCAMD, LDO_1P8);
69 /* delay 1ms for realtek's power sequence request */
70 mdelay(1);
71 /* vcama set to 1.8V */
72 mt6391_configure_ldo(LDO_VCAMA, LDO_1P8);
Koro Chen9733ba52015-07-31 17:11:04 +080073
74 /* reset ALC5676 */
Koro Chena9f65292015-12-30 17:31:44 +080075 if (board_id() < 5)
76 gpio_output(PAD_LCM_RST, 1);
Koro Chen9733ba52015-07-31 17:11:04 +080077
78 /* SoC I2S */
79 gpio_set_mode(PAD_I2S0_LRCK, PAD_I2S0_LRCK_FUNC_I2S1_WS);
80 gpio_set_mode(PAD_I2S0_BCK, PAD_I2S0_BCK_FUNC_I2S1_BCK);
81 gpio_set_mode(PAD_I2S0_MCK, PAD_I2S0_MCK_FUNC_I2S1_MCK);
82 gpio_set_mode(PAD_I2S0_DATA0, PAD_I2S0_DATA0_FUNC_I2S1_DO_1);
83 gpio_set_mode(PAD_I2S0_DATA1, PAD_I2S0_DATA1_FUNC_I2S2_DI_2);
Koro Chena9f65292015-12-30 17:31:44 +080084 if (board_id() >= 5)
85 gpio_set_mode(PAD_UCTS0, PAD_UCTS0_FUNC_I2S2_DI_1);
Koro Chen9733ba52015-07-31 17:11:04 +080086
87 /* codec ext MCLK ON */
88 mt6391_gpio_output(MT6391_KP_COL4, 1);
89 mt6391_gpio_output(MT6391_KP_COL5, 1);
90
jun.gaof059e972015-12-17 16:59:55 +080091 /* Init i2c bus Timing register for audio codecs */
henryc.chen316ded82016-03-11 14:55:30 +080092 mtk_i2c_bus_init(CODEC_I2C_BUS);
jun.gaof059e972015-12-17 16:59:55 +080093
Koro Chen9733ba52015-07-31 17:11:04 +080094 /* set I2S clock to 48KHz */
95 mt_pll_set_aud_div(48 * KHz);
96}
97
Ben Loka7379402015-07-31 17:11:11 +080098static void configure_usb(void)
99{
100 setup_usb_host();
101
Yidi Lin358f66a2016-01-11 10:05:46 +0800102 if (board_id() > 3) {
103 /* Enable current limit */
Ben Loka7379402015-07-31 17:11:11 +0800104 gpio_output(PAD_CM2MCLK, 1);
Yidi Lin358f66a2016-01-11 10:05:46 +0800105 /* Configure USB OC pins*/
106 gpio_input_pullup(PAD_MSDC3_DSL);
107 gpio_input_pullup(PAD_CMPCLK);
108 gpio_input_pullup(PAD_PCM_SYNC);
109 }
110
111 if (board_id() > 4) {
112 /* USB 2.0 type A port over current interrupt pin(low active) */
113 gpio_input_pullup(PAD_UCTS2);
114 /* USB 2.0 type A port BC1.2 STATUS(low active) */
115 gpio_input_pullup(PAD_AUD_DAT_MISO);
116 }
Ben Loka7379402015-07-31 17:11:11 +0800117}
118
Ben Lok7d7dc202016-01-08 13:10:34 +0800119static void configure_usb_hub(void)
120{
121 /* set usb hub reset pin (low active) to high */
122 if (board_id() > 4)
123 gpio_output(PAD_UTXD3, 1);
124}
125
YH Huang1fcee362015-07-31 17:11:07 +0800126/* Setup backlight control pins as output pin and power-off by default */
127static void configure_backlight(void)
128{
Yidi Lin0443ecc2015-12-28 16:40:54 +0800129 /* Configure PANEL_LCD_POWER_EN */
YH Huang1fcee362015-07-31 17:11:07 +0800130 switch (board_id()) {
YH Huang1fcee362015-07-31 17:11:07 +0800131 case 1:
132 case 2:
YH Huang1fcee362015-07-31 17:11:07 +0800133 break;
134 case 3:
Yidi Lin0443ecc2015-12-28 16:40:54 +0800135 gpio_output(PAD_UCTS2, 0);
YH Huang1fcee362015-07-31 17:11:07 +0800136 break;
137 case 4:
Yidi Lin0443ecc2015-12-28 16:40:54 +0800138 gpio_output(PAD_SRCLKENAI, 0);
139 break;
YH Huang1fcee362015-07-31 17:11:07 +0800140 default:
Yidi Lin0443ecc2015-12-28 16:40:54 +0800141 gpio_output(PAD_UTXD2, 0);
YH Huang1fcee362015-07-31 17:11:07 +0800142 break;
143 }
Yidi Lin0443ecc2015-12-28 16:40:54 +0800144
145 gpio_output(PAD_DISP_PWM0, 0); /* DISP_PWM0 */
146 gpio_output(PAD_PCM_TX, 0); /* PANEL_POWER_EN */
YH Huang1fcee362015-07-31 17:11:07 +0800147}
148
Yidi Lin3d7b6062015-07-31 17:10:40 +0800149static void mainboard_init(device_t dev)
150{
Ben Loka7379402015-07-31 17:11:11 +0800151 /* TP_SHIFT_EN: Enables the level shifter for I2C bus 4 (TPAD), which
152 * also contains the PS8640 eDP brige and the USB hub.
153 */
Yidi Lincd6aac12015-12-28 17:22:33 +0800154 if (board_id() < 5)
155 mt6391_gpio_output(MT6391_KP_ROW2, 1);
Ben Loka7379402015-07-31 17:11:11 +0800156
Yidi Linb9b2c6f2015-11-13 16:21:48 +0800157 /* Config SD card detection pin */
158 gpio_input(PAD_EINT1); /* SD_DET */
159
Koro Chen9733ba52015-07-31 17:11:04 +0800160 configure_audio();
YH Huang1fcee362015-07-31 17:11:07 +0800161 configure_backlight();
Ben Loka7379402015-07-31 17:11:11 +0800162 configure_usb();
Ben Lok7d7dc202016-01-08 13:10:34 +0800163 configure_usb_hub();
henryc.chen316ded82016-03-11 14:55:30 +0800164 configure_ext_buck();
CC Ma72980b12015-09-15 17:33:38 +0800165
166 elog_init();
167 elog_add_boot_reason();
Yidi Lin3d7b6062015-07-31 17:10:40 +0800168}
169
170static void mainboard_enable(device_t dev)
171{
172 dev->ops->init = &mainboard_init;
173}
174
175struct chip_operations mainboard_ops = {
176 .name = "oak",
177 .enable_dev = mainboard_enable,
178};