Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1643945lql; Wed, 13 Mar 2024 04:25:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXix2TMTFA4k5PfiTO+4QE1vfVOWkYIV0fXbjX60jykNs8VHHLR+dkpi6u3u5RVPKQ7ZrIC9HbLk6O9Z3bsLhDbslIKk1knf6Pq1GO1nQ== X-Google-Smtp-Source: AGHT+IHa74m7rj7h5InOukMNV3mvmEO4l5yo75QGfl2XTuZS+gmP5bTV87LU7fnsShiO6LSoiTcZ X-Received: by 2002:a05:6870:41cc:b0:220:873d:dbcc with SMTP id z12-20020a05687041cc00b00220873ddbccmr12952413oac.49.1710329147627; Wed, 13 Mar 2024 04:25:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710329147; cv=pass; d=google.com; s=arc-20160816; b=BVMekUGFKeulC2PPH2DXFA1bPoHPAy2d9ZUKCey4k9cplHkwI2PxM23OAFuHoJge8/ 0s6IJRsqzeiPcVeu/WOugQIdlAdV++7pLEILq662QQ36pbSLaHslWV+qsCznqDckVjXM DhPOM9qcB1ZEI+g5d0Ivcmtfomo6q7CWNseGeIVtNtfmeRgYu8pwCuXmdq5gUHTMSXBz +88tWyiN2o3DbTeHL74KPkGZcCEPDrO7NrEzYL1brPg44vdV55pU6EXYV8cbVWpZh1YE Q710F7y69/6KYFns1oZNtXzJW4rviW9ElZH30K5WWFF7P35MQ/jILqCbz420OgI9uCS2 FzDQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=reply-to:cc:to:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:subject:date :from:dkim-signature:message-id; bh=Khp9WhdhrUMC3rjvLeiFVDA0pee+bxFrxYN8BOO/r2Q=; fh=OaL65AkYiOxZ6qI1zxM3FDGOPapB2BL3WpZrXnQBIpY=; b=sQAGlV/GtgVTJHgs6PTQ4OmQJVr4ZNmVSVYQhUqwbIHdobJZyqR1JKhz3UgKVPF5VG Rheat8dQVjs6bmKKQMhnkHrCk/U2E+DxS/rZ2O155fecjuCkZS5HVdsWzEk12zpN//Xk wQ9zAWbQ9uw786vPCs2oBV1TclZWwLFai5prgKhAiGeZQ/K3f8XgYdmiEAGpA7CQ/9lE 7nDj9nlXbRk+pZzLaGvjVnUWp/kqXfv+rdr1YjjXg2iHEV0vceJnSSdPVSTTPsNpIGrZ DbH+gRAK47vQsAp6ZbBv9tMEv08rdKEH2GwAu7xpjngL8DHOYS/Ooypdes1p4PnTCeWm MPqQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UbL5fwOe; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-101434-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101434-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id m184-20020a633fc1000000b005dcd2963f82si9096808pga.626.2024.03.13.04.25.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 04:25:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-101434-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UbL5fwOe; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-101434-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101434-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Message-ID: <65f18d3b.630a0220.4f83e.26d4SMTPIN_ADDED_BROKEN@mx.google.com> X-Google-Original-Message-ID: =?utf-8?q?=3C20240313-for-netnext-mt7530-better-fix-xtal-frequen?= =?utf-8?q?cy-v1-1-5a50df99f51a=40arinc9=2Ecom=3E?= 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 448A52827D4 for ; Wed, 13 Mar 2024 11:25:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 216573F9C2; Wed, 13 Mar 2024 11:25:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UbL5fwOe" 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 0BBBB3EA72; Wed, 13 Mar 2024 11:25:35 +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=1710329136; cv=none; b=crP1umV2vr3twZUIZn4wHiy/OxTiYpfcb4TCzx30lQYkOg/rIsDpOQkGwnf1HNM+uyeoTQuEYNDy3IsNzRmCbab3ojp24HS8a9A7++8mbJ94hpcRm4dskDZgCPJX4Hl6//OYeeGs1gM381tbj1gSGuE8yGQR/4b7DfafScKhiXE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710329136; c=relaxed/simple; bh=LYcNh8f/VUH2gSW2953XdtfYjWbGSG8COCLwOqFU9ss=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=Ts0v3/PSqx1OrFjsaLmyS85NaWyXYKuW5WqBOXJBrFhxJBTSb1+0KE88/z9gTbHjxFvBS/wf1hTwIt1RCewQJAHVTuaraRZiFALCCb/CmjRg8gtwQ5d+7Q3qo8n74T3DexRhDoVwtFeXL62Vo+l1LkjI8r+GC0pmSXY9lPYrxUA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UbL5fwOe; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPS id 8D208C433C7; Wed, 13 Mar 2024 11:25:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710329135; bh=LYcNh8f/VUH2gSW2953XdtfYjWbGSG8COCLwOqFU9ss=; h=From:Date:Subject:To:Cc:Reply-To:From; b=UbL5fwOesmZxDjwGCadSLhlMetEzhhV4Sk6MRiBZPi7LHDafsiZ6rtdallYJqmKiM 79yeNbQpI9PHxcxAoF7Etf1rVvKhH8EZ0hAXLqHgMBzVHs1vWpU2iuwGcDT3/uPDIv qbNYSTqmojPupxOpwiIC7PyLYq96LuxCM89+phSPRnLP57O/ViLtUG4b2o+OzwSJXl cSLK2aGj+Y1mT7eDUipud8VnAtU1K4RBjfW3lW58ZPteo1JsrpKl+iB7xQJSQ+Egul sZaN/0scE39HIUN15P74xpLI1w0J1c6lGwjAmtIghqbsXfpnk/AaJPjXQ0QpW4Myqg iMkw97lR19y+A== 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 682FCC54791; Wed, 13 Mar 2024 11:25:35 +0000 (UTC) From: =?utf-8?b?QXLEsW7DpyDDnE5BTA==?= via B4 Relay Date: Wed, 13 Mar 2024 14:25:07 +0300 Subject: [PATCH net] net: dsa: mt7530: prevent possible incorrect XTAL frequency selection 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 X-B4-Tracking: v=1; b=H4sIABKN8WUC/x2NzQrCMBAGX6Xs2YX8WEt9FemhrV80oKluVkkpf XeDx4FhZqMMich0bjYSfGOOS6pgDw3N9zHdwPFamZxxR+Ot47AIJ2hCUX5q13rDE1QhHGLhouO Dg+D9QZpX9han0Pa9t12gmnwJqvXfXahWaNj3H5EuS5uDAAAA 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 , Philipp Zabel , Landen Chao Cc: Bartel Eerdekens , mithat.guner@xeront.com, erkin.bozoglu@xeront.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Justin Swartz , =?utf-8?q?Ar=C4=B1n=C3=A7_=C3=9CNAL?= X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1710329122; l=6561; i=arinc.unal@arinc9.com; s=arinc9-patatt; h=from:subject:message-id; bh=L64g+46HN+S29jthqvg493sRpkqBmVTreKHISDH47E8=; b=QETKrDhCZGIxxkfvVHrUw+tUQmz/zGwkbwSTF7U2X5bdPBFZKtDOmY0SPiSsK98/qW7i0Kty1 Fo+cDhkeTl+DLsjd42I1KWahApVmEMICNgNOyCa7nk9iV2a8eGtGNzy 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 On MT7530, the HT_XTAL_FSEL field of the HWTRAP register stores a 2-bit value that represents the frequency of the crystal oscillator connected to the switch IC. The field is populated by the state of the ESW_P4_LED_0 and ESW_P4_LED_0 pins, which is done right after reset is deasserted. ESW_P4_LED_0 ESW_P3_LED_0 Frequency ----------------------------------------- 0 0 Reserved 0 1 20MHz 1 0 40MHz 1 1 25MHz On MT7531, the XTAL25 bit of the STRAP register stores this. The LAN0LED0 pin is used to populate the bit. 25MHz when the pin is high, 40MHz when it's low. These pins are also used with LEDs, therefore, their state can be set to something other than the bootstrapping configuration. For example, a link may be established on port 3 before the DSA subdriver takes control of the switch which would set ESW_P3_LED_0 to high. Currently on mt7530_setup() and mt7531_setup(), 1000 - 1100 usec delay is described between reset assertion and deassertion. Some switch ICs in real life conditions cannot always have these pins set back to the bootstrapping configuration before reset deassertion in this amount of delay. This causes wrong crystal frequency to be selected which puts the switch in a nonfunctional state after reset deassertion. The tests below are conducted on an MT7530 with a 40MHz crystal oscillator by Justin Swartz. With a cable from an active peer connected to port 3 before reset, an incorrect crystal frequency (0b11 = 25MHz) is selected: [1] [3] [5] : : : _____________________________ __________________ ESW_P4_LED_0 |_______| _____________________________ ESW_P3_LED_0 |__________________________ : : : : : : [4]...: : : [2]................: [1] Reset is asserted. [2] Period of 1000 - 1100 usec. [3] Reset is deasserted. [4] Period of 315 usec. HWTRAP register is populated with incorrect XTAL frequency. [5] Signals reflect the bootstrapped configuration. Increase the delay between reset_control_assert() and reset_control_deassert(), and gpiod_set_value_cansleep(priv->reset, 0) and gpiod_set_value_cansleep(priv->reset, 1) to 5000 - 5100 usec. This amount ensures a higher possibility that the switch IC will have these pins back to the bootstrapping configuration before reset deassertion. With a cable from an active peer connected to port 3 before reset, the correct crystal frequency (0b10 = 40MHz) is selected: [1] [2-1] [3] [5] : : : : _____________________________ __________________ ESW_P4_LED_0 |_______| ___________________ _______ ESW_P3_LED_0 |_________| |__________________ : : : : : : [2-2]...: [4]...: [2]................: [1] Reset is asserted. [2] Period of 5000 - 5100 usec. [2-1] ESW_P3_LED_0 goes low. [2-2] Remaining period of 5000 - 5100 usec. [3] Reset is deasserted. [4] Period of 310 usec. HWTRAP register is populated with bootstrapped XTAL frequency. [5] Signals reflect the bootstrapped configuration. ESW_P3_LED_0 low period before reset deassertion: 5000 usec - 5100 usec TEST RESET HOLD # (usec) --------------------- 1 5410 2 5440 3 4375 4 5490 5 5475 6 4335 7 4370 8 5435 9 4205 10 4335 11 3750 12 3170 13 4395 14 4375 15 3515 16 4335 17 4220 18 4175 19 4175 20 4350 Min 3170 Max 5490 Median 4342.500 Avg 4466.500 Revert commit 2920dd92b980 ("net: dsa: mt7530: disable LEDs before reset"). Changing the state of pins via reset assertion is simpler and more efficient than doing so by setting the LED controller off. Reported-by: Justin Swartz Fixes: b8f126a8d543 ("net-next: dsa: add dsa support for Mediatek MT7530 switch") Fixes: c288575f7810 ("net: dsa: mt7530: Add the support of MT7531 switch") Signed-off-by: Arınç ÜNAL --- drivers/net/dsa/mt7530.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index 678b51f9cea6..6986f538a4d0 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -2192,22 +2192,16 @@ mt7530_setup(struct dsa_switch *ds) } } - /* Disable LEDs before reset to prevent the MT7530 sampling a - * potentially incorrect HT_XTAL_FSEL value. - */ - mt7530_write(priv, MT7530_LED_EN, 0); - usleep_range(1000, 1100); - /* Reset whole chip through gpio pin or memory-mapped registers for * different type of hardware */ if (priv->mcm) { reset_control_assert(priv->rstc); - usleep_range(1000, 1100); + usleep_range(5000, 5100); reset_control_deassert(priv->rstc); } else { gpiod_set_value_cansleep(priv->reset, 0); - usleep_range(1000, 1100); + usleep_range(5000, 5100); gpiod_set_value_cansleep(priv->reset, 1); } @@ -2420,11 +2414,11 @@ mt7531_setup(struct dsa_switch *ds) */ if (priv->mcm) { reset_control_assert(priv->rstc); - usleep_range(1000, 1100); + usleep_range(5000, 5100); reset_control_deassert(priv->rstc); } else { gpiod_set_value_cansleep(priv->reset, 0); - usleep_range(1000, 1100); + usleep_range(5000, 5100); gpiod_set_value_cansleep(priv->reset, 1); } --- base-commit: d7d75124965aee23e5e4421d78376545cf070b0a change-id: 20240312-for-netnext-mt7530-better-fix-xtal-frequency-31e6f599317f Best regards, -- Arınç ÜNAL