From patchwork Fri Jan 22 18:18:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 8091891 Return-Path: X-Original-To: patchwork-linux-rockchip@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7ACE29F859 for ; Fri, 22 Jan 2016 18:20:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 837D7204DE for ; Fri, 22 Jan 2016 18:20:27 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 79679205B3 for ; Fri, 22 Jan 2016 18:20:26 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aMgJu-0005Qb-5a; Fri, 22 Jan 2016 18:20:26 +0000 Received: from mail-pf0-x236.google.com ([2607:f8b0:400e:c00::236]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aMgJd-0003w1-O5 for linux-rockchip@lists.infradead.org; Fri, 22 Jan 2016 18:20:13 +0000 Received: by mail-pf0-x236.google.com with SMTP id q63so47324016pfb.1 for ; Fri, 22 Jan 2016 10:19:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8CEoVH2kwQmDe88onpPWiBDGQYQ3J5w0mOpU0jEp1TU=; b=CbjDNcOfsVfH2XcC9zKlTlaj95xzRbdbOlsVJMvefrJybGwh9WlgIeO+an2qCitfYn cNvSXLRWrm4WvbbNsBYk5iM6kslL64owQtif5zcBg4GSrV4bioD9+MIOGDc2uzUvxPej yDFVOux6ORqPBXBiB+4z/0XXUteY86/nlyeDY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8CEoVH2kwQmDe88onpPWiBDGQYQ3J5w0mOpU0jEp1TU=; b=k6ndL3uSUgk/MKQGaYBxtHTRLfRqto8nb2Dd8BUycUsN1G730lSsjtxBoCctYI77AJ Imxo6oM8Qu4W2Q+dpu11aDX+0fUu8+WUz6okXuqhc7NqbfAgobZySlzKyfyXBhtmXPiT LUemLMGFp6my4Y5xqUUWuYF2eYUo9cgnlcseIL2vgIFFydF6p5lPtNe7MHYo07sElNHC GYOFB0cpl8aDeNNMrGD7idLtfhjA+8yQ48/IyhAlGOOUhNrni8hWvkXIo+XJLmy4TlsS WDxpD2D4BiUcHKD1RWwRpQCKAGKgG534IHw1uwn2AwCB8WmnqFNk+M4sSjy8rL0zmeas y0KQ== X-Gm-Message-State: AG10YOT8KmUcBaBxfB5gKY0MzXHmeopRPCldO4VXvuJTHwjzIUDM7jGunTgcy8SFBQDBhA== X-Received: by 10.98.32.76 with SMTP id g73mr6477729pfg.48.1453486789061; Fri, 22 Jan 2016 10:19:49 -0800 (PST) Received: from tictac.mtv.corp.google.com ([172.22.65.76]) by smtp.gmail.com with ESMTPSA id y86sm11276415pfa.26.2016.01.22.10.19.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 22 Jan 2016 10:19:48 -0800 (PST) From: Douglas Anderson To: John Youn , balbi@ti.com, kever.yang@rock-chips.com Subject: [PATCH v5 18/21] usb: dwc2: host: Add dwc2_hcd_get_future_frame_number() call Date: Fri, 22 Jan 2016 10:18:53 -0800 Message-Id: <1453486736-15358-19-git-send-email-dianders@chromium.org> X-Mailer: git-send-email 2.7.0.rc3.207.g0ac5344 In-Reply-To: <1453486736-15358-1-git-send-email-dianders@chromium.org> References: <1453486736-15358-1-git-send-email-dianders@chromium.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160122_102010_254355_451125F5 X-CRM114-Status: GOOD ( 12.01 ) X-Spam-Score: -2.7 (--) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: huangtao@rock-chips.com, gregory.herrero@intel.com, heiko@sntech.de, johnyoun@synopsys.com, gregkh@linuxfoundation.org, ming.lei@canonical.com, linux-usb@vger.kernel.org, Douglas Anderson , linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, yousaf.kaukab@intel.com, stern@rowland.harvard.edu, william.wu@rock-chips.com, Julius Werner , dinguyen@opensource.altera.com MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP As we start getting more exact about our scheduling it's becoming more and more important to know exactly how far through the current frame we are. This lets us make decisions about whether there's still time left to start a new transaction in the current frame. We'll add dwc2_hcd_get_future_frame_number() which will tell you what the frame number will be a certain number of microseconds (us) from now. We can use this information to help decide if there's enough time left in the frame for a transaction that will take a certain duration. This is expected to be used by a future change ("usb: dwc2: host: Properly set even/odd frame"). Signed-off-by: Douglas Anderson --- Changes in v5: None Changes in v4: - Add dwc2_hcd_get_future_frame_number() call new for v4. Changes in v3: None Changes in v2: None drivers/usb/dwc2/core.h | 4 ++++ drivers/usb/dwc2/hcd.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index 64d45a2053bb..52cbea28d0e9 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h @@ -1235,12 +1235,16 @@ static inline int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg, #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE) extern int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg); +extern int dwc2_hcd_get_future_frame_number(struct dwc2_hsotg *hsotg, int us); extern void dwc2_hcd_connect(struct dwc2_hsotg *hsotg); extern void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force); extern void dwc2_hcd_start(struct dwc2_hsotg *hsotg); #else static inline int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg) { return 0; } +static inline int dwc2_hcd_get_future_frame_number(struct dwc2_hsotg *hsotg, + int us) +{ return 0; } static inline void dwc2_hcd_connect(struct dwc2_hsotg *hsotg) {} static inline void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force) {} static inline void dwc2_hcd_start(struct dwc2_hsotg *hsotg) {} diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index 03072d1fd44d..83dc92da10a0 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c @@ -1947,6 +1947,35 @@ int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg) return (hfnum & HFNUM_FRNUM_MASK) >> HFNUM_FRNUM_SHIFT; } +int dwc2_hcd_get_future_frame_number(struct dwc2_hsotg *hsotg, int us) +{ + u32 hprt = dwc2_readl(hsotg->regs + HPRT0); + u32 hfir = dwc2_readl(hsotg->regs + HFIR); + u32 hfnum = dwc2_readl(hsotg->regs + HFNUM); + unsigned int us_per_frame; + unsigned int frame_number; + unsigned int remaining; + unsigned int interval; + unsigned int phy_clks; + + /* High speed has 125 us per (micro) frame; others are 1 ms per */ + us_per_frame = (hprt & HPRT0_SPD_MASK) ? 1000 : 125; + + /* Extract fields */ + frame_number = (hfnum & HFNUM_FRNUM_MASK) >> HFNUM_FRNUM_SHIFT; + remaining = (hfnum & HFNUM_FRREM_MASK) >> HFNUM_FRREM_SHIFT; + interval = (hfir & HFIR_FRINT_MASK) >> HFIR_FRINT_SHIFT; + + /* + * Number of phy clocks since the last tick of the frame number after + * "us" has passed. + */ + phy_clks = (interval - remaining) + + DIV_ROUND_UP(interval * us, us_per_frame); + + return dwc2_frame_num_inc(frame_number, phy_clks / interval); +} + int dwc2_hcd_is_b_host(struct dwc2_hsotg *hsotg) { return hsotg->op_state == OTG_STATE_B_HOST;