blob: 6425fa881ea6a90ee035276bc5c6a809b9236483 [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
Marcel Ziswiler61c99fe2022-05-21 12:42:46 +02006#include <env.h>
Tom Rinicb4f59c2022-06-14 12:28:58 -04007#include <fdt_support.h>
Simon Glass97589732020-05-10 11:40:02 -06008#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
Lucas Stach85990a92012-10-07 11:36:06 +000010#include <asm/arch/clock.h>
11#include <asm/arch/funcmux.h>
12#include <asm/arch/pinmux.h>
Marcel Ziswilerdd899d02015-08-06 00:47:00 +020013#include <asm/arch-tegra/ap.h>
Lucas Stach85990a92012-10-07 11:36:06 +000014#include <asm/arch-tegra/board.h>
Marcel Ziswilerdd899d02015-08-06 00:47:00 +020015#include <asm/arch-tegra/tegra.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060016#include <asm/global_data.h>
Marcel Ziswileraf722622015-03-26 01:31:53 +010017#include <asm/gpio.h>
Marcel Ziswilerdd899d02015-08-06 00:47:00 +020018#include <asm/io.h>
Marcel Ziswilerf0c3fb72015-08-06 00:47:04 +020019#include <i2c.h>
Marcel Ziswilerd92dee52016-11-16 17:49:23 +010020#include <nand.h>
Simon Glassdbd79542020-05-10 11:40:11 -060021#include <linux/delay.h>
Stefan Agner98ffd0f2016-11-30 13:41:53 -080022#include "../common/tdx-common.h"
Marcel Ziswilerd92dee52016-11-16 17:49:23 +010023
24DECLARE_GLOBAL_DATA_PTR;
Marcel Ziswilerf0c3fb72015-08-06 00:47:04 +020025
26#define PMU_I2C_ADDRESS 0x34
27#define MAX_I2C_RETRY 3
28#define PMU_SUPPLYENE 0x14
29#define PMU_SUPPLYENE_SYSINEN (1<<5)
30#define PMU_SUPPLYENE_EXITSLREQ (1<<1)
Marcel Ziswilerdd899d02015-08-06 00:47:00 +020031
32int arch_misc_init(void)
33{
Marcel Ziswilerf0c3fb72015-08-06 00:47:04 +020034 /* Disable PMIC sleep mode on low supply voltage */
35 struct udevice *dev;
36 u8 addr, data[1];
37 int err;
38
39 err = i2c_get_chip_for_busnum(0, PMU_I2C_ADDRESS, 1, &dev);
40 if (err) {
41 debug("%s: Cannot find PMIC I2C chip\n", __func__);
42 return err;
43 }
44
45 addr = PMU_SUPPLYENE;
46
47 err = dm_i2c_read(dev, addr, data, 1);
48 if (err) {
49 debug("failed to get PMU_SUPPLYENE\n");
50 return err;
51 }
52
53 data[0] &= ~PMU_SUPPLYENE_SYSINEN;
54 data[0] |= PMU_SUPPLYENE_EXITSLREQ;
55
56 err = dm_i2c_write(dev, addr, data, 1);
57 if (err) {
58 debug("failed to set PMU_SUPPLYENE\n");
59 return err;
60 }
61
Marcel Ziswiler653bc792015-08-06 00:47:11 +020062 /* make sure SODIMM pin 87 nRESET_OUT is released properly */
63 pinmux_set_func(PMUX_PINGRP_ATA, PMUX_FUNC_GMI);
64
Marcel Ziswilerdd899d02015-08-06 00:47:00 +020065 if (readl(NV_PA_BASE_SRAM + NVBOOTINFOTABLE_BOOTTYPE) ==
66 NVBOOTTYPE_RECOVERY)
67 printf("USB recovery mode\n");
68
69 return 0;
70}
Lucas Stach85990a92012-10-07 11:36:06 +000071
Stefan Agner98ffd0f2016-11-30 13:41:53 -080072#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090073int ft_board_setup(void *blob, struct bd_info *bd)
Stefan Agner98ffd0f2016-11-30 13:41:53 -080074{
Marcel Ziswiler61c99fe2022-05-21 12:42:46 +020075 u8 enetaddr[6];
76
77 /* MAC addr */
78 if (eth_env_get_enetaddr("ethaddr", enetaddr)) {
79 int err = fdt_find_and_setprop(blob,
80 "/usb@7d004000/ethernet@1",
81 "local-mac-address", enetaddr, 6, 0);
82
83 /* Older device trees might have used a different node name */
84 if (err < 0)
85 err = fdt_find_and_setprop(blob,
86 "/usb@7d004000/asix@1",
87 "local-mac-address", enetaddr, 6, 0);
88
89 if (err >= 0)
90 puts(" MAC address updated...\n");
91 }
92
Stefan Agner98ffd0f2016-11-30 13:41:53 -080093 return ft_common_board_setup(blob, bd);
94}
95#endif
96
Masahiro Yamadab2c88682017-01-10 13:32:07 +090097#ifdef CONFIG_MMC_SDHCI_TEGRA
Tom Warren9745cf82013-02-21 12:31:30 +000098/*
99 * Routine: pin_mux_mmc
100 * Description: setup the pin muxes/tristate values for the SDMMC(s)
101 */
102void pin_mux_mmc(void)
Lucas Stach85990a92012-10-07 11:36:06 +0000103{
104 funcmux_select(PERIPH_ID_SDMMC4, FUNCMUX_SDMMC4_ATB_GMA_4_BIT);
Stephen Warrenf27f4e82014-03-21 12:28:58 -0600105 pinmux_tristate_disable(PMUX_PINGRP_GMB);
Lucas Stach85990a92012-10-07 11:36:06 +0000106}
107#endif
Marcel Ziswileraf722622015-03-26 01:31:53 +0100108
109#ifdef CONFIG_TEGRA_NAND
110void pin_mux_nand(void)
111{
112 funcmux_select(PERIPH_ID_NDFLASH, FUNCMUX_NDFLASH_KBC_8_BIT);
Marcel Ziswilerbdddbab2015-03-27 01:31:45 +0100113
114 /*
115 * configure pingroup ATC to something unrelated to
116 * avoid ATC overriding KBC
117 */
118 pinmux_set_func(PMUX_PINGRP_ATC, PMUX_FUNC_GMI);
Marcel Ziswileraf722622015-03-26 01:31:53 +0100119}
120#endif
121
122#ifdef CONFIG_USB_EHCI_TEGRA
123void pin_mux_usb(void)
124{
125 /* module internal USB bus to connect ethernet chipset */
126 funcmux_select(PERIPH_ID_USB2, FUNCMUX_USB2_ULPI);
127
128 /* ULPI reference clock output */
129 pinmux_set_func(PMUX_PINGRP_CDEV2, PMUX_FUNC_PLLP_OUT4);
130 pinmux_tristate_disable(PMUX_PINGRP_CDEV2);
131
132 /* PHY reset GPIO */
133 pinmux_tristate_disable(PMUX_PINGRP_UAC);
134
135 /* VBus GPIO */
136 pinmux_tristate_disable(PMUX_PINGRP_DTE);
137
Marcel Ziswilerc33dd262015-03-26 02:17:07 +0100138 /* Reset ASIX using LAN_RESET */
Stephen Warren7f20bb22016-05-12 12:07:39 -0600139 gpio_request(TEGRA_GPIO(V, 4), "LAN_RESET");
140 gpio_direction_output(TEGRA_GPIO(V, 4), 0);
Marcel Ziswilerc33dd262015-03-26 02:17:07 +0100141 pinmux_tristate_disable(PMUX_PINGRP_GPV);
142 udelay(5);
Stephen Warren7f20bb22016-05-12 12:07:39 -0600143 gpio_set_value(TEGRA_GPIO(V, 4), 1);
Marcel Ziswilerc33dd262015-03-26 02:17:07 +0100144
145 /* USBH_PEN: USB 1 aka Tegra USB port 3 VBus */
Marcel Ziswileraf722622015-03-26 01:31:53 +0100146 pinmux_tristate_disable(PMUX_PINGRP_SPIG);
147}
148#endif
Marcel Ziswilercbd2b512015-08-06 00:47:02 +0200149
Simon Glass89c03462016-01-30 16:37:51 -0700150#ifdef CONFIG_VIDEO_TEGRA20
Marcel Ziswilercbd2b512015-08-06 00:47:02 +0200151/*
152 * Routine: pin_mux_display
153 * Description: setup the pin muxes/tristate values for the LCD interface)
154 */
155void pin_mux_display(void)
156{
157 /*
158 * Manually untristate BL_ON (PT4 - SODIMM 71) as specified through
159 * device-tree
160 */
161 pinmux_tristate_disable(PMUX_PINGRP_DTA);
162
163 pinmux_set_func(PMUX_PINGRP_SDC, PMUX_FUNC_PWM);
164 pinmux_tristate_disable(PMUX_PINGRP_SDC);
165}
Gerard Salvatella108d7392018-11-19 15:54:10 +0100166
167/*
168 * Backlight off before OS handover
169 */
170void board_preboot_os(void)
171{
172 gpio_request(TEGRA_GPIO(T, 4), "BL_ON");
173 gpio_direction_output(TEGRA_GPIO(T, 4), 0);
174}
Marcel Ziswilercbd2b512015-08-06 00:47:02 +0200175#endif