Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 2 | /* |
Marcel Ziswiler | 07ce1a6 | 2018-05-08 17:34:11 +0200 | [diff] [blame] | 3 | * Copyright (c) 2016-2018 Toradex, Inc. |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Marcel Ziswiler | 07ce1a6 | 2018-05-08 17:34:11 +0200 | [diff] [blame] | 7 | #include <dm.h> |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [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 | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 11 | #include <asm/arch-tegra/ap.h> |
| 12 | #include <asm/gpio.h> |
| 13 | #include <asm/io.h> |
| 14 | #include <asm/arch/gpio.h> |
| 15 | #include <asm/arch/pinmux.h> |
Simon Glass | 9d1f619 | 2019-08-02 09:44:25 -0600 | [diff] [blame] | 16 | #include <env_internal.h> |
Marcel Ziswiler | 07ce1a6 | 2018-05-08 17:34:11 +0200 | [diff] [blame] | 17 | #include <pci_tegra.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 18 | #include <linux/delay.h> |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 19 | #include <power/as3722.h> |
Marcel Ziswiler | 07ce1a6 | 2018-05-08 17:34:11 +0200 | [diff] [blame] | 20 | #include <power/pmic.h> |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 21 | |
| 22 | #include "../common/tdx-common.h" |
| 23 | #include "pinmux-config-apalis-tk1.h" |
| 24 | |
Marcel Ziswiler | 07ce1a6 | 2018-05-08 17:34:11 +0200 | [diff] [blame] | 25 | #define LAN_DEV_OFF_N TEGRA_GPIO(O, 6) |
| 26 | #define LAN_RESET_N TEGRA_GPIO(S, 2) |
Igor Opaniuk | feb8c0d | 2019-08-01 11:06:32 +0300 | [diff] [blame] | 27 | #define FAN_EN TEGRA_GPIO(DD, 2) |
Marcel Ziswiler | 07ce1a6 | 2018-05-08 17:34:11 +0200 | [diff] [blame] | 28 | #define LAN_WAKE_N TEGRA_GPIO(O, 5) |
| 29 | #ifdef CONFIG_APALIS_TK1_PCIE_EVALBOARD_INIT |
| 30 | #define PEX_PERST_N TEGRA_GPIO(DD, 1) /* Apalis GPIO7 */ |
| 31 | #define RESET_MOCI_CTRL TEGRA_GPIO(U, 4) |
| 32 | #endif /* CONFIG_APALIS_TK1_PCIE_EVALBOARD_INIT */ |
Marcel Ziswiler | 46eb729 | 2019-08-09 13:21:46 +0300 | [diff] [blame] | 33 | #define VCC_USBH TEGRA_GPIO(T, 6) |
| 34 | #define VCC_USBH_V1_0 TEGRA_GPIO(N, 5) |
| 35 | #define VCC_USBO1 TEGRA_GPIO(T, 5) |
| 36 | #define VCC_USBO1_V1_0 TEGRA_GPIO(N, 4) |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 37 | |
| 38 | int arch_misc_init(void) |
| 39 | { |
| 40 | if (readl(NV_PA_BASE_SRAM + NVBOOTINFOTABLE_BOOTTYPE) == |
| 41 | NVBOOTTYPE_RECOVERY) |
| 42 | printf("USB recovery mode\n"); |
| 43 | |
Marcel Ziswiler | 46eb729 | 2019-08-09 13:21:46 +0300 | [diff] [blame] | 44 | /* PCB Version Indication: V1.2 and later have GPIO_PV0 wired to GND */ |
| 45 | gpio_request(TEGRA_GPIO(V, 0), "PCB Version Indication"); |
| 46 | gpio_direction_input(TEGRA_GPIO(V, 0)); |
| 47 | if (gpio_get_value(TEGRA_GPIO(V, 0))) { |
| 48 | /* |
| 49 | * if using the default device tree for new V1.2 and later HW, |
| 50 | * use version for older V1.0 and V1.1 HW |
| 51 | */ |
| 52 | char *fdt_env = env_get("fdt_module"); |
| 53 | |
| 54 | if (fdt_env && !strcmp(FDT_MODULE, fdt_env)) { |
| 55 | env_set("fdt_module", FDT_MODULE_V1_0); |
| 56 | printf("patching fdt_module to " FDT_MODULE_V1_0 |
| 57 | " for older V1.0 and V1.1 HW\n"); |
| 58 | #ifndef CONFIG_ENV_IS_NOWHERE |
| 59 | env_save(); |
| 60 | #endif |
| 61 | } |
| 62 | |
| 63 | /* activate USB power enable GPIOs */ |
| 64 | gpio_request(VCC_USBH_V1_0, "VCC_USBH"); |
| 65 | gpio_direction_output(VCC_USBH_V1_0, 1); |
| 66 | gpio_request(VCC_USBO1_V1_0, "VCC_USBO1"); |
| 67 | gpio_direction_output(VCC_USBO1_V1_0, 1); |
| 68 | } else { |
| 69 | /* activate USB power enable GPIOs */ |
| 70 | gpio_request(VCC_USBH, "VCC_USBH"); |
| 71 | gpio_direction_output(VCC_USBH, 1); |
| 72 | gpio_request(VCC_USBO1, "VCC_USBO1"); |
| 73 | gpio_direction_output(VCC_USBO1, 1); |
| 74 | } |
| 75 | |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | int checkboard(void) |
| 80 | { |
| 81 | puts("Model: Toradex Apalis TK1 2GB\n"); |
| 82 | |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 87 | int ft_board_setup(void *blob, struct bd_info *bd) |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 88 | { |
| 89 | return ft_common_board_setup(blob, bd); |
| 90 | } |
| 91 | #endif |
| 92 | |
| 93 | /* |
| 94 | * Routine: pinmux_init |
| 95 | * Description: Do individual peripheral pinmux configs |
| 96 | */ |
| 97 | void pinmux_init(void) |
| 98 | { |
| 99 | pinmux_clear_tristate_input_clamping(); |
| 100 | |
| 101 | gpio_config_table(apalis_tk1_gpio_inits, |
| 102 | ARRAY_SIZE(apalis_tk1_gpio_inits)); |
| 103 | |
| 104 | pinmux_config_pingrp_table(apalis_tk1_pingrps, |
| 105 | ARRAY_SIZE(apalis_tk1_pingrps)); |
| 106 | |
| 107 | pinmux_config_drvgrp_table(apalis_tk1_drvgrps, |
| 108 | ARRAY_SIZE(apalis_tk1_drvgrps)); |
| 109 | } |
| 110 | |
| 111 | #ifdef CONFIG_PCI_TEGRA |
Marcel Ziswiler | 07ce1a6 | 2018-05-08 17:34:11 +0200 | [diff] [blame] | 112 | /* TODO: Convert to driver model */ |
| 113 | static int as3722_sd_enable(struct udevice *pmic, unsigned int sd) |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 114 | { |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 115 | int err; |
| 116 | |
Marcel Ziswiler | 07ce1a6 | 2018-05-08 17:34:11 +0200 | [diff] [blame] | 117 | if (sd > 6) |
| 118 | return -EINVAL; |
| 119 | |
| 120 | err = pmic_clrsetbits(pmic, AS3722_SD_CONTROL, 0, 1 << sd); |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 121 | if (err) { |
Marcel Ziswiler | 07ce1a6 | 2018-05-08 17:34:11 +0200 | [diff] [blame] | 122 | pr_err("failed to update SD control register: %d", err); |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 123 | return err; |
| 124 | } |
| 125 | |
Marcel Ziswiler | 07ce1a6 | 2018-05-08 17:34:11 +0200 | [diff] [blame] | 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | /* TODO: Convert to driver model */ |
| 130 | static int as3722_ldo_enable(struct udevice *pmic, unsigned int ldo) |
| 131 | { |
| 132 | int err; |
| 133 | u8 ctrl_reg = AS3722_LDO_CONTROL0; |
| 134 | |
| 135 | if (ldo > 11) |
| 136 | return -EINVAL; |
| 137 | |
| 138 | if (ldo > 7) { |
| 139 | ctrl_reg = AS3722_LDO_CONTROL1; |
| 140 | ldo -= 8; |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Marcel Ziswiler | 07ce1a6 | 2018-05-08 17:34:11 +0200 | [diff] [blame] | 143 | err = pmic_clrsetbits(pmic, ctrl_reg, 0, 1 << ldo); |
| 144 | if (err) { |
| 145 | pr_err("failed to update LDO control register: %d", err); |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 146 | return err; |
| 147 | } |
| 148 | |
Marcel Ziswiler | 07ce1a6 | 2018-05-08 17:34:11 +0200 | [diff] [blame] | 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | int tegra_pcie_board_init(void) |
| 153 | { |
| 154 | struct udevice *dev; |
| 155 | int ret; |
| 156 | |
| 157 | ret = uclass_get_device_by_driver(UCLASS_PMIC, |
| 158 | DM_GET_DRIVER(pmic_as3722), &dev); |
| 159 | if (ret) { |
| 160 | pr_err("failed to find AS3722 PMIC: %d\n", ret); |
| 161 | return ret; |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Marcel Ziswiler | 07ce1a6 | 2018-05-08 17:34:11 +0200 | [diff] [blame] | 164 | ret = as3722_sd_enable(dev, 4); |
| 165 | if (ret < 0) { |
| 166 | pr_err("failed to enable SD4: %d\n", ret); |
| 167 | return ret; |
| 168 | } |
| 169 | |
| 170 | ret = as3722_sd_set_voltage(dev, 4, 0x24); |
| 171 | if (ret < 0) { |
| 172 | pr_err("failed to set SD4 voltage: %d\n", ret); |
| 173 | return ret; |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Marcel Ziswiler | 07ce1a6 | 2018-05-08 17:34:11 +0200 | [diff] [blame] | 176 | gpio_request(LAN_DEV_OFF_N, "LAN_DEV_OFF_N"); |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 177 | gpio_request(LAN_RESET_N, "LAN_RESET_N"); |
Marcel Ziswiler | 07ce1a6 | 2018-05-08 17:34:11 +0200 | [diff] [blame] | 178 | gpio_request(LAN_WAKE_N, "LAN_WAKE_N"); |
| 179 | |
| 180 | #ifdef CONFIG_APALIS_TK1_PCIE_EVALBOARD_INIT |
| 181 | gpio_request(PEX_PERST_N, "PEX_PERST_N"); |
| 182 | gpio_request(RESET_MOCI_CTRL, "RESET_MOCI_CTRL"); |
| 183 | #endif /* CONFIG_APALIS_TK1_PCIE_EVALBOARD_INIT */ |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 184 | |
Marcel Ziswiler | 07ce1a6 | 2018-05-08 17:34:11 +0200 | [diff] [blame] | 185 | return 0; |
| 186 | } |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 187 | |
Marcel Ziswiler | 07ce1a6 | 2018-05-08 17:34:11 +0200 | [diff] [blame] | 188 | void tegra_pcie_board_port_reset(struct tegra_pcie_port *port) |
| 189 | { |
| 190 | int index = tegra_pcie_port_index_of_port(port); |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 191 | |
Marcel Ziswiler | 07ce1a6 | 2018-05-08 17:34:11 +0200 | [diff] [blame] | 192 | if (index == 1) { /* I210 Gigabit Ethernet Controller (On-module) */ |
| 193 | struct udevice *dev; |
| 194 | int ret; |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 195 | |
Marcel Ziswiler | 07ce1a6 | 2018-05-08 17:34:11 +0200 | [diff] [blame] | 196 | ret = uclass_get_device_by_driver(UCLASS_PMIC, |
| 197 | DM_GET_DRIVER(pmic_as3722), |
| 198 | &dev); |
| 199 | if (ret) { |
| 200 | debug("%s: Failed to find PMIC\n", __func__); |
| 201 | return; |
| 202 | } |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 203 | |
Marcel Ziswiler | 07ce1a6 | 2018-05-08 17:34:11 +0200 | [diff] [blame] | 204 | /* Reset I210 Gigabit Ethernet Controller */ |
| 205 | gpio_direction_output(LAN_RESET_N, 0); |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 206 | |
Marcel Ziswiler | 07ce1a6 | 2018-05-08 17:34:11 +0200 | [diff] [blame] | 207 | /* |
| 208 | * Make sure we don't get any back feeding from DEV_OFF_N resp. |
| 209 | * LAN_WAKE_N |
| 210 | */ |
| 211 | gpio_direction_output(LAN_DEV_OFF_N, 0); |
| 212 | gpio_direction_output(LAN_WAKE_N, 0); |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 213 | |
Marcel Ziswiler | 07ce1a6 | 2018-05-08 17:34:11 +0200 | [diff] [blame] | 214 | /* Make sure LDO9 and LDO10 are initially enabled @ 0V */ |
| 215 | ret = as3722_ldo_enable(dev, 9); |
| 216 | if (ret < 0) { |
| 217 | pr_err("failed to enable LDO9: %d\n", ret); |
| 218 | return; |
| 219 | } |
| 220 | ret = as3722_ldo_enable(dev, 10); |
| 221 | if (ret < 0) { |
| 222 | pr_err("failed to enable LDO10: %d\n", ret); |
| 223 | return; |
| 224 | } |
| 225 | ret = as3722_ldo_set_voltage(dev, 9, 0x80); |
| 226 | if (ret < 0) { |
| 227 | pr_err("failed to set LDO9 voltage: %d\n", ret); |
| 228 | return; |
| 229 | } |
| 230 | ret = as3722_ldo_set_voltage(dev, 10, 0x80); |
| 231 | if (ret < 0) { |
| 232 | pr_err("failed to set LDO10 voltage: %d\n", ret); |
| 233 | return; |
| 234 | } |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 235 | |
Marcel Ziswiler | 07ce1a6 | 2018-05-08 17:34:11 +0200 | [diff] [blame] | 236 | /* Make sure controller gets enabled by disabling DEV_OFF_N */ |
| 237 | gpio_set_value(LAN_DEV_OFF_N, 1); |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 238 | |
Marcel Ziswiler | 07ce1a6 | 2018-05-08 17:34:11 +0200 | [diff] [blame] | 239 | /* |
| 240 | * Enable LDO9 and LDO10 for +V3.3_ETH on patched prototype |
| 241 | * V1.0A and sample V1.0B and newer modules |
| 242 | */ |
| 243 | ret = as3722_ldo_set_voltage(dev, 9, 0xff); |
| 244 | if (ret < 0) { |
| 245 | pr_err("failed to set LDO9 voltage: %d\n", ret); |
| 246 | return; |
| 247 | } |
| 248 | ret = as3722_ldo_set_voltage(dev, 10, 0xff); |
| 249 | if (ret < 0) { |
| 250 | pr_err("failed to set LDO10 voltage: %d\n", ret); |
| 251 | return; |
| 252 | } |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 253 | |
Marcel Ziswiler | 07ce1a6 | 2018-05-08 17:34:11 +0200 | [diff] [blame] | 254 | /* |
| 255 | * Must be asserted for 100 ms after power and clocks are stable |
| 256 | */ |
| 257 | mdelay(100); |
| 258 | |
| 259 | gpio_set_value(LAN_RESET_N, 1); |
| 260 | } else if (index == 0) { /* Apalis PCIe */ |
| 261 | #ifdef CONFIG_APALIS_TK1_PCIE_EVALBOARD_INIT |
| 262 | /* |
| 263 | * Reset PLX PEX 8605 PCIe Switch plus PCIe devices on Apalis |
| 264 | * Evaluation Board |
| 265 | */ |
| 266 | gpio_direction_output(PEX_PERST_N, 0); |
| 267 | gpio_direction_output(RESET_MOCI_CTRL, 0); |
| 268 | |
| 269 | /* |
| 270 | * Must be asserted for 100 ms after power and clocks are stable |
| 271 | */ |
| 272 | mdelay(100); |
| 273 | |
| 274 | gpio_set_value(PEX_PERST_N, 1); |
| 275 | /* |
| 276 | * Err_5: PEX_REFCLK_OUTpx/nx Clock Outputs is not Guaranteed |
| 277 | * Until 900 us After PEX_PERST# De-assertion |
| 278 | */ |
| 279 | mdelay(1); |
| 280 | gpio_set_value(RESET_MOCI_CTRL, 1); |
| 281 | #endif /* CONFIG_APALIS_TK1_PCIE_EVALBOARD_INIT */ |
| 282 | } |
Marcel Ziswiler | d2b64bd | 2017-04-01 15:43:16 -0700 | [diff] [blame] | 283 | } |
| 284 | #endif /* CONFIG_PCI_TEGRA */ |
Gerard Salvatella | 108d739 | 2018-11-19 15:54:10 +0100 | [diff] [blame] | 285 | |
| 286 | /* |
Igor Opaniuk | feb8c0d | 2019-08-01 11:06:32 +0300 | [diff] [blame] | 287 | * Enable/start PWM CPU fan |
| 288 | */ |
| 289 | void start_cpu_fan(void) |
| 290 | { |
| 291 | gpio_request(FAN_EN, "FAN_EN"); |
| 292 | gpio_direction_output(FAN_EN, 1); |
| 293 | } |
| 294 | |
| 295 | /* |
Gerard Salvatella | 108d739 | 2018-11-19 15:54:10 +0100 | [diff] [blame] | 296 | * Backlight off before OS handover |
| 297 | */ |
| 298 | void board_preboot_os(void) |
| 299 | { |
| 300 | gpio_request(TEGRA_GPIO(BB, 5), "BL_ON"); |
| 301 | gpio_direction_output(TEGRA_GPIO(BB, 5), 0); |
| 302 | } |