blob: 3d8038164662c5532ed9fde7eb3ca94e57a1ad9a [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -07002/*
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +02003 * Copyright (c) 2016-2018 Toradex, Inc.
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -07004 */
5
6#include <common.h>
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +02007#include <dm.h>
Simon Glassed38aef2020-05-10 11:40:03 -06008#include <env.h>
Simon Glass97589732020-05-10 11:40:02 -06009#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -070011#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 Glass9d1f6192019-08-02 09:44:25 -060016#include <env_internal.h>
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +020017#include <pci_tegra.h>
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -070018#include <power/as3722.h>
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +020019#include <power/pmic.h>
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -070020
21#include "../common/tdx-common.h"
22#include "pinmux-config-apalis-tk1.h"
23
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +020024#define LAN_DEV_OFF_N TEGRA_GPIO(O, 6)
25#define LAN_RESET_N TEGRA_GPIO(S, 2)
Igor Opaniukfeb8c0d2019-08-01 11:06:32 +030026#define FAN_EN TEGRA_GPIO(DD, 2)
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +020027#define LAN_WAKE_N TEGRA_GPIO(O, 5)
28#ifdef CONFIG_APALIS_TK1_PCIE_EVALBOARD_INIT
29#define PEX_PERST_N TEGRA_GPIO(DD, 1) /* Apalis GPIO7 */
30#define RESET_MOCI_CTRL TEGRA_GPIO(U, 4)
31#endif /* CONFIG_APALIS_TK1_PCIE_EVALBOARD_INIT */
Marcel Ziswiler46eb7292019-08-09 13:21:46 +030032#define VCC_USBH TEGRA_GPIO(T, 6)
33#define VCC_USBH_V1_0 TEGRA_GPIO(N, 5)
34#define VCC_USBO1 TEGRA_GPIO(T, 5)
35#define VCC_USBO1_V1_0 TEGRA_GPIO(N, 4)
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -070036
37int arch_misc_init(void)
38{
39 if (readl(NV_PA_BASE_SRAM + NVBOOTINFOTABLE_BOOTTYPE) ==
40 NVBOOTTYPE_RECOVERY)
41 printf("USB recovery mode\n");
42
Marcel Ziswiler46eb7292019-08-09 13:21:46 +030043 /* PCB Version Indication: V1.2 and later have GPIO_PV0 wired to GND */
44 gpio_request(TEGRA_GPIO(V, 0), "PCB Version Indication");
45 gpio_direction_input(TEGRA_GPIO(V, 0));
46 if (gpio_get_value(TEGRA_GPIO(V, 0))) {
47 /*
48 * if using the default device tree for new V1.2 and later HW,
49 * use version for older V1.0 and V1.1 HW
50 */
51 char *fdt_env = env_get("fdt_module");
52
53 if (fdt_env && !strcmp(FDT_MODULE, fdt_env)) {
54 env_set("fdt_module", FDT_MODULE_V1_0);
55 printf("patching fdt_module to " FDT_MODULE_V1_0
56 " for older V1.0 and V1.1 HW\n");
57#ifndef CONFIG_ENV_IS_NOWHERE
58 env_save();
59#endif
60 }
61
62 /* activate USB power enable GPIOs */
63 gpio_request(VCC_USBH_V1_0, "VCC_USBH");
64 gpio_direction_output(VCC_USBH_V1_0, 1);
65 gpio_request(VCC_USBO1_V1_0, "VCC_USBO1");
66 gpio_direction_output(VCC_USBO1_V1_0, 1);
67 } else {
68 /* activate USB power enable GPIOs */
69 gpio_request(VCC_USBH, "VCC_USBH");
70 gpio_direction_output(VCC_USBH, 1);
71 gpio_request(VCC_USBO1, "VCC_USBO1");
72 gpio_direction_output(VCC_USBO1, 1);
73 }
74
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -070075 return 0;
76}
77
78int checkboard(void)
79{
80 puts("Model: Toradex Apalis TK1 2GB\n");
81
82 return 0;
83}
84
85#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
86int ft_board_setup(void *blob, bd_t *bd)
87{
88 return ft_common_board_setup(blob, bd);
89}
90#endif
91
92/*
93 * Routine: pinmux_init
94 * Description: Do individual peripheral pinmux configs
95 */
96void pinmux_init(void)
97{
98 pinmux_clear_tristate_input_clamping();
99
100 gpio_config_table(apalis_tk1_gpio_inits,
101 ARRAY_SIZE(apalis_tk1_gpio_inits));
102
103 pinmux_config_pingrp_table(apalis_tk1_pingrps,
104 ARRAY_SIZE(apalis_tk1_pingrps));
105
106 pinmux_config_drvgrp_table(apalis_tk1_drvgrps,
107 ARRAY_SIZE(apalis_tk1_drvgrps));
108}
109
110#ifdef CONFIG_PCI_TEGRA
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200111/* TODO: Convert to driver model */
112static int as3722_sd_enable(struct udevice *pmic, unsigned int sd)
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -0700113{
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -0700114 int err;
115
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200116 if (sd > 6)
117 return -EINVAL;
118
119 err = pmic_clrsetbits(pmic, AS3722_SD_CONTROL, 0, 1 << sd);
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -0700120 if (err) {
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200121 pr_err("failed to update SD control register: %d", err);
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -0700122 return err;
123 }
124
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200125 return 0;
126}
127
128/* TODO: Convert to driver model */
129static int as3722_ldo_enable(struct udevice *pmic, unsigned int ldo)
130{
131 int err;
132 u8 ctrl_reg = AS3722_LDO_CONTROL0;
133
134 if (ldo > 11)
135 return -EINVAL;
136
137 if (ldo > 7) {
138 ctrl_reg = AS3722_LDO_CONTROL1;
139 ldo -= 8;
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -0700140 }
141
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200142 err = pmic_clrsetbits(pmic, ctrl_reg, 0, 1 << ldo);
143 if (err) {
144 pr_err("failed to update LDO control register: %d", err);
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -0700145 return err;
146 }
147
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200148 return 0;
149}
150
151int tegra_pcie_board_init(void)
152{
153 struct udevice *dev;
154 int ret;
155
156 ret = uclass_get_device_by_driver(UCLASS_PMIC,
157 DM_GET_DRIVER(pmic_as3722), &dev);
158 if (ret) {
159 pr_err("failed to find AS3722 PMIC: %d\n", ret);
160 return ret;
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -0700161 }
162
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200163 ret = as3722_sd_enable(dev, 4);
164 if (ret < 0) {
165 pr_err("failed to enable SD4: %d\n", ret);
166 return ret;
167 }
168
169 ret = as3722_sd_set_voltage(dev, 4, 0x24);
170 if (ret < 0) {
171 pr_err("failed to set SD4 voltage: %d\n", ret);
172 return ret;
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -0700173 }
174
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200175 gpio_request(LAN_DEV_OFF_N, "LAN_DEV_OFF_N");
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -0700176 gpio_request(LAN_RESET_N, "LAN_RESET_N");
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200177 gpio_request(LAN_WAKE_N, "LAN_WAKE_N");
178
179#ifdef CONFIG_APALIS_TK1_PCIE_EVALBOARD_INIT
180 gpio_request(PEX_PERST_N, "PEX_PERST_N");
181 gpio_request(RESET_MOCI_CTRL, "RESET_MOCI_CTRL");
182#endif /* CONFIG_APALIS_TK1_PCIE_EVALBOARD_INIT */
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -0700183
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200184 return 0;
185}
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -0700186
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200187void tegra_pcie_board_port_reset(struct tegra_pcie_port *port)
188{
189 int index = tegra_pcie_port_index_of_port(port);
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -0700190
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200191 if (index == 1) { /* I210 Gigabit Ethernet Controller (On-module) */
192 struct udevice *dev;
193 int ret;
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -0700194
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200195 ret = uclass_get_device_by_driver(UCLASS_PMIC,
196 DM_GET_DRIVER(pmic_as3722),
197 &dev);
198 if (ret) {
199 debug("%s: Failed to find PMIC\n", __func__);
200 return;
201 }
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -0700202
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200203 /* Reset I210 Gigabit Ethernet Controller */
204 gpio_direction_output(LAN_RESET_N, 0);
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -0700205
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200206 /*
207 * Make sure we don't get any back feeding from DEV_OFF_N resp.
208 * LAN_WAKE_N
209 */
210 gpio_direction_output(LAN_DEV_OFF_N, 0);
211 gpio_direction_output(LAN_WAKE_N, 0);
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -0700212
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200213 /* Make sure LDO9 and LDO10 are initially enabled @ 0V */
214 ret = as3722_ldo_enable(dev, 9);
215 if (ret < 0) {
216 pr_err("failed to enable LDO9: %d\n", ret);
217 return;
218 }
219 ret = as3722_ldo_enable(dev, 10);
220 if (ret < 0) {
221 pr_err("failed to enable LDO10: %d\n", ret);
222 return;
223 }
224 ret = as3722_ldo_set_voltage(dev, 9, 0x80);
225 if (ret < 0) {
226 pr_err("failed to set LDO9 voltage: %d\n", ret);
227 return;
228 }
229 ret = as3722_ldo_set_voltage(dev, 10, 0x80);
230 if (ret < 0) {
231 pr_err("failed to set LDO10 voltage: %d\n", ret);
232 return;
233 }
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -0700234
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200235 /* Make sure controller gets enabled by disabling DEV_OFF_N */
236 gpio_set_value(LAN_DEV_OFF_N, 1);
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -0700237
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200238 /*
239 * Enable LDO9 and LDO10 for +V3.3_ETH on patched prototype
240 * V1.0A and sample V1.0B and newer modules
241 */
242 ret = as3722_ldo_set_voltage(dev, 9, 0xff);
243 if (ret < 0) {
244 pr_err("failed to set LDO9 voltage: %d\n", ret);
245 return;
246 }
247 ret = as3722_ldo_set_voltage(dev, 10, 0xff);
248 if (ret < 0) {
249 pr_err("failed to set LDO10 voltage: %d\n", ret);
250 return;
251 }
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -0700252
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200253 /*
254 * Must be asserted for 100 ms after power and clocks are stable
255 */
256 mdelay(100);
257
258 gpio_set_value(LAN_RESET_N, 1);
259 } else if (index == 0) { /* Apalis PCIe */
260#ifdef CONFIG_APALIS_TK1_PCIE_EVALBOARD_INIT
261 /*
262 * Reset PLX PEX 8605 PCIe Switch plus PCIe devices on Apalis
263 * Evaluation Board
264 */
265 gpio_direction_output(PEX_PERST_N, 0);
266 gpio_direction_output(RESET_MOCI_CTRL, 0);
267
268 /*
269 * Must be asserted for 100 ms after power and clocks are stable
270 */
271 mdelay(100);
272
273 gpio_set_value(PEX_PERST_N, 1);
274 /*
275 * Err_5: PEX_REFCLK_OUTpx/nx Clock Outputs is not Guaranteed
276 * Until 900 us After PEX_PERST# De-assertion
277 */
278 mdelay(1);
279 gpio_set_value(RESET_MOCI_CTRL, 1);
280#endif /* CONFIG_APALIS_TK1_PCIE_EVALBOARD_INIT */
281 }
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -0700282}
283#endif /* CONFIG_PCI_TEGRA */
Gerard Salvatella108d7392018-11-19 15:54:10 +0100284
285/*
Igor Opaniukfeb8c0d2019-08-01 11:06:32 +0300286 * Enable/start PWM CPU fan
287 */
288void start_cpu_fan(void)
289{
290 gpio_request(FAN_EN, "FAN_EN");
291 gpio_direction_output(FAN_EN, 1);
292}
293
294/*
Gerard Salvatella108d7392018-11-19 15:54:10 +0100295 * Backlight off before OS handover
296 */
297void board_preboot_os(void)
298{
299 gpio_request(TEGRA_GPIO(BB, 5), "BL_ON");
300 gpio_direction_output(TEGRA_GPIO(BB, 5), 0);
301}