1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * ACPI helpers for GPIO API 4 * 5 * Copyright (C) 2012,2019 Intel Corporation 6 */ 7 8 #ifndef GPIOLIB_ACPI_H 9 #define GPIOLIB_ACPI_H 10 11 #include <linux/err.h> 12 #include <linux/errno.h> 13 #include <linux/types.h> 14 15 #include <linux/gpio/consumer.h> 16 17 struct acpi_device; 18 struct device; 19 struct fwnode_handle; 20 21 struct gpio_chip; 22 struct gpio_desc; 23 struct gpio_device; 24 25 /** 26 * struct acpi_gpio_info - ACPI GPIO specific information 27 * @adev: reference to ACPI device which consumes GPIO resource 28 * @flags: GPIO initialization flags 29 * @gpioint: if %true this GPIO is of type GpioInt otherwise type is GpioIo 30 * @pin_config: pin bias as provided by ACPI 31 * @polarity: interrupt polarity as provided by ACPI 32 * @triggering: triggering type as provided by ACPI 33 * @wake_capable: wake capability as provided by ACPI 34 * @debounce: debounce timeout as provided by ACPI 35 * @quirks: Linux specific quirks as provided by struct acpi_gpio_mapping 36 */ 37 struct acpi_gpio_info { 38 struct acpi_device *adev; 39 enum gpiod_flags flags; 40 bool gpioint; 41 int pin_config; 42 int polarity; 43 int triggering; 44 bool wake_capable; 45 unsigned int debounce; 46 unsigned int quirks; 47 }; 48 49 #ifdef CONFIG_ACPI 50 void acpi_gpiochip_add(struct gpio_chip *chip); 51 void acpi_gpiochip_remove(struct gpio_chip *chip); 52 53 void acpi_gpio_dev_init(struct gpio_chip *gc, struct gpio_device *gdev); 54 55 void acpi_gpiochip_request_interrupts(struct gpio_chip *chip); 56 void acpi_gpiochip_free_interrupts(struct gpio_chip *chip); 57 58 int acpi_gpio_update_gpiod_flags(enum gpiod_flags *flags, 59 struct acpi_gpio_info *info); 60 int acpi_gpio_update_gpiod_lookup_flags(unsigned long *lookupflags, 61 struct acpi_gpio_info *info); 62 63 struct gpio_desc *acpi_find_gpio(struct device *dev, 64 const char *con_id, 65 unsigned int idx, 66 enum gpiod_flags *dflags, 67 unsigned long *lookupflags); 68 struct gpio_desc *acpi_node_get_gpiod(struct fwnode_handle *fwnode, 69 const char *propname, int index, 70 struct acpi_gpio_info *info); 71 72 int acpi_gpio_count(struct device *dev, const char *con_id); 73 #else 74 static inline void acpi_gpiochip_add(struct gpio_chip *chip) { } 75 static inline void acpi_gpiochip_remove(struct gpio_chip *chip) { } 76 77 static inline void acpi_gpio_dev_init(struct gpio_chip *gc, struct gpio_device *gdev) { } 78 79 static inline void 80 acpi_gpiochip_request_interrupts(struct gpio_chip *chip) { } 81 82 static inline void 83 acpi_gpiochip_free_interrupts(struct gpio_chip *chip) { } 84 85 static inline int 86 acpi_gpio_update_gpiod_flags(enum gpiod_flags *flags, struct acpi_gpio_info *info) 87 { 88 return 0; 89 } 90 static inline int 91 acpi_gpio_update_gpiod_lookup_flags(unsigned long *lookupflags, 92 struct acpi_gpio_info *info) 93 { 94 return 0; 95 } 96 97 static inline struct gpio_desc * 98 acpi_find_gpio(struct device *dev, const char *con_id, 99 unsigned int idx, enum gpiod_flags *dflags, 100 unsigned long *lookupflags) 101 { 102 return ERR_PTR(-ENOENT); 103 } 104 static inline struct gpio_desc * 105 acpi_node_get_gpiod(struct fwnode_handle *fwnode, const char *propname, 106 int index, struct acpi_gpio_info *info) 107 { 108 return ERR_PTR(-ENXIO); 109 } 110 static inline int acpi_gpio_count(struct device *dev, const char *con_id) 111 { 112 return -ENODEV; 113 } 114 #endif 115 116 #endif /* GPIOLIB_ACPI_H */ 117