From: Sanjeev Premi <premi@ti.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC 1/3] omap: gpio: Use generic API
Date: Wed, 31 Aug 2011 01:22:32 +0530 [thread overview]
Message-ID: <1314733954-29576-2-git-send-email-premi@ti.com> (raw)
In-Reply-To: <1314733954-29576-1-git-send-email-premi@ti.com>
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 --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_ */
--
1.7.0.4
next prev parent reply other threads:[~2011-08-30 19:52 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-30 19:52 [U-Boot] [RFC 0/3] omap: gpio: User generic (instead of custom) API Sanjeev Premi
2011-08-30 19:52 ` Sanjeev Premi [this message]
2011-08-30 19:52 ` [U-Boot] [RFC 2/3] omap: gpio: generic changes after changing API Sanjeev Premi
2011-08-30 19:52 ` [U-Boot] [PATCH 3/3] omap: gpio: Adapt board files to use generic API Sanjeev Premi
2011-08-30 19:55 ` Premi, Sanjeev
2011-09-01 16:48 ` [U-Boot] [RFC 0/3] omap: gpio: User generic (instead of custom) API Luca Ceresoli
2011-09-02 13:15 ` Premi, Sanjeev
2011-09-02 5:50 ` Premi, Sanjeev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1314733954-29576-2-git-send-email-premi@ti.com \
--to=premi@ti.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox