]>
git.ipfire.org Git - thirdparty/u-boot.git/blob - arch/avr32/include/asm/arch-common/portmux-gpio.h
2 * Copyright (C) 2008 Atmel Corporation
4 * SPDX-License-Identifier: GPL-2.0+
6 #ifndef __AVR32_PORTMUX_GPIO_H__
7 #define __AVR32_PORTMUX_GPIO_H__
11 /* Register layout for this specific device */
12 #include <asm/arch/gpio-impl.h>
14 /* Register access macros */
15 #define gpio_readl(port, reg) \
16 __raw_readl(&((struct gpio_regs *)port)->reg)
17 #define gpio_writel(gpio, reg, value) \
18 __raw_writel(value, &((struct gpio_regs *)port)->reg)
20 /* Portmux API starts here. See doc/README.AVR32-port-muxing */
22 enum portmux_function
{
29 #define PORTMUX_DIR_INPUT (0 << 0)
30 #define PORTMUX_DIR_OUTPUT (1 << 0)
31 #define PORTMUX_INIT_LOW (0 << 1)
32 #define PORTMUX_INIT_HIGH (1 << 1)
33 #define PORTMUX_PULL_UP (1 << 2)
34 #define PORTMUX_PULL_DOWN (2 << 2)
35 #define PORTMUX_BUSKEEPER (3 << 2)
36 #define PORTMUX_DRIVE_MIN (0 << 4)
37 #define PORTMUX_DRIVE_LOW (1 << 4)
38 #define PORTMUX_DRIVE_HIGH (2 << 4)
39 #define PORTMUX_DRIVE_MAX (3 << 4)
40 #define PORTMUX_OPEN_DRAIN (1 << 6)
42 void portmux_select_peripheral(void *port
, unsigned long pin_mask
,
43 enum portmux_function func
, unsigned long flags
);
44 void portmux_select_gpio(void *port
, unsigned long pin_mask
,
47 /* Internal helper functions */
49 static inline void *gpio_pin_to_port(unsigned int pin
)
51 return (void *)GPIO_BASE
+ (pin
>> 5) * 0x200;
54 static inline void __gpio_set_output_value(void *port
, unsigned int pin
,
58 gpio_writel(port
, OVRS
, 1 << pin
);
60 gpio_writel(port
, OVRC
, 1 << pin
);
63 static inline int __gpio_get_input_value(void *port
, unsigned int pin
)
65 return (gpio_readl(port
, PVR
) >> pin
) & 1;
68 void gpio_set_output_value(unsigned int pin
, int value
);
69 int gpio_get_input_value(unsigned int pin
);
71 /* GPIO API starts here */
74 * GCC doesn't realize that the constant case is extremely trivial,
75 * so we need to help it make the right decision by using
78 __attribute__((always_inline
))
79 static inline void gpio_set_value(unsigned int pin
, int value
)
81 if (__builtin_constant_p(pin
))
82 __gpio_set_output_value(gpio_pin_to_port(pin
),
85 gpio_set_output_value(pin
, value
);
88 __attribute__((always_inline
))
89 static inline int gpio_get_value(unsigned int pin
)
91 if (__builtin_constant_p(pin
))
92 return __gpio_get_input_value(gpio_pin_to_port(pin
),
95 return gpio_get_input_value(pin
);
98 #endif /* __AVR32_PORTMUX_GPIO_H__ */