History

gpio: pass lookup and descriptor flags to request_own

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.

Linus Walleij committed 7 years ago

Commit 5923ea61 parent 0aa3ebf8 files · +34 −38Browse files

Unified · Split

8 files
  1. arch/arm/mach-omap1/ams-delta-fiq.c +3 −1
  2. arch/arm/mach-omap1/board-ams-delta.c +3 −2
  3. drivers/gpio/gpio-mvebu.c +4 −7
  4. drivers/gpio/gpiolib-acpi.c +3 −3
  5. drivers/gpio/gpiolib.c +10 −21
  6. drivers/hid/hid-cp2112.c +5 −2
  7. drivers/memory/omap-gpmc.c +3 −1
  8. include/linux/gpio/driver.h +3 −1
arch/arm/mach-omap1/ams-delta-fiq.c+3−1
@@ -14,6 +14,7 @@ · 13 unmodified lines
1414 * the Free Software Foundation.
1515 */
1616 #include <linux/gpio/consumer.h>
17+#include <linux/gpio/machine.h>
1718 #include <linux/gpio/driver.h>
1819 #include <linux/interrupt.h>
1920 #include <linux/irq.h>
@@ -102,7 +103,8 @@ void __init ams_delta_init_fiq(struct gpio_chip *chip, · 82 unmodified lines
102103 }
103104
104105 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);
106108 if (IS_ERR(gpiod)) {
107109 pr_err("%s: failed to get GPIO pin %d (%ld)\n",
108110 __func__, i, PTR_ERR(gpiod));
arch/arm/mach-omap1/board-ams-delta.c+3−2
@@ -13,6 +13,7 @@ · 12 unmodified lines
1313 */
1414 #include <linux/gpio/driver.h>
1515 #include <linux/gpio/machine.h>
16+#include <linux/gpio/consumer.h>
1617 #include <linux/gpio.h>
1718 #include <linux/kernel.h>
1819 #include <linux/init.h>
@@ -609,12 +610,12 @@ static void __init modem_assign_irq(struct gpio_chip *chip) · 590 unmodified lines
609610 struct gpio_desc *gpiod;
610611
611612 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);
613615 if (IS_ERR(gpiod)) {
614616 pr_err("%s: modem IRQ GPIO request failed (%ld)\n", __func__,
615617 PTR_ERR(gpiod));
616618 } else {
617− gpiod_direction_input(gpiod);
618619 ams_delta_modem_ports[0].irq = gpiod_to_irq(gpiod);
619620 }
620621 }
drivers/gpio/gpio-mvebu.c+4−7
@@ -38,6 +38,7 @@ · 37 unmodified lines
3838 #include <linux/err.h>
3939 #include <linux/gpio/driver.h>
4040 #include <linux/gpio/consumer.h>
41+#include <linux/gpio/machine.h>
4142 #include <linux/init.h>
4243 #include <linux/io.h>
4344 #include <linux/irq.h>
@@ -618,18 +619,14 @@ static int mvebu_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) · 574 unmodified lines
618619 ret = -EBUSY;
619620 } else {
620621 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);
622625 if (IS_ERR(desc)) {
623626 ret = PTR_ERR(desc);
624627 goto out;
625628 }
626629
627− ret = gpiod_direction_output(desc, 0);
628− if (ret) {
629− gpiochip_free_own_desc(desc);
630− goto out;
631− }
632−
633630 mvpwm->gpiod = desc;
634631 }
635632 out:
drivers/gpio/gpiolib-acpi.c+3−3
@@ -217,14 +217,13 @@ static acpi_status acpi_gpiochip_alloc_event(struct acpi_resource *ares, · 216 unmodified lines
217217 if (!handler)
218218 return AE_OK;
219219
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);
221222 if (IS_ERR(desc)) {
222223 dev_err(chip->parent, "Failed to request GPIO\n");
223224 return AE_ERROR;
224225 }
225226
226− gpiod_direction_input(desc);
227−
228227 ret = gpiochip_lock_as_irq(chip, pin);
229228 if (ret) {
230229 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
951950 const char *label = "ACPI:OpRegion";
952951
953952 desc = gpiochip_request_own_desc(chip, pin, label,
953+ GPIO_ACTIVE_HIGH,
954954 flags);
955955 if (IS_ERR(desc)) {
956956 status = AE_ERROR;
drivers/gpio/gpiolib.c+10−21
@@ -2503,7 +2503,11 @@ EXPORT_SYMBOL_GPL(gpiochip_is_requested); · 2502 unmodified lines
25032503 * @chip: GPIO chip
25042504 * @hwnum: hardware number of the GPIO for which to request the descriptor
25052505 * @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
25072511 *
25082512 * Function allows GPIO chip drivers to request and use their own GPIO
25092513 * descriptors via gpiolib API. Difference to gpiod_request() is that this
@@ -2517,9 +2521,9 @@ EXPORT_SYMBOL_GPL(gpiochip_is_requested); · 7 unmodified lines
25172521 */
25182522 struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum,
25192523 const char *label,
2520− enum gpiod_flags flags)
2524+ enum gpio_lookup_flags lflags,
2525+ enum gpiod_flags dflags)
25212526 {
2522− unsigned long lflags = GPIO_LOOKUP_FLAGS_DEFAULT;
25232527 struct gpio_desc *desc = gpiochip_get_desc(chip, hwnum);
25242528 int err;
25252529
@@ -2532,7 +2536,7 @@ struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum, · 6 unmodified lines
25322536 if (err < 0)
25332537 return ERR_PTR(err);
25342538
2535− err = gpiod_configure_flags(desc, label, lflags, flags);
2539+ err = gpiod_configure_flags(desc, label, lflags, dflags);
25362540 if (err) {
25372541 chip_err(chip, "setup of own GPIO %s failed\n", label);
25382542 gpiod_free_commit(desc);
@@ -4420,15 +4424,8 @@ int gpiod_hog(struct gpio_desc *desc, const char *name, · 1881 unmodified lines
44204424 chip = gpiod_to_chip(desc);
44214425 hwnum = gpio_chip_hwgpio(desc);
44224426
4423− /*
4424− * FIXME: not very elegant that we call gpiod_configure_flags()
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);
4427+ local_desc = gpiochip_request_own_desc(chip, hwnum, name,
4428+ lflags, dflags);
44324429 if (IS_ERR(local_desc)) {
44334430 status = PTR_ERR(local_desc);
44344431 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
44364433 return status;
44374434 }
44384435
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−
44474436 /* Mark GPIO as hogged so it can be identified and removed later */
44484437 set_bit(FLAG_IS_HOGGED, &desc->flags);
44494438
drivers/hid/hid-cp2112.c+5−2
@@ -24,7 +24,8 @@ · 23 unmodified lines
2424 * https://www.silabs.com/documents/public/application-notes/an495-cp2112-interface-specification.pdf
2525 */
2626
27−#include <linux/gpio.h>
27+#include <linux/gpio/consumer.h>
28+#include <linux/gpio/machine.h>
2829 #include <linux/gpio/driver.h>
2930 #include <linux/hid.h>
3031 #include <linux/hidraw.h>
@@ -1203,7 +1204,9 @@ static int __maybe_unused cp2112_allocate_irq(struct cp2112_device *dev, · 1172 unmodified lines
12031204 return -EINVAL;
12041205
12051206 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);
12071210 if (IS_ERR(dev->desc[pin])) {
12081211 dev_err(dev->gc.parent, "Failed to request GPIO\n");
12091212 return PTR_ERR(dev->desc[pin]);
drivers/memory/omap-gpmc.c+3−1
@@ -22,6 +22,7 @@ · 21 unmodified lines
2222 #include <linux/io.h>
2323 #include <linux/gpio/driver.h>
2424 #include <linux/gpio/consumer.h> /* GPIO descriptor enum */
25+#include <linux/gpio/machine.h>
2526 #include <linux/interrupt.h>
2627 #include <linux/irqdomain.h>
2728 #include <linux/platform_device.h>
@@ -2172,7 +2173,8 @@ static int gpmc_probe_generic_child(struct platform_device *pdev, · 2144 unmodified lines
21722173
21732174 waitpin_desc = gpiochip_request_own_desc(&gpmc->gpio_chip,
21742175 wait_pin, "WAITPIN",
2175− 0);
2176+ GPIO_ACTIVE_HIGH,
2177+ GPIOD_IN);
21762178 if (IS_ERR(waitpin_desc)) {
21772179 dev_err(&pdev->dev, "invalid wait-pin: %d\n", wait_pin);
21782180 ret = PTR_ERR(waitpin_desc);
include/linux/gpio/driver.h+3−1
@@ -18,6 +18,7 @@ struct seq_file; · 17 unmodified lines
1818 struct gpio_device;
1919 struct module;
2020 enum gpiod_flags;
21+enum gpio_lookup_flags;
2122
2223 #ifdef CONFIG_GPIOLIB
2324
@@ -614,7 +615,8 @@ gpiochip_remove_pin_ranges(struct gpio_chip *chip) · 590 unmodified lines
614615
615616 struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum,
616617 const char *label,
617− enum gpiod_flags flags);
618+ enum gpio_lookup_flags lflags,
619+ enum gpiod_flags dflags);
618620 void gpiochip_free_own_desc(struct gpio_desc *desc);
619621
620622 void devprop_gpiochip_set_names(struct gpio_chip *chip,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t