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. |
Ronald G. Minnich | b0efbd3 | 2013-08-05 15:56:37 -0700 | [diff] [blame] | 5 | * Copyright (C) 2012 Samsung Electronics |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -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. |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
Julius Werner | 80af442 | 2014-10-20 13:18:56 -0700 | [diff] [blame] | 17 | #include <arch/cache.h> |
| 18 | #include <cbmem.h> |
| 19 | #include <console/console.h> |
| 20 | #include <delay.h> |
| 21 | #include <device/device.h> |
| 22 | #include <ec/google/chromeec/ec.h> |
| 23 | #include <soc/dp.h> |
| 24 | #include <soc/fimd.h> |
| 25 | #include <soc/cpu.h> |
| 26 | #include <soc/clk.h> |
| 27 | #include <stddef.h> |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 28 | #include <stdlib.h> |
| 29 | #include <string.h> |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 30 | |
Julius Werner | 80af442 | 2014-10-20 13:18:56 -0700 | [diff] [blame] | 31 | #include "chip.h" |
David Hendricks | c81187f | 2013-08-01 19:09:21 -0700 | [diff] [blame] | 32 | |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 33 | static unsigned int cpu_id; |
| 34 | static unsigned int cpu_rev; |
| 35 | |
| 36 | static void set_cpu_id(void) |
| 37 | { |
Julius Werner | fa938c7 | 2013-08-29 14:17:36 -0700 | [diff] [blame] | 38 | u32 pro_id = (read32((void *)EXYNOS5_PRO_ID) & 0x00FFF000) >> 12; |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 39 | |
David Hendricks | d598cac | 2013-08-01 18:17:55 -0700 | [diff] [blame] | 40 | switch (pro_id) { |
| 41 | case 0x200: |
| 42 | /* Exynos4210 EVT0 */ |
| 43 | cpu_id = 0x4210; |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 44 | cpu_rev = 0; |
David Hendricks | d598cac | 2013-08-01 18:17:55 -0700 | [diff] [blame] | 45 | break; |
| 46 | case 0x210: |
| 47 | /* Exynos4210 EVT1 */ |
| 48 | cpu_id = 0x4210; |
| 49 | break; |
| 50 | case 0x412: |
| 51 | /* Exynos4412 */ |
| 52 | cpu_id = 0x4412; |
| 53 | break; |
| 54 | case 0x520: |
| 55 | /* Exynos5250 */ |
| 56 | cpu_id = 0x5250; |
| 57 | break; |
| 58 | case 0x420: |
| 59 | /* Exynos5420 */ |
| 60 | cpu_id = 0x5420; |
| 61 | break; |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 62 | } |
| 63 | } |
| 64 | |
| 65 | /* we distinguish a display port device from a raw graphics device |
| 66 | * because there are dramatic differences in startup depending on |
| 67 | * graphics usage. To make startup fast and easier to understand and |
| 68 | * debug we explicitly name this common case. The alternate approach, |
| 69 | * involving lots of machine and callbacks, is hard to debug and |
| 70 | * verify. |
| 71 | */ |
Stefan Reinauer | 80e6293 | 2013-07-29 15:52:23 -0700 | [diff] [blame] | 72 | static void exynos_displayport_init(device_t dev, u32 lcdbase, |
| 73 | unsigned long fb_size) |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 74 | { |
Hung-Te Lin | 22d0ca0 | 2013-09-27 12:45:45 +0800 | [diff] [blame] | 75 | struct soc_samsung_exynos5420_config *conf = dev->chip_info; |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 76 | /* put these on the stack. If, at some point, we want to move |
| 77 | * this code to a pre-ram stage, it will be much easier. |
| 78 | */ |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 79 | struct exynos5_fimd_panel panel; |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 80 | memset(&panel, 0, sizeof(panel)); |
| 81 | |
| 82 | panel.is_dp = 1; /* Display I/F is eDP */ |
| 83 | /* while it is true that we did a memset to zero, |
| 84 | * we leave some 'set to zero' entries here to make |
| 85 | * it clear what's going on. Graphics is confusing. |
| 86 | */ |
| 87 | panel.is_mipi = 0; |
| 88 | panel.fixvclk = 0; |
| 89 | panel.ivclk = 0; |
| 90 | panel.clkval_f = conf->clkval_f; |
| 91 | panel.upper_margin = conf->upper_margin; |
| 92 | panel.lower_margin = conf->lower_margin; |
| 93 | panel.vsync = conf->vsync; |
| 94 | panel.left_margin = conf->left_margin; |
| 95 | panel.right_margin = conf->right_margin; |
| 96 | panel.hsync = conf->hsync; |
| 97 | panel.xres = conf->xres; |
| 98 | panel.yres = conf->yres; |
| 99 | |
Stefan Reinauer | 80e6293 | 2013-07-29 15:52:23 -0700 | [diff] [blame] | 100 | printk(BIOS_SPEW, "LCD framebuffer @%p\n", (void *)(lcdbase)); |
Stefan Reinauer | 2d81125 | 2013-05-20 15:24:13 -0700 | [diff] [blame] | 101 | memset((void *)lcdbase, 0, fb_size); /* clear the framebuffer */ |
| 102 | |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 103 | /* |
| 104 | * We need to clean and invalidate the framebuffer region and disable |
| 105 | * caching as well. We assume that our dcache <--> memory address |
| 106 | * space is identity-mapped in 1MB chunks, so align accordingly. |
| 107 | * |
| 108 | * Note: We may want to do something clever to ensure the framebuffer |
| 109 | * region is aligned such that we don't change dcache policy for other |
Martin Roth | 1fc2ba5 | 2014-12-07 14:59:11 -0700 | [diff] [blame] | 110 | * stuff inadvertently. |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 111 | */ |
| 112 | uint32_t lower = ALIGN_DOWN(lcdbase, MiB); |
Stefan Reinauer | f175191 | 2013-05-20 15:17:44 -0700 | [diff] [blame] | 113 | uint32_t upper = ALIGN_UP(lcdbase + fb_size, MiB); |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 114 | |
Julius Werner | f09f224 | 2013-08-28 14:43:14 -0700 | [diff] [blame] | 115 | dcache_clean_invalidate_by_mva((void *)lower, upper - lower); |
Stefan Reinauer | 80e6293 | 2013-07-29 15:52:23 -0700 | [diff] [blame] | 116 | mmu_config_range(lower / MiB, (upper - lower) / MiB, DCACHE_OFF); |
| 117 | |
Edward O'Callaghan | 7116ac8 | 2014-07-08 01:53:24 +1000 | [diff] [blame] | 118 | mmio_resource(dev, 1, lcdbase/KiB, CEIL_DIV(fb_size, KiB)); |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 119 | } |
| 120 | |
David Hendricks | c81187f | 2013-08-01 19:09:21 -0700 | [diff] [blame] | 121 | static void tps65090_thru_ec_fet_disable(int index) |
| 122 | { |
| 123 | uint8_t value = 0; |
| 124 | |
| 125 | if (google_chromeec_i2c_xfer(0x48, 0xe + index, 1, &value, 1, 0)) { |
| 126 | printk(BIOS_ERR, |
| 127 | "Error sending i2c pass through command to EC.\n"); |
| 128 | return; |
| 129 | } |
| 130 | } |
| 131 | |
Stefan Reinauer | 3a0d0d8 | 2013-06-20 16:13:19 -0700 | [diff] [blame] | 132 | static void cpu_enable(device_t dev) |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 133 | { |
Stefan Reinauer | 80e6293 | 2013-07-29 15:52:23 -0700 | [diff] [blame] | 134 | unsigned long fb_size = FB_SIZE_KB * KiB; |
| 135 | u32 lcdbase = get_fb_base_kb() * KiB; |
Stefan Reinauer | 3a0d0d8 | 2013-06-20 16:13:19 -0700 | [diff] [blame] | 136 | |
Stefan Reinauer | 80e6293 | 2013-07-29 15:52:23 -0700 | [diff] [blame] | 137 | 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] | 138 | mmio_resource(dev, 1, lcdbase / KiB, CEIL_DIV(fb_size, KiB)); |
Stefan Reinauer | 80e6293 | 2013-07-29 15:52:23 -0700 | [diff] [blame] | 139 | |
David Hendricks | c81187f | 2013-08-01 19:09:21 -0700 | [diff] [blame] | 140 | /* |
| 141 | * Disable LCD FETs before we do anything with the display. |
| 142 | * FIXME(dhendrix): This is a gross hack and should be done |
| 143 | * elsewhere (romstage?). |
| 144 | */ |
| 145 | tps65090_thru_ec_fet_disable(1); |
| 146 | tps65090_thru_ec_fet_disable(6); |
| 147 | |
Stefan Reinauer | 80e6293 | 2013-07-29 15:52:23 -0700 | [diff] [blame] | 148 | exynos_displayport_init(dev, lcdbase, fb_size); |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 149 | |
| 150 | set_cpu_id(); |
Stefan Reinauer | 3a0d0d8 | 2013-06-20 16:13:19 -0700 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | static void cpu_init(device_t dev) |
| 154 | { |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 155 | printk(BIOS_INFO, "CPU: S5P%X @ %ldMHz\n", |
David Hendricks | 56a7cff | 2013-08-05 18:53:15 -0700 | [diff] [blame] | 156 | cpu_id, get_arm_clk() / 1000000); |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 159 | static struct device_operations cpu_ops = { |
Edward O'Callaghan | 0625a8b | 2014-10-31 08:03:16 +1100 | [diff] [blame] | 160 | .read_resources = DEVICE_NOOP, |
| 161 | .set_resources = DEVICE_NOOP, |
Stefan Reinauer | 3a0d0d8 | 2013-06-20 16:13:19 -0700 | [diff] [blame] | 162 | .enable_resources = cpu_enable, |
| 163 | .init = cpu_init, |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 164 | .scan_bus = 0, |
| 165 | }; |
| 166 | |
| 167 | static void enable_exynos5420_dev(device_t dev) |
| 168 | { |
| 169 | dev->ops = &cpu_ops; |
| 170 | } |
| 171 | |
Gabe Black | d81f409 | 2013-10-08 23:16:51 -0700 | [diff] [blame] | 172 | struct chip_operations soc_samsung_exynos5420_ops = { |
| 173 | CHIP_NAME("SOC Samsung Exynos 5420") |
Gabe Black | 607c0b6 | 2013-05-16 05:45:57 -0700 | [diff] [blame] | 174 | .enable_dev = enable_exynos5420_dev, |
| 175 | }; |