Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp213017imm; Wed, 18 Jul 2018 00:27:32 -0700 (PDT) X-Google-Smtp-Source: AAOMgpffWn6ASrtP2R1TkBsbqreXOYUZapsrA9314p92KFCXUU6XwSgjbU8OXEa0de+C/9hmooLL X-Received: by 2002:a63:5204:: with SMTP id g4-v6mr4771775pgb.274.1531898852726; Wed, 18 Jul 2018 00:27:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531898852; cv=none; d=google.com; s=arc-20160816; b=t4BAY0DHwP/3Dj59AntpTd6z3jvWvcWLmUGzVGM+XHNmBpDcq7S3ZE3MxIG2PgUIds KYJC+CHvuN4ojK9ln3TykuWxY+D9RzU1YvBOnBh5kz2zGq7lFJ8sQmacF765gyXXjSMz 474GTtzjLz9Q93Aa7kEFUMbPM8QUSw0wlXl50qYvKwlLMub+Fg0jPJCs/SN6eFRexuyw BWFYfHKh7pjJuMBGTWtkcz9DnKyxxcCRujXpc3IxHOZgwrX1i55ywQvAKh228VDU5lpY qvj2iJaNhEbdmM8XEOwdH3Es21oruii34icsnRtUEqRYSR7T4+ccBCxhOE1jAUOvUf0S PtGQ== 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=Q8IhPflf5vQzAr8jXJ3uD7+CS3folAs9uFIXOP8jFrM02asL2rmf11f7SNbXiHqgTb w58dFBGh2l2PkdCerDNIFtXlTCegmjmNybvnjN0Il8p60NgTtoBKoAOTWDAJ6nVSVgGN 83P3brTjs7FcjaHMdNHmf+bUcu5d+o1Tx2aEDFpxBkWUWEc4qRtRaiMrsvrU28kBDccA sV1ZReWB+sySQ8ZbbOSWjtsWnMUzQWbG+WkOr8YYxCyzuyLBR1v5WJJZvsW0drU1Np4H PX5AwWSEhj1MoNMF1kw1jIZ6vgWRGgOTN/Q0+Ps227j5e8UeXfXiudJpt4xA2JfqvGnh IXbg== 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-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 o18-v6si2827584pgh.91.2018.07.18.00.27.17; Wed, 18 Jul 2018 00:27:32 -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=e74zkUDu; 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 S1730054AbeGRICM (ORCPT + 99 others); Wed, 18 Jul 2018 04:02:12 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:35126 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729863AbeGRICK (ORCPT ); Wed, 18 Jul 2018 04:02:10 -0400 Received: by mail-wr1-f68.google.com with SMTP id a3-v6so3548180wrt.2 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=mMegnin51AZuuwlmAlAcF6Y6+1z5kQ5ZsxjWm7xr0AQQUl2w278O5GPSIOBgFlaHT5 V9klOA72Z69x4PY7Hwmm/z+eAVRpdePCm/0awYubGAxBYHI3LPSqnEse4V69NJMe7/YH yMIfbJMFHKTMEcNh0eVPNNe+FtYJfhruF3gQR8xnczxwCeIp5BF9Umtp6Mkexbjk0R6U TZ0f1pSPxmm1RDHMWZrgObz/Ig4yUW4x1rQc78UOhxsDwpo+lgk1VVh8TNKVYzeK13A5 aQxutV7zxQO5FPlJgtYiMJ2oZtTMYJMQ3vJ9V3UJILU6+dkKMjppwBZ8dldqyxM66V/O Cy4A== X-Gm-Message-State: AOUpUlGerhKRNJaq3LBkuNZjbwE4s7IzkEMFgfkX9eJTDGhuP35BOgV2 KAEZyYpEipUoxNBZISKIIkmZMFCH8SE= 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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(-) 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; } -- 2.7.4