Debian Codegraph @

src/soc/mediatek/common/display.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
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>
14
15 static struct panel_serializable_data *get_mipi_cmd_from_cbfs(struct panel_description *desc)
16 {
17 /*
18 * The CBFS file name is panel-{MANUFACTURER}-${PANEL_NAME}, where MANUFACTURER is 3
19 * characters and PANEL_NAME is usually 13 characters.
20 */
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;
26
27 if (!desc->name) {
28 printk(BIOS_ERR, "Missing panel CBFS file name.\n");
29 return NULL;
30 }
31
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;
35
36 printk(BIOS_ERR, "Missing %s in CBFS.\n", cbfs_name);
37 return NULL;
38 }
39
40 __weak int mtk_edp_init(struct mtk_dp *mtk_dp, struct edid *edid)
41 {
42 printk(BIOS_WARNING, "%s: Not supported\n", __func__);
43 return -1;
44 }
45
46 __weak int mtk_edp_enable(struct mtk_dp *mtk_dp)
47 {
48 printk(BIOS_WARNING, "%s: Not supported\n", __func__);
49 return -1;
50 }
51
52 __weak int mtk_dsi_init(u32 mode_flags, u32 format, u32 lanes,
53 const struct edid *edid, const u8 *init_commands)
54 {
55 printk(BIOS_WARNING, "%s: Not supported\n", __func__);
56 return -1;
57 }
58
59 static void process_panel_quirks(struct mtk_dp *mtk_dp,
60 struct panel_description *panel)
61 {
62 if (panel->quirks & PANEL_QUIRK_FORCE_MAX_SWING)
63 mtk_dp->force_max_swing = true;
64 }
65
66 int mtk_display_init(void)
67 {
68 struct edid edid = {0};
69 struct mtk_dp mtk_edp = {0};
70 struct fb_info *info;
71 const char *name;
72 struct panel_description *panel = get_active_panel();
73
74 if (!panel || panel->disp_path == DISP_PATH_NONE) {
75 printk(BIOS_ERR, "%s: Failed to get the active panel\n", __func__);
76 return -1;
77 }
78
79 printk(BIOS_INFO, "%s: Starting display initialization\n", __func__);
80
81 mtcmos_display_power_on();
82 mtcmos_protect_display_bus();
83
84 if (panel->configure_backlight)
85 panel->configure_backlight();
86 if (panel->power_on)
87 panel->power_on();
88
89 mtk_ddp_init();
90 process_panel_quirks(&mtk_edp, panel);
91
92 if (panel->disp_path == DISP_PATH_EDP) {
93 if (mtk_edp_init(&mtk_edp, &edid) < 0) {
94 printk(BIOS_ERR, "%s: Failed to initialize eDP\n", __func__);
95 return -1;
96 }
97 } else {
98 struct panel_serializable_data *mipi_data = NULL;
99
100 if (panel->get_edid) {
101 if (panel->get_edid(&edid) < 0)
102 return -1;
103 } else {
104 mipi_data = get_mipi_cmd_from_cbfs(panel);
105 if (!mipi_data)
106 return -1;
107 edid = mipi_data->edid;
108 }
109
110 u32 mipi_dsi_flags = (MIPI_DSI_MODE_VIDEO |
111 MIPI_DSI_MODE_VIDEO_SYNC_PULSE |
112 MIPI_DSI_MODE_LPM |
113 MIPI_DSI_MODE_EOT_PACKET);
114
115 if (mtk_dsi_init(mipi_dsi_flags, MIPI_DSI_FMT_RGB888, 4, &edid,
116 mipi_data ? mipi_data->init : NULL) < 0) {
117 printk(BIOS_ERR, "%s: Failed in DSI init\n", __func__);
118 return -1;
119 }
120
121 if (panel->post_power_on && panel->post_power_on(&edid) < 0) {
122 printk(BIOS_ERR, "%s: Failed to post power on bridge\n", __func__);
123 return -1;
124 }
125 }
126
127 name = edid.ascii_string;
128 if (name[0] == '\0')
129 name = "unknown name";
130 printk(BIOS_INFO, "%s: '%s %s' %dx%d@%dHz\n", __func__,
131 edid.manufacturer_name, name, edid.mode.ha, edid.mode.va,
132 edid.mode.refresh);
133
134 edid_set_framebuffer_bits_per_pixel(&edid, 32, 0);
135
136 mtk_ddp_mode_set(&edid, panel->disp_path);
137
138 if (panel->disp_path == DISP_PATH_EDP) {
139 if (mtk_edp_enable(&mtk_edp) < 0) {
140 printk(BIOS_ERR, "%s: Failed to enable eDP\n", __func__);
141 return -1;
142 }
143 }
144
145 info = fb_new_framebuffer_info_from_edid(&edid, (uintptr_t)0);
146 if (info)
147 fb_set_orientation(info, panel->orientation);
148
149 return 0;
150 }