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 | |
Mark Brown | feb8369 | 2011-10-24 15:24:10 +0200 | [diff] [blame] | 20 | /** |
| 21 | * struct gpio - a structure describing a GPIO with configuration |
| 22 | * @gpio: the GPIO number |
| 23 | * @flags: GPIO configuration as specified by GPIOF_* |
| 24 | * @label: a literal description string of this GPIO |
| 25 | */ |
| 26 | struct gpio { |
| 27 | unsigned gpio; |
| 28 | unsigned long flags; |
| 29 | const char *label; |
| 30 | }; |
| 31 | |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 32 | #ifdef CONFIG_GENERIC_GPIO |
| 33 | #include <asm/gpio.h> |
| 34 | |
| 35 | #else |
| 36 | |
Uwe Kleine-König | 3d599d1 | 2008-10-15 22:03:12 -0700 | [diff] [blame] | 37 | #include <linux/kernel.h> |
David Brownell | 6ea0205 | 2008-05-23 13:04:58 -0700 | [diff] [blame] | 38 | #include <linux/types.h> |
| 39 | #include <linux/errno.h> |
| 40 | |
Jani Nikula | a4177ee | 2009-09-22 16:46:33 -0700 | [diff] [blame] | 41 | struct device; |
Anton Vorontsov | 4e4438b | 2010-09-01 08:55:24 -0600 | [diff] [blame] | 42 | struct gpio_chip; |
Jani Nikula | a4177ee | 2009-09-22 16:46:33 -0700 | [diff] [blame] | 43 | |
Joe Perches | 3474cb3 | 2011-05-10 16:23:07 -0700 | [diff] [blame] | 44 | static inline bool gpio_is_valid(int number) |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 45 | { |
Joe Perches | 3474cb3 | 2011-05-10 16:23:07 -0700 | [diff] [blame] | 46 | return false; |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 47 | } |
| 48 | |
Linus Torvalds | d8a3515 | 2011-01-13 17:26:46 -0800 | [diff] [blame] | 49 | static inline int gpio_request(unsigned gpio, const char *label) |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 50 | { |
| 51 | return -ENOSYS; |
| 52 | } |
| 53 | |
Wolfram Sang | 323b7fe | 2011-01-14 09:34:29 +0100 | [diff] [blame] | 54 | static inline int gpio_request_one(unsigned gpio, |
Wolfram Sang | 5f829e4 | 2011-01-12 17:00:24 -0800 | [diff] [blame] | 55 | unsigned long flags, const char *label) |
| 56 | { |
| 57 | return -ENOSYS; |
| 58 | } |
| 59 | |
Lars-Peter Clausen | 7c29597 | 2011-05-25 16:20:31 -0700 | [diff] [blame] | 60 | 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] | 61 | { |
| 62 | return -ENOSYS; |
| 63 | } |
| 64 | |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 65 | static inline void gpio_free(unsigned gpio) |
| 66 | { |
Uwe Kleine-König | 3d599d1 | 2008-10-15 22:03:12 -0700 | [diff] [blame] | 67 | might_sleep(); |
| 68 | |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 69 | /* GPIO can never have been requested */ |
| 70 | WARN_ON(1); |
| 71 | } |
| 72 | |
Lars-Peter Clausen | 7c29597 | 2011-05-25 16:20:31 -0700 | [diff] [blame] | 73 | 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] | 74 | { |
| 75 | might_sleep(); |
| 76 | |
| 77 | /* GPIO can never have been requested */ |
| 78 | WARN_ON(1); |
| 79 | } |
| 80 | |
Linus Torvalds | d8a3515 | 2011-01-13 17:26:46 -0800 | [diff] [blame] | 81 | static inline int gpio_direction_input(unsigned gpio) |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 82 | { |
| 83 | return -ENOSYS; |
| 84 | } |
| 85 | |
Linus Torvalds | d8a3515 | 2011-01-13 17:26:46 -0800 | [diff] [blame] | 86 | static inline int gpio_direction_output(unsigned gpio, int value) |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 87 | { |
| 88 | return -ENOSYS; |
| 89 | } |
| 90 | |
Felipe Balbi | c4b5be9 | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 91 | static inline int gpio_set_debounce(unsigned gpio, unsigned debounce) |
| 92 | { |
| 93 | return -ENOSYS; |
| 94 | } |
| 95 | |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 96 | static inline int gpio_get_value(unsigned gpio) |
| 97 | { |
| 98 | /* GPIO can never have been requested or set as {in,out}put */ |
| 99 | WARN_ON(1); |
| 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | static inline void gpio_set_value(unsigned gpio, int value) |
| 104 | { |
| 105 | /* GPIO can never have been requested or set as output */ |
| 106 | WARN_ON(1); |
| 107 | } |
| 108 | |
| 109 | static inline int gpio_cansleep(unsigned gpio) |
| 110 | { |
| 111 | /* GPIO can never have been requested or set as {in,out}put */ |
| 112 | WARN_ON(1); |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | static inline int gpio_get_value_cansleep(unsigned gpio) |
| 117 | { |
| 118 | /* GPIO can never have been requested or set as {in,out}put */ |
| 119 | WARN_ON(1); |
| 120 | return 0; |
| 121 | } |
| 122 | |
| 123 | static inline void gpio_set_value_cansleep(unsigned gpio, int value) |
| 124 | { |
| 125 | /* GPIO can never have been requested or set as output */ |
| 126 | WARN_ON(1); |
| 127 | } |
| 128 | |
David Brownell | d8f388d8 | 2008-07-25 01:46:07 -0700 | [diff] [blame] | 129 | static inline int gpio_export(unsigned gpio, bool direction_may_change) |
| 130 | { |
| 131 | /* GPIO can never have been requested or set as {in,out}put */ |
| 132 | WARN_ON(1); |
| 133 | return -EINVAL; |
| 134 | } |
| 135 | |
Jani Nikula | a4177ee | 2009-09-22 16:46:33 -0700 | [diff] [blame] | 136 | static inline int gpio_export_link(struct device *dev, const char *name, |
| 137 | unsigned gpio) |
| 138 | { |
| 139 | /* GPIO can never have been exported */ |
| 140 | WARN_ON(1); |
| 141 | return -EINVAL; |
| 142 | } |
| 143 | |
Jani Nikula | 0769746 | 2009-12-15 16:46:20 -0800 | [diff] [blame] | 144 | static inline int gpio_sysfs_set_active_low(unsigned gpio, int value) |
| 145 | { |
| 146 | /* GPIO can never have been requested */ |
| 147 | WARN_ON(1); |
| 148 | return -EINVAL; |
| 149 | } |
Jani Nikula | a4177ee | 2009-09-22 16:46:33 -0700 | [diff] [blame] | 150 | |
David Brownell | d8f388d8 | 2008-07-25 01:46:07 -0700 | [diff] [blame] | 151 | static inline void gpio_unexport(unsigned gpio) |
| 152 | { |
| 153 | /* GPIO can never have been exported */ |
| 154 | WARN_ON(1); |
| 155 | } |
| 156 | |
David Brownell | 7560fa6 | 2008-03-04 14:28:27 -0800 | [diff] [blame] | 157 | static inline int gpio_to_irq(unsigned gpio) |
| 158 | { |
| 159 | /* GPIO can never have been requested or set as input */ |
| 160 | WARN_ON(1); |
| 161 | return -EINVAL; |
| 162 | } |
| 163 | |
| 164 | static inline int irq_to_gpio(unsigned irq) |
| 165 | { |
| 166 | /* irq can never have been returned from gpio_to_irq() */ |
| 167 | WARN_ON(1); |
| 168 | return -EINVAL; |
| 169 | } |
| 170 | |
| 171 | #endif |
| 172 | |
| 173 | #endif /* __LINUX_GPIO_H */ |