Add fdtbus_clock_byname, which can be used by clock backends to

lookup clocks in other domains by "clock-output-names" property.
Not intended for ordinary driver use.
This commit is contained in:
jmcneill 2018-06-10 13:26:29 +00:00
parent 061f0fcc8a
commit 9a2e3e05ca
2 changed files with 38 additions and 3 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: fdt_clock.c,v 1.1 2015/12/22 21:42:11 jmcneill Exp $ */
/* $NetBSD: fdt_clock.c,v 1.2 2018/06/10 13:26:29 jmcneill Exp $ */
/*-
* Copyright (c) 2015 Jared D. McNeill <jmcneill@invisible.ca>
@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: fdt_clock.c,v 1.1 2015/12/22 21:42:11 jmcneill Exp $");
__KERNEL_RCSID(0, "$NetBSD: fdt_clock.c,v 1.2 2018/06/10 13:26:29 jmcneill Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@ -156,3 +156,37 @@ fdtbus_clock_get(int phandle, const char *clkname)
return clk;
}
/*
* Search the DT for a clock by "clock-output-names" property.
*
* This should only be used by clk backends. Not for use by ordinary
* clock consumers!
*/
struct clk *
fdtbus_clock_byname(const char *clkname)
{
struct fdtbus_clock_controller *cc;
u_int len, resid, index, clock_cells;
const char *p;
for (cc = fdtbus_cc; cc; cc = cc->cc_next) {
if (!of_hasprop(cc->cc_phandle, "clock-output-names"))
continue;
p = fdtbus_get_prop(cc->cc_phandle, "clock-output-names", &len);
for (index = 0, resid = len; resid > 0; index++) {
if (strcmp(p, clkname) == 0) {
if (of_getprop_uint32(cc->cc_phandle, "#clock-cells", &clock_cells))
break;
const u_int index_raw = htobe32(index);
return cc->cc_funcs->decode(cc->cc_dev,
clock_cells > 0 ? &index_raw : NULL,
clock_cells > 0 ? 4 : 0);
}
resid -= strlen(p) + 1;
p += strlen(p) + 1;
}
}
return NULL;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: fdtvar.h,v 1.32 2018/05/15 10:17:55 jmcneill Exp $ */
/* $NetBSD: fdtvar.h,v 1.33 2018/06/10 13:26:29 jmcneill Exp $ */
/*-
* Copyright (c) 2015 Jared D. McNeill <jmcneill@invisible.ca>
@ -303,6 +303,7 @@ void fdtbus_dma_halt(struct fdtbus_dma *);
struct clk * fdtbus_clock_get(int, const char *);
struct clk * fdtbus_clock_get_index(int, u_int);
struct clk * fdtbus_clock_byname(const char *);
struct fdtbus_reset *fdtbus_reset_get(int, const char *);
struct fdtbus_reset *fdtbus_reset_get_index(int, u_int);