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> |
Koro Chen | 9733ba5 | 2015-07-31 17:11:04 +0800 | [diff] [blame] | 20 | #include <delay.h> |
Yidi Lin | 3d7b606 | 2015-07-31 17:10:40 +0800 | [diff] [blame] | 21 | #include <device/device.h> |
| 22 | |
CC Ma | 72980b1 | 2015-09-15 17:33:38 +0800 | [diff] [blame] | 23 | #include <elog.h> |
Koro Chen | 9733ba5 | 2015-07-31 17:11:04 +0800 | [diff] [blame] | 24 | #include <gpio.h> |
henryc.chen | 316ded8 | 2016-03-11 14:55:30 +0800 | [diff] [blame^] | 25 | #include <soc/da9212.h> |
jun.gao | f059e97 | 2015-12-17 16:59:55 +0800 | [diff] [blame] | 26 | #include <soc/i2c.h> |
henryc.chen | 316ded8 | 2016-03-11 14:55:30 +0800 | [diff] [blame^] | 27 | #include <soc/mt6311.h> |
Koro Chen | 9733ba5 | 2015-07-31 17:11:04 +0800 | [diff] [blame] | 28 | #include <soc/mt6391.h> |
| 29 | #include <soc/mtcmos.h> |
| 30 | #include <soc/pinmux.h> |
| 31 | #include <soc/pll.h> |
Ben Lok | a737940 | 2015-07-31 17:11:11 +0800 | [diff] [blame] | 32 | #include <soc/usb.h> |
CC Ma | 72980b1 | 2015-09-15 17:33:38 +0800 | [diff] [blame] | 33 | #include <vendorcode/google/chromeos/chromeos.h> |
Koro Chen | 9733ba5 | 2015-07-31 17:11:04 +0800 | [diff] [blame] | 34 | |
henryc.chen | 316ded8 | 2016-03-11 14:55:30 +0800 | [diff] [blame^] | 35 | enum { |
| 36 | CODEC_I2C_BUS = 0, |
| 37 | EXT_BUCK_I2C_BUS = 1, |
| 38 | }; |
| 39 | |
| 40 | static void configure_ext_buck(void) |
Jimmy Huang | 27eba67 | 2015-07-31 17:11:00 +0800 | [diff] [blame] | 41 | { |
henryc.chen | 316ded8 | 2016-03-11 14:55:30 +0800 | [diff] [blame^] | 42 | mtk_i2c_bus_init(EXT_BUCK_I2C_BUS); |
jun.gao | f059e97 | 2015-12-17 16:59:55 +0800 | [diff] [blame] | 43 | |
Jimmy Huang | 27eba67 | 2015-07-31 17:11:00 +0800 | [diff] [blame] | 44 | switch (board_id()) { |
henryc.chen | 70b3044 | 2015-12-23 11:45:29 +0800 | [diff] [blame] | 45 | case 3: |
| 46 | case 4: |
Jimmy Huang | 27eba67 | 2015-07-31 17:11:00 +0800 | [diff] [blame] | 47 | /* rev-3 and rev-4 use mt6311 as external buck */ |
henryc.chen | 316ded8 | 2016-03-11 14:55:30 +0800 | [diff] [blame^] | 48 | gpio_output(PAD_EINT15, 1); |
| 49 | udelay(500); |
| 50 | mt6311_probe(EXT_BUCK_I2C_BUS); |
Jimmy Huang | 27eba67 | 2015-07-31 17:11:00 +0800 | [diff] [blame] | 51 | break; |
henryc.chen | 70b3044 | 2015-12-23 11:45:29 +0800 | [diff] [blame] | 52 | case 2: |
| 53 | default: |
| 54 | /* rev-2 and rev-5 use da9212 as external buck */ |
henryc.chen | 316ded8 | 2016-03-11 14:55:30 +0800 | [diff] [blame^] | 55 | 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.chen | 70b3044 | 2015-12-23 11:45:29 +0800 | [diff] [blame] | 59 | break; |
Jimmy Huang | 27eba67 | 2015-07-31 17:11:00 +0800 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | |
Koro Chen | 9733ba5 | 2015-07-31 17:11:04 +0800 | [diff] [blame] | 63 | static void configure_audio(void) |
| 64 | { |
| 65 | mtcmos_audio_power_on(); |
| 66 | |
Koro Chen | 603cb85 | 2015-12-30 17:50:56 +0800 | [diff] [blame] | 67 | /* 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 Chen | 9733ba5 | 2015-07-31 17:11:04 +0800 | [diff] [blame] | 73 | |
| 74 | /* reset ALC5676 */ |
Koro Chen | a9f6529 | 2015-12-30 17:31:44 +0800 | [diff] [blame] | 75 | if (board_id() < 5) |
| 76 | gpio_output(PAD_LCM_RST, 1); |
Koro Chen | 9733ba5 | 2015-07-31 17:11:04 +0800 | [diff] [blame] | 77 | |
| 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 Chen | a9f6529 | 2015-12-30 17:31:44 +0800 | [diff] [blame] | 84 | if (board_id() >= 5) |
| 85 | gpio_set_mode(PAD_UCTS0, PAD_UCTS0_FUNC_I2S2_DI_1); |
Koro Chen | 9733ba5 | 2015-07-31 17:11:04 +0800 | [diff] [blame] | 86 | |
| 87 | /* codec ext MCLK ON */ |
| 88 | mt6391_gpio_output(MT6391_KP_COL4, 1); |
| 89 | mt6391_gpio_output(MT6391_KP_COL5, 1); |
| 90 | |
jun.gao | f059e97 | 2015-12-17 16:59:55 +0800 | [diff] [blame] | 91 | /* Init i2c bus Timing register for audio codecs */ |
henryc.chen | 316ded8 | 2016-03-11 14:55:30 +0800 | [diff] [blame^] | 92 | mtk_i2c_bus_init(CODEC_I2C_BUS); |
jun.gao | f059e97 | 2015-12-17 16:59:55 +0800 | [diff] [blame] | 93 | |
Koro Chen | 9733ba5 | 2015-07-31 17:11:04 +0800 | [diff] [blame] | 94 | /* set I2S clock to 48KHz */ |
| 95 | mt_pll_set_aud_div(48 * KHz); |
| 96 | } |
| 97 | |
Ben Lok | a737940 | 2015-07-31 17:11:11 +0800 | [diff] [blame] | 98 | static void configure_usb(void) |
| 99 | { |
| 100 | setup_usb_host(); |
| 101 | |
Yidi Lin | 358f66a | 2016-01-11 10:05:46 +0800 | [diff] [blame] | 102 | if (board_id() > 3) { |
| 103 | /* Enable current limit */ |
Ben Lok | a737940 | 2015-07-31 17:11:11 +0800 | [diff] [blame] | 104 | gpio_output(PAD_CM2MCLK, 1); |
Yidi Lin | 358f66a | 2016-01-11 10:05:46 +0800 | [diff] [blame] | 105 | /* 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 Lok | a737940 | 2015-07-31 17:11:11 +0800 | [diff] [blame] | 117 | } |
| 118 | |
Ben Lok | 7d7dc20 | 2016-01-08 13:10:34 +0800 | [diff] [blame] | 119 | static 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 Huang | 1fcee36 | 2015-07-31 17:11:07 +0800 | [diff] [blame] | 126 | /* Setup backlight control pins as output pin and power-off by default */ |
| 127 | static void configure_backlight(void) |
| 128 | { |
Yidi Lin | 0443ecc | 2015-12-28 16:40:54 +0800 | [diff] [blame] | 129 | /* Configure PANEL_LCD_POWER_EN */ |
YH Huang | 1fcee36 | 2015-07-31 17:11:07 +0800 | [diff] [blame] | 130 | switch (board_id()) { |
YH Huang | 1fcee36 | 2015-07-31 17:11:07 +0800 | [diff] [blame] | 131 | case 1: |
| 132 | case 2: |
YH Huang | 1fcee36 | 2015-07-31 17:11:07 +0800 | [diff] [blame] | 133 | break; |
| 134 | case 3: |
Yidi Lin | 0443ecc | 2015-12-28 16:40:54 +0800 | [diff] [blame] | 135 | gpio_output(PAD_UCTS2, 0); |
YH Huang | 1fcee36 | 2015-07-31 17:11:07 +0800 | [diff] [blame] | 136 | break; |
| 137 | case 4: |
Yidi Lin | 0443ecc | 2015-12-28 16:40:54 +0800 | [diff] [blame] | 138 | gpio_output(PAD_SRCLKENAI, 0); |
| 139 | break; |
YH Huang | 1fcee36 | 2015-07-31 17:11:07 +0800 | [diff] [blame] | 140 | default: |
Yidi Lin | 0443ecc | 2015-12-28 16:40:54 +0800 | [diff] [blame] | 141 | gpio_output(PAD_UTXD2, 0); |
YH Huang | 1fcee36 | 2015-07-31 17:11:07 +0800 | [diff] [blame] | 142 | break; |
| 143 | } |
Yidi Lin | 0443ecc | 2015-12-28 16:40:54 +0800 | [diff] [blame] | 144 | |
| 145 | gpio_output(PAD_DISP_PWM0, 0); /* DISP_PWM0 */ |
| 146 | gpio_output(PAD_PCM_TX, 0); /* PANEL_POWER_EN */ |
YH Huang | 1fcee36 | 2015-07-31 17:11:07 +0800 | [diff] [blame] | 147 | } |
| 148 | |
Yidi Lin | 3d7b606 | 2015-07-31 17:10:40 +0800 | [diff] [blame] | 149 | static void mainboard_init(device_t dev) |
| 150 | { |
Ben Lok | a737940 | 2015-07-31 17:11:11 +0800 | [diff] [blame] | 151 | /* 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 Lin | cd6aac1 | 2015-12-28 17:22:33 +0800 | [diff] [blame] | 154 | if (board_id() < 5) |
| 155 | mt6391_gpio_output(MT6391_KP_ROW2, 1); |
Ben Lok | a737940 | 2015-07-31 17:11:11 +0800 | [diff] [blame] | 156 | |
Yidi Lin | b9b2c6f | 2015-11-13 16:21:48 +0800 | [diff] [blame] | 157 | /* Config SD card detection pin */ |
| 158 | gpio_input(PAD_EINT1); /* SD_DET */ |
| 159 | |
Koro Chen | 9733ba5 | 2015-07-31 17:11:04 +0800 | [diff] [blame] | 160 | configure_audio(); |
YH Huang | 1fcee36 | 2015-07-31 17:11:07 +0800 | [diff] [blame] | 161 | configure_backlight(); |
Ben Lok | a737940 | 2015-07-31 17:11:11 +0800 | [diff] [blame] | 162 | configure_usb(); |
Ben Lok | 7d7dc20 | 2016-01-08 13:10:34 +0800 | [diff] [blame] | 163 | configure_usb_hub(); |
henryc.chen | 316ded8 | 2016-03-11 14:55:30 +0800 | [diff] [blame^] | 164 | configure_ext_buck(); |
CC Ma | 72980b1 | 2015-09-15 17:33:38 +0800 | [diff] [blame] | 165 | |
| 166 | elog_init(); |
| 167 | elog_add_boot_reason(); |
Yidi Lin | 3d7b606 | 2015-07-31 17:10:40 +0800 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | static void mainboard_enable(device_t dev) |
| 171 | { |
| 172 | dev->ops->init = &mainboard_init; |
| 173 | } |
| 174 | |
| 175 | struct chip_operations mainboard_ops = { |
| 176 | .name = "oak", |
| 177 | .enable_dev = mainboard_enable, |
| 178 | }; |