| Jim Cromie | 55b8c04 | 2006-06-27 02:54:15 -0700 | [diff] [blame] | 1 | u32 scx200_gpio_configure(unsigned index, u32 set, u32 clear); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 |  | 
|  | 3 | extern unsigned scx200_gpio_base; | 
| Al Viro | 64b3361 | 2007-10-14 19:35:20 +0100 | [diff] [blame] | 4 | extern unsigned long scx200_gpio_shadow[2]; | 
| Chris Boot | 58012cd | 2006-09-29 01:59:07 -0700 | [diff] [blame] | 5 | extern struct nsc_gpio_ops scx200_gpio_ops; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | 
| Al Viro | 64b3361 | 2007-10-14 19:35:20 +0100 | [diff] [blame] | 12 | #define __SCx200_GPIO_SHADOW unsigned long *shadow = scx200_gpio_shadow+bank | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
| Jim Cromie | 55b8c04 | 2006-06-27 02:54:15 -0700 | [diff] [blame] | 19 | static inline int scx200_gpio_get(unsigned index) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
| Jim Cromie | 55b8c04 | 2006-06-27 02:54:15 -0700 | [diff] [blame] | 31 | static inline int scx200_gpio_current(unsigned index) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
| Jim Cromie | 55b8c04 | 2006-06-27 02:54:15 -0700 | [diff] [blame] | 40 | static inline void scx200_gpio_set_high(unsigned index) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | __SCx200_GPIO_BANK; | 
|  | 42 | __SCx200_GPIO_IOADDR; | 
|  | 43 | __SCx200_GPIO_SHADOW; | 
|  | 44 | __SCx200_GPIO_INDEX; | 
| Al Viro | 64b3361 | 2007-10-14 19:35:20 +0100 | [diff] [blame] | 45 | set_bit(index, shadow);	/* __set_bit()? */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | __SCx200_GPIO_OUT; | 
|  | 47 | } | 
|  | 48 |  | 
|  | 49 | /* drive the GPIO signal low */ | 
|  | 50 |  | 
| Jim Cromie | 55b8c04 | 2006-06-27 02:54:15 -0700 | [diff] [blame] | 51 | static inline void scx200_gpio_set_low(unsigned index) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | __SCx200_GPIO_BANK; | 
|  | 53 | __SCx200_GPIO_IOADDR; | 
|  | 54 | __SCx200_GPIO_SHADOW; | 
|  | 55 | __SCx200_GPIO_INDEX; | 
| Al Viro | 64b3361 | 2007-10-14 19:35:20 +0100 | [diff] [blame] | 56 | clear_bit(index, shadow); /* __clear_bit()? */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | __SCx200_GPIO_OUT; | 
|  | 58 | } | 
|  | 59 |  | 
|  | 60 | /* drive the GPIO signal to state */ | 
|  | 61 |  | 
| Jim Cromie | 55b8c04 | 2006-06-27 02:54:15 -0700 | [diff] [blame] | 62 | static inline void scx200_gpio_set(unsigned index, int state) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 */ | 
| Jim Cromie | 55b8c04 | 2006-06-27 02:54:15 -0700 | [diff] [blame] | 75 | static inline void scx200_gpio_change(unsigned index) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |