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