Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp153552pxj; Mon, 17 May 2021 23:43:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxJl/i2dM1FSS1K44nICrm1dcXO9KicMkpMjxqwQJ3MYn7ozWW2rBLNhdfZTRfcy90cYAG X-Received: by 2002:a6b:8b89:: with SMTP id n131mr3053946iod.142.1621320187049; Mon, 17 May 2021 23:43:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621320187; cv=none; d=google.com; s=arc-20160816; b=0Uot3aDTIKsNEPuk1K63OlLUc8g708w9Y/rZL9qJKp4+7LwN/fiL2cLvh+dle0+eFd Dtn9N8PueOnuL3ohanuJSF69Ck3MzTxqQfmIqZgNf16IGOCZhUgZSHZmmPRBZfHJrc+4 CrVDrrVQFcmJD3dhHfGi+YerhAv2q7Khqppk4SFgfi7390CFm+EwxoxMdweEpflXS1tH A5gtDjxTLRwSve3N9xkrEKj0ro+/39zlCMq0MF7fFaUNSj5BUtmaCrQZwBQnBpcz4Eaa DXFapCFyFrZanf+DK4PwyQhJFQtaSLyaIW44/U1ZkHtR4fB5MfzZqjJpGsnzg37Ap7sE L53w== 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=D3kTTv47R1E5MwGdiJv1QSAOr+IlUQjrmN8N2hBK1lI=; b=t7j8aWUHQcdXHtHlRzoxxqVG93niXDTHen9cXK65Mw3XlKsp09HymE+iGSIiFjIcuQ 32qBLmRvOEFP9lVJ0hThCupYNL0CSdaPCckXmCnt9VzTs2tjGxXxKshi+YXKcCMXIWPI MX9/BNVheqNhpIRXIAE1OVegQadwGc6QdoAH+Z/WLgOKG0EL10cv8EeCaKhhdgRFdg8m TPtax07RPH+71CsamlHwMrObgwWGGUl7v3QsWg5814o2zuwOgduJKAR78Q4bbERCEuFJ Vzwj2iOkICTWWCwsXaz0KjzjWWgS0hi7JWtE/lEOr1g7yYw8BKfAWtNymbDgw5v1y1Ca pAsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gWf6S2LI; 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 w9si21453932ilv.15.2021.05.17.23.42.54; Mon, 17 May 2021 23:43:07 -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=gWf6S2LI; 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 S238095AbhEQOwY (ORCPT + 99 others); Mon, 17 May 2021 10:52:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:56944 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241310AbhEQOoX (ORCPT ); Mon, 17 May 2021 10:44:23 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 94BDB6195C; Mon, 17 May 2021 14:20:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621261245; bh=3d+IWm9c/O8sHKIwBHAISjeRkekeqprqysvOxnSGRLc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gWf6S2LIDzuee+4eAyHj8laqLbIQH83Q297ZlcHC3DjS6GJtHNdK8tlBB6S7g6JH6 irDylLiHG64xEa/YwXri7B/ShPm4jBradTaskPoePU+l5o8ZwvowfQq7r8YIveK3wa sOReRujaiNBCOxaDVS9MxxreMB7PB6+V8pOIKKws= 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.12 324/363] iio: gyro: mpu3050: Fix reported temperature value Date: Mon, 17 May 2021 16:03:10 +0200 Message-Id: <20210517140313.557493957@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@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 @@ -272,7 +272,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: @@ -329,7 +338,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;