1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#ifndef __AVR32_PORTMUX_GPIO_H__
23#define __AVR32_PORTMUX_GPIO_H__
24
25#include <asm/io.h>
26
27
28#include <asm/arch/gpio-impl.h>
29
30
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)
35
36
37
38enum portmux_function {
39 PORTMUX_FUNC_A,
40 PORTMUX_FUNC_B,
41 PORTMUX_FUNC_C,
42 PORTMUX_FUNC_D,
43};
44
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)
57
58void portmux_select_peripheral(void *port, unsigned long pin_mask,
59 enum portmux_function func, unsigned long flags);
60void portmux_select_gpio(void *port, unsigned long pin_mask,
61 unsigned long flags);
62
63
64
65static inline void *gpio_pin_to_port(unsigned int pin)
66{
67 return (void *)GPIO_BASE + (pin >> 5) * 0x200;
68}
69
70static inline void __gpio_set_output_value(void *port, unsigned int pin,
71 int value)
72{
73 if (value)
74 gpio_writel(port, OVRS, 1 << pin);
75 else
76 gpio_writel(port, OVRC, 1 << pin);
77}
78
79static inline int __gpio_get_input_value(void *port, unsigned int pin)
80{
81 return (gpio_readl(port, PVR) >> pin) & 1;
82}
83
84void gpio_set_output_value(unsigned int pin, int value);
85int gpio_get_input_value(unsigned int pin);
86
87
88
89
90
91
92
93
94__attribute__((always_inline))
95static inline void gpio_set_value(unsigned int pin, int value)
96{
97 if (__builtin_constant_p(pin))
98 __gpio_set_output_value(gpio_pin_to_port(pin),
99 pin & 0x1f, value);
100 else
101 gpio_set_output_value(pin, value);
102}
103
104__attribute__((always_inline))
105static inline int gpio_get_value(unsigned int pin)
106{
107 if (__builtin_constant_p(pin))
108 return __gpio_get_input_value(gpio_pin_to_port(pin),
109 pin & 0x1f);
110 else
111 return gpio_get_input_value(pin);
112}
113
114#endif
115