initial commit with v2.6.9
[linux-2.6.9-moxart.git] / include / linux / scx200_gpio.h
blob2c6d739706b6c5eaa5c64f7ef26d721b17a518ad
1 #include <linux/spinlock.h>
3 u32 scx200_gpio_configure(int index, u32 set, u32 clear);
4 void scx200_gpio_dump(unsigned index);
6 extern unsigned scx200_gpio_base;
7 extern spinlock_t scx200_gpio_lock;
8 extern long scx200_gpio_shadow[2];
10 #define scx200_gpio_present() (scx200_gpio_base!=0)
12 /* Definitions to make sure I do the same thing in all functions */
13 #define __SCx200_GPIO_BANK unsigned bank = index>>5
14 #define __SCx200_GPIO_IOADDR unsigned short ioaddr = scx200_gpio_base+0x10*bank
15 #define __SCx200_GPIO_SHADOW long *shadow = scx200_gpio_shadow+bank
16 #define __SCx200_GPIO_INDEX index &= 31
18 #define __SCx200_GPIO_OUT __asm__ __volatile__("outsl":"=mS" (shadow):"d" (ioaddr), "0" (shadow))
20 /* returns the value of the GPIO pin */
22 static inline int scx200_gpio_get(int index) {
23 __SCx200_GPIO_BANK;
24 __SCx200_GPIO_IOADDR + 0x04;
25 __SCx200_GPIO_INDEX;
27 return (inl(ioaddr) & (1<<index)) ? 1 : 0;
30 /* return the value driven on the GPIO signal (the value that will be
31 driven if the GPIO is configured as an output, it might not be the
32 state of the GPIO right now if the GPIO is configured as an input) */
34 static inline int scx200_gpio_current(int index) {
35 __SCx200_GPIO_BANK;
36 __SCx200_GPIO_INDEX;
38 return (scx200_gpio_shadow[bank] & (1<<index)) ? 1 : 0;
41 /* drive the GPIO signal high */
43 static inline void scx200_gpio_set_high(int index) {
44 __SCx200_GPIO_BANK;
45 __SCx200_GPIO_IOADDR;
46 __SCx200_GPIO_SHADOW;
47 __SCx200_GPIO_INDEX;
48 set_bit(index, shadow);
49 __SCx200_GPIO_OUT;
52 /* drive the GPIO signal low */
54 static inline void scx200_gpio_set_low(int index) {
55 __SCx200_GPIO_BANK;
56 __SCx200_GPIO_IOADDR;
57 __SCx200_GPIO_SHADOW;
58 __SCx200_GPIO_INDEX;
59 clear_bit(index, shadow);
60 __SCx200_GPIO_OUT;
63 /* drive the GPIO signal to state */
65 static inline void scx200_gpio_set(int index, int state) {
66 __SCx200_GPIO_BANK;
67 __SCx200_GPIO_IOADDR;
68 __SCx200_GPIO_SHADOW;
69 __SCx200_GPIO_INDEX;
70 if (state)
71 set_bit(index, shadow);
72 else
73 clear_bit(index, shadow);
74 __SCx200_GPIO_OUT;
77 /* toggle the GPIO signal */
78 static inline void scx200_gpio_change(int index) {
79 __SCx200_GPIO_BANK;
80 __SCx200_GPIO_IOADDR;
81 __SCx200_GPIO_SHADOW;
82 __SCx200_GPIO_INDEX;
83 change_bit(index, shadow);
84 __SCx200_GPIO_OUT;
87 #undef __SCx200_GPIO_BANK
88 #undef __SCx200_GPIO_IOADDR
89 #undef __SCx200_GPIO_SHADOW
90 #undef __SCx200_GPIO_INDEX
91 #undef __SCx200_GPIO_OUT
94 Local variables:
95 compile-command: "make -C ../.. bzImage modules"
96 c-basic-offset: 8
97 End: