diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2017-11-18 13:48:51 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2017-11-18 13:48:51 +0000 |
commit | 9805698199e4303cfc09dfe18c921337e229a464 (patch) | |
tree | 81c09ce660b3163c7f76d983f27010789aca0d51 | |
parent | 78831b87c2b78c83347c801bd94ad7d7694f31f2 (diff) |
Extend regulator "framework" with functions to get/set voltages.
ok jsg@
-rw-r--r-- | sys/dev/ofw/ofw_regulator.c | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/sys/dev/ofw/ofw_regulator.c b/sys/dev/ofw/ofw_regulator.c index 3b2d352f855..a728bdbdcff 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.1 2016/08/13 10:52:21 kettenis Exp $ */ +/* $OpenBSD: ofw_regulator.c,v 1.2 2017/11/18 13:48:50 kettenis Exp $ */ /* * Copyright (c) 2016 Mark Kettenis * @@ -24,6 +24,19 @@ #include <dev/ofw/ofw_pinctrl.h> #include <dev/ofw/ofw_regulator.h> +LIST_HEAD(, regulator_device) regulator_devices = + LIST_HEAD_INITIALIZER(regulator_devices); + +void +regulator_register(struct regulator_device *rd) +{ + rd->rd_phandle = OF_getpropint(rd->rd_node, "phandle", 0); + if (rd->rd_phandle == 0) + return; + + LIST_INSERT_HEAD(®ulator_devices, rd, rd_list); +} + int regulator_set(uint32_t phandle, int enable) { @@ -79,3 +92,43 @@ regulator_disable(uint32_t phandle) { return regulator_set(phandle, 0); } + +uint32_t +regulator_get_voltage(uint32_t phandle) +{ + struct regulator_device *rd; + int node; + + LIST_FOREACH(rd, ®ulator_devices, rd_list) { + if (rd->rd_phandle == phandle) + break; + } + + if (rd && rd->rd_get_voltage) + return rd->rd_get_voltage(rd->rd_cookie); + + node = OF_getnodebyphandle(phandle); + if (node == 0) + return 0; + + if (OF_is_compatible(node, "regulator-fixed")) + return OF_getpropint(node, "regulator-min-voltage", 0); + + return 0; +} + +int +regulator_set_voltage(uint32_t phandle, uint32_t voltage) +{ + struct regulator_device *rd; + + LIST_FOREACH(rd, ®ulator_devices, rd_list) { + if (rd->rd_phandle == phandle) + break; + } + + if (rd && rd->rd_set_voltage) + return rd->rd_set_voltage(rd->rd_cookie, voltage); + + return -1; +} |