From patchwork Thu Jul 26 10:33:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Kucheria X-Patchwork-Id: 10545597 X-Patchwork-Delegate: agross@codeaurora.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 60E9A9093 for ; Thu, 26 Jul 2018 10:34:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F5432AE2A for ; Thu, 26 Jul 2018 10:34:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3BD6D2A7E8; Thu, 26 Jul 2018 10:34:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C954B2A4B5 for ; Thu, 26 Jul 2018 10:34:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729216AbeGZLuG (ORCPT ); Thu, 26 Jul 2018 07:50:06 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:56146 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729435AbeGZLuF (ORCPT ); Thu, 26 Jul 2018 07:50:05 -0400 Received: by mail-wm0-f67.google.com with SMTP id f21-v6so1449885wmc.5 for ; Thu, 26 Jul 2018 03:33:51 -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=LnuO8mINuH/6zEhwieXU1MyQ1uhrZQBRKE+R5lMhY9U=; b=JHfy94uO0KUBlye3Ri4yZvHQKKeISc0CUzRbZtwLlgsPJ8Gt1oItxh7O0vvX/q5ZAz w9peiRZXhYQ5G3OY/LXCJ+3Cdu5XFGeltKLjqkGemvBU6WQKIXahhcM1WefrHclDiU9e e4wZBgkr6uxqW8nxQM5F86ZPCJbeMxytR8JlM= 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=LnuO8mINuH/6zEhwieXU1MyQ1uhrZQBRKE+R5lMhY9U=; b=TNw+Iia3SjWNCUN7hb18xuOUGWwVuVKRJgYdcUU3OpbvU8mfZRaKnfBfGzHGemmYK0 OhdEmKKkKFqU6pJkU1M/OwxCFvi6U/0Awxhc9zuHg7HWb24HLdQ7FevifXUFHh45iyXs +CgJMlmOaps/ZRpQ3lgsgaCEXdtEh5i4yNW8Ows0J7YjtiNlZmOe2Z0XZGPDjgire8Xi 4gMconTM5+pbSDOL5q0bxpVIEohpBy1GuWGgaARkokYt+Z9u1scwbCk2mEoFwXtmVshQ Lrec7z0SQSg6JUygaAGjrLo5bZQ5ctPt4xUofDXTyLk16GsuJMAsx5CHsK/MslirPon+ 1ZGg== X-Gm-Message-State: AOUpUlEMKTW+SYfERC7hJ+XLHD0E7YMcGlHm4kfeigR+Jb5605b5nvmu jJLfuxFwfwVm8gvzDt5dGRlK7Q== X-Google-Smtp-Source: AAOMgpdP0M7RJmFn5l+qENdZ5+AaglRgxQhkkw2EnTT7Ql/qK1wNx6lQuhzWhpqxt79RuzqJx8dT8w== X-Received: by 2002:a1c:7d47:: with SMTP id y68-v6mr1149937wmc.62.1532601230918; Thu, 26 Jul 2018 03:33:50 -0700 (PDT) Received: from localhost ([49.248.197.57]) by smtp.gmail.com with ESMTPSA id i125-v6sm2357906wmd.23.2018.07.26.03.33.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Jul 2018 03:33:50 -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 v2 3/3] thermal: tsens: Fix negative temperature reporting Date: Thu, 26 Jul 2018 16:03:10 +0530 Message-Id: <52516c287c9455676e7cbde4a4fa94282d73367f.1532600791.git.amit.kucheria@linaro.org> X-Mailer: git-send-email 2.17.GIT In-Reply-To: References: In-Reply-To: References: Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Matthias Kaehlcke Reviewed-by: Bjorn Andersson --- 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 908e3dcb2d5c..44da02f594ac 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 temperature from deciCelsius to milliCelsius */ + *temp = sign_extend32(last_temp, fls(LAST_TEMP_MASK) - 1) * 100; return 0; }