22517b9c546098f6543de30d262932eb4acfef68
[oweals/u-boot.git] / board / toradex / colibri_t20 / colibri_t20.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  *  Copyright (C) 2012 Lucas Stach
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/gpio.h>
16 #include <asm/io.h>
17 #include <i2c.h>
18 #include <nand.h>
19 #include "../common/tdx-common.h"
20
21 DECLARE_GLOBAL_DATA_PTR;
22
23 #define PMU_I2C_ADDRESS         0x34
24 #define MAX_I2C_RETRY           3
25 #define PMU_SUPPLYENE           0x14
26 #define PMU_SUPPLYENE_SYSINEN   (1<<5)
27 #define PMU_SUPPLYENE_EXITSLREQ (1<<1)
28
29 int arch_misc_init(void)
30 {
31         /* Disable PMIC sleep mode on low supply voltage */
32         struct udevice *dev;
33         u8 addr, data[1];
34         int err;
35
36         err = i2c_get_chip_for_busnum(0, PMU_I2C_ADDRESS, 1, &dev);
37         if (err) {
38                 debug("%s: Cannot find PMIC I2C chip\n", __func__);
39                 return err;
40         }
41
42         addr = PMU_SUPPLYENE;
43
44         err = dm_i2c_read(dev, addr, data, 1);
45         if (err) {
46                 debug("failed to get PMU_SUPPLYENE\n");
47                 return err;
48         }
49
50         data[0] &= ~PMU_SUPPLYENE_SYSINEN;
51         data[0] |= PMU_SUPPLYENE_EXITSLREQ;
52
53         err = dm_i2c_write(dev, addr, data, 1);
54         if (err) {
55                 debug("failed to set PMU_SUPPLYENE\n");
56                 return err;
57         }
58
59         /* make sure SODIMM pin 87 nRESET_OUT is released properly */
60         pinmux_set_func(PMUX_PINGRP_ATA, PMUX_FUNC_GMI);
61
62         if (readl(NV_PA_BASE_SRAM + NVBOOTINFOTABLE_BOOTTYPE) ==
63             NVBOOTTYPE_RECOVERY)
64                 printf("USB recovery mode\n");
65
66         return 0;
67 }
68
69 int checkboard(void)
70 {
71         printf("Model: Toradex Colibri T20 %dMB V%s\n",
72                (gd->ram_size == 0x10000000) ? 256 : 512,
73                (get_nand_dev_by_index(0)->erasesize >> 10 == 512) ?
74                ((gd->ram_size == 0x10000000) ? "1.1B" : "1.1C") : "1.2A");
75
76         return 0;
77 }
78
79 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
80 int ft_board_setup(void *blob, bd_t *bd)
81 {
82         return ft_common_board_setup(blob, bd);
83 }
84 #endif
85
86 #ifdef CONFIG_MMC_SDHCI_TEGRA
87 /*
88  * Routine: pin_mux_mmc
89  * Description: setup the pin muxes/tristate values for the SDMMC(s)
90  */
91 void pin_mux_mmc(void)
92 {
93         funcmux_select(PERIPH_ID_SDMMC4, FUNCMUX_SDMMC4_ATB_GMA_4_BIT);
94         pinmux_tristate_disable(PMUX_PINGRP_GMB);
95 }
96 #endif
97
98 #ifdef CONFIG_TEGRA_NAND
99 void pin_mux_nand(void)
100 {
101         funcmux_select(PERIPH_ID_NDFLASH, FUNCMUX_NDFLASH_KBC_8_BIT);
102
103         /*
104          * configure pingroup ATC to something unrelated to
105          * avoid ATC overriding KBC
106          */
107         pinmux_set_func(PMUX_PINGRP_ATC, PMUX_FUNC_GMI);
108 }
109 #endif
110
111 #ifdef CONFIG_USB_EHCI_TEGRA
112 void pin_mux_usb(void)
113 {
114         /* module internal USB bus to connect ethernet chipset */
115         funcmux_select(PERIPH_ID_USB2, FUNCMUX_USB2_ULPI);
116
117         /* ULPI reference clock output */
118         pinmux_set_func(PMUX_PINGRP_CDEV2, PMUX_FUNC_PLLP_OUT4);
119         pinmux_tristate_disable(PMUX_PINGRP_CDEV2);
120
121         /* PHY reset GPIO */
122         pinmux_tristate_disable(PMUX_PINGRP_UAC);
123
124         /* VBus GPIO */
125         pinmux_tristate_disable(PMUX_PINGRP_DTE);
126
127         /* Reset ASIX using LAN_RESET */
128         gpio_request(TEGRA_GPIO(V, 4), "LAN_RESET");
129         gpio_direction_output(TEGRA_GPIO(V, 4), 0);
130         pinmux_tristate_disable(PMUX_PINGRP_GPV);
131         udelay(5);
132         gpio_set_value(TEGRA_GPIO(V, 4), 1);
133
134         /* USBH_PEN: USB 1 aka Tegra USB port 3 VBus */
135         pinmux_tristate_disable(PMUX_PINGRP_SPIG);
136 }
137 #endif
138
139 #ifdef CONFIG_VIDEO_TEGRA20
140 /*
141  * Routine: pin_mux_display
142  * Description: setup the pin muxes/tristate values for the LCD interface)
143  */
144 void pin_mux_display(void)
145 {
146         /*
147          * Manually untristate BL_ON (PT4 - SODIMM 71) as specified through
148          * device-tree
149          */
150         pinmux_tristate_disable(PMUX_PINGRP_DTA);
151
152         pinmux_set_func(PMUX_PINGRP_SDC, PMUX_FUNC_PWM);
153         pinmux_tristate_disable(PMUX_PINGRP_SDC);
154 }
155
156 /*
157  * Backlight off before OS handover
158  */
159 void board_preboot_os(void)
160 {
161         gpio_request(TEGRA_GPIO(T, 4), "BL_ON");
162         gpio_direction_output(TEGRA_GPIO(T, 4), 0);
163 }
164 #endif