]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/openrisc/include/asm/gpio.h
mxc_ipuv3: fix memory alignment of framebuffer
[karo-tx-uboot.git] / arch / openrisc / include / asm / gpio.h
1 /*
2  * OpenRISC gpio driver
3  *
4  * Copyright (C) 2011 Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
5  *
6  * based on nios2 gpio driver
7  * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>
8  *
9  * when CONFIG_SYS_GPIO_BASE is not defined, board may provide
10  * its own driver.
11  *
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.
16  *
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.
21  *
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,
25  * MA 02111-1307 USA
26  */
27
28 #ifdef CONFIG_SYS_GPIO_BASE
29 #include <asm/io.h>
30
31 static inline int gpio_request(unsigned gpio, const char *label)
32 {
33         return 0;
34 }
35
36 static inline int gpio_free(unsigned gpio)
37 {
38         return 0;
39 }
40
41 static inline int gpio_get_value(unsigned gpio)
42 {
43         return (readb(CONFIG_SYS_GPIO_BASE + gpio/8) >> gpio%8) & 0x1;
44 }
45
46 static inline void gpio_set_value(unsigned gpio, int value)
47 {
48         u8 tmp = readb(CONFIG_SYS_GPIO_BASE + gpio/8);
49
50         if (value)
51                 tmp |= (1 << gpio%8);
52         else
53                 tmp &= ~(1 << gpio%8);
54         writeb(tmp, CONFIG_SYS_GPIO_BASE + gpio/8);
55 }
56
57 static inline int gpio_direction_input(unsigned gpio)
58 {
59         gpio_set_value(gpio + CONFIG_SYS_GPIO_WIDTH, 0);
60
61         return 0;
62 }
63
64 static inline int gpio_direction_output(unsigned gpio, int value)
65 {
66         gpio_set_value(gpio + CONFIG_SYS_GPIO_WIDTH, 1);
67         gpio_set_value(gpio, value);
68
69         return 0;
70 }
71
72 static inline int gpio_is_valid(int number)
73 {
74         return ((unsigned)number) < CONFIG_SYS_GPIO_WIDTH;
75 }
76 #else
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 */