blob: a8ba31a1297442e015c2f4d9630b7f476e7691cc [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
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
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>
34#include <soc/gpio.h>
35#include <soc/grf.h>
36#include <soc/soc.h>
37#include <soc/vop.h>
38
39#include "chip.h"
40
41void rk_display_init(device_t dev, u32 lcdbase,
42 unsigned long fb_size)
43{
44 struct edid edid;
45 struct soc_rockchip_rk3288_config *conf = dev->chip_info;
46 uint32_t lower = ALIGN_DOWN(lcdbase, MiB);
47 uint32_t upper = ALIGN_UP(lcdbase + fb_size, MiB);
48
49 printk(BIOS_SPEW, "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(lower / MiB, (upper - lower) / MiB, DCACHE_OFF);
53
54 rkclk_configure_edp();
55
56 rkclk_configure_vop_aclk(conf->vop_id, 192 * MHz);
57
58 rk_edp_init(conf->vop_id);
59 udelay(conf->lcd_power_on_udelay);
60
61 if (rk_edp_get_edid(&edid)) {
62 printk(BIOS_WARNING, "can not get edid\n");
63 return;
64 }
65
66 if (rkclk_configure_vop_dclk(conf->vop_id, edid.pixel_clock * KHz)) {
67 printk(BIOS_WARNING, "config vop err\n");
68 return;
69 }
70
71 edid.framebuffer_bits_per_pixel = conf->framebuffer_bits_per_pixel;
72 edid.bytes_per_line = edid.ha * conf->framebuffer_bits_per_pixel / 8;
73 edid.x_resolution = edid.ha;
74 edid.y_resolution = edid.va;
75 rkvop_mode_set(conf->vop_id, &edid);
76
77 rkvop_enable(conf->vop_id, lcdbase, &edid);
78
79 if (rk_edp_enable()) {
80 printk(BIOS_WARNING, "edp enable err\n");
81 return;
82 }
83
84 set_vbe_mode_info_valid(&edid, (uintptr_t)lcdbase);
85 gpio_output(conf->lcd_bl_pwm_gpio, 0);
86 gpio_output(conf->lcd_bl_en_gpio, 1); /* LCD_BL */
87 udelay(conf->bl_power_on_udelay);
88 gpio_output(conf->lcd_bl_pwm_gpio, 1); /* BL_EN */
89}