@@ -77,12 +77,11 @@ static void tqmx86_gpio_set(struct gpio_chip *chip, unsigned int offset,
77
77
int value )
78
78
{
79
79
struct tqmx86_gpio_data * gpio = gpiochip_get_data (chip );
80
- unsigned long flags ;
81
80
82
- raw_spin_lock_irqsave (& gpio -> spinlock , flags );
81
+ guard (raw_spinlock_irqsave )(& gpio -> spinlock );
82
+
83
83
__assign_bit (offset , gpio -> output , value );
84
84
tqmx86_gpio_write (gpio , bitmap_get_value8 (gpio -> output , 0 ), TQMX86_GPIOD );
85
- raw_spin_unlock_irqrestore (& gpio -> spinlock , flags );
86
85
}
87
86
88
87
static int tqmx86_gpio_direction_input (struct gpio_chip * chip ,
@@ -141,12 +140,11 @@ static void tqmx86_gpio_irq_mask(struct irq_data *data)
141
140
{
142
141
struct tqmx86_gpio_data * gpio = gpiochip_get_data (
143
142
irq_data_get_irq_chip_data (data ));
144
- unsigned long flags ;
145
143
146
- raw_spin_lock_irqsave ( & gpio -> spinlock , flags );
147
- gpio -> irq_type [data -> hwirq ] &= ~TQMX86_INT_UNMASKED ;
148
- tqmx86_gpio_irq_config (gpio , data -> hwirq );
149
- raw_spin_unlock_irqrestore ( & gpio -> spinlock , flags );
144
+ scoped_guard ( raw_spinlock_irqsave , & gpio -> spinlock ) {
145
+ gpio -> irq_type [data -> hwirq ] &= ~TQMX86_INT_UNMASKED ;
146
+ tqmx86_gpio_irq_config (gpio , data -> hwirq );
147
+ }
150
148
151
149
gpiochip_disable_irq (& gpio -> chip , irqd_to_hwirq (data ));
152
150
}
@@ -155,22 +153,20 @@ static void tqmx86_gpio_irq_unmask(struct irq_data *data)
155
153
{
156
154
struct tqmx86_gpio_data * gpio = gpiochip_get_data (
157
155
irq_data_get_irq_chip_data (data ));
158
- unsigned long flags ;
159
156
160
157
gpiochip_enable_irq (& gpio -> chip , irqd_to_hwirq (data ));
161
158
162
- raw_spin_lock_irqsave (& gpio -> spinlock , flags );
159
+ guard (raw_spinlock_irqsave )(& gpio -> spinlock );
160
+
163
161
gpio -> irq_type [data -> hwirq ] |= TQMX86_INT_UNMASKED ;
164
162
tqmx86_gpio_irq_config (gpio , data -> hwirq );
165
- raw_spin_unlock_irqrestore (& gpio -> spinlock , flags );
166
163
}
167
164
168
165
static int tqmx86_gpio_irq_set_type (struct irq_data * data , unsigned int type )
169
166
{
170
167
struct tqmx86_gpio_data * gpio = gpiochip_get_data (
171
168
irq_data_get_irq_chip_data (data ));
172
169
unsigned int edge_type = type & IRQF_TRIGGER_MASK ;
173
- unsigned long flags ;
174
170
u8 new_type ;
175
171
176
172
switch (edge_type ) {
@@ -187,11 +183,11 @@ static int tqmx86_gpio_irq_set_type(struct irq_data *data, unsigned int type)
187
183
return - EINVAL ; /* not supported */
188
184
}
189
185
190
- raw_spin_lock_irqsave (& gpio -> spinlock , flags );
186
+ guard (raw_spinlock_irqsave )(& gpio -> spinlock );
187
+
191
188
gpio -> irq_type [data -> hwirq ] &= ~TQMX86_INT_TRIG_MASK ;
192
189
gpio -> irq_type [data -> hwirq ] |= new_type ;
193
190
tqmx86_gpio_irq_config (gpio , data -> hwirq );
194
- raw_spin_unlock_irqrestore (& gpio -> spinlock , flags );
195
191
196
192
return 0 ;
197
193
}
@@ -201,7 +197,7 @@ static void tqmx86_gpio_irq_handler(struct irq_desc *desc)
201
197
struct gpio_chip * chip = irq_desc_get_handler_data (desc );
202
198
struct tqmx86_gpio_data * gpio = gpiochip_get_data (chip );
203
199
struct irq_chip * irq_chip = irq_desc_get_chip (desc );
204
- unsigned long irq_bits , flags ;
200
+ unsigned long irq_bits ;
205
201
int i , hwirq ;
206
202
u8 irq_status ;
207
203
@@ -212,34 +208,38 @@ static void tqmx86_gpio_irq_handler(struct irq_desc *desc)
212
208
213
209
irq_bits = irq_status ;
214
210
215
- raw_spin_lock_irqsave (& gpio -> spinlock , flags );
216
- for_each_set_bit (i , & irq_bits , TQMX86_NGPI ) {
217
- hwirq = i + TQMX86_NGPO ;
218
-
219
- /*
220
- * Edge-both triggers are implemented by flipping the edge
221
- * trigger after each interrupt, as the controller only supports
222
- * either rising or falling edge triggers, but not both.
223
- *
224
- * Internally, the TQMx86 GPIO controller has separate status
225
- * registers for rising and falling edge interrupts. GPIIC
226
- * configures which bits from which register are visible in the
227
- * interrupt status register GPIIS and defines what triggers the
228
- * parent IRQ line. Writing to GPIIS always clears both rising
229
- * and falling interrupt flags internally, regardless of the
230
- * currently configured trigger.
231
- *
232
- * In consequence, we can cleanly implement the edge-both
233
- * trigger in software by first clearing the interrupt and then
234
- * setting the new trigger based on the current GPIO input in
235
- * tqmx86_gpio_irq_config() - even if an edge arrives between
236
- * reading the input and setting the trigger, we will have a new
237
- * interrupt pending.
238
- */
239
- if ((gpio -> irq_type [hwirq ] & TQMX86_INT_TRIG_MASK ) == TQMX86_INT_TRIG_BOTH )
240
- tqmx86_gpio_irq_config (gpio , hwirq );
211
+ scoped_guard (raw_spinlock_irqsave , & gpio -> spinlock ) {
212
+ for_each_set_bit (i , & irq_bits , TQMX86_NGPI ) {
213
+ hwirq = i + TQMX86_NGPO ;
214
+
215
+ /*
216
+ * Edge-both triggers are implemented by flipping the
217
+ * edge trigger after each interrupt, as the controller
218
+ * only supports either rising or falling edge triggers,
219
+ * but not both.
220
+ *
221
+ * Internally, the TQMx86 GPIO controller has separate
222
+ * status registers for rising and falling edge
223
+ * interrupts. GPIIC configures which bits from which
224
+ * register are visible in the interrupt status register
225
+ * GPIIS and defines what triggers the parent IRQ line.
226
+ * Writing to GPIIS always clears both rising and
227
+ * falling interrupt flags internally, regardless of the
228
+ * currently configured trigger.
229
+ *
230
+ * In consequence, we can cleanly implement the
231
+ * edge-both trigger in software by first clearing the
232
+ * interrupt and then setting the new trigger based on
233
+ * the current GPIO input in tqmx86_gpio_irq_config() -
234
+ * even if an edge arrives between reading the input and
235
+ * setting the trigger, we will have a new interrupt
236
+ * pending.
237
+ */
238
+ if ((gpio -> irq_type [hwirq ] & TQMX86_INT_TRIG_MASK ) ==
239
+ TQMX86_INT_TRIG_BOTH )
240
+ tqmx86_gpio_irq_config (gpio , hwirq );
241
+ }
241
242
}
242
- raw_spin_unlock_irqrestore (& gpio -> spinlock , flags );
243
243
244
244
for_each_set_bit (i , & irq_bits , TQMX86_NGPI )
245
245
generic_handle_domain_irq (gpio -> chip .irq .domain ,
0 commit comments