0001
0002 #ifndef __LINUX_GPIO_MACHINE_H
0003 #define __LINUX_GPIO_MACHINE_H
0004
0005 #include <linux/types.h>
0006 #include <linux/list.h>
0007
0008 enum gpio_lookup_flags {
0009 GPIO_ACTIVE_HIGH = (0 << 0),
0010 GPIO_ACTIVE_LOW = (1 << 0),
0011 GPIO_OPEN_DRAIN = (1 << 1),
0012 GPIO_OPEN_SOURCE = (1 << 2),
0013 GPIO_PERSISTENT = (0 << 3),
0014 GPIO_TRANSITORY = (1 << 3),
0015 GPIO_PULL_UP = (1 << 4),
0016 GPIO_PULL_DOWN = (1 << 5),
0017 GPIO_PULL_DISABLE = (1 << 6),
0018
0019 GPIO_LOOKUP_FLAGS_DEFAULT = GPIO_ACTIVE_HIGH | GPIO_PERSISTENT,
0020 };
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 struct gpiod_lookup {
0037 const char *key;
0038 u16 chip_hwnum;
0039 const char *con_id;
0040 unsigned int idx;
0041 unsigned long flags;
0042 };
0043
0044 struct gpiod_lookup_table {
0045 struct list_head list;
0046 const char *dev_id;
0047 struct gpiod_lookup table[];
0048 };
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058 struct gpiod_hog {
0059 struct list_head list;
0060 const char *chip_label;
0061 u16 chip_hwnum;
0062 const char *line_name;
0063 unsigned long lflags;
0064 int dflags;
0065 };
0066
0067
0068
0069
0070 #define GPIO_LOOKUP_SINGLE(_name, _dev_id, _key, _chip_hwnum, _con_id, _flags) \
0071 static struct gpiod_lookup_table _name = { \
0072 .dev_id = _dev_id, \
0073 .table = { \
0074 GPIO_LOOKUP(_key, _chip_hwnum, _con_id, _flags), \
0075 {}, \
0076 }, \
0077 }
0078
0079
0080
0081
0082 #define GPIO_LOOKUP(_key, _chip_hwnum, _con_id, _flags) \
0083 GPIO_LOOKUP_IDX(_key, _chip_hwnum, _con_id, 0, _flags)
0084
0085
0086
0087
0088
0089
0090 #define GPIO_LOOKUP_IDX(_key, _chip_hwnum, _con_id, _idx, _flags) \
0091 (struct gpiod_lookup) { \
0092 .key = _key, \
0093 .chip_hwnum = _chip_hwnum, \
0094 .con_id = _con_id, \
0095 .idx = _idx, \
0096 .flags = _flags, \
0097 }
0098
0099
0100
0101
0102 #define GPIO_HOG(_chip_label, _chip_hwnum, _line_name, _lflags, _dflags) \
0103 (struct gpiod_hog) { \
0104 .chip_label = _chip_label, \
0105 .chip_hwnum = _chip_hwnum, \
0106 .line_name = _line_name, \
0107 .lflags = _lflags, \
0108 .dflags = _dflags, \
0109 }
0110
0111 #ifdef CONFIG_GPIOLIB
0112 void gpiod_add_lookup_table(struct gpiod_lookup_table *table);
0113 void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n);
0114 void gpiod_remove_lookup_table(struct gpiod_lookup_table *table);
0115 void gpiod_add_hogs(struct gpiod_hog *hogs);
0116 void gpiod_remove_hogs(struct gpiod_hog *hogs);
0117 #else
0118 static inline
0119 void gpiod_add_lookup_table(struct gpiod_lookup_table *table) {}
0120 static inline
0121 void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n) {}
0122 static inline
0123 void gpiod_remove_lookup_table(struct gpiod_lookup_table *table) {}
0124 static inline void gpiod_add_hogs(struct gpiod_hog *hogs) {}
0125 static inline void gpiod_remove_hogs(struct gpiod_hog *hogs) {}
0126 #endif
0127
0128 #endif