Skip to content

Commit 6452fea

Browse files
committed
Merge tag 'gpio-fixes-for-v6.14-rc3-take2' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux
Pull gpio fixes from Bartosz Golaszewski: - fix interrupt handling issues in gpio-bcm-kona - add an ACPI quirk for Acer Nitro ANV14 fixing an issue with spurious wake up events - add missing return value checks to gpio-stmpe - fix a crash in error path in gpiochip_get_ngpios() * tag 'gpio-fixes-for-v6.14-rc3-take2' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux: gpiolib: Fix crash on error in gpiochip_get_ngpios() gpio: stmpe: Check return value of stmpe_reg_read in stmpe_gpio_irq_sync_unlock gpiolib: acpi: Add a quirk for Acer Nitro ANV14 gpio: bcm-kona: Add missing newline to dev_err format string gpio: bcm-kona: Make sure GPIO bits are unlocked when requesting IRQ gpio: bcm-kona: Fix GPIO lock/unlock for banks above bank 0
2 parents 7ff71e6 + 7b4aebe commit 6452fea

File tree

4 files changed

+87
-19
lines changed

4 files changed

+87
-19
lines changed

drivers/gpio/gpio-bcm-kona.c

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,22 @@ struct bcm_kona_gpio {
6969
struct bcm_kona_gpio_bank {
7070
int id;
7171
int irq;
72+
/*
73+
* Used to keep track of lock/unlock operations for each GPIO in the
74+
* bank.
75+
*
76+
* All GPIOs are locked by default (see bcm_kona_gpio_reset), and the
77+
* unlock count for all GPIOs is 0 by default. Each unlock increments
78+
* the counter, and each lock decrements the counter.
79+
*
80+
* The lock function only locks the GPIO once its unlock counter is
81+
* down to 0. This is necessary because the GPIO is unlocked in two
82+
* places in this driver: once for requested GPIOs, and once for
83+
* requested IRQs. Since it is possible for a GPIO to be requested
84+
* as both a GPIO and an IRQ, we need to ensure that we don't lock it
85+
* too early.
86+
*/
87+
u8 gpio_unlock_count[GPIO_PER_BANK];
7288
/* Used in the interrupt handler */
7389
struct bcm_kona_gpio *kona_gpio;
7490
};
@@ -86,14 +102,24 @@ static void bcm_kona_gpio_lock_gpio(struct bcm_kona_gpio *kona_gpio,
86102
u32 val;
87103
unsigned long flags;
88104
int bank_id = GPIO_BANK(gpio);
105+
int bit = GPIO_BIT(gpio);
106+
struct bcm_kona_gpio_bank *bank = &kona_gpio->banks[bank_id];
89107

90-
raw_spin_lock_irqsave(&kona_gpio->lock, flags);
108+
if (bank->gpio_unlock_count[bit] == 0) {
109+
dev_err(kona_gpio->gpio_chip.parent,
110+
"Unbalanced locks for GPIO %u\n", gpio);
111+
return;
112+
}
91113

92-
val = readl(kona_gpio->reg_base + GPIO_PWD_STATUS(bank_id));
93-
val |= BIT(gpio);
94-
bcm_kona_gpio_write_lock_regs(kona_gpio->reg_base, bank_id, val);
114+
if (--bank->gpio_unlock_count[bit] == 0) {
115+
raw_spin_lock_irqsave(&kona_gpio->lock, flags);
95116

96-
raw_spin_unlock_irqrestore(&kona_gpio->lock, flags);
117+
val = readl(kona_gpio->reg_base + GPIO_PWD_STATUS(bank_id));
118+
val |= BIT(bit);
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+
}
97123
}
98124

99125
static void bcm_kona_gpio_unlock_gpio(struct bcm_kona_gpio *kona_gpio,
@@ -102,14 +128,20 @@ static void bcm_kona_gpio_unlock_gpio(struct bcm_kona_gpio *kona_gpio,
102128
u32 val;
103129
unsigned long flags;
104130
int bank_id = GPIO_BANK(gpio);
131+
int bit = GPIO_BIT(gpio);
132+
struct bcm_kona_gpio_bank *bank = &kona_gpio->banks[bank_id];
105133

106-
raw_spin_lock_irqsave(&kona_gpio->lock, flags);
134+
if (bank->gpio_unlock_count[bit] == 0) {
135+
raw_spin_lock_irqsave(&kona_gpio->lock, flags);
107136

108-
val = readl(kona_gpio->reg_base + GPIO_PWD_STATUS(bank_id));
109-
val &= ~BIT(gpio);
110-
bcm_kona_gpio_write_lock_regs(kona_gpio->reg_base, bank_id, val);
137+
val = readl(kona_gpio->reg_base + GPIO_PWD_STATUS(bank_id));
138+
val &= ~BIT(bit);
139+
bcm_kona_gpio_write_lock_regs(kona_gpio->reg_base, bank_id, val);
111140

112-
raw_spin_unlock_irqrestore(&kona_gpio->lock, flags);
141+
raw_spin_unlock_irqrestore(&kona_gpio->lock, flags);
142+
}
143+
144+
++bank->gpio_unlock_count[bit];
113145
}
114146

115147
static int bcm_kona_gpio_get_dir(struct gpio_chip *chip, unsigned gpio)
@@ -360,6 +392,7 @@ static void bcm_kona_gpio_irq_mask(struct irq_data *d)
360392

361393
kona_gpio = irq_data_get_irq_chip_data(d);
362394
reg_base = kona_gpio->reg_base;
395+
363396
raw_spin_lock_irqsave(&kona_gpio->lock, flags);
364397

365398
val = readl(reg_base + GPIO_INT_MASK(bank_id));
@@ -382,6 +415,7 @@ static void bcm_kona_gpio_irq_unmask(struct irq_data *d)
382415

383416
kona_gpio = irq_data_get_irq_chip_data(d);
384417
reg_base = kona_gpio->reg_base;
418+
385419
raw_spin_lock_irqsave(&kona_gpio->lock, flags);
386420

387421
val = readl(reg_base + GPIO_INT_MSKCLR(bank_id));
@@ -477,15 +511,26 @@ static void bcm_kona_gpio_irq_handler(struct irq_desc *desc)
477511
static int bcm_kona_gpio_irq_reqres(struct irq_data *d)
478512
{
479513
struct bcm_kona_gpio *kona_gpio = irq_data_get_irq_chip_data(d);
514+
unsigned int gpio = d->hwirq;
480515

481-
return gpiochip_reqres_irq(&kona_gpio->gpio_chip, d->hwirq);
516+
/*
517+
* We need to unlock the GPIO before any other operations are performed
518+
* on the relevant GPIO configuration registers
519+
*/
520+
bcm_kona_gpio_unlock_gpio(kona_gpio, gpio);
521+
522+
return gpiochip_reqres_irq(&kona_gpio->gpio_chip, gpio);
482523
}
483524

484525
static void bcm_kona_gpio_irq_relres(struct irq_data *d)
485526
{
486527
struct bcm_kona_gpio *kona_gpio = irq_data_get_irq_chip_data(d);
528+
unsigned int gpio = d->hwirq;
529+
530+
/* Once we no longer use it, lock the GPIO again */
531+
bcm_kona_gpio_lock_gpio(kona_gpio, gpio);
487532

488-
gpiochip_relres_irq(&kona_gpio->gpio_chip, d->hwirq);
533+
gpiochip_relres_irq(&kona_gpio->gpio_chip, gpio);
489534
}
490535

491536
static struct irq_chip bcm_gpio_irq_chip = {
@@ -614,7 +659,7 @@ static int bcm_kona_gpio_probe(struct platform_device *pdev)
614659
bank->irq = platform_get_irq(pdev, i);
615660
bank->kona_gpio = kona_gpio;
616661
if (bank->irq < 0) {
617-
dev_err(dev, "Couldn't get IRQ for bank %d", i);
662+
dev_err(dev, "Couldn't get IRQ for bank %d\n", i);
618663
ret = -ENOENT;
619664
goto err_irq_domain;
620665
}

drivers/gpio/gpio-stmpe.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,16 +191,24 @@ static void stmpe_gpio_irq_sync_unlock(struct irq_data *d)
191191
[REG_IE][CSB] = STMPE_IDX_IEGPIOR_CSB,
192192
[REG_IE][MSB] = STMPE_IDX_IEGPIOR_MSB,
193193
};
194-
int i, j;
194+
int ret, i, j;
195195

196196
/*
197197
* STMPE1600: to be able to get IRQ from pins,
198198
* a read must be done on GPMR register, or a write in
199199
* GPSR or GPCR registers
200200
*/
201201
if (stmpe->partnum == STMPE1600) {
202-
stmpe_reg_read(stmpe, stmpe->regs[STMPE_IDX_GPMR_LSB]);
203-
stmpe_reg_read(stmpe, stmpe->regs[STMPE_IDX_GPMR_CSB]);
202+
ret = stmpe_reg_read(stmpe, stmpe->regs[STMPE_IDX_GPMR_LSB]);
203+
if (ret < 0) {
204+
dev_err(stmpe->dev, "Failed to read GPMR_LSB: %d\n", ret);
205+
goto err;
206+
}
207+
ret = stmpe_reg_read(stmpe, stmpe->regs[STMPE_IDX_GPMR_CSB]);
208+
if (ret < 0) {
209+
dev_err(stmpe->dev, "Failed to read GPMR_CSB: %d\n", ret);
210+
goto err;
211+
}
204212
}
205213

206214
for (i = 0; i < CACHE_NR_REGS; i++) {
@@ -222,6 +230,7 @@ static void stmpe_gpio_irq_sync_unlock(struct irq_data *d)
222230
}
223231
}
224232

233+
err:
225234
mutex_unlock(&stmpe_gpio->irq_lock);
226235
}
227236

