Angel Pons | 163030b | 2020-04-05 13:22:07 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Daisuke Nojiri | 1b05d88 | 2014-08-27 11:48:03 -0700 | [diff] [blame] | 2 | |
Julius Werner | eaa9c45 | 2014-09-24 15:40:49 -0700 | [diff] [blame] | 3 | #include <gpio.h> |
Daisuke Nojiri | 1b05d88 | 2014-08-27 11:48:03 -0700 | [diff] [blame] | 4 | #include <soc/addressmap.h> |
| 5 | #include <soc/clock.h> |
Julius Werner | f0d21ff3 | 2014-10-20 13:24:14 -0700 | [diff] [blame] | 6 | #include <soc/early_configs.h> |
Daisuke Nojiri | 1b05d88 | 2014-08-27 11:48:03 -0700 | [diff] [blame] | 7 | #include <soc/nvidia/tegra/i2c.h> |
Daisuke Nojiri | 1b05d88 | 2014-08-27 11:48:03 -0700 | [diff] [blame] | 8 | |
| 9 | static struct clk_rst_ctlr *clk_rst = (void *)TEGRA_CLK_RST_BASE; |
| 10 | |
| 11 | static void setup_pinmux(void) |
| 12 | { |
| 13 | /* Write protect. */ |
| 14 | gpio_input_pullup(GPIO(R1)); |
| 15 | /* Recovery mode. */ |
| 16 | gpio_input_pullup(GPIO(Q7)); |
| 17 | /* Lid switch. */ |
| 18 | gpio_input_pullup(GPIO(R4)); |
| 19 | /* Power switch. */ |
| 20 | gpio_input_pullup(GPIO(Q0)); |
| 21 | /* Developer mode. */ |
| 22 | gpio_input_pullup(GPIO(Q6)); |
| 23 | /* EC in RW. */ |
| 24 | gpio_input_pullup(GPIO(U4)); |
| 25 | |
| 26 | /* route PU4/5 to GMI to remove conflict w/PWM1/2. */ |
| 27 | pinmux_set_config(PINMUX_GPIO_PU4_INDEX, |
| 28 | PINMUX_GPIO_PU4_FUNC_NOR); /* s/b GMI */ |
| 29 | pinmux_set_config(PINMUX_GPIO_PU5_INDEX, |
| 30 | PINMUX_GPIO_PU5_FUNC_NOR); /* s/b GMI */ |
| 31 | |
| 32 | /* SOC and TPM reset GPIO, active low. */ |
| 33 | gpio_output(GPIO(I5), 1); |
| 34 | |
| 35 | /* SPI1 MOSI */ |
| 36 | pinmux_set_config(PINMUX_ULPI_CLK_INDEX, PINMUX_ULPI_CLK_FUNC_SPI1 | |
| 37 | PINMUX_PULL_NONE | |
| 38 | PINMUX_INPUT_ENABLE); |
| 39 | /* SPI1 MISO */ |
| 40 | pinmux_set_config(PINMUX_ULPI_DIR_INDEX, PINMUX_ULPI_DIR_FUNC_SPI1 | |
| 41 | PINMUX_PULL_NONE | |
| 42 | PINMUX_INPUT_ENABLE); |
| 43 | /* SPI1 SCLK */ |
| 44 | pinmux_set_config(PINMUX_ULPI_NXT_INDEX, PINMUX_ULPI_NXT_FUNC_SPI1 | |
| 45 | PINMUX_PULL_NONE | |
| 46 | PINMUX_INPUT_ENABLE); |
| 47 | /* SPI1 CS0 */ |
| 48 | pinmux_set_config(PINMUX_ULPI_STP_INDEX, PINMUX_ULPI_STP_FUNC_SPI1 | |
| 49 | PINMUX_PULL_NONE | |
| 50 | PINMUX_INPUT_ENABLE); |
| 51 | |
| 52 | /* I2C3 (cam) clock. */ |
| 53 | pinmux_set_config(PINMUX_CAM_I2C_SCL_INDEX, |
| 54 | PINMUX_CAM_I2C_SCL_FUNC_I2C3 | PINMUX_INPUT_ENABLE); |
| 55 | /* I2C3 (cam) data. */ |
| 56 | pinmux_set_config(PINMUX_CAM_I2C_SDA_INDEX, |
| 57 | PINMUX_CAM_I2C_SDA_FUNC_I2C3 | PINMUX_INPUT_ENABLE); |
| 58 | |
| 59 | /* switch unused pin to GPIO */ |
| 60 | gpio_set_mode(GPIO(X3), GPIO_MODE_GPIO); |
| 61 | gpio_set_mode(GPIO(X4), GPIO_MODE_GPIO); |
| 62 | gpio_set_mode(GPIO(X5), GPIO_MODE_GPIO); |
| 63 | gpio_set_mode(GPIO(X6), GPIO_MODE_GPIO); |
| 64 | gpio_set_mode(GPIO(X7), GPIO_MODE_GPIO); |
| 65 | gpio_set_mode(GPIO(W3), GPIO_MODE_GPIO); |
| 66 | } |
| 67 | |
| 68 | static void configure_ec_spi_bus(void) |
| 69 | { |
| 70 | clock_configure_source(sbc1, CLK_M, 3000); |
| 71 | } |
| 72 | |
| 73 | static void configure_tpm_i2c_bus(void) |
| 74 | { |
| 75 | clock_configure_i2c_scl_freq(i2c3, PLLP, 400); |
| 76 | |
| 77 | i2c_init(2); |
| 78 | } |
| 79 | |
| 80 | void early_mainboard_init(void) |
| 81 | { |
| 82 | clock_enable_clear_reset(0, CLK_H_SBC1, CLK_U_I2C3, 0, 0, 0); |
| 83 | setup_pinmux(); |
| 84 | configure_ec_spi_bus(); |
| 85 | configure_tpm_i2c_bus(); |
| 86 | } |