2 #include <linux/config.h>
3 #include <linux/module.h>
4 #include <linux/kernel.h>
5 #include <linux/types.h>
6 #include <linux/spinlock.h>
9 #include <asm/arch/moxa.h>
10 #include <asm/arch/gpio.h>
12 #define VICTOR_USE_LOCK_IRQ
13 static mcpu_gpio_reg_t
*gpio_reg
=(mcpu_gpio_reg_t
*)CPE_GPIO_VA_BASE
;
14 static spinlock_t gpio_lock
=SPIN_LOCK_UNLOCKED
;
17 * To set the GPIO mode for INPUT or OUTPUT
19 void mcpu_gpio_inout(u32 gpio
, int inout
)
21 #ifdef VICTOR_USE_LOCK_IRQ // add by Victor Yu. 07-25-2007
25 #ifdef VICTOR_USE_LOCK_IRQ // add by Victor Yu. 07-25-2007
26 spin_lock_irqsave(&gpio_lock
, flags
);
28 spin_lock(&gpio_lock
);
31 case MCPU_GPIO_INPUT
:
32 writel(readl(&gpio_reg
->pin_dir
)&~gpio
, &gpio_reg
->pin_dir
);
34 case MCPU_GPIO_OUTPUT
:
35 writel(readl(&gpio_reg
->pin_dir
)|gpio
, &gpio_reg
->pin_dir
);
38 #ifdef VICTOR_USE_LOCK_IRQ // add by Victor Yu. 07-25-2007
39 spin_unlock_irqrestore(&gpio_lock
, flags
);
41 spin_unlock(&gpio_lock
);
44 EXPORT_SYMBOL(mcpu_gpio_inout
);
47 * To get the GPIO which mode, INPUT or OUTPUT
49 u32
mcpu_gpio_get_inout(u32 gpio
)
52 #ifdef VICTOR_USE_LOCK_IRQ // add by Victor Yu. 07-25-2007
56 #ifdef VICTOR_USE_LOCK_IRQ // add by Victor Yu. 07-25-2007
57 spin_lock_irqsave(&gpio_lock
, flags
);
59 spin_lock(&gpio_lock
);
61 if ( readl(&gpio_reg
->pin_dir
) & gpio
)
62 ret
= MCPU_GPIO_OUTPUT
;
64 ret
= MCPU_GPIO_INPUT
;
65 #ifdef VICTOR_USE_LOCK_IRQ // add by Victor Yu. 07-25-2007
66 spin_unlock_irqrestore(&gpio_lock
, flags
);
68 spin_unlock(&gpio_lock
);
72 EXPORT_SYMBOL(mcpu_gpio_get_inout
);
75 * To set the GPIO ouput signal to high or low
77 void mcpu_gpio_set(u32 gpio
, int highlow
)
79 #ifdef VICTOR_USE_LOCK_IRQ // add by Victor Yu. 07-25-2007
83 #ifdef VICTOR_USE_LOCK_IRQ // add by Victor Yu. 07-25-2007
84 spin_lock_irqsave(&gpio_lock
, flags
);
86 spin_lock(&gpio_lock
);
90 writel(readl(&gpio_reg
->data_out
)|gpio
, &gpio_reg
->data_out
);
93 writel(readl(&gpio_reg
->data_out
)&~gpio
, &gpio_reg
->data_out
);
96 #ifdef VICTOR_USE_LOCK_IRQ // add by Victor Yu. 07-25-2007
97 spin_unlock_irqrestore(&gpio_lock
, flags
);
99 spin_unlock(&gpio_lock
);
102 EXPORT_SYMBOL(mcpu_gpio_set
);
105 * to get the GPIO input which level, high or low
107 u32
mcpu_gpio_get(u32 gpio
)
110 #ifdef VICTOR_USE_LOCK_IRQ // add by Victor Yu. 07-25-2007
114 #ifdef VICTOR_USE_LOCK_IRQ // add by Victor Yu. 07-25-2007
115 spin_lock_irqsave(&gpio_lock
, flags
);
117 spin_lock(&gpio_lock
);
119 #if 0 // mask by Victor Yu. 04-20-2007
120 ret
= readl(&gpio_reg
->data_in
) & gpio
;
122 ret
= readl(&gpio_reg
->pin_dir
);
123 if ( ret
& gpio
) // this is output GPIO
124 ret
= readl(&gpio_reg
->data_out
) & gpio
;
126 ret
= readl(&gpio_reg
->data_in
) & gpio
;
128 #ifdef VICTOR_USE_LOCK_IRQ // add by Victor Yu. 07-25-2007
129 spin_unlock_irqrestore(&gpio_lock
, flags
);
131 spin_unlock(&gpio_lock
);
135 EXPORT_SYMBOL(mcpu_gpio_get
);
138 * To set thie GPIO to work GPIO mode
140 void mcpu_gpio_mp_set(u32 gpio
)
142 #ifdef VICTOR_USE_LOCK_IRQ // add by Victor Yu. 07-25-2007
146 #ifdef VICTOR_USE_LOCK_IRQ // add by Victor Yu. 07-25-2007
147 spin_lock_irqsave(&gpio_lock
, flags
);
149 spin_lock(&gpio_lock
);
151 *(volatile unsigned int *)(CPE_PMU_VA_BASE
+0x100) |= gpio
;
152 #ifdef VICTOR_USE_LOCK_IRQ // add by Victor Yu. 07-25-2007
153 spin_unlock_irqrestore(&gpio_lock
, flags
);
155 spin_unlock(&gpio_lock
);
158 EXPORT_SYMBOL(mcpu_gpio_mp_set
);
161 * To set the GPIO for component mode
163 void mcpu_gpio_mp_clear(u32 gpio
)
165 #ifdef VICTOR_USE_LOCK_IRQ // add by Victor Yu. 07-25-2007
169 #ifdef VICTOR_USE_LOCK_IRQ // add by Victor Yu. 07-25-2007
170 spin_lock_irqsave(&gpio_lock
, flags
);
172 spin_lock(&gpio_lock
);
174 *(volatile unsigned int *)(CPE_PMU_VA_BASE
+0x100) &= ~gpio
;
175 #ifdef VICTOR_USE_LOCK_IRQ // add by Victor Yu. 07-25-2007
176 spin_unlock_irqrestore(&gpio_lock
, flags
);
178 spin_unlock(&gpio_lock
);
181 EXPORT_SYMBOL(mcpu_gpio_mp_clear
);