2 * Memory Setup stuff - taken from blob memsetup.S
4 * Copyright (C) 2009 Jens Scharsig (js_at_ng@scharsoft.de)
6 * Copyright (C) 2005 HP Labs
8 * See file CREDITS for list of people who contributed to this
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 * As the code is right now, it expects all PIO ports A,B,C,...
31 * to be evenly spaced in the memory map:
32 * ATMEL_BASE_PIOA + port * sizeof at91pio_t
33 * This might not necessaryly be true in future Atmel SoCs.
34 * This code should be fixed to use a pointer array to the ports.
40 #include <asm/sizes.h>
41 #include <asm/arch/hardware.h>
42 #include <asm/arch/at91_pio.h>
44 int at91_set_pio_pullup(unsigned port, unsigned pin, int use_pullup)
46 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIOA;
49 if ((port < ATMEL_PIO_PORTS) && (pin < 32)) {
52 writel(1 << pin, &pio->port[port].puer);
54 writel(1 << pin, &pio->port[port].pudr);
55 writel(mask, &pio->port[port].per);
61 * mux the pin to the "GPIO" peripheral role.
63 int at91_set_pio_periph(unsigned port, unsigned pin, int use_pullup)
65 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIOA;
68 if ((port < ATMEL_PIO_PORTS) && (pin < 32)) {
70 writel(mask, &pio->port[port].idr);
71 at91_set_pio_pullup(port, pin, use_pullup);
72 writel(mask, &pio->port[port].per);
78 * mux the pin to the "A" internal peripheral role.
80 int at91_set_a_periph(unsigned port, unsigned pin, int use_pullup)
82 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIOA;
85 if ((port < ATMEL_PIO_PORTS) && (pin < 32)) {
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);
96 * mux the pin to the "B" internal peripheral role.
98 int at91_set_b_periph(unsigned port, unsigned pin, int use_pullup)
100 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIOA;
103 if ((port < ATMEL_PIO_PORTS) && (pin < 32)) {
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);
114 * mux the pin to the gpio controller (instead of "A" or "B" peripheral), and
115 * configure it for an input.
117 int at91_set_pio_input(unsigned port, u32 pin, int use_pullup)
119 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIOA;
122 if ((port < ATMEL_PIO_PORTS) && (pin < 32)) {
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);
133 * mux the pin to the gpio controller (instead of "A" or "B" peripheral),
134 * and configure it for an output.
136 int at91_set_pio_output(unsigned port, u32 pin, int value)
138 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIOA;
141 if ((port < ATMEL_PIO_PORTS) && (pin < 32)) {
143 writel(mask, &pio->port[port].idr);
144 writel(mask, &pio->port[port].pudr);
146 writel(mask, &pio->port[port].sodr);
148 writel(mask, &pio->port[port].codr);
149 writel(mask, &pio->port[port].oer);
150 writel(mask, &pio->port[port].per);
156 * enable/disable the glitch filter. mostly used with IRQ handling.
158 int at91_set_pio_deglitch(unsigned port, unsigned pin, int is_on)
160 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIOA;
163 if ((port < ATMEL_PIO_PORTS) && (pin < 32)) {
166 writel(mask, &pio->port[port].ifer);
168 writel(mask, &pio->port[port].ifdr);
174 * enable/disable the multi-driver. This is only valid for output and
175 * allows the output pin to run as an open collector output.
177 int at91_set_pio_multi_drive(unsigned port, unsigned pin, int is_on)
179 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIOA;
182 if ((port < ATMEL_PIO_PORTS) && (pin < 32)) {
185 writel(mask, &pio->port[port].mder);
187 writel(mask, &pio->port[port].mddr);
193 * assuming the pin is muxed as a gpio output, set its value.
195 int at91_set_pio_value(unsigned port, unsigned pin, int value)
197 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIOA;
200 if ((port < ATMEL_PIO_PORTS) && (pin < 32)) {
203 writel(mask, &pio->port[port].sodr);
205 writel(mask, &pio->port[port].codr);
211 * read the pin's value (works even if it's not muxed as a gpio).
213 int at91_get_pio_value(unsigned port, unsigned pin)
216 at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIOA;
219 if ((port < ATMEL_PIO_PORTS) && (pin < 32)) {
221 pdsr = readl(&pio->port[port].pdsr) & mask;