aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpiolib.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-05-17 20:39:42 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-05-17 20:39:42 -0400
commit1eccc6e1529ec7ad1cebbd2c97ceb2a1a39f7d76 (patch)
tree725aff1150489e706b2b8b854b195a7a50dc6501 /drivers/gpio/gpiolib.c
parentdcc4c2f61cdc7e0ab61b25b8d28205302497a8c4 (diff)
parentd30a2b47d4c2b75573d93f60655d48ba8e3ed2b3 (diff)
Merge tag 'gpio-v4.7-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio
Pull GPIO updates from Linus Walleij: "This is the bulk of GPIO changes for kernel cycle v4.7: Core infrastructural changes: - Support for natively single-ended GPIO driver stages. This means that if the hardware has registers to configure open drain or open source configuration, we use that rather than (as we did before) try to emulate it by switching the line to an input to get high impedance. This is also documented throughly in Documentation/gpio/driver.txt for those of you who did not understand one word of what I just wrote. - Start to do away with the unnecessarily complex and unitelligible ARCH_REQUIRE_GPIOLIB and ARCH_WANT_OPTIONAL_GPIOLIB, another evolutional artifact from the time when the GPIO subsystem was unmaintained. Archs can now just select GPIOLIB and be done with it, cleanups to arches will trickle in for the next kernel. Some minor archs ACKed the changes immediately so these are included in this pull request. - Advancing the use of the data pointer inside the GPIO device for storing driver data by switching the PowerPC, Super-H Unicore and a few other subarches or subsystem drivers in ALSA SoC, Input, serial, SSB, staging etc to use it. - The initialization now reads the input/output state of the GPIO lines, so that each GPIO descriptor knows - if this callback is implemented - whether the line is input or output. This also reflects nicely in userspace "lsgpio". - It is now possible to name GPIO producer names, line names, from the device tree. (Platform data has been supported for a while). I bet we will get a similar mechanism for ACPI one of those days. This makes is possible to get sensible producer names for e.g. GPIO rails in "lsgpio" in userspace. New drivers: - New driver for the Loongson1. - The XLP driver now supports Broadcom Vulcan ARM64. - The IT87 driver now supports IT8620 and IT8628. - The PCA953X driver now supports Galileo Gen2. Driver improvements: - MCP23S08 was switched to use the gpiolib irqchip helpers and now also suppors level-triggered interrupts. - 74x164 and RCAR now supports the .set_multiple() callback - AMDPT was converted to use generic GPIO. - TC3589x, TPS65218, SX150X, F7188X, MENZ127, VX855, WM831X, WM8994 support the new single ended callback for open drain and in some cases open source. - Implement the .get_direction() callback for a few more drivers like PL061, Xgene. Cleanups: - Paul Gortmaker combed through the drivers and de-modularized those who are not really modules. - Move the GPIO poweroff DT bindings to the power subdir where they belong. - Rename gpio-generic.c to gpio-mmio.c, which is much more to the point. That's what it is handling, nothing more, nothing less" * tag 'gpio-v4.7-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (126 commits) MIPS: do away with ARCH_[WANT_OPTIONAL|REQUIRE]_GPIOLIB gpio: zevio: make it explicitly non-modular gpio: timberdale: make it explicitly non-modular gpio: stmpe: make it explicitly non-modular gpio: sodaville: make it explicitly non-modular pinctrl: sh-pfc: Let gpio_chip.to_irq() return zero on error gpio: dwapb: Add ACPI device ID for DWAPB GPIO controller on X-Gene platforms gpio: dt-bindings: add wd,mbl-gpio bindings gpio: of: make it possible to name GPIO lines gpio: make gpiod_to_irq() return negative for NO_IRQ gpio: xgene: implement .get_direction() gpio: xgene: Enable ACPI support for X-Gene GFC GPIO driver gpio: tegra: Implement gpio_get_direction callback gpio: set up initial state from .get_direction() gpio: rename gpio-generic.c into gpio-mmio.c gpio: generic: fix GPIO_GENERIC_PLATFORM is set to module case gpio: dwapb: add gpio-signaled acpi event support gpio: dwapb: convert device node to fwnode gpio: dwapb: remove name from dwapb_port_property gpio/qoriq: select IRQ_DOMAIN ...
Diffstat (limited to 'drivers/gpio/gpiolib.c')
-rw-r--r--drivers/gpio/gpiolib.c133
1 files changed, 91 insertions, 42 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index b747c76fd2b1..d407f904a31c 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -622,14 +622,31 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data)
622 struct gpio_desc *desc = &gdev->descs[i]; 622 struct gpio_desc *desc = &gdev->descs[i];
623 623
624 desc->gdev = gdev; 624 desc->gdev = gdev;
625 625 /*
626 /* REVISIT: most hardware initializes GPIOs as inputs (often 626 * REVISIT: most hardware initializes GPIOs as inputs
627 * with pullups enabled) so power usage is minimized. Linux 627 * (often with pullups enabled) so power usage is
628 * code should set the gpio direction first thing; but until 628 * minimized. Linux code should set the gpio direction
629 * it does, and in case chip->get_direction is not set, we may 629 * first thing; but until it does, and in case
630 * expose the wrong direction in sysfs. 630 * chip->get_direction is not set, we may expose the
631 * wrong direction in sysfs.
631 */ 632 */
632 desc->flags = !chip->direction_input ? (1 << FLAG_IS_OUT) : 0; 633
634 if (chip->get_direction) {
635 /*
636 * If we have .get_direction, set up the initial
637 * direction flag from the hardware.
638 */
639 int dir = chip->get_direction(chip, i);
640
641 if (!dir)
642 set_bit(FLAG_IS_OUT, &desc->flags);
643 } else if (!chip->direction_input) {
644 /*
645 * If the chip lacks the .direction_input callback
646 * we logically assume all lines are outputs.
647 */
648 set_bit(FLAG_IS_OUT, &desc->flags);
649 }
633 } 650 }
634 651
635 spin_unlock_irqrestore(&gpio_lock, flags); 652 spin_unlock_irqrestore(&gpio_lock, flags);
@@ -1547,8 +1564,8 @@ EXPORT_SYMBOL_GPL(gpiod_direction_input);
1547 1564
1548static int _gpiod_direction_output_raw(struct gpio_desc *desc, int value) 1565static int _gpiod_direction_output_raw(struct gpio_desc *desc, int value)
1549{ 1566{
1550 struct gpio_chip *chip; 1567 struct gpio_chip *gc = desc->gdev->chip;
1551 int status = -EINVAL; 1568 int ret;
1552 1569
1553 /* GPIOs used for IRQs shall not be set as output */ 1570 /* GPIOs used for IRQs shall not be set as output */
1554 if (test_bit(FLAG_USED_AS_IRQ, &desc->flags)) { 1571 if (test_bit(FLAG_USED_AS_IRQ, &desc->flags)) {
@@ -1558,28 +1575,50 @@ static int _gpiod_direction_output_raw(struct gpio_desc *desc, int value)
1558 return -EIO; 1575 return -EIO;
1559 } 1576 }
1560 1577
1561 /* Open drain pin should not be driven to 1 */ 1578 if (test_bit(FLAG_OPEN_DRAIN, &desc->flags)) {
1562 if (value && test_bit(FLAG_OPEN_DRAIN, &desc->flags)) 1579 /* First see if we can enable open drain in hardware */
1563 return gpiod_direction_input(desc); 1580 if (gc->set_single_ended) {
1564 1581 ret = gc->set_single_ended(gc, gpio_chip_hwgpio(desc),
1565 /* Open source pin should not be driven to 0 */ 1582 LINE_MODE_OPEN_DRAIN);
1566 if (!value && test_bit(FLAG_OPEN_SOURCE, &desc->flags)) 1583 if (!ret)
1567 return gpiod_direction_input(desc); 1584 goto set_output_value;
1585 }
1586 /* Emulate open drain by not actively driving the line high */
1587 if (value)
1588 return gpiod_direction_input(desc);
1589 }
1590 else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) {
1591 if (gc->set_single_ended) {
1592 ret = gc->set_single_ended(gc, gpio_chip_hwgpio(desc),
1593 LINE_MODE_OPEN_SOURCE);
1594 if (!ret)
1595 goto set_output_value;
1596 }
1597 /* Emulate open source by not actively driving the line low */
1598 if (!value)
1599 return gpiod_direction_input(desc);
1600 } else {
1601 /* Make sure to disable open drain/source hardware, if any */
1602 if (gc->set_single_ended)
1603 gc->set_single_ended(gc,
1604 gpio_chip_hwgpio(desc),
1605 LINE_MODE_PUSH_PULL);
1606 }
1568 1607
1569 chip = desc->gdev->chip; 1608set_output_value:
1570 if (!chip->set || !chip->direction_output) { 1609 if (!gc->set || !gc->direction_output) {
1571 gpiod_warn(desc, 1610 gpiod_warn(desc,
1572 "%s: missing set() or direction_output() operations\n", 1611 "%s: missing set() or direction_output() operations\n",
1573 __func__); 1612 __func__);
1574 return -EIO; 1613 return -EIO;
1575 } 1614 }
1576 1615
1577 status = chip->direction_output(chip, gpio_chip_hwgpio(desc), value); 1616 ret = gc->direction_output(gc, gpio_chip_hwgpio(desc), value);
1578 if (status == 0) 1617 if (!ret)
1579 set_bit(FLAG_IS_OUT, &desc->flags); 1618 set_bit(FLAG_IS_OUT, &desc->flags);
1580 trace_gpio_value(desc_to_gpio(desc), 0, value); 1619 trace_gpio_value(desc_to_gpio(desc), 0, value);
1581 trace_gpio_direction(desc_to_gpio(desc), 0, status); 1620 trace_gpio_direction(desc_to_gpio(desc), 0, ret);
1582 return status; 1621 return ret;
1583} 1622}
1584 1623
1585/** 1624/**
@@ -1841,10 +1880,10 @@ static void gpio_chip_set_multiple(struct gpio_chip *chip,
1841 } 1880 }
1842} 1881}
1843 1882
1844static void gpiod_set_array_value_priv(bool raw, bool can_sleep, 1883void gpiod_set_array_value_complex(bool raw, bool can_sleep,
1845 unsigned int array_size, 1884 unsigned int array_size,
1846 struct gpio_desc **desc_array, 1885 struct gpio_desc **desc_array,
1847 int *value_array) 1886 int *value_array)
1848{ 1887{
1849 int i = 0; 1888 int i = 0;
1850 1889
@@ -1950,8 +1989,8 @@ void gpiod_set_raw_array_value(unsigned int array_size,
1950{ 1989{
1951 if (!desc_array) 1990 if (!desc_array)
1952 return; 1991 return;
1953 gpiod_set_array_value_priv(true, false, array_size, desc_array, 1992 gpiod_set_array_value_complex(true, false, array_size, desc_array,
1954 value_array); 1993 value_array);
1955} 1994}
1956EXPORT_SYMBOL_GPL(gpiod_set_raw_array_value); 1995EXPORT_SYMBOL_GPL(gpiod_set_raw_array_value);
1957 1996
@@ -1972,8 +2011,8 @@ void gpiod_set_array_value(unsigned int array_size,
1972{ 2011{
1973 if (!desc_array) 2012 if (!desc_array)
1974 return; 2013 return;
1975 gpiod_set_array_value_priv(false, false, array_size, desc_array, 2014 gpiod_set_array_value_complex(false, false, array_size, desc_array,
1976 value_array); 2015 value_array);
1977} 2016}
1978EXPORT_SYMBOL_GPL(gpiod_set_array_value); 2017EXPORT_SYMBOL_GPL(gpiod_set_array_value);
1979 2018
@@ -1998,13 +2037,22 @@ EXPORT_SYMBOL_GPL(gpiod_cansleep);
1998 */ 2037 */
1999int gpiod_to_irq(const struct gpio_desc *desc) 2038int gpiod_to_irq(const struct gpio_desc *desc)
2000{ 2039{
2001 struct gpio_chip *chip; 2040 struct gpio_chip *chip;
2002 int offset; 2041 int offset;
2003 2042
2004 VALIDATE_DESC(desc); 2043 VALIDATE_DESC(desc);
2005 chip = desc->gdev->chip; 2044 chip = desc->gdev->chip;
2006 offset = gpio_chip_hwgpio(desc); 2045 offset = gpio_chip_hwgpio(desc);
2007 return chip->to_irq ? chip->to_irq(chip, offset) : -ENXIO; 2046 if (chip->to_irq) {
2047 int retirq = chip->to_irq(chip, offset);
2048
2049 /* Zero means NO_IRQ */
2050 if (!retirq)
2051 return -ENXIO;
2052
2053 return retirq;
2054 }
2055 return -ENXIO;
2008} 2056}
2009EXPORT_SYMBOL_GPL(gpiod_to_irq); 2057EXPORT_SYMBOL_GPL(gpiod_to_irq);
2010 2058
@@ -2176,8 +2224,8 @@ void gpiod_set_raw_array_value_cansleep(unsigned int array_size,
2176 might_sleep_if(extra_checks); 2224 might_sleep_if(extra_checks);
2177 if (!desc_array) 2225 if (!desc_array)
2178 return; 2226 return;
2179 gpiod_set_array_value_priv(true, true, array_size, desc_array, 2227 gpiod_set_array_value_complex(true, true, array_size, desc_array,
2180 value_array); 2228 value_array);
2181} 2229}
2182EXPORT_SYMBOL_GPL(gpiod_set_raw_array_value_cansleep); 2230EXPORT_SYMBOL_GPL(gpiod_set_raw_array_value_cansleep);
2183 2231
@@ -2199,8 +2247,8 @@ void gpiod_set_array_value_cansleep(unsigned int array_size,
2199 might_sleep_if(extra_checks); 2247 might_sleep_if(extra_checks);
2200 if (!desc_array) 2248 if (!desc_array)
2201 return; 2249 return;
2202 gpiod_set_array_value_priv(false, true, array_size, desc_array, 2250 gpiod_set_array_value_complex(false, true, array_size, desc_array,
2203 value_array); 2251 value_array);
2204} 2252}
2205EXPORT_SYMBOL_GPL(gpiod_set_array_value_cansleep); 2253EXPORT_SYMBOL_GPL(gpiod_set_array_value_cansleep);
2206 2254
@@ -2726,15 +2774,16 @@ int gpiod_hog(struct gpio_desc *desc, const char *name,
2726 2774
2727 local_desc = gpiochip_request_own_desc(chip, hwnum, name); 2775 local_desc = gpiochip_request_own_desc(chip, hwnum, name);
2728 if (IS_ERR(local_desc)) { 2776 if (IS_ERR(local_desc)) {
2729 pr_err("requesting hog GPIO %s (chip %s, offset %d) failed\n", 2777 status = PTR_ERR(local_desc);
2730 name, chip->label, hwnum); 2778 pr_err("requesting hog GPIO %s (chip %s, offset %d) failed, %d\n",
2731 return PTR_ERR(local_desc); 2779 name, chip->label, hwnum, status);
2780 return status;
2732 } 2781 }
2733 2782
2734 status = gpiod_configure_flags(desc, name, dflags); 2783 status = gpiod_configure_flags(desc, name, dflags);
2735 if (status < 0) { 2784 if (status < 0) {
2736 pr_err("setup of hog GPIO %s (chip %s, offset %d) failed\n", 2785 pr_err("setup of hog GPIO %s (chip %s, offset %d) failed, %d\n",
2737 name, chip->label, hwnum); 2786 name, chip->label, hwnum, status);
2738 gpiochip_free_own_desc(desc); 2787 gpiochip_free_own_desc(desc);
2739 return status; 2788 return status;
2740 } 2789 }