Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp394781pxj; Thu, 20 May 2021 11:48:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzsUz8J0yLbs1VO3KfLaWQLWyLK15Krja/zqx+z5geLC1lsFE9c4xVIwA6GHjS0LkFb/lt6 X-Received: by 2002:a17:907:33d4:: with SMTP id zk20mr6084461ejb.330.1621536492896; Thu, 20 May 2021 11:48:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621536492; cv=none; d=google.com; s=arc-20160816; b=JqqZjcxwzxvVvuCoCehZq36JUZbHAGDTPLRTaPHK/exp9YxvFGWBJGtbECqtaCr9ZK qYn4YYKYZVJoNNZaTeUC25NM3D/eIBCaP13iO0IUuFndwss8jCAPYX8BY/s83j8VTWiZ SuwoX/xFNaTy3j/2TxsDRQsxtCtzjTsspMP3RKEu8o39PEqycaw2QmNHotB5I/+q/Irw +P51KlWoYur5W2jYnbfRLiG2fVStJN6iHBvREj5zbo+c+5Chys26eSTZtqE9Rc9HKrsf WlbBCP5Y9WcliTPAgUG8ssM0kRY8a1wiC5xzWAM76xITbk+7iBVgIBwIso4P29cq/KWC 2msQ== 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=oT3ghKDRDSaB3DHjykTX1danMn+X48BezZv+LzpD07tJiRuOPgjd09rITQ/l/zN5WC gBttLMgOllwogswglN77IGD/rkizM14qIYDNkq82/mqqchBYvhZe4mZhKVeyLa5VIj9E g93w1ZNDaE3wkiqeU8EusiywXlFxz818988WaFdcfIUWUoNmjesLdeCYfy6AXUAjvRIL p8UljgP6lyZO5xzteiS4ql4q/YP5xkNA+PVSoaWb75CJ9ghodooq1i5EcFz53MPP6EaG aXkj3fmqPbeYjY3XxZpgUQSNPs1L1BUMbwDCZL0h3sM9het+oRMNMz9AtidGf3uviCkZ zNkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WC4uR3G2; 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 kl4si3287835ejc.648.2021.05.20.11.47.46; Thu, 20 May 2021 11:48:12 -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=WC4uR3G2; 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 S235745AbhETKUm (ORCPT + 99 others); Thu, 20 May 2021 06:20:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:42316 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235243AbhETKKq (ORCPT ); Thu, 20 May 2021 06:10:46 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E9A7A6195F; Thu, 20 May 2021 09:43:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503789; bh=WnyYopMNt9BjFihbU75UhtCFU5TR8jhcjbt70Rxz7X8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WC4uR3G2fgsot3UsJpjVE21oFdPiAlCoODVK6zSsJ+NFQampfdXZihafNyGjXo2am Te3uXlFEh7ilFanpar2R/YX5z05v7qiyOWtvDlnXzeNdkcH/rcxmPlQTRjUd6LEhNz a9QgcO++Eg/UhnVRZggQRG40ttPk6MksCLXWkrzc= 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.19 381/425] iio: gyro: mpu3050: Fix reported temperature value Date: Thu, 20 May 2021 11:22:30 +0200 Message-Id: <20210520092143.917930163@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092131.308959589@linuxfoundation.org> References: <20210520092131.308959589@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;