Gabe Black | d40be11 | 2013-10-09 23:45:07 -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. |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 16 | #include <arch/io.h> |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 17 | #include <bootblock_common.h> |
| 18 | #include <console/console.h> |
| 19 | #include <device/i2c.h> |
Julius Werner | eaa9c45 | 2014-09-24 15:40:49 -0700 | [diff] [blame] | 20 | #include <gpio.h> |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 21 | #include <soc/addressmap.h> |
Julius Werner | f0d21ff3 | 2014-10-20 13:24:14 -0700 | [diff] [blame] | 22 | #include <soc/clk_rst.h> |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 23 | #include <soc/clock.h> |
| 24 | #include <soc/nvidia/tegra/i2c.h> |
Julius Werner | f0d21ff3 | 2014-10-20 13:24:14 -0700 | [diff] [blame] | 25 | #include <soc/pinmux.h> |
| 26 | #include <soc/spi.h> /* FIXME: move back to soc code? */ |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 27 | |
| 28 | #include "pmic.h" |
| 29 | |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 30 | static struct clk_rst_ctlr *clk_rst = (void *)TEGRA_CLK_RST_BASE; |
| 31 | |
| 32 | static void set_clock_sources(void) |
| 33 | { |
| 34 | /* UARTA gets PLLP, deactivate CLK_UART_DIV_OVERRIDE */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 35 | write32(&clk_rst->clk_src_uarta, PLLP << CLK_SOURCE_SHIFT); |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 36 | |
| 37 | clock_configure_source(mselect, PLLP, 102000); |
| 38 | |
Gabe Black | 41c9260 | 2014-03-05 22:07:41 -0800 | [diff] [blame] | 39 | /* The PMIC is on I2C5 and can run at 400 KHz. */ |
| 40 | clock_configure_i2c_scl_freq(i2c5, PLLP, 400); |
Julius Werner | edf6b57 | 2013-10-25 17:49:26 -0700 | [diff] [blame] | 41 | |
| 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 Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 45 | } |
| 46 | |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 47 | void bootblock_mainboard_init(void) |
| 48 | { |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 49 | set_clock_sources(); |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 50 | |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 51 | clock_enable_clear_reset(CLK_L_CACHE2 | CLK_L_TMR, |
| 52 | CLK_H_I2C5 | CLK_H_APBDMA, |
Julius Werner | edf6b57 | 2013-10-25 17:49:26 -0700 | [diff] [blame] | 53 | 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 Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 60 | |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 61 | // 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 Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 67 | i2c_init(4); |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 68 | pmic_init(4); |
| 69 | |
| 70 | /* SPI4 data out (MOSI) */ |
Tom Warren | 64982c50 | 2014-01-23 13:37:50 -0700 | [diff] [blame] | 71 | pinmux_set_config(PINMUX_GPIO_PG6_INDEX, |
| 72 | PINMUX_GPIO_PG6_FUNC_SPI4 | PINMUX_INPUT_ENABLE | |
| 73 | PINMUX_PULL_UP); |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 74 | /* SPI4 data in (MISO) */ |
Tom Warren | 64982c50 | 2014-01-23 13:37:50 -0700 | [diff] [blame] | 75 | pinmux_set_config(PINMUX_GPIO_PG7_INDEX, |
| 76 | PINMUX_GPIO_PG7_FUNC_SPI4 | PINMUX_INPUT_ENABLE | |
| 77 | PINMUX_PULL_UP); |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 78 | /* SPI4 clock */ |
Tom Warren | 64982c50 | 2014-01-23 13:37:50 -0700 | [diff] [blame] | 79 | pinmux_set_config(PINMUX_GPIO_PG5_INDEX, |
| 80 | PINMUX_GPIO_PG5_FUNC_SPI4 | PINMUX_INPUT_ENABLE); |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 81 | /* SPI4 chip select 0 */ |
Tom Warren | 64982c50 | 2014-01-23 13:37:50 -0700 | [diff] [blame] | 82 | pinmux_set_config(PINMUX_GPIO_PI3_INDEX, |
| 83 | PINMUX_GPIO_PI3_FUNC_SPI4 | PINMUX_INPUT_ENABLE); |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 84 | |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 85 | tegra_spi_init(4); |
| 86 | } |