Thomas Chou | cedd341 | 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 | * |
Joachim Foerster | 03d67e1 | 2011-10-21 15:48:50 +0200 | [diff] [blame] | 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. |
Thomas Chou | cedd341 | 2010-04-30 11:34:13 +0800 | [diff] [blame] | 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 | 6db6c18 | 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 | e91d545 | 2010-12-24 15:19:44 +0800 | [diff] [blame] | 29 | static inline int gpio_free(unsigned gpio) |
| 30 | { |
| 31 | return 0; |
| 32 | } |
| 33 | |
Thomas Chou | cedd341 | 2010-04-30 11:34:13 +0800 | [diff] [blame] | 34 | static inline int gpio_direction_input(unsigned gpio) |
| 35 | { |
| 36 | writel(1, CONFIG_SYS_GPIO_BASE + (gpio << 2)); |
| 37 | return 0; |
| 38 | } |
| 39 | |
| 40 | static 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 | |
| 46 | static inline int gpio_get_value(unsigned gpio) |
| 47 | { |
| 48 | return readl(CONFIG_SYS_GPIO_BASE + (gpio << 2)); |
| 49 | } |
| 50 | |
| 51 | static inline void gpio_set_value(unsigned gpio, int value) |
| 52 | { |
| 53 | writel(value ? 3 : 2, CONFIG_SYS_GPIO_BASE + (gpio << 2)); |
| 54 | } |
Thomas Chou | d8a593c | 2010-12-27 10:46:01 +0800 | [diff] [blame] | 55 | |
| 56 | static inline int gpio_is_valid(int number) |
| 57 | { |
| 58 | return ((unsigned)number) < CONFIG_SYS_GPIO_WIDTH; |
| 59 | } |
Thomas Chou | cedd341 | 2010-04-30 11:34:13 +0800 | [diff] [blame] | 60 | #else |
Joachim Foerster | 03d67e1 | 2011-10-21 15:48:50 +0200 | [diff] [blame] | 61 | #ifdef CONFIG_ALTERA_PIO |
| 62 | extern int altera_pio_init(u32 base, u8 width, char iot, |
| 63 | u32 rstval, u32 negmask, |
| 64 | const char *label); |
| 65 | |
| 66 | extern void altera_pio_info(void); |
| 67 | #define gpio_status() altera_pio_info() |
| 68 | #endif |
| 69 | |
Thomas Chou | 6db6c18 | 2010-06-09 09:51:09 +0800 | [diff] [blame] | 70 | extern int gpio_request(unsigned gpio, const char *label); |
Thomas Chou | e91d545 | 2010-12-24 15:19:44 +0800 | [diff] [blame] | 71 | extern int gpio_free(unsigned gpio); |
Thomas Chou | cedd341 | 2010-04-30 11:34:13 +0800 | [diff] [blame] | 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); |
Thomas Chou | d8a593c | 2010-12-27 10:46:01 +0800 | [diff] [blame] | 76 | extern int gpio_is_valid(int number); |
Thomas Chou | cedd341 | 2010-04-30 11:34:13 +0800 | [diff] [blame] | 77 | #endif /* CONFIG_SYS_GPIO_BASE */ |
| 78 | |
| 79 | #endif /* _ASM_NIOS2_GPIO_H_ */ |