]> git.ipfire.org Git - people/ms/u-boot.git/blob - arch/openrisc/include/asm/gpio.h
Add GPL-2.0+ SPDX-License-Identifier to source files
[people/ms/u-boot.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 * SPDX-License-Identifier: GPL-2.0+
13 */
14
15 #ifdef CONFIG_SYS_GPIO_BASE
16 #include <asm/io.h>
17
18 static inline int gpio_request(unsigned gpio, const char *label)
19 {
20 return 0;
21 }
22
23 static inline int gpio_free(unsigned gpio)
24 {
25 return 0;
26 }
27
28 static inline int gpio_get_value(unsigned gpio)
29 {
30 return (readb(CONFIG_SYS_GPIO_BASE + gpio/8) >> gpio%8) & 0x1;
31 }
32
33 static inline void gpio_set_value(unsigned gpio, int value)
34 {
35 u8 tmp = readb(CONFIG_SYS_GPIO_BASE + gpio/8);
36
37 if (value)
38 tmp |= (1 << gpio%8);
39 else
40 tmp &= ~(1 << gpio%8);
41 writeb(tmp, CONFIG_SYS_GPIO_BASE + gpio/8);
42 }
43
44 static inline int gpio_direction_input(unsigned gpio)
45 {
46 gpio_set_value(gpio + CONFIG_SYS_GPIO_WIDTH, 0);
47
48 return 0;
49 }
50
51 static inline int gpio_direction_output(unsigned gpio, int value)
52 {
53 gpio_set_value(gpio + CONFIG_SYS_GPIO_WIDTH, 1);
54 gpio_set_value(gpio, value);
55
56 return 0;
57 }
58
59 static inline int gpio_is_valid(int number)
60 {
61 return ((unsigned)number) < CONFIG_SYS_GPIO_WIDTH;
62 }
63 #else
64 extern int gpio_request(unsigned gpio, const char *label);
65 extern int gpio_free(unsigned gpio);
66 extern int gpio_direction_input(unsigned gpio);
67 extern int gpio_direction_output(unsigned gpio, int value);
68 extern int gpio_get_value(unsigned gpio);
69 extern void gpio_set_value(unsigned gpio, int value);
70 extern int gpio_is_valid(int number);
71 #endif /* CONFIG_SYS_GPIO_BASE */