66 */
77
88#include <linux/bitfield.h>
9+ #include <linux/cleanup.h>
910#include <linux/clk.h>
1011#include <linux/gpio/driver.h>
1112#include <linux/hashtable.h>
@@ -170,17 +171,14 @@ static int aspeed_sgpio_get(struct gpio_chip *gc, unsigned int offset)
170171{
171172 struct aspeed_sgpio * gpio = gpiochip_get_data (gc );
172173 const struct aspeed_sgpio_bank * bank = to_bank (offset );
173- unsigned long flags ;
174174 enum aspeed_sgpio_reg reg ;
175175 int rc = 0 ;
176176
177- raw_spin_lock_irqsave ( & gpio -> lock , flags );
177+ guard ( raw_spinlock_irqsave )( & gpio -> lock );
178178
179179 reg = aspeed_sgpio_is_input (offset ) ? reg_val : reg_rdata ;
180180 rc = !!(ioread32 (bank_reg (gpio , bank , reg )) & GPIO_BIT (offset ));
181181
182- raw_spin_unlock_irqrestore (& gpio -> lock , flags );
183-
184182 return rc ;
185183}
186184
@@ -214,13 +212,10 @@ static int sgpio_set_value(struct gpio_chip *gc, unsigned int offset, int val)
214212static void aspeed_sgpio_set (struct gpio_chip * gc , unsigned int offset , int val )
215213{
216214 struct aspeed_sgpio * gpio = gpiochip_get_data (gc );
217- unsigned long flags ;
218215
219- raw_spin_lock_irqsave ( & gpio -> lock , flags );
216+ guard ( raw_spinlock_irqsave )( & gpio -> lock );
220217
221218 sgpio_set_value (gc , offset , val );
222-
223- raw_spin_unlock_irqrestore (& gpio -> lock , flags );
224219}
225220
226221static int aspeed_sgpio_dir_in (struct gpio_chip * gc , unsigned int offset )
@@ -231,15 +226,14 @@ static int aspeed_sgpio_dir_in(struct gpio_chip *gc, unsigned int offset)
231226static int aspeed_sgpio_dir_out (struct gpio_chip * gc , unsigned int offset , int val )
232227{
233228 struct aspeed_sgpio * gpio = gpiochip_get_data (gc );
234- unsigned long flags ;
235229 int rc ;
236230
237231 /* No special action is required for setting the direction; we'll
238232 * error-out in sgpio_set_value if this isn't an output GPIO */
239233
240- raw_spin_lock_irqsave (& gpio -> lock , flags );
234+ guard (raw_spinlock_irqsave )(& gpio -> lock );
235+
241236 rc = sgpio_set_value (gc , offset , val );
242- raw_spin_unlock_irqrestore (& gpio -> lock , flags );
243237
244238 return rc ;
245239}
@@ -269,7 +263,6 @@ static void aspeed_sgpio_irq_ack(struct irq_data *d)
269263{
270264 const struct aspeed_sgpio_bank * bank ;
271265 struct aspeed_sgpio * gpio ;
272- unsigned long flags ;
273266 void __iomem * status_addr ;
274267 int offset ;
275268 u32 bit ;
@@ -278,18 +271,15 @@ static void aspeed_sgpio_irq_ack(struct irq_data *d)
278271
279272 status_addr = bank_reg (gpio , bank , reg_irq_status );
280273
281- raw_spin_lock_irqsave ( & gpio -> lock , flags );
274+ guard ( raw_spinlock_irqsave )( & gpio -> lock );
282275
283276 iowrite32 (bit , status_addr );
284-
285- raw_spin_unlock_irqrestore (& gpio -> lock , flags );
286277}
287278
288279static void aspeed_sgpio_irq_set_mask (struct irq_data * d , bool set )
289280{
290281 const struct aspeed_sgpio_bank * bank ;
291282 struct aspeed_sgpio * gpio ;
292- unsigned long flags ;
293283 u32 reg , bit ;
294284 void __iomem * addr ;
295285 int offset ;
@@ -301,17 +291,15 @@ static void aspeed_sgpio_irq_set_mask(struct irq_data *d, bool set)
301291 if (set )
302292 gpiochip_enable_irq (& gpio -> chip , irqd_to_hwirq (d ));
303293
304- raw_spin_lock_irqsave (& gpio -> lock , flags );
305-
306- reg = ioread32 (addr );
307- if (set )
308- reg |= bit ;
309- else
310- reg &= ~bit ;
311-
312- iowrite32 (reg , addr );
294+ scoped_guard (raw_spinlock_irqsave , & gpio -> lock ) {
295+ reg = ioread32 (addr );
296+ if (set )
297+ reg |= bit ;
298+ else
299+ reg &= ~bit ;
313300
314- raw_spin_unlock_irqrestore (& gpio -> lock , flags );
301+ iowrite32 (reg , addr );
302+ }
315303
316304 /* Masking the IRQ */
317305 if (!set )
@@ -339,7 +327,6 @@ static int aspeed_sgpio_set_type(struct irq_data *d, unsigned int type)
339327 const struct aspeed_sgpio_bank * bank ;
340328 irq_flow_handler_t handler ;
341329 struct aspeed_sgpio * gpio ;
342- unsigned long flags ;
343330 void __iomem * addr ;
344331 int offset ;
345332
@@ -366,24 +353,22 @@ static int aspeed_sgpio_set_type(struct irq_data *d, unsigned int type)
366353 return - EINVAL ;
367354 }
368355
369- raw_spin_lock_irqsave (& gpio -> lock , flags );
370-
371- addr = bank_reg (gpio , bank , reg_irq_type0 );
372- reg = ioread32 (addr );
373- reg = (reg & ~bit ) | type0 ;
374- iowrite32 (reg , addr );
375-
376- addr = bank_reg (gpio , bank , reg_irq_type1 );
377- reg = ioread32 (addr );
378- reg = (reg & ~bit ) | type1 ;
379- iowrite32 (reg , addr );
380-
381- addr = bank_reg (gpio , bank , reg_irq_type2 );
382- reg = ioread32 (addr );
383- reg = (reg & ~bit ) | type2 ;
384- iowrite32 (reg , addr );
385-
386- raw_spin_unlock_irqrestore (& gpio -> lock , flags );
356+ scoped_guard (raw_spinlock_irqsave , & gpio -> lock ) {
357+ addr = bank_reg (gpio , bank , reg_irq_type0 );
358+ reg = ioread32 (addr );
359+ reg = (reg & ~bit ) | type0 ;
360+ iowrite32 (reg , addr );
361+
362+ addr = bank_reg (gpio , bank , reg_irq_type1 );
363+ reg = ioread32 (addr );
364+ reg = (reg & ~bit ) | type1 ;
365+ iowrite32 (reg , addr );
366+
367+ addr = bank_reg (gpio , bank , reg_irq_type2 );
368+ reg = ioread32 (addr );
369+ reg = (reg & ~bit ) | type2 ;
370+ iowrite32 (reg , addr );
371+ }
387372
388373 irq_set_handler_locked (d , handler );
389374
@@ -487,13 +472,12 @@ static int aspeed_sgpio_reset_tolerance(struct gpio_chip *chip,
487472 unsigned int offset , bool enable )
488473{
489474 struct aspeed_sgpio * gpio = gpiochip_get_data (chip );
490- unsigned long flags ;
491475 void __iomem * reg ;
492476 u32 val ;
493477
494478 reg = bank_reg (gpio , to_bank (offset ), reg_tolerance );
495479
496- raw_spin_lock_irqsave ( & gpio -> lock , flags );
480+ guard ( raw_spinlock_irqsave )( & gpio -> lock );
497481
498482 val = readl (reg );
499483
@@ -504,8 +488,6 @@ static int aspeed_sgpio_reset_tolerance(struct gpio_chip *chip,
504488
505489 writel (val , reg );
506490
507- raw_spin_unlock_irqrestore (& gpio -> lock , flags );
508-
509491 return 0 ;
510492}
511493
0 commit comments