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 | |
Lin Huang | 152e675 | 2016-10-20 14:22:11 -0700 | [diff] [blame^] | 39 | void rk_display_init(device_t dev) |
Shunqian Zheng | d1cec75 | 2016-05-04 16:21:36 +0800 | [diff] [blame] | 40 | { |
| 41 | struct edid edid; |
Shunqian Zheng | d1cec75 | 2016-05-04 16:21:36 +0800 | [diff] [blame] | 42 | struct soc_rockchip_rk3399_config *conf = dev->chip_info; |
Shunqian Zheng | d1cec75 | 2016-05-04 16:21:36 +0800 | [diff] [blame] | 43 | enum vop_modes detected_mode = VOP_MODE_UNKNOWN; |
| 44 | |
Lin Huang | 152e675 | 2016-10-20 14:22:11 -0700 | [diff] [blame^] | 45 | /* let's use vop0 in rk3399 */ |
| 46 | uint32_t vop_id = 0; |
Shunqian Zheng | d1cec75 | 2016-05-04 16:21:36 +0800 | [diff] [blame] | 47 | |
| 48 | switch (conf->vop_mode) { |
| 49 | case VOP_MODE_NONE: |
| 50 | return; |
| 51 | case VOP_MODE_AUTO_DETECT: |
| 52 | /* try EDP first, then HDMI */ |
| 53 | case VOP_MODE_EDP: |
| 54 | printk(BIOS_DEBUG, "Attempting to set up EDP display.\n"); |
Lin Huang | 152e675 | 2016-10-20 14:22:11 -0700 | [diff] [blame^] | 55 | rkclk_configure_vop_aclk(vop_id, 192 * MHz); |
Shunqian Zheng | d1cec75 | 2016-05-04 16:21:36 +0800 | [diff] [blame] | 56 | |
Lin Huang | 152e675 | 2016-10-20 14:22:11 -0700 | [diff] [blame^] | 57 | /* select edp signal from vop0 */ |
| 58 | write32(&rk3399_grf->soc_con20, RK_CLRBITS(1 << 5)); |
Shunqian Zheng | d1cec75 | 2016-05-04 16:21:36 +0800 | [diff] [blame] | 59 | |
| 60 | /* select edp clk from SoC internal 24M crystal, otherwise, |
| 61 | * it will source from edp's 24M clock (that depends on |
| 62 | * edp vendor, could be unstable) |
| 63 | */ |
| 64 | write32(&rk3399_grf->soc_con25, RK_SETBITS(1 << 11)); |
| 65 | |
| 66 | rk_edp_init(); |
| 67 | |
| 68 | if (rk_edp_get_edid(&edid) == 0) { |
| 69 | detected_mode = VOP_MODE_EDP; |
| 70 | break; |
| 71 | } |
| 72 | printk(BIOS_WARNING, "Cannot get EDID from EDP.\n"); |
| 73 | if (conf->vop_mode == VOP_MODE_EDP) |
| 74 | return; |
| 75 | /* fall thru */ |
| 76 | case VOP_MODE_HDMI: |
| 77 | printk(BIOS_WARNING, "HDMI display is NOT supported yet.\n"); |
| 78 | return; |
| 79 | default: |
| 80 | printk(BIOS_WARNING, "Cannot read any EDID info, aborting.\n"); |
| 81 | return; |
| 82 | } |
| 83 | |
Lin Huang | 152e675 | 2016-10-20 14:22:11 -0700 | [diff] [blame^] | 84 | if (rkclk_configure_vop_dclk(vop_id, |
Shunqian Zheng | d1cec75 | 2016-05-04 16:21:36 +0800 | [diff] [blame] | 85 | edid.mode.pixel_clock * KHz)) { |
| 86 | printk(BIOS_WARNING, "config vop err\n"); |
| 87 | return; |
| 88 | } |
| 89 | |
Julius Werner | e74f5ea | 2016-10-17 18:14:41 -0700 | [diff] [blame] | 90 | edid_set_framebuffer_bits_per_pixel(&edid, |
| 91 | conf->framebuffer_bits_per_pixel, 0); |
Lin Huang | 152e675 | 2016-10-20 14:22:11 -0700 | [diff] [blame^] | 92 | rkvop_mode_set(vop_id, &edid, detected_mode); |
Shunqian Zheng | d1cec75 | 2016-05-04 16:21:36 +0800 | [diff] [blame] | 93 | |
Lin Huang | 152e675 | 2016-10-20 14:22:11 -0700 | [diff] [blame^] | 94 | rkvop_prepare(vop_id, &edid); |
Shunqian Zheng | d1cec75 | 2016-05-04 16:21:36 +0800 | [diff] [blame] | 95 | |
| 96 | switch (detected_mode) { |
| 97 | case VOP_MODE_HDMI: |
| 98 | /* should not be here before HDMI supported */ |
| 99 | return; |
| 100 | case VOP_MODE_EDP: |
| 101 | default: |
| 102 | if (rk_edp_enable()) { |
| 103 | printk(BIOS_WARNING, "edp enable error\n"); |
| 104 | return; |
| 105 | } |
| 106 | mainboard_power_on_backlight(); |
| 107 | break; |
| 108 | } |
| 109 | |
Lin Huang | 152e675 | 2016-10-20 14:22:11 -0700 | [diff] [blame^] | 110 | set_vbe_mode_info_valid(&edid, (uintptr_t)0); |
Shunqian Zheng | d1cec75 | 2016-05-04 16:21:36 +0800 | [diff] [blame] | 111 | } |