From patchwork Fri Oct 28 22:55:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Cercueil X-Patchwork-Id: 12583 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1083458wru; Fri, 28 Oct 2022 16:00:41 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6UoKWazsCF0kdpmSmr7nsFMLVIID9tA1l1CzFaST5BYksp+rHmUTk+BivnvVTEFFBa4eao X-Received: by 2002:a17:907:a48:b0:7a7:3714:1629 with SMTP id be8-20020a1709070a4800b007a737141629mr1397154ejc.569.1666998041826; Fri, 28 Oct 2022 16:00:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666998041; cv=none; d=google.com; s=arc-20160816; b=eAxn7bXstR2TpuaRnnhDo5L7YhbEwXVPPFVsBmoQhPUdb+QdQy0Q7X1SSHXXPChAyT dcRIhxVeZ2jecsjXAVwbOFHu2YFNuM4LJzwYqyNvr0nmsFZ5ZuHw3eDkqTgmzdz+4RoC jvVHroQ9bsTv3naT29rm01uGozpxHdScHpyk2SltNeFkTcGixUxyXgfuuG31fqaXOcmk X3FrTHuIILD3V/hy3ynIibcyb3RdvX325drkpttKigc3YUQSrQdvvVsRuMvQ2cBLh+NR L5Kw+08bdRwWQyy6NbjOAhg3gWeYt/wIt0FmoNnv6ms+N6RFhfo1oPWG+8FJv91zKv97 btAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VRHSnhFqlAbB4ByXHkBp5FSSjtyBVVmk/Lv0SwF9ti8=; b=sSia2XQvqT37IJOKu8l8nUFt87ZtsIRJ58NY8GDONNRknmRaLKUjyU3TplWd16Dov7 B1Xe86X8u7oBl+0l3vnd5aGxpWU7T/bnmxLpBXq1jUOwtToZYzX0N9nOnLyPILvZWh9f 9qN3ZJZkeJ7ta8w7X/C010UI6lbCSJt2A0iCC7Z3ZwmzA8BJV9krM0IUZqP/bMpbTUMv QXdgV+ESurKsdiV7OlqyMzvwuOeHYjjc2F8MiHZ/RHPp+DthwWyLSvOy8vKSy8jH5+sn rvqOOgozPNpxMFqfJ2C469u3Y4oz1527poD1/Le1Q+moLL1UhhavcU/Nq4jTtxW5xHcH a9Ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@crapouillou.net header.s=mail header.b=ok9Fs3gb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o24-20020a50fd98000000b004608c0b9a8asi765984edt.201.2022.10.28.16.00.18; Fri, 28 Oct 2022 16:00:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@crapouillou.net header.s=mail header.b=ok9Fs3gb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230149AbiJ1W4G (ORCPT + 99 others); Fri, 28 Oct 2022 18:56:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230030AbiJ1Wzz (ORCPT ); Fri, 28 Oct 2022 18:55:55 -0400 Received: from aposti.net (aposti.net [89.234.176.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D2BA1EF06D; Fri, 28 Oct 2022 15:55:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crapouillou.net; s=mail; t=1666997728; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VRHSnhFqlAbB4ByXHkBp5FSSjtyBVVmk/Lv0SwF9ti8=; b=ok9Fs3gbFSdHNylRdcL+uco+GLwquJAiuljCCeoCxNdupA9Q+12Aj8bhmYqlOMAgHfFRAW xaBoP5hpECfimN0t+gXSLjp8ifJz5rqSdEQ/tASvC1Zf+1evUBlMdocy03o2CCEhESbKHj YRPqJANJ3ZQpMI1BvgxcNloqgQGOUk8= From: Paul Cercueil To: Alessandro Zummo , Alexandre Belloni , Rob Herring , Krzysztof Kozlowski Cc: linux-rtc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, od@opendingux.net, Paul Cercueil Subject: [PATCH v2 2/4] rtc: jz4740: Use readl_poll_timeout Date: Fri, 28 Oct 2022 23:55:17 +0100 Message-Id: <20221028225519.89210-3-paul@crapouillou.net> In-Reply-To: <20221028225519.89210-1-paul@crapouillou.net> References: <20221028225519.89210-1-paul@crapouillou.net> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747974138491107698?= X-GMAIL-MSGID: =?utf-8?q?1747974138491107698?= Use readl_poll_timeout() from instead of using custom poll loops. The timeout settings are different, but that shouldn't be much of a problem. Instead of polling 10000 times in a close loop, it polls for one millisecond. Signed-off-by: Paul Cercueil --- drivers/rtc/rtc-jz4740.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/drivers/rtc/rtc-jz4740.c b/drivers/rtc/rtc-jz4740.c index c383719292c7..4ee6e5ee09b1 100644 --- a/drivers/rtc/rtc-jz4740.c +++ b/drivers/rtc/rtc-jz4740.c @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -69,19 +70,15 @@ static inline uint32_t jz4740_rtc_reg_read(struct jz4740_rtc *rtc, size_t reg) static int jz4740_rtc_wait_write_ready(struct jz4740_rtc *rtc) { uint32_t ctrl; - int timeout = 10000; - do { - ctrl = jz4740_rtc_reg_read(rtc, JZ_REG_RTC_CTRL); - } while (!(ctrl & JZ_RTC_CTRL_WRDY) && --timeout); - - return timeout ? 0 : -EIO; + return readl_poll_timeout(rtc->base + JZ_REG_RTC_CTRL, ctrl, + ctrl & JZ_RTC_CTRL_WRDY, 0, 1000); } static inline int jz4780_rtc_enable_write(struct jz4740_rtc *rtc) { uint32_t ctrl; - int ret, timeout = 10000; + int ret; ret = jz4740_rtc_wait_write_ready(rtc); if (ret != 0) @@ -89,11 +86,8 @@ static inline int jz4780_rtc_enable_write(struct jz4740_rtc *rtc) writel(JZ_RTC_WENR_MAGIC, rtc->base + JZ_REG_RTC_WENR); - do { - ctrl = readl(rtc->base + JZ_REG_RTC_WENR); - } while (!(ctrl & JZ_RTC_WENR_WEN) && --timeout); - - return timeout ? 0 : -EIO; + return readl_poll_timeout(rtc->base + JZ_REG_RTC_WENR, ctrl, + ctrl & JZ_RTC_WENR_WEN, 0, 1000); } static inline int jz4740_rtc_reg_write(struct jz4740_rtc *rtc, size_t reg,