2 * Copyright (c) 2003 Jake Burkholder.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
31 #include <sys/systm.h>
33 #include <sys/kernel.h>
34 #include <sys/malloc.h>
35 #include <sys/module.h>
37 #include <dev/ofw/ofw_bus.h>
39 #include <machine/bus.h>
40 #include <machine/resource.h>
44 #include <sparc64/fhc/fhcreg.h>
45 #include <sparc64/fhc/fhcvar.h>
47 static device_probe_t fhc_central_probe;
48 static device_attach_t fhc_central_attach;
50 static device_method_t fhc_central_methods[] = {
51 /* Device interface. */
52 DEVMETHOD(device_probe, fhc_central_probe),
53 DEVMETHOD(device_attach, fhc_central_attach),
54 DEVMETHOD(device_shutdown, bus_generic_shutdown),
55 DEVMETHOD(device_suspend, bus_generic_suspend),
56 DEVMETHOD(device_resume, bus_generic_resume),
59 DEVMETHOD(bus_print_child, fhc_print_child),
60 DEVMETHOD(bus_probe_nomatch, fhc_probe_nomatch),
61 DEVMETHOD(bus_setup_intr, fhc_setup_intr),
62 DEVMETHOD(bus_teardown_intr, fhc_teardown_intr),
63 DEVMETHOD(bus_alloc_resource, fhc_alloc_resource),
64 DEVMETHOD(bus_release_resource, bus_generic_rl_release_resource),
65 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
66 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
67 DEVMETHOD(bus_get_resource_list, fhc_get_resource_list),
68 DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource),
70 /* ofw_bus interface */
71 DEVMETHOD(ofw_bus_get_compat, fhc_get_compat),
72 DEVMETHOD(ofw_bus_get_model, fhc_get_model),
73 DEVMETHOD(ofw_bus_get_name, fhc_get_name),
74 DEVMETHOD(ofw_bus_get_node, fhc_get_node),
75 DEVMETHOD(ofw_bus_get_type, fhc_get_type),
80 static driver_t fhc_central_driver = {
83 sizeof(struct fhc_softc),
86 static devclass_t fhc_central_devclass;
88 DRIVER_MODULE(fhc, central, fhc_central_driver, fhc_central_devclass, 0, 0);
89 MODULE_DEPEND(fhc, central, 1, 1, 1);
92 fhc_central_probe(device_t dev)
95 if (strcmp(ofw_bus_get_name(dev), "fhc") == 0) {
96 device_set_desc(dev, "fhc");
97 return (fhc_probe(dev));
103 fhc_central_attach(device_t dev)
105 struct fhc_softc *sc;
111 sc = device_get_softc(dev);
112 node = ofw_bus_get_node(dev);
114 sc->sc_flags |= FHC_CENTRAL;
116 for (i = 0; i < FHC_NREG; i++) {
118 sc->sc_memres[i] = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
120 if (sc->sc_memres[i] == NULL)
121 panic("%s: can't allocate registers", __func__);
122 sc->sc_bt[i] = rman_get_bustag(sc->sc_memres[i]);
123 sc->sc_bh[i] = rman_get_bushandle(sc->sc_memres[i]);
126 board = bus_space_read_4(sc->sc_bt[FHC_INTERNAL],
127 sc->sc_bh[FHC_INTERNAL], FHC_BSR);
128 sc->sc_board = ((board >> 16) & 0x1) | ((board >> 12) & 0xe);
130 return (fhc_attach(dev));