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 | { |
David Hendricks | d598cac | 2013-08-01 18:17:55 -0700 | [diff] [blame^] | 40 | u32 pro_id = (read32((void *)EXYNOS_PRO_ID) & 0x00FFF000) >> 12; |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 41 | |
David Hendricks | d598cac | 2013-08-01 18:17:55 -0700 | [diff] [blame^] | 42 | switch (pro_id) { |
| 43 | case 0x200: |
| 44 | /* Exynos4210 EVT0 */ |
| 45 | cpu_id = 0x4210; |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 46 | cpu_rev = 0; |
David Hendricks | d598cac | 2013-08-01 18:17:55 -0700 | [diff] [blame^] | 47 | break; |
| 48 | case 0x210: |
| 49 | /* Exynos4210 EVT1 */ |
| 50 | cpu_id = 0x4210; |
| 51 | break; |
| 52 | case 0x412: |
| 53 | /* Exynos4412 */ |
| 54 | cpu_id = 0x4412; |
| 55 | break; |
| 56 | case 0x520: |
| 57 | /* Exynos5250 */ |
| 58 | cpu_id = 0x5250; |
| 59 | break; |
| 60 | case 0x420: |
| 61 | /* Exynos5420 */ |
| 62 | cpu_id = 0x5420; |
| 63 | break; |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 64 | } |
| 65 | } |
| 66 | |
| 67 | /* we distinguish a display port device from a raw graphics device |
| 68 | * because there are dramatic differences in startup depending on |
| 69 | * graphics usage. To make startup fast and easier to understand and |
| 70 | * debug we explicitly name this common case. The alternate approach, |
| 71 | * involving lots of machine and callbacks, is hard to debug and |
| 72 | * verify. |
| 73 | */ |
Stefan Reinauer | 80e6293 | 2013-07-29 15:52:23 -0700 | [diff] [blame] | 74 | static void exynos_displayport_init(device_t dev, u32 lcdbase, |
| 75 | unsigned long fb_size) |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 76 | { |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 77 | struct cpu_samsung_exynos5420_config *conf = dev->chip_info; |
| 78 | /* put these on the stack. If, at some point, we want to move |
| 79 | * this code to a pre-ram stage, it will be much easier. |
| 80 | */ |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 81 | struct exynos5_fimd_panel panel; |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 82 | memset(&panel, 0, sizeof(panel)); |
| 83 | |
| 84 | panel.is_dp = 1; /* Display I/F is eDP */ |
| 85 | /* while it is true that we did a memset to zero, |
| 86 | * we leave some 'set to zero' entries here to make |
| 87 | * it clear what's going on. Graphics is confusing. |
| 88 | */ |
| 89 | panel.is_mipi = 0; |
| 90 | panel.fixvclk = 0; |
| 91 | panel.ivclk = 0; |
| 92 | panel.clkval_f = conf->clkval_f; |
| 93 | panel.upper_margin = conf->upper_margin; |
| 94 | panel.lower_margin = conf->lower_margin; |
| 95 | panel.vsync = conf->vsync; |
| 96 | panel.left_margin = conf->left_margin; |
| 97 | panel.right_margin = conf->right_margin; |
| 98 | panel.hsync = conf->hsync; |
| 99 | panel.xres = conf->xres; |
| 100 | panel.yres = conf->yres; |
| 101 | |
Stefan Reinauer | 80e6293 | 2013-07-29 15:52:23 -0700 | [diff] [blame] | 102 | printk(BIOS_SPEW, "LCD framebuffer @%p\n", (void *)(lcdbase)); |
Stefan Reinauer | 2d81125 | 2013-05-20 15:24:13 -0700 | [diff] [blame] | 103 | memset((void *)lcdbase, 0, fb_size); /* clear the framebuffer */ |
| 104 | |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 105 | /* |
| 106 | * We need to clean and invalidate the framebuffer region and disable |
| 107 | * caching as well. We assume that our dcache <--> memory address |
| 108 | * space is identity-mapped in 1MB chunks, so align accordingly. |
| 109 | * |
| 110 | * Note: We may want to do something clever to ensure the framebuffer |
| 111 | * region is aligned such that we don't change dcache policy for other |
| 112 | * stuff inadvertantly. |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 113 | */ |
| 114 | uint32_t lower = ALIGN_DOWN(lcdbase, MiB); |
Stefan Reinauer | f175191 | 2013-05-20 15:17:44 -0700 | [diff] [blame] | 115 | uint32_t upper = ALIGN_UP(lcdbase + fb_size, MiB); |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 116 | |
Stefan Reinauer | 80e6293 | 2013-07-29 15:52:23 -0700 | [diff] [blame] | 117 | dcache_clean_invalidate_by_mva(lower, upper - lower); |
| 118 | mmu_config_range(lower / MiB, (upper - lower) / MiB, DCACHE_OFF); |
| 119 | |
| 120 | printk(BIOS_DEBUG, "Initializing Exynos LCD.\n"); |
| 121 | |
Allen Martin | 681d17e | 2013-09-26 11:13:01 -0700 | [diff] [blame] | 122 | lcd_ctrl_init(fb_size, &panel, (void *)lcdbase); |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Stefan Reinauer | 3a0d0d8 | 2013-06-20 16:13:19 -0700 | [diff] [blame] | 125 | static void cpu_enable(device_t dev) |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 126 | { |
Stefan Reinauer | 80e6293 | 2013-07-29 15:52:23 -0700 | [diff] [blame] | 127 | unsigned long fb_size = FB_SIZE_KB * KiB; |
| 128 | u32 lcdbase = get_fb_base_kb() * KiB; |
Stefan Reinauer | 3a0d0d8 | 2013-06-20 16:13:19 -0700 | [diff] [blame] | 129 | |
Stefan Reinauer | 80e6293 | 2013-07-29 15:52:23 -0700 | [diff] [blame] | 130 | ram_resource(dev, 0, RAM_BASE_KB, RAM_SIZE_KB - FB_SIZE_KB); |
| 131 | mmio_resource(dev, 1, lcdbase / KiB, (fb_size + KiB - 1) / KiB); |
| 132 | |
| 133 | exynos_displayport_init(dev, lcdbase, fb_size); |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 134 | |
| 135 | set_cpu_id(); |
Stefan Reinauer | 3a0d0d8 | 2013-06-20 16:13:19 -0700 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | static void cpu_init(device_t dev) |
| 139 | { |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 140 | printk(BIOS_INFO, "CPU: S5P%X @ %ldMHz\n", |
| 141 | cpu_id, get_arm_clk() / (1024*1024)); |
Stefan Reinauer | 3a0d0d8 | 2013-06-20 16:13:19 -0700 | [diff] [blame] | 142 | |
| 143 | usb_init(dev); |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | static void cpu_noop(device_t dev) |
| 147 | { |
| 148 | } |
| 149 | |
| 150 | static struct device_operations cpu_ops = { |
| 151 | .read_resources = cpu_noop, |
| 152 | .set_resources = cpu_noop, |
Stefan Reinauer | 3a0d0d8 | 2013-06-20 16:13:19 -0700 | [diff] [blame] | 153 | .enable_resources = cpu_enable, |
| 154 | .init = cpu_init, |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 155 | .scan_bus = 0, |
| 156 | }; |
| 157 | |
| 158 | static void enable_exynos5420_dev(device_t dev) |
| 159 | { |
| 160 | dev->ops = &cpu_ops; |
| 161 | } |
| 162 | |
| 163 | struct chip_operations cpu_samsung_exynos5420_ops = { |
| 164 | CHIP_NAME("CPU Samsung Exynos 5420") |
| 165 | .enable_dev = enable_exynos5420_dev, |
| 166 | }; |
| 167 | |
| 168 | void exynos5420_config_l2_cache(void) |
| 169 | { |
| 170 | uint32_t val; |
| 171 | |
| 172 | /* |
| 173 | * Bit 9 - L2 tag RAM setup (1 cycle) |
| 174 | * Bits 8:6 - L2 tag RAM latency (3 cycles) |
| 175 | * Bit 5 - L2 data RAM setup (1 cycle) |
| 176 | * Bits 2:0 - L2 data RAM latency (3 cycles) |
| 177 | */ |
| 178 | val = (1 << 9) | (0x2 << 6) | (1 << 5) | (0x2); |
| 179 | write_l2ctlr(val); |
| 180 | } |