2014-03-20 03:21:17 +08:00
|
|
|
/*
|
|
|
|
* Allwinner A20/A31 SoCs NMI IRQ chip driver.
|
|
|
|
*
|
|
|
|
* Carlo Caione <carlo.caione@gmail.com>
|
|
|
|
*
|
|
|
|
* This file is licensed under the terms of the GNU General Public
|
|
|
|
* License version 2. This program is licensed "as is" without any
|
|
|
|
* warranty of any kind, whether express or implied.
|
|
|
|
*/
|
|
|
|
|
2015-10-06 00:42:13 +08:00
|
|
|
#define DRV_NAME "sunxi-nmi"
|
|
|
|
#define pr_fmt(fmt) DRV_NAME ": " fmt
|
|
|
|
|
2014-03-20 03:21:17 +08:00
|
|
|
#include <linux/bitops.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/irq.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/irqdomain.h>
|
|
|
|
#include <linux/of_irq.h>
|
|
|
|
#include <linux/of_address.h>
|
|
|
|
#include <linux/of_platform.h>
|
2015-07-08 05:11:46 +08:00
|
|
|
#include <linux/irqchip.h>
|
2014-03-20 03:21:17 +08:00
|
|
|
#include <linux/irqchip/chained_irq.h>
|
|
|
|
|
|
|
|
#define SUNXI_NMI_SRC_TYPE_MASK 0x00000003
|
|
|
|
|
2017-06-06 13:59:23 +08:00
|
|
|
#define SUNXI_NMI_IRQ_BIT BIT(0)
|
|
|
|
|
2017-06-06 13:59:28 +08:00
|
|
|
/*
|
|
|
|
* For deprecated sun6i-a31-sc-nmi compatible.
|
|
|
|
*/
|
irqchip/sun6i-r: Use a stacked irqchip driver
The R_INTC in the A31 and newer sun8i/sun50i SoCs is more similar to the
original sun4i interrupt controller than the sun7i/sun9i NMI controller.
It is used for two distinct purposes:
- To control the trigger, latch, and mask for the NMI input pin
- To provide the interrupt input for the ARISC coprocessor
As this interrupt controller is not documented, information about it
comes from vendor-provided firmware blobs and from experimentation.
Differences from the sun4i interrupt controller appear to be:
- It only has one or two registers of each kind (max 32 or 64 IRQs)
- Multiplexing logic is added to support additional inputs
- There is no FIQ-related logic
- There is no interrupt priority logic
In order to fulfill its two purposes, this hardware block combines four
types of IRQs. First, the NMI pin is routed to the "IRQ 0" input on this
chip, with a trigger type controlled by the NMI_CTRL_REG. The "IRQ 0
pending" output from this chip, if enabled, is then routed to a SPI IRQ
input on the GIC. In other words, bit 0 of IRQ_ENABLE_REG *does* affect
the NMI IRQ seen at the GIC.
The NMI is followed by a contiguous block of 15 "direct" (my name for
them) IRQ inputs that are connected in parallel to both R_INTC and the
GIC. Or in other words, these bits of IRQ_ENABLE_REG *do not* affect the
IRQs seen at the GIC.
Following the direct IRQs are the ARISC's copy of banked IRQs for shared
peripherals. These are not relevant to Linux. The remaining IRQs are
connected to a multiplexer and provide access to the first (up to) 128
SPIs from the ARISC. This range of SPIs overlaps with the direct IRQs.
Because of the 1:1 correspondence between R_INTC and GIC inputs, this is
a perfect scenario for using a stacked irqchip driver. We want to hook
into setting the NMI trigger type, but not actually handle any IRQ here.
To allow access to all multiplexed IRQs, this driver requires a new
binding where the interrupt number matches the GIC interrupt number.
(This moves the NMI from number 0 to 32 or 96, depending on the SoC.)
For simplicity, copy the three-cell GIC binding; this disambiguates
interrupt 0 in the old binding (the NMI) from interrupt 0 in the new
binding (SPI 0) by the number of cells.
Since R_INTC is in the always-on power domain, and its output is visible
to the power management coprocessor, a stacked irqchip driver provides a
simple way to add wakeup support to any of its IRQs. That is the next
patch; for now, just the NMI is moved over.
This commit mostly reverts commit 173bda53b340 ("irqchip/sunxi-nmi:
Support sun6i-a31-r-intc compatible").
Acked-by: Maxime Ripard <mripard@kernel.org>
Signed-off-by: Samuel Holland <samuel@sholland.org>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20210118055040.21910-4-samuel@sholland.org
2021-01-18 13:50:33 +08:00
|
|
|
#define SUN6I_NMI_CTRL 0x00
|
|
|
|
#define SUN6I_NMI_PENDING 0x04
|
|
|
|
#define SUN6I_NMI_ENABLE 0x34
|
2017-06-06 13:59:23 +08:00
|
|
|
|
|
|
|
#define SUN7I_NMI_CTRL 0x00
|
|
|
|
#define SUN7I_NMI_PENDING 0x04
|
|
|
|
#define SUN7I_NMI_ENABLE 0x08
|
|
|
|
|
|
|
|
#define SUN9I_NMI_CTRL 0x00
|
|
|
|
#define SUN9I_NMI_ENABLE 0x04
|
|
|
|
#define SUN9I_NMI_PENDING 0x08
|
|
|
|
|
2014-03-20 03:21:17 +08:00
|
|
|
enum {
|
|
|
|
SUNXI_SRC_TYPE_LEVEL_LOW = 0,
|
|
|
|
SUNXI_SRC_TYPE_EDGE_FALLING,
|
|
|
|
SUNXI_SRC_TYPE_LEVEL_HIGH,
|
|
|
|
SUNXI_SRC_TYPE_EDGE_RISING,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sunxi_sc_nmi_reg_offs {
|
|
|
|
u32 ctrl;
|
|
|
|
u32 pend;
|
|
|
|
u32 enable;
|
|
|
|
};
|
|
|
|
|
2017-06-06 13:59:26 +08:00
|
|
|
static const struct sunxi_sc_nmi_reg_offs sun6i_reg_offs __initconst = {
|
2017-06-06 13:59:23 +08:00
|
|
|
.ctrl = SUN6I_NMI_CTRL,
|
|
|
|
.pend = SUN6I_NMI_PENDING,
|
|
|
|
.enable = SUN6I_NMI_ENABLE,
|
2014-03-20 03:21:17 +08:00
|
|
|
};
|
|
|
|
|
2017-06-06 13:59:26 +08:00
|
|
|
static const struct sunxi_sc_nmi_reg_offs sun7i_reg_offs __initconst = {
|
2017-06-06 13:59:25 +08:00
|
|
|
.ctrl = SUN7I_NMI_CTRL,
|
|
|
|
.pend = SUN7I_NMI_PENDING,
|
|
|
|
.enable = SUN7I_NMI_ENABLE,
|
|
|
|
};
|
|
|
|
|
2017-06-06 13:59:26 +08:00
|
|
|
static const struct sunxi_sc_nmi_reg_offs sun9i_reg_offs __initconst = {
|
2017-06-06 13:59:23 +08:00
|
|
|
.ctrl = SUN9I_NMI_CTRL,
|
|
|
|
.pend = SUN9I_NMI_PENDING,
|
|
|
|
.enable = SUN9I_NMI_ENABLE,
|
2015-12-03 16:20:12 +08:00
|
|
|
};
|
|
|
|
|
2014-03-20 03:21:17 +08:00
|
|
|
static inline void sunxi_sc_nmi_write(struct irq_chip_generic *gc, u32 off,
|
|
|
|
u32 val)
|
|
|
|
{
|
2014-11-07 14:44:17 +08:00
|
|
|
irq_reg_writel(gc, val, off);
|
2014-03-20 03:21:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline u32 sunxi_sc_nmi_read(struct irq_chip_generic *gc, u32 off)
|
|
|
|
{
|
2014-11-07 14:44:17 +08:00
|
|
|
return irq_reg_readl(gc, off);
|
2014-03-20 03:21:17 +08:00
|
|
|
}
|
|
|
|
|
2015-09-14 16:42:37 +08:00
|
|
|
static void sunxi_sc_nmi_handle_irq(struct irq_desc *desc)
|
2014-03-20 03:21:17 +08:00
|
|
|
{
|
|
|
|
struct irq_domain *domain = irq_desc_get_handler_data(desc);
|
2015-06-04 12:13:20 +08:00
|
|
|
struct irq_chip *chip = irq_desc_get_chip(desc);
|
2014-03-20 03:21:17 +08:00
|
|
|
|
|
|
|
chained_irq_enter(chip, desc);
|
2021-05-05 00:42:18 +08:00
|
|
|
generic_handle_domain_irq(domain, 0);
|
2014-03-20 03:21:17 +08:00
|
|
|
chained_irq_exit(chip, desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sunxi_sc_nmi_set_type(struct irq_data *data, unsigned int flow_type)
|
|
|
|
{
|
|
|
|
struct irq_chip_generic *gc = irq_data_get_irq_chip_data(data);
|
|
|
|
struct irq_chip_type *ct = gc->chip_types;
|
|
|
|
u32 src_type_reg;
|
|
|
|
u32 ctrl_off = ct->regs.type;
|
|
|
|
unsigned int src_type;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
irq_gc_lock(gc);
|
|
|
|
|
|
|
|
switch (flow_type & IRQF_TRIGGER_MASK) {
|
|
|
|
case IRQ_TYPE_EDGE_FALLING:
|
|
|
|
src_type = SUNXI_SRC_TYPE_EDGE_FALLING;
|
|
|
|
break;
|
|
|
|
case IRQ_TYPE_EDGE_RISING:
|
|
|
|
src_type = SUNXI_SRC_TYPE_EDGE_RISING;
|
|
|
|
break;
|
|
|
|
case IRQ_TYPE_LEVEL_HIGH:
|
|
|
|
src_type = SUNXI_SRC_TYPE_LEVEL_HIGH;
|
|
|
|
break;
|
|
|
|
case IRQ_TYPE_NONE:
|
|
|
|
case IRQ_TYPE_LEVEL_LOW:
|
|
|
|
src_type = SUNXI_SRC_TYPE_LEVEL_LOW;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
irq_gc_unlock(gc);
|
2015-10-06 00:42:13 +08:00
|
|
|
pr_err("Cannot assign multiple trigger modes to IRQ %d.\n",
|
|
|
|
data->irq);
|
2014-03-20 03:21:17 +08:00
|
|
|
return -EBADR;
|
|
|
|
}
|
|
|
|
|
|
|
|
irqd_set_trigger_type(data, flow_type);
|
|
|
|
irq_setup_alt_chip(data, flow_type);
|
|
|
|
|
2015-06-07 21:33:29 +08:00
|
|
|
for (i = 0; i < gc->num_ct; i++, ct++)
|
2014-03-20 03:21:17 +08:00
|
|
|
if (ct->type & flow_type)
|
|
|
|
ctrl_off = ct->regs.type;
|
|
|
|
|
|
|
|
src_type_reg = sunxi_sc_nmi_read(gc, ctrl_off);
|
|
|
|
src_type_reg &= ~SUNXI_NMI_SRC_TYPE_MASK;
|
|
|
|
src_type_reg |= src_type;
|
|
|
|
sunxi_sc_nmi_write(gc, ctrl_off, src_type_reg);
|
|
|
|
|
|
|
|
irq_gc_unlock(gc);
|
|
|
|
|
|
|
|
return IRQ_SET_MASK_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init sunxi_sc_nmi_irq_init(struct device_node *node,
|
2017-06-06 13:59:26 +08:00
|
|
|
const struct sunxi_sc_nmi_reg_offs *reg_offs)
|
2014-03-20 03:21:17 +08:00
|
|
|
{
|
|
|
|
struct irq_domain *domain;
|
|
|
|
struct irq_chip_generic *gc;
|
|
|
|
unsigned int irq;
|
|
|
|
unsigned int clr = IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_NOAUTOEN;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
|
|
domain = irq_domain_add_linear(node, 1, &irq_generic_chip_ops, NULL);
|
|
|
|
if (!domain) {
|
2015-10-06 00:42:13 +08:00
|
|
|
pr_err("Could not register interrupt domain.\n");
|
2014-03-20 03:21:17 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2015-10-06 00:42:13 +08:00
|
|
|
ret = irq_alloc_domain_generic_chips(domain, 1, 2, DRV_NAME,
|
2014-03-20 03:21:17 +08:00
|
|
|
handle_fasteoi_irq, clr, 0,
|
|
|
|
IRQ_GC_INIT_MASK_CACHE);
|
|
|
|
if (ret) {
|
2015-10-06 00:42:13 +08:00
|
|
|
pr_err("Could not allocate generic interrupt chip.\n");
|
|
|
|
goto fail_irqd_remove;
|
2014-03-20 03:21:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
irq = irq_of_parse_and_map(node, 0);
|
|
|
|
if (irq <= 0) {
|
2015-10-06 00:42:13 +08:00
|
|
|
pr_err("unable to parse irq\n");
|
2014-03-20 03:21:17 +08:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto fail_irqd_remove;
|
|
|
|
}
|
|
|
|
|
|
|
|
gc = irq_get_domain_generic_chip(domain, 0);
|
2015-10-06 00:42:14 +08:00
|
|
|
gc->reg_base = of_io_request_and_map(node, 0, of_node_full_name(node));
|
2016-03-09 09:21:29 +08:00
|
|
|
if (IS_ERR(gc->reg_base)) {
|
2015-10-06 00:42:13 +08:00
|
|
|
pr_err("unable to map resource\n");
|
2016-03-09 09:21:29 +08:00
|
|
|
ret = PTR_ERR(gc->reg_base);
|
2014-03-20 03:21:17 +08:00
|
|
|
goto fail_irqd_remove;
|
|
|
|
}
|
|
|
|
|
|
|
|
gc->chip_types[0].type = IRQ_TYPE_LEVEL_MASK;
|
|
|
|
gc->chip_types[0].chip.irq_mask = irq_gc_mask_clr_bit;
|
|
|
|
gc->chip_types[0].chip.irq_unmask = irq_gc_mask_set_bit;
|
|
|
|
gc->chip_types[0].chip.irq_eoi = irq_gc_ack_set_bit;
|
|
|
|
gc->chip_types[0].chip.irq_set_type = sunxi_sc_nmi_set_type;
|
|
|
|
gc->chip_types[0].chip.flags = IRQCHIP_EOI_THREADED | IRQCHIP_EOI_IF_HANDLED;
|
|
|
|
gc->chip_types[0].regs.ack = reg_offs->pend;
|
|
|
|
gc->chip_types[0].regs.mask = reg_offs->enable;
|
|
|
|
gc->chip_types[0].regs.type = reg_offs->ctrl;
|
|
|
|
|
|
|
|
gc->chip_types[1].type = IRQ_TYPE_EDGE_BOTH;
|
|
|
|
gc->chip_types[1].chip.name = gc->chip_types[0].chip.name;
|
|
|
|
gc->chip_types[1].chip.irq_ack = irq_gc_ack_set_bit;
|
|
|
|
gc->chip_types[1].chip.irq_mask = irq_gc_mask_clr_bit;
|
|
|
|
gc->chip_types[1].chip.irq_unmask = irq_gc_mask_set_bit;
|
|
|
|
gc->chip_types[1].chip.irq_set_type = sunxi_sc_nmi_set_type;
|
|
|
|
gc->chip_types[1].regs.ack = reg_offs->pend;
|
|
|
|
gc->chip_types[1].regs.mask = reg_offs->enable;
|
|
|
|
gc->chip_types[1].regs.type = reg_offs->ctrl;
|
|
|
|
gc->chip_types[1].handler = handle_edge_irq;
|
|
|
|
|
2017-06-06 13:59:24 +08:00
|
|
|
/* Disable any active interrupts */
|
2014-03-20 03:21:17 +08:00
|
|
|
sunxi_sc_nmi_write(gc, reg_offs->enable, 0);
|
2017-06-06 13:59:24 +08:00
|
|
|
|
|
|
|
/* Clear any pending NMI interrupts */
|
2017-06-06 13:59:23 +08:00
|
|
|
sunxi_sc_nmi_write(gc, reg_offs->pend, SUNXI_NMI_IRQ_BIT);
|
2014-03-20 03:21:17 +08:00
|
|
|
|
irqchip/sunxi-nmi: Consolidate chained IRQ handler install/remove
Chained irq handlers usually set up handler data as well. We now have
a function to set both under irq_desc->lock. Replace the two calls
with one.
Search and conversion was done with coccinelle:
@@
expression E1, E2, E3;
@@
(
-if (irq_set_handler_data(E1, E2) != 0)
- BUG();
|
-irq_set_handler_data(E1, E2);
)
-irq_set_chained_handler(E1, E3);
+irq_set_chained_handler_and_data(E1, E3, E2);
@@
expression E1, E2, E3;
@@
(
-if (irq_set_handler_data(E1, E2) != 0)
- BUG();
...
|
-irq_set_handler_data(E1, E2);
...
)
-irq_set_chained_handler(E1, E3);
+irq_set_chained_handler_and_data(E1, E3, E2);
Reported-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Julia Lawall <Julia.Lawall@lip6.fr>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Jason Cooper <jason@lakedaemon.net>
Cc: Maxime Ripard <maxime.ripard@free-electrons.com>
Cc: linux-arm-kernel@lists.infradead.org
2015-06-22 03:10:58 +08:00
|
|
|
irq_set_chained_handler_and_data(irq, sunxi_sc_nmi_handle_irq, domain);
|
2014-03-28 01:02:39 +08:00
|
|
|
|
2014-03-20 03:21:17 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail_irqd_remove:
|
|
|
|
irq_domain_remove(domain);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init sun6i_sc_nmi_irq_init(struct device_node *node,
|
|
|
|
struct device_node *parent)
|
|
|
|
{
|
|
|
|
return sunxi_sc_nmi_irq_init(node, &sun6i_reg_offs);
|
|
|
|
}
|
|
|
|
IRQCHIP_DECLARE(sun6i_sc_nmi, "allwinner,sun6i-a31-sc-nmi", sun6i_sc_nmi_irq_init);
|
|
|
|
|
|
|
|
static int __init sun7i_sc_nmi_irq_init(struct device_node *node,
|
|
|
|
struct device_node *parent)
|
|
|
|
{
|
|
|
|
return sunxi_sc_nmi_irq_init(node, &sun7i_reg_offs);
|
|
|
|
}
|
|
|
|
IRQCHIP_DECLARE(sun7i_sc_nmi, "allwinner,sun7i-a20-sc-nmi", sun7i_sc_nmi_irq_init);
|
2015-12-03 16:20:12 +08:00
|
|
|
|
|
|
|
static int __init sun9i_nmi_irq_init(struct device_node *node,
|
|
|
|
struct device_node *parent)
|
|
|
|
{
|
|
|
|
return sunxi_sc_nmi_irq_init(node, &sun9i_reg_offs);
|
|
|
|
}
|
|
|
|
IRQCHIP_DECLARE(sun9i_nmi, "allwinner,sun9i-a80-nmi", sun9i_nmi_irq_init);
|