Gabe Black | d3163ab | 2013-05-16 05:53:40 -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 <console/console.h> |
| 21 | #include <device/device.h> |
| 22 | #include <device/i2c.h> |
Gabe Black | d3163ab | 2013-05-16 05:53:40 -0700 | [diff] [blame] | 23 | #include <cbmem.h> |
| 24 | #include <delay.h> |
| 25 | #include <edid.h> |
| 26 | #include <vbe.h> |
| 27 | #include <boot/coreboot_tables.h> |
| 28 | #include <arch/cache.h> |
| 29 | #include <arch/exception.h> |
| 30 | #include <cpu/samsung/exynos5420/tmu.h> |
| 31 | #include <cpu/samsung/exynos5420/clk.h> |
| 32 | #include <cpu/samsung/exynos5420/cpu.h> |
| 33 | #include <cpu/samsung/exynos5420/gpio.h> |
| 34 | #include <cpu/samsung/exynos5420/power.h> |
| 35 | #include <cpu/samsung/exynos5420/i2c.h> |
| 36 | #include <cpu/samsung/exynos5420/dp-core.h> |
Gabe Black | d686acd | 2013-06-30 05:19:53 -0700 | [diff] [blame^] | 37 | #include <drivers/parade/ps8625/ps8625.h> |
Gabe Black | c0b2144 | 2013-06-28 14:27:16 -0700 | [diff] [blame] | 38 | #include <ec/google/chromeec/ec.h> |
Gabe Black | d686acd | 2013-06-30 05:19:53 -0700 | [diff] [blame^] | 39 | #include <stdlib.h> |
Gabe Black | d3163ab | 2013-05-16 05:53:40 -0700 | [diff] [blame] | 40 | |
| 41 | #include "exynos5420.h" |
| 42 | |
| 43 | /* convenient shorthand (in MB) */ |
| 44 | #define DRAM_START (CONFIG_SYS_SDRAM_BASE >> 20) |
| 45 | #define DRAM_SIZE CONFIG_DRAM_SIZE_MB |
| 46 | #define DRAM_END (DRAM_START + DRAM_SIZE) /* plus one... */ |
| 47 | |
| 48 | static struct edid edid = { |
| 49 | .ha = 1366, |
| 50 | .va = 768, |
| 51 | .bpp = 16, |
| 52 | }; |
| 53 | |
| 54 | /* TODO: transplanted DP stuff, clean up once we have something that works */ |
Gabe Black | 63bb610 | 2013-06-19 03:29:45 -0700 | [diff] [blame] | 55 | static enum exynos5_gpio_pin dp_pd_l = GPIO_X35; /* active low */ |
| 56 | static enum exynos5_gpio_pin dp_rst_l = GPIO_Y77; /* active low */ |
| 57 | static enum exynos5_gpio_pin dp_hpd = GPIO_X26; /* active high */ |
| 58 | static enum exynos5_gpio_pin bl_pwm = GPIO_B20; /* active high */ |
| 59 | static enum exynos5_gpio_pin bl_en = GPIO_X22; /* active high */ |
Gabe Black | d3163ab | 2013-05-16 05:53:40 -0700 | [diff] [blame] | 60 | |
Gabe Black | d686acd | 2013-06-30 05:19:53 -0700 | [diff] [blame^] | 61 | static void parade_dp_bridge_setup(void) |
Gabe Black | d3163ab | 2013-05-16 05:53:40 -0700 | [diff] [blame] | 62 | { |
Gabe Black | d3163ab | 2013-05-16 05:53:40 -0700 | [diff] [blame] | 63 | gpio_set_value(dp_pd_l, 1); |
| 64 | gpio_cfg_pin(dp_pd_l, GPIO_OUTPUT); |
| 65 | gpio_set_pull(dp_pd_l, GPIO_PULL_NONE); |
| 66 | |
| 67 | gpio_set_value(dp_rst_l, 0); |
| 68 | gpio_cfg_pin(dp_rst_l, GPIO_OUTPUT); |
| 69 | gpio_set_pull(dp_rst_l, GPIO_PULL_NONE); |
| 70 | udelay(10); |
| 71 | gpio_set_value(dp_rst_l, 1); |
Gabe Black | c0b2144 | 2013-06-28 14:27:16 -0700 | [diff] [blame] | 72 | |
| 73 | gpio_cfg_pin(dp_hpd, GPIO_INPUT); |
Gabe Black | d3163ab | 2013-05-16 05:53:40 -0700 | [diff] [blame] | 74 | |
Gabe Black | d686acd | 2013-06-30 05:19:53 -0700 | [diff] [blame^] | 75 | /* De-assert PD (and possibly RST) to power up the bridge. */ |
Gabe Black | d3163ab | 2013-05-16 05:53:40 -0700 | [diff] [blame] | 76 | gpio_set_value(dp_pd_l, 1); |
| 77 | gpio_set_value(dp_rst_l, 1); |
| 78 | |
Gabe Black | d686acd | 2013-06-30 05:19:53 -0700 | [diff] [blame^] | 79 | /* Hang around for the bridge to come up. */ |
| 80 | mdelay(40); |
Gabe Black | d3163ab | 2013-05-16 05:53:40 -0700 | [diff] [blame] | 81 | |
Gabe Black | d686acd | 2013-06-30 05:19:53 -0700 | [diff] [blame^] | 82 | /* Configure the bridge chip. */ |
| 83 | exynos_pinmux_i2c7(); |
| 84 | i2c_init(7, 100000, 0x00); |
Gabe Black | d3163ab | 2013-05-16 05:53:40 -0700 | [diff] [blame] | 85 | |
Gabe Black | d686acd | 2013-06-30 05:19:53 -0700 | [diff] [blame^] | 86 | parade_ps8625_bridge_setup(7, 0x48); |
Gabe Black | d3163ab | 2013-05-16 05:53:40 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | /* |
| 90 | * This delay is T3 in the LCD timing spec (defined as >200ms). We set |
| 91 | * this down to 60ms since that's the approximate maximum amount of time |
| 92 | * it'll take a bridge to start outputting LVDS data. The delay of |
| 93 | * >200ms is just a conservative value to avoid turning on the backlight |
| 94 | * when there's random LCD data on the screen. Shaving 140ms off the |
| 95 | * boot is an acceptable trade-off. |
| 96 | */ |
| 97 | #define LCD_T3_DELAY_MS 60 |
| 98 | |
| 99 | #define LCD_T5_DELAY_MS 10 |
| 100 | #define LCD_T6_DELAY_MS 10 |
| 101 | |
| 102 | static void backlight_pwm(void) |
| 103 | { |
| 104 | /*Configure backlight PWM as a simple output high (100% brightness) */ |
Gabe Black | 63bb610 | 2013-06-19 03:29:45 -0700 | [diff] [blame] | 105 | gpio_direction_output(bl_pwm, 1); |
Gabe Black | d3163ab | 2013-05-16 05:53:40 -0700 | [diff] [blame] | 106 | udelay(LCD_T6_DELAY_MS * 1000); |
| 107 | } |
| 108 | |
| 109 | static void backlight_en(void) |
| 110 | { |
| 111 | /* Configure GPIO for LCD_BL_EN */ |
Gabe Black | 63bb610 | 2013-06-19 03:29:45 -0700 | [diff] [blame] | 112 | gpio_direction_output(bl_en, 1); |
Gabe Black | d3163ab | 2013-05-16 05:53:40 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Gabe Black | d3163ab | 2013-05-16 05:53:40 -0700 | [diff] [blame] | 115 | //static struct video_info smdk5420_dp_config = { |
| 116 | static struct video_info dp_video_info = { |
| 117 | /* FIXME: fix video_info struct to use const for name */ |
| 118 | .name = (char *)"eDP-LVDS NXP PTN3460", |
| 119 | |
| 120 | .h_sync_polarity = 0, |
| 121 | .v_sync_polarity = 0, |
| 122 | .interlaced = 0, |
| 123 | |
| 124 | .color_space = COLOR_RGB, |
| 125 | .dynamic_range = VESA, |
| 126 | .ycbcr_coeff = COLOR_YCBCR601, |
| 127 | .color_depth = COLOR_8, |
| 128 | |
| 129 | .link_rate = LINK_RATE_2_70GBPS, |
| 130 | .lane_count = LANE_COUNT2, |
| 131 | }; |
| 132 | |
| 133 | /* FIXME: move some place more appropriate */ |
| 134 | #define EXYNOS5420_DP1_BASE 0x145b0000 |
| 135 | #define MAX_DP_TRIES 5 |
| 136 | |
| 137 | /* |
| 138 | * This function disables the USB3.0 PLL to save power |
| 139 | */ |
| 140 | static void disable_usb30_pll(void) |
| 141 | { |
| 142 | enum exynos5_gpio_pin usb3_pll_l = GPIO_Y11; |
| 143 | |
| 144 | gpio_direction_output(usb3_pll_l, 0); |
| 145 | } |
| 146 | |
Gabe Black | 04d6e01 | 2013-06-23 03:16:46 -0700 | [diff] [blame] | 147 | static void gpio_init(void) |
| 148 | { |
| 149 | /* Set up the I2C busses. */ |
| 150 | exynos_pinmux_i2c2(); |
| 151 | exynos_pinmux_i2c4(); |
| 152 | exynos_pinmux_i2c7(); |
| 153 | exynos_pinmux_i2c8(); |
| 154 | exynos_pinmux_i2c9(); |
| 155 | exynos_pinmux_i2c10(); |
| 156 | } |
| 157 | |
Gabe Black | c0b2144 | 2013-06-28 14:27:16 -0700 | [diff] [blame] | 158 | enum { |
| 159 | FET_CTRL_WAIT = 3 << 2, |
| 160 | FET_CTRL_ADENFET = 1 << 1, |
| 161 | FET_CTRL_ENFET = 1 << 0 |
| 162 | }; |
| 163 | |
| 164 | static void tps65090_thru_ec_fet_set(int index) |
| 165 | { |
| 166 | uint8_t value = FET_CTRL_ADENFET | FET_CTRL_WAIT | FET_CTRL_ENFET; |
| 167 | |
| 168 | if (google_chromeec_i2c_xfer(0x48, 0xe + index, 1, &value, 1, 0)) { |
| 169 | printk(BIOS_ERR, |
| 170 | "Error sending i2c pass through command to EC.\n"); |
| 171 | return; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | static void lcd_vdd(void) |
| 176 | { |
| 177 | /* Enable FET6, lcd panel */ |
| 178 | tps65090_thru_ec_fet_set(6); |
| 179 | } |
| 180 | |
| 181 | static void backlight_vdd(void) |
| 182 | { |
| 183 | /* Enable FET1, backlight */ |
| 184 | tps65090_thru_ec_fet_set(1); |
| 185 | } |
| 186 | |
Gabe Black | d3163ab | 2013-05-16 05:53:40 -0700 | [diff] [blame] | 187 | /* this happens after cpu_init where exynos resources are set */ |
| 188 | static void mainboard_init(device_t dev) |
| 189 | { |
Gabe Black | d3163ab | 2013-05-16 05:53:40 -0700 | [diff] [blame] | 190 | struct s5p_dp_device dp_device = { |
| 191 | .base = (struct exynos5_dp *)EXYNOS5420_DP1_BASE, |
| 192 | .video_info = &dp_video_info, |
| 193 | }; |
| 194 | void *fb_addr; |
| 195 | |
Gabe Black | 04d6e01 | 2013-06-23 03:16:46 -0700 | [diff] [blame] | 196 | gpio_init(); |
| 197 | |
Gabe Black | d3163ab | 2013-05-16 05:53:40 -0700 | [diff] [blame] | 198 | tmu_init(&exynos5420_tmu_info); |
| 199 | |
| 200 | /* Clock Gating all the unused IP's to save power */ |
| 201 | clock_gate(); |
| 202 | |
| 203 | /* Disable USB3.0 PLL to save 250mW of power */ |
| 204 | disable_usb30_pll(); |
| 205 | |
| 206 | fb_addr = cbmem_find(CBMEM_ID_CONSOLE); |
Stefan Reinauer | f175191 | 2013-05-20 15:17:44 -0700 | [diff] [blame] | 207 | set_vbe_mode_info_valid(&edid, (uintptr_t)fb_addr); |
Gabe Black | d3163ab | 2013-05-16 05:53:40 -0700 | [diff] [blame] | 208 | |
Gabe Black | c0b2144 | 2013-06-28 14:27:16 -0700 | [diff] [blame] | 209 | lcd_vdd(); |
Stefan Reinauer | c2c4f84 | 2013-05-20 12:51:02 -0700 | [diff] [blame] | 210 | |
Gabe Black | d686acd | 2013-06-30 05:19:53 -0700 | [diff] [blame^] | 211 | parade_dp_bridge_setup(); |
| 212 | dp_controller_init(&dp_device); |
Gabe Black | d3163ab | 2013-05-16 05:53:40 -0700 | [diff] [blame] | 213 | |
Gabe Black | d686acd | 2013-06-30 05:19:53 -0700 | [diff] [blame^] | 214 | udelay(LCD_T3_DELAY_MS * 1000); |
Gabe Black | d3163ab | 2013-05-16 05:53:40 -0700 | [diff] [blame] | 215 | |
Gabe Black | d686acd | 2013-06-30 05:19:53 -0700 | [diff] [blame^] | 216 | backlight_vdd(); |
| 217 | backlight_pwm(); |
| 218 | backlight_en(); |
Gabe Black | d3163ab | 2013-05-16 05:53:40 -0700 | [diff] [blame] | 219 | |
Stefan Reinauer | c2c4f84 | 2013-05-20 12:51:02 -0700 | [diff] [blame] | 220 | // Uncomment to get excessive GPIO output: |
| 221 | // gpio_info(); |
Gabe Black | d3163ab | 2013-05-16 05:53:40 -0700 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | static void mainboard_enable(device_t dev) |
| 225 | { |
| 226 | dev->ops->init = &mainboard_init; |
| 227 | |
| 228 | /* set up coreboot tables */ |
| 229 | /* FIXME: this should happen somewhere else */ |
| 230 | high_tables_size = CONFIG_COREBOOT_TABLES_SIZE; |
| 231 | high_tables_base = CONFIG_SYS_SDRAM_BASE + |
| 232 | ((unsigned)CONFIG_DRAM_SIZE_MB << 20ULL) - |
| 233 | CONFIG_COREBOOT_TABLES_SIZE; |
| 234 | cbmem_init(high_tables_base, high_tables_size); |
| 235 | |
| 236 | /* set up dcache and MMU */ |
| 237 | /* FIXME: this should happen via resource allocator */ |
| 238 | exynos5420_config_l2_cache(); |
| 239 | mmu_init(); |
| 240 | mmu_config_range(0, DRAM_START, DCACHE_OFF); |
| 241 | mmu_config_range(DRAM_START, DRAM_SIZE, DCACHE_WRITEBACK); |
| 242 | mmu_config_range(DRAM_END, 4096 - DRAM_END, DCACHE_OFF); |
| 243 | dcache_invalidate_all(); |
| 244 | dcache_mmu_enable(); |
| 245 | |
| 246 | /* this is going to move, but we must have it now and we're |
| 247 | * not sure where */ |
| 248 | exception_init(); |
| 249 | |
| 250 | const unsigned epll_hz = 192000000; |
| 251 | const unsigned sample_rate = 48000; |
| 252 | const unsigned lr_frame_size = 256; |
| 253 | clock_epll_set_rate(epll_hz); |
| 254 | clock_select_i2s_clk_source(); |
| 255 | clock_set_i2s_clk_prescaler(epll_hz, sample_rate * lr_frame_size); |
| 256 | |
| 257 | power_enable_xclkout(); |
| 258 | } |
| 259 | |
| 260 | struct chip_operations mainboard_ops = { |
| 261 | .name = "Samsung/Google ARM Chromebook", |
| 262 | .enable_dev = mainboard_enable, |
| 263 | }; |