blob: d209a762fc610f18342ad4a1a437f68449878fc9 [file] [log] [blame]
Ronald G. Minnichf89e6b22012-12-10 16:13:43 -08001/*
Stefan Reinauer043eb0e2013-05-10 16:21:58 -07002 * This file is part of the coreboot project.
Ronald G. Minnichf89e6b22012-12-10 16:13:43 -08003 *
Stefan Reinauer08dc3572013-05-14 16:57:50 -07004 * Copyright 2013 Google Inc.
Stefan Reinauer043eb0e2013-05-10 16:21:58 -07005 *
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.
Ronald G. Minnichf89e6b22012-12-10 16:13:43 -08009 *
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
Stefan Reinauer043eb0e2013-05-10 16:21:58 -070017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Ronald G. Minnichf89e6b22012-12-10 16:13:43 -080018 */
19
David Hendricks50c0a502013-01-31 17:05:50 -080020#include <console/console.h>
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -070021#include <device/device.h>
22#include <device/i2c.h>
23#include <drivers/ti/tps65090/tps65090.h>
24#include <cbmem.h>
25#include <delay.h>
26#include <edid.h>
27#include <vbe.h>
28#include <boot/coreboot_tables.h>
29#include <arch/cache.h>
30#include <arch/exception.h>
Stefan Reinauer08dc3572013-05-14 16:57:50 -070031#include <cpu/samsung/exynos5250/tmu.h>
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -070032#include <cpu/samsung/exynos5250/clk.h>
33#include <cpu/samsung/exynos5250/cpu.h>
David Hendricks0d4f97e2013-02-03 18:09:58 -080034#include <cpu/samsung/exynos5250/gpio.h>
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -070035#include <cpu/samsung/exynos5250/power.h>
Stefan Reinauerb98dec02013-05-14 13:32:33 -070036#include <cpu/samsung/exynos5250/i2c.h>
Stefan Reinauer08dc3572013-05-14 16:57:50 -070037#include <cpu/samsung/exynos5250/dp-core.h>
Julius Werner79bff702013-08-15 17:34:45 -070038#include <cpu/samsung/exynos5250/usb.h>
David Hendricks0d4f97e2013-02-03 18:09:58 -080039
Stefan Reinauer043eb0e2013-05-10 16:21:58 -070040#include "exynos5250.h"
David Hendricks0d4f97e2013-02-03 18:09:58 -080041
Julius Wernerad4556f22013-08-21 17:33:31 -070042#define MMC0_GPIO_PIN (58)
43
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -070044/* convenient shorthand (in MB) */
45#define DRAM_START (CONFIG_SYS_SDRAM_BASE >> 20)
46#define DRAM_SIZE CONFIG_DRAM_SIZE_MB
47#define DRAM_END (DRAM_START + DRAM_SIZE) /* plus one... */
48
Stefan Reinauer043eb0e2013-05-10 16:21:58 -070049static struct edid edid = {
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -070050 .ha = 1366,
51 .va = 768,
52 .bpp = 16,
Gabe Blackdcaaba42013-07-07 04:05:51 -070053 .x_resolution = 1366,
54 .y_resolution = 768,
55 .bytes_per_line = 2 * 1366
David Hendricks0d4f97e2013-02-03 18:09:58 -080056};
57
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -070058/* TODO: transplanted DP stuff, clean up once we have something that works */
59static enum exynos5_gpio_pin dp_pd_l = GPIO_Y25; /* active low */
60static enum exynos5_gpio_pin dp_rst_l = GPIO_X15; /* active low */
61static enum exynos5_gpio_pin dp_hpd = GPIO_X07; /* active high */
62
63static void exynos_dp_bridge_setup(void)
Ronald G. Minnichf89e6b22012-12-10 16:13:43 -080064{
Gabe Blackfe640602013-06-15 20:33:05 -070065 exynos_pinmux_dphpd();
David Hendricks0d4f97e2013-02-03 18:09:58 -080066
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -070067 gpio_set_value(dp_pd_l, 1);
Stefan Reinauerdc006c12013-05-15 14:54:07 -070068 gpio_cfg_pin(dp_pd_l, GPIO_OUTPUT);
69 gpio_set_pull(dp_pd_l, GPIO_PULL_NONE);
David Hendricks0d4f97e2013-02-03 18:09:58 -080070
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -070071 gpio_set_value(dp_rst_l, 0);
Stefan Reinauerdc006c12013-05-15 14:54:07 -070072 gpio_cfg_pin(dp_rst_l, GPIO_OUTPUT);
73 gpio_set_pull(dp_rst_l, GPIO_PULL_NONE);
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -070074 udelay(10);
75 gpio_set_value(dp_rst_l, 1);
Ronald G. Minnichf89e6b22012-12-10 16:13:43 -080076}
77
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -070078static void exynos_dp_bridge_init(void)
79{
80 /* De-assert PD (and possibly RST) to power up the bridge */
81 gpio_set_value(dp_pd_l, 1);
82 gpio_set_value(dp_rst_l, 1);
83
84 /*
85 * We need to wait for 90ms after bringing up the bridge since
86 * there is a phantom "high" on the HPD chip during its
87 * bootup. The phantom high comes within 7ms of de-asserting
88 * PD and persists for at least 15ms. The real high comes
89 * roughly 50ms after PD is de-asserted. The phantom high
90 * makes it hard for us to know when the NXP chip is up.
91 */
92 udelay(90000);
93}
94
95static int exynos_dp_hotplug(void)
96{
97 /* Check HPD. If it's high, we're all good. */
98 return gpio_get_value(dp_hpd) ? 0 : 1;
99}
100
101static void exynos_dp_reset(void)
102{
103 gpio_set_value(dp_pd_l, 0);
104 gpio_set_value(dp_rst_l, 0);
105 /* paranoid delay period (300ms) */
106 udelay(300 * 1000);
107}
108
109/*
110 * This delay is T3 in the LCD timing spec (defined as >200ms). We set
111 * this down to 60ms since that's the approximate maximum amount of time
112 * it'll take a bridge to start outputting LVDS data. The delay of
113 * >200ms is just a conservative value to avoid turning on the backlight
114 * when there's random LCD data on the screen. Shaving 140ms off the
115 * boot is an acceptable trade-off.
116 */
117#define LCD_T3_DELAY_MS 60
118
119#define LCD_T5_DELAY_MS 10
120#define LCD_T6_DELAY_MS 10
121
Stefan Reinauer043eb0e2013-05-10 16:21:58 -0700122static void backlight_pwm(void)
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700123{
124 /*Configure backlight PWM as a simple output high (100% brightness) */
125 gpio_direction_output(GPIO_B20, 1);
126 udelay(LCD_T6_DELAY_MS * 1000);
127}
128
Stefan Reinauer043eb0e2013-05-10 16:21:58 -0700129static void backlight_en(void)
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700130{
Stefan Reinauerdc006c12013-05-15 14:54:07 -0700131 /* Configure GPIO for LCD_BL_EN */
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700132 gpio_direction_output(GPIO_X30, 1);
133}
134
David Hendricks8ccabb62013-08-01 19:12:56 -0700135#define TPS65090_BUS 4 /* Snow-specific */
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700136
137#define FET1_CTRL 0x0f
Julius Wernerad4556f22013-08-21 17:33:31 -0700138#define FET4_CTRL 0x12
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700139#define FET6_CTRL 0x14
140
Stefan Reinauer043eb0e2013-05-10 16:21:58 -0700141static void lcd_vdd(void)
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700142{
143 /* Enable FET6, lcd panel */
David Hendricks8ccabb62013-08-01 19:12:56 -0700144 tps65090_fet_enable(TPS65090_BUS, FET6_CTRL);
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700145}
146
Stefan Reinauer043eb0e2013-05-10 16:21:58 -0700147static void backlight_vdd(void)
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700148{
149 /* Enable FET1, backlight */
David Hendricks8ccabb62013-08-01 19:12:56 -0700150 tps65090_fet_enable(TPS65090_BUS, FET1_CTRL);
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700151 udelay(LCD_T5_DELAY_MS * 1000);
152}
153
Julius Wernerad4556f22013-08-21 17:33:31 -0700154static void sdmmc_vdd(void)
155{
156 /* Enable FET4, P3.3V_SDCARD */
157 tps65090_fet_enable(TPS65090_BUS, FET4_CTRL);
158}
159
Julius Werner79bff702013-08-15 17:34:45 -0700160static enum exynos5_gpio_pin usb_host_vbus = GPIO_X11;
161static enum exynos5_gpio_pin usb_drd_vbus = GPIO_X27;
162/* static enum exynos5_gpio_pin hsic_reset_l = GPIO_E10; */
163
164static void setup_usb(void)
165{
166 /* HSIC not needed in firmware on this board */
167 setup_usb_host_phy(0);
168
169 gpio_direction_output(usb_host_vbus, 1);
170 gpio_direction_output(usb_drd_vbus, 1);
171}
172
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700173//static struct video_info smdk5250_dp_config = {
Stefan Reinauer043eb0e2013-05-10 16:21:58 -0700174static struct video_info dp_video_info = {
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700175 /* FIXME: fix video_info struct to use const for name */
176 .name = (char *)"eDP-LVDS NXP PTN3460",
177
178 .h_sync_polarity = 0,
179 .v_sync_polarity = 0,
180 .interlaced = 0,
181
182 .color_space = COLOR_RGB,
183 .dynamic_range = VESA,
184 .ycbcr_coeff = COLOR_YCBCR601,
185 .color_depth = COLOR_8,
186
187 .link_rate = LINK_RATE_2_70GBPS,
188 .lane_count = LANE_COUNT2,
189};
190
191/* FIXME: move some place more appropriate */
192#define EXYNOS5250_DP1_BASE 0x145b0000
Stefan Reinauer043eb0e2013-05-10 16:21:58 -0700193#define MAX_DP_TRIES 5
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700194
195/*
196 * This function disables the USB3.0 PLL to save power
197 */
198static void disable_usb30_pll(void)
199{
200 enum exynos5_gpio_pin usb3_pll_l = GPIO_Y11;
201
202 gpio_direction_output(usb3_pll_l, 0);
203}
204
Julius Wernerad4556f22013-08-21 17:33:31 -0700205static void setup_storage(void)
206{
207 /* MMC0: Fixed, 8 bit mode, connected with GPIO. */
208 if (clock_set_mshci(PERIPH_ID_SDMMC0))
209 printk(BIOS_CRIT, "%s: Failed to set MMC0 clock.\n", __func__);
210 if (gpio_direction_output(MMC0_GPIO_PIN, 1)) {
211 printk(BIOS_CRIT, "%s: Unable to power on MMC0.\n", __func__);
212 }
213 gpio_set_pull(MMC0_GPIO_PIN, GPIO_PULL_NONE);
214 gpio_set_drv(MMC0_GPIO_PIN, GPIO_DRV_4X);
215 exynos_pinmux_sdmmc0();
216
217 /* MMC2: Removable, 4 bit mode, no GPIO. */
218 /* (Must be after romstage to avoid breaking SDMMC boot.) */
219 clock_set_mshci(PERIPH_ID_SDMMC2);
220 exynos_pinmux_sdmmc2();
221}
222
Gabe Black1387b432013-05-18 15:55:47 -0700223static void gpio_init(void)
224{
225 /* Set up the I2C busses. */
Gabe Blackfe640602013-06-15 20:33:05 -0700226 exynos_pinmux_i2c0();
227 exynos_pinmux_i2c1();
228 exynos_pinmux_i2c2();
229 exynos_pinmux_i2c3();
230 exynos_pinmux_i2c4();
231 exynos_pinmux_i2c7();
Gabe Black1387b432013-05-18 15:55:47 -0700232
233 /* Set up the GPIOs used to arbitrate for I2C bus 4. */
234 gpio_set_pull(GPIO_F03, GPIO_PULL_NONE);
235 gpio_set_pull(GPIO_E04, GPIO_PULL_NONE);
236 gpio_direction_output(GPIO_F03, 1);
237 gpio_direction_input(GPIO_E04);
238
239 /* Set up the GPIO used to enable the audio codec. */
240 gpio_set_pull(GPIO_X17, GPIO_PULL_NONE);
241 gpio_set_pull(GPIO_X15, GPIO_PULL_NONE);
242 gpio_direction_output(GPIO_X17, 1);
243 gpio_direction_output(GPIO_X15, 1);
244
245 /* Set up the I2S busses. */
Gabe Blacke6789c12013-08-05 22:19:36 -0700246 exynos_pinmux_i2s0();
Gabe Blackfe640602013-06-15 20:33:05 -0700247 exynos_pinmux_i2s1();
Gabe Black1387b432013-05-18 15:55:47 -0700248}
249
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700250/* this happens after cpu_init where exynos resources are set */
251static void mainboard_init(device_t dev)
252{
253 int dp_tries;
254 struct s5p_dp_device dp_device = {
255 .base = (struct exynos5_dp *)EXYNOS5250_DP1_BASE,
Stefan Reinauer043eb0e2013-05-10 16:21:58 -0700256 .video_info = &dp_video_info,
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700257 };
Stefan Reinauer66287442013-06-19 15:54:19 -0700258 void *fb_addr = (void *)(get_fb_base_kb() * KiB);
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700259
Gabe Black1387b432013-05-18 15:55:47 -0700260 gpio_init();
Julius Wernerad4556f22013-08-21 17:33:31 -0700261 setup_storage();
Gabe Black1387b432013-05-18 15:55:47 -0700262
David Hendricks8ccabb62013-08-01 19:12:56 -0700263 i2c_init(TPS65090_BUS, I2C_0_SPEED, I2C_SLAVE);
Stefan Reinauer043eb0e2013-05-10 16:21:58 -0700264 i2c_init(7, I2C_0_SPEED, I2C_SLAVE);
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700265
266 tmu_init(&exynos5250_tmu_info);
267
268 /* Clock Gating all the unused IP's to save power */
269 clock_gate();
270
271 /* Disable USB3.0 PLL to save 250mW of power */
272 disable_usb30_pll();
Julius Werner79bff702013-08-15 17:34:45 -0700273 setup_usb();
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700274
Julius Wernerad4556f22013-08-21 17:33:31 -0700275 sdmmc_vdd();
276
Gabe Black1e797bd2013-05-18 15:58:46 -0700277 set_vbe_mode_info_valid(&edid, (uintptr_t)fb_addr);
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700278
Stefan Reinauer043eb0e2013-05-10 16:21:58 -0700279 lcd_vdd();
Stefan Reinauera86c33a2013-05-17 10:34:25 -0700280
281 // FIXME: should timeout
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700282 do {
283 udelay(50);
284 } while (!exynos_dp_hotplug());
285
286 exynos_dp_bridge_setup();
Stefan Reinauer043eb0e2013-05-10 16:21:58 -0700287 for (dp_tries = 1; dp_tries <= MAX_DP_TRIES; dp_tries++) {
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700288 exynos_dp_bridge_init();
289 if (exynos_dp_hotplug()) {
290 exynos_dp_reset();
291 continue;
292 }
293
294 if (dp_controller_init(&dp_device))
295 continue;
296
297 udelay(LCD_T3_DELAY_MS * 1000);
298
Stefan Reinauer043eb0e2013-05-10 16:21:58 -0700299 backlight_vdd();
300 backlight_pwm();
301 backlight_en();
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700302 /* if we're here, we're successful */
303 break;
304 }
305
Stefan Reinauer043eb0e2013-05-10 16:21:58 -0700306 if (dp_tries > MAX_DP_TRIES)
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700307 printk(BIOS_ERR, "%s: Failed to set up displayport\n", __func__);
Stefan Reinauerdc006c12013-05-15 14:54:07 -0700308
Stefan Reinauera86c33a2013-05-17 10:34:25 -0700309 // Uncomment to get excessive GPIO output:
310 // gpio_info();
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700311}
312
313static void mainboard_enable(device_t dev)
314{
315 dev->ops->init = &mainboard_init;
316
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700317 /* set up dcache and MMU */
318 /* FIXME: this should happen via resource allocator */
319 exynos5250_config_l2_cache();
320 mmu_init();
321 mmu_config_range(0, DRAM_START, DCACHE_OFF);
322 mmu_config_range(DRAM_START, DRAM_SIZE, DCACHE_WRITEBACK);
323 mmu_config_range(DRAM_END, 4096 - DRAM_END, DCACHE_OFF);
324 dcache_invalidate_all();
325 dcache_mmu_enable();
326
327 /* this is going to move, but we must have it now and we're
328 * not sure where */
329 exception_init();
330
331 const unsigned epll_hz = 192000000;
332 const unsigned sample_rate = 48000;
333 const unsigned lr_frame_size = 256;
334 clock_epll_set_rate(epll_hz);
335 clock_select_i2s_clk_source();
336 clock_set_i2s_clk_prescaler(epll_hz, sample_rate * lr_frame_size);
337
338 power_enable_xclkout();
339}
340
Ronald G. Minnichf89e6b22012-12-10 16:13:43 -0800341struct chip_operations mainboard_ops = {
Paul Menzel7df4ec02013-02-12 13:12:51 +0100342 .name = "Samsung/Google ARM Chromebook",
Ronald G. Minnichf89e6b22012-12-10 16:13:43 -0800343 .enable_dev = mainboard_enable,
344};