When MUSB is operating in peripheral mode, probe registering
musb core using musb_register which intern return int value
for validation. so there is no scope to preserve struct musb
pointer but the same can be used in .remove musb_stop.
So fix this by return musb_register with struct musb pointer.

Signed-off-by: Jagan Teki <ja...@amarulasolutions.com>
---
 board/compulab/cm_t3517/cm_t3517.c |  4 ++--
 drivers/usb/musb-new/musb_uboot.c  | 10 +++++-----
 drivers/usb/musb-new/pic32.c       |  6 ++++--
 drivers/usb/musb-new/sunxi.c       |  8 +++++---
 include/linux/usb/musb.h           |  4 ++--
 5 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/board/compulab/cm_t3517/cm_t3517.c 
b/board/compulab/cm_t3517/cm_t3517.c
index 09cb27def0..668bb7631a 100644
--- a/board/compulab/cm_t3517/cm_t3517.c
+++ b/board/compulab/cm_t3517/cm_t3517.c
@@ -74,8 +74,8 @@ static void cm_t3517_musb_init(void)
                        CONF2_REFFREQ_13MHZ | CONF2_SESENDEN |
                        CONF2_VBDTCTEN | CONF2_DATPOL);
 
-       if (musb_register(&cm_t3517_musb_pdata, &cm_t3517_musb_board_data,
-                         (void *)AM35XX_IPSS_USBOTGSS_BASE))
+       if (!musb_register(&cm_t3517_musb_pdata, &cm_t3517_musb_board_data,
+                          (void *)AM35XX_IPSS_USBOTGSS_BASE))
                printf("Failed initializing AM35x MUSB!\n");
 }
 #else
diff --git a/drivers/usb/musb-new/musb_uboot.c 
b/drivers/usb/musb-new/musb_uboot.c
index 2b04fbd046..3cd89793c9 100644
--- a/drivers/usb/musb-new/musb_uboot.c
+++ b/drivers/usb/musb-new/musb_uboot.c
@@ -419,8 +419,8 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver 
*driver)
 }
 #endif /* CONFIG_USB_MUSB_GADGET */
 
-int musb_register(struct musb_hdrc_platform_data *plat, void *bdata,
-                       void *ctl_regs)
+struct musb *musb_register(struct musb_hdrc_platform_data *plat, void *bdata,
+                          void *ctl_regs)
 {
        struct musb **musbp;
 
@@ -436,14 +436,14 @@ int musb_register(struct musb_hdrc_platform_data *plat, 
void *bdata,
                break;
 #endif
        default:
-               return -EINVAL;
+               return NULL;
        }
 
        *musbp = musb_init_controller(plat, (struct device *)bdata, ctl_regs);
        if (!*musbp) {
                printf("Failed to init the controller\n");
-               return -EIO;
+               return NULL;
        }
 
-       return 0;
+       return *musbp;
 }
diff --git a/drivers/usb/musb-new/pic32.c b/drivers/usb/musb-new/pic32.c
index f04719d7af..3a19900e21 100644
--- a/drivers/usb/musb-new/pic32.c
+++ b/drivers/usb/musb-new/pic32.c
@@ -251,9 +251,11 @@ static int musb_usb_probe(struct udevice *dev)
        ret = musb_lowlevel_init(mdata);
 #else
        pic32_musb_plat.mode = MUSB_PERIPHERAL;
-       ret = musb_register(&pic32_musb_plat, &pdata->dev, mregs);
+       mdata->host = musb_register(&pic32_musb_plat, &pdata->dev, mregs);
+       if (!mdata->host)
+               return -EIO;
 #endif
-       if (ret == 0)
+       if ((ret == 0) && mdata->host)
                printf("PIC32 MUSB OTG\n");
 
        return ret;
diff --git a/drivers/usb/musb-new/sunxi.c b/drivers/usb/musb-new/sunxi.c
index 08de9c69c7..b846afb094 100644
--- a/drivers/usb/musb-new/sunxi.c
+++ b/drivers/usb/musb-new/sunxi.c
@@ -444,9 +444,11 @@ static int musb_usb_probe(struct udevice *dev)
                printf("Allwinner mUSB OTG (Host)\n");
 #else
        pdata.mode = MUSB_PERIPHERAL;
-       ret = musb_register(&pdata, &glue->dev, base);
-       if (!ret)
-               printf("Allwinner mUSB OTG (Peripheral)\n");
+       host->host = musb_register(&pdata, &glue->dev, base);
+       if (!host->host)
+               return -EIO;
+
+       printf("Allwinner mUSB OTG (Peripheral)\n");
 #endif
 
        return ret;
diff --git a/include/linux/usb/musb.h b/include/linux/usb/musb.h
index 9104414cf0..a31ce67a81 100644
--- a/include/linux/usb/musb.h
+++ b/include/linux/usb/musb.h
@@ -150,7 +150,7 @@ extern int tusb6010_platform_retime(unsigned is_refclk);
 /*
  * U-Boot specfic stuff
  */
-int musb_register(struct musb_hdrc_platform_data *plat, void *bdata,
-                       void *ctl_regs);
+struct musb *musb_register(struct musb_hdrc_platform_data *plat, void *bdata,
+                          void *ctl_regs);
 
 #endif /* __LINUX_USB_MUSB_H */
-- 
2.17.1

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot

Reply via email to