From nobody Thu Nov 14 17:14:31 2024 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 55ADCC77B70 for ; Wed, 29 Mar 2023 16:00:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229771AbjC2QAP (ORCPT ); Wed, 29 Mar 2023 12:00:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230034AbjC2P72 (ORCPT ); Wed, 29 Mar 2023 11:59:28 -0400 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3BF06A6F; Wed, 29 Mar 2023 08:58:56 -0700 (PDT) Received: from local by fudo.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96) (envelope-from ) id 1phYCM-0003O6-1l; Wed, 29 Mar 2023 17:58:54 +0200 Date: Wed, 29 Mar 2023 16:58:50 +0100 From: Daniel Golle To: netdev@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Matthias Brugger , AngeloGioacchino Del Regno , Sean Wang , Landen Chao , DENG Qingfang , Philipp Zabel Cc: Sam Shih , Lorenzo Bianconi , John Crispin , Felix Fietkau Subject: [RFC PATCH net-next v3 07/15] net: dsa: mt7530: introduce mt7530_probe_common helper function Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move commonly used parts from mt7530_probe into new mt7530_probe_common helper function which will be used by both, mt7530_probe and the to-be-introduced mt7988_probe. Signed-off-by: Daniel Golle Reviewed-by: Andrew Lunn --- drivers/net/dsa/mt7530.c | 86 ++++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 39 deletions(-) diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index 221d56cf9e710..32875762b3d96 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -3145,44 +3145,47 @@ static const struct of_device_id mt7530_of_match[] = =3D { MODULE_DEVICE_TABLE(of, mt7530_of_match); =20 static int -mt7530_probe(struct mdio_device *mdiodev) +mt7530_probe_common(struct mt7530_priv *priv) { - static struct regmap_config *regmap_config; - struct mt7530_priv *priv; - struct device_node *dn; - int ret; - - dn =3D mdiodev->dev.of_node; - - priv =3D devm_kzalloc(&mdiodev->dev, sizeof(*priv), GFP_KERNEL); - if (!priv) - return -ENOMEM; + struct device *dev =3D priv->dev; + struct device_node *dn =3D dev->of_node; =20 - priv->ds =3D devm_kzalloc(&mdiodev->dev, sizeof(*priv->ds), GFP_KERNEL); + priv->ds =3D devm_kzalloc(dev, sizeof(*priv->ds), GFP_KERNEL); if (!priv->ds) return -ENOMEM; =20 - priv->ds->dev =3D &mdiodev->dev; + priv->ds->dev =3D dev; priv->ds->num_ports =3D MT7530_NUM_PORTS; =20 /* Use medatek,mcm property to distinguish hardware type that would - * casues a little bit differences on power-on sequence. + * cause a little bit differences on power-on sequence. + * Note MCM that indicates switch works as the remote standalone + * integrated circuit so the GPIO pin would be used to complete + * the reset, otherwise memory-mapped register accessing used + * through syscon provides in the case of MCM. */ priv->mcm =3D of_property_read_bool(dn, "mediatek,mcm"); if (priv->mcm) { - dev_info(&mdiodev->dev, "MT7530 adapts as multi-chip module\n"); + dev_dbg(dev, "MT7530 adapts as multi-chip module\n"); =20 - priv->rstc =3D devm_reset_control_get(&mdiodev->dev, "mcm"); + priv->rstc =3D devm_reset_control_get(dev, "mcm"); if (IS_ERR(priv->rstc)) { - dev_err(&mdiodev->dev, "Couldn't get our reset line\n"); + dev_err(dev, "Couldn't get our reset line\n"); return PTR_ERR(priv->rstc); } + } else { + priv->reset =3D devm_gpiod_get_optional(dev, "reset", + GPIOD_OUT_LOW); + if (IS_ERR(priv->reset)) { + dev_err(dev, "Couldn't get our reset line\n"); + return PTR_ERR(priv->reset); + } } =20 /* Get the hardware identifier from the devicetree node. * We will need it for some of the clock and regulator setup. */ - priv->info =3D of_device_get_match_data(&mdiodev->dev); + priv->info =3D of_device_get_match_data(dev); if (!priv->info) return -EINVAL; =20 @@ -3196,6 +3199,32 @@ mt7530_probe(struct mdio_device *mdiodev) return -EINVAL; =20 priv->id =3D priv->info->id; + priv->dev =3D dev; + priv->ds->priv =3D priv; + priv->ds->ops =3D &mt7530_switch_ops; + mutex_init(&priv->reg_mutex); + dev_set_drvdata(dev, priv); + + return 0; +} + +static int +mt7530_probe(struct mdio_device *mdiodev) +{ + static struct regmap_config *regmap_config; + struct mt7530_priv *priv; + int ret; + + priv =3D devm_kzalloc(&mdiodev->dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->bus =3D mdiodev->bus; + priv->dev =3D &mdiodev->dev; + + ret =3D mt7530_probe_common(priv); + if (ret) + return ret; =20 if (priv->id =3D=3D ID_MT7530) { priv->core_pwr =3D devm_regulator_get(&mdiodev->dev, "core"); @@ -3207,27 +3236,6 @@ mt7530_probe(struct mdio_device *mdiodev) return PTR_ERR(priv->io_pwr); } =20 - /* Not MCM that indicates switch works as the remote standalone - * integrated circuit so the GPIO pin would be used to complete - * the reset, otherwise memory-mapped register accessing used - * through syscon provides in the case of MCM. - */ - if (!priv->mcm) { - priv->reset =3D devm_gpiod_get_optional(&mdiodev->dev, "reset", - GPIOD_OUT_LOW); - if (IS_ERR(priv->reset)) { - dev_err(&mdiodev->dev, "Couldn't get our reset line\n"); - return PTR_ERR(priv->reset); - } - } - - priv->bus =3D mdiodev->bus; - priv->dev =3D &mdiodev->dev; - priv->ds->priv =3D priv; - priv->ds->ops =3D &mt7530_switch_ops; - mutex_init(&priv->reg_mutex); - dev_set_drvdata(&mdiodev->dev, priv); - regmap_config =3D devm_kzalloc(&mdiodev->dev, sizeof(*regmap_config), GFP_KERNEL); if (!regmap_config) --=20 2.39.2