Quentin Schulz | 00a6f60 | 2023-01-09 11:36:45 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) Copyright 2022 Theobroma Systems Design und Consulting GmbH |
| 4 | */ |
| 5 | |
Quentin Schulz | 47d3e0b | 2023-11-03 10:28:12 +0100 | [diff] [blame] | 6 | #include <asm/gpio.h> |
Quentin Schulz | 47d3e0b | 2023-11-03 10:28:12 +0100 | [diff] [blame] | 7 | #include <linux/delay.h> |
Quentin Schulz | 1e1a92b | 2024-01-17 18:59:10 +0100 | [diff] [blame] | 8 | #include "../common/common.h" |
Quentin Schulz | 00a6f60 | 2023-01-09 11:36:45 +0100 | [diff] [blame] | 9 | |
Quentin Schulz | 3d9a058 | 2024-03-11 13:01:51 +0100 | [diff] [blame] | 10 | int rockchip_early_misc_init_r(void) |
Quentin Schulz | 00a6f60 | 2023-01-09 11:36:45 +0100 | [diff] [blame] | 11 | { |
Quentin Schulz | 00a6f60 | 2023-01-09 11:36:45 +0100 | [diff] [blame] | 12 | setup_boottargets(); |
| 13 | |
| 14 | return 0; |
| 15 | } |
Quentin Schulz | 47d3e0b | 2023-11-03 10:28:12 +0100 | [diff] [blame] | 16 | |
| 17 | #define STM32_RST 100 /* GPIO3_A4 */ |
| 18 | #define STM32_BOOT 101 /* GPIO3_A5 */ |
| 19 | |
| 20 | void spl_board_init(void) |
| 21 | { |
| 22 | /* |
| 23 | * Glitches on STM32_BOOT and STM32_RST lines during poweroff or power |
| 24 | * on may put the STM32 companion microcontroller into DFU mode, let's |
| 25 | * always reset it into normal mode instead. |
| 26 | * Toggling the STM32_RST line is safe to do with the ATtiny companion |
| 27 | * microcontroller variant because it will not trigger an MCU reset |
| 28 | * since only a UPDI reset command will. Since a UPDI reset is difficult |
| 29 | * to mistakenly trigger, glitches to the lines are theoretically also |
| 30 | * incapable of triggering an actual ATtiny reset. |
| 31 | */ |
| 32 | int ret; |
| 33 | |
| 34 | ret = gpio_request(STM32_RST, "STM32_RST"); |
| 35 | if (ret) { |
| 36 | debug("Failed to request STM32_RST\n"); |
| 37 | return; |
| 38 | } |
| 39 | |
| 40 | ret = gpio_request(STM32_BOOT, "STM32_BOOT"); |
| 41 | if (ret) { |
| 42 | debug("Failed to request STM32_BOOT\n"); |
| 43 | return; |
| 44 | } |
| 45 | |
| 46 | /* Rely on HW pull-down for inactive level */ |
| 47 | ret = gpio_direction_input(STM32_BOOT); |
| 48 | if (ret) { |
| 49 | debug("Failed to configure STM32_BOOT as input\n"); |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | ret = gpio_direction_output(STM32_RST, 0); |
| 54 | if (ret) { |
| 55 | debug("Failed to configure STM32_RST as output low\n"); |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | mdelay(1); |
| 60 | |
Quentin Schulz | fd3fa50 | 2024-02-09 14:18:09 +0100 | [diff] [blame] | 61 | ret = gpio_direction_input(STM32_RST); |
Quentin Schulz | 47d3e0b | 2023-11-03 10:28:12 +0100 | [diff] [blame] | 62 | if (ret) { |
Quentin Schulz | fd3fa50 | 2024-02-09 14:18:09 +0100 | [diff] [blame] | 63 | debug("Failed to configure STM32_RST as input\n"); |
Quentin Schulz | 47d3e0b | 2023-11-03 10:28:12 +0100 | [diff] [blame] | 64 | return; |
| 65 | } |
| 66 | } |