From patchwork Wed Jun 17 13:42:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 6626291 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 63578C0020 for ; Wed, 17 Jun 2015 13:50:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 73D122062F for ; Wed, 17 Jun 2015 13:50:58 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 82E2C204AD for ; Wed, 17 Jun 2015 13:50:54 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z5Dgp-00071g-FO; Wed, 17 Jun 2015 13:47:39 +0000 Received: from mail-wi0-x233.google.com ([2a00:1450:400c:c05::233]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z5Dcx-0002yI-SQ for linux-arm-kernel@lists.infradead.org; Wed, 17 Jun 2015 13:43:40 +0000 Received: by wicnd19 with SMTP id nd19so29545874wic.1 for ; Wed, 17 Jun 2015 06:43:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=T+mrTOieXcJg8txwVdQLKhPEiHIXoj3TKF9sj9nsJzw=; b=h9DgQJQYFwHKDSLLr0fEDFrRZzOCVWS58gL9qc/o4u+zOhS54cfhCpF/pFf04bSntj iTuDpPNK+1NW9lOYw4ABFH/rliBZovAjcCe6Nd8OGuI3Eg9gGbLxtkA9jHPf6pEalSNr hviGqVhT9qwUqJhzPh7g1aea4v++4nkklz0ZykFrAbGB0YynIbsVj3u+avWwXNpMbXM6 A6nA1Q24ZyKDaPDPaD8iRPuU5Pr8p+gw+jGlXbtsexuBpfYVjQV5VetvcLD2PqC53yKr ti1KRrcAiQtQEyACcMpqxbzXnL4kPIFJ1WTfJPo/YgfqDaVB75lUUxUN1U7pAazvKZE6 sWqA== X-Received: by 10.194.81.67 with SMTP id y3mr5917320wjx.7.1434548597703; Wed, 17 Jun 2015 06:43:17 -0700 (PDT) Received: from cizrna.lan ([109.72.12.132]) by mx.google.com with ESMTPSA id v3sm6920361wja.31.2015.06.17.06.43.15 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Jun 2015 06:43:16 -0700 (PDT) From: Tomeu Vizoso To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 11/13] device property: add fwnode_get_parent() Date: Wed, 17 Jun 2015 15:42:21 +0200 Message-Id: <1434548543-22949-12-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.4.1 In-Reply-To: <1434548543-22949-1-git-send-email-tomeu.vizoso@collabora.com> References: <1434548543-22949-1-git-send-email-tomeu.vizoso@collabora.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150617_064340_112229_3A14344A X-CRM114-Status: GOOD ( 12.72 ) X-Spam-Score: -0.7 (/) Cc: Mark Rutland , Krzysztof Kozlowski , Linus Walleij , Andrzej Hajda , Thierry Reding , Lv Zheng , Alexander Holler , Alexandre Courbot , Russell King , Pawel Moll , Stephen Warren , Robert Moore , Grant Likely , Len Brown , Arnd Bergmann , Ian Campbell , Rob Herring , =?UTF-8?q?Terje=20Bergstr=C3=B6m?= , Tomeu Vizoso , Greg Kroah-Hartman , Dmitry Torokhov , "Rafael J. Wysocki" , linux-kernel@vger.kernel.org, Mark Brown , Kumar Gala , Javier Martinez Canillas X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP So we can query the parent of a fwnode without having to resort to API that is specific to a firmware data format. Also adds a acpi_get_parent_dev() function to retrieve the parent of an acpi_device. acpi_get_parent() already existed but it works with acpi_handles. The interface covers both ACPI and Device Trees. Signed-off-by: Tomeu Vizoso --- drivers/base/property.c | 23 +++++++++++++++++++++++ include/acpi/acpi_bus.h | 5 +++++ include/linux/acpi.h | 5 +++++ include/linux/property.h | 2 ++ 4 files changed, 35 insertions(+) diff --git a/drivers/base/property.c b/drivers/base/property.c index 1d0b116..28645a9 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -519,3 +519,26 @@ unsigned int device_get_child_node_count(struct device *dev) return count; } EXPORT_SYMBOL_GPL(device_get_child_node_count); + +/** + * fwnode_get_parent - return the parent node of a device node + * @fwnode: Device node to find the parent node of + */ +struct fwnode_handle *fwnode_get_parent(struct fwnode_handle *fwnode) +{ + if (is_of_node(fwnode)) { + struct device_node *node = of_node(fwnode); + + if (node->parent) + return &node->parent->fwnode; + } else if (is_acpi_node(fwnode)) { + struct acpi_device *node; + + node = acpi_get_parent_dev(acpi_node(fwnode)); + if (node) + return acpi_fwnode_handle(node); + } + + return NULL; +} +EXPORT_SYMBOL_GPL(fwnode_get_parent); diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index 5dec08d..bf8ef1a 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -401,6 +401,11 @@ static inline void *acpi_driver_data(struct acpi_device *d) return d->driver_data; } +static inline struct acpi_device *acpi_get_parent_dev(struct acpi_device *adev) +{ + return adev->parent; +} + #define to_acpi_device(d) container_of(d, struct acpi_device, dev) #define to_acpi_driver(d) container_of(d, struct acpi_driver, drv) diff --git a/include/linux/acpi.h b/include/linux/acpi.h index a4acb55..d9dfacc 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -825,6 +825,11 @@ static inline struct acpi_device *acpi_get_next_child(struct device *dev, return NULL; } +static inline struct acpi_device *acpi_get_parent_dev(struct acpi_device *adev) +{ + return NULL; +} + #endif #endif /*_LINUX_ACPI_H*/ diff --git a/include/linux/property.h b/include/linux/property.h index de8bdf4..01e0483 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -63,6 +63,8 @@ int fwnode_property_read_string(struct fwnode_handle *fwnode, struct fwnode_handle *device_get_next_child_node(struct device *dev, struct fwnode_handle *child); +struct fwnode_handle *fwnode_get_parent(struct fwnode_handle *fwnode); + #define device_for_each_child_node(dev, child) \ for (child = device_get_next_child_node(dev, NULL); child; \ child = device_get_next_child_node(dev, child))