blob: 27fa08d5aa5c6727451bbfece88167a232e0ee20 [file] [log] [blame]
Gabe Black607c0b62013-05-16 05:45:57 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2013 Google 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 <stdlib.h>
21#include <string.h>
22#include <stddef.h>
23#include <delay.h>
24#include <console/console.h>
25#include <device/device.h>
26#include <cbmem.h>
27#include <arch/cache.h>
28#include "fimd.h"
29#include "dp-core.h"
30#include "cpu.h"
31#include "clk.h"
Stefan Reinauer3a0d0d82013-06-20 16:13:19 -070032#include "usb.h"
Gabe Black607c0b62013-05-16 05:45:57 -070033#include "chip.h"
34
Gabe Black607c0b62013-05-16 05:45:57 -070035static unsigned int cpu_id;
36static unsigned int cpu_rev;
37
38static void set_cpu_id(void)
39{
40 cpu_id = readl((void *)EXYNOS_PRO_ID);
41 cpu_id = (0xC000 | ((cpu_id & 0x00FFF000) >> 12));
42
43 /*
44 * 0xC200: EXYNOS4210 EVT0
45 * 0xC210: EXYNOS4210 EVT1
46 */
47 if (cpu_id == 0xC200) {
48 cpu_id |= 0x10;
49 cpu_rev = 0;
50 } else if (cpu_id == 0xC210) {
51 cpu_rev = 1;
52 }
53}
54
55/* we distinguish a display port device from a raw graphics device
56 * because there are dramatic differences in startup depending on
57 * graphics usage. To make startup fast and easier to understand and
58 * debug we explicitly name this common case. The alternate approach,
59 * involving lots of machine and callbacks, is hard to debug and
60 * verify.
61 */
Stefan Reinauer80e62932013-07-29 15:52:23 -070062static void exynos_displayport_init(device_t dev, u32 lcdbase,
63 unsigned long fb_size)
Gabe Black607c0b62013-05-16 05:45:57 -070064{
Gabe Black607c0b62013-05-16 05:45:57 -070065 struct cpu_samsung_exynos5420_config *conf = dev->chip_info;
66 /* put these on the stack. If, at some point, we want to move
67 * this code to a pre-ram stage, it will be much easier.
68 */
Gabe Black607c0b62013-05-16 05:45:57 -070069 struct exynos5_fimd_panel panel;
Gabe Black607c0b62013-05-16 05:45:57 -070070 memset(&panel, 0, sizeof(panel));
71
72 panel.is_dp = 1; /* Display I/F is eDP */
73 /* while it is true that we did a memset to zero,
74 * we leave some 'set to zero' entries here to make
75 * it clear what's going on. Graphics is confusing.
76 */
77 panel.is_mipi = 0;
78 panel.fixvclk = 0;
79 panel.ivclk = 0;
80 panel.clkval_f = conf->clkval_f;
81 panel.upper_margin = conf->upper_margin;
82 panel.lower_margin = conf->lower_margin;
83 panel.vsync = conf->vsync;
84 panel.left_margin = conf->left_margin;
85 panel.right_margin = conf->right_margin;
86 panel.hsync = conf->hsync;
87 panel.xres = conf->xres;
88 panel.yres = conf->yres;
89
Stefan Reinauer80e62932013-07-29 15:52:23 -070090 printk(BIOS_SPEW, "LCD framebuffer @%p\n", (void *)(lcdbase));
Stefan Reinauer2d811252013-05-20 15:24:13 -070091 memset((void *)lcdbase, 0, fb_size); /* clear the framebuffer */
92
Gabe Black607c0b62013-05-16 05:45:57 -070093 /*
94 * We need to clean and invalidate the framebuffer region and disable
95 * caching as well. We assume that our dcache <--> memory address
96 * space is identity-mapped in 1MB chunks, so align accordingly.
97 *
98 * Note: We may want to do something clever to ensure the framebuffer
99 * region is aligned such that we don't change dcache policy for other
100 * stuff inadvertantly.
Gabe Black607c0b62013-05-16 05:45:57 -0700101 */
102 uint32_t lower = ALIGN_DOWN(lcdbase, MiB);
Stefan Reinauerf1751912013-05-20 15:17:44 -0700103 uint32_t upper = ALIGN_UP(lcdbase + fb_size, MiB);
Gabe Black607c0b62013-05-16 05:45:57 -0700104
Stefan Reinauer80e62932013-07-29 15:52:23 -0700105 dcache_clean_invalidate_by_mva(lower, upper - lower);
106 mmu_config_range(lower / MiB, (upper - lower) / MiB, DCACHE_OFF);
107
108 printk(BIOS_DEBUG, "Initializing Exynos LCD.\n");
109
Allen Martin681d17e2013-09-26 11:13:01 -0700110 lcd_ctrl_init(fb_size, &panel, (void *)lcdbase);
Gabe Black607c0b62013-05-16 05:45:57 -0700111}
112
Stefan Reinauer3a0d0d82013-06-20 16:13:19 -0700113static void cpu_enable(device_t dev)
Gabe Black607c0b62013-05-16 05:45:57 -0700114{
Stefan Reinauer80e62932013-07-29 15:52:23 -0700115 unsigned long fb_size = FB_SIZE_KB * KiB;
116 u32 lcdbase = get_fb_base_kb() * KiB;
Stefan Reinauer3a0d0d82013-06-20 16:13:19 -0700117
Stefan Reinauer80e62932013-07-29 15:52:23 -0700118 ram_resource(dev, 0, RAM_BASE_KB, RAM_SIZE_KB - FB_SIZE_KB);
119 mmio_resource(dev, 1, lcdbase / KiB, (fb_size + KiB - 1) / KiB);
120
121 exynos_displayport_init(dev, lcdbase, fb_size);
Gabe Black607c0b62013-05-16 05:45:57 -0700122
123 set_cpu_id();
Stefan Reinauer3a0d0d82013-06-20 16:13:19 -0700124}
125
126static void cpu_init(device_t dev)
127{
Gabe Black607c0b62013-05-16 05:45:57 -0700128 printk(BIOS_INFO, "CPU: S5P%X @ %ldMHz\n",
129 cpu_id, get_arm_clk() / (1024*1024));
Stefan Reinauer3a0d0d82013-06-20 16:13:19 -0700130
131 usb_init(dev);
Gabe Black607c0b62013-05-16 05:45:57 -0700132}
133
134static void cpu_noop(device_t dev)
135{
136}
137
138static struct device_operations cpu_ops = {
139 .read_resources = cpu_noop,
140 .set_resources = cpu_noop,
Stefan Reinauer3a0d0d82013-06-20 16:13:19 -0700141 .enable_resources = cpu_enable,
142 .init = cpu_init,
Gabe Black607c0b62013-05-16 05:45:57 -0700143 .scan_bus = 0,
144};
145
146static void enable_exynos5420_dev(device_t dev)
147{
148 dev->ops = &cpu_ops;
149}
150
151struct chip_operations cpu_samsung_exynos5420_ops = {
152 CHIP_NAME("CPU Samsung Exynos 5420")
153 .enable_dev = enable_exynos5420_dev,
154};
155
156void exynos5420_config_l2_cache(void)
157{
158 uint32_t val;
159
160 /*
161 * Bit 9 - L2 tag RAM setup (1 cycle)
162 * Bits 8:6 - L2 tag RAM latency (3 cycles)
163 * Bit 5 - L2 data RAM setup (1 cycle)
164 * Bits 2:0 - L2 data RAM latency (3 cycles)
165 */
166 val = (1 << 9) | (0x2 << 6) | (1 << 5) | (0x2);
167 write_l2ctlr(val);
168}