drivers/wifi: Remove unnecessary data structure copy
[coreboot2.git] / src / soc / mediatek / common / display.c
bloba212805b5b1828933a4849608a84c86eff45ea4b
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <cbfs.h>
4 #include <console/console.h>
5 #include <delay.h>
6 #include <edid.h>
7 #include <framebuffer_info.h>
8 #include <soc/ddp.h>
9 #include <soc/display.h>
10 #include <soc/dptx.h>
11 #include <soc/dsi.h>
12 #include <soc/mtcmos.h>
13 #include <stdio.h>
15 static struct panel_serializable_data *get_mipi_cmd_from_cbfs(struct panel_description *desc)
18 * The CBFS file name is panel-{MANUFACTURER}-${PANEL_NAME}, where MANUFACTURER is 3
19 * characters and PANEL_NAME is usually 13 characters.
21 char cbfs_name[64];
22 static union {
23 u8 raw[4 * 1024]; /* Most panels only need < 2K. */
24 struct panel_serializable_data s;
25 } buffer;
27 if (!desc->name) {
28 printk(BIOS_ERR, "Missing panel CBFS file name.\n");
29 return NULL;
32 snprintf(cbfs_name, sizeof(cbfs_name), "panel-%s", desc->name);
33 if (cbfs_load(cbfs_name, buffer.raw, sizeof(buffer)))
34 return &buffer.s;
36 printk(BIOS_ERR, "Missing %s in CBFS.\n", cbfs_name);
37 return NULL;
40 __weak int mtk_edp_init(struct edid *edid)
42 printk(BIOS_WARNING, "%s: Not supported\n", __func__);
43 return -1;
46 __weak int mtk_dsi_init(u32 mode_flags, u32 format, u32 lanes,
47 const struct edid *edid, const u8 *init_commands)
49 printk(BIOS_WARNING, "%s: Not supported\n", __func__);
50 return -1;
53 int mtk_display_init(void)
55 struct edid edid;
56 struct fb_info *info;
57 const char *name;
58 struct panel_description *panel = get_active_panel();
60 if (!panel || panel->disp_path == DISP_PATH_NONE) {
61 printk(BIOS_ERR, "%s: Failed to get the active panel\n", __func__);
62 return -1;
65 printk(BIOS_INFO, "%s: Starting display initialization\n", __func__);
67 mtcmos_display_power_on();
68 mtcmos_protect_display_bus();
70 if (panel->configure_backlight)
71 panel->configure_backlight();
72 if (panel->power_on)
73 panel->power_on();
75 mtk_ddp_init();
77 if (panel->disp_path == DISP_PATH_EDP) {
78 mdelay(200);
79 if (mtk_edp_init(&edid) < 0) {
80 printk(BIOS_ERR, "%s: Failed to initialize eDP\n", __func__);
81 return -1;
83 } else {
84 struct panel_serializable_data *mipi_data = NULL;
86 if (panel->get_edid) {
87 if (panel->get_edid(&edid) < 0)
88 return -1;
89 } else {
90 mipi_data = get_mipi_cmd_from_cbfs(panel);
91 if (!mipi_data)
92 return -1;
93 edid = mipi_data->edid;
96 u32 mipi_dsi_flags = (MIPI_DSI_MODE_VIDEO |
97 MIPI_DSI_MODE_VIDEO_SYNC_PULSE |
98 MIPI_DSI_MODE_LPM |
99 MIPI_DSI_MODE_EOT_PACKET);
101 if (mtk_dsi_init(mipi_dsi_flags, MIPI_DSI_FMT_RGB888, 4, &edid,
102 mipi_data ? mipi_data->init : NULL) < 0) {
103 printk(BIOS_ERR, "%s: Failed in DSI init\n", __func__);
104 return -1;
107 if (panel->post_power_on && panel->post_power_on(&edid) < 0) {
108 printk(BIOS_ERR, "%s: Failed to post power on bridge\n", __func__);
109 return -1;
113 name = edid.ascii_string;
114 if (name[0] == '\0')
115 name = "unknown name";
116 printk(BIOS_INFO, "%s: '%s %s' %dx%d@%dHz\n", __func__,
117 edid.manufacturer_name, name, edid.mode.ha, edid.mode.va,
118 edid.mode.refresh);
120 edid_set_framebuffer_bits_per_pixel(&edid, 32, 0);
122 mtk_ddp_mode_set(&edid, panel->disp_path);
123 info = fb_new_framebuffer_info_from_edid(&edid, (uintptr_t)0);
124 if (info)
125 fb_set_orientation(info, panel->orientation);
127 return 0;