From patchwork Wed Oct 16 07:34:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Kucheria X-Patchwork-Id: 176439 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp6993341ill; Wed, 16 Oct 2019 00:35:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqyPJRcVopfbOPuraJ7gCtevmdIL3LZ2rthzVY7NmfyF3jZJDtWRUHA8hcuMYhnTuvvu9kU1 X-Received: by 2002:a17:906:8608:: with SMTP id o8mr38997740ejx.179.1571211315883; Wed, 16 Oct 2019 00:35:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571211315; cv=none; d=google.com; s=arc-20160816; b=ypq+WZSlNBdbP/v395fzwp4aJpHxBfb7+OdIFBbkFfj6JbAF/iHV2xOwI6ifbE7kiZ I5Q4gRIEXmV+Z5vL5xQwuZbUvzLwgMqyeP66qCX6+Rf2FflDGaJanPZkLaG2fxe29dA9 ebyrATp0p3dS6nFZaq09H6Cvrze1U/Oi/b+gOQdX1+RH6fIQSZrHS3M5FgY9E+C+SwL/ UtkktvwD5O1/jMOUzzw1ePk90HwG/ugoe8sYlyLz9s6ZHNr43vltNBeQszIU1blEG/OY Lix8n1bEu7gXEGt/CWnB9vGUn2kaXuVpDJ7xaMDlkm6EN8/jVGNodrVMLWIXSwERhBQ5 e5wg== 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=/kNhWSzT1XF3+/kAR7Dxjp13J1ZI+CyyKCX+EYBQmx8=; b=waNiTZu9pMo3ARRNEAwsz0i7A5WM4/NKrdnxOJngfPBzeFspkkM7ZE0osScmO00pBU MZ5i0OmbZ1UVmf+7lF8KqEPl0yP73qIfkjvEZgq7u1r9CouxhEkzx9pDAbJcX5Sw8drv 6//gyRt8ECBX1Y1icx9JpsxzsLJYyoMlkrtwnUyOk/ntBWeMxjI1BGMh4g+bvb70Y0bt hh+iNxMrWt5P6nCJlTpP0gU5hmCZJuVwlgEelbdevVoQ5REaCoWUZUrBhwPxOgPkBBmH Nx7wrqyulGfzPbqPB7w9o9Qt36E040aO766ycqvfwJEIsu9TaUN822PACu2Bul4XVetE LOhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QmzymGkd; 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 l12si18986313edk.444.2019.10.16.00.35.15; Wed, 16 Oct 2019 00:35:15 -0700 (PDT) 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=QmzymGkd; 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 S2390811AbfJPHfO (ORCPT + 15 others); Wed, 16 Oct 2019 03:35:14 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:46963 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390610AbfJPHfO (ORCPT ); Wed, 16 Oct 2019 03:35:14 -0400 Received: by mail-pf1-f194.google.com with SMTP id q5so14131153pfg.13 for ; Wed, 16 Oct 2019 00:35:14 -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=/kNhWSzT1XF3+/kAR7Dxjp13J1ZI+CyyKCX+EYBQmx8=; b=QmzymGkdzTKuxhlQQbG1q+cOpiRxZSL4bdv7TTVHrcS7uAjgk0NhCFOkhZSDoi0agg dfs2fDlBES/nfc5WbMchIaqgOFuKZZZ5lnP2maSL3pITe59vcfuNo+veBb7BWXWh9MIN elCftBIxAO646pb6sAd0Ej0vLFEYSQITYp6Y1C3BT1toeeScAk8P/zDRxnmDSmdaP4JT SDHTUIwg1v6fpMQH3w4yZ5qhnIESZOLl4EL2Q4xdx0dlu1CDgtHge5LJx29Lta020jge pnkaZ+gNJ1FCG7Dde3tKXqfEqG87y6g1uMl1gNWmZKMty67hlR5rzQjDrGWHmmnaQV/4 QLfA== 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=/kNhWSzT1XF3+/kAR7Dxjp13J1ZI+CyyKCX+EYBQmx8=; b=Y7rzc2V7QL8qI3RDbgw8m4pc22P5fQKAinvSDfoKX1RRiAoeLVk6OqgYEVKdqOV95R 4cyUqroqp3Q9mpWFuSASZztHqD1QXXIbCP1Q5bb27E70+gGMj5ODnTrTjTOL9AobTe0s Dk+pQvglqhgpXHqX+BAL8E1H1651T3iV6+C5IfsCxPq4LR8m2tAtle5j22cxvz9QH3wG LhmDmdCF/cAuP5xNaa/n406+soRf9D7gWFxg5S18ky9jScpgCVc5KaEegpDhUiN3IHVV E6eB7KZvru9l0CBQtOt1rwyakHK7xbPVJUyh7/yY8cPj+CG/NCMnwwkb0Ey47jMKRQGM g9+g== X-Gm-Message-State: APjAAAXAji7fhruhFhFMoM/n4RUOt6hnIS9U0Ybc0nwuwSkKxo/4aJjt nxYhIU8naz8oCJcL/aVfR/MmZA== X-Received: by 2002:aa7:93de:: with SMTP id y30mr42412010pff.98.1571211313730; Wed, 16 Oct 2019 00:35:13 -0700 (PDT) Received: from localhost ([49.248.175.127]) by smtp.gmail.com with ESMTPSA id v68sm28026272pfv.47.2019.10.16.00.35.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 16 Oct 2019 00:35:13 -0700 (PDT) From: Amit Kucheria To: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, bjorn.andersson@linaro.org, edubezval@gmail.com, agross@kernel.org, masneyb@onstation.org, swboyd@chromium.org, Amit Kucheria , Daniel Lezcano , Mark Rutland , Rob Herring , Zhang Rui Cc: linux-pm@vger.kernel.org Subject: [PATCH 14/15] drivers: thermal: tsens: Create function to return sign-extended temperature Date: Wed, 16 Oct 2019 13:04:13 +0530 Message-Id: <0689917475cf83b7e01f6978504fd37352a5e3ca.1571210269.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 Hide the details of how to convert values read from TSENS HW to mCelsius behind a function. All versions of the IP can be supported as a result. Signed-off-by: Amit Kucheria Reviewed-by: Stephen Boyd --- drivers/thermal/qcom/tsens-common.c | 49 ++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 14 deletions(-) -- 2.17.1 diff --git a/drivers/thermal/qcom/tsens-common.c b/drivers/thermal/qcom/tsens-common.c index ea2c46cc6a66..c34a1a26ce29 100644 --- a/drivers/thermal/qcom/tsens-common.c +++ b/drivers/thermal/qcom/tsens-common.c @@ -84,13 +84,46 @@ static inline int code_to_degc(u32 adc_code, const struct tsens_sensor *s) return degc; } +/** + * tsens_hw_to_mC - Return sign-extended temperature in mCelsius. + * @s: Pointer to sensor struct + * @field: Index into regmap_field array pointing to temperature data + * + * This function handles temperature returned in ADC code or deciCelsius + * depending on IP version. + * + * Return: Temperature in milliCelsius on success, a negative errno will + * be returned in error cases + */ +static int tsens_hw_to_mC(struct tsens_sensor *s, int field) +{ + struct tsens_priv *priv = s->priv; + u32 resolution; + u32 temp = 0; + int ret; + + resolution = priv->fields[LAST_TEMP_0].msb - + priv->fields[LAST_TEMP_0].lsb; + + ret = regmap_field_read(priv->rf[field], &temp); + if (ret) + return ret; + + /* Convert temperature from ADC code to milliCelsius */ + if (priv->feat->adc) + return code_to_degc(temp, s) * 1000; + + /* deciCelsius -> milliCelsius along with sign extension */ + return sign_extend32(temp, resolution) * 100; +} + int get_temp_tsens_valid(struct tsens_sensor *s, int *temp) { struct tsens_priv *priv = s->priv; int hw_id = s->hw_id; u32 temp_idx = LAST_TEMP_0 + hw_id; u32 valid_idx = VALID_0 + hw_id; - u32 last_temp = 0, valid, mask; + u32 valid; int ret; ret = regmap_field_read(priv->rf[valid_idx], &valid); @@ -108,19 +141,7 @@ int get_temp_tsens_valid(struct tsens_sensor *s, int *temp) } /* Valid bit is set, OK to read the temperature */ - ret = regmap_field_read(priv->rf[temp_idx], &last_temp); - if (ret) - return ret; - - if (priv->feat->adc) { - /* Convert temperature from ADC code to milliCelsius */ - *temp = code_to_degc(last_temp, s) * 1000; - } else { - 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(mask) - 1) * 100; - } + *temp = tsens_hw_to_mC(s, temp_idx); return 0; }