diff options
author | Ville Syrjälä <ville.syrjala@linux.intel.com> | 2015-02-05 16:50:07 +0200 |
---|---|---|
committer | Ville Syrjälä <ville.syrjala@linux.intel.com> | 2015-03-24 15:30:20 +0200 |
commit | 0461e8cf4314ee43ef4440ebdaf68eff2c57e5a2 (patch) | |
tree | 9fa5c49bd4521a4734d34d43fb04d2f7602bed99 /tools/intel_iosf_sb_read.c | |
parent | 38e3c58cba951ff43f8314edfd0adb8082d81f8b (diff) |
tools/intel_iosf_sb_*: Use getopt() to parse the options
I want to add some command line options so switch to getopt() to make
that easier.
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Diffstat (limited to 'tools/intel_iosf_sb_read.c')
-rw-r--r-- | tools/intel_iosf_sb_read.c | 45 |
1 files changed, 37 insertions, 8 deletions
diff --git a/tools/intel_iosf_sb_read.c b/tools/intel_iosf_sb_read.c index 51b0d114..abe7fb50 100644 --- a/tools/intel_iosf_sb_read.c +++ b/tools/intel_iosf_sb_read.c @@ -70,30 +70,59 @@ static int iosf_sb_port_parse(const char *name) static void usage(const char *name) { - printf("Warning : This program will work only on Valleyview\n" - "Usage: %s <port> <reg>\n" - "\t port/reg : in 0xXXXX format\n", - name); + int i; + + printf("Warning : This program will work only on Valleyview/Cherryview\n" + "Usage: %s [-h] [--] <port> <reg>\n" + "\t -h : Show this help text\n" + "\t <port> : ", name); + for (i = 0; i < ARRAY_SIZE(iosf_sb_ports); i++) + printf("%s,", iosf_sb_ports[i].name); + printf(" or in hex\n" + "\t <reg> : in hex\n"); } int main(int argc, char *argv[]) { uint32_t port, reg, val; struct pci_device *dev = intel_get_pci_device(); + int i, nregs; + const char *name; - if (argc != 3 || !(IS_VALLEYVIEW(dev->device_id) || IS_CHERRYVIEW(dev->device_id))) { + if (!IS_VALLEYVIEW(dev->device_id) && + !IS_CHERRYVIEW(dev->device_id)) { usage(argv[0]); return 1; } - port = iosf_sb_port_parse(argv[1]); + for (;;) { + int c = getopt(argc, argv, "h"); + + if (c == -1) + break; + + switch (c) { + case 'h': + usage(argv[0]); + return 0; + } + } + + nregs = argc - optind; + if (nregs < 1) { + usage(argv[0]); + return 2; + } - reg = strtoul(argv[2], NULL, 16); + i = optind; + name = argv[i++]; + port = iosf_sb_port_parse(name); intel_register_access_init(dev, 0); + reg = strtoul(argv[i], NULL, 16); val = intel_iosf_sb_read(port, reg); - printf("0x%02x(%s)/0x%04x : 0x%08x\n", port, argv[1], reg, val); + printf("0x%02x(%s)/0x%04x : 0x%08x\n", port, name, reg, val); intel_register_access_fini(); |