svn commit: r286678 - head/sys/arm/ti
Ian Lepore
ian at FreeBSD.org
Wed Aug 12 17:23:16 UTC 2015
Author: ian
Date: Wed Aug 12 17:23:15 2015
New Revision: 286678
URL: https://svnweb.freebsd.org/changeset/base/286678
Log:
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.
Modified:
head/sys/arm/ti/ti_hwmods.c
head/sys/arm/ti/ti_hwmods.h
Modified: head/sys/arm/ti/ti_hwmods.c
==============================================================================
--- head/sys/arm/ti/ti_hwmods.c Wed Aug 12 17:21:41 2015 (r286677)
+++ head/sys/arm/ti/ti_hwmods.c Wed Aug 12 17:23:15 2015 (r286678)
@@ -168,3 +168,35 @@ int ti_hwmods_contains(device_t dev, con
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);
+}
Modified: head/sys/arm/ti/ti_hwmods.h
==============================================================================
--- head/sys/arm/ti/ti_hwmods.h Wed Aug 12 17:21:41 2015 (r286677)
+++ head/sys/arm/ti/ti_hwmods.h Wed Aug 12 17:23:15 2015 (r286678)
@@ -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_ */
More information about the svn-src-head
mailing list