blob: bac6fc50c7086a4c279449b4b5cd0c0f5f1a8b8b [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>
Yidi Lin3d7b6062015-07-31 17:10:40 +080017#include <boardid.h>
18#include <boot/coreboot_tables.h>
Jitao Shi4a04a7b2016-01-08 16:02:13 +080019#include <bootmode.h>
20#include <console/console.h>
Koro Chen9733ba52015-07-31 17:11:04 +080021#include <delay.h>
Yidi Lin3d7b6062015-07-31 17:10:40 +080022#include <device/device.h>
Jitao Shi4a04a7b2016-01-08 16:02:13 +080023#include <drivers/parade/ps8640/ps8640.h>
24#include <edid.h>
Yidi Lin3d7b6062015-07-31 17:10:40 +080025
CC Ma72980b12015-09-15 17:33:38 +080026#include <elog.h>
Koro Chen9733ba52015-07-31 17:11:04 +080027#include <gpio.h>
henryc.chen316ded82016-03-11 14:55:30 +080028#include <soc/da9212.h>
Jitao Shi4a04a7b2016-01-08 16:02:13 +080029#include <soc/ddp.h>
30#include <soc/dsi.h>
jun.gaof059e972015-12-17 16:59:55 +080031#include <soc/i2c.h>
henryc.chen316ded82016-03-11 14:55:30 +080032#include <soc/mt6311.h>
Koro Chen9733ba52015-07-31 17:11:04 +080033#include <soc/mt6391.h>
34#include <soc/mtcmos.h>
Koro Chen9733ba52015-07-31 17:11:04 +080035#include <soc/pll.h>
Ben Loka7379402015-07-31 17:11:11 +080036#include <soc/usb.h>
CC Ma72980b12015-09-15 17:33:38 +080037#include <vendorcode/google/chromeos/chromeos.h>
Koro Chen9733ba52015-07-31 17:11:04 +080038
henryc.chen316ded82016-03-11 14:55:30 +080039enum {
40 CODEC_I2C_BUS = 0,
41 EXT_BUCK_I2C_BUS = 1,
42};
43
44static void configure_ext_buck(void)
Jimmy Huang27eba672015-07-31 17:11:00 +080045{
henryc.chen316ded82016-03-11 14:55:30 +080046 mtk_i2c_bus_init(EXT_BUCK_I2C_BUS);
jun.gaof059e972015-12-17 16:59:55 +080047
Julius Werner9a570952016-03-14 20:12:18 -070048 switch (board_id() + CONFIG_BOARD_ID_ADJUSTMENT) {
henryc.chen70b30442015-12-23 11:45:29 +080049 case 3:
50 case 4:
Jimmy Huang27eba672015-07-31 17:11:00 +080051 /* rev-3 and rev-4 use mt6311 as external buck */
Tristan Shieh71d227b2018-07-09 18:59:32 +080052 gpio_output(GPIO(EINT15), 1);
henryc.chen316ded82016-03-11 14:55:30 +080053 udelay(500);
54 mt6311_probe(EXT_BUCK_I2C_BUS);
Jimmy Huang27eba672015-07-31 17:11:00 +080055 break;
henryc.chen70b30442015-12-23 11:45:29 +080056 case 2:
57 default:
58 /* rev-2 and rev-5 use da9212 as external buck */
henryc.chen316ded82016-03-11 14:55:30 +080059 mt6391_gpio_output(MT6391_KP_ROW3, 1); /* DA9212_IC_EN */
60 mt6391_gpio_output(MT6391_KP_ROW4, 1); /* DA9212_EN_A */
61 udelay(500); /* add 500us delay for powering on da9212 */
62 da9212_probe(EXT_BUCK_I2C_BUS);
henryc.chen70b30442015-12-23 11:45:29 +080063 break;
Jimmy Huang27eba672015-07-31 17:11:00 +080064 }
65}
66
YH Huang5d687ad2016-07-14 11:49:01 +080067static void configure_touchscreen(void)
68{
69 /* Pull low reset gpio for 500us and then pull high */
70 if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT >= 7) {
Tristan Shieh71d227b2018-07-09 18:59:32 +080071 gpio_output(GPIO(PCM_SYNC), 0);
YH Huang5d687ad2016-07-14 11:49:01 +080072 udelay(500);
Tristan Shieh71d227b2018-07-09 18:59:32 +080073 gpio_output(GPIO(PCM_SYNC), 1);
YH Huang5d687ad2016-07-14 11:49:01 +080074 }
75}
76
Koro Chen9733ba52015-07-31 17:11:04 +080077static void configure_audio(void)
78{
79 mtcmos_audio_power_on();
80
Koro Chen603cb852015-12-30 17:50:56 +080081 /* vgp1 set to 1.8V */
82 mt6391_configure_ldo(LDO_VCAMD, LDO_1P8);
83 /* delay 1ms for realtek's power sequence request */
84 mdelay(1);
85 /* vcama set to 1.8V */
86 mt6391_configure_ldo(LDO_VCAMA, LDO_1P8);
Koro Chen9733ba52015-07-31 17:11:04 +080087
88 /* reset ALC5676 */
Julius Werner9a570952016-03-14 20:12:18 -070089 if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT < 5)
Tristan Shieh71d227b2018-07-09 18:59:32 +080090 gpio_output(GPIO(LCM_RST), 1);
Koro Chen9733ba52015-07-31 17:11:04 +080091
92 /* SoC I2S */
Tristan Shieh71d227b2018-07-09 18:59:32 +080093 gpio_set_mode(GPIO(I2S0_LRCK), PAD_I2S0_LRCK_FUNC_I2S1_WS);
94 gpio_set_mode(GPIO(I2S0_BCK), PAD_I2S0_BCK_FUNC_I2S1_BCK);
95 gpio_set_mode(GPIO(I2S0_MCK), PAD_I2S0_MCK_FUNC_I2S1_MCK);
96 gpio_set_mode(GPIO(I2S0_DATA0), PAD_I2S0_DATA0_FUNC_I2S1_DO_1);
97 gpio_set_mode(GPIO(I2S0_DATA1), PAD_I2S0_DATA1_FUNC_I2S2_DI_2);
Koro Chen9733ba52015-07-31 17:11:04 +080098 /* codec ext MCLK ON */
99 mt6391_gpio_output(MT6391_KP_COL4, 1);
Yidi Lin19318dd2016-03-16 16:59:17 +0800100
101 switch (board_id() + CONFIG_BOARD_ID_ADJUSTMENT) {
102 case 2:
103 case 3:
104 case 4:
105 mt6391_gpio_output(MT6391_KP_COL5, 1);
106 break;
107 case 5:
108 case 6:
Tristan Shieh71d227b2018-07-09 18:59:32 +0800109 gpio_set_mode(GPIO(UCTS0), PAD_UCTS0_FUNC_I2S2_DI_1);
Yidi Lin19318dd2016-03-16 16:59:17 +0800110 mt6391_gpio_output(MT6391_KP_COL5, 1);
111 break;
112 default:
113 break;
114 }
Koro Chen9733ba52015-07-31 17:11:04 +0800115
jun.gaof059e972015-12-17 16:59:55 +0800116 /* Init i2c bus Timing register for audio codecs */
henryc.chen316ded82016-03-11 14:55:30 +0800117 mtk_i2c_bus_init(CODEC_I2C_BUS);
jun.gaof059e972015-12-17 16:59:55 +0800118
Koro Chen9733ba52015-07-31 17:11:04 +0800119 /* set I2S clock to 48KHz */
120 mt_pll_set_aud_div(48 * KHz);
121}
122
Ben Loka7379402015-07-31 17:11:11 +0800123static void configure_usb(void)
124{
125 setup_usb_host();
126
Julius Werner9a570952016-03-14 20:12:18 -0700127 if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT > 3) {
Yidi Lin57debca2017-02-17 15:59:17 +0800128 /* Type C port 0 Over current alert pin */
Tristan Shieh71d227b2018-07-09 18:59:32 +0800129 gpio_input_pullup(GPIO(MSDC3_DSL));
Evan Green0aa1f9e2019-03-26 11:37:30 -0700130 /* Enable USB3 type A port 0 5V load switch */
131 gpio_output(GPIO(CM2MCLK), 1);
132 /* USB3 Type A port 0 power over current alert pin */
133 gpio_input_pullup(GPIO(CMPCLK));
Yidi Lin57debca2017-02-17 15:59:17 +0800134 /* Type C port 1 over current alert pin */
Yidi Lin19318dd2016-03-16 16:59:17 +0800135 if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT < 7)
Tristan Shieh71d227b2018-07-09 18:59:32 +0800136 gpio_input_pullup(GPIO(PCM_SYNC));
Yidi Lin358f66a2016-01-11 10:05:46 +0800137 }
138
Yidi Lin19318dd2016-03-16 16:59:17 +0800139 if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT > 4 &&
140 board_id() + CONFIG_BOARD_ID_ADJUSTMENT < 7)
141 {
Yidi Lin358f66a2016-01-11 10:05:46 +0800142 /* USB 2.0 type A port over current interrupt pin(low active) */
Tristan Shieh71d227b2018-07-09 18:59:32 +0800143 gpio_input_pullup(GPIO(UCTS2));
Yidi Lin358f66a2016-01-11 10:05:46 +0800144 /* USB 2.0 type A port BC1.2 STATUS(low active) */
Tristan Shieh71d227b2018-07-09 18:59:32 +0800145 gpio_input_pullup(GPIO(AUD_DAT_MISO));
Yidi Lin358f66a2016-01-11 10:05:46 +0800146 }
Ben Loka7379402015-07-31 17:11:11 +0800147}
148
Ben Lok7d7dc202016-01-08 13:10:34 +0800149static void configure_usb_hub(void)
150{
151 /* set usb hub reset pin (low active) to high */
Julius Werner9a570952016-03-14 20:12:18 -0700152 if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT > 4)
Tristan Shieh71d227b2018-07-09 18:59:32 +0800153 gpio_output(GPIO(UTXD3), 1);
Ben Lok7d7dc202016-01-08 13:10:34 +0800154}
155
YH Huang1fcee362015-07-31 17:11:07 +0800156/* Setup backlight control pins as output pin and power-off by default */
157static void configure_backlight(void)
158{
Yidi Lin0443ecc2015-12-28 16:40:54 +0800159 /* Configure PANEL_LCD_POWER_EN */
Julius Werner9a570952016-03-14 20:12:18 -0700160 switch (board_id() + CONFIG_BOARD_ID_ADJUSTMENT) {
YH Huang1fcee362015-07-31 17:11:07 +0800161 case 3:
Tristan Shieh71d227b2018-07-09 18:59:32 +0800162 gpio_output(GPIO(UCTS2), 0);
YH Huang1fcee362015-07-31 17:11:07 +0800163 break;
164 case 4:
Tristan Shieh71d227b2018-07-09 18:59:32 +0800165 gpio_output(GPIO(SRCLKENAI), 0);
Yidi Lin0443ecc2015-12-28 16:40:54 +0800166 break;
YH Huang1fcee362015-07-31 17:11:07 +0800167 default:
Tristan Shieh71d227b2018-07-09 18:59:32 +0800168 gpio_output(GPIO(UTXD2), 0);
YH Huang1fcee362015-07-31 17:11:07 +0800169 break;
170 }
Yidi Lin0443ecc2015-12-28 16:40:54 +0800171
Tristan Shieh71d227b2018-07-09 18:59:32 +0800172 gpio_output(GPIO(DISP_PWM0), 0); /* DISP_PWM0 */
173 gpio_output(GPIO(PCM_TX), 0); /* PANEL_POWER_EN */
YH Huang1fcee362015-07-31 17:11:07 +0800174}
175
Jitao Shi8ea218b2016-01-11 19:24:37 +0800176static void configure_display(void)
177{
Yidi Lin19318dd2016-03-16 16:59:17 +0800178 /* board from Rev2 */
Tristan Shieh71d227b2018-07-09 18:59:32 +0800179 gpio_output(GPIO(CMMCLK), 1); /* PANEL_3V3_ENABLE */
Yidi Lin19318dd2016-03-16 16:59:17 +0800180 /* vgp2 set to 3.3V for ps8640 */
181 mt6391_configure_ldo(LDO_VGP2, LDO_3P3);
Tristan Shieh71d227b2018-07-09 18:59:32 +0800182 gpio_output(GPIO(URTS0), 0); /* PS8640_SYSRSTN */
Yidi Lin19318dd2016-03-16 16:59:17 +0800183 /* PS8640_1V2_ENABLE */
184 if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT == 4)
Tristan Shieh71d227b2018-07-09 18:59:32 +0800185 gpio_output(GPIO(SRCLKENAI2), 1);
Yidi Lin19318dd2016-03-16 16:59:17 +0800186 else
Tristan Shieh71d227b2018-07-09 18:59:32 +0800187 gpio_output(GPIO(URTS2), 1);
Yidi Lin19318dd2016-03-16 16:59:17 +0800188 /* delay 2ms for vgp2 and PS8640_1V2_ENABLE stable */
189 mdelay(2);
190 /* PS8640_PDN */
191 if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT > 4)
Tristan Shieh71d227b2018-07-09 18:59:32 +0800192 gpio_output(GPIO(LCM_RST), 1);
Yidi Lin19318dd2016-03-16 16:59:17 +0800193 else
Tristan Shieh71d227b2018-07-09 18:59:32 +0800194 gpio_output(GPIO(UCTS0), 1);
195 gpio_output(GPIO(PCM_CLK), 1); /* PS8640_MODE_CONF */
196 gpio_output(GPIO(URTS0), 1); /* PS8640_SYSRSTN */
Yidi Lin19318dd2016-03-16 16:59:17 +0800197 /* for level shift(1.8V to 3.3V) on */
198 udelay(100);
Jitao Shi8ea218b2016-01-11 19:24:37 +0800199}
200
Daniel Kurtz8e055f82017-04-20 15:31:33 +0800201static int read_edid_from_ps8640(struct edid *edid)
202{
Yidi Lin19318dd2016-03-16 16:59:17 +0800203 u8 i2c_bus, i2c_addr;
Jitao Shi4a04a7b2016-01-08 16:02:13 +0800204
Yidi Lin19318dd2016-03-16 16:59:17 +0800205 if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT > 6) {
206 i2c_bus = 0;
207 i2c_addr = 0x8;
208 } else {
Jitao Shi4a04a7b2016-01-08 16:02:13 +0800209 i2c_bus = 4;
Yidi Lin19318dd2016-03-16 16:59:17 +0800210 i2c_addr = 0x18;
Jitao Shi4a04a7b2016-01-08 16:02:13 +0800211 }
Yidi Lin19318dd2016-03-16 16:59:17 +0800212
Jitao Shi4a04a7b2016-01-08 16:02:13 +0800213 mtk_i2c_bus_init(i2c_bus);
214
Yidi Lin19318dd2016-03-16 16:59:17 +0800215 ps8640_init(i2c_bus, i2c_addr);
Daniel Kurtz8e055f82017-04-20 15:31:33 +0800216 if (ps8640_get_edid(i2c_bus, i2c_addr, edid)) {
Jitao Shi4a04a7b2016-01-08 16:02:13 +0800217 printk(BIOS_ERR, "Can't get panel's edid\n");
Daniel Kurtz8e055f82017-04-20 15:31:33 +0800218 return -1;
219 }
220
221 return 0;
222}
223
224static void display_startup(void)
225{
226 struct edid edid;
227 int ret;
228 u32 mipi_dsi_flags;
Daniel Kurtz8e055f82017-04-20 15:31:33 +0800229
Evan Green0aa1f9e2019-03-26 11:37:30 -0700230 if (read_edid_from_ps8640(&edid) < 0)
231 return;
Daniel Kurtz8e055f82017-04-20 15:31:33 +0800232
Evan Green0aa1f9e2019-03-26 11:37:30 -0700233 mipi_dsi_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE;
Daniel Kurtz2332ada2017-04-20 12:30:00 +0800234 edid_set_framebuffer_bits_per_pixel(&edid, 32, 0);
Jitao Shi4a04a7b2016-01-08 16:02:13 +0800235
Hung-Te Lin1c6e5a62019-08-05 14:38:30 +0800236 mtk_ddp_init();
Hung-Te Lin75e43142019-08-07 10:31:27 +0800237 ret = mtk_dsi_init(mipi_dsi_flags, MIPI_DSI_FMT_RGB888, 4, &edid, NULL);
Jitao Shi4a04a7b2016-01-08 16:02:13 +0800238 if (ret < 0) {
239 printk(BIOS_ERR, "dsi init fail\n");
240 return;
241 }
242
Hung-Te Lin1c6e5a62019-08-05 14:38:30 +0800243 mtk_ddp_mode_set(&edid);
Jitao Shi4a04a7b2016-01-08 16:02:13 +0800244 set_vbe_mode_info_valid(&edid, (uintptr_t)0);
245}
246
Elyes HAOUASd129d432018-05-04 20:23:33 +0200247static void mainboard_init(struct device *dev)
Yidi Lin3d7b6062015-07-31 17:10:40 +0800248{
Ben Loka7379402015-07-31 17:11:11 +0800249 /* TP_SHIFT_EN: Enables the level shifter for I2C bus 4 (TPAD), which
250 * also contains the PS8640 eDP brige and the USB hub.
251 */
Julius Werner9a570952016-03-14 20:12:18 -0700252 if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT < 5)
Yidi Lincd6aac12015-12-28 17:22:33 +0800253 mt6391_gpio_output(MT6391_KP_ROW2, 1);
Ben Loka7379402015-07-31 17:11:11 +0800254
Yidi Linb9b2c6f2015-11-13 16:21:48 +0800255 /* Config SD card detection pin */
Tristan Shieh71d227b2018-07-09 18:59:32 +0800256 gpio_input_pullup(GPIO(EINT1)); /* SD_DET */
Yidi Linb9b2c6f2015-11-13 16:21:48 +0800257
Koro Chen9733ba52015-07-31 17:11:04 +0800258 configure_audio();
Martin Rothc7dfbe22016-07-22 11:15:12 -0600259
260 /* fix dsi lp mode is half voltage attenuation */
261 mtk_dsi_pin_drv_ctrl();
262
Jitao Shi4a04a7b2016-01-08 16:02:13 +0800263 if (display_init_required()) {
Daniel Kurtz8e055f82017-04-20 15:31:33 +0800264 mtcmos_display_power_on();
Evan Green0aa1f9e2019-03-26 11:37:30 -0700265 configure_backlight();
266 configure_display();
Daniel Kurtz8e055f82017-04-20 15:31:33 +0800267 display_startup();
Jitao Shi4a04a7b2016-01-08 16:02:13 +0800268 } else {
269 printk(BIOS_INFO, "Skipping display init.\n");
270 }
Ben Loka7379402015-07-31 17:11:11 +0800271 configure_usb();
Ben Lok7d7dc202016-01-08 13:10:34 +0800272 configure_usb_hub();
henryc.chen316ded82016-03-11 14:55:30 +0800273 configure_ext_buck();
YH Huang5d687ad2016-07-14 11:49:01 +0800274 configure_touchscreen();
Yidi Lin3d7b6062015-07-31 17:10:40 +0800275}
276
Elyes HAOUASd129d432018-05-04 20:23:33 +0200277static void mainboard_enable(struct device *dev)
Yidi Lin3d7b6062015-07-31 17:10:40 +0800278{
279 dev->ops->init = &mainboard_init;
280}
281
282struct chip_operations mainboard_ops = {
283 .name = "oak",
284 .enable_dev = mainboard_enable,
285};