Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2680604rdb; Mon, 5 Feb 2024 14:19:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IFFGkoZUrYS5dFouFjU6nNCYoflzzPPAfYXoc5h+MZj0vLXWEm+aziMHhNpva94+oa3VKRG X-Received: by 2002:a17:906:388:b0:a37:4bce:ca00 with SMTP id b8-20020a170906038800b00a374bceca00mr489573eja.59.1707171579968; Mon, 05 Feb 2024 14:19:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707171579; cv=pass; d=google.com; s=arc-20160816; b=Uz26Hh9s1xMRcPc+PpsjPT5vTkPsnvtY5RAJ4ng3GfoZgXJZ13Ui7hAXxg41kSYbWf 1NsXCy0sO8k7e1cepcGKnIE5hzofT0kb+keQ/clFupwZSOyxyM9XE7ssIJFNsJ66bhdQ YQI/sSalOk6HILsWLSgFjW/Q+9MKXB1ptIf7p642gwDOOe4gUInY60bcmay8t26YQwMP DtIeP/djX170hAG0jp9M70sOMHZpHr72fqvcS48/vSkR+RKi/shjRqQw50rbE8WwNDyL VEV32ulnYLTrf8wa93Avu+TxZaUBRELI/8QVHdJl3oKpAUoPifOgHqsqna/4LBwS8JQj rE+Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=reply-to:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:subject:date:from:dkim-signature; bh=iBAH3aawsVywEVbWoVzcM5jzPafpIP/QwG2nbsiBSUA=; fh=IV1pAUYVBNyTJ3E1LjA8huzx2SD8/vOeLzaZfk+p++g=; b=yWNgkFD1ZqiPPMMh9vTS/4ylM69KQmZoJQOyHdGh+5kzWqKDNb72gbN4xUrTG6T6Cz S3z02jHCeF8iVTyvMIhDSkWEKYPB0ULMJjrsxttGbe3jcK13ihNcYqiMuWAAjb4Iv/xp cW9vPgas3R2Scd+zmabdaCyERGoRYKnoMhwZ0MufdjHDsMXYCvj7Px1J7xJqJ8TDa7s9 PurUUc1mU3AQGppvkbwxTrP46mFzCXfNAXaGa+lVt1VZqDh9r4W5lSwYgOIy04RNqBv3 pu7tzeVTC+vRecaozwUgsdXlYK+6G9KZlhM0zX07OtnAi7tn5CfHZELiOJeaNJNbjuPZ I4nA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oTOJOgFK; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-54003-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54003-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCXYDyaV/zQPglN1muL1xLPz3WKaSB8LJLCmvwdY71k8klqAmXSrIfxgMdsNJgOYAUGpojm5ZWSUpRE/rdQ6acaRMsjx7ytKEo5VP4Sz2A== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id hb20-20020a170906b89400b00a37ee225324si303079ejb.116.2024.02.05.14.19.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 14:19:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54003-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oTOJOgFK; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-54003-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54003-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 78AB61F2D388 for ; Mon, 5 Feb 2024 22:19:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C830E5025F; Mon, 5 Feb 2024 22:08:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oTOJOgFK" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DB324F611; Mon, 5 Feb 2024 22:08:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707170894; cv=none; b=k76clZD5/Pfkbodh84oy0XGszRV++dfhc1X1u+fkfq88u9ZD+5SnODLl3iTlQg3J/h7VIpxSAn9xL8KPRwo1hdhs4dHf3B5TTpbgaQ3OiXq/SN+0r8zXuLzbFVLPchUq0V4VqB3XRDJR+wlREDkCjupTBDG0GlCoLyDUSiCWx+0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707170894; c=relaxed/simple; bh=Ttjg7L6LSJIN/4qKBgyu688lh/DDe+hETjj4w09DuAw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Hxacj89Py7b7XumYBNxF0fEwuH4WHlGPaIvVfovAVCzw3ij8FTY2bKlU2VKavXnub8Kb+OfBJNx88bJ6rMeoDRyhc4OZSIU+k7q5dZFypKQZQr3Itx4bKtPlRmSLYFbDczoNKArols7xV4tkDMysvgsbNODksyK510sJMCLo05E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oTOJOgFK; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPS id 63B5FC43399; Mon, 5 Feb 2024 22:08:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707170894; bh=Ttjg7L6LSJIN/4qKBgyu688lh/DDe+hETjj4w09DuAw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=oTOJOgFKg9f+TsQrSckDBPq481LGMf47Z9BHHB3SVSKy0s48mcvsDmD1vxxtJDe5x RWlLLO9sCMVhBpioPUYNaVmBXnHDtaljal5PRYEHzh1L0wE1ojltJiQb0C04XFN3wl C6ohJBnoXyueH5mpAmbfKSs7e+i8EzoGcddN4Z1naDWT9uMs/VpvvAKxsoL1A1fVpM 2/LS9yd7JyOu2mUhadQ3u0+WbFHpsQGS6Prln6FaM+zVGr0jyac71hvxJ4w2eXEABG nZJ4L8ZQ0Rf4a9Gd4VYLCfbynWaQZMB1rdxy6mZiFsfV6Aik2BHT4nAvMr5HuQAw7V joNcm73KizN4Q== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4CB58C48299; Mon, 5 Feb 2024 22:08:14 +0000 (UTC) From: =?utf-8?b?QXLEsW7DpyDDnE5BTA==?= via B4 Relay Date: Tue, 06 Feb 2024 01:08:04 +0300 Subject: [PATCH net-next v5 3/7] net: dsa: mt7530: simplify mt7530_pad_clk_setup() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20240206-for-netnext-mt7530-improvements-2-v5-3-d7d92a185cb1@arinc9.com> References: <20240206-for-netnext-mt7530-improvements-2-v5-0-d7d92a185cb1@arinc9.com> In-Reply-To: <20240206-for-netnext-mt7530-improvements-2-v5-0-d7d92a185cb1@arinc9.com> To: Daniel Golle , DENG Qingfang , Sean Wang , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Matthias Brugger , AngeloGioacchino Del Regno , Russell King Cc: mithat.guner@xeront.com, erkin.bozoglu@xeront.com, Bartel Eerdekens , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, =?utf-8?q?Ar=C4=B1n=C3=A7_=C3=9CNAL?= , "Russell King (Oracle)" X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1707170890; l=4956; i=arinc.unal@arinc9.com; s=arinc9-patatt; h=from:subject:message-id; bh=RRUQnNSPrRHOOZ/GFpvVNQgWdt14UbbbPAdZ3VLciVU=; b=CLij4/7/rsfFCF6JR/blPhD82B43gurgQ8+wRIPlvQ0mhrOwgPYXy+oDLcpsJ8mLWgKpIp7iV qyMGRhYFkz1DWBe/TmAjNNjqWy34cCVDQObwHn32tvcr5nZ6MZw9oMO X-Developer-Key: i=arinc.unal@arinc9.com; a=ed25519; pk=VmvgMWwm73yVIrlyJYvGtnXkQJy9CvbaeEqPQO9Z4kA= X-Endpoint-Received: by B4 Relay for arinc.unal@arinc9.com/arinc9-patatt with auth_id=115 X-Original-From: =?utf-8?b?QXLEsW7DpyDDnE5BTA==?= Reply-To: From: Arınç ÜNAL This code is from before this driver was converted to phylink API. Phylink deals with the unsupported interface cases before mt7530_pad_clk_setup() is run. Therefore, the default case would never run. However, it must be defined nonetheless to handle all the remaining enumeration values, the phy-modes. Switch to if statement for RGMII and return which simplifies the code and saves an indent. Set P6_INTF_MODE, which is the three least significant bits of the MT7530_P6ECR register, to 0 for RGMII even though it will already be 0 after reset. This is to keep supporting dynamic reconfiguration of the port in the case the interface changes from TRGMII to RGMII. Disable the TRGMII clocks for all cases. They will be enabled if TRGMII is being used. Read XTAL after checking for RGMII as it's only needed for the TRGMII interface mode. Reviewed-by: Daniel Golle Reviewed-by: Russell King (Oracle) Signed-off-by: Arınç ÜNAL --- drivers/net/dsa/mt7530.c | 91 +++++++++++++++++++++--------------------------- 1 file changed, 40 insertions(+), 51 deletions(-) diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index 8b8469eba863..e13b9c9cb19f 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -418,64 +418,53 @@ static int mt7530_pad_clk_setup(struct dsa_switch *ds, phy_interface_t interface) { struct mt7530_priv *priv = ds->priv; - u32 ncpo1, ssc_delta, trgint, xtal; + u32 ncpo1, ssc_delta, xtal; - xtal = mt7530_read(priv, MT7530_MHWTRAP) & HWTRAP_XTAL_MASK; + /* Disable the MT7530 TRGMII clocks */ + core_clear(priv, CORE_TRGMII_GSW_CLK_CG, REG_TRGMIICK_EN); - switch (interface) { - case PHY_INTERFACE_MODE_RGMII: - trgint = 0; - break; - case PHY_INTERFACE_MODE_TRGMII: - trgint = 1; - if (xtal == HWTRAP_XTAL_25MHZ) - ssc_delta = 0x57; - else - ssc_delta = 0x87; - if (priv->id == ID_MT7621) { - /* PLL frequency: 125MHz: 1.0GBit */ - if (xtal == HWTRAP_XTAL_40MHZ) - ncpo1 = 0x0640; - if (xtal == HWTRAP_XTAL_25MHZ) - ncpo1 = 0x0a00; - } else { /* PLL frequency: 250MHz: 2.0Gbit */ - if (xtal == HWTRAP_XTAL_40MHZ) - ncpo1 = 0x0c80; - if (xtal == HWTRAP_XTAL_25MHZ) - ncpo1 = 0x1400; - } - break; - default: - dev_err(priv->dev, "xMII interface %d not supported\n", - interface); - return -EINVAL; + if (interface == PHY_INTERFACE_MODE_RGMII) { + mt7530_rmw(priv, MT7530_P6ECR, P6_INTF_MODE_MASK, + P6_INTF_MODE(0)); + return 0; } - mt7530_rmw(priv, MT7530_P6ECR, P6_INTF_MODE_MASK, - P6_INTF_MODE(trgint)); + mt7530_rmw(priv, MT7530_P6ECR, P6_INTF_MODE_MASK, P6_INTF_MODE(1)); - if (trgint) { - /* Disable the MT7530 TRGMII clocks */ - core_clear(priv, CORE_TRGMII_GSW_CLK_CG, REG_TRGMIICK_EN); + xtal = mt7530_read(priv, MT7530_MHWTRAP) & HWTRAP_XTAL_MASK; - /* Setup the MT7530 TRGMII Tx Clock */ - core_write(priv, CORE_PLL_GROUP5, RG_LCDDS_PCW_NCPO1(ncpo1)); - core_write(priv, CORE_PLL_GROUP6, RG_LCDDS_PCW_NCPO0(0)); - core_write(priv, CORE_PLL_GROUP10, RG_LCDDS_SSC_DELTA(ssc_delta)); - core_write(priv, CORE_PLL_GROUP11, RG_LCDDS_SSC_DELTA1(ssc_delta)); - core_write(priv, CORE_PLL_GROUP4, - RG_SYSPLL_DDSFBK_EN | RG_SYSPLL_BIAS_EN | - RG_SYSPLL_BIAS_LPF_EN); - core_write(priv, CORE_PLL_GROUP2, - RG_SYSPLL_EN_NORMAL | RG_SYSPLL_VODEN | - RG_SYSPLL_POSDIV(1)); - core_write(priv, CORE_PLL_GROUP7, - RG_LCDDS_PCW_NCPO_CHG | RG_LCCDS_C(3) | - RG_LCDDS_PWDB | RG_LCDDS_ISO_EN); + if (xtal == HWTRAP_XTAL_25MHZ) + ssc_delta = 0x57; + else + ssc_delta = 0x87; - /* Enable the MT7530 TRGMII clocks */ - core_set(priv, CORE_TRGMII_GSW_CLK_CG, REG_TRGMIICK_EN); - } + if (priv->id == ID_MT7621) { + /* PLL frequency: 125MHz: 1.0GBit */ + if (xtal == HWTRAP_XTAL_40MHZ) + ncpo1 = 0x0640; + if (xtal == HWTRAP_XTAL_25MHZ) + ncpo1 = 0x0a00; + } else { /* PLL frequency: 250MHz: 2.0Gbit */ + if (xtal == HWTRAP_XTAL_40MHZ) + ncpo1 = 0x0c80; + if (xtal == HWTRAP_XTAL_25MHZ) + ncpo1 = 0x1400; + } + + /* Setup the MT7530 TRGMII Tx Clock */ + core_write(priv, CORE_PLL_GROUP5, RG_LCDDS_PCW_NCPO1(ncpo1)); + core_write(priv, CORE_PLL_GROUP6, RG_LCDDS_PCW_NCPO0(0)); + core_write(priv, CORE_PLL_GROUP10, RG_LCDDS_SSC_DELTA(ssc_delta)); + core_write(priv, CORE_PLL_GROUP11, RG_LCDDS_SSC_DELTA1(ssc_delta)); + core_write(priv, CORE_PLL_GROUP4, RG_SYSPLL_DDSFBK_EN | + RG_SYSPLL_BIAS_EN | RG_SYSPLL_BIAS_LPF_EN); + core_write(priv, CORE_PLL_GROUP2, RG_SYSPLL_EN_NORMAL | + RG_SYSPLL_VODEN | RG_SYSPLL_POSDIV(1)); + core_write(priv, CORE_PLL_GROUP7, RG_LCDDS_PCW_NCPO_CHG | + RG_LCCDS_C(3) | RG_LCDDS_PWDB | RG_LCDDS_ISO_EN); + + /* Enable the MT7530 TRGMII clocks */ + core_set(priv, CORE_TRGMII_GSW_CLK_CG, REG_TRGMIICK_EN); return 0; } -- 2.40.1