Further code simplifications and improvements.
authorUwe Hermann <uwe@hermann-uwe.de>
Wed, 19 Sep 2007 01:55:35 +0000 (01:55 +0000)
committerUwe Hermann <uwe@hermann-uwe.de>
Wed, 19 Sep 2007 01:55:35 +0000 (01:55 +0000)
Add command line option handling code. The following options
are defined at the moment:

-d|--dump      Dump Super I/O registers.
-V|--verbose   Verbose mode.
-v|--version   Show the superiotool version.
-h|--help      Show a short help text.

Per default (no options) we just probe for a Super I/O
and print its vendor, name, ID, version, and config port.

Example:

$ ./superiotool
Found SMSC FDC37N769 Super I/O (id=0x28, rev=0x01) at port=0x03f0

$ ./superiotool -d
Found SMSC FDC37N769 Super I/O (id=0x28, rev=0x01) at port=0x03f0
idx 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f
val 20 90 80 f4 00 00 ff 00 00 00 40 00 0e 28 01 00 00 00 00 00 02 00 01 03 00 00 00 00 00 00 80 00 00 00 00 00 00 ba 00 00 03 00 00 23 03 03 00 00
def 28 9c 88 70 00 00 ff 00 00 00 00 00 02 28 NA 00 00 80 RR RR NA NA NA 03 RR RR RR RR RR RR 80 00 3c RR RR 00 00 00 00 00 00 00 RR 00 00 03 00 00

$ ./superiotool -s
./superiotool: invalid option -- s

$ ./superiotool -h
Usage: superiotool [-d] [-V] [-v] [-h]

$ ./superiotool -v
superiotool 0.1

Signed-off-by: Uwe Hermann <uwe@hermann-uwe.de>
Acked-by: Uwe Hermann <uwe@hermann-uwe.de>
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@2788 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1

util/superiotool/fintek.c
util/superiotool/ite.c
util/superiotool/nsc.c
util/superiotool/smsc.c
util/superiotool/superiotool.c
util/superiotool/superiotool.h

index 3e7bf9fd360984e49c907c18ce628c8a5f37b449..8b5fa5b93c5e05e5bac425bfd8e9c58c92f739f7 100644 (file)
@@ -89,7 +89,7 @@ void dump_fintek(uint16_t port, uint16_t did)
               regval(port, 0xf6), regval(port, 0xf7), regval(port, 0xf8));
 }
 
-void enter_conf_mode_fintek(uint16_t port)
+static void enter_conf_mode_fintek(uint16_t port)
 {
        /* Enable configuration sequence (Fintek uses this for example)
         * Older ITE chips have the same enable sequence.
@@ -98,7 +98,7 @@ void enter_conf_mode_fintek(uint16_t port)
        outb(0x87, port);
 }
 
-void exit_conf_mode_fintek(uint16_t port)
+static void exit_conf_mode_fintek(uint16_t port)
 {
        /* Exit MB PnP mode (for Fintek, doesn't hurt ITE). */
        outb(0xaa, port);
@@ -112,10 +112,7 @@ void probe_idregs_fintek(uint16_t port)
 
        outb(0x20, port);
        if (inb(port) != 0x20) {
-               if (inb(port) == 0xff)
-                       printf("No Super I/O chip found at 0x%04x\n", port);
-               else
-                       printf("Probing 0x%04x, failed (0x%02x), data returns 0x%02x\n", port, inb(port), inb(port + 1));
+               no_superio_found(port);
                return;
        }
        did = inb(port + 1);
index 8b0fc53b4b66e68a041bc2218e89cf5db6b29988..e042fb78622c894524c63e7d28dfe98c5ea47bb4 100644 (file)
@@ -211,7 +211,7 @@ void dump_ite(uint16_t port, uint16_t id)
        }
 }
 
