From patchwork Wed Mar 29 15:57:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 76705 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp537841vqo; Wed, 29 Mar 2023 09:28:29 -0700 (PDT) X-Google-Smtp-Source: AKy350a4s8E8RjKhVlL4egnEM1J+d1Kop1iNaCAXpMZY5WGNyJTUbA49Pv5FTgVkDYs9al/HoO8h X-Received: by 2002:a17:90b:4c45:b0:23d:35d9:d065 with SMTP id np5-20020a17090b4c4500b0023d35d9d065mr19136105pjb.48.1680107308905; Wed, 29 Mar 2023 09:28:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680107308; cv=none; d=google.com; s=arc-20160816; b=YDYwnJae9H+ii8MXsDclJQhrBaxDb7sJgMekmi+kWhjz5P/CUiwSVbkXGHF7EYqDSo KL2XShAIxvq4wECjZq+CdCPjhTAvG64z6F1mgjwIeIjD0AZOzpcgP3qoDQI4DuMppUh1 Tg4tdfOuwVZEPmoneASZJewDEpi4nnTFgcrJuQXgnpn3ZSKj86RZ5nZLxXY7HM82X50H csjaVLa8HMmPmhAuTnoUVLkUnYQtSSP7BEnYpPVmPPkRN9D+f/FrUy+uwjtG+ufL0QqI 8nJF269ZqjyrYJsxQWiBm6IKWizzsD/ZVdxpaUE31OhHEf7rNZ9fKYgGmlpNsvmF98rI VU3A== 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=25HbsLi2exhsO1Vdnh7+E6AZdHg4r2k8wl/WLyaBXRA=; b=hui07IY5bSZHMqRU1nydo9tt9UKL324cWWtVw0PMMisw8NfrjkGEJhVXx3T8DAg/lN me4pN12iec5YF1Ia0ebO5hglGn6N3ZoF8EQyGMeokvaQuEopvoPRxbIhlGvnRdlEWwr7 W9WgP3Hu7c4WIJoWLsQAgxdSi8Pj6pYZ4oFqn4fne0lvyN0AoQdnkRIXDeeihg/Cwqbh 2mhnDrNft1/+7XuvHsJ0RG11g1KLC7bC4BhLWgrgNwtCW0a+3RjI4C4XU2t2df2Nca38 JgETAic+I6emwLWU9TeIoB+iTWncNSkb9t6Vf0XZxz8bLxzpQFK51pMEJK5XIx4LaGpt q50w== 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 bg23-20020a17090b0d9700b0023cfd288a09si1623644pjb.157.2023.03.29.09.28.16; Wed, 29 Mar 2023 09:28:28 -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 S231318AbjC2P65 (ORCPT + 99 others); Wed, 29 Mar 2023 11:58:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231193AbjC2P6h (ORCPT ); Wed, 29 Mar 2023 11:58:37 -0400 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BCBB61AF; Wed, 29 Mar 2023 08:58:10 -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 1phYAv-0003K3-0f; Wed, 29 Mar 2023 17:57:25 +0200 Date: Wed, 29 Mar 2023 16:57:21 +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 01/15] net: dsa: mt7530: refactor SGMII PCS creation Message-ID: <921a8076420545206612e873753edfd0868e7a36.1680105013.git.daniel@makrotopia.org> 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?1761720201567748279?= X-GMAIL-MSGID: =?utf-8?q?1761720201567748279?= Instead of macro templates use a dedidated function and allocated regmap_config when creating the regmaps for the pcs-mtk-lynxi instances. This is in preparation to switching to use unlocked regmap accessors and have regmap's locking API handle locking for us. Signed-off-by: Daniel Golle --- drivers/net/dsa/mt7530.c | 74 +++++++++++++++++++++++++++------------- 1 file changed, 50 insertions(+), 24 deletions(-) diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index a0d99af897ace..9b88ce5cee5bd 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -2926,26 +2926,56 @@ static const struct regmap_bus mt7531_regmap_bus = { .reg_update_bits = mt7530_regmap_update_bits, }; -#define MT7531_PCS_REGMAP_CONFIG(_name, _reg_base) \ - { \ - .name = _name, \ - .reg_bits = 16, \ - .val_bits = 32, \ - .reg_stride = 4, \ - .reg_base = _reg_base, \ - .max_register = 0x17c, \ - } - -static const struct regmap_config mt7531_pcs_config[] = { - MT7531_PCS_REGMAP_CONFIG("port5", MT7531_SGMII_REG_BASE(5)), - MT7531_PCS_REGMAP_CONFIG("port6", MT7531_SGMII_REG_BASE(6)), -}; +static int +mt7531_create_sgmii(struct mt7530_priv *priv) +{ + struct regmap_config *mt7531_pcs_config[2]; + struct phylink_pcs *pcs; + struct regmap *regmap; + int i, ret = 0; + + for (i = 0; i < 2; i++) { + mt7531_pcs_config[i] = devm_kzalloc(priv->dev, + sizeof(struct regmap_config), + GFP_KERNEL); + if (!mt7531_pcs_config[i]) { + ret = -ENOMEM; + break; + } + + mt7531_pcs_config[i]->name = i ? "port6" : "port5"; + mt7531_pcs_config[i]->reg_bits = 16; + mt7531_pcs_config[i]->val_bits = 32; + mt7531_pcs_config[i]->reg_stride = 4; + mt7531_pcs_config[i]->reg_base = MT7531_SGMII_REG_BASE(5 + i); + mt7531_pcs_config[i]->max_register = 0x17c; + + regmap = devm_regmap_init(priv->dev, + &mt7531_regmap_bus, priv, + mt7531_pcs_config[i]); + if (IS_ERR(regmap)) { + ret = PTR_ERR(regmap); + break; + } + pcs = mtk_pcs_lynxi_create(priv->dev, regmap, + MT7531_PHYA_CTRL_SIGNAL3, 0); + if (!pcs) { + ret = -ENXIO; + break; + } + priv->ports[5 + i].sgmii_pcs = pcs; + } + + if (ret && i) + mtk_pcs_lynxi_destroy(priv->ports[5].sgmii_pcs); + + return ret; +} static int mt753x_setup(struct dsa_switch *ds) { struct mt7530_priv *priv = ds->priv; - struct regmap *regmap; int i, ret; /* Initialise the PCS devices */ @@ -2967,15 +2997,11 @@ mt753x_setup(struct dsa_switch *ds) if (ret && priv->irq) mt7530_free_irq_common(priv); - if (priv->id == ID_MT7531) - for (i = 0; i < 2; i++) { - regmap = devm_regmap_init(ds->dev, - &mt7531_regmap_bus, priv, - &mt7531_pcs_config[i]); - priv->ports[5 + i].sgmii_pcs = - mtk_pcs_lynxi_create(ds->dev, regmap, - MT7531_PHYA_CTRL_SIGNAL3, 0); - } + if (priv->id == ID_MT7531) { + ret = mt7531_create_sgmii(priv); + if (ret && priv->irq) + mt7530_free_irq_common(priv); + } return ret; }