summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorVille Syrjälä <ville.syrjala@linux.intel.com>2015-02-05 16:50:07 +0200
committerVille Syrjälä <ville.syrjala@linux.intel.com>2015-03-24 15:30:20 +0200
commit0461e8cf4314ee43ef4440ebdaf68eff2c57e5a2 (patch)
tree9fa5c49bd4521a4734d34d43fb04d2f7602bed99 /tools
parent38e3c58cba951ff43f8314edfd0adb8082d81f8b (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')
-rw-r--r--tools/intel_iosf_sb_read.c45
-rw-r--r--tools/intel_iosf_sb_write.c51
2 files changed, 78 insertions, 18 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();
diff --git a/tools/intel_iosf_sb_write.c b/tools/intel_iosf_sb_write.c
index f6aa8f1c..d0ba4d34 100644
--- a/tools/intel_iosf_sb_write.c
+++ b/tools/intel_iosf_sb_write.c
@@ -69,36 +69,67 @@ 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> <val>\n"
- "\t port/reg/val : in 0xXXXX format\n",
- name);
+ int i;
+
+ printf("Warning : This program will work only on Valleyview/Cherryview\n"
+ "Usage: %s [-h] [--] <port> <reg> <val>\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"
+ "\t <val> : in hex\n");
}
int main(int argc, char** argv)
{
uint32_t port, reg, val, tmp;
struct pci_device *dev = intel_get_pci_device();
+ int i, nregs;
+ const char *name;
- if (argc != 4 || !(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 < 2) {
+ usage(argv[0]);
+ return 2;
+ }
+
+ i = optind;
+ name = argv[i++];
+ port = iosf_sb_port_parse(name);
- reg = strtoul(argv[2], NULL, 16);
- val = strtoul(argv[3], NULL, 16);
+ reg = strtoul(argv[i], NULL, 16);
+ val = strtoul(argv[i+1], NULL, 16);
intel_register_access_init(dev, 0);
tmp = intel_iosf_sb_read(port, reg);
- printf("0x%02x(%s)/0x%04x before : 0x%08x\n", port, argv[1], reg, tmp);
+ printf("0x%02x(%s)/0x%04x before : 0x%08x\n", port, name, reg, tmp);
intel_iosf_sb_write(port, reg, val);
tmp = intel_iosf_sb_read(port, reg);
- printf("0x%02x(%s)/0x%04x after : 0x%08x\n", port, argv[1], reg, tmp);
+ printf("0x%02x(%s)/0x%04x after : 0x%08x\n", port, name, reg, tmp);
intel_register_access_fini();