aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2014-07-22 11:01:01 -0400
committerLinus Walleij <linus.walleij@linaro.org>2014-07-24 04:25:00 -0400
commitf7d4ad98fdd08932ffda2354c62e2e2ee059adcc (patch)
tree86e7dc2cd3a2c617e27795762aacabbb779339e2
parentd82da79722400c63cc70f4c9c2493e31561ea607 (diff)
gpiolib: Export gpiochip_request_own_desc and gpiochip_free_own_desc
Both functions were introduced to let gpio drivers request their own gpio pins. Without exporting the functions, this can however only be used by gpio drivers built into the kernel. Secondary impact is that the functions can not currently be used by platform initialization code associated with the gpio-pca953x driver. This code permits auto-export of gpio pins through platform data, but if this functionality is used, the module can no longer be unloaded due to the problem solved with the introduction of gpiochip_request_own_desc and gpiochip_free_own_desc. Export both function so they can be used from modules and from platform initialization code. Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
-rw-r--r--Documentation/gpio/driver.txt21
-rw-r--r--drivers/gpio/gpiolib.c2
-rw-r--r--drivers/gpio/gpiolib.h3
-rw-r--r--include/linux/gpio/driver.h3
4 files changed, 26 insertions, 3 deletions
diff --git a/Documentation/gpio/driver.txt b/Documentation/gpio/driver.txt
index 224dbbcd1804..18790c237977 100644
--- a/Documentation/gpio/driver.txt
+++ b/Documentation/gpio/driver.txt
@@ -167,3 +167,24 @@ is released:
167When implementing an irqchip inside a GPIO driver, these two functions should 167When implementing an irqchip inside a GPIO driver, these two functions should
168typically be called in the .startup() and .shutdown() callbacks from the 168typically be called in the .startup() and .shutdown() callbacks from the
169irqchip. 169irqchip.
170
171
172Requesting self-owned GPIO pins
173-------------------------------
174
175Sometimes it is useful to allow a GPIO chip driver to request its own GPIO
176descriptors through the gpiolib API. Using gpio_request() for this purpose
177does not help since it pins the module to the kernel forever (it calls
178try_module_get()). A GPIO driver can use the following functions instead
179to request and free descriptors without being pinned to the kernel forever.
180
181 int gpiochip_request_own_desc(struct gpio_desc *desc, const char *label)
182
183 void gpiochip_free_own_desc(struct gpio_desc *desc)
184
185Descriptors requested with gpiochip_request_own_desc() must be released with
186gpiochip_free_own_desc().
187
188These functions must be used with care since they do not affect module use
189count. Do not use the functions to request gpio descriptors not owned by the
190calling driver.
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 412d64e93cfb..768f0831db18 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -897,6 +897,7 @@ int gpiochip_request_own_desc(struct gpio_desc *desc, const char *label)
897 897
898 return __gpiod_request(desc, label); 898 return __gpiod_request(desc, label);
899} 899}
900EXPORT_SYMBOL_GPL(gpiochip_request_own_desc);
900 901
901/** 902/**
902 * gpiochip_free_own_desc - Free GPIO requested by the chip driver 903 * gpiochip_free_own_desc - Free GPIO requested by the chip driver
@@ -910,6 +911,7 @@ void gpiochip_free_own_desc(struct gpio_desc *desc)
910 if (desc) 911 if (desc)
911 __gpiod_free(desc); 912 __gpiod_free(desc);
912} 913}
914EXPORT_SYMBOL_GPL(gpiochip_free_own_desc);
913 915
914/* Drivers MUST set GPIO direction before making get/set calls. In 916/* Drivers MUST set GPIO direction before making get/set calls. In
915 * some cases this is done in early boot, before IRQs are enabled. 917 * some cases this is done in early boot, before IRQs are enabled.
diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h
index acbb9335f08c..7fcb645ded4c 100644
--- a/drivers/gpio/gpiolib.h
+++ b/drivers/gpio/gpiolib.h
@@ -45,9 +45,6 @@ acpi_get_gpiod_by_index(struct device *dev, int index,
45} 45}
46#endif 46#endif
47 47
48int gpiochip_request_own_desc(struct gpio_desc *desc, const char *label);
49void gpiochip_free_own_desc(struct gpio_desc *desc);
50
51struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np, 48struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np,
52 const char *list_name, int index, enum of_gpio_flags *flags); 49 const char *list_name, int index, enum of_gpio_flags *flags);
53 50
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index c66c91682d9e..4c463fb0155e 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -220,6 +220,9 @@ int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
220 220
221#endif /* CONFIG_GPIO_IRQCHIP */ 221#endif /* CONFIG_GPIO_IRQCHIP */
222 222
223int gpiochip_request_own_desc(struct gpio_desc *desc, const char *label);
224void gpiochip_free_own_desc(struct gpio_desc *desc);
225
223#else /* CONFIG_GPIOLIB */ 226#else /* CONFIG_GPIOLIB */
224 227
225static inline struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc) 228static inline struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc)