From eabd9194d38ed3d260182983bde0682078e53854 Mon Sep 17 00:00:00 2001 From: kettenis Date: Sun, 30 Apr 2017 14:00:06 +0000 Subject: [PATCH] Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip RK3399 available to other drivers through the regmap interface. --- sys/arch/arm64/conf/GENERIC | 5 ++- sys/arch/arm64/conf/RAMDISK | 5 ++- sys/arch/arm64/conf/files.arm64 | 3 +- sys/dev/fdt/files.fdt | 6 ++- sys/dev/fdt/rkgrf.c | 79 +++++++++++++++++++++++++++++++++ 5 files changed, 94 insertions(+), 4 deletions(-) create mode 100644 sys/dev/fdt/rkgrf.c diff --git a/sys/arch/arm64/conf/GENERIC b/sys/arch/arm64/conf/GENERIC index 1bd4c2bbcf5..6d2ace33cc9 100644 --- a/sys/arch/arm64/conf/GENERIC +++ b/sys/arch/arm64/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.24 2017/04/29 17:24:41 kettenis Exp $ +# $OpenBSD: GENERIC,v 1.25 2017/04/30 14:00:06 kettenis Exp $ # # GENERIC machine description file # @@ -78,6 +78,9 @@ bcmdog* at fdt? dwctwo* at fdt? usb* at dwctwo? +# Rockchip SoCs +rkgrf* at fdt? early 1 + # Sunxi SoCs sxipio* at fdt? early 1 # GPIO pins for leds & PHYs gpio* at sxipio? diff --git a/sys/arch/arm64/conf/RAMDISK b/sys/arch/arm64/conf/RAMDISK index 46abe2ff5db..465970b7ec7 100644 --- a/sys/arch/arm64/conf/RAMDISK +++ b/sys/arch/arm64/conf/RAMDISK @@ -1,4 +1,4 @@ -# $OpenBSD: RAMDISK,v 1.21 2017/04/29 17:24:41 kettenis Exp $ +# $OpenBSD: RAMDISK,v 1.22 2017/04/30 14:00:06 kettenis Exp $ # # GENERIC machine description file # @@ -85,6 +85,9 @@ bcmdog* at fdt? dwctwo* at fdt? usb* at dwctwo? +# Rockchip SoCs +rkgrf* at fdt? early 1 + # Sunxi SoCs sxipio* at fdt? early 1 # GPIO pins for leds & PHYs gpio* at sxipio? diff --git a/sys/arch/arm64/conf/files.arm64 b/sys/arch/arm64/conf/files.arm64 index 95a107a8a43..8dae608f001 100644 --- a/sys/arch/arm64/conf/files.arm64 +++ b/sys/arch/arm64/conf/files.arm64 @@ -1,4 +1,4 @@ -# $OpenBSD: files.arm64,v 1.13 2017/04/29 17:24:41 kettenis Exp $ +# $OpenBSD: files.arm64,v 1.14 2017/04/30 14:00:06 kettenis Exp $ maxpartitions 16 maxusers 2 8 64 @@ -61,6 +61,7 @@ file arch/arm64/dev/simplebus.c simplebus file dev/ofw/fdt.c file dev/ofw/ofw_clock.c file dev/ofw/ofw_gpio.c +file dev/ofw/ofw_misc.c file dev/ofw/ofw_pinctrl.c file dev/ofw/ofw_regulator.c diff --git a/sys/dev/fdt/files.fdt b/sys/dev/fdt/files.fdt index c5ffce01553..b1f8db12441 100644 --- a/sys/dev/fdt/files.fdt +++ b/sys/dev/fdt/files.fdt @@ -1,4 +1,4 @@ -# $OpenBSD: files.fdt,v 1.10 2017/04/29 20:49:09 kettenis Exp $ +# $OpenBSD: files.fdt,v 1.11 2017/04/30 14:00:06 kettenis Exp $ # # Config file and device description for machine-independent FDT code. # Included by ports that need it. @@ -57,3 +57,7 @@ file dev/fdt/xhci_fdt.c xhci_fdt device syscon attach syscon at fdt file dev/fdt/syscon.c syscon + +device rkgrf +attach rkgrf at fdt +file dev/fdt/rkgrf.c rkgrf diff --git a/sys/dev/fdt/rkgrf.c b/sys/dev/fdt/rkgrf.c new file mode 100644 index 00000000000..184b666fc2f --- /dev/null +++ b/sys/dev/fdt/rkgrf.c @@ -0,0 +1,79 @@ +/* $OpenBSD: rkgrf.c,v 1.1 2017/04/30 14:00:06 kettenis Exp $ */ +/* + * Copyright (c) 2017 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +struct rkgrf_softc { + struct device sc_dev; + bus_space_tag_t sc_iot; + bus_space_handle_t sc_ioh; +}; + +int rkgrf_match(struct device *, void *, void *); +void rkgrf_attach(struct device *, struct device *, void *); + +struct cfattach rkgrf_ca = { + sizeof (struct rkgrf_softc), rkgrf_match, rkgrf_attach +}; + +struct cfdriver rkgrf_cd = { + NULL, "rkgrf", DV_DULL +}; + +int +rkgrf_match(struct device *parent, void *match, void *aux) +{ + struct fdt_attach_args *faa = aux; + + return (OF_is_compatible(faa->fa_node, "rockchip,rk3399-grf") || + OF_is_compatible(faa->fa_node, "rockchip,rk3399-pmugrf")); +} + +void +rkgrf_attach(struct device *parent, struct device *self, void *aux) +{ + struct rkgrf_softc *sc = (struct rkgrf_softc *)self; + struct fdt_attach_args *faa = aux; + + if (faa->fa_nreg < 1) { + printf(": no registers\n"); + return; + } + + sc->sc_iot = faa->fa_iot; + + if (bus_space_map(sc->sc_iot, faa->fa_reg[0].addr, + faa->fa_reg[0].size, 0, &sc->sc_ioh)) { + printf(": can't map registers\n"); + return; + } + + printf("\n"); + + regmap_register(faa->fa_node, sc->sc_iot, sc->sc_ioh, + faa->fa_reg[0].size); +} -- 2.20.1