blob: bda46de63dbf931f046326cb5ad536058430a2d1 [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.
Ronald G. Minnichb0efbd32013-08-05 15:56:37 -07005 * Copyright (C) 2012 Samsung Electronics
Gabe Black607c0b62013-05-16 05:45:57 -07006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <stdlib.h>
22#include <string.h>
23#include <stddef.h>
24#include <delay.h>
25#include <console/console.h>
26#include <device/device.h>
27#include <cbmem.h>
28#include <arch/cache.h>
Ronald G. Minnichc0d5eb22013-08-01 11:38:05 -070029#include "dp.h"
Gabe Black607c0b62013-05-16 05:45:57 -070030#include "fimd.h"
Gabe Black607c0b62013-05-16 05:45:57 -070031#include "cpu.h"
32#include "clk.h"
Stefan Reinauer3a0d0d82013-06-20 16:13:19 -070033#include "usb.h"
Gabe Black607c0b62013-05-16 05:45:57 -070034#include "chip.h"
35
Gabe Black607c0b62013-05-16 05:45:57 -070036static unsigned int cpu_id;
37static unsigned int cpu_rev;
38
Ronald G. Minnichb0efbd32013-08-05 15:56:37 -070039/* Setting TZPC[TrustZone Protection Controller]
40 * We pretty much disable it all, as the kernel
41 * expects it that way -- and that's not the default.
42 */
43static void tzpc_init(void)
44{
45 struct exynos_tzpc *tzpc;
46 unsigned int addr;
47
48 for (addr = TZPC10_BASE; addr <= TZPC9_BASE; addr += TZPC_BASE_OFFSET) {
49 tzpc = (struct exynos_tzpc *)addr;
50 if (addr == TZPC0_BASE)
51 writel(R0SIZE, &tzpc->r0size);
52 writel(DECPROTXSET, &tzpc->decprot0set);
53 writel(DECPROTXSET, &tzpc->decprot1set);
54 writel(DECPROTXSET, &tzpc->decprot2set);
55 writel(DECPROTXSET, &tzpc->decprot3set);
56 }
57}
58
Gabe Black607c0b62013-05-16 05:45:57 -070059static void set_cpu_id(void)
60{
David Hendricksd598cac2013-08-01 18:17:55 -070061 u32 pro_id = (read32((void *)EXYNOS_PRO_ID) & 0x00FFF000) >> 12;
Gabe Black607c0b62013-05-16 05:45:57 -070062
David Hendricksd598cac2013-08-01 18:17:55 -070063 switch (pro_id) {
64 case 0x200:
65 /* Exynos4210 EVT0 */
66 cpu_id = 0x4210;
Gabe Black607c0b62013-05-16 05:45:57 -070067 cpu_rev = 0;
David Hendricksd598cac2013-08-01 18:17:55 -070068 break;
69 case 0x210:
70 /* Exynos4210 EVT1 */
71 cpu_id = 0x4210;
72 break;
73 case 0x412:
74 /* Exynos4412 */
75 cpu_id = 0x4412;
76 break;
77 case 0x520:
78 /* Exynos5250 */
79 cpu_id = 0x5250;
80 break;
81 case 0x420:
82 /* Exynos5420 */
83 cpu_id = 0x5420;
84 break;
Gabe Black607c0b62013-05-16 05:45:57 -070085 }
86}
87
88/* we distinguish a display port device from a raw graphics device
89 * because there are dramatic differences in startup depending on
90 * graphics usage. To make startup fast and easier to understand and
91 * debug we explicitly name this common case. The alternate approach,
92 * involving lots of machine and callbacks, is hard to debug and
93 * verify.
94 */
Stefan Reinauer80e62932013-07-29 15:52:23 -070095static void exynos_displayport_init(device_t dev, u32 lcdbase,
96 unsigned long fb_size)
Gabe Black607c0b62013-05-16 05:45:57 -070097{
Gabe Black607c0b62013-05-16 05:45:57 -070098 struct cpu_samsung_exynos5420_config *conf = dev->chip_info;
99 /* put these on the stack. If, at some point, we want to move
100 * this code to a pre-ram stage, it will be much easier.
101 */
Gabe Black607c0b62013-05-16 05:45:57 -0700102 struct exynos5_fimd_panel panel;
Gabe Black607c0b62013-05-16 05:45:57 -0700103 memset(&panel, 0, sizeof(panel));
104
105 panel.is_dp = 1; /* Display I/F is eDP */
106 /* while it is true that we did a memset to zero,
107 * we leave some 'set to zero' entries here to make
108 * it clear what's going on. Graphics is confusing.
109 */
110 panel.is_mipi = 0;
111 panel.fixvclk = 0;
112 panel.ivclk = 0;
113 panel.clkval_f = conf->clkval_f;
114 panel.upper_margin = conf->upper_margin;
115 panel.lower_margin = conf->lower_margin;
116 panel.vsync = conf->vsync;
117 panel.left_margin = conf->left_margin;
118 panel.right_margin = conf->right_margin;
119 panel.hsync = conf->hsync;
120 panel.xres = conf->xres;
121 panel.yres = conf->yres;
122
Stefan Reinauer80e62932013-07-29 15:52:23 -0700123 printk(BIOS_SPEW, "LCD framebuffer @%p\n", (void *)(lcdbase));
Stefan Reinauer2d811252013-05-20 15:24:13 -0700124 memset((void *)lcdbase, 0, fb_size); /* clear the framebuffer */
125
Gabe Black607c0b62013-05-16 05:45:57 -0700126 /*
127 * We need to clean and invalidate the framebuffer region and disable
128 * caching as well. We assume that our dcache <--> memory address
129 * space is identity-mapped in 1MB chunks, so align accordingly.
130 *
131 * Note: We may want to do something clever to ensure the framebuffer
132 * region is aligned such that we don't change dcache policy for other
133 * stuff inadvertantly.
Gabe Black607c0b62013-05-16 05:45:57 -0700134 */
135 uint32_t lower = ALIGN_DOWN(lcdbase, MiB);
Stefan Reinauerf1751912013-05-20 15:17:44 -0700136 uint32_t upper = ALIGN_UP(lcdbase + fb_size, MiB);
Gabe Black607c0b62013-05-16 05:45:57 -0700137
Stefan Reinauer80e62932013-07-29 15:52:23 -0700138 dcache_clean_invalidate_by_mva(lower, upper - lower);
139 mmu_config_range(lower / MiB, (upper - lower) / MiB, DCACHE_OFF);
140
Ronald G. Minnichc0d5eb22013-08-01 11:38:05 -0700141 mmio_resource(dev, 1, lcdbase/KiB, (fb_size + KiB - 1)/KiB);
Gabe Black607c0b62013-05-16 05:45:57 -0700142}
143
Stefan Reinauer3a0d0d82013-06-20 16:13:19 -0700144static void cpu_enable(device_t dev)
Gabe Black607c0b62013-05-16 05:45:57 -0700145{
Stefan Reinauer80e62932013-07-29 15:52:23 -0700146 unsigned long fb_size = FB_SIZE_KB * KiB;
147 u32 lcdbase = get_fb_base_kb() * KiB;
Stefan Reinauer3a0d0d82013-06-20 16:13:19 -0700148
Stefan Reinauer80e62932013-07-29 15:52:23 -0700149 ram_resource(dev, 0, RAM_BASE_KB, RAM_SIZE_KB - FB_SIZE_KB);
150 mmio_resource(dev, 1, lcdbase / KiB, (fb_size + KiB - 1) / KiB);
151
152 exynos_displayport_init(dev, lcdbase, fb_size);
Gabe Black607c0b62013-05-16 05:45:57 -0700153
154 set_cpu_id();
Ronald G. Minnichb0efbd32013-08-05 15:56:37 -0700155
156 tzpc_init();
Stefan Reinauer3a0d0d82013-06-20 16:13:19 -0700157}
158
159static void cpu_init(device_t dev)
160{
Gabe Black607c0b62013-05-16 05:45:57 -0700161 printk(BIOS_INFO, "CPU: S5P%X @ %ldMHz\n",
David Hendricks56a7cff2013-08-05 18:53:15 -0700162 cpu_id, get_arm_clk() / 1000000);
Stefan Reinauer3a0d0d82013-06-20 16:13:19 -0700163
164 usb_init(dev);
Gabe Black607c0b62013-05-16 05:45:57 -0700165}
166
167static void cpu_noop(device_t dev)
168{
169}
170
171static struct device_operations cpu_ops = {
172 .read_resources = cpu_noop,
173 .set_resources = cpu_noop,
Stefan Reinauer3a0d0d82013-06-20 16:13:19 -0700174 .enable_resources = cpu_enable,
175 .init = cpu_init,
Gabe Black607c0b62013-05-16 05:45:57 -0700176 .scan_bus = 0,
177};
178
179static void enable_exynos5420_dev(device_t dev)
180{
181 dev->ops = &cpu_ops;
182}
183
184struct chip_operations cpu_samsung_exynos5420_ops = {
185 CHIP_NAME("CPU Samsung Exynos 5420")
186 .enable_dev = enable_exynos5420_dev,
187};
188
189void exynos5420_config_l2_cache(void)
190{
191 uint32_t val;
192
193 /*
194 * Bit 9 - L2 tag RAM setup (1 cycle)
195 * Bits 8:6 - L2 tag RAM latency (3 cycles)
196 * Bit 5 - L2 data RAM setup (1 cycle)
197 * Bits 2:0 - L2 data RAM latency (3 cycles)
198 */
199 val = (1 << 9) | (0x2 << 6) | (1 << 5) | (0x2);
200 write_l2ctlr(val);
David Hendricks49c1be92013-08-06 18:05:55 -0700201
202 val = read_l2actlr();
203
204 /* L2ACTLR[3]: Disable clean/evict push to external */
205 val |= (1 << 3);
206
207 /* L2ACTLR[7]: Enable hazard detect timeout for A15 */
208 val |= (1 << 7);
209
210 /* L2ACTLR[27]: Prevents stopping the L2 logic clock */
211 val |= (1 << 27);
212
213 write_l2actlr(val);
214
215 /* Read the l2 control register to force things to take effect? */
216 val = read_l2ctlr();
Gabe Black607c0b62013-05-16 05:45:57 -0700217}