diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2018-08-27 14:13:00 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2018-08-27 14:13:00 +0000 |
commit | f15f7cfc720afc12db0a45aaceddbf50dc3dc44d (patch) | |
tree | a71d08ee7faa486cd3302d9abd135698b5a0f4ee | |
parent | c42c23cdf7d5be9a83e271e960f0819805636a53 (diff) |
Add hirest(4), a driver to support reset signal controller blocks on
HiSilicon SoCs.
-rw-r--r-- | sys/dev/fdt/files.fdt | 6 | ||||
-rw-r--r-- | sys/dev/fdt/hireset.c | 93 |
2 files changed, 98 insertions, 1 deletions
diff --git a/sys/dev/fdt/files.fdt b/sys/dev/fdt/files.fdt index 66d67870b46..d2efbb9c507 100644 --- a/sys/dev/fdt/files.fdt +++ b/sys/dev/fdt/files.fdt @@ -1,4 +1,4 @@ -# $OpenBSD: files.fdt,v 1.71 2018/08/27 13:56:11 kettenis Exp $ +# $OpenBSD: files.fdt,v 1.72 2018/08/27 14:12:59 kettenis Exp $ # # Config file and device description for machine-independent FDT code. # Included by ports that need it. @@ -123,6 +123,10 @@ device hidwusb: fdt attach hidwusb at fdt file dev/fdt/hidwusb.c hidwusb +device hireset +attach hireset at fdt +file dev/fdt/hireset.c hireset + device rkclock attach rkclock at fdt file dev/fdt/rkclock.c rkclock diff --git a/sys/dev/fdt/hireset.c b/sys/dev/fdt/hireset.c new file mode 100644 index 00000000000..1be7086415c --- /dev/null +++ b/sys/dev/fdt/hireset.c @@ -0,0 +1,93 @@ +/* $OpenBSD: hireset.c,v 1.1 2018/08/27 14:12:59 kettenis Exp $ */ +/* + * Copyright (c) 2018 Mark Kettenis <kettenis@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/device.h> + +#include <machine/intr.h> +#include <machine/bus.h> +#include <machine/fdt.h> + +#include <dev/ofw/openfirm.h> +#include <dev/ofw/ofw_clock.h> +#include <dev/ofw/ofw_misc.h> +#include <dev/ofw/fdt.h> + +struct hireset_softc { + struct device sc_dev; + uint32_t sc_rst_syscon; + + struct reset_device sc_rd; +}; + +int hireset_match(struct device *, void *, void *); +void hireset_attach(struct device *, struct device *, void *); + +struct cfattach hireset_ca = { + sizeof (struct hireset_softc), hireset_match, hireset_attach +}; + +struct cfdriver hireset_cd = { + NULL, "hireset", DV_DULL +}; + +void hireset_reset(void *, uint32_t *, int); + +int +hireset_match(struct device *parent, void *match, void *aux) +{ + struct fdt_attach_args *faa = aux; + + return OF_is_compatible(faa->fa_node, "hisilicon,hi3660-reset"); +} + +void +hireset_attach(struct device *parent, struct device *self, void *aux) +{ + struct hireset_softc *sc = (struct hireset_softc *)self; + struct fdt_attach_args *faa = aux; + + sc->sc_rst_syscon = OF_getpropint(faa->fa_node, "hisi,rst-syscon", 0); + + printf("\n"); + + sc->sc_rd.rd_node = faa->fa_node; + sc->sc_rd.rd_cookie = sc; + sc->sc_rd.rd_reset = hireset_reset; + reset_register(&sc->sc_rd); +} + +void +hireset_reset(void *cookie, uint32_t *cells, int on) +{ + struct hireset_softc *sc = cookie; + struct regmap *rm; + uint32_t offset = cells[0]; + uint32_t bit = cells[1]; + + rm = regmap_byphandle(sc->sc_rst_syscon); + if (rm == NULL) { + printf("%s: can't find regmap\n", sc->sc_dev.dv_xname); + return; + } + + if (on) + regmap_write_4(rm, offset + 0, (1 << bit)); + else + regmap_write_4(rm, offset + 4, (1 << bit)); +} |