Module Name:    src
Committed By:   jmcneill
Date:           Fri Jan  3 01:17:29 UTC 2020

Modified Files:
        src/sys/dev/i2c: rkpmic.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/i2c/rkpmic.c

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/i2c/rkpmic.c
diff -u src/sys/dev/i2c/rkpmic.c:1.7 src/sys/dev/i2c/rkpmic.c:1.8
--- src/sys/dev/i2c/rkpmic.c:1.7	Thu Jan  2 17:09:59 2020
+++ src/sys/dev/i2c/rkpmic.c	Fri Jan  3 01:17:29 2020
@@ -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 <[email protected]>
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: rkpmic.c,v 1
 #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 @@ struct rkpmic_config {
 	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 @@ static const struct rkpmic_config rk808_
 	.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 @@ static const struct clk_funcs rkpmic_clk
 	.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 @@ rkpmic_attach(device_t parent, device_t 
 	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;

Reply via email to