From: Juergen Beisert <jbe@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 6/9] ARM STM/i.MX: Add support for the gpio commands
Date: Tue, 21 Dec 2010 12:25:18 +0100 [thread overview]
Message-ID: <1292930721-31734-7-git-send-email-jbe@pengutronix.de> (raw)
In-Reply-To: <1292930721-31734-1-git-send-email-jbe@pengutronix.de>
Just an architecture improvement.
Signed-off-by: Juergen Beisert <jbe@pengutronix.de>
---
arch/arm/Kconfig | 1 +
arch/arm/configs/chumbyone_defconfig | 1 +
arch/arm/configs/tx28stk5_defconfig | 1 +
arch/arm/mach-stm/include/mach/gpio.h | 4 ++
arch/arm/mach-stm/iomux-imx.c | 60 +++++++++++++++++++++++++++++++++
5 files changed, 67 insertions(+), 0 deletions(-)
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index c09d21b..f1536a5 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -41,6 +41,7 @@ config ARCH_IMX
config ARCH_STM
bool "SigmaTel/FSL iMX-based"
+ select GENERIC_GPIO
config ARCH_NETX
bool "Hilscher NetX based"
diff --git a/arch/arm/configs/chumbyone_defconfig b/arch/arm/configs/chumbyone_defconfig
index 6e6623a..45804a8 100644
--- a/arch/arm/configs/chumbyone_defconfig
+++ b/arch/arm/configs/chumbyone_defconfig
@@ -24,6 +24,7 @@ CONFIG_CMD_RESET=y
CONFIG_CMD_TIMEOUT=y
CONFIG_CMD_PARTITION=y
CONFIG_CMD_BMP=y
+CONFIG_CMD_GPIO=y
# CONFIG_SPI is not set
CONFIG_VIDEO=y
CONFIG_DRIVER_VIDEO_STM=y
diff --git a/arch/arm/configs/tx28stk5_defconfig b/arch/arm/configs/tx28stk5_defconfig
index d6b81c6..0851d5e 100644
--- a/arch/arm/configs/tx28stk5_defconfig
+++ b/arch/arm/configs/tx28stk5_defconfig
@@ -32,6 +32,7 @@ CONFIG_CMD_GO=y
CONFIG_CMD_TIMEOUT=y
CONFIG_CMD_PARTITION=y
CONFIG_CMD_BMP=y
+CONFIG_CMD_GPIO=y
CONFIG_NET=y
CONFIG_NET_DHCP=y
CONFIG_NET_TFTP=y
diff --git a/arch/arm/mach-stm/include/mach/gpio.h b/arch/arm/mach-stm/include/mach/gpio.h
index 97566a2..c419926 100644
--- a/arch/arm/mach-stm/include/mach/gpio.h
+++ b/arch/arm/mach-stm/include/mach/gpio.h
@@ -30,5 +30,9 @@
#endif
void imx_gpio_mode(uint32_t);
+void gpio_set_value(unsigned, int);
+int gpio_direction_input(unsigned);
+int gpio_direction_output(unsigned, int);
+int gpio_get_value(unsigned);
#endif /* __ASM_MACH_GPIO_H */
diff --git a/arch/arm/mach-stm/iomux-imx.c b/arch/arm/mach-stm/iomux-imx.c
index 8a34e4c..b9fa565 100644
--- a/arch/arm/mach-stm/iomux-imx.c
+++ b/arch/arm/mach-stm/iomux-imx.c
@@ -20,6 +20,7 @@
#include <common.h>
#include <init.h>
#include <gpio.h>
+#include <errno.h>
#include <asm/io.h>
#include <mach/imx-regs.h>
@@ -76,6 +77,12 @@ static unsigned calc_output_reg(unsigned no)
return ((no >> 5) << 4) + HW_PINCTRL_DOUT0;
}
+static unsigned calc_input_reg(unsigned no)
+{
+ /* each register controls 32 pads */
+ return ((no >> 5) << 4) + HW_PINCTRL_DIN0;
+}
+
/**
* @param[in] m One pin define per call from iomux-mx23.h/iomux-mx28.h
*/
@@ -137,3 +144,56 @@ void imx_gpio_mode(uint32_t m)
}
}
}
+
+int gpio_direction_input(unsigned gpio)
+{
+ unsigned reg_offset;
+
+ if (gpio > MAX_GPIO_NO)
+ return -EINVAL;
+
+ reg_offset = calc_output_enable_reg(gpio);
+ writel(0x1 << (gpio % 32), IMX_IOMUXC_BASE + reg_offset + BIT_CLR);
+
+ return 0;
+}
+
+int gpio_direction_output(unsigned gpio, int val)
+{
+ unsigned reg_offset;
+
+ if (gpio > MAX_GPIO_NO)
+ return -EINVAL;
+
+ /* first set the output value... */
+ reg_offset = calc_output_reg(gpio);
+ writel(0x1 << (gpio % 32), IMX_IOMUXC_BASE +
+ reg_offset + (val != 0 ? BIT_SET : BIT_CLR));
+ /* ...then the direction */
+ reg_offset = calc_output_enable_reg(gpio);
+ writel(0x1 << (gpio % 32), IMX_IOMUXC_BASE + reg_offset + BIT_SET);
+
+ return 0;
+}
+
+void gpio_set_value(unsigned gpio, int val)
+{
+ unsigned reg_offset;
+
+ reg_offset = calc_output_reg(gpio);
+ writel(0x1 << (gpio % 32), IMX_IOMUXC_BASE +
+ reg_offset + (val != 0 ? BIT_SET : BIT_CLR));
+}
+
+int gpio_get_value(unsigned gpio)
+{
+ uint32_t reg;
+ unsigned reg_offset;
+
+ reg_offset = calc_input_reg(gpio);
+ reg = readl(IMX_IOMUXC_BASE + reg_offset);
+ if (reg & (0x1 << (gpio % 32)))
+ return 1;
+
+ return 0;
+}
--
1.7.2.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2010-12-21 11:25 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-21 11:25 [PATCH] Add gpio command support to STM/i.MX arch Juergen Beisert
2010-12-21 11:25 ` [PATCH 1/9] Fix a typo in the GPIO doc Juergen Beisert
2010-12-21 11:25 ` [PATCH 2/9] ARM STM/i.MX: Fix register offset calculation for GPIO input pins Juergen Beisert
2010-12-21 11:25 ` [PATCH 3/9] ARM STM/i.MX: Remove variable size restrictions in iomux managing routines Juergen Beisert
2010-12-21 11:25 ` [PATCH 4/9] ARM STM/i.MX: Setting the iomux needs at least 32 bit Juergen Beisert
2010-12-21 11:25 ` [PATCH 5/9] ARM STM/i.MX: Just fix the docs Juergen Beisert
2010-12-21 11:25 ` Juergen Beisert [this message]
2010-12-21 11:25 ` [PATCH 7/9] ARM STM/i.MX: Avoid very long lines Juergen Beisert
2010-12-21 11:25 ` [PATCH 8/9] ARM STM/i.MX: Replace cryptic numbers Juergen Beisert
2010-12-21 11:25 ` [PATCH 9/9] ARM Chumby: Add list of available GPIOs and their meaning Juergen Beisert
2010-12-23 11:30 ` [PATCH] Add gpio command support to STM/i.MX arch Gregory CLEMENT
2010-12-23 11:50 ` Juergen Beisert
2010-12-23 11:58 ` Gregory CLEMENT
2010-12-23 14:36 ` Uwe Kleine-König
2010-12-23 11:53 ` Eric Bénard
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=1292930721-31734-7-git-send-email-jbe@pengutronix.de \
--to=jbe@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