devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V3 1/5] genirq: define flag IRQ_SRC_DST_INVERTED, and accessors
@ 2014-03-03 19:51 Stephen Warren
  2014-03-03 19:51 ` [PATCH V3 2/5] dt: define IRQ flags bit 4 as src/dst inversion Stephen Warren
                   ` (3 more replies)
  0 siblings, 4 replies; 14+ messages in thread
From: Stephen Warren @ 2014-03-03 19:51 UTC (permalink / raw)
  To: Thomas Gleixner, Samuel Ortiz, Lee Jones, Rob Herring, Pawel Moll,
	Mark Rutland, Ian Campbell, Kumar Gala
  Cc: devicetree, linux-kernel, linux-arm-kernel, linux-tegra,
	Stephen Warren

From: Stephen Warren <swarren@nvidia.com>

Some devices have configurable IRQ output polarities. Software might
use IRQ_TYPE_* to determine how to configure such a device's IRQ
output polarity in order to match how the IRQ controller input is
configured. If the board or SoC inverts the signal between the
device's IRQ output and controller's IRQ output, software must be
aware of this fact, in order to program the IRQ output to the correct
(i.e. opposite) polarity. This flag provides that information.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
---
v3: New patch.
---
 include/linux/irq.h    | 12 ++++++++++++
 kernel/irq/chip.c      | 24 ++++++++++++++++++++++++
 kernel/irq/irqdomain.c |  4 ++++
 3 files changed, 40 insertions(+)

diff --git a/include/linux/irq.h b/include/linux/irq.h
index 7dc10036eff5..535f3937e99e 100644
--- a/include/linux/irq.h
+++ b/include/linux/irq.h
@@ -73,6 +73,11 @@ typedef	void (*irq_preflow_handler_t)(struct irq_data *data);
  * IRQ_IS_POLLED		- Always polled by another interrupt. Exclude
  *				  it from the spurious interrupt detection
  *				  mechanism and from core side polling.
+ * IRQ_SRC_DST_INVERTED		- An inverter exists between the source's IRQ
+ *				  output, and the IRQ controller's input.
+ *				  For devices with programmable output polarity
+ *				  this helps the driver match the device output
+ *				  to the controller's input polarity.
  */
 enum {
 	IRQ_TYPE_NONE		= 0x00000000,
@@ -98,6 +103,7 @@ enum {
 	IRQ_NOTHREAD		= (1 << 16),
 	IRQ_PER_CPU_DEVID	= (1 << 17),
 	IRQ_IS_POLLED		= (1 << 18),
+	IRQ_SRC_DST_INVERTED	= (1 << 19),
 };
 
 #define IRQF_MODIFY_MASK	\
@@ -218,6 +224,11 @@ static inline u32 irqd_get_trigger_type(struct irq_data *d)
 	return d->state_use_accessors & IRQD_TRIGGER_MASK;
 }
 
+static inline u32 irqd_get_src_dst_inverted(struct irq_data *d)
+{
+	return d->state_use_accessors & IRQ_SRC_DST_INVERTED;
+}
+
 /*
  * Must only be called inside irq_chip.irq_set_type() functions.
  */
@@ -538,6 +549,7 @@ extern int irq_set_chip(unsigned int irq, struct irq_chip *chip);
 extern int irq_set_handler_data(unsigned int irq, void *data);
 extern int irq_set_chip_data(unsigned int irq, void *data);
 extern int irq_set_irq_type(unsigned int irq, unsigned int type);
+extern int irq_set_src_dst_inverted(unsigned int irq, unsigned int inverted);
 extern int irq_set_msi_desc(unsigned int irq, struct msi_desc *entry);
 extern int irq_set_msi_desc_off(unsigned int irq_base, unsigned int irq_offset,
 				struct msi_desc *entry);
