Skip to contentSkip to conversation

regulator: rtmv20: Fix .set_current_limit/.get_current_limit callbacks

PATCH In review Axel Lin 3 participants 4 messages May 30, 2021 – Jun 1, 2021 Voltage and current regulator framework

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/2 regulator: rtmv20: Fix .set_current_limit/.get_current_limit callbacks

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 b8c054a5eaf0 ("regulator: rtmv20: Adds support for Richtek RTMV20 load switch regulator")

---
Hi ChiYuan,
I don't have this h/w to test.
Please help to review and test this patch.

Thanks,
Axel

 drivers/regulator/rtmv20-regulator.c | 42 ++++++++++++++++++++++++++--
 1 file changed, 40 insertions(+), 2 deletions(-)
drivers/regulator/rtmv20-regulator.c +40 -2
index 852fb2596ffd..5adc552dffd5 100644
@@ -103,9 +103,47 @@ static int rtmv20_lsw_disable(struct regulator_dev *rdev)
 	return 0;
 }
 
+static int rtmv20_lsw_set_current_limit(struct regulator_dev *rdev, int min_uA,
+					int max_uA)
+{
+	int sel;
+
+	if (min_uA > RTMV20_LSW_MAXUA || max_uA < RTMV20_LSW_MINUA)
+		return -EINVAL;
+
+	if (max_uA > RTMV20_LSW_MAXUA)
+		max_uA = RTMV20_LSW_MAXUA;
+
+	sel = (max_uA - RTMV20_LSW_MINUA) / RTMV20_LSW_STEPUA;
+
+	/* Ensure the selected setting is still in range */
+	if ((sel * RTMV20_LSW_STEPUA + RTMV20_LSW_MINUA) < min_uA)
+		return -EINVAL;
+
+	sel <<= ffs(rdev->desc->csel_mask) - 1;
+
+	return regmap_update_bits(rdev->regmap, rdev->desc->csel_reg,
+				  rdev->desc->csel_mask, sel);
+}
+
+static int rtmv20_lsw_get_current_limit(struct regulator_dev *rdev)
+{
+	unsigned int val;
+	int ret;
+
+	ret = regmap_read(rdev->regmap, rdev->desc->csel_reg, &val);
+	if (ret)
+		return ret;
+
+	val &= rdev->desc->csel_mask;
+	val >>= ffs(rdev->desc->csel_mask) - 1;
+
+	return val * RTMV20_LSW_STEPUA + RTMV20_LSW_MINUA;
+}
+
 static const struct regulator_ops rtmv20_regulator_ops = {
-	.set_current_limit = regulator_set_current_limit_regmap,
-	.get_current_limit = regulator_get_current_limit_regmap,
+	.set_current_limit = rtmv20_lsw_set_current_limit,
+	.get_current_limit = rtmv20_lsw_get_current_limit,
 	.enable = rtmv20_lsw_enable,
 	.disable = rtmv20_lsw_disable,
 	.is_enabled = regulator_is_enabled_regmap,
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH 2/2 regulator: rtmv20: Add Richtek to Kconfig text

The other Richtek drivers has Richtek prefix, make it consistent.

---
 drivers/regulator/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/regulator/Kconfig +1 -1
index 9aeb32c320aa..fc9e8f589d16 100644
@@ -1032,7 +1032,7 @@ config REGULATOR_RT5033
 	  current source, LDO and Buck.
 
 config REGULATOR_RTMV20
-	tristate "RTMV20 Laser Diode Regulator"
+	tristate "Richtek RTMV20 Laser Diode Regulator"
 	depends on I2C
 	select REGMAP_I2C
 	help
Signature · 1 line
2.25.1
Reviewed-by on v1 1/2
#2 lore raw
In reply to Axel Lin
Quoted 9 lines

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 b8c054a5eaf0 ("regulator: rtmv20: Adds support for Richtek RTMV20 load

switch regulator")

Quoted 8 lines

---
Hi ChiYuan,
I don't have this h/w to test.
Please help to review and test this patch.

Thanks,
Axel

Thanks for the fix. I really didn't notice that.

Quoted 60 lines

 drivers/regulator/rtmv20-regulator.c | 42 ++++++++++++++++++++++++++--
 1 file changed, 40 insertions(+), 2 deletions(-)
drivers/regulator/rtmv20- renamed from drivers/regulator/rtmv20-regulator.c +0 -0

regulator.c
index 852fb2596ffd..5adc552dffd5 100644

drivers/regulator/rtmv20-regulator.c +40 -2
@@ -103,9 +103,47 @@ static int rtmv20_lsw_disable(struct regulator_dev *rdev)
 return 0;
 }
 
+static int rtmv20_lsw_set_current_limit(struct regulator_dev *rdev, int
 min_uA,
+int max_uA)
+{
+int sel;
+
+if (min_uA > RTMV20_LSW_MAXUA || max_uA < RTMV20_LSW_MINUA)
+return -EINVAL;
+
+if (max_uA > RTMV20_LSW_MAXUA)
+max_uA = RTMV20_LSW_MAXUA;
+
+sel = (max_uA - RTMV20_LSW_MINUA) / RTMV20_LSW_STEPUA;
+
+/* Ensure the selected setting is still in range */
+if ((sel * RTMV20_LSW_STEPUA + RTMV20_LSW_MINUA) < min_uA)
+return -EINVAL;
+
+sel <<= ffs(rdev->desc->csel_mask) - 1;
+
+return regmap_update_bits(rdev->regmap, rdev->desc->csel_reg,
+  rdev->desc->csel_mask, sel);
+}
+
+static int rtmv20_lsw_get_current_limit(struct regulator_dev *rdev)
+{
+unsigned int val;
+int ret;
+
+ret = regmap_read(rdev->regmap, rdev->desc->csel_reg, &val);
+if (ret)
+return ret;
+
+val &= rdev->desc->csel_mask;
+val >>= ffs(rdev->desc->csel_mask) - 1;
+
+return val * RTMV20_LSW_STEPUA + RTMV20_LSW_MINUA;
+}
+
 static const struct regulator_ops rtmv20_regulator_ops = {
-.set_current_limit = regulator_set_current_limit_regmap,
-.get_current_limit = regulator_get_current_limit_regmap,
+.set_current_limit = rtmv20_lsw_set_current_limit,
+.get_current_limit = rtmv20_lsw_get_current_limit,
 .enable = rtmv20_lsw_enable,
 .disable = rtmv20_lsw_disable,
Quoted 1 line

.is_enabled = regulator_is_enabled_regmap,

************* Email Confidentiality Notice ********************

The information contained in this e-mail message (including any attachments) may be confidential, proprietary, privileged, or otherwise exempt from disclosure under applicable laws. It is intended to be conveyed only to the designated recipient(s). Any use, dissemination, distribution, printing, retaining or copying of this e-mail (including its attachments) by unintended recipient(s) is strictly prohibited and may be unlawful. If you are not an intended recipient of this e-mail, or believe that you have received this e-mail in error, please notify the sender immediately (by replying to this e-mail), delete any and all copies of this e-mail (including any attachments) from your system, and do not disclose the content of this e-mail to any other person. Thank you!

maintainer
#3 lore raw
In reply to Axel Lin
Quoted 5 lines · Axel Lin

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.

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-next

Thanks!

[1/2] regulator: rtmv20: Fix .set_current_limit/.get_current_limit callbacks

      commit: 86ab21cc39e6b99b7065ab9008c90bec5dec535a
[2/2] regulator: rtmv20: Add Richtek to Kconfig text
      commit: 5f01de6ffae2b00d3795a399d8d630bdae3c8997

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark