Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
422 giacomo 1
#include <linux/spinlock.h>
2
 
3
u32 scx200_gpio_configure(int index, u32 set, u32 clear);
4
void scx200_gpio_dump(unsigned index);
5
 
6
extern unsigned scx200_gpio_base;
7
extern spinlock_t scx200_gpio_lock;
8
extern long scx200_gpio_shadow[2];
9
 
10
#define scx200_gpio_present() (scx200_gpio_base!=0)
11
 
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
17
 
18
#define __SCx200_GPIO_OUT __asm__ __volatile__("outsl":"=mS" (shadow):"d" (ioaddr), "0" (shadow))
19
 
20
/* returns the value of the GPIO pin */
21
 
22
static inline int scx200_gpio_get(int index) {
23
        __SCx200_GPIO_BANK;
24
        __SCx200_GPIO_IOADDR + 0x04;
25
        __SCx200_GPIO_INDEX;
26
 
27
        return (inl(ioaddr) & (1<<index)) ? 1 : 0;
28
}
29
 
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) */
33
 
34
static inline int scx200_gpio_current(int index) {
35
        __SCx200_GPIO_BANK;
36
        __SCx200_GPIO_INDEX;
37
 
38
        return (scx200_gpio_shadow[bank] & (1<<index)) ? 1 : 0;
39
}
40
 
41
/* drive the GPIO signal high */
42
 
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;
50
}
51
 
52
/* drive the GPIO signal low */
53
 
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;
61
}
62
 
63
/* drive the GPIO signal to state */
64
 
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;
75
}
76
 
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;
85
}
86
 
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
92
 
93
/*
94
    Local variables:
95
        compile-command: "make -C ../.. bzImage modules"
96
        c-basic-offset: 8
97
    End:
98
*/