From patchwork Mon Jun 15 14:44:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiko Stuebner X-Patchwork-Id: 217760 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23C15C433DF for ; Mon, 15 Jun 2020 14:45:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 043E720679 for ; Mon, 15 Jun 2020 14:45:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730679AbgFOOpS (ORCPT ); Mon, 15 Jun 2020 10:45:18 -0400 Received: from gloria.sntech.de ([185.11.138.130]:57632 "EHLO gloria.sntech.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728304AbgFOOpP (ORCPT ); Mon, 15 Jun 2020 10:45:15 -0400 Received: from ip5f5aa64a.dynamic.kabel-deutschland.de ([95.90.166.74] helo=phil.lan) by gloria.sntech.de with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jkqMC-0004iN-07; Mon, 15 Jun 2020 16:45:04 +0200 From: Heiko Stuebner To: davem@davemloft.net, kuba@kernel.org Cc: robh+dt@kernel.org, andrew@lunn.ch, f.fainelli@gmail.com, hkallweit1@gmail.com, linux@armlinux.org.uk, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, heiko@sntech.de, christoph.muellner@theobroma-systems.com, Heiko Stuebner Subject: [PATCH v3 1/3] net: phy: mscc: move shared probe code into a helper Date: Mon, 15 Jun 2020 16:44:59 +0200 Message-Id: <20200615144501.1140870-1-heiko@sntech.de> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Heiko Stuebner The different probe functions share a lot of code, so move the common parts into a helper to reduce duplication. This moves the devm_phy_package_join below the general allocation but as all components just allocate things, this should be ok. Suggested-by: Andrew Lunn Signed-off-by: Heiko Stuebner --- changes in v3: - adapt to 5.8 merge-window results changes in v2: - new patch as suggested by Andrew drivers/net/phy/mscc/mscc_main.c | 123 +++++++++++++++---------------- 1 file changed, 60 insertions(+), 63 deletions(-) diff --git a/drivers/net/phy/mscc/mscc_main.c b/drivers/net/phy/mscc/mscc_main.c index 5ddc44f87eaf..68308d3e9589 100644 --- a/drivers/net/phy/mscc/mscc_main.c +++ b/drivers/net/phy/mscc/mscc_main.c @@ -1935,12 +1935,11 @@ static int vsc85xx_read_status(struct phy_device *phydev) return genphy_read_status(phydev); } -static int vsc8514_probe(struct phy_device *phydev) +static int vsc85xx_probe_helper(struct phy_device *phydev, + u32 *leds, int num_leds, u16 led_modes, + const struct vsc85xx_hw_stat *stats, int nstats) { struct vsc8531_private *vsc8531; - u32 default_mode[4] = {VSC8531_LINK_1000_ACTIVITY, - VSC8531_LINK_100_ACTIVITY, VSC8531_LINK_ACTIVITY, - VSC8531_DUPLEX_COLLISION}; vsc8531 = devm_kzalloc(&phydev->mdio.dev, sizeof(*vsc8531), GFP_KERNEL); if (!vsc8531) @@ -1948,54 +1947,65 @@ static int vsc8514_probe(struct phy_device *phydev) phydev->priv = vsc8531; - vsc8584_get_base_addr(phydev); - devm_phy_package_join(&phydev->mdio.dev, phydev, - vsc8531->base_addr, 0); - - vsc8531->nleds = 4; - vsc8531->supp_led_modes = VSC85XX_SUPP_LED_MODES; - vsc8531->hw_stats = vsc85xx_hw_stats; - vsc8531->nstats = ARRAY_SIZE(vsc85xx_hw_stats); + vsc8531->nleds = num_leds; + vsc8531->supp_led_modes = led_modes; + vsc8531->hw_stats = stats; + vsc8531->nstats = nstats; vsc8531->stats = devm_kcalloc(&phydev->mdio.dev, vsc8531->nstats, sizeof(u64), GFP_KERNEL); if (!vsc8531->stats) return -ENOMEM; - return vsc85xx_dt_led_modes_get(phydev, default_mode); + return vsc85xx_dt_led_modes_get(phydev, leds); } -static int vsc8574_probe(struct phy_device *phydev) +static int vsc8514_probe(struct phy_device *phydev) { struct vsc8531_private *vsc8531; + int rc; u32 default_mode[4] = {VSC8531_LINK_1000_ACTIVITY, VSC8531_LINK_100_ACTIVITY, VSC8531_LINK_ACTIVITY, VSC8531_DUPLEX_COLLISION}; - vsc8531 = devm_kzalloc(&phydev->mdio.dev, sizeof(*vsc8531), GFP_KERNEL); - if (!vsc8531) - return -ENOMEM; - - phydev->priv = vsc8531; + rc = vsc85xx_probe_helper(phydev, default_mode, + ARRAY_SIZE(default_mode), + VSC85XX_SUPP_LED_MODES, + vsc85xx_hw_stats, + ARRAY_SIZE(vsc85xx_hw_stats)); + if (rc < 0) + return rc; + vsc8531 = phydev->priv; vsc8584_get_base_addr(phydev); - devm_phy_package_join(&phydev->mdio.dev, phydev, - vsc8531->base_addr, 0); + return devm_phy_package_join(&phydev->mdio.dev, phydev, + vsc8531->base_addr, 0); +} - vsc8531->nleds = 4; - vsc8531->supp_led_modes = VSC8584_SUPP_LED_MODES; - vsc8531->hw_stats = vsc8584_hw_stats; - vsc8531->nstats = ARRAY_SIZE(vsc8584_hw_stats); - vsc8531->stats = devm_kcalloc(&phydev->mdio.dev, vsc8531->nstats, - sizeof(u64), GFP_KERNEL); - if (!vsc8531->stats) - return -ENOMEM; +static int vsc8574_probe(struct phy_device *phydev) +{ + struct vsc8531_private *vsc8531; + int rc; + u32 default_mode[4] = {VSC8531_LINK_1000_ACTIVITY, + VSC8531_LINK_100_ACTIVITY, VSC8531_LINK_ACTIVITY, + VSC8531_DUPLEX_COLLISION}; + + rc = vsc85xx_probe_helper(phydev, default_mode, + ARRAY_SIZE(default_mode), + VSC8584_SUPP_LED_MODES, + vsc8584_hw_stats, + ARRAY_SIZE(vsc8584_hw_stats)); + if (rc < 0) + return rc; - return vsc85xx_dt_led_modes_get(phydev, default_mode); + vsc8584_get_base_addr(phydev); + return devm_phy_package_join(&phydev->mdio.dev, phydev, + vsc8531->base_addr, 0); } static int vsc8584_probe(struct phy_device *phydev) { struct vsc8531_private *vsc8531; + int rc; u32 default_mode[4] = {VSC8531_LINK_1000_ACTIVITY, VSC8531_LINK_100_ACTIVITY, VSC8531_LINK_ACTIVITY, VSC8531_DUPLEX_COLLISION}; @@ -2005,32 +2015,24 @@ static int vsc8584_probe(struct phy_device *phydev) return -ENOTSUPP; } - vsc8531 = devm_kzalloc(&phydev->mdio.dev, sizeof(*vsc8531), GFP_KERNEL); - if (!vsc8531) - return -ENOMEM; - - phydev->priv = vsc8531; + rc = vsc85xx_probe_helper(phydev, default_mode, + ARRAY_SIZE(default_mode), + VSC8584_SUPP_LED_MODES, + vsc8584_hw_stats, + ARRAY_SIZE(vsc8584_hw_stats)); + if (rc < 0) + return rc; + vsc8531 = phydev->priv; vsc8584_get_base_addr(phydev); - devm_phy_package_join(&phydev->mdio.dev, phydev, - vsc8531->base_addr, 0); - - vsc8531->nleds = 4; - vsc8531->supp_led_modes = VSC8584_SUPP_LED_MODES; - vsc8531->hw_stats = vsc8584_hw_stats; - vsc8531->nstats = ARRAY_SIZE(vsc8584_hw_stats); - vsc8531->stats = devm_kcalloc(&phydev->mdio.dev, vsc8531->nstats, - sizeof(u64), GFP_KERNEL); - if (!vsc8531->stats) - return -ENOMEM; - - return vsc85xx_dt_led_modes_get(phydev, default_mode); + return devm_phy_package_join(&phydev->mdio.dev, phydev, + vsc8531->base_addr, 0); } static int vsc85xx_probe(struct phy_device *phydev) { struct vsc8531_private *vsc8531; - int rate_magic; + int rate_magic, rc; u32 default_mode[2] = {VSC8531_LINK_1000_ACTIVITY, VSC8531_LINK_100_ACTIVITY}; @@ -2038,23 +2040,18 @@ static int vsc85xx_probe(struct phy_device *phydev) if (rate_magic < 0) return rate_magic; - vsc8531 = devm_kzalloc(&phydev->mdio.dev, sizeof(*vsc8531), GFP_KERNEL); - if (!vsc8531) - return -ENOMEM; - - phydev->priv = vsc8531; + rc = vsc85xx_probe_helper(phydev, default_mode, + ARRAY_SIZE(default_mode), + VSC85XX_SUPP_LED_MODES, + vsc85xx_hw_stats, + ARRAY_SIZE(vsc85xx_hw_stats)); + if (rc < 0) + return rc; + vsc8531 = phydev->priv; vsc8531->rate_magic = rate_magic; - vsc8531->nleds = 2; - vsc8531->supp_led_modes = VSC85XX_SUPP_LED_MODES; - vsc8531->hw_stats = vsc85xx_hw_stats; - vsc8531->nstats = ARRAY_SIZE(vsc85xx_hw_stats); - vsc8531->stats = devm_kcalloc(&phydev->mdio.dev, vsc8531->nstats, - sizeof(u64), GFP_KERNEL); - if (!vsc8531->stats) - return -ENOMEM; - return vsc85xx_dt_led_modes_get(phydev, default_mode); + return 0; } /* Microsemi VSC85xx PHYs */