Module Name: src
Committed By: jmcneill
Date: Wed Jan 2 18:38:43 UTC 2019
Modified Files:
src/sys/dev/fdt: fdt_regulator.c fdtvar.h
Log Message:
Add a function to report if a regulator can support the requested voltage range
To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/fdt/fdt_regulator.c
cvs rdiff -u -r1.43 -r1.44 src/sys/dev/fdt/fdtvar.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/fdt/fdt_regulator.c
diff -u src/sys/dev/fdt/fdt_regulator.c:1.6 src/sys/dev/fdt/fdt_regulator.c:1.7
--- src/sys/dev/fdt/fdt_regulator.c:1.6 Sat Jun 30 20:34:43 2018
+++ src/sys/dev/fdt/fdt_regulator.c Wed Jan 2 18:38:43 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_regulator.c,v 1.6 2018/06/30 20:34:43 jmcneill Exp $ */
+/* $NetBSD: fdt_regulator.c,v 1.7 2019/01/02 18:38:43 jmcneill Exp $ */
/*-
* Copyright (c) 2015 Jared D. McNeill <[email protected]>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fdt_regulator.c,v 1.6 2018/06/30 20:34:43 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_regulator.c,v 1.7 2019/01/02 18:38:43 jmcneill Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@@ -130,6 +130,9 @@ fdtbus_regulator_disable(struct fdtbus_r
{
struct fdtbus_regulator_controller *rc = reg->reg_rc;
+ if (of_hasprop(rc->rc_phandle, "regulator-always-on"))
+ return EIO;
+
return rc->rc_funcs->enable(rc->rc_dev, false);
}
@@ -155,3 +158,25 @@ fdtbus_regulator_get_voltage(struct fdtb
return rc->rc_funcs->get_voltage(rc->rc_dev, puvol);
}
+
+int
+fdtbus_regulator_supports_voltage(struct fdtbus_regulator *reg, u_int min_uvol,
+ u_int max_uvol)
+{
+ struct fdtbus_regulator_controller *rc = reg->reg_rc;
+ u_int uvol;
+
+ if (rc->rc_funcs->set_voltage == NULL)
+ return EINVAL;
+
+ if (of_getprop_uint32(rc->rc_phandle, "regulator-min-microvolt", &uvol) == 0) {
+ if (uvol < min_uvol)
+ return ERANGE;
+ }
+ if (of_getprop_uint32(rc->rc_phandle, "regulator-max-microvolt", &uvol) == 0) {
+ if (uvol > max_uvol)
+ return ERANGE;
+ }
+
+ return 0;
+}
Index: src/sys/dev/fdt/fdtvar.h
diff -u src/sys/dev/fdt/fdtvar.h:1.43 src/sys/dev/fdt/fdtvar.h:1.44
--- src/sys/dev/fdt/fdtvar.h:1.43 Wed Jan 2 14:54:54 2019
+++ src/sys/dev/fdt/fdtvar.h Wed Jan 2 18:38:43 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtvar.h,v 1.43 2019/01/02 14:54:54 jmcneill Exp $ */
+/* $NetBSD: fdtvar.h,v 1.44 2019/01/02 18:38:43 jmcneill Exp $ */
/*-
* Copyright (c) 2015 Jared D. McNeill <[email protected]>
@@ -300,6 +300,8 @@ int fdtbus_regulator_set_voltage(struct
u_int, u_int);
int fdtbus_regulator_get_voltage(struct fdtbus_regulator *,
u_int *);
+int fdtbus_regulator_supports_voltage(struct fdtbus_regulator *,
+ u_int, u_int);
struct syscon * fdtbus_syscon_acquire(int, const char *);
struct syscon * fdtbus_syscon_lookup(int);