Skip to content

Commit d209898

Browse files
andredkrzk
authored andcommitted
firmware: exynos-acpm: use ktime APIs for timeout detection
acpm_dequeue_by_polling() uses a loop counter and assumes that each iteration of the loop takes 20us. It may take longer, though, because usleep_range() may sleep a different amount. Switch to using ktime_get() / ktime_before() to detect the timeout condition more reliably. This change also makes the code easier to follow and it allows us to adjust the sleep if necessary, without having to adjust the loop counter exit condition. Reviewed-by: Tudor Ambarus <[email protected]> Signed-off-by: André Draszik <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Krzysztof Kozlowski <[email protected]>
1 parent 0af2f6b commit d209898

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

drivers/firmware/samsung/exynos-acpm.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/firmware/samsung/exynos-acpm-protocol.h>
1616
#include <linux/io.h>
1717
#include <linux/iopoll.h>
18+
#include <linux/ktime.h>
1819
#include <linux/mailbox/exynos-message.h>
1920
#include <linux/mailbox_client.h>
2021
#include <linux/module.h>
@@ -32,8 +33,7 @@
3233

3334
#define ACPM_PROTOCOL_SEQNUM GENMASK(21, 16)
3435

35-
/* The unit of counter is 20 us. 5000 * 20 = 100 ms */
36-
#define ACPM_POLL_TIMEOUT 5000
36+
#define ACPM_POLL_TIMEOUT_US (100 * USEC_PER_MSEC)
3737
#define ACPM_TX_TIMEOUT_US 500000
3838

3939
#define ACPM_GS101_INITDATA_BASE 0xa000
@@ -284,12 +284,13 @@ static int acpm_dequeue_by_polling(struct acpm_chan *achan,
284284
const struct acpm_xfer *xfer)
285285
{
286286
struct device *dev = achan->acpm->dev;
287-
unsigned int cnt_20us = 0;
287+
ktime_t timeout;
288288
u32 seqnum;
289289
int ret;
290290

291291
seqnum = FIELD_GET(ACPM_PROTOCOL_SEQNUM, xfer->txd[0]);
292292

293+
timeout = ktime_add_us(ktime_get(), ACPM_POLL_TIMEOUT_US);
293294
do {
294295
ret = acpm_get_rx(achan, xfer);
295296
if (ret)
@@ -300,11 +301,10 @@ static int acpm_dequeue_by_polling(struct acpm_chan *achan,
300301

301302
/* Determined experimentally. */
302303
usleep_range(20, 30);
303-
cnt_20us++;
304-
} while (cnt_20us < ACPM_POLL_TIMEOUT);
304+
} while (ktime_before(ktime_get(), timeout));
305305

306-
dev_err(dev, "Timeout! ch:%u s:%u bitmap:%lx, cnt_20us = %d.\n",
307-
achan->id, seqnum, achan->bitmap_seqnum[0], cnt_20us);
306+
dev_err(dev, "Timeout! ch:%u s:%u bitmap:%lx.\n",
307+
achan->id, seqnum, achan->bitmap_seqnum[0]);
308308

309309
return -ETIME;
310310
}

0 commit comments

Comments
 (0)