Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp11378388ybi; Thu, 25 Jul 2019 15:21:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqx/AGDQ8xULscJhsEjDUdgKTrQ/PPwMhSV6srjxjgnMSRhIiBzttqbsDmmnCGuMPuHvhd59 X-Received: by 2002:a62:cec4:: with SMTP id y187mr18653405pfg.84.1564093264197; Thu, 25 Jul 2019 15:21:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564093264; cv=none; d=google.com; s=arc-20160816; b=wsWxYdUBfBOw0sgBaUrd7jkeO0fXnr3lDUvm2ALP86TMpyK4TW0+ep5ZMMM1pMmgcR GNc24DK4NKU+LTDdiQhzx/GlpvCzT754Ho3XnmGJx77uDXyV5o6J8aXelvM3PfRoy27T fiPczSZLgvBSUExvZcS4t4QauFZShYTLMIZPnjBzYEmNPokGe8ydfYOi0wQSR6KnPInl A0NedrPhUnsNSf8rlRH6Hoh1/KaNk6UeAM6fN4gM9iPdFlru5AD1GwK5BWc2ZtHmb52H nk21IfUafQE9rLEHL7oZKJRaytRyZ9WcOfD1463e06hjJC+Qw33kOxxAvmxdbuUzeyYj sWtw== 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=/nFT7aY+11WI394WPKOgkqXda4OYZ0oDO3kCARFs51M=; b=rrQdVOYHRZPKj5WIO6v+PK91naLaUUrURzeq51jv5pujmvrtZRmCSdamliZYiyqzEd u3MTQBNKcaHE4aqyrdCoEJ6rtJB80Ld1Bqh0q6xSTH6svwaB6J8X7IKVfjgUPuf74z8R MCdJCGm82fJ/tIHgxhw7wlGZ52qz0KZ03AFCdrjIPfVLm6e/AWUsIKjJXuEudzrYP13w JT8xXu0FIzYaGn+jqsw6l4VFjsrtzJ+se0NU9MUEG/hrIFiypPFDBPKGo7Uces5D4jRa Bue7yHgsKi920pIuvm+oC2XiXtFljDQgjURs6da5gx2S4y5cIPrAo2/IlZDupwgMsLQW 3ifQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GWrdhk3b; 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 m15si17666897pff.267.2019.07.25.15.20.48; Thu, 25 Jul 2019 15:21:04 -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=GWrdhk3b; 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 S1727339AbfGYWTv (ORCPT + 99 others); Thu, 25 Jul 2019 18:19:51 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:36002 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727327AbfGYWTt (ORCPT ); Thu, 25 Jul 2019 18:19:49 -0400 Received: by mail-pf1-f193.google.com with SMTP id r7so23437371pfl.3 for ; Thu, 25 Jul 2019 15:19:48 -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=/nFT7aY+11WI394WPKOgkqXda4OYZ0oDO3kCARFs51M=; b=GWrdhk3bhTqlZTC/WMAEHdZVfSr4B1Pd39mel3VbpvzuIB7xxk5KSQqNv1k/8hPCJx 3hXikhSNXs+PC2xSDqGk7UIQSH3UikR06q3iKd3D7TufSYX1didtRDvQxH/u5NqzZJJF hUDdCjvIVyTruCcyBN11bd2QNuq2y68AEyi9N7mcuCVo11vSGFhOedZ6nllosGplJrR+ ikyvS5nf/xhL4TjFRg/6W4gmirbAXLWP2lk8Ex8HDBje033ejKifqvWQuqQrjIIsnPbr SDJGnuVk6ZcBawmxMIDMv5n3Y0870eXl03wLInNcxDa4wXaG6bdgCpiBjyoo/a4sTo+U 3QLA== 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=/nFT7aY+11WI394WPKOgkqXda4OYZ0oDO3kCARFs51M=; b=kPcRxApoeBaO7L8HBf+q74VSKZrPkbt+ZljeNlP37hJjw7zxstx6nWXg2yqpvszkm7 QzgPkLaZv1X+IpzDnAVF0VLAwsXahqiITKbAZFFSQmBssH2BShUCmi59xK4kHMob1IzF BhzdDNF8wZqrwitIYpv3Y6rFuPCd/DciDBvucjB694pc+6+Wu6arnOkKaj3FtLvDl9YO lD81jbGEQcpJL1dTIjC0cdx2LN7vezghMHEt1JLgbt9EfG1vwFngimgl4wups1LSj24N 6ZEOW8Cn9FX4ftgKWAg2hyzv8VQMEJNw/nFDj4f73vaGthY4U8yX3fHOZdjOvZGBT6sK TqLQ== X-Gm-Message-State: APjAAAUWv0LL4AmsOWntsA5oeJoT4w5B/JIGLN71FQf5LVhwrXqOXJEF JxGTDUxVl+yyzhLlwcggQBSWvRnMTqb/mg== X-Received: by 2002:aa7:83ce:: with SMTP id j14mr18579789pfn.55.1564093188189; Thu, 25 Jul 2019 15:19:48 -0700 (PDT) Received: from localhost ([49.248.170.216]) by smtp.gmail.com with ESMTPSA id z6sm21560243pgk.18.2019.07.25.15.19.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 25 Jul 2019 15:19:47 -0700 (PDT) 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, Andy Gross , 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: Fri, 26 Jul 2019 03:48:49 +0530 Message-Id: <07de61a57cf2362169d3b128405d7305eb20785f.1564091601.git.amit.kucheria@linaro.org> 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 | 34 ++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/drivers/thermal/qcom/tsens-common.c b/drivers/thermal/qcom/tsens-common.c index 7ab2e740a1da..13a875b99094 100644 --- a/drivers/thermal/qcom/tsens-common.c +++ b/drivers/thermal/qcom/tsens-common.c @@ -84,13 +84,35 @@ static inline int code_to_degc(u32 adc_code, const struct tsens_sensor *s) return degc; } +/** + * tsens_hw_to_mC - Return properly sign extended temperature in mCelsius, + * whether in ADC code or deciCelsius depending on IP version. + * This function handles the different widths of the signed integer across IPs. + */ +static int tsens_hw_to_mC(char *str, struct tsens_sensor *s, int field, int temp) +{ + struct tsens_priv *priv = s->priv; + u32 mask; + + if (priv->feat->adc) { + /* Convert temperature from ADC code to milliCelsius */ + return code_to_degc(temp, s) * 1000; + } else { + mask = GENMASK(priv->fields[field].msb, + priv->fields[field].lsb) >> priv->fields[field].lsb; + dev_dbg(priv->dev, "%s: mask: %d\n", str, fls(mask)); + /* Convert temperature from deciCelsius to milliCelsius */ + return sign_extend32(temp, fls(mask) - 1) * 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 last_temp = 0, valid; int ret; ret = regmap_field_read(priv->rf[valid_idx], &valid); @@ -112,15 +134,7 @@ int get_temp_tsens_valid(struct tsens_sensor *s, int *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("get_temp", s, LAST_TEMP_0, last_temp); return 0; } -- 2.17.1