Linus Walleij | dae5f0a | 2018-09-25 09:08:48 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Mika Westerberg | 664e3e5 | 2014-01-08 12:40:54 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Internal GPIO functions. |
| 4 | * |
| 5 | * Copyright (C) 2013, Intel Corporation |
| 6 | * Author: Mika Westerberg <mika.westerberg@linux.intel.com> |
Mika Westerberg | 664e3e5 | 2014-01-08 12:40:54 +0200 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #ifndef GPIOLIB_H |
| 10 | #define GPIOLIB_H |
| 11 | |
Linus Walleij | ff2b135 | 2015-10-20 11:10:38 +0200 | [diff] [blame] | 12 | #include <linux/gpio/driver.h> |
Linus Walleij | 63f2dc0 | 2018-02-08 17:57:43 +0100 | [diff] [blame] | 13 | #include <linux/gpio/consumer.h> /* for enum gpiod_flags */ |
Mika Westerberg | 5ccff85 | 2014-01-08 12:40:56 +0200 | [diff] [blame] | 14 | #include <linux/err.h> |
| 15 | #include <linux/device.h> |
Linus Walleij | ff2b135 | 2015-10-20 11:10:38 +0200 | [diff] [blame] | 16 | #include <linux/module.h> |
| 17 | #include <linux/cdev.h> |
Mika Westerberg | 5ccff85 | 2014-01-08 12:40:56 +0200 | [diff] [blame] | 18 | |
Alexandre Courbot | f01d907 | 2014-05-17 14:54:50 +0900 | [diff] [blame] | 19 | enum of_gpio_flags; |
Linus Walleij | ea713bc | 2016-10-03 10:09:40 +0200 | [diff] [blame] | 20 | enum gpio_lookup_flags; |
Rafael J. Wysocki | ce79348 | 2015-03-16 23:49:03 +0100 | [diff] [blame] | 21 | struct acpi_device; |
| 22 | |
Mika Westerberg | 5ccff85 | 2014-01-08 12:40:56 +0200 | [diff] [blame] | 23 | /** |
Linus Walleij | ff2b135 | 2015-10-20 11:10:38 +0200 | [diff] [blame] | 24 | * struct gpio_device - internal state container for GPIO devices |
| 25 | * @id: numerical ID number for the GPIO chip |
| 26 | * @dev: the GPIO device struct |
Linus Walleij | 3c702e9 | 2015-10-21 15:29:53 +0200 | [diff] [blame] | 27 | * @chrdev: character device for the GPIO device |
Linus Walleij | afbc4f3 | 2016-02-09 13:21:06 +0100 | [diff] [blame] | 28 | * @mockdev: class device used by the deprecated sysfs interface (may be |
| 29 | * NULL) |
Linus Walleij | ff2b135 | 2015-10-20 11:10:38 +0200 | [diff] [blame] | 30 | * @owner: helps prevent removal of modules exporting active GPIOs |
| 31 | * @chip: pointer to the corresponding gpiochip, holding static |
| 32 | * data for this device |
Linus Walleij | 1c3cdb1 | 2016-02-09 13:51:59 +0100 | [diff] [blame] | 33 | * @descs: array of ngpio descriptors. |
Linus Walleij | fdeb8e1 | 2016-02-10 10:57:36 +0100 | [diff] [blame] | 34 | * @ngpio: the number of GPIO lines on this GPIO device, equal to the size |
| 35 | * of the @descs array. |
| 36 | * @base: GPIO base in the DEPRECATED global Linux GPIO numberspace, assigned |
| 37 | * at device creation time. |
Linus Walleij | df4878e | 2016-02-12 14:48:23 +0100 | [diff] [blame] | 38 | * @label: a descriptive name for the GPIO device, such as the part number |
| 39 | * or name of the IP component in a System on Chip. |
Linus Walleij | 43c54ec | 2016-02-11 11:37:48 +0100 | [diff] [blame] | 40 | * @data: per-instance data assigned by the driver |
Linus Walleij | ff2b135 | 2015-10-20 11:10:38 +0200 | [diff] [blame] | 41 | * @list: links gpio_device:s together for traversal |
| 42 | * |
| 43 | * This state container holds most of the runtime variable data |
| 44 | * for a GPIO device and can hold references and live on after the |
| 45 | * GPIO chip has been removed, if it is still being used from |
| 46 | * userspace. |
| 47 | */ |
| 48 | struct gpio_device { |
| 49 | int id; |
| 50 | struct device dev; |
Linus Walleij | 3c702e9 | 2015-10-21 15:29:53 +0200 | [diff] [blame] | 51 | struct cdev chrdev; |
Linus Walleij | afbc4f3 | 2016-02-09 13:21:06 +0100 | [diff] [blame] | 52 | struct device *mockdev; |
Linus Walleij | ff2b135 | 2015-10-20 11:10:38 +0200 | [diff] [blame] | 53 | struct module *owner; |
| 54 | struct gpio_chip *chip; |
Linus Walleij | 1c3cdb1 | 2016-02-09 13:51:59 +0100 | [diff] [blame] | 55 | struct gpio_desc *descs; |
Linus Walleij | fdeb8e1 | 2016-02-10 10:57:36 +0100 | [diff] [blame] | 56 | int base; |
| 57 | u16 ngpio; |
Bartosz Golaszewski | 3b469b0 | 2017-12-13 12:25:19 +0100 | [diff] [blame] | 58 | const char *label; |
Linus Walleij | 43c54ec | 2016-02-11 11:37:48 +0100 | [diff] [blame] | 59 | void *data; |
Linus Walleij | ff2b135 | 2015-10-20 11:10:38 +0200 | [diff] [blame] | 60 | struct list_head list; |
Linus Walleij | 20ec3e3 | 2016-02-11 11:03:06 +0100 | [diff] [blame] | 61 | |
| 62 | #ifdef CONFIG_PINCTRL |
| 63 | /* |
| 64 | * If CONFIG_PINCTRL is enabled, then gpio controllers can optionally |
| 65 | * describe the actual pin range which they serve in an SoC. This |
| 66 | * information would be used by pinctrl subsystem to configure |
| 67 | * corresponding pins for gpio usage. |
| 68 | */ |
| 69 | struct list_head pin_ranges; |
| 70 | #endif |
Linus Walleij | ff2b135 | 2015-10-20 11:10:38 +0200 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | /** |
Mika Westerberg | 5ccff85 | 2014-01-08 12:40:56 +0200 | [diff] [blame] | 74 | * struct acpi_gpio_info - ACPI GPIO specific information |
Andy Shevchenko | 5870cff47 | 2017-11-10 15:40:30 +0200 | [diff] [blame] | 75 | * @adev: reference to ACPI device which consumes GPIO resource |
Andy Shevchenko | a31f5c3 | 2017-05-23 20:03:23 +0300 | [diff] [blame] | 76 | * @flags: GPIO initialization flags |
Mika Westerberg | 5ccff85 | 2014-01-08 12:40:56 +0200 | [diff] [blame] | 77 | * @gpioint: if %true this GPIO is of type GpioInt otherwise type is GpioIo |
Andy Shevchenko | e567c35 | 2017-01-03 19:01:18 +0200 | [diff] [blame] | 78 | * @polarity: interrupt polarity as provided by ACPI |
| 79 | * @triggering: triggering type as provided by ACPI |
Andy Shevchenko | ce0929d | 2017-11-10 15:40:32 +0200 | [diff] [blame] | 80 | * @quirks: Linux specific quirks as provided by struct acpi_gpio_mapping |
Mika Westerberg | 5ccff85 | 2014-01-08 12:40:56 +0200 | [diff] [blame] | 81 | */ |
| 82 | struct acpi_gpio_info { |
Andy Shevchenko | 5870cff47 | 2017-11-10 15:40:30 +0200 | [diff] [blame] | 83 | struct acpi_device *adev; |
Andy Shevchenko | a31f5c3 | 2017-05-23 20:03:23 +0300 | [diff] [blame] | 84 | enum gpiod_flags flags; |
Mika Westerberg | 5ccff85 | 2014-01-08 12:40:56 +0200 | [diff] [blame] | 85 | bool gpioint; |
Christophe RICARD | 5204472 | 2015-12-23 23:25:34 +0100 | [diff] [blame] | 86 | int polarity; |
| 87 | int triggering; |
Andy Shevchenko | ce0929d | 2017-11-10 15:40:32 +0200 | [diff] [blame] | 88 | unsigned int quirks; |
Mika Westerberg | 5ccff85 | 2014-01-08 12:40:56 +0200 | [diff] [blame] | 89 | }; |
| 90 | |
Rojhalat Ibrahim | 7f2e553 | 2015-02-11 17:27:55 +0100 | [diff] [blame] | 91 | /* gpio suffixes used for ACPI and device tree lookup */ |
Andy Shevchenko | b23ec59 | 2018-07-09 21:47:27 +0300 | [diff] [blame] | 92 | static __maybe_unused const char * const gpio_suffixes[] = { "gpios", "gpio" }; |
Rojhalat Ibrahim | 7f2e553 | 2015-02-11 17:27:55 +0100 | [diff] [blame] | 93 | |
Linus Walleij | ea713bc | 2016-10-03 10:09:40 +0200 | [diff] [blame] | 94 | #ifdef CONFIG_OF_GPIO |
| 95 | struct gpio_desc *of_find_gpio(struct device *dev, |
| 96 | const char *con_id, |
| 97 | unsigned int idx, |
| 98 | enum gpio_lookup_flags *flags); |
Linus Walleij | e085294 | 2016-10-03 11:37:24 +0200 | [diff] [blame] | 99 | struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np, |
| 100 | const char *list_name, int index, enum of_gpio_flags *flags); |
Linus Walleij | f4c1181 | 2016-10-03 10:59:32 +0200 | [diff] [blame] | 101 | int of_gpiochip_add(struct gpio_chip *gc); |
| 102 | void of_gpiochip_remove(struct gpio_chip *gc); |
Linus Walleij | ea713bc | 2016-10-03 10:09:40 +0200 | [diff] [blame] | 103 | #else |
| 104 | static inline struct gpio_desc *of_find_gpio(struct device *dev, |
| 105 | const char *con_id, |
| 106 | unsigned int idx, |
| 107 | enum gpio_lookup_flags *flags) |
| 108 | { |
| 109 | return ERR_PTR(-ENOENT); |
| 110 | } |
Linus Walleij | e085294 | 2016-10-03 11:37:24 +0200 | [diff] [blame] | 111 | static inline struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np, |
| 112 | const char *list_name, int index, enum of_gpio_flags *flags) |
| 113 | { |
| 114 | return ERR_PTR(-ENOENT); |
| 115 | } |
Linus Walleij | f4c1181 | 2016-10-03 10:59:32 +0200 | [diff] [blame] | 116 | static inline int of_gpiochip_add(struct gpio_chip *gc) { return 0; } |
| 117 | static inline void of_gpiochip_remove(struct gpio_chip *gc) { } |
Linus Walleij | ea713bc | 2016-10-03 10:09:40 +0200 | [diff] [blame] | 118 | #endif /* CONFIG_OF_GPIO */ |
| 119 | |
Mika Westerberg | 664e3e5 | 2014-01-08 12:40:54 +0200 | [diff] [blame] | 120 | #ifdef CONFIG_ACPI |
| 121 | void acpi_gpiochip_add(struct gpio_chip *chip); |
| 122 | void acpi_gpiochip_remove(struct gpio_chip *chip); |
Mika Westerberg | 5ccff85 | 2014-01-08 12:40:56 +0200 | [diff] [blame] | 123 | |
Mika Westerberg | afa82fa | 2014-07-25 09:54:48 +0300 | [diff] [blame] | 124 | void acpi_gpiochip_request_interrupts(struct gpio_chip *chip); |
| 125 | void acpi_gpiochip_free_interrupts(struct gpio_chip *chip); |
| 126 | |
Andy Shevchenko | a31f5c3 | 2017-05-23 20:03:23 +0300 | [diff] [blame] | 127 | int acpi_gpio_update_gpiod_flags(enum gpiod_flags *flags, |
Andy Shevchenko | 5c34b6c | 2017-11-10 15:40:31 +0200 | [diff] [blame] | 128 | struct acpi_gpio_info *info); |
Andy Shevchenko | a31f5c3 | 2017-05-23 20:03:23 +0300 | [diff] [blame] | 129 | |
Linus Walleij | 031ba28 | 2016-10-03 10:40:03 +0200 | [diff] [blame] | 130 | struct gpio_desc *acpi_find_gpio(struct device *dev, |
| 131 | const char *con_id, |
| 132 | unsigned int idx, |
Andy Shevchenko | a31f5c3 | 2017-05-23 20:03:23 +0300 | [diff] [blame] | 133 | enum gpiod_flags *dflags, |
Linus Walleij | 031ba28 | 2016-10-03 10:40:03 +0200 | [diff] [blame] | 134 | enum gpio_lookup_flags *lookupflags); |
Rafael J. Wysocki | 504a337 | 2015-08-27 04:42:33 +0200 | [diff] [blame] | 135 | struct gpio_desc *acpi_node_get_gpiod(struct fwnode_handle *fwnode, |
| 136 | const char *propname, int index, |
| 137 | struct acpi_gpio_info *info); |
Rojhalat Ibrahim | 6685852 | 2015-02-11 17:27:58 +0100 | [diff] [blame] | 138 | |
| 139 | int acpi_gpio_count(struct device *dev, const char *con_id); |
Dmitry Torokhov | 10cf489 | 2015-11-11 11:45:30 -0800 | [diff] [blame] | 140 | |
| 141 | bool acpi_can_fallback_to_crs(struct acpi_device *adev, const char *con_id); |
Mika Westerberg | 664e3e5 | 2014-01-08 12:40:54 +0200 | [diff] [blame] | 142 | #else |
| 143 | static inline void acpi_gpiochip_add(struct gpio_chip *chip) { } |
| 144 | static inline void acpi_gpiochip_remove(struct gpio_chip *chip) { } |
Mika Westerberg | 5ccff85 | 2014-01-08 12:40:56 +0200 | [diff] [blame] | 145 | |
Mika Westerberg | afa82fa | 2014-07-25 09:54:48 +0300 | [diff] [blame] | 146 | static inline void |
| 147 | acpi_gpiochip_request_interrupts(struct gpio_chip *chip) { } |
| 148 | |
| 149 | static inline void |
| 150 | acpi_gpiochip_free_interrupts(struct gpio_chip *chip) { } |
| 151 | |
Andy Shevchenko | a31f5c3 | 2017-05-23 20:03:23 +0300 | [diff] [blame] | 152 | static inline int |
Andy Shevchenko | 5c34b6c | 2017-11-10 15:40:31 +0200 | [diff] [blame] | 153 | acpi_gpio_update_gpiod_flags(enum gpiod_flags *flags, struct acpi_gpio_info *info) |
Andy Shevchenko | a31f5c3 | 2017-05-23 20:03:23 +0300 | [diff] [blame] | 154 | { |
| 155 | return 0; |
| 156 | } |
| 157 | |
Mika Westerberg | 5ccff85 | 2014-01-08 12:40:56 +0200 | [diff] [blame] | 158 | static inline struct gpio_desc * |
Linus Walleij | 031ba28 | 2016-10-03 10:40:03 +0200 | [diff] [blame] | 159 | acpi_find_gpio(struct device *dev, const char *con_id, |
Andy Shevchenko | a31f5c3 | 2017-05-23 20:03:23 +0300 | [diff] [blame] | 160 | unsigned int idx, enum gpiod_flags *dflags, |
Linus Walleij | 031ba28 | 2016-10-03 10:40:03 +0200 | [diff] [blame] | 161 | enum gpio_lookup_flags *lookupflags) |
Mika Westerberg | 5ccff85 | 2014-01-08 12:40:56 +0200 | [diff] [blame] | 162 | { |
Linus Walleij | 031ba28 | 2016-10-03 10:40:03 +0200 | [diff] [blame] | 163 | return ERR_PTR(-ENOENT); |
Mika Westerberg | 5ccff85 | 2014-01-08 12:40:56 +0200 | [diff] [blame] | 164 | } |
Rafael J. Wysocki | 504a337 | 2015-08-27 04:42:33 +0200 | [diff] [blame] | 165 | static inline struct gpio_desc * |
| 166 | acpi_node_get_gpiod(struct fwnode_handle *fwnode, const char *propname, |
| 167 | int index, struct acpi_gpio_info *info) |
| 168 | { |
| 169 | return ERR_PTR(-ENXIO); |
| 170 | } |
Rojhalat Ibrahim | 6685852 | 2015-02-11 17:27:58 +0100 | [diff] [blame] | 171 | static inline int acpi_gpio_count(struct device *dev, const char *con_id) |
| 172 | { |
| 173 | return -ENODEV; |
| 174 | } |
Dmitry Torokhov | 10cf489 | 2015-11-11 11:45:30 -0800 | [diff] [blame] | 175 | |
| 176 | static inline bool acpi_can_fallback_to_crs(struct acpi_device *adev, |
| 177 | const char *con_id) |
| 178 | { |
| 179 | return false; |
| 180 | } |
Mika Westerberg | 664e3e5 | 2014-01-08 12:40:54 +0200 | [diff] [blame] | 181 | #endif |
| 182 | |
Janusz Krzysztofik | bf9346f | 2018-09-05 23:50:06 +0200 | [diff] [blame] | 183 | struct gpio_array { |
| 184 | struct gpio_desc **desc; |
| 185 | unsigned int size; |
| 186 | struct gpio_chip *chip; |
| 187 | unsigned long *get_mask; |
| 188 | unsigned long *set_mask; |
| 189 | unsigned long invert_mask[]; |
| 190 | }; |
| 191 | |
Alexandre Courbot | 1bd6b60 | 2014-07-22 16:17:41 +0900 | [diff] [blame] | 192 | struct gpio_desc *gpiochip_get_desc(struct gpio_chip *chip, u16 hwnum); |
Lukas Wunner | eec1d56 | 2017-10-12 12:40:10 +0200 | [diff] [blame] | 193 | int gpiod_get_array_value_complex(bool raw, bool can_sleep, |
| 194 | unsigned int array_size, |
| 195 | struct gpio_desc **desc_array, |
Janusz Krzysztofik | 77588c1 | 2018-09-05 23:50:07 +0200 | [diff] [blame] | 196 | struct gpio_array *array_info, |
Janusz Krzysztofik | b9762be | 2018-09-05 23:50:05 +0200 | [diff] [blame] | 197 | unsigned long *value_bitmap); |
Laura Abbott | 3027743 | 2018-05-21 10:57:07 -0700 | [diff] [blame] | 198 | int gpiod_set_array_value_complex(bool raw, bool can_sleep, |
Geert Uytterhoeven | 3c94066 | 2018-09-27 13:38:10 +0200 | [diff] [blame] | 199 | unsigned int array_size, |
| 200 | struct gpio_desc **desc_array, |
| 201 | struct gpio_array *array_info, |
| 202 | unsigned long *value_bitmap); |
Alexandre Courbot | 1bd6b60 | 2014-07-22 16:17:41 +0900 | [diff] [blame] | 203 | |
Linus Walleij | 92542ed | 2017-12-29 22:52:02 +0100 | [diff] [blame] | 204 | /* This is just passed between gpiolib and devres */ |
| 205 | struct gpio_desc *gpiod_get_from_of_node(struct device_node *node, |
| 206 | const char *propname, int index, |
| 207 | enum gpiod_flags dflags, |
| 208 | const char *label); |
| 209 | |
Alexandre Courbot | 0eb4c6c | 2014-07-01 14:45:15 +0900 | [diff] [blame] | 210 | extern struct spinlock gpio_lock; |
Linus Walleij | ff2b135 | 2015-10-20 11:10:38 +0200 | [diff] [blame] | 211 | extern struct list_head gpio_devices; |
Alexandre Courbot | 0eb4c6c | 2014-07-01 14:45:15 +0900 | [diff] [blame] | 212 | |
| 213 | struct gpio_desc { |
Linus Walleij | fdeb8e1 | 2016-02-10 10:57:36 +0100 | [diff] [blame] | 214 | struct gpio_device *gdev; |
Alexandre Courbot | 0eb4c6c | 2014-07-01 14:45:15 +0900 | [diff] [blame] | 215 | unsigned long flags; |
| 216 | /* flag symbols are bit numbers */ |
| 217 | #define FLAG_REQUESTED 0 |
| 218 | #define FLAG_IS_OUT 1 |
| 219 | #define FLAG_EXPORT 2 /* protected by sysfs_lock */ |
| 220 | #define FLAG_SYSFS 3 /* exported via /sys/class/gpio/control */ |
Alexandre Courbot | 0eb4c6c | 2014-07-01 14:45:15 +0900 | [diff] [blame] | 221 | #define FLAG_ACTIVE_LOW 6 /* value has active low */ |
| 222 | #define FLAG_OPEN_DRAIN 7 /* Gpio is open drain type */ |
| 223 | #define FLAG_OPEN_SOURCE 8 /* Gpio is open source type */ |
| 224 | #define FLAG_USED_AS_IRQ 9 /* GPIO is connected to an IRQ */ |
Hans Verkuil | 4e9439d | 2018-09-08 11:23:16 +0200 | [diff] [blame] | 225 | #define FLAG_IRQ_IS_ENABLED 10 /* GPIO is connected to an enabled IRQ */ |
Benoit Parrot | f625d46 | 2015-02-02 11:44:44 -0600 | [diff] [blame] | 226 | #define FLAG_IS_HOGGED 11 /* GPIO is hogged */ |
Andrew Jeffery | e10f72b | 2017-11-30 14:25:24 +1030 | [diff] [blame] | 227 | #define FLAG_TRANSITORY 12 /* GPIO may lose value in sleep or reset */ |
Alexandre Courbot | 0eb4c6c | 2014-07-01 14:45:15 +0900 | [diff] [blame] | 228 | |
Markus Pargmann | c0017ed | 2015-08-14 16:10:59 +0200 | [diff] [blame] | 229 | /* Connection label */ |
Alexandre Courbot | 0eb4c6c | 2014-07-01 14:45:15 +0900 | [diff] [blame] | 230 | const char *label; |
Markus Pargmann | c0017ed | 2015-08-14 16:10:59 +0200 | [diff] [blame] | 231 | /* Name of the GPIO */ |
| 232 | const char *name; |
Alexandre Courbot | 0eb4c6c | 2014-07-01 14:45:15 +0900 | [diff] [blame] | 233 | }; |
| 234 | |
| 235 | int gpiod_request(struct gpio_desc *desc, const char *label); |
| 236 | void gpiod_free(struct gpio_desc *desc); |
Andy Shevchenko | c29fd9e | 2017-05-23 20:03:16 +0300 | [diff] [blame] | 237 | int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id, |
| 238 | unsigned long lflags, enum gpiod_flags dflags); |
Benoit Parrot | f625d46 | 2015-02-02 11:44:44 -0600 | [diff] [blame] | 239 | int gpiod_hog(struct gpio_desc *desc, const char *name, |
| 240 | unsigned long lflags, enum gpiod_flags dflags); |
Alexandre Courbot | 0eb4c6c | 2014-07-01 14:45:15 +0900 | [diff] [blame] | 241 | |
| 242 | /* |
| 243 | * Return the GPIO number of the passed descriptor relative to its chip |
| 244 | */ |
Masahiro Yamada | 4a5c886 | 2017-07-11 23:41:43 +0900 | [diff] [blame] | 245 | static inline int gpio_chip_hwgpio(const struct gpio_desc *desc) |
Alexandre Courbot | 0eb4c6c | 2014-07-01 14:45:15 +0900 | [diff] [blame] | 246 | { |
Linus Walleij | fdeb8e1 | 2016-02-10 10:57:36 +0100 | [diff] [blame] | 247 | return desc - &desc->gdev->descs[0]; |
Alexandre Courbot | 0eb4c6c | 2014-07-01 14:45:15 +0900 | [diff] [blame] | 248 | } |
| 249 | |
Christophe Leroy | 8227033 | 2017-12-15 15:02:33 +0100 | [diff] [blame] | 250 | void devprop_gpiochip_set_names(struct gpio_chip *chip, |
| 251 | const struct fwnode_handle *fwnode); |
Mika Westerberg | 9427ecb | 2016-10-21 17:21:31 +0300 | [diff] [blame] | 252 | |
Alexandre Courbot | 0eb4c6c | 2014-07-01 14:45:15 +0900 | [diff] [blame] | 253 | /* With descriptor prefix */ |
| 254 | |
| 255 | #define gpiod_emerg(desc, fmt, ...) \ |
| 256 | pr_emerg("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?",\ |
| 257 | ##__VA_ARGS__) |
| 258 | #define gpiod_crit(desc, fmt, ...) \ |
| 259 | pr_crit("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \ |
| 260 | ##__VA_ARGS__) |
| 261 | #define gpiod_err(desc, fmt, ...) \ |
| 262 | pr_err("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \ |
| 263 | ##__VA_ARGS__) |
| 264 | #define gpiod_warn(desc, fmt, ...) \ |
| 265 | pr_warn("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \ |
| 266 | ##__VA_ARGS__) |
| 267 | #define gpiod_info(desc, fmt, ...) \ |
| 268 | pr_info("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \ |
| 269 | ##__VA_ARGS__) |
| 270 | #define gpiod_dbg(desc, fmt, ...) \ |
| 271 | pr_debug("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?",\ |
| 272 | ##__VA_ARGS__) |
| 273 | |
| 274 | /* With chip prefix */ |
| 275 | |
| 276 | #define chip_emerg(chip, fmt, ...) \ |
Linus Walleij | 34ffd85 | 2015-10-20 11:31:54 +0200 | [diff] [blame] | 277 | dev_emerg(&chip->gpiodev->dev, "(%s): " fmt, chip->label, ##__VA_ARGS__) |
Alexandre Courbot | 0eb4c6c | 2014-07-01 14:45:15 +0900 | [diff] [blame] | 278 | #define chip_crit(chip, fmt, ...) \ |
Linus Walleij | 34ffd85 | 2015-10-20 11:31:54 +0200 | [diff] [blame] | 279 | dev_crit(&chip->gpiodev->dev, "(%s): " fmt, chip->label, ##__VA_ARGS__) |
Alexandre Courbot | 0eb4c6c | 2014-07-01 14:45:15 +0900 | [diff] [blame] | 280 | #define chip_err(chip, fmt, ...) \ |
Linus Walleij | 34ffd85 | 2015-10-20 11:31:54 +0200 | [diff] [blame] | 281 | dev_err(&chip->gpiodev->dev, "(%s): " fmt, chip->label, ##__VA_ARGS__) |
Alexandre Courbot | 0eb4c6c | 2014-07-01 14:45:15 +0900 | [diff] [blame] | 282 | #define chip_warn(chip, fmt, ...) \ |
Linus Walleij | 34ffd85 | 2015-10-20 11:31:54 +0200 | [diff] [blame] | 283 | dev_warn(&chip->gpiodev->dev, "(%s): " fmt, chip->label, ##__VA_ARGS__) |
Alexandre Courbot | 0eb4c6c | 2014-07-01 14:45:15 +0900 | [diff] [blame] | 284 | #define chip_info(chip, fmt, ...) \ |
Linus Walleij | 34ffd85 | 2015-10-20 11:31:54 +0200 | [diff] [blame] | 285 | dev_info(&chip->gpiodev->dev, "(%s): " fmt, chip->label, ##__VA_ARGS__) |
Alexandre Courbot | 0eb4c6c | 2014-07-01 14:45:15 +0900 | [diff] [blame] | 286 | #define chip_dbg(chip, fmt, ...) \ |
Linus Walleij | 34ffd85 | 2015-10-20 11:31:54 +0200 | [diff] [blame] | 287 | dev_dbg(&chip->gpiodev->dev, "(%s): " fmt, chip->label, ##__VA_ARGS__) |
Alexandre Courbot | 0eb4c6c | 2014-07-01 14:45:15 +0900 | [diff] [blame] | 288 | |
| 289 | #ifdef CONFIG_GPIO_SYSFS |
| 290 | |
Linus Walleij | afbc4f3 | 2016-02-09 13:21:06 +0100 | [diff] [blame] | 291 | int gpiochip_sysfs_register(struct gpio_device *gdev); |
| 292 | void gpiochip_sysfs_unregister(struct gpio_device *gdev); |
Alexandre Courbot | 0eb4c6c | 2014-07-01 14:45:15 +0900 | [diff] [blame] | 293 | |
| 294 | #else |
| 295 | |
Linus Walleij | afbc4f3 | 2016-02-09 13:21:06 +0100 | [diff] [blame] | 296 | static inline int gpiochip_sysfs_register(struct gpio_device *gdev) |
Alexandre Courbot | 0eb4c6c | 2014-07-01 14:45:15 +0900 | [diff] [blame] | 297 | { |
| 298 | return 0; |
| 299 | } |
| 300 | |
Linus Walleij | afbc4f3 | 2016-02-09 13:21:06 +0100 | [diff] [blame] | 301 | static inline void gpiochip_sysfs_unregister(struct gpio_device *gdev) |
Alexandre Courbot | 0eb4c6c | 2014-07-01 14:45:15 +0900 | [diff] [blame] | 302 | { |
| 303 | } |
| 304 | |
| 305 | #endif /* CONFIG_GPIO_SYSFS */ |
| 306 | |
Mika Westerberg | 664e3e5 | 2014-01-08 12:40:54 +0200 | [diff] [blame] | 307 | #endif /* GPIOLIB_H */ |