Received: by 10.223.148.5 with SMTP id 5csp7359502wrq; Thu, 18 Jan 2018 04:37:51 -0800 (PST) X-Google-Smtp-Source: ACJfBosXSE33te0ZDjGTmuTRtEKt6Hx9rYCMkVrFP8wDQ0vt1dgnO8MabatEEE7F3S/fkrkmcj7d X-Received: by 10.98.80.20 with SMTP id e20mr8550140pfb.148.1516279070918; Thu, 18 Jan 2018 04:37:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516279070; cv=none; d=google.com; s=arc-20160816; b=xQDdx1vwjcKXqXst/Qnf3k92pKu6fcuDbvelJ1O1T2k5CXwXREzrmk/2D8NeWt9CZQ jhatRjHvsJzscxMWI9mxADpQy7WgWM1PzD2S91Lsoiy36E0GuSIvXTsqVJjA5QDbhScr vmeTg1sjVdUT5605lE2seOy+kGp85B7c70hGwjoMQh0XTsBx77DO8SWNWMPFjzjpoWFd bVgRpwyTxKNiReuS+a74EcIhi7yukxDzKNuxeZTWSfzBglfMQjIbgb+dzlDuywE1RkfC tA9xPX/ZvWDL/tgdV+yRYLSHq4JiV3DyhQZ142Sy/DD5Jlad69xGQPxepj7cLDCCywZz hLZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=n/GBpY5cs99pdOrfw5q1OvjvLjo7alAa/fhsFDVWonw=; b=ylrtdz+V2xukSh2WgkJ3IWU0C3ZprIwtmeK4WMQ/v5hUuP5drtuxWYH38GPQxgGGnn AitOMCW7tD+T5FtgTiVW9jcm1EP95dMmyYVO6tmICmeMHpxSsxFP5EHmMCPSS9XcXh4b xfFbw2vh7CWksWIxc9WJMbXCEToAS6+G9TNc/S/Ws9Iuka9MhDk9m6fqHVJjnTtp16K0 8udkdHdjxNuujZqWNtaJJvh0e+Q/Ig4cPnALZsymD00MqFko7Qc4edN4OMFWaK2aed5U pfmYJe6P4ddf88yWMPWmmLpSYvadRisbHxYY62BgUcha78uxa4Ri49ZQPqVt1WA7uIBb OLQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@semihalf-com.20150623.gappssmtp.com header.s=20150623 header.b=peZ0eAtP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o30si5884089pgn.548.2018.01.18.04.37.36; Thu, 18 Jan 2018 04:37:50 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@semihalf-com.20150623.gappssmtp.com header.s=20150623 header.b=peZ0eAtP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932372AbeARMcJ (ORCPT + 99 others); Thu, 18 Jan 2018 07:32:09 -0500 Received: from mail-lf0-f68.google.com ([209.85.215.68]:34125 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755706AbeARMcE (ORCPT ); Thu, 18 Jan 2018 07:32:04 -0500 Received: by mail-lf0-f68.google.com with SMTP id k19so6191245lfj.1 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=UOL3doATSnH9QUa6b+wkq6lLCubonuWUF6hXSZzgHdVxDsBZi7msGkXVv4MH6JBjRb fwOQXUTna08iU4umerGvTrMuZ4OKo9eN5RORJ9rM93bFK1D/0DNW4/piPPXy6jO4HZ8V ZvcIRpBTPv85J2mO4HJRRYzKevFYMbIwdV4ZGnxYRhn9YEUw9EIrzBm2EMD4OLp0ngOu yOzYeAvfait5Uf5+QGe+FMEmXqJue0jwd2wz2fJ51LNNTdR/m3FWuSH0mCaGb6wHxAdA nmTv+Y8Nb9V8wRNNUlf3KyQDUXb8UT2Xpq2A7XieRxhAyEL+xeJTV4l1lShA/D0RXoc4 nGrw== X-Gm-Message-State: AKGB3mISDXLP0dRBgX7AyeybaQ9e/VgiPV4laMiEuD1y5m5W/kYrs1DR DV3BTWbnugmoBFdzz82BLfxxc5eeDVY= 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 Cc: graeme.gregory@linaro.org, davem@davemloft.net, linux@armlinux.org.uk, rafael.j.wysocki@intel.com, andrew@lunn.ch, f.fainelli@gmail.com, antoine.tenart@free-electrons.com, thomas.petazzoni@free-electrons.com, gregory.clement@free-electrons.com, stefanc@marvell.com, nadavh@marvell.com, neta@marvell.com, ard.biesheuvel@linaro.org, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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, -- 2.7.4