From patchwork Fri Feb 5 13:45:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 12071221 X-Patchwork-Delegate: daniel.lezcano@linaro.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B20C8C433DB for ; Fri, 5 Feb 2021 22:42:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8055064FF0 for ; Fri, 5 Feb 2021 22:42:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230127AbhBEWmC (ORCPT ); Fri, 5 Feb 2021 17:42:02 -0500 Received: from muru.com ([72.249.23.125]:57664 "EHLO muru.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231421AbhBENq2 (ORCPT ); Fri, 5 Feb 2021 08:46:28 -0500 Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 364CB81BC; Fri, 5 Feb 2021 13:45:59 +0000 (UTC) From: Tony Lindgren To: Amit Kucheria , Daniel Lezcano , Zhang Rui Cc: Eduardo Valentin , Keerthy , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org, Adam Ford , Carl Philipp Klemm , "H . Nikolaus Schaller" , Merlijn Wajer , Pavel Machek , Peter Ujfalusi , Sebastian Reichel Subject: [PATCH 3/4] thermal: ti-soc-thermal: Simplify polling with iopoll Date: Fri, 5 Feb 2021 15:45:33 +0200 Message-Id: <20210205134534.49200-4-tony@atomide.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210205134534.49200-1-tony@atomide.com> References: <20210205134534.49200-1-tony@atomide.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org We can use iopoll for checking the EOCZ (end of conversion) bit. And with this we now also want to handle the timeout errors properly. For omap3, we need about 1.2ms for the single mode sampling to wait for EOCZ down, so let's use 1.5ms timeout there. Waiting for sampling to start is faster and we can use 1ms timeout. Cc: Adam Ford Cc: Carl Philipp Klemm Cc: Eduardo Valentin Cc: H. Nikolaus Schaller Cc: Merlijn Wajer Cc: Pavel Machek Cc: Peter Ujfalusi Cc: Sebastian Reichel Signed-off-by: Tony Lindgren Tested-by: Adam Ford #logicpd-torpedo-37xx-devkit --- drivers/thermal/ti-soc-thermal/ti-bandgap.c | 30 ++++++++++----------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/drivers/thermal/ti-soc-thermal/ti-bandgap.c b/drivers/thermal/ti-soc-thermal/ti-bandgap.c --- a/drivers/thermal/ti-soc-thermal/ti-bandgap.c +++ b/drivers/thermal/ti-soc-thermal/ti-bandgap.c @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -27,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -604,7 +604,9 @@ static int ti_bandgap_force_single_read(struct ti_bandgap *bgp, int id) { struct temp_sensor_registers *tsr = bgp->conf->sensors[id].registers; - u32 counter; + void __iomem *temp_sensor_ctrl = bgp->base + tsr->temp_sensor_ctrl; + int error; + u32 val; /* Select continuous or single conversion mode */ if (TI_BANDGAP_HAS(bgp, MODE_CONFIG)) { @@ -619,26 +621,22 @@ ti_bandgap_force_single_read(struct ti_bandgap *bgp, int id) RMW_BITS(bgp, id, temp_sensor_ctrl, bgap_soc_mask, 1); /* Wait for EOCZ going up */ - counter = 1000; - while (--counter) { - if (ti_bandgap_readl(bgp, tsr->temp_sensor_ctrl) & - tsr->bgap_eocz_mask) - break; - udelay(1); - } + error = readl_poll_timeout_atomic(temp_sensor_ctrl, val, + val & tsr->bgap_eocz_mask, + 1, 1000); + if (error) + dev_warn(bgp->dev, "eocz timed out waiting high\n"); /* Clear Start of Conversion if available */ RMW_BITS(bgp, id, temp_sensor_ctrl, bgap_soc_mask, 0); } /* Wait for EOCZ going down, always needed even if no bgap_soc_mask */ - counter = 1000; - while (--counter) { - if (!(ti_bandgap_readl(bgp, tsr->temp_sensor_ctrl) & - tsr->bgap_eocz_mask)) - break; - udelay(1); - } + error = readl_poll_timeout_atomic(temp_sensor_ctrl, val, + !(val & tsr->bgap_eocz_mask), + 1, 1500); + if (error) + dev_warn(bgp->dev, "eocz timed out waiting low\n"); return 0; }