1 /* $OpenBSD: expower.c,v 1.7 2017/03/10 21:26:19 kettenis 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/intr.h> 23 #include <machine/bus.h> 24 #include <machine/fdt.h> 25 26 #include <dev/ofw/openfirm.h> 27 #include <dev/ofw/ofw_misc.h> 28 #include <dev/ofw/fdt.h> 29 30 #define HREAD4(sc, reg) \ 31 (bus_space_read_4((sc)->sc_iot, (sc)->sc_ioh, (reg))) 32 #define HWRITE4(sc, reg, val) \ 33 bus_space_write_4((sc)->sc_iot, (sc)->sc_ioh, (reg), (val)) 34 #define HSET4(sc, reg, bits) \ 35 HWRITE4((sc), (reg), HREAD4((sc), (reg)) | (bits)) 36 #define HCLR4(sc, reg, bits) \ 37 HWRITE4((sc), (reg), HREAD4((sc), (reg)) & ~(bits)) 38 39 struct expower_softc { 40 struct device sc_dev; 41 bus_space_tag_t sc_iot; 42 bus_space_handle_t sc_ioh; 43 }; 44 45 int expower_match(struct device *, void *, void *); 46 void expower_attach(struct device *, struct device *, void *); 47 48 struct cfattach expower_ca = { 49 sizeof (struct expower_softc), expower_match, expower_attach 50 }; 51 52 struct cfdriver expower_cd = { 53 NULL, "expower", DV_DULL 54 }; 55 56 int 57 expower_match(struct device *parent, void *match, void *aux) 58 { 59 struct fdt_attach_args *faa = aux; 60 61 return (OF_is_compatible(faa->fa_node, "samsung,exynos5250-pmu") || 62 OF_is_compatible(faa->fa_node, "samsung,exynos5420-pmu")); 63 } 64 65 void 66 expower_attach(struct device *parent, struct device *self, void *aux) 67 { 68 struct expower_softc *sc = (struct expower_softc *)self; 69 struct fdt_attach_args *faa = aux; 70 71 sc->sc_iot = faa->fa_iot; 72 73 if (bus_space_map(sc->sc_iot, faa->fa_reg[0].addr, 74 faa->fa_reg[0].size, 0, &sc->sc_ioh)) 75 panic("%s: bus_space_map failed!", __func__); 76 77 printf("\n"); 78 79 regmap_register(faa->fa_node, sc->sc_iot, sc->sc_ioh, 80 faa->fa_reg[0].size); 81 } 82