some fixes to the etrax build
[openwrt.git] / target / linux / etrax-2.6 / files / arch / cris / arch-v10 / drivers / gpio_syscalls.c
1 #include <linux/autoconf.h>
2
3 #include <linux/module.h>
4 #include <linux/sched.h>
5 #include <linux/slab.h>
6 #include <linux/ioport.h>
7 #include <linux/errno.h>
8 #include <linux/kernel.h>
9 #include <linux/fs.h>
10 #include <linux/string.h>
11 #include <linux/poll.h>
12 #include <linux/init.h>
13 #include <linux/interrupt.h>
14
15 #include <asm/uaccess.h>
16 #include <linux/gpio_syscalls.h>
17
18 #include <asm/etraxgpio.h>
19 #include <asm/arch/svinto.h>
20 #include <asm/io.h>
21 #include <asm/system.h>
22 #include <asm/irq.h>
23 #include <asm/arch/io_interface_mux.h>
24
25 #include <asm/unistd.h>
26
27
28 extern int errno;
29
30
31 asmlinkage void sys_gpiosetbits(unsigned char port, unsigned int bits){
32 switch(port){
33 case 'G':
34 case 'g':
35 *R_PORT_G_DATA = port_g_data_shadow |= bits;
36 break;
37
38 case 'A':
39 case 'a':
40 *R_PORT_PA_DATA = port_pa_data_shadow |= bits;
41 break;
42
43 case 'B':
44 case 'b':
45 *R_PORT_PB_DATA = port_pb_data_shadow |= bits;
46 break;
47
48 };
49 };
50
51
52 asmlinkage void sys_gpioclearbits(unsigned char port, unsigned int bits){
53 switch(port){
54 case 'G':
55 case 'g':
56 *R_PORT_G_DATA = port_g_data_shadow &= ~bits;
57 break;
58
59 case 'A':
60 case 'a':
61 *R_PORT_PA_DATA = port_pa_data_shadow &= ~bits;
62 break;
63
64 case 'B':
65 case 'b':
66 *R_PORT_PB_DATA = port_pb_data_shadow &= ~bits;
67 break;
68
69 };
70 };
71
72 asmlinkage void sys_gpiosetdir(unsigned char port, unsigned char dir, unsigned int bits){
73 if((dir=='I' )||(dir=='i')){
74 switch(port){
75 case 'G':
76 case 'g':
77 if(bits & (1<<0)){
78 genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, g0dir);
79 };
80 if((bits & 0x0000FF00)==0x0000FF00){
81 genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, g8_15dir);
82 };
83 if((bits & 0x00FF0000)==0x00FF0000){
84 genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, g16_23dir);
85 };
86 if(bits & (1<<24)){
87 genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, g24dir);
88 };
89 *R_GEN_CONFIG = genconfig_shadow;
90 break;
91
92 case 'A':
93 case 'a':
94 *R_PORT_PA_DIR = port_pa_dir_shadow &= ~(bits & 0xff);
95 break;
96
97 case 'B':
98 case 'b':
99 *R_PORT_PB_DIR = port_pb_dir_shadow &= ~(bits & 0xff);
100 break;
101 };
102 } else if((dir=='O' )||(dir=='o')){
103 switch(port){
104 case 'G':
105 case 'g':
106 if(bits & (1<<0)){
107 genconfig_shadow |= IO_MASK(R_GEN_CONFIG, g0dir);
108 };
109 if((bits & 0x0000FF00)==0x0000FF00){
110 genconfig_shadow |= IO_MASK(R_GEN_CONFIG, g8_15dir);
111 };
112 if((bits & 0x00FF0000)==0x00FF0000){
113 genconfig_shadow |= IO_MASK(R_GEN_CONFIG, g8_15dir);
114 };
115 if(bits & (1<<24)){
116 genconfig_shadow |= IO_MASK(R_GEN_CONFIG, g24dir);
117 };
118 *R_GEN_CONFIG = genconfig_shadow;
119 break;
120
121 case 'A':
122 case 'a':
123 *R_PORT_PA_DIR = port_pa_dir_shadow |= (bits & 0xff);
124 break;
125
126 case 'B':
127 case 'b':
128 *R_PORT_PB_DIR = port_pb_dir_shadow |= (bits & 0xff);
129 break;
130 };
131 };
132 };
133
134
135 asmlinkage void sys_gpiotogglebit(unsigned char port, unsigned int bits){
136 switch(port){
137 case 'G':
138 case 'g':
139 if(port_g_data_shadow & bits){
140 *R_PORT_G_DATA = port_g_data_shadow &= ~bits;
141 } else {
142 *R_PORT_G_DATA = port_g_data_shadow |= bits;
143 };
144 break;
145
146 case 'A':
147 case 'a':
148 if(*R_PORT_PA_DATA & bits){
149 *R_PORT_PA_DATA = port_pa_data_shadow &= ~(bits & 0xff);
150 } else {
151 *R_PORT_PA_DATA = port_pa_data_shadow |= (bits & 0xff);
152 };
153 break;
154
155 case 'B':
156 case 'b':
157 if(*R_PORT_PB_DATA & bits){
158 *R_PORT_PB_DATA = port_pb_data_shadow &= ~(bits & 0xff);
159 } else {
160 *R_PORT_PB_DATA = port_pb_data_shadow |= (bits & 0xff);
161 };
162 break;
163
164 };
165 };
166
167
168 asmlinkage unsigned int sys_gpiogetbits(unsigned char port, unsigned int bits){
169 unsigned int data = 0;
170 switch(port){
171 case 'G':
172 case 'g':
173 data = *R_PORT_G_DATA;
174 break;
175
176 case 'A':
177 case 'a':
178 data = *R_PORT_PA_DATA;
179 break;
180
181 case 'B':
182 case 'b':
183 data = *R_PORT_PB_DATA;
184 break;
185
186 };
187 data &= bits;
188 return data;
189 };
190
191
This page took 0.069325 seconds and 5 git commands to generate.