]>
git.ipfire.org Git - people/ms/u-boot.git/blob - include/asm-avr32/arch-common/portmux-gpio.h
1306cbe5dc9ecb0771c58980be040d1b6dd1b539
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 layout for this specific device */
28 #include <asm/arch/gpio-impl.h>
30 /* Register access macros */
31 #define gpio_readl(port, reg) \
32 __raw_readl(&((struct gpio_regs *)port)->reg)
33 #define gpio_writel(gpio, reg, value) \
34 __raw_writel(value, &((struct gpio_regs *)port)->reg)
36 /* Portmux API starts here. See doc/README.AVR32-port-muxing */
38 enum portmux_function
{
45 #define PORTMUX_DIR_INPUT (0 << 0)
46 #define PORTMUX_DIR_OUTPUT (1 << 0)
47 #define PORTMUX_INIT_LOW (0 << 1)
48 #define PORTMUX_INIT_HIGH (1 << 1)
49 #define PORTMUX_PULL_UP (1 << 2)
50 #define PORTMUX_PULL_DOWN (2 << 2)
51 #define PORTMUX_BUSKEEPER (3 << 2)
52 #define PORTMUX_DRIVE_MIN (0 << 4)
53 #define PORTMUX_DRIVE_LOW (1 << 4)
54 #define PORTMUX_DRIVE_HIGH (2 << 4)
55 #define PORTMUX_DRIVE_MAX (3 << 4)
56 #define PORTMUX_OPEN_DRAIN (1 << 6)
58 void portmux_select_peripheral(void *port
, unsigned long pin_mask
,
59 enum portmux_function func
, unsigned long flags
);
60 void portmux_select_gpio(void *port
, unsigned long pin_mask
,
63 /* Internal helper functions */
65 static inline void *gpio_pin_to_port(unsigned int pin
)
67 return (void *)GPIO_BASE
+ (pin
>> 5) * 0x200;
70 static inline void __gpio_set_output_value(void *port
, unsigned int pin
,
74 gpio_writel(port
, OVRS
, 1 << pin
);
76 gpio_writel(port
, OVRC
, 1 << pin
);
79 static inline int __gpio_get_input_value(void *port
, unsigned int pin
)
81 return (gpio_readl(port
, PVR
) >> pin
) & 1;
84 void gpio_set_output_value(unsigned int pin
, int value
);
85 int gpio_get_input_value(unsigned int pin
);
87 /* GPIO API starts here */
90 * GCC doesn't realize that the constant case is extremely trivial,
91 * so we need to help it make the right decision by using
94 __attribute__((always_inline
))
95 static inline void gpio_set_value(unsigned int pin
, int value
)
97 if (__builtin_constant_p(pin
))
98 __gpio_set_output_value(gpio_pin_to_port(pin
),
101 gpio_set_output_value(pin
, value
);
104 __attribute__((always_inline
))
105 static inline int gpio_get_value(unsigned int pin
)
107 if (__builtin_constant_p(pin
))
108 return __gpio_get_input_value(gpio_pin_to_port(pin
),
111 return gpio_get_input_value(pin
);
114 #endif /* __AVR32_PORTMUX_GPIO_H__ */