aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2016-10-03 04:40:03 -0400
committerLinus Walleij <linus.walleij@linaro.org>2016-10-03 17:38:10 -0400
commit031ba28a8197a08e67b12d7ec935b24eb3638345 (patch)
tree3e823552153799ffb990cc7b9eb05b541a6b5745 /drivers/gpio
parentea713bc450054aed3114da74bf76cfda64b698d0 (diff)
gpio: acpi: separation of concerns
The generic GPIO library directly implement code for acpi_find_gpio() which is only used with CONFIG_ACPI. This was probably done because OF did the same thing, but I removed that so remove this too. Rename the internal acpi_find_gpio() in gpiolib-acpi.c to acpi_populate_gpio_lookup() which seems to be more appropriate anyway so as to avoid a namespace clash with the same function. Make the stub return -ENOENT rather than -ENOSYS (as that is for syscalls!). For some reason the sunxi pin control driver was including the private gpiolib header, it works just fine without it so remove that oneliner. Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio')
-rw-r--r--drivers/gpio/gpiolib-acpi.c57
-rw-r--r--drivers/gpio/gpiolib.c49
-rw-r--r--drivers/gpio/gpiolib.h15
3 files changed, 63 insertions, 58 deletions
diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index af514618d7fb..58ece201b8e6 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -14,6 +14,7 @@
14#include <linux/gpio.h> 14#include <linux/gpio.h>
15#include <linux/gpio/consumer.h> 15#include <linux/gpio/consumer.h>
16#include <linux/gpio/driver.h> 16#include <linux/gpio/driver.h>
17#include <linux/gpio/machine.h>
17#include <linux/export.h> 18#include <linux/export.h>
18#include <linux/acpi.h> 19#include <linux/acpi.h>
19#include <linux/interrupt.h> 20#include <linux/interrupt.h>
@@ -395,7 +396,7 @@ struct acpi_gpio_lookup {
395 int n; 396 int n;
396}; 397};
397 398
398static int acpi_find_gpio(struct acpi_resource *ares, void *data) 399static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data)
399{ 400{
400 struct acpi_gpio_lookup *lookup = data; 401 struct acpi_gpio_lookup *lookup = data;
401 402
@@ -440,7 +441,8 @@ static int acpi_gpio_resource_lookup(struct acpi_gpio_lookup *lookup,
440 441
441 INIT_LIST_HEAD(&res_list); 442 INIT_LIST_HEAD(&res_list);
442 443
443 ret = acpi_dev_get_resources(lookup->adev, &res_list, acpi_find_gpio, 444 ret = acpi_dev_get_resources(lookup->adev, &res_list,
445 acpi_populate_gpio_lookup,
444 lookup); 446 lookup);
445 if (ret < 0) 447 if (ret < 0)
446 return ret; 448 return ret;
@@ -513,7 +515,7 @@ static int acpi_gpio_property_lookup(struct fwnode_handle *fwnode,
513 * Note: if the GPIO resource has multiple entries in the pin list, this 515 * Note: if the GPIO resource has multiple entries in the pin list, this
514 * function only returns the first. 516 * function only returns the first.
515 */ 517 */
516struct gpio_desc *acpi_get_gpiod_by_index(struct acpi_device *adev, 518static struct gpio_desc *acpi_get_gpiod_by_index(struct acpi_device *adev,
517 const char *propname, int index, 519 const char *propname, int index,
518 struct acpi_gpio_info *info) 520 struct acpi_gpio_info *info)
519{ 521{
@@ -546,6 +548,55 @@ struct gpio_desc *acpi_get_gpiod_by_index(struct acpi_device *adev,
546 return ret ? ERR_PTR(ret) : lookup.desc; 548 return ret ? ERR_PTR(ret) : lookup.desc;
547} 549}
548 550
551struct gpio_desc *acpi_find_gpio(struct device *dev,
552 const char *con_id,
553 unsigned int idx,
554 enum gpiod_flags flags,
555 enum gpio_lookup_flags *lookupflags)
556{
557 struct acpi_device *adev = ACPI_COMPANION(dev);
558 struct acpi_gpio_info info;
559 struct gpio_desc *desc;
560 char propname[32];
561 int i;
562
563 /* Try first from _DSD */
564 for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) {
565 if (con_id && strcmp(con_id, "gpios")) {
566 snprintf(propname, sizeof(propname), "%s-%s",
567 con_id, gpio_suffixes[i]);
568 } else {
569 snprintf(propname, sizeof(propname), "%s",
570 gpio_suffixes[i]);
571 }
572
573 desc = acpi_get_gpiod_by_index(adev, propname, idx, &info);
574 if (!IS_ERR(desc) || (PTR_ERR(desc) == -EPROBE_DEFER))
575 break;
576 }
577
578 /* Then from plain _CRS GPIOs */
579 if (IS_ERR(desc)) {
580 if (!acpi_can_fallback_to_crs(adev, con_id))
581 return ERR_PTR(-ENOENT);
582
583 desc = acpi_get_gpiod_by_index(adev, NULL, idx, &info);
584 if (IS_ERR(desc))
585 return desc;
586
587 if ((flags == GPIOD_OUT_LOW || flags == GPIOD_OUT_HIGH) &&
588 info.gpioint) {
589 dev_dbg(dev, "refusing GpioInt() entry when doing GPIOD_OUT_* lookup\n");
590 return ERR_PTR(-ENOENT);
591 }
592 }
593
594 if (info.polarity == GPIO_ACTIVE_LOW)
595 *lookupflags |= GPIO_ACTIVE_LOW;
596
597 return desc;
598}
599
549/** 600/**
550 * acpi_node_get_gpiod() - get a GPIO descriptor from ACPI resources 601 * acpi_node_get_gpiod() - get a GPIO descriptor from ACPI resources
551 * @fwnode: pointer to an ACPI firmware node to get the GPIO information from 602 * @fwnode: pointer to an ACPI firmware node to get the GPIO information from
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 5404cdcfed19..f0fc3a0d37c8 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -2883,55 +2883,6 @@ void gpiod_remove_lookup_table(struct gpiod_lookup_table *table)
2883 mutex_unlock(&gpio_lookup_lock); 2883 mutex_unlock(&gpio_lookup_lock);
2884} 2884}
2885 2885
2886static struct gpio_desc *acpi_find_gpio(struct device *dev,
2887 const char *con_id,
2888 unsigned int idx,
2889 enum gpiod_flags flags,
2890 enum gpio_lookup_flags *lookupflags)
2891{
2892 struct acpi_device *adev = ACPI_COMPANION(dev);
2893 struct acpi_gpio_info info;
2894 struct gpio_desc *desc;
2895 char propname[32];
2896 int i;
2897
2898 /* Try first from _DSD */
2899 for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) {
2900 if (con_id && strcmp(con_id, "gpios")) {
2901 snprintf(propname, sizeof(propname), "%s-%s",
2902 con_id, gpio_suffixes[i]);
2903 } else {
2904 snprintf(propname, sizeof(propname), "%s",
2905 gpio_suffixes[i]);
2906 }
2907
2908 desc = acpi_get_gpiod_by_index(adev, propname, idx, &info);
2909 if (!IS_ERR(desc) || (PTR_ERR(desc) == -EPROBE_DEFER))
2910 break;
2911 }
2912
2913 /* Then from plain _CRS GPIOs */
2914 if (IS_ERR(desc)) {
2915 if (!acpi_can_fallback_to_crs(adev, con_id))
2916 return ERR_PTR(-ENOENT);
2917
2918 desc = acpi_get_gpiod_by_index(adev, NULL, idx, &info);
2919 if (IS_ERR(desc))
2920 return desc;
2921
2922 if ((flags == GPIOD_OUT_LOW || flags == GPIOD_OUT_HIGH) &&
2923 info.gpioint) {
2924 dev_dbg(dev, "refusing GpioInt() entry when doing GPIOD_OUT_* lookup\n");
2925 return ERR_PTR(-ENOENT);
2926 }
2927 }
2928
2929 if (info.polarity == GPIO_ACTIVE_LOW)
2930 *lookupflags |= GPIO_ACTIVE_LOW;
2931
2932 return desc;
2933}
2934
2935static struct gpiod_lookup_table *gpiod_find_lookup_table(struct device *dev) 2886static struct gpiod_lookup_table *gpiod_find_lookup_table(struct device *dev)
2936{ 2887{
2937 const char *dev_id = dev ? dev_name(dev) : NULL; 2888 const char *dev_id = dev ? dev_name(dev) : NULL;
diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h
index 9ed29342f41e..d4c139ceb0a3 100644
--- a/drivers/gpio/gpiolib.h
+++ b/drivers/gpio/gpiolib.h
@@ -109,9 +109,11 @@ void acpi_gpiochip_remove(struct gpio_chip *chip);
109void acpi_gpiochip_request_interrupts(struct gpio_chip *chip); 109void acpi_gpiochip_request_interrupts(struct gpio_chip *chip);
110void acpi_gpiochip_free_interrupts(struct gpio_chip *chip); 110void acpi_gpiochip_free_interrupts(struct gpio_chip *chip);
111 111
112struct gpio_desc *acpi_get_gpiod_by_index(struct acpi_device *adev, 112struct gpio_desc *acpi_find_gpio(struct device *dev,
113 const char *propname, int index, 113 const char *con_id,
114 struct acpi_gpio_info *info); 114 unsigned int idx,
115 enum gpiod_flags flags,
116 enum gpio_lookup_flags *lookupflags);
115struct gpio_desc *acpi_node_get_gpiod(struct fwnode_handle *fwnode, 117struct gpio_desc *acpi_node_get_gpiod(struct fwnode_handle *fwnode,
116 const char *propname, int index, 118 const char *propname, int index,
117 struct acpi_gpio_info *info); 119 struct acpi_gpio_info *info);
@@ -130,10 +132,11 @@ static inline void
130acpi_gpiochip_free_interrupts(struct gpio_chip *chip) { } 132acpi_gpiochip_free_interrupts(struct gpio_chip *chip) { }
131 133
132static inline struct gpio_desc * 134static inline struct gpio_desc *
133acpi_get_gpiod_by_index(struct acpi_device *adev, const char *propname, 135acpi_find_gpio(struct device *dev, const char *con_id,
134 int index, struct acpi_gpio_info *info) 136 unsigned int idx, enum gpiod_flags flags,
137 enum gpio_lookup_flags *lookupflags)
135{ 138{
136 return ERR_PTR(-ENOSYS); 139 return ERR_PTR(-ENOENT);
137} 140}
138static inline struct gpio_desc * 141static inline struct gpio_desc *
139acpi_node_get_gpiod(struct fwnode_handle *fwnode, const char *propname, 142acpi_node_get_gpiod(struct fwnode_handle *fwnode, const char *propname,