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.
This commit is contained in:
Ian Lepore 2015-08-12 17:23:15 +00:00
parent 2d41b1006f
commit beacf789e5
2 changed files with 35 additions and 0 deletions

View File

@ -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);
}

View File

@ -31,4 +31,7 @@
clk_ident_t ti_hwmods_get_clock(device_t dev);
int ti_hwmods_contains(device_t dev, const char *hwmod);
/* Returns the N from "hwmodN" in the ti,hwmods property; 0 on failure. */
int ti_hwmods_get_unit(device_t dev, const char *hwmod);
#endif /* _TI_HWMODS_H_ */