Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/fdt fdt: regulator: pre-allocate regulator handle



details:   https://anonhg.NetBSD.org/src/rev/f0e8a6e6dff2
branches:  trunk
changeset: 1022825:f0e8a6e6dff2
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun Aug 08 15:23:42 2021 +0000

description:
fdt: regulator: pre-allocate regulator handle

Workaround for PR# port-evbarm/54664

diffstat:

 sys/dev/fdt/fdt_regulator.c |  30 +++++++++++++++---------------
 1 files changed, 15 insertions(+), 15 deletions(-)

diffs (119 lines):

diff -r f368d67f9a7f -r f0e8a6e6dff2 sys/dev/fdt/fdt_regulator.c
--- a/sys/dev/fdt/fdt_regulator.c       Sun Aug 08 15:06:44 2021 +0000
+++ b/sys/dev/fdt/fdt_regulator.c       Sun Aug 08 15:23:42 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_regulator.c,v 1.8 2019/05/27 23:18:33 jmcneill Exp $ */
+/* $NetBSD: fdt_regulator.c,v 1.9 2021/08/08 15:23:42 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.8 2019/05/27 23:18:33 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_regulator.c,v 1.9 2021/08/08 15:23:42 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -37,6 +37,9 @@
 #include <libfdt.h>
 #include <dev/fdt/fdtvar.h>
 
+#define        REGULATOR_TO_RC(_reg)   \
+       container_of((_reg), struct fdtbus_regulator_controller, rc_reg)
+
 struct fdtbus_regulator_controller {
        device_t rc_dev;
        int rc_phandle;
@@ -44,6 +47,8 @@
 
        u_int rc_enable_ramp_delay;
 
+       struct fdtbus_regulator rc_reg; /* handle returned by acquire() */
+
        LIST_ENTRY(fdtbus_regulator_controller) rc_next;
 };
 
@@ -60,6 +65,7 @@
        rc->rc_dev = dev;
        rc->rc_phandle = phandle;
        rc->rc_funcs = funcs;
+       rc->rc_reg.reg_rc = rc;
 
        of_getprop_uint32(phandle, "regulator-enable-ramp-delay", &rc->rc_enable_ramp_delay);
 
@@ -85,7 +91,6 @@
 fdtbus_regulator_acquire(int phandle, const char *prop)
 {
        struct fdtbus_regulator_controller *rc;
-       struct fdtbus_regulator *reg;
        int regulator_phandle;
        int error;
 
@@ -105,26 +110,21 @@
                return NULL;
        }
 
-       reg = kmem_alloc(sizeof(*reg), KM_SLEEP);
-       reg->reg_rc = rc;
-
-       return reg;
+       return &rc->rc_reg;
 }
 
 void
 fdtbus_regulator_release(struct fdtbus_regulator *reg)
 {
-       struct fdtbus_regulator_controller *rc = reg->reg_rc;
+       struct fdtbus_regulator_controller *rc = REGULATOR_TO_RC(reg);
 
        rc->rc_funcs->release(rc->rc_dev);
-
-       kmem_free(reg, sizeof(*reg));
 }
 
 int
 fdtbus_regulator_enable(struct fdtbus_regulator *reg)
 {
-       struct fdtbus_regulator_controller *rc = reg->reg_rc;
+       struct fdtbus_regulator_controller *rc = REGULATOR_TO_RC(reg);
        int error;
 
        error = rc->rc_funcs->enable(rc->rc_dev, true);
@@ -140,7 +140,7 @@
 int
 fdtbus_regulator_disable(struct fdtbus_regulator *reg)
 {
-       struct fdtbus_regulator_controller *rc = reg->reg_rc;
+       struct fdtbus_regulator_controller *rc = REGULATOR_TO_RC(reg);
 
        if (of_hasprop(rc->rc_phandle, "regulator-always-on"))
                return EIO;
@@ -152,7 +152,7 @@
 fdtbus_regulator_set_voltage(struct fdtbus_regulator *reg, u_int min_uvol,
     u_int max_uvol)
 {
-       struct fdtbus_regulator_controller *rc = reg->reg_rc;
+       struct fdtbus_regulator_controller *rc = REGULATOR_TO_RC(reg);
 
        if (rc->rc_funcs->set_voltage == NULL)
                return EINVAL;
@@ -163,7 +163,7 @@
 int
 fdtbus_regulator_get_voltage(struct fdtbus_regulator *reg, u_int *puvol)
 {
-       struct fdtbus_regulator_controller *rc = reg->reg_rc;
+       struct fdtbus_regulator_controller *rc = REGULATOR_TO_RC(reg);
 
        if (rc->rc_funcs->get_voltage == NULL)
                return EINVAL;
@@ -175,7 +175,7 @@
 fdtbus_regulator_supports_voltage(struct fdtbus_regulator *reg, u_int min_uvol,
     u_int max_uvol)
 {
-       struct fdtbus_regulator_controller *rc = reg->reg_rc;
+       struct fdtbus_regulator_controller *rc = REGULATOR_TO_RC(reg);
        u_int uvol;
 
        if (rc->rc_funcs->set_voltage == NULL)



Home | Main Index | Thread Index | Old Index