From patchwork Thu Aug 17 10:11:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 9905593 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 3B9F060386 for ; Thu, 17 Aug 2017 10:19:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F5A028AB2 for ; Thu, 17 Aug 2017 10:19:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 33FC528ACA; Thu, 17 Aug 2017 10:19:36 +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,RCVD_IN_DNSWL_LOW autolearn=ham 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 8DEF628AB2 for ; Thu, 17 Aug 2017 10:19:35 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=120aMre/8HrOnvyZ6tS+8aG9qhhL1D2q00a5CbJSNqs=; b=EpnvOdsuVLdTA8 Zwgduw10+nOnMRRrwDZdeGtzxlH3jy6gygTqVu2eyOFyRZbV6lNBbSqJGAnWOwBPvcG2+uTbkDnIz 1C9yhgRn0g7EzKy/DZXRRYmK5hUzCYXl6q5R/HPNdwXLTYcQsrgYDlfPrNA9g3fzMZ11uXOpf0HLw q0jsobNQT6h6+kjP+SHyOVT3Ft9GdExLu/ZaLTGdB5sTXQUFCRLmQp8kSbOMondHlyS0mInCYRrx1 dUe6Tbwpy3vVqOmEo/Kk5dZe2dDwJGUeLGe8pV9hTwVASNkudXKIkadvEsB895VUmHpdmNgGiBuKv yKapDeEMMwuXwBJNOpVg==; 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 1diHtY-0001i9-Ce; Thu, 17 Aug 2017 10:19:20 +0000 Received: from mx2.suse.de ([195.135.220.15] helo=mx1.suse.de) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1diHmf-0004hs-KE for linux-arm-kernel@lists.infradead.org; Thu, 17 Aug 2017 10:12:18 +0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 5CD03AF81; Thu, 17 Aug 2017 10:11:49 +0000 (UTC) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: Thomas Gleixner , Jason Cooper , Marc Zyngier , linux-arm-kernel@lists.infradead.org Subject: [RFC 3/3] irqchip: Add Realtek RTD1295 mux driver Date: Thu, 17 Aug 2017 12:11:40 +0200 Message-Id: <20170817101140.32000-4-afaerber@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20170817101140.32000-1-afaerber@suse.de> References: <20170817101140.32000-1-afaerber@suse.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170817_031214_107920_CA0589DC X-CRM114-Status: GOOD ( 17.36 ) 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: =?UTF-8?q?=E8=92=8B=E4=B8=BD=E7=90=B4?= , linux-kernel@vger.kernel.org, =?UTF-8?q?Andreas=20F=C3=A4rber?= , Roc He 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 irq mux driver is derived from the RTD1295 vendor DT and assumes a linear mapping between intr_en and intr_status registers. Code for RTD119x indicates this may not always be the case (i2c_3). The register initialization was copied from QNAP's mach-rtk119x/rtk_irq_mux.c as a boot fix, without full insights into what exactly this is changing (TODO). Signed-off-by: Andreas Färber --- drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-rtd119x-mux.c | 201 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 202 insertions(+) create mode 100644 drivers/irqchip/irq-rtd119x-mux.c diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile index e88d856cc09c..46202a0b7d96 100644 --- a/drivers/irqchip/Makefile +++ b/drivers/irqchip/Makefile @@ -78,3 +78,4 @@ obj-$(CONFIG_EZNPS_GIC) += irq-eznps.o obj-$(CONFIG_ARCH_ASPEED) += irq-aspeed-vic.o irq-aspeed-i2c-ic.o obj-$(CONFIG_STM32_EXTI) += irq-stm32-exti.o obj-$(CONFIG_QCOM_IRQ_COMBINER) += qcom-irq-combiner.o +obj-$(CONFIG_ARCH_REALTEK) += irq-rtd119x-mux.o diff --git a/drivers/irqchip/irq-rtd119x-mux.c b/drivers/irqchip/irq-rtd119x-mux.c new file mode 100644 index 000000000000..c6c1ba126bf3 --- /dev/null +++ b/drivers/irqchip/irq-rtd119x-mux.c @@ -0,0 +1,201 @@ +/* + * Realtek RTD129x IRQ mux + * + * Copyright (c) 2017 Andreas Färber + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include +#include +#include +#include + +struct rtd119x_irq_mux_info { + unsigned intr_status; + unsigned intr_en; +}; + +struct rtd119x_irq_mux_data { + void __iomem *intr_status; + void __iomem *intr_en; + int irq; + struct irq_domain *domain; + spinlock_t lock; +}; + +static void rtd119x_mux_irq_handle(struct irq_desc *desc) +{ + struct rtd119x_irq_mux_data *data = irq_desc_get_handler_data(desc); + struct irq_chip *chip = irq_desc_get_chip(desc); + u32 intr_en, intr_status, status; + int ret; + + chained_irq_enter(chip, desc); + + spin_lock(&data->lock); + intr_en = readl(data->intr_en); + intr_status = readl(data->intr_status); + spin_unlock(&data->lock); + + status = intr_status & intr_en; + if (status != 0) { + unsigned irq = __ffs(status); + ret = generic_handle_irq(irq_find_mapping(data->domain, irq)); + if (ret == 0) { + spin_lock(&data->lock); + intr_status = readl(data->intr_status); + intr_status |= BIT(irq - 1); + writel(intr_status, data->intr_status); + spin_unlock(&data->lock); + } + } + + chained_irq_exit(chip, desc); +} + +static void rtd119x_mux_mask_irq(struct irq_data *data) +{ + struct rtd119x_irq_mux_data *mux_data = irq_data_get_irq_chip_data(data); + u32 intr_status; + + intr_status = readl(mux_data->intr_status); + intr_status |= BIT(data->hwirq); + writel(intr_status, mux_data->intr_status); +} + +static void rtd119x_mux_unmask_irq(struct irq_data *data) +{ + struct rtd119x_irq_mux_data *mux_data = irq_data_get_irq_chip_data(data); + u32 intr_en; + + intr_en = readl(mux_data->intr_en); + intr_en |= BIT(data->hwirq); + writel(intr_en, mux_data->intr_en); +} + +static int rtd119x_mux_set_affinity(struct irq_data *d, + const struct cpumask *mask_val, bool force) +{ + struct rtd119x_irq_mux_data *mux_data = irq_data_get_irq_chip_data(d); + struct irq_chip *chip = irq_get_chip(mux_data->irq); + struct irq_data *data = irq_get_irq_data(mux_data->irq); + + if (chip && chip->irq_set_affinity) + return chip->irq_set_affinity(data, mask_val, force); + + return -EINVAL; +} + +static struct irq_chip rtd119x_mux_irq_chip = { + .name = "rtd119x-mux", + .irq_mask = rtd119x_mux_mask_irq, + .irq_unmask = rtd119x_mux_unmask_irq, + .irq_set_affinity = rtd119x_mux_set_affinity, +}; + +static int rtd119x_mux_irq_domain_xlate(struct irq_domain *d, + struct device_node *controller, + const u32 *intspec, unsigned int intsize, + unsigned long *out_hwirq, + unsigned int *out_type) +{ + if (irq_domain_get_of_node(d) != controller) + return -EINVAL; + + if (intsize < 1) + return -EINVAL; + + *out_hwirq = intspec[0]; + *out_type = 0; + + return 0; +} + +static int rtd119x_mux_irq_domain_map(struct irq_domain *d, + unsigned int irq, irq_hw_number_t hw) +{ + struct rtd119x_irq_mux_data *data = d->host_data; + + irq_set_chip_and_handler(irq, &rtd119x_mux_irq_chip, handle_level_irq); + irq_set_chip_data(irq, data); + irq_set_probe(irq); + + return 0; +} + +static struct irq_domain_ops rtd119x_mux_irq_domain_ops = { + .xlate = rtd119x_mux_irq_domain_xlate, + .map = rtd119x_mux_irq_domain_map, +}; + +static int __init rtd119x_irq_mux_init(struct device_node *node, + struct device_node *parent, + const struct rtd119x_irq_mux_info *info) +{ + struct rtd119x_irq_mux_data *data; + void __iomem *base; + u32 val; + + base = of_iomap(node, 0); + if (IS_ERR(base)) + return PTR_ERR(base); + + data = kzalloc(sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + data->intr_status = base + info->intr_status; + data->intr_en = base + info->intr_en; + + data->irq = irq_of_parse_and_map(node, 0); + if (data->irq <= 0) { + kfree(data); + return -EINVAL; + } + + data->domain = irq_domain_add_linear(node, 32, + &rtd119x_mux_irq_domain_ops, data); + if (!data->domain) { + kfree(data); + return -ENOMEM; + } + + /* TODO Investigate why these are necessary (from downstream rtk119x rtk_irq_mux.c) */ + val = readl(data->intr_en); + val &= ~BIT(2); + writel(val, data->intr_en); + + writel(BIT(2), data->intr_status); + + irq_set_chained_handler_and_data(data->irq, rtd119x_mux_irq_handle, data); + + return 0; +} + +static const struct rtd119x_irq_mux_info rtd1295_iso_irq_mux_info = { + .intr_status = 0x0, + .intr_en = 0x40, +}; + +static int __init rtd1295_iso_irq_mux_init(struct device_node *node, + struct device_node *parent) +{ + return rtd119x_irq_mux_init(node, parent, &rtd1295_iso_irq_mux_info); +} +IRQCHIP_DECLARE(rtd1295_iso_mux, "realtek,rtd1295-iso-irq-mux", rtd1295_iso_irq_mux_init); + +static const struct rtd119x_irq_mux_info rtd1295_irq_mux_info = { + .intr_status = 0xc, + .intr_en = 0x80, +}; + +static int __init rtd1295_irq_mux_init(struct device_node *node, + struct device_node *parent) +{ + return rtd119x_irq_mux_init(node, parent, &rtd1295_irq_mux_info); +} +IRQCHIP_DECLARE(rtd1295_mux, "realtek,rtd1295-irq-mux", rtd1295_irq_mux_init);