[PATCH] I2C bus fake enumeration applet lsi2c
alison at she-devel.com
alison at she-devel.com
Fri Jan 10 06:56:00 UTC 2014
From: Alison Chaiken <alison_chaiken at mentor.com>
Signed-off-by: Alison Chaiken <alison_chaiken at mentor.com>
---
util-linux/lsi2c.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 55 insertions(+)
create mode 100644 util-linux/lsi2c.c
diff --git a/util-linux/lsi2c.c b/util-linux/lsi2c.c
new file mode 100644
index 0000000..d87ff42
--- /dev/null
+++ b/util-linux/lsi2c.c
@@ -0,0 +1,55 @@
+/*
+ * lsi2c implementation for busybox
+ *
+ * Copyright (C) 2013, 2014 Alison Chaiken alison at she-devel.com,
+ * Souf Oued souf_oued at yahoo.fr
+ *
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
+ */
+
+//usage:#define lsi2c_trivial_usage NOUSAGE_STR
+//usage:#define lsi2c_full_usage ""
+
+#include "libbb.h"
+
+static int FAST_FUNC fileAction(
+ const char *instring,
+ struct stat *statbuf UNUSED_PARAM,
+ void *userData UNUSED_PARAM,
+ int depth)
+{
+ const char *sysfs_node, *drivername;
+ char *address;
+
+ sysfs_node = bb_basename(instring);
+
+ if (!isdigit(sysfs_node[0])) {
+ depth++;
+ return depth;
+ }
+
+ drivername = bb_basename(dirname((char *)instring));
+ address = strchr(sysfs_node, '-');
+
+ if (*address++)
+ printf("Controller %c for driver %s at address 0x%s.\n", *sysfs_node,
+ drivername, address);
+
+ return 0;
+}
+
+int lsi2c_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int lsi2c_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
+{
+ const char *fileName = "/sys/bus/i2c/drivers";
+ int depth = 0;
+
+ recursive_action(fileName,
+ ACTION_RECURSE,
+ fileAction,
+ NULL, /* dirAction */
+ NULL, /* userData */
+ depth);
+
+ return EXIT_SUCCESS;
+}
--
1.8.5.2
More information about the busybox
mailing list