1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <arch/cache.h>
4 #include <device/mmio.h>
5 #include <console/console.h>
6 #include <device/device.h>
11 #include <soc/addressmap.h>
12 #include <soc/clock.h>
13 #include <soc/display.h>
19 #include <framebuffer_info.h>
23 void rk_display_init(struct device
*dev
, u32 lcdbase
, unsigned long fb_size
)
27 struct soc_rockchip_rk3288_config
*conf
= dev
->chip_info
;
28 uint32_t lower
= ALIGN_DOWN(lcdbase
, MiB
);
29 uint32_t upper
= ALIGN_UP(lcdbase
+ fb_size
, MiB
);
30 enum vop_modes detected_mode
= VOP_MODE_UNKNOWN
;
32 printk(BIOS_SPEW
, "LCD framebuffer @%p\n", (void *)(lcdbase
));
33 memset((void *)lcdbase
, 0, fb_size
); /* clear the framebuffer */
34 dcache_clean_invalidate_by_mva((void *)lower
, upper
- lower
);
35 mmu_config_range(lower
/ MiB
, (upper
- lower
) / MiB
, DCACHE_OFF
);
37 switch (conf
->vop_mode
) {
40 case VOP_MODE_AUTO_DETECT
:
41 /* try EDP first, then HDMI */
43 printk(BIOS_DEBUG
, "Attempting to setup EDP display.\n");
44 rkclk_configure_edp();
45 rkclk_configure_vop_aclk(conf
->vop_id
, 192 * MHz
);
47 /* grf_edp_ref_clk_sel: from internal 24MHz or 27MHz clock */
48 write32(&rk3288_grf
->soc_con12
, RK_SETBITS(1 << 4));
50 /* select epd signal from vop0 or vop1 */
51 val
= (conf
->vop_id
== 1) ? RK_SETBITS(1 << 5) :
53 write32(&rk3288_grf
->soc_con6
, val
);
57 if (rk_edp_get_edid(&edid
) == 0) {
58 detected_mode
= VOP_MODE_EDP
;
61 printk(BIOS_WARNING
, "Cannot get EDID from EDP.\n");
62 if (conf
->vop_mode
== VOP_MODE_EDP
)
67 printk(BIOS_DEBUG
, "Attempting to setup HDMI display.\n");
68 rkclk_configure_hdmi();
69 rkclk_configure_vop_aclk(conf
->vop_id
, 384 * MHz
);
70 rk_hdmi_init(conf
->vop_id
);
72 if (rk_hdmi_get_edid(&edid
) == 0) {
73 detected_mode
= VOP_MODE_HDMI
;
76 printk(BIOS_WARNING
, "Cannot get EDID from HDMI.\n");
77 if (conf
->vop_mode
== VOP_MODE_HDMI
)
82 printk(BIOS_WARNING
, "Cannot read any edid info, aborting.\n");
86 if (rkclk_configure_vop_dclk(conf
->vop_id
, edid
.mode
.pixel_clock
* KHz
)) {
87 printk(BIOS_WARNING
, "config vop err\n");
91 edid_set_framebuffer_bits_per_pixel(&edid
,
92 conf
->framebuffer_bits_per_pixel
, 0);
93 rkvop_mode_set(conf
->vop_id
, &edid
, detected_mode
);
95 rkvop_prepare(conf
->vop_id
, &edid
);
96 rkvop_enable(conf
->vop_id
, lcdbase
);
98 switch (detected_mode
) {
100 if (rk_hdmi_enable(&edid
)) {
101 printk(BIOS_WARNING
, "hdmi enable err\n");
106 * HACK: if we do remove this delay, HDMI TV may not show
107 * anythings. So we make an delay here, ensure TV have
108 * enough time to respond.
115 if (rk_edp_prepare()) {
116 printk(BIOS_WARNING
, "edp prepare err\n");
119 if (rk_edp_enable()) {
120 printk(BIOS_WARNING
, "edp enable err\n");
123 mainboard_power_on_backlight();
127 fb_new_framebuffer_info_from_edid(&edid
, (uintptr_t)lcdbase
);