Svyatoslav Ryhel | 1ea1b8a | 2023-12-03 19:34:49 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * T20 Motorola Atrix 4G and Droid X2 SPL stage configuration |
| 4 | * |
| 5 | * (C) Copyright 2025 |
| 6 | * Svyatoslav Ryhel <clamor95@gmail.com> |
| 7 | */ |
| 8 | |
| 9 | #include <asm/gpio.h> |
| 10 | #include <asm/arch/pinmux.h> |
| 11 | #include <asm/arch/tegra.h> |
| 12 | #include <asm/arch-tegra/pmc.h> |
| 13 | #include <spl_gpio.h> |
| 14 | #include <linux/delay.h> |
| 15 | |
| 16 | /* |
| 17 | * Unlike all other supported Tegra devices and most known Tegra devices, the |
| 18 | * both Atrix 4G and Droid X2 have no hardware way to enter APX/RCM mode, which |
| 19 | * may lead to a dangerous situation when, if BCT is set correctly and the |
| 20 | * bootloader is faulty, the device will hang in a permanent brick state. |
| 21 | * Exiting from this state can be done only by disassembling the device and |
| 22 | * shortening testpad to the ground. |
| 23 | * |
| 24 | * To prevent this or to minimize the probability of such an accident, it was |
| 25 | * proposed to add the RCM rebooting hook as early into SPL as possible since |
| 26 | * SPL is much more robust and has minimal changes that can break bootflow. |
| 27 | * |
| 28 | * gpio_early_init_uart() function was chosen as it is the earliest function |
| 29 | * exposed for setup by the device. Hook performs a check for volume up |
| 30 | * button state and triggers RCM if it is pressed. |
| 31 | */ |
| 32 | void gpio_early_init_uart(void) |
| 33 | { |
| 34 | int value; |
| 35 | |
| 36 | /* Configure pinmux for PR0 */ |
| 37 | pinmux_set_func(PMUX_PINGRP_KBCA, PMUX_FUNC_KBC); |
| 38 | pinmux_set_pullupdown(PMUX_PINGRP_KBCA, PMUX_PULL_UP); |
| 39 | pinmux_tristate_disable(PMUX_PINGRP_KBCA); |
| 40 | |
| 41 | /* Configure pinmux for PQ0 */ |
| 42 | pinmux_set_func(PMUX_PINGRP_KBCC, PMUX_FUNC_KBC); |
| 43 | pinmux_set_pullupdown(PMUX_PINGRP_KBCC, PMUX_PULL_UP); |
| 44 | pinmux_tristate_disable(PMUX_PINGRP_KBCC); |
| 45 | |
| 46 | /* Hog column 0 (PQ0) low - active */ |
| 47 | spl_gpio_output(NULL, TEGRA_GPIO(Q, 0), 0); |
| 48 | udelay(500); |
| 49 | |
| 50 | spl_gpio_input(NULL, TEGRA_GPIO(R, 0)); |
| 51 | value = spl_gpio_get_value(NULL, TEGRA_GPIO(R, 0)); |
| 52 | |
| 53 | /* Enter RCM if button is pressed */ |
| 54 | if (!value) { |
| 55 | tegra_pmc_writel(2, PMC_SCRATCH0); |
| 56 | tegra_pmc_writel(PMC_CNTRL_MAIN_RST, PMC_CNTRL); |
| 57 | } |
| 58 | } |