From patchwork Mon Feb 21 16:26: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: 12753924 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 60A1BC4332F for ; Mon, 21 Feb 2022 16:38:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380820AbiBUQjM (ORCPT ); Mon, 21 Feb 2022 11:39:12 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:49574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380785AbiBUQjJ (ORCPT ); Mon, 21 Feb 2022 11:39:09 -0500 Received: from mslow1.mail.gandi.net (mslow1.mail.gandi.net [217.70.178.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9482E22BCA; Mon, 21 Feb 2022 08:38:36 -0800 (PST) Received: from relay9-d.mail.gandi.net (unknown [IPv6:2001:4b98:dc4:8::229]) by mslow1.mail.gandi.net (Postfix) with ESMTP id E3897D2381; Mon, 21 Feb 2022 16:29:13 +0000 (UTC) Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id DFC37FF811; Mon, 21 Feb 2022 16:29:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1645460950; 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=xXIueXWvKxX/LWoZoq8jZVCI0+VYYMkfxQec0Aoej8w=; b=k9pOzn/E8KfAwsEXXS7qTBi2mXEUtZG4qKbix+L1jspzTevhd5LWGxEAv85ivZ7qWQhUei WyOsKvz8JiRFtKGrD/OXRZXhT5fHPxjeJ1+49RdQaM5W0hVZBeyyQ1O2PpwgDBcv8LCmuk tZtwKY1gzZWnRWWoogwQaANIgQVzRp7KGVMUG4LGmLgTjb/RJAy7XpS0GX+5alDLrGqqw4 Aqq/lR+k4CPkwel6dkE0G54BIxePw/YD+jg0gClUw+mWilAcyi4SuL1Uq4SSIfzryj8Zjm zIsgBH18h658z2Cq598xFuSu9n5EVLEibMm76swdi72qjnldQJKkb191qY0o4A== From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J . Wysocki" , Wolfram Sang , Peter Rosin , Russell King , Andrew Lunn , Heiner Kallweit , "David S . Miller" , Jakub Kicinski Cc: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org, netdev@vger.kernel.org, Thomas Petazzoni , Alexandre Belloni , =?utf-8?b?Q2zDqW1lbnQg?= =?utf-8?b?TMOpZ2Vy?= Subject: [RFC 01/10] property: add fwnode_match_node() Date: Mon, 21 Feb 2022 17:26:43 +0100 Message-Id: <20220221162652.103834-2-clement.leger@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220221162652.103834-1-clement.leger@bootlin.com> References: <20220221162652.103834-1-clement.leger@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-State: RFC Add a function equivalent to of_match_node() which is usable for fwnode support. Matching is based on the compatible property and it returns the best matches for the node according to the compatible list ordering. Signed-off-by: Clément Léger --- drivers/base/property.c | 23 +++++++++++++++++++++++ include/linux/property.h | 3 +++ 2 files changed, 26 insertions(+) diff --git a/drivers/base/property.c b/drivers/base/property.c index e6497f6877ee..434c2713fd99 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -1158,6 +1158,29 @@ int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode, } EXPORT_SYMBOL(fwnode_graph_parse_endpoint); +const struct of_device_id *fwnode_match_node(const struct fwnode_handle *fwnode, + const struct of_device_id *matches) +{ + int index; + const struct of_device_id *best_match = NULL; + int best_index = INT_MAX; + + if (!matches) + return NULL; + + for (; matches->name[0] || matches->type[0] || matches->compatible[0]; matches++) { + index = fwnode_property_match_string(fwnode, "compatible", + matches->compatible); + if (index >= 0 && index < best_index) { + best_match = matches; + best_index = index; + } + } + + return best_match; +} +EXPORT_SYMBOL(fwnode_match_node); + const void *device_get_match_data(struct device *dev) { return fwnode_call_ptr_op(dev_fwnode(dev), device_get_match_data, dev); diff --git a/include/linux/property.h b/include/linux/property.h index 7399a0b45f98..978ecf6be34e 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -446,6 +446,9 @@ static inline void *device_connection_find_match(struct device *dev, return fwnode_connection_find_match(dev_fwnode(dev), con_id, data, match); } +const struct of_device_id *fwnode_match_node(const struct fwnode_handle *fwnode, + const struct of_device_id *matches); + /* -------------------------------------------------------------------------- */ /* Software fwnode support - when HW description is incomplete or missing */ From patchwork Mon Feb 21 16:26: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: 12753925 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 89549C433EF for ; Mon, 21 Feb 2022 16:38:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380833AbiBUQjQ (ORCPT ); Mon, 21 Feb 2022 11:39:16 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:49578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380781AbiBUQjJ (ORCPT ); Mon, 21 Feb 2022 11:39:09 -0500 Received: from mslow1.mail.gandi.net (mslow1.mail.gandi.net [217.70.178.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2960F22BD5; Mon, 21 Feb 2022 08:38:37 -0800 (PST) Received: from relay9-d.mail.gandi.net (unknown [IPv6:2001:4b98:dc4:8::229]) by mslow1.mail.gandi.net (Postfix) with ESMTP id 1847DD243E; Mon, 21 Feb 2022 16:29:15 +0000 (UTC) Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 971DFFF806; Mon, 21 Feb 2022 16:29:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1645460952; 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=/e2iZsxFY+H/44yYHExPJa6lTflMw/3gK08JNl6XbE4=; b=UC/wIbPYMT+4T+ynra4OxvY0MmvzqiCwd3KVJH2dNZOt70UaJPYg4rXhW5sS7ZS+igOLqo AAYoS2n2nrvsrKOkgtQ7rNYXNGTFZvGn2vhAmYOTvOJbcLrfAOHlpvF1r9K/dVjpoq7xOo kTg0aAkhBB9HC0WQJ7OzO6UX/1oyLcRm95lkS55mSvtYLm18InaFuJMXYXI5KiE4mJduF+ DyIM3U1dzmYffdx8lIq2O80rPpludWnkuSJwj+bD+OoX/NiaQMlGbBlUmunVhVHPiptUBt TMQw32HqV6hQPwGti7YjKkdHeghrtl+jDYv3bK719dSHBtv2PGVZRHcQiGuF+Q== From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J . Wysocki" , Wolfram Sang , Peter Rosin , Russell King , Andrew Lunn , Heiner Kallweit , "David S . Miller" , Jakub Kicinski Cc: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org, netdev@vger.kernel.org, Thomas Petazzoni , Alexandre Belloni , =?utf-8?b?Q2zDqW1lbnQg?= =?utf-8?b?TMOpZ2Vy?= Subject: [RFC 02/10] property: add fwnode_get_match_data() Date: Mon, 21 Feb 2022 17:26:44 +0100 Message-Id: <20220221162652.103834-3-clement.leger@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220221162652.103834-1-clement.leger@bootlin.com> References: <20220221162652.103834-1-clement.leger@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-State: RFC Add fwnode_get_match_data() which is meant to be used as device_get_match_data for fwnode_operations. Signed-off-by: Clément Léger --- drivers/base/property.c | 12 ++++++++++++ include/linux/property.h | 3 +++ 2 files changed, 15 insertions(+) diff --git a/drivers/base/property.c b/drivers/base/property.c index 434c2713fd99..6ffb3ac4509c 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -1181,6 +1181,18 @@ const struct of_device_id *fwnode_match_node(const struct fwnode_handle *fwnode, } EXPORT_SYMBOL(fwnode_match_node); +const void *fwnode_get_match_data(const struct fwnode_handle *fwnode, + const struct device *dev) +{ + const struct of_device_id *match; + + match = fwnode_match_node(fwnode, dev->driver->of_match_table); + if (!match) + return NULL; + + return match->data; +} + const void *device_get_match_data(struct device *dev) { return fwnode_call_ptr_op(dev_fwnode(dev), device_get_match_data, dev); diff --git a/include/linux/property.h b/include/linux/property.h index 978ecf6be34e..7f727c492602 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -449,6 +449,9 @@ static inline void *device_connection_find_match(struct device *dev, const struct of_device_id *fwnode_match_node(const struct fwnode_handle *fwnode, const struct of_device_id *matches); +const void *fwnode_get_match_data(const struct fwnode_handle *fwnode, + const struct device *dev); + /* -------------------------------------------------------------------------- */ /* Software fwnode support - when HW description is incomplete or missing */ From patchwork Mon Feb 21 16:26: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: 12753923 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 5AEBCC433F5 for ; Mon, 21 Feb 2022 16:38:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380773AbiBUQjL (ORCPT ); Mon, 21 Feb 2022 11:39:11 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:49582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380782AbiBUQjJ (ORCPT ); Mon, 21 Feb 2022 11:39:09 -0500 Received: from mslow1.mail.gandi.net (mslow1.mail.gandi.net [217.70.178.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BE3022BEA; Mon, 21 Feb 2022 08:38:37 -0800 (PST) Received: from relay9-d.mail.gandi.net (unknown [217.70.183.199]) by mslow1.mail.gandi.net (Postfix) with ESMTP id A7F0ED24FD; Mon, 21 Feb 2022 16:29:16 +0000 (UTC) Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 5F39CFF804; Mon, 21 Feb 2022 16:29:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1645460953; 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=MRgKG648hOdSkPSK+Ra17yf3vVrdkJOIS/gSbgZNuPk=; b=S49qdn1hnZBcRsguEbukf7/eO6ALAhSvMvmyv2kEwe6zRJO88M9Dj5DXQ93SCdfGt4W+Qs OeYHM0jZJvDRWKkP/Ix1yc/hQ80Sd24VszyimxQYcN81tYCXYHtvp1KyV+75stqGE3QvDi Hfa8r+SqoDWwHFHVvI9Lb77xBgDZSdudMdYVjfNqwN9fitFBRdICbyHH7+z+rYyNsxeB/3 r3/flFsSqEmQ1UTknn6jjSdYp+6ha1Ws3CraHqaxmYZXvRLjV9IQ3chkd/6c0PTQheAHYE XbVHbStw3GrlWR+wI8i3D42lXdzT2sIOFg7akx8vaOxGgDKXbqJUQ/ACG9rABw== From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J . Wysocki" , Wolfram Sang , Peter Rosin , Russell King , Andrew Lunn , Heiner Kallweit , "David S . Miller" , Jakub Kicinski Cc: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org, netdev@vger.kernel.org, Thomas Petazzoni , Alexandre Belloni , =?utf-8?b?Q2zDqW1lbnQg?= =?utf-8?b?TMOpZ2Vy?= Subject: [RFC 03/10] base: swnode: use fwnode_get_match_data() Date: Mon, 21 Feb 2022 17:26:45 +0100 Message-Id: <20220221162652.103834-4-clement.leger@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220221162652.103834-1-clement.leger@bootlin.com> References: <20220221162652.103834-1-clement.leger@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-State: RFC In order to allow matching devices with software node with device_get_match_data(), use fwnode_get_match_data() for .device_get_match_data operation. Signed-off-by: Clément Léger --- drivers/base/swnode.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index 0a482212c7e8..783ad18f49af 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -662,6 +662,7 @@ software_node_graph_parse_endpoint(const struct fwnode_handle *fwnode, static const struct fwnode_operations software_node_ops = { .get = software_node_get, .put = software_node_put, + .device_get_match_data = fwnode_get_match_data, .property_present = software_node_property_present, .property_read_int_array = software_node_read_int_array, .property_read_string_array = software_node_read_string_array, From patchwork Mon Feb 21 16:26: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: 12753927 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 73EABC433FE for ; Mon, 21 Feb 2022 16:38:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380853AbiBUQjT (ORCPT ); Mon, 21 Feb 2022 11:39:19 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:49582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380793AbiBUQjK (ORCPT ); Mon, 21 Feb 2022 11:39:10 -0500 Received: from mslow1.mail.gandi.net (mslow1.mail.gandi.net [217.70.178.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98894237FF; Mon, 21 Feb 2022 08:38:39 -0800 (PST) Received: from relay9-d.mail.gandi.net (unknown [217.70.183.199]) by mslow1.mail.gandi.net (Postfix) with ESMTP id 83F0BC3549; Mon, 21 Feb 2022 16:29:18 +0000 (UTC) Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id E0190FF80E; Mon, 21 Feb 2022 16:29:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1645460955; 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=yFZyD/xsoWg/S0R33oq47fx2Ang45t7YDLbGipkmDBU=; b=owA9gnqTS5qqrRnkgIHNLJMrzZ/Xpguf/yNrSyIkJdRdPNBZiwWwffvpJqwydxsTlrBXIG 4GqmqKnGSJecFBvzF1zKDEtl5eBZeRrHKTEJUOR4Ditxxp0JQfi1GDtwYNiEkpy8n58X5w DQAeRKgHbiUu6XRKL+62CPJpJDXbEVaTvyyznf//QxXDeBvr77b8Ly3Wu8WwL+OrB5K8z7 YQglolFnIAL2wIUaxw/h3d3o4CM5DFQ+w9In8tyTRvHH3tMD+K/iw+4XYG6EDJjIadrXkj 0LGjKCnJEuueFOzQdKreE9C5LYJ22XL67mO3FM4EdsizWoorp/DFpab6nAqfPw== From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J . Wysocki" , Wolfram Sang , Peter Rosin , Russell King , Andrew Lunn , Heiner Kallweit , "David S . Miller" , Jakub Kicinski Cc: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org, netdev@vger.kernel.org, Thomas Petazzoni , Alexandre Belloni , =?utf-8?b?Q2zDqW1lbnQg?= =?utf-8?b?TMOpZ2Vy?= Subject: [RFC 04/10] property: add a callback parameter to fwnode_property_match_string() Date: Mon, 21 Feb 2022 17:26:46 +0100 Message-Id: <20220221162652.103834-5-clement.leger@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220221162652.103834-1-clement.leger@bootlin.com> References: <20220221162652.103834-1-clement.leger@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-State: RFC This function will be modified to be reused for fwnode_property_read_string_index(). In order to avoid copy/paste of existing code, split the existing function and pass a callback that will be executed once the string array has been retrieved. In order to reuse this function with other actions. Signed-off-by: Clément Léger --- drivers/base/property.c | 50 +++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/drivers/base/property.c b/drivers/base/property.c index 6ffb3ac4509c..cd1c30999fd9 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -410,10 +410,11 @@ EXPORT_SYMBOL_GPL(fwnode_property_read_string); * fwnode_property_match_string - find a string in an array and return index * @fwnode: Firmware node to get the property of * @propname: Name of the property holding the array - * @string: String to look for + * @cb: callback to execute on the string array + * @data: data to be passed to the callback * - * Find a given string in a string array and if it is found return the - * index back. + * Execute a given callback on a string array values and returns the callback + * return value. * * Return: %0 if the property was found (success), * %-EINVAL if given arguments are not valid, @@ -421,8 +422,10 @@ EXPORT_SYMBOL_GPL(fwnode_property_read_string); * %-EPROTO if the property is not an array of strings, * %-ENXIO if no suitable firmware interface is present. */ -int fwnode_property_match_string(const struct fwnode_handle *fwnode, - const char *propname, const char *string) +static int fwnode_property_string_match(const struct fwnode_handle *fwnode, + const char *propname, + int (*cb)(const char **, int, void *), + void *data) { const char **values; int nval, ret; @@ -442,13 +445,46 @@ int fwnode_property_match_string(const struct fwnode_handle *fwnode, if (ret < 0) goto out; + ret = cb(values, nval, data); +out: + kfree(values); + return ret; +} + +static int match_string_callback(const char **values, int nval, void *data) +{ + int ret; + const char *string = data; + ret = match_string(values, nval, string); if (ret < 0) ret = -ENODATA; -out: - kfree(values); + return ret; } + +/** + * fwnode_property_match_string - find a string in an array and return index + * @fwnode: Firmware node to get the property of + * @propname: Name of the property holding the array + * @string: String to look for + * + * Find a given string in a string array and if it is found return the + * index back. + * + * 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_match_string(const struct fwnode_handle *fwnode, + const char *propname, const char *string) +{ + return fwnode_property_string_match(fwnode, propname, + match_string_callback, + (void *)string); +} EXPORT_SYMBOL_GPL(fwnode_property_match_string); /** From patchwork Mon Feb 21 16:26: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: 12753933 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 DC1A1C433FE for ; Mon, 21 Feb 2022 16:39:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380911AbiBUQj3 (ORCPT ); Mon, 21 Feb 2022 11:39:29 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:49576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380788AbiBUQjK (ORCPT ); Mon, 21 Feb 2022 11:39:10 -0500 Received: from mslow1.mail.gandi.net (mslow1.mail.gandi.net [217.70.178.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AE2022BE8; Mon, 21 Feb 2022 08:38:37 -0800 (PST) Received: from relay9-d.mail.gandi.net (unknown [217.70.183.199]) by mslow1.mail.gandi.net (Postfix) with ESMTP id F103FC2458; Mon, 21 Feb 2022 16:29:16 +0000 (UTC) Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 8A417FF815; Mon, 21 Feb 2022 16:29:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1645460956; 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=w8VXJLW2FAIIFmTtYZLQHDFFw7si1/w4sSkhBjrOQnI=; b=pEzyFYzNzHAqzU266UJ1CEeViLXPnqIXs7PsoQwbDM3DfG20pTF/W/4ida1KoDfZEkd7/U ZhQBjh8pOzwuy+oIGXzUT632IAZLLf1uy13+beH/oW53pSzIjYq3xayNS0I7aJpabVcqWu YBaJxLKsChgwMMlYpwbyYephOlCn51B00BSX7E7t8JIcUTEEKGiV7V4l6ReAiruQ7mqdvb EOL/id9lbhV31J57324G09Bug277sdAPHBYX9Wrq4WrPB1lN7kZH4ZCcnMYcwOMsrherii tx6iGY0V8d+sJ2t6EajUmurjr2T7ieZ4EWja7cqe06jSUz1XL+Ak049/gIAQSw== From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J . Wysocki" , Wolfram Sang , Peter Rosin , Russell King , Andrew Lunn , Heiner Kallweit , "David S . Miller" , Jakub Kicinski Cc: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org, netdev@vger.kernel.org, Thomas Petazzoni , Alexandre Belloni , =?utf-8?b?Q2zDqW1lbnQg?= =?utf-8?b?TMOpZ2Vy?= Subject: [RFC 05/10] property: add fwnode_property_read_string_index() Date: Mon, 21 Feb 2022 17:26:47 +0100 Message-Id: <20220221162652.103834-6-clement.leger@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220221162652.103834-1-clement.leger@bootlin.com> References: <20220221162652.103834-1-clement.leger@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-State: RFC 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. Signed-off-by: Clément Léger --- drivers/base/property.c | 48 ++++++++++++++++++++++++++++++++++++++++ include/linux/property.h | 3 +++ 2 files changed, 51 insertions(+) diff --git a/drivers/base/property.c b/drivers/base/property.c index cd1c30999fd9..00d9f171329c 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -487,6 +487,54 @@ int fwnode_property_match_string(const struct fwnode_handle *fwnode, } EXPORT_SYMBOL_GPL(fwnode_property_match_string); +struct read_index_data { + const char **string; + int index; +}; + +static int read_string_index(const char **values, int nval, void *data) +{ + struct read_index_data *cb_data = data; + + if (cb_data->index >= nval) + return -EINVAL; + + *cb_data->string = values[cb_data->index]; + + return 0; +} + +/** + * fwnode_property_read_string_index - read a string in an array using an index + * and return a pointer to the string + * @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) +{ + struct read_index_data cb_data; + + cb_data.index = index; + cb_data.string = string; + + return fwnode_property_string_match(fwnode, propname, read_string_index, + &cb_data); +} +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/property.h b/include/linux/property.h index 7f727c492602..f6ede3840c40 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 Mon Feb 21 16:26: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: 12753931 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 ACB0EC4332F for ; Mon, 21 Feb 2022 16:39:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380794AbiBUQj0 (ORCPT ); Mon, 21 Feb 2022 11:39:26 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:49596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380795AbiBUQjK (ORCPT ); Mon, 21 Feb 2022 11:39:10 -0500 Received: from mslow1.mail.gandi.net (mslow1.mail.gandi.net [217.70.178.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98B3423BC2; Mon, 21 Feb 2022 08:38:39 -0800 (PST) Received: from relay9-d.mail.gandi.net (unknown [217.70.183.199]) by mslow1.mail.gandi.net (Postfix) with ESMTP id 1D871D002D; Mon, 21 Feb 2022 16:29:49 +0000 (UTC) Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 0BF17FF80C; Mon, 21 Feb 2022 16:29:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1645460958; 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=6T8JMiVJYEhPc3/+R+YuyfEtX8+1W5M79oF4paVWi50=; b=LePMPR//Yb5TFldYIp1/MIM8cL0eDjZN0xbTUQr4DMj5rkhF1CLPLanLJuKweBXYtQO576 nFABFf+h9o1wpTj5jU0wHBgQaG1NXMyw0WwFQAKCGpkUYsbVwKAXvWuy9iEV4XtIwMBQrx 80V6DvULDcjxpCSnfG2MZNLZOfm4L7PREU/aB/m/7pF6yKlYOJRm5kBAZFsjQ9fDDdcJVu 844hUuv445bYUylE+Hiu63CO0apgH7QZ0YbeZQsSZiwC2FY/n0OQLhMhhxg4K1xYriXXS9 gIJmfcnc+x2c8Udc3kQf8F6A+8A49IK9by2KSmPrMgFzZiAdj5K6tElQO2TybQ== From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J . Wysocki" , Wolfram Sang , Peter Rosin , Russell King , Andrew Lunn , Heiner Kallweit , "David S . Miller" , Jakub Kicinski Cc: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org, netdev@vger.kernel.org, Thomas Petazzoni , Alexandre Belloni , =?utf-8?b?Q2zDqW1lbnQg?= =?utf-8?b?TMOpZ2Vy?= Subject: [RFC 06/10] i2c: fwnode: add fwnode_find_i2c_adapter_by_node() Date: Mon, 21 Feb 2022 17:26:48 +0100 Message-Id: <20220221162652.103834-7-clement.leger@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220221162652.103834-1-clement.leger@bootlin.com> References: <20220221162652.103834-1-clement.leger@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-State: RFC 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. Signed-off-by: Clément Léger --- drivers/i2c/Makefile | 1 + drivers/i2c/i2c-core-fwnode.c | 40 +++++++++++++++++++++++++++++++++++ include/linux/i2c.h | 2 ++ 3 files changed, 43 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..d116aca3e2ec --- /dev/null +++ b/drivers/i2c/i2c-core-fwnode.c @@ -0,0 +1,40 @@ +// 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 (dev_fwnode(dev) == data) + return 1; + + if (dev->parent) + return dev_fwnode(dev->parent) == data; + + return 0; +} + +struct i2c_adapter *fwnode_find_i2c_adapter_by_node(struct fwnode_handle *node) +{ + struct device *dev; + struct i2c_adapter *adapter; + + dev = bus_find_device(&i2c_bus_type, NULL, node, + 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..9b480a8b0a76 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -967,6 +967,8 @@ 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 *node); + #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 Mon Feb 21 16:26:49 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: 12753928 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 C7275C433EF for ; Mon, 21 Feb 2022 16:39:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380867AbiBUQjV (ORCPT ); Mon, 21 Feb 2022 11:39:21 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:49600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380799AbiBUQjK (ORCPT ); Mon, 21 Feb 2022 11:39:10 -0500 Received: from mslow1.mail.gandi.net (mslow1.mail.gandi.net [217.70.178.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0080C23BFD; Mon, 21 Feb 2022 08:38:39 -0800 (PST) Received: from relay9-d.mail.gandi.net (unknown [IPv6:2001:4b98:dc4:8::229]) by mslow1.mail.gandi.net (Postfix) with ESMTP id 66D90D256D; Mon, 21 Feb 2022 16:30:00 +0000 (UTC) Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 8CE4EFF812; Mon, 21 Feb 2022 16:29:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1645460960; 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=URJAXhlDauk/l4yfi8v6pFwWxIgQSIBOv7Iyc/z2WsI=; b=iLM0m5Zhw8xCMe5DS5xURtrpDXGzRBjyN+Hhy7M5/KVA/Mx7uv6KQuU6hNdVlevMepJ1YQ jv834IIM0c45I/AYxhIT0e5Ow8+4B0Gn0evf0wQ8bIyCCVrJMvykTkePjo97Qx7bgcX7Cp qHobEt4AwL6j4eiyDYAOUnBIzZ+bTr/ba6rTAzde/58k14ewYeafcNrgEsNQ4l3kEdlwGX tSkUhWqE3cubuZgVXJxWAyU11EUM63qOfWXu+7nYOlyAVJW9IsrkC4k52uoVgZ7+wFe7+F G6Qwjq6uOfA4ZvVStOOjBmK8VHYM+36VT9X11UpwcxepSVTiAJb8Dr9Qr/LRWg== From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J . Wysocki" , Wolfram Sang , Peter Rosin , Russell King , Andrew Lunn , Heiner Kallweit , "David S . Miller" , Jakub Kicinski Cc: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org, netdev@vger.kernel.org, Thomas Petazzoni , Alexandre Belloni , =?utf-8?b?Q2zDqW1lbnQg?= =?utf-8?b?TMOpZ2Vy?= Subject: [RFC 07/10] i2c: of: use fwnode_get_i2c_adapter_by_node() Date: Mon, 21 Feb 2022 17:26:49 +0100 Message-Id: <20220221162652.103834-8-clement.leger@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220221162652.103834-1-clement.leger@bootlin.com> References: <20220221162652.103834-1-clement.leger@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-State: RFC Since the new fwnode function does the same check that was done by of_get_i2c_adapter_by_node(), call this one 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 9b480a8b0a76..d1f384b805ad 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -974,7 +974,10 @@ struct i2c_adapter *fwnode_find_i2c_adapter_by_node(struct fwnode_handle *node); 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 Mon Feb 21 16:26:50 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: 12753930 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 14D31C433EF for ; Mon, 21 Feb 2022 16:39:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380901AbiBUQjZ (ORCPT ); Mon, 21 Feb 2022 11:39:25 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:49598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380797AbiBUQjK (ORCPT ); Mon, 21 Feb 2022 11:39:10 -0500 Received: from mslow1.mail.gandi.net (mslow1.mail.gandi.net [217.70.178.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16DF824082; Mon, 21 Feb 2022 08:38:39 -0800 (PST) Received: from relay9-d.mail.gandi.net (unknown [IPv6:2001:4b98:dc4:8::229]) by mslow1.mail.gandi.net (Postfix) with ESMTP id 25C8DD25C2; Mon, 21 Feb 2022 16:30:02 +0000 (UTC) Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 600E4FF80F; Mon, 21 Feb 2022 16:29:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1645460962; 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=dKFshFvhHLkkwMZS+Ktyvof/6+xmfHa5cEKRMGqTKV8=; b=eo4eaxqAU8v0VIW/jjOBhVvEcHrKZ4idhn6P7RhSsGFMr38v63aves1B551iO7vtTs+fSs BLYtyBS9PxAT6A2yCNOBysVtuvzUwn4p/r+GMbm9M1HHKK+ZPwkJYcIOxm/KdtAS/EeCm8 m8j79DzdbNI+Oil8hQQyOIo1vw7zXA9mQl0DiG2kgGYXbnpoMH5QdyHHlv7gFUxNken6G4 uo874QeMNWym4QuDp0bQkE/4NQGnbLI8/lzIc3yZyV3eQ/UBK0FvCyKdUINHMrCdMzuszF nuPUuBztuerge9fNS3FsAVN9TP0J6Gh+3ugdeUdWgNgQW7dlLVo3TNctxd1hLQ== From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J . Wysocki" , Wolfram Sang , Peter Rosin , Russell King , Andrew Lunn , Heiner Kallweit , "David S . Miller" , Jakub Kicinski Cc: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org, netdev@vger.kernel.org, Thomas Petazzoni , Alexandre Belloni , =?utf-8?b?Q2zDqW1lbnQg?= =?utf-8?b?TMOpZ2Vy?= Subject: [RFC 08/10] i2c: mux: pinctrl: remove CONFIG_OF dependency and use fwnode API Date: Mon, 21 Feb 2022 17:26:50 +0100 Message-Id: <20220221162652.103834-9-clement.leger@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220221162652.103834-1-clement.leger@bootlin.com> References: <20220221162652.103834-1-clement.leger@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-State: RFC In order to use i2c muxes with software_node when added with a struct mfd_cell, switch to fwnode API. The fwnode layer will allow to use this with both device_node and software_node. Signed-off-by: Clément Léger --- drivers/i2c/muxes/Kconfig | 1 - drivers/i2c/muxes/i2c-mux-pinctrl.c | 21 +++++++++++---------- 2 files changed, 11 insertions(+), 11 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..200890d7a625 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_np; struct i2c_adapter *parent; - parent_np = of_parse_phandle(np, "i2c-parent", 0); + parent_np = fwnode_find_reference(fwnode, "i2c-parent", 0); if (!parent_np) { 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_np); + 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 *np = 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(np, "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(np, "pinctrl-names", i, + &name); if (ret < 0) { dev_err(dev, "Cannot parse pinctrl-names: %d\n", ret); goto err_put_parent; From patchwork Mon Feb 21 16:26:51 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: 12753932 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 521D7C433EF for ; Mon, 21 Feb 2022 16:39:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380903AbiBUQj2 (ORCPT ); Mon, 21 Feb 2022 11:39:28 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:49602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380803AbiBUQjK (ORCPT ); Mon, 21 Feb 2022 11:39:10 -0500 Received: from mslow1.mail.gandi.net (mslow1.mail.gandi.net [217.70.178.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 262612408B; Mon, 21 Feb 2022 08:38:40 -0800 (PST) Received: from relay9-d.mail.gandi.net (unknown [IPv6:2001:4b98:dc4:8::229]) by mslow1.mail.gandi.net (Postfix) with ESMTP id BE46CD264A; Mon, 21 Feb 2022 16:30:03 +0000 (UTC) Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 1B18BFF811; Mon, 21 Feb 2022 16:29:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1645460963; 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=ocoul7ljnoZTu5D9WXKfAGT93AKe2N6I6+O6VziLVXM=; b=GAlclXPXVSGlWfer2ykk3URw3VhDeJ7r2IeffYChhxQoPQAxRI919CYsW5yen8aODmGYyD qinWr8T9DMf9HwBxvnRZbt7hJ+KpQDVOsF+n5+K8uqwkqE4bfID/RkZcl0G+7fbW5boyLe crags0YEaxVRYwGPqYtBdQ8C2wfDXKvFGmWuK+Ot3JJ2F/K2p3Hh4JspEf49/0Ok8ycNbE 1yVCnRhXAtfz5EhN4VxmEC8kg2y54D0Cy3B9KrY/DXOCSUlyUIADiuZbTo2alSlJJ5gDUI jmUHVP8K0CFx1zdYdp1vnTwHctW0NwN2NZqecly3POy6MAbISz1bTYBy1qscLg== From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J . Wysocki" , Wolfram Sang , Peter Rosin , Russell King , Andrew Lunn , Heiner Kallweit , "David S . Miller" , Jakub Kicinski Cc: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org, netdev@vger.kernel.org, Thomas Petazzoni , Alexandre Belloni , =?utf-8?b?Q2zDqW1lbnQg?= =?utf-8?b?TMOpZ2Vy?= Subject: [RFC 09/10] i2c: mux: add support for fwnode Date: Mon, 21 Feb 2022 17:26:51 +0100 Message-Id: <20220221162652.103834-10-clement.leger@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220221162652.103834-1-clement.leger@bootlin.com> References: <20220221162652.103834-1-clement.leger@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-State: RFC Modify i2c_mux_add_adapter() to use with fwnode API to allow creating mux adapters with fwnode based devices. This allows to have a node independent 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..93c916220da5 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 *np = 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(np); kfree(priv); } } From patchwork Mon Feb 21 16:26:52 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: 12753929 X-Patchwork-Delegate: kuba@kernel.org 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 539EDC433F5 for ; Mon, 21 Feb 2022 16:39:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380885AbiBUQjX (ORCPT ); Mon, 21 Feb 2022 11:39:23 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:49580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380805AbiBUQjL (ORCPT ); Mon, 21 Feb 2022 11:39:11 -0500 Received: from mslow1.mail.gandi.net (mslow1.mail.gandi.net [217.70.178.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A5492408D; Mon, 21 Feb 2022 08:38:40 -0800 (PST) Received: from relay9-d.mail.gandi.net (unknown [IPv6:2001:4b98:dc4:8::229]) by mslow1.mail.gandi.net (Postfix) with ESMTP id 62B7AD26C6; Mon, 21 Feb 2022 16:30:05 +0000 (UTC) Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id B2FF4FF813; Mon, 21 Feb 2022 16:29:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1645460965; 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=IwJT7O+ycIIE2B/+I0PXXUOt4c+jLoAf67OAg4gFgvc=; b=Qwo8YWwLdfMsmfiY94ufBkAM9expN513dX5+VcMfJhaEjDPz+QL9DhWi7HCxyANoNo9jG5 hfyRmusIiVsECh+6ve4bNOHBeq2T1FvaCx2xjaUJGSajuNXSa2XwCnyBDcAzxnCYfSlZXN 56BGKVKQCkkfVh/LcJQyH51f0UXsl3K4juxlDsbotEDEn+DlP/tXwwrUQ/hObDQxyx9Bht qyV5m92oGiKLiJyY/FZFO7G5PRflHWEMe6+Cs5aK61Rtuj9cefSnIlkza1rb5xgt0kpQqh iLXH73CPxNLS9rVBejg0uYUDYO+utSOHCPl8t6Za764WxXqH/M7tebae7L2kXw== From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J . Wysocki" , Wolfram Sang , Peter Rosin , Russell King , Andrew Lunn , Heiner Kallweit , "David S . Miller" , Jakub Kicinski Cc: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org, netdev@vger.kernel.org, Thomas Petazzoni , Alexandre Belloni , =?utf-8?b?Q2zDqW1lbnQg?= =?utf-8?b?TMOpZ2Vy?= Subject: [RFC 10/10] net: sfp: add support for fwnode Date: Mon, 21 Feb 2022 17:26:52 +0100 Message-Id: <20220221162652.103834-11-clement.leger@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220221162652.103834-1-clement.leger@bootlin.com> References: <20220221162652.103834-1-clement.leger@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add support to retrieve a i2c bus in sfp with a fwnode. This support is using the fwnode API which also works with device-tree and ACPI. For this purpose, the device-tree and ACPI code handling the i2c adapter retrieval was factorized with the new code. This also allows i2c devices using a software_node description to be used by sfp code. Signed-off-by: Clément Léger Reviewed-by: Russell King (Oracle) --- drivers/net/phy/sfp.c | 44 +++++++++++++------------------------------ 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c index 4720b24ca51b..9d9e3d209408 100644 --- a/drivers/net/phy/sfp.c +++ b/drivers/net/phy/sfp.c @@ -2499,43 +2499,25 @@ static int sfp_probe(struct platform_device *pdev) return err; sff = sfp->type = &sfp_data; + if (dev_fwnode(&pdev->dev)) { + struct fwnode_handle *fwnode = dev_fwnode(&pdev->dev); + struct fwnode_handle *np; - if (pdev->dev.of_node) { - struct device_node *node = pdev->dev.of_node; - const struct of_device_id *id; - struct device_node *np; + if (!is_acpi_device_node(fwnode)) { + sff = device_get_match_data(&pdev->dev); + if (WARN_ON(!sff)) + return -EINVAL; - id = of_match_node(sfp_of_match, node); - if (WARN_ON(!id)) - return -EINVAL; - - sff = sfp->type = id->data; - - np = of_parse_phandle(node, "i2c-bus", 0); - if (!np) { - dev_err(sfp->dev, "missing 'i2c-bus' property\n"); - return -ENODEV; + sfp->type = sff; } - i2c = of_find_i2c_adapter_by_node(np); - of_node_put(np); - } else if (has_acpi_companion(&pdev->dev)) { - struct acpi_device *adev = ACPI_COMPANION(&pdev->dev); - struct fwnode_handle *fw = acpi_fwnode_handle(adev); - struct fwnode_reference_args args; - struct acpi_handle *acpi_handle; - int ret; - - ret = acpi_node_get_property_reference(fw, "i2c-bus", 0, &args); - if (ret || !is_acpi_device_node(args.fwnode)) { - dev_err(&pdev->dev, "missing 'i2c-bus' property\n"); + np = fwnode_find_reference(fwnode, "i2c-bus", 0); + if (!np) { + dev_err(&pdev->dev, "Cannot parse i2c-bus\n"); return -ENODEV; } - - acpi_handle = ACPI_HANDLE_FWNODE(args.fwnode); - i2c = i2c_acpi_find_adapter_by_handle(acpi_handle); - } else { - return -EINVAL; + i2c = fwnode_find_i2c_adapter_by_node(np); + fwnode_handle_put(np); } if (!i2c)