Bo-Chen Chen | 4946516 | 2022-11-30 14:47:41 +0800 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <boardid.h> |
| 4 | #include <cbfs.h> |
| 5 | #include <console/console.h> |
| 6 | #include <edid.h> |
| 7 | #include <gpio.h> |
| 8 | #include <soc/gpio_common.h> |
| 9 | #include <string.h> |
| 10 | |
| 11 | #include "gpio.h" |
| 12 | #include "panel.h" |
| 13 | |
| 14 | static void get_mipi_cmd_from_cbfs(struct panel_description *desc) |
| 15 | { |
| 16 | /* |
| 17 | * The CBFS file name is panel-{MANUFACTURER}-${PANEL_NAME}, where MANUFACTURER is 3 |
| 18 | * characters and PANEL_NAME is usually 13 characters. |
| 19 | */ |
| 20 | char cbfs_name[64]; |
| 21 | static union { |
| 22 | u8 raw[4 * 1024]; /* Most panels only need < 2K. */ |
| 23 | struct panel_serializable_data s; |
| 24 | } buffer; |
| 25 | |
| 26 | if (!desc->name) { |
| 27 | printk(BIOS_ERR, "Missing panel CBFS file name.\n"); |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | snprintf(cbfs_name, sizeof(cbfs_name), "panel-%s", desc->name); |
| 32 | if (cbfs_load(cbfs_name, buffer.raw, sizeof(buffer))) |
| 33 | desc->s = &buffer.s; |
| 34 | else |
| 35 | printk(BIOS_ERR, "Missing %s in CBFS.\n", cbfs_name); |
| 36 | } |
| 37 | |
| 38 | struct panel_description *get_active_panel(void) |
| 39 | { |
| 40 | uint32_t active_panel_id = panel_id(); |
| 41 | |
| 42 | struct panel_description *panel = get_panel_description(active_panel_id); |
| 43 | if (!panel || panel->disp_path == DISP_PATH_NONE) { |
| 44 | printk(BIOS_ERR, "%s: Panel %u is not supported.\n", __func__, active_panel_id); |
| 45 | return NULL; |
| 46 | } |
| 47 | |
| 48 | /* For eDP, we will get edid after eDP initialization is done, so we return directly. */ |
| 49 | if (panel->disp_path == DISP_PATH_EDP) { |
| 50 | printk(BIOS_INFO, "%s: Use eDP as the display\n", __func__); |
| 51 | return panel; |
| 52 | } |
| 53 | |
| 54 | /* We need to find init cmds for MIPI panel from CBFS */ |
| 55 | get_mipi_cmd_from_cbfs(panel); |
| 56 | assert(panel->s); |
| 57 | |
| 58 | const struct edid *edid = &panel->s->edid; |
| 59 | const char *name = edid->ascii_string; |
| 60 | if (name[0] == '\0') { |
| 61 | name = "unknown name"; |
| 62 | printk(BIOS_INFO, "%s: Found ID %u: '%s %s' %dx%d@%dHz\n", __func__, |
| 63 | active_panel_id, edid->manufacturer_name, name, edid->mode.ha, |
| 64 | edid->mode.va, edid->mode.refresh); |
| 65 | } |
| 66 | return panel; |
| 67 | } |