blob: 02526a4625b42605879a0d4dda93367a74aa4593 [file] [log] [blame]
huang lin40f558e2014-09-19 14:51:52 +08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2014 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 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Patrick Georgib890a122015-03-26 15:17:45 +010017 * Foundation, Inc.
huang lin40f558e2014-09-19 14:51:52 +080018 */
19
20#include <arch/cache.h>
21#include <arch/io.h>
22#include <console/console.h>
23#include <device/device.h>
24#include <delay.h>
25#include <edid.h>
26#include <gpio.h>
27#include <stdlib.h>
28#include <stddef.h>
29#include <string.h>
30#include <soc/addressmap.h>
31#include <soc/clock.h>
32#include <soc/display.h>
33#include <soc/edp.h>
Yakir Yang68f42be2015-04-29 10:08:12 -050034#include <soc/hdmi.h>
huang lin40f558e2014-09-19 14:51:52 +080035#include <soc/gpio.h>
36#include <soc/grf.h>
37#include <soc/soc.h>
38#include <soc/vop.h>
39
40#include "chip.h"
41
42void rk_display_init(device_t dev, u32 lcdbase,
43 unsigned long fb_size)
44{
45 struct edid edid;
46 struct soc_rockchip_rk3288_config *conf = dev->chip_info;
47 uint32_t lower = ALIGN_DOWN(lcdbase, MiB);
48 uint32_t upper = ALIGN_UP(lcdbase + fb_size, MiB);
David Hendricksaf42f062015-06-17 13:47:28 -070049 enum vop_modes detected_mode = VOP_MODE_UNKNOWN;
huang lin40f558e2014-09-19 14:51:52 +080050
51 printk(BIOS_SPEW, "LCD framebuffer @%p\n", (void *)(lcdbase));
52 memset((void *)lcdbase, 0, fb_size); /* clear the framebuffer */
53 dcache_clean_invalidate_by_mva((void *)lower, upper - lower);
54 mmu_config_range(lower / MiB, (upper - lower) / MiB, DCACHE_OFF);
55
Yakir Yang68f42be2015-04-29 10:08:12 -050056 switch (conf->vop_mode) {
David Hendrickscc828512015-06-25 18:00:37 -070057 case VOP_MODE_NONE:
58 return;
David Hendricksaf42f062015-06-17 13:47:28 -070059 case VOP_MODE_AUTO_DETECT:
60 /* try EDP first, then HDMI */
61 case VOP_MODE_EDP:
62 printk(BIOS_DEBUG, "Attempting to setup EDP display.\n");
Yakir Yang68f42be2015-04-29 10:08:12 -050063 rkclk_configure_edp();
64 rkclk_configure_vop_aclk(conf->vop_id, 192 * MHz);
65 rk_edp_init(conf->vop_id);
David Hendricksaf42f062015-06-17 13:47:28 -070066
67 if (rk_edp_get_edid(&edid) == 0) {
68 detected_mode = VOP_MODE_EDP;
69 break;
70 } else {
71 printk(BIOS_WARNING, "Cannot get EDID from EDP.\n");
72 if (conf->vop_mode == VOP_MODE_EDP)
73 return;
Yakir Yang68f42be2015-04-29 10:08:12 -050074 }
David Hendricksaf42f062015-06-17 13:47:28 -070075 /* fall thru */
76 case VOP_MODE_HDMI:
77 printk(BIOS_DEBUG, "Attempting to setup HDMI display.\n");
78 rkclk_configure_hdmi();
79 rkclk_configure_vop_aclk(conf->vop_id, 384 * MHz);
80 rk_hdmi_init(conf->vop_id);
81
82 if (rk_hdmi_get_edid(&edid) == 0) {
83 detected_mode = VOP_MODE_HDMI;
84 break;
85 } else {
86 printk(BIOS_WARNING, "Cannot get EDID from HDMI.\n");
87 if (conf->vop_mode == VOP_MODE_HDMI)
88 return;
89 }
90 /* fall thru */
91 default:
92 printk(BIOS_WARNING, "Cannot read any edid info, aborting.\n");
93 return;
huang lin40f558e2014-09-19 14:51:52 +080094 }
95
David Hendricks7dbf9c62015-07-30 18:49:48 -070096 if (rkclk_configure_vop_dclk(conf->vop_id, edid.mode.pixel_clock * KHz)) {
huang lin40f558e2014-09-19 14:51:52 +080097 printk(BIOS_WARNING, "config vop err\n");
98 return;
99 }
100
101 edid.framebuffer_bits_per_pixel = conf->framebuffer_bits_per_pixel;
David Hendricks7dbf9c62015-07-30 18:49:48 -0700102 edid.bytes_per_line = edid.mode.ha * conf->framebuffer_bits_per_pixel / 8;
103 edid.x_resolution = edid.mode.ha;
104 edid.y_resolution = edid.mode.va;
David Hendricksaf42f062015-06-17 13:47:28 -0700105 rkvop_mode_set(conf->vop_id, &edid, detected_mode);
huang lin40f558e2014-09-19 14:51:52 +0800106
107 rkvop_enable(conf->vop_id, lcdbase, &edid);
108
David Hendricksaf42f062015-06-17 13:47:28 -0700109 switch (detected_mode) {
110 case VOP_MODE_HDMI:
Yakir Yang68f42be2015-04-29 10:08:12 -0500111 if (rk_hdmi_enable(&edid)) {
112 printk(BIOS_WARNING, "hdmi enable err\n");
113 return;
114 }
115
116 /*
117 * HACK: if we do remove this delay, HDMI TV may not show
118 * anythings. So we make an delay here, ensure TV have
119 * enough time to respond.
120 */
121 mdelay(2000);
122 break;
123
David Hendricksaf42f062015-06-17 13:47:28 -0700124 case VOP_MODE_EDP:
Yakir Yang68f42be2015-04-29 10:08:12 -0500125 default:
126 if (rk_edp_enable()) {
127 printk(BIOS_WARNING, "edp enable err\n");
128 return;
129 }
130 mainboard_power_on_backlight();
131 break;
huang lin40f558e2014-09-19 14:51:52 +0800132 }
133
134 set_vbe_mode_info_valid(&edid, (uintptr_t)lcdbase);
huang lin40f558e2014-09-19 14:51:52 +0800135}