regulator: ap72200: add retry logic for regulator enablement

In some cases, like if CPU frequencies are increased, the register write
to set voltage may not work on the first attempt as the regulator may
need a small delay after the EN gpio configuration to fully turn on. Add
logic to retry voltage setting up to 5 times after EN gpio configuration
in regulator enable callback to avoid failure due to this delay.

Change-Id: I9e32cb2330363e237b3a0729db5f4e60db774b20
Signed-off-by: Jishnu Prakash <quic_jprakash@quicinc.com>
This commit is contained in:
Jishnu Prakash 2024-09-25 12:17:32 +05:30
parent 2ef8e6f344
commit 5975afdf64

View file

@ -39,18 +39,26 @@ static const struct regmap_config ap27700_regmap_config = {
.max_register = 0x4,
};
#define AP72200_MAX_WRITE_RETRIES 4
static int ap72200_vreg_enable(struct regulator_dev *rdev)
{
struct ap72200_vreg *vreg = rdev_get_drvdata(rdev);
int rc, val;
int rc, val, retries;
gpiod_set_value_cansleep(vreg->ena_gpiod, 1);
val = DIV_ROUND_UP(vreg->rdesc.fixed_uV - AP72200_MIN_UV, AP72200_STEP_UV);
/* Set the voltage */
rc = regmap_write(vreg->regmap, AP72200_VSEL_REG_ADDR,
val);
retries = AP72200_MAX_WRITE_RETRIES;
do {
/* Set the voltage */
rc = regmap_write(vreg->regmap, AP72200_VSEL_REG_ADDR,
val);
if (!rc)
break;
} while (retries--);
if (rc) {
dev_err(vreg->dev, "Failed to set voltage rc: %d\n", rc);
return rc;