diff mbox series

usb: gadget: bdc: use readl_poll_timeout() to simplify code

Message ID 1594351856-876-1-git-send-email-chunfeng.yun@mediatek.com (mailing list archive)
State New, archived
Headers show
Series usb: gadget: bdc: use readl_poll_timeout() to simplify code | expand

Commit Message

Chunfeng Yun (云春峰) July 10, 2020, 3:30 a.m. UTC
Use readl_poll_timeout() to poll register status

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
---
 drivers/usb/gadget/udc/bdc/bdc_core.c | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)

Comments

Stephen Boyd July 10, 2020, 11:37 p.m. UTC | #1
Quoting Chunfeng Yun (2020-07-09 20:30:56)
> diff --git a/drivers/usb/gadget/udc/bdc/bdc_core.c b/drivers/usb/gadget/udc/bdc/bdc_core.c
> index 02a3a77..fa173de 100644
> --- a/drivers/usb/gadget/udc/bdc/bdc_core.c
> +++ b/drivers/usb/gadget/udc/bdc/bdc_core.c
> @@ -32,21 +33,14 @@
>  static int poll_oip(struct bdc *bdc, int usec)

Can we change usec to unsigned? Not sure why negative time is important.

>  {
>         u32 status;
> -       /* Poll till STS!= OIP */
> -       while (usec) {
> -               status = bdc_readl(bdc->regs, BDC_BDCSC);
> -               if (BDC_CSTS(status) != BDC_OIP) {
> -                       dev_dbg(bdc->dev,
> -                               "poll_oip complete status=%d",
> -                               BDC_CSTS(status));

This debug message was lost in the conversion. Any reason?

> -                       return 0;
> -               }
> -               udelay(10);
> -               usec -= 10;
> -       }
> -       dev_err(bdc->dev, "Err: operation timedout BDCSC: 0x%08x\n", status);
> +       int ret;
>  
> -       return -ETIMEDOUT;
> +       ret = readl_poll_timeout(bdc->regs + BDC_BDCSC, status,
> +               (BDC_CSTS(status) != BDC_OIP), 10, usec);
> +       if (ret)
> +               dev_err(bdc->dev, "Err: operation timedout BDCSC: 0x%08x\n", status);

Please drop "Err:" as we have kernel log levels (i.e. dev_err() used
here) for that.

> +
> +       return ret;
>  }
Chunfeng Yun (云春峰) July 13, 2020, 3:06 a.m. UTC | #2
On Fri, 2020-07-10 at 16:37 -0700, Stephen Boyd wrote:
> Quoting Chunfeng Yun (2020-07-09 20:30:56)
> > diff --git a/drivers/usb/gadget/udc/bdc/bdc_core.c b/drivers/usb/gadget/udc/bdc/bdc_core.c
> > index 02a3a77..fa173de 100644
> > --- a/drivers/usb/gadget/udc/bdc/bdc_core.c
> > +++ b/drivers/usb/gadget/udc/bdc/bdc_core.c
> > @@ -32,21 +33,14 @@
> >  static int poll_oip(struct bdc *bdc, int usec)
> 
> Can we change usec to unsigned? Not sure why negative time is important.
Yes, it's sensible to use unsigned.

> 
> >  {
> >         u32 status;
> > -       /* Poll till STS!= OIP */
> > -       while (usec) {
> > -               status = bdc_readl(bdc->regs, BDC_BDCSC);
> > -               if (BDC_CSTS(status) != BDC_OIP) {
> > -                       dev_dbg(bdc->dev,
> > -                               "poll_oip complete status=%d",
> > -                               BDC_CSTS(status));
> 
> This debug message was lost in the conversion. Any reason?
No, will add it back
> 
> > -                       return 0;
> > -               }
> > -               udelay(10);
> > -               usec -= 10;
> > -       }
> > -       dev_err(bdc->dev, "Err: operation timedout BDCSC: 0x%08x\n", status);
> > +       int ret;
> >  
> > -       return -ETIMEDOUT;
> > +       ret = readl_poll_timeout(bdc->regs + BDC_BDCSC, status,
> > +               (BDC_CSTS(status) != BDC_OIP), 10, usec);
> > +       if (ret)
> > +               dev_err(bdc->dev, "Err: operation timedout BDCSC: 0x%08x\n", status);
> 
> Please drop "Err:" as we have kernel log levels (i.e. dev_err() used
> here) for that.
Ok

Thanks

> 
> > +
> > +       return ret;
> >  }
diff mbox series

Patch

diff --git a/drivers/usb/gadget/udc/bdc/bdc_core.c b/drivers/usb/gadget/udc/bdc/bdc_core.c
index 02a3a77..fa173de 100644
--- a/drivers/usb/gadget/udc/bdc/bdc_core.c
+++ b/drivers/usb/gadget/udc/bdc/bdc_core.c
@@ -12,6 +12,7 @@ 
 #include <linux/spinlock.h>
 #include <linux/platform_device.h>
 #include <linux/interrupt.h>
+#include <linux/iopoll.h>
 #include <linux/ioport.h>
 #include <linux/io.h>
 #include <linux/list.h>
@@ -32,21 +33,14 @@ 
 static int poll_oip(struct bdc *bdc, int usec)
 {
 	u32 status;
-	/* Poll till STS!= OIP */
-	while (usec) {
-		status = bdc_readl(bdc->regs, BDC_BDCSC);
-		if (BDC_CSTS(status) != BDC_OIP) {
-			dev_dbg(bdc->dev,
-				"poll_oip complete status=%d",
-				BDC_CSTS(status));
-			return 0;
-		}
-		udelay(10);
-		usec -= 10;
-	}
-	dev_err(bdc->dev, "Err: operation timedout BDCSC: 0x%08x\n", status);
+	int ret;
 
-	return -ETIMEDOUT;
+	ret = readl_poll_timeout(bdc->regs + BDC_BDCSC, status,
+		(BDC_CSTS(status) != BDC_OIP), 10, usec);
+	if (ret)
+		dev_err(bdc->dev, "Err: operation timedout BDCSC: 0x%08x\n", status);
+
+	return ret;
 }
 
 /* Stop the BDC controller */