[coreboot-gerrit] New patch to review for coreboot: 064ed26 util/intelgpio: Handy tool to build gpio.h from dumped values
Edward O'Callaghan (eocallaghan@alterapraxis.com)
gerrit at coreboot.org
Mon Aug 25 16:13:46 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 064ed26052797e97e421767880f63ed70f366f05
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..
Change-Id: I2812a3546849347567efe71c714fefe39e02e5d7
Signed-off-by: Edward O'Callaghan <eocallaghan at alterapraxis.com>
---
util/intelgpio/Makefile | 47 ++++++++++++++++
util/intelgpio/intelgpio.c | 131 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 178 insertions(+)
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..a73965f
--- /dev/null
+++ b/util/intelgpio/intelgpio.c
@@ -0,0 +1,131 @@
+/*
+ * inteltool - Prepare gpio.h file from register dumps from inteltool.
+ *
+ * Copyright (C) 2014 Edward O'Callaghan <eocallaghan at alterapraxis.com>
+ * Copyright (C) 2014 Nicolas Reinecke <nr at das-labor.org>
+ *
+ * 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", "dir"};
+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");
+ printf("\t\t Copyright (C) 2014 Nicolas Reinecke.\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?sa]\n", name);
+ printf("\n"
+ " -v | --version: print the version\n"
+ " -h | --help: print this help\n\n"
+ " -s | --set: GPIO register set\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;
+ printf("const struct pch_gpio_set%i pch_gpio_set%i_%s = {\n", set, set, type[2]);
+ for (i = 0; i < 32; i++)
+ printf("\t.gpio%i%c = GPIO_%s,\n", ((set - 1 ) * 32 + i), (((set - 1 ) * 32 ) + i < 10 ? ' ': '\0'), type[(gpioval >> i) & 1]);
+ printf("}\n\n");
+}
+
+static void write_gpio_header(int set)
+{
+ print_gpio_config(mode, set, 0x3962a5ff);
+ print_gpio_config(dir, set, 0x8ebf6aff);
+ print_gpio_config(level, set, 0x66957f3b);
+ if (set == 1)
+ print_gpio_config(invert, set, 0x00002082);
+}
+
+int main(int argc, char *argv[])
+{
+ int opt, option_index = 0;
+ int dump_set = 0, dump_all_sets = 0;
+
+ static struct option long_options[] = {
+ {"version", no_argument, 0, 'v'},
+ {"help", no_argument, 0, 'h'},
+ {"set", required_argument, 0, 's'},
+ {"all", 0, 0, 'a'},
+ {0, 0, 0, 0}
+ };
+
+ while ((opt = getopt_long(argc, argv, "vh?sa",
+ long_options, &option_index)) != EOF) {
+ switch (opt) {
+ case 'v':
+ print_version();
+ exit(0);
+ break;
+ case 's':
+ dump_set = atoi(optarg);
+ break;
+ case 'a':
+ dump_all_sets = 1;
+ break;
+ case 'h':
+ case '?':
+ default:
+ print_usage(argv[0]);
+ exit(0);
+ break;
+ }
+ }
+
+
+ if (dump_all_sets) {
+ write_gpio_header(1);
+ write_gpio_header(2);
+ write_gpio_header(3);
+ }
+
+ if (!((dump_set < 1) || (dump_set > 3))) {
+ write_gpio_header(dump_set);
+ } else {
+ print_usage(argv[0]);
+ exit(0);
+ }
+
+ return 0;
+}
More information about the coreboot-gerrit
mailing list