From patchwork Wed Apr 10 15:24:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heikki Krogerus X-Patchwork-Id: 10894255 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 60F92139A for ; Wed, 10 Apr 2019 15:26:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B27228BBD for ; Wed, 10 Apr 2019 15:26:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 48F6628BFA; Wed, 10 Apr 2019 15:26:21 +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 D204828B12 for ; Wed, 10 Apr 2019 15:26:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732826AbfDJPZT (ORCPT ); Wed, 10 Apr 2019 11:25:19 -0400 Received: from mga06.intel.com ([134.134.136.31]:15566 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729439AbfDJPZT (ORCPT ); Wed, 10 Apr 2019 11:25:19 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Apr 2019 08:25:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,332,1549958400"; d="scan'208";a="163102937" Received: from black.fi.intel.com (HELO black.fi.intel.com.) ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 10 Apr 2019 08:25:16 -0700 From: Heikki Krogerus To: "Rafael J. Wysocki" Cc: Greg Kroah-Hartman , Hans de Goede , Darren Hart , Andy Shevchenko , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH v2 04/12] software node: Implement .get_reference_args fwnode operation Date: Wed, 10 Apr 2019 18:24:57 +0300 Message-Id: <20190410152505.87041-5-heikki.krogerus@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190410152505.87041-1-heikki.krogerus@linux.intel.com> References: <20190410152505.87041-1-heikki.krogerus@linux.intel.com> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This makes it possible to support drivers that use fwnode_property_get_reference_args() function. Signed-off-by: Heikki Krogerus --- drivers/base/swnode.c | 56 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index 39b8f8f35cfe..d6a9b56cb073 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -534,6 +534,61 @@ software_node_get_named_child_node(const struct fwnode_handle *fwnode, return NULL; } +static int +software_node_get_reference_args(const struct fwnode_handle *fwnode, + const char *propname, const char *nargs_prop, + unsigned int nargs, unsigned int index, + struct fwnode_reference_args *args) +{ + struct software_node *swnode = to_software_node(fwnode); + struct software_node_reference *ref; + const struct property_entry *prop; + int ret = -ENOENT; + int i; + + mutex_lock(&swnode->lock); + + if (!swnode || list_empty(&swnode->references)) + goto err_unlock; + + if (nargs_prop) { + prop = property_entry_get(swnode->properties, nargs_prop); + if (!prop) { + ret = -EINVAL; + goto err_unlock; + } + + nargs = prop->value.u32_data; + } + + if (nargs > NR_FWNODE_REFERENCE_ARGS) { + ret = -EINVAL; + goto err_unlock; + } + + list_for_each_entry(ref, &swnode->references, list) { + if (strcmp(ref->name, propname)) + continue; + + if (index > (ref->nrefs - 1)) + break; + + args->nargs = nargs; + args->fwnode = software_node_get(ref->args[index].fwnode); + + for (i = 0; i < nargs; i++) + args->args[i] = ref->args[index].args[i]; + + ret = 0; + break; + } + +err_unlock: + mutex_unlock(&swnode->lock); + + return ret; +} + static const struct fwnode_operations software_node_ops = { .get = software_node_get, .put = software_node_put, @@ -543,6 +598,7 @@ static const struct fwnode_operations software_node_ops = { .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, + .get_reference_args = software_node_get_reference_args, }; /* -------------------------------------------------------------------------- */