From patchwork Fri Mar 23 09:15:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Wang X-Patchwork-Id: 10303039 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 0215A600F6 for ; Fri, 23 Mar 2018 09:18:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E750C28D1B for ; Fri, 23 Mar 2018 09:18:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D9E8328D21; Fri, 23 Mar 2018 09:18:47 +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=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 763E728D1B for ; Fri, 23 Mar 2018 09:18:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752302AbeCWJSp (ORCPT ); Fri, 23 Mar 2018 05:18:45 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:39333 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752027AbeCWJPd (ORCPT ); Fri, 23 Mar 2018 05:15:33 -0400 X-UUID: ca7b3118c3384fb081e8928fbfa42111-20180323 Received: from mtkcas09.mediatek.inc [(172.21.101.178)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 443444959; Fri, 23 Mar 2018 17:15:27 +0800 Received: from mtkcas08.mediatek.inc (172.21.101.126) by mtkmbs08n1.mediatek.inc (172.21.101.55) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Fri, 23 Mar 2018 17:15:24 +0800 Received: from mtkswgap22.mediatek.inc (172.21.77.33) by mtkcas08.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1210.3 via Frontend Transport; Fri, 23 Mar 2018 17:15:25 +0800 From: To: , , , , , , CC: , , , , , Sean Wang Subject: [PATCH v1 07/16] rtc: mediatek: replace a poll with regmap_read_poll_timeout Date: Fri, 23 Mar 2018 17:15:04 +0800 Message-ID: <5e34fe67466d09ad5ce15e913dbe371eeb0a250f.1521794177.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-23736.004 X-TM-AS-Result: No-5.321300-8.000000-10 X-TMASE-MatchedRID: K16+lmNpxx3CFAQD9fptVUZakoam9+aeTJDl9FKHbrlGL0g1nVmkYVUn QAOplXiGujQMTOaH2U4zqRoAWOSvao5S9RIYp1E+B7TqRAYVohZ9LQinZ4QefPcjNeVeWlqY+gt Hj7OwNO2+SzuwiNJ7ezeMJvMCOAKnycbRS8Uo6LOEWZeoactEMTdi8hzJL0eXVlxr1FJij9s= X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--5.321300-8.000000 X-TMASE-Version: SMEX-12.5.0.5042-8.2.9001-23736.004 X-TMASE-POSTMAN: 2-d; X-MTK: N Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Sean Wang Reuse the helper regmap_read_poll_timeout instead to simpify the logic. Furthermore, the time for a wait in each iteration changed from cpu_relax to 20us is for matching the usage of the helper, but it wouldn't acctually break any the existent functionality according to a good test on MT6323 PMIC. Signed-off-by: Sean Wang --- drivers/rtc/rtc-mt6397.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c index 4411c08..b62eaa8 100644 --- a/drivers/rtc/rtc-mt6397.c +++ b/drivers/rtc/rtc-mt6397.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -63,6 +64,9 @@ #define RTC_NUM_YEARS 128 #define RTC_MIN_YEAR_OFFSET (RTC_MIN_YEAR - RTC_BASE_YEAR) +#define MTK_RTC_POLL_DELAY_US 10 +#define MTK_RTC_POLL_TIMEOUT (jiffies_to_usecs(HZ)) + struct mt6397_rtc { struct device *dev; struct rtc_device *rtc_dev; @@ -74,7 +78,6 @@ struct mt6397_rtc { static int mtk_rtc_write_trigger(struct mt6397_rtc *rtc) { - unsigned long timeout = jiffies + HZ; int ret; u32 data; @@ -82,19 +85,13 @@ static int mtk_rtc_write_trigger(struct mt6397_rtc *rtc) if (ret < 0) return ret; - while (1) { - ret = regmap_read(rtc->regmap, rtc->addr_base + RTC_BBPU, - &data); - if (ret < 0) - break; - if (!(data & RTC_BBPU_CBUSY)) - break; - if (time_after(jiffies, timeout)) { - ret = -ETIMEDOUT; - break; - } - cpu_relax(); - } + ret = regmap_read_poll_timeout(rtc->regmap, + rtc->addr_base + RTC_BBPU, data, + !(data & RTC_BBPU_CBUSY), + MTK_RTC_POLL_DELAY_US, + MTK_RTC_POLL_TIMEOUT); + if (ret) + dev_err(rtc->dev, "failed to write WRTGE: %d\n", ret); return ret; }