Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #include <linux/spinlock.h> |
| 2 | |
Jim Cromie | 55b8c04 | 2006-06-27 02:54:15 -0700 | [diff] [blame] | 3 | u32 scx200_gpio_configure(unsigned index, u32 set, u32 clear); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | |
| 5 | extern unsigned scx200_gpio_base; |
| 6 | extern long scx200_gpio_shadow[2]; |
Chris Boot | 58012cd | 2006-09-29 01:59:07 -0700 | [diff] [blame] | 7 | extern struct nsc_gpio_ops scx200_gpio_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | |
| 9 | #define scx200_gpio_present() (scx200_gpio_base!=0) |
| 10 | |
| 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 |
| 16 | |
| 17 | #define __SCx200_GPIO_OUT __asm__ __volatile__("outsl":"=mS" (shadow):"d" (ioaddr), "0" (shadow)) |
| 18 | |
| 19 | /* returns the value of the GPIO pin */ |
| 20 | |
Jim Cromie | 55b8c04 | 2006-06-27 02:54:15 -0700 | [diff] [blame] | 21 | static inline int scx200_gpio_get(unsigned index) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | __SCx200_GPIO_BANK; |
| 23 | __SCx200_GPIO_IOADDR + 0x04; |
| 24 | __SCx200_GPIO_INDEX; |
| 25 | |
| 26 | return (inl(ioaddr) & (1<<index)) ? 1 : 0; |
| 27 | } |
| 28 | |
| 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) */ |
| 32 | |
Jim Cromie | 55b8c04 | 2006-06-27 02:54:15 -0700 | [diff] [blame] | 33 | static inline int scx200_gpio_current(unsigned index) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | __SCx200_GPIO_BANK; |
| 35 | __SCx200_GPIO_INDEX; |
| 36 | |
| 37 | return (scx200_gpio_shadow[bank] & (1<<index)) ? 1 : 0; |
| 38 | } |
| 39 | |
| 40 | /* drive the GPIO signal high */ |
| 41 | |
Jim Cromie | 55b8c04 | 2006-06-27 02:54:15 -0700 | [diff] [blame] | 42 | static inline void scx200_gpio_set_high(unsigned index) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
| 49 | } |
| 50 | |
| 51 | /* drive the GPIO signal low */ |
| 52 | |
Jim Cromie | 55b8c04 | 2006-06-27 02:54:15 -0700 | [diff] [blame] | 53 | static inline void scx200_gpio_set_low(unsigned index) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
| 60 | } |
| 61 | |
| 62 | /* drive the GPIO signal to state */ |
| 63 | |
Jim Cromie | 55b8c04 | 2006-06-27 02:54:15 -0700 | [diff] [blame] | 64 | static inline void scx200_gpio_set(unsigned index, int state) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
| 74 | } |
| 75 | |
| 76 | /* toggle the GPIO signal */ |
Jim Cromie | 55b8c04 | 2006-06-27 02:54:15 -0700 | [diff] [blame] | 77 | static inline void scx200_gpio_change(unsigned index) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
| 84 | } |
| 85 | |
| 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 |