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: 862844 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=semihalf-com.20150623.gappssmtp.com header.i=@semihalf-com.20150623.gappssmtp.com header.b="peZ0eAtP"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zMk0X1zgHz9s0g for ; Thu, 18 Jan 2018 23:34:04 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755272AbeARMeB (ORCPT ); Thu, 18 Jan 2018 07:34:01 -0500 Received: from mail-lf0-f67.google.com ([209.85.215.67]:39347 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755800AbeARMcD (ORCPT ); Thu, 18 Jan 2018 07:32:03 -0500 Received: by mail-lf0-f67.google.com with SMTP id m8so26446221lfc.6 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=uTcE1Dz1eONJsagzo7Q4OzYgPV6QHbi3Eu4isjbweeC4NpapLmliK1bFYnQ200pRtQ BXgNLyawF/DqkzYscTvBC7i8obAzE94hiy09XaTJqYNiZI01Z/xQpWBqBlgTXMwHInU0 zffEn8UKT+/wL5zM1NrB/VI1PHRk84877u/l7hNL4bUk1N26mvpl9zopzms7cVo5sulZ dybvJ8vsxkqkpDkArzSRpcTcdwHPvd6kfMm3OSOhfAkCxGNdxewE3EZbQMDlCcd89BbT Y4xR0nsihHNw72fAy4cQNFDmrT77BRXVZTYSY5aia7BVB3nZbTd2qaKmh9hafbNIz7a+ mNMw== X-Gm-Message-State: AKGB3mIu7Bq8ZXH2lcIkdi/rG4/nZKHbm1bx2Eqwkw63ccYiQLjFgQK1 ra7HPqdkTigG0yeP1CS88eQQhQ== 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 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: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@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,