source: svn/trunk/newcon3bcm2_21bu/toolchain/mips-linux-uclibc/include/linux/scx200_gpio.h

Last change on this file was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 2.4 KB
Line 
1#include <asm/types.h>
2
3
4__u32 scx200_gpio_configure(int index, __u32 set, __u32 clear);
5
6extern unsigned scx200_gpio_base;
7extern long scx200_gpio_shadow[2];
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
21static inline int scx200_gpio_get(int index) {
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
33static inline int scx200_gpio_current(int index) {
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
42static inline void scx200_gpio_set_high(int index) {
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
53static inline void scx200_gpio_set_low(int index) {
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
64static inline void scx200_gpio_set(int index, int state) {
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 */
77static inline void scx200_gpio_change(int index) {
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
91
92/*
93    Local variables:
94        compile-command: "make -C ../.. bzImage modules"
95        c-basic-offset: 8
96    End:
97*/
Note: See TracBrowser for help on using the repository browser.