blob: d69df93f748f631778ef2a8606bde079f032ac6b [file] [log] [blame]
Shunqian Zhengd1cec752016-05-04 16:21:36 +08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2016 Rockchip Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#include <arch/cache.h>
17#include <arch/mmu.h>
18#include <arch/io.h>
19#include <console/console.h>
20#include <device/device.h>
21#include <delay.h>
22#include <edid.h>
23#include <gpio.h>
24#include <stdlib.h>
25#include <stddef.h>
26#include <string.h>
27#include <soc/addressmap.h>
28#include <soc/clock.h>
29#include <soc/display.h>
30#include <soc/edp.h>
31#include <soc/gpio.h>
32#include <soc/grf.h>
33#include <soc/mmu_operations.h>
34#include <soc/soc.h>
35#include <soc/vop.h>
36
37#include "chip.h"
38
39void rk_display_init(device_t dev, uintptr_t lcdbase,
40 unsigned long fb_size)
41{
42 struct edid edid;
43 uint32_t val;
44 struct soc_rockchip_rk3399_config *conf = dev->chip_info;
45 uintptr_t lower = ALIGN_DOWN(lcdbase, MiB);
46 uintptr_t upper = ALIGN_UP(lcdbase + fb_size, MiB);
47 enum vop_modes detected_mode = VOP_MODE_UNKNOWN;
48
49 printk(BIOS_DEBUG, "LCD framebuffer @%p\n", (void *)(lcdbase));
50 memset((void *)lcdbase, 0, fb_size); /* clear the framebuffer */
51 dcache_clean_invalidate_by_mva((void *)lower, upper - lower);
52 mmu_config_range((void *)lower, upper - lower, UNCACHED_MEM);
53
54 switch (conf->vop_mode) {
55 case VOP_MODE_NONE:
56 return;
57 case VOP_MODE_AUTO_DETECT:
58 /* try EDP first, then HDMI */
59 case VOP_MODE_EDP:
60 printk(BIOS_DEBUG, "Attempting to set up EDP display.\n");
61 rkclk_configure_vop_aclk(conf->vop_id, 192 * MHz);
62
63 /* select edp signal from vop0(big) or vop1(little) */
64 val = (conf->vop_id == 1) ? RK_SETBITS(1 << 5) :
65 RK_CLRBITS(1 << 5);
66 write32(&rk3399_grf->soc_con20, val);
67
68 /* select edp clk from SoC internal 24M crystal, otherwise,
69 * it will source from edp's 24M clock (that depends on
70 * edp vendor, could be unstable)
71 */
72 write32(&rk3399_grf->soc_con25, RK_SETBITS(1 << 11));
73
74 rk_edp_init();
75
76 if (rk_edp_get_edid(&edid) == 0) {
77 detected_mode = VOP_MODE_EDP;
78 break;
79 }
80 printk(BIOS_WARNING, "Cannot get EDID from EDP.\n");
81 if (conf->vop_mode == VOP_MODE_EDP)
82 return;
83 /* fall thru */
84 case VOP_MODE_HDMI:
85 printk(BIOS_WARNING, "HDMI display is NOT supported yet.\n");
86 return;
87 default:
88 printk(BIOS_WARNING, "Cannot read any EDID info, aborting.\n");
89 return;
90 }
91
92 if (rkclk_configure_vop_dclk(conf->vop_id,
93 edid.mode.pixel_clock * KHz)) {
94 printk(BIOS_WARNING, "config vop err\n");
95 return;
96 }
97
98 edid.framebuffer_bits_per_pixel = conf->framebuffer_bits_per_pixel;
99 edid.bytes_per_line =
100 edid.mode.ha * conf->framebuffer_bits_per_pixel / 8;
101 edid.x_resolution = edid.mode.ha;
102 edid.y_resolution = edid.mode.va;
103 rkvop_mode_set(conf->vop_id, &edid, detected_mode);
104
105 rkvop_enable(conf->vop_id, lcdbase, &edid);
106
107 switch (detected_mode) {
108 case VOP_MODE_HDMI:
109 /* should not be here before HDMI supported */
110 return;
111 case VOP_MODE_EDP:
112 default:
113 if (rk_edp_enable()) {
114 printk(BIOS_WARNING, "edp enable error\n");
115 return;
116 }
117 mainboard_power_on_backlight();
118 break;
119 }
120
121 set_vbe_mode_info_valid(&edid, (uintptr_t)lcdbase);
122}