blob: 506b6768c6620b8ca76d37cbe05b850d10bbaa32 [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.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <stdlib.h>
22#include <string.h>
23#include <stddef.h>
24#include <delay.h>
25#include <console/console.h>
26#include <device/device.h>
27#include <cbmem.h>
28#include <arch/cache.h>
Ronald G. Minnichc0d5eb22013-08-01 11:38:05 -070029#include "dp.h"
Gabe Black607c0b62013-05-16 05:45:57 -070030#include "fimd.h"
Gabe Black607c0b62013-05-16 05:45:57 -070031#include "cpu.h"
32#include "clk.h"
33#include "chip.h"
34
David Hendricksc81187f2013-08-01 19:09:21 -070035#include <ec/google/chromeec/ec.h>
36
Gabe Black607c0b62013-05-16 05:45:57 -070037static unsigned int cpu_id;
38static unsigned int cpu_rev;
39
40static void set_cpu_id(void)
41{
Julius Wernerfa938c72013-08-29 14:17:36 -070042 u32 pro_id = (read32((void *)EXYNOS5_PRO_ID) & 0x00FFF000) >> 12;
Gabe Black607c0b62013-05-16 05:45:57 -070043
David Hendricksd598cac2013-08-01 18:17:55 -070044 switch (pro_id) {
45 case 0x200:
46 /* Exynos4210 EVT0 */
47 cpu_id = 0x4210;
Gabe Black607c0b62013-05-16 05:45:57 -070048 cpu_rev = 0;
David Hendricksd598cac2013-08-01 18:17:55 -070049 break;
50 case 0x210:
51 /* Exynos4210 EVT1 */
52 cpu_id = 0x4210;
53 break;
54 case 0x412:
55 /* Exynos4412 */
56 cpu_id = 0x4412;
57 break;
58 case 0x520:
59 /* Exynos5250 */
60 cpu_id = 0x5250;
61 break;
62 case 0x420:
63 /* Exynos5420 */
64 cpu_id = 0x5420;
65 break;
Gabe Black607c0b62013-05-16 05:45:57 -070066 }
67}
68
69/* we distinguish a display port device from a raw graphics device
70 * because there are dramatic differences in startup depending on
71 * graphics usage. To make startup fast and easier to understand and
72 * debug we explicitly name this common case. The alternate approach,
73 * involving lots of machine and callbacks, is hard to debug and
74 * verify.
75 */
Stefan Reinauer80e62932013-07-29 15:52:23 -070076static void exynos_displayport_init(device_t dev, u32 lcdbase,
77 unsigned long fb_size)
Gabe Black607c0b62013-05-16 05:45:57 -070078{
Hung-Te Lin22d0ca02013-09-27 12:45:45 +080079 struct soc_samsung_exynos5420_config *conf = dev->chip_info;
Gabe Black607c0b62013-05-16 05:45:57 -070080 /* put these on the stack. If, at some point, we want to move
81 * this code to a pre-ram stage, it will be much easier.
82 */
Gabe Black607c0b62013-05-16 05:45:57 -070083 struct exynos5_fimd_panel panel;
Gabe Black607c0b62013-05-16 05:45:57 -070084 memset(&panel, 0, sizeof(panel));
85
86 panel.is_dp = 1; /* Display I/F is eDP */
87 /* while it is true that we did a memset to zero,
88 * we leave some 'set to zero' entries here to make
89 * it clear what's going on. Graphics is confusing.
90 */
91 panel.is_mipi = 0;
92 panel.fixvclk = 0;
93 panel.ivclk = 0;
94 panel.clkval_f = conf->clkval_f;
95 panel.upper_margin = conf->upper_margin;
96 panel.lower_margin = conf->lower_margin;
97 panel.vsync = conf->vsync;
98 panel.left_margin = conf->left_margin;
99 panel.right_margin = conf->right_margin;
100 panel.hsync = conf->hsync;
101 panel.xres = conf->xres;
102 panel.yres = conf->yres;
103
Stefan Reinauer80e62932013-07-29 15:52:23 -0700104 printk(BIOS_SPEW, "LCD framebuffer @%p\n", (void *)(lcdbase));
Stefan Reinauer2d811252013-05-20 15:24:13 -0700105 memset((void *)lcdbase, 0, fb_size); /* clear the framebuffer */
106
Gabe Black607c0b62013-05-16 05:45:57 -0700107 /*
108 * We need to clean and invalidate the framebuffer region and disable
109 * caching as well. We assume that our dcache <--> memory address
110 * space is identity-mapped in 1MB chunks, so align accordingly.
111 *
112 * Note: We may want to do something clever to ensure the framebuffer
113 * region is aligned such that we don't change dcache policy for other
114 * stuff inadvertantly.
Gabe Black607c0b62013-05-16 05:45:57 -0700115 */
116 uint32_t lower = ALIGN_DOWN(lcdbase, MiB);
Stefan Reinauerf1751912013-05-20 15:17:44 -0700117 uint32_t upper = ALIGN_UP(lcdbase + fb_size, MiB);
Gabe Black607c0b62013-05-16 05:45:57 -0700118
Julius Wernerf09f2242013-08-28 14:43:14 -0700119 dcache_clean_invalidate_by_mva((void *)lower, upper - lower);
Stefan Reinauer80e62932013-07-29 15:52:23 -0700120 mmu_config_range(lower / MiB, (upper - lower) / MiB, DCACHE_OFF);
121
Edward O'Callaghan7116ac82014-07-08 01:53:24 +1000122 mmio_resource(dev, 1, lcdbase/KiB, CEIL_DIV(fb_size, KiB));
Gabe Black607c0b62013-05-16 05:45:57 -0700123}
124
David Hendricksc81187f2013-08-01 19:09:21 -0700125static void tps65090_thru_ec_fet_disable(int index)
126{
127 uint8_t value = 0;
128
129 if (google_chromeec_i2c_xfer(0x48, 0xe + index, 1, &value, 1, 0)) {
130 printk(BIOS_ERR,
131 "Error sending i2c pass through command to EC.\n");
132 return;
133 }
134}
135
Stefan Reinauer3a0d0d82013-06-20 16:13:19 -0700136static void cpu_enable(device_t dev)
Gabe Black607c0b62013-05-16 05:45:57 -0700137{
Stefan Reinauer80e62932013-07-29 15:52:23 -0700138 unsigned long fb_size = FB_SIZE_KB * KiB;
139 u32 lcdbase = get_fb_base_kb() * KiB;
Stefan Reinauer3a0d0d82013-06-20 16:13:19 -0700140
Stefan Reinauer80e62932013-07-29 15:52:23 -0700141 ram_resource(dev, 0, RAM_BASE_KB, RAM_SIZE_KB - FB_SIZE_KB);
Edward O'Callaghan7116ac82014-07-08 01:53:24 +1000142 mmio_resource(dev, 1, lcdbase / KiB, CEIL_DIV(fb_size, KiB));
Stefan Reinauer80e62932013-07-29 15:52:23 -0700143
David Hendricksc81187f2013-08-01 19:09:21 -0700144 /*
145 * Disable LCD FETs before we do anything with the display.
146 * FIXME(dhendrix): This is a gross hack and should be done
147 * elsewhere (romstage?).
148 */
149 tps65090_thru_ec_fet_disable(1);
150 tps65090_thru_ec_fet_disable(6);
151
Stefan Reinauer80e62932013-07-29 15:52:23 -0700152 exynos_displayport_init(dev, lcdbase, fb_size);
Gabe Black607c0b62013-05-16 05:45:57 -0700153
154 set_cpu_id();
Stefan Reinauer3a0d0d82013-06-20 16:13:19 -0700155}
156
157static void cpu_init(device_t dev)
158{
Gabe Black607c0b62013-05-16 05:45:57 -0700159 printk(BIOS_INFO, "CPU: S5P%X @ %ldMHz\n",
David Hendricks56a7cff2013-08-05 18:53:15 -0700160 cpu_id, get_arm_clk() / 1000000);
Gabe Black607c0b62013-05-16 05:45:57 -0700161}
162
163static void cpu_noop(device_t dev)
164{
165}
166
167static struct device_operations cpu_ops = {
168 .read_resources = cpu_noop,
169 .set_resources = cpu_noop,
Stefan Reinauer3a0d0d82013-06-20 16:13:19 -0700170 .enable_resources = cpu_enable,
171 .init = cpu_init,
Gabe Black607c0b62013-05-16 05:45:57 -0700172 .scan_bus = 0,
173};
174
175static void enable_exynos5420_dev(device_t dev)
176{
177 dev->ops = &cpu_ops;
178}
179
Gabe Blackd81f4092013-10-08 23:16:51 -0700180struct chip_operations soc_samsung_exynos5420_ops = {
181 CHIP_NAME("SOC Samsung Exynos 5420")
Gabe Black607c0b62013-05-16 05:45:57 -0700182 .enable_dev = enable_exynos5420_dev,
183};