diff mbox

[U-Boot,RFC,1/3] omap: gpio: Use generic API

Message ID 1314733954-29576-2-git-send-email-premi@ti.com
State Superseded
Headers show

Commit Message

Sanjeev Premi Aug. 30, 2011, 7:52 p.m. UTC
Convert all OMAP specific functions to use the common API
definitions in include/asm/gpio.h. In the process, made
few additional changes:
 - Use -EINVAL consistently. -1 was used in many places.
 - Removed one-liner static functions that were used only
   once. Replaced the content as necessary.

A dummy header was created to meet the include dependency
of asm/arch/gpio.h.

Signed-off-by: Sanjeev Premi <premi@ti.com>
Cc: Sandeep Paulraj <s-paulraj@ti.com>
Cc: Igor Grinberg <grinberg@compulab.co.il>
Cc: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Enric Balletbo i Serra <eballetbo@gmail.com>
Cc: Sunil Kumar <sunilsaini05@gmail.com>
Cc: Shashi Ranjan <shashiranjanmca05@gmail.com>
Cc: Nishanth Menon <nm@ti.com>
Cc: Steve Sakoman <steve@sakoman.com>

---

 It appears that file omap_gpio.h can be renamed to gpio.h
 avoiding the need to create a dummy file, but I have to
 try this.


 arch/arm/cpu/armv7/omap-common/gpio.c  |   74 +++++++++++++++++++++++---------
 arch/arm/include/asm/arch-omap3/gpio.h |   19 ++++++++
 arch/arm/include/asm/omap_gpio.h       |   13 ------
 3 files changed, 72 insertions(+), 34 deletions(-)
 create mode 100644 arch/arm/include/asm/arch-omap3/gpio.h
diff mbox

Patch

diff --git a/arch/arm/cpu/armv7/omap-common/gpio.c b/arch/arm/cpu/armv7/omap-common/gpio.c
index f4c3479..5c584ad 100644
--- a/arch/arm/cpu/armv7/omap-common/gpio.c
+++ b/arch/arm/cpu/armv7/omap-common/gpio.c
@@ -36,9 +36,9 @@ 
  * published by the Free Software Foundation.
  */
 #include <common.h>
-#include <asm/omap_gpio.h>
 #include <asm/io.h>
 #include <asm/errno.h>
