2 * Copyright (c) 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$");
34 * ChipCommon attachment support for the bhnd(4) PMU driver.
36 * Supports non-AOB ("Always-on Bus") devices that map the PMU register blocks
37 * via the ChipCommon core, rather than vending a distinct PMU core on the
41 #include <sys/param.h>
42 #include <sys/kernel.h>
44 #include <sys/limits.h>
45 #include <sys/malloc.h>
46 #include <sys/module.h>
47 #include <sys/systm.h>
49 #include <dev/bhnd/bhnd.h>
51 #include <dev/bhnd/cores/pmu/bhnd_pmuvar.h>
52 #include <dev/bhnd/cores/pmu/bhnd_pmureg.h>
54 #include "bhnd_chipc_if.h"
55 #include "bhnd_pmu_if.h"
60 bhnd_pmu_chipc_probe(device_t dev)
62 struct bhnd_pmu_softc *sc;
63 struct chipc_caps *ccaps;
64 struct chipc_softc *chipc_sc;
71 sc = device_get_softc(dev);
73 /* Look for chipc parent */
74 chipc = device_get_parent(dev);
75 if (device_get_devclass(chipc) != devclass_find("bhnd_chipc"))
78 /* Check the chipc PMU capability flag. */
79 ccaps = BHND_CHIPC_GET_CAPS(chipc);
83 /* Delegate to common driver implementation */
84 if ((error = bhnd_pmu_probe(dev)) > 0)
87 /* Fetch PMU capability flags */
88 chipc_sc = device_get_softc(chipc);
89 pcaps = bhnd_bus_read_4(chipc_sc->core, BHND_PMU_CAP);
92 rev = BHND_PMU_GET_BITS(pcaps, BHND_PMU_CAP_REV);
93 snprintf(desc, sizeof(desc), "Broadcom ChipCommon PMU, rev %hhu", rev);
94 device_set_desc_copy(dev, desc);
96 return (BUS_PROBE_NOWILDCARD);
100 bhnd_pmu_chipc_attach(device_t dev)
102 struct chipc_softc *chipc_sc;
103 struct bhnd_resource *r;
105 /* Fetch core registers from ChipCommon parent */
106 chipc_sc = device_get_softc(device_get_parent(dev));
109 return (bhnd_pmu_attach(dev, r));
112 static device_method_t bhnd_pmu_chipc_methods[] = {
113 /* Device interface */
114 DEVMETHOD(device_probe, bhnd_pmu_chipc_probe),
115 DEVMETHOD(device_attach, bhnd_pmu_chipc_attach),
120 DEFINE_CLASS_1(bhnd_pmu, bhnd_pmu_chipc_driver, bhnd_pmu_chipc_methods,
121 sizeof(struct bhnd_pmu_softc), bhnd_pmu_driver);
122 EARLY_DRIVER_MODULE(bhnd_pmu_chipc, bhnd_chipc, bhnd_pmu_chipc_driver,
123 bhnd_pmu_devclass, NULL, NULL, BUS_PASS_TIMER + BUS_PASS_ORDER_MIDDLE);
125 MODULE_DEPEND(bhnd_pmu_chipc, bhnd, 1, 1, 1);
126 MODULE_VERSION(bhnd_pmu_chipc, 1);