Stefan Reinauer | 08dc357 | 2013-05-14 16:57:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Stefan Reinauer | 08dc357 | 2013-05-14 16:57:50 -0700 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; version 2 of the License. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
Stefan Reinauer | 08dc357 | 2013-05-14 16:57:50 -0700 | [diff] [blame] | 13 | */ |
| 14 | |
Julius Werner | 1ed0c8c | 2014-10-20 13:16:29 -0700 | [diff] [blame] | 15 | #include <arch/cache.h> |
Julius Werner | 1ed0c8c | 2014-10-20 13:16:29 -0700 | [diff] [blame] | 16 | #include <console/console.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 17 | #include <device/mmio.h> |
Julius Werner | 1ed0c8c | 2014-10-20 13:16:29 -0700 | [diff] [blame] | 18 | #include <device/device.h> |
| 19 | #include <soc/clk.h> |
| 20 | #include <soc/cpu.h> |
| 21 | #include <soc/dp-core.h> |
| 22 | #include <soc/fimd.h> |
| 23 | #include <stddef.h> |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 24 | #include <string.h> |
Julius Werner | 1ed0c8c | 2014-10-20 13:16:29 -0700 | [diff] [blame] | 25 | |
Stefan Reinauer | 08dc357 | 2013-05-14 16:57:50 -0700 | [diff] [blame] | 26 | #include "chip.h" |
David Hendricks | 6802dc8 | 2013-02-15 16:18:28 -0800 | [diff] [blame] | 27 | |
Stefan Reinauer | 08dc357 | 2013-05-14 16:57:50 -0700 | [diff] [blame] | 28 | static unsigned int cpu_id; |
| 29 | static unsigned int cpu_rev; |
| 30 | |
| 31 | static void set_cpu_id(void) |
| 32 | { |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 33 | cpu_id = read32((void *)EXYNOS5_PRO_ID); |
Stefan Reinauer | 08dc357 | 2013-05-14 16:57:50 -0700 | [diff] [blame] | 34 | cpu_id = (0xC000 | ((cpu_id & 0x00FFF000) >> 12)); |
| 35 | |
| 36 | /* |
| 37 | * 0xC200: EXYNOS4210 EVT0 |
| 38 | * 0xC210: EXYNOS4210 EVT1 |
| 39 | */ |
| 40 | if (cpu_id == 0xC200) { |
| 41 | cpu_id |= 0x10; |
| 42 | cpu_rev = 0; |
| 43 | } else if (cpu_id == 0xC210) { |
| 44 | cpu_rev = 1; |
| 45 | } |
| 46 | } |
| 47 | |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 48 | /* we distinguish a display port device from a raw graphics device |
| 49 | * because there are dramatic differences in startup depending on |
| 50 | * graphics usage. To make startup fast and easier to understand and |
| 51 | * debug we explicitly name this common case. The alternate approach, |
| 52 | * involving lots of machine and callbacks, is hard to debug and |
| 53 | * verify. |
| 54 | */ |
Elyes HAOUAS | 0111533 | 2018-05-25 09:15:21 +0200 | [diff] [blame] | 55 | static void exynos_displayport_init(struct device *dev, u32 lcdbase, |
Stefan Reinauer | 6628744 | 2013-06-19 15:54:19 -0700 | [diff] [blame] | 56 | unsigned long fb_size) |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 57 | { |
Hung-Te Lin | 22d0ca0 | 2013-09-27 12:45:45 +0800 | [diff] [blame] | 58 | struct soc_samsung_exynos5250_config *conf = dev->chip_info; |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 59 | /* put these on the stack. If, at some point, we want to move |
| 60 | * this code to a pre-ram stage, it will be much easier. |
| 61 | */ |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 62 | struct exynos5_fimd_panel panel; |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 63 | memset(&panel, 0, sizeof(panel)); |
| 64 | |
| 65 | panel.is_dp = 1; /* Display I/F is eDP */ |
| 66 | /* while it is true that we did a memset to zero, |
| 67 | * we leave some 'set to zero' entries here to make |
| 68 | * it clear what's going on. Graphics is confusing. |
| 69 | */ |
| 70 | panel.is_mipi = 0; |
| 71 | panel.fixvclk = 0; |
| 72 | panel.ivclk = 0; |
| 73 | panel.clkval_f = conf->clkval_f; |
| 74 | panel.upper_margin = conf->upper_margin; |
| 75 | panel.lower_margin = conf->lower_margin; |
| 76 | panel.vsync = conf->vsync; |
| 77 | panel.left_margin = conf->left_margin; |
| 78 | panel.right_margin = conf->right_margin; |
| 79 | panel.hsync = conf->hsync; |
Ronald G. Minnich | d83c117 | 2013-04-18 16:10:29 -0700 | [diff] [blame] | 80 | panel.xres = conf->xres; |
| 81 | panel.yres = conf->yres; |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 82 | |
Stefan Reinauer | 6628744 | 2013-06-19 15:54:19 -0700 | [diff] [blame] | 83 | printk(BIOS_SPEW, "LCD framebuffer @%p\n", (void *)(lcdbase)); |
Gabe Black | 39fda6d | 2013-05-18 23:06:47 -0700 | [diff] [blame] | 84 | memset((void *)lcdbase, 0, fb_size); /* clear the framebuffer */ |
| 85 | |
Ronald G. Minnich | 2810afa | 2013-04-18 18:09:24 -0700 | [diff] [blame] | 86 | /* |
| 87 | * We need to clean and invalidate the framebuffer region and disable |
| 88 | * caching as well. We assume that our dcache <--> memory address |
| 89 | * space is identity-mapped in 1MB chunks, so align accordingly. |
| 90 | * |
| 91 | * Note: We may want to do something clever to ensure the framebuffer |
| 92 | * 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] | 93 | * stuff inadvertently. |
Ronald G. Minnich | 2810afa | 2013-04-18 18:09:24 -0700 | [diff] [blame] | 94 | */ |
| 95 | uint32_t lower = ALIGN_DOWN(lcdbase, MiB); |
Gabe Black | 1e797bd | 2013-05-18 15:58:46 -0700 | [diff] [blame] | 96 | uint32_t upper = ALIGN_UP(lcdbase + fb_size, MiB); |
Ronald G. Minnich | 2810afa | 2013-04-18 18:09:24 -0700 | [diff] [blame] | 97 | |
Julius Werner | f09f224 | 2013-08-28 14:43:14 -0700 | [diff] [blame] | 98 | dcache_clean_invalidate_by_mva((void *)lower, upper - lower); |
Stefan Reinauer | 6628744 | 2013-06-19 15:54:19 -0700 | [diff] [blame] | 99 | mmu_config_range(lower / MiB, (upper - lower) / MiB, DCACHE_OFF); |
| 100 | |
| 101 | printk(BIOS_DEBUG, "Initializing Exynos LCD.\n"); |
| 102 | |
Isaac Christensen | 0c0efa7 | 2014-09-17 16:14:18 -0600 | [diff] [blame] | 103 | lcd_ctrl_init(fb_size, &panel, (void *)lcdbase); |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Elyes HAOUAS | 0111533 | 2018-05-25 09:15:21 +0200 | [diff] [blame] | 106 | static void cpu_enable(struct device *dev) |
David Hendricks | 6802dc8 | 2013-02-15 16:18:28 -0800 | [diff] [blame] | 107 | { |
Stefan Reinauer | 6628744 | 2013-06-19 15:54:19 -0700 | [diff] [blame] | 108 | unsigned long fb_size = FB_SIZE_KB * KiB; |
| 109 | u32 lcdbase = get_fb_base_kb() * KiB; |
Stefan Reinauer | 2ad63c2 | 2013-05-17 11:52:45 -0700 | [diff] [blame] | 110 | |
Stefan Reinauer | 6628744 | 2013-06-19 15:54:19 -0700 | [diff] [blame] | 111 | ram_resource(dev, 0, RAM_BASE_KB, RAM_SIZE_KB - FB_SIZE_KB); |
Elyes HAOUAS | 6df3b64 | 2018-11-26 22:53:49 +0100 | [diff] [blame] | 112 | mmio_resource(dev, 1, lcdbase / KiB, DIV_ROUND_UP(fb_size, KiB)); |
Stefan Reinauer | 6628744 | 2013-06-19 15:54:19 -0700 | [diff] [blame] | 113 | |
| 114 | exynos_displayport_init(dev, lcdbase, fb_size); |
Stefan Reinauer | 043eb0e | 2013-05-10 16:21:58 -0700 | [diff] [blame] | 115 | |
Stefan Reinauer | 08dc357 | 2013-05-14 16:57:50 -0700 | [diff] [blame] | 116 | set_cpu_id(); |
Stefan Reinauer | 2ad63c2 | 2013-05-17 11:52:45 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Elyes HAOUAS | 0111533 | 2018-05-25 09:15:21 +0200 | [diff] [blame] | 119 | static void cpu_init(struct device *dev) |
Stefan Reinauer | 2ad63c2 | 2013-05-17 11:52:45 -0700 | [diff] [blame] | 120 | { |
Stefan Reinauer | 08dc357 | 2013-05-14 16:57:50 -0700 | [diff] [blame] | 121 | printk(BIOS_INFO, "CPU: S5P%X @ %ldMHz\n", |
| 122 | cpu_id, get_arm_clk() / (1024*1024)); |
David Hendricks | 6802dc8 | 2013-02-15 16:18:28 -0800 | [diff] [blame] | 123 | } |
| 124 | |
David Hendricks | 6802dc8 | 2013-02-15 16:18:28 -0800 | [diff] [blame] | 125 | static struct device_operations cpu_ops = { |
Edward O'Callaghan | 0625a8b | 2014-10-31 08:03:16 +1100 | [diff] [blame] | 126 | .read_resources = DEVICE_NOOP, |
| 127 | .set_resources = DEVICE_NOOP, |
Stefan Reinauer | 2ad63c2 | 2013-05-17 11:52:45 -0700 | [diff] [blame] | 128 | .enable_resources = cpu_enable, |
| 129 | .init = cpu_init, |
David Hendricks | 6802dc8 | 2013-02-15 16:18:28 -0800 | [diff] [blame] | 130 | }; |
| 131 | |
Elyes HAOUAS | 0111533 | 2018-05-25 09:15:21 +0200 | [diff] [blame] | 132 | static void enable_exynos5250_dev(struct device *dev) |
David Hendricks | 6802dc8 | 2013-02-15 16:18:28 -0800 | [diff] [blame] | 133 | { |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 134 | dev->ops = &cpu_ops; |
David Hendricks | 6802dc8 | 2013-02-15 16:18:28 -0800 | [diff] [blame] | 135 | } |
| 136 | |
Gabe Black | d81f409 | 2013-10-08 23:16:51 -0700 | [diff] [blame] | 137 | struct chip_operations soc_samsung_exynos5250_ops = { |
| 138 | CHIP_NAME("SOC Samsung Exynos 5250") |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 139 | .enable_dev = enable_exynos5250_dev, |
David Hendricks | 6802dc8 | 2013-02-15 16:18:28 -0800 | [diff] [blame] | 140 | }; |
David Hendricks | c01d138 | 2013-03-28 19:04:58 -0700 | [diff] [blame] | 141 | |
| 142 | void exynos5250_config_l2_cache(void) |
| 143 | { |
| 144 | uint32_t val; |
| 145 | |
| 146 | /* |
| 147 | * Bit 9 - L2 tag RAM setup (1 cycle) |
| 148 | * Bits 8:6 - L2 tag RAM latency (3 cycles) |
| 149 | * Bit 5 - L2 data RAM setup (1 cycle) |
| 150 | * Bits 2:0 - L2 data RAM latency (3 cycles) |
| 151 | */ |
| 152 | val = (1 << 9) | (0x2 << 6) | (1 << 5) | (0x2); |
| 153 | write_l2ctlr(val); |
| 154 | } |