Shunqian Zheng | d1cec75 | 2016-05-04 16:21:36 +0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 39 | void 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 | |
Julius Werner | e74f5ea | 2016-10-17 18:14:41 -0700 | [diff] [blame^] | 98 | edid_set_framebuffer_bits_per_pixel(&edid, |
| 99 | conf->framebuffer_bits_per_pixel, 0); |
Shunqian Zheng | d1cec75 | 2016-05-04 16:21:36 +0800 | [diff] [blame] | 100 | rkvop_mode_set(conf->vop_id, &edid, detected_mode); |
| 101 | |
| 102 | rkvop_enable(conf->vop_id, lcdbase, &edid); |
| 103 | |
| 104 | switch (detected_mode) { |
| 105 | case VOP_MODE_HDMI: |
| 106 | /* should not be here before HDMI supported */ |
| 107 | return; |
| 108 | case VOP_MODE_EDP: |
| 109 | default: |
| 110 | if (rk_edp_enable()) { |
| 111 | printk(BIOS_WARNING, "edp enable error\n"); |
| 112 | return; |
| 113 | } |
| 114 | mainboard_power_on_backlight(); |
| 115 | break; |
| 116 | } |
| 117 | |
| 118 | set_vbe_mode_info_valid(&edid, (uintptr_t)lcdbase); |
| 119 | } |