From patchwork Mon Nov 26 11:47:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heikki Krogerus X-Patchwork-Id: 10698077 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 3E61613BF for ; Mon, 26 Nov 2018 11:48:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2EB062932A for ; Mon, 26 Nov 2018 11:48:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 20C75295CC; Mon, 26 Nov 2018 11:48:19 +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 573422932A for ; Mon, 26 Nov 2018 11:48:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726582AbeKZWlv (ORCPT ); Mon, 26 Nov 2018 17:41:51 -0500 Received: from mga11.intel.com ([192.55.52.93]:26804 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726580AbeKZWlv (ORCPT ); Mon, 26 Nov 2018 17:41:51 -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 fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Nov 2018 03:47:57 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,282,1539673200"; d="scan'208";a="111296772" Received: from black.fi.intel.com (HELO black.fi.intel.com.) ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 26 Nov 2018 03:47:55 -0800 From: Heikki Krogerus To: "Rafael J. Wysocki" Cc: Mika Westerberg , Andy Shevchenko , Rob Herring , Frank Rowand , linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v3 1/3] device property: Introduce fwnode_get_name() Date: Mon, 26 Nov 2018 14:47:50 +0300 Message-Id: <20181126114752.69597-2-heikki.krogerus@linux.intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181126114752.69597-1-heikki.krogerus@linux.intel.com> References: <20181126114752.69597-1-heikki.krogerus@linux.intel.com> 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 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 | 26 ++++++++++++++++++++++++++ include/linux/fwnode.h | 3 +++ include/linux/property.h | 2 ++ 3 files changed, 31 insertions(+) diff --git a/drivers/base/property.c b/drivers/base/property.c index 240ab5230ff6..f4a3270b3de6 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -1156,6 +1156,32 @@ 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 + * @len: Size of the buffer + * + * 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, size_t len) +{ + const char *name; + int ret; + + if (!fwnode_call_int_op(fwnode, get_name, buf, len)) + return 0; + + ret = fwnode_call_int_op(fwnode, property_read_string_array, + "name", &name, 1); + if (!ret) + snprintf(buf, len, "%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..a211b55a5da1 100644 --- a/include/linux/fwnode.h +++ b/include/linux/fwnode.h @@ -52,6 +52,7 @@ struct fwnode_reference_args { * struct fwnode_operations - Operations for fwnode interface * @get: Get a reference to an fwnode. * @put: Put a reference to an fwnode. + * @get_name: Get the name of an fwnode * @device_get_match_data: Return the device driver match data. * @property_present: Return true if a property is present. * @property_read_integer_array: Read an array of integer properties. Return @@ -72,6 +73,8 @@ 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, + size_t len); 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..e77f08f49c48 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, size_t len); + int fwnode_irq_get(struct fwnode_handle *fwnode, unsigned int index); unsigned int device_get_child_node_count(struct device *dev); From patchwork Mon Nov 26 11:47:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heikki Krogerus X-Patchwork-Id: 10698075 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 EA2DC13BB for ; Mon, 26 Nov 2018 11:48:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA4942932A for ; Mon, 26 Nov 2018 11:48:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE9F9295CC; Mon, 26 Nov 2018 11:48:14 +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 7EC2C2932A for ; Mon, 26 Nov 2018 11:48:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726641AbeKZWly (ORCPT ); Mon, 26 Nov 2018 17:41:54 -0500 Received: from mga11.intel.com ([192.55.52.93]:26804 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726580AbeKZWlx (ORCPT ); Mon, 26 Nov 2018 17:41:53 -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 fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Nov 2018 03:48:00 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,282,1539673200"; d="scan'208";a="111296787" Received: from black.fi.intel.com (HELO black.fi.intel.com.) ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 26 Nov 2018 03:47:57 -0800 From: Heikki Krogerus To: "Rafael J. Wysocki" Cc: Mika Westerberg , Andy Shevchenko , Rob Herring , Frank Rowand , linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v3 2/3] ACPI: property: Add acpi_fwnode_name() Date: Mon, 26 Nov 2018 14:47:51 +0300 Message-Id: <20181126114752.69597-3-heikki.krogerus@linux.intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181126114752.69597-1-heikki.krogerus@linux.intel.com> References: <20181126114752.69597-1-heikki.krogerus@linux.intel.com> 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 implements the get_name fwnode op for ACPI. Signed-off-by: Heikki Krogerus --- drivers/acpi/property.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c index 8c7c4583b52d..a38daa6f32cb 100644 --- a/drivers/acpi/property.c +++ b/drivers/acpi/property.c @@ -1219,6 +1219,29 @@ acpi_graph_get_remote_endpoint(const struct fwnode_handle *__fwnode) return acpi_graph_get_child_prop_value(fwnode, "endpoint", endpoint_nr); } +static int +acpi_fwnode_get_name(const struct fwnode_handle *fwnode, char *buf, size_t len) +{ + struct acpi_buffer buffer; + acpi_handle handle; + acpi_status status; + + if (is_acpi_data_node(fwnode)) { + snprintf(buf, len, "%s", to_acpi_data_node(fwnode)->name); + return 0; + } + + handle = to_acpi_device_node(fwnode)->handle; + + buffer.length = min((size_t)ACPI_NAME_SIZE + 1, len); + buffer.pointer = buf; + + status = acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer); + if (ACPI_FAILURE(status)) + return -ENXIO; + return 0; +} + static bool acpi_fwnode_device_is_available(const struct fwnode_handle *fwnode) { if (!is_acpi_device_node(fwnode)) @@ -1310,6 +1333,7 @@ acpi_fwnode_device_get_match_data(const struct fwnode_handle *fwnode, #define DECLARE_ACPI_FWNODE_OPS(ops) \ const struct fwnode_operations ops = { \ + .get_name = acpi_fwnode_get_name, \ .device_is_available = acpi_fwnode_device_is_available, \ .device_get_match_data = acpi_fwnode_device_get_match_data, \ .property_present = acpi_fwnode_property_present, \ From patchwork Mon Nov 26 11:47:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heikki Krogerus X-Patchwork-Id: 10698073 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 60CEB13BF for ; Mon, 26 Nov 2018 11:48:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C6F12932A for ; Mon, 26 Nov 2018 11:48:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 40FE7295CC; Mon, 26 Nov 2018 11:48:10 +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 D42212932A for ; Mon, 26 Nov 2018 11:48:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726691AbeKZWl5 (ORCPT ); Mon, 26 Nov 2018 17:41:57 -0500 Received: from mga11.intel.com ([192.55.52.93]:26804 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726580AbeKZWlz (ORCPT ); Mon, 26 Nov 2018 17:41:55 -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 fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Nov 2018 03:48:02 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,282,1539673200"; d="scan'208";a="111296801" Received: from black.fi.intel.com (HELO black.fi.intel.com.) ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 26 Nov 2018 03:48:00 -0800 From: Heikki Krogerus To: "Rafael J. Wysocki" Cc: Mika Westerberg , Andy Shevchenko , Rob Herring , Frank Rowand , linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v3 3/3] of/property: Add of_fwnode_name() Date: Mon, 26 Nov 2018 14:47:52 +0300 Message-Id: <20181126114752.69597-4-heikki.krogerus@linux.intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181126114752.69597-1-heikki.krogerus@linux.intel.com> References: <20181126114752.69597-1-heikki.krogerus@linux.intel.com> 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 implements get_name fwnode op for DT. Signed-off-by: Heikki Krogerus --- drivers/of/property.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/of/property.c b/drivers/of/property.c index f46828e3b082..253ed0e9d804 100644 --- a/drivers/of/property.c +++ b/drivers/of/property.c @@ -823,6 +823,13 @@ static void of_fwnode_put(struct fwnode_handle *fwnode) of_node_put(to_of_node(fwnode)); } +static int of_fwnode_get_name(const struct fwnode_handle *fwnode, char *buf, + size_t len) +{ + snprintf(buf, len, "%pOFn", to_of_node(fwnode)); + return 0; +} + static bool of_fwnode_device_is_available(const struct fwnode_handle *fwnode) { return of_device_is_available(to_of_node(fwnode)); @@ -987,6 +994,7 @@ of_fwnode_device_get_match_data(const struct fwnode_handle *fwnode, const struct fwnode_operations of_fwnode_ops = { .get = of_fwnode_get, .put = of_fwnode_put, + .get_name = of_fwnode_get_name, .device_is_available = of_fwnode_device_is_available, .device_get_match_data = of_fwnode_device_get_match_data, .property_present = of_fwnode_property_present,