From patchwork Thu Apr 25 10:20:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 10916763 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 191F01575 for ; Thu, 25 Apr 2019 10:20:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0890F28AFB for ; Thu, 25 Apr 2019 10:20:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F0C1228C3F; Thu, 25 Apr 2019 10:20:54 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.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 8590C28AFB for ; Thu, 25 Apr 2019 10:20:54 +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=g9xnKZbJ+hNwePj9i4iWOiW8D4Iv2QcxHtTLpdtSaLA=; b=cQxRyRM9UUnEvZ LPoIH8lKeC9ej/lZSCF3V3VnSWv9dbVmjSPsEMA3yX17ydachcv7e9OkxgNZPjpvw6BNu7+B459fO th2waeC5HL3CJk2O+t/PMkwz/kl7pLxw1Z2jSZC+xthO+YGgHFgI5LvJKb2pq0SUSLxdA3fDQ+hB+ u5TcAI3h6PNpwuYq8ojixH5SZTvDCVBFqw+T8Nw0Wxj/Q3gwtPIfcxm64Hs4h6Y2g3Qsf8UDONGl4 HpnEAWibBUaJ1m619mp1QZDIophBNfql/4mwv5ImTrch1AxB01OMDDKptLwUw12Rb7rmPePVuk1Jm 3OjRL54ygyWSeNW8plkw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hJbUo-0005Em-NC; Thu, 25 Apr 2019 10:20:50 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hJbUS-0004qW-Cd for linux-arm-kernel@lists.infradead.org; Thu, 25 Apr 2019 10:20:29 +0000 Received: by mail-wr1-x442.google.com with SMTP id c5so20638389wrs.11 for ; Thu, 25 Apr 2019 03:20:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/iI7nJ73SLpzt1a6DM6iMbKuntjQ5I6wTyzYnyQXX5c=; b=rSPNLktuJUWLr5ogZiBx00ruj9atfIW58tOa2byzuHAiY5SeG8rphCoi0i4uOG6UFP 694PwquuI9UCQRjzomAS4j6fbICBc9rskc8sdbG4NpXke8v3opzQfOu85VVebTyAOxz9 kPHlH+l6jYaBlBA0YTEyjvv3ya1RlvVxTPXapT8BKbseqbG2oiglJIGy87ZT2qhDr0M/ XF61Uz6d6rl13ObhK4cgrCz7ttjNFA+4TvFIBy34teVW0Vl/oL5QmjgBS/Co5aJXz42S Ysv60Ad2wxfB9v40d4LvoUMKvHvCqBvH6XJI/Hc53N8IEXo+0Po2P8VGfjmCKinZp/0K wUBg== 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:mime-version:content-transfer-encoding; bh=/iI7nJ73SLpzt1a6DM6iMbKuntjQ5I6wTyzYnyQXX5c=; b=Pq96/2Xm1ZK2xoguQE15SazecXfgdiuG457taGb5dh1krLUkTHPixZWaHhmyZ2f8gn AVapGIpt4bJNmZp/boaMkmaLaFnWLi8iFliSUnYXJvhVb3ZJpK9C8vHGe2BugEr73yd8 wx13gLZVCalyrdSUFsAfObhqm/H+4J9vEycvVMToWbkaqVaoY5dhMc6Lr78ihjeixnYU fwHa1YB8caO2mjdqxLwB+Y35OEYY3DryYFmRrPvQi7EUGIiMSMDmeWHLEjhsIzkSS7Go syfyExowZUA6QhSxdIbMdPjXqwSoStX+0B66H5cbML6WFL9unMaZr5zemF0q1LitTXBw ySRA== X-Gm-Message-State: APjAAAUXJK2/Qeri8V7v5vd98bjOSwEp2H2AHaEgzM9Vv35J39xJ4JMi X56UlkgJgj+QTrh2ZL0tpyIWRlvqcG07aA== X-Google-Smtp-Source: APXvYqw5ln/YQG/F3RdMgZaL0CijSSPRy8G4WcqmOhLUNyBt5wl6kdqtNHYafMg1S9hBQpra8LkmQg== X-Received: by 2002:adf:fb0d:: with SMTP id c13mr6697537wrr.214.1556187625771; Thu, 25 Apr 2019 03:20:25 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:95f:9014:5be9:5288]) by smtp.gmail.com with ESMTPSA id p18sm5611364wrp.38.2019.04.25.03.20.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Apr 2019 03:20:24 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [RFC PATCH 2/3] irqchip/exiu: implement ACPI gpiolib/irqchip support Date: Thu, 25 Apr 2019 12:20:19 +0200 Message-Id: <20190425102020.21533-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190425102020.21533-1-ard.biesheuvel@linaro.org> References: <20190425102020.21533-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190425_032028_441095_C1A0B2B8 X-CRM114-Status: GOOD ( 15.87 ) 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: Graeme Gregory , Ard Biesheuvel , Marc Zyngier , Linus Walleij , linux-gpio@vger.kernel.org, Masahisa Kojima 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 Expose the existing EXIU hierarchical irqchip domain code to permit the interrupt controller to be used as the irqchip component of a GPIO controller on ACPI systems. Signed-off-by: Ard Biesheuvel --- drivers/irqchip/irq-sni-exiu.c | 82 +++++++++++++++++--- 1 file changed, 73 insertions(+), 9 deletions(-) diff --git a/drivers/irqchip/irq-sni-exiu.c b/drivers/irqchip/irq-sni-exiu.c index 52ce662334d4..99351cf997d9 100644 --- a/drivers/irqchip/irq-sni-exiu.c +++ b/drivers/irqchip/irq-sni-exiu.c @@ -12,6 +12,7 @@ * published by the Free Software Foundation. */ +#include #include #include #include @@ -20,6 +21,7 @@ #include #include #include +#include #include @@ -134,9 +136,13 @@ static int exiu_domain_translate(struct irq_domain *domain, *hwirq = fwspec->param[1] - info->spi_base; *type = fwspec->param[2] & IRQ_TYPE_SENSE_MASK; - return 0; + } else { + if (fwspec->param_count != 2) + return -EINVAL; + *hwirq = fwspec->param[0]; + *type = fwspec->param[2] & IRQ_TYPE_SENSE_MASK; } - return -EINVAL; + return 0; } static int exiu_domain_alloc(struct irq_domain *dom, unsigned int virq, @@ -147,16 +153,23 @@ static int exiu_domain_alloc(struct irq_domain *dom, unsigned int virq, struct exiu_irq_data *info = dom->host_data; irq_hw_number_t hwirq; - if (fwspec->param_count != 3) - return -EINVAL; /* Not GIC compliant */ - if (fwspec->param[0] != GIC_SPI) - return -EINVAL; /* No PPI should point to this domain */ - + parent_fwspec = *fwspec; + if (is_of_node(dom->parent->fwnode)) { + if (fwspec->param_count != 3) + return -EINVAL; /* Not GIC compliant */ + if (fwspec->param[0] != GIC_SPI) + return -EINVAL; /* No PPI should point to this domain */ + + hwirq = fwspec->param[1] - info->spi_base; + } else if (is_fwnode_irqchip(dom->parent->fwnode)) { + hwirq = fwspec->param[0]; + parent_fwspec.param[0] = hwirq + info->spi_base + 32; + } else { + return -EINVAL; + } WARN_ON(nr_irqs != 1); - hwirq = fwspec->param[1] - info->spi_base; irq_domain_set_hwirq_and_chip(dom, virq, hwirq, &exiu_irq_chip, info); - parent_fwspec = *fwspec; parent_fwspec.fwnode = dom->parent->fwnode; return irq_domain_alloc_irqs_parent(dom, virq, nr_irqs, &parent_fwspec); } @@ -244,3 +257,54 @@ static int __init exiu_dt_init(struct device_node *node, return 0; } IRQCHIP_DECLARE(exiu, "socionext,synquacer-exiu", exiu_dt_init); + +#ifdef CONFIG_ACPI +static int exiu_acpi_gpio_to_irq(struct gpio_chip *gc, u32 gpio) +{ + struct irq_fwspec fwspec; + + fwspec.fwnode = gc->parent->fwnode; + fwspec.param_count = 2; + fwspec.param[0] = gpio; + fwspec.param[1] = IRQ_TYPE_LEVEL_HIGH; + + return irq_create_fwspec_mapping(&fwspec); +} + +int exiu_acpi_init(struct platform_device *pdev, struct gpio_chip *gc) +{ + struct irq_domain *parent_domain = NULL, *domain; + struct resource *res; + int irq; + + irq = platform_get_irq(pdev, 0); + if (irq > 0) + parent_domain = irq_get_irq_data(irq)->domain; + + if (!parent_domain) { + dev_err(&pdev->dev, "unable to obtain parent domain\n"); + return -ENODEV; + } + + res = platform_get_resource(pdev, IORESOURCE_MEM, 1); + if (!res) { + dev_err(&pdev->dev, "failed to parse memory resource\n"); + return -ENXIO; + } + + domain = exiu_init(parent_domain, dev_fwnode(&pdev->dev), res); + if (IS_ERR(domain)) { + dev_err(&pdev->dev, "failed to create IRQ domain (%ld)\n", + PTR_ERR(domain)); + return PTR_ERR(domain); + } + + gc->irq.domain = domain; + gc->to_irq = exiu_acpi_gpio_to_irq; + + dev_info(&pdev->dev, "%d interrupts forwarded\n", NUM_IRQS); + + return 0; +} +EXPORT_SYMBOL(exiu_acpi_init); +#endif