[PATCH v2 1/2] ARM: i.MX: Add lowlevel gpio input functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This adds the function to set direction input and read the values
in the header file for setting i.MX gpios early.

Signed-off-by: Michael Grzeschik <m.grzeschik@xxxxxxxxxxxxxx>
---
 arch/arm/mach-imx/include/mach/imx-gpio.h | 46 +++++++++++++++++++++++++++----
 1 file changed, 41 insertions(+), 5 deletions(-)

diff --git a/arch/arm/mach-imx/include/mach/imx-gpio.h b/arch/arm/mach-imx/include/mach/imx-gpio.h
index 5e673beef9..891c33a3f4 100644
--- a/arch/arm/mach-imx/include/mach/imx-gpio.h
+++ b/arch/arm/mach-imx/include/mach/imx-gpio.h
@@ -8,15 +8,21 @@
  * regular gpio functions outside of lowlevel code!
  */
 
-static inline void imx_gpio_direction_output(void __iomem *gdir, void __iomem *dr,
-		int gpio, int value)
+static inline void imx_gpio_direction(void __iomem *gdir, void __iomem *dr,
+		int gpio, int out, int value)
 {
 	uint32_t val;
 
 	val = readl(gdir);
-	val |= 1 << gpio;
+	if (out)
+		val |= 1 << gpio;
+	else
+		val &= ~(1 << gpio);
 	writel(val, gdir);
 
+	if (!out)
+		return;
+
 	val = readl(dr);
 	if (value)
 		val |= 1 << gpio;
@@ -28,7 +34,7 @@ static inline void imx_gpio_direction_output(void __iomem *gdir, void __iomem *d
 
 static inline void imx1_gpio_direction_output(void *base, int gpio, int value)
 {
-	imx_gpio_direction_output(base + 0x0, base + 0x1c, gpio, value);
+	imx_gpio_direction(base + 0x0, base + 0x1c, gpio, 1, value);
 }
 
 #define imx21_gpio_direction_output(base, gpio, value) imx1_gpio_direction_output(base, gpio,value)
@@ -36,7 +42,7 @@ static inline void imx1_gpio_direction_output(void *base, int gpio, int value)
 
 static inline void imx31_gpio_direction_output(void *base, int gpio, int value)
 {
-	imx_gpio_direction_output(base + 0x4, base + 0x0, gpio, value);
+	imx_gpio_direction(base + 0x4, base + 0x0, gpio, 1, value);
 }
 
 #define imx25_gpio_direction_output(base, gpio, value) imx31_gpio_direction_output(base, gpio,value)
@@ -45,4 +51,34 @@ static inline void imx31_gpio_direction_output(void *base, int gpio, int 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)
 
+static inline void imx1_gpio_direction_input(void *base, int gpio, int value)
+{
+	imx_gpio_direction(base + 0x0, base + 0x1c, gpio, 0, 0);
+}
+
+#define imx21_gpio_direction_input(base, gpio, value) imx1_gpio_direction_input(base, gpio)
+#define imx27_gpio_direction_input(base, gpio, value) imx1_gpio_direction_input(base, gpio)
+
+static inline void imx31_gpio_direction_input(void *base, int gpio)
+{
+	imx_gpio_direction(base + 0x4, base + 0x0, gpio, 0, 0);
+}
+
+#define imx25_gpio_direction_input(base, gpio, value) imx31_gpio_direction_input(base, gpio)
+#define imx35_gpio_direction_input(base, gpio, value) imx31_gpio_direction_input(base, gpio)
+#define imx51_gpio_direction_input(base, gpio, value) imx31_gpio_direction_input(base, gpio)
+#define imx53_gpio_direction_input(base, gpio, value) imx31_gpio_direction_input(base, gpio)
+#define imx6_gpio_direction_input(base, gpio) imx31_gpio_direction_input(base, gpio)
+
+#define imx1_gpio_val(base, gpio) readl(base + 0x1c) & (1 << gpio) ? 1 : 0
+#define imx21_gpio_val(base, gpio) imx1_gpio_val(base, gpio)
+#define imx27_gpio_val(base, gpio) imx1_gpio_val(base, gpio)
+
+#define imx31_gpio_val(base, gpio) readl(base) & (1 << gpio) ? 1 : 0
+#define imx25_gpio_val(base, gpio) imx31_gpio_val(base, gpio)
+#define imx35_gpio_val(base, gpio) imx31_gpio_val(base, gpio)
+#define imx51_gpio_val(base, gpio) imx31_gpio_val(base, gpio)
+#define imx53_gpio_val(base, gpio) imx31_gpio_val(base, gpio)
+#define imx6_gpio_val(base, gpio) imx31_gpio_val(base, gpio)
+
 #endif /* __MACH_IMX_GPIO_H */
-- 
2.16.1


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux