From nobody Fri Sep 25 00:02:41 2026 Received: from mail-lf2-f13.google.com (mail-lf2-f13.google.com [74.125.229.205]) (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 EF1654E9C2D for ; Fri, 18 Sep 2026 12:25:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.229.205 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789734329; cv=none; b=AqPvxPFZmTvPt3dSPDy20eIkbVlR33PtMO5o6R4yLY8RPH/vWohfBflodQsXYZQgnoz46o5UfIeGq7RVUvv1Sxby1sSH6kIcaC09lPO6WvXZx4hFLSITmfjaSpSQxybZfOGTwAOoUbFwbArRKQh6BMWKBOMnyAJIEXWCWoiHLow= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789734329; c=relaxed/simple; bh=XEU3X6TrPs6UzvTqsbHKRzxHg0PLadxing8itj7f4nw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ot4puYnYM8P+xH5i/OaQyvF6rvRMtLIHluPn7eXPfU8ckDPxbrtFDTRHJanpA5Q+xAr3o2I+/XoEM0uVZDyZGwZA1IGtcY89nXMNhqiLLvzZpMG+VhpeZNhtSgGrtGQTEfG5/ERpGkj6GxwXXINnVzjvIeyZ/GtBnQGn3G2saeE= 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=jnwhAQkT; arc=none smtp.client-ip=74.125.229.205 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="jnwhAQkT" Received: by mail-lf2-f13.google.com with SMTP id 2adb3069b0e04-5b5e4f1651bso647318e87.3 for ; Fri, 18 Sep 2026 05:25:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789734321; x=1790339121; 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=OfR3YrnGEF1eVDtqqFJbMom6dYue/Q5AxIRNa4I1fXg=; b=jnwhAQkT5QOibrOI4GsyOst+ElbFwout/QutsXF0V/Xrzw+6XwIuIfg1Q791MqhXia S8WLl5Srl+Qw8Ey8yqjymFKZdNe9Wp4JCT7Vv2tmzrbyr1NBudYeXEs9ZWFz0W+7traA WFBqF9gImjs7dm2tFj42CCfrP4duM5RcsaKysFNy89xz1qCgpUrSfhC69NcLIiPoAeSq qVu1ZGtMc5yXsEMQ+H+NuU/kxEQJO0vppeC+ClE8z2r4bXjSypD/0W7E3LMoG+rcXYXd oYeeV/WeuOZsCtndQ8Jb8a2pnUlHCGHBMQ6WhUyeg1DDqcHPmofsuiBgi9sP47fQ56VS 3j4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789734321; x=1790339121; 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=OfR3YrnGEF1eVDtqqFJbMom6dYue/Q5AxIRNa4I1fXg=; b=L2t6UGMdAl4t2xdFDuZlYg+LudhNd5VGJZp0RcLsh7RrYEtPE9HCjNUUNpT4qa63a0 U07lB9UHSbc9wSVF3Bc7/Kx61gf7gr4DDDunWXwouftXQF/K0qnu41zD/DbK8MCOYXNj SwGuDF6G6yTpHpGByIW7X3NPdt3DX86GWFtI+bPprLA0GnsjT2yKus1jUzvepCm69XpM Gv2for5tcWqeos2suU70sMIJF4yvwK/1iLslOWScKvdFs0LTHtWx29SpRe3w0yTdIJwo uA6DlMagFubZIEWMXsIXQxs5659PzKBmed+eabIl7xlXqPtkA9BR2t6A0dkE0KvAwabG HyGA== X-Forwarded-Encrypted: i=1; AKwUvBzgAR3XpTgDIeOudbgfDpBgis5Ugg+dVA4T/o1KofgHGUtlY4BSAlqSKov9tEAC6lwlitT1t9kbzJ1P80Q=@vger.kernel.org X-Gm-Message-State: AFuF++lMo1yPFDDl9MtU5EgJAjGMLG8slnzcJoZUriRpy0zofqxm1Peg q43zQUcNtbovi1s5r/m2HxWQNuAkYZ9DCnWVgi/QLwruIMhfCKKUIypH X-Gm-Gg: AYBFou2u++NyMotIfrwGbPTWLW2f/qaxMFPTPi9R1ruWwcZtOVfI4XxYHIggJlte5lT OAdr6VFpy2hBpcrpnRe4wV4Fsx7G3px+djncd2+yN2zKkV5okh6+oH9RaEOrKmjQsOW4hPBXZ4G 5/uE8w0JNnXHoP2LawtE7KOeq8LUVfwgBtgu15f65p3nzqr5kP50ygd/wSMVVBHmIN0Ka/5pELu JVN7LnKAEaH2aPtpkAm5FZG66cTrXrfdqGlTWTYz4+40tYc8tDVFR9FFALfzUIC59qXSKyav4Lm WQdjwyieEGlRQH8Z8fulpUVPYVyLOLAqqOJqvvNzMEFYPYdkams+hOa9OH7qmDi2tDfIpJeiXZ9 GIvvyNviJWLLfkoin7n7LDj4ajostrm1177e2cTKZ56OnRJC84lsQsoCYLmW+6+rWOZDNcYfeEK rulfdBrU4GzncuZ1kV9EgJjQPDujSSaPdLz5mOVXgf3MuCdte+dtECeGBQqttm/95Gt/wLJqzwa 1hS8iBQ53Ab9GrGrDPZ6AZwEPHAWHnqnFYVbRAq8MpLkBLDiGuX+Y6Ev1RbD8XO4RDM4g== X-Received: by 2002:a05:6512:3baa:b0:5b6:4ae:3ff7 with SMTP id 2adb3069b0e04-5b8c18449abmr695430e87.31.1789734320670; Fri, 18 Sep 2026 05:25:20 -0700 (PDT) Received: from yantra.. (dsl-trebng21-58c187-236.dhcp.inet.fi. [88.193.135.236]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5b8c270ea53sm398549e87.12.2026.09.18.05.25.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2026 05:25:19 -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 v7 01/10] iio: pressure: dps310: fix CFG_REG bit definitions Date: Fri, 18 Sep 2026 15:25:08 +0300 Message-ID: <20260918122517.377565-2-zoone.rupert@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260918122517.377565-1-zoone.rupert@gmail.com> References: <20260918122517.377565-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: LLM 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 45bdb8c7670f..35260b399390 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 Fri Sep 25 00:02:41 2026 Received: from mail-lf2-f12.google.com (mail-lf2-f12.google.com [74.125.229.204]) (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 33D584EB866 for ; Fri, 18 Sep 2026 12:25:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.229.204 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789734330; cv=none; b=OjIaXNMsK+jxunVPxh1SjSO/wCqjMjjf2f1lDTMJG4oeObwzZeN2KACkCkroqcY7n2P4jCFMUzseXnuMY7kX8um6grIP/7r3dMwGDfqSF4mZhQoMDf4tyIQ+KGrhAqEW1TVhJiQzgcPb5FuNKoZLob0+6KqslhRg+RhIJNRV5uY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789734330; c=relaxed/simple; bh=Yj4RwbCvi7B7lQgZjaL6AuMOkRGQNU1rLzNzZVSRhLU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WqmYBpHgYVrPjtJOzg9yXvY0IItHcU2aQKGSNl8IzZZBLNwWaqNCP25x4eeOqqg91NNloQAcxQdrw/D7qyzNqUiugjOCAWU18gGICH6QNkVpEG6+kzhM6Alk9B+irFWUGd7NflyYMLs1QGg8VCy0TfhmwAM4amRx5gOmQURkYN8= 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=TewyKczt; arc=none smtp.client-ip=74.125.229.204 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="TewyKczt" Received: by mail-lf2-f12.google.com with SMTP id 2adb3069b0e04-5b5e4f13d77so747792e87.0 for ; Fri, 18 Sep 2026 05:25:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789734322; x=1790339122; 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=bIjQv3Ni12nKKfUqhl2wfffLShu1iZGR3QKWNIW24Vw=; b=TewyKcztUbm7jz1l3JyXaqkHyF5NpsyWTh1Db8yKsyA2VPHZdgHyY1GveURgAUHSO+ +C+ZpiCr3VjQNzIxCTqnHl4L10fpG3zkD9C1HUwXFAHh/yKsnzqttuwdNmzfloBRbUXz f0i9q8hkmYlJ61nza4p6SYDmLVnzJvWg6jazTee3p06jv6j0xJTyWatDxsq/YAAqqjqK psTPx84FQ7uLcqrdOj0erPdV7A6+jAxCaVovsUv1M1E6TOBLZXauEcGfMo0UqrT6eoXP sS9azI1McRUyr6o1kvx78ZwgTfbqOQ65Gz7SUa8XNVChOXtxLkfWcs0WGn1CEqTLiNfJ pQFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789734322; x=1790339122; 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=bIjQv3Ni12nKKfUqhl2wfffLShu1iZGR3QKWNIW24Vw=; b=pFb7zWp2Evbc0VSRv1ds/4erdHwhNbCccsIhTAmljk8Gb1kVuao0mgpnXnMjuEX5lf SEIQFGmSzuXW+mFNjS0f6ZivUoGtFNibzCTqMrvxOUnorM5lFlBsTcPyn36/IBGoHyCY 4/B9PX7Sc0vOVoEvCMyxzU8UmGIk0Et04L8LzOeTN22r0wlc3zs/WztufSy0+Oubq3+S YqsYUrd+E5za9rye2tg4DXLP40RbZMusy12BiC8IbPt71CuVHZeZWuRvVCjw2LdWbFnt u4pbkiARHggdSnA+GGMksqCpfrJL7j0fsqP+uof9CrtjYJiaLVQLvM7njLoswlNZthlJ 3SIQ== X-Forwarded-Encrypted: i=1; AKwUvByg5FVzt211JMrGQTADiZCUs+6kh/RSMfTmmMjJBzdQaXjj7K6uCB/U5jN2uNTWbsJAh2bzGHNmMs3uHPw=@vger.kernel.org X-Gm-Message-State: AFuF++nT63+QleFN3IhkBNSkTOQADBqry8rxxwaidhPfmhiRwhE8QSBd ka9X3TdJl+Xc2ft/T0URLVLxSeQwIVLVP7HOTjZdbXJWY8EcNebacMuv X-Gm-Gg: AYBFou1hLLfps1Q/nckwts9znL3+HQtOlIWUKYh236/QGp/ttVW5nl3+ugYf02mKYru pbQymTNW33aBevknwIhhN6EH1qyaoZvNr72ftrV0UMvJxZglGDsx1xjasyJwkSKtnKzBX6j/zOg ML6jENKDo7WSMVY/miyjYzf/6yg119ocXGPwpb8rLypmldXQKrHPbefKTTnfrtUcxF7T+kiLiKC td5u+t8Q/iFgYvFPHkjTUETIHtZooLT31O9x0accBjRVcmcA+pEOCCrSZszM9F6bbpNC59spAT/ WtUF2gn6EQ6qPRqEG293JxhZJyA5fC+Hus8iKvUDW6Vvv2rZss66BgT/jnCS/Yuek5SBsu+3ypE e8V0kzZTmFnsHM2cFtX/NFiBwnqiqdSGmgxwAUATTLC9/h3+Qi8QV+et/i5RrSy517muWlrUxeP bQRykGlfX5FJ5M2vptRCHI0upTIkcAlPBVYYitP/a/ibLedUt7jQ+X9QrEDBlxBzGRjreQfR/do 6x/pGIJchcqUDIeM8+FzQfjAiaNWSUqs5S8eXuWTIZ7URuZrfwdWpL8ozaCu2GAX7MNXES8Myjw i5Eh X-Received: by 2002:a05:6512:234e:b0:5b4:ac1b:89bc with SMTP id 2adb3069b0e04-5b8c1818e38mr752954e87.24.1789734321552; Fri, 18 Sep 2026 05:25:21 -0700 (PDT) Received: from yantra.. (dsl-trebng21-58c187-236.dhcp.inet.fi. [88.193.135.236]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5b8c270ea53sm398549e87.12.2026.09.18.05.25.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2026 05:25:21 -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 v7 02/10] iio: pressure: dps310: use a local device pointer in probe Date: Fri, 18 Sep 2026 15:25:09 +0300 Message-ID: <20260918122517.377565-3-zoone.rupert@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260918122517.377565-1-zoone.rupert@gmail.com> References: <20260918122517.377565-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 instead. Keeps lines short as more calls are added later in this series. No functional change. Assisted-by: LLM 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 35260b399390..bd7da4f12749 100644 --- a/drivers/iio/pressure/dps310.c +++ b/drivers/iio/pressure/dps310.c @@ -845,11 +845,12 @@ static const struct iio_info dps310_info =3D { =20 static int dps310_probe(struct i2c_client *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 @@ -868,7 +869,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 @@ -876,7 +877,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 Fri Sep 25 00:02:41 2026 Received: from mail-lf2-f13.google.com (mail-lf2-f13.google.com [74.125.229.205]) (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 324BA4EB859 for ; Fri, 18 Sep 2026 12:25:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.229.205 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789734330; cv=none; b=upcDYkXSEsUPE8/ICSQYJbmT6U7I2EuAxOkFZ7GDJTnl6mngEfS+GNG7SsWPKQrKeTDd+IqFnjbP0q+AXqNYJzWfJw/0kZ268KR9cCdrkqAs4Pp+kUnwDwhW1Yt++ItiLsuSPYt8tk65/YNN/E3EHuE5Pq+knSe0vT+PjHxXVHk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789734330; c=relaxed/simple; bh=2f3W7ewvZD9vQ7bzg12iNZ75xkP2pWmWjFYvl7E8R3Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Lg8qSlAUPNwuBywmH2ekfsIBiBpGmIaVmL5m8z2y96JZeHR9bX41FEmHH/rXLT2ZidG7GgPb9j/d5Vwpa73o8Z90w0Az/shVrCHjLyCMZE1T53GEHRGvHkHXGdsm2sg27ZbkLSLZQ8D3uBhNSWnADLa8gagm6IV9acrz21tMro0= 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=B/79rJ6o; arc=none smtp.client-ip=74.125.229.205 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="B/79rJ6o" Received: by mail-lf2-f13.google.com with SMTP id 2adb3069b0e04-5b8c1b8d7b5so510990e87.0 for ; Fri, 18 Sep 2026 05:25:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789734323; x=1790339123; 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=2j1Tv4agtRXuOvbEOgkc069No6p6dhHi73ng2NMw2ME=; b=B/79rJ6oBGFHcWWCezTYMlkT/VHthiSXZRuOqaFJthcYm+oSR69BiRiN4Y2eDAuFgP dhQ7Z0jBDQT3lI2FWVrnDVtS59URLfCfaO3Vw+w5LByqSiXJzMOTWgqLJ7XbwjRHINtD 9zSBmemnyn/oMGd/+h8l5x3pQCaNYahISK4epnQC0BdMpcpIa5yD87nOGE1YsczhpI5f Ie/2mQ807F9sK5JyJB1csimPNb2S4lnN1jE/i9Vy3Pk7B3dN0vYUFVJ4ZIvRTafbEpC2 Icn8PQUOMkJZVcCQyg+l6EKaULK8v0lpDb4SOvwnrBAuzE7BGxDTYlZDXHeTV6d66A5M 2BbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789734323; x=1790339123; 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=2j1Tv4agtRXuOvbEOgkc069No6p6dhHi73ng2NMw2ME=; b=2DzY2iZPQ3ID7Ww7xHrwaFAGL6DzWISZ0gQaiRJIP+chm5/L0U9MMd+6M3HmQL5prH 3anLB3RQwbfgvhJiNh6cgQnY2dGOAjoQNEGYO41FF/iwXvPzJrP092lHJx0UddAIBfgL wd7aX0bL0mYh2AVn83fdKlUJvQyPQ8Cp5ioRQiCLNUfpigATI3IQW0OX/elMIZwiGnfQ tjB34GXWNOffL5z6xg12ffW9Eu1arr6rktawbqy5e6vT81Wb1cu0nmzm6A8jcv2JSAwa JGdxFgME3k6ecCgiND884tI8BxT82nFy3smCgFsx8pQQ6rx25NdJLTe15gRwpP4Enpnp sXYQ== X-Forwarded-Encrypted: i=1; AKwUvByL/n9WR6qC60kFqsDCBkLueI/sb7aYqjiM1Zza9MCAocVSDD4fzDjUQ8vwOrYkHMovBNvOMA1sHHVDQig=@vger.kernel.org X-Gm-Message-State: AFuF++mwOBNu+bXQs9DeP4mLwloe7Nuc9vNzQixk8j+PchbF+8EKA2U9 ORvIpV4+H3U1nG32fUx0G7oGflKMGtIf3kRrqyuP7H5CHtEgrjSWSqCM X-Gm-Gg: AYBFou0xpnQBbIz8O11s7jtyesiL3F9jEEw/ouOz4+EfMZdzM2vNcSAWPx/RQdCd/qI PcbET6pKUU6POxKrGlD2RVur/GSrXLObFE1VrzgLAnZ0APz6DQthpeBwkv0XRB2a+ROIspeW6hM rhLTgkvdN/k0OOofFcAGvJ+PMEOWVuAlSP0hipjRqIQsm9xV/kVhu1CTOLljsBqD4ugua6rTxIT BZ0kKDKrG1l+W7f/aZ9Z0rHXJt8u2AGNPjsO46414VALMRs6FDn4VR53fOimU2CbhFTfjZwpysy Sx6vt5AJysoQ8bo43/Hjo4n6+S2QDXyQMCqxjV4x1DNZbG7D80EDcAKMCkxza8xJ74PvOHNttDp p2Y8e3UbhWk1HW6GrfoCZiTzNsa2OEnayTMEF4TegSEZd4XH1Gn7EwN77T6LthzL8+sWzEimnZa Ot8JUhqungqt999eVBmNYE4tBXbTS+EYtu1vk/w/+TbfiVuW8EoIVJKVYtf681uMc0YuWZAbMpt FVXaf9Uhvf8W1bTCVgUAMZRIAeqPPSWIP/cxFNX93cFIBss9OdA718nAWvqnFc2q7C7Ig== X-Received: by 2002:a05:6512:1293:b0:5b8:9ee1:10fd with SMTP id 2adb3069b0e04-5b8c195b2a3mr741943e87.32.1789734322491; Fri, 18 Sep 2026 05:25:22 -0700 (PDT) Received: from yantra.. (dsl-trebng21-58c187-236.dhcp.inet.fi. [88.193.135.236]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5b8c270ea53sm398549e87.12.2026.09.18.05.25.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2026 05:25:22 -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 v7 03/10] iio: pressure: dps310: use get_unaligned_be24() for the 24-bit results Date: Fri, 18 Sep 2026 15:25:10 +0300 Message-ID: <20260918122517.377565-4-zoone.rupert@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260918122517.377565-1-zoone.rupert@gmail.com> References: <20260918122517.377565-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" Pressure and temperature results are big-endian 24-bit values. Build them with get_unaligned_be24() instead of open-coded shifts. The coefficients are packed into the bytes rather than byte-aligned, so they stay as they are. Assisted-by: LLM Signed-off-by: Rupesh Majhi --- drivers/iio/pressure/dps310.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c index bd7da4f12749..e7f173e08e01 100644 --- a/drivers/iio/pressure/dps310.c +++ b/drivers/iio/pressure/dps310.c @@ -19,6 +19,7 @@ #include #include #include +#include =20 #include #include @@ -468,7 +469,6 @@ static int dps310_read_pres_raw(struct dps310_data *dat= a) int rc; int rate; int timeout; - s32 raw; u8 val[3]; =20 if (mutex_lock_interruptible(&data->lock)) @@ -489,8 +489,7 @@ static int dps310_read_pres_raw(struct dps310_data *dat= a) if (rc < 0) goto done; =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); @@ -502,14 +501,12 @@ static int dps310_read_temp_ready(struct dps310_data = *data) { 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 2.43.0 From nobody Fri Sep 25 00:02:41 2026 Received: from mail-lf2-f13.google.com (mail-lf2-f13.google.com [74.125.229.205]) (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 CE4052BE7DD for ; Fri, 18 Sep 2026 12:25:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.229.205 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789734336; cv=none; b=M2ZJlgYDjANs7fWwdRGXo6Z1U+kx6iMJQtEz9sTJS4gugbLKENyyFW9g+Cnz1k5CBVNK88b3N7hKb+tjSK54ZthxZJvm3JcmMwDdNDVM2yJeHzoC+IbZphxubanCdFBKo76DHycta6elZwht9P3E8tKIwkH4A+R1Q85gQCSzYpQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789734336; c=relaxed/simple; bh=M8fIINHnIxZB6qEGrsAABH8P+wRPzJ0kqqIWTT4CBow=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gIavaO0iMTKkwjJNHx30a5IkMp19g2C/ZpaCE5pKKaIb4DeyfJKHKwtOEE1tTI8w4ewkmmpZnAYOZTOJD+T9niDYy6cZHkaUAiF3AVn9cpUTflhrMQxclXoPeoBTCEnPE1sPK5s2POWu+eXABqx+cRpZyEuiwsHYy7givljFcjE= 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=nXq3XYTY; arc=none smtp.client-ip=74.125.229.205 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="nXq3XYTY" Received: by mail-lf2-f13.google.com with SMTP id 2adb3069b0e04-5b5e4f1b845so567114e87.1 for ; Fri, 18 Sep 2026 05:25:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789734324; x=1790339124; 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=4ceWGBhcz2v2+A70YlsGrXNu+jmKzqHeUxRvhPX+bxg=; b=nXq3XYTY6s/x0zRbVUrohCt+ZHA8MISkmwS7N1dZ4s8cgzuM1SaTfyNqfe3UqpFvEJ hpuCE9T76vwZ+yTobtHCmt2YBUrROFq3N+ABYPBphztof8yUU79OQT7kMFPaty83lTyz z1MFe9hG9hWTeWHdB9zWyQE4L5NW2DugwM0RZHYwEIkKlU0LYHsPBcYW9nFhxd3+Tgbr 11tQyulCoF46UxT+5VHrMn6j1GhowYuLXXk3LIkke9w5AuBImDs79XgIzuOa1RhZx/tR 9XV83Z+zWrip5BSKlLnvoxuXnckt6UyV2UtNfe/E8oGqO9qPnH2WApGF2/KHpf6FZFcB 94eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789734324; x=1790339124; 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=4ceWGBhcz2v2+A70YlsGrXNu+jmKzqHeUxRvhPX+bxg=; b=zdqbvVDu2Oc+68aELDNYLubmWUyfKAGbhr75ilkPV7dI1zaUj8LbewsA3bdFHuXIdz bBp2FAFThrjagj5gAEmkd+AXdjK7Jyk7U3yz2v3+Km+EysW6wi4i52SfLqvzp7OYaquG japotT3nLuYLk6qX+lp+GdK+taFQwaEOnsOzxD8JwLtyE+vR92TlZxcwNR397MkoHktS UfGXfze2DbjnJUo3u2DnMpLs7DnNYikWyc8ByQ4XEEAomZg+6yvmj+Ue8dRABKCqUx5y MwFLQYTTqSNfSukDBqMD9YcwYT9GDQfww0uA41z+HCBhBEmaDIkrEgV1O6w+DANCAICp wwTw== X-Forwarded-Encrypted: i=1; AKwUvBzNpz5Z7qCtpRkihp5Xz+f2gRgJTN/8YuStQWv+RuQLPdAPXTZJTQK0Ki2Nxu4nRie5WkeS795AYk+LMh4=@vger.kernel.org X-Gm-Message-State: AFuF++kDZkHVY0KhzFhyWBy8t7mLsnqOfQNGYsqTakFh3WDKzSgCPvR3 q4NaPtThuDZGBt0PPaClZD/T+Q1+OLSg2AVQVvkUdUTThJTcIJF/FXP9qAdNu386 X-Gm-Gg: AYBFou39sZSCQvNmZsqSnEfP6Oe8awpz8OUHRd7p4wusuCXkIvauvyW1OHOTb1vfK1P b5ce+hUUD4kzz8mae1OnR1wFCMDsIY8pjHDT5hl05CXqks5g/R5G8lAKi4JPJRuKJg4cv9WqL1W zAw1vHmUyAlpc0Z9hIva97xJv60qFVgpueKdcgwiW81E2y7gmhC8QdUB1SHI0ATb0Op0PV8vBrn 5Qi7p0ZiZb7PAefDrnq02it/KBK2s6tPCdzqM30n9pYp2oHDDgJjpJvVajLD5PULR+55JA1B4UO tmTjcQd+6q98W5YB8Wxe+j3ziBP+tI1JCFVMhPKQ8zR7ePtFd/CfzUKFR//K4nLb/aL6oeLuMtT UX1L0jtMbIP2rby8s4mDlccsLR+bp9Ifu1+QuVh96XpwwrKXCdj4xXTsRpdF+33EGpIRbIdl3eB qzFbqLUkXwUCTOcfTXn0CKLSZUvz7bWmfKzrb4KSRNndvF3eQ887/d1SLYjXvefQYQYzCKQDuM1 roWgdfotrtOxN6IOC0FSx57Z/MKw9G5RYgTbMcnxf0b13F7ptXEzcWs1JIBESlkZoST/w== X-Received: by 2002:ac2:5681:0:b0:5b6:1a7c:aa24 with SMTP id 2adb3069b0e04-5b8c1986428mr845036e87.60.1789734323440; Fri, 18 Sep 2026 05:25:23 -0700 (PDT) Received: from yantra.. (dsl-trebng21-58c187-236.dhcp.inet.fi. [88.193.135.236]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5b8c270ea53sm398549e87.12.2026.09.18.05.25.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2026 05:25:22 -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 v7 04/10] iio: pressure: dps310: take the lock once per raw read Date: Fri, 18 Sep 2026 15:25:11 +0300 Message-ID: <20260918122517.377565-5-zoone.rupert@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260918122517.377565-1-zoone.rupert@gmail.com> References: <20260918122517.377565-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" A processed pressure read takes the lock twice: once in the raw read, then again when dps310_calculate_pressure() trylocks to refresh the temperature. The refresh is skipped whenever the lock is busy. Split the raw reads into variants that expect the lock held and give each channel a helper that takes it once for the whole sequence, so the temperature refresh is unconditional. Buffered capture later in this series needs the same shape. Mark the functions that need the lock with __must_hold() rather than a comment, and include cleanup.h, which ACQUIRE() needs and was coming in transitively. Assisted-by: LLM Signed-off-by: Rupesh Majhi --- drivers/iio/pressure/dps310.c | 143 ++++++++++++++++++---------------- 1 file changed, 77 insertions(+), 66 deletions(-) diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c index e7f173e08e01..8cefca928077 100644 --- a/drivers/iio/pressure/dps310.c +++ b/drivers/iio/pressure/dps310.c @@ -14,6 +14,7 @@ * - Optionally support the FIFO */ =20 +#include #include #include #include @@ -287,8 +288,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; @@ -306,8 +307,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; @@ -325,8 +326,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 @@ -339,8 +340,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 @@ -439,6 +440,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 @@ -464,40 +466,36 @@ 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; 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 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]; @@ -511,31 +509,40 @@ static int dps310_read_temp_ready(struct dps310_data = *data) 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); +} + +/* Best effort: on error the previous temperature stands */ +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) @@ -577,59 +584,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; @@ -653,15 +648,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 @@ -707,6 +693,23 @@ static int dps310_calculate_pressure(struct dps310_dat= a *data, int *val) return 0; } =20 +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) { @@ -721,11 +724,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 @@ -744,6 +743,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; @@ -765,6 +765,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) { @@ -779,11 +794,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 Fri Sep 25 00:02:41 2026 Received: from mail-lr2-f41.google.com (mail-lr2-f41.google.com [74.125.230.105]) (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 408854E9C17 for ; Fri, 18 Sep 2026 12:25:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.230.105 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789734341; cv=none; b=R4QVi/MZ/xHkhlsRPF2XY+Nv+VZf393Mro8z8Q173ULMRXHs50j9LAnQUX5Udy5NiOIkvfqhzWtK8z/Zh1s91G7lEFwAWpl3yF5zcuD3m5Lq1tN9UL7Gf8SR4Yxj0N+DKiDUN2VRIWn5JnUV4KrYVfLCF4lC6RklrbeJXiOSjlw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789734341; c=relaxed/simple; bh=laksdeSdPu2zA6kfA0TK1uIuDUMTPBAhLTpGoGGPG4U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tCXL/4MGJhhsWY/IhLrQkf0hojIGoFCKvsb9RLzQNRb63SshG8zQu3f6YSxLOx7zJtJC1EzJcklRGwTrTljg4MX5zifxA8+ZCAieQpah81UwfNa6qajkhGuymHsyuWWf7qCf50EAWBqzYdCF5V08dc8DsW1QMpPSaZA9QS0SSQY= 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=NPlGpvja; arc=none smtp.client-ip=74.125.230.105 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="NPlGpvja" Received: by mail-lr2-f41.google.com with SMTP id 38308e7fff4ca-3a2ff176d7eso4811381fa.3 for ; Fri, 18 Sep 2026 05:25:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789734324; x=1790339124; 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=60p97ewNtG9tKiPuMUOcTc/j/UXlUPAQ6cFtl0QC6Hg=; b=NPlGpvjach0+zo82mgGJjz/fcY+/5EzzNVOVwTBB8fDpwARaDz0V0rSKOAuum+7cz4 tb+4mOC0OimV0WjzIZKcbwQsL8F4xUi9yJUIJjvIfXktk6oDaIg1S0MZgx8EjSxHQN1w MVSHeZgHhRMup1PEVSa2loYSaWeTaHZHnZAOW9ohAKXMnhjWwuRYG6M7H1JjjEDb5ilZ vGl6PZxiN8Y6ooXMd38UUf39gJhl17SrpbSVPo5yk/DhK4UCi8ogifZgYyTnvzNuEloB flRYXxoGZiqMRmI4ZGF2ujiZge3JGr3yZEQPKA1+o3IXDSdH5jJfkKpFICY6wSAlo0/o IYWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789734324; x=1790339124; 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=60p97ewNtG9tKiPuMUOcTc/j/UXlUPAQ6cFtl0QC6Hg=; b=E/FxpS2miNIWZBNOzUNVYzaqSdrH6o5xXlbV86HggLGWnz1dh1y7EziWT0lsuxg+Ms r4/bhqs/pNVZpaD9yHdde8/+swhcVz2qR26k1gmNNr0KvY5s1muNtyryjKsA9CGOPu4m FKsbHlU/cXzagFwBUZn0i5sNGwOm9ntr+SXjB+bhJfuAaRn0s4+/+KIv9Yh0KOxFq6nS G/1mFoPrLuXdMRkzDoU4k5Yg67T2x2qJchfJsn0HrjhL8SGQ/LNKA+Y0eZY1AYxw9q6+ 1f0uxtwGGqF7enr5+/tZFgHuYaPE+74aWM55hHGrwkpOMCMm6Kz3GMISMiiSX2UOz8qh PM2Q== X-Forwarded-Encrypted: i=1; AKwUvByyXQfLUPhFavCJOqEaDz2bfgekpkykHRo2N42LNEqs/qauBp6y8Kt3eYScKdnJl4BdH6NEZme3NrheqYQ=@vger.kernel.org X-Gm-Message-State: AFuF++lWCp5uSTkTtZrYJCqrtaEMfp6wkBRT4HE+RGRe8G5ccL67mKVW zgd1NLko8av/r2XbdE3e5Wpuhw4x9AT27JNWoWQJEvi3F+MVQr4IBfEZ X-Gm-Gg: AYBFou29hjaoxnVSAL9Suu57HGRfL0wwbT73P/JiQ0yfir3LF8FF5dzC7SnibEuQd27 aD13vzFkGcE3XFzUbM6ft8aVgrCv9HL6Xtt+2FbDfOtSlE+YxNGCXztIuDO3noyyCau8N8zbEhh Cp1qYcjJE1sHXyoYv8x2as9B5T8TJuJUaL/b/41LwHGuNGAWCpnyNs2+liRoTTn3fX5YXZ16Sjr I1J7gvHEpsfe766mr18XL0EDKeRlH+r9vMtpYirruwtJlpMVQfvbEnPiRup3P70VftPX7l2Pvje mYHPGo+XkFPofcFHdjO2tLvKfe3umNIBMAkoW9YBYIG9D4eKy1V9O84TWiVJAylxDok8aC+2PvD 7DjJsePgpCmZAPJLZymJMI0Om/Oj8TfNpTIC/KCBLakrZ3imMxBs6YbGhq1cSFzVl8ORAm2+ceq t2GigzWpraxQK67pk+qfrHfddt4E02WuHGC+jMuny97TdPKLMbhh1K3/gwyoXJ+ZCG4dauhDmna 9/vX+miHlwcZEdV0gvZMkUmJUfVdYETuHzoM3ftIibzeeFs7sUCgX8F8pmXS4goW15z4g== X-Received: by 2002:a05:6512:1389:b0:5b7:6489:37c7 with SMTP id 2adb3069b0e04-5b8c179d8cdmr728262e87.0.1789734324360; Fri, 18 Sep 2026 05:25:24 -0700 (PDT) Received: from yantra.. (dsl-trebng21-58c187-236.dhcp.inet.fi. [88.193.135.236]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5b8c270ea53sm398549e87.12.2026.09.18.05.25.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2026 05:25:23 -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 v7 05/10] iio: pressure: dps310: add triggered buffer support Date: Fri, 18 Sep 2026 15:25:12 +0300 Message-ID: <20260918122517.377565-6-zoone.rupert@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260918122517.377565-1-zoone.rupert@gmail.com> References: <20260918122517.377565-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 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: LLM Signed-off-by: Rupesh Majhi --- drivers/iio/pressure/Kconfig | 2 + drivers/iio/pressure/dps310.c | 151 ++++++++++++++++++++++++++++++++-- 2 files changed, 148 insertions(+), 5 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 8cefca928077..dd816d47bbec 100644 --- a/drivers/iio/pressure/dps310.c +++ b/drivers/iio/pressure/dps310.c @@ -22,8 +22,11 @@ #include #include =20 +#include #include #include +#include +#include =20 #define DPS310_DEV_NAME "dps310" =20 @@ -94,19 +97,50 @@ struct dps310_data { bool timeout_recovery_failed; }; =20 +enum dps310_scan_index { + DPS310_SCAN_TEMP, + DPS310_SCAN_PRESSURE, +}; + 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, + /* + * _raw here is already compensated (section 4.9.1, which needs + * a temperature too) and in Pa; _scale converts to the kPa the + * ABI wants. _processed predates buffers and has to stay. + * + * Do not copy this into other drivers. A _raw that is not the + * raw register value is only tolerable because the alternative + * is losing resolution or breaking existing _processed users. + */ .info_mask_separate =3D BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO) | BIT(IIO_CHAN_INFO_SAMP_FREQ) | + BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_PROCESSED), + .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 */ @@ -586,6 +620,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; @@ -723,6 +762,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) @@ -731,6 +777,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) @@ -812,12 +864,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); @@ -830,6 +880,87 @@ 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: { + /* This consumes the measurement the capture path reads */ + 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_channels(struct dps310_data *data, + const unsigned long *scan_mask, + s32 channels[2]) + __must_hold(&data->lock) +{ + unsigned int i; + int rc; + + /* Compensation needs a temperature, so it is sampled either way */ + rc =3D dps310_read_temp_raw_locked(data); + if (rc) + return rc; + + i =3D 0; + if (test_bit(DPS310_SCAN_TEMP, scan_mask)) { + /* Millidegrees Celsius */ + rc =3D dps310_calculate_temp(data, &channels[i++]); + if (rc) + return rc; + } + + if (test_bit(DPS310_SCAN_PRESSURE, scan_mask)) { + rc =3D dps310_read_pres_raw_locked(data); + if (rc) + return rc; + + /* Pascals, see the channel definition */ + rc =3D dps310_calculate_pressure(data, &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 { + s32 channels[2]; + aligned_s64 timestamp; + } scan =3D { }; + int rc; + + mutex_lock(&data->lock); + rc =3D dps310_fill_channels(data, iio->active_scan_mask, scan.channels); + 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; @@ -885,6 +1016,16 @@ 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. The trigger is not aligned with + * the measurements, so the timestamp is taken in the handler. + */ + 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 Fri Sep 25 00:02:41 2026 Received: from mail-lf2-f13.google.com (mail-lf2-f13.google.com [74.125.229.205]) (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 1CAE74E8E19 for ; Fri, 18 Sep 2026 12:25:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.229.205 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789734339; cv=none; b=UdmO5XEz2xs4rjtV6cOZYaYq+pj/QU358i+i0XdkCMYeMHa2kPxVUQFOcv9+WYQIqTl8MRTN3SMUZLVmd6cQHw9lq3FGBqJrvVSu6XeXcZF5AqpkrvTEBxpZbIhW6TtXXRBWS8BlC65w8wQj4VMaVK8iF6GvY3ng/+/uUogOuDg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789734339; c=relaxed/simple; bh=LqBSm3USoMc1NhaRdGxHYrJshaTcBLFmk+HruTyC934=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hFtCPLXBVMaze6MJqdTgWR6IX+63QXMxrH4dI5KRSzVQQWfIXMeie+7peCteAD3D+jsmvtaT8RST8iFjcSJjPTKbBOR2tliSXyReHgk05hyp8tgAsuJF7pd4+wV/FZxGtf6ITO9Tjtq4uqPKRLXdxXJ8Fi1vPTqV1bKx0uvYqzw= 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=dMelwOQV; arc=none smtp.client-ip=74.125.229.205 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="dMelwOQV" Received: by mail-lf2-f13.google.com with SMTP id 2adb3069b0e04-5b5e4f13d76so722945e87.3 for ; Fri, 18 Sep 2026 05:25:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789734325; x=1790339125; 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=tl5FK/P0IILzUPHeJ1tB9KQK9WXKF1I6DTxx+ou/T/Q=; b=dMelwOQVFF66kAG3ertbmXXbtBZLfsljfipx08+1qZ27yikuLRt5jGLMSz7F0BOKvF zxnImRUGYLq3OZkICJbYmzAGYa7J3UUNttj5dwMjx0Malmhzr9ywqho+gYEiljj7uOkI i2kVQaLqFaxF8YivVzhNIQ/3t0vv5wLqmjDw2g89xhWkvkPNivdbwRj0Z9sCH8gpfnm/ 1ND5pcY9U/20DOSWg+6tZfhbb+g8g3co+r0i3H2jy//Fz1iX094sA5x8F3cfXwdIe9fv supH57sNicCN732A89506kw/lCQ3FWzOhpAJzOzwSb2B+jbU1zsBQQroetKWrjIfaFDl 8pOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789734325; x=1790339125; 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=tl5FK/P0IILzUPHeJ1tB9KQK9WXKF1I6DTxx+ou/T/Q=; b=ma5L8feIbPHCrbZQoVBztGhGFzBR18oBq5coI0GBvXREQi1qc+D6lmPgAj3fbAxDTo uIHiD6UJXq7DChmbnTcg02RTNdmyATIhXcckAcAkEHNNIaRT2DVOw/3J3oNR0DNp1QHM K6NPEqtNFQR5P44rgDgbzG32fJwV03XHsWsMqvXdQcWvTVjZAcyBbgq2c9zLZvLcsRAt MfWMb7llgYka++zPaTqinjZqqWpzBHcE/00pdHH0GhW/rEybwokPavo6HcMWmo67PX3E CG5GdGJ2ugzhqvaWEl3YWcP4mTE93CRXMIpGZGt6QMuKEwdBWgEt8JNwCeTE3d7B4YyQ RXTQ== X-Forwarded-Encrypted: i=1; AKwUvBxI9B3kp/Qy6POaEqrMgvOBwDoraQpe0lK8akPe6Py01dss7hl8hSYBnrwxQB3EbU/ZuTWF9R89UxaGg3M=@vger.kernel.org X-Gm-Message-State: AFuF++mwhXRXKMzfhQqcsEjtn4ZcrHHAbdKxIL2pecpFCHaU4rYSSW+G zBKjdw546TJPevAkNyRktsNfF06LUomIgw4NUuB96ZhQp6gQ/okY2+Qg X-Gm-Gg: AYBFou0j0wxn+jl7QWscYtrOBm96cFPgpg9+9jUCnjpQJGba9DGXA0QFYjoa7OZ6UZV pmqXZ1oPSa47bcYpoInxVcJx3kOmxcqIgU4hCxTTgA+v1IDKq2jlU3mrKjXTcJgr43Sfx26KMuL a4sPHn5FMFW9xXTY/FaLHlwKGQCMA0IejN5kPSkh9P1W94NH/SaZzFfkE2e6BM8ZiYcyY9a8ffA qpDOUrmIJASKEy3AgQoZs2nRPaa9FGFqq6wkcKlmqeQMrkUmW2T84lkq8u6xogE22zgd/Ox3PPM jBQBGCnO2L8N1M37nCXq/t7GMkzBTb2jo8INeXdbPQjH36/8Wa47MaM6wO4T4Jm/nSgbTJp4F3x B5Z9ofBvRcmWhwRTgRyIXlln9Lc3oIvJr3L3ZSAVhC+BI73RG603t0JPJMFGYHcoU35tlnMo+iV asOQ8dBl8Yyixeo4xyklT1HfTWK7w00KoswNAcrgnmknqfb6vhTFZkAAkbHuYNUlUWg6mZ2Bz0k 3yNulkbDuCHTNyime5nL5JfYmjsaPKjaiVnwpW+T+YwXVo1wOtYR53BihAnMUkj4+4m8sY8KqMP kRcm X-Received: by 2002:a05:6512:6894:20b0:5b8:b331:19b8 with SMTP id 2adb3069b0e04-5b8c184e382mr435418e87.38.1789734325210; Fri, 18 Sep 2026 05:25:25 -0700 (PDT) Received: from yantra.. (dsl-trebng21-58c187-236.dhcp.inet.fi. [88.193.135.236]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5b8c270ea53sm398549e87.12.2026.09.18.05.25.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2026 05:25:24 -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 v7 06/10] iio: core: add an accessor for scan_timestamp Date: Fri, 18 Sep 2026 15:25:13 +0300 Message-ID: <20260918122517.377565-7-zoone.rupert@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260918122517.377565-1-zoone.rupert@gmail.com> References: <20260918122517.377565-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" indio_dev->scan_timestamp is __private, so a driver has no way to ask whether the timestamp channel is in the current scan. Hide the ACCESS_PRIVATE() behind a read-only helper, the way iio_get_masklength() already does. The dps310 FIFO patch later in this series is the first user: that hardware does not timestamp entries, so it refuses a buffer with the timestamp channel enabled. Suggested-by: Jonathan Cameron Assisted-by: LLM Signed-off-by: Rupesh Majhi --- include/linux/iio/iio.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h index 989c1db8fb36..a893e36be988 100644 --- a/include/linux/iio/iio.h +++ b/include/linux/iio/iio.h @@ -1083,6 +1083,15 @@ static inline unsigned int iio_get_masklength(const = struct iio_dev *indio_dev) return ACCESS_PRIVATE(indio_dev, masklength); } =20 +/** + * iio_scan_timestamp_enabled - Is the timestamp channel in the current sc= an + * @indio_dev: the IIO device to check + */ +static inline bool iio_scan_timestamp_enabled(const struct iio_dev *indio_= dev) +{ + return ACCESS_PRIVATE(indio_dev, scan_timestamp); +} + int iio_active_scan_mask_index(struct iio_dev *indio_dev); =20 /** --=20 2.43.0 From nobody Fri Sep 25 00:02:41 2026 Received: from mail-lf2-f13.google.com (mail-lf2-f13.google.com [74.125.229.205]) (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 D60994EC647 for ; Fri, 18 Sep 2026 12:25:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.229.205 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789734339; cv=none; b=im5n6JgDxXRlZPDq++raGrdTfWoRIcI5eIN9gEJLUPRjNzPZu5WAs2gQbiBA4BfgaZw7sNXkYmwpT6GWFM0MYPMcZrKrXQFbzAetsdnq6+QyVkY3BITiJgMuMkRia74xm1aJfHYB3O9r0k2ClXKqDrWCdkVUdSqCiQ+qdb/1dCo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789734339; c=relaxed/simple; bh=BqD+7tSzLxTJxUspsiSX8hEETeKDZb8PtvBn/q2GlbY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cfAVYo8csUQKnpzSVTiU+Gu3BIR+ofPi5xwSJk/kSYx+5aX4nMr+Kw9VH0J0r9rmNqs4pE/Z85L6su5rlkuseso9jZrS5eKnr9WPCs4W6dDlVaj/WfHNcLXVM9vVZDaSn0MFTVQYStSXUDoDbFB2frQ8LMPYTUTQAQwvu7OoTr4= 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=Mj8RbSpS; arc=none smtp.client-ip=74.125.229.205 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="Mj8RbSpS" Received: by mail-lf2-f13.google.com with SMTP id 2adb3069b0e04-5b8c58fd069so176124e87.3 for ; Fri, 18 Sep 2026 05:25:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789734326; x=1790339126; 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=Tq3h6JKJmzsaFI+i9MuIchESUOERl8g67kAMYSTdEy0=; b=Mj8RbSpS+EPbFDRrYoS349ciVhy1uEgvokHxwM/ZyVBr9qamriOdFbT2taoqJOXKFy dhx1DYfNINgyTMky2mi9ZQEtKtyeJu27uijc7AwyKNtoailvA5r/04/rm6z1DDsGD/vE jm/JOH0aEMZGu5fLXjLWAD7+uAKWWjLavf4vhxPxj+BZtz9nzcSCd4a7VEnjylVMCHGW uzXrezgnOYFyfSDVfuu9vUDifPmjtE98eDZe8/XiNMPxDfJ+N5WrQuhpaKWr5Cka+UhN f8Fir1WWs8/tA8NjkkWnwaIRC6vE0d9+tO8wmOTglYOZwLrzlU85X1EyJTQODJG48+1/ 4pyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789734326; x=1790339126; 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=Tq3h6JKJmzsaFI+i9MuIchESUOERl8g67kAMYSTdEy0=; b=APjFLtzWakLo+LECfvvUT2EvkBVobcBnIZMyCpPUlc8R5uPWiRZCfmbmhNDYeO/vWF Dqxe/6CTma4OlGfjnBsEqDXmsEfHQItXcHQEo/H3cNvcdgVZCGHyxhv73Lt2lvxwsj2P cEpbREyzwZl/FjZgpyH/+/mJla6snE3Pv/3xlvOfWMAYUXLP/w5fni1gs1S1+UJJ6B1s v2fKnko5yJAWRoyR/RQo2nk1VE8hYBln6aMV14t9SjZajQwjRaqIXGip09AZolgFcnTq w7rtRhIUA6A7gnT5rjYb+bnHyOMg2KfjZgWgPQL5Ydldp5w7+zBAyTLvL2HeT/zcD+ts j/Gw== X-Forwarded-Encrypted: i=1; AKwUvByG6e/JicQ3Qs1xDrbOgxuSLxbXT0OmvKF/gYFUv0uPbX+pVQYmDNdoOPLP/v3u6E9ZRk0ry/SvAkM63yI=@vger.kernel.org X-Gm-Message-State: AFuF++nLf/Y5OBhFYOCjZJX50Qmv1vYP881XVyxIqQtnxW8FV7BZXYSB vE7o+9kA+gyzT2yVmfYpY0UFBNAE9BlzwbrU+BKwuubOhwnVTlEB2U1p X-Gm-Gg: AYBFou1IY79lgxIw2VUYGAKUFgBjZozFH6lu2Zs3hDfXIbeA/kp7qT/BdkQrXpz7mtA 1Y6vPwIp0D5w0R1cKanh9FLeVsJtrd5Cf3SUwBLNsNu1T2u8aoQEVgdaJD+ddBEpzvk/qSX+fhq KEdkIvAsjQPoDV/uNZoXeRKkDUi6Df7BLppcvP0ftDLuMXnwVNofO7xBlFeF4Vt+SaOkQ6lBFJM Iq6Cp79z0fzJ85clOCbTjMfp1T+tS1q569NxEYY8FlIQa064Lllet8dvoUzQBQKz3TMlg5Xtt0N hMWq7v6bfGNr0ZGykyBP0NeFB0HGw7PQdY4KmowNNEd9F59pnHXOlm9vRKunGZs/z1zWQeIhJR7 GwadW90TcH4LgSc4XKWxXwahZ8LWGu6B4kilHcQyK7SmEXRN0H1FP3L+d8CKBQQepUr+FAOMhJA N2Vyiqjr8Iq+JM/M1R1rsesNQJBaaNdzO7d0PgREsCHe7xYaoXCfuqC5pJD+5GSFXe5VVamhJOy yOgrLGcRCL+PAanjYD58i42FBt0WK4Irvb4+vJ6qVVn+HqxSv8ZcfX4zdXxyoRT44s9fw== X-Received: by 2002:a05:6512:110a:b0:5b8:99a5:5162 with SMTP id 2adb3069b0e04-5b8c180e6cfmr704214e87.26.1789734326022; Fri, 18 Sep 2026 05:25:26 -0700 (PDT) Received: from yantra.. (dsl-trebng21-58c187-236.dhcp.inet.fi. [88.193.135.236]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5b8c270ea53sm398549e87.12.2026.09.18.05.25.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2026 05:25:25 -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 v7 07/10] iio: pressure: dps310: read buffered samples from the hardware FIFO Date: Fri, 18 Sep 2026 15:25:14 +0300 Message-ID: <20260918122517.377565-8-zoone.rupert@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260918122517.377565-1-zoone.rupert@gmail.com> References: <20260918122517.377565-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 The DPS310 has a 32-entry FIFO shared by both measurements. Drain it from a work item and push what it held, so a buffered capture needs no trigger. Nothing in tree wires the interrupt pin, so the work rearms itself at half the time the FIFO takes to fill. Entries carry one measurement each, so a pressure entry is compensated with the temperature ahead of it. Pressure read before the first temperature of a session is held until one arrives rather than dropped, so the first push can wait a temperature period. FIFO entries are not timestamped, so postenable refuses the timestamp channel unless a trigger is attached. Tested on a DPS310 on a BeagleBone Black. Assisted-by: LLM Signed-off-by: Rupesh Majhi --- drivers/iio/pressure/dps310.c | 371 +++++++++++++++++++++++++++++++++- 1 file changed, 360 insertions(+), 11 deletions(-) diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c index dd816d47bbec..e63ea7873e5b 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,7 +15,10 @@ #include #include #include +#include #include +#include +#include =20 #include #include @@ -59,9 +57,22 @@ #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: 32 shared entries. Stops when full, so late drains lose da= ta */ +#define DPS310_FIFO_DEPTH 32 + +/* Read back once the FIFO is empty */ +#define DPS310_FIFO_EMPTY_VAL 0x800000 + +/* LSB tags which measurement produced the entry */ +#define DPS310_FIFO_TAG_PRS BIT(0) + +#define DPS310_DRAIN_MIN_MS 20 +#define DPS310_DRAIN_MAX_MS (2 * MSEC_PER_SEC) + /* 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 */ @@ -95,11 +106,28 @@ struct dps310_data { s32 pressure_raw; s32 temp_raw; bool timeout_recovery_failed; + bool fifo_temp_valid; + + /* Used only while the FIFO is enabled */ + struct iio_dev *iio; + struct delayed_work fifo_work; + s32 *fifo_hold; + unsigned int fifo_hold_max; + unsigned int fifo_held; + unsigned int drain_interval_ms; + s32 fifo_temp_raw; +}; + +enum dps310_fifo_entry { + DPS310_FIFO_EMPTY, + DPS310_FIFO_TEMP, + DPS310_FIFO_PRESSURE, }; =20 enum dps310_scan_index { DPS310_SCAN_TEMP, DPS310_SCAN_PRESSURE, + DPS310_SCAN_TIMESTAMP, }; =20 static const struct iio_chan_spec dps310_channels[] =3D { @@ -140,7 +168,7 @@ static const struct iio_chan_spec dps310_channels[] =3D= { .endianness =3D IIO_CPU, }, }, - IIO_CHAN_SOFT_TIMESTAMP(2), + IIO_CHAN_SOFT_TIMESTAMP(DPS310_SCAN_TIMESTAMP), }; =20 /* To be called after checking the COEF_RDY bit in MEAS_CFG */ @@ -936,6 +964,306 @@ static int dps310_fill_channels(struct dps310_data *d= ata, 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_assign_bits(data->regmap, DPS310_CFG_REG, DPS310_FIFO_EN, + enable); +} + +/* + * No interrupt pin is wired in tree, so drain on a timer. Both measuremen= ts + * share the entries, so they fill it together. + */ +static unsigned int dps310_fifo_interval(int prs_rate, int tmp_rate) +{ + unsigned int fill_ms; + + fill_ms =3D MSEC_PER_SEC * DPS310_FIFO_DEPTH / (prs_rate + tmp_rate); + + return clamp(fill_ms / 2, DPS310_DRAIN_MIN_MS, DPS310_DRAIN_MAX_MS); +} + +/* Returns which measurement the entry came from, or a negative error */ +static int dps310_fifo_read_entry(struct dps310_data *data, s32 *value) + __must_hold(&data->lock) +{ + u8 val[3]; + s32 raw; + int rc; + + /* Entries come out of the pressure registers whichever made them */ + 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 DPS310_FIFO_EMPTY; + + *value =3D sign_extend32(raw, 23); + + return raw & DPS310_FIFO_TAG_PRS ? DPS310_FIFO_PRESSURE : + DPS310_FIFO_TEMP; +} + +static int dps310_fifo_push_scan(struct dps310_data *data, s32 temp_raw, + s32 pressure_raw) + __must_hold(&data->lock) +{ + struct iio_dev *iio =3D data->iio; + s32 channels[2] =3D { }; + unsigned int i; + int rc; + + /* Direct-mode claim keeps sysfs reads off these */ + data->temp_raw =3D temp_raw; + data->pressure_raw =3D pressure_raw; + + i =3D 0; + if (test_bit(DPS310_SCAN_TEMP, iio->active_scan_mask)) { + rc =3D dps310_calculate_temp(data, &channels[i++]); + if (rc) + return rc; + } + + if (test_bit(DPS310_SCAN_PRESSURE, iio->active_scan_mask)) { + rc =3D dps310_calculate_pressure(data, &channels[i++]); + if (rc) + return rc; + } + + iio_push_to_buffers(iio, channels); + + return 0; +} + +/* Pressure seen before any temperature, kept until one turns up */ +static void dps310_fifo_hold(struct dps310_data *data, s32 pressure_raw) + __must_hold(&data->lock) +{ + if (data->fifo_held < data->fifo_hold_max) + data->fifo_hold[data->fifo_held++] =3D pressure_raw; +} + +/* Returns scans pushed */ +static int dps310_fifo_push_held(struct dps310_data *data) + __must_hold(&data->lock) +{ + unsigned int i, held =3D data->fifo_held; + int rc =3D 0; + + for (i =3D 0; i < held; i++) { + rc =3D dps310_fifo_push_scan(data, data->fifo_temp_raw, + data->fifo_hold[i]); + if (rc) + break; + } + + /* What did not go out stays for the next drain */ + data->fifo_held =3D held - i; + memmove(data->fifo_hold, &data->fifo_hold[i], + data->fifo_held * sizeof(*data->fifo_hold)); + + return rc ? rc : i; +} + +/* + * Read the batch out before compensating it, so a pressure entry pairs wi= th + * the temperature preceding it rather than the last one in the batch. + * + * Returns scans pushed. + */ +static int dps310_fifo_drain(struct dps310_data *data) + __must_hold(&data->lock) +{ + bool pressure_enabled =3D test_bit(DPS310_SCAN_PRESSURE, + data->iio->active_scan_mask); + u8 kind[DPS310_FIFO_DEPTH]; + s32 raw[DPS310_FIFO_DEPTH]; + unsigned int i, n =3D 0, pushed =3D 0; + int rc; + + for (i =3D 0; i < DPS310_FIFO_DEPTH; i++) { + rc =3D dps310_fifo_read_entry(data, &raw[n]); + if (rc < 0) + return rc; + + if (rc =3D=3D DPS310_FIFO_EMPTY) + break; + + kind[n++] =3D rc; + } + + for (i =3D 0; i < n; i++) { + if (kind[i] =3D=3D DPS310_FIFO_TEMP) { + data->fifo_temp_raw =3D raw[i]; + data->fifo_temp_valid =3D true; + + if (!pressure_enabled) { + rc =3D dps310_fifo_push_scan(data, raw[i], 0); + if (rc) + return rc; + + pushed++; + continue; + } + + rc =3D dps310_fifo_push_held(data); + if (rc < 0) + return rc; + + pushed +=3D rc; + continue; + } + + if (!pressure_enabled) + continue; + + if (!data->fifo_temp_valid) { + dps310_fifo_hold(data, raw[i]); + continue; + } + + rc =3D dps310_fifo_push_scan(data, data->fifo_temp_raw, raw[i]); + if (rc) + return rc; + + 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); + 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)); +} + +/* + * First temperature is one temperature period away at most, which bounds = the + * pressure before it. Rates cannot change while the buffer runs. + */ +static int dps310_fifo_hold_alloc(struct dps310_data *data, int prs_rate, + int tmp_rate) + __must_hold(&data->lock) +{ + data->fifo_temp_valid =3D false; + data->fifo_held =3D 0; + + if (!test_bit(DPS310_SCAN_PRESSURE, data->iio->active_scan_mask)) + return 0; + + data->fifo_hold_max =3D prs_rate / tmp_rate + 2; + data->fifo_hold =3D kcalloc(data->fifo_hold_max, sizeof(*data->fifo_hold), + GFP_KERNEL); + if (!data->fifo_hold) + return -ENOMEM; + + return 0; +} + +static void dps310_fifo_hold_free(struct dps310_data *data) + __must_hold(&data->lock) +{ + kfree(data->fifo_hold); + data->fifo_hold =3D NULL; + data->fifo_hold_max =3D 0; +} + +static int dps310_buffer_postenable(struct iio_dev *iio) +{ + struct dps310_data *data =3D iio_priv(iio); + int rc, prs_rate, tmp_rate; + + /* An attached trigger drives the capture instead, FIFO stays off */ + if (iio_device_get_current_mode(iio) =3D=3D INDIO_BUFFER_TRIGGERED) + return 0; + + /* Entries are not timestamped and the drain timer is no substitute */ + if (iio_scan_timestamp_enabled(iio)) + return -EINVAL; + + guard(mutex)(&data->lock); + + 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; + + data->drain_interval_ms =3D dps310_fifo_interval(prs_rate, tmp_rate); + + rc =3D dps310_fifo_hold_alloc(data, prs_rate, tmp_rate); + if (rc) + return rc; + + /* Drop whatever accumulated before enable */ + rc =3D dps310_fifo_hw_flush(data); + if (rc) + goto err_hold; + + rc =3D dps310_fifo_set_enable(data, true); + if (rc) + goto err_hold; + + schedule_delayed_work(&data->fifo_work, + msecs_to_jiffies(data->drain_interval_ms)); + + return 0; + +err_hold: + dps310_fifo_hold_free(data); + + return rc; +} + +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); + + dps310_fifo_hold_free(data); + + 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; @@ -968,6 +1296,14 @@ static void dps310_reset(void *action_data) dps310_reset_wait(data); } =20 +/* The drain rearms itself, so stop it even if the buffer never disabled */ +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, @@ -995,13 +1331,20 @@ static int dps310_probe(struct i2c_client *client) =20 data =3D iio_priv(iio); data->client =3D client; + data->iio =3D iio; mutex_init(&data->lock); + INIT_DELAYED_WORK(&data->fifo_work, dps310_fifo_work); =20 iio->name =3D DPS310_DEV_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 modes advertised: the core picks TRIGGERED with a trigger + * attached and falls back to SOFTWARE, which the FIFO path uses. + */ + 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)) @@ -1017,12 +1360,18 @@ 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. The trigger is not aligned with - * the measurements, so the timestamp is taken in the handler. + * The device measures continuously in background mode, so a triggered + * capture is just a read of the latest results. The setup ops run the + * FIFO drain when no trigger is attached. The trigger is not aligned + * with the measurements, so the timestamp is taken in the handler. */ 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 Fri Sep 25 00:02:41 2026 Received: from mail-lf2-f12.google.com (mail-lf2-f12.google.com [74.125.229.204]) (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 11DDA41A4E7 for ; Fri, 18 Sep 2026 12:25:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.229.204 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789734337; cv=none; b=fSFa5raHKCi55di3dh7C36tMthba9qJKlPg2uAaLfhDPZ8EEEkSjbweCVOo/uZI39aErKPZa4YFMzaaoyX3NRv3ZgS8VY2+/j64xGOSgpYaUzfSc/feQycJo7o4ywgab3ycPJxiX3boykCV0QsHLNcMghguhLqqcQmCG52uTJA4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789734337; c=relaxed/simple; bh=HDxsKpPajvO1pDBGt+Cg3JRzppun/aKifwXpwM5P7LI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kK0tka6D/dksBypAx7VVLcrI2QKlyc7yI+V0r+38MJOxo2vtYdzip6wnTfNabmFpw0C9zQaThHj89kjdxryZC5Jm+JdX8jGKbpn6wN5a4Uv8avr/nc1H0TrP4T/MoZfdnht5k7Mv2MFj0cpnhJnXiXgJmsnmb+mFoFJtDRnU/98= 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=kFKyhL8y; arc=none smtp.client-ip=74.125.229.204 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="kFKyhL8y" Received: by mail-lf2-f12.google.com with SMTP id 2adb3069b0e04-5b76462aae9so482138e87.2 for ; Fri, 18 Sep 2026 05:25:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789734327; x=1790339127; 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=qM09fZNeu0wGJcMJFEcwruCO/xWOafFLtCE4C1cUZM0=; b=kFKyhL8ygNcnRZB0whSwib+wdlJnytcQwJKakGRDN+5ia4oW3YAH3H+Kk4F/PttPsp uU95buPLgDe7aLLUVDo4BApfuLClZ/cz+vQpTDds6VktD95OkTzssxaKyxf4X5mQZunH gkz0Ks1Z46Q6kKe3B7d1B/fWJ4zkABBfNWn/oJh2gLDXe7NOFenhtYOizWt3gwFcJGmn EtC64z5jl/oD88JwrT3xTLc9E7yukAL2kcNnXPdCTf5/OdahLi3cPOJmrs8SD9oZfSrQ cRBHtGwTL3/HnsjeDMC5lXv9PlZFz1X9r/4RUQEjRUkQeQ22nhxTcoAJb4tDCL9dfyi+ Ogqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789734327; x=1790339127; 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=qM09fZNeu0wGJcMJFEcwruCO/xWOafFLtCE4C1cUZM0=; b=ws8k6U9jDF8cJ8kTs/hn7HqCMKGtuJsqbPXXACVTuVZorWwPFIqx1N1Yd71OYmWw7e rYlsM6EX6uzypli+q+Vy0+x/CZYzlWrxEATv8BpK1yiBWn9mFqX89aeGB17bsq9dFvVO 5sOZeC3XakdygQNeeKE8S8KNrG8LWKYCpB5DG9aWRjMUkag6OmkRCxtBkSCOVoucPACe AiJsis1jrljBIQgcJjFKTligfi+K5G9/qVAYaM1RcvuWG4zYde+sfexs0y2PuUaKGw0x vILJbC55g0ZBI9OTcAP5ebJdzDPGM0H9FkfWSn2tlRszcPs62vcwtTfcIT/yh/bDa66o RAvw== X-Forwarded-Encrypted: i=1; AKwUvByI+edywt4g6hwctFupzvIXCxxmM8cZ/QdQM5Qny01YNwa/mkhWTlGrIQ72s7rWXEeFYr+4Vx+CV0N+R8Y=@vger.kernel.org X-Gm-Message-State: AFuF++nW+y5wT7/PXExg09Yak7+5+vaUsrhxzLLAgJazJA+r7iIWNGEE S9ZCI7wQs5EROZsrfGVppEVUP/ktlvOBpNQBcGj7fYZ1t5V5qPpIEKaH X-Gm-Gg: AYBFou14HzkYlfEIWpCAP4uC99oHnFuQnFq2IhZ1yGyd4kxg6g1InkXLve8OmLEBCbM yU8+Z848vP7gqCEq8ojOMhMXblVqgQTvIIrgj0i6Cd35hFmvTWtjxSFwjqZsAImjLhfymZj8JrQ SjET4dlQmdSGuUBikIlcGmg/840Tcv+bsxyPszThZiBlagzhnceyjN/ANacWWe8ZxRcxdR01U6A wQ9Rj2OKSee3rDpAuj5dwL+e/gsVzEmZn0lcxSp9F1BlH6YlIs5uYx1QiWkh4WfjcFjWf2Jw81W Xx7LbfwVDISEEygmZZQwTeypjh8DMfQRcf7BiXVHsbiMdca8ZCay+3DbVFk1HfGOoeUf72VNpFT bGFkCzDFhTZvU0Acn7XEFY01ZrqX0tzBqw2xD6E6DhSyQ2FgtdLCdZfksfSDjWgI/3dZhwT9DUx jKoNMWcLpPvL1vEMCMtYK46eUp+PURRts8Wk3I13gwWWuMZZbXP6uif7a9z7m0CFZE9mW6cmpuI 5HY/w5tLsXZtSTbeq7lXwASpDAl0mXUlD2mpDTLCwOtM5cYJOmXnYFCslC/dUFddPWjew== X-Received: by 2002:a05:6512:158b:b0:5b4:fdc3:d3f1 with SMTP id 2adb3069b0e04-5b8c18057c5mr656114e87.18.1789734327121; Fri, 18 Sep 2026 05:25:27 -0700 (PDT) Received: from yantra.. (dsl-trebng21-58c187-236.dhcp.inet.fi. [88.193.135.236]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5b8c270ea53sm398549e87.12.2026.09.18.05.25.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2026 05:25:26 -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 v7 08/10] iio: pressure: dps310: derive the drain interval from the watermark Date: Fri, 18 Sep 2026 15:25:15 +0300 Message-ID: <20260918122517.377565-9-zoone.rupert@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260918122517.377565-1-zoone.rupert@gmail.com> References: <20260918122517.377565-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" The drain interval only tracked how fast the FIFO fills, so a small watermark still waited half a FIFO for its samples. Take the watermark as the number of scans to wait for, but never drain slower than half a fill. Assisted-by: LLM Signed-off-by: Rupesh Majhi --- drivers/iio/pressure/dps310.c | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c index e63ea7873e5b..024fcdc7f4e7 100644 --- a/drivers/iio/pressure/dps310.c +++ b/drivers/iio/pressure/dps310.c @@ -114,6 +114,7 @@ struct dps310_data { s32 *fifo_hold; unsigned int fifo_hold_max; unsigned int fifo_held; + unsigned int watermark; unsigned int drain_interval_ms; s32 fifo_temp_raw; }; @@ -981,13 +982,28 @@ static int dps310_fifo_set_enable(struct dps310_data = *data, bool enable) * No interrupt pin is wired in tree, so drain on a timer. Both measuremen= ts * share the entries, so they fill it together. */ -static unsigned int dps310_fifo_interval(int prs_rate, int tmp_rate) +static unsigned int dps310_fifo_interval(struct dps310_data *data, int prs= _rate, + int tmp_rate) { - unsigned int fill_ms; + unsigned int fill_ms, want_ms; + int scan_rate; =20 fill_ms =3D MSEC_PER_SEC * DPS310_FIFO_DEPTH / (prs_rate + tmp_rate); =20 - return clamp(fill_ms / 2, DPS310_DRAIN_MIN_MS, DPS310_DRAIN_MAX_MS); + /* + * There is no hardware watermark, so take it as the number of scans + * the user will wait for and drain at that rate. Scans come from + * whichever measurement drives them. + */ + if (test_bit(DPS310_SCAN_PRESSURE, data->iio->active_scan_mask)) + scan_rate =3D prs_rate; + else + scan_rate =3D tmp_rate; + + want_ms =3D data->watermark * MSEC_PER_SEC / scan_rate; + + return clamp(min(want_ms, fill_ms / 2), DPS310_DRAIN_MIN_MS, + DPS310_DRAIN_MAX_MS); } =20 /* Returns which measurement the entry came from, or a negative error */ @@ -1189,6 +1205,15 @@ static void dps310_fifo_hold_free(struct dps310_data= *data) data->fifo_hold_max =3D 0; } =20 +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_buffer_postenable(struct iio_dev *iio) { struct dps310_data *data =3D iio_priv(iio); @@ -1212,7 +1237,7 @@ static int dps310_buffer_postenable(struct iio_dev *i= io) if (rc) return rc; =20 - data->drain_interval_ms =3D dps310_fifo_interval(prs_rate, tmp_rate); + data->drain_interval_ms =3D dps310_fifo_interval(data, prs_rate, tmp_rate= ); =20 rc =3D dps310_fifo_hold_alloc(data, prs_rate, tmp_rate); if (rc) @@ -1316,6 +1341,7 @@ 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, }; =20 static int dps310_probe(struct i2c_client *client) @@ -1332,6 +1358,7 @@ static int dps310_probe(struct i2c_client *client) 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 --=20 2.43.0 From nobody Fri Sep 25 00:02:41 2026 Received: from mail-lf2-f12.google.com (mail-lf2-f12.google.com [74.125.229.204]) (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 025DF4EB86C for ; Fri, 18 Sep 2026 12:25:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.229.204 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789734334; cv=none; b=F0kqCgDMa/TqCC7LaixPbXTyxpHy6WDcUjTVJVqYze58QucUYsfa59UgOLDUYifrAdXjL3ys77VZxiEL++c/892lm8w8iTerLG0Hcc27N/ybajaSdCT3nMYPWU+e3LxVvtIOqI/cYQLgzeBrshGhczshneT/iRkXgnxgXZesXuA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789734334; c=relaxed/simple; bh=NquUPFXNGtd4Ni0z6JEwZnVsUBIfxDLoSJ0188QE9MA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TQSO0vfeP37sOA+DRUX7VhLFA3DOy7gMdSoEyOA2jflJdY91zmF0vvCYvHGO1Wq0h4NgP46ssrhG5bcPGx86x2+u56af9/Js9pXoqqSc5SZCabZ3vHi8w9fIqWeLkdqo+B86tvkN9RI9dU0TB3iXxPNM3kghEPrNCRy6JwW8qKw= 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=RivCcwWn; arc=none smtp.client-ip=74.125.229.204 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="RivCcwWn" Received: by mail-lf2-f12.google.com with SMTP id 2adb3069b0e04-5b5e4f16c72so553390e87.0 for ; Fri, 18 Sep 2026 05:25:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789734328; x=1790339128; 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=buSpNdyZjmDa81oD9lpAG13/8iu4Pu88B1wBEU4L/m0=; b=RivCcwWnFwFyKL9y3wVD53VY01KNk1UlxJtPhRhVzOigMK76FZzYeiQcSsLSeQhqdU uexGNQeeSvXbefsbndTDm7Y64Pwq9HdhtW30S4L2aADuTxXcUdrHD985CnY7t3lW8kd3 neck8s59KGdr/31GiAM9OfGnZU0kOYiIVo6SPU95uYfk+hS3UVCxJP963i3dsU0cNpiZ yrFsxlXCa/2BXwR9mk2anVDV4hXNchnB8rRUC8Tb8+/rcXrhKdtDbGWcSty8QRhBMuZk CAa1H9qGypVQD/WuS5X9ZwUB2RhSPCH8vHWBtueWx/w1W3wJe+8dhwz9tuk7W/uRSZNu 6zpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789734328; x=1790339128; 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=buSpNdyZjmDa81oD9lpAG13/8iu4Pu88B1wBEU4L/m0=; b=uwCz5lCKwOegV9vs90/V3tegZ+CuHjqdoJjPDFEJ1eXxb1vQZF/JjnPMeFScswOPuV kcoc/3LFSsLjZ4g/FnUc4RLpKmqWeihY9wQU0STMrceTt6PZO/DQ0kAE2zAsrDFo2ySa SKuHHMptqb65hD7vMTeYwpgD7TM2LQbN4BFNQnSnI2cBZDGilxcf25cFntFeFyserZ7l 0yKkJ15eyRusOU7OafAhmP0w2gdN84hBsl+T58OdFTTKZSjNtW4ADYjVoo4g20+qbV8d RbtmQONZe+98+QDYpqVScXPCI1efQnPyJuRfA9YroZ8Hb6jsXsibrKpg7eMzBxY0OMxl Pu+Q== X-Forwarded-Encrypted: i=1; AKwUvBx48jro+F7zSEqbf4x5vqxv+XjSrs3F8TU4dVfnlQCazeOK76LstCrwrYVbd+RkLcmFn1LPitoXk2uMw1I=@vger.kernel.org X-Gm-Message-State: AFuF++n9Rsjvt8ohxrUDGlXwmPUFMLPG5FMRQAdO0Kbh2NI2A7Dqqq6X 5BbNpMozX+9iJ3Uy/6eL+JFtqZ+EATETNI54LxBcDqUNeR5qOWly8G46 X-Gm-Gg: AYBFou0/q5v+Kg5VsxoLfiK2O3XEmcbTughkQQl0DEpC/hHX3bA7ocVJ9XfSjB/qtsG WOBD8SemhPiSnzHYNodWHCW5O+vIh+Yo7VLmFoMiois5oodzcye/CJqcqXqlaznwOqK1nvVDYG7 fIZY9pQxdSpMAs/M22B6OpIuapbd7VrD/m+rVcAuln/xh0HLtsgDqnKlJl8xNDdsruwNsFYFH+U jY3jP65/snffIs/ou9FLrygD4/hDbWKxP8CIrpy11YrzomB4LSvizY/zlqMy/oFYIKSXmvvVUDz AWclb84gwPyRlaWUpVmIlSOS+N/GMBDAZm9ww89rRVvAWe3mnCN8nufL7UJWemVc3A1gCHCLzYc 4QOAWW32xXLBChz3Enppa8gglOaLgoDm2vZZGaVw+seRzPYgRY0TCN/3LJ0DTicy850EmnZEDEf 2U5OVmwUJOfwiEqoPxSy0tREpqTZcWD1/HUyKpLBiZJJNloA0kG+FrkSZAlmpOw7uM0d1P2kNcu RsQIKzAnbZ9ln9IFx5D9V7Oz915cmh1FiPAfChJYlr73reD2sikRQjwr0Ebz0adQugeRT36EKIS EDvZ X-Received: by 2002:a05:6512:4023:b0:5b6:1a7c:fd96 with SMTP id 2adb3069b0e04-5b8c197532bmr717255e87.60.1789734327937; Fri, 18 Sep 2026 05:25:27 -0700 (PDT) Received: from yantra.. (dsl-trebng21-58c187-236.dhcp.inet.fi. [88.193.135.236]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5b8c270ea53sm398549e87.12.2026.09.18.05.25.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2026 05:25:27 -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 v7 09/10] iio: pressure: dps310: implement .hwfifo_flush_to_buffer() Date: Fri, 18 Sep 2026 15:25:16 +0300 Message-ID: <20260918122517.377565-10-zoone.rupert@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260918122517.377565-1-zoone.rupert@gmail.com> References: <20260918122517.377565-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" Let userspace drain the FIFO on demand rather than only from the periodic drain. With a trigger attached the FIFO is not running, so there is nothing to flush and the hook returns 0. Assisted-by: LLM Signed-off-by: Rupesh Majhi --- drivers/iio/pressure/dps310.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c index 024fcdc7f4e7..f888bff2c996 100644 --- a/drivers/iio/pressure/dps310.c +++ b/drivers/iio/pressure/dps310.c @@ -1092,18 +1092,22 @@ static int dps310_fifo_push_held(struct dps310_data= *data) =20 /* * Read the batch out before compensating it, so a pressure entry pairs wi= th - * the temperature preceding it rather than the last one in the batch. + * the temperature preceding it rather than the last one in the batch. Stop + * reading at max_scans rather than after it, since entries leave the hard= ware + * as they are read and any extra would have to be thrown away. max_scans = of + * zero drains everything. * * Returns scans pushed. */ -static int dps310_fifo_drain(struct dps310_data *data) +static int dps310_fifo_drain(struct dps310_data *data, unsigned int max_sc= ans) __must_hold(&data->lock) { bool pressure_enabled =3D test_bit(DPS310_SCAN_PRESSURE, data->iio->active_scan_mask); u8 kind[DPS310_FIFO_DEPTH]; s32 raw[DPS310_FIFO_DEPTH]; - unsigned int i, n =3D 0, pushed =3D 0; + unsigned int i, n =3D 0, scans =3D 0, pushed =3D 0; + bool is_pressure; int rc; =20 for (i =3D 0; i < DPS310_FIFO_DEPTH; i++) { @@ -1114,7 +1118,15 @@ static int dps310_fifo_drain(struct dps310_data *dat= a) if (rc =3D=3D DPS310_FIFO_EMPTY) break; =20 + is_pressure =3D rc =3D=3D DPS310_FIFO_PRESSURE; kind[n++] =3D rc; + + /* Only the measurement that drives the scans counts */ + if (is_pressure =3D=3D pressure_enabled) + scans++; + + if (max_scans && scans >=3D max_scans) + break; } =20 for (i =3D 0; i < n; i++) { @@ -1164,7 +1176,7 @@ static void dps310_fifo_work(struct work_struct *work) int rc; =20 mutex_lock(&data->lock); - rc =3D dps310_fifo_drain(data); + rc =3D dps310_fifo_drain(data, 0); mutex_unlock(&data->lock); =20 if (rc < 0) @@ -1205,6 +1217,19 @@ static void dps310_fifo_hold_free(struct dps310_data= *data) data->fifo_hold_max =3D 0; } =20 +static int dps310_hwfifo_flush(struct iio_dev *iio, unsigned int count) +{ + struct dps310_data *data =3D iio_priv(iio); + + /* A trigger drives the capture instead and leaves the FIFO empty */ + if (iio_device_get_current_mode(iio) !=3D INDIO_BUFFER_SOFTWARE) + return 0; + + guard(mutex)(&data->lock); + + return dps310_fifo_drain(data, count); +} + static int dps310_hwfifo_set_watermark(struct iio_dev *iio, unsigned int v= al) { struct dps310_data *data =3D iio_priv(iio); @@ -1342,6 +1367,7 @@ 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) --=20 2.43.0 From nobody Fri Sep 25 00:02:41 2026 Received: from mail-lf2-f13.google.com (mail-lf2-f13.google.com [74.125.229.205]) (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 39BB54ED19A for ; Fri, 18 Sep 2026 12:25:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.229.205 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789734341; cv=none; b=uXJAbrG8lotmyCqY5p6ftQ5IzZH+JtmuKr8mp6stOy6+y6Gg1AsyXWS/r6oEYdex3iUcLUQ+AEIA4gHJzjSkEtOnsu7JeWwKWAptf4ORWNVjTi0PwAS57/J85NphkiPvZs8skv1+MsLHscChWGwQnkgooeQOrfhr2eO2g0IpOvE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789734341; c=relaxed/simple; bh=LSoXDOkihoTe+1aeuwkzPsOIbGrXJATfUTeqR5S99lA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=vEqJOk5d5IBCw6huLslenRXRAzWU6trRCWk3pIKZoVinZd3nDy2LW4C+BfN/6B1ohXWJuexPHOi75r3Bx1MHj/D/n+ZhYOwSedwl+wpvxE/S4hoZ9ynd+LgAg9pU1KHl/F5Q6+QfyHAsAdDACaauJQ0nbZx1M207/Ls5pF4i5vQ= 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=AEL7xXN0; arc=none smtp.client-ip=74.125.229.205 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="AEL7xXN0" Received: by mail-lf2-f13.google.com with SMTP id 2adb3069b0e04-5b5e4f15b79so660654e87.1 for ; Fri, 18 Sep 2026 05:25:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789734329; x=1790339129; 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=Pj32bFFZvi2cnsgj5gH1ddQyBwu2DGpSO+g4f8bX3TE=; b=AEL7xXN0UwJ6VFsT/iXOdPakeB/ZVEYtVslE3nC65clMSIVOou1AHTB8zFs1EBYiK2 dK3ml1bdkqUuHp+WKF+1oj587l55/l7MRv0uHjlLMTrPdABBPAX9/Xk/4ex1as6G2p/I LEQIW1QNxX5PBAdsIUZkghWsOxT3c5lppTj+kWa0gCD0h68QKDmDGEdHRX8rhh1PVtrD XodjbwqxXfZzpugmekin5S8nuRif3wn4hZYSvN8URrxUGdowDTd8Md5NRd9KcW4mMtUJ GVjpPikp++JFQmR4fIC5w+p4T1lNVwnepZTpl1ytkjhhx9pYMHlaFDhqx4TrI1+L6N4l cK+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789734329; x=1790339129; 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=Pj32bFFZvi2cnsgj5gH1ddQyBwu2DGpSO+g4f8bX3TE=; b=MMGcPJKkxiXWB0tBm3XGQsJNN4GmcbPJCfKfB6KQxr9WkAxn/85TuplsJOVFnMT0EP oXF2o31xSAqQQOy3EOlecfayl0VNhM+5CN1b/5m4NIlaOqvcJYplub+vHRWA8lBdMF0m w6a8CsvQm5HbyiSVxnqiHX1bxBXLFFoQV5yTjCLwkX5P/8uVzO1RpE3AriSwMiBZMgQv EdQlO3p1A8Cuu2Td1qexsPZzbT+KEtkhEe4yHIpLeJRppXDqRwtzaLgY8aGkgwFqznZp cLmcpoh6XgtKPKW3qTjDC4Ni7phOkco+q9ZhABEI3xMnHTBWLE0Ni9KMXKo55MG2IJnL 8IVA== X-Forwarded-Encrypted: i=1; AKwUvBwrEOWPmyvj1+OYx+YeV3iD/v0VEBo7ChFfwRJ1h5FUO9jUgUXrQf3I9dbMzBIb+oFuzCttUM0/++ZZJ6Y=@vger.kernel.org X-Gm-Message-State: AFuF++n2Q7z9DwErOhMROLP5AnbT+qWlSgCoPkJB2E5PWHFAogx0AQZg 8igSpUQ0gs9PMu2iWg6+PTRZigZmmeuEgzbib1Cf8b+HBKOIT9gX6/uU X-Gm-Gg: AYBFou1RtoqdmIOSBgXd77wqsUUKUKf/aNUuWiGKjyPtTkTxn+Y4K1PH/xioDw56vxp J79aW/RhxkkTrDyE4ZU58BjrV9g5fZnavjX5nEbGEmceegFN6hjmH5uZtW1iYR/yTZTHKLszMEx wk/rEJUEwzw1VeZBNC7tZ8/iK5QudLVq5wHLw8APMf+0a/B4jS8r82mu1+NlU87cXmqYRp1Ec4m ZUHrGUeutxRi/t22FO/kkqrGn+hcy85j0HDDvfoKdp9j5jNc+U36YBkKYg9oYaa5UTrWBgJ+ECf j5OpY3ovsYBN/2L4Hlc40o5na2WeAlnL89sJWy9hBrQ9AQ/dWwgDTVGj1ND3utD5Wt/pUTKjNc4 nMDZV1GNqdg1PTKMcMWjrDXTrFloRRo0mnC6fEOX943op4C76tKXN3K3B3Q2r+GK4nVLkfR0m33 Jd/xXk1PUuHB3gVgOkT+tD0T2fiRBF/pkzp20n3SJA0GWTHpsDAia1goS/kQJPyvaDyUbuiuOl4 kKY6zY79TLx+ckoLAXafZuhK66iVJYWt9JSnY7Sg2oKQuoX3OdpgkHGR5O1uRYldOXqkg== X-Received: by 2002:a05:6512:3c89:b0:5b8:bc5e:b584 with SMTP id 2adb3069b0e04-5b8c195dba5mr702953e87.60.1789734329260; Fri, 18 Sep 2026 05:25:29 -0700 (PDT) Received: from yantra.. (dsl-trebng21-58c187-236.dhcp.inet.fi. [88.193.135.236]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5b8c270ea53sm398549e87.12.2026.09.18.05.25.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2026 05:25:28 -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 v7 10/10] iio: pressure: dps310: check the lock markings with context analysis Date: Fri, 18 Sep 2026 15:25:17 +0300 Message-ID: <20260918122517.377565-11-zoone.rupert@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260918122517.377565-1-zoone.rupert@gmail.com> References: <20260918122517.377565-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 and CONFIG_WARN_CONTEXT_ANALYSIS=3Dy. It does run: dropping the lock around dps310_fifo_drain() warns rather than going quietly. Assisted-by: LLM 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