2024-02-29 18:12:34

by Théo Lebrun

[permalink] [raw]
Subject: [PATCH v2 07/11] i2c: nomadik: replace jiffies by ktime for FIFO flushing timeout

The FIFO flush function uses a jiffies amount to detect timeouts as the
flushing is async. Replace with ktime to get more accurate precision
and support short timeouts.

Reviewed-by: Linus Walleij <[email protected]>
Signed-off-by: Théo Lebrun <[email protected]>
---
drivers/i2c/busses/i2c-nomadik.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c
index e68b8e0d7919..afd54999bbbb 100644
--- a/drivers/i2c/busses/i2c-nomadik.c
+++ b/drivers/i2c/busses/i2c-nomadik.c
@@ -219,8 +219,8 @@ static inline void i2c_clr_bit(void __iomem *reg, u32 mask)
static int flush_i2c_fifo(struct nmk_i2c_dev *priv)
{
#define LOOP_ATTEMPTS 10
+ ktime_t timeout;
int i;
- unsigned long timeout;

/*
* flush the transmit and receive FIFO. The flushing
@@ -232,9 +232,9 @@ static int flush_i2c_fifo(struct nmk_i2c_dev *priv)
writel((I2C_CR_FTX | I2C_CR_FRX), priv->virtbase + I2C_CR);

for (i = 0; i < LOOP_ATTEMPTS; i++) {
- timeout = jiffies + priv->adap.timeout;
+ timeout = ktime_add_us(ktime_get(), priv->timeout_usecs);

- while (!time_after(jiffies, timeout)) {
+ while (ktime_after(timeout, ktime_get())) {
if ((readl(priv->virtbase + I2C_CR) &
(I2C_CR_FTX | I2C_CR_FRX)) == 0)
return 0;

--
2.44.0



2024-03-04 09:24:10

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH v2 07/11] i2c: nomadik: replace jiffies by ktime for FIFO flushing timeout

On Thu, Feb 29, 2024 at 07:10:55PM +0100, Théo Lebrun wrote:
> The FIFO flush function uses a jiffies amount to detect timeouts as the
> flushing is async. Replace with ktime to get more accurate precision
> and support short timeouts.
>
> Reviewed-by: Linus Walleij <[email protected]>
> Signed-off-by: Théo Lebrun <[email protected]>

Reviewed-by: Wolfram Sang <[email protected]>


Attachments:
(No filename) (425.00 B)
signature.asc (849.00 B)
Download all attachments

2024-03-04 14:19:49

by Andi Shyti

[permalink] [raw]
Subject: Re: [PATCH v2 07/11] i2c: nomadik: replace jiffies by ktime for FIFO flushing timeout

Hi Theo,

On Thu, Feb 29, 2024 at 07:10:55PM +0100, Th?o Lebrun wrote:
> The FIFO flush function uses a jiffies amount to detect timeouts as the
> flushing is async. Replace with ktime to get more accurate precision
> and support short timeouts.
>
> Reviewed-by: Linus Walleij <[email protected]>
> Signed-off-by: Th?o Lebrun <[email protected]>

Reviewed-by: Andi Shyti <[email protected]>

Thanks,
Andi