blob: 96e7dc361a33d3ea87c1335ce659990af6a603fd [file] [log] [blame]
Stefan Reinauer08dc3572013-05-14 16:57:50 -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
Ronald G. Minnichb48605d2013-04-09 14:35:35 -070020#include <stdlib.h>
21#include <string.h>
22#include <stddef.h>
23#include <delay.h>
David Hendricks6802dc82013-02-15 16:18:28 -080024#include <console/console.h>
25#include <device/device.h>
Ronald G. Minnichb48605d2013-04-09 14:35:35 -070026#include <cbmem.h>
Ronald G. Minnich2810afa2013-04-18 18:09:24 -070027#include <arch/cache.h>
Stefan Reinauer08dc3572013-05-14 16:57:50 -070028#include "fimd.h"
29#include "dp-core.h"
Ronald G. Minnichb48605d2013-04-09 14:35:35 -070030#include "cpu.h"
Stefan Reinauer08dc3572013-05-14 16:57:50 -070031#include "clk.h"
Stefan Reinauer2ad63c22013-05-17 11:52:45 -070032#include "usb.h"
Stefan Reinauer08dc3572013-05-14 16:57:50 -070033#include "chip.h"
David Hendricks6802dc82013-02-15 16:18:28 -080034
David Hendricks0f5a3fc2013-03-12 20:16:44 -070035#define RAM_BASE_KB (CONFIG_SYS_SDRAM_BASE >> 10)
36#define RAM_SIZE_KB (CONFIG_DRAM_SIZE_MB << 10UL)
David Hendricks6802dc82013-02-15 16:18:28 -080037
Stefan Reinauer08dc3572013-05-14 16:57:50 -070038static unsigned int cpu_id;
39static unsigned int cpu_rev;
40
41static void set_cpu_id(void)
42{
43 cpu_id = readl((void *)EXYNOS_PRO_ID);
44 cpu_id = (0xC000 | ((cpu_id & 0x00FFF000) >> 12));
45
46 /*
47 * 0xC200: EXYNOS4210 EVT0
48 * 0xC210: EXYNOS4210 EVT1
49 */
50 if (cpu_id == 0xC200) {
51 cpu_id |= 0x10;
52 cpu_rev = 0;
53 } else if (cpu_id == 0xC210) {
54 cpu_rev = 1;
55 }
56}
57
Ronald G. Minnichb48605d2013-04-09 14:35:35 -070058/* we distinguish a display port device from a raw graphics device
59 * because there are dramatic differences in startup depending on
60 * graphics usage. To make startup fast and easier to understand and
61 * debug we explicitly name this common case. The alternate approach,
62 * involving lots of machine and callbacks, is hard to debug and
63 * verify.
64 */
65static void exynos_displayport_init(device_t dev)
66{
67 int ret;
68 struct cpu_samsung_exynos5250_config *conf = dev->chip_info;
69 /* put these on the stack. If, at some point, we want to move
70 * this code to a pre-ram stage, it will be much easier.
71 */
Ronald G. Minnichb48605d2013-04-09 14:35:35 -070072 struct exynos5_fimd_panel panel;
73 unsigned long int fb_size;
74 u32 lcdbase;
75
Ronald G. Minnichb48605d2013-04-09 14:35:35 -070076 memset(&panel, 0, sizeof(panel));
77
78 panel.is_dp = 1; /* Display I/F is eDP */
79 /* while it is true that we did a memset to zero,
80 * we leave some 'set to zero' entries here to make
81 * it clear what's going on. Graphics is confusing.
82 */
83 panel.is_mipi = 0;
84 panel.fixvclk = 0;
85 panel.ivclk = 0;
86 panel.clkval_f = conf->clkval_f;
87 panel.upper_margin = conf->upper_margin;
88 panel.lower_margin = conf->lower_margin;
89 panel.vsync = conf->vsync;
90 panel.left_margin = conf->left_margin;
91 panel.right_margin = conf->right_margin;
92 panel.hsync = conf->hsync;
Ronald G. Minnichd83c1172013-04-18 16:10:29 -070093 panel.xres = conf->xres;
94 panel.yres = conf->yres;
Ronald G. Minnichb48605d2013-04-09 14:35:35 -070095
Gabe Black1e797bd2013-05-18 15:58:46 -070096 /* The size is a magic number from hardware. */
Ronald G. Minnich2810afa2013-04-18 18:09:24 -070097 fb_size = conf->xres * conf->yres * (conf->bpp / 8);
Gabe Black1e797bd2013-05-18 15:58:46 -070098 lcdbase = (uintptr_t)cbmem_add(CBMEM_ID_CONSOLE, fb_size);
99 printk(BIOS_SPEW, "LCD framebuffer base is %p\n", (void *)(lcdbase));
Ronald G. Minnichb48605d2013-04-09 14:35:35 -0700100
Gabe Black39fda6d2013-05-18 23:06:47 -0700101 memset((void *)lcdbase, 0, fb_size); /* clear the framebuffer */
102
Ronald G. Minnich2810afa2013-04-18 18:09:24 -0700103 /*
104 * We need to clean and invalidate the framebuffer region and disable
105 * caching as well. We assume that our dcache <--> memory address
106 * space is identity-mapped in 1MB chunks, so align accordingly.
107 *
108 * Note: We may want to do something clever to ensure the framebuffer
109 * region is aligned such that we don't change dcache policy for other
110 * stuff inadvertantly.
Ronald G. Minnich2810afa2013-04-18 18:09:24 -0700111 */
112 uint32_t lower = ALIGN_DOWN(lcdbase, MiB);
Gabe Black1e797bd2013-05-18 15:58:46 -0700113 uint32_t upper = ALIGN_UP(lcdbase + fb_size, MiB);
Ronald G. Minnich2810afa2013-04-18 18:09:24 -0700114 dcache_clean_invalidate_by_mva(lower, upper - lower);
Ronald G. Minnich2810afa2013-04-18 18:09:24 -0700115 mmu_config_range(lower/MiB, (upper - lower)/MiB, DCACHE_OFF);
Ronald G. Minnich2810afa2013-04-18 18:09:24 -0700116
Ronald G. Minniche8a91342013-04-22 10:46:53 -0700117 mmio_resource(dev, 1, lcdbase/KiB, (fb_size + KiB - 1)/KiB);
Ronald G. Minnichb48605d2013-04-09 14:35:35 -0700118 printk(BIOS_DEBUG,
Stefan Reinauer08dc3572013-05-14 16:57:50 -0700119 "Initializing Exynos VGA, base %p\n", (void *)lcdbase);
Gabe Black1e797bd2013-05-18 15:58:46 -0700120 ret = lcd_ctrl_init(fb_size, &panel, (void *)lcdbase);
Ronald G. Minnichb48605d2013-04-09 14:35:35 -0700121}
122
Stefan Reinauer2ad63c22013-05-17 11:52:45 -0700123static void cpu_enable(device_t dev)
David Hendricks6802dc82013-02-15 16:18:28 -0800124{
Ronald G. Minnichb48605d2013-04-09 14:35:35 -0700125 exynos_displayport_init(dev);
Stefan Reinauer2ad63c22013-05-17 11:52:45 -0700126
David Hendricks3cc0d1e2013-03-26 16:28:21 -0700127 ram_resource(dev, 0, RAM_BASE_KB, RAM_SIZE_KB);
Stefan Reinauer043eb0e2013-05-10 16:21:58 -0700128
Stefan Reinauer08dc3572013-05-14 16:57:50 -0700129 set_cpu_id();
130
Stefan Reinauer2ad63c22013-05-17 11:52:45 -0700131}
132
133static void cpu_init(device_t dev)
134{
Stefan Reinauer08dc3572013-05-14 16:57:50 -0700135 printk(BIOS_INFO, "CPU: S5P%X @ %ldMHz\n",
136 cpu_id, get_arm_clk() / (1024*1024));
Stefan Reinauer2ad63c22013-05-17 11:52:45 -0700137
138 usb_init(dev);
David Hendricks6802dc82013-02-15 16:18:28 -0800139}
140
141static void cpu_noop(device_t dev)
142{
143}
144
145static struct device_operations cpu_ops = {
146 .read_resources = cpu_noop,
147 .set_resources = cpu_noop,
Stefan Reinauer2ad63c22013-05-17 11:52:45 -0700148 .enable_resources = cpu_enable,
149 .init = cpu_init,
David Hendricks6802dc82013-02-15 16:18:28 -0800150 .scan_bus = 0,
151};
152
Ronald G. Minnichb48605d2013-04-09 14:35:35 -0700153static void enable_exynos5250_dev(device_t dev)
David Hendricks6802dc82013-02-15 16:18:28 -0800154{
Ronald G. Minnichb48605d2013-04-09 14:35:35 -0700155 dev->ops = &cpu_ops;
David Hendricks6802dc82013-02-15 16:18:28 -0800156}
157
158struct chip_operations cpu_samsung_exynos5250_ops = {
159 CHIP_NAME("CPU Samsung Exynos 5250")
Ronald G. Minnichb48605d2013-04-09 14:35:35 -0700160 .enable_dev = enable_exynos5250_dev,
David Hendricks6802dc82013-02-15 16:18:28 -0800161};
David Hendricksc01d1382013-03-28 19:04:58 -0700162
163void exynos5250_config_l2_cache(void)
164{
165 uint32_t val;
166
167 /*
168 * Bit 9 - L2 tag RAM setup (1 cycle)
169 * Bits 8:6 - L2 tag RAM latency (3 cycles)
170 * Bit 5 - L2 data RAM setup (1 cycle)
171 * Bits 2:0 - L2 data RAM latency (3 cycles)
172 */
173 val = (1 << 9) | (0x2 << 6) | (1 << 5) | (0x2);
174 write_l2ctlr(val);
175}