linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* polarity inversion on LS1021a
@ 2017-12-04 15:11 Rasmus Villemoes
  2017-12-04 15:23 ` Marc Zyngier
  2017-12-04 15:31 ` polarity inversion on LS1021a Alexander Stein
  0 siblings, 2 replies; 39+ messages in thread
From: Rasmus Villemoes @ 2017-12-04 15:11 UTC (permalink / raw)
  To: LKML; +Cc: Thomas Gleixner, Marc Zyngier, Shawn Guo

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)

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

end of thread, other threads:[~2019-09-17  9:39 UTC | newest]

Thread overview: 39+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-04 15:11 polarity inversion on LS1021a Rasmus Villemoes
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

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).