History

Merge tag 'gpio-fixes-for-v7.0-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux

Pull gpio fixes from Bartosz Golaszewski: - fix kerneldocs for gpio-timberdale and gpio-nomadik - clear the "requested" flag in error path in gpiod_request_commit() - call of_xlate() if provided when setting up shared GPIOs - handle pins shared by child firmware nodes of consumer devices - fix return value check in gpio-qixis-fpga - fix suspend on gpio-mxc - fix gpio-microchip DT bindings * tag 'gpio-fixes-for-v7.0-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux: dt-bindings: gpio: fix microchip #interrupt-cells gpio: shared: shorten the critical section in gpiochip_setup_shared() gpio: mxc: map Both Edge pad wakeup to Rising Edge gpio: qixis-fpga: Fix error handling for devm_regmap_init_mmio() gpio: shared: handle pins shared by child nodes of devices gpio: shared: call gpio_chip::of_xlate() if set gpiolib: clear requested flag if line is invalid gpio: nomadik: repair some kernel-doc comments gpio: timberdale: repair kernel-doc comments gpio: Fix resource leaks on errors in gpiochip_add_data_with_key()

Linus Torvalds committed 7 months ago

Commit 116a3302 parents 441c63f 6b5ef8c8 files · +124 −93Browse files

Unified · Split

8 files
  1. Documentation/devicetree/bindings/gpio/microchip,mpfs-gpio.yaml +2 −2
  2. drivers/gpio/gpio-mxc.c +9 −1
  3. drivers/gpio/gpio-qixis-fpga.c +2 −2
  4. drivers/gpio/gpiolib-shared.c +41 −16
  5. drivers/gpio/gpiolib-shared.h +7 −4
  6. drivers/gpio/gpiolib.c +55 −58
  7. include/linux/gpio/gpio-nomadik.h +5 −7
  8. include/linux/timb_gpio.h +3 −3
