aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandre Courbot <acourbot@nvidia.com>2014-07-25 10:38:36 -0400
committerLinus Walleij <linus.walleij@linaro.org>2014-07-28 06:28:05 -0400
commit39b2bbe3d715cf5013b5c48695ccdd25bd3bf120 (patch)
tree019129dbc7b1cc10200342602fe7eac47230219e
parent9b5b33f6256a941d9d34f219b508ba7140a39dba (diff)
gpio: add flags argument to gpiod_get*() functions
The huge majority of GPIOs have their direction and initial value set right after being obtained by one of the gpiod_get() functions. The integer GPIO API had gpio_request_one() that took a convenience flags parameter allowing to specify an direction and value applied to the returned GPIO. This feature greatly simplifies client code and ensures errors are always handled properly. A similar feature has been requested for the gpiod API. Since setting the direction of a GPIO is so often the very next action done after obtaining its descriptor, we prefer to extend the existing functions instead of introducing new functions that would raise the number of gpiod getters to 16 (!). The drawback of this approach is that all gpiod clients need to be updated. To limit the pain, temporary macros are introduced that allow gpiod_get*() to be called with or without the extra flags argument. They will be removed once all consumer code has been updated. Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> Reviewed-by: Mark Brown <broonie@linaro.org> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
-rw-r--r--Documentation/gpio/consumer.txt26
-rw-r--r--drivers/gpio/devres.c40
-rw-r--r--drivers/gpio/gpiolib.c67
-rw-r--r--include/linux/gpio/consumer.h81
4 files changed, 155 insertions, 59 deletions
diff --git a/Documentation/gpio/consumer.txt b/Documentation/gpio/consumer.txt
index d8abfc31abbe..76546324e968 100644
--- a/Documentation/gpio/consumer.txt
+++ b/Documentation/gpio/consumer.txt
@@ -29,13 +29,24 @@ gpiod_get() functions. Like many other kernel subsystems, gpiod_get() takes the
29device that will use the GPIO and the function the requested GPIO is supposed to 29device that will use the GPIO and the function the requested GPIO is supposed to
30fulfill: 30fulfill:
31 31
32 struct gpio_desc *gpiod_get(struct device *dev, const char *con_id) 32 struct gpio_desc *gpiod_get(struct device *dev, const char *con_id,
33 enum gpiod_flags flags)
33 34
34If a function is implemented by using several GPIOs together (e.g. a simple LED 35If a function is implemented by using several GPIOs together (e.g. a simple LED
35device that displays digits), an additional index argument can be specified: 36device that displays digits), an additional index argument can be specified:
36 37
37 struct gpio_desc *gpiod_get_index(struct device *dev, 38 struct gpio_desc *gpiod_get_index(struct device *dev,
38 const char *con_id, unsigned int idx) 39 const char *con_id, unsigned int idx,
40 enum gpiod_flags flags)
41
42The flags parameter is used to optionally specify a direction and initial value
43for the GPIO. Values can be:
44
45* GPIOD_ASIS or 0 to not initialize the GPIO at all. The direction must be set
46 later with one of the dedicated functions.
47* GPIOD_IN to initialize the GPIO as input.
48* GPIOD_OUT_LOW to initialize the GPIO as output with a value of 0.
49* GPIOD_OUT_HIGH to initialize the GPIO as output with a value of 1.
39 50
40Both functions return either a valid GPIO descriptor, or an error code checkable 51Both functions return either a valid GPIO descriptor, or an error code checkable
41with IS_ERR() (they will never return a NULL pointer). -ENOENT will be returned 52with IS_ERR() (they will never return a NULL pointer). -ENOENT will be returned
@@ -46,11 +57,13 @@ errors and an absence of GPIO for optional GPIO parameters.
46 57
47Device-managed variants of these functions are also defined: 58Device-managed variants of these functions are also defined:
48 59
49 struct gpio_desc *devm_gpiod_get(struct device *dev, const char *con_id) 60 struct gpio_desc *devm_gpiod_get(struct device *dev, const char *con_id,
61 enum gpiod_flags flags)
50 62
51 struct gpio_desc *devm_gpiod_get_index(struct device *dev, 63 struct gpio_desc *devm_gpiod_get_index(struct device *dev,
52 const char *con_id, 64 const char *con_id,
53 unsigned int idx) 65 unsigned int idx,
66 enum gpiod_flags flags)
54 67
55A GPIO descriptor can be disposed of using the gpiod_put() function: 68A GPIO descriptor can be disposed of using the gpiod_put() function:
56 69
@@ -67,8 +80,9 @@ Using GPIOs
67 80
68Setting Direction 81Setting Direction
69----------------- 82-----------------
70The first thing a driver must do with a GPIO is setting its direction. This is 83The first thing a driver must do with a GPIO is setting its direction. If no
71done by invoking one of the gpiod_direction_*() functions: 84direction-setting flags have been given to gpiod_get*(), this is done by
85invoking one of the gpiod_direction_*() functions:
72 86
73 int gpiod_direction_input(struct gpio_desc *desc) 87 int gpiod_direction_input(struct gpio_desc *desc)
74 int gpiod_direction_output(struct gpio_desc *desc, int value) 88 int gpiod_direction_output(struct gpio_desc *desc, int value)
diff --git a/drivers/gpio/devres.c b/drivers/gpio/devres.c
index 65978cf85f79..41b2f40578d5 100644
--- a/drivers/gpio/devres.c
+++ b/drivers/gpio/devres.c
@@ -39,47 +39,53 @@ static int devm_gpiod_match(struct device *dev, void *res, void *data)
39 * devm_gpiod_get - Resource-managed gpiod_get() 39 * devm_gpiod_get - Resource-managed gpiod_get()
40 * @dev: GPIO consumer 40 * @dev: GPIO consumer
41 * @con_id: function within the GPIO consumer 41 * @con_id: function within the GPIO consumer
42 * @flags: optional GPIO initialization flags
42 * 43 *
43 * Managed gpiod_get(). GPIO descriptors returned from this function are 44 * Managed gpiod_get(). GPIO descriptors returned from this function are
44 * automatically disposed on driver detach. See gpiod_get() for detailed 45 * automatically disposed on driver detach. See gpiod_get() for detailed
45 * information about behavior and return values. 46 * information about behavior and return values.
46 */ 47 */
47struct gpio_desc *__must_check devm_gpiod_get(struct device *dev, 48struct gpio_desc *__must_check __devm_gpiod_get(struct device *dev,
48 const char *con_id) 49 const char *con_id,
50 enum gpiod_flags flags)
49{ 51{
50 return devm_gpiod_get_index(dev, con_id, 0); 52 return devm_gpiod_get_index(dev, con_id, 0, flags);
51} 53}
52EXPORT_SYMBOL(devm_gpiod_get); 54EXPORT_SYMBOL(__devm_gpiod_get);
53 55
54/** 56/**
55 * devm_gpiod_get_optional - Resource-managed gpiod_get_optional() 57 * devm_gpiod_get_optional - Resource-managed gpiod_get_optional()
56 * @dev: GPIO consumer 58 * @dev: GPIO consumer
57 * @con_id: function within the GPIO consumer 59 * @con_id: function within the GPIO consumer
60 * @flags: optional GPIO initialization flags
58 * 61 *
59 * Managed gpiod_get_optional(). GPIO descriptors returned from this function 62 * Managed gpiod_get_optional(). GPIO descriptors returned from this function
60 * are automatically disposed on driver detach. See gpiod_get_optional() for 63 * are automatically disposed on driver detach. See gpiod_get_optional() for
61 * detailed information about behavior and return values. 64 * detailed information about behavior and return values.
62 */ 65 */
63struct gpio_desc *__must_check devm_gpiod_get_optional(struct device *dev, 66struct gpio_desc *__must_check __devm_gpiod_get_optional(struct device *dev,
64 const char *con_id) 67 const char *con_id,
68 enum gpiod_flags flags)
65{ 69{
66 return devm_gpiod_get_index_optional(dev, con_id, 0); 70 return devm_gpiod_get_index_optional(dev, con_id, 0, flags);
67} 71}
68EXPORT_SYMBOL(devm_gpiod_get_optional); 72EXPORT_SYMBOL(__devm_gpiod_get_optional);
69 73
70/** 74/**
71 * devm_gpiod_get_index - Resource-managed gpiod_get_index() 75 * devm_gpiod_get_index - Resource-managed gpiod_get_index()
72 * @dev: GPIO consumer 76 * @dev: GPIO consumer
73 * @con_id: function within the GPIO consumer 77 * @con_id: function within the GPIO consumer
74 * @idx: index of the GPIO to obtain in the consumer 78 * @idx: index of the GPIO to obtain in the consumer
79 * @flags: optional GPIO initialization flags
75 * 80 *
76 * Managed gpiod_get_index(). GPIO descriptors returned from this function are 81 * Managed gpiod_get_index(). GPIO descriptors returned from this function are
77 * automatically disposed on driver detach. See gpiod_get_index() for detailed 82 * automatically disposed on driver detach. See gpiod_get_index() for detailed
78 * information about behavior and return values. 83 * information about behavior and return values.
79 */ 84 */
80struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev, 85struct gpio_desc *__must_check __devm_gpiod_get_index(struct device *dev,
81 const char *con_id, 86 const char *con_id,
82 unsigned int idx) 87 unsigned int idx,
88 enum gpiod_flags flags)
83{ 89{
84 struct gpio_desc **dr; 90 struct gpio_desc **dr;
85 struct gpio_desc *desc; 91 struct gpio_desc *desc;
@@ -89,7 +95,7 @@ struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev,
89 if (!dr) 95 if (!dr)
90 return ERR_PTR(-ENOMEM); 96 return ERR_PTR(-ENOMEM);
91 97
92 desc = gpiod_get_index(dev, con_id, idx); 98 desc = gpiod_get_index(dev, con_id, idx, flags);
93 if (IS_ERR(desc)) { 99 if (IS_ERR(desc)) {
94 devres_free(dr); 100 devres_free(dr);
95 return desc; 101 return desc;
@@ -100,26 +106,28 @@ struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev,
100 106
101 return desc; 107 return desc;
102} 108}
103EXPORT_SYMBOL(devm_gpiod_get_index); 109EXPORT_SYMBOL(__devm_gpiod_get_index);
104 110
105/** 111/**
106 * devm_gpiod_get_index_optional - Resource-managed gpiod_get_index_optional() 112 * devm_gpiod_get_index_optional - Resource-managed gpiod_get_index_optional()
107 * @dev: GPIO consumer 113 * @dev: GPIO consumer
108 * @con_id: function within the GPIO consumer 114 * @con_id: function within the GPIO consumer
109 * @index: index of the GPIO to obtain in the consumer 115 * @index: index of the GPIO to obtain in the consumer
116 * @flags: optional GPIO initialization flags
110 * 117 *
111 * Managed gpiod_get_index_optional(). GPIO descriptors returned from this 118 * Managed gpiod_get_index_optional(). GPIO descriptors returned from this
112 * function are automatically disposed on driver detach. See 119 * function are automatically disposed on driver detach. See
113 * gpiod_get_index_optional() for detailed information about behavior and 120 * gpiod_get_index_optional() for detailed information about behavior and
114 * return values. 121 * return values.
115 */ 122 */
116struct gpio_desc *__must_check devm_gpiod_get_index_optional(struct device *dev, 123struct gpio_desc *__must_check __devm_gpiod_get_index_optional(struct device *dev,
117 const char *con_id, 124 const char *con_id,
118 unsigned int index) 125 unsigned int index,
126 enum gpiod_flags flags)
119{ 127{
120 struct gpio_desc *desc; 128 struct gpio_desc *desc;
121 129
122 desc = devm_gpiod_get_index(dev, con_id, index); 130 desc = devm_gpiod_get_index(dev, con_id, index, flags);
123 if (IS_ERR(desc)) { 131 if (IS_ERR(desc)) {
124 if (PTR_ERR(desc) == -ENOENT) 132 if (PTR_ERR(desc) == -ENOENT)
125 return NULL; 133 return NULL;
@@ -127,7 +135,7 @@ struct gpio_desc *__must_check devm_gpiod_get_index_optional(struct device *dev,
127 135
128 return desc; 136 return desc;
129} 137}
130EXPORT_SYMBOL(devm_gpiod_get_index_optional); 138EXPORT_SYMBOL(__devm_gpiod_get_index_optional);
131 139
132/** 140/**
133 * devm_gpiod_put - Resource-managed gpiod_put() 141 * devm_gpiod_put - Resource-managed gpiod_put()
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 330227581a25..15cc0bb65dda 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1582,38 +1582,43 @@ static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id,
1582 * gpiod_get - obtain a GPIO for a given GPIO function 1582 * gpiod_get - obtain a GPIO for a given GPIO function
1583 * @dev: GPIO consumer, can be NULL for system-global GPIOs 1583 * @dev: GPIO consumer, can be NULL for system-global GPIOs
1584 * @con_id: function within the GPIO consumer 1584 * @con_id: function within the GPIO consumer
1585 * @flags: optional GPIO initialization flags
1585 * 1586 *
1586 * Return the GPIO descriptor corresponding to the function con_id of device 1587 * Return the GPIO descriptor corresponding to the function con_id of device
1587 * dev, -ENOENT if no GPIO has been assigned to the requested function, or 1588 * dev, -ENOENT if no GPIO has been assigned to the requested function, or
1588 * another IS_ERR() code if an error occured while trying to acquire the GPIO. 1589 * another IS_ERR() code if an error occured while trying to acquire the GPIO.
1589 */ 1590 */
1590struct gpio_desc *__must_check gpiod_get(struct device *dev, const char *con_id) 1591struct gpio_desc *__must_check __gpiod_get(struct device *dev, const char *con_id,
1592 enum gpiod_flags flags)
1591{ 1593{
1592 return gpiod_get_index(dev, con_id, 0); 1594 return gpiod_get_index(dev, con_id, 0, flags);
1593} 1595}
1594EXPORT_SYMBOL_GPL(gpiod_get); 1596EXPORT_SYMBOL_GPL(__gpiod_get);
1595 1597
1596/** 1598/**
1597 * gpiod_get_optional - obtain an optional GPIO for a given GPIO function 1599 * gpiod_get_optional - obtain an optional GPIO for a given GPIO function
1598 * @dev: GPIO consumer, can be NULL for system-global GPIOs 1600 * @dev: GPIO consumer, can be NULL for system-global GPIOs
1599 * @con_id: function within the GPIO consumer 1601 * @con_id: function within the GPIO consumer
1602 * @flags: optional GPIO initialization flags
1600 * 1603 *
1601 * This is equivalent to gpiod_get(), except that when no GPIO was assigned to 1604 * This is equivalent to gpiod_get(), except that when no GPIO was assigned to
1602 * the requested function it will return NULL. This is convenient for drivers 1605 * the requested function it will return NULL. This is convenient for drivers
1603 * that need to handle optional GPIOs. 1606 * that need to handle optional GPIOs.
1604 */ 1607 */
1605struct gpio_desc *__must_check gpiod_get_optional(struct device *dev, 1608struct gpio_desc *__must_check __gpiod_get_optional(struct device *dev,
1606 const char *con_id) 1609 const char *con_id,
1610 enum gpiod_flags flags)
1607{ 1611{
1608 return gpiod_get_index_optional(dev, con_id, 0); 1612 return gpiod_get_index_optional(dev, con_id, 0, flags);
1609} 1613}
1610EXPORT_SYMBOL_GPL(gpiod_get_optional); 1614EXPORT_SYMBOL_GPL(__gpiod_get_optional);
1611 1615
1612/** 1616/**
1613 * gpiod_get_index - obtain a GPIO from a multi-index GPIO function 1617 * gpiod_get_index - obtain a GPIO from a multi-index GPIO function
1614 * @dev: GPIO consumer, can be NULL for system-global GPIOs 1618 * @dev: GPIO consumer, can be NULL for system-global GPIOs
1615 * @con_id: function within the GPIO consumer 1619 * @con_id: function within the GPIO consumer
1616 * @idx: index of the GPIO to obtain in the consumer 1620 * @idx: index of the GPIO to obtain in the consumer
1621 * @flags: optional GPIO initialization flags
1617 * 1622 *
1618 * This variant of gpiod_get() allows to access GPIOs other than the first 1623 * This variant of gpiod_get() allows to access GPIOs other than the first
1619 * defined one for functions that define several GPIOs. 1624 * defined one for functions that define several GPIOs.
@@ -1622,23 +1627,24 @@ EXPORT_SYMBOL_GPL(gpiod_get_optional);
1622 * requested function and/or index, or another IS_ERR() code if an error 1627 * requested function and/or index, or another IS_ERR() code if an error
1623 * occured while trying to acquire the GPIO. 1628 * occured while trying to acquire the GPIO.
1624 */ 1629 */
1625struct gpio_desc *__must_check gpiod_get_index(struct device *dev, 1630struct gpio_desc *__must_check __gpiod_get_index(struct device *dev,
1626 const char *con_id, 1631 const char *con_id,
1627 unsigned int idx) 1632 unsigned int idx,
1633 enum gpiod_flags flags)
1628{ 1634{
1629 struct gpio_desc *desc = NULL; 1635 struct gpio_desc *desc = NULL;
1630 int status; 1636 int status;
1631 enum gpio_lookup_flags flags = 0; 1637 enum gpio_lookup_flags lookupflags = 0;
1632 1638
1633 dev_dbg(dev, "GPIO lookup for consumer %s\n", con_id); 1639 dev_dbg(dev, "GPIO lookup for consumer %s\n", con_id);
1634 1640
1635 /* Using device tree? */ 1641 /* Using device tree? */
1636 if (IS_ENABLED(CONFIG_OF) && dev && dev->of_node) { 1642 if (IS_ENABLED(CONFIG_OF) && dev && dev->of_node) {
1637 dev_dbg(dev, "using device tree for GPIO lookup\n"); 1643 dev_dbg(dev, "using device tree for GPIO lookup\n");
1638 desc = of_find_gpio(dev, con_id, idx, &flags); 1644 desc = of_find_gpio(dev, con_id, idx, &lookupflags);
1639 } else if (IS_ENABLED(CONFIG_ACPI) && dev && ACPI_HANDLE(dev)) { 1645 } else if (IS_ENABLED(CONFIG_ACPI) && dev && ACPI_HANDLE(dev)) {
1640 dev_dbg(dev, "using ACPI for GPIO lookup\n"); 1646 dev_dbg(dev, "using ACPI for GPIO lookup\n");
1641 desc = acpi_find_gpio(dev, con_id, idx, &flags); 1647 desc = acpi_find_gpio(dev, con_id, idx, &lookupflags);
1642 } 1648 }
1643 1649
1644 /* 1650 /*
@@ -1647,7 +1653,7 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
1647 */ 1653 */
1648 if (!desc || desc == ERR_PTR(-ENOENT)) { 1654 if (!desc || desc == ERR_PTR(-ENOENT)) {
1649 dev_dbg(dev, "using lookup tables for GPIO lookup"); 1655 dev_dbg(dev, "using lookup tables for GPIO lookup");
1650 desc = gpiod_find(dev, con_id, idx, &flags); 1656 desc = gpiod_find(dev, con_id, idx, &lookupflags);
1651 } 1657 }
1652 1658
1653 if (IS_ERR(desc)) { 1659 if (IS_ERR(desc)) {
@@ -1660,16 +1666,33 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
1660 if (status < 0) 1666 if (status < 0)
1661 return ERR_PTR(status); 1667 return ERR_PTR(status);
1662 1668
1663 if (flags & GPIO_ACTIVE_LOW) 1669 if (lookupflags & GPIO_ACTIVE_LOW)
1664 set_bit(FLAG_ACTIVE_LOW, &desc->flags); 1670 set_bit(FLAG_ACTIVE_LOW, &desc->flags);
1665 if (flags & GPIO_OPEN_DRAIN) 1671 if (lookupflags & GPIO_OPEN_DRAIN)
1666 set_bit(FLAG_OPEN_DRAIN, &desc->flags); 1672 set_bit(FLAG_OPEN_DRAIN, &desc->flags);
1667 if (flags & GPIO_OPEN_SOURCE) 1673 if (lookupflags & GPIO_OPEN_SOURCE)
1668 set_bit(FLAG_OPEN_SOURCE, &desc->flags); 1674 set_bit(FLAG_OPEN_SOURCE, &desc->flags);
1669 1675
1676 /* No particular flag request, return here... */
1677 if (flags & GPIOD_FLAGS_BIT_DIR_SET)
1678 return desc;
1679
1680 /* Process flags */
1681 if (flags & GPIOD_FLAGS_BIT_DIR_OUT)
1682 status = gpiod_direction_output(desc,
1683 flags & GPIOD_FLAGS_BIT_DIR_VAL);
1684 else
1685 status = gpiod_direction_input(desc);
1686
1687 if (status < 0) {
1688 dev_dbg(dev, "setup of GPIO %s failed\n", con_id);
1689 gpiod_put(desc);
1690 return ERR_PTR(status);
1691 }
1692
1670 return desc; 1693 return desc;
1671} 1694}
1672EXPORT_SYMBOL_GPL(gpiod_get_index); 1695EXPORT_SYMBOL_GPL(__gpiod_get_index);
1673 1696
1674/** 1697/**
1675 * gpiod_get_index_optional - obtain an optional GPIO from a multi-index GPIO 1698 * gpiod_get_index_optional - obtain an optional GPIO from a multi-index GPIO
@@ -1677,18 +1700,20 @@ EXPORT_SYMBOL_GPL(gpiod_get_index);
1677 * @dev: GPIO consumer, can be NULL for system-global GPIOs 1700 * @dev: GPIO consumer, can be NULL for system-global GPIOs
1678 * @con_id: function within the GPIO consumer 1701 * @con_id: function within the GPIO consumer
1679 * @index: index of the GPIO to obtain in the consumer 1702 * @index: index of the GPIO to obtain in the consumer
1703 * @flags: optional GPIO initialization flags
1680 * 1704 *
1681 * This is equivalent to gpiod_get_index(), except that when no GPIO with the 1705 * This is equivalent to gpiod_get_index(), except that when no GPIO with the
1682 * specified index was assigned to the requested function it will return NULL. 1706 * specified index was assigned to the requested function it will return NULL.
1683 * This is convenient for drivers that need to handle optional GPIOs. 1707 * This is convenient for drivers that need to handle optional GPIOs.
1684 */ 1708 */
1685struct gpio_desc *__must_check gpiod_get_index_optional(struct device *dev, 1709struct gpio_desc *__must_check __gpiod_get_index_optional(struct device *dev,
1686 const char *con_id, 1710 const char *con_id,
1687 unsigned int index) 1711 unsigned int index,
1712 enum gpiod_flags flags)
1688{ 1713{
1689 struct gpio_desc *desc; 1714 struct gpio_desc *desc;
1690 1715
1691 desc = gpiod_get_index(dev, con_id, index); 1716 desc = gpiod_get_index(dev, con_id, index, flags);
1692 if (IS_ERR(desc)) { 1717 if (IS_ERR(desc)) {
1693 if (PTR_ERR(desc) == -ENOENT) 1718 if (PTR_ERR(desc) == -ENOENT)
1694 return NULL; 1719 return NULL;
@@ -1696,7 +1721,7 @@ struct gpio_desc *__must_check gpiod_get_index_optional(struct device *dev,
1696 1721
1697 return desc; 1722 return desc;
1698} 1723}
1699EXPORT_SYMBOL_GPL(gpiod_get_index_optional); 1724EXPORT_SYMBOL_GPL(__gpiod_get_index_optional);
1700 1725
1701/** 1726/**
1702 * gpiod_put - dispose of a GPIO descriptor 1727 * gpiod_put - dispose of a GPIO descriptor
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
index 05e53ccb708b..b7ce0c64c6f3 100644
--- a/include/linux/gpio/consumer.h
+++ b/include/linux/gpio/consumer.h
@@ -18,30 +18,79 @@ struct gpio_desc;
18 18
19#ifdef CONFIG_GPIOLIB 19#ifdef CONFIG_GPIOLIB
20 20
21#define GPIOD_FLAGS_BIT_DIR_SET BIT(0)
22#define GPIOD_FLAGS_BIT_DIR_OUT BIT(1)
23#define GPIOD_FLAGS_BIT_DIR_VAL BIT(2)
24
25/**
26 * Optional flags that can be passed to one of gpiod_* to configure direction
27 * and output value. These values cannot be OR'd.
28 */
29enum gpiod_flags {
30 GPIOD_ASIS = 0,
31 GPIOD_IN = GPIOD_FLAGS_BIT_DIR_SET,
32 GPIOD_OUT_LOW = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT,
33 GPIOD_OUT_HIGH = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT |
34 GPIOD_FLAGS_BIT_DIR_VAL,
35};
36
21/* Acquire and dispose GPIOs */ 37/* Acquire and dispose GPIOs */
22struct gpio_desc *__must_check gpiod_get(struct device *dev, 38struct gpio_desc *__must_check __gpiod_get(struct device *dev,
23 const char *con_id); 39 const char *con_id,
24struct gpio_desc *__must_check gpiod_get_index(struct device *dev, 40 enum gpiod_flags flags);
41#define __gpiod_get(dev, con_id, flags, ...) __gpiod_get(dev, con_id, flags)
42#define gpiod_get(varargs...) __gpiod_get(varargs, 0)
43struct gpio_desc *__must_check __gpiod_get_index(struct device *dev,
25 const char *con_id, 44 const char *con_id,
26 unsigned int idx); 45 unsigned int idx,
27struct gpio_desc *__must_check gpiod_get_optional(struct device *dev, 46 enum gpiod_flags flags);
28 const char *con_id); 47#define __gpiod_get_index(dev, con_id, index, flags, ...) \
29struct gpio_desc *__must_check gpiod_get_index_optional(struct device *dev, 48 __gpiod_get_index(dev, con_id, index, flags)
49#define gpiod_get_index(varargs...) __gpiod_get_index(varargs, 0)
50struct gpio_desc *__must_check __gpiod_get_optional(struct device *dev,
51 const char *con_id,
52 enum gpiod_flags flags);
53#define __gpiod_get_optional(dev, con_id, flags, ...) \
54 __gpiod_get_optional(dev, con_id, flags)
55#define gpiod_get_optional(varargs...) __gpiod_get_optional(varargs, 0)
56struct gpio_desc *__must_check __gpiod_get_index_optional(struct device *dev,
30 const char *con_id, 57 const char *con_id,
31 unsigned int index); 58 unsigned int index,
59 enum gpiod_flags flags);
60#define __gpiod_get_index_optional(dev, con_id, index, flags, ...) \
61 __gpiod_get_index_optional(dev, con_id, index, flags)
62#define gpiod_get_index_optional(varargs...) \
63 __gpiod_get_index_optional(varargs, 0)
32 64
33void gpiod_put(struct gpio_desc *desc); 65void gpiod_put(struct gpio_desc *desc);
34 66
35struct gpio_desc *__must_check devm_gpiod_get(struct device *dev, 67struct gpio_desc *__must_check __devm_gpiod_get(struct device *dev,
36 const char *con_id); 68 const char *con_id,
37struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev, 69 enum gpiod_flags flags);
70#define __devm_gpiod_get(dev, con_id, flags, ...) \
71 __devm_gpiod_get(dev, con_id, flags)
72#define devm_gpiod_get(varargs...) __devm_gpiod_get(varargs, 0)
73struct gpio_desc *__must_check __devm_gpiod_get_index(struct device *dev,
38 const char *con_id, 74 const char *con_id,
39 unsigned int idx); 75 unsigned int idx,
40struct gpio_desc *__must_check devm_gpiod_get_optional(struct device *dev, 76 enum gpiod_flags flags);
41 const char *con_id); 77#define __devm_gpiod_get_index(dev, con_id, index, flags, ...) \
78 __devm_gpiod_get_index(dev, con_id, index, flags)
79#define devm_gpiod_get_index(varargs...) __devm_gpiod_get_index(varargs, 0)
80struct gpio_desc *__must_check __devm_gpiod_get_optional(struct device *dev,
81 const char *con_id,
82 enum gpiod_flags flags);
83#define __devm_gpiod_get_optional(dev, con_id, flags, ...) \
84 __devm_gpiod_get_optional(dev, con_id, flags)
85#define devm_gpiod_get_optional(varargs...) \
86 __devm_gpiod_get_optional(varargs, 0)
42struct gpio_desc *__must_check 87struct gpio_desc *__must_check
43devm_gpiod_get_index_optional(struct device *dev, const char *con_id, 88__devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
44 unsigned int index); 89 unsigned int index, enum gpiod_flags flags);
90#define __devm_gpiod_get_index_optional(dev, con_id, index, flags, ...) \
91 __devm_gpiod_get_index_optional(dev, con_id, index, flags)
92#define devm_gpiod_get_index_optional(varargs...) \
93 __devm_gpiod_get_index_optional(varargs, 0)
45 94
46void devm_gpiod_put(struct device *dev, struct gpio_desc *desc); 95void devm_gpiod_put(struct device *dev, struct gpio_desc *desc);
47 96