]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - include/linux/scx200_gpio.h
Merge branch 'upstream' into upstream-jgarzik
[mirror_ubuntu-artful-kernel.git] / include / linux / scx200_gpio.h
CommitLineData
1da177e4
LT
1#include <linux/spinlock.h>
2
55b8c045 3u32 scx200_gpio_configure(unsigned index, u32 set, u32 clear);
1da177e4
LT
4
5extern unsigned scx200_gpio_base;
6extern long scx200_gpio_shadow[2];
58012cd7 7extern struct nsc_gpio_ops scx200_gpio_ops;
1da177e4
LT
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
55b8c045 21static inline int scx200_gpio_get(unsigned index) {
1da177e4
LT
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
55b8c045 33static inline int scx200_gpio_current(unsigned index) {
1da177e4
LT
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
55b8c045 42static inline void scx200_gpio_set_high(unsigned index) {
1da177e4
LT
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
55b8c045 53static inline void scx200_gpio_set_low(unsigned index) {
1da177e4
LT
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
55b8c045 64static inline void scx200_gpio_set(unsigned index, int state) {
1da177e4
LT
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 */
55b8c045 77static inline void scx200_gpio_change(unsigned index) {
1da177e4
LT
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