Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
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  * struct gpiod_lookup - lookup table
0024  * @key: either the name of the chip the GPIO belongs to, or the GPIO line name
0025  *       Note that GPIO line names are not guaranteed to be globally unique,
0026  *       so this will use the first match found!
0027  * @chip_hwnum: hardware number (i.e. relative to the chip) of the GPIO, or
0028  *              U16_MAX to indicate that @key is a GPIO line name
0029  * @con_id: name of the GPIO from the device's point of view
0030  * @idx: index of the GPIO in case several GPIOs share the same name
0031  * @flags: bitmask of gpio_lookup_flags GPIO_* values
0032  *
0033  * gpiod_lookup is a lookup table for associating GPIOs to specific devices and
0034  * functions using platform data.
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  * struct gpiod_hog - GPIO line hog table
0052  * @chip_label: name of the chip the GPIO belongs to
0053  * @chip_hwnum: hardware number (i.e. relative to the chip) of the GPIO
0054  * @line_name: consumer name for the hogged line
0055  * @lflags: bitmask of gpio_lookup_flags GPIO_* values
0056  * @dflags: GPIO flags used to specify the direction and value
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  * Helper for lookup tables with just one single lookup for a device.
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  * Simple definition of a single GPIO under a con_id
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  * Use this macro if you need to have several GPIOs under the same con_id.
0087  * Each GPIO needs to use a different index and can be accessed using
0088  * gpiod_get_index()
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  * Simple definition of a single GPIO hog in an array.
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 /* ! CONFIG_GPIOLIB */
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 /* CONFIG_GPIOLIB */
0127 
0128 #endif /* __LINUX_GPIO_MACHINE_H */