Svyatoslav Ryhel | 4c5fe37 | 2023-06-30 10:29:06 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * T30 HTC Endeavoru SPL stage configuration |
| 4 | * |
| 5 | * (C) Copyright 2010-2013 |
| 6 | * NVIDIA Corporation <www.nvidia.com> |
| 7 | * |
| 8 | * (C) Copyright 2022 |
| 9 | * Svyatoslav Ryhel <clamor95@gmail.com> |
| 10 | */ |
| 11 | |
Svyatoslav Ryhel | 7be8031 | 2024-01-05 17:35:26 +0200 | [diff] [blame] | 12 | #include <asm/io.h> |
| 13 | #include <asm/gpio.h> |
| 14 | #include <asm/arch/pinmux.h> |
Svyatoslav Ryhel | 8c8fb85 | 2023-08-26 18:35:35 +0300 | [diff] [blame] | 15 | #include <asm/arch/tegra.h> |
Svyatoslav Ryhel | 7be8031 | 2024-01-05 17:35:26 +0200 | [diff] [blame] | 16 | #include <asm/arch-tegra/board.h> |
| 17 | #include <asm/arch-tegra/pmc.h> |
Svyatoslav Ryhel | 4c5fe37 | 2023-06-30 10:29:06 +0300 | [diff] [blame] | 18 | #include <asm/arch-tegra/tegra_i2c.h> |
| 19 | #include <linux/delay.h> |
| 20 | |
| 21 | /* |
| 22 | * Endeavoru uses TPS80032 PMIC with SMPS1 and SMPS2 in strandard |
| 23 | * mode with zero offset. |
| 24 | */ |
| 25 | |
| 26 | #define TPS80032_DVS_I2C_ADDR (0x12 << 1) |
| 27 | #define TPS80032_SMPS1_CFG_VOLTAGE_REG 0x56 |
| 28 | #define TPS80032_SMPS2_CFG_VOLTAGE_REG 0x5C |
| 29 | #define TPS80032_SMPS1_CFG_VOLTAGE_DATA (0x2100 | TPS80032_SMPS1_CFG_VOLTAGE_REG) |
| 30 | #define TPS80032_SMPS2_CFG_VOLTAGE_DATA (0x3000 | TPS80032_SMPS2_CFG_VOLTAGE_REG) |
| 31 | |
| 32 | #define TPS80032_CTL1_I2C_ADDR (0x48 << 1) |
| 33 | #define TPS80032_SMPS1_CFG_STATE_REG 0x54 |
| 34 | #define TPS80032_SMPS2_CFG_STATE_REG 0x5A |
| 35 | #define TPS80032_SMPS1_CFG_STATE_DATA (0x0100 | TPS80032_SMPS1_CFG_STATE_REG) |
| 36 | #define TPS80032_SMPS2_CFG_STATE_DATA (0x0100 | TPS80032_SMPS2_CFG_STATE_REG) |
| 37 | |
Svyatoslav Ryhel | 7be8031 | 2024-01-05 17:35:26 +0200 | [diff] [blame] | 38 | #define TEGRA_GPIO_PS0 144 |
| 39 | |
Svyatoslav Ryhel | 4c5fe37 | 2023-06-30 10:29:06 +0300 | [diff] [blame] | 40 | void pmic_enable_cpu_vdd(void) |
| 41 | { |
| 42 | /* Set VDD_CORE to 1.200V. */ |
| 43 | tegra_i2c_ll_write(TPS80032_DVS_I2C_ADDR, TPS80032_SMPS2_CFG_VOLTAGE_DATA); |
| 44 | udelay(1000); |
| 45 | tegra_i2c_ll_write(TPS80032_CTL1_I2C_ADDR, TPS80032_SMPS2_CFG_STATE_DATA); |
| 46 | |
| 47 | udelay(1000); |
| 48 | |
| 49 | /* Bring up VDD_CPU to 1.0125V. */ |
| 50 | tegra_i2c_ll_write(TPS80032_DVS_I2C_ADDR, TPS80032_SMPS1_CFG_VOLTAGE_DATA); |
| 51 | udelay(1000); |
| 52 | tegra_i2c_ll_write(TPS80032_CTL1_I2C_ADDR, TPS80032_SMPS1_CFG_STATE_DATA); |
| 53 | udelay(10 * 1000); |
| 54 | } |
Svyatoslav Ryhel | 7be8031 | 2024-01-05 17:35:26 +0200 | [diff] [blame] | 55 | |
| 56 | /* |
| 57 | * Unlike all other supported Tegra devices and most known Tegra devices, the |
| 58 | * HTC One X has no hardware way to enter APX/RCM mode, which may lead to a |
| 59 | * dangerous situation when, if BCT is set correctly and the bootloader is |
| 60 | * faulty, the device will hang in a permanent brick state. Exiting from this |
| 61 | * state can be done only by disassembling the device and shortening testpad |
| 62 | * to the ground. |
| 63 | * |
| 64 | * To prevent this or to minimize the probability of such an accident, it was |
| 65 | * proposed to add the RCM rebooting hook as early into SPL as possible since |
| 66 | * SPL is much more robust and has minimal changes that can break bootflow. |
| 67 | * |
| 68 | * gpio_early_init_uart() function was chosen as it is the earliest function |
| 69 | * exposed for setup by the device. Hook performs a check for volume up |
| 70 | * button state and triggers RCM if it is pressed. |
| 71 | */ |
| 72 | void gpio_early_init_uart(void) |
| 73 | { |
| 74 | struct gpio_ctlr *ctlr = (struct gpio_ctlr *)NV_PA_GPIO_BASE; |
| 75 | struct gpio_ctlr_bank *bank = &ctlr->gpio_bank[GPIO_BANK(TEGRA_GPIO_PS0)]; |
| 76 | u32 value; |
| 77 | |
| 78 | /* Configure pinmux */ |
| 79 | pinmux_set_func(PMUX_PINGRP_KB_ROW8_PS0, PMUX_FUNC_KBC); |
| 80 | pinmux_set_pullupdown(PMUX_PINGRP_KB_ROW8_PS0, PMUX_PULL_UP); |
| 81 | pinmux_tristate_disable(PMUX_PINGRP_KB_ROW8_PS0); |
| 82 | pinmux_set_io(PMUX_PINGRP_KB_ROW8_PS0, PMUX_PIN_INPUT); |
| 83 | |
| 84 | /* Configure GPIO direction as input. */ |
| 85 | value = readl(&bank->gpio_dir_out[GPIO_PORT(TEGRA_GPIO_PS0)]); |
| 86 | value &= ~(1 << GPIO_BIT(TEGRA_GPIO_PS0)); |
| 87 | writel(value, &bank->gpio_dir_out[GPIO_PORT(TEGRA_GPIO_PS0)]); |
| 88 | |
| 89 | /* Enable the pin as a GPIO */ |
| 90 | value = readl(&bank->gpio_config[GPIO_PORT(TEGRA_GPIO_PS0)]); |
| 91 | value |= 1 << GPIO_BIT(TEGRA_GPIO_PS0); |
| 92 | writel(value, &bank->gpio_config[GPIO_PORT(TEGRA_GPIO_PS0)]); |
| 93 | |
| 94 | /* Get GPIO value */ |
| 95 | value = readl(&bank->gpio_in[GPIO_PORT(TEGRA_GPIO_PS0)]); |
| 96 | value = (value >> GPIO_BIT(TEGRA_GPIO_PS0)) & 1; |
| 97 | |
| 98 | /* Enter RCM if button is pressed */ |
| 99 | if (!value) { |
| 100 | tegra_pmc_writel(2, PMC_SCRATCH0); |
| 101 | tegra_pmc_writel(PMC_CNTRL_MAIN_RST, PMC_CNTRL); |
| 102 | } |
| 103 | } |