David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 1 | #ifndef __LINUX_GPIO_H |
| 2 | #define __LINUX_GPIO_H |
| 3 | |
| 4 | /* see Documentation/gpio.txt */ |
| 5 | |
Randy Dunlap | c001fb7 | 2011-06-14 17:05:11 -0700 | [diff] [blame] | 6 | /* make these flag values available regardless of GPIO kconfig options */ |
| 7 | #define GPIOF_DIR_OUT (0 << 0) |
| 8 | #define GPIOF_DIR_IN (1 << 0) |
| 9 | |
| 10 | #define GPIOF_INIT_LOW (0 << 1) |
| 11 | #define GPIOF_INIT_HIGH (1 << 1) |
| 12 | |
| 13 | #define GPIOF_IN (GPIOF_DIR_IN) |
| 14 | #define GPIOF_OUT_INIT_LOW (GPIOF_DIR_OUT | GPIOF_INIT_LOW) |
| 15 | #define GPIOF_OUT_INIT_HIGH (GPIOF_DIR_OUT | GPIOF_INIT_HIGH) |
| 16 | |
Laxman Dewangan | aca5ce1 | 2012-02-17 20:26:21 +0530 | [diff] [blame] | 17 | /* Gpio pin is open drain */ |
| 18 | #define GPIOF_OPEN_DRAIN (1 << 2) |
| 19 | |
Laxman Dewangan | 25553ff | 2012-02-17 20:26:22 +0530 | [diff] [blame] | 20 | /* Gpio pin is open source */ |
| 21 | #define GPIOF_OPEN_SOURCE (1 << 3) |
| 22 | |
Wolfram Sang | fc3a1f0 | 2011-12-13 18:34:01 +0100 | [diff] [blame] | 23 | #define GPIOF_EXPORT (1 << 2) |
| 24 | #define GPIOF_EXPORT_CHANGEABLE (1 << 3) |
| 25 | #define GPIOF_EXPORT_DIR_FIXED (GPIOF_EXPORT) |
| 26 | #define GPIOF_EXPORT_DIR_CHANGEABLE (GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE) |
| 27 | |
Mark Brown | feb8369 | 2011-10-24 15:24:10 +0200 | [diff] [blame] | 28 | /** |
| 29 | * struct gpio - a structure describing a GPIO with configuration |
| 30 | * @gpio: the GPIO number |
| 31 | * @flags: GPIO configuration as specified by GPIOF_* |
| 32 | * @label: a literal description string of this GPIO |
| 33 | */ |
| 34 | struct gpio { |
| 35 | unsigned gpio; |
| 36 | unsigned long flags; |
| 37 | const char *label; |
| 38 | }; |
| 39 | |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 40 | #ifdef CONFIG_GENERIC_GPIO |
| 41 | #include <asm/gpio.h> |
| 42 | |
| 43 | #else |
| 44 | |
Uwe Kleine-König | 3d599d1 | 2008-10-15 22:03:12 -0700 | [diff] [blame] | 45 | #include <linux/kernel.h> |
David Brownell | 6ea0205 | 2008-05-23 13:04:58 -0700 | [diff] [blame] | 46 | #include <linux/types.h> |
| 47 | #include <linux/errno.h> |
Paul Gortmaker | 187f188 | 2011-11-23 20:12:59 -0500 | [diff] [blame] | 48 | #include <linux/bug.h> |
David Brownell | 6ea0205 | 2008-05-23 13:04:58 -0700 | [diff] [blame] | 49 | |
Jani Nikula | a4177ee | 2009-09-22 16:46:33 -0700 | [diff] [blame] | 50 | struct device; |
Anton Vorontsov | 4e4438b | 2010-09-01 08:55:24 -0600 | [diff] [blame] | 51 | struct gpio_chip; |
Jani Nikula | a4177ee | 2009-09-22 16:46:33 -0700 | [diff] [blame] | 52 | |
Joe Perches | 3474cb3 | 2011-05-10 16:23:07 -0700 | [diff] [blame] | 53 | static inline bool gpio_is_valid(int number) |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 54 | { |
Joe Perches | 3474cb3 | 2011-05-10 16:23:07 -0700 | [diff] [blame] | 55 | return false; |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 56 | } |
| 57 | |
Linus Torvalds | d8a3515 | 2011-01-13 17:26:46 -0800 | [diff] [blame] | 58 | static inline int gpio_request(unsigned gpio, const char *label) |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 59 | { |
| 60 | return -ENOSYS; |
| 61 | } |
| 62 | |
Mark Brown | 2c96922 | 2012-04-04 16:14:48 +0100 | [diff] [blame] | 63 | static inline int devm_gpio_request(struct device *dev, unsigned gpio, |
| 64 | const char *label) |
| 65 | { |
| 66 | return -ENOSYS; |
| 67 | } |
| 68 | |
Wolfram Sang | 323b7fe | 2011-01-14 09:34:29 +0100 | [diff] [blame] | 69 | static inline int gpio_request_one(unsigned gpio, |
Wolfram Sang | 5f829e4 | 2011-01-12 17:00:24 -0800 | [diff] [blame] | 70 | unsigned long flags, const char *label) |
| 71 | { |
| 72 | return -ENOSYS; |
| 73 | } |
| 74 | |
Lars-Peter Clausen | 7c29597 | 2011-05-25 16:20:31 -0700 | [diff] [blame] | 75 | static inline int gpio_request_array(const struct gpio *array, size_t num) |
Wolfram Sang | 5f829e4 | 2011-01-12 17:00:24 -0800 | [diff] [blame] | 76 | { |
| 77 | return -ENOSYS; |
| 78 | } |
| 79 | |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 80 | static inline void gpio_free(unsigned gpio) |
| 81 | { |
Uwe Kleine-König | 3d599d1 | 2008-10-15 22:03:12 -0700 | [diff] [blame] | 82 | might_sleep(); |
| 83 | |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 84 | /* GPIO can never have been requested */ |
| 85 | WARN_ON(1); |
| 86 | } |
| 87 | |
Mark Brown | 2c96922 | 2012-04-04 16:14:48 +0100 | [diff] [blame] | 88 | static inline void devm_gpio_free(struct device *dev, unsigned gpio) |
| 89 | { |
| 90 | might_sleep(); |
| 91 | |
| 92 | /* GPIO can never have been requested */ |
| 93 | WARN_ON(1); |
| 94 | } |
| 95 | |
Lars-Peter Clausen | 7c29597 | 2011-05-25 16:20:31 -0700 | [diff] [blame] | 96 | static inline void gpio_free_array(const struct gpio *array, size_t num) |
Wolfram Sang | 5f829e4 | 2011-01-12 17:00:24 -0800 | [diff] [blame] | 97 | { |
| 98 | might_sleep(); |
| 99 | |
| 100 | /* GPIO can never have been requested */ |
| 101 | WARN_ON(1); |
| 102 | } |
| 103 | |
Linus Torvalds | d8a3515 | 2011-01-13 17:26:46 -0800 | [diff] [blame] | 104 | static inline int gpio_direction_input(unsigned gpio) |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 105 | { |
| 106 | return -ENOSYS; |
| 107 | } |
| 108 | |
Linus Torvalds | d8a3515 | 2011-01-13 17:26:46 -0800 | [diff] [blame] | 109 | static inline int gpio_direction_output(unsigned gpio, int value) |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 110 | { |
| 111 | return -ENOSYS; |
| 112 | } |
| 113 | |
Felipe Balbi | c4b5be9 | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 114 | static inline int gpio_set_debounce(unsigned gpio, unsigned debounce) |
| 115 | { |
| 116 | return -ENOSYS; |
| 117 | } |
| 118 | |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 119 | static inline int gpio_get_value(unsigned gpio) |
| 120 | { |
| 121 | /* GPIO can never have been requested or set as {in,out}put */ |
| 122 | WARN_ON(1); |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | static inline void gpio_set_value(unsigned gpio, int value) |
| 127 | { |
| 128 | /* GPIO can never have been requested or set as output */ |
| 129 | WARN_ON(1); |
| 130 | } |
| 131 | |
| 132 | static inline int gpio_cansleep(unsigned gpio) |
| 133 | { |
| 134 | /* GPIO can never have been requested or set as {in,out}put */ |
| 135 | WARN_ON(1); |
| 136 | return 0; |
| 137 | } |
| 138 | |
| 139 | static inline int gpio_get_value_cansleep(unsigned gpio) |
| 140 | { |
| 141 | /* GPIO can never have been requested or set as {in,out}put */ |
| 142 | WARN_ON(1); |
| 143 | return 0; |
| 144 | } |
| 145 | |
| 146 | static inline void gpio_set_value_cansleep(unsigned gpio, int value) |
| 147 | { |
| 148 | /* GPIO can never have been requested or set as output */ |
| 149 | WARN_ON(1); |
| 150 | } |
| 151 | |
David Brownell | d8f388d | 2008-07-25 01:46:07 -0700 | [diff] [blame] | 152 | static inline int gpio_export(unsigned gpio, bool direction_may_change) |
| 153 | { |
| 154 | /* GPIO can never have been requested or set as {in,out}put */ |
| 155 | WARN_ON(1); |
| 156 | return -EINVAL; |
| 157 | } |
| 158 | |
Jani Nikula | a4177ee | 2009-09-22 16:46:33 -0700 | [diff] [blame] | 159 | static inline int gpio_export_link(struct device *dev, const char *name, |
| 160 | unsigned gpio) |
| 161 | { |
| 162 | /* GPIO can never have been exported */ |
| 163 | WARN_ON(1); |
| 164 | return -EINVAL; |
| 165 | } |
| 166 | |
Jani Nikula | 0769746 | 2009-12-15 16:46:20 -0800 | [diff] [blame] | 167 | static inline int gpio_sysfs_set_active_low(unsigned gpio, int value) |
| 168 | { |
| 169 | /* GPIO can never have been requested */ |
| 170 | WARN_ON(1); |
| 171 | return -EINVAL; |
| 172 | } |
Jani Nikula | a4177ee | 2009-09-22 16:46:33 -0700 | [diff] [blame] | 173 | |
David Brownell | d8f388d | 2008-07-25 01:46:07 -0700 | [diff] [blame] | 174 | static inline void gpio_unexport(unsigned gpio) |
| 175 | { |
| 176 | /* GPIO can never have been exported */ |
| 177 | WARN_ON(1); |
| 178 | } |
| 179 | |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 180 | static inline int gpio_to_irq(unsigned gpio) |
| 181 | { |
| 182 | /* GPIO can never have been requested or set as input */ |
| 183 | WARN_ON(1); |
| 184 | return -EINVAL; |
| 185 | } |
| 186 | |
| 187 | static inline int irq_to_gpio(unsigned irq) |
| 188 | { |
| 189 | /* irq can never have been returned from gpio_to_irq() */ |
| 190 | WARN_ON(1); |
| 191 | return -EINVAL; |
| 192 | } |
| 193 | |
| 194 | #endif |
| 195 | |
| 196 | #endif /* __LINUX_GPIO_H */ |