This patch adds a driver for the GPIO part of the milkymist sysctl unit.
Signed-off-by: Lars-Peter Clausen <[email protected]>
---
arch/lm32/Kconfig | 4 ++
arch/lm32/include/asm/gpio.h | 16 ++++++++
arch/lm32/kernel/Makefile | 2 +-
arch/lm32/kernel/gpio.c | 82 ++++++++++++++++++++++++++++++++++++++++++
4 files changed, 103 insertions(+), 1 deletions(-)
create mode 100644 arch/lm32/include/asm/gpio.h
create mode 100644 arch/lm32/kernel/gpio.c
diff --git a/arch/lm32/Kconfig b/arch/lm32/Kconfig
index 0563647..dbc20c9 100644
--- a/arch/lm32/Kconfig
+++ b/arch/lm32/Kconfig
@@ -4,6 +4,10 @@ config LM32
select CPU_MICO32
select HAVE_GENERIC_HARDIRQS
select GENERIC_HARDIRQS_NO_DEPRECATED
+ select ARCH_REQUIRE_GPIOLIB
+
+config GENERIC_GPIO
+ bool
config MMU
bool
diff --git a/arch/lm32/include/asm/gpio.h b/arch/lm32/include/asm/gpio.h
new file mode 100644
index 0000000..a7fb09c
--- /dev/null
+++ b/arch/lm32/include/asm/gpio.h
@@ -0,0 +1,16 @@
+#ifndef __ASM_GPIO_H__
+#define __ASM_GPIO_H__
+
+#include <linux/errno.h>
+
+#define gpio_get_value __gpio_get_value
+#define gpio_set_value __gpio_set_value
+#define gpio_cansleep __gpio_cansleep
+#define gpio_to_irq __gpio_to_irq
+
+static inline int irq_to_gpio(unsigned irq) { return -EINVAL; }
+
+
+#include <asm-generic/gpio.h>
+
+#endif
diff --git a/arch/lm32/kernel/Makefile b/arch/lm32/kernel/Makefile
index 6b94d3f..43e53e2 100644
--- a/arch/lm32/kernel/Makefile
+++ b/arch/lm32/kernel/Makefile
@@ -5,7 +5,7 @@
extra-y := head.o init_task.o vmlinux.lds
obj-y += sys_lm32.o setup.o traps.o signal.o \
- time.o ptrace.o irq.o process.o entry.o dma.o
+ time.o ptrace.o irq.o process.o entry.o dma.o gpio.o
obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
obj-$(CONFIG_MODULES) += module.o
diff --git a/arch/lm32/kernel/gpio.c b/arch/lm32/kernel/gpio.c
new file mode 100644
index 0000000..1defa09
--- /dev/null
+++ b/arch/lm32/kernel/gpio.c
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2011, Lars-Peter Clausen <[email protected]>
+ * GPIO driver for the Milkymist sysctl
+ *
+ * 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.
+ *
+ * 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.
+ *
+ */
+
+#include <linux/gpio.h>
+#include <linux/init.h>
+#include <linux/types.h>
+#include <linux/io.h>
+
+#include <asm/hw/sysctl.h>
+
+#define MILKYMIST_GPIO_NR_INPUTS 8
+#define MILKYMIST_GPIO_NR_OUTPUTS 8
+
+static int milkymist_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
+{
+ uint32_t mask = BIT(gpio);
+
+ return !!(ioread32be(CSR_GPIO_IN) & mask);
+}
+
+static void milkymist_gpio_set_value(struct gpio_chip *chip, unsigned gpio,
+ int value)
+{
+ uint32_t mask;
+ uint32_t reg;
+
+ gpio -= MILKYMIST_GPIO_NR_INPUTS;
+ mask = BIT(gpio);
+
+ reg = ioread32be(CSR_GPIO_OUT);
+
+ if (value)
+ reg |= mask;
+ else
+ reg &= ~mask;
+
+ iowrite32be(reg, CSR_GPIO_OUT);
+}
+
+static int milkymist_gpio_direction_input(struct gpio_chip *chip, unsigned
gpio)
+{
+ if (gpio >= MILKYMIST_GPIO_NR_INPUTS)
+ return -EINVAL;
+ return 0;
+}
+
+static int milkymist_gpio_direction_output(struct gpio_chip *chip,
+ unsigned gpio, int value)
+{
+ if (gpio < MILKYMIST_GPIO_NR_INPUTS)
+ return -EINVAL;
+
+ milkymist_gpio_set_value(chip, gpio, value);
+ return 0;
+}
+
+static struct gpio_chip milkymist_gpio_chip = {
+ .direction_input = milkymist_gpio_direction_input,
+ .direction_output = milkymist_gpio_direction_output,
+ .get = milkymist_gpio_get_value,
+ .set = milkymist_gpio_set_value,
+ .ngpio = MILKYMIST_GPIO_NR_INPUTS + MILKYMIST_GPIO_NR_OUTPUTS,
+};
+
+static int milkymist_gpio_init(void)
+{
+ gpiochip_add(&milkymist_gpio_chip);
+ return 0;
+}
+arch_initcall(milkymist_gpio_init);
--
1.7.2.3
_______________________________________________
http://lists.milkymist.org/listinfo.cgi/devel-milkymist.org
IRC: #milkymist@Freenode
Twitter: www.twitter.com/milkymistvj
Ideas? http://milkymist.uservoice.com