blob: bfebfe5136dd55af3b12a4310647832c2ddc38c2 [file] [log] [blame]
Quentin Schulzc925be72023-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 Schulz6acdd632023-11-03 10:28:12 +01006#include <asm/gpio.h>
Quentin Schulz6acdd632023-11-03 10:28:12 +01007#include <linux/delay.h>
Quentin Schulz56bb09f2024-01-17 18:59:10 +01008#include "../common/common.h"
Quentin Schulzc925be72023-01-09 11:36:45 +01009
Quentin Schulz80cc4be2024-03-11 13:01:51 +010010int rockchip_early_misc_init_r(void)
Quentin Schulzc925be72023-01-09 11:36:45 +010011{
Quentin Schulzc925be72023-01-09 11:36:45 +010012 setup_boottargets();
13
14 return 0;
15}
Quentin Schulz6acdd632023-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
61 ret = gpio_direction_output(STM32_RST, 1);
62 if (ret) {
63 debug("Failed to configure STM32_RST as output high\n");
64 return;
65 }
66}