@@ -77,12 +77,11 @@ static void tqmx86_gpio_set(struct gpio_chip *chip, unsigned int offset,
7777 int value )
7878{
7979 struct tqmx86_gpio_data * gpio = gpiochip_get_data (chip );
80- unsigned long flags ;
8180
82- raw_spin_lock_irqsave (& gpio -> spinlock , flags );
81+ guard (raw_spinlock_irqsave )(& gpio -> spinlock );
82+
8383 __assign_bit (offset , gpio -> output , value );
8484 tqmx86_gpio_write (gpio , bitmap_get_value8 (gpio -> output , 0 ), TQMX86_GPIOD );
85- raw_spin_unlock_irqrestore (& gpio -> spinlock , flags );
8685}
8786
8887static int tqmx86_gpio_direction_input (struct gpio_chip * chip ,
@@ -141,12 +140,11 @@ static void tqmx86_gpio_irq_mask(struct irq_data *data)
141140{
142141 struct tqmx86_gpio_data * gpio = gpiochip_get_data (
143142 irq_data_get_irq_chip_data (data ));
144- unsigned long flags ;
145143
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+ }
150148
151149 gpiochip_disable_irq (& gpio -> chip , irqd_to_hwirq (data ));
152150}
@@ -155,22 +153,20 @@ static void tqmx86_gpio_irq_unmask(struct irq_data *data)
155153{
156154 struct tqmx86_gpio_data * gpio = gpiochip_get_data (
157155 irq_data_get_irq_chip_data (data ));
158- unsigned long flags ;
159156
160157 gpiochip_enable_irq (& gpio -> chip , irqd_to_hwirq (data ));
161158
162- raw_spin_lock_irqsave (& gpio -> spinlock , flags );
159+ guard (raw_spinlock_irqsave )(& gpio -> spinlock );
160+
163161 gpio -> irq_type [data -> hwirq ] |= TQMX86_INT_UNMASKED ;
164162 tqmx86_gpio_irq_config (gpio , data -> hwirq );
165- raw_spin_unlock_irqrestore (& gpio -> spinlock , flags );
166163}
167164
168165static int tqmx86_gpio_irq_set_type (struct irq_data * data , unsigned int type )
169166{
170167 struct tqmx86_gpio_data * gpio = gpiochip_get_data (
171168 irq_data_get_irq_chip_data (data ));
172169 unsigned int edge_type = type & IRQF_TRIGGER_MASK ;
173- unsigned long flags ;
174170 u8 new_type ;
175171
176172 switch (edge_type ) {
@@ -187,11 +183,11 @@ static int tqmx86_gpio_irq_set_type(struct irq_data *data, unsigned int type)
187183 return - EINVAL ; /* not supported */
188184 }
189185
190- raw_spin_lock_irqsave (& gpio -> spinlock , flags );
186+ guard (raw_spinlock_irqsave )(& gpio -> spinlock );
187+
191188 gpio -> irq_type [data -> hwirq ] &= ~TQMX86_INT_TRIG_MASK ;
192189 gpio -> irq_type [data -> hwirq ] |= new_type ;
193190 tqmx86_gpio_irq_config (gpio , data -> hwirq );
194- raw_spin_unlock_irqrestore (& gpio -> spinlock , flags );
195191
196192 return 0 ;
197193}
@@ -201,7 +197,7 @@ static void tqmx86_gpio_irq_handler(struct irq_desc *desc)
201197 struct gpio_chip * chip = irq_desc_get_handler_data (desc );
202198 struct tqmx86_gpio_data * gpio = gpiochip_get_data (chip );
203199 struct irq_chip * irq_chip = irq_desc_get_chip (desc );
204- unsigned long irq_bits , flags ;
200+ unsigned long irq_bits ;
205201 int i , hwirq ;
206202 u8 irq_status ;
207203
@@ -212,34 +208,38 @@ static void tqmx86_gpio_irq_handler(struct irq_desc *desc)
212208
213209 irq_bits = irq_status ;
214210
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+ }
241242 }
242- raw_spin_unlock_irqrestore (& gpio -> spinlock , flags );
243243
244244 for_each_set_bit (i , & irq_bits , TQMX86_NGPI )
245245 generic_handle_domain_irq (gpio -> chip .irq .domain ,
0 commit comments