Debian Codegraph @

src/soc/mediatek/mt8189/ddp.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only OR MIT */
2
3 #include <console/console.h>
4 #include <edid.h>
5 #include <soc/addressmap.h>
6 #include <soc/ddp.h>
7 #include <device/mmio.h>
8
9 static void disp_config_main_path_connection(enum disp_path_sel path)
10 {
11 /* Main path: OVL0->RDMA0->DVO0 */
12 write32(&mmsys_cfg->disp_ovl0_bgclr_mout_en, 0x1);
13 write32(&mmsys_cfg->disp_ovl0_out0_mout_en, 0x2);
14 write32(&mmsys_cfg->disp_rdma0_sel_in, 0x1);
15 write32(&mmsys_cfg->disp_rdma0_rsz0_sout_sel, 0x0);
16 write32(&mmsys_cfg->ovl_pq_out_cross1_mout_en, 0x10);
17 write32(&mmsys_cfg->comp_out_cross4_mout_en, 0x02);
18 printk(BIOS_DEBUG,
19 "%s: bgclr_mout_en: %#x ovl0_mout_en: %#x sel_in: %#x sout_sel: %#x"
20 "cross1_mout_en: %#x cross4_mout_en: %#x\n",
21 __func__, read32(&mmsys_cfg->disp_ovl0_bgclr_mout_en),
22 read32(&mmsys_cfg->disp_ovl0_out0_mout_en),
23 read32(&mmsys_cfg->disp_rdma0_sel_in),
24 read32(&mmsys_cfg->disp_rdma0_rsz0_sout_sel),
25 read32(&mmsys_cfg->ovl_pq_out_cross1_mout_en),
26 read32(&mmsys_cfg->comp_out_cross4_mout_en));
27 }
28
29 static void disp_config_main_path_mutex(enum disp_path_sel path)
30 {
31 write32(&disp_mutex->mutex[0].mod, MUTEX_MOD_MAIN_PATH);
32
33 /* Clock source from DVO0 */
34 write32(&disp_mutex->mutex[0].ctl,
35 MUTEX_SOF_DVO | (MUTEX_SOF_DVO << 7));
36 write32(&disp_mutex->mutex[0].en, BIT(0));
37 printk(BIOS_DEBUG, "%s: mutex_mod: %#x ctl %#x\n",
38 __func__, read32(&disp_mutex->mutex[0].mod), read32(&disp_mutex->mutex[0].ctl));
39 }
40
41 static void ovl_layer_smi_id_en(u32 idx)
42 {
43 setbits32(&disp_ovl[idx]->datapath_con, BIT(0));
44 }
45
46 static void ovl_layer_gclast_en(u32 idx)
47 {
48 setbits32(&disp_ovl[idx]->datapath_con, BIT(24));
49 setbits32(&disp_ovl[idx]->datapath_con, BIT(25));
50 }
51
52 static void ovl_layer_output_clamp_en(u32 idx)
53 {
54 setbits32(&disp_ovl[idx]->datapath_con, BIT(26));
55 }
56
57 static void ovl_layer_en(u32 idx)
58 {
59 setbits32(&disp_ovl[idx]->en, BIT(0));
60 }
61
62 static void main_disp_path_setup(u32 width, u32 height, u32 vrefresh, enum disp_path_sel path)
63 {
64 u32 idx;
65 const u32 pixel_clk = width * height * vrefresh;
66
67 for (idx = 0; idx < MAIN_PATH_OVL_NR; idx++) {
68 /* Set OVL background color to blue */
69 ovl_set_roi(idx, width, height, idx ? 0 : 0xff0000ff);
70 ovl_layer_smi_id_en(idx);
71 ovl_layer_gclast_en(idx);
72 ovl_layer_output_clamp_en(idx);
73 ovl_layer_en(idx);
74 }
75
76 rdma_config(width, height, pixel_clk, 5 * KiB);
77 disp_config_main_path_connection(path);
78 disp_config_main_path_mutex(path);
79 }
80
81 static void disp_clock_on(void)
82 {
83 clrbits32(&mmsys_cfg->mmsys_cg_con0, CG_CON0_ALL);
84 clrbits32(&mmsys_cfg->mmsys_cg_con1, CG_CON0_ALL);
85 printk(BIOS_DEBUG, "%s: disp_clock: [%#x %#x]\n",
86 __func__, read32(&mmsys_cfg->mmsys_cg_con0), read32(&mmsys_cfg->mmsys_cg_con1));
87 }
88
89 void mtk_display_disable_secure_mode(void)
90 {
91 disp_clock_on();
92
93 printk(BIOS_DEBUG, "%s: shadow: %#x %#x, secure before: [%#x %#x %#x]\n",
94 __func__,
95 read32(&mmsys_cfg->disp_bypass_mux_shadow),
96 read32(&mmsys_cfg->disp_crossbar_con),
97 read32(&mmsys_cfg->mmsys_security_disable),
98 read32(&mmsys_cfg->mmsys_security_disable1),
99 read32(&mmsys_cfg->mmsys_security_disable2));
100
101 /* disable shadow */
102 write32(&mmsys_cfg->disp_bypass_mux_shadow, 0x1);
103 write32(&mmsys_cfg->disp_crossbar_con, 0x00FF0000);
104 /* disable secure mode */
105 write32(&mmsys_cfg->mmsys_security_disable, 0xFFFFFFFF);
106 write32(&mmsys_cfg->mmsys_security_disable1, 0xFFFFFFFF);
107 write32(&mmsys_cfg->mmsys_security_disable2, 0xFFFFFFFF);
108
109 printk(BIOS_DEBUG, "%s: shadow: %#x %#x, secure: [%#x %#x %#x]n",
110 __func__,
111 read32(&mmsys_cfg->disp_bypass_mux_shadow),
112 read32(&mmsys_cfg->disp_crossbar_con),
113 read32(&mmsys_cfg->mmsys_security_disable),
114 read32(&mmsys_cfg->mmsys_security_disable1),
115 read32(&mmsys_cfg->mmsys_security_disable2));
116 }
117
118 void mtk_ddp_init(void)
119 {
120 int i;
121
122 mtk_display_disable_secure_mode();
123
124 /* Turn off M4U port */
125 for (i = 0; i < RDMA_PORT_NR; i++) {
126 write32(&smi_larb0->port_l0_ovl_rdma[i], 0);
127 write32(&smi_larb1->port_l0_ovl_rdma[i], 0);
128 }
129
130 printk(BIOS_DEBUG, "%s: larb: %#x\n",
131 __func__, read32(&smi_larb0->port_l0_ovl_rdma[0]));
132 }
133
134 void mtk_ddp_mode_set(const struct edid *edid, enum disp_path_sel path)
135 {
136 u32 fmt = OVL_INFMT_RGBA8888;
137 u32 bpp = edid->framebuffer_bits_per_pixel / 8;
138 u32 width = edid->mode.ha;
139 u32 height = edid->mode.va;
140 u32 vrefresh_hz = edid->mode.refresh;
141
142 printk(BIOS_INFO, "%s: display resolution: %dx%d@%d bpp %d\n",
143 __func__, width, height, vrefresh_hz, bpp);
144
145 if (!vrefresh_hz) {
146 if (!width || !height)
147 vrefresh_hz = 60;
148 else
149 vrefresh_hz = edid->mode.pixel_clock * 1000 /
150 ((width + edid->mode.hbl) * (height + edid->mode.vbl));
151
152 printk(BIOS_WARNING, "%s: vrefresh is not provided; using %d\n",
153 __func__, vrefresh_hz);
154 }
155
156 main_disp_path_setup(width, height, vrefresh_hz, path);
157 rdma_start();
158 ovl_layer_config(fmt, bpp, width, height);
159 }