From patchwork Thu Jan 18 12:31:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 10173101 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 DED72603B5 for ; Thu, 18 Jan 2018 12:34:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D4C152013C for ; Thu, 18 Jan 2018 12:34:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C7DDE27C2D; Thu, 18 Jan 2018 12:34:23 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED 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 4AD722013C for ; Thu, 18 Jan 2018 12:34:23 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=ckQOWIyn1fWZTT/dCHd5UZEWhQ22Z7BN5FDvJQBR4xE=; b=c5Q7OubQnXvyQ2ab7HVhSMan7L +1NnHBeH8OsF+08/3cbroiuByKRDQv3hjBJ3JWmFXqZU5Uc3k+iyzhKS37m+PLUUS4bMOojyv7ANs hLdcP7X9TZ6zZtoUPI5aIKhEKIyXsjZDGSyYKLtk+vCXRR3Bv1ILRmh6d7GqXmziRMZ4eKawCME4m TIn4pY9040mFRDBZXpgTsvpTJbafmT05JeOHdJ5UyjnuexaN/Kxw6Q0gCS0xYDMxWy4Fx9KdvyjB1 RcEEyEyZ2GqmHrFDSKrU1GSE99Pq9b7cvITgINHQceGS9GhpProi8/UgWJUeX/OQ2G9kG9NP1425F q9vCPQbw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1ec9Of-0003Fq-6q; Thu, 18 Jan 2018 12:34:21 +0000 Received: from mail-lf0-x243.google.com ([2a00:1450:4010:c07::243]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1ec9Mc-0000hY-Bz for linux-arm-kernel@lists.infradead.org; Thu, 18 Jan 2018 12:32:22 +0000 Received: by mail-lf0-x243.google.com with SMTP id q194so14961573lfe.13 for ; Thu, 18 Jan 2018 04:32:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=n/GBpY5cs99pdOrfw5q1OvjvLjo7alAa/fhsFDVWonw=; b=peZ0eAtPOqXycrdZOjsuWzuJ+c9bxSZvRzylc82z/9PzS3TYPBJPV58Qkw/CoJ5RLO R3y7kZjbJyXC4NsbbPpBaAA7Ut/QRpjJnGibw7al1PM9nAvXEzTtOiEmCNddiGIjuujT 7zShrfwqhrr2f+CRXDN1knLxpxZ3BycXFqUzDxHhOxmi3kN35wjpcWxFj3kf2xscRBpA 9D8hq18GllS0mcHWEkOU5U+yJmBSOmnlX1X5ntQXPz09uBiRvL5bPh4bP9jWWdbx/WhN cUVFSGyszNXZHAw/83nW0z5PA7LqQOvSOPjtcwpvS3XH9REuyo4Uql3l5EU1Nvlo3bcO kDIQ== 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=n/GBpY5cs99pdOrfw5q1OvjvLjo7alAa/fhsFDVWonw=; b=rmSHEexkV2z8FUCQ/g+u3vACX6+OCR7C5buHe89yNX/s5PqPZ7WSP9GwgTiq1H5MZk jVsigMiIj5dsh+ZEUKrUrsReMwjjH34PKeJ0fdEmdXx/St7rhJCX+LPs9wE0t44wIWKk LQvPxSClnI43hytdXFmUvfyv9YNGXZQhL5tG3sPdawH5NseFchpteiYIaR1KfbTX12Pa 4EO4+4nENYohlGS5V4cWVfu0tkv1A1N+UNoYNVZRpDDnDNyAC6HElrh87jZgZ/ZYSuRw 64Ei5NrJIdeVLRW4QU1J6f9A9AtKkyYadoMoSRFXM4PEgar7TQU1W7mloi8y8JmozI4i vY9A== X-Gm-Message-State: AKGB3mL/cYFxGgud66AxoiOIxUf9y4pphqfyEPoX4+FNEfAwrepK8mpX 7+t/lT7HPz4KGU2Zyk1JVUnJZA== X-Google-Smtp-Source: ACJfBotmiy59JmbQMb6VPCKqaHRf8SEDroi66xDDhgvpZNaLyQWo3KGRbcUKcjlV6EM3LVB6NC4gRw== X-Received: by 10.46.9.198 with SMTP id 189mr27418839ljj.116.1516278722259; Thu, 18 Jan 2018 04:32:02 -0800 (PST) Received: from gilgamesh.semihalf.com (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id s23sm1303906ljs.1.2018.01.18.04.32.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 18 Jan 2018 04:32:01 -0800 (PST) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, linux-acpi@vger.kernel.org Subject: [net-next: PATCH v4 3/7] device property: Introduce fwnode_irq_get() Date: Thu, 18 Jan 2018 13:31:40 +0100 Message-Id: <1516278704-17141-4-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516278704-17141-1-git-send-email-mw@semihalf.com> References: <1516278704-17141-1-git-send-email-mw@semihalf.com> 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@free-electrons.com, andrew@lunn.ch, f.fainelli@gmail.com, graeme.gregory@linaro.org, ard.biesheuvel@linaro.org, jaz@semihalf.com, antoine.tenart@free-electrons.com, rafael.j.wysocki@intel.com, linux@armlinux.org.uk, nadavh@marvell.com, neta@marvell.com, tn@semihalf.com, gregory.clement@free-electrons.com, stefanc@marvell.com, mw@semihalf.com, davem@davemloft.net MIME-Version: 1.0 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 Until now there were two very similar functions allowing to get Linux IRQ number from ACPI handle (acpi_irq_get()) and OF node (of_irq_get()). The first one appeared to be used only as a subroutine of platform_irq_get(), which (in the generic code) limited IRQ obtaining from _CRS method only to nodes associated to kernel's struct platform_device. This patch introduces a new helper routine - fwnode_irq_get(), which allows to get the IRQ number directly from the fwnode to be used as common for OF/ACPI worlds. It is usable not only for the parents fwnodes, but also for the child nodes comprising their own _CRS methods with interrupts description. In order to be able o satisfy compilation with !CONFIG_ACPI and also simplify the new code, introduce a helper macro (ACPI_HANDLE_FWNODE), with which it is possible to reach an ACPI handle directly from its fwnode. Signed-off-by: Marcin Wojtas --- drivers/base/property.c | 26 ++++++++++++++++++++ include/linux/acpi.h | 3 +++ include/linux/property.h | 2 ++ 3 files changed, 31 insertions(+) diff --git a/drivers/base/property.c b/drivers/base/property.c index 7c4a53d..1d6c9d9 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -1230,6 +1231,31 @@ void *device_get_mac_address(struct device *dev, char *addr, int alen) EXPORT_SYMBOL(device_get_mac_address); /** + * fwnode_irq_get - Get IRQ directly from a fwnode + * @fwnode: Pointer to the firmware node + * @index: Zero-based index of the IRQ + * + * Returns Linux IRQ number on success. Other values are determined + * accordingly to acpi_/of_ irq_get() operation. + */ +int fwnode_irq_get(struct fwnode_handle *fwnode, unsigned int index) +{ + struct device_node *of_node = to_of_node(fwnode); + struct resource res; + int ret; + + if (IS_ENABLED(CONFIG_OF) && of_node) + return of_irq_get(of_node, index); + + ret = acpi_irq_get(ACPI_HANDLE_FWNODE(fwnode), index, &res); + if (ret) + return ret; + + return res.start; +} +EXPORT_SYMBOL(fwnode_irq_get); + +/** * device_graph_get_next_endpoint - Get next endpoint firmware node * @fwnode: Pointer to the parent firmware node * @prev: Previous endpoint node or %NULL to get the first diff --git a/include/linux/acpi.h b/include/linux/acpi.h index dc1ebfe..f05b9b6 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -56,6 +56,8 @@ static inline acpi_handle acpi_device_handle(struct acpi_device *adev) #define ACPI_COMPANION_SET(dev, adev) set_primary_fwnode(dev, (adev) ? \ acpi_fwnode_handle(adev) : NULL) #define ACPI_HANDLE(dev) acpi_device_handle(ACPI_COMPANION(dev)) +#define ACPI_HANDLE_FWNODE(fwnode) \ + acpi_device_handle(to_acpi_device_node(fwnode)) static inline struct fwnode_handle *acpi_alloc_fwnode_static(void) { @@ -626,6 +628,7 @@ int acpi_arch_timer_mem_init(struct arch_timer_mem *timer_mem, int *timer_count) #define ACPI_COMPANION(dev) (NULL) #define ACPI_COMPANION_SET(dev, adev) do { } while (0) #define ACPI_HANDLE(dev) (NULL) +#define ACPI_HANDLE_FWNODE(fwnode) (NULL) #define ACPI_DEVICE_CLASS(_cls, _msk) .cls = (0), .cls_msk = (0), struct fwnode_handle; diff --git a/include/linux/property.h b/include/linux/property.h index 9b13332..e05889f 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -103,6 +103,8 @@ struct fwnode_handle *device_get_named_child_node(struct device *dev, struct fwnode_handle *fwnode_handle_get(struct fwnode_handle *fwnode); void fwnode_handle_put(struct fwnode_handle *fwnode); +int fwnode_irq_get(struct fwnode_handle *fwnode, unsigned int index); + unsigned int device_get_child_node_count(struct device *dev); static inline bool device_property_read_bool(struct device *dev,