blob: 35f299d1f6a794d0898f276836a345c88a7c14a5 [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 {
Andy Shevchenko40505862019-04-10 18:39:15 +03009 GPIO_ACTIVE_HIGH = (0 << 0),
10 GPIO_ACTIVE_LOW = (1 << 0),
11 GPIO_OPEN_DRAIN = (1 << 1),
12 GPIO_OPEN_SOURCE = (1 << 2),
13 GPIO_PERSISTENT = (0 << 3),
14 GPIO_TRANSITORY = (1 << 3),
15 GPIO_PULL_UP = (1 << 4),
16 GPIO_PULL_DOWN = (1 << 5),
Andy Shevchenko2d6c06f2019-04-10 18:39:17 +030017
18 GPIO_LOOKUP_FLAGS_DEFAULT = GPIO_ACTIVE_HIGH | GPIO_PERSISTENT,
Linus Walleij0a6d3152014-07-24 20:08:55 +020019};
20
21/**
22 * struct gpiod_lookup - lookup table
23 * @chip_label: name of the chip the GPIO belongs to
24 * @chip_hwnum: hardware number (i.e. relative to the chip) of the GPIO
25 * @con_id: name of the GPIO from the device's point of view
26 * @idx: index of the GPIO in case several GPIOs share the same name
Andy Shevchenkofed70262019-04-10 18:39:16 +030027 * @flags: bitmask of gpio_lookup_flags GPIO_* values
Linus Walleij0a6d3152014-07-24 20:08:55 +020028 *
29 * gpiod_lookup is a lookup table for associating GPIOs to specific devices and
30 * functions using platform data.
31 */
32struct gpiod_lookup {
33 const char *chip_label;
34 u16 chip_hwnum;
35 const char *con_id;
36 unsigned int idx;
Andy Shevchenkofed70262019-04-10 18:39:16 +030037 unsigned long flags;
Linus Walleij0a6d3152014-07-24 20:08:55 +020038};
39
40struct gpiod_lookup_table {
41 struct list_head list;
42 const char *dev_id;
43 struct gpiod_lookup table[];
44};
45
Bartosz Golaszewskia411e812018-04-10 22:30:28 +020046/**
47 * struct gpiod_hog - GPIO line hog table
48 * @chip_label: name of the chip the GPIO belongs to
49 * @chip_hwnum: hardware number (i.e. relative to the chip) of the GPIO
50 * @line_name: consumer name for the hogged line
Andy Shevchenkofed70262019-04-10 18:39:16 +030051 * @lflags: bitmask of gpio_lookup_flags GPIO_* values
Bartosz Golaszewskia411e812018-04-10 22:30:28 +020052 * @dflags: GPIO flags used to specify the direction and value
53 */
54struct gpiod_hog {
55 struct list_head list;
56 const char *chip_label;
57 u16 chip_hwnum;
58 const char *line_name;
Andy Shevchenkofed70262019-04-10 18:39:16 +030059 unsigned long lflags;
Bartosz Golaszewskia411e812018-04-10 22:30:28 +020060 int dflags;
61};
62
Linus Walleij0a6d3152014-07-24 20:08:55 +020063/*
64 * Simple definition of a single GPIO under a con_id
65 */
66#define GPIO_LOOKUP(_chip_label, _chip_hwnum, _con_id, _flags) \
67 GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _con_id, 0, _flags)
68
69/*
70 * Use this macro if you need to have several GPIOs under the same con_id.
71 * Each GPIO needs to use a different index and can be accessed using
72 * gpiod_get_index()
73 */
74#define GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _con_id, _idx, _flags) \
75{ \
76 .chip_label = _chip_label, \
77 .chip_hwnum = _chip_hwnum, \
78 .con_id = _con_id, \
79 .idx = _idx, \
80 .flags = _flags, \
81}
82
Bartosz Golaszewskia411e812018-04-10 22:30:28 +020083/*
84 * Simple definition of a single GPIO hog in an array.
85 */
86#define GPIO_HOG(_chip_label, _chip_hwnum, _line_name, _lflags, _dflags) \
87{ \
88 .chip_label = _chip_label, \
89 .chip_hwnum = _chip_hwnum, \
90 .line_name = _line_name, \
91 .lflags = _lflags, \
92 .dflags = _dflags, \
93}
94
Anatolij Gustschin020e0b12017-05-11 20:24:31 +020095#ifdef CONFIG_GPIOLIB
Linus Walleij0a6d3152014-07-24 20:08:55 +020096void gpiod_add_lookup_table(struct gpiod_lookup_table *table);
Dmitry Torokhov3946d182017-08-14 21:59:55 -070097void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n);
Shobhit Kumarbe9015a2015-06-26 14:32:04 +053098void gpiod_remove_lookup_table(struct gpiod_lookup_table *table);
Bartosz Golaszewskia411e812018-04-10 22:30:28 +020099void gpiod_add_hogs(struct gpiod_hog *hogs);
Anatolij Gustschin020e0b12017-05-11 20:24:31 +0200100#else
101static inline
102void gpiod_add_lookup_table(struct gpiod_lookup_table *table) {}
103static inline
Dmitry Torokhov3946d182017-08-14 21:59:55 -0700104void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n) {}
105static inline
Anatolij Gustschin020e0b12017-05-11 20:24:31 +0200106void gpiod_remove_lookup_table(struct gpiod_lookup_table *table) {}
Bartosz Golaszewskia411e812018-04-10 22:30:28 +0200107static inline void gpiod_add_hogs(struct gpiod_hog *hogs) {}
Anatolij Gustschin020e0b12017-05-11 20:24:31 +0200108#endif
Linus Walleij0a6d3152014-07-24 20:08:55 +0200109
110#endif /* __LINUX_GPIO_MACHINE_H */