1
1
/*
2
2
* Copyright (c) 2022 Andrei-Edward Popa
3
+ * Copyright (c) 2025 Dmitrii Sharshakov <[email protected] >
3
4
*
4
5
* SPDX-License-Identifier: Apache-2.0
5
6
*/
6
7
7
8
#define DT_DRV_COMPAT raspberrypi_pico_reset
8
9
9
- #include <limits.h>
10
-
11
- #include <zephyr/arch/cpu.h>
12
10
#include <zephyr/device.h>
13
11
#include <zephyr/drivers/reset.h>
14
12
15
- struct reset_rpi_config {
16
- DEVICE_MMIO_ROM ;
17
- uint8_t reg_width ;
18
- uint8_t active_low ;
19
- uintptr_t base_address ;
20
- };
13
+ #include <hardware/resets.h>
21
14
22
- static int reset_rpi_read_register (const struct device * dev , uint16_t offset , uint32_t * value )
15
+ static int reset_rpi_status (const struct device * dev , uint32_t id , uint8_t * status )
23
16
{
24
- const struct reset_rpi_config * config = dev -> config ;
25
- uint32_t base_address = config -> base_address ;
26
-
27
- switch (config -> reg_width ) {
28
- case 1 :
29
- * value = sys_read8 (base_address + offset );
30
- break ;
31
- case 2 :
32
- * value = sys_read16 (base_address + offset );
33
- break ;
34
- case 4 :
35
- * value = sys_read32 (base_address + offset );
36
- break ;
37
- default :
38
- return - EINVAL ;
39
- }
17
+ * status = !!(resets_hw -> reset & (1u << id ));
40
18
41
19
return 0 ;
42
20
}
43
21
44
- static int reset_rpi_write_register (const struct device * dev , uint16_t offset , uint32_t value )
22
+ static int reset_rpi_line_assert (const struct device * dev , uint32_t id )
45
23
{
46
- const struct reset_rpi_config * config = dev -> config ;
47
- uint32_t base_address = config -> base_address ;
48
-
49
- switch (config -> reg_width ) {
50
- case 1 :
51
- sys_write8 (value , base_address + offset );
52
- break ;
53
- case 2 :
54
- sys_write16 (value , base_address + offset );
55
- break ;
56
- case 4 :
57
- sys_write32 (value , base_address + offset );
58
- break ;
59
- default :
60
- return - EINVAL ;
61
- }
24
+ reset_block_num (id );
62
25
63
26
return 0 ;
64
27
}
65
28
66
- static int reset_rpi_status (const struct device * dev , uint32_t id , uint8_t * status )
67
- {
68
- const struct reset_rpi_config * config = dev -> config ;
69
- uint16_t offset ;
70
- uint32_t value ;
71
- uint8_t regbit ;
72
- int ret ;
73
-
74
- offset = id / (config -> reg_width * CHAR_BIT );
75
- regbit = id % (config -> reg_width * CHAR_BIT );
76
-
77
- ret = reset_rpi_read_register (dev , offset , & value );
78
- if (ret ) {
79
- return ret ;
80
- }
81
-
82
- * status = !(value & BIT (regbit )) ^ !config -> active_low ;
83
-
84
- return ret ;
85
- }
86
-
87
- static int reset_rpi_update (const struct device * dev , uint32_t id , uint8_t assert )
88
- {
89
- const struct reset_rpi_config * config = dev -> config ;
90
- uint16_t offset ;
91
- uint32_t value ;
92
- uint8_t regbit ;
93
- int ret ;
94
-
95
- offset = id / (config -> reg_width * CHAR_BIT );
96
- regbit = id % (config -> reg_width * CHAR_BIT );
97
-
98
- ret = reset_rpi_read_register (dev , offset , & value );
99
- if (ret ) {
100
- return ret ;
101
- }
102
-
103
- if (assert ^ config -> active_low ) {
104
- value |= BIT (regbit );
105
- } else {
106
- value &= ~BIT (regbit );
107
- }
108
-
109
- return reset_rpi_write_register (dev , offset , value );
110
- }
111
-
112
- static int reset_rpi_line_assert (const struct device * dev , uint32_t id )
113
- {
114
- return reset_rpi_update (dev , id , 1 );
115
- }
116
-
117
29
static int reset_rpi_line_deassert (const struct device * dev , uint32_t id )
118
30
{
119
- return reset_rpi_update (dev , id , 0 );
31
+ unreset_block_num_wait_blocking (id );
32
+
33
+ return 0 ;
120
34
}
121
35
122
36
static int reset_rpi_line_toggle (const struct device * dev , uint32_t id )
@@ -131,13 +45,6 @@ static int reset_rpi_line_toggle(const struct device *dev, uint32_t id)
131
45
return reset_rpi_line_deassert (dev , id );
132
46
}
133
47
134
- static int reset_rpi_init (const struct device * dev )
135
- {
136
- DEVICE_MMIO_MAP (dev , K_MEM_CACHE_NONE );
137
-
138
- return 0 ;
139
- }
140
-
141
48
static DEVICE_API (reset , reset_rpi_driver_api ) = {
142
49
.status = reset_rpi_status ,
143
50
.line_assert = reset_rpi_line_assert ,
@@ -146,16 +53,10 @@ static DEVICE_API(reset, reset_rpi_driver_api) = {
146
53
};
147
54
148
55
#define RPI_RESET_INIT (idx ) \
149
- static const struct reset_rpi_config reset_rpi_config_##idx = { \
150
- DEVICE_MMIO_ROM_INIT(DT_DRV_INST(idx)), \
151
- .reg_width = DT_INST_PROP_OR(idx, reg_width, 4), \
152
- .active_low = DT_INST_PROP_OR(idx, active_low, 0), \
153
- .base_address = DT_INST_REG_ADDR(idx), \
154
- }; \
155
56
\
156
- DEVICE_DT_INST_DEFINE(idx, reset_rpi_init , \
57
+ DEVICE_DT_INST_DEFINE(idx, NULL , \
157
58
NULL, NULL, \
158
- &reset_rpi_config_##idx , PRE_KERNEL_1, \
59
+ NULL , PRE_KERNEL_1, \
159
60
CONFIG_RESET_INIT_PRIORITY, \
160
61
&reset_rpi_driver_api);
161
62
0 commit comments