summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorVille Syrjälä <ville.syrjala@linux.intel.com>2015-02-05 19:44:40 +0200
committerVille Syrjälä <ville.syrjala@linux.intel.com>2015-03-24 15:30:20 +0200
commit38e3c58cba951ff43f8314edfd0adb8082d81f8b (patch)
tree3d071294bbed768d38cba74eb1bed52f4fa95365 /tools
parent29ebc68313a8dee9b98fac1b337f9bf60b3bfb0a (diff)
tools/intel_iosf_sb_*: Replace if ladder with an array and bsearch()
Replace the silly strcasecmp() if ladder with and array that maps the unit names to port numbers. And keep the thing sorted so we can do the lookup with bsearch() for extra speed :) Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/intel_iosf_sb_read.c59
-rw-r--r--tools/intel_iosf_sb_write.c59
2 files changed, 78 insertions, 40 deletions
diff --git a/tools/intel_iosf_sb_read.c b/tools/intel_iosf_sb_read.c
index 03bf0076..51b0d114 100644
--- a/tools/intel_iosf_sb_read.c
+++ b/tools/intel_iosf_sb_read.c
@@ -29,6 +29,44 @@
#include <string.h>
#include "intel_io.h"
#include "intel_chipset.h"
+#include "drmtest.h"
+
+/* keep sorted by name for bsearch() */
+static const struct iosf_sb_port {
+ const char *name;
+ uint8_t port;
+} iosf_sb_ports[] = {
+ { "bunit", 0x03, },
+ { "cck", 0x14, },
+ { "ccu", 0xa9, },
+ { "dpio", 0x12, },
+ { "dpio2", 0x1a, },
+ { "flisdsi", 0x1b, },
+ { "gpio_nc", 0x13, },
+ { "nc", 0x11, },
+ { "punit", 0x04, },
+};
+
+static int iosf_sb_port_compare(const void *a, const void *b)
+{
+ const char *name = a;
+ const struct iosf_sb_port *p = b;
+
+ return strcasecmp(name, p->name);
+}
+
+static int iosf_sb_port_parse(const char *name)
+{
+ const struct iosf_sb_port *p;
+
+ p = bsearch(name, iosf_sb_ports, ARRAY_SIZE(iosf_sb_ports),
+ sizeof(iosf_sb_ports[0]),
+ iosf_sb_port_compare);
+ if (p)
+ return p->port;
+
+ return strtoul(name, NULL, 16);
+}
static void usage(const char *name)
{
@@ -48,26 +86,7 @@ int main(int argc, char *argv[])
return 1;
}
- if (!strcasecmp(argv[1], "bunit"))
- port = 0x03;
- else if (!strcasecmp(argv[1], "punit"))
- port = 0x04;
- else if (!strcasecmp(argv[1], "nc"))
- port = 0x11;
- else if (!strcasecmp(argv[1], "dpio"))
- port = 0x12;
- else if (!strcasecmp(argv[1], "gpio_nc"))
- port = 0x13;
- else if (!strcasecmp(argv[1], "cck"))
- port = 0x14;
- else if (!strcasecmp(argv[1], "ccu"))
- port = 0xa9;
- else if (!strcasecmp(argv[1], "dpio2"))
- port = 0x1a;
- else if (!strcasecmp(argv[1], "flisdsi"))
- port = 0x1b;
- else
- port = strtoul(argv[1], NULL, 16);
+ port = iosf_sb_port_parse(argv[1]);
reg = strtoul(argv[2], NULL, 16);
diff --git a/tools/intel_iosf_sb_write.c b/tools/intel_iosf_sb_write.c
index 13c738f1..f6aa8f1c 100644
--- a/tools/intel_iosf_sb_write.c
+++ b/tools/intel_iosf_sb_write.c
@@ -28,6 +28,44 @@
#include <string.h>
#include "intel_io.h"
#include "intel_chipset.h"
+#include "drmtest.h"
+
+/* keep sorted by name for bsearch() */
+static const struct iosf_sb_port {
+ const char *name;
+ uint8_t port;
+} iosf_sb_ports[] = {
+ { "bunit", 0x03, },
+ { "cck", 0x14, },
+ { "ccu", 0xa9, },
+ { "dpio", 0x12, },
+ { "dpio2", 0x1a, },
+ { "flisdsi", 0x1b, },
+ { "gpio_nc", 0x13, },
+ { "nc", 0x11, },
+ { "punit", 0x04, },
+};
+
+static int iosf_sb_port_compare(const void *a, const void *b)
+{
+ const char *name = a;
+ const struct iosf_sb_port *p = b;
+
+ return strcasecmp(name, p->name);
+}
+
+static int iosf_sb_port_parse(const char *name)
+{
+ const struct iosf_sb_port *p;
+
+ p = bsearch(name, iosf_sb_ports, ARRAY_SIZE(iosf_sb_ports),
+ sizeof(iosf_sb_ports[0]),
+ iosf_sb_port_compare);
+ if (p)
+ return p->port;
+
+ return strtoul(name, NULL, 16);
+}
static void usage(const char *name)
{
@@ -47,26 +85,7 @@ int main(int argc, char** argv)
return 1;
}
- if (!strcasecmp(argv[1], "bunit"))
- port = 0x03;
- else if (!strcasecmp(argv[1], "punit"))
- port = 0x04;
- else if (!strcasecmp(argv[1], "nc"))
- port = 0x11;
- else if (!strcasecmp(argv[1], "dpio"))
- port = 0x12;
- else if (!strcasecmp(argv[1], "gpio_nc"))
- port = 0x13;
- else if (!strcasecmp(argv[1], "cck"))
- port = 0x14;
- else if (!strcasecmp(argv[1], "ccu"))
- port = 0xa9;
- else if (!strcasecmp(argv[1], "dpio2"))
- port = 0x1a;
- else if (!strcasecmp(argv[1], "flisdsi"))
- port = 0x1b;
- else
- port = strtoul(argv[1], NULL, 16);
+ port = iosf_sb_port_parse(argv[1]);
reg = strtoul(argv[2], NULL, 16);
val = strtoul(argv[3], NULL, 16);