From nobody Mon Feb 9 04:22:36 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E14B021FF23; Thu, 1 Jan 2026 16:18:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767284293; cv=none; b=IZDhqBnhjUjqcCRy7COg4KAQAJCMPIyLQ5Su6e4ZR7UKiWdW3/LCj6shf1+0snjXSifXv+zAcS3ukLoAgCAOPNlQQbJvV5v5ti1fE7yUEq9NYyE+UDibmCIemltam5BMCAmn8d5Zp/XP6FBjG50KlUv4Xe7HjxNOIMMqfgIU7i4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767284293; c=relaxed/simple; bh=Mx2p707lQguqjpJp/MylxYZW2GopeXvIoHFqyoaw+1Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KTZCjkOXS49InLLHs8qvBR5sx6OlvgUWywPaaEGicRbW2J3LVM/v/zi1aweqPGEmADWyAP0Ed1M/Ao6B3hcImvVtcnfeq3RaI+mPKmIpmPkBt52tmqNthXh5Wr0Tu1zpyXynqaCu6jvp3l3JSvM2gK9H5tm01tI/ZJxx/U0dIm0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=T6l8kBWz; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="T6l8kBWz" Received: by smtp.kernel.org (Postfix) with ESMTPS id 5F488C19421; Thu, 1 Jan 2026 16:18:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767284292; bh=Mx2p707lQguqjpJp/MylxYZW2GopeXvIoHFqyoaw+1Y=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=T6l8kBWzorv2rv249iTzQPyRDW+zq//2S4d6/VDUm0tSgjZGH/ypDAeIdKKkfuQZA hev2q/0iam0+RqxY2IsOBZ4cs9yyxvVC/0ZxWYtZehSFZCrpEsEvTV+6ZoDZV13hk5 oUZ96AlRKeq0zkGarv1DWgaFUs3sy4LnEv9/ZXRJcO0zTqrSlKW5IUIE3H+DkoBD81 Ms6lOy8zmxBUJNXkh6mIP5nx6K9BRKSBm2OMmkMxF2ydL3L7sAKfGk0s/2F5oDBKo3 CuEH8oMDMv0I8UqwPRUUTzE4ruJWTJJKjp7di2f+42clNR/ZR7nOoGejC86Tfp542X WNtqOoy/e+POQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 518EEEEB579; Thu, 1 Jan 2026 16:18:12 +0000 (UTC) From: Shrikant Raskar via B4 Relay Date: Thu, 01 Jan 2026 21:47:38 +0530 Subject: [PATCH v4 1/4] dt-bindings: iio: proximity: Add RF Digital RFD77402 ToF sensor 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 Message-Id: <20260101-b4-rfd77402_irq-v4-1-42cd54359e9f@gmail.com> References: <20260101-b4-rfd77402_irq-v4-0-42cd54359e9f@gmail.com> In-Reply-To: <20260101-b4-rfd77402_irq-v4-0-42cd54359e9f@gmail.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: raskar.shree97@gmail.com, skhan@linuxfoundation.org, david.hunter.linux@gmail.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Krzysztof Kozlowski X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1767284290; l=2840; i=raskar.shree97@gmail.com; s=20260101; h=from:subject:message-id; bh=OVYVzLMgPVMO/XnImN7RwZfXGcsHmKgD/1eOSTZgZaQ=; b=kIZPx5FzhAN7jjdlvkZ8JEn43fuXoqi+SyBOinIPl6GRMa65POu3IIEjE5Vf8vc83Lb94d7T2 75OjkeqXlXaCpTBAzOFattW3iO+EcD7CMA03lslwPSituzH5Ch3yJmZ X-Developer-Key: i=raskar.shree97@gmail.com; a=ed25519; pk=4m2wXDvY0vlXefvRRzawNcNAif88Cy4XvbLkU6iMG/Y= X-Endpoint-Received: by B4 Relay for raskar.shree97@gmail.com/20260101 with auth_id=589 X-Original-From: Shrikant Raskar Reply-To: raskar.shree97@gmail.com From: Shrikant Raskar The RF Digital RFD77402 is a Time-of-Flight (ToF) proximity and distance sensor that provides absolute and highly accurate distance measurements from 100 mm up to 2000 mm over an I2C interface. It includes an optional interrupt pin that signals when new measurement data is ready. Reviewed-by: Krzysztof Kozlowski Signed-off-by: Shrikant Raskar --- .../bindings/iio/proximity/rfdigital,rfd77402.yaml | 53 ++++++++++++++++++= ++++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + 2 files changed, 55 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/proximity/rfdigital,rfd7= 7402.yaml b/Documentation/devicetree/bindings/iio/proximity/rfdigital,rfd77= 402.yaml new file mode 100644 index 000000000000..1ef6326b209e --- /dev/null +++ b/Documentation/devicetree/bindings/iio/proximity/rfdigital,rfd77402.ya= ml @@ -0,0 +1,53 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/proximity/rfdigital,rfd77402.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: RF Digital RFD77402 ToF sensor + +maintainers: + - Shrikant Raskar + +description: + The RF Digital RFD77402 is a Time-of-Flight (ToF) proximity and distance + sensor providing up to 200 mm range measurement over an I2C interface. + +properties: + compatible: + const: rfdigital,rfd77402 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + description: + Interrupt asserted when a new distance measurement is available. + + vdd-supply: + description: Regulator that provides power to the sensor. + +required: + - compatible + - reg + - vdd-supply + +additionalProperties: false + +examples: + - | + #include + i2c { + #address-cells =3D <1>; + #size-cells =3D <0>; + + proximity@4c { + compatible =3D "rfdigital,rfd77402"; + reg =3D <0x4c>; + vdd-supply =3D <&vdd_3v3>; + interrupt-parent =3D <&gpio>; + interrupts =3D <4 IRQ_TYPE_EDGE_FALLING>; + }; + }; +... diff --git a/Documentation/devicetree/bindings/vendor-prefixes.yaml b/Docum= entation/devicetree/bindings/vendor-prefixes.yaml index c7591b2aec2a..59ac4f0756d9 100644 --- a/Documentation/devicetree/bindings/vendor-prefixes.yaml +++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml @@ -1361,6 +1361,8 @@ patternProperties: description: Revolution Robotics, Inc. (Revotics) "^rex,.*": description: iMX6 Rex Project + "^rfdigital,.*": + description: RF Digital Corporation "^richtek,.*": description: Richtek Technology Corporation "^ricoh,.*": --=20 2.43.0 From nobody Mon Feb 9 04:22:36 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E15FD2DCF52; Thu, 1 Jan 2026 16:18:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767284293; cv=none; b=CjhBCbERLTFBvFGUMgblkhR8FW7cwfuZOYvSX6JR0VFrd9OIaruqWxt6FQGPCLeKL7rOelv8yO4tr41RCyEek55SJ8QpOrwLThAQRGonTrgCkeku3o09y0gjeCfym6L8o0wKhtFb6T42b+gSIQaEDyN9MzBDUMQDXg6e22gIbWU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767284293; c=relaxed/simple; bh=NbLST8l1hY2ztieLg0GKRhQ61QRNSErpZcGOxuaun7g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=POvimocFj+encz9UDdYuoYxaSCKZrERFlCPzxlaI3TM/XRppI2W9oEVUr2qxBptzDkEkM9USVTNZuSMrInbu2nVFd37r19e3dD0BA7T5a2cGv82ap7+0N12HFf03k+QkV9O/KNZfCtXeYdISkMkFV3jReLrBx6dmBxFz9UwGTIc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=o4Amq/Z6; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="o4Amq/Z6" Received: by smtp.kernel.org (Postfix) with ESMTPS id 6DAB3C16AAE; Thu, 1 Jan 2026 16:18:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767284292; bh=NbLST8l1hY2ztieLg0GKRhQ61QRNSErpZcGOxuaun7g=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=o4Amq/Z6VZMhmzTQ2DRBWxvW8F5RJMXe/DLuwU4Q2lg+u+k7BAk+EdA0wvdGn31H0 fhqKGNMFgfwal27qgndfPJR1AbnYsMKUKb99Z6cqJJQb95B9X6xJCIr35CG+NWxURA sNRWQYw3bjEXAQvEqE4ZY8ez4USHClQ8khed/pelyG0GqCdQ6WGcAorOb60J7UgDjb siHbSPGgoGMtNHJmgw+VG7s/6PdZbTCN+VjwRHktZDEefGnokcKZ+kRnm0KQj1sy7A RQAWCjjfOJ0cnOIem109g+afwBoqYLx9zYDlumi27XEtOoduFFPKcaNHZWG2IclTXF 9EfLIx18komxg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5EE6EEED618; Thu, 1 Jan 2026 16:18:12 +0000 (UTC) From: Shrikant Raskar via B4 Relay Date: Thu, 01 Jan 2026 21:47:39 +0530 Subject: [PATCH v4 2/4] iio: proximity: rfd77402: Add OF device ID for enumeration via DT 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 Message-Id: <20260101-b4-rfd77402_irq-v4-2-42cd54359e9f@gmail.com> References: <20260101-b4-rfd77402_irq-v4-0-42cd54359e9f@gmail.com> In-Reply-To: <20260101-b4-rfd77402_irq-v4-0-42cd54359e9f@gmail.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: raskar.shree97@gmail.com, skhan@linuxfoundation.org, david.hunter.linux@gmail.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1767284290; l=1125; i=raskar.shree97@gmail.com; s=20260101; h=from:subject:message-id; bh=vqy/DEvaK2P0nm0mNsxwW8n+PXruCd9gkMKLRnARTow=; b=frtbWm1r4IhTdmJDt/qUUyVWIuZQ4oI98i6dPTEhD5SabnuSda4wo8Tm3aqoUnIOG4QeaWneq m1futJKEcg1Dm+HlKaO297UHXcqZgg9sUnfevh8uxHaZdFE+HwdyZXk X-Developer-Key: i=raskar.shree97@gmail.com; a=ed25519; pk=4m2wXDvY0vlXefvRRzawNcNAif88Cy4XvbLkU6iMG/Y= X-Endpoint-Received: by B4 Relay for raskar.shree97@gmail.com/20260101 with auth_id=589 X-Original-From: Shrikant Raskar Reply-To: raskar.shree97@gmail.com From: Shrikant Raskar Add an OF device ID table so the driver can bind automatically when the RFD77402 sensor is described in Device Tree. This enables proper enumeration via its compatible string and allows instantiation on DT-based platforms. Signed-off-by: Shrikant Raskar --- drivers/iio/proximity/rfd77402.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/iio/proximity/rfd77402.c b/drivers/iio/proximity/rfd77= 402.c index aff60a3c1a6f..3262af6f6882 100644 --- a/drivers/iio/proximity/rfd77402.c +++ b/drivers/iio/proximity/rfd77402.c @@ -313,10 +313,17 @@ static const struct i2c_device_id rfd77402_id[] =3D { }; MODULE_DEVICE_TABLE(i2c, rfd77402_id); =20 +static const struct of_device_id rfd77402_of_match[] =3D { + { .compatible =3D "rfdigital,rfd77402" }, + { } +}; +MODULE_DEVICE_TABLE(of, rfd77402_of_match); + static struct i2c_driver rfd77402_driver =3D { .driver =3D { .name =3D RFD77402_DRV_NAME, .pm =3D pm_sleep_ptr(&rfd77402_pm_ops), + .of_match_table =3D rfd77402_of_match, }, .probe =3D rfd77402_probe, .id_table =3D rfd77402_id, --=20 2.43.0 From nobody Mon Feb 9 04:22:36 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E158627874F; Thu, 1 Jan 2026 16:18:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767284293; cv=none; b=ptFwNSYKOic07YybgWDl3J5zfN0dmfiVn9Hi//3vpg1CN1TJkmvAmQ5PoGHtPcmF974LH6vHUeCFEBZqyFtx/ISiGe2bAloZNhCF+yDZwNRHYDkPCgVJNFsyjnb01SktdMljj6TLnd1nTGinLxTi8KVOJeY7P3wjJIaIDnjJHDs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767284293; c=relaxed/simple; bh=4MeX26Uz9CqThCeP7n61Cdxs3/XzsdN1BSOCj4rcVlM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HkyiJcWShPc3W6q3q0plIYD23M1UUv2IHfpkGPRIGLd60DLJX4KxoHY9LzhnueLMInoEqjuAToiTLxPpLFlXHNKR33g2ie6i5iwk0NsmLgsSD/r/pubMk2X8Y++PGi56ZKdfY2+B0DV4pRMCoFxA6AlEkGH4zupgRNhegsukWxY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IDlf11c+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IDlf11c+" Received: by smtp.kernel.org (Postfix) with ESMTPS id 79678C19422; Thu, 1 Jan 2026 16:18:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767284292; bh=4MeX26Uz9CqThCeP7n61Cdxs3/XzsdN1BSOCj4rcVlM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=IDlf11c+jTWfjwztVYkpaDmnRaFKns8LIl1ZbVhuDq+jOYrbuSteUvBPCcOBH65fU oJwkaLikHEx6N46+FTfa1pzvukx802Z/JsSLjorvMXF+IBEgzLF1joBharH53BZ177 ylQYX2miEFLnTxtKGGB7G2GD6Pd3+VWPs3qyldn9kCxci6lIMLgMJaW6PRbkE3QjS0 xYFjLhYus52Zfl+0t+TLHInbYey4xavwlcEO/pgJcHo1VNWejjY/ikjgmBM9miQUHB 6IJwT0cExfKULQYjnAf2Wu7u4mr2tAC7QEg+AdjhjR3AypFV1Beb5+b192ru6T1U3l 3a8B7g6yy0J2g== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6CBF4EED60F; Thu, 1 Jan 2026 16:18:12 +0000 (UTC) From: Shrikant Raskar via B4 Relay Date: Thu, 01 Jan 2026 21:47:40 +0530 Subject: [PATCH v4 3/4] iio: proximity: rfd77402: Use kernel helper for result polling 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 Message-Id: <20260101-b4-rfd77402_irq-v4-3-42cd54359e9f@gmail.com> References: <20260101-b4-rfd77402_irq-v4-0-42cd54359e9f@gmail.com> In-Reply-To: <20260101-b4-rfd77402_irq-v4-0-42cd54359e9f@gmail.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: raskar.shree97@gmail.com, skhan@linuxfoundation.org, david.hunter.linux@gmail.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1767284290; l=1779; i=raskar.shree97@gmail.com; s=20260101; h=from:subject:message-id; bh=LS/GSeSQrtkZGeuXrepvOA1K2RRvlQ1qjhZCkwokVvE=; b=C+NrC31Xzpph97j24fL29MGZ28F+Z2CvCubZfv7JLjNSG9Ci3juEc5vysFpIQLqcfPxmMljCG SFWfDAnHZkkBuN+smeYYMuOxwmAFeLN6ib8bO9ZMQXWWhlTvc8u3j/g X-Developer-Key: i=raskar.shree97@gmail.com; a=ed25519; pk=4m2wXDvY0vlXefvRRzawNcNAif88Cy4XvbLkU6iMG/Y= X-Endpoint-Received: by B4 Relay for raskar.shree97@gmail.com/20260101 with auth_id=589 X-Original-From: Shrikant Raskar Reply-To: raskar.shree97@gmail.com From: Shrikant Raskar Replace the manually written polling loop with read_poll_timeout(), the kernel's standard helper for waiting on hardware status. This makes the code easier to read and avoids repeating the same polling code in the driver. Signed-off-by: Shrikant Raskar --- drivers/iio/proximity/rfd77402.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/drivers/iio/proximity/rfd77402.c b/drivers/iio/proximity/rfd77= 402.c index 3262af6f6882..496c1412ebf8 100644 --- a/drivers/iio/proximity/rfd77402.c +++ b/drivers/iio/proximity/rfd77402.c @@ -13,6 +13,7 @@ #include #include #include +#include =20 #include =20 @@ -113,7 +114,6 @@ static int rfd77402_set_state(struct i2c_client *client= , u8 state, u16 check) static int rfd77402_measure(struct i2c_client *client) { int ret; - int tries =3D 10; =20 ret =3D rfd77402_set_state(client, RFD77402_CMD_MCPU_ON, RFD77402_STATUS_MCPU_ON); @@ -126,19 +126,15 @@ static int rfd77402_measure(struct i2c_client *client) if (ret < 0) goto err; =20 - while (tries-- > 0) { - ret =3D i2c_smbus_read_byte_data(client, RFD77402_ICSR); - if (ret < 0) - goto err; - if (ret & RFD77402_ICSR_RESULT) - break; - msleep(20); - } - - if (tries < 0) { - ret =3D -ETIMEDOUT; + /* Poll ICSR until RESULT bit is set */ + ret =3D read_poll_timeout(i2c_smbus_read_byte_data, ret, + ret & RFD77402_ICSR_RESULT, + 10000, /* sleep: 10ms */ + 100000, /* timeout: 100ms */ + false, + client, RFD77402_ICSR); + if (ret < 0) goto err; - } =20 ret =3D i2c_smbus_read_word_data(client, RFD77402_RESULT_R); if (ret < 0) --=20 2.43.0 From nobody Mon Feb 9 04:22:36 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 392502ED853; Thu, 1 Jan 2026 16:18:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767284293; cv=none; b=Y9Cvg3Glm8RrDDf6kZZNHETLIFDJBH39308G9yFljvzAFgHaHJL29nEWw8rIJgp3B/vW35Syp/rmoIJ0SHGoxLg584f46Lv2lR/WKRhx0IiTUmSjBVDnkalBeOdzJAAufS5acxiXSyfpXJJ4+YSaX80W3Z2inMMdGVjZzSdqXKs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767284293; c=relaxed/simple; bh=kgeuZ/y8NZNVHt7bXiE/Wp4IIMdUUDkagYV0xkmQi5Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ga4AsaMyN5oFURvSEKtyW+nfszXn4I4bdLq+ddeicA6sIB7RNazcXbnkVP2lXJrM/yO74QU37bwmST1jTl9wqHvSqxp14abLaQhU+d0kfkz7X1OXa9HziJjiCZg1buCzzdh7YhSppVexp4fA9gbMPxkjbffnzA235FtQiGcao0E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NPJnlGiu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NPJnlGiu" Received: by smtp.kernel.org (Postfix) with ESMTPS id 84D35C4AF0B; Thu, 1 Jan 2026 16:18:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767284292; bh=kgeuZ/y8NZNVHt7bXiE/Wp4IIMdUUDkagYV0xkmQi5Y=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=NPJnlGiu9AW5J5fqgMeoYNIkgUvEYo7v5PapdLn130ng/tavFe9A2VIRdtdzV6EOf 3tio2kebLCbnjFZzgATn1i0FnufekRpOrywXu1tvpNtkEYL/MxtoX9KZA8Xg9up/SF PalNJf29F++b4iIOeI38c01WWOIJPx3oqNmO2kYfMn4vqkSmPPqnATCy6wSxQef2Co 5LzsHHrODt7r7f3t+ET95DdNUEK0G7Gv1eXiz/3+N8uLTmHJtreXkqLOFOgbTYN9r3 UbCYP4YaXrHsMyyJVSzQLPqUlt3Z1K222LgqHBnB2cPKBL0haw7J+7En5KvC9RvLrq stHOM4Ta4Z75g== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7AEC6EED621; Thu, 1 Jan 2026 16:18:12 +0000 (UTC) From: Shrikant Raskar via B4 Relay Date: Thu, 01 Jan 2026 21:47:41 +0530 Subject: [PATCH v4 4/4] iio: proximity: rfd77402: Add interrupt handling support 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 Message-Id: <20260101-b4-rfd77402_irq-v4-4-42cd54359e9f@gmail.com> References: <20260101-b4-rfd77402_irq-v4-0-42cd54359e9f@gmail.com> In-Reply-To: <20260101-b4-rfd77402_irq-v4-0-42cd54359e9f@gmail.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: raskar.shree97@gmail.com, skhan@linuxfoundation.org, david.hunter.linux@gmail.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1767284290; l=7074; i=raskar.shree97@gmail.com; s=20260101; h=from:subject:message-id; bh=RKV4qe8g75WaYJMPnvpOFnWfihHaP50YTCl+fCPC7AA=; b=KixV0F0nd1ERUhIPUqvcYXxmksFaaITYzw7d14OL2jve9voC01kzH9qbybHbZ05DQQ8USWpte nkkB6lQWPzjAVT+TbjmlIrm+6sR/Waqp6lO/nGo6ybrFTfgm/iTK1OJ X-Developer-Key: i=raskar.shree97@gmail.com; a=ed25519; pk=4m2wXDvY0vlXefvRRzawNcNAif88Cy4XvbLkU6iMG/Y= X-Endpoint-Received: by B4 Relay for raskar.shree97@gmail.com/20260101 with auth_id=589 X-Original-From: Shrikant Raskar Reply-To: raskar.shree97@gmail.com From: Shrikant Raskar Add interrupt handling support to enable event-driven data acquisition instead of continuous polling. This improves responsiveness, reduces CPU overhead, and supports low-power operation by allowing the system to remain idle until an interrupt occurs. Signed-off-by: Shrikant Raskar --- drivers/iio/proximity/rfd77402.c | 136 ++++++++++++++++++++++++++++++++++-= ---- 1 file changed, 120 insertions(+), 16 deletions(-) diff --git a/drivers/iio/proximity/rfd77402.c b/drivers/iio/proximity/rfd77= 402.c index 496c1412ebf8..8cddf509f9c6 100644 --- a/drivers/iio/proximity/rfd77402.c +++ b/drivers/iio/proximity/rfd77402.c @@ -6,13 +6,14 @@ * * 7-bit I2C slave address 0x4c * - * TODO: interrupt * https://media.digikey.com/pdf/Data%20Sheets/RF%20Digital%20PDFs/RFD7740= 2.pdf */ =20 #include #include #include +#include +#include #include =20 #include @@ -20,6 +21,8 @@ #define RFD77402_DRV_NAME "rfd77402" =20 #define RFD77402_ICSR 0x00 /* Interrupt Control Status Register */ +#define RFD77402_ICSR_CLR_CFG BIT(0) +#define RFD77402_ICSR_CLR_TYPE BIT(1) #define RFD77402_ICSR_INT_MODE BIT(2) #define RFD77402_ICSR_INT_POL BIT(3) #define RFD77402_ICSR_RESULT BIT(4) @@ -27,6 +30,12 @@ #define RFD77402_ICSR_H2M_MSG BIT(6) #define RFD77402_ICSR_RESET BIT(7) =20 +#define RFD77402_IER 0x02 +#define RFD77402_IER_RESULT BIT(0) +#define RFD77402_IER_M2H_MSG BIT(1) +#define RFD77402_IER_H2M_MSG BIT(2) +#define RFD77402_IER_RESET BIT(3) + #define RFD77402_CMD_R 0x04 #define RFD77402_CMD_SINGLE 0x01 #define RFD77402_CMD_STANDBY 0x10 @@ -77,10 +86,18 @@ static const struct { {RFD77402_HFCFG_3, 0x45d4}, }; =20 +/** + * struct rfd77402_data - device-specific data for the RFD77402 sensor + * @client: I2C client handle + * @lock: mutex to serialize sensor reads + * @completion: completion used for interrupt-driven measurements + * @irq_en: indicates whether interrupt mode is enabled + */ struct rfd77402_data { struct i2c_client *client; - /* Serialize reads from the sensor */ struct mutex lock; + struct completion completion; + bool irq_en; }; =20 static const struct iio_chan_spec rfd77402_channels[] =3D { @@ -91,6 +108,39 @@ static const struct iio_chan_spec rfd77402_channels[] = =3D { }, }; =20 +static irqreturn_t rfd77402_interrupt_handler(int irq, void *pdata) +{ + struct rfd77402_data *data =3D pdata; + int ret; + + if (!data || !data->client) + return IRQ_NONE; + + ret =3D i2c_smbus_read_byte_data(data->client, RFD77402_ICSR); + if (ret < 0) + return IRQ_NONE; + + /* Check if the interrupt is from our device */ + if (!(ret & RFD77402_ICSR_RESULT)) + return IRQ_NONE; + + /* Signal completion of measurement */ + complete(&data->completion); + return IRQ_HANDLED; +} + +static int rfd77402_wait_for_irq(struct rfd77402_data *data) +{ + int ret; + /* As per datasheet, single measurement flow takes 100ms */ + ret =3D wait_for_completion_timeout(&data->completion, + msecs_to_jiffies(100)); + if (ret =3D=3D 0) + return -ETIMEDOUT; + + return 0; +} + static int rfd77402_set_state(struct i2c_client *client, u8 state, u16 che= ck) { int ret; @@ -111,8 +161,9 @@ static int rfd77402_set_state(struct i2c_client *client= , u8 state, u16 check) return 0; } =20 -static int rfd77402_measure(struct i2c_client *client) +static int rfd77402_measure(struct rfd77402_data *data) { + struct i2c_client *client =3D data->client; int ret; =20 ret =3D rfd77402_set_state(client, RFD77402_CMD_MCPU_ON, @@ -126,13 +177,19 @@ static int rfd77402_measure(struct i2c_client *client) if (ret < 0) goto err; =20 - /* Poll ICSR until RESULT bit is set */ - ret =3D read_poll_timeout(i2c_smbus_read_byte_data, ret, - ret & RFD77402_ICSR_RESULT, - 10000, /* sleep: 10ms */ - 100000, /* timeout: 100ms */ - false, - client, RFD77402_ICSR); + if (data->irq_en) { + /* Re-initialize completion and wait for interrupt */ + reinit_completion(&data->completion); + ret =3D rfd77402_wait_for_irq(data); + } else { + /* Poll ICSR until RESULT bit is set */ + ret =3D read_poll_timeout(i2c_smbus_read_byte_data, ret, + ret & RFD77402_ICSR_RESULT, + 10000, /* sleep 10ms */ + 100000, /* timeout 100ms */ + false, + client, RFD77402_ICSR); + } if (ret < 0) goto err; =20 @@ -164,7 +221,7 @@ static int rfd77402_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: mutex_lock(&data->lock); - ret =3D rfd77402_measure(data->client); + ret =3D rfd77402_measure(data); mutex_unlock(&data->lock); if (ret < 0) return ret; @@ -184,8 +241,21 @@ static const struct iio_info rfd77402_info =3D { .read_raw =3D rfd77402_read_raw, }; =20 +static int rfd77402_config_irq(struct i2c_client *client, u8 csr, u8 ier) +{ + int ret; + + ret =3D i2c_smbus_write_byte_data(client, RFD77402_ICSR, csr); + if (ret) + return ret; + + return i2c_smbus_write_byte_data(client, RFD77402_IER, ier); +} + static int rfd77402_init(struct i2c_client *client) { + struct iio_dev *indio_dev =3D i2c_get_clientdata(client); + struct rfd77402_data *data =3D iio_priv(indio_dev); int ret, i; =20 ret =3D rfd77402_set_state(client, RFD77402_CMD_STANDBY, @@ -193,10 +263,24 @@ static int rfd77402_init(struct i2c_client *client) if (ret < 0) return ret; =20 - /* configure INT pad as push-pull, active low */ - ret =3D i2c_smbus_write_byte_data(client, RFD77402_ICSR, - RFD77402_ICSR_INT_MODE); - if (ret < 0) + if (data->irq_en) { + /* Enable interrupt mode: + * - Configure ICSR for auto-clear on read and + * push-pull output + * - Enable "result ready" interrupt in IER + */ + ret =3D rfd77402_config_irq(client, + RFD77402_ICSR_CLR_CFG | + RFD77402_ICSR_INT_MODE, + RFD77402_IER_RESULT); + } else { + /* Disable all interrupts: + * - Clear ICSR configuration + * - Disable all interrupts in IER + */ + ret =3D rfd77402_config_irq(client, 0, 0); + } + if (ret) return ret; =20 /* I2C configuration */ @@ -271,7 +355,27 @@ static int rfd77402_probe(struct i2c_client *client) =20 data =3D iio_priv(indio_dev); data->client =3D client; - mutex_init(&data->lock); + ret =3D devm_mutex_init(&client->dev, &data->lock); + if (ret) + return ret; + + init_completion(&data->completion); + i2c_set_clientdata(client, indio_dev); + + data->irq_en =3D false; + if (client->irq > 0) { + ret =3D devm_request_threaded_irq(&client->dev, client->irq, + NULL, rfd77402_interrupt_handler, + IRQF_ONESHOT, + "rfd77402", data); + if (ret) + return ret; + + data->irq_en =3D true; + dev_dbg(&client->dev, "Using interrupt mode\n"); + } else { + dev_dbg(&client->dev, "Using polling mode\n"); + } =20 indio_dev->info =3D &rfd77402_info; indio_dev->channels =3D rfd77402_channels; --=20 2.43.0