-void enter_conf_mode_ite(uint16_t port)
+static void enter_conf_mode_ite(uint16_t port)
 {
        /* Enable configuration sequence (ITE uses this for newer IT87[012]x)
         * IT871[01] uses 0x87, 0x87 -> fintek detection should handle it
@@ -230,7 +230,7 @@ void enter_conf_mode_ite(uint16_t port)
                outb(0xAA, port);
 }
 
-void exit_conf_mode_ite(uint16_t port)
+static void exit_conf_mode_ite(uint16_t port)
 {
        regwrite(port, 0x02, 0x02);
 }
@@ -244,10 +244,7 @@ void probe_idregs_ite(uint16_t port)
        /* Read Chip ID Byte 1. */
        id = regval(port, 0x20);
        if (id != 0x87) {
-               if (inb(port) == 0xff)
-                       printf("No Super I/O chip found at 0x%04x\n", port);
-               else
-                       printf("Probing 0x%04x, failed (0x%02x), data returns 0x%02x\n", port, inb(port), inb(port + 1));
+               no_superio_found(port);
                return;
        }
 
@@ -262,7 +259,8 @@ void probe_idregs_ite(uint16_t port)
        printf("Super I/O found at 0x%02x: id=0x%04x, chipver=0x%01x\n",
               port, id, chipver);
 
-       dump_ite(port, id);
+       if (dump)
+               dump_ite(port, id);
 
        exit_conf_mode_ite(port);
 }
index 691ce13967ea1af4e7a6dc9e234a11d13fd1b45b..c308256e7fa28aae9affa22df7b307bb5bed7805 100644 (file)
@@ -62,10 +62,7 @@ void probe_idregs_simple(uint16_t port)
 
        outb(0x20, port);
        if (inb(port) != 0x20) {
-               if (inb(port) == 0xff)
-                       printf("No Super I/O chip found at 0x%04x\n", port);
-               else
-                       printf("Probing 0x%04x, failed (0x%02x), data returns 0x%02x\n", port, inb(port), inb(port + 1));
+               no_superio_found(port);
                return;
        }
        id = inb(port + 1);
index e583471bac97f0e3686641a54d7d59231edfb3e0..acbb4773b04a0594a7510117cd36befa3cb9e4f7 100644 (file)
@@ -40,29 +40,16 @@ const static struct superio_registers reg_table[] = {
        {EOT}
 };
 
-void enter_conf_mode_smsc(uint16_t port)
+static void enter_conf_mode_smsc(uint16_t port)
 {
        outb(0x55, port);
 }
 
-void exit_conf_mode_smsc(uint16_t port)
+static void exit_conf_mode_smsc(uint16_t port)
 {
        outb(0xaa, port);
 }
 
-/* Note: The actual SMSC ID is 16 bits, but we must pass 32 bits here. */
-void dump_smsc(uint16_t port, uint16_t id)
-{
-       switch (id) {
-       case 0x28:
-               dump_superio("SMSC", reg_table, port, id);
-               break;
-       default:
-               printf("Unknown SMSC chip, id=0x%02x\n", id);
-               break;
-       }
-}
-
 void probe_idregs_smsc(uint16_t port)
 {
        uint16_t id, rev;
@@ -72,20 +59,18 @@ void probe_idregs_smsc(uint16_t port)
        /* Read device ID. */
        id = regval(port, DEVICE_ID_REG);
        if (id != 0x28) {       /* TODO: Support for other SMSC chips. */
-               if (inb(port) != 0xff)
-                       printf("No Super I/O chip found at 0x%04x\n", port);
-               else
-                       printf("Probing 0x%04x, failed (0x%02x), data returns 0x%02x\n", port, inb(port), inb(port + 1));
+               no_superio_found(port);
                return;
        }
 
        /* Read chip revision. */
        rev = regval(port, DEVICE_REV_REG);
 
-       printf("Super I/O found at 0x%04x: id=0x%02x, rev=0x%02x\n",
-              port, id, rev);
+       printf("Found SMSC %s Super I/O (id=0x%02x, rev=0x%02x) at port=0x%04x\n",
+              get_superio_name(reg_table, id), id, rev, port);
 
-       dump_smsc(port, id );
+       if (dump)
+               dump_superio("SMSC", reg_table, port, id);
 
        exit_conf_mode_smsc(port);
 }
index fd49c309eef86a90156a36d6025bc54612f7a805..de512486e608ba202faeaea7c2b7a68e30dea860 100644 (file)
@@ -22,6 +22,9 @@
 
 #include "superiotool.h"
 
+/* Command line options. */
+int dump = 0, verbose = 0;
+
 uint8_t regval(uint16_t port, uint8_t reg)
 {
        outb(reg, port);
@@ -34,6 +37,24 @@ void regwrite(uint16_t port, uint8_t reg, uint8_t val)
        outb(val, port + 1);
 }
 
