Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp378338pxj; Tue, 18 May 2021 05:34:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcXoxMD7KhmpmsCWeKJTjObbUdwy8CJO2hc4kKxpBlqR0USEkzJbMAomK+9RD3iKjZUCFg X-Received: by 2002:a17:906:cc9:: with SMTP id l9mr5834993ejh.454.1621341282236; Tue, 18 May 2021 05:34:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621341282; cv=none; d=google.com; s=arc-20160816; b=fzGRBLfzbhiGvZeeHNl3jikY9hJ9M25IgmJ6XUSZepaB9w5SGGGXYt/VlJnDwtieb1 Ql9xEToNLkKausuc5X+/k6eQd87lfAmvHjtYv/OwEDm45jDBQVfBU4K0UOtCZn8FgHDG zfEsacIwFeW6+RZAM6XIfHOVkzO/gUZ90JT8DXYa8MULxuQprF4gZlTzFS0M874S8QlR QFkfNasyDO6HHIgTk39P0HeVKThaPHSxtvTKowAt+fffE2UoLctPh2VQJtJglZDOJhzV 3dCBy5ij63HSTn1O+X5zWeOWRfthuzriuNqZY4kcTxPNaoyuSjsKh0Nzw/f8q8iN6YMq UuDw== 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=Iwp4XffeZJtBTa0c0YYN9onc9YTmZrdn+mbIzNlfZ8Jh7erTSrmE1e97XWC3usEYYm HX7AfUu+C8hOoDSt4k1dbUWL1B5aBOYKXMjO91i9QlwAYQ3WLsmGrG0Aq78UhS2T81nG HmfcD1W5XIhquO4Mc4S+a/bBPxYMq8p0Gm65a9MnIw6+q2ytSink/61Rkfk2FgMHw3Wx DJ8DBckedQub/EagBNU82fVgl8niKn0m8t2rseQ2Lrhc4l15RI03GCW3OAGaOu9+Mu3v cYqM+dRWsHWxg/iDF8jmNWVDVW3GTEoxOX0HeCDYH359bwrVTBNXGYGOxdXEHhIknd7D T09g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QZ82zazY; 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 bo12si6283128edb.267.2021.05.18.05.34.19; Tue, 18 May 2021 05:34:42 -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=QZ82zazY; 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 S244759AbhEQPc0 (ORCPT + 99 others); Mon, 17 May 2021 11:32:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:58612 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243576AbhEQPRi (ORCPT ); Mon, 17 May 2021 11:17:38 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6DEAF61C63; Mon, 17 May 2021 14:33:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621261991; bh=qx/PjOA/ZuU7CCjNcrmVLoFRUgUwwm36wgvT06uqZQk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QZ82zazY48b6eWlOjhJh6Zwg7jyOj4dBYhJqO7Ho2E+8JUXgAfdNclTyLfAQ5m15x OYeDASgM3BCTQT7k1G7opoS8Xhzusn+rIsGHTvyyW82mAPNJqvSAa6bkFJwItYcFnK JhisAIABZFFZB0a8rdI5aVwgnBU9a0jkIEaN+9N4= 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.4 121/141] iio: gyro: mpu3050: Fix reported temperature value Date: Mon, 17 May 2021 16:02:53 +0200 Message-Id: <20210517140246.870447276@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140242.729269392@linuxfoundation.org> References: <20210517140242.729269392@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;