1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __LINUX_GPIO_MACHINE_H
3 #define __LINUX_GPIO_MACHINE_H
5 #include <linux/types.h>
6 #include <linux/list.h>
8 enum gpio_lookup_flags {
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),
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
25 * @flags: mask of GPIO_* values
27 * gpiod_lookup is a lookup table for associating GPIOs to specific devices and
28 * functions using platform data.
31 const char *chip_label;
35 enum gpio_lookup_flags flags;
38 struct gpiod_lookup_table {
39 struct list_head list;
41 struct gpiod_lookup table[];
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
49 * @lflags: mask of GPIO lookup flags
50 * @dflags: GPIO flags used to specify the direction and value
53 struct list_head list;
54 const char *chip_label;
56 const char *line_name;
57 enum gpio_lookup_flags lflags;
62 * Simple definition of a single GPIO under a con_id
64 #define GPIO_LOOKUP(_chip_label, _chip_hwnum, _con_id, _flags) \
65 GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _con_id, 0, _flags)
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
72 #define GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _con_id, _idx, _flags) \
74 .chip_label = _chip_label, \
75 .chip_hwnum = _chip_hwnum, \
82 * Simple definition of a single GPIO hog in an array.
84 #define GPIO_HOG(_chip_label, _chip_hwnum, _line_name, _lflags, _dflags) \
86 .chip_label = _chip_label, \
87 .chip_hwnum = _chip_hwnum, \
88 .line_name = _line_name, \
94 void gpiod_add_lookup_table(struct gpiod_lookup_table *table);
95 void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n);
96 void gpiod_remove_lookup_table(struct gpiod_lookup_table *table);
97 void gpiod_add_hogs(struct gpiod_hog *hogs);
100 void gpiod_add_lookup_table(struct gpiod_lookup_table *table) {}
102 void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n) {}
104 void gpiod_remove_lookup_table(struct gpiod_lookup_table *table) {}
105 static inline void gpiod_add_hogs(struct gpiod_hog *hogs) {}
108 #endif /* __LINUX_GPIO_MACHINE_H */