aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpiolib.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-08-16 00:35:38 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-08-16 00:35:38 -0400
commit6de4c691eab8f421e34c5250f63bf3f477d30eec (patch)
treedd3deaa163bb478b13778a712afdfccc8cf43f20 /drivers/gpio/gpiolib.c
parentc1c2ad82c772966d3cdb9a4852329fa2cf71853a (diff)
parenta5ec96ddfd55c501d451cb310566a1170c267ecb (diff)
Merge tag 'gpio-v4.19-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 the v4.19 kernel cycle. I don't know if anything in particular stands out. Maybe the Aspeed coprocessor thing from Benji: Aspeed is doing baseboard management chips (BMC's) for servers etc. These Aspeed's are ARM processors that exist inside (I guess) Intel servers, and they are moving forward to using mainline Linux in those. This is one of the pieces of the puzzle to achive that. They are doing OpenBMC, it's pretty cool: https://lwn.net/Articles/683320/ Summary: Core changes: - Add a new API for explicitly naming GPIO consumers, when needed. - Don't let userspace set values on input lines. While we do not think anyone would do this crazy thing we better plug the hole before someone uses it and think it's a nifty feature. - Avoid calling chip->request() for unused GPIOs. New drivers/subdrivers: - The Mediatek MT7621 is supported which is a big win for OpenWRT and similar router distributions using this chip, as it seems every major router manufacturer on the planet has made products using this chip: https://wikidevi.com/wiki/MediaTek_MT7621 - The Tegra 194 is now supported. - The IT87 driver now supports IT8786E and IT8718F super-IO chips. - Add support for Rockchip RK3328 in the syscon GPIO driver. Driver changes: - Handle the get/set_multiple() properly on MMIO chips with inverted direction registers. We didn't have this problem until a new chip appear that has get/set registers AND inverted direction bits, OK now we handle it. - A patch series making more error codes percolate upward properly for different errors on gpiochip_lock_as_irq(). - Get/set multiple for the OMAP driver, accelerating these multiple line operations if possible. - A coprocessor interface for the Aspeed driver. Sometimes a few GPIO lines need to be grabbed by a co-processor for doing automated tasks, sometimes they are available as GPIO lines. By adding an explicit API in this driver we make it possible for the two line consumers to coexist. (This work was made available on the ib-aspeed branch, which may be appearing in other pull requests.) - Implemented .get_direction() and open drain in the SCH311x driver. - Continuing cleanup of included headers in GPIO drivers" * tag 'gpio-v4.19-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (80 commits) gpio: it87: Add support for IT8613 gpio: it87: add support for IT8718F Super I/O. gpiolib: Avoid calling chip->request() for unused gpios gpio: tegra: Include the right header gpio: mmio: Fix up inverted direction registers gpio: xilinx: Use the right include gpio: timberdale: Include the right header gpio: tb10x: Use the right include gpiolib: Fix of_node inconsistency gpio: vr41xx: Bail out on gpiochip_lock_as_irq() error gpio: uniphier: Bail out on gpiochip_lock_as_irq() error gpio: xgene-sb: Don't shadow error code of gpiochip_lock_as_irq() gpio: em: Don't shadow error code of gpiochip_lock_as_irq() gpio: dwapb: Don't shadow error code of gpiochip_lock_as_irq() gpio: bcm-kona: Don't shadow error code of gpiochip_lock_as_irq() gpiolib: Don't shadow error code of gpiochip_lock_as_irq() gpio: syscon: rockchip: add GRF GPIO support for rk3328 gpio: omap: Add get/set_multiple() callbacks gpio: pxa: remove set but not used variable 'gpio_offset' gpio-it87: add support for IT8786E Super I/O ...
Diffstat (limited to 'drivers/gpio/gpiolib.c')
-rw-r--r--drivers/gpio/gpiolib.c82
1 files changed, 57 insertions, 25 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index e11a3bb03820..e8f8a1999393 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -431,7 +431,7 @@ static long linehandle_ioctl(struct file *filep, unsigned int cmd,
431 int i; 431 int i;
432 432
433 if (cmd == GPIOHANDLE_GET_LINE_VALUES_IOCTL) { 433 if (cmd == GPIOHANDLE_GET_LINE_VALUES_IOCTL) {
434 /* TODO: check if descriptors are really input */ 434 /* NOTE: It's ok to read values of output lines. */
435 int ret = gpiod_get_array_value_complex(false, 435 int ret = gpiod_get_array_value_complex(false,
436 true, 436 true,
437 lh->numdescs, 437 lh->numdescs,
@@ -449,7 +449,13 @@ static long linehandle_ioctl(struct file *filep, unsigned int cmd,
449 449
450 return 0; 450 return 0;
451 } else if (cmd == GPIOHANDLE_SET_LINE_VALUES_IOCTL) { 451 } else if (cmd == GPIOHANDLE_SET_LINE_VALUES_IOCTL) {
452 /* TODO: check if descriptors are really output */ 452 /*
453 * All line descriptors were created at once with the same
454 * flags so just check if the first one is really output.
455 */
456 if (!test_bit(FLAG_IS_OUT, &lh->descs[0]->flags))
457 return -EPERM;
458
453 if (copy_from_user(&ghd, ip, sizeof(ghd))) 459 if (copy_from_user(&ghd, ip, sizeof(ghd)))
454 return -EFAULT; 460 return -EFAULT;
455 461
@@ -1256,6 +1262,8 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data,
1256 /* If the gpiochip has an assigned OF node this takes precedence */ 1262 /* If the gpiochip has an assigned OF node this takes precedence */
1257 if (chip->of_node) 1263 if (chip->of_node)
1258 gdev->dev.of_node = chip->of_node; 1264 gdev->dev.of_node = chip->of_node;
1265 else
1266 chip->of_node = gdev->dev.of_node;
1259#endif 1267#endif
1260 1268
1261 gdev->id = ida_simple_get(&gpio_ida, 0, 0, GFP_KERNEL); 1269 gdev->id = ida_simple_get(&gpio_ida, 0, 0, GFP_KERNEL);
@@ -1408,9 +1416,9 @@ err_free_descs:
1408err_free_gdev: 1416err_free_gdev:
1409 ida_simple_remove(&gpio_ida, gdev->id); 1417 ida_simple_remove(&gpio_ida, gdev->id);
1410 /* failures here can mean systems won't boot... */ 1418 /* failures here can mean systems won't boot... */
1411 pr_err("%s: GPIOs %d..%d (%s) failed to register\n", __func__, 1419 pr_err("%s: GPIOs %d..%d (%s) failed to register, %d\n", __func__,
1412 gdev->base, gdev->base + gdev->ngpio - 1, 1420 gdev->base, gdev->base + gdev->ngpio - 1,
1413 chip->label ? : "generic"); 1421 chip->label ? : "generic", status);
1414 kfree(gdev); 1422 kfree(gdev);
1415 return status; 1423 return status;
1416} 1424}
@@ -1664,8 +1672,7 @@ static void gpiochip_set_cascaded_irqchip(struct gpio_chip *gpiochip,
1664 if (parent_handler) { 1672 if (parent_handler) {
1665 if (gpiochip->can_sleep) { 1673 if (gpiochip->can_sleep) {
1666 chip_err(gpiochip, 1674 chip_err(gpiochip,
1667 "you cannot have chained interrupts on a " 1675 "you cannot have chained interrupts on a chip that may sleep\n");
1668 "chip that may sleep\n");
1669 return; 1676 return;
1670 } 1677 }
1671 /* 1678 /*
@@ -1800,16 +1807,18 @@ static const struct irq_domain_ops gpiochip_domain_ops = {
1800static int gpiochip_irq_reqres(struct irq_data *d) 1807static int gpiochip_irq_reqres(struct irq_data *d)
1801{ 1808{
1802 struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 1809 struct gpio_chip *chip = irq_data_get_irq_chip_data(d);
1810 int ret;
1803 1811
1804 if (!try_module_get(chip->gpiodev->owner)) 1812 if (!try_module_get(chip->gpiodev->owner))
1805 return -ENODEV; 1813 return -ENODEV;
1806 1814
1807 if (gpiochip_lock_as_irq(chip, d->hwirq)) { 1815 ret = gpiochip_lock_as_irq(chip, d->hwirq);
1816 if (ret) {
1808 chip_err(chip, 1817 chip_err(chip,
1809 "unable to lock HW IRQ %lu for IRQ\n", 1818 "unable to lock HW IRQ %lu for IRQ\n",
1810 d->hwirq); 1819 d->hwirq);
1811 module_put(chip->gpiodev->owner); 1820 module_put(chip->gpiodev->owner);
1812 return -EINVAL; 1821 return ret;
1813 } 1822 }
1814 return 0; 1823 return 0;
1815} 1824}
@@ -1850,8 +1859,7 @@ static int gpiochip_add_irqchip(struct gpio_chip *gpiochip,
1850 return 0; 1859 return 0;
1851 1860
1852 if (gpiochip->irq.parent_handler && gpiochip->can_sleep) { 1861 if (gpiochip->irq.parent_handler && gpiochip->can_sleep) {
1853 chip_err(gpiochip, "you cannot have chained interrupts on a " 1862 chip_err(gpiochip, "you cannot have chained interrupts on a chip that may sleep\n");
1854 "chip that may sleep\n");
1855 return -EINVAL; 1863 return -EINVAL;
1856 } 1864 }
1857 1865
@@ -2259,6 +2267,7 @@ static int gpiod_request_commit(struct gpio_desc *desc, const char *label)
2259 struct gpio_chip *chip = desc->gdev->chip; 2267 struct gpio_chip *chip = desc->gdev->chip;
2260 int status; 2268 int status;
2261 unsigned long flags; 2269 unsigned long flags;
2270 unsigned offset;
2262 2271
2263 spin_lock_irqsave(&gpio_lock, flags); 2272 spin_lock_irqsave(&gpio_lock, flags);
2264 2273
@@ -2277,7 +2286,11 @@ static int gpiod_request_commit(struct gpio_desc *desc, const char *label)
2277 if (chip->request) { 2286 if (chip->request) {
2278 /* chip->request may sleep */ 2287 /* chip->request may sleep */
2279 spin_unlock_irqrestore(&gpio_lock, flags); 2288 spin_unlock_irqrestore(&gpio_lock, flags);
2280 status = chip->request(chip, gpio_chip_hwgpio(desc)); 2289 offset = gpio_chip_hwgpio(desc);
2290 if (gpiochip_line_is_valid(chip, offset))
2291 status = chip->request(chip, offset);
2292 else
2293 status = -EINVAL;
2281 spin_lock_irqsave(&gpio_lock, flags); 2294 spin_lock_irqsave(&gpio_lock, flags);
2282 2295
2283 if (status < 0) { 2296 if (status < 0) {
@@ -3194,6 +3207,19 @@ int gpiod_cansleep(const struct gpio_desc *desc)
3194EXPORT_SYMBOL_GPL(gpiod_cansleep); 3207EXPORT_SYMBOL_GPL(gpiod_cansleep);
3195 3208
3196/** 3209/**
3210 * gpiod_set_consumer_name() - set the consumer name for the descriptor
3211 * @desc: gpio to set the consumer name on
3212 * @name: the new consumer name
3213 */
3214void gpiod_set_consumer_name(struct gpio_desc *desc, const char *name)
3215{
3216 VALIDATE_DESC_VOID(desc);
3217 /* Just overwrite whatever the previous name was */
3218 desc->label = name;
3219}
3220EXPORT_SYMBOL_GPL(gpiod_set_consumer_name);
3221
3222/**
3197 * gpiod_to_irq() - return the IRQ corresponding to a GPIO 3223 * gpiod_to_irq() - return the IRQ corresponding to a GPIO
3198 * @desc: gpio whose IRQ will be returned (already requested) 3224 * @desc: gpio whose IRQ will be returned (already requested)
3199 * 3225 *
@@ -3249,18 +3275,19 @@ int gpiochip_lock_as_irq(struct gpio_chip *chip, unsigned int offset)
3249 * behind our back 3275 * behind our back
3250 */ 3276 */
3251 if (!chip->can_sleep && chip->get_direction) { 3277 if (!chip->can_sleep && chip->get_direction) {
3252 int dir = chip->get_direction(chip, offset); 3278 int dir = gpiod_get_direction(desc);
3253 3279
3254 if (dir) 3280 if (dir < 0) {
3255 clear_bit(FLAG_IS_OUT, &desc->flags); 3281 chip_err(chip, "%s: cannot get GPIO direction\n",
3256 else 3282 __func__);
3257 set_bit(FLAG_IS_OUT, &desc->flags); 3283 return dir;
3284 }
3258 } 3285 }
3259 3286
3260 if (test_bit(FLAG_IS_OUT, &desc->flags)) { 3287 if (test_bit(FLAG_IS_OUT, &desc->flags)) {
3261 chip_err(chip, 3288 chip_err(chip,
3262 "%s: tried to flag a GPIO set as output for IRQ\n", 3289 "%s: tried to flag a GPIO set as output for IRQ\n",
3263 __func__); 3290 __func__);
3264 return -EIO; 3291 return -EIO;
3265 } 3292 }
3266 3293
@@ -3639,9 +3666,16 @@ static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id,
3639 chip = find_chip_by_name(p->chip_label); 3666 chip = find_chip_by_name(p->chip_label);
3640 3667
3641 if (!chip) { 3668 if (!chip) {
3642 dev_err(dev, "cannot find GPIO chip %s\n", 3669 /*
3643 p->chip_label); 3670 * As the lookup table indicates a chip with
3644 return ERR_PTR(-ENODEV); 3671 * p->chip_label should exist, assume it may
3672 * still appear later and let the interested
3673 * consumer be probed again or let the Deferred
3674 * Probe infrastructure handle the error.
3675 */
3676 dev_warn(dev, "cannot find GPIO chip %s, deferring\n",
3677 p->chip_label);
3678 return ERR_PTR(-EPROBE_DEFER);
3645 } 3679 }
3646 3680
3647 if (chip->ngpio <= p->chip_hwnum) { 3681 if (chip->ngpio <= p->chip_hwnum) {
@@ -4215,7 +4249,7 @@ static int __init gpiolib_dev_init(void)
4215 int ret; 4249 int ret;
4216 4250
4217 /* Register GPIO sysfs bus */ 4251 /* Register GPIO sysfs bus */
4218 ret = bus_register(&gpio_bus_type); 4252 ret = bus_register(&gpio_bus_type);
4219 if (ret < 0) { 4253 if (ret < 0) {
4220 pr_err("gpiolib: could not register GPIO bus type\n"); 4254 pr_err("gpiolib: could not register GPIO bus type\n");
4221 return ret; 4255 return ret;
@@ -4259,9 +4293,7 @@ static void gpiolib_dbg_show(struct seq_file *s, struct gpio_device *gdev)
4259 seq_printf(s, " gpio-%-3d (%-20.20s|%-20.20s) %s %s %s", 4293 seq_printf(s, " gpio-%-3d (%-20.20s|%-20.20s) %s %s %s",
4260 gpio, gdesc->name ? gdesc->name : "", gdesc->label, 4294 gpio, gdesc->name ? gdesc->name : "", gdesc->label,
4261 is_out ? "out" : "in ", 4295 is_out ? "out" : "in ",
4262 chip->get 4296 chip->get ? (chip->get(chip, i) ? "hi" : "lo") : "? ",
4263 ? (chip->get(chip, i) ? "hi" : "lo")
4264 : "? ",
4265 is_irq ? "IRQ" : " "); 4297 is_irq ? "IRQ" : " ");
4266 seq_printf(s, "\n"); 4298 seq_printf(s, "\n");
4267 } 4299 }