linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Should irq_enable/disable be flagging/unflagging gpio lines used as irq?
@ 2017-07-11 17:55 Davide Hug
  2017-07-12 11:35 ` Linus Walleij
  0 siblings, 1 reply; 12+ messages in thread
From: Davide Hug @ 2017-07-11 17:55 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-gpio

Hi,

I'm looking at a driver (hwmon/sht15) that does not load with message:

	gpio-48 (SHT15 data): _gpiod_direction_output_raw: tried to set a GPIO tied to an IRQ as output

This happens because the driver uses a GPIO line alternately (and not at the
same time) as IRQ and output. To do this irq_enable/disable are used to
prevent setting a GPIO with enabled IRQ as output. This seems the right
approach to me since in the patch "gpio: add API to be strict about GPIO IRQ
usage"[1] I read:

	The API is symmetric so that lines can also be flagged from
	.irq_enable() and unflagged from IRQ by .irq_disable().

But I didn't find any GPIO driver implementing this API in irq_enable/disable.

Since my platform uses omap_gpio which does not implement
irq_enable/disable at all, I added a default irq_enable/disable
implementation in gpio/gpiolib.c (in the patch below).

Is it the right approach to call gpiochip_lock_as_irq/gpiochip_unlock_as_irq
in irq_enable/irq_disable?

Thanks, Davide

[1]: https://github.com/torvalds/linux/commit/d468bf9ecaabd3bf3a6134e5a369ced82b1d1ca1



diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 8b4d721d6d63..c1db0461f29d 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1678,6 +1678,22 @@ static void gpiochip_irq_relres(struct irq_data *d)
 	module_put(chip->gpiodev->owner);
 }
 
+static void gpiochip_irq_disable(struct irq_data *data)
+{
+	struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
+
+	gpiochip_unlock_as_irq(chip, data->hwirq);
+	data->chip->irq_mask(data);
+}
+
+static void gpiochip_irq_enable(struct irq_data *data)
+{
+	struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
+
+	gpiochip_lock_as_irq(chip, data->hwirq);
+	data->chip->irq_unmask(data);
+}
+
 static int gpiochip_to_irq(struct gpio_chip *chip, unsigned offset)
 {
 	return irq_find_mapping(chip->irqdomain, offset);
@@ -1714,6 +1730,8 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
 	if (gpiochip->irqchip) {
 		gpiochip->irqchip->irq_request_resources = NULL;
 		gpiochip->irqchip->irq_release_resources = NULL;
+		gpiochip->irqchip->irq_disable = NULL;
+		gpiochip->irqchip->irq_enable  = NULL;
 		gpiochip->irqchip = NULL;
 	}
 
@@ -1814,6 +1832,11 @@ int gpiochip_irqchip_add_key(struct gpio_chip *gpiochip,
 		irqchip->irq_request_resources = gpiochip_irq_reqres;
 		irqchip->irq_release_resources = gpiochip_irq_relres;
 	}
+	if (!irqchip->irq_disable &&
+	    !irqchip->irq_enable) {
+		irqchip->irq_disable = gpiochip_irq_disable;
+		irqchip->irq_enable  = gpiochip_irq_enable;
+	}
 
 	/*
 	 * Prepare the mapping since the irqchip shall be orthogonal to

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2017-11-30 13:55 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-11 17:55 Should irq_enable/disable be flagging/unflagging gpio lines used as irq? Davide Hug
2017-07-12 11:35 ` Linus Walleij
2017-07-12 18:33   ` Grygorii Strashko
2017-07-12 21:41   ` Thomas Gleixner
2017-07-13 20:17     ` Davide Hug
2017-08-01  7:37       ` Linus Walleij
2017-08-25 22:45         ` Davide Hug
2017-09-08 14:22           ` Linus Walleij
2017-09-10 14:16             ` Davide Hug
2017-09-12 13:57               ` Linus Walleij
2017-11-20 22:48                 ` Davide Hug
2017-11-30 13:55                   ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).