From patchwork Tue Apr 3 07:15:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Wang X-Patchwork-Id: 10320727 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B6128602C8 for ; Tue, 3 Apr 2018 07:33:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F0CE289B9 for ; Tue, 3 Apr 2018 07:33:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 939DA289BD; Tue, 3 Apr 2018 07:33:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 12F28289B9 for ; Tue, 3 Apr 2018 07:33:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=PwQ2N5rAjgcRyKjUrCj2MWX3BW5SlgFWdy8JNWsSqfg=; b=AFr5rCHDH/Raek ODYMqecw8PF1IWizfGX9D20iOgTA16RkP4RADXEohZbjCtWJjE3ZU96c407dptTTKXwSAXXNW8OKr CAbeSKm35GU5Xv9B2DzM8nFm/6g6IL7xMLnuGn01PbMAmkyRgvzwgjlUJq/TLeHKhlOYZYznTR9Qz ZhR4f2f3AxwITXDi2TwiwYluY7cYk31BgIYmJKxlB/MnDcPKm6I26p2zfZm1ylPinAa+8cSBV1AgW vK32fruPc9L2pCtmjjWJJbsjCZmrs0TCLS4hjzxnyUnjAG02wTufmtPnQp4JYa3c9t+FpCJ1BjzjA AVnGunkkntxUd/B1K9Cg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f3GRJ-0003Ab-1d; Tue, 03 Apr 2018 07:33:09 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f3GQt-0002pT-7M; Tue, 03 Apr 2018 07:32:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:CC:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=k9+cwIt8r9nSqwsLXyxl9NCew1wFUjuoSfzut//KeDY=; b=sC+MNoCIqe4t0iX0YL/MqIEN5 rrdEbXFu3l/iZ6LIq5yisrWQ61Zgzhw5F0eCvW3eofpWA5qqAzidoXvHoupeUGnV0f0zYCWpwjc3S PGCM72Ka//9Q2ZY0NRGpyPW1xky1xYHn+m1XArO9g7SIzz3tQZWhtdROc/yl64BM/IlnkeIjbNOCC wmEV0UR1u66IwrUCMm3j29dU0GNQr+Z/8ocvj5nAm+DMiGlW3PpfBC0KSb6eDYNnVe26NBAIXLKpC jrqD/Yt8BDLp/jR2n2+eLrzV+hpF1qmDnoSw43qDqGTzwxJ8y4MnTJfCx1hvLBIgDp/tuMO+Ylxn1 NBGnYWsqA==; Received: from [210.61.82.183] (helo=mailgw01.mediatek.com) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f3GBF-0006UO-V6; Tue, 03 Apr 2018 07:16:36 +0000 X-UUID: 57dcce543e774c968d2aa3369e66022b-20180403 Received: from mtkcas08.mediatek.inc [(172.21.101.126)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 891228540; Tue, 03 Apr 2018 15:16:10 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs02n2.mediatek.inc (172.21.101.101) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Tue, 3 Apr 2018 15:16:08 +0800 Received: from mtkswgap22.mediatek.inc (172.21.77.33) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1210.3 via Frontend Transport; Tue, 3 Apr 2018 15:16:08 +0800 From: To: , , , Subject: [PATCH v1 4/7] soc: mediatek: reuse regmap_read_poll_timeout helpers Date: Tue, 3 Apr 2018 15:15:54 +0800 Message-ID: <2f84f7695ea3223b8626a8369aa4ae5e0d03fdce.1522736996.git.sean.wang@mediatek.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-12.5.0.5042-8.2.9001-23760.005 X-TM-AS-Result: No-2.757200-8.000000-10 X-TMASE-MatchedRID: K16+lmNpxx2kwTZnxyBJ8wPZZctd3P4Bl2F9+KxZd8cCgjr7b0ytGURX PzMAiCClE4XSoP7sKf9blfYeHRl8CKmRcn9t9csLliwpJdZauwd9LQinZ4QefPcjNeVeWlqY+gt Hj7OwNO3DBRxZClZqwVKENRwtMheUs/ukzHUWa4VE0Qow03OSYbzzbi8SaXX8Oty0bGeZI/OATk RXSCHKGGiED+bMVzF6GjL4m1EM04WlkT9Huk9AodpAu0sLxpSoQ8G+yYJYYdZRZDsGiXQioL4jx KnHJRLcwL6SxPpr1/I= X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--2.757200-8.000000 X-TMASE-Version: SMEX-12.5.0.5042-8.2.9001-23760.005 X-TMASE-POSTMAN: 2-d; X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180403_081634_285837_15682042 X-CRM114-Status: GOOD ( 10.47 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Ulf Hansson , Weiyi Lu , Sean Wang , linux-kernel@vger.kernel.org, linux-bluetooth@vger.kernel.org, linux-mediatek@lists.infradead.org, Matthias Brugger , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Sean Wang Reuse the common helpers regmap_read_poll_timeout provided by Linux core instead of an open-coded handling. Signed-off-by: Sean Wang Cc: Matthias Brugger Cc: Ulf Hansson Cc: Weiyi Lu --- drivers/soc/mediatek/mtk-infracfg.c | 45 +++++++++---------------------------- 1 file changed, 10 insertions(+), 35 deletions(-) diff --git a/drivers/soc/mediatek/mtk-infracfg.c b/drivers/soc/mediatek/mtk-infracfg.c index 8c310de..b849aa5 100644 --- a/drivers/soc/mediatek/mtk-infracfg.c +++ b/drivers/soc/mediatek/mtk-infracfg.c @@ -12,6 +12,7 @@ */ #include +#include #include #include #include @@ -37,7 +38,6 @@ int mtk_infracfg_set_bus_protection(struct regmap *infracfg, u32 mask, bool reg_update) { - unsigned long expired; u32 val; int ret; @@ -47,22 +47,11 @@ int mtk_infracfg_set_bus_protection(struct regmap *infracfg, u32 mask, else regmap_write(infracfg, INFRA_TOPAXI_PROTECTEN_SET, mask); - expired = jiffies + HZ; + ret = regmap_read_poll_timeout(infracfg, INFRA_TOPAXI_PROTECTSTA1, + val, (val & mask) == mask, 10, + jiffies_to_usecs(HZ)); - while (1) { - ret = regmap_read(infracfg, INFRA_TOPAXI_PROTECTSTA1, &val); - if (ret) - return ret; - - if ((val & mask) == mask) - break; - - cpu_relax(); - if (time_after(jiffies, expired)) - return -EIO; - } - - return 0; + return ret; } /** @@ -80,30 +69,16 @@ int mtk_infracfg_set_bus_protection(struct regmap *infracfg, u32 mask, int mtk_infracfg_clear_bus_protection(struct regmap *infracfg, u32 mask, bool reg_update) { - unsigned long expired; int ret; + u32 val; if (reg_update) regmap_update_bits(infracfg, INFRA_TOPAXI_PROTECTEN, mask, 0); else regmap_write(infracfg, INFRA_TOPAXI_PROTECTEN_CLR, mask); - expired = jiffies + HZ; - - while (1) { - u32 val; - - ret = regmap_read(infracfg, INFRA_TOPAXI_PROTECTSTA1, &val); - if (ret) - return ret; - - if (!(val & mask)) - break; - - cpu_relax(); - if (time_after(jiffies, expired)) - return -EIO; - } - - return 0; + ret = regmap_read_poll_timeout(infracfg, INFRA_TOPAXI_PROTECTSTA1, + val, !(val & mask), 10, + jiffies_to_usecs(HZ)); + return ret; }