From nobody Mon Sep 15 01:56:02 2025 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 AC3BCC46467 for ; Mon, 16 Jan 2023 17:53:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235147AbjAPRxD (ORCPT ); Mon, 16 Jan 2023 12:53:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233847AbjAPRwW (ORCPT ); Mon, 16 Jan 2023 12:52:22 -0500 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 030643B3CC for ; Mon, 16 Jan 2023 09:35:00 -0800 (PST) Received: by mail-lj1-x22b.google.com with SMTP id e16so3818068ljn.3 for ; Mon, 16 Jan 2023 09:34:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zEb4lOT+O4pg8nXGe0kZqRkEJZCgvHhijruZskMfGvU=; b=dlmINt9wdDatqcnTccEZ9/hR53OWh+oxXX5cJLeZo1u/d6bJ+UNoZEHgBgmogD2WM8 66VKndzb2dX6JsroREQjsRE6SPWlTACzrUSE+jcDUdhYDF/I2iVrfIaGK+Vj65P5SvZC NfRT/Vw19FSIPXHj2IjulhCaQSQQJaNNeKAHP4+2ZofTPVjLVBfgGFq4y8kPKP9f+drF 9ET7i3oehoHRk5d707PX3l0B2ep3UDVoadZ7RSozuqBhGa0nHrt8S2kfJoVAEwKMqmGA 3SNq4hJ29rhHfeFmVkjtB4tY6wL4nWrAY+HegdmzdOmMQ7VMIlglnpmoQMjyXn3SXpgx Vihw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zEb4lOT+O4pg8nXGe0kZqRkEJZCgvHhijruZskMfGvU=; b=bMvPT0OQnmT4hBXWDBUaciJYoY7wlEHEgCcvkKjKjlZa4Y4nt3FoI8uxzXZ4yYL5qZ HI3u46hQBD4CMLr64OsriQabBCypU28L8ll5OKC1lgP7rZgDeQNaUrauJ2Uc7t8KW5FN jjPpcKagjtpYRLhZ53395gSRLl9A+f54nJwSeHDY/7b5Yy+AF+aIKoLLnlI/c9FLWnS+ 4mxUogF9etGEvsVTJxfJt6SqE8bQrhN+zh3G2LMmM6xgS8bdMNP6LVbhwts6+/7PSkUx nzJA1xSW3gXs3Uyx2JQzM4AlmupeDF6AmZAomRdM1FCWVMmxlLjSGJMZz/Rlcxu9rcIj LRTQ== X-Gm-Message-State: AFqh2kohUxj+odZmMceaFYyhIBkMSCQ2NGzOT6tcNyrG0L88kYEPbLsI MYhTJuB4hov/ioGiJOUExWNju5shYB1gGfcP X-Google-Smtp-Source: AMrXdXsEOa+Vzqq3OenNeL3qmLI1gI2AEgLe399qXt7MFvh/gXSieRTo+VZPpvXMF3DKfZvSP+/hSQ== X-Received: by 2002:a2e:868e:0:b0:280:2c4e:3d3e with SMTP id l14-20020a2e868e000000b002802c4e3d3emr3321703lji.41.1673890498322; Mon, 16 Jan 2023 09:34:58 -0800 (PST) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id k20-20020a2e8894000000b0028b7f51414fsm707333lji.80.2023.01.16.09.34.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Jan 2023 09:34:57 -0800 (PST) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, netdev@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@linux.intel.com, sean.wang@mediatek.com, Landen.Chao@mediatek.com, linus.walleij@linaro.org, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux@armlinux.org.uk, hkallweit1@gmail.com, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com, Samer.El-Haj-Mahmoud@arm.com Subject: [net-next: PATCH v4 1/8] net: phy: fixed_phy: switch to fwnode_ API Date: Mon, 16 Jan 2023 18:34:13 +0100 Message-Id: <20230116173420.1278704-2-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20230116173420.1278704-1-mw@semihalf.com> References: <20230116173420.1278704-1-mw@semihalf.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Allow to use fixed_phy driver and its helper functions without Device Tree dependency, by swtiching from of_ to fwnode_ API. Signed-off-by: Marcin Wojtas Reviewed-by: Florian Fainelli --- include/linux/phy_fixed.h | 6 +-- drivers/net/mdio/of_mdio.c | 2 +- drivers/net/phy/fixed_phy.c | 39 +++++++------------- 3 files changed, 18 insertions(+), 29 deletions(-) diff --git a/include/linux/phy_fixed.h b/include/linux/phy_fixed.h index 1acafd86ab13..b3edf0c7c687 100644 --- a/include/linux/phy_fixed.h +++ b/include/linux/phy_fixed.h @@ -12,7 +12,7 @@ struct fixed_phy_status { int asym_pause; }; =20 -struct device_node; +struct fwnode_handle; struct gpio_desc; struct net_device; =20 @@ -22,7 +22,7 @@ extern int fixed_phy_add(unsigned int irq, int phy_id, struct fixed_phy_status *status); extern struct phy_device *fixed_phy_register(unsigned int irq, struct fixed_phy_status *status, - struct device_node *np); + struct fwnode_handle *fwnode); =20 extern struct phy_device * fixed_phy_register_with_gpiod(unsigned int irq, @@ -41,7 +41,7 @@ static inline int fixed_phy_add(unsigned int irq, int phy= _id, } static inline struct phy_device *fixed_phy_register(unsigned int irq, struct fixed_phy_status *status, - struct device_node *np) + struct fwnode_handle *fwnode) { return ERR_PTR(-ENODEV); } diff --git a/drivers/net/mdio/of_mdio.c b/drivers/net/mdio/of_mdio.c index 510822d6d0d9..ba22b7110cdc 100644 --- a/drivers/net/mdio/of_mdio.c +++ b/drivers/net/mdio/of_mdio.c @@ -423,7 +423,7 @@ int of_phy_register_fixed_link(struct device_node *np) return -ENODEV; =20 register_phy: - return PTR_ERR_OR_ZERO(fixed_phy_register(PHY_POLL, &status, np)); + return PTR_ERR_OR_ZERO(fixed_phy_register(PHY_POLL, &status, of_fwnode_ha= ndle(np))); } EXPORT_SYMBOL(of_phy_register_fixed_link); =20 diff --git a/drivers/net/phy/fixed_phy.c b/drivers/net/phy/fixed_phy.c index aef739c20ac4..e59d186f78e6 100644 --- a/drivers/net/phy/fixed_phy.c +++ b/drivers/net/phy/fixed_phy.c @@ -15,9 +15,9 @@ #include #include #include +#include #include #include -#include #include #include #include @@ -186,16 +186,12 @@ static void fixed_phy_del(int phy_addr) } } =20 -#ifdef CONFIG_OF_GPIO -static struct gpio_desc *fixed_phy_get_gpiod(struct device_node *np) +static struct gpio_desc *fixed_phy_get_gpiod(struct fwnode_handle *fwnode) { - struct device_node *fixed_link_node; + struct fwnode_handle *fixed_link_node; struct gpio_desc *gpiod; =20 - if (!np) - return NULL; - - fixed_link_node =3D of_get_child_by_name(np, "fixed-link"); + fixed_link_node =3D fwnode_get_named_child_node(fwnode, "fixed-link"); if (!fixed_link_node) return NULL; =20 @@ -204,28 +200,21 @@ static struct gpio_desc *fixed_phy_get_gpiod(struct d= evice_node *np) * Linux device associated with it, we simply have obtain * the GPIO descriptor from the device tree like this. */ - gpiod =3D fwnode_gpiod_get_index(of_fwnode_handle(fixed_link_node), - "link", 0, GPIOD_IN, "mdio"); + gpiod =3D fwnode_gpiod_get_index(fixed_link_node, "link", 0, GPIOD_IN, "m= dio"); if (IS_ERR(gpiod) && PTR_ERR(gpiod) !=3D -EPROBE_DEFER) { if (PTR_ERR(gpiod) !=3D -ENOENT) pr_err("error getting GPIO for fixed link %pOF, proceed without\n", fixed_link_node); gpiod =3D NULL; } - of_node_put(fixed_link_node); + fwnode_handle_put(fixed_link_node); =20 return gpiod; } -#else -static struct gpio_desc *fixed_phy_get_gpiod(struct device_node *np) -{ - return NULL; -} -#endif =20 static struct phy_device *__fixed_phy_register(unsigned int irq, struct fixed_phy_status *status, - struct device_node *np, + struct fwnode_handle *fwnode, struct gpio_desc *gpiod) { struct fixed_mdio_bus *fmb =3D &platform_fmb; @@ -238,7 +227,7 @@ static struct phy_device *__fixed_phy_register(unsigned= int irq, =20 /* Check if we have a GPIO associated with this fixed phy */ if (!gpiod) { - gpiod =3D fixed_phy_get_gpiod(np); + gpiod =3D fixed_phy_get_gpiod(fwnode); if (IS_ERR(gpiod)) return ERR_CAST(gpiod); } @@ -269,8 +258,8 @@ static struct phy_device *__fixed_phy_register(unsigned= int irq, phy->asym_pause =3D status->asym_pause; } =20 - of_node_get(np); - phy->mdio.dev.of_node =3D np; + fwnode_handle_get(fwnode); + device_set_node(&phy->mdio.dev, fwnode); phy->is_pseudo_fixed_link =3D true; =20 switch (status->speed) { @@ -299,7 +288,7 @@ static struct phy_device *__fixed_phy_register(unsigned= int irq, ret =3D phy_device_register(phy); if (ret) { phy_device_free(phy); - of_node_put(np); + fwnode_handle_put(fwnode); fixed_phy_del(phy_addr); return ERR_PTR(ret); } @@ -309,9 +298,9 @@ static struct phy_device *__fixed_phy_register(unsigned= int irq, =20 struct phy_device *fixed_phy_register(unsigned int irq, struct fixed_phy_status *status, - struct device_node *np) + struct fwnode_handle *fwnode) { - return __fixed_phy_register(irq, status, np, NULL); + return __fixed_phy_register(irq, status, fwnode, NULL); } EXPORT_SYMBOL_GPL(fixed_phy_register); =20 @@ -327,7 +316,7 @@ EXPORT_SYMBOL_GPL(fixed_phy_register_with_gpiod); void fixed_phy_unregister(struct phy_device *phy) { phy_device_remove(phy); - of_node_put(phy->mdio.dev.of_node); + fwnode_handle_put(dev_fwnode(&phy->mdio.dev)); fixed_phy_del(phy->mdio.addr); } EXPORT_SYMBOL_GPL(fixed_phy_unregister); --=20 2.29.0 From nobody Mon Sep 15 01:56:02 2025 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 85A53C46467 for ; Mon, 16 Jan 2023 17:53:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235154AbjAPRxP (ORCPT ); Mon, 16 Jan 2023 12:53:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233175AbjAPRwa (ORCPT ); Mon, 16 Jan 2023 12:52:30 -0500 Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 930ED30E9E for ; Mon, 16 Jan 2023 09:35:01 -0800 (PST) Received: by mail-lj1-x22d.google.com with SMTP id o7so30347147ljj.8 for ; Mon, 16 Jan 2023 09:35:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=p7zRzIvSvAnePdgerXrTk1rkO3KZL7nxc+XvMTxQPhY=; b=Xw/fj4+FQpuzGP7EaLIXAVXbJxMPn0Ykf3JEyIVvh0e4CzvpJ+Ly0jSQ3R8nTXqfzg VJGosRKpmExhQ9GpsUvmDtQWbOHyRkh5QTYCstCk04Rt4pkYX0ma0fOiQcPnskzbcRJL /gXJNwOBsx1qqirgcQ1+ghYY1A9aNvklPV3uqw8rsqrbN5J6fqLdwuBgwkGtHVjG5xXh UjpZbwI3W8mHWLpQaDCUMqXYCweFwB+cv2KJAV2xSc9lzC27lMd7ha/3jy/6nDiXGfRs wl4xkixjqViuR8690NymFAvdA+n3U759J6sArzAcVTCri00qP0eYxpdBX5C3t9kbNfXx N8WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=p7zRzIvSvAnePdgerXrTk1rkO3KZL7nxc+XvMTxQPhY=; b=CBIdFiWn2iJtBf2cMZi/QAugGsaEPywJr1VsYGcXrBEKBICGcGV+hbac1Cve/wrtbQ yIwUTVwq8MdufnY78aYTRAnqZM5ffhwaLBYDIK/KiLMQcvCrTaHOZ54C4102TzP23Wcr mfIHNfwldlqa4kF9v3EFZPbybtW0kw1vVyZITLjrKRBhigjyUx1yZ9ATpDadCv72J+gy QYZIMkRNnWgsUhyYaAZbak9fGPNXwoceweqCxyNvDeorn5dWJLB35gPaLMLtZ+chXQW0 jwmSsJeK8zF+oOgjTUW5vtZzf+Qq+JqRmEIjcFIJxVt5D49vmBiqwMQPEKK3baGfgOMe KNNw== X-Gm-Message-State: AFqh2kpDTJvIXL9MikACN1oGKXEsTIJH532S1TJM3BBU1fN1LgHjc2Tf drGqOF+cZlTy4Xv435GxzAMvRFa00hR0YUmq X-Google-Smtp-Source: AMrXdXvNYSPJXM5gb+VT2fXLJrPCPxJy38bDlYjViAKETboBghKQPve9JtUslr/FnDDbMt26+/vwHg== X-Received: by 2002:a2e:838b:0:b0:285:478a:7f2c with SMTP id x11-20020a2e838b000000b00285478a7f2cmr164267ljg.38.1673890499896; Mon, 16 Jan 2023 09:34:59 -0800 (PST) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id k20-20020a2e8894000000b0028b7f51414fsm707333lji.80.2023.01.16.09.34.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Jan 2023 09:34:59 -0800 (PST) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, netdev@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@linux.intel.com, sean.wang@mediatek.com, Landen.Chao@mediatek.com, linus.walleij@linaro.org, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux@armlinux.org.uk, hkallweit1@gmail.com, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com, Samer.El-Haj-Mahmoud@arm.com Subject: [net-next: PATCH v4 2/8] net: mdio: switch fixed-link PHYs API to fwnode_ Date: Mon, 16 Jan 2023 18:34:14 +0100 Message-Id: <20230116173420.1278704-3-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20230116173420.1278704-1-mw@semihalf.com> References: <20230116173420.1278704-1-mw@semihalf.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" fixed-link PHYs API is used by DSA and a number of drivers and was depending on of_. Switch to fwnode_ so to make it hardware description agnostic and allow to be used in ACPI world as well. Signed-off-by: Marcin Wojtas --- include/linux/fwnode_mdio.h | 19 ++++ drivers/net/mdio/fwnode_mdio.c | 96 ++++++++++++++++++++ drivers/net/mdio/of_mdio.c | 79 +--------------- 3 files changed, 118 insertions(+), 76 deletions(-) diff --git a/include/linux/fwnode_mdio.h b/include/linux/fwnode_mdio.h index faf603c48c86..98755b8c6c8a 100644 --- a/include/linux/fwnode_mdio.h +++ b/include/linux/fwnode_mdio.h @@ -16,6 +16,11 @@ int fwnode_mdiobus_phy_device_register(struct mii_bus *m= dio, int fwnode_mdiobus_register_phy(struct mii_bus *bus, struct fwnode_handle *child, u32 addr); =20 +int fwnode_phy_register_fixed_link(struct fwnode_handle *fwnode); + +void fwnode_phy_deregister_fixed_link(struct fwnode_handle *fwnode); + +bool fwnode_phy_is_fixed_link(struct fwnode_handle *fwnode); #else /* CONFIG_FWNODE_MDIO */ int fwnode_mdiobus_phy_device_register(struct mii_bus *mdio, struct phy_device *phy, @@ -30,6 +35,20 @@ static inline int fwnode_mdiobus_register_phy(struct mii= _bus *bus, { return -EINVAL; } + +static inline int fwnode_phy_register_fixed_link(struct fwnode_handle *fwn= ode) +{ + return -ENODEV; +} + +static inline void fwnode_phy_deregister_fixed_link(struct fwnode_handle *= fwnode) +{ +} + +static inline bool fwnode_phy_is_fixed_link(struct fwnode_handle *fwnode) +{ + return false; +} #endif =20 #endif /* __LINUX_FWNODE_MDIO_H */ diff --git a/drivers/net/mdio/fwnode_mdio.c b/drivers/net/mdio/fwnode_mdio.c index b782c35c4ac1..56f57381ae69 100644 --- a/drivers/net/mdio/fwnode_mdio.c +++ b/drivers/net/mdio/fwnode_mdio.c @@ -10,6 +10,7 @@ #include #include #include +#include #include =20 MODULE_AUTHOR("Calvin Johnson "); @@ -185,3 +186,98 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, return rc; } EXPORT_SYMBOL(fwnode_mdiobus_register_phy); + +/* + * fwnode_phy_is_fixed_link() and fwnode_phy_register_fixed_link() must + * support two bindings: + * - the old binding, where 'fixed-link' was a property with 5 + * cells encoding various information about the fixed PHY + * - the new binding, where 'fixed-link' is a sub-node of the + * Ethernet device. + */ +bool fwnode_phy_is_fixed_link(struct fwnode_handle *fwnode) +{ + struct fwnode_handle *fixed_link_node; + const char *managed; + + /* New binding */ + fixed_link_node =3D fwnode_get_named_child_node(fwnode, "fixed-link"); + if (fixed_link_node) { + fwnode_handle_put(fixed_link_node); + return true; + } + + if (fwnode_property_read_string(fwnode, "managed", &managed) =3D=3D 0 && + strcmp(managed, "auto") !=3D 0) + return true; + + /* Old binding */ + return fwnode_property_count_u32(fwnode, "fixed-link") =3D=3D 5; +} +EXPORT_SYMBOL(fwnode_phy_is_fixed_link); + +int fwnode_phy_register_fixed_link(struct fwnode_handle *fwnode) +{ + struct fixed_phy_status status =3D {}; + struct fwnode_handle *fixed_link_node; + u32 fixed_link_prop[5]; + const char *managed; + int rc; + + if (fwnode_property_read_string(fwnode, "managed", &managed) =3D=3D 0 && + strcmp(managed, "in-band-status") =3D=3D 0) { + /* status is zeroed, namely its .link member */ + goto register_phy; + } + + /* New binding */ + fixed_link_node =3D fwnode_get_named_child_node(fwnode, "fixed-link"); + if (fixed_link_node) { + status.link =3D 1; + status.duplex =3D fwnode_property_present(fixed_link_node, + "full-duplex"); + rc =3D fwnode_property_read_u32(fixed_link_node, "speed", + &status.speed); + if (rc) { + fwnode_handle_put(fixed_link_node); + return rc; + } + status.pause =3D fwnode_property_present(fixed_link_node, "pause"); + status.asym_pause =3D fwnode_property_present(fixed_link_node, + "asym-pause"); + fwnode_handle_put(fixed_link_node); + + goto register_phy; + } + + /* Old binding */ + rc =3D fwnode_property_read_u32_array(fwnode, "fixed-link", fixed_link_pr= op, + ARRAY_SIZE(fixed_link_prop)); + if (rc) + return rc; + + status.link =3D 1; + status.duplex =3D fixed_link_prop[1]; + status.speed =3D fixed_link_prop[2]; + status.pause =3D fixed_link_prop[3]; + status.asym_pause =3D fixed_link_prop[4]; + +register_phy: + return PTR_ERR_OR_ZERO(fixed_phy_register(PHY_POLL, &status, fwnode)); +} +EXPORT_SYMBOL(fwnode_phy_register_fixed_link); + +void fwnode_phy_deregister_fixed_link(struct fwnode_handle *fwnode) +{ + struct phy_device *phydev; + + phydev =3D fwnode_phy_find_device(fwnode); + if (!phydev) + return; + + fixed_phy_unregister(phydev); + + put_device(&phydev->mdio.dev); /* fwnode_phy_find_device() */ + phy_device_free(phydev); /* fixed_phy_register() */ +} +EXPORT_SYMBOL(fwnode_phy_deregister_fixed_link); diff --git a/drivers/net/mdio/of_mdio.c b/drivers/net/mdio/of_mdio.c index ba22b7110cdc..e6b3a4e251a1 100644 --- a/drivers/net/mdio/of_mdio.c +++ b/drivers/net/mdio/of_mdio.c @@ -353,91 +353,18 @@ EXPORT_SYMBOL(of_phy_get_and_connect); */ bool of_phy_is_fixed_link(struct device_node *np) { - struct device_node *dn; - int len, err; - const char *managed; - - /* New binding */ - dn =3D of_get_child_by_name(np, "fixed-link"); - if (dn) { - of_node_put(dn); - return true; - } - - err =3D of_property_read_string(np, "managed", &managed); - if (err =3D=3D 0 && strcmp(managed, "auto") !=3D 0) - return true; - - /* Old binding */ - if (of_get_property(np, "fixed-link", &len) && - len =3D=3D (5 * sizeof(__be32))) - return true; - - return false; + return fwnode_phy_is_fixed_link(of_fwnode_handle(np)); } EXPORT_SYMBOL(of_phy_is_fixed_link); =20 int of_phy_register_fixed_link(struct device_node *np) { - struct fixed_phy_status status =3D {}; - struct device_node *fixed_link_node; - u32 fixed_link_prop[5]; - const char *managed; - - if (of_property_read_string(np, "managed", &managed) =3D=3D 0 && - strcmp(managed, "in-band-status") =3D=3D 0) { - /* status is zeroed, namely its .link member */ - goto register_phy; - } - - /* New binding */ - fixed_link_node =3D of_get_child_by_name(np, "fixed-link"); - if (fixed_link_node) { - status.link =3D 1; - status.duplex =3D of_property_read_bool(fixed_link_node, - "full-duplex"); - if (of_property_read_u32(fixed_link_node, "speed", - &status.speed)) { - of_node_put(fixed_link_node); - return -EINVAL; - } - status.pause =3D of_property_read_bool(fixed_link_node, "pause"); - status.asym_pause =3D of_property_read_bool(fixed_link_node, - "asym-pause"); - of_node_put(fixed_link_node); - - goto register_phy; - } - - /* Old binding */ - if (of_property_read_u32_array(np, "fixed-link", fixed_link_prop, - ARRAY_SIZE(fixed_link_prop)) =3D=3D 0) { - status.link =3D 1; - status.duplex =3D fixed_link_prop[1]; - status.speed =3D fixed_link_prop[2]; - status.pause =3D fixed_link_prop[3]; - status.asym_pause =3D fixed_link_prop[4]; - goto register_phy; - } - - return -ENODEV; - -register_phy: - return PTR_ERR_OR_ZERO(fixed_phy_register(PHY_POLL, &status, of_fwnode_ha= ndle(np))); + return fwnode_phy_register_fixed_link(of_fwnode_handle(np)); } EXPORT_SYMBOL(of_phy_register_fixed_link); =20 void of_phy_deregister_fixed_link(struct device_node *np) { - struct phy_device *phydev; - - phydev =3D of_phy_find_device(np); - if (!phydev) - return; - - fixed_phy_unregister(phydev); - - put_device(&phydev->mdio.dev); /* of_phy_find_device() */ - phy_device_free(phydev); /* fixed_phy_register() */ + fwnode_phy_deregister_fixed_link(of_fwnode_handle(np)); } EXPORT_SYMBOL(of_phy_deregister_fixed_link); --=20 2.29.0 From nobody Mon Sep 15 01:56:02 2025 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 A2D49C46467 for ; Mon, 16 Jan 2023 17:53:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235161AbjAPRx0 (ORCPT ); Mon, 16 Jan 2023 12:53:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234991AbjAPRwc (ORCPT ); Mon, 16 Jan 2023 12:52:32 -0500 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F00A3B3FC for ; Mon, 16 Jan 2023 09:35:03 -0800 (PST) Received: by mail-lj1-x229.google.com with SMTP id c3so807681ljh.1 for ; Mon, 16 Jan 2023 09:35:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2mmk9wI3+C8ssmxR+DpT3SDJM6QGPsI0pDiXXE/Ux+4=; b=mVSJR9izrtn8REjhj4XqnwcyPGABR2JM6lKBsAZbCEjbjsHURusNR09T5nKNDVhIIZ NTaYjBj8l7WG9pkdbHHGCOYl0yrqUES+kElLjeaXPo6GSTje2genBqcuhWjgaVRnhPx8 yatCz72qgWRumx2nfT0Lp1DOwoSBLsXRFH9AT9M4V8+1DbKEfzxPACN97T+sNzAsVW4M Oc8g7B1djvHKggbrz+Fy6zgU0JlosLxCnMFdyltQY46tggiYUnG58NrzpRHbKJuHxLBQ mA3Dd5UCy9v3CLLuIA6r6tPXn8HvRs+tuv385DmyMQyldDQUruLpcDL+NYRTATsXWo+b uW/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2mmk9wI3+C8ssmxR+DpT3SDJM6QGPsI0pDiXXE/Ux+4=; b=vdgQGrYBEaulnQbDYunlTeFgza2w2lPJmFzfXyi8yHamlP7FRkH+NQb26maSrZtRP9 0L1Rt/t434ibohu1mU8zI0l1Phwa3VZ8U/84TOls8gXQaeNa0fzh/Ik+5GccTFRpggH0 +2h1CdL7qe2czOuAh0NNGGybeZo3oYJQcRIp7kTuLpk0J3zcEVwrFtZsriD1bhW79NGE Xs+3enJmO23L3irGwvRUDV5TziRiti7lWw93wBiSH+s4toyk6gAlmkxfY7Uetd3PijUe J3EqINsOuiiwgw0QNxqI97qjvIk/m04AJ00ooRHPIn2XSvXAL3JUf6NPzSWMQP1qijqq JV/w== X-Gm-Message-State: AFqh2kq3Ltq15hPNd+miD7UR0VHH4i4dzd/J3kWHsk6HD6FCVVIjrE54 xPwAMCvXhs/D6yEgkuEjltBItsRxsSxsRJ8Q X-Google-Smtp-Source: AMrXdXss8H0gbWs28XqQtnJ2QyT/hDi+CE2b0WlWVk57pQf05wIO5SbYvmxXHAzd6auZ7WOrCC7Qeg== X-Received: by 2002:a2e:5cd:0:b0:282:160b:e359 with SMTP id 196-20020a2e05cd000000b00282160be359mr166385ljf.23.1673890501403; Mon, 16 Jan 2023 09:35:01 -0800 (PST) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id k20-20020a2e8894000000b0028b7f51414fsm707333lji.80.2023.01.16.09.35.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Jan 2023 09:35:00 -0800 (PST) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, netdev@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@linux.intel.com, sean.wang@mediatek.com, Landen.Chao@mediatek.com, linus.walleij@linaro.org, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux@armlinux.org.uk, hkallweit1@gmail.com, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com, Samer.El-Haj-Mahmoud@arm.com Subject: [net-next: PATCH v4 3/8] net: dsa: switch to device_/fwnode_ APIs Date: Mon, 16 Jan 2023 18:34:15 +0100 Message-Id: <20230116173420.1278704-4-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20230116173420.1278704-1-mw@semihalf.com> References: <20230116173420.1278704-1-mw@semihalf.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In order to support both DT and ACPI in future, modify the generic DSA code to use device_/fwnode_ equivalent routines. Drop using port's 'dn' field and use only fwnode - update all dependent drivers. Because support for more generic fwnode is added, replace '_of' suffix with '_fw' in related routines. No functional change is introduced by this patch. Signed-off-by: Marcin Wojtas --- include/net/dsa.h | 2 +- net/dsa/port.h | 4 +- drivers/net/dsa/mt7530.c | 6 +- drivers/net/dsa/mv88e6xxx/chip.c | 16 +-- drivers/net/dsa/qca/qca8k-8xxx.c | 2 +- drivers/net/dsa/realtek/rtl8365mb.c | 2 +- net/dsa/dsa.c | 117 +++++++++++--------- net/dsa/port.c | 85 +++++++------- net/dsa/slave.c | 7 +- 9 files changed, 120 insertions(+), 121 deletions(-) diff --git a/include/net/dsa.h b/include/net/dsa.h index 96086289aa9b..b933b88ace78 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -300,7 +300,7 @@ struct dsa_port { =20 u8 setup:1; =20 - struct device_node *dn; + struct fwnode_handle *fwnode; unsigned int ageing_time; =20 struct dsa_bridge *bridge; diff --git a/net/dsa/port.h b/net/dsa/port.h index 9c218660d223..5037b8be982e 100644 --- a/net/dsa/port.h +++ b/net/dsa/port.h @@ -101,8 +101,8 @@ int dsa_port_mrp_del_ring_role(const struct dsa_port *d= p, const struct switchdev_obj_ring_role_mrp *mrp); int dsa_port_phylink_create(struct dsa_port *dp); void dsa_port_phylink_destroy(struct dsa_port *dp); -int dsa_shared_port_link_register_of(struct dsa_port *dp); -void dsa_shared_port_link_unregister_of(struct dsa_port *dp); +int dsa_shared_port_link_register_fw(struct dsa_port *dp); +void dsa_shared_port_link_unregister_fw(struct dsa_port *dp); int dsa_port_hsr_join(struct dsa_port *dp, struct net_device *hsr); void dsa_port_hsr_leave(struct dsa_port *dp, struct net_device *hsr); int dsa_port_tag_8021q_vlan_add(struct dsa_port *dp, u16 vid, bool broadca= st); diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index 908fa89444c9..35c4c71216fe 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -2235,8 +2235,10 @@ mt7530_setup(struct dsa_switch *ds) =20 if (!dsa_is_unused_port(ds, 5)) { priv->p5_intf_sel =3D P5_INTF_SEL_GMAC5; - ret =3D of_get_phy_mode(dsa_to_port(ds, 5)->dn, &interface); - if (ret && ret !=3D -ENODEV) + ret =3D fwnode_get_phy_mode(dsa_to_port(ds, 5)->fwnode); + if (ret >=3D 0) + interface =3D ret; + else if (ret !=3D -ENODEV) return ret; } else { /* Scan the ethernet nodes. look for GMAC1, lookup used phy */ diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/c= hip.c index 1168ea75f5f5..6731597bded0 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -3285,7 +3285,7 @@ static int mv88e6xxx_setup_upstream_port(struct mv88e= 6xxx_chip *chip, int port) =20 static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port) { - struct device_node *phy_handle =3D NULL; + struct fwnode_handle *phy_handle =3D NULL; struct dsa_switch *ds =3D chip->ds; phy_interface_t mode; struct dsa_port *dp; @@ -3509,18 +3509,14 @@ static int mv88e6xxx_setup_port(struct mv88e6xxx_ch= ip *chip, int port) =20 if (chip->info->ops->serdes_set_tx_amplitude) { if (dp) - phy_handle =3D of_parse_phandle(dp->dn, "phy-handle", 0); + phy_handle =3D fwnode_find_reference(dp->fwnode, "phy-handle", 0); =20 - if (phy_handle && !of_property_read_u32(phy_handle, - "tx-p2p-microvolt", - &tx_amp)) + if (!fwnode_property_read_u32(phy_handle, "tx-p2p-microvolt", &tx_amp)) err =3D chip->info->ops->serdes_set_tx_amplitude(chip, port, tx_amp); - if (phy_handle) { - of_node_put(phy_handle); - if (err) - return err; - } + fwnode_handle_put(phy_handle); + if (err) + return err; } =20 /* Port based VLAN map: give each port the same default address diff --git a/drivers/net/dsa/qca/qca8k-8xxx.c b/drivers/net/dsa/qca/qca8k-8= xxx.c index 2f224b166bbb..6ceb9478309f 100644 --- a/drivers/net/dsa/qca/qca8k-8xxx.c +++ b/drivers/net/dsa/qca/qca8k-8xxx.c @@ -1088,7 +1088,7 @@ qca8k_parse_port_config(struct qca8k_priv *priv) continue; =20 dp =3D dsa_to_port(priv->ds, port); - port_dn =3D dp->dn; + port_dn =3D to_of_node(dp->fwnode); cpu_port_index++; =20 if (!of_device_is_available(port_dn)) diff --git a/drivers/net/dsa/realtek/rtl8365mb.c b/drivers/net/dsa/realtek/= rtl8365mb.c index da31d8b839ac..d61da012451f 100644 --- a/drivers/net/dsa/realtek/rtl8365mb.c +++ b/drivers/net/dsa/realtek/rtl8365mb.c @@ -887,7 +887,7 @@ static int rtl8365mb_ext_config_rgmii(struct realtek_pr= iv *priv, int port, return -ENODEV; =20 dp =3D dsa_to_port(priv->ds, port); - dn =3D dp->dn; + dn =3D to_of_node(dp->fwnode); =20 /* Set the RGMII TX/RX delay * diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c index e5f156940c67..d1ca3bb03858 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c @@ -273,12 +273,12 @@ static void dsa_tree_put(struct dsa_switch_tree *dst) } =20 static struct dsa_port *dsa_tree_find_port_by_node(struct dsa_switch_tree = *dst, - struct device_node *dn) + struct fwnode_handle *fwnode) { struct dsa_port *dp; =20 list_for_each_entry(dp, &dst->ports, list) - if (dp->dn =3D=3D dn) + if (dp->fwnode =3D=3D fwnode) return dp; =20 return NULL; @@ -314,14 +314,13 @@ static bool dsa_port_setup_routing_table(struct dsa_p= ort *dp) { struct dsa_switch *ds =3D dp->ds; struct dsa_switch_tree *dst =3D ds->dst; - struct device_node *dn =3D dp->dn; struct of_phandle_iterator it; struct dsa_port *link_dp; struct dsa_link *dl; int err; =20 - of_for_each_phandle(&it, err, dn, "link", NULL, 0) { - link_dp =3D dsa_tree_find_port_by_node(dst, it.node); + of_for_each_phandle(&it, err, to_of_node(dp->fwnode), "link", NULL, 0) { + link_dp =3D dsa_tree_find_port_by_node(dst, of_fwnode_handle(it.node)); if (!link_dp) { of_node_put(it.node); return false; @@ -366,14 +365,17 @@ static struct dsa_port *dsa_tree_find_first_cpu(struc= t dsa_switch_tree *dst) =20 struct net_device *dsa_tree_find_first_master(struct dsa_switch_tree *dst) { - struct device_node *ethernet; + struct fwnode_handle *ethernet; struct net_device *master; struct dsa_port *cpu_dp; =20 cpu_dp =3D dsa_tree_find_first_cpu(dst); - ethernet =3D of_parse_phandle(cpu_dp->dn, "ethernet", 0); - master =3D of_find_net_device_by_node(ethernet); - of_node_put(ethernet); + ethernet =3D fwnode_find_reference(cpu_dp->fwnode, "ethernet", 0); + if (IS_ERR(ethernet)) + return NULL; + + master =3D of_find_net_device_by_node(to_of_node(ethernet)); + fwnode_handle_put(ethernet); =20 return master; } @@ -457,8 +459,8 @@ static int dsa_port_setup(struct dsa_port *dp) dsa_port_disable(dp); break; case DSA_PORT_TYPE_CPU: - if (dp->dn) { - err =3D dsa_shared_port_link_register_of(dp); + if (dp->fwnode) { + err =3D dsa_shared_port_link_register_fw(dp); if (err) break; dsa_port_link_registered =3D true; @@ -475,8 +477,8 @@ static int dsa_port_setup(struct dsa_port *dp) =20 break; case DSA_PORT_TYPE_DSA: - if (dp->dn) { - err =3D dsa_shared_port_link_register_of(dp); + if (dp->fwnode) { + err =3D dsa_shared_port_link_register_fw(dp); if (err) break; dsa_port_link_registered =3D true; @@ -493,7 +495,7 @@ static int dsa_port_setup(struct dsa_port *dp) =20 break; case DSA_PORT_TYPE_USER: - of_get_mac_address(dp->dn, dp->mac); + fwnode_get_mac_address(dp->fwnode, dp->mac); err =3D dsa_slave_create(dp); break; } @@ -501,7 +503,7 @@ static int dsa_port_setup(struct dsa_port *dp) if (err && dsa_port_enabled) dsa_port_disable(dp); if (err && dsa_port_link_registered) - dsa_shared_port_link_unregister_of(dp); + dsa_shared_port_link_unregister_fw(dp); if (err) { dsa_port_devlink_teardown(dp); return err; @@ -522,13 +524,13 @@ static void dsa_port_teardown(struct dsa_port *dp) break; case DSA_PORT_TYPE_CPU: dsa_port_disable(dp); - if (dp->dn) - dsa_shared_port_link_unregister_of(dp); + if (dp->fwnode) + dsa_shared_port_link_unregister_fw(dp); break; case DSA_PORT_TYPE_DSA: dsa_port_disable(dp); - if (dp->dn) - dsa_shared_port_link_unregister_of(dp); + if (dp->fwnode) + dsa_shared_port_link_unregister_fw(dp); break; case DSA_PORT_TYPE_USER: if (dp->slave) { @@ -603,7 +605,7 @@ static void dsa_switch_teardown_tag_protocol(struct dsa= _switch *ds) =20 static int dsa_switch_setup(struct dsa_switch *ds) { - struct device_node *dn; + struct fwnode_handle *fwnode; int err; =20 if (ds->setup) @@ -643,10 +645,10 @@ static int dsa_switch_setup(struct dsa_switch *ds) =20 dsa_slave_mii_bus_init(ds); =20 - dn =3D of_get_child_by_name(ds->dev->of_node, "mdio"); + fwnode =3D device_get_named_child_node(ds->dev, "mdio"); =20 - err =3D of_mdiobus_register(ds->slave_mii_bus, dn); - of_node_put(dn); + err =3D of_mdiobus_register(ds->slave_mii_bus, to_of_node(fwnode)); + fwnode_handle_put(fwnode); if (err < 0) goto free_slave_mii_bus; } @@ -1216,24 +1218,31 @@ static int dsa_port_parse_cpu(struct dsa_port *dp, = struct net_device *master, return 0; } =20 -static int dsa_port_parse_of(struct dsa_port *dp, struct device_node *dn) +static int dsa_port_parse_fw(struct dsa_port *dp, struct fwnode_handle *fw= node) { - struct device_node *ethernet =3D of_parse_phandle(dn, "ethernet", 0); - const char *name =3D of_get_property(dn, "label", NULL); - bool link =3D of_property_read_bool(dn, "link"); + struct fwnode_handle *ethernet =3D fwnode_find_reference(fwnode, "etherne= t", 0); + bool link =3D fwnode_property_present(fwnode, "link"); + const char *name; + int ret; =20 - dp->dn =3D dn; + fwnode_property_read_string(fwnode, "label", &name); =20 - if (ethernet) { + dp->fwnode =3D fwnode; + + if (!IS_ERR(ethernet)) { struct net_device *master; const char *user_protocol; =20 - master =3D of_find_net_device_by_node(ethernet); - of_node_put(ethernet); + master =3D of_find_net_device_by_node(to_of_node(ethernet)); + fwnode_handle_put(ethernet); if (!master) return -EPROBE_DEFER; =20 - user_protocol =3D of_get_property(dn, "dsa-tag-protocol", NULL); + ret =3D fwnode_property_read_string(fwnode, "dsa-tag-protocol", + &user_protocol); + if (ret) + user_protocol =3D NULL; + return dsa_port_parse_cpu(dp, master, user_protocol); } =20 @@ -1243,61 +1252,61 @@ static int dsa_port_parse_of(struct dsa_port *dp, s= truct device_node *dn) return dsa_port_parse_user(dp, name); } =20 -static int dsa_switch_parse_ports_of(struct dsa_switch *ds, - struct device_node *dn) +static int dsa_switch_parse_ports_fw(struct dsa_switch *ds, + struct fwnode_handle *fwnode) { - struct device_node *ports, *port; + struct fwnode_handle *ports, *port; struct dsa_port *dp; int err =3D 0; u32 reg; =20 - ports =3D of_get_child_by_name(dn, "ports"); + ports =3D fwnode_get_named_child_node(fwnode, "ports"); if (!ports) { /* The second possibility is "ethernet-ports" */ - ports =3D of_get_child_by_name(dn, "ethernet-ports"); + ports =3D fwnode_get_named_child_node(fwnode, "ethernet-ports"); if (!ports) { dev_err(ds->dev, "no ports child node found\n"); return -EINVAL; } } =20 - for_each_available_child_of_node(ports, port) { - err =3D of_property_read_u32(port, "reg", ®); + fwnode_for_each_available_child_node(ports, port) { + err =3D fwnode_property_read_u32(port, "reg", ®); if (err) { - of_node_put(port); + fwnode_handle_put(port); goto out_put_node; } =20 if (reg >=3D ds->num_ports) { dev_err(ds->dev, "port %pOF index %u exceeds num_ports (%u)\n", port, reg, ds->num_ports); - of_node_put(port); + fwnode_handle_put(port); err =3D -EINVAL; goto out_put_node; } =20 dp =3D dsa_to_port(ds, reg); =20 - err =3D dsa_port_parse_of(dp, port); + err =3D dsa_port_parse_fw(dp, port); if (err) { - of_node_put(port); + fwnode_handle_put(port); goto out_put_node; } } =20 out_put_node: - of_node_put(ports); + fwnode_handle_put(ports); return err; } =20 -static int dsa_switch_parse_member_of(struct dsa_switch *ds, - struct device_node *dn) +static int dsa_switch_parse_member_fw(struct dsa_switch *ds, + struct fwnode_handle *fwnode) { u32 m[2] =3D { 0, 0 }; int sz; =20 /* Don't error out if this optional property isn't found */ - sz =3D of_property_read_variable_u32_array(dn, "dsa,member", m, 2, 2); + sz =3D fwnode_property_read_u32_array(fwnode, "dsa,member", m, 2); if (sz < 0 && sz !=3D -EINVAL) return sz; =20 @@ -1334,11 +1343,11 @@ static int dsa_switch_touch_ports(struct dsa_switch= *ds) return 0; } =20 -static int dsa_switch_parse_of(struct dsa_switch *ds, struct device_node *= dn) +static int dsa_switch_parse_fw(struct dsa_switch *ds, struct fwnode_handle= *fwnode) { int err; =20 - err =3D dsa_switch_parse_member_of(ds, dn); + err =3D dsa_switch_parse_member_fw(ds, fwnode); if (err) return err; =20 @@ -1346,7 +1355,7 @@ static int dsa_switch_parse_of(struct dsa_switch *ds,= struct device_node *dn) if (err) return err; =20 - return dsa_switch_parse_ports_of(ds, dn); + return dsa_switch_parse_ports_fw(ds, fwnode); } =20 static int dev_is_class(struct device *dev, void *class) @@ -1475,20 +1484,20 @@ static int dsa_switch_probe(struct dsa_switch *ds) { struct dsa_switch_tree *dst; struct dsa_chip_data *pdata; - struct device_node *np; + struct fwnode_handle *fwnode; int err; =20 if (!ds->dev) return -ENODEV; =20 pdata =3D ds->dev->platform_data; - np =3D ds->dev->of_node; + fwnode =3D dev_fwnode(ds->dev); =20 if (!ds->num_ports) return -EINVAL; =20 - if (np) { - err =3D dsa_switch_parse_of(ds, np); + if (fwnode) { + err =3D dsa_switch_parse_fw(ds, fwnode); if (err) dsa_switch_release_ports(ds); } else if (pdata) { diff --git a/net/dsa/port.c b/net/dsa/port.c index 67ad1adec2a2..8f5793f87f40 100644 --- a/net/dsa/port.c +++ b/net/dsa/port.c @@ -6,11 +6,10 @@ * Vivien Didelot */ =20 +#include #include #include #include -#include -#include =20 #include "dsa.h" #include "port.h" @@ -1535,20 +1534,20 @@ void dsa_port_set_tag_protocol(struct dsa_port *cpu= _dp, =20 static struct phy_device *dsa_port_get_phy_device(struct dsa_port *dp) { - struct device_node *phy_dn; + struct fwnode_handle *phy_handle; struct phy_device *phydev; =20 - phy_dn =3D of_parse_phandle(dp->dn, "phy-handle", 0); - if (!phy_dn) + phy_handle =3D fwnode_find_reference(dp->fwnode, "phy-handle", 0); + if (IS_ERR(phy_handle)) return NULL; =20 - phydev =3D of_phy_find_device(phy_dn); + phydev =3D fwnode_phy_find_device(phy_handle); if (!phydev) { - of_node_put(phy_dn); + fwnode_handle_put(phy_handle); return ERR_PTR(-EPROBE_DEFER); } =20 - of_node_put(phy_dn); + fwnode_handle_put(phy_handle); return phydev; } =20 @@ -1678,12 +1677,11 @@ static const struct phylink_mac_ops dsa_port_phylin= k_mac_ops =3D { int dsa_port_phylink_create(struct dsa_port *dp) { struct dsa_switch *ds =3D dp->ds; - phy_interface_t mode; struct phylink *pl; - int err; + int mode; =20 - err =3D of_get_phy_mode(dp->dn, &mode); - if (err) + mode =3D fwnode_get_phy_mode(dp->fwnode); + if (mode < 0) mode =3D PHY_INTERFACE_MODE_NA; =20 /* Presence of phylink_mac_link_state or phylink_mac_an_restart is @@ -1696,7 +1694,7 @@ int dsa_port_phylink_create(struct dsa_port *dp) if (ds->ops->phylink_get_caps) ds->ops->phylink_get_caps(ds, dp->index, &dp->pl_config); =20 - pl =3D phylink_create(&dp->pl_config, of_fwnode_handle(dp->dn), + pl =3D phylink_create(&dp->pl_config, dp->fwnode, mode, &dsa_port_phylink_mac_ops); if (IS_ERR(pl)) { pr_err("error creating PHYLINK: %ld\n", PTR_ERR(pl)); @@ -1714,7 +1712,7 @@ void dsa_port_phylink_destroy(struct dsa_port *dp) dp->pl =3D NULL; } =20 -static int dsa_shared_port_setup_phy_of(struct dsa_port *dp, bool enable) +static int dsa_shared_port_setup_phy_fw(struct dsa_port *dp, bool enable) { struct dsa_switch *ds =3D dp->ds; struct phy_device *phydev; @@ -1752,16 +1750,15 @@ static int dsa_shared_port_setup_phy_of(struct dsa_= port *dp, bool enable) return err; } =20 -static int dsa_shared_port_fixed_link_register_of(struct dsa_port *dp) +static int dsa_shared_port_fixed_link_register_fw(struct dsa_port *dp) { - struct device_node *dn =3D dp->dn; struct dsa_switch *ds =3D dp->ds; struct phy_device *phydev; int port =3D dp->index; - phy_interface_t mode; + int mode; int err; =20 - err =3D of_phy_register_fixed_link(dn); + err =3D fwnode_phy_register_fixed_link(dp->fwnode); if (err) { dev_err(ds->dev, "failed to register the fixed PHY of port %d\n", @@ -1769,10 +1766,10 @@ static int dsa_shared_port_fixed_link_register_of(s= truct dsa_port *dp) return err; } =20 - phydev =3D of_phy_find_device(dn); + phydev =3D fwnode_phy_find_device(dp->fwnode); =20 - err =3D of_get_phy_mode(dn, &mode); - if (err) + mode =3D fwnode_get_phy_mode(dp->fwnode); + if (mode < 0) mode =3D PHY_INTERFACE_MODE_NA; phydev->interface =3D mode; =20 @@ -1789,7 +1786,6 @@ static int dsa_shared_port_fixed_link_register_of(str= uct dsa_port *dp) static int dsa_shared_port_phylink_register(struct dsa_port *dp) { struct dsa_switch *ds =3D dp->ds; - struct device_node *port_dn =3D dp->dn; int err; =20 dp->pl_config.dev =3D ds->dev; @@ -1799,7 +1795,7 @@ static int dsa_shared_port_phylink_register(struct ds= a_port *dp) if (err) return err; =20 - err =3D phylink_of_phy_connect(dp->pl, port_dn, 0); + err =3D phylink_fwnode_phy_connect(dp->pl, dp->fwnode, 0); if (err && err !=3D -ENODEV) { pr_err("could not attach to PHY: %d\n", err); goto err_phy_connect; @@ -1926,51 +1922,50 @@ static const char * const dsa_switches_apply_workar= ounds[] =3D { NULL, }; =20 -static void dsa_shared_port_validate_of(struct dsa_port *dp, +static void dsa_shared_port_validate_fw(struct dsa_port *dp, bool *missing_phy_mode, bool *missing_link_description) { - struct device_node *dn =3D dp->dn, *phy_np; + struct fwnode_handle *phy_handle; struct dsa_switch *ds =3D dp->ds; - phy_interface_t mode; =20 *missing_phy_mode =3D false; *missing_link_description =3D false; =20 - if (of_get_phy_mode(dn, &mode)) { + if (fwnode_get_phy_mode(dp->fwnode) < 0) { *missing_phy_mode =3D true; dev_err(ds->dev, - "OF node %pOF of %s port %d lacks the required \"phy-mode\" property\n", - dn, dsa_port_is_cpu(dp) ? "CPU" : "DSA", dp->index); + "FW node %p of %s port %d lacks the required \"phy-mode\" property\n", + dp->fwnode, dsa_port_is_cpu(dp) ? "CPU" : "DSA", dp->index); } =20 - /* Note: of_phy_is_fixed_link() also returns true for + /* Note: fwnode_phy_is_fixed_link() also returns true for * managed =3D "in-band-status" */ - if (of_phy_is_fixed_link(dn)) + if (fwnode_phy_is_fixed_link(dp->fwnode)) return; =20 - phy_np =3D of_parse_phandle(dn, "phy-handle", 0); - if (phy_np) { - of_node_put(phy_np); + phy_handle =3D fwnode_find_reference(dp->fwnode, "phy-handle", 0); + if (!IS_ERR(phy_handle)) { + fwnode_handle_put(phy_handle); return; } =20 *missing_link_description =3D true; =20 dev_err(ds->dev, - "OF node %pOF of %s port %d lacks the required \"phy-handle\", \"fixed-l= ink\" or \"managed\" properties\n", - dn, dsa_port_is_cpu(dp) ? "CPU" : "DSA", dp->index); + "FW node %p of %s port %d lacks the required \"phy-handle\", \"fixed-lin= k\" or \"managed\" properties\n", + dp->fwnode, dsa_port_is_cpu(dp) ? "CPU" : "DSA", dp->index); } =20 -int dsa_shared_port_link_register_of(struct dsa_port *dp) +int dsa_shared_port_link_register_fw(struct dsa_port *dp) { struct dsa_switch *ds =3D dp->ds; bool missing_link_description; bool missing_phy_mode; int port =3D dp->index; =20 - dsa_shared_port_validate_of(dp, &missing_phy_mode, + dsa_shared_port_validate_fw(dp, &missing_phy_mode, &missing_link_description); =20 if ((missing_phy_mode || missing_link_description) && @@ -1996,13 +1991,13 @@ int dsa_shared_port_link_register_of(struct dsa_por= t *dp) dev_warn(ds->dev, "Using legacy PHYLIB callbacks. Please migrate to PHYLINK!\n"); =20 - if (of_phy_is_fixed_link(dp->dn)) - return dsa_shared_port_fixed_link_register_of(dp); + if (fwnode_phy_is_fixed_link(dp->fwnode)) + return dsa_shared_port_fixed_link_register_fw(dp); else - return dsa_shared_port_setup_phy_of(dp, true); + return dsa_shared_port_setup_phy_fw(dp, true); } =20 -void dsa_shared_port_link_unregister_of(struct dsa_port *dp) +void dsa_shared_port_link_unregister_fw(struct dsa_port *dp) { struct dsa_switch *ds =3D dp->ds; =20 @@ -2014,10 +2009,10 @@ void dsa_shared_port_link_unregister_of(struct dsa_= port *dp) return; } =20 - if (of_phy_is_fixed_link(dp->dn)) - of_phy_deregister_fixed_link(dp->dn); + if (fwnode_phy_is_fixed_link(dp->fwnode)) + fwnode_phy_deregister_fixed_link(dp->fwnode); else - dsa_shared_port_setup_phy_of(dp, false); + dsa_shared_port_setup_phy_fw(dp, false); } =20 int dsa_port_hsr_join(struct dsa_port *dp, struct net_device *hsr) diff --git a/net/dsa/slave.c b/net/dsa/slave.c index aab79c355224..fb150a543c30 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -10,8 +10,6 @@ #include #include #include -#include -#include #include #include #include @@ -2309,7 +2307,6 @@ static int dsa_slave_phy_connect(struct net_device *s= lave_dev, int addr, static int dsa_slave_phy_setup(struct net_device *slave_dev) { struct dsa_port *dp =3D dsa_slave_to_port(slave_dev); - struct device_node *port_dn =3D dp->dn; struct dsa_switch *ds =3D dp->ds; u32 phy_flags =3D 0; int ret; @@ -2333,7 +2330,7 @@ static int dsa_slave_phy_setup(struct net_device *sla= ve_dev) if (ds->ops->get_phy_flags) phy_flags =3D ds->ops->get_phy_flags(ds, dp->index); =20 - ret =3D phylink_of_phy_connect(dp->pl, port_dn, phy_flags); + ret =3D phylink_fwnode_phy_connect(dp->pl, dp->fwnode, phy_flags); if (ret =3D=3D -ENODEV && ds->slave_mii_bus) { /* We could not connect to a designated PHY or SFP, so try to * use the switch internal MDIO bus instead @@ -2455,7 +2452,7 @@ int dsa_slave_create(struct dsa_port *port) =20 SET_NETDEV_DEV(slave_dev, port->ds->dev); SET_NETDEV_DEVLINK_PORT(slave_dev, &port->devlink_port); - slave_dev->dev.of_node =3D port->dn; + device_set_node(&slave_dev->dev, port->fwnode); slave_dev->vlan_features =3D master->vlan_features; =20 p =3D netdev_priv(slave_dev); --=20 2.29.0 From nobody Mon Sep 15 01:56:02 2025 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 1859BC677F1 for ; Mon, 16 Jan 2023 17:53:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235174AbjAPRxa (ORCPT ); Mon, 16 Jan 2023 12:53:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229774AbjAPRwf (ORCPT ); Mon, 16 Jan 2023 12:52:35 -0500 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6537C3B3E0 for ; Mon, 16 Jan 2023 09:35:04 -0800 (PST) Received: by mail-lj1-x235.google.com with SMTP id f20so30689895lja.4 for ; Mon, 16 Jan 2023 09:35:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WLkKdr7pDQEIzmgkyKtN1Zu++zCyw4Keu9Km6S3sT2o=; b=QasTzb8h2vrOzkCrftuDbLS+D57mrkSyDJFNmvhtJg61QCpXBah5MQQ/klFT+Jr44m OfExarCYmScCqot8/2QoF2Kn6hockeWUu27BKBHaw+Vw6fz+Jow6YpMOSiHlDgxC7qhP EM/wOHX1PS88OTZXj6uG2qMVwZFi3u37IBsUODw2sJtv45GymLllUGbqdIyHat9jZEtp 5zGyuiyAQFvvbErrOfKVgcXcmSh4wE+9Wf+/et6R0cs1BNYNaTQaqu1mJphmFK7n2v7q InbhxENc/mnmZeHgZx7q7HwnK4+wdwGzz+9hvYhYU6h+LbB+kKtF52ZSeZA/SVyzh2hW tN6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WLkKdr7pDQEIzmgkyKtN1Zu++zCyw4Keu9Km6S3sT2o=; b=BriZnccPP7vEJzR7cRfphWFxeZR1523arn0a1DVLrYmCCURP8nS38HuxbzTy1bmUkV 3UnFPec8lKdDpbSWowwnwrQeHkjcEGUvcxBKYuFvSHIq9pqInX6m29P7japvnlYoMpoj 8wlnGgB9l8PCrHKSM7Ce82JTZnyuqoKnW0L/S8h0qAHB1AvPXqq/HECGPCNvd++KISv5 6FgeBzy+Lm7a/J+U+LdSVAOivkMF8ABD4/v2s9ZaQ8lOVx6MPdiKhNJtFUTQBbjt3QsS QsH6HKGF84tWF+PfzCulxajt11v9fAI6IkDjV/+0jh1a6GBsV+HS/3r8d0ai9Ghb1kVo DLyg== X-Gm-Message-State: AFqh2kqzRNg94bFEbO6lbqaipbKkgxojRY787RpyFgWSakKq8g7aQcif P8e5M4dvIpcdz5CCfX/7K86LrsGJ9UuYC3lE X-Google-Smtp-Source: AMrXdXsY9dU88GrMUZ0keyqwQPbzPga4V1dJtLnUYV90CFWzYZr4I98PrEX0dJGG50/qWJssb6/MCA== X-Received: by 2002:a2e:994f:0:b0:281:771:e1cd with SMTP id r15-20020a2e994f000000b002810771e1cdmr3381416ljj.33.1673890502691; Mon, 16 Jan 2023 09:35:02 -0800 (PST) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id k20-20020a2e8894000000b0028b7f51414fsm707333lji.80.2023.01.16.09.35.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Jan 2023 09:35:02 -0800 (PST) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, netdev@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@linux.intel.com, sean.wang@mediatek.com, Landen.Chao@mediatek.com, linus.walleij@linaro.org, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux@armlinux.org.uk, hkallweit1@gmail.com, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com, Samer.El-Haj-Mahmoud@arm.com Subject: [net-next: PATCH v4 4/8] net: mvpp2: initialize port fwnode pointer Date: Mon, 16 Jan 2023 18:34:16 +0100 Message-Id: <20230116173420.1278704-5-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20230116173420.1278704-1-mw@semihalf.com> References: <20230116173420.1278704-1-mw@semihalf.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" As a preparation to switch the DSA subsystem from using of_find_net_device_by_node() to its more generic fwnode_ equivalent, and later to allow ACPI description, update the port's device structure also with its fwnode pointer. Signed-off-by: Marcin Wojtas Reviewed-by: Andy Shevchenko --- drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/= ethernet/marvell/mvpp2/mvpp2_main.c index 5f89fcec07b1..a25e90791700 100644 --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c @@ -6884,7 +6884,7 @@ static int mvpp2_port_probe(struct platform_device *p= dev, dev->min_mtu =3D ETH_MIN_MTU; /* 9704 =3D=3D 9728 - 20 and rounding to 8 */ dev->max_mtu =3D MVPP2_BM_JUMBO_PKT_SIZE; - dev->dev.of_node =3D port_node; + device_set_node(&dev->dev, port_fwnode); =20 port->pcs_gmac.ops =3D &mvpp2_phylink_gmac_pcs_ops; port->pcs_xlg.ops =3D &mvpp2_phylink_xlg_pcs_ops; --=20 2.29.0 From nobody Mon Sep 15 01:56:02 2025 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 06C6AC678D8 for ; Mon, 16 Jan 2023 17:53:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234702AbjAPRxn (ORCPT ); Mon, 16 Jan 2023 12:53:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235026AbjAPRwn (ORCPT ); Mon, 16 Jan 2023 12:52:43 -0500 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC7C43B658 for ; Mon, 16 Jan 2023 09:35:05 -0800 (PST) Received: by mail-lj1-x22b.google.com with SMTP id s25so30712219lji.2 for ; Mon, 16 Jan 2023 09:35:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=t7F9JKouL1KurTO0QVKHN8g/5zAESWUg12UOdA+LKsI=; b=E3DYP0epTmdQaBr8PG3Lc8mLskVrmA2L1g1uosAju1bFb9Zd1/cbdiapQ5fFkaSZWK o6rwyTvWmoqnqO3GQ/PewcCOeU0+EVt2OCdA60ZsN2J+CeH1ab2BXc3aMXbO3uUsfHzx qv2fyovh8SRghPRZL80Urm0MOg9l7NaqDEA9Wj0/szZhsXkat75oRTQwgH4S2taaVfvI ye2rM+2rYjemoac3jVmVgsJM7q93qCrMpk1DijXEctb18ivK5LdNH+j1ll+sZnNopfVw p5jf7bQUsXQ7jDJbMKnRbGzaygpSujEZUXF/8g/SGPq88bZcs42LLCGQMTgOI04QcHju UK2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=t7F9JKouL1KurTO0QVKHN8g/5zAESWUg12UOdA+LKsI=; b=V3cLLIj0tmvLyjpY6efFbipplufw+Tc1QYO+lzljmb0cIkO5Rxk5MwDoON/mRbg0LT +wIHziQN41fkKeNvQ71sdYOET4B09Wb8cIllvGECGa4JN52jK6EuZLYxlKEH+H93ZO/o JNdYcvONo7ON/iVdYGuTezeuE0T2OtQjUM2MIzkmV5TbThEFAxe8fv7wnv4bojmkEFBU +acXUAa0I6+yGXwD8861LCqLtHQuqfFb87XApm8Ot1Kkl6tuDxSPDLh34WIr1fwKLziH VzTlDKBQ8mq3MPmUly6qMDhu4HX+bMdqRIpiV4QaRhcwVp/4iBg9j14G+kePDjNUebZ2 VDug== X-Gm-Message-State: AFqh2krBEohxuWAo4f3SrJN1r44W0LZhx2fdKKQ92Pf9gw5gpilbyLmj Xrobs5r1/B+RbN3IWZNq/ARDRaPILz20cXEn X-Google-Smtp-Source: AMrXdXuUnMtiRTBXJ6Nfs4XBmV3kM8wxIrl3j8mU01006aaUz85HcnPiZoQhJ+bNzRNdkZ6kmD/RtQ== X-Received: by 2002:a2e:90c7:0:b0:28b:77ce:f88b with SMTP id o7-20020a2e90c7000000b0028b77cef88bmr180131ljg.8.1673890504000; Mon, 16 Jan 2023 09:35:04 -0800 (PST) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id k20-20020a2e8894000000b0028b7f51414fsm707333lji.80.2023.01.16.09.35.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Jan 2023 09:35:03 -0800 (PST) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, netdev@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@linux.intel.com, sean.wang@mediatek.com, Landen.Chao@mediatek.com, linus.walleij@linaro.org, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux@armlinux.org.uk, hkallweit1@gmail.com, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com, Samer.El-Haj-Mahmoud@arm.com Subject: [net-next: PATCH v4 5/8] device property: introduce fwnode_find_parent_dev_match Date: Mon, 16 Jan 2023 18:34:17 +0100 Message-Id: <20230116173420.1278704-6-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20230116173420.1278704-1-mw@semihalf.com> References: <20230116173420.1278704-1-mw@semihalf.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add a new generic routine fwnode_find_parent_dev_match that can be used e.g. as a callback for class_find_device(). It searches for the struct device corresponding to a struct fwnode_handle by iterating over device and its parents. Signed-off-by: Marcin Wojtas Reviewed-by: Andy Shevchenko --- include/linux/property.h | 1 + drivers/base/property.c | 23 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/linux/property.h b/include/linux/property.h index 37179e3abad5..4ae20d7c5103 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -109,6 +109,7 @@ struct device *fwnode_get_next_parent_dev(struct fwnode= _handle *fwnode); unsigned int fwnode_count_parents(const struct fwnode_handle *fwn); struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwn, unsigned int depth); +int fwnode_find_parent_dev_match(struct device *dev, const void *data); bool fwnode_is_ancestor_of(struct fwnode_handle *ancestor, struct fwnode_h= andle *child); struct fwnode_handle *fwnode_get_next_child_node( const struct fwnode_handle *fwnode, struct fwnode_handle *child); diff --git a/drivers/base/property.c b/drivers/base/property.c index bbb3e499ff4a..84849d4934cc 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -693,6 +693,29 @@ struct fwnode_handle *fwnode_get_nth_parent(struct fwn= ode_handle *fwnode, } EXPORT_SYMBOL_GPL(fwnode_get_nth_parent); =20 +/** + * fwnode_find_parent_dev_match - look for a device matching the struct fw= node_handle + * @dev: the struct device to initiate the search + * @data: pointer passed for comparison + * + * Looks up the device structure corresponding with the fwnode by iterating + * over @dev and its parents. + * The routine can be used e.g. as a callback for class_find_device(). + * + * Returns: %1 - match is found + * %0 - match not found + */ +int fwnode_find_parent_dev_match(struct device *dev, const void *data) +{ + for (; dev; dev =3D dev->parent) { + if (device_match_fwnode(dev, data)) + return 1; + } + + return 0; +} +EXPORT_SYMBOL_GPL(fwnode_find_parent_dev_match); + /** * fwnode_is_ancestor_of - Test if @ancestor is ancestor of @child * @ancestor: Firmware which is tested for being an ancestor --=20 2.29.0 From nobody Mon Sep 15 01:56:02 2025 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 9411AC46467 for ; Mon, 16 Jan 2023 17:53:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235026AbjAPRxr (ORCPT ); Mon, 16 Jan 2023 12:53:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234749AbjAPRwo (ORCPT ); Mon, 16 Jan 2023 12:52:44 -0500 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDEA63B65B for ; Mon, 16 Jan 2023 09:35:06 -0800 (PST) Received: by mail-lj1-x22c.google.com with SMTP id q2so30723340ljp.6 for ; Mon, 16 Jan 2023 09:35:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RBUWzvDNamFGOC4iHjWn4zwEVY2qfQxl959ozP5DmYU=; b=U8jkVa+yYUfb1cCQseahksgWBpJukt1b1CaGFB+iPybFlVBjpECij+I2ZT4ata0oK0 kden32bhaDCCV4Ys+ariMdMSE72FyHU0IEYhws6Opat0vHBpv6NKEsiD/qI6mBsbwzxH xvrFiaCNHxPAZwsIlLTynN5pIZSKI0sWGJpTfj8pkM70sTZyXkndUy9JSkKfx0+LUu8z kc77vOo7mHxmgYrLnzVNM3+LOivOjEQ/QvRewiHQfXQrMOK1a+2iXuFUstPp5L1iChbx mOj9XY2URHfAwUdP9gloI3NqSSwb1dkVKGUJCiPaIt/HiVdwXy+7g3rI/ohGj0L6eQ5c 0gxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RBUWzvDNamFGOC4iHjWn4zwEVY2qfQxl959ozP5DmYU=; b=Vr5RKqUKj6rccdpa/NZ3hXoylJfAQC8m8bMnfTuBl3rMCIW9Nck2vZZosfEqRjr1xW DgkrRtXAPvvIPIgtKxgHruejY77kz/J+/vYIxYH6tbZ2O+NKSC+YX8kEENsmVSWG7akR Mh0EuKEld0TF1c1u01rBZd5LQMmDKAykrgBdglfx6BeVkpVDnYPq9LANPubX/ZWvz2VF 9k4ZIfgaa5KEo6qOWRs7OeTdTShZjk32hfHKfdjABghMjg0mvvQ973ZlLzVyaaacsCua 2J/u7e0Y/EJBwWnl3ml9ApwT/kxeGK62NFy82r0SfSI/fNx8Sjc8zlL8JknhDgrHhgcb 8DdQ== X-Gm-Message-State: AFqh2kpkQG2j4GyjsePhUVoCNPY5+Z9HMya3LoAh/N7G1BYGxbLYGHx3 3uWrL0gbA/HkPxPLn2vEpGee4p+JLzD5b7wG X-Google-Smtp-Source: AMrXdXtXXluHetGVDb9ihfasqH/ZvEunGrnR+uMrcj5mIztAAZ+L/N9e9JpuKfcIdjjKClxsIUUAbQ== X-Received: by 2002:a2e:960b:0:b0:286:6412:7060 with SMTP id v11-20020a2e960b000000b0028664127060mr185195ljh.15.1673890505233; Mon, 16 Jan 2023 09:35:05 -0800 (PST) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id k20-20020a2e8894000000b0028b7f51414fsm707333lji.80.2023.01.16.09.35.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Jan 2023 09:35:04 -0800 (PST) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, netdev@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@linux.intel.com, sean.wang@mediatek.com, Landen.Chao@mediatek.com, linus.walleij@linaro.org, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux@armlinux.org.uk, hkallweit1@gmail.com, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com, Samer.El-Haj-Mahmoud@arm.com Subject: [net-next: PATCH v4 6/8] net: core: switch to fwnode_find_net_device_by_node() Date: Mon, 16 Jan 2023 18:34:18 +0100 Message-Id: <20230116173420.1278704-7-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20230116173420.1278704-1-mw@semihalf.com> References: <20230116173420.1278704-1-mw@semihalf.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" A helper function which allows getting the struct net_device pointer associated with a given device tree node can be more generic and also support alternative hardware description. Switch to fwnode_ and update the only existing caller (in the DSA subsystem). For that purpose use newly added fwnode_find_parent_dev_match routine. Signed-off-by: Marcin Wojtas --- include/linux/etherdevice.h | 1 + include/linux/of_net.h | 6 ----- net/core/net-sysfs.c | 25 ++++++-------------- net/dsa/dsa.c | 5 ++-- 4 files changed, 11 insertions(+), 26 deletions(-) diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h index a541f0c4f146..3d475ee4a2d7 100644 --- a/include/linux/etherdevice.h +++ b/include/linux/etherdevice.h @@ -35,6 +35,7 @@ int nvmem_get_mac_address(struct device *dev, void *addrb= uf); int device_get_mac_address(struct device *dev, char *addr); int device_get_ethdev_address(struct device *dev, struct net_device *netde= v); int fwnode_get_mac_address(struct fwnode_handle *fwnode, char *addr); +struct net_device *fwnode_find_net_device_by_node(struct fwnode_handle *fw= node); =20 u32 eth_get_headlen(const struct net_device *dev, const void *data, u32 le= n); __be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev); diff --git a/include/linux/of_net.h b/include/linux/of_net.h index d88715a0b3a5..8a677f44c270 100644 --- a/include/linux/of_net.h +++ b/include/linux/of_net.h @@ -16,7 +16,6 @@ extern int of_get_phy_mode(struct device_node *np, phy_in= terface_t *interface); extern int of_get_mac_address(struct device_node *np, u8 *mac); extern int of_get_mac_address_nvmem(struct device_node *np, u8 *mac); int of_get_ethdev_address(struct device_node *np, struct net_device *dev); -extern struct net_device *of_find_net_device_by_node(struct device_node *n= p); #else static inline int of_get_phy_mode(struct device_node *np, phy_interface_t *interface) @@ -38,11 +37,6 @@ static inline int of_get_ethdev_address(struct device_no= de *np, struct net_devic { return -ENODEV; } - -static inline struct net_device *of_find_net_device_by_node(struct device_= node *np) -{ - return NULL; -} #endif =20 #endif /* __LINUX_OF_NET_H */ diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index ca55dd747d6c..652ba785e6f7 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -6,6 +6,7 @@ */ =20 #include +#include #include #include #include @@ -1935,38 +1936,26 @@ static struct class net_class __ro_after_init =3D { .get_ownership =3D net_get_ownership, }; =20 -#ifdef CONFIG_OF -static int of_dev_node_match(struct device *dev, const void *data) -{ - for (; dev; dev =3D dev->parent) { - if (dev->of_node =3D=3D data) - return 1; - } - - return 0; -} - /* - * of_find_net_device_by_node - lookup the net device for the device node - * @np: OF device node + * fwnode_find_net_device_by_node - lookup the net device for the device f= wnode + * @fwnode: firmware node * - * Looks up the net_device structure corresponding with the device node. + * Looks up the net_device structure corresponding with the fwnode. * If successful, returns a pointer to the net_device with the embedded * struct device refcount incremented by one, or NULL on failure. The * refcount must be dropped when done with the net_device. */ -struct net_device *of_find_net_device_by_node(struct device_node *np) +struct net_device *fwnode_find_net_device_by_node(struct fwnode_handle *fw= node) { struct device *dev; =20 - dev =3D class_find_device(&net_class, NULL, np, of_dev_node_match); + dev =3D class_find_device(&net_class, NULL, fwnode, fwnode_find_parent_de= v_match); if (!dev) return NULL; =20 return to_net_dev(dev); } -EXPORT_SYMBOL(of_find_net_device_by_node); -#endif +EXPORT_SYMBOL(fwnode_find_net_device_by_node); =20 /* Delete sysfs entries but hold kobject reference until after all * netdev references are gone. diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c index d1ca3bb03858..55f22a58556b 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c @@ -9,6 +9,7 @@ =20 #include #include +#include #include #include #include @@ -374,7 +375,7 @@ struct net_device *dsa_tree_find_first_master(struct ds= a_switch_tree *dst) if (IS_ERR(ethernet)) return NULL; =20 - master =3D of_find_net_device_by_node(to_of_node(ethernet)); + master =3D fwnode_find_net_device_by_node(ethernet); fwnode_handle_put(ethernet); =20 return master; @@ -1233,7 +1234,7 @@ static int dsa_port_parse_fw(struct dsa_port *dp, str= uct fwnode_handle *fwnode) struct net_device *master; const char *user_protocol; =20 - master =3D of_find_net_device_by_node(to_of_node(ethernet)); + master =3D fwnode_find_net_device_by_node(ethernet); fwnode_handle_put(ethernet); if (!master) return -EPROBE_DEFER; --=20 2.29.0 From nobody Mon Sep 15 01:56:02 2025 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 88F08C46467 for ; Mon, 16 Jan 2023 17:54:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232804AbjAPRx6 (ORCPT ); Mon, 16 Jan 2023 12:53:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235059AbjAPRwq (ORCPT ); Mon, 16 Jan 2023 12:52:46 -0500 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3542C3B666 for ; Mon, 16 Jan 2023 09:35:08 -0800 (PST) Received: by mail-lj1-x22b.google.com with SMTP id a37so4816903ljq.0 for ; Mon, 16 Jan 2023 09:35:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IG3bSK8xYQLNtQeDwvBcudzQX24jvHqx7mvJjzT4TmQ=; b=NPPSzrmDs8k+ezhrh00GcRf0wAc4JHNJtbo8IqBvhwEOUsIlLvXJcg6xefxvubKk0z mSZ9AXHXqbGkWG+FWznlDA3jSo7MjMc4i076oDzdYwIFhttJ21lQkxkttGPDJuoQFNQg uVEPVEtC/HACLci+urdlpqjvlo17YyhuZUsMDZjlTV4Ju/KPjrBEoZYGbAJPCsx9Xnyf HP5UEyFh4z6xfvbDi+L8oW/vKwzAJS94JjdiyweQE60zv/6YhfzIDfZ3KZy8mW2clk7U efsWN+ZLLlJggSP3XWYdqSJC54Fyo1uGmEavCzN0f7DEnGjpbSZFcv9v3lHmGNsyJgfT XYcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IG3bSK8xYQLNtQeDwvBcudzQX24jvHqx7mvJjzT4TmQ=; b=vtzx+BFNzT7d1q6fyaYLtBr3FFZwi4ZTMcXuSLmFrWuwoOe1OIYkhbjvQYlEFyH0Hi Tecr/u90MeJSiP77YuNiQ31HGJom2BAiXRFbl2gc15BxqoKDORZCQtzzGZBEqcsjY2iA coAdhVbcD9qeqjR2eTmROFlPxgySgWEfQhEX3kbJK6a4tzA//a+SuqeEmkRr7aBb3hwi O35/yQmBBPBiYewRJt8FW4W+I1ktCC3D1jY1/T3VPfAw20dwf+jK6PzVvi0ITErp2P6A 7B39GDbM8xhQIl1Fcoe5nqFcvh082LVaXJiwdUuzECW5js+Va6pKG4oaDkVNrbZy+BCO pU/A== X-Gm-Message-State: AFqh2kr/O5rud9PzMoGLxn5h5kIr82t5Znu61ZpXsuDeMmZAHlp6xms4 cQiRjTAjeELPG932QaTqR1btdeac8Nxty+XH X-Google-Smtp-Source: AMrXdXszKdh7LiiGRlyW8vhmOXa05ofxdBH4JgcNygyrmsBj7cAG1g74BCMnEDuUK1KWC6MWLYhkcA== X-Received: by 2002:a05:651c:1592:b0:27f:bede:c748 with SMTP id h18-20020a05651c159200b0027fbedec748mr4008770ljq.35.1673890506496; Mon, 16 Jan 2023 09:35:06 -0800 (PST) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id k20-20020a2e8894000000b0028b7f51414fsm707333lji.80.2023.01.16.09.35.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Jan 2023 09:35:06 -0800 (PST) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, netdev@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@linux.intel.com, sean.wang@mediatek.com, Landen.Chao@mediatek.com, linus.walleij@linaro.org, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux@armlinux.org.uk, hkallweit1@gmail.com, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com, Samer.El-Haj-Mahmoud@arm.com Subject: [net-next: PATCH v4 7/8] net: mdio: introduce fwnode_mdiobus_register_device() Date: Mon, 16 Jan 2023 18:34:19 +0100 Message-Id: <20230116173420.1278704-8-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20230116173420.1278704-1-mw@semihalf.com> References: <20230116173420.1278704-1-mw@semihalf.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" As a preparation patch to extend MDIO capabilities in the ACPI world, introduce fwnode_mdiobus_register_device() to register non-PHY devices on the mdiobus. Use the newly introduced routine instead of of_mdiobus_register_device(). Signed-off-by: Marcin Wojtas --- include/linux/fwnode_mdio.h | 3 ++ drivers/net/mdio/fwnode_mdio.c | 29 +++++++++++++++++ drivers/net/mdio/of_mdio.c | 33 +------------------- 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/include/linux/fwnode_mdio.h b/include/linux/fwnode_mdio.h index 98755b8c6c8a..39d74c5d1bb0 100644 --- a/include/linux/fwnode_mdio.h +++ b/include/linux/fwnode_mdio.h @@ -16,6 +16,9 @@ int fwnode_mdiobus_phy_device_register(struct mii_bus *md= io, int fwnode_mdiobus_register_phy(struct mii_bus *bus, struct fwnode_handle *child, u32 addr); =20 +int fwnode_mdiobus_register_device(struct mii_bus *mdio, + struct fwnode_handle *child, u32 addr); + int fwnode_phy_register_fixed_link(struct fwnode_handle *fwnode); =20 void fwnode_phy_deregister_fixed_link(struct fwnode_handle *fwnode); diff --git a/drivers/net/mdio/fwnode_mdio.c b/drivers/net/mdio/fwnode_mdio.c index 56f57381ae69..4d712d8873d0 100644 --- a/drivers/net/mdio/fwnode_mdio.c +++ b/drivers/net/mdio/fwnode_mdio.c @@ -187,6 +187,35 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, } EXPORT_SYMBOL(fwnode_mdiobus_register_phy); =20 +int fwnode_mdiobus_register_device(struct mii_bus *mdio, + struct fwnode_handle *child, u32 addr) +{ + struct mdio_device *mdiodev; + int rc; + + mdiodev =3D mdio_device_create(mdio, addr); + if (IS_ERR(mdiodev)) + return PTR_ERR(mdiodev); + + /* Associate the fwnode with the device structure so it + * can be looked up later. + */ + device_set_node(&mdiodev->dev, child); + + /* All data is now stored in the mdiodev struct; register it. */ + rc =3D mdio_device_register(mdiodev); + if (rc) { + device_set_node(&mdiodev->dev, NULL); + mdio_device_free(mdiodev); + return rc; + } + + dev_dbg(&mdio->dev, "registered mdio device %pfw at address %i\n", + child, addr); + return 0; +} +EXPORT_SYMBOL(fwnode_mdiobus_register_device); + /* * fwnode_phy_is_fixed_link() and fwnode_phy_register_fixed_link() must * support two bindings: diff --git a/drivers/net/mdio/of_mdio.c b/drivers/net/mdio/of_mdio.c index e6b3a4e251a1..685ac00f9dee 100644 --- a/drivers/net/mdio/of_mdio.c +++ b/drivers/net/mdio/of_mdio.c @@ -48,37 +48,6 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio, return fwnode_mdiobus_register_phy(mdio, of_fwnode_handle(child), addr); } =20 -static int of_mdiobus_register_device(struct mii_bus *mdio, - struct device_node *child, u32 addr) -{ - struct fwnode_handle *fwnode =3D of_fwnode_handle(child); - struct mdio_device *mdiodev; - int rc; - - mdiodev =3D mdio_device_create(mdio, addr); - if (IS_ERR(mdiodev)) - return PTR_ERR(mdiodev); - - /* Associate the OF node with the device structure so it - * can be looked up later. - */ - fwnode_handle_get(fwnode); - device_set_node(&mdiodev->dev, fwnode); - - /* All data is now stored in the mdiodev struct; register it. */ - rc =3D mdio_device_register(mdiodev); - if (rc) { - device_set_node(&mdiodev->dev, NULL); - fwnode_handle_put(fwnode); - mdio_device_free(mdiodev); - return rc; - } - - dev_dbg(&mdio->dev, "registered mdio device %pOFn at address %i\n", - child, addr); - return 0; -} - /* The following is a list of PHY compatible strings which appear in * some DTBs. The compatible string is never matched against a PHY * driver, so is pointless. We only expect devices which are not PHYs @@ -187,7 +156,7 @@ int of_mdiobus_register(struct mii_bus *mdio, struct de= vice_node *np) if (of_mdiobus_child_is_phy(child)) rc =3D of_mdiobus_register_phy(mdio, child, addr); else - rc =3D of_mdiobus_register_device(mdio, child, addr); + rc =3D fwnode_mdiobus_register_device(mdio, of_fwnode_handle(child), ad= dr); =20 if (rc =3D=3D -ENODEV) dev_err(&mdio->dev, --=20 2.29.0 From nobody Mon Sep 15 01:56:02 2025 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 DCA9EC46467 for ; Mon, 16 Jan 2023 17:53:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233521AbjAPRxw (ORCPT ); Mon, 16 Jan 2023 12:53:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234911AbjAPRwq (ORCPT ); Mon, 16 Jan 2023 12:52:46 -0500 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A3453B667 for ; Mon, 16 Jan 2023 09:35:08 -0800 (PST) Received: by mail-lf1-x130.google.com with SMTP id bf43so43673890lfb.6 for ; Mon, 16 Jan 2023 09:35:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/pYK289ULrgsf/Jk8COetz13qlDoBjNKsMyxX7loUDw=; b=pKr/SoBpM/X64xXxDigtMbtty8+VxmqTToE5Vgfyx5AgTZCZq/O/SbGt0/wX7GVCqH 8Y352t1YrUJsUC0U0+XZJAKlfgZ9tIzBMz22FPxzGHFBmoZDXFHDjmZSgfLN4TyNUx2r cXHZT/0j+ulQkHENMfQFdztFPN+A4US4owf0UHcYCJsGcJySYx9metSlSm7XqrrBHdt+ u6ICsAAbnmehCYG+qrRRkflgH1+EvK52yMd3UliLXV6qsGYsOV1GmJdkPHsl4Llphhs3 rerp1uohcvhhRwacpNEAMJnFT3aYJqyvlm9IqrgjtIu7vyd0gmBoPRo9jXPJtFr/hesM yPdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/pYK289ULrgsf/Jk8COetz13qlDoBjNKsMyxX7loUDw=; b=c6O47BpvTi3/uisCTuxzbpPSHjFczQC3MMEPB2FABvy6VnfKimh/s0SJ2n0UqDcu49 p0NyAZ49NUngfR/7iuDWc7o364l1/JvJpS+5iyVZl0wOrdhHtn0FqxIAdWjMZ59ugk4f rBfOSk3ge/rqzRdbAGA3nGEum2EwIHDzYyr6vhWDTL0mVYLPXar+9Xqk4czQ2NLP0pPY mor20Vn/jO+DzBBRRtViSmCIN0WIlXlJdPjSfbaUnZg9PYKUcuumWIY1i9QR7jV7zrz5 Mgzgu/ftG31GsxBgwB+VP03sBL6Rjvs/RZVF3bP8UulrSuEK4fwqXVA3CMWtKHf92Iq2 uFWw== X-Gm-Message-State: AFqh2kpmHEgUAcoJkSx1/3Bph9vvoFo0Ackiad+TqZq3rxtPmhF8NFlP Xwfl3XoBTEu6Qx2m1yzfD0Hr4Gv3+k3cdLtP X-Google-Smtp-Source: AMrXdXsKJwqskOP/by0HTMPg+FUXa81A0yDzLkE3gsr+Ks87ZDrAVUjBgQY8fXG4kCztFu/RTIIr8w== X-Received: by 2002:a19:f514:0:b0:4b5:61e8:8934 with SMTP id j20-20020a19f514000000b004b561e88934mr23683566lfb.64.1673890507730; Mon, 16 Jan 2023 09:35:07 -0800 (PST) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id k20-20020a2e8894000000b0028b7f51414fsm707333lji.80.2023.01.16.09.35.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Jan 2023 09:35:07 -0800 (PST) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, netdev@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@linux.intel.com, sean.wang@mediatek.com, Landen.Chao@mediatek.com, linus.walleij@linaro.org, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux@armlinux.org.uk, hkallweit1@gmail.com, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com, Samer.El-Haj-Mahmoud@arm.com Subject: [net-next: PATCH v4 8/8] net: dsa: mv88e6xxx: switch to device_/fwnode_ APIs Date: Mon, 16 Jan 2023 18:34:20 +0100 Message-Id: <20230116173420.1278704-9-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20230116173420.1278704-1-mw@semihalf.com> References: <20230116173420.1278704-1-mw@semihalf.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In order to support both DT and ACPI in future, modify the mv88e6xx driver code to use device_/fwnode_ equivalent routines. No functional change is introduced by this patch. Signed-off-by: Marcin Wojtas --- drivers/net/dsa/mv88e6xxx/chip.c | 41 +++++++++----------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/c= hip.c index 6731597bded0..1f1dd3dd4012 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -3932,10 +3932,11 @@ static int mv88e6xxx_mdio_write_c45(struct mii_bus = *bus, int phy, int devad, } =20 static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip, - struct device_node *np, + struct fwnode_handle *fwnode, bool external) { static int index; + struct device_node *np =3D to_of_node(fwnode); struct mv88e6xxx_mdio_bus *mdio_bus; struct mii_bus *bus; int err; @@ -4016,18 +4017,18 @@ static void mv88e6xxx_mdios_unregister(struct mv88e= 6xxx_chip *chip) } =20 static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip, - struct device_node *np) + struct fwnode_handle *fwnode) { - struct device_node *child; + struct fwnode_handle *child; int err; =20 /* Always register one mdio bus for the internal/default mdio * bus. This maybe represented in the device tree, but is * optional. */ - child =3D of_get_child_by_name(np, "mdio"); + child =3D fwnode_get_named_child_node(fwnode, "mdio"); err =3D mv88e6xxx_mdio_register(chip, child, false); - of_node_put(child); + fwnode_handle_put(child); if (err) return err; =20 @@ -4035,13 +4036,13 @@ static int mv88e6xxx_mdios_register(struct mv88e6xx= x_chip *chip, * which say they are compatible with the external mdio * bus. */ - for_each_available_child_of_node(np, child) { - if (of_device_is_compatible( - child, "marvell,mv88e6xxx-mdio-external")) { + fwnode_for_each_available_child_node(fwnode, child) { + if (fwnode_property_match_string(child, "compatible", + "marvell,mv88e6xxx-mdio-external") =3D=3D 0) { err =3D mv88e6xxx_mdio_register(chip, child, true); if (err) { mv88e6xxx_mdios_unregister(chip); - of_node_put(child); + fwnode_handle_put(child); return err; } } @@ -7096,18 +7097,14 @@ static int mv88e6xxx_probe(struct mdio_device *mdio= dev) struct dsa_mv88e6xxx_pdata *pdata =3D mdiodev->dev.platform_data; const struct mv88e6xxx_info *compat_info =3D NULL; struct device *dev =3D &mdiodev->dev; - struct device_node *np =3D dev->of_node; + struct fwnode_handle *fwnode =3D dev_fwnode(dev); struct mv88e6xxx_chip *chip; int port; int err; =20 - if (!np && !pdata) - return -EINVAL; - - if (np) - compat_info =3D of_device_get_match_data(dev); + compat_info =3D device_get_match_data(dev); =20 - if (pdata) { + if (!compat_info && pdata) { compat_info =3D pdata_device_get_match_data(dev); =20 if (!pdata->netdev) @@ -7164,9 +7161,9 @@ static int mv88e6xxx_probe(struct mdio_device *mdiode= v) mv88e6xxx_phy_init(chip); =20 if (chip->info->ops->get_eeprom) { - if (np) - of_property_read_u32(np, "eeprom-length", - &chip->eeprom_len); + if (fwnode) + device_property_read_u32(dev, "eeprom-length", + &chip->eeprom_len); else chip->eeprom_len =3D pdata->eeprom_len; } @@ -7177,8 +7174,8 @@ static int mv88e6xxx_probe(struct mdio_device *mdiode= v) if (err) goto out; =20 - if (np) { - chip->irq =3D of_irq_get(np, 0); + if (fwnode) { + chip->irq =3D fwnode_irq_get(fwnode, 0); if (chip->irq =3D=3D -EPROBE_DEFER) { err =3D chip->irq; goto out; @@ -7216,7 +7213,7 @@ static int mv88e6xxx_probe(struct mdio_device *mdiode= v) if (err) goto out_g1_atu_prob_irq; =20 - err =3D mv88e6xxx_mdios_register(chip, np); + err =3D mv88e6xxx_mdios_register(chip, fwnode); if (err) goto out_g1_vtu_prob_irq; =20 --=20 2.29.0