Message ID | 1597840865-26631-10-git-send-email-chunfeng.yun@mediatek.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [01/10] usb: early: convert to readl_poll_timeout_atomic() | expand |
On Wed, Aug 19, 2020 at 08:41:05PM +0800, Chunfeng Yun wrote: > Use readl_poll_timeout_atomic() to simplify code > > Cc: Alan Stern <stern@rowland.harvard.edu> > Cc: Felipe Balbi <balbi@kernel.org> > Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com> > --- > drivers/usb/gadget/udc/net2280.c | 21 ++++++++++----------- > 1 file changed, 10 insertions(+), 11 deletions(-) > > diff --git a/drivers/usb/gadget/udc/net2280.c b/drivers/usb/gadget/udc/net2280.c > index 7530bd9..f1a21f4 100644 > --- a/drivers/usb/gadget/udc/net2280.c > +++ b/drivers/usb/gadget/udc/net2280.c > @@ -52,6 +52,7 @@ > #include <linux/usb/gadget.h> > #include <linux/prefetch.h> > #include <linux/io.h> > +#include <linux/iopoll.h> > > #include <asm/byteorder.h> > #include <asm/irq.h> > @@ -360,18 +361,16 @@ static inline void enable_pciirqenb(struct net2280_ep *ep) > static int handshake(u32 __iomem *ptr, u32 mask, u32 done, int usec) > { > u32 result; > + int ret; > > - do { > - result = readl(ptr); > - if (result == ~(u32)0) /* "device unplugged" */ > - return -ENODEV; > - result &= mask; > - if (result == done) > - return 0; > - udelay(1); > - usec--; > - } while (usec > 0); > - return -ETIMEDOUT; > + ret = readl_poll_timeout_atomic(ptr, result, > + ((result & mask) == done || > + result == U32_MAX), > + 1, usec); > + if (result == U32_MAX) /* device unplugged */ > + return -ENODEV; > + > + return ret; > } > > static const struct usb_ep_ops net2280_ep_ops; > -- Acked-by: Alan Stern <stern@rowland.harvard.edu> However, I noticed that the kerneldoc for readl_poll_timeout_atomic() is out of date. Can you fix it up? Alan Stern
On Wed, 2020-08-19 at 10:59 -0400, Alan Stern wrote: > On Wed, Aug 19, 2020 at 08:41:05PM +0800, Chunfeng Yun wrote: > > Use readl_poll_timeout_atomic() to simplify code > > > > Cc: Alan Stern <stern@rowland.harvard.edu> > > Cc: Felipe Balbi <balbi@kernel.org> > > Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com> > > --- > > drivers/usb/gadget/udc/net2280.c | 21 ++++++++++----------- > > 1 file changed, 10 insertions(+), 11 deletions(-) > > > > diff --git a/drivers/usb/gadget/udc/net2280.c b/drivers/usb/gadget/udc/net2280.c > > index 7530bd9..f1a21f4 100644 > > --- a/drivers/usb/gadget/udc/net2280.c > > +++ b/drivers/usb/gadget/udc/net2280.c > > @@ -52,6 +52,7 @@ > > #include <linux/usb/gadget.h> > > #include <linux/prefetch.h> > > #include <linux/io.h> > > +#include <linux/iopoll.h> > > > > #include <asm/byteorder.h> > > #include <asm/irq.h> > > @@ -360,18 +361,16 @@ static inline void enable_pciirqenb(struct net2280_ep *ep) > > static int handshake(u32 __iomem *ptr, u32 mask, u32 done, int usec) > > { > > u32 result; > > + int ret; > > > > - do { > > - result = readl(ptr); > > - if (result == ~(u32)0) /* "device unplugged" */ > > - return -ENODEV; > > - result &= mask; > > - if (result == done) > > - return 0; > > - udelay(1); > > - usec--; > > - } while (usec > 0); > > - return -ETIMEDOUT; > > + ret = readl_poll_timeout_atomic(ptr, result, > > + ((result & mask) == done || > > + result == U32_MAX), > > + 1, usec); > > + if (result == U32_MAX) /* device unplugged */ > > + return -ENODEV; > > + > > + return ret; > > } > > > > static const struct usb_ep_ops net2280_ep_ops; > > -- > > Acked-by: Alan Stern <stern@rowland.harvard.edu> > > However, I noticed that the kerneldoc for readl_poll_timeout_atomic() is > out of date. Can you fix it up? Ok, will do it, thanks > > Alan Stern
diff --git a/drivers/usb/gadget/udc/net2280.c b/drivers/usb/gadget/udc/net2280.c index 7530bd9..f1a21f4 100644 --- a/drivers/usb/gadget/udc/net2280.c +++ b/drivers/usb/gadget/udc/net2280.c @@ -52,6 +52,7 @@ #include <linux/usb/gadget.h> #include <linux/prefetch.h> #include <linux/io.h> +#include <linux/iopoll.h> #include <asm/byteorder.h> #include <asm/irq.h> @@ -360,18 +361,16 @@ static inline void enable_pciirqenb(struct net2280_ep *ep) static int handshake(u32 __iomem *ptr, u32 mask, u32 done, int usec) { u32 result; + int ret; - do { - result = readl(ptr); - if (result == ~(u32)0) /* "device unplugged" */ - return -ENODEV; - result &= mask; - if (result == done) - return 0; - udelay(1); - usec--; - } while (usec > 0); - return -ETIMEDOUT; + ret = readl_poll_timeout_atomic(ptr, result, + ((result & mask) == done || + result == U32_MAX), + 1, usec); + if (result == U32_MAX) /* device unplugged */ + return -ENODEV; + + return ret; } static const struct usb_ep_ops net2280_ep_ops;
Use readl_poll_timeout_atomic() to simplify code Cc: Alan Stern <stern@rowland.harvard.edu> Cc: Felipe Balbi <balbi@kernel.org> Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com> --- drivers/usb/gadget/udc/net2280.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)