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: 157736 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp610622jaa; Thu, 7 Feb 2019 04:57:01 -0800 (PST) X-Google-Smtp-Source: AHgI3Ia2WVEhPN10P4WKmtLaTP5w+xg4TGT/biPC5/yney435GZ7R6Pl3tIoV0j97sr6E3/a3/wf X-Received: by 2002:a65:64c8:: with SMTP id t8mr4291966pgv.31.1549544221578; Thu, 07 Feb 2019 04:57:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549544221; cv=none; d=google.com; s=arc-20160816; b=V47tCUNSjTzWXGdy/r3WgPcRyzqUflhS7xay6R+5i4mg7HA5gWIUMUOV6MDkIjFz5x /YJkNuwhdMkHwks5Ca2CcKTXPN4NmoYpQKDrkr48IZhWVJVQOPjn2I/ba3Tp26IOmSqZ XfMCZ5T19QFMFkPcEmqih/MP1mMh/PqRCQBXBW3lEYUWRbtEjRRHkHcyUmFRDRRL/v74 Hly2JpvGPKyIvk3+athmuOVSq1z6LcdSb6O7yjbWRtPPcssyh0Gb97c9cng1R25DMWY1 I3fLNz4JL/6yD5YGpknMypFZDswXZShX/1wgw9dt53zb+2efN6lnjGMidPQQ0UPJY+aw rkHA== 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=mSp0BJaAkKriZPizUSoQw+VR9SnVdso3SWK1GQEdFzY=; b=vlYQ94IfHJpduvP+kksgKfEFfMNFU6WCE1tX9huUEvC1mrP4QBblno+wGI4W1KdhJ1 +3jNzY8rU7NkEw+E2iB2E43Lpujg9x9Ud9I4hGVQl9hY/5NbQRcweQhsV1QeYT8P1suc z7y6qVsHe/Ec/OJ0BAkbCBZ1aafP7/58591bpCeae47PbZJv2ahBfU2uuP7TmFj6jKDn /wakp+RWLe+I5BLSarUje61L+DFwnVfVho6rOthvZP+3TrfB2G2XV6ql4KRwOvttL93T rxe/zEfu/6plsHBgz7ATxoE9l8kq/3T7qOiLUcXdXJaQrNxJaMTkueN2LbCyqkN6bJ3t p8Og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Rw4Veysd; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-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 j91si3759161pld.395.2019.02.07.04.57.01; Thu, 07 Feb 2019 04:57:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-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=Rw4Veysd; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-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 S1727211AbfBGM5A (ORCPT + 15 others); Thu, 7 Feb 2019 07:57:00 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:42898 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727173AbfBGM5A (ORCPT ); Thu, 7 Feb 2019 07:57:00 -0500 Received: by mail-pg1-f194.google.com with SMTP id d72so4449875pga.9 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=o62QUK++8/Wh4ERjc3dKMZc/LQLG2po6Vb6z7c1atbv7W1B0VBqgV/1hFq7pTaAn4s b1d5NcmjTkwUm11qQ4H9Y81CC6/RBRbR3ViiGqU1UShAsJDOSLKXoA9Q6jxiYjUKUgOM EBlGMspkeAVTOgz2UHeiZhgXd7mDi5x21GXa3BYBj7T+iXtL4P6oDdCJba7biCPxrroS n65/SZ6FeIqox4OGoVy/OxsbeOX79gUXRz5bpksIvUCAN4s7Hq/cJQk/7YC1Ess1Yy90 A47adkjWcPgGBDV3U8J1Wo85drEVd3ikuvSeAXkIZ/0lRI91zoG7XPm3kIJL3FeJBAMX CxMA== X-Gm-Message-State: AHQUAubE/fnWaE6F5HvqSTqCxLDbUgUOyd25C8kXMWOVUP/a3hAyyNsO 8yCTGika9e+AYUZ/8LE0Oe7Vkg== 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-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@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 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; }