1 From 6896b5f0538a7a7cfb7fac2d9ed3c6841c72ed40 Mon Sep 17 00:00:00 2001
2 From: Jonas Gorski <jogo@openwrt.org>
3 Date: Sun, 30 Nov 2014 14:54:27 +0100
4 Subject: [PATCH 18/20] irqchip: add support for bcm6345-style external
7 Signed-off-by: Jonas Gorski <jogo@openwrt.org>
9 .../interrupt-controller/brcm,bcm6345-ext-intc.txt | 24 ++
10 drivers/irqchip/Kconfig | 4 +
11 drivers/irqchip/Makefile | 1 +
12 drivers/irqchip/irq-bcm6345-ext.c | 296 ++++++++++++++++++++
13 include/linux/irqchip/irq-bcm6345-ext-intc.h | 14 +
14 5 files changed, 339 insertions(+)
15 create mode 100644 Documentation/devicetree/bindings/interrupt-controller/brcm,bcm6345-ext-intc.txt
16 create mode 100644 drivers/irqchip/irq-bcm6345-ext.c
17 create mode 100644 include/linux/irqchip/irq-bcm6345-ext-intc.h
20 +++ b/Documentation/devicetree/bindings/interrupt-controller/brcm,bcm6345-ext-intc.txt
22 +Broadcom BCM6345-style external interrupt controller
26 +- compatible: should be "brcm,bcm6345-l2-intc" or "brcm,bcm6345-l2-intc"
27 +- reg: specifies the base physical addresses and size of the registers.
28 +- interrupt-controller: identifies the node as an interrupt controller
29 +- #interrupt-cells: specifies the number of cells needed to encode an interrupt
31 +- interrupt-parent: specifies the phandle to the parent interrupt controller
32 + this one is cascaded from
33 +- interrupts: specifies the interrupt line(s) in the interrupt-parent controller
34 + node, valid values depend on the type of parent interrupt controller
38 +ext_intc: interrupt-controller@10000018 {
39 + compatible = "brcm,bcm6345-l2-intc";
40 + interrupt-parent = <&periph_intc>;
41 + #interrupt-cells = <2>;
42 + reg = <0x10000018 0x4>;
43 + interrupt-controller;
44 + interrupts = <24>, <25>, <26>, <27>;
46 --- a/drivers/irqchip/Kconfig
47 +++ b/drivers/irqchip/Kconfig
48 @@ -54,6 +54,10 @@ config BRCMSTB_L2_IRQ
49 select GENERIC_IRQ_CHIP
52 +config BCM6345_EXT_IRQ
59 --- a/drivers/irqchip/Makefile
60 +++ b/drivers/irqchip/Makefile
61 @@ -7,6 +7,7 @@ obj-$(CONFIG_ARCH_MMP) += irq-mmp.o
62 obj-$(CONFIG_ARCH_MVEBU) += irq-armada-370-xp.o
63 obj-$(CONFIG_ARCH_MXS) += irq-mxs.o
64 obj-$(CONFIG_ARCH_S3C24XX) += irq-s3c24xx.o
65 +obj-$(CONFIG_BCM6345_EXT_IRQ) += irq-bcm6345-ext.o
66 obj-$(CONFIG_BCM6345_L2_IRQ) += irq-bcm6345-l2.o
67 obj-$(CONFIG_DW_APB_ICTL) += irq-dw-apb-ictl.o
68 obj-$(CONFIG_METAG) += irq-metag-ext.o
70 +++ b/drivers/irqchip/irq-bcm6345-ext.c
73 + * This file is subject to the terms and conditions of the GNU General Public
74 + * License. See the file "COPYING" in the main directory of this archive
77 + * Copyright (C) 2014 Jonas Gorski <jogo@openwrt.org>
80 +#include <linux/ioport.h>
81 +#include <linux/irq.h>
82 +#include <linux/irqchip/chained_irq.h>
83 +#include <linux/irqchip/irq-bcm6345-ext-intc.h>
84 +#include <linux/kernel.h>
85 +#include <linux/of.h>
86 +#include <linux/of_irq.h>
87 +#include <linux/of_address.h>
88 +#include <linux/slab.h>
89 +#include <linux/spinlock.h>
93 +#ifdef CONFIG_BCM63XX
94 +#include <asm/mach-bcm63xx/bcm63xx_irq.h>
96 +#define VIRQ_BASE IRQ_EXTERNAL_BASE
103 +#define EXTIRQ_CFG_SENSE 0
104 +#define EXTIRQ_CFG_STAT 1
105 +#define EXTIRQ_CFG_CLEAR 2
106 +#define EXTIRQ_CFG_MASK 3
107 +#define EXTIRQ_CFG_BOTHEDGE 4
108 +#define EXTIRQ_CFG_LEVELSENSE 5
111 + struct irq_chip chip;
112 + struct irq_domain *domain;
115 + int parent_irq[MAX_IRQS];
120 +static void bcm6345_ext_intc_irq_handle(unsigned int irq, struct irq_desc *desc)
122 + struct intc_data *data = irq_desc_get_handler_data(desc);
123 + struct irq_chip *chip = irq_desc_get_chip(desc);
126 + chained_irq_enter(chip, desc);
128 + for (idx = 0; idx < MAX_IRQS; idx++) {
129 + if (data->parent_irq[idx] != irq)
132 + generic_handle_irq(irq_find_mapping(data->domain, idx));
135 + chained_irq_exit(chip, desc);
138 +static void bcm6345_ext_intc_irq_ack(struct irq_data *data)
140 + struct intc_data *priv = data->domain->host_data;
141 + irq_hw_number_t hwirq = irqd_to_hwirq(data);
144 + raw_spin_lock(priv->lock);
145 + reg = __raw_readl(priv->reg);
146 + reg |= hwirq << (EXTIRQ_CFG_CLEAR * priv->shift);
147 + __raw_writel(reg, priv->reg);
148 + raw_spin_unlock(priv->lock);
151 +static void bcm6345_ext_intc_irq_mask(struct irq_data *data)
153 + struct intc_data *priv = data->domain->host_data;
154 + irq_hw_number_t hwirq = irqd_to_hwirq(data);
157 + raw_spin_lock(priv->lock);
158 + reg = __raw_readl(priv->reg);
159 + reg &= ~(hwirq << (EXTIRQ_CFG_MASK * priv->shift));
160 + __raw_writel(reg, priv->reg);
161 + raw_spin_unlock(priv->lock);
164 +static void bcm6345_ext_intc_irq_unmask(struct irq_data *data)
166 + struct intc_data *priv = data->domain->host_data;
167 + irq_hw_number_t hwirq = irqd_to_hwirq(data);
170 + raw_spin_lock(priv->lock);
171 + reg = __raw_readl(priv->reg);
172 + reg |= hwirq << (EXTIRQ_CFG_MASK * priv->shift);
173 + __raw_writel(reg, priv->reg);
174 + raw_spin_unlock(priv->lock);
177 +static int bcm6345_ext_intc_set_type(struct irq_data *data,
178 + unsigned int flow_type)
180 + struct intc_data *priv = data->domain->host_data;
181 + irq_hw_number_t hwirq = irqd_to_hwirq(data);
182 + bool levelsense = 0, sense = 0, bothedge = 0;
185 + flow_type &= IRQ_TYPE_SENSE_MASK;
187 + if (flow_type == IRQ_TYPE_NONE)
188 + flow_type = IRQ_TYPE_LEVEL_LOW;
190 + switch (flow_type) {
191 + case IRQ_TYPE_EDGE_BOTH:
195 + case IRQ_TYPE_EDGE_RISING:
198 + case IRQ_TYPE_EDGE_FALLING:
202 + case IRQ_TYPE_LEVEL_HIGH:
207 + case IRQ_TYPE_LEVEL_LOW:
212 + pr_err("bogus flow type combination given!\n");
216 + raw_spin_lock(priv->lock);
217 + reg = __raw_readl(priv->reg);
220 + reg |= hwirq << (EXTIRQ_CFG_LEVELSENSE * priv->shift);
222 + reg &= ~(hwirq << (EXTIRQ_CFG_LEVELSENSE * priv->shift));
224 + reg |= hwirq << (EXTIRQ_CFG_SENSE * priv->shift);
226 + reg &= ~(hwirq << (EXTIRQ_CFG_SENSE * priv->shift));
228 + reg |= hwirq << (EXTIRQ_CFG_BOTHEDGE * priv->shift);
230 + reg &= ~(hwirq << (EXTIRQ_CFG_BOTHEDGE * priv->shift));
232 + __raw_writel(reg, priv->reg);
233 + raw_spin_unlock(priv->lock);
235 + irqd_set_trigger_type(data, flow_type);
236 + if (flow_type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
237 + __irq_set_handler_locked(data->irq, handle_level_irq);
239 + __irq_set_handler_locked(data->irq, handle_edge_irq);
244 +static int bcm6345_ext_intc_map(struct irq_domain *d, unsigned int irq,
245 + irq_hw_number_t hw)
247 + struct intc_data *priv = d->host_data;
249 + irq_set_chip_and_handler(irq, &priv->chip, handle_level_irq);
255 +static const struct irq_domain_ops bcm6345_ext_domain_ops = {
256 + .xlate = irq_domain_xlate_twocell,
257 + .map = bcm6345_ext_intc_map,
260 +static int __init __bcm6345_ext_intc_init(struct device_node *node,
261 + int num_irqs, int *irqs,
262 + void __iomem *reg, int shift)
264 + struct intc_data *data;
266 + int start = VIRQ_BASE;
268 + data = kzalloc(sizeof(*data), GFP_KERNEL);
272 + for (i = 0; i < num_irqs; i++) {
273 + data->parent_irq[i] = irqs[i];
275 + irq_set_handler_data(irqs[i], data);
276 + irq_set_chained_handler(irqs[i], bcm6345_ext_intc_irq_handle);
281 + data->chip.name = "bcm6345-ext-intc";
282 + data->chip.irq_ack = bcm6345_ext_intc_irq_ack;
283 + data->chip.irq_mask = bcm6345_ext_intc_irq_mask;
284 + data->chip.irq_unmask = bcm6345_ext_intc_irq_unmask;
285 + data->chip.irq_set_type = bcm6345_ext_intc_set_type;
288 + * If we have less than 4 irqs, this is the second controller on
289 + * bcm63xx. So increase the VIRQ start to not overlap with the first
290 + * one, but only do so if we actually use a non-zero start.
292 + * This can be removed when bcm63xx has no legacy users anymore.
294 + if (start && num_irqs < 4)
297 + data->domain = irq_domain_add_simple(node, num_irqs, start,
298 + &bcm6345_ext_domain_ops, data);
299 + if (!data->domain) {
307 +void __init bcm6345_ext_intc_init(int num_irqs, int *irqs, void __iomem *reg,
310 + __bcm6345_ext_intc_init(NULL, num_irqs, irqs, reg, shift);
314 +static int __init bcm63xx_ext_intc_of_init(struct device_node *node,
315 + struct device_node *parent,
318 + int num_irqs, ret = -EINVAL;
320 + void __iomem *base;
321 + int irqs[MAX_IRQS] = { 0 };
323 + num_irqs = of_irq_count(node);
325 + if (!num_irqs || num_irqs > MAX_IRQS)
328 + for (i = 0; i < num_irqs; i++) {
329 + irqs[i] = irq_of_parse_and_map(node, i);
336 + base = of_iomap(node, 0);
340 + ret = __bcm6345_ext_intc_init(node, num_irqs, irqs, base, shift);
346 + for (i = 0; i < num_irqs; i++)
347 + irq_dispose_mapping(irqs[i]);
352 +static int __init bcm6345_ext_intc_of_init(struct device_node *node,
353 + struct device_node *parent)
355 + return bcm63xx_ext_intc_of_init(node, parent, 4);
357 +static int __init bcm6348_ext_intc_of_init(struct device_node *node,
358 + struct device_node *parent)
360 + return bcm63xx_ext_intc_of_init(node, parent, 5);
363 +IRQCHIP_DECLARE(bcm6345_ext_intc, "brcm,bcm6345-ext-intc",
364 + bcm6345_ext_intc_of_init);
365 +IRQCHIP_DECLARE(bcm6348_ext_intc, "brcm,bcm6348-ext-intc",
366 + bcm6348_ext_intc_of_init);
369 +++ b/include/linux/irqchip/irq-bcm6345-ext-intc.h
372 + * This file is subject to the terms and conditions of the GNU General Public
373 + * License. See the file "COPYING" in the main directory of this archive
374 + * for more details.
376 + * Copyright (C) 2014 Jonas Gorski <jogo@openwrt.org>
379 +#ifndef __INCLUDE_LINUX_IRQCHIP_IRQ_BCM6345_EXT_INTC_H
380 +#define __INCLUDE_LINUX_IRQCHIP_IRQ_BCM6345_EXT_INTC_H
382 +void bcm6345_ext_intc_init(int n_irqs, int *irqs, void __iomem *reg, int shift);
384 +#endif /* __INCLUDE_LINUX_IRQCHIP_IRQ_BCM6345_EXT_INTC_H */