Commit | Line | Data |
---|---|---|
55b8c045 | 1 | u32 scx200_gpio_configure(unsigned index, u32 set, u32 clear); |
1da177e4 LT |
2 | |
3 | extern unsigned scx200_gpio_base; | |
64b33619 | 4 | extern unsigned long scx200_gpio_shadow[2]; |
58012cd7 | 5 | extern struct nsc_gpio_ops scx200_gpio_ops; |
1da177e4 LT |
6 | |
7 | #define scx200_gpio_present() (scx200_gpio_base!=0) | |
8 | ||
9 | /* Definitions to make sure I do the same thing in all functions */ | |
10 | #define __SCx200_GPIO_BANK unsigned bank = index>>5 | |
11 | #define __SCx200_GPIO_IOADDR unsigned short ioaddr = scx200_gpio_base+0x10*bank | |
64b33619 | 12 | #define __SCx200_GPIO_SHADOW unsigned long *shadow = scx200_gpio_shadow+bank |
1da177e4 LT |
13 | #define __SCx200_GPIO_INDEX index &= 31 |
14 | ||
15 | #define __SCx200_GPIO_OUT __asm__ __volatile__("outsl":"=mS" (shadow):"d" (ioaddr), "0" (shadow)) | |
16 | ||
17 | /* returns the value of the GPIO pin */ | |
18 | ||
55b8c045 | 19 | static inline int scx200_gpio_get(unsigned index) { |
1da177e4 LT |
20 | __SCx200_GPIO_BANK; |
21 | __SCx200_GPIO_IOADDR + 0x04; | |
22 | __SCx200_GPIO_INDEX; | |
23 | ||
24 | return (inl(ioaddr) & (1<<index)) ? 1 : 0; | |
25 | } | |
26 | ||
27 | /* return the value driven on the GPIO signal (the value that will be | |
28 | driven if the GPIO is configured as an output, it might not be the | |
29 | state of the GPIO right now if the GPIO is configured as an input) */ | |
30 | ||
55b8c045 | 31 | static inline int scx200_gpio_current(unsigned index) { |
1da177e4 LT |
32 | __SCx200_GPIO_BANK; |
33 | __SCx200_GPIO_INDEX; | |
34 | ||
35 | return (scx200_gpio_shadow[bank] & (1<<index)) ? 1 : 0; | |
36 | } | |
37 | ||
38 | /* drive the GPIO signal high */ | |
39 | ||
55b8c045 | 40 | static inline void scx200_gpio_set_high(unsigned index) { |
1da177e4 LT |
41 | __SCx200_GPIO_BANK; |
42 | __SCx200_GPIO_IOADDR; | |
43 | __SCx200_GPIO_SHADOW; | |
44 | __SCx200_GPIO_INDEX; | |
64b33619 | 45 | set_bit(index, shadow); /* __set_bit()? */ |
1da177e4 LT |
46 | __SCx200_GPIO_OUT; |
47 | } | |
48 | ||
49 | /* drive the GPIO signal low */ | |
50 | ||
55b8c045 | 51 | static inline void scx200_gpio_set_low(unsigned index) { |
1da177e4 LT |
52 | __SCx200_GPIO_BANK; |
53 | __SCx200_GPIO_IOADDR; | |
54 | __SCx200_GPIO_SHADOW; | |
55 | __SCx200_GPIO_INDEX; | |
64b33619 | 56 | clear_bit(index, shadow); /* __clear_bit()? */ |
1da177e4 LT |
57 | __SCx200_GPIO_OUT; |
58 | } | |
59 | ||
60 | /* drive the GPIO signal to state */ | |
61 | ||
55b8c045 | 62 | static inline void scx200_gpio_set(unsigned index, int state) { |
1da177e4 LT |
63 | __SCx200_GPIO_BANK; |
64 | __SCx200_GPIO_IOADDR; | |
65 | __SCx200_GPIO_SHADOW; | |
66 | __SCx200_GPIO_INDEX; | |
67 | if (state) | |
68 | set_bit(index, shadow); | |
69 | else | |
70 | clear_bit(index, shadow); | |
71 | __SCx200_GPIO_OUT; | |
72 | } | |
73 | ||
74 | /* toggle the GPIO signal */ | |
55b8c045 | 75 | static inline void scx200_gpio_change(unsigned index) { |
1da177e4 LT |
76 | __SCx200_GPIO_BANK; |
77 | __SCx200_GPIO_IOADDR; | |
78 | __SCx200_GPIO_SHADOW; | |
79 | __SCx200_GPIO_INDEX; | |
80 | change_bit(index, shadow); | |
81 | __SCx200_GPIO_OUT; | |
82 | } | |
83 | ||
84 | #undef __SCx200_GPIO_BANK | |
85 | #undef __SCx200_GPIO_IOADDR | |
86 | #undef __SCx200_GPIO_SHADOW | |
87 | #undef __SCx200_GPIO_INDEX | |
88 | #undef __SCx200_GPIO_OUT |