blob: d2b058130eb123586c95d843521f4cbbfdab6629 [file] [log] [blame]
Jim Cromie55b8c042006-06-27 02:54:15 -07001u32 scx200_gpio_configure(unsigned index, u32 set, u32 clear);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002
3extern unsigned scx200_gpio_base;
4extern long scx200_gpio_shadow[2];
Chris Boot58012cd2006-09-29 01:59:07 -07005extern struct nsc_gpio_ops scx200_gpio_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006
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
12#define __SCx200_GPIO_SHADOW long *shadow = scx200_gpio_shadow+bank
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 Cromie55b8c042006-06-27 02:54:15 -070019static inline int scx200_gpio_get(unsigned index) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 __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 Cromie55b8c042006-06-27 02:54:15 -070031static inline int scx200_gpio_current(unsigned index) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 __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 Cromie55b8c042006-06-27 02:54:15 -070040static inline void scx200_gpio_set_high(unsigned index) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 __SCx200_GPIO_BANK;
42 __SCx200_GPIO_IOADDR;
43 __SCx200_GPIO_SHADOW;
44 __SCx200_GPIO_INDEX;
45 set_bit(index, shadow);
46 __SCx200_GPIO_OUT;
47}
48
49/* drive the GPIO signal low */
50
Jim Cromie55b8c042006-06-27 02:54:15 -070051static inline void scx200_gpio_set_low(unsigned index) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 __SCx200_GPIO_BANK;
53 __SCx200_GPIO_IOADDR;
54 __SCx200_GPIO_SHADOW;
55 __SCx200_GPIO_INDEX;
56 clear_bit(index, shadow);
57 __SCx200_GPIO_OUT;
58}
59
60/* drive the GPIO signal to state */
61
Jim Cromie55b8c042006-06-27 02:54:15 -070062static inline void scx200_gpio_set(unsigned index, int state) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 __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 Cromie55b8c042006-06-27 02:54:15 -070075static inline void scx200_gpio_change(unsigned index) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 __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