From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8FDF4ECDE47 for ; Thu, 8 Nov 2018 16:52:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5D63720825 for ; Thu, 8 Nov 2018 16:52:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5D63720825 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727027AbeKIC2Z (ORCPT ); Thu, 8 Nov 2018 21:28:25 -0500 Received: from mga02.intel.com ([134.134.136.20]:6164 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726921AbeKIC2Y (ORCPT ); Thu, 8 Nov 2018 21:28:24 -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 orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Nov 2018 08:52:03 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,480,1534834800"; d="scan'208";a="106431342" Received: from black.fi.intel.com (HELO black.fi.intel.com.) ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 08 Nov 2018 08:52:00 -0800 From: Heikki Krogerus To: "Rafael J. Wysocki" Cc: Mika Westerberg , Andy Shevchenko , Rob Herring , linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v2 1/4] device property: Introduce fwnode_get_name() Date: Thu, 8 Nov 2018 19:51:53 +0300 Message-Id: <20181108165156.60073-2-heikki.krogerus@linux.intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181108165156.60073-1-heikki.krogerus@linux.intel.com> References: <20181108165156.60073-1-heikki.krogerus@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This helper returns the name of the node. The name is primarily expected to be returned from a new fwnode operation meant for this purpose, but when no name is returned, the helper will also attempt to read a device property "name". Signed-off-by: Heikki Krogerus --- drivers/base/property.c | 25 +++++++++++++++++++++++++ include/linux/fwnode.h | 3 +++ include/linux/property.h | 2 ++ 3 files changed, 30 insertions(+) diff --git a/drivers/base/property.c b/drivers/base/property.c index 240ab5230ff6..4db710e2ce34 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -1156,6 +1156,31 @@ void fwnode_handle_put(struct fwnode_handle *fwnode) } EXPORT_SYMBOL_GPL(fwnode_handle_put); +/** + * fwnode_get_name - Read the name of a node + * @fwnode: Pointer to the node. + * @buf: Buffer where the name is copied to + * + * Reads the node name of @fwnode with get_name fwnode op. If get_name op fails, + * the routine attempts to also read a property "name". + */ +int fwnode_get_name(const struct fwnode_handle *fwnode, char *buf) +{ + const char *name; + int ret; + + if (!fwnode_call_int_op(fwnode, get_name, buf)) + return 0; + + ret = fwnode_call_int_op(fwnode, property_read_string_array, + "name", &name, 1); + if (!ret) + sprintf(buf, "%s", name); + + return ret; +} +EXPORT_SYMBOL_GPL(fwnode_get_name); + /** * fwnode_device_is_available - check if a device is available for use * @fwnode: Pointer to the fwnode of the device. diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h index faebf0ca0686..cc234f5d2b40 100644 --- a/include/linux/fwnode.h +++ b/include/linux/fwnode.h @@ -48,6 +48,8 @@ struct fwnode_reference_args { u64 args[NR_FWNODE_REFERENCE_ARGS]; }; +#define FWNODE_NAME_MAX_SIZE 32 + /** * struct fwnode_operations - Operations for fwnode interface * @get: Get a reference to an fwnode. @@ -72,6 +74,7 @@ struct fwnode_reference_args { struct fwnode_operations { struct fwnode_handle *(*get)(struct fwnode_handle *fwnode); void (*put)(struct fwnode_handle *fwnode); + int (*get_name)(const struct fwnode_handle *fwnode, char *buf); bool (*device_is_available)(const struct fwnode_handle *fwnode); const void *(*device_get_match_data)(const struct fwnode_handle *fwnode, const struct device *dev); diff --git a/include/linux/property.h b/include/linux/property.h index ac8a1ebc4c1b..da37bdebf7ab 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -109,6 +109,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_get_name(const struct fwnode_handle *fwnode, char *name); + int fwnode_irq_get(struct fwnode_handle *fwnode, unsigned int index); unsigned int device_get_child_node_count(struct device *dev); -- 2.19.1