From 46b99dcbf2a6d50337addecbcf72e949bf5a0c99 Mon Sep 17 00:00:00 2001 From: kettenis Date: Mon, 27 Aug 2018 14:12:59 +0000 Subject: [PATCH] Add hirest(4), a driver to support reset signal controller blocks on HiSilicon SoCs. --- sys/dev/fdt/files.fdt | 6 ++- sys/dev/fdt/hireset.c | 93 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 sys/dev/fdt/hireset.c 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 + * + * 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 +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + +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)); +} -- 2.20.1