+#include <asm/omap_gpio.h>
 
 static inline const struct gpio_bank *get_gpio_bank(int gpio)
 {
@@ -53,17 +53,17 @@  static inline int get_gpio_index(int gpio)
 static inline int gpio_valid(int gpio)
 {
 	if (gpio < 0)
-		return -1;
+		return -EINVAL;
 	if (gpio < 192)
 		return 0;
-	return -1;
+	return -EINVAL;
 }
 
 static int check_gpio(int gpio)
 {
 	if (gpio_valid(gpio) < 0) {
 		printf("ERROR : check_gpio: invalid GPIO %d\n", gpio);
-		return -1;
+		return -EINVAL;
 	}
 	return 0;
 }
@@ -89,16 +89,6 @@  static void _set_gpio_direction(const struct gpio_bank *bank, int gpio,
 	__raw_writel(l, reg);
 }
 
-void omap_set_gpio_direction(int gpio, int is_input)
-{
-	const struct gpio_bank *bank;
-
-	if (check_gpio(gpio) < 0)
-		return;
-	bank = get_gpio_bank(gpio);
-	_set_gpio_direction(bank, get_gpio_index(gpio), is_input);
-}
-
 static void _set_gpio_dataout(const struct gpio_bank *bank, int gpio,
 				int enable)
 {
@@ -121,17 +111,23 @@  static void _set_gpio_dataout(const struct gpio_bank *bank, int gpio,
 	__raw_writel(l, reg);
 }
 
-void omap_set_gpio_dataout(int gpio, int enable)
+/**
+ * Set value of the specified gpio
+ */
+void gpio_set_value(int gpio, int value)
 {
 	const struct gpio_bank *bank;
 
 	if (check_gpio(gpio) < 0)
 		return;
 	bank = get_gpio_bank(gpio);
-	_set_gpio_dataout(bank, get_gpio_index(gpio), enable);
+	_set_gpio_dataout(bank, get_gpio_index(gpio), value);
 }
 
-int omap_get_gpio_datain(int gpio)
+/**
+ * Get value of the cpscified gpio
+ */
+int gpio_get_value(int gpio)
 {
 	const struct gpio_bank *bank;
 	void *reg;
@@ -151,20 +147,56 @@  int omap_get_gpio_datain(int gpio)
 			& (1 << get_gpio_index(gpio))) != 0;
 }
 
-static void _reset_gpio(const struct gpio_bank *bank, int gpio)
+/**
+ * Set gpio direction as input
+ */
+int gpio_direction_input(unsigned gpio)
 {
+	const struct gpio_bank *bank;
+
+	if (check_gpio(gpio) < 0)
+		return -EINVAL;
+
+	bank = get_gpio_bank(gpio);
 	_set_gpio_direction(bank, get_gpio_index(gpio), 1);
+
+	return 0;
 }
 
-int omap_request_gpio(int gpio)
+/**
+ * Set gpio direction as output
+ */
+int gpio_direction_output(unsigned gpio, int value)
 {
+	const struct gpio_bank *bank;
+
 	if (check_gpio(gpio) < 0)
 		return -EINVAL;
 
+	bank = get_gpio_bank(gpio);
+	_set_gpio_dataout(bank, get_gpio_index(gpio), value);
+	_set_gpio_direction(bank, get_gpio_index(gpio), 0);
+
 	return 0;
 }
 
-void omap_free_gpio(int gpio)
+/**
+ * Request a gpio before using it.
+ *
+ * NOTE: Argument 'label' is unused.
+ */
+int gpio_request(int gpio, const char *label)
+{
+	if (check_gpio(gpio) < 0)
+		return -EINVAL;
+
+	return 0;
+}
+
+/**
+ * Reset and free the gpio after using it.
+ */
+void gpio_free(unsigned gpio)
 {
 	const struct gpio_bank *bank;
 
@@ -172,5 +204,5 @@  void omap_free_gpio(int gpio)
 		return;
 	bank = get_gpio_bank(gpio);
 
-	_reset_gpio(bank, gpio);
+	_set_gpio_direction(bank, get_gpio_index(gpio), 1);
 }
diff --git a/arch/arm/include/asm/arch-omap3/gpio.h b/arch/arm/include/asm/arch-omap3/gpio.h
new file mode 100644
index 0000000..89dd824
--- /dev/null
+++ b/arch/arm/include/asm/arch-omap3/gpio.h
@@ -0,0 +1,19 @@ 
+/*
+ * Copyright (C) 2011, Texas Instruments Incorporated - http://www.ti.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 version 2.
+ *
+ * This program is distributed as is WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef _ARCH_GPIO_H_
+#define _ARCH_GPIO_H_
+
+/* Empty file required to fulfill include dependency in asm/gpio.h */
+
+#endif
diff --git a/arch/arm/include/asm/omap_gpio.h b/arch/arm/include/asm/omap_gpio.h
index 3089e1c..516cc42 100644
--- a/arch/arm/include/asm/omap_gpio.h
+++ b/arch/arm/include/asm/omap_gpio.h
@@ -49,17 +49,4 @@  extern const struct gpio_bank *const omap_gpio_bank;
 
 #define METHOD_GPIO_24XX	4
 
-/* This is the interface */
-
-/* Request a gpio before using it */
-int omap_request_gpio(int gpio);
-/* Reset and free a gpio after using it */
-void omap_free_gpio(int gpio);
-/* Sets the gpio as input or output */
-void omap_set_gpio_direction(int gpio, int is_input);
-/* Set or clear a gpio output */
-void omap_set_gpio_dataout(int gpio, int enable);
-/* Get the value of a gpio input */
-int omap_get_gpio_datain(int gpio);
-
 #endif /* _GPIO_H_ */