Skip to contentSkip to conversation

gpio: pca953x: Switch to bitops in IRQ callbacks

PATCH In review Andy Shevchenko 2 participants 4 messages Dec 9, 2019 – Dec 11, 2019 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 gpio: pca953x: Switch to bitops in IRQ callbacks

Since we have driver converted to use bitmap API we must use traditional bit operations (set_bit(), clear_bit(), etc.) against it.

Currently IRQ callbacks are missed in the conversion and thus broken.

Let's fix it right here right now.

Fixes 35d13d94893f ("gpio: pca953x: convert to use bitmap API")
---
 drivers/gpio/gpio-pca953x.c | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)
drivers/gpio/gpio-pca953x.c +10 -16
index 6652bee01966..9853547e7276 100644
@@ -568,16 +568,18 @@ static void pca953x_irq_mask(struct irq_data *d)
 {
 	struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
 	struct pca953x_chip *chip = gpiochip_get_data(gc);
+	irq_hw_number_t hwirq = irqd_to_hwirq(d);
 
-	chip->irq_mask[d->hwirq / BANK_SZ] &= ~BIT(d->hwirq % BANK_SZ);
+	clear_bit(hwirq, chip->irq_mask);
 }
 
 static void pca953x_irq_unmask(struct irq_data *d)
 {
 	struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
 	struct pca953x_chip *chip = gpiochip_get_data(gc);
+	irq_hw_number_t hwirq = irqd_to_hwirq(d);
 
-	chip->irq_mask[d->hwirq / BANK_SZ] |= BIT(d->hwirq % BANK_SZ);
+	set_bit(hwirq, chip->irq_mask);
 }
 
 static int pca953x_irq_set_wake(struct irq_data *d, unsigned int on)
@@ -635,8 +637,7 @@ static int pca953x_irq_set_type(struct irq_data *d, unsigned int type)
 {
 	struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
 	struct pca953x_chip *chip = gpiochip_get_data(gc);
-	int bank_nb = d->hwirq / BANK_SZ;
-	u8 mask = BIT(d->hwirq % BANK_SZ);
+	irq_hw_number_t hwirq = irqd_to_hwirq(d);
 
 	if (!(type & IRQ_TYPE_EDGE_BOTH)) {
 		dev_err(&chip->client->dev, "irq %d: unsupported type %d\n",
@@ -644,15 +645,8 @@ static int pca953x_irq_set_type(struct irq_data *d, unsigned int type)
 		return -EINVAL;
 	}
 
-	if (type & IRQ_TYPE_EDGE_FALLING)
-		chip->irq_trig_fall[bank_nb] |= mask;
-	else
-		chip->irq_trig_fall[bank_nb] &= ~mask;
-
-	if (type & IRQ_TYPE_EDGE_RISING)
-		chip->irq_trig_raise[bank_nb] |= mask;
-	else
-		chip->irq_trig_raise[bank_nb] &= ~mask;
+	assign_bit(hwirq, chip->irq_trig_fall, type & IRQ_TYPE_EDGE_FALLING);
+	assign_bit(hwirq, chip->irq_trig_raise, type & IRQ_TYPE_EDGE_RISING);
 
 	return 0;
 }
@@ -661,10 +655,10 @@ static void pca953x_irq_shutdown(struct irq_data *d)
 {
 	struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
 	struct pca953x_chip *chip = gpiochip_get_data(gc);
-	u8 mask = BIT(d->hwirq % BANK_SZ);
+	irq_hw_number_t hwirq = irqd_to_hwirq(d);
 
-	chip->irq_trig_raise[d->hwirq / BANK_SZ] &= ~mask;
-	chip->irq_trig_fall[d->hwirq / BANK_SZ] &= ~mask;
+	clear_bit(hwirq, chip->irq_trig_raise);
+	clear_bit(hwirq, chip->irq_trig_fall);
 }
 
 static bool pca953x_irq_pending(struct pca953x_chip *chip, unsigned long *pending)
Signature · 1 line
2.24.0
#1 lore raw

PATCH 2/2 gpio: pca953x: Remove redundant forward declaration

There is no need to have a forward declaration for pca953x_dt_ids[].

---
 drivers/gpio/gpio-pca953x.c | 2 --
 1 file changed, 2 deletions(-)
drivers/gpio/gpio-pca953x.c +0 -2
index 9853547e7276..2f8f5eb28ec5 100644
@@ -855,8 +855,6 @@ static int device_pca957x_init(struct pca953x_chip *chip, u32 invert)
 	return ret;
 }
 
-static const struct of_device_id pca953x_dt_ids[];
-
 static int pca953x_probe(struct i2c_client *client,
 			 const struct i2c_device_id *i2c_id)
 {
Signature · 1 line
2.24.0
#2 lore raw

Re: [PATCH v1 2/2] gpio: pca953x: Remove redundant forward declaration

pon., 9 gru 2019 o 13:35 Andy Shevchenko
<[email protected]> napisał(a):

Quoted 22 lines

There is no need to have a forward declaration for pca953x_dt_ids[].

---
 drivers/gpio/gpio-pca953x.c | 2 --
 1 file changed, 2 deletions(-)
drivers/gpio/gpio-pca953x.c +0 -3
index 9853547e7276..2f8f5eb28ec5 100644
@@ -855,8 +855,6 @@ static int device_pca957x_init(struct pca953x_chip *chip, u32 invert)
        return ret;
 }
 
-static const struct of_device_id pca953x_dt_ids[];
-
 static int pca953x_probe(struct i2c_client *client,
                         const struct i2c_device_id *i2c_id)
 {
--
Quoted 2 lines

2.24.0

Applied for next.

Bart

#3 lore raw
In reply to Andy Shevchenko

pon., 9 gru 2019 o 13:35 Andy Shevchenko
<[email protected]> napisał(a):

Quoted 8 lines

Since we have driver converted to use bitmap API we must use traditional bit operations (set_bit(), clear_bit(), etc.) against it.

Currently IRQ callbacks are missed in the conversion and thus broken.

Quoted 8 lines

Let's fix it right here right now.

Fixes 35d13d94893f ("gpio: pca953x: convert to use bitmap API")
---
 drivers/gpio/gpio-pca953x.c | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)

Applied for fixes.

Bart