Tristan Shieh | bb684e0 | 2018-06-19 16:07:54 +0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2018 MediaTek Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | |
Hung-Te Lin | 9ede2ff | 2019-08-15 09:43:55 +0800 | [diff] [blame] | 16 | #include <assert.h> |
Tristan Shieh | 4d990ab | 2019-02-25 17:14:14 +0800 | [diff] [blame^] | 17 | #include <bl31.h> |
Hung-Te Lin | 2c307a0 | 2019-02-20 14:31:23 +0800 | [diff] [blame] | 18 | #include <boardid.h> |
| 19 | #include <bootmode.h> |
Hung-Te Lin | 9ede2ff | 2019-08-15 09:43:55 +0800 | [diff] [blame] | 20 | #include <cbfs.h> |
Hung-Te Lin | 2c307a0 | 2019-02-20 14:31:23 +0800 | [diff] [blame] | 21 | #include <console/console.h> |
| 22 | #include <delay.h> |
Tristan Shieh | bb684e0 | 2018-06-19 16:07:54 +0800 | [diff] [blame] | 23 | #include <device/device.h> |
Hung-Te Lin | 2c307a0 | 2019-02-20 14:31:23 +0800 | [diff] [blame] | 24 | #include <edid.h> |
| 25 | #include <gpio.h> |
| 26 | #include <soc/ddp.h> |
| 27 | #include <soc/dsi.h> |
Tristan Shieh | 8db79c1 | 2018-09-07 17:26:21 +0800 | [diff] [blame] | 28 | #include <soc/gpio.h> |
Tristan Shieh | bb684e0 | 2018-06-19 16:07:54 +0800 | [diff] [blame] | 29 | #include <soc/mmu_operations.h> |
Jiaxin Yu | 30bc9f4 | 2019-04-23 20:45:50 +0800 | [diff] [blame] | 30 | #include <soc/mtcmos.h> |
Tristan Shieh | 71ae582 | 2018-09-26 14:33:54 +0800 | [diff] [blame] | 31 | #include <soc/usb.h> |
Hung-Te Lin | 9ede2ff | 2019-08-15 09:43:55 +0800 | [diff] [blame] | 32 | #include <string.h> |
Tristan Shieh | bb684e0 | 2018-06-19 16:07:54 +0800 | [diff] [blame] | 33 | |
Tristan Shieh | 4d990ab | 2019-02-25 17:14:14 +0800 | [diff] [blame^] | 34 | #include "gpio.h" |
Hung-Te Lin | 2c307a0 | 2019-02-20 14:31:23 +0800 | [diff] [blame] | 35 | #include "panel.h" |
| 36 | |
Tristan Shieh | 4d990ab | 2019-02-25 17:14:14 +0800 | [diff] [blame^] | 37 | #include <arm-trusted-firmware/include/export/plat/mediatek/common/plat_params_exp.h> |
| 38 | |
Tristan Shieh | 8db79c1 | 2018-09-07 17:26:21 +0800 | [diff] [blame] | 39 | static void configure_emmc(void) |
| 40 | { |
| 41 | const gpio_t emmc_pin[] = { |
| 42 | GPIO(MSDC0_DAT0), GPIO(MSDC0_DAT1), |
| 43 | GPIO(MSDC0_DAT2), GPIO(MSDC0_DAT3), |
| 44 | GPIO(MSDC0_DAT4), GPIO(MSDC0_DAT5), |
| 45 | GPIO(MSDC0_DAT6), GPIO(MSDC0_DAT7), |
| 46 | GPIO(MSDC0_CMD), GPIO(MSDC0_RSTB), |
| 47 | }; |
| 48 | |
| 49 | for (size_t i = 0; i < ARRAY_SIZE(emmc_pin); i++) |
| 50 | gpio_set_pull(emmc_pin[i], GPIO_PULL_ENABLE, GPIO_PULL_UP); |
| 51 | } |
| 52 | |
Tristan Shieh | 71ae582 | 2018-09-26 14:33:54 +0800 | [diff] [blame] | 53 | static void configure_usb(void) |
| 54 | { |
| 55 | setup_usb_host(); |
| 56 | } |
| 57 | |
Jiaxin Yu | 30bc9f4 | 2019-04-23 20:45:50 +0800 | [diff] [blame] | 58 | static void configure_audio(void) |
| 59 | { |
| 60 | /* Audio PWR*/ |
| 61 | mtcmos_audio_power_on(); |
| 62 | |
| 63 | /* SoC I2S */ |
| 64 | gpio_set_mode(GPIO(CAM_RST0), PAD_CAM_RST0_FUNC_I2S2_LRCK); |
| 65 | gpio_set_mode(GPIO(CAM_PDN1), PAD_CAM_PDN1_FUNC_I2S2_BCK); |
| 66 | gpio_set_mode(GPIO(CAM_PDN0), PAD_CAM_PDN0_FUNC_I2S2_MCK); |
| 67 | gpio_set_mode(GPIO(EINT3), PAD_EINT3_FUNC_I2S3_DO); |
| 68 | } |
Hung-Te Lin | 2c307a0 | 2019-02-20 14:31:23 +0800 | [diff] [blame] | 69 | |
| 70 | /* Default implementation for boards without panels defined yet. */ |
| 71 | struct panel_description __weak *get_panel_description(int panel_id) |
| 72 | { |
| 73 | printk(BIOS_ERR, "%s: ERROR: No panels defined for board: %s.\n", |
| 74 | __func__, CONFIG_MAINBOARD_PART_NUMBER); |
| 75 | return NULL; |
| 76 | } |
| 77 | |
| 78 | /* Set up backlight control pins as output pin and power-off by default */ |
| 79 | static void configure_panel_backlight(void) |
| 80 | { |
| 81 | gpio_output(GPIO(PERIPHERAL_EN13), 0); |
| 82 | gpio_output(GPIO(DISP_PWM), 0); |
| 83 | } |
| 84 | |
| 85 | static void power_on_panel(struct panel_description *panel) |
| 86 | { |
| 87 | if (panel->power_on) { |
| 88 | panel->power_on(); |
| 89 | return; |
| 90 | } |
| 91 | |
| 92 | /* Default power sequence for most panels. */ |
| 93 | gpio_output(GPIO_LCM_RST_1V8, 0); |
| 94 | gpio_output(GPIO_PPVARP_LCD_EN, 1); |
| 95 | gpio_output(GPIO_PPVARN_LCD_EN, 1); |
| 96 | gpio_output(GPIO_PP1800_LCM_EN, 1); |
| 97 | gpio_output(GPIO_PP3300_LCM_EN, 1); |
| 98 | mdelay(6); |
| 99 | gpio_output(GPIO_LCM_RST_1V8, 1); |
| 100 | mdelay(6); |
| 101 | } |
| 102 | |
Hung-Te Lin | 9ede2ff | 2019-08-15 09:43:55 +0800 | [diff] [blame] | 103 | struct panel_description *get_panel_from_cbfs(struct panel_description *desc) |
| 104 | { |
| 105 | /* The CBFS name will be panel-{MANUFACTURER}-${PANEL_NAME}, |
| 106 | * where MANUFACTURER is 3 characters and PANEL_NAME is usually |
| 107 | * 13 characters. |
| 108 | */ |
| 109 | char cbfs_name[64]; |
| 110 | static union { |
| 111 | u8 raw[4 * 1024]; /* Most panels only need < 2K. */ |
| 112 | struct panel_serializable_data s; |
| 113 | } buffer; |
| 114 | |
| 115 | if (!desc->name) |
| 116 | return NULL; |
| 117 | |
| 118 | snprintf(cbfs_name, sizeof(cbfs_name), "panel-%s", desc->name); |
| 119 | if (cbfs_boot_load_file(cbfs_name, buffer.raw, sizeof(buffer), |
| 120 | CBFS_TYPE_STRUCT)) |
| 121 | desc->s = &buffer.s; |
| 122 | else |
| 123 | printk(BIOS_ERR, "Missing %s in CBFS.\n", cbfs_name); |
| 124 | |
| 125 | return desc->s ? desc : NULL; |
| 126 | } |
| 127 | |
Hung-Te Lin | 2c307a0 | 2019-02-20 14:31:23 +0800 | [diff] [blame] | 128 | static struct panel_description *get_active_panel(void) |
| 129 | { |
| 130 | /* TODO(hungte) Create a dedicated panel_id() in board_id.c */ |
| 131 | int panel_id = sku_id() >> 4; |
| 132 | |
| 133 | struct panel_description *panel = get_panel_description(panel_id); |
| 134 | if (!panel) { |
| 135 | printk(BIOS_ERR, "%s: Panel %d is not supported.\n", |
| 136 | __func__, panel_id); |
| 137 | return NULL; |
| 138 | } |
Hung-Te Lin | 9ede2ff | 2019-08-15 09:43:55 +0800 | [diff] [blame] | 139 | assert(panel->s); |
| 140 | |
| 141 | const struct edid *edid = &panel->s->edid; |
| 142 | const char *name = edid->ascii_string; |
Hung-Te Lin | 2c307a0 | 2019-02-20 14:31:23 +0800 | [diff] [blame] | 143 | if (name[0] == '\0') |
| 144 | name = "unknown name"; |
Hung-Te Lin | 9ede2ff | 2019-08-15 09:43:55 +0800 | [diff] [blame] | 145 | printk(BIOS_INFO, "%s: Found ID %d: '%s %s' %dx%d@%dHz\n", __func__, |
| 146 | panel_id, edid->manufacturer_name, name, edid->mode.ha, |
| 147 | edid->mode.va, edid->mode.refresh); |
Hung-Te Lin | 2c307a0 | 2019-02-20 14:31:23 +0800 | [diff] [blame] | 148 | return panel; |
| 149 | } |
| 150 | |
| 151 | static bool configure_display(void) |
| 152 | { |
| 153 | struct panel_description *panel = get_active_panel(); |
| 154 | if (!panel) |
| 155 | return false; |
| 156 | |
| 157 | mtcmos_display_power_on(); |
| 158 | mtcmos_protect_display_bus(); |
| 159 | configure_panel_backlight(); |
| 160 | power_on_panel(panel); |
| 161 | |
Hung-Te Lin | 9ede2ff | 2019-08-15 09:43:55 +0800 | [diff] [blame] | 162 | struct edid *edid = &panel->s->edid; |
Hung-Te Lin | 2c307a0 | 2019-02-20 14:31:23 +0800 | [diff] [blame] | 163 | edid_set_framebuffer_bits_per_pixel(edid, 32, 0); |
| 164 | mtk_ddp_init(); |
| 165 | u32 mipi_dsi_flags = (MIPI_DSI_MODE_VIDEO | |
| 166 | MIPI_DSI_MODE_VIDEO_SYNC_PULSE | |
| 167 | MIPI_DSI_MODE_LPM); |
| 168 | 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] | 169 | panel->s->init) < 0) { |
Hung-Te Lin | 2c307a0 | 2019-02-20 14:31:23 +0800 | [diff] [blame] | 170 | printk(BIOS_ERR, "%s: Failed in DSI init.\n", __func__); |
| 171 | return false; |
| 172 | } |
| 173 | mtk_ddp_mode_set(edid); |
| 174 | set_vbe_mode_info_valid(edid, 0); |
Hung-Te Lin | 9ede2ff | 2019-08-15 09:43:55 +0800 | [diff] [blame] | 175 | set_vbe_framebuffer_orientation(panel->s->orientation); |
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(); |
Tristan Shieh | 4d990ab | 2019-02-25 17:14:14 +0800 | [diff] [blame^] | 204 | |
| 205 | register_reset_to_bl31(); |
Tristan Shieh | bb684e0 | 2018-06-19 16:07:54 +0800 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | static void mainboard_enable(struct device *dev) |
| 209 | { |
| 210 | dev->ops->init = &mainboard_init; |
| 211 | } |
| 212 | |
| 213 | struct chip_operations mainboard_ops = { |
| 214 | .name = CONFIG_MAINBOARD_PART_NUMBER, |
| 215 | .enable_dev = mainboard_enable, |
| 216 | }; |