Skip to contentSkip to conversation

Add Actions Semi Owl family sirq support

PATCH Superseded Cristian Ciocaltea 2 participants 8 messages Aug 16, 2020 – Aug 19, 2020

Subsystems (3)

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#7 lore raw

PATCH v4 3/3 MAINTAINERS: Add entries for Actions Semi Owl SIRQ controller

In reply to Cristian Ciocaltea

Add entries for Actions Semi Owl SIRQ controller binding and driver.

---
 MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)
MAINTAINERS +2 -0
index 87fa408d0f15..00eb0fb2eb68 100644
@@ -1518,6 +1518,7 @@ F:	Documentation/devicetree/bindings/arm/actions.yaml
 F:	Documentation/devicetree/bindings/clock/actions,owl-cmu.txt
 F:	Documentation/devicetree/bindings/dma/owl-dma.txt
 F:	Documentation/devicetree/bindings/i2c/i2c-owl.txt
+F:	Documentation/devicetree/bindings/interrupt-controller/actions,owl-sirq.yaml
 F:	Documentation/devicetree/bindings/mmc/owl-mmc.yaml
 F:	Documentation/devicetree/bindings/pinctrl/actions,*
 F:	Documentation/devicetree/bindings/power/actions,owl-sps.txt
@@ -1529,6 +1530,7 @@ F:	drivers/clk/actions/
 F:	drivers/clocksource/timer-owl*
 F:	drivers/dma/owl-dma.c
 F:	drivers/i2c/busses/i2c-owl.c
+F:	drivers/irqchip/irq-owl-sirq.c
 F:	drivers/mmc/host/owl-mmc.c
 F:	drivers/pinctrl/actions/*
 F:	drivers/soc/actions/
Signature · 7 lines
2.28.0


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#0 lore raw

v4 cover Add Actions Semi Owl family sirq support

This patch series adds support for the external interrupt controller (SIRQ) found in Actions Semi Owl famil of SoC's (S500, S700 and S900). The controller allows connecting up to 3 external interrupt controllers through dedicated SIRQ pins.

This is a rework of the patch series submitted some time ago by Parthiban Nallathambi:
https://lore.kernel.org/lkml/[email protected]/

Please note I have dropped, for the moment, the S700 related patches since I do not own a compatible hardware for testing. I'm using, instead, an S500 SoC based board for which I have already provided an initial support:
https://lore.kernel.org/lkml/[email protected]/

The SIRQ controller support is a prerequisite of the soon to be submitted MFD driver for the Actions Semi ATC260x PMICs.

Thanks and regards,
Cristi

Changes in v4:
- Simplified the DTS structure:
* dropped 'actions,sirq-shared-reg' node, now the differentiation between SoC variants is handled now via the compatible property
* dropped 'actions,sirq-reg-offset', now controller base address in DTS points to SIRQ0 register, so no additional information is required for S500 and S700, while for S900 SoC the offsets of SIRQ1 and SIRQ2 regs are provided by the driver
* 'actions,ext-irq-range' was replaced with 'actions,ext-interrupts', an array of the GIC interrupts triggered by the controller
- Fixed wrong INTC_EXTCTL_TYPE_MASK definition
- Removed redundant irq_fwspec checks in owl_sirq_domain_alloc()
- Improved error handling in owl_sirq_of_init()
- Added yaml binding document
- Dropped S700 related DTS patches for lack of testing hardware:
* arm64: dts: actions: Add sirq node for Actions Semi S700
* arm64: dts: actions: s700-cubieboard7: Enable SIRQ
- Updated MAINTAINERS
- Rebased patchset on kernel v5.8
- Cosmetic changes
* Ordered include statements alphabetically
* Added comment to owl_sirq_set_type() describing conversion of falling edge or active low signals
* Replaced IRQF_TRIGGER_* with corresponding IRQ_TYPE_* variants
* Ensured data types and function naming are consistent regarding the 'owl_sirq' prefix

Changes in v3 (Parthiban Nallathambi):
- Set default operating frequency to 24MHz
- Falling edge and Low Level interrupts translated to rising edge and high level
- Introduced common function with lock handling for register read and write
- Used direct GIC interrupt number for interrupt local hwirq and finding offset using DT entry (range) when registers are shared
- Changed irq_ack to irq_eoi
- Added translation method for irq_domain_ops
- Clearing interrupt pending based on bitmask for edge triggered
- Added pinctrl definition for sirq for cubieboard7. This depends on,
https://lore.kernel.org/patchwork/patch/1012859/

Changes in v2 (Parthiban Nallathambi):
- Added SIRQ as hierarchical chip

        GIC <----> SIRQ <----> External interrupt controller/Child devices

- Device binding updates with vendor prefix
- Register sharing handled globally and common init sequence/data for all actions SoC family

Cristian Ciocaltea (3):
dt-bindings: interrupt-controller: Add Actions SIRQ controller binding
irqchip: Add Actions Semi Owl SIRQ controller
MAINTAINERS: Add entries for Actions Semi Owl SIRQ controller

 .../actions,owl-sirq.yaml                     |  69 ++++
 MAINTAINERS                                   |   2 +
 drivers/irqchip/Makefile                      |   1 +
 drivers/irqchip/irq-owl-sirq.c                | 318 ++++++++++++++++++
 4 files changed, 390 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/interrupt-controller/actions,owl-sirq.yaml
 create mode 100644 drivers/irqchip/irq-owl-sirq.c
Signature · 7 lines
2.28.0


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#1 lore raw

PATCH v4 1/3 dt-bindings: interrupt-controller: Add Actions SIRQ controller binding

Actions Semi Owl SoCs SIRQ interrupt controller is found in S500, S700 and S900 SoCs and provides support for connecting up to 3 independent external interrupt controllers through dedicated SIRQ pins.

---
 .../actions,owl-sirq.yaml                     | 69 +++++++++++++++++++
 1 file changed, 69 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/interrupt-controller/actions,owl-sirq.yaml
Documentation/devicetree/bindings/interrupt-controller/actions,owl-sirq.yaml new file +69 -0
new file mode 100644
index 000000000000..b9903f9d7449
@@ -0,0 +1,69 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/interrupt-controller/actions,owl-sirq.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Actions Semi Owl SoCs SIRQ interrupt controller
+
+maintainers:
+  - Manivannan Sadhasivam <[email protected]>
+  - Cristian Ciocaltea <[email protected]>
+
+description: |
+  This interrupt controller is found in the Actions Semi Owl SoCs (S500, S700
+  and S900) and provides support for connecting up to 3 independent external
+  interrupt controllers through SIRQ0, SIRQ1 and SIRQ2 pins.
+
+properties:
+  compatible:
+    oneOf:
+      - items:
+        - enum:
+          - actions,s500-sirq
+          - actions,s700-sirq
+          - actions,s900-sirq
+        - const: actions,owl-sirq
+      - const: actions,owl-sirq
+
+  reg:
+    maxItems: 1
+
+  interrupt-controller: true
+
+  '#interrupt-cells':
+    const: 2
+    description:
+      The first cell is the input IRQ number, between 0 and 2, while the second
+      cell is the trigger type as defined in interrupt.txt in this directory.
+
+  'actions,ext-interrupts':
+    description: |
+      Contains the GIC SPI IRQ numbers mapped to the external interrupt
+      lines. They shall be specified sequentially from output 0 to 2.
+    $ref: /schemas/types.yaml#/definitions/uint32-array
+    minItems: 3
+    maxItems: 3
+
+required:
+  - compatible
+  - reg
+  - interrupt-controller
+  - '#interrupt-cells'
+  - 'actions,ext-interrupts'
+
+additionalProperties: false
+
+examples:
+  - |
+    sirq: interrupt-controller@b01b0200 {
+      compatible = "actions,s500-sirq", "actions,owl-sirq";
+      reg = <0xb01b0200 0x4>;
+      interrupt-controller;
+      #interrupt-cells = <2>;
+      actions,ext-interrupts = <13>, /* SIRQ0 */
+                               <14>, /* SIRQ1 */
+                               <15>; /* SIRQ2 */
+    };
+
+...
Signature · 7 lines
2.28.0


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#2 lore raw

PATCH v4 2/3 irqchip: Add Actions Semi Owl SIRQ controller

In reply to Cristian Ciocaltea

This controller appears on Actions Semi Owl family SoC's S500, S700 and S900 and provides support for 3 external interrupt controllers through dedicated SIRQ pins.

Each line can be independently configured as interrupt and triggers on either of the edges (raising or falling) or either of the levels (high or low). Each line can also be masked independently.

This is based on the patch series submitted by Parthiban Nallathambi:
https://lore.kernel.org/lkml/[email protected]/

[cristi: optimized DT, various fixes/cleanups/improvements]
---
 drivers/irqchip/Makefile       |   1 +
 drivers/irqchip/irq-owl-sirq.c | 318 +++++++++++++++++++++++++++++++++
 2 files changed, 319 insertions(+)
 create mode 100644 drivers/irqchip/irq-owl-sirq.c
drivers/irqchip/Makefile +1 -0
index 133f9c45744a..b8eb5b8b766d 100644
@@ -7,6 +7,7 @@ obj-$(CONFIG_ATH79)			+= irq-ath79-cpu.o
 obj-$(CONFIG_ATH79)			+= irq-ath79-misc.o
 obj-$(CONFIG_ARCH_BCM2835)		+= irq-bcm2835.o
 obj-$(CONFIG_ARCH_BCM2835)		+= irq-bcm2836.o
+obj-$(CONFIG_ARCH_ACTIONS)		+= irq-owl-sirq.o
 obj-$(CONFIG_DAVINCI_AINTC)		+= irq-davinci-aintc.o
 obj-$(CONFIG_DAVINCI_CP_INTC)		+= irq-davinci-cp-intc.o
 obj-$(CONFIG_EXYNOS_IRQ_COMBINER)	+= exynos-combiner.o
