From patchwork Wed Feb 13 11:55:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heikki Krogerus X-Patchwork-Id: 10809667 X-Patchwork-Delegate: rjw@sisk.pl Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 158C41390 for ; Wed, 13 Feb 2019 11:56:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F357C2CA3E for ; Wed, 13 Feb 2019 11:56:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E51C92CDB5; Wed, 13 Feb 2019 11:56:00 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 857AB2CA3E for ; Wed, 13 Feb 2019 11:56:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733126AbfBMLzz (ORCPT ); Wed, 13 Feb 2019 06:55:55 -0500 Received: from mga18.intel.com ([134.134.136.126]:23378 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388245AbfBMLzw (ORCPT ); Wed, 13 Feb 2019 06:55:52 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Feb 2019 03:55:51 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,365,1544515200"; d="scan'208";a="146481610" Received: from black.fi.intel.com (HELO black.fi.intel.com.) ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 13 Feb 2019 03:55:49 -0800 From: Heikki Krogerus To: "Rafael J. Wysocki" Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] software node: Implement get_named_child_node fwnode callback Date: Wed, 13 Feb 2019 14:55:49 +0300 Message-Id: <20190213115549.81917-1-heikki.krogerus@linux.intel.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This makes it possible to support drivers that use fwnode_get_named_child_node() and device_get_named_child_node() functions. The node name is for now taken from a device property named "name". That mimics the old style of naming of the nodes in devicetree (though with modern flattened DT, the name is matched against the actual node-name, it used to be done with a property "name"). In Open Firmware DT the "name" property is also still being used. Signed-off-by: Heikki Krogerus --- drivers/base/swnode.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index 89ad8dee6ad5..1fad9291f6aa 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -499,6 +499,28 @@ software_node_get_next_child(const struct fwnode_handle *fwnode, return &c->fwnode; } +static struct fwnode_handle * +software_node_get_named_child_node(const struct fwnode_handle *fwnode, + const char *childname) +{ + struct software_node *swnode = to_software_node(fwnode); + const struct property_entry *prop; + struct software_node *child; + + if (!swnode || list_empty(&swnode->children)) + return NULL; + + list_for_each_entry(child, &swnode->children, entry) { + prop = property_entry_get(child->properties, "name"); + if (!prop) + continue; + if (!strcmp(childname, prop->value.str)) { + kobject_get(&child->kobj); + return &child->fwnode; + } + } + return NULL; +} static const struct fwnode_operations software_node_ops = { .get = software_node_get, @@ -508,6 +530,7 @@ static const struct fwnode_operations software_node_ops = { .property_read_string_array = software_node_read_string_array, .get_parent = software_node_get_parent, .get_next_child_node = software_node_get_next_child, + .get_named_child_node = software_node_get_named_child_node, }; /* -------------------------------------------------------------------------- */