2 * Copyright (c) 2015-2016 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$");
33 #include <sys/param.h>
34 #include <sys/kernel.h>
37 #include <sys/module.h>
38 #include <sys/mutex.h>
39 #include <sys/systm.h>
41 #include <machine/bus.h>
42 #include <machine/resource.h>
44 #include <dev/bhnd/bhnd.h>
46 #include "bhnd_pmureg.h"
47 #include "bhnd_pmuvar.h"
53 /* Supported device identifiers */
54 static const struct bhnd_device bhnd_pmucore_devices[] = {
55 BHND_DEVICE(BCM, PMU, NULL, NULL),
61 bhnd_pmu_core_probe(device_t dev)
63 const struct bhnd_device *id;
66 id = bhnd_device_lookup(dev, bhnd_pmucore_devices,
67 sizeof(bhnd_pmucore_devices[0]));
71 /* Delegate to common driver implementation */
72 if ((error = bhnd_pmu_probe(dev)) > 0)
75 bhnd_set_default_core_desc(dev);
76 return (BUS_PROBE_DEFAULT);
80 bhnd_pmu_core_attach(device_t dev)
82 struct bhnd_pmu_softc *sc;
83 struct bhnd_resource *res;
87 sc = device_get_softc(dev);
89 /* Allocate register block */
91 res = bhnd_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
93 device_printf(dev, "failed to allocate resources\n");
97 /* Delegate to common driver implementation */
98 if ((error = bhnd_pmu_attach(dev, res))) {
99 bhnd_release_resource(dev, SYS_RES_MEMORY, rid, res);
108 bhnd_pmu_core_detach(device_t dev)
110 struct bhnd_pmu_softc *sc;
113 sc = device_get_softc(dev);
115 /* Delegate to common driver implementation */
116 if ((error = bhnd_pmu_detach(dev)))
119 bhnd_release_resource(dev, SYS_RES_MEMORY, sc->rid, sc->res);
123 static device_method_t bhnd_pmucore_methods[] = {
124 /* Device interface */
125 DEVMETHOD(device_probe, bhnd_pmu_core_probe),
126 DEVMETHOD(device_attach, bhnd_pmu_core_attach),
127 DEVMETHOD(device_detach, bhnd_pmu_core_detach),
132 DEFINE_CLASS_1(bhnd_pmu, bhnd_pmucore_driver, bhnd_pmucore_methods,
133 sizeof(struct bhnd_pmu_softc), bhnd_pmu_driver);
134 EARLY_DRIVER_MODULE(bhnd_pmu, bhnd, bhnd_pmucore_driver, bhnd_pmu_devclass,
135 NULL, NULL, BUS_PASS_TIMER + BUS_PASS_ORDER_MIDDLE);
137 MODULE_DEPEND(bhnd_pmu_core, bhnd_pmu, 1, 1, 1);
138 MODULE_VERSION(bhnd_pmu_core, 1);