From patchwork Wed Mar 20 13:17:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Kucheria X-Patchwork-Id: 10861691 X-Patchwork-Delegate: eduardo.valentin@ti.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CD4D06C2 for ; Wed, 20 Mar 2019 13:19:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B430727CAF for ; Wed, 20 Mar 2019 13:19:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A5EC329AEB; Wed, 20 Mar 2019 13:19:37 +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.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_WEB 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 4026527CAF for ; Wed, 20 Mar 2019 13:19:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728307AbfCTNTg (ORCPT ); Wed, 20 Mar 2019 09:19:36 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:46824 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728311AbfCTNTf (ORCPT ); Wed, 20 Mar 2019 09:19:35 -0400 Received: by mail-pg1-f196.google.com with SMTP id a22so1767796pgg.13 for ; Wed, 20 Mar 2019 06:19:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=M+ri0/t8z+fxO1Ckfy5EpkjgMAx02hieB7076U60UDM=; b=d5w7gFx+s6qEhPWnyeJ50nwZRlljAtcyHQH3+Bqw1x7yrPSK4dgon1Ns8xBU0HqNBn fQXwMdPrAU6UJzoT4Mc2BblS/cmGX1ozJY7h46Kh/6/Az/T34lZsmBPQamUwr04OH6WC spn6F+RRmMgmZYIst/odl5A+WxCmSLusToJ2tKWpAcrLD22BQ0v0gmUXw3B7A+canCO5 tbvFlmmYcapUoqyeUvdFNA8VBj7/Iuo7MrxdYKWh8Fdgvrwgk8vztU9LSG5k7ux1zeYO irMTwluddlSF4W6l9uezv9QH9Xa1/O1FOnwe50FtUkBqxAxiQ7KVnvCNp8oCVUKe48wr Um8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=M+ri0/t8z+fxO1Ckfy5EpkjgMAx02hieB7076U60UDM=; b=qs6Wzh9Jz/ZmDjsN74TNHUcGZHDttKu96fOaqC3EBgfXcz08KXXjPQ6C7O6bSiGMhl 1YnDwTm/rscQOnB7s/6MNG3/3sB/DobLk+KGk5fLjaL65o3buzT41MkJH/6oSnF5lSrE 0/Pt7F16T7n+O4RNx9MAIQGia8JkzhB1xt86o57Kfo7wf/NM02cfDrU/rWwYDw5qb7rd VPq/gr5RU5OMCplScSQ+W0ukIqAtoKWkQB8LRYoWqp58yIw7fIo35XkQjHm6dxnCo9Zg A+aEmr7tbyzdfQAJ5Lf0jaInWpCbb+rlja657ao5pnSzvZsI1zhHw/1wRJues9BqUgVt Cy2A== X-Gm-Message-State: APjAAAX5zAwiJyorzwffDJ+MY3ADyVFaeKiIZ2aMFYNP2S6BFEN6joJl 3y4QDlu7i5PGD8z7CZHuz981qQ== X-Google-Smtp-Source: APXvYqy3SLutOmrb7MyL/K385uvWHZXFVOUa5pSwonEs3HN437R7plhgzJUJWjC6xlXQnRZlRHWvOw== X-Received: by 2002:a17:902:8c8a:: with SMTP id t10mr32048360plo.160.1553087974103; Wed, 20 Mar 2019 06:19:34 -0700 (PDT) Received: from localhost ([114.143.122.221]) by smtp.gmail.com with ESMTPSA id 17sm2716025pgt.0.2019.03.20.06.19.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Mar 2019 06:19:33 -0700 (PDT) From: Amit Kucheria To: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, bjorn.andersson@linaro.org, edubezval@gmail.com, andy.gross@linaro.org, Daniel Lezcano , David Brown , Zhang Rui Cc: linux-pm@vger.kernel.org Subject: [PATCHv3 16/23] drivers: thermal: tsens: simplify get_temp_tsens_v2 routine Date: Wed, 20 Mar 2019 18:47:56 +0530 Message-Id: <5646f7e3bd90e4644718f380b28c6115c01bcb7a.1553086065.git.amit.kucheria@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: 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 The current implementation is based on an algorithm published in the docs. Instead of reading the temperature thrice w/o any explanation, improve the algorithm. This will become the basis for a common get_temp routine in the future. Signed-off-by: Amit Kucheria --- drivers/thermal/qcom/tsens-v2.c | 55 ++++++++++----------------------- 1 file changed, 17 insertions(+), 38 deletions(-) diff --git a/drivers/thermal/qcom/tsens-v2.c b/drivers/thermal/qcom/tsens-v2.c index f3eb8661cf7a..716d7f827459 100644 --- a/drivers/thermal/qcom/tsens-v2.c +++ b/drivers/thermal/qcom/tsens-v2.c @@ -25,58 +25,37 @@ #define TM_Sn_STATUS_OFF 0x00a0 #define TM_TRDY_OFF 0x00e4 -#define LAST_TEMP_MASK 0xfff - -static int get_temp_tsens_v2(struct tsens_priv *priv, int id, int *temp) +static int get_temp_tsens_v2(struct tsens_priv *priv, int i, int *temp) { - struct tsens_sensor *s = &priv->sensor[id]; + struct tsens_sensor *s = &priv->sensor[i]; u32 temp_idx = LAST_TEMP_0 + s->hw_id; u32 valid_idx = VALID_0 + s->hw_id; - u32 last_temp = 0, last_temp2 = 0, last_temp3 = 0, valid; + u32 last_temp = 0, valid, mask; int ret; - ret = regmap_field_read(priv->rf[temp_idx], &last_temp); - if (ret) - return ret; - ret = regmap_field_read(priv->rf[valid_idx], &valid); if (ret) return ret; - - if (valid) - goto done; - - /* Try a second time */ - ret = regmap_field_read(priv->rf[valid_idx], &valid); - if (ret) - return ret; - ret = regmap_field_read(priv->rf[temp_idx], &last_temp2); - if (ret) - return ret; - if (valid) { - last_temp = last_temp2; - goto done; + while (!valid) { + /* Valid bit is 0 for 6 AHB clock cycles. + * At 19.2MHz, 1 AHB clock is ~60ns. + * We should enter this loop very, very rarely. + */ + ndelay(400); + ret = regmap_field_read(priv->rf[valid_idx], &valid); + if (ret) + return ret; } - /* Try a third/last time */ - ret = regmap_field_read(priv->rf[valid_idx], &valid); - if (ret) - return ret; - ret = regmap_field_read(priv->rf[temp_idx], &last_temp3); + /* Valid bit is set, OK to read the temperature */ + ret = regmap_field_read(priv->rf[temp_idx], &last_temp); if (ret) return ret; - if (valid) { - last_temp = last_temp3; - goto done; - } - if (last_temp == last_temp2) - last_temp = last_temp2; - else if (last_temp2 == last_temp3) - last_temp = last_temp3; -done: + mask = GENMASK(priv->fields[LAST_TEMP_0].msb, + priv->fields[LAST_TEMP_0].lsb); /* Convert temperature from deciCelsius to milliCelsius */ - *temp = sign_extend32(last_temp, fls(LAST_TEMP_MASK) - 1) * 100; + *temp = sign_extend32(last_temp, fls(mask) - 1) * 100; return 0; }