When a gpio_chip wants to request a descriptor from itself using gpiochip_request_own_desc() it needs to be able to specify fully how to use the descriptor, notably line inversion semantics. The workaround in the gpiolib.c can be removed and cases (such as SPI CS) where we need at times to request a GPIO with line inversion semantics directly on a chip for workarounds, can be fully supported with this call. Fix up some users of the API that weren't really using the last flag to set up the line as input or output properly but instead just calling direction setting explicitly after requesting the line.
Unified · Split
| @@ -14,6 +14,7 @@ · 13 unmodified lines | |||
| 14 | * the Free Software Foundation. | 14 | * the Free Software Foundation. |
| 15 | */ | 15 | */ |
| 16 | #include <linux/gpio/consumer.h> | 16 | #include <linux/gpio/consumer.h> |
| 17 | #include <linux/gpio/machine.h> | ||
| 17 | #include <linux/gpio/driver.h> | 18 | #include <linux/gpio/driver.h> |
| 18 | #include <linux/interrupt.h> | 19 | #include <linux/interrupt.h> |
| 19 | #include <linux/irq.h> | 20 | #include <linux/irq.h> |
| @@ -102,7 +103,8 @@ void __init ams_delta_init_fiq(struct gpio_chip *chip, · 82 unmodified lines | |||
| 102 | } | 103 | } |
| 103 | 104 | ||
| 104 | for (i = 0; i < ARRAY_SIZE(irq_data); i++) { | 105 | for (i = 0; i < ARRAY_SIZE(irq_data); i++) { |
| 105 | gpiod = gpiochip_request_own_desc(chip, i, pin_name[i], 0); | 106 | gpiod = gpiochip_request_own_desc(chip, i, pin_name[i], |
| 107 | GPIO_ACTIVE_HIGH, GPIOD_IN); | ||
| 106 | if (IS_ERR(gpiod)) { | 108 | if (IS_ERR(gpiod)) { |
| 107 | pr_err("%s: failed to get GPIO pin %d (%ld)\n", | 109 | pr_err("%s: failed to get GPIO pin %d (%ld)\n", |
| 108 | __func__, i, PTR_ERR(gpiod)); | 110 | __func__, i, PTR_ERR(gpiod)); |
| @@ -13,6 +13,7 @@ · 12 unmodified lines | |||
| 13 | */ | 13 | */ |
| 14 | #include <linux/gpio/driver.h> | 14 | #include <linux/gpio/driver.h> |
| 15 | #include <linux/gpio/machine.h> | 15 | #include <linux/gpio/machine.h> |
| 16 | #include <linux/gpio/consumer.h> | ||
| 16 | #include <linux/gpio.h> | 17 | #include <linux/gpio.h> |
| 17 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
| 18 | #include <linux/init.h> | 19 | #include <linux/init.h> |
| @@ -609,12 +610,12 @@ static void __init modem_assign_irq(struct gpio_chip *chip) · 590 unmodified lines | |||
| 609 | struct gpio_desc *gpiod; | 610 | struct gpio_desc *gpiod; |
| 610 | 611 | ||
| 611 | gpiod = gpiochip_request_own_desc(chip, AMS_DELTA_GPIO_PIN_MODEM_IRQ, | 612 | gpiod = gpiochip_request_own_desc(chip, AMS_DELTA_GPIO_PIN_MODEM_IRQ, |
| 612 | "modem_irq", 0); | 613 | "modem_irq", GPIO_ACTIVE_HIGH, |
| 614 | GPIOD_IN); | ||
| 613 | if (IS_ERR(gpiod)) { | 615 | if (IS_ERR(gpiod)) { |
| 614 | pr_err("%s: modem IRQ GPIO request failed (%ld)\n", __func__, | 616 | pr_err("%s: modem IRQ GPIO request failed (%ld)\n", __func__, |
| 615 | PTR_ERR(gpiod)); | 617 | PTR_ERR(gpiod)); |
| 616 | } else { | 618 | } else { |
| 617 | gpiod_direction_input(gpiod); | ||
| 618 | ams_delta_modem_ports[0].irq = gpiod_to_irq(gpiod); | 619 | ams_delta_modem_ports[0].irq = gpiod_to_irq(gpiod); |
| 619 | } | 620 | } |
| 620 | } | 621 | } |
| @@ -38,6 +38,7 @@ · 37 unmodified lines | |||
| 38 | #include <linux/err.h> | 38 | #include <linux/err.h> |
| 39 | #include <linux/gpio/driver.h> | 39 | #include <linux/gpio/driver.h> |
| 40 | #include <linux/gpio/consumer.h> | 40 | #include <linux/gpio/consumer.h> |
| 41 | #include <linux/gpio/machine.h> | ||
| 41 | #include <linux/init.h> | 42 | #include <linux/init.h> |
| 42 | #include <linux/io.h> | 43 | #include <linux/io.h> |
| 43 | #include <linux/irq.h> | 44 | #include <linux/irq.h> |
| @@ -618,18 +619,14 @@ static int mvebu_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) · 574 unmodified lines | |||
| 618 | ret = -EBUSY; | 619 | ret = -EBUSY; |
| 619 | } else { | 620 | } else { |
| 620 | desc = gpiochip_request_own_desc(&mvchip->chip, | 621 | desc = gpiochip_request_own_desc(&mvchip->chip, |
| 621 | pwm->hwpwm, "mvebu-pwm", 0); | 622 | pwm->hwpwm, "mvebu-pwm", |
| 623 | GPIO_ACTIVE_HIGH, | ||
| 624 | GPIOD_OUT_LOW); | ||
| 622 | if (IS_ERR(desc)) { | 625 | if (IS_ERR(desc)) { |
| 623 | ret = PTR_ERR(desc); | 626 | ret = PTR_ERR(desc); |
| 624 | goto out; | 627 | goto out; |
| 625 | } | 628 | } |
| 626 | 629 | ||
| 627 | ret = gpiod_direction_output(desc, 0); | ||
| 628 | if (ret) { | ||
| 629 | gpiochip_free_own_desc(desc); | ||
| 630 | goto out; | ||
| 631 | } | ||
| 632 | |||
| 633 | mvpwm->gpiod = desc; | 630 | mvpwm->gpiod = desc; |
| 634 | } | 631 | } |
| 635 | out: | 632 | out: |
| @@ -217,14 +217,13 @@ static acpi_status acpi_gpiochip_alloc_event(struct acpi_resource *ares, · 216 unmodified lines | |||
| 217 | if (!handler) | 217 | if (!handler) |
| 218 | return AE_OK; | 218 | return AE_OK; |
| 219 | 219 | ||
| 220 | desc = gpiochip_request_own_desc(chip, pin, "ACPI:Event", 0); | 220 | desc = gpiochip_request_own_desc(chip, pin, "ACPI:Event", |
| 221 | GPIO_ACTIVE_HIGH, GPIOD_IN); | ||
| 221 | if (IS_ERR(desc)) { | 222 | if (IS_ERR(desc)) { |
| 222 | dev_err(chip->parent, "Failed to request GPIO\n"); | 223 | dev_err(chip->parent, "Failed to request GPIO\n"); |
| 223 | return AE_ERROR; | 224 | return AE_ERROR; |
| 224 | } | 225 | } |
| 225 | 226 | ||
| 226 | gpiod_direction_input(desc); | ||
| 227 | |||
| 228 | ret = gpiochip_lock_as_irq(chip, pin); | 227 | ret = gpiochip_lock_as_irq(chip, pin); |
| 229 | if (ret) { | 228 | if (ret) { |
| 230 | dev_err(chip->parent, "Failed to lock GPIO as interrupt\n"); | 229 | dev_err(chip->parent, "Failed to lock GPIO as interrupt\n"); |
| @@ -951,6 +950,7 @@ acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address, · 720 unmodified lines | |||
| 951 | const char *label = "ACPI:OpRegion"; | 950 | const char *label = "ACPI:OpRegion"; |
| 952 | 951 | ||
| 953 | desc = gpiochip_request_own_desc(chip, pin, label, | 952 | desc = gpiochip_request_own_desc(chip, pin, label, |
| 953 | GPIO_ACTIVE_HIGH, | ||
| 954 | flags); | 954 | flags); |
| 955 | if (IS_ERR(desc)) { | 955 | if (IS_ERR(desc)) { |
| 956 | status = AE_ERROR; | 956 | status = AE_ERROR; |
| @@ -2503,7 +2503,11 @@ EXPORT_SYMBOL_GPL(gpiochip_is_requested); · 2502 unmodified lines | |||
| 2503 | * @chip: GPIO chip | 2503 | * @chip: GPIO chip |
| 2504 | * @hwnum: hardware number of the GPIO for which to request the descriptor | 2504 | * @hwnum: hardware number of the GPIO for which to request the descriptor |
| 2505 | * @label: label for the GPIO | 2505 | * @label: label for the GPIO |
| 2506 | * @flags: flags for this GPIO or 0 if default | 2506 | * @lflags: lookup flags for this GPIO or 0 if default, this can be used to |
| 2507 | * specify things like line inversion semantics with the machine flags | ||
| 2508 | * such as GPIO_OUT_LOW | ||
| 2509 | * @dflags: descriptor request flags for this GPIO or 0 if default, this | ||
| 2510 | * can be used to specify consumer semantics such as open drain | ||
| 2507 | * | 2511 | * |
| 2508 | * Function allows GPIO chip drivers to request and use their own GPIO | 2512 | * Function allows GPIO chip drivers to request and use their own GPIO |
| 2509 | * descriptors via gpiolib API. Difference to gpiod_request() is that this | 2513 | * descriptors via gpiolib API. Difference to gpiod_request() is that this |
| @@ -2517,9 +2521,9 @@ EXPORT_SYMBOL_GPL(gpiochip_is_requested); · 7 unmodified lines | |||
| 2517 | */ | 2521 | */ |
| 2518 | struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum, | 2522 | struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum, |
| 2519 | const char *label, | 2523 | const char *label, |
| 2520 | enum gpiod_flags flags) | 2524 | enum gpio_lookup_flags lflags, |
| 2525 | enum gpiod_flags dflags) | ||
| 2521 | { | 2526 | { |
| 2522 | unsigned long lflags = GPIO_LOOKUP_FLAGS_DEFAULT; | ||
| 2523 | struct gpio_desc *desc = gpiochip_get_desc(chip, hwnum); | 2527 | struct gpio_desc *desc = gpiochip_get_desc(chip, hwnum); |
| 2524 | int err; | 2528 | int err; |
| 2525 | 2529 | ||
| @@ -2532,7 +2536,7 @@ struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum, · 6 unmodified lines | |||
| 2532 | if (err < 0) | 2536 | if (err < 0) |
| 2533 | return ERR_PTR(err); | 2537 | return ERR_PTR(err); |
| 2534 | 2538 | ||
| 2535 | err = gpiod_configure_flags(desc, label, lflags, flags); | 2539 | err = gpiod_configure_flags(desc, label, lflags, dflags); |
| 2536 | if (err) { | 2540 | if (err) { |
| 2537 | chip_err(chip, "setup of own GPIO %s failed\n", label); | 2541 | chip_err(chip, "setup of own GPIO %s failed\n", label); |
| 2538 | gpiod_free_commit(desc); | 2542 | gpiod_free_commit(desc); |
| @@ -4420,15 +4424,8 @@ int gpiod_hog(struct gpio_desc *desc, const char *name, · 1881 unmodified lines | |||
| 4420 | chip = gpiod_to_chip(desc); | 4424 | chip = gpiod_to_chip(desc); |
| 4421 | hwnum = gpio_chip_hwgpio(desc); | 4425 | hwnum = gpio_chip_hwgpio(desc); |
| 4422 | 4426 | ||
| 4423 | /* | 4427 | local_desc = gpiochip_request_own_desc(chip, hwnum, name, |
| 4424 | * FIXME: not very elegant that we call gpiod_configure_flags() | 4428 | lflags, dflags); |
| 4425 | * twice here (once inside gpiochip_request_own_desc() and | ||
| 4426 | * again here), but the gpiochip_request_own_desc() is external | ||
| 4427 | * and cannot really pass the lflags so this is the lesser evil | ||
| 4428 | * at the moment. Pass zero as dflags on this first call so we | ||
| 4429 | * don't screw anything up. | ||
| 4430 | */ | ||
| 4431 | local_desc = gpiochip_request_own_desc(chip, hwnum, name, 0); | ||
| 4432 | if (IS_ERR(local_desc)) { | 4429 | if (IS_ERR(local_desc)) { |
| 4433 | status = PTR_ERR(local_desc); | 4430 | status = PTR_ERR(local_desc); |
| 4434 | pr_err("requesting hog GPIO %s (chip %s, offset %d) failed, %d\n", | 4431 | pr_err("requesting hog GPIO %s (chip %s, offset %d) failed, %d\n", |
| @@ -4436,14 +4433,6 @@ int gpiod_hog(struct gpio_desc *desc, const char *name, · 1 unmodified line | |||
| 4436 | return status; | 4433 | return status; |
| 4437 | } | 4434 | } |
| 4438 | 4435 | ||
| 4439 | status = gpiod_configure_flags(desc, name, lflags, dflags); | ||
| 4440 | if (status < 0) { | ||
| 4441 | pr_err("setup of hog GPIO %s (chip %s, offset %d) failed, %d\n", | ||
| 4442 | name, chip->label, hwnum, status); | ||
| 4443 | gpiochip_free_own_desc(desc); | ||
| 4444 | return status; | ||
| 4445 | } | ||
| 4446 | |||
| 4447 | /* Mark GPIO as hogged so it can be identified and removed later */ | 4436 | /* Mark GPIO as hogged so it can be identified and removed later */ |
| 4448 | set_bit(FLAG_IS_HOGGED, &desc->flags); | 4437 | set_bit(FLAG_IS_HOGGED, &desc->flags); |
| 4449 | 4438 | ||
| @@ -24,7 +24,8 @@ · 23 unmodified lines | |||
| 24 | * https://www.silabs.com/documents/public/application-notes/an495-cp2112-interface-specification.pdf | 24 | * https://www.silabs.com/documents/public/application-notes/an495-cp2112-interface-specification.pdf |
| 25 | */ | 25 | */ |
| 26 | 26 | ||
| 27 | #include <linux/gpio.h> | 27 | #include <linux/gpio/consumer.h> |
| 28 | #include <linux/gpio/machine.h> | ||
| 28 | #include <linux/gpio/driver.h> | 29 | #include <linux/gpio/driver.h> |
| 29 | #include <linux/hid.h> | 30 | #include <linux/hid.h> |
| 30 | #include <linux/hidraw.h> | 31 | #include <linux/hidraw.h> |
| @@ -1203,7 +1204,9 @@ static int __maybe_unused cp2112_allocate_irq(struct cp2112_device *dev, · 1172 unmodified lines | |||
| 1203 | return -EINVAL; | 1204 | return -EINVAL; |
| 1204 | 1205 | ||
| 1205 | dev->desc[pin] = gpiochip_request_own_desc(&dev->gc, pin, | 1206 | dev->desc[pin] = gpiochip_request_own_desc(&dev->gc, pin, |
| 1206 | "HID/I2C:Event", 0); | 1207 | "HID/I2C:Event", |
| 1208 | GPIO_ACTIVE_HIGH, | ||
| 1209 | GPIOD_IN); | ||
| 1207 | if (IS_ERR(dev->desc[pin])) { | 1210 | if (IS_ERR(dev->desc[pin])) { |
| 1208 | dev_err(dev->gc.parent, "Failed to request GPIO\n"); | 1211 | dev_err(dev->gc.parent, "Failed to request GPIO\n"); |
| 1209 | return PTR_ERR(dev->desc[pin]); | 1212 | return PTR_ERR(dev->desc[pin]); |
| @@ -22,6 +22,7 @@ · 21 unmodified lines | |||
| 22 | #include <linux/io.h> | 22 | #include <linux/io.h> |
| 23 | #include <linux/gpio/driver.h> | 23 | #include <linux/gpio/driver.h> |
| 24 | #include <linux/gpio/consumer.h> /* GPIO descriptor enum */ | 24 | #include <linux/gpio/consumer.h> /* GPIO descriptor enum */ |
| 25 | #include <linux/gpio/machine.h> | ||
| 25 | #include <linux/interrupt.h> | 26 | #include <linux/interrupt.h> |
| 26 | #include <linux/irqdomain.h> | 27 | #include <linux/irqdomain.h> |
| 27 | #include <linux/platform_device.h> | 28 | #include <linux/platform_device.h> |
| @@ -2172,7 +2173,8 @@ static int gpmc_probe_generic_child(struct platform_device *pdev, · 2144 unmodified lines | |||
| 2172 | 2173 | ||
| 2173 | waitpin_desc = gpiochip_request_own_desc(&gpmc->gpio_chip, | 2174 | waitpin_desc = gpiochip_request_own_desc(&gpmc->gpio_chip, |
| 2174 | wait_pin, "WAITPIN", | 2175 | wait_pin, "WAITPIN", |
| 2175 | 0); | 2176 | GPIO_ACTIVE_HIGH, |
| 2177 | GPIOD_IN); | ||
| 2176 | if (IS_ERR(waitpin_desc)) { | 2178 | if (IS_ERR(waitpin_desc)) { |
| 2177 | dev_err(&pdev->dev, "invalid wait-pin: %d\n", wait_pin); | 2179 | dev_err(&pdev->dev, "invalid wait-pin: %d\n", wait_pin); |
| 2178 | ret = PTR_ERR(waitpin_desc); | 2180 | ret = PTR_ERR(waitpin_desc); |
| @@ -18,6 +18,7 @@ struct seq_file; · 17 unmodified lines | |||
| 18 | struct gpio_device; | 18 | struct gpio_device; |
| 19 | struct module; | 19 | struct module; |
| 20 | enum gpiod_flags; | 20 | enum gpiod_flags; |
| 21 | enum gpio_lookup_flags; | ||
| 21 | 22 | ||
| 22 | #ifdef CONFIG_GPIOLIB | 23 | #ifdef CONFIG_GPIOLIB |
| 23 | 24 | ||
| @@ -614,7 +615,8 @@ gpiochip_remove_pin_ranges(struct gpio_chip *chip) · 590 unmodified lines | |||
| 614 | 615 | ||
| 615 | struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum, | 616 | struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum, |
| 616 | const char *label, | 617 | const char *label, |
| 617 | enum gpiod_flags flags); | 618 | enum gpio_lookup_flags lflags, |
| 619 | enum gpiod_flags dflags); | ||
| 618 | void gpiochip_free_own_desc(struct gpio_desc *desc); | 620 | void gpiochip_free_own_desc(struct gpio_desc *desc); |
| 619 | 621 | ||
| 620 | void devprop_gpiochip_set_names(struct gpio_chip *chip, | 622 | void devprop_gpiochip_set_names(struct gpio_chip *chip, |