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. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include <stdlib.h> |
| 21 | #include <string.h> |
| 22 | #include <stddef.h> |
| 23 | #include <delay.h> |
| 24 | #include <console/console.h> |
| 25 | #include <device/device.h> |
| 26 | #include <cbmem.h> |
| 27 | #include <arch/cache.h> |
| 28 | #include "fimd.h" |
| 29 | #include "dp-core.h" |
| 30 | #include "cpu.h" |
| 31 | #include "clk.h" |
Stefan Reinauer | 3a0d0d8 | 2013-06-20 16:13:19 -0700 | [diff] [blame] | 32 | #include "usb.h" |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 33 | #include "chip.h" |
| 34 | |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 35 | static unsigned int cpu_id; |
| 36 | static unsigned int cpu_rev; |
| 37 | |
| 38 | static void set_cpu_id(void) |
| 39 | { |
| 40 | cpu_id = readl((void *)EXYNOS_PRO_ID); |
| 41 | cpu_id = (0xC000 | ((cpu_id & 0x00FFF000) >> 12)); |
| 42 | |
| 43 | /* |
| 44 | * 0xC200: EXYNOS4210 EVT0 |
| 45 | * 0xC210: EXYNOS4210 EVT1 |
| 46 | */ |
| 47 | if (cpu_id == 0xC200) { |
| 48 | cpu_id |= 0x10; |
| 49 | cpu_rev = 0; |
| 50 | } else if (cpu_id == 0xC210) { |
| 51 | cpu_rev = 1; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | /* we distinguish a display port device from a raw graphics device |
| 56 | * because there are dramatic differences in startup depending on |
| 57 | * graphics usage. To make startup fast and easier to understand and |
| 58 | * debug we explicitly name this common case. The alternate approach, |
| 59 | * involving lots of machine and callbacks, is hard to debug and |
| 60 | * verify. |
| 61 | */ |
Stefan Reinauer | 80e6293 | 2013-07-29 15:52:23 -0700 | [diff] [blame] | 62 | static void exynos_displayport_init(device_t dev, u32 lcdbase, |
| 63 | unsigned long fb_size) |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 64 | { |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 65 | struct cpu_samsung_exynos5420_config *conf = dev->chip_info; |
| 66 | /* put these on the stack. If, at some point, we want to move |
| 67 | * this code to a pre-ram stage, it will be much easier. |
| 68 | */ |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 69 | struct exynos5_fimd_panel panel; |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 70 | memset(&panel, 0, sizeof(panel)); |
| 71 | |
| 72 | panel.is_dp = 1; /* Display I/F is eDP */ |
| 73 | /* while it is true that we did a memset to zero, |
| 74 | * we leave some 'set to zero' entries here to make |
| 75 | * it clear what's going on. Graphics is confusing. |
| 76 | */ |
| 77 | panel.is_mipi = 0; |
| 78 | panel.fixvclk = 0; |
| 79 | panel.ivclk = 0; |
| 80 | panel.clkval_f = conf->clkval_f; |
| 81 | panel.upper_margin = conf->upper_margin; |
| 82 | panel.lower_margin = conf->lower_margin; |
| 83 | panel.vsync = conf->vsync; |
| 84 | panel.left_margin = conf->left_margin; |
| 85 | panel.right_margin = conf->right_margin; |
| 86 | panel.hsync = conf->hsync; |
| 87 | panel.xres = conf->xres; |
| 88 | panel.yres = conf->yres; |
| 89 | |
Stefan Reinauer | 80e6293 | 2013-07-29 15:52:23 -0700 | [diff] [blame] | 90 | printk(BIOS_SPEW, "LCD framebuffer @%p\n", (void *)(lcdbase)); |
Stefan Reinauer | 2d81125 | 2013-05-20 15:24:13 -0700 | [diff] [blame] | 91 | memset((void *)lcdbase, 0, fb_size); /* clear the framebuffer */ |
| 92 | |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 93 | /* |
| 94 | * We need to clean and invalidate the framebuffer region and disable |
| 95 | * caching as well. We assume that our dcache <--> memory address |
| 96 | * space is identity-mapped in 1MB chunks, so align accordingly. |
| 97 | * |
| 98 | * Note: We may want to do something clever to ensure the framebuffer |
| 99 | * region is aligned such that we don't change dcache policy for other |
| 100 | * stuff inadvertantly. |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 101 | */ |
| 102 | uint32_t lower = ALIGN_DOWN(lcdbase, MiB); |
Stefan Reinauer | f175191 | 2013-05-20 15:17:44 -0700 | [diff] [blame] | 103 | uint32_t upper = ALIGN_UP(lcdbase + fb_size, MiB); |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 104 | |
Stefan Reinauer | 80e6293 | 2013-07-29 15:52:23 -0700 | [diff] [blame] | 105 | dcache_clean_invalidate_by_mva(lower, upper - lower); |
| 106 | mmu_config_range(lower / MiB, (upper - lower) / MiB, DCACHE_OFF); |
| 107 | |
| 108 | printk(BIOS_DEBUG, "Initializing Exynos LCD.\n"); |
| 109 | |
Allen Martin | 681d17e | 2013-09-26 11:13:01 -0700 | [diff] [blame] | 110 | lcd_ctrl_init(fb_size, &panel, (void *)lcdbase); |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Stefan Reinauer | 3a0d0d8 | 2013-06-20 16:13:19 -0700 | [diff] [blame] | 113 | static void cpu_enable(device_t dev) |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 114 | { |
Stefan Reinauer | 80e6293 | 2013-07-29 15:52:23 -0700 | [diff] [blame] | 115 | unsigned long fb_size = FB_SIZE_KB * KiB; |
| 116 | u32 lcdbase = get_fb_base_kb() * KiB; |
Stefan Reinauer | 3a0d0d8 | 2013-06-20 16:13:19 -0700 | [diff] [blame] | 117 | |
Stefan Reinauer | 80e6293 | 2013-07-29 15:52:23 -0700 | [diff] [blame] | 118 | ram_resource(dev, 0, RAM_BASE_KB, RAM_SIZE_KB - FB_SIZE_KB); |
| 119 | mmio_resource(dev, 1, lcdbase / KiB, (fb_size + KiB - 1) / KiB); |
| 120 | |
| 121 | exynos_displayport_init(dev, lcdbase, fb_size); |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 122 | |
| 123 | set_cpu_id(); |
Stefan Reinauer | 3a0d0d8 | 2013-06-20 16:13:19 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | static void cpu_init(device_t dev) |
| 127 | { |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 128 | printk(BIOS_INFO, "CPU: S5P%X @ %ldMHz\n", |
| 129 | cpu_id, get_arm_clk() / (1024*1024)); |
Stefan Reinauer | 3a0d0d8 | 2013-06-20 16:13:19 -0700 | [diff] [blame] | 130 | |
| 131 | usb_init(dev); |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | static void cpu_noop(device_t dev) |
| 135 | { |
| 136 | } |
| 137 | |
| 138 | static struct device_operations cpu_ops = { |
| 139 | .read_resources = cpu_noop, |
| 140 | .set_resources = cpu_noop, |
Stefan Reinauer | 3a0d0d8 | 2013-06-20 16:13:19 -0700 | [diff] [blame] | 141 | .enable_resources = cpu_enable, |
| 142 | .init = cpu_init, |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 143 | .scan_bus = 0, |
| 144 | }; |
| 145 | |
| 146 | static void enable_exynos5420_dev(device_t dev) |
| 147 | { |
| 148 | dev->ops = &cpu_ops; |
| 149 | } |
| 150 | |
| 151 | struct chip_operations cpu_samsung_exynos5420_ops = { |
| 152 | CHIP_NAME("CPU Samsung Exynos 5420") |
| 153 | .enable_dev = enable_exynos5420_dev, |
| 154 | }; |
| 155 | |
| 156 | void exynos5420_config_l2_cache(void) |
| 157 | { |
| 158 | uint32_t val; |
| 159 | |
| 160 | /* |
| 161 | * Bit 9 - L2 tag RAM setup (1 cycle) |
| 162 | * Bits 8:6 - L2 tag RAM latency (3 cycles) |
| 163 | * Bit 5 - L2 data RAM setup (1 cycle) |
| 164 | * Bits 2:0 - L2 data RAM latency (3 cycles) |
| 165 | */ |
| 166 | val = (1 << 9) | (0x2 << 6) | (1 << 5) | (0x2); |
| 167 | write_l2ctlr(val); |
| 168 | } |