blob: 0adadb6649858c040717070ae5453765ad89948a [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>
Hung-Te Lin22d0ca02013-09-27 12:45:45 +080030#include <soc/samsung/exynos5250/tmu.h>
31#include <soc/samsung/exynos5250/clk.h>
32#include <soc/samsung/exynos5250/gpio.h>
33#include <soc/samsung/exynos5250/power.h>
34#include <soc/samsung/exynos5250/i2c.h>
35#include <soc/samsung/exynos5250/dp-core.h>
36#include <soc/samsung/exynos5250/dp.h>
37#include <soc/samsung/exynos5250/usb.h>
David Hendricks0d4f97e2013-02-03 18:09:58 -080038
Stefan Reinauer043eb0e2013-05-10 16:21:58 -070039#include "exynos5250.h"
David Hendricks0d4f97e2013-02-03 18:09:58 -080040
Julius Wernerad4556f22013-08-21 17:33:31 -070041#define MMC0_GPIO_PIN (58)
42
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -070043/* 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
Julius Wernerb8fad3d2013-08-27 15:48:32 -070048/* Arbitrary range of DMA memory for depthcharge's drivers */
49#define DMA_START (0x77300000)
50#define DMA_SIZE (0x00100000)
51
Stefan Reinauer043eb0e2013-05-10 16:21:58 -070052static struct edid edid = {
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -070053 .ha = 1366,
54 .va = 768,
Ronald G. Minnich9518b562013-09-19 16:45:22 -070055 .framebuffer_bits_per_pixel = 16,
Gabe Blackdcaaba42013-07-07 04:05:51 -070056 .x_resolution = 1366,
57 .y_resolution = 768,
58 .bytes_per_line = 2 * 1366
David Hendricks0d4f97e2013-02-03 18:09:58 -080059};
60
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -070061/* TODO: transplanted DP stuff, clean up once we have something that works */
62static enum exynos5_gpio_pin dp_pd_l = GPIO_Y25; /* active low */
63static enum exynos5_gpio_pin dp_rst_l = GPIO_X15; /* active low */
64static enum exynos5_gpio_pin dp_hpd = GPIO_X07; /* active high */
65
66static void exynos_dp_bridge_setup(void)
Ronald G. Minnichf89e6b22012-12-10 16:13:43 -080067{
Gabe Blackfe640602013-06-15 20:33:05 -070068 exynos_pinmux_dphpd();
David Hendricks0d4f97e2013-02-03 18:09:58 -080069
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -070070 gpio_set_value(dp_pd_l, 1);
Stefan Reinauerdc006c12013-05-15 14:54:07 -070071 gpio_cfg_pin(dp_pd_l, GPIO_OUTPUT);
72 gpio_set_pull(dp_pd_l, GPIO_PULL_NONE);
David Hendricks0d4f97e2013-02-03 18:09:58 -080073
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -070074 gpio_set_value(dp_rst_l, 0);
Stefan Reinauerdc006c12013-05-15 14:54:07 -070075 gpio_cfg_pin(dp_rst_l, GPIO_OUTPUT);
76 gpio_set_pull(dp_rst_l, GPIO_PULL_NONE);
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -070077 udelay(10);
78 gpio_set_value(dp_rst_l, 1);
Ronald G. Minnichf89e6b22012-12-10 16:13:43 -080079}
80
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -070081static void exynos_dp_bridge_init(void)
82{
83 /* De-assert PD (and possibly RST) to power up the bridge */
84 gpio_set_value(dp_pd_l, 1);
85 gpio_set_value(dp_rst_l, 1);
86
87 /*
88 * We need to wait for 90ms after bringing up the bridge since
89 * there is a phantom "high" on the HPD chip during its
90 * bootup. The phantom high comes within 7ms of de-asserting
91 * PD and persists for at least 15ms. The real high comes
92 * roughly 50ms after PD is de-asserted. The phantom high
93 * makes it hard for us to know when the NXP chip is up.
94 */
95 udelay(90000);
96}
97
98static int exynos_dp_hotplug(void)
99{
100 /* Check HPD. If it's high, we're all good. */
101 return gpio_get_value(dp_hpd) ? 0 : 1;
102}
103
104static void exynos_dp_reset(void)
105{
106 gpio_set_value(dp_pd_l, 0);
107 gpio_set_value(dp_rst_l, 0);
108 /* paranoid delay period (300ms) */
109 udelay(300 * 1000);
110}
111
112/*
113 * This delay is T3 in the LCD timing spec (defined as >200ms). We set
114 * this down to 60ms since that's the approximate maximum amount of time
115 * it'll take a bridge to start outputting LVDS data. The delay of
116 * >200ms is just a conservative value to avoid turning on the backlight
117 * when there's random LCD data on the screen. Shaving 140ms off the
118 * boot is an acceptable trade-off.
119 */
120#define LCD_T3_DELAY_MS 60
121
122#define LCD_T5_DELAY_MS 10
123#define LCD_T6_DELAY_MS 10
124
Stefan Reinauer043eb0e2013-05-10 16:21:58 -0700125static void backlight_pwm(void)
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700126{
127 /*Configure backlight PWM as a simple output high (100% brightness) */
128 gpio_direction_output(GPIO_B20, 1);
129 udelay(LCD_T6_DELAY_MS * 1000);
130}
131
Stefan Reinauer043eb0e2013-05-10 16:21:58 -0700132static void backlight_en(void)
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700133{
Stefan Reinauerdc006c12013-05-15 14:54:07 -0700134 /* Configure GPIO for LCD_BL_EN */
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700135 gpio_direction_output(GPIO_X30, 1);
136}
137
Gabe Black49c98dc2014-01-22 21:06:32 -0800138#define TPS65090_BUS 4 /* Daisy-specific */
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700139
140#define FET1_CTRL 0x0f
Julius Wernerad4556f22013-08-21 17:33:31 -0700141#define FET4_CTRL 0x12
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700142#define FET6_CTRL 0x14
143
Stefan Reinauer043eb0e2013-05-10 16:21:58 -0700144static void lcd_vdd(void)
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700145{
146 /* Enable FET6, lcd panel */
David Hendricks8ccabb62013-08-01 19:12:56 -0700147 tps65090_fet_enable(TPS65090_BUS, FET6_CTRL);
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700148}
149
Stefan Reinauer043eb0e2013-05-10 16:21:58 -0700150static void backlight_vdd(void)
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700151{
152 /* Enable FET1, backlight */
David Hendricks8ccabb62013-08-01 19:12:56 -0700153 tps65090_fet_enable(TPS65090_BUS, FET1_CTRL);
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700154 udelay(LCD_T5_DELAY_MS * 1000);
155}
156
Julius Wernerad4556f22013-08-21 17:33:31 -0700157static void sdmmc_vdd(void)
158{
159 /* Enable FET4, P3.3V_SDCARD */
160 tps65090_fet_enable(TPS65090_BUS, FET4_CTRL);
161}
162
Julius Werner79bff702013-08-15 17:34:45 -0700163static enum exynos5_gpio_pin usb_host_vbus = GPIO_X11;
164static enum exynos5_gpio_pin usb_drd_vbus = GPIO_X27;
165/* static enum exynos5_gpio_pin hsic_reset_l = GPIO_E10; */
166
Julius Werner68aef112013-09-03 15:07:31 -0700167static void prepare_usb(void)
168{
169 /* Kick this reset off early so it gets at least 100ms to settle */
170 reset_usb_drd_dwc3();
171}
172
Julius Werner79bff702013-08-15 17:34:45 -0700173static void setup_usb(void)
174{
175 /* HSIC not needed in firmware on this board */
Julius Werner68aef112013-09-03 15:07:31 -0700176 setup_usb_drd_phy();
177 setup_usb_drd_dwc3();
Julius Werner79bff702013-08-15 17:34:45 -0700178 setup_usb_host_phy(0);
179
180 gpio_direction_output(usb_host_vbus, 1);
181 gpio_direction_output(usb_drd_vbus, 1);
182}
183
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700184//static struct video_info smdk5250_dp_config = {
Stefan Reinauer043eb0e2013-05-10 16:21:58 -0700185static struct video_info dp_video_info = {
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700186 /* FIXME: fix video_info struct to use const for name */
187 .name = (char *)"eDP-LVDS NXP PTN3460",
188
189 .h_sync_polarity = 0,
190 .v_sync_polarity = 0,
191 .interlaced = 0,
192
193 .color_space = COLOR_RGB,
194 .dynamic_range = VESA,
195 .ycbcr_coeff = COLOR_YCBCR601,
196 .color_depth = COLOR_8,
197
198 .link_rate = LINK_RATE_2_70GBPS,
199 .lane_count = LANE_COUNT2,
200};
201
202/* FIXME: move some place more appropriate */
Stefan Reinauer043eb0e2013-05-10 16:21:58 -0700203#define MAX_DP_TRIES 5
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700204
205/*
206 * This function disables the USB3.0 PLL to save power
207 */
208static void disable_usb30_pll(void)
209{
210 enum exynos5_gpio_pin usb3_pll_l = GPIO_Y11;
211
212 gpio_direction_output(usb3_pll_l, 0);
213}
214
Julius Wernerad4556f22013-08-21 17:33:31 -0700215static void setup_storage(void)
216{
217 /* MMC0: Fixed, 8 bit mode, connected with GPIO. */
218 if (clock_set_mshci(PERIPH_ID_SDMMC0))
219 printk(BIOS_CRIT, "%s: Failed to set MMC0 clock.\n", __func__);
220 if (gpio_direction_output(MMC0_GPIO_PIN, 1)) {
221 printk(BIOS_CRIT, "%s: Unable to power on MMC0.\n", __func__);
222 }
223 gpio_set_pull(MMC0_GPIO_PIN, GPIO_PULL_NONE);
224 gpio_set_drv(MMC0_GPIO_PIN, GPIO_DRV_4X);
225 exynos_pinmux_sdmmc0();
226
227 /* MMC2: Removable, 4 bit mode, no GPIO. */
228 /* (Must be after romstage to avoid breaking SDMMC boot.) */
229 clock_set_mshci(PERIPH_ID_SDMMC2);
230 exynos_pinmux_sdmmc2();
231}
232
Gabe Black1387b432013-05-18 15:55:47 -0700233static void gpio_init(void)
234{
235 /* Set up the I2C busses. */
Gabe Blackfe640602013-06-15 20:33:05 -0700236 exynos_pinmux_i2c0();
237 exynos_pinmux_i2c1();
238 exynos_pinmux_i2c2();
239 exynos_pinmux_i2c3();
240 exynos_pinmux_i2c4();
241 exynos_pinmux_i2c7();
Gabe Black1387b432013-05-18 15:55:47 -0700242
243 /* Set up the GPIOs used to arbitrate for I2C bus 4. */
244 gpio_set_pull(GPIO_F03, GPIO_PULL_NONE);
245 gpio_set_pull(GPIO_E04, GPIO_PULL_NONE);
246 gpio_direction_output(GPIO_F03, 1);
247 gpio_direction_input(GPIO_E04);
248
249 /* Set up the GPIO used to enable the audio codec. */
250 gpio_set_pull(GPIO_X17, GPIO_PULL_NONE);
251 gpio_set_pull(GPIO_X15, GPIO_PULL_NONE);
252 gpio_direction_output(GPIO_X17, 1);
253 gpio_direction_output(GPIO_X15, 1);
254
255 /* Set up the I2S busses. */
Gabe Blacke6789c12013-08-05 22:19:36 -0700256 exynos_pinmux_i2s0();
Gabe Blackfe640602013-06-15 20:33:05 -0700257 exynos_pinmux_i2s1();
Gabe Black1387b432013-05-18 15:55:47 -0700258}
259
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700260/* this happens after cpu_init where exynos resources are set */
261static void mainboard_init(device_t dev)
262{
263 int dp_tries;
264 struct s5p_dp_device dp_device = {
Julius Wernerfa938c72013-08-29 14:17:36 -0700265 .base = exynos_dp1,
Stefan Reinauer043eb0e2013-05-10 16:21:58 -0700266 .video_info = &dp_video_info,
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700267 };
Stefan Reinauer66287442013-06-19 15:54:19 -0700268 void *fb_addr = (void *)(get_fb_base_kb() * KiB);
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700269
Julius Werner68aef112013-09-03 15:07:31 -0700270 prepare_usb();
Gabe Black1387b432013-05-18 15:55:47 -0700271 gpio_init();
Julius Wernerad4556f22013-08-21 17:33:31 -0700272 setup_storage();
Gabe Black1387b432013-05-18 15:55:47 -0700273
David Hendricks8ccabb62013-08-01 19:12:56 -0700274 i2c_init(TPS65090_BUS, I2C_0_SPEED, I2C_SLAVE);
Stefan Reinauer043eb0e2013-05-10 16:21:58 -0700275 i2c_init(7, I2C_0_SPEED, I2C_SLAVE);
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700276
277 tmu_init(&exynos5250_tmu_info);
278
279 /* Clock Gating all the unused IP's to save power */
280 clock_gate();
281
282 /* Disable USB3.0 PLL to save 250mW of power */
283 disable_usb30_pll();
284
Julius Wernerad4556f22013-08-21 17:33:31 -0700285 sdmmc_vdd();
286
Gabe Black1e797bd2013-05-18 15:58:46 -0700287 set_vbe_mode_info_valid(&edid, (uintptr_t)fb_addr);
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700288
Stefan Reinauer043eb0e2013-05-10 16:21:58 -0700289 lcd_vdd();
Stefan Reinauera86c33a2013-05-17 10:34:25 -0700290
291 // FIXME: should timeout
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700292 do {
293 udelay(50);
294 } while (!exynos_dp_hotplug());
295
296 exynos_dp_bridge_setup();
Stefan Reinauer043eb0e2013-05-10 16:21:58 -0700297 for (dp_tries = 1; dp_tries <= MAX_DP_TRIES; dp_tries++) {
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700298 exynos_dp_bridge_init();
299 if (exynos_dp_hotplug()) {
300 exynos_dp_reset();
301 continue;
302 }
303
304 if (dp_controller_init(&dp_device))
305 continue;
306
307 udelay(LCD_T3_DELAY_MS * 1000);
308
Stefan Reinauer043eb0e2013-05-10 16:21:58 -0700309 backlight_vdd();
310 backlight_pwm();
311 backlight_en();
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700312 /* if we're here, we're successful */
313 break;
314 }
315
Stefan Reinauer043eb0e2013-05-10 16:21:58 -0700316 if (dp_tries > MAX_DP_TRIES)
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700317 printk(BIOS_ERR, "%s: Failed to set up displayport\n", __func__);
Stefan Reinauerdc006c12013-05-15 14:54:07 -0700318
Julius Werner68aef112013-09-03 15:07:31 -0700319 setup_usb();
320
Stefan Reinauera86c33a2013-05-17 10:34:25 -0700321 // Uncomment to get excessive GPIO output:
322 // gpio_info();
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700323}
324
325static void mainboard_enable(device_t dev)
326{
327 dev->ops->init = &mainboard_init;
328
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700329 /* set up dcache and MMU */
330 /* FIXME: this should happen via resource allocator */
331 exynos5250_config_l2_cache();
332 mmu_init();
333 mmu_config_range(0, DRAM_START, DCACHE_OFF);
334 mmu_config_range(DRAM_START, DRAM_SIZE, DCACHE_WRITEBACK);
Julius Wernerb8fad3d2013-08-27 15:48:32 -0700335 mmu_config_range(DMA_START >> 20, DMA_SIZE >> 20, DCACHE_OFF);
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700336 mmu_config_range(DRAM_END, 4096 - DRAM_END, DCACHE_OFF);
337 dcache_invalidate_all();
338 dcache_mmu_enable();
339
Stefan Reinauer2ae6d6f2013-05-09 16:16:13 -0700340 const unsigned epll_hz = 192000000;
341 const unsigned sample_rate = 48000;
342 const unsigned lr_frame_size = 256;
343 clock_epll_set_rate(epll_hz);
344 clock_select_i2s_clk_source();
345 clock_set_i2s_clk_prescaler(epll_hz, sample_rate * lr_frame_size);
346
347 power_enable_xclkout();
348}
349
Ronald G. Minnichf89e6b22012-12-10 16:13:43 -0800350struct chip_operations mainboard_ops = {
Paul Menzel7df4ec02013-02-12 13:12:51 +0100351 .name = "Samsung/Google ARM Chromebook",
Ronald G. Minnichf89e6b22012-12-10 16:13:43 -0800352 .enable_dev = mainboard_enable,
353};
Julius Wernerb8fad3d2013-08-27 15:48:32 -0700354
355void lb_board(struct lb_header *header)
356{
357 struct lb_range *dma;
358
359 dma = (struct lb_range *)lb_new_record(header);
360 dma->tag = LB_TAB_DMA;
361 dma->size = sizeof(*dma);
362 dma->range_start = (intptr_t)DMA_START;
363 dma->range_size = DMA_SIZE;
364}