mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2024-12-28 16:52:18 +00:00
regulator: mp8859: Implement set_current_limit()
The mp8859 implements support for current limiting, provide support for configuring this via the driver. The datasheet recommends that if the device has hit the current limit then any changes should be implemented via a ramp so we do so in the driver. Tested-by: Markus Reichl <m.reichl@fivetechno.de> Signed-off-by: Mark Brown <broonie@kernel.org> Link: https://msgid.link/r/20240225-regulator-mp8859-v1-8-68ee2c839ded@kernel.org Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
6df0921e90
commit
c8e794cfb0
@ -35,6 +35,8 @@
|
||||
|
||||
#define MP8859_GO_BIT 0x01
|
||||
|
||||
#define MP8859_IOUT_LIM_MASK 0x7f
|
||||
|
||||
#define MP8859_ENABLE_MASK 0x80
|
||||
#define MP8859_DISCHG_EN_MASK 0x10
|
||||
#define MP8859_MODE_MASK 0x08
|
||||
@ -131,6 +133,58 @@ static int mp8859_set_mode(struct regulator_dev *rdev, unsigned int mode)
|
||||
MP8859_MODE_MASK, val);
|
||||
}
|
||||
|
||||
static int mp8859_set_current_limit(struct regulator_dev *rdev,
|
||||
int min_uA, int max_uA)
|
||||
{
|
||||
unsigned int cur_val, new_val;
|
||||
int ret, i;
|
||||
|
||||
/* Steps of 50mA */
|
||||
new_val = max_uA / 50000;
|
||||
if (new_val > MP8859_IOUT_LIM_MASK)
|
||||
return -EINVAL;
|
||||
if (new_val == 0)
|
||||
return -EINVAL;
|
||||
|
||||
/*
|
||||
* If the regulator is limiting then ramp gradually as per
|
||||
* datasheet, otherwise just set the value directly.
|
||||
*/
|
||||
ret = regmap_read(rdev->regmap, MP8859_STATUS_REG, &cur_val);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
if (!(cur_val & MP8859_CC_CV_MASK)) {
|
||||
return regmap_update_bits(rdev->regmap, MP8859_IOUT_LIM_REG,
|
||||
MP8859_IOUT_LIM_MASK, new_val);
|
||||
}
|
||||
|
||||
ret = regmap_read(rdev->regmap, MP8859_IOUT_LIM_REG, &cur_val);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
if (cur_val >= new_val) {
|
||||
for (i = cur_val; i >= new_val; i--) {
|
||||
ret = regmap_update_bits(rdev->regmap,
|
||||
MP8859_IOUT_LIM_REG,
|
||||
MP8859_IOUT_LIM_MASK,
|
||||
cur_val - i);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
for (i = cur_val; i <= new_val; i++) {
|
||||
ret = regmap_update_bits(rdev->regmap,
|
||||
MP8859_IOUT_LIM_REG,
|
||||
MP8859_IOUT_LIM_MASK,
|
||||
cur_val + i);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mp8859_get_status(struct regulator_dev *rdev)
|
||||
{
|
||||
unsigned int val;
|
||||
@ -241,6 +295,7 @@ static const struct regulator_ops mp8859_ops = {
|
||||
.set_mode = mp8859_set_mode,
|
||||
.get_mode = mp8859_get_mode,
|
||||
.set_active_discharge = regulator_set_active_discharge_regmap,
|
||||
.set_current_limit = mp8859_set_current_limit,
|
||||
.get_status = mp8859_get_status,
|
||||
.get_error_flags = mp8859_get_error_flags,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user