Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2013 Google Inc. |
Ronald G. Minnich | b0efbd3 | 2013-08-05 15:56:37 -0700 | [diff] [blame] | 5 | * Copyright (C) 2012 Samsung Electronics |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 6 | * |
| 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. Minnich | c0d5eb2 | 2013-08-01 11:38:05 -0700 | [diff] [blame] | 29 | #include "dp.h" |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 30 | #include "fimd.h" |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 31 | #include "cpu.h" |
| 32 | #include "clk.h" |
Stefan Reinauer | 3a0d0d8 | 2013-06-20 16:13:19 -0700 | [diff] [blame] | 33 | #include "usb.h" |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 34 | #include "chip.h" |
| 35 | |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 36 | static unsigned int cpu_id; |
| 37 | static unsigned int cpu_rev; |
| 38 | |
Ronald G. Minnich | b0efbd3 | 2013-08-05 15:56:37 -0700 | [diff] [blame] | 39 | /* Setting TZPC[TrustZone Protection Controller] |
| 40 | * We pretty much disable it all, as the kernel |
| 41 | * expects it that way -- and that's not the default. |
| 42 | */ |
| 43 | static void tzpc_init(void) |
| 44 | { |
| 45 | struct exynos_tzpc *tzpc; |
| 46 | unsigned int addr; |
| 47 | |
| 48 | for (addr = TZPC10_BASE; addr <= TZPC9_BASE; addr += TZPC_BASE_OFFSET) { |
| 49 | tzpc = (struct exynos_tzpc *)addr; |
| 50 | if (addr == TZPC0_BASE) |
| 51 | writel(R0SIZE, &tzpc->r0size); |
| 52 | writel(DECPROTXSET, &tzpc->decprot0set); |
| 53 | writel(DECPROTXSET, &tzpc->decprot1set); |
| 54 | writel(DECPROTXSET, &tzpc->decprot2set); |
| 55 | writel(DECPROTXSET, &tzpc->decprot3set); |
| 56 | } |
| 57 | } |
| 58 | |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 59 | static void set_cpu_id(void) |
| 60 | { |
David Hendricks | d598cac | 2013-08-01 18:17:55 -0700 | [diff] [blame] | 61 | u32 pro_id = (read32((void *)EXYNOS_PRO_ID) & 0x00FFF000) >> 12; |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 62 | |
David Hendricks | d598cac | 2013-08-01 18:17:55 -0700 | [diff] [blame] | 63 | switch (pro_id) { |
| 64 | case 0x200: |
| 65 | /* Exynos4210 EVT0 */ |
| 66 | cpu_id = 0x4210; |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 67 | cpu_rev = 0; |
David Hendricks | d598cac | 2013-08-01 18:17:55 -0700 | [diff] [blame] | 68 | break; |
| 69 | case 0x210: |
| 70 | /* Exynos4210 EVT1 */ |
| 71 | cpu_id = 0x4210; |
| 72 | break; |
| 73 | case 0x412: |
| 74 | /* Exynos4412 */ |
| 75 | cpu_id = 0x4412; |
| 76 | break; |
| 77 | case 0x520: |
| 78 | /* Exynos5250 */ |
| 79 | cpu_id = 0x5250; |
| 80 | break; |
| 81 | case 0x420: |
| 82 | /* Exynos5420 */ |
| 83 | cpu_id = 0x5420; |
| 84 | break; |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 85 | } |
| 86 | } |
| 87 | |
| 88 | /* we distinguish a display port device from a raw graphics device |
| 89 | * because there are dramatic differences in startup depending on |
| 90 | * graphics usage. To make startup fast and easier to understand and |
| 91 | * debug we explicitly name this common case. The alternate approach, |
| 92 | * involving lots of machine and callbacks, is hard to debug and |
| 93 | * verify. |
| 94 | */ |
Stefan Reinauer | 80e6293 | 2013-07-29 15:52:23 -0700 | [diff] [blame] | 95 | static void exynos_displayport_init(device_t dev, u32 lcdbase, |
| 96 | unsigned long fb_size) |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 97 | { |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 98 | struct cpu_samsung_exynos5420_config *conf = dev->chip_info; |
| 99 | /* put these on the stack. If, at some point, we want to move |
| 100 | * this code to a pre-ram stage, it will be much easier. |
| 101 | */ |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 102 | struct exynos5_fimd_panel panel; |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 103 | memset(&panel, 0, sizeof(panel)); |
| 104 | |
| 105 | panel.is_dp = 1; /* Display I/F is eDP */ |
| 106 | /* while it is true that we did a memset to zero, |
| 107 | * we leave some 'set to zero' entries here to make |
| 108 | * it clear what's going on. Graphics is confusing. |
| 109 | */ |
| 110 | panel.is_mipi = 0; |
| 111 | panel.fixvclk = 0; |
| 112 | panel.ivclk = 0; |
| 113 | panel.clkval_f = conf->clkval_f; |
| 114 | panel.upper_margin = conf->upper_margin; |
| 115 | panel.lower_margin = conf->lower_margin; |
| 116 | panel.vsync = conf->vsync; |
| 117 | panel.left_margin = conf->left_margin; |
| 118 | panel.right_margin = conf->right_margin; |
| 119 | panel.hsync = conf->hsync; |
| 120 | panel.xres = conf->xres; |
| 121 | panel.yres = conf->yres; |
| 122 | |
Stefan Reinauer | 80e6293 | 2013-07-29 15:52:23 -0700 | [diff] [blame] | 123 | printk(BIOS_SPEW, "LCD framebuffer @%p\n", (void *)(lcdbase)); |
Stefan Reinauer | 2d81125 | 2013-05-20 15:24:13 -0700 | [diff] [blame] | 124 | memset((void *)lcdbase, 0, fb_size); /* clear the framebuffer */ |
| 125 | |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 126 | /* |
| 127 | * We need to clean and invalidate the framebuffer region and disable |
| 128 | * caching as well. We assume that our dcache <--> memory address |
| 129 | * space is identity-mapped in 1MB chunks, so align accordingly. |
| 130 | * |
| 131 | * Note: We may want to do something clever to ensure the framebuffer |
| 132 | * region is aligned such that we don't change dcache policy for other |
| 133 | * stuff inadvertantly. |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 134 | */ |
| 135 | uint32_t lower = ALIGN_DOWN(lcdbase, MiB); |
Stefan Reinauer | f175191 | 2013-05-20 15:17:44 -0700 | [diff] [blame] | 136 | uint32_t upper = ALIGN_UP(lcdbase + fb_size, MiB); |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 137 | |
Stefan Reinauer | 80e6293 | 2013-07-29 15:52:23 -0700 | [diff] [blame] | 138 | dcache_clean_invalidate_by_mva(lower, upper - lower); |
| 139 | mmu_config_range(lower / MiB, (upper - lower) / MiB, DCACHE_OFF); |
| 140 | |
Ronald G. Minnich | c0d5eb2 | 2013-08-01 11:38:05 -0700 | [diff] [blame] | 141 | mmio_resource(dev, 1, lcdbase/KiB, (fb_size + KiB - 1)/KiB); |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Stefan Reinauer | 3a0d0d8 | 2013-06-20 16:13:19 -0700 | [diff] [blame] | 144 | static void cpu_enable(device_t dev) |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 145 | { |
Stefan Reinauer | 80e6293 | 2013-07-29 15:52:23 -0700 | [diff] [blame] | 146 | unsigned long fb_size = FB_SIZE_KB * KiB; |
| 147 | u32 lcdbase = get_fb_base_kb() * KiB; |
Stefan Reinauer | 3a0d0d8 | 2013-06-20 16:13:19 -0700 | [diff] [blame] | 148 | |
Stefan Reinauer | 80e6293 | 2013-07-29 15:52:23 -0700 | [diff] [blame] | 149 | ram_resource(dev, 0, RAM_BASE_KB, RAM_SIZE_KB - FB_SIZE_KB); |
| 150 | mmio_resource(dev, 1, lcdbase / KiB, (fb_size + KiB - 1) / KiB); |
| 151 | |
| 152 | exynos_displayport_init(dev, lcdbase, fb_size); |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 153 | |
| 154 | set_cpu_id(); |
Ronald G. Minnich | b0efbd3 | 2013-08-05 15:56:37 -0700 | [diff] [blame] | 155 | |
| 156 | tzpc_init(); |
Stefan Reinauer | 3a0d0d8 | 2013-06-20 16:13:19 -0700 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | static void cpu_init(device_t dev) |
| 160 | { |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 161 | printk(BIOS_INFO, "CPU: S5P%X @ %ldMHz\n", |
David Hendricks | 56a7cff | 2013-08-05 18:53:15 -0700 | [diff] [blame] | 162 | cpu_id, get_arm_clk() / 1000000); |
Stefan Reinauer | 3a0d0d8 | 2013-06-20 16:13:19 -0700 | [diff] [blame] | 163 | |
| 164 | usb_init(dev); |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | static void cpu_noop(device_t dev) |
| 168 | { |
| 169 | } |
| 170 | |
| 171 | static struct device_operations cpu_ops = { |
| 172 | .read_resources = cpu_noop, |
| 173 | .set_resources = cpu_noop, |
Stefan Reinauer | 3a0d0d8 | 2013-06-20 16:13:19 -0700 | [diff] [blame] | 174 | .enable_resources = cpu_enable, |
| 175 | .init = cpu_init, |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 176 | .scan_bus = 0, |
| 177 | }; |
| 178 | |
| 179 | static void enable_exynos5420_dev(device_t dev) |
| 180 | { |
| 181 | dev->ops = &cpu_ops; |
| 182 | } |
| 183 | |
| 184 | struct chip_operations cpu_samsung_exynos5420_ops = { |
| 185 | CHIP_NAME("CPU Samsung Exynos 5420") |
| 186 | .enable_dev = enable_exynos5420_dev, |
| 187 | }; |
| 188 | |
| 189 | void exynos5420_config_l2_cache(void) |
| 190 | { |
| 191 | uint32_t val; |
| 192 | |
| 193 | /* |
| 194 | * Bit 9 - L2 tag RAM setup (1 cycle) |
| 195 | * Bits 8:6 - L2 tag RAM latency (3 cycles) |
| 196 | * Bit 5 - L2 data RAM setup (1 cycle) |
| 197 | * Bits 2:0 - L2 data RAM latency (3 cycles) |
| 198 | */ |
| 199 | val = (1 << 9) | (0x2 << 6) | (1 << 5) | (0x2); |
| 200 | write_l2ctlr(val); |
David Hendricks | 49c1be9 | 2013-08-06 18:05:55 -0700 | [diff] [blame^] | 201 | |
| 202 | val = read_l2actlr(); |
| 203 | |
| 204 | /* L2ACTLR[3]: Disable clean/evict push to external */ |
| 205 | val |= (1 << 3); |
| 206 | |
| 207 | /* L2ACTLR[7]: Enable hazard detect timeout for A15 */ |
| 208 | val |= (1 << 7); |
| 209 | |
| 210 | /* L2ACTLR[27]: Prevents stopping the L2 logic clock */ |
| 211 | val |= (1 << 27); |
| 212 | |
| 213 | write_l2actlr(val); |
| 214 | |
| 215 | /* Read the l2 control register to force things to take effect? */ |
| 216 | val = read_l2ctlr(); |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 217 | } |