mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Marc Zyngier <marc.zyngier@arm.com>,
	Shawn Guo <shawnguo@kernel.org>
Subject: polarity inversion on LS1021a
Date: Mon, 4 Dec 2017 16:11:06 +0100	[thread overview]
Message-ID: <67135504-72fb-ef7e-cac4-03331550a38d@prevas.dk> (raw)

The LS1021A has a standard GIC-400, but allows inverting the polarity of
six external interrupt lines via a certain register, effectively
supporting IRQ_TYPE_LEVEL_LOW and IRQ_TYPE_EDGE_FALLING for those.

I'm trying to figure out how one would add support for this. The patch
below works but is obviously just meant to help show what I mean, so
please don't comment on all the things that are wrong with it.

It feels wrong to create a whole new irqchip driver copy-pasting the
entire irg-gic.c, but I can't figure out how and where one could hook
into the existing one. Any pointers on how to do this properly will be
greatly appreciated.

Thanks,
Rasmus


diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
index 651d726e8b12..299710b7dd09 100644
--- a/drivers/irqchip/irq-gic.c
+++ b/drivers/irqchip/irq-gic.c
@@ -290,6 +290,48 @@ static int gic_irq_get_irqchip_state(struct
irq_data *d,
 	return 0;
 }

+static int gic_set_type_ls1_ext_irq_polarity(unsigned int gicirq,
+					     unsigned int *type)
+{
+	struct device_node *np;
+	void __iomem *scfg = NULL;
+	u32 polarity_mask = 0;
+	u32 intpcr;
+
+	np = of_find_compatible_node(NULL, NULL, "fsl,ls1021a-scfg");
+	if (!np)
+		return 0;
+
+	scfg = of_iomap(np, 0);
+	if (!scfg)
+		return -EINVAL;
+
+	switch (gicirq) {
+	case 195: polarity_mask = 0x80000000; break;
+	case 196: polarity_mask = 0x40000000; break;
+	case 197: polarity_mask = 0x20000000; break;
+	case 199: polarity_mask = 0x10000000; break;
+	case 200: polarity_mask = 0x08000000; break;
+	case 201: polarity_mask = 0x04000000; break;
+	}
+	if (!polarity_mask)
+		return 0;
+
+	intpcr = ioread32be(scfg + 0x1ac);
+
+	if (*type == IRQ_TYPE_LEVEL_LOW || *type == IRQ_TYPE_EDGE_FALLING)
+		iowrite32be(intpcr | polarity_mask, scfg + 0x1ac);
+	else
+		iowrite32be(intpcr & ~polarity_mask, scfg + 0x1ac);
+
+	if (*type == IRQ_TYPE_LEVEL_LOW)
+		*type = IRQ_TYPE_LEVEL_HIGH;
+	else if (*type == IRQ_TYPE_EDGE_FALLING)
+		*type = IRQ_TYPE_EDGE_RISING;
+
+	return 0;
+}
+
 static int gic_set_type(struct irq_data *d, unsigned int type)
 {
 	void __iomem *base = gic_dist_base(d);
@@ -299,6 +341,8 @@ static int gic_set_type(struct irq_data *d, unsigned
int type)
 	if (gicirq < 16)
 		return -EINVAL;

+	gic_set_type_ls1_ext_irq_polarity(gicirq, &type);
+
 	/* SPIs have restrictions on the supported types */
 	if (gicirq >= 32 && type != IRQ_TYPE_LEVEL_HIGH &&
 			    type != IRQ_TYPE_EDGE_RISING)

             reply	other threads:[~2017-12-04 15:11 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-04 15:11 Rasmus Villemoes [this message]
2017-12-04 15:23 ` Marc Zyngier
2017-12-08 14:33   ` [RFC] irqchip: add support for LS1021A external interrupt lines Rasmus Villemoes
2017-12-08 15:11     ` Alexander Stein
2017-12-08 16:09       ` Marc Zyngier
2017-12-11  9:08         ` Rasmus Villemoes
2017-12-11  9:45           ` Alexander Stein
2017-12-11 10:02             ` Alexander Stein
2017-12-11 13:45               ` Rasmus Villemoes
2017-12-11 14:06                 ` Rasmus Villemoes
2017-12-11 14:38                   ` Alexander Stein
2017-12-08 16:02     ` Marc Zyngier
2017-12-11  9:30       ` Rasmus Villemoes
2017-12-11 18:29         ` Marc Zyngier
2017-12-12 23:28     ` Rob Herring
2017-12-15 22:55       ` Rasmus Villemoes
2017-12-21 22:45         ` Rob Herring
2017-12-20  8:30     ` [PATCH v2 1/2] irqchip: add support for Layerscape " Rasmus Villemoes
2017-12-20  8:30       ` [PATCH v2 2/2] dt/bindings: Add bindings for Layerscape external irqs Rasmus Villemoes
2017-12-21 22:44         ` Rob Herring
2018-01-22  9:21       ` [PATCH v3 1/2] irqchip: add support for Layerscape external interrupt lines Rasmus Villemoes
2018-01-22  9:21         ` [PATCH v3 2/2] dt/bindings: Add bindings for Layerscape external irqs Rasmus Villemoes
2018-01-24 15:28           ` Marc Zyngier
2018-01-25 15:02         ` [PATCH v4 1/2] irqchip: add support for Layerscape external interrupt lines Rasmus Villemoes
2018-01-25 15:02           ` [PATCH v4 2/2] dt/bindings: Add bindings for Layerscape external irqs Rasmus Villemoes
2018-02-05  6:07             ` Rob Herring
2018-02-08 15:08               ` Rasmus Villemoes
2018-02-09  9:47                 ` Marc Zyngier
2018-02-23 21:08           ` [PATCH v5 0/2] irqchip: add support for Layerscape external interrupt lines Rasmus Villemoes
2018-02-23 21:08             ` [PATCH v5 1/2] " Rasmus Villemoes
2018-03-01 12:16               ` Thomas Gleixner
2018-05-04  7:44                 ` Rasmus Villemoes
2019-09-17  9:39                   ` Kurt Kanzenbach
2018-02-23 21:09             ` [PATCH v5 2/2] dt/bindings: Add bindings for Layerscape external irqs Rasmus Villemoes
2018-03-02 19:49               ` Rob Herring
2018-05-04  8:07                 ` Rasmus Villemoes
2017-12-04 15:31 ` polarity inversion on LS1021a Alexander Stein
2017-12-04 15:37   ` Marc Zyngier
2017-12-04 16:04     ` Alexander Stein

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=67135504-72fb-ef7e-cac4-03331550a38d@prevas.dk \
    --to=rasmus.villemoes@prevas.dk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marc.zyngier@arm.com \
    --cc=shawnguo@kernel.org \
    --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

all inboxes | Powered by JetHome®