blob: ab35667bc8c62d732b147932a025620ca3c4fec2 [file] [log] [blame]
Angel Pons1ddb8942020-04-04 18:51:26 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Gabe Black607c0b62013-05-16 05:45:57 -07002
Julius Werner80af4422014-10-20 13:18:56 -07003#include <arch/cache.h>
Julius Werner80af4422014-10-20 13:18:56 -07004#include <console/console.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02005#include <device/mmio.h>
Julius Werner80af4422014-10-20 13:18:56 -07006#include <device/device.h>
7#include <ec/google/chromeec/ec.h>
8#include <soc/dp.h>
9#include <soc/fimd.h>
10#include <soc/cpu.h>
11#include <soc/clk.h>
Gabe Black607c0b62013-05-16 05:45:57 -070012#include <string.h>
Gabe Black607c0b62013-05-16 05:45:57 -070013
Julius Werner80af4422014-10-20 13:18:56 -070014#include "chip.h"
David Hendricksc81187f2013-08-01 19:09:21 -070015
Gabe Black607c0b62013-05-16 05:45:57 -070016static unsigned int cpu_id;
17static unsigned int cpu_rev;
18
19static void set_cpu_id(void)
20{
Julius Wernerfa938c72013-08-29 14:17:36 -070021 u32 pro_id = (read32((void *)EXYNOS5_PRO_ID) & 0x00FFF000) >> 12;
Gabe Black607c0b62013-05-16 05:45:57 -070022
David Hendricksd598cac2013-08-01 18:17:55 -070023 switch (pro_id) {
24 case 0x200:
25 /* Exynos4210 EVT0 */
26 cpu_id = 0x4210;
Gabe Black607c0b62013-05-16 05:45:57 -070027 cpu_rev = 0;
David Hendricksd598cac2013-08-01 18:17:55 -070028 break;
29 case 0x210:
30 /* Exynos4210 EVT1 */
31 cpu_id = 0x4210;
32 break;
33 case 0x412:
34 /* Exynos4412 */
35 cpu_id = 0x4412;
36 break;
37 case 0x520:
38 /* Exynos5250 */
39 cpu_id = 0x5250;
40 break;
41 case 0x420:
42 /* Exynos5420 */
43 cpu_id = 0x5420;
44 break;
Gabe Black607c0b62013-05-16 05:45:57 -070045 }
46}
47
48/* we distinguish a display port device from a raw graphics device
49 * because there are dramatic differences in startup depending on
50 * graphics usage. To make startup fast and easier to understand and
51 * debug we explicitly name this common case. The alternate approach,
52 * involving lots of machine and callbacks, is hard to debug and
53 * verify.
54 */
Elyes HAOUAS01115332018-05-25 09:15:21 +020055static void exynos_displayport_init(struct device *dev, u32 lcdbase,
Stefan Reinauer80e62932013-07-29 15:52:23 -070056 unsigned long fb_size)
Gabe Black607c0b62013-05-16 05:45:57 -070057{
Hung-Te Lin22d0ca02013-09-27 12:45:45 +080058 struct soc_samsung_exynos5420_config *conf = dev->chip_info;
Gabe Black607c0b62013-05-16 05:45:57 -070059 /* put these on the stack. If, at some point, we want to move
60 * this code to a pre-ram stage, it will be much easier.
61 */
Gabe Black607c0b62013-05-16 05:45:57 -070062 struct exynos5_fimd_panel panel;
Gabe Black607c0b62013-05-16 05:45:57 -070063 memset(&panel, 0, sizeof(panel));
64
65 panel.is_dp = 1; /* Display I/F is eDP */
66 /* while it is true that we did a memset to zero,
67 * we leave some 'set to zero' entries here to make
68 * it clear what's going on. Graphics is confusing.
69 */
70 panel.is_mipi = 0;
71 panel.fixvclk = 0;
72 panel.ivclk = 0;
73 panel.clkval_f = conf->clkval_f;
74 panel.upper_margin = conf->upper_margin;
75 panel.lower_margin = conf->lower_margin;
76 panel.vsync = conf->vsync;
77 panel.left_margin = conf->left_margin;
78 panel.right_margin = conf->right_margin;
79 panel.hsync = conf->hsync;
80 panel.xres = conf->xres;
81 panel.yres = conf->yres;
82
Stefan Reinauer80e62932013-07-29 15:52:23 -070083 printk(BIOS_SPEW, "LCD framebuffer @%p\n", (void *)(lcdbase));
Stefan Reinauer2d811252013-05-20 15:24:13 -070084 memset((void *)lcdbase, 0, fb_size); /* clear the framebuffer */
85
Gabe Black607c0b62013-05-16 05:45:57 -070086 /*
87 * We need to clean and invalidate the framebuffer region and disable
88 * caching as well. We assume that our dcache <--> memory address
89 * space is identity-mapped in 1MB chunks, so align accordingly.
90 *
91 * Note: We may want to do something clever to ensure the framebuffer
92 * region is aligned such that we don't change dcache policy for other
Martin Roth1fc2ba52014-12-07 14:59:11 -070093 * stuff inadvertently.
Gabe Black607c0b62013-05-16 05:45:57 -070094 */
95 uint32_t lower = ALIGN_DOWN(lcdbase, MiB);
Stefan Reinauerf1751912013-05-20 15:17:44 -070096 uint32_t upper = ALIGN_UP(lcdbase + fb_size, MiB);
Gabe Black607c0b62013-05-16 05:45:57 -070097
Julius Wernerf09f2242013-08-28 14:43:14 -070098 dcache_clean_invalidate_by_mva((void *)lower, upper - lower);
Stefan Reinauer80e62932013-07-29 15:52:23 -070099 mmu_config_range(lower / MiB, (upper - lower) / MiB, DCACHE_OFF);
Gabe Black607c0b62013-05-16 05:45:57 -0700100}
101
David Hendricksc81187f2013-08-01 19:09:21 -0700102static void tps65090_thru_ec_fet_disable(int index)
103{
104 uint8_t value = 0;
105
106 if (google_chromeec_i2c_xfer(0x48, 0xe + index, 1, &value, 1, 0)) {
107 printk(BIOS_ERR,
108 "Error sending i2c pass through command to EC.\n");
109 return;
110 }
111}
112
Elyes HAOUAS01115332018-05-25 09:15:21 +0200113static void cpu_enable(struct device *dev)
Gabe Black607c0b62013-05-16 05:45:57 -0700114{
Stefan Reinauer80e62932013-07-29 15:52:23 -0700115 unsigned long fb_size = FB_SIZE_KB * KiB;
116 u32 lcdbase = get_fb_base_kb() * KiB;
Stefan Reinauer3a0d0d82013-06-20 16:13:19 -0700117
David Hendricksc81187f2013-08-01 19:09:21 -0700118 /*
119 * Disable LCD FETs before we do anything with the display.
120 * FIXME(dhendrix): This is a gross hack and should be done
121 * elsewhere (romstage?).
122 */
123 tps65090_thru_ec_fet_disable(1);
124 tps65090_thru_ec_fet_disable(6);
125
Stefan Reinauer80e62932013-07-29 15:52:23 -0700126 exynos_displayport_init(dev, lcdbase, fb_size);
Gabe Black607c0b62013-05-16 05:45:57 -0700127
128 set_cpu_id();
Stefan Reinauer3a0d0d82013-06-20 16:13:19 -0700129}
130
Furquan Shaikhcd6804c2020-05-13 12:22:53 -0700131static void cpu_read_resources(struct device *dev)
132{
133 unsigned long fb_size = FB_SIZE_KB * KiB;
134 u32 lcdbase = get_fb_base_kb() * KiB;
135
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300136 ram_resource_kb(dev, 0, RAM_BASE_KB, RAM_SIZE_KB - FB_SIZE_KB);
137 mmio_resource_kb(dev, 1, lcdbase / KiB, DIV_ROUND_UP(fb_size, KiB));
Furquan Shaikhcd6804c2020-05-13 12:22:53 -0700138}
139
Elyes HAOUAS01115332018-05-25 09:15:21 +0200140static void cpu_init(struct device *dev)
Stefan Reinauer3a0d0d82013-06-20 16:13:19 -0700141{
Gabe Black607c0b62013-05-16 05:45:57 -0700142 printk(BIOS_INFO, "CPU: S5P%X @ %ldMHz\n",
David Hendricks56a7cff2013-08-05 18:53:15 -0700143 cpu_id, get_arm_clk() / 1000000);
Gabe Black607c0b62013-05-16 05:45:57 -0700144}
145
Gabe Black607c0b62013-05-16 05:45:57 -0700146static struct device_operations cpu_ops = {
Furquan Shaikhcd6804c2020-05-13 12:22:53 -0700147 .read_resources = cpu_read_resources,
Nico Huber2f8ba692020-04-05 14:05:24 +0200148 .set_resources = noop_set_resources,
Stefan Reinauer3a0d0d82013-06-20 16:13:19 -0700149 .enable_resources = cpu_enable,
150 .init = cpu_init,
Gabe Black607c0b62013-05-16 05:45:57 -0700151};
152
Elyes HAOUAS01115332018-05-25 09:15:21 +0200153static void enable_exynos5420_dev(struct device *dev)
Gabe Black607c0b62013-05-16 05:45:57 -0700154{
155 dev->ops = &cpu_ops;
156}
157
Gabe Blackd81f4092013-10-08 23:16:51 -0700158struct chip_operations soc_samsung_exynos5420_ops = {
159 CHIP_NAME("SOC Samsung Exynos 5420")
Gabe Black607c0b62013-05-16 05:45:57 -0700160 .enable_dev = enable_exynos5420_dev,
161};