From patchwork Mon Aug 28 13:58:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mason X-Patchwork-Id: 9925559 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5457B60329 for ; Mon, 28 Aug 2017 13:59:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 456C6286BF for ; Mon, 28 Aug 2017 13:59:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3A197286C4; Mon, 28 Aug 2017 13:59:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 73220286C0 for ; Mon, 28 Aug 2017 13:59:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date: Message-ID:From:References:To:Subject:Reply-To:Content-ID:Content-Description :Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=rCkbgMz1DkMhvHHgENxzdXfKM0gIAiDfUmYRxHywjyE=; b=S9zi03mVC5JFs5 sJbxwP0sepBVBdGPrDacehatFg5ZRGVYoR/qK22lD+a7/xGpxvQqD/KTqSwP5RrAW+3ewkZGjp1FJ I5u71Y75o48JJTQnYxWlAUQxeoZ0Po4kAO+WD7+xVu7GpTd4qAMcqWK8BTvtIyK+tTQDF8bz+mHzD yqb91Qkyl8cC2KomPNN9U5CnEr0aLLXQKYW3fyk1EzLhc4DYygsTN7YdZ1hEVyR2xHOJuYbzDdXq9 e9VLVRAUJAu7rGM80JjZYhVNpGKhjHHrFjYSb1p5P8sLKnhfE8wFNr0MLRkd3Ajj88/HU4FO/9tIi gmHiW+JxS6my71hQKe1w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dmKZY-0000tt-Qe; Mon, 28 Aug 2017 13:59:24 +0000 Received: from smtp5-g21.free.fr ([2a01:e0c:1:1599::14]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dmKZU-0000rA-H4 for linux-arm-kernel@lists.infradead.org; Mon, 28 Aug 2017 13:59:22 +0000 Received: from [172.27.0.114] (unknown [92.154.11.170]) (Authenticated sender: slash.tmp) by smtp5-g21.free.fr (Postfix) with ESMTPSA id 603D85FF67; Mon, 28 Aug 2017 15:58:36 +0200 (CEST) Subject: [PATCH v7] irqchip: Add support for tango interrupt mapper To: Marc Zyngier , Thomas Gleixner , Jason Cooper References: <657580dd-0cfe-e377-e425-0deabf6d20c3@free.fr> <20170606175219.34ef62b9@free-electrons.com> <24f34220-a017-f4e0-b72e-d1fdb014c0e1@free.fr> <9f384711-eef0-5117-b89c-9d2dc16e5ae5@free.fr> <473118cd-20dc-3534-d0d8-88799e3d2c3b@free.fr> <21670cea-beaf-8a41-84fb-f3c892527b0e@free.fr> <29109a5f-3c0d-374a-97d5-f98b365d0e0e@arm.com> From: Mason Message-ID: <0ade4a95-c7b9-1904-c639-d986255c7530@free.fr> Date: Mon, 28 Aug 2017 15:58:35 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0 SeaMonkey/2.49.1 MIME-Version: 1.0 In-Reply-To: <29109a5f-3c0d-374a-97d5-f98b365d0e0e@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170828_065920_895299_C58A3309 X-CRM114-Status: GOOD ( 18.62 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Petazzoni , Mark Rutland , Thibaud Cornic , LKML , Linux ARM Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This controller maps 128 input lines to 24 output lines. The 24 output lines are routed to GIC SPI 0 to 23. This driver only allocates exclusive output lines (hierarchy). Let the legacy controller mux latency-insensitive interrupts. --- Changes from v6 to v7 * Muxing level interrupts leaves performance on the table => Give "important" interrupts a dedicated output line (hierarchical setup). And let the legacy interrupt controller mux "less important" interrupts. * Use a bitmap to manage output line allocation * Don't panic on error; clean up and return error code --- .../interrupt-controller/sigma,smp8759-intc.txt | 18 +++ drivers/irqchip/Makefile | 2 +- drivers/irqchip/irq-smp8759.c | 158 +++++++++++++++++++++ 3 files changed, 177 insertions(+), 1 deletion(-) create mode 100644 Documentation/devicetree/bindings/interrupt-controller/sigma,smp8759-intc.txt create mode 100644 drivers/irqchip/irq-smp8759.c diff --git a/Documentation/devicetree/bindings/interrupt-controller/sigma,smp8759-intc.txt b/Documentation/devicetree/bindings/interrupt-controller/sigma,smp8759-intc.txt new file mode 100644 index 000000000000..f4864979ab44 --- /dev/null +++ b/Documentation/devicetree/bindings/interrupt-controller/sigma,smp8759-intc.txt @@ -0,0 +1,18 @@ +Sigma Designs SMP8759 interrupt mapper + +Required properties: +- compatible: "sigma,smp8759-intc" +- reg: address/size of register area +- interrupt-controller +- #interrupt-cells: <2> (hwirq and trigger_type) +- interrupt-parent: parent phandle + +Example: + + interrupt-controller@6f800 { + compatible = "sigma,smp8759-intc"; + reg = <0x6f800 0x430>; + interrupt-controller; + #interrupt-cells = <2>; + interrupt-parent = <&gic>; + }; diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile index e4dbfc85abdb..013104923b71 100644 --- a/drivers/irqchip/Makefile +++ b/drivers/irqchip/Makefile @@ -47,7 +47,7 @@ obj-$(CONFIG_VERSATILE_FPGA_IRQ) += irq-versatile-fpga.o obj-$(CONFIG_ARCH_NSPIRE) += irq-zevio.o obj-$(CONFIG_ARCH_VT8500) += irq-vt8500.o obj-$(CONFIG_ST_IRQCHIP) += irq-st.o -obj-$(CONFIG_TANGO_IRQ) += irq-tango.o +obj-$(CONFIG_TANGO_IRQ) += irq-tango.o irq-smp8759.o obj-$(CONFIG_TB10X_IRQC) += irq-tb10x.o obj-$(CONFIG_TS4800_IRQ) += irq-ts4800.o obj-$(CONFIG_XTENSA) += irq-xtensa-pic.o diff --git a/drivers/irqchip/irq-smp8759.c b/drivers/irqchip/irq-smp8759.c new file mode 100644 index 000000000000..359ab706f504 --- /dev/null +++ b/drivers/irqchip/irq-smp8759.c @@ -0,0 +1,158 @@ +#include +#include +#include +#include +#include + +/* + * This controller maps IRQ_MAX input lines to SPI_MAX output lines. + * The output lines are routed to GIC SPI 0 to 23. + * This driver only allocates exclusive output lines (hierarchy). + * Let the legacy controller mux latency-insensitive interrupts. + */ +#define IRQ_MAX 128 +#define SPI_MAX 24 +#define IRQ_ENABLE BIT(31) +#define STATUS 0x420 + +struct tango_intc { + void __iomem *base; + DECLARE_BITMAP(used_spi, SPI_MAX); + DECLARE_BITMAP(enabled_irq, IRQ_MAX); + u8 tango_irq_to_spi[IRQ_MAX]; + spinlock_t lock; +}; + +static struct tango_intc *tango_intc; + +static void tango_mask(struct irq_data *data) +{ + unsigned long flags; + struct tango_intc *intc = data->chip_data; + + spin_lock_irqsave(&intc->lock, flags); + writel_relaxed(0, intc->base + data->hwirq * 4); + __clear_bit(data->hwirq, intc->enabled_irq); + spin_unlock_irqrestore(&intc->lock, flags); + + irq_chip_mask_parent(data); +} + +static void tango_unmask(struct irq_data *data) +{ + unsigned long flags; + struct tango_intc *intc = data->chip_data; + u32 val = IRQ_ENABLE | intc->tango_irq_to_spi[data->hwirq]; + + spin_lock_irqsave(&intc->lock, flags); + writel_relaxed(val, intc->base + data->hwirq * 4); + __set_bit(data->hwirq, intc->enabled_irq); + spin_unlock_irqrestore(&intc->lock, flags); + + irq_chip_unmask_parent(data); +} + +static struct irq_chip tango_chip = { + .name = "mapper", + .irq_mask = tango_mask, + .irq_unmask = tango_unmask, + .irq_eoi = irq_chip_eoi_parent, + .irq_set_type = irq_chip_set_type_parent, +}; + +static int alloc_gic_irq(struct irq_domain *dom, uint virq, u32 spi, u32 type) +{ + struct fwnode_handle *gic = dom->parent->fwnode; + struct irq_fwspec gic_fwspec = { gic, 3, { 0, spi, type }}; + return irq_domain_alloc_irqs_parent(dom, virq, 1, &gic_fwspec); +} + +static int tango_alloc(struct irq_domain *dom, uint virq, uint nirq, void *arg) +{ + int err, spi; + unsigned long flags; + struct irq_fwspec *fwspec = arg; + struct tango_intc *intc = dom->host_data; + u32 hwirq = fwspec->param[0], type = fwspec->param[1]; + + if (type & IRQ_TYPE_EDGE_FALLING || type & IRQ_TYPE_LEVEL_LOW) + return -EINVAL; + + spin_lock_irqsave(&intc->lock, flags); + spi = find_first_zero_bit(intc->used_spi, SPI_MAX); + if (spi >= SPI_MAX) { + spin_unlock_irqrestore(&intc->lock, flags); + return -ENOSPC; + } + __set_bit(spi, intc->used_spi); + spin_unlock_irqrestore(&intc->lock, flags); + + err = alloc_gic_irq(dom, virq, spi, type); + if (err) { + spin_lock_irqsave(&intc->lock, flags); + __clear_bit(spi, intc->used_spi); + spin_unlock_irqrestore(&intc->lock, flags); + return err; + } + + intc->tango_irq_to_spi[hwirq] = spi; + irq_domain_set_hwirq_and_chip(dom, virq, hwirq, &tango_chip, intc); + + return 0; +} + +static struct irq_domain_ops dom_ops = { + .xlate = irq_domain_xlate_twocell, + .alloc = tango_alloc, +}; + +static void tango_resume(void) +{ + int hwirq; + struct tango_intc *intc = tango_intc; + + for (hwirq = 0; hwirq < IRQ_MAX; ++hwirq) { + u32 val = intc->tango_irq_to_spi[hwirq]; + if (test_bit(hwirq, intc->enabled_irq)) + val |= IRQ_ENABLE; + writel_relaxed(val, intc->base + hwirq * 4); + } +} + +static struct syscore_ops tango_syscore_ops = { + .resume = tango_resume, +}; + +static int __init tango_irq_init(struct device_node *node, struct device_node *parent) +{ + struct tango_intc *intc; + struct irq_domain *dom, *gic_dom; + + gic_dom = irq_find_host(parent); + if (!gic_dom) + return -ENODEV; + + intc = kzalloc(sizeof(*intc), GFP_KERNEL); + if (!intc) + return -ENOMEM; + + intc->base = of_iomap(node, 0); + if (!intc->base) { + kfree(intc); + return -ENXIO; + } + + dom = irq_domain_add_hierarchy(gic_dom, 0, IRQ_MAX, node, &dom_ops, intc); + if (!dom) { + iounmap(intc->base); + kfree(intc); + return -ENOMEM; + } + + tango_intc = intc; + register_syscore_ops(&tango_syscore_ops); + spin_lock_init(&intc->lock); + + return 0; +} +IRQCHIP_DECLARE(tango_intc, "sigma,smp8759-intc", tango_irq_init);