From patchwork Tue May 17 10:28:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Thomson X-Patchwork-Id: 9111441 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id ED9599F30C for ; Tue, 17 May 2016 10:29:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EC1A3202EB for ; Tue, 17 May 2016 10:29:25 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 92FCE201C0 for ; Tue, 17 May 2016 10:29:24 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 89B2E265A28; Tue, 17 May 2016 12:29:21 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NO_DNS_FOR_FROM, RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id B05912617BB; Tue, 17 May 2016 12:29:11 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 198142619FA; Tue, 17 May 2016 12:29:10 +0200 (CEST) Received: from mail1.bemta3.messagelabs.com (mail1.bemta3.messagelabs.com [195.245.230.163]) by alsa0.perex.cz (Postfix) with ESMTP id D83F82607C8 for ; Tue, 17 May 2016 12:29:02 +0200 (CEST) Received: from [85.158.137.3] by server-3.bemta-3.messagelabs.com id AB/68-03294-C62FA375; Tue, 17 May 2016 10:29:00 +0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-Env-Sender: Adam.Thomson.Opensource@diasemi.com X-Msg-Ref: server-10.tower-38.messagelabs.com!1463480939!40285804!2 X-Originating-IP: [94.185.165.51] X-StarScan-Received: X-StarScan-Version: 8.34; banners=-,-,- X-VirusChecked: Checked Received: (qmail 9470 invoked from network); 17 May 2016 10:29:00 -0000 Received: from mailrelay2.diasemi.com (HELO sw-ex-cashub01.diasemi.com) (94.185.165.51) by server-10.tower-38.messagelabs.com with AES128-SHA encrypted SMTP; 17 May 2016 10:29:00 -0000 Received: from swsrvapps-01.diasemi.com (10.20.28.141) by SW-EX-CASHUB01.diasemi.com (10.20.16.140) with Microsoft SMTP Server id 14.3.248.2; Tue, 17 May 2016 11:28:58 +0100 Received: by swsrvapps-01.diasemi.com (Postfix, from userid 22379) id AE7913FB97; Tue, 17 May 2016 11:28:58 +0100 (BST) Message-ID: <39ccf372455f0b21a9ca29e58baf30ac4cd0c281.1463477116.git.Adam.Thomson.Opensource@diasemi.com> In-Reply-To: References: From: Adam Thomson Date: Tue, 17 May 2016 11:28:58 +0100 To: Mark Brown , Liam Girdwood , Jaroslav Kysela , Takashi Iwai , Greg Kroah-Hartman , Robert Moore , Lv Zheng , Rafael J.Wysocki , Len Brown MIME-Version: 1.0 X-KSE-AttachmentFiltering-Interceptor-Info: protection disabled X-KSE-ServerInfo: sw-ex-cashub01.diasemi.com, 9 X-KSE-Antivirus-Interceptor-Info: scan successful X-KSE-Antivirus-Info: Clean, bases: 17/05/2016 08:40:00 Cc: alsa-devel@alsa-project.org, Heikki Krogerus , Support Opensource , Hanjun Guo , linux-kernel@vger.kernel.org, Suthikulpanit@diasemi.com, linux-acpi@vger.kernel.org, Sathyanarayana Nujella , Suravee , Bjorn Helgaas , Andrew Morton , Andy Shevchenko , Mika Westerberg , devel@acpica.org Subject: [alsa-devel] [PATCH 1/2] device property: Add function to search for named child of device X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP For device nodes in both DT and ACPI, it possible to have named child nodes which contain properties (an existing example being gpio-leds). This adds a function to find a named child node for a device which can be used by drivers for property retrieval. For ACPI data node name matching, a helper function is also added which returns false if CONFIG_ACPI is not set, otherwise it performs a string comparison on the data node name. This avoids using the acpi_data_node struct for non CONFIG_ACPI builds, which would otherwise cause a build failure. Signed-off-by: Adam Thomson Tested-by: Sathyanarayana Nujella --- drivers/base/property.c | 28 ++++++++++++++++++++++++++++ include/acpi/acpi_bus.h | 7 +++++++ include/linux/acpi.h | 6 ++++++ include/linux/property.h | 3 +++ 4 files changed, 44 insertions(+) -- 1.9.3 diff --git a/drivers/base/property.c b/drivers/base/property.c index 7f692ac..8b2cb09 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -880,6 +880,34 @@ struct fwnode_handle *device_get_next_child_node(struct device *dev, EXPORT_SYMBOL_GPL(device_get_next_child_node); /** + * device_get_named_child_node - Return first matching named child node handle + * @dev: Device to find the named child node for. + * @childname: String to match child node name against. + */ +struct fwnode_handle *device_get_named_child_node(struct device *dev, + const char *childname) +{ + struct fwnode_handle *child; + + /* + * Find first matching named child node of this device. + * For ACPI this will be a data only sub-node. + */ + device_for_each_child_node(dev, child) { + if (is_of_node(child)) { + if (!strcasecmp(to_of_node(child)->name, childname)) + return child; + } else if (is_acpi_data_node(child)) { + if (acpi_data_node_match(child, childname)) + return child; + } + } + + return NULL; +} +EXPORT_SYMBOL_GPL(device_get_named_child_node); + +/** * fwnode_handle_put - Drop reference to a device node * @fwnode: Pointer to the device node to drop the reference to. * diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index 3a93250..6dc3544 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -420,6 +420,13 @@ static inline struct acpi_data_node *to_acpi_data_node(struct fwnode_handle *fwn container_of(fwnode, struct acpi_data_node, fwnode) : NULL; } +static inline bool acpi_data_node_match(struct fwnode_handle *fwnode, + const char *name) +{ + return is_acpi_data_node(fwnode) ? + (!strcasecmp(to_acpi_data_node(fwnode)->name, name)) : false; +} + static inline struct fwnode_handle *acpi_fwnode_handle(struct acpi_device *adev) { return &adev->fwnode; diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 06ed7e5..c37a385 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -576,6 +576,12 @@ static inline struct acpi_data_node *to_acpi_data_node(struct fwnode_handle *fwn return NULL; } +static inline bool acpi_data_node_match(struct fwnode_handle *fwnode, + const char *name) +{ + return false; +} + static inline struct fwnode_handle *acpi_fwnode_handle(struct acpi_device *adev) { return NULL; diff --git a/include/linux/property.h b/include/linux/property.h index b51fcd3..d2752dc 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -77,6 +77,9 @@ struct fwnode_handle *device_get_next_child_node(struct device *dev, for (child = device_get_next_child_node(dev, NULL); child; \ child = device_get_next_child_node(dev, child)) +struct fwnode_handle *device_get_named_child_node(struct device *dev, + const char *childname); + void fwnode_handle_put(struct fwnode_handle *fwnode); unsigned int device_get_child_node_count(struct device *dev);