From patchwork Wed Sep 11 07:16:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Kucheria X-Patchwork-Id: 173602 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp374829ilq; Wed, 11 Sep 2019 00:17:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqzXVwhtkEDbDwRK2bzk/w6FhgCBchkSFkaoCKxZJ3apwm+oz5+FGt3l6iOdpToLbDVDW4FT X-Received: by 2002:a17:906:e0d9:: with SMTP id gl25mr28729565ejb.101.1568186254996; Wed, 11 Sep 2019 00:17:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568186254; cv=none; d=google.com; s=arc-20160816; b=MhYk6pIXfsOm+daEPrDfXQ7tksYCD9yhsDRzsURmOs41ygRrPLsNDi2nZMixVZHbh9 /chfjQnDnDF7ryd297SEolpAwYMvgYzEGFsIYqBTAL7XT+pAORd4PjE/VotrKWaT9uXy e1WbVEzslmn38UR+dJvD3dyw2PYpWSbzAJpOZ5HqpSEjRiIlKtoSiJSDE2lWXDAh2sNl zWGcsvEYQTBd+Z0W6t13t6wwaAok2DNdBsajw72CsOGGSUqIhq8PfkJnvO1u1xCrK+Rv dFP8Pcwv1inDbFIjzNkkSvbfyK2oRf5bMnkA6v/hPsPoHgh4lu3I2upkB/s5f8ck73CZ 4K0A== 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=3XLPlhPImWAomUfs/g8BXhfm3lVXoZB+dL/zQw9KVyY=; b=JAi3BnOGbHhEN0PwjOkBVSICYahhov70ugq0PsS/5D1AxuRtZuc5lIY/zaYLaYf5aG t6wTZ0QJJeHpoLNE6dkPT0lXs6gN+3bop4lDoGMc866A+6ii8eFg50mJLPKxPrzeW3E7 44mMJHFlMGFZEW7YpSagoLMdVA21KEvxbSzJrgrY9ir9Nv6UkQTwO4x/YDfwpf4EzZDc UcRv6h01CKk8l8/QdxPibocCRVWamkUd8/ILbUy4DfNaOjunbBCKnwJL+EW/EK9eWBkK tZcdAxGNkMC8KO5SfUFM65WGd4thjOnTDAelokFS1J9GhKbQqihNn+HEYTN+B6g7QBKX +0bA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GJlxsZb2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 a53si11898538edc.175.2019.09.11.00.17.34; Wed, 11 Sep 2019 00:17:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=GJlxsZb2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1727313AbfIKHRd (ORCPT + 27 others); Wed, 11 Sep 2019 03:17:33 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:38315 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727299AbfIKHRc (ORCPT ); Wed, 11 Sep 2019 03:17:32 -0400 Received: by mail-pf1-f196.google.com with SMTP id h195so13099239pfe.5 for ; Wed, 11 Sep 2019 00:17:31 -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=3XLPlhPImWAomUfs/g8BXhfm3lVXoZB+dL/zQw9KVyY=; b=GJlxsZb21zDn7otYAc58zN7PyahcMkAX7EQUNWffJZs6M0x8PWTmcZ1KKAhmuxa7/v ue70ggqmS5flX5o6oKsh1Yz/o9isB7U1Q3arBhYZJUbO9XqYbFzYbdN35eDe8QaTjGvp tUPhdIgxrboTihBK+X6FS+TpH+nZkcLCRz45g2Mlk3LqqkhmthATiA41Bw20vGxFJbIc MBXQvVkz7jJ0GrBYNYyZOy6cQc9epnmjzyWMhWZ9AMKHyiYXXrk7TZrfRuLmxWtBBz5j i1H1Q4fuYCbQgJ4p+8GfZQLgM5HRg7nrOmYVRS+chWO1JrYsfTnRUS0G5WIPkBXF9PbX z7Nw== 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=3XLPlhPImWAomUfs/g8BXhfm3lVXoZB+dL/zQw9KVyY=; b=o9avzmV/nQ1eXF5NYuRqjDyhv0XQQkKUYgc7H821bjjgVvL14v+0jzav4/36kDYURz jenLzuSTUsMtHX8ozlRf9FkxXU9sYSu5bNS2tbM3+c+P4VNkTYRE6j8oeXXpHXsQhHLO P1eYeI7I1eXaXkbGXAimtoVLA9aRSnOlbAPjXlZ5CTw+8E8b5RZFKvFxvDgeRwfZ0jGp zKPA0DZTj5N1obnDzd+WBbr2YYFiADgj3GKSzoM33U5fuRybhwAqMs8U+sPq0BlO/avI QWw0x8r6a51S8T4vFSX+MH9EqXGuofT0UuejBI15NLGxHs4xXZhEKdvHptDPEHigok08 5Fyw== X-Gm-Message-State: APjAAAXpnbpYWLiPFhcGACURvVvtE9yt8MHTwqnywGoSr7xAHnbL4e6t QMVbgnDLV7bVfF/pnXbgPRj7UwtgA8kcDw== X-Received: by 2002:a65:6097:: with SMTP id t23mr31510470pgu.357.1568186251210; Wed, 11 Sep 2019 00:17:31 -0700 (PDT) Received: from localhost ([49.248.201.118]) by smtp.gmail.com with ESMTPSA id h3sm833961pgb.13.2019.09.11.00.17.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Sep 2019 00:17:30 -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, Daniel Lezcano , Mark Rutland , Rob Herring , Zhang Rui Cc: linux-pm@vger.kernel.org Subject: [PATCH v3 14/15] drivers: thermal: tsens: Create function to return sign-extended temperature Date: Wed, 11 Sep 2019 12:46:31 +0530 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 --- drivers/thermal/qcom/tsens-common.c | 50 +++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 14 deletions(-) -- 2.17.1 diff --git a/drivers/thermal/qcom/tsens-common.c b/drivers/thermal/qcom/tsens-common.c index ea2c46cc6a66..6b6b3841c2d0 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; } @@ -310,6 +331,7 @@ int __init init_common(struct tsens_priv *priv) goto err_put_device; } } + for (i = 0, j = VALID_0; i < priv->feat->max_sensors; i++, j++) { priv->rf[j] = devm_regmap_field_alloc(dev, priv->tm_map, priv->fields[j]);