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> |
Wenbin Mei | 24c6355 | 2021-02-24 15:17:41 +0800 | [diff] [blame] | 10 | #include <gpio.h> |
Hung-Te Lin | a01f8bc | 2022-09-06 14:32:05 +0800 | [diff] [blame] | 11 | #include <soc/bl31.h> |
Yidi Lin | c4e14c2 | 2024-01-09 11:50:27 +0800 | [diff] [blame^] | 12 | #include <soc/display.h> |
Ryan Chuang | da63f09 | 2021-06-23 09:47:37 +0800 | [diff] [blame] | 13 | #include <soc/dpm.h> |
Wenbin Mei | 24c6355 | 2021-02-24 15:17:41 +0800 | [diff] [blame] | 14 | #include <soc/i2c.h> |
Wenbin Mei | ca33b74a | 2021-08-04 10:53:27 +0800 | [diff] [blame] | 15 | #include <soc/msdc.h> |
Jitao Shi | f2c259c | 2021-06-03 13:51:29 +0800 | [diff] [blame] | 16 | #include <soc/mtcmos.h> |
Yu-Ping Wu | 7b7250d | 2022-07-19 17:43:29 +0800 | [diff] [blame] | 17 | #include <soc/pcie.h> |
Rex-BC Chen | 9e3e0f5 | 2021-06-03 11:41:07 +0800 | [diff] [blame] | 18 | #include <soc/spm.h> |
Yuchen Huang | 144237f | 2021-03-01 14:39:33 +0800 | [diff] [blame] | 19 | #include <soc/usb.h> |
Yu-Ping Wu | 514277f | 2022-08-09 15:54:05 +0800 | [diff] [blame] | 20 | #include <types.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 | |
Jitao Shi | f2c259c | 2021-06-03 13:51:29 +0800 | [diff] [blame] | 24 | /* GPIO to schematics names */ |
| 25 | #define GPIO_AP_EDP_BKLTEN GPIO(DGI_D5) |
| 26 | #define GPIO_BL_PWM_1V8 GPIO(DISP_PWM0) |
| 27 | #define GPIO_EDP_HPD_1V8 GPIO(GPIO_07) |
| 28 | #define GPIO_EN_PP3300_DISP_X GPIO(I2SO1_D2) |
| 29 | |
Yu-Ping Wu | 7b7250d | 2022-07-19 17:43:29 +0800 | [diff] [blame] | 30 | bool mainboard_needs_pcie_init(void) |
| 31 | { |
Yu-Ping Wu | 514277f | 2022-08-09 15:54:05 +0800 | [diff] [blame] | 32 | uint32_t sku = sku_id(); |
Yu-Ping Wu | 7b7250d | 2022-07-19 17:43:29 +0800 | [diff] [blame] | 33 | |
Yu-Ping Wu | 514277f | 2022-08-09 15:54:05 +0800 | [diff] [blame] | 34 | if (sku == CROS_SKU_UNKNOWN) { |
| 35 | printk(BIOS_WARNING, "Unknown SKU (%#x); assuming PCIe", sku); |
Yu-Ping Wu | 7b7250d | 2022-07-19 17:43:29 +0800 | [diff] [blame] | 36 | return true; |
Yu-Ping Wu | 514277f | 2022-08-09 15:54:05 +0800 | [diff] [blame] | 37 | } else if (sku == CROS_SKU_UNPROVISIONED) { |
| 38 | printk(BIOS_WARNING, "Unprovisioned SKU (%#x); assuming PCIe", sku); |
Yu-Ping Wu | 7b7250d | 2022-07-19 17:43:29 +0800 | [diff] [blame] | 39 | return true; |
| 40 | } |
Yu-Ping Wu | 514277f | 2022-08-09 15:54:05 +0800 | [diff] [blame] | 41 | |
| 42 | /* |
| 43 | * All cherry boards share the same SKU encoding. Therefore there is no need to check |
| 44 | * the board here. |
| 45 | * - BIT(1): NVMe (PCIe) |
| 46 | * - BIT(3): UFS (which takes precedence over BIT(1)) |
| 47 | */ |
| 48 | if (sku & BIT(3)) |
| 49 | return false; |
| 50 | if (sku & BIT(1)) |
| 51 | return true; |
| 52 | |
| 53 | /* Otherwise, eMMC */ |
| 54 | return false; |
Yu-Ping Wu | 7b7250d | 2022-07-19 17:43:29 +0800 | [diff] [blame] | 55 | } |
| 56 | |
Jitao Shi | f2c259c | 2021-06-03 13:51:29 +0800 | [diff] [blame] | 57 | /* Set up backlight control pins as output pin and power-off by default */ |
Yidi Lin | c4e14c2 | 2024-01-09 11:50:27 +0800 | [diff] [blame^] | 58 | static void configure_backlight(void) |
Jitao Shi | f2c259c | 2021-06-03 13:51:29 +0800 | [diff] [blame] | 59 | { |
| 60 | gpio_output(GPIO_AP_EDP_BKLTEN, 0); |
| 61 | gpio_output(GPIO_BL_PWM_1V8, 0); |
| 62 | } |
| 63 | |
| 64 | static void power_on_panel(void) |
| 65 | { |
| 66 | /* Default power sequence for most panels. */ |
| 67 | gpio_set_pull(GPIO_EDP_HPD_1V8, GPIO_PULL_ENABLE, GPIO_PULL_UP); |
| 68 | gpio_set_mode(GPIO_EDP_HPD_1V8, 2); |
| 69 | gpio_output(GPIO_EN_PP3300_DISP_X, 1); |
| 70 | } |
| 71 | |
Yidi Lin | c4e14c2 | 2024-01-09 11:50:27 +0800 | [diff] [blame^] | 72 | static struct panel_description panel = { |
| 73 | .configure_backlight = configure_backlight, |
| 74 | .power_on = power_on_panel, |
| 75 | .disp_path = DISP_PATH_EDP, |
| 76 | .orientation = LB_FB_ORIENTATION_NORMAL, |
| 77 | }; |
| 78 | |
| 79 | struct panel_description *get_active_panel(void) |
Jitao Shi | f2c259c | 2021-06-03 13:51:29 +0800 | [diff] [blame] | 80 | { |
Yidi Lin | c4e14c2 | 2024-01-09 11:50:27 +0800 | [diff] [blame^] | 81 | return &panel; |
Jitao Shi | f2c259c | 2021-06-03 13:51:29 +0800 | [diff] [blame] | 82 | } |
| 83 | |
Trevor Wu | 812df72 | 2022-03-22 13:09:13 +0800 | [diff] [blame] | 84 | static void configure_i2s(void) |
| 85 | { |
| 86 | /* Audio PWR */ |
| 87 | mtcmos_audio_power_on(); |
| 88 | mtcmos_protect_audio_bus(); |
| 89 | |
| 90 | /* SoC I2S */ |
| 91 | gpio_set_mode(GPIO(GPIO_02), PAD_GPIO_02_FUNC_TDMIN_LRCK); |
| 92 | gpio_set_mode(GPIO(GPIO_03), PAD_GPIO_03_FUNC_TDMIN_BCK); |
| 93 | gpio_set_mode(GPIO(I2SO2_D0), PAD_I2SO2_D0_FUNC_I2SO2_D0); |
| 94 | } |
| 95 | |
| 96 | static void configure_audio(void) |
| 97 | { |
| 98 | if (CONFIG(CHERRY_USE_RT1011) || CONFIG(CHERRY_USE_MAX98390)) |
| 99 | mtk_i2c_bus_init(I2C2, I2C_SPEED_FAST); |
| 100 | |
| 101 | if (CONFIG(CHERRY_USE_MAX98390)) |
| 102 | configure_i2s(); |
| 103 | } |
| 104 | |
Wenbin Mei | 24c6355 | 2021-02-24 15:17:41 +0800 | [diff] [blame] | 105 | static void mainboard_init(struct device *dev) |
| 106 | { |
Jitao Shi | f2c259c | 2021-06-03 13:51:29 +0800 | [diff] [blame] | 107 | if (display_init_required()) |
Yidi Lin | c4e14c2 | 2024-01-09 11:50:27 +0800 | [diff] [blame^] | 108 | mtk_display_init(); |
Jitao Shi | f2c259c | 2021-06-03 13:51:29 +0800 | [diff] [blame] | 109 | else |
| 110 | printk(BIOS_INFO, "%s: Skipped display initialization\n", __func__); |
| 111 | |
Rex-BC Chen | 15486f4 | 2021-11-12 18:28:18 +0800 | [diff] [blame] | 112 | mtk_msdc_configure_emmc(true); |
| 113 | mtk_msdc_configure_sdcard(); |
Yuchen Huang | 144237f | 2021-03-01 14:39:33 +0800 | [diff] [blame] | 114 | setup_usb_host(); |
Yidi Lin | 7c06dd9 | 2021-04-08 09:55:11 +0800 | [diff] [blame] | 115 | |
Trevor Wu | 812df72 | 2022-03-22 13:09:13 +0800 | [diff] [blame] | 116 | configure_audio(); |
Trevor Wu | 1d19432 | 2021-08-17 15:58:11 +0800 | [diff] [blame] | 117 | |
Ryan Chuang | da63f09 | 2021-06-23 09:47:37 +0800 | [diff] [blame] | 118 | if (dpm_init()) |
| 119 | printk(BIOS_ERR, "dpm init failed, DVFS may not work\n"); |
| 120 | |
Rex-BC Chen | 9e3e0f5 | 2021-06-03 11:41:07 +0800 | [diff] [blame] | 121 | if (spm_init()) |
| 122 | printk(BIOS_ERR, "spm init failed, system suspend may not work\n"); |
| 123 | |
Hung-Te Lin | a01f8bc | 2022-09-06 14:32:05 +0800 | [diff] [blame] | 124 | if (CONFIG(ARM64_USE_ARM_TRUSTED_FIRMWARE)) |
| 125 | register_reset_to_bl31(GPIO_RESET.id, true); |
Wenbin Mei | 24c6355 | 2021-02-24 15:17:41 +0800 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | static void mainboard_enable(struct device *dev) |
| 129 | { |
| 130 | dev->ops->init = &mainboard_init; |
| 131 | } |
| 132 | |
| 133 | struct chip_operations mainboard_ops = { |
Wenbin Mei | 24c6355 | 2021-02-24 15:17:41 +0800 | [diff] [blame] | 134 | .enable_dev = mainboard_enable, |
| 135 | }; |