4 * Copyright (C) 2011 Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
6 * based on nios2 gpio driver
7 * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>
9 * when CONFIG_SYS_GPIO_BASE is not defined, board may provide
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 #ifdef CONFIG_SYS_GPIO_BASE
31 static inline int gpio_request(unsigned gpio, const char *label)
36 static inline int gpio_free(unsigned gpio)
41 static inline int gpio_get_value(unsigned gpio)
43 return (readb(CONFIG_SYS_GPIO_BASE + gpio/8) >> gpio%8) & 0x1;
46 static inline void gpio_set_value(unsigned gpio, int value)
48 u8 tmp = readb(CONFIG_SYS_GPIO_BASE + gpio/8);
53 tmp &= ~(1 << gpio%8);
54 writeb(tmp, CONFIG_SYS_GPIO_BASE + gpio/8);
57 static inline int gpio_direction_input(unsigned gpio)
59 gpio_set_value(gpio + CONFIG_SYS_GPIO_WIDTH, 0);
64 static inline int gpio_direction_output(unsigned gpio, int value)
66 gpio_set_value(gpio + CONFIG_SYS_GPIO_WIDTH, 1);
67 gpio_set_value(gpio, value);
72 static inline int gpio_is_valid(int number)
74 return ((unsigned)number) < CONFIG_SYS_GPIO_WIDTH;
77 extern int gpio_request(unsigned gpio, const char *label);
78 extern int gpio_free(unsigned gpio);
79 extern int gpio_direction_input(unsigned gpio);
80 extern int gpio_direction_output(unsigned gpio, int value);
81 extern int gpio_get_value(unsigned gpio);
82 extern void gpio_set_value(unsigned gpio, int value);
83 extern int gpio_is_valid(int number);
84 #endif /* CONFIG_SYS_GPIO_BASE */