blob: 98c6fb963e7073a9c5992e8f42e7696042c90036 [file] [log] [blame]
Gabe Blackd40be112013-10-09 23:45:07 -07001/*
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.
Gabe Blackd40be112013-10-09 23:45:07 -070014 */
15
Hung-Te Lin2fc3b622013-10-21 21:43:03 +080016#include <arch/io.h>
Gabe Blackd40be112013-10-09 23:45:07 -070017#include <bootblock_common.h>
18#include <console/console.h>
19#include <device/i2c.h>
Julius Wernereaa9c452014-09-24 15:40:49 -070020#include <gpio.h>
Hung-Te Lin2fc3b622013-10-21 21:43:03 +080021#include <soc/addressmap.h>
Julius Wernerf0d21ff32014-10-20 13:24:14 -070022#include <soc/clk_rst.h>
Gabe Blackd40be112013-10-09 23:45:07 -070023#include <soc/clock.h>
24#include <soc/nvidia/tegra/i2c.h>
Julius Wernerf0d21ff32014-10-20 13:24:14 -070025#include <soc/pinmux.h>
26#include <soc/spi.h> /* FIXME: move back to soc code? */
Gabe Blackd40be112013-10-09 23:45:07 -070027
28#include "pmic.h"
29
Hung-Te Lin2fc3b622013-10-21 21:43:03 +080030static struct clk_rst_ctlr *clk_rst = (void *)TEGRA_CLK_RST_BASE;
31
32static void set_clock_sources(void)
33{
34 /* UARTA gets PLLP, deactivate CLK_UART_DIV_OVERRIDE */
Julius Werner2f37bd62015-02-19 14:51:15 -080035 write32(&clk_rst->clk_src_uarta, PLLP << CLK_SOURCE_SHIFT);
Hung-Te Lin2fc3b622013-10-21 21:43:03 +080036
37 clock_configure_source(mselect, PLLP, 102000);
38
Gabe Black41c92602014-03-05 22:07:41 -080039 /* The PMIC is on I2C5 and can run at 400 KHz. */
40 clock_configure_i2c_scl_freq(i2c5, PLLP, 400);
Julius Werneredf6b572013-10-25 17:49:26 -070041
42 /* TODO: We should be able to set this to 50MHz, but that did not seem
43 * reliable. */
44 clock_configure_source(sbc4, PLLP, 33333);
Hung-Te Lin2fc3b622013-10-21 21:43:03 +080045}
46
Gabe Blackd40be112013-10-09 23:45:07 -070047void bootblock_mainboard_init(void)
48{
Hung-Te Lin2fc3b622013-10-21 21:43:03 +080049 set_clock_sources();
Gabe Blackd40be112013-10-09 23:45:07 -070050
Hung-Te Lin2fc3b622013-10-21 21:43:03 +080051 clock_enable_clear_reset(CLK_L_CACHE2 | CLK_L_TMR,
52 CLK_H_I2C5 | CLK_H_APBDMA,
Julius Werneredf6b572013-10-25 17:49:26 -070053 0, CLK_V_MSELECT, 0, 0);
54
55 // Board ID GPIOs, bits 0-3.
56 gpio_input(GPIO(Q3));
57 gpio_input(GPIO(T1));
58 gpio_input(GPIO(X1));
59 gpio_input(GPIO(X4));
Hung-Te Lin2fc3b622013-10-21 21:43:03 +080060
Gabe Blackd40be112013-10-09 23:45:07 -070061 // I2C5 (PMU) clock.
62 pinmux_set_config(PINMUX_PWR_I2C_SCL_INDEX,
63 PINMUX_PWR_I2C_SCL_FUNC_I2CPMU | PINMUX_INPUT_ENABLE);
64 // I2C5 (PMU) data.
65 pinmux_set_config(PINMUX_PWR_I2C_SDA_INDEX,
66 PINMUX_PWR_I2C_SDA_FUNC_I2CPMU | PINMUX_INPUT_ENABLE);
Gabe Blackd40be112013-10-09 23:45:07 -070067 i2c_init(4);
Gabe Blackd40be112013-10-09 23:45:07 -070068 pmic_init(4);
69
70 /* SPI4 data out (MOSI) */
Tom Warren64982c502014-01-23 13:37:50 -070071 pinmux_set_config(PINMUX_GPIO_PG6_INDEX,
72 PINMUX_GPIO_PG6_FUNC_SPI4 | PINMUX_INPUT_ENABLE |
73 PINMUX_PULL_UP);
Gabe Blackd40be112013-10-09 23:45:07 -070074 /* SPI4 data in (MISO) */
Tom Warren64982c502014-01-23 13:37:50 -070075 pinmux_set_config(PINMUX_GPIO_PG7_INDEX,
76 PINMUX_GPIO_PG7_FUNC_SPI4 | PINMUX_INPUT_ENABLE |
77 PINMUX_PULL_UP);
Gabe Blackd40be112013-10-09 23:45:07 -070078 /* SPI4 clock */
Tom Warren64982c502014-01-23 13:37:50 -070079 pinmux_set_config(PINMUX_GPIO_PG5_INDEX,
80 PINMUX_GPIO_PG5_FUNC_SPI4 | PINMUX_INPUT_ENABLE);
Gabe Blackd40be112013-10-09 23:45:07 -070081 /* SPI4 chip select 0 */
Tom Warren64982c502014-01-23 13:37:50 -070082 pinmux_set_config(PINMUX_GPIO_PI3_INDEX,
83 PINMUX_GPIO_PI3_FUNC_SPI4 | PINMUX_INPUT_ENABLE);
Hung-Te Lin2fc3b622013-10-21 21:43:03 +080084
Gabe Blackd40be112013-10-09 23:45:07 -070085 tegra_spi_init(4);
86}