4 * This gpio core is described in http://nioswiki.com/GPIO
8 * When CONFIG_SYS_GPIO_BASE is not defined, the board may either
9 * provide its own driver or the altera_pio driver may be used.
11 * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2 as
15 * published by the Free Software Foundation.
18 #ifndef _ASM_NIOS2_GPIO_H_
19 #define _ASM_NIOS2_GPIO_H_
21 #ifdef CONFIG_SYS_GPIO_BASE
24 static inline int gpio_request(unsigned gpio, const char *label)
29 static inline int gpio_free(unsigned gpio)
34 static inline int gpio_direction_input(unsigned gpio)
36 writel(1, CONFIG_SYS_GPIO_BASE + (gpio << 2));
40 static inline int gpio_direction_output(unsigned gpio, int value)
42 writel(value ? 3 : 2, CONFIG_SYS_GPIO_BASE + (gpio << 2));
46 static inline int gpio_get_value(unsigned gpio)
48 return readl(CONFIG_SYS_GPIO_BASE + (gpio << 2));
51 static inline void gpio_set_value(unsigned gpio, int value)
53 writel(value ? 3 : 2, CONFIG_SYS_GPIO_BASE + (gpio << 2));
56 static inline int gpio_is_valid(int number)
58 return ((unsigned)number) < CONFIG_SYS_GPIO_WIDTH;
61 #ifdef CONFIG_ALTERA_PIO
62 extern int altera_pio_init(u32 base, u8 width, char iot,
63 u32 rstval, u32 negmask,
66 extern void altera_pio_info(void);
67 #define gpio_status() altera_pio_info()
70 extern int gpio_request(unsigned gpio, const char *label);
71 extern int gpio_free(unsigned gpio);
72 extern int gpio_direction_input(unsigned gpio);
73 extern int gpio_direction_output(unsigned gpio, int value);
74 extern int gpio_get_value(unsigned gpio);
75 extern void gpio_set_value(unsigned gpio, int value);
76 extern int gpio_is_valid(int number);
77 #endif /* CONFIG_SYS_GPIO_BASE */
79 #endif /* _ASM_NIOS2_GPIO_H_ */