Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 1 | #include <stdlib.h> |
| 2 | #include <string.h> |
| 3 | #include <stddef.h> |
| 4 | #include <delay.h> |
David Hendricks | 6802dc8 | 2013-02-15 16:18:28 -0800 | [diff] [blame] | 5 | #include <console/console.h> |
| 6 | #include <device/device.h> |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 7 | #include <cbmem.h> |
Ronald G. Minnich | 2810afa | 2013-04-18 18:09:24 -0700 | [diff] [blame] | 8 | #include <arch/cache.h> |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 9 | #include <cpu/samsung/exynos5250/fimd.h> |
| 10 | #include <cpu/samsung/exynos5-common/s5p-dp-core.h> |
Stefan Reinauer | 043eb0e | 2013-05-10 16:21:58 -0700 | [diff] [blame^] | 11 | #include <cpu/samsung/exynos5-common/cpu.h> |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 12 | #include "chip.h" |
| 13 | #include "cpu.h" |
David Hendricks | 6802dc8 | 2013-02-15 16:18:28 -0800 | [diff] [blame] | 14 | |
David Hendricks | 0f5a3fc | 2013-03-12 20:16:44 -0700 | [diff] [blame] | 15 | #define RAM_BASE_KB (CONFIG_SYS_SDRAM_BASE >> 10) |
| 16 | #define RAM_SIZE_KB (CONFIG_DRAM_SIZE_MB << 10UL) |
David Hendricks | 6802dc8 | 2013-02-15 16:18:28 -0800 | [diff] [blame] | 17 | |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 18 | /* we distinguish a display port device from a raw graphics device |
| 19 | * because there are dramatic differences in startup depending on |
| 20 | * graphics usage. To make startup fast and easier to understand and |
| 21 | * debug we explicitly name this common case. The alternate approach, |
| 22 | * involving lots of machine and callbacks, is hard to debug and |
| 23 | * verify. |
| 24 | */ |
| 25 | static void exynos_displayport_init(device_t dev) |
| 26 | { |
| 27 | int ret; |
| 28 | struct cpu_samsung_exynos5250_config *conf = dev->chip_info; |
| 29 | /* put these on the stack. If, at some point, we want to move |
| 30 | * this code to a pre-ram stage, it will be much easier. |
| 31 | */ |
| 32 | vidinfo_t vi; |
| 33 | struct exynos5_fimd_panel panel; |
| 34 | unsigned long int fb_size; |
| 35 | u32 lcdbase; |
| 36 | |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 37 | memset(&vi, 0, sizeof(vi)); |
| 38 | memset(&panel, 0, sizeof(panel)); |
| 39 | |
| 40 | panel.is_dp = 1; /* Display I/F is eDP */ |
| 41 | /* while it is true that we did a memset to zero, |
| 42 | * we leave some 'set to zero' entries here to make |
| 43 | * it clear what's going on. Graphics is confusing. |
| 44 | */ |
| 45 | panel.is_mipi = 0; |
| 46 | panel.fixvclk = 0; |
| 47 | panel.ivclk = 0; |
| 48 | panel.clkval_f = conf->clkval_f; |
| 49 | panel.upper_margin = conf->upper_margin; |
| 50 | panel.lower_margin = conf->lower_margin; |
| 51 | panel.vsync = conf->vsync; |
| 52 | panel.left_margin = conf->left_margin; |
| 53 | panel.right_margin = conf->right_margin; |
| 54 | panel.hsync = conf->hsync; |
Ronald G. Minnich | d83c117 | 2013-04-18 16:10:29 -0700 | [diff] [blame] | 55 | panel.xres = conf->xres; |
| 56 | panel.yres = conf->yres; |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 57 | |
| 58 | vi.vl_col = conf->xres; |
| 59 | vi.vl_row = conf->yres; |
| 60 | vi.vl_bpix = conf->bpp; |
| 61 | /* |
| 62 | * The size is a magic number from hardware. Allocate enough for the |
| 63 | * frame buffer and color map. |
| 64 | */ |
Ronald G. Minnich | 2810afa | 2013-04-18 18:09:24 -0700 | [diff] [blame] | 65 | fb_size = conf->xres * conf->yres * (conf->bpp / 8); |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 66 | lcdbase = (uintptr_t)cbmem_add(CBMEM_ID_CONSOLE, fb_size + 64*KiB); |
| 67 | printk(BIOS_SPEW, "lcd colormap base is %p\n", (void *)(lcdbase)); |
| 68 | mmio_resource(dev, 0, lcdbase/KiB, 64); |
| 69 | vi.cmap = (void *)lcdbase; |
| 70 | |
Ronald G. Minnich | 2810afa | 2013-04-18 18:09:24 -0700 | [diff] [blame] | 71 | /* |
| 72 | * We need to clean and invalidate the framebuffer region and disable |
| 73 | * caching as well. We assume that our dcache <--> memory address |
| 74 | * space is identity-mapped in 1MB chunks, so align accordingly. |
| 75 | * |
| 76 | * Note: We may want to do something clever to ensure the framebuffer |
| 77 | * region is aligned such that we don't change dcache policy for other |
| 78 | * stuff inadvertantly. |
| 79 | * |
| 80 | * FIXME: Is disabling/re-enabling the MMU entirely necessary? |
| 81 | */ |
| 82 | uint32_t lower = ALIGN_DOWN(lcdbase, MiB); |
| 83 | uint32_t upper = ALIGN_UP(lcdbase + fb_size + 64*KiB, MiB); |
| 84 | dcache_clean_invalidate_by_mva(lower, upper - lower); |
| 85 | dcache_mmu_disable(); |
| 86 | mmu_config_range(lower/MiB, (upper - lower)/MiB, DCACHE_OFF); |
| 87 | dcache_mmu_enable(); |
| 88 | |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 89 | lcdbase += 64*KiB; |
Ronald G. Minnich | e8a9134 | 2013-04-22 10:46:53 -0700 | [diff] [blame] | 90 | mmio_resource(dev, 1, lcdbase/KiB, (fb_size + KiB - 1)/KiB); |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 91 | printk(BIOS_DEBUG, |
Ronald G. Minnich | 2810afa | 2013-04-18 18:09:24 -0700 | [diff] [blame] | 92 | "Initializing exynos VGA, base %p\n", (void *)lcdbase); |
| 93 | memset((void *)lcdbase, 0, fb_size); /* clear the framebuffer */ |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 94 | ret = lcd_ctrl_init(&vi, &panel, (void *)lcdbase); |
| 95 | } |
| 96 | |
David Hendricks | 6802dc8 | 2013-02-15 16:18:28 -0800 | [diff] [blame] | 97 | static void cpu_init(device_t dev) |
| 98 | { |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 99 | exynos_displayport_init(dev); |
David Hendricks | 3cc0d1e | 2013-03-26 16:28:21 -0700 | [diff] [blame] | 100 | ram_resource(dev, 0, RAM_BASE_KB, RAM_SIZE_KB); |
Stefan Reinauer | 043eb0e | 2013-05-10 16:21:58 -0700 | [diff] [blame^] | 101 | |
| 102 | arch_cpu_init(); |
David Hendricks | 6802dc8 | 2013-02-15 16:18:28 -0800 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | static void cpu_noop(device_t dev) |
| 106 | { |
| 107 | } |
| 108 | |
| 109 | static struct device_operations cpu_ops = { |
| 110 | .read_resources = cpu_noop, |
| 111 | .set_resources = cpu_noop, |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 112 | .enable_resources = cpu_init, |
| 113 | .init = cpu_noop, |
David Hendricks | 6802dc8 | 2013-02-15 16:18:28 -0800 | [diff] [blame] | 114 | .scan_bus = 0, |
| 115 | }; |
| 116 | |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 117 | static void enable_exynos5250_dev(device_t dev) |
David Hendricks | 6802dc8 | 2013-02-15 16:18:28 -0800 | [diff] [blame] | 118 | { |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 119 | dev->ops = &cpu_ops; |
David Hendricks | 6802dc8 | 2013-02-15 16:18:28 -0800 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | struct chip_operations cpu_samsung_exynos5250_ops = { |
| 123 | CHIP_NAME("CPU Samsung Exynos 5250") |
Ronald G. Minnich | b48605d | 2013-04-09 14:35:35 -0700 | [diff] [blame] | 124 | .enable_dev = enable_exynos5250_dev, |
David Hendricks | 6802dc8 | 2013-02-15 16:18:28 -0800 | [diff] [blame] | 125 | }; |
David Hendricks | c01d138 | 2013-03-28 19:04:58 -0700 | [diff] [blame] | 126 | |
| 127 | void exynos5250_config_l2_cache(void) |
| 128 | { |
| 129 | uint32_t val; |
| 130 | |
| 131 | /* |
| 132 | * Bit 9 - L2 tag RAM setup (1 cycle) |
| 133 | * Bits 8:6 - L2 tag RAM latency (3 cycles) |
| 134 | * Bit 5 - L2 data RAM setup (1 cycle) |
| 135 | * Bits 2:0 - L2 data RAM latency (3 cycles) |
| 136 | */ |
| 137 | val = (1 << 9) | (0x2 << 6) | (1 << 5) | (0x2); |
| 138 | write_l2ctlr(val); |
| 139 | } |