Skip to content

Commit 3f88343

Browse files
committed
Merge tag 'gpio-v5.8-2' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio
Pull GPIO fixes from Linus Walleij: "Some GPIO fixes, most of them for the PCA953x that Andy worked hard to fix up. - Fix two runtime PM errorpath problems in the Arizona GPIO driver. - Fix three interrupt issues in the PCA953x driver. - Fix the automatic address increment handling in the PCA953x driver again. - Add a quirk to the PCA953x that fixes a problem in the Intel Galileo Gen 2" * tag 'gpio-v5.8-2' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: gpio: pca953x: Fix GPIO resource leak on Intel Galileo Gen 2 gpio: pca953x: disable regmap locking for automatic address incrementing gpio: pca953x: Fix direction setting when configure an IRQ gpio: pca953x: Override IRQ for one of the expanders on Galileo Gen 2 gpio: pca953x: Synchronize interrupt handler properly gpio: arizona: put pm_runtime in case of failure gpio: arizona: handle pm_runtime_get_sync failure case
2 parents d02b047 + 93e0272 commit 3f88343

File tree

2 files changed

+100
-6
lines changed

2 files changed

+100
-6
lines changed

drivers/gpio/gpio-arizona.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ static int arizona_gpio_get(struct gpio_chip *chip, unsigned offset)
6464
ret = pm_runtime_get_sync(chip->parent);
6565
if (ret < 0) {
6666
dev_err(chip->parent, "Failed to resume: %d\n", ret);
67+
pm_runtime_put_autosuspend(chip->parent);
6768
return ret;
6869
}
6970

@@ -72,12 +73,15 @@ static int arizona_gpio_get(struct gpio_chip *chip, unsigned offset)
7273
if (ret < 0) {
7374
dev_err(chip->parent, "Failed to drop cache: %d\n",
7475
ret);
76+
pm_runtime_put_autosuspend(chip->parent);
7577
return ret;
7678
}
7779

7880
ret = regmap_read(arizona->regmap, reg, &val);
79-
if (ret < 0)
81+
if (ret < 0) {
82+
pm_runtime_put_autosuspend(chip->parent);
8083
return ret;
84+
}
8185

8286
pm_runtime_mark_last_busy(chip->parent);
8387
pm_runtime_put_autosuspend(chip->parent);
@@ -106,6 +110,7 @@ static int arizona_gpio_direction_out(struct gpio_chip *chip,
106110
ret = pm_runtime_get_sync(chip->parent);
107111
if (ret < 0) {
108112
dev_err(chip->parent, "Failed to resume: %d\n", ret);
113+
pm_runtime_put(chip->parent);
109114
return ret;
110115
}
111116
}

drivers/gpio/gpio-pca953x.c

Lines changed: 94 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,84 @@ static const struct i2c_device_id pca953x_id[] = {
107107
};
108108
MODULE_DEVICE_TABLE(i2c, pca953x_id);
109109

