Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at 92d5a606721f759ebebf448b3bd2b7a781d50bd0 94 lines 3.2 kB view raw
1/* SPDX-License-Identifier: GPL-2.0 */ 2#ifndef __LINUX_GPIO_MACHINE_H 3#define __LINUX_GPIO_MACHINE_H 4 5#include <linux/types.h> 6 7enum gpio_lookup_flags { 8 GPIO_ACTIVE_HIGH = (0 << 0), 9 GPIO_ACTIVE_LOW = (1 << 0), 10 GPIO_OPEN_DRAIN = (1 << 1), 11 GPIO_OPEN_SOURCE = (1 << 2), 12 GPIO_PERSISTENT = (0 << 3), 13 GPIO_TRANSITORY = (1 << 3), 14 GPIO_PULL_UP = (1 << 4), 15 GPIO_PULL_DOWN = (1 << 5), 16 GPIO_PULL_DISABLE = (1 << 6), 17 18 GPIO_LOOKUP_FLAGS_DEFAULT = GPIO_ACTIVE_HIGH | GPIO_PERSISTENT, 19}; 20 21/** 22 * struct gpiod_lookup - lookup table 23 * @key: either the name of the chip the GPIO belongs to, or the GPIO line name 24 * Note that GPIO line names are not guaranteed to be globally unique, 25 * so this will use the first match found! 26 * @chip_hwnum: hardware number (i.e. relative to the chip) of the GPIO, or 27 * U16_MAX to indicate that @key is a GPIO line name 28 * @con_id: name of the GPIO from the device's point of view 29 * @idx: index of the GPIO in case several GPIOs share the same name 30 * @flags: bitmask of gpio_lookup_flags GPIO_* values 31 * 32 * gpiod_lookup is a lookup table for associating GPIOs to specific devices and 33 * functions using platform data. 34 */ 35struct gpiod_lookup { 36 const char *key; 37 u16 chip_hwnum; 38 const char *con_id; 39 unsigned int idx; 40 unsigned long flags; 41}; 42 43struct gpiod_lookup_table { 44 struct list_head list; 45 const char *dev_id; 46 struct gpiod_lookup table[]; 47}; 48 49/* 50 * Helper for lookup tables with just one single lookup for a device. 51 */ 52#define GPIO_LOOKUP_SINGLE(_name, _dev_id, _key, _chip_hwnum, _con_id, _flags) \ 53static struct gpiod_lookup_table _name = { \ 54 .dev_id = _dev_id, \ 55 .table = { \ 56 GPIO_LOOKUP(_key, _chip_hwnum, _con_id, _flags), \ 57 {}, \ 58 }, \ 59} 60 61/* 62 * Simple definition of a single GPIO under a con_id 63 */ 64#define GPIO_LOOKUP(_key, _chip_hwnum, _con_id, _flags) \ 65 GPIO_LOOKUP_IDX(_key, _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(_key, _chip_hwnum, _con_id, _idx, _flags) \ 73(struct gpiod_lookup) { \ 74 .key = _key, \ 75 .chip_hwnum = _chip_hwnum, \ 76 .con_id = _con_id, \ 77 .idx = _idx, \ 78 .flags = _flags, \ 79} 80 81#ifdef CONFIG_GPIOLIB 82void gpiod_add_lookup_table(struct gpiod_lookup_table *table); 83void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n); 84void gpiod_remove_lookup_table(struct gpiod_lookup_table *table); 85#else /* ! CONFIG_GPIOLIB */ 86static inline 87void gpiod_add_lookup_table(struct gpiod_lookup_table *table) {} 88static inline 89void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n) {} 90static inline 91void gpiod_remove_lookup_table(struct gpiod_lookup_table *table) {} 92#endif /* CONFIG_GPIOLIB */ 93 94#endif /* __LINUX_GPIO_MACHINE_H */