* [v2 PATCH] usb: gadget: bdc: use readl_poll_timeout() to simplify code
@ 2020-07-13 3:30 Chunfeng Yun
2020-07-13 3:53 ` Florian Fainelli
0 siblings, 1 reply; 3+ messages in thread
From: Chunfeng Yun @ 2020-07-13 3:30 UTC (permalink / raw)
To: Felipe Balbi, Florian Fainelli
Cc: Greg Kroah-Hartman, Matthias Brugger, YueHaibing, Stephen Boyd,
Chunfeng Yun, linux-usb, linux-kernel, linux-arm-kernel,
linux-mediatek
Use readl_poll_timeout() to poll register status
Cc: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
---
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(-)
diff --git a/drivers/usb/gadget/udc/bdc/bdc_core.c b/drivers/usb/gadget/udc/bdc/bdc_core.c
index 02a3a77..53dccb1 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 */
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [v2 PATCH] usb: gadget: bdc: use readl_poll_timeout() to simplify code
2020-07-13 3:30 [v2 PATCH] usb: gadget: bdc: use readl_poll_timeout() to simplify code Chunfeng Yun
@ 2020-07-13 3:53 ` Florian Fainelli
2020-07-13 6:55 ` Chunfeng Yun
0 siblings, 1 reply; 3+ messages in thread
From: Florian Fainelli @ 2020-07-13 3:53 UTC (permalink / raw)
To: Chunfeng Yun, Felipe Balbi
Cc: Greg Kroah-Hartman, Matthias Brugger, YueHaibing, Stephen Boyd,
linux-usb, linux-kernel, linux-arm-kernel, linux-mediatek
On 7/12/2020 8:30 PM, Chunfeng Yun wrote:
> Use readl_poll_timeout() to poll register status
>
> Cc: Florian Fainelli <f.fainelli@gmail.com>
> Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
> ---
> 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(-)
>
> diff --git a/drivers/usb/gadget/udc/bdc/bdc_core.c b/drivers/usb/gadget/udc/bdc/bdc_core.c
> index 02a3a77..53dccb1 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);
You could probably indent this to the opening parenthesis, but with or
without it:
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
and thanks for picking up the MAINTAINERS file update ;)
> + 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 */
>
--
Florian
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [v2 PATCH] usb: gadget: bdc: use readl_poll_timeout() to simplify code
2020-07-13 3:53 ` Florian Fainelli
@ 2020-07-13 6:55 ` Chunfeng Yun
0 siblings, 0 replies; 3+ messages in thread
From: Chunfeng Yun @ 2020-07-13 6:55 UTC (permalink / raw)
To: Florian Fainelli
Cc: Felipe Balbi, Greg Kroah-Hartman, Matthias Brugger, YueHaibing,
Stephen Boyd, linux-usb, linux-kernel, linux-arm-kernel,
linux-mediatek
On Sun, 2020-07-12 at 20:53 -0700, Florian Fainelli wrote:
>
> On 7/12/2020 8:30 PM, Chunfeng Yun wrote:
> > Use readl_poll_timeout() to poll register status
> >
> > Cc: Florian Fainelli <f.fainelli@gmail.com>
> > Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
> > ---
> > 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(-)
> >
> > diff --git a/drivers/usb/gadget/udc/bdc/bdc_core.c b/drivers/usb/gadget/udc/bdc/bdc_core.c
> > index 02a3a77..53dccb1 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);
>
> You could probably indent this to the opening parenthesis,
Done, v3 is sent out, thanks
> but with or
> without it:
>
> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
>
> and thanks for picking up the MAINTAINERS file update ;)
>
> > + 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 */
> >
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-07-13 6:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-13 3:30 [v2 PATCH] usb: gadget: bdc: use readl_poll_timeout() to simplify code Chunfeng Yun
2020-07-13 3:53 ` Florian Fainelli
2020-07-13 6:55 ` Chunfeng Yun
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).