Wenbin Mei | 24c6355 | 2021-02-24 15:17:41 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
Yidi Lin | 7c06dd9 | 2021-04-08 09:55:11 +0800 | [diff] [blame] | 3 | #include <bl31.h> |
Wenbin Mei | 24c6355 | 2021-02-24 15:17:41 +0800 | [diff] [blame] | 4 | #include <bootmode.h> |
| 5 | #include <console/console.h> |
| 6 | #include <delay.h> |
| 7 | #include <device/device.h> |
| 8 | #include <device/mmio.h> |
Jitao Shi | f2c259c | 2021-06-03 13:51:29 +0800 | [diff] [blame] | 9 | #include <edid.h> |
| 10 | #include <framebuffer_info.h> |
Wenbin Mei | 24c6355 | 2021-02-24 15:17:41 +0800 | [diff] [blame] | 11 | #include <gpio.h> |
Jitao Shi | f2c259c | 2021-06-03 13:51:29 +0800 | [diff] [blame] | 12 | #include <soc/ddp.h> |
Ryan Chuang | da63f09 | 2021-06-23 09:47:37 +0800 | [diff] [blame] | 13 | #include <soc/dpm.h> |
Jitao Shi | f2c259c | 2021-06-03 13:51:29 +0800 | [diff] [blame] | 14 | #include <soc/dptx.h> |
Wenbin Mei | 24c6355 | 2021-02-24 15:17:41 +0800 | [diff] [blame] | 15 | #include <soc/gpio.h> |
| 16 | #include <soc/i2c.h> |
| 17 | #include <soc/mt6360.h> |
Jitao Shi | f2c259c | 2021-06-03 13:51:29 +0800 | [diff] [blame] | 18 | #include <soc/mtcmos.h> |
Wenbin Mei | 24c6355 | 2021-02-24 15:17:41 +0800 | [diff] [blame] | 19 | #include <soc/regulator.h> |
Rex-BC Chen | 9e3e0f5 | 2021-06-03 11:41:07 +0800 | [diff] [blame] | 20 | #include <soc/spm.h> |
Yuchen Huang | 144237f | 2021-03-01 14:39:33 +0800 | [diff] [blame] | 21 | #include <soc/usb.h> |
Wenbin Mei | 24c6355 | 2021-02-24 15:17:41 +0800 | [diff] [blame] | 22 | |
Yidi Lin | 7c06dd9 | 2021-04-08 09:55:11 +0800 | [diff] [blame] | 23 | #include "gpio.h" |
| 24 | |
| 25 | #include <arm-trusted-firmware/include/export/plat/mediatek/common/plat_params_exp.h> |
| 26 | |
Jitao Shi | f2c259c | 2021-06-03 13:51:29 +0800 | [diff] [blame] | 27 | /* GPIO to schematics names */ |
| 28 | #define GPIO_AP_EDP_BKLTEN GPIO(DGI_D5) |
| 29 | #define GPIO_BL_PWM_1V8 GPIO(DISP_PWM0) |
| 30 | #define GPIO_EDP_HPD_1V8 GPIO(GPIO_07) |
| 31 | #define GPIO_EN_PP3300_DISP_X GPIO(I2SO1_D2) |
| 32 | |
Wenbin Mei | 24c6355 | 2021-02-24 15:17:41 +0800 | [diff] [blame] | 33 | DEFINE_BITFIELD(MSDC0_DRV, 29, 0) |
| 34 | DEFINE_BITFIELD(MSDC1_DRV, 17, 0) |
| 35 | DEFINE_BITFIELD(MSDC1_GPIO_MODE0_0, 26, 24) |
| 36 | DEFINE_BITFIELD(MSDC1_GPIO_MODE0_1, 30, 28) |
| 37 | DEFINE_BITFIELD(MSDC1_GPIO_MODE1_0, 2, 0) |
| 38 | DEFINE_BITFIELD(MSDC1_GPIO_MODE1_1, 6, 4) |
| 39 | DEFINE_BITFIELD(MSDC1_GPIO_MODE1_2, 10, 8) |
| 40 | DEFINE_BITFIELD(MSDC1_GPIO_MODE1_3, 14, 12) |
| 41 | |
| 42 | #define MSDC0_DRV_VALUE 0x1b6db6db |
| 43 | #define MSDC1_DRV_VALUE 0x1b6db |
| 44 | #define MSDC1_GPIO_MODE0_VALUE 0x1 |
| 45 | #define MSDC1_GPIO_MODE1_VALUE 0x1 |
| 46 | |
| 47 | enum { |
| 48 | MSDC1_GPIO_MODE0_BASE = 0x100053d0, |
| 49 | MSDC1_GPIO_MODE1_BASE = 0x100053e0, |
| 50 | }; |
| 51 | |
Yidi Lin | 7c06dd9 | 2021-04-08 09:55:11 +0800 | [diff] [blame] | 52 | static void register_reset_to_bl31(void) |
| 53 | { |
| 54 | static struct bl_aux_param_gpio param_reset = { |
| 55 | .h = { .type = BL_AUX_PARAM_MTK_RESET_GPIO }, |
| 56 | .gpio = { .polarity = ARM_TF_GPIO_LEVEL_HIGH }, |
| 57 | }; |
| 58 | |
| 59 | param_reset.gpio.index = GPIO_RESET.id; |
| 60 | register_bl31_aux_param(¶m_reset.h); |
| 61 | } |
| 62 | |
Wenbin Mei | 24c6355 | 2021-02-24 15:17:41 +0800 | [diff] [blame] | 63 | static void configure_emmc(void) |
| 64 | { |
| 65 | void *gpio_base = (void *)IOCFG_TL_BASE; |
| 66 | int i; |
| 67 | |
| 68 | const gpio_t emmc_pu_pin[] = { |
| 69 | GPIO(EMMC_DAT0), GPIO(EMMC_DAT1), |
| 70 | GPIO(EMMC_DAT2), GPIO(EMMC_DAT3), |
| 71 | GPIO(EMMC_DAT4), GPIO(EMMC_DAT5), |
| 72 | GPIO(EMMC_DAT6), GPIO(EMMC_DAT7), |
| 73 | GPIO(EMMC_CMD), GPIO(EMMC_RSTB), |
| 74 | }; |
| 75 | |
| 76 | const gpio_t emmc_pd_pin[] = { |
| 77 | GPIO(EMMC_DSL), GPIO(EMMC_CLK), |
| 78 | }; |
| 79 | |
| 80 | for (i = 0; i < ARRAY_SIZE(emmc_pu_pin); i++) |
| 81 | gpio_set_pull(emmc_pu_pin[i], GPIO_PULL_ENABLE, GPIO_PULL_UP); |
| 82 | |
| 83 | for (i = 0; i < ARRAY_SIZE(emmc_pd_pin); i++) |
| 84 | gpio_set_pull(emmc_pd_pin[i], GPIO_PULL_ENABLE, GPIO_PULL_DOWN); |
| 85 | |
| 86 | /* set eMMC cmd/dat/clk/ds/rstb pins driving to 8mA */ |
| 87 | SET32_BITFIELDS(gpio_base, MSDC0_DRV, MSDC0_DRV_VALUE); |
| 88 | } |
| 89 | |
| 90 | static void configure_sdcard(void) |
| 91 | { |
| 92 | void *gpio_base = (void *)IOCFG_RB_BASE; |
| 93 | void *gpio_mode0_base = (void *)MSDC1_GPIO_MODE0_BASE; |
| 94 | void *gpio_mode1_base = (void *)MSDC1_GPIO_MODE1_BASE; |
| 95 | int i; |
| 96 | |
| 97 | const gpio_t sdcard_pu_pin[] = { |
| 98 | GPIO(MSDC1_DAT0), GPIO(MSDC1_DAT1), |
| 99 | GPIO(MSDC1_DAT2), GPIO(MSDC1_DAT3), |
| 100 | GPIO(MSDC1_CMD), |
| 101 | }; |
| 102 | |
| 103 | const gpio_t sdcard_pd_pin[] = { |
| 104 | GPIO(MSDC1_CLK), |
| 105 | }; |
| 106 | |
| 107 | for (i = 0; i < ARRAY_SIZE(sdcard_pu_pin); i++) |
| 108 | gpio_set_pull(sdcard_pu_pin[i], GPIO_PULL_ENABLE, GPIO_PULL_UP); |
| 109 | |
| 110 | for (i = 0; i < ARRAY_SIZE(sdcard_pd_pin); i++) |
| 111 | gpio_set_pull(sdcard_pd_pin[i], GPIO_PULL_ENABLE, GPIO_PULL_DOWN); |
| 112 | |
| 113 | /* set sdcard cmd/dat/clk pins driving to 8mA */ |
| 114 | SET32_BITFIELDS(gpio_base, MSDC1_DRV, MSDC1_DRV_VALUE); |
| 115 | |
| 116 | /* set sdcard dat2/dat0/dat3/cmd/clk pins to msdc1 mode */ |
| 117 | SET32_BITFIELDS(gpio_mode0_base, |
| 118 | MSDC1_GPIO_MODE0_0, MSDC1_GPIO_MODE0_VALUE, |
| 119 | MSDC1_GPIO_MODE0_1, MSDC1_GPIO_MODE0_VALUE); |
| 120 | |
| 121 | /* set sdcard dat1 pin to msdc1 mode */ |
| 122 | SET32_BITFIELDS(gpio_mode1_base, |
| 123 | MSDC1_GPIO_MODE1_0, MSDC1_GPIO_MODE1_VALUE, |
| 124 | MSDC1_GPIO_MODE1_1, MSDC1_GPIO_MODE1_VALUE, |
| 125 | MSDC1_GPIO_MODE1_2, MSDC1_GPIO_MODE1_VALUE, |
| 126 | MSDC1_GPIO_MODE1_3, MSDC1_GPIO_MODE1_VALUE); |
| 127 | |
Rex-BC Chen | 97582de | 2021-07-22 11:16:15 +0800 | [diff] [blame] | 128 | mtk_i2c_bus_init(I2C7); |
Rex-BC Chen | cc80a9a | 2021-07-13 19:41:02 +0800 | [diff] [blame] | 129 | |
| 130 | if (CONFIG(BOARD_GOOGLE_CHERRY)) |
Rex-BC Chen | 97582de | 2021-07-22 11:16:15 +0800 | [diff] [blame] | 131 | mt6360_init(I2C7); |
Rex-BC Chen | cc80a9a | 2021-07-13 19:41:02 +0800 | [diff] [blame] | 132 | |
Rex-BC Chen | fdde4cd | 2021-07-13 18:55:58 +0800 | [diff] [blame] | 133 | mainboard_enable_regulator(MTK_REGULATOR_VCCQ, 1); |
| 134 | mainboard_enable_regulator(MTK_REGULATOR_VCC, 1); |
Wenbin Mei | 24c6355 | 2021-02-24 15:17:41 +0800 | [diff] [blame] | 135 | } |
| 136 | |
Jitao Shi | f2c259c | 2021-06-03 13:51:29 +0800 | [diff] [blame] | 137 | /* Set up backlight control pins as output pin and power-off by default */ |
| 138 | static void configure_panel_backlight(void) |
| 139 | { |
| 140 | gpio_output(GPIO_AP_EDP_BKLTEN, 0); |
| 141 | gpio_output(GPIO_BL_PWM_1V8, 0); |
| 142 | } |
| 143 | |
| 144 | static void power_on_panel(void) |
| 145 | { |
| 146 | /* Default power sequence for most panels. */ |
| 147 | gpio_set_pull(GPIO_EDP_HPD_1V8, GPIO_PULL_ENABLE, GPIO_PULL_UP); |
| 148 | gpio_set_mode(GPIO_EDP_HPD_1V8, 2); |
| 149 | gpio_output(GPIO_EN_PP3300_DISP_X, 1); |
| 150 | } |
| 151 | |
| 152 | static bool configure_display(void) |
| 153 | { |
| 154 | struct edid edid; |
| 155 | struct fb_info *info; |
| 156 | const char *name; |
| 157 | |
| 158 | printk(BIOS_INFO, "%s: Starting display initialization\n", __func__); |
| 159 | |
| 160 | mtcmos_display_power_on(); |
| 161 | mtcmos_protect_display_bus(); |
| 162 | configure_panel_backlight(); |
| 163 | power_on_panel(); |
| 164 | |
| 165 | mtk_ddp_init(); |
| 166 | mdelay(200); |
| 167 | |
| 168 | if (mtk_edp_init(&edid) < 0) { |
| 169 | printk(BIOS_ERR, "%s: Failed to initialize eDP\n", __func__); |
| 170 | return false; |
| 171 | } |
| 172 | name = edid.ascii_string; |
| 173 | if (name[0] == '\0') |
| 174 | name = "unknown name"; |
| 175 | printk(BIOS_INFO, "%s: '%s %s' %dx%d@%dHz\n", __func__, |
| 176 | edid.manufacturer_name, name, edid.mode.ha, edid.mode.va, |
| 177 | edid.mode.refresh); |
| 178 | |
| 179 | edid_set_framebuffer_bits_per_pixel(&edid, 32, 0); |
| 180 | |
| 181 | mtk_ddp_mode_set(&edid); |
| 182 | info = fb_new_framebuffer_info_from_edid(&edid, (uintptr_t)0); |
| 183 | if (info) |
| 184 | fb_set_orientation(info, LB_FB_ORIENTATION_NORMAL); |
| 185 | |
| 186 | return true; |
| 187 | } |
| 188 | |
Wenbin Mei | 24c6355 | 2021-02-24 15:17:41 +0800 | [diff] [blame] | 189 | static void mainboard_init(struct device *dev) |
| 190 | { |
Jitao Shi | f2c259c | 2021-06-03 13:51:29 +0800 | [diff] [blame] | 191 | if (display_init_required()) |
| 192 | configure_display(); |
| 193 | else |
| 194 | printk(BIOS_INFO, "%s: Skipped display initialization\n", __func__); |
| 195 | |
Wenbin Mei | 24c6355 | 2021-02-24 15:17:41 +0800 | [diff] [blame] | 196 | configure_emmc(); |
| 197 | configure_sdcard(); |
Yuchen Huang | 144237f | 2021-03-01 14:39:33 +0800 | [diff] [blame] | 198 | setup_usb_host(); |
Yidi Lin | 7c06dd9 | 2021-04-08 09:55:11 +0800 | [diff] [blame] | 199 | |
Ryan Chuang | da63f09 | 2021-06-23 09:47:37 +0800 | [diff] [blame] | 200 | if (dpm_init()) |
| 201 | printk(BIOS_ERR, "dpm init failed, DVFS may not work\n"); |
| 202 | |
Rex-BC Chen | 9e3e0f5 | 2021-06-03 11:41:07 +0800 | [diff] [blame] | 203 | if (spm_init()) |
| 204 | printk(BIOS_ERR, "spm init failed, system suspend may not work\n"); |
| 205 | |
Yidi Lin | 7c06dd9 | 2021-04-08 09:55:11 +0800 | [diff] [blame] | 206 | register_reset_to_bl31(); |
Wenbin Mei | 24c6355 | 2021-02-24 15:17:41 +0800 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | static void mainboard_enable(struct device *dev) |
| 210 | { |
| 211 | dev->ops->init = &mainboard_init; |
| 212 | } |
| 213 | |
| 214 | struct chip_operations mainboard_ops = { |
| 215 | .name = CONFIG_MAINBOARD_PART_NUMBER, |
| 216 | .enable_dev = mainboard_enable, |
| 217 | }; |