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