From patchwork Tue Feb 25 19:40:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Balbi X-Patchwork-Id: 25311 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f71.google.com (mail-pa0-f71.google.com [209.85.220.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 9216320143 for ; Tue, 25 Feb 2014 19:42:28 +0000 (UTC) Received: by mail-pa0-f71.google.com with SMTP id kp14sf23958672pab.6 for ; Tue, 25 Feb 2014 11:42:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=OWvKJ6hZqMDoJsDPqCXxy6kmpPD1QNmzPtgQFhDG3jE=; b=Pf/xXnYmTLs8FXzk5aMcHO3HZr5rMKjnULKI+cdT6Ef0MGR5v61FRjObDnwgblT5hQ MS/eTi1SHuTZbzEFoRZR9GquXNV/qMRVzAjKLn2ZJAOoNhf4TEK6MAEj9pS4Vq3x/OR9 diNBzGUBwmsO/9KwyQ68eMnDP/ixhwtrZ6YeKjUwlNe+SnC+NHLI68wbeeJDAKa8pRdu mG40u4NiN4pMdxedq5ajRqh+XZ2ENZ6ck2o4p03S8m8qLzL+etpL4jaf4qfQd4TTRjqp 6ejgv0nay60iEF2dUbvXyIZI1LColyKc+JD0e9yhQRokL1wgyGeu/GpmTxThdPZ4h4eS k2yw== X-Gm-Message-State: ALoCoQmoeptYrFVia6HPZnM8UthcDD2vUGXZ0jFPIPWxYJ58waV2kUYHJAFpRveaBVRLlYFw/KHv X-Received: by 10.66.227.103 with SMTP id rz7mr1354927pac.37.1393357347826; Tue, 25 Feb 2014 11:42:27 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.42.14 with SMTP id b14ls2557671qga.47.gmail; Tue, 25 Feb 2014 11:42:27 -0800 (PST) X-Received: by 10.221.55.133 with SMTP id vy5mr2380479vcb.17.1393357347685; Tue, 25 Feb 2014 11:42:27 -0800 (PST) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by mx.google.com with ESMTPS id wz4si7081197vdc.7.2014.02.25.11.42.27 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Feb 2014 11:42:27 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.178 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.178; Received: by mail-vc0-f178.google.com with SMTP id ik5so7819499vcb.37 for ; Tue, 25 Feb 2014 11:42:27 -0800 (PST) X-Received: by 10.58.190.99 with SMTP id gp3mr1309158vec.32.1393357347569; Tue, 25 Feb 2014 11:42:27 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.174.196 with SMTP id u4csp163123vcz; Tue, 25 Feb 2014 11:42:27 -0800 (PST) X-Received: by 10.68.204.231 with SMTP id lb7mr1767986pbc.30.1393357346711; Tue, 25 Feb 2014 11:42:26 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gp2si21476007pac.70.2014.02.25.11.42.26; Tue, 25 Feb 2014 11:42:26 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753493AbaBYTmT (ORCPT + 3 others); Tue, 25 Feb 2014 14:42:19 -0500 Received: from bear.ext.ti.com ([192.94.94.41]:53840 "EHLO bear.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753410AbaBYTmO (ORCPT ); Tue, 25 Feb 2014 14:42:14 -0500 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id s1PJgClY028780; Tue, 25 Feb 2014 13:42:12 -0600 Received: from DLEE70.ent.ti.com (dlee70.ent.ti.com [157.170.170.113]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id s1PJgCrD005453; Tue, 25 Feb 2014 13:42:12 -0600 Received: from dlep32.itg.ti.com (157.170.170.100) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.3.174.1; Tue, 25 Feb 2014 13:42:11 -0600 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id s1PJgBdC029251; Tue, 25 Feb 2014 13:42:11 -0600 From: Felipe Balbi To: Linux USB Mailing List CC: Paul Zimmerman , Paul Zimmerman , Felipe Balbi Subject: [PATCH 04/11] usb: dwc3: gadget: implement dwc3_gadget_get_link_state Date: Tue, 25 Feb 2014 13:40:36 -0600 Message-ID: <1393357243-2958-5-git-send-email-balbi@ti.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1393357243-2958-1-git-send-email-balbi@ti.com> References: <1393357243-2958-1-git-send-email-balbi@ti.com> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: balbi@ti.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.178 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Paul Zimmerman This function will be used during hibernation to get the current link state. It will be needed at least for Hibernation support. Signed-off-by: Paul Zimmerman Signed-off-by: Felipe Balbi --- drivers/usb/dwc3/gadget.c | 36 ++++++++++++++++++++++++++++++++++++ drivers/usb/dwc3/gadget.h | 1 + 2 files changed, 37 insertions(+) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 31b13c2..ff10161 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -68,6 +68,42 @@ int dwc3_gadget_set_test_mode(struct dwc3 *dwc, int mode) } /** + * dwc3_gadget_get_lik_state - Gets current state of USB Link + * @dwc: pointer to our context structure + * + * Caller should take care of locking. This function will + * return the link state on success (>= 0) or -ETIMEDOUT. + */ +int dwc3_gadget_get_link_state(struct dwc3 *dwc) +{ + u32 reg; + + reg = dwc3_readl(dwc->regs, DWC3_DSTS); + + /* + * Wait until device controller is ready. + * (This only applied to 1.94a and later + * RTL releases) + */ + if (dwc->revision >= DWC3_REVISION_194A) { + int retries = 10000; + + do { + reg = dwc3_readl(dwc->regs, DWC3_DSTS); + if (!(reg & DWC3_DSTS_DCNRD)) + break; + + if (!retries) + return -ETIMEDOUT; + + udelay(5); + } while (--retries); + } + + return DWC3_DSTS_USBLNKST(reg); +} + +/** * dwc3_gadget_set_link_state - Sets USB Link to a particular State * @dwc: pointer to our context structure * @state: the state to put link into diff --git a/drivers/usb/dwc3/gadget.h b/drivers/usb/dwc3/gadget.h index febe1aa..d101244 100644 --- a/drivers/usb/dwc3/gadget.h +++ b/drivers/usb/dwc3/gadget.h @@ -86,6 +86,7 @@ void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req, int status); int dwc3_gadget_set_test_mode(struct dwc3 *dwc, int mode); +int dwc3_gadget_get_link_state(struct dwc3 *dwc); int dwc3_gadget_set_link_state(struct dwc3 *dwc, enum dwc3_link_state state); void dwc3_ep0_interrupt(struct dwc3 *dwc,