sync hh.org
[hh.org.git] / include / linux / scx200_gpio.h
blob1a82d30c4b17eea493a8f1ff3fd6c293d48dc434
1 #include <linux/spinlock.h>
3 u32 scx200_gpio_configure(unsigned index, u32 set, u32 clear);
5 extern unsigned scx200_gpio_base;
6 extern long scx200_gpio_shadow[2];
7 extern struct nsc_gpio_ops scx200_gpio_ops;
9 #define scx200_gpio_present() (scx200_gpio_base!=0)
11 /* Definitions to make sure I do the same thing in all functions */
12 #define __SCx200_GPIO_BANK unsigned bank = index>>5
13 #define __SCx200_GPIO_IOADDR unsigned short ioaddr = scx200_gpio_base+0x10*bank
14 #define __SCx200_GPIO_SHADOW long *shadow = scx200_gpio_shadow+bank
15 #define __SCx200_GPIO_INDEX index &= 31
17 #define __SCx200_GPIO_OUT __asm__ __volatile__("outsl":"=mS" (shadow):"d" (ioaddr), "0" (shadow))
19 /* returns the value of the GPIO pin */
21 static inline int scx200_gpio_get(unsigned index) {
22 __SCx200_GPIO_BANK;
23 __SCx200_GPIO_IOADDR + 0x04;
24 __SCx200_GPIO_INDEX;
26 return (inl(ioaddr) & (1<<index)) ? 1 : 0;
29 /* return the value driven on the GPIO signal (the value that will be
30 driven if the GPIO is configured as an output, it might not be the
31 state of the GPIO right now if the GPIO is configured as an input) */
33 static inline int scx200_gpio_current(unsigned index) {
34 __SCx200_GPIO_BANK;
35 __SCx200_GPIO_INDEX;
37 return (scx200_gpio_shadow[bank] & (1<<index)) ? 1 : 0;
40 /* drive the GPIO signal high */
42 static inline void scx200_gpio_set_high(unsigned index) {
43 __SCx200_GPIO_BANK;
44 __SCx200_GPIO_IOADDR;
45 __SCx200_GPIO_SHADOW;
46 __SCx200_GPIO_INDEX;
47 set_bit(index, shadow);
48 __SCx200_GPIO_OUT;
51 /* drive the GPIO signal low */
53 static inline void scx200_gpio_set_low(unsigned index) {
54 __SCx200_GPIO_BANK;
55 __SCx200_GPIO_IOADDR;
56 __SCx200_GPIO_SHADOW;
57 __SCx200_GPIO_INDEX;
58 clear_bit(index, shadow);
59 __SCx200_GPIO_OUT;
62 /* drive the GPIO signal to state */
64 static inline void scx200_gpio_set(unsigned index, int state) {
65 __SCx200_GPIO_BANK;
66 __SCx200_GPIO_IOADDR;
67 __SCx200_GPIO_SHADOW;
68 __SCx200_GPIO_INDEX;
69 if (state)
70 set_bit(index, shadow);
71 else
72 clear_bit(index, shadow);
73 __SCx200_GPIO_OUT;
76 /* toggle the GPIO signal */
77 static inline void scx200_gpio_change(unsigned index) {
78 __SCx200_GPIO_BANK;
79 __SCx200_GPIO_IOADDR;
80 __SCx200_GPIO_SHADOW;
81 __SCx200_GPIO_INDEX;
82 change_bit(index, shadow);
83 __SCx200_GPIO_OUT;
86 #undef __SCx200_GPIO_BANK
87 #undef __SCx200_GPIO_IOADDR
88 #undef __SCx200_GPIO_SHADOW
89 #undef __SCx200_GPIO_INDEX
90 #undef __SCx200_GPIO_OUT