From patchwork Wed Jul 18 07:25:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Kucheria X-Patchwork-Id: 142250 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp211794ljj; Wed, 18 Jul 2018 00:25:46 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc13IfFf8qjlmqTD3T9mpRIKjVEmGMg4oFpS0gQpq/5iFM4hMeJiLmfVgEmB9CfxR54Z7II X-Received: by 2002:a17:902:4503:: with SMTP id m3-v6mr4294890pld.168.1531898746444; Wed, 18 Jul 2018 00:25:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531898746; cv=none; d=google.com; s=arc-20160816; b=NPHg8TxOv0Qete1PmAgIPu25SE8XdiSWu9RibyUXUC8qyuL9CI7X2t1QAfr1ciloam 7p+ohbZy8XQNy2AwYvmDsw37WcOh1doR3a9qtSIPWF04DTvq2yLEzZL7791ewtklF6yh 0sVU9SnlHPEyXsYdWpgJCoCE/jAH2jsp1dO5iLlcRant1Sq6Hgb2s52gSakohUerzQlK 9bsWdO+ais1Y2syulsHjWpq7pSlHWebK9TJ2/C9r/OA2nwyCp9EMDPmizkhp4NgJo5BH 3FXZLNyKs9vr1mUI+PJ9RNGMjNAq2cohWWU6zZyJBabDs7kTAvqMT3rAsDg4VokfFuxF o2zg== 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 :arc-authentication-results; bh=PRLjO4NtEBHF3gs51RwAFkmtv8s6MEbP/FrpA8XBlqY=; b=H9oFd2nt0YgQPoqgHCEXvpKj3+imAA1az0wXE3wDvtzOvomqTCNj+SBua6M0LgsjGs JYrjw+wknJSE8UlVjvPaA046tVEWMVDN0eNZCGuuP3emCXqKoBP2Loaeg4E72tGEp/8F oSgkQKW8FM64hSGo8fbryE+CBaZpxhB+YA/oKQHZzt/gWU1g7D/H3eIIKdmAlbq0Xubk GhX6PsRq5eOGplCNhPi8FiYyW9GS7+G8yvzFoTgoe3Fsfz8pYBlvAG1NC2Os7XRALpaX X4b5sCAspx2kCRloZlWreAZQ/XhaCC6UTX/F6l2Xeo0xLxk7fy5B6fGqCDtKyH7ov2EG V1Xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=e74zkUDu; 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 k6-v6si2585736pgb.446.2018.07.18.00.25.46; Wed, 18 Jul 2018 00:25:46 -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=e74zkUDu; 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 S1729861AbeGRICL (ORCPT + 10 others); Wed, 18 Jul 2018 04:02:11 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:43548 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729462AbeGRICK (ORCPT ); Wed, 18 Jul 2018 04:02:10 -0400 Received: by mail-wr1-f67.google.com with SMTP id b15-v6so3524537wrv.10 for ; Wed, 18 Jul 2018 00:25:43 -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=PRLjO4NtEBHF3gs51RwAFkmtv8s6MEbP/FrpA8XBlqY=; b=e74zkUDuqT7GYt7618dzrGPvIsDdZdmol4UIQI7axxkYed1TVtfj4ZJwY6PlJ2d29q nC2SGzUeH4zTybBtWaZvWBQkGZd7is9HONCvuWKREXkIlr6XAowV3p50GpVKkziAAOga GCRSvf6zZ1BMS1olVsjRH4AFVtu3vidCE+o4A= 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=PRLjO4NtEBHF3gs51RwAFkmtv8s6MEbP/FrpA8XBlqY=; b=pmV13olOjqW60V2n1PW7n/Lj2MdYVT1mBlStxdcviBsOHh/hL+WcOZYyFsU7MW6kpD aUObD7B1l7zP+Vfs2t7/2Q5dBH78qQppWY60H1TP37Gwjd6kBfEJRsoARH6HIFkVRkjh suGY4SEqIL1vRlfebkO/80Z/yiHOOLXcTQdVOjWUFOtQchtQYHWeeiocL7A+6pRuUdf6 2bOn1iXvow4OXgpEzbxaQMD1auhKsNbH7sPiim5gjAGKIZ/En4K7a11G1+LKan9LGPKq d5E+KC+C4m1GwihPYJp2ERVT7uSxDOuZ6fqiSnXcPMD5UpwsbJLLKni4ks3WOZc3hcMI faOw== X-Gm-Message-State: AOUpUlHUiAAqYZL+zjJkmh9k2SkDnWFgSjSBa0AUuMaf8ji5ofjk0XH3 6AP6uNrJpemFaMARoJnIg5k67A== X-Received: by 2002:adf:96c3:: with SMTP id u61-v6mr3477566wrb.72.1531898742996; Wed, 18 Jul 2018 00:25:42 -0700 (PDT) Received: from localhost ([49.248.170.255]) by smtp.gmail.com with ESMTPSA id l127-v6sm5729520wma.41.2018.07.18.00.25.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Jul 2018 00:25:42 -0700 (PDT) From: Amit Kucheria To: linux-kernel@vger.kernel.org Cc: rnayak@codeaurora.org, linux-arm-msm@vger.kernel.org, bjorn.andersson@linaro.org, edubezval@gmail.com, smohanad@codeaurora.org, andy.gross@linaro.org, dianders@chromium.org, mka@chromium.org, Zhang Rui , linux-pm@vger.kernel.org Subject: [PATCH v1 3/3] thermal: tsens: Fix negative temperature reporting Date: Wed, 18 Jul 2018 12:55:03 +0530 Message-Id: <42d6f2a6f9babd6351bd2fcde4000d5ca9c351ce.1531898088.git.amit.kucheria@linaro.org> X-Mailer: git-send-email 2.7.4 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 The current code will always return 0xffffffff in case of negative temperatures due to a bug in how the binary sign extension is being done. Use sign_extend32() instead. Signed-off-by: Amit Kucheria --- drivers/thermal/qcom/tsens-v2.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/qcom/tsens-v2.c b/drivers/thermal/qcom/tsens-v2.c index 908e3dc..46abc21 100644 --- a/drivers/thermal/qcom/tsens-v2.c +++ b/drivers/thermal/qcom/tsens-v2.c @@ -5,19 +5,20 @@ */ #include +#include #include "tsens.h" #define STATUS_OFFSET 0xa0 #define LAST_TEMP_MASK 0xfff #define STATUS_VALID_BIT BIT(21) -#define CODE_SIGN_BIT BIT(11) static int get_temp_tsens_v2(struct tsens_device *tmdev, int id, int *temp) { struct tsens_sensor *s = &tmdev->sensor[id]; u32 code; unsigned int status_reg; - int last_temp = 0, last_temp2 = 0, last_temp3 = 0, ret; + u32 last_temp = 0, last_temp2 = 0, last_temp3 = 0; + int ret; status_reg = tmdev->tm_offset + STATUS_OFFSET + s->hw_id * 4; ret = regmap_read(tmdev->map, status_reg, &code); @@ -54,12 +55,8 @@ static int get_temp_tsens_v2(struct tsens_device *tmdev, int id, int *temp) else if (last_temp2 == last_temp3) last_temp = last_temp3; done: - /* Code sign bit is the sign extension for a negative value */ - if (last_temp & CODE_SIGN_BIT) - last_temp |= ~CODE_SIGN_BIT; - - /* Temperatures are in deciCelicius */ - *temp = last_temp * 100; + /* Convert temperatures to milliCelicius */ + *temp = sign_extend32(last_temp, fls(LAST_TEMP_MASK) - 1) * 100; return 0; }