blob: c48de7345f79e3189c77bb670e5ff5421adf6235 [file] [log] [blame]
Quentin Schulz00a6f602023-01-09 11:36:45 +01001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2022 Theobroma Systems Design und Consulting GmbH
4 */
5
Quentin Schulz47d3e0b2023-11-03 10:28:12 +01006#include <asm/gpio.h>
Quentin Schulz47d3e0b2023-11-03 10:28:12 +01007#include <linux/delay.h>
Quentin Schulz1e1a92b2024-01-17 18:59:10 +01008#include "../common/common.h"
Quentin Schulz00a6f602023-01-09 11:36:45 +01009
Quentin Schulz3d9a0582024-03-11 13:01:51 +010010int rockchip_early_misc_init_r(void)
Quentin Schulz00a6f602023-01-09 11:36:45 +010011{
Quentin Schulz00a6f602023-01-09 11:36:45 +010012 setup_boottargets();
13
14 return 0;
15}
Quentin Schulz47d3e0b2023-11-03 10:28:12 +010016
17#define STM32_RST 100 /* GPIO3_A4 */
18#define STM32_BOOT 101 /* GPIO3_A5 */
19
20void 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 Schulzfd3fa502024-02-09 14:18:09 +010061 ret = gpio_direction_input(STM32_RST);
Quentin Schulz47d3e0b2023-11-03 10:28:12 +010062 if (ret) {
Quentin Schulzfd3fa502024-02-09 14:18:09 +010063 debug("Failed to configure STM32_RST as input\n");
Quentin Schulz47d3e0b2023-11-03 10:28:12 +010064 return;
65 }
66}