[PATCH v3 4/4] mfd: arizona: Use regmap_read_poll_timeout instead of hard coding it

From: Charles Keepax
Date: Thu Feb 09 2017 - 08:32:30 EST


arizona_poll_reg essentially hard-codes regmap_read_poll_timeout, this
patch updates the implementation to use regmap_read_poll_timeout. We
still keep arizona_poll_reg around as regmap_read_poll_timeout is a
macro so rather than expand this for each caller keep it wrapped in
arizona_poll_reg.

Whilst we are doing this make the timeouts a little more generous as the
previous system had a bit more slack as it was done as a delay per
iteration of the loop whereas regmap_read_poll_timeout compares ktime's.

Signed-off-by: Charles Keepax <ckeepax@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
---

Changes since v2:
- No changes

drivers/mfd/arizona-core.c | 38 ++++++++++++++------------------------
1 file changed, 14 insertions(+), 24 deletions(-)

diff --git a/drivers/mfd/arizona-core.c b/drivers/mfd/arizona-core.c
index 09d48ed..75488e6 100644
--- a/drivers/mfd/arizona-core.c
+++ b/drivers/mfd/arizona-core.c
@@ -235,35 +235,25 @@ static irqreturn_t arizona_overclocked(int irq, void *data)
return IRQ_HANDLED;
}

-#define ARIZONA_REG_POLL_DELAY_MS 5
-#define ARIZONA_REG_POLL_DELAY_US (ARIZONA_REG_POLL_DELAY_MS * 1000)
+#define ARIZONA_REG_POLL_DELAY_US 7500

static int arizona_poll_reg(struct arizona *arizona,
int timeout_ms, unsigned int reg,
unsigned int mask, unsigned int target)
{
- unsigned int npolls = (timeout_ms + ARIZONA_REG_POLL_DELAY_MS - 1) /
- ARIZONA_REG_POLL_DELAY_MS;
unsigned int val = 0;
- int ret, i;
-
- for (i = 0; i < npolls; i++) {
- ret = regmap_read(arizona->regmap, reg, &val);
- if (ret != 0) {
- dev_err(arizona->dev, "Failed to read reg 0x%x: %d\n",
- reg, ret);
- continue;
- }
-
- if ((val & mask) == target)
- return 0;
+ int ret;

- usleep_range(ARIZONA_REG_POLL_DELAY_US,
- ARIZONA_REG_POLL_DELAY_US * 2);
- }
+ ret = regmap_read_poll_timeout(arizona->regmap,
+ ARIZONA_INTERRUPT_RAW_STATUS_5, val,
+ ((val & mask) == target),
+ ARIZONA_REG_POLL_DELAY_US,
+ timeout_ms * 1000);
+ if (ret)
+ dev_err(arizona->dev, "Polling reg 0x%x timed out: %x\n",
+ reg, val);

- dev_err(arizona->dev, "Polling reg 0x%x timed out: %x\n", reg, val);
- return -ETIMEDOUT;
+ return ret;
}

static int arizona_wait_for_boot(struct arizona *arizona)
@@ -275,7 +265,7 @@ static int arizona_wait_for_boot(struct arizona *arizona)
* we won't race with the interrupt handler as it'll be blocked on
* runtime resume.
*/
- ret = arizona_poll_reg(arizona, 25, ARIZONA_INTERRUPT_RAW_STATUS_5,
+ ret = arizona_poll_reg(arizona, 30, ARIZONA_INTERRUPT_RAW_STATUS_5,
ARIZONA_BOOT_DONE_STS, ARIZONA_BOOT_DONE_STS);

if (!ret)
@@ -345,7 +335,7 @@ static int arizona_enable_freerun_sysclk(struct arizona *arizona,
ret);
return ret;
}
- ret = arizona_poll_reg(arizona, 125, ARIZONA_INTERRUPT_RAW_STATUS_5,
+ ret = arizona_poll_reg(arizona, 180, ARIZONA_INTERRUPT_RAW_STATUS_5,
ARIZONA_FLL1_CLOCK_OK_STS,
ARIZONA_FLL1_CLOCK_OK_STS);
if (ret)
@@ -409,7 +399,7 @@ static int wm5102_apply_hardware_patch(struct arizona *arizona)
goto err;
}

- ret = arizona_poll_reg(arizona, 25, ARIZONA_WRITE_SEQUENCER_CTRL_1,
+ ret = arizona_poll_reg(arizona, 30, ARIZONA_WRITE_SEQUENCER_CTRL_1,
ARIZONA_WSEQ_BUSY, 0);
if (ret)
regmap_write(arizona->regmap, ARIZONA_WRITE_SEQUENCER_CTRL_0,
--
2.1.4