Documentation/devicetree/bindings/gpio/microchip,mpfs-gpio.yaml+2−2
@@ -37,7 +37,7 @@ properties: · 36 unmodified lines
3737 const: 2
3838
3939 "#interrupt-cells":
40− const: 1
40+ const: 2
4141
4242 ngpios:
4343 description:
@@ -86,7 +86,7 @@ examples: · 42 unmodified lines
8686 gpio-controller;
8787 #gpio-cells = <2>;
8888 interrupt-controller;
89− #interrupt-cells = <1>;
89+ #interrupt-cells = <2>;
9090 interrupts = <53>, <53>, <53>, <53>,
9191 <53>, <53>, <53>, <53>,
9292 <53>, <53>, <53>, <53>,
drivers/gpio/gpio-mxc.c+9−1
@@ -584,12 +584,13 @@ static bool mxc_gpio_set_pad_wakeup(struct mxc_gpio_port *port, bool enable) · 583 unmodified lines
584584 unsigned long config;
585585 bool ret = false;
586586 int i, type;
587+ bool is_imx8qm = of_device_is_compatible(port->dev->of_node, "fsl,imx8qm-gpio");
587588
588589 static const u32 pad_type_map[] = {
589590 IMX_SCU_WAKEUP_OFF, /* 0 */
590591 IMX_SCU_WAKEUP_RISE_EDGE, /* IRQ_TYPE_EDGE_RISING */
591592 IMX_SCU_WAKEUP_FALL_EDGE, /* IRQ_TYPE_EDGE_FALLING */
592− IMX_SCU_WAKEUP_FALL_EDGE, /* IRQ_TYPE_EDGE_BOTH */
593+ IMX_SCU_WAKEUP_RISE_EDGE, /* IRQ_TYPE_EDGE_BOTH */
593594 IMX_SCU_WAKEUP_HIGH_LVL, /* IRQ_TYPE_LEVEL_HIGH */
594595 IMX_SCU_WAKEUP_OFF, /* 5 */
595596 IMX_SCU_WAKEUP_OFF, /* 6 */
@@ -604,6 +605,13 @@ static bool mxc_gpio_set_pad_wakeup(struct mxc_gpio_port *port, bool enable) · 8 unmodified lines
604605 config = pad_type_map[type];
605606 else
606607 config = IMX_SCU_WAKEUP_OFF;
608+
609+ if (is_imx8qm && config == IMX_SCU_WAKEUP_FALL_EDGE) {
610+ dev_warn_once(port->dev,
611+ "No falling-edge support for wakeup on i.MX8QM\n");
612+ config = IMX_SCU_WAKEUP_OFF;
613+ }
614+
607615 ret |= mxc_gpio_generic_config(port, i, config);
608616 }
609617 }
drivers/gpio/gpio-qixis-fpga.c+2−2
@@ -60,8 +60,8 @@ static int qixis_cpld_gpio_probe(struct platform_device *pdev) · 59 unmodified lines
6060 return PTR_ERR(reg);
6161
6262 regmap = devm_regmap_init_mmio(&pdev->dev, reg, &regmap_config_8r_8v);
63− if (!regmap)
64− return -ENODEV;
63+ if (IS_ERR(regmap))
64+ return PTR_ERR(regmap);
6565
6666 /* In this case, the offset of our register is 0 inside the
6767 * regmap area that we just created.
drivers/gpio/gpiolib-shared.c+41−16
@@ -443,8 +443,8 @@ static bool gpio_shared_dev_is_reset_gpio(struct device *consumer, · 442 unmodified lines
443443 }
444444 #endif /* CONFIG_RESET_GPIO */
445445
446−int gpio_shared_add_proxy_lookup(struct device *consumer, const char *con_id,
447− unsigned long lflags)
446+int gpio_shared_add_proxy_lookup(struct device *consumer, struct fwnode_handle *fwnode,
447+ const char *con_id, unsigned long lflags)
448448 {
449449 const char *dev_id = dev_name(consumer);
450450 struct gpiod_lookup_table *lookup;
@@ -458,7 +458,7 @@ int gpio_shared_add_proxy_lookup(struct device *consumer, const char *con_id, · 7 unmodified lines
458458 if (!ref->fwnode && device_is_compatible(consumer, "reset-gpio")) {
459459 if (!gpio_shared_dev_is_reset_gpio(consumer, entry, ref))
460460 continue;
461− } else if (!device_match_fwnode(consumer, ref->fwnode)) {
461+ } else if (fwnode != ref->fwnode) {
462462 continue;
463463 }
464464
@@ -506,8 +506,9 @@ static void gpio_shared_remove_adev(struct auxiliary_device *adev) · 41 unmodified lines
506506 auxiliary_device_uninit(adev);
507507 }
508508
509−int gpio_device_setup_shared(struct gpio_device *gdev)
509+int gpiochip_setup_shared(struct gpio_chip *gc)
510510 {
511+ struct gpio_device *gdev = gc->gpiodev;
511512 struct gpio_shared_entry *entry;
512513 struct gpio_shared_ref *ref;
513514 struct gpio_desc *desc;
@@ -538,20 +539,42 @@ int gpio_device_setup_shared(struct gpio_device *gdev) · 24 unmodified lines
538539 if (list_count_nodes(&entry->refs) <= 1)
539540 continue;
540541
541− desc = &gdev->descs[entry->offset];
542+ scoped_guard(mutex, &entry->lock) {
543+#if IS_ENABLED(CONFIG_OF)
544+ if (is_of_node(entry->fwnode) && gc->of_xlate) {
545+ /*
546+ * This is the earliest that we can tranlate the
547+ * devicetree offset to the chip offset.
548+ */
549+ struct of_phandle_args gpiospec = { };
542550
543− __set_bit(GPIOD_FLAG_SHARED, &desc->flags);
544− /*
545− * Shared GPIOs are not requested via the normal path. Make
546− * them inaccessible to anyone even before we register the
547− * chip.
548− */
549− ret = gpiod_request_commit(desc, "shared");
550− if (ret)
551− return ret;
551+ gpiospec.np = to_of_node(entry->fwnode);
552+ gpiospec.args_count = 2;
553+ gpiospec.args[0] = entry->offset;
554+
555+ ret = gc->of_xlate(gc, &gpiospec, NULL);
556+ if (ret < 0)
557+ return ret;
558+
559+ entry->offset = ret;
560+ }
561+#endif /* CONFIG_OF */
562+
563+ desc = &gdev->descs[entry->offset];
564+
565+ __set_bit(GPIOD_FLAG_SHARED, &desc->flags);
566+ /*
567+ * Shared GPIOs are not requested via the normal path. Make
568+ * them inaccessible to anyone even before we register the
569+ * chip.
570+ */
571+ ret = gpiod_request_commit(desc, "shared");
572+ if (ret)
573+ return ret;
552574
553− pr_debug("GPIO %u owned by %s is shared by multiple consumers\n",
554− entry->offset, gpio_device_get_label(gdev));
575+ pr_debug("GPIO %u owned by %s is shared by multiple consumers\n",
576+ entry->offset, gpio_device_get_label(gdev));
577+ }
555578
556579 list_for_each_entry(ref, &entry->refs, list) {
557580 pr_debug("Setting up a shared GPIO entry for %s (con_id: '%s')\n",
@@ -575,6 +598,8 @@ void gpio_device_teardown_shared(struct gpio_device *gdev) · 17 unmodified lines
575598 struct gpio_shared_ref *ref;
576599
577600 list_for_each_entry(entry, &gpio_shared_list, list) {
601+ guard(mutex)(&entry->lock);
602+
578603 if (!device_match_fwnode(&gdev->dev, entry->fwnode))
579604 continue;
580605
drivers/gpio/gpiolib-shared.h+7−4
@@ -11,17 +11,19 @@ · 10 unmodified lines
1111 struct gpio_device;
1212 struct gpio_desc;
1313 struct device;
14+struct fwnode_handle;
1415
1516 #if IS_ENABLED(CONFIG_GPIO_SHARED)
1617
17−int gpio_device_setup_shared(struct gpio_device *gdev);
18+int gpiochip_setup_shared(struct gpio_chip *gc);
1819 void gpio_device_teardown_shared(struct gpio_device *gdev);
19−int gpio_shared_add_proxy_lookup(struct device *consumer, const char *con_id,
20− unsigned long lflags);
20+int gpio_shared_add_proxy_lookup(struct device *consumer,
21+ struct fwnode_handle *fwnode,
22+ const char *con_id, unsigned long lflags);
2123
2224 #else
2325
24−static inline int gpio_device_setup_shared(struct gpio_device *gdev)
26+static inline int gpiochip_setup_shared(struct gpio_chip *gc)
2527 {
2628 return 0;
2729 }
@@ -29,6 +31,7 @@ static inline int gpio_device_setup_shared(struct gpio_device *gdev) · 1 unmodified line
2931 static inline void gpio_device_teardown_shared(struct gpio_device *gdev) { }
3032
3133 static inline int gpio_shared_add_proxy_lookup(struct device *consumer,
34+ struct fwnode_handle *fwnode,
3235 const char *con_id,
3336 unsigned long lflags)
3437 {
drivers/gpio/gpiolib.c+55−58
@@ -892,13 +892,15 @@ static const struct device_type gpio_dev_type = { · 891 unmodified lines
892892 #define gcdev_unregister(gdev) device_del(&(gdev)->dev)
893893 #endif
894894
895+/*
896+ * An initial reference count has been held in gpiochip_add_data_with_key().
897+ * The caller should drop the reference via gpio_device_put() on errors.
898+ */
895899 static int gpiochip_setup_dev(struct gpio_device *gdev)
896900 {
897901 struct fwnode_handle *fwnode = dev_fwnode(&gdev->dev);
898902 int ret;
899903
900− device_initialize(&gdev->dev);
901−
902904 /*
903905 * If fwnode doesn't belong to another device, it's safe to clear its
904906 * initialized flag.
@@ -964,9 +966,11 @@ static void gpiochip_setup_devs(void) · 59 unmodified lines
964966 list_for_each_entry_srcu(gdev, &gpio_devices, list,
965967 srcu_read_lock_held(&gpio_devices_srcu)) {
966968 ret = gpiochip_setup_dev(gdev);
967− if (ret)
969+ if (ret) {
970+ gpio_device_put(gdev);
968971 dev_err(&gdev->dev,
969972 "Failed to initialize gpio device (%d)\n", ret);
973+ }
970974 }
971975 }
972976
@@ -1047,71 +1051,72 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, · 74 unmodified lines
10471051 int base = 0;
10481052 int ret;
10491053
1050− /*
1051− * First: allocate and populate the internal stat container, and
1052− * set up the struct device.
1053− */
10541054 gdev = kzalloc(sizeof(*gdev), GFP_KERNEL);
10551055 if (!gdev)
10561056 return -ENOMEM;
1057−
1058− gdev->dev.type = &gpio_dev_type;
1059− gdev->dev.bus = &gpio_bus_type;
1060− gdev->dev.parent = gc->parent;
1061− rcu_assign_pointer(gdev->chip, gc);
1062−
10631057 gc->gpiodev = gdev;
10641058 gpiochip_set_data(gc, data);
10651059
1066− device_set_node(&gdev->dev, gpiochip_choose_fwnode(gc));
1067−
10681060 ret = ida_alloc(&gpio_ida, GFP_KERNEL);
10691061 if (ret < 0)
10701062 goto err_free_gdev;
10711063 gdev->id = ret;
10721064
1073− ret = dev_set_name(&gdev->dev, GPIOCHIP_NAME "%d", gdev->id);
1065+ ret = init_srcu_struct(&gdev->srcu);
10741066 if (ret)
10751067 goto err_free_ida;
1068+ rcu_assign_pointer(gdev->chip, gc);
10761069
1077− if (gc->parent && gc->parent->driver)
1078− gdev->owner = gc->parent->driver->owner;
1079− else if (gc->owner)
1080− /* TODO: remove chip->owner */
1081− gdev->owner = gc->owner;
1082− else
1083− gdev->owner = THIS_MODULE;
1070+ ret = init_srcu_struct(&gdev->desc_srcu);
1071+ if (ret)
1072+ goto err_cleanup_gdev_srcu;
1073+
1074+ ret = dev_set_name(&gdev->dev, GPIOCHIP_NAME "%d", gdev->id);
1075+ if (ret)
1076+ goto err_cleanup_desc_srcu;
1077+
1078+ device_initialize(&gdev->dev);
1079+ /*
1080+ * After this point any allocated resources to `gdev` will be
1081+ * free():ed by gpiodev_release(). If you add new resources
1082+ * then make sure they get free():ed there.
1083+ */
1084+ gdev->dev.type = &gpio_dev_type;
1085+ gdev->dev.bus = &gpio_bus_type;
1086+ gdev->dev.parent = gc->parent;
1087+ device_set_node(&gdev->dev, gpiochip_choose_fwnode(gc));
10841088
10851089 ret = gpiochip_get_ngpios(gc, &gdev->dev);
10861090 if (ret)
1087− goto err_free_dev_name;
1091+ goto err_put_device;
1092+ gdev->ngpio = gc->ngpio;
10881093
10891094 gdev->descs = kcalloc(gc->ngpio, sizeof(*gdev->descs), GFP_KERNEL);
10901095 if (!gdev->descs) {
10911096 ret = -ENOMEM;
1092− goto err_free_dev_name;
1097+ goto err_put_device;
10931098 }
10941099
10951100 gdev->label = kstrdup_const(gc->label ?: "unknown", GFP_KERNEL);
10961101 if (!gdev->label) {
10971102 ret = -ENOMEM;
1098− goto err_free_descs;
1103+ goto err_put_device;
10991104 }
11001105
1101− gdev->ngpio = gc->ngpio;
11021106 gdev->can_sleep = gc->can_sleep;
1103−
11041107 rwlock_init(&gdev->line_state_lock);
11051108 RAW_INIT_NOTIFIER_HEAD(&gdev->line_state_notifier);
11061109 BLOCKING_INIT_NOTIFIER_HEAD(&gdev->device_notifier);
1107−
1108− ret = init_srcu_struct(&gdev->srcu);
1109− if (ret)
1110− goto err_free_label;
1111−
1112− ret = init_srcu_struct(&gdev->desc_srcu);
1113− if (ret)
1114− goto err_cleanup_gdev_srcu;
1110+#ifdef CONFIG_PINCTRL
1111+ INIT_LIST_HEAD(&gdev->pin_ranges);
1112+#endif
1113+ if (gc->parent && gc->parent->driver)
1114+ gdev->owner = gc->parent->driver->owner;
1115+ else if (gc->owner)
1116+ /* TODO: remove chip->owner */
1117+ gdev->owner = gc->owner;
1118+ else
1119+ gdev->owner = THIS_MODULE;
11151120
11161121 scoped_guard(mutex, &gpio_devices_lock) {
11171122 /*
@@ -1127,7 +1132,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, · 9 unmodified lines
11271132 if (base < 0) {
11281133 ret = base;
11291134 base = 0;
1130− goto err_cleanup_desc_srcu;
1135+ goto err_put_device;
11311136 }
11321137
11331138 /*
@@ -1147,14 +1152,10 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, · 13 unmodified lines
11471152 ret = gpiodev_add_to_list_unlocked(gdev);
11481153 if (ret) {
11491154 gpiochip_err(gc, "GPIO integer space overlap, cannot add chip\n");
1150− goto err_cleanup_desc_srcu;
1155+ goto err_put_device;
11511156 }
11521157 }
11531158
1154−#ifdef CONFIG_PINCTRL
1155− INIT_LIST_HEAD(&gdev->pin_ranges);
1156−#endif
1157−
11581159 if (gc->names)
11591160 gpiochip_set_desc_names(gc);
11601161
@@ -1210,7 +1211,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, · 49 unmodified lines
12101211 if (ret)
12111212 goto err_remove_irqchip_mask;
12121213
1213− ret = gpio_device_setup_shared(gdev);
1214+ ret = gpiochip_setup_shared(gc);
12141215 if (ret)
12151216 goto err_remove_irqchip;
12161217
@@ -1248,25 +1249,19 @@ err_remove_from_list: · 31 unmodified lines
12481249 scoped_guard(mutex, &gpio_devices_lock)
12491250 list_del_rcu(&gdev->list);
12501251 synchronize_srcu(&gpio_devices_srcu);
1251− if (gdev->dev.release) {
1252− /* release() has been registered by gpiochip_setup_dev() */
1253− gpio_device_put(gdev);
1254− goto err_print_message;
1255− }
1252+err_put_device:
1253+ gpio_device_put(gdev);
1254+ goto err_print_message;
1255+
12561256 err_cleanup_desc_srcu:
12571257 cleanup_srcu_struct(&gdev->desc_srcu);
12581258 err_cleanup_gdev_srcu:
12591259 cleanup_srcu_struct(&gdev->srcu);
1260−err_free_label:
1261− kfree_const(gdev->label);
1262−err_free_descs:
1263− kfree(gdev->descs);
1264−err_free_dev_name:
1265− kfree(dev_name(&gdev->dev));
12661260 err_free_ida:
12671261 ida_free(&gpio_ida, gdev->id);
12681262 err_free_gdev:
12691263 kfree(gdev);
1264+
12701265 err_print_message:
12711266 /* failures here can mean systems won't boot... */
12721267 if (ret != -EPROBE_DEFER) {
@@ -2465,8 +2460,10 @@ int gpiod_request_commit(struct gpio_desc *desc, const char *label) · 1192 unmodified lines
24652460 return -EBUSY;
24662461
24672462 offset = gpiod_hwgpio(desc);
2468− if (!gpiochip_line_is_valid(guard.gc, offset))
2469− return -EINVAL;
2463+ if (!gpiochip_line_is_valid(guard.gc, offset)) {
2464+ ret = -EINVAL;
2465+ goto out_clear_bit;
2466+ }
24702467
24712468 /* NOTE: gpio_request() can be called in early boot,
24722469 * before IRQs are enabled, for non-sleeping (SOC) GPIOs.
@@ -4717,8 +4714,8 @@ struct gpio_desc *gpiod_find_and_request(struct device *consumer, · 2244 unmodified lines
47174714 * lookup table for the proxy device as previously
47184715 * we only knew the consumer's fwnode.
47194716 */
4720− ret = gpio_shared_add_proxy_lookup(consumer, con_id,
4721− lookupflags);
4717+ ret = gpio_shared_add_proxy_lookup(consumer, fwnode,
4718+ con_id, lookupflags);
47224719 if (ret)
47234720 return ERR_PTR(ret);
47244721
include/linux/gpio/gpio-nomadik.h+5−7
@@ -114,8 +114,7 @@ struct nmk_gpio_chip { · 113 unmodified lines
114114 }
115115
116116 /**
117− * enum prcm_gpiocr_reg_index
118− * Used to reference an PRCM GPIOCR register address.
117+ * enum prcm_gpiocr_reg_index - Used to reference a PRCM GPIOCR register address.
119118 */
120119 enum prcm_gpiocr_reg_index {
121120 PRCM_IDX_GPIOCR1,
@@ -123,8 +122,7 @@ enum prcm_gpiocr_reg_index { · 1 unmodified line
123122 PRCM_IDX_GPIOCR3
124123 };
125124 /**
126− * enum prcm_gpiocr_altcx_index
127− * Used to reference an Other alternate-C function.
125+ * enum prcm_gpiocr_altcx_index - Used to reference an Other alternate-C function.
128126 */
129127 enum prcm_gpiocr_altcx_index {
130128 PRCM_IDX_GPIOCR_ALTC1,
@@ -135,7 +133,7 @@ enum prcm_gpiocr_altcx_index { · 4 unmodified lines
135133 };
136134
137135 /**
138− * struct prcm_gpio_altcx - Other alternate-C function
136+ * struct prcm_gpiocr_altcx - Other alternate-C function
139137 * @used: other alternate-C function availability
140138 * @reg_index: PRCM GPIOCR register index used to control the function
141139 * @control_bit: PRCM GPIOCR bit used to control the function
@@ -147,7 +145,7 @@ struct prcm_gpiocr_altcx { · 5 unmodified lines
147145 } __packed;
148146
149147 /**
150− * struct prcm_gpio_altcx_pin_desc - Other alternate-C pin
148+ * struct prcm_gpiocr_altcx_pin_desc - Other alternate-C pin
151149 * @pin: The pin number
152150 * @altcx: array of other alternate-C[1-4] functions
153151 */
@@ -193,7 +191,7 @@ struct nmk_pingroup { · 39 unmodified lines
193191 * numbering.
194192 * @npins: The number of entries in @pins.
195193 * @functions: The functions supported on this SoC.
196− * @nfunction: The number of entries in @functions.
194+ * @nfunctions: The number of entries in @functions.
197195 * @groups: An array describing all pin groups the pin SoC supports.
198196 * @ngroups: The number of entries in @groups.
199197 * @altcx_pins: The pins that support Other alternate-C function on this SoC
include/linux/timb_gpio.h+3−3
@@ -9,10 +9,10 @@ · 8 unmodified lines
99
1010 /**
1111 * struct timbgpio_platform_data - Platform data of the Timberdale GPIO driver
12− * @gpio_base The number of the first GPIO pin, set to -1 for
12+ * @gpio_base: The number of the first GPIO pin, set to -1 for
1313 * dynamic number allocation.
14− * @nr_pins Number of pins that is supported by the hardware (1-32)
15− * @irq_base If IRQ is supported by the hardware, this is the base
14+ * @nr_pins: Number of pins that is supported by the hardware (1-32)
15+ * @irq_base: If IRQ is supported by the hardware, this is the base
1616 * number of IRQ:s. One IRQ per pin will be used. Set to
1717 * -1 if IRQ:s is not supported.
1818 */