blob: 1a82d30c4b17eea493a8f1ff3fd6c293d48dc434 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include <linux/spinlock.h>
2
Jim Cromie55b8c042006-06-27 02:54:15 -07003u32 scx200_gpio_configure(unsigned index, u32 set, u32 clear);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004
5extern unsigned scx200_gpio_base;
6extern long scx200_gpio_shadow[2];
Chris Boot58012cd2006-09-29 01:59:07 -07007extern struct nsc_gpio_ops scx200_gpio_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
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 Cromie55b8c042006-06-27 02:54:15 -070021static inline int scx200_gpio_get(unsigned index) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 __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 Cromie55b8c042006-06-27 02:54:15 -070033static inline int scx200_gpio_current(unsigned index) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 __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 Cromie55b8c042006-06-27 02:54:15 -070042static inline void scx200_gpio_set_high(unsigned index) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 __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 Cromie55b8c042006-06-27 02:54:15 -070053static inline void scx200_gpio_set_low(unsigned index) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 __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 Cromie55b8c042006-06-27 02:54:15 -070064static inline void scx200_gpio_set(unsigned index, int state) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 __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 Cromie55b8c042006-06-27 02:54:15 -070077static inline void scx200_gpio_change(unsigned index) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 __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