Merge tag 'xtensa-20150416' of git://github.com/czankel/xtensa-linux
[deliverable/linux.git] / drivers / gpio / gpiolib.h
CommitLineData
664e3e5a
MW
1/*
2 * Internal GPIO functions.
3 *
4 * Copyright (C) 2013, Intel Corporation
5 * Author: Mika Westerberg <mika.westerberg@linux.intel.com>
6 *
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.
10 */
11
12#ifndef GPIOLIB_H
13#define GPIOLIB_H
14
5ccff852
MW
15#include <linux/err.h>
16#include <linux/device.h>
17
f01d9075
AC
18enum of_gpio_flags;
19
ce793486
RW
20struct acpi_device;
21
5ccff852
MW
22/**
23 * struct acpi_gpio_info - ACPI GPIO specific information
24 * @gpioint: if %true this GPIO is of type GpioInt otherwise type is GpioIo
25 * @active_low: in case of @gpioint, the pin is active low
26 */
27struct acpi_gpio_info {
28 bool gpioint;
29 bool active_low;
30};
31
664e3e5a
MW
32#ifdef CONFIG_ACPI
33void acpi_gpiochip_add(struct gpio_chip *chip);
34void acpi_gpiochip_remove(struct gpio_chip *chip);
5ccff852 35
afa82fab
MW
36void acpi_gpiochip_request_interrupts(struct gpio_chip *chip);
37void acpi_gpiochip_free_interrupts(struct gpio_chip *chip);
38
0d9a693c
MW
39struct gpio_desc *acpi_get_gpiod_by_index(struct acpi_device *adev,
40 const char *propname, int index,
5ccff852 41 struct acpi_gpio_info *info);
664e3e5a
MW
42#else
43static inline void acpi_gpiochip_add(struct gpio_chip *chip) { }
44static inline void acpi_gpiochip_remove(struct gpio_chip *chip) { }
5ccff852 45
afa82fab
MW
46static inline void
47acpi_gpiochip_request_interrupts(struct gpio_chip *chip) { }
48
49static inline void
50acpi_gpiochip_free_interrupts(struct gpio_chip *chip) { }
51
5ccff852 52static inline struct gpio_desc *
0d9a693c
MW
53acpi_get_gpiod_by_index(struct acpi_device *adev, const char *propname,
54 int index, struct acpi_gpio_info *info)
5ccff852
MW
55{
56 return ERR_PTR(-ENOSYS);
57}
664e3e5a
MW
58#endif
59
f01d9075
AC
60struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np,
61 const char *list_name, int index, enum of_gpio_flags *flags);
62
1bd6b601
AC
63struct gpio_desc *gpiochip_get_desc(struct gpio_chip *chip, u16 hwnum);
64
0eb4c6c2
AC
65extern struct spinlock gpio_lock;
66extern struct list_head gpio_chips;
67
68struct gpio_desc {
69 struct gpio_chip *chip;
70 unsigned long flags;
71/* flag symbols are bit numbers */
72#define FLAG_REQUESTED 0
73#define FLAG_IS_OUT 1
74#define FLAG_EXPORT 2 /* protected by sysfs_lock */
75#define FLAG_SYSFS 3 /* exported via /sys/class/gpio/control */
76#define FLAG_TRIG_FALL 4 /* trigger on falling edge */
77#define FLAG_TRIG_RISE 5 /* trigger on rising edge */
78#define FLAG_ACTIVE_LOW 6 /* value has active low */
79#define FLAG_OPEN_DRAIN 7 /* Gpio is open drain type */
80#define FLAG_OPEN_SOURCE 8 /* Gpio is open source type */
81#define FLAG_USED_AS_IRQ 9 /* GPIO is connected to an IRQ */
ebbeba12 82#define FLAG_SYSFS_DIR 10 /* show sysfs direction attribute */
0eb4c6c2
AC
83
84#define ID_SHIFT 16 /* add new flags before this one */
85
86#define GPIO_FLAGS_MASK ((1 << ID_SHIFT) - 1)
87#define GPIO_TRIGGER_MASK (BIT(FLAG_TRIG_FALL) | BIT(FLAG_TRIG_RISE))
88
89 const char *label;
90};
91
92int gpiod_request(struct gpio_desc *desc, const char *label);
93void gpiod_free(struct gpio_desc *desc);
94
95/*
96 * Return the GPIO number of the passed descriptor relative to its chip
97 */
98static int __maybe_unused gpio_chip_hwgpio(const struct gpio_desc *desc)
99{
100 return desc - &desc->chip->desc[0];
101}
102
103/* With descriptor prefix */
104
105#define gpiod_emerg(desc, fmt, ...) \
106 pr_emerg("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?",\
107 ##__VA_ARGS__)
108#define gpiod_crit(desc, fmt, ...) \
109 pr_crit("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \
110 ##__VA_ARGS__)
111#define gpiod_err(desc, fmt, ...) \
112 pr_err("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \
113 ##__VA_ARGS__)
114#define gpiod_warn(desc, fmt, ...) \
115 pr_warn("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \
116 ##__VA_ARGS__)
117#define gpiod_info(desc, fmt, ...) \
118 pr_info("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \
119 ##__VA_ARGS__)
120#define gpiod_dbg(desc, fmt, ...) \
121 pr_debug("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?",\
122 ##__VA_ARGS__)
123
124/* With chip prefix */
125
126#define chip_emerg(chip, fmt, ...) \
127 pr_emerg("GPIO chip %s: " fmt, chip->label, ##__VA_ARGS__)
128#define chip_crit(chip, fmt, ...) \
129 pr_crit("GPIO chip %s: " fmt, chip->label, ##__VA_ARGS__)
130#define chip_err(chip, fmt, ...) \
131 pr_err("GPIO chip %s: " fmt, chip->label, ##__VA_ARGS__)
132#define chip_warn(chip, fmt, ...) \
133 pr_warn("GPIO chip %s: " fmt, chip->label, ##__VA_ARGS__)
134#define chip_info(chip, fmt, ...) \
135 pr_info("GPIO chip %s: " fmt, chip->label, ##__VA_ARGS__)
136#define chip_dbg(chip, fmt, ...) \
137 pr_debug("GPIO chip %s: " fmt, chip->label, ##__VA_ARGS__)
138
139#ifdef CONFIG_GPIO_SYSFS
140
141int gpiochip_export(struct gpio_chip *chip);
142void gpiochip_unexport(struct gpio_chip *chip);
143
144#else
145
146static inline int gpiochip_export(struct gpio_chip *chip)
147{
148 return 0;
149}
150
151static inline void gpiochip_unexport(struct gpio_chip *chip)
152{
153}
154
155#endif /* CONFIG_GPIO_SYSFS */
156
664e3e5a 157#endif /* GPIOLIB_H */
This page took 0.100921 seconds and 5 git commands to generate.