blob: 73ef4d2db32ca4dca3d7076b4ee6f60426edd45f [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Lucas Stach85990a92012-10-07 11:36:06 +00002/*
3 * Copyright (C) 2012 Lucas Stach
Lucas Stach85990a92012-10-07 11:36:06 +00004 */
5
6#include <common.h>
Simon Glass97589732020-05-10 11:40:02 -06007#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -06008#include <log.h>
Lucas Stach85990a92012-10-07 11:36:06 +00009#include <asm/arch/clock.h>
10#include <asm/arch/funcmux.h>
11#include <asm/arch/pinmux.h>
Marcel Ziswilerdd899d02015-08-06 00:47:00 +020012#include <asm/arch-tegra/ap.h>
Lucas Stach85990a92012-10-07 11:36:06 +000013#include <asm/arch-tegra/board.h>
Marcel Ziswilerdd899d02015-08-06 00:47:00 +020014#include <asm/arch-tegra/tegra.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060015#include <asm/global_data.h>
Marcel Ziswileraf722622015-03-26 01:31:53 +010016#include <asm/gpio.h>
Marcel Ziswilerdd899d02015-08-06 00:47:00 +020017#include <asm/io.h>
Marcel Ziswilerf0c3fb72015-08-06 00:47:04 +020018#include <i2c.h>
Marcel Ziswilerd92dee52016-11-16 17:49:23 +010019#include <nand.h>
Simon Glassdbd79542020-05-10 11:40:11 -060020#include <linux/delay.h>
Stefan Agner98ffd0f2016-11-30 13:41:53 -080021#include "../common/tdx-common.h"
Marcel Ziswilerd92dee52016-11-16 17:49:23 +010022
23DECLARE_GLOBAL_DATA_PTR;
Marcel Ziswilerf0c3fb72015-08-06 00:47:04 +020024
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)
Marcel Ziswilerdd899d02015-08-06 00:47:00 +020030
31int arch_misc_init(void)
32{
Marcel Ziswilerf0c3fb72015-08-06 00:47:04 +020033 /* Disable PMIC sleep mode on low supply voltage */
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
Marcel Ziswiler653bc792015-08-06 00:47:11 +020061 /* make sure SODIMM pin 87 nRESET_OUT is released properly */
62 pinmux_set_func(PMUX_PINGRP_ATA, PMUX_FUNC_GMI);
63
Marcel Ziswilerdd899d02015-08-06 00:47:00 +020064 if (readl(NV_PA_BASE_SRAM + NVBOOTINFOTABLE_BOOTTYPE) ==
65 NVBOOTTYPE_RECOVERY)
66 printf("USB recovery mode\n");
67
68 return 0;
69}
Lucas Stach85990a92012-10-07 11:36:06 +000070
Marcel Ziswilerd92dee52016-11-16 17:49:23 +010071int checkboard(void)
72{
73 printf("Model: Toradex Colibri T20 %dMB V%s\n",
74 (gd->ram_size == 0x10000000) ? 256 : 512,
Grygorii Strashkobb314622017-06-26 19:13:06 -050075 (get_nand_dev_by_index(0)->erasesize >> 10 == 512) ?
Marcel Ziswilerd92dee52016-11-16 17:49:23 +010076 ((gd->ram_size == 0x10000000) ? "1.1B" : "1.1C") : "1.2A");
77
78 return 0;
79}
80
Stefan Agner98ffd0f2016-11-30 13:41:53 -080081#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090082int ft_board_setup(void *blob, struct bd_info *bd)
Stefan Agner98ffd0f2016-11-30 13:41:53 -080083{
84 return ft_common_board_setup(blob, bd);
85}
86#endif
87
Masahiro Yamadab2c88682017-01-10 13:32:07 +090088#ifdef CONFIG_MMC_SDHCI_TEGRA
Tom Warren9745cf82013-02-21 12:31:30 +000089/*
90 * Routine: pin_mux_mmc
91 * Description: setup the pin muxes/tristate values for the SDMMC(s)
92 */
93void pin_mux_mmc(void)
Lucas Stach85990a92012-10-07 11:36:06 +000094{
95 funcmux_select(PERIPH_ID_SDMMC4, FUNCMUX_SDMMC4_ATB_GMA_4_BIT);
Stephen Warrenf27f4e82014-03-21 12:28:58 -060096 pinmux_tristate_disable(PMUX_PINGRP_GMB);
Lucas Stach85990a92012-10-07 11:36:06 +000097}
98#endif
Marcel Ziswileraf722622015-03-26 01:31:53 +010099
100#ifdef CONFIG_TEGRA_NAND
101void pin_mux_nand(void)
102{
103 funcmux_select(PERIPH_ID_NDFLASH, FUNCMUX_NDFLASH_KBC_8_BIT);
Marcel Ziswilerbdddbab2015-03-27 01:31:45 +0100104
105 /*
106 * configure pingroup ATC to something unrelated to
107 * avoid ATC overriding KBC
108 */
109 pinmux_set_func(PMUX_PINGRP_ATC, PMUX_FUNC_GMI);
Marcel Ziswileraf722622015-03-26 01:31:53 +0100110}
111#endif
112
113#ifdef CONFIG_USB_EHCI_TEGRA
114void pin_mux_usb(void)
115{
116 /* module internal USB bus to connect ethernet chipset */
117 funcmux_select(PERIPH_ID_USB2, FUNCMUX_USB2_ULPI);
118
119 /* ULPI reference clock output */
120 pinmux_set_func(PMUX_PINGRP_CDEV2, PMUX_FUNC_PLLP_OUT4);
121 pinmux_tristate_disable(PMUX_PINGRP_CDEV2);
122
123 /* PHY reset GPIO */
124 pinmux_tristate_disable(PMUX_PINGRP_UAC);
125
126 /* VBus GPIO */
127 pinmux_tristate_disable(PMUX_PINGRP_DTE);
128
Marcel Ziswilerc33dd262015-03-26 02:17:07 +0100129 /* Reset ASIX using LAN_RESET */
Stephen Warren7f20bb22016-05-12 12:07:39 -0600130 gpio_request(TEGRA_GPIO(V, 4), "LAN_RESET");
131 gpio_direction_output(TEGRA_GPIO(V, 4), 0);
Marcel Ziswilerc33dd262015-03-26 02:17:07 +0100132 pinmux_tristate_disable(PMUX_PINGRP_GPV);
133 udelay(5);
Stephen Warren7f20bb22016-05-12 12:07:39 -0600134 gpio_set_value(TEGRA_GPIO(V, 4), 1);
Marcel Ziswilerc33dd262015-03-26 02:17:07 +0100135
136 /* USBH_PEN: USB 1 aka Tegra USB port 3 VBus */
Marcel Ziswileraf722622015-03-26 01:31:53 +0100137 pinmux_tristate_disable(PMUX_PINGRP_SPIG);
138}
139#endif
Marcel Ziswilercbd2b512015-08-06 00:47:02 +0200140
Simon Glass89c03462016-01-30 16:37:51 -0700141#ifdef CONFIG_VIDEO_TEGRA20
Marcel Ziswilercbd2b512015-08-06 00:47:02 +0200142/*
143 * Routine: pin_mux_display
144 * Description: setup the pin muxes/tristate values for the LCD interface)
145 */
146void pin_mux_display(void)
147{
148 /*
149 * Manually untristate BL_ON (PT4 - SODIMM 71) as specified through
150 * device-tree
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}
Gerard Salvatella108d7392018-11-19 15:54:10 +0100157
158/*
159 * Backlight off before OS handover
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}
Marcel Ziswilercbd2b512015-08-06 00:47:02 +0200166#endif