diff options
Diffstat (limited to 'include/gpio.h')
-rw-r--r-- | include/gpio.h | 64 |
1 files changed, 62 insertions, 2 deletions
diff --git a/include/gpio.h b/include/gpio.h index 4d5f2c25c7..adc1eb39ac 100644 --- a/include/gpio.h +++ b/include/gpio.h @@ -1,9 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ #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); @@ -32,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 @@ -60,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 @@ -114,6 +123,11 @@ static inline int gpio_request(unsigned gpio, const char *label) return 0; } +static inline int gpio_find_by_name(const char *name) +{ + return -ENOSYS; +} + static inline int gpio_find_by_label(const char *label) { return -ENOSYS; @@ -139,16 +153,30 @@ static inline void gpio_free_array(const struct gpio *array, size_t num) /* GPIO can never have been requested */ WARN_ON(1); } +static inline int gpio_array_to_id(const struct gpio *array, size_t num, u32 *val) +{ + 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); int gpio_find_by_label(const char *label); void gpio_free(unsigned gpio); 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); @@ -158,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 */ |