Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/i2c Add powerdown support and hook it in to FDT



details:   https://anonhg.NetBSD.org/src/rev/ec633ae16f92
branches:  trunk
changeset: 826349:ec633ae16f92
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Tue Aug 29 10:10:54 2017 +0000

description:
Add powerdown support and hook it in to FDT

diffstat:

 sys/dev/i2c/axp20x.c    |  49 +++++++++++++++++++++++++++++++++++++++++++++++--
 sys/dev/i2c/axp20xvar.h |   3 ++-
 2 files changed, 49 insertions(+), 3 deletions(-)

diffs (111 lines):

diff -r 83d6b07443de -r ec633ae16f92 sys/dev/i2c/axp20x.c
--- a/sys/dev/i2c/axp20x.c      Tue Aug 29 09:55:25 2017 +0000
+++ b/sys/dev/i2c/axp20x.c      Tue Aug 29 10:10:54 2017 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -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 @@
 
 #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 @@
 #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 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 @@
                        );
                }
        }
+
+#ifdef FDT
+       axp20x_fdt_attach(sc);
+#endif
 }
 
 static void
@@ -616,3 +631,33 @@
                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, &reg, 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 */
diff -r 83d6b07443de -r ec633ae16f92 sys/dev/i2c/axp20xvar.h
--- a/sys/dev/i2c/axp20xvar.h   Tue Aug 29 09:55:25 2017 +0000
+++ b/sys/dev/i2c/axp20xvar.h   Tue Aug 29 10:10:54 2017 +0000
@@ -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_ */



Home | Main Index | Thread Index | Old Index