1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37#include <config.h>
38#include <common.h>
39#include <asm/io.h>
40#include <asm/sizes.h>
41#include <asm/arch/hardware.h>
42#include <asm/arch/at91_pio.h>
43
44int at91_set_pio_pullup(unsigned port, unsigned pin, int use_pullup)
45{
46 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIOA;
47 u32 mask;
48
49 if ((port < ATMEL_PIO_PORTS) && (pin < 32)) {
50 mask = 1 << pin;
51 if (use_pullup)
52 writel(1 << pin, &pio->port[port].puer);
53 else
54 writel(1 << pin, &pio->port[port].pudr);
55 writel(mask, &pio->port[port].per);
56 }
57 return 0;
58}
59
60
61
62
63int at91_set_pio_periph(unsigned port, unsigned pin, int use_pullup)
64{
65 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIOA;
66 u32 mask;
67
68 if ((port < ATMEL_PIO_PORTS) && (pin < 32)) {
69 mask = 1 << pin;
70 writel(mask, &pio->port[port].idr);
71 at91_set_pio_pullup(port, pin, use_pullup);
72 writel(mask, &pio->port[port].per);
73 }
74 return 0;
75}
76
77
78
79
80int at91_set_a_periph(unsigned port, unsigned pin, int use_pullup)
81{
82 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIOA;
83 u32 mask;
84
85 if ((port < ATMEL_PIO_PORTS) && (pin < 32)) {
86 mask = 1 << pin;
87 writel(mask, &pio->port[port].idr);
88 at91_set_pio_pullup(port, pin, use_pullup);
89 writel(mask, &pio->port[port].asr);
90 writel(mask, &pio->port[port].pdr);
91 }
92 return 0;
93}
94
95
96
97
98int at91_set_b_periph(unsigned port, unsigned pin, int use_pullup)
99{
100 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIOA;
101 u32 mask;
102
103 if ((port < ATMEL_PIO_PORTS) && (pin < 32)) {
104 mask = 1 << pin;
105 writel(mask, &pio->port[port].idr);
106 at91_set_pio_pullup(port, pin, use_pullup);
107 writel(mask, &pio->port[port].bsr);
108 writel(mask, &pio->port[port].pdr);
109 }
110 return 0;
111}
112
113
114
115
116
117int at91_set_pio_input(unsigned port, u32 pin, int use_pullup)
118{
119 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIOA;
120 u32 mask;
121
122 if ((port < ATMEL_PIO_PORTS) && (pin < 32)) {
123 mask = 1 << pin;
124 writel(mask, &pio->port[port].idr);
125 at91_set_pio_pullup(port, pin, use_pullup);
126 writel(mask, &pio->port[port].odr);
127 writel(mask, &pio->port[port].per);
128 }
129 return 0;
130}
131
132
133
134
135
136int at91_set_pio_output(unsigned port, u32 pin, int value)
137{
138 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIOA;
139 u32 mask;
140
141 if ((port < ATMEL_PIO_PORTS) && (pin < 32)) {
142 mask = 1 << pin;
143 writel(mask, &pio->port[port].idr);
144 writel(mask, &pio->port[port].pudr);
145 if (value)
146 writel(mask, &pio->port[port].sodr);
147 else
148 writel(mask, &pio->port[port].codr);
149 writel(mask, &pio->port[port].oer);
150 writel(mask, &pio->port[port].per);
151 }
152 return 0;
153}
154
155
156
157
158int at91_set_pio_deglitch(unsigned port, unsigned pin, int is_on)
159{
160 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIOA;
161 u32 mask;
162
163 if ((port < ATMEL_PIO_PORTS) && (pin < 32)) {
164 mask = 1 << pin;
165 if (is_on)
166 writel(mask, &pio->port[port].ifer);
167 else
168 writel(mask, &pio->port[port].ifdr);
169 }
170 return 0;
171}
172
173
174
175
176
177int at91_set_pio_multi_drive(unsigned port, unsigned pin, int is_on)
178{
179 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIOA;
180 u32 mask;
181
182 if ((port < ATMEL_PIO_PORTS) && (pin < 32)) {
183 mask = 1 << pin;
184 if (is_on)
185 writel(mask, &pio->port[port].mder);
186 else
187 writel(mask, &pio->port[port].mddr);
188 }
189 return 0;
190}
191
192
193
194
195int at91_set_pio_value(unsigned port, unsigned pin, int value)
196{
197 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIOA;
198 u32 mask;
199
200 if ((port < ATMEL_PIO_PORTS) && (pin < 32)) {
201 mask = 1 << pin;
202 if (value)
203 writel(mask, &pio->port[port].sodr);
204 else
205 writel(mask, &pio->port[port].codr);
206 }
207 return 0;
208}
209
210
211
212
213int at91_get_pio_value(unsigned port, unsigned pin)
214{
215 u32 pdsr = 0;
216 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIOA;
217 u32 mask;
218
219 if ((port < ATMEL_PIO_PORTS) && (pin < 32)) {
220 mask = 1 << pin;
221 pdsr = readl(&pio->port[port].pdsr) & mask;
222 }
223 return pdsr != 0;
224}
225