2 * Copyright (C) 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,
22 #ifndef __AVR32_PORTMUX_GPIO_H__
23 #define __AVR32_PORTMUX_GPIO_H__
27 /* Register offsets */
109 /* Register access macros */
110 #define gpio_readl(port, reg) \
111 __raw_readl(&((struct gpio_regs *)port)->reg)
112 #define gpio_writel(gpio, reg, value) \
113 __raw_writel(value, &((struct gpio_regs *)port)->reg)
115 /* Portmux API starts here. See doc/README.AVR32-port-muxing */
117 enum portmux_function {
124 #define PORTMUX_DIR_INPUT (0 << 0)
125 #define PORTMUX_DIR_OUTPUT (1 << 0)
126 #define PORTMUX_INIT_LOW (0 << 1)
127 #define PORTMUX_INIT_HIGH (1 << 1)
128 #define PORTMUX_PULL_UP (1 << 2)
129 #define PORTMUX_PULL_DOWN (2 << 2)
130 #define PORTMUX_BUSKEEPER (3 << 2)
131 #define PORTMUX_DRIVE_MIN (0 << 4)
132 #define PORTMUX_DRIVE_LOW (1 << 4)
133 #define PORTMUX_DRIVE_HIGH (2 << 4)
134 #define PORTMUX_DRIVE_MAX (3 << 4)
135 #define PORTMUX_OPEN_DRAIN (1 << 6)
137 void portmux_select_peripheral(void *port, unsigned long pin_mask,
138 enum portmux_function func, unsigned long flags);
139 void portmux_select_gpio(void *port, unsigned long pin_mask,
140 unsigned long flags);
142 /* Internal helper functions */
144 static inline void *gpio_pin_to_port(unsigned int pin)
146 return (void *)GPIO_BASE + (pin >> 5) * 0x200;
149 static inline void __gpio_set_output_value(void *port, unsigned int pin,
153 gpio_writel(port, OVRS, 1 << pin);
155 gpio_writel(port, OVRC, 1 << pin);
158 static inline int __gpio_get_input_value(void *port, unsigned int pin)
160 return (gpio_readl(port, PVR) >> pin) & 1;
163 void gpio_set_output_value(unsigned int pin, int value);
164 int gpio_get_input_value(unsigned int pin);
166 /* GPIO API starts here */
169 * GCC doesn't realize that the constant case is extremely trivial,
170 * so we need to help it make the right decision by using
173 __attribute__((always_inline))
174 static inline void gpio_set_value(unsigned int pin, int value)
176 if (__builtin_constant_p(pin))
177 __gpio_set_output_value(gpio_pin_to_port(pin),
180 gpio_set_output_value(pin, value);
183 __attribute__((always_inline))
184 static inline int gpio_get_value(unsigned int pin)
186 if (__builtin_constant_p(pin))
187 return __gpio_get_input_value(gpio_pin_to_port(pin),
190 return gpio_get_input_value(pin);
193 #endif /* __AVR32_PORTMUX_GPIO_H__ */