diff --git a/kernel/irq/chip.c b/kernel/irq/chip.c
index dc04c166c54d..ff9e13fa1170 100644
--- a/kernel/irq/chip.c
+++ b/kernel/irq/chip.c
@@ -70,6 +70,30 @@ int irq_set_irq_type(unsigned int irq, unsigned int type)
 EXPORT_SYMBOL(irq_set_irq_type);
 
 /**
+ *	irq_set_src_dst_inverted(unsigned int irq, u32 inverted)
+ *	@irq:		irq number
+ *	@inverted:	IRQ_SRC_DST_INVERTED value - see include/linux/irq.h
+ */
+int irq_set_src_dst_inverted(unsigned int irq, unsigned int inverted)
+{
+	unsigned long flags;
+	struct irq_desc *desc = irq_get_desc_buslock(irq, &flags, IRQ_GET_DESC_CHECK_GLOBAL);
+	int ret = 0;
+
+	if (!desc)
+		return -EINVAL;
+
+	inverted &= IRQ_SRC_DST_INVERTED;
+	if (inverted)
+		irqd_set(&desc->irq_data, inverted);
+	else
+		irqd_clear(&desc->irq_data, inverted);
+	irq_put_desc_busunlock(desc, flags);
+	return ret;
+}
+EXPORT_SYMBOL(irq_set_src_dst_inverted);
+
+/**
  *	irq_set_handler_data - set irq handler data for an irq
  *	@irq:	Interrupt number
  *	@data:	Pointer to interrupt specific data
diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c
index f14033700c25..f9cee747424e 100644
--- a/kernel/irq/irqdomain.c
+++ b/kernel/irq/irqdomain.c
@@ -471,6 +471,7 @@ unsigned int irq_create_of_mapping(struct of_phandle_args *irq_data)
 	struct irq_domain *domain;
 	irq_hw_number_t hwirq;
 	unsigned int type = IRQ_TYPE_NONE;
+	unsigned int inverted = 0;
 	unsigned int virq;
 
 	domain = irq_data->np ? irq_find_host(irq_data->np) : irq_default_domain;
@@ -487,6 +488,8 @@ unsigned int irq_create_of_mapping(struct of_phandle_args *irq_data)
 		if (domain->ops->xlate(domain, irq_data->np, irq_data->args,
 					irq_data->args_count, &hwirq, &type))
 			return 0;
+		inverted = type & IRQ_SRC_DST_INVERTED;
+		type &= IRQ_TYPE_SENSE_MASK;
 	}
 
 	/* Create mapping */
@@ -498,6 +501,7 @@ unsigned int irq_create_of_mapping(struct of_phandle_args *irq_data)
 	if (type != IRQ_TYPE_NONE &&
 	    type != irq_get_trigger_type(virq))
 		irq_set_irq_type(virq, type);
+	irq_set_src_dst_inverted(virq, inverted);
 	return virq;
 }
 EXPORT_SYMBOL_GPL(irq_create_of_mapping);
-- 
1.8.1.5

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

end of thread, other threads:[~2014-04-11  2:44 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-03 19:51 [PATCH V3 1/5] genirq: define flag IRQ_SRC_DST_INVERTED, and accessors Stephen Warren
2014-03-03 19:51 ` [PATCH V3 2/5] dt: define IRQ flags bit 4 as src/dst inversion Stephen Warren
2014-03-03 19:51 ` [PATCH V3 3/5] irqchip: gic: parse IRQ specifier flag " Stephen Warren
     [not found] ` <1393876300-3061-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2014-03-03 19:51   ` [PATCH V3 4/5] mfd: palmas: support IRQ inversion at the board level Stephen Warren
2014-03-04  8:25     ` Lee Jones
     [not found]     ` <1393876300-3061-4-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2014-04-10  7:04       ` Alexandre Courbot
     [not found]         ` <CAAVeFuJY67zdoHiZufxDbkaw=xt8YwxyDAwHW_T7UZeSOt35NA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-04-10  7:25           ` Lee Jones
2014-04-10 15:42           ` Stephen Warren
     [not found]             ` <5346BBDF.4050901-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2014-04-11  2:44               ` Alexandre Courbot
2014-03-04 10:04   ` [PATCH V3 1/5] genirq: define flag IRQ_SRC_DST_INVERTED, and accessors Thomas Gleixner
     [not found]     ` <alpine.DEB.2.02.1403041018370.18573-3cz04HxQygjZikZi3RtOZ1XZhhPuCNm+@public.gmane.org>
2014-03-04 10:34       ` Thomas Gleixner
2014-03-04 15:57       ` Stephen Warren
2014-03-04 21:31         ` Thomas Gleixner
2014-03-03 19:51 ` [PATCH V3 5/5] ARM: tegra: fix Dalmore PMIC IRQ polarity Stephen Warren

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