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