blob: dd27730dc1c942f8e6bd33a0fc96310f4b60e09a [file] [log] [blame]
Angel Pons1ddb8942020-04-04 18:51:26 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Gabe Black607c0b62013-05-16 05:45:57 -07003
Julius Werner80af4422014-10-20 13:18:56 -07004#include <arch/cache.h>
Julius Werner80af4422014-10-20 13:18:56 -07005#include <console/console.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02006#include <device/mmio.h>
Julius Werner80af4422014-10-20 13:18:56 -07007#include <device/device.h>
8#include <ec/google/chromeec/ec.h>
9#include <soc/dp.h>
10#include <soc/fimd.h>
11#include <soc/cpu.h>
12#include <soc/clk.h>
13#include <stddef.h>
Gabe Black607c0b62013-05-16 05:45:57 -070014#include <string.h>
Gabe Black607c0b62013-05-16 05:45:57 -070015
Julius Werner80af4422014-10-20 13:18:56 -070016#include "chip.h"
David Hendricksc81187f2013-08-01 19:09:21 -070017
Gabe Black607c0b62013-05-16 05:45:57 -070018static unsigned int cpu_id;
19static unsigned int cpu_rev;
20
21static void set_cpu_id(void)
22{
Julius Wernerfa938c72013-08-29 14:17:36 -070023 u32 pro_id = (read32((void *)EXYNOS5_PRO_ID) & 0x00FFF000) >> 12;
Gabe Black607c0b62013-05-16 05:45:57 -070024
David Hendricksd598cac2013-08-01 18:17:55 -070025 switch (pro_id) {
26 case 0x200:
27 /* Exynos4210 EVT0 */
28 cpu_id = 0x4210;
Gabe Black607c0b62013-05-16 05:45:57 -070029 cpu_rev = 0;
David Hendricksd598cac2013-08-01 18:17:55 -070030 break;
31 case 0x210:
32 /* Exynos4210 EVT1 */
33 cpu_id = 0x4210;
34 break;
35 case 0x412:
36 /* Exynos4412 */
37 cpu_id = 0x4412;
38 break;
39 case 0x520:
40 /* Exynos5250 */
41 cpu_id = 0x5250;
42 break;
43 case 0x420:
44 /* Exynos5420 */
45 cpu_id = 0x5420;
46 break;
Gabe Black607c0b62013-05-16 05:45:57 -070047 }
48}
49
50/* we distinguish a display port device from a raw graphics device
51 * because there are dramatic differences in startup depending on
52 * graphics usage. To make startup fast and easier to understand and
53 * debug we explicitly name this common case. The alternate approach,
54 * involving lots of machine and callbacks, is hard to debug and
55 * verify.
56 */
Elyes HAOUAS01115332018-05-25 09:15:21 +020057static void exynos_displayport_init(struct device *dev, u32 lcdbase,
Stefan Reinauer80e62932013-07-29 15:52:23 -070058 unsigned long fb_size)
Gabe Black607c0b62013-05-16 05:45:57 -070059{
Hung-Te Lin22d0ca02013-09-27 12:45:45 +080060 struct soc_samsung_exynos5420_config *conf = dev->chip_info;
Gabe Black607c0b62013-05-16 05:45:57 -070061 /* put these on the stack. If, at some point, we want to move
62 * this code to a pre-ram stage, it will be much easier.
63 */
Gabe Black607c0b62013-05-16 05:45:57 -070064 struct exynos5_fimd_panel panel;
Gabe Black607c0b62013-05-16 05:45:57 -070065 memset(&panel, 0, sizeof(panel));
66
67 panel.is_dp = 1; /* Display I/F is eDP */
68 /* while it is true that we did a memset to zero,
69 * we leave some 'set to zero' entries here to make
70 * it clear what's going on. Graphics is confusing.
71 */
72 panel.is_mipi = 0;
73 panel.fixvclk = 0;
74 panel.ivclk = 0;
75 panel.clkval_f = conf->clkval_f;
76 panel.upper_margin = conf->upper_margin;
77 panel.lower_margin = conf->lower_margin;
78 panel.vsync = conf->vsync;
79 panel.left_margin = conf->left_margin;
80 panel.right_margin = conf->right_margin;
81 panel.hsync = conf->hsync;
82 panel.xres = conf->xres;
83 panel.yres = conf->yres;
84
Stefan Reinauer80e62932013-07-29 15:52:23 -070085 printk(BIOS_SPEW, "LCD framebuffer @%p\n", (void *)(lcdbase));
Stefan Reinauer2d811252013-05-20 15:24:13 -070086 memset((void *)lcdbase, 0, fb_size); /* clear the framebuffer */
87
Gabe Black607c0b62013-05-16 05:45:57 -070088 /*
89 * We need to clean and invalidate the framebuffer region and disable
90 * caching as well. We assume that our dcache <--> memory address
91 * space is identity-mapped in 1MB chunks, so align accordingly.
92 *
93 * Note: We may want to do something clever to ensure the framebuffer
94 * region is aligned such that we don't change dcache policy for other
Martin Roth1fc2ba52014-12-07 14:59:11 -070095 * stuff inadvertently.
Gabe Black607c0b62013-05-16 05:45:57 -070096 */
97 uint32_t lower = ALIGN_DOWN(lcdbase, MiB);
Stefan Reinauerf1751912013-05-20 15:17:44 -070098 uint32_t upper = ALIGN_UP(lcdbase + fb_size, MiB);
Gabe Black607c0b62013-05-16 05:45:57 -070099
Julius Wernerf09f2242013-08-28 14:43:14 -0700100 dcache_clean_invalidate_by_mva((void *)lower, upper - lower);
Stefan Reinauer80e62932013-07-29 15:52:23 -0700101 mmu_config_range(lower / MiB, (upper - lower) / MiB, DCACHE_OFF);
102
Elyes HAOUAS6df3b642018-11-26 22:53:49 +0100103 mmio_resource(dev, 1, lcdbase/KiB, DIV_ROUND_UP(fb_size, KiB));
Gabe Black607c0b62013-05-16 05:45:57 -0700104}
105
David Hendricksc81187f2013-08-01 19:09:21 -0700106static void tps65090_thru_ec_fet_disable(int index)
107{
108 uint8_t value = 0;
109
110 if (google_chromeec_i2c_xfer(0x48, 0xe + index, 1, &value, 1, 0)) {
111 printk(BIOS_ERR,
112 "Error sending i2c pass through command to EC.\n");
113 return;
114 }
115}
116
Elyes HAOUAS01115332018-05-25 09:15:21 +0200117static void cpu_enable(struct device *dev)
Gabe Black607c0b62013-05-16 05:45:57 -0700118{
Stefan Reinauer80e62932013-07-29 15:52:23 -0700119 unsigned long fb_size = FB_SIZE_KB * KiB;
120 u32 lcdbase = get_fb_base_kb() * KiB;
Stefan Reinauer3a0d0d82013-06-20 16:13:19 -0700121
Stefan Reinauer80e62932013-07-29 15:52:23 -0700122 ram_resource(dev, 0, RAM_BASE_KB, RAM_SIZE_KB - FB_SIZE_KB);
Elyes HAOUAS6df3b642018-11-26 22:53:49 +0100123 mmio_resource(dev, 1, lcdbase / KiB, DIV_ROUND_UP(fb_size, KiB));
Stefan Reinauer80e62932013-07-29 15:52:23 -0700124
David Hendricksc81187f2013-08-01 19:09:21 -0700125 /*
126 * Disable LCD FETs before we do anything with the display.
127 * FIXME(dhendrix): This is a gross hack and should be done
128 * elsewhere (romstage?).
129 */
130 tps65090_thru_ec_fet_disable(1);
131 tps65090_thru_ec_fet_disable(6);
132
Stefan Reinauer80e62932013-07-29 15:52:23 -0700133 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
Elyes HAOUAS01115332018-05-25 09:15:21 +0200138static void cpu_init(struct device *dev)
Stefan Reinauer3a0d0d82013-06-20 16:13:19 -0700139{
Gabe Black607c0b62013-05-16 05:45:57 -0700140 printk(BIOS_INFO, "CPU: S5P%X @ %ldMHz\n",
David Hendricks56a7cff2013-08-05 18:53:15 -0700141 cpu_id, get_arm_clk() / 1000000);
Gabe Black607c0b62013-05-16 05:45:57 -0700142}
143
Gabe Black607c0b62013-05-16 05:45:57 -0700144static struct device_operations cpu_ops = {
Edward O'Callaghan0625a8b2014-10-31 08:03:16 +1100145 .read_resources = DEVICE_NOOP,
146 .set_resources = DEVICE_NOOP,
Stefan Reinauer3a0d0d82013-06-20 16:13:19 -0700147 .enable_resources = cpu_enable,
148 .init = cpu_init,
Gabe Black607c0b62013-05-16 05:45:57 -0700149};
150
Elyes HAOUAS01115332018-05-25 09:15:21 +0200151static void enable_exynos5420_dev(struct device *dev)
Gabe Black607c0b62013-05-16 05:45:57 -0700152{
153 dev->ops = &cpu_ops;
154}
155
Gabe Blackd81f4092013-10-08 23:16:51 -0700156struct chip_operations soc_samsung_exynos5420_ops = {
157 CHIP_NAME("SOC Samsung Exynos 5420")
Gabe Black607c0b62013-05-16 05:45:57 -0700158 .enable_dev = enable_exynos5420_dev,
159};