Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'gpio-v4.6-3' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio

Pull GPIO fixes from Linus Walleij:
"Here is a set of four GPIO fixes. The two fixes to the core are
serious as they are regressing minor architectures.

Core fixes:

- Defer GPIO device setup until after gpiolib is initialized.

It turns out that a few very tightly integrated GPIO platform
drivers initialize so early (befor core_initcall()) so that the
gpiolib isn't even initialized itself. That limits what the
library can do, and we cannot reference uninitialized fields until
later.

Defer some of the initialization until right after the gpiolib is
initialized in these (rare) cases.

- As a consequence: do not use devm_* resources when allocating the
states in the initial set-up of the gpiochip.

Driver fixes:

- In ACPI retrieveal: ignore GpioInt when looking for output GPIOs.

- Fix legacy builds on the PXA without a backing pin controller.

- Use correct datatype on pca953x register writes"

* tag 'gpio-v4.6-3' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio:
gpio: pca953x: Use correct u16 value for register word write
gpiolib: Defer gpio device setup until after gpiolib initialization
gpiolib: Do not use devm functions when registering gpio chip
gpio: pxa: fix legacy non pinctrl aware builds
gpio / ACPI: ignore GpioInt() GPIOs when requesting GPIO_OUT_*

+95 -45
+2 -1
drivers/gpio/gpio-pca953x.c
··· 18 18 #include <linux/i2c.h> 19 19 #include <linux/platform_data/pca953x.h> 20 20 #include <linux/slab.h> 21 + #include <asm/unaligned.h> 21 22 #include <linux/of_platform.h> 22 23 #include <linux/acpi.h> 23 24 ··· 160 159 switch (chip->chip_type) { 161 160 case PCA953X_TYPE: 162 161 ret = i2c_smbus_write_word_data(chip->client, 163 - reg << 1, (u16) *val); 162 + reg << 1, cpu_to_le16(get_unaligned((u16 *)val))); 164 163 break; 165 164 case PCA957X_TYPE: 166 165 ret = i2c_smbus_write_byte_data(chip->client, reg << 1,
+2 -2
drivers/gpio/gpio-pxa.c
··· 283 283 writel_relaxed(mask, base + (value ? GPSR_OFFSET : GPCR_OFFSET)); 284 284 285 285 ret = pinctrl_gpio_direction_output(chip->base + offset); 286 - if (!ret) 287 - return 0; 286 + if (ret) 287 + return ret; 288 288 289 289 spin_lock_irqsave(&gpio_lock, flags); 290 290
+91 -42
drivers/gpio/gpiolib.c
··· 68 68 static void gpiochip_free_hogs(struct gpio_chip *chip); 69 69 static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip); 70 70 71 + static bool gpiolib_initialized; 71 72 72 73 static inline void desc_set_label(struct gpio_desc *d, const char *label) 73 74 { ··· 441 440 cdev_del(&gdev->chrdev); 442 441 list_del(&gdev->list); 443 442 ida_simple_remove(&gpio_ida, gdev->id); 443 + kfree(gdev->label); 444 + kfree(gdev->descs); 444 445 kfree(gdev); 446 + } 447 + 448 + static int gpiochip_setup_dev(struct gpio_device *gdev) 449 + { 450 + int status; 451 + 452 + cdev_init(&gdev->chrdev, &gpio_fileops); 453 + gdev->chrdev.owner = THIS_MODULE; 454 + gdev->chrdev.kobj.parent = &gdev->dev.kobj; 455 + gdev->dev.devt = MKDEV(MAJOR(gpio_devt), gdev->id); 456 + status = cdev_add(&gdev->chrdev, gdev->dev.devt, 1); 457 + if (status < 0) 458 + chip_warn(gdev->chip, "failed to add char device %d:%d\n", 459 + MAJOR(gpio_devt), gdev->id); 460 + else 461 + chip_dbg(gdev->chip, "added GPIO chardev (%d:%d)\n", 462 + MAJOR(gpio_devt), gdev->id); 463 + status = device_add(&gdev->dev); 464 + if (status) 465 + goto err_remove_chardev; 466 + 467 + status = gpiochip_sysfs_register(gdev); 468 + if (status) 469 + goto err_remove_device; 470 + 471 + /* From this point, the .release() function cleans up gpio_device */ 472 + gdev->dev.release = gpiodevice_release; 473 + get_device(&gdev->dev); 474 + pr_debug("%s: registered GPIOs %d to %d on device: %s (%s)\n", 475 + __func__, gdev->base, gdev->base + gdev->ngpio - 1, 476 + dev_name(&gdev->dev), gdev->chip->label ? : "generic"); 477 + 478 + return 0; 479 + 480 + err_remove_device: 481 + device_del(&gdev->dev); 482 + err_remove_chardev: 483 + cdev_del(&gdev->chrdev); 484 + return status; 485 + } 486 + 487 + static void gpiochip_setup_devs(void) 488 + { 489 + struct gpio_device *gdev; 490 + int err; 491 + 492 + list_for_each_entry(gdev, &gpio_devices, list) { 493 + err = gpiochip_setup_dev(gdev); 494 + if (err) 495 + pr_err("%s: Failed to initialize gpio device (%d)\n", 496 + dev_name(&gdev->dev), err); 497 + } 445 498 } 446 499 447 500 /** ··· 511 456 * can be freely used, the chip->parent device must be registered before 512 457 * the gpio framework's arch_initcall(). Otherwise sysfs initialization 513 458 * for GPIOs will fail rudely. 459 + * 460 + * gpiochip_add_data() must only be called after gpiolib initialization, 461 + * ie after core_initcall(). 514 462 * 515 463 * If chip->base is negative, this requests dynamic assignment of 516 464 * a range of valid GPIOs. ··· 562 504 else 563 505 gdev->owner = THIS_MODULE; 564 506 565 - gdev->descs = devm_kcalloc(&gdev->dev, chip->ngpio, 566 - sizeof(gdev->descs[0]), GFP_KERNEL); 507 + gdev->descs = kcalloc(chip->ngpio, sizeof(gdev->descs[0]), GFP_KERNEL); 567 508 if (!gdev->descs) { 568 509 status = -ENOMEM; 569 510 goto err_free_gdev; ··· 571 514 if (chip->ngpio == 0) { 572 515 chip_err(chip, "tried to insert a GPIO chip with zero lines\n"); 573 516 status = -EINVAL; 574 - goto err_free_gdev; 517 + goto err_free_descs; 575 518 } 576 519 577 520 if (chip->label) 578 - gdev->label = devm_kstrdup(&gdev->dev, chip->label, GFP_KERNEL); 521 + gdev->label = kstrdup(chip->label, GFP_KERNEL); 579 522 else 580 - gdev->label = devm_kstrdup(&gdev->dev, "unknown", GFP_KERNEL); 523 + gdev->label = kstrdup("unknown", GFP_KERNEL); 581 524 if (!gdev->label) { 582 525 status = -ENOMEM; 583 - goto err_free_gdev; 526 + goto err_free_descs; 584 527 } 585 528 586 529 gdev->ngpio = chip->ngpio; ··· 600 543 if (base < 0) { 601 544 status = base; 602 545 spin_unlock_irqrestore(&gpio_lock, flags); 603 - goto err_free_gdev; 546 + goto err_free_label; 604 547 } 605 548 /* 606 549 * TODO: it should not be necessary to reflect the assigned ··· 615 558 status = gpiodev_add_to_list(gdev); 616 559 if (status) { 617 560 spin_unlock_irqrestore(&gpio_lock, flags); 618 - goto err_free_gdev; 561 + goto err_free_label; 619 562 } 620 563 621 564 for (i = 0; i < chip->ngpio; i++) { ··· 653 596 * we get a device node entry in sysfs under 654 597 * /sys/bus/gpio/devices/gpiochipN/dev that can be used for 655 598 * coldplug of device nodes and other udev business. 599 + * We can do this only if gpiolib has been initialized. 600 + * Otherwise, defer until later. 656 601 */ 657 - cdev_init(&gdev->chrdev, &gpio_fileops); 658 - gdev->chrdev.owner = THIS_MODULE; 659 - gdev->chrdev.kobj.parent = &gdev->dev.kobj; 660 - gdev->dev.devt = MKDEV(MAJOR(gpio_devt), gdev->id); 661 - status = cdev_add(&gdev->chrdev, gdev->dev.devt, 1); 662 - if (status < 0) 663 - chip_warn(chip, "failed to add char device %d:%d\n", 664 - MAJOR(gpio_devt), gdev->id); 665 - else 666 - chip_dbg(chip, "added GPIO chardev (%d:%d)\n", 667 - MAJOR(gpio_devt), gdev->id); 668 - status = device_add(&gdev->dev); 669 - if (status) 670 - goto err_remove_chardev; 671 - 672 - status = gpiochip_sysfs_register(gdev); 673 - if (status) 674 - goto err_remove_device; 675 - 676 - /* From this point, the .release() function cleans up gpio_device */ 677 - gdev->dev.release = gpiodevice_release; 678 - get_device(&gdev->dev); 679 - pr_debug("%s: registered GPIOs %d to %d on device: %s (%s)\n", 680 - __func__, gdev->base, gdev->base + gdev->ngpio - 1, 681 - dev_name(&gdev->dev), chip->label ? : "generic"); 682 - 602 + if (gpiolib_initialized) { 603 + status = gpiochip_setup_dev(gdev); 604 + if (status) 605 + goto err_remove_chip; 606 + } 683 607 return 0; 684 608 685 - err_remove_device: 686 - device_del(&gdev->dev); 687 - err_remove_chardev: 688 - cdev_del(&gdev->chrdev); 689 609 err_remove_chip: 690 610 acpi_gpiochip_remove(chip); 691 611 gpiochip_free_hogs(chip); ··· 671 637 spin_lock_irqsave(&gpio_lock, flags); 672 638 list_del(&gdev->list); 673 639 spin_unlock_irqrestore(&gpio_lock, flags); 640 + err_free_label: 641 + kfree(gdev->label); 642 + err_free_descs: 643 + kfree(gdev->descs); 674 644 err_free_gdev: 675 645 ida_simple_remove(&gpio_ida, gdev->id); 676 646 /* failures here can mean systems won't boot... */ ··· 2269 2231 return desc; 2270 2232 } 2271 2233 2272 - static struct gpio_desc *acpi_find_gpio(struct device *dev, const char *con_id, 2234 + static struct gpio_desc *acpi_find_gpio(struct device *dev, 2235 + const char *con_id, 2273 2236 unsigned int idx, 2274 - enum gpio_lookup_flags *flags) 2237 + enum gpiod_flags flags, 2238 + enum gpio_lookup_flags *lookupflags) 2275 2239 { 2276 2240 struct acpi_device *adev = ACPI_COMPANION(dev); 2277 2241 struct acpi_gpio_info info; ··· 2304 2264 desc = acpi_get_gpiod_by_index(adev, NULL, idx, &info); 2305 2265 if (IS_ERR(desc)) 2306 2266 return desc; 2267 + 2268 + if ((flags == GPIOD_OUT_LOW || flags == GPIOD_OUT_HIGH) && 2269 + info.gpioint) { 2270 + dev_dbg(dev, "refusing GpioInt() entry when doing GPIOD_OUT_* lookup\n"); 2271 + return ERR_PTR(-ENOENT); 2272 + } 2307 2273 } 2308 2274 2309 2275 if (info.polarity == GPIO_ACTIVE_LOW) 2310 - *flags |= GPIO_ACTIVE_LOW; 2276 + *lookupflags |= GPIO_ACTIVE_LOW; 2311 2277 2312 2278 return desc; 2313 2279 } ··· 2576 2530 desc = of_find_gpio(dev, con_id, idx, &lookupflags); 2577 2531 } else if (ACPI_COMPANION(dev)) { 2578 2532 dev_dbg(dev, "using ACPI for GPIO lookup\n"); 2579 - desc = acpi_find_gpio(dev, con_id, idx, &lookupflags); 2533 + desc = acpi_find_gpio(dev, con_id, idx, flags, &lookupflags); 2580 2534 } 2581 2535 } 2582 2536 ··· 2875 2829 if (ret < 0) { 2876 2830 pr_err("gpiolib: failed to allocate char dev region\n"); 2877 2831 bus_unregister(&gpio_bus_type); 2832 + } else { 2833 + gpiolib_initialized = true; 2834 + gpiochip_setup_devs(); 2878 2835 } 2879 2836 return ret; 2880 2837 }