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; } From patchwork Wed Mar 29 15:57:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 76707 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp540903vqo; Wed, 29 Mar 2023 09:33:02 -0700 (PDT) X-Google-Smtp-Source: AKy350YkkZyrFGfuGxMSfd5gMV4fVYuQsSlAAl58K+reVyytPzd9wAvDmlS8PKNbM1iKNaO0Uhzq X-Received: by 2002:a17:903:1c7:b0:19d:323:e68 with SMTP id e7-20020a17090301c700b0019d03230e68mr24231100plh.1.1680107582600; Wed, 29 Mar 2023 09:33:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680107582; cv=none; d=google.com; s=arc-20160816; b=oLcrSC5InLdrtoJOg05k6jUeBx0GufBYpaDhn+vSRiLpXK6jKlWy3GWQlsHMyw/a56 wqxqcOBqHzeXNP8SNJjWZAK6yZuinzIMdzVRSwKOd6pJkSANSuPDDPdeDd/a6ufwW3Mb mVP13aiurJMdZ1c56FC9J8SqYG/nDmMCBNbOy7hl8nDfkFooDMrKZyznClq1rFWfV1Ir 8oyOptCBw9yI3dwZ23Oo0WPxZhHdf1e5WoovuXNd+ub4DD5kEJmWmW9eYVl0HLtEuW3q fOzYUK4cY5TkKXnV39wxYxWkdaMaediiZpBzOUVCWE2d1L9W05xIBJzNCbQsO53BkY/X ijAA== 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=J6oly2xRWX9QImtXrd+etwvRvcekLzfKBndnbaLLUFM=; b=EuNxig8lK0jBb5jVvsLsTGsaIkcFAkajtIm+sWkAkXlrvf4CsWP7NAgWX/Vh+xWK9b zhonxEQlAfGy6EwYyaSGUmMiAsZhKI46AnqnF5rkG1iHdjA2T8Gyxja4TraeiOULsMNP 1QE8Firhx8Z3Pk5gjFFqDGlYiIUWPdT8gLjdpATh76on2jPRTPp1FKwpdVTMb8xpbPtz WKupI4ksEtJULixdJ4y4eaYO0BJFjjCOonKnuCZoUEZenEk/OduMX8U93cg277aOCDSr 7+NcIFm+4hbw75Lbw6+c+BTcH7sMbZf0fgTdbTHSp+8pgsp4BhZH1CCN10piMvGFM2PC 3sLw== 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 jb11-20020a170903258b00b001a216572122si12551715plb.285.2023.03.29.09.32.50; Wed, 29 Mar 2023 09:33:02 -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 S231243AbjC2P7g (ORCPT + 99 others); Wed, 29 Mar 2023 11:59:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231262AbjC2P6p (ORCPT ); Wed, 29 Mar 2023 11:58:45 -0400 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C2CF61B6; Wed, 29 Mar 2023 08:58:23 -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 1phYB6-0003Kc-2a; Wed, 29 Mar 2023 17:57:36 +0200 Date: Wed, 29 Mar 2023 16:57:32 +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 02/15] net: dsa: mt7530: use unlocked regmap accessors Message-ID: <1b79468f3043810ff8ec06a66cf8571738a13f72.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?1761720488444588609?= X-GMAIL-MSGID: =?utf-8?q?1761720488444588609?= Instead of wrapping the locked register accessor functions, use the unlocked variants and add wrappers to let regmap handle the locking. This is a preparation towards being able to always use regmap to access switch registers instead of open-coded accessor functions. Signed-off-by: Daniel Golle --- drivers/net/dsa/mt7530.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index 9b88ce5cee5bd..deb0b338b22c2 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -2899,7 +2899,7 @@ static int mt7530_regmap_read(void *context, unsigned int reg, unsigned int *val { struct mt7530_priv *priv = context; - *val = mt7530_read(priv, reg); + *val = mt7530_mii_read(priv, reg); return 0; }; @@ -2907,23 +2907,25 @@ static int mt7530_regmap_write(void *context, unsigned int reg, unsigned int val { struct mt7530_priv *priv = context; - mt7530_write(priv, reg, val); + mt7530_mii_write(priv, reg, val); return 0; }; -static int mt7530_regmap_update_bits(void *context, unsigned int reg, - unsigned int mask, unsigned int val) +static void +mt7530_mdio_regmap_lock(void *mdio_lock) { - struct mt7530_priv *priv = context; + mutex_lock_nested(mdio_lock, MDIO_MUTEX_NESTED); +} - mt7530_rmw(priv, reg, mask, val); - return 0; -}; +static void +mt7530_mdio_regmap_unlock(void *mdio_lock) +{ + mutex_unlock(mdio_lock); +} static const struct regmap_bus mt7531_regmap_bus = { .reg_write = mt7530_regmap_write, .reg_read = mt7530_regmap_read, - .reg_update_bits = mt7530_regmap_update_bits, }; static int @@ -2949,6 +2951,9 @@ mt7531_create_sgmii(struct mt7530_priv *priv) 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; + mt7531_pcs_config[i]->lock = mt7530_mdio_regmap_lock; + mt7531_pcs_config[i]->unlock = mt7530_mdio_regmap_unlock; + mt7531_pcs_config[i]->lock_arg = &priv->bus->mdio_lock; regmap = devm_regmap_init(priv->dev, &mt7531_regmap_bus, priv, From patchwork Wed Mar 29 15:57:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 76696 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp526172vqo; Wed, 29 Mar 2023 09:11:02 -0700 (PDT) X-Google-Smtp-Source: AKy350ZHkizrjpUL4zlXgLwuKdsqXQkAtRElug16deqJLG9vEUjeK41+bV39GJIGw57VhO/85IzE X-Received: by 2002:a17:906:b4e:b0:92f:2c64:9d43 with SMTP id v14-20020a1709060b4e00b0092f2c649d43mr20628634ejg.68.1680106262255; Wed, 29 Mar 2023 09:11:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680106262; cv=none; d=google.com; s=arc-20160816; b=VSC+Zn2qkzevugvz69MAHZ3LqEibvZ4lMeAgvgue4jpGwfvIkZnBtZb8YxWROjuv98 aVxPigdDfKP2q1mhv7qv8jpRDSxnuXs+dsbDkDKkzjH5lu9yRJEnCUHm96Ur/iIUUVUY Rllnn0aHzPufrFigYnNodeIS1sZHyZpfF1uBd+F8ixhQ9wS79G0YU6ajRr7epEgbdFOV jlsMPtwahrd2S1FxpLjhuDfs4j3LFkIt9RzsL4NWtRadVeCHF99i4P1c9ukJ1rESAQ1e JYYyuSpl+XDObwivI/KbHl3G/tPQAlo7bZHTIJk6sTUfXgxx4XSScu32iNokjAMfUfZT 80gA== 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=U5iV8Zt0YE88EP/zfjKUBLbCn0W/9z4Lyl0A9XTPuUY=; b=u85+4d7wOBURmTqu/aV/SmisHepPI9xF6tQ9LJJmKgUId7k3o34hn8C0UlnA0VBL3G jEr7T2jMcqTs0nReS8s177mzTm23QkWJMo2Q2XsYEAh+m1JWh3oa7EelpD0XIyZ90k8L N0mK57CklOfiH3iLtWSMPbaus4zjMo8zzgpA9S3hsEmoC3GEiN6tq6UkT8iOj24TWcUa 51cTp2JzCIgHFZLmQ1ZB65SMfR7JEBYmZxY+riG7XGrbteO40Z57532c9YH0vbWBVPI5 JeuzPJCPKhTFmZRIC+OLAX8QTxOHZ0FGmcySK+rVbjMVwwJsnPZBKrylJ+qlRRnfP9Nd MKSQ== 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 y15-20020a17090614cf00b00933c194cd1dsi24441106ejc.804.2023.03.29.09.10.38; Wed, 29 Mar 2023 09:11:02 -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 S231138AbjC2P7d (ORCPT + 99 others); Wed, 29 Mar 2023 11:59:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230514AbjC2P6p (ORCPT ); Wed, 29 Mar 2023 11:58:45 -0400 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABAD059F9; Wed, 29 Mar 2023 08:58:23 -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 1phYBI-0003LQ-0V; Wed, 29 Mar 2023 17:57:48 +0200 Date: Wed, 29 Mar 2023 16:57:44 +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 03/15] net: dsa: mt7530: use regmap to access switch register space Message-ID: <754322262cd754aee5916954b8e651989b229a09.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?1761719104251591768?= X-GMAIL-MSGID: =?utf-8?q?1761719104251591768?= Use regmap API to access the switch register space. Signed-off-by: Daniel Golle --- drivers/net/dsa/mt7530.c | 88 +++++++++++++++++++++++++--------------- drivers/net/dsa/mt7530.h | 2 + 2 files changed, 58 insertions(+), 32 deletions(-) diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index deb0b338b22c2..fffeac8d34855 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -183,9 +183,9 @@ core_clear(struct mt7530_priv *priv, u32 reg, u32 val) } static int -mt7530_mii_write(struct mt7530_priv *priv, u32 reg, u32 val) +mt7530_regmap_write(void *context, unsigned int reg, unsigned int val) { - struct mii_bus *bus = priv->bus; + struct mii_bus *bus = context; u16 page, r, lo, hi; int ret; @@ -197,24 +197,33 @@ mt7530_mii_write(struct mt7530_priv *priv, u32 reg, u32 val) /* MT7530 uses 31 as the pseudo port */ ret = bus->write(bus, 0x1f, 0x1f, page); if (ret < 0) - goto err; + return ret; ret = bus->write(bus, 0x1f, r, lo); if (ret < 0) - goto err; + return ret; ret = bus->write(bus, 0x1f, 0x10, hi); -err: + return ret; +} + +static int +mt7530_mii_write(struct mt7530_priv *priv, u32 reg, u32 val) +{ + int ret; + + ret = regmap_write(priv->regmap, reg, val); + if (ret < 0) - dev_err(&bus->dev, + dev_err(priv->dev, "failed to write mt7530 register\n"); return ret; } -static u32 -mt7530_mii_read(struct mt7530_priv *priv, u32 reg) +static int +mt7530_regmap_read(void *context, unsigned int reg, unsigned int *val) { - struct mii_bus *bus = priv->bus; + struct mii_bus *bus = context; u16 page, r, lo, hi; int ret; @@ -223,16 +232,31 @@ mt7530_mii_read(struct mt7530_priv *priv, u32 reg) /* MT7530 uses 31 as the pseudo port */ ret = bus->write(bus, 0x1f, 0x1f, page); - if (ret < 0) { - dev_err(&bus->dev, - "failed to read mt7530 register\n"); + if (ret < 0) return ret; - } lo = bus->read(bus, 0x1f, r); hi = bus->read(bus, 0x1f, 0x10); - return (hi << 16) | (lo & 0xffff); + *val = (hi << 16) | (lo & 0xffff); + + return 0; +} + +static u32 +mt7530_mii_read(struct mt7530_priv *priv, u32 reg) +{ + int ret; + u32 val; + + ret = regmap_read(priv->regmap, reg, &val); + if (ret) { + dev_err(priv->dev, + "failed to read mt7530 register\n"); + return ret; + } + + return val; } static void @@ -2895,22 +2919,6 @@ static const struct phylink_pcs_ops mt7530_pcs_ops = { .pcs_an_restart = mt7530_pcs_an_restart, }; -static int mt7530_regmap_read(void *context, unsigned int reg, unsigned int *val) -{ - struct mt7530_priv *priv = context; - - *val = mt7530_mii_read(priv, reg); - return 0; -}; - -static int mt7530_regmap_write(void *context, unsigned int reg, unsigned int val) -{ - struct mt7530_priv *priv = context; - - mt7530_mii_write(priv, reg, val); - return 0; -}; - static void mt7530_mdio_regmap_lock(void *mdio_lock) { @@ -2923,7 +2931,7 @@ mt7530_mdio_regmap_unlock(void *mdio_lock) mutex_unlock(mdio_lock); } -static const struct regmap_bus mt7531_regmap_bus = { +static const struct regmap_bus mt7530_regmap_bus = { .reg_write = mt7530_regmap_write, .reg_read = mt7530_regmap_read, }; @@ -2956,7 +2964,7 @@ mt7531_create_sgmii(struct mt7530_priv *priv) mt7531_pcs_config[i]->lock_arg = &priv->bus->mdio_lock; regmap = devm_regmap_init(priv->dev, - &mt7531_regmap_bus, priv, + &mt7530_regmap_bus, priv->bus, mt7531_pcs_config[i]); if (IS_ERR(regmap)) { ret = PTR_ERR(regmap); @@ -3127,6 +3135,7 @@ MODULE_DEVICE_TABLE(of, mt7530_of_match); static int mt7530_probe(struct mdio_device *mdiodev) { + static struct regmap_config *regmap_config; struct mt7530_priv *priv; struct device_node *dn; @@ -3206,6 +3215,21 @@ mt7530_probe(struct mdio_device *mdiodev) 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) + return -ENOMEM; + + regmap_config->reg_bits = 16; + regmap_config->val_bits = 32; + regmap_config->reg_stride = 4; + regmap_config->max_register = MT7530_CREV; + regmap_config->disable_locking = true; + priv->regmap = devm_regmap_init(priv->dev, &mt7530_regmap_bus, + priv->bus, regmap_config); + if (IS_ERR(priv->regmap)) + return PTR_ERR(priv->regmap); + return dsa_register_switch(priv->ds); } diff --git a/drivers/net/dsa/mt7530.h b/drivers/net/dsa/mt7530.h index c5d29f3fc1d80..39aaca50961bd 100644 --- a/drivers/net/dsa/mt7530.h +++ b/drivers/net/dsa/mt7530.h @@ -754,6 +754,7 @@ struct mt753x_info { * @dev: The device pointer * @ds: The pointer to the dsa core structure * @bus: The bus used for the device and built-in PHY + * @regmap: The regmap instance representing all switch registers * @rstc: The pointer to reset control used by MCM * @core_pwr: The power supplied into the core * @io_pwr: The power supplied into the I/O @@ -774,6 +775,7 @@ struct mt7530_priv { struct device *dev; struct dsa_switch *ds; struct mii_bus *bus; + struct regmap *regmap; struct reset_control *rstc; struct regulator *core_pwr; struct regulator *io_pwr; From patchwork Wed Mar 29 15:58:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 76701 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp536005vqo; Wed, 29 Mar 2023 09:25:09 -0700 (PDT) X-Google-Smtp-Source: AKy350al2PUyWA7uRJ/zk770X70RZgmuwcUaYmXgsWZQDI/D+0GLMvsyDprBBPX1jRIcwSAM/zC+ X-Received: by 2002:a05:6a20:4c82:b0:e1:204e:ddd6 with SMTP id fq2-20020a056a204c8200b000e1204eddd6mr5353011pzb.6.1680107109199; Wed, 29 Mar 2023 09:25:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680107109; cv=none; d=google.com; s=arc-20160816; b=NxIq0V79XeW7vuW6UazxvX5VFeIDiuE4QRboahCO6JIkkvrY85mgZzTXl4Un12+ehh Ff/j8VDXFATX8lFSK1uJBuEMfTRJ/hZkNs0qJyN0W8ymTn9Zs2eS6UPjYJXLHEykxobL wehmaW6pZlBHy5Vx90vB+e1zPhxt3Kg5SDV5PinQ7To/bKIoVhoK5B4LOqDUN5Xli67k e6nnVEZoa+qwbjDSyem8UL/Xl9juI+t3L+fuM4oPd6KNB54eR9bZbvGGcsSO00RLPcmp C8/R60VU6ZzudnJbomuo6pIExGjZfeB0b+LGNtxWbT2gGdGX3sSkc8CqqRTkiGRAkwVZ cunw== 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=gyBXOXVoCKA+b3WVcwiOCaoLDwhqDfZdCqHh5F/s6MA=; b=bBSyfqGj7LjmBNCb0svJRA1t2u1Tuj/g0XAOFeiEBmb7E1pWESmyn9OeJSE9xqtG0d AwpRmJkS1BDXNKzoydXSstzcQztgX/WreDp9oMP07JEcKxr8ro2dOQ/G7WM8ani5R+XI MmikG+pmo2bzmCkiTIVA/BgfNG7Ado5TtvcGX47MjGA4g8HI9wRphDkJUyq282705Ir2 u4kAH8wA7uZENHmkc8uI/PFKmNCrYeMr7PIz2gmtk746Biuk/x526Ztm7QMM7dxEjIj9 qp+ZDfkpVVeTmOfwnNGtrj9oFqU6Penm83YbrN+xBQ6ejWyKWMqn41yswN75WgTYjnl/ vYhg== 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 bd9-20020a056a00278900b00625683e6d41si32570460pfb.343.2023.03.29.09.24.55; Wed, 29 Mar 2023 09:25:09 -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 S231311AbjC2P7i (ORCPT + 99 others); Wed, 29 Mar 2023 11:59:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230218AbjC2P6r (ORCPT ); Wed, 29 Mar 2023 11:58:47 -0400 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9750865A9; Wed, 29 Mar 2023 08:58:25 -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 1phYBc-0003MM-1u; Wed, 29 Mar 2023 17:58:09 +0200 Date: Wed, 29 Mar 2023 16:58:04 +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 04/15] net: dsa: mt7530: move SGMII PCS creation to mt7530_probe 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?1761719992096208104?= X-GMAIL-MSGID: =?utf-8?q?1761719992096208104?= Move creating the SGMII PCS from mt753x_setup() to the more appropriate mt7530_probe() function. This is done also in preparation of moving all functions related to MDIO-connected MT753x switches to a separate module. Signed-off-by: Daniel Golle --- drivers/net/dsa/mt7530.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index fffeac8d34855..42c89d4863cd5 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -3010,12 +3010,6 @@ mt753x_setup(struct dsa_switch *ds) if (ret && priv->irq) mt7530_free_irq_common(priv); - if (priv->id == ID_MT7531) { - ret = mt7531_create_sgmii(priv); - if (ret && priv->irq) - mt7530_free_irq_common(priv); - } - return ret; } @@ -3138,6 +3132,7 @@ mt7530_probe(struct mdio_device *mdiodev) static struct regmap_config *regmap_config; struct mt7530_priv *priv; struct device_node *dn; + int ret; dn = mdiodev->dev.of_node; @@ -3230,6 +3225,12 @@ mt7530_probe(struct mdio_device *mdiodev) if (IS_ERR(priv->regmap)) return PTR_ERR(priv->regmap); + if (priv->id == ID_MT7531) { + ret = mt7531_create_sgmii(priv); + if (ret) + return ret; + } + return dsa_register_switch(priv->ds); } From patchwork Wed Mar 29 15:58:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 76706 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp540600vqo; Wed, 29 Mar 2023 09:32:36 -0700 (PDT) X-Google-Smtp-Source: AKy350YQQ/5CqwMi7haFuzBDEohXCtYDVS7tn/TyQYLzfl8/3TIfITo3Ndy93/ctKrn1/XXBgPPG X-Received: by 2002:a17:902:f693:b0:19a:9406:b234 with SMTP id l19-20020a170902f69300b0019a9406b234mr24209080plg.45.1680107556195; Wed, 29 Mar 2023 09:32:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680107556; cv=none; d=google.com; s=arc-20160816; b=zACz9n4OghBMuR1iDGPSoepMIQBriOIVxNW9DfPDEovzwOcFEsFx8TqdWp/PxeelDV RZqRqtMWzo56t81MlEd6jN/3M/X3iz8R4gMIPC9trHsN0FMlxSlbgGlQ2akJqvR1O9l4 HUb6Fkgm9H41Cv88ZtrsP7J30kF1RDcBdXozsy3Ro6fXID9cDelVwe3/eoDY331OsLHx OBpL4Sm/oeN7MPp97JnF04Yu49+jCuhD/BkcRt+rRUHifV6/UcKpKvQntHNzDXD1rIGU Wkofa4OE6hp1i/Mi7xyB5tukqUMCfXxb6DqT4x/W+v6Nn9qFwJ+qwkm8ELwnH4FiLrKT s1uQ== 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=JicQJBOXFrDWWxGLYRCrFrZzUf6exvsT/WdINPAJD5g=; b=Zizqf2EamEjRZfSOjNOwSbVhkkHSTIrnjYyzzL8tTNuZmg5Ep4hVdS87tzXigUGiHu TlSGuldIoizE/jJYmbZi78hKx31fvK81F8hX2Jb+JblXgW+MAJoKLOjLm+Qxi3Wj4tL5 rWEuf56C/tXNy2m31UapX21uhKyRp3Zjha1fhr4sUcfjbE9dCTSreW3rcK893SwVb9Z6 PkYW09jfwN5VZddFw4w/3kmTdRuSOp5sp9RCgWhViKtI8wKaGHrKmeaSrxSHndT2fenx X+h7kpNuvMrsqlpdUY3Ihgzh92Oby1YMOugLsB8SiVdPl8cNV13ZXLc27yuB8tguNnsJ l20Q== 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 ko5-20020a17090307c500b001a1fe40a8d7si15095848plb.520.2023.03.29.09.31.53; Wed, 29 Mar 2023 09:32:36 -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 S231352AbjC2P7k (ORCPT + 99 others); Wed, 29 Mar 2023 11:59:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230523AbjC2P6x (ORCPT ); Wed, 29 Mar 2023 11:58:53 -0400 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64D3D6A40; Wed, 29 Mar 2023 08:58:29 -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 1phYBu-0003My-26; Wed, 29 Mar 2023 17:58:26 +0200 Date: Wed, 29 Mar 2023 16:58:22 +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 05/15] net: dsa: mt7530: introduce mutex helpers Message-ID: <118badcdd9741d21e3d367e10c34a2d66ae04f59.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?1761720460824061168?= X-GMAIL-MSGID: =?utf-8?q?1761720460824061168?= As the MDIO bus lock only needs to be involved if actually operating on an MDIO-connected switch we will need to skip locking for built-in switches which are accessed via MMIO. Create helper functions which simplify that upcoming change. Signed-off-by: Daniel Golle Reviewed-by: Andrew Lunn --- drivers/net/dsa/mt7530.c | 72 ++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index 42c89d4863cd5..033e70b42b12a 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -143,31 +143,40 @@ core_write_mmd_indirect(struct mt7530_priv *priv, int prtad, } static void -core_write(struct mt7530_priv *priv, u32 reg, u32 val) +mt7530_mutex_lock(struct mt7530_priv *priv) { - struct mii_bus *bus = priv->bus; + mutex_lock_nested(&priv->bus->mdio_lock, MDIO_MUTEX_NESTED); +} - mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); +static void +mt7530_mutex_unlock(struct mt7530_priv *priv) +{ + mutex_unlock(&priv->bus->mdio_lock); +} + +static void +core_write(struct mt7530_priv *priv, u32 reg, u32 val) +{ + mt7530_mutex_lock(priv); core_write_mmd_indirect(priv, reg, MDIO_MMD_VEND2, val); - mutex_unlock(&bus->mdio_lock); + mt7530_mutex_unlock(priv); } static void core_rmw(struct mt7530_priv *priv, u32 reg, u32 mask, u32 set) { - struct mii_bus *bus = priv->bus; u32 val; - mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); + mt7530_mutex_lock(priv); val = core_read_mmd_indirect(priv, reg, MDIO_MMD_VEND2); val &= ~mask; val |= set; core_write_mmd_indirect(priv, reg, MDIO_MMD_VEND2, val); - mutex_unlock(&bus->mdio_lock); + mt7530_mutex_unlock(priv); } static void @@ -262,13 +271,11 @@ mt7530_mii_read(struct mt7530_priv *priv, u32 reg) static void mt7530_write(struct mt7530_priv *priv, u32 reg, u32 val) { - struct mii_bus *bus = priv->bus; - - mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); + mt7530_mutex_lock(priv); mt7530_mii_write(priv, reg, val); - mutex_unlock(&bus->mdio_lock); + mt7530_mutex_unlock(priv); } static u32 @@ -280,14 +287,13 @@ _mt7530_unlocked_read(struct mt7530_dummy_poll *p) static u32 _mt7530_read(struct mt7530_dummy_poll *p) { - struct mii_bus *bus = p->priv->bus; u32 val; - mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); + mt7530_mutex_lock(p->priv); val = mt7530_mii_read(p->priv, p->reg); - mutex_unlock(&bus->mdio_lock); + mt7530_mutex_unlock(p->priv); return val; } @@ -305,17 +311,16 @@ static void mt7530_rmw(struct mt7530_priv *priv, u32 reg, u32 mask, u32 set) { - struct mii_bus *bus = priv->bus; u32 val; - mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); + mt7530_mutex_lock(priv); val = mt7530_mii_read(priv, reg); val &= ~mask; val |= set; mt7530_mii_write(priv, reg, val); - mutex_unlock(&bus->mdio_lock); + mt7530_mutex_unlock(priv); } static void @@ -659,14 +664,13 @@ static int mt7531_ind_c45_phy_read(struct mt7530_priv *priv, int port, int devad, int regnum) { - struct mii_bus *bus = priv->bus; struct mt7530_dummy_poll p; u32 reg, val; int ret; INIT_MT7530_DUMMY_POLL(&p, priv, MT7531_PHY_IAC); - mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); + mt7530_mutex_lock(priv); ret = readx_poll_timeout(_mt7530_unlocked_read, &p, val, !(val & MT7531_PHY_ACS_ST), 20, 100000); @@ -699,7 +703,7 @@ mt7531_ind_c45_phy_read(struct mt7530_priv *priv, int port, int devad, ret = val & MT7531_MDIO_RW_DATA_MASK; out: - mutex_unlock(&bus->mdio_lock); + mt7530_mutex_unlock(priv); return ret; } @@ -708,14 +712,13 @@ static int mt7531_ind_c45_phy_write(struct mt7530_priv *priv, int port, int devad, int regnum, u16 data) { - struct mii_bus *bus = priv->bus; struct mt7530_dummy_poll p; u32 val, reg; int ret; INIT_MT7530_DUMMY_POLL(&p, priv, MT7531_PHY_IAC); - mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); + mt7530_mutex_lock(priv); ret = readx_poll_timeout(_mt7530_unlocked_read, &p, val, !(val & MT7531_PHY_ACS_ST), 20, 100000); @@ -747,7 +750,7 @@ mt7531_ind_c45_phy_write(struct mt7530_priv *priv, int port, int devad, } out: - mutex_unlock(&bus->mdio_lock); + mt7530_mutex_unlock(priv); return ret; } @@ -755,14 +758,13 @@ mt7531_ind_c45_phy_write(struct mt7530_priv *priv, int port, int devad, static int mt7531_ind_c22_phy_read(struct mt7530_priv *priv, int port, int regnum) { - struct mii_bus *bus = priv->bus; struct mt7530_dummy_poll p; int ret; u32 val; INIT_MT7530_DUMMY_POLL(&p, priv, MT7531_PHY_IAC); - mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); + mt7530_mutex_lock(priv); ret = readx_poll_timeout(_mt7530_unlocked_read, &p, val, !(val & MT7531_PHY_ACS_ST), 20, 100000); @@ -785,7 +787,7 @@ mt7531_ind_c22_phy_read(struct mt7530_priv *priv, int port, int regnum) ret = val & MT7531_MDIO_RW_DATA_MASK; out: - mutex_unlock(&bus->mdio_lock); + mt7530_mutex_unlock(priv); return ret; } @@ -794,14 +796,13 @@ static int mt7531_ind_c22_phy_write(struct mt7530_priv *priv, int port, int regnum, u16 data) { - struct mii_bus *bus = priv->bus; struct mt7530_dummy_poll p; int ret; u32 reg; INIT_MT7530_DUMMY_POLL(&p, priv, MT7531_PHY_IAC); - mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); + mt7530_mutex_lock(priv); ret = readx_poll_timeout(_mt7530_unlocked_read, &p, reg, !(reg & MT7531_PHY_ACS_ST), 20, 100000); @@ -823,7 +824,7 @@ mt7531_ind_c22_phy_write(struct mt7530_priv *priv, int port, int regnum, } out: - mutex_unlock(&bus->mdio_lock); + mt7530_mutex_unlock(priv); return ret; } @@ -1104,7 +1105,6 @@ static int mt7530_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu) { struct mt7530_priv *priv = ds->priv; - struct mii_bus *bus = priv->bus; int length; u32 val; @@ -1115,7 +1115,7 @@ mt7530_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu) if (!dsa_is_cpu_port(ds, port)) return 0; - mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); + mt7530_mutex_lock(priv); val = mt7530_mii_read(priv, MT7530_GMACCR); val &= ~MAX_RX_PKT_LEN_MASK; @@ -1136,7 +1136,7 @@ mt7530_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu) mt7530_mii_write(priv, MT7530_GMACCR, val); - mutex_unlock(&bus->mdio_lock); + mt7530_mutex_unlock(priv); return 0; } @@ -1937,10 +1937,10 @@ mt7530_irq_thread_fn(int irq, void *dev_id) u32 val; int p; - mutex_lock_nested(&priv->bus->mdio_lock, MDIO_MUTEX_NESTED); + mt7530_mutex_lock(priv); val = mt7530_mii_read(priv, MT7530_SYS_INT_STS); mt7530_mii_write(priv, MT7530_SYS_INT_STS, val); - mutex_unlock(&priv->bus->mdio_lock); + mt7530_mutex_unlock(priv); for (p = 0; p < MT7530_NUM_PHYS; p++) { if (BIT(p) & val) { @@ -1976,7 +1976,7 @@ mt7530_irq_bus_lock(struct irq_data *d) { struct mt7530_priv *priv = irq_data_get_irq_chip_data(d); - mutex_lock_nested(&priv->bus->mdio_lock, MDIO_MUTEX_NESTED); + mt7530_mutex_lock(priv); } static void @@ -1985,7 +1985,7 @@ mt7530_irq_bus_sync_unlock(struct irq_data *d) struct mt7530_priv *priv = irq_data_get_irq_chip_data(d); mt7530_mii_write(priv, MT7530_SYS_INT_EN, priv->irq_enable); - mutex_unlock(&priv->bus->mdio_lock); + mt7530_mutex_unlock(priv); } static struct irq_chip mt7530_irq_chip = { From patchwork Wed Mar 29 15:58:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 76690 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp519688vqo; Wed, 29 Mar 2023 09:03:14 -0700 (PDT) X-Google-Smtp-Source: AKy350ZS+LtDh6PLAyr638PCguubSBahzZ8zw9RsqOTCNJKWSVpo0B6K1nqC4F+4AejT5G8ynFeS X-Received: by 2002:a17:906:2759:b0:930:8fd7:789f with SMTP id a25-20020a170906275900b009308fd7789fmr18077370ejd.38.1680105794461; Wed, 29 Mar 2023 09:03:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680105794; cv=none; d=google.com; s=arc-20160816; b=M3+kURi3QrfJu51LU1G6nspbPcQkcZHxuk7RcEwL0SGtEbY5ycPm2lztvYyySSaZER UTnj+rGrA2Vwo6S+cA8AaFuyMdpVTk/STI9l+QoLRIdm/5rf5b9v5E3GqWVpem643Qf7 DNeZEXLaT4uyG7KWwxLAbIqesBwfzF7NMYJQ+ouoLTjgEoriE9f/quTk7LMPW0xVUrGc PUSnRwt3hYzeAsPAbT6ScUXXnUgYG9ha+Q9cuD/k222AmAsI74ZLI+xSzAhMRK6+KpzB ve+0ST1DkNGtmTEPN8ePVPkVJfFTapoodFYV4V6rralR8EmjKZReBslX1mJ6vGsPko7v UBCg== 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=X/vg3LHJEYX8njHmHR1XRnTW1s07I4OfY1UbowpGtCQ=; b=o6H5o99oKe5hj0a03hCXqY8QuWYv/YX0SWmzdcTQQI5BmiIlUd2XmdyqaEMvLzrCg0 w2n6rKYkDZ2d1y2f+3OsLE98GATL5g6pHu+HVnayJ2D37my5FOVjyEBGnrYnv5iNDKvs 3ino9W2WTAoQv+KIzr6vkm2WkJqER8ecIpvTIaKsoI2yMhaMnE+HD5P56MpimTxCP5nJ cEf67VQGJxDNlUpt01pOCFR1tGc5UP1isxTZR1HjsCPGtAEjPSTrEEbwABjboDmgbTmf iiP4KQD3qyZS2MikpnEarkyzvJVRmvGLJn+gXJMEwp4OwBZ1zngohWcv0qbAo5cKOlr2 knsg== 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 sg13-20020a170907a40d00b009334637f8a5si34206901ejc.125.2023.03.29.09.02.45; Wed, 29 Mar 2023 09:03:14 -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 S229983AbjC2QAK (ORCPT + 99 others); Wed, 29 Mar 2023 12:00:10 -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 S231437AbjC2P7R (ORCPT ); Wed, 29 Mar 2023 11:59:17 -0400 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D017059E7; Wed, 29 Mar 2023 08:58:42 -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 1phYC7-0003Ne-1w; Wed, 29 Mar 2023 17:58:40 +0200 Date: Wed, 29 Mar 2023 16:58:35 +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 06/15] net: dsa: mt7530: move p5_intf_modes() function to mt7530.c Message-ID: <98fc2eec00985854010e3d0d16ba7f4c924ab49f.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?1761718613297212901?= X-GMAIL-MSGID: =?utf-8?q?1761718613297212901?= In preparation of splitting mt7530.c into a driver for MDIO-connected as well as MDIO-accessed built-in switches on one hand and MMIO-accessed built-in switches move the p5_inft_modes() function from mt7530.h to mt7530.c. The function is only needed there and will trigger a compiler warning about a defined but unused function otherwise when including mt7530.h in the to-be-introduced bus-specific drivers. Signed-off-by: Daniel Golle Reviewed-by: Andrew Lunn --- drivers/net/dsa/mt7530.c | 18 ++++++++++++++++++ drivers/net/dsa/mt7530.h | 18 ------------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index 033e70b42b12a..221d56cf9e710 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -946,6 +946,24 @@ mt7530_set_ageing_time(struct dsa_switch *ds, unsigned int msecs) return 0; } +static const char *p5_intf_modes(unsigned int p5_interface) +{ + switch (p5_interface) { + case P5_DISABLED: + return "DISABLED"; + case P5_INTF_SEL_PHY_P0: + return "PHY P0"; + case P5_INTF_SEL_PHY_P4: + return "PHY P4"; + case P5_INTF_SEL_GMAC5: + return "GMAC5"; + case P5_INTF_SEL_GMAC5_SGMII: + return "GMAC5_SGMII"; + default: + return "unknown"; + } +} + static void mt7530_setup_port5(struct dsa_switch *ds, phy_interface_t interface) { struct mt7530_priv *priv = ds->priv; diff --git a/drivers/net/dsa/mt7530.h b/drivers/net/dsa/mt7530.h index 39aaca50961bd..2a611173a7d08 100644 --- a/drivers/net/dsa/mt7530.h +++ b/drivers/net/dsa/mt7530.h @@ -682,24 +682,6 @@ enum p5_interface_select { P5_INTF_SEL_GMAC5_SGMII, }; -static const char *p5_intf_modes(unsigned int p5_interface) -{ - switch (p5_interface) { - case P5_DISABLED: - return "DISABLED"; - case P5_INTF_SEL_PHY_P0: - return "PHY P0"; - case P5_INTF_SEL_PHY_P4: - return "PHY P4"; - case P5_INTF_SEL_GMAC5: - return "GMAC5"; - case P5_INTF_SEL_GMAC5_SGMII: - return "GMAC5_SGMII"; - default: - return "unknown"; - } -} - struct mt7530_priv; struct mt753x_pcs { 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) From patchwork Wed Mar 29 15:59:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 76693 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp524284vqo; Wed, 29 Mar 2023 09:08:32 -0700 (PDT) X-Google-Smtp-Source: AKy350YdmM4RIQvZRAK13TLXsl5AxkSWDjD4W/lGY++0Idw1FhAoY57/UX3SfaPjx9jjHeGlyaUA X-Received: by 2002:a17:90b:4c08:b0:237:97a3:1479 with SMTP id na8-20020a17090b4c0800b0023797a31479mr22943521pjb.28.1680106111837; Wed, 29 Mar 2023 09:08:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680106111; cv=none; d=google.com; s=arc-20160816; b=l94tj3iEN3GrGF+y9/x5cRPcvKfKt3vBp022PbyxeMgYs2Wgt8dz0hfm8jaWKyTzEE OO08QMry/QbzLQN4RLVHB2zYPfmOSfkTIgWqDUVjiwGP1v/udze+fa02Gsy7wIifD7Zh Mxg4MQmS/K6vtaNGQCKXEERsqnPmnI0HK3GFzxjsBQxzz50vSvdjSgoE6LNau7AeQ2rj 2XQRFb64D3P6gfw01iyWhdCP/wwadFgwwJYYQr+TM+h2yGIdyohERxJvb5S4WxMpH5cC VS5apnJ2RkI3yB7szoeaKnFPwRLy4KNQWJR4ls/03/nzUTZ+WIyVefuBp+yJvQ5DTVYL MlLQ== 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=l+DkvKIc4UikUz+XgK4Ir0YY4PqE6BVizpiJNliG644=; b=N4LhLnWSoOkQXkDSi1585V3SqshWPrxrp54jnIVTVefZiCcOKcuNrECQ5KTPb9QcXr v6EsexygWHkCqg6ddJnOnC3ASCKZsK5djW+bK8dgeQkfBEDkFvWhwEro9H9ZeDSoVKUh fRVZz/jgzJ/xfhIR8/tSVYLK9t/Y4quAfanODWLbmD7ncrh7+fVzXLeeLJWkoLQNLuGj BdNfeM/i31rREOubLBdaxQIEWk3UhKtHyPdiFTbnQnZ8kRPMcKC0kiu+ESixI0Y9Ny5Y jmfVEUunqZlHGdPO8TeymB4bsKoQJW+/6Bf8Nryafn3HDOx4xmtZcA5oG73A+kkuTbR+ Vq5g== 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 hk7-20020a17090b224700b00233ebd4c537si1759036pjb.22.2023.03.29.09.08.18; Wed, 29 Mar 2023 09:08:31 -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 S230461AbjC2QAZ (ORCPT + 99 others); Wed, 29 Mar 2023 12:00:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231396AbjC2P7m (ORCPT ); Wed, 29 Mar 2023 11:59:42 -0400 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36E425FCA; Wed, 29 Mar 2023 08:59:12 -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 1phYCZ-0003PD-0M; Wed, 29 Mar 2023 17:59:07 +0200 Date: Wed, 29 Mar 2023 16:59:03 +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 08/15] net: dsa: mt7530: introduce mt7530_remove_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?1761718946377567648?= X-GMAIL-MSGID: =?utf-8?q?1761718946377567648?= Move commonly used parts from mt7530_remove into new mt7530_remove_common helper function which will be used by both, mt7530_remove and the to-be-introduced mt7988_remove. Signed-off-by: Daniel Golle Reviewed-by: Andrew Lunn --- drivers/net/dsa/mt7530.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index 32875762b3d96..f84cbd251d1c1 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -3260,6 +3260,17 @@ mt7530_probe(struct mdio_device *mdiodev) return dsa_register_switch(priv->ds); } +static void +mt7530_remove_common(struct mt7530_priv *priv) +{ + if (priv->irq) + mt7530_free_irq(priv); + + dsa_unregister_switch(priv->ds); + + mutex_destroy(&priv->reg_mutex); +} + static void mt7530_remove(struct mdio_device *mdiodev) { @@ -3279,15 +3290,10 @@ mt7530_remove(struct mdio_device *mdiodev) dev_err(priv->dev, "Failed to disable io pwr: %d\n", ret); - if (priv->irq) - mt7530_free_irq(priv); - - dsa_unregister_switch(priv->ds); + mt7530_remove_common(priv); for (i = 0; i < 2; ++i) mtk_pcs_lynxi_destroy(priv->ports[5 + i].sgmii_pcs); - - mutex_destroy(&priv->reg_mutex); } static void mt7530_shutdown(struct mdio_device *mdiodev) From patchwork Wed Mar 29 15:59:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 76692 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp520025vqo; Wed, 29 Mar 2023 09:03:35 -0700 (PDT) X-Google-Smtp-Source: AKy350bJp2cpX/uzhDYrPOiSAYnJyJGgFAnfCMvmrgBJ9mgKDeyiWpw13IZmIy3baTlI6zSTl35B X-Received: by 2002:aa7:c914:0:b0:4af:69b8:52af with SMTP id b20-20020aa7c914000000b004af69b852afmr18417166edt.24.1680105815724; Wed, 29 Mar 2023 09:03:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680105815; cv=none; d=google.com; s=arc-20160816; b=I3Y7x0gRPQNH56NsMkRcOFLsPvnW5eDplkkaOZ9y1dEGkrg5//TSMv3fIvFQRlibf7 SCvP8mUI7eb+x/6f/CQ/IGLAbQw+3CLCiZMGStLpn8a8mTlfG8RV3HejBI1NbPwRCMHU K+NNlxcO8mq1CYDCqtGleYbLtIKT9T5+OKgsQiaDklcTNu6Es5y3PeW+kUThDmX/938H pDtxgLRu7xQBIbN78goMoTj7nxaojtVZOIGPda8IV2cPFbHw25Di/CLeQXMEqOTtEEMG 8DUedtHn2NYNm9pXxrwsnltHfeiBBlYLlLSGLkK1yUBQq/xOvvQLGZlb8KTO+Y53yh8l oDkQ== 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=03QvlqFdlMOrwEhzI7IdSTJLC4P0hb76uaLHOPX/5Yw=; b=KGPDaWf90P6WmHsNymI0uTN5LZq+pnZTBj8Mhd+GfVfTo5pZ9C0tIoB+R2iuU8HKGm VFmv4uLljxD62zXMBQ6GKI+0d9eRA6+ReJ08MNy62wQkf8WQVovgiN5X5uq298L+LvJ5 am9NvWDwbRDL0nwTbDQaoNopd7yapNPLHBOx1dzAQFOo7/GkwoorXzB+wazfeKoa6P2A nUQ3Qze4UeGFnYH1YVzeYZZYcTBElCblI/AwTL+md9toNFzmer11CMcn2ItWmNvDxpTD EFgyyClxGHYpyri2x8s6lgssomDvm+Ok9wvX7A773pewHI22/atWSw9vP2bk2uf97XLz CNkQ== 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 n5-20020a056402514500b004fafb8d85e2si31075320edd.309.2023.03.29.09.03.11; Wed, 29 Mar 2023 09:03:35 -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 S230506AbjC2QA1 (ORCPT + 99 others); Wed, 29 Mar 2023 12:00:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231593AbjC2P7w (ORCPT ); Wed, 29 Mar 2023 11:59:52 -0400 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E46AE525A; Wed, 29 Mar 2023 08:59:21 -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 1phYCk-0003Pu-2L; Wed, 29 Mar 2023 17:59:19 +0200 Date: Wed, 29 Mar 2023 16:59:13 +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 09/15] net: dsa: mt7530: split-off common parts from mt7531_setup Message-ID: <8e3a00982abc91dfc724ba1a21cbcd9f865f8650.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?1761718636104303056?= X-GMAIL-MSGID: =?utf-8?q?1761718636104303056?= MT7988 shares a significant part of the setup function with MT7531. Split-off those parts into a shared function which is going to be used also by mt7988_setup. Signed-off-by: Daniel Golle Reviewed-by: Andrew Lunn --- drivers/net/dsa/mt7530.c | 99 ++++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 44 deletions(-) diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index f84cbd251d1c1..c9b6b11273683 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -2350,12 +2350,65 @@ mt7530_setup(struct dsa_switch *ds) return 0; } +static int +mt7531_setup_common(struct dsa_switch *ds) +{ + struct mt7530_priv *priv = ds->priv; + struct dsa_port *cpu_dp; + int ret, i; + + /* BPDU to CPU port */ + dsa_switch_for_each_cpu_port(cpu_dp, ds) { + mt7530_rmw(priv, MT7531_CFC, MT7531_CPU_PMAP_MASK, + BIT(cpu_dp->index)); + break; + } + mt7530_rmw(priv, MT753X_BPC, MT753X_BPDU_PORT_FW_MASK, + MT753X_BPDU_CPU_ONLY); + + /* Enable and reset MIB counters */ + mt7530_mib_reset(ds); + + for (i = 0; i < MT7530_NUM_PORTS; i++) { + /* Disable forwarding by default on all ports */ + mt7530_rmw(priv, MT7530_PCR_P(i), PCR_MATRIX_MASK, + PCR_MATRIX_CLR); + + /* Disable learning by default on all ports */ + mt7530_set(priv, MT7530_PSC_P(i), SA_DIS); + + mt7530_set(priv, MT7531_DBG_CNT(i), MT7531_DIS_CLR); + + if (dsa_is_cpu_port(ds, i)) { + ret = mt753x_cpu_port_enable(ds, i); + if (ret) + return ret; + } else { + mt7530_port_disable(ds, i); + + /* Set default PVID to 0 on all user ports */ + mt7530_rmw(priv, MT7530_PPBV1_P(i), G0_PORT_VID_MASK, + G0_PORT_VID_DEF); + } + + /* Enable consistent egress tag */ + mt7530_rmw(priv, MT7530_PVC_P(i), PVC_EG_TAG_MASK, + PVC_EG_TAG(MT7530_VLAN_EG_CONSISTENT)); + } + + /* Flush the FDB table */ + ret = mt7530_fdb_cmd(priv, MT7530_FDB_FLUSH, NULL); + if (ret < 0) + return ret; + + return 0; +} + static int mt7531_setup(struct dsa_switch *ds) { struct mt7530_priv *priv = ds->priv; struct mt7530_dummy_poll p; - struct dsa_port *cpu_dp; u32 val, id; int ret, i; @@ -2433,44 +2486,7 @@ mt7531_setup(struct dsa_switch *ds) mt7531_ind_c45_phy_write(priv, MT753X_CTRL_PHY_ADDR, MDIO_MMD_VEND2, CORE_PLL_GROUP4, val); - /* BPDU to CPU port */ - dsa_switch_for_each_cpu_port(cpu_dp, ds) { - mt7530_rmw(priv, MT7531_CFC, MT7531_CPU_PMAP_MASK, - BIT(cpu_dp->index)); - break; - } - mt7530_rmw(priv, MT753X_BPC, MT753X_BPDU_PORT_FW_MASK, - MT753X_BPDU_CPU_ONLY); - - /* Enable and reset MIB counters */ - mt7530_mib_reset(ds); - - for (i = 0; i < MT7530_NUM_PORTS; i++) { - /* Disable forwarding by default on all ports */ - mt7530_rmw(priv, MT7530_PCR_P(i), PCR_MATRIX_MASK, - PCR_MATRIX_CLR); - - /* Disable learning by default on all ports */ - mt7530_set(priv, MT7530_PSC_P(i), SA_DIS); - - mt7530_set(priv, MT7531_DBG_CNT(i), MT7531_DIS_CLR); - - if (dsa_is_cpu_port(ds, i)) { - ret = mt753x_cpu_port_enable(ds, i); - if (ret) - return ret; - } else { - mt7530_port_disable(ds, i); - - /* Set default PVID to 0 on all user ports */ - mt7530_rmw(priv, MT7530_PPBV1_P(i), G0_PORT_VID_MASK, - G0_PORT_VID_DEF); - } - - /* Enable consistent egress tag */ - mt7530_rmw(priv, MT7530_PVC_P(i), PVC_EG_TAG_MASK, - PVC_EG_TAG(MT7530_VLAN_EG_CONSISTENT)); - } + mt7531_setup_common(ds); /* Setup VLAN ID 0 for VLAN-unaware bridges */ ret = mt7530_setup_vlan0(priv); @@ -2480,11 +2496,6 @@ mt7531_setup(struct dsa_switch *ds) ds->assisted_learning_on_cpu_port = true; ds->mtu_enforcement_ingress = true; - /* Flush the FDB table */ - ret = mt7530_fdb_cmd(priv, MT7530_FDB_FLUSH, NULL); - if (ret < 0) - return ret; - return 0; } From patchwork Wed Mar 29 15:59:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 76694 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp524306vqo; Wed, 29 Mar 2023 09:08:33 -0700 (PDT) X-Google-Smtp-Source: AKy350ZcfxypWNeXx42Vp5KyWytQ7GtOo8F0V8deBYFi8/mk555QbNMAguF3jp2+lDQENlbZxErS X-Received: by 2002:a05:6a20:3b8f:b0:df:83fe:fb55 with SMTP id b15-20020a056a203b8f00b000df83fefb55mr11368890pzh.35.1680106113407; Wed, 29 Mar 2023 09:08:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680106113; cv=none; d=google.com; s=arc-20160816; b=uZYLV0htCYBWQ5nAnnWH4B/xkineqwjwVSjExJcebv5vikxn+FU4QNOCgRMAFqd8qi fyNZmdUP6H8x5kR4Hg42pyKWUfpVyXR6iH+HelJODT8GY/5+QCjQi7iRpUV+8PHDZ07t sW7PGsFLiiRDpg0qSgxmak/nxg7ftWEE/MbPFXYfqRF5Jda4c2mn9tg2TWNGrHUN0u61 EKa/lgBR4NIB52Y/eo0VN30FOytDYUp7zm6e/UcrgRtUIPvnqYsI6tQivD0aZfvLNApL iFqrzCrOIc9DozxeD4V8HeiubEBvaO7czG5oLf7x6LJXKMVIY0++Les2g1vUZXUTew8l sYHw== 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=h6DLOLyVTei12nVBBTBCyqkCLmKmFf6CqMJ5KT0rj6c=; b=Fj7OGQtyQIyHJ/LrCBhXz1+hvrmspLKROH54k9K+prynob3pP0xBHZno+77JN0ts+m 5NbUWKkscQOLMHohTYZdcBBrSa9yYMbaUHHrm5T1LqDRcAMoEkoKsW4Rm0zAr1xR6mkt HDeCg2ECWPxRmlY5fvOkSwey/MuV0cGqhSqmpttcqe0t4r9viNhqaAZByYHbtjdx2Cze 4NI76WahXxMfIn5h4hqiYxfPpJRD3p0DLcCOOKdxuQXlw9WglpuTZk5kdTHjcOYlaysE n3TuQWpixfT9OmW3Rnio+RwIFHneaZ2kN5MXmCzPz0TT31WaFeEwArDrFa+p+09EdN8c pd9A== 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 e16-20020a63db10000000b0050308cba870si32062264pgg.137.2023.03.29.09.08.20; Wed, 29 Mar 2023 09:08:33 -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 S229608AbjC2QBq (ORCPT + 99 others); Wed, 29 Mar 2023 12:01:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231719AbjC2QAG (ORCPT ); Wed, 29 Mar 2023 12:00:06 -0400 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE8E76A5F; Wed, 29 Mar 2023 08:59:38 -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 1phYD0-0003Qe-2m; Wed, 29 Mar 2023 17:59:36 +0200 Date: Wed, 29 Mar 2023 16:59:30 +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 10/15] net: dsa: mt7530: introduce separate MDIO driver Message-ID: <2bef9ef442261e26d4d933f101f4a25c0f3aad2a.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?1761718947733675438?= X-GMAIL-MSGID: =?utf-8?q?1761718947733675438?= Split MT7530 switch driver into a common part and a part specific for MDIO connected switches and multi-chip modules. Move MDIO-specific functions to newly introduced mt7530-mdio.c while keeping the common parts in mt7530.c. In order to maintain compatibility with existing kernel configurations keep CONFIG_NET_DSA_MT7530 as symbol to select the MDIO-specific driver while the newly introduced hidden symbol CONFIG_NET_DSA_MT7530_COMMON is selected by CONFIG_NET_DSA_MT7530. Signed-off-by: Daniel Golle Reviewed-by: Andrew Lunn --- MAINTAINERS | 1 + drivers/net/dsa/Kconfig | 16 ++- drivers/net/dsa/Makefile | 3 +- drivers/net/dsa/mt7530-mdio.c | 242 ++++++++++++++++++++++++++++++++++ drivers/net/dsa/mt7530.c | 235 ++------------------------------- drivers/net/dsa/mt7530.h | 6 + 6 files changed, 271 insertions(+), 232 deletions(-) create mode 100644 drivers/net/dsa/mt7530-mdio.c diff --git a/MAINTAINERS b/MAINTAINERS index fbbda4671e734..7feb52d9ae0b9 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13176,6 +13176,7 @@ M: Landen Chao M: DENG Qingfang L: netdev@vger.kernel.org S: Maintained +F: drivers/net/dsa/mt7530-mdio.c F: drivers/net/dsa/mt7530.* F: net/dsa/tag_mtk.c diff --git a/drivers/net/dsa/Kconfig b/drivers/net/dsa/Kconfig index 6b45fa8b69078..c2551b13324c2 100644 --- a/drivers/net/dsa/Kconfig +++ b/drivers/net/dsa/Kconfig @@ -34,15 +34,23 @@ config NET_DSA_LANTIQ_GSWIP This enables support for the Lantiq / Intel GSWIP 2.1 found in the xrx200 / VR9 SoC. -config NET_DSA_MT7530 - tristate "MediaTek MT7530 and MT7531 Ethernet switch support" +config NET_DSA_MT7530_COMMON + tristate select NET_DSA_TAG_MTK select MEDIATEK_GE_PHY + help + This enables support for the common parts of MediaTek Ethernet + switch chips. + +config NET_DSA_MT7530 + tristate "MediaTek MT7530 and MT7531 Ethernet switch support" + select NET_DSA_MT7530_COMMON select PCS_MTK_LYNXI help This enables support for the MediaTek MT7530 and MT7531 Ethernet - switch chips. Multi-chip module MT7530 in MT7621AT, MT7621DAT, - MT7621ST and MT7623AI SoCs is supported. + switch chips which are connected via MDIO. + Multi-chip module MT7530 in MT7621AT, MT7621DAT, MT7621ST and + MT7623AI SoCs is supported as well. config NET_DSA_MV88E6060 tristate "Marvell 88E6060 ethernet switch chip support" diff --git a/drivers/net/dsa/Makefile b/drivers/net/dsa/Makefile index 16eb879e0cb4d..71250d7dd41af 100644 --- a/drivers/net/dsa/Makefile +++ b/drivers/net/dsa/Makefile @@ -6,7 +6,8 @@ ifdef CONFIG_NET_DSA_LOOP obj-$(CONFIG_FIXED_PHY) += dsa_loop_bdinfo.o endif obj-$(CONFIG_NET_DSA_LANTIQ_GSWIP) += lantiq_gswip.o -obj-$(CONFIG_NET_DSA_MT7530) += mt7530.o +obj-$(CONFIG_NET_DSA_MT7530_COMMON) += mt7530.o +obj-$(CONFIG_NET_DSA_MT7530) += mt7530-mdio.o obj-$(CONFIG_NET_DSA_MV88E6060) += mv88e6060.o obj-$(CONFIG_NET_DSA_RZN1_A5PSW) += rzn1_a5psw.o obj-$(CONFIG_NET_DSA_SMSC_LAN9303) += lan9303-core.o diff --git a/drivers/net/dsa/mt7530-mdio.c b/drivers/net/dsa/mt7530-mdio.c new file mode 100644 index 0000000000000..2b1757e585cf1 --- /dev/null +++ b/drivers/net/dsa/mt7530-mdio.c @@ -0,0 +1,242 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mt7530.h" + +static int +mt7530_regmap_write(void *context, unsigned int reg, unsigned int val) +{ + struct mii_bus *bus = context; + u16 page, r, lo, hi; + int ret; + + page = (reg >> 6) & 0x3ff; + r = (reg >> 2) & 0xf; + lo = val & 0xffff; + hi = val >> 16; + + /* MT7530 uses 31 as the pseudo port */ + ret = bus->write(bus, 0x1f, 0x1f, page); + if (ret < 0) + return ret; + + ret = bus->write(bus, 0x1f, r, lo); + if (ret < 0) + return ret; + + ret = bus->write(bus, 0x1f, 0x10, hi); + return ret; +} + +static int +mt7530_regmap_read(void *context, unsigned int reg, unsigned int *val) +{ + struct mii_bus *bus = context; + u16 page, r, lo, hi; + int ret; + + page = (reg >> 6) & 0x3ff; + r = (reg >> 2) & 0xf; + + /* MT7530 uses 31 as the pseudo port */ + ret = bus->write(bus, 0x1f, 0x1f, page); + if (ret < 0) + return ret; + + lo = bus->read(bus, 0x1f, r); + hi = bus->read(bus, 0x1f, 0x10); + + *val = (hi << 16) | (lo & 0xffff); + + return 0; +} + +static void +mt7530_mdio_regmap_lock(void *mdio_lock) +{ + mutex_lock_nested(mdio_lock, MDIO_MUTEX_NESTED); +} + +static void +mt7530_mdio_regmap_unlock(void *mdio_lock) +{ + mutex_unlock(mdio_lock); +} + +static const struct regmap_bus mt7530_regmap_bus = { + .reg_write = mt7530_regmap_write, + .reg_read = mt7530_regmap_read, +}; + +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; + mt7531_pcs_config[i]->lock = mt7530_mdio_regmap_lock; + mt7531_pcs_config[i]->unlock = mt7530_mdio_regmap_unlock; + mt7531_pcs_config[i]->lock_arg = &priv->bus->mdio_lock; + + regmap = devm_regmap_init(priv->dev, + &mt7530_regmap_bus, priv->bus, + 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 const struct of_device_id mt7530_of_match[] = { + { .compatible = "mediatek,mt7621", .data = &mt753x_table[ID_MT7621], }, + { .compatible = "mediatek,mt7530", .data = &mt753x_table[ID_MT7530], }, + { .compatible = "mediatek,mt7531", .data = &mt753x_table[ID_MT7531], }, + { /* sentinel */ }, +}; +MODULE_DEVICE_TABLE(of, mt7530_of_match); + +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"); + if (IS_ERR(priv->core_pwr)) + return PTR_ERR(priv->core_pwr); + + priv->io_pwr = devm_regulator_get(&mdiodev->dev, "io"); + if (IS_ERR(priv->io_pwr)) + return PTR_ERR(priv->io_pwr); + } + + regmap_config = devm_kzalloc(&mdiodev->dev, sizeof(*regmap_config), + GFP_KERNEL); + if (!regmap_config) + return -ENOMEM; + + regmap_config->reg_bits = 16; + regmap_config->val_bits = 32; + regmap_config->reg_stride = 4; + regmap_config->max_register = MT7530_CREV; + regmap_config->disable_locking = true; + priv->regmap = devm_regmap_init(priv->dev, &mt7530_regmap_bus, + priv->bus, regmap_config); + if (IS_ERR(priv->regmap)) + return PTR_ERR(priv->regmap); + + if (priv->id == ID_MT7531) { + ret = mt7531_create_sgmii(priv); + if (ret) + return ret; + } + + return dsa_register_switch(priv->ds); +} + +static void +mt7530_remove(struct mdio_device *mdiodev) +{ + struct mt7530_priv *priv = dev_get_drvdata(&mdiodev->dev); + int ret = 0, i; + + if (!priv) + return; + + ret = regulator_disable(priv->core_pwr); + if (ret < 0) + dev_err(priv->dev, + "Failed to disable core power: %d\n", ret); + + ret = regulator_disable(priv->io_pwr); + if (ret < 0) + dev_err(priv->dev, "Failed to disable io pwr: %d\n", + ret); + + mt7530_remove_common(priv); + + for (i = 0; i < 2; ++i) + mtk_pcs_lynxi_destroy(priv->ports[5 + i].sgmii_pcs); +} + +static void mt7530_shutdown(struct mdio_device *mdiodev) +{ + struct mt7530_priv *priv = dev_get_drvdata(&mdiodev->dev); + + if (!priv) + return; + + dsa_switch_shutdown(priv->ds); + + dev_set_drvdata(&mdiodev->dev, NULL); +} + +static struct mdio_driver mt7530_mdio_driver = { + .probe = mt7530_probe, + .remove = mt7530_remove, + .shutdown = mt7530_shutdown, + .mdiodrv.driver = { + .name = "mt7530", + .of_match_table = mt7530_of_match, + }, +}; + +mdio_module_driver(mt7530_mdio_driver); + +MODULE_AUTHOR("Sean Wang "); +MODULE_DESCRIPTION("Driver for Mediatek MT7530 Switch (MDIO)"); +MODULE_LICENSE("GPL"); diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index c9b6b11273683..ce2665abaaf57 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -191,31 +191,6 @@ core_clear(struct mt7530_priv *priv, u32 reg, u32 val) core_rmw(priv, reg, val, 0); } -static int -mt7530_regmap_write(void *context, unsigned int reg, unsigned int val) -{ - struct mii_bus *bus = context; - u16 page, r, lo, hi; - int ret; - - page = (reg >> 6) & 0x3ff; - r = (reg >> 2) & 0xf; - lo = val & 0xffff; - hi = val >> 16; - - /* MT7530 uses 31 as the pseudo port */ - ret = bus->write(bus, 0x1f, 0x1f, page); - if (ret < 0) - return ret; - - ret = bus->write(bus, 0x1f, r, lo); - if (ret < 0) - return ret; - - ret = bus->write(bus, 0x1f, 0x10, hi); - return ret; -} - static int mt7530_mii_write(struct mt7530_priv *priv, u32 reg, u32 val) { @@ -229,29 +204,6 @@ mt7530_mii_write(struct mt7530_priv *priv, u32 reg, u32 val) return ret; } -static int -mt7530_regmap_read(void *context, unsigned int reg, unsigned int *val) -{ - struct mii_bus *bus = context; - u16 page, r, lo, hi; - int ret; - - page = (reg >> 6) & 0x3ff; - r = (reg >> 2) & 0xf; - - /* MT7530 uses 31 as the pseudo port */ - ret = bus->write(bus, 0x1f, 0x1f, page); - if (ret < 0) - return ret; - - lo = bus->read(bus, 0x1f, r); - hi = bus->read(bus, 0x1f, 0x10); - - *val = (hi << 16) | (lo & 0xffff); - - return 0; -} - static u32 mt7530_mii_read(struct mt7530_priv *priv, u32 reg) { @@ -2948,72 +2900,6 @@ static const struct phylink_pcs_ops mt7530_pcs_ops = { .pcs_an_restart = mt7530_pcs_an_restart, }; -static void -mt7530_mdio_regmap_lock(void *mdio_lock) -{ - mutex_lock_nested(mdio_lock, MDIO_MUTEX_NESTED); -} - -static void -mt7530_mdio_regmap_unlock(void *mdio_lock) -{ - mutex_unlock(mdio_lock); -} - -static const struct regmap_bus mt7530_regmap_bus = { - .reg_write = mt7530_regmap_write, - .reg_read = mt7530_regmap_read, -}; - -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; - mt7531_pcs_config[i]->lock = mt7530_mdio_regmap_lock; - mt7531_pcs_config[i]->unlock = mt7530_mdio_regmap_unlock; - mt7531_pcs_config[i]->lock_arg = &priv->bus->mdio_lock; - - regmap = devm_regmap_init(priv->dev, - &mt7530_regmap_bus, priv->bus, - 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) { @@ -3072,7 +2958,7 @@ static int mt753x_set_mac_eee(struct dsa_switch *ds, int port, return 0; } -static const struct dsa_switch_ops mt7530_switch_ops = { +const struct dsa_switch_ops mt7530_switch_ops = { .get_tag_protocol = mtk_get_tag_protocol, .setup = mt753x_setup, .get_strings = mt7530_get_strings, @@ -3106,8 +2992,9 @@ static const struct dsa_switch_ops mt7530_switch_ops = { .get_mac_eee = mt753x_get_mac_eee, .set_mac_eee = mt753x_set_mac_eee, }; +EXPORT_SYMBOL_GPL(mt7530_switch_ops); -static const struct mt753x_info mt753x_table[] = { +const struct mt753x_info mt753x_table[] = { [ID_MT7621] = { .id = ID_MT7621, .pcs_ops = &mt7530_pcs_ops, @@ -3146,16 +3033,9 @@ static const struct mt753x_info mt753x_table[] = { .mac_port_config = mt7531_mac_config, }, }; +EXPORT_SYMBOL_GPL(mt753x_table); -static const struct of_device_id mt7530_of_match[] = { - { .compatible = "mediatek,mt7621", .data = &mt753x_table[ID_MT7621], }, - { .compatible = "mediatek,mt7530", .data = &mt753x_table[ID_MT7530], }, - { .compatible = "mediatek,mt7531", .data = &mt753x_table[ID_MT7531], }, - { /* sentinel */ }, -}; -MODULE_DEVICE_TABLE(of, mt7530_of_match); - -static int +int mt7530_probe_common(struct mt7530_priv *priv) { struct device *dev = priv->dev; @@ -3218,60 +3098,9 @@ mt7530_probe_common(struct mt7530_priv *priv) return 0; } +EXPORT_SYMBOL_GPL(mt7530_probe_common); -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"); - if (IS_ERR(priv->core_pwr)) - return PTR_ERR(priv->core_pwr); - - priv->io_pwr = devm_regulator_get(&mdiodev->dev, "io"); - if (IS_ERR(priv->io_pwr)) - return PTR_ERR(priv->io_pwr); - } - - regmap_config = devm_kzalloc(&mdiodev->dev, sizeof(*regmap_config), - GFP_KERNEL); - if (!regmap_config) - return -ENOMEM; - - regmap_config->reg_bits = 16; - regmap_config->val_bits = 32; - regmap_config->reg_stride = 4; - regmap_config->max_register = MT7530_CREV; - regmap_config->disable_locking = true; - priv->regmap = devm_regmap_init(priv->dev, &mt7530_regmap_bus, - priv->bus, regmap_config); - if (IS_ERR(priv->regmap)) - return PTR_ERR(priv->regmap); - - if (priv->id == ID_MT7531) { - ret = mt7531_create_sgmii(priv); - if (ret) - return ret; - } - - return dsa_register_switch(priv->ds); -} - -static void +void mt7530_remove_common(struct mt7530_priv *priv) { if (priv->irq) @@ -3281,55 +3110,7 @@ mt7530_remove_common(struct mt7530_priv *priv) mutex_destroy(&priv->reg_mutex); } - -static void -mt7530_remove(struct mdio_device *mdiodev) -{ - struct mt7530_priv *priv = dev_get_drvdata(&mdiodev->dev); - int ret = 0, i; - - if (!priv) - return; - - ret = regulator_disable(priv->core_pwr); - if (ret < 0) - dev_err(priv->dev, - "Failed to disable core power: %d\n", ret); - - ret = regulator_disable(priv->io_pwr); - if (ret < 0) - dev_err(priv->dev, "Failed to disable io pwr: %d\n", - ret); - - mt7530_remove_common(priv); - - for (i = 0; i < 2; ++i) - mtk_pcs_lynxi_destroy(priv->ports[5 + i].sgmii_pcs); -} - -static void mt7530_shutdown(struct mdio_device *mdiodev) -{ - struct mt7530_priv *priv = dev_get_drvdata(&mdiodev->dev); - - if (!priv) - return; - - dsa_switch_shutdown(priv->ds); - - dev_set_drvdata(&mdiodev->dev, NULL); -} - -static struct mdio_driver mt7530_mdio_driver = { - .probe = mt7530_probe, - .remove = mt7530_remove, - .shutdown = mt7530_shutdown, - .mdiodrv.driver = { - .name = "mt7530", - .of_match_table = mt7530_of_match, - }, -}; - -mdio_module_driver(mt7530_mdio_driver); +EXPORT_SYMBOL_GPL(mt7530_remove_common); MODULE_AUTHOR("Sean Wang "); MODULE_DESCRIPTION("Driver for Mediatek MT7530 Switch"); diff --git a/drivers/net/dsa/mt7530.h b/drivers/net/dsa/mt7530.h index 2a611173a7d08..ce02aa592a7a8 100644 --- a/drivers/net/dsa/mt7530.h +++ b/drivers/net/dsa/mt7530.h @@ -814,4 +814,10 @@ static inline void INIT_MT7530_DUMMY_POLL(struct mt7530_dummy_poll *p, p->reg = reg; } +int mt7530_probe_common(struct mt7530_priv *priv); +void mt7530_remove_common(struct mt7530_priv *priv); + +extern const struct dsa_switch_ops mt7530_switch_ops; +extern const struct mt753x_info mt753x_table[]; + #endif /* __MT7530_H */ From patchwork Wed Mar 29 15:59:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 76698 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp530246vqo; Wed, 29 Mar 2023 09:16:42 -0700 (PDT) X-Google-Smtp-Source: AKy350avPcts71k232dg99b3m0JHVHd7PX0162Pp97NzJRHMHyISFggVTxiNCcIJrBwlLKvGPSTi X-Received: by 2002:aa7:c6d1:0:b0:501:d6d4:ef33 with SMTP id b17-20020aa7c6d1000000b00501d6d4ef33mr18572307eds.40.1680106602296; Wed, 29 Mar 2023 09:16:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680106602; cv=none; d=google.com; s=arc-20160816; b=yYSnr0miw/Hwt5grmW5o85ysks9lQrYJ2gjdsmfTSyYJPhRz4LRXE/bPSpO+eJoZfV dhFsiU5fIkCBNmldGDSixDKSTEA5ehsGS328KucHl8LfuQ8l3MDDsXfDhlbuJp1GOLIQ dXxktViJXqm0q9IpCJeJc2UtNZjg4VQLE7EoEEz9RwF7bsJRJkj+wLbFLXPPGUb1YB9t +dM846MR+NMrQOoDp8LY98dcUw2CbvJ3vlRo5WOeK0BUs0H5AmE03LFpL6Y5urCrM37Z 8TVvpYySDs52XQlCXk3fOhreAPQfnvpg+0XZghsCK7lbm8GVYiYkQJrqTrA/sL19CgsY fhXw== 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=MKuUSgy1LKC1fzavlY6dVE3HFo8hotnsiWf2bQBe4YI=; b=ZgNC7KAvH+gQyP99SO5v9w5waeyQsfQDW54EhOFK60AgXJSiWyLVstgT8Gzve4gekG Suzsr/S6UFEpeyr+aHm142Xw4Urn5hX2pkM/H+Vr+YWG6vfVx1L/iGTcdYA5JryZyQf7 fdF8zllChyB6Q3rG3PsHjwCZuaiNL6aURE6JqOXPnUzhFS9XxZBRpgf0jF2mD7xGwy03 cEWXXBjpkxGKSxnuwCWDDNSebiLsta/QkCHmiD6OSAgMVkPC5oelG4byjajCf+r4jDPi FioA0gX4ICPd/CUxOMjDQvkCZMApjPWJbGUdVkL/dbchTGMiSX2VoPQ5kjnYTUq8sXPH jE8A== 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 r9-20020aa7cfc9000000b004fd26753791si13379321edy.649.2023.03.29.09.16.05; Wed, 29 Mar 2023 09:16:42 -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 S231222AbjC2QBv (ORCPT + 99 others); Wed, 29 Mar 2023 12:01:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230282AbjC2QAy (ORCPT ); Wed, 29 Mar 2023 12:00:54 -0400 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C58B64C2C; Wed, 29 Mar 2023 08:59: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 1phYDH-0003RC-1w; Wed, 29 Mar 2023 17:59:51 +0200 Date: Wed, 29 Mar 2023 16:59:47 +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 11/15] net: dsa: mt7530: skip locking if MDIO bus isn't present Message-ID: <4e6d1cbba2ff16cad5b9ac48ccdf4407f45c7857.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?1761719460342214253?= X-GMAIL-MSGID: =?utf-8?q?1761719460342214253?= As MT7530 and MT7531 internally use 32-bit wide registers, each access to any register of the switch requires several operations on the MDIO bus. Hence if there is congruent access, e.g. due to PCS or PHY polling, this can mess up and interfere with another ongoing register access sequence. However, the MDIO bus mutex is only relevant for MDIO-connected switches. Prepare switches which have there registers directly mapped into the SoCs register space via MMIO which do not require such locking. There we can simply use regmap's default locking mechanism. Hence guard mutex operations to only be performed in case of MDIO connected switches. Signed-off-by: Daniel Golle Reviewed-by: Andrew Lunn --- drivers/net/dsa/mt7530.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index ce2665abaaf57..c6fad2d156160 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -145,13 +145,15 @@ core_write_mmd_indirect(struct mt7530_priv *priv, int prtad, static void mt7530_mutex_lock(struct mt7530_priv *priv) { - mutex_lock_nested(&priv->bus->mdio_lock, MDIO_MUTEX_NESTED); + if (priv->bus) + mutex_lock_nested(&priv->bus->mdio_lock, MDIO_MUTEX_NESTED); } static void mt7530_mutex_unlock(struct mt7530_priv *priv) { - mutex_unlock(&priv->bus->mdio_lock); + if (priv->bus) + mutex_unlock(&priv->bus->mdio_lock); } static void From patchwork Wed Mar 29 16:00:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 76702 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp537393vqo; Wed, 29 Mar 2023 09:27:36 -0700 (PDT) X-Google-Smtp-Source: AKy350aeetKp/cOsNR9vSVdrg/FNh2ZHk6guZecWuBEctEBpQHnuhJYCozEvqNyCaL+Xngznwj1p X-Received: by 2002:aa7:d713:0:b0:501:d52d:7f88 with SMTP id t19-20020aa7d713000000b00501d52d7f88mr19318126edq.10.1680107255924; Wed, 29 Mar 2023 09:27:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680107255; cv=none; d=google.com; s=arc-20160816; b=v9VSlOBgNT+GsZClptnEvH6HiD/XaLkd3d4fNPd17pbI1T6YA8q+X2QH33UoCqsFdo syFyNhV4ofY3UpzHYvP3vG13rKgqEc5tVB+5x2i1wVZlubkDRRwalPrJse8TAiRKgn+e l2oXxddEKMd6LvuNZ6m2+tcf1wNU0sp8wNcAb33anOZtESv0V3IOxAk+vDZeQmeJ8fFm z9+1wVcAFUNoosO5xbpJ1wO05DVvVFwi9y+PJeHXH/EU+jZqZBKExp903s3IcX0fNQ04 E4Bvl9sbmnNkOUeQlbO2SPns1fe1PMbKc1dCps+gMCxZfNNbl7QLyAD73Jch6ZjQNH0K Xlig== 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=aqizc6/ZjAWz90A3jk7+7u+bSaPAPILOhNROkch9Cc4=; b=sT2+vZYK6NMNilcEhwGjH/ej4PlMNdrWMNsoag0J02/m4sJOSGAgFx1FlLGfPatKdD lZSXWni5K3IQ5ydKVhLlnrZ+3e5LlXGHI6hmR19ll8HLvEZ8lYUAAe8jNd+QeN/MhJIY TaVTjbPCAY3QVSezNMQFGekDIQK/CXnU+JGpSnq3Pi0EcUkB6iG9X8Hvw/efJu4l7zM7 ss47+DtTePejJHMpMXoBxJOt4FsEHR7PFVt8PFDn4T3p3cTZXZigevSh1vicMZV7XJth TVKK7Z0tKbMLygw6Hz3awJ/ktcnB46uFarYhy2RLiWrYq9B6rMn/nGBzzOZHIH10Tv8w evWg== 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 u14-20020aa7d98e000000b005021f0d576dsi14510859eds.692.2023.03.29.09.27.11; Wed, 29 Mar 2023 09:27:35 -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 S229643AbjC2QCQ (ORCPT + 99 others); Wed, 29 Mar 2023 12:02:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231485AbjC2QBj (ORCPT ); Wed, 29 Mar 2023 12:01:39 -0400 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60FDF6A72; Wed, 29 Mar 2023 09:00:25 -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 1phYDc-0003S1-1W; Wed, 29 Mar 2023 18:00:13 +0200 Date: Wed, 29 Mar 2023 17:00:06 +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 12/15] net: dsa: mt7530: add support for single-chip reset line Message-ID: <0f696278bd8d13121a500f80cfe2f806debe4da5.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?1761720146245243706?= X-GMAIL-MSGID: =?utf-8?q?1761720146245243706?= Similar to multi-chip-module MT7530 also MT7988 uses an internal reset line instead of using an optional reset GPIO like it is the case for external MT7530 and MT7531 ICs. Add support for internal but non-MCM reset line in preparation for adding support for MT7988. Signed-off-by: Daniel Golle --- drivers/net/dsa/mt7530.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index c6fad2d156160..fd55ddc2d1eb3 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -3066,6 +3066,12 @@ mt7530_probe_common(struct mt7530_priv *priv) dev_err(dev, "Couldn't get our reset line\n"); return PTR_ERR(priv->rstc); } + } else if (!priv->bus) { + priv->rstc = devm_reset_control_get(dev, NULL); + if (IS_ERR(priv->rstc)) { + 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); From patchwork Wed Mar 29 16:00: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: 76697 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp528859vqo; Wed, 29 Mar 2023 09:14:48 -0700 (PDT) X-Google-Smtp-Source: AKy350Zh5p8JmFjqpVQQyLut+ZJBKdZ4KDmxgsimct0N4Qvw7xNKWIi7CzMrnZilM2ypLvUJ5eeK X-Received: by 2002:a05:6402:12cc:b0:4f9:f07d:a978 with SMTP id k12-20020a05640212cc00b004f9f07da978mr19994423edx.5.1680106488101; Wed, 29 Mar 2023 09:14:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680106488; cv=none; d=google.com; s=arc-20160816; b=NLOOMsAPzZtZzgiExZo0Md/ZpDnYmBlkpeAlyaWKh+b0VUpHoBsJWQNUeyMFOWOEcp mEQrKGwEG0c+eQ7VveXVaLcawLSyP/iXesIB+/z+6N6S+8r6MXvjSQeolivY7sXlnGRT BzjhawdbElZBzsRcWqLuSW9EoWXzGhyw2XZXXN0MAtaH7wovSGyjkEw/srZp5eVAwe8x CkpAhpaXw3Ye78OWU3H5AW/fJaTFluJutfaNAA+MnGRmg1BvxiIpHYQFj0iPR3nMDt4d e+QL67gqirDeDLtjIKBoQpQS1KewDOhug1QcC3LlcNFRYYfgFLPUiNRnHz/M5urpGCaa wkjw== 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=EvX5AZmd4a7hpZVRfDvfVhXWm6XtqWCUdYcL19XDaQ8=; b=y/sXOYQ/B4epplEZxMrd9fvbpPZfJIwhyfy3pXIeZpoOHlmjzYM07/Fx/CLKB8h8k9 FtiUmPIpaAAB/nFwTomszh1wUbXufIHLYHk/x7AAiq7e7N0x9nxl5k+sMiisnfcfIBNK Xsy3i82hxj7EW2oXSqY1WBk8ANqWrpU7Td8DG0Adm8QGSdldsUgZ4qBPZ0+i5Qd6aBVS Un87UoZNccaLXQv8AdFAbf/c4ymmsAYiyuYzQnfR7pZMzoMrl1m4PJZtsjh4nAmqbxXv /4keEpkTd3Ov9OKGIJnq8/HTEmT5elL9IuedxuAqoHYY9ZzFpcIb8e43IeITch/YElqq J9Sw== 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 w11-20020aa7d28b000000b004bfcd531e73si17116987edq.291.2023.03.29.09.14.24; Wed, 29 Mar 2023 09:14:48 -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 S230248AbjC2QCV (ORCPT + 99 others); Wed, 29 Mar 2023 12:02:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230180AbjC2QBx (ORCPT ); Wed, 29 Mar 2023 12:01:53 -0400 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B37A7693; Wed, 29 Mar 2023 09:00:39 -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 1phYDp-0003Tk-2O; Wed, 29 Mar 2023 18:00:25 +0200 Date: Wed, 29 Mar 2023 17:00: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 13/15] net: dsa: mt7530: add support for 10G link modes for CPU port Message-ID: <495231a9d84159878116c2cb181537da674edc27.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?1761719341049835410?= X-GMAIL-MSGID: =?utf-8?q?1761719341049835410?= The built-in switch of the MT7988 SoC is internally connected using a stateless 10G link. Add support for 10G interface modes to silence a warning otherwise occurring when the switch driver is setup. Signed-off-by: Daniel Golle Reviewed-by: Andrew Lunn --- drivers/net/dsa/mt7530.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index fd55ddc2d1eb3..a4b49e5753bdc 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -2616,6 +2616,9 @@ mt7531_mac_config(struct dsa_switch *ds, int port, unsigned int mode, case PHY_INTERFACE_MODE_1000BASEX: case PHY_INTERFACE_MODE_2500BASEX: /* handled in SGMII PCS driver */ + case PHY_INTERFACE_MODE_USXGMII: + case PHY_INTERFACE_MODE_10GKR: + /* internal stateless 10G link */ return 0; default: return -EINVAL; @@ -2739,7 +2742,9 @@ static void mt753x_phylink_mac_link_up(struct dsa_switch *ds, int port, * variants. */ if (interface == PHY_INTERFACE_MODE_TRGMII || - (phy_interface_mode_is_8023z(interface))) { + interface == PHY_INTERFACE_MODE_USXGMII || + interface == PHY_INTERFACE_MODE_10GKR || + phy_interface_mode_is_8023z(interface)) { speed = SPEED_1000; duplex = DUPLEX_FULL; } From patchwork Wed Mar 29 16:00:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 76695 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp525009vqo; Wed, 29 Mar 2023 09:09:26 -0700 (PDT) X-Google-Smtp-Source: AKy350ajpZpvOpM2HM2chVMI1ppOatMtJimmJEe7QM/5IWr5xTqGgz565qHAQtGCcWaA4x2i7DOd X-Received: by 2002:aa7:d784:0:b0:500:50f6:dd30 with SMTP id s4-20020aa7d784000000b0050050f6dd30mr19403321edq.15.1680106166041; Wed, 29 Mar 2023 09:09:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680106166; cv=none; d=google.com; s=arc-20160816; b=pJPijQh7l/FX1yru6zYE+jSxrDtF2SrPUmGCeLULSoFYK4QMMJiRvdwMUC4mYAc/8T cI1QEATGwEAy4Y7WPqNj6J+NKhVE28d3phLBFP31JvYAQj/6TKPzWwZ6UQ5b0vXVN1N+ /EcFgZYZwsjyoBkEG1JBYMM+L6nKGeR7ZmTJS3s/kVY3NI7p6JoRPaKccN0iSl20jYwK H86+pFn41efvCHkP3rfhr4YhNfEjh8TPa3XvjmRctfXC6o9OyjvpVRWaMlb1qYIyeclL wn1G+ZRWLl+GvZ5XY7MPmsEs/mJuLaW5Ov8aM9HMSZuoeL5enR/QFUjVG/7jjLlj1Bd9 I4Qw== 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=m/6FJJKf1aV0jDEMEdXXGKICHrsTXaX+pXgYZQmwMFM=; b=k+lQ1lHf/tJ6xdmEaYx87o+ROui0FuV+3cJL2yj7YgpT27H+i6WAQrNASSqtNdiDRV pgge3UB0UYruXiPH91WERS1PXBXmJTJD3SmNy4lUHY8O3fKLIqW6exKfCaIB6eiec51s w1ieYG51s0Jl+0CDPKYok5DIQfzaBt6ljh3AzqTNt78DiJ1HIsmkMfV6eF1LyN3dPNlq hWdhYvW6QSRXURujmI1JwlQGwjk8gHEfKwH1g08DDkC73zo4rtpCV5sjfdNe+JTClpIo Kws26qA39VkRcX4266jm1urCCd3i5mZAFgzcra9NdnLSSA5z9a/tRkJSQBS3qs2IFfID KEnQ== 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 i26-20020a50fc1a000000b005021f0d5762si13758298edr.681.2023.03.29.09.09.01; Wed, 29 Mar 2023 09:09:26 -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 S231240AbjC2QCw (ORCPT + 99 others); Wed, 29 Mar 2023 12:02:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231349AbjC2QB6 (ORCPT ); Wed, 29 Mar 2023 12:01:58 -0400 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2045F7AA0; Wed, 29 Mar 2023 09:00:50 -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 1phYE3-0003UF-2y; Wed, 29 Mar 2023 18:00:41 +0200 Date: Wed, 29 Mar 2023 17:00:34 +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 14/15] net: dsa: mt7530: introduce driver for MT7988 built-in switch Message-ID: <371f0586e257d098993847e71d0c916a03c04191.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?1761719003326168139?= X-GMAIL-MSGID: =?utf-8?q?1761719003326168139?= Add driver for the built-in Gigabit Ethernet switch which can be found in the MediaTek MT7988 SoC. The switch shares most of its design with MT7530 and MT7531, but has it's registers mapped into the SoCs register space rather than being connected externally or internally via MDIO. Introduce a new platform driver to support that. Signed-off-by: Daniel Golle --- MAINTAINERS | 2 + drivers/net/dsa/Kconfig | 12 +++++ drivers/net/dsa/Makefile | 1 + drivers/net/dsa/mt7530-mmio.c | 96 +++++++++++++++++++++++++++++++++++ drivers/net/dsa/mt7530.c | 86 ++++++++++++++++++++++++++++++- drivers/net/dsa/mt7530.h | 12 ++--- 6 files changed, 201 insertions(+), 8 deletions(-) create mode 100644 drivers/net/dsa/mt7530-mmio.c diff --git a/MAINTAINERS b/MAINTAINERS index 7feb52d9ae0b9..f39c2520d5323 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13174,9 +13174,11 @@ MEDIATEK SWITCH DRIVER M: Sean Wang M: Landen Chao M: DENG Qingfang +M: Daniel Golle L: netdev@vger.kernel.org S: Maintained F: drivers/net/dsa/mt7530-mdio.c +F: drivers/net/dsa/mt7530-mmio.c F: drivers/net/dsa/mt7530.* F: net/dsa/tag_mtk.c diff --git a/drivers/net/dsa/Kconfig b/drivers/net/dsa/Kconfig index c2551b13324c2..de4d86e37973f 100644 --- a/drivers/net/dsa/Kconfig +++ b/drivers/net/dsa/Kconfig @@ -52,6 +52,18 @@ config NET_DSA_MT7530 Multi-chip module MT7530 in MT7621AT, MT7621DAT, MT7621ST and MT7623AI SoCs is supported as well. +config NET_DSA_MT7988 + tristate "MediaTek MT7988 built-in Ethernet switch support" + select NET_DSA_MT7530_COMMON + depends on HAS_IOMEM + help + This enables support for the built-in Ethernet switch found + in the MediaTek MT7988 SoC. + The switch is a similar design as MT7531, however, unlike + other MT7530 and MT7531 the switch registers are directly + mapped into the SoCs register space rather than being accessible + via MDIO. + config NET_DSA_MV88E6060 tristate "Marvell 88E6060 ethernet switch chip support" select NET_DSA_TAG_TRAILER diff --git a/drivers/net/dsa/Makefile b/drivers/net/dsa/Makefile index 71250d7dd41af..103a33e20de4b 100644 --- a/drivers/net/dsa/Makefile +++ b/drivers/net/dsa/Makefile @@ -8,6 +8,7 @@ endif obj-$(CONFIG_NET_DSA_LANTIQ_GSWIP) += lantiq_gswip.o obj-$(CONFIG_NET_DSA_MT7530_COMMON) += mt7530.o obj-$(CONFIG_NET_DSA_MT7530) += mt7530-mdio.o +obj-$(CONFIG_NET_DSA_MT7988) += mt7530-mmio.o obj-$(CONFIG_NET_DSA_MV88E6060) += mv88e6060.o obj-$(CONFIG_NET_DSA_RZN1_A5PSW) += rzn1_a5psw.o obj-$(CONFIG_NET_DSA_SMSC_LAN9303) += lan9303-core.o diff --git a/drivers/net/dsa/mt7530-mmio.c b/drivers/net/dsa/mt7530-mmio.c new file mode 100644 index 0000000000000..ce03605b67fc5 --- /dev/null +++ b/drivers/net/dsa/mt7530-mmio.c @@ -0,0 +1,96 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include +#include +#include +#include + +#include "mt7530.h" + +static const struct of_device_id mt7988_of_match[] = { + { .compatible = "mediatek,mt7988-switch", .data = &mt753x_table[ID_MT7988], }, + { /* sentinel */ }, +}; +MODULE_DEVICE_TABLE(of, mt7988_of_match); + +static int +mt7988_probe(struct platform_device *pdev) +{ + static struct regmap_config *sw_regmap_config; + struct mt7530_priv *priv; + void __iomem *base_addr; + int ret; + + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->bus = NULL; + priv->dev = &pdev->dev; + + ret = mt7530_probe_common(priv); + if (ret) + return ret; + + base_addr = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(base_addr)) { + dev_err(&pdev->dev, "cannot request I/O memory space\n"); + return -ENXIO; + } + + sw_regmap_config = devm_kzalloc(&pdev->dev, sizeof(*sw_regmap_config), GFP_KERNEL); + if (!sw_regmap_config) + return -ENOMEM; + + sw_regmap_config->name = "switch"; + sw_regmap_config->reg_bits = 16; + sw_regmap_config->val_bits = 32; + sw_regmap_config->reg_stride = 4; + sw_regmap_config->reg_base = 0x0; + sw_regmap_config->max_register = 0x7ffc; + priv->regmap = devm_regmap_init_mmio(&pdev->dev, base_addr, sw_regmap_config); + if (IS_ERR(priv->regmap)) + return PTR_ERR(priv->regmap); + + return dsa_register_switch(priv->ds); +} + +static int +mt7988_remove(struct platform_device *pdev) +{ + struct mt7530_priv *priv = platform_get_drvdata(pdev); + + if (priv) + mt7530_remove_common(priv); + + return 0; +} + +static void mt7988_shutdown(struct platform_device *pdev) +{ + struct mt7530_priv *priv = platform_get_drvdata(pdev); + + if (!priv) + return; + + dsa_switch_shutdown(priv->ds); + + dev_set_drvdata(&pdev->dev, NULL); +} + +static struct platform_driver mt7988_platform_driver = { + .probe = mt7988_probe, + .remove = mt7988_remove, + .shutdown = mt7988_shutdown, + .driver = { + .name = "mt7988-switch", + .of_match_table = mt7988_of_match, + }, +}; +module_platform_driver(mt7988_platform_driver); + +MODULE_AUTHOR("Daniel Golle "); +MODULE_DESCRIPTION("Driver for Mediatek MT7530 Switch (MMIO)"); +MODULE_LICENSE("GPL"); diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index a4b49e5753bdc..f8cb45de5ba84 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -1985,6 +1985,47 @@ static const struct irq_domain_ops mt7530_irq_domain_ops = { .xlate = irq_domain_xlate_onecell, }; +static void +mt7988_irq_mask(struct irq_data *d) +{ + struct mt7530_priv *priv = irq_data_get_irq_chip_data(d); + + priv->irq_enable &= ~BIT(d->hwirq); + mt7530_mii_write(priv, MT7530_SYS_INT_EN, priv->irq_enable); +} + +static void +mt7988_irq_unmask(struct irq_data *d) +{ + struct mt7530_priv *priv = irq_data_get_irq_chip_data(d); + + priv->irq_enable |= BIT(d->hwirq); + mt7530_mii_write(priv, MT7530_SYS_INT_EN, priv->irq_enable); +} + +static struct irq_chip mt7988_irq_chip = { + .name = KBUILD_MODNAME, + .irq_mask = mt7988_irq_mask, + .irq_unmask = mt7988_irq_unmask, +}; + +static int +mt7988_irq_map(struct irq_domain *domain, unsigned int irq, + irq_hw_number_t hwirq) +{ + irq_set_chip_data(irq, domain->host_data); + irq_set_chip_and_handler(irq, &mt7988_irq_chip, handle_simple_irq); + irq_set_nested_thread(irq, true); + irq_set_noprobe(irq); + + return 0; +} + +static const struct irq_domain_ops mt7988_irq_domain_ops = { + .map = mt7988_irq_map, + .xlate = irq_domain_xlate_onecell, +}; + static void mt7530_setup_mdio_irq(struct mt7530_priv *priv) { @@ -2019,8 +2060,15 @@ mt7530_setup_irq(struct mt7530_priv *priv) return priv->irq ? : -EINVAL; } - priv->irq_domain = irq_domain_add_linear(np, MT7530_NUM_PHYS, - &mt7530_irq_domain_ops, priv); + if (priv->id == ID_MT7988) + priv->irq_domain = irq_domain_add_linear(np, MT7530_NUM_PHYS, + &mt7988_irq_domain_ops, + priv); + else + priv->irq_domain = irq_domain_add_linear(np, MT7530_NUM_PHYS, + &mt7530_irq_domain_ops, + priv); + if (!priv->irq_domain) { dev_err(dev, "failed to create IRQ domain\n"); return -ENOMEM; @@ -2965,6 +3013,27 @@ static int mt753x_set_mac_eee(struct dsa_switch *ds, int port, return 0; } +static int mt7988_pad_setup(struct dsa_switch *ds, phy_interface_t interface) +{ + return 0; +} + +static int mt7988_setup(struct dsa_switch *ds) +{ + struct mt7530_priv *priv = ds->priv; + + /* Reset the switch */ + reset_control_assert(priv->rstc); + usleep_range(20, 50); + reset_control_deassert(priv->rstc); + usleep_range(20, 50); + + /* Reset the switch PHYs */ + mt7530_write(priv, MT7530_SYS_CTRL, SYS_CTRL_PHY_RST); + + return mt7531_setup_common(ds); +} + const struct dsa_switch_ops mt7530_switch_ops = { .get_tag_protocol = mtk_get_tag_protocol, .setup = mt753x_setup, @@ -3039,6 +3108,19 @@ const struct mt753x_info mt753x_table[] = { .mac_port_get_caps = mt7531_mac_port_get_caps, .mac_port_config = mt7531_mac_config, }, + [ID_MT7988] = { + .id = ID_MT7988, + .pcs_ops = &mt7530_pcs_ops, + .sw_setup = mt7988_setup, + .phy_read_c22 = mt7531_ind_c22_phy_read, + .phy_write_c22 = mt7531_ind_c22_phy_write, + .phy_read_c45 = mt7531_ind_c45_phy_read, + .phy_write_c45 = mt7531_ind_c45_phy_write, + .pad_setup = mt7988_pad_setup, + .cpu_port_config = mt7531_cpu_port_config, + .mac_port_get_caps = mt7531_mac_port_get_caps, + .mac_port_config = mt7531_mac_config, + }, }; EXPORT_SYMBOL_GPL(mt753x_table); diff --git a/drivers/net/dsa/mt7530.h b/drivers/net/dsa/mt7530.h index ce02aa592a7a8..01db5c9724fa8 100644 --- a/drivers/net/dsa/mt7530.h +++ b/drivers/net/dsa/mt7530.h @@ -18,6 +18,7 @@ enum mt753x_id { ID_MT7530 = 0, ID_MT7621 = 1, ID_MT7531 = 2, + ID_MT7988 = 3, }; #define NUM_TRGMII_CTRL 5 @@ -54,11 +55,11 @@ enum mt753x_id { #define MT7531_MIRROR_PORT_SET(x) (((x) & MIRROR_MASK) << 16) #define MT7531_CPU_PMAP_MASK GENMASK(7, 0) -#define MT753X_MIRROR_REG(id) (((id) == ID_MT7531) ? \ +#define MT753X_MIRROR_REG(id) ((((id) == ID_MT7531) || ((id) == ID_MT7988)) ? \ MT7531_CFC : MT7530_MFC) -#define MT753X_MIRROR_EN(id) (((id) == ID_MT7531) ? \ +#define MT753X_MIRROR_EN(id) ((((id) == ID_MT7531) || ((id) == ID_MT7988)) ? \ MT7531_MIRROR_EN : MIRROR_EN) -#define MT753X_MIRROR_MASK(id) (((id) == ID_MT7531) ? \ +#define MT753X_MIRROR_MASK(id) ((((id) == ID_MT7531) || ((id) == ID_MT7988)) ? \ MT7531_MIRROR_MASK : MIRROR_MASK) /* Registers for BPDU and PAE frame control*/ @@ -295,9 +296,8 @@ enum mt7530_vlan_port_acc_frm { MT7531_FORCE_DPX | \ MT7531_FORCE_RX_FC | \ MT7531_FORCE_TX_FC) -#define PMCR_FORCE_MODE_ID(id) (((id) == ID_MT7531) ? \ - MT7531_FORCE_MODE : \ - PMCR_FORCE_MODE) +#define PMCR_FORCE_MODE_ID(id) ((((id) == ID_MT7531) || ((id) == ID_MT7988)) ? \ + MT7531_FORCE_MODE : PMCR_FORCE_MODE) #define PMCR_LINK_SETTINGS_MASK (PMCR_TX_EN | PMCR_FORCE_SPEED_1000 | \ PMCR_RX_EN | PMCR_FORCE_SPEED_100 | \ PMCR_TX_FC_EN | PMCR_RX_FC_EN | \ From patchwork Wed Mar 29 16:00:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 76699 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp531862vqo; Wed, 29 Mar 2023 09:18:46 -0700 (PDT) X-Google-Smtp-Source: AKy350Yn/Mgg+guL7S+jIw6mK4g4aYJSx5pnKRxMEqncByX0cnpn2hUvIocl0TNUnLZiiWqgUSab X-Received: by 2002:a17:906:5850:b0:935:3028:ff58 with SMTP id h16-20020a170906585000b009353028ff58mr20520555ejs.55.1680106726619; Wed, 29 Mar 2023 09:18:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680106726; cv=none; d=google.com; s=arc-20160816; b=J8FbshixfsbTxvet3Nd7dTcH4frm0N4zAxrgZVGt2GG3mr9tf2udgv1Q6CGyAAcGtR WApZs2IUzbOL1m046gdFTSJ9DWxNFdJfpHnBTmTJSZx/mScQMwHHZZU6q1xnYDkq21QH O61qChY+Wq4mFdn3W1FO0NejSRyTRI5Oi0UynfG+BVsZnjHrF0LpLBfuk1Zn+iVj2B0S nMXqLkedKLgM/OaHxmK14TVlZaA7FPbAWHuS7hc50Uku3AY3evMeFtNP26XMEjzGIfRu uCxoRE/nGZsORoqCLm8ik43wfXZovf7DfCHa8JSdYzSBJX9ibT+x9NaiaKhi5v2SYrMb do2g== 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=2ZzZTeTbACO9jNrXV7gkXRIT2/Za9jKiU5TxwHhZyjc=; b=mUcKH0ukx2n97aEHi1fKckg3jVsOjV0pbZqKWJbwOezRklpjWv1E4eAdzpxoBoZ4WM Ejz1r/kidBiELQoGbPpcuMbpB0srjOsOZ/lx6bYstYzwfbEDZMj/4b7t4ZdKstweFkDu 2mhR46nGLRgNg/47BnYQM2V5IGajq/U4rTSHGxaPny2I7/Ft/AUN9MwMzT8WTgMI6r2d OwksMWRTn71DZHSMsdCqSx5gqE/B/sWsSid+4X3+TDoMEHe00/s3sxGcWNJXmSLgP7RA Bc4nC5LjYjsayhNIQnV5RoTLmWeoOygS+qwOMDFu4dQFVKlvC4B5IHHjxuI1ufEefegk JnKA== 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 t6-20020a17090616c600b008e0363188c7si31342652ejd.890.2023.03.29.09.18.22; Wed, 29 Mar 2023 09:18:46 -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 S230151AbjC2QDv (ORCPT + 99 others); Wed, 29 Mar 2023 12:03:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231347AbjC2QDD (ORCPT ); Wed, 29 Mar 2023 12:03:03 -0400 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0156F46BF for ; Wed, 29 Mar 2023 09:01:27 -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 1phYEH-0003V2-1M; Wed, 29 Mar 2023 18:00:54 +0200 Date: Wed, 29 Mar 2023 17:00:49 +0100 From: Daniel Golle To: 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 , Krzysztof Kozlowski , Rob Herring Cc: Sam Shih , Lorenzo Bianconi , John Crispin , Felix Fietkau Subject: [RFC PATCH net-next v3 15/15] dt-bindings: net: dsa: mediatek,mt7530: add mediatek,mt7988-switch Message-ID: <9b504e3e88807bfb62022c0877451933d30abeb5.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?1761719590824848591?= X-GMAIL-MSGID: =?utf-8?q?1761719590824848591?= Add documentation for the built-in switch which can be found in the MediaTek MT7988 SoC. Signed-off-by: Daniel Golle --- .../bindings/net/dsa/mediatek,mt7530.yaml | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/net/dsa/mediatek,mt7530.yaml b/Documentation/devicetree/bindings/net/dsa/mediatek,mt7530.yaml index 5ae9cd8f99a24..15953f0e9d1a6 100644 --- a/Documentation/devicetree/bindings/net/dsa/mediatek,mt7530.yaml +++ b/Documentation/devicetree/bindings/net/dsa/mediatek,mt7530.yaml @@ -11,16 +11,23 @@ maintainers: - Landen Chao - DENG Qingfang - Sean Wang + - Daniel Golle description: | - There are two versions of MT7530, standalone and in a multi-chip module. + There are three versions of MT7530, standalone, in a multi-chip module and + built-into a SoC. MT7530 is a part of the multi-chip module in MT7620AN, MT7620DA, MT7620DAN, MT7620NN, MT7621AT, MT7621DAT, MT7621ST and MT7623AI SoCs. + The MT7988 SoC comes a built-in switch similar to MT7531 as well as 4 Gigabit + Ethernet PHYs and the switch registers are directly mapped into SoC's memory + map rather than using MDIO. It comes with an internally connected 10G CPU port + and 4 user ports connected to the built-in Gigabit Ethernet PHYs. + MT7530 in MT7620AN, MT7620DA, MT7620DAN and MT7620NN SoCs has got 10/100 PHYs and the switch registers are directly mapped into SoC's memory map rather than - using MDIO. The DSA driver currently doesn't support this. + using MDIO. The DSA driver currently doesn't support MT7620 variants. There is only the standalone version of MT7531. @@ -81,6 +88,10 @@ properties: Multi-chip module MT7530 in MT7621AT, MT7621DAT and MT7621ST SoCs const: mediatek,mt7621 + - description: + Built-in switch of the MT7988 SoC + const: mediatek,mt7988-switch + reg: maxItems: 1 @@ -268,6 +279,17 @@ allOf: required: - mediatek,mcm + - if: + properties: + compatible: + const: mediatek,mt7988-switch + then: + $ref: "#/$defs/mt7530-dsa-port" + properties: + gpio-controller: false + mediatek,mcm: false + reset-names: false + unevaluatedProperties: false examples: