xref: /freebsd/sys/dev/quicc/quicc_bfe_fdt.c (revision fdafd315ad0d0f28a11b9fb4476a9ab059c62b92)
1d1d3233eSRafal Jaworowski /*-
2718cf2ccSPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
3718cf2ccSPedro F. Giffuni  *
4d1d3233eSRafal Jaworowski  * Copyright (c) 2006 Juniper Networks.
5d1d3233eSRafal Jaworowski  * All rights reserved.
6d1d3233eSRafal Jaworowski  *
7d1d3233eSRafal Jaworowski  * Redistribution and use in source and binary forms, with or without
8d1d3233eSRafal Jaworowski  * modification, are permitted provided that the following conditions
9d1d3233eSRafal Jaworowski  * are met:
10d1d3233eSRafal Jaworowski  * 1. Redistributions of source code must retain the above copyright
11d1d3233eSRafal Jaworowski  *    notice, this list of conditions and the following disclaimer.
12d1d3233eSRafal Jaworowski  * 2. Redistributions in binary form must reproduce the above copyright
13d1d3233eSRafal Jaworowski  *    notice, this list of conditions and the following disclaimer in the
14d1d3233eSRafal Jaworowski  *    documentation and/or other materials provided with the distribution.
15d1d3233eSRafal Jaworowski  * 3. The name of the author may not be used to endorse or promote products
16d1d3233eSRafal Jaworowski  *    derived from this software without specific prior written permission.
17d1d3233eSRafal Jaworowski  *
18d1d3233eSRafal Jaworowski  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19d1d3233eSRafal Jaworowski  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20d1d3233eSRafal Jaworowski  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21d1d3233eSRafal Jaworowski  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22d1d3233eSRafal Jaworowski  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23d1d3233eSRafal Jaworowski  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24d1d3233eSRafal Jaworowski  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25d1d3233eSRafal Jaworowski  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26d1d3233eSRafal Jaworowski  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27d1d3233eSRafal Jaworowski  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28d1d3233eSRafal Jaworowski  * SUCH DAMAGE.
29d1d3233eSRafal Jaworowski  */
30d1d3233eSRafal Jaworowski 
31d1d3233eSRafal Jaworowski #include <sys/param.h>
32d1d3233eSRafal Jaworowski #include <sys/systm.h>
33d1d3233eSRafal Jaworowski #include <sys/bus.h>
34d1d3233eSRafal Jaworowski #include <sys/conf.h>
35d1d3233eSRafal Jaworowski #include <sys/kernel.h>
36d1d3233eSRafal Jaworowski #include <sys/lock.h>
37d1d3233eSRafal Jaworowski #include <sys/malloc.h>
38d1d3233eSRafal Jaworowski #include <sys/module.h>
39d1d3233eSRafal Jaworowski #include <sys/rman.h>
40d1d3233eSRafal Jaworowski #include <machine/bus.h>
41d1d3233eSRafal Jaworowski 
42d1d3233eSRafal Jaworowski #include <dev/ofw/ofw_bus.h>
43d1d3233eSRafal Jaworowski #include <dev/ofw/ofw_bus_subr.h>
44d1d3233eSRafal Jaworowski #include <dev/quicc/quicc_bfe.h>
45d1d3233eSRafal Jaworowski 
46d1d3233eSRafal Jaworowski static int quicc_fdt_probe(device_t dev);
47d1d3233eSRafal Jaworowski 
48d1d3233eSRafal Jaworowski static device_method_t quicc_fdt_methods[] = {
49d1d3233eSRafal Jaworowski 	/* Device interface */
50d1d3233eSRafal Jaworowski 	DEVMETHOD(device_probe,		quicc_fdt_probe),
51d1d3233eSRafal Jaworowski 	DEVMETHOD(device_attach,	quicc_bfe_attach),
52d1d3233eSRafal Jaworowski 	DEVMETHOD(device_detach,	quicc_bfe_detach),
53d1d3233eSRafal Jaworowski 
54d1d3233eSRafal Jaworowski 	DEVMETHOD(bus_alloc_resource,	quicc_bus_alloc_resource),
55d1d3233eSRafal Jaworowski 	DEVMETHOD(bus_release_resource,	quicc_bus_release_resource),
56d1d3233eSRafal Jaworowski 	DEVMETHOD(bus_get_resource,	quicc_bus_get_resource),
57d1d3233eSRafal Jaworowski 	DEVMETHOD(bus_read_ivar,	quicc_bus_read_ivar),
58d1d3233eSRafal Jaworowski 	DEVMETHOD(bus_setup_intr,	quicc_bus_setup_intr),
59d1d3233eSRafal Jaworowski 	DEVMETHOD(bus_teardown_intr,	quicc_bus_teardown_intr),
60d1d3233eSRafal Jaworowski 
614b7ec270SMarius Strobl 	DEVMETHOD_END
62d1d3233eSRafal Jaworowski };
63d1d3233eSRafal Jaworowski 
64d1d3233eSRafal Jaworowski static driver_t quicc_fdt_driver = {
65d1d3233eSRafal Jaworowski 	quicc_driver_name,
66d1d3233eSRafal Jaworowski 	quicc_fdt_methods,
67d1d3233eSRafal Jaworowski 	sizeof(struct quicc_softc),
68d1d3233eSRafal Jaworowski };
69d1d3233eSRafal Jaworowski 
70d1d3233eSRafal Jaworowski static int
quicc_fdt_probe(device_t dev)71d1d3233eSRafal Jaworowski quicc_fdt_probe(device_t dev)
72d1d3233eSRafal Jaworowski {
73d1d3233eSRafal Jaworowski 	phandle_t par;
74d1d3233eSRafal Jaworowski 	pcell_t clock;
75d1d3233eSRafal Jaworowski 
76add35ed5SIan Lepore 	if (!ofw_bus_status_okay(dev))
77add35ed5SIan Lepore 		return (ENXIO);
78add35ed5SIan Lepore 
79d1d3233eSRafal Jaworowski 	if (!ofw_bus_is_compatible(dev, "fsl,cpm2"))
80d1d3233eSRafal Jaworowski 		return (ENXIO);
81d1d3233eSRafal Jaworowski 
82d1d3233eSRafal Jaworowski 	par = OF_parent(ofw_bus_get_node(dev));
83d1d3233eSRafal Jaworowski 	if (OF_getprop(par, "bus-frequency", &clock, sizeof(clock)) <= 0)
84d1d3233eSRafal Jaworowski 		clock = 0;
85d1d3233eSRafal Jaworowski 
86d1d3233eSRafal Jaworowski 	return (quicc_bfe_probe(dev, (uintptr_t)clock));
87d1d3233eSRafal Jaworowski }
88d1d3233eSRafal Jaworowski 
89*28140529SJohn Baldwin DRIVER_MODULE(quicc, simplebus, quicc_fdt_driver, 0, 0);
90