[coreboot-gerrit] Patch set updated for coreboot: 7c6d7e1 util/intelgpio: Handy tool to build gpio.h from dumped values
Edward O'Callaghan (eocallaghan@alterapraxis.com)
gerrit at coreboot.org
Mon Aug 25 18:42:29 CEST 2014
Edward O'Callaghan (eocallaghan at alterapraxis.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/6762
-gerrit
commit 7c6d7e10ae398e1634d39c58174120c8b55a82e8
Author: Edward O'Callaghan <eocallaghan at alterapraxis.com>
Date: Tue Aug 26 00:12:03 2014 +1000
util/intelgpio: Handy tool to build gpio.h from dumped values
This purpose of this tool is to build the 'gpio.h' header from dumped
values out of the inteltool.
NOTFORMERGE: incomplete.. RFC
Change-Id: I2812a3546849347567efe71c714fefe39e02e5d7
Signed-off-by: Edward O'Callaghan <eocallaghan at alterapraxis.com>
---
.gitignore | 1 +
util/intelgpio/Makefile | 47 +++++++++++++
util/intelgpio/intelgpio.c | 162 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 210 insertions(+)
diff --git a/.gitignore b/.gitignore
index 203ad9a..0a05520 100644
--- a/.gitignore
+++ b/.gitignore
@@ -71,6 +71,7 @@ util/ifdtool/ifdtool
util/ifdfake/ifdfake
util/inteltool/.dependencies
util/inteltool/inteltool
+util/intelgpio/intelgpio
util/k8resdump/k8resdump
util/lbtdump/lbtdump
util/mptable/mptable
diff --git a/util/intelgpio/Makefile b/util/intelgpio/Makefile
new file mode 100644
index 0000000..6347bfc
--- /dev/null
+++ b/util/intelgpio/Makefile
@@ -0,0 +1,47 @@
+#
+# Makefile for intelgpio utility
+#
+# Copyright (C) 2014 Edward O'Callaghan <eocallaghan at alterapraxis.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+
+PROGRAM = intelgpio
+
+CC ?= clang
+INSTALL ?= /usr/bin/install
+PREFIX ?= /usr/local
+CFLAGS ?= -O2 -g -Wall -W
+LDFLAGS +=
+
+OBJS = intelgpio.o
+
+all: $(PROGRAM)
+
+$(PROGRAM): $(OBJS)
+ $(CC) $(CFLAGS) -o $(PROGRAM) $(OBJS) $(LDFLAGS)
+
+clean:
+ rm -f $(PROGRAM) *.o *~
+
+install: $(PROGRAM)
+ mkdir -p $(DESTDIR)$(PREFIX)/sbin
+ $(INSTALL) $(PROGRAM) $(DESTDIR)$(PREFIX)/sbin
+ mkdir -p $(DESTDIR)$(PREFIX)/share/man/man8
+ $(INSTALL) -p -m644 $(PROGRAM).8 $(DESTDIR)$(PREFIX)/share/man/man8
+
+.PHONY: all clean
+
+-include .dependencies
diff --git a/util/intelgpio/intelgpio.c b/util/intelgpio/intelgpio.c
new file mode 100644
index 0000000..c5aad77
--- /dev/null
+++ b/util/intelgpio/intelgpio.c
@@ -0,0 +1,162 @@
+/*
+ * inteltool - Prepare gpio.h file from register dumps from inteltool.
+ *
+ * Copyright (C) 2014 Edward O'Callaghan <eocallaghan at alterapraxis.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#define INTELGPIO_VERSION "0.1"
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <getopt.h>
+
+static const __attribute__((unused)) char *mode[] = {"MODE_NATIVE", "MODE_GPIO", "mode"};
+static const __attribute__((unused)) char *dir[] = {"DIR_OUTPUT", "DIR_INPUT", "direction"};
+static const __attribute__((unused)) char *invert[] = {"NO_INVERT", "GPIO_INVERT", "invert"};
+static const __attribute__((unused)) char *level[] = {"LEVEL_LOW", "LEVEL_HIGH", "level"};
+static const __attribute__((unused)) char *blink[] = {"NO_BLINK", "BLINK", "blink"};
+static const __attribute__((unused)) char *reset[] = {"RESET_PWROK", "RESET_RSMRST", "reset"};
+
+static void print_version(void)
+{
+ printf("intelgpio v%s -- ", INTELGPIO_VERSION);
+ printf("Copyright (C) 2014 Edward O'Callaghan\n\n");
+ printf(
+ "This program is free software: you can redistribute it and/or modify\n"
+ "it under the terms of the GNU General Public License as published by\n"
+ "the Free Software Foundation, version 2 of the License.\n\n"
+ "This program is distributed in the hope that it will be useful,\n"
+ "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
+ "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
+ "GNU General Public License for more details.\n\n"
+ "You should have received a copy of the GNU General Public License\n"
+ "along with this program. If not, see <http://www.gnu.org/licenses/>.\n\n");
+}
+
+static void print_usage(const char *name)
+{
+ printf("usage: %s [-vh?sdmlia]\n", name);
+ printf("\n"
+ " -v | --version: print the version\n"
+ " -h | --help: print this help\n\n"
+ " -s | --set= GPIO register set\n"
+ " -d | --direction= direction val\n"
+ " -m | --mode= mode val\n"
+ " -l | --level= level val\n"
+ " -i | --invert= invert val\n"
+ " -a | --all: all register sets 1,2,3\n"
+ "\n");
+ exit(1);
+}
+
+static void print_gpio_config(const char *type[], uint8_t set, uint32_t gpioval) {
+ unsigned int i;
+ uint8_t pin;
+// char pin_flag;
+
+ printf("const struct pch_gpio_set%i pch_gpio_set%i_%s = {\n", set, set, type[2]);
+ for (i = 0; i < 32; i++) {
+ pin = ((set - 1) * 32 + i);
+// pin_flag = (pin < 10 ? ' ': '\0');
+// printf("\t.gpio%i%c = GPIO_%s,\n", pin, pin_flag
+ printf("\t.gpio%i = GPIO_%s,\n", pin
+ , type[(gpioval >> i) & 1]);
+ }
+ printf("};\n\n");
+}
+
+// TODO write to file.. or keep as stdout???
+static void write_gpio_header(uint8_t set, uint32_t mv, uint32_t dv, uint32_t lv, uint32_t iv)
+{
+ // TODO: check bounds on mode, dir, level & invert for sane values??
+ print_gpio_config(mode, set, mv);
+ print_gpio_config(dir, set, dv);
+ print_gpio_config(level, set, lv);
+ if (set == 1)
+ print_gpio_config(invert, set, iv);
+}
+
+int main(int argc, char *argv[])
+{
+ int opt, option_index = 0;
+ uint8_t dump_set = 0, dump_all_sets = 0;
+ uint32_t direction = 0, mode = 0, level = 0, invert = 0;
+
+ static struct option long_options[] = {
+ {"version", no_argument, 0, 'v'},
+ {"help", no_argument, 0, 'h'},
+ {"set", required_argument, 0, 's'},
+ {"direction", required_argument, 0, 'd'},
+ {"mode", required_argument, 0, 'm'},
+ {"level", required_argument, 0, 'l'},
+ {"invert", required_argument, 0, 'i'},
+ {"all", 0, 0, 'a'},
+ {0, 0, 0, 0}
+ };
+
+ while ((opt = getopt_long(argc, argv, "vh?s:d:m:l:i:a",
+ long_options, &option_index)) != EOF) {
+ switch (opt) {
+ case 'v':
+ print_version();
+ exit(0);
+ break;
+ case 's':
+ dump_set = atoi(optarg);
+ break;
+ case 'd':
+ direction = strtol(optarg, NULL, 16);
+ break;
+ case 'm':
+ mode = strtol(optarg, NULL, 16);
+ break;
+ case 'l':
+ level = strtol(optarg, NULL, 16);
+ break;
+ case 'i':
+ invert = strtol(optarg, NULL, 16);
+ break;
+ case 'a':
+ dump_all_sets = 1;
+ break;
+ case 'h':
+ case '?':
+ default:
+ print_usage(argv[0]);
+ exit(0);
+ break;
+ }
+ }
+
+// FIXME: do this properly.. should also print out the struct packing at
+// the end of gpio.h also while in the 'all' mode of operation..
+ if (dump_all_sets) {
+ write_gpio_header(1, mode, direction, level, invert);
+ write_gpio_header(2, mode, direction, level, invert);
+ write_gpio_header(3, mode, direction, level, invert);
+ }
+
+// FIXME: check if mode, direction, level and invert were /all/ set..
+ if (!((dump_set < 1) || (dump_set > 3))) {
+ write_gpio_header(dump_set, mode, direction, level, invert);
+ } else {
+ print_usage(argv[0]);
+ exit(0);
+ }
+
+ return 0;
+}
More information about the coreboot-gerrit
mailing list