drivers/irqchip/irq-owl-sirq.c new file +318 -0

318 lines not on this page · raw message

Signature · 7 lines
2.28.0


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#3 lore raw

Re: [PATCH v4 2/3] irqchip: Add Actions Semi Owl SIRQ controller

Quoted 2 lines · Cristian Ciocaltea

This controller appears on Actions Semi Owl family SoC's S500, S700 and S900 and provides support for 3 external interrupt controllers through

Is that really 3 interrupt controllers? Or merely 3 interrupt lines?

Quoted 72 lines

dedicated SIRQ pins.

Each line can be independently configured as interrupt and triggers on either of the edges (raising or falling) or either of the levels (high or low). Each line can also be masked independently.

This is based on the patch series submitted by Parthiban Nallathambi:
https://lore.kernel.org/lkml/[email protected]/

[cristi: optimized DT, various fixes/cleanups/improvements]
---
 drivers/irqchip/Makefile       |   1 +
 drivers/irqchip/irq-owl-sirq.c | 318 +++++++++++++++++++++++++++++++++
 2 files changed, 319 insertions(+)
 create mode 100644 drivers/irqchip/irq-owl-sirq.c
drivers/irqchip/Makefile +1 -0
index 133f9c45744a..b8eb5b8b766d 100644
@@ -7,6 +7,7 @@ obj-$(CONFIG_ATH79)			+= irq-ath79-cpu.o
 obj-$(CONFIG_ATH79)			+= irq-ath79-misc.o
 obj-$(CONFIG_ARCH_BCM2835)		+= irq-bcm2835.o
 obj-$(CONFIG_ARCH_BCM2835)		+= irq-bcm2836.o
+obj-$(CONFIG_ARCH_ACTIONS)		+= irq-owl-sirq.o
 obj-$(CONFIG_DAVINCI_AINTC)		+= irq-davinci-aintc.o
 obj-$(CONFIG_DAVINCI_CP_INTC)		+= irq-davinci-cp-intc.o
 obj-$(CONFIG_EXYNOS_IRQ_COMBINER)	+= exynos-combiner.o
drivers/irqchip/irq-owl-sirq.c new file +35 -0
new file mode 100644
index 000000000000..29b7ffc40ac7
@@ -0,0 +1,318 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Actions Semi Owl SoCs SIRQ interrupt controller driver
+ *
+ * Copyright (C) 2014 Actions Semi Inc.
+ * David Liu <[email protected]>
+ *
+ * Author: Parthiban Nallathambi <[email protected]>
+ * Author: Saravanan Sekar <[email protected]>
+ * Author: Cristian Ciocaltea <[email protected]>
+ */
+
+#include <linux/interrupt.h>
+#include <linux/irqchip.h>
+#include <linux/of_address.h>
+#include <linux/of_irq.h>
+
+#define NUM_SIRQ			3
+
+#define INTC_EXTCTL_PENDING		BIT(0)
+#define INTC_EXTCTL_CLK_SEL		BIT(4)
+#define INTC_EXTCTL_EN			BIT(5)
+#define INTC_EXTCTL_TYPE_MASK		GENMASK(7, 6)
+#define INTC_EXTCTL_TYPE_HIGH		0
+#define INTC_EXTCTL_TYPE_LOW		BIT(6)
+#define INTC_EXTCTL_TYPE_RISING		BIT(7)
+#define INTC_EXTCTL_TYPE_FALLING	(BIT(6) | BIT(7))
+
+/* S900 SIRQ1 & SIRQ2 control register offsets, relative to SIRQ0 */
+#define INTC_EXTCTL1			0x0328
+#define INTC_EXTCTL2			0x032c
+
+struct owl_sirq_params {
+	/* INTC_EXTCTL reg shared for all three SIRQ lines */
+	bool reg_shared;

drivers/irqchip/irq-owl-sirq.c line 45

Quoted 10 lines
drivers/irqchip/irq-owl-sirq.c new file +10 -0
+	/* INTC_EXTCTL reg offsets relative to controller base address */
+	u16 reg_offset[NUM_SIRQ];
+};
+
+struct owl_sirq_chip_data {
+	const struct owl_sirq_params *params;
+	void __iomem *base;
+	raw_spinlock_t lock;
+	u32 ext_irqs[NUM_SIRQ];
+	u8 trigger;

Nit: Please align data structure members vertically:

struct owl_sirq_chip_data {
	const struct owl_sirq_params *params;
	void __iomem                 *base;
	raw_spinlock_t               lock;
	u32                          ext_irqs[NUM_SIRQ];
	u8                           trigger;
};

drivers/irqchip/irq-owl-sirq.c line 57

Quoted 12 lines
drivers/irqchip/irq-owl-sirq.c new file +12 -0
+};
+
+/* S500 and S700 SoCs */
+static const struct owl_sirq_params owl_sirq_s500_params = {
+	.reg_shared = true,
+	.reg_offset = { 0, 0, 0 },
+};
+
+/* S900 SoC */
+static const struct owl_sirq_params owl_sirq_s900_params = {
+	.reg_shared = false,
+	.reg_offset = { 0, INTC_EXTCTL1, INTC_EXTCTL2 },

0 *is* an offset, right? Why doesn't it have a name too?

drivers/irqchip/irq-owl-sirq.c line 66

Quoted 10 lines
drivers/irqchip/irq-owl-sirq.c new file +3 -0
+};
+
+static u32 owl_sirq_read_extctl(struct owl_sirq_chip_data *data, u32 

index)

drivers/irqchip/irq-owl-sirq.c new file +6 -0
+{
+	u32 val;
+
+	val = readl_relaxed(data->base + data->params->reg_offset[index]);
+	if (data->params->reg_shared)
+		val = (val >> (2 - index) * 8) & 0xff;
        base = (2 - index) * 8;
        val = FIELD_GET(GENMASK(base + 7, base), val);
Quoted 4 lines
drivers/irqchip/irq-owl-sirq.c new file +4 -0
+
+	return val;
+}
+

drivers/irqchip/irq-owl-sirq.c line 80

