7
7
*/
8
8
9
9
#include <linux/bitops.h>
10
+ #include <linux/cleanup.h>
10
11
#include <linux/err.h>
11
12
#include <linux/gpio/driver.h>
12
13
#include <linux/init.h>
@@ -100,7 +101,6 @@ static void bcm_kona_gpio_lock_gpio(struct bcm_kona_gpio *kona_gpio,
100
101
unsigned gpio )
101
102
{
102
103
u32 val ;
103
- unsigned long flags ;
104
104
int bank_id = GPIO_BANK (gpio );
105
105
int bit = GPIO_BIT (gpio );
106
106
struct bcm_kona_gpio_bank * bank = & kona_gpio -> banks [bank_id ];
@@ -112,33 +112,28 @@ static void bcm_kona_gpio_lock_gpio(struct bcm_kona_gpio *kona_gpio,
112
112
}
113
113
114
114
if (-- bank -> gpio_unlock_count [bit ] == 0 ) {
115
- raw_spin_lock_irqsave ( & kona_gpio -> lock , flags );
115
+ guard ( raw_spinlock_irqsave )( & kona_gpio -> lock );
116
116
117
117
val = readl (kona_gpio -> reg_base + GPIO_PWD_STATUS (bank_id ));
118
118
val |= BIT (bit );
119
119
bcm_kona_gpio_write_lock_regs (kona_gpio -> reg_base , bank_id , val );
120
-
121
- raw_spin_unlock_irqrestore (& kona_gpio -> lock , flags );
122
120
}
123
121
}
124
122
125
123
static void bcm_kona_gpio_unlock_gpio (struct bcm_kona_gpio * kona_gpio ,
126
124
unsigned gpio )
127
125
{
128
126
u32 val ;
129
- unsigned long flags ;
130
127
int bank_id = GPIO_BANK (gpio );
131
128
int bit = GPIO_BIT (gpio );
132
129
struct bcm_kona_gpio_bank * bank = & kona_gpio -> banks [bank_id ];
133
130
134
131
if (bank -> gpio_unlock_count [bit ] == 0 ) {
135
- raw_spin_lock_irqsave ( & kona_gpio -> lock , flags );
132
+ guard ( raw_spinlock_irqsave )( & kona_gpio -> lock );
136
133
137
134
val = readl (kona_gpio -> reg_base + GPIO_PWD_STATUS (bank_id ));
138
135
val &= ~BIT (bit );
139
136
bcm_kona_gpio_write_lock_regs (kona_gpio -> reg_base , bank_id , val );
140
-
141
- raw_spin_unlock_irqrestore (& kona_gpio -> lock , flags );
142
137
}
143
138
144
139
++ bank -> gpio_unlock_count [bit ];
@@ -161,24 +156,21 @@ static void bcm_kona_gpio_set(struct gpio_chip *chip, unsigned gpio, int value)
161
156
int bank_id = GPIO_BANK (gpio );
162
157
int bit = GPIO_BIT (gpio );
163
158
u32 val , reg_offset ;
164
- unsigned long flags ;
165
159
166
160
kona_gpio = gpiochip_get_data (chip );
167
161
reg_base = kona_gpio -> reg_base ;
168
- raw_spin_lock_irqsave (& kona_gpio -> lock , flags );
162
+
163
+ guard (raw_spinlock_irqsave )(& kona_gpio -> lock );
169
164
170
165
/* this function only applies to output pin */
171
166
if (bcm_kona_gpio_get_dir (chip , gpio ) == GPIO_LINE_DIRECTION_IN )
172
- goto out ;
167
+ return ;
173
168
174
169
reg_offset = value ? GPIO_OUT_SET (bank_id ) : GPIO_OUT_CLEAR (bank_id );
175
170
176
171
val = readl (reg_base + reg_offset );
177
172
val |= BIT (bit );
178
173
writel (val , reg_base + reg_offset );
179
-
180
- out :
181
- raw_spin_unlock_irqrestore (& kona_gpio -> lock , flags );
182
174
}
183
175
184
176
static int bcm_kona_gpio_get (struct gpio_chip * chip , unsigned gpio )
@@ -188,11 +180,11 @@ static int bcm_kona_gpio_get(struct gpio_chip *chip, unsigned gpio)
188
180
int bank_id = GPIO_BANK (gpio );
189
181
int bit = GPIO_BIT (gpio );
190
182
u32 val , reg_offset ;
191
- unsigned long flags ;
192
183
193
184
kona_gpio = gpiochip_get_data (chip );
194
185
reg_base = kona_gpio -> reg_base ;
195
- raw_spin_lock_irqsave (& kona_gpio -> lock , flags );
186
+
187
+ guard (raw_spinlock_irqsave )(& kona_gpio -> lock );
196
188
197
189
if (bcm_kona_gpio_get_dir (chip , gpio ) == GPIO_LINE_DIRECTION_IN )
198
190
reg_offset = GPIO_IN_STATUS (bank_id );
@@ -202,8 +194,6 @@ static int bcm_kona_gpio_get(struct gpio_chip *chip, unsigned gpio)
202
194
/* read the GPIO bank status */
203
195
val = readl (reg_base + reg_offset );
204
196
205
- raw_spin_unlock_irqrestore (& kona_gpio -> lock , flags );
206
-
207
197
/* return the specified bit status */
208
198
return !!(val & BIT (bit ));
209
199
}
@@ -228,19 +218,17 @@ static int bcm_kona_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
228
218
struct bcm_kona_gpio * kona_gpio ;
229
219
void __iomem * reg_base ;
230
220
u32 val ;
231
- unsigned long flags ;
232
221
233
222
kona_gpio = gpiochip_get_data (chip );
234
223
reg_base = kona_gpio -> reg_base ;
235
- raw_spin_lock_irqsave (& kona_gpio -> lock , flags );
224
+
225
+ guard (raw_spinlock_irqsave )(& kona_gpio -> lock );
236
226
237
227
val = readl (reg_base + GPIO_CONTROL (gpio ));
238
228
val &= ~GPIO_GPCTR0_IOTR_MASK ;
239
229
val |= GPIO_GPCTR0_IOTR_CMD_INPUT ;
240
230
writel (val , reg_base + GPIO_CONTROL (gpio ));
241
231
242
- raw_spin_unlock_irqrestore (& kona_gpio -> lock , flags );
243
-
244
232
return 0 ;
245
233
}
246
234
@@ -252,11 +240,11 @@ static int bcm_kona_gpio_direction_output(struct gpio_chip *chip,
252
240
int bank_id = GPIO_BANK (gpio );
253
241
int bit = GPIO_BIT (gpio );
254
242
u32 val , reg_offset ;
255
- unsigned long flags ;
256
243
257
244
kona_gpio = gpiochip_get_data (chip );
258
245
reg_base = kona_gpio -> reg_base ;
259
- raw_spin_lock_irqsave (& kona_gpio -> lock , flags );
246
+
247
+ guard (raw_spinlock_irqsave )(& kona_gpio -> lock );
260
248
261
249
val = readl (reg_base + GPIO_CONTROL (gpio ));
262
250
val &= ~GPIO_GPCTR0_IOTR_MASK ;
@@ -268,8 +256,6 @@ static int bcm_kona_gpio_direction_output(struct gpio_chip *chip,
268
256
val |= BIT (bit );
269
257
writel (val , reg_base + reg_offset );
270
258
271
- raw_spin_unlock_irqrestore (& kona_gpio -> lock , flags );
272
-
273
259
return 0 ;
274
260
}
275
261
@@ -289,7 +275,6 @@ static int bcm_kona_gpio_set_debounce(struct gpio_chip *chip, unsigned gpio,
289
275
struct bcm_kona_gpio * kona_gpio ;
290
276
void __iomem * reg_base ;
291
277
u32 val , res ;
292
- unsigned long flags ;
293
278
294
279
kona_gpio = gpiochip_get_data (chip );
295
280
reg_base = kona_gpio -> reg_base ;
@@ -312,7 +297,7 @@ static int bcm_kona_gpio_set_debounce(struct gpio_chip *chip, unsigned gpio,
312
297
}
313
298
314
299
/* spin lock for read-modify-write of the GPIO register */
315
- raw_spin_lock_irqsave ( & kona_gpio -> lock , flags );
300
+ guard ( raw_spinlock_irqsave )( & kona_gpio -> lock );
316
301
317
302
val = readl (reg_base + GPIO_CONTROL (gpio ));
318
303
val &= ~GPIO_GPCTR0_DBR_MASK ;
@@ -327,8 +312,6 @@ static int bcm_kona_gpio_set_debounce(struct gpio_chip *chip, unsigned gpio,
327
312
328
313
writel (val , reg_base + GPIO_CONTROL (gpio ));
329
314
330
- raw_spin_unlock_irqrestore (& kona_gpio -> lock , flags );
331
-
332
315
return 0 ;
333
316
}
334
317
@@ -367,17 +350,15 @@ static void bcm_kona_gpio_irq_ack(struct irq_data *d)
367
350
int bank_id = GPIO_BANK (gpio );
368
351
int bit = GPIO_BIT (gpio );
369
352
u32 val ;
370
- unsigned long flags ;
371
353
372
354
kona_gpio = irq_data_get_irq_chip_data (d );
373
355
reg_base = kona_gpio -> reg_base ;
374
- raw_spin_lock_irqsave (& kona_gpio -> lock , flags );
356
+
357
+ guard (raw_spinlock_irqsave )(& kona_gpio -> lock );
375
358
376
359
val = readl (reg_base + GPIO_INT_STATUS (bank_id ));
377
360
val |= BIT (bit );
378
361
writel (val , reg_base + GPIO_INT_STATUS (bank_id ));
379
-
380
- raw_spin_unlock_irqrestore (& kona_gpio -> lock , flags );
381
362
}
382
363
383
364
static void bcm_kona_gpio_irq_mask (struct irq_data * d )
@@ -388,19 +369,16 @@ static void bcm_kona_gpio_irq_mask(struct irq_data *d)
388
369
int bank_id = GPIO_BANK (gpio );
389
370
int bit = GPIO_BIT (gpio );
390
371
u32 val ;
391
- unsigned long flags ;
392
372
393
373
kona_gpio = irq_data_get_irq_chip_data (d );
394
374
reg_base = kona_gpio -> reg_base ;
395
375
396
- raw_spin_lock_irqsave ( & kona_gpio -> lock , flags );
376
+ guard ( raw_spinlock_irqsave )( & kona_gpio -> lock );
397
377
398
378
val = readl (reg_base + GPIO_INT_MASK (bank_id ));
399
379
val |= BIT (bit );
400
380
writel (val , reg_base + GPIO_INT_MASK (bank_id ));
401
381
gpiochip_disable_irq (& kona_gpio -> gpio_chip , gpio );
402
-
403
- raw_spin_unlock_irqrestore (& kona_gpio -> lock , flags );
404
382
}
405
383
406
384
static void bcm_kona_gpio_irq_unmask (struct irq_data * d )
@@ -411,19 +389,16 @@ static void bcm_kona_gpio_irq_unmask(struct irq_data *d)
411
389
int bank_id = GPIO_BANK (gpio );
412
390
int bit = GPIO_BIT (gpio );
413
391
u32 val ;
414
- unsigned long flags ;
415
392
416
393
kona_gpio = irq_data_get_irq_chip_data (d );
417
394
reg_base = kona_gpio -> reg_base ;
418
395
419
- raw_spin_lock_irqsave ( & kona_gpio -> lock , flags );
396
+ guard ( raw_spinlock_irqsave )( & kona_gpio -> lock );
420
397
421
398
val = readl (reg_base + GPIO_INT_MSKCLR (bank_id ));
422
399
val |= BIT (bit );
423
400
writel (val , reg_base + GPIO_INT_MSKCLR (bank_id ));
424
401
gpiochip_enable_irq (& kona_gpio -> gpio_chip , gpio );
425
-
426
- raw_spin_unlock_irqrestore (& kona_gpio -> lock , flags );
427
402
}
428
403
429
404
static int bcm_kona_gpio_irq_set_type (struct irq_data * d , unsigned int type )
@@ -433,7 +408,6 @@ static int bcm_kona_gpio_irq_set_type(struct irq_data *d, unsigned int type)
433
408
unsigned gpio = d -> hwirq ;
434
409
u32 lvl_type ;
435
410
u32 val ;
436
- unsigned long flags ;
437
411
438
412
kona_gpio = irq_data_get_irq_chip_data (d );
439
413
reg_base = kona_gpio -> reg_base ;
@@ -459,15 +433,13 @@ static int bcm_kona_gpio_irq_set_type(struct irq_data *d, unsigned int type)
459
433
return - EINVAL ;
460
434
}
461
435
462
- raw_spin_lock_irqsave ( & kona_gpio -> lock , flags );
436
+ guard ( raw_spinlock_irqsave )( & kona_gpio -> lock );
463
437
464
438
val = readl (reg_base + GPIO_CONTROL (gpio ));
465
439
val &= ~GPIO_GPCTR0_ITR_MASK ;
466
440
val |= lvl_type << GPIO_GPCTR0_ITR_SHIFT ;
467
441
writel (val , reg_base + GPIO_CONTROL (gpio ));
468
442
469
- raw_spin_unlock_irqrestore (& kona_gpio -> lock , flags );
470
-
471
443
return 0 ;
472
444
}
473
445
0 commit comments