devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jerome Brunet <jbrunet@baylibre.com>
To: Kevin Hilman <khilman@baylibre.com>,
	Carlo Caione <carlo@caione.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Jason Cooper <jason@lakedaemon.net>,
	Marc Zyngier <marc.zyngier@arm.com>
Cc: Jerome Brunet <jbrunet@baylibre.com>,
	linux-amlogic@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org,
	linux-gpio@vger.kernel.org
Subject: [RFC 10/10] irqchip: meson: Add support for IRQ_TYPE_EDGE_BOTH
Date: Tue,  4 Oct 2016 17:08:28 +0200	[thread overview]
Message-ID: <1475593708-10526-11-git-send-email-jbrunet@baylibre.com> (raw)
In-Reply-To: <1475593708-10526-1-git-send-email-jbrunet@baylibre.com>

The IP cannot take IRQ_EDGE_BOTH because the polarity in the filtering
block is just one bit. It can trigger on either edge, but not both with
the same configuration.

This prevents meson based SoC to use some simple generic driver, like
gpio-keys. The proposition is to change edge polarity in the end of
interrupt callback (just toggling the polarity register of the IP).

This works nicely but has 2 limitations:
 1) If the signal is initially high, the first falling edge will not be
    detected, because the chip is initially configured for a rising
    edge.
 2) If the signal changes too quickly for all edges to be properly
    handled, an additional edge might get lost, for the same reason as
    point 1.

There is no drawback for introducing this work around so, knowing the
limitation, it would be nice to have it

Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
---
 drivers/irqchip/irq-meson-gpio.c | 45 +++++++++++++++++++++++++++++++++++++---
 1 file changed, 42 insertions(+), 3 deletions(-)

