Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/i2c If the rockchip,system-power-controller property...



details:   https://anonhg.NetBSD.org/src/rev/3da234ff969d
branches:  trunk
changeset: 1006158:3da234ff969d
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Fri Jan 03 01:17:29 2020 +0000

description:
If the rockchip,system-power-controller property is present, try to power off with the PMIC

diffstat:

 sys/dev/i2c/rkpmic.c |  36 ++++++++++++++++++++++++++++++++++--
 1 files changed, 34 insertions(+), 2 deletions(-)

diffs (85 lines):

diff -r c65f5c1c13a9 -r 3da234ff969d sys/dev/i2c/rkpmic.c
--- a/sys/dev/i2c/rkpmic.c      Fri Jan 03 01:00:08 2020 +0000
+++ b/sys/dev/i2c/rkpmic.c      Fri Jan 03 01:17:29 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rkpmic.c,v 1.7 2020/01/02 17:09:59 thorpej Exp $ */
+/* $NetBSD: rkpmic.c,v 1.8 2020/01/03 01:17:29 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rkpmic.c,v 1.7 2020/01/02 17:09:59 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rkpmic.c,v 1.8 2020/01/03 01:17:29 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -72,6 +72,9 @@
 #define        CLK32OUT_REG            0x20
 #define        CLK32OUT_CLKOUT2_EN     __BIT(0)
 
+#define        DEVCTRL_REG             0x4b
+#define        DEVCTRL_DEV_OFF_RST     __BIT(3)
+
 struct rkpmic_ctrl {
        const char *    name;
        uint8_t         enable_reg;
@@ -88,6 +91,9 @@
        const char *    name;
        const struct rkpmic_ctrl *ctrl;
        u_int           nctrl;
+
+       u_int           poweroff_reg;
+       u_int           poweroff_mask;
 };
 
 static const struct rkpmic_ctrl rk805_ctrls[] = {
@@ -190,6 +196,8 @@
        .name = "RK808",
        .ctrl = rk808_ctrls,
        .nctrl = __arraycount(rk808_ctrls),
+       .poweroff_reg = DEVCTRL_REG,
+       .poweroff_mask = DEVCTRL_DEV_OFF_RST,
 };
 
 struct rkpmic_softc;
@@ -417,6 +425,25 @@
        .disable = rkpmic_clk_disable,
 };
 
+static void
+rkpmic_power_poweroff(device_t dev)
+{
+       struct rkpmic_softc * const sc = device_private(dev);
+       uint8_t val;
+
+       delay(1000000);
+
+       I2C_LOCK(sc);
+       val = I2C_READ(sc, sc->sc_conf->poweroff_reg);
+       val |= sc->sc_conf->poweroff_mask;
+       I2C_WRITE(sc, sc->sc_conf->poweroff_reg, val);
+       I2C_UNLOCK(sc);
+}
+
+static struct fdtbus_power_controller_func rkpmic_power_funcs = {
+       .poweroff = rkpmic_power_poweroff,
+};
+
 static int
 rkpmic_match(device_t parent, cfdata_t match, void *aux)
 {
@@ -482,6 +509,11 @@
        fdtbus_register_clock_controller(self, sc->sc_phandle,
            &rkpmic_clk_fdt_funcs);
 
+       if (of_hasprop(sc->sc_phandle, "rockchip,system-power-controller") &&
+           sc->sc_conf->poweroff_mask != 0)
+               fdtbus_register_power_controller(self, sc->sc_phandle,
+                   &rkpmic_power_funcs);
+
        regulators = of_find_firstchild_byname(sc->sc_phandle, "regulators");
        if (regulators < 0)
                return;



Home | Main Index | Thread Index | Old Index