blob: e6c43eabb4190346b05a92df2ad800503260239d [file] [log] [blame]
Angel Pons1ddb8942020-04-04 18:51:26 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauer08dc3572013-05-14 16:57:50 -07002
Julius Werner1ed0c8c2014-10-20 13:16:29 -07003#include <arch/cache.h>
Julius Werner1ed0c8c2014-10-20 13:16:29 -07004#include <console/console.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02005#include <device/mmio.h>
Julius Werner1ed0c8c2014-10-20 13:16:29 -07006#include <device/device.h>
7#include <soc/clk.h>
8#include <soc/cpu.h>
9#include <soc/dp-core.h>
10#include <soc/fimd.h>
Ronald G. Minnichb48605d2013-04-09 14:35:35 -070011#include <string.h>
Julius Werner1ed0c8c2014-10-20 13:16:29 -070012
Stefan Reinauer08dc3572013-05-14 16:57:50 -070013#include "chip.h"
David Hendricks6802dc82013-02-15 16:18:28 -080014
Stefan Reinauer08dc3572013-05-14 16:57:50 -070015static unsigned int cpu_id;
16static unsigned int cpu_rev;
17
18static void set_cpu_id(void)
19{
Julius Werner2f37bd62015-02-19 14:51:15 -080020 cpu_id = read32((void *)EXYNOS5_PRO_ID);
Stefan Reinauer08dc3572013-05-14 16:57:50 -070021 cpu_id = (0xC000 | ((cpu_id & 0x00FFF000) >> 12));
22
23 /*
24 * 0xC200: EXYNOS4210 EVT0
25 * 0xC210: EXYNOS4210 EVT1
26 */
27 if (cpu_id == 0xC200) {
28 cpu_id |= 0x10;
29 cpu_rev = 0;
30 } else if (cpu_id == 0xC210) {
31 cpu_rev = 1;
32 }
33}
34
Ronald G. Minnichb48605d2013-04-09 14:35:35 -070035/* we distinguish a display port device from a raw graphics device
36 * because there are dramatic differences in startup depending on
37 * graphics usage. To make startup fast and easier to understand and
38 * debug we explicitly name this common case. The alternate approach,
39 * involving lots of machine and callbacks, is hard to debug and
40 * verify.
41 */
Elyes HAOUAS01115332018-05-25 09:15:21 +020042static void exynos_displayport_init(struct device *dev, u32 lcdbase,
Stefan Reinauer66287442013-06-19 15:54:19 -070043 unsigned long fb_size)
Ronald G. Minnichb48605d2013-04-09 14:35:35 -070044{
Hung-Te Lin22d0ca02013-09-27 12:45:45 +080045 struct soc_samsung_exynos5250_config *conf = dev->chip_info;
Ronald G. Minnichb48605d2013-04-09 14:35:35 -070046 /* put these on the stack. If, at some point, we want to move
47 * this code to a pre-ram stage, it will be much easier.
48 */
Ronald G. Minnichb48605d2013-04-09 14:35:35 -070049 struct exynos5_fimd_panel panel;
Ronald G. Minnichb48605d2013-04-09 14:35:35 -070050 memset(&panel, 0, sizeof(panel));
51
52 panel.is_dp = 1; /* Display I/F is eDP */
53 /* while it is true that we did a memset to zero,
54 * we leave some 'set to zero' entries here to make
55 * it clear what's going on. Graphics is confusing.
56 */
57 panel.is_mipi = 0;
58 panel.fixvclk = 0;
59 panel.ivclk = 0;
60 panel.clkval_f = conf->clkval_f;
61 panel.upper_margin = conf->upper_margin;
62 panel.lower_margin = conf->lower_margin;
63 panel.vsync = conf->vsync;
64 panel.left_margin = conf->left_margin;
65 panel.right_margin = conf->right_margin;
66 panel.hsync = conf->hsync;
Ronald G. Minnichd83c1172013-04-18 16:10:29 -070067 panel.xres = conf->xres;
68 panel.yres = conf->yres;
Ronald G. Minnichb48605d2013-04-09 14:35:35 -070069
Stefan Reinauer66287442013-06-19 15:54:19 -070070 printk(BIOS_SPEW, "LCD framebuffer @%p\n", (void *)(lcdbase));
Gabe Black39fda6d2013-05-18 23:06:47 -070071 memset((void *)lcdbase, 0, fb_size); /* clear the framebuffer */
72
Ronald G. Minnich2810afa2013-04-18 18:09:24 -070073 /*
74 * We need to clean and invalidate the framebuffer region and disable
75 * caching as well. We assume that our dcache <--> memory address
76 * space is identity-mapped in 1MB chunks, so align accordingly.
77 *
78 * Note: We may want to do something clever to ensure the framebuffer
79 * region is aligned such that we don't change dcache policy for other
Martin Roth4c3ab732013-07-08 16:23:54 -060080 * stuff inadvertently.
Ronald G. Minnich2810afa2013-04-18 18:09:24 -070081 */
82 uint32_t lower = ALIGN_DOWN(lcdbase, MiB);
Gabe Black1e797bd2013-05-18 15:58:46 -070083 uint32_t upper = ALIGN_UP(lcdbase + fb_size, MiB);
Ronald G. Minnich2810afa2013-04-18 18:09:24 -070084
Julius Wernerf09f2242013-08-28 14:43:14 -070085 dcache_clean_invalidate_by_mva((void *)lower, upper - lower);
Stefan Reinauer66287442013-06-19 15:54:19 -070086 mmu_config_range(lower / MiB, (upper - lower) / MiB, DCACHE_OFF);
87
88 printk(BIOS_DEBUG, "Initializing Exynos LCD.\n");
89
Isaac Christensen0c0efa72014-09-17 16:14:18 -060090 lcd_ctrl_init(fb_size, &panel, (void *)lcdbase);
Ronald G. Minnichb48605d2013-04-09 14:35:35 -070091}
92
Elyes HAOUAS01115332018-05-25 09:15:21 +020093static void cpu_enable(struct device *dev)
David Hendricks6802dc82013-02-15 16:18:28 -080094{
Stefan Reinauer66287442013-06-19 15:54:19 -070095 unsigned long fb_size = FB_SIZE_KB * KiB;
96 u32 lcdbase = get_fb_base_kb() * KiB;
Stefan Reinauer2ad63c22013-05-17 11:52:45 -070097
Stefan Reinauer66287442013-06-19 15:54:19 -070098 exynos_displayport_init(dev, lcdbase, fb_size);
Stefan Reinauer043eb0e2013-05-10 16:21:58 -070099
Stefan Reinauer08dc3572013-05-14 16:57:50 -0700100 set_cpu_id();
Stefan Reinauer2ad63c22013-05-17 11:52:45 -0700101}
102
Furquan Shaikhd6973e82020-05-13 12:21:06 -0700103static void cpu_read_resources(struct device *dev)
104{
105 unsigned long fb_size = FB_SIZE_KB * KiB;
106 u32 lcdbase = get_fb_base_kb() * KiB;
107
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300108 ram_resource_kb(dev, 0, RAM_BASE_KB, RAM_SIZE_KB - FB_SIZE_KB);
109 mmio_resource_kb(dev, 1, lcdbase / KiB, DIV_ROUND_UP(fb_size, KiB));
Furquan Shaikhd6973e82020-05-13 12:21:06 -0700110}
111
Elyes HAOUAS01115332018-05-25 09:15:21 +0200112static void cpu_init(struct device *dev)
Stefan Reinauer2ad63c22013-05-17 11:52:45 -0700113{
Stefan Reinauer08dc3572013-05-14 16:57:50 -0700114 printk(BIOS_INFO, "CPU: S5P%X @ %ldMHz\n",
115 cpu_id, get_arm_clk() / (1024*1024));
David Hendricks6802dc82013-02-15 16:18:28 -0800116}
117
David Hendricks6802dc82013-02-15 16:18:28 -0800118static struct device_operations cpu_ops = {
Furquan Shaikhd6973e82020-05-13 12:21:06 -0700119 .read_resources = cpu_read_resources,
Nico Huber2f8ba692020-04-05 14:05:24 +0200120 .set_resources = noop_set_resources,
Stefan Reinauer2ad63c22013-05-17 11:52:45 -0700121 .enable_resources = cpu_enable,
122 .init = cpu_init,
David Hendricks6802dc82013-02-15 16:18:28 -0800123};
124
Elyes HAOUAS01115332018-05-25 09:15:21 +0200125static void enable_exynos5250_dev(struct device *dev)
David Hendricks6802dc82013-02-15 16:18:28 -0800126{
Ronald G. Minnichb48605d2013-04-09 14:35:35 -0700127 dev->ops = &cpu_ops;
David Hendricks6802dc82013-02-15 16:18:28 -0800128}
129
Gabe Blackd81f4092013-10-08 23:16:51 -0700130struct chip_operations soc_samsung_exynos5250_ops = {
131 CHIP_NAME("SOC Samsung Exynos 5250")
Ronald G. Minnichb48605d2013-04-09 14:35:35 -0700132 .enable_dev = enable_exynos5250_dev,
David Hendricks6802dc82013-02-15 16:18:28 -0800133};
David Hendricksc01d1382013-03-28 19:04:58 -0700134
135void exynos5250_config_l2_cache(void)
136{
137 uint32_t val;
138
139 /*
140 * Bit 9 - L2 tag RAM setup (1 cycle)
141 * Bits 8:6 - L2 tag RAM latency (3 cycles)
142 * Bit 5 - L2 data RAM setup (1 cycle)
143 * Bits 2:0 - L2 data RAM latency (3 cycles)
144 */
145 val = (1 << 9) | (0x2 << 6) | (1 << 5) | (0x2);
146 write_l2ctlr(val);
147}