[PATCH] ARM: i.MX: Add lowlevel gpio functions

Sascha Hauer s.hauer at pengutronix.de
Fri Jan 31 09:24:23 EST 2014


Some boards need gpio functions very early and also sometimes
is useful to toggle gpios during early code debug. This adds a header
file for setting i.MX gpios early.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/mach-imx/include/mach/imx-gpio.h | 48 +++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 arch/arm/mach-imx/include/mach/imx-gpio.h

diff --git a/arch/arm/mach-imx/include/mach/imx-gpio.h b/arch/arm/mach-imx/include/mach/imx-gpio.h
new file mode 100644
index 0000000..5e673be
--- /dev/null
+++ b/arch/arm/mach-imx/include/mach/imx-gpio.h
@@ -0,0 +1,48 @@
+#ifndef __MACH_IMX_GPIO_H
+#define __MACH_IMX_GPIO_H
+
+#include <io.h>
+
+/*
+ * i.MX lowlevel gpio functions. Only for use with lowlevel code. Use
+ * regular gpio functions outside of lowlevel code!
+ */
+
+static inline void imx_gpio_direction_output(void __iomem *gdir, void __iomem *dr,
+		int gpio, int value)
+{
+	uint32_t val;
+
+	val = readl(gdir);
+	val |= 1 << gpio;
+	writel(val, gdir);
+
+	val = readl(dr);
+	if (value)
+		val |= 1 << gpio;
+	else
+		val &= ~(1 << gpio);
+
+	writel(val, dr);
+}
+
+static inline void imx1_gpio_direction_output(void *base, int gpio, int value)
+{
+	imx_gpio_direction_output(base + 0x0, base + 0x1c, gpio, value);
+}
+
+#define imx21_gpio_direction_output(base, gpio, value) imx1_gpio_direction_output(base, gpio,value)
+#define imx27_gpio_direction_output(base, gpio, value) imx1_gpio_direction_output(base, gpio,value)
+
+static inline void imx31_gpio_direction_output(void *base, int gpio, int value)
+{
+	imx_gpio_direction_output(base + 0x4, base + 0x0, gpio, value);
+}
+
+#define imx25_gpio_direction_output(base, gpio, value) imx31_gpio_direction_output(base, gpio,value)
+#define imx35_gpio_direction_output(base, gpio, value) imx31_gpio_direction_output(base, gpio,value)
+#define imx51_gpio_direction_output(base, gpio, value) imx31_gpio_direction_output(base, gpio,value)
+#define imx53_gpio_direction_output(base, gpio, value) imx31_gpio_direction_output(base, gpio,value)
+#define imx6_gpio_direction_output(base, gpio, value) imx31_gpio_direction_output(base, gpio,value)
+
+#endif /* __MACH_IMX_GPIO_H */
-- 
1.8.5.3




More information about the barebox mailing list