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