summaryrefslogtreecommitdiff
path: root/board/cm-bf527/gpio.c
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2008-10-12 21:55:45 -0400
committerMike Frysinger <vapier@gentoo.org>2009-06-14 20:01:07 -0400
commit59e4be945b6469e31eee721e0bcdccf4940d75ac (patch)
tree13f7b85092f396d302efe47553e5955c75975231 /board/cm-bf527/gpio.c
parent8b219cf07c186cc9d97354cf4b14f24a53d193c5 (diff)
downloadu-boot-imx-59e4be945b6469e31eee721e0bcdccf4940d75ac.zip
u-boot-imx-59e4be945b6469e31eee721e0bcdccf4940d75ac.tar.gz
u-boot-imx-59e4be945b6469e31eee721e0bcdccf4940d75ac.tar.bz2
Blackfin: cm-bf527: new board port
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'board/cm-bf527/gpio.c')
-rw-r--r--board/cm-bf527/gpio.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/board/cm-bf527/gpio.c b/board/cm-bf527/gpio.c
new file mode 100644
index 0000000..dcf641b
--- /dev/null
+++ b/board/cm-bf527/gpio.c
@@ -0,0 +1,74 @@
+/*
+ * Control GPIO pins on the fly
+ *
+ * Copyright (c) 2008 Analog Devices Inc.
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+#include <common.h>
+#include <command.h>
+
+#include <asm/blackfin.h>
+
+int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+ if (argc != 3) {
+ show_usage:
+ printf("Usage:\n%s\n", cmdtp->usage);
+ return 1;
+ }
+
+ /* parse the behavior */
+ ulong port_cmd = 0;
+ switch (argv[1][0]) {
+ case 'i': break;
+ case 's': port_cmd = (PORTFIO_SET - PORTFIO); break;
+ case 'c': port_cmd = (PORTFIO_CLEAR - PORTFIO); break;
+ case 't': port_cmd = (PORTFIO_TOGGLE - PORTFIO); break;
+ default: goto show_usage;
+ }
+
+ /* parse the pin with format: [p]<fgh><#> */
+ const char *str_pin = argv[2];
+
+ /* grab the [p]<fgh> portion */
+ ulong port_base;
+ if (*str_pin == 'p') ++str_pin;
+ switch (*str_pin) {
+ case 'f': port_base = PORTFIO; break;
+ case 'g': port_base = PORTGIO; break;
+ case 'h': port_base = PORTHIO; break;
+ default: goto show_usage;
+ }
+
+ /* grab the <#> portion */
+ ulong pin = simple_strtoul(str_pin+1, NULL, 10);
+ ulong pin_mask = (1 << pin);
+ if (pin > 15)
+ goto show_usage;
+
+ /* finally, let's do it: set direction and exec command */
+ switch (*str_pin) {
+ case 'f': bfin_write_PORTF_FER(bfin_read_PORTF_FER() & ~pin_mask); break;
+ case 'g': bfin_write_PORTG_FER(bfin_read_PORTG_FER() & ~pin_mask); break;
+ case 'h': bfin_write_PORTH_FER(bfin_read_PORTH_FER() & ~pin_mask); break;
+ }
+
+ ulong port_dir = port_base + (PORTFIO_DIR - PORTFIO);
+ if (argv[1][0] == 'i')
+ bfin_write16(port_dir, bfin_read16(port_dir) & ~pin_mask);
+ else {
+ bfin_write16(port_dir, bfin_read16(port_dir) | pin_mask);
+ bfin_write16(port_base + port_cmd, pin_mask);
+ }
+
+ printf("gpio: pin %li on port %c has been %c\n", pin, *str_pin, argv[1][0]);
+
+ return 0;
+}
+
+U_BOOT_CMD(gpio, 3, 0, do_gpio,
+ "gpio - set/clear/toggle gpio output pins\n",
+ "<s|c|t> <port><pin>\n"
+ " - set/clear/toggle the specified pin\n");