Index: share/man/man4/Makefile =================================================================== --- share/man/man4/Makefile +++ share/man/man4/Makefile @@ -74,6 +74,7 @@ ${_aw_mmc.4} \ ${_aw_rtc.4} \ ${_aw_sid.4} \ + ${_aw_syscon.4} \ axe.4 \ axge.4 \ bce.4 \ @@ -765,6 +766,7 @@ _aw_mmc.4= aw_mmc.4 _aw_rtc.4= aw_rtc.4 _aw_sid.4= aw_sid.4 +_aw_syscon.4= aw_syscon.4 .endif .if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386" Index: share/man/man4/aw_syscon.4 =================================================================== --- /dev/null +++ share/man/man4/aw_syscon.4 @@ -0,0 +1,60 @@ +.\"- +.\" Copyright (c) 2018 Kyle Evans +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd January 7, 2018 +.Dt AW_SYSCON 4 +.Os +.Sh NAME +.Nm aw_syscon +.Nd driver for the system controller in Allwinner SoC +.Sh DESCRIPTION +The +.Nm +device driver provides support for the Allwinner system controller. +This controller provides registers for tying together related functionality in a +common space. +.Nm +is required for ethernet functionality on supported devices. +.Sh HARDWARE +The +.Nm +driver supports the system controller with one of the following compatible +strings: +.Pp +.Bl -bullet -compact +.It +allwinner,sun50i-a64-system-controller +.It +allwinner,sun8i-a83t-system-controller +.It +allwinner,sun8i-h3-system-controller +.El +.Sh AUTHORS +The +.Nm +device driver was written by +.An Kyle Evans Aq Mt kevans@FreeBSD.org . Index: sys/arm/allwinner/aw_syscon.c =================================================================== --- /dev/null +++ sys/arm/allwinner/aw_syscon.c @@ -0,0 +1,101 @@ +/*- + * Copyright (c) 2018 Kyle Evans + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * Allwinner syscon driver + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +static struct ofw_compat_data compat_data[] = { + {"allwinner,sun50i-a64-system-controller", 1}, + {"allwinner,sun8i-a83t-system-controller", 1}, + {"allwinner,sun8i-h3-system-controller", 1}, + {NULL, 0} +}; + +static int +aw_syscon_probe(device_t dev) +{ + + if (!ofw_bus_status_okay(dev)) + return (ENXIO); + if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0) + return (ENXIO); + + device_set_desc(dev, "Allwinner syscon"); + return (BUS_PROBE_DEFAULT); +} + +static int +aw_syscon_attach(device_t dev) +{ + + return (syscon_generic_attach(dev)); +} + +static int +aw_syscon_detach(device_t dev) +{ + + return (syscon_generic_detach(dev)); +} + +static device_method_t aw_syscon_methods[] = { + DEVMETHOD(device_probe, aw_syscon_probe), + DEVMETHOD(device_attach, aw_syscon_attach), + DEVMETHOD(device_detach, aw_syscon_detach), + + DEVMETHOD_END +}; + +static driver_t aw_syscon_driver = { + "aw_syscon", + aw_syscon_methods, + sizeof(struct syscon_generic_softc), +}; + +static devclass_t aw_syscon_devclass; +/* aw_syscon needs to attach prior to if_awg */ +EARLY_DRIVER_MODULE(aw_syscon, simplebus, aw_syscon_driver, aw_syscon_devclass, + 0, 0, BUS_PASS_DEFAULT - 1000); +MODULE_VERSION(aw_syscon, 1); Index: sys/arm/allwinner/files.allwinner =================================================================== --- sys/arm/allwinner/files.allwinner +++ sys/arm/allwinner/files.allwinner @@ -15,6 +15,7 @@ arm/allwinner/aw_nmi.c optional intrng arm/allwinner/aw_rsb.c optional rsb | p2wi arm/allwinner/aw_rtc.c standard +arm/allwinner/aw_syscon.c optional ext_resources syscon arm/allwinner/aw_ts.c standard arm/allwinner/aw_usbphy.c optional ehci | ohci arm/allwinner/aw_wdog.c standard Index: sys/dev/extres/syscon/syscon_generic.h =================================================================== --- /dev/null +++ sys/dev/extres/syscon/syscon_generic.h @@ -0,0 +1,41 @@ +/*- + * Copyright 2018 Kyle Evans + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef DEV_SYSCON_GENERIC_H +#define DEV_SYSCON_GENERIC_H + +struct syscon_generic_softc { + device_t dev; + struct syscon *syscon; + struct resource *mem_res; + struct mtx mtx; +}; + +int syscon_generic_detach(device_t dev); +int syscon_generic_attach(device_t dev); + +#endif /* DEV_SYSCON_GENERIC_H */ Index: sys/dev/extres/syscon/syscon_generic.c =================================================================== --- sys/dev/extres/syscon/syscon_generic.c +++ sys/dev/extres/syscon/syscon_generic.c @@ -48,6 +48,7 @@ #include "syscon_if.h" #include "syscon.h" +#include "syscon_generic.h" MALLOC_DECLARE(M_SYSCON); @@ -60,13 +61,6 @@ /* * Generic syscon driver (FDT) */ -struct syscon_generic_softc { - device_t dev; - struct syscon *syscon; - struct resource *mem_res; - struct mtx mtx; -}; - static struct ofw_compat_data compat_data[] = { {"syscon", 1}, {NULL, 0} @@ -148,7 +142,7 @@ return (BUS_PROBE_GENERIC); } -static int +int syscon_generic_attach(device_t dev) { struct syscon_generic_softc *sc; @@ -175,7 +169,7 @@ return (0); } -static int +int syscon_generic_detach(device_t dev) { struct syscon_generic_softc *sc; @@ -206,11 +200,7 @@ DEFINE_CLASS_0(syscon_generic, syscon_generic_driver, syscon_generic_dmethods, sizeof(struct syscon_generic_softc)); static devclass_t syscon_generic_devclass; -/* - * syscon_generic needs to attach before other devices that may require it, such - * as if_awg, but later than others to give way for more specialized syscon - * implementations. - */ + EARLY_DRIVER_MODULE(syscon_generic, simplebus, syscon_generic_driver, - syscon_generic_devclass, 0, 0, BUS_PASS_DEFAULT - 1000); + syscon_generic_devclass, 0, 0, BUS_PASS_DEFAULT); MODULE_VERSION(syscon_generic, 1);