1 /* $OpenBSD: mvsysctrl.c,v 1.2 2021/10/24 17:52:27 mpi Exp $ */ 2 /* 3 * Copyright (c) 2016 Patrick Wildt <patrick@blueri.se> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 #include <sys/param.h> 19 #include <sys/systm.h> 20 #include <sys/device.h> 21 #include <machine/bus.h> 22 #include <machine/fdt.h> 23 #include <armv7/armv7/armv7_machdep.h> 24 25 #include <dev/ofw/openfirm.h> 26 #include <dev/ofw/fdt.h> 27 28 #define RSTOUTN 0x60 29 #define RSTOUTN_GLOBAL_SOFT_RSTOUT_EN 1 30 #define SYSSOFTRST 0x64 31 #define SYSSOFTRST_GLOBAL_SOFT_RST 1 32 33 #define HREAD4(sc, reg) \ 34 (bus_space_read_4((sc)->sc_iot, (sc)->sc_ioh, (reg))) 35 #define HWRITE4(sc, reg, val) \ 36 bus_space_write_4((sc)->sc_iot, (sc)->sc_ioh, (reg), (val)) 37 #define HSET4(sc, reg, bits) \ 38 HWRITE4((sc), (reg), HREAD4((sc), (reg)) | (bits)) 39 #define HCLR4(sc, reg, bits) \ 40 HWRITE4((sc), (reg), HREAD4((sc), (reg)) & ~(bits)) 41 42 struct mvsysctrl_softc { 43 struct device sc_dev; 44 bus_space_tag_t sc_iot; 45 bus_space_handle_t sc_ioh; 46 }; 47 48 int mvsysctrl_match(struct device *, void *, void *); 49 void mvsysctrl_attach(struct device *, struct device *, void *); 50 51 void mvsysctrl_reset(void); 52 53 struct mvsysctrl_softc *mvsysctrl_sc; 54 55 const struct cfattach mvsysctrl_ca = { 56 sizeof (struct mvsysctrl_softc), mvsysctrl_match, mvsysctrl_attach 57 }; 58 59 struct cfdriver mvsysctrl_cd = { 60 NULL, "mvsysctrl", DV_DULL 61 }; 62 63 int 64 mvsysctrl_match(struct device *parent, void *cfdata, void *aux) 65 { 66 struct fdt_attach_args *faa = aux; 67 68 return OF_is_compatible(faa->fa_node, 69 "marvell,armada-370-xp-system-controller"); 70 } 71 72 void 73 mvsysctrl_attach(struct device *parent, struct device *self, void *args) 74 { 75 struct mvsysctrl_softc *sc = (struct mvsysctrl_softc *)self; 76 struct fdt_attach_args *faa = args; 77 78 sc->sc_iot = faa->fa_iot; 79 if (bus_space_map(sc->sc_iot, faa->fa_reg[0].addr, 80 faa->fa_reg[0].size, 0, &sc->sc_ioh)) 81 panic("%s: bus_space_map failed!", __func__); 82 83 printf("\n"); 84 85 mvsysctrl_sc = sc; 86 cpuresetfn = mvsysctrl_reset; 87 } 88 89 void 90 mvsysctrl_reset(void) 91 { 92 struct mvsysctrl_softc *sc = mvsysctrl_sc; 93 94 HWRITE4(sc, RSTOUTN, RSTOUTN_GLOBAL_SOFT_RSTOUT_EN); 95 HWRITE4(sc, SYSSOFTRST, SYSSOFTRST_GLOBAL_SOFT_RST); 96 97 for (;;) 98 continue; 99 } 100