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
* SPDX-License-Identifier: GPL-2.0+
15
#ifdef CONFIG_SYS_GPIO_BASE
18
static inline int gpio_request(unsigned gpio, const char *label)
23
static inline int gpio_free(unsigned gpio)
28
static inline int gpio_get_value(unsigned gpio)
30
return (readb(CONFIG_SYS_GPIO_BASE + gpio/8) >> gpio%8) & 0x1;
33
static inline void gpio_set_value(unsigned gpio, int value)
35
u8 tmp = readb(CONFIG_SYS_GPIO_BASE + gpio/8);
40
tmp &= ~(1 << gpio%8);
41
writeb(tmp, CONFIG_SYS_GPIO_BASE + gpio/8);
44
static inline int gpio_direction_input(unsigned gpio)
46
gpio_set_value(gpio + CONFIG_SYS_GPIO_WIDTH, 0);
51
static inline int gpio_direction_output(unsigned gpio, int value)
53
gpio_set_value(gpio + CONFIG_SYS_GPIO_WIDTH, 1);
54
gpio_set_value(gpio, value);
59
static inline int gpio_is_valid(int number)
61
return ((unsigned)number) < CONFIG_SYS_GPIO_WIDTH;
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 */