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> |
| 17 | |
| 18 | #define PMU_I2C_ADDRESS 0x34 |
| 19 | #define MAX_I2C_RETRY 3 |
| 20 | #define PMU_SUPPLYENE 0x14 |
| 21 | #define PMU_SUPPLYENE_SYSINEN (1<<5) |
| 22 | #define PMU_SUPPLYENE_EXITSLREQ (1<<1) |
Marcel Ziswiler | dd899d0 | 2015-08-06 00:47:00 +0200 | [diff] [blame] | 23 | |
| 24 | int arch_misc_init(void) |
| 25 | { |
Marcel Ziswiler | f0c3fb7 | 2015-08-06 00:47:04 +0200 | [diff] [blame] | 26 | /* Disable PMIC sleep mode on low supply voltage */ |
| 27 | struct udevice *dev; |
| 28 | u8 addr, data[1]; |
| 29 | int err; |
| 30 | |
| 31 | err = i2c_get_chip_for_busnum(0, PMU_I2C_ADDRESS, 1, &dev); |
| 32 | if (err) { |
| 33 | debug("%s: Cannot find PMIC I2C chip\n", __func__); |
| 34 | return err; |
| 35 | } |
| 36 | |
| 37 | addr = PMU_SUPPLYENE; |
| 38 | |
| 39 | err = dm_i2c_read(dev, addr, data, 1); |
| 40 | if (err) { |
| 41 | debug("failed to get PMU_SUPPLYENE\n"); |
| 42 | return err; |
| 43 | } |
| 44 | |
| 45 | data[0] &= ~PMU_SUPPLYENE_SYSINEN; |
| 46 | data[0] |= PMU_SUPPLYENE_EXITSLREQ; |
| 47 | |
| 48 | err = dm_i2c_write(dev, addr, data, 1); |
| 49 | if (err) { |
| 50 | debug("failed to set PMU_SUPPLYENE\n"); |
| 51 | return err; |
| 52 | } |
| 53 | |
Marcel Ziswiler | 653bc79 | 2015-08-06 00:47:11 +0200 | [diff] [blame] | 54 | /* make sure SODIMM pin 87 nRESET_OUT is released properly */ |
| 55 | pinmux_set_func(PMUX_PINGRP_ATA, PMUX_FUNC_GMI); |
| 56 | |
Marcel Ziswiler | dd899d0 | 2015-08-06 00:47:00 +0200 | [diff] [blame] | 57 | if (readl(NV_PA_BASE_SRAM + NVBOOTINFOTABLE_BOOTTYPE) == |
| 58 | NVBOOTTYPE_RECOVERY) |
| 59 | printf("USB recovery mode\n"); |
| 60 | |
| 61 | return 0; |
| 62 | } |
Lucas Stach | 85990a9 | 2012-10-07 11:36:06 +0000 | [diff] [blame] | 63 | |
| 64 | #ifdef CONFIG_TEGRA_MMC |
Tom Warren | 9745cf8 | 2013-02-21 12:31:30 +0000 | [diff] [blame] | 65 | /* |
| 66 | * Routine: pin_mux_mmc |
| 67 | * Description: setup the pin muxes/tristate values for the SDMMC(s) |
| 68 | */ |
| 69 | void pin_mux_mmc(void) |
Lucas Stach | 85990a9 | 2012-10-07 11:36:06 +0000 | [diff] [blame] | 70 | { |
| 71 | funcmux_select(PERIPH_ID_SDMMC4, FUNCMUX_SDMMC4_ATB_GMA_4_BIT); |
Stephen Warren | f27f4e8 | 2014-03-21 12:28:58 -0600 | [diff] [blame] | 72 | pinmux_tristate_disable(PMUX_PINGRP_GMB); |
Lucas Stach | 85990a9 | 2012-10-07 11:36:06 +0000 | [diff] [blame] | 73 | } |
| 74 | #endif |
Marcel Ziswiler | af72262 | 2015-03-26 01:31:53 +0100 | [diff] [blame] | 75 | |
| 76 | #ifdef CONFIG_TEGRA_NAND |
| 77 | void pin_mux_nand(void) |
| 78 | { |
| 79 | funcmux_select(PERIPH_ID_NDFLASH, FUNCMUX_NDFLASH_KBC_8_BIT); |
Marcel Ziswiler | bdddbab | 2015-03-27 01:31:45 +0100 | [diff] [blame] | 80 | |
| 81 | /* |
| 82 | * configure pingroup ATC to something unrelated to |
| 83 | * avoid ATC overriding KBC |
| 84 | */ |
| 85 | pinmux_set_func(PMUX_PINGRP_ATC, PMUX_FUNC_GMI); |
Marcel Ziswiler | af72262 | 2015-03-26 01:31:53 +0100 | [diff] [blame] | 86 | } |
| 87 | #endif |
| 88 | |
| 89 | #ifdef CONFIG_USB_EHCI_TEGRA |
| 90 | void pin_mux_usb(void) |
| 91 | { |
| 92 | /* module internal USB bus to connect ethernet chipset */ |
| 93 | funcmux_select(PERIPH_ID_USB2, FUNCMUX_USB2_ULPI); |
| 94 | |
| 95 | /* ULPI reference clock output */ |
| 96 | pinmux_set_func(PMUX_PINGRP_CDEV2, PMUX_FUNC_PLLP_OUT4); |
| 97 | pinmux_tristate_disable(PMUX_PINGRP_CDEV2); |
| 98 | |
| 99 | /* PHY reset GPIO */ |
| 100 | pinmux_tristate_disable(PMUX_PINGRP_UAC); |
| 101 | |
| 102 | /* VBus GPIO */ |
| 103 | pinmux_tristate_disable(PMUX_PINGRP_DTE); |
| 104 | |
Marcel Ziswiler | c33dd26 | 2015-03-26 02:17:07 +0100 | [diff] [blame] | 105 | /* Reset ASIX using LAN_RESET */ |
| 106 | gpio_request(GPIO_PV4, "LAN_RESET"); |
| 107 | gpio_direction_output(GPIO_PV4, 0); |
| 108 | pinmux_tristate_disable(PMUX_PINGRP_GPV); |
| 109 | udelay(5); |
| 110 | gpio_set_value(GPIO_PV4, 1); |
| 111 | |
| 112 | /* USBH_PEN: USB 1 aka Tegra USB port 3 VBus */ |
Marcel Ziswiler | af72262 | 2015-03-26 01:31:53 +0100 | [diff] [blame] | 113 | pinmux_tristate_disable(PMUX_PINGRP_SPIG); |
| 114 | } |
| 115 | #endif |
Marcel Ziswiler | cbd2b51 | 2015-08-06 00:47:02 +0200 | [diff] [blame] | 116 | |
| 117 | #ifdef CONFIG_VIDEO_TEGRA |
| 118 | /* |
| 119 | * Routine: pin_mux_display |
| 120 | * Description: setup the pin muxes/tristate values for the LCD interface) |
| 121 | */ |
| 122 | void pin_mux_display(void) |
| 123 | { |
| 124 | /* |
| 125 | * Manually untristate BL_ON (PT4 - SODIMM 71) as specified through |
| 126 | * device-tree |
| 127 | */ |
| 128 | pinmux_tristate_disable(PMUX_PINGRP_DTA); |
| 129 | |
| 130 | pinmux_set_func(PMUX_PINGRP_SDC, PMUX_FUNC_PWM); |
| 131 | pinmux_tristate_disable(PMUX_PINGRP_SDC); |
| 132 | } |
| 133 | #endif |