1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2016-2018 Toradex, Inc.
11 #include <asm/arch-tegra/ap.h>
14 #include <asm/arch/gpio.h>
15 #include <asm/arch/pinmux.h>
16 #include <env_internal.h>
17 #include <pci_tegra.h>
18 #include <linux/delay.h>
19 #include <power/as3722.h>
20 #include <power/pmic.h>
22 #include "../common/tdx-common.h"
23 #include "pinmux-config-apalis-tk1.h"
25 #define LAN_DEV_OFF_N TEGRA_GPIO(O, 6)
26 #define LAN_RESET_N TEGRA_GPIO(S, 2)
27 #define FAN_EN TEGRA_GPIO(DD, 2)
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 */
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)
38 int arch_misc_init(void)
40 if (readl(NV_PA_BASE_SRAM + NVBOOTINFOTABLE_BOOTTYPE) ==
42 printf("USB recovery mode\n");
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))) {
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
52 char *fdt_env = env_get("fdt_module");
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
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);
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);
81 puts("Model: Toradex Apalis TK1 2GB\n");
86 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
87 int ft_board_setup(void *blob, struct bd_info *bd)
89 return ft_common_board_setup(blob, bd);
94 * Routine: pinmux_init
95 * Description: Do individual peripheral pinmux configs
97 void pinmux_init(void)
99 pinmux_clear_tristate_input_clamping();
101 gpio_config_table(apalis_tk1_gpio_inits,
102 ARRAY_SIZE(apalis_tk1_gpio_inits));
104 pinmux_config_pingrp_table(apalis_tk1_pingrps,
105 ARRAY_SIZE(apalis_tk1_pingrps));
107 pinmux_config_drvgrp_table(apalis_tk1_drvgrps,
108 ARRAY_SIZE(apalis_tk1_drvgrps));
111 #ifdef CONFIG_PCI_TEGRA
112 /* TODO: Convert to driver model */
113 static int as3722_sd_enable(struct udevice *pmic, unsigned int sd)
120 err = pmic_clrsetbits(pmic, AS3722_SD_CONTROL, 0, 1 << sd);
122 pr_err("failed to update SD control register: %d", err);
129 /* TODO: Convert to driver model */
130 static int as3722_ldo_enable(struct udevice *pmic, unsigned int ldo)
133 u8 ctrl_reg = AS3722_LDO_CONTROL0;
139 ctrl_reg = AS3722_LDO_CONTROL1;
143 err = pmic_clrsetbits(pmic, ctrl_reg, 0, 1 << ldo);
145 pr_err("failed to update LDO control register: %d", err);
152 int tegra_pcie_board_init(void)
157 ret = uclass_get_device_by_driver(UCLASS_PMIC,
158 DM_DRIVER_GET(pmic_as3722), &dev);
160 pr_err("failed to find AS3722 PMIC: %d\n", ret);
164 ret = as3722_sd_enable(dev, 4);
166 pr_err("failed to enable SD4: %d\n", ret);
170 ret = as3722_sd_set_voltage(dev, 4, 0x24);
172 pr_err("failed to set SD4 voltage: %d\n", ret);
176 gpio_request(LAN_DEV_OFF_N, "LAN_DEV_OFF_N");
177 gpio_request(LAN_RESET_N, "LAN_RESET_N");
178 gpio_request(LAN_WAKE_N, "LAN_WAKE_N");
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 */
188 void tegra_pcie_board_port_reset(struct tegra_pcie_port *port)
190 int index = tegra_pcie_port_index_of_port(port);
192 if (index == 1) { /* I210 Gigabit Ethernet Controller (On-module) */
196 ret = uclass_get_device_by_driver(UCLASS_PMIC,
197 DM_DRIVER_GET(pmic_as3722),
200 debug("%s: Failed to find PMIC\n", __func__);
204 /* Reset I210 Gigabit Ethernet Controller */
205 gpio_direction_output(LAN_RESET_N, 0);
208 * Make sure we don't get any back feeding from DEV_OFF_N resp.
211 gpio_direction_output(LAN_DEV_OFF_N, 0);
212 gpio_direction_output(LAN_WAKE_N, 0);
214 /* Make sure LDO9 and LDO10 are initially enabled @ 0V */
215 ret = as3722_ldo_enable(dev, 9);
217 pr_err("failed to enable LDO9: %d\n", ret);
220 ret = as3722_ldo_enable(dev, 10);
222 pr_err("failed to enable LDO10: %d\n", ret);
225 ret = as3722_ldo_set_voltage(dev, 9, 0x80);
227 pr_err("failed to set LDO9 voltage: %d\n", ret);
230 ret = as3722_ldo_set_voltage(dev, 10, 0x80);
232 pr_err("failed to set LDO10 voltage: %d\n", ret);
236 /* Make sure controller gets enabled by disabling DEV_OFF_N */
237 gpio_set_value(LAN_DEV_OFF_N, 1);
240 * Enable LDO9 and LDO10 for +V3.3_ETH on patched prototype
241 * V1.0A and sample V1.0B and newer modules
243 ret = as3722_ldo_set_voltage(dev, 9, 0xff);
245 pr_err("failed to set LDO9 voltage: %d\n", ret);
248 ret = as3722_ldo_set_voltage(dev, 10, 0xff);
250 pr_err("failed to set LDO10 voltage: %d\n", ret);
255 * Must be asserted for 100 ms after power and clocks are stable
259 gpio_set_value(LAN_RESET_N, 1);
260 } else if (index == 0) { /* Apalis PCIe */
261 #ifdef CONFIG_APALIS_TK1_PCIE_EVALBOARD_INIT
263 * Reset PLX PEX 8605 PCIe Switch plus PCIe devices on Apalis
266 gpio_direction_output(PEX_PERST_N, 0);
267 gpio_direction_output(RESET_MOCI_CTRL, 0);
270 * Must be asserted for 100 ms after power and clocks are stable
274 gpio_set_value(PEX_PERST_N, 1);
276 * Err_5: PEX_REFCLK_OUTpx/nx Clock Outputs is not Guaranteed
277 * Until 900 us After PEX_PERST# De-assertion
280 gpio_set_value(RESET_MOCI_CTRL, 1);
281 #endif /* CONFIG_APALIS_TK1_PCIE_EVALBOARD_INIT */
284 #endif /* CONFIG_PCI_TEGRA */
287 * Enable/start PWM CPU fan
289 void start_cpu_fan(void)
291 gpio_request(FAN_EN, "FAN_EN");
292 gpio_direction_output(FAN_EN, 1);
296 * Backlight off before OS handover
298 void board_preboot_os(void)
300 gpio_request(TEGRA_GPIO(BB, 5), "BL_ON");
301 gpio_direction_output(TEGRA_GPIO(BB, 5), 0);