Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Walleij | 0a6d315 | 2014-07-24 20:08:55 +0200 | [diff] [blame] | 2 | #ifndef __LINUX_GPIO_MACHINE_H |
| 3 | #define __LINUX_GPIO_MACHINE_H |
| 4 | |
Alexandre Courbot | b3ea074 | 2014-08-04 13:05:56 +0900 | [diff] [blame] | 5 | #include <linux/types.h> |
| 6 | #include <linux/list.h> |
| 7 | |
Linus Walleij | 0a6d315 | 2014-07-24 20:08:55 +0200 | [diff] [blame] | 8 | enum gpio_lookup_flags { |
Andy Shevchenko | 4050586 | 2019-04-10 18:39:15 +0300 | [diff] [blame] | 9 | GPIO_ACTIVE_HIGH = (0 << 0), |
| 10 | GPIO_ACTIVE_LOW = (1 << 0), |
| 11 | GPIO_OPEN_DRAIN = (1 << 1), |
| 12 | GPIO_OPEN_SOURCE = (1 << 2), |
| 13 | GPIO_PERSISTENT = (0 << 3), |
| 14 | GPIO_TRANSITORY = (1 << 3), |
| 15 | GPIO_PULL_UP = (1 << 4), |
| 16 | GPIO_PULL_DOWN = (1 << 5), |
Linus Walleij | 0a6d315 | 2014-07-24 20:08:55 +0200 | [diff] [blame] | 17 | }; |
| 18 | |
| 19 | /** |
| 20 | * struct gpiod_lookup - lookup table |
| 21 | * @chip_label: name of the chip the GPIO belongs to |
| 22 | * @chip_hwnum: hardware number (i.e. relative to the chip) of the GPIO |
| 23 | * @con_id: name of the GPIO from the device's point of view |
| 24 | * @idx: index of the GPIO in case several GPIOs share the same name |
Andy Shevchenko | fed7026 | 2019-04-10 18:39:16 +0300 | [diff] [blame^] | 25 | * @flags: bitmask of gpio_lookup_flags GPIO_* values |
Linus Walleij | 0a6d315 | 2014-07-24 20:08:55 +0200 | [diff] [blame] | 26 | * |
| 27 | * gpiod_lookup is a lookup table for associating GPIOs to specific devices and |
| 28 | * functions using platform data. |
| 29 | */ |
| 30 | struct gpiod_lookup { |
| 31 | const char *chip_label; |
| 32 | u16 chip_hwnum; |
| 33 | const char *con_id; |
| 34 | unsigned int idx; |
Andy Shevchenko | fed7026 | 2019-04-10 18:39:16 +0300 | [diff] [blame^] | 35 | unsigned long flags; |
Linus Walleij | 0a6d315 | 2014-07-24 20:08:55 +0200 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | struct gpiod_lookup_table { |
| 39 | struct list_head list; |
| 40 | const char *dev_id; |
| 41 | struct gpiod_lookup table[]; |
| 42 | }; |
| 43 | |
Bartosz Golaszewski | a411e81 | 2018-04-10 22:30:28 +0200 | [diff] [blame] | 44 | /** |
| 45 | * struct gpiod_hog - GPIO line hog table |
| 46 | * @chip_label: name of the chip the GPIO belongs to |
| 47 | * @chip_hwnum: hardware number (i.e. relative to the chip) of the GPIO |
| 48 | * @line_name: consumer name for the hogged line |
Andy Shevchenko | fed7026 | 2019-04-10 18:39:16 +0300 | [diff] [blame^] | 49 | * @lflags: bitmask of gpio_lookup_flags GPIO_* values |
Bartosz Golaszewski | a411e81 | 2018-04-10 22:30:28 +0200 | [diff] [blame] | 50 | * @dflags: GPIO flags used to specify the direction and value |
| 51 | */ |
| 52 | struct gpiod_hog { |
| 53 | struct list_head list; |
| 54 | const char *chip_label; |
| 55 | u16 chip_hwnum; |
| 56 | const char *line_name; |
Andy Shevchenko | fed7026 | 2019-04-10 18:39:16 +0300 | [diff] [blame^] | 57 | unsigned long lflags; |
Bartosz Golaszewski | a411e81 | 2018-04-10 22:30:28 +0200 | [diff] [blame] | 58 | int dflags; |
| 59 | }; |
| 60 | |
Linus Walleij | 0a6d315 | 2014-07-24 20:08:55 +0200 | [diff] [blame] | 61 | /* |
| 62 | * Simple definition of a single GPIO under a con_id |
| 63 | */ |
| 64 | #define GPIO_LOOKUP(_chip_label, _chip_hwnum, _con_id, _flags) \ |
| 65 | GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _con_id, 0, _flags) |
| 66 | |
| 67 | /* |
| 68 | * Use this macro if you need to have several GPIOs under the same con_id. |
| 69 | * Each GPIO needs to use a different index and can be accessed using |
| 70 | * gpiod_get_index() |
| 71 | */ |
| 72 | #define GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _con_id, _idx, _flags) \ |
| 73 | { \ |
| 74 | .chip_label = _chip_label, \ |
| 75 | .chip_hwnum = _chip_hwnum, \ |
| 76 | .con_id = _con_id, \ |
| 77 | .idx = _idx, \ |
| 78 | .flags = _flags, \ |
| 79 | } |
| 80 | |
Bartosz Golaszewski | a411e81 | 2018-04-10 22:30:28 +0200 | [diff] [blame] | 81 | /* |
| 82 | * Simple definition of a single GPIO hog in an array. |
| 83 | */ |
| 84 | #define GPIO_HOG(_chip_label, _chip_hwnum, _line_name, _lflags, _dflags) \ |
| 85 | { \ |
| 86 | .chip_label = _chip_label, \ |
| 87 | .chip_hwnum = _chip_hwnum, \ |
| 88 | .line_name = _line_name, \ |
| 89 | .lflags = _lflags, \ |
| 90 | .dflags = _dflags, \ |
| 91 | } |
| 92 | |
Anatolij Gustschin | 020e0b1 | 2017-05-11 20:24:31 +0200 | [diff] [blame] | 93 | #ifdef CONFIG_GPIOLIB |
Linus Walleij | 0a6d315 | 2014-07-24 20:08:55 +0200 | [diff] [blame] | 94 | void gpiod_add_lookup_table(struct gpiod_lookup_table *table); |
Dmitry Torokhov | 3946d18 | 2017-08-14 21:59:55 -0700 | [diff] [blame] | 95 | void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n); |
Shobhit Kumar | be9015a | 2015-06-26 14:32:04 +0530 | [diff] [blame] | 96 | void gpiod_remove_lookup_table(struct gpiod_lookup_table *table); |
Bartosz Golaszewski | a411e81 | 2018-04-10 22:30:28 +0200 | [diff] [blame] | 97 | void gpiod_add_hogs(struct gpiod_hog *hogs); |
Anatolij Gustschin | 020e0b1 | 2017-05-11 20:24:31 +0200 | [diff] [blame] | 98 | #else |
| 99 | static inline |
| 100 | void gpiod_add_lookup_table(struct gpiod_lookup_table *table) {} |
| 101 | static inline |
Dmitry Torokhov | 3946d18 | 2017-08-14 21:59:55 -0700 | [diff] [blame] | 102 | void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n) {} |
| 103 | static inline |
Anatolij Gustschin | 020e0b1 | 2017-05-11 20:24:31 +0200 | [diff] [blame] | 104 | void gpiod_remove_lookup_table(struct gpiod_lookup_table *table) {} |
Bartosz Golaszewski | a411e81 | 2018-04-10 22:30:28 +0200 | [diff] [blame] | 105 | static inline void gpiod_add_hogs(struct gpiod_hog *hogs) {} |
Anatolij Gustschin | 020e0b1 | 2017-05-11 20:24:31 +0200 | [diff] [blame] | 106 | #endif |
Linus Walleij | 0a6d315 | 2014-07-24 20:08:55 +0200 | [diff] [blame] | 107 | |
| 108 | #endif /* __LINUX_GPIO_MACHINE_H */ |