Add support for enabling registered regulators. Make sure that we leave
authorkettenis <kettenis@openbsd.org>
Mon, 18 Dec 2017 09:13:47 +0000 (09:13 +0000)
committerkettenis <kettenis@openbsd.org>
Mon, 18 Dec 2017 09:13:47 +0000 (09:13 +0000)
regulators with a "regulator-always-on" property alone.

ok patrick@

sys/dev/ofw/ofw_regulator.c
sys/dev/ofw/ofw_regulator.h

index efd720a..d941887 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ofw_regulator.c,v 1.3 2017/12/16 21:12:03 kettenis Exp $      */
+/*     $OpenBSD: ofw_regulator.c,v 1.4 2017/12/18 09:13:47 kettenis Exp $      */
 /*
  * Copyright (c) 2016 Mark Kettenis
  *
@@ -50,21 +50,13 @@ regulator_register(struct regulator_device *rd)
 }
 
 int
-regulator_set(uint32_t phandle, int enable)
+regulator_fixed_set(int node, int enable)
 {
        uint32_t *gpio;
        uint32_t startup_delay;
        int active;
-       int node;
        int len;
 
-       node = OF_getnodebyphandle(phandle);
-       if (node == 0)
-               return -1;
-
-       if (!OF_is_compatible(node, "regulator-fixed"))
-               return -1;
-
        pinctrl_byname(node, "default");
 
        if (OF_getproplen(node, "enable-active-high") == 0)
@@ -93,6 +85,34 @@ regulator_set(uint32_t phandle, int enable)
        return 0;
 }
 
+int
+regulator_set(uint32_t phandle, int enable)
+{
+       struct regulator_device *rd;
+       int node;
+
+       node = OF_getnodebyphandle(phandle);
+       if (node == 0)
+               return ENODEV;
+
+       /* Don't mess around with regulators that are always on. */
+       if (OF_getproplen(node, "regulator-always-on") == 0)
+               return 0;
+
+       LIST_FOREACH(rd, &regulator_devices, rd_list) {
+               if (rd->rd_phandle == phandle)
+                       break;
+       }
+
+       if (rd && rd->rd_enable)
+               return rd->rd_enable(rd->rd_cookie, enable);
+
+       if (OF_is_compatible(node, "regulator-fixed"))
+               return regulator_fixed_set(node, enable);
+
+       return ENODEV;
+}
+
 int
 regulator_enable(uint32_t phandle)
 {
index 006ecfa..80bb0a4 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ofw_regulator.h,v 1.4 2017/12/16 21:12:03 kettenis Exp $      */
+/*     $OpenBSD: ofw_regulator.h,v 1.5 2017/12/18 09:13:47 kettenis Exp $      */
 /*
  * Copyright (c) 2016 Mark Kettenis
  *
@@ -23,6 +23,7 @@ struct regulator_device {
        void    *rd_cookie;
        uint32_t (*rd_get_voltage)(void *);
        int     (*rd_set_voltage)(void *, uint32_t);
+       int     (*rd_enable)(void *, int);
 
        uint32_t rd_min, rd_max;