From patchwork Wed Jun 14 16:29:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Elwell X-Patchwork-Id: 9786905 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 BA4CA6038E for ; Wed, 14 Jun 2017 16:30:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB68A274D0 for ; Wed, 14 Jun 2017 16:30:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9FC65285AE; Wed, 14 Jun 2017 16:30:42 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0332B284F1 for ; Wed, 14 Jun 2017 16:30:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752554AbdFNQaf (ORCPT ); Wed, 14 Jun 2017 12:30:35 -0400 Received: from mx07-00252a01.pphosted.com ([62.209.51.214]:33586 "EHLO mx07-00252a01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752426AbdFNQ3j (ORCPT ); Wed, 14 Jun 2017 12:29:39 -0400 Received: from pps.filterd (m0102628.ppops.net [127.0.0.1]) by mx07-00252a01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v5EGTYEx023589 for ; Wed, 14 Jun 2017 17:29:38 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.org; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=pp; bh=3a09V/DEIz5CjQqoBS3Uu6n9rLq0B5J5AF8DgkOkhiM=; b=lRo1+Id5LEz80CE3ro+elzfNVTKf4v2xMDxKziAqCTTXh13e5PkIgdFFSbDoo1clKqVv NpUHr//FLCw7be2UTw387KZ0Nuv3zsGzfluohquyBRvHjWvjpRAs/WDrPJ1u9f/IjqYP d4BcqHnXjUVNfbcpxN1ppR+MtcDEhs47zYcCiAIp8nQfwo+nGKr2aJRDdrbPwOVXkwBb kd9cgaPVN5sykyTL5xku9ZKLzohfSzYap5wb9R8tydkx87icwa1uc0PQIVw3LqoUSkVq 56beuZGUGrllU4qDrUSUz3iZ/ysuzYwcgezOvCJNLaGWTGRSCpx1Tkne/I2rKAXsm/9s rw== Received: from mail-wr0-f198.google.com (mail-wr0-f198.google.com [209.85.128.198]) by mx07-00252a01.pphosted.com with ESMTP id 2b065yt4yb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=OK) for ; Wed, 14 Jun 2017 17:29:38 +0100 Received: by mail-wr0-f198.google.com with SMTP id l34so1533296wrc.12 for ; Wed, 14 Jun 2017 09:29:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3a09V/DEIz5CjQqoBS3Uu6n9rLq0B5J5AF8DgkOkhiM=; b=HiUu6ulULLHj97w0znavC7Wz3R3WXb+7G+Mo3hqu0n2yzyg4+ONPBdjuDn1fbmjvCt SJIa7SH2LxJKwu/T6mRyfwb2WvH+cIBXKEWLDnqqulv3MaIW/YM8h8PMNRCI743T6Bwa MmKks9aNOZrMI6VMrjqxjuxQIndM6Vc9LUV+mzlCuImLu1XR+PeZpjzkfXvfh0DqTZHk MDrncfIiCmimKvHDhaUm+SutnRim2Y3xBW6L1jEolHgDh0ELRSUYxF+o2Ycfno9RvGJe jJLf5AZ8jnf1SWOElqhv1wa69O+wM2PrP7dO07DVXAwI5+4v1Z3qQ1frGFxlB3b4c9Ra BwEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=3a09V/DEIz5CjQqoBS3Uu6n9rLq0B5J5AF8DgkOkhiM=; b=sjt0zIQytjyTmgNtisxbE/5+aGsr38dZwBrBI81xrurUkbQzFjfEorqn5hOxP26VUm prflLbvTGvq2GZUK8LYQ9O+N00E+HWQRO6DOEG0WuBASDrqmT43RARlPA5+55HrXlxVo rKuM5pMG34Snyd5yPFupUK9ykk8Sse/1zt1zsVepPAtKwHwKibsU2mgzF7g0eVgLOj2F GQlFLqpJ23hGLUV/G6S5tIqYuQOxUDAMkogVpC4rcxlA7lycP0UBoQMLdnGJ0iIIxZUH +1i8qUHwEmo7BRIO6FTvCYkWID4zEey3TnXP5uw5FKjUg43iQNVJahTfgEjxylZn1zKi 5TsA== X-Gm-Message-State: AKS2vOzlX8b+vR19mjB5hYQrxafGPwqX8Gzm2IrCjS6W8qf9e2m5yNkf 5iza5FYXABdRAZLn5w3nKdJxN+NKeRoOwVjh6WgJpOBokXWQVDEBK+8hGDPmsdm7a0S4AUy9rhp f4eHYg7yS/bU= X-Received: by 10.223.166.8 with SMTP id k8mr685817wrc.172.1497457777661; Wed, 14 Jun 2017 09:29:37 -0700 (PDT) X-Received: by 10.223.166.8 with SMTP id k8mr685793wrc.172.1497457777446; Wed, 14 Jun 2017 09:29:37 -0700 (PDT) Received: from buildbot.pitowers.org ([217.33.127.173]) by smtp.gmail.com with ESMTPSA id e24sm545129wre.54.2017.06.14.09.29.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Jun 2017 09:29:36 -0700 (PDT) From: Phil Elwell To: Thomas Gleixner , Jason Cooper , Marc Zyngier , Rob Herring , Mark Rutland , Florian Fainelli , Stefan Wahren , Eric Anholt , Russell King , Michael Turquette , Stephen Boyd , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-clk@vger.kernel.org Cc: Phil Elwell Subject: [PATCH v3 3/4] irqchip: Add BCM2835 AUX interrupt controller Date: Wed, 14 Jun 2017 17:29:09 +0100 Message-Id: <1497457750-35585-4-git-send-email-phil@raspberrypi.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1497457750-35585-1-git-send-email-phil@raspberrypi.org> References: <4ceb6c92-f752-180e-6a6e-a94dcd120737@raspberrypi.org> <1497457750-35585-1-git-send-email-phil@raspberrypi.org> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-06-14_03:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_spam_notspam policy=outbound_spam score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1706140277 Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Devices in the BCM2835 AUX block share a common interrupt line, with a register indicating which devices have active IRQs. Expose this as a nested interrupt controller to avoid IRQ sharing problems (easily observed if UART1 and SPI1/2 are enabled simultaneously). Signed-off-by: Phil Elwell --- drivers/irqchip/Makefile | 2 +- drivers/irqchip/irq-bcm2835-aux.c | 153 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 drivers/irqchip/irq-bcm2835-aux.c diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile index b64c59b..cf01920 100644 --- a/drivers/irqchip/Makefile +++ b/drivers/irqchip/Makefile @@ -3,7 +3,7 @@ obj-$(CONFIG_IRQCHIP) += irqchip.o obj-$(CONFIG_ALPINE_MSI) += irq-alpine-msi.o 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-bcm2835.o irq-bcm2835-aux.o obj-$(CONFIG_ARCH_BCM2835) += irq-bcm2836.o obj-$(CONFIG_ARCH_EXYNOS) += exynos-combiner.o obj-$(CONFIG_FARADAY_FTINTC010) += irq-ftintc010.o diff --git a/drivers/irqchip/irq-bcm2835-aux.c b/drivers/irqchip/irq-bcm2835-aux.c new file mode 100644 index 0000000..2151d51 --- /dev/null +++ b/drivers/irqchip/irq-bcm2835-aux.c @@ -0,0 +1,153 @@ +/* + * Copyright (C) 2017 Raspberry Pi (Trading) Ltd. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include + +#define BCM2835_AUXIRQ 0x00 + +#define BCM2835_AUX_IRQ_UART_MASK BIT(BCM2835_AUX_IRQ_UART) +#define BCM2835_AUX_IRQ_SPI1_MASK BIT(BCM2835_AUX_IRQ_SPI1) +#define BCM2835_AUX_IRQ_SPI2_MASK BIT(BCM2835_AUX_IRQ_SPI2) + +#define BCM2835_AUX_IRQ_ALL_MASK \ + (BCM2835_AUX_IRQ_UART_MASK | \ + BCM2835_AUX_IRQ_SPI1_MASK | \ + BCM2835_AUX_IRQ_SPI2_MASK) + +struct aux_irq_state { + void __iomem *status; + struct irq_domain *domain; +}; + +static struct aux_irq_state aux_irq __read_mostly; + +static irqreturn_t bcm2835_aux_irq_handler(int irq, void *dev_id) +{ + u32 stat = readl_relaxed(aux_irq.status); + + if (stat & BCM2835_AUX_IRQ_UART_MASK) + generic_handle_irq(irq_linear_revmap(aux_irq.domain, + BCM2835_AUX_IRQ_UART)); + + if (stat & BCM2835_AUX_IRQ_SPI1_MASK) + generic_handle_irq(irq_linear_revmap(aux_irq.domain, + BCM2835_AUX_IRQ_SPI1)); + + if (stat & BCM2835_AUX_IRQ_SPI2_MASK) + generic_handle_irq(irq_linear_revmap(aux_irq.domain, + BCM2835_AUX_IRQ_SPI2)); + + return (stat & BCM2835_AUX_IRQ_ALL_MASK) ? IRQ_HANDLED : IRQ_NONE; +} + +/* + * The irq_mask and irq_unmask function pointers are used without + * validity checks, so they must not be NULL. Create a dummy function + * with the expected type for use as a no-op. + */ +static void bcm2835_aux_irq_dummy(struct irq_data *data) +{ +} + +static struct irq_chip bcm2835_aux_irq_chip = { + .name = "bcm2835-aux_irq", + .irq_mask = bcm2835_aux_irq_dummy, + .irq_unmask = bcm2835_aux_irq_dummy, +}; + +static int bcm2835_aux_irq_xlate(struct irq_domain *d, + struct device_node *ctrlr, + const u32 *intspec, unsigned int intsize, + unsigned long *out_hwirq, + unsigned int *out_type) +{ + if (WARN_ON(intsize != 1)) + return -EINVAL; + + if (WARN_ON(intspec[0] >= BCM2835_AUX_IRQ_COUNT)) + return -EINVAL; + + *out_hwirq = intspec[0]; + *out_type = IRQ_TYPE_LEVEL_HIGH; + + return 0; +} + +static int bcm2835_aux_irq_map(struct irq_domain *d, unsigned int irq, + irq_hw_number_t hwirq) +{ + irq_set_chip_and_handler(irq, &bcm2835_aux_irq_chip, + handle_level_irq); + return 0; +} + +static const struct irq_domain_ops bcm2835_aux_irq_ops = { + .xlate = bcm2835_aux_irq_xlate, + .map = bcm2835_aux_irq_map, +}; + +static int bcm2835_aux_irq_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *node = dev->of_node; + int parent_irq; + struct resource *res; + void __iomem *reg; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + reg = devm_ioremap_resource(dev, res); + if (IS_ERR(reg)) + return PTR_ERR(reg); + + parent_irq = irq_of_parse_and_map(node, 0); + if (!parent_irq) + return -ENXIO; + + aux_irq.status = reg + BCM2835_AUXIRQ; + aux_irq.domain = irq_domain_add_linear(node, + BCM2835_AUX_IRQ_COUNT, + &bcm2835_aux_irq_ops, + NULL); + if (!aux_irq.domain) + return -ENXIO; + + return devm_request_irq(dev, parent_irq, bcm2835_aux_irq_handler, + 0, "bcm2835-aux-intc", NULL); +} + +static const struct of_device_id bcm2835_aux_irq_of_match[] = { + { .compatible = "brcm,bcm2835-aux-intc", }, + {}, +}; +MODULE_DEVICE_TABLE(of, bcm2835_aux_irq_of_match); + +static struct platform_driver bcm2835_aux_irq_driver = { + .driver = { + .name = "bcm2835-aux-intc", + .of_match_table = bcm2835_aux_irq_of_match, + }, + .probe = bcm2835_aux_irq_probe, +}; +builtin_platform_driver(bcm2835_aux_irq_driver); + +MODULE_AUTHOR("Phil Elwell "); +MODULE_DESCRIPTION("BCM2835 auxiliary peripheral interrupt driver"); +MODULE_LICENSE("GPL v2");