1
2
3
4
5
6#include <common.h>
7#include <init.h>
8#include <log.h>
9#include <asm/arch/clock.h>
10#include <asm/arch/funcmux.h>
11#include <asm/arch/pinmux.h>
12#include <asm/arch-tegra/ap.h>
13#include <asm/arch-tegra/board.h>
14#include <asm/arch-tegra/tegra.h>
15#include <asm/global_data.h>
16#include <asm/gpio.h>
17#include <asm/io.h>
18#include <i2c.h>
19#include <nand.h>
20#include <linux/delay.h>
21#include "../common/tdx-common.h"
22
23DECLARE_GLOBAL_DATA_PTR;
24
25#define PMU_I2C_ADDRESS 0x34
26#define MAX_I2C_RETRY 3
27#define PMU_SUPPLYENE 0x14
28#define PMU_SUPPLYENE_SYSINEN (1<<5)
29#define PMU_SUPPLYENE_EXITSLREQ (1<<1)
30
31int arch_misc_init(void)
32{
33
34 struct udevice *dev;
35 u8 addr, data[1];
36 int err;
37
38 err = i2c_get_chip_for_busnum(0, PMU_I2C_ADDRESS, 1, &dev);
39 if (err) {
40 debug("%s: Cannot find PMIC I2C chip\n", __func__);
41 return err;
42 }
43
44 addr = PMU_SUPPLYENE;
45
46 err = dm_i2c_read(dev, addr, data, 1);
47 if (err) {
48 debug("failed to get PMU_SUPPLYENE\n");
49 return err;
50 }
51
52 data[0] &= ~PMU_SUPPLYENE_SYSINEN;
53 data[0] |= PMU_SUPPLYENE_EXITSLREQ;
54
55 err = dm_i2c_write(dev, addr, data, 1);
56 if (err) {
57 debug("failed to set PMU_SUPPLYENE\n");
58 return err;
59 }
60
61
62 pinmux_set_func(PMUX_PINGRP_ATA, PMUX_FUNC_GMI);
63
64 if (readl(NV_PA_BASE_SRAM + NVBOOTINFOTABLE_BOOTTYPE) ==
65 NVBOOTTYPE_RECOVERY)
66 printf("USB recovery mode\n");
67
68 return 0;
69}
70
71int checkboard(void)
72{
73 printf("Model: Toradex Colibri T20 %dMB V%s\n",
74 (gd->ram_size == 0x10000000) ? 256 : 512,
75 (get_nand_dev_by_index(0)->erasesize >> 10 == 512) ?
76 ((gd->ram_size == 0x10000000) ? "1.1B" : "1.1C") : "1.2A");
77
78 return 0;
79}
80
81#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
82int ft_board_setup(void *blob, struct bd_info *bd)
83{
84 return ft_common_board_setup(blob, bd);
85}
86#endif
87
88#ifdef CONFIG_MMC_SDHCI_TEGRA
89
90
91
92
93void pin_mux_mmc(void)
94{
95 funcmux_select(PERIPH_ID_SDMMC4, FUNCMUX_SDMMC4_ATB_GMA_4_BIT);
96 pinmux_tristate_disable(PMUX_PINGRP_GMB);
97}
98#endif
99
100#ifdef CONFIG_TEGRA_NAND
101void pin_mux_nand(void)
102{
103 funcmux_select(PERIPH_ID_NDFLASH, FUNCMUX_NDFLASH_KBC_8_BIT);
104
105
106
107
108
109 pinmux_set_func(PMUX_PINGRP_ATC, PMUX_FUNC_GMI);
110}
111#endif
112
113#ifdef CONFIG_USB_EHCI_TEGRA
114void pin_mux_usb(void)
115{
116
117 funcmux_select(PERIPH_ID_USB2, FUNCMUX_USB2_ULPI);
118
119
120 pinmux_set_func(PMUX_PINGRP_CDEV2, PMUX_FUNC_PLLP_OUT4);
121 pinmux_tristate_disable(PMUX_PINGRP_CDEV2);
122
123
124 pinmux_tristate_disable(PMUX_PINGRP_UAC);
125
126
127 pinmux_tristate_disable(PMUX_PINGRP_DTE);
128
129
130 gpio_request(TEGRA_GPIO(V, 4), "LAN_RESET");
131 gpio_direction_output(TEGRA_GPIO(V, 4), 0);
132 pinmux_tristate_disable(PMUX_PINGRP_GPV);
133 udelay(5);
134 gpio_set_value(TEGRA_GPIO(V, 4), 1);
135
136
137 pinmux_tristate_disable(PMUX_PINGRP_SPIG);
138}
139#endif
140
141#ifdef CONFIG_VIDEO_TEGRA20
142
143
144
145
146void pin_mux_display(void)
147{
148
149
150
151
152 pinmux_tristate_disable(PMUX_PINGRP_DTA);
153
154 pinmux_set_func(PMUX_PINGRP_SDC, PMUX_FUNC_PWM);
155 pinmux_tristate_disable(PMUX_PINGRP_SDC);
156}
157
158
159
160
161void board_preboot_os(void)
162{
163 gpio_request(TEGRA_GPIO(T, 4), "BL_ON");
164 gpio_direction_output(TEGRA_GPIO(T, 4), 0);
165}
166#endif
167