Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3098326rwi; Fri, 28 Oct 2022 16:01:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM415mRgSF1WfND1QmRnnoknMxPyk8dmVzP9NecCjmCo1D5AurKe/cQZijK0DTj34k02zXy9 X-Received: by 2002:a17:907:7fac:b0:7a1:cace:1352 with SMTP id qk44-20020a1709077fac00b007a1cace1352mr1511626ejc.6.1666998090880; Fri, 28 Oct 2022 16:01:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666998090; cv=none; d=google.com; s=arc-20160816; b=zILT3KAH2MHePbUeSRd56mhN/J+2M1gry8eLUopKrVYYYNF3fwA3LsXIH8jPF+039A qIRn06qVMI80Nx7qM/7cFVf52zH7sDwucHq9lmINIApK1wUDiEfQp6jtKsxBPsM5y1/H YHN1q42Nk4sCQb9MPJAnl1+pN5oznmZg+yc/j8RDH6W26T5TzD0UeiLhrJtaGv80CR9o sx3rTAVEs0ukLvbUNmoaS9mORQ1zablRIDSILtqi/+Hd2FH2wOTn89uEkV93f2wKGnxx 3s7H9nwY2ccxWrTvVS+VBr13QqiflARmQNLsxsU0RxEAhAT0bPnGqcZ6qDIIj/GxNplC 7LOQ== 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 Return-Path: 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.01.06; Fri, 28 Oct 2022 16:01:30 -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 Content-Transfer-Encoding: 8bit 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 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, -- 2.35.1