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:
parent
2d41b1006f
commit
beacf789e5
@ -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);
|
||||
}
|
||||
|
@ -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_ */
|
||||
|
Loading…
Reference in New Issue
Block a user