From patchwork Wed Jun 17 19:33:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 485640 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 358B51401E7 for ; Thu, 18 Jun 2015 05:36:17 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 89C154B6AD; Wed, 17 Jun 2015 21:35:32 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tWt4V1RBpKd8; Wed, 17 Jun 2015 21:35:32 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B834F4B6BD; Wed, 17 Jun 2015 21:35:06 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5CD264B61F for ; Wed, 17 Jun 2015 21:34:51 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uN4oaxO_vUWp for ; Wed, 17 Jun 2015 21:34:51 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by theia.denx.de (Postfix) with ESMTPS id 78EF24B66A for ; Wed, 17 Jun 2015 21:34:34 +0200 (CEST) Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id F2DB8379E32; Wed, 17 Jun 2015 19:34:32 +0000 (UTC) Received: from shalem.localdomain.com (vpn1-4-77.ams2.redhat.com [10.36.4.77]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t5HJY6T1028265; Wed, 17 Jun 2015 15:34:31 -0400 From: Hans de Goede To: Simon Glass , Marek Vasut Date: Wed, 17 Jun 2015 21:33:54 +0200 Message-Id: <1434569645-30322-12-git-send-email-hdegoede@redhat.com> In-Reply-To: <1434569645-30322-1-git-send-email-hdegoede@redhat.com> References: <1434569645-30322-1-git-send-email-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 Cc: Ian Campbell , u-boot@lists.denx.de Subject: [U-Boot] [PATCH 11/22] musb: Allow musb_platform_enable to return an error code X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Allow musb_platform_enable to return an error code and propagate it up to usb_lowlevel_init(). This allows moving the checks for an external vbus being present to be moved from platform_init to platform_enable, so that the user can unplug a charger, plug in a host adapter with a usb-device, do a "usb reset" and have things working. This also allows adding a check for the id-pin to platform_enable, so that it can short circuit the 1s delay in usb_lowlevel_init() when no host cable is plugged in and thus waiting for a device to show up is useless. Note that all the changes to code shared with the kernel are wrapped in the kernel. Signed-off-by: Hans de Goede Acked-by: Simon Glass --- drivers/usb/musb-new/am35x.c | 7 +++++++ drivers/usb/musb-new/musb_core.c | 20 ++++++++++++++++++++ drivers/usb/musb-new/musb_core.h | 18 ++++++++++++++++++ drivers/usb/musb-new/musb_dsps.c | 6 ++++++ drivers/usb/musb-new/musb_uboot.c | 6 +++++- drivers/usb/musb-new/omap2430.c | 5 +++++ drivers/usb/musb-new/sunxi.c | 5 +++-- 7 files changed, 64 insertions(+), 3 deletions(-) diff --git a/drivers/usb/musb-new/am35x.c b/drivers/usb/musb-new/am35x.c index 857d7eb..d158454 100644 --- a/drivers/usb/musb-new/am35x.c +++ b/drivers/usb/musb-new/am35x.c @@ -100,7 +100,11 @@ struct am35x_glue { /* * am35x_musb_enable - enable interrupts */ +#ifndef __UBOOT__ static void am35x_musb_enable(struct musb *musb) +#else +static int am35x_musb_enable(struct musb *musb) +#endif { void __iomem *reg_base = musb->ctrl_base; u32 epmask; @@ -116,6 +120,9 @@ static void am35x_musb_enable(struct musb *musb) if (is_otg_enabled(musb)) musb_writel(reg_base, CORE_INTR_SRC_SET_REG, AM35X_INTR_DRVVBUS << AM35X_INTR_USB_SHIFT); +#ifdef __UBOOT__ + return 0; +#endif } /* diff --git a/drivers/usb/musb-new/musb_core.c b/drivers/usb/musb-new/musb_core.c index 242cc30..f530af4 100644 --- a/drivers/usb/musb-new/musb_core.c +++ b/drivers/usb/musb-new/musb_core.c @@ -926,10 +926,17 @@ b_host: /* * Program the HDRC to start (enable interrupts, dma, etc.). */ +#ifndef __UBOOT__ void musb_start(struct musb *musb) +#else +int musb_start(struct musb *musb) +#endif { void __iomem *regs = musb->mregs; u8 devctl = musb_readb(regs, MUSB_DEVCTL); +#ifdef __UBOOT__ + int ret; +#endif dev_dbg(musb->controller, "<== devctl %02x\n", devctl); @@ -972,8 +979,21 @@ void musb_start(struct musb *musb) if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) musb->is_active = 1; } + +#ifndef __UBOOT__ musb_platform_enable(musb); +#else + ret = musb_platform_enable(musb); + if (ret) { + musb->is_active = 0; + return ret; + } +#endif musb_writeb(regs, MUSB_DEVCTL, devctl); + +#ifdef __UBOOT__ + return 0; +#endif } diff --git a/drivers/usb/musb-new/musb_core.h b/drivers/usb/musb-new/musb_core.h index 2695742..8727f64 100644 --- a/drivers/usb/musb-new/musb_core.h +++ b/drivers/usb/musb-new/musb_core.h @@ -231,7 +231,11 @@ struct musb_platform_ops { int (*init)(struct musb *musb); int (*exit)(struct musb *musb); +#ifndef __UBOOT__ void (*enable)(struct musb *musb); +#else + int (*enable)(struct musb *musb); +#endif void (*disable)(struct musb *musb); int (*set_mode)(struct musb *musb, u8 mode); @@ -546,7 +550,11 @@ static inline void musb_configure_ep0(struct musb *musb) extern const char musb_driver_name[]; +#ifndef __UBOOT__ extern void musb_start(struct musb *musb); +#else +extern int musb_start(struct musb *musb); +#endif extern void musb_stop(struct musb *musb); extern void musb_write_fifo(struct musb_hw_ep *ep, u16 len, const u8 *src); @@ -564,11 +572,21 @@ static inline void musb_platform_set_vbus(struct musb *musb, int is_on) musb->ops->set_vbus(musb, is_on); } +#ifndef __UBOOT__ static inline void musb_platform_enable(struct musb *musb) { if (musb->ops->enable) musb->ops->enable(musb); } +#else +static inline int musb_platform_enable(struct musb *musb) +{ + if (!musb->ops->enable) + return 0; + + return musb->ops->enable(musb); +} +#endif static inline void musb_platform_disable(struct musb *musb) { diff --git a/drivers/usb/musb-new/musb_dsps.c b/drivers/usb/musb-new/musb_dsps.c index 17ed224..8959397 100644 --- a/drivers/usb/musb-new/musb_dsps.c +++ b/drivers/usb/musb-new/musb_dsps.c @@ -156,7 +156,11 @@ struct dsps_glue { /** * dsps_musb_enable - enable interrupts */ +#ifndef __UBOOT__ static void dsps_musb_enable(struct musb *musb) +#else +static int dsps_musb_enable(struct musb *musb) +#endif { #ifndef __UBOOT__ struct device *dev = musb->controller; @@ -181,6 +185,8 @@ static void dsps_musb_enable(struct musb *musb) if (is_otg_enabled(musb)) dsps_writel(reg_base, wrp->coreintr_set, (1 << wrp->drvvbus) << wrp->usb_shift); +#else + return 0; #endif } diff --git a/drivers/usb/musb-new/musb_uboot.c b/drivers/usb/musb-new/musb_uboot.c index 1bf676c..70e87c9 100644 --- a/drivers/usb/musb-new/musb_uboot.c +++ b/drivers/usb/musb-new/musb_uboot.c @@ -217,13 +217,17 @@ int usb_lowlevel_init(int index, enum usb_init_type init, void **controller) void *mbase; /* USB spec says it may take up to 1 second for a device to connect */ unsigned long timeout = get_timer(0) + 1000; + int ret; if (!host) { printf("MUSB host is not registered\n"); return -ENODEV; } - musb_start(host); + ret = musb_start(host); + if (ret) + return ret; + mbase = host->mregs; do { if (musb_readb(mbase, MUSB_DEVCTL) & MUSB_DEVCTL_HM) diff --git a/drivers/usb/musb-new/omap2430.c b/drivers/usb/musb-new/omap2430.c index 31a280e..77273a4 100644 --- a/drivers/usb/musb-new/omap2430.c +++ b/drivers/usb/musb-new/omap2430.c @@ -400,7 +400,11 @@ err1: return status; } +#ifndef __UBOOT__ static void omap2430_musb_enable(struct musb *musb) +#else +static int omap2430_musb_enable(struct musb *musb) +#endif { #ifndef __UBOOT__ u8 devctl; @@ -445,6 +449,7 @@ static void omap2430_musb_enable(struct musb *musb) __PRETTY_FUNCTION__); } #endif + return 0; #endif } diff --git a/drivers/usb/musb-new/sunxi.c b/drivers/usb/musb-new/sunxi.c index 052e065..c123d61 100644 --- a/drivers/usb/musb-new/sunxi.c +++ b/drivers/usb/musb-new/sunxi.c @@ -199,12 +199,12 @@ static irqreturn_t sunxi_musb_interrupt(int irq, void *__hci) /* musb_core does not call enable / disable in a balanced manner */ static bool enabled = false; -static void sunxi_musb_enable(struct musb *musb) +static int sunxi_musb_enable(struct musb *musb) { pr_debug("%s():\n", __func__); if (enabled) - return; + return 0; /* select PIO mode */ musb_writeb(musb->mregs, USBC_REG_o_VEND0, 0); @@ -215,6 +215,7 @@ static void sunxi_musb_enable(struct musb *musb) USBC_ForceVbusValidToHigh(musb->mregs); enabled = true; + return 0; } static void sunxi_musb_disable(struct musb *musb)