diff mbox series

[U-Boot] usb: r8a66597: convert wait loop to readw_poll_timeout

Message ID 20171129193706.10753-1-chris.brandt@renesas.com
State Superseded
Delegated to: Marek Vasut
Headers show
Series [U-Boot] usb: r8a66597: convert wait loop to readw_poll_timeout | expand

Commit Message

Chris Brandt Nov. 29, 2017, 7:37 p.m. UTC
It is better to use an existing wait loop implementation.

Signed-off-by: Chris Brandt <chris.brandt@renesas.com>
---
 drivers/usb/host/r8a66597-hcd.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

Comments

Fabio Estevam Nov. 29, 2017, 7:41 p.m. UTC | #1
On Wed, Nov 29, 2017 at 5:37 PM, Chris Brandt <chris.brandt@renesas.com> wrote:
> @@ -308,13 +308,10 @@ static int send_setup_packet(struct r8a66597 *r8a66597, struct usb_device *dev,
>  #if defined(CONFIG_RZA_USB)
>         dcpctr = r8a66597_read(r8a66597, DCPCTR);
>         if ((dcpctr & PID) == PID_BUF) {
> -               timeout2 = 10000;
> -               while (!(dcpctr & BSTS)) {
> -                       dcpctr = r8a66597_read(r8a66597, DCPCTR);
> -                       if (timeout2-- < 0) {
> -                               printf("DCPCTR clear timeout!\n");
> -                               break;
> -                       }
> +               if (readw_poll_timeout(r8a66597->reg + DCPCTR, dcpctr,
> +                                      dcpctr & BSTS, 1000) < 0) {
> +                       printf("DCPCTR BSTS timeout!\n");
> +                       return -1;

What about returning -ETIMEDOUT instead?
Chris Brandt Nov. 29, 2017, 7:48 p.m. UTC | #2
On Wednesday, November 29, 2017, Fabio Estevam wrote:
> > +               if (readw_poll_timeout(r8a66597->reg + DCPCTR, dcpctr,

> > +                                      dcpctr & BSTS, 1000) < 0) {

> > +                       printf("DCPCTR BSTS timeout!\n");

> > +                       return -1;

> 

> What about returning -ETIMEDOUT instead?



OK, that sounds reasonable.


Chris
diff mbox series

Patch

diff --git a/drivers/usb/host/r8a66597-hcd.c b/drivers/usb/host/r8a66597-hcd.c
index 28d2bc8454..7ae26b33fd 100644
--- a/drivers/usb/host/r8a66597-hcd.c
+++ b/drivers/usb/host/r8a66597-hcd.c
@@ -10,6 +10,7 @@ 
 #include <console.h>
 #include <usb.h>
 #include <asm/io.h>
+#include <linux/iopoll.h>
 
 #include "r8a66597.h"
 
@@ -297,7 +298,6 @@  static int send_setup_packet(struct r8a66597 *r8a66597, struct usb_device *dev,
 	int timeout = 3000;
 #if defined(CONFIG_RZA_USB)
 	u16 dcpctr;
-	int timeout2 = 10000;
 #endif
 	u16 devsel = setup->request == USB_REQ_SET_ADDRESS ? 0 : dev->devnum;
 
@@ -308,13 +308,10 @@  static int send_setup_packet(struct r8a66597 *r8a66597, struct usb_device *dev,
 #if defined(CONFIG_RZA_USB)
 	dcpctr = r8a66597_read(r8a66597, DCPCTR);
 	if ((dcpctr & PID) == PID_BUF) {
-		timeout2 = 10000;
-		while (!(dcpctr & BSTS)) {
-			dcpctr = r8a66597_read(r8a66597, DCPCTR);
-			if (timeout2-- < 0) {
-				printf("DCPCTR clear timeout!\n");
-				break;
-			}
+		if (readw_poll_timeout(r8a66597->reg + DCPCTR, dcpctr,
+				       dcpctr & BSTS, 1000) < 0) {
+			printf("DCPCTR BSTS timeout!\n");
+			return -1;
 		}
 	}
 #endif