summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2018-08-02 09:45:18 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2018-08-02 09:45:18 +0000
commitaf1b4288a7a739d74fb210dfc4c453720b30ed96 (patch)
treecc04b33e0b8b01e16784e9b58a8a2acc40fc6ddd /sys/dev
parent036a606a2bd7de6e4830def2f29db5b983008bd5 (diff)
Add delay when increasing the voltage of a regulator that has a
"regulator-ramp-delay" property to guerantee that the target voltage has been reached when regulator_set_voltage(9) returns. ok patrick@
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/ofw/ofw_regulator.c18
-rw-r--r--sys/dev/ofw/ofw_regulator.h3
2 files changed, 17 insertions, 4 deletions
diff --git a/sys/dev/ofw/ofw_regulator.c b/sys/dev/ofw/ofw_regulator.c
index d941887a23f..4c2c7152721 100644
--- a/sys/dev/ofw/ofw_regulator.c
+++ b/sys/dev/ofw/ofw_regulator.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ofw_regulator.c,v 1.4 2017/12/18 09:13:47 kettenis Exp $ */
+/* $OpenBSD: ofw_regulator.c,v 1.5 2018/08/02 09:45:17 kettenis Exp $ */
/*
* Copyright (c) 2016 Mark Kettenis
*
@@ -34,6 +34,9 @@ regulator_register(struct regulator_device *rd)
rd->rd_max = OF_getpropint(rd->rd_node, "regulator-max-microvolt", ~0);
KASSERT(rd->rd_min <= rd->rd_max);
+ rd->rd_ramp_delay =
+ OF_getpropint(rd->rd_node, "regulator-ramp-delay", 0);
+
if (rd->rd_get_voltage && rd->rd_set_voltage) {
uint32_t voltage = rd->rd_get_voltage(rd->rd_cookie);
if (voltage < rd->rd_min)
@@ -153,6 +156,8 @@ int
regulator_set_voltage(uint32_t phandle, uint32_t voltage)
{
struct regulator_device *rd;
+ uint32_t old, delta;
+ int error;
LIST_FOREACH(rd, &regulator_devices, rd_list) {
if (rd->rd_phandle == phandle)
@@ -163,8 +168,15 @@ regulator_set_voltage(uint32_t phandle, uint32_t voltage)
if (rd && (voltage < rd->rd_min || voltage > rd->rd_max))
return EINVAL;
- if (rd && rd->rd_set_voltage)
- return rd->rd_set_voltage(rd->rd_cookie, voltage);
+ if (rd && rd->rd_set_voltage) {
+ old = rd->rd_get_voltage(rd->rd_cookie);
+ error = rd->rd_set_voltage(rd->rd_cookie, voltage);
+ if (voltage > old && rd->rd_ramp_delay > 0) {
+ delta = voltage - old;
+ delay(howmany(delta, rd->rd_ramp_delay));
+ }
+ return error;
+ }
return ENODEV;
}
diff --git a/sys/dev/ofw/ofw_regulator.h b/sys/dev/ofw/ofw_regulator.h
index 80bb0a45df4..337cc895f72 100644
--- a/sys/dev/ofw/ofw_regulator.h
+++ b/sys/dev/ofw/ofw_regulator.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ofw_regulator.h,v 1.5 2017/12/18 09:13:47 kettenis Exp $ */
+/* $OpenBSD: ofw_regulator.h,v 1.6 2018/08/02 09:45:17 kettenis Exp $ */
/*
* Copyright (c) 2016 Mark Kettenis
*
@@ -26,6 +26,7 @@ struct regulator_device {
int (*rd_enable)(void *, int);
uint32_t rd_min, rd_max;
+ uint32_t rd_ramp_delay;
LIST_ENTRY(regulator_device) rd_list;
uint32_t rd_phandle;