2 * Copyright (C) 2006, 2008 Atmel Corporation
4 * See file CREDITS for list of people who contributed to this
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 #include <asm/arch/memory-map.h>
26 #include <asm/arch/gpio.h>
28 void portmux_select_peripheral(void *port, unsigned long pin_mask,
29 enum portmux_function func, unsigned long flags)
31 if (flags & PORTMUX_PULL_UP)
32 pio_writel(port, PUER, pin_mask);
34 pio_writel(port, PUDR, pin_mask);
38 pio_writel(port, ASR, pin_mask);
41 pio_writel(port, BSR, pin_mask);
45 pio_writel(port, PDR, pin_mask);
48 void portmux_select_gpio(void *port, unsigned long pin_mask,
51 if (flags & PORTMUX_PULL_UP)
52 pio_writel(port, PUER, pin_mask);
54 pio_writel(port, PUDR, pin_mask);
56 if (flags & PORTMUX_OPEN_DRAIN)
57 pio_writel(port, MDER, pin_mask);
59 pio_writel(port, MDDR, pin_mask);
61 if (flags & PORTMUX_DIR_OUTPUT) {
62 if (flags & PORTMUX_INIT_HIGH)
63 pio_writel(port, SODR, pin_mask);
65 pio_writel(port, CODR, pin_mask);
66 pio_writel(port, OER, pin_mask);
68 pio_writel(port, ODR, pin_mask);
71 pio_writel(port, PER, pin_mask);
74 void pio_set_output_value(unsigned int pin, int value)
76 void *port = pio_pin_to_port(pin);
79 panic("Invalid GPIO pin %u\n", pin);
81 __pio_set_output_value(port, pin & 0x1f, value);
84 int pio_get_input_value(unsigned int pin)
86 void *port = pio_pin_to_port(pin);
89 panic("Invalid GPIO pin %u\n", pin);
91 return __pio_get_input_value(port, pin & 0x1f);