mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Oleksij Rempel <o.rempel@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Oleksij Rempel <o.rempel@pengutronix.de>
Subject: [PATCH v1 3/8] net: ksz8873: add device validation to be able to detect missing switch
Date: Mon, 26 Sep 2022 10:17:35 +0200	[thread overview]
Message-ID: <20220926081740.76968-3-o.rempel@pengutronix.de> (raw)
In-Reply-To: <20220926081740.76968-1-o.rempel@pengutronix.de>

Some board variants do not have ksz8873 chip but still need to use
same devicetree as the board with this chip. So we need to make sure if
switch chip is actually present, before completing the probe sequence.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/ksz8873.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/drivers/net/ksz8873.c b/drivers/net/ksz8873.c
index bd8071b872..38f61ed43e 100644
--- a/drivers/net/ksz8873.c
+++ b/drivers/net/ksz8873.c
@@ -10,6 +10,11 @@
 #include <of_device.h>
 #include <regmap.h>
 
+#define KSZ8873_CHIP_ID0		0x00
+#define KSZ8873_CHIP_ID1		0x01
+#define KSZ88_CHIP_ID_M			GENMASK(7, 4)
+#define KSZ88_REV_ID_M			GENMASK(3, 1)
+
 #define KSZ8873_GLOBAL_CTRL_1		0x03
 #define KSZ8873_PASS_ALL_FRAMES		BIT(7)
 #define KSZ8873_P3_TAIL_TAG_EN		BIT(6)
@@ -52,6 +57,8 @@
 struct ksz8873_dcfg {
 	unsigned int num_ports;
 	unsigned int phy_port_cnt;
+	u8 id0;
+	u8 id1;
 };
 
 struct ksz8873_switch {
@@ -363,6 +370,7 @@ static int ksz8873_probe_mdio(struct phy_device *mdiodev)
 	struct ksz8873_switch *priv;
 	struct dsa_switch *ds;
 	int ret, gpio;
+	u8 id0, id1;
 
 	priv = xzalloc(sizeof(*priv));
 
@@ -387,6 +395,18 @@ static int ksz8873_probe_mdio(struct phy_device *mdiodev)
 		gpio_set_active(gpio, false);
 	}
 
+	ret = ksz_read8(priv, KSZ8873_CHIP_ID0, &id0);
+	if (ret)
+		return ret;
+
+	ret = ksz_read8(priv, KSZ8873_CHIP_ID1, &id1);
+	if (ret)
+		return ret;
+
+	if (id0 != dcfg->id0 ||
+	    (id1 & (KSZ88_CHIP_ID_M | KSZ88_REV_ID_M)) != dcfg->id1)
+		return -ENODEV;
+
 	ds = &priv->ds;
 	ds->dev = dev;
 	ds->num_ports = dcfg->num_ports;
@@ -407,6 +427,8 @@ static int ksz8873_probe_mdio(struct phy_device *mdiodev)
 static const struct ksz8873_dcfg ksz8873_dcfg = {
 	.num_ports = 3,
 	.phy_port_cnt = 2,
+	.id0 = 0x88,
+	.id1 = 0x30,
 };
 
 static const struct of_device_id ksz8873_dt_ids[] = {
-- 
2.30.2




  parent reply	other threads:[~2022-09-26  8:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-26  8:17 [PATCH v1 1/8] mdio_bus: do reset only on PHY devices Oleksij Rempel
2022-09-26  8:17 ` [PATCH v1 2/8] driver: add dev_is_probed() helper function Oleksij Rempel
2022-09-26  8:17 ` Oleksij Rempel [this message]
2022-09-26  8:17 ` [PATCH v1 4/8] ARM: boards: skov-imx6: free used gpio devices pins Oleksij Rempel
2022-09-26  8:17 ` [PATCH v1 5/8] ARM: boards: skov-imx6: rework switch detection Oleksij Rempel
2022-09-26  8:17 ` [PATCH v1 6/8] ARM: boards: Skov-i.MX6: select KSZ8873 switch driver Oleksij Rempel
2022-09-26  8:17 ` [PATCH v1 7/8] ARM: dts: Skov i.MX6: start using mainlined kernel dts Oleksij Rempel
2022-09-26  8:17 ` [PATCH v1 8/8] net: dsa: do not wait for aneg is actually done on the port start Oleksij Rempel
2022-10-04  7:44 ` [PATCH v1 1/8] mdio_bus: do reset only on PHY devices Sascha Hauer

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=20220926081740.76968-3-o.rempel@pengutronix.de \
    --to=o.rempel@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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