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> |
Wenbin Mei | ca33b74a | 2021-08-04 10:53:27 +0800 | [diff] [blame] | 17 | #include <soc/msdc.h> |
Jitao Shi | f2c259c | 2021-06-03 13:51:29 +0800 | [diff] [blame] | 18 | #include <soc/mtcmos.h> |
Rex-BC Chen | 9e3e0f5 | 2021-06-03 11:41:07 +0800 | [diff] [blame] | 19 | #include <soc/spm.h> |
Yuchen Huang | 144237f | 2021-03-01 14:39:33 +0800 | [diff] [blame] | 20 | #include <soc/usb.h> |
Wenbin Mei | 24c6355 | 2021-02-24 15:17:41 +0800 | [diff] [blame] | 21 | |
Yidi Lin | 7c06dd9 | 2021-04-08 09:55:11 +0800 | [diff] [blame] | 22 | #include "gpio.h" |
| 23 | |
| 24 | #include <arm-trusted-firmware/include/export/plat/mediatek/common/plat_params_exp.h> |
| 25 | |
Jitao Shi | f2c259c | 2021-06-03 13:51:29 +0800 | [diff] [blame] | 26 | /* GPIO to schematics names */ |
| 27 | #define GPIO_AP_EDP_BKLTEN GPIO(DGI_D5) |
| 28 | #define GPIO_BL_PWM_1V8 GPIO(DISP_PWM0) |
| 29 | #define GPIO_EDP_HPD_1V8 GPIO(GPIO_07) |
| 30 | #define GPIO_EN_PP3300_DISP_X GPIO(I2SO1_D2) |
| 31 | |
Yidi Lin | 7c06dd9 | 2021-04-08 09:55:11 +0800 | [diff] [blame] | 32 | static void register_reset_to_bl31(void) |
| 33 | { |
| 34 | static struct bl_aux_param_gpio param_reset = { |
| 35 | .h = { .type = BL_AUX_PARAM_MTK_RESET_GPIO }, |
| 36 | .gpio = { .polarity = ARM_TF_GPIO_LEVEL_HIGH }, |
| 37 | }; |
| 38 | |
| 39 | param_reset.gpio.index = GPIO_RESET.id; |
| 40 | register_bl31_aux_param(¶m_reset.h); |
| 41 | } |
| 42 | |
Jitao Shi | f2c259c | 2021-06-03 13:51:29 +0800 | [diff] [blame] | 43 | /* Set up backlight control pins as output pin and power-off by default */ |
| 44 | static void configure_panel_backlight(void) |
| 45 | { |
| 46 | gpio_output(GPIO_AP_EDP_BKLTEN, 0); |
| 47 | gpio_output(GPIO_BL_PWM_1V8, 0); |
| 48 | } |
| 49 | |
| 50 | static void power_on_panel(void) |
| 51 | { |
| 52 | /* Default power sequence for most panels. */ |
| 53 | gpio_set_pull(GPIO_EDP_HPD_1V8, GPIO_PULL_ENABLE, GPIO_PULL_UP); |
| 54 | gpio_set_mode(GPIO_EDP_HPD_1V8, 2); |
| 55 | gpio_output(GPIO_EN_PP3300_DISP_X, 1); |
| 56 | } |
| 57 | |
| 58 | static bool configure_display(void) |
| 59 | { |
| 60 | struct edid edid; |
| 61 | struct fb_info *info; |
| 62 | const char *name; |
| 63 | |
| 64 | printk(BIOS_INFO, "%s: Starting display initialization\n", __func__); |
| 65 | |
| 66 | mtcmos_display_power_on(); |
| 67 | mtcmos_protect_display_bus(); |
| 68 | configure_panel_backlight(); |
| 69 | power_on_panel(); |
| 70 | |
| 71 | mtk_ddp_init(); |
| 72 | mdelay(200); |
| 73 | |
| 74 | if (mtk_edp_init(&edid) < 0) { |
| 75 | printk(BIOS_ERR, "%s: Failed to initialize eDP\n", __func__); |
| 76 | return false; |
| 77 | } |
| 78 | name = edid.ascii_string; |
| 79 | if (name[0] == '\0') |
| 80 | name = "unknown name"; |
| 81 | printk(BIOS_INFO, "%s: '%s %s' %dx%d@%dHz\n", __func__, |
| 82 | edid.manufacturer_name, name, edid.mode.ha, edid.mode.va, |
| 83 | edid.mode.refresh); |
| 84 | |
| 85 | edid_set_framebuffer_bits_per_pixel(&edid, 32, 0); |
| 86 | |
| 87 | mtk_ddp_mode_set(&edid); |
| 88 | info = fb_new_framebuffer_info_from_edid(&edid, (uintptr_t)0); |
| 89 | if (info) |
| 90 | fb_set_orientation(info, LB_FB_ORIENTATION_NORMAL); |
| 91 | |
| 92 | return true; |
| 93 | } |
| 94 | |
Wenbin Mei | 24c6355 | 2021-02-24 15:17:41 +0800 | [diff] [blame] | 95 | static void mainboard_init(struct device *dev) |
| 96 | { |
Jitao Shi | f2c259c | 2021-06-03 13:51:29 +0800 | [diff] [blame] | 97 | if (display_init_required()) |
| 98 | configure_display(); |
| 99 | else |
| 100 | printk(BIOS_INFO, "%s: Skipped display initialization\n", __func__); |
| 101 | |
Rex-BC Chen | 15486f4 | 2021-11-12 18:28:18 +0800 | [diff] [blame^] | 102 | mtk_msdc_configure_emmc(true); |
| 103 | mtk_msdc_configure_sdcard(); |
Yuchen Huang | 144237f | 2021-03-01 14:39:33 +0800 | [diff] [blame] | 104 | setup_usb_host(); |
Yidi Lin | 7c06dd9 | 2021-04-08 09:55:11 +0800 | [diff] [blame] | 105 | |
Trevor Wu | 1d19432 | 2021-08-17 15:58:11 +0800 | [diff] [blame] | 106 | /* for audio usage */ |
| 107 | if (CONFIG(CHERRY_USE_RT1011)) |
Daolong Zhu | f4b7173 | 2021-09-15 13:01:55 +0800 | [diff] [blame] | 108 | mtk_i2c_bus_init(I2C2, I2C_SPEED_FAST); |
Trevor Wu | 1d19432 | 2021-08-17 15:58:11 +0800 | [diff] [blame] | 109 | |
Ryan Chuang | da63f09 | 2021-06-23 09:47:37 +0800 | [diff] [blame] | 110 | if (dpm_init()) |
| 111 | printk(BIOS_ERR, "dpm init failed, DVFS may not work\n"); |
| 112 | |
Rex-BC Chen | 9e3e0f5 | 2021-06-03 11:41:07 +0800 | [diff] [blame] | 113 | if (spm_init()) |
| 114 | printk(BIOS_ERR, "spm init failed, system suspend may not work\n"); |
| 115 | |
Yidi Lin | 7c06dd9 | 2021-04-08 09:55:11 +0800 | [diff] [blame] | 116 | register_reset_to_bl31(); |
Wenbin Mei | 24c6355 | 2021-02-24 15:17:41 +0800 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | static void mainboard_enable(struct device *dev) |
| 120 | { |
| 121 | dev->ops->init = &mainboard_init; |
| 122 | } |
| 123 | |
| 124 | struct chip_operations mainboard_ops = { |
| 125 | .name = CONFIG_MAINBOARD_PART_NUMBER, |
| 126 | .enable_dev = mainboard_enable, |
| 127 | }; |