Skip to content

Commit 3c8ac10

Browse files
henrikbrixandersenkartben
authored andcommitted
drivers: gpio: neorv32: use spinlock instead of irq_lock()
Switch from using irq_lock()/irq_unlock() to using a k_spinlock. Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
1 parent 437c16f commit 3c8ac10

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

drivers/gpio/gpio_neorv32.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <zephyr/drivers/gpio.h>
1212
#include <zephyr/drivers/syscon.h>
1313
#include <zephyr/irq.h>
14+
#include <zephyr/spinlock.h>
1415
#include <zephyr/sys/sys_io.h>
1516
#include <zephyr/logging/log.h>
1617

@@ -39,6 +40,7 @@ struct neorv32_gpio_data {
3940
struct gpio_driver_data common;
4041
/* Shadow register for output */
4142
uint32_t output;
43+
struct k_spinlock lock;
4244
};
4345

4446
static inline uint32_t neorv32_gpio_read(const struct device *dev)
@@ -60,7 +62,7 @@ static int neorv32_gpio_pin_configure(const struct device *dev, gpio_pin_t pin,
6062
{
6163
const struct neorv32_gpio_config *config = dev->config;
6264
struct neorv32_gpio_data *data = dev->data;
63-
unsigned int key;
65+
k_spinlock_key_t key;
6466

6567
if (!(BIT(pin) & config->common.port_pin_mask)) {
6668
return -EINVAL;
@@ -75,7 +77,7 @@ static int neorv32_gpio_pin_configure(const struct device *dev, gpio_pin_t pin,
7577
}
7678

7779
if ((flags & GPIO_OUTPUT) != 0) {
78-
key = irq_lock();
80+
key = k_spin_lock(&data->lock);
7981

8082
if ((flags & GPIO_OUTPUT_INIT_HIGH) != 0) {
8183
data->output |= BIT(pin);
@@ -84,7 +86,7 @@ static int neorv32_gpio_pin_configure(const struct device *dev, gpio_pin_t pin,
8486
}
8587

8688
neorv32_gpio_write(dev, data->output);
87-
irq_unlock(key);
89+
k_spin_unlock(&data->lock, key);
8890
}
8991

9092
return 0;
@@ -102,12 +104,12 @@ static int neorv32_gpio_port_set_masked_raw(const struct device *dev,
102104
gpio_port_value_t value)
103105
{
104106
struct neorv32_gpio_data *data = dev->data;
105-
unsigned int key;
107+
k_spinlock_key_t key;
106108

107-
key = irq_lock();
109+
key = k_spin_lock(&data->lock);
108110
data->output = (data->output & ~mask) | (mask & value);
109111
neorv32_gpio_write(dev, data->output);
110-
irq_unlock(key);
112+
k_spin_unlock(&data->lock, key);
111113

112114
return 0;
113115
}
@@ -116,12 +118,12 @@ static int neorv32_gpio_port_set_bits_raw(const struct device *dev,
116118
gpio_port_pins_t pins)
117119
{
118120
struct neorv32_gpio_data *data = dev->data;
119-
unsigned int key;
121+
k_spinlock_key_t key;
120122

121-
key = irq_lock();
123+
key = k_spin_lock(&data->lock);
122124
data->output |= pins;
123125
neorv32_gpio_write(dev, data->output);
124-
irq_unlock(key);
126+
k_spin_unlock(&data->lock, key);
125127

126128
return 0;
127129
}
@@ -130,12 +132,12 @@ static int neorv32_gpio_port_clear_bits_raw(const struct device *dev,
130132
gpio_port_pins_t pins)
131133
{
132134
struct neorv32_gpio_data *data = dev->data;
133-
unsigned int key;
135+
k_spinlock_key_t key;
134136

135-
key = irq_lock();
137+
key = k_spin_lock(&data->lock);
136138
data->output &= ~pins;
137139
neorv32_gpio_write(dev, data->output);
138-
irq_unlock(key);
140+
k_spin_unlock(&data->lock, key);
139141

140142
return 0;
141143
}
@@ -144,12 +146,12 @@ static int neorv32_gpio_port_toggle_bits(const struct device *dev,
144146
gpio_port_pins_t pins)
145147
{
146148
struct neorv32_gpio_data *data = dev->data;
147-
unsigned int key;
149+
k_spinlock_key_t key;
148150

149-
key = irq_lock();
151+
key = k_spin_lock(&data->lock);
150152
data->output ^= pins;
151153
neorv32_gpio_write(dev, data->output);
152-
irq_unlock(key);
154+
k_spin_unlock(&data->lock, key);
153155

154156
return 0;
155157
}

0 commit comments

Comments
 (0)