netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chen Minqiang <ptpt52@gmail.com>
To: Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	"Chester A. Unal" <chester.a.unal@arinc9.com>,
	Daniel Golle <daniel@makrotopia.org>,
	DENG Qingfang <dqfext@gmail.com>,
	Sean Wang <sean.wang@mediatek.com>, Andrew Lunn <andrew@lunn.ch>
Cc: linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org, netdev@vger.kernel.org,
	Chen Minqiang <ptpt52@gmail.com>
Subject: [PATCH v3 2/2] net: dsa: mt7530: Use GPIO polarity to generate correct reset sequence
Date: Sun, 30 Nov 2025 07:46:03 +0800	[thread overview]
Message-ID: <20251129234603.2544-2-ptpt52@gmail.com> (raw)
In-Reply-To: <20251129234603.2544-1-ptpt52@gmail.com>

The MT7530/MT7531 reset pin is active-low in hardware, but the driver
historically hardcoded a high-active reset sequence by toggling the GPIO
as 0 → 1. This only worked because several DTS files incorrectly marked
the reset GPIO as active-high, making both DTS and driver wrong in the
same way.

This patch changes the driver to respect the GPIO polarity using
gpiod_is_active_low(), and generates the reset sequence as:

    assert   = drive logical active level
    deassert = drive logical inactive level

As a result, both cases now correctly produce the required
high → low → high transition on the actual reset pin.

Compatibility
-------------

This change makes the driver fully backward-compatible with older,
incorrect DTS files that marked the reset line as GPIO_ACTIVE_HIGH:

 * Old DTS marked active-high:
       is_active_low = 0
       driver drives 0 → 1
       actual levels: high → low → high  (correct)

 * New DTS marked active-low:
       is_active_low = 1
       driver drives 1 → 0
       actual levels: high → low → high  (correct)

Therefore, regardless of whether a DTS is old or new, correct or
incorrect, the driver now generates the correct electrical reset pulse.

Going forward, DTS files should use GPIO_ACTIVE_LOW to match the
hardware, but no regressions will occur with older DTS blobs.

Signed-off-by: Chen Minqiang <ptpt52@gmail.com>
---
 drivers/net/dsa/mt7530.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
index 548b85befbf4..615e9a5709ca 100644
--- a/drivers/net/dsa/mt7530.c
+++ b/drivers/net/dsa/mt7530.c
@@ -2405,9 +2405,10 @@ mt7530_setup(struct dsa_switch *ds)
 		usleep_range(5000, 5100);
 		reset_control_deassert(priv->rstc);
 	} else {
-		gpiod_set_value_cansleep(priv->reset, 0);
+		int is_active_low = !!gpiod_is_active_low(priv->reset);
+		gpiod_set_value_cansleep(priv->reset, is_active_low);
 		usleep_range(5000, 5100);
-		gpiod_set_value_cansleep(priv->reset, 1);
+		gpiod_set_value_cansleep(priv->reset, !is_active_low);
 	}
 
 	/* Waiting for MT7530 got to stable */
@@ -2643,9 +2644,10 @@ mt7531_setup(struct dsa_switch *ds)
 		usleep_range(5000, 5100);
 		reset_control_deassert(priv->rstc);
 	} else {
-		gpiod_set_value_cansleep(priv->reset, 0);
+		int is_active_low = !!gpiod_is_active_low(priv->reset);
+		gpiod_set_value_cansleep(priv->reset, is_active_low);
 		usleep_range(5000, 5100);
-		gpiod_set_value_cansleep(priv->reset, 1);
+		gpiod_set_value_cansleep(priv->reset, !is_active_low);
 	}
 
 	/* Waiting for MT7530 got to stable */
-- 
2.17.1


  reply	other threads:[~2025-11-29 23:46 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-29 23:46 [PATCH v3 1/2] ARM64: dts: mediatek: fix MT7531 reset GPIO polarity on multiple boards Chen Minqiang
2025-11-29 23:46 ` Chen Minqiang [this message]
2025-11-30  1:11   ` [PATCH v3 2/2] net: dsa: mt7530: Use GPIO polarity to generate correct reset sequence Andrew Lunn
2025-11-30  8:07     ` Vladimir Oltean
2025-11-30 20:17       ` Andrew Lunn
2025-12-01  7:48         ` Krzysztof Kozlowski
2025-12-02 11:52           ` Frank Wunderlich
2025-12-02 12:20             ` Daniel Golle
2025-12-04 13:16               ` Vladimir Oltean
2025-12-04 13:50                 ` Daniel Golle
2025-12-04 15:45                   ` Vladimir Oltean
2025-12-04 14:49                 ` Krzysztof Kozlowski
2025-12-04 16:02                   ` Vladimir Oltean
2025-12-04 16:48                     ` Krzysztof Kozlowski
2025-12-04 17:11                       ` Vladimir Oltean
2025-12-04 17:23                         ` Krzysztof Kozlowski
2025-12-04 17:32                           ` Krzysztof Kozlowski
2025-12-04 20:47                             ` Russell King (Oracle)
2025-12-04 17:45                           ` Russell King (Oracle)
2025-12-04 18:21                             ` Vladimir Oltean
2025-12-04 15:22                 ` Andrew Lunn
2025-12-04 15:37                   ` Vladimir Oltean
2025-12-04 15:50                     ` Andrew Lunn
2025-12-04 15:52                     ` Krzysztof Kozlowski
2025-12-04 16:33                       ` Vladimir Oltean
2025-11-30  8:22   ` Vladimir Oltean
2025-12-01  7:50   ` Krzysztof Kozlowski
2025-11-30  1:00 ` [PATCH v3 1/2] ARM64: dts: mediatek: fix MT7531 reset GPIO polarity on multiple boards Andrew Lunn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251129234603.2544-2-ptpt52@gmail.com \
    --to=ptpt52@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=chester.a.unal@arinc9.com \
    --cc=conor+dt@kernel.org \
    --cc=daniel@makrotopia.org \
    --cc=dqfext@gmail.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sean.wang@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).