[Letux-kernel] [Internal RFC 11/16] regulator: twl: Expose the TWL4030's REGEN signal as a regulator
H. Nikolaus Schaller
hns at goldelico.com
Wed Sep 7 20:01:50 CEST 2022
From: Grond <grond66 at riseup.net>
This is needed on some boards (for example, the Pandora), where REGEN is
used to drive external regulators.
Signed-off-by: Grond <grond66 at riseup.net>
Signed-off-by: H. Nikolaus Schaller <hns at goldelico.com>
---
drivers/regulator/twl-regulator.c | 52 +++++++++++++++++++++++++++++++
include/linux/mfd/twl.h | 3 ++
2 files changed, 55 insertions(+)
diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c
index e2a20d5121529..72dd6e7e67171 100644
--- a/drivers/regulator/twl-regulator.c
+++ b/drivers/regulator/twl-regulator.c
@@ -452,6 +452,16 @@ static const struct regulator_ops twl4030fixed_ops = {
.get_status = twl4030reg_get_status,
};
+static const struct regulator_ops twl4030signal_ops = {
+ .enable = twl4030reg_enable,
+ .disable = twl4030reg_disable,
+ .is_enabled = twl4030reg_is_enabled,
+
+ .set_mode = twl4030reg_set_mode,
+
+ .get_status = twl4030reg_get_status,
+};
+
/*----------------------------------------------------------------------*/
#define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf) \
@@ -512,6 +522,24 @@ static const struct twlreg_info TWLFIXED_INFO_##label = { \
}, \
}
+#define TWL4030_SIGNAL(label, offset, num, remap_conf) \
+static const struct twlreg_info TWLSIGNAL_INFO_##label = { \
+ .base = offset, \
+ .id = num, \
+ .remap = remap_conf, \
+ .desc = { \
+ .name = #label, \
+ .id = TWL4030_REG_##label, \
+ .n_voltages = 1, \
+ .fixed_uV = 0, /* filled in from DT later */ \
+ .ops = &twl4030signal_ops, \
+ .type = REGULATOR_VOLTAGE, \
+ .owner = THIS_MODULE, \
+ .enable_time = 0, /* also filled in from DT */ \
+ .of_map_mode = twl4030reg_map_mode, \
+ }, \
+ }
+
/*
* We list regulators here if systems need some level of
* software control over them after boot.
@@ -537,6 +565,7 @@ TWL4030_FIXED_LDO(VINTDIG, 0x47, 1500, 13, 100, 0x08);
TWL4030_FIXED_LDO(VUSB1V5, 0x71, 1500, 17, 100, 0x08);
TWL4030_FIXED_LDO(VUSB1V8, 0x74, 1800, 18, 100, 0x08);
TWL4030_FIXED_LDO(VUSB3V1, 0x77, 3100, 19, 150, 0x08);
+TWL4030_SIGNAL(REGEN, 0x7f, 21, 0x08);
#define TWL_OF_MATCH(comp, family, label) \
{ \
@@ -549,6 +578,7 @@ TWL4030_FIXED_LDO(VUSB3V1, 0x77, 3100, 19, 150, 0x08);
#define TWL6032_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6032, label)
#define TWLFIXED_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLFIXED, label)
#define TWLSMPS_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLSMPS, label)
+#define TWLSIGNAL_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLSIGNAL, label)
static const struct of_device_id twl_of_match[] = {
TWL4030_OF_MATCH("ti,twl4030-vaux1", VAUX1),
@@ -571,6 +601,7 @@ static const struct of_device_id twl_of_match[] = {
TWLFIXED_OF_MATCH("ti,twl4030-vusb1v5", VUSB1V5),
TWLFIXED_OF_MATCH("ti,twl4030-vusb1v8", VUSB1V8),
TWLFIXED_OF_MATCH("ti,twl4030-vusb3v1", VUSB3V1),
+ TWLSIGNAL_OF_MATCH("ti,twl4030-regen", REGEN),
{},
};
MODULE_DEVICE_TABLE(of, twl_of_match);
@@ -584,6 +615,7 @@ static int twlreg_probe(struct platform_device *pdev)
struct regulation_constraints *c;
struct regulator_dev *rdev;
struct regulator_config config = { };
+ int ret;
template = of_device_get_match_data(&pdev->dev);
if (!template)
@@ -616,6 +648,26 @@ static int twlreg_probe(struct platform_device *pdev)
case TWL4030_REG_VINTANA2:
case TWL4030_REG_VINTDIG:
c->always_on = true;
+ break;
+ case TWL4030_REG_REGEN:
+ if (c->min_uV == 0 || c->max_uV == 0) {
+ dev_err(&pdev->dev, "minimum or maximum regulator voltage zero in DT\n");
+ return -EINVAL;
+ }
+
+ if (c->min_uV != c->max_uV) {
+ dev_err(&pdev->dev, "minimum and maximum voltage are different in DT\n");
+ return -EINVAL;
+ }
+ info->desc.fixed_uV = c->min_uV;
+
+ ret = of_property_read_u32(pdev->dev.of_node, "startup-delay-us",
+ &info->desc.enable_time);
+ if (ret) {
+ dev_err(&pdev->dev, "no valid startup delay set in DT: %d\n", ret);
+ return ret;
+ }
+
break;
default:
break;
diff --git a/include/linux/mfd/twl.h b/include/linux/mfd/twl.h
index eaa2330382546..b27f2370af09a 100644
--- a/include/linux/mfd/twl.h
+++ b/include/linux/mfd/twl.h
@@ -759,6 +759,9 @@ int twl4030_sih_setup(struct device *dev, int module, int irq_base);
#define TWL4030_REG_VUSB1V8 18
#define TWL4030_REG_VUSB3V1 19
+/* digital output signal for enabling external regulators */
+#define TWL4030_REG_REGEN 21
+
/* TWL6030 SMPS/LDO's */
/* EXTERNAL dc-to-dc buck convertor controllable via SR */
#define TWL6030_REG_VDD1 30
--
2.33.0
More information about the Letux-kernel
mailing list