staticint max77802_get_opmode_shift(int id)
{ if (id == MAX77802_BUCK1 || (id >= MAX77802_BUCK5 &&
id <= MAX77802_BUCK10)) return 0;
if (id >= MAX77802_BUCK2 && id <= MAX77802_BUCK4) return MAX77802_OPMODE_BUCK234_SHIFT;
if (id >= MAX77802_LDO1 && id <= MAX77802_LDO35) return MAX77802_OPMODE_SHIFT_LDO;
return -EINVAL;
}
/** * max77802_set_suspend_disable - Disable the regulator during system suspend * @rdev: regulator to mark as disabled * * All regulators expect LDO 1, 3, 20 and 21 support OFF by PWRREQ. * Configure the regulator so the PMIC will turn it OFF during system suspend.
*/ staticint max77802_set_suspend_disable(struct regulator_dev *rdev)
{ unsignedint val = MAX77802_OFF_PWRREQ; struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev); unsignedint id = rdev_get_id(rdev); int shift = max77802_get_opmode_shift(id);
if (WARN_ON_ONCE(id >= ARRAY_SIZE(max77802->opmode))) return -EINVAL;
max77802->opmode[id] = val; return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
rdev->desc->enable_mask, val << shift);
}
/* * Some LDOs support Low Power Mode while the system is running. * * LDOs 1, 3, 20, 21.
*/ staticint max77802_set_mode(struct regulator_dev *rdev, unsignedint mode)
{ struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev); unsignedint id = rdev_get_id(rdev); unsignedint val; int shift = max77802_get_opmode_shift(id);
switch (mode) { case REGULATOR_MODE_STANDBY:
val = MAX77802_OPMODE_LP; /* ON in Low Power Mode */ break; case REGULATOR_MODE_NORMAL:
val = MAX77802_OPMODE_NORMAL; /* ON in Normal Mode */ break; default:
dev_warn(&rdev->dev, "%s: regulator mode: 0x%x not supported\n",
rdev->desc->name, mode); return -EINVAL;
}
if (WARN_ON_ONCE(id >= ARRAY_SIZE(max77802->opmode))) return -EINVAL;
if (WARN_ON_ONCE(id >= ARRAY_SIZE(max77802->opmode))) return -EINVAL; return max77802_map_mode(max77802->opmode[id]);
}
/** * max77802_set_suspend_mode - set regulator opmode when the system is suspended * @rdev: regulator to change mode * @mode: operating mode to be set * * Will set the operating mode for the regulators during system suspend. * This function is valid for the three different enable control logics: * * Enable Control Logic1 by PWRREQ (BUCK 2-4 and LDOs 2, 4-19, 22-35) * Enable Control Logic2 by PWRREQ (LDOs 1, 20, 21) * Enable Control Logic3 by PWRREQ (LDO 3) * * If setting the regulator mode fails, the function only warns but does * not return a negative error number to avoid the regulator core to stop * setting the operating mode for the remaining regulators.
*/ staticint max77802_set_suspend_mode(struct regulator_dev *rdev, unsignedint mode)
{ struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev); unsignedint id = rdev_get_id(rdev); unsignedint val; int shift = max77802_get_opmode_shift(id);
if (WARN_ON_ONCE(id >= ARRAY_SIZE(max77802->opmode))) return -EINVAL;
/* * If the regulator has been disabled for suspend * then is invalid to try setting a suspend mode.
*/ if (max77802->opmode[id] == MAX77802_OFF_PWRREQ) {
dev_warn(&rdev->dev, "%s: is disabled, mode: 0x%x not set\n",
rdev->desc->name, mode); return 0;
}
switch (mode) { case REGULATOR_MODE_STANDBY: /* * If the regulator opmode is normal then enable * ON in Low Power Mode by PWRREQ. If the mode is * already Low Power then no action is required.
*/ if (max77802->opmode[id] == MAX77802_OPMODE_NORMAL)
val = MAX77802_LP_PWRREQ; else return 0; break; case REGULATOR_MODE_NORMAL: /* * If the regulator operating mode is Low Power then * normal is not a valid opmode in suspend. If the * mode is already normal then no action is required.
*/ if (max77802->opmode[id] == MAX77802_OPMODE_LP)
dev_warn(&rdev->dev, "%s: in Low Power: 0x%x invalid\n",
rdev->desc->name, mode); return 0; default:
dev_warn(&rdev->dev, "%s: regulator mode: 0x%x not supported\n",
rdev->desc->name, mode); return -EINVAL;
}
return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
rdev->desc->enable_mask, val << shift);
}
staticint max77802_enable(struct regulator_dev *rdev)
{ struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev); unsignedint id = rdev_get_id(rdev); int shift = max77802_get_opmode_shift(id);
if (WARN_ON_ONCE(id >= ARRAY_SIZE(max77802->opmode))) return -EINVAL; if (max77802->opmode[id] == MAX77802_OFF_PWRREQ)
max77802->opmode[id] = MAX77802_OPMODE_NORMAL;
for (i = 0; i < MAX77802_REG_MAX; i++) { struct regulator_dev *rdev; unsignedint id = regulators[i].id; int shift = max77802_get_opmode_shift(id); int ret;
ret = regmap_read(iodev->regmap, regulators[i].enable_reg, &val); if (ret < 0) {
dev_warn(&pdev->dev, "cannot read current mode for %d\n", i);
val = MAX77802_OPMODE_NORMAL;
} else {
val = val >> shift & MAX77802_OPMODE_MASK;
}
/* * If the regulator is disabled and the system warm rebooted, * the hardware reports OFF as the regulator operating mode. * Default to operating mode NORMAL in that case.
*/ if (id < ARRAY_SIZE(max77802->opmode)) { if (val == MAX77802_STATUS_OFF)
max77802->opmode[id] = MAX77802_OPMODE_NORMAL; else
max77802->opmode[id] = val;
}
rdev = devm_regulator_register(&pdev->dev,
®ulators[i], &config); if (IS_ERR(rdev)) {
ret = PTR_ERR(rdev);
dev_err(&pdev->dev, "regulator init failed for %d: %d\n", i, ret); return ret;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.