xref: /freebsd/sys/arm/allwinner/aw_syscon.c (revision 62e8ccc3)
1a9f41defSKyle Evans /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3a5beb55bSKyle Evans  *
4a9f41defSKyle Evans  * Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org>
5a9f41defSKyle Evans  *
6a9f41defSKyle Evans  * Redistribution and use in source and binary forms, with or without
7a9f41defSKyle Evans  * modification, are permitted provided that the following conditions
8a9f41defSKyle Evans  * are met:
9a9f41defSKyle Evans  * 1. Redistributions of source code must retain the above copyright
10a9f41defSKyle Evans  *    notice, this list of conditions and the following disclaimer.
11a9f41defSKyle Evans  * 2. Redistributions in binary form must reproduce the above copyright
12a9f41defSKyle Evans  *    notice, this list of conditions and the following disclaimer in the
13a9f41defSKyle Evans  *    documentation and/or other materials provided with the distribution.
14a9f41defSKyle Evans  *
15a9f41defSKyle Evans  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16a9f41defSKyle Evans  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17a9f41defSKyle Evans  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18a9f41defSKyle Evans  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19a9f41defSKyle Evans  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20a9f41defSKyle Evans  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21a9f41defSKyle Evans  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22a9f41defSKyle Evans  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23a9f41defSKyle Evans  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24a9f41defSKyle Evans  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25a9f41defSKyle Evans  * SUCH DAMAGE.
26a9f41defSKyle Evans  */
27a9f41defSKyle Evans 
28a9f41defSKyle Evans /*
29a9f41defSKyle Evans  * Allwinner syscon driver
30a9f41defSKyle Evans  */
31a9f41defSKyle Evans 
32a9f41defSKyle Evans #include <sys/param.h>
33a9f41defSKyle Evans #include <sys/bus.h>
34a9f41defSKyle Evans #include <sys/kernel.h>
35a9f41defSKyle Evans #include <sys/module.h>
36a9f41defSKyle Evans #include <sys/mutex.h>
37a9f41defSKyle Evans #include <sys/rman.h>
38a9f41defSKyle Evans #include <machine/bus.h>
39a9f41defSKyle Evans 
40a9f41defSKyle Evans #include <dev/ofw/openfirm.h>
41a9f41defSKyle Evans #include <dev/ofw/ofw_bus.h>
42a9f41defSKyle Evans #include <dev/ofw/ofw_bus_subr.h>
43a9f41defSKyle Evans 
4462e8ccc3SEmmanuel Vadot #include <dev/syscon/syscon.h>
4562e8ccc3SEmmanuel Vadot #include <dev/syscon/syscon_generic.h>
46a9f41defSKyle Evans 
47a9f41defSKyle Evans static struct ofw_compat_data compat_data[] = {
48a9f41defSKyle Evans 	{"allwinner,sun50i-a64-system-controller", 1},
4965aee3a8SEmmanuel Vadot 	{"allwinner,sun50i-a64-system-control", 1},
50a9f41defSKyle Evans 	{"allwinner,sun8i-a83t-system-controller", 1},
51a9f41defSKyle Evans 	{"allwinner,sun8i-h3-system-controller", 1},
5254612fd5SEmmanuel Vadot 	{"allwinner,sun8i-h3-system-control", 1},
53bfb92761SEmmanuel Vadot 	{"allwinner,sun50i-h5-system-control", 1},
54a9f41defSKyle Evans 	{NULL,             0}
55a9f41defSKyle Evans };
56a9f41defSKyle Evans 
57a9f41defSKyle Evans static int
aw_syscon_probe(device_t dev)58a9f41defSKyle Evans aw_syscon_probe(device_t dev)
59a9f41defSKyle Evans {
60a9f41defSKyle Evans 
61a9f41defSKyle Evans 	if (!ofw_bus_status_okay(dev))
62a9f41defSKyle Evans 		return (ENXIO);
63a9f41defSKyle Evans 	if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)
64a9f41defSKyle Evans 		return (ENXIO);
65a9f41defSKyle Evans 
66a9f41defSKyle Evans 	device_set_desc(dev, "Allwinner syscon");
67a9f41defSKyle Evans 	return (BUS_PROBE_DEFAULT);
68a9f41defSKyle Evans }
69a9f41defSKyle Evans 
70a9f41defSKyle Evans static device_method_t aw_syscon_methods[] = {
71a9f41defSKyle Evans 	DEVMETHOD(device_probe, aw_syscon_probe),
72a9f41defSKyle Evans 
73a9f41defSKyle Evans 	DEVMETHOD_END
74a9f41defSKyle Evans };
75a9f41defSKyle Evans 
76a9f41defSKyle Evans DEFINE_CLASS_1(aw_syscon, aw_syscon_driver, aw_syscon_methods,
77a9f41defSKyle Evans     sizeof(struct syscon_generic_softc), syscon_generic_driver);
78a9f41defSKyle Evans 
79a9f41defSKyle Evans /* aw_syscon needs to attach prior to if_awg */
807e1e2ba1SJohn Baldwin EARLY_DRIVER_MODULE(aw_syscon, simplebus, aw_syscon_driver, 0, 0,
817e1e2ba1SJohn Baldwin     BUS_PASS_SCHEDULER + BUS_PASS_ORDER_LAST);
82a9f41defSKyle Evans MODULE_VERSION(aw_syscon, 1);
83