Skip to content

Commit f2f496d

Browse files
dssengcfriedt
authored andcommitted
drivers: reset: rpi_pico: rewrite
Use HAL functions, which also wait for reset to complete. Remove unused register size and active-low DT props. Signed-off-by: Dmitrii Sharshakov <[email protected]>
1 parent 5261e53 commit f2f496d

File tree

4 files changed

+12
-120
lines changed

4 files changed

+12
-120
lines changed

drivers/reset/reset_rpi_pico.c

Lines changed: 11 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,36 @@
11
/*
22
* Copyright (c) 2022 Andrei-Edward Popa
3+
* Copyright (c) 2025 Dmitrii Sharshakov <[email protected]>
34
*
45
* SPDX-License-Identifier: Apache-2.0
56
*/
67

78
#define DT_DRV_COMPAT raspberrypi_pico_reset
89

9-
#include <limits.h>
10-
11-
#include <zephyr/arch/cpu.h>
1210
#include <zephyr/device.h>
1311
#include <zephyr/drivers/reset.h>
1412

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>
2114

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)
2316
{
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));
4018

4119
return 0;
4220
}
4321

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)
4523
{
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);
6225

6326
return 0;
6427
}
6528

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-
11729
static int reset_rpi_line_deassert(const struct device *dev, uint32_t id)
11830
{
119-
return reset_rpi_update(dev, id, 0);
31+
unreset_block_num_wait_blocking(id);
32+
33+
return 0;
12034
}
12135

12236
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)
13145
return reset_rpi_line_deassert(dev, id);
13246
}
13347

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-
14148
static DEVICE_API(reset, reset_rpi_driver_api) = {
14249
.status = reset_rpi_status,
14350
.line_assert = reset_rpi_line_assert,
@@ -146,16 +53,10 @@ static DEVICE_API(reset, reset_rpi_driver_api) = {
14653
};
14754

14855
#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-
}; \
15556
\
156-
DEVICE_DT_INST_DEFINE(idx, reset_rpi_init, \
57+
DEVICE_DT_INST_DEFINE(idx, NULL, \
15758
NULL, NULL, \
158-
&reset_rpi_config_##idx, PRE_KERNEL_1, \
59+
NULL, PRE_KERNEL_1, \
15960
CONFIG_RESET_INIT_PRIORITY, \
16061
&reset_rpi_driver_api);
16162

dts/arm/raspberrypi/rpi_pico/rp2040.dtsi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,6 @@
211211
reset: reset-controller@4000c000 {
212212
compatible = "raspberrypi,pico-reset";
213213
reg = <0x4000c000 DT_SIZE_K(4)>;
214-
reg-width = <4>;
215-
active-low = <0>;
216214
#reset-cells = <1>;
217215
};
218216

dts/arm/raspberrypi/rpi_pico/rp2350.dtsi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,6 @@
207207
reset: reset-controller@40020000 {
208208
compatible = "raspberrypi,pico-reset";
209209
reg = <0x40020000 DT_SIZE_K(4)>;
210-
reg-width = <4>;
211-
active-low = <0>;
212210
#reset-cells = <1>;
213211
};
214212

dts/bindings/reset/raspberrypi,pico-reset.yaml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@ include: [base.yaml, reset-controller.yaml]
1010
properties:
1111
reg:
1212
required: true
13-
reg-width:
14-
type: int
15-
description: The width of the reset registers in bytes. Default is 4 bytes.
16-
active-low:
17-
type: int
18-
description: Set if reset is active low. Default is 0, which means active-high.
13+
1914
"#reset-cells":
2015
const: 1
2116

0 commit comments

Comments
 (0)