aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpiolib.c
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2013-12-09 08:04:37 -0500
committerLinus Walleij <linus.walleij@linaro.org>2013-12-09 08:04:37 -0500
commitbdc54ef45d7670aeb52ce73f8b7ad5f3e5563661 (patch)
treeda6e170ce87891a0242de88d8d7c1ba34faf9bb7 /drivers/gpio/gpiolib.c
parent33e0aae11e4854c792e9871f94da6d28bf2e2bb8 (diff)
parent374b105797c3d4f29c685f3be535c35f5689b30e (diff)
Merge tag 'v3.13-rc3' into devel
Linux 3.13-rc3
Diffstat (limited to 'drivers/gpio/gpiolib.c')
-rw-r--r--drivers/gpio/gpiolib.c78
1 files changed, 47 insertions, 31 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 94467ddb3711..44a232701179 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -14,6 +14,7 @@
14#include <linux/idr.h> 14#include <linux/idr.h>
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/acpi.h> 16#include <linux/acpi.h>
17#include <linux/gpio/driver.h>
17 18
18#define CREATE_TRACE_POINTS 19#define CREATE_TRACE_POINTS
19#include <trace/events/gpio.h> 20#include <trace/events/gpio.h>
@@ -1309,6 +1310,18 @@ struct gpio_chip *gpiochip_find(void *data,
1309} 1310}
1310EXPORT_SYMBOL_GPL(gpiochip_find); 1311EXPORT_SYMBOL_GPL(gpiochip_find);
1311 1312
1313static int gpiochip_match_name(struct gpio_chip *chip, void *data)
1314{
1315 const char *name = data;
1316
1317 return !strcmp(chip->label, name);
1318}
1319
1320static struct gpio_chip *find_chip_by_name(const char *name)
1321{
1322 return gpiochip_find((void *)name, gpiochip_match_name);
1323}
1324
1312#ifdef CONFIG_PINCTRL 1325#ifdef CONFIG_PINCTRL
1313 1326
1314/** 1327/**
@@ -1342,8 +1355,10 @@ int gpiochip_add_pingroup_range(struct gpio_chip *chip,
1342 ret = pinctrl_get_group_pins(pctldev, pin_group, 1355 ret = pinctrl_get_group_pins(pctldev, pin_group,
1343 &pin_range->range.pins, 1356 &pin_range->range.pins,
1344 &pin_range->range.npins); 1357 &pin_range->range.npins);
1345 if (ret < 0) 1358 if (ret < 0) {
1359 kfree(pin_range);
1346 return ret; 1360 return ret;
1361 }
1347 1362
1348 pinctrl_add_gpio_range(pctldev, &pin_range->range); 1363 pinctrl_add_gpio_range(pctldev, &pin_range->range);
1349 1364
@@ -2261,26 +2276,10 @@ void gpiod_add_table(struct gpiod_lookup *table, size_t size)
2261 mutex_unlock(&gpio_lookup_lock); 2276 mutex_unlock(&gpio_lookup_lock);
2262} 2277}
2263 2278
2264/*
2265 * Caller must have a acquired gpio_lookup_lock
2266 */
2267static struct gpio_chip *find_chip_by_name(const char *name)
2268{
2269 struct gpio_chip *chip = NULL;
2270
2271 list_for_each_entry(chip, &gpio_lookup_list, list) {
2272 if (chip->label == NULL)
2273 continue;
2274 if (!strcmp(chip->label, name))
2275 break;
2276 }
2277
2278 return chip;
2279}
2280
2281#ifdef CONFIG_OF 2279#ifdef CONFIG_OF
2282static struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, 2280static struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
2283 unsigned int idx, unsigned long *flags) 2281 unsigned int idx,
2282 enum gpio_lookup_flags *flags)
2284{ 2283{
2285 char prop_name[32]; /* 32 is max size of property name */ 2284 char prop_name[32]; /* 32 is max size of property name */
2286 enum of_gpio_flags of_flags; 2285 enum of_gpio_flags of_flags;
@@ -2298,20 +2297,22 @@ static struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
2298 return desc; 2297 return desc;
2299 2298
2300 if (of_flags & OF_GPIO_ACTIVE_LOW) 2299 if (of_flags & OF_GPIO_ACTIVE_LOW)
2301 *flags |= GPIOF_ACTIVE_LOW; 2300 *flags |= GPIO_ACTIVE_LOW;
2302 2301
2303 return desc; 2302 return desc;
2304} 2303}
2305#else 2304#else
2306static struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, 2305static struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
2307 unsigned int idx, unsigned long *flags) 2306 unsigned int idx,
2307 enum gpio_lookup_flags *flags)
2308{ 2308{
2309 return ERR_PTR(-ENODEV); 2309 return ERR_PTR(-ENODEV);
2310} 2310}
2311#endif 2311#endif
2312 2312
2313static struct gpio_desc *acpi_find_gpio(struct device *dev, const char *con_id, 2313static struct gpio_desc *acpi_find_gpio(struct device *dev, const char *con_id,
2314 unsigned int idx, unsigned long *flags) 2314 unsigned int idx,
2315 enum gpio_lookup_flags *flags)
2315{ 2316{
2316 struct acpi_gpio_info info; 2317 struct acpi_gpio_info info;
2317 struct gpio_desc *desc; 2318 struct gpio_desc *desc;
@@ -2321,13 +2322,14 @@ static struct gpio_desc *acpi_find_gpio(struct device *dev, const char *con_id,
2321 return desc; 2322 return desc;
2322 2323
2323 if (info.gpioint && info.active_low) 2324 if (info.gpioint && info.active_low)
2324 *flags |= GPIOF_ACTIVE_LOW; 2325 *flags |= GPIO_ACTIVE_LOW;
2325 2326
2326 return desc; 2327 return desc;
2327} 2328}
2328 2329
2329static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id, 2330static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id,
2330 unsigned int idx, unsigned long *flags) 2331 unsigned int idx,
2332 enum gpio_lookup_flags *flags)
2331{ 2333{
2332 const char *dev_id = dev ? dev_name(dev) : NULL; 2334 const char *dev_id = dev ? dev_name(dev) : NULL;
2333 struct gpio_desc *desc = ERR_PTR(-ENODEV); 2335 struct gpio_desc *desc = ERR_PTR(-ENODEV);
@@ -2367,7 +2369,7 @@ static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id,
2367 continue; 2369 continue;
2368 } 2370 }
2369 2371
2370 if (chip->ngpio >= p->chip_hwnum) { 2372 if (chip->ngpio <= p->chip_hwnum) {
2371 dev_warn(dev, "GPIO chip %s has %d GPIOs\n", 2373 dev_warn(dev, "GPIO chip %s has %d GPIOs\n",
2372 chip->label, chip->ngpio); 2374 chip->label, chip->ngpio);
2373 continue; 2375 continue;
@@ -2417,9 +2419,9 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
2417 const char *con_id, 2419 const char *con_id,
2418 unsigned int idx) 2420 unsigned int idx)
2419{ 2421{
2420 struct gpio_desc *desc; 2422 struct gpio_desc *desc = NULL;
2421 int status; 2423 int status;
2422 unsigned long flags = 0; 2424 enum gpio_lookup_flags flags = 0;
2423 2425
2424 dev_dbg(dev, "GPIO lookup for consumer %s\n", con_id); 2426 dev_dbg(dev, "GPIO lookup for consumer %s\n", con_id);
2425 2427
@@ -2430,13 +2432,23 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
2430 } else if (IS_ENABLED(CONFIG_ACPI) && dev && ACPI_HANDLE(dev)) { 2432 } else if (IS_ENABLED(CONFIG_ACPI) && dev && ACPI_HANDLE(dev)) {
2431 dev_dbg(dev, "using ACPI for GPIO lookup\n"); 2433 dev_dbg(dev, "using ACPI for GPIO lookup\n");
2432 desc = acpi_find_gpio(dev, con_id, idx, &flags); 2434 desc = acpi_find_gpio(dev, con_id, idx, &flags);
2433 } else { 2435 }
2436
2437 /*
2438 * Either we are not using DT or ACPI, or their lookup did not return
2439 * a result. In that case, use platform lookup as a fallback.
2440 */
2441 if (!desc || IS_ERR(desc)) {
2442 struct gpio_desc *pdesc;
2434 dev_dbg(dev, "using lookup tables for GPIO lookup"); 2443 dev_dbg(dev, "using lookup tables for GPIO lookup");
2435 desc = gpiod_find(dev, con_id, idx, &flags); 2444 pdesc = gpiod_find(dev, con_id, idx, &flags);
2445 /* If used as fallback, do not replace the previous error */
2446 if (!IS_ERR(pdesc) || !desc)
2447 desc = pdesc;
2436 } 2448 }
2437 2449
2438 if (IS_ERR(desc)) { 2450 if (IS_ERR(desc)) {
2439 dev_warn(dev, "lookup for GPIO %s failed\n", con_id); 2451 dev_dbg(dev, "lookup for GPIO %s failed\n", con_id);
2440 return desc; 2452 return desc;
2441 } 2453 }
2442 2454
@@ -2445,8 +2457,12 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
2445 if (status < 0) 2457 if (status < 0)
2446 return ERR_PTR(status); 2458 return ERR_PTR(status);
2447 2459
2448 if (flags & GPIOF_ACTIVE_LOW) 2460 if (flags & GPIO_ACTIVE_LOW)
2449 set_bit(FLAG_ACTIVE_LOW, &desc->flags); 2461 set_bit(FLAG_ACTIVE_LOW, &desc->flags);
2462 if (flags & GPIO_OPEN_DRAIN)
2463 set_bit(FLAG_OPEN_DRAIN, &desc->flags);
2464 if (flags & GPIO_OPEN_SOURCE)
2465 set_bit(FLAG_OPEN_SOURCE, &desc->flags);
2450 2466
2451 return desc; 2467 return desc;
2452} 2468}