Skip to content

Commit f99fea9

Browse files
charleskeepaxLee Jones
authored andcommitted
mfd: arizona: Don't use regmap_read_poll_timeout
Some Arizona CODECs have a small timing window where they will NAK an I2C transaction if it happens before the boot done bit is set. This can cause the read of the register containing the boot done bit to fail until it is set. Since regmap_read_poll_timeout will abort polling if a read fails it can't be reliably used to poll the boot done bit over I2C. Do a partial revert of ef84f88 ("mfd: arizona: Refactor arizona_poll_reg"), removing the regmap_read_poll_timeout but leaving the refactoring to make the arizona_poll_reg take more sensible arguments. Fixes: ef84f88 ("mfd: arizona: Refactor arizona_poll_reg") Signed-off-by: Charles Keepax <[email protected]> Signed-off-by: Lee Jones <[email protected]>
1 parent a13c93b commit f99fea9

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

drivers/mfd/arizona-core.c

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/regulator/consumer.h>
2525
#include <linux/regulator/machine.h>
2626
#include <linux/slab.h>
27+
#include <linux/ktime.h>
2728
#include <linux/platform_device.h>
2829

2930
#include <linux/mfd/arizona/core.h>
@@ -236,22 +237,39 @@ static irqreturn_t arizona_overclocked(int irq, void *data)
236237

237238
#define ARIZONA_REG_POLL_DELAY_US 7500
238239

240+
static inline bool arizona_poll_reg_delay(ktime_t timeout)
241+
{
242+
if (ktime_compare(ktime_get(), timeout) > 0)
243+
return false;
244+
245+
usleep_range(ARIZONA_REG_POLL_DELAY_US / 2, ARIZONA_REG_POLL_DELAY_US);
246+
247+
return true;
248+
}
249+
239250
static int arizona_poll_reg(struct arizona *arizona,
240251
int timeout_ms, unsigned int reg,
241252
unsigned int mask, unsigned int target)
242253
{
254+
ktime_t timeout = ktime_add_us(ktime_get(), timeout_ms * USEC_PER_MSEC);
243255
unsigned int val = 0;
244256
int ret;
245257

246-
ret = regmap_read_poll_timeout(arizona->regmap,
247-
reg, val, ((val & mask) == target),
248-
ARIZONA_REG_POLL_DELAY_US,
249-
timeout_ms * 1000);
250-
if (ret)
251-
dev_err(arizona->dev, "Polling reg 0x%x timed out: %x\n",
252-
reg, val);
258+
do {
259+
ret = regmap_read(arizona->regmap, reg, &val);
253260

254-
return ret;
261+
if ((val & mask) == target)
262+
return 0;
263+
} while (arizona_poll_reg_delay(timeout));
264+
265+
if (ret) {
266+
dev_err(arizona->dev, "Failed polling reg 0x%x: %d\n",
267+
reg, ret);
268+
return ret;
269+
}
270+
271+
dev_err(arizona->dev, "Polling reg 0x%x timed out: %x\n", reg, val);
272+
return -ETIMEDOUT;
255273
}
256274

257275
static int arizona_wait_for_boot(struct arizona *arizona)

0 commit comments

Comments
 (0)