.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
---|
1 | 2 | /* |
---|
2 | 3 | * ACPI helpers for GPIO API |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2012, Intel Corporation |
---|
5 | 6 | * Authors: Mathias Nyman <mathias.nyman@linux.intel.com> |
---|
6 | 7 | * Mika Westerberg <mika.westerberg@linux.intel.com> |
---|
7 | | - * |
---|
8 | | - * This program is free software; you can redistribute it and/or modify |
---|
9 | | - * it under the terms of the GNU General Public License version 2 as |
---|
10 | | - * published by the Free Software Foundation. |
---|
11 | 8 | */ |
---|
12 | 9 | |
---|
13 | 10 | #include <linux/dmi.h> |
---|
14 | 11 | #include <linux/errno.h> |
---|
15 | | -#include <linux/gpio.h> |
---|
16 | 12 | #include <linux/gpio/consumer.h> |
---|
17 | 13 | #include <linux/gpio/driver.h> |
---|
18 | 14 | #include <linux/gpio/machine.h> |
---|
.. | .. |
---|
23 | 19 | #include <linux/pinctrl/pinctrl.h> |
---|
24 | 20 | |
---|
25 | 21 | #include "gpiolib.h" |
---|
| 22 | +#include "gpiolib-acpi.h" |
---|
26 | 23 | |
---|
27 | 24 | static int run_edge_events_on_boot = -1; |
---|
28 | 25 | module_param(run_edge_events_on_boot, int, 0444); |
---|
.. | .. |
---|
45 | 42 | * |
---|
46 | 43 | * @node: list-entry of the events list of the struct acpi_gpio_chip |
---|
47 | 44 | * @handle: handle of ACPI method to execute when the IRQ triggers |
---|
48 | | - * @handler: irq_handler to pass to request_irq when requesting the IRQ |
---|
49 | | - * @pin: GPIO pin number on the gpio_chip |
---|
50 | | - * @irq: Linux IRQ number for the event, for request_ / free_irq |
---|
51 | | - * @irqflags: flags to pass to request_irq when requesting the IRQ |
---|
| 45 | + * @handler: handler function to pass to request_irq() when requesting the IRQ |
---|
| 46 | + * @pin: GPIO pin number on the struct gpio_chip |
---|
| 47 | + * @irq: Linux IRQ number for the event, for request_irq() / free_irq() |
---|
| 48 | + * @irqflags: flags to pass to request_irq() when requesting the IRQ |
---|
52 | 49 | * @irq_is_wake: If the ACPI flags indicate the IRQ is a wakeup source |
---|
53 | | - * @is_requested: True if request_irq has been done |
---|
54 | | - * @desc: gpio_desc for the GPIO pin for this event |
---|
| 50 | + * @irq_requested:True if request_irq() has been done |
---|
| 51 | + * @desc: struct gpio_desc for the GPIO pin for this event |
---|
55 | 52 | */ |
---|
56 | 53 | struct acpi_gpio_event { |
---|
57 | 54 | struct list_head node; |
---|
.. | .. |
---|
86 | 83 | }; |
---|
87 | 84 | |
---|
88 | 85 | /* |
---|
89 | | - * For gpiochips which call acpi_gpiochip_request_interrupts() before late_init |
---|
| 86 | + * For GPIO chips which call acpi_gpiochip_request_interrupts() before late_init |
---|
90 | 87 | * (so builtin drivers) we register the ACPI GpioInt IRQ handlers from a |
---|
91 | | - * late_initcall_sync handler, so that other builtin drivers can register their |
---|
92 | | - * OpRegions before the event handlers can run. This list contains gpiochips |
---|
| 88 | + * late_initcall_sync() handler, so that other builtin drivers can register their |
---|
| 89 | + * OpRegions before the event handlers can run. This list contains GPIO chips |
---|
93 | 90 | * for which the acpi_gpiochip_request_irqs() call has been deferred. |
---|
94 | 91 | */ |
---|
95 | 92 | static DEFINE_MUTEX(acpi_gpio_deferred_req_irqs_lock); |
---|
.. | .. |
---|
111 | 108 | * |
---|
112 | 109 | * Return: GPIO descriptor to use with Linux generic GPIO API, or ERR_PTR |
---|
113 | 110 | * error value. Specifically returns %-EPROBE_DEFER if the referenced GPIO |
---|
114 | | - * controller does not have gpiochip registered at the moment. This is to |
---|
| 111 | + * controller does not have GPIO chip registered at the moment. This is to |
---|
115 | 112 | * support probe deferral. |
---|
116 | 113 | */ |
---|
117 | 114 | static struct gpio_desc *acpi_get_gpiod(char *path, int pin) |
---|
.. | .. |
---|
259 | 256 | return true; |
---|
260 | 257 | } |
---|
261 | 258 | |
---|
| 259 | +/* Always returns AE_OK so that we keep looping over the resources */ |
---|
262 | 260 | static acpi_status acpi_gpiochip_alloc_event(struct acpi_resource *ares, |
---|
263 | 261 | void *context) |
---|
264 | 262 | { |
---|
.. | .. |
---|
278 | 276 | pin = agpio->pin_table[0]; |
---|
279 | 277 | |
---|
280 | 278 | if (pin <= 255) { |
---|
281 | | - char ev_name[5]; |
---|
282 | | - sprintf(ev_name, "_%c%02hhX", |
---|
| 279 | + char ev_name[8]; |
---|
| 280 | + sprintf(ev_name, "_%c%02X", |
---|
283 | 281 | agpio->triggering == ACPI_EDGE_SENSITIVE ? 'E' : 'L', |
---|
284 | 282 | pin); |
---|
285 | 283 | if (ACPI_SUCCESS(acpi_get_handle(handle, ev_name, &evt_handle))) |
---|
.. | .. |
---|
292 | 290 | if (!handler) |
---|
293 | 291 | return AE_OK; |
---|
294 | 292 | |
---|
295 | | - desc = gpiochip_request_own_desc(chip, pin, "ACPI:Event"); |
---|
| 293 | + desc = gpiochip_request_own_desc(chip, pin, "ACPI:Event", |
---|
| 294 | + GPIO_ACTIVE_HIGH, GPIOD_IN); |
---|
296 | 295 | if (IS_ERR(desc)) { |
---|
297 | | - dev_err(chip->parent, "Failed to request GPIO\n"); |
---|
298 | | - return AE_ERROR; |
---|
| 296 | + dev_err(chip->parent, |
---|
| 297 | + "Failed to request GPIO for pin 0x%04X, err %ld\n", |
---|
| 298 | + pin, PTR_ERR(desc)); |
---|
| 299 | + return AE_OK; |
---|
299 | 300 | } |
---|
300 | | - |
---|
301 | | - gpiod_direction_input(desc); |
---|
302 | 301 | |
---|
303 | 302 | ret = gpiochip_lock_as_irq(chip, pin); |
---|
304 | 303 | if (ret) { |
---|
305 | | - dev_err(chip->parent, "Failed to lock GPIO as interrupt\n"); |
---|
| 304 | + dev_err(chip->parent, |
---|
| 305 | + "Failed to lock GPIO pin 0x%04X as interrupt, err %d\n", |
---|
| 306 | + pin, ret); |
---|
306 | 307 | goto fail_free_desc; |
---|
307 | 308 | } |
---|
308 | 309 | |
---|
309 | 310 | irq = gpiod_to_irq(desc); |
---|
310 | 311 | if (irq < 0) { |
---|
311 | | - dev_err(chip->parent, "Failed to translate GPIO to IRQ\n"); |
---|
| 312 | + dev_err(chip->parent, |
---|
| 313 | + "Failed to translate GPIO pin 0x%04X to IRQ, err %d\n", |
---|
| 314 | + pin, irq); |
---|
312 | 315 | goto fail_unlock_irq; |
---|
313 | 316 | } |
---|
314 | 317 | |
---|
.. | .. |
---|
353 | 356 | fail_free_desc: |
---|
354 | 357 | gpiochip_free_own_desc(desc); |
---|
355 | 358 | |
---|
356 | | - return AE_ERROR; |
---|
| 359 | + return AE_OK; |
---|
357 | 360 | } |
---|
358 | 361 | |
---|
359 | 362 | /** |
---|
.. | .. |
---|
362 | 365 | * |
---|
363 | 366 | * ACPI5 platforms can use GPIO signaled ACPI events. These GPIO interrupts are |
---|
364 | 367 | * handled by ACPI event methods which need to be called from the GPIO |
---|
365 | | - * chip's interrupt handler. acpi_gpiochip_request_interrupts finds out which |
---|
366 | | - * gpio pins have acpi event methods and assigns interrupt handlers that calls |
---|
367 | | - * the acpi event methods for those pins. |
---|
| 368 | + * chip's interrupt handler. acpi_gpiochip_request_interrupts() finds out which |
---|
| 369 | + * GPIO pins have ACPI event methods and assigns interrupt handlers that calls |
---|
| 370 | + * the ACPI event methods for those pins. |
---|
368 | 371 | */ |
---|
369 | 372 | void acpi_gpiochip_request_interrupts(struct gpio_chip *chip) |
---|
370 | 373 | { |
---|
.. | .. |
---|
432 | 435 | mutex_unlock(&acpi_gpio_deferred_req_irqs_lock); |
---|
433 | 436 | |
---|
434 | 437 | list_for_each_entry_safe_reverse(event, ep, &acpi_gpio->events, node) { |
---|
435 | | - struct gpio_desc *desc; |
---|
436 | | - |
---|
437 | 438 | if (event->irq_requested) { |
---|
438 | 439 | if (event->irq_is_wake) |
---|
439 | 440 | disable_irq_wake(event->irq); |
---|
.. | .. |
---|
441 | 442 | free_irq(event->irq, event); |
---|
442 | 443 | } |
---|
443 | 444 | |
---|
444 | | - desc = event->desc; |
---|
445 | | - if (WARN_ON(IS_ERR(desc))) |
---|
446 | | - continue; |
---|
447 | 445 | gpiochip_unlock_as_irq(chip, event->pin); |
---|
448 | | - gpiochip_free_own_desc(desc); |
---|
| 446 | + gpiochip_free_own_desc(event->desc); |
---|
449 | 447 | list_del(&event->node); |
---|
450 | 448 | kfree(event); |
---|
451 | 449 | } |
---|
.. | .. |
---|
462 | 460 | return -EINVAL; |
---|
463 | 461 | } |
---|
464 | 462 | EXPORT_SYMBOL_GPL(acpi_dev_add_driver_gpios); |
---|
| 463 | + |
---|
| 464 | +void acpi_dev_remove_driver_gpios(struct acpi_device *adev) |
---|
| 465 | +{ |
---|
| 466 | + if (adev) |
---|
| 467 | + adev->driver_gpios = NULL; |
---|
| 468 | +} |
---|
| 469 | +EXPORT_SYMBOL_GPL(acpi_dev_remove_driver_gpios); |
---|
465 | 470 | |
---|
466 | 471 | static void devm_acpi_dev_release_driver_gpios(struct device *dev, void *res) |
---|
467 | 472 | { |
---|
.. | .. |
---|
524 | 529 | static enum gpiod_flags |
---|
525 | 530 | acpi_gpio_to_gpiod_flags(const struct acpi_resource_gpio *agpio) |
---|
526 | 531 | { |
---|
527 | | - bool pull_up = agpio->pin_config == ACPI_PIN_CONFIG_PULLUP; |
---|
528 | | - |
---|
529 | 532 | switch (agpio->io_restriction) { |
---|
530 | 533 | case ACPI_IO_RESTRICT_INPUT: |
---|
531 | 534 | return GPIOD_IN; |
---|
.. | .. |
---|
534 | 537 | * ACPI GPIO resources don't contain an initial value for the |
---|
535 | 538 | * GPIO. Therefore we deduce that value from the pull field |
---|
536 | 539 | * instead. If the pin is pulled up we assume default to be |
---|
537 | | - * high, otherwise low. |
---|
| 540 | + * high, if it is pulled down we assume default to be low, |
---|
| 541 | + * otherwise we leave pin untouched. |
---|
538 | 542 | */ |
---|
539 | | - return pull_up ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW; |
---|
| 543 | + switch (agpio->pin_config) { |
---|
| 544 | + case ACPI_PIN_CONFIG_PULLUP: |
---|
| 545 | + return GPIOD_OUT_HIGH; |
---|
| 546 | + case ACPI_PIN_CONFIG_PULLDOWN: |
---|
| 547 | + return GPIOD_OUT_LOW; |
---|
| 548 | + default: |
---|
| 549 | + break; |
---|
| 550 | + } |
---|
540 | 551 | default: |
---|
541 | | - /* |
---|
542 | | - * Assume that the BIOS has configured the direction and pull |
---|
543 | | - * accordingly. |
---|
544 | | - */ |
---|
545 | | - return GPIOD_ASIS; |
---|
| 552 | + break; |
---|
546 | 553 | } |
---|
| 554 | + |
---|
| 555 | + /* |
---|
| 556 | + * Assume that the BIOS has configured the direction and pull |
---|
| 557 | + * accordingly. |
---|
| 558 | + */ |
---|
| 559 | + return GPIOD_ASIS; |
---|
547 | 560 | } |
---|
548 | 561 | |
---|
549 | 562 | static int |
---|
550 | 563 | __acpi_gpio_update_gpiod_flags(enum gpiod_flags *flags, enum gpiod_flags update) |
---|
551 | 564 | { |
---|
| 565 | + const enum gpiod_flags mask = |
---|
| 566 | + GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT | |
---|
| 567 | + GPIOD_FLAGS_BIT_DIR_VAL; |
---|
552 | 568 | int ret = 0; |
---|
553 | 569 | |
---|
554 | 570 | /* |
---|
.. | .. |
---|
569 | 585 | if (((*flags & GPIOD_FLAGS_BIT_DIR_SET) && (diff & GPIOD_FLAGS_BIT_DIR_OUT)) || |
---|
570 | 586 | ((*flags & GPIOD_FLAGS_BIT_DIR_OUT) && (diff & GPIOD_FLAGS_BIT_DIR_VAL))) |
---|
571 | 587 | ret = -EINVAL; |
---|
572 | | - *flags = update; |
---|
| 588 | + *flags = (*flags & ~mask) | (update & mask); |
---|
573 | 589 | } |
---|
574 | 590 | return ret; |
---|
575 | 591 | } |
---|
.. | .. |
---|
594 | 610 | return ret; |
---|
595 | 611 | } |
---|
596 | 612 | |
---|
| 613 | +int acpi_gpio_update_gpiod_lookup_flags(unsigned long *lookupflags, |
---|
| 614 | + struct acpi_gpio_info *info) |
---|
| 615 | +{ |
---|
| 616 | + switch (info->pin_config) { |
---|
| 617 | + case ACPI_PIN_CONFIG_PULLUP: |
---|
| 618 | + *lookupflags |= GPIO_PULL_UP; |
---|
| 619 | + break; |
---|
| 620 | + case ACPI_PIN_CONFIG_PULLDOWN: |
---|
| 621 | + *lookupflags |= GPIO_PULL_DOWN; |
---|
| 622 | + break; |
---|
| 623 | + default: |
---|
| 624 | + break; |
---|
| 625 | + } |
---|
| 626 | + |
---|
| 627 | + if (info->polarity == GPIO_ACTIVE_LOW) |
---|
| 628 | + *lookupflags |= GPIO_ACTIVE_LOW; |
---|
| 629 | + |
---|
| 630 | + return 0; |
---|
| 631 | +} |
---|
| 632 | + |
---|
597 | 633 | struct acpi_gpio_lookup { |
---|
598 | 634 | struct acpi_gpio_info info; |
---|
599 | 635 | int index; |
---|
.. | .. |
---|
610 | 646 | if (ares->type != ACPI_RESOURCE_TYPE_GPIO) |
---|
611 | 647 | return 1; |
---|
612 | 648 | |
---|
613 | | - if (lookup->n++ == lookup->index && !lookup->desc) { |
---|
| 649 | + if (!lookup->desc) { |
---|
614 | 650 | const struct acpi_resource_gpio *agpio = &ares->data.gpio; |
---|
615 | | - int pin_index = lookup->pin_index; |
---|
| 651 | + bool gpioint = agpio->connection_type == ACPI_RESOURCE_GPIO_TYPE_INT; |
---|
| 652 | + struct gpio_desc *desc; |
---|
| 653 | + int pin_index; |
---|
616 | 654 | |
---|
| 655 | + if (lookup->info.quirks & ACPI_GPIO_QUIRK_ONLY_GPIOIO && gpioint) |
---|
| 656 | + lookup->index++; |
---|
| 657 | + |
---|
| 658 | + if (lookup->n++ != lookup->index) |
---|
| 659 | + return 1; |
---|
| 660 | + |
---|
| 661 | + pin_index = lookup->pin_index; |
---|
617 | 662 | if (pin_index >= agpio->pin_table_length) |
---|
618 | 663 | return 1; |
---|
619 | 664 | |
---|
620 | | - lookup->desc = acpi_get_gpiod(agpio->resource_source.string_ptr, |
---|
| 665 | + if (lookup->info.quirks & ACPI_GPIO_QUIRK_ABSOLUTE_NUMBER) |
---|
| 666 | + desc = gpio_to_desc(agpio->pin_table[pin_index]); |
---|
| 667 | + else |
---|
| 668 | + desc = acpi_get_gpiod(agpio->resource_source.string_ptr, |
---|
621 | 669 | agpio->pin_table[pin_index]); |
---|
622 | | - lookup->info.gpioint = |
---|
623 | | - agpio->connection_type == ACPI_RESOURCE_GPIO_TYPE_INT; |
---|
| 670 | + lookup->desc = desc; |
---|
| 671 | + lookup->info.pin_config = agpio->pin_config; |
---|
| 672 | + lookup->info.gpioint = gpioint; |
---|
624 | 673 | |
---|
625 | 674 | /* |
---|
626 | 675 | * Polarity and triggering are only specified for GpioInt |
---|
.. | .. |
---|
723 | 772 | * that case @index is used to select the GPIO entry in the property value |
---|
724 | 773 | * (in case of multiple). |
---|
725 | 774 | * |
---|
726 | | - * If the GPIO cannot be translated or there is an error an ERR_PTR is |
---|
| 775 | + * If the GPIO cannot be translated or there is an error, an ERR_PTR is |
---|
727 | 776 | * returned. |
---|
728 | 777 | * |
---|
729 | 778 | * Note: if the GPIO resource has multiple entries in the pin list, this |
---|
.. | .. |
---|
762 | 811 | return ret ? ERR_PTR(ret) : lookup.desc; |
---|
763 | 812 | } |
---|
764 | 813 | |
---|
| 814 | +static bool acpi_can_fallback_to_crs(struct acpi_device *adev, |
---|
| 815 | + const char *con_id) |
---|
| 816 | +{ |
---|
| 817 | + /* Never allow fallback if the device has properties */ |
---|
| 818 | + if (acpi_dev_has_props(adev) || adev->driver_gpios) |
---|
| 819 | + return false; |
---|
| 820 | + |
---|
| 821 | + return con_id == NULL; |
---|
| 822 | +} |
---|
| 823 | + |
---|
765 | 824 | struct gpio_desc *acpi_find_gpio(struct device *dev, |
---|
766 | 825 | const char *con_id, |
---|
767 | 826 | unsigned int idx, |
---|
768 | 827 | enum gpiod_flags *dflags, |
---|
769 | | - enum gpio_lookup_flags *lookupflags) |
---|
| 828 | + unsigned long *lookupflags) |
---|
770 | 829 | { |
---|
771 | 830 | struct acpi_device *adev = ACPI_COMPANION(dev); |
---|
772 | 831 | struct acpi_gpio_info info; |
---|
.. | .. |
---|
807 | 866 | return ERR_PTR(-ENOENT); |
---|
808 | 867 | } |
---|
809 | 868 | |
---|
810 | | - if (info.polarity == GPIO_ACTIVE_LOW) |
---|
811 | | - *lookupflags |= GPIO_ACTIVE_LOW; |
---|
812 | | - |
---|
813 | 869 | acpi_gpio_update_gpiod_flags(dflags, &info); |
---|
| 870 | + acpi_gpio_update_gpiod_lookup_flags(lookupflags, &info); |
---|
814 | 871 | return desc; |
---|
815 | 872 | } |
---|
816 | 873 | |
---|
.. | .. |
---|
821 | 878 | * @index: index of GpioIo/GpioInt resource (starting from %0) |
---|
822 | 879 | * @info: info pointer to fill in (optional) |
---|
823 | 880 | * |
---|
824 | | - * If @fwnode is an ACPI device object, call %acpi_get_gpiod_by_index() for it. |
---|
825 | | - * Otherwise (ie. it is a data-only non-device object), use the property-based |
---|
| 881 | + * If @fwnode is an ACPI device object, call acpi_get_gpiod_by_index() for it. |
---|
| 882 | + * Otherwise (i.e. it is a data-only non-device object), use the property-based |
---|
826 | 883 | * GPIO lookup to get to the GPIO resource with the relevant information and use |
---|
827 | 884 | * that to obtain the GPIO descriptor to return. |
---|
| 885 | + * |
---|
| 886 | + * If the GPIO cannot be translated or there is an error an ERR_PTR is |
---|
| 887 | + * returned. |
---|
828 | 888 | */ |
---|
829 | 889 | struct gpio_desc *acpi_node_get_gpiod(struct fwnode_handle *fwnode, |
---|
830 | 890 | const char *propname, int index, |
---|
.. | .. |
---|
856 | 916 | } |
---|
857 | 917 | |
---|
858 | 918 | /** |
---|
859 | | - * acpi_dev_gpio_irq_get() - Find GpioInt and translate it to Linux IRQ number |
---|
| 919 | + * acpi_dev_gpio_irq_get_by() - Find GpioInt and translate it to Linux IRQ number |
---|
860 | 920 | * @adev: pointer to a ACPI device to get IRQ from |
---|
| 921 | + * @name: optional name of GpioInt resource |
---|
861 | 922 | * @index: index of GpioInt resource (starting from %0) |
---|
862 | 923 | * |
---|
863 | 924 | * If the device has one or more GpioInt resources, this function can be |
---|
.. | .. |
---|
867 | 928 | * The function is idempotent, though each time it runs it will configure GPIO |
---|
868 | 929 | * pin direction according to the flags in GpioInt resource. |
---|
869 | 930 | * |
---|
| 931 | + * The function takes optional @name parameter. If the resource has a property |
---|
| 932 | + * name, then only those will be taken into account. |
---|
| 933 | + * |
---|
870 | 934 | * Return: Linux IRQ number (> %0) on success, negative errno on failure. |
---|
871 | 935 | */ |
---|
872 | | -int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index) |
---|
| 936 | +int acpi_dev_gpio_irq_get_by(struct acpi_device *adev, const char *name, int index) |
---|
873 | 937 | { |
---|
874 | 938 | int idx, i; |
---|
875 | 939 | unsigned int irq_flags; |
---|
.. | .. |
---|
879 | 943 | struct acpi_gpio_info info; |
---|
880 | 944 | struct gpio_desc *desc; |
---|
881 | 945 | |
---|
882 | | - desc = acpi_get_gpiod_by_index(adev, NULL, i, &info); |
---|
| 946 | + desc = acpi_get_gpiod_by_index(adev, name, i, &info); |
---|
883 | 947 | |
---|
884 | 948 | /* Ignore -EPROBE_DEFER, it only matters if idx matches */ |
---|
885 | 949 | if (IS_ERR(desc) && PTR_ERR(desc) != -EPROBE_DEFER) |
---|
886 | 950 | return PTR_ERR(desc); |
---|
887 | 951 | |
---|
888 | 952 | if (info.gpioint && idx++ == index) { |
---|
| 953 | + unsigned long lflags = GPIO_LOOKUP_FLAGS_DEFAULT; |
---|
889 | 954 | char label[32]; |
---|
890 | 955 | int irq; |
---|
891 | 956 | |
---|
.. | .. |
---|
897 | 962 | return irq; |
---|
898 | 963 | |
---|
899 | 964 | snprintf(label, sizeof(label), "GpioInt() %d", index); |
---|
900 | | - ret = gpiod_configure_flags(desc, label, 0, info.flags); |
---|
| 965 | + ret = gpiod_configure_flags(desc, label, lflags, info.flags); |
---|
901 | 966 | if (ret < 0) |
---|
902 | 967 | return ret; |
---|
903 | 968 | |
---|
.. | .. |
---|
922 | 987 | } |
---|
923 | 988 | return -ENOENT; |
---|
924 | 989 | } |
---|
925 | | -EXPORT_SYMBOL_GPL(acpi_dev_gpio_irq_get); |
---|
| 990 | +EXPORT_SYMBOL_GPL(acpi_dev_gpio_irq_get_by); |
---|
926 | 991 | |
---|
927 | 992 | static acpi_status |
---|
928 | 993 | acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address, |
---|
.. | .. |
---|
979 | 1044 | * event but only if the access here is ACPI_READ. In that |
---|
980 | 1045 | * case we "borrow" the event GPIO instead. |
---|
981 | 1046 | */ |
---|
982 | | - if (!found && agpio->sharable == ACPI_SHARED && |
---|
| 1047 | + if (!found && agpio->shareable == ACPI_SHARED && |
---|
983 | 1048 | function == ACPI_READ) { |
---|
984 | 1049 | struct acpi_gpio_event *event; |
---|
985 | 1050 | |
---|
.. | .. |
---|
995 | 1060 | if (!found) { |
---|
996 | 1061 | enum gpiod_flags flags = acpi_gpio_to_gpiod_flags(agpio); |
---|
997 | 1062 | const char *label = "ACPI:OpRegion"; |
---|
998 | | - int err; |
---|
999 | 1063 | |
---|
1000 | | - desc = gpiochip_request_own_desc(chip, pin, label); |
---|
| 1064 | + desc = gpiochip_request_own_desc(chip, pin, label, |
---|
| 1065 | + GPIO_ACTIVE_HIGH, |
---|
| 1066 | + flags); |
---|
1001 | 1067 | if (IS_ERR(desc)) { |
---|
1002 | 1068 | status = AE_ERROR; |
---|
1003 | | - mutex_unlock(&achip->conn_lock); |
---|
1004 | | - goto out; |
---|
1005 | | - } |
---|
1006 | | - |
---|
1007 | | - err = gpiod_configure_flags(desc, label, 0, flags); |
---|
1008 | | - if (err < 0) { |
---|
1009 | | - status = AE_NOT_CONFIGURED; |
---|
1010 | | - gpiochip_free_own_desc(desc); |
---|
1011 | 1069 | mutex_unlock(&achip->conn_lock); |
---|
1012 | 1070 | goto out; |
---|
1013 | 1071 | } |
---|
.. | .. |
---|
1077 | 1135 | } |
---|
1078 | 1136 | } |
---|
1079 | 1137 | |
---|
1080 | | -static struct gpio_desc *acpi_gpiochip_parse_own_gpio( |
---|
1081 | | - struct acpi_gpio_chip *achip, struct fwnode_handle *fwnode, |
---|
1082 | | - const char **name, unsigned int *lflags, unsigned int *dflags) |
---|
| 1138 | +static struct gpio_desc * |
---|
| 1139 | +acpi_gpiochip_parse_own_gpio(struct acpi_gpio_chip *achip, |
---|
| 1140 | + struct fwnode_handle *fwnode, |
---|
| 1141 | + const char **name, |
---|
| 1142 | + unsigned long *lflags, |
---|
| 1143 | + enum gpiod_flags *dflags) |
---|
1083 | 1144 | { |
---|
1084 | 1145 | struct gpio_chip *chip = achip->chip; |
---|
1085 | 1146 | struct gpio_desc *desc; |
---|
1086 | 1147 | u32 gpios[2]; |
---|
1087 | 1148 | int ret; |
---|
1088 | 1149 | |
---|
1089 | | - *lflags = 0; |
---|
| 1150 | + *lflags = GPIO_LOOKUP_FLAGS_DEFAULT; |
---|
1090 | 1151 | *dflags = 0; |
---|
1091 | 1152 | *name = NULL; |
---|
1092 | 1153 | |
---|
.. | .. |
---|
1122 | 1183 | struct fwnode_handle *fwnode; |
---|
1123 | 1184 | |
---|
1124 | 1185 | device_for_each_child_node(chip->parent, fwnode) { |
---|
1125 | | - unsigned int lflags, dflags; |
---|
| 1186 | + unsigned long lflags; |
---|
| 1187 | + enum gpiod_flags dflags; |
---|
1126 | 1188 | struct gpio_desc *desc; |
---|
1127 | 1189 | const char *name; |
---|
1128 | 1190 | int ret; |
---|
.. | .. |
---|
1175 | 1237 | return; |
---|
1176 | 1238 | } |
---|
1177 | 1239 | |
---|
1178 | | - if (!chip->names) |
---|
1179 | | - devprop_gpiochip_set_names(chip, dev_fwnode(chip->parent)); |
---|
1180 | | - |
---|
1181 | 1240 | acpi_gpiochip_request_regions(acpi_gpio); |
---|
1182 | 1241 | acpi_gpiochip_scan_gpios(acpi_gpio); |
---|
1183 | 1242 | acpi_walk_dep_device_list(handle); |
---|
.. | .. |
---|
1218 | 1277 | switch (element->type) { |
---|
1219 | 1278 | case ACPI_TYPE_LOCAL_REFERENCE: |
---|
1220 | 1279 | element += 3; |
---|
1221 | | - /* Fallthrough */ |
---|
| 1280 | + fallthrough; |
---|
1222 | 1281 | case ACPI_TYPE_INTEGER: |
---|
1223 | 1282 | element++; |
---|
1224 | 1283 | count++; |
---|
.. | .. |
---|
1243 | 1302 | } |
---|
1244 | 1303 | |
---|
1245 | 1304 | /** |
---|
1246 | | - * acpi_gpio_count - return the number of GPIOs associated with a |
---|
1247 | | - * device / function or -ENOENT if no GPIO has been |
---|
1248 | | - * assigned to the requested function. |
---|
1249 | | - * @dev: GPIO consumer, can be NULL for system-global GPIOs |
---|
| 1305 | + * acpi_gpio_count - count the GPIOs associated with a device / function |
---|
| 1306 | + * @dev: GPIO consumer, can be %NULL for system-global GPIOs |
---|
1250 | 1307 | * @con_id: function within the GPIO consumer |
---|
| 1308 | + * |
---|
| 1309 | + * Return: |
---|
| 1310 | + * The number of GPIOs associated with a device / function or %-ENOENT, |
---|
| 1311 | + * if no GPIO has been assigned to the requested function. |
---|
1251 | 1312 | */ |
---|
1252 | 1313 | int acpi_gpio_count(struct device *dev, const char *con_id) |
---|
1253 | 1314 | { |
---|
.. | .. |
---|
1304 | 1365 | return count ? count : -ENOENT; |
---|
1305 | 1366 | } |
---|
1306 | 1367 | |
---|
1307 | | -bool acpi_can_fallback_to_crs(struct acpi_device *adev, const char *con_id) |
---|
1308 | | -{ |
---|
1309 | | - /* Never allow fallback if the device has properties */ |
---|
1310 | | - if (adev->data.properties || adev->driver_gpios) |
---|
1311 | | - return false; |
---|
1312 | | - |
---|
1313 | | - return con_id == NULL; |
---|
1314 | | -} |
---|
1315 | | - |
---|
1316 | 1368 | /* Run deferred acpi_gpiochip_request_irqs() */ |
---|
1317 | | -static int acpi_gpio_handle_deferred_request_irqs(void) |
---|
| 1369 | +static int __init acpi_gpio_handle_deferred_request_irqs(void) |
---|
1318 | 1370 | { |
---|
1319 | 1371 | struct acpi_gpio_chip *acpi_gpio, *tmp; |
---|
1320 | 1372 | |
---|
.. | .. |
---|
1332 | 1384 | /* We must use _sync so that this runs after the first deferred_probe run */ |
---|
1333 | 1385 | late_initcall_sync(acpi_gpio_handle_deferred_request_irqs); |
---|
1334 | 1386 | |
---|
1335 | | -static const struct dmi_system_id gpiolib_acpi_quirks[] = { |
---|
| 1387 | +static const struct dmi_system_id gpiolib_acpi_quirks[] __initconst = { |
---|
1336 | 1388 | { |
---|
1337 | 1389 | /* |
---|
1338 | 1390 | * The Minix Neo Z83-4 has a micro-USB-B id-pin handler for |
---|
.. | .. |
---|
1430 | 1482 | {} /* Terminating entry */ |
---|
1431 | 1483 | }; |
---|
1432 | 1484 | |
---|
1433 | | -static int acpi_gpio_setup_params(void) |
---|
| 1485 | +static int __init acpi_gpio_setup_params(void) |
---|
1434 | 1486 | { |
---|
1435 | 1487 | const struct acpi_gpiolib_dmi_quirk *quirk = NULL; |
---|
1436 | 1488 | const struct dmi_system_id *id; |
---|