Lines Matching +full:irq +full:- +full:gpios
1 // SPDX-License-Identifier: GPL-2.0
6 #include <linux/irq.h>
26 #include "gpiolib-of.h"
27 #include "gpiolib-acpi.h"
28 #include "gpiolib-cdev.h"
29 #include "gpiolib-sysfs.h"
36 * The GPIO programming interface allows for inlining speed-critical
37 * get/set operations for common cases, so that access to SOC-integrated
38 * GPIOs can sometimes cost only an instruction or two per bit.
54 /* Device and char device-related information */
63 * Number of GPIOs to use for the fast path in set array
93 d->label = label; in desc_set_label()
97 * gpio_to_desc - Convert a GPIO number to its descriptor
112 if (gdev->base <= gpio && in gpio_to_desc()
113 gdev->base + gdev->ngpio > gpio) { in gpio_to_desc()
115 return &gdev->descs[gpio - gdev->base]; in gpio_to_desc()
129 * gpiochip_get_desc - get the GPIO descriptor corresponding to the given
135 * A pointer to the GPIO descriptor or ``ERR_PTR(-EINVAL)`` if no GPIO exists
141 struct gpio_device *gdev = gc->gpiodev; in gpiochip_get_desc()
143 if (hwnum >= gdev->ngpio) in gpiochip_get_desc()
144 return ERR_PTR(-EINVAL); in gpiochip_get_desc()
146 return &gdev->descs[hwnum]; in gpiochip_get_desc()
151 * desc_to_gpio - convert a GPIO descriptor to the integer namespace
162 return desc->gdev->base + (desc - &desc->gdev->descs[0]); in desc_to_gpio()
168 * gpiod_to_chip - Return the GPIO chip to which a GPIO descriptor belongs
173 if (!desc || !desc->gdev) in gpiod_to_chip()
175 return desc->gdev->chip; in gpiod_to_chip()
179 /* dynamic allocation of GPIOs, e.g. on a hotplugged device */
183 int base = ARCH_NR_GPIOS - ngpio; in gpiochip_find_base()
187 if (gdev->base + gdev->ngpio <= base) in gpiochip_find_base()
191 base = gdev->base - ngpio; in gpiochip_find_base()
199 return -ENOSPC; in gpiochip_find_base()
204 * gpiod_get_direction - return the current direction of a GPIO
224 if (test_bit(FLAG_OPEN_DRAIN, &desc->flags) && in gpiod_get_direction()
225 test_bit(FLAG_IS_OUT, &desc->flags)) in gpiod_get_direction()
228 if (!gc->get_direction) in gpiod_get_direction()
229 return -ENOTSUPP; in gpiod_get_direction()
231 ret = gc->get_direction(gc, offset); in gpiod_get_direction()
239 assign_bit(FLAG_IS_OUT, &desc->flags, !ret); in gpiod_get_direction()
247 * by range(means [base, base + ngpio - 1]) order.
249 * Return -EBUSY if the new chip overlaps with some other chip's integer
258 list_add_tail(&gdev->list, &gpio_devices); in gpiodev_add_to_list()
263 if (gdev->base + gdev->ngpio <= next->base) { in gpiodev_add_to_list()
265 list_add(&gdev->list, &gpio_devices); in gpiodev_add_to_list()
270 if (prev->base + prev->ngpio <= gdev->base) { in gpiodev_add_to_list()
272 list_add_tail(&gdev->list, &gpio_devices); in gpiodev_add_to_list()
278 if (&next->list == &gpio_devices) in gpiodev_add_to_list()
282 if (prev->base + prev->ngpio <= gdev->base in gpiodev_add_to_list()
283 && gdev->base + gdev->ngpio <= next->base) { in gpiodev_add_to_list()
284 list_add(&gdev->list, &prev->list); in gpiodev_add_to_list()
289 dev_err(&gdev->dev, "GPIO integer space overlap, cannot add chip\n"); in gpiodev_add_to_list()
290 return -EBUSY; in gpiodev_add_to_list()
312 for (i = 0; i != gdev->ngpio; ++i) { in gpio_name_to_desc()
313 struct gpio_desc *desc = &gdev->descs[i]; in gpio_name_to_desc()
315 if (!desc->name) in gpio_name_to_desc()
318 if (!strcmp(desc->name, name)) { in gpio_name_to_desc()
331 * Take the names from gc->names and assign them to their GPIO descriptors.
335 * 1. Non-unique names are still accepted,
340 struct gpio_device *gdev = gc->gpiodev; in gpiochip_set_desc_names()
344 for (i = 0; i != gc->ngpio; ++i) { in gpiochip_set_desc_names()
347 gpio = gpio_name_to_desc(gc->names[i]); in gpiochip_set_desc_names()
349 dev_warn(&gdev->dev, in gpiochip_set_desc_names()
351 gc->names[i]); in gpiochip_set_desc_names()
355 for (i = 0; i != gc->ngpio; ++i) in gpiochip_set_desc_names()
356 gdev->descs[i].name = gc->names[i]; in gpiochip_set_desc_names()
362 * devprop_gpiochip_set_names - Set GPIO line names using device properties
365 * Looks for device property "gpio-line-names" and if it exists assigns
372 struct gpio_device *gdev = chip->gpiodev; in devprop_gpiochip_set_names()
373 struct fwnode_handle *fwnode = dev_fwnode(&gdev->dev); in devprop_gpiochip_set_names()
378 count = fwnode_property_string_array_count(fwnode, "gpio-line-names"); in devprop_gpiochip_set_names()
382 if (count > gdev->ngpio) { in devprop_gpiochip_set_names()
383 dev_warn(&gdev->dev, "gpio-line-names is length %d but should be at most length %d", in devprop_gpiochip_set_names()
384 count, gdev->ngpio); in devprop_gpiochip_set_names()
385 count = gdev->ngpio; in devprop_gpiochip_set_names()
390 return -ENOMEM; in devprop_gpiochip_set_names()
392 ret = fwnode_property_read_string_array(fwnode, "gpio-line-names", in devprop_gpiochip_set_names()
395 dev_warn(&gdev->dev, "failed to read GPIO line names\n"); in devprop_gpiochip_set_names()
401 gdev->descs[i].name = names[i]; in devprop_gpiochip_set_names()
412 p = bitmap_alloc(gc->ngpio, GFP_KERNEL); in gpiochip_allocate_mask()
416 /* Assume by default all GPIOs are valid */ in gpiochip_allocate_mask()
417 bitmap_fill(p, gc->ngpio); in gpiochip_allocate_mask()
424 if (!(of_gpio_need_valid_mask(gc) || gc->init_valid_mask)) in gpiochip_alloc_valid_mask()
427 gc->valid_mask = gpiochip_allocate_mask(gc); in gpiochip_alloc_valid_mask()
428 if (!gc->valid_mask) in gpiochip_alloc_valid_mask()
429 return -ENOMEM; in gpiochip_alloc_valid_mask()
436 if (gc->init_valid_mask) in gpiochip_init_valid_mask()
437 return gc->init_valid_mask(gc, in gpiochip_init_valid_mask()
438 gc->valid_mask, in gpiochip_init_valid_mask()
439 gc->ngpio); in gpiochip_init_valid_mask()
446 bitmap_free(gc->valid_mask); in gpiochip_free_valid_mask()
447 gc->valid_mask = NULL; in gpiochip_free_valid_mask()
452 if (gc->add_pin_ranges) in gpiochip_add_pin_ranges()
453 return gc->add_pin_ranges(gc); in gpiochip_add_pin_ranges()
462 if (likely(!gc->valid_mask)) in gpiochip_line_is_valid()
464 return test_bit(offset, gc->valid_mask); in gpiochip_line_is_valid()
474 list_del(&gdev->list); in gpiodevice_release()
477 ida_free(&gpio_ida, gdev->id); in gpiodevice_release()
478 kfree_const(gdev->label); in gpiodevice_release()
479 kfree(gdev->descs); in gpiodevice_release()
491 #define gcdev_register(gdev, devt) device_add(&(gdev)->dev)
492 #define gcdev_unregister(gdev) device_del(&(gdev)->dev)
508 gdev->dev.release = gpiodevice_release; in gpiochip_setup_dev()
509 dev_dbg(&gdev->dev, "registered GPIOs %d to %d on %s\n", gdev->base, in gpiochip_setup_dev()
510 gdev->base + gdev->ngpio - 1, gdev->chip->label ? : "generic"); in gpiochip_setup_dev()
524 desc = gpiochip_get_desc(gc, hog->chip_hwnum); in gpiochip_machine_hog()
531 if (test_bit(FLAG_IS_HOGGED, &desc->flags)) in gpiochip_machine_hog()
534 rv = gpiod_hog(desc, hog->line_name, hog->lflags, hog->dflags); in gpiochip_machine_hog()
537 __func__, gc->label, hog->chip_hwnum, rv); in gpiochip_machine_hog()
547 if (!strcmp(gc->label, hog->chip_label)) in machine_gpiochip_add()
562 dev_err(&gdev->dev, in gpiochip_setup_devs()
571 struct fwnode_handle *fwnode = gc->parent ? dev_fwnode(gc->parent) : NULL; in gpiochip_add_data_with_key()
575 int base = gc->base; in gpiochip_add_data_with_key()
584 return -ENOMEM; in gpiochip_add_data_with_key()
585 gdev->dev.bus = &gpio_bus_type; in gpiochip_add_data_with_key()
586 gdev->chip = gc; in gpiochip_add_data_with_key()
587 gc->gpiodev = gdev; in gpiochip_add_data_with_key()
588 if (gc->parent) { in gpiochip_add_data_with_key()
589 gdev->dev.parent = gc->parent; in gpiochip_add_data_with_key()
590 gdev->dev.of_node = gc->parent->of_node; in gpiochip_add_data_with_key()
595 if (gc->of_node) in gpiochip_add_data_with_key()
596 gdev->dev.of_node = gc->of_node; in gpiochip_add_data_with_key()
598 gc->of_node = gdev->dev.of_node; in gpiochip_add_data_with_key()
605 gdev->dev.fwnode = dev_fwnode(&gdev->dev) ?: fwnode; in gpiochip_add_data_with_key()
607 gdev->id = ida_alloc(&gpio_ida, GFP_KERNEL); in gpiochip_add_data_with_key()
608 if (gdev->id < 0) { in gpiochip_add_data_with_key()
609 ret = gdev->id; in gpiochip_add_data_with_key()
613 ret = dev_set_name(&gdev->dev, GPIOCHIP_NAME "%d", gdev->id); in gpiochip_add_data_with_key()
617 device_initialize(&gdev->dev); in gpiochip_add_data_with_key()
618 dev_set_drvdata(&gdev->dev, gdev); in gpiochip_add_data_with_key()
619 if (gc->parent && gc->parent->driver) in gpiochip_add_data_with_key()
620 gdev->owner = gc->parent->driver->owner; in gpiochip_add_data_with_key()
621 else if (gc->owner) in gpiochip_add_data_with_key()
622 /* TODO: remove chip->owner */ in gpiochip_add_data_with_key()
623 gdev->owner = gc->owner; in gpiochip_add_data_with_key()
625 gdev->owner = THIS_MODULE; in gpiochip_add_data_with_key()
627 gdev->descs = kcalloc(gc->ngpio, sizeof(gdev->descs[0]), GFP_KERNEL); in gpiochip_add_data_with_key()
628 if (!gdev->descs) { in gpiochip_add_data_with_key()
629 ret = -ENOMEM; in gpiochip_add_data_with_key()
633 if (gc->ngpio == 0) { in gpiochip_add_data_with_key()
635 ret = -EINVAL; in gpiochip_add_data_with_key()
639 if (gc->ngpio > FASTPATH_NGPIO) in gpiochip_add_data_with_key()
641 gc->ngpio, FASTPATH_NGPIO); in gpiochip_add_data_with_key()
643 gdev->label = kstrdup_const(gc->label ?: "unknown", GFP_KERNEL); in gpiochip_add_data_with_key()
644 if (!gdev->label) { in gpiochip_add_data_with_key()
645 ret = -ENOMEM; in gpiochip_add_data_with_key()
649 gdev->ngpio = gc->ngpio; in gpiochip_add_data_with_key()
650 gdev->data = data; in gpiochip_add_data_with_key()
662 base = gpiochip_find_base(gc->ngpio); in gpiochip_add_data_with_key()
674 gc->base = base; in gpiochip_add_data_with_key()
676 gdev->base = base; in gpiochip_add_data_with_key()
684 for (i = 0; i < gc->ngpio; i++) in gpiochip_add_data_with_key()
685 gdev->descs[i].gdev = gdev; in gpiochip_add_data_with_key()
689 BLOCKING_INIT_NOTIFIER_HEAD(&gdev->notifier); in gpiochip_add_data_with_key()
692 INIT_LIST_HEAD(&gdev->pin_ranges); in gpiochip_add_data_with_key()
695 if (gc->names) in gpiochip_add_data_with_key()
714 for (i = 0; i < gc->ngpio; i++) { in gpiochip_add_data_with_key()
715 struct gpio_desc *desc = &gdev->descs[i]; in gpiochip_add_data_with_key()
717 if (gc->get_direction && gpiochip_line_is_valid(gc, i)) { in gpiochip_add_data_with_key()
719 &desc->flags, !gc->get_direction(gc, i)); in gpiochip_add_data_with_key()
722 &desc->flags, !gc->direction_input); in gpiochip_add_data_with_key()
775 list_del(&gdev->list); in gpiochip_add_data_with_key()
778 kfree_const(gdev->label); in gpiochip_add_data_with_key()
780 kfree(gdev->descs); in gpiochip_add_data_with_key()
782 kfree(dev_name(&gdev->dev)); in gpiochip_add_data_with_key()
784 ida_free(&gpio_ida, gdev->id); in gpiochip_add_data_with_key()
787 pr_err("%s: GPIOs %d..%d (%s) failed to register, %d\n", __func__, in gpiochip_add_data_with_key()
788 gdev->base, gdev->base + gdev->ngpio - 1, in gpiochip_add_data_with_key()
789 gc->label ? : "generic", ret); in gpiochip_add_data_with_key()
796 * gpiochip_get_data() - get per-subdriver data for the chip
800 * The per-subdriver data for the chip.
804 return gc->gpiodev->data; in gpiochip_get_data()
809 * gpiochip_remove() - unregister a gpio_chip
812 * A gpio_chip with any GPIOs still requested may not be removed.
816 struct gpio_device *gdev = gc->gpiodev; in gpiochip_remove()
824 gdev->chip = NULL; in gpiochip_remove()
834 gdev->data = NULL; in gpiochip_remove()
837 for (i = 0; i < gdev->ngpio; i++) { in gpiochip_remove()
843 if (i != gdev->ngpio) in gpiochip_remove()
844 dev_crit(&gdev->dev, in gpiochip_remove()
845 "REMOVING GPIOCHIP WITH GPIOS STILL REQUESTED\n"); in gpiochip_remove()
854 put_device(&gdev->dev); in gpiochip_remove()
859 * gpiochip_find() - iterator for locating a specific gpio_chip
865 * 0 if the device doesn't match and non-zero if it does. If the callback is
866 * non-zero, this function will return to the caller and not iterate over any
879 if (gdev->chip && match(gdev->chip, data)) { in gpiochip_find()
880 gc = gdev->chip; in gpiochip_find()
894 return !strcmp(gc->label, name); in gpiochip_match_name()
910 struct gpio_irq_chip *girq = &gc->irq; in gpiochip_irqchip_init_hw()
912 if (!girq->init_hw) in gpiochip_irqchip_init_hw()
915 return girq->init_hw(gc); in gpiochip_irqchip_init_hw()
920 struct gpio_irq_chip *girq = &gc->irq; in gpiochip_irqchip_init_valid_mask()
922 if (!girq->init_valid_mask) in gpiochip_irqchip_init_valid_mask()
925 girq->valid_mask = gpiochip_allocate_mask(gc); in gpiochip_irqchip_init_valid_mask()
926 if (!girq->valid_mask) in gpiochip_irqchip_init_valid_mask()
927 return -ENOMEM; in gpiochip_irqchip_init_valid_mask()
929 girq->init_valid_mask(gc, girq->valid_mask, gc->ngpio); in gpiochip_irqchip_init_valid_mask()
936 bitmap_free(gc->irq.valid_mask); in gpiochip_irqchip_free_valid_mask()
937 gc->irq.valid_mask = NULL; in gpiochip_irqchip_free_valid_mask()
946 if (likely(!gc->irq.valid_mask)) in gpiochip_irqchip_irq_valid()
948 return test_bit(offset, gc->irq.valid_mask); in gpiochip_irqchip_irq_valid()
953 * gpiochip_set_cascaded_irqchip() - connects a cascaded irqchip to a gpiochip
955 * @parent_irq: the irq number corresponding to the parent IRQ for this
957 * @parent_handler: the parent interrupt handler for the accumulated IRQ
965 struct gpio_irq_chip *girq = &gc->irq; in gpiochip_set_cascaded_irqchip()
966 struct device *dev = &gc->gpiodev->dev; in gpiochip_set_cascaded_irqchip()
968 if (!girq->domain) { in gpiochip_set_cascaded_irqchip()
975 if (gc->can_sleep) { in gpiochip_set_cascaded_irqchip()
980 girq->parents = devm_kcalloc(dev, 1, in gpiochip_set_cascaded_irqchip()
981 sizeof(*girq->parents), in gpiochip_set_cascaded_irqchip()
983 if (!girq->parents) { in gpiochip_set_cascaded_irqchip()
984 chip_err(gc, "out of memory allocating parent IRQ\n"); in gpiochip_set_cascaded_irqchip()
987 girq->parents[0] = parent_irq; in gpiochip_set_cascaded_irqchip()
988 girq->num_parents = 1; in gpiochip_set_cascaded_irqchip()
999 * gpiochip_set_nested_irqchip() - connects a nested irqchip to a gpiochip
1002 * @parent_irq: the irq number corresponding to the parent IRQ for this
1016 * gpiochip_set_hierarchical_irqchip() - connects a hierarchical irqchip
1025 /* DT will deal with mapping each IRQ as we go along */ in gpiochip_set_hierarchical_irqchip()
1026 if (is_of_node(gc->irq.fwnode)) in gpiochip_set_hierarchical_irqchip()
1037 if (is_fwnode_irqchip(gc->irq.fwnode)) { in gpiochip_set_hierarchical_irqchip()
1041 for (i = 0; i < gc->ngpio; i++) { in gpiochip_set_hierarchical_irqchip()
1045 struct gpio_irq_chip *girq = &gc->irq; in gpiochip_set_hierarchical_irqchip()
1049 * only to check if the child IRQ is valid or not. in gpiochip_set_hierarchical_irqchip()
1053 ret = girq->child_to_parent_hwirq(gc, i, in gpiochip_set_hierarchical_irqchip()
1058 chip_err(gc, "skip set-up on hwirq %d\n", in gpiochip_set_hierarchical_irqchip()
1063 fwspec.fwnode = gc->irq.fwnode; in gpiochip_set_hierarchical_irqchip()
1065 fwspec.param[0] = girq->child_offset_to_irq(gc, i); in gpiochip_set_hierarchical_irqchip()
1069 ret = __irq_domain_alloc_irqs(gc->irq.domain, in gpiochip_set_hierarchical_irqchip()
1071 -1, in gpiochip_set_hierarchical_irqchip()
1079 "can not allocate irq for GPIO line %d parent hwirq %d in hierarchy domain: %d\n", in gpiochip_set_hierarchical_irqchip()
1097 if (is_of_node(fwspec->fwnode) && fwspec->param_count == 2) { in gpiochip_hierarchy_irq_domain_translate()
1102 if (is_fwnode_irqchip(fwspec->fwnode)) { in gpiochip_hierarchy_irq_domain_translate()
1111 return -EINVAL; in gpiochip_hierarchy_irq_domain_translate()
1115 unsigned int irq, in gpiochip_hierarchy_irq_domain_alloc() argument
1119 struct gpio_chip *gc = d->host_data; in gpiochip_hierarchy_irq_domain_alloc()
1126 struct gpio_irq_chip *girq = &gc->irq; in gpiochip_hierarchy_irq_domain_alloc()
1130 * The nr_irqs parameter is always one except for PCI multi-MSI in gpiochip_hierarchy_irq_domain_alloc()
1135 ret = gc->irq.child_irq_domain_ops.translate(d, fwspec, &hwirq, &type); in gpiochip_hierarchy_irq_domain_alloc()
1139 chip_dbg(gc, "allocate IRQ %d, hwirq %lu\n", irq, hwirq); in gpiochip_hierarchy_irq_domain_alloc()
1141 ret = girq->child_to_parent_hwirq(gc, hwirq, type, in gpiochip_hierarchy_irq_domain_alloc()
1154 irq, in gpiochip_hierarchy_irq_domain_alloc()
1156 gc->irq.chip, in gpiochip_hierarchy_irq_domain_alloc()
1158 girq->handler, in gpiochip_hierarchy_irq_domain_alloc()
1160 irq_set_probe(irq); in gpiochip_hierarchy_irq_domain_alloc()
1163 parent_arg = girq->populate_parent_alloc_arg(gc, parent_hwirq, parent_type); in gpiochip_hierarchy_irq_domain_alloc()
1165 return -ENOMEM; in gpiochip_hierarchy_irq_domain_alloc()
1168 irq, parent_hwirq); in gpiochip_hierarchy_irq_domain_alloc()
1169 irq_set_lockdep_class(irq, gc->irq.lock_key, gc->irq.request_key); in gpiochip_hierarchy_irq_domain_alloc()
1170 ret = irq_domain_alloc_irqs_parent(d, irq, 1, parent_arg); in gpiochip_hierarchy_irq_domain_alloc()
1175 if (irq_domain_is_msi(d->parent) && (ret == -EEXIST)) in gpiochip_hierarchy_irq_domain_alloc()
1194 ops->activate = gpiochip_irq_domain_activate; in gpiochip_hierarchy_setup_domain_ops()
1195 ops->deactivate = gpiochip_irq_domain_deactivate; in gpiochip_hierarchy_setup_domain_ops()
1196 ops->alloc = gpiochip_hierarchy_irq_domain_alloc; in gpiochip_hierarchy_setup_domain_ops()
1197 ops->free = irq_domain_free_irqs_common; in gpiochip_hierarchy_setup_domain_ops()
1204 if (!ops->translate) in gpiochip_hierarchy_setup_domain_ops()
1205 ops->translate = gpiochip_hierarchy_irq_domain_translate; in gpiochip_hierarchy_setup_domain_ops()
1210 if (!gc->irq.child_to_parent_hwirq || in gpiochip_hierarchy_add_domain()
1211 !gc->irq.fwnode) { in gpiochip_hierarchy_add_domain()
1213 return -EINVAL; in gpiochip_hierarchy_add_domain()
1216 if (!gc->irq.child_offset_to_irq) in gpiochip_hierarchy_add_domain()
1217 gc->irq.child_offset_to_irq = gpiochip_child_offset_to_irq_noop; in gpiochip_hierarchy_add_domain()
1219 if (!gc->irq.populate_parent_alloc_arg) in gpiochip_hierarchy_add_domain()
1220 gc->irq.populate_parent_alloc_arg = in gpiochip_hierarchy_add_domain()
1223 gpiochip_hierarchy_setup_domain_ops(&gc->irq.child_irq_domain_ops); in gpiochip_hierarchy_add_domain()
1225 gc->irq.domain = irq_domain_create_hierarchy( in gpiochip_hierarchy_add_domain()
1226 gc->irq.parent_domain, in gpiochip_hierarchy_add_domain()
1228 gc->ngpio, in gpiochip_hierarchy_add_domain()
1229 gc->irq.fwnode, in gpiochip_hierarchy_add_domain()
1230 &gc->irq.child_irq_domain_ops, in gpiochip_hierarchy_add_domain()
1233 if (!gc->irq.domain) in gpiochip_hierarchy_add_domain()
1234 return -ENOMEM; in gpiochip_hierarchy_add_domain()
1236 gpiochip_set_hierarchical_irqchip(gc, gc->irq.chip); in gpiochip_hierarchy_add_domain()
1243 return !!gc->irq.parent_domain; in gpiochip_hierarchy_is_hierarchical()
1256 fwspec->fwnode = gc->irq.parent_domain->fwnode; in gpiochip_populate_parent_fwspec_twocell()
1257 fwspec->param_count = 2; in gpiochip_populate_parent_fwspec_twocell()
1258 fwspec->param[0] = parent_hwirq; in gpiochip_populate_parent_fwspec_twocell()
1259 fwspec->param[1] = parent_type; in gpiochip_populate_parent_fwspec_twocell()
1275 fwspec->fwnode = gc->irq.parent_domain->fwnode; in gpiochip_populate_parent_fwspec_fourcell()
1276 fwspec->param_count = 4; in gpiochip_populate_parent_fwspec_fourcell()
1277 fwspec->param[0] = 0; in gpiochip_populate_parent_fwspec_fourcell()
1278 fwspec->param[1] = parent_hwirq; in gpiochip_populate_parent_fwspec_fourcell()
1279 fwspec->param[2] = 0; in gpiochip_populate_parent_fwspec_fourcell()
1280 fwspec->param[3] = parent_type; in gpiochip_populate_parent_fwspec_fourcell()
1290 return -EINVAL; in gpiochip_hierarchy_add_domain()
1301 * gpiochip_irq_map() - maps an IRQ into a GPIO irqchip
1303 * @irq: the global irq number used by this GPIO irqchip irq
1304 * @hwirq: the local IRQ/GPIO line offset on this gpiochip
1306 * This function will set up the mapping for a certain IRQ line on a
1310 int gpiochip_irq_map(struct irq_domain *d, unsigned int irq, in gpiochip_irq_map() argument
1313 struct gpio_chip *gc = d->host_data; in gpiochip_irq_map()
1317 return -ENXIO; in gpiochip_irq_map()
1319 irq_set_chip_data(irq, gc); in gpiochip_irq_map()
1324 irq_set_lockdep_class(irq, gc->irq.lock_key, gc->irq.request_key); in gpiochip_irq_map()
1325 irq_set_chip_and_handler(irq, gc->irq.chip, gc->irq.handler); in gpiochip_irq_map()
1327 if (gc->irq.threaded) in gpiochip_irq_map()
1328 irq_set_nested_thread(irq, 1); in gpiochip_irq_map()
1329 irq_set_noprobe(irq); in gpiochip_irq_map()
1331 if (gc->irq.num_parents == 1) in gpiochip_irq_map()
1332 ret = irq_set_parent(irq, gc->irq.parents[0]); in gpiochip_irq_map()
1333 else if (gc->irq.map) in gpiochip_irq_map()
1334 ret = irq_set_parent(irq, gc->irq.map[hwirq]); in gpiochip_irq_map()
1340 * No set-up of the hardware will happen if IRQ_TYPE_NONE in gpiochip_irq_map()
1343 if (gc->irq.default_type != IRQ_TYPE_NONE) in gpiochip_irq_map()
1344 irq_set_irq_type(irq, gc->irq.default_type); in gpiochip_irq_map()
1350 void gpiochip_irq_unmap(struct irq_domain *d, unsigned int irq) in gpiochip_irq_unmap() argument
1352 struct gpio_chip *gc = d->host_data; in gpiochip_irq_unmap()
1354 if (gc->irq.threaded) in gpiochip_irq_unmap()
1355 irq_set_nested_thread(irq, 0); in gpiochip_irq_unmap()
1356 irq_set_chip_and_handler(irq, NULL, NULL); in gpiochip_irq_unmap()
1357 irq_set_chip_data(irq, NULL); in gpiochip_irq_unmap()
1374 * gpiochip_irq_domain_activate() - Lock a GPIO to be used as an IRQ
1375 * @domain: The IRQ domain used by this IRQ chip
1376 * @data: Outermost irq_data associated with the IRQ
1381 * for the IRQ domain must be the &struct gpio_chip.
1386 struct gpio_chip *gc = domain->host_data; in gpiochip_irq_domain_activate()
1388 return gpiochip_lock_as_irq(gc, data->hwirq); in gpiochip_irq_domain_activate()
1393 * gpiochip_irq_domain_deactivate() - Unlock a GPIO used as an IRQ
1394 * @domain: The IRQ domain used by this IRQ chip
1395 * @data: Outermost irq_data associated with the IRQ
1399 * host_data for the IRQ domain must be the &struct gpio_chip.
1404 struct gpio_chip *gc = domain->host_data; in gpiochip_irq_domain_deactivate()
1406 return gpiochip_unlock_as_irq(gc, data->hwirq); in gpiochip_irq_domain_deactivate()
1412 struct irq_domain *domain = gc->irq.domain; in gpiochip_to_irq()
1415 return -ENXIO; in gpiochip_to_irq()
1421 spec.fwnode = domain->fwnode; in gpiochip_to_irq()
1423 spec.param[0] = gc->irq.child_offset_to_irq(gc, offset); in gpiochip_to_irq()
1437 return gpiochip_reqres_irq(gc, d->hwirq); in gpiochip_irq_reqres()
1444 gpiochip_relres_irq(gc, d->hwirq); in gpiochip_irq_relres()
1451 if (gc->irq.irq_mask) in gpiochip_irq_mask()
1452 gc->irq.irq_mask(d); in gpiochip_irq_mask()
1453 gpiochip_disable_irq(gc, d->hwirq); in gpiochip_irq_mask()
1460 gpiochip_enable_irq(gc, d->hwirq); in gpiochip_irq_unmask()
1461 if (gc->irq.irq_unmask) in gpiochip_irq_unmask()
1462 gc->irq.irq_unmask(d); in gpiochip_irq_unmask()
1469 gpiochip_enable_irq(gc, d->hwirq); in gpiochip_irq_enable()
1470 gc->irq.irq_enable(d); in gpiochip_irq_enable()
1477 gc->irq.irq_disable(d); in gpiochip_irq_disable()
1478 gpiochip_disable_irq(gc, d->hwirq); in gpiochip_irq_disable()
1483 struct irq_chip *irqchip = gc->irq.chip; in gpiochip_set_irq_hooks()
1485 if (!irqchip->irq_request_resources && in gpiochip_set_irq_hooks()
1486 !irqchip->irq_release_resources) { in gpiochip_set_irq_hooks()
1487 irqchip->irq_request_resources = gpiochip_irq_reqres; in gpiochip_set_irq_hooks()
1488 irqchip->irq_release_resources = gpiochip_irq_relres; in gpiochip_set_irq_hooks()
1490 if (WARN_ON(gc->irq.irq_enable)) in gpiochip_set_irq_hooks()
1493 if (irqchip->irq_enable == gpiochip_irq_enable || in gpiochip_set_irq_hooks()
1494 irqchip->irq_mask == gpiochip_irq_mask) { in gpiochip_set_irq_hooks()
1504 if (irqchip->irq_disable) { in gpiochip_set_irq_hooks()
1505 gc->irq.irq_disable = irqchip->irq_disable; in gpiochip_set_irq_hooks()
1506 irqchip->irq_disable = gpiochip_irq_disable; in gpiochip_set_irq_hooks()
1508 gc->irq.irq_mask = irqchip->irq_mask; in gpiochip_set_irq_hooks()
1509 irqchip->irq_mask = gpiochip_irq_mask; in gpiochip_set_irq_hooks()
1512 if (irqchip->irq_enable) { in gpiochip_set_irq_hooks()
1513 gc->irq.irq_enable = irqchip->irq_enable; in gpiochip_set_irq_hooks()
1514 irqchip->irq_enable = gpiochip_irq_enable; in gpiochip_set_irq_hooks()
1516 gc->irq.irq_unmask = irqchip->irq_unmask; in gpiochip_set_irq_hooks()
1517 irqchip->irq_unmask = gpiochip_irq_unmask; in gpiochip_set_irq_hooks()
1522 * gpiochip_add_irqchip() - adds an IRQ chip to a GPIO chip
1523 * @gc: the GPIO chip to add the IRQ chip to
1524 * @lock_key: lockdep class for IRQ lock
1525 * @request_key: lockdep class for IRQ request
1531 struct irq_chip *irqchip = gc->irq.chip; in gpiochip_add_irqchip()
1540 if (gc->irq.parent_handler && gc->can_sleep) { in gpiochip_add_irqchip()
1542 return -EINVAL; in gpiochip_add_irqchip()
1545 np = gc->gpiodev->dev.of_node; in gpiochip_add_irqchip()
1546 type = gc->irq.default_type; in gpiochip_add_irqchip()
1554 "%s: Ignoring %u default trigger\n", np->full_name, type)) in gpiochip_add_irqchip()
1557 if (has_acpi_companion(gc->parent) && type != IRQ_TYPE_NONE) { in gpiochip_add_irqchip()
1558 acpi_handle_warn(ACPI_HANDLE(gc->parent), in gpiochip_add_irqchip()
1563 gc->to_irq = gpiochip_to_irq; in gpiochip_add_irqchip()
1564 gc->irq.default_type = type; in gpiochip_add_irqchip()
1565 gc->irq.lock_key = lock_key; in gpiochip_add_irqchip()
1566 gc->irq.request_key = request_key; in gpiochip_add_irqchip()
1575 if (gc->irq.domain_ops) in gpiochip_add_irqchip()
1576 ops = gc->irq.domain_ops; in gpiochip_add_irqchip()
1580 gc->irq.domain = irq_domain_add_simple(np, in gpiochip_add_irqchip()
1581 gc->ngpio, in gpiochip_add_irqchip()
1582 gc->irq.first, in gpiochip_add_irqchip()
1584 if (!gc->irq.domain) in gpiochip_add_irqchip()
1585 return -EINVAL; in gpiochip_add_irqchip()
1588 if (gc->irq.parent_handler) { in gpiochip_add_irqchip()
1589 void *data = gc->irq.parent_handler_data ?: gc; in gpiochip_add_irqchip()
1591 for (i = 0; i < gc->irq.num_parents; i++) { in gpiochip_add_irqchip()
1593 * The parent IRQ chip is already using the chip_data in gpiochip_add_irqchip()
1594 * for this IRQ chip, so our callbacks simply use the in gpiochip_add_irqchip()
1597 irq_set_chained_handler_and_data(gc->irq.parents[i], in gpiochip_add_irqchip()
1598 gc->irq.parent_handler, in gpiochip_add_irqchip()
1611 * gpiochip_irqchip_remove() - removes an irqchip added to a gpiochip
1618 struct irq_chip *irqchip = gc->irq.chip; in gpiochip_irqchip_remove()
1623 if (irqchip && gc->irq.parent_handler) { in gpiochip_irqchip_remove()
1624 struct gpio_irq_chip *irq = &gc->irq; in gpiochip_irqchip_remove() local
1627 for (i = 0; i < irq->num_parents; i++) in gpiochip_irqchip_remove()
1628 irq_set_chained_handler_and_data(irq->parents[i], in gpiochip_irqchip_remove()
1632 /* Remove all IRQ mappings and delete the domain */ in gpiochip_irqchip_remove()
1633 if (gc->irq.domain) { in gpiochip_irqchip_remove()
1634 unsigned int irq; in gpiochip_irqchip_remove() local
1636 for (offset = 0; offset < gc->ngpio; offset++) { in gpiochip_irqchip_remove()
1640 irq = irq_find_mapping(gc->irq.domain, offset); in gpiochip_irqchip_remove()
1641 irq_dispose_mapping(irq); in gpiochip_irqchip_remove()
1644 irq_domain_remove(gc->irq.domain); in gpiochip_irqchip_remove()
1648 if (irqchip->irq_request_resources == gpiochip_irq_reqres) { in gpiochip_irqchip_remove()
1649 irqchip->irq_request_resources = NULL; in gpiochip_irqchip_remove()
1650 irqchip->irq_release_resources = NULL; in gpiochip_irqchip_remove()
1652 if (irqchip->irq_enable == gpiochip_irq_enable) { in gpiochip_irqchip_remove()
1653 irqchip->irq_enable = gc->irq.irq_enable; in gpiochip_irqchip_remove()
1654 irqchip->irq_disable = gc->irq.irq_disable; in gpiochip_irqchip_remove()
1657 gc->irq.irq_enable = NULL; in gpiochip_irqchip_remove()
1658 gc->irq.irq_disable = NULL; in gpiochip_irqchip_remove()
1659 gc->irq.chip = NULL; in gpiochip_irqchip_remove()
1665 * gpiochip_irqchip_add_key() - adds an irqchip to a gpiochip
1668 * @first_irq: if not dynamically assigned, the base (first) IRQ to
1670 * @handler: the irq handler to use (often a predefined irq core function)
1674 * @lock_key: lockdep class for IRQ lock
1675 * @request_key: lockdep class for IRQ request
1678 * gpiochip, providing an irq domain to translate the local IRQs to
1683 * in the gpiochip that shall be used by the driver to handle IRQ number
1688 * the pins on the gpiochip can generate a unique IRQ. Everything else
1703 return -EINVAL; in gpiochip_irqchip_add_key()
1705 if (!gc->parent) { in gpiochip_irqchip_add_key()
1707 return -EINVAL; in gpiochip_irqchip_add_key()
1709 gc->irq.threaded = threaded; in gpiochip_irqchip_add_key()
1710 of_node = gc->parent->of_node; in gpiochip_irqchip_add_key()
1714 * FIXME: get rid of this and use gc->parent->of_node in gpiochip_irqchip_add_key()
1717 if (gc->of_node) in gpiochip_irqchip_add_key()
1718 of_node = gc->of_node; in gpiochip_irqchip_add_key()
1722 * used to configure the interrupts, as you may end-up with in gpiochip_irqchip_add_key()
1728 if (has_acpi_companion(gc->parent) && type != IRQ_TYPE_NONE) { in gpiochip_irqchip_add_key()
1729 acpi_handle_warn(ACPI_HANDLE(gc->parent), in gpiochip_irqchip_add_key()
1734 gc->irq.chip = irqchip; in gpiochip_irqchip_add_key()
1735 gc->irq.handler = handler; in gpiochip_irqchip_add_key()
1736 gc->irq.default_type = type; in gpiochip_irqchip_add_key()
1737 gc->to_irq = gpiochip_to_irq; in gpiochip_irqchip_add_key()
1738 gc->irq.lock_key = lock_key; in gpiochip_irqchip_add_key()
1739 gc->irq.request_key = request_key; in gpiochip_irqchip_add_key()
1740 gc->irq.domain = irq_domain_add_simple(of_node, in gpiochip_irqchip_add_key()
1741 gc->ngpio, first_irq, in gpiochip_irqchip_add_key()
1743 if (!gc->irq.domain) { in gpiochip_irqchip_add_key()
1744 gc->irq.chip = NULL; in gpiochip_irqchip_add_key()
1745 return -EINVAL; in gpiochip_irqchip_add_key()
1757 * gpiochip_irqchip_add_domain() - adds an irqdomain to a gpiochip
1761 * This function adds an IRQ domain to the gpiochip.
1767 return -EINVAL; in gpiochip_irqchip_add_domain()
1769 gc->to_irq = gpiochip_to_irq; in gpiochip_irqchip_add_domain()
1770 gc->irq.domain = domain; in gpiochip_irqchip_add_domain()
1801 * gpiochip_generic_request() - request the gpio function for a pin
1808 if (list_empty(&gc->gpiodev->pin_ranges)) in gpiochip_generic_request()
1812 return pinctrl_gpio_request(gc->gpiodev->base + offset); in gpiochip_generic_request()
1817 * gpiochip_generic_free() - free the gpio function from a pin
1824 if (list_empty(&gc->gpiodev->pin_ranges)) in gpiochip_generic_free()
1828 pinctrl_gpio_free(gc->gpiodev->base + offset); in gpiochip_generic_free()
1833 * gpiochip_generic_config() - apply configuration for a pin
1841 return pinctrl_gpio_set_config(gc->gpiodev->base + offset, config); in gpiochip_generic_config()
1848 * gpiochip_add_pingroup_range() - add a range for GPIO <-> pin mapping
1854 * Calling this function directly from a DeviceTree-supported
1857 * bind pinctrl and gpio drivers via the "gpio-ranges" property.
1864 struct gpio_device *gdev = gc->gpiodev; in gpiochip_add_pingroup_range()
1870 return -ENOMEM; in gpiochip_add_pingroup_range()
1874 pin_range->range.id = gpio_offset; in gpiochip_add_pingroup_range()
1875 pin_range->range.gc = gc; in gpiochip_add_pingroup_range()
1876 pin_range->range.name = gc->label; in gpiochip_add_pingroup_range()
1877 pin_range->range.base = gdev->base + gpio_offset; in gpiochip_add_pingroup_range()
1878 pin_range->pctldev = pctldev; in gpiochip_add_pingroup_range()
1881 &pin_range->range.pins, in gpiochip_add_pingroup_range()
1882 &pin_range->range.npins); in gpiochip_add_pingroup_range()
1888 pinctrl_add_gpio_range(pctldev, &pin_range->range); in gpiochip_add_pingroup_range()
1890 chip_dbg(gc, "created GPIO range %d->%d ==> %s PINGRP %s\n", in gpiochip_add_pingroup_range()
1891 gpio_offset, gpio_offset + pin_range->range.npins - 1, in gpiochip_add_pingroup_range()
1894 list_add_tail(&pin_range->node, &gdev->pin_ranges); in gpiochip_add_pingroup_range()
1901 * gpiochip_add_pin_range() - add a range for GPIO <-> pin mapping
1910 * 0 on success, or a negative error-code on failure.
1912 * Calling this function directly from a DeviceTree-supported
1915 * bind pinctrl and gpio drivers via the "gpio-ranges" property.
1922 struct gpio_device *gdev = gc->gpiodev; in gpiochip_add_pin_range()
1928 return -ENOMEM; in gpiochip_add_pin_range()
1932 pin_range->range.id = gpio_offset; in gpiochip_add_pin_range()
1933 pin_range->range.gc = gc; in gpiochip_add_pin_range()
1934 pin_range->range.name = gc->label; in gpiochip_add_pin_range()
1935 pin_range->range.base = gdev->base + gpio_offset; in gpiochip_add_pin_range()
1936 pin_range->range.pin_base = pin_offset; in gpiochip_add_pin_range()
1937 pin_range->range.npins = npins; in gpiochip_add_pin_range()
1938 pin_range->pctldev = pinctrl_find_and_add_gpio_range(pinctl_name, in gpiochip_add_pin_range()
1939 &pin_range->range); in gpiochip_add_pin_range()
1940 if (IS_ERR(pin_range->pctldev)) { in gpiochip_add_pin_range()
1941 ret = PTR_ERR(pin_range->pctldev); in gpiochip_add_pin_range()
1946 chip_dbg(gc, "created GPIO range %d->%d ==> %s PIN %d->%d\n", in gpiochip_add_pin_range()
1947 gpio_offset, gpio_offset + npins - 1, in gpiochip_add_pin_range()
1949 pin_offset, pin_offset + npins - 1); in gpiochip_add_pin_range()
1951 list_add_tail(&pin_range->node, &gdev->pin_ranges); in gpiochip_add_pin_range()
1958 * gpiochip_remove_pin_ranges() - remove all the GPIO <-> pin mappings
1964 struct gpio_device *gdev = gc->gpiodev; in gpiochip_remove_pin_ranges()
1966 list_for_each_entry_safe(pin_range, tmp, &gdev->pin_ranges, node) { in gpiochip_remove_pin_ranges()
1967 list_del(&pin_range->node); in gpiochip_remove_pin_ranges()
1968 pinctrl_remove_gpio_range(pin_range->pctldev, in gpiochip_remove_pin_ranges()
1969 &pin_range->range); in gpiochip_remove_pin_ranges()
1983 struct gpio_chip *gc = desc->gdev->chip; in gpiod_request_commit()
1991 return -ENOMEM; in gpiod_request_commit()
1997 * before IRQs are enabled, for non-sleeping (SOC) GPIOs. in gpiod_request_commit()
2000 if (test_and_set_bit(FLAG_REQUESTED, &desc->flags) == 0) { in gpiod_request_commit()
2005 ret = -EBUSY; in gpiod_request_commit()
2009 if (gc->request) { in gpiod_request_commit()
2010 /* gc->request may sleep */ in gpiod_request_commit()
2014 ret = gc->request(gc, offset); in gpiod_request_commit()
2016 ret = -EINVAL; in gpiod_request_commit()
2022 clear_bit(FLAG_REQUESTED, &desc->flags); in gpiod_request_commit()
2026 if (gc->get_direction) { in gpiod_request_commit()
2027 /* gc->get_direction may sleep */ in gpiod_request_commit()
2051 if (!desc->gdev) { in validate_desc()
2053 return -EINVAL; in validate_desc()
2055 if (!desc->gdev->chip) { in validate_desc()
2056 dev_warn(&desc->gdev->dev, in validate_desc()
2077 int ret = -EPROBE_DEFER; in gpiod_request()
2081 gdev = desc->gdev; in gpiod_request()
2083 if (try_module_get(gdev->owner)) { in gpiod_request()
2086 module_put(gdev->owner); in gpiod_request()
2088 get_device(&gdev->dev); in gpiod_request()
2109 gc = desc->gdev->chip; in gpiod_free_commit()
2110 if (gc && test_bit(FLAG_REQUESTED, &desc->flags)) { in gpiod_free_commit()
2111 if (gc->free) { in gpiod_free_commit()
2113 might_sleep_if(gc->can_sleep); in gpiod_free_commit()
2114 gc->free(gc, gpio_chip_hwgpio(desc)); in gpiod_free_commit()
2117 kfree_const(desc->label); in gpiod_free_commit()
2119 clear_bit(FLAG_ACTIVE_LOW, &desc->flags); in gpiod_free_commit()
2120 clear_bit(FLAG_REQUESTED, &desc->flags); in gpiod_free_commit()
2121 clear_bit(FLAG_OPEN_DRAIN, &desc->flags); in gpiod_free_commit()
2122 clear_bit(FLAG_OPEN_SOURCE, &desc->flags); in gpiod_free_commit()
2123 clear_bit(FLAG_PULL_UP, &desc->flags); in gpiod_free_commit()
2124 clear_bit(FLAG_PULL_DOWN, &desc->flags); in gpiod_free_commit()
2125 clear_bit(FLAG_BIAS_DISABLE, &desc->flags); in gpiod_free_commit()
2126 clear_bit(FLAG_EDGE_RISING, &desc->flags); in gpiod_free_commit()
2127 clear_bit(FLAG_EDGE_FALLING, &desc->flags); in gpiod_free_commit()
2128 clear_bit(FLAG_IS_HOGGED, &desc->flags); in gpiod_free_commit()
2130 desc->hog = NULL; in gpiod_free_commit()
2133 WRITE_ONCE(desc->debounce_period_us, 0); in gpiod_free_commit()
2139 blocking_notifier_call_chain(&desc->gdev->notifier, in gpiod_free_commit()
2147 if (desc && desc->gdev && gpiod_free_commit(desc)) { in gpiod_free()
2148 module_put(desc->gdev->owner); in gpiod_free()
2149 put_device(&desc->gdev->dev); in gpiod_free()
2156 * gpiochip_is_requested - return string iff signal was requested
2158 * @offset: of signal within controller's 0..(ngpio - 1) range
2162 * passed it is a meaningless, non-NULL constant.
2172 if (offset >= gc->ngpio) in gpiochip_is_requested()
2179 if (test_bit(FLAG_REQUESTED, &desc->flags) == 0) in gpiochip_is_requested()
2181 return desc->label; in gpiochip_is_requested()
2186 * gpiochip_request_own_desc - Allow GPIO chip to request its own descriptor
2200 * GPIO chip driver handles freeing the GPIOs it has requested).
2203 * A pointer to the GPIO descriptor, or an ERR_PTR()-encoded negative error
2236 * gpiochip_free_own_desc - Free GPIO requested by the chip driver
2254 * using the open-drain emulation idiom) so these are natural places
2262 if (!gc->set_config) in gpio_do_set_config()
2263 return -ENOTSUPP; in gpio_do_set_config()
2265 return gc->set_config(gc, offset, config); in gpio_do_set_config()
2270 struct gpio_chip *gc = desc->gdev->chip; in gpio_set_config()
2293 if (test_bit(FLAG_BIAS_DISABLE, &desc->flags)) in gpio_set_bias()
2295 else if (test_bit(FLAG_PULL_UP, &desc->flags)) in gpio_set_bias()
2297 else if (test_bit(FLAG_PULL_DOWN, &desc->flags)) in gpio_set_bias()
2302 if (ret != -ENOTSUPP) in gpio_set_bias()
2309 * gpiod_direction_input - set the GPIO direction to input
2323 gc = desc->gdev->chip; in gpiod_direction_input()
2327 * the chip is output-only, but you can't specify .direction_input() in gpiod_direction_input()
2330 if (!gc->get && gc->direction_input) { in gpiod_direction_input()
2334 return -EIO; in gpiod_direction_input()
2339 * just call it. Else we are some input-only chip so try to check the in gpiod_direction_input()
2343 if (gc->direction_input) { in gpiod_direction_input()
2344 ret = gc->direction_input(gc, gpio_chip_hwgpio(desc)); in gpiod_direction_input()
2345 } else if (gc->get_direction && in gpiod_direction_input()
2346 (gc->get_direction(gc, gpio_chip_hwgpio(desc)) != 1)) { in gpiod_direction_input()
2350 return -EIO; in gpiod_direction_input()
2353 clear_bit(FLAG_IS_OUT, &desc->flags); in gpiod_direction_input()
2365 struct gpio_chip *gc = desc->gdev->chip; in gpiod_direction_output_raw_commit()
2371 * output-only, but if there is then not even a .set() operation it in gpiod_direction_output_raw_commit()
2374 if (!gc->set && !gc->direction_output) { in gpiod_direction_output_raw_commit()
2378 return -EIO; in gpiod_direction_output_raw_commit()
2381 if (gc->direction_output) { in gpiod_direction_output_raw_commit()
2382 ret = gc->direction_output(gc, gpio_chip_hwgpio(desc), val); in gpiod_direction_output_raw_commit()
2385 if (gc->get_direction && in gpiod_direction_output_raw_commit()
2386 gc->get_direction(gc, gpio_chip_hwgpio(desc))) { in gpiod_direction_output_raw_commit()
2390 return -EIO; in gpiod_direction_output_raw_commit()
2394 * output-only chip, so just drive the output as desired. in gpiod_direction_output_raw_commit()
2396 gc->set(gc, gpio_chip_hwgpio(desc), val); in gpiod_direction_output_raw_commit()
2400 set_bit(FLAG_IS_OUT, &desc->flags); in gpiod_direction_output_raw_commit()
2407 * gpiod_direction_output_raw - set the GPIO direction to output
2425 * gpiod_direction_output - set the GPIO direction to output
2441 if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) in gpiod_direction_output()
2446 /* GPIOs used for enabled IRQs shall not be set as output */ in gpiod_direction_output()
2447 if (test_bit(FLAG_USED_AS_IRQ, &desc->flags) && in gpiod_direction_output()
2448 test_bit(FLAG_IRQ_IS_ENABLED, &desc->flags)) { in gpiod_direction_output()
2450 "%s: tried to set a GPIO tied to an IRQ as output\n", in gpiod_direction_output()
2452 return -EIO; in gpiod_direction_output()
2455 if (test_bit(FLAG_OPEN_DRAIN, &desc->flags)) { in gpiod_direction_output()
2466 else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) { in gpiod_direction_output()
2487 * When emulating open-source or open-drain functionalities by not in gpiod_direction_output()
2493 set_bit(FLAG_IS_OUT, &desc->flags); in gpiod_direction_output()
2499 * gpiod_set_config - sets @config for a GPIO
2504 * 0 on success, %-ENOTSUPP if the controller doesn't support setting the
2512 gc = desc->gdev->chip; in gpiod_set_config()
2519 * gpiod_set_debounce - sets @debounce time for a GPIO
2524 * 0 on success, %-ENOTSUPP if the controller doesn't support setting the
2537 * gpiod_set_transitory - Lose or retain GPIO state on suspend or reset
2556 assign_bit(FLAG_TRANSITORY, &desc->flags, transitory); in gpiod_set_transitory()
2559 gc = desc->gdev->chip; in gpiod_set_transitory()
2560 if (!gc->set_config) in gpiod_set_transitory()
2567 if (rc == -ENOTSUPP) { in gpiod_set_transitory()
2568 dev_dbg(&desc->gdev->dev, "Persistence not supported for GPIO %d\n", in gpiod_set_transitory()
2578 * gpiod_is_active_low - test whether a GPIO is active-low or not
2581 * Returns 1 if the GPIO is active-low, 0 otherwise.
2586 return test_bit(FLAG_ACTIVE_LOW, &desc->flags); in gpiod_is_active_low()
2591 * gpiod_toggle_active_low - toggle whether a GPIO is active-low or not
2597 change_bit(FLAG_ACTIVE_LOW, &desc->flags); in gpiod_toggle_active_low()
2611 *------------------------------------------------------------------------
2613 * IMPORTANT!!! The hot paths -- get/set value -- assume that callers
2629 gc = desc->gdev->chip; in gpiod_get_raw_value_commit()
2631 value = gc->get ? gc->get(gc, offset) : -EIO; in gpiod_get_raw_value_commit()
2640 if (gc->get_multiple) { in gpio_chip_get_multiple()
2641 return gc->get_multiple(gc, mask, bits); in gpio_chip_get_multiple()
2642 } else if (gc->get) { in gpio_chip_get_multiple()
2645 for_each_set_bit(i, mask, gc->ngpio) { in gpio_chip_get_multiple()
2646 value = gc->get(gc, i); in gpio_chip_get_multiple()
2653 return -EIO; in gpio_chip_get_multiple()
2669 if (array_info && array_info->desc == desc_array && in gpiod_get_array_value_complex()
2670 array_size <= array_info->size && in gpiod_get_array_value_complex()
2671 (void *)array_info == desc_array + array_info->size) { in gpiod_get_array_value_complex()
2673 WARN_ON(array_info->chip->can_sleep); in gpiod_get_array_value_complex()
2675 ret = gpio_chip_get_multiple(array_info->chip, in gpiod_get_array_value_complex()
2676 array_info->get_mask, in gpiod_get_array_value_complex()
2681 if (!raw && !bitmap_empty(array_info->invert_mask, array_size)) in gpiod_get_array_value_complex()
2683 array_info->invert_mask, array_size); in gpiod_get_array_value_complex()
2685 i = find_first_zero_bit(array_info->get_mask, array_size); in gpiod_get_array_value_complex()
2693 struct gpio_chip *gc = desc_array[i]->gdev->chip; in gpiod_get_array_value_complex()
2698 if (likely(gc->ngpio <= FASTPATH_NGPIO)) { in gpiod_get_array_value_complex()
2701 mask = kmalloc_array(2 * BITS_TO_LONGS(gc->ngpio), in gpiod_get_array_value_complex()
2705 return -ENOMEM; in gpiod_get_array_value_complex()
2708 bits = mask + BITS_TO_LONGS(gc->ngpio); in gpiod_get_array_value_complex()
2709 bitmap_zero(mask, gc->ngpio); in gpiod_get_array_value_complex()
2712 WARN_ON(gc->can_sleep); in gpiod_get_array_value_complex()
2724 i = find_next_zero_bit(array_info->get_mask, in gpiod_get_array_value_complex()
2727 (desc_array[i]->gdev->chip == gc)); in gpiod_get_array_value_complex()
2741 if (!raw && test_bit(FLAG_ACTIVE_LOW, &desc->flags)) in gpiod_get_array_value_complex()
2748 j = find_next_zero_bit(array_info->get_mask, i, in gpiod_get_array_value_complex()
2759 * gpiod_get_raw_value() - return a gpio's raw value
2772 WARN_ON(desc->gdev->chip->can_sleep); in gpiod_get_raw_value()
2778 * gpiod_get_value() - return a gpio's value
2793 WARN_ON(desc->gdev->chip->can_sleep); in gpiod_get_value()
2799 if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) in gpiod_get_value()
2807 * gpiod_get_raw_array_value() - read raw values from an array of GPIOs
2813 * Read the raw values of the GPIOs, i.e. the values of the physical lines
2826 return -EINVAL; in gpiod_get_raw_array_value()
2834 * gpiod_get_array_value() - read values from an array of GPIOs
2840 * Read the logical values of the GPIOs, i.e. taking their ACTIVE_LOW status
2852 return -EINVAL; in gpiod_get_array_value()
2860 * gpio_set_open_drain_value_commit() - Set the open drain gpio's value.
2862 * @value: Non-zero for setting it HIGH otherwise it will set to LOW.
2867 struct gpio_chip *gc = desc->gdev->chip; in gpio_set_open_drain_value_commit()
2871 ret = gc->direction_input(gc, offset); in gpio_set_open_drain_value_commit()
2873 ret = gc->direction_output(gc, offset, 0); in gpio_set_open_drain_value_commit()
2875 set_bit(FLAG_IS_OUT, &desc->flags); in gpio_set_open_drain_value_commit()
2885 * _gpio_set_open_source_value() - Set the open source gpio's value.
2887 * @value: Non-zero for setting it HIGH otherwise it will set to LOW.
2892 struct gpio_chip *gc = desc->gdev->chip; in gpio_set_open_source_value_commit()
2896 ret = gc->direction_output(gc, offset, 1); in gpio_set_open_source_value_commit()
2898 set_bit(FLAG_IS_OUT, &desc->flags); in gpio_set_open_source_value_commit()
2900 ret = gc->direction_input(gc, offset); in gpio_set_open_source_value_commit()
2913 gc = desc->gdev->chip; in gpiod_set_raw_value_commit()
2915 gc->set(gc, gpio_chip_hwgpio(desc), value); in gpiod_set_raw_value_commit()
2931 if (gc->set_multiple) { in gpio_chip_set_multiple()
2932 gc->set_multiple(gc, mask, bits); in gpio_chip_set_multiple()
2937 for_each_set_bit(i, mask, gc->ngpio) in gpio_chip_set_multiple()
2938 gc->set(gc, i, test_bit(i, bits)); in gpio_chip_set_multiple()
2955 if (array_info && array_info->desc == desc_array && in gpiod_set_array_value_complex()
2956 array_size <= array_info->size && in gpiod_set_array_value_complex()
2957 (void *)array_info == desc_array + array_info->size) { in gpiod_set_array_value_complex()
2959 WARN_ON(array_info->chip->can_sleep); in gpiod_set_array_value_complex()
2961 if (!raw && !bitmap_empty(array_info->invert_mask, array_size)) in gpiod_set_array_value_complex()
2963 array_info->invert_mask, array_size); in gpiod_set_array_value_complex()
2965 gpio_chip_set_multiple(array_info->chip, array_info->set_mask, in gpiod_set_array_value_complex()
2968 i = find_first_zero_bit(array_info->set_mask, array_size); in gpiod_set_array_value_complex()
2976 struct gpio_chip *gc = desc_array[i]->gdev->chip; in gpiod_set_array_value_complex()
2981 if (likely(gc->ngpio <= FASTPATH_NGPIO)) { in gpiod_set_array_value_complex()
2984 mask = kmalloc_array(2 * BITS_TO_LONGS(gc->ngpio), in gpiod_set_array_value_complex()
2988 return -ENOMEM; in gpiod_set_array_value_complex()
2991 bits = mask + BITS_TO_LONGS(gc->ngpio); in gpiod_set_array_value_complex()
2992 bitmap_zero(mask, gc->ngpio); in gpiod_set_array_value_complex()
2995 WARN_ON(gc->can_sleep); in gpiod_set_array_value_complex()
3008 test_bit(i, array_info->invert_mask)) && in gpiod_set_array_value_complex()
3009 test_bit(FLAG_ACTIVE_LOW, &desc->flags)) in gpiod_set_array_value_complex()
3016 if (test_bit(FLAG_OPEN_DRAIN, &desc->flags) && !raw) { in gpiod_set_array_value_complex()
3018 } else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags) && !raw) { in gpiod_set_array_value_complex()
3028 i = find_next_zero_bit(array_info->set_mask, in gpiod_set_array_value_complex()
3031 (desc_array[i]->gdev->chip == gc)); in gpiod_set_array_value_complex()
3043 * gpiod_set_raw_value() - assign a gpio's raw value
3057 WARN_ON(desc->gdev->chip->can_sleep); in gpiod_set_raw_value()
3063 * gpiod_set_value_nocheck() - set a GPIO line value without checking
3073 if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) in gpiod_set_value_nocheck()
3075 if (test_bit(FLAG_OPEN_DRAIN, &desc->flags)) in gpiod_set_value_nocheck()
3077 else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) in gpiod_set_value_nocheck()
3084 * gpiod_set_value() - assign a gpio's value
3098 WARN_ON(desc->gdev->chip->can_sleep); in gpiod_set_value()
3104 * gpiod_set_raw_array_value() - assign values to an array of GPIOs
3110 * Set the raw values of the GPIOs, i.e. the values of the physical lines
3122 return -EINVAL; in gpiod_set_raw_array_value()
3129 * gpiod_set_array_value() - assign values to an array of GPIOs
3135 * Set the logical values of the GPIOs, i.e. taking their ACTIVE_LOW status
3147 return -EINVAL; in gpiod_set_array_value()
3155 * gpiod_cansleep() - report whether gpio value access may sleep
3162 return desc->gdev->chip->can_sleep; in gpiod_cansleep()
3167 * gpiod_set_consumer_name() - set the consumer name for the descriptor
3177 return -ENOMEM; in gpiod_set_consumer_name()
3180 kfree_const(desc->label); in gpiod_set_consumer_name()
3188 * gpiod_to_irq() - return the IRQ corresponding to a GPIO
3189 * @desc: gpio whose IRQ will be returned (already requested)
3191 * Return the IRQ corresponding to the passed GPIO, or an error code in case of
3204 if (!desc || IS_ERR(desc) || !desc->gdev || !desc->gdev->chip) in gpiod_to_irq()
3205 return -EINVAL; in gpiod_to_irq()
3207 gc = desc->gdev->chip; in gpiod_to_irq()
3209 if (gc->to_irq) { in gpiod_to_irq()
3210 int retirq = gc->to_irq(gc, offset); in gpiod_to_irq()
3214 return -ENXIO; in gpiod_to_irq()
3218 return -ENXIO; in gpiod_to_irq()
3223 * gpiochip_lock_as_irq() - lock a GPIO to be used as IRQ
3225 * @offset: the offset of the GPIO to lock as IRQ
3242 if (!gc->can_sleep && gc->get_direction) { in gpiochip_lock_as_irq()
3252 /* To be valid for IRQ the line needs to be input or open drain */ in gpiochip_lock_as_irq()
3253 if (test_bit(FLAG_IS_OUT, &desc->flags) && in gpiochip_lock_as_irq()
3254 !test_bit(FLAG_OPEN_DRAIN, &desc->flags)) { in gpiochip_lock_as_irq()
3256 "%s: tried to flag a GPIO set as output for IRQ\n", in gpiochip_lock_as_irq()
3258 return -EIO; in gpiochip_lock_as_irq()
3261 set_bit(FLAG_USED_AS_IRQ, &desc->flags); in gpiochip_lock_as_irq()
3262 set_bit(FLAG_IRQ_IS_ENABLED, &desc->flags); in gpiochip_lock_as_irq()
3266 * IRQ is referenced from .to_irq()) we set up a label here in gpiochip_lock_as_irq()
3269 if (!desc->label) in gpiochip_lock_as_irq()
3277 * gpiochip_unlock_as_irq() - unlock a GPIO used as IRQ
3279 * @offset: the offset of the GPIO to lock as IRQ
3282 * that a certain GPIO is no longer used exclusively for IRQ.
3292 clear_bit(FLAG_USED_AS_IRQ, &desc->flags); in gpiochip_unlock_as_irq()
3293 clear_bit(FLAG_IRQ_IS_ENABLED, &desc->flags); in gpiochip_unlock_as_irq()
3296 if (desc->label && !strcmp(desc->label, "interrupt")) in gpiochip_unlock_as_irq()
3306 !WARN_ON(!test_bit(FLAG_USED_AS_IRQ, &desc->flags))) in gpiochip_disable_irq()
3307 clear_bit(FLAG_IRQ_IS_ENABLED, &desc->flags); in gpiochip_disable_irq()
3316 !WARN_ON(!test_bit(FLAG_USED_AS_IRQ, &desc->flags))) { in gpiochip_enable_irq()
3318 * We must not be output when using IRQ UNLESS we are in gpiochip_enable_irq()
3321 WARN_ON(test_bit(FLAG_IS_OUT, &desc->flags) && in gpiochip_enable_irq()
3322 !test_bit(FLAG_OPEN_DRAIN, &desc->flags)); in gpiochip_enable_irq()
3323 set_bit(FLAG_IRQ_IS_ENABLED, &desc->flags); in gpiochip_enable_irq()
3330 if (offset >= gc->ngpio) in gpiochip_line_is_irq()
3333 return test_bit(FLAG_USED_AS_IRQ, &gc->gpiodev->descs[offset].flags); in gpiochip_line_is_irq()
3341 if (!try_module_get(gc->gpiodev->owner)) in gpiochip_reqres_irq()
3342 return -ENODEV; in gpiochip_reqres_irq()
3346 chip_err(gc, "unable to lock HW IRQ %u for IRQ\n", offset); in gpiochip_reqres_irq()
3347 module_put(gc->gpiodev->owner); in gpiochip_reqres_irq()
3357 module_put(gc->gpiodev->owner); in gpiochip_relres_irq()
3363 if (offset >= gc->ngpio) in gpiochip_line_is_open_drain()
3366 return test_bit(FLAG_OPEN_DRAIN, &gc->gpiodev->descs[offset].flags); in gpiochip_line_is_open_drain()
3372 if (offset >= gc->ngpio) in gpiochip_line_is_open_source()
3375 return test_bit(FLAG_OPEN_SOURCE, &gc->gpiodev->descs[offset].flags); in gpiochip_line_is_open_source()
3381 if (offset >= gc->ngpio) in gpiochip_line_is_persistent()
3384 return !test_bit(FLAG_TRANSITORY, &gc->gpiodev->descs[offset].flags); in gpiochip_line_is_persistent()
3389 * gpiod_get_raw_value_cansleep() - return a gpio's raw value
3406 * gpiod_get_value_cansleep() - return a gpio's value
3424 if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) in gpiod_get_value_cansleep()
3432 * gpiod_get_raw_array_value_cansleep() - read raw values from an array of GPIOs
3438 * Read the raw values of the GPIOs, i.e. the values of the physical lines
3451 return -EINVAL; in gpiod_get_raw_array_value_cansleep()
3459 * gpiod_get_array_value_cansleep() - read values from an array of GPIOs
3465 * Read the logical values of the GPIOs, i.e. taking their ACTIVE_LOW status
3477 return -EINVAL; in gpiod_get_array_value_cansleep()
3485 * gpiod_set_raw_value_cansleep() - assign a gpio's raw value
3503 * gpiod_set_value_cansleep() - assign a gpio's value
3521 * gpiod_set_raw_array_value_cansleep() - assign values to an array of GPIOs
3527 * Set the raw values of the GPIOs, i.e. the values of the physical lines
3539 return -EINVAL; in gpiod_set_raw_array_value_cansleep()
3546 * gpiod_add_lookup_tables() - register GPIO device consumers
3557 list_add_tail(&tables[i]->list, &gpio_lookup_list); in gpiod_add_lookup_tables()
3563 * gpiod_set_array_value_cansleep() - assign values to an array of GPIOs
3569 * Set the logical values of the GPIOs, i.e. taking their ACTIVE_LOW status
3581 return -EINVAL; in gpiod_set_array_value_cansleep()
3589 * gpiod_add_lookup_table() - register GPIO device consumers
3596 list_add_tail(&table->list, &gpio_lookup_list); in gpiod_add_lookup_table()
3603 * gpiod_remove_lookup_table() - unregister GPIO device consumers
3610 list_del(&table->list); in gpiod_remove_lookup_table()
3617 * gpiod_add_hogs() - register a set of GPIO hogs from machine code
3627 for (hog = &hogs[0]; hog->chip_label; hog++) { in gpiod_add_hogs()
3628 list_add_tail(&hog->list, &gpio_machine_hogs); in gpiod_add_hogs()
3634 gc = find_chip_by_name(hog->chip_label); in gpiod_add_hogs()
3651 if (table->dev_id && dev_id) { in gpiod_find_lookup_table()
3656 if (!strcmp(table->dev_id, dev_id)) in gpiod_find_lookup_table()
3663 if (dev_id == table->dev_id) in gpiod_find_lookup_table()
3677 struct gpio_desc *desc = ERR_PTR(-ENOENT); in gpiod_find()
3685 for (p = &table->table[0]; p->key; p++) { in gpiod_find()
3689 if (p->idx != idx) in gpiod_find()
3693 if (p->con_id && (!con_id || strcmp(p->con_id, con_id))) in gpiod_find()
3696 if (p->chip_hwnum == U16_MAX) { in gpiod_find()
3697 desc = gpio_name_to_desc(p->key); in gpiod_find()
3699 *flags = p->flags; in gpiod_find()
3704 p->key); in gpiod_find()
3705 return ERR_PTR(-EPROBE_DEFER); in gpiod_find()
3708 gc = find_chip_by_name(p->key); in gpiod_find()
3713 * p->key should exist, assume it may in gpiod_find()
3719 p->key); in gpiod_find()
3720 return ERR_PTR(-EPROBE_DEFER); in gpiod_find()
3723 if (gc->ngpio <= p->chip_hwnum) { in gpiod_find()
3726 idx, p->chip_hwnum, gc->ngpio - 1, in gpiod_find()
3727 gc->label); in gpiod_find()
3728 return ERR_PTR(-EINVAL); in gpiod_find()
3731 desc = gpiochip_get_desc(gc, p->chip_hwnum); in gpiod_find()
3732 *flags = p->flags; in gpiod_find()
3748 return -ENOENT; in platform_gpio_count()
3750 for (p = &table->table[0]; p->key; p++) { in platform_gpio_count()
3751 if ((con_id && p->con_id && !strcmp(con_id, p->con_id)) || in platform_gpio_count()
3752 (!con_id && !p->con_id)) in platform_gpio_count()
3756 return -ENOENT; in platform_gpio_count()
3762 * fwnode_gpiod_get_index - obtain a GPIO from firmware node
3793 snprintf(prop_name, sizeof(prop_name), "%s-%s", in fwnode_gpiod_get_index()
3801 if (!IS_ERR(desc) || (PTR_ERR(desc) != -ENOENT)) in fwnode_gpiod_get_index()
3810 * gpiod_count - return the number of GPIOs associated with a device / function
3811 * or -ENOENT if no GPIO has been assigned to the requested function
3812 * @dev: GPIO consumer, can be NULL for system-global GPIOs
3817 int count = -ENOENT; in gpiod_count()
3819 if (IS_ENABLED(CONFIG_OF) && dev && dev->of_node) in gpiod_count()
3832 * gpiod_get - obtain a GPIO for a given GPIO function
3833 * @dev: GPIO consumer, can be NULL for system-global GPIOs
3838 * dev, -ENOENT if no GPIO has been assigned to the requested function, or
3849 * gpiod_get_optional - obtain an optional GPIO for a given GPIO function
3850 * @dev: GPIO consumer, can be NULL for system-global GPIOs
3856 * that need to handle optional GPIOs.
3868 * gpiod_configure_flags - helper function to configure a given GPIO
3871 * @lflags: bitmask of gpio_lookup_flags GPIO_* values - returned from
3873 * @dflags: gpiod_flags - optional GPIO initialization flags
3875 * Return 0 on success, -ENOENT if no GPIO has been assigned to the
3885 set_bit(FLAG_ACTIVE_LOW, &desc->flags); in gpiod_configure_flags()
3888 set_bit(FLAG_OPEN_DRAIN, &desc->flags); in gpiod_configure_flags()
3896 set_bit(FLAG_OPEN_DRAIN, &desc->flags); in gpiod_configure_flags()
3902 set_bit(FLAG_OPEN_SOURCE, &desc->flags); in gpiod_configure_flags()
3906 "both pull-up and pull-down enabled, invalid configuration\n"); in gpiod_configure_flags()
3907 return -EINVAL; in gpiod_configure_flags()
3911 set_bit(FLAG_PULL_UP, &desc->flags); in gpiod_configure_flags()
3913 set_bit(FLAG_PULL_DOWN, &desc->flags); in gpiod_configure_flags()
3936 * gpiod_get_index - obtain a GPIO from a multi-index GPIO function
3937 * @dev: GPIO consumer, can be NULL for system-global GPIOs
3942 * This variant of gpiod_get() allows to access GPIOs other than the first
3943 * defined one for functions that define several GPIOs.
3945 * Return a valid GPIO descriptor, -ENOENT if no GPIO has been assigned to the
3964 if (IS_ENABLED(CONFIG_OF) && dev->of_node) { in gpiod_get_index()
3977 if (!desc || desc == ERR_PTR(-ENOENT)) { in gpiod_get_index()
3993 if (ret == -EBUSY && flags & GPIOD_FLAGS_BIT_NONEXCLUSIVE) { in gpiod_get_index()
4017 blocking_notifier_call_chain(&desc->gdev->notifier, in gpiod_get_index()
4025 * fwnode_get_named_gpiod - obtain a GPIO from firmware node
4051 struct gpio_desc *desc = ERR_PTR(-ENODEV); in fwnode_get_named_gpiod()
4055 return ERR_PTR(-EINVAL); in fwnode_get_named_gpiod()
4085 blocking_notifier_call_chain(&desc->gdev->notifier, in fwnode_get_named_gpiod()
4093 * gpiod_get_index_optional - obtain an optional GPIO from a multi-index GPIO
4095 * @dev: GPIO consumer, can be NULL for system-global GPIOs
4102 * This is convenient for drivers that need to handle optional GPIOs.
4113 if (PTR_ERR(desc) == -ENOENT) in gpiod_get_index_optional()
4122 * gpiod_hog - Hog the specified GPIO desc given the provided flags
4125 * @lflags: bitmask of gpio_lookup_flags GPIO_* values - returned from
4127 * @dflags: gpiod_flags - optional GPIO initialization flags
4145 name, gc->label, hwnum, ret); in gpiod_hog()
4150 set_bit(FLAG_IS_HOGGED, &desc->flags); in gpiod_hog()
4161 * gpiochip_free_hogs - Scan gpio-controller chip and release GPIO hog
4168 for (id = 0; id < gc->ngpio; id++) { in gpiochip_free_hogs()
4169 if (test_bit(FLAG_IS_HOGGED, &gc->gpiodev->descs[id].flags)) in gpiochip_free_hogs()
4170 gpiochip_free_own_desc(&gc->gpiodev->descs[id]); in gpiochip_free_hogs()
4175 * gpiod_get_array - obtain multiple GPIOs from a multi-index GPIO function
4176 * @dev: GPIO consumer, can be NULL for system-global GPIOs
4180 * This function acquires all the GPIOs defined under a given function.
4182 * Return a struct gpio_descs containing an array of descriptors, -ENOENT if
4184 * code if an error occurred while trying to acquire the GPIOs.
4202 return ERR_PTR(-ENOMEM); in gpiod_get_array()
4204 for (descs->ndescs = 0; descs->ndescs < count; ) { in gpiod_get_array()
4205 desc = gpiod_get_index(dev, con_id, descs->ndescs, flags); in gpiod_get_array()
4211 descs->desc[descs->ndescs] = desc; in gpiod_get_array()
4218 if (descs->ndescs == 0 && gpio_chip_hwgpio(desc) == 0) { in gpiod_get_array()
4221 bitmap_size = BITS_TO_LONGS(gc->ngpio > count ? in gpiod_get_array()
4222 gc->ngpio : count); in gpiod_get_array()
4229 return ERR_PTR(-ENOMEM); in gpiod_get_array()
4233 struct_size(descs, desc, descs->ndescs + 1)); in gpiod_get_array()
4237 array_info = (void *)(descs->desc + count); in gpiod_get_array()
4238 array_info->get_mask = array_info->invert_mask + in gpiod_get_array()
4240 array_info->set_mask = array_info->get_mask + in gpiod_get_array()
4243 array_info->desc = descs->desc; in gpiod_get_array()
4244 array_info->size = count; in gpiod_get_array()
4245 array_info->chip = gc; in gpiod_get_array()
4246 bitmap_set(array_info->get_mask, descs->ndescs, in gpiod_get_array()
4247 count - descs->ndescs); in gpiod_get_array()
4248 bitmap_set(array_info->set_mask, descs->ndescs, in gpiod_get_array()
4249 count - descs->ndescs); in gpiod_get_array()
4250 descs->info = array_info; in gpiod_get_array()
4253 if (array_info && array_info->chip != gc) { in gpiod_get_array()
4254 __clear_bit(descs->ndescs, array_info->get_mask); in gpiod_get_array()
4255 __clear_bit(descs->ndescs, array_info->set_mask); in gpiod_get_array()
4262 gpio_chip_hwgpio(desc) != descs->ndescs) { in gpiod_get_array()
4268 if (bitmap_full(array_info->get_mask, descs->ndescs)) { in gpiod_get_array()
4271 __clear_bit(descs->ndescs, in gpiod_get_array()
4272 array_info->get_mask); in gpiod_get_array()
4273 __clear_bit(descs->ndescs, in gpiod_get_array()
4274 array_info->set_mask); in gpiod_get_array()
4278 if (gpiochip_line_is_open_drain(gc, descs->ndescs) || in gpiod_get_array()
4279 gpiochip_line_is_open_source(gc, descs->ndescs)) in gpiod_get_array()
4280 __clear_bit(descs->ndescs, in gpiod_get_array()
4281 array_info->set_mask); in gpiod_get_array()
4284 __set_bit(descs->ndescs, in gpiod_get_array()
4285 array_info->invert_mask); in gpiod_get_array()
4288 descs->ndescs++; in gpiod_get_array()
4293 array_info->chip->label, array_info->size, in gpiod_get_array()
4294 *array_info->get_mask, *array_info->set_mask, in gpiod_get_array()
4295 *array_info->invert_mask); in gpiod_get_array()
4301 * gpiod_get_array_optional - obtain multiple GPIOs from a multi-index GPIO
4303 * @dev: GPIO consumer, can be NULL for system-global GPIOs
4317 if (PTR_ERR(descs) == -ENOENT) in gpiod_get_array_optional()
4325 * gpiod_put - dispose of a GPIO descriptor
4338 * gpiod_put_array - dispose of multiple GPIO descriptors
4345 for (i = 0; i < descs->ndescs; i++) in gpiod_put_array()
4346 gpiod_put(descs->desc[i]); in gpiod_put_array()
4386 struct gpio_chip *gc = gdev->chip; in gpiolib_dbg_show()
4387 unsigned gpio = gdev->base; in gpiolib_dbg_show()
4388 struct gpio_desc *gdesc = &gdev->descs[0]; in gpiolib_dbg_show()
4393 for (i = 0; i < gdev->ngpio; i++, gpio++, gdesc++) { in gpiolib_dbg_show()
4394 if (!test_bit(FLAG_REQUESTED, &gdesc->flags)) { in gpiolib_dbg_show()
4395 if (gdesc->name) { in gpiolib_dbg_show()
4396 seq_printf(s, " gpio-%-3d (%-20.20s)\n", in gpiolib_dbg_show()
4397 gpio, gdesc->name); in gpiolib_dbg_show()
4403 is_out = test_bit(FLAG_IS_OUT, &gdesc->flags); in gpiolib_dbg_show()
4404 is_irq = test_bit(FLAG_USED_AS_IRQ, &gdesc->flags); in gpiolib_dbg_show()
4405 active_low = test_bit(FLAG_ACTIVE_LOW, &gdesc->flags); in gpiolib_dbg_show()
4406 seq_printf(s, " gpio-%-3d (%-20.20s|%-20.20s) %s %s %s%s", in gpiolib_dbg_show()
4407 gpio, gdesc->name ? gdesc->name : "", gdesc->label, in gpiolib_dbg_show()
4409 gc->get ? (gc->get(gc, i) ? "hi" : "lo") : "? ", in gpiolib_dbg_show()
4410 is_irq ? "IRQ " : "", in gpiolib_dbg_show()
4422 s->private = ""; in gpiolib_seq_start()
4426 if (index-- == 0) { in gpiolib_seq_start()
4442 if (list_is_last(&gdev->list, &gpio_devices)) in gpiolib_seq_next()
4445 ret = list_entry(gdev->list.next, struct gpio_device, list); in gpiolib_seq_next()
4448 s->private = "\n"; in gpiolib_seq_next()
4461 struct gpio_chip *gc = gdev->chip; in gpiolib_seq_show()
4465 seq_printf(s, "%s%s: (dangling chip)", (char *)s->private, in gpiolib_seq_show()
4466 dev_name(&gdev->dev)); in gpiolib_seq_show()
4470 seq_printf(s, "%s%s: GPIOs %d-%d", (char *)s->private, in gpiolib_seq_show()
4471 dev_name(&gdev->dev), in gpiolib_seq_show()
4472 gdev->base, gdev->base + gdev->ngpio - 1); in gpiolib_seq_show()
4473 parent = gc->parent; in gpiolib_seq_show()
4476 parent->bus ? parent->bus->name : "no-bus", in gpiolib_seq_show()
4478 if (gc->label) in gpiolib_seq_show()
4479 seq_printf(s, ", %s", gc->label); in gpiolib_seq_show()
4480 if (gc->can_sleep) in gpiolib_seq_show()
4484 if (gc->dbg_show) in gpiolib_seq_show()
4485 gc->dbg_show(s, gc); in gpiolib_seq_show()