drivers/gpio/gpiolib-acpi.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,6 +1689,20 @@ static const struct dmi_system_id gpiolib_acpi_quirks[] __initconst = {
16891689
.ignore_wake = "PNP0C50:00@8",
16901690
},
16911691
},
1692+
{
1693+
/*
1694+
* Spurious wakeups from GPIO 11
1695+
* Found in BIOS 1.04
1696+
* https://gitlab.freedesktop.org/drm/amd/-/issues/3954
1697+
*/
1698+
.matches = {
1699+
DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
1700+
DMI_MATCH(DMI_PRODUCT_FAMILY, "Acer Nitro V 14"),
1701+
},
1702+
.driver_data = &(struct acpi_gpiolib_dmi_quirk) {
1703+
.ignore_interrupt = "AMDI0030:00@11",
1704+
},
1705+
},
16921706
{} /* Terminating entry */
16931707
};
16941708

drivers/gpio/gpiolib.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -904,13 +904,13 @@ int gpiochip_get_ngpios(struct gpio_chip *gc, struct device *dev)
904904
}
905905

906906
if (gc->ngpio == 0) {
907-
chip_err(gc, "tried to insert a GPIO chip with zero lines\n");
907+
dev_err(dev, "tried to insert a GPIO chip with zero lines\n");
908908
return -EINVAL;
909909
}
910910

911911
if (gc->ngpio > FASTPATH_NGPIO)
912-
chip_warn(gc, "line cnt %u is greater than fast path cnt %u\n",
913-
gc->ngpio, FASTPATH_NGPIO);
912+
dev_warn(dev, "line cnt %u is greater than fast path cnt %u\n",
913+
gc->ngpio, FASTPATH_NGPIO);
914914

915915
return 0;
916916
}

0 commit comments

Comments
 (0)