Thomas Chou | dc394a4 | 2010-04-30 11:34:13 +0800 | [diff] [blame] | 1 | /* |
| 2 | * nios2 gpio driver |
| 3 | * |
| 4 | * This gpio core is described in http://nioswiki.com/GPIO |
| 5 | * bit[0] data |
| 6 | * bit[1] output enable |
| 7 | * |
| 8 | * when CONFIG_SYS_GPIO_BASE is not defined, board may provide |
| 9 | * its own driver. |
| 10 | * |
| 11 | * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw> |
| 12 | * |
| 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. |
| 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 | |
Thomas Chou | 5ae05c5 | 2010-06-09 09:51:09 +0800 | [diff] [blame^] | 24 | static inline int gpio_request(unsigned gpio, const char *label) |
| 25 | { |
| 26 | return 0; |
| 27 | } |
| 28 | |
Thomas Chou | dc394a4 | 2010-04-30 11:34:13 +0800 | [diff] [blame] | 29 | static inline int gpio_direction_input(unsigned gpio) |
| 30 | { |
| 31 | writel(1, CONFIG_SYS_GPIO_BASE + (gpio << 2)); |
| 32 | return 0; |
| 33 | } |
| 34 | |
| 35 | static inline int gpio_direction_output(unsigned gpio, int value) |
| 36 | { |
| 37 | writel(value ? 3 : 2, CONFIG_SYS_GPIO_BASE + (gpio << 2)); |
| 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | static inline int gpio_get_value(unsigned gpio) |
| 42 | { |
| 43 | return readl(CONFIG_SYS_GPIO_BASE + (gpio << 2)); |
| 44 | } |
| 45 | |
| 46 | static inline void gpio_set_value(unsigned gpio, int value) |
| 47 | { |
| 48 | writel(value ? 3 : 2, CONFIG_SYS_GPIO_BASE + (gpio << 2)); |
| 49 | } |
| 50 | #else |
Thomas Chou | 5ae05c5 | 2010-06-09 09:51:09 +0800 | [diff] [blame^] | 51 | extern int gpio_request(unsigned gpio, const char *label); |
Thomas Chou | dc394a4 | 2010-04-30 11:34:13 +0800 | [diff] [blame] | 52 | extern int gpio_direction_input(unsigned gpio); |
| 53 | extern int gpio_direction_output(unsigned gpio, int value); |
| 54 | extern int gpio_get_value(unsigned gpio); |
| 55 | extern void gpio_set_value(unsigned gpio, int value); |
| 56 | #endif /* CONFIG_SYS_GPIO_BASE */ |
| 57 | |
| 58 | #endif /* _ASM_NIOS2_GPIO_H_ */ |