110+
#ifdef CONFIG_GPIO_PCA953X_IRQ
111+
112+
#include <linux/dmi.h>
113+
#include <linux/gpio.h>
114+
#include <linux/list.h>
115+
116+
static const struct dmi_system_id pca953x_dmi_acpi_irq_info[] = {
117+
{
118+
/*
119+
* On Intel Galileo Gen 2 board the IRQ pin of one of
120+
* the I²C GPIO expanders, which has GpioInt() resource,
121+
* is provided as an absolute number instead of being
122+
* relative. Since first controller (gpio-sch.c) and
123+
* second (gpio-dwapb.c) are at the fixed bases, we may
124+
* safely refer to the number in the global space to get
125+
* an IRQ out of it.
126+
*/
127+
.matches = {
128+
DMI_EXACT_MATCH(DMI_BOARD_NAME, "GalileoGen2"),
129+
},
130+
},
131+
{}
132+
};
133+
134+
#ifdef CONFIG_ACPI
135+
static int pca953x_acpi_get_pin(struct acpi_resource *ares, void *data)
136+
{
137+
struct acpi_resource_gpio *agpio;
138+
int *pin = data;
139+
140+
if (acpi_gpio_get_irq_resource(ares, &agpio))
141+
*pin = agpio->pin_table[0];
142+
return 1;
143+
}
144+
145+
static int pca953x_acpi_find_pin(struct device *dev)
146+
{
147+
struct acpi_device *adev = ACPI_COMPANION(dev);
148+
int pin = -ENOENT, ret;
149+
LIST_HEAD(r);
150+
151+
ret = acpi_dev_get_resources(adev, &r, pca953x_acpi_get_pin, &pin);
152+
acpi_dev_free_resource_list(&r);
153+
if (ret < 0)
154+
return ret;
155+
156+
return pin;
157+
}
158+
#else
159+
static inline int pca953x_acpi_find_pin(struct device *dev) { return -ENXIO; }
160+
#endif
161+
162+
static int pca953x_acpi_get_irq(struct device *dev)
163+
{
164+
int pin, ret;
165+
166+
pin = pca953x_acpi_find_pin(dev);
167+
if (pin < 0)
168+
return pin;
169+
170+
dev_info(dev, "Applying ACPI interrupt quirk (GPIO %d)\n", pin);
171+
172+
if (!gpio_is_valid(pin))
173+
return -EINVAL;
174+
175+
ret = gpio_request(pin, "pca953x interrupt");
176+
if (ret)
177+
return ret;
178+
179+
ret = gpio_to_irq(pin);
180+
181+
/* When pin is used as an IRQ, no need to keep it requested */
182+
gpio_free(pin);
183+
184+
return ret;
185+
}
186+
#endif
187+
110188
static const struct acpi_device_id pca953x_acpi_ids[] = {
111189
{ "INT3491", 16 | PCA953X_TYPE | PCA_LATCH_INT, },
112190
{ }
@@ -322,6 +400,7 @@ static const struct regmap_config pca953x_ai_i2c_regmap = {
322400
.writeable_reg = pca953x_writeable_register,
323401
.volatile_reg = pca953x_volatile_register,
324402

403+
.disable_locking = true,
325404
.cache_type = REGCACHE_RBTREE,
326405
.max_register = 0x7f,
327406
};
@@ -623,8 +702,6 @@ static void pca953x_irq_bus_sync_unlock(struct irq_data *d)
623702
DECLARE_BITMAP(reg_direction, MAX_LINE);
624703
int level;
625704

626-
pca953x_read_regs(chip, chip->regs->direction, reg_direction);
627-
628705
if (chip->driver_data & PCA_PCAL) {
629706
/* Enable latch on interrupt-enabled inputs */
630707
pca953x_write_regs(chip, PCAL953X_IN_LATCH, chip->irq_mask);
@@ -635,7 +712,11 @@ static void pca953x_irq_bus_sync_unlock(struct irq_data *d)
635712
pca953x_write_regs(chip, PCAL953X_INT_MASK, irq_mask);
636713
}
637714

715+
/* Switch direction to input if needed */
716+
pca953x_read_regs(chip, chip->regs->direction, reg_direction);
717+
638718
bitmap_or(irq_mask, chip->irq_trig_fall, chip->irq_trig_raise, gc->ngpio);
719+
bitmap_complement(reg_direction, reg_direction, gc->ngpio);
639720
bitmap_and(irq_mask, irq_mask, reg_direction, gc->ngpio);
640721

641722
/* Look for any newly setup interrupt */
@@ -734,14 +815,16 @@ static irqreturn_t pca953x_irq_handler(int irq, void *devid)
734815
struct gpio_chip *gc = &chip->gpio_chip;
735816
DECLARE_BITMAP(pending, MAX_LINE);
736817
int level;
818+
bool ret;
737819

738-
if (!pca953x_irq_pending(chip, pending))
739-
return IRQ_NONE;
820+
mutex_lock(&chip->i2c_lock);
821+
ret = pca953x_irq_pending(chip, pending);
822+
mutex_unlock(&chip->i2c_lock);
740823

741824
for_each_set_bit(level, pending, gc->ngpio)
742825
handle_nested_irq(irq_find_mapping(gc->irq.domain, level));
743826

744-
return IRQ_HANDLED;
827+
return IRQ_RETVAL(ret);
745828
}
746829

747830
static int pca953x_irq_setup(struct pca953x_chip *chip, int irq_base)
@@ -752,6 +835,12 @@ static int pca953x_irq_setup(struct pca953x_chip *chip, int irq_base)
752835
DECLARE_BITMAP(irq_stat, MAX_LINE);
753836
int ret;
754837

838+
if (dmi_first_match(pca953x_dmi_acpi_irq_info)) {
839+
ret = pca953x_acpi_get_irq(&client->dev);
840+
if (ret > 0)
841+
client->irq = ret;
842+
}
843+
755844
if (!client->irq)
756845
return 0;
757846

0 commit comments

Comments
 (0)