0001
0002 #ifndef _ASM_GENERIC_GPIO_H
0003 #define _ASM_GENERIC_GPIO_H
0004
0005 #include <linux/types.h>
0006 #include <linux/errno.h>
0007
0008 #ifdef CONFIG_GPIOLIB
0009
0010 #include <linux/compiler.h>
0011 #include <linux/gpio/driver.h>
0012 #include <linux/gpio/consumer.h>
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027 #ifndef ARCH_NR_GPIOS
0028 #if defined(CONFIG_ARCH_NR_GPIO) && CONFIG_ARCH_NR_GPIO > 0
0029 #define ARCH_NR_GPIOS CONFIG_ARCH_NR_GPIO
0030 #else
0031 #define ARCH_NR_GPIOS 512
0032 #endif
0033 #endif
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 static inline bool gpio_is_valid(int number)
0045 {
0046 return number >= 0 && number < ARCH_NR_GPIOS;
0047 }
0048
0049 struct device;
0050 struct gpio;
0051 struct seq_file;
0052 struct module;
0053 struct device_node;
0054 struct gpio_desc;
0055
0056
0057 static inline struct gpio_chip *gpio_to_chip(unsigned gpio)
0058 {
0059 return gpiod_to_chip(gpio_to_desc(gpio));
0060 }
0061
0062
0063
0064
0065 extern int gpio_request(unsigned gpio, const char *label);
0066 extern void gpio_free(unsigned gpio);
0067
0068 static inline int gpio_direction_input(unsigned gpio)
0069 {
0070 return gpiod_direction_input(gpio_to_desc(gpio));
0071 }
0072 static inline int gpio_direction_output(unsigned gpio, int value)
0073 {
0074 return gpiod_direction_output_raw(gpio_to_desc(gpio), value);
0075 }
0076
0077 static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
0078 {
0079 return gpiod_set_debounce(gpio_to_desc(gpio), debounce);
0080 }
0081
0082 static inline int gpio_get_value_cansleep(unsigned gpio)
0083 {
0084 return gpiod_get_raw_value_cansleep(gpio_to_desc(gpio));
0085 }
0086 static inline void gpio_set_value_cansleep(unsigned gpio, int value)
0087 {
0088 return gpiod_set_raw_value_cansleep(gpio_to_desc(gpio), value);
0089 }
0090
0091
0092
0093
0094
0095
0096 static inline int __gpio_get_value(unsigned gpio)
0097 {
0098 return gpiod_get_raw_value(gpio_to_desc(gpio));
0099 }
0100 static inline void __gpio_set_value(unsigned gpio, int value)
0101 {
0102 return gpiod_set_raw_value(gpio_to_desc(gpio), value);
0103 }
0104
0105 static inline int __gpio_cansleep(unsigned gpio)
0106 {
0107 return gpiod_cansleep(gpio_to_desc(gpio));
0108 }
0109
0110 static inline int __gpio_to_irq(unsigned gpio)
0111 {
0112 return gpiod_to_irq(gpio_to_desc(gpio));
0113 }
0114
0115 extern int gpio_request_one(unsigned gpio, unsigned long flags, const char *label);
0116 extern int gpio_request_array(const struct gpio *array, size_t num);
0117 extern void gpio_free_array(const struct gpio *array, size_t num);
0118
0119
0120
0121
0122
0123 static inline int gpio_export(unsigned gpio, bool direction_may_change)
0124 {
0125 return gpiod_export(gpio_to_desc(gpio), direction_may_change);
0126 }
0127
0128 static inline int gpio_export_link(struct device *dev, const char *name,
0129 unsigned gpio)
0130 {
0131 return gpiod_export_link(dev, name, gpio_to_desc(gpio));
0132 }
0133
0134 static inline void gpio_unexport(unsigned gpio)
0135 {
0136 gpiod_unexport(gpio_to_desc(gpio));
0137 }
0138
0139 #else
0140
0141 #include <linux/kernel.h>
0142
0143 static inline bool gpio_is_valid(int number)
0144 {
0145
0146 return number >= 0;
0147 }
0148
0149
0150
0151
0152
0153 static inline int gpio_cansleep(unsigned gpio)
0154 {
0155 return 0;
0156 }
0157
0158 static inline int gpio_get_value_cansleep(unsigned gpio)
0159 {
0160 might_sleep();
0161 return __gpio_get_value(gpio);
0162 }
0163
0164 static inline void gpio_set_value_cansleep(unsigned gpio, int value)
0165 {
0166 might_sleep();
0167 __gpio_set_value(gpio, value);
0168 }
0169
0170 #endif
0171
0172 #endif