All of lore.kernel.org
 help / color / mirror / Atom feed
From: Parthiban Veerasooran <Parthiban.Veerasooran@microchip.com>
To: <davem@davemloft.net>, <edumazet@google.com>, <kuba@kernel.org>,
	<pabeni@redhat.com>, <robh+dt@kernel.org>,
	<krzysztof.kozlowski+dt@linaro.org>, <conor+dt@kernel.org>,
	<corbet@lwn.net>, <steen.hegelund@microchip.com>,
	<rdunlap@infradead.org>, <horms@kernel.org>,
	<casper.casan@gmail.com>, <andrew@lunn.ch>
Cc: <netdev@vger.kernel.org>, <devicetree@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <linux-doc@vger.kernel.org>,
	<horatiu.vultur@microchip.com>, <Woojung.Huh@microchip.com>,
	<Nicolas.Ferre@microchip.com>, <UNGLinuxDriver@microchip.com>,
	<Thorsten.Kummermehr@microchip.com>,
	Parthiban Veerasooran <Parthiban.Veerasooran@microchip.com>
Subject: [PATCH net-next v2 2/9] net: ethernet: oa_tc6: implement mac-phy software reset
Date: Mon, 23 Oct 2023 21:16:42 +0530	[thread overview]
Message-ID: <20231023154649.45931-3-Parthiban.Veerasooran@microchip.com> (raw)
In-Reply-To: <20231023154649.45931-1-Parthiban.Veerasooran@microchip.com>

Reset complete bit is set when the MAC-PHY reset completes and ready for
configuration. When it is set, it will generate a non-maskable interrupt
to alert the SPI host. Additionally reset complete bit in the STS0
register has to be written by one upon reset complete to clear the
interrupt.

Signed-off-by: Parthiban Veerasooran <Parthiban.Veerasooran@microchip.com>
---
 drivers/net/ethernet/oa_tc6.c | 64 ++++++++++++++++++++++++++++++++---
 include/linux/oa_tc6.h        |  9 +++++
 2 files changed, 69 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/oa_tc6.c b/drivers/net/ethernet/oa_tc6.c
index acedc327b05e..e4457569135f 100644
--- a/drivers/net/ethernet/oa_tc6.c
+++ b/drivers/net/ethernet/oa_tc6.c
@@ -6,6 +6,8 @@
  */
 
 #include <linux/bitfield.h>
+#include <linux/interrupt.h>
+#include <linux/delay.h>
 #include <linux/oa_tc6.h>
 
 /* Opaque structure for MACPHY drivers */
