2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2015-2016 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>
39 #include <sys/module.h>
40 #include <sys/mutex.h>
41 #include <sys/systm.h>
43 #include <machine/bus.h>
44 #include <machine/resource.h>
46 #include <dev/bhnd/bhnd.h>
48 #include "bhnd_pmureg.h"
49 #include "bhnd_pmuvar.h"
55 /* Supported device identifiers */
56 static const struct bhnd_device bhnd_pmucore_devices[] = {
57 BHND_DEVICE(BCM, PMU, NULL, NULL),
63 bhnd_pmu_core_probe(device_t dev)
65 const struct bhnd_device *id;
68 id = bhnd_device_lookup(dev, bhnd_pmucore_devices,
69 sizeof(bhnd_pmucore_devices[0]));
73 /* Delegate to common driver implementation */
74 if ((error = bhnd_pmu_probe(dev)) > 0)
77 bhnd_set_default_core_desc(dev);
78 return (BUS_PROBE_DEFAULT);
82 bhnd_pmu_core_attach(device_t dev)
84 struct bhnd_pmu_softc *sc;
85 struct bhnd_resource *res;
89 sc = device_get_softc(dev);
91 /* Allocate register block */
93 res = bhnd_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
95 device_printf(dev, "failed to allocate resources\n");
99 /* Allocate our per-core PMU state */
100 if ((error = bhnd_alloc_pmu(dev))) {
101 device_printf(sc->dev, "failed to allocate PMU state: %d\n",
107 /* Delegate to common driver implementation */
108 if ((error = bhnd_pmu_attach(dev, res))) {
109 bhnd_release_resource(dev, SYS_RES_MEMORY, rid, res);
118 bhnd_pmu_core_detach(device_t dev)
120 struct bhnd_pmu_softc *sc;
123 sc = device_get_softc(dev);
125 /* Delegate to common driver implementation */
126 if ((error = bhnd_pmu_detach(dev)))
129 bhnd_release_resource(dev, SYS_RES_MEMORY, sc->rid, sc->res);
133 static device_method_t bhnd_pmucore_methods[] = {
134 /* Device interface */
135 DEVMETHOD(device_probe, bhnd_pmu_core_probe),
136 DEVMETHOD(device_attach, bhnd_pmu_core_attach),
137 DEVMETHOD(device_detach, bhnd_pmu_core_detach),
142 DEFINE_CLASS_1(bhnd_pmu, bhnd_pmucore_driver, bhnd_pmucore_methods,
143 sizeof(struct bhnd_pmu_softc), bhnd_pmu_driver);
144 EARLY_DRIVER_MODULE(bhnd_pmu, bhnd, bhnd_pmucore_driver, bhnd_pmu_devclass,
145 NULL, NULL, BUS_PASS_TIMER + BUS_PASS_ORDER_MIDDLE);
147 MODULE_DEPEND(bhnd_pmu_core, bhnd_pmu, 1, 1, 1);
148 MODULE_VERSION(bhnd_pmu_core, 1);