Skip to content

Commit ef84f88

Browse files
charleskeepaxLee Jones
authored andcommitted
mfd: arizona: Refactor arizona_poll_reg
Currently, we specify the timeout in terms of the number of polls but it is more clear from a user of the functions perspective to specify the timeout directly in milliseconds, as such update the function to these new semantics. Additionally, arizona_poll_reg essentially hard-codes regmap_read_poll_timeout, update 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 <[email protected]> Signed-off-by: Lee Jones <[email protected]>
1 parent f9657b8 commit ef84f88

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

drivers/mfd/arizona-core.c

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -235,29 +235,25 @@ static irqreturn_t arizona_overclocked(int irq, void *data)
235235
return IRQ_HANDLED;
236236
}
237237

238+
#define ARIZONA_REG_POLL_DELAY_US 7500
239+
238240
static int arizona_poll_reg(struct arizona *arizona,
239-
int timeout, unsigned int reg,
241+
int timeout_ms, unsigned int reg,
240242
unsigned int mask, unsigned int target)
241243
{
242244
unsigned int val = 0;
243-
int ret, i;
244-
245-
for (i = 0; i < timeout; i++) {
246-
ret = regmap_read(arizona->regmap, reg, &val);
247-
if (ret != 0) {
248-
dev_err(arizona->dev, "Failed to read reg 0x%x: %d\n",
249-
reg, ret);
250-
continue;
251-
}
252-
253-
if ((val & mask) == target)
254-
return 0;
245+
int ret;
255246

256-
usleep_range(1000, 5000);
257-
}
247+
ret = regmap_read_poll_timeout(arizona->regmap,
248+
ARIZONA_INTERRUPT_RAW_STATUS_5, val,
249+
((val & mask) == target),
250+
ARIZONA_REG_POLL_DELAY_US,
251+
timeout_ms * 1000);
252+
if (ret)
253+
dev_err(arizona->dev, "Polling reg 0x%x timed out: %x\n",
254+
reg, val);
258255

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

263259
static int arizona_wait_for_boot(struct arizona *arizona)
@@ -269,7 +265,7 @@ static int arizona_wait_for_boot(struct arizona *arizona)
269265
* we won't race with the interrupt handler as it'll be blocked on
270266
* runtime resume.
271267
*/
272-
ret = arizona_poll_reg(arizona, 5, ARIZONA_INTERRUPT_RAW_STATUS_5,
268+
ret = arizona_poll_reg(arizona, 30, ARIZONA_INTERRUPT_RAW_STATUS_5,
273269
ARIZONA_BOOT_DONE_STS, ARIZONA_BOOT_DONE_STS);
274270

275271
if (!ret)
@@ -339,7 +335,7 @@ static int arizona_enable_freerun_sysclk(struct arizona *arizona,
339335
ret);
340336
return ret;
341337
}
342-
ret = arizona_poll_reg(arizona, 25, ARIZONA_INTERRUPT_RAW_STATUS_5,
338+
ret = arizona_poll_reg(arizona, 180, ARIZONA_INTERRUPT_RAW_STATUS_5,
343339
ARIZONA_FLL1_CLOCK_OK_STS,
344340
ARIZONA_FLL1_CLOCK_OK_STS);
345341
if (ret)
@@ -403,7 +399,7 @@ static int wm5102_apply_hardware_patch(struct arizona *arizona)
403399
goto err;
404400
}
405401

406-
ret = arizona_poll_reg(arizona, 5, ARIZONA_WRITE_SEQUENCER_CTRL_1,
402+
ret = arizona_poll_reg(arizona, 30, ARIZONA_WRITE_SEQUENCER_CTRL_1,
407403
ARIZONA_WSEQ_BUSY, 0);
408404
if (ret)
409405
regmap_write(arizona->regmap, ARIZONA_WRITE_SEQUENCER_CTRL_0,

0 commit comments

Comments
 (0)