Skip to content

Commit aafc51f

Browse files
AxelLingregkh
authored andcommitted
regulator: rtmv20: Fix .set_current_limit/.get_current_limit callbacks
commit 86ab21c upstream. Current code does not set .curr_table and .n_linear_ranges settings, so it cannot use the regulator_get/set_current_limit_regmap helpers. If we setup the curr_table, it will has 200 entries. Implement customized .set_current_limit/.get_current_limit callbacks instead. Fixes: b8c054a ("regulator: rtmv20: Adds support for Richtek RTMV20 load switch regulator") Signed-off-by: Axel Lin <axel.lin@ingics.com> Reviewed-by: ChiYuan Huang <cy_huang@richtek.com> Link: https://lore.kernel.org/r/20210530124101.477727-1-axel.lin@ingics.com Signed-off-by: Mark Brown <broonie@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4579f65 commit aafc51f

1 file changed

Lines changed: 40 additions & 2 deletions

File tree

‎drivers/regulator/rtmv20-regulator.c‎

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,47 @@ static int rtmv20_lsw_disable(struct regulator_dev *rdev)
103103
return 0;
104104
}
105105

106+
static int rtmv20_lsw_set_current_limit(struct regulator_dev *rdev, int min_uA,
107+
int max_uA)
108+
{
109+
int sel;
110+
111+
if (min_uA > RTMV20_LSW_MAXUA || max_uA < RTMV20_LSW_MINUA)
112+
return -EINVAL;
113+
114+
if (max_uA > RTMV20_LSW_MAXUA)
115+
max_uA = RTMV20_LSW_MAXUA;
116+
117+
sel = (max_uA - RTMV20_LSW_MINUA) / RTMV20_LSW_STEPUA;
118+
119+
/* Ensure the selected setting is still in range */
120+
if ((sel * RTMV20_LSW_STEPUA + RTMV20_LSW_MINUA) < min_uA)
121+
return -EINVAL;
122+
123+
sel <<= ffs(rdev->desc->csel_mask) - 1;
124+
125+
return regmap_update_bits(rdev->regmap, rdev->desc->csel_reg,
126+
rdev->desc->csel_mask, sel);
127+
}
128+
129+
static int rtmv20_lsw_get_current_limit(struct regulator_dev *rdev)
130+
{
131+
unsigned int val;
132+
int ret;
133+
134+
ret = regmap_read(rdev->regmap, rdev->desc->csel_reg, &val);
135+
if (ret)
136+
return ret;
137+
138+
val &= rdev->desc->csel_mask;
139+
val >>= ffs(rdev->desc->csel_mask) - 1;
140+
141+
return val * RTMV20_LSW_STEPUA + RTMV20_LSW_MINUA;
142+
}
143+
106144
static const struct regulator_ops rtmv20_regulator_ops = {
107-
.set_current_limit = regulator_set_current_limit_regmap,
108-
.get_current_limit = regulator_get_current_limit_regmap,
145+
.set_current_limit = rtmv20_lsw_set_current_limit,
146+
.get_current_limit = rtmv20_lsw_get_current_limit,
109147
.enable = rtmv20_lsw_enable,
110148
.disable = rtmv20_lsw_disable,
111149
.is_enabled = regulator_is_enabled_regmap,

0 commit comments

Comments
 (0)