]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
nios2: add gpio support to nios2-generic board
authorThomas Chou <thomas@wytron.com.tw>
Fri, 30 Apr 2010 03:34:15 +0000 (11:34 +0800)
committerScott McNutt <smcnutt@psyent.com>
Fri, 28 May 2010 14:56:03 +0000 (10:56 -0400)
This patch adds gpio support of Altera PIO component to the
nios2-generic board. Though it drives only gpio_led at the
moment, it supports bidirectional port to control bit-banging
I2C, NAND flash busy status or button switches, etc.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
Tested-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Scott McNutt <smcnutt@psyent.com>
board/altera/nios2-generic/Makefile
board/altera/nios2-generic/gpio.c [new file with mode: 0644]
include/configs/nios2-generic.h

index 6780872505d1246e056a5f132c78a5f43da18383..d1fca70a0e321ca2d8351d280de75dfa523beff9 100644 (file)
@@ -32,6 +32,7 @@ LIB   = $(obj)lib$(BOARD).a
 COBJS-y        := $(BOARD).o
 COBJS-$(CONFIG_CMD_IDE) += ../common/cfide.o
 COBJS-$(CONFIG_EPLED) += ../common/epled.o
+COBJS-$(CONFIG_GPIO) += gpio.o
 COBJS-$(CONFIG_SEVENSEG) += ../common/sevenseg.o
 
 SOBJS-y        := text_base.o
diff --git a/board/altera/nios2-generic/gpio.c b/board/altera/nios2-generic/gpio.c
new file mode 100644 (file)
index 0000000..6c9c6c2
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * board gpio driver
+ *
+ * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>
+ * Licensed under the GPL-2 or later.
+ */
+#include <common.h>
+#include <asm/io.h>
+
+#ifndef CONFIG_SYS_GPIO_BASE
+
+#define ALTERA_PIO_BASE LED_PIO_BASE
+#define ALTERA_PIO_DATA (ALTERA_PIO_BASE + 0)
+#define ALTERA_PIO_DIR (ALTERA_PIO_BASE + 4)
+static u32 pio_data_reg;
+static u32 pio_dir_reg;
+
+int gpio_direction_input(unsigned gpio)
+{
+       u32 mask = 1 << gpio;
+       writel(pio_dir_reg &= ~mask, ALTERA_PIO_DIR);
+       return 0;
+}
+
+int gpio_direction_output(unsigned gpio, int value)
+{
+       u32 mask = 1 << gpio;
+       if (value)
+               pio_data_reg |= mask;
+       else
+               pio_data_reg &= ~mask;
+       writel(pio_data_reg, ALTERA_PIO_DATA);
+       writel(pio_dir_reg |= mask, ALTERA_PIO_DIR);
+       return 0;
+}
+
+int gpio_get_value(unsigned gpio)
+{
+       u32 mask = 1 << gpio;
+       if (pio_dir_reg & mask)
+               return (pio_data_reg & mask) ? 1 : 0;
+       else
+               return (readl(ALTERA_PIO_DATA) & mask) ? 1 : 0;
+}
+
+void gpio_set_value(unsigned gpio, int value)
+{
+       u32 mask = 1 << gpio;
+       if (value)
+               pio_data_reg |= mask;
+       else
+               pio_data_reg &= ~mask;
+       writel(pio_data_reg, ALTERA_PIO_DATA);
+}
+#endif
index e83e1e391e9c2ce2f1d9b0f801e318df289041eb..e4bf57b7555630238a964cef067b12e419539776 100644 (file)
  * STATUS LED
  */
 #define CONFIG_STATUS_LED              /* Enable status driver */
-#define CONFIG_EPLED                   /* Enable LED PIO driver */
-#define CONFIG_SYS_LEDPIO_ADDR         LED_PIO_BASE
+#define CONFIG_GPIO_LED                /* Enable GPIO LED driver */
+#define CONFIG_GPIO                    /* Enable GPIO driver */
 
-#define STATUS_LED_BIT                 1       /* Bit-0 on PIO */
+#define STATUS_LED_BIT                 0       /* Bit-0 on GPIO */
 #define STATUS_LED_STATE               1       /* Blinking */
 #define STATUS_LED_PERIOD      (500 / CONFIG_SYS_NIOS_TMRMS) /* 500 msec */