Stefan Reinauer | 08dc357 | 2013-05-14 16:57:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2013 Google Inc. |
Ronald G. Minnich | 01b4383 | 2013-08-05 17:18:44 -0700 | [diff] [blame] | 5 | * Copyright (C) 2012 Samsung Electronics |
Stefan Reinauer | 08dc357 | 2013-05-14 16:57:50 -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 | |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 21 | #include <stdlib.h> |
| 22 | #include <string.h> |
| 23 | #include <stddef.h> |
| 24 | #include <delay.h> |
David Hendricks | 6802dc8 | 2013-02-15 16:18:28 -0800 | [diff] [blame] | 25 | #include <console/console.h> |
| 26 | #include <device/device.h> |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 27 | #include <cbmem.h> |
Ronald G. Minnich | 2810afa | 2013-04-18 18:09:24 -0700 | [diff] [blame] | 28 | #include <arch/cache.h> |
Stefan Reinauer | 08dc357 | 2013-05-14 16:57:50 -0700 | [diff] [blame] | 29 | #include "fimd.h" |
| 30 | #include "dp-core.h" |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 31 | #include "cpu.h" |
Stefan Reinauer | 08dc357 | 2013-05-14 16:57:50 -0700 | [diff] [blame] | 32 | #include "clk.h" |
| 33 | #include "chip.h" |
David Hendricks | 6802dc8 | 2013-02-15 16:18:28 -0800 | [diff] [blame] | 34 | |
Stefan Reinauer | 08dc357 | 2013-05-14 16:57:50 -0700 | [diff] [blame] | 35 | static unsigned int cpu_id; |
| 36 | static unsigned int cpu_rev; |
| 37 | |
| 38 | static void set_cpu_id(void) |
| 39 | { |
Julius Werner | fa938c7 | 2013-08-29 14:17:36 -0700 | [diff] [blame] | 40 | cpu_id = readl((void *)EXYNOS5_PRO_ID); |
Stefan Reinauer | 08dc357 | 2013-05-14 16:57:50 -0700 | [diff] [blame] | 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 | |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 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 | 6628744 | 2013-06-19 15:54:19 -0700 | [diff] [blame] | 62 | static void exynos_displayport_init(device_t dev, u32 lcdbase, |
| 63 | unsigned long fb_size) |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 64 | { |
Hung-Te Lin | 22d0ca0 | 2013-09-27 12:45:45 +0800 | [diff] [blame] | 65 | struct soc_samsung_exynos5250_config *conf = dev->chip_info; |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 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 | */ |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 69 | struct exynos5_fimd_panel panel; |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -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; |
Ronald G. Minnich | d83c117 | 2013-04-18 16:10:29 -0700 | [diff] [blame] | 87 | panel.xres = conf->xres; |
| 88 | panel.yres = conf->yres; |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 89 | |
Stefan Reinauer | 6628744 | 2013-06-19 15:54:19 -0700 | [diff] [blame] | 90 | printk(BIOS_SPEW, "LCD framebuffer @%p\n", (void *)(lcdbase)); |
Gabe Black | 39fda6d | 2013-05-18 23:06:47 -0700 | [diff] [blame] | 91 | memset((void *)lcdbase, 0, fb_size); /* clear the framebuffer */ |
| 92 | |
Ronald G. Minnich | 2810afa | 2013-04-18 18:09:24 -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 |
Martin Roth | 4c3ab73 | 2013-07-08 16:23:54 -0600 | [diff] [blame] | 100 | * stuff inadvertently. |
Ronald G. Minnich | 2810afa | 2013-04-18 18:09:24 -0700 | [diff] [blame] | 101 | */ |
| 102 | uint32_t lower = ALIGN_DOWN(lcdbase, MiB); |
Gabe Black | 1e797bd | 2013-05-18 15:58:46 -0700 | [diff] [blame] | 103 | uint32_t upper = ALIGN_UP(lcdbase + fb_size, MiB); |
Ronald G. Minnich | 2810afa | 2013-04-18 18:09:24 -0700 | [diff] [blame] | 104 | |
Julius Werner | f09f224 | 2013-08-28 14:43:14 -0700 | [diff] [blame] | 105 | dcache_clean_invalidate_by_mva((void *)lower, upper - lower); |
Stefan Reinauer | 6628744 | 2013-06-19 15:54:19 -0700 | [diff] [blame] | 106 | mmu_config_range(lower / MiB, (upper - lower) / MiB, DCACHE_OFF); |
| 107 | |
| 108 | printk(BIOS_DEBUG, "Initializing Exynos LCD.\n"); |
| 109 | |
Isaac Christensen | 0c0efa7 | 2014-09-17 16:14:18 -0600 | [diff] [blame^] | 110 | lcd_ctrl_init(fb_size, &panel, (void *)lcdbase); |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Stefan Reinauer | 2ad63c2 | 2013-05-17 11:52:45 -0700 | [diff] [blame] | 113 | static void cpu_enable(device_t dev) |
David Hendricks | 6802dc8 | 2013-02-15 16:18:28 -0800 | [diff] [blame] | 114 | { |
Stefan Reinauer | 6628744 | 2013-06-19 15:54:19 -0700 | [diff] [blame] | 115 | unsigned long fb_size = FB_SIZE_KB * KiB; |
| 116 | u32 lcdbase = get_fb_base_kb() * KiB; |
Stefan Reinauer | 2ad63c2 | 2013-05-17 11:52:45 -0700 | [diff] [blame] | 117 | |
Stefan Reinauer | 6628744 | 2013-06-19 15:54:19 -0700 | [diff] [blame] | 118 | ram_resource(dev, 0, RAM_BASE_KB, RAM_SIZE_KB - FB_SIZE_KB); |
Edward O'Callaghan | 7116ac8 | 2014-07-08 01:53:24 +1000 | [diff] [blame] | 119 | mmio_resource(dev, 1, lcdbase / KiB, CEIL_DIV(fb_size, KiB)); |
Stefan Reinauer | 6628744 | 2013-06-19 15:54:19 -0700 | [diff] [blame] | 120 | |
| 121 | exynos_displayport_init(dev, lcdbase, fb_size); |
Stefan Reinauer | 043eb0e | 2013-05-10 16:21:58 -0700 | [diff] [blame] | 122 | |
Stefan Reinauer | 08dc357 | 2013-05-14 16:57:50 -0700 | [diff] [blame] | 123 | set_cpu_id(); |
Stefan Reinauer | 2ad63c2 | 2013-05-17 11:52:45 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | static void cpu_init(device_t dev) |
| 127 | { |
Stefan Reinauer | 08dc357 | 2013-05-14 16:57:50 -0700 | [diff] [blame] | 128 | printk(BIOS_INFO, "CPU: S5P%X @ %ldMHz\n", |
| 129 | cpu_id, get_arm_clk() / (1024*1024)); |
David Hendricks | 6802dc8 | 2013-02-15 16:18:28 -0800 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | static void cpu_noop(device_t dev) |
| 133 | { |
| 134 | } |
| 135 | |
| 136 | static struct device_operations cpu_ops = { |
| 137 | .read_resources = cpu_noop, |
| 138 | .set_resources = cpu_noop, |
Stefan Reinauer | 2ad63c2 | 2013-05-17 11:52:45 -0700 | [diff] [blame] | 139 | .enable_resources = cpu_enable, |
| 140 | .init = cpu_init, |
David Hendricks | 6802dc8 | 2013-02-15 16:18:28 -0800 | [diff] [blame] | 141 | .scan_bus = 0, |
| 142 | }; |
| 143 | |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 144 | static void enable_exynos5250_dev(device_t dev) |
David Hendricks | 6802dc8 | 2013-02-15 16:18:28 -0800 | [diff] [blame] | 145 | { |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 146 | dev->ops = &cpu_ops; |
David Hendricks | 6802dc8 | 2013-02-15 16:18:28 -0800 | [diff] [blame] | 147 | } |
| 148 | |
Gabe Black | d81f409 | 2013-10-08 23:16:51 -0700 | [diff] [blame] | 149 | struct chip_operations soc_samsung_exynos5250_ops = { |
| 150 | CHIP_NAME("SOC Samsung Exynos 5250") |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 151 | .enable_dev = enable_exynos5250_dev, |
David Hendricks | 6802dc8 | 2013-02-15 16:18:28 -0800 | [diff] [blame] | 152 | }; |
David Hendricks | c01d138 | 2013-03-28 19:04:58 -0700 | [diff] [blame] | 153 | |
| 154 | void exynos5250_config_l2_cache(void) |
| 155 | { |
| 156 | uint32_t val; |
| 157 | |
| 158 | /* |
| 159 | * Bit 9 - L2 tag RAM setup (1 cycle) |
| 160 | * Bits 8:6 - L2 tag RAM latency (3 cycles) |
| 161 | * Bit 5 - L2 data RAM setup (1 cycle) |
| 162 | * Bits 2:0 - L2 data RAM latency (3 cycles) |
| 163 | */ |
| 164 | val = (1 << 9) | (0x2 << 6) | (1 << 5) | (0x2); |
| 165 | write_l2ctlr(val); |
| 166 | } |