dm: regulator: add "regulator-ramp-delay" support
Change-Id: Ic5bc78b2688b88d726c54dfff4f790746d92966b Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
This commit is contained in:
parent
f2d1698c73
commit
b29e2b63a9
|
|
@ -42,6 +42,8 @@ int regulator_set_value(struct udevice *dev, int uV)
|
||||||
{
|
{
|
||||||
const struct dm_regulator_ops *ops = dev_get_driver_ops(dev);
|
const struct dm_regulator_ops *ops = dev_get_driver_ops(dev);
|
||||||
struct dm_regulator_uclass_platdata *uc_pdata;
|
struct dm_regulator_uclass_platdata *uc_pdata;
|
||||||
|
u32 old_uV = -ENODATA, us;
|
||||||
|
int ret;
|
||||||
|
|
||||||
uc_pdata = dev_get_uclass_platdata(dev);
|
uc_pdata = dev_get_uclass_platdata(dev);
|
||||||
if (uc_pdata->min_uV != -ENODATA && uV < uc_pdata->min_uV)
|
if (uc_pdata->min_uV != -ENODATA && uV < uc_pdata->min_uV)
|
||||||
|
|
@ -52,7 +54,24 @@ int regulator_set_value(struct udevice *dev, int uV)
|
||||||
if (!ops || !ops->set_value)
|
if (!ops || !ops->set_value)
|
||||||
return -ENOSYS;
|
return -ENOSYS;
|
||||||
|
|
||||||
return ops->set_value(dev, uV);
|
if (uc_pdata->ramp_delay != -ENODATA) {
|
||||||
|
if (!ops->get_value)
|
||||||
|
return -ENOSYS;
|
||||||
|
old_uV = ops->get_value(dev);
|
||||||
|
if (old_uV < 0)
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = ops->set_value(dev, uV);
|
||||||
|
|
||||||
|
if (!ret && (old_uV != -ENODATA) && (old_uV != uV)) {
|
||||||
|
us = DIV_ROUND_UP(abs(uV - old_uV), uc_pdata->ramp_delay);
|
||||||
|
udelay(us);
|
||||||
|
debug("%s: ramp=%d, old_uV=%d, uV=%d, us=%d\n",
|
||||||
|
uc_pdata->name, uc_pdata->ramp_delay, old_uV, uV, us);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int regulator_set_suspend_value(struct udevice *dev, int uV)
|
int regulator_set_suspend_value(struct udevice *dev, int uV)
|
||||||
|
|
@ -136,6 +155,16 @@ int regulator_set_suspend_enable(struct udevice *dev, bool enable)
|
||||||
return ops->set_suspend_enable(dev, enable);
|
return ops->set_suspend_enable(dev, enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int regulator_set_ramp_delay(struct udevice *dev, u32 ramp_delay)
|
||||||
|
{
|
||||||
|
const struct dm_regulator_ops *ops = dev_get_driver_ops(dev);
|
||||||
|
|
||||||
|
if (!ops || !ops->set_ramp_delay)
|
||||||
|
return -ENOSYS;
|
||||||
|
|
||||||
|
return ops->set_ramp_delay(dev, ramp_delay);
|
||||||
|
}
|
||||||
|
|
||||||
int regulator_get_mode(struct udevice *dev)
|
int regulator_get_mode(struct udevice *dev)
|
||||||
{
|
{
|
||||||
const struct dm_regulator_ops *ops = dev_get_driver_ops(dev);
|
const struct dm_regulator_ops *ops = dev_get_driver_ops(dev);
|
||||||
|
|
@ -202,6 +231,9 @@ int regulator_autoset(struct udevice *dev)
|
||||||
|
|
||||||
uc_pdata = dev_get_uclass_platdata(dev);
|
uc_pdata = dev_get_uclass_platdata(dev);
|
||||||
|
|
||||||
|
if (uc_pdata->ramp_delay != -ENODATA)
|
||||||
|
regulator_set_ramp_delay(dev, uc_pdata->ramp_delay);
|
||||||
|
|
||||||
ret = regulator_set_suspend_enable(dev, uc_pdata->suspend_on);
|
ret = regulator_set_suspend_enable(dev, uc_pdata->suspend_on);
|
||||||
if (!ret && uc_pdata->suspend_on)
|
if (!ret && uc_pdata->suspend_on)
|
||||||
ret = regulator_set_suspend_value(dev, uc_pdata->suspend_uV);
|
ret = regulator_set_suspend_value(dev, uc_pdata->suspend_uV);
|
||||||
|
|
@ -352,7 +384,8 @@ static int regulator_pre_probe(struct udevice *dev)
|
||||||
-ENODATA);
|
-ENODATA);
|
||||||
uc_pdata->always_on = dev_read_bool(dev, "regulator-always-on");
|
uc_pdata->always_on = dev_read_bool(dev, "regulator-always-on");
|
||||||
uc_pdata->boot_on = dev_read_bool(dev, "regulator-boot-on");
|
uc_pdata->boot_on = dev_read_bool(dev, "regulator-boot-on");
|
||||||
|
uc_pdata->ramp_delay = dev_read_u32_default(dev, "regulator-ramp-delay",
|
||||||
|
-ENODATA);
|
||||||
node = dev_read_subnode(dev, "regulator-state-mem");
|
node = dev_read_subnode(dev, "regulator-state-mem");
|
||||||
if (ofnode_valid(node)) {
|
if (ofnode_valid(node)) {
|
||||||
uc_pdata->suspend_on = !ofnode_read_bool(node, "regulator-off-in-suspend");
|
uc_pdata->suspend_on = !ofnode_read_bool(node, "regulator-off-in-suspend");
|
||||||
|
|
|
||||||
|
|
@ -179,6 +179,7 @@ struct dm_regulator_uclass_platdata {
|
||||||
u8 volt_reg;
|
u8 volt_reg;
|
||||||
bool suspend_on;
|
bool suspend_on;
|
||||||
u32 suspend_uV;
|
u32 suspend_uV;
|
||||||
|
u32 ramp_delay;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Regulator device operations */
|
/* Regulator device operations */
|
||||||
|
|
@ -237,6 +238,15 @@ struct dm_regulator_ops {
|
||||||
*/
|
*/
|
||||||
int (*get_mode)(struct udevice *dev);
|
int (*get_mode)(struct udevice *dev);
|
||||||
int (*set_mode)(struct udevice *dev, int mode_id);
|
int (*set_mode)(struct udevice *dev, int mode_id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The regulator voltage set ramp delay
|
||||||
|
*
|
||||||
|
* @dev - regulator device
|
||||||
|
* @ramp_delay - ramp delay [uV/uS]
|
||||||
|
* @return zero on success and other failed.
|
||||||
|
*/
|
||||||
|
int (*set_ramp_delay)(struct udevice *dev, u32 ramp_delay);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue