From patchwork Thu Nov 4 08:24:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gwendal Grignou X-Patchwork-Id: 12602717 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 761B9C433EF for ; Thu, 4 Nov 2021 08:24:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5C8A0610D0 for ; Thu, 4 Nov 2021 08:24:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230363AbhKDI1A (ORCPT ); Thu, 4 Nov 2021 04:27:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230084AbhKDI1A (ORCPT ); Thu, 4 Nov 2021 04:27:00 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 705F5C061714 for ; Thu, 4 Nov 2021 01:24:22 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id n85so621474pfd.10 for ; Thu, 04 Nov 2021 01:24:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Feq0h+YQ890t+lGo5iwncpQJOuAUT7hzdpdax9qSy+4=; b=N6rHksfRHzjuWEh27X1XAWR3aKYvrBtK1qMxXiKxTG9eCWdpc51FoJSfiRng6iA93o q0DIkv0Jdk4EvwxxAaB1XliWZbMg38K6BOFErlWZiz0XFh1q/60+xQvXQufOzVUefcqX 361IaPHsCRPDmDG6OYcvHGce4QSFNJbZ4C3do= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Feq0h+YQ890t+lGo5iwncpQJOuAUT7hzdpdax9qSy+4=; b=IbNk8RMrD/IEfP7B/DapcnS22IrI/rQJ9c8xQJfwLKOx0l4+KxXxJOCY0cidLMuXlY R2uBeH/Zl8rTCWBM7zWOz5izndZPlIGAL/jvOUJQW4jFWGN5QW4bVLELb9JUe4XWVUQE +ZJNUG4qmUGezAK7fumcjX/kLlsOkisEFsuWNOq7zYyZsD73Zzffh1mMkMmFf7YV3VyK xvFVkJhBhNkFp3548S5ctsgI8rbNzZtyw3TK01VSKlrzWHvf4jV17GrodFhg4Ju836YG GEQcd8da0LuLsayAjX13lgZn1rFsTceSlMBE3ub+zm9fsHOldCkRIRJsjn1NQABW29cY GQUA== X-Gm-Message-State: AOAM531So0ml3kA0LsxK67Hds+xFrATPv+OY4frm86ha+tzIu1mv0g7w Ve2aMLUkzWJQKY3HGxeDrPzPnw== X-Google-Smtp-Source: ABdhPJwYx0SKOT5r6073dAPNNYG4tUJmyhz3kLHXCGnDSaXoaTSw9ogUu3QnUd7bFi0gwkt6gk9iag== X-Received: by 2002:a63:8943:: with SMTP id v64mr22016990pgd.87.1636014261895; Thu, 04 Nov 2021 01:24:21 -0700 (PDT) Received: from localhost ([2620:15c:202:201:b129:c9aa:6634:6c4c]) by smtp.gmail.com with UTF8SMTPSA id p1sm4805837pfo.143.2021.11.04.01.24.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 04 Nov 2021 01:24:21 -0700 (PDT) From: Gwendal Grignou To: jic23@kernel.org, lars@metafoo.de Cc: andy.shevchenko@gmail.com, linux-iio@vger.kernel.org, Gwendal Grignou Subject: [PATCH v2 01/13] iio: bma220: Use scan_type when processing raw data Date: Thu, 4 Nov 2021 01:24:01 -0700 Message-Id: <20211104082413.3681212-2-gwendal@chromium.org> X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog In-Reply-To: <20211104082413.3681212-1-gwendal@chromium.org> References: <20211104082413.3681212-1-gwendal@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Use channel definition as root of trust and replace constant when reading elements directly using the raw sysfs attributes. Signed-off-by: Gwendal Grignou --- drivers/iio/accel/bma220_spi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/iio/accel/bma220_spi.c b/drivers/iio/accel/bma220_spi.c index bc4c626e454d3..74024d7ce5ac2 100644 --- a/drivers/iio/accel/bma220_spi.c +++ b/drivers/iio/accel/bma220_spi.c @@ -27,7 +27,6 @@ #define BMA220_CHIP_ID 0xDD #define BMA220_READ_MASK BIT(7) #define BMA220_RANGE_MASK GENMASK(1, 0) -#define BMA220_DATA_SHIFT 2 #define BMA220_SUSPEND_SLEEP 0xFF #define BMA220_SUSPEND_WAKE 0x00 @@ -45,7 +44,7 @@ .sign = 's', \ .realbits = 6, \ .storagebits = 8, \ - .shift = BMA220_DATA_SHIFT, \ + .shift = 2, \ .endianness = IIO_CPU, \ }, \ } @@ -125,7 +124,8 @@ static int bma220_read_raw(struct iio_dev *indio_dev, ret = bma220_read_reg(data->spi_device, chan->address); if (ret < 0) return -EINVAL; - *val = sign_extend32(ret >> BMA220_DATA_SHIFT, 5); + *val = sign_extend32(ret >> chan->scan_type.shift, + chan->scan_type.realbits - 1); return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: ret = bma220_read_reg(data->spi_device, BMA220_REG_RANGE); From patchwork Thu Nov 4 08:24:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gwendal Grignou X-Patchwork-Id: 12602719 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A14EC433FE for ; Thu, 4 Nov 2021 08:24:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 01C51610D0 for ; Thu, 4 Nov 2021 08:24:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230335AbhKDI1B (ORCPT ); Thu, 4 Nov 2021 04:27:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230084AbhKDI1B (ORCPT ); Thu, 4 Nov 2021 04:27:01 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDF33C061714 for ; Thu, 4 Nov 2021 01:24:23 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id u33so5122019pfg.8 for ; Thu, 04 Nov 2021 01:24:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bh12gTIx46vyaIw8y+v4iTIFGiXlnzf9QVNIRa80mj8=; b=W2JNMqpz6m9aCOtX+sl0dQ+5C97ljhFYmINFYx866Uk8H1mzzcno9zUmmD5BaalMkD /Y3ybrWE2TGsuK6T9mDSHpY4ES9Hvwbv9VKHkupxgEwYBxkKhQCsOUn6dq2wjw23rLQm 1/qq3drkWoPeSzzfh4We7H4/9wKHBbw7fJfW0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bh12gTIx46vyaIw8y+v4iTIFGiXlnzf9QVNIRa80mj8=; b=wzA/MkyLGmIpq9eEX12rF99xRvUwCwBtrkmRW6IMHlSVIrHi7aUT4OXqI2pgv7UqqS FZEb1lo8VxNuuQh0aMO8jobbSXVWE5Ggjq+GfQs39GtQySg+OC0rpmaqiMjnbuXI/rWS kphbrT1cO6YQJ+W07FoLV6QxFcjXDHKGyPcYgHKrqmJsMH6X1l1rXXWlV5E8ywcb7YnE 8vm/XJmMi8b1Kfm6RsJqlPEn9WsfKoZUpKc1erg9MuiX2539N6hymQ2xYAsUzpEgxz/b A7VBb0vIccQ5a/tscdNrxlqHiRbwGx3uATGK0VTBC8vXeoAKdjWI21fa+V9Jr62PHcFI wt+Q== X-Gm-Message-State: AOAM5311hIaOmdHc55EOruB8M+62m+MwI59FPaQKYdnHcpIZ2L4Tbomz SlV6MiklbUSjHQFZNc0hN7ycQw== X-Google-Smtp-Source: ABdhPJz63x2jRIxS+l+dcPUxdVnj4vgnWQVLTjHEy9y+qsf5FyvEKrNbqdZMkmRssC0+GMMWFf9Z7w== X-Received: by 2002:a63:8a43:: with SMTP id y64mr21723482pgd.113.1636014263326; Thu, 04 Nov 2021 01:24:23 -0700 (PDT) Received: from localhost ([2620:15c:202:201:b129:c9aa:6634:6c4c]) by smtp.gmail.com with UTF8SMTPSA id q9sm4777423pfj.88.2021.11.04.01.24.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 04 Nov 2021 01:24:23 -0700 (PDT) From: Gwendal Grignou To: jic23@kernel.org, lars@metafoo.de Cc: andy.shevchenko@gmail.com, linux-iio@vger.kernel.org, Gwendal Grignou Subject: [PATCH v2 02/13] iio: kxcjk-1013: Use scan_type when processing raw data Date: Thu, 4 Nov 2021 01:24:02 -0700 Message-Id: <20211104082413.3681212-3-gwendal@chromium.org> X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog In-Reply-To: <20211104082413.3681212-1-gwendal@chromium.org> References: <20211104082413.3681212-1-gwendal@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Use channel definition as root of trust and replace constant when reading elements directly using the raw sysfs attributes. Signed-off-by: Gwendal Grignou --- drivers/iio/accel/kxcjk-1013.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/iio/accel/kxcjk-1013.c b/drivers/iio/accel/kxcjk-1013.c index a51fdd3c9b5b5..88cf0c276893a 100644 --- a/drivers/iio/accel/kxcjk-1013.c +++ b/drivers/iio/accel/kxcjk-1013.c @@ -927,7 +927,8 @@ static int kxcjk1013_read_raw(struct iio_dev *indio_dev, mutex_unlock(&data->mutex); return ret; } - *val = sign_extend32(ret >> 4, 11); + *val = sign_extend32(ret >> chan->scan_type.shift, + chan->scan_type.realbits - 1); ret = kxcjk1013_set_power_state(data, false); } mutex_unlock(&data->mutex); From patchwork Thu Nov 4 08:24:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gwendal Grignou X-Patchwork-Id: 12602721 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7AA69C4332F for ; Thu, 4 Nov 2021 08:24:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 600A96109F for ; Thu, 4 Nov 2021 08:24:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230401AbhKDI1D (ORCPT ); Thu, 4 Nov 2021 04:27:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230084AbhKDI1C (ORCPT ); Thu, 4 Nov 2021 04:27:02 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36A61C061714 for ; Thu, 4 Nov 2021 01:24:25 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id f8so5944615plo.12 for ; Thu, 04 Nov 2021 01:24:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JdZv0B1+U+lvfR+/5ZB+jRAodarD3Qdo87VQjmtnu2Y=; b=kJXE7VOjLjc+5XaGt4iJG/udNSxsKr9xq1tbBobyntqFVqjrq9tS/rJ/kkHx8T+ovG V1W9PYLybi+3VGz4KNhYSO+9SQttW6qGaoZNmeRJyjAEbt2dadUpqVr9M1iLpXQa/EQR YPfPClMryiSNEujRRkbnVAKUCg5SyVO7m8PDY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JdZv0B1+U+lvfR+/5ZB+jRAodarD3Qdo87VQjmtnu2Y=; b=wuoIcRZpqYLKUnMI2l9EoSOs4uKuGPjGfomi/Ebiik7THj+WRI6BTxrdin5TAIOzyB VTTHK2dGK9e9PkZpEq7Jk0a5i/85Kj7FVURhjSJnqXCCeG0TyvdygoX1WFhR1alyjiGj CbyyKdXF0CX/UWq95fzS8Gq6jzfmU+1eoNPhQxln8fZXqkVARKQF0BiZyBe1PItFopxJ ZlWwLoXsIbaeRq8v191zMwjcqgWGR9WKwiqlE9HxKDRnaxKsVffVUDtgEZLYPfAySgOw 3fN/dHjEiFvJJn1ZMpN5DeSyZT8ocU3SosAzWVWYU9zBIMNKCUuRGVV6g9cKh9tM0ayx +zPg== X-Gm-Message-State: AOAM530M1XSwo45kIUXoutShJeyCZHzgG0+Ihic8KNlHO7YSXUDqADJd OSKAq1sF3AHbHC8fl1+0yrts8A== X-Google-Smtp-Source: ABdhPJxc9LwqmSpXRDHwWTh5FETrABV6STr1qei6dOLHQxAlDpk9PBWm6LPmiej/fEqrMFTjKFq0sQ== X-Received: by 2002:a17:90b:3848:: with SMTP id nl8mr717047pjb.221.1636014264720; Thu, 04 Nov 2021 01:24:24 -0700 (PDT) Received: from localhost ([2620:15c:202:201:b129:c9aa:6634:6c4c]) by smtp.gmail.com with UTF8SMTPSA id e8sm4597895pfn.45.2021.11.04.01.24.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 04 Nov 2021 01:24:24 -0700 (PDT) From: Gwendal Grignou To: jic23@kernel.org, lars@metafoo.de Cc: andy.shevchenko@gmail.com, linux-iio@vger.kernel.org, Gwendal Grignou Subject: [PATCH v2 03/13] iio: mma7455: Use scan_type when processing raw data Date: Thu, 4 Nov 2021 01:24:03 -0700 Message-Id: <20211104082413.3681212-4-gwendal@chromium.org> X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog In-Reply-To: <20211104082413.3681212-1-gwendal@chromium.org> References: <20211104082413.3681212-1-gwendal@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Use channel definition as root of trust and replace constant when reading elements directly using the raw sysfs attributes. Signed-off-by: Gwendal Grignou --- drivers/iio/accel/mma7455_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/iio/accel/mma7455_core.c b/drivers/iio/accel/mma7455_core.c index 777c6c384b09e..e6739ba74edfa 100644 --- a/drivers/iio/accel/mma7455_core.c +++ b/drivers/iio/accel/mma7455_core.c @@ -134,7 +134,8 @@ static int mma7455_read_raw(struct iio_dev *indio_dev, if (ret) return ret; - *val = sign_extend32(le16_to_cpu(data), 9); + *val = sign_extend32(le16_to_cpu(data), + chan->scan_type.realbits - 1); return IIO_VAL_INT; From patchwork Thu Nov 4 08:24:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gwendal Grignou X-Patchwork-Id: 12602723 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0EFC2C433F5 for ; Thu, 4 Nov 2021 08:24:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ECC61610D0 for ; Thu, 4 Nov 2021 08:24:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230365AbhKDI1E (ORCPT ); Thu, 4 Nov 2021 04:27:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230084AbhKDI1E (ORCPT ); Thu, 4 Nov 2021 04:27:04 -0400 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A952FC061714 for ; Thu, 4 Nov 2021 01:24:26 -0700 (PDT) Received: by mail-pg1-x536.google.com with SMTP id r28so4825975pga.0 for ; Thu, 04 Nov 2021 01:24:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=m2NF2iQiTW0SCiPPmUKQtfO2X1ePHPLUOi6iTgYkNyg=; b=eO11pi8A2i4HirN/r4G19fEw8OVgBkWTMf3Na2L5rGzzynwsKdpkNZt+ki08wgW8gd KvGbKjipvrGKZdNMNPhvSn6pux4oKYi2/o2GUrZ2MX3g5Wkggc4MvscEpPpVvVy1vM4M qSpSn18CdwGFi0P4NiASKfT2lh9uYovq9HBrk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=m2NF2iQiTW0SCiPPmUKQtfO2X1ePHPLUOi6iTgYkNyg=; b=Xmb+E1RQ/wsAXhP8Ny8vRWBJYJxSGo/nsRKW6APP2Um52qbBaCdGRsoVgGx9yAS3LT R016dXRQiqiWi6fAoCvglxdkTCCaAGtZG2aNCIfkACf4uINHs3vXKxkIn+WON26mjIPn nZ1s85EGgL5Ww+ZzLwJIXc4srEB0PcBUiIWJcxd3KGhJaT+UBrmhigAsh7NS15kyZnOh sy6M2twvkLeoma1Q+TnRJ+oCoz0+yyw8qALjN430R8gsgGWY4QmMPupkU9NKk8buCcw5 058CZrLZmU7gPd6apsUyihgU4ixbLoBwl3vb09zxSlWpT/KeW+h5nMHxev2PivkSd7Df 8m1w== X-Gm-Message-State: AOAM532zVZoYyFSxUQCNXWcAY7FFFz37qrLLNTW7b4OgaBBtlqxUhFo0 JsIvwFZU9z7HClahCGfOTU6+ti/T+i1Akg== X-Google-Smtp-Source: ABdhPJz966mbrlX5Y0szuNRWypFhvtWDmmQYsT67iwta61FhQy6z5gFKGYKcp5/7A0tUwJDkdD8lmg== X-Received: by 2002:a63:3d8f:: with SMTP id k137mr38062282pga.21.1636014266235; Thu, 04 Nov 2021 01:24:26 -0700 (PDT) Received: from localhost ([2620:15c:202:201:b129:c9aa:6634:6c4c]) by smtp.gmail.com with UTF8SMTPSA id ng9sm7024811pjb.4.2021.11.04.01.24.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 04 Nov 2021 01:24:25 -0700 (PDT) From: Gwendal Grignou To: jic23@kernel.org, lars@metafoo.de Cc: andy.shevchenko@gmail.com, linux-iio@vger.kernel.org, Gwendal Grignou Subject: [PATCH v2 04/13] iio: sca3000: Use scan_type when processing raw data Date: Thu, 4 Nov 2021 01:24:04 -0700 Message-Id: <20211104082413.3681212-5-gwendal@chromium.org> X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog In-Reply-To: <20211104082413.3681212-1-gwendal@chromium.org> References: <20211104082413.3681212-1-gwendal@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Use channel definition as root of trust and replace constant when reading elements directly using the raw sysfs attributes. Signed-off-by: Gwendal Grignou --- drivers/iio/accel/sca3000.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/iio/accel/sca3000.c b/drivers/iio/accel/sca3000.c index c6b75308148aa..43ecacbdc95ae 100644 --- a/drivers/iio/accel/sca3000.c +++ b/drivers/iio/accel/sca3000.c @@ -534,6 +534,13 @@ static const struct iio_chan_spec sca3000_channels_with_temp[] = { BIT(IIO_CHAN_INFO_OFFSET), /* No buffer support */ .scan_index = -1, + .scan_type = { + .sign = 'u', + .realbits = 9, + .storagebits = 16, + .shift = 5, + .endianness = IIO_BE, + }, }, { .type = IIO_ACCEL, @@ -730,8 +737,9 @@ static int sca3000_read_raw(struct iio_dev *indio_dev, mutex_unlock(&st->lock); return ret; } - *val = (be16_to_cpup((__be16 *)st->rx) >> 3) & 0x1FFF; - *val = sign_extend32(*val, 12); + *val = sign_extend32(be16_to_cpup((__be16 *)st->rx) >> + chan->scan_type.shift, + chan->scan_type.realbits - 1); } else { /* get the temperature when available */ ret = sca3000_read_data_short(st, @@ -741,8 +749,9 @@ static int sca3000_read_raw(struct iio_dev *indio_dev, mutex_unlock(&st->lock); return ret; } - *val = ((st->rx[0] & 0x3F) << 3) | - ((st->rx[1] & 0xE0) >> 5); + *val = (be16_to_cpup((__be16 *)st->rx) >> + chan->scan_type.shift) & + GENMASK(chan->scan_type.realbits - 1, 0); } mutex_unlock(&st->lock); return IIO_VAL_INT; From patchwork Thu Nov 4 08:24:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gwendal Grignou X-Patchwork-Id: 12602725 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77C11C433EF for ; Thu, 4 Nov 2021 08:24:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5AFA56109F for ; Thu, 4 Nov 2021 08:24:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230397AbhKDI1G (ORCPT ); Thu, 4 Nov 2021 04:27:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230084AbhKDI1F (ORCPT ); Thu, 4 Nov 2021 04:27:05 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61A0AC061714 for ; Thu, 4 Nov 2021 01:24:28 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id y1so5954034plk.10 for ; Thu, 04 Nov 2021 01:24:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/9SRX06i76D4HI1nkgfBuD3aMtpTGwkvvOZTDSanavI=; b=cEfrj58Pl0oapVNps6POcHoO4Z5DpMHypL62gbWxHtg6FMRFvcfhZtzhRU9KgOv1XF 6H8hzieG13aauBPFsxLNvyUHgFzD3bZQRcL9iF8oNDcSqLJ0syOhvPKnEBRp8BGzF0dg Lf7UadaYTX8o27FrF756sxpDa+ZF/TVKM8HEQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/9SRX06i76D4HI1nkgfBuD3aMtpTGwkvvOZTDSanavI=; b=MSqLF2iO2WnSh4H9XY4PUhiUd+DDXCbbfougOlCoc0O3qvG0I2OADTDH1RTH44NWC5 AHwG5MzQFhZR3NUiBDXmJidYDyQhf+r4V+gT2jnvb2jJVDozHVT+w3OMx1XiY3G73Pgt uPf6/23B8VuoXKtUekuUXRU4bSdsmBLXVOQH6DAAn6qhWTvgB/sSnkq9eBrdLRjw0JCb yRTC5uOR9PvsjakgbiiKlz7zHAWMRaqcBHs/ASaAkWw+u3n7JRLr2KY9+kt85hJWw51g 617v7d4wePZ+aYnDIeLn3QPBuATHypzWYwAWxW9ke06AWlFEBBP0luy70U5fdazgfAlN vL6Q== X-Gm-Message-State: AOAM531YCg5lfIPIgMJ3DA0Yghw+sX94VzMuElcmEs2OBP+YkeSj+SL9 1DJR1c2enySXmM9xwnHy3JC/Fg== X-Google-Smtp-Source: ABdhPJwdKSEj8gjIES/Pbf2sS2fGGEJ4Q/LzP5gzYP0tZ9VMfavgXmf3ld4bqj9lg9OG3EXrLTFEBQ== X-Received: by 2002:a17:903:32c2:b0:141:eed4:ec0a with SMTP id i2-20020a17090332c200b00141eed4ec0amr23066123plr.74.1636014267928; Thu, 04 Nov 2021 01:24:27 -0700 (PDT) Received: from localhost ([2620:15c:202:201:b129:c9aa:6634:6c4c]) by smtp.gmail.com with UTF8SMTPSA id c9sm3457251pgq.58.2021.11.04.01.24.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 04 Nov 2021 01:24:27 -0700 (PDT) From: Gwendal Grignou To: jic23@kernel.org, lars@metafoo.de Cc: andy.shevchenko@gmail.com, linux-iio@vger.kernel.org, Gwendal Grignou Subject: [PATCH v2 05/13] iio: stk8312: Use scan_type when processing raw data Date: Thu, 4 Nov 2021 01:24:05 -0700 Message-Id: <20211104082413.3681212-6-gwendal@chromium.org> X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog In-Reply-To: <20211104082413.3681212-1-gwendal@chromium.org> References: <20211104082413.3681212-1-gwendal@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Use channel definition as root of trust and replace constant when reading elements directly using the raw sysfs attributes. Signed-off-by: Gwendal Grignou --- drivers/iio/accel/stk8312.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/accel/stk8312.c b/drivers/iio/accel/stk8312.c index 43c621d0f11e4..de0cdf8c1f94c 100644 --- a/drivers/iio/accel/stk8312.c +++ b/drivers/iio/accel/stk8312.c @@ -355,7 +355,7 @@ static int stk8312_read_raw(struct iio_dev *indio_dev, mutex_unlock(&data->lock); return ret; } - *val = sign_extend32(ret, 7); + *val = sign_extend32(ret, chan->scan_type.realbits - 1); ret = stk8312_set_mode(data, data->mode & (~STK8312_MODE_ACTIVE)); mutex_unlock(&data->lock); From patchwork Thu Nov 4 08:24:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gwendal Grignou X-Patchwork-Id: 12602727 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC65BC433F5 for ; Thu, 4 Nov 2021 08:24:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D4B48610D0 for ; Thu, 4 Nov 2021 08:24:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230084AbhKDI1H (ORCPT ); Thu, 4 Nov 2021 04:27:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230404AbhKDI1H (ORCPT ); Thu, 4 Nov 2021 04:27:07 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E67EAC061714 for ; Thu, 4 Nov 2021 01:24:29 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id k4so5980209plx.8 for ; Thu, 04 Nov 2021 01:24:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sfOVCvVYnXf5Qn6Otdy07nqhnP7h5NZHYQtwyvdfb7A=; b=Rd5gMOrl7v4l2SaqlB65B6t+vB65mfcJyr0jERqpPJgliRwbBMHxERTdz7f6cocwtE +xNpzQ10Pe60QjRVi+cc1zeN5ZHKMnZmBSHmYSUcXNA66bfFftZUajcDJ1N50NqCnxm0 xVsITl/OGcctT1rie4S4inUOAa7fbmmjfbT74= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sfOVCvVYnXf5Qn6Otdy07nqhnP7h5NZHYQtwyvdfb7A=; b=AWgySpWEgOz/0/fHpO8G5RLIyLYEnM+/7UYOjtCoGp6ceXApq4VO0JV/XUbYw1Qzs+ TOxPSxWmDKopBrsdDR9MIs+TzwfKsyspf0dxH8snxmLatutCZ4zkY5ovpURtZ1hl5GIY tCnXQMyCSPuHFwSns9fJ2UtWC/LOac82oQh6reh1gKAJgR1C2CEPXbVFvpOQ6On5SEDH wo9lxWOc0BOHe3gqs+YOsszo2UQrfEoYqop5Udl7V3H3Mp0vqmE2QciIfyYpj5v5TWZF pXL9oqZJR7e3ZN+1Piv4/4mM0U4/baRKgKQHPAb4QayDkNT5IClYKGERNhwgC+D13Xef 6UEg== X-Gm-Message-State: AOAM5330/LFmJbAFLKKDC8iMIL8ZQT2NL6FhxEopd1XuckxjRsUBZAAk e+12FoeuA7QlpwcF2T+t307OKj5nhLFy2A== X-Google-Smtp-Source: ABdhPJzbG5tE9QT0nAp7EYcXSqpIlUlK5fRIj1udr6ZmuKH0oSDRggqWLVlSMOMVT7sXYKU1fCl/oA== X-Received: by 2002:a17:902:d711:b0:141:efff:9f3 with SMTP id w17-20020a170902d71100b00141efff09f3mr22711064ply.48.1636014269493; Thu, 04 Nov 2021 01:24:29 -0700 (PDT) Received: from localhost ([2620:15c:202:201:b129:c9aa:6634:6c4c]) by smtp.gmail.com with UTF8SMTPSA id w13sm6897039pjc.29.2021.11.04.01.24.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 04 Nov 2021 01:24:29 -0700 (PDT) From: Gwendal Grignou To: jic23@kernel.org, lars@metafoo.de Cc: andy.shevchenko@gmail.com, linux-iio@vger.kernel.org, Gwendal Grignou Subject: [PATCH v2 06/13] iio: stk8ba50: Use scan_type when processing raw data Date: Thu, 4 Nov 2021 01:24:06 -0700 Message-Id: <20211104082413.3681212-7-gwendal@chromium.org> X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog In-Reply-To: <20211104082413.3681212-1-gwendal@chromium.org> References: <20211104082413.3681212-1-gwendal@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Use channel definition as root of trust and replace constant when reading elements directly using the raw sysfs attributes. Signed-off-by: Gwendal Grignou --- drivers/iio/accel/stk8ba50.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/iio/accel/stk8ba50.c b/drivers/iio/accel/stk8ba50.c index e137a34b5c9a9..517c57ed9e949 100644 --- a/drivers/iio/accel/stk8ba50.c +++ b/drivers/iio/accel/stk8ba50.c @@ -227,7 +227,8 @@ static int stk8ba50_read_raw(struct iio_dev *indio_dev, mutex_unlock(&data->lock); return -EINVAL; } - *val = sign_extend32(ret >> STK8BA50_DATA_SHIFT, 9); + *val = sign_extend32(ret >> chan->scan_type.shift, + chan->scan_type.realbits - 1); stk8ba50_set_power(data, STK8BA50_MODE_SUSPEND); mutex_unlock(&data->lock); return IIO_VAL_INT; From patchwork Thu Nov 4 08:24:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gwendal Grignou X-Patchwork-Id: 12602729 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 448D7C433EF for ; Thu, 4 Nov 2021 08:24:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2E3DE60240 for ; Thu, 4 Nov 2021 08:24:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230410AbhKDI1J (ORCPT ); Thu, 4 Nov 2021 04:27:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230404AbhKDI1I (ORCPT ); Thu, 4 Nov 2021 04:27:08 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35E4DC061714 for ; Thu, 4 Nov 2021 01:24:31 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id n8so6007919plf.4 for ; Thu, 04 Nov 2021 01:24:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=idY4qdu4LGBcB8a0Px2nHDOUUuSlRmvZ25ss85X1YpI=; b=ShQFTjnAKSHGiBvAKzbOKDi7ud0H3QDxCHSYUMSs+71tyyfKOt0u1e8+3q9YWBwt6R EqzPrFQCWnUDstK83rmExSpxNx+SPjhxF2X9Zw/8zF2F3tN1MjXiFPLvC7rF34VLCoA/ 292i8gDxc/f4G/Kwnbs4FpOnEdKSuaabAUBsg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=idY4qdu4LGBcB8a0Px2nHDOUUuSlRmvZ25ss85X1YpI=; b=fDHgB0fG9Hoor7pz4pdHcNN+KsdZXtcDNoY87r9HgXJcJVBpqzReGiT4WBE/9w74D1 l0Uu0O2PgyLhp274KQjecaqppZDt/BzOapl8A4DQi53oLcelgIq2m6x0kEv8+sYqlXga hPgkUsKincFe4S4Tj7QDajlajQ9y9Qp2QDm+3tiMCY1zr7BJZ/QTYZsPOqrKIGtCyB0k YEf22lBOPReaSHZOk7/iObBMoBqUWMVDtxMrtW2wbsuNDIt1WeEZnS8CAcXAx1RMgeM7 lwOC6qP/dyAyAoYRqxpvRdlq4UWwPNJMWZ874mOcBFAHT3CikJfmghN9FxDoZ4aWJlbq lt2w== X-Gm-Message-State: AOAM531ycE9TCMa4JJ8WWK9ROWUlY8U1F72EJVw3rn7u6cwmluMbHp2d im5TNSeViqK92wQ60/niOKym1g== X-Google-Smtp-Source: ABdhPJwqXnGdBfDO9rD3t1ekzzZU6bTD7aoL50wj/yf1+y13SVU7jE6FBGggzw/OhuTfmZ30bPqPaA== X-Received: by 2002:a17:90a:408f:: with SMTP id l15mr20534011pjg.34.1636014270802; Thu, 04 Nov 2021 01:24:30 -0700 (PDT) Received: from localhost ([2620:15c:202:201:b129:c9aa:6634:6c4c]) by smtp.gmail.com with UTF8SMTPSA id g37sm3450693pgg.89.2021.11.04.01.24.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 04 Nov 2021 01:24:30 -0700 (PDT) From: Gwendal Grignou To: jic23@kernel.org, lars@metafoo.de Cc: andy.shevchenko@gmail.com, linux-iio@vger.kernel.org, Gwendal Grignou Subject: [PATCH v2 07/13] iio: ad7266: Use scan_type when processing raw data Date: Thu, 4 Nov 2021 01:24:07 -0700 Message-Id: <20211104082413.3681212-8-gwendal@chromium.org> X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog In-Reply-To: <20211104082413.3681212-1-gwendal@chromium.org> References: <20211104082413.3681212-1-gwendal@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Use channel definition as root of trust and replace constant when reading elements directly using the raw sysfs attributes. Signed-off-by: Gwendal Grignou --- drivers/iio/adc/ad7266.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/iio/adc/ad7266.c b/drivers/iio/adc/ad7266.c index a8ec3efd659ed..1d345d66742d8 100644 --- a/drivers/iio/adc/ad7266.c +++ b/drivers/iio/adc/ad7266.c @@ -159,7 +159,8 @@ static int ad7266_read_raw(struct iio_dev *indio_dev, *val = (*val >> 2) & 0xfff; if (chan->scan_type.sign == 's') - *val = sign_extend32(*val, 11); + *val = sign_extend32(*val, + chan->scan_type.realbits - 1); return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: From patchwork Thu Nov 4 08:24:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gwendal Grignou X-Patchwork-Id: 12602731 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C136C433FE for ; Thu, 4 Nov 2021 08:24:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 82E38610D0 for ; Thu, 4 Nov 2021 08:24:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230451AbhKDI1K (ORCPT ); Thu, 4 Nov 2021 04:27:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230445AbhKDI1K (ORCPT ); Thu, 4 Nov 2021 04:27:10 -0400 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 863C0C06127A for ; Thu, 4 Nov 2021 01:24:32 -0700 (PDT) Received: by mail-pg1-x52a.google.com with SMTP id s136so4813447pgs.4 for ; Thu, 04 Nov 2021 01:24:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ji6JqzNTrcD6aFrkDMF+a46Vd/1TQkWuUyVLT3OJmZ0=; b=h4bMu91NVku/k8RN9sOVqCcGi+SCr5N5sxM7Gfcaag4dkHSdp+SdkEP0UAPg5ZCjw2 XtE1WQpd9BDa1Yza2IVFREi3jTOwEwMzHYPZ9UxkloU2aRNRXbCOOKgisNKqi0SsUeyt yvMAFSXV/Okf8AsJJoBOnNGwel8J0twbARV8k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ji6JqzNTrcD6aFrkDMF+a46Vd/1TQkWuUyVLT3OJmZ0=; b=L8tGOuYaEduycM7sUeVcae3R/Si9K5N4QH3iWgyMJRKRB8f/4AvZfpgABVNIJdcnFn diLaj3YHvQ0sfJqZ0cKuCafDqIADRlCy43CQqB7gn1N8yq1Na+aGjm++HmVcZwRQbI39 iMoTBHthepJKP61XRF1co1eZDW13iFeDT+gJXT5dAdztrXhloNpkOBO084kz48wg/J2w g2tpyESugcKKZCzNqiCrs9ro3Wsmso/90pjlPoDWfURirQsUQE6Gb3y5N7OJTQ70bO7g q+fFhr34CPWE9uKl/yD+7TGiKrbSa9k1QGOIaqEWVKWRvzRI0ECuEn/6coJoKPf4RSd+ eknQ== X-Gm-Message-State: AOAM533GTieH14xHkuTtdCUSrOODHv4yvwoL41Wj7RJUTF1p9xe6cUZX 6+d0xxzyxXvKNhR/NkW0C/jSqPfhJv+uwg== X-Google-Smtp-Source: ABdhPJxacx36coGhhnpKfK8qMCUpPL2+nplUhikKP8ZVymm3Dxdz/VLcwrUh4ySugO6HI7YflMdd8A== X-Received: by 2002:a63:1441:: with SMTP id 1mr18073840pgu.66.1636014272061; Thu, 04 Nov 2021 01:24:32 -0700 (PDT) Received: from localhost ([2620:15c:202:201:b129:c9aa:6634:6c4c]) by smtp.gmail.com with UTF8SMTPSA id k6sm4577852pfu.48.2021.11.04.01.24.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 04 Nov 2021 01:24:31 -0700 (PDT) From: Gwendal Grignou To: jic23@kernel.org, lars@metafoo.de Cc: andy.shevchenko@gmail.com, linux-iio@vger.kernel.org, Gwendal Grignou Subject: [PATCH v2 08/13] iio: at91-sama5d2: Use scan_type when processing raw data Date: Thu, 4 Nov 2021 01:24:08 -0700 Message-Id: <20211104082413.3681212-9-gwendal@chromium.org> X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog In-Reply-To: <20211104082413.3681212-1-gwendal@chromium.org> References: <20211104082413.3681212-1-gwendal@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Use channel definition as root of trust and replace constant when reading elements directly using the raw sysfs attributes. Signed-off-by: Gwendal Grignou Reviewed-by: Eugen Hristev --- drivers/iio/adc/at91-sama5d2_adc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/iio/adc/at91-sama5d2_adc.c b/drivers/iio/adc/at91-sama5d2_adc.c index 4c922ef634f8e..92a57cf10fba4 100644 --- a/drivers/iio/adc/at91-sama5d2_adc.c +++ b/drivers/iio/adc/at91-sama5d2_adc.c @@ -1586,7 +1586,8 @@ static int at91_adc_read_info_raw(struct iio_dev *indio_dev, *val = st->conversion_value; ret = at91_adc_adjust_val_osr(st, val); if (chan->scan_type.sign == 's') - *val = sign_extend32(*val, 11); + *val = sign_extend32(*val, + chan->scan_type.realbits - 1); st->conversion_done = false; } From patchwork Thu Nov 4 08:24:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gwendal Grignou X-Patchwork-Id: 12602733 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78413C433FE for ; Thu, 4 Nov 2021 08:24:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 60A86611C3 for ; Thu, 4 Nov 2021 08:24:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230494AbhKDI1M (ORCPT ); Thu, 4 Nov 2021 04:27:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230478AbhKDI1L (ORCPT ); Thu, 4 Nov 2021 04:27:11 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C4EEC061714 for ; Thu, 4 Nov 2021 01:24:34 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id g18so343927pfk.5 for ; Thu, 04 Nov 2021 01:24:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lc8uPyEyzTKLweKdBJnTSpt9yRwuF15SqjA0MLF4iFg=; b=Vx0H17Sh9q0td9Jy4ofevsf4Mj5MEhDGTLbCEUAVX5duv6VDEA9i68gPyfwAuhWdJ8 jVyo2R92ZBu/ZiONrVcn3H8RqhYxuy06+Rz8lClp3MkPAENeUzfmY1jtQd1AeOLurCgG izxiHrU4hGB5SgX6sX9zcwMNtGGIxMRK0SFTU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lc8uPyEyzTKLweKdBJnTSpt9yRwuF15SqjA0MLF4iFg=; b=l8aVEdChLEksPJoeq1OA/0i6BD/2Jk5gACnIPyOjdCHqd2mXxinL/J0MFOoXhfgY2N XxaNeGSxGrSQGFdESd6tHCMWHSPQ1Q1su00PfrgEHAaeKAMxfYvNZnplGLT9F2FPV2LF gp1JpkXRxeCCeVAVdDqCgRuemvW24eOVArM+Y9mPdm/KQ9rPBsYdYS/9we7zdHjl4kWi gUZ0usERnJmmXWrtvcsyqL+0/lPGERnn3tXKZgSn2VinhiK8Gzr8UiaA6yYufW7aUq/d ZtPf7BeR3y3gZW1n1LcQznLzyAUIsU75H9ONPCtVCIMJPBnfqE5KY75OicniXiCZIzIk fEqA== X-Gm-Message-State: AOAM5304WcfVNskmSPhaFhP12osXP1SBFi9JLLtxlbUyWxZefW8JyomK RmuxicJDyOn2GcelEheFqKu5iQ== X-Google-Smtp-Source: ABdhPJzp58s7+oItIKw5Ejd+TF6/4zMxlAhKAGVBdu3DMF+hgwXn4kPHevj2jBiq/0iJjbrFdf+dgQ== X-Received: by 2002:a63:874a:: with SMTP id i71mr24106957pge.81.1636014273552; Thu, 04 Nov 2021 01:24:33 -0700 (PDT) Received: from localhost ([2620:15c:202:201:b129:c9aa:6634:6c4c]) by smtp.gmail.com with UTF8SMTPSA id p9sm4266718pfn.7.2021.11.04.01.24.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 04 Nov 2021 01:24:33 -0700 (PDT) From: Gwendal Grignou To: jic23@kernel.org, lars@metafoo.de Cc: andy.shevchenko@gmail.com, linux-iio@vger.kernel.org, Gwendal Grignou Subject: [PATCH v2 09/13] iio: ti-adc12138: Use scan_type when processing raw data Date: Thu, 4 Nov 2021 01:24:09 -0700 Message-Id: <20211104082413.3681212-10-gwendal@chromium.org> X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog In-Reply-To: <20211104082413.3681212-1-gwendal@chromium.org> References: <20211104082413.3681212-1-gwendal@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Use channel definition as root of trust and replace constant when reading elements directly using the raw sysfs attributes. Signed-off-by: Gwendal Grignou --- drivers/iio/adc/ti-adc12138.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/iio/adc/ti-adc12138.c b/drivers/iio/adc/ti-adc12138.c index fcd5d39dd03ea..5b5d452105393 100644 --- a/drivers/iio/adc/ti-adc12138.c +++ b/drivers/iio/adc/ti-adc12138.c @@ -239,7 +239,8 @@ static int adc12138_read_raw(struct iio_dev *iio, if (ret) return ret; - *value = sign_extend32(be16_to_cpu(data) >> 3, 12); + *value = sign_extend32(be16_to_cpu(data) >> channel->scan_type.shift, + channel->scan_type.realbits - 1); return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: From patchwork Thu Nov 4 08:24:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gwendal Grignou X-Patchwork-Id: 12602735 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F372C433EF for ; Thu, 4 Nov 2021 08:24:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 67A1E6109F for ; Thu, 4 Nov 2021 08:24:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230404AbhKDI1O (ORCPT ); Thu, 4 Nov 2021 04:27:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231147AbhKDI1M (ORCPT ); Thu, 4 Nov 2021 04:27:12 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F53EC06127A for ; Thu, 4 Nov 2021 01:24:35 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id r5so6034329pls.1 for ; Thu, 04 Nov 2021 01:24:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=050XYfAs5h9fYsKsLiHkYANnHJbrZ8oMXRf8QMjyzYM=; b=LEfQc7z7K4yFPsKkZw43TyrMwkqIgIAb8cVbRgknoflBNByrctsR1ctmR5ZmiS1WO3 zMm/TLOWgp/fhINi5jVJriHNYvaXSITzEaWjSrb0mv1iAzgEY0UOT767B2cZaQX3rfkz dZheU6vOHmw0ZqW5hQ9LoXQQD4/hileC5/wG8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=050XYfAs5h9fYsKsLiHkYANnHJbrZ8oMXRf8QMjyzYM=; b=qoQifI+dTrXj5+cPZAw2yWmPMGVUcEt+3FYJN2dK9jzxOso1InD5kCL1lBK8sQ7+et ZBkWL3vrgke8161SMXfzYf1fvAB6Vc4oSLR+or3PzDgH5kw6INtEIO07yGPj4WrY4X13 S1uT/pD5iIsO4G64xkhipPeLhbRrRyob7JkLaPm2Y+Vbwl7IGVI+C0mZ5BeTsHA/IB7v hj4iTKiEkQTRND9cOloMnhZa6pQM99TeBt4MuXy7nkqTbmj9d7R/d7is0jyp+esgp/G4 0IBH6EHBZYTl6wmIzEGq4num/XAV+R4R3V56g6+CAFa2yIyvg6M6xswsJevoitaRclIC MQqw== X-Gm-Message-State: AOAM532CekEo43Bjsj8Sgqcv8QGqIG+kpkCmK6b1LyjY3DOnlptsvvqu Lv1jEoPLY0UBfQRnPmfomw1Kkg== X-Google-Smtp-Source: ABdhPJwwDoy+8Sc0CKgnI0sbrwp8CBOOEsk5Jcd/LJes84xXHsxABGm784YFv0e6siH7EWlGO9AXAQ== X-Received: by 2002:a17:902:8605:b0:13f:7c1d:56d1 with SMTP id f5-20020a170902860500b0013f7c1d56d1mr43445764plo.57.1636014274872; Thu, 04 Nov 2021 01:24:34 -0700 (PDT) Received: from localhost ([2620:15c:202:201:b129:c9aa:6634:6c4c]) by smtp.gmail.com with UTF8SMTPSA id bf19sm6839973pjb.6.2021.11.04.01.24.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 04 Nov 2021 01:24:34 -0700 (PDT) From: Gwendal Grignou To: jic23@kernel.org, lars@metafoo.de Cc: andy.shevchenko@gmail.com, linux-iio@vger.kernel.org, Gwendal Grignou Subject: [PATCH v2 10/13] iio: mag3110: Use scan_type when processing raw data Date: Thu, 4 Nov 2021 01:24:10 -0700 Message-Id: <20211104082413.3681212-11-gwendal@chromium.org> X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog In-Reply-To: <20211104082413.3681212-1-gwendal@chromium.org> References: <20211104082413.3681212-1-gwendal@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Use channel definition as root of trust and replace constant when reading elements directly using the raw sysfs attributes. Signed-off-by: Gwendal Grignou --- drivers/iio/magnetometer/mag3110.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/iio/magnetometer/mag3110.c b/drivers/iio/magnetometer/mag3110.c index c96415a1aeadd..17c62d806218d 100644 --- a/drivers/iio/magnetometer/mag3110.c +++ b/drivers/iio/magnetometer/mag3110.c @@ -291,7 +291,8 @@ static int mag3110_read_raw(struct iio_dev *indio_dev, if (ret < 0) goto release; *val = sign_extend32( - be16_to_cpu(buffer[chan->scan_index]), 15); + be16_to_cpu(buffer[chan->scan_index]), + chan->scan_type.realbits - 1); ret = IIO_VAL_INT; break; case IIO_TEMP: /* in 1 C / LSB */ @@ -306,7 +307,8 @@ static int mag3110_read_raw(struct iio_dev *indio_dev, mutex_unlock(&data->lock); if (ret < 0) goto release; - *val = sign_extend32(ret, 7); + *val = sign_extend32(ret, + chan->scan_type.realbits - 1); ret = IIO_VAL_INT; break; default: From patchwork Thu Nov 4 08:24:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gwendal Grignou X-Patchwork-Id: 12602737 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 040A2C433F5 for ; Thu, 4 Nov 2021 08:24:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E238D60240 for ; Thu, 4 Nov 2021 08:24:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231160AbhKDI1O (ORCPT ); Thu, 4 Nov 2021 04:27:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230478AbhKDI1O (ORCPT ); Thu, 4 Nov 2021 04:27:14 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7130C061714 for ; Thu, 4 Nov 2021 01:24:36 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id f8so5945318plo.12 for ; Thu, 04 Nov 2021 01:24:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GuLak6n2D+xx1jRMo02bIST3H8cpHj9A6SUpEXVo4Kg=; b=PZA0QqsHy/TdKx42gjLZwXQyYvqkFPURwEqxKzAK1Di8uKqpBcI2rrsMm/CF0vNztK Es6HjIvLVt88eRodWq0Poys+P+9b18rEZfyv0h49DzvSfizgQNXj6Lwnca0NWoMYT9Sh C7NW/G27/cD7SB53+Tg/2g044MWssj/1VkNRg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GuLak6n2D+xx1jRMo02bIST3H8cpHj9A6SUpEXVo4Kg=; b=3rU5U5CthbymeN5vnnfqkUrT+aau54vZQwr3AtCMC0DIC8hGsKga2FUj2LvXUcX3rO YP5dc2ZAXUAsEHGN6QsOQ2H/u21iOXxhynHRk4PHhypaFM7wVc5o2JLoViG/kXR07gaF OJ21LhEkvABpLtYv3XIjqu1tzBfp7y7ztUVB4qv9ZWjKMqcAE4rM9CJzNTcfpKo6x5Hk 83sL5hsutqs+V4/BQ+2je45Ik4XHQvXmXIHXEUDCWwCgki2/ttvN/i1xLRBIvoo8LsU9 +FsQTnRVeVs/I4r1zo0S38mRvX54JxwHpMLN8+h4Z8KjtOJk0sHOfRlq2kCPxl7MtMt3 Wpig== X-Gm-Message-State: AOAM530hMwWbelfyJV2hwn4Hx4xD/rB63Df0L+sfqcL8ZsQ50aXMp6Us 908At1qv9mzCQHXsvqBq3T/9mg== X-Google-Smtp-Source: ABdhPJzv/w7srlBAGURkCzggPnZTqDQPlib/6JwM2CEKXd8C61woL914Ho3/11qoCwHtqA15ygvEAw== X-Received: by 2002:a17:902:f542:b0:141:fa0e:1590 with SMTP id h2-20020a170902f54200b00141fa0e1590mr20591325plf.20.1636014276390; Thu, 04 Nov 2021 01:24:36 -0700 (PDT) Received: from localhost ([2620:15c:202:201:b129:c9aa:6634:6c4c]) by smtp.gmail.com with UTF8SMTPSA id pg13sm3564132pjb.8.2021.11.04.01.24.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 04 Nov 2021 01:24:36 -0700 (PDT) From: Gwendal Grignou To: jic23@kernel.org, lars@metafoo.de Cc: andy.shevchenko@gmail.com, linux-iio@vger.kernel.org, Gwendal Grignou Subject: [PATCH v2 11/13] iio: ti-ads1015: Remove shift variable ads1015_read_raw Date: Thu, 4 Nov 2021 01:24:11 -0700 Message-Id: <20211104082413.3681212-12-gwendal@chromium.org> X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog In-Reply-To: <20211104082413.3681212-1-gwendal@chromium.org> References: <20211104082413.3681212-1-gwendal@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org By using scan_type.realbits when processing raw data, we use scan_type.shit only once, thus we don't need to define a local variable for it anymore. Signed-off-by: Gwendal Grignou --- drivers/iio/adc/ti-ads1015.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c index b0352e91ac165..b92d4cd1b8238 100644 --- a/drivers/iio/adc/ti-ads1015.c +++ b/drivers/iio/adc/ti-ads1015.c @@ -464,9 +464,7 @@ static int ads1015_read_raw(struct iio_dev *indio_dev, mutex_lock(&data->lock); switch (mask) { - case IIO_CHAN_INFO_RAW: { - int shift = chan->scan_type.shift; - + case IIO_CHAN_INFO_RAW: ret = iio_device_claim_direct_mode(indio_dev); if (ret) break; @@ -487,7 +485,8 @@ static int ads1015_read_raw(struct iio_dev *indio_dev, goto release_direct; } - *val = sign_extend32(*val >> shift, 15 - shift); + *val = sign_extend32(*val >> chan->scan_type.shift, + chan->scan_type.realbits - 1); ret = ads1015_set_power_state(data, false); if (ret < 0) @@ -497,7 +496,6 @@ static int ads1015_read_raw(struct iio_dev *indio_dev, release_direct: iio_device_release_direct_mode(indio_dev); break; - } case IIO_CHAN_INFO_SCALE: idx = data->channel_data[chan->address].pga; *val = ads1015_fullscale_range[idx]; From patchwork Thu Nov 4 08:24:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gwendal Grignou X-Patchwork-Id: 12602739 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 571A5C433FE for ; Thu, 4 Nov 2021 08:24:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4141160240 for ; Thu, 4 Nov 2021 08:24:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230492AbhKDI1Q (ORCPT ); Thu, 4 Nov 2021 04:27:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230478AbhKDI1P (ORCPT ); Thu, 4 Nov 2021 04:27:15 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F3E2C061714 for ; Thu, 4 Nov 2021 01:24:38 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id u17so5975169plg.9 for ; Thu, 04 Nov 2021 01:24:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9OqXE6OoYroe6veay0WvtZ0d2Pt4NYeP8Cveo7pjMiI=; b=kFDRN3o694lxq25DAIUimKGXetwMqsYgmCGoDEvR5/biyn8883oj5q96V5mnHKLCeC t49/RzAxFcPNwUxGo5tPntzaSVzzLh9vUipTQtZxZecV2VB+pPY3mTikUVWRDzCKwlqP +yBVnSFClvRKFETBl+RDrUG9FUFZ0FNzwHshg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9OqXE6OoYroe6veay0WvtZ0d2Pt4NYeP8Cveo7pjMiI=; b=NegdvGFpiYFraJe0Ulu1vyOUoyU0dNMtNLPWeR16rsgLHgBH18+scVtFvM5nVyY9Xr f9QZQtZXCr244MPFz3HW5K6rHGF0LjMd2ogwsf6WuZUs/wl3IlaB7Ofg6gudR36VDHmy +/7hU2QAkrO0vZNQYso5qtgi8o4ju+D7833NdYfd0tD/qXTs+rcymW3zsSmmYTKmRTZE W4HO8RvvsKN3shtBk5KDoIKhytXZ5WKc+mGUzSCjaeAuoxjCgjBolUFjipgAkRIOtWZm V7uow+zSJBX3QBntJpj/hpmVsEjibg2MpOKpXbub/VMq4aB/14aNzETIx+rGzdCjLsDq 7x6A== X-Gm-Message-State: AOAM532abOxx41SAYiiDow/275FyGxWbSW0c2fclAH1Poza9N/WB7WKT e/ZJ7gACylucmHPMB9iVVWLrRtOr9NrToA== X-Google-Smtp-Source: ABdhPJztlPFBfKoxDSZ78lXY2ziFIiCo8FVKBQdKfkynUmy445uClyxZOTHgcj7djcY10n+7se+B6A== X-Received: by 2002:a17:90b:4f45:: with SMTP id pj5mr4267631pjb.70.1636014277789; Thu, 04 Nov 2021 01:24:37 -0700 (PDT) Received: from localhost ([2620:15c:202:201:b129:c9aa:6634:6c4c]) by smtp.gmail.com with UTF8SMTPSA id e187sm4444948pfe.181.2021.11.04.01.24.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 04 Nov 2021 01:24:37 -0700 (PDT) From: Gwendal Grignou To: jic23@kernel.org, lars@metafoo.de Cc: andy.shevchenko@gmail.com, linux-iio@vger.kernel.org, Gwendal Grignou Subject: [PATCH v2 12/13] iio: xilinx-xadc-core: Use local variable in xadc_read_raw Date: Thu, 4 Nov 2021 01:24:12 -0700 Message-Id: <20211104082413.3681212-13-gwendal@chromium.org> X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog In-Reply-To: <20211104082413.3681212-1-gwendal@chromium.org> References: <20211104082413.3681212-1-gwendal@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Minor cleanup: bit is already defined as chan->scan_type.realbits, use bit when needed. Signed-off-by: Gwendal Grignou --- drivers/iio/adc/xilinx-xadc-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/adc/xilinx-xadc-core.c b/drivers/iio/adc/xilinx-xadc-core.c index 2aa4278ecba78..823c8e5f9809b 100644 --- a/drivers/iio/adc/xilinx-xadc-core.c +++ b/drivers/iio/adc/xilinx-xadc-core.c @@ -944,7 +944,7 @@ static int xadc_read_raw(struct iio_dev *indio_dev, *val = 1000; break; } - *val2 = chan->scan_type.realbits; + *val2 = bits; return IIO_VAL_FRACTIONAL_LOG2; case IIO_TEMP: /* Temp in C = (val * 503.975) / 2**bits - 273.15 */ From patchwork Thu Nov 4 08:24:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gwendal Grignou X-Patchwork-Id: 12602741 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26524C433F5 for ; Thu, 4 Nov 2021 08:24:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0ECF7610D0 for ; Thu, 4 Nov 2021 08:24:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231171AbhKDI1R (ORCPT ); Thu, 4 Nov 2021 04:27:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231166AbhKDI1R (ORCPT ); Thu, 4 Nov 2021 04:27:17 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD2C9C061714 for ; Thu, 4 Nov 2021 01:24:39 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id m14so5110317pfc.9 for ; Thu, 04 Nov 2021 01:24:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2/IAh9b2ZtQRqOn+VVVEM3bR790w8gUv8rHS+EEtkRk=; b=FRKDxcn6u2HMiNmkTw3d1yfcfjE9s9IuJJH+BQ5TRIW8sOF42nPwOZ//AxHyaao2cF J50C1jv/QDoHsZjm7gYLJXnfLgmlE6fykyBxWAZ0OJl6MB8H2JrCvZl6SYJFHypV1MnJ cNo0BOEqHo1imPRSWGto8EpWY/wzu4u4emZdI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2/IAh9b2ZtQRqOn+VVVEM3bR790w8gUv8rHS+EEtkRk=; b=tuZPabmllMikOxFIPXcqv3FXXzicp03N904T5O5kmWvxljvONy1Yzi1sO/nUeb8WWI jNv9jpov7IOfXkEkhCQArdwIJZTKzbog18llYgGR2PzUh0DI2535avEZd75RnKz1Ze3C icKxsvt2G6+Hn+2xDOzNpkmIbyBBkl+B/lf0dnMtCs09liEYWiQ4hsG2LeGUQ/O1rc16 Ga5c9qlREwHipUoO8r/3nPyxFffFHnV3yYdeUTPvFN7D5MvFZBgb8Ka+OF4KZXc9f771 5U2gZShqvBmkK/NsRJ6JUVhXPka4CZ1sZsqK76Qve8LTcuWrHOyqR4pO18IRoShjRV63 Pfxg== X-Gm-Message-State: AOAM5305eNIiTSWBZ7cuf7cnGtEhV1d8V6Y+Ja3ANRUk3ktlO4JHrp2H e/0Qc5jQV/zVC8LiRktgOHGgzQ== X-Google-Smtp-Source: ABdhPJz4S40ExTYGvv4nURgPQ36sXl8N5PwwEBRejEAp+Fyi7AWtEcsoKV8kx80kKxSMSVrnAs0MuQ== X-Received: by 2002:a63:954a:: with SMTP id t10mr37752082pgn.89.1636014279244; Thu, 04 Nov 2021 01:24:39 -0700 (PDT) Received: from localhost ([2620:15c:202:201:b129:c9aa:6634:6c4c]) by smtp.gmail.com with UTF8SMTPSA id t4sm4611565pfj.13.2021.11.04.01.24.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 04 Nov 2021 01:24:38 -0700 (PDT) From: Gwendal Grignou To: jic23@kernel.org, lars@metafoo.de Cc: andy.shevchenko@gmail.com, linux-iio@vger.kernel.org, Gwendal Grignou Subject: [PATCH v2 13/13] iio: mpl3115: Use scan_type.shift and realbit in mpl3115_read_raw Date: Thu, 4 Nov 2021 01:24:13 -0700 Message-Id: <20211104082413.3681212-14-gwendal@chromium.org> X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog In-Reply-To: <20211104082413.3681212-1-gwendal@chromium.org> References: <20211104082413.3681212-1-gwendal@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org When processing raw data using channel scan_type.shift as source of trust to shift data appropriately. When processing the temperature channel, use a 16bit big endian variable as buffer to increase conversion readability. Signed-off-by: Gwendal Grignou --- drivers/iio/pressure/mpl3115.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/iio/pressure/mpl3115.c b/drivers/iio/pressure/mpl3115.c index 1eb9e7b29e050..e95b9a5475b4e 100644 --- a/drivers/iio/pressure/mpl3115.c +++ b/drivers/iio/pressure/mpl3115.c @@ -74,7 +74,6 @@ static int mpl3115_read_raw(struct iio_dev *indio_dev, int *val, int *val2, long mask) { struct mpl3115_data *data = iio_priv(indio_dev); - __be32 tmp = 0; int ret; switch (mask) { @@ -84,7 +83,9 @@ static int mpl3115_read_raw(struct iio_dev *indio_dev, return ret; switch (chan->type) { - case IIO_PRESSURE: /* in 0.25 pascal / LSB */ + case IIO_PRESSURE: { /* in 0.25 pascal / LSB */ + __be32 tmp = 0; + mutex_lock(&data->lock); ret = mpl3115_request(data); if (ret < 0) { @@ -96,10 +97,13 @@ static int mpl3115_read_raw(struct iio_dev *indio_dev, mutex_unlock(&data->lock); if (ret < 0) break; - *val = be32_to_cpu(tmp) >> 12; + *val = be32_to_cpu(tmp) >> chan->scan_type.shift; ret = IIO_VAL_INT; break; - case IIO_TEMP: /* in 0.0625 celsius / LSB */ + } + case IIO_TEMP: { /* in 0.0625 celsius / LSB */ + __be16 tmp; + mutex_lock(&data->lock); ret = mpl3115_request(data); if (ret < 0) { @@ -111,9 +115,11 @@ static int mpl3115_read_raw(struct iio_dev *indio_dev, mutex_unlock(&data->lock); if (ret < 0) break; - *val = sign_extend32(be32_to_cpu(tmp) >> 20, 11); + *val = sign_extend32(be16_to_cpu(tmp) >> chan->scan_type.shift, + chan->scan_type.realbits - 1); ret = IIO_VAL_INT; break; + } default: ret = -EINVAL; break;