public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
[parent not found: <2088605993.55298.1312607122087.JavaMail.root@ahm.einfochips.com>]
[parent not found: <1990439524.39318.1312346163802.JavaMail.root@ahm.einfochips.com>]
* [U-Boot] [PATCH v2 1/2] gpio: Add GPIO driver framework for Marvell SoCs
@ 2011-07-22  7:16 Ajay Bhargav
  2011-08-02 14:10 ` Simon Guinot
  0 siblings, 1 reply; 12+ messages in thread
From: Ajay Bhargav @ 2011-07-22  7:16 UTC (permalink / raw)
  To: u-boot

This patch adds generic GPIO driver framework support for Marvell SoCs.

To enable GPIO driver define CONFIG_MARVELL_GPIO and for GPIO commands
define CONFIG_CMD_GPIO in your board configuration file.

Signed-off-by: Ajay Bhargav <ajay.bhargav@einfochips.com>
---
 drivers/gpio/Makefile |    1 +
 drivers/gpio/mvgpio.c |  114 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 115 insertions(+), 0 deletions(-)
 create mode 100644 drivers/gpio/mvgpio.c

diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 62ec97d..beca1da 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -27,6 +27,7 @@ LIB 	:= $(obj)libgpio.o
 
 COBJS-$(CONFIG_AT91_GPIO)	+= at91_gpio.o
 COBJS-$(CONFIG_KIRKWOOD_GPIO)	+= kw_gpio.o
+COBJS-$(CONFIG_MARVELL_GPIO)	+= mvgpio.o
 COBJS-$(CONFIG_MARVELL_MFP)	+= mvmfp.o
 COBJS-$(CONFIG_MXC_GPIO)	+= mxc_gpio.o
 COBJS-$(CONFIG_PCA953X)		+= pca953x.o
diff --git a/drivers/gpio/mvgpio.c b/drivers/gpio/mvgpio.c
new file mode 100644
index 0000000..0cc8ed7
--- /dev/null
+++ b/drivers/gpio/mvgpio.c
@@ -0,0 +1,114 @@
+/*
+ * (C) Copyright 2011
+ * eInfochips Ltd. <www.einfochips.com>
+ * Written-by: Ajay Bhargav <ajay.bhargav@einfochips.com>
+ *
+ * (C) Copyright 2010
+ * Marvell Semiconductor <www.marvell.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301 USA
+ */
+
+#include <common.h>
+#include <asm/io.h>
+#include <asm/errno.h>
+#include <asm/gpio.h>
+
+#ifndef MV_MAX_GPIO
+#define MV_MAX_GPIO	128
+#endif
+
+int gpio_request(int gp, const char *label)
+{
+	if (gp >= MV_MAX_GPIO) {
+		printf("%s: Invalid GPIO requested %d\n", __func__, gp);
+		return -EINVAL;
+	}
+	return 0;
+}
+
+void gpio_free(int gp)
+{
+}
+
+void gpio_toggle_value(int gp)
+{
+	gpio_set_value(gp, !gpio_get_value(gp));
+}
+
+int gpio_direction_input(int gp)
+{
+	struct gpio_reg *gpio_reg_bank;
+
+	if (gp >= MV_MAX_GPIO) {
+		printf("%s: Invalid GPIO %d\n", __func__, gp);
+		return -EINVAL;
+	}
+
+	gpio_reg_bank = get_gpio_base(GPIO_TO_REG(gp));
+	writel(GPIO_TO_BIT(gp), &gpio_reg_bank->gcdr);
+	return 0;
+}
+
+int gpio_direction_output(int gp, int value)
+{
+	struct gpio_reg *gpio_reg_bank;
+
+	if (gp >= MV_MAX_GPIO) {
+		printf("%s: Invalid GPIO %d\n", __func__, gp);
+		return -EINVAL;
+	}
+
+	gpio_reg_bank = get_gpio_base(GPIO_TO_REG(gp));
+	writel(GPIO_TO_BIT(gp), &gpio_reg_bank->gsdr);
+	gpio_set_value(gp, value);
+	return 0;
+}
+
+int gpio_get_value(int gp)
+{
+	struct gpio_reg *gpio_reg_bank;
+	u32 gp_val;
+
+	if (gp >= MV_MAX_GPIO) {
+		printf("%s: Invalid GPIO %d\n", __func__, gp);
+		return -EINVAL;
+	}
+
+	gpio_reg_bank = get_gpio_base(GPIO_TO_REG(gp));
+	gp_val = readl(&gpio_reg_bank->gplr);
+
+	return GPIO_VAL(gp, gp_val);
+}
+
+void gpio_set_value(int gp, int value)
+{
+	struct gpio_reg *gpio_reg_bank;
+
+	if (gp >= MV_MAX_GPIO) {
+		printf("%s: Invalid GPIO %d\n", __func__, gp);
+		return;
+	}
+
+	gpio_reg_bank = get_gpio_base(GPIO_TO_REG(gp));
+	if (value)
+		writel(GPIO_TO_BIT(gp),	&gpio_reg_bank->gpsr);
+	else
+		writel(GPIO_TO_BIT(gp),	&gpio_reg_bank->gpcr);
+}
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2011-08-07  2:16 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1874826476.47235.1312454749903.JavaMail.root@ahm.einfochips.com>
2011-08-04 10:51 ` [U-Boot] [PATCH v2 1/2] gpio: Add GPIO driver framework for Marvell SoCs Ajay Bhargav
2011-08-04 11:25   ` Prafulla Wadaskar
2011-08-04 12:51   ` Lei Wen
     [not found] <2088605993.55298.1312607122087.JavaMail.root@ahm.einfochips.com>
2011-08-06  5:10 ` Ajay Bhargav
2011-08-07  2:16   ` Prafulla Wadaskar
     [not found] <1990439524.39318.1312346163802.JavaMail.root@ahm.einfochips.com>
2011-08-03  4:40 ` Ajay Bhargav
2011-08-04  0:04   ` Simon Guinot
2011-08-04  8:51     ` Albert ARIBAUD
2011-08-04  9:18       ` Lei Wen
2011-07-22  7:16 Ajay Bhargav
2011-08-02 14:10 ` Simon Guinot
2011-08-03 10:18   ` Prafulla Wadaskar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox