Angel Pons | 11ba353 | 2020-04-05 13:21:58 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Tristan Shieh | bb684e0 | 2018-06-19 16:07:54 +0800 | [diff] [blame] | 2 | |
Hung-Te Lin | 9ede2ff | 2019-08-15 09:43:55 +0800 | [diff] [blame] | 3 | #include <assert.h> |
Tristan Shieh | 4d990ab | 2019-02-25 17:14:14 +0800 | [diff] [blame] | 4 | #include <bl31.h> |
Hung-Te Lin | 2c307a0 | 2019-02-20 14:31:23 +0800 | [diff] [blame] | 5 | #include <boardid.h> |
| 6 | #include <bootmode.h> |
Hung-Te Lin | 9ede2ff | 2019-08-15 09:43:55 +0800 | [diff] [blame] | 7 | #include <cbfs.h> |
Hung-Te Lin | 2c307a0 | 2019-02-20 14:31:23 +0800 | [diff] [blame] | 8 | #include <console/console.h> |
| 9 | #include <delay.h> |
Tristan Shieh | bb684e0 | 2018-06-19 16:07:54 +0800 | [diff] [blame] | 10 | #include <device/device.h> |
Hung-Te Lin | 7fc2281 | 2020-07-24 08:49:41 +0800 | [diff] [blame] | 11 | #include <ec/google/chromeec/ec.h> |
Hung-Te Lin | 2c307a0 | 2019-02-20 14:31:23 +0800 | [diff] [blame] | 12 | #include <edid.h> |
Patrick Rudolph | 7319288 | 2020-02-19 12:10:51 +0100 | [diff] [blame] | 13 | #include <framebuffer_info.h> |
Hung-Te Lin | 2c307a0 | 2019-02-20 14:31:23 +0800 | [diff] [blame] | 14 | #include <gpio.h> |
| 15 | #include <soc/ddp.h> |
| 16 | #include <soc/dsi.h> |
Tristan Shieh | 8db79c1 | 2018-09-07 17:26:21 +0800 | [diff] [blame] | 17 | #include <soc/gpio.h> |
Tristan Shieh | bb684e0 | 2018-06-19 16:07:54 +0800 | [diff] [blame] | 18 | #include <soc/mmu_operations.h> |
Jiaxin Yu | 30bc9f4 | 2019-04-23 20:45:50 +0800 | [diff] [blame] | 19 | #include <soc/mtcmos.h> |
Dawei Chien | 2422f8c | 2019-05-30 11:55:10 +0800 | [diff] [blame] | 20 | #include <soc/spm.h> |
Tristan Shieh | 71ae582 | 2018-09-26 14:33:54 +0800 | [diff] [blame] | 21 | #include <soc/usb.h> |
Hung-Te Lin | 9ede2ff | 2019-08-15 09:43:55 +0800 | [diff] [blame] | 22 | #include <string.h> |
Tristan Shieh | bb684e0 | 2018-06-19 16:07:54 +0800 | [diff] [blame] | 23 | |
Tristan Shieh | 4d990ab | 2019-02-25 17:14:14 +0800 | [diff] [blame] | 24 | #include "gpio.h" |
Hung-Te Lin | 2c307a0 | 2019-02-20 14:31:23 +0800 | [diff] [blame] | 25 | #include "panel.h" |
| 26 | |
Tristan Shieh | 4d990ab | 2019-02-25 17:14:14 +0800 | [diff] [blame] | 27 | #include <arm-trusted-firmware/include/export/plat/mediatek/common/plat_params_exp.h> |
| 28 | |
Tristan Shieh | 8db79c1 | 2018-09-07 17:26:21 +0800 | [diff] [blame] | 29 | static void configure_emmc(void) |
| 30 | { |
| 31 | const gpio_t emmc_pin[] = { |
| 32 | GPIO(MSDC0_DAT0), GPIO(MSDC0_DAT1), |
| 33 | GPIO(MSDC0_DAT2), GPIO(MSDC0_DAT3), |
| 34 | GPIO(MSDC0_DAT4), GPIO(MSDC0_DAT5), |
| 35 | GPIO(MSDC0_DAT6), GPIO(MSDC0_DAT7), |
| 36 | GPIO(MSDC0_CMD), GPIO(MSDC0_RSTB), |
| 37 | }; |
| 38 | |
| 39 | for (size_t i = 0; i < ARRAY_SIZE(emmc_pin); i++) |
| 40 | gpio_set_pull(emmc_pin[i], GPIO_PULL_ENABLE, GPIO_PULL_UP); |
| 41 | } |
| 42 | |
Tristan Shieh | 71ae582 | 2018-09-26 14:33:54 +0800 | [diff] [blame] | 43 | static void configure_usb(void) |
| 44 | { |
| 45 | setup_usb_host(); |
| 46 | } |
| 47 | |
Jiaxin Yu | 30bc9f4 | 2019-04-23 20:45:50 +0800 | [diff] [blame] | 48 | static void configure_audio(void) |
| 49 | { |
| 50 | /* Audio PWR*/ |
| 51 | mtcmos_audio_power_on(); |
| 52 | |
| 53 | /* SoC I2S */ |
| 54 | gpio_set_mode(GPIO(CAM_RST0), PAD_CAM_RST0_FUNC_I2S2_LRCK); |
| 55 | gpio_set_mode(GPIO(CAM_PDN1), PAD_CAM_PDN1_FUNC_I2S2_BCK); |
| 56 | gpio_set_mode(GPIO(CAM_PDN0), PAD_CAM_PDN0_FUNC_I2S2_MCK); |
| 57 | gpio_set_mode(GPIO(EINT3), PAD_EINT3_FUNC_I2S3_DO); |
| 58 | } |
Hung-Te Lin | 2c307a0 | 2019-02-20 14:31:23 +0800 | [diff] [blame] | 59 | |
Hung-Te Lin | 7fc2281 | 2020-07-24 08:49:41 +0800 | [diff] [blame] | 60 | static void configure_ec(void) |
| 61 | { |
| 62 | /* EC may need SKU ID to identify if it is clamshell or convertible. */ |
| 63 | if (CONFIG(BOARD_GOOGLE_JACUZZI_COMMON)) |
| 64 | google_chromeec_set_sku_id(sku_id()); |
| 65 | } |
| 66 | |
Hung-Te Lin | 2c307a0 | 2019-02-20 14:31:23 +0800 | [diff] [blame] | 67 | /* Default implementation for boards without panels defined yet. */ |
| 68 | struct panel_description __weak *get_panel_description(int panel_id) |
| 69 | { |
| 70 | printk(BIOS_ERR, "%s: ERROR: No panels defined for board: %s.\n", |
| 71 | __func__, CONFIG_MAINBOARD_PART_NUMBER); |
| 72 | return NULL; |
| 73 | } |
| 74 | |
| 75 | /* Set up backlight control pins as output pin and power-off by default */ |
| 76 | static void configure_panel_backlight(void) |
| 77 | { |
| 78 | gpio_output(GPIO(PERIPHERAL_EN13), 0); |
| 79 | gpio_output(GPIO(DISP_PWM), 0); |
| 80 | } |
| 81 | |
| 82 | static void power_on_panel(struct panel_description *panel) |
| 83 | { |
| 84 | if (panel->power_on) { |
| 85 | panel->power_on(); |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | /* Default power sequence for most panels. */ |
| 90 | gpio_output(GPIO_LCM_RST_1V8, 0); |
| 91 | gpio_output(GPIO_PPVARP_LCD_EN, 1); |
| 92 | gpio_output(GPIO_PPVARN_LCD_EN, 1); |
| 93 | gpio_output(GPIO_PP1800_LCM_EN, 1); |
| 94 | gpio_output(GPIO_PP3300_LCM_EN, 1); |
Tao Xia | f3c0a01 | 2020-11-11 15:32:46 +0800 | [diff] [blame] | 95 | mdelay(15); |
Hung-Te Lin | 2c307a0 | 2019-02-20 14:31:23 +0800 | [diff] [blame] | 96 | gpio_output(GPIO_LCM_RST_1V8, 1); |
| 97 | mdelay(6); |
| 98 | } |
| 99 | |
Hung-Te Lin | 9ede2ff | 2019-08-15 09:43:55 +0800 | [diff] [blame] | 100 | struct panel_description *get_panel_from_cbfs(struct panel_description *desc) |
| 101 | { |
| 102 | /* The CBFS name will be panel-{MANUFACTURER}-${PANEL_NAME}, |
| 103 | * where MANUFACTURER is 3 characters and PANEL_NAME is usually |
| 104 | * 13 characters. |
| 105 | */ |
| 106 | char cbfs_name[64]; |
| 107 | static union { |
| 108 | u8 raw[4 * 1024]; /* Most panels only need < 2K. */ |
| 109 | struct panel_serializable_data s; |
| 110 | } buffer; |
| 111 | |
| 112 | if (!desc->name) |
| 113 | return NULL; |
| 114 | |
| 115 | snprintf(cbfs_name, sizeof(cbfs_name), "panel-%s", desc->name); |
Julius Werner | 834b3ec | 2020-03-04 16:52:08 -0800 | [diff] [blame] | 116 | if (cbfs_load(cbfs_name, buffer.raw, sizeof(buffer))) |
Hung-Te Lin | 9ede2ff | 2019-08-15 09:43:55 +0800 | [diff] [blame] | 117 | desc->s = &buffer.s; |
| 118 | else |
| 119 | printk(BIOS_ERR, "Missing %s in CBFS.\n", cbfs_name); |
| 120 | |
| 121 | return desc->s ? desc : NULL; |
| 122 | } |
| 123 | |
Hung-Te Lin | 2c307a0 | 2019-02-20 14:31:23 +0800 | [diff] [blame] | 124 | static struct panel_description *get_active_panel(void) |
| 125 | { |
| 126 | /* TODO(hungte) Create a dedicated panel_id() in board_id.c */ |
| 127 | int panel_id = sku_id() >> 4; |
| 128 | |
| 129 | struct panel_description *panel = get_panel_description(panel_id); |
| 130 | if (!panel) { |
| 131 | printk(BIOS_ERR, "%s: Panel %d is not supported.\n", |
| 132 | __func__, panel_id); |
| 133 | return NULL; |
| 134 | } |
Hung-Te Lin | 9ede2ff | 2019-08-15 09:43:55 +0800 | [diff] [blame] | 135 | assert(panel->s); |
| 136 | |
| 137 | const struct edid *edid = &panel->s->edid; |
| 138 | const char *name = edid->ascii_string; |
Hung-Te Lin | 2c307a0 | 2019-02-20 14:31:23 +0800 | [diff] [blame] | 139 | if (name[0] == '\0') |
| 140 | name = "unknown name"; |
Hung-Te Lin | 9ede2ff | 2019-08-15 09:43:55 +0800 | [diff] [blame] | 141 | printk(BIOS_INFO, "%s: Found ID %d: '%s %s' %dx%d@%dHz\n", __func__, |
| 142 | panel_id, edid->manufacturer_name, name, edid->mode.ha, |
| 143 | edid->mode.va, edid->mode.refresh); |
Hung-Te Lin | 2c307a0 | 2019-02-20 14:31:23 +0800 | [diff] [blame] | 144 | return panel; |
| 145 | } |
| 146 | |
| 147 | static bool configure_display(void) |
| 148 | { |
| 149 | struct panel_description *panel = get_active_panel(); |
| 150 | if (!panel) |
| 151 | return false; |
| 152 | |
| 153 | mtcmos_display_power_on(); |
| 154 | mtcmos_protect_display_bus(); |
| 155 | configure_panel_backlight(); |
| 156 | power_on_panel(panel); |
| 157 | |
Hung-Te Lin | 9ede2ff | 2019-08-15 09:43:55 +0800 | [diff] [blame] | 158 | struct edid *edid = &panel->s->edid; |
Hung-Te Lin | 2c307a0 | 2019-02-20 14:31:23 +0800 | [diff] [blame] | 159 | edid_set_framebuffer_bits_per_pixel(edid, 32, 0); |
| 160 | mtk_ddp_init(); |
| 161 | u32 mipi_dsi_flags = (MIPI_DSI_MODE_VIDEO | |
| 162 | MIPI_DSI_MODE_VIDEO_SYNC_PULSE | |
| 163 | MIPI_DSI_MODE_LPM); |
Paul Ma | 6d500a2 | 2020-05-08 13:16:04 +0800 | [diff] [blame] | 164 | if (CONFIG(DRIVER_ANALOGIX_ANX7625)) |
| 165 | mipi_dsi_flags |= MIPI_DSI_MODE_EOT_PACKET; |
Hung-Te Lin | 2c307a0 | 2019-02-20 14:31:23 +0800 | [diff] [blame] | 166 | if (mtk_dsi_init(mipi_dsi_flags, MIPI_DSI_FMT_RGB888, 4, edid, |
Hung-Te Lin | 9ede2ff | 2019-08-15 09:43:55 +0800 | [diff] [blame] | 167 | panel->s->init) < 0) { |
Hung-Te Lin | 2c307a0 | 2019-02-20 14:31:23 +0800 | [diff] [blame] | 168 | printk(BIOS_ERR, "%s: Failed in DSI init.\n", __func__); |
| 169 | return false; |
| 170 | } |
| 171 | mtk_ddp_mode_set(edid); |
Patrick Rudolph | 8b56c8c | 2020-02-19 12:57:00 +0100 | [diff] [blame^] | 172 | struct fb_info *info = fb_new_framebuffer_info_from_edid(edid, 0); |
Patrick Rudolph | 7319288 | 2020-02-19 12:10:51 +0100 | [diff] [blame] | 173 | if (info) |
| 174 | fb_set_orientation(info, panel->s->orientation); |
| 175 | |
Hung-Te Lin | 2c307a0 | 2019-02-20 14:31:23 +0800 | [diff] [blame] | 176 | return true; |
| 177 | } |
| 178 | |
Tristan Shieh | 4d990ab | 2019-02-25 17:14:14 +0800 | [diff] [blame] | 179 | static void register_reset_to_bl31(void) |
| 180 | { |
| 181 | static struct bl_aux_param_gpio param_reset = { |
| 182 | .h = { .type = BL_AUX_PARAM_MTK_RESET_GPIO }, |
| 183 | .gpio = { .polarity = ARM_TF_GPIO_LEVEL_HIGH }, |
| 184 | }; |
| 185 | |
| 186 | param_reset.gpio.index = GPIO_RESET.id; |
| 187 | register_bl31_aux_param(¶m_reset.h); |
| 188 | } |
| 189 | |
Tristan Shieh | bb684e0 | 2018-06-19 16:07:54 +0800 | [diff] [blame] | 190 | static void mainboard_init(struct device *dev) |
| 191 | { |
Hung-Te Lin | 2c307a0 | 2019-02-20 14:31:23 +0800 | [diff] [blame] | 192 | if (display_init_required()) { |
| 193 | printk(BIOS_INFO, "%s: Starting display init.\n", __func__); |
| 194 | if (!configure_display()) |
| 195 | printk(BIOS_ERR, "%s: Failed to init display.\n", |
| 196 | __func__); |
| 197 | } else { |
| 198 | printk(BIOS_INFO, "%s: Skipped display init.\n", __func__); |
| 199 | } |
| 200 | |
Tristan Shieh | 8db79c1 | 2018-09-07 17:26:21 +0800 | [diff] [blame] | 201 | configure_emmc(); |
Tristan Shieh | 71ae582 | 2018-09-26 14:33:54 +0800 | [diff] [blame] | 202 | configure_usb(); |
Jiaxin Yu | 30bc9f4 | 2019-04-23 20:45:50 +0800 | [diff] [blame] | 203 | configure_audio(); |
Hung-Te Lin | 7fc2281 | 2020-07-24 08:49:41 +0800 | [diff] [blame] | 204 | configure_ec(); |
Dawei Chien | 2422f8c | 2019-05-30 11:55:10 +0800 | [diff] [blame] | 205 | if (spm_init()) |
| 206 | printk(BIOS_ERR, |
| 207 | "SPM initialization failed, suspend/resume may fail.\n"); |
Tristan Shieh | 4d990ab | 2019-02-25 17:14:14 +0800 | [diff] [blame] | 208 | |
| 209 | register_reset_to_bl31(); |
Tristan Shieh | bb684e0 | 2018-06-19 16:07:54 +0800 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | static void mainboard_enable(struct device *dev) |
| 213 | { |
| 214 | dev->ops->init = &mainboard_init; |
| 215 | } |
| 216 | |
| 217 | struct chip_operations mainboard_ops = { |
| 218 | .name = CONFIG_MAINBOARD_PART_NUMBER, |
| 219 | .enable_dev = mainboard_enable, |
| 220 | }; |