rkgrf.c revision 1.1
1/* $OpenBSD: rkgrf.c,v 1.1 2017/04/30 14:00:06 kettenis Exp $ */ 2/* 3 * Copyright (c) 2017 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_misc.h> 28#include <dev/ofw/fdt.h> 29 30struct rkgrf_softc { 31 struct device sc_dev; 32 bus_space_tag_t sc_iot; 33 bus_space_handle_t sc_ioh; 34}; 35 36int rkgrf_match(struct device *, void *, void *); 37void rkgrf_attach(struct device *, struct device *, void *); 38 39struct cfattach rkgrf_ca = { 40 sizeof (struct rkgrf_softc), rkgrf_match, rkgrf_attach 41}; 42 43struct cfdriver rkgrf_cd = { 44 NULL, "rkgrf", DV_DULL 45}; 46 47int 48rkgrf_match(struct device *parent, void *match, void *aux) 49{ 50 struct fdt_attach_args *faa = aux; 51 52 return (OF_is_compatible(faa->fa_node, "rockchip,rk3399-grf") || 53 OF_is_compatible(faa->fa_node, "rockchip,rk3399-pmugrf")); 54} 55 56void 57rkgrf_attach(struct device *parent, struct device *self, void *aux) 58{ 59 struct rkgrf_softc *sc = (struct rkgrf_softc *)self; 60 struct fdt_attach_args *faa = aux; 61 62 if (faa->fa_nreg < 1) { 63 printf(": no registers\n"); 64 return; 65 } 66 67 sc->sc_iot = faa->fa_iot; 68 69 if (bus_space_map(sc->sc_iot, faa->fa_reg[0].addr, 70 faa->fa_reg[0].size, 0, &sc->sc_ioh)) { 71 printf(": can't map registers\n"); 72 return; 73 } 74 75 printf("\n"); 76 77 regmap_register(faa->fa_node, sc->sc_iot, sc->sc_ioh, 78 faa->fa_reg[0].size); 79} 80