blob: 4b21c8f7f2ec6042023ba63f925bdc751271d239 [file] [log] [blame]
Thomas Choudc394a42010-04-30 11:34:13 +08001/*
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 Chou5ae05c52010-06-09 09:51:09 +080024static inline int gpio_request(unsigned gpio, const char *label)
25{
26 return 0;
27}
28
Thomas Chouc259ec82010-12-24 15:19:44 +080029static inline int gpio_free(unsigned gpio)
30{
31 return 0;
32}
33
Thomas Choudc394a42010-04-30 11:34:13 +080034static 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}
Thomas Chou5dbb29f2010-12-27 10:46:01 +080055
56static inline int gpio_is_valid(int number)
57{
58 return ((unsigned)number) < CONFIG_SYS_GPIO_WIDTH;
59}
Thomas Choudc394a42010-04-30 11:34:13 +080060#else
Thomas Chou5ae05c52010-06-09 09:51:09 +080061extern int gpio_request(unsigned gpio, const char *label);
Thomas Chouc259ec82010-12-24 15:19:44 +080062extern int gpio_free(unsigned gpio);
Thomas Choudc394a42010-04-30 11:34:13 +080063extern int gpio_direction_input(unsigned gpio);
64extern int gpio_direction_output(unsigned gpio, int value);
65extern int gpio_get_value(unsigned gpio);
66extern void gpio_set_value(unsigned gpio, int value);
Thomas Chou5dbb29f2010-12-27 10:46:01 +080067extern int gpio_is_valid(int number);
Thomas Choudc394a42010-04-30 11:34:13 +080068#endif /* CONFIG_SYS_GPIO_BASE */
69
70#endif /* _ASM_NIOS2_GPIO_H_ */