From nobody Mon Sep 28 08:02:24 2026 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5DE8B38D40B for ; Mon, 24 Aug 2026 20:14:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787602456; cv=none; b=d898FchGdzyntqZz6017s7k3CVW2rcgX5LXIuJvB3bEyLIr/g6E1CjzFZGEFrppUZbLZyVLWG2sfYnsuHfihy03atCtAhGYewcBz7EFBZ7cu62o3HtG8PF58VzVfpUsz424Hw041shX8XRAfd5RkPgaUsO4A+uY0gbchNpEyjFk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787602456; c=relaxed/simple; bh=x2S1FPcFw6xB0ZEc3bzyK1hPMMiTGwFHOTi1d6ZsdXY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lNgG1+np5vDswvCp0KU2lFpixGrbIqS0eZuRdE6F/G9nHDsTkKSF2vyIjFrh8DMxmMQEo/3q2quRg+z2DeK/DE7GBfME/hhSOr6vKWcF1WhSZzMjGcT0oz3Tm84ZRXJPaudyOgoS3WBktaVYHVOmofJz/k1cbFg1n/R5mFy/hmo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KfyFU3gx; arc=none smtp.client-ip=209.85.167.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KfyFU3gx" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-5aeb24c0807so3310629e87.0 for ; Mon, 24 Aug 2026 13:14:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787602453; x=1788207253; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=tsCzfWJOg7SVbU+X222eaAOaisGnyr8WXZV/pRTp8oY=; b=KfyFU3gxlPi16iogDrJAy7JhGORULAirVcUtxjlY61YbR3Puj8xxOACAyNPDEtzCWg Dw631odOAZYGlX8nGh5gMHW6LzMe6BVdmR2/pE9i8PuFyFfkkwXijI+eS85hWQbwhyPV e1HXynlh+AJtahWoiOY1UTWb9A1M7mNggLV5oUZTPzv1IPstZc6mMz+H2b330JPNq71K moubkqIqO9yxWybnuEFoVbbS1arY/NAyMlSi/49BU405BfoEv2m6vJ9cXrbgf3mWDSBT Up0UfAIVe4rqTwXnw/AEE05il1fW/Lji1ml4kii1s7XkQ3gWtGru0hKpK0qgCBPmm5V4 lf0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787602453; x=1788207253; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=tsCzfWJOg7SVbU+X222eaAOaisGnyr8WXZV/pRTp8oY=; b=qZzwnnJ8DRIXW+IH/grbUPfmCJhFPk4hzN0Ggb7lNOHCBiSt5bu7fPDktYTu4OlJmU tx6h7Plrq/63VRhAHnlQ53CCEYtcJl/kXe55tnqq9M5M75lB4sM0QRCWTwjlX72wKQKk exn0S9JAD53kr+6/LNkzE8HHH3jIQdVhmat1sc14OGFhhMf23HwZnvly5b+mV8hD+Eo5 QQpMObtSK7SBdhVHMgbPM5R/wOM80jio6YebernSEHGg0MqvMIHEpBdHFuEB8hF8PZeM lCvVW8f1A7EEn2ILAVVhO7YprVvWsjaPRcnsY60HrJjJ8t7NWsssW7cBHSwcv4AfQCNN ADbA== X-Forwarded-Encrypted: i=1; AHgh+RqDt6uroXmg9b1KsJkLfSLOowT3p4XP06SddrkORPJgCF8RKs71l+6oBDEzqkevIGrITbGMXAtId7rpkdE=@vger.kernel.org X-Gm-Message-State: AFuF++nBPSyVXI9FtFVXE9cRhoOJd+UF5e+LQPC/QxTafSWfpar85zXl JCu9uj2LdiWAT3Fs48XH5VKkD1S5uLeaBv1VjcdfHJnFGILGyFRy2p0G X-Gm-Gg: AR+sD13GNghJbREm811OQNpCv4nmxxDf+/UTcdruk2DZNuMJP9WjWTC9/dKYdickCTw aRJkMMK0deSMQykweP9V+7EsPBDsAt0OMpz2fZnov2PE5JPetsOA/f1q8UoKi5VscZXxS5plNX3 OpCmH6vKvwh+X+lY2LY7pywC8R6fNaJKgs0TCLVEbjwQSZ6zQBiyJfk7YzO9VsMvXWDtlBUAI0B eVygJ4XLAeUZ0jnI01jxbZzLuLyNvW3iaKMcERCMjQ9X5y18SNPaV8rEpz4dG1XbqonmorDVPai RYw3jqDziPONr53ueglf/GZIn464HwyszBIfzAdq7Lks9QumKdx553BBYaTyx1CeoOOEup3f0lH Z14pTVqYDmsB75ntcaeCZ3LyFdF1CQeut+e3BuoXbMl0JjDYXtY6fMv6XX3mibLOKn+YejxDnoL yAT83tLIcUxx8n/ezkptpkCaoh0rZ4F+GX5MhsWGH1X1dziSg8LHR1gz/42OQYZKEnLc36dwq6q rRm0/D3lateRRdnhNCB48u6d/OTO/8J3iY5qK9VSrBIMwpKIdHUGmtL7qk= X-Received: by 2002:a05:6512:2304:b0:5b2:e947:b3e6 with SMTP id 2adb3069b0e04-5b484209176mr9381158e87.2.1787602452978; Mon, 24 Aug 2026 13:14:12 -0700 (PDT) Received: from yantra.. (dsl-trebng21-58c187-236.dhcp.inet.fi. [88.193.135.236]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5b48ce0cd9csm1923620e87.71.2026.08.24.13.14.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Aug 2026 13:14:12 -0700 (PDT) From: Rupesh Majhi To: Andy Shevchenko , Bill Wendling , David Lechner , Eddie James , Joel Stanley , Jonathan Cameron , Justin Stitt , Nathan Chancellor , Nick Desaulniers , =?UTF-8?q?Nuno=20S=C3=A1?= Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Rupesh Majhi , stable@vger.kernel.org Subject: [PATCH v6 1/6] iio: pressure: dps310: fix CFG_REG bit definitions Date: Mon, 24 Aug 2026 23:11:58 +0300 Message-ID: <20260824201203.396651-2-zoone.rupert@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260824201203.396651-1-zoone.rupert@gmail.com> References: <20260824201203.396651-1-zoone.rupert@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Driver defines them as BIT(4), BIT(5) and BIT(6). Per datasheet P_SHIFT is bit 2, FIFO_EN is bit 1 and SPI_MODE is bit 0. Only P_SHIFT has a user. dps310_set_pres_precision() sets it at oversampling 16 or above, so with wrong bit the result register is never shifted and stops matching the scale factor compensation divides by. in_pressure_input returns -ERANGE at oversampling 16, 32 and 64. FIFO_EN needed by FIFO support later in this series. Fixes: ba6ec48e76bc ("iio: Add driver for Infineon DPS310") Fixes: d711a3c7dc82 ("iio: dps310: Add pressure sensing capability") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-5 Signed-off-by: Rupesh Majhi --- drivers/iio/pressure/dps310.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c index f45af72a0554..68382960382f 100644 --- a/drivers/iio/pressure/dps310.c +++ b/drivers/iio/pressure/dps310.c @@ -50,9 +50,9 @@ #define DPS310_CFG_REG 0x09 #define DPS310_INT_HL BIT(7) #define DPS310_TMP_SHIFT_EN BIT(3) -#define DPS310_PRS_SHIFT_EN BIT(4) -#define DPS310_FIFO_EN BIT(5) -#define DPS310_SPI_EN BIT(6) +#define DPS310_PRS_SHIFT_EN BIT(2) +#define DPS310_FIFO_EN BIT(1) +#define DPS310_SPI_EN BIT(0) #define DPS310_RESET 0x0c #define DPS310_RESET_MAGIC 0x09 #define DPS310_COEF_BASE 0x10 --=20 2.43.0 From nobody Mon Sep 28 08:02:24 2026 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE75238DC51 for ; Mon, 24 Aug 2026 20:14:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787602457; cv=none; b=PhkJHYKGmsO22/if5I/ubc1LW6DBFMzIolipj8rzi3C6I+NFjLLhXHlFUqK+0oD2MvMSrQnKbOjY7SlZ4ka7AwA4nH1CeVBsM5PpqLubYvJBXvRCHwFjKYJ7/qjZPIXQP1ir6aSFhnGSSjjoPT3Y8gmAhlIxKvVpaZul6Sws6zI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787602457; c=relaxed/simple; bh=n9Bht//Yk3scXsF8UPLRoojJO5J/1T0We2RgP49xtRY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k1/gJlfVLFpkTzwzB/Pp+K6UbQ4+rdIkD4Bl8sly7OYPTvsH6fZWYDdbjzk6xPA60hUxSnRIHUlmNeLrYi1ieAER5llBT9j5/trldpCxM9Mh9j6zPiIhtSQJSnR95RPZx+TVNIYWLoF1uxYyb4kSq6I2Vf6YqvySALA0DSsxmjM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=skx4dy1w; arc=none smtp.client-ip=209.85.167.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="skx4dy1w" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-5b4747943b8so3311422e87.0 for ; Mon, 24 Aug 2026 13:14:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787602454; x=1788207254; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=QSIPUen5mSK3/7kB5RAMGdblegdItDVxkIK2jwNz2kU=; b=skx4dy1wfxLk/AVRkSrcBo9+0Y0sEoRat4ynaeuasDkS3afSekgTNScn7uFe+BmgZ6 2pw4WRcqYA+fkJgSsA6Rz2z5PghY6pIl8P3IVKgG76TRas43w0P+mjP6RT2YjQ3TOTn9 m705wcbQE2TAm3OC//vxcpYh7DbrHPQLyMtl++6M7PWz2PZtieiFCjU6pPKiTlomZbwf OATj1QpdE9DFz+wwsR/MV2KzV9baM8ygJSo4STVAd13P1Gwe/J/FGdHptwGPfLJMwcWP wsflCJ8tT8lPZLhvrUk61aZ66SGySvEVV9DjmAe85ouJn1pFQwNat+DxhczFw++VaHXk yj5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787602454; x=1788207254; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=QSIPUen5mSK3/7kB5RAMGdblegdItDVxkIK2jwNz2kU=; b=Hp2OYZj4Sl1IkZ30uWbIwuPOyYqv7SEpWZESHBoPgUn1I4VFN+cecuAi9tjJxYRHOZ gNDF6+Z9aTiuQqrKG3L5oZaDTEfE6NlKt0/18h3O3opm2M/+JvQXyqem33f+lTXFGvfg PDa8wpOjk+KJlkxfI5PizffOgJOVZGF3DROfxgc1hBE4XVWdFlHNYSKqtwCKiOlSYAaI 0wAfCfUdDGAshjpQPboft707gei9UhCiCS2rtaJyM7QTQQH8u/mZoXO5F6Lmo5FAEgh+ OzAVsNT8WiTs55EewNbfdh52q/zTHXccy9t4Lca8/OPSv+eFTMnVQveJ457rb5cm5kh4 nIJg== X-Forwarded-Encrypted: i=1; AHgh+RqHgOqiru+cUY03iY9cu3f+Qb7h5MQJ9r1+bDInuG6mYdi5Nj+rViuY207C1MP/C66HQwneww0XL4DM4ww=@vger.kernel.org X-Gm-Message-State: AFuF++n+qxKkCCHQzJUHMSqsPm2MKijfVSd6CNlPhSXK/cMQpO1X4XDd gG3nZbU+Fgdv0QGO6qm/RwZ8no5rhuzbKtqbVKf9SqpJluCKEmAYceSm X-Gm-Gg: AR+sD10uf1OOoLfVVV4Jt+Qjju0L234NvTuzeKHXbe1jk5WDo0EZFf2Ur9VQNYE00qD nluU2exXKEPFOKwVaZOeN9yqCicjG63ksFmfhGzZGu2ks3Vyr6gF5Sq0jcPdF2gCiN1cPsA/XBg ktLLhg6nqpPr1AOiNgLJ/NdJRdHCABCKVxFtDBEMjtsf/0qDwc6/6xQrKBMzhrZvhyS8N0fhOOQ QuKAvfdBDwTLxQaeRBkIMFd1Q3nT6I3PoW7BgAeQyjQm1dFgd24npeV6MJ3G1+AeYwg9VtjiGEh p8ezZ+gUDCMNTJ5xwlWAv/53ChPV86e3i1z+vmEP8JwP9w7k86cnq3nW8KaDamyNC8+ZU9jpMKQ poqTs5+AanDPfiQoC7Ahi8RZm+KPaxqNYKTZBwUXGzROQ1rEBHxPly5pcN2p3zrJi/yPWPYRvN7 LmrqALTJ+7AOKhDjmKmS+a9JtpK12aktL1tOE5oWKVnKq/AHzeu1+5tvrBqsxaDchDkMHUDnpP1 jyZlMnvluPKsVXZg07btmL0Ter3v6650dCtqNNmRFC6ByG8Xm5mI/vFEXE= X-Received: by 2002:ac2:5688:0:b0:5b0:23cb:91ea with SMTP id 2adb3069b0e04-5b48b8a15e8mr5879737e87.22.1787602453887; Mon, 24 Aug 2026 13:14:13 -0700 (PDT) Received: from yantra.. (dsl-trebng21-58c187-236.dhcp.inet.fi. [88.193.135.236]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5b48ce0cd9csm1923620e87.71.2026.08.24.13.14.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Aug 2026 13:14:13 -0700 (PDT) From: Rupesh Majhi To: Andy Shevchenko , Bill Wendling , David Lechner , Eddie James , Joel Stanley , Jonathan Cameron , Justin Stitt , Nathan Chancellor , Nick Desaulniers , =?UTF-8?q?Nuno=20S=C3=A1?= Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Rupesh Majhi Subject: [PATCH v6 2/6] iio: pressure: dps310: use a local device pointer in probe Date: Mon, 24 Aug 2026 23:11:59 +0300 Message-ID: <20260824201203.396651-3-zoone.rupert@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260824201203.396651-1-zoone.rupert@gmail.com> References: <20260824201203.396651-1-zoone.rupert@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" probe() spells out &client->dev for every devm call. Take it into a local once instead, keeps lines short as more calls are added later in this series. No functional change. Assisted-by: Claude:claude-opus-5 Signed-off-by: Rupesh Majhi --- drivers/iio/pressure/dps310.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c index 68382960382f..25d1c79876e6 100644 --- a/drivers/iio/pressure/dps310.c +++ b/drivers/iio/pressure/dps310.c @@ -846,11 +846,12 @@ static const struct iio_info dps310_info =3D { static int dps310_probe(struct i2c_client *client) { const struct i2c_device_id *id =3D i2c_client_get_device_id(client); + struct device *dev =3D &client->dev; struct dps310_data *data; struct iio_dev *iio; int rc; =20 - iio =3D devm_iio_device_alloc(&client->dev, sizeof(*data)); + iio =3D devm_iio_device_alloc(dev, sizeof(*data)); if (!iio) return -ENOMEM; =20 @@ -869,7 +870,7 @@ static int dps310_probe(struct i2c_client *client) return PTR_ERR(data->regmap); =20 /* Register to run the device reset when the device is removed */ - rc =3D devm_add_action_or_reset(&client->dev, dps310_reset, data); + rc =3D devm_add_action_or_reset(dev, dps310_reset, data); if (rc) return rc; =20 @@ -877,7 +878,7 @@ static int dps310_probe(struct i2c_client *client) if (rc) return rc; =20 - rc =3D devm_iio_device_register(&client->dev, iio); + rc =3D devm_iio_device_register(dev, iio); if (rc) return rc; =20 --=20 2.43.0 From nobody Mon Sep 28 08:02:24 2026 Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC7F338DC53 for ; Mon, 24 Aug 2026 20:14:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787602458; cv=none; b=Vw2h7TuKsXeHlS9zUQ5YfR3nT3tp2muhHIlLzQDSIS4azbTjeM+LUw9VkfCs/RbQh4NjAhHpig08UmlAjSGG0odLeNejwhr9ecI8uZb0kJe413QVw68+DD8KyNg8l/vpMNiOojd64iv4KlmIaeiR5LJ7r5hrIRVb8iw0TIc5AB4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787602458; c=relaxed/simple; bh=Z8Q6Cje1VKDpJnaujnQksPmxZ0zKmJ2ZAE7GDaSwEZM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A6Gw9nvSrFevkjlLxVBFhaSpJFCdyqy+UsN7SZ/hTfnm/W9Pn+IOfNE5e9ZiiX6GCglQCCK7hWu9O5UGopbed5c8q5DSgy3KbwWMuaajnGtjK5IMoLwSu96DHj02jM/DWTaCkoXDlc9tOaqlng6y271isCoYwPB+2EG1K1Rta9g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=S3zlh/r/; arc=none smtp.client-ip=209.85.167.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="S3zlh/r/" Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-5aeba09900bso3104036e87.2 for ; Mon, 24 Aug 2026 13:14:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787602455; x=1788207255; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=nQXWTdBiGOmg9WRHvHkejupB58j8w1lmLGZTr2gy6Vs=; b=S3zlh/r/sltgB85ewkIuFuOeyCGVIgROqCL0SNLvrJtUzSZhHv3dt/65psU5F70ceF dLUfEez3qOggbkWr+u/HAF4Cjw+38FRKIqa/DMPX7JwYJs2sDW/LVQCfzvXeAQ92iTKe uy+3SBqe0EzDTFLHVgbRy+63xQdT39WkzDnjFCKFv4uL8YcRh3RNUh4uqo2vmVtXataY 1GU53X5ComV3MU1LUxMM0Plpt88w+86FlNl+MlJKjkzsim2iIrlFi8C/YSCm0ik1KBak qdj3XwYFH6SzgD6X/YJVgIMGoTrcydb+xztfhL9VMvYdYmSdOtlHL5bzHJ/eFw1VYhQB 9Cyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787602455; x=1788207255; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=nQXWTdBiGOmg9WRHvHkejupB58j8w1lmLGZTr2gy6Vs=; b=MnPxaOABITUn/4LV3xcI9Aa3eRIWFyf6NpRSSyNxwgzOfKKCMOhjYY1lDwW4hTnAZR ie7TjUlKlgqoAtC9dGRW6Aa6MbTdGYvsmgrx6VZSqPlDY03SZ+Ppv/L9fzLBltDRgnwh WTWOHZeYmp1pk+/gMokqQrRWNy3ZlRS+bNcx2lLBXHmuCuFxsmH53J0vb/NT7wKwDDRf Vs+aUjKYEH38Cw/TwfAw8UN/JqOqDEFpDSoxD/tZ9ta5eX/Wu8tMVdNa3Ty5qw2WuDsw vBKiFS8yry5ZOUdO4O7umXs3nBBqAI/B6I4TBlJ653q32yAvZYMSLsDqEJAcMKpNAjbI VIkQ== X-Forwarded-Encrypted: i=1; AHgh+RpZ4fD2VFZ+MhspwBiaEWrWu9IRyQVFc+SCOlH8eqbWX2Z+bqcaEJvu6cjYBnfggsnMfzqitB+zntYl5jI=@vger.kernel.org X-Gm-Message-State: AFuF++mxnqM4oU4qRdAPZloWO1zmalnNZudO22IGujviklPIyNO5+SpY g1TS7f9OHdJ5fjqOidTRdjme5soytbsZxvbM7SZwdjpuuiJvy7OEsckF X-Gm-Gg: AR+sD10W6DpuSuejJbSSHPqlXX34ZZeXg7EfXM+gmnTs28Wx481F8jlDFS9zfMcCk7n /bvl+bp79uQB2qUZGhaofs5Vn3bHoJcBgvZyAdzQsTmviP5GgGvBYAYsBs2a01tP2K6+epKaRqL 84OUc1zatDvEeof2Kusca4nyIDUCvK25oEAyKSrUw73BnEBul8qJ8ea1iOUj8C2BfppG3aXD7bI 9NZjSb8ZRKlitKWOQ77THgjjWQoeBU6WAZNmCDZ2T3ffYC6gK/eXPD8rr9cJOmzKuuHtTLVAKsP yBnz+cvcxzgq1FjRRiBvDfcJ+I0ljjxJfibSZcBWEPdUymeI5IlmfTqHeuKR5De6OJAt6/NEQnk gYgW6Qt7A+XMF0x3IQNaRhsOYQtMoV7NkO+HBKce9+pAzX56bv79J5ZAvFsR9xRzXGHVgu/dahg pNZFgOH3b5YvcEBXFuHdTMFAg/TX8+ILeIacyVuVjA2MhBOhSVXymF5c8nFX4QslYY6sqEhH0TB J9SF0Kz1ThJR7MHJxKdnsLeyNFan8t0s9H5x14Tfy1YXmrW1EZpC8Hho2lzaa2TKGBUs1AdoTE= X-Received: by 2002:a05:6512:3f25:b0:5ae:b969:417d with SMTP id 2adb3069b0e04-5b49cc05204mr327990e87.0.1787602454609; Mon, 24 Aug 2026 13:14:14 -0700 (PDT) Received: from yantra.. (dsl-trebng21-58c187-236.dhcp.inet.fi. [88.193.135.236]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5b48ce0cd9csm1923620e87.71.2026.08.24.13.14.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Aug 2026 13:14:14 -0700 (PDT) From: Rupesh Majhi To: Andy Shevchenko , Bill Wendling , David Lechner , Eddie James , Joel Stanley , Jonathan Cameron , Justin Stitt , Nathan Chancellor , Nick Desaulniers , =?UTF-8?q?Nuno=20S=C3=A1?= Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Rupesh Majhi Subject: [PATCH v6 3/6] iio: pressure: dps310: rework the raw read paths Date: Mon, 24 Aug 2026 23:12:00 +0300 Message-ID: <20260824201203.396651-4-zoone.rupert@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260824201203.396651-1-zoone.rupert@gmail.com> References: <20260824201203.396651-1-zoone.rupert@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Raw reads take the lock themselves, so a processed pressure read takes it twice: once for the raw read, then again when dps310_calculate_pressure() trylocks to refresh temperature. Refresh is skipped whenever lock is busy. Split raw reads into variants that expect lock held, one helper per channel taking it once for the whole sequence. Temperature refresh is unconditional now. Buffered capture later in this series needs the same shape. Also use get_unaligned_be24() for 24-bit results, and mark functions that need the lock with __must_hold() rather than a comment. Assisted-by: Claude:claude-opus-5 Signed-off-by: Rupesh Majhi --- drivers/iio/pressure/dps310.c | 159 +++++++++++++++++++--------------- 1 file changed, 87 insertions(+), 72 deletions(-) diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c index 25d1c79876e6..269a71ea3e7a 100644 --- a/drivers/iio/pressure/dps310.c +++ b/drivers/iio/pressure/dps310.c @@ -19,6 +19,7 @@ #include #include #include +#include =20 #include #include @@ -286,8 +287,8 @@ static int dps310_get_temp_precision(struct dps310_data= *data, int *val) return 0; } =20 -/* Called with lock held */ static int dps310_set_pres_precision(struct dps310_data *data, int val) + __must_hold(&data->lock) { int rc; u8 shift_en; @@ -305,8 +306,8 @@ static int dps310_set_pres_precision(struct dps310_data= *data, int val) DPS310_PRS_PRC_BITS, ilog2(val)); } =20 -/* Called with lock held */ static int dps310_set_temp_precision(struct dps310_data *data, int val) + __must_hold(&data->lock) { int rc; u8 shift_en; @@ -324,8 +325,8 @@ static int dps310_set_temp_precision(struct dps310_data= *data, int val) DPS310_TMP_PRC_BITS, ilog2(val)); } =20 -/* Called with lock held */ static int dps310_set_pres_samp_freq(struct dps310_data *data, int freq) + __must_hold(&data->lock) { u8 val; =20 @@ -338,8 +339,8 @@ static int dps310_set_pres_samp_freq(struct dps310_data= *data, int freq) DPS310_PRS_RATE_BITS, val); } =20 -/* Called with lock held */ static int dps310_set_temp_samp_freq(struct dps310_data *data, int freq) + __must_hold(&data->lock) { u8 val; =20 @@ -438,6 +439,7 @@ static int dps310_ready_status(struct dps310_data *data= , int ready_bit, int time } =20 static int dps310_ready(struct dps310_data *data, int ready_bit, int timeo= ut) + __must_hold(&data->lock) { int rc; =20 @@ -463,82 +465,87 @@ static int dps310_ready(struct dps310_data *data, int= ready_bit, int timeout) return 0; } =20 -static int dps310_read_pres_raw(struct dps310_data *data) +static int dps310_read_pres_raw_locked(struct dps310_data *data) + __must_hold(&data->lock) { int rc; int rate; int timeout; - s32 raw; u8 val[3]; =20 - if (mutex_lock_interruptible(&data->lock)) - return -EINTR; - rc =3D dps310_get_pres_samp_freq(data, &rate); if (rc) - goto done; + return rc; =20 timeout =3D DPS310_POLL_TIMEOUT_US(rate); =20 /* Poll for sensor readiness; base the timeout upon the sample rate. */ rc =3D dps310_ready(data, DPS310_PRS_RDY, timeout); if (rc) - goto done; + return rc; =20 rc =3D regmap_bulk_read(data->regmap, DPS310_PRS_BASE, val, sizeof(val)); if (rc < 0) - goto done; + return rc; =20 - raw =3D (val[0] << 16) | (val[1] << 8) | val[2]; - data->pressure_raw =3D sign_extend32(raw, 23); + data->pressure_raw =3D sign_extend32(get_unaligned_be24(val), 23); =20 -done: - mutex_unlock(&data->lock); - return rc; + return 0; } =20 -/* Called with lock held */ static int dps310_read_temp_ready(struct dps310_data *data) + __must_hold(&data->lock) { int rc; u8 val[3]; - s32 raw; =20 rc =3D regmap_bulk_read(data->regmap, DPS310_TMP_BASE, val, sizeof(val)); if (rc < 0) return rc; =20 - raw =3D (val[0] << 16) | (val[1] << 8) | val[2]; - data->temp_raw =3D sign_extend32(raw, 23); + data->temp_raw =3D sign_extend32(get_unaligned_be24(val), 23); =20 return 0; } =20 -static int dps310_read_temp_raw(struct dps310_data *data) +static int dps310_read_temp_raw_locked(struct dps310_data *data) + __must_hold(&data->lock) { int rc; int rate; int timeout; =20 - if (mutex_lock_interruptible(&data->lock)) - return -EINTR; - rc =3D dps310_get_temp_samp_freq(data, &rate); if (rc) - goto done; + return rc; =20 timeout =3D DPS310_POLL_TIMEOUT_US(rate); =20 /* Poll for sensor readiness; base the timeout upon the sample rate. */ rc =3D dps310_ready(data, DPS310_TMP_RDY, timeout); if (rc) - goto done; + return rc; + + return dps310_read_temp_ready(data); +} + +/* + * Refresh the cached temperature if a new measurement is ready, so that t= he + * pressure compensation uses a recent value. An error is not fatal here, = the + * previous temperature is used instead. + */ +static void dps310_refresh_temp_locked(struct dps310_data *data) + __must_hold(&data->lock) +{ + int rc; + int t_ready; =20 - rc =3D dps310_read_temp_ready(data); + rc =3D regmap_read(data->regmap, DPS310_MEAS_CFG, &t_ready); + if (rc) + return; =20 -done: - mutex_unlock(&data->lock); - return rc; + if (t_ready & DPS310_TMP_RDY) + dps310_read_temp_ready(data); } =20 static bool dps310_is_writeable_reg(struct device *dev, unsigned int reg) @@ -580,59 +587,47 @@ static int dps310_write_raw(struct iio_dev *iio, struct iio_chan_spec const *chan, int val, int val2, long mask) { - int rc; struct dps310_data *data =3D iio_priv(iio); =20 - if (mutex_lock_interruptible(&data->lock)) + ACQUIRE(mutex_intr, lock)(&data->lock); + if (ACQUIRE_ERR(mutex_intr, &lock)) return -EINTR; =20 switch (mask) { case IIO_CHAN_INFO_SAMP_FREQ: switch (chan->type) { case IIO_PRESSURE: - rc =3D dps310_set_pres_samp_freq(data, val); - break; + return dps310_set_pres_samp_freq(data, val); =20 case IIO_TEMP: - rc =3D dps310_set_temp_samp_freq(data, val); - break; + return dps310_set_temp_samp_freq(data, val); =20 default: - rc =3D -EINVAL; - break; + return -EINVAL; } - break; =20 case IIO_CHAN_INFO_OVERSAMPLING_RATIO: switch (chan->type) { case IIO_PRESSURE: - rc =3D dps310_set_pres_precision(data, val); - break; + return dps310_set_pres_precision(data, val); =20 case IIO_TEMP: - rc =3D dps310_set_temp_precision(data, val); - break; + return dps310_set_temp_precision(data, val); =20 default: - rc =3D -EINVAL; - break; + return -EINVAL; } - break; =20 default: - rc =3D -EINVAL; - break; + return -EINVAL; } - - mutex_unlock(&data->lock); - return rc; } =20 static int dps310_calculate_pressure(struct dps310_data *data, int *val) + __must_hold(&data->lock) { int i; int rc; - int t_ready; int kpi; int kti; s64 rem =3D 0ULL; @@ -656,15 +651,6 @@ static int dps310_calculate_pressure(struct dps310_dat= a *data, int *val) kp =3D (s64)kpi; kt =3D (s64)kti; =20 - /* Refresh temp if it's ready, otherwise just use the latest value */ - if (mutex_trylock(&data->lock)) { - rc =3D regmap_read(data->regmap, DPS310_MEAS_CFG, &t_ready); - if (rc >=3D 0 && t_ready & DPS310_TMP_RDY) - dps310_read_temp_ready(data); - - mutex_unlock(&data->lock); - } - p =3D (s64)data->pressure_raw; t =3D (s64)data->temp_raw; =20 @@ -710,6 +696,27 @@ static int dps310_calculate_pressure(struct dps310_dat= a *data, int *val) return 0; } =20 +/* + * Sample the pressure and compensate it, taking the lock once for the who= le + * sequence rather than once per register read. + */ +static int dps310_read_pressure_value(struct dps310_data *data, int *val) +{ + int rc; + + ACQUIRE(mutex_intr, lock)(&data->lock); + if (ACQUIRE_ERR(mutex_intr, &lock)) + return -EINTR; + + rc =3D dps310_read_pres_raw_locked(data); + if (rc) + return rc; + + dps310_refresh_temp_locked(data); + + return dps310_calculate_pressure(data, val); +} + static int dps310_read_pressure(struct dps310_data *data, int *val, int *v= al2, long mask) { @@ -724,11 +731,7 @@ static int dps310_read_pressure(struct dps310_data *da= ta, int *val, int *val2, return IIO_VAL_INT; =20 case IIO_CHAN_INFO_PROCESSED: - rc =3D dps310_read_pres_raw(data); - if (rc) - return rc; - - rc =3D dps310_calculate_pressure(data, val); + rc =3D dps310_read_pressure_value(data, val); if (rc) return rc; =20 @@ -747,6 +750,7 @@ static int dps310_read_pressure(struct dps310_data *dat= a, int *val, int *val2, } =20 static int dps310_calculate_temp(struct dps310_data *data, int *val) + __must_hold(&data->lock) { s64 c0; s64 t; @@ -768,6 +772,21 @@ static int dps310_calculate_temp(struct dps310_data *d= ata, int *val) return 0; } =20 +static int dps310_read_temp_value(struct dps310_data *data, int *val) +{ + int rc; + + ACQUIRE(mutex_intr, lock)(&data->lock); + if (ACQUIRE_ERR(mutex_intr, &lock)) + return -EINTR; + + rc =3D dps310_read_temp_raw_locked(data); + if (rc) + return rc; + + return dps310_calculate_temp(data, val); +} + static int dps310_read_temp(struct dps310_data *data, int *val, int *val2, long mask) { @@ -782,11 +801,7 @@ static int dps310_read_temp(struct dps310_data *data, = int *val, int *val2, return IIO_VAL_INT; =20 case IIO_CHAN_INFO_PROCESSED: - rc =3D dps310_read_temp_raw(data); - if (rc) - return rc; - - rc =3D dps310_calculate_temp(data, val); + rc =3D dps310_read_temp_value(data, val); if (rc) return rc; =20 --=20 2.43.0 From nobody Mon Sep 28 08:02:24 2026 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD3DA38D407 for ; Mon, 24 Aug 2026 20:14:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787602462; cv=none; b=tJqqcz/hGmCzztRPpDQhodZ1ws3dCrIBMwSjaRwAHiQbS34O8qA/7TCCfEFrgsWLDM6O7nAoq+RibFMGlnHY4GLU/61xhO2pH5vDYLkJqnzFHgx6uF7zF6KUzMJJMZ2gwWT+8c9ZgJM2e5/iVC0KAn4lZXUQPTXZQayHBON3GDc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787602462; c=relaxed/simple; bh=csUPRYnD1mZEqYaD+zR8/M55EcN2oznVfK16WyklPNE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Na7nKa/kqryDtNfnTQdIJWSb9Aza35hbBFvDtzT5K2AY/P+GEKnxmK5gEXI5v7rQYqhAnnJ4u7+3wvkcxGAq7TESerySyfoi2QZX9UVWcaZ85kNruikE5E29XSEEYiK81o6S98F6iQrTZ67QO0w3m+3cgvERt3KbGAVEoPA8mMg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ft9HjAqj; arc=none smtp.client-ip=209.85.167.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ft9HjAqj" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-5b2a22c52c1so3703905e87.3 for ; Mon, 24 Aug 2026 13:14:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787602457; x=1788207257; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Jr7LJu6Ksb6SAGIGzJSc2rS20dUT4t5olBG8OLxTlPA=; b=ft9HjAqjmmepc2pUFmqCCp4wIjHsFIUSGUN3CIwcuEdlSGg9MxqOuTlvNCxtc6NK+O sclQQ8g+4dCKJWNoX/NpWmw+Czkfzq9n/JFFx//Y+12koz/8zcfbMheol3zr2c9lFKuo tuWhDIclY2bfeKeyAGyydCem0jt9DoSUA4J7+0tCxz+9o5haHq1cwP0gSobIwsUM0+lM 3Re5+dRozDd5rnsK90GhWn0QrUj6ClJNGQQer1t89YtGVx+BDOc2wmYHT2DckmOmi8kq hYkMajCqujTuDtmPFaVTwch0ffmGvlx9kF69wcvmMxbY4jEuc8zaytWrGHiYOtGOZTM8 7dSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787602457; x=1788207257; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Jr7LJu6Ksb6SAGIGzJSc2rS20dUT4t5olBG8OLxTlPA=; b=Qus9HTIzt/iryMWyYAxDgXak4sPzRfHbBVAT6WcXH8d23qkh5acrA1tm/fgn3TEZcw 4BwQkz/cuRJNBc42nG/owYwBSqu1xbSHSk2h6kFnChOrBhxu5PujHkJk2r9/lgpDAq6M /C1L8+B0147WAUvUAE3FTwY+vYxnSC1JBvXCn4J2NcRvw4seakZhtTVazkUAsOxkFaoS wijYrUxUsUMcNNjJg8BfP2vIDvswoPa7slG5Ld0qQI5oV3eMkpyHLOC4AQXCL5CYMu30 klwkSMIMlmbXLdZXQ5rrFmXx8vlrCytiiPO2S81Vr4/Pd+BpfsSdeKfxMUVtsd9jXz6I 8aEw== X-Forwarded-Encrypted: i=1; AHgh+RrvbDVoj6+P5aZr8XQ40ib5v9DWK/0BfNcyrmxMea7mpxSwrHvm/SUdE0tmyuOeYt+y/fSMlTbEHcOAvsQ=@vger.kernel.org X-Gm-Message-State: AFuF++lIlCLBoHqV88Zr9MN7VD46CCyG6iU0o1zTbduBk6g1TLUNh+Uv 3H3qByb+lqItti4vKc6F0hVkXKiFE3+u7DJp09D3dOq0pp66cUxmmxpG X-Gm-Gg: AR+sD10fBdMjbPRAFQUc2l+EwZImgCTu2pszG28fLjH2dgLX5UlquilQbnI7aOIG8ce NrpzYw1NvDpbejBMUj+zIEtgcoPEZm58X8vZP97vQvSpLyDV3tNFk+C9Wb5K88YdWsRnEMhgb1i LMGN2O0Hx0L35hUVv4aGbeXDkuiciwkz6SsXbGNoAxQ+/O4sDie7CkAqfgOokMrKnF5cAET4AgO ug/zZYn5BDxpN6E68JyaC6+sA4uxl2ae/KF9rMt2hFX3a17Uz3IKHZLmDM7Vdk0wKMH7uBXi4vo ZzQJUQdusWNd8yCe1qe/XbUADcZJLMVJ0I4vSuQ/tZt6haRYzKRIB3t71uHoUVeBG2OBOmWXrRF Ibs3QLjb3T9DORs+VJ53ZpPi9s7Twdj/2d4uOI2PSzz59B9IS8gnIVb7Uww/y6KtoMvGCkfQI2u ItAkgpHCz50OfJiD6jmQFDx9kOulT545WJOdl/T0pUXvRI+qd9OypbnLxMKFkT4UNGbvfL7ElpK BVe/FpxxFbhJZvq2+NAyCv2cHx4bDfKVjuSDO7rrBNJS1ualtaiMIvV00z3qdtQc/v3QA== X-Received: by 2002:a05:6512:1192:b0:5b3:11a0:968b with SMTP id 2adb3069b0e04-5b48b8979a8mr6248951e87.19.1787602456505; Mon, 24 Aug 2026 13:14:16 -0700 (PDT) Received: from yantra.. (dsl-trebng21-58c187-236.dhcp.inet.fi. [88.193.135.236]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5b48ce0cd9csm1923620e87.71.2026.08.24.13.14.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Aug 2026 13:14:16 -0700 (PDT) From: Rupesh Majhi To: Andy Shevchenko , Bill Wendling , David Lechner , Eddie James , Joel Stanley , Jonathan Cameron , Justin Stitt , Nathan Chancellor , Nick Desaulniers , =?UTF-8?q?Nuno=20S=C3=A1?= Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Rupesh Majhi Subject: [PATCH v6 4/6] iio: pressure: dps310: add triggered buffer support Date: Mon, 24 Aug 2026 23:12:01 +0300 Message-ID: <20260824201203.396651-5-zoone.rupert@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260824201203.396651-1-zoone.rupert@gmail.com> References: <20260824201203.396651-1-zoone.rupert@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a triggered buffer in order to capture continuously on both channels instead of one sysfs read at a time. Raw register value is not useful on its own, pressure has to go through the compensation polynomial and needs a temperature reading. Report raw in Pa with 1/1000 scale to keep full resolution in the buffer without changing what the existing processed attribute reports. Raw and processed reads return -EBUSY while buffer is on, so does any reconfiguration. Assisted-by: Claude:claude-opus-5 Signed-off-by: Rupesh Majhi --- drivers/iio/pressure/Kconfig | 2 + drivers/iio/pressure/dps310.c | 169 ++++++++++++++++++++++++++++++++-- 2 files changed, 165 insertions(+), 6 deletions(-) diff --git a/drivers/iio/pressure/Kconfig b/drivers/iio/pressure/Kconfig index 838a8340c4c0..cef8b90b9ae7 100644 --- a/drivers/iio/pressure/Kconfig +++ b/drivers/iio/pressure/Kconfig @@ -112,6 +112,8 @@ config DPS310 tristate "Infineon DPS310 pressure and temperature sensor" depends on I2C select REGMAP_I2C + select IIO_BUFFER + select IIO_TRIGGERED_BUFFER help Support for the Infineon DPS310 digital barometric pressure sensor. It can be accessed over I2C bus. diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c index 269a71ea3e7a..f122acd72b0c 100644 --- a/drivers/iio/pressure/dps310.c +++ b/drivers/iio/pressure/dps310.c @@ -21,8 +21,11 @@ #include #include =20 +#include #include #include +#include +#include =20 #define DPS310_DEV_NAME "dps310" =20 @@ -93,19 +96,60 @@ struct dps310_data { bool timeout_recovery_failed; }; =20 +enum dps310_scan_index { + DPS310_SCAN_TEMP, + DPS310_SCAN_PRESSURE, +}; + +struct dps310_scan { + s32 channels[2]; + aligned_s64 ts; +}; + static const struct iio_chan_spec dps310_channels[] =3D { { .type =3D IIO_TEMP, .info_mask_separate =3D BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO) | BIT(IIO_CHAN_INFO_SAMP_FREQ) | BIT(IIO_CHAN_INFO_PROCESSED), + .scan_index =3D DPS310_SCAN_TEMP, + .scan_type =3D { + .sign =3D 's', + .realbits =3D 32, + .storagebits =3D 32, + .endianness =3D IIO_CPU, + }, }, { .type =3D IIO_PRESSURE, + /* + * Pressure is only meaningful once the raw register value has + * been run through the compensation polynomial in section 4.9.1 + * of the datasheet, which needs a temperature reading as well. + * So what is reported as _raw here is already compensated, in + * Pa, and _scale converts it to the kPa the ABI asks for. The + * _processed attribute reports the same value and predates + * buffer support, so it has to stay. + * + * Do not copy this pattern into other drivers. A raw attribute + * that is not the raw register value is only tolerable here + * because the alternative is either losing resolution in the + * buffer or breaking existing users of _processed. + */ .info_mask_separate =3D BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO) | BIT(IIO_CHAN_INFO_SAMP_FREQ) | - BIT(IIO_CHAN_INFO_PROCESSED), + BIT(IIO_CHAN_INFO_PROCESSED) | + BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE), + .scan_index =3D DPS310_SCAN_PRESSURE, + .scan_type =3D { + .sign =3D 's', + .realbits =3D 32, + .storagebits =3D 32, + .endianness =3D IIO_CPU, + }, }, + IIO_CHAN_SOFT_TIMESTAMP(2), }; =20 /* To be called after checking the COEF_RDY bit in MEAS_CFG */ @@ -589,6 +633,11 @@ static int dps310_write_raw(struct iio_dev *iio, { struct dps310_data *data =3D iio_priv(iio); =20 + /* Reconfiguring mid-capture would change the values being captured */ + IIO_DEV_ACQUIRE_DIRECT_MODE(iio, claim); + if (IIO_DEV_ACQUIRE_FAILED(claim)) + return -EBUSY; + ACQUIRE(mutex_intr, lock)(&data->lock); if (ACQUIRE_ERR(mutex_intr, &lock)) return -EINTR; @@ -730,6 +779,13 @@ static int dps310_read_pressure(struct dps310_data *da= ta, int *val, int *val2, =20 return IIO_VAL_INT; =20 + case IIO_CHAN_INFO_RAW: + rc =3D dps310_read_pressure_value(data, val); + if (rc) + return rc; + + return IIO_VAL_INT; + case IIO_CHAN_INFO_PROCESSED: rc =3D dps310_read_pressure_value(data, val); if (rc) @@ -738,6 +794,12 @@ static int dps310_read_pressure(struct dps310_data *da= ta, int *val, int *val2, *val2 =3D 1000; /* Convert Pa to KPa per IIO ABI */ return IIO_VAL_FRACTIONAL; =20 + case IIO_CHAN_INFO_SCALE: + /* The raw value is in Pa, the ABI wants kPa */ + *val =3D 1; + *val2 =3D 1000; + return IIO_VAL_FRACTIONAL; + case IIO_CHAN_INFO_OVERSAMPLING_RATIO: rc =3D dps310_get_pres_precision(data, val); if (rc) @@ -819,12 +881,10 @@ static int dps310_read_temp(struct dps310_data *data,= int *val, int *val2, } } =20 -static int dps310_read_raw(struct iio_dev *iio, - struct iio_chan_spec const *chan, - int *val, int *val2, long mask) +static int dps310_read_channel(struct dps310_data *data, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) { - struct dps310_data *data =3D iio_priv(iio); - switch (chan->type) { case IIO_PRESSURE: return dps310_read_pressure(data, val, val2, mask); @@ -837,6 +897,92 @@ static int dps310_read_raw(struct iio_dev *iio, } } =20 +static int dps310_read_raw(struct iio_dev *iio, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) +{ + struct dps310_data *data =3D iio_priv(iio); + + switch (mask) { + case IIO_CHAN_INFO_RAW: + case IIO_CHAN_INFO_PROCESSED: { + /* + * Sampling here consumes the same measurement the capture path + * reads, so refuse while the buffer is enabled. + */ + IIO_DEV_ACQUIRE_DIRECT_MODE(iio, claim); + if (IIO_DEV_ACQUIRE_FAILED(claim)) + return -EBUSY; + + return dps310_read_channel(data, chan, val, val2, mask); + } + default: + return dps310_read_channel(data, chan, val, val2, mask); + } +} + +static int dps310_fill_scan(struct dps310_data *data, + const unsigned long *scan_mask, + struct dps310_scan *scan) + __must_hold(&data->lock) +{ + int rc; + int i =3D 0; + + /* + * The pressure compensation needs a temperature reading, so temperature + * is sampled even when only the pressure channel is enabled. + */ + rc =3D dps310_read_temp_raw_locked(data); + if (rc) + return rc; + + if (test_bit(DPS310_SCAN_TEMP, scan_mask)) { + /* Millidegrees Celsius */ + rc =3D dps310_calculate_temp(data, &scan->channels[i]); + if (rc) + return rc; + + i++; + } + + if (test_bit(DPS310_SCAN_PRESSURE, scan_mask)) { + rc =3D dps310_read_pres_raw_locked(data); + if (rc) + return rc; + + /* Pascals, see the comment on the channel definition */ + rc =3D dps310_calculate_pressure(data, &scan->channels[i]); + if (rc) + return rc; + } + + return 0; +} + +static irqreturn_t dps310_trigger_handler(int irq, void *p) +{ + struct iio_poll_func *pf =3D p; + struct iio_dev *iio =3D pf->indio_dev; + struct dps310_data *data =3D iio_priv(iio); + struct dps310_scan scan =3D { }; + int rc; + + mutex_lock(&data->lock); + rc =3D dps310_fill_scan(data, iio->active_scan_mask, &scan); + mutex_unlock(&data->lock); + if (rc) + goto err; + + iio_push_to_buffers_with_ts(iio, &scan, sizeof(scan), + iio_get_time_ns(iio)); + +err: + iio_trigger_notify_done(iio->trig); + + return IRQ_HANDLED; +} + static void dps310_reset(void *action_data) { struct dps310_data *data =3D action_data; @@ -893,6 +1039,17 @@ static int dps310_probe(struct i2c_client *client) if (rc) return rc; =20 + /* + * The device measures continuously in background mode, so a capture is + * just a read of the latest results and no buffer setup ops are needed. + * The trigger is not aligned with the measurements either way, so the + * timestamp is taken in the handler rather than by a top half. + */ + rc =3D devm_iio_triggered_buffer_setup(dev, iio, NULL, + dps310_trigger_handler, NULL); + if (rc) + return rc; + rc =3D devm_iio_device_register(dev, iio); if (rc) return rc; --=20 2.43.0 From nobody Mon Sep 28 08:02:24 2026 Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C51D238DC59 for ; Mon, 24 Aug 2026 20:14:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787602464; cv=none; b=HCcyf+pf5UZKVQHvIPd4t3h/iurwZkn5GGa+NJo+XusQtF/rXit+A4YWEfCu96cY4LeLi1jmxWQLJMvcRCDHZciukaEh8i7xBACdsu36VVo9LtugsRRhQTZN2ljBc3rlDan1GZKz1423DiPl9Zq57umFFksBBRYPRW9cFyCJRug= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787602464; c=relaxed/simple; bh=5Y4Ui7ASXnX2/fxd3WaMxXXqW1055XMY7zXqCakiBzY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hKXGNpA75zZ3Hmvhag6577cM/SECcRU2LFeAxHX/pgP2ieBMZMIZJsIjQhaKGLQ3JOrGvc4cD2lHjMkAqDGwSHTfWR8nIuikzsr+WcHXp7AXSzWnW1aRkI/rjbXzgX+D+EfQUFe25XUL2GTqWJKt39aSiDSNDLXAZnKOb3+fAnc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hdfEKLam; arc=none smtp.client-ip=209.85.167.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hdfEKLam" Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-5b14d1f9315so3431756e87.2 for ; Mon, 24 Aug 2026 13:14:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787602458; x=1788207258; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=+1teNulq1mG2liXyLQtq+EAs4stE38hsRBs7UIDWNmo=; b=hdfEKLamUROdRHv2/n0y4S8WmOBzBjtZLqO025G5E1il2E7fnv06J2Zu0zxVGYzQS2 llaDQhE+Jj8I9S5qGa1/3fOr7WpYeceiuePoHRNm2eFbD/V2D08DuiwA07/XYmgZrCe6 m13RfYN64nvdjmBCTjgbMnF7AEL3NLtdhqp01PguUVsHrrD7EUewHqSuj6UcOTnCPTa6 jSDw6zBXJLgRHnFKHv88buadPN4E7pC796oVFClhZs1ZcJ+yLCafSuVX1ouuOQCvL1lj vlqGX6uRshGZSv/imo1VSDevx5hnoPMB87+CSDLT/GhtRIlKosWWKKnV/9pTdj2X5JxI pevg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787602458; x=1788207258; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=+1teNulq1mG2liXyLQtq+EAs4stE38hsRBs7UIDWNmo=; b=bf9Wibso7fv/hCfRcnZIAHp/ntqebsXz4Svrq/hUSyDWfZ+Q6c2eFVohVDNHtp7Zng MPa/xfxPb43p+J3fsZie9VJwf4UQUFmjXdK6Nn3SWu2PrNXwi+5w9TgV34Sb49sQ38vJ bmtl0fIiDwGdqTv3E05T6TPutN/Z45fZlXmw9G1HM6x67CILGyaR7Ges8TY4UJxTP2dH bmr3e2pWJHaJzWjltA68sTw+zKSELMGH6HWpOnd8PyRpbuvQ4be3lDI9DCjM0kz7LzpF WdVH7GMAxnGEPvKuupbrbPoGa3YnqTN4cNIR3DYWHBbdIp/vGopVAZppLEr4v5zBg5WF 6Ckg== X-Forwarded-Encrypted: i=1; AHgh+RqRQz1d57WWuo2PsGG6urZ3YOzidP2QNNXUppr3hQYjGVhEIj80x8mW+xNY19gVsqtKgLeifV1u6T9aJbA=@vger.kernel.org X-Gm-Message-State: AFuF++m9PkOTUkc2ILyt76wKox583KYcKblFOqiCF8w1TVK+nGd70ClZ kkcW37zdYG6HuSm4SeRlBk4JVMA1PLjylNHI2O2GSYJTZev5vDnpNEdK X-Gm-Gg: AR+sD13bc+FLy0bi/mgw0nezBCsLMBh5CO4rH+M4c6noFWudVIxjIwIFaWFaMiO8dv1 EL915ni5G0DjJ3Dld8WCWrLAqLU8QGl+4T6lkxHHZ8gU3vDZHzSvup9c4oN0emQ+LiyOgq3cuQX Riy1yy793z+cLi2LY5nINMxE74jXPzGO0cSB2cdu186ZhQjCllcuo3N/m9XNo72x6hG4X/HbFDS tQbLXA4QLuzqTSJUd+jZFLZkcu4nAk9ZD+KU/xocis9idW9oAOHc8n+HsCHCP36MzgDO23bAR03 L1q/wzuhsWA83EHFATVyCUhBQZE7HyOuxtzbiY9+lSuvKBXwuDDTNE2ukQhhk56wZPF+6bOzmoI gktrCAVP0EAUr2UQVPYG7z5bNmlMOdZ/iZuht3KUXHxpBFlNrI8koJvZyC59YK//wiE9gVQLXEv Bdp6fo9Y2SWQapELyfCt+VuJ1Io1ybtdgqO0caS2FRuCocqZGllx6uglugFyJC1gYcwpJkp8H04 kKWHtCajZPeAOJBkedQYrFHjs2jfYGcbQEPdAv/+BWC2oHut+j8Supc46Y= X-Received: by 2002:a05:6512:3da0:b0:5ae:bcc4:c071 with SMTP id 2adb3069b0e04-5b484090f50mr10147641e87.0.1787602457292; Mon, 24 Aug 2026 13:14:17 -0700 (PDT) Received: from yantra.. (dsl-trebng21-58c187-236.dhcp.inet.fi. [88.193.135.236]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5b48ce0cd9csm1923620e87.71.2026.08.24.13.14.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Aug 2026 13:14:16 -0700 (PDT) From: Rupesh Majhi To: Andy Shevchenko , Bill Wendling , David Lechner , Eddie James , Joel Stanley , Jonathan Cameron , Justin Stitt , Nathan Chancellor , Nick Desaulniers , =?UTF-8?q?Nuno=20S=C3=A1?= Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Rupesh Majhi Subject: [PATCH v6 5/6] iio: pressure: dps310: add hardware FIFO support Date: Mon, 24 Aug 2026 23:12:02 +0300 Message-ID: <20260824201203.396651-6-zoone.rupert@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260824201203.396651-1-zoone.rupert@gmail.com> References: <20260824201203.396651-1-zoone.rupert@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Use the 32 entry FIFO for buffered capture, so a reader wakes once per batch of samples instead of once per sample. FIFO runs when no trigger is attached and stays off when one is. iio_verify_update() already picks the mode, so buffer setup ops just branch on iio_device_get_current_mode(), as rohm-bm1390.c does. Drain is on a timer because there is no interrupt to use and nothing in tree wires the INT pin. hwfifo_flush_to_buffer is not enough on its own: iio_buffer_read() sleeps until something is pushed, so a blocking reader would hang with samples still sitting in the FIFO. Hook is kept for poll() and non-blocking reads. Pressure entries drive the scans and reuse last temperature, so the two configured rates stay independent. FIFO does not timestamp entries, they are estimated from the sample rate. Assisted-by: Claude:claude-opus-5 Signed-off-by: Rupesh Majhi --- drivers/iio/pressure/dps310.c | 411 +++++++++++++++++++++++++++++++++- 1 file changed, 400 insertions(+), 11 deletions(-) diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c index f122acd72b0c..d05aa05d6222 100644 --- a/drivers/iio/pressure/dps310.c +++ b/drivers/iio/pressure/dps310.c @@ -2,16 +2,11 @@ // Copyright IBM Corp 2019 /* * The DPS310 is a barometric pressure and temperature sensor. - * Currently only reading a single temperature is supported by - * this driver. * * https://www.infineon.com/dgdl/?fileId=3D5546d462576f34750157750826c42242 * * Temperature calculation: * c0 * 0.5 + c1 * T_raw / kT =C2=B0C - * - * TODO: - * - Optionally support the FIFO */ =20 #include @@ -20,6 +15,8 @@ #include #include #include +#include +#include =20 #include #include @@ -58,9 +55,31 @@ #define DPS310_FIFO_EN BIT(1) #define DPS310_SPI_EN BIT(0) #define DPS310_RESET 0x0c +#define DPS310_FIFO_FLUSH BIT(7) #define DPS310_RESET_MAGIC 0x09 #define DPS310_COEF_BASE 0x10 =20 +/* + * Section 4.8: the FIFO holds 32 entries shared between the pressure and + * temperature streams, and stops recording once full rather than overwrit= ing. + * A late drain therefore loses the newest samples, not the oldest. + */ +#define DPS310_FIFO_DEPTH 32 + +/* Read back in place of a sample once the FIFO has been drained */ +#define DPS310_FIFO_EMPTY_VAL 0x800000 + +/* The LSB of a FIFO entry tags which measurement produced it */ +#define DPS310_FIFO_TAG_PRS BIT(0) + +/* + * Bounds on the drain interval. The lower bound keeps a fast rate from + * flooding the workqueue; the upper bound keeps the FIFO from filling whi= le + * nothing is looking at it. + */ +#define DPS310_DRAIN_MIN_MS 20 +#define DPS310_DRAIN_MAX_MS 2000 + /* Make sure sleep time is <=3D 30ms for usleep_range */ #define DPS310_POLL_SLEEP_US(t) min(30000, (t) / 8) /* Silently handle error in rate value here */ @@ -94,6 +113,15 @@ struct dps310_data { s32 pressure_raw; s32 temp_raw; bool timeout_recovery_failed; + + /* FIFO capture state, used only while the hardware FIFO is enabled */ + struct iio_dev *iio; + struct delayed_work fifo_work; + unsigned int watermark; + unsigned int drain_interval_ms; + s64 fifo_timestamp; + s32 fifo_temp_raw; + bool fifo_temp_valid; }; =20 enum dps310_scan_index { @@ -960,6 +988,339 @@ static int dps310_fill_scan(struct dps310_data *data, return 0; } =20 +static int dps310_fifo_hw_flush(struct dps310_data *data) + __must_hold(&data->lock) +{ + return regmap_write(data->regmap, DPS310_RESET, DPS310_FIFO_FLUSH); +} + +static int dps310_fifo_set_enable(struct dps310_data *data, bool enable) + __must_hold(&data->lock) +{ + return regmap_write_bits(data->regmap, DPS310_CFG_REG, DPS310_FIFO_EN, + enable ? DPS310_FIFO_EN : 0); +} + +/* + * There is no interrupt wired on any in-tree platform and the binding has= no + * interrupts property, so the FIFO is drained on a timer, at an interval = below + * the time it takes to fill. See DPS310_FIFO_DEPTH for why late is bad. + */ +static int dps310_fifo_interval(struct dps310_data *data, unsigned int *ms) + __must_hold(&data->lock) +{ + bool pressure_enabled =3D test_bit(DPS310_SCAN_PRESSURE, + data->iio->active_scan_mask); + unsigned int fill_ms, want_ms; + int rc, prs_rate, tmp_rate; + + rc =3D dps310_get_pres_samp_freq(data, &prs_rate); + if (rc) + return rc; + + rc =3D dps310_get_temp_samp_freq(data, &tmp_rate); + if (rc) + return rc; + + /* Both streams share the same entries, so they fill it together. */ + fill_ms =3D MSEC_PER_SEC * DPS310_FIFO_DEPTH / (prs_rate + tmp_rate); + + /* + * The DPS310 has no configurable hardware watermark, only a FIFO-full + * condition, so the watermark is taken as the number of scans the user + * is prepared to wait for and drives the drain interval instead. Scans + * come at the rate of whichever measurement drives them, which is not + * the pressure rate when only the temperature channel is enabled. + */ + want_ms =3D data->watermark * MSEC_PER_SEC / + (pressure_enabled ? prs_rate : tmp_rate); + + *ms =3D clamp(min(want_ms, fill_ms / 2), DPS310_DRAIN_MIN_MS, + DPS310_DRAIN_MAX_MS); + + return 0; +} + +/* + * Read a single FIFO entry. Returns 1 if a sample was read, 0 once the FI= FO is + * empty, or a negative error. + */ +static int dps310_fifo_read_entry(struct dps310_data *data, s32 *value, + bool *is_pressure) + __must_hold(&data->lock) +{ + u8 val[3]; + s32 raw; + int rc; + + /* + * Every entry is read through the pressure registers regardless of + * which measurement produced it, with the type tagged in the LSB. + */ + rc =3D regmap_bulk_read(data->regmap, DPS310_PRS_BASE, val, sizeof(val)); + if (rc < 0) + return rc; + + raw =3D get_unaligned_be24(val); + if (raw =3D=3D DPS310_FIFO_EMPTY_VAL) + return 0; + + *is_pressure =3D raw & DPS310_FIFO_TAG_PRS; + *value =3D sign_extend32(raw, 23); + + return 1; +} + +static int dps310_fifo_push_scan(struct dps310_data *data, s32 temp_raw, + s32 pressure_raw, s64 timestamp) + __must_hold(&data->lock) +{ + struct iio_dev *iio =3D data->iio; + struct dps310_scan scan =3D { }; + int i =3D 0; + int rc; + + /* + * The compensation helpers read the cached raw values. Sysfs reads take + * the direct-mode claim, so they cannot be looking at these while a + * buffered capture is running. + */ + data->temp_raw =3D temp_raw; + data->pressure_raw =3D pressure_raw; + + if (test_bit(DPS310_SCAN_TEMP, iio->active_scan_mask)) { + rc =3D dps310_calculate_temp(data, &scan.channels[i]); + if (rc) + return rc; + + i++; + } + + if (test_bit(DPS310_SCAN_PRESSURE, iio->active_scan_mask)) { + rc =3D dps310_calculate_pressure(data, &scan.channels[i]); + if (rc) + return rc; + } + + iio_push_to_buffers_with_ts(iio, &scan, sizeof(scan), timestamp); + + return 0; +} + +/* + * Drain the FIFO and push the samples it held, stopping once max_scans sc= ans + * are in hand or draining everything when max_scans is zero. Stopping at = the + * read rather than after it matters: entries leave the hardware as they a= re + * read, so any collected beyond the caller's limit would have to be disca= rded. + * + * Returns the number of scans pushed. + */ +static int dps310_fifo_drain(struct dps310_data *data, s64 now, + unsigned int max_scans) + __must_hold(&data->lock) +{ + bool pressure_enabled =3D test_bit(DPS310_SCAN_PRESSURE, + data->iio->active_scan_mask); + bool temp_valid =3D data->fifo_temp_valid; + bool is_pressure[DPS310_FIFO_DEPTH]; + s32 raw[DPS310_FIFO_DEPTH]; + unsigned int i, n =3D 0, scans =3D 0, pushed =3D 0; + s64 interval, first; + int rc, rate; + + /* + * Empty the hardware first and compensate afterwards, so the time spent + * in the polynomial is not time the FIFO spends filling. + * + * Pressure entries drive the scans and reuse the most recent + * temperature, so the two rates stay independent; entries arriving + * before any temperature cannot be compensated and are dropped. With + * only the temperature channel enabled there is nothing to pair with + * and temperature drives the scans itself. + */ + for (i =3D 0; i < DPS310_FIFO_DEPTH; i++) { + rc =3D dps310_fifo_read_entry(data, &raw[n], &is_pressure[n]); + if (rc < 0) + return rc; + if (!rc) + break; + + if (!is_pressure[n]) { + temp_valid =3D true; + if (!pressure_enabled) + scans++; + } else if (pressure_enabled && temp_valid) { + scans++; + } + n++; + + if (max_scans && scans >=3D max_scans) + break; + } + + if (!scans) + return 0; + + /* + * FIFO entries carry no timestamps. They are synthesised by working + * back from the drain with the configured period of whichever + * measurement drives the scans, so the spacing matches the sampling + * frequency the user asked for instead of varying with how much each + * drain happened to collect. These are estimates, not hardware + * timestamps. + */ + rc =3D pressure_enabled ? dps310_get_pres_samp_freq(data, &rate) : + dps310_get_temp_samp_freq(data, &rate); + if (rc) + return rc; + + interval =3D div_s64(NSEC_PER_SEC, rate); + first =3D now - (s64)(scans - 1) * interval; + + /* + * A batch must not start before the previous one ended, or the buffer + * would carry timestamps that go backwards. If this drain collected + * more than the configured rate accounts for, spread it across the + * window since the last sample instead. + */ + if (data->fifo_timestamp && first <=3D data->fifo_timestamp) { + interval =3D max_t(s64, div_s64(now - data->fifo_timestamp, scans), 1); + first =3D data->fifo_timestamp + interval; + } + + for (i =3D 0; i < n; i++) { + s64 timestamp; + + if (!is_pressure[i]) { + data->fifo_temp_raw =3D raw[i]; + data->fifo_temp_valid =3D true; + + if (pressure_enabled) + continue; + } else if (!pressure_enabled || !data->fifo_temp_valid) { + continue; + } + + timestamp =3D first + (s64)pushed * interval; + + rc =3D dps310_fifo_push_scan(data, + is_pressure[i] ? data->fifo_temp_raw + : raw[i], + is_pressure[i] ? raw[i] : 0, + timestamp); + if (rc) + return rc; + + data->fifo_timestamp =3D timestamp; + pushed++; + } + + return pushed; +} + +static void dps310_fifo_work(struct work_struct *work) +{ + struct dps310_data *data =3D container_of(to_delayed_work(work), + struct dps310_data, fifo_work); + int rc; + + mutex_lock(&data->lock); + rc =3D dps310_fifo_drain(data, iio_get_time_ns(data->iio), 0); + mutex_unlock(&data->lock); + + if (rc < 0) + dev_dbg(&data->client->dev, "FIFO drain failed: %d\n", rc); + + schedule_delayed_work(&data->fifo_work, + msecs_to_jiffies(data->drain_interval_ms)); +} + +static int dps310_hwfifo_set_watermark(struct iio_dev *iio, unsigned int v= al) +{ + struct dps310_data *data =3D iio_priv(iio); + + data->watermark =3D clamp(val, 1, DPS310_FIFO_DEPTH); + + return 0; +} + +static int dps310_hwfifo_flush(struct iio_dev *iio, unsigned int count) +{ + struct dps310_data *data =3D iio_priv(iio); + + /* + * With a trigger attached the FIFO is left disabled, and the pressure + * registers then hold the latest measurement rather than queued entries + * with an empty marker to stop on. There is nothing to drain. + */ + if (iio_device_get_current_mode(iio) !=3D INDIO_BUFFER_SOFTWARE) + return 0; + + guard(mutex)(&data->lock); + + return dps310_fifo_drain(data, iio_get_time_ns(iio), count); +} + +static int dps310_buffer_postenable(struct iio_dev *iio) +{ + struct dps310_data *data =3D iio_priv(iio); + int rc; + + /* + * An attached trigger drives the capture instead, so the FIFO stays + * disabled and the two never both feed the buffer. + */ + if (iio_device_get_current_mode(iio) =3D=3D INDIO_BUFFER_TRIGGERED) + return 0; + + guard(mutex)(&data->lock); + + data->fifo_temp_valid =3D false; + data->fifo_timestamp =3D 0; + + rc =3D dps310_fifo_interval(data, &data->drain_interval_ms); + if (rc) + return rc; + + /* Drop whatever accumulated before the buffer was enabled */ + rc =3D dps310_fifo_hw_flush(data); + if (rc) + return rc; + + rc =3D dps310_fifo_set_enable(data, true); + if (rc) + return rc; + + schedule_delayed_work(&data->fifo_work, + msecs_to_jiffies(data->drain_interval_ms)); + + return 0; +} + +static int dps310_buffer_predisable(struct iio_dev *iio) +{ + struct dps310_data *data =3D iio_priv(iio); + int rc; + + if (iio_device_get_current_mode(iio) =3D=3D INDIO_BUFFER_TRIGGERED) + return 0; + + cancel_delayed_work_sync(&data->fifo_work); + + guard(mutex)(&data->lock); + + rc =3D dps310_fifo_set_enable(data, false); + if (rc) + return rc; + + return dps310_fifo_hw_flush(data); +} + +static const struct iio_buffer_setup_ops dps310_buffer_setup_ops =3D { + .postenable =3D dps310_buffer_postenable, + .predisable =3D dps310_buffer_predisable, +}; + static irqreturn_t dps310_trigger_handler(int irq, void *p) { struct iio_poll_func *pf =3D p; @@ -990,6 +1351,17 @@ static void dps310_reset(void *action_data) dps310_reset_wait(data); } =20 +/* + * The drain reschedules itself, so make sure it is stopped before the dev= ice + * goes away even if the buffer was never disabled cleanly. + */ +static void dps310_cancel_fifo_work(void *action_data) +{ + struct dps310_data *data =3D action_data; + + cancel_delayed_work_sync(&data->fifo_work); +} + static const struct regmap_config dps310_regmap_config =3D { .reg_bits =3D 8, .val_bits =3D 8, @@ -1002,6 +1374,8 @@ static const struct regmap_config dps310_regmap_confi= g =3D { static const struct iio_info dps310_info =3D { .read_raw =3D dps310_read_raw, .write_raw =3D dps310_write_raw, + .hwfifo_set_watermark =3D dps310_hwfifo_set_watermark, + .hwfifo_flush_to_buffer =3D dps310_hwfifo_flush, }; =20 static int dps310_probe(struct i2c_client *client) @@ -1018,13 +1392,22 @@ static int dps310_probe(struct i2c_client *client) =20 data =3D iio_priv(iio); data->client =3D client; + data->iio =3D iio; + data->watermark =3D 1; mutex_init(&data->lock); + INIT_DELAYED_WORK(&data->fifo_work, dps310_fifo_work); =20 iio->name =3D id->name; iio->channels =3D dps310_channels; iio->num_channels =3D ARRAY_SIZE(dps310_channels); iio->info =3D &dps310_info; - iio->modes =3D INDIO_DIRECT_MODE; + /* + * Both buffer modes are advertised so that iio_verify_update() picks + * INDIO_BUFFER_TRIGGERED when a trigger is attached and falls back to + * INDIO_BUFFER_SOFTWARE, which the FIFO path uses, when one is not. + */ + iio->modes =3D INDIO_DIRECT_MODE | INDIO_BUFFER_TRIGGERED | + INDIO_BUFFER_SOFTWARE; =20 data->regmap =3D devm_regmap_init_i2c(client, &dps310_regmap_config); if (IS_ERR(data->regmap)) @@ -1040,13 +1423,19 @@ static int dps310_probe(struct i2c_client *client) return rc; =20 /* - * The device measures continuously in background mode, so a capture is - * just a read of the latest results and no buffer setup ops are needed. - * The trigger is not aligned with the measurements either way, so the - * timestamp is taken in the handler rather than by a top half. + * The device measures continuously in background mode, so a triggered + * capture is just a read of the latest results. The setup ops start and + * stop the FIFO drain when no trigger is attached. The trigger is not + * aligned with the measurements either way, so the timestamp is taken + * in the handler rather than by a top half. */ rc =3D devm_iio_triggered_buffer_setup(dev, iio, NULL, - dps310_trigger_handler, NULL); + dps310_trigger_handler, + &dps310_buffer_setup_ops); + if (rc) + return rc; + + rc =3D devm_add_action_or_reset(dev, dps310_cancel_fifo_work, data); if (rc) return rc; =20 --=20 2.43.0 From nobody Mon Sep 28 08:02:24 2026 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 831B438E5DF for ; Mon, 24 Aug 2026 20:14:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787602465; cv=none; b=g5sSPUeREY1yXjdaWYilwpnUjDU6w/u1QWj9o5ppAZpNv0qgJAeOtpSaBCwfDxyB+RdPaxzwTQaF+9Qk5aH+m+yJbOOyn4DvOIuZt70LrRgB8m5JhHimX3ZPjrfvyyZ/nTMfXexptQEEoqTVmrsn8oROqLN0vZ1sQEBSK+5p7iM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787602465; c=relaxed/simple; bh=m4oJxPscrxxq0i2z/68SeZy8svwkKCtvosHLYsFT6TQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KCHVH2NbmDKGYMKvtt11YH9Gxo/bk/JXPmEGcscZPkcyZVV71PQPOFaqR1eeePSisEgqqfEOgcgUc/xJ6uQjA9CHDDEq/VERVQwjxo5WsMEfhs/jEh7UM3eErplzm71H+In67rXxZMels23FgwyhXXt02a6Y6qVtePo0/fJvZrw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=i6yWh4Wu; arc=none smtp.client-ip=209.85.167.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="i6yWh4Wu" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-5b29599b81cso4847815e87.1 for ; Mon, 24 Aug 2026 13:14:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787602459; x=1788207259; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=EmhmgT8VKFfYQHk+qL1AZ/XS5DwXnr8XjJwyeM/eoq8=; b=i6yWh4WuqdCUe2M+nl6z1bi20P09S23LxM/Gkqli11poBHLY0gMBkMQQVJabQZaVB7 hm6tk2qypkdBwl8JpnYtNwKEitCD32205I8ihgc+EFlQtCROOb3ADMZ6C6LYBrYEQrKf pwArXLivHGezB12jMeI9fHSuZHG5UvKFl1kp36SLmcuOQln4asMluWNI/p5r1vss7I0T Wmv6HXkBoczBLqhn5IBjxU7HTcnaT9GhXe+mWCnkybA88rupjMTUVUuLYh/I206W8zZE Ctejg+Rz6RXiuHfeGv+3EGW4h3SMPKPIj7tYfBL0xQDHRQic9ChHwNTB/U5XrzkA9EMo prTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787602459; x=1788207259; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=EmhmgT8VKFfYQHk+qL1AZ/XS5DwXnr8XjJwyeM/eoq8=; b=eXcXFwz+3H5YFGEcgc+J1YVGE3tcbqFnZuU22iqEImbf/JRaEjhqj8y0OE1yCYc0ud qh/kuLIdEBtRoYpuyck46cseKkOEn6DfM8Jmb7j5Qx0OIaKqT2E1knZB1/XoxVh4oz04 JAodCNM/G35Wkqc1ODoBgbS1QHPbPkL0hqAp0ZLE8dSOgUUltChCcDCNNiR9vBn/4ZiU 0lpK1nsQZpS1Qt22RpcojzsSfy04F8PdxHdzYbsDh33Pm0ZvSySKYgTikA1HiUq4kaG0 +9yNACLvqeuK8emO4G3TVlhsZUFdu0DqoNEuFyMqjt3RMbZ+mFwmhqI2wIh8nKKIX2LH mnEA== X-Forwarded-Encrypted: i=1; AHgh+Rqr+A/khrIbqIseitIy4ohuj9Noib6Aw41pJJJFXrT2HYTM5gHO2E93D5wVIrA6sQtlWt7PO0vtvtWSPS0=@vger.kernel.org X-Gm-Message-State: AFuF++mCxbv90FItqi/w0QDl9PDrgBFXZHEJohM61Z77x4euF0V2WEqh mNMi6hL45edqGHw0d3GyCfN3zSWKTeE7c+nkI/Fv0keRClQ0qxhlUiXK X-Gm-Gg: AR+sD11Gyn1b1IiuTxe9HXGoRAmQ9sRs/9jVBwVDRb7kbooirqoHoLiNQxOQE5EEovi 5cIIg+5STJbjlO6qmkPLw3qSZ6kfMpPKyl59Cqp3NgqcbpNwcjvqt3oj7v423p3y1EkDPi02xNI lausARVNJIhkn8KG9uPVCjkvOE2nvo7iCOf/CJCLn6bCAyvja6swec65MW6hcigKjbcvRDPFbL0 HJUDo0vbq6NJaNm0PcpRihbwoOUjNMCXCbt53q2jM5AU0FqVjlkWxGgPhsfvLvEHxbDurXdszyf Av9bcaF9SzvwhZAM599jTDvlIWXmaATYAQC+i0sOXyTj9qCBfSrvRS7FCqdBHK0tELHi6oT8y/t eeRRR8XJNCN4EMqUUDDXQf/NnGZxcJbI2bGtPSEiAWemdgZPwNuvQ+sdGqnLkAbgzEM59IWUJYD 5bcgPkzLxI0qunH2IEHLvxTUgZvQmH4Ue5hHJXUrWzb4gV28Qw2AkDCm6ogr+utozjn5eI3LlHQ Cm0QZeoHnMDDTEF9DQDkW1MtJHDvux49V8I5f9rCm3NoidWuiZW4zQV1y8= X-Received: by 2002:a05:6512:2389:b0:5ae:cee7:52bf with SMTP id 2adb3069b0e04-5b48b67eed9mr5722292e87.9.1787602459341; Mon, 24 Aug 2026 13:14:19 -0700 (PDT) Received: from yantra.. (dsl-trebng21-58c187-236.dhcp.inet.fi. [88.193.135.236]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5b48ce0cd9csm1923620e87.71.2026.08.24.13.14.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Aug 2026 13:14:18 -0700 (PDT) From: Rupesh Majhi To: Andy Shevchenko , Bill Wendling , David Lechner , Eddie James , Joel Stanley , Jonathan Cameron , Justin Stitt , Nathan Chancellor , Nick Desaulniers , =?UTF-8?q?Nuno=20S=C3=A1?= Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Rupesh Majhi Subject: [PATCH v6 6/6] iio: pressure: dps310: check the lock markings with context analysis Date: Mon, 24 Aug 2026 23:12:03 +0300 Message-ID: <20260824201203.396651-7-zoone.rupert@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260824201203.396651-1-zoone.rupert@gmail.com> References: <20260824201203.396651-1-zoone.rupert@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" __must_hold() markings added earlier in this series are only documentation unless the file opts in, so switch the analysis on for dps310.o. Clean with clang 23.1.0 at W=3D1. It does run: dropping the lock around dps310_fill_scan() fails the build rather than going quietly. Assisted-by: Claude:claude-opus-5 Signed-off-by: Rupesh Majhi --- drivers/iio/pressure/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/iio/pressure/Makefile b/drivers/iio/pressure/Makefile index bc0d11a20acc..4b1a05f7a0bd 100644 --- a/drivers/iio/pressure/Makefile +++ b/drivers/iio/pressure/Makefile @@ -3,6 +3,8 @@ # Makefile for industrial I/O pressure drivers # =20 +CONTEXT_ANALYSIS_dps310.o :=3D y + # When adding new entries keep the list in alphabetical order obj-$(CONFIG_ABP060MG) +=3D abp060mg.o obj-$(CONFIG_ABP2030PA) +=3D abp2030pa.o --=20 2.43.0