Module Name: src Committed By: jmcneill Date: Sun May 28 15:55:11 UTC 2017
Modified Files: src/sys/arch/evbarm/tegra: tegra_machdep.c src/sys/dev/fdt: fdtvar.h files.fdt src/sys/dev/i2c: as3722.c Added Files: src/sys/dev/fdt: fdt_power.c Log Message: Add facility for fdt devices to register reset and poweroff handlers. Use this to remove as3722-specific code in tegra_machdep.c To generate a diff of this commit: cvs rdiff -u -r1.44 -r1.45 src/sys/arch/evbarm/tegra/tegra_machdep.c cvs rdiff -u -r0 -r1.1 src/sys/dev/fdt/fdt_power.c cvs rdiff -u -r1.17 -r1.18 src/sys/dev/fdt/fdtvar.h cvs rdiff -u -r1.13 -r1.14 src/sys/dev/fdt/files.fdt cvs rdiff -u -r1.11 -r1.12 src/sys/dev/i2c/as3722.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/arch/evbarm/tegra/tegra_machdep.c diff -u src/sys/arch/evbarm/tegra/tegra_machdep.c:1.44 src/sys/arch/evbarm/tegra/tegra_machdep.c:1.45 --- src/sys/arch/evbarm/tegra/tegra_machdep.c:1.44 Sun May 28 00:40:21 2017 +++ src/sys/arch/evbarm/tegra/tegra_machdep.c Sun May 28 15:55:11 2017 @@ -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 <jmcne...@invisible.ca> @@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: tegra_machde #include "ukbd.h" #include "genfb.h" #include "ether.h" -#include "as3722pmic.h" #include <sys/param.h> #include <sys/systm.h> @@ -89,10 +88,6 @@ __KERNEL_RCSID(0, "$NetBSD: tegra_machde #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 @@ tegra_device_register(device_t self, voi 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(); } Index: src/sys/dev/fdt/fdtvar.h diff -u src/sys/dev/fdt/fdtvar.h:1.17 src/sys/dev/fdt/fdtvar.h:1.18 --- src/sys/dev/fdt/fdtvar.h:1.17 Fri May 26 18:56:27 2017 +++ src/sys/dev/fdt/fdtvar.h Sun May 28 15:55:11 2017 @@ -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 <jmcne...@invisible.ca> @@ -164,6 +164,13 @@ struct fdtbus_dma_controller_func { 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 @@ int fdtbus_register_reset_controller(de 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_reset_deassert(struct fdtbus 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); Index: src/sys/dev/fdt/files.fdt diff -u src/sys/dev/fdt/files.fdt:1.13 src/sys/dev/fdt/files.fdt:1.14 --- src/sys/dev/fdt/files.fdt:1.13 Sun May 28 00:38:40 2017 +++ src/sys/dev/fdt/files.fdt Sun May 28 15:55:11 2017 @@ -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_dma.c fdtbus 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 Index: src/sys/dev/i2c/as3722.c diff -u src/sys/dev/i2c/as3722.c:1.11 src/sys/dev/i2c/as3722.c:1.12 --- src/sys/dev/i2c/as3722.c:1.11 Sat Apr 29 20:43:48 2017 +++ src/sys/dev/i2c/as3722.c Sun May 28 15:55:11 2017 @@ -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 <jmcne...@invisible.ca> @@ -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 @@ static struct fdtbus_regulator_controlle .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_attach(device_t parent, device_t 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 @@ as3722reg_get_voltage(device_t dev, u_in 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 Added files: Index: src/sys/dev/fdt/fdt_power.c diff -u /dev/null src/sys/dev/fdt/fdt_power.c:1.1 --- /dev/null Sun May 28 15:55:11 2017 +++ src/sys/dev/fdt/fdt_power.c Sun May 28 15:55:11 2017 @@ -0,0 +1,86 @@ +/* $NetBSD: fdt_power.c,v 1.1 2017/05/28 15:55:11 jmcneill Exp $ */ + +/*- + * Copyright (c) 2017 Jared McNeill <jmcne...@invisible.ca> + * 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); + } +}