]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - drivers/gpio/gpiolib.h
2 * Internal GPIO functions.
4 * Copyright (C) 2013, Intel Corporation
5 * Author: Mika Westerberg <mika.westerberg@linux.intel.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
15 #include <linux/gpio/driver.h>
16 #include <linux/err.h>
17 #include <linux/device.h>
18 #include <linux/module.h>
19 #include <linux/cdev.h>
26 * struct gpio_device - internal state container for GPIO devices
27 * @id: numerical ID number for the GPIO chip
28 * @dev: the GPIO device struct
29 * @owner: helps prevent removal of modules exporting active GPIOs
30 * @chip: pointer to the corresponding gpiochip, holding static
31 * data for this device
32 * @list: links gpio_device:s together for traversal
34 * This state container holds most of the runtime variable data
35 * for a GPIO device and can hold references and live on after the
36 * GPIO chip has been removed, if it is still being used from
43 struct gpio_chip
*chip
;
44 struct list_head list
;
48 * struct acpi_gpio_info - ACPI GPIO specific information
49 * @gpioint: if %true this GPIO is of type GpioInt otherwise type is GpioIo
50 * @active_low: in case of @gpioint, the pin is active low
52 struct acpi_gpio_info
{
58 /* gpio suffixes used for ACPI and device tree lookup */
59 static const char * const gpio_suffixes
[] = { "gpios", "gpio" };
62 void acpi_gpiochip_add(struct gpio_chip
*chip
);
63 void acpi_gpiochip_remove(struct gpio_chip
*chip
);
65 void acpi_gpiochip_request_interrupts(struct gpio_chip
*chip
);
66 void acpi_gpiochip_free_interrupts(struct gpio_chip
*chip
);
68 struct gpio_desc
*acpi_get_gpiod_by_index(struct acpi_device
*adev
,
69 const char *propname
, int index
,
70 struct acpi_gpio_info
*info
);
71 struct gpio_desc
*acpi_node_get_gpiod(struct fwnode_handle
*fwnode
,
72 const char *propname
, int index
,
73 struct acpi_gpio_info
*info
);
75 int acpi_gpio_count(struct device
*dev
, const char *con_id
);
77 bool acpi_can_fallback_to_crs(struct acpi_device
*adev
, const char *con_id
);
79 static inline void acpi_gpiochip_add(struct gpio_chip
*chip
) { }
80 static inline void acpi_gpiochip_remove(struct gpio_chip
*chip
) { }
83 acpi_gpiochip_request_interrupts(struct gpio_chip
*chip
) { }
86 acpi_gpiochip_free_interrupts(struct gpio_chip
*chip
) { }
88 static inline struct gpio_desc
*
89 acpi_get_gpiod_by_index(struct acpi_device
*adev
, const char *propname
,
90 int index
, struct acpi_gpio_info
*info
)
92 return ERR_PTR(-ENOSYS
);
94 static inline struct gpio_desc
*
95 acpi_node_get_gpiod(struct fwnode_handle
*fwnode
, const char *propname
,
96 int index
, struct acpi_gpio_info
*info
)
98 return ERR_PTR(-ENXIO
);
100 static inline int acpi_gpio_count(struct device
*dev
, const char *con_id
)
105 static inline bool acpi_can_fallback_to_crs(struct acpi_device
*adev
,
112 struct gpio_desc
*of_get_named_gpiod_flags(struct device_node
*np
,
113 const char *list_name
, int index
, enum of_gpio_flags
*flags
);
115 struct gpio_desc
*gpiochip_get_desc(struct gpio_chip
*chip
, u16 hwnum
);
117 extern struct spinlock gpio_lock
;
118 extern struct list_head gpio_devices
;
121 struct gpio_chip
*chip
;
123 /* flag symbols are bit numbers */
124 #define FLAG_REQUESTED 0
125 #define FLAG_IS_OUT 1
126 #define FLAG_EXPORT 2 /* protected by sysfs_lock */
127 #define FLAG_SYSFS 3 /* exported via /sys/class/gpio/control */
128 #define FLAG_ACTIVE_LOW 6 /* value has active low */
129 #define FLAG_OPEN_DRAIN 7 /* Gpio is open drain type */
130 #define FLAG_OPEN_SOURCE 8 /* Gpio is open source type */
131 #define FLAG_USED_AS_IRQ 9 /* GPIO is connected to an IRQ */
132 #define FLAG_IS_HOGGED 11 /* GPIO is hogged */
134 /* Connection label */
136 /* Name of the GPIO */
140 int gpiod_request(struct gpio_desc
*desc
, const char *label
);
141 void gpiod_free(struct gpio_desc
*desc
);
142 int gpiod_hog(struct gpio_desc
*desc
, const char *name
,
143 unsigned long lflags
, enum gpiod_flags dflags
);
146 * Return the GPIO number of the passed descriptor relative to its chip
148 static int __maybe_unused
gpio_chip_hwgpio(const struct gpio_desc
*desc
)
150 return desc
- &desc
->chip
->desc
[0];
153 /* With descriptor prefix */
155 #define gpiod_emerg(desc, fmt, ...) \
156 pr_emerg("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?",\
158 #define gpiod_crit(desc, fmt, ...) \
159 pr_crit("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \
161 #define gpiod_err(desc, fmt, ...) \
162 pr_err("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \
164 #define gpiod_warn(desc, fmt, ...) \
165 pr_warn("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \
167 #define gpiod_info(desc, fmt, ...) \
168 pr_info("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \
170 #define gpiod_dbg(desc, fmt, ...) \
171 pr_debug("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?",\
174 /* With chip prefix */
176 #define chip_emerg(chip, fmt, ...) \
177 pr_emerg("GPIO chip %s: " fmt, chip->label, ##__VA_ARGS__)
178 #define chip_crit(chip, fmt, ...) \
179 pr_crit("GPIO chip %s: " fmt, chip->label, ##__VA_ARGS__)
180 #define chip_err(chip, fmt, ...) \
181 pr_err("GPIO chip %s: " fmt, chip->label, ##__VA_ARGS__)
182 #define chip_warn(chip, fmt, ...) \
183 pr_warn("GPIO chip %s: " fmt, chip->label, ##__VA_ARGS__)
184 #define chip_info(chip, fmt, ...) \
185 pr_info("GPIO chip %s: " fmt, chip->label, ##__VA_ARGS__)
186 #define chip_dbg(chip, fmt, ...) \
187 pr_debug("GPIO chip %s: " fmt, chip->label, ##__VA_ARGS__)
189 #ifdef CONFIG_GPIO_SYSFS
191 int gpiochip_sysfs_register(struct gpio_chip
*chip
);
192 void gpiochip_sysfs_unregister(struct gpio_chip
*chip
);
196 static inline int gpiochip_sysfs_register(struct gpio_chip
*chip
)
201 static inline void gpiochip_sysfs_unregister(struct gpio_chip
*chip
)
205 #endif /* CONFIG_GPIO_SYSFS */
207 #endif /* GPIOLIB_H */