xref: /freebsd/sys/arm64/rockchip/rk_grf.c (revision 62e8ccc3a489434af379c7f47da71545bc1e14ee)
149755fc6SEmmanuel Vadot /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
349755fc6SEmmanuel Vadot  *
449755fc6SEmmanuel Vadot  * Copyright (c) 2018 Emmanuel Vadot <manu@FreeBSD.org>
549755fc6SEmmanuel Vadot  *
649755fc6SEmmanuel Vadot  * Redistribution and use in source and binary forms, with or without
749755fc6SEmmanuel Vadot  * modification, are permitted provided that the following conditions
849755fc6SEmmanuel Vadot  * are met:
949755fc6SEmmanuel Vadot  * 1. Redistributions of source code must retain the above copyright
1049755fc6SEmmanuel Vadot  *    notice, this list of conditions and the following disclaimer.
1149755fc6SEmmanuel Vadot  * 2. Redistributions in binary form must reproduce the above copyright
1249755fc6SEmmanuel Vadot  *    notice, this list of conditions and the following disclaimer in the
1349755fc6SEmmanuel Vadot  *    documentation and/or other materials provided with the distribution.
1449755fc6SEmmanuel Vadot  *
1549755fc6SEmmanuel Vadot  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1649755fc6SEmmanuel Vadot  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1749755fc6SEmmanuel Vadot  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1849755fc6SEmmanuel Vadot  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1949755fc6SEmmanuel Vadot  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2049755fc6SEmmanuel Vadot  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2149755fc6SEmmanuel Vadot  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2249755fc6SEmmanuel Vadot  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2349755fc6SEmmanuel Vadot  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2449755fc6SEmmanuel Vadot  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2549755fc6SEmmanuel Vadot  * SUCH DAMAGE.
2649755fc6SEmmanuel Vadot  */
2749755fc6SEmmanuel Vadot 
2849755fc6SEmmanuel Vadot #include <sys/param.h>
2949755fc6SEmmanuel Vadot #include <sys/bus.h>
3049755fc6SEmmanuel Vadot #include <sys/kernel.h>
3149755fc6SEmmanuel Vadot #include <sys/module.h>
3249755fc6SEmmanuel Vadot #include <sys/mutex.h>
3349755fc6SEmmanuel Vadot #include <sys/rman.h>
3449755fc6SEmmanuel Vadot #include <machine/bus.h>
3549755fc6SEmmanuel Vadot 
3649755fc6SEmmanuel Vadot #include <dev/ofw/openfirm.h>
3749755fc6SEmmanuel Vadot #include <dev/ofw/ofw_bus.h>
3849755fc6SEmmanuel Vadot #include <dev/ofw/ofw_bus_subr.h>
3949755fc6SEmmanuel Vadot 
40*62e8ccc3SEmmanuel Vadot #include <dev/syscon/syscon.h>
4140c30bf3SGanbold Tsagaankhuu #include <dev/fdt/simple_mfd.h>
4249755fc6SEmmanuel Vadot 
4349755fc6SEmmanuel Vadot static struct ofw_compat_data compat_data[] = {
44f69c06c3SMichal Meloun 	{"rockchip,rk3288-grf", 1},
4549755fc6SEmmanuel Vadot 	{"rockchip,rk3328-grf", 1},
4636ae7efeSEmmanuel Vadot 	{"rockchip,rk3399-grf", 1},
4736ae7efeSEmmanuel Vadot 	{"rockchip,rk3399-pmugrf", 1},
48ace8bb34SGanbold Tsagaankhuu 	{"rockchip,rk3568-grf", 1},
49ace8bb34SGanbold Tsagaankhuu 	{"rockchip,rk3568-pmugrf", 1},
50ace8bb34SGanbold Tsagaankhuu 	{"rockchip,rk3568-usb2phy-grf", 1},
510e3c99cbSSøren Schmidt 	{"rockchip,rk3566-pipe-grf", 1},
520e3c99cbSSøren Schmidt 	{"rockchip,rk3568-pipe-grf", 1},
530e3c99cbSSøren Schmidt 	{"rockchip,rk3568-pipe-phy-grf", 1},
540e3c99cbSSøren Schmidt 	{"rockchip,rk3568-pcie3-phy-grf", 1},
5549755fc6SEmmanuel Vadot 	{NULL,             0}
5649755fc6SEmmanuel Vadot };
5749755fc6SEmmanuel Vadot 
5849755fc6SEmmanuel Vadot static int
rk_grf_probe(device_t dev)5949755fc6SEmmanuel Vadot rk_grf_probe(device_t dev)
6049755fc6SEmmanuel Vadot {
6149755fc6SEmmanuel Vadot 
6249755fc6SEmmanuel Vadot 	if (!ofw_bus_status_okay(dev))
6349755fc6SEmmanuel Vadot 		return (ENXIO);
6449755fc6SEmmanuel Vadot 	if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)
6549755fc6SEmmanuel Vadot 		return (ENXIO);
6649755fc6SEmmanuel Vadot 
6749755fc6SEmmanuel Vadot 	device_set_desc(dev, "RockChip General Register Files");
6849755fc6SEmmanuel Vadot 	return (BUS_PROBE_DEFAULT);
6949755fc6SEmmanuel Vadot }
7049755fc6SEmmanuel Vadot 
7149755fc6SEmmanuel Vadot static device_method_t rk_grf_methods[] = {
7249755fc6SEmmanuel Vadot 	DEVMETHOD(device_probe, rk_grf_probe),
7349755fc6SEmmanuel Vadot 
7449755fc6SEmmanuel Vadot 	DEVMETHOD_END
7549755fc6SEmmanuel Vadot };
7649755fc6SEmmanuel Vadot 
7749755fc6SEmmanuel Vadot DEFINE_CLASS_1(rk_grf, rk_grf_driver, rk_grf_methods,
7840c30bf3SGanbold Tsagaankhuu     sizeof(struct simple_mfd_softc), simple_mfd_driver);
7949755fc6SEmmanuel Vadot 
80b2c1681aSJohn Baldwin EARLY_DRIVER_MODULE(rk_grf, simplebus, rk_grf_driver, 0, 0,
81b2c1681aSJohn Baldwin     BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE);
8249755fc6SEmmanuel Vadot MODULE_VERSION(rk_grf, 1);
83