From patchwork Mon Sep 7 07:12:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2h1bmZlbmcgWXVuICjkupHmmKXls7Ap?= X-Patchwork-Id: 1358634 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=mediatek.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=mediatek.com header.i=@mediatek.com header.a=rsa-sha256 header.s=dk header.b=ROySud+J; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BlKM062Hvz9sSP for ; Mon, 7 Sep 2020 17:15:56 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 31D488242E; Mon, 7 Sep 2020 09:14:40 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=mediatek.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=mediatek.com header.i=@mediatek.com header.b="ROySud+J"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CBBD28241B; Mon, 7 Sep 2020 09:14:33 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=0.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MIME_BASE64_TEXT,RDNS_NONE,SPF_HELO_NONE, UNPARSEABLE_RELAY,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from mailgw01.mediatek.com (unknown [210.61.82.183]) by phobos.denx.de (Postfix) with ESMTP id F192282401 for ; Mon, 7 Sep 2020 09:14:26 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=mediatek.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=chunfeng.yun@mediatek.com X-UUID: 02b930d6bd7e4296baf060e62842b6ad-20200907 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=toRwJlVWTwPACLEx+HvO7AcWKqjWuAkDm5M5peBd8is=; b=ROySud+JDPxYHNCi+YlltxxQh7UL0lthhj/ZXVjk4T+A3HBeKuPhmIst4aJEwnfPs/2M3MdrFnA+Pf738/uz9cIQeWgWOse6xADSOEh8oA5IaDtL87TgDIFxj2wanGD3WMZfkl6M2TeA6HVSiaGaXk2BRAxGv5HE4gEKBVbuPDU=; X-UUID: 02b930d6bd7e4296baf060e62842b6ad-20200907 Received: from mtkcas06.mediatek.inc [(172.21.101.30)] by mailgw01.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.14 Build 0819 with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1013374626; Mon, 07 Sep 2020 15:14:16 +0800 Received: from mtkcas08.mediatek.inc (172.21.101.126) by mtkmbs08n2.mediatek.inc (172.21.101.56) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 7 Sep 2020 15:14:13 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas08.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 7 Sep 2020 15:14:14 +0800 From: Chunfeng Yun To: Bin Meng , Marek Vasut CC: , GSS_MTK_Uboot_upstream , Frank Wunderlich , Tom Rini , Ryder Lee , Weijie Gao , Simon Glass , Chunfeng Yun Subject: [PATCH v3 9/9] usb: xhci: convert to readx_poll_sleep_timeout() Date: Mon, 7 Sep 2020 15:12:07 +0800 Message-ID: <1599462727-2188-9-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty In-Reply-To: <1599462727-2188-1-git-send-email-chunfeng.yun@mediatek.com> References: <1599462727-2188-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 X-TM-SNTS-SMTP: 5241901CFFC1BFD75A18E7ACD032A45C278510D76C57000581B122D4CCD8AE9C2000:8 X-MTK: N X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Use readx_poll_sleep_timeout() to poll the register status Signed-off-by: Chunfeng Yun Reviewed-by: Bin Meng --- v3: no changes v2: fix typo of title suggested by Frank --- drivers/usb/host/xhci.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index fe30101..3547a9b 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #ifndef CONFIG_USB_MAX_CONTROLLER_COUNT @@ -143,23 +144,19 @@ struct xhci_ctrl *xhci_get_ctrl(struct usb_device *udev) * @param usec time to wait till * @return 0 if handshake is success else < 0 on failure */ -static int handshake(uint32_t volatile *ptr, uint32_t mask, - uint32_t done, int usec) +static int +handshake(uint32_t volatile *ptr, uint32_t mask, uint32_t done, int usec) { uint32_t result; + int ret; + + ret = readx_poll_sleep_timeout(xhci_readl, ptr, result, + (result & mask) == done || result == U32_MAX, + 1, usec); + if (result == U32_MAX) /* card removed */ + return -ENODEV; - do { - result = xhci_readl(ptr); - if (result == ~(uint32_t)0) - return -ENODEV; - result &= mask; - if (result == done) - return 0; - usec--; - udelay(1); - } while (usec > 0); - - return -ETIMEDOUT; + return ret; } /**