Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp630670pxj; Tue, 18 May 2021 10:36:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLCoNMNEEZW9izlE1Ng4DbylLLKkcQA29Hf+bwqXOQNk0qGWUdal75OZVpbOEO6XglF16R X-Received: by 2002:a5d:81d5:: with SMTP id t21mr3214070iol.21.1621359359995; Tue, 18 May 2021 10:35:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621359359; cv=none; d=google.com; s=arc-20160816; b=Hjg+Hf2dbzpqxGaf2ov9kclRaL8Shm2GZCpSoh5M9YTFJVP5TftQy6RF8otGAsGzSI OD6ZErREaBnv4Pm92UpThEygxgf0qCKHOLQpqJVD6/dG9qcNNCzfzW8UmamOnab+Z5yJ i31kqHZOMkXb9Ar56OmkBOIKY1YohNEcshMMhUW0+aZAR2vGnSWz45FqPKAYPrnFndEv bTidCrC+E/5Bfnqlo/E6Nqq+KpDWImnwsXF8sjTxWUo4JhEL/wBpx1fvNIyPGKaT6P57 m4VAvBLg5zbTwDDZUbrbOo0vILSSEWhxihnVa8O3u0Pe9nQXVlaQmFHSFViBh8NoA/0D xK7A== 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=zFfLjRDsiZnL2xvCj8hVCbKPjgUocTPZqosNiabR9+U=; b=V/tc2tOYBsloAWQxJRm3p0rqAMzeQivVJXool8m4US+ip2kN0Xu5E/OE/jvQQRCWlC pKVmHX8iBCvW0qgSrGOu3+0HWUAF1KDCQfYngjsbksACUDlVNc0xZ/mHq2dvs/QcRCrB K6Exv3xKNHrhBob8XuyJqM8nntTcLuzJVb6hWd16vV7vlXUAL+RcfQUvpr/d2kfYy1TZ I+9UC9Evgh4xFqSEKyC84wokF5hKnaox6Avx/WnX2lJtyx7idTR0M2ClnRE0DYlqb6YI Cv8xSCJxNvVMU26lM4epAjwF1FPp0ZtAItSXPANnVov9WPFczsXQJ8lhY0CYczh5AeI2 mmDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=p5xrvXQb; 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 q8si25247298ilv.144.2021.05.18.10.35.04; Tue, 18 May 2021 10:35:59 -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=p5xrvXQb; 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 S1346755AbhEQQJt (ORCPT + 99 others); Mon, 17 May 2021 12:09:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:35758 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345058AbhEQPqR (ORCPT ); Mon, 17 May 2021 11:46:17 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3788861D35; Mon, 17 May 2021 14:44:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262663; bh=qx/PjOA/ZuU7CCjNcrmVLoFRUgUwwm36wgvT06uqZQk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p5xrvXQb31rtmv3mGQIecJx7jp+CCQGFaVloMktITOfMwqP8mF6j2wN42mPdNOO/m KvjKam5UG5qzFU683i2GX6WcgXx0O1uK2sbkQEWQbsnhg4/ZPnOGAVMy7TgHsnLlcD vgiKrZpjGAxXggjGp5zDgAPQjQVX+uQy6xPbD3Yc= 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 5.10 252/289] iio: gyro: mpu3050: Fix reported temperature value Date: Mon, 17 May 2021 16:02:57 +0200 Message-Id: <20210517140313.631285862@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140305.140529752@linuxfoundation.org> References: <20210517140305.140529752@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 @@ -271,7 +271,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: @@ -328,7 +337,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;