diff --git a/drivers/irqchip/irq-meson-gpio.c b/drivers/irqchip/irq-meson-gpio.c
index 184025a9cdaf..5bcbefef3e94 100644
--- a/drivers/irqchip/irq-meson-gpio.c
+++ b/drivers/irqchip/irq-meson-gpio.c
@@ -58,6 +58,7 @@ struct meson_gpio_irq_domain {
 struct meson_gpio_irq_chip {
 	void __iomem *base;
 	int index;
+	unsigned int flow_type;
 };
 
 static const struct meson_gpio_irq_params meson8_params = {
@@ -91,6 +92,19 @@ static void meson_gpio_irq_update_bits(void __iomem *base, unsigned int reg,
 	writel(tmp, base + reg);
 }
 
+static void meson_gpio_irq_flip_bits(void __iomem *base, unsigned int reg,
+				     u32 mask)
+{
+	u32 tmp, val;
+
+	tmp = readl(base + reg);
+	val = tmp ^ mask;
+	tmp = (tmp & val) | val;
+
+	writel(tmp, base + reg);
+}
+
+
 static int meson_gpio_irq_get_index(struct meson_gpio_irq_domain *domain_data,
 				    int hwirq)
 {
@@ -135,11 +149,15 @@ static int meson_gpio_irq_set_type(struct irq_data *data, unsigned int type)
 
 	pr_debug("set type of hwirq %lu to %u\n", data->hwirq, type);
 
-	if ((type & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH)
-		return -EINVAL;
+	cd->flow_type = type;
 
 	if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
 		val |= REG_EDGE_POL_EDGE(cd->index);
+	/*
+	 * Take care of the dual polarity issue here, starting positive
+	 */
+	if ((type & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH)
+		type &= ~IRQ_TYPE_EDGE_FALLING;
 
 	if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_EDGE_FALLING)) {
 		val |= REG_EDGE_POL_LOW(cd->index);
@@ -162,11 +180,31 @@ static int meson_gpio_irq_set_type(struct irq_data *data, unsigned int type)
 	return irq_chip_set_type_parent(data, type);
 }
 
+static void meson_gpio_irq_eoi(struct irq_data *data)
+{
+	struct meson_gpio_irq_chip *cd = irq_data_get_irq_chip_data(data);
+
+	/*
+	 * To simulate IRQ_TYPE_EDGE_BOTH, change the polarity of the edge
+	 * after each interrupt.
+	 * Limitation:
+	 * 1) If the signal is initially high, the first falling edge will not
+	 *    be detected
+	 * 2) If the signal changes too quickly to detect all the edges, an
+	 *    additional edge might get lost.
+	 */
+	if ((cd->flow_type & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH)
+		meson_gpio_irq_flip_bits(cd->base, REG_EDGE_POL,
+					 REG_EDGE_POL_LOW(cd->index));
+
+	irq_chip_eoi_parent(data);
+}
+
 static struct irq_chip meson_gpio_irq_chip = {
 	.name			= "meson-gpio-irqchip",
 	.irq_mask		= irq_chip_mask_parent,
 	.irq_unmask		= irq_chip_unmask_parent,
-	.irq_eoi		= irq_chip_eoi_parent,
+	.irq_eoi		= meson_gpio_irq_eoi,
 	.irq_set_type		= meson_gpio_irq_set_type,
 	.irq_retrigger		= irq_chip_retrigger_hierarchy,
 #ifdef CONFIG_SMP
@@ -221,6 +259,7 @@ static int meson_gpio_irq_domain_alloc(struct irq_domain *domain,
 
 		cd->base = domain_data->base;
 		cd->index = index;
+		cd->flow_type = type;
 		fwspec_parent = &domain_data->parent_irqs[index];
 
 		irq_domain_set_hwirq_and_chip(domain, virq + i, hwirq + i,
-- 
2.7.4


      parent reply	other threads:[~2016-10-04 15:08 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-04 15:08 [RFC 00/10] irqchip: meson: add support for the gpio interrupt controller Jerome Brunet
2016-10-04 15:08 ` [RFC 06/10] ARM64: meson: enable MESON_IRQ_GPIO in Kconfig Jerome Brunet
     [not found] ` <1475593708-10526-1-git-send-email-jbrunet-rdvid1DuHRBWk0Htik3J/w@public.gmane.org>
2016-10-04 15:08   ` [RFC 01/10] irqchip: meson: add support for gpio interrupt controller Jerome Brunet
2016-10-04 15:08   ` [RFC 02/10] dt-bindings: interrupt-controller: add DT binding for meson GPIO " Jerome Brunet
2016-10-09  1:29     ` Rob Herring
2016-10-10  8:11       ` Jerome Brunet
2016-10-04 15:08   ` [RFC 03/10] pinctrl: meson: update pinctrl data with gpio irq base number Jerome Brunet
2016-10-04 15:08   ` [RFC 04/10] pinctrl: meson: allow gpio to request irq Jerome Brunet
2016-10-04 15:08   ` [RFC 05/10] dt-bindings: pinctrl: meson: update gpio dt-bindings Jerome Brunet
     [not found]     ` <1475593708-10526-6-git-send-email-jbrunet-rdvid1DuHRBWk0Htik3J/w@public.gmane.org>
2016-10-09  1:29       ` Rob Herring
2016-10-04 15:08   ` [RFC 07/10] ARM: meson: enable MESON_IRQ_GPIO in Kconfig for meson8 Jerome Brunet
2016-10-04 15:08   ` [RFC 09/10] ARM: dts: amlogic: enable gpio interrupt controller on meson8 Jerome Brunet
2016-10-04 15:08 ` [RFC 08/10] ARM64: dts: amlogic: enable gpio interrupt controller on gxbb Jerome Brunet
2016-10-04 15:08 ` Jerome Brunet [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1475593708-10526-11-git-send-email-jbrunet@baylibre.com \
    --to=jbrunet@baylibre.com \
    --cc=carlo@caione.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jason@lakedaemon.net \
    --cc=khilman@baylibre.com \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=marc.zyngier@arm.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).