0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef __LINUX_OF_GPIO_H
0011 #define __LINUX_OF_GPIO_H
0012
0013 #include <linux/compiler.h>
0014 #include <linux/gpio/driver.h>
0015 #include <linux/gpio.h> /* FIXME: Shouldn't be here */
0016 #include <linux/of.h>
0017
0018 struct device_node;
0019
0020
0021
0022
0023
0024
0025 enum of_gpio_flags {
0026 OF_GPIO_ACTIVE_LOW = 0x1,
0027 OF_GPIO_SINGLE_ENDED = 0x2,
0028 OF_GPIO_OPEN_DRAIN = 0x4,
0029 OF_GPIO_TRANSITORY = 0x8,
0030 OF_GPIO_PULL_UP = 0x10,
0031 OF_GPIO_PULL_DOWN = 0x20,
0032 OF_GPIO_PULL_DISABLE = 0x40,
0033 };
0034
0035 #ifdef CONFIG_OF_GPIO
0036
0037 #include <linux/kernel.h>
0038
0039
0040
0041
0042 struct of_mm_gpio_chip {
0043 struct gpio_chip gc;
0044 void (*save_regs)(struct of_mm_gpio_chip *mm_gc);
0045 void __iomem *regs;
0046 };
0047
0048 static inline struct of_mm_gpio_chip *to_of_mm_gpio_chip(struct gpio_chip *gc)
0049 {
0050 return container_of(gc, struct of_mm_gpio_chip, gc);
0051 }
0052
0053 extern int of_get_named_gpio_flags(const struct device_node *np,
0054 const char *list_name, int index, enum of_gpio_flags *flags);
0055
0056 extern int of_mm_gpiochip_add_data(struct device_node *np,
0057 struct of_mm_gpio_chip *mm_gc,
0058 void *data);
0059 static inline int of_mm_gpiochip_add(struct device_node *np,
0060 struct of_mm_gpio_chip *mm_gc)
0061 {
0062 return of_mm_gpiochip_add_data(np, mm_gc, NULL);
0063 }
0064 extern void of_mm_gpiochip_remove(struct of_mm_gpio_chip *mm_gc);
0065
0066 #else
0067
0068 #include <linux/errno.h>
0069
0070
0071 static inline int of_get_named_gpio_flags(const struct device_node *np,
0072 const char *list_name, int index, enum of_gpio_flags *flags)
0073 {
0074 if (flags)
0075 *flags = 0;
0076
0077 return -ENOSYS;
0078 }
0079
0080 #endif
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102 static inline int of_gpio_named_count(const struct device_node *np,
0103 const char *propname)
0104 {
0105 return of_count_phandle_with_args(np, propname, "#gpio-cells");
0106 }
0107
0108
0109
0110
0111
0112
0113
0114 static inline int of_gpio_count(const struct device_node *np)
0115 {
0116 return of_gpio_named_count(np, "gpios");
0117 }
0118
0119 static inline int of_get_gpio_flags(const struct device_node *np, int index,
0120 enum of_gpio_flags *flags)
0121 {
0122 return of_get_named_gpio_flags(np, "gpios", index, flags);
0123 }
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134 static inline int of_get_named_gpio(const struct device_node *np,
0135 const char *propname, int index)
0136 {
0137 return of_get_named_gpio_flags(np, propname, index, NULL);
0138 }
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148 static inline int of_get_gpio(const struct device_node *np, int index)
0149 {
0150 return of_get_gpio_flags(np, index, NULL);
0151 }
0152
0153 #endif