diff options
author | ian <ian@FreeBSD.org> | 2015-08-12 17:23:15 +0000 |
---|---|---|
committer | ian <ian@FreeBSD.org> | 2015-08-12 17:23:15 +0000 |
commit | 63fee1ed3c12307e2e8fbbb11ada91970a9dcac9 (patch) | |
tree | 6f7cad2c36afae24b4a47fe4d810f35b08937241 /sys/arm/ti/ti_hwmods.c | |
parent | e8e83ea04ffd331beea107ebc6809904c8046e9f (diff) | |
download | FreeBSD-src-63fee1ed3c12307e2e8fbbb11ada91970a9dcac9.zip FreeBSD-src-63fee1ed3c12307e2e8fbbb11ada91970a9dcac9.tar.gz |
Add a routine to return the hardware instance/unit number from ti,hwmods,
given the hardware name.
The ti,hwmods property is used (among other things) to associate an fdt node
with a specific instance of some hardware. For example given a device node
that contains the property ti,hwmods = "timer3", if you call this passing
"timer" as the hwmod string to look for it would return 3.
Diffstat (limited to 'sys/arm/ti/ti_hwmods.c')
-rw-r--r-- | sys/arm/ti/ti_hwmods.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/sys/arm/ti/ti_hwmods.c b/sys/arm/ti/ti_hwmods.c index eb39bd2..1488e55 100644 --- a/sys/arm/ti/ti_hwmods.c +++ b/sys/arm/ti/ti_hwmods.c @@ -168,3 +168,35 @@ int ti_hwmods_contains(device_t dev, const char *hwmod) return (result); } + +int +ti_hwmods_get_unit(device_t dev, const char *hwmod) +{ + phandle_t node; + int l, len, hwmodlen, result; + char *name; + char *buf; + + if ((node = ofw_bus_get_node(dev)) == 0) + return (0); + + if ((len = OF_getprop_alloc(node, "ti,hwmods", 1, (void**)&name)) <= 0) + return (0); + + buf = name; + hwmodlen = strlen(hwmod); + result = 0; + while (len > 0) { + if (strncmp(name, hwmod, hwmodlen) == 0) { + result = (int)strtoul(name + hwmodlen, NULL, 10); + break; + } + /* Slide to the next sub-string. */ + l = strlen(name) + 1; + name += l; + len -= l; + } + + free(buf, M_OFWPROP); + return (result); +} |