Skip to content

Commit 5257169

Browse files
FDESTMMarc Zyngier
authored andcommitted
irqchip/stm32-exti: Use the hwspin_lock_timeout_in_atomic() API
Now that the hwspin_lock_timeout_in_atomic() API is available use it. Signed-off-by: Fabien Dessenne <[email protected]> Signed-off-by: Alexandre Torgue <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent fa03587 commit 5257169

File tree

1 file changed

+20
-45
lines changed

1 file changed

+20
-45
lines changed

drivers/irqchip/irq-stm32-exti.c

Lines changed: 20 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#define IRQS_PER_BANK 32
2626

2727
#define HWSPNLCK_TIMEOUT 1000 /* usec */
28-
#define HWSPNLCK_RETRY_DELAY 100 /* usec */
2928

3029
struct stm32_exti_bank {
3130
u32 imr_ofst;
@@ -277,55 +276,24 @@ static int stm32_exti_set_type(struct irq_data *d,
277276
return 0;
278277
}
279278

280-
static int stm32_exti_hwspin_lock(struct stm32_exti_chip_data *chip_data)
281-
{
282-
int ret, timeout = 0;
283-
284-
if (!chip_data->host_data->hwlock)
285-
return 0;
286-
287-
/*
288-
* Use the x_raw API since we are under spin_lock protection.
289-
* Do not use the x_timeout API because we are under irq_disable
290-
* mode (see __setup_irq())
291-
*/
292-
do {
293-
ret = hwspin_trylock_raw(chip_data->host_data->hwlock);
294-
if (!ret)
295-
return 0;
296-
297-
udelay(HWSPNLCK_RETRY_DELAY);
298-
timeout += HWSPNLCK_RETRY_DELAY;
299-
} while (timeout < HWSPNLCK_TIMEOUT);
300-
301-
if (ret == -EBUSY)
302-
ret = -ETIMEDOUT;
303-
304-
if (ret)
305-
pr_err("%s can't get hwspinlock (%d)\n", __func__, ret);
306-
307-
return ret;
308-
}
309-
310-
static void stm32_exti_hwspin_unlock(struct stm32_exti_chip_data *chip_data)
311-
{
312-
if (chip_data->host_data->hwlock)
313-
hwspin_unlock_raw(chip_data->host_data->hwlock);
314-
}
315-
316279
static int stm32_irq_set_type(struct irq_data *d, unsigned int type)
317280
{
318281
struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
319282
struct stm32_exti_chip_data *chip_data = gc->private;
320283
const struct stm32_exti_bank *stm32_bank = chip_data->reg_bank;
284+
struct hwspinlock *hwlock = chip_data->host_data->hwlock;
321285
u32 rtsr, ftsr;
322286
int err;
323287

324288
irq_gc_lock(gc);
325289

326-
err = stm32_exti_hwspin_lock(chip_data);
327-
if (err)
328-
goto unlock;
290+
if (hwlock) {
291+
err = hwspin_lock_timeout_in_atomic(hwlock, HWSPNLCK_TIMEOUT);
292+
if (err) {
293+
pr_err("%s can't get hwspinlock (%d)\n", __func__, err);
294+
goto unlock;
295+
}
296+
}
329297

330298
rtsr = irq_reg_readl(gc, stm32_bank->rtsr_ofst);
331299
ftsr = irq_reg_readl(gc, stm32_bank->ftsr_ofst);
@@ -338,7 +306,8 @@ static int stm32_irq_set_type(struct irq_data *d, unsigned int type)
338306
irq_reg_writel(gc, ftsr, stm32_bank->ftsr_ofst);
339307

340308
unspinlock:
341-
stm32_exti_hwspin_unlock(chip_data);
309+
if (hwlock)
310+
hwspin_unlock_in_atomic(hwlock);
342311
unlock:
343312
irq_gc_unlock(gc);
344313

@@ -504,15 +473,20 @@ static int stm32_exti_h_set_type(struct irq_data *d, unsigned int type)
504473
{
505474
struct stm32_exti_chip_data *chip_data = irq_data_get_irq_chip_data(d);
506475
const struct stm32_exti_bank *stm32_bank = chip_data->reg_bank;
476+
struct hwspinlock *hwlock = chip_data->host_data->hwlock;
507477
void __iomem *base = chip_data->host_data->base;
508478
u32 rtsr, ftsr;
509479
int err;
510480

511481
raw_spin_lock(&chip_data->rlock);
512482

513-
err = stm32_exti_hwspin_lock(chip_data);
514-
if (err)
515-
goto unlock;
483+
if (hwlock) {
484+
err = hwspin_lock_timeout_in_atomic(hwlock, HWSPNLCK_TIMEOUT);
485+
if (err) {
486+
pr_err("%s can't get hwspinlock (%d)\n", __func__, err);
487+
goto unlock;
488+
}
489+
}
516490

517491
rtsr = readl_relaxed(base + stm32_bank->rtsr_ofst);
518492
ftsr = readl_relaxed(base + stm32_bank->ftsr_ofst);
@@ -525,7 +499,8 @@ static int stm32_exti_h_set_type(struct irq_data *d, unsigned int type)
525499
writel_relaxed(ftsr, base + stm32_bank->ftsr_ofst);
526500

527501
unspinlock:
528-
stm32_exti_hwspin_unlock(chip_data);
502+
if (hwlock)
503+
hwspin_unlock_in_atomic(hwlock);
529504
unlock:
530505
raw_spin_unlock(&chip_data->rlock);
531506

0 commit comments

Comments
 (0)