From patchwork Fri Sep 20 21:52:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Kucheria X-Patchwork-Id: 174166 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp3032074ill; Fri, 20 Sep 2019 14:53:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqwl0XbeUgMcliwRa2xRomemVXN5YwzSLtI5UFlLy+j/q2hW+TxkaQ9K2S2icSew7AbOax6o X-Received: by 2002:a50:ed8e:: with SMTP id h14mr14542134edr.69.1569016393836; Fri, 20 Sep 2019 14:53:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569016393; cv=none; d=google.com; s=arc-20160816; b=0vXE3hjBXNZyBEz5G3txxWdG21Wx2gr6VwOnz4TbwhARgLNGFSKXKRH12ZE0apgxgp 4qjB7dJ2h5oryYUG8csrO1AESomoD11A1PoD6gNjPG6CH8aFZ3e7o6i9t+ym6MJMv8QB o4opu4DbL7cZxhlh1Pm3xDdC91dlYxlvMrVlEDG4Lii2/pcMfvjh5pPeEXq+7xKVUoZ1 ZnPHz5okS5f3evDrYkAdJFAa/bxg8RrRJEj4Du6g+bezwTwl/8Wl3pGEDP9+gIUJCJug SWI/0ySp1L2kRNfvZtSPCW4e+WCxiCQlFAMHBFuvC3sRbGnr/jT5uWCK7ajLDUNH8hAL MEJw== 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=YL6q2JVUBbo0fJpAfIZIPHfIu49FMijwp5VEsxh+fXYhHWPCXDnuGIE5VtAYiXCBBS ctfCDm3MMfzwEIMRx/xhanAZmP/AXGOrGBYrgAqHmr5GlDwEg/bJPjT23DU+9Ks/CF+K 1syAWBIotSQ/vCDJD1+Fkp8VI3nJLmHdEZtFls7LZyR99IUY0x/sB+YwhzZh+9sIld60 QOeXRbywndzcXM5AO/GEoHQzyEcgnU9ldH+f4dFTMzBQSl8HMLvJ7JkFom4YqRPaHB88 Qyxgtjq1sceA3THDpyjC1PyxntNsXCiK0gZRhNCzJn/NPn2aCsBcNiYirIABS31rrmLo s6zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lEv2wwv0; 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 y1si1783567ejr.272.2019.09.20.14.53.13; Fri, 20 Sep 2019 14:53:13 -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=lEv2wwv0; 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 S1729839AbfITVxM (ORCPT + 11 others); Fri, 20 Sep 2019 17:53:12 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:33001 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730305AbfITVxM (ORCPT ); Fri, 20 Sep 2019 17:53:12 -0400 Received: by mail-pl1-f195.google.com with SMTP id d22so2489444pls.0 for ; Fri, 20 Sep 2019 14:53:11 -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=lEv2wwv0SVuY/tTqDvXJSzksXwIRavTm9n2Rm3hSLNHJUGWIlejeRUEPY6e7vxqoTO QzS1uexKLsb/OFZ4LMMCx+wOmVjSQSKugPd55NX+3OIbRWvhfwfuMGqPxZH/7toTIDLY 9aIApMHudMQPQuRIAJB1bQAlQ5w6wnBBFnTo5lRViTCi6DbPEP2j7csIdp/myh69+iP0 3lQytGe46/oPFUcNaASXHAf4K3fYYaoA/Q/25txOFfi5I/WqoOXeaZ8vWk2MAkxpKvTr ob0tfgetkAZKjhxdJv3AAoGj9UF/Mew8l1Ilf7lv+UXuOXuAcJZTXAA3ugSTDvoVLIcq TjQA== 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=tZXMscAamPE/vgWFB6uP4G0JH3guYgVuMIx1FN6zp4vQrLCpwZHTMPHyICgpczQSGp L12sa6M/lD8O5CI0ivOCgnuCETv5yGRzNAyiUsivs1/kriKzqYoEsHW5BpdlUA2wQG/7 Dy+a7gSMNAThTL1Yyg4qgY6LCN/TlHnOXuq6+a5du94OOeRFO9402VhbxwUZ86DSepvx DGfcv4NnXROFALRj2CmU8AoyEfkc5uee+URqjRH31rZuc71O1Fa60sGa+tYyYaVQEqNY xZ37UcVfAcSbtSPIiZxfgt1N2CYUPAImqk0MCNWy/GO2UCA8jyHwkp3/iPwhPrAUUL5O tPWg== X-Gm-Message-State: APjAAAUOJX6bfrlaUYGeWYrO/DDcUaX6mR1TR7/0NSIl1z9WQTFsEbau J4h1eQBryFLOnD6QZbZvdyFhkw== X-Received: by 2002:a17:902:aa03:: with SMTP id be3mr19569285plb.84.1569016391020; Fri, 20 Sep 2019 14:53:11 -0700 (PDT) Received: from localhost (wsip-98-175-107-49.sd.sd.cox.net. [98.175.107.49]) by smtp.gmail.com with ESMTPSA id b196sm35326pga.56.2019.09.20.14.53.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Sep 2019 14:53:10 -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 v4 14/15] drivers: thermal: tsens: Create function to return sign-extended temperature Date: Fri, 20 Sep 2019 14:52:29 -0700 Message-Id: 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 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]);