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: 160683 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp283024jan; Wed, 20 Mar 2019 06:19:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqyEEttCI9UCkqTtfNuovN2YYdzao/LpsA0Xe/VujWHiEwp0GN7BnVt8i9Fv6bosEoicuiSi X-Received: by 2002:a65:50cc:: with SMTP id s12mr7727440pgp.130.1553087977905; Wed, 20 Mar 2019 06:19:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553087977; cv=none; d=google.com; s=arc-20160816; b=Dm0WDGEMi4M8Yqm7uP2qQ3+s6u74RyC0iT6HjbQdf6fDG64LMuTgyXuZtZat0Gx1OA DFMqeJ2Z5ccSotx9PiEpA+MheHcTaHV+9D0KWz3yDJ5N+tQXQaMI2eKLKp764behOgZ1 lOKTM9QHjDiajWFUNZfS5ClBiBDaiMnyx/FXwodrkN3dUbomvZ63497d2RxTv942Xww7 sknEITk7vxUGXi+fogDqlaofJW1dG4StkoyQRsvz4LGpP8P4DsZgLpDHAsu47weK8Hvg fhczeduiCYmXmSEc6VmxxeU9Zz3afnofRiLYUtxVKU5RfAkNY5DcgE/YgtCtMH/dZGST +OPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=M+ri0/t8z+fxO1Ckfy5EpkjgMAx02hieB7076U60UDM=; b=SyOfadsb1aIikVtlwLZ00Xb50NlN3M8VSuF9e/lj3n6eihJtDmyTbPhovA7X5SvSfx kcZqyfdzEDV1nOd8c+d3FcBSeYhl4Y5+8e2TlG5eKJeHMpOx/0TZmcJKESLXj3fXql3X SKVp+YGk7C9uwIxj/UkTrZxzrkwZ17YfSG3HF2kmqSgYpRjdCXzuEJI3Sm5Xp3Va6YSe t6DAKu16UVUPp/3a3Kt5P8uqblDXKr1flZ6KsQPrZciEVXRIwATIXlPRUgvjew3amA/t zXAqZJIEbXyNvWsjV6qAeUy/P59Dv4n8xTW5y4/VEEHT6NqKA5BNc32bWhi87z8KoUsn 8Paw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=d5w7gFx+; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i31si1596189pgi.284.2019.03.20.06.19.37; Wed, 20 Mar 2019 06:19:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=d5w7gFx+; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728307AbfCTNTg (ORCPT + 11 others); 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-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 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(-) -- 2.17.1 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; }