huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 1 | /* |
| 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 Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 17 | * Foundation, Inc. |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 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> |
Yakir Yang | 68f42be | 2015-04-29 10:08:12 -0500 | [diff] [blame] | 34 | #include <soc/hdmi.h> |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 35 | #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 | |
| 42 | void 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 Hendricks | af42f06 | 2015-06-17 13:47:28 -0700 | [diff] [blame] | 49 | enum vop_modes detected_mode = VOP_MODE_UNKNOWN; |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 50 | |
| 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 Yang | 68f42be | 2015-04-29 10:08:12 -0500 | [diff] [blame] | 56 | switch (conf->vop_mode) { |
David Hendricks | cc82851 | 2015-06-25 18:00:37 -0700 | [diff] [blame] | 57 | case VOP_MODE_NONE: |
| 58 | return; |
David Hendricks | af42f06 | 2015-06-17 13:47:28 -0700 | [diff] [blame] | 59 | 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 Yang | 68f42be | 2015-04-29 10:08:12 -0500 | [diff] [blame] | 63 | rkclk_configure_edp(); |
| 64 | rkclk_configure_vop_aclk(conf->vop_id, 192 * MHz); |
| 65 | rk_edp_init(conf->vop_id); |
David Hendricks | af42f06 | 2015-06-17 13:47:28 -0700 | [diff] [blame] | 66 | |
| 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 Yang | 68f42be | 2015-04-29 10:08:12 -0500 | [diff] [blame] | 74 | } |
David Hendricks | af42f06 | 2015-06-17 13:47:28 -0700 | [diff] [blame] | 75 | /* 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 lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 94 | } |
| 95 | |
David Hendricks | 7dbf9c6 | 2015-07-30 18:49:48 -0700 | [diff] [blame^] | 96 | if (rkclk_configure_vop_dclk(conf->vop_id, edid.mode.pixel_clock * KHz)) { |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 97 | printk(BIOS_WARNING, "config vop err\n"); |
| 98 | return; |
| 99 | } |
| 100 | |
| 101 | edid.framebuffer_bits_per_pixel = conf->framebuffer_bits_per_pixel; |
David Hendricks | 7dbf9c6 | 2015-07-30 18:49:48 -0700 | [diff] [blame^] | 102 | 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 Hendricks | af42f06 | 2015-06-17 13:47:28 -0700 | [diff] [blame] | 105 | rkvop_mode_set(conf->vop_id, &edid, detected_mode); |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 106 | |
| 107 | rkvop_enable(conf->vop_id, lcdbase, &edid); |
| 108 | |
David Hendricks | af42f06 | 2015-06-17 13:47:28 -0700 | [diff] [blame] | 109 | switch (detected_mode) { |
| 110 | case VOP_MODE_HDMI: |
Yakir Yang | 68f42be | 2015-04-29 10:08:12 -0500 | [diff] [blame] | 111 | 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 Hendricks | af42f06 | 2015-06-17 13:47:28 -0700 | [diff] [blame] | 124 | case VOP_MODE_EDP: |
Yakir Yang | 68f42be | 2015-04-29 10:08:12 -0500 | [diff] [blame] | 125 | 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 lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | set_vbe_mode_info_valid(&edid, (uintptr_t)lcdbase); |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 135 | } |