mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Rodolfo Giometti <giometti@enneenne.com>
To: Woojung Huh <woojung.huh@microchip.com>,
	UNGLinuxDriver@microchip.com, Andrew Lunn <andrew@lunn.ch>,
	Vladimir Oltean <olteanv@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>
Cc: Marek Vasut <marex@denx.de>,
	netdev@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Rodolfo Giometti <giometti@enneenne.com>
Subject: [PATCH net-next 2/2] net: dsa: microchip: take the reset timings from the device tree
Date: Fri,  2 Oct 2026 15:55:42 +0200	[thread overview]
Message-ID: <20261002135542.359756-3-giometti@enneenne.com> (raw)
In-Reply-To: <20261002135542.359756-1-giometti@enneenne.com>

ksz_switch_register() holds the reset line asserted for 10ms and then
waits a fixed 100ms before reading the chip ID. On an i.MX93 board
fitted with a KSZ9897 the switch starts answering 95-120ms after a
10ms reset pulse, and about 160ms after a 1s one, so the read can
return all ones, and the probe then gives up:

  ksz-switch spi0.0: unsupported switch detected ffffff00)

The same part on another board of the same family answers well within
the 100ms, which makes the wait a property of the board rather than of
the driver.

Take reset-assert-us and reset-deassert-us from the device tree, keeping
the current timings as the defaults so nothing changes for the boards
that do not set them. The delays are now free to span the ranges of the
different sleep helpers, so let fsleep() pick.

Assisted-by: LLM
Signed-off-by: Rodolfo Giometti <giometti@enneenne.com>
---
 drivers/net/dsa/microchip/ksz_common.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index 767c8fe8e819..365a804eee31 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -23,6 +23,7 @@
 #include <linux/of_net.h>
 #include <linux/micrel_phy.h>
 #include <linux/pinctrl/consumer.h>
+#include <linux/property.h>
 #include <net/dsa.h>
 #include <net/ieee8021q.h>
 #include <net/pkt_cls.h>
@@ -3990,6 +3991,8 @@ int ksz_switch_register(struct ksz_device *dev)
 	const struct ksz_chip_data *info;
 	struct device_node *ports;
 	phy_interface_t interface;
+	u32 deassert_us = 100000;
+	u32 assert_us = 10000;
 	unsigned int port_num;
 	u32 lookup_chip_id;
 	int ret;
@@ -4001,6 +4004,19 @@ int ksz_switch_register(struct ksz_device *dev)
 		return PTR_ERR(dev->reset_gpio);
 
 	if (dev->reset_gpio) {
+		/*
+		 * How long the switch takes to answer on the management bus
+		 * after the reset is released is a property of the board, not
+		 * of the driver: about 160ms has been measured on one of
+		 * them. The values above are only the historical default,
+		 * so a board that needs more states its own timing with the
+		 * properties MDIO devices already use for the same purpose.
+		 */
+		device_property_read_u32(dev->dev, "reset-assert-us",
+					 &assert_us);
+		device_property_read_u32(dev->dev, "reset-deassert-us",
+					 &deassert_us);
+
 		if (of_device_is_compatible(dev->dev->of_node, "microchip,ksz8463")) {
 			ret = ksz8463_configure_straps_spi(dev);
 			if (ret)
@@ -4008,9 +4024,9 @@ int ksz_switch_register(struct ksz_device *dev)
 		}
 
 		gpiod_set_value_cansleep(dev->reset_gpio, 1);
-		usleep_range(10000, 12000);
+		fsleep(assert_us);
 		gpiod_set_value_cansleep(dev->reset_gpio, 0);
-		msleep(100);
+		fsleep(deassert_us);
 
 		if (of_device_is_compatible(dev->dev->of_node, "microchip,ksz8463")) {
 			ret = ksz8463_release_straps_spi(dev);
-- 
2.43.0


      parent reply	other threads:[~2026-10-02 13:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-02 13:55 [PATCH net-next 0/2] net: dsa: microchip: let the board state its reset timing Rodolfo Giometti
2026-10-02 13:55 ` [PATCH net-next 1/2] dt-bindings: net: dsa: microchip: add reset timing properties Rodolfo Giometti
2026-10-02 13:55 ` Rodolfo Giometti [this message]

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=20261002135542.359756-3-giometti@enneenne.com \
    --to=giometti@enneenne.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=andrew@lunn.ch \
    --cc=conor+dt@kernel.org \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marex@denx.de \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=robh@kernel.org \
    --cc=woojung.huh@microchip.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

all inboxes | Powered by JetHome®