blob: cab23a60e6c47eee3579d948b5f50fd4e09c153a [file] [log] [blame]
Gabe Black607c0b62013-05-16 05:45:57 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2013 Google Inc.
Ronald G. Minnichb0efbd32013-08-05 15:56:37 -07005 * Copyright (C) 2012 Samsung Electronics
Gabe Black607c0b62013-05-16 05:45:57 -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.
Gabe Black607c0b62013-05-16 05:45:57 -070015 */
16
Julius Werner80af4422014-10-20 13:18:56 -070017#include <arch/cache.h>
18#include <cbmem.h>
19#include <console/console.h>
20#include <delay.h>
21#include <device/device.h>
22#include <ec/google/chromeec/ec.h>
23#include <soc/dp.h>
24#include <soc/fimd.h>
25#include <soc/cpu.h>
26#include <soc/clk.h>
27#include <stddef.h>
Gabe Black607c0b62013-05-16 05:45:57 -070028#include <stdlib.h>
29#include <string.h>
Gabe Black607c0b62013-05-16 05:45:57 -070030
Julius Werner80af4422014-10-20 13:18:56 -070031#include "chip.h"
David Hendricksc81187f2013-08-01 19:09:21 -070032
Gabe Black607c0b62013-05-16 05:45:57 -070033static unsigned int cpu_id;
34static unsigned int cpu_rev;
35
36static void set_cpu_id(void)
37{
Julius Wernerfa938c72013-08-29 14:17:36 -070038 u32 pro_id = (read32((void *)EXYNOS5_PRO_ID) & 0x00FFF000) >> 12;
Gabe Black607c0b62013-05-16 05:45:57 -070039
David Hendricksd598cac2013-08-01 18:17:55 -070040 switch (pro_id) {
41 case 0x200:
42 /* Exynos4210 EVT0 */
43 cpu_id = 0x4210;
Gabe Black607c0b62013-05-16 05:45:57 -070044 cpu_rev = 0;
David Hendricksd598cac2013-08-01 18:17:55 -070045 break;
46 case 0x210:
47 /* Exynos4210 EVT1 */
48 cpu_id = 0x4210;
49 break;
50 case 0x412:
51 /* Exynos4412 */
52 cpu_id = 0x4412;
53 break;
54 case 0x520:
55 /* Exynos5250 */
56 cpu_id = 0x5250;
57 break;
58 case 0x420:
59 /* Exynos5420 */
60 cpu_id = 0x5420;
61 break;
Gabe Black607c0b62013-05-16 05:45:57 -070062 }
63}
64
65/* we distinguish a display port device from a raw graphics device
66 * because there are dramatic differences in startup depending on
67 * graphics usage. To make startup fast and easier to understand and
68 * debug we explicitly name this common case. The alternate approach,
69 * involving lots of machine and callbacks, is hard to debug and
70 * verify.
71 */
Elyes HAOUAS01115332018-05-25 09:15:21 +020072static void exynos_displayport_init(struct device *dev, u32 lcdbase,
Stefan Reinauer80e62932013-07-29 15:52:23 -070073 unsigned long fb_size)
Gabe Black607c0b62013-05-16 05:45:57 -070074{
Hung-Te Lin22d0ca02013-09-27 12:45:45 +080075 struct soc_samsung_exynos5420_config *conf = dev->chip_info;
Gabe Black607c0b62013-05-16 05:45:57 -070076 /* put these on the stack. If, at some point, we want to move
77 * this code to a pre-ram stage, it will be much easier.
78 */
Gabe Black607c0b62013-05-16 05:45:57 -070079 struct exynos5_fimd_panel panel;
Gabe Black607c0b62013-05-16 05:45:57 -070080 memset(&panel, 0, sizeof(panel));
81
82 panel.is_dp = 1; /* Display I/F is eDP */
83 /* while it is true that we did a memset to zero,
84 * we leave some 'set to zero' entries here to make
85 * it clear what's going on. Graphics is confusing.
86 */
87 panel.is_mipi = 0;
88 panel.fixvclk = 0;
89 panel.ivclk = 0;
90 panel.clkval_f = conf->clkval_f;
91 panel.upper_margin = conf->upper_margin;
92 panel.lower_margin = conf->lower_margin;
93 panel.vsync = conf->vsync;
94 panel.left_margin = conf->left_margin;
95 panel.right_margin = conf->right_margin;
96 panel.hsync = conf->hsync;
97 panel.xres = conf->xres;
98 panel.yres = conf->yres;
99
Stefan Reinauer80e62932013-07-29 15:52:23 -0700100 printk(BIOS_SPEW, "LCD framebuffer @%p\n", (void *)(lcdbase));
Stefan Reinauer2d811252013-05-20 15:24:13 -0700101 memset((void *)lcdbase, 0, fb_size); /* clear the framebuffer */
102
Gabe Black607c0b62013-05-16 05:45:57 -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
Martin Roth1fc2ba52014-12-07 14:59:11 -0700110 * stuff inadvertently.
Gabe Black607c0b62013-05-16 05:45:57 -0700111 */
112 uint32_t lower = ALIGN_DOWN(lcdbase, MiB);
Stefan Reinauerf1751912013-05-20 15:17:44 -0700113 uint32_t upper = ALIGN_UP(lcdbase + fb_size, MiB);
Gabe Black607c0b62013-05-16 05:45:57 -0700114
Julius Wernerf09f2242013-08-28 14:43:14 -0700115 dcache_clean_invalidate_by_mva((void *)lower, upper - lower);
Stefan Reinauer80e62932013-07-29 15:52:23 -0700116 mmu_config_range(lower / MiB, (upper - lower) / MiB, DCACHE_OFF);
117
Edward O'Callaghan7116ac82014-07-08 01:53:24 +1000118 mmio_resource(dev, 1, lcdbase/KiB, CEIL_DIV(fb_size, KiB));
Gabe Black607c0b62013-05-16 05:45:57 -0700119}
120
David Hendricksc81187f2013-08-01 19:09:21 -0700121static void tps65090_thru_ec_fet_disable(int index)
122{
123 uint8_t value = 0;
124
125 if (google_chromeec_i2c_xfer(0x48, 0xe + index, 1, &value, 1, 0)) {
126 printk(BIOS_ERR,
127 "Error sending i2c pass through command to EC.\n");
128 return;
129 }
130}
131
Elyes HAOUAS01115332018-05-25 09:15:21 +0200132static void cpu_enable(struct device *dev)
Gabe Black607c0b62013-05-16 05:45:57 -0700133{
Stefan Reinauer80e62932013-07-29 15:52:23 -0700134 unsigned long fb_size = FB_SIZE_KB * KiB;
135 u32 lcdbase = get_fb_base_kb() * KiB;
Stefan Reinauer3a0d0d82013-06-20 16:13:19 -0700136
Stefan Reinauer80e62932013-07-29 15:52:23 -0700137 ram_resource(dev, 0, RAM_BASE_KB, RAM_SIZE_KB - FB_SIZE_KB);
Edward O'Callaghan7116ac82014-07-08 01:53:24 +1000138 mmio_resource(dev, 1, lcdbase / KiB, CEIL_DIV(fb_size, KiB));
Stefan Reinauer80e62932013-07-29 15:52:23 -0700139
David Hendricksc81187f2013-08-01 19:09:21 -0700140 /*
141 * Disable LCD FETs before we do anything with the display.
142 * FIXME(dhendrix): This is a gross hack and should be done
143 * elsewhere (romstage?).
144 */
145 tps65090_thru_ec_fet_disable(1);
146 tps65090_thru_ec_fet_disable(6);
147
Stefan Reinauer80e62932013-07-29 15:52:23 -0700148 exynos_displayport_init(dev, lcdbase, fb_size);
Gabe Black607c0b62013-05-16 05:45:57 -0700149
150 set_cpu_id();
Stefan Reinauer3a0d0d82013-06-20 16:13:19 -0700151}
152
Elyes HAOUAS01115332018-05-25 09:15:21 +0200153static void cpu_init(struct device *dev)
Stefan Reinauer3a0d0d82013-06-20 16:13:19 -0700154{
Gabe Black607c0b62013-05-16 05:45:57 -0700155 printk(BIOS_INFO, "CPU: S5P%X @ %ldMHz\n",
David Hendricks56a7cff2013-08-05 18:53:15 -0700156 cpu_id, get_arm_clk() / 1000000);
Gabe Black607c0b62013-05-16 05:45:57 -0700157}
158
Gabe Black607c0b62013-05-16 05:45:57 -0700159static struct device_operations cpu_ops = {
Edward O'Callaghan0625a8b2014-10-31 08:03:16 +1100160 .read_resources = DEVICE_NOOP,
161 .set_resources = DEVICE_NOOP,
Stefan Reinauer3a0d0d82013-06-20 16:13:19 -0700162 .enable_resources = cpu_enable,
163 .init = cpu_init,
Gabe Black607c0b62013-05-16 05:45:57 -0700164 .scan_bus = 0,
165};
166
Elyes HAOUAS01115332018-05-25 09:15:21 +0200167static void enable_exynos5420_dev(struct device *dev)
Gabe Black607c0b62013-05-16 05:45:57 -0700168{
169 dev->ops = &cpu_ops;
170}
171
Gabe Blackd81f4092013-10-08 23:16:51 -0700172struct chip_operations soc_samsung_exynos5420_ops = {
173 CHIP_NAME("SOC Samsung Exynos 5420")
Gabe Black607c0b62013-05-16 05:45:57 -0700174 .enable_dev = enable_exynos5420_dev,
175};