From patchwork Wed Mar 29 15:58:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 76691 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp519785vqo; Wed, 29 Mar 2023 09:03:21 -0700 (PDT) X-Google-Smtp-Source: AKy350YFYLdqTNIGy9BcbpP/xtpFLXDlChs1MHY8C2ybWwoBMYjKmM8TrRz9SGdvAbYK7lLdjtt0 X-Received: by 2002:aa7:c846:0:b0:4fb:8d3c:3b86 with SMTP id g6-20020aa7c846000000b004fb8d3c3b86mr18860886edt.1.1680105800821; Wed, 29 Mar 2023 09:03:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680105800; cv=none; d=google.com; s=arc-20160816; b=UxoWUUPkCn4okl4Hc5+eWUMaps/je7CLvTTwfKLnPnm62pSPH801t+vhP45xNXNAzc jlvn1ZpPp9dyVc6jvD9W1vfjVPjzMFkCnZIJtzf9Yjry0JGlkBq8cay8twZqPIRE9HSk VZJvk8bDIla92Dz/LME8GtIGjpjfIQQ1mNQo63K8D4k2CJOGfSFctyy4SJfPjWgWdcl2 CuDlKUsXdNAWVxpo2W3iZxY2KQv1Qcyd0C73l7KzQGmAO8kI+qbDtPxo7W0O+mCeN5vf QErIWeqPSiXbfN3LSmtUjwrStlbtUfvDaw3EFoEKkU1HsKqsddXCA9M9YMy9iMcL0JGd uxBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=Za88rYgwgKn0WiofuSK1WGYOeJU3Yac28j/dIRDh7Ew=; b=ZMxDYDJN/Pq5PPfhDvQo7Twz8JiMQVQFdzttlDSQZd8Sqm2MuJNj8l+RluDmOcCum8 C61UQrJpBefW3q+CIOjkV9e0HPkmTnyfkgzG5yQul+KuG301U890SJqvsWBQ8TbHLm2p UR0VS3VzO/fWI69V9gJtYBvcnAB5A+aFEKQxayK++6R0F4R1VGk4395t7KcR8SDjZrdy ItnNc8e/lya5DmXM6vZyWPWqIH+Oa1zPhMBTmTiSRjGGR/Dz/Enmi2xprSuopJdEp7TB AxZA42xpJau75RGVXI1D6bRCv4Vp42DF0nqlk5qQYxpTfh15dvH+7APPK83E8OLuKnrh RhDg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j5-20020aa7c405000000b00502259be703si13527695edq.434.2023.03.29.09.02.52; Wed, 29 Mar 2023 09:03:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230216AbjC2QAP (ORCPT + 99 others); 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: X-Spam-Status: No, score=0.0 required=5.0 tests=SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761718620204628422?= X-GMAIL-MSGID: =?utf-8?q?1761718620204628422?= 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[] = { MODULE_DEVICE_TABLE(of, mt7530_of_match); 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 = mdiodev->dev.of_node; - - priv = devm_kzalloc(&mdiodev->dev, sizeof(*priv), GFP_KERNEL); - if (!priv) - return -ENOMEM; + struct device *dev = priv->dev; + struct device_node *dn = dev->of_node; - priv->ds = devm_kzalloc(&mdiodev->dev, sizeof(*priv->ds), GFP_KERNEL); + priv->ds = devm_kzalloc(dev, sizeof(*priv->ds), GFP_KERNEL); if (!priv->ds) return -ENOMEM; - priv->ds->dev = &mdiodev->dev; + priv->ds->dev = dev; priv->ds->num_ports = MT7530_NUM_PORTS; /* 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 = 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"); - priv->rstc = devm_reset_control_get(&mdiodev->dev, "mcm"); + priv->rstc = 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 = 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); + } } /* Get the hardware identifier from the devicetree node. * We will need it for some of the clock and regulator setup. */ - priv->info = of_device_get_match_data(&mdiodev->dev); + priv->info = of_device_get_match_data(dev); if (!priv->info) return -EINVAL; @@ -3196,6 +3199,32 @@ mt7530_probe(struct mdio_device *mdiodev) return -EINVAL; priv->id = priv->info->id; + priv->dev = dev; + priv->ds->priv = priv; + priv->ds->ops = &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 = devm_kzalloc(&mdiodev->dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->bus = mdiodev->bus; + priv->dev = &mdiodev->dev; + + ret = mt7530_probe_common(priv); + if (ret) + return ret; if (priv->id == ID_MT7530) { priv->core_pwr = devm_regulator_get(&mdiodev->dev, "core"); @@ -3207,27 +3236,6 @@ mt7530_probe(struct mdio_device *mdiodev) return PTR_ERR(priv->io_pwr); } - /* 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 = 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 = mdiodev->bus; - priv->dev = &mdiodev->dev; - priv->ds->priv = priv; - priv->ds->ops = &mt7530_switch_ops; - mutex_init(&priv->reg_mutex); - dev_set_drvdata(&mdiodev->dev, priv); - regmap_config = devm_kzalloc(&mdiodev->dev, sizeof(*regmap_config), GFP_KERNEL); if (!regmap_config)