diff mbox series

[v3] usb: gadget: bdc: use readl_poll_timeout() to simplify code

Message ID 1594622881-6563-1-git-send-email-chunfeng.yun@mediatek.com (mailing list archive)
State Mainlined
Commit 75ae051efc9b3cceaed525e7ecb9cf19780e0af5
Headers show
Series [v3] usb: gadget: bdc: use readl_poll_timeout() to simplify code | expand

Commit Message

Chunfeng Yun (云春峰) July 13, 2020, 6:48 a.m. UTC
Use readl_poll_timeout() to poll register status

Cc: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
---
v3 changes:
  1. indent code to match open parenthesis suggested by Florian
  2. add Reviewed-by Florian

v2 changes, suggested by Stephen:
  1. use unsigned int instead of int for @usec parameter
  2. add dev_log() back
  3. drop "Err" in error log
---
 drivers/usb/gadget/udc/bdc/bdc_core.c | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)

Comments

Stephen Boyd July 16, 2020, 1:06 a.m. UTC | #1
Quoting Chunfeng Yun (2020-07-12 23:48:01)
> diff --git a/drivers/usb/gadget/udc/bdc/bdc_core.c b/drivers/usb/gadget/udc/bdc/bdc_core.c
> index 02a3a77..d567e20 100644
> --- a/drivers/usb/gadget/udc/bdc/bdc_core.c
> +++ b/drivers/usb/gadget/udc/bdc/bdc_core.c
> @@ -29,24 +30,19 @@
>  #include "bdc_dbg.h"
>  
>  /* Poll till controller status is not OIP */
> -static int poll_oip(struct bdc *bdc, int usec)
> +static int poll_oip(struct bdc *bdc, u32 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, "operation timedout BDCSC: 0x%08x\n", status);
> +       else
> +               dev_dbg(bdc->dev, "%s complete status=%d", __func__, BDC_CSTS(status));

Different than before but OK.

Reviewed-by: Stephen Boyd <swboyd@chromium.org>
Felipe Balbi July 21, 2020, 9:42 a.m. UTC | #2
Hi,

Chunfeng Yun <chunfeng.yun@mediatek.com> writes:
> Use readl_poll_timeout() to poll register status
>
> Cc: Florian Fainelli <f.fainelli@gmail.com>
> Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>

I had a lot of trouble to apply this patch, could you avoid base64
encoding on the patch body next time?

Thanks
Chunfeng Yun (云春峰) July 22, 2020, 6:51 a.m. UTC | #3
On Tue, 2020-07-21 at 12:42 +0300, Felipe Balbi wrote:
> Hi,
> 
> Chunfeng Yun <chunfeng.yun@mediatek.com> writes:
> > Use readl_poll_timeout() to poll register status
> >
> > Cc: Florian Fainelli <f.fainelli@gmail.com>
> > Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
> > Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
> 
> I had a lot of trouble to apply this patch, could you avoid base64
> encoding on the patch body next time?
Sorry for inconvenience.


I usually use Source Insight 3.5 or Vim to edit the code, sometimes use
Beyond Compare to compare patches, their default encoding is UTF-8 or
ANSI. Not sure which tool would use base64 encoding, maybe introduced
when I copy email address from Win7 with Chinese (used to receive email)
into Win10 with English (used to sent email/patch). 


Can you tell me which lines are base64 encoding in this patch?


The patch's encoding is ANSI, I'll convert it into UTF-8 and resend it,
please try it again.

> 
> Thanks
>
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..d567e20 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>
@@ -29,24 +30,19 @@ 
 #include "bdc_dbg.h"
 
 /* Poll till controller status is not OIP */
-static int poll_oip(struct bdc *bdc, int usec)
+static int poll_oip(struct bdc *bdc, u32 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, "operation timedout BDCSC: 0x%08x\n", status);
+	else
+		dev_dbg(bdc->dev, "%s complete status=%d", __func__, BDC_CSTS(status));
+
+	return ret;
 }
 
 /* Stop the BDC controller */