linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] drivers: net: mdio-sun4i: Speedup mdio read and write
@ 2022-09-06  7:56 qianfanguijin
  2022-09-06  7:56 ` [PATCH 2/2] drivers: net: mdio-sun4i: Wait mdio write done qianfanguijin
  2022-09-06 19:52 ` [PATCH 1/2] drivers: net: mdio-sun4i: Speedup mdio read and write Jernej Škrabec
  0 siblings, 2 replies; 3+ messages in thread
From: qianfanguijin @ 2022-09-06  7:56 UTC (permalink / raw)
  To: linux-sunxi, linux-kernel
  Cc: Maxime Ripard, Chen-Yu Tsai, Jernej Skrabec, linux-arm-kernel,
	Evgeny Boger, qianfan Zhao

From: qianfan Zhao <qianfanguijin@163.com>

msleep(1) on my board takes about 30ms, and it is too long to accept.
Use read_poll_timeout to speedup.

Signed-off-by: qianfan Zhao <qianfanguijin@163.com>
---
 drivers/net/mdio/mdio-sun4i.c | 29 ++++++++++++-----------------
 1 file changed, 12 insertions(+), 17 deletions(-)

diff --git a/drivers/net/mdio/mdio-sun4i.c b/drivers/net/mdio/mdio-sun4i.c
index f798de3276dc..168e2a375535 100644
--- a/drivers/net/mdio/mdio-sun4i.c
+++ b/drivers/net/mdio/mdio-sun4i.c
@@ -26,8 +26,6 @@
 #define EMAC_MAC_MIND_REG	(0x10)
 #define EMAC_MAC_SSRR_REG	(0x14)
 
-#define MDIO_TIMEOUT		(msecs_to_jiffies(100))
-
 struct sun4i_mdio_data {
 	void __iomem		*membase;
 	struct regulator	*regulator;
@@ -36,8 +34,7 @@ struct sun4i_mdio_data {
 static int sun4i_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
 {
 	struct sun4i_mdio_data *data = bus->priv;
-	unsigned long timeout_jiffies;
-	int value;
+	int ret, tmp, value;
 
 	/* issue the phy address and reg */
 	writel((mii_id << 8) | regnum, data->membase + EMAC_MAC_MADR_REG);
@@ -45,12 +42,11 @@ static int sun4i_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
 	writel(0x1, data->membase + EMAC_MAC_MCMD_REG);
 
 	/* Wait read complete */
-	timeout_jiffies = jiffies + MDIO_TIMEOUT;
-	while (readl(data->membase + EMAC_MAC_MIND_REG) & 0x1) {
-		if (time_is_before_jiffies(timeout_jiffies))
-			return -ETIMEDOUT;
-		msleep(1);
-	}
+	ret = read_poll_timeout(readl, tmp, (tmp & 1) == 0,
+				20, 10000, false,
+				data->membase + EMAC_MAC_MIND_REG);
+	if (ret < 0)
+		return ret;
 
 	/* push down the phy io line */
 	writel(0x0, data->membase + EMAC_MAC_MCMD_REG);
@@ -64,7 +60,7 @@ static int sun4i_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
 			    u16 value)
 {
 	struct sun4i_mdio_data *data = bus->priv;
-	unsigned long timeout_jiffies;
+	int ret, tmp;
 
 	/* issue the phy address and reg */
 	writel((mii_id << 8) | regnum, data->membase + EMAC_MAC_MADR_REG);
@@ -72,12 +68,11 @@ static int sun4i_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
 	writel(0x1, data->membase + EMAC_MAC_MCMD_REG);
 
 	/* Wait read complete */
-	timeout_jiffies = jiffies + MDIO_TIMEOUT;
-	while (readl(data->membase + EMAC_MAC_MIND_REG) & 0x1) {
-		if (time_is_before_jiffies(timeout_jiffies))
-			return -ETIMEDOUT;
-		msleep(1);
-	}
+	ret = read_poll_timeout(readl, tmp, (tmp & 1) == 0,
+				20, 10000, false,
+				data->membase + EMAC_MAC_MIND_REG);
+	if (ret < 0)
+		return ret;
 
 	/* push down the phy io line */
 	writel(0x0, data->membase + EMAC_MAC_MCMD_REG);
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-09-06 19:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-06  7:56 [PATCH 1/2] drivers: net: mdio-sun4i: Speedup mdio read and write qianfanguijin
2022-09-06  7:56 ` [PATCH 2/2] drivers: net: mdio-sun4i: Wait mdio write done qianfanguijin
2022-09-06 19:52 ` [PATCH 1/2] drivers: net: mdio-sun4i: Speedup mdio read and write Jernej Škrabec

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).