From patchwork Fri Mar 8 02:27:06 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabio Baltieri X-Patchwork-Id: 15271 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id E1A8123E2E for ; Fri, 8 Mar 2013 02:27:29 +0000 (UTC) Received: from mail-ve0-f175.google.com (mail-ve0-f175.google.com [209.85.128.175]) by fiordland.canonical.com (Postfix) with ESMTP id 850D8A1917B for ; Fri, 8 Mar 2013 02:27:29 +0000 (UTC) Received: by mail-ve0-f175.google.com with SMTP id cy12so907392veb.20 for ; Thu, 07 Mar 2013 18:27:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state; bh=s4a/6gPvm0k9qzOAlB0ap/S5GFPQjXHV1XefuvQ/Coo=; b=eU5ZaBtp8XIvzP6uq+qGxL16xqm+SkUxJPXzBa4crS//fRJlv2Rhi5NBIVF6DcJYT1 2xLIT1aLE48IPiRw8s4l4TFdjqC7x/OhWDL/V5KvGUr8WYfVTEMeT3me/UeaehLzw5b1 EpU3pcIMwy1RcH7/F2xcj3wBWkm5mNGL19domz12rc6rp+jF/0IA3rsdV6/7f2+ZglnI RF2EUXEr3vK8yPQ8Y+1y+XacANNQ1N02syAmsyG+ON9iCJdvUeH5s/HbpKaCHwdgw2wH 76NR2Q7x/xSYBjR0r3h6siFHcYN1Roi/dLIffT6MDEJkMbVvu24W0/xTGNTH0dXtxLRz YmFw== X-Received: by 10.220.242.73 with SMTP id lh9mr226783vcb.49.1362709649040; Thu, 07 Mar 2013 18:27:29 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.58.127.98 with SMTP id nf2csp98702veb; Thu, 7 Mar 2013 18:27:28 -0800 (PST) X-Received: by 10.66.182.193 with SMTP id eg1mr1690908pac.5.1362709648022; Thu, 07 Mar 2013 18:27:28 -0800 (PST) Received: from mail-pa0-f43.google.com (mail-pa0-f43.google.com [209.85.220.43]) by mx.google.com with ESMTPS id ai10si3831798pbd.220.2013.03.07.18.27.27 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 07 Mar 2013 18:27:28 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.43 is neither permitted nor denied by best guess record for domain of fabio.baltieri@linaro.org) client-ip=209.85.220.43; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.43 is neither permitted nor denied by best guess record for domain of fabio.baltieri@linaro.org) smtp.mail=fabio.baltieri@linaro.org Received: by mail-pa0-f43.google.com with SMTP id bh2so934178pad.30 for ; Thu, 07 Mar 2013 18:27:27 -0800 (PST) X-Received: by 10.68.24.33 with SMTP id r1mr757372pbf.139.1362709647655; Thu, 07 Mar 2013 18:27:27 -0800 (PST) Received: from localhost ([118.143.64.134]) by mx.google.com with ESMTPS id rr14sm3683485pbb.34.2013.03.07.18.27.24 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 07 Mar 2013 18:27:26 -0800 (PST) From: Fabio Baltieri To: Felipe Balbi Cc: Linus Walleij , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, Fabio Baltieri Subject: [PATCH v2 2/5] usb: musb: ux500: implement musb_set_vbus Date: Fri, 8 Mar 2013 10:27:06 +0800 Message-Id: <1362709629-27238-3-git-send-email-fabio.baltieri@linaro.org> X-Mailer: git-send-email 1.8.1.3 In-Reply-To: <1362709629-27238-1-git-send-email-fabio.baltieri@linaro.org> References: <1362709629-27238-1-git-send-email-fabio.baltieri@linaro.org> X-Gm-Message-State: ALoCoQmoT8D62OK/yOhCHJLFVKBDqZRJYiyLbPSi0WQffTYNQEOte/+4cYtn7XhMl1xLLPLQzYjQ Add ux500_musb_set_vbus() implementation for ux500. This is based on the version originally developed inside ST-Ericsson. Acked-by: Linus Walleij Signed-off-by: Fabio Baltieri --- drivers/usb/musb/ux500.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/drivers/usb/musb/ux500.c b/drivers/usb/musb/ux500.c index 13a3929..5b742ba 100644 --- a/drivers/usb/musb/ux500.c +++ b/drivers/usb/musb/ux500.c @@ -36,6 +36,68 @@ struct ux500_glue { }; #define glue_to_musb(g) platform_get_drvdata(g->musb) +static void ux500_musb_set_vbus(struct musb *musb, int is_on) +{ + u8 devctl; + unsigned long timeout = jiffies + msecs_to_jiffies(1000); + /* HDRC controls CPEN, but beware current surges during device + * connect. They can trigger transient overcurrent conditions + * that must be ignored. + */ + + devctl = musb_readb(musb->mregs, MUSB_DEVCTL); + + if (is_on) { + if (musb->xceiv->state == OTG_STATE_A_IDLE) { + /* start the session */ + devctl |= MUSB_DEVCTL_SESSION; + musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); + /* + * Wait for the musb to set as A device to enable the + * VBUS + */ + while (musb_readb(musb->mregs, MUSB_DEVCTL) & 0x80) { + + if (time_after(jiffies, timeout)) { + dev_err(musb->controller, + "configured as A device timeout"); + break; + } + } + + } else { + musb->is_active = 1; + musb->xceiv->otg->default_a = 1; + musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; + devctl |= MUSB_DEVCTL_SESSION; + MUSB_HST_MODE(musb); + } + } else { + musb->is_active = 0; + + /* NOTE: we're skipping A_WAIT_VFALL -> A_IDLE and jumping + * right to B_IDLE... + */ + musb->xceiv->otg->default_a = 0; + devctl &= ~MUSB_DEVCTL_SESSION; + MUSB_DEV_MODE(musb); + } + musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); + + /* + * Devctl values will be updated after vbus goes below + * session_valid. The time taken depends on the capacitance + * on VBUS line. The max discharge time can be upto 1 sec + * as per the spec. Typically on our platform, it is 200ms + */ + if (!is_on) + mdelay(200); + + dev_dbg(musb->controller, "VBUS %s, devctl %02x\n", + otg_state_string(musb->xceiv->state), + musb_readb(musb->mregs, MUSB_DEVCTL)); +} + static irqreturn_t ux500_musb_interrupt(int irq, void *__hci) { unsigned long flags; @@ -79,6 +141,8 @@ static int ux500_musb_exit(struct musb *musb) static const struct musb_platform_ops ux500_ops = { .init = ux500_musb_init, .exit = ux500_musb_exit, + + .set_vbus = ux500_musb_set_vbus, }; static int ux500_probe(struct platform_device *pdev)