Yidi Lin | 3d7b606 | 2015-07-31 17:10:40 +0800 | [diff] [blame] | 1 | /* |
| 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 Lin | 3d7b606 | 2015-07-31 17:10:40 +0800 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <arch/cache.h> |
| 17 | #include <arch/io.h> |
| 18 | #include <boardid.h> |
| 19 | #include <boot/coreboot_tables.h> |
Jitao Shi | 4a04a7b | 2016-01-08 16:02:13 +0800 | [diff] [blame^] | 20 | #include <bootmode.h> |
| 21 | #include <console/console.h> |
Koro Chen | 9733ba5 | 2015-07-31 17:11:04 +0800 | [diff] [blame] | 22 | #include <delay.h> |
Yidi Lin | 3d7b606 | 2015-07-31 17:10:40 +0800 | [diff] [blame] | 23 | #include <device/device.h> |
Jitao Shi | 4a04a7b | 2016-01-08 16:02:13 +0800 | [diff] [blame^] | 24 | #include <drivers/parade/ps8640/ps8640.h> |
| 25 | #include <edid.h> |
Yidi Lin | 3d7b606 | 2015-07-31 17:10:40 +0800 | [diff] [blame] | 26 | |
CC Ma | 72980b1 | 2015-09-15 17:33:38 +0800 | [diff] [blame] | 27 | #include <elog.h> |
Koro Chen | 9733ba5 | 2015-07-31 17:11:04 +0800 | [diff] [blame] | 28 | #include <gpio.h> |
henryc.chen | 316ded8 | 2016-03-11 14:55:30 +0800 | [diff] [blame] | 29 | #include <soc/da9212.h> |
Jitao Shi | 4a04a7b | 2016-01-08 16:02:13 +0800 | [diff] [blame^] | 30 | #include <soc/ddp.h> |
| 31 | #include <soc/dsi.h> |
jun.gao | f059e97 | 2015-12-17 16:59:55 +0800 | [diff] [blame] | 32 | #include <soc/i2c.h> |
henryc.chen | 316ded8 | 2016-03-11 14:55:30 +0800 | [diff] [blame] | 33 | #include <soc/mt6311.h> |
Koro Chen | 9733ba5 | 2015-07-31 17:11:04 +0800 | [diff] [blame] | 34 | #include <soc/mt6391.h> |
| 35 | #include <soc/mtcmos.h> |
| 36 | #include <soc/pinmux.h> |
| 37 | #include <soc/pll.h> |
Ben Lok | a737940 | 2015-07-31 17:11:11 +0800 | [diff] [blame] | 38 | #include <soc/usb.h> |
CC Ma | 72980b1 | 2015-09-15 17:33:38 +0800 | [diff] [blame] | 39 | #include <vendorcode/google/chromeos/chromeos.h> |
Koro Chen | 9733ba5 | 2015-07-31 17:11:04 +0800 | [diff] [blame] | 40 | |
henryc.chen | 316ded8 | 2016-03-11 14:55:30 +0800 | [diff] [blame] | 41 | enum { |
| 42 | CODEC_I2C_BUS = 0, |
| 43 | EXT_BUCK_I2C_BUS = 1, |
| 44 | }; |
| 45 | |
| 46 | static void configure_ext_buck(void) |
Jimmy Huang | 27eba67 | 2015-07-31 17:11:00 +0800 | [diff] [blame] | 47 | { |
henryc.chen | 316ded8 | 2016-03-11 14:55:30 +0800 | [diff] [blame] | 48 | mtk_i2c_bus_init(EXT_BUCK_I2C_BUS); |
jun.gao | f059e97 | 2015-12-17 16:59:55 +0800 | [diff] [blame] | 49 | |
Jimmy Huang | 27eba67 | 2015-07-31 17:11:00 +0800 | [diff] [blame] | 50 | switch (board_id()) { |
henryc.chen | 70b3044 | 2015-12-23 11:45:29 +0800 | [diff] [blame] | 51 | case 3: |
| 52 | case 4: |
Jimmy Huang | 27eba67 | 2015-07-31 17:11:00 +0800 | [diff] [blame] | 53 | /* rev-3 and rev-4 use mt6311 as external buck */ |
henryc.chen | 316ded8 | 2016-03-11 14:55:30 +0800 | [diff] [blame] | 54 | gpio_output(PAD_EINT15, 1); |
| 55 | udelay(500); |
| 56 | mt6311_probe(EXT_BUCK_I2C_BUS); |
Jimmy Huang | 27eba67 | 2015-07-31 17:11:00 +0800 | [diff] [blame] | 57 | break; |
henryc.chen | 70b3044 | 2015-12-23 11:45:29 +0800 | [diff] [blame] | 58 | case 2: |
| 59 | default: |
| 60 | /* rev-2 and rev-5 use da9212 as external buck */ |
henryc.chen | 316ded8 | 2016-03-11 14:55:30 +0800 | [diff] [blame] | 61 | mt6391_gpio_output(MT6391_KP_ROW3, 1); /* DA9212_IC_EN */ |
| 62 | mt6391_gpio_output(MT6391_KP_ROW4, 1); /* DA9212_EN_A */ |
| 63 | udelay(500); /* add 500us delay for powering on da9212 */ |
| 64 | da9212_probe(EXT_BUCK_I2C_BUS); |
henryc.chen | 70b3044 | 2015-12-23 11:45:29 +0800 | [diff] [blame] | 65 | break; |
Jimmy Huang | 27eba67 | 2015-07-31 17:11:00 +0800 | [diff] [blame] | 66 | } |
| 67 | } |
| 68 | |
Koro Chen | 9733ba5 | 2015-07-31 17:11:04 +0800 | [diff] [blame] | 69 | static void configure_audio(void) |
| 70 | { |
| 71 | mtcmos_audio_power_on(); |
| 72 | |
Koro Chen | 603cb85 | 2015-12-30 17:50:56 +0800 | [diff] [blame] | 73 | /* vgp1 set to 1.8V */ |
| 74 | mt6391_configure_ldo(LDO_VCAMD, LDO_1P8); |
| 75 | /* delay 1ms for realtek's power sequence request */ |
| 76 | mdelay(1); |
| 77 | /* vcama set to 1.8V */ |
| 78 | mt6391_configure_ldo(LDO_VCAMA, LDO_1P8); |
Koro Chen | 9733ba5 | 2015-07-31 17:11:04 +0800 | [diff] [blame] | 79 | |
| 80 | /* reset ALC5676 */ |
Koro Chen | a9f6529 | 2015-12-30 17:31:44 +0800 | [diff] [blame] | 81 | if (board_id() < 5) |
| 82 | gpio_output(PAD_LCM_RST, 1); |
Koro Chen | 9733ba5 | 2015-07-31 17:11:04 +0800 | [diff] [blame] | 83 | |
| 84 | /* SoC I2S */ |
| 85 | gpio_set_mode(PAD_I2S0_LRCK, PAD_I2S0_LRCK_FUNC_I2S1_WS); |
| 86 | gpio_set_mode(PAD_I2S0_BCK, PAD_I2S0_BCK_FUNC_I2S1_BCK); |
| 87 | gpio_set_mode(PAD_I2S0_MCK, PAD_I2S0_MCK_FUNC_I2S1_MCK); |
| 88 | gpio_set_mode(PAD_I2S0_DATA0, PAD_I2S0_DATA0_FUNC_I2S1_DO_1); |
| 89 | gpio_set_mode(PAD_I2S0_DATA1, PAD_I2S0_DATA1_FUNC_I2S2_DI_2); |
Koro Chen | a9f6529 | 2015-12-30 17:31:44 +0800 | [diff] [blame] | 90 | if (board_id() >= 5) |
| 91 | gpio_set_mode(PAD_UCTS0, PAD_UCTS0_FUNC_I2S2_DI_1); |
Koro Chen | 9733ba5 | 2015-07-31 17:11:04 +0800 | [diff] [blame] | 92 | |
| 93 | /* codec ext MCLK ON */ |
| 94 | mt6391_gpio_output(MT6391_KP_COL4, 1); |
| 95 | mt6391_gpio_output(MT6391_KP_COL5, 1); |
| 96 | |
jun.gao | f059e97 | 2015-12-17 16:59:55 +0800 | [diff] [blame] | 97 | /* Init i2c bus Timing register for audio codecs */ |
henryc.chen | 316ded8 | 2016-03-11 14:55:30 +0800 | [diff] [blame] | 98 | mtk_i2c_bus_init(CODEC_I2C_BUS); |
jun.gao | f059e97 | 2015-12-17 16:59:55 +0800 | [diff] [blame] | 99 | |
Koro Chen | 9733ba5 | 2015-07-31 17:11:04 +0800 | [diff] [blame] | 100 | /* set I2S clock to 48KHz */ |
| 101 | mt_pll_set_aud_div(48 * KHz); |
| 102 | } |
| 103 | |
Ben Lok | a737940 | 2015-07-31 17:11:11 +0800 | [diff] [blame] | 104 | static void configure_usb(void) |
| 105 | { |
| 106 | setup_usb_host(); |
| 107 | |
Yidi Lin | 358f66a | 2016-01-11 10:05:46 +0800 | [diff] [blame] | 108 | if (board_id() > 3) { |
| 109 | /* Enable current limit */ |
Ben Lok | a737940 | 2015-07-31 17:11:11 +0800 | [diff] [blame] | 110 | gpio_output(PAD_CM2MCLK, 1); |
Yidi Lin | 358f66a | 2016-01-11 10:05:46 +0800 | [diff] [blame] | 111 | /* Configure USB OC pins*/ |
| 112 | gpio_input_pullup(PAD_MSDC3_DSL); |
| 113 | gpio_input_pullup(PAD_CMPCLK); |
| 114 | gpio_input_pullup(PAD_PCM_SYNC); |
| 115 | } |
| 116 | |
| 117 | if (board_id() > 4) { |
| 118 | /* USB 2.0 type A port over current interrupt pin(low active) */ |
| 119 | gpio_input_pullup(PAD_UCTS2); |
| 120 | /* USB 2.0 type A port BC1.2 STATUS(low active) */ |
| 121 | gpio_input_pullup(PAD_AUD_DAT_MISO); |
| 122 | } |
Ben Lok | a737940 | 2015-07-31 17:11:11 +0800 | [diff] [blame] | 123 | } |
| 124 | |
Ben Lok | 7d7dc20 | 2016-01-08 13:10:34 +0800 | [diff] [blame] | 125 | static void configure_usb_hub(void) |
| 126 | { |
| 127 | /* set usb hub reset pin (low active) to high */ |
| 128 | if (board_id() > 4) |
| 129 | gpio_output(PAD_UTXD3, 1); |
| 130 | } |
| 131 | |
YH Huang | 1fcee36 | 2015-07-31 17:11:07 +0800 | [diff] [blame] | 132 | /* Setup backlight control pins as output pin and power-off by default */ |
| 133 | static void configure_backlight(void) |
| 134 | { |
Yidi Lin | 0443ecc | 2015-12-28 16:40:54 +0800 | [diff] [blame] | 135 | /* Configure PANEL_LCD_POWER_EN */ |
YH Huang | 1fcee36 | 2015-07-31 17:11:07 +0800 | [diff] [blame] | 136 | switch (board_id()) { |
YH Huang | 1fcee36 | 2015-07-31 17:11:07 +0800 | [diff] [blame] | 137 | case 1: |
| 138 | case 2: |
YH Huang | 1fcee36 | 2015-07-31 17:11:07 +0800 | [diff] [blame] | 139 | break; |
| 140 | case 3: |
Yidi Lin | 0443ecc | 2015-12-28 16:40:54 +0800 | [diff] [blame] | 141 | gpio_output(PAD_UCTS2, 0); |
YH Huang | 1fcee36 | 2015-07-31 17:11:07 +0800 | [diff] [blame] | 142 | break; |
| 143 | case 4: |
Yidi Lin | 0443ecc | 2015-12-28 16:40:54 +0800 | [diff] [blame] | 144 | gpio_output(PAD_SRCLKENAI, 0); |
| 145 | break; |
YH Huang | 1fcee36 | 2015-07-31 17:11:07 +0800 | [diff] [blame] | 146 | default: |
Yidi Lin | 0443ecc | 2015-12-28 16:40:54 +0800 | [diff] [blame] | 147 | gpio_output(PAD_UTXD2, 0); |
YH Huang | 1fcee36 | 2015-07-31 17:11:07 +0800 | [diff] [blame] | 148 | break; |
| 149 | } |
Yidi Lin | 0443ecc | 2015-12-28 16:40:54 +0800 | [diff] [blame] | 150 | |
| 151 | gpio_output(PAD_DISP_PWM0, 0); /* DISP_PWM0 */ |
| 152 | gpio_output(PAD_PCM_TX, 0); /* PANEL_POWER_EN */ |
YH Huang | 1fcee36 | 2015-07-31 17:11:07 +0800 | [diff] [blame] | 153 | } |
| 154 | |
Jitao Shi | 4a04a7b | 2016-01-08 16:02:13 +0800 | [diff] [blame^] | 155 | static void display_startup(void) |
| 156 | { |
| 157 | struct edid edid; |
| 158 | u8 i2c_bus; |
| 159 | int ret; |
| 160 | |
| 161 | switch (board_id()) { |
| 162 | case 0: |
| 163 | case 1: |
| 164 | i2c_bus = 3; |
| 165 | break; |
| 166 | default: |
| 167 | i2c_bus = 4; |
| 168 | break; |
| 169 | } |
| 170 | mtk_i2c_bus_init(i2c_bus); |
| 171 | |
| 172 | ps8640_init(i2c_bus, 0x18); |
| 173 | if (ps8640_get_edid(i2c_bus, 0x18, &edid)) { |
| 174 | printk(BIOS_ERR, "Can't get panel's edid\n"); |
| 175 | return; |
| 176 | } |
| 177 | |
| 178 | edid.x_resolution = edid.mode.ha; |
| 179 | edid.y_resolution = edid.mode.va; |
| 180 | edid.bytes_per_line = edid.mode.ha * edid.framebuffer_bits_per_pixel / |
| 181 | 8; |
| 182 | |
| 183 | mtk_ddp_init(); |
| 184 | ret = mtk_dsi_init(MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE, |
| 185 | MIPI_DSI_FMT_RGB888, 4, &edid); |
| 186 | if (ret < 0) { |
| 187 | printk(BIOS_ERR, "dsi init fail\n"); |
| 188 | return; |
| 189 | } |
| 190 | |
| 191 | mtk_ddp_mode_set(&edid); |
| 192 | |
| 193 | set_vbe_mode_info_valid(&edid, (uintptr_t)0); |
| 194 | } |
| 195 | |
Yidi Lin | 3d7b606 | 2015-07-31 17:10:40 +0800 | [diff] [blame] | 196 | static void mainboard_init(device_t dev) |
| 197 | { |
Ben Lok | a737940 | 2015-07-31 17:11:11 +0800 | [diff] [blame] | 198 | /* TP_SHIFT_EN: Enables the level shifter for I2C bus 4 (TPAD), which |
| 199 | * also contains the PS8640 eDP brige and the USB hub. |
| 200 | */ |
Yidi Lin | cd6aac1 | 2015-12-28 17:22:33 +0800 | [diff] [blame] | 201 | if (board_id() < 5) |
| 202 | mt6391_gpio_output(MT6391_KP_ROW2, 1); |
Ben Lok | a737940 | 2015-07-31 17:11:11 +0800 | [diff] [blame] | 203 | |
Yidi Lin | b9b2c6f | 2015-11-13 16:21:48 +0800 | [diff] [blame] | 204 | /* Config SD card detection pin */ |
| 205 | gpio_input(PAD_EINT1); /* SD_DET */ |
| 206 | |
Koro Chen | 9733ba5 | 2015-07-31 17:11:04 +0800 | [diff] [blame] | 207 | configure_audio(); |
Jitao Shi | 4a04a7b | 2016-01-08 16:02:13 +0800 | [diff] [blame^] | 208 | if (display_init_required()) { |
| 209 | configure_backlight(); |
| 210 | display_startup(); |
| 211 | } else { |
| 212 | printk(BIOS_INFO, "Skipping display init.\n"); |
| 213 | } |
Ben Lok | a737940 | 2015-07-31 17:11:11 +0800 | [diff] [blame] | 214 | configure_usb(); |
Ben Lok | 7d7dc20 | 2016-01-08 13:10:34 +0800 | [diff] [blame] | 215 | configure_usb_hub(); |
henryc.chen | 316ded8 | 2016-03-11 14:55:30 +0800 | [diff] [blame] | 216 | configure_ext_buck(); |
CC Ma | 72980b1 | 2015-09-15 17:33:38 +0800 | [diff] [blame] | 217 | |
| 218 | elog_init(); |
Julius Werner | c713594 | 2016-03-23 16:08:11 -0700 | [diff] [blame] | 219 | elog_add_watchdog_reset(); |
CC Ma | 72980b1 | 2015-09-15 17:33:38 +0800 | [diff] [blame] | 220 | elog_add_boot_reason(); |
Yidi Lin | 3d7b606 | 2015-07-31 17:10:40 +0800 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | static void mainboard_enable(device_t dev) |
| 224 | { |
| 225 | dev->ops->init = &mainboard_init; |
| 226 | } |
| 227 | |
| 228 | struct chip_operations mainboard_ops = { |
| 229 | .name = "oak", |
| 230 | .enable_dev = mainboard_enable, |
| 231 | }; |