2 * Copyright (c) 2015 Landon Fuller <landon@landonf.org>
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 * without modification.
11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13 * redistribution must be conditioned upon including a substantially
14 * similar Disclaimer requirement for further binary redistribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 * THE POSSIBILITY OF SUCH DAMAGES.
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
36 #include <sys/param.h>
37 #include <sys/kernel.h>
38 #include <sys/module.h>
39 #include <sys/systm.h>
41 #include <machine/bus.h>
43 #include <machine/resource.h>
45 #include <dev/bhnd/bhnd.h>
46 #include <dev/bhnd/bhnd_ids.h>
48 #include "bhnd_nvram_map.h"
52 struct bhnd_resource *mem_res;
55 struct resource *intr_res;
58 static const struct bwn_device {
62 { BHND_MFGID_BCM, BHND_COREID_D11 },
63 { BHND_MFGID_INVALID, BHND_COREID_INVALID }
67 bwn_probe(device_t dev)
69 const struct bwn_device *id;
71 for (id = bwn_devices; id->device != BHND_COREID_INVALID; id++)
73 if (bhnd_get_vendor(dev) == id->vendor &&
74 bhnd_get_device(dev) == id->device)
76 device_set_desc(dev, bhnd_get_device_name(dev));
77 return (BUS_PROBE_DEFAULT);
85 bwn_attach(device_t dev)
90 sc = device_get_softc(dev);
92 /* Allocate device resources */
94 sc->mem_res = bhnd_alloc_resource_any(dev, SYS_RES_MEMORY,
95 &sc->mem_rid, RF_ACTIVE);
96 if (sc->mem_res == NULL) {
97 device_printf(dev, "failed to allocate device registers\n");
103 sc->intr_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->intr_rid,
104 RF_ACTIVE|RF_SHAREABLE);
105 if (sc->intr_res == NULL) {
106 device_printf(dev, "failed to allocate device interrupt\n");
113 error = bhnd_nvram_getvar_array(dev, BHND_NVAR_MACADDR, macaddr,
114 sizeof(macaddr), BHND_NVRAM_TYPE_UINT8_ARRAY);
116 device_printf(dev, "error fetching macaddr: %d\n", error);
118 device_printf(dev, "got macaddr %6D\n", macaddr, ":");
123 if (sc->mem_res != NULL)
124 bhnd_release_resource(dev, SYS_RES_MEMORY, sc->mem_rid,
127 if (sc->intr_res != NULL)
128 bus_release_resource(dev, SYS_RES_IRQ, sc->intr_rid,
135 bwn_detach(device_t dev)
137 struct bwn_softc *sc;
139 sc = device_get_softc(dev);
141 bhnd_release_resource(dev, SYS_RES_MEMORY, sc->mem_rid, sc->mem_res);
142 bus_release_resource(dev, SYS_RES_IRQ, sc->intr_rid, sc->intr_res);
148 bwn_suspend(device_t dev)
154 bwn_resume(device_t dev)
159 static device_method_t bwn_methods[] = {
160 /* Device interface */
161 DEVMETHOD(device_probe, bwn_probe),
162 DEVMETHOD(device_attach, bwn_attach),
163 DEVMETHOD(device_detach, bwn_detach),
164 DEVMETHOD(device_suspend, bwn_suspend),
165 DEVMETHOD(device_resume, bwn_resume),
169 static devclass_t bwn_devclass;
171 DEFINE_CLASS_0(bwn, bwn_driver, bwn_methods, sizeof(struct bwn_softc));
172 DRIVER_MODULE(bwn_mac, bhnd, bwn_driver, bwn_devclass, 0, 0);
173 MODULE_DEPEND(bwn_mac, bhnd, 1, 1, 1);
174 MODULE_VERSION(bwn_mac, 1);