From patchwork Thu Feb 7 10:49:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Kucheria X-Patchwork-Id: 10801077 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 2B27D17FB for ; Thu, 7 Feb 2019 12:57:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 19A892D3F2 for ; Thu, 7 Feb 2019 12:57:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0D7732D421; Thu, 7 Feb 2019 12:57:02 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable 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 A68E82D3F2 for ; Thu, 7 Feb 2019 12:57:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727301AbfBGM5A (ORCPT ); Thu, 7 Feb 2019 07:57:00 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:40680 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727074AbfBGM5A (ORCPT ); Thu, 7 Feb 2019 07:57:00 -0500 Received: by mail-pg1-f195.google.com with SMTP id z10so4450236pgp.7 for ; Thu, 07 Feb 2019 04:56:59 -0800 (PST) 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=mSp0BJaAkKriZPizUSoQw+VR9SnVdso3SWK1GQEdFzY=; b=Rw4VeysdYDxv46ohT/hQhRZ61k/cyvNP2LNx3OQuYGCjF6+NpvEGujKlN1blLXLjZr SavbJH9YLLXqOeQEbyAhBTX57keBIhBZFLYmqFBWd4Q3t4rAuy/jvjhQMRZZiy6JQJnW onbViFZNGbmr1Pv4AO7/DN5T9SxP5uvvRZ4Q3COF9RbvCnYlL74oQe9IzyFTljMUAQTM YxdBrngtI98QAfWZiI6sHzXRzxWrQ0oZYfUCRvif/s6i44V5D32clZtKy8bR8zyJLKcm ww9JST7zgyGPimH8hUVLBlOHbSJq9O3mMDj3FyJ0ODxRHMQV4y3RrXvq+rD5OuNs509a pbDw== 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=mSp0BJaAkKriZPizUSoQw+VR9SnVdso3SWK1GQEdFzY=; b=eW2/UezYZ9GDBh8w51oWlMdBvYiag+FXt1YNPBdrBNhpE48gWqukvAW4s50Jt++4Hb FlgIw6iUl5ynJghbDx/MF5Zzo7oBaD88g3D2KJiBVIhRz4WBMlXosa1s8ge8lQ4EbURy 4nMh2ymUi9E8pjbOTqDrC8BVpLEdECT5KmUTbx/FllBzjyVAwxP6ZQrdaIG/qq+Izm2m GZ32PKC8rmuYP9YaW1dU2X740Z04PDKxYb3XhOYV6Q7+J6mLtZ2Iv6XJazTueb+hyoy8 jIdITZQ9EyDS4Eb7uHsMS3ryXy91tkBlODoBpHUv6ml9BmoswECxUvP7AG/8s7m+wVyN p+rg== X-Gm-Message-State: AHQUAub9NUlsppRDiKlNoR28GnrPFhTwVuDSfT+glgvt2STWd4gmcrmE DY2mBAEnhY4qLXwa8hZhdrektw== X-Google-Smtp-Source: AHgI3IampPr/DGPACAjc6CAaEhObtQ0u59f5LcVD10hy3/z/gIKBi6Xu47qY7EQzvZNbE14bIrOu9w== X-Received: by 2002:a63:2406:: with SMTP id k6mr14174003pgk.229.1549544219356; Thu, 07 Feb 2019 04:56:59 -0800 (PST) Received: from localhost ([2402:3a80:c80:4138:75dd:3900:1d90:762f]) by smtp.gmail.com with ESMTPSA id z14sm10034958pgv.47.2019.02.07.04.56.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Feb 2019 04:56:58 -0800 (PST) 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: [PATCH v1 17/24] drivers: thermal: tsens: simplify get_temp_tsens_v2 routine Date: Thu, 7 Feb 2019 16:19:35 +0530 Message-Id: <9ee687bdeb1c0529038be823947da02f7d368f53.1549525708.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 8052266447f5..0ea93b89bc65 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; }