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