Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp465300pxj; Thu, 20 May 2021 13:37:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxh8teuOrywh7FKzpQKU0US7rDHfdxllZd1pJDdap53kYjMI0ijujz09jyGYXiNXg7iF46p X-Received: by 2002:a92:c884:: with SMTP id w4mr7884298ilo.117.1621543021233; Thu, 20 May 2021 13:37:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621543021; cv=none; d=google.com; s=arc-20160816; b=pfcd/zxAUpvHqkOG8H0SGt00CK096ClUu1WaUEGlcqDKCBGBh2E7w/L2ltYcaevD54 iDFR/idA5VkeLI78jNA7ZhxqxBWdGR9HIbPEEaxY895J8b3ZCQcE3gv8ddWZR7HsNoKG fNevN9CxC3quWqi8yo7tUc+Oh2udojJ5VX+msOCOju1Pp86ntwHEYJ1cpoZqMWyYNe82 ui7mUE3xl0wl04/GeT9Ta7Gv1VM4LTGNjXLIgiuOWA5O6n+HvgONt067BtUSjn5gaAi3 3DJ4jC2ON8FUSo1l/yoW/krS2JmmxiZO/R7aExZrpieVp//NIx7n7vqXNAsLsJkPjNn+ bXVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9qFOgIqY5awercE2vBJj2UTOgWTDdcdVM9kajRr7VTk=; b=DZJqrwksb5+Rzps8BZjs+B4iYR9BlO6fAkTPS9ZKkhSAZLAxDUYCBb+iHN+fJbxi5c CMU2emQPhM6J/VZK1AiAUUPBTTkJ2UhMcDiQtwQvYvVBeo6aohQCa++h8K2j1/I75/uN d2HtgWDHmZ+K0AhG3LsOvTtAy2tLCf2t+4j9ME4cOvEGLZGT91xZEwbhewi43S+96dsn TT6zlHLGxE5plF6xfhAlZ2PeG9zkYkKoa9Um3QQIAtCFkvYLOhBtAbNIQpehx6n2D16O 5qa/w5Y2Me6as/azjWCzsFfdJF6wpdkepeBsr+XzAnuaYmac23pLHWyjxcaFP5ilgEhP c6mA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dMZuk5al; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a23si3221118jap.18.2021.05.20.13.36.44; Thu, 20 May 2021 13:37:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dMZuk5al; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238802AbhETKzz (ORCPT + 99 others); Thu, 20 May 2021 06:55:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:40080 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234765AbhETKkT (ORCPT ); Thu, 20 May 2021 06:40:19 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1428561C81; Thu, 20 May 2021 09:55:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504534; bh=WnyYopMNt9BjFihbU75UhtCFU5TR8jhcjbt70Rxz7X8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dMZuk5al5YgpiPjxHjkQNH6yEP6B4tvoL7Vz1XLHnm1pMInrbR30S+y/PEF64Uhxn R4gTEavaW/x6/HSqmhrI7kJdCTc0nRuQhVC3WSmMA6goBSDbKjg6vngr7bwsoWy7lH ahTuCUPDPrmwVsd++W/xKGMSicaqI9d76jXS5mtk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Svyatoslav Ryhel , Andy Shevchenko , Linus Walleij , Dmitry Osipenko , Jean-Baptiste Maneyrol , Jonathan Cameron , Maxim Schwalm Subject: [PATCH 4.14 290/323] iio: gyro: mpu3050: Fix reported temperature value Date: Thu, 20 May 2021 11:23:02 +0200 Message-Id: <20210520092130.151303166@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dmitry Osipenko commit f73c730774d88a14d7b60feee6d0e13570f99499 upstream. The raw temperature value is a 16-bit signed integer. The sign casting is missing in the code, which results in a wrong temperature reported by userspace tools, fix it. Cc: stable@vger.kernel.org Fixes: 3904b28efb2c ("iio: gyro: Add driver for the MPU-3050 gyroscope") Datasheet: https://www.cdiweb.com/datasheets/invensense/mpu-3000a.pdf Tested-by: Maxim Schwalm # Asus TF700T Tested-by: Svyatoslav Ryhel # Asus TF201 Reported-by: Svyatoslav Ryhel Reviewed-by: Andy Shevchenko Reviewed-by: Linus Walleij Signed-off-by: Dmitry Osipenko Acked-by: Jean-Baptiste Maneyrol Link: https://lore.kernel.org/r/20210423020959.5023-1-digetx@gmail.com Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/iio/gyro/mpu3050-core.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) --- a/drivers/iio/gyro/mpu3050-core.c +++ b/drivers/iio/gyro/mpu3050-core.c @@ -270,7 +270,16 @@ static int mpu3050_read_raw(struct iio_d case IIO_CHAN_INFO_OFFSET: switch (chan->type) { case IIO_TEMP: - /* The temperature scaling is (x+23000)/280 Celsius */ + /* + * The temperature scaling is (x+23000)/280 Celsius + * for the "best fit straight line" temperature range + * of -30C..85C. The 23000 includes room temperature + * offset of +35C, 280 is the precision scale and x is + * the 16-bit signed integer reported by hardware. + * + * Temperature value itself represents temperature of + * the sensor die. + */ *val = 23000; return IIO_VAL_INT; default: @@ -327,7 +336,7 @@ static int mpu3050_read_raw(struct iio_d goto out_read_raw_unlock; } - *val = be16_to_cpu(raw_val); + *val = (s16)be16_to_cpu(raw_val); ret = IIO_VAL_INT; goto out_read_raw_unlock;