Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/fdt Add a function to report if a regulator can supp...



details:   https://anonhg.NetBSD.org/src/rev/4310254c2b7b
branches:  trunk
changeset: 447168:4310254c2b7b
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Wed Jan 02 18:38:43 2019 +0000

description:
Add a function to report if a regulator can support the requested voltage range

diffstat:

 sys/dev/fdt/fdt_regulator.c |  29 +++++++++++++++++++++++++++--
 sys/dev/fdt/fdtvar.h        |   4 +++-
 2 files changed, 30 insertions(+), 3 deletions(-)

diffs (72 lines):

diff -r 52ab0b8d06f9 -r 4310254c2b7b sys/dev/fdt/fdt_regulator.c
--- a/sys/dev/fdt/fdt_regulator.c       Wed Jan 02 18:38:03 2019 +0000
+++ b/sys/dev/fdt/fdt_regulator.c       Wed Jan 02 18:38:43 2019 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -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 @@
 {
        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 @@
 
        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;
+}
diff -r 52ab0b8d06f9 -r 4310254c2b7b sys/dev/fdt/fdtvar.h
--- a/sys/dev/fdt/fdtvar.h      Wed Jan 02 18:38:03 2019 +0000
+++ b/sys/dev/fdt/fdtvar.h      Wed Jan 02 18:38:43 2019 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -300,6 +300,8 @@
                    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);
 



Home | Main Index | Thread Index | Old Index