Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp974870pxy; Thu, 22 Apr 2021 19:11:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqsJrXaBq+PfaS+bfia5QNSncG12GI0V83wgCp+DeQieeIWzmNMJGalCmK21vU9nX7umpN X-Received: by 2002:a17:907:3a98:: with SMTP id fh24mr1650083ejc.371.1619143897155; Thu, 22 Apr 2021 19:11:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619143897; cv=none; d=google.com; s=arc-20160816; b=HIHTgCLF17nYfCcNdFrRUqLAe6jq4Y1tFIPtMLYBnYrDOrHuOpdCmK453b7p1M3AaC lgq4ZeltUtuzdq1r5dK2Mbhn3dpuEk5+8L+m3hWlD3pgK+vVl32FYPbKN/Lzr9G6/c0/ OlnbaogHIZ9CojhuMHelnO6hCsym5zDR8TcHMxUQJxG5Bj8QDHB8rU9UdhuvRxawJtHl hMgxkcb1wxUzcs1jcL8zqq8OSHSUm5/CYMGAQpODFAEdZENpqryB4Ze/X/m3x+wolWzP Pm130miTSNrFQQfglr/k1I3EdOL57cFPq+zFY5ruefozzy3tLyrMVahdkBOtuHeqhzN3 QsLA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=Z1+bwtZ0MCH93R65mDiW9cH6H6AcURGrd4JDJqJEmgc=; b=qX3gyYMA2uSZb11WPEGgtCMKqn32e9N0DkhbPvyfIu3dbVIlJNNVEBmWJUaGHpF9Nc lMbuSEPJ6lygwA8G6K0nXDzixCTPj8GyFJ/ovCoNNaPat2UZxazPOmOClrAOYKIVn1Cx x/ERBTVXulDZ6mzJK9WoCXAuiwAxGl+R7TZ8R2kBowrMe2SSKFldAIbgAK3CA2nWN8ip 0Wnaoa3ff2H7vt//U/jULTmIpL+HHu37y0XNcn0cEhVexesKsnwIqRrZQ3VVHh5SUH0J Xvly7DVQbyAo/JU9TzfH1Eu9NQVatXoamDP57k+vO4/oU2jypraVdQU9kugl01lm4ToU hOwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bVYgDSer; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g4si3827079ejo.421.2021.04.22.19.11.12; Thu, 22 Apr 2021 19:11:37 -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=@gmail.com header.s=20161025 header.b=bVYgDSer; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236844AbhDWCKo (ORCPT + 99 others); Thu, 22 Apr 2021 22:10:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230367AbhDWCKn (ORCPT ); Thu, 22 Apr 2021 22:10:43 -0400 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38ED1C061574; Thu, 22 Apr 2021 19:10:07 -0700 (PDT) Received: by mail-lf1-x132.google.com with SMTP id x20so44889959lfu.6; Thu, 22 Apr 2021 19:10:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Z1+bwtZ0MCH93R65mDiW9cH6H6AcURGrd4JDJqJEmgc=; b=bVYgDSersnQPTNwFZ5U4L2TdNqQEwG/XxNxk5gsxa9RClV04efBLGHXii2ocYQvKye U4FlkFjuaX40TRqw+iGRxtM8d/MutlmMhcNaAFiAiF84T9+6MialivSIVIC/3rC6ga/h 7ODi7ox/VomAxQqGeRo4ohFLqVPV4jSmx/8SXbpvp/FzULat/fPoqcZ7t3SouiN7mcSy ZtXja95z0hYlmZyewkTLqfV6MO2P2ygFw0F0IDwvUDt0GTxggbHdtbE/kyo84zVHDoO+ lFJNMeoOFxXfEoKWInmCn6tGY32btFmQ2v2bJtb6YhCFwHagBPsHEUtU0L+Hjl23RNUJ owLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Z1+bwtZ0MCH93R65mDiW9cH6H6AcURGrd4JDJqJEmgc=; b=N023KWC2cn4X/IgfCJuj5A17prugEVzvlzE3ZY/spWN2+dVi6VL3cnMNj/OQlQ8zqb R4YzpYT7+S0xrWyapVAZbjHCn6EH76b5+Z3Y1SUNjODFyRxqz8vf1bPQeuqHVtOQ8aqp ChmlPPORIafe54AJUNF4BzqW2uSN8CSgPlmnNsLAS4ZA0egy8HzKyUy14UZ87lDvbW5T K9Djt682Xs4zDVexTpMEw1Cz8EK17rN1sF8bMvJsB6C0C3/vgEx/F9SvrrxyHE0CJHfo GziVHKetqbDbvrfZpkimf9LB0nRIOd7mVn/r7mjcGSr/KjmDPRejX/eMKOx8AKXe7WDE RHRQ== X-Gm-Message-State: AOAM532/Jm/SnupvGQKUYvQdvpfD3xR8pqk6DSYwY8wp0l8Ui/lmFxiL MzNyz/xBH7ajr0DsATFdakQYbsAEreA= X-Received: by 2002:ac2:4c85:: with SMTP id d5mr921854lfl.79.1619143805558; Thu, 22 Apr 2021 19:10:05 -0700 (PDT) Received: from localhost.localdomain (109-252-193-103.dynamic.spd-mgts.ru. [109.252.193.103]) by smtp.gmail.com with ESMTPSA id m19sm416489lfg.140.2021.04.22.19.10.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Apr 2021 19:10:05 -0700 (PDT) From: Dmitry Osipenko To: Linus Walleij , Jonathan Cameron , Lars-Peter Clausen , Andy Shevchenko , Maxim Schwalm , Svyatoslav Ryhel Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] iio: gyro: mpu3050: Fix reported temperature value Date: Fri, 23 Apr 2021 05:09:59 +0300 Message-Id: <20210423020959.5023-1-digetx@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- v3: - Improved comment in the code, saying that the temperature range corresponds to the "best fit straight line" range where temperature is reported reliably, i.e. in accordance to the linear equation. v2: - Replaced "signed 16bit integer" wording with "16-bit signed integer", replaced "Link" tag with the "Datasheet" and added "Fixes" tag as was suggested by Andy Shevchenko. - Added r-b from Andy Shevchenko and Linus Walleij. drivers/iio/gyro/mpu3050-core.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/iio/gyro/mpu3050-core.c b/drivers/iio/gyro/mpu3050-core.c index ac90be03332a..f17a93519535 100644 --- 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_dev *indio_dev, 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_dev *indio_dev, 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; -- 2.30.2