License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[linux-block.git] / include / linux / gpio / machine.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
0a6d3158
LW
2#ifndef __LINUX_GPIO_MACHINE_H
3#define __LINUX_GPIO_MACHINE_H
4
b3ea074f
AC
5#include <linux/types.h>
6#include <linux/list.h>
7
0a6d3158
LW
8enum 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),
05f479bf
CK
13 GPIO_SLEEP_MAINTAIN_VALUE = (0 << 3),
14 GPIO_SLEEP_MAY_LOOSE_VALUE = (1 << 3),
0a6d3158
LW
15};
16
17/**
18 * struct gpiod_lookup - lookup table
19 * @chip_label: name of the chip the GPIO belongs to
20 * @chip_hwnum: hardware number (i.e. relative to the chip) of the GPIO
21 * @con_id: name of the GPIO from the device's point of view
22 * @idx: index of the GPIO in case several GPIOs share the same name
23 * @flags: mask of GPIO_* values
24 *
25 * gpiod_lookup is a lookup table for associating GPIOs to specific devices and
26 * functions using platform data.
27 */
28struct gpiod_lookup {
29 const char *chip_label;
30 u16 chip_hwnum;
31 const char *con_id;
32 unsigned int idx;
33 enum gpio_lookup_flags flags;
34};
35
36struct gpiod_lookup_table {
37 struct list_head list;
38 const char *dev_id;
39 struct gpiod_lookup table[];
40};
41
42/*
43 * Simple definition of a single GPIO under a con_id
44 */
45#define GPIO_LOOKUP(_chip_label, _chip_hwnum, _con_id, _flags) \
46 GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _con_id, 0, _flags)
47
48/*
49 * Use this macro if you need to have several GPIOs under the same con_id.
50 * Each GPIO needs to use a different index and can be accessed using
51 * gpiod_get_index()
52 */
53#define GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _con_id, _idx, _flags) \
54{ \
55 .chip_label = _chip_label, \
56 .chip_hwnum = _chip_hwnum, \
57 .con_id = _con_id, \
58 .idx = _idx, \
59 .flags = _flags, \
60}
61
020e0b1c 62#ifdef CONFIG_GPIOLIB
0a6d3158 63void gpiod_add_lookup_table(struct gpiod_lookup_table *table);
3946d187 64void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n);
be9015ab 65void gpiod_remove_lookup_table(struct gpiod_lookup_table *table);
020e0b1c
AG
66#else
67static inline
68void gpiod_add_lookup_table(struct gpiod_lookup_table *table) {}
69static inline
3946d187
DT
70void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n) {}
71static inline
020e0b1c
AG
72void gpiod_remove_lookup_table(struct gpiod_lookup_table *table) {}
73#endif
0a6d3158
LW
74
75#endif /* __LINUX_GPIO_MACHINE_H */