Skip to content

Commit 93e0272

Browse files
committed
Merge tag 'gpio-fixes-for-v5.8-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux into fixes
gpio fixes for v5.8-rc3 - several fixes for gpio-pca953x
2 parents 861254d + 5d89135 commit 93e0272

File tree

1 file changed

+94
-5
lines changed

1 file changed

+94
-5
lines changed

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)