diff mbox series

[net-next,v2,1/2] net: stmmac: use readl_poll_timeout() function in init_systime()

Message ID 20200315150301.32129-2-zhengdejin5@gmail.com (mailing list archive)
State New, archived
Headers show
Series net: stmmac: Use readl_poll_timeout() to simplify the code | expand

Commit Message

Dejin Zheng March 15, 2020, 3:03 p.m. UTC
The init_systime() function use an open coded of readl_poll_timeout().
Replace the open coded handling with the proper function.

Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>
---
v1 -> v2:
	- no changed.

 .../net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c  | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

Comments

Andrew Lunn March 15, 2020, 6:25 p.m. UTC | #1
On Sun, Mar 15, 2020 at 11:03:00PM +0800, Dejin Zheng wrote:
> The init_systime() function use an open coded of readl_poll_timeout().
> Replace the open coded handling with the proper function.
> 
> Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>
> ---
> v1 -> v2:
> 	- no changed.
> 
>  .../net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c  | 14 ++++++--------
>  1 file changed, 6 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
> index 020159622559..2a24e2a7db3b 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
> @@ -10,6 +10,7 @@
>  *******************************************************************************/
>  
>  #include <linux/io.h>
> +#include <linux/iopoll.h>
>  #include <linux/delay.h>
>  #include "common.h"
>  #include "stmmac_ptp.h"
> @@ -53,8 +54,8 @@ static void config_sub_second_increment(void __iomem *ioaddr,
>  
>  static int init_systime(void __iomem *ioaddr, u32 sec, u32 nsec)
>  {
> -	int limit;
>  	u32 value;
> +	int err;
>  
>  	writel(sec, ioaddr + PTP_STSUR);
>  	writel(nsec, ioaddr + PTP_STNSUR);
> @@ -64,13 +65,10 @@ static int init_systime(void __iomem *ioaddr, u32 sec, u32 nsec)
>  	writel(value, ioaddr + PTP_TCR);
>  
>  	/* wait for present system time initialize to complete */
> -	limit = 10;
> -	while (limit--) {
> -		if (!(readl(ioaddr + PTP_TCR) & PTP_TCR_TSINIT))
> -			break;
> -		mdelay(10);
> -	}
> -	if (limit < 0)
> +	err = readl_poll_timeout(ioaddr + PTP_TCR, value,
> +				 !(value & PTP_TCR_TSINIT),
> +				 10000, 100000);
> +	if (err)
>  		return -EBUSY;

Hi Dejin

It is normal to just return whatever error code readl_poll_timeout()
returned.

	Andrew
David Miller March 16, 2020, 12:03 a.m. UTC | #2
From: Andrew Lunn <andrew@lunn.ch>
Date: Sun, 15 Mar 2020 19:25:04 +0100

> It is normal to just return whatever error code readl_poll_timeout()
> returned.

Agreed.
Dejin Zheng March 16, 2020, 2:17 a.m. UTC | #3
On Sun, Mar 15, 2020 at 07:25:04PM +0100, Andrew Lunn wrote:

Hi Andrew and David :

> On Sun, Mar 15, 2020 at 11:03:00PM +0800, Dejin Zheng wrote:
> > The init_systime() function use an open coded of readl_poll_timeout().
> > Replace the open coded handling with the proper function.
> > 
> > Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>
> > ---
> > v1 -> v2:
> > 	- no changed.
> > 
> >  .../net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c  | 14 ++++++--------
> >  1 file changed, 6 insertions(+), 8 deletions(-)
> > 
> > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
> > index 020159622559..2a24e2a7db3b 100644
> > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
> > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
> > @@ -10,6 +10,7 @@
> >  *******************************************************************************/
> >  
> >  #include <linux/io.h>
> > +#include <linux/iopoll.h>
> >  #include <linux/delay.h>
> >  #include "common.h"
> >  #include "stmmac_ptp.h"
> > @@ -53,8 +54,8 @@ static void config_sub_second_increment(void __iomem *ioaddr,
> >  
> >  static int init_systime(void __iomem *ioaddr, u32 sec, u32 nsec)
> >  {
> > -	int limit;
> >  	u32 value;
> > +	int err;
> >  
> >  	writel(sec, ioaddr + PTP_STSUR);
> >  	writel(nsec, ioaddr + PTP_STNSUR);
> > @@ -64,13 +65,10 @@ static int init_systime(void __iomem *ioaddr, u32 sec, u32 nsec)
> >  	writel(value, ioaddr + PTP_TCR);
> >  
> >  	/* wait for present system time initialize to complete */
> > -	limit = 10;
> > -	while (limit--) {
> > -		if (!(readl(ioaddr + PTP_TCR) & PTP_TCR_TSINIT))
> > -			break;
> > -		mdelay(10);
> > -	}
> > -	if (limit < 0)
> > +	err = readl_poll_timeout(ioaddr + PTP_TCR, value,
> > +				 !(value & PTP_TCR_TSINIT),
> > +				 10000, 100000);
> > +	if (err)
> >  		return -EBUSY;
> 
> Hi Dejin
> 
> It is normal to just return whatever error code readl_poll_timeout()
> returned.
> 
> 	Andrew

You are right. I will modify it. Thanks!

BR,
Dejin
diff mbox series

Patch

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
index 020159622559..2a24e2a7db3b 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
@@ -10,6 +10,7 @@ 
 *******************************************************************************/
 
 #include <linux/io.h>
+#include <linux/iopoll.h>
 #include <linux/delay.h>
 #include "common.h"
 #include "stmmac_ptp.h"
@@ -53,8 +54,8 @@  static void config_sub_second_increment(void __iomem *ioaddr,
 
 static int init_systime(void __iomem *ioaddr, u32 sec, u32 nsec)
 {
-	int limit;
 	u32 value;
+	int err;
 
 	writel(sec, ioaddr + PTP_STSUR);
 	writel(nsec, ioaddr + PTP_STNSUR);
@@ -64,13 +65,10 @@  static int init_systime(void __iomem *ioaddr, u32 sec, u32 nsec)
 	writel(value, ioaddr + PTP_TCR);
 
 	/* wait for present system time initialize to complete */
-	limit = 10;
-	while (limit--) {
-		if (!(readl(ioaddr + PTP_TCR) & PTP_TCR_TSINIT))
-			break;
-		mdelay(10);
-	}
-	if (limit < 0)
+	err = readl_poll_timeout(ioaddr + PTP_TCR, value,
+				 !(value & PTP_TCR_TSINIT),
+				 10000, 100000);
+	if (err)
 		return -EBUSY;
 
 	return 0;