From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 2/9] ARM omap: rework gpio support
Date: Mon, 4 Apr 2011 15:13:56 +0200 [thread overview]
Message-ID: <1301922843-12118-3-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1301922843-12118-1-git-send-email-s.hauer@pengutronix.de>
The current gpio support is derived from the kernel which allows
for support for omap2/3/4 in a single kernel. We do not need this
here, so make it more simple to be able to add omap4 support later.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/mach-omap/gpio.c | 111 ++++++++++++--------------------
arch/arm/mach-omap/include/mach/gpio.h | 42 ------------
2 files changed, 42 insertions(+), 111 deletions(-)
diff --git a/arch/arm/mach-omap/gpio.c b/arch/arm/mach-omap/gpio.c
index 240ac8e..6b06a73 100644
--- a/arch/arm/mach-omap/gpio.c
+++ b/arch/arm/mach-omap/gpio.c
@@ -40,20 +40,27 @@
#include <asm/io.h>
#include <errno.h>
-static struct gpio_bank gpio_bank_34xx[6] = {
- { (void *)OMAP34XX_GPIO1_BASE, METHOD_GPIO_24XX },
- { (void *)OMAP34XX_GPIO2_BASE, METHOD_GPIO_24XX },
- { (void *)OMAP34XX_GPIO3_BASE, METHOD_GPIO_24XX },
- { (void *)OMAP34XX_GPIO4_BASE, METHOD_GPIO_24XX },
- { (void *)OMAP34XX_GPIO5_BASE, METHOD_GPIO_24XX },
- { (void *)OMAP34XX_GPIO6_BASE, METHOD_GPIO_24XX },
+#ifdef CONFIG_ARCH_OMAP3
+
+#define OMAP_GPIO_OE 0x0034
+#define OMAP_GPIO_DATAIN 0x0038
+#define OMAP_GPIO_DATAOUT 0x003c
+#define OMAP_GPIO_CLEARDATAOUT 0x0090
+#define OMAP_GPIO_SETDATAOUT 0x0094
+
+static void __iomem *gpio_bank[] = {
+ (void *)0x48310000,
+ (void *)0x49050000,
+ (void *)0x49052000,
+ (void *)0x49054000,
+ (void *)0x49056000,
+ (void *)0x49058000,
};
+#endif
-static struct gpio_bank *gpio_bank = &gpio_bank_34xx[0];
-
-static inline struct gpio_bank *get_gpio_bank(int gpio)
+static inline void __iomem *get_gpio_base(int gpio)
{
- return &gpio_bank[gpio >> 5];
+ return gpio_bank[gpio >> 5];
}
static inline int get_gpio_index(int gpio)
@@ -65,7 +72,7 @@ static inline int gpio_valid(int gpio)
{
if (gpio < 0)
return -1;
- if (gpio < 192)
+ if (gpio / 32 < ARRAY_SIZE(gpio_bank))
return 0;
return -1;
}
@@ -81,50 +88,35 @@ static int check_gpio(int gpio)
void gpio_set_value(unsigned gpio, int value)
{
- struct gpio_bank *bank;
- void *reg;
+ void __iomem *reg;
u32 l = 0;
if (check_gpio(gpio) < 0)
return;
- bank = get_gpio_bank(gpio);
- reg = bank->base;
-
- switch (bank->method) {
- case METHOD_GPIO_24XX:
- if (value)
- reg += OMAP24XX_GPIO_SETDATAOUT;
- else
- reg += OMAP24XX_GPIO_CLEARDATAOUT;
- l = 1 << get_gpio_index(gpio);
- break;
- default:
- printf("omap3-gpio unknown bank method %s %d\n",
- __FILE__, __LINE__);
- return;
- }
+
+ reg = get_gpio_base(gpio);
+
+ if (value)
+ reg += OMAP_GPIO_SETDATAOUT;
+ else
+ reg += OMAP_GPIO_CLEARDATAOUT;
+ l = 1 << get_gpio_index(gpio);
+
__raw_writel(l, reg);
}
int gpio_direction_input(unsigned gpio)
{
- struct gpio_bank *bank;
- void *reg;
+ void __iomem *reg;
u32 val;
if (check_gpio(gpio) < 0)
return -EINVAL;
- bank = get_gpio_bank(gpio);
- reg = bank->base;
+ reg = get_gpio_base(gpio);
+
+ reg += OMAP_GPIO_OE;
- switch (bank->method) {
- case METHOD_GPIO_24XX:
- reg += OMAP24XX_GPIO_OE;
- break;
- default:
- return -EINVAL;
- }
val = __raw_readl(reg);
val |= 1 << get_gpio_index(gpio);
__raw_writel(val, reg);
@@ -134,25 +126,16 @@ int gpio_direction_input(unsigned gpio)
int gpio_direction_output(unsigned gpio, int value)
{
- struct gpio_bank *bank;
- void *reg;
+ void __iomem *reg;
u32 val;
if (check_gpio(gpio) < 0)
return -EINVAL;
- bank = get_gpio_bank(gpio);
-
- reg = bank->base;
+ reg = get_gpio_base(gpio);
gpio_set_value(gpio, value);
- switch (bank->method) {
- case METHOD_GPIO_24XX:
- reg += OMAP24XX_GPIO_OE;
- break;
- default:
- return -EINVAL;
- }
+ reg += OMAP_GPIO_OE;
val = __raw_readl(reg);
val &= ~(1 << get_gpio_index(gpio));
@@ -163,22 +146,15 @@ int gpio_direction_output(unsigned gpio, int value)
int gpio_get_value(unsigned gpio)
{
- struct gpio_bank *bank;
- void *reg;
+ void __iomem *reg;
if (check_gpio(gpio) < 0)
return -EINVAL;
- bank = get_gpio_bank(gpio);
- reg = bank->base;
- switch (bank->method) {
- case METHOD_GPIO_24XX:
- reg += OMAP24XX_GPIO_DATAIN;
- break;
- default:
- return -EINVAL;
- }
- return (__raw_readl(reg)
- & (1 << get_gpio_index(gpio))) != 0;
+ reg = get_gpio_base(gpio);
+
+ reg += OMAP_GPIO_DATAIN;
+
+ return (__raw_readl(reg) & (1 << get_gpio_index(gpio))) != 0;
}
static void _reset_gpio(int gpio)
@@ -196,11 +172,8 @@ int omap_request_gpio(int gpio)
void omap_free_gpio(int gpio)
{
- struct gpio_bank *bank;
-
if (check_gpio(gpio) < 0)
return;
- bank = get_gpio_bank(gpio);
_reset_gpio(gpio);
}
diff --git a/arch/arm/mach-omap/include/mach/gpio.h b/arch/arm/mach-omap/include/mach/gpio.h
index 9840b6e..6758f9c 100644
--- a/arch/arm/mach-omap/include/mach/gpio.h
+++ b/arch/arm/mach-omap/include/mach/gpio.h
@@ -38,48 +38,6 @@
#ifndef _GPIO_H
#define _GPIO_H
-#define OMAP24XX_GPIO_REVISION 0x0000
-#define OMAP24XX_GPIO_SYSCONFIG 0x0010
-#define OMAP24XX_GPIO_SYSSTATUS 0x0014
-#define OMAP24XX_GPIO_IRQSTATUS1 0x0018
-#define OMAP24XX_GPIO_IRQSTATUS2 0x0028
-#define OMAP24XX_GPIO_IRQENABLE2 0x002c
-#define OMAP24XX_GPIO_IRQENABLE1 0x001c
-#define OMAP24XX_GPIO_WAKE_EN 0x0020
-#define OMAP24XX_GPIO_CTRL 0x0030
-#define OMAP24XX_GPIO_OE 0x0034
-#define OMAP24XX_GPIO_DATAIN 0x0038
-#define OMAP24XX_GPIO_DATAOUT 0x003c
-#define OMAP24XX_GPIO_LEVELDETECT0 0x0040
-#define OMAP24XX_GPIO_LEVELDETECT1 0x0044
-#define OMAP24XX_GPIO_RISINGDETECT 0x0048
-#define OMAP24XX_GPIO_FALLINGDETECT 0x004c
-#define OMAP24XX_GPIO_DEBOUNCE_EN 0x0050
-#define OMAP24XX_GPIO_DEBOUNCE_VAL 0x0054
-#define OMAP24XX_GPIO_CLEARIRQENABLE1 0x0060
-#define OMAP24XX_GPIO_SETIRQENABLE1 0x0064
-#define OMAP24XX_GPIO_CLEARWKUENA 0x0080
-#define OMAP24XX_GPIO_SETWKUENA 0x0084
-#define OMAP24XX_GPIO_CLEARDATAOUT 0x0090
-#define OMAP24XX_GPIO_SETDATAOUT 0x0094
-
-struct gpio_bank {
- void *base;
- int method;
-};
-
-/* OMAP3 GPIO registers */
-#define OMAP34XX_GPIO1_BASE 0x48310000
-#define OMAP34XX_GPIO2_BASE 0x49050000
-#define OMAP34XX_GPIO3_BASE 0x49052000
-#define OMAP34XX_GPIO4_BASE 0x49054000
-#define OMAP34XX_GPIO5_BASE 0x49056000
-#define OMAP34XX_GPIO6_BASE 0x49058000
-
-#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 */
--
1.7.2.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2011-04-04 13:14 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-04 13:13 On the road to omap4 Sascha Hauer
2011-04-04 13:13 ` [PATCH 1/9] ARM omap: move uart access functions to a more generic place Sascha Hauer
2011-04-04 13:13 ` Sascha Hauer [this message]
2011-04-04 13:13 ` [PATCH 3/9] ARM omap: move devices-gpmc-nand.c to omap architecture directory Sascha Hauer
2011-04-04 13:13 ` [PATCH 4/9] ARM omap: move architecture specific kconfig entries to arch part Sascha Hauer
2011-04-04 13:13 ` [PATCH 5/9] ARM omap: allow to put omap boards into another directory Sascha Hauer
2011-04-04 13:14 ` [PATCH 6/9] ARM omap4: fix indention in Kconfig Sascha Hauer
2011-04-04 13:14 ` [PATCH 7/9] omap: rename GPMC Kconfig entry to OMAP_GPMC Sascha Hauer
2011-04-04 13:14 ` [PATCH 8/9] arm omap: remove unused request/free gpio functions Sascha Hauer
2011-04-04 13:14 ` [PATCH 9/9] ARM omap: make gpio support mandatory Sascha Hauer
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=1301922843-12118-3-git-send-email-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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