blob: 2b80d52fcfbcd52a2d57fbec7d4f44c0dc2c0e8a [file] [log] [blame]
Aaron Durbin072e0cc2014-07-14 19:09:23 -05001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2014 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.
Aaron Durbin072e0cc2014-07-14 19:09:23 -050014 */
15
16#include <arch/io.h>
Julius Wernerf1e32102014-11-25 13:22:20 -080017#include <bootblock_common.h>
Aaron Durbin072e0cc2014-07-14 19:09:23 -050018#include <console/console.h>
19#include <device/i2c.h>
20#include <soc/addressmap.h>
Julius Werner96195ee2014-10-20 13:25:21 -070021#include <soc/clk_rst.h>
Aaron Durbin072e0cc2014-07-14 19:09:23 -050022#include <soc/clock.h>
Aaron Durbin65627dd2014-08-13 13:27:14 -050023#include <soc/funitcfg.h>
Aaron Durbin072e0cc2014-07-14 19:09:23 -050024#include <soc/nvidia/tegra/i2c.h>
Julius Werner96195ee2014-10-20 13:25:21 -070025#include <soc/padconfig.h>
Aaron Durbin072e0cc2014-07-14 19:09:23 -050026
27#include "pmic.h"
28
Aaron Durbin6ecf3f62014-08-01 15:11:11 -050029static const struct pad_config uart_console_pads[] = {
Aaron Durbine68ee3b2014-08-06 15:27:12 -050030 /* UARTA: tx and rx. */
31 PAD_CFG_SFIO(KB_ROW9, PINMUX_PULL_NONE, UA3),
Aaron Durbin6ecf3f62014-08-01 15:11:11 -050032 PAD_CFG_SFIO(KB_ROW10, PINMUX_INPUT_ENABLE | PINMUX_PULL_UP, UA3),
33 /*
34 * Disable UART2 pads as they are default connected to UARTA controller.
35 */
36 PAD_CFG_UNUSED(UART2_RXD),
37 PAD_CFG_UNUSED(UART2_TXD),
38 PAD_CFG_UNUSED(UART2_RTS_N),
39 PAD_CFG_UNUSED(UART2_CTS_N),
40};
41
Aaron Durbin65627dd2014-08-13 13:27:14 -050042static const struct pad_config pmic_pads[] = {
43 PAD_CFG_SFIO(PWR_I2C_SCL, PINMUX_INPUT_ENABLE, I2CPMU),
44 PAD_CFG_SFIO(PWR_I2C_SDA, PINMUX_INPUT_ENABLE, I2CPMU),
45};
46
47static const struct pad_config spiflash_pads[] = {
48 /* mosi, miso, clk, cs0 */
49 PAD_CFG_SFIO(GPIO_PG6, PINMUX_INPUT_ENABLE | PINMUX_PULL_UP, SPI4),
50 PAD_CFG_SFIO(GPIO_PG7, PINMUX_INPUT_ENABLE | PINMUX_PULL_UP, SPI4),
51 PAD_CFG_SFIO(GPIO_PG5, PINMUX_INPUT_ENABLE, SPI4),
52 PAD_CFG_SFIO(GPIO_PI3, PINMUX_INPUT_ENABLE, SPI4),
53};
54
55static const struct funit_cfg funits[] = {
56 /* PMIC on I2C5 (PWR_I2C* pads) at 400kHz. */
57 FUNIT_CFG(I2C5, PLLP, 400, pmic_pads, ARRAY_SIZE(pmic_pads)),
58 /* SPI flash at 33MHz on SPI4 controller. */
59 FUNIT_CFG(SBC4, PLLP, 33333, spiflash_pads, ARRAY_SIZE(spiflash_pads)),
60};
61
Aaron Durbin6ecf3f62014-08-01 15:11:11 -050062void bootblock_mainboard_early_init(void)
63{
64 soc_configure_pads(uart_console_pads, ARRAY_SIZE(uart_console_pads));
65}
66
Aaron Durbin072e0cc2014-07-14 19:09:23 -050067static void set_clock_sources(void)
68{
69 /* UARTA gets PLLP, deactivate CLK_UART_DIV_OVERRIDE */
Julius Werner2f37bd62015-02-19 14:51:15 -080070 write32(CLK_RST_REG(clk_src_uarta), PLLP << CLK_SOURCE_SHIFT);
Aaron Durbin072e0cc2014-07-14 19:09:23 -050071}
72
Aaron Durbind0f9f742014-08-01 16:11:48 -050073static const struct pad_config padcfgs[] = {
74 /* Board build id bits 1:0 */
75 PAD_CFG_GPIO_INPUT(KB_COL4, PINMUX_PULL_NONE),
76 PAD_CFG_GPIO_INPUT(KB_COL3, PINMUX_PULL_NONE),
Aaron Durbind0f9f742014-08-01 16:11:48 -050077};
78
Aaron Durbin072e0cc2014-07-14 19:09:23 -050079void bootblock_mainboard_init(void)
80{
81 set_clock_sources();
82
Aaron Durbin65627dd2014-08-13 13:27:14 -050083 /* Set up controllers and pads to load romstage. */
84 soc_configure_funits(funits, ARRAY_SIZE(funits));
Aaron Durbind0f9f742014-08-01 16:11:48 -050085 soc_configure_pads(padcfgs, ARRAY_SIZE(padcfgs));
Aaron Durbin072e0cc2014-07-14 19:09:23 -050086
Aaron Durbin175c6362014-08-21 14:54:45 -050087 i2c_init(I2CPWR_BUS);
88 pmic_init(I2CPWR_BUS);
Aaron Durbin072e0cc2014-07-14 19:09:23 -050089}