blob: d57c5042dddb98a5a724755c7017d6736970dbd6 [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>
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -07008#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 Ziswiler07ce1a62018-05-08 17:34:11 +020013#include <pci_tegra.h>
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -070014#include <power/as3722.h>
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +020015#include <power/pmic.h>
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -070016
17#include "../common/tdx-common.h"
18#include "pinmux-config-apalis-tk1.h"
19
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +020020#define LAN_DEV_OFF_N TEGRA_GPIO(O, 6)
21#define LAN_RESET_N TEGRA_GPIO(S, 2)
Igor Opaniukfeb8c0d2019-08-01 11:06:32 +030022#define FAN_EN TEGRA_GPIO(DD, 2)
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +020023#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 Ziswilerd2b64bd2017-04-01 15:43:16 -070028
29int 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
38int 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)
46int 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 */
56void 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 Ziswiler07ce1a62018-05-08 17:34:11 +020071/* TODO: Convert to driver model */
72static int as3722_sd_enable(struct udevice *pmic, unsigned int sd)
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -070073{
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -070074 int err;
75
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +020076 if (sd > 6)
77 return -EINVAL;
78
79 err = pmic_clrsetbits(pmic, AS3722_SD_CONTROL, 0, 1 << sd);
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -070080 if (err) {
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +020081 pr_err("failed to update SD control register: %d", err);
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -070082 return err;
83 }
84
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +020085 return 0;
86}
87
88/* TODO: Convert to driver model */
89static 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 Ziswilerd2b64bd2017-04-01 15:43:16 -0700100 }
101
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200102 err = pmic_clrsetbits(pmic, ctrl_reg, 0, 1 << ldo);
103 if (err) {
104 pr_err("failed to update LDO control register: %d", err);
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -0700105 return err;
106 }
107
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200108 return 0;
109}
110
111int 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 Ziswilerd2b64bd2017-04-01 15:43:16 -0700121 }
122
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200123 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 Ziswilerd2b64bd2017-04-01 15:43:16 -0700133 }
134
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200135 gpio_request(LAN_DEV_OFF_N, "LAN_DEV_OFF_N");
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -0700136 gpio_request(LAN_RESET_N, "LAN_RESET_N");
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200137 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 Ziswilerd2b64bd2017-04-01 15:43:16 -0700143
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200144 return 0;
145}
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -0700146
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200147void tegra_pcie_board_port_reset(struct tegra_pcie_port *port)
148{
149 int index = tegra_pcie_port_index_of_port(port);
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -0700150
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200151 if (index == 1) { /* I210 Gigabit Ethernet Controller (On-module) */
152 struct udevice *dev;
153 int ret;
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -0700154
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200155 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 Ziswilerd2b64bd2017-04-01 15:43:16 -0700162
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200163 /* Reset I210 Gigabit Ethernet Controller */
164 gpio_direction_output(LAN_RESET_N, 0);
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -0700165
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200166 /*
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 Ziswilerd2b64bd2017-04-01 15:43:16 -0700172
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200173 /* 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 Ziswilerd2b64bd2017-04-01 15:43:16 -0700194
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200195 /* Make sure controller gets enabled by disabling DEV_OFF_N */
196 gpio_set_value(LAN_DEV_OFF_N, 1);
Marcel Ziswilerd2b64bd2017-04-01 15:43:16 -0700197
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200198 /*
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 Ziswilerd2b64bd2017-04-01 15:43:16 -0700212
Marcel Ziswiler07ce1a62018-05-08 17:34:11 +0200213 /*
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 Ziswilerd2b64bd2017-04-01 15:43:16 -0700242}
243#endif /* CONFIG_PCI_TEGRA */
Gerard Salvatella108d7392018-11-19 15:54:10 +0100244
245/*
Igor Opaniukfeb8c0d2019-08-01 11:06:32 +0300246 * Enable/start PWM CPU fan
247 */
248void start_cpu_fan(void)
249{
250 gpio_request(FAN_EN, "FAN_EN");
251 gpio_direction_output(FAN_EN, 1);
252}
253
254/*
Gerard Salvatella108d7392018-11-19 15:54:10 +0100255 * Backlight off before OS handover
256 */
257void board_preboot_os(void)
258{
259 gpio_request(TEGRA_GPIO(BB, 5), "BL_ON");
260 gpio_direction_output(TEGRA_GPIO(BB, 5), 0);
261}