summaryrefslogtreecommitdiffstats
path: root/include/gpio.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/gpio.h')
-rw-r--r--include/gpio.h52
1 files changed, 50 insertions, 2 deletions
diff --git a/include/gpio.h b/include/gpio.h
index 81beb47309..adc1eb39ac 100644
--- a/include/gpio.h
+++ b/include/gpio.h
@@ -2,9 +2,11 @@
#ifndef __GPIO_H
#define __GPIO_H
+#include <slice.h>
#include <linux/types.h>
#include <linux/list.h>
#include <linux/iopoll.h>
+#include <linux/bitops.h>
#ifdef CONFIG_GENERIC_GPIO
void gpio_set_value(unsigned gpio, int value);
@@ -33,6 +35,7 @@ static inline int gpio_direction_input(unsigned gpio)
void gpio_set_active(unsigned gpio, bool state);
int gpio_is_active(unsigned gpio);
int gpio_direction_active(unsigned gpio, bool state);
+struct gpio_chip *gpio_get_chip_by_dev(struct device *);
/**
* gpio_poll_timeout_us - Poll till GPIO reaches requested active state
@@ -61,6 +64,11 @@ static inline int gpio_direction_active(unsigned gpio, int value)
return -EINVAL;
}
+static inline struct gpio_chip *gpio_get_chip_by_dev(struct device *dev)
+{
+ return NULL;
+}
+
#define gpio_poll_timeout_us(gpio, val, timeout_us) (-ENOSYS)
#endif
@@ -149,6 +157,12 @@ static inline int gpio_array_to_id(const struct gpio *array, size_t num, u32 *va
{
return -EINVAL;
}
+
+static inline bool gpio_slice_acquired(unsigned gpio)
+{
+ return false;
+}
+
#else
int gpio_request(unsigned gpio, const char *label);
int gpio_find_by_name(const char *name);
@@ -158,9 +172,11 @@ int gpio_request_one(unsigned gpio, unsigned long flags, const char *label);
int gpio_request_array(const struct gpio *array, size_t num);
void gpio_free_array(const struct gpio *array, size_t num);
int gpio_array_to_id(const struct gpio *array, size_t num, u32 *val);
+bool gpio_slice_acquired(unsigned gpio);
#endif
struct gpio_chip;
+struct of_phandle_args;
struct gpio_ops {
int (*request)(struct gpio_chip *chip, unsigned offset);
@@ -170,23 +186,55 @@ struct gpio_ops {
int (*get_direction)(struct gpio_chip *chip, unsigned offset);
int (*get)(struct gpio_chip *chip, unsigned offset);
void (*set)(struct gpio_chip *chip, unsigned offset, int value);
+
+#if defined(CONFIG_OF_GPIO)
+ /*
+ * If CONFIG_OF_GPIO is enabled, then all GPIO controllers described in
+ * the device tree automatically may have an OF translation
+ */
+
+ /**
+ * @of_xlate:
+ *
+ * Callback to translate a device tree GPIO specifier into a chip-
+ * relative GPIO number and flags.
+ */
+ int (*of_xlate)(struct gpio_chip *gc,
+ const struct of_phandle_args *gpiospec, u32 *flags);
+#endif
};
struct gpio_chip {
- struct device_d *dev;
+ struct device *dev;
int base;
int ngpio;
+#if defined(CONFIG_OF_GPIO)
+ /**
+ * @of_gpio_n_cells:
+ *
+ * Number of cells used to form the GPIO specifier.
+ */
+ unsigned int of_gpio_n_cells;
+#endif
+
struct gpio_ops *ops;
+ struct slice slice;
+
struct list_head list;
};
+static inline struct slice *gpiochip_slice(struct gpio_chip *chip)
+{
+ return &chip->slice;
+}
+
int gpiochip_add(struct gpio_chip *chip);
void gpiochip_remove(struct gpio_chip *chip);
-int gpio_get_num(struct device_d *dev, int gpio);
+int gpio_get_num(struct device *dev, int gpio);
struct gpio_chip *gpio_get_chip(int gpio);
#endif /* __GPIO_H */