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> |
Jimmy Huang | 27eba67 | 2015-07-31 17:11:00 +0800 | [diff] [blame] | 25 | #include <soc/bl31_plat_params.h> |
jun.gao | f059e97 | 2015-12-17 16:59:55 +0800 | [diff] [blame] | 26 | #include <soc/i2c.h> |
Koro Chen | 9733ba5 | 2015-07-31 17:11:04 +0800 | [diff] [blame] | 27 | #include <soc/mt6391.h> |
| 28 | #include <soc/mtcmos.h> |
| 29 | #include <soc/pinmux.h> |
| 30 | #include <soc/pll.h> |
Ben Lok | a737940 | 2015-07-31 17:11:11 +0800 | [diff] [blame] | 31 | #include <soc/usb.h> |
CC Ma | 72980b1 | 2015-09-15 17:33:38 +0800 | [diff] [blame] | 32 | #include <vendorcode/google/chromeos/chromeos.h> |
Koro Chen | 9733ba5 | 2015-07-31 17:11:04 +0800 | [diff] [blame] | 33 | |
Jimmy Huang | 27eba67 | 2015-07-31 17:11:00 +0800 | [diff] [blame] | 34 | static 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 = { |
henryc.chen | 70b3044 | 2015-12-23 11:45:29 +0800 | [diff] [blame] | 43 | .type = PARAM_GPIO_MT6391, |
Jimmy Huang | 27eba67 | 2015-07-31 17:11:00 +0800 | [diff] [blame] | 44 | .polarity = PARAM_GPIO_ACTIVE_HIGH, |
henryc.chen | 70b3044 | 2015-12-23 11:45:29 +0800 | [diff] [blame] | 45 | .index = MT6391_KP_ROW3, |
Jimmy Huang | 27eba67 | 2015-07-31 17:11:00 +0800 | [diff] [blame] | 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 | }; |
henryc.chen | 70b3044 | 2015-12-23 11:45:29 +0800 | [diff] [blame] | 56 | if (board_id() == 2) { |
| 57 | param_da9212.ic_en.type = PARAM_GPIO_SOC; |
| 58 | param_da9212.ic_en.index = PAD_UCTS2; |
| 59 | } |
Jimmy Huang | 27eba67 | 2015-07-31 17:11:00 +0800 | [diff] [blame] | 60 | register_bl31_param(¶m_da9212.h); |
jun.gao | f059e97 | 2015-12-17 16:59:55 +0800 | [diff] [blame] | 61 | |
| 62 | /* Init i2c bus Timing register for da9212 */ |
| 63 | mtk_i2c_bus_init(param_da9212.i2c_bus); |
Jimmy Huang | 27eba67 | 2015-07-31 17:11:00 +0800 | [diff] [blame] | 64 | #endif |
| 65 | } |
| 66 | |
| 67 | static void register_mt6311_to_bl31(void) |
| 68 | { |
| 69 | #if IS_ENABLED(CONFIG_ARM64_USE_ARM_TRUSTED_FIRMWARE) |
| 70 | static struct bl31_mt6311_param param_mt6311 = { |
| 71 | .h = { |
| 72 | .type = PARAM_CLUSTER1_MT6311, |
| 73 | }, |
| 74 | .i2c_bus = 1, |
| 75 | }; |
| 76 | register_bl31_param(¶m_mt6311.h); |
jun.gao | f059e97 | 2015-12-17 16:59:55 +0800 | [diff] [blame] | 77 | |
| 78 | /* Init i2c bus Timing register for mt6311 */ |
| 79 | mtk_i2c_bus_init(param_mt6311.i2c_bus); |
Jimmy Huang | 27eba67 | 2015-07-31 17:11:00 +0800 | [diff] [blame] | 80 | #endif |
| 81 | } |
| 82 | |
| 83 | static void configure_bl31(void) |
| 84 | { |
| 85 | switch (board_id()) { |
henryc.chen | 70b3044 | 2015-12-23 11:45:29 +0800 | [diff] [blame] | 86 | case 3: |
| 87 | case 4: |
Jimmy Huang | 27eba67 | 2015-07-31 17:11:00 +0800 | [diff] [blame] | 88 | /* rev-3 and rev-4 use mt6311 as external buck */ |
| 89 | register_mt6311_to_bl31(); |
| 90 | break; |
henryc.chen | 70b3044 | 2015-12-23 11:45:29 +0800 | [diff] [blame] | 91 | case 2: |
| 92 | default: |
| 93 | /* rev-2 and rev-5 use da9212 as external buck */ |
| 94 | register_da9212_to_bl31(); |
| 95 | break; |
Jimmy Huang | 27eba67 | 2015-07-31 17:11:00 +0800 | [diff] [blame] | 96 | } |
| 97 | } |
| 98 | |
Koro Chen | 9733ba5 | 2015-07-31 17:11:04 +0800 | [diff] [blame] | 99 | static void configure_audio(void) |
| 100 | { |
| 101 | mtcmos_audio_power_on(); |
| 102 | |
Koro Chen | 603cb85 | 2015-12-30 17:50:56 +0800 | [diff] [blame] | 103 | /* vgp1 set to 1.8V */ |
| 104 | mt6391_configure_ldo(LDO_VCAMD, LDO_1P8); |
| 105 | /* delay 1ms for realtek's power sequence request */ |
| 106 | mdelay(1); |
| 107 | /* vcama set to 1.8V */ |
| 108 | mt6391_configure_ldo(LDO_VCAMA, LDO_1P8); |
Koro Chen | 9733ba5 | 2015-07-31 17:11:04 +0800 | [diff] [blame] | 109 | |
| 110 | /* reset ALC5676 */ |
Koro Chen | a9f6529 | 2015-12-30 17:31:44 +0800 | [diff] [blame] | 111 | if (board_id() < 5) |
| 112 | gpio_output(PAD_LCM_RST, 1); |
Koro Chen | 9733ba5 | 2015-07-31 17:11:04 +0800 | [diff] [blame] | 113 | |
| 114 | /* SoC I2S */ |
| 115 | gpio_set_mode(PAD_I2S0_LRCK, PAD_I2S0_LRCK_FUNC_I2S1_WS); |
| 116 | gpio_set_mode(PAD_I2S0_BCK, PAD_I2S0_BCK_FUNC_I2S1_BCK); |
| 117 | gpio_set_mode(PAD_I2S0_MCK, PAD_I2S0_MCK_FUNC_I2S1_MCK); |
| 118 | gpio_set_mode(PAD_I2S0_DATA0, PAD_I2S0_DATA0_FUNC_I2S1_DO_1); |
| 119 | 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] | 120 | if (board_id() >= 5) |
| 121 | gpio_set_mode(PAD_UCTS0, PAD_UCTS0_FUNC_I2S2_DI_1); |
Koro Chen | 9733ba5 | 2015-07-31 17:11:04 +0800 | [diff] [blame] | 122 | |
| 123 | /* codec ext MCLK ON */ |
| 124 | mt6391_gpio_output(MT6391_KP_COL4, 1); |
| 125 | mt6391_gpio_output(MT6391_KP_COL5, 1); |
| 126 | |
jun.gao | f059e97 | 2015-12-17 16:59:55 +0800 | [diff] [blame] | 127 | /* Init i2c bus Timing register for audio codecs */ |
| 128 | mtk_i2c_bus_init(0); |
| 129 | |
Koro Chen | 9733ba5 | 2015-07-31 17:11:04 +0800 | [diff] [blame] | 130 | /* set I2S clock to 48KHz */ |
| 131 | mt_pll_set_aud_div(48 * KHz); |
| 132 | } |
| 133 | |
Ben Lok | a737940 | 2015-07-31 17:11:11 +0800 | [diff] [blame] | 134 | static void configure_usb(void) |
| 135 | { |
| 136 | setup_usb_host(); |
| 137 | |
| 138 | if (board_id() > 3) |
| 139 | gpio_output(PAD_CM2MCLK, 1); |
| 140 | } |
| 141 | |
Ben Lok | 7d7dc20 | 2016-01-08 13:10:34 +0800 | [diff] [blame^] | 142 | static void configure_usb_hub(void) |
| 143 | { |
| 144 | /* set usb hub reset pin (low active) to high */ |
| 145 | if (board_id() > 4) |
| 146 | gpio_output(PAD_UTXD3, 1); |
| 147 | } |
| 148 | |
YH Huang | 1fcee36 | 2015-07-31 17:11:07 +0800 | [diff] [blame] | 149 | /* Setup backlight control pins as output pin and power-off by default */ |
| 150 | static void configure_backlight(void) |
| 151 | { |
Yidi Lin | 0443ecc | 2015-12-28 16:40:54 +0800 | [diff] [blame] | 152 | /* Configure PANEL_LCD_POWER_EN */ |
YH Huang | 1fcee36 | 2015-07-31 17:11:07 +0800 | [diff] [blame] | 153 | switch (board_id()) { |
YH Huang | 1fcee36 | 2015-07-31 17:11:07 +0800 | [diff] [blame] | 154 | case 1: |
| 155 | case 2: |
YH Huang | 1fcee36 | 2015-07-31 17:11:07 +0800 | [diff] [blame] | 156 | break; |
| 157 | case 3: |
Yidi Lin | 0443ecc | 2015-12-28 16:40:54 +0800 | [diff] [blame] | 158 | gpio_output(PAD_UCTS2, 0); |
YH Huang | 1fcee36 | 2015-07-31 17:11:07 +0800 | [diff] [blame] | 159 | break; |
| 160 | case 4: |
Yidi Lin | 0443ecc | 2015-12-28 16:40:54 +0800 | [diff] [blame] | 161 | gpio_output(PAD_SRCLKENAI, 0); |
| 162 | break; |
YH Huang | 1fcee36 | 2015-07-31 17:11:07 +0800 | [diff] [blame] | 163 | default: |
Yidi Lin | 0443ecc | 2015-12-28 16:40:54 +0800 | [diff] [blame] | 164 | gpio_output(PAD_UTXD2, 0); |
YH Huang | 1fcee36 | 2015-07-31 17:11:07 +0800 | [diff] [blame] | 165 | break; |
| 166 | } |
Yidi Lin | 0443ecc | 2015-12-28 16:40:54 +0800 | [diff] [blame] | 167 | |
| 168 | gpio_output(PAD_DISP_PWM0, 0); /* DISP_PWM0 */ |
| 169 | gpio_output(PAD_PCM_TX, 0); /* PANEL_POWER_EN */ |
YH Huang | 1fcee36 | 2015-07-31 17:11:07 +0800 | [diff] [blame] | 170 | } |
| 171 | |
Yidi Lin | 3d7b606 | 2015-07-31 17:10:40 +0800 | [diff] [blame] | 172 | static void mainboard_init(device_t dev) |
| 173 | { |
Ben Lok | a737940 | 2015-07-31 17:11:11 +0800 | [diff] [blame] | 174 | /* TP_SHIFT_EN: Enables the level shifter for I2C bus 4 (TPAD), which |
| 175 | * also contains the PS8640 eDP brige and the USB hub. |
| 176 | */ |
Yidi Lin | cd6aac1 | 2015-12-28 17:22:33 +0800 | [diff] [blame] | 177 | if (board_id() < 5) |
| 178 | mt6391_gpio_output(MT6391_KP_ROW2, 1); |
Ben Lok | a737940 | 2015-07-31 17:11:11 +0800 | [diff] [blame] | 179 | |
Yidi Lin | b9b2c6f | 2015-11-13 16:21:48 +0800 | [diff] [blame] | 180 | /* Config SD card detection pin */ |
| 181 | gpio_input(PAD_EINT1); /* SD_DET */ |
| 182 | |
Koro Chen | 9733ba5 | 2015-07-31 17:11:04 +0800 | [diff] [blame] | 183 | configure_audio(); |
YH Huang | 1fcee36 | 2015-07-31 17:11:07 +0800 | [diff] [blame] | 184 | configure_backlight(); |
Ben Lok | a737940 | 2015-07-31 17:11:11 +0800 | [diff] [blame] | 185 | configure_usb(); |
Ben Lok | 7d7dc20 | 2016-01-08 13:10:34 +0800 | [diff] [blame^] | 186 | configure_usb_hub(); |
Jimmy Huang | 27eba67 | 2015-07-31 17:11:00 +0800 | [diff] [blame] | 187 | configure_bl31(); |
CC Ma | 72980b1 | 2015-09-15 17:33:38 +0800 | [diff] [blame] | 188 | |
| 189 | elog_init(); |
| 190 | elog_add_boot_reason(); |
Yidi Lin | 3d7b606 | 2015-07-31 17:10:40 +0800 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | static void mainboard_enable(device_t dev) |
| 194 | { |
| 195 | dev->ops->init = &mainboard_init; |
| 196 | } |
| 197 | |
| 198 | struct chip_operations mainboard_ops = { |
| 199 | .name = "oak", |
| 200 | .enable_dev = mainboard_enable, |
| 201 | }; |