From patchwork Fri Jun 2 08:50:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 102387 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp885389vqr; Fri, 2 Jun 2023 01:59:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7/g9ZEiWLTnhwWcZVlGWg5BqREkEGX+xIWwWladyf3rPmrm15R968QdKWDQMxgG6T1ndHt X-Received: by 2002:a05:6a20:9389:b0:110:873a:a8 with SMTP id x9-20020a056a20938900b00110873a00a8mr13573055pzh.52.1685696361512; Fri, 02 Jun 2023 01:59:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685696361; cv=none; d=google.com; s=arc-20160816; b=Kgc13N32h4xrwvKsL40QjWM3zYg43+pf/z+kSoBTneNtmEOkHv2rkDDZs6gfLa/h2L Lh8oBR4XtwA30AiqmELi6Qf1SLxXh/ZqG9h+h11N4U07CT4LA7F7PGC+rJoiwseK1Pis nh+vETZF9Ipxh2InjeVqanZ5BNUFNDDLFAZJDormFuQ85XQfQ3oCPaGd3pbs7cDrEn9w 4aVySD+3aiIi/aEZ+iYqJWIonXbJNF93VFWSnJcEAmr+phWV7rWDPsYzoVLBxJ5T6zQF tTb3UB510gT39vQ3jGM/QCwf1Ki1+jOZMAUN4/iLj8itcEIa7tsGgifXE/1vF80q8mla /1+Q== 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; bh=HQDEWTcbGvbpQ/4fpOwDwd869G3YfVM+8tc2uh2GD2Y=; b=W43oll/aW7n4qvXl71qXkuAxaJIZQmyzSgCm4q6yGS9Ok8vCoiR3LKFlRAWoZsNsqz iSehc+a88VE+qpVJ5tvM9y+n0HnoAPIVArIBuob+iEeuHixlx4PVPMg9+ZsnMO0jqr0R u6DVyXbqo1QBuC5/CQYE6Pr3OdELb6rB7WzuFQ9Nx165AaTRrMOzE1ZSc5cHclAtuBs4 pynzcio7X03vEw9aOY+1aq1Q16hBfUo0LN2wykqxtdM0dF3hG5hmqglGF33S6/9DdLzO j54GVdurYEBDP1L2NwVs0yYYj+L0L1a8qAkxxG6Ro3iiEIVN0c3bxS0TX28QZAZq1sFI KnCw== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o25-20020a637319000000b0053fec3ed061si638885pgc.718.2023.06.02.01.59.07; Fri, 02 Jun 2023 01:59:21 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234980AbjFBIw0 (ORCPT + 99 others); Fri, 2 Jun 2023 04:52:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234896AbjFBIvy (ORCPT ); Fri, 2 Jun 2023 04:51:54 -0400 Received: from andre.telenet-ops.be (andre.telenet-ops.be [IPv6:2a02:1800:120:4::f00:15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D2231728 for ; Fri, 2 Jun 2023 01:51:15 -0700 (PDT) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed30:158c:2ccf:1f70:e136]) by andre.telenet-ops.be with bizsmtp id 48qo2A00L1tRZS8018qoWZ; Fri, 02 Jun 2023 10:51:13 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.95) (envelope-from ) id 1q50UO-00BhYR-Vj; Fri, 02 Jun 2023 10:50:48 +0200 Received: from geert by rox.of.borg with local (Exim 4.95) (envelope-from ) id 1q50Ui-00APxl-2q; Fri, 02 Jun 2023 10:50:48 +0200 From: Geert Uytterhoeven To: Michael Turquette , Stephen Boyd , Yoshihiro Shimoda , Magnus Damm , Joerg Roedel , Robin Murphy Cc: Tomasz Figa , Sylwester Nawrocki , Will Deacon , Arnd Bergmann , Wolfram Sang , Dejin Zheng , Kai-Heng Feng , Nicholas Piggin , Heiko Carstens , Peter Zijlstra , Russell King , John Stultz , Thomas Gleixner , Tony Lindgren , Krzysztof Kozlowski , Tero Kristo , Ulf Hansson , "Rafael J . Wysocki" , Vincent Guittot , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-renesas-soc@vger.kernel.org, linux-pm@vger.kernel.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH v3 6/7] soc: renesas: rmobile-sysc: Convert to readl_poll_timeout_atomic() Date: Fri, 2 Jun 2023 10:50:41 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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?1767580748100394631?= X-GMAIL-MSGID: =?utf-8?q?1767580748100394631?= Use readl_poll_timeout_atomic() instead of open-coding the same operation. 1. rmobile_pd_power_down(): as typically less than 20 retries are needed, PSTR_RETRIES (100) µs is a suitable timeout value. 2. __rmobile_pd_power_up(): the old method of first polling some cycles with a 1 µs delay, followed by more polling cycles without any delay didn't make much sense, as the latter was insignificant compared to the former. Furthermore, typically no retries are needed. Hence just retain the polling with delay. Signed-off-by: Geert Uytterhoeven --- Polling measurements done on R-Mobile APE6 and A1, and SH-Mobile AG5. v3: - New. --- drivers/soc/renesas/rmobile-sysc.c | 31 ++++++++++-------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/drivers/soc/renesas/rmobile-sysc.c b/drivers/soc/renesas/rmobile-sysc.c index 728ebac98e14a5cc..5d621c35fba1116a 100644 --- a/drivers/soc/renesas/rmobile-sysc.c +++ b/drivers/soc/renesas/rmobile-sysc.c @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include #include #include @@ -19,8 +21,6 @@ #include #include -#include - /* SYSC */ #define SPDCR 0x08 /* SYS Power Down Control Register */ #define SWUCR 0x14 /* SYS Wakeup Control Register */ @@ -47,6 +47,7 @@ static int rmobile_pd_power_down(struct generic_pm_domain *genpd) { struct rmobile_pm_domain *rmobile_pd = to_rmobile_pd(genpd); unsigned int mask = BIT(rmobile_pd->bit_shift); + u32 val; if (rmobile_pd->suspend) { int ret = rmobile_pd->suspend(); @@ -56,14 +57,10 @@ static int rmobile_pd_power_down(struct generic_pm_domain *genpd) } if (readl(rmobile_pd->base + PSTR) & mask) { - unsigned int retry_count; writel(mask, rmobile_pd->base + SPDCR); - for (retry_count = PSTR_RETRIES; retry_count; retry_count--) { - if (!(readl(rmobile_pd->base + SPDCR) & mask)) - break; - cpu_relax(); - } + readl_poll_timeout_atomic(rmobile_pd->base + SPDCR, val, + !(val & mask), 0, PSTR_RETRIES); } pr_debug("%s: Power off, 0x%08x -> PSTR = 0x%08x\n", genpd->name, mask, @@ -74,25 +71,17 @@ static int rmobile_pd_power_down(struct generic_pm_domain *genpd) static int __rmobile_pd_power_up(struct rmobile_pm_domain *rmobile_pd) { - unsigned int mask = BIT(rmobile_pd->bit_shift); - unsigned int retry_count; - int ret = 0; + unsigned int val, mask = BIT(rmobile_pd->bit_shift); + int ret; if (readl(rmobile_pd->base + PSTR) & mask) return ret; writel(mask, rmobile_pd->base + SWUCR); - for (retry_count = 2 * PSTR_RETRIES; retry_count; retry_count--) { - if (!(readl(rmobile_pd->base + SWUCR) & mask)) - break; - if (retry_count > PSTR_RETRIES) - udelay(PSTR_DELAY_US); - else - cpu_relax(); - } - if (!retry_count) - ret = -EIO; + ret = readl_poll_timeout_atomic(rmobile_pd->base + SWUCR, val, + (val & mask), PSTR_DELAY_US, + PSTR_RETRIES * PSTR_DELAY_US); pr_debug("%s: Power on, 0x%08x -> PSTR = 0x%08x\n", rmobile_pd->genpd.name, mask,