jcs's openbsd hax
openbsd

Add bcmstbreset(4), a driver for the reset controller found on the rpi5.

ok mglocker@

kettenis 8dd4d68c fd599d8f

+120 -3
+2 -1
sys/arch/arm64/conf/GENERIC
··· 1 - # $OpenBSD: GENERIC,v 1.299 2025/08/15 13:35:49 kettenis Exp $ 1 + # $OpenBSD: GENERIC,v 1.300 2025/08/20 12:01:02 kettenis Exp $ 2 2 # 3 3 # GENERIC machine description file 4 4 # ··· 243 243 sdmmc* at bcmsdhost? 244 244 bcmstbgpio* at fdt? early 1 245 245 bcmstbpinctrl* at fdt? early 1 246 + bcmstbreset* at fdt? early 1 246 247 bcmtemp* at fdt? 247 248 bcmtmon* at fdt? early 1 248 249 bse* at fdt?
+2 -1
sys/arch/arm64/conf/RAMDISK
··· 1 - # $OpenBSD: RAMDISK,v 1.226 2025/08/15 13:35:49 kettenis Exp $ 1 + # $OpenBSD: RAMDISK,v 1.227 2025/08/20 12:01:02 kettenis Exp $ 2 2 3 3 machine arm64 4 4 maxusers 4 ··· 179 179 sdmmc* at bcmsdhost? 180 180 bcmstbgpio* at fdt? early 1 181 181 bcmstbpinctrl* at fdt? early 1 182 + bcmstbreset* at fdt? early 1 182 183 bse* at fdt? 183 184 bse* at acpi? 184 185 dwctwo* at fdt?
+111
sys/dev/fdt/bcmstbreset.c
··· 1 + /* $OpenBSD: bcmstbreset.c,v 1.1 2025/08/20 12:01:02 kettenis Exp $ */ 2 + /* 3 + * Copyright (c) 2025 Mark Kettenis <kettenis@openbsd.org> 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 + 22 + #include <machine/intr.h> 23 + #include <machine/bus.h> 24 + #include <machine/fdt.h> 25 + 26 + #include <dev/ofw/openfirm.h> 27 + #include <dev/ofw/ofw_clock.h> 28 + #include <dev/ofw/fdt.h> 29 + 30 + /* Registers. */ 31 + #define SW_INIT_SET(_bank) (0x00 + (_bank) * 24) 32 + #define SW_INIT_CLR(_bank) (0x04 + (_bank) * 24) 33 + 34 + #define HREAD4(sc, reg) \ 35 + (bus_space_read_4((sc)->sc_iot, (sc)->sc_ioh, (reg))) 36 + #define HWRITE4(sc, reg, val) \ 37 + bus_space_write_4((sc)->sc_iot, (sc)->sc_ioh, (reg), (val)) 38 + 39 + struct bcmstbreset_softc { 40 + struct device sc_dev; 41 + bus_space_tag_t sc_iot; 42 + bus_space_handle_t sc_ioh; 43 + u_int sc_nbanks; 44 + 45 + struct reset_device sc_rd; 46 + }; 47 + 48 + int bcmstbreset_match(struct device *, void *, void *); 49 + void bcmstbreset_attach(struct device *, struct device *, void *); 50 + 51 + const struct cfattach bcmstbreset_ca = { 52 + sizeof (struct bcmstbreset_softc), 53 + bcmstbreset_match, bcmstbreset_attach 54 + }; 55 + 56 + struct cfdriver bcmstbreset_cd = { 57 + NULL, "bcmstbreset", DV_DULL 58 + }; 59 + 60 + void bcmstbreset_reset(void *, uint32_t *, int); 61 + 62 + int 63 + bcmstbreset_match(struct device *parent, void *match, void *aux) 64 + { 65 + struct fdt_attach_args *faa = aux; 66 + 67 + return OF_is_compatible(faa->fa_node, "brcm,brcmstb-reset"); 68 + } 69 + 70 + void 71 + bcmstbreset_attach(struct device *parent, struct device *self, void *aux) 72 + { 73 + struct bcmstbreset_softc *sc = (struct bcmstbreset_softc *)self; 74 + struct fdt_attach_args *faa = aux; 75 + 76 + if (faa->fa_nreg < 1) { 77 + printf(": no registers\n"); 78 + return; 79 + } 80 + 81 + sc->sc_iot = faa->fa_iot; 82 + if (bus_space_map(sc->sc_iot, faa->fa_reg[0].addr, 83 + faa->fa_reg[0].size, 0, &sc->sc_ioh)) { 84 + printf(": can't map registers\n"); 85 + return; 86 + } 87 + sc->sc_nbanks = faa->fa_reg[0].size / 24; 88 + 89 + printf("\n"); 90 + 91 + sc->sc_rd.rd_node = faa->fa_node; 92 + sc->sc_rd.rd_cookie = sc; 93 + sc->sc_rd.rd_reset = bcmstbreset_reset; 94 + reset_register(&sc->sc_rd); 95 + } 96 + 97 + void 98 + bcmstbreset_reset(void *cookie, uint32_t *cells, int assert) 99 + { 100 + struct bcmstbreset_softc *sc = cookie; 101 + uint32_t bank = cells[0] / 32;; 102 + uint32_t bit = cells[0] % 32; 103 + 104 + if (bank >= sc->sc_nbanks) 105 + return; 106 + 107 + if (assert) 108 + HWRITE4(sc, SW_INIT_SET(bank), 1U << bit); 109 + else 110 + HWRITE4(sc, SW_INIT_CLR(bank), 1U << bit); 111 + }
+5 -1
sys/dev/fdt/files.fdt
··· 1 - # $OpenBSD: files.fdt,v 1.211 2025/08/15 13:35:49 kettenis Exp $ 1 + # $OpenBSD: files.fdt,v 1.212 2025/08/20 12:01:02 kettenis Exp $ 2 2 # 3 3 # Config file and device description for machine-independent FDT code. 4 4 # Included by ports that need it. ··· 151 151 device bcmstbpinctrl 152 152 attach bcmstbpinctrl at fdt 153 153 file dev/fdt/bcmstbpinctrl.c bcmstbpinctrl 154 + 155 + device bcmstbreset 156 + attach bcmstbreset at fdt 157 + file dev/fdt/bcmstbreset.c bcmstbreset 154 158 155 159 device bcmtemp 156 160 attach bcmtemp at fdt