blob: daa44eac9241b008a3848ad76ef6b73dbf6495d0 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Walleij0a6d3152014-07-24 20:08:55 +02002#ifndef __LINUX_GPIO_MACHINE_H
3#define __LINUX_GPIO_MACHINE_H
4
Alexandre Courbotb3ea0742014-08-04 13:05:56 +09005#include <linux/types.h>
6#include <linux/list.h>
7
Linus Walleij0a6d3152014-07-24 20:08:55 +02008enum 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),
Andrew Jefferye10f72b2017-11-30 14:25:24 +103013 GPIO_PERSISTENT = (0 << 3),
14 GPIO_TRANSITORY = (1 << 3),
Linus Walleij0a6d3152014-07-24 20:08:55 +020015};
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
Bartosz Golaszewskia411e812018-04-10 22:30:28 +020042/**
43 * struct gpiod_hog - GPIO line hog table
44 * @chip_label: name of the chip the GPIO belongs to
45 * @chip_hwnum: hardware number (i.e. relative to the chip) of the GPIO
46 * @line_name: consumer name for the hogged line
47 * @lflags: mask of GPIO lookup flags
48 * @dflags: GPIO flags used to specify the direction and value
49 */
50struct gpiod_hog {
51 struct list_head list;
52 const char *chip_label;
53 u16 chip_hwnum;
54 const char *line_name;
55 enum gpio_lookup_flags lflags;
56 int dflags;
57};
58
Linus Walleij0a6d3152014-07-24 20:08:55 +020059/*
60 * Simple definition of a single GPIO under a con_id
61 */
62#define GPIO_LOOKUP(_chip_label, _chip_hwnum, _con_id, _flags) \
63 GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _con_id, 0, _flags)
64
65/*
66 * Use this macro if you need to have several GPIOs under the same con_id.
67 * Each GPIO needs to use a different index and can be accessed using
68 * gpiod_get_index()
69 */
70#define GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _con_id, _idx, _flags) \
71{ \
72 .chip_label = _chip_label, \
73 .chip_hwnum = _chip_hwnum, \
74 .con_id = _con_id, \
75 .idx = _idx, \
76 .flags = _flags, \
77}
78
Bartosz Golaszewskia411e812018-04-10 22:30:28 +020079/*
80 * Simple definition of a single GPIO hog in an array.
81 */
82#define GPIO_HOG(_chip_label, _chip_hwnum, _line_name, _lflags, _dflags) \
83{ \
84 .chip_label = _chip_label, \
85 .chip_hwnum = _chip_hwnum, \
86 .line_name = _line_name, \
87 .lflags = _lflags, \
88 .dflags = _dflags, \
89}
90
Anatolij Gustschin020e0b12017-05-11 20:24:31 +020091#ifdef CONFIG_GPIOLIB
Linus Walleij0a6d3152014-07-24 20:08:55 +020092void gpiod_add_lookup_table(struct gpiod_lookup_table *table);
Dmitry Torokhov3946d182017-08-14 21:59:55 -070093void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n);
Shobhit Kumarbe9015a2015-06-26 14:32:04 +053094void gpiod_remove_lookup_table(struct gpiod_lookup_table *table);
Bartosz Golaszewskia411e812018-04-10 22:30:28 +020095void gpiod_add_hogs(struct gpiod_hog *hogs);
Anatolij Gustschin020e0b12017-05-11 20:24:31 +020096#else
97static inline
98void gpiod_add_lookup_table(struct gpiod_lookup_table *table) {}
99static inline
Dmitry Torokhov3946d182017-08-14 21:59:55 -0700100void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n) {}
101static inline
Anatolij Gustschin020e0b12017-05-11 20:24:31 +0200102void gpiod_remove_lookup_table(struct gpiod_lookup_table *table) {}
Bartosz Golaszewskia411e812018-04-10 22:30:28 +0200103static inline void gpiod_add_hogs(struct gpiod_hog *hogs) {}
Anatolij Gustschin020e0b12017-05-11 20:24:31 +0200104#endif
Linus Walleij0a6d3152014-07-24 20:08:55 +0200105
106#endif /* __LINUX_GPIO_MACHINE_H */