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