diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2024-02-05 08:45:47 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2024-02-08 08:17:00 +0100 |
commit | 8dae33d9a5c0e4eee7e08e07920d77bd322d6401 (patch) | |
tree | 1ece7d4a6e418726b96aa15c2f80fd7a61be9ced | |
parent | b28091f154eaa70b7e8ca229c1ebe9ab3caa4ad6 (diff) | |
download | barebox-8dae33d9a5c0.tar.gz barebox-8dae33d9a5c0.tar.xz |
i2c: lpi2c: use udelay for timeout loops
In PBL we don't have get_time_ns() and is_timeout() available. In
preparation for adding PBL support to the driver replace the timeout
loops with udelay() which we have available in PBL.
Link: https://lore.barebox.org/20240205074553.2005284-3-s.hauer@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | drivers/i2c/busses/i2c-imx-lpi2c.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c b/drivers/i2c/busses/i2c-imx-lpi2c.c index 91203d90be..42f7b37143 100644 --- a/drivers/i2c/busses/i2c-imx-lpi2c.c +++ b/drivers/i2c/busses/i2c-imx-lpi2c.c @@ -116,7 +116,7 @@ static void lpi2c_imx_intctrl(struct lpi2c_imx_struct *lpi2c_imx, static int lpi2c_imx_bus_busy(struct lpi2c_imx_struct *lpi2c_imx) { unsigned int temp; - u64 start = get_time_ns(); + unsigned int timeout = 500000; while (1) { temp = readl(lpi2c_imx->base + LPI2C_MSR); @@ -130,7 +130,8 @@ static int lpi2c_imx_bus_busy(struct lpi2c_imx_struct *lpi2c_imx) if (temp & (MSR_BBF | MSR_MBF)) break; - if (is_timeout(start, 500 * MSECOND)) { + udelay(1); + if (!timeout--) { dev_dbg(&lpi2c_imx->adapter.dev, "bus not work\n"); return -ETIMEDOUT; } @@ -177,7 +178,7 @@ static int lpi2c_imx_start(struct lpi2c_imx_struct *lpi2c_imx, static void lpi2c_imx_stop(struct lpi2c_imx_struct *lpi2c_imx) { unsigned int temp; - u64 start = get_time_ns(); + unsigned int timeout = 500000; writel(GEN_STOP << 8, lpi2c_imx->base + LPI2C_MTDR); @@ -186,7 +187,8 @@ static void lpi2c_imx_stop(struct lpi2c_imx_struct *lpi2c_imx) if (temp & MSR_SDF) break; - if (is_timeout(start, 500 * MSECOND)) { + udelay(1); + if (!timeout--) { dev_dbg(&lpi2c_imx->adapter.dev, "stop timeout\n"); break; } @@ -284,7 +286,7 @@ static int lpi2c_imx_master_disable(struct lpi2c_imx_struct *lpi2c_imx) static int lpi2c_imx_txfifo_empty(struct lpi2c_imx_struct *lpi2c_imx) { u32 txcnt; - u64 start = get_time_ns(); + unsigned int timeout = 500000; do { txcnt = readl(lpi2c_imx->base + LPI2C_MFSR) & 0xff; @@ -294,7 +296,8 @@ static int lpi2c_imx_txfifo_empty(struct lpi2c_imx_struct *lpi2c_imx) return -EIO; } - if (is_timeout(start, 500 * MSECOND)) { + udelay(1); + if (!timeout--) { dev_dbg(&lpi2c_imx->adapter.dev, "txfifo empty timeout\n"); return -ETIMEDOUT; } @@ -326,12 +329,13 @@ static void lpi2c_imx_set_rx_watermark(struct lpi2c_imx_struct *lpi2c_imx) static int lpi2c_imx_write_txfifo(struct lpi2c_imx_struct *lpi2c_imx) { unsigned int data, remaining; - uint64_t start = get_time_ns(); + unsigned int timeout = 100000;; do { u32 cnt = readl(lpi2c_imx->base + LPI2C_MFSR) & 0xff; if (cnt == lpi2c_imx->txfifosize) { - if (is_timeout(start, 100 * MSECOND)) + udelay(1); + if (!timeout--) return -EIO; continue; } @@ -349,12 +353,13 @@ static int lpi2c_imx_read_rxfifo(struct lpi2c_imx_struct *lpi2c_imx) { unsigned int remaining; unsigned int data; - uint64_t start = get_time_ns(); + unsigned int timeout = 100000;; do { data = readl(lpi2c_imx->base + LPI2C_MRDR); if (data & MRDR_RXEMPTY) { - if (is_timeout(start, 100 * MSECOND)) + udelay(1); + if (!timeout--) return -EIO; continue; } |