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