Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Marcel Ziswiler | 11e2a53 | 2014-09-05 10:18:38 +0200 | [diff] [blame] | 2 | /* |
Marcel Ziswiler | 97d3449 | 2018-05-09 00:18:40 +0200 | [diff] [blame] | 3 | * (C) Copyright 2014-2018 |
Marcel Ziswiler | 11e2a53 | 2014-09-05 10:18:38 +0200 | [diff] [blame] | 4 | * Marcel Ziswiler <marcel@ziswiler.com> |
Marcel Ziswiler | 11e2a53 | 2014-09-05 10:18:38 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 8 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Marcel Ziswiler | 11e2a53 | 2014-09-05 10:18:38 +0200 | [diff] [blame] | 10 | #include <asm/arch/gp_padctrl.h> |
| 11 | #include <asm/arch/pinmux.h> |
Marcel Ziswiler | dd899d0 | 2015-08-06 00:47:00 +0200 | [diff] [blame] | 12 | #include <asm/arch-tegra/ap.h> |
| 13 | #include <asm/arch-tegra/tegra.h> |
Marcel Ziswiler | 11e2a53 | 2014-09-05 10:18:38 +0200 | [diff] [blame] | 14 | #include <asm/gpio.h> |
Marcel Ziswiler | dd899d0 | 2015-08-06 00:47:00 +0200 | [diff] [blame] | 15 | #include <asm/io.h> |
Marcel Ziswiler | 764d412 | 2015-08-06 00:47:10 +0200 | [diff] [blame] | 16 | #include <dm.h> |
Marcel Ziswiler | 11e2a53 | 2014-09-05 10:18:38 +0200 | [diff] [blame] | 17 | #include <i2c.h> |
Marcel Ziswiler | 97d3449 | 2018-05-09 00:18:40 +0200 | [diff] [blame] | 18 | #include <pci_tegra.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 19 | #include <linux/delay.h> |
Stefan Agner | 98ffd0f | 2016-11-30 13:41:53 -0800 | [diff] [blame] | 20 | #include "../common/tdx-common.h" |
Marcel Ziswiler | 11e2a53 | 2014-09-05 10:18:38 +0200 | [diff] [blame] | 21 | |
| 22 | #include "pinmux-config-apalis_t30.h" |
| 23 | |
Marcel Ziswiler | d92dee5 | 2016-11-16 17:49:23 +0100 | [diff] [blame] | 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | |
Marcel Ziswiler | 11e2a53 | 2014-09-05 10:18:38 +0200 | [diff] [blame] | 26 | #define PMU_I2C_ADDRESS 0x2D |
| 27 | #define MAX_I2C_RETRY 3 |
| 28 | |
Marcel Ziswiler | 97d3449 | 2018-05-09 00:18:40 +0200 | [diff] [blame] | 29 | #ifdef CONFIG_APALIS_T30_PCIE_EVALBOARD_INIT |
| 30 | #define PEX_PERST_N TEGRA_GPIO(S, 7) /* Apalis GPIO7 */ |
| 31 | #define RESET_MOCI_CTRL TEGRA_GPIO(I, 4) |
| 32 | |
| 33 | static int pci_reset_status; |
| 34 | #endif /* CONFIG_APALIS_T30_PCIE_EVALBOARD_INIT */ |
| 35 | |
Marcel Ziswiler | dd899d0 | 2015-08-06 00:47:00 +0200 | [diff] [blame] | 36 | int arch_misc_init(void) |
| 37 | { |
| 38 | if (readl(NV_PA_BASE_SRAM + NVBOOTINFOTABLE_BOOTTYPE) == |
| 39 | NVBOOTTYPE_RECOVERY) |
| 40 | printf("USB recovery mode\n"); |
| 41 | |
| 42 | return 0; |
| 43 | } |
| 44 | |
Marcel Ziswiler | d92dee5 | 2016-11-16 17:49:23 +0100 | [diff] [blame] | 45 | int checkboard(void) |
| 46 | { |
| 47 | printf("Model: Toradex Apalis T30 %dGB\n", |
| 48 | (gd->ram_size == 0x40000000) ? 1 : 2); |
| 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |
Stefan Agner | 98ffd0f | 2016-11-30 13:41:53 -0800 | [diff] [blame] | 53 | #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 54 | int ft_board_setup(void *blob, struct bd_info *bd) |
Stefan Agner | 98ffd0f | 2016-11-30 13:41:53 -0800 | [diff] [blame] | 55 | { |
| 56 | return ft_common_board_setup(blob, bd); |
| 57 | } |
| 58 | #endif |
| 59 | |
Marcel Ziswiler | 11e2a53 | 2014-09-05 10:18:38 +0200 | [diff] [blame] | 60 | /* |
| 61 | * Routine: pinmux_init |
| 62 | * Description: Do individual peripheral pinmux configs |
| 63 | */ |
| 64 | void pinmux_init(void) |
| 65 | { |
| 66 | pinmux_config_pingrp_table(tegra3_pinmux_common, |
| 67 | ARRAY_SIZE(tegra3_pinmux_common)); |
| 68 | |
| 69 | pinmux_config_pingrp_table(unused_pins_lowpower, |
| 70 | ARRAY_SIZE(unused_pins_lowpower)); |
| 71 | |
| 72 | /* Initialize any non-default pad configs (APB_MISC_GP regs) */ |
| 73 | pinmux_config_drvgrp_table(apalis_t30_padctrl, |
| 74 | ARRAY_SIZE(apalis_t30_padctrl)); |
| 75 | } |
| 76 | |
| 77 | #ifdef CONFIG_PCI_TEGRA |
| 78 | int tegra_pcie_board_init(void) |
| 79 | { |
Simon Glass | 667aee9 | 2014-12-10 08:55:57 -0700 | [diff] [blame] | 80 | struct udevice *dev; |
Marcel Ziswiler | 11e2a53 | 2014-09-05 10:18:38 +0200 | [diff] [blame] | 81 | u8 addr, data[1]; |
| 82 | int err; |
| 83 | |
Simon Glass | a2723ae | 2015-01-25 08:26:55 -0700 | [diff] [blame] | 84 | err = i2c_get_chip_for_busnum(0, PMU_I2C_ADDRESS, 1, &dev); |
Marcel Ziswiler | 11e2a53 | 2014-09-05 10:18:38 +0200 | [diff] [blame] | 85 | if (err) { |
Simon Glass | 667aee9 | 2014-12-10 08:55:57 -0700 | [diff] [blame] | 86 | debug("%s: Cannot find PMIC I2C chip\n", __func__); |
Marcel Ziswiler | 11e2a53 | 2014-09-05 10:18:38 +0200 | [diff] [blame] | 87 | return err; |
| 88 | } |
Marcel Ziswiler | 764d412 | 2015-08-06 00:47:10 +0200 | [diff] [blame] | 89 | |
Marcel Ziswiler | 11e2a53 | 2014-09-05 10:18:38 +0200 | [diff] [blame] | 90 | /* TPS659110: VDD2_OP_REG = 1.05V */ |
| 91 | data[0] = 0x27; |
| 92 | addr = 0x25; |
| 93 | |
Simon Glass | 7d72276 | 2015-01-12 18:02:07 -0700 | [diff] [blame] | 94 | err = dm_i2c_write(dev, addr, data, 1); |
Marcel Ziswiler | 11e2a53 | 2014-09-05 10:18:38 +0200 | [diff] [blame] | 95 | if (err) { |
| 96 | debug("failed to set VDD supply\n"); |
| 97 | return err; |
| 98 | } |
| 99 | |
| 100 | /* TPS659110: VDD2_REG 7.5 mV/us, ACTIVE */ |
| 101 | data[0] = 0x0D; |
| 102 | addr = 0x24; |
| 103 | |
Simon Glass | 7d72276 | 2015-01-12 18:02:07 -0700 | [diff] [blame] | 104 | err = dm_i2c_write(dev, addr, data, 1); |
Marcel Ziswiler | 11e2a53 | 2014-09-05 10:18:38 +0200 | [diff] [blame] | 105 | if (err) { |
| 106 | debug("failed to enable VDD supply\n"); |
| 107 | return err; |
| 108 | } |
| 109 | |
| 110 | /* TPS659110: LDO6_REG = 1.1V, ACTIVE */ |
| 111 | data[0] = 0x0D; |
| 112 | addr = 0x35; |
| 113 | |
Simon Glass | 7d72276 | 2015-01-12 18:02:07 -0700 | [diff] [blame] | 114 | err = dm_i2c_write(dev, addr, data, 1); |
Marcel Ziswiler | 11e2a53 | 2014-09-05 10:18:38 +0200 | [diff] [blame] | 115 | if (err) { |
| 116 | debug("failed to set AVDD supply\n"); |
| 117 | return err; |
| 118 | } |
| 119 | |
Marcel Ziswiler | 97d3449 | 2018-05-09 00:18:40 +0200 | [diff] [blame] | 120 | #ifdef CONFIG_APALIS_T30_PCIE_EVALBOARD_INIT |
| 121 | gpio_request(PEX_PERST_N, "PEX_PERST_N"); |
| 122 | gpio_request(RESET_MOCI_CTRL, "RESET_MOCI_CTRL"); |
| 123 | #endif /* CONFIG_APALIS_T30_PCIE_EVALBOARD_INIT */ |
| 124 | |
Marcel Ziswiler | 11e2a53 | 2014-09-05 10:18:38 +0200 | [diff] [blame] | 125 | return 0; |
| 126 | } |
Marcel Ziswiler | 97d3449 | 2018-05-09 00:18:40 +0200 | [diff] [blame] | 127 | |
| 128 | void tegra_pcie_board_port_reset(struct tegra_pcie_port *port) |
| 129 | { |
| 130 | int index = tegra_pcie_port_index_of_port(port); |
| 131 | |
| 132 | if (index == 2) { /* I210 Gigabit Ethernet Controller (On-module) */ |
| 133 | tegra_pcie_port_reset(port); |
| 134 | } |
| 135 | #ifdef CONFIG_APALIS_T30_PCIE_EVALBOARD_INIT |
| 136 | /* |
| 137 | * Apalis PCIe aka port 1 and Apalis Type Specific 4 Lane PCIe aka port |
| 138 | * 0 share the same RESET_MOCI therefore only assert it once for both |
| 139 | * ports to avoid losing the previously brought up port again. |
| 140 | */ |
| 141 | else if ((index == 1) || (index == 0)) { |
| 142 | /* only do it once per init cycle */ |
| 143 | if (pci_reset_status % 2 == 0) { |
| 144 | /* |
| 145 | * Reset PLX PEX 8605 PCIe Switch plus PCIe devices on |
| 146 | * Apalis Evaluation Board |
| 147 | */ |
| 148 | gpio_direction_output(PEX_PERST_N, 0); |
| 149 | gpio_direction_output(RESET_MOCI_CTRL, 0); |
| 150 | |
| 151 | /* |
| 152 | * Must be asserted for 100 ms after power and clocks |
| 153 | * are stable |
| 154 | */ |
| 155 | mdelay(100); |
| 156 | |
| 157 | gpio_set_value(PEX_PERST_N, 1); |
| 158 | /* |
| 159 | * Err_5: PEX_REFCLK_OUTpx/nx Clock Outputs is not |
| 160 | * Guaranteed Until 900 us After PEX_PERST# De-assertion |
| 161 | */ |
| 162 | mdelay(1); |
| 163 | gpio_set_value(RESET_MOCI_CTRL, 1); |
| 164 | } |
| 165 | pci_reset_status++; |
| 166 | } |
| 167 | #endif /* CONFIG_APALIS_T30_PCIE_EVALBOARD_INIT */ |
| 168 | } |
Marcel Ziswiler | 11e2a53 | 2014-09-05 10:18:38 +0200 | [diff] [blame] | 169 | #endif /* CONFIG_PCI_TEGRA */ |
Gerard Salvatella | 108d739 | 2018-11-19 15:54:10 +0100 | [diff] [blame] | 170 | |
| 171 | /* |
| 172 | * Backlight off before OS handover |
| 173 | */ |
| 174 | void board_preboot_os(void) |
| 175 | { |
| 176 | gpio_request(TEGRA_GPIO(V, 2), "BKL1_ON"); |
| 177 | gpio_direction_output(TEGRA_GPIO(V, 2), 0); |
| 178 | } |