Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Lucas Stach | 85990a9 | 2012-10-07 11:36:06 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2012 Lucas Stach |
Lucas Stach | 85990a9 | 2012-10-07 11:36:06 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Marcel Ziswiler | 61c99fe | 2022-05-21 12:42:46 +0200 | [diff] [blame] | 7 | #include <env.h> |
Tom Rini | cb4f59c | 2022-06-14 12:28:58 -0400 | [diff] [blame] | 8 | #include <fdt_support.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 9 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Lucas Stach | 85990a9 | 2012-10-07 11:36:06 +0000 | [diff] [blame] | 11 | #include <asm/arch/clock.h> |
| 12 | #include <asm/arch/funcmux.h> |
| 13 | #include <asm/arch/pinmux.h> |
Marcel Ziswiler | dd899d0 | 2015-08-06 00:47:00 +0200 | [diff] [blame] | 14 | #include <asm/arch-tegra/ap.h> |
Lucas Stach | 85990a9 | 2012-10-07 11:36:06 +0000 | [diff] [blame] | 15 | #include <asm/arch-tegra/board.h> |
Marcel Ziswiler | dd899d0 | 2015-08-06 00:47:00 +0200 | [diff] [blame] | 16 | #include <asm/arch-tegra/tegra.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 17 | #include <asm/global_data.h> |
Marcel Ziswiler | af72262 | 2015-03-26 01:31:53 +0100 | [diff] [blame] | 18 | #include <asm/gpio.h> |
Marcel Ziswiler | dd899d0 | 2015-08-06 00:47:00 +0200 | [diff] [blame] | 19 | #include <asm/io.h> |
Marcel Ziswiler | f0c3fb7 | 2015-08-06 00:47:04 +0200 | [diff] [blame] | 20 | #include <i2c.h> |
Marcel Ziswiler | d92dee5 | 2016-11-16 17:49:23 +0100 | [diff] [blame] | 21 | #include <nand.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 22 | #include <linux/delay.h> |
Stefan Agner | 98ffd0f | 2016-11-30 13:41:53 -0800 | [diff] [blame] | 23 | #include "../common/tdx-common.h" |
Marcel Ziswiler | d92dee5 | 2016-11-16 17:49:23 +0100 | [diff] [blame] | 24 | |
| 25 | DECLARE_GLOBAL_DATA_PTR; |
Marcel Ziswiler | f0c3fb7 | 2015-08-06 00:47:04 +0200 | [diff] [blame] | 26 | |
| 27 | #define PMU_I2C_ADDRESS 0x34 |
| 28 | #define MAX_I2C_RETRY 3 |
| 29 | #define PMU_SUPPLYENE 0x14 |
| 30 | #define PMU_SUPPLYENE_SYSINEN (1<<5) |
| 31 | #define PMU_SUPPLYENE_EXITSLREQ (1<<1) |
Marcel Ziswiler | dd899d0 | 2015-08-06 00:47:00 +0200 | [diff] [blame] | 32 | |
| 33 | int arch_misc_init(void) |
| 34 | { |
Marcel Ziswiler | f0c3fb7 | 2015-08-06 00:47:04 +0200 | [diff] [blame] | 35 | /* Disable PMIC sleep mode on low supply voltage */ |
| 36 | struct udevice *dev; |
| 37 | u8 addr, data[1]; |
| 38 | int err; |
| 39 | |
| 40 | err = i2c_get_chip_for_busnum(0, PMU_I2C_ADDRESS, 1, &dev); |
| 41 | if (err) { |
| 42 | debug("%s: Cannot find PMIC I2C chip\n", __func__); |
| 43 | return err; |
| 44 | } |
| 45 | |
| 46 | addr = PMU_SUPPLYENE; |
| 47 | |
| 48 | err = dm_i2c_read(dev, addr, data, 1); |
| 49 | if (err) { |
| 50 | debug("failed to get PMU_SUPPLYENE\n"); |
| 51 | return err; |
| 52 | } |
| 53 | |
| 54 | data[0] &= ~PMU_SUPPLYENE_SYSINEN; |
| 55 | data[0] |= PMU_SUPPLYENE_EXITSLREQ; |
| 56 | |
| 57 | err = dm_i2c_write(dev, addr, data, 1); |
| 58 | if (err) { |
| 59 | debug("failed to set PMU_SUPPLYENE\n"); |
| 60 | return err; |
| 61 | } |
| 62 | |
Marcel Ziswiler | 653bc79 | 2015-08-06 00:47:11 +0200 | [diff] [blame] | 63 | /* make sure SODIMM pin 87 nRESET_OUT is released properly */ |
| 64 | pinmux_set_func(PMUX_PINGRP_ATA, PMUX_FUNC_GMI); |
| 65 | |
Marcel Ziswiler | dd899d0 | 2015-08-06 00:47:00 +0200 | [diff] [blame] | 66 | if (readl(NV_PA_BASE_SRAM + NVBOOTINFOTABLE_BOOTTYPE) == |
| 67 | NVBOOTTYPE_RECOVERY) |
| 68 | printf("USB recovery mode\n"); |
| 69 | |
| 70 | return 0; |
| 71 | } |
Lucas Stach | 85990a9 | 2012-10-07 11:36:06 +0000 | [diff] [blame] | 72 | |
Marcel Ziswiler | d92dee5 | 2016-11-16 17:49:23 +0100 | [diff] [blame] | 73 | int checkboard(void) |
| 74 | { |
| 75 | printf("Model: Toradex Colibri T20 %dMB V%s\n", |
| 76 | (gd->ram_size == 0x10000000) ? 256 : 512, |
Grygorii Strashko | bb31462 | 2017-06-26 19:13:06 -0500 | [diff] [blame] | 77 | (get_nand_dev_by_index(0)->erasesize >> 10 == 512) ? |
Marcel Ziswiler | d92dee5 | 2016-11-16 17:49:23 +0100 | [diff] [blame] | 78 | ((gd->ram_size == 0x10000000) ? "1.1B" : "1.1C") : "1.2A"); |
| 79 | |
| 80 | return 0; |
| 81 | } |
| 82 | |
Stefan Agner | 98ffd0f | 2016-11-30 13:41:53 -0800 | [diff] [blame] | 83 | #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 84 | int ft_board_setup(void *blob, struct bd_info *bd) |
Stefan Agner | 98ffd0f | 2016-11-30 13:41:53 -0800 | [diff] [blame] | 85 | { |
Marcel Ziswiler | 61c99fe | 2022-05-21 12:42:46 +0200 | [diff] [blame] | 86 | u8 enetaddr[6]; |
| 87 | |
| 88 | /* MAC addr */ |
| 89 | if (eth_env_get_enetaddr("ethaddr", enetaddr)) { |
| 90 | int err = fdt_find_and_setprop(blob, |
| 91 | "/usb@7d004000/ethernet@1", |
| 92 | "local-mac-address", enetaddr, 6, 0); |
| 93 | |
| 94 | /* Older device trees might have used a different node name */ |
| 95 | if (err < 0) |
| 96 | err = fdt_find_and_setprop(blob, |
| 97 | "/usb@7d004000/asix@1", |
| 98 | "local-mac-address", enetaddr, 6, 0); |
| 99 | |
| 100 | if (err >= 0) |
| 101 | puts(" MAC address updated...\n"); |
| 102 | } |
| 103 | |
Stefan Agner | 98ffd0f | 2016-11-30 13:41:53 -0800 | [diff] [blame] | 104 | return ft_common_board_setup(blob, bd); |
| 105 | } |
| 106 | #endif |
| 107 | |
Masahiro Yamada | b2c8868 | 2017-01-10 13:32:07 +0900 | [diff] [blame] | 108 | #ifdef CONFIG_MMC_SDHCI_TEGRA |
Tom Warren | 9745cf8 | 2013-02-21 12:31:30 +0000 | [diff] [blame] | 109 | /* |
| 110 | * Routine: pin_mux_mmc |
| 111 | * Description: setup the pin muxes/tristate values for the SDMMC(s) |
| 112 | */ |
| 113 | void pin_mux_mmc(void) |
Lucas Stach | 85990a9 | 2012-10-07 11:36:06 +0000 | [diff] [blame] | 114 | { |
| 115 | funcmux_select(PERIPH_ID_SDMMC4, FUNCMUX_SDMMC4_ATB_GMA_4_BIT); |
Stephen Warren | f27f4e8 | 2014-03-21 12:28:58 -0600 | [diff] [blame] | 116 | pinmux_tristate_disable(PMUX_PINGRP_GMB); |
Lucas Stach | 85990a9 | 2012-10-07 11:36:06 +0000 | [diff] [blame] | 117 | } |
| 118 | #endif |
Marcel Ziswiler | af72262 | 2015-03-26 01:31:53 +0100 | [diff] [blame] | 119 | |
| 120 | #ifdef CONFIG_TEGRA_NAND |
| 121 | void pin_mux_nand(void) |
| 122 | { |
| 123 | funcmux_select(PERIPH_ID_NDFLASH, FUNCMUX_NDFLASH_KBC_8_BIT); |
Marcel Ziswiler | bdddbab | 2015-03-27 01:31:45 +0100 | [diff] [blame] | 124 | |
| 125 | /* |
| 126 | * configure pingroup ATC to something unrelated to |
| 127 | * avoid ATC overriding KBC |
| 128 | */ |
| 129 | pinmux_set_func(PMUX_PINGRP_ATC, PMUX_FUNC_GMI); |
Marcel Ziswiler | af72262 | 2015-03-26 01:31:53 +0100 | [diff] [blame] | 130 | } |
| 131 | #endif |
| 132 | |
| 133 | #ifdef CONFIG_USB_EHCI_TEGRA |
| 134 | void pin_mux_usb(void) |
| 135 | { |
| 136 | /* module internal USB bus to connect ethernet chipset */ |
| 137 | funcmux_select(PERIPH_ID_USB2, FUNCMUX_USB2_ULPI); |
| 138 | |
| 139 | /* ULPI reference clock output */ |
| 140 | pinmux_set_func(PMUX_PINGRP_CDEV2, PMUX_FUNC_PLLP_OUT4); |
| 141 | pinmux_tristate_disable(PMUX_PINGRP_CDEV2); |
| 142 | |
| 143 | /* PHY reset GPIO */ |
| 144 | pinmux_tristate_disable(PMUX_PINGRP_UAC); |
| 145 | |
| 146 | /* VBus GPIO */ |
| 147 | pinmux_tristate_disable(PMUX_PINGRP_DTE); |
| 148 | |
Marcel Ziswiler | c33dd26 | 2015-03-26 02:17:07 +0100 | [diff] [blame] | 149 | /* Reset ASIX using LAN_RESET */ |
Stephen Warren | 7f20bb2 | 2016-05-12 12:07:39 -0600 | [diff] [blame] | 150 | gpio_request(TEGRA_GPIO(V, 4), "LAN_RESET"); |
| 151 | gpio_direction_output(TEGRA_GPIO(V, 4), 0); |
Marcel Ziswiler | c33dd26 | 2015-03-26 02:17:07 +0100 | [diff] [blame] | 152 | pinmux_tristate_disable(PMUX_PINGRP_GPV); |
| 153 | udelay(5); |
Stephen Warren | 7f20bb2 | 2016-05-12 12:07:39 -0600 | [diff] [blame] | 154 | gpio_set_value(TEGRA_GPIO(V, 4), 1); |
Marcel Ziswiler | c33dd26 | 2015-03-26 02:17:07 +0100 | [diff] [blame] | 155 | |
| 156 | /* USBH_PEN: USB 1 aka Tegra USB port 3 VBus */ |
Marcel Ziswiler | af72262 | 2015-03-26 01:31:53 +0100 | [diff] [blame] | 157 | pinmux_tristate_disable(PMUX_PINGRP_SPIG); |
| 158 | } |
| 159 | #endif |
Marcel Ziswiler | cbd2b51 | 2015-08-06 00:47:02 +0200 | [diff] [blame] | 160 | |
Simon Glass | 89c0346 | 2016-01-30 16:37:51 -0700 | [diff] [blame] | 161 | #ifdef CONFIG_VIDEO_TEGRA20 |
Marcel Ziswiler | cbd2b51 | 2015-08-06 00:47:02 +0200 | [diff] [blame] | 162 | /* |
| 163 | * Routine: pin_mux_display |
| 164 | * Description: setup the pin muxes/tristate values for the LCD interface) |
| 165 | */ |
| 166 | void pin_mux_display(void) |
| 167 | { |
| 168 | /* |
| 169 | * Manually untristate BL_ON (PT4 - SODIMM 71) as specified through |
| 170 | * device-tree |
| 171 | */ |
| 172 | pinmux_tristate_disable(PMUX_PINGRP_DTA); |
| 173 | |
| 174 | pinmux_set_func(PMUX_PINGRP_SDC, PMUX_FUNC_PWM); |
| 175 | pinmux_tristate_disable(PMUX_PINGRP_SDC); |
| 176 | } |
Gerard Salvatella | 108d739 | 2018-11-19 15:54:10 +0100 | [diff] [blame] | 177 | |
| 178 | /* |
| 179 | * Backlight off before OS handover |
| 180 | */ |
| 181 | void board_preboot_os(void) |
| 182 | { |
| 183 | gpio_request(TEGRA_GPIO(T, 4), "BL_ON"); |
| 184 | gpio_direction_output(TEGRA_GPIO(T, 4), 0); |
| 185 | } |
Marcel Ziswiler | cbd2b51 | 2015-08-06 00:47:02 +0200 | [diff] [blame] | 186 | #endif |