Quoted 10 lines
drivers/irqchip/irq-owl-sirq.c new file +10 -0
+static void owl_sirq_write_extctl(struct owl_sirq_chip_data *data,
+				  u32 extctl, u32 index)
+{
+	u32 val;
+
+	if (data->params->reg_shared) {
+		val = readl_relaxed(data->base + data->params->reg_offset[index]);
+		val &= ~(0xff << (2 - index) * 8);
+		extctl &= 0xff;
+		extctl = (extctl << (2 - index) * 8) | val;

Please make use of FIELD_PREP, FIELD_GET and GENMASK.

Quoted 27 lines
drivers/irqchip/irq-owl-sirq.c new file +22 -0
+	}
+
+	writel_relaxed(extctl, data->base + data->params->reg_offset[index]);
+}
+
+static void owl_sirq_clear_set_extctl(struct owl_sirq_chip_data *d,
+				      u32 clear, u32 set, u32 index)
+{
+	unsigned long flags;
+	u32 val;
+
+	raw_spin_lock_irqsave(&d->lock, flags);
+	val = owl_sirq_read_extctl(d, index);
+	val &= ~clear;
+	val |= set;
+	owl_sirq_write_extctl(d, val, index);
+	raw_spin_unlock_irqrestore(&d->lock, flags);
+}
+
+static void owl_sirq_eoi(struct irq_data *data)
+{
+	struct owl_sirq_chip_data *chip_data = 

irq_data_get_irq_chip_data(data);

drivers/irqchip/irq-owl-sirq.c new file +3 -0
+
+	/*
+	 * Software must clear external interrupt pending, when interrupt 

type

drivers/irqchip/irq-owl-sirq.c line 108

Quoted 3 lines
drivers/irqchip/irq-owl-sirq.c new file +3 -0
+	 * is edge triggered, so we need per SIRQ based clearing.
+	 */
+	if (chip_data->trigger & (1 << data->hwirq))

BIT(d->hwirq)

But it also begs the question: we already have all the trigger information in the irqdesc. Why do you need some additional bookkeeping?

Quoted 46 lines
drivers/irqchip/irq-owl-sirq.c new file +9 -0
+		owl_sirq_clear_set_extctl(chip_data, 0, INTC_EXTCTL_PENDING,
+					  data->hwirq);
+
+	irq_chip_eoi_parent(data);
+}
+
+static void owl_sirq_mask(struct irq_data *data)
+{
+	struct owl_sirq_chip_data *chip_data = 

irq_data_get_irq_chip_data(data);

drivers/irqchip/irq-owl-sirq.c new file +8 -0
+
+	owl_sirq_clear_set_extctl(chip_data, INTC_EXTCTL_EN, 0, data->hwirq);
+	irq_chip_mask_parent(data);
+}
+
+static void owl_sirq_unmask(struct irq_data *data)
+{
+	struct owl_sirq_chip_data *chip_data = 

irq_data_get_irq_chip_data(data);

drivers/irqchip/irq-owl-sirq.c new file +13 -0
+
+	owl_sirq_clear_set_extctl(chip_data, 0, INTC_EXTCTL_EN, data->hwirq);
+	irq_chip_unmask_parent(data);
+}
+
+/*
+ * GIC does not handle falling edge or active low, hence SIRQ shall be
+ * programmed to convert falling edge to rising edge signal and active
+ * low to active high signal.
+ */
+static int owl_sirq_set_type(struct irq_data *data, unsigned int type)
+{
+	struct owl_sirq_chip_data *chip_data = 

irq_data_get_irq_chip_data(data);

drivers/irqchip/irq-owl-sirq.c new file +13 -0
+	u32 sirq_type;
+
+	switch (type) {
+	case IRQ_TYPE_LEVEL_LOW:
+		sirq_type = INTC_EXTCTL_TYPE_LOW;
+		chip_data->trigger &= ~(1 << data->hwirq);
+		type = IRQ_TYPE_LEVEL_HIGH;
+		break;
+	case IRQ_TYPE_LEVEL_HIGH:
+		sirq_type = INTC_EXTCTL_TYPE_HIGH;
+		chip_data->trigger &= ~(1 << data->hwirq);
+		break;
+	case IRQ_TYPE_EDGE_FALLING:

drivers/irqchip/irq-owl-sirq.c line 161

Quoted 10 lines
drivers/irqchip/irq-owl-sirq.c new file +10 -0
+		sirq_type = INTC_EXTCTL_TYPE_FALLING;
+		chip_data->trigger |= 1 << data->hwirq;
+		type = IRQ_TYPE_EDGE_RISING;
+		break;
+	case IRQ_TYPE_EDGE_RISING:
+		sirq_type = INTC_EXTCTL_TYPE_RISING;
+		chip_data->trigger |= 1 << data->hwirq;
+		break;
+	default:
+		WARN_ON(1);

No need for this WARN_ON(), the core kernel is loud enough.

Quoted 7 lines
drivers/irqchip/irq-owl-sirq.c new file +4 -0
+		return -EINVAL;
+	}
+
+	owl_sirq_clear_set_extctl(chip_data, INTC_EXTCTL_TYPE_MASK, 

sirq_type,

drivers/irqchip/irq-owl-sirq.c new file +2 -0
+				  data->hwirq);
+

drivers/irqchip/irq-owl-sirq.c line 177

Quoted 10 lines
drivers/irqchip/irq-owl-sirq.c new file +10 -0
+	return irq_chip_set_type_parent(data, type);
+}
+
+static struct irq_chip owl_sirq_chip = {
+	.name		= "owl-sirq",
+	.irq_mask	= owl_sirq_mask,
+	.irq_unmask	= owl_sirq_unmask,
+	.irq_eoi	= owl_sirq_eoi,
+	.irq_set_type	= owl_sirq_set_type,
+	.irq_retrigger	= irq_chip_retrigger_hierarchy,

How about irq_set_affinity? Or does it only exist on UP systems?

Quoted 133 lines
drivers/irqchip/irq-owl-sirq.c new file +20 -0
+};
+
+static int owl_sirq_domain_translate(struct irq_domain *d,
+				     struct irq_fwspec *fwspec,
+				     unsigned long *hwirq,
+				     unsigned int *type)
+{
+	if (!is_of_node(fwspec->fwnode))
+		return -EINVAL;
+
+	if (fwspec->param_count != 2 || fwspec->param[0] >= NUM_SIRQ)
+		return -EINVAL;
+
+	*hwirq = fwspec->param[0];
+	*type = fwspec->param[1];
+
+	return 0;
+}
+
+static int owl_sirq_domain_alloc(struct irq_domain *domain, unsigned 

int virq,

drivers/irqchip/irq-owl-sirq.c new file +91 -0
+				 unsigned int nr_irqs, void *data)
+{
+	struct owl_sirq_chip_data *chip_data = domain->host_data;
+	struct irq_fwspec *fwspec = data;
+	struct irq_fwspec parent_fwspec;
+	irq_hw_number_t hwirq;
+	unsigned int type;
+	int ret;
+
+	if (WARN_ON(nr_irqs != 1))
+		return -EINVAL;
+
+	ret = owl_sirq_domain_translate(domain, fwspec, &hwirq, &type);
+	if (ret)
+		return ret;
+
+	switch (type) {
+	case IRQ_TYPE_EDGE_RISING:
+	case IRQ_TYPE_LEVEL_HIGH:
+		break;
+	case IRQ_TYPE_EDGE_FALLING:
+		type = IRQ_TYPE_EDGE_RISING;
+		break;
+	case IRQ_TYPE_LEVEL_LOW:
+		type = IRQ_TYPE_LEVEL_HIGH;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	irq_domain_set_hwirq_and_chip(domain, virq, hwirq, &owl_sirq_chip,
+				      chip_data);
+
+	parent_fwspec.fwnode = domain->parent->fwnode;
+	parent_fwspec.param_count = 3;
+	parent_fwspec.param[0] = 0;	/* SPI */
+	parent_fwspec.param[1] = chip_data->ext_irqs[hwirq];
+	parent_fwspec.param[2] = type;
+
+	return irq_domain_alloc_irqs_parent(domain, virq, 1, &parent_fwspec);
+}
+
+static const struct irq_domain_ops owl_sirq_domain_ops = {
+	.translate	= owl_sirq_domain_translate,
+	.alloc		= owl_sirq_domain_alloc,
+	.free		= irq_domain_free_irqs_common,
+};
+
+static const struct of_device_id owl_sirq_of_match[] = {
+	{ .compatible = "actions,s500-sirq", .data = &owl_sirq_s500_params },
+	{ .compatible = "actions,s700-sirq", .data = &owl_sirq_s500_params },
+	{ .compatible = "actions,s900-sirq", .data = &owl_sirq_s900_params },
+	{ /* sentinel */ }
+};
+
+static int __init owl_sirq_of_init(struct device_node *node,
+				   struct device_node *parent)
+{
+	const struct of_device_id *match;
+	struct irq_domain *domain, *parent_domain;
+	struct owl_sirq_chip_data *chip_data;
+	int ret, i;
+
+	parent_domain = irq_find_host(parent);
+	if (!parent_domain) {
+		pr_err("%pOF: failed to find sirq parent domain\n", node);
+		return -ENXIO;
+	}
+
+	chip_data = kzalloc(sizeof(*chip_data), GFP_KERNEL);
+	if (!chip_data)
+		return -ENOMEM;
+
+	match = of_match_node(owl_sirq_of_match, node);
+	if (!match) {
+		pr_warn("owl-sirq: assuming S500/S700 compatible controller\n");
+		chip_data->params = &owl_sirq_s500_params;
+	} else {
+		chip_data->params = match->data;
+	}
+
+	raw_spin_lock_init(&chip_data->lock);
+
+	chip_data->base = of_iomap(node, 0);
+	if (!chip_data->base) {
+		pr_err("%pOF: failed to map sirq registers\n", node);
+		ret = -ENXIO;
+		goto out_free;
+	}
+
+	ret = of_property_read_variable_u32_array(node, 

"actions,ext-interrupts",

drivers/irqchip/irq-owl-sirq.c new file +20 -0
+						  chip_data->ext_irqs,
+						  NUM_SIRQ, NUM_SIRQ);
+	if (ret < NUM_SIRQ) {
+		pr_err("%pOF: failed to read sirq interrupts\n", node);
+		goto out_unmap;
+	}
+
+	/* Set 24MHz external interrupt clock freq */
+	for (i = 0; i < NUM_SIRQ; i++)
+		owl_sirq_clear_set_extctl(chip_data, 0, INTC_EXTCTL_CLK_SEL, i);
+
+	domain = irq_domain_add_hierarchy(parent_domain, 0, NUM_SIRQ, node,
+					  &owl_sirq_domain_ops, chip_data);
+	if (!domain) {
+		pr_err("%pOF: failed to add domain\n", node);
+		ret = -ENOMEM;
+		goto out_unmap;
+	}
+
+	return 0;

drivers/irqchip/irq-owl-sirq.c line 318

Quoted 10 lines
drivers/irqchip/irq-owl-sirq.c new file +10 -0
+
+out_unmap:
+	iounmap(chip_data->base);
+out_free:
+	kfree(chip_data);
+
+	return ret;
+}
+
+IRQCHIP_DECLARE(owl_sirq, "actions,owl-sirq", owl_sirq_of_init);

Thanks,

        M.
Signature · 1 line
Jazz is not dead. It just smells funny...
#4 lore raw

Re: [PATCH v4 2/3] irqchip: Add Actions Semi Owl SIRQ controller

Hi Marc,

Thanks for your quick and detailed review!

Quoted 5 lines · Marc Zyngier
Quoted 2 lines · Cristian Ciocaltea

This controller appears on Actions Semi Owl family SoC's S500, S700 and S900 and provides support for 3 external interrupt controllers through

Is that really 3 interrupt controllers? Or merely 3 interrupt lines?

This is mostly a leftover statement from the previous patch revision. I will change it to something like:

"This interrupt controller is found in the Actions Semi Owl SoCs (S500, S700 and S900) and provides support for handling up to 3 external interrupt lines."

Quoted 86 lines
Quoted 73 lines

dedicated SIRQ pins.

Each line can be independently configured as interrupt and triggers on either of the edges (raising or falling) or either of the levels (high or low). Each line can also be masked independently.

This is based on the patch series submitted by Parthiban Nallathambi:
https://lore.kernel.org/lkml/[email protected]/

[cristi: optimized DT, various fixes/cleanups/improvements]
---
 drivers/irqchip/Makefile       |   1 +
 drivers/irqchip/irq-owl-sirq.c | 318 +++++++++++++++++++++++++++++++++
 2 files changed, 319 insertions(+)
 create mode 100644 drivers/irqchip/irq-owl-sirq.c
drivers/irqchip/Makefile +1 -0
index 133f9c45744a..b8eb5b8b766d 100644
@@ -7,6 +7,7 @@ obj-$(CONFIG_ATH79)			+= irq-ath79-cpu.o
 obj-$(CONFIG_ATH79)			+= irq-ath79-misc.o
 obj-$(CONFIG_ARCH_BCM2835)		+= irq-bcm2835.o
 obj-$(CONFIG_ARCH_BCM2835)		+= irq-bcm2836.o
+obj-$(CONFIG_ARCH_ACTIONS)		+= irq-owl-sirq.o
 obj-$(CONFIG_DAVINCI_AINTC)		+= irq-davinci-aintc.o
 obj-$(CONFIG_DAVINCI_CP_INTC)		+= irq-davinci-cp-intc.o
 obj-$(CONFIG_EXYNOS_IRQ_COMBINER)	+= exynos-combiner.o
drivers/irqchip/irq-owl-sirq.c new file +35 -0
new file mode 100644
index 000000000000..29b7ffc40ac7
@@ -0,0 +1,318 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Actions Semi Owl SoCs SIRQ interrupt controller driver
+ *
+ * Copyright (C) 2014 Actions Semi Inc.
+ * David Liu <[email protected]>
+ *
+ * Author: Parthiban Nallathambi <[email protected]>
+ * Author: Saravanan Sekar <[email protected]>
+ * Author: Cristian Ciocaltea <[email protected]>
+ */
+
+#include <linux/interrupt.h>
+#include <linux/irqchip.h>
+#include <linux/of_address.h>
+#include <linux/of_irq.h>
+
+#define NUM_SIRQ			3
+
+#define INTC_EXTCTL_PENDING		BIT(0)
+#define INTC_EXTCTL_CLK_SEL		BIT(4)
+#define INTC_EXTCTL_EN			BIT(5)
+#define INTC_EXTCTL_TYPE_MASK		GENMASK(7, 6)
+#define INTC_EXTCTL_TYPE_HIGH		0
+#define INTC_EXTCTL_TYPE_LOW		BIT(6)
+#define INTC_EXTCTL_TYPE_RISING		BIT(7)
+#define INTC_EXTCTL_TYPE_FALLING	(BIT(6) | BIT(7))
+
+/* S900 SIRQ1 & SIRQ2 control register offsets, relative to SIRQ0 */
+#define INTC_EXTCTL1			0x0328
+#define INTC_EXTCTL2			0x032c
+
+struct owl_sirq_params {
+	/* INTC_EXTCTL reg shared for all three SIRQ lines */
+	bool reg_shared;

drivers/irqchip/irq-owl-sirq.c line 45

Quoted 10 lines
drivers/irqchip/irq-owl-sirq.c new file +10 -0
+	/* INTC_EXTCTL reg offsets relative to controller base address */
+	u16 reg_offset[NUM_SIRQ];
+};
+
+struct owl_sirq_chip_data {
+	const struct owl_sirq_params *params;
+	void __iomem *base;
+	raw_spinlock_t lock;
+	u32 ext_irqs[NUM_SIRQ];
+	u8 trigger;

Nit: Please align data structure members vertically:

Quoted 7 lines
struct owl_sirq_chip_data {
	const struct owl_sirq_params *params;
	void __iomem                 *base;
	raw_spinlock_t               lock;
	u32                          ext_irqs[NUM_SIRQ];
	u8                           trigger;
};

Done.

Quoted 6 lines
Quoted 6 lines
drivers/irqchip/irq-owl-sirq.c new file +6 -0
+};
+
+/* S500 and S700 SoCs */
+static const struct owl_sirq_params owl_sirq_s500_params = {
+	.reg_shared = true,
+	.reg_offset = { 0, 0, 0 },
Quoted 8 lines

drivers/irqchip/irq-owl-sirq.c line 57

Quoted 6 lines
drivers/irqchip/irq-owl-sirq.c new file +6 -0
+};
+
+/* S900 SoC */
+static const struct owl_sirq_params owl_sirq_s900_params = {
+	.reg_shared = false,
+	.reg_offset = { 0, INTC_EXTCTL1, INTC_EXTCTL2 },

0 *is* an offset, right? Why doesn't it have a name too?

Right, I updated the defines section:

/* S900 SIRQ control register offsets, relative to controller base address */
#define INTC_EXTCTL0 0x0000
#define INTC_EXTCTL1 0x0328
[...]

The controller base address points to SIRQ0 control register, so this offset is always 0, but I totally agree we should have a name for it.

Quoted 5 lines
Quoted 5 lines
drivers/irqchip/irq-owl-sirq.c new file +3 -0
+};
+
+static u32 owl_sirq_read_extctl(struct owl_sirq_chip_data *data, u32

index)
+{

Quoted 8 lines

drivers/irqchip/irq-owl-sirq.c line 66

Quoted 5 lines
drivers/irqchip/irq-owl-sirq.c new file +5 -0
+	u32 val;
+
+	val = readl_relaxed(data->base + data->params->reg_offset[index]);
+	if (data->params->reg_shared)
+		val = (val >> (2 - index) * 8) & 0xff;
        base = (2 - index) * 8;
        val = FIELD_GET(GENMASK(base + 7, base), val);

Unfortunately the context doesn't allow using FIELD_GET:

./include/linux/compiler.h:392:38: error: call to ‘__compiletime_assert_159’
declared with attribute error: FIELD_GET: mask is not constant

Quoted 8 lines
Quoted 8 lines
drivers/irqchip/irq-owl-sirq.c new file +8 -0
+
+	return val;
+}
+
+static void owl_sirq_write_extctl(struct owl_sirq_chip_data *data,
+				  u32 extctl, u32 index)
+{
+	u32 val;
Quoted 8 lines

drivers/irqchip/irq-owl-sirq.c line 80

Quoted 6 lines
drivers/irqchip/irq-owl-sirq.c new file +6 -0
+
+	if (data->params->reg_shared) {
+		val = readl_relaxed(data->base + data->params->reg_offset[index]);
+		val &= ~(0xff << (2 - index) * 8);
+		extctl &= 0xff;
+		extctl = (extctl << (2 - index) * 8) | val;

Please make use of FIELD_PREP, FIELD_GET and GENMASK.

I'm not sure how to deal with the mask constness restriction, except using static defines and if/else statements, which is not quite elegant.

Quoted 32 lines
Quoted 23 lines
drivers/irqchip/irq-owl-sirq.c new file +22 -0
+	}
+
+	writel_relaxed(extctl, data->base + data->params->reg_offset[index]);
+}
+
+static void owl_sirq_clear_set_extctl(struct owl_sirq_chip_data *d,
+				      u32 clear, u32 set, u32 index)
+{
+	unsigned long flags;
+	u32 val;
+
+	raw_spin_lock_irqsave(&d->lock, flags);
+	val = owl_sirq_read_extctl(d, index);
+	val &= ~clear;
+	val |= set;
+	owl_sirq_write_extctl(d, val, index);
+	raw_spin_unlock_irqrestore(&d->lock, flags);
+}
+
+static void owl_sirq_eoi(struct irq_data *data)
+{
+	struct owl_sirq_chip_data *chip_data =

irq_data_get_irq_chip_data(data);

drivers/irqchip/irq-owl-sirq.c line 108

Quoted 6 lines
drivers/irqchip/irq-owl-sirq.c new file +6 -0
+
+	/*
+	 * Software must clear external interrupt pending, when interrupt type
+	 * is edge triggered, so we need per SIRQ based clearing.
+	 */
+	if (chip_data->trigger & (1 << data->hwirq))

BIT(d->hwirq)

Quoted 2 lines

But it also begs the question: we already have all the trigger information in the irqdesc. Why do you need some additional bookkeeping?

That's another leftover from the original work. Thanks for pointing this out, I missed it. I dropped the redundant handling of the IRQ trigger information and just replaced this with:

if (!irqd_is_level_type(data))

Quoted 50 lines
Quoted 50 lines
drivers/irqchip/irq-owl-sirq.c new file +9 -0
+		owl_sirq_clear_set_extctl(chip_data, 0, INTC_EXTCTL_PENDING,
+					  data->hwirq);
+
+	irq_chip_eoi_parent(data);
+}
+
+static void owl_sirq_mask(struct irq_data *data)
+{
+	struct owl_sirq_chip_data *chip_data =

irq_data_get_irq_chip_data(data);

drivers/irqchip/irq-owl-sirq.c new file +8 -0
+
+	owl_sirq_clear_set_extctl(chip_data, INTC_EXTCTL_EN, 0, data->hwirq);
+	irq_chip_mask_parent(data);
+}
+
+static void owl_sirq_unmask(struct irq_data *data)
+{
+	struct owl_sirq_chip_data *chip_data =

irq_data_get_irq_chip_data(data);

drivers/irqchip/irq-owl-sirq.c new file +13 -0
+
+	owl_sirq_clear_set_extctl(chip_data, 0, INTC_EXTCTL_EN, data->hwirq);
+	irq_chip_unmask_parent(data);
+}
+
+/*
+ * GIC does not handle falling edge or active low, hence SIRQ shall be
+ * programmed to convert falling edge to rising edge signal and active
+ * low to active high signal.
+ */
+static int owl_sirq_set_type(struct irq_data *data, unsigned int type)
+{
+	struct owl_sirq_chip_data *chip_data =

irq_data_get_irq_chip_data(data);

drivers/irqchip/irq-owl-sirq.c new file +17 -0
+	u32 sirq_type;
+
+	switch (type) {
+	case IRQ_TYPE_LEVEL_LOW:
+		sirq_type = INTC_EXTCTL_TYPE_LOW;
+		chip_data->trigger &= ~(1 << data->hwirq);
+		type = IRQ_TYPE_LEVEL_HIGH;
+		break;
+	case IRQ_TYPE_LEVEL_HIGH:
+		sirq_type = INTC_EXTCTL_TYPE_HIGH;
+		chip_data->trigger &= ~(1 << data->hwirq);
+		break;
+	case IRQ_TYPE_EDGE_FALLING:
+		sirq_type = INTC_EXTCTL_TYPE_FALLING;
+		chip_data->trigger |= 1 << data->hwirq;
+		type = IRQ_TYPE_EDGE_RISING;
+		break;
Quoted 8 lines

drivers/irqchip/irq-owl-sirq.c line 161

Quoted 6 lines
drivers/irqchip/irq-owl-sirq.c new file +6 -0
+	case IRQ_TYPE_EDGE_RISING:
+		sirq_type = INTC_EXTCTL_TYPE_RISING;
+		chip_data->trigger |= 1 << data->hwirq;
+		break;
+	default:
+		WARN_ON(1);

No need for this WARN_ON(), the core kernel is loud enough.

Done.

Quoted 10 lines
Quoted 10 lines
drivers/irqchip/irq-owl-sirq.c new file +10 -0
+		return -EINVAL;
+	}
+
+	owl_sirq_clear_set_extctl(chip_data, INTC_EXTCTL_TYPE_MASK, sirq_type,
+				  data->hwirq);
+
+	return irq_chip_set_type_parent(data, type);
+}
+
+static struct irq_chip owl_sirq_chip = {
Quoted 8 lines

drivers/irqchip/irq-owl-sirq.c line 177

Quoted 6 lines
drivers/irqchip/irq-owl-sirq.c new file +6 -0
+	.name		= "owl-sirq",
+	.irq_mask	= owl_sirq_mask,
+	.irq_unmask	= owl_sirq_unmask,
+	.irq_eoi	= owl_sirq_eoi,
+	.irq_set_type	= owl_sirq_set_type,
+	.irq_retrigger	= irq_chip_retrigger_hierarchy,

How about irq_set_affinity? Or does it only exist on UP systems?

I have just added:

#ifdef CONFIG_SMP
.irq_set_affinity = irq_chip_set_affinity_parent,
#endif

Quoted 146 lines
Quoted 133 lines
drivers/irqchip/irq-owl-sirq.c new file +20 -0
+};
+
+static int owl_sirq_domain_translate(struct irq_domain *d,
+				     struct irq_fwspec *fwspec,
+				     unsigned long *hwirq,
+				     unsigned int *type)
+{
+	if (!is_of_node(fwspec->fwnode))
+		return -EINVAL;
+
+	if (fwspec->param_count != 2 || fwspec->param[0] >= NUM_SIRQ)
+		return -EINVAL;
+
+	*hwirq = fwspec->param[0];
+	*type = fwspec->param[1];
+
+	return 0;
+}
+
+static int owl_sirq_domain_alloc(struct irq_domain *domain, unsigned

int virq,

drivers/irqchip/irq-owl-sirq.c new file +91 -0
+				 unsigned int nr_irqs, void *data)
+{
+	struct owl_sirq_chip_data *chip_data = domain->host_data;
+	struct irq_fwspec *fwspec = data;
+	struct irq_fwspec parent_fwspec;
+	irq_hw_number_t hwirq;
+	unsigned int type;
+	int ret;
+
+	if (WARN_ON(nr_irqs != 1))
+		return -EINVAL;
+
+	ret = owl_sirq_domain_translate(domain, fwspec, &hwirq, &type);
+	if (ret)
+		return ret;
+
+	switch (type) {
+	case IRQ_TYPE_EDGE_RISING:
+	case IRQ_TYPE_LEVEL_HIGH:
+		break;
+	case IRQ_TYPE_EDGE_FALLING:
+		type = IRQ_TYPE_EDGE_RISING;
+		break;
+	case IRQ_TYPE_LEVEL_LOW:
+		type = IRQ_TYPE_LEVEL_HIGH;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	irq_domain_set_hwirq_and_chip(domain, virq, hwirq, &owl_sirq_chip,
+				      chip_data);
+
+	parent_fwspec.fwnode = domain->parent->fwnode;
+	parent_fwspec.param_count = 3;
+	parent_fwspec.param[0] = 0;	/* SPI */
+	parent_fwspec.param[1] = chip_data->ext_irqs[hwirq];
+	parent_fwspec.param[2] = type;
+
+	return irq_domain_alloc_irqs_parent(domain, virq, 1, &parent_fwspec);
+}
+
+static const struct irq_domain_ops owl_sirq_domain_ops = {
+	.translate	= owl_sirq_domain_translate,
+	.alloc		= owl_sirq_domain_alloc,
+	.free		= irq_domain_free_irqs_common,
+};
+
+static const struct of_device_id owl_sirq_of_match[] = {
+	{ .compatible = "actions,s500-sirq", .data = &owl_sirq_s500_params },
+	{ .compatible = "actions,s700-sirq", .data = &owl_sirq_s500_params },
+	{ .compatible = "actions,s900-sirq", .data = &owl_sirq_s900_params },
+	{ /* sentinel */ }
+};
+
+static int __init owl_sirq_of_init(struct device_node *node,
+				   struct device_node *parent)
+{
+	const struct of_device_id *match;
+	struct irq_domain *domain, *parent_domain;
+	struct owl_sirq_chip_data *chip_data;
+	int ret, i;
+
+	parent_domain = irq_find_host(parent);
+	if (!parent_domain) {
+		pr_err("%pOF: failed to find sirq parent domain\n", node);
+		return -ENXIO;
+	}
+
+	chip_data = kzalloc(sizeof(*chip_data), GFP_KERNEL);
+	if (!chip_data)
+		return -ENOMEM;
+
+	match = of_match_node(owl_sirq_of_match, node);
+	if (!match) {
+		pr_warn("owl-sirq: assuming S500/S700 compatible controller\n");
+		chip_data->params = &owl_sirq_s500_params;
+	} else {
+		chip_data->params = match->data;
+	}
+
+	raw_spin_lock_init(&chip_data->lock);
+
+	chip_data->base = of_iomap(node, 0);
+	if (!chip_data->base) {
+		pr_err("%pOF: failed to map sirq registers\n", node);
+		ret = -ENXIO;
+		goto out_free;
+	}
+
+	ret = of_property_read_variable_u32_array(node,

"actions,ext-interrupts",

drivers/irqchip/irq-owl-sirq.c new file +20 -0
+						  chip_data->ext_irqs,
+						  NUM_SIRQ, NUM_SIRQ);
+	if (ret < NUM_SIRQ) {
+		pr_err("%pOF: failed to read sirq interrupts\n", node);
+		goto out_unmap;
+	}
+
+	/* Set 24MHz external interrupt clock freq */
+	for (i = 0; i < NUM_SIRQ; i++)
+		owl_sirq_clear_set_extctl(chip_data, 0, INTC_EXTCTL_CLK_SEL, i);
+
+	domain = irq_domain_add_hierarchy(parent_domain, 0, NUM_SIRQ, node,
+					  &owl_sirq_domain_ops, chip_data);
+	if (!domain) {
+		pr_err("%pOF: failed to add domain\n", node);
+		ret = -ENOMEM;
+		goto out_unmap;
+	}
+
+	return 0;

drivers/irqchip/irq-owl-sirq.c line 318

Quoted 10 lines
drivers/irqchip/irq-owl-sirq.c new file +10 -0
+
+out_unmap:
+	iounmap(chip_data->base);
+out_free:
+	kfree(chip_data);
+
+	return ret;
+}
+
+IRQCHIP_DECLARE(owl_sirq, "actions,owl-sirq", owl_sirq_of_init);

Thanks,

Quoted 3 lines
        M.
Signature · 1 line
Jazz is not dead. It just smells funny...

Thanks again,
Cristi

#5 lore raw

Re: [PATCH v4 2/3] irqchip: Add Actions Semi Owl SIRQ controller

Quoted 10 lines · Cristian Ciocaltea

Hi Marc,

Thanks for your quick and detailed review!

Quoted 4 lines · Marc Zyngier
Quoted 2 lines · Cristian Ciocaltea

This controller appears on Actions Semi Owl family SoC's S500, S700 and S900 and provides support for 3 external interrupt controllers through

Quoted 8 lines
Quoted 1 line

Is that really 3 interrupt controllers? Or merely 3 interrupt lines?

This is mostly a leftover statement from the previous patch revision. I will change it to something like:

"This interrupt controller is found in the Actions Semi Owl SoCs (S500, S700 and S900) and provides support for handling up to 3 external interrupt lines."

Looks good.

Quoted 136 lines
Quoted 87 lines
Quoted 74 lines

dedicated SIRQ pins.

Each line can be independently configured as interrupt and triggers on either of the edges (raising or falling) or either of the levels (high or low). Each line can also be masked independently.

This is based on the patch series submitted by Parthiban Nallathambi:
https://lore.kernel.org/lkml/[email protected]/

[cristi: optimized DT, various fixes/cleanups/improvements]
---
 drivers/irqchip/Makefile       |   1 +
 drivers/irqchip/irq-owl-sirq.c | 318 +++++++++++++++++++++++++++++++++
 2 files changed, 319 insertions(+)
 create mode 100644 drivers/irqchip/irq-owl-sirq.c
drivers/irqchip/Makefile +1 -0
index 133f9c45744a..b8eb5b8b766d 100644
@@ -7,6 +7,7 @@ obj-$(CONFIG_ATH79)			+= irq-ath79-cpu.o
 obj-$(CONFIG_ATH79)			+= irq-ath79-misc.o
 obj-$(CONFIG_ARCH_BCM2835)		+= irq-bcm2835.o
 obj-$(CONFIG_ARCH_BCM2835)		+= irq-bcm2836.o
+obj-$(CONFIG_ARCH_ACTIONS)		+= irq-owl-sirq.o
 obj-$(CONFIG_DAVINCI_AINTC)		+= irq-davinci-aintc.o
 obj-$(CONFIG_DAVINCI_CP_INTC)		+= irq-davinci-cp-intc.o
 obj-$(CONFIG_EXYNOS_IRQ_COMBINER)	+= exynos-combiner.o
drivers/irqchip/irq-owl-sirq.c new file +35 -0
new file mode 100644
index 000000000000..29b7ffc40ac7
@@ -0,0 +1,318 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Actions Semi Owl SoCs SIRQ interrupt controller driver
+ *
+ * Copyright (C) 2014 Actions Semi Inc.
+ * David Liu <[email protected]>
+ *
+ * Author: Parthiban Nallathambi <[email protected]>
+ * Author: Saravanan Sekar <[email protected]>
+ * Author: Cristian Ciocaltea <[email protected]>
+ */
+
+#include <linux/interrupt.h>
+#include <linux/irqchip.h>
+#include <linux/of_address.h>
+#include <linux/of_irq.h>
+
+#define NUM_SIRQ			3
+
+#define INTC_EXTCTL_PENDING		BIT(0)
+#define INTC_EXTCTL_CLK_SEL		BIT(4)
+#define INTC_EXTCTL_EN			BIT(5)
+#define INTC_EXTCTL_TYPE_MASK		GENMASK(7, 6)
+#define INTC_EXTCTL_TYPE_HIGH		0
+#define INTC_EXTCTL_TYPE_LOW		BIT(6)
+#define INTC_EXTCTL_TYPE_RISING		BIT(7)
+#define INTC_EXTCTL_TYPE_FALLING	(BIT(6) | BIT(7))
+
+/* S900 SIRQ1 & SIRQ2 control register offsets, relative to SIRQ0 */
+#define INTC_EXTCTL1			0x0328
+#define INTC_EXTCTL2			0x032c
+
+struct owl_sirq_params {
+	/* INTC_EXTCTL reg shared for all three SIRQ lines */
+	bool reg_shared;

drivers/irqchip/irq-owl-sirq.c line 45

Quoted 10 lines
drivers/irqchip/irq-owl-sirq.c new file +10 -0
+	/* INTC_EXTCTL reg offsets relative to controller base address */
+	u16 reg_offset[NUM_SIRQ];
+};
+
+struct owl_sirq_chip_data {
+	const struct owl_sirq_params *params;
+	void __iomem *base;
+	raw_spinlock_t lock;
+	u32 ext_irqs[NUM_SIRQ];
+	u8 trigger;

Nit: Please align data structure members vertically:

Quoted 7 lines
struct owl_sirq_chip_data {
	const struct owl_sirq_params *params;
	void __iomem                 *base;
	raw_spinlock_t               lock;
	u32                          ext_irqs[NUM_SIRQ];
	u8                           trigger;
};

Done.

Quoted 6 lines
Quoted 6 lines
drivers/irqchip/irq-owl-sirq.c new file +6 -0
+};
+
+/* S500 and S700 SoCs */
+static const struct owl_sirq_params owl_sirq_s500_params = {
+	.reg_shared = true,
+	.reg_offset = { 0, 0, 0 },
Quoted 8 lines

drivers/irqchip/irq-owl-sirq.c line 57

Quoted 6 lines
drivers/irqchip/irq-owl-sirq.c new file +6 -0
+};
+
+/* S900 SoC */
+static const struct owl_sirq_params owl_sirq_s900_params = {
+	.reg_shared = false,
+	.reg_offset = { 0, INTC_EXTCTL1, INTC_EXTCTL2 },

0 *is* an offset, right? Why doesn't it have a name too?

Right, I updated the defines section:

/* S900 SIRQ control register offsets, relative to controller base address */
#define INTC_EXTCTL0 0x0000
#define INTC_EXTCTL1 0x0328
[...]

The controller base address points to SIRQ0 control register, so this offset is always 0, but I totally agree we should have a name for it.

Quoted 5 lines
Quoted 5 lines
drivers/irqchip/irq-owl-sirq.c new file +3 -0
+};
+
+static u32 owl_sirq_read_extctl(struct owl_sirq_chip_data *data, u32

index)
+{

Quoted 8 lines

drivers/irqchip/irq-owl-sirq.c

Quoted 5 lines
drivers/irqchip/irq-owl-sirq.c new file +5 -0
+	u32 val;
+
+	val = readl_relaxed(data->base + data->params->reg_offset[index]);
+	if (data->params->reg_shared)
+		val = (val >> (2 - index) * 8) & 0xff;
        base = (2 - index) * 8;
        val = FIELD_GET(GENMASK(base + 7, base), val);
Quoted 4 lines

Unfortunately the context doesn't allow using FIELD_GET:

./include/linux/compiler.h:392:38: error: call to ‘__compiletime_assert_159’
declared with attribute error: FIELD_GET: mask is not constant

Bah. Turning the whole thing into compile-time values would actually be more readable, so how about this:

drivers/irqchip/irq-owl-sirq.c +29 -4
index 29b7ffc40ac7..b771acbda7d5 100644
@@ -57,13 +57,39 @@ static const struct owl_sirq_params owl_sirq_s900_params = {
 	.reg_offset = { 0, INTC_EXTCTL1, INTC_EXTCTL2 },
 };
 
+static u32 owl_field_get(u32 val, int index)
+{
+	switch(index) {
+	case 0:
+		return FIELD_GET(GENMASK(23, 16), val);
+	case 1:
+		return FIELD_GET(GENMASK(15, 8), val);
+	case 2:
+	default:
+		return FIELD_GET(GENMASK(7, 0), val);
+	}
+}
+
+static u32 owl_field_prep(u32 val, int index)
+{
+	switch(index) {
+	case 0:
+		return FIELD_PREP(GENMASK(23, 16), val);
+	case 1:
+		return FIELD_PREP(GENMASK(15, 8), val);
+	case 2:
+	default:
+		return FIELD_PREP(GENMASK(7, 0), val);
+	}
+}
+
 static u32 owl_sirq_read_extctl(struct owl_sirq_chip_data *data, u32 index)
 {
 	u32 val;
 
 	val = readl_relaxed(data->base + data->params->reg_offset[index]);
 	if (data->params->reg_shared)
-		val = (val >> (2 - index) * 8) & 0xff;
+		val = owl_field_get(val, index);
 
 	return val;
 }
@@ -75,9 +101,8 @@ static void owl_sirq_write_extctl(struct owl_sirq_chip_data *data,
 
 	if (data->params->reg_shared) {
 		val = readl_relaxed(data->base + data->params->reg_offset[index]);
-		val &= ~(0xff << (2 - index) * 8);
-		extctl &= 0xff;
-		extctl = (extctl << (2 - index) * 8) | val;
+		val &= ~owl_field_prep(0xff, index);
+		extctl = owl_field_prep(extctl, index) | val;
 	}
 
 	writel_relaxed(extctl, data->base + data->params->reg_offset[index]);

Yes, this is a bit more code, but it *is* readable. Bonus points if you add proper defines for the masks.

Quoted 18 lines
Quoted 17 lines
Quoted 5 lines
drivers/irqchip/irq-owl-sirq.c new file +4 -0
+
+	return val;
+}
+

drivers/irqchip/irq-owl-sirq.c

Quoted 10 lines
drivers/irqchip/irq-owl-sirq.c new file +10 -0
+static void owl_sirq_write_extctl(struct owl_sirq_chip_data *data,
+				  u32 extctl, u32 index)
+{
+	u32 val;
+
+	if (data->params->reg_shared) {
+		val = readl_relaxed(data->base + data->params->reg_offset[index]);
+		val &= ~(0xff << (2 - index) * 8);
+		extctl &= 0xff;
+		extctl = (extctl << (2 - index) * 8) | val;

Please make use of FIELD_PREP, FIELD_GET and GENMASK.

Quoted 3 lines

I'm not sure how to deal with the mask constness restriction, except using static defines and if/else statements, which is not quite elegant.

See above.

Quoted 33 lines
Quoted 33 lines
Quoted 24 lines
drivers/irqchip/irq-owl-sirq.c new file +22 -0
+	}
+
+	writel_relaxed(extctl, data->base + data->params->reg_offset[index]);
+}
+
+static void owl_sirq_clear_set_extctl(struct owl_sirq_chip_data *d,
+				      u32 clear, u32 set, u32 index)
+{
+	unsigned long flags;
+	u32 val;
+
+	raw_spin_lock_irqsave(&d->lock, flags);
+	val = owl_sirq_read_extctl(d, index);
+	val &= ~clear;
+	val |= set;
+	owl_sirq_write_extctl(d, val, index);
+	raw_spin_unlock_irqrestore(&d->lock, flags);
+}
+
+static void owl_sirq_eoi(struct irq_data *data)
+{
+	struct owl_sirq_chip_data *chip_data =

irq_data_get_irq_chip_data(data);

drivers/irqchip/irq-owl-sirq.c

Quoted 6 lines
drivers/irqchip/irq-owl-sirq.c new file +6 -0
+
+	/*
+	 * Software must clear external interrupt pending, when interrupt type
+	 * is edge triggered, so we need per SIRQ based clearing.
+	 */
+	if (chip_data->trigger & (1 << data->hwirq))

BIT(d->hwirq)

Quoted 8 lines
Quoted 2 lines

But it also begs the question: we already have all the trigger information in the irqdesc. Why do you need some additional bookkeeping?

That's another leftover from the original work. Thanks for pointing this out, I missed it. I dropped the redundant handling of the IRQ trigger information and just replaced this with:

if (!irqd_is_level_type(data))

Yup.

Quoted 81 lines
Quoted 51 lines
Quoted 51 lines
drivers/irqchip/irq-owl-sirq.c new file +9 -0
+		owl_sirq_clear_set_extctl(chip_data, 0, INTC_EXTCTL_PENDING,
+					  data->hwirq);
+
+	irq_chip_eoi_parent(data);
+}
+
+static void owl_sirq_mask(struct irq_data *data)
+{
+	struct owl_sirq_chip_data *chip_data =

irq_data_get_irq_chip_data(data);

drivers/irqchip/irq-owl-sirq.c new file +8 -0
+
+	owl_sirq_clear_set_extctl(chip_data, INTC_EXTCTL_EN, 0, data->hwirq);
+	irq_chip_mask_parent(data);
+}
+
+static void owl_sirq_unmask(struct irq_data *data)
+{
+	struct owl_sirq_chip_data *chip_data =

irq_data_get_irq_chip_data(data);

drivers/irqchip/irq-owl-sirq.c new file +13 -0
+
+	owl_sirq_clear_set_extctl(chip_data, 0, INTC_EXTCTL_EN, data->hwirq);
+	irq_chip_unmask_parent(data);
+}
+
+/*
+ * GIC does not handle falling edge or active low, hence SIRQ shall be
+ * programmed to convert falling edge to rising edge signal and active
+ * low to active high signal.
+ */
+static int owl_sirq_set_type(struct irq_data *data, unsigned int type)
+{
+	struct owl_sirq_chip_data *chip_data =

irq_data_get_irq_chip_data(data);

drivers/irqchip/irq-owl-sirq.c new file +17 -0
+	u32 sirq_type;
+
+	switch (type) {
+	case IRQ_TYPE_LEVEL_LOW:
+		sirq_type = INTC_EXTCTL_TYPE_LOW;
+		chip_data->trigger &= ~(1 << data->hwirq);
+		type = IRQ_TYPE_LEVEL_HIGH;
+		break;
+	case IRQ_TYPE_LEVEL_HIGH:
+		sirq_type = INTC_EXTCTL_TYPE_HIGH;
+		chip_data->trigger &= ~(1 << data->hwirq);
+		break;
+	case IRQ_TYPE_EDGE_FALLING:
+		sirq_type = INTC_EXTCTL_TYPE_FALLING;
+		chip_data->trigger |= 1 << data->hwirq;
+		type = IRQ_TYPE_EDGE_RISING;
+		break;
Quoted 8 lines

drivers/irqchip/irq-owl-sirq.c

Quoted 6 lines
drivers/irqchip/irq-owl-sirq.c new file +6 -0
+	case IRQ_TYPE_EDGE_RISING:
+		sirq_type = INTC_EXTCTL_TYPE_RISING;
+		chip_data->trigger |= 1 << data->hwirq;
+		break;
+	default:
+		WARN_ON(1);

No need for this WARN_ON(), the core kernel is loud enough.

Done.

Quoted 10 lines
Quoted 10 lines
drivers/irqchip/irq-owl-sirq.c new file +10 -0
+		return -EINVAL;
+	}
+
+	owl_sirq_clear_set_extctl(chip_data, INTC_EXTCTL_TYPE_MASK, sirq_type,
+				  data->hwirq);
+
+	return irq_chip_set_type_parent(data, type);
+}
+
+static struct irq_chip owl_sirq_chip = {
Quoted 8 lines

drivers/irqchip/irq-owl-sirq.c

Quoted 6 lines
drivers/irqchip/irq-owl-sirq.c new file +6 -0
+	.name		= "owl-sirq",
+	.irq_mask	= owl_sirq_mask,
+	.irq_unmask	= owl_sirq_unmask,
+	.irq_eoi	= owl_sirq_eoi,
+	.irq_set_type	= owl_sirq_set_type,
+	.irq_retrigger	= irq_chip_retrigger_hierarchy,

How about irq_set_affinity? Or does it only exist on UP systems?

Quoted 5 lines

I have just added:

#ifdef CONFIG_SMP
.irq_set_affinity = irq_chip_set_affinity_parent,
#endif

Looks OK.

Cheers,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
#6 lore raw

Re: [PATCH v4 2/3] irqchip: Add Actions Semi Owl SIRQ controller

Quoted 225 lines · Marc Zyngier
Quoted 10 lines · Cristian Ciocaltea

Hi Marc,

Thanks for your quick and detailed review!

Quoted 4 lines · Marc Zyngier
Quoted 2 lines · Cristian Ciocaltea

This controller appears on Actions Semi Owl family SoC's S500, S700 and S900 and provides support for 3 external interrupt controllers through

Quoted 8 lines
Quoted 1 line

Is that really 3 interrupt controllers? Or merely 3 interrupt lines?

This is mostly a leftover statement from the previous patch revision. I will change it to something like:

"This interrupt controller is found in the Actions Semi Owl SoCs (S500, S700 and S900) and provides support for handling up to 3 external interrupt lines."

Looks good.

Quoted 136 lines
Quoted 87 lines
Quoted 74 lines

dedicated SIRQ pins.

Each line can be independently configured as interrupt and triggers on either of the edges (raising or falling) or either of the levels (high or low). Each line can also be masked independently.

This is based on the patch series submitted by Parthiban Nallathambi:
https://lore.kernel.org/lkml/[email protected]/

[cristi: optimized DT, various fixes/cleanups/improvements]
---
 drivers/irqchip/Makefile       |   1 +
 drivers/irqchip/irq-owl-sirq.c | 318 +++++++++++++++++++++++++++++++++
 2 files changed, 319 insertions(+)
 create mode 100644 drivers/irqchip/irq-owl-sirq.c
drivers/irqchip/Makefile +1 -0
index 133f9c45744a..b8eb5b8b766d 100644
@@ -7,6 +7,7 @@ obj-$(CONFIG_ATH79)			+= irq-ath79-cpu.o
 obj-$(CONFIG_ATH79)			+= irq-ath79-misc.o
 obj-$(CONFIG_ARCH_BCM2835)		+= irq-bcm2835.o
 obj-$(CONFIG_ARCH_BCM2835)		+= irq-bcm2836.o
+obj-$(CONFIG_ARCH_ACTIONS)		+= irq-owl-sirq.o
 obj-$(CONFIG_DAVINCI_AINTC)		+= irq-davinci-aintc.o
 obj-$(CONFIG_DAVINCI_CP_INTC)		+= irq-davinci-cp-intc.o
 obj-$(CONFIG_EXYNOS_IRQ_COMBINER)	+= exynos-combiner.o
drivers/irqchip/irq-owl-sirq.c new file +35 -0
new file mode 100644
index 000000000000..29b7ffc40ac7
@@ -0,0 +1,318 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Actions Semi Owl SoCs SIRQ interrupt controller driver
+ *
+ * Copyright (C) 2014 Actions Semi Inc.
+ * David Liu <[email protected]>
+ *
+ * Author: Parthiban Nallathambi <[email protected]>
+ * Author: Saravanan Sekar <[email protected]>
+ * Author: Cristian Ciocaltea <[email protected]>
+ */
+
+#include <linux/interrupt.h>
+#include <linux/irqchip.h>
+#include <linux/of_address.h>
+#include <linux/of_irq.h>
+
+#define NUM_SIRQ			3
+
+#define INTC_EXTCTL_PENDING		BIT(0)
+#define INTC_EXTCTL_CLK_SEL		BIT(4)
+#define INTC_EXTCTL_EN			BIT(5)
+#define INTC_EXTCTL_TYPE_MASK		GENMASK(7, 6)
+#define INTC_EXTCTL_TYPE_HIGH		0
+#define INTC_EXTCTL_TYPE_LOW		BIT(6)
+#define INTC_EXTCTL_TYPE_RISING		BIT(7)
+#define INTC_EXTCTL_TYPE_FALLING	(BIT(6) | BIT(7))
+
+/* S900 SIRQ1 & SIRQ2 control register offsets, relative to SIRQ0 */
+#define INTC_EXTCTL1			0x0328
+#define INTC_EXTCTL2			0x032c
+
+struct owl_sirq_params {
+	/* INTC_EXTCTL reg shared for all three SIRQ lines */
+	bool reg_shared;

drivers/irqchip/irq-owl-sirq.c line 45

Quoted 10 lines
drivers/irqchip/irq-owl-sirq.c new file +10 -0
+	/* INTC_EXTCTL reg offsets relative to controller base address */
+	u16 reg_offset[NUM_SIRQ];
+};
+
+struct owl_sirq_chip_data {
+	const struct owl_sirq_params *params;
+	void __iomem *base;
+	raw_spinlock_t lock;
+	u32 ext_irqs[NUM_SIRQ];
+	u8 trigger;

Nit: Please align data structure members vertically:

Quoted 7 lines
struct owl_sirq_chip_data {
	const struct owl_sirq_params *params;
	void __iomem                 *base;
	raw_spinlock_t               lock;
	u32                          ext_irqs[NUM_SIRQ];
	u8                           trigger;
};

Done.

Quoted 6 lines
Quoted 6 lines
drivers/irqchip/irq-owl-sirq.c new file +6 -0
+};
+
+/* S500 and S700 SoCs */
+static const struct owl_sirq_params owl_sirq_s500_params = {
+	.reg_shared = true,
+	.reg_offset = { 0, 0, 0 },
Quoted 8 lines

drivers/irqchip/irq-owl-sirq.c line 57

Quoted 6 lines
drivers/irqchip/irq-owl-sirq.c new file +6 -0
+};
+
+/* S900 SoC */
+static const struct owl_sirq_params owl_sirq_s900_params = {
+	.reg_shared = false,
+	.reg_offset = { 0, INTC_EXTCTL1, INTC_EXTCTL2 },

0 *is* an offset, right? Why doesn't it have a name too?

Right, I updated the defines section:

/* S900 SIRQ control register offsets, relative to controller base address */
#define INTC_EXTCTL0 0x0000
#define INTC_EXTCTL1 0x0328
[...]

The controller base address points to SIRQ0 control register, so this offset is always 0, but I totally agree we should have a name for it.

Quoted 5 lines
Quoted 5 lines
drivers/irqchip/irq-owl-sirq.c new file +3 -0
+};
+
+static u32 owl_sirq_read_extctl(struct owl_sirq_chip_data *data, u32

index)
+{

Quoted 8 lines

drivers/irqchip/irq-owl-sirq.c

Quoted 5 lines
drivers/irqchip/irq-owl-sirq.c new file +5 -0
+	u32 val;
+
+	val = readl_relaxed(data->base + data->params->reg_offset[index]);
+	if (data->params->reg_shared)
+		val = (val >> (2 - index) * 8) & 0xff;
        base = (2 - index) * 8;
        val = FIELD_GET(GENMASK(base + 7, base), val);
Quoted 4 lines

Unfortunately the context doesn't allow using FIELD_GET:

./include/linux/compiler.h:392:38: error: call to ‘__compiletime_assert_159’
declared with attribute error: FIELD_GET: mask is not constant

Bah. Turning the whole thing into compile-time values would actually be more readable, so how about this:

drivers/irqchip/irq-owl-sirq.c +29 -4
index 29b7ffc40ac7..b771acbda7d5 100644
@@ -57,13 +57,39 @@ static const struct owl_sirq_params owl_sirq_s900_params = {
 	.reg_offset = { 0, INTC_EXTCTL1, INTC_EXTCTL2 },
 };
 
+static u32 owl_field_get(u32 val, int index)
+{
+	switch(index) {
+	case 0:
+		return FIELD_GET(GENMASK(23, 16), val);
+	case 1:
+		return FIELD_GET(GENMASK(15, 8), val);
+	case 2:
+	default:
+		return FIELD_GET(GENMASK(7, 0), val);
+	}
+}
+
+static u32 owl_field_prep(u32 val, int index)
+{
+	switch(index) {
+	case 0:
+		return FIELD_PREP(GENMASK(23, 16), val);
+	case 1:
+		return FIELD_PREP(GENMASK(15, 8), val);
+	case 2:
+	default:
+		return FIELD_PREP(GENMASK(7, 0), val);
+	}
+}
+
 static u32 owl_sirq_read_extctl(struct owl_sirq_chip_data *data, u32 index)
 {
 	u32 val;
 
 	val = readl_relaxed(data->base + data->params->reg_offset[index]);
 	if (data->params->reg_shared)
-		val = (val >> (2 - index) * 8) & 0xff;
+		val = owl_field_get(val, index);
 
 	return val;
 }
@@ -75,9 +101,8 @@ static void owl_sirq_write_extctl(struct owl_sirq_chip_data *data,
 
 	if (data->params->reg_shared) {
 		val = readl_relaxed(data->base + data->params->reg_offset[index]);
-		val &= ~(0xff << (2 - index) * 8);
-		extctl &= 0xff;
-		extctl = (extctl << (2 - index) * 8) | val;
+		val &= ~owl_field_prep(0xff, index);
+		extctl = owl_field_prep(extctl, index) | val;
 	}
 
 	writel_relaxed(extctl, data->base + data->params->reg_offset[index]);
Quoted 2 lines

Yes, this is a bit more code, but it *is* readable. Bonus points if you add proper defines for the masks.

That's great, thanks a lot!

I have submitted a new revision:
https://lore.kernel.org/lkml/[email protected]/

Regards,
Cristi

Quoted 163 lines
Quoted 18 lines
Quoted 17 lines
Quoted 5 lines
drivers/irqchip/irq-owl-sirq.c new file +4 -0
+
+	return val;
+}
+

drivers/irqchip/irq-owl-sirq.c

Quoted 10 lines
drivers/irqchip/irq-owl-sirq.c new file +10 -0
+static void owl_sirq_write_extctl(struct owl_sirq_chip_data *data,
+				  u32 extctl, u32 index)
+{
+	u32 val;
+
+	if (data->params->reg_shared) {
+		val = readl_relaxed(data->base + data->params->reg_offset[index]);
+		val &= ~(0xff << (2 - index) * 8);
+		extctl &= 0xff;
+		extctl = (extctl << (2 - index) * 8) | val;

Please make use of FIELD_PREP, FIELD_GET and GENMASK.

Quoted 3 lines

I'm not sure how to deal with the mask constness restriction, except using static defines and if/else statements, which is not quite elegant.

See above.

Quoted 33 lines
Quoted 33 lines
Quoted 24 lines
drivers/irqchip/irq-owl-sirq.c new file +22 -0
+	}
+
+	writel_relaxed(extctl, data->base + data->params->reg_offset[index]);
+}
+
+static void owl_sirq_clear_set_extctl(struct owl_sirq_chip_data *d,
+				      u32 clear, u32 set, u32 index)
+{
+	unsigned long flags;
+	u32 val;
+
+	raw_spin_lock_irqsave(&d->lock, flags);
+	val = owl_sirq_read_extctl(d, index);
+	val &= ~clear;
+	val |= set;
+	owl_sirq_write_extctl(d, val, index);
+	raw_spin_unlock_irqrestore(&d->lock, flags);
+}
+
+static void owl_sirq_eoi(struct irq_data *data)
+{
+	struct owl_sirq_chip_data *chip_data =

irq_data_get_irq_chip_data(data);

drivers/irqchip/irq-owl-sirq.c

Quoted 6 lines
drivers/irqchip/irq-owl-sirq.c new file +6 -0
+
+	/*
+	 * Software must clear external interrupt pending, when interrupt type
+	 * is edge triggered, so we need per SIRQ based clearing.
+	 */
+	if (chip_data->trigger & (1 << data->hwirq))

BIT(d->hwirq)

Quoted 8 lines
Quoted 2 lines

But it also begs the question: we already have all the trigger information in the irqdesc. Why do you need some additional bookkeeping?

That's another leftover from the original work. Thanks for pointing this out, I missed it. I dropped the redundant handling of the IRQ trigger information and just replaced this with:

if (!irqd_is_level_type(data))

Yup.

Quoted 81 lines
Quoted 51 lines
Quoted 51 lines
drivers/irqchip/irq-owl-sirq.c new file +9 -0
+		owl_sirq_clear_set_extctl(chip_data, 0, INTC_EXTCTL_PENDING,
+					  data->hwirq);
+
+	irq_chip_eoi_parent(data);
+}
+
+static void owl_sirq_mask(struct irq_data *data)
+{
+	struct owl_sirq_chip_data *chip_data =

irq_data_get_irq_chip_data(data);

drivers/irqchip/irq-owl-sirq.c new file +8 -0
+
+	owl_sirq_clear_set_extctl(chip_data, INTC_EXTCTL_EN, 0, data->hwirq);
+	irq_chip_mask_parent(data);
+}
+
+static void owl_sirq_unmask(struct irq_data *data)
+{
+	struct owl_sirq_chip_data *chip_data =

irq_data_get_irq_chip_data(data);

drivers/irqchip/irq-owl-sirq.c new file +13 -0
+
+	owl_sirq_clear_set_extctl(chip_data, 0, INTC_EXTCTL_EN, data->hwirq);
+	irq_chip_unmask_parent(data);
+}
+
+/*
+ * GIC does not handle falling edge or active low, hence SIRQ shall be
+ * programmed to convert falling edge to rising edge signal and active
+ * low to active high signal.
+ */
+static int owl_sirq_set_type(struct irq_data *data, unsigned int type)
+{
+	struct owl_sirq_chip_data *chip_data =

irq_data_get_irq_chip_data(data);

drivers/irqchip/irq-owl-sirq.c new file +17 -0
+	u32 sirq_type;
+
+	switch (type) {
+	case IRQ_TYPE_LEVEL_LOW:
+		sirq_type = INTC_EXTCTL_TYPE_LOW;
+		chip_data->trigger &= ~(1 << data->hwirq);
+		type = IRQ_TYPE_LEVEL_HIGH;
+		break;
+	case IRQ_TYPE_LEVEL_HIGH:
+		sirq_type = INTC_EXTCTL_TYPE_HIGH;
+		chip_data->trigger &= ~(1 << data->hwirq);
+		break;
+	case IRQ_TYPE_EDGE_FALLING:
+		sirq_type = INTC_EXTCTL_TYPE_FALLING;
+		chip_data->trigger |= 1 << data->hwirq;
+		type = IRQ_TYPE_EDGE_RISING;
+		break;
Quoted 8 lines

drivers/irqchip/irq-owl-sirq.c

Quoted 6 lines
drivers/irqchip/irq-owl-sirq.c new file +6 -0
+	case IRQ_TYPE_EDGE_RISING:
+		sirq_type = INTC_EXTCTL_TYPE_RISING;
+		chip_data->trigger |= 1 << data->hwirq;
+		break;
+	default:
+		WARN_ON(1);

No need for this WARN_ON(), the core kernel is loud enough.

Done.

Quoted 10 lines
Quoted 10 lines
drivers/irqchip/irq-owl-sirq.c new file +10 -0
+		return -EINVAL;
+	}
+
+	owl_sirq_clear_set_extctl(chip_data, INTC_EXTCTL_TYPE_MASK, sirq_type,
+				  data->hwirq);
+
+	return irq_chip_set_type_parent(data, type);
+}
+
+static struct irq_chip owl_sirq_chip = {
Quoted 8 lines

drivers/irqchip/irq-owl-sirq.c

Quoted 6 lines
drivers/irqchip/irq-owl-sirq.c new file +6 -0
+	.name		= "owl-sirq",
+	.irq_mask	= owl_sirq_mask,
+	.irq_unmask	= owl_sirq_unmask,
+	.irq_eoi	= owl_sirq_eoi,
+	.irq_set_type	= owl_sirq_set_type,
+	.irq_retrigger	= irq_chip_retrigger_hierarchy,

How about irq_set_affinity? Or does it only exist on UP systems?

Quoted 5 lines

I have just added:

#ifdef CONFIG_SMP
.irq_set_affinity = irq_chip_set_affinity_parent,
#endif

Looks OK.

Cheers,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.