diff options
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/ofw/ofw_regulator.c | 18 | ||||
-rw-r--r-- | sys/dev/ofw/ofw_regulator.h | 3 |
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, ®ulator_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; |