blob: ba4ccfd900f91cafe1721a6a633c30b967bf9475 [file] [log] [blame]
Linus Walleij0a6d3152014-07-24 20:08:55 +02001#ifndef __LINUX_GPIO_MACHINE_H
2#define __LINUX_GPIO_MACHINE_H
3
Alexandre Courbotb3ea0742014-08-04 13:05:56 +09004#include <linux/types.h>
5#include <linux/list.h>
6
Linus Walleij0a6d3152014-07-24 20:08:55 +02007enum 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),
Charles Keepax05f479b2017-05-23 15:47:29 +010012 GPIO_SLEEP_MAINTAIN_VALUE = (0 << 3),
13 GPIO_SLEEP_MAY_LOOSE_VALUE = (1 << 3),
Linus Walleij0a6d3152014-07-24 20:08:55 +020014};
15
16/**
17 * struct gpiod_lookup - lookup table
18 * @chip_label: name of the chip the GPIO belongs to
19 * @chip_hwnum: hardware number (i.e. relative to the chip) of the GPIO
20 * @con_id: name of the GPIO from the device's point of view
21 * @idx: index of the GPIO in case several GPIOs share the same name
22 * @flags: mask of GPIO_* values
23 *
24 * gpiod_lookup is a lookup table for associating GPIOs to specific devices and
25 * functions using platform data.
26 */
27struct gpiod_lookup {
28 const char *chip_label;
29 u16 chip_hwnum;
30 const char *con_id;
31 unsigned int idx;
32 enum gpio_lookup_flags flags;
33};
34
35struct gpiod_lookup_table {
36 struct list_head list;
37 const char *dev_id;
38 struct gpiod_lookup table[];
39};
40
41/*
42 * Simple definition of a single GPIO under a con_id
43 */
44#define GPIO_LOOKUP(_chip_label, _chip_hwnum, _con_id, _flags) \
45 GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _con_id, 0, _flags)
46
47/*
48 * Use this macro if you need to have several GPIOs under the same con_id.
49 * Each GPIO needs to use a different index and can be accessed using
50 * gpiod_get_index()
51 */
52#define GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _con_id, _idx, _flags) \
53{ \
54 .chip_label = _chip_label, \
55 .chip_hwnum = _chip_hwnum, \
56 .con_id = _con_id, \
57 .idx = _idx, \
58 .flags = _flags, \
59}
60
Anatolij Gustschin020e0b12017-05-11 20:24:31 +020061#ifdef CONFIG_GPIOLIB
Linus Walleij0a6d3152014-07-24 20:08:55 +020062void gpiod_add_lookup_table(struct gpiod_lookup_table *table);
Dmitry Torokhov3946d182017-08-14 21:59:55 -070063void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n);
Shobhit Kumarbe9015a2015-06-26 14:32:04 +053064void gpiod_remove_lookup_table(struct gpiod_lookup_table *table);
Anatolij Gustschin020e0b12017-05-11 20:24:31 +020065#else
66static inline
67void gpiod_add_lookup_table(struct gpiod_lookup_table *table) {}
68static inline
Dmitry Torokhov3946d182017-08-14 21:59:55 -070069void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n) {}
70static inline
Anatolij Gustschin020e0b12017-05-11 20:24:31 +020071void gpiod_remove_lookup_table(struct gpiod_lookup_table *table) {}
72#endif
Linus Walleij0a6d3152014-07-24 20:08:55 +020073
74#endif /* __LINUX_GPIO_MACHINE_H */