1
1
/*
2
2
* Copyright (c) 2022 Yonatan Schachter
3
+ * Copyright (c) 2024 Andrew Featherstone
3
4
*
4
5
* SPDX-License-Identifier: Apache-2.0
5
6
*/
6
7
7
8
#include <string.h>
8
9
#include <zephyr/drivers/hwinfo.h>
9
10
#include <hardware/flash.h>
11
+ #if defined(CONFIG_SOC_SERIES_RP2040 )
10
12
#include <hardware/structs/vreg_and_chip_reset.h>
13
+ #else
14
+ #include <hardware/structs/powman.h>
15
+ #endif
11
16
12
17
#define FLASH_RUID_DATA_BYTES 8
13
18
19
+ #if defined(CONFIG_SOC_SERIES_RP2040 )
14
20
#define HAD_RUN_BIT BIT(VREG_AND_CHIP_RESET_CHIP_RESET_HAD_RUN_LSB)
15
21
#define HAD_PSM_RESTART_BIT BIT(VREG_AND_CHIP_RESET_CHIP_RESET_HAD_PSM_RESTART_LSB)
16
22
#define HAD_POR_BIT BIT(VREG_AND_CHIP_RESET_CHIP_RESET_HAD_POR_LSB)
23
+ #else
24
+ #define HAD_RUN_BIT BIT(POWMAN_CHIP_RESET_HAD_RUN_LOW_LSB)
25
+ #define HAD_PSM_RESTART_BIT BIT(POWMAN_CHIP_RESET_HAD_DP_RESET_REQ_LSB)
26
+ #define HAD_POR_BIT BIT(POWMAN_CHIP_RESET_HAD_POR_LSB)
27
+ #endif
17
28
18
29
ssize_t z_impl_hwinfo_get_device_id (uint8_t * buffer , size_t length )
19
30
{
@@ -41,7 +52,11 @@ ssize_t z_impl_hwinfo_get_device_id(uint8_t *buffer, size_t length)
41
52
int z_impl_hwinfo_get_reset_cause (uint32_t * cause )
42
53
{
43
54
uint32_t flags = 0 ;
55
+ #if defined(CONFIG_SOC_SERIES_RP2040 )
44
56
uint32_t reset_register = vreg_and_chip_reset_hw -> chip_reset ;
57
+ #else
58
+ uint32_t reset_register = powman_hw -> chip_reset ;
59
+ #endif
45
60
46
61
if (reset_register & HAD_POR_BIT ) {
47
62
flags |= RESET_POR ;
@@ -54,6 +69,18 @@ int z_impl_hwinfo_get_reset_cause(uint32_t *cause)
54
69
if (reset_register & HAD_PSM_RESTART_BIT ) {
55
70
flags |= RESET_DEBUG ;
56
71
}
72
+ #if defined(CONFIG_SOC_SERIES_RP2350 )
73
+ if (reset_register & POWMAN_CHIP_RESET_HAD_BOR_BITS ) {
74
+ flags |= RESET_BROWNOUT ;
75
+ }
76
+
77
+ if (reset_register & (POWMAN_CHIP_RESET_HAD_WATCHDOG_RESET_RSM_BITS |
78
+ POWMAN_CHIP_RESET_HAD_WATCHDOG_RESET_SWCORE_BITS |
79
+ POWMAN_CHIP_RESET_HAD_WATCHDOG_RESET_POWMAN_BITS |
80
+ POWMAN_CHIP_RESET_HAD_WATCHDOG_RESET_POWMAN_ASYNC_BITS )) {
81
+ flags |= RESET_WATCHDOG ;
82
+ }
83
+ #endif
57
84
58
85
* cause = flags ;
59
86
return 0 ;
@@ -69,6 +96,9 @@ int z_impl_hwinfo_clear_reset_cause(void)
69
96
int z_impl_hwinfo_get_supported_reset_cause (uint32_t * supported )
70
97
{
71
98
* supported = RESET_PIN | RESET_DEBUG | RESET_POR ;
99
+ #if defined(CONFIG_SOC_SERIES_RP2350 )
100
+ * supported |= RESET_BROWNOUT | RESET_WATCHDOG ;
101
+ #endif
72
102
73
103
return 0 ;
74
104
}
0 commit comments