+const char *get_superio_name(const struct superio_registers reg_table[],
+                            uint16_t id)
+{
+       int i;
+
+       for (i = 0; /* Nothing */; i++) {
+               if (reg_table[i].superio_id == EOT)
+                       break;
+
+               if ((uint16_t)reg_table[i].superio_id != id)
+                       continue;
+
+               return reg_table[i].name;
+       }
+
+       return "<unknown>";
+}
+
 void dump_superio(const char *vendor, const struct superio_registers reg_table[],
                  uint16_t port, uint16_t id)
 {
@@ -53,7 +74,6 @@ void dump_superio(const char *vendor, const struct superio_registers reg_table[]
                        if (reg_table[i].ldn[j].ldn == EOT)
                                break;
 
-                       printf("%s %s\n", vendor, reg_table[i].name);
                        nodump = 0;
 
                        if (reg_table[i].ldn[j].ldn != NOLDN) {
@@ -98,9 +118,51 @@ void dump_superio(const char *vendor, const struct superio_registers reg_table[]
        }
 }
 
+void no_superio_found(uint16_t port) {
+       if (!verbose)
+               return;
+
+       if (inb(port) == 0xff)
+               printf("No Super I/O chip found at 0x%04x\n", port);
+       else
+               printf("Probing 0x%04x, failed (0x%02x), data returns 0x%02x\n", port, inb(port), inb(port + 1));
+}
+
 int main(int argc, char *argv[])
 {
-       int i, j;
+       int i, j, opt, option_index;
+
+       const static struct option long_options[] = {
+               {"dump",        no_argument, NULL, 'd'},
+               {"verbose",     no_argument, NULL, 'V'},
+               {"version",     no_argument, NULL, 'v'},
+               {"help",        no_argument, NULL, 'h'},
+               {0, 0, 0, 0}
+       };
+
+       while ((opt = getopt_long(argc, argv, "dVvh",
+                                 long_options, &option_index)) != EOF) {
+               switch (opt) {
+               case 'd':
+                       dump = 1;
+                       break;
+               case 'V':
+                       verbose = 1;
+                       break;
+               case 'v':
+                       printf("superiotool %s\n", SUPERIOTOOL_VERSION);
+                       exit(0);
+                       break;
+               case 'h':
+                       printf("Usage: superiotool [-d] [-V] [-v] [-h]\n");
+                       exit(0);
+                       break;
+               default:
+                       /* Unknown option. */
+                       exit(1);
+                       break;
+               }
+       }
 
        if (iopl(3) < 0) {
                perror("iopl");
index 0dcc2fa261cd30f19fa7f21b11c8f6d07f4576ee..bcd8d5c2ffc9765d074a169b3caa92ca072fd5ff 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
+#include <getopt.h>
 #include <sys/io.h>
 
+#define SUPERIOTOOL_VERSION "0.1"
+
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
 
 #define EOT            -1              /* End Of Table */
@@ -40,6 +43,9 @@
 #define IDXSIZE        (MAXNUMIDX + 1)
 #define MAXNUMPORTS    (2 + 1)         /* Maximum number of Super I/O ports */
 
+/* Command line parameters. */
+extern int dump, verbose;
+
 struct superio_registers {
        int32_t superio_id; /* Signed, as we need EOT. */
        const char name[MAXNAMELEN];
@@ -53,19 +59,17 @@ struct superio_registers {
 /* superiotool.c */
 uint8_t regval(uint16_t port, uint8_t reg);
 void regwrite(uint16_t port, uint8_t reg, uint8_t val);
+const char *get_superio_name(const struct superio_registers reg_table[],
+                            uint16_t id);
 void dump_superio(const char *name, const struct superio_registers reg_table[],
                  uint16_t port, uint16_t id);
-void probe_superio(uint16_t port);
+void no_superio_found(uint16_t port);
 
 /* fintek.c */
-void enter_conf_mode_fintek(uint16_t port);
-void exit_conf_mode_fintek(uint16_t port);
 void dump_fintek(uint16_t port, uint16_t did);
 void probe_idregs_fintek(uint16_t port);
 
 /* ite.c */
-void enter_conf_mode_ite(uint16_t port);
-void exit_conf_mode_ite(uint16_t port);
 void dump_ite(uint16_t port, uint16_t id);
 void probe_idregs_ite(uint16_t port);
 
@@ -74,9 +78,6 @@ void dump_ns8374(uint16_t port);
 void probe_idregs_simple(uint16_t port);
 
 /* smsc.c */
-void enter_conf_mode_smsc(uint16_t port);
-void exit_conf_mode_smsc(uint16_t port);
-void dump_smsc(uint16_t port, uint16_t id);
 void probe_idregs_smsc(uint16_t port);
 
 /** Table of which config ports to probe on each Super I/O. */