From patchwork Fri Jul 15 08:50:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 12918926 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38247C433EF for ; Fri, 15 Jul 2022 08:50:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233081AbiGOIuz (ORCPT ); Fri, 15 Jul 2022 04:50:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232754AbiGOIut (ORCPT ); Fri, 15 Jul 2022 04:50:49 -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 13307823B4 for ; Fri, 15 Jul 2022 01:50:43 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id d12so6741025lfq.12 for ; Fri, 15 Jul 2022 01:50:42 -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=XlwLsPYG5i93bmO2q8/Pe3x/LuD1+PCcBdrlng7Aedg=; b=Aj1o6NogwqqstqnVImvNma+KFET4cd1xUCZ3D/txdxgZaP4x6ZIrzqhHH58JH3Dab5 OI7Z/IIP/MPTsPM0Jj8X4n8f0LbQt0Jn90OuLrJsU2y8VJ1S/FIto6e0ZXcXZt1RRUZg ayiaiLmIcwDyihdsgakRfU/q1osN4jh2Q1O04rKFlusckqyUmqN3TMUk8i+rKAIQWT2r UBLuMYvpqQsoajxq6rhto9qmFGYPXkHpUNf4WJuw2XxaLq5DWAKxJK3yQ/ziaN6o/FSP 2iR95EFRSJx/mc8N4SRdojYOqQycKJooAyMPf6RWDpShuUQOzOivJ0JeTjpIvXoDLB1k C/Yw== 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=XlwLsPYG5i93bmO2q8/Pe3x/LuD1+PCcBdrlng7Aedg=; b=is7umjAqO4bAOETmTwUT9duWBw+ooYSwg636Bvo4kdP5fsufKQPcHEZPyVvexFabn3 QS1J+H6x+wpHlD+qnGEkkkaNmlmzRDsH2h0z6AWDO50gh09nby4vYtEs3qLGl0BeYQgd OLL7YE0zjKZRmhWE+1xA2wuXaqGgU4ilSW8QVRbaPaHJQv2pRwNz8VysXU8a7aME4pTz NWeoT/8Q+Yru+3E12gK+plTLT4eR2GScDT2mGWCUljzLbAztMn6myBAaVPuxcu2WZtOA NJ58t+tiAwmxxssZmxeS4i4qEGkeQY99g5qP1ML1Lx7boxEqKWAsu4//52HQU1xrTLLn a2lA== X-Gm-Message-State: AJIora+2F5vSk5Ec/FKfcKSPxW9dxuFI5C4ICYZ15DLjqEj2ynwcHCEA znddjrZoYMEi/h5CWZfRkoUPpA== X-Google-Smtp-Source: AGRyM1vWd0JqSFC8cwniB2kMWKofB28D0S+ZE0Hfe8UwLV/npzmuHk/z6XTQOX49HNz+un4V6Ebl/g== X-Received: by 2002:ac2:4d5c:0:b0:48a:4ac:d0e4 with SMTP id 28-20020ac24d5c000000b0048a04acd0e4mr7770832lfp.519.1657875041312; Fri, 15 Jul 2022 01:50:41 -0700 (PDT) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id e4-20020a2e9e04000000b0025d773448basm667846ljk.23.2022.07.15.01.50.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 01:50: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 v2 1/8] net: phy: fixed_phy: switch to fwnode_ API Date: Fri, 15 Jul 2022 10:50:05 +0200 Message-Id: <20220715085012.2630214-2-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220715085012.2630214-1-mw@semihalf.com> References: <20220715085012.2630214-1-mw@semihalf.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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 | 4 +- drivers/net/mdio/of_mdio.c | 2 +- drivers/net/phy/fixed_phy.c | 39 +++++++------------- 3 files changed, 17 insertions(+), 28 deletions(-) diff --git a/include/linux/phy_fixed.h b/include/linux/phy_fixed.h index 52bc8e487ef7..449a927231ec 100644 --- a/include/linux/phy_fixed.h +++ b/include/linux/phy_fixed.h @@ -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); 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; 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_handle(np))); } EXPORT_SYMBOL(of_phy_register_fixed_link); 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) } } -#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; - if (!np) - return NULL; - - fixed_link_node = of_get_child_by_name(np, "fixed-link"); + fixed_link_node = fwnode_get_named_child_node(fwnode, "fixed-link"); if (!fixed_link_node) return NULL; @@ -204,28 +200,21 @@ static struct gpio_desc *fixed_phy_get_gpiod(struct device_node *np) * Linux device associated with it, we simply have obtain * the GPIO descriptor from the device tree like this. */ - gpiod = fwnode_gpiod_get_index(of_fwnode_handle(fixed_link_node), - "link", 0, GPIOD_IN, "mdio"); + gpiod = fwnode_gpiod_get_index(fixed_link_node, "link", 0, GPIOD_IN, "mdio"); if (IS_ERR(gpiod) && PTR_ERR(gpiod) != -EPROBE_DEFER) { if (PTR_ERR(gpiod) != -ENOENT) pr_err("error getting GPIO for fixed link %pOF, proceed without\n", fixed_link_node); gpiod = NULL; } - of_node_put(fixed_link_node); + fwnode_handle_put(fixed_link_node); return gpiod; } -#else -static struct gpio_desc *fixed_phy_get_gpiod(struct device_node *np) -{ - return NULL; -} -#endif 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 = &platform_fmb; @@ -238,7 +227,7 @@ static struct phy_device *__fixed_phy_register(unsigned int irq, /* Check if we have a GPIO associated with this fixed phy */ if (!gpiod) { - gpiod = fixed_phy_get_gpiod(np); + gpiod = 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 = status->asym_pause; } - of_node_get(np); - phy->mdio.dev.of_node = np; + fwnode_handle_get(fwnode); + device_set_node(&phy->mdio.dev, fwnode); phy->is_pseudo_fixed_link = true; switch (status->speed) { @@ -299,7 +288,7 @@ static struct phy_device *__fixed_phy_register(unsigned int irq, ret = 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, 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); @@ -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); From patchwork Fri Jul 15 08:50:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 12918927 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED145CCA483 for ; Fri, 15 Jul 2022 08:50:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233126AbiGOIu5 (ORCPT ); Fri, 15 Jul 2022 04:50:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232906AbiGOIut (ORCPT ); Fri, 15 Jul 2022 04:50:49 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7ED00823B8 for ; Fri, 15 Jul 2022 01:50:44 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id bp17so6791412lfb.3 for ; Fri, 15 Jul 2022 01:50: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=1I6Xn/UXiMT6VknV/yDkGje3BjUktQ7ZyDrns9mPDHA=; b=tUnGCC/GQIIyy+t0787Awd+rfsuwYSWkGp2De2EmOe1fCjEUbDwof/Q37g0pE6s0DZ kZY0Pj//cVOE2vo0ua8cQh0IwvC+G0kaNNX+gsCWKS1xbVxUysDXcpOfrO7wzHXi7QEz oX1ggXIy5MVrQe5/GFETbeobhEPaXNg9YWyQlDjcPZEjDqiLq1vqadJF2UwldLrwThqX 71QvHMkJbqTmUJnMP0FTlO47YRwXjOkTvdx/h8JjvxJqwQbfgHxEMFpKRs+bgm3h8ZQ3 B6g5D666RYyzhMG8eIlYGuUas47nnEqPlTMIZSdhpAMv2t/n3UB3dUTwjL7x4cPMZ98l 06vw== 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=LPykk8IfdWZF7AOBHNUvuiQogL0KKlIA8dOlTp/UtaXHOYHbM9CSMlMasRY6C4gFzv FL5UqrQ7qZMaeM1em6TwnDHVyZYtARkfyGcTj5CopBIjKMIlJczGE1CNPWE1z0rQHzgc 8diwumaaKs3ViZIogI7D6b63PKQKvRP5eiEzWAZB+mfFpsCPsHWMbZw1bh5ROzETtTci N/L+t0k7f/X+wChf5ydYX+CwWSp3Yzg1ZnZH6/rvcimawjj/p4vnfGmYgzhXS/hWDjQI 1KS43YrxSx78MD5preFZ79f7SeSvgIgQox3S1dOmpEnF8M+jcEp1R5RG003As/E2Otj2 95FA== X-Gm-Message-State: AJIora+JqiCz9iQQgVfx1ggtlLZYR5eyoeQlabTJYBnBYqqAA9dSdCZ1 qZHNBQJ2R3Q4EH60hxOJtZyfWA== X-Google-Smtp-Source: AGRyM1sT+txbuj8aeOb+S4GbLEviAUKdHHPRLnU1Lw59c82guf+N90aYkPJYVMfC78qi/Enaont8aA== X-Received: by 2002:a05:6512:505:b0:489:c93d:a95c with SMTP id o5-20020a056512050500b00489c93da95cmr8083214lfb.115.1657875042728; Fri, 15 Jul 2022 01:50:42 -0700 (PDT) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id e4-20020a2e9e04000000b0025d773448basm667846ljk.23.2022.07.15.01.50.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 01:50: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 v2 2/8] net: mdio: switch fixed-link PHYs API to fwnode_ Date: Fri, 15 Jul 2022 10:50:06 +0200 Message-Id: <20220715085012.2630214-3-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220715085012.2630214-1-mw@semihalf.com> References: <20220715085012.2630214-1-mw@semihalf.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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 *mdio, int fwnode_mdiobus_register_phy(struct mii_bus *bus, struct fwnode_handle *child, u32 addr); +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 *fwnode) +{ + 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 #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 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 = 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) == 0 && + strcmp(managed, "auto") != 0) + return true; + + /* Old binding */ + len = fwnode_property_count_u32(fwnode, "fixed-link"); + if (len == 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 = {}; + struct fwnode_handle *fixed_link_node; + u32 fixed_link_prop[5]; + const char *managed; + + if (fwnode_property_read_string(fwnode, "managed", &managed) == 0 && + strcmp(managed, "in-band-status") == 0) { + /* status is zeroed, namely its .link member */ + goto register_phy; + } + + /* New binding */ + fixed_link_node = fwnode_get_named_child_node(fwnode, "fixed-link"); + if (fixed_link_node) { + status.link = 1; + status.duplex = 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 = fwnode_property_present(fixed_link_node, "pause"); + status.asym_pause = 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)) == 0) { + status.link = 1; + status.duplex = fixed_link_prop[1]; + status.speed = fixed_link_prop[2]; + status.pause = fixed_link_prop[3]; + status.asym_pause = 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 = 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 = of_get_child_by_name(np, "fixed-link"); - if (dn) { - of_node_put(dn); - return true; - } - - err = of_property_read_string(np, "managed", &managed); - if (err == 0 && strcmp(managed, "auto") != 0) - return true; - - /* Old binding */ - if (of_get_property(np, "fixed-link", &len) && - len == (5 * sizeof(__be32))) - return true; - - return false; + return fwnode_phy_is_fixed_link(of_fwnode_handle(np)); } EXPORT_SYMBOL(of_phy_is_fixed_link); int of_phy_register_fixed_link(struct device_node *np) { - struct fixed_phy_status status = {}; - struct device_node *fixed_link_node; - u32 fixed_link_prop[5]; - const char *managed; - - if (of_property_read_string(np, "managed", &managed) == 0 && - strcmp(managed, "in-band-status") == 0) { - /* status is zeroed, namely its .link member */ - goto register_phy; - } - - /* New binding */ - fixed_link_node = of_get_child_by_name(np, "fixed-link"); - if (fixed_link_node) { - status.link = 1; - status.duplex = 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 = of_property_read_bool(fixed_link_node, "pause"); - status.asym_pause = 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)) == 0) { - status.link = 1; - status.duplex = fixed_link_prop[1]; - status.speed = fixed_link_prop[2]; - status.pause = fixed_link_prop[3]; - status.asym_pause = fixed_link_prop[4]; - goto register_phy; - } - - return -ENODEV; - -register_phy: - return PTR_ERR_OR_ZERO(fixed_phy_register(PHY_POLL, &status, of_fwnode_handle(np))); + return fwnode_phy_register_fixed_link(of_fwnode_handle(np)); } EXPORT_SYMBOL(of_phy_register_fixed_link); void of_phy_deregister_fixed_link(struct device_node *np) { - struct phy_device *phydev; - - phydev = 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); From patchwork Fri Jul 15 08:50:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 12918928 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5FE4BC43334 for ; Fri, 15 Jul 2022 08:51:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233311AbiGOIvc (ORCPT ); Fri, 15 Jul 2022 04:51:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232704AbiGOIuu (ORCPT ); Fri, 15 Jul 2022 04:50:50 -0400 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 407A68244E for ; Fri, 15 Jul 2022 01:50:46 -0700 (PDT) Received: by mail-lf1-x129.google.com with SMTP id bu42so6842111lfb.0 for ; Fri, 15 Jul 2022 01:50: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=sbDYvZq4O+B1/WFFjCS89/4ARFp4dv9vR5UNAfQQqpk=; b=T2cxWhtoCc31+EasHa9s4YeAouB4t79XBKAjfoULt4x7IE1oPxQ5Dc2h4NBUR0qMJS 8rIuoOGEvjeyNlrvhYVbV6B1DJ2/+IGuEKFvtpcBJlWYJzxtUwYVJQF6SFP5/gzVg81M sxIH27ZS2stCYGVETcSYIltPjlJ9/mr22RdmR5SFE9RmvA/FvmYFLbDsmxGOWC9h4HCh nXNYQWAhisWVFWjzkYs7vlAB2p9+itOy25TUaNIBWqTrIfveSwbZdbDtc7SIgrM8N6SU 0VmA/HwftKXmCQpzbDVQahioY4v0Hs5QWzPicsLwdrNkcvgATLNGOoo8Yt02/4M/Aytp 9q+A== 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=sbDYvZq4O+B1/WFFjCS89/4ARFp4dv9vR5UNAfQQqpk=; b=jUtaSUrQfLGIRWl9FTZVnHYRfDX9/psMpJDURglfOacuGjR5h85to2XNz7QaNYw579 bFlc9g6UV+rbfM6nbUTIrCC3ZnoqfrrEZTa+7cX9xja60fuoE0qAvk1FfAdaOhpklIug SaW3m3K6lYSsLxsE2B+I3iVajbr39ha2HuyQGqnkzjvH49W3ewO8sVAKDnxmdsreUVVR 3jbO2cLRURAzvXmoTA1JPJarJvyusxfsQCarajFdpllXtIVVW30o/itfPNW2qBZQkg42 pPwHY71KEhxpyt9DLQbi4ghK8VM9sFhtGy7sliFsHLXeyLTXGrkCdJceuWHcUd+4u20B Sctg== X-Gm-Message-State: AJIora8DSkqWPa6ySqhylzohIXVVdZ6+/vXBOX2FVMayfkuyjHN46zI9 bap48es+y8M6iBa2km2vVgkFVg== X-Google-Smtp-Source: AGRyM1vEO61Awb80CQQLsZTm/BwCjgyZ/hJw6c7DxuGkdQwvLXxaQbNHeKJbkMmQVHZBsxOkceltow== X-Received: by 2002:a05:6512:3084:b0:489:e658:25ac with SMTP id z4-20020a056512308400b00489e65825acmr7777395lfd.431.1657875044088; Fri, 15 Jul 2022 01:50:44 -0700 (PDT) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id e4-20020a2e9e04000000b0025d773448basm667846ljk.23.2022.07.15.01.50.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 01:50: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 v2 3/8] net: dsa: switch to device_/fwnode_ APIs Date: Fri, 15 Jul 2022 10:50:07 +0200 Message-Id: <20220715085012.2630214-4-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220715085012.2630214-1-mw@semihalf.com> References: <20220715085012.2630214-1-mw@semihalf.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org In order to support both ACPI and DT, 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 | 2 +- drivers/net/dsa/mv88e6xxx/chip.c | 2 +- drivers/net/dsa/qca8k.c | 2 +- drivers/net/dsa/realtek/rtl8365mb.c | 2 +- net/dsa/dsa2.c | 100 +++++++++++--------- net/dsa/port.c | 70 +++++++------- net/dsa/slave.c | 7 +- 9 files changed, 97 insertions(+), 94 deletions(-) diff --git a/include/net/dsa.h b/include/net/dsa.h index 7c6870d2c607..d0c944e2b920 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -302,7 +302,7 @@ struct dsa_port { u8 setup:1; - struct device_node *dn; + struct fwnode_handle *fwnode; unsigned int ageing_time; 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 *dp, 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 broadcast); diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index dab308e454e3..036ca130d86e 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -2232,7 +2232,7 @@ mt7530_setup(struct dsa_switch *ds) if (!dsa_is_unused_port(ds, 5)) { priv->p5_intf_sel = P5_INTF_SEL_GMAC5; - ret = of_get_phy_mode(dsa_to_port(ds, 5)->dn, &interface); + ret = of_get_phy_mode(to_of_node(dsa_to_port(ds, 5)->fwnode), &interface); if (ret && ret != -ENODEV) return ret; } else { diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index 01dff8d46642..1baf07b3284b 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -3499,7 +3499,7 @@ static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port) if (chip->info->ops->serdes_set_tx_amplitude) { if (dp) - phy_handle = of_parse_phandle(dp->dn, "phy-handle", 0); + phy_handle = of_parse_phandle(to_of_node(dp->fwnode), "phy-handle", 0); if (phy_handle && !of_property_read_u32(phy_handle, "tx-p2p-microvolt", diff --git a/drivers/net/dsa/qca8k.c b/drivers/net/dsa/qca8k.c index beccd8338c81..597ff5f1be4c 100644 --- a/drivers/net/dsa/qca8k.c +++ b/drivers/net/dsa/qca8k.c @@ -1517,7 +1517,7 @@ qca8k_parse_port_config(struct qca8k_priv *priv) continue; dp = dsa_to_port(priv->ds, port); - port_dn = dp->dn; + port_dn = to_of_node(dp->fwnode); cpu_port_index++; if (!of_device_is_available(port_dn)) diff --git a/drivers/net/dsa/realtek/rtl8365mb.c b/drivers/net/dsa/realtek/rtl8365mb.c index 7bf420c2b083..143e5718b531 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_priv *priv, int port, return -ENODEV; dp = dsa_to_port(priv->ds, port); - dn = dp->dn; + dn = to_of_node(dp->fwnode); /* 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) } 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; list_for_each_entry(dp, &dst->ports, list) - if (dp->dn == dn) + if (dp->fwnode == fwnode) return dp; return NULL; @@ -337,14 +337,13 @@ static bool dsa_port_setup_routing_table(struct dsa_port *dp) { struct dsa_switch *ds = dp->ds; struct dsa_switch_tree *dst = ds->dst; - struct device_node *dn = dp->dn; struct of_phandle_iterator it; struct dsa_port *link_dp; struct dsa_link *dl; int err; - of_for_each_phandle(&it, err, dn, "link", NULL, 0) { - link_dp = 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 = 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 = dsa_port_link_register_of(dp); + err = dsa_port_link_register_fw(dp); if (err) break; dsa_port_link_registered = true; @@ -481,7 +480,7 @@ static int dsa_port_setup(struct dsa_port *dp) break; case DSA_PORT_TYPE_DSA: - err = dsa_port_link_register_of(dp); + err = dsa_port_link_register_fw(dp); if (err) break; dsa_port_link_registered = true; @@ -493,7 +492,7 @@ static int dsa_port_setup(struct dsa_port *dp) break; case DSA_PORT_TYPE_USER: - of_get_mac_address(dp->dn, dp->mac); + fwnode_get_mac_address(dp->fwnode, dp->mac); err = 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_switch *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; @@ -909,10 +908,10 @@ static int dsa_switch_setup(struct dsa_switch *ds) dsa_slave_mii_bus_init(ds); - dn = of_get_child_by_name(ds->dev->of_node, "mdio"); + fwnode = device_get_named_child_node(ds->dev, "mdio"); - err = of_mdiobus_register(ds->slave_mii_bus, dn); - of_node_put(dn); + err = 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; } -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 *fwnode) { - struct device_node *ethernet = of_parse_phandle(dn, "ethernet", 0); - const char *name = of_get_property(dn, "label", NULL); - bool link = of_property_read_bool(dn, "link"); + struct fwnode_handle *ethernet = fwnode_find_reference(fwnode, "ethernet", 0); + bool link = fwnode_property_present(fwnode, "link"); + const char *name; + int ret; + + ret = fwnode_property_read_string(fwnode, "label", &name); + if (ret) + return ret; - dp->dn = dn; + dp->fwnode = fwnode; - if (ethernet) { + if (!IS_ERR(ethernet)) { struct net_device *master; const char *user_protocol; - master = of_find_net_device_by_node(ethernet); - of_node_put(ethernet); + master = of_find_net_device_by_node(to_of_node(ethernet)); + fwnode_handle_put(ethernet); if (!master) return -EPROBE_DEFER; - user_protocol = of_get_property(dn, "dsa-tag-protocol", NULL); + ret = fwnode_property_read_string(fwnode, "dsa-tag-protocol", + &user_protocol); + if (ret) + user_protocol = NULL; + return dsa_port_parse_cpu(dp, master, user_protocol); } @@ -1509,61 +1517,61 @@ static int dsa_port_parse_of(struct dsa_port *dp, struct device_node *dn) return dsa_port_parse_user(dp, name); } -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 = 0; u32 reg; - ports = of_get_child_by_name(dn, "ports"); + ports = fwnode_get_named_child_node(fwnode, "ports"); if (!ports) { /* The second possibility is "ethernet-ports" */ - ports = of_get_child_by_name(dn, "ethernet-ports"); + ports = fwnode_get_named_child_node(fwnode, "ethernet-ports"); if (!ports) { dev_err(ds->dev, "no ports child node found\n"); return -EINVAL; } } - for_each_available_child_of_node(ports, port) { - err = of_property_read_u32(port, "reg", ®); + fwnode_for_each_available_child_node(ports, port) { + err = fwnode_property_read_u32(port, "reg", ®); if (err) { - of_node_put(port); + fwnode_handle_put(port); goto out_put_node; } if (reg >= 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 = -EINVAL; goto out_put_node; } dp = dsa_to_port(ds, reg); - err = dsa_port_parse_of(dp, port); + err = dsa_port_parse_fw(dp, port); if (err) { - of_node_put(port); + fwnode_handle_put(port); goto out_put_node; } } out_put_node: - of_node_put(ports); + fwnode_handle_put(ports); return err; } -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] = { 0, 0 }; int sz; /* Don't error out if this optional property isn't found */ - sz = of_property_read_variable_u32_array(dn, "dsa,member", m, 2, 2); + sz = fwnode_property_read_u32_array(fwnode, "dsa,member", m, 2); if (sz < 0 && sz != -EINVAL) return sz; @@ -1600,11 +1608,11 @@ static int dsa_switch_touch_ports(struct dsa_switch *ds) return 0; } -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; - err = dsa_switch_parse_member_of(ds, dn); + err = dsa_switch_parse_member_fw(ds, fwnode); if (err) return err; @@ -1612,7 +1620,7 @@ static int dsa_switch_parse_of(struct dsa_switch *ds, struct device_node *dn) if (err) return err; - return dsa_switch_parse_ports_of(ds, dn); + return dsa_switch_parse_ports_fw(ds, fwnode); } 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; if (!ds->dev) return -ENODEV; pdata = ds->dev->platform_data; - np = ds->dev->of_node; + fwnode = dev_fwnode(ds->dev); if (!ds->num_ports) return -EINVAL; - if (np) { - err = dsa_switch_parse_of(ds, np); + if (fwnode) { + err = 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 abcf7899abf8..c03baf20f5e5 100644 --- a/net/dsa/port.c +++ b/net/dsa/port.c @@ -6,10 +6,9 @@ * Vivien Didelot */ +#include #include #include -#include -#include #include "dsa_priv.h" @@ -1379,20 +1378,20 @@ void dsa_port_set_tag_protocol(struct dsa_port *cpu_dp, 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; - phy_dn = of_parse_phandle(dp->dn, "phy-handle", 0); - if (!phy_dn) + phy_handle = fwnode_find_reference(dp->fwnode, "phy-handle", 0); + if (IS_ERR(phy_handle)) return NULL; - phydev = of_phy_find_device(phy_dn); + phydev = fwnode_phy_find_device(phy_handle); if (!phydev) { - of_node_put(phy_dn); + fwnode_handle_put(phy_handle); return ERR_PTR(-EPROBE_DEFER); } - of_node_put(phy_dn); + fwnode_handle_put(phy_handle); return phydev; } @@ -1592,20 +1591,19 @@ static struct fwnode_handle *dsa_port_get_fwnode(struct dsa_port *dp, struct property_entry port_props[3] = {}; struct fwnode_handle *fixed_link_fwnode; struct fwnode_handle *new_port_fwnode; - struct device_node *dn = dp->dn; - struct device_node *phy_node; + struct fwnode_handle *phy_handle; int err, speed, duplex; unsigned long caps; - phy_node = of_parse_phandle(dn, "phy-handle", 0); - of_node_put(phy_node); - if (phy_node || of_phy_is_fixed_link(dn)) + phy_handle = fwnode_find_reference(dp->fwnode, "phy-handle", 0); + fwnode_handle_put(phy_handle); + if (!IS_ERR(phy_handle) || fwnode_phy_is_fixed_link(dp->fwnode)) /* Nothing broken, nothing to fix. * TODO: As discussed with Russell, maybe phylink could provide * a more comprehensive helper to determine what constitutes a * valid fwnode binding than this guerilla kludge. */ - return of_fwnode_handle(dn); + return dp->fwnode; if (mode == PHY_INTERFACE_MODE_NA) dsa_port_find_max_caps(dp, &mode, &caps); @@ -1644,9 +1642,9 @@ static struct fwnode_handle *dsa_port_get_fwnode(struct dsa_port *dp, int dsa_port_phylink_create(struct dsa_port *dp) { struct dsa_switch *ds = dp->ds; - phy_interface_t mode, def_mode; struct fwnode_handle *fwnode; - int err; + phy_interface_t def_mode; + int mode; /* Presence of phylink_mac_link_state or phylink_mac_an_restart is * an indicator of a legacy phylink driver. @@ -1660,8 +1658,8 @@ int dsa_port_phylink_create(struct dsa_port *dp) ds->ops->phylink_get_caps(ds, dp->index, &dp->pl_config, &def_mode); - err = of_get_phy_mode(dp->dn, &mode); - if (err) { + mode = fwnode_get_phy_mode(dp->fwnode); + if (mode < 0) { /* We must not set the default mode for user ports as a PHY * overrides the NA mode in phylink. Setting it here would * prevent the interface mode being updated. @@ -1686,6 +1684,8 @@ int dsa_port_phylink_create(struct dsa_port *dp) fwnode_remove_software_node(fwnode); + dp->pl = 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)); return PTR_ERR(dp->pl); @@ -1694,7 +1694,7 @@ int dsa_port_phylink_create(struct dsa_port *dp) return 0; } -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 = dp->ds; struct phy_device *phydev; @@ -1732,16 +1732,15 @@ static int dsa_port_setup_phy_of(struct dsa_port *dp, bool enable) return err; } -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 = dp->dn; struct dsa_switch *ds = dp->ds; struct phy_device *phydev; int port = dp->index; - phy_interface_t mode; + int mode; int err; - err = of_phy_register_fixed_link(dn); + err = fwnode_phy_register_fixed_link(dp->fwnode); if (err) { dev_err(ds->dev, "failed to register the fixed PHY of port %d\n", @@ -1749,10 +1748,10 @@ static int dsa_port_fixed_link_register_of(struct dsa_port *dp) return err; } - phydev = of_phy_find_device(dn); + phydev = fwnode_phy_find_device(dp->fwnode); - err = of_get_phy_mode(dn, &mode); - if (err) + mode = fwnode_get_phy_mode(dp->fwnode); + if (mode < 0) mode = PHY_INTERFACE_MODE_NA; phydev->interface = mode; @@ -1769,7 +1768,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 = dp->ds; - struct device_node *port_dn = dp->dn; int err; dp->pl_config.dev = ds->dev; @@ -1779,7 +1777,7 @@ static int dsa_port_phylink_register(struct dsa_port *dp) if (err) return err; - err = phylink_of_phy_connect(dp->pl, port_dn, 0); + err = phylink_fwnode_phy_connect(dp->pl, dp->fwnode, 0); if (err && err != -ENODEV) { pr_err("could not attach to PHY: %d\n", err); goto err_phy_connect; @@ -1792,7 +1790,7 @@ static int dsa_port_phylink_register(struct dsa_port *dp) return err; } -int dsa_port_link_register_of(struct dsa_port *dp) +int dsa_port_link_register_fw(struct dsa_port *dp) { struct dsa_switch *ds = dp->ds; int port = dp->index; @@ -1808,13 +1806,13 @@ int dsa_port_link_register_of(struct dsa_port *dp) dev_warn(ds->dev, "Using legacy PHYLIB callbacks. Please migrate to PHYLINK!\n"); - 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); } -void dsa_port_link_unregister_of(struct dsa_port *dp) +void dsa_port_link_unregister_fw(struct dsa_port *dp) { struct dsa_switch *ds = dp->ds; @@ -1827,10 +1825,10 @@ void dsa_port_link_unregister_of(struct dsa_port *dp) return; } - 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); } 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 *slave_dev, int addr, static int dsa_slave_phy_setup(struct net_device *slave_dev) { struct dsa_port *dp = dsa_slave_to_port(slave_dev); - struct device_node *port_dn = dp->dn; struct dsa_switch *ds = dp->ds; u32 phy_flags = 0; int ret; @@ -2252,7 +2249,7 @@ static int dsa_slave_phy_setup(struct net_device *slave_dev) if (ds->ops->get_phy_flags) phy_flags = ds->ops->get_phy_flags(ds, dp->index); - ret = phylink_of_phy_connect(dp->pl, port_dn, phy_flags); + ret = phylink_fwnode_phy_connect(dp->pl, dp->fwnode, phy_flags); if (ret == -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); SET_NETDEV_DEV(slave_dev, port->ds->dev); - slave_dev->dev.of_node = port->dn; + device_set_node(&slave_dev->dev, port->fwnode); slave_dev->vlan_features = master->vlan_features; p = netdev_priv(slave_dev); From patchwork Fri Jul 15 08:50:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 12918929 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4985FCCA47C for ; Fri, 15 Jul 2022 08:51:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233484AbiGOIvd (ORCPT ); Fri, 15 Jul 2022 04:51:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233034AbiGOIuu (ORCPT ); Fri, 15 Jul 2022 04:50:50 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 478FE82460 for ; Fri, 15 Jul 2022 01:50:47 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id e28so6779082lfj.4 for ; Fri, 15 Jul 2022 01:50:47 -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=Csg+XBvQXDUJJyiEkv/Pn2FIpcj+ic/32obyLUtvvYy93EcsZ0fEMr0vcuA5L4pBVI cXOZEYBpHmORuphlcLHebTylvpZLiWXGZ7J0Zkzz9iKINVQTHWzvdWvm7IYYd5kX1byH A0EDO3IP1RoJjmfQxuSDz0WN49ZvpFaoknWVa4qNtQBfQFAMBKjA1YJClSv8M5dU/Eyh LhUFThZbNEuggtcaGgkAOce4193FmQ1Xya4EBa0O86f0MdLxZwn6IVhF69RJO1VhVlIW sN9fgohUnn8up92RwpwvqmUx6b97AJgr42JXP8pTBMRqerwj7hR1uMoV0ixr2KBwNZA6 pWYw== 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=Vj8g0DJBl4J5b/7boKS+hMQfbKDU703c1Rcf7Kx/HyU+dFdVovbOsg6TNjJl+gXVBH C6dF0IzDGsmRPV0KvWQYTRDq9Z9OPGT8E/gxdaqS8++TmN66/ORcG+0RNtBqMOWdQ/2Z /FBmbsWDUmWu2w1DfM9xVq/kgXUcMO1VwaRPTQEW46x+N7fpT3/9DHvY2wTB5bbAKGdK 2MavFOTlaBcZFYVaXyN9W82ybGE1+UJt4VLRVfkYdM8t1qoHaSnjno+s23S95R25t7Tn mgswTRE+F8zR8hZiZ4xdlptH2hqbxYi4Z7yS+m78FLXv1AlQfb8AirJOS5LcUvpimNPq iANw== X-Gm-Message-State: AJIora8hN0JzZT4Oiac6N74DiVmxcuvuhWnTQqZ7meI91006eEus84hc AfWCOUfIYw8uh/8Rs1ZhQYIEkw== X-Google-Smtp-Source: AGRyM1vGJNBjEBQkEjQov65wX5302UAtQD2jH7TjcEWqfZTkmMOaegIuQZGOutC7HVnFEstpCAhwAw== X-Received: by 2002:a05:6512:2030:b0:489:c8bf:3f29 with SMTP id s16-20020a056512203000b00489c8bf3f29mr7867805lfs.274.1657875045544; Fri, 15 Jul 2022 01:50:45 -0700 (PDT) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id e4-20020a2e9e04000000b0025d773448basm667846ljk.23.2022.07.15.01.50.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 01:50: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 v2 4/8] net: mvpp2: initialize port fwnode pointer Date: Fri, 15 Jul 2022 10:50:08 +0200 Message-Id: <20220715085012.2630214-5-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220715085012.2630214-1-mw@semihalf.com> References: <20220715085012.2630214-1-mw@semihalf.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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 *pdev, dev->min_mtu = ETH_MIN_MTU; /* 9704 == 9728 - 20 and rounding to 8 */ dev->max_mtu = MVPP2_BM_JUMBO_PKT_SIZE; - dev->dev.of_node = port_node; + device_set_node(&dev->dev, port_fwnode); port->pcs_gmac.ops = &mvpp2_phylink_gmac_pcs_ops; port->pcs_xlg.ops = &mvpp2_phylink_xlg_pcs_ops; From patchwork Fri Jul 15 08:50:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 12918930 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4169DC433EF for ; Fri, 15 Jul 2022 08:51:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233042AbiGOIve (ORCPT ); Fri, 15 Jul 2022 04:51:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233058AbiGOIuw (ORCPT ); Fri, 15 Jul 2022 04:50:52 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A9C682467 for ; Fri, 15 Jul 2022 01:50:48 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id o7so6754759lfq.9 for ; Fri, 15 Jul 2022 01:50: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=NP3se/v+PuUKcQzIVvkexwGw74o8V8786Z6WGRgnFd4=; b=T1AAWzyWHscRbhdS3ButzMw0CabKXq0cifLUUd0wszCigDtPwU+z8OiyTMscLUk0vx lycERdVrvbGyqYO/rzmIXtJp2TVZX6/Ko/QfPBaTKh6nPqm9XGLig3V3V/u4YC5JKZcU /fjy7/hQIQsG3e6mU2sdy/1g0j366PROruhTALEIppwVs3VeTFyLUBCKUTSyhCRw/J4Y fwi/MEuw50OGzqFunexOlL+BDtSLqkOY/OGbxxjv4MgIzsVr60ck91q6U3hgvDSmUpwq 6R4LI8wLDc4+YB6dXjDkSO9IQgL6whgqp2oBis4fAHtvwFYyIb8aapRofVIohJKDdOy+ WLJw== 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=NP3se/v+PuUKcQzIVvkexwGw74o8V8786Z6WGRgnFd4=; b=HnNN1bMgxGUXqqdS7sNFvhYZ9Xn/zUr8Yw9gEA0rexvNODZTw/eEN0mrsGidJ031EM fMzsYD8jeGPk1wMZCBa9y4BRVfQTeRQqS5sPJ4povrg9TvOqp2gsRrRCTXvCd1NI7R2b ffbqa2H/QXO7Y9qIUEvgFwIh+pL6kbXzXoGfRNnL/ESq7ZJ79tOmQBH6yd3XRqS+F3Cl RlKv379oimZbjUJczjyrOGiEaLCF4233mEjc3EadrdyXviYpT0WAH6v7Z4KYM/Cqx1RB MoDHFGwq8PWpRj65A7GNMcj9wxPE7eiJgjkIvMwz6dLRkMWQcHtelNAjXjK8S94ElPJ2 0TiA== X-Gm-Message-State: AJIora/2/c/yQPmR1HGS5okv3guJHDzR+e19ws/V+A27LhdGaBifiVIZ QV8viTu8tp+ZsOLjamBhVc3iRA== X-Google-Smtp-Source: AGRyM1sBfVkmYm14X9HuLxbsoNDGodL7vOsJqQoD9ZLXB6h07RwQpFb90Cm16jRuckKPSICUHXNZoA== X-Received: by 2002:a05:6512:3e2a:b0:489:cf16:2d90 with SMTP id i42-20020a0565123e2a00b00489cf162d90mr7228043lfv.594.1657875046911; Fri, 15 Jul 2022 01:50:46 -0700 (PDT) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id e4-20020a2e9e04000000b0025d773448basm667846ljk.23.2022.07.15.01.50.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 01:50:46 -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 v2 5/8] device property: introduce fwnode_dev_node_match Date: Fri, 15 Jul 2022 10:50:09 +0200 Message-Id: <20220715085012.2630214-6-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220715085012.2630214-1-mw@semihalf.com> References: <20220715085012.2630214-1-mw@semihalf.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org This patch adds a new generic routine fwnode_dev_node_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 | 2 ++ drivers/base/property.c | 22 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/linux/property.h b/include/linux/property.h index 23330ae2b1fa..21b59ad08a39 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -456,6 +456,8 @@ int fwnode_connection_find_matches(struct fwnode_handle *fwnode, devcon_match_fn_t match, void **matches, unsigned int matches_len); +int fwnode_dev_node_match(struct device *dev, const void *data); + /* -------------------------------------------------------------------------- */ /* Software fwnode support - when HW description is incomplete or missing */ diff --git a/drivers/base/property.c b/drivers/base/property.c index ed6f449f8e5c..839e7d586129 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -1344,3 +1344,25 @@ int fwnode_connection_find_matches(struct fwnode_handle *fwnode, return count_graph + count_ref; } EXPORT_SYMBOL_GPL(fwnode_connection_find_matches); + +/* + * fwnode_dev_node_match - look for a device matching the struct fwnode_handle + * @dev: the struct device to initiate the search + * @data: pointer to the fwnode_handle + * + * 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(). + * + * Return: 1 - if match is found, 0 - otherwise. + */ +int fwnode_dev_node_match(struct device *dev, const void *data) +{ + for (; dev; dev = dev->parent) { + if (device_match_fwnode(dev, data)) + return 1; + } + + return 0; +} +EXPORT_SYMBOL_GPL(fwnode_dev_node_match); From patchwork Fri Jul 15 08:50:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 12918933 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E733DC43334 for ; Fri, 15 Jul 2022 08:52:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233994AbiGOIwB (ORCPT ); Fri, 15 Jul 2022 04:52:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233194AbiGOIvb (ORCPT ); Fri, 15 Jul 2022 04:51:31 -0400 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 DC53E82477 for ; Fri, 15 Jul 2022 01:50:49 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id bf9so6729806lfb.13 for ; Fri, 15 Jul 2022 01:50: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=ZsJ1XfZRYI9NmeAXNFV8MuDj1Gltas2LdIIHCwgqqO0=; b=QTH5tkb70ZxN94jwXV0HUGYi7YbC84SL3mnfLNNr9V3uZkgWbe2bTU8K8/7BmV43t3 3Tb7bomuZWZgu4z0MuUhPSz9My7ZRJWmzGZVmepWzbRXTdKIfqWJlqiBGvWXp3JgNyWy I8V9df+oHTVWHDVsvt6g22UIETI6zEqh04GZ0zme+AdpU1u9QQuTAo2UkacMHho1hZ2Y sdBBzL5C2kKU1QfaeOEp+G+zF1dkC7r5P+44TnJrLmZ6slsOjd2IBx0Sflt4sVsztsvb zNNd1RLUF2arfKtdVWdWkEdscBhSBpsGpCTbBWwdtxhEiCLGDPAb/rMx6U2UtrDf/XrN mx/g== 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=ZsJ1XfZRYI9NmeAXNFV8MuDj1Gltas2LdIIHCwgqqO0=; b=FgY6xgT+pLAJ02c+hK4y1E8uWGpb6pFDeP9s4txZyJHPT4wKBHqvC/W7SF0MxJEDXx xOsslFotYpnEXhMD/oZy/OJACvxz1pZey1/q+w2KreLf9ktKolzzPPA3beWKb4E1Rm25 oY4crCkZwEsHy2bNVCOooVgldt2Ch1K11h3LB/j7Qaqs3YZ3tDqt13MctX2G/4tEEH44 3EhPcSDYI1jICch6Uj/kCF4AQ179DuKHtb22ap8Fs6MjqAI2HSEvGqn99RkvsO7l+xnZ u6okvLlyEI4huBglwS4yLzoDXIIo1szgGRz0he2sKwWLMhCilSh0zrBI6wFBK5lUgpTd wKsA== X-Gm-Message-State: AJIora96Hygo6/zwDAHws7oAl3vnt0Cp9dLigbstX8slsYRTcZ9yQ/CE O9erXpUaGmVWT4oOkm9d6D8UGg== X-Google-Smtp-Source: AGRyM1uN7SYOYgSM7kELq7ZCklUGDTMuTfH21IXRqbrw4fFlhX6GAOu+ojw4ORdIBa8Tn5vyBLt+0Q== X-Received: by 2002:a05:6512:32c2:b0:487:cc5e:9ad2 with SMTP id f2-20020a05651232c200b00487cc5e9ad2mr7849959lfg.78.1657875048134; Fri, 15 Jul 2022 01:50:48 -0700 (PDT) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id e4-20020a2e9e04000000b0025d773448basm667846ljk.23.2022.07.15.01.50.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 01:50: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 v2 6/8] net: core: switch to fwnode_find_net_device_by_node() Date: Fri, 15 Jul 2022 10:50:10 +0200 Message-Id: <20220715085012.2630214-7-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220715085012.2630214-1-mw@semihalf.com> References: <20220715085012.2630214-1-mw@semihalf.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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 *addrbuf); int device_get_mac_address(struct device *dev, char *addr); int device_get_ethdev_address(struct device *dev, struct net_device *netdev); int fwnode_get_mac_address(struct fwnode_handle *fwnode, char *addr); +struct net_device *fwnode_find_net_device_by_node(struct fwnode_handle *fwnode); u32 eth_get_headlen(const struct net_device *dev, const void *data, u32 len); __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 *interface); 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 *np); #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_node *np, struct net_devic { return -ENODEV; } - -static inline struct net_device *of_find_net_device_by_node(struct device_node *np) -{ - return NULL; -} #endif #endif /* __LINUX_OF_NET_H */ diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index d61afd21aab5..7262e4749f57 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -1935,38 +1936,26 @@ static struct class net_class __ro_after_init = { .get_ownership = net_get_ownership, }; -#ifdef CONFIG_OF -static int of_dev_node_match(struct device *dev, const void *data) -{ - for (; dev; dev = dev->parent) { - if (dev->of_node == 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 fwnode + * @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 *fwnode) { struct device *dev; - dev = class_find_device(&net_class, NULL, np, of_dev_node_match); + dev = class_find_device(&net_class, NULL, fwnode, fwnode_dev_node_match); if (!dev) return NULL; return to_net_dev(dev); } -EXPORT_SYMBOL(of_find_net_device_by_node); -#endif +EXPORT_SYMBOL(fwnode_find_net_device_by_node); /* 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 @@ */ #include +#include #include #include #include @@ -1498,7 +1499,7 @@ static int dsa_port_parse_fw(struct dsa_port *dp, struct fwnode_handle *fwnode) struct net_device *master; const char *user_protocol; - master = of_find_net_device_by_node(to_of_node(ethernet)); + master = fwnode_find_net_device_by_node(ethernet); fwnode_handle_put(ethernet); if (!master) return -EPROBE_DEFER; From patchwork Fri Jul 15 08:50:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 12918932 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11185C43334 for ; Fri, 15 Jul 2022 08:51:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233878AbiGOIv4 (ORCPT ); Fri, 15 Jul 2022 04:51:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232974AbiGOIvb (ORCPT ); Fri, 15 Jul 2022 04:51:31 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BD2682479 for ; Fri, 15 Jul 2022 01:50:50 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id bp17so6791757lfb.3 for ; Fri, 15 Jul 2022 01:50: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=ImNEmSIVG+pNkIsz2aTPBuxUuaC/pO8aBnsJWK9rfm7pbBcaR27//qg5RCEzAbNDad S1farQUpHWFmRKlYdTewVcHblLJZsyLjhUFxjBKXDESyiVWiMJqVFTALSpa0fETFiT+n Nn1AbnFyznYE6sRgalKiXNNKNw9TAXfj9HJ2ag21bLUEbk9l8zrRTNa65VuCnsLNyS/I ICUKcpg0agE2QvxiNxYGTOEaf1eZsLFwDqFqi+1GLkTIy/OzVmmxwTinShUiKJMIP7cF xT75jQKRcHob/L1T22U+SHMi7IQw0PUp6yvHjUFOguoeBdmDmrhPTIvpE6/TmahluGbR rMOQ== 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=cEwooFW5pF9tpmL6ecMF1ODN49xgakFGCPClY+AwyUga5cWUxPr4f0UDrgDBV5AoY5 flGj+7YaCFywWz2JIhUfEfF4jJigMIPpusMId5H5bFTFQUbMhhkyXb4XsWIx5qaQs5nS FU1g6enttlzNjWtzJWNeybdP+ySzzITGYgewCJh+hguDwBnrazQOchooUYK0haYPU3Ds ySY53kNe9Iu48pYLLoULITRHrR+uXKZ+ytLEKUwRlvj8imxL9vR84icEfT/jYoZdP6xv uce96TpUrBAKxTXY2f0yyqojJnywOFR95Wq1/4HkeIrnY8rzoQ8eVnAvGaixMAAwNEOE VPUQ== X-Gm-Message-State: AJIora90Bny7DmP68T7AkSfCho7Dp6AcLa6XTdIqhxTgJjRxNuZBrY5B P0RNm4NiuciZgxWHq3LjMbqHbw== X-Google-Smtp-Source: AGRyM1uyZcbZnX6NZ8r2m2MZSyoYfzeZnbd1TFzCXcQDB72dxRLrr1PKS6VFQgc9KMlW9UbO1rGc1w== X-Received: by 2002:a05:6512:3081:b0:481:1691:e7ad with SMTP id z1-20020a056512308100b004811691e7admr8098247lfd.396.1657875049523; Fri, 15 Jul 2022 01:50:49 -0700 (PDT) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id e4-20020a2e9e04000000b0025d773448basm667846ljk.23.2022.07.15.01.50.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 01:50:49 -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 v2 7/8] net: mdio: introduce fwnode_mdiobus_register_device() Date: Fri, 15 Jul 2022 10:50:11 +0200 Message-Id: <20220715085012.2630214-8-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220715085012.2630214-1-mw@semihalf.com> References: <20220715085012.2630214-1-mw@semihalf.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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 *mdio, int fwnode_mdiobus_register_phy(struct mii_bus *bus, struct fwnode_handle *child, u32 addr); +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); 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); +int fwnode_mdiobus_register_device(struct mii_bus *mdio, + struct fwnode_handle *child, u32 addr) +{ + struct mdio_device *mdiodev; + int rc; + + mdiodev = 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 = 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); } -static int of_mdiobus_register_device(struct mii_bus *mdio, - struct device_node *child, u32 addr) -{ - struct fwnode_handle *fwnode = of_fwnode_handle(child); - struct mdio_device *mdiodev; - int rc; - - mdiodev = 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 = 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 device_node *np) if (of_mdiobus_child_is_phy(child)) rc = of_mdiobus_register_phy(mdio, child, addr); else - rc = of_mdiobus_register_device(mdio, child, addr); + rc = fwnode_mdiobus_register_device(mdio, of_fwnode_handle(child), addr); if (rc == -ENODEV) dev_err(&mdio->dev, From patchwork Fri Jul 15 08:50:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 12918931 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86904C433EF for ; Fri, 15 Jul 2022 08:51:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233841AbiGOIvt (ORCPT ); Fri, 15 Jul 2022 04:51:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233155AbiGOIvI (ORCPT ); Fri, 15 Jul 2022 04:51:08 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BAF1823B4 for ; Fri, 15 Jul 2022 01:50:51 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id y11so6770889lfs.6 for ; Fri, 15 Jul 2022 01:50:51 -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=fezBfQAJ2Jc7g4+Nk8PG5Lswj+jW8kXFPL2QSLPMg9I=; b=rzw3ryPC9hPJVQEddHD6sIN07bCLWZ+7xexAZCwSN0fdkxSWGggvu0wwZABHG7Zxlz fOXQZxWSI6Z9FkWwoztaKyinsqC45qiKqWLO/hpg84vEbYAviBeQBSPoGs3G8itffhJV Sspi+9GSj6/4bTv26ly7dufqYaJmq7mz/9ntQnO6H0w9ghdOS2nnog5CQ+Ixo1U0QNkk w9hZpbjPcHXsE+r5bYuCi2FrnbtUCvTadE+CCt+YWwfpNuT9H1TnKAC2qDHKICNRA1Xg eVvltOXKfcZ8rxHC+6lJS4hrLKeBA4lGH+DFT+rBLz0MFfyFUJKpgCQdM24bgB2Kai0e nbuA== 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=fezBfQAJ2Jc7g4+Nk8PG5Lswj+jW8kXFPL2QSLPMg9I=; b=CXUmZQmvMCj8NfpyGQSX+RonT8jbEuZ3e2PJKY0VJA0fEMLjAeJSRmhSGEMXWEaRXK He9F9fyWDJ+fZM/YTDOVBW+llo4R0Y38GJmbKWlzkI1TbucstvuLkxVE+4GW36A+d9Lk 12bvLqkNJty+IL1PidxJhF1f2/rJBz0oSKuIqS72eV4SLqYbheD9WYvi3SkcyDYHh3xs 8ePZJ/xmJQFET4az4cqbKVGbxyZdg50SH4+juvEeQ3WLkLIVUACa/NDwOwvzaT4ii6Nd Zdzox8TTrpQy+2KrOiUPVqvFYf0SS6yY7k8wNL90GSjMDdX5duA4gHpX06Qq1ywtmnxo tF+Q== X-Gm-Message-State: AJIora+kWrNV3Z7+hWkTy5tYDzHEMbiikZpcKzZwt2w3bFxeCzvSfmkw T6mHZbZO6hu8dEF1Sc66wLINIw== X-Google-Smtp-Source: AGRyM1tJ2ITwJs8M2KuFzKSj3rn0UjsLc2ZbkOPICf/e+RhQbzA1sT5YPMhqJIgUjJPuYr/DjTxafg== X-Received: by 2002:a05:6512:2527:b0:489:ec08:7ada with SMTP id be39-20020a056512252700b00489ec087adamr7203114lfb.621.1657875050824; Fri, 15 Jul 2022 01:50:50 -0700 (PDT) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id e4-20020a2e9e04000000b0025d773448basm667846ljk.23.2022.07.15.01.50.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 01:50: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 v2 8/8] net: dsa: mv88e6xxx: switch to device_/fwnode_ APIs Date: Fri, 15 Jul 2022 10:50:12 +0200 Message-Id: <20220715085012.2630214-9-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220715085012.2630214-1-mw@semihalf.com> References: <20220715085012.2630214-1-mw@semihalf.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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 | 57 ++++++++++---------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index 1baf07b3284b..ca9ae691573e 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -3312,7 +3312,7 @@ static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port) static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port) { - struct device_node *phy_handle = NULL; + struct fwnode_handle *phy_handle = NULL; struct dsa_switch *ds = chip->ds; struct dsa_port *dp; int tx_amp; @@ -3499,15 +3499,15 @@ static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port) if (chip->info->ops->serdes_set_tx_amplitude) { if (dp) - phy_handle = of_parse_phandle(to_of_node(dp->fwnode), "phy-handle", 0); + phy_handle = fwnode_find_reference(dp->fwnode, "phy-handle", 0); - 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 = 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; } @@ -3891,10 +3891,11 @@ static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val) } 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 = 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 mv88e6xxx_chip *chip) } 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; /* Always register one mdio bus for the internal/default mdio * bus. This maybe represented in the device tree, but is * optional. */ - child = of_get_child_by_name(np, "mdio"); + child = fwnode_get_named_child_node(fwnode, "mdio"); err = mv88e6xxx_mdio_register(chip, child, false); - of_node_put(child); + fwnode_handle_put(child); if (err) return err; @@ -3992,13 +3993,13 @@ static int mv88e6xxx_mdios_register(struct mv88e6xxx_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") == 0) { err = mv88e6xxx_mdio_register(chip, child, true); if (err) { mv88e6xxx_mdios_unregister(chip); - of_node_put(child); + fwnode_handle_put(child); return err; } } @@ -6975,20 +6976,16 @@ static SIMPLE_DEV_PM_OPS(mv88e6xxx_pm_ops, mv88e6xxx_suspend, mv88e6xxx_resume); static int mv88e6xxx_probe(struct mdio_device *mdiodev) { struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data; + struct fwnode_handle *fwnode = dev_fwnode(&mdiodev->dev); const struct mv88e6xxx_info *compat_info = NULL; struct device *dev = &mdiodev->dev; - struct device_node *np = dev->of_node; struct mv88e6xxx_chip *chip; int port; int err; - if (!np && !pdata) - return -EINVAL; - - if (np) - compat_info = of_device_get_match_data(dev); - - if (pdata) { + if (fwnode) + compat_info = device_get_match_data(dev); + else if (pdata) { compat_info = pdata_device_get_match_data(dev); if (!pdata->netdev) @@ -7045,9 +7042,9 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev) mv88e6xxx_phy_init(chip); 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 = pdata->eeprom_len; } @@ -7058,8 +7055,8 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev) if (err) goto out; - if (np) { - chip->irq = of_irq_get(np, 0); + if (fwnode) { + chip->irq = fwnode_irq_get(fwnode, 0); if (chip->irq == -EPROBE_DEFER) { err = chip->irq; goto out; @@ -7097,7 +7094,7 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev) if (err) goto out_g1_atu_prob_irq; - err = mv88e6xxx_mdios_register(chip, np); + err = mv88e6xxx_mdios_register(chip, fwnode); if (err) goto out_g1_vtu_prob_irq;