blob: 49e1692723c4ae8425ee4dc5e2f7d334b7dd06e8 [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{
David Hendricksd598cac2013-08-01 18:17:55 -070040 u32 pro_id = (read32((void *)EXYNOS_PRO_ID) & 0x00FFF000) >> 12;
Gabe Black607c0b62013-05-16 05:45:57 -070041
David Hendricksd598cac2013-08-01 18:17:55 -070042 switch (pro_id) {
43 case 0x200:
44 /* Exynos4210 EVT0 */
45 cpu_id = 0x4210;
Gabe Black607c0b62013-05-16 05:45:57 -070046 cpu_rev = 0;
David Hendricksd598cac2013-08-01 18:17:55 -070047 break;
48 case 0x210:
49 /* Exynos4210 EVT1 */
50 cpu_id = 0x4210;
51 break;
52 case 0x412:
53 /* Exynos4412 */
54 cpu_id = 0x4412;
55 break;
56 case 0x520:
57 /* Exynos5250 */
58 cpu_id = 0x5250;
59 break;
60 case 0x420:
61 /* Exynos5420 */
62 cpu_id = 0x5420;
63 break;
Gabe Black607c0b62013-05-16 05:45:57 -070064 }
65}
66
67/* we distinguish a display port device from a raw graphics device
68 * because there are dramatic differences in startup depending on
69 * graphics usage. To make startup fast and easier to understand and
70 * debug we explicitly name this common case. The alternate approach,
71 * involving lots of machine and callbacks, is hard to debug and
72 * verify.
73 */
Stefan Reinauer80e62932013-07-29 15:52:23 -070074static void exynos_displayport_init(device_t dev, u32 lcdbase,
75 unsigned long fb_size)
Gabe Black607c0b62013-05-16 05:45:57 -070076{
Gabe Black607c0b62013-05-16 05:45:57 -070077 struct cpu_samsung_exynos5420_config *conf = dev->chip_info;
78 /* put these on the stack. If, at some point, we want to move
79 * this code to a pre-ram stage, it will be much easier.
80 */
Gabe Black607c0b62013-05-16 05:45:57 -070081 struct exynos5_fimd_panel panel;
Gabe Black607c0b62013-05-16 05:45:57 -070082 memset(&panel, 0, sizeof(panel));
83
84 panel.is_dp = 1; /* Display I/F is eDP */
85 /* while it is true that we did a memset to zero,
86 * we leave some 'set to zero' entries here to make
87 * it clear what's going on. Graphics is confusing.
88 */
89 panel.is_mipi = 0;
90 panel.fixvclk = 0;
91 panel.ivclk = 0;
92 panel.clkval_f = conf->clkval_f;
93 panel.upper_margin = conf->upper_margin;
94 panel.lower_margin = conf->lower_margin;
95 panel.vsync = conf->vsync;
96 panel.left_margin = conf->left_margin;
97 panel.right_margin = conf->right_margin;
98 panel.hsync = conf->hsync;
99 panel.xres = conf->xres;
100 panel.yres = conf->yres;
101
Stefan Reinauer80e62932013-07-29 15:52:23 -0700102 printk(BIOS_SPEW, "LCD framebuffer @%p\n", (void *)(lcdbase));
Stefan Reinauer2d811252013-05-20 15:24:13 -0700103 memset((void *)lcdbase, 0, fb_size); /* clear the framebuffer */
104
Gabe Black607c0b62013-05-16 05:45:57 -0700105 /*
106 * We need to clean and invalidate the framebuffer region and disable
107 * caching as well. We assume that our dcache <--> memory address
108 * space is identity-mapped in 1MB chunks, so align accordingly.
109 *
110 * Note: We may want to do something clever to ensure the framebuffer
111 * region is aligned such that we don't change dcache policy for other
112 * stuff inadvertantly.
Gabe Black607c0b62013-05-16 05:45:57 -0700113 */
114 uint32_t lower = ALIGN_DOWN(lcdbase, MiB);
Stefan Reinauerf1751912013-05-20 15:17:44 -0700115 uint32_t upper = ALIGN_UP(lcdbase + fb_size, MiB);
Gabe Black607c0b62013-05-16 05:45:57 -0700116
Stefan Reinauer80e62932013-07-29 15:52:23 -0700117 dcache_clean_invalidate_by_mva(lower, upper - lower);
118 mmu_config_range(lower / MiB, (upper - lower) / MiB, DCACHE_OFF);
119
120 printk(BIOS_DEBUG, "Initializing Exynos LCD.\n");
121
Allen Martin681d17e2013-09-26 11:13:01 -0700122 lcd_ctrl_init(fb_size, &panel, (void *)lcdbase);
Gabe Black607c0b62013-05-16 05:45:57 -0700123}
124
Stefan Reinauer3a0d0d82013-06-20 16:13:19 -0700125static void cpu_enable(device_t dev)
Gabe Black607c0b62013-05-16 05:45:57 -0700126{
Stefan Reinauer80e62932013-07-29 15:52:23 -0700127 unsigned long fb_size = FB_SIZE_KB * KiB;
128 u32 lcdbase = get_fb_base_kb() * KiB;
Stefan Reinauer3a0d0d82013-06-20 16:13:19 -0700129
Stefan Reinauer80e62932013-07-29 15:52:23 -0700130 ram_resource(dev, 0, RAM_BASE_KB, RAM_SIZE_KB - FB_SIZE_KB);
131 mmio_resource(dev, 1, lcdbase / KiB, (fb_size + KiB - 1) / KiB);
132
133 exynos_displayport_init(dev, lcdbase, fb_size);
Gabe Black607c0b62013-05-16 05:45:57 -0700134
135 set_cpu_id();
Stefan Reinauer3a0d0d82013-06-20 16:13:19 -0700136}
137
138static void cpu_init(device_t dev)
139{
Gabe Black607c0b62013-05-16 05:45:57 -0700140 printk(BIOS_INFO, "CPU: S5P%X @ %ldMHz\n",
141 cpu_id, get_arm_clk() / (1024*1024));
Stefan Reinauer3a0d0d82013-06-20 16:13:19 -0700142
143 usb_init(dev);
Gabe Black607c0b62013-05-16 05:45:57 -0700144}
145
146static void cpu_noop(device_t dev)
147{
148}
149
150static struct device_operations cpu_ops = {
151 .read_resources = cpu_noop,
152 .set_resources = cpu_noop,
Stefan Reinauer3a0d0d82013-06-20 16:13:19 -0700153 .enable_resources = cpu_enable,
154 .init = cpu_init,
Gabe Black607c0b62013-05-16 05:45:57 -0700155 .scan_bus = 0,
156};
157
158static void enable_exynos5420_dev(device_t dev)
159{
160 dev->ops = &cpu_ops;
161}
162
163struct chip_operations cpu_samsung_exynos5420_ops = {
164 CHIP_NAME("CPU Samsung Exynos 5420")
165 .enable_dev = enable_exynos5420_dev,
166};
167
168void exynos5420_config_l2_cache(void)
169{
170 uint32_t val;
171
172 /*
173 * Bit 9 - L2 tag RAM setup (1 cycle)
174 * Bits 8:6 - L2 tag RAM latency (3 cycles)
175 * Bit 5 - L2 data RAM setup (1 cycle)
176 * Bits 2:0 - L2 data RAM latency (3 cycles)
177 */
178 val = (1 << 9) | (0x2 << 6) | (1 << 5) | (0x2);
179 write_l2ctlr(val);
180}