mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-15 17:43:59 +00:00
mfd: arizona: Factor out register polling
Factor out the polling of the interrupt status register whilst we wait for boot done to allow the polling to be reused in other situations. Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
parent
4c9bb8bc35
commit
9d53dfdc82
@ -196,42 +196,50 @@ static irqreturn_t arizona_overclocked(int irq, void *data)
|
|||||||
return IRQ_HANDLED;
|
return IRQ_HANDLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int arizona_poll_reg(struct arizona *arizona,
|
||||||
|
int timeout, unsigned int reg,
|
||||||
|
unsigned int mask, unsigned int target)
|
||||||
|
{
|
||||||
|
unsigned int val = 0;
|
||||||
|
int ret, i;
|
||||||
|
|
||||||
|
for (i = 0; i < timeout; i++) {
|
||||||
|
ret = regmap_read(arizona->regmap, reg, &val);
|
||||||
|
if (ret != 0) {
|
||||||
|
dev_err(arizona->dev, "Failed to read reg %u: %d\n",
|
||||||
|
reg, ret);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((val & mask) == target)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
msleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
dev_err(arizona->dev, "Polling reg %u timed out: %x\n", reg, val);
|
||||||
|
return -ETIMEDOUT;
|
||||||
|
}
|
||||||
|
|
||||||
static int arizona_wait_for_boot(struct arizona *arizona)
|
static int arizona_wait_for_boot(struct arizona *arizona)
|
||||||
{
|
{
|
||||||
unsigned int reg;
|
int ret;
|
||||||
int ret, i;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We can't use an interrupt as we need to runtime resume to do so,
|
* We can't use an interrupt as we need to runtime resume to do so,
|
||||||
* we won't race with the interrupt handler as it'll be blocked on
|
* we won't race with the interrupt handler as it'll be blocked on
|
||||||
* runtime resume.
|
* runtime resume.
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < 5; i++) {
|
ret = arizona_poll_reg(arizona, 5, ARIZONA_INTERRUPT_RAW_STATUS_5,
|
||||||
msleep(1);
|
ARIZONA_BOOT_DONE_STS, ARIZONA_BOOT_DONE_STS);
|
||||||
|
|
||||||
ret = regmap_read(arizona->regmap,
|
if (!ret)
|
||||||
ARIZONA_INTERRUPT_RAW_STATUS_5, ®);
|
|
||||||
if (ret != 0) {
|
|
||||||
dev_err(arizona->dev, "Failed to read boot state: %d\n",
|
|
||||||
ret);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (reg & ARIZONA_BOOT_DONE_STS)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (reg & ARIZONA_BOOT_DONE_STS) {
|
|
||||||
regmap_write(arizona->regmap, ARIZONA_INTERRUPT_STATUS_5,
|
regmap_write(arizona->regmap, ARIZONA_INTERRUPT_STATUS_5,
|
||||||
ARIZONA_BOOT_DONE_STS);
|
ARIZONA_BOOT_DONE_STS);
|
||||||
} else {
|
|
||||||
dev_err(arizona->dev, "Device boot timed out: %x\n", reg);
|
|
||||||
return -ETIMEDOUT;
|
|
||||||
}
|
|
||||||
|
|
||||||
pm_runtime_mark_last_busy(arizona->dev);
|
pm_runtime_mark_last_busy(arizona->dev);
|
||||||
|
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_PM_RUNTIME
|
#ifdef CONFIG_PM_RUNTIME
|
||||||
|
Loading…
x
Reference in New Issue
Block a user