summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorjmcneill <jmcneill@NetBSD.org>2019-10-28 21:14:58 +0000
committerjmcneill <jmcneill@NetBSD.org>2019-10-28 21:14:58 +0000
commitce40651bedbdbe8eeba17b6185433e053576e970 (patch)
tree8a3a0066190e3ad790b602ff05548c581bf2da2d /sys/dev
parentb7e5a86dd7ce88894731f85a75c96d3d4d00481d (diff)
Add support for platform specific opp table filters.
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/fdt/cpufreq_dt.c49
-rw-r--r--sys/dev/fdt/fdtvar.h17
2 files changed, 57 insertions, 9 deletions
diff --git a/sys/dev/fdt/cpufreq_dt.c b/sys/dev/fdt/cpufreq_dt.c
index e2c0226cf4d..c3acb6f3986 100644
--- a/sys/dev/fdt/cpufreq_dt.c
+++ b/sys/dev/fdt/cpufreq_dt.c
@@ -1,4 +1,4 @@
-/* $NetBSD: cpufreq_dt.c,v 1.11 2019/10/28 10:43:08 jmcneill Exp $ */
+/* $NetBSD: cpufreq_dt.c,v 1.12 2019/10/28 21:14:58 jmcneill Exp $ */
/*-
* Copyright (c) 2015-2017 Jared McNeill <jmcneill@invisible.ca>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpufreq_dt.c,v 1.11 2019/10/28 10:43:08 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpufreq_dt.c,v 1.12 2019/10/28 21:14:58 jmcneill Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -356,11 +356,46 @@ cpufreq_dt_parse_opp(struct cpufreq_dt_softc *sc)
return 0;
}
+static const struct fdt_opp_info *
+cpufreq_dt_lookup_opp_info(const int opp_table)
+{
+ __link_set_decl(fdt_opps, struct fdt_opp_info);
+ struct fdt_opp_info * const *opp;
+ const struct fdt_opp_info *best_opp = NULL;
+ int match, best_match = 0;
+
+ __link_set_foreach(opp, fdt_opps) {
+ const char * const compat[] = { (*opp)->opp_compat, NULL };
+ match = of_match_compatible(opp_table, compat);
+ if (match > best_match) {
+ best_match = match;
+ best_opp = *opp;
+ }
+ }
+
+ return best_opp;
+}
+
+static bool
+cpufreq_dt_node_supported(const struct fdt_opp_info *opp_info, const int opp_table, const int opp_node)
+{
+ if (!fdtbus_status_okay(opp_node))
+ return false;
+ if (of_hasprop(opp_node, "opp-suspend"))
+ return false;
+
+ if (opp_info != NULL)
+ return opp_info->opp_supported(opp_table, opp_node);
+
+ return true;
+}
+
static int
cpufreq_dt_parse_opp_v2(struct cpufreq_dt_softc *sc)
{
const int phandle = sc->sc_phandle;
struct cpufreq_dt_table *table;
+ const struct fdt_opp_info *opp_info;
const u_int *opp_uv;
uint64_t opp_hz;
int opp_node, len, i, index;
@@ -378,10 +413,10 @@ cpufreq_dt_parse_opp_v2(struct cpufreq_dt_softc *sc)
TAILQ_INSERT_TAIL(&cpufreq_dt_tables, &sc->sc_table, next);
}
+ opp_info = cpufreq_dt_lookup_opp_info(opp_table);
+
for (opp_node = OF_child(opp_table); opp_node; opp_node = OF_peer(opp_node)) {
- if (!fdtbus_status_okay(opp_node))
- continue;
- if (of_hasprop(opp_node, "opp-suspend"))
+ if (!cpufreq_dt_node_supported(opp_info, opp_table, opp_node))
continue;
sc->sc_nopp++;
}
@@ -392,9 +427,7 @@ cpufreq_dt_parse_opp_v2(struct cpufreq_dt_softc *sc)
sc->sc_opp = kmem_zalloc(sizeof(*sc->sc_opp) * sc->sc_nopp, KM_SLEEP);
index = sc->sc_nopp - 1;
for (opp_node = OF_child(opp_table), i = 0; opp_node; opp_node = OF_peer(opp_node), i++) {
- if (!fdtbus_status_okay(opp_node))
- continue;
- if (of_hasprop(opp_node, "opp-suspend"))
+ if (!cpufreq_dt_node_supported(opp_info, opp_table, opp_node))
continue;
if (of_getprop_uint64(opp_node, "opp-hz", &opp_hz) != 0)
return EINVAL;
diff --git a/sys/dev/fdt/fdtvar.h b/sys/dev/fdt/fdtvar.h
index 13545e4063a..15119617ed2 100644
--- a/sys/dev/fdt/fdtvar.h
+++ b/sys/dev/fdt/fdtvar.h
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtvar.h,v 1.54 2019/10/01 23:32:52 jmcneill Exp $ */
+/* $NetBSD: fdtvar.h,v 1.55 2019/10/28 21:14:58 jmcneill Exp $ */
/*-
* Copyright (c) 2015 Jared D. McNeill <jmcneill@invisible.ca>
@@ -251,6 +251,21 @@ static const struct fdt_console_info __CONCAT(_name,_consinfo) = { \
}; \
_FDT_CONSOLE_REGISTER(_name)
+struct fdt_opp_info {
+ const char * opp_compat;
+ bool (*opp_supported)(const int, const int);
+};
+
+#define _FDT_OPP_REGISTER(name) \
+ __link_set_add_rodata(fdt_opps, __CONCAT(name,_oppinfo));
+
+#define FDT_OPP(_name, _compat, _suppfn) \
+static const struct fdt_opp_info __CONCAT(_name,_oppinfo) = { \
+ .opp_compat = (_compat), \
+ .opp_supported = (_suppfn) \
+}; \
+_FDT_OPP_REGISTER(_name)
+
TAILQ_HEAD(fdt_conslist, fdt_console_info);
int fdtbus_register_interrupt_controller(device_t, int,