1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#ifndef _ASM_NIOS2_GPIO_H_
19#define _ASM_NIOS2_GPIO_H_
20
21#ifdef CONFIG_SYS_GPIO_BASE
22#include <asm/io.h>
23
24static inline int gpio_request(unsigned gpio, const char *label)
25{
26 return 0;
27}
28
29static inline int gpio_free(unsigned gpio)
30{
31 return 0;
32}
33
34static inline int gpio_direction_input(unsigned gpio)
35{
36 writel(1, CONFIG_SYS_GPIO_BASE + (gpio << 2));
37 return 0;
38}
39
40static inline int gpio_direction_output(unsigned gpio, int value)
41{
42 writel(value ? 3 : 2, CONFIG_SYS_GPIO_BASE + (gpio << 2));
43 return 0;
44}
45
46static inline int gpio_get_value(unsigned gpio)
47{
48 return readl(CONFIG_SYS_GPIO_BASE + (gpio << 2));
49}
50
51static inline void gpio_set_value(unsigned gpio, int value)
52{
53 writel(value ? 3 : 2, CONFIG_SYS_GPIO_BASE + (gpio << 2));
54}
55
56static inline int gpio_is_valid(int number)
57{
58 return ((unsigned)number) < CONFIG_SYS_GPIO_WIDTH;
59}
60#else
61#ifdef CONFIG_ALTERA_PIO
62extern int altera_pio_init(u32 base, u8 width, char iot,
63 u32 rstval, u32 negmask,
64 const char *label);
65
66extern void altera_pio_info(void);
67#define gpio_status() altera_pio_info()
68#endif
69
70extern int gpio_request(unsigned gpio, const char *label);
71extern int gpio_free(unsigned gpio);
72extern int gpio_direction_input(unsigned gpio);
73extern int gpio_direction_output(unsigned gpio, int value);
74extern int gpio_get_value(unsigned gpio);
75extern void gpio_set_value(unsigned gpio, int value);
76extern int gpio_is_valid(int number);
77#endif
78
79#endif
80