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 |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include <arch/io.h> |
| 21 | #include <console/console.h> |
| 22 | #include <delay.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <string.h> |
| 25 | #include <stddef.h> |
| 26 | #include <soc/addressmap.h> |
| 27 | #include <soc/clock.h> |
| 28 | #include <soc/edp.h> |
| 29 | #include <soc/vop.h> |
| 30 | |
| 31 | #include "chip.h" |
| 32 | |
| 33 | static struct rk3288_vop_regs * const vop_regs[] = { |
| 34 | (struct rk3288_vop_regs *)VOP_BIG_BASE, |
| 35 | (struct rk3288_vop_regs *)VOP_LIT_BASE |
| 36 | }; |
| 37 | |
| 38 | void rkvop_enable(u32 vop_id, u32 fbbase, const struct edid *edid) |
| 39 | { |
| 40 | u32 lb_mode; |
| 41 | u32 rgb_mode; |
| 42 | u32 hactive = edid->ha; |
| 43 | u32 vactive = edid->va; |
| 44 | u32 hsync_len = edid->hspw; |
| 45 | u32 hback_porch = edid->hbl - edid->hso - edid->hspw; |
| 46 | u32 vsync_len = edid->vspw; |
| 47 | u32 vback_porch = edid->vbl - edid->vso - edid->vspw; |
| 48 | u32 xpos = 0, ypos = 0; |
| 49 | struct rk3288_vop_regs *preg = vop_regs[vop_id]; |
| 50 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame^] | 51 | write32(&preg->win0_act_info, |
| 52 | V_ACT_WIDTH(hactive - 1) | V_ACT_HEIGHT(vactive - 1)); |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 53 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame^] | 54 | write32(&preg->win0_dsp_st, |
| 55 | V_DSP_XST(xpos + hsync_len + hback_porch) | V_DSP_YST(ypos + vsync_len + vback_porch)); |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 56 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame^] | 57 | write32(&preg->win0_dsp_info, |
| 58 | V_DSP_WIDTH(hactive - 1) | V_DSP_HEIGHT(vactive - 1)); |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 59 | |
| 60 | clrsetbits_le32(&preg->win0_color_key, M_WIN0_KEY_EN | M_WIN0_KEY_COLOR, |
| 61 | V_WIN0_KEY_EN(0) | |
| 62 | V_WIN0_KEY_COLOR(0)); |
| 63 | |
| 64 | switch (edid->framebuffer_bits_per_pixel) { |
| 65 | case 16: |
| 66 | rgb_mode = RGB565; |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame^] | 67 | write32(&preg->win0_vir, V_RGB565_VIRWIDTH(hactive)); |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 68 | break; |
| 69 | case 24: |
| 70 | rgb_mode = RGB888; |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame^] | 71 | write32(&preg->win0_vir, V_RGB888_VIRWIDTH(hactive)); |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 72 | break; |
| 73 | case 32: |
| 74 | default: |
| 75 | rgb_mode = ARGB8888; |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame^] | 76 | write32(&preg->win0_vir, V_ARGB888_VIRWIDTH(hactive)); |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 77 | break; |
| 78 | } |
| 79 | |
| 80 | if (hactive > 2560) |
| 81 | lb_mode = LB_RGB_3840X2; |
| 82 | else if (hactive > 1920) |
| 83 | lb_mode = LB_RGB_2560X4; |
| 84 | else if (hactive > 1280) |
| 85 | lb_mode = LB_RGB_1920X5; |
| 86 | else |
| 87 | lb_mode = LB_RGB_1280X8; |
| 88 | |
| 89 | clrsetbits_le32(&preg->win0_ctrl0, |
| 90 | M_WIN0_LB_MODE | M_WIN0_DATA_FMT | M_WIN0_EN, |
| 91 | V_WIN0_LB_MODE(lb_mode) | |
| 92 | V_WIN0_DATA_FMT(rgb_mode) | V_WIN0_EN(1)); |
| 93 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame^] | 94 | write32(&preg->win0_yrgb_mst, fbbase); |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 95 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame^] | 96 | write32(&preg->reg_cfg_done, 0x01); /* enable reg config */ |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | void rkvop_mode_set(u32 vop_id, const struct edid *edid) |
| 100 | { |
| 101 | u32 hactive = edid->ha; |
| 102 | u32 vactive = edid->va; |
| 103 | u32 hfront_porch = edid->hso; |
| 104 | u32 hsync_len = edid->hspw; |
| 105 | u32 hback_porch = edid->hbl - edid->hso - edid->hspw; |
| 106 | u32 vfront_porch = edid->vso; |
| 107 | u32 vsync_len = edid->vspw; |
| 108 | u32 vback_porch = edid->vbl - edid->vso - edid->vspw; |
| 109 | struct rk3288_vop_regs *preg = vop_regs[vop_id]; |
| 110 | |
| 111 | clrsetbits_le32(&preg->sys_ctrl, M_ALL_OUT_EN, V_EDP_OUT_EN(1)); |
| 112 | clrsetbits_le32(&preg->dsp_ctrl0, M_DSP_OUT_MODE, |
| 113 | V_DSP_OUT_MODE(15)); |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame^] | 114 | write32(&preg->dsp_htotal_hs_end, |
| 115 | V_HSYNC(hsync_len) | V_HORPRD(hsync_len + hback_porch + hactive + hfront_porch)); |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 116 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame^] | 117 | write32(&preg->dsp_hact_st_end, |
| 118 | V_HEAP(hsync_len + hback_porch + hactive) | V_HASP(hsync_len + hback_porch)); |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 119 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame^] | 120 | write32(&preg->dsp_vtotal_vs_end, |
| 121 | V_VSYNC(vsync_len) | V_VERPRD(vsync_len + vback_porch + vactive + vfront_porch)); |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 122 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame^] | 123 | write32(&preg->dsp_vact_st_end, |
| 124 | V_VAEP(vsync_len + vback_porch + vactive) | V_VASP(vsync_len + vback_porch)); |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 125 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame^] | 126 | write32(&preg->post_dsp_hact_info, |
| 127 | V_HEAP(hsync_len + hback_porch + hactive) | V_HASP(hsync_len + hback_porch)); |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 128 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame^] | 129 | write32(&preg->post_dsp_vact_info, |
| 130 | V_VAEP(vsync_len + vback_porch + vactive) | V_VASP(vsync_len + vback_porch)); |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 131 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame^] | 132 | write32(&preg->reg_cfg_done, 0x01); /* enable reg config */ |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 133 | } |