Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Add facility for fdt devices to register reset and power...
details: https://anonhg.NetBSD.org/src/rev/3cbbc42dc5ac
branches: trunk
changeset: 824222:3cbbc42dc5ac
user: jmcneill <jmcneill%NetBSD.org@localhost>
date: Sun May 28 15:55:11 2017 +0000
description:
Add facility for fdt devices to register reset and poweroff handlers.
Use this to remove as3722-specific code in tegra_machdep.c
diffstat:
sys/arch/evbarm/tegra/tegra_machdep.c | 31 +----------
sys/dev/fdt/fdt_power.c | 86 +++++++++++++++++++++++++++++++++++
sys/dev/fdt/fdtvar.h | 14 +++++-
sys/dev/fdt/files.fdt | 3 +-
sys/dev/i2c/as3722.c | 29 ++++++++++-
5 files changed, 132 insertions(+), 31 deletions(-)
diffs (283 lines):
diff -r 15a42c7d46ee -r 3cbbc42dc5ac sys/arch/evbarm/tegra/tegra_machdep.c
--- a/sys/arch/evbarm/tegra/tegra_machdep.c Sun May 28 14:53:13 2017 +0000
+++ b/sys/arch/evbarm/tegra/tegra_machdep.c Sun May 28 15:55:11 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tegra_machdep.c,v 1.44 2017/05/28 00:40:21 jmcneill Exp $ */
+/* $NetBSD: tegra_machdep.c,v 1.45 2017/05/28 15:55:11 jmcneill Exp $ */
/*-
* Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tegra_machdep.c,v 1.44 2017/05/28 00:40:21 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tegra_machdep.c,v 1.45 2017/05/28 15:55:11 jmcneill Exp $");
#include "opt_tegra.h"
#include "opt_machdep.h"
@@ -40,7 +40,6 @@
#include "ukbd.h"
#include "genfb.h"
#include "ether.h"
-#include "as3722pmic.h"
#include <sys/param.h>
#include <sys/systm.h>
@@ -89,10 +88,6 @@
#include <dev/usb/ukbdvar.h>
#include <net/if_ether.h>
-#if NAS3722PMIC > 0
-#include <dev/i2c/as3722.h>
-#endif
-
#ifndef TEGRA_MAX_BOOT_STRING
#define TEGRA_MAX_BOOT_STRING 1024
#endif
@@ -503,30 +498,12 @@
static void
tegra_reset(void)
{
-#if NAS3722PMIC > 0
- device_t pmic = device_find_by_driver_unit("as3722pmic", 0);
- if (pmic != NULL) {
- delay(1000000);
- if (as3722_reboot(pmic) != 0) {
- printf("WARNING: AS3722 reset failed\n");
- return;
- }
- }
-#endif
+ fdtbus_power_reset();
tegra_pmc_reset();
}
static void
tegra_powerdown(void)
{
-#if NAS3722PMIC > 0
- device_t pmic = device_find_by_driver_unit("as3722pmic", 0);
- if (pmic != NULL) {
- delay(1000000);
- if (as3722_poweroff(pmic) != 0) {
- printf("WARNING: AS3722 poweroff failed\n");
- return;
- }
- }
-#endif
+ fdtbus_power_poweroff();
}
diff -r 15a42c7d46ee -r 3cbbc42dc5ac sys/dev/fdt/fdt_power.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/fdt/fdt_power.c Sun May 28 15:55:11 2017 +0000
@@ -0,0 +1,86 @@
+/* $NetBSD: fdt_power.c,v 1.1 2017/05/28 15:55:11 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2017 Jared McNeill <jmcneill%invisible.ca@localhost>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: fdt_power.c,v 1.1 2017/05/28 15:55:11 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/kmem.h>
+
+#include <libfdt.h>
+#include <dev/fdt/fdtvar.h>
+
+struct fdtbus_power_controller {
+ device_t power_dev;
+ int power_phandle;
+ const struct fdtbus_power_controller_func *power_funcs;
+
+ struct fdtbus_power_controller *power_next;
+};
+
+static struct fdtbus_power_controller *fdtbus_power = NULL;
+
+int
+fdtbus_register_power_controller(device_t dev, int phandle,
+ const struct fdtbus_power_controller_func *funcs)
+{
+ struct fdtbus_power_controller *power;
+
+ power = kmem_alloc(sizeof(*power), KM_SLEEP);
+ power->power_dev = dev;
+ power->power_phandle = phandle;
+ power->power_funcs = funcs;
+
+ power->power_next = fdtbus_power;
+ fdtbus_power = power;
+
+ return 0;
+}
+
+void
+fdtbus_power_reset(void)
+{
+ struct fdtbus_power_controller *power;
+
+ for (power = fdtbus_power; power; power = power->power_next) {
+ if (power->power_funcs->reset)
+ power->power_funcs->reset(power->power_dev);
+ }
+}
+
+void
+fdtbus_power_poweroff(void)
+{
+ struct fdtbus_power_controller *power;
+
+ for (power = fdtbus_power; power; power = power->power_next) {
+ if (power->power_funcs->poweroff)
+ power->power_funcs->poweroff(power->power_dev);
+ }
+}
diff -r 15a42c7d46ee -r 3cbbc42dc5ac sys/dev/fdt/fdtvar.h
--- a/sys/dev/fdt/fdtvar.h Sun May 28 14:53:13 2017 +0000
+++ b/sys/dev/fdt/fdtvar.h Sun May 28 15:55:11 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtvar.h,v 1.17 2017/05/26 18:56:27 jmcneill Exp $ */
+/* $NetBSD: fdtvar.h,v 1.18 2017/05/28 15:55:11 jmcneill Exp $ */
/*-
* Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -164,6 +164,13 @@
void (*halt)(device_t, void *);
};
+struct fdtbus_power_controller;
+
+struct fdtbus_power_controller_func {
+ void (*reset)(device_t);
+ void (*poweroff)(device_t);
+};
+
int fdtbus_register_interrupt_controller(device_t, int,
const struct fdtbus_interrupt_controller_func *);
int fdtbus_register_i2c_controller(device_t, int,
@@ -180,6 +187,8 @@
const struct fdtbus_reset_controller_func *);
int fdtbus_register_dma_controller(device_t, int,
const struct fdtbus_dma_controller_func *);
+int fdtbus_register_power_controller(device_t, int,
+ const struct fdtbus_power_controller_func *);
int fdtbus_get_reg(int, u_int, bus_addr_t *, bus_size_t *);
int fdtbus_get_reg64(int, u_int, uint64_t *, uint64_t *);
@@ -226,6 +235,9 @@
int fdtbus_todr_attach(device_t, int, todr_chip_handle_t);
+void fdtbus_power_reset(void);
+void fdtbus_power_poweroff(void);
+
bool fdtbus_set_data(const void *);
const void * fdtbus_get_data(void);
int fdtbus_phandle2offset(int);
diff -r 15a42c7d46ee -r 3cbbc42dc5ac sys/dev/fdt/files.fdt
--- a/sys/dev/fdt/files.fdt Sun May 28 14:53:13 2017 +0000
+++ b/sys/dev/fdt/files.fdt Sun May 28 15:55:11 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.fdt,v 1.13 2017/05/28 00:38:40 jmcneill Exp $
+# $NetBSD: files.fdt,v 1.14 2017/05/28 15:55:11 jmcneill Exp $
include "external/bsd/libfdt/conf/files.libfdt"
@@ -29,6 +29,7 @@
file dev/fdt/fdt_gpio.c fdtbus
file dev/fdt/fdt_i2c.c fdtbus
file dev/fdt/fdt_intr.c fdtbus
+file dev/fdt/fdt_power.c fdtbus
file dev/fdt/fdt_regulator.c fdtbus
file dev/fdt/fdt_reset.c fdtbus
file dev/fdt/fdt_rtc.c fdtbus
diff -r 15a42c7d46ee -r 3cbbc42dc5ac sys/dev/i2c/as3722.c
--- a/sys/dev/i2c/as3722.c Sun May 28 14:53:13 2017 +0000
+++ b/sys/dev/i2c/as3722.c Sun May 28 15:55:11 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: as3722.c,v 1.11 2017/04/29 20:43:48 jakllsch Exp $ */
+/* $NetBSD: as3722.c,v 1.12 2017/05/28 15:55:11 jmcneill Exp $ */
/*-
* Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -29,7 +29,7 @@
#include "opt_fdt.h"
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: as3722.c,v 1.11 2017/04/29 20:43:48 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: as3722.c,v 1.12 2017/05/28 15:55:11 jmcneill Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -197,6 +197,14 @@
.set_voltage = as3722reg_set_voltage,
.get_voltage = as3722reg_get_voltage,
};
+
+static void as3722_power_reset(device_t);
+static void as3722_power_poweroff(device_t);
+
+static struct fdtbus_power_controller_func as3722power_funcs = {
+ .reset = as3722_power_reset,
+ .poweroff = as3722_power_poweroff,
+};
#endif
static int as3722_read(struct as3722_softc *, uint8_t, uint8_t *, int);
@@ -258,6 +266,9 @@
as3722_rtc_attach(sc);
#ifdef FDT
as3722_regulator_attach(sc);
+
+ fdtbus_register_power_controller(self, sc->sc_phandle,
+ &as3722power_funcs);
#endif
}
@@ -813,6 +824,20 @@
return regdef->get(dev, puvol);
}
+
+static void
+as3722_power_reset(device_t dev)
+{
+ delay(1000000);
+ as3722_reboot(dev);
+}
+
+static void
+as3722_power_poweroff(device_t dev)
+{
+ delay(1000000);
+ as3722_poweroff(dev);
+}
#endif
int
Home |
Main Index |
Thread Index |
Old Index