@@ -169,10 +171,15 @@ static int oa_tc6_perform_ctrl(struct oa_tc6 *tc6, u32 addr, u32 val[], u8 len,
 	if (ret)
 		return ret;
 
-	/* Check echoed/received control reply for errors */
-	ret = oa_tc6_check_control(tc6, tx_buf, rx_buf, len, wnr, prote);
-	if (ret)
-		return ret;
+	/* In case of reset write, the echoed control command doesn't have any
+	 * valid data. So no need to check for errors.
+	 */
+	if (addr != RESET) {
+		/* Check echoed/received control reply for errors */
+		ret = oa_tc6_check_control(tc6, tx_buf, rx_buf, len, wnr, prote);
+		if (ret)
+			return ret;
+	}
 
 	if (!wnr) {
 		/* Copy read data from the rx data in case of ctrl read */
@@ -191,6 +198,49 @@ static int oa_tc6_perform_ctrl(struct oa_tc6 *tc6, u32 addr, u32 val[], u8 len,
 	return ret;
 }
 
+static int oa_tc6_sw_reset(struct oa_tc6 *tc6)
+{
+	u32 regval;
+	int ret;
+
+	/* Perform software reset with both protected and unprotected control
+	 * commands because the driver doesn't know the current status of the
+	 * MAC-PHY.
+	 */
+	regval = SWRESET;
+	ret = oa_tc6_perform_ctrl(tc6, RESET, &regval, 1, true, true);
+	if (ret)
+		return ret;
+
+	ret = oa_tc6_perform_ctrl(tc6, RESET, &regval, 1, true, false);
+	if (ret)
+		return ret;
+
+	/* The chip completes a reset in 3us, we might get here earlier than
+	 * that, as an added margin we'll conditionally sleep 5us.
+	 */
+	udelay(5);
+
+	ret = oa_tc6_perform_ctrl(tc6, STATUS0, &regval, 1, false, false);
+	if (ret)
+		return ret;
+
+	/* Check for reset complete interrupt status */
+	if (regval & RESETC) {
+		regval = RESETC;
+		/* SPI host should write RESETC bit with one to
+		 * clear the reset interrupt status.
+		 */
+		ret = oa_tc6_perform_ctrl(tc6, STATUS0, &regval, 1, true, false);
+		if (ret)
+			return ret;
+	} else {
+		return -ENODEV;
+	}
+
+	return 0;
+}
+
 /**
  * oa_tc6_write_register - function for writing a MACPHY register.
  * @tc6: oa_tc6 struct.
@@ -279,6 +329,12 @@ struct oa_tc6 *oa_tc6_init(struct spi_device *spi, bool prote)
 	tc6->spi = spi;
 	tc6->prote = prote;
 
+	/* Perform MAC-PHY software reset */
+	if (oa_tc6_sw_reset(tc6)) {
+		dev_err(&spi->dev, "MAC-PHY software reset failed\n");
+		return NULL;
+	}
+
 	return tc6;
 }
 EXPORT_SYMBOL_GPL(oa_tc6_init);
diff --git a/include/linux/oa_tc6.h b/include/linux/oa_tc6.h
index 6284828bda42..8a838499da97 100644
--- a/include/linux/oa_tc6.h
+++ b/include/linux/oa_tc6.h
@@ -21,6 +21,15 @@
 #define TC6_FTR_SIZE		4	/* Ctrl command footer size ss per OA */
 #define TC6_CTRL_BUF_SIZE	1032	/* Max ctrl buffer size for 128 regs */
 
+/* Open Alliance TC6 Standard Control and Status Registers */
+/* Reset Control and Status Register */
+#define RESET			0x0003
+#define SWRESET			BIT(0)	/* Software Reset */
+
+/* Status Register #0 */
+#define STATUS0			0x0008
+#define RESETC			BIT(6)	/* Reset Complete */
+
 struct oa_tc6 *oa_tc6_init(struct spi_device *spi, bool prote);
 int oa_tc6_write_register(struct oa_tc6 *tc6, u32 addr, u32 val);
 int oa_tc6_read_register(struct oa_tc6 *tc6, u32 addr, u32 *val);
-- 
2.34.1


  parent reply	other threads:[~2023-10-23 15:47 UTC|newest]

Thread overview: 73+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-23 15:46 [PATCH net-next v2 0/9] Add support for OPEN Alliance 10BASE-T1x MACPHY Serial Interface Parthiban Veerasooran
2023-10-23 15:46 ` [PATCH net-next v2 1/9] net: ethernet: implement OPEN Alliance control transaction interface Parthiban Veerasooran
2023-10-23 21:28   ` Andrew Lunn
2023-10-25 11:16     ` Parthiban.Veerasooran
2023-10-26 19:46       ` Andrew Lunn
2023-10-27  7:15         ` Parthiban.Veerasooran
2023-10-23 23:09   ` kernel test robot
2023-10-25 19:09   ` kernel test robot
2023-10-23 15:46 ` Parthiban Veerasooran [this message]
2023-10-23 22:43   ` [PATCH net-next v2 2/9] net: ethernet: oa_tc6: implement mac-phy software reset Andrew Lunn
2023-10-25 11:39     ` Parthiban.Veerasooran
2023-10-26 20:01       ` Andrew Lunn
2023-10-27  7:00         ` Parthiban.Veerasooran
2023-10-25 11:39     ` Parthiban.Veerasooran
2023-10-23 15:46 ` [PATCH net-next v2 3/9] net: ethernet: oa_tc6: implement OA TC6 configuration function Parthiban Veerasooran
2023-10-23 22:58   ` Andrew Lunn
2023-10-25 12:02     ` Parthiban.Veerasooran
2023-10-26 20:06       ` Andrew Lunn
2023-10-27  7:10         ` Parthiban.Veerasooran
2023-10-23 15:46 ` [PATCH net-next v2 4/9] dt-bindings: net: add OPEN Alliance 10BASE-T1x MAC-PHY Serial Interface Parthiban Veerasooran
2023-10-23 17:40   ` Rob Herring
2023-10-25 12:28     ` Parthiban.Veerasooran
2023-10-24  0:37   ` Andrew Lunn
2023-10-27  9:12     ` Parthiban.Veerasooran
2023-10-27 12:32       ` Andrew Lunn
2023-10-30 10:09         ` Parthiban.Veerasooran
2023-10-24  7:44   ` Krzysztof Kozlowski
2023-10-31 12:59     ` Parthiban.Veerasooran
2023-10-23 15:46 ` [PATCH net-next v2 5/9] net: ethernet: oa_tc6: implement internal PHY initialization Parthiban Veerasooran
2023-10-24  0:56   ` Andrew Lunn
2023-10-31  4:20     ` Parthiban.Veerasooran
2023-10-31 12:48       ` Andrew Lunn
2023-11-01  4:53         ` Parthiban.Veerasooran
2023-10-23 15:46 ` [PATCH net-next v2 6/9] dt-bindings: net: oa-tc6: add PHY register access capability Parthiban Veerasooran
2023-10-24  1:21   ` Andrew Lunn
2023-10-31  4:22     ` Parthiban.Veerasooran
2023-10-23 15:46 ` [PATCH net-next v2 7/9] net: ethernet: oa_tc6: implement data transaction interface Parthiban Veerasooran
2023-10-24  2:07   ` Andrew Lunn
2023-10-31  8:26     ` Parthiban.Veerasooran
2023-10-23 15:46 ` [PATCH net-next v2 8/9] microchip: lan865x: add driver support for Microchip's LAN865X MACPHY Parthiban Veerasooran
2023-10-24  2:33   ` Andrew Lunn
2023-10-31 11:04     ` Parthiban.Veerasooran
2023-10-31 12:53       ` Andrew Lunn
2023-11-01  4:51         ` Parthiban.Veerasooran
2023-10-24 11:57   ` Krzysztof Kozlowski
2023-10-31 10:25     ` Parthiban.Veerasooran
2023-11-02 12:20   ` Ramón Nordin Rodriguez
2023-11-02 12:39     ` Andrew Lunn
2023-11-02 13:40       ` Ramón Nordin Rodriguez
2023-11-03 14:59     ` Parthiban.Veerasooran
2023-11-06  8:59       ` Ramón Nordin Rodriguez
2023-10-23 15:46 ` [PATCH net-next v2 9/9] dt-bindings: net: add Microchip's LAN865X 10BASE-T1S MACPHY Parthiban Veerasooran
2023-10-23 17:40   ` Rob Herring
2023-10-30 12:41     ` Parthiban.Veerasooran
2023-10-24  8:03   ` Krzysztof Kozlowski
2023-10-30 13:16     ` Parthiban.Veerasooran
2023-10-30 14:45       ` Krzysztof Kozlowski
2023-11-02 13:31         ` Parthiban.Veerasooran
2024-02-16 22:13 ` [PATCH net-next v2 0/9] Add support for OPEN Alliance 10BASE-T1x MACPHY Serial Interface Andrew Lunn
2024-02-19  9:46   ` Parthiban.Veerasooran
2024-02-19 14:30     ` Andrew Lunn
2024-02-21  5:15       ` Parthiban.Veerasooran
2024-02-21 12:21         ` Piergiorgio Beruto
2024-02-22  5:17           ` Parthiban.Veerasooran
2024-03-04 11:14       ` Parthiban.Veerasooran
2024-03-04 13:22         ` Andrew Lunn
2024-03-05 13:22           ` Parthiban.Veerasooran
2024-03-24 11:55 ` Benjamin Bigler
2024-03-25 13:24   ` Parthiban.Veerasooran
2024-03-25 14:01     ` Andrew Lunn
2024-03-26  9:43       ` Parthiban.Veerasooran
2024-04-03 21:40     ` Benjamin Bigler
2024-04-08 13:41       ` Parthiban.Veerasooran

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=20231023154649.45931-3-Parthiban.Veerasooran@microchip.com \
    --to=parthiban.veerasooran@microchip.com \
    --cc=Nicolas.Ferre@microchip.com \
    --cc=Thorsten.Kummermehr@microchip.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=Woojung.Huh@microchip.com \
    --cc=andrew@lunn.ch \
    --cc=casper.casan@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@google.com \
    --cc=horatiu.vultur@microchip.com \
    --cc=horms@kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=kuba@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rdunlap@infradead.org \
    --cc=robh+dt@kernel.org \
    --cc=steen.hegelund@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.