Wenbin Mei | 24c6355 | 2021-02-24 15:17:41 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
Yu-Ping Wu | 7b7250d | 2022-07-19 17:43:29 +0800 | [diff] [blame] | 3 | #include <boardid.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> |
Yu-Ping Wu | 514277f | 2022-08-09 15:54:05 +0800 | [diff] [blame] | 9 | #include <ec/google/chromeec/ec.h> |
Jitao Shi | f2c259c | 2021-06-03 13:51:29 +0800 | [diff] [blame] | 10 | #include <edid.h> |
| 11 | #include <framebuffer_info.h> |
Wenbin Mei | 24c6355 | 2021-02-24 15:17:41 +0800 | [diff] [blame] | 12 | #include <gpio.h> |
Hung-Te Lin | a01f8bc | 2022-09-06 14:32:05 +0800 | [diff] [blame] | 13 | #include <soc/bl31.h> |
Jitao Shi | f2c259c | 2021-06-03 13:51:29 +0800 | [diff] [blame] | 14 | #include <soc/ddp.h> |
Ryan Chuang | da63f09 | 2021-06-23 09:47:37 +0800 | [diff] [blame] | 15 | #include <soc/dpm.h> |
Jitao Shi | f2c259c | 2021-06-03 13:51:29 +0800 | [diff] [blame] | 16 | #include <soc/dptx.h> |
Wenbin Mei | 24c6355 | 2021-02-24 15:17:41 +0800 | [diff] [blame] | 17 | #include <soc/i2c.h> |
Wenbin Mei | ca33b74a | 2021-08-04 10:53:27 +0800 | [diff] [blame] | 18 | #include <soc/msdc.h> |
Jitao Shi | f2c259c | 2021-06-03 13:51:29 +0800 | [diff] [blame] | 19 | #include <soc/mtcmos.h> |
Yu-Ping Wu | 7b7250d | 2022-07-19 17:43:29 +0800 | [diff] [blame] | 20 | #include <soc/pcie.h> |
Rex-BC Chen | 9e3e0f5 | 2021-06-03 11:41:07 +0800 | [diff] [blame] | 21 | #include <soc/spm.h> |
Yuchen Huang | 144237f | 2021-03-01 14:39:33 +0800 | [diff] [blame] | 22 | #include <soc/usb.h> |
Yu-Ping Wu | 514277f | 2022-08-09 15:54:05 +0800 | [diff] [blame] | 23 | #include <types.h> |
Wenbin Mei | 24c6355 | 2021-02-24 15:17:41 +0800 | [diff] [blame] | 24 | |
Yidi Lin | 7c06dd9 | 2021-04-08 09:55:11 +0800 | [diff] [blame] | 25 | #include "gpio.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 | |
Yu-Ping Wu | 7b7250d | 2022-07-19 17:43:29 +0800 | [diff] [blame] | 33 | bool mainboard_needs_pcie_init(void) |
| 34 | { |
Yu-Ping Wu | 514277f | 2022-08-09 15:54:05 +0800 | [diff] [blame] | 35 | uint32_t sku = sku_id(); |
Yu-Ping Wu | 7b7250d | 2022-07-19 17:43:29 +0800 | [diff] [blame] | 36 | |
Yu-Ping Wu | 514277f | 2022-08-09 15:54:05 +0800 | [diff] [blame] | 37 | if (sku == CROS_SKU_UNKNOWN) { |
| 38 | printk(BIOS_WARNING, "Unknown SKU (%#x); assuming PCIe", sku); |
Yu-Ping Wu | 7b7250d | 2022-07-19 17:43:29 +0800 | [diff] [blame] | 39 | return true; |
Yu-Ping Wu | 514277f | 2022-08-09 15:54:05 +0800 | [diff] [blame] | 40 | } else if (sku == CROS_SKU_UNPROVISIONED) { |
| 41 | printk(BIOS_WARNING, "Unprovisioned SKU (%#x); assuming PCIe", sku); |
Yu-Ping Wu | 7b7250d | 2022-07-19 17:43:29 +0800 | [diff] [blame] | 42 | return true; |
| 43 | } |
Yu-Ping Wu | 514277f | 2022-08-09 15:54:05 +0800 | [diff] [blame] | 44 | |
| 45 | /* |
| 46 | * All cherry boards share the same SKU encoding. Therefore there is no need to check |
| 47 | * the board here. |
| 48 | * - BIT(1): NVMe (PCIe) |
| 49 | * - BIT(3): UFS (which takes precedence over BIT(1)) |
| 50 | */ |
| 51 | if (sku & BIT(3)) |
| 52 | return false; |
| 53 | if (sku & BIT(1)) |
| 54 | return true; |
| 55 | |
| 56 | /* Otherwise, eMMC */ |
| 57 | return false; |
Yu-Ping Wu | 7b7250d | 2022-07-19 17:43:29 +0800 | [diff] [blame] | 58 | } |
| 59 | |
Jitao Shi | f2c259c | 2021-06-03 13:51:29 +0800 | [diff] [blame] | 60 | /* Set up backlight control pins as output pin and power-off by default */ |
| 61 | static void configure_panel_backlight(void) |
| 62 | { |
| 63 | gpio_output(GPIO_AP_EDP_BKLTEN, 0); |
| 64 | gpio_output(GPIO_BL_PWM_1V8, 0); |
| 65 | } |
| 66 | |
| 67 | static void power_on_panel(void) |
| 68 | { |
| 69 | /* Default power sequence for most panels. */ |
| 70 | gpio_set_pull(GPIO_EDP_HPD_1V8, GPIO_PULL_ENABLE, GPIO_PULL_UP); |
| 71 | gpio_set_mode(GPIO_EDP_HPD_1V8, 2); |
| 72 | gpio_output(GPIO_EN_PP3300_DISP_X, 1); |
| 73 | } |
| 74 | |
| 75 | static bool configure_display(void) |
| 76 | { |
| 77 | struct edid edid; |
| 78 | struct fb_info *info; |
| 79 | const char *name; |
| 80 | |
| 81 | printk(BIOS_INFO, "%s: Starting display initialization\n", __func__); |
| 82 | |
| 83 | mtcmos_display_power_on(); |
| 84 | mtcmos_protect_display_bus(); |
| 85 | configure_panel_backlight(); |
| 86 | power_on_panel(); |
| 87 | |
| 88 | mtk_ddp_init(); |
| 89 | mdelay(200); |
| 90 | |
| 91 | if (mtk_edp_init(&edid) < 0) { |
| 92 | printk(BIOS_ERR, "%s: Failed to initialize eDP\n", __func__); |
| 93 | return false; |
| 94 | } |
| 95 | name = edid.ascii_string; |
| 96 | if (name[0] == '\0') |
| 97 | name = "unknown name"; |
| 98 | printk(BIOS_INFO, "%s: '%s %s' %dx%d@%dHz\n", __func__, |
| 99 | edid.manufacturer_name, name, edid.mode.ha, edid.mode.va, |
| 100 | edid.mode.refresh); |
| 101 | |
| 102 | edid_set_framebuffer_bits_per_pixel(&edid, 32, 0); |
| 103 | |
| 104 | mtk_ddp_mode_set(&edid); |
| 105 | info = fb_new_framebuffer_info_from_edid(&edid, (uintptr_t)0); |
| 106 | if (info) |
| 107 | fb_set_orientation(info, LB_FB_ORIENTATION_NORMAL); |
| 108 | |
| 109 | return true; |
| 110 | } |
| 111 | |
Trevor Wu | 812df72 | 2022-03-22 13:09:13 +0800 | [diff] [blame] | 112 | static void configure_i2s(void) |
| 113 | { |
| 114 | /* Audio PWR */ |
| 115 | mtcmos_audio_power_on(); |
| 116 | mtcmos_protect_audio_bus(); |
| 117 | |
| 118 | /* SoC I2S */ |
| 119 | gpio_set_mode(GPIO(GPIO_02), PAD_GPIO_02_FUNC_TDMIN_LRCK); |
| 120 | gpio_set_mode(GPIO(GPIO_03), PAD_GPIO_03_FUNC_TDMIN_BCK); |
| 121 | gpio_set_mode(GPIO(I2SO2_D0), PAD_I2SO2_D0_FUNC_I2SO2_D0); |
| 122 | } |
| 123 | |
| 124 | static void configure_audio(void) |
| 125 | { |
| 126 | if (CONFIG(CHERRY_USE_RT1011) || CONFIG(CHERRY_USE_MAX98390)) |
| 127 | mtk_i2c_bus_init(I2C2, I2C_SPEED_FAST); |
| 128 | |
| 129 | if (CONFIG(CHERRY_USE_MAX98390)) |
| 130 | configure_i2s(); |
| 131 | } |
| 132 | |
Wenbin Mei | 24c6355 | 2021-02-24 15:17:41 +0800 | [diff] [blame] | 133 | static void mainboard_init(struct device *dev) |
| 134 | { |
Jitao Shi | f2c259c | 2021-06-03 13:51:29 +0800 | [diff] [blame] | 135 | if (display_init_required()) |
| 136 | configure_display(); |
| 137 | else |
| 138 | printk(BIOS_INFO, "%s: Skipped display initialization\n", __func__); |
| 139 | |
Rex-BC Chen | 15486f4 | 2021-11-12 18:28:18 +0800 | [diff] [blame] | 140 | mtk_msdc_configure_emmc(true); |
| 141 | mtk_msdc_configure_sdcard(); |
Yuchen Huang | 144237f | 2021-03-01 14:39:33 +0800 | [diff] [blame] | 142 | setup_usb_host(); |
Yidi Lin | 7c06dd9 | 2021-04-08 09:55:11 +0800 | [diff] [blame] | 143 | |
Trevor Wu | 812df72 | 2022-03-22 13:09:13 +0800 | [diff] [blame] | 144 | configure_audio(); |
Trevor Wu | 1d19432 | 2021-08-17 15:58:11 +0800 | [diff] [blame] | 145 | |
Ryan Chuang | da63f09 | 2021-06-23 09:47:37 +0800 | [diff] [blame] | 146 | if (dpm_init()) |
| 147 | printk(BIOS_ERR, "dpm init failed, DVFS may not work\n"); |
| 148 | |
Rex-BC Chen | 9e3e0f5 | 2021-06-03 11:41:07 +0800 | [diff] [blame] | 149 | if (spm_init()) |
| 150 | printk(BIOS_ERR, "spm init failed, system suspend may not work\n"); |
| 151 | |
Hung-Te Lin | a01f8bc | 2022-09-06 14:32:05 +0800 | [diff] [blame] | 152 | if (CONFIG(ARM64_USE_ARM_TRUSTED_FIRMWARE)) |
| 153 | register_reset_to_bl31(GPIO_RESET.id, true); |
Wenbin Mei | 24c6355 | 2021-02-24 15:17:41 +0800 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | static void mainboard_enable(struct device *dev) |
| 157 | { |
| 158 | dev->ops->init = &mainboard_init; |
| 159 | } |
| 160 | |
| 161 | struct chip_operations mainboard_ops = { |
Wenbin Mei | 24c6355 | 2021-02-24 15:17:41 +0800 | [diff] [blame] | 162 | .enable_dev = mainboard_enable, |
| 163 | }; |