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