[Letux-kernel] [PATCH 5/8] regulator: twl: Expose the TWL4030's REGEN signal as a regulator
Grond
grond66 at riseup.net
Thu Dec 30 11:25:18 CET 2021
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>
---
.../bindings/regulator/twl-regulator.txt | 12 +++++
arch/arm/boot/dts/twl4030.dtsi | 14 +++++
drivers/regulator/twl-regulator.c | 51 +++++++++++++++++++
include/linux/mfd/twl.h | 3 ++
4 files changed, 80 insertions(+)
diff --git a/Documentation/devicetree/bindings/regulator/twl-regulator.txt b/Documentation/devicetree/bindings/regulator/twl-regulator.txt
index 549f80436deb..13488784add9 100644
--- a/Documentation/devicetree/bindings/regulator/twl-regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/twl-regulator.txt
@@ -54,6 +54,18 @@ For twl4030 regulators/LDOs
- "ti,twl4030-vusb1v5" for VUSB1V5 LDO
- "ti,twl4030-vusb1v8" for VUSB1V8 LDO
- "ti,twl4030-vusb3v1" for VUSB3V1 LDO
+ - "ti,twl4030-regen" for REGEN external regulator enable signal
+
+Reguired properties:
+For twl3040 REGEN signal:
+ - regulator-min-microvolt:
+ - Same meaning as in bindings/regulator/regulator.yaml, but must match
+ regulator-max-microvolt.
+ - regulator-max-microvolt:
+ - Same meaning as in bindings/regulator/regulator.yaml, but must match
+ regulator-min-microvolt.
+ - startup-delay-us:
+ - Same meaning as in bindings/regulator/fixed-regulator.yaml.
Optional properties:
- Any optional property defined in bindings/regulator/regulator.txt
diff --git a/arch/arm/boot/dts/twl4030.dtsi b/arch/arm/boot/dts/twl4030.dtsi
index 93e07c18781b..dbe328ef208e 100644
--- a/arch/arm/boot/dts/twl4030.dtsi
+++ b/arch/arm/boot/dts/twl4030.dtsi
@@ -112,6 +112,20 @@ vsim: regulator-vsim {
regulator-max-microvolt = <3000000>;
};
+ regen: regulator-regen {
+ compatible = "ti,twl4030-regen";
+ /*
+ * Since REGEN is technically just a signal that actuates an
+ * external regulator, we do not know what what voltage it will
+ * eventually have, or what it's on/off timing should be.
+ * Therefore, disable it here; boards that use it can override
+ * the status to "okay" once they have set the
+ * regulator-{min,max}-microvolt and startup-delay-us
+ * attributes.
+ */
+ status = "disabled";
+ };
+
twl_gpio: gpio {
compatible = "ti,twl4030-gpio";
gpio-controller;
diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c
index 4a51cfea45ac..d6aea2a557b9 100644
--- a/drivers/regulator/twl-regulator.c
+++ b/drivers/regulator/twl-regulator.c
@@ -458,6 +458,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) \
@@ -518,6 +528,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.
@@ -543,6 +571,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) \
{ \
@@ -555,6 +584,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),
@@ -577,6 +607,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);
@@ -590,6 +621,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)
@@ -622,6 +654,25 @@ 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 8871cc5188a0..cbb1ea9003bd 100644
--- a/include/linux/mfd/twl.h
+++ b/include/linux/mfd/twl.h
@@ -816,6 +816,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.30.2
More information about the Letux-kernel
mailing list