From nobody Mon Feb 9 17:58:07 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 4A26B333752; Thu, 15 Jan 2026 08:28:15 +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=1768465695; cv=none; b=Y72v2wUBwH7gxtJcT8TqA9kc9Ikktlq8p7ud+SVmDbtn3bsBA6ox9oRFWQhFGan25ZhhW7Go2T/AAw1v+fw9BlAJMdZZGTQIoT2/DT+HZlrtPu2S1azjAaqVTFzg4NC5O5rlL/GVQy/D+gWBGeqAwEjSuFtPkAgfsr/w4wmk/mk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768465695; c=relaxed/simple; bh=KPba62IqbsuMVgb2wGwXvzb3M/gVX4dJMynxBAA3LPo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZDPmU1sMigRgbTOT4s6N69zey38QYiGAhnP9jlq/CvjWaitQsj+dzvCPF+pHzaMZRNED558z8/DYNkBWzwLjO1ye3Rd7kX4w4Gy3uRA/X/DKzTmzYsKHEw+1HmhMdUfNMbm0i1M4HSZC7lfYWvGYnOZTdEKmuLcHJAP1JneAB8k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MZ+etE21; 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="MZ+etE21" Received: by smtp.kernel.org (Postfix) with ESMTPS id B015EC19425; Thu, 15 Jan 2026 08:28:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768465694; bh=KPba62IqbsuMVgb2wGwXvzb3M/gVX4dJMynxBAA3LPo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=MZ+etE21wNpL8XZQ7h6oAEglSFipXYVYXcQ9HgUdXIiHqDEYrLD/uvPUDsb+hmXEA IQgUFC5AUS+S1PQai+7dxjcsFLmPx28ASzgPdCH+ukBJ/2Z5TaDXb39hzFX3X9NEQF VvbvP/fvO0ygVnH2ghuuAvByTKMV52lDaI90ya4Dx7cR5RjIOrBx4tqCHXNLYZzFOZ khVH988zCRvOnMDqj4NAppYgemPtY9TEm6G0YgeEe148RSbF12BWZP3YQR6/wLxX6G XOSE76NjEwy+Gvkv9WPnDhyAYr5AXOcI/yIb+635hAUY2PB6H4G/7SRVzZMvDpTkYF pb11+G+4yiNzA== 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 A449CD3CC9F; Thu, 15 Jan 2026 08:28:14 +0000 (UTC) From: Shrikant Raskar via B4 Relay Date: Thu, 15 Jan 2026 13:57:38 +0530 Subject: [PATCH v5 2/5] 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: <20260115-rfd77402_v5-v5-2-594eb57683e4@gmail.com> References: <20260115-rfd77402_v5-v5-0-594eb57683e4@gmail.com> In-Reply-To: <20260115-rfd77402_v5-v5-0-594eb57683e4@gmail.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: skhan@linuxfoundation.org, david.hunter.linux@gmail.com, raskar.shree97@gmail.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1768465693; l=2336; i=raskar.shree97@gmail.com; s=20260101; h=from:subject:message-id; bh=LaZ44z8hgRMvbV0yeT+/nj7G5ikDhjSZuco4zkRzSNU=; b=p2RHYl6Q3UQP7UvUpegS5IEklJMs2jFdiZSdUE2+j+s+Hac63yQxUSvKxZCUpHwkVNikVCBIi 4YdXBLhzVN4Coj85CJWiXhfiCw3dFowxCSUo0YOuWmffm63ic+AeXNW 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 | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/drivers/iio/proximity/rfd77402.c b/drivers/iio/proximity/rfd77= 402.c index 4499939215e7..8c6379bebcc3 100644 --- a/drivers/iio/proximity/rfd77402.c +++ b/drivers/iio/proximity/rfd77402.c @@ -12,6 +12,7 @@ =20 #include #include +#include #include =20 #include @@ -110,10 +111,23 @@ static int rfd77402_set_state(struct i2c_client *clie= nt, u8 state, u16 check) return 0; } =20 -static int rfd77402_measure(struct i2c_client *client) +static int rfd77402_wait_for_result(struct rfd77402_data *data) { + struct i2c_client *client =3D data->client; + int ret; + + return read_poll_timeout(i2c_smbus_read_byte_data, ret, + ret & RFD77402_ICSR_RESULT, + 10 * USEC_PER_MSEC, + 10 * 10 * USEC_PER_MSEC, + false, + client, RFD77402_ICSR); +} + +static int rfd77402_measure(struct rfd77402_data *data) +{ + struct i2c_client *client =3D data->client; int ret; - int tries =3D 10; =20 ret =3D rfd77402_set_state(client, RFD77402_CMD_MCPU_ON, RFD77402_STATUS_MCPU_ON); @@ -126,19 +140,9 @@ 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; + ret =3D rfd77402_wait_for_result(data); + if (ret < 0) goto err; - } =20 ret =3D i2c_smbus_read_word_data(client, RFD77402_RESULT_R); if (ret < 0) @@ -168,7 +172,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; --=20 2.43.0