From nobody Wed Apr 15 04:32:57 2026 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 7D47CC04A68 for ; Wed, 27 Jul 2022 06:43:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229990AbiG0Gnv (ORCPT ); Wed, 27 Jul 2022 02:43:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229882AbiG0Gnn (ORCPT ); Wed, 27 Jul 2022 02:43:43 -0400 Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0F1C37FBC for ; Tue, 26 Jul 2022 23:43:41 -0700 (PDT) Received: by mail-lj1-x234.google.com with SMTP id e11so18787389ljl.4 for ; Tue, 26 Jul 2022 23:43:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cJn5eJrQBgo7tuywMv4Py5sc3iuwS0QcYqm0ShMZmnU=; b=KnxA90C523PXH75NDyqi2SpJTXCgXziLJQj51RiAra8BA3zLILBIkW7kMXtvY7KVCH lWrqBYwwgi9yEWM4wFJo/F3HoaLWLouFvJTq5BYE7KqbyS1/r8Cx3cmXwSMwwVzuSGGD BuSJGP9PAzlEyZphLGIIfz9SvWawvpQGhtgpxgJp+UL+JB5WKSTFq48dzeJssdjd1lDA zlpDtPXKLM3bRaJtxid1AzlMggIFCMckcDY5afbT8Tm37D53Q5LWuMDuc1NO87uifkfJ QLuVS1ih6jhC0S2sxh00U1G+q4f2RS4p5ZgSca9URyrnRiO1gJbh8Lev0MV3bXnspLKu aFzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cJn5eJrQBgo7tuywMv4Py5sc3iuwS0QcYqm0ShMZmnU=; b=UXXnwBUo2Tsk0Ig/XCyKcrqq6BefAL2B61eXpsTvzJPnelKqJe7ZuVQMWr8hcj6d8e P+D9CENk2q8MMpLr+73KVLyXq7lFCTZ2+XLW+HyxUIJB7wMfX5nQww/NEAXtzNNp313M bhxErj4K+D4EgzNjqlkagsuTK2GsMqNgee2fO50Np7+nGKw1LYjfIEwxgajFWnim5ii5 EIOlZroegUYLourOCcsr/iAQ3GZu5BWvDU3bwpSUbLAUQCygHZQRUhwmzv5YXiiWocKj Anp/0B4qV6K//fXXPzlbSKkhDEBUOH0hkl+YkpdKS8vWOD/wk2q/yxg5OQj8kbIEItJO Ja2Q== X-Gm-Message-State: AJIora+2R66I+01cJeK837dMIHOeHG+RALiYPhEBpyYjmuNkoFDbjlqY a71csIaNw8+jrQdWD4/cZWRno+JBE0a8xg== X-Google-Smtp-Source: AGRyM1vYUz1GhQ7qGNoIE2fR7VrH4ISlLslGzu1m/eJZZ89qmboUkipzw9u4TCMeqWdGyKa/ve2pHQ== X-Received: by 2002:a2e:a287:0:b0:25d:b515:430c with SMTP id k7-20020a2ea287000000b0025db515430cmr7383480lja.358.1658904219726; Tue, 26 Jul 2022 23:43:39 -0700 (PDT) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id w19-20020a05651234d300b0048a97a1df02sm1157231lfr.6.2022.07.26.23.43.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 23:43:39 -0700 (PDT) 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, gjb@semihalf.com, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com, Samer.El-Haj-Mahmoud@arm.com, upstream@semihalf.com Subject: [net-next: PATCH v3 1/8] net: phy: fixed_phy: switch to fwnode_ API Date: Wed, 27 Jul 2022 08:43:14 +0200 Message-Id: <20220727064321.2953971-2-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220727064321.2953971-1-mw@semihalf.com> References: <20220727064321.2953971-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" This patch allows 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 52bc8e487ef7..e3a03494f218 100644 --- a/include/linux/phy_fixed.h +++ b/include/linux/phy_fixed.h @@ -10,7 +10,7 @@ struct fixed_phy_status { int asym_pause; }; =20 -struct device_node; +struct fwnode_handle; struct gpio_desc; =20 #if IS_ENABLED(CONFIG_FIXED_PHY) @@ -19,7 +19,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, @@ -38,7 +38,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 9e3c815a070f..d755fe1ecdda 100644 --- a/drivers/net/mdio/of_mdio.c +++ b/drivers/net/mdio/of_mdio.c @@ -421,7 +421,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 Wed Apr 15 04:32:57 2026 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 7E975C04A68 for ; Wed, 27 Jul 2022 06:45:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230077AbiG0GpN (ORCPT ); Wed, 27 Jul 2022 02:45:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229926AbiG0Gnp (ORCPT ); Wed, 27 Jul 2022 02:43:45 -0400 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E5873C8F7 for ; Tue, 26 Jul 2022 23:43:43 -0700 (PDT) Received: by mail-lj1-x22a.google.com with SMTP id w18so7706363lje.1 for ; Tue, 26 Jul 2022 23:43:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1I6Xn/UXiMT6VknV/yDkGje3BjUktQ7ZyDrns9mPDHA=; b=VyV9z9XcHmSKY/u+3U+ob/ycFMUa7f5bUOn+KNNvQdUmPbbqJSVo6GNMx1l0c+WFVF nsz/45MckkVUmrrFwnK9eBECxxhD9pFmpG9rKsQq9M4napzTyi3nNFi/rElJr8Ve0NhZ lUdSmMDveFfx1ZdHDk8zIdBl+iyDgrgSlff/+vgWF/GSAnWAW209aAEtcmNjI2jpNh/+ OuPpiSSl9wbFVTGnqiVeHztIxD3Apr532L2PjVytPkwIZRGywgRn8yGtbG9vphpk45VY uFQC9aNJX8WGCS+1mZU4jMDykTy1IEno9mqhjMTkFq7Z0xxyT+WMG4CLaS6WqC1jAIm7 Lu0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1I6Xn/UXiMT6VknV/yDkGje3BjUktQ7ZyDrns9mPDHA=; b=jGwCB1H8S20+19o0PZLVvRNSRr0Aa+z5rYzkXXP8j2lyhUytLdtSL395IRlF1AGs6I KrPTuaSOCWEbeNP7q3SbPR/HaNCLxiC4ATYudqf+PYvF3QL/cgJYCJWdDNvIUnGoScL0 Lu8TUgTcWjw+erlijYMKfToyATVi8sfSQb+TCsdHKH/D46i6s+b60MvNNhZk7/xa1Gle 39H2JTiwzWpUuN0G9Pjhljq1Qn0NLQOlt4M6sMfM2LMPSrfScWrOFspmBMDH/hkxQfcm mwb614kymkYaqI64O4rdPOw30CEuDjNMz2V4tEjjHzjw62eMCPAuk8pHQzm8p9NeLmT5 7Qtg== X-Gm-Message-State: AJIora9+TTd9fCndqZtVvaICgK30ObeyrNHOgVReJoqdSHGvmLItj2r4 8LhxqcaUtfUVu8Vc25FeER2RfXK/sejrbg== X-Google-Smtp-Source: AGRyM1v2Jzg8MJOoV3C0xCVgg4McEUzad5WIKWRz1P+ChhkRcykn+p8NckVdHoYsFxms8sfYYTk0Bw== X-Received: by 2002:a2e:be90:0:b0:25e:1496:a0b8 with SMTP id a16-20020a2ebe90000000b0025e1496a0b8mr2264676ljr.194.1658904221266; Tue, 26 Jul 2022 23:43:41 -0700 (PDT) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id w19-20020a05651234d300b0048a97a1df02sm1157231lfr.6.2022.07.26.23.43.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 23:43:40 -0700 (PDT) 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, gjb@semihalf.com, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com, Samer.El-Haj-Mahmoud@arm.com, upstream@semihalf.com Subject: [net-next: PATCH v3 2/8] net: mdio: switch fixed-link PHYs API to fwnode_ Date: Wed, 27 Jul 2022 08:43:15 +0200 Message-Id: <20220727064321.2953971-3-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220727064321.2953971-1-mw@semihalf.com> References: <20220727064321.2953971-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 | 100 ++++++++++++++++++++ drivers/net/mdio/of_mdio.c | 79 +--------------- 3 files changed, 122 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 1c1584fca632..454fdae24150 100644 --- a/drivers/net/mdio/fwnode_mdio.c +++ b/drivers/net/mdio/fwnode_mdio.c @@ -10,6 +10,7 @@ #include #include #include +#include =20 MODULE_AUTHOR("Calvin Johnson "); MODULE_LICENSE("GPL"); @@ -147,3 +148,102 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, return 0; } 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; + int len; + + /* 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 */ + len =3D fwnode_property_count_u32(fwnode, "fixed-link"); + if (len =3D=3D 5) + return true; + + return false; +} +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; + + 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"); + if (fwnode_property_read_u32(fixed_link_node, "speed", + &status.speed)) { + fwnode_handle_put(fixed_link_node); + return -EINVAL; + } + 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 */ + if (fwnode_property_read_u32_array(fwnode, "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, 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 d755fe1ecdda..409da6e92f7d 100644 --- a/drivers/net/mdio/of_mdio.c +++ b/drivers/net/mdio/of_mdio.c @@ -351,91 +351,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 Wed Apr 15 04:32:57 2026 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 A60A4C04A68 for ; Wed, 27 Jul 2022 06:44:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230165AbiG0Gok (ORCPT ); Wed, 27 Jul 2022 02:44:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229951AbiG0Gnw (ORCPT ); Wed, 27 Jul 2022 02:43:52 -0400 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD2C9371B3 for ; Tue, 26 Jul 2022 23:43:44 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id t1so25717722lft.8 for ; Tue, 26 Jul 2022 23:43:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LCYfkQYBVUz+N80duT8GehXeSbCMzuDkINreOMolbEg=; b=jIkc5ADh2NQaFz9xfHLydQdc2SLuHpwUDaPsVGK03uL66OFTjgVquWkw39KdPdmmPF 3miZ36H8ojRxBYf+f7bAl47AahCDwK2LI3HjXx0Z8Jum2qXx+HAU0WfDiuTy1h/smJz5 Pm8Qjic8o+yXVCyw6laqxGY+i2wACbOCtG9ClMVSuwHC5NYQl4PYlu3k4tAsVakJ4FTm /4qjVOQeR5EyhaOJx8N41DTfhgnW1MOfgHbY10vikTEME+C8Azci8gjmvaXSB2xh8f1W hABhi54TbK05s9LZFkUKawkP/3HxnAGIbaTUPaQcr6yZqH5c5ZC+jfKivsx1Q4I9g3hl 0/VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LCYfkQYBVUz+N80duT8GehXeSbCMzuDkINreOMolbEg=; b=rnEnYff+ceBnsDTV2p6DEqEdWr/VnExYt3Gg2Pn/pM8FAeyaNCpp//ggQ7OeSD17Mz jnc6f+aP6Utz2EgL2iK/t48PqEGY93JlnRqEhGonbuBTpz1Acnj+EiswtpQJrG12mPko ndDTTBZ1YkCrUBPHhgN3fxecSWS4OcunHvIq/CdBvI2IMX63uHENT+BRHxbQPiUMIx/y HV1syXVAHNLIAlPUQHxo4vrvPumSc14Hi58SFzyCaSMEZG7rhv3Vg7IEgMLvzhT87WQz cGhDhrbKthiiFfTxj/hMnbHoy8cGHXbx/s4U422dGmpje3iNEXTcIQdYnmRUQY5Uq9gN HrTA== X-Gm-Message-State: AJIora9sAIUOUfXRkrFDPwNTZ86IMIqEzLqygXp2X+WNpUPe/fzmuYJ5 BzupV/pGY9Ao1h9sVWUlKb1WTZ87cunOtQ== X-Google-Smtp-Source: AGRyM1v75qA+ISRsWkPw1KmxR25Z9t+gjZ+afAk5jSOgr/4F0bz4ZmaWu9ZTfRZhNyJw0OCwSzia/Q== X-Received: by 2002:a19:674a:0:b0:47f:863d:5bc2 with SMTP id e10-20020a19674a000000b0047f863d5bc2mr7452792lfj.92.1658904222856; Tue, 26 Jul 2022 23:43:42 -0700 (PDT) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id w19-20020a05651234d300b0048a97a1df02sm1157231lfr.6.2022.07.26.23.43.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 23:43:42 -0700 (PDT) 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, gjb@semihalf.com, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com, Samer.El-Haj-Mahmoud@arm.com, upstream@semihalf.com Subject: [net-next: PATCH v3 3/8] net: dsa: switch to device_/fwnode_ APIs Date: Wed, 27 Jul 2022 08:43:16 +0200 Message-Id: <20220727064321.2953971-4-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220727064321.2953971-1-mw@semihalf.com> References: <20220727064321.2953971-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/dsa_priv.h | 4 +- drivers/net/dsa/mt7530.c | 6 +- drivers/net/dsa/mv88e6xxx/chip.c | 14 +-- drivers/net/dsa/qca/qca8k.c | 2 +- drivers/net/dsa/realtek/rtl8365mb.c | 2 +- net/dsa/dsa2.c | 100 +++++++++++--------- net/dsa/port.c | 68 +++++++------ net/dsa/slave.c | 7 +- 9 files changed, 103 insertions(+), 102 deletions(-) diff --git a/include/net/dsa.h b/include/net/dsa.h index b902b31bebce..0a328c0073ec 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -302,7 +302,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/dsa_priv.h b/net/dsa/dsa_priv.h index d9722e49864b..2c0034a915ee 100644 --- a/net/dsa/dsa_priv.h +++ b/net/dsa/dsa_priv.h @@ -285,8 +285,8 @@ int dsa_port_mrp_add_ring_role(const struct dsa_port *d= p, int dsa_port_mrp_del_ring_role(const struct dsa_port *dp, const struct switchdev_obj_ring_role_mrp *mrp); int dsa_port_phylink_create(struct dsa_port *dp); -int dsa_port_link_register_of(struct dsa_port *dp); -void dsa_port_link_unregister_of(struct dsa_port *dp); +int dsa_port_link_register_fw(struct dsa_port *dp); +void dsa_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 835807911be0..427b66342493 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -2109,8 +2109,8 @@ mt7530_setup(struct dsa_switch *ds) struct device_node *phy_node; struct device_node *mac_np; struct mt7530_dummy_poll p; - phy_interface_t interface; struct dsa_port *cpu_dp; + int interface; u32 id, val; int ret, i; =20 @@ -2232,8 +2232,8 @@ 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) + interface =3D fwnode_get_phy_mode(dsa_to_port(ds, 5)->fwnode); + if (interface < 0) 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 07e9a4da924c..a46ebdfba1c3 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -3275,7 +3275,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; @@ -3499,15 +3499,15 @@ 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 (!IS_ERR(phy_handle) && !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 (!IS_ERR(phy_handle)) { + fwnode_handle_put(phy_handle); if (err) return err; } diff --git a/drivers/net/dsa/qca/qca8k.c b/drivers/net/dsa/qca/qca8k.c index 1cbb05b0323f..77b14ade0828 100644 --- a/drivers/net/dsa/qca/qca8k.c +++ b/drivers/net/dsa/qca/qca8k.c @@ -1517,7 +1517,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/dsa2.c b/net/dsa/dsa2.c index cac48a741f27..82fb3b009fb4 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -296,12 +296,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; @@ -337,14 +337,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; @@ -469,7 +468,7 @@ static int dsa_port_setup(struct dsa_port *dp) dsa_port_disable(dp); break; case DSA_PORT_TYPE_CPU: - err =3D dsa_port_link_register_of(dp); + err =3D dsa_port_link_register_fw(dp); if (err) break; dsa_port_link_registered =3D true; @@ -481,7 +480,7 @@ static int dsa_port_setup(struct dsa_port *dp) =20 break; case DSA_PORT_TYPE_DSA: - err =3D dsa_port_link_register_of(dp); + err =3D dsa_port_link_register_fw(dp); if (err) break; dsa_port_link_registered =3D true; @@ -493,7 +492,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); if (err) break; @@ -505,7 +504,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_port_link_unregister_of(dp); + dsa_port_link_unregister_fw(dp); if (err) { if (ds->ops->port_teardown) ds->ops->port_teardown(ds, dp->index); @@ -577,11 +576,11 @@ static void dsa_port_teardown(struct dsa_port *dp) break; case DSA_PORT_TYPE_CPU: dsa_port_disable(dp); - dsa_port_link_unregister_of(dp); + dsa_port_link_unregister_fw(dp); break; case DSA_PORT_TYPE_DSA: dsa_port_disable(dp); - dsa_port_link_unregister_of(dp); + dsa_port_link_unregister_fw(dp); break; case DSA_PORT_TYPE_USER: if (dp->slave) { @@ -853,7 +852,7 @@ static int dsa_switch_setup_tag_protocol(struct dsa_swi= tch *ds) static int dsa_switch_setup(struct dsa_switch *ds) { struct dsa_devlink_priv *dl_priv; - struct device_node *dn; + struct fwnode_handle *fwnode; struct dsa_port *dp; int err; =20 @@ -909,10 +908,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; } @@ -1482,24 +1481,33 @@ 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; + + ret =3D fwnode_property_read_string(fwnode, "label", &name); + if (ret) + return ret; =20 - dp->dn =3D dn; + dp->fwnode =3D fwnode; =20 - if (ethernet) { + 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 @@ -1509,61 +1517,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 @@ -1600,11 +1608,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 @@ -1612,7 +1620,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 dsa_port_parse(struct dsa_port *dp, const char *name, @@ -1705,20 +1713,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 2dd76eb1621c..40c7d1d9b488 100644 --- a/net/dsa/port.c +++ b/net/dsa/port.c @@ -6,10 +6,9 @@ * Vivien Didelot */ =20 +#include #include #include -#include -#include =20 #include "dsa_priv.h" =20 @@ -1380,20 +1379,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 @@ -1525,11 +1524,10 @@ 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; - 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 @@ -1542,7 +1540,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 - dp->pl =3D phylink_create(&dp->pl_config, of_fwnode_handle(dp->dn), + dp->pl =3D phylink_create(&dp->pl_config, dp->fwnode, mode, &dsa_port_phylink_mac_ops); if (IS_ERR(dp->pl)) { pr_err("error creating PHYLINK: %ld\n", PTR_ERR(dp->pl)); @@ -1552,7 +1550,7 @@ int dsa_port_phylink_create(struct dsa_port *dp) return 0; } =20 -static int dsa_port_setup_phy_of(struct dsa_port *dp, bool enable) +static int dsa_port_setup_phy_fw(struct dsa_port *dp, bool enable) { struct dsa_switch *ds =3D dp->ds; struct phy_device *phydev; @@ -1590,16 +1588,15 @@ static int dsa_port_setup_phy_of(struct dsa_port *d= p, bool enable) return err; } =20 -static int dsa_port_fixed_link_register_of(struct dsa_port *dp) +static int dsa_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", @@ -1607,10 +1604,10 @@ static int dsa_port_fixed_link_register_of(struct d= sa_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 @@ -1627,7 +1624,6 @@ static int dsa_port_fixed_link_register_of(struct dsa= _port *dp) static int dsa_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; @@ -1637,7 +1633,7 @@ static int dsa_port_phylink_register(struct dsa_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; @@ -1650,35 +1646,35 @@ static int dsa_port_phylink_register(struct dsa_por= t *dp) return err; } =20 -int dsa_port_link_register_of(struct dsa_port *dp) +int dsa_port_link_register_fw(struct dsa_port *dp) { + struct fwnode_handle *phy_handle; struct dsa_switch *ds =3D dp->ds; - struct device_node *phy_np; int port =3D dp->index; =20 if (!ds->ops->adjust_link) { - phy_np =3D of_parse_phandle(dp->dn, "phy-handle", 0); - if (of_phy_is_fixed_link(dp->dn) || phy_np) { + phy_handle =3D fwnode_find_reference(dp->fwnode, "phy-handle", 0); + if (fwnode_phy_is_fixed_link(dp->fwnode) || !IS_ERR(phy_handle)) { if (ds->ops->phylink_mac_link_down) ds->ops->phylink_mac_link_down(ds, port, MLO_AN_FIXED, PHY_INTERFACE_MODE_NA); - of_node_put(phy_np); + fwnode_handle_put(dp->fwnode); return dsa_port_phylink_register(dp); } - of_node_put(phy_np); + fwnode_handle_put(dp->fwnode); return 0; } =20 dev_warn(ds->dev, "Using legacy PHYLIB callbacks. Please migrate to PHYLINK!\n"); =20 - if (of_phy_is_fixed_link(dp->dn)) - return dsa_port_fixed_link_register_of(dp); + if (fwnode_phy_is_fixed_link(dp->fwnode)) + return dsa_port_fixed_link_register_fw(dp); else - return dsa_port_setup_phy_of(dp, true); + return dsa_port_setup_phy_fw(dp, true); } =20 -void dsa_port_link_unregister_of(struct dsa_port *dp) +void dsa_port_link_unregister_fw(struct dsa_port *dp) { struct dsa_switch *ds =3D dp->ds; =20 @@ -1691,10 +1687,10 @@ void dsa_port_link_unregister_of(struct dsa_port *d= p) 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_port_setup_phy_of(dp, false); + dsa_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 ad6a6663feeb..209e24cb1477 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -10,8 +10,6 @@ #include #include #include -#include -#include #include #include #include @@ -2228,7 +2226,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; @@ -2252,7 +2249,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 @@ -2364,7 +2361,7 @@ int dsa_slave_create(struct dsa_port *port) SET_NETDEV_DEVTYPE(slave_dev, &dsa_type); =20 SET_NETDEV_DEV(slave_dev, port->ds->dev); - 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 Wed Apr 15 04:32:57 2026 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 A16CEC19F2C for ; Wed, 27 Jul 2022 06:44:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230025AbiG0Gog (ORCPT ); Wed, 27 Jul 2022 02:44:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230041AbiG0GoJ (ORCPT ); Wed, 27 Jul 2022 02:44:09 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A4CA40BCE for ; Tue, 26 Jul 2022 23:43:46 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id bf9so25649474lfb.13 for ; Tue, 26 Jul 2022 23:43:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+d/aojT1TCgagMDA6o2QljnvpRxpeI/WOeBAtluw3O0=; b=KgE76jCoQUSTM3acGvNgdioxOEkcwqT3ATxQ/UKzncXpzHm99rgdQcDERpI7r0DfFz +kuBVu/gqktgjLZuKQpqo/2Dcsy3A/EbG4tmCU7vt1sShG6wE+bzGY7TwcJNFGCDzK0o 9Byu/2RBM6kvb6w4suTzpCgxsv7cq7icKIz6y8yeCHzuM3qVjxrcIBl31wKX7RkywxI9 nV1g914DXiCqEsTlKfNgLX1z6BmmnRP6qquAFA4vtuMwWQfeRBAPG975EnFuppbFuFuA M9enYRdLjp4FUaDYzrM6y1LuZp+h/IgPdOSmE11tyligi2Ud46aPuEDcjwnpRwhkl+Dy evlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+d/aojT1TCgagMDA6o2QljnvpRxpeI/WOeBAtluw3O0=; b=GTipLsFA9aIvEjbZn6nz1a3DHXlELMHOpXc9ks6B/MiQqSVufUp95AkPo3ueWworWU eI693lweFxVL6EjC6o0zZGY6bRuCqRBXsMQf6Dz8YEkCVxWrDiSme29bkQv3EZ4ugO6p HaT2XvwIwlNFTHUZcIAjdgt7lvXStxocAWb9cFYwA8HmzSRJdYAowCdW4TPySQXY3xxo 4av0n2RjHRvYLhB6S3IX1/HvQzb/dEqHCbOfBZqI8o2hkYa0CX2bM55kUO16OTeQ85qx bvhydvH42S7YKYt205riDFrUKX0691xrHJLO88J4KFe5hmkXTi91PBK5V8p4JLDslJD8 rPFA== X-Gm-Message-State: AJIora9j5yswX9wupoaC2pc40s3QnL6MfLSSuHvNls0kJvUqviG8EnwG gfRsHKPsjzOV40n/rqDY5L+P/9H3MCcrqg== X-Google-Smtp-Source: AGRyM1stenOwsAHzzcXaa1c51ami5gL6ZJn0lL6L3V+GXYFnR39RX0SCospuWmnJUC7p/bKt+S155A== X-Received: by 2002:ac2:456c:0:b0:48a:8c7f:e332 with SMTP id k12-20020ac2456c000000b0048a8c7fe332mr4788547lfm.410.1658904224554; Tue, 26 Jul 2022 23:43:44 -0700 (PDT) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id w19-20020a05651234d300b0048a97a1df02sm1157231lfr.6.2022.07.26.23.43.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 23:43:43 -0700 (PDT) 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, gjb@semihalf.com, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com, Samer.El-Haj-Mahmoud@arm.com, upstream@semihalf.com Subject: [net-next: PATCH v3 4/8] net: mvpp2: initialize port fwnode pointer Date: Wed, 27 Jul 2022 08:43:17 +0200 Message-Id: <20220727064321.2953971-5-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220727064321.2953971-1-mw@semihalf.com> References: <20220727064321.2953971-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, the port's device structure should be updated with its fwnode pointer, similarly to of_node - see analogous commit c4053ef32208 ("net: mvpp2: initialize port of_node pointer"). This patch is required to prevent a regression before updating the DSA API on boards that connect the mvpp2 port to switch, such as Clearfog GT-8K or CN913x CEx7 Evaluation Board. Signed-off-by: Marcin Wojtas --- 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 b84128b549b4..03d5ff649c47 100644 --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c @@ -6868,7 +6868,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 Wed Apr 15 04:32:57 2026 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 BA203C19F29 for ; Wed, 27 Jul 2022 06:45:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230378AbiG0GpI (ORCPT ); Wed, 27 Jul 2022 02:45:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230057AbiG0GoJ (ORCPT ); Wed, 27 Jul 2022 02:44:09 -0400 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D10D40BF9 for ; Tue, 26 Jul 2022 23:43:48 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id d17so23661884lfa.12 for ; Tue, 26 Jul 2022 23:43:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AZnXgTWAmHAAkiH1J3eS3SuupS7jjAspolqgIKE9W3w=; b=If2TkJ8pMmsyfyfVuwa7SGbtltDAMjKUSVBgzQ482CqXgjwCPUCroLSM7qOdjNGVBM TNPjT8ZkVwGNKL8KCbhck1+9MDMX3E+ZB9bZ8Ln7FDo9IGAf+bVsd8o9PoPr32469aVn Cm/v5Ya0yA901PbzfwGPaBZu1hX69UpO9iriYZ+vuUP1/N2EQZDVthkd/lZz6qmy7kdC 9ipfZGbD+lPMZJHPkZzgG9NW9Kp8WjNVjbtxD6hE8Ydrdg8lJ/ykf2UZWKlRb20T0ygH jsYPNiKVscbNdWaUugzaY1V4gawVPKOtbCC8ivNzlCzf4g6mZFqhTvWM/gttpgL4BB9Q 10tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AZnXgTWAmHAAkiH1J3eS3SuupS7jjAspolqgIKE9W3w=; b=3gvmTiKjX9f8/4ONfxMuUW2YoZuQPqC5h2RoUVvu+1e8WwB6Oa8c6+wamg07F5lae2 x3SQTnBMtZaDyHDDZ4WcLnehKJ6ch37T66kwxXHJe3HMhQHsagJSHd/KrRNyCcFdt/gl ZruSdlYBvwmzP2649bOU9dUOESxwxHH4SLjlu+TB5s7XUMHLLBgboN4HSraIhfj6R1+O zC+/FfRSQlhkDCckHOxLwj6ZeRf0owCmulWspnVkrYXd6jqJXI8wiFv65tWyPmQoZJkZ NI0yJef+w4CDA5NS1j01S3RN4oO+1wx0P8CtYwaFXyE4BGkWCGJCguod5wR9x5QmsBdo SP6A== X-Gm-Message-State: AJIora8vZiEmbPq6jI9T+8Ry38vuIaOG6/rU6fvslm6Qg/G1K+jzRMGL kbq7v8fc0rQ8wO/nXq3LtxKEccTSV5QqbQ== X-Google-Smtp-Source: AGRyM1ulVcNyJ4rwZ+4mPHuX4JlRF3Mn/mt8yKy6C/OG/KII/LeRx1Z9arhrE35NZl54VBFs1Azx0g== X-Received: by 2002:a05:6512:602:b0:48a:8278:52da with SMTP id b2-20020a056512060200b0048a827852damr6096896lfe.257.1658904226137; Tue, 26 Jul 2022 23:43:46 -0700 (PDT) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id w19-20020a05651234d300b0048a97a1df02sm1157231lfr.6.2022.07.26.23.43.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 23:43:45 -0700 (PDT) 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, gjb@semihalf.com, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com, Samer.El-Haj-Mahmoud@arm.com, upstream@semihalf.com Subject: [net-next: PATCH v3 5/8] device property: introduce fwnode_find_parent_dev_match Date: Wed, 27 Jul 2022 08:43:18 +0200 Message-Id: <20220727064321.2953971-6-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220727064321.2953971-1-mw@semihalf.com> References: <20220727064321.2953971-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" This patch adds 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 --- 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 a5b429d623f6..829254a5ae63 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -95,6 +95,7 @@ struct device *fwnode_get_next_parent_dev(struct fwnode_h= andle *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 ed6f449f8e5c..ee6a8144f103 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -685,6 +685,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 Wed Apr 15 04:32:57 2026 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 E8AE7C3F6B0 for ; Wed, 27 Jul 2022 06:44:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229908AbiG0Goo (ORCPT ); Wed, 27 Jul 2022 02:44:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230079AbiG0GoL (ORCPT ); Wed, 27 Jul 2022 02:44:11 -0400 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4FE641995 for ; Tue, 26 Jul 2022 23:43:49 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id a23so23392869lfm.10 for ; Tue, 26 Jul 2022 23:43:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9YzF/moGV0ykdIvPXLa6CisfKYdf2yrfdtDijEUJPuI=; b=kZw2qp1fqzn/11TXztXmeboNZn+S/94NltYlqBuJzWhuN6PSawQ6kygf2qfhUEuxOn jZ39zJQCcC/KfT0/sLA8dxxzyKDDuSnxT3E4ycdOqRPKrBd+wPVSjvD4FpJ/UaYtUzfN jyD1IG61jopdRT5jfxqPJFi+zGSv0t8R0IH/YKCfNn4rGlagjYqJ9mtEHvAX/qHRAvmG LvLYTYAnJRZrviGu+JwpmjH+EQkZeBlKqEayJcfGMIg/A8DlRizFnt1BrvC+x5JaNsh/ bkS+08klYM8jOOCQfUQbi98cIG3foD7iYgmWNOQXVSU0N7NmuPFTDHsvCniJAETgzTcA 89Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9YzF/moGV0ykdIvPXLa6CisfKYdf2yrfdtDijEUJPuI=; b=XrqhPDx6IS9E46Ttv4q1NK8DYFTDkGJTJx0tV9vJtBfLnBCSOsZ7BWpPRPrZEDLFXv qiDth3bP4U46Kvc5n/0p11jHnrPe50z1WFr4P4KOkD5GFLXFef5D6y8CXSKh/OmQ+9h6 vInDbY0KCR6cocLwMqvYDFb0vMD6O1Ray62qEz4t31DTyNEe856YsABsDFS8td4K7d76 A54vJRs40aLC46e/iMMSMTsADCoXAzc/pCB5GVNE50olTKGJ72Hc+PcJebCB9Xid615G wjYUbVhLtMOL21XYRve1+QYHl1IoRtCcuqEPhQ4rZIFVjfx1IL56gBANA/cZ5kKmdfvI 9ZKQ== X-Gm-Message-State: AJIora9pUMoDS5wr0sgKnhOOkwKJCeNO5v5e0x4NOjo/pKaT35dGkDZt qU7J3dBfdknVy7xoExQIf3sg0npsCuV1iw== X-Google-Smtp-Source: AGRyM1tTz/84Id/kCPHS/5up9fpPurIKbeeCVAo2XxHNrBTI9XHmL66WhjTosvTu54j7SvnhOBkQeg== X-Received: by 2002:a05:6512:39c8:b0:48a:7816:1f7f with SMTP id k8-20020a05651239c800b0048a78161f7fmr7251843lfu.571.1658904227638; Tue, 26 Jul 2022 23:43:47 -0700 (PDT) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id w19-20020a05651234d300b0048a97a1df02sm1157231lfr.6.2022.07.26.23.43.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 23:43:47 -0700 (PDT) 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, gjb@semihalf.com, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com, Samer.El-Haj-Mahmoud@arm.com, upstream@semihalf.com Subject: [net-next: PATCH v3 6/8] net: core: switch to fwnode_find_net_device_by_node() Date: Wed, 27 Jul 2022 08:43:19 +0200 Message-Id: <20220727064321.2953971-7-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220727064321.2953971-1-mw@semihalf.com> References: <20220727064321.2953971-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 DSA subsystem. For that purpose use newly added fwnode_dev_node_match helper 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/dsa2.c | 3 ++- 4 files changed, 10 insertions(+), 25 deletions(-) diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h index 92b10e67d5f8..a335775af244 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 0484b613ca64..f672f831292d 100644 --- a/include/linux/of_net.h +++ b/include/linux/of_net.h @@ -15,7 +15,6 @@ struct net_device; extern int of_get_phy_mode(struct device_node *np, phy_interface_t *interf= ace); extern int of_get_mac_address(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) @@ -32,11 +31,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 d61afd21aab5..fc972545aaea 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/dsa2.c b/net/dsa/dsa2.c index 82fb3b009fb4..bba416eba9c2 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -7,6 +7,7 @@ */ =20 #include +#include #include #include #include @@ -1498,7 +1499,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 Wed Apr 15 04:32:57 2026 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 EFBFEC04A68 for ; Wed, 27 Jul 2022 06:45:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231223AbiG0GpT (ORCPT ); Wed, 27 Jul 2022 02:45:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230107AbiG0GoL (ORCPT ); Wed, 27 Jul 2022 02:44:11 -0400 Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 294A4419AC for ; Tue, 26 Jul 2022 23:43:51 -0700 (PDT) Received: by mail-lj1-x234.google.com with SMTP id a13so18596068ljr.11 for ; Tue, 26 Jul 2022 23:43:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2odXpn4NqvflBREYUYmO1+1RxmW+GuL0cfDw3Dw0WVQ=; b=M5LVaRcVeMUdyxjTy9X4a749CDwTC2L+S1rGrABeAnCVmMLXlZUhhSAGPfNkGkJs8+ JQjk61NYK23w4PK9C0W4lFUDAlxAihIBcBlh5KFv0vIjI+zlcJ46UWwxoD0XeXTBsEfr myKPItxzYkFMNKpkcL0ZAjkHPWipe+wWSeEH1gOtGAOvMwo+UOQufTqB4HB+R8e8s9NO KStZG2zKWuyt6NYOGbHGPOOIVDtWccQdJ6HoEv57uZVC2DzZfmcc4GBuAjSVO2EBPEgA zjCxb3hQevi+8G8WdEd0TejJz+EX0kRTiWQHwaNlNeuWmuTtPK+kFS5NWo5mwKzC3g3p Lrjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2odXpn4NqvflBREYUYmO1+1RxmW+GuL0cfDw3Dw0WVQ=; b=nYuqwcZ3hyjwmMMwDucQlYxuF6o56DXRJH8L7S1p+7xTvSBN/KjFOosDOVkMRB+74V n/BR1tDS+X7KKlxxtl2eW2MLzC58WJ0smyz3q0X3Gp2OaIiwKJUUL7aT4q9tYqNcjAYK 9oNsB0//Hysgl2IADLD5YfjywY8HvlXyxGlK3oaASP0jHnnvCl91ug126Vgz4ElFyU2i 6onjbSuERrW0ls2xPnOW5IlfXJjqEbvsyGB1uF87F0eX857TzgBiM51kfRHizCG8jETn pxBNVVJsI7COdWoTkvk30hMkqK95Baufnmwj9eHVOSZ6wg27sykQG990qpiAYLPNxehp k/6g== X-Gm-Message-State: AJIora/MawhFbft2lp1Y12SA/Me5Yx5l/YnqPp6gaJ8IlchBlRaB7hJx iTsIbCwhPYRri/UbnWGCs7LgLkUcq5eVqA== X-Google-Smtp-Source: AGRyM1v9ZHWvAdoM5hxEHP3+vt59f9C0lTTPauONXgBFyLTQhLSEZgKMsfzvVEnMO3r5sBQvh/at2Q== X-Received: by 2002:a2e:93c8:0:b0:24d:b348:b070 with SMTP id p8-20020a2e93c8000000b0024db348b070mr7445132ljh.434.1658904229157; Tue, 26 Jul 2022 23:43:49 -0700 (PDT) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id w19-20020a05651234d300b0048a97a1df02sm1157231lfr.6.2022.07.26.23.43.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 23:43:48 -0700 (PDT) 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, gjb@semihalf.com, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com, Samer.El-Haj-Mahmoud@arm.com, upstream@semihalf.com Subject: [net-next: PATCH v3 7/8] net: mdio: introduce fwnode_mdiobus_register_device() Date: Wed, 27 Jul 2022 08:43:20 +0200 Message-Id: <20220727064321.2953971-8-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220727064321.2953971-1-mw@semihalf.com> References: <20220727064321.2953971-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 | 32 +------------------- 3 files changed, 33 insertions(+), 31 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 454fdae24150..3743f34e7c2d 100644 --- a/drivers/net/mdio/fwnode_mdio.c +++ b/drivers/net/mdio/fwnode_mdio.c @@ -149,6 +149,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) { + mdio_device_free(mdiodev); + fwnode_handle_put(child); + return rc; + } + + dev_dbg(&mdio->dev, "registered mdio device %p fwnode 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 409da6e92f7d..bd941da030bb 100644 --- a/drivers/net/mdio/of_mdio.c +++ b/drivers/net/mdio/of_mdio.c @@ -48,36 +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) { - mdio_device_free(mdiodev); - of_node_put(child); - 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 @@ -186,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 Wed Apr 15 04:32:57 2026 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 B5E7BC19F29 for ; Wed, 27 Jul 2022 06:44:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230250AbiG0Got (ORCPT ); Wed, 27 Jul 2022 02:44:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230128AbiG0GoL (ORCPT ); Wed, 27 Jul 2022 02:44:11 -0400 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25413419A9 for ; Tue, 26 Jul 2022 23:43:51 -0700 (PDT) Received: by mail-lj1-x233.google.com with SMTP id r14so18770099ljp.2 for ; Tue, 26 Jul 2022 23:43:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KjpPOw/EHkdGMlNJx96x3tiCm2I3MhnvsH5Bdl+D29E=; b=eaw0CSRmVCkatxLGZl8bUwnuKZqXHQmUWTrF+8ClFW+gQ+9nkwgzFmxXSTo0VK0RbC aV4dIUCd2t5RH2ECwdVSLNJydWtb7HpjuulvoE7z2UM/j0gCGG++g9KYh2JHI0GNLWBj S6HgOpQZcWXfE7pE1QQVqYk54vEerMk55ek4xUXekKIiojkJBeMT86Fe3eDNe18qyb2g 5TsYchAHEV4HtRX37aQd78d4S5JfwXXH9afyAP+BUzdGemP/K60BZ1wEY1bpyqq9c4Ht M8xbVByvmTcxrdO+Oo1Azy12WA8R3tnv5BnEG6VHhQ6u9zozukNlYH6wfjlRJI618HAe ePQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KjpPOw/EHkdGMlNJx96x3tiCm2I3MhnvsH5Bdl+D29E=; b=jev7dlWhVQVy8YvCPXwX1mB7d/QFosj1sYD71sQzvA4KxKDH3yWhkGZwL82GfIu6Ks YPwoJfeg8HR+afyoJIKh4gkZ3E3ABBu76z7pWcDBYSdpWsWC2ErQdxVKWlPFDwAIhPnX 0NkTY4rAi/jnfZrdUeXgIsazhZEeqUN55aVnx4s58dathY/uoQU7asycQjXj4Ny4arLm FVChFT+4qO89wkAYLQfjriCvpxDldl8wvZGa5J6VBy9vCFdaWjiguTkv8HR3wKRnxgll 6L0hPyyYIYjoSyiPTuQLgXyfMhp6qDEoeSPqSjeeHLAqilw4k6dXLjhlYMOVhvjtNk92 RzTg== X-Gm-Message-State: AJIora/ckXyycLIUffs7lZWcTJAMhyf4ZLIkkQRfrDODEoEZWWWfTpL6 f9HYKiDhSRVfClEoiE+r32gF7VyducNZWg== X-Google-Smtp-Source: AGRyM1s0sRFTSUqI9uwyloFsy7TMvBWrfyPieQcx1tIMUxMjzvRQhRmhkmi48m6OKXIMRsCJE25Y6Q== X-Received: by 2002:a2e:9cd8:0:b0:25e:ec:237c with SMTP id g24-20020a2e9cd8000000b0025e00ec237cmr5283663ljj.277.1658904230528; Tue, 26 Jul 2022 23:43:50 -0700 (PDT) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id w19-20020a05651234d300b0048a97a1df02sm1157231lfr.6.2022.07.26.23.43.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 23:43:50 -0700 (PDT) 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, gjb@semihalf.com, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com, Samer.El-Haj-Mahmoud@arm.com, upstream@semihalf.com Subject: [net-next: PATCH v3 8/8] net: dsa: mv88e6xxx: switch to device_/fwnode_ APIs Date: Wed, 27 Jul 2022 08:43:21 +0200 Message-Id: <20220727064321.2953971-9-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220727064321.2953971-1-mw@semihalf.com> References: <20220727064321.2953971-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 | 43 +++++++++----------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/c= hip.c index a46ebdfba1c3..e7848b56316f 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -3891,10 +3891,11 @@ static int mv88e6xxx_mdio_write(struct mii_bus *bus= , int phy, int reg, u16 val) } =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; @@ -3973,18 +3974,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 @@ -3992,13 +3993,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; } } @@ -6984,20 +6985,16 @@ static SIMPLE_DEV_PM_OPS(mv88e6xxx_pm_ops, mv88e6xx= x_suspend, mv88e6xxx_resume); static int mv88e6xxx_probe(struct mdio_device *mdiodev) { struct dsa_mv88e6xxx_pdata *pdata =3D mdiodev->dev.platform_data; + struct fwnode_handle *fwnode =3D dev_fwnode(&mdiodev->dev); const struct mv88e6xxx_info *compat_info =3D NULL; struct device *dev =3D &mdiodev->dev; - struct device_node *np =3D dev->of_node; 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); - - if (pdata) { + if (fwnode) + compat_info =3D device_get_match_data(dev); + else if (pdata) { compat_info =3D pdata_device_get_match_data(dev); =20 if (!pdata->netdev) @@ -7054,9 +7051,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; } @@ -7067,8 +7064,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; @@ -7106,7 +7103,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