2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2015 Landon Fuller <landon@landonf.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer,
12 * without modification.
13 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
14 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
15 * redistribution must be conditioned upon including a substantially
16 * similar Disclaimer requirement for further binary redistribution.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
22 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
24 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
27 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29 * THE POSSIBILITY OF SUCH DAMAGES.
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
35 #include <sys/param.h>
36 #include <sys/kernel.h>
38 #include <sys/module.h>
40 #include <dev/bhnd/bhnd_ids.h>
41 #include <dev/bhnd/bhndb/bhndbvar.h>
42 #include <dev/bhnd/bhndb/bhndb_hwdata.h>
46 #include "bcma_eromreg.h"
47 #include "bcma_eromvar.h"
50 * Supports attachment of bcma(4) bus devices via a bhndb bridge.
54 bcma_bhndb_probe(device_t dev)
56 const struct bhnd_chipid *cid;
59 /* Defer to default probe implementation */
60 if ((error = bcma_probe(dev)) > 0)
64 cid = BHNDB_GET_CHIPID(device_get_parent(dev), dev);
65 if (cid->chip_type != BHND_CHIPTYPE_BCMA)
68 /* Set device description */
69 bhnd_set_default_bus_desc(dev, cid);
75 bcma_bhndb_attach(device_t dev)
79 /* Perform initial attach and enumerate our children. */
80 if ((error = bcma_attach(dev)))
83 /* Delegate remainder to standard bhnd method implementation */
84 if ((error = bhnd_generic_attach(dev)))
90 device_delete_children(dev);
95 bcma_bhndb_suspend_child(device_t dev, device_t child)
97 struct bcma_devinfo *dinfo;
100 if (device_get_parent(child) != dev)
101 BUS_SUSPEND_CHILD(device_get_parent(dev), child);
103 if (device_is_suspended(child))
106 dinfo = device_get_ivars(child);
108 /* Suspend the child */
109 if ((error = bhnd_generic_br_suspend_child(dev, child)))
112 /* Suspend child's agent resource */
113 if (dinfo->res_agent != NULL)
114 BHNDB_SUSPEND_RESOURCE(device_get_parent(dev), dev,
115 SYS_RES_MEMORY, dinfo->res_agent->res);
121 bcma_bhndb_resume_child(device_t dev, device_t child)
123 struct bcma_devinfo *dinfo;
126 if (device_get_parent(child) != dev)
127 BUS_SUSPEND_CHILD(device_get_parent(dev), child);
129 if (!device_is_suspended(child))
132 dinfo = device_get_ivars(child);
134 /* Resume child's agent resource */
135 if (dinfo->res_agent != NULL) {
136 error = BHNDB_RESUME_RESOURCE(device_get_parent(dev), dev,
137 SYS_RES_MEMORY, dinfo->res_agent->res);
142 /* Resume the child */
143 if ((error = bhnd_generic_br_resume_child(dev, child))) {
144 /* On failure, re-suspend the agent resource */
145 if (dinfo->res_agent != NULL) {
146 BHNDB_SUSPEND_RESOURCE(device_get_parent(dev), dev,
147 SYS_RES_MEMORY, dinfo->res_agent->res);
156 static device_method_t bcma_bhndb_methods[] = {
157 /* Device interface */
158 DEVMETHOD(device_probe, bcma_bhndb_probe),
159 DEVMETHOD(device_attach, bcma_bhndb_attach),
162 DEVMETHOD(bus_suspend_child, bcma_bhndb_suspend_child),
163 DEVMETHOD(bus_resume_child, bcma_bhndb_resume_child),
168 DEFINE_CLASS_2(bhnd, bcma_bhndb_driver, bcma_bhndb_methods,
169 sizeof(struct bcma_softc), bhnd_bhndb_driver, bcma_driver);
171 DRIVER_MODULE(bcma_bhndb, bhndb, bcma_bhndb_driver, bhnd_devclass, NULL, NULL);
173 MODULE_VERSION(bcma_bhndb, 1);
174 MODULE_DEPEND(bcma_bhndb, bcma, 1, 1, 1);
175 MODULE_DEPEND(bcma_bhndb, bhnd, 1, 1, 1);
176 MODULE_DEPEND(bcma_bhndb, bhndb, 1, 1, 1);