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"
50 static const struct resource_spec bwn_rspec[] = {
51 { SYS_RES_MEMORY, 0, RF_ACTIVE },
55 #define RSPEC_LEN (sizeof(bwn_rspec)/sizeof(bwn_rspec[0]))
58 struct resource_spec rspec[RSPEC_LEN];
59 struct bhnd_resource *res[RSPEC_LEN-1];
62 static const struct bwn_device {
66 { BHND_MFGID_BCM, BHND_COREID_D11 },
67 { BHND_MFGID_INVALID, BHND_COREID_INVALID }
71 bwn_probe(device_t dev)
73 const struct bwn_device *id;
75 for (id = bwn_devices; id->device != BHND_COREID_INVALID; id++)
77 if (bhnd_get_vendor(dev) == id->vendor &&
78 bhnd_get_device(dev) == id->device)
80 device_set_desc(dev, bhnd_get_device_name(dev));
81 return (BUS_PROBE_DEFAULT);
89 bwn_attach(device_t dev)
92 struct bhnd_resource *r;
95 sc = device_get_softc(dev);
97 memcpy(sc->rspec, bwn_rspec, sizeof(bwn_rspec));
98 if ((error = bhnd_alloc_resources(dev, sc->rspec, sc->res)))
103 device_printf(dev, "got rid=%d res=%p\n", sc->rspec[0].rid, r);
106 error = bhnd_nvram_getvar(dev, BHND_NVAR_MACADDR, macaddr,
111 device_printf(dev, "got macaddr %6D\n", macaddr, ":");
117 bwn_detach(device_t dev)
119 struct bwn_softc *sc;
121 sc = device_get_softc(dev);
122 bhnd_release_resources(dev, sc->rspec, sc->res);
128 bwn_suspend(device_t dev)
134 bwn_resume(device_t dev)
139 static device_method_t bwn_methods[] = {
140 /* Device interface */
141 DEVMETHOD(device_probe, bwn_probe),
142 DEVMETHOD(device_attach, bwn_attach),
143 DEVMETHOD(device_detach, bwn_detach),
144 DEVMETHOD(device_suspend, bwn_suspend),
145 DEVMETHOD(device_resume, bwn_resume),
149 static devclass_t bwn_devclass;
151 DEFINE_CLASS_0(bwn, bwn_driver, bwn_methods, sizeof(struct bwn_softc));
152 DRIVER_MODULE(bwn_mac, bhnd, bwn_driver, bwn_devclass, 0, 0);
153 MODULE_DEPEND(bwn_mac, bhnd, 1, 1, 1);
154 MODULE_VERSION(bwn_mac, 1);