blob: 4fdb8f8e9c6547c07e51f4aafa8a59bb4743a686 [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.
Ronald G. Minnich01b43832013-08-05 17:18:44 -07005 * Copyright (C) 2012 Samsung Electronics
Stefan Reinauer08dc3572013-05-14 16:57:50 -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.
Stefan Reinauer08dc3572013-05-14 16:57:50 -070015 */
16
Julius Werner1ed0c8c2014-10-20 13:16:29 -070017#include <arch/cache.h>
Julius Werner1ed0c8c2014-10-20 13:16:29 -070018#include <console/console.h>
19#include <delay.h>
20#include <device/device.h>
21#include <soc/clk.h>
22#include <soc/cpu.h>
23#include <soc/dp-core.h>
24#include <soc/fimd.h>
25#include <stddef.h>
Ronald G. Minnichb48605d2013-04-09 14:35:35 -070026#include <stdlib.h>
27#include <string.h>
Julius Werner1ed0c8c2014-10-20 13:16:29 -070028
Stefan Reinauer08dc3572013-05-14 16:57:50 -070029#include "chip.h"
David Hendricks6802dc82013-02-15 16:18:28 -080030
Stefan Reinauer08dc3572013-05-14 16:57:50 -070031static unsigned int cpu_id;
32static unsigned int cpu_rev;
33
34static void set_cpu_id(void)
35{
Julius Werner2f37bd62015-02-19 14:51:15 -080036 cpu_id = read32((void *)EXYNOS5_PRO_ID);
Stefan Reinauer08dc3572013-05-14 16:57:50 -070037 cpu_id = (0xC000 | ((cpu_id & 0x00FFF000) >> 12));
38
39 /*
40 * 0xC200: EXYNOS4210 EVT0
41 * 0xC210: EXYNOS4210 EVT1
42 */
43 if (cpu_id == 0xC200) {
44 cpu_id |= 0x10;
45 cpu_rev = 0;
46 } else if (cpu_id == 0xC210) {
47 cpu_rev = 1;
48 }
49}
50
Ronald G. Minnichb48605d2013-04-09 14:35:35 -070051/* we distinguish a display port device from a raw graphics device
52 * because there are dramatic differences in startup depending on
53 * graphics usage. To make startup fast and easier to understand and
54 * debug we explicitly name this common case. The alternate approach,
55 * involving lots of machine and callbacks, is hard to debug and
56 * verify.
57 */
Elyes HAOUAS01115332018-05-25 09:15:21 +020058static void exynos_displayport_init(struct device *dev, u32 lcdbase,
Stefan Reinauer66287442013-06-19 15:54:19 -070059 unsigned long fb_size)
Ronald G. Minnichb48605d2013-04-09 14:35:35 -070060{
Hung-Te Lin22d0ca02013-09-27 12:45:45 +080061 struct soc_samsung_exynos5250_config *conf = dev->chip_info;
Ronald G. Minnichb48605d2013-04-09 14:35:35 -070062 /* put these on the stack. If, at some point, we want to move
63 * this code to a pre-ram stage, it will be much easier.
64 */
Ronald G. Minnichb48605d2013-04-09 14:35:35 -070065 struct exynos5_fimd_panel panel;
Ronald G. Minnichb48605d2013-04-09 14:35:35 -070066 memset(&panel, 0, sizeof(panel));
67
68 panel.is_dp = 1; /* Display I/F is eDP */
69 /* while it is true that we did a memset to zero,
70 * we leave some 'set to zero' entries here to make
71 * it clear what's going on. Graphics is confusing.
72 */
73 panel.is_mipi = 0;
74 panel.fixvclk = 0;
75 panel.ivclk = 0;
76 panel.clkval_f = conf->clkval_f;
77 panel.upper_margin = conf->upper_margin;
78 panel.lower_margin = conf->lower_margin;
79 panel.vsync = conf->vsync;
80 panel.left_margin = conf->left_margin;
81 panel.right_margin = conf->right_margin;
82 panel.hsync = conf->hsync;
Ronald G. Minnichd83c1172013-04-18 16:10:29 -070083 panel.xres = conf->xres;
84 panel.yres = conf->yres;
Ronald G. Minnichb48605d2013-04-09 14:35:35 -070085
Stefan Reinauer66287442013-06-19 15:54:19 -070086 printk(BIOS_SPEW, "LCD framebuffer @%p\n", (void *)(lcdbase));
Gabe Black39fda6d2013-05-18 23:06:47 -070087 memset((void *)lcdbase, 0, fb_size); /* clear the framebuffer */
88
Ronald G. Minnich2810afa2013-04-18 18:09:24 -070089 /*
90 * We need to clean and invalidate the framebuffer region and disable
91 * caching as well. We assume that our dcache <--> memory address
92 * space is identity-mapped in 1MB chunks, so align accordingly.
93 *
94 * Note: We may want to do something clever to ensure the framebuffer
95 * region is aligned such that we don't change dcache policy for other
Martin Roth4c3ab732013-07-08 16:23:54 -060096 * stuff inadvertently.
Ronald G. Minnich2810afa2013-04-18 18:09:24 -070097 */
98 uint32_t lower = ALIGN_DOWN(lcdbase, MiB);
Gabe Black1e797bd2013-05-18 15:58:46 -070099 uint32_t upper = ALIGN_UP(lcdbase + fb_size, MiB);
Ronald G. Minnich2810afa2013-04-18 18:09:24 -0700100
Julius Wernerf09f2242013-08-28 14:43:14 -0700101 dcache_clean_invalidate_by_mva((void *)lower, upper - lower);
Stefan Reinauer66287442013-06-19 15:54:19 -0700102 mmu_config_range(lower / MiB, (upper - lower) / MiB, DCACHE_OFF);
103
104 printk(BIOS_DEBUG, "Initializing Exynos LCD.\n");
105
Isaac Christensen0c0efa72014-09-17 16:14:18 -0600106 lcd_ctrl_init(fb_size, &panel, (void *)lcdbase);
Ronald G. Minnichb48605d2013-04-09 14:35:35 -0700107}
108
Elyes HAOUAS01115332018-05-25 09:15:21 +0200109static void cpu_enable(struct device *dev)
David Hendricks6802dc82013-02-15 16:18:28 -0800110{
Stefan Reinauer66287442013-06-19 15:54:19 -0700111 unsigned long fb_size = FB_SIZE_KB * KiB;
112 u32 lcdbase = get_fb_base_kb() * KiB;
Stefan Reinauer2ad63c22013-05-17 11:52:45 -0700113
Stefan Reinauer66287442013-06-19 15:54:19 -0700114 ram_resource(dev, 0, RAM_BASE_KB, RAM_SIZE_KB - FB_SIZE_KB);
Elyes HAOUAS6df3b642018-11-26 22:53:49 +0100115 mmio_resource(dev, 1, lcdbase / KiB, DIV_ROUND_UP(fb_size, KiB));
Stefan Reinauer66287442013-06-19 15:54:19 -0700116
117 exynos_displayport_init(dev, lcdbase, fb_size);
Stefan Reinauer043eb0e2013-05-10 16:21:58 -0700118
Stefan Reinauer08dc3572013-05-14 16:57:50 -0700119 set_cpu_id();
Stefan Reinauer2ad63c22013-05-17 11:52:45 -0700120}
121
Elyes HAOUAS01115332018-05-25 09:15:21 +0200122static void cpu_init(struct device *dev)
Stefan Reinauer2ad63c22013-05-17 11:52:45 -0700123{
Stefan Reinauer08dc3572013-05-14 16:57:50 -0700124 printk(BIOS_INFO, "CPU: S5P%X @ %ldMHz\n",
125 cpu_id, get_arm_clk() / (1024*1024));
David Hendricks6802dc82013-02-15 16:18:28 -0800126}
127
David Hendricks6802dc82013-02-15 16:18:28 -0800128static struct device_operations cpu_ops = {
Edward O'Callaghan0625a8b2014-10-31 08:03:16 +1100129 .read_resources = DEVICE_NOOP,
130 .set_resources = DEVICE_NOOP,
Stefan Reinauer2ad63c22013-05-17 11:52:45 -0700131 .enable_resources = cpu_enable,
132 .init = cpu_init,
David Hendricks6802dc82013-02-15 16:18:28 -0800133 .scan_bus = 0,
134};
135
Elyes HAOUAS01115332018-05-25 09:15:21 +0200136static void enable_exynos5250_dev(struct device *dev)
David Hendricks6802dc82013-02-15 16:18:28 -0800137{
Ronald G. Minnichb48605d2013-04-09 14:35:35 -0700138 dev->ops = &cpu_ops;
David Hendricks6802dc82013-02-15 16:18:28 -0800139}
140
Gabe Blackd81f4092013-10-08 23:16:51 -0700141struct chip_operations soc_samsung_exynos5250_ops = {
142 CHIP_NAME("SOC Samsung Exynos 5250")
Ronald G. Minnichb48605d2013-04-09 14:35:35 -0700143 .enable_dev = enable_exynos5250_dev,
David Hendricks6802dc82013-02-15 16:18:28 -0800144};
David Hendricksc01d1382013-03-28 19:04:58 -0700145
146void exynos5250_config_l2_cache(void)
147{
148 uint32_t val;
149
150 /*
151 * Bit 9 - L2 tag RAM setup (1 cycle)
152 * Bits 8:6 - L2 tag RAM latency (3 cycles)
153 * Bit 5 - L2 data RAM setup (1 cycle)
154 * Bits 2:0 - L2 data RAM latency (3 cycles)
155 */
156 val = (1 << 9) | (0x2 << 6) | (1 << 5) | (0x2);
157 write_l2ctlr(val);
158}