Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v2.6.26-rc2 138 lines 4.3 kB view raw
1#ifndef _ASM_GENERIC_GPIO_H 2#define _ASM_GENERIC_GPIO_H 3 4#ifdef CONFIG_HAVE_GPIO_LIB 5 6/* Platforms may implement their GPIO interface with library code, 7 * at a small performance cost for non-inlined operations and some 8 * extra memory (for code and for per-GPIO table entries). 9 * 10 * While the GPIO programming interface defines valid GPIO numbers 11 * to be in the range 0..MAX_INT, this library restricts them to the 12 * smaller range 0..ARCH_NR_GPIOS. 13 */ 14 15#ifndef ARCH_NR_GPIOS 16#define ARCH_NR_GPIOS 256 17#endif 18 19static inline int gpio_is_valid(int number) 20{ 21 /* only some non-negative numbers are valid */ 22 return ((unsigned)number) < ARCH_NR_GPIOS; 23} 24 25struct seq_file; 26struct module; 27 28/** 29 * struct gpio_chip - abstract a GPIO controller 30 * @label: for diagnostics 31 * @direction_input: configures signal "offset" as input, or returns error 32 * @get: returns value for signal "offset"; for output signals this 33 * returns either the value actually sensed, or zero 34 * @direction_output: configures signal "offset" as output, or returns error 35 * @set: assigns output value for signal "offset" 36 * @dbg_show: optional routine to show contents in debugfs; default code 37 * will be used when this is omitted, but custom code can show extra 38 * state (such as pullup/pulldown configuration). 39 * @base: identifies the first GPIO number handled by this chip; or, if 40 * negative during registration, requests dynamic ID allocation. 41 * @ngpio: the number of GPIOs handled by this controller; the last GPIO 42 * handled is (base + ngpio - 1). 43 * @can_sleep: flag must be set iff get()/set() methods sleep, as they 44 * must while accessing GPIO expander chips over I2C or SPI 45 * 46 * A gpio_chip can help platforms abstract various sources of GPIOs so 47 * they can all be accessed through a common programing interface. 48 * Example sources would be SOC controllers, FPGAs, multifunction 49 * chips, dedicated GPIO expanders, and so on. 50 * 51 * Each chip controls a number of signals, identified in method calls 52 * by "offset" values in the range 0..(@ngpio - 1). When those signals 53 * are referenced through calls like gpio_get_value(gpio), the offset 54 * is calculated by subtracting @base from the gpio number. 55 */ 56struct gpio_chip { 57 char *label; 58 struct module *owner; 59 60 int (*direction_input)(struct gpio_chip *chip, 61 unsigned offset); 62 int (*get)(struct gpio_chip *chip, 63 unsigned offset); 64 int (*direction_output)(struct gpio_chip *chip, 65 unsigned offset, int value); 66 void (*set)(struct gpio_chip *chip, 67 unsigned offset, int value); 68 void (*dbg_show)(struct seq_file *s, 69 struct gpio_chip *chip); 70 int base; 71 u16 ngpio; 72 unsigned can_sleep:1; 73}; 74 75extern const char *gpiochip_is_requested(struct gpio_chip *chip, 76 unsigned offset); 77extern int __init __must_check gpiochip_reserve(int start, int ngpio); 78 79/* add/remove chips */ 80extern int gpiochip_add(struct gpio_chip *chip); 81extern int __must_check gpiochip_remove(struct gpio_chip *chip); 82 83 84/* Always use the library code for GPIO management calls, 85 * or when sleeping may be involved. 86 */ 87extern int gpio_request(unsigned gpio, const char *label); 88extern void gpio_free(unsigned gpio); 89 90extern int gpio_direction_input(unsigned gpio); 91extern int gpio_direction_output(unsigned gpio, int value); 92 93extern int gpio_get_value_cansleep(unsigned gpio); 94extern void gpio_set_value_cansleep(unsigned gpio, int value); 95 96 97/* A platform's <asm/gpio.h> code may want to inline the I/O calls when 98 * the GPIO is constant and refers to some always-present controller, 99 * giving direct access to chip registers and tight bitbanging loops. 100 */ 101extern int __gpio_get_value(unsigned gpio); 102extern void __gpio_set_value(unsigned gpio, int value); 103 104extern int __gpio_cansleep(unsigned gpio); 105 106 107#else 108 109static inline int gpio_is_valid(int number) 110{ 111 /* only non-negative numbers are valid */ 112 return number >= 0; 113} 114 115/* platforms that don't directly support access to GPIOs through I2C, SPI, 116 * or other blocking infrastructure can use these wrappers. 117 */ 118 119static inline int gpio_cansleep(unsigned gpio) 120{ 121 return 0; 122} 123 124static inline int gpio_get_value_cansleep(unsigned gpio) 125{ 126 might_sleep(); 127 return gpio_get_value(gpio); 128} 129 130static inline void gpio_set_value_cansleep(unsigned gpio, int value) 131{ 132 might_sleep(); 133 gpio_set_value(gpio, value); 134} 135 136#endif 137 138#endif /* _ASM_GENERIC_GPIO_H */