5e6ba69c0b8a61a62185a211e5afeedeabf5727a
[oweals/u-boot.git] / board / toradex / apalis_t30 / apalis_t30.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  *  (C) Copyright 2014-2018
4  *  Marcel Ziswiler <marcel@ziswiler.com>
5  */
6
7 #include <common.h>
8 #include <init.h>
9 #include <log.h>
10 #include <asm/arch/gp_padctrl.h>
11 #include <asm/arch/pinmux.h>
12 #include <asm/arch-tegra/ap.h>
13 #include <asm/arch-tegra/tegra.h>
14 #include <asm/gpio.h>
15 #include <asm/io.h>
16 #include <dm.h>
17 #include <i2c.h>
18 #include <pci_tegra.h>
19 #include "../common/tdx-common.h"
20
21 #include "pinmux-config-apalis_t30.h"
22
23 DECLARE_GLOBAL_DATA_PTR;
24
25 #define PMU_I2C_ADDRESS         0x2D
26 #define MAX_I2C_RETRY           3
27
28 #ifdef CONFIG_APALIS_T30_PCIE_EVALBOARD_INIT
29 #define PEX_PERST_N     TEGRA_GPIO(S, 7) /* Apalis GPIO7 */
30 #define RESET_MOCI_CTRL TEGRA_GPIO(I, 4)
31
32 static int pci_reset_status;
33 #endif /* CONFIG_APALIS_T30_PCIE_EVALBOARD_INIT */
34
35 int arch_misc_init(void)
36 {
37         if (readl(NV_PA_BASE_SRAM + NVBOOTINFOTABLE_BOOTTYPE) ==
38             NVBOOTTYPE_RECOVERY)
39                 printf("USB recovery mode\n");
40
41         return 0;
42 }
43
44 int checkboard(void)
45 {
46         printf("Model: Toradex Apalis T30 %dGB\n",
47                (gd->ram_size == 0x40000000) ? 1 : 2);
48
49         return 0;
50 }
51
52 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
53 int ft_board_setup(void *blob, bd_t *bd)
54 {
55         return ft_common_board_setup(blob, bd);
56 }
57 #endif
58
59 /*
60  * Routine: pinmux_init
61  * Description: Do individual peripheral pinmux configs
62  */
63 void pinmux_init(void)
64 {
65         pinmux_config_pingrp_table(tegra3_pinmux_common,
66                                    ARRAY_SIZE(tegra3_pinmux_common));
67
68         pinmux_config_pingrp_table(unused_pins_lowpower,
69                                    ARRAY_SIZE(unused_pins_lowpower));
70
71         /* Initialize any non-default pad configs (APB_MISC_GP regs) */
72         pinmux_config_drvgrp_table(apalis_t30_padctrl,
73                                    ARRAY_SIZE(apalis_t30_padctrl));
74 }
75
76 #ifdef CONFIG_PCI_TEGRA
77 int tegra_pcie_board_init(void)
78 {
79         struct udevice *dev;
80         u8 addr, data[1];
81         int err;
82
83         err = i2c_get_chip_for_busnum(0, PMU_I2C_ADDRESS, 1, &dev);
84         if (err) {
85                 debug("%s: Cannot find PMIC I2C chip\n", __func__);
86                 return err;
87         }
88
89         /* TPS659110: VDD2_OP_REG = 1.05V */
90         data[0] = 0x27;
91         addr = 0x25;
92
93         err = dm_i2c_write(dev, addr, data, 1);
94         if (err) {
95                 debug("failed to set VDD supply\n");
96                 return err;
97         }
98
99         /* TPS659110: VDD2_REG 7.5 mV/us, ACTIVE */
100         data[0] = 0x0D;
101         addr = 0x24;
102
103         err = dm_i2c_write(dev, addr, data, 1);
104         if (err) {
105                 debug("failed to enable VDD supply\n");
106                 return err;
107         }
108
109         /* TPS659110: LDO6_REG = 1.1V, ACTIVE */
110         data[0] = 0x0D;
111         addr = 0x35;
112
113         err = dm_i2c_write(dev, addr, data, 1);
114         if (err) {
115                 debug("failed to set AVDD supply\n");
116                 return err;
117         }
118
119 #ifdef CONFIG_APALIS_T30_PCIE_EVALBOARD_INIT
120         gpio_request(PEX_PERST_N, "PEX_PERST_N");
121         gpio_request(RESET_MOCI_CTRL, "RESET_MOCI_CTRL");
122 #endif /* CONFIG_APALIS_T30_PCIE_EVALBOARD_INIT */
123
124         return 0;
125 }
126
127 void tegra_pcie_board_port_reset(struct tegra_pcie_port *port)
128 {
129         int index = tegra_pcie_port_index_of_port(port);
130
131         if (index == 2) { /* I210 Gigabit Ethernet Controller (On-module) */
132                 tegra_pcie_port_reset(port);
133         }
134 #ifdef CONFIG_APALIS_T30_PCIE_EVALBOARD_INIT
135         /*
136          * Apalis PCIe aka port 1 and Apalis Type Specific 4 Lane PCIe aka port
137          * 0 share the same RESET_MOCI therefore only assert it once for both
138          * ports to avoid losing the previously brought up port again.
139          */
140         else if ((index == 1) || (index == 0)) {
141                 /* only do it once per init cycle */
142                 if (pci_reset_status % 2 == 0) {
143                         /*
144                          * Reset PLX PEX 8605 PCIe Switch plus PCIe devices on
145                          * Apalis Evaluation Board
146                          */
147                         gpio_direction_output(PEX_PERST_N, 0);
148                         gpio_direction_output(RESET_MOCI_CTRL, 0);
149
150                         /*
151                          * Must be asserted for 100 ms after power and clocks
152                          * are stable
153                          */
154                         mdelay(100);
155
156                         gpio_set_value(PEX_PERST_N, 1);
157                         /*
158                          * Err_5: PEX_REFCLK_OUTpx/nx Clock Outputs is not
159                          * Guaranteed Until 900 us After PEX_PERST# De-assertion
160                          */
161                         mdelay(1);
162                         gpio_set_value(RESET_MOCI_CTRL, 1);
163                 }
164                 pci_reset_status++;
165         }
166 #endif /* CONFIG_APALIS_T30_PCIE_EVALBOARD_INIT */
167 }
168 #endif /* CONFIG_PCI_TEGRA */
169
170 /*
171  * Backlight off before OS handover
172  */
173 void board_preboot_os(void)
174 {
175         gpio_request(TEGRA_GPIO(V, 2), "BKL1_ON");
176         gpio_direction_output(TEGRA_GPIO(V, 2), 0);
177 }