From patchwork Wed Mar 23 09:18:04 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: 553816 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 8BC60C433FE for ; Wed, 23 Mar 2022 09:20:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243137AbiCWJV2 (ORCPT ); Wed, 23 Mar 2022 05:21:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243129AbiCWJV1 (ORCPT ); Wed, 23 Mar 2022 05:21:27 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EF8575E7C; Wed, 23 Mar 2022 02:19:56 -0700 (PDT) Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 0F449E0004; Wed, 23 Mar 2022 09:19:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1648027194; 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=LFZ0Z7uvf0VFG2tUAEpLJUaxBE7qdMjsJkE8V6W3WAM=; b=nOuB63TVx0TmcZXmCmw8aLIxa0FBePow7kE7/h05JJVQV1cUj5mMRYPN5ERsNoj49ARY4f Caj0HnMNN8Js+1JtOG46YgfVYJiIataFu80LNW3P20UtkjS1OdrdztTnc4K/edGT4cety6 3GUXtUkpioPA1SVkvWsStP2/AVj/4Qe4mC+Bz084CYCIWEEhe8exsvi4/Sop8Hyao9cIKk /luXEH2wYZ+8pXzXPLcb6eJeLL+EBC9+LJcSrAJUMwTdc6JBFzWrI0yc4+tHE3yFok+yHd 2MH3w1mb7oeFnPJTepTv9PWz5aeRJhCt0Wt4nywdysAFQoWRIbHpL2olGIbg3w== 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, =?utf-8?b?Q2zDqW1l?= =?utf-8?b?bnQgTMOpZ2Vy?= Subject: [PATCH v2 1/7] device property: add fwnode_property_read_string_index() Date: Wed, 23 Mar 2022 10:18:04 +0100 Message-Id: <20220323091810.329217-2-clement.leger@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220323091810.329217-1-clement.leger@bootlin.com> References: <20220323091810.329217-1-clement.leger@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Add fwnode_property_read_string_index() function which allows to retrieve a string from an array by its index. This function is the equivalent of of_property_read_string_index() but for fwnode support. A .property_read_string_index callback is added to fwnode_ops to avoid doing a full allocation of an array just to retrieve one value. Signed-off-by: Clément Léger --- drivers/base/property.c | 26 ++++++++++++++++++++++++++ include/linux/fwnode.h | 6 ++++++ include/linux/property.h | 3 +++ 3 files changed, 35 insertions(+) diff --git a/drivers/base/property.c b/drivers/base/property.c index e6497f6877ee..a8dd6e496a1d 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -451,6 +451,32 @@ int fwnode_property_match_string(const struct fwnode_handle *fwnode, } EXPORT_SYMBOL_GPL(fwnode_property_match_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 property 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) +{ + return fwnode_call_int_op(fwnode, property_read_string_index, propname, + index, + string); +} +EXPORT_SYMBOL_GPL(fwnode_property_read_string_index); + /** * fwnode_property_get_reference_args() - Find a reference with arguments * @fwnode: Firmware node where to look for the reference diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h index 3a532ba66f6c..71ba8f53cf1e 100644 --- a/include/linux/fwnode.h +++ b/include/linux/fwnode.h @@ -93,6 +93,9 @@ struct fwnode_reference_args { * 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_index: Read a string from a string array using an + * 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. @@ -123,6 +126,9 @@ struct fwnode_operations { (*property_read_string_array)(const struct fwnode_handle *fwnode_handle, const char *propname, const char **val, size_t nval); + int (*property_read_string_index)(const struct fwnode_handle *fwnode, + const char *propname, int index, + const char **string); 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); 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 Wed Mar 23 09:18:06 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: 553815 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 87185C433FE for ; Wed, 23 Mar 2022 09:20:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243152AbiCWJVe (ORCPT ); Wed, 23 Mar 2022 05:21:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243144AbiCWJV2 (ORCPT ); Wed, 23 Mar 2022 05:21:28 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2690874DD2; Wed, 23 Mar 2022 02:19:58 -0700 (PDT) Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 72F0DE0010; Wed, 23 Mar 2022 09:19:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1648027197; 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=cICvQx2VKeX9fxChlYZQ7+y007LmLSMNhcKdMqcVDIA=; b=LIWhl7Yee+it6/kRd+Y5X/8B6QozydisfINYYSoHM6PKm8xgRqDx7gR7ktA0M1NRjxWMWH /NFTcwwUezvBPX2K0Uio/AO46YutnkRJc5gVGHR1/eqKCIPaZpXj0u4YEWFpZyb0pj0QPG a0aHRxRBl0s/y5N0D6WAffqMLLmxqLB+Pb6/ooi/YuWxul0viTEOeWcddjQOArwLBW/C8R CbpqKfzIjptXZow9RjHj0709VwpzGNSQeShLaBQvwasmnNCFOaGHgq7bkEQK49TsyNlq3B lIF6FOTOK+mgciDwePzLY8mMBNXjMUVdiGrM2rbI4GzwOB9bF5HrfDZiXx8ntQ== 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, =?utf-8?b?Q2zDqW1l?= =?utf-8?b?bnQgTMOpZ2Vy?= Subject: [PATCH v2 3/7] software node: implement .property_read_string_index callback Date: Wed, 23 Mar 2022 10:18:06 +0100 Message-Id: <20220323091810.329217-4-clement.leger@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220323091810.329217-1-clement.leger@bootlin.com> References: <20220323091810.329217-1-clement.leger@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Implement .property_read_string_index callback by fetching the strings pointers from the software node property and getting the one at the requested index. Signed-off-by: Clément Léger --- drivers/base/swnode.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index 0a482212c7e8..91cefc62adb3 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -182,6 +182,34 @@ static int property_entry_read_int_array(const struct property_entry *props, return 0; } +static int property_entry_read_string_index(const struct property_entry *props, + const char *propname, int index, + const char **string) +{ + const char * const *strings; + size_t length; + int array_len; + + /* Find out the array length. */ + array_len = property_entry_count_elems_of_size(props, propname, + sizeof(const char *)); + if (array_len < 0) + return array_len; + + if (index >= array_len) + return -EINVAL; + + length = array_len * sizeof(const char *); + + strings = property_entry_find(props, propname, length); + if (IS_ERR(strings)) + return PTR_ERR(strings); + + *string = strings[index]; + + return 0; +} + static int property_entry_read_string_array(const struct property_entry *props, const char *propname, const char **strings, size_t nval) @@ -408,6 +436,17 @@ static int software_node_read_string_array(const struct fwnode_handle *fwnode, propname, val, nval); } +static int +software_node_read_string_index(const struct fwnode_handle *fwnode, + const char *propname, int index, + const char **string) +{ + struct swnode *swnode = to_swnode(fwnode); + + return property_entry_read_string_index(swnode->node->properties, + propname, index, string); +} + static const char * software_node_get_name(const struct fwnode_handle *fwnode) { @@ -665,6 +704,7 @@ static const struct fwnode_operations software_node_ops = { .property_present = software_node_property_present, .property_read_int_array = software_node_read_int_array, .property_read_string_array = software_node_read_string_array, + .property_read_string_index = software_node_read_string_index, .get_name = software_node_get_name, .get_name_prefix = software_node_get_name_prefix, .get_parent = software_node_get_parent, From patchwork Wed Mar 23 09:18:08 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: 553814 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 DAF11C433EF for ; Wed, 23 Mar 2022 09:20:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243232AbiCWJV5 (ORCPT ); Wed, 23 Mar 2022 05:21:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243187AbiCWJVd (ORCPT ); Wed, 23 Mar 2022 05:21:33 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 744B875E7C; Wed, 23 Mar 2022 02:20:02 -0700 (PDT) Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 88FCCE000E; Wed, 23 Mar 2022 09:19:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1648027201; 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=Slcfg90L7zse1fdHC1cbToI+C6ptiFNPPwtNRh+sKwrkru7R4N454yhBxrMgNYitIqI9/Q OsT521a3zN21ONiX0jiJcvdO8sqBzkN6o1fy1gOz8zuK10ESAbkc4Gm0rx05/vOq26myJp Wl0DPwiayaTWQkXx1YV3iSfqudMaO51uiEzV1bP2BXIJyjYu3EKIiVZcSNOvxIki/UmwZR rQ67gaRuTsW57t/0qph6fw/EUka5OIjxL+vZzZLoNSIFrhaM31t/VGCmiAeGORuKmWCQpE /sXC/pH5vbHH8aN+4WGetZzcEoUnX4hbY9vFcuEIkw3HZXfP6HmU5G6k+0am7g== 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, =?utf-8?b?Q2zDqW1l?= =?utf-8?b?bnQgTMOpZ2Vy?= Subject: [PATCH v2 5/7] i2c: of: use fwnode_get_i2c_adapter_by_node() Date: Wed, 23 Mar 2022 10:18:08 +0100 Message-Id: <20220323091810.329217-6-clement.leger@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220323091810.329217-1-clement.leger@bootlin.com> References: <20220323091810.329217-1-clement.leger@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@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 Wed Mar 23 09:18:10 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: 553813 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 7A7FFC433F5 for ; Wed, 23 Mar 2022 09:20:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240825AbiCWJWK (ORCPT ); Wed, 23 Mar 2022 05:22:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243154AbiCWJVu (ORCPT ); Wed, 23 Mar 2022 05:21:50 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 694F976291; Wed, 23 Mar 2022 02:20:07 -0700 (PDT) Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 56466E000A; Wed, 23 Mar 2022 09:20:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1648027206; 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=dPvmXmGtXpgBmU1X0IlbQ4qB7A3M7R3VFWbgsUAMc7U5dSbAoIHqa/TMUyBECy09gFb/sd dfMTJ3l3p0921MauzwIIx3fCOvczkB+8yWh7YKgRn5ymB65znHPpRYIpxHFdKjYvH6KoYp EvVJub2GPjbY0sIR6LXTRHvm6BHU0NZQuEEMdpTkm2LG7AyqVHJl/4DWH3fFClWgTcnXhY jLavWf80tTzW7suR7DkG20a+ZsdTrQFXPecq5fsrwosUmhnGdys/pr07IhpRWT5fMLAHtJ h2BgrEZOTk5hDJms6fdEeEqUY3ErY2Rs5xv29gmvFgBRA+mcCHailEX40WSn3A== 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, =?utf-8?b?Q2zDqW1l?= =?utf-8?b?bnQgTMOpZ2Vy?= Subject: [PATCH v2 7/7] i2c: mux: add support for fwnode Date: Wed, 23 Mar 2022 10:18:10 +0100 Message-Id: <20220323091810.329217-8-clement.leger@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220323091810.329217-1-clement.leger@bootlin.com> References: <20220323091810.329217-1-clement.leger@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@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); } }