1 /* $OpenBSD: expower.c,v 1.11 2023/09/22 01:10:43 jsg Exp $ */ 2 /* 3 * Copyright (c) 2012-2013 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 22 #include <machine/bus.h> 23 #include <machine/fdt.h> 24 25 #include <dev/ofw/openfirm.h> 26 #include <dev/ofw/ofw_misc.h> 27 #include <dev/ofw/fdt.h> 28 29 #include <machine/simplebusvar.h> 30 31 #define HREAD4(sc, reg) \ 32 (bus_space_read_4((sc)->sc_iot, (sc)->sc_ioh, (reg))) 33 #define HWRITE4(sc, reg, val) \ 34 bus_space_write_4((sc)->sc_iot, (sc)->sc_ioh, (reg), (val)) 35 #define HSET4(sc, reg, bits) \ 36 HWRITE4((sc), (reg), HREAD4((sc), (reg)) | (bits)) 37 #define HCLR4(sc, reg, bits) \ 38 HWRITE4((sc), (reg), HREAD4((sc), (reg)) & ~(bits)) 39 40 struct expower_softc { 41 struct simplebus_softc sc_sbus; 42 bus_space_tag_t sc_iot; 43 bus_space_handle_t sc_ioh; 44 }; 45 46 int expower_match(struct device *, void *, void *); 47 void expower_attach(struct device *, struct device *, void *); 48 49 const struct cfattach expower_ca = { 50 sizeof (struct expower_softc), expower_match, expower_attach 51 }; 52 53 struct cfdriver expower_cd = { 54 NULL, "expower", DV_DULL 55 }; 56 57 int 58 expower_match(struct device *parent, void *match, void *aux) 59 { 60 struct fdt_attach_args *faa = aux; 61 62 if (OF_is_compatible(faa->fa_node, "samsung,exynos5250-pmu") || 63 OF_is_compatible(faa->fa_node, "samsung,exynos5420-pmu")) 64 return 10; /* Must beat syscon(4). */ 65 66 return 0; 67 } 68 69 void 70 expower_attach(struct device *parent, struct device *self, void *aux) 71 { 72 struct expower_softc *sc = (struct expower_softc *)self; 73 struct fdt_attach_args *faa = aux; 74 75 if (faa->fa_nreg < 1) { 76 printf(": no registers\n"); 77 return; 78 } 79 80 sc->sc_iot = faa->fa_iot; 81 if (bus_space_map(sc->sc_iot, faa->fa_reg[0].addr, 82 faa->fa_reg[0].size, 0, &sc->sc_ioh)) { 83 printf(": can't map registers\n"); 84 return; 85 } 86 87 regmap_register(faa->fa_node, sc->sc_iot, sc->sc_ioh, 88 faa->fa_reg[0].size); 89 90 simplebus_attach(parent, &sc->sc_sbus.sc_dev, faa); 91 } 92