Module Name: src
Committed By: jmcneill
Date: Tue Aug 29 10:10:54 UTC 2017
Modified Files:
src/sys/dev/i2c: axp20x.c axp20xvar.h
Log Message:
Add powerdown support and hook it in to FDT
To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/i2c/axp20x.c
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/i2c/axp20xvar.h
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/axp20x.c
diff -u src/sys/dev/i2c/axp20x.c:1.6 src/sys/dev/i2c/axp20x.c:1.7
--- src/sys/dev/i2c/axp20x.c:1.6 Tue Aug 29 09:55:03 2017
+++ src/sys/dev/i2c/axp20x.c Tue Aug 29 10:10:54 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: axp20x.c,v 1.6 2017/08/29 09:55:03 jmcneill Exp $ */
+/* $NetBSD: axp20x.c,v 1.7 2017/08/29 10:10:54 jmcneill Exp $ */
/*-
* Copyright (c) 2014-2017 Jared McNeill <[email protected]>
@@ -29,7 +29,7 @@
#include "opt_fdt.h"
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: axp20x.c,v 1.6 2017/08/29 09:55:03 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: axp20x.c,v 1.7 2017/08/29 10:10:54 jmcneill Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -43,6 +43,10 @@ __KERNEL_RCSID(0, "$NetBSD: axp20x.c,v 1
#include <dev/sysmon/sysmonvar.h>
+#ifdef FDT
+#include <dev/fdt/fdtvar.h>
+#endif
+
#define AXP_INPUT_STATUS 0x00
#define AXP_INPUT_STATUS_AC_PRESENT __BIT(7)
#define AXP_INPUT_STATUS_AC_OK __BIT(6)
@@ -101,6 +105,9 @@ static int ldo4_mvV[] = {
#define AXP_LDO3_VOLT_MASK __BITS(0,6)
#define AXP_LDO3_VOLT_SHIFT 0
+#define AXP_SHUTDOWN 0x32
+#define AXP_SHUTDOWN_CTRL __BIT(7)
+
#define AXP_BKUP_CTRL 0x35
#define AXP_BKUP_CTRL_ENABLE __BIT(7)
#define AXP_BKUP_CTRL_VOLT_MASK __BITS(5,6)
@@ -198,6 +205,10 @@ static void axp20x_sensors_refresh(struc
static int axp20x_read(struct axp20x_softc *, uint8_t, uint8_t *, size_t, int);
static int axp20x_write(struct axp20x_softc *, uint8_t, uint8_t *, size_t, int);
+#ifdef FDT
+static void axp20x_fdt_attach(struct axp20x_softc *);
+#endif
+
CFATTACH_DECL_NEW(axp20x, sizeof(struct axp20x_softc),
axp20x_match, axp20x_attach, NULL, NULL);
@@ -400,6 +411,10 @@ axp20x_attach(device_t parent, device_t
);
}
}
+
+#ifdef FDT
+ axp20x_fdt_attach(sc);
+#endif
}
static void
@@ -616,3 +631,33 @@ axp20x_set_dcdc(device_t dev, int dcdc,
return EINVAL;
}
}
+
+void
+axp20x_poweroff(device_t dev)
+{
+ struct axp20x_softc * const sc = device_private(dev);
+ uint8_t reg = AXP_SHUTDOWN_CTRL;
+
+ if (axp20x_write(sc, AXP_SHUTDOWN, ®, 1, I2C_F_POLL) != 0)
+ device_printf(dev, "WARNING: poweroff failed\n");
+}
+
+#ifdef FDT
+static void
+axp20x_fdt_poweroff(device_t dev)
+{
+ delay(1000000);
+ axp20x_poweroff(dev);
+}
+
+static struct fdtbus_power_controller_func axp20x_fdt_power_funcs = {
+ .poweroff = axp20x_fdt_poweroff,
+};
+
+static void
+axp20x_fdt_attach(struct axp20x_softc *sc)
+{
+ fdtbus_register_power_controller(sc->sc_dev, sc->sc_phandle,
+ &axp20x_fdt_power_funcs);
+}
+#endif /* FDT */
Index: src/sys/dev/i2c/axp20xvar.h
diff -u src/sys/dev/i2c/axp20xvar.h:1.1 src/sys/dev/i2c/axp20xvar.h:1.2
--- src/sys/dev/i2c/axp20xvar.h:1.1 Thu Oct 15 13:41:11 2015
+++ src/sys/dev/i2c/axp20xvar.h Tue Aug 29 10:10:54 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: axp20xvar.h,v 1.1 2015/10/15 13:41:11 bouyer Exp $ */
+/* $NetBSD: axp20xvar.h,v 1.2 2017/08/29 10:10:54 jmcneill Exp $ */
/*
* Copyright (c) 1998, 2001 Manuel Bouyer.
@@ -31,5 +31,6 @@
#define AXP20X_DCDC3 3
int axp20x_set_dcdc(device_t, int, int, bool);
+void axp20x_poweroff(device_t);
#endif /* _DEV_I2C_AXP20XVAR_H_ */