From patchwork Fri Mar 25 11:31:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 12791502 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6AD08C43217 for ; Fri, 25 Mar 2022 11:34:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355971AbiCYLfl (ORCPT ); Fri, 25 Mar 2022 07:35:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232143AbiCYLfk (ORCPT ); Fri, 25 Mar 2022 07:35:40 -0400 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06998A995C; Fri, 25 Mar 2022 04:34:05 -0700 (PDT) Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id CD46820012; Fri, 25 Mar 2022 11:34:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1648208044; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7h5U+Wv/MCPvlMQZC9RddFjnnGvegr7ExkBEVjPAZkg=; b=oUisZjuRnZzAKfKfHS3IZA9SPvSHB+yh+uf4+RJ97ZHAowKVOSJ0hubxoeLZB177rqgqtJ 3AIHilOvwZEFzWDXX6IFKmLhGoX5qdlQ07raXrZN6wJTL/R9o5S5coNj7/rZ8tdtITlAQf kZWjmyBB+xoqe3030lR5tMhQGA5/ZkXOTUhbDpGLuqZBdlTedzhdua5Hlt6b7DDM71LjDo pAGggGuXsZWc+3FSJEzws13t4D0r71RBAUn6BakSWIpwvou3TCP3yXieLqhXQLlieS0cP6 /jqqJc8yU2M75s5Z5WjmYypBsdjKJ3TjFD7q+UUzMJwal/WetMDeHyFbbc061A== From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J . Wysocki" , Wolfram Sang , Peter Rosin , Rob Herring , Frank Rowand , Len Brown Cc: Hans de Goede , Thomas Petazzoni , Alexandre Belloni , Allan Nielsen , linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= Subject: [PATCH v3 1/9] of: add of_property_read_string_array_index() Date: Fri, 25 Mar 2022 12:31:40 +0100 Message-Id: <20220325113148.588163-2-clement.leger@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220325113148.588163-1-clement.leger@bootlin.com> References: <20220325113148.588163-1-clement.leger@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Add of_property_read_string_array_index() which allows to read a string array starting at a specific index. Signed-off-by: Clément Léger Reviewed-by: Rob Herring --- include/linux/of.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/linux/of.h b/include/linux/of.h index 2dc77430a91a..93f04c530bd1 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -1115,6 +1115,28 @@ static inline int of_property_read_string_array(const struct device_node *np, return of_property_read_string_helper(np, propname, out_strs, sz, 0); } +/** + * of_property_read_string_array_index() - Read an array of strings from a + * multiple strings property starting at a specified index + * @np: device node from which the property value is to be read. + * @propname: name of the property to be searched. + * @out_strs: output array of string pointers. + * @sz: number of array elements to read. + * @index: index to start reading from + * + * Search for a property in a device tree node and retrieve a list of + * terminated string values (pointer to data, not a copy) in that property + * starting at specified index. + * + * Return: If @out_strs is NULL, the number of strings in the property is returned. + */ +static inline int of_property_read_string_array_index(const struct device_node *np, + const char *propname, + const char **out_strs, + size_t sz, int index) +{ + return of_property_read_string_helper(np, propname, out_strs, sz, index); +} /** * of_property_count_strings() - Find and return the number of strings from a * multiple strings property. From patchwork Fri Mar 25 11:31:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 12791503 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C8F9C433EF for ; Fri, 25 Mar 2022 11:34:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356470AbiCYLfr (ORCPT ); Fri, 25 Mar 2022 07:35:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356159AbiCYLfm (ORCPT ); Fri, 25 Mar 2022 07:35:42 -0400 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6628A9956; Fri, 25 Mar 2022 04:34:07 -0700 (PDT) Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 7BC6120004; Fri, 25 Mar 2022 11:34:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1648208046; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=t7jG696msxIP+uipvIAwEjfKw2CtLhwybjn43oZI2Bk=; b=E3Y78V/6ViYdGor+Zi7veNZ75Wfj/6aczWRtwfYm5OXuROosQ4A/pbVfUSZKKK5GRycOtL qaHuoPi6N4oMqcCXh673Ct+qZIcMuKPfXZ7Qq/ZNaZM9k+JFbtptl4R7PrruN+4O57muPg usFJ2JhCQOpfUN7s5Qgzy3/jIyoamSeUWpMs8UWGOfOfGF9x04bO1sbf4aNHWrYghDoIC0 J2+lGqph+k5iIxjZKiawakTGONCrAGeBX3opz5XnujJa79N92j1kw41AvbN95KEIOZa4Td mD7gCqP4DmV6Fng7+x4MxpHihzGnAyH3Keea2diZ8rYx7d6UHPvvs8+us945wg== From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J . Wysocki" , Wolfram Sang , Peter Rosin , Rob Herring , Frank Rowand , Len Brown Cc: Hans de Goede , Thomas Petazzoni , Alexandre Belloni , Allan Nielsen , linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= Subject: [PATCH v3 2/9] of: unittests: add tests for of_property_read_string_array_index() Date: Fri, 25 Mar 2022 12:31:41 +0100 Message-Id: <20220325113148.588163-3-clement.leger@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220325113148.588163-1-clement.leger@bootlin.com> References: <20220325113148.588163-1-clement.leger@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Add testing for of_property_read_string_array_index() function which allows to retrieve a string array starting at a specified offset. These tests are testing some basic use-case for this function. Signed-off-by: Clément Léger Reviewed-by: Rob Herring --- drivers/of/unittest.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 2c2fb161b572..d39ec2f5d2c5 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -759,6 +759,26 @@ static void __init of_unittest_property_string(void) strings[1] = NULL; rc = of_property_read_string_array(np, "phandle-list-names", strings, 1); unittest(rc == 1 && strings[1] == NULL, "Overwrote end of string array; rc=%i, str='%s'\n", rc, strings[1]); + + /* of_property_read_string_array_index() tests */ + rc = of_property_read_string_array_index(np, "string-property", strings, 4, 0); + unittest(rc == 1, "Incorrect string count; rc=%i\n", rc); + rc = of_property_read_string_array_index(np, "string-property", strings, 4, 1); + unittest(rc == -ENODATA, "Incorrect return value; rc=%i\n", rc); + rc = of_property_read_string_array_index(np, "phandle-list-names", strings, 2, 0); + unittest(rc == 2 && !strcmp(strings[0], "first") && !strcmp(strings[1], "second"), + "of_property_read_string_array_index() failure; rc=%i\n", rc); + rc = of_property_read_string_array_index(np, "phandle-list-names", strings, 2, 1); + unittest(rc == 2 && !strcmp(strings[0], "second") && !strcmp(strings[1], "third"), + "of_property_read_string_array_index() failure; rc=%i\n", rc); + rc = of_property_read_string_array_index(np, "phandle-list-names", strings, 4, 1); + unittest(rc == 2 && !strcmp(strings[0], "second") && !strcmp(strings[1], "third"), + "of_property_read_string_array_index() failure; rc=%i\n", rc); + rc = of_property_read_string_array_index(np, "phandle-list-names", strings, 1, 2); + unittest(rc == 1 && !strcmp(strings[0], "third"), + "of_property_read_string_array_index() failure; rc=%i\n", rc); + rc = of_property_read_string_array_index(np, "phandle-list-names", strings, 1, 3); + unittest(rc == -ENODATA, "Incorrect return value; rc=%i\n", rc); } #define propcmp(p1, p2) (((p1)->length == (p2)->length) && \ From patchwork Fri Mar 25 11:31:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 12791504 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9412FC4332F for ; Fri, 25 Mar 2022 11:34:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356573AbiCYLfr (ORCPT ); Fri, 25 Mar 2022 07:35:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356244AbiCYLfn (ORCPT ); Fri, 25 Mar 2022 07:35:43 -0400 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED67DA995C; Fri, 25 Mar 2022 04:34:08 -0700 (PDT) Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 2B9022000E; Fri, 25 Mar 2022 11:34:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1648208047; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7+j1FPgQHZrTvHRl55BohIN+XKqxXzL6DLT9mW+8SbQ=; b=jfM9ZDVwVxnFawUXJBUIwwfmpiscLOblMJUT9HyN3XVBBzZft04rgUs0nIREde2YuPQy1g Lr+8nU4H7lvnXatRtaNICyEw/zyi59ahu0RpkvfHMnrFpvGBd+R5fbx7R2ZSDawvtL6PYz FgMqHErsE2YFdmdNoRJIcegaAGRV9SELe3Ig51de9Ay6R6LoH3QYjcVGQ6NL8/dmmYWn1c QRmEucDQxhgjdCuZOvIp3ZyT11/fwzIxsl0Y5x6OQO4EM4aw6xEFgxrvKH2k2jKamNBeSZ 9XgXoGwhQLWZtG5Ygdpxq0T4hc9p4iZpThT2aHOrkdSgOA44jCfXDXCQVZZeXQ== From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J . Wysocki" , Wolfram Sang , Peter Rosin , Rob Herring , Frank Rowand , Len Brown Cc: Hans de Goede , Thomas Petazzoni , Alexandre Belloni , Allan Nielsen , linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= Subject: [PATCH v3 3/9] device property: add index argument to property_read_string_array() callback Date: Fri, 25 Mar 2022 12:31:42 +0100 Message-Id: <20220325113148.588163-4-clement.leger@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220325113148.588163-1-clement.leger@bootlin.com> References: <20220325113148.588163-1-clement.leger@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org This will allow to read a string array from a specified offset. Support for this new parameter has been added in both of through the use of of_property_read_string_array_index() and in swnode though the existing property_entry_read_string_array() function. ACPI support has not yet been added and only index == 0 is accepted. Signed-off-by: Clément Léger --- drivers/acpi/property.c | 5 ++++- drivers/base/property.c | 4 ++-- drivers/base/swnode.c | 21 +++++++++++++++------ drivers/of/property.c | 5 +++-- include/linux/fwnode.h | 7 ++++--- 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c index 12bbfe833609..7847b21c94f7 100644 --- a/drivers/acpi/property.c +++ b/drivers/acpi/property.c @@ -1293,8 +1293,11 @@ acpi_fwnode_property_read_int_array(const struct fwnode_handle *fwnode, static int acpi_fwnode_property_read_string_array(const struct fwnode_handle *fwnode, const char *propname, const char **val, - size_t nval) + size_t nval, int index) { + if (index != 0) + return -EINVAL; + return acpi_node_prop_read(fwnode, propname, DEV_PROP_STRING, val, nval); } diff --git a/drivers/base/property.c b/drivers/base/property.c index e6497f6877ee..d95c949e0a79 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -372,12 +372,12 @@ int fwnode_property_read_string_array(const struct fwnode_handle *fwnode, int ret; ret = fwnode_call_int_op(fwnode, property_read_string_array, propname, - val, nval); + val, nval, 0); if (ret == -EINVAL && !IS_ERR_OR_NULL(fwnode) && !IS_ERR_OR_NULL(fwnode->secondary)) ret = fwnode_call_int_op(fwnode->secondary, property_read_string_array, propname, - val, nval); + val, nval, 0); return ret; } EXPORT_SYMBOL_GPL(fwnode_property_read_string_array); diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index 0a482212c7e8..cb80dab041ef 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -184,9 +184,10 @@ static int property_entry_read_int_array(const struct property_entry *props, static int property_entry_read_string_array(const struct property_entry *props, const char *propname, - const char **strings, size_t nval) + const char **strings, size_t nval, + int index) { - const void *pointer; + const char * const *pointer; size_t length; int array_len; @@ -200,13 +201,20 @@ static int property_entry_read_string_array(const struct property_entry *props, if (!strings) return array_len; - array_len = min_t(size_t, nval, array_len); length = array_len * sizeof(*strings); - pointer = property_entry_find(props, propname, length); if (IS_ERR(pointer)) return PTR_ERR(pointer); + if (index >= array_len) + return -ENODATA; + + pointer += index; + array_len -= index; + + array_len = min_t(size_t, nval, array_len); + length = array_len * sizeof(*strings); + memcpy(strings, pointer, length); return array_len; @@ -400,12 +408,13 @@ static int software_node_read_int_array(const struct fwnode_handle *fwnode, static int software_node_read_string_array(const struct fwnode_handle *fwnode, const char *propname, - const char **val, size_t nval) + const char **val, size_t nval, + int index) { struct swnode *swnode = to_swnode(fwnode); return property_entry_read_string_array(swnode->node->properties, - propname, val, nval); + propname, val, nval, index); } static const char * diff --git a/drivers/of/property.c b/drivers/of/property.c index 8e90071de6ed..77e8df4a6267 100644 --- a/drivers/of/property.c +++ b/drivers/of/property.c @@ -906,12 +906,13 @@ static int of_fwnode_property_read_int_array(const struct fwnode_handle *fwnode, static int of_fwnode_property_read_string_array(const struct fwnode_handle *fwnode, const char *propname, const char **val, - size_t nval) + size_t nval, int index) { const struct device_node *node = to_of_node(fwnode); return val ? - of_property_read_string_array(node, propname, val, nval) : + of_property_read_string_array_index(node, propname, val, nval, + index) : of_property_count_strings(node, propname); } diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h index 3a532ba66f6c..b9e28ba49038 100644 --- a/include/linux/fwnode.h +++ b/include/linux/fwnode.h @@ -91,8 +91,9 @@ struct fwnode_reference_args { * @property_present: Return true if a property is present. * @property_read_int_array: Read an array of integer properties. Return zero on * success, a negative error code otherwise. - * @property_read_string_array: Read an array of string properties. Return zero - * on success, a negative error code otherwise. + * @property_read_string_array: Read an array of string properties starting at + * a specified index. Return zero on success, a + * negative error code otherwise. * @get_name: Return the name of an fwnode. * @get_name_prefix: Get a prefix for a node (for printing purposes). * @get_parent: Return the parent of an fwnode. @@ -122,7 +123,7 @@ struct fwnode_operations { int (*property_read_string_array)(const struct fwnode_handle *fwnode_handle, const char *propname, const char **val, - size_t nval); + size_t nval, int index); const char *(*get_name)(const struct fwnode_handle *fwnode); const char *(*get_name_prefix)(const struct fwnode_handle *fwnode); struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode); From patchwork Fri Mar 25 11:31:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 12791506 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C102C3527A for ; Fri, 25 Mar 2022 11:34:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356893AbiCYLfu (ORCPT ); Fri, 25 Mar 2022 07:35:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356273AbiCYLfp (ORCPT ); Fri, 25 Mar 2022 07:35:45 -0400 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 953CCBF500; Fri, 25 Mar 2022 04:34:10 -0700 (PDT) Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id AF6D12000D; Fri, 25 Mar 2022 11:34:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1648208049; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FMZGg8/3IdkuVd8+r/gnt8MAIBaSCmXIF+AlPEdNXgs=; b=M6bW8oLwl4IGPQ9ZEIfRTt+ppthPDu8zKCbG3J86s9PZ4jrnc/t5omOPZp/QpsyOxwoC/o kIkwpXlqU0Bx0Eol6vQ/VAU/gedIKcvej23cAali0haV2GETrIgU4Ut9G34FYpGpXxTlSm 5tDKJDs0/8W2ntMGzrdBZofJrGCj/Qk+lekKTvGjhyAMozOGD15m0XdBFt/mQKRn62VMcT s0F7Zv965bb7djJ+ZyvrRAYBq43m2cviYqLYB2gIq+UwlSAwLXopFzwf5ZmLqk5omzqm9F YwufOla0Hhp+gfJByKXszFqMLe1MWmPoo6lgeSajwcjWErS1yWfxicpB9tLu7w== From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J . Wysocki" , Wolfram Sang , Peter Rosin , Rob Herring , Frank Rowand , Len Brown Cc: Hans de Goede , Thomas Petazzoni , Alexandre Belloni , Allan Nielsen , linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= Subject: [PATCH v3 4/9] device property: add fwnode_property_read_string_index() Date: Fri, 25 Mar 2022 12:31:43 +0100 Message-Id: <20220325113148.588163-5-clement.leger@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220325113148.588163-1-clement.leger@bootlin.com> References: <20220325113148.588163-1-clement.leger@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Add fwnode_property_read_string_index() function which allows to retrieve a single string from an array by its index. This function is the equivalent of of_property_read_string_index() but for fwnode support. Signed-off-by: Clément Léger --- drivers/base/property.c | 33 +++++++++++++++++++++++++++++++++ include/linux/property.h | 3 +++ 2 files changed, 36 insertions(+) diff --git a/drivers/base/property.c b/drivers/base/property.c index d95c949e0a79..a2cfdf57b847 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -406,6 +406,39 @@ int fwnode_property_read_string(const struct fwnode_handle *fwnode, } EXPORT_SYMBOL_GPL(fwnode_property_read_string); +/** + * fwnode_property_read_string_index - read a string in an array using an index + * @fwnode: Firmware node to get the property of + * @propname: Name of the property holding the array + * @index: Index of the string to look for + * @string: Pointer to the string if found + * + * Find a string by a given index in a string array and if it is found return + * the string value in @string. + * + * Return: %0 if the string was found (success), + * %-EINVAL if given arguments are not valid, + * %-ENODATA if the property does not have a value, + * %-EPROTO if the property is not an array of strings, + * %-ENXIO if no suitable firmware interface is present. + */ +int fwnode_property_read_string_index(const struct fwnode_handle *fwnode, + const char *propname, int index, + const char **string) +{ + int ret; + + ret = fwnode_call_int_op(fwnode, property_read_string_array, propname, + string, 1, index); + if (ret == -EINVAL && !IS_ERR_OR_NULL(fwnode) && + !IS_ERR_OR_NULL(fwnode->secondary)) + ret = fwnode_call_int_op(fwnode->secondary, + property_read_string_array, propname, + string, 1, index); + return ret == 1 ? 0 : ret; +} +EXPORT_SYMBOL_GPL(fwnode_property_read_string_index); + /** * fwnode_property_match_string - find a string in an array and return index * @fwnode: Firmware node to get the property of diff --git a/include/linux/property.h b/include/linux/property.h index 7399a0b45f98..a033920eb10a 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -70,6 +70,9 @@ int fwnode_property_read_string_array(const struct fwnode_handle *fwnode, size_t nval); int fwnode_property_read_string(const struct fwnode_handle *fwnode, const char *propname, const char **val); +int fwnode_property_read_string_index(const struct fwnode_handle *fwnode, + const char *propname, int index, + const char **string); int fwnode_property_match_string(const struct fwnode_handle *fwnode, const char *propname, const char *string); int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode, From patchwork Fri Mar 25 11:31:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 12791505 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E888C4167B for ; Fri, 25 Mar 2022 11:34:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356665AbiCYLfs (ORCPT ); Fri, 25 Mar 2022 07:35:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356438AbiCYLfq (ORCPT ); Fri, 25 Mar 2022 07:35:46 -0400 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5ED78D3AF3; Fri, 25 Mar 2022 04:34:12 -0700 (PDT) Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 544D720013; Fri, 25 Mar 2022 11:34:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1648208051; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4R0N7D8tALRuS3AKBt7M/T2sGusCMys4umR0Kgc6iOo=; b=LuGDvVn+ffmAktrWs6yCD0HkYlWOV1nxlFJI+5QfyUr+X0KpQk5YUBYKygI81lBhP9yqZt 5vfM8gLhSbh28tGaFmHmcaqJQI97FwwQt1ED92dboof0tP+S6rggLmJHb/4VMEae90hHm/ DpwbWBifSxsRb1i6UvN9j5FR+SI5CNiexh8ZrBUd/tfqXy4BVHcA9MyB68vgz0bgaeP9lY TRLClBEQfpSp+LcAH5vZc10RMnfs+Aev/mzZMqQtlUtvuzycUyb1JMLQQTZdSTEKXZUf0U vhRu20eVuJvFBmsmE0adTFsn9O0H3Ip0JH+xZsmGrPZKyUquV7cYMRbGl3AHNg== From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J . Wysocki" , Wolfram Sang , Peter Rosin , Rob Herring , Frank Rowand , Len Brown Cc: Hans de Goede , Thomas Petazzoni , Alexandre Belloni , Allan Nielsen , linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= Subject: [PATCH v3 5/9] device property: add tests for fwnode_property_read_string_index() Date: Fri, 25 Mar 2022 12:31:44 +0100 Message-Id: <20220325113148.588163-6-clement.leger@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220325113148.588163-1-clement.leger@bootlin.com> References: <20220325113148.588163-1-clement.leger@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Add somes tests to validate fwnode_property_read_string_index(). Signed-off-by: Clément Léger --- drivers/base/test/property-entry-test.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/base/test/property-entry-test.c b/drivers/base/test/property-entry-test.c index 6071d5bc128c..9edbaa53a950 100644 --- a/drivers/base/test/property-entry-test.c +++ b/drivers/base/test/property-entry-test.c @@ -318,6 +318,24 @@ static void pe_test_strings(struct kunit *test) KUNIT_EXPECT_EQ(test, error, 0); KUNIT_EXPECT_STREQ(test, str, "string-a"); + error = fwnode_property_read_string_index(node, "str", 0, strs); + KUNIT_EXPECT_EQ(test, error, 0); + KUNIT_EXPECT_STREQ(test, strs[0], "single"); + + error = fwnode_property_read_string_index(node, "strs", 0, strs); + KUNIT_EXPECT_EQ(test, error, 0); + KUNIT_EXPECT_STREQ(test, strs[0], "string-a"); + + error = fwnode_property_read_string_index(node, "strs", 1, strs); + KUNIT_EXPECT_EQ(test, error, 0); + KUNIT_EXPECT_STREQ(test, strs[0], "string-b"); + + error = fwnode_property_read_string_index(node, "str", 1, strs); + KUNIT_EXPECT_EQ(test, error, -ENODATA); + + error = fwnode_property_read_string_index(node, "strs", 3, strs); + KUNIT_EXPECT_EQ(test, error, -ENODATA); + fwnode_remove_software_node(node); } From patchwork Fri Mar 25 11:31:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 12791507 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A412C433F5 for ; Fri, 25 Mar 2022 11:34:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356829AbiCYLf6 (ORCPT ); Fri, 25 Mar 2022 07:35:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356834AbiCYLfu (ORCPT ); Fri, 25 Mar 2022 07:35:50 -0400 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81986D0AA0; Fri, 25 Mar 2022 04:34:14 -0700 (PDT) Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 1B7B82000A; Fri, 25 Mar 2022 11:34:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1648208053; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MDm4YP1sE29344rf2R0COIQGSk7+i5VU29q/DiQVbuo=; b=fQumbr94pjkHijI+6zW+z78A41y+IOIUv0R9PUVZdKcQ+vXD5q0X9vEBQwhLZnbp7nuXR0 4PwC6uqutz4MMEHFBFM/MHCYm4ocKnV9T7is0W7K7HwdoG2qazPDvh2JpM9KCoPg9084pp 2EizFc+ySBSg4DQ5pezyrwFmSKyMwcOx5ZxnzlVh2LYgoFJqvSfXuK0OPAGQdtGF7AoBHk kDiiCAk3MSFsH+dtzhB9z8OSq/VEuWEQDWJfM5TYrIlfQT4U4xvUW/85LotXAkcUWiWb2Y umuSa2kv89CEHynCm5XDB5eO5KXXAoM4Lczj0Qpm4srEzl2XRUGdyW3BmGbXBQ== From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J . Wysocki" , Wolfram Sang , Peter Rosin , Rob Herring , Frank Rowand , Len Brown Cc: Hans de Goede , Thomas Petazzoni , Alexandre Belloni , Allan Nielsen , linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= Subject: [PATCH v3 6/9] i2c: fwnode: add fwnode_find_i2c_adapter_by_node() Date: Fri, 25 Mar 2022 12:31:45 +0100 Message-Id: <20220325113148.588163-7-clement.leger@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220325113148.588163-1-clement.leger@bootlin.com> References: <20220325113148.588163-1-clement.leger@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Add fwnode_find_i2c_adapter_by_node() which allows to retrieve a i2c adapter using a fwnode. Since dev_fwnode() uses the fwnode provided by the of_node member of the device, this will also work for devices were the of_node has been set and not the fwnode field. For acpi nodes, the check for parent node is skipped since i2c_acpi_find_adapter_by_handle() does not check it and we don't want to change this behavior. Signed-off-by: Clément Léger --- drivers/i2c/Makefile | 1 + drivers/i2c/i2c-core-fwnode.c | 45 +++++++++++++++++++++++++++++++++++ include/linux/i2c.h | 3 +++ 3 files changed, 49 insertions(+) create mode 100644 drivers/i2c/i2c-core-fwnode.c diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile index c1d493dc9bac..c9c97675163e 100644 --- a/drivers/i2c/Makefile +++ b/drivers/i2c/Makefile @@ -6,6 +6,7 @@ obj-$(CONFIG_I2C_BOARDINFO) += i2c-boardinfo.o obj-$(CONFIG_I2C) += i2c-core.o i2c-core-objs := i2c-core-base.o i2c-core-smbus.o +i2c-core-objs += i2c-core-fwnode.o i2c-core-$(CONFIG_ACPI) += i2c-core-acpi.o i2c-core-$(CONFIG_I2C_SLAVE) += i2c-core-slave.o i2c-core-$(CONFIG_OF) += i2c-core-of.o diff --git a/drivers/i2c/i2c-core-fwnode.c b/drivers/i2c/i2c-core-fwnode.c new file mode 100644 index 000000000000..fb1c820b686e --- /dev/null +++ b/drivers/i2c/i2c-core-fwnode.c @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Linux I2C core fwnode support code + * + * Copyright (C) 2022 Microchip + */ + +#include +#include + +#include "i2c-core.h" + +static int fwnode_dev_or_parent_node_match(struct device *dev, const void *data) +{ + if (device_match_fwnode(dev, data)) + return 1; + + /* + * For ACPI device node, the behavior is to not match the parent (see + * i2c_acpi_find_adapter_by_handle()) + */ + if (!is_acpi_device_node(dev_fwnode(dev)) && dev->parent) + return device_match_fwnode(dev->parent, data); + + return 0; +} + +struct i2c_adapter * +fwnode_find_i2c_adapter_by_node(struct fwnode_handle *fwnode) +{ + struct device *dev; + struct i2c_adapter *adapter; + + dev = bus_find_device(&i2c_bus_type, NULL, fwnode, + fwnode_dev_or_parent_node_match); + if (!dev) + return NULL; + + adapter = i2c_verify_adapter(dev); + if (!adapter) + put_device(dev); + + return adapter; +} +EXPORT_SYMBOL(fwnode_find_i2c_adapter_by_node); diff --git a/include/linux/i2c.h b/include/linux/i2c.h index 7d4f52ceb7b5..8dadf8c89fd9 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -967,6 +967,9 @@ int i2c_handle_smbus_host_notify(struct i2c_adapter *adap, unsigned short addr); #endif /* I2C */ +struct i2c_adapter * +fwnode_find_i2c_adapter_by_node(struct fwnode_handle *fwnode); + #if IS_ENABLED(CONFIG_OF) /* must call put_device() when done with returned i2c_client device */ struct i2c_client *of_find_i2c_device_by_node(struct device_node *node); From patchwork Fri Mar 25 11:31:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 12791509 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC8EAC4321E for ; Fri, 25 Mar 2022 11:34:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356244AbiCYLgD (ORCPT ); Fri, 25 Mar 2022 07:36:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349385AbiCYLf4 (ORCPT ); Fri, 25 Mar 2022 07:35:56 -0400 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1462D3AFE; Fri, 25 Mar 2022 04:34:16 -0700 (PDT) Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 30F692000C; Fri, 25 Mar 2022 11:34:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1648208055; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4eDLu/2S0pER1wydEQfRnihBM7t30+ODzLZgZNZH6Fs=; b=VSBvB2rgJnBlytaFmt2Sj8/mSMuGp6ocmmY6VLXtdDuFoZnbQ3NpDd4P+/EvnPrJrnmqLl fu4h80rH64GgU/EBQEfo37iXpsecvkErhf4BZUJWbepk3yzUj0JsrTrnWfiD7EX9vdO414 adX5BZHaYTxMBR+ukt9AxorWwSCdy9Qv9Akh+Z5wYR5zk2qTW7gkv6dtF5OjhH2DQI5pzP 8hcvFNYLP+yRwCOnJk+APpIV/zw+0zWV6sa0LXGt3Hnpv1lRNJbsybvBQWCIwzJFfDCSq5 AaKmyZ7dlfFbS1nclRCLV2v3/3iLkn8TjDeHyNSkelw8y6WArkwL03zKI0yrmg== From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J . Wysocki" , Wolfram Sang , Peter Rosin , Rob Herring , Frank Rowand , Len Brown Cc: Hans de Goede , Thomas Petazzoni , Alexandre Belloni , Allan Nielsen , linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= Subject: [PATCH v3 7/9] i2c: of: use fwnode_get_i2c_adapter_by_node() Date: Fri, 25 Mar 2022 12:31:46 +0100 Message-Id: <20220325113148.588163-8-clement.leger@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220325113148.588163-1-clement.leger@bootlin.com> References: <20220325113148.588163-1-clement.leger@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Since the new fwnode based fwnode_find_i2c_adapter_by_node() function has the same behavior than of_get_i2c_adapter_by_node(), call it to avoid code duplication. Signed-off-by: Clément Léger --- drivers/i2c/i2c-core-of.c | 30 ------------------------------ include/linux/i2c.h | 5 ++++- 2 files changed, 4 insertions(+), 31 deletions(-) diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c index 3ed74aa4b44b..be7d66aa0f49 100644 --- a/drivers/i2c/i2c-core-of.c +++ b/drivers/i2c/i2c-core-of.c @@ -113,17 +113,6 @@ void of_i2c_register_devices(struct i2c_adapter *adap) of_node_put(bus); } -static int of_dev_or_parent_node_match(struct device *dev, const void *data) -{ - if (dev->of_node == data) - return 1; - - if (dev->parent) - return dev->parent->of_node == data; - - return 0; -} - /* must call put_device() when done with returned i2c_client device */ struct i2c_client *of_find_i2c_device_by_node(struct device_node *node) { @@ -142,25 +131,6 @@ struct i2c_client *of_find_i2c_device_by_node(struct device_node *node) } EXPORT_SYMBOL(of_find_i2c_device_by_node); -/* must call put_device() when done with returned i2c_adapter device */ -struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node) -{ - struct device *dev; - struct i2c_adapter *adapter; - - dev = bus_find_device(&i2c_bus_type, NULL, node, - of_dev_or_parent_node_match); - if (!dev) - return NULL; - - adapter = i2c_verify_adapter(dev); - if (!adapter) - put_device(dev); - - return adapter; -} -EXPORT_SYMBOL(of_find_i2c_adapter_by_node); - /* must call i2c_put_adapter() when done with returned i2c_adapter device */ struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node *node) { diff --git a/include/linux/i2c.h b/include/linux/i2c.h index 8dadf8c89fd9..982918fd0093 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -975,7 +975,10 @@ fwnode_find_i2c_adapter_by_node(struct fwnode_handle *fwnode); struct i2c_client *of_find_i2c_device_by_node(struct device_node *node); /* must call put_device() when done with returned i2c_adapter device */ -struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node); +static inline struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node) +{ + return fwnode_find_i2c_adapter_by_node(of_fwnode_handle(node)); +} /* must call i2c_put_adapter() when done with returned i2c_adapter device */ struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node *node); From patchwork Fri Mar 25 11:31:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 12791508 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C222C4332F for ; Fri, 25 Mar 2022 11:34:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353092AbiCYLgB (ORCPT ); Fri, 25 Mar 2022 07:36:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356299AbiCYLf7 (ORCPT ); Fri, 25 Mar 2022 07:35:59 -0400 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90F6CD444C; Fri, 25 Mar 2022 04:34:18 -0700 (PDT) Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 9B3052000D; Fri, 25 Mar 2022 11:34:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1648208057; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IdtHSEns/kbR1RODo7rJJZ+DXlhGmh7K4+UmBU92PnA=; b=e4PCD8Ju0RNF87b3BW82QPiUv9PS6gexdvFliyb9NOwHje8H8EiJXVSZsYYuMVquOhe2k/ 9U2UM7Ifk38vQ5aRGIw0FlxSyivf+Z3zgac7TWMByfxz9OVKpw8S46AI0df+0Hto90seey jqhO26BBezbEumafoKKn0L4+4u1jyrpUcEMHeZz6+8gP6/wefNlc4HOHmLLlc3BSyEult8 sAfXDSCd+bnVkY9ouLjgDx1q/H76Hyp5vbjZwIV1JGJCkxYBSv0mGYOSNXGmhRPxj3Y17h 9lnUDBsWFCQEVOxY5Efisq91zRCjuFQURV8ooufRWKBmxymyrvGrB/bi0HbZYQ== From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J . Wysocki" , Wolfram Sang , Peter Rosin , Rob Herring , Frank Rowand , Len Brown Cc: Hans de Goede , Thomas Petazzoni , Alexandre Belloni , Allan Nielsen , linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= Subject: [PATCH v3 8/9] i2c: mux: pinctrl: remove CONFIG_OF dependency and use fwnode API Date: Fri, 25 Mar 2022 12:31:47 +0100 Message-Id: <20220325113148.588163-9-clement.leger@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220325113148.588163-1-clement.leger@bootlin.com> References: <20220325113148.588163-1-clement.leger@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org In order to use i2c muxes with all types of nodes, switch to fwnode API. The fwnode layer will allow to use this with both device_node and software_node. This commits is simply replacing the use of "of_" prefixed functions with there fwnode equivalent. Signed-off-by: Clément Léger --- drivers/i2c/muxes/Kconfig | 1 - drivers/i2c/muxes/i2c-mux-pinctrl.c | 23 ++++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/i2c/muxes/Kconfig b/drivers/i2c/muxes/Kconfig index 1708b1a82da2..d9cb15cfba3e 100644 --- a/drivers/i2c/muxes/Kconfig +++ b/drivers/i2c/muxes/Kconfig @@ -77,7 +77,6 @@ config I2C_MUX_PCA954x config I2C_MUX_PINCTRL tristate "pinctrl-based I2C multiplexer" depends on PINCTRL - depends on OF || COMPILE_TEST help If you say yes to this option, support will be included for an I2C multiplexer that uses the pinctrl subsystem, i.e. pin multiplexing. diff --git a/drivers/i2c/muxes/i2c-mux-pinctrl.c b/drivers/i2c/muxes/i2c-mux-pinctrl.c index f1bb00a11ad6..d9c0241e8790 100644 --- a/drivers/i2c/muxes/i2c-mux-pinctrl.c +++ b/drivers/i2c/muxes/i2c-mux-pinctrl.c @@ -53,19 +53,20 @@ static struct i2c_adapter *i2c_mux_pinctrl_root_adapter( static struct i2c_adapter *i2c_mux_pinctrl_parent_adapter(struct device *dev) { - struct device_node *np = dev->of_node; - struct device_node *parent_np; + struct fwnode_handle *fwnode = dev_fwnode(dev); + struct fwnode_handle *parent_fwnode; struct i2c_adapter *parent; - parent_np = of_parse_phandle(np, "i2c-parent", 0); - if (!parent_np) { + parent_fwnode = fwnode_find_reference(fwnode, "i2c-parent", 0); + if (!parent_fwnode) { dev_err(dev, "Cannot parse i2c-parent\n"); return ERR_PTR(-ENODEV); } - parent = of_find_i2c_adapter_by_node(parent_np); - of_node_put(parent_np); - if (!parent) + parent = fwnode_find_i2c_adapter_by_node(parent_fwnode); + if (!parent) { + dev_err(dev, "Cannot find i2c-parent\n"); return ERR_PTR(-EPROBE_DEFER); + } return parent; } @@ -73,7 +74,7 @@ static struct i2c_adapter *i2c_mux_pinctrl_parent_adapter(struct device *dev) static int i2c_mux_pinctrl_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; - struct device_node *np = dev->of_node; + struct fwnode_handle *fwnode = dev_fwnode(dev); struct i2c_mux_core *muxc; struct i2c_mux_pinctrl *mux; struct i2c_adapter *parent; @@ -81,7 +82,7 @@ static int i2c_mux_pinctrl_probe(struct platform_device *pdev) int num_names, i, ret; const char *name; - num_names = of_property_count_strings(np, "pinctrl-names"); + num_names = fwnode_property_string_array_count(fwnode, "pinctrl-names"); if (num_names < 0) { dev_err(dev, "Cannot parse pinctrl-names: %d\n", num_names); @@ -111,8 +112,8 @@ static int i2c_mux_pinctrl_probe(struct platform_device *pdev) } for (i = 0; i < num_names; i++) { - ret = of_property_read_string_index(np, "pinctrl-names", i, - &name); + ret = fwnode_property_read_string_index(fwnode, "pinctrl-names", i, + &name); if (ret < 0) { dev_err(dev, "Cannot parse pinctrl-names: %d\n", ret); goto err_put_parent; From patchwork Fri Mar 25 11:31:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 12791510 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B88E2C433F5 for ; Fri, 25 Mar 2022 11:34:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357131AbiCYLgZ (ORCPT ); Fri, 25 Mar 2022 07:36:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357112AbiCYLgA (ORCPT ); Fri, 25 Mar 2022 07:36:00 -0400 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64336D4460; Fri, 25 Mar 2022 04:34:20 -0700 (PDT) Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 5637A20013; Fri, 25 Mar 2022 11:34:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1648208058; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HUpLm117R6qk/dVKFhWwKw0DOB6khYAmxgji50KW67s=; b=Yip7aUAf6QKSRIUfebg75F7lbIEZuHnFlsuQ5u1HR5EQawmloYET9ySHQVEDTlokV2pCPG BBeDo3NiHiugqObDF8eZ95WFAo5KF/GHG7AsF0XZC1hVPWxgJLE7AJomQNu9gKR+RNAP9P MbAYFDjtSZnTrJJ/abL22Ki1SBehfPJfXvqWtVTPHVnYdc8dz7byYWT/AXPRjmTvn9z4Y7 chIoIrAI6upZJTfrGjU4ooYk9fQ0pokDLsXu5wNc6VTHyYl89szRg1ap8/YblkHdGs65u2 zHSDt++i26DnlQYh7Yjbmz7I7iVIf1NMBQQcGWuH73ys75wc5ZEqY1EeYW8Iqg== From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J . Wysocki" , Wolfram Sang , Peter Rosin , Rob Herring , Frank Rowand , Len Brown Cc: Hans de Goede , Thomas Petazzoni , Alexandre Belloni , Allan Nielsen , linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= Subject: [PATCH v3 9/9] i2c: mux: add support for fwnode Date: Fri, 25 Mar 2022 12:31:48 +0100 Message-Id: <20220325113148.588163-10-clement.leger@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220325113148.588163-1-clement.leger@bootlin.com> References: <20220325113148.588163-1-clement.leger@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Modify i2c_mux_add_adapter() to use the fwnode API to create mux adapters with fwnode based devices. This allows to have a node agnostic support for i2c muxes. Signed-off-by: Clément Léger --- drivers/i2c/i2c-mux.c | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c index 774507b54b57..98d735349bd6 100644 --- a/drivers/i2c/i2c-mux.c +++ b/drivers/i2c/i2c-mux.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include @@ -347,38 +347,35 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc, else priv->adap.class = class; - /* - * Try to populate the mux adapter's of_node, expands to - * nothing if !CONFIG_OF. - */ - if (muxc->dev->of_node) { - struct device_node *dev_node = muxc->dev->of_node; - struct device_node *mux_node, *child = NULL; + /* Try to populate the mux adapter's device node */ + if (dev_fwnode(muxc->dev) && !has_acpi_companion(muxc->dev)) { + struct fwnode_handle *dev_node = dev_fwnode(muxc->dev); + struct fwnode_handle *mux_node, *child = NULL; u32 reg; if (muxc->arbitrator) - mux_node = of_get_child_by_name(dev_node, "i2c-arb"); + mux_node = fwnode_get_named_child_node(dev_node, "i2c-arb"); else if (muxc->gate) - mux_node = of_get_child_by_name(dev_node, "i2c-gate"); + mux_node = fwnode_get_named_child_node(dev_node, "i2c-gate"); else - mux_node = of_get_child_by_name(dev_node, "i2c-mux"); + mux_node = fwnode_get_named_child_node(dev_node, "i2c-mux"); if (mux_node) { /* A "reg" property indicates an old-style DT entry */ - if (!of_property_read_u32(mux_node, "reg", ®)) { - of_node_put(mux_node); + if (!fwnode_property_read_u32(mux_node, "reg", ®)) { + fwnode_handle_put(mux_node); mux_node = NULL; } } if (!mux_node) - mux_node = of_node_get(dev_node); + mux_node = fwnode_handle_get(dev_node); else if (muxc->arbitrator || muxc->gate) - child = of_node_get(mux_node); + child = fwnode_handle_get(mux_node); if (!child) { - for_each_child_of_node(mux_node, child) { - ret = of_property_read_u32(child, "reg", ®); + fwnode_for_each_child_node(mux_node, child) { + ret = fwnode_property_read_u32(child, "reg", ®); if (ret) continue; if (chan_id == reg) @@ -386,8 +383,8 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc, } } - priv->adap.dev.of_node = child; - of_node_put(mux_node); + device_set_node(&priv->adap.dev, child); + fwnode_handle_put(mux_node); } /* @@ -444,7 +441,7 @@ void i2c_mux_del_adapters(struct i2c_mux_core *muxc) while (muxc->num_adapters) { struct i2c_adapter *adap = muxc->adapter[--muxc->num_adapters]; struct i2c_mux_priv *priv = adap->algo_data; - struct device_node *np = adap->dev.of_node; + struct fwnode_handle *fwnode = dev_fwnode(&adap->dev); muxc->adapter[muxc->num_adapters] = NULL; @@ -454,7 +451,7 @@ void i2c_mux_del_adapters(struct i2c_mux_core *muxc) sysfs_remove_link(&priv->adap.dev.kobj, "mux_device"); i2c_del_adapter(adap); - of_node_put(np); + fwnode_handle_put(fwnode); kfree(priv); } }