• Home
  • Raw
  • Download

Lines Matching full:gc

80 static void gpiochip_free_hogs(struct gpio_chip *gc);
81 static int gpiochip_add_irqchip(struct gpio_chip *gc,
84 static void gpiochip_irqchip_remove(struct gpio_chip *gc);
85 static int gpiochip_irqchip_init_hw(struct gpio_chip *gc);
86 static int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gc);
87 static void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gc);
131 * @gc: GPIO chip
138 struct gpio_desc *gpiochip_get_desc(struct gpio_chip *gc, in gpiochip_get_desc() argument
141 struct gpio_device *gdev = gc->gpiodev; in gpiochip_get_desc()
212 struct gpio_chip *gc; in gpiod_get_direction() local
216 gc = gpiod_to_chip(desc); in gpiod_get_direction()
227 if (!gc->get_direction) in gpiod_get_direction()
230 ret = gc->get_direction(gc, offset); in gpiod_get_direction()
330 * Take the names from gc->names and assign them to their GPIO descriptors.
337 static int gpiochip_set_desc_names(struct gpio_chip *gc) in gpiochip_set_desc_names() argument
339 struct gpio_device *gdev = gc->gpiodev; in gpiochip_set_desc_names()
343 for (i = 0; i != gc->ngpio; ++i) { in gpiochip_set_desc_names()
346 gpio = gpio_name_to_desc(gc->names[i]); in gpiochip_set_desc_names()
350 gc->names[i]); in gpiochip_set_desc_names()
354 for (i = 0; i != gc->ngpio; ++i) in gpiochip_set_desc_names()
355 gdev->descs[i].name = gc->names[i]; in gpiochip_set_desc_names()
407 static unsigned long *gpiochip_allocate_mask(struct gpio_chip *gc) in gpiochip_allocate_mask() argument
411 p = bitmap_alloc(gc->ngpio, GFP_KERNEL); in gpiochip_allocate_mask()
416 bitmap_fill(p, gc->ngpio); in gpiochip_allocate_mask()
421 static int gpiochip_alloc_valid_mask(struct gpio_chip *gc) in gpiochip_alloc_valid_mask() argument
423 if (!(of_gpio_need_valid_mask(gc) || gc->init_valid_mask)) in gpiochip_alloc_valid_mask()
426 gc->valid_mask = gpiochip_allocate_mask(gc); in gpiochip_alloc_valid_mask()
427 if (!gc->valid_mask) in gpiochip_alloc_valid_mask()
433 static int gpiochip_init_valid_mask(struct gpio_chip *gc) in gpiochip_init_valid_mask() argument
435 if (gc->init_valid_mask) in gpiochip_init_valid_mask()
436 return gc->init_valid_mask(gc, in gpiochip_init_valid_mask()
437 gc->valid_mask, in gpiochip_init_valid_mask()
438 gc->ngpio); in gpiochip_init_valid_mask()
443 static void gpiochip_free_valid_mask(struct gpio_chip *gc) in gpiochip_free_valid_mask() argument
445 bitmap_free(gc->valid_mask); in gpiochip_free_valid_mask()
446 gc->valid_mask = NULL; in gpiochip_free_valid_mask()
449 static int gpiochip_add_pin_ranges(struct gpio_chip *gc) in gpiochip_add_pin_ranges() argument
451 if (gc->add_pin_ranges) in gpiochip_add_pin_ranges()
452 return gc->add_pin_ranges(gc); in gpiochip_add_pin_ranges()
457 bool gpiochip_line_is_valid(const struct gpio_chip *gc, in gpiochip_line_is_valid() argument
461 if (likely(!gc->valid_mask)) in gpiochip_line_is_valid()
463 return test_bit(offset, gc->valid_mask); in gpiochip_line_is_valid()
518 static void gpiochip_machine_hog(struct gpio_chip *gc, struct gpiod_hog *hog) in gpiochip_machine_hog() argument
523 desc = gpiochip_get_desc(gc, hog->chip_hwnum); in gpiochip_machine_hog()
525 chip_err(gc, "%s: unable to get GPIO desc: %ld\n", __func__, in gpiochip_machine_hog()
536 __func__, gc->label, hog->chip_hwnum, rv); in gpiochip_machine_hog()
539 static void machine_gpiochip_add(struct gpio_chip *gc) in machine_gpiochip_add() argument
546 if (!strcmp(gc->label, hog->chip_label)) in machine_gpiochip_add()
547 gpiochip_machine_hog(gc, hog); in machine_gpiochip_add()
566 int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, in gpiochip_add_data_with_key() argument
570 struct fwnode_handle *fwnode = gc->parent ? dev_fwnode(gc->parent) : NULL; in gpiochip_add_data_with_key()
574 int base = gc->base; in gpiochip_add_data_with_key()
585 gdev->chip = gc; in gpiochip_add_data_with_key()
586 gc->gpiodev = gdev; in gpiochip_add_data_with_key()
587 if (gc->parent) { in gpiochip_add_data_with_key()
588 gdev->dev.parent = gc->parent; in gpiochip_add_data_with_key()
589 gdev->dev.of_node = gc->parent->of_node; in gpiochip_add_data_with_key()
594 if (gc->of_node) in gpiochip_add_data_with_key()
595 gdev->dev.of_node = gc->of_node; in gpiochip_add_data_with_key()
597 gc->of_node = gdev->dev.of_node; in gpiochip_add_data_with_key()
618 if (gc->parent && gc->parent->driver) in gpiochip_add_data_with_key()
619 gdev->owner = gc->parent->driver->owner; in gpiochip_add_data_with_key()
620 else if (gc->owner) in gpiochip_add_data_with_key()
622 gdev->owner = gc->owner; in gpiochip_add_data_with_key()
626 gdev->descs = kcalloc(gc->ngpio, sizeof(gdev->descs[0]), GFP_KERNEL); in gpiochip_add_data_with_key()
632 if (gc->ngpio == 0) { in gpiochip_add_data_with_key()
633 chip_err(gc, "tried to insert a GPIO chip with zero lines\n"); in gpiochip_add_data_with_key()
638 if (gc->ngpio > FASTPATH_NGPIO) in gpiochip_add_data_with_key()
639 chip_warn(gc, "line cnt %u is greater than fast path cnt %u\n", in gpiochip_add_data_with_key()
640 gc->ngpio, FASTPATH_NGPIO); in gpiochip_add_data_with_key()
642 gdev->label = kstrdup_const(gc->label ?: "unknown", GFP_KERNEL); in gpiochip_add_data_with_key()
648 gdev->ngpio = gc->ngpio; in gpiochip_add_data_with_key()
661 base = gpiochip_find_base(gc->ngpio); in gpiochip_add_data_with_key()
673 gc->base = base; in gpiochip_add_data_with_key()
683 for (i = 0; i < gc->ngpio; i++) in gpiochip_add_data_with_key()
694 if (gc->names) in gpiochip_add_data_with_key()
695 ret = gpiochip_set_desc_names(gc); in gpiochip_add_data_with_key()
697 ret = devprop_gpiochip_set_names(gc); in gpiochip_add_data_with_key()
701 ret = gpiochip_alloc_valid_mask(gc); in gpiochip_add_data_with_key()
705 ret = of_gpiochip_add(gc); in gpiochip_add_data_with_key()
709 ret = gpiochip_init_valid_mask(gc); in gpiochip_add_data_with_key()
713 for (i = 0; i < gc->ngpio; i++) { in gpiochip_add_data_with_key()
716 if (gc->get_direction && gpiochip_line_is_valid(gc, i)) { in gpiochip_add_data_with_key()
718 &desc->flags, !gc->get_direction(gc, i)); in gpiochip_add_data_with_key()
721 &desc->flags, !gc->direction_input); in gpiochip_add_data_with_key()
725 ret = gpiochip_add_pin_ranges(gc); in gpiochip_add_data_with_key()
729 acpi_gpiochip_add(gc); in gpiochip_add_data_with_key()
731 machine_gpiochip_add(gc); in gpiochip_add_data_with_key()
733 ret = gpiochip_irqchip_init_valid_mask(gc); in gpiochip_add_data_with_key()
737 ret = gpiochip_irqchip_init_hw(gc); in gpiochip_add_data_with_key()
741 ret = gpiochip_add_irqchip(gc, lock_key, request_key); in gpiochip_add_data_with_key()
761 gpiochip_irqchip_remove(gc); in gpiochip_add_data_with_key()
763 gpiochip_irqchip_free_valid_mask(gc); in gpiochip_add_data_with_key()
765 acpi_gpiochip_remove(gc); in gpiochip_add_data_with_key()
767 gpiochip_free_hogs(gc); in gpiochip_add_data_with_key()
768 of_gpiochip_remove(gc); in gpiochip_add_data_with_key()
770 gpiochip_remove_pin_ranges(gc); in gpiochip_add_data_with_key()
771 gpiochip_free_valid_mask(gc); in gpiochip_add_data_with_key()
788 gc->label ? : "generic", ret); in gpiochip_add_data_with_key()
796 * @gc: GPIO chip
801 void *gpiochip_get_data(struct gpio_chip *gc) in gpiochip_get_data() argument
803 return gc->gpiodev->data; in gpiochip_get_data()
809 * @gc: the chip to unregister
813 void gpiochip_remove(struct gpio_chip *gc) in gpiochip_remove() argument
815 struct gpio_device *gdev = gc->gpiodev; in gpiochip_remove()
821 gpiochip_free_hogs(gc); in gpiochip_remove()
824 gpiochip_irqchip_remove(gc); in gpiochip_remove()
825 acpi_gpiochip_remove(gc); in gpiochip_remove()
826 of_gpiochip_remove(gc); in gpiochip_remove()
827 gpiochip_remove_pin_ranges(gc); in gpiochip_remove()
828 gpiochip_free_valid_mask(gc); in gpiochip_remove()
837 if (gpiochip_is_requested(gc, i)) in gpiochip_remove()
869 int (*match)(struct gpio_chip *gc, in gpiochip_find() argument
873 struct gpio_chip *gc = NULL; in gpiochip_find() local
879 gc = gdev->chip; in gpiochip_find()
885 return gc; in gpiochip_find()
889 static int gpiochip_match_name(struct gpio_chip *gc, void *data) in gpiochip_match_name() argument
893 return !strcmp(gc->label, name); in gpiochip_match_name()
907 static int gpiochip_irqchip_init_hw(struct gpio_chip *gc) in gpiochip_irqchip_init_hw() argument
909 struct gpio_irq_chip *girq = &gc->irq; in gpiochip_irqchip_init_hw()
914 return girq->init_hw(gc); in gpiochip_irqchip_init_hw()
917 static int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gc) in gpiochip_irqchip_init_valid_mask() argument
919 struct gpio_irq_chip *girq = &gc->irq; in gpiochip_irqchip_init_valid_mask()
924 girq->valid_mask = gpiochip_allocate_mask(gc); in gpiochip_irqchip_init_valid_mask()
928 girq->init_valid_mask(gc, girq->valid_mask, gc->ngpio); in gpiochip_irqchip_init_valid_mask()
933 static void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gc) in gpiochip_irqchip_free_valid_mask() argument
935 bitmap_free(gc->irq.valid_mask); in gpiochip_irqchip_free_valid_mask()
936 gc->irq.valid_mask = NULL; in gpiochip_irqchip_free_valid_mask()
939 bool gpiochip_irqchip_irq_valid(const struct gpio_chip *gc, in gpiochip_irqchip_irq_valid() argument
942 if (!gpiochip_line_is_valid(gc, offset)) in gpiochip_irqchip_irq_valid()
945 if (likely(!gc->irq.valid_mask)) in gpiochip_irqchip_irq_valid()
947 return test_bit(offset, gc->irq.valid_mask); in gpiochip_irqchip_irq_valid()
953 * @gc: the gpiochip to set the irqchip chain to
960 static void gpiochip_set_cascaded_irqchip(struct gpio_chip *gc, in gpiochip_set_cascaded_irqchip() argument
964 struct gpio_irq_chip *girq = &gc->irq; in gpiochip_set_cascaded_irqchip()
965 struct device *dev = &gc->gpiodev->dev; in gpiochip_set_cascaded_irqchip()
968 chip_err(gc, "called %s before setting up irqchip\n", in gpiochip_set_cascaded_irqchip()
974 if (gc->can_sleep) { in gpiochip_set_cascaded_irqchip()
975 chip_err(gc, in gpiochip_set_cascaded_irqchip()
983 chip_err(gc, "out of memory allocating parent IRQ\n"); in gpiochip_set_cascaded_irqchip()
993 gc); in gpiochip_set_cascaded_irqchip()
999 * @gc: the gpiochip to set the irqchip nested handler to
1004 void gpiochip_set_nested_irqchip(struct gpio_chip *gc, in gpiochip_set_nested_irqchip() argument
1008 gpiochip_set_cascaded_irqchip(gc, parent_irq, NULL); in gpiochip_set_nested_irqchip()
1017 * @gc: the gpiochip to set the irqchip hierarchical handler to
1021 static void gpiochip_set_hierarchical_irqchip(struct gpio_chip *gc, in gpiochip_set_hierarchical_irqchip() argument
1025 if (is_of_node(gc->irq.fwnode)) in gpiochip_set_hierarchical_irqchip()
1036 if (is_fwnode_irqchip(gc->irq.fwnode)) { in gpiochip_set_hierarchical_irqchip()
1040 for (i = 0; i < gc->ngpio; i++) { in gpiochip_set_hierarchical_irqchip()
1044 struct gpio_irq_chip *girq = &gc->irq; in gpiochip_set_hierarchical_irqchip()
1052 ret = girq->child_to_parent_hwirq(gc, i, in gpiochip_set_hierarchical_irqchip()
1057 chip_err(gc, "skip set-up on hwirq %d\n", in gpiochip_set_hierarchical_irqchip()
1062 fwspec.fwnode = gc->irq.fwnode; in gpiochip_set_hierarchical_irqchip()
1064 fwspec.param[0] = girq->child_offset_to_irq(gc, i); in gpiochip_set_hierarchical_irqchip()
1068 ret = __irq_domain_alloc_irqs(gc->irq.domain, in gpiochip_set_hierarchical_irqchip()
1077 chip_err(gc, in gpiochip_set_hierarchical_irqchip()
1085 chip_err(gc, "%s unknown fwnode type proceed anyway\n", __func__); in gpiochip_set_hierarchical_irqchip()
1118 struct gpio_chip *gc = d->host_data; in gpiochip_hierarchy_irq_domain_alloc() local
1125 struct gpio_irq_chip *girq = &gc->irq; in gpiochip_hierarchy_irq_domain_alloc()
1134 ret = gc->irq.child_irq_domain_ops.translate(d, fwspec, &hwirq, &type); in gpiochip_hierarchy_irq_domain_alloc()
1138 chip_dbg(gc, "allocate IRQ %d, hwirq %lu\n", irq, hwirq); in gpiochip_hierarchy_irq_domain_alloc()
1140 ret = girq->child_to_parent_hwirq(gc, hwirq, type, in gpiochip_hierarchy_irq_domain_alloc()
1143 chip_err(gc, "can't look up hwirq %lu\n", hwirq); in gpiochip_hierarchy_irq_domain_alloc()
1146 chip_dbg(gc, "found parent hwirq %u\n", parent_hwirq); in gpiochip_hierarchy_irq_domain_alloc()
1155 gc->irq.chip, in gpiochip_hierarchy_irq_domain_alloc()
1156 gc, in gpiochip_hierarchy_irq_domain_alloc()
1162 parent_arg = girq->populate_parent_alloc_arg(gc, parent_hwirq, parent_type); in gpiochip_hierarchy_irq_domain_alloc()
1166 chip_dbg(gc, "alloc_irqs_parent for %d parent hwirq %d\n", in gpiochip_hierarchy_irq_domain_alloc()
1168 irq_set_lockdep_class(irq, gc->irq.lock_key, gc->irq.request_key); in gpiochip_hierarchy_irq_domain_alloc()
1177 chip_err(gc, in gpiochip_hierarchy_irq_domain_alloc()
1185 static unsigned int gpiochip_child_offset_to_irq_noop(struct gpio_chip *gc, in gpiochip_child_offset_to_irq_noop() argument
1207 static int gpiochip_hierarchy_add_domain(struct gpio_chip *gc) in gpiochip_hierarchy_add_domain() argument
1209 if (!gc->irq.child_to_parent_hwirq || in gpiochip_hierarchy_add_domain()
1210 !gc->irq.fwnode) { in gpiochip_hierarchy_add_domain()
1211 chip_err(gc, "missing irqdomain vital data\n"); in gpiochip_hierarchy_add_domain()
1215 if (!gc->irq.child_offset_to_irq) in gpiochip_hierarchy_add_domain()
1216 gc->irq.child_offset_to_irq = gpiochip_child_offset_to_irq_noop; in gpiochip_hierarchy_add_domain()
1218 if (!gc->irq.populate_parent_alloc_arg) in gpiochip_hierarchy_add_domain()
1219 gc->irq.populate_parent_alloc_arg = in gpiochip_hierarchy_add_domain()
1222 gpiochip_hierarchy_setup_domain_ops(&gc->irq.child_irq_domain_ops); in gpiochip_hierarchy_add_domain()
1224 gc->irq.domain = irq_domain_create_hierarchy( in gpiochip_hierarchy_add_domain()
1225 gc->irq.parent_domain, in gpiochip_hierarchy_add_domain()
1227 gc->ngpio, in gpiochip_hierarchy_add_domain()
1228 gc->irq.fwnode, in gpiochip_hierarchy_add_domain()
1229 &gc->irq.child_irq_domain_ops, in gpiochip_hierarchy_add_domain()
1230 gc); in gpiochip_hierarchy_add_domain()
1232 if (!gc->irq.domain) in gpiochip_hierarchy_add_domain()
1235 gpiochip_set_hierarchical_irqchip(gc, gc->irq.chip); in gpiochip_hierarchy_add_domain()
1240 static bool gpiochip_hierarchy_is_hierarchical(struct gpio_chip *gc) in gpiochip_hierarchy_is_hierarchical() argument
1242 return !!gc->irq.parent_domain; in gpiochip_hierarchy_is_hierarchical()
1245 void *gpiochip_populate_parent_fwspec_twocell(struct gpio_chip *gc, in gpiochip_populate_parent_fwspec_twocell() argument
1255 fwspec->fwnode = gc->irq.parent_domain->fwnode; in gpiochip_populate_parent_fwspec_twocell()
1264 void *gpiochip_populate_parent_fwspec_fourcell(struct gpio_chip *gc, in gpiochip_populate_parent_fwspec_fourcell() argument
1274 fwspec->fwnode = gc->irq.parent_domain->fwnode; in gpiochip_populate_parent_fwspec_fourcell()
1287 static int gpiochip_hierarchy_add_domain(struct gpio_chip *gc) in gpiochip_hierarchy_add_domain() argument
1292 static bool gpiochip_hierarchy_is_hierarchical(struct gpio_chip *gc) in gpiochip_hierarchy_is_hierarchical() argument
1312 struct gpio_chip *gc = d->host_data; in gpiochip_irq_map() local
1315 if (!gpiochip_irqchip_irq_valid(gc, hwirq)) in gpiochip_irq_map()
1318 irq_set_chip_data(irq, gc); in gpiochip_irq_map()
1323 irq_set_lockdep_class(irq, gc->irq.lock_key, gc->irq.request_key); in gpiochip_irq_map()
1324 irq_set_chip_and_handler(irq, gc->irq.chip, gc->irq.handler); in gpiochip_irq_map()
1326 if (gc->irq.threaded) in gpiochip_irq_map()
1330 if (gc->irq.num_parents == 1) in gpiochip_irq_map()
1331 ret = irq_set_parent(irq, gc->irq.parents[0]); in gpiochip_irq_map()
1332 else if (gc->irq.map) in gpiochip_irq_map()
1333 ret = irq_set_parent(irq, gc->irq.map[hwirq]); in gpiochip_irq_map()
1342 if (gc->irq.default_type != IRQ_TYPE_NONE) in gpiochip_irq_map()
1343 irq_set_irq_type(irq, gc->irq.default_type); in gpiochip_irq_map()
1351 struct gpio_chip *gc = d->host_data; in gpiochip_irq_unmap() local
1353 if (gc->irq.threaded) in gpiochip_irq_unmap()
1385 struct gpio_chip *gc = domain->host_data; in gpiochip_irq_domain_activate() local
1387 return gpiochip_lock_as_irq(gc, data->hwirq); in gpiochip_irq_domain_activate()
1403 struct gpio_chip *gc = domain->host_data; in gpiochip_irq_domain_deactivate() local
1405 return gpiochip_unlock_as_irq(gc, data->hwirq); in gpiochip_irq_domain_deactivate()
1409 static int gpiochip_to_irq(struct gpio_chip *gc, unsigned offset) in gpiochip_to_irq() argument
1411 struct irq_domain *domain = gc->irq.domain; in gpiochip_to_irq()
1419 if (!gc->irq.initialized) in gpiochip_to_irq()
1423 if (!gpiochip_irqchip_irq_valid(gc, offset)) in gpiochip_to_irq()
1432 spec.param[0] = gc->irq.child_offset_to_irq(gc, offset); in gpiochip_to_irq()
1444 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); in gpiochip_irq_reqres() local
1446 return gpiochip_reqres_irq(gc, d->hwirq); in gpiochip_irq_reqres()
1451 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); in gpiochip_irq_relres() local
1453 gpiochip_relres_irq(gc, d->hwirq); in gpiochip_irq_relres()
1458 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); in gpiochip_irq_mask() local
1460 if (gc->irq.irq_mask) in gpiochip_irq_mask()
1461 gc->irq.irq_mask(d); in gpiochip_irq_mask()
1462 gpiochip_disable_irq(gc, d->hwirq); in gpiochip_irq_mask()
1467 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); in gpiochip_irq_unmask() local
1469 gpiochip_enable_irq(gc, d->hwirq); in gpiochip_irq_unmask()
1470 if (gc->irq.irq_unmask) in gpiochip_irq_unmask()
1471 gc->irq.irq_unmask(d); in gpiochip_irq_unmask()
1476 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); in gpiochip_irq_enable() local
1478 gpiochip_enable_irq(gc, d->hwirq); in gpiochip_irq_enable()
1479 gc->irq.irq_enable(d); in gpiochip_irq_enable()
1484 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); in gpiochip_irq_disable() local
1486 gc->irq.irq_disable(d); in gpiochip_irq_disable()
1487 gpiochip_disable_irq(gc, d->hwirq); in gpiochip_irq_disable()
1490 static void gpiochip_set_irq_hooks(struct gpio_chip *gc) in gpiochip_set_irq_hooks() argument
1492 struct irq_chip *irqchip = gc->irq.chip; in gpiochip_set_irq_hooks()
1499 if (WARN_ON(gc->irq.irq_enable)) in gpiochip_set_irq_hooks()
1508 chip_info(gc, in gpiochip_set_irq_hooks()
1514 gc->irq.irq_disable = irqchip->irq_disable; in gpiochip_set_irq_hooks()
1517 gc->irq.irq_mask = irqchip->irq_mask; in gpiochip_set_irq_hooks()
1522 gc->irq.irq_enable = irqchip->irq_enable; in gpiochip_set_irq_hooks()
1525 gc->irq.irq_unmask = irqchip->irq_unmask; in gpiochip_set_irq_hooks()
1532 * @gc: the GPIO chip to add the IRQ chip to
1536 static int gpiochip_add_irqchip(struct gpio_chip *gc, in gpiochip_add_irqchip() argument
1540 struct irq_chip *irqchip = gc->irq.chip; in gpiochip_add_irqchip()
1549 if (gc->irq.parent_handler && gc->can_sleep) { in gpiochip_add_irqchip()
1550 chip_err(gc, "you cannot have chained interrupts on a chip that may sleep\n"); in gpiochip_add_irqchip()
1554 np = gc->gpiodev->dev.of_node; in gpiochip_add_irqchip()
1555 type = gc->irq.default_type; in gpiochip_add_irqchip()
1566 if (has_acpi_companion(gc->parent) && type != IRQ_TYPE_NONE) { in gpiochip_add_irqchip()
1567 acpi_handle_warn(ACPI_HANDLE(gc->parent), in gpiochip_add_irqchip()
1572 gc->to_irq = gpiochip_to_irq; in gpiochip_add_irqchip()
1573 gc->irq.default_type = type; in gpiochip_add_irqchip()
1574 gc->irq.lock_key = lock_key; in gpiochip_add_irqchip()
1575 gc->irq.request_key = request_key; in gpiochip_add_irqchip()
1578 if (gpiochip_hierarchy_is_hierarchical(gc)) { in gpiochip_add_irqchip()
1579 int ret = gpiochip_hierarchy_add_domain(gc); in gpiochip_add_irqchip()
1584 if (gc->irq.domain_ops) in gpiochip_add_irqchip()
1585 ops = gc->irq.domain_ops; in gpiochip_add_irqchip()
1589 gc->irq.domain = irq_domain_add_simple(np, in gpiochip_add_irqchip()
1590 gc->ngpio, in gpiochip_add_irqchip()
1591 gc->irq.first, in gpiochip_add_irqchip()
1592 ops, gc); in gpiochip_add_irqchip()
1593 if (!gc->irq.domain) in gpiochip_add_irqchip()
1597 if (gc->irq.parent_handler) { in gpiochip_add_irqchip()
1598 for (i = 0; i < gc->irq.num_parents; i++) { in gpiochip_add_irqchip()
1601 if (gc->irq.per_parent_data) in gpiochip_add_irqchip()
1602 data = gc->irq.parent_handler_data_array[i]; in gpiochip_add_irqchip()
1604 data = gc->irq.parent_handler_data ?: gc; in gpiochip_add_irqchip()
1611 irq_set_chained_handler_and_data(gc->irq.parents[i], in gpiochip_add_irqchip()
1612 gc->irq.parent_handler, in gpiochip_add_irqchip()
1617 gpiochip_set_irq_hooks(gc); in gpiochip_add_irqchip()
1621 * gc->irq.initialized before initialization of above in gpiochip_add_irqchip()
1626 gc->irq.initialized = true; in gpiochip_add_irqchip()
1628 acpi_gpiochip_request_interrupts(gc); in gpiochip_add_irqchip()
1635 * @gc: the gpiochip to remove the irqchip from
1639 static void gpiochip_irqchip_remove(struct gpio_chip *gc) in gpiochip_irqchip_remove() argument
1641 struct irq_chip *irqchip = gc->irq.chip; in gpiochip_irqchip_remove()
1644 acpi_gpiochip_free_interrupts(gc); in gpiochip_irqchip_remove()
1646 if (irqchip && gc->irq.parent_handler) { in gpiochip_irqchip_remove()
1647 struct gpio_irq_chip *irq = &gc->irq; in gpiochip_irqchip_remove()
1656 if (gc->irq.domain) { in gpiochip_irqchip_remove()
1659 for (offset = 0; offset < gc->ngpio; offset++) { in gpiochip_irqchip_remove()
1660 if (!gpiochip_irqchip_irq_valid(gc, offset)) in gpiochip_irqchip_remove()
1663 irq = irq_find_mapping(gc->irq.domain, offset); in gpiochip_irqchip_remove()
1667 irq_domain_remove(gc->irq.domain); in gpiochip_irqchip_remove()
1676 irqchip->irq_enable = gc->irq.irq_enable; in gpiochip_irqchip_remove()
1677 irqchip->irq_disable = gc->irq.irq_disable; in gpiochip_irqchip_remove()
1680 gc->irq.irq_enable = NULL; in gpiochip_irqchip_remove()
1681 gc->irq.irq_disable = NULL; in gpiochip_irqchip_remove()
1682 gc->irq.chip = NULL; in gpiochip_irqchip_remove()
1684 gpiochip_irqchip_free_valid_mask(gc); in gpiochip_irqchip_remove()
1689 * @gc: the gpiochip to add the irqchip to
1714 int gpiochip_irqchip_add_key(struct gpio_chip *gc, in gpiochip_irqchip_add_key() argument
1725 if (!gc || !irqchip) in gpiochip_irqchip_add_key()
1728 if (!gc->parent) { in gpiochip_irqchip_add_key()
1729 chip_err(gc, "missing gpiochip .dev parent pointer\n"); in gpiochip_irqchip_add_key()
1732 gc->irq.threaded = threaded; in gpiochip_irqchip_add_key()
1733 of_node = gc->parent->of_node; in gpiochip_irqchip_add_key()
1737 * FIXME: get rid of this and use gc->parent->of_node in gpiochip_irqchip_add_key()
1740 if (gc->of_node) in gpiochip_irqchip_add_key()
1741 of_node = gc->of_node; in gpiochip_irqchip_add_key()
1751 if (has_acpi_companion(gc->parent) && type != IRQ_TYPE_NONE) { in gpiochip_irqchip_add_key()
1752 acpi_handle_warn(ACPI_HANDLE(gc->parent), in gpiochip_irqchip_add_key()
1757 gc->irq.chip = irqchip; in gpiochip_irqchip_add_key()
1758 gc->irq.handler = handler; in gpiochip_irqchip_add_key()
1759 gc->irq.default_type = type; in gpiochip_irqchip_add_key()
1760 gc->to_irq = gpiochip_to_irq; in gpiochip_irqchip_add_key()
1761 gc->irq.lock_key = lock_key; in gpiochip_irqchip_add_key()
1762 gc->irq.request_key = request_key; in gpiochip_irqchip_add_key()
1763 gc->irq.domain = irq_domain_add_simple(of_node, in gpiochip_irqchip_add_key()
1764 gc->ngpio, first_irq, in gpiochip_irqchip_add_key()
1765 &gpiochip_domain_ops, gc); in gpiochip_irqchip_add_key()
1766 if (!gc->irq.domain) { in gpiochip_irqchip_add_key()
1767 gc->irq.chip = NULL; in gpiochip_irqchip_add_key()
1771 gpiochip_set_irq_hooks(gc); in gpiochip_irqchip_add_key()
1773 acpi_gpiochip_request_interrupts(gc); in gpiochip_irqchip_add_key()
1781 * @gc: the gpiochip to add the irqchip to
1786 int gpiochip_irqchip_add_domain(struct gpio_chip *gc, in gpiochip_irqchip_add_domain() argument
1792 gc->to_irq = gpiochip_to_irq; in gpiochip_irqchip_add_domain()
1793 gc->irq.domain = domain; in gpiochip_irqchip_add_domain()
1797 * gc->irq.initialized before adding irqdomain. in gpiochip_irqchip_add_domain()
1801 gc->irq.initialized = true; in gpiochip_irqchip_add_domain()
1809 static inline int gpiochip_add_irqchip(struct gpio_chip *gc, in gpiochip_add_irqchip() argument
1815 static void gpiochip_irqchip_remove(struct gpio_chip *gc) {} in gpiochip_irqchip_remove() argument
1817 static inline int gpiochip_irqchip_init_hw(struct gpio_chip *gc) in gpiochip_irqchip_init_hw() argument
1822 static inline int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gc) in gpiochip_irqchip_init_valid_mask() argument
1826 static inline void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gc) in gpiochip_irqchip_free_valid_mask() argument
1833 * @gc: the gpiochip owning the GPIO
1836 int gpiochip_generic_request(struct gpio_chip *gc, unsigned offset) in gpiochip_generic_request() argument
1839 if (list_empty(&gc->gpiodev->pin_ranges)) in gpiochip_generic_request()
1843 return pinctrl_gpio_request(gc->gpiodev->base + offset); in gpiochip_generic_request()
1849 * @gc: the gpiochip to request the gpio function for
1852 void gpiochip_generic_free(struct gpio_chip *gc, unsigned offset) in gpiochip_generic_free() argument
1855 if (list_empty(&gc->gpiodev->pin_ranges)) in gpiochip_generic_free()
1859 pinctrl_gpio_free(gc->gpiodev->base + offset); in gpiochip_generic_free()
1865 * @gc: the gpiochip owning the GPIO
1869 int gpiochip_generic_config(struct gpio_chip *gc, unsigned offset, in gpiochip_generic_config() argument
1872 return pinctrl_gpio_set_config(gc->gpiodev->base + offset, config); in gpiochip_generic_config()
1880 * @gc: the gpiochip to add the range for
1890 int gpiochip_add_pingroup_range(struct gpio_chip *gc, in gpiochip_add_pingroup_range() argument
1895 struct gpio_device *gdev = gc->gpiodev; in gpiochip_add_pingroup_range()
1900 chip_err(gc, "failed to allocate pin ranges\n"); in gpiochip_add_pingroup_range()
1906 pin_range->range.gc = gc; in gpiochip_add_pingroup_range()
1907 pin_range->range.name = gc->label; in gpiochip_add_pingroup_range()
1921 chip_dbg(gc, "created GPIO range %d->%d ==> %s PINGRP %s\n", in gpiochip_add_pingroup_range()
1933 * @gc: the gpiochip to add the range for
1948 int gpiochip_add_pin_range(struct gpio_chip *gc, const char *pinctl_name, in gpiochip_add_pin_range() argument
1953 struct gpio_device *gdev = gc->gpiodev; in gpiochip_add_pin_range()
1958 chip_err(gc, "failed to allocate pin ranges\n"); in gpiochip_add_pin_range()
1964 pin_range->range.gc = gc; in gpiochip_add_pin_range()
1965 pin_range->range.name = gc->label; in gpiochip_add_pin_range()
1973 chip_err(gc, "could not create pin range\n"); in gpiochip_add_pin_range()
1977 chip_dbg(gc, "created GPIO range %d->%d ==> %s PIN %d->%d\n", in gpiochip_add_pin_range()
1990 * @gc: the chip to remove all the mappings for
1992 void gpiochip_remove_pin_ranges(struct gpio_chip *gc) in gpiochip_remove_pin_ranges() argument
1995 struct gpio_device *gdev = gc->gpiodev; in gpiochip_remove_pin_ranges()
2014 struct gpio_chip *gc = desc->gdev->chip; in gpiod_request_commit() local
2040 if (gc->request) { in gpiod_request_commit()
2041 /* gc->request may sleep */ in gpiod_request_commit()
2044 if (gpiochip_line_is_valid(gc, offset)) in gpiod_request_commit()
2045 ret = gc->request(gc, offset); in gpiod_request_commit()
2057 if (gc->get_direction) { in gpiod_request_commit()
2058 /* gc->get_direction may sleep */ in gpiod_request_commit()
2132 struct gpio_chip *gc; in gpiod_free_commit() local
2140 gc = desc->gdev->chip; in gpiod_free_commit()
2141 if (gc && test_bit(FLAG_REQUESTED, &desc->flags)) { in gpiod_free_commit()
2142 if (gc->free) { in gpiod_free_commit()
2144 might_sleep_if(gc->can_sleep); in gpiod_free_commit()
2145 gc->free(gc, gpio_chip_hwgpio(desc)); in gpiod_free_commit()
2188 * @gc: controller managing the signal
2199 const char *gpiochip_is_requested(struct gpio_chip *gc, unsigned offset) in gpiochip_is_requested() argument
2203 if (offset >= gc->ngpio) in gpiochip_is_requested()
2206 desc = gpiochip_get_desc(gc, offset); in gpiochip_is_requested()
2218 * @gc: GPIO chip
2237 struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *gc, in gpiochip_request_own_desc() argument
2243 struct gpio_desc *desc = gpiochip_get_desc(gc, hwnum); in gpiochip_request_own_desc()
2247 chip_err(gc, "failed to get GPIO descriptor\n"); in gpiochip_request_own_desc()
2257 chip_err(gc, "setup of own GPIO %s failed\n", label); in gpiochip_request_own_desc()
2290 static int gpio_do_set_config(struct gpio_chip *gc, unsigned int offset, in gpio_do_set_config() argument
2293 if (!gc->set_config) in gpio_do_set_config()
2296 return gc->set_config(gc, offset, config); in gpio_do_set_config()
2301 struct gpio_chip *gc = desc->gdev->chip; in gpio_set_config() local
2316 return gpio_do_set_config(gc, gpio_chip_hwgpio(desc), config); in gpio_set_config()
2350 struct gpio_chip *gc; in gpiod_direction_input() local
2354 gc = desc->gdev->chip; in gpiod_direction_input()
2361 if (!gc->get && gc->direction_input) { in gpiod_direction_input()
2374 if (gc->direction_input) { in gpiod_direction_input()
2375 ret = gc->direction_input(gc, gpio_chip_hwgpio(desc)); in gpiod_direction_input()
2376 } else if (gc->get_direction && in gpiod_direction_input()
2377 (gc->get_direction(gc, gpio_chip_hwgpio(desc)) != 1)) { in gpiod_direction_input()
2396 struct gpio_chip *gc = desc->gdev->chip; in gpiod_direction_output_raw_commit() local
2405 if (!gc->set && !gc->direction_output) { in gpiod_direction_output_raw_commit()
2412 if (gc->direction_output) { in gpiod_direction_output_raw_commit()
2413 ret = gc->direction_output(gc, gpio_chip_hwgpio(desc), val); in gpiod_direction_output_raw_commit()
2416 if (gc->get_direction && in gpiod_direction_output_raw_commit()
2417 gc->get_direction(gc, gpio_chip_hwgpio(desc))) { in gpiod_direction_output_raw_commit()
2427 gc->set(gc, gpio_chip_hwgpio(desc), val); in gpiod_direction_output_raw_commit()
2539 struct gpio_chip *gc; in gpiod_set_config() local
2542 gc = desc->gdev->chip; in gpiod_set_config()
2544 return gpio_do_set_config(gc, gpio_chip_hwgpio(desc), config); in gpiod_set_config()
2576 struct gpio_chip *gc; in gpiod_set_transitory() local
2589 gc = desc->gdev->chip; in gpiod_set_transitory()
2590 if (!gc->set_config) in gpiod_set_transitory()
2596 rc = gpio_do_set_config(gc, gpio, packed); in gpiod_set_transitory()
2655 struct gpio_chip *gc; in gpiod_get_raw_value_commit() local
2659 gc = desc->gdev->chip; in gpiod_get_raw_value_commit()
2661 value = gc->get ? gc->get(gc, offset) : -EIO; in gpiod_get_raw_value_commit()
2667 static int gpio_chip_get_multiple(struct gpio_chip *gc, in gpio_chip_get_multiple() argument
2670 if (gc->get_multiple) in gpio_chip_get_multiple()
2671 return gc->get_multiple(gc, mask, bits); in gpio_chip_get_multiple()
2672 if (gc->get) { in gpio_chip_get_multiple()
2675 for_each_set_bit(i, mask, gc->ngpio) { in gpio_chip_get_multiple()
2676 value = gc->get(gc, i); in gpio_chip_get_multiple()
2723 struct gpio_chip *gc = desc_array[i]->gdev->chip; in gpiod_get_array_value_complex() local
2728 if (likely(gc->ngpio <= FASTPATH_NGPIO)) { in gpiod_get_array_value_complex()
2731 mask = kmalloc_array(2 * BITS_TO_LONGS(gc->ngpio), in gpiod_get_array_value_complex()
2738 bits = mask + BITS_TO_LONGS(gc->ngpio); in gpiod_get_array_value_complex()
2739 bitmap_zero(mask, gc->ngpio); in gpiod_get_array_value_complex()
2742 WARN_ON(gc->can_sleep); in gpiod_get_array_value_complex()
2757 (desc_array[i]->gdev->chip == gc)); in gpiod_get_array_value_complex()
2759 ret = gpio_chip_get_multiple(gc, mask, bits); in gpiod_get_array_value_complex()
2897 struct gpio_chip *gc = desc->gdev->chip; in gpio_set_open_drain_value_commit() local
2901 ret = gc->direction_input(gc, offset); in gpio_set_open_drain_value_commit()
2903 ret = gc->direction_output(gc, offset, 0); in gpio_set_open_drain_value_commit()
2922 struct gpio_chip *gc = desc->gdev->chip; in gpio_set_open_source_value_commit() local
2926 ret = gc->direction_output(gc, offset, 1); in gpio_set_open_source_value_commit()
2930 ret = gc->direction_input(gc, offset); in gpio_set_open_source_value_commit()
2941 struct gpio_chip *gc; in gpiod_set_raw_value_commit() local
2943 gc = desc->gdev->chip; in gpiod_set_raw_value_commit()
2945 gc->set(gc, gpio_chip_hwgpio(desc), value); in gpiod_set_raw_value_commit()
2958 static void gpio_chip_set_multiple(struct gpio_chip *gc, in gpio_chip_set_multiple() argument
2961 if (gc->set_multiple) { in gpio_chip_set_multiple()
2962 gc->set_multiple(gc, mask, bits); in gpio_chip_set_multiple()
2967 for_each_set_bit(i, mask, gc->ngpio) in gpio_chip_set_multiple()
2968 gc->set(gc, i, test_bit(i, bits)); in gpio_chip_set_multiple()
3006 struct gpio_chip *gc = desc_array[i]->gdev->chip; in gpiod_set_array_value_complex() local
3011 if (likely(gc->ngpio <= FASTPATH_NGPIO)) { in gpiod_set_array_value_complex()
3014 mask = kmalloc_array(2 * BITS_TO_LONGS(gc->ngpio), in gpiod_set_array_value_complex()
3021 bits = mask + BITS_TO_LONGS(gc->ngpio); in gpiod_set_array_value_complex()
3022 bitmap_zero(mask, gc->ngpio); in gpiod_set_array_value_complex()
3025 WARN_ON(gc->can_sleep); in gpiod_set_array_value_complex()
3061 (desc_array[i]->gdev->chip == gc)); in gpiod_set_array_value_complex()
3064 gpio_chip_set_multiple(gc, mask, bits); in gpiod_set_array_value_complex()
3226 struct gpio_chip *gc; in gpiod_to_irq() local
3237 gc = desc->gdev->chip; in gpiod_to_irq()
3239 if (gc->to_irq) { in gpiod_to_irq()
3240 int retirq = gc->to_irq(gc, offset); in gpiod_to_irq()
3249 if (gc->irq.chip) { in gpiod_to_irq()
3264 * @gc: the chip the GPIO to lock belongs to
3270 int gpiochip_lock_as_irq(struct gpio_chip *gc, unsigned int offset) in gpiochip_lock_as_irq() argument
3274 desc = gpiochip_get_desc(gc, offset); in gpiochip_lock_as_irq()
3282 if (!gc->can_sleep && gc->get_direction) { in gpiochip_lock_as_irq()
3286 chip_err(gc, "%s: cannot get GPIO direction\n", in gpiochip_lock_as_irq()
3295 chip_err(gc, in gpiochip_lock_as_irq()
3318 * @gc: the chip the GPIO to lock belongs to
3324 void gpiochip_unlock_as_irq(struct gpio_chip *gc, unsigned int offset) in gpiochip_unlock_as_irq() argument
3328 desc = gpiochip_get_desc(gc, offset); in gpiochip_unlock_as_irq()
3341 void gpiochip_disable_irq(struct gpio_chip *gc, unsigned int offset) in gpiochip_disable_irq() argument
3343 struct gpio_desc *desc = gpiochip_get_desc(gc, offset); in gpiochip_disable_irq()
3351 void gpiochip_enable_irq(struct gpio_chip *gc, unsigned int offset) in gpiochip_enable_irq() argument
3353 struct gpio_desc *desc = gpiochip_get_desc(gc, offset); in gpiochip_enable_irq()
3368 bool gpiochip_line_is_irq(struct gpio_chip *gc, unsigned int offset) in gpiochip_line_is_irq() argument
3370 if (offset >= gc->ngpio) in gpiochip_line_is_irq()
3373 return test_bit(FLAG_USED_AS_IRQ, &gc->gpiodev->descs[offset].flags); in gpiochip_line_is_irq()
3377 int gpiochip_reqres_irq(struct gpio_chip *gc, unsigned int offset) in gpiochip_reqres_irq() argument
3381 if (!try_module_get(gc->gpiodev->owner)) in gpiochip_reqres_irq()
3384 ret = gpiochip_lock_as_irq(gc, offset); in gpiochip_reqres_irq()
3386 chip_err(gc, "unable to lock HW IRQ %u for IRQ\n", offset); in gpiochip_reqres_irq()
3387 module_put(gc->gpiodev->owner); in gpiochip_reqres_irq()
3394 void gpiochip_relres_irq(struct gpio_chip *gc, unsigned int offset) in gpiochip_relres_irq() argument
3396 gpiochip_unlock_as_irq(gc, offset); in gpiochip_relres_irq()
3397 module_put(gc->gpiodev->owner); in gpiochip_relres_irq()
3401 bool gpiochip_line_is_open_drain(struct gpio_chip *gc, unsigned int offset) in gpiochip_line_is_open_drain() argument
3403 if (offset >= gc->ngpio) in gpiochip_line_is_open_drain()
3406 return test_bit(FLAG_OPEN_DRAIN, &gc->gpiodev->descs[offset].flags); in gpiochip_line_is_open_drain()
3410 bool gpiochip_line_is_open_source(struct gpio_chip *gc, unsigned int offset) in gpiochip_line_is_open_source() argument
3412 if (offset >= gc->ngpio) in gpiochip_line_is_open_source()
3415 return test_bit(FLAG_OPEN_SOURCE, &gc->gpiodev->descs[offset].flags); in gpiochip_line_is_open_source()
3419 bool gpiochip_line_is_persistent(struct gpio_chip *gc, unsigned int offset) in gpiochip_line_is_persistent() argument
3421 if (offset >= gc->ngpio) in gpiochip_line_is_persistent()
3424 return !test_bit(FLAG_TRANSITORY, &gc->gpiodev->descs[offset].flags); in gpiochip_line_is_persistent()
3662 struct gpio_chip *gc; in gpiod_add_hogs() local
3674 gc = find_chip_by_name(hog->chip_label); in gpiod_add_hogs()
3675 if (gc) in gpiod_add_hogs()
3676 gpiochip_machine_hog(gc, hog); in gpiod_add_hogs()
3726 struct gpio_chip *gc; in gpiod_find() local
3748 gc = find_chip_by_name(p->key); in gpiod_find()
3750 if (!gc) { in gpiod_find()
3763 if (gc->ngpio <= p->chip_hwnum) { in gpiod_find()
3766 idx, p->chip_hwnum, gc->ngpio - 1, in gpiod_find()
3767 gc->label); in gpiod_find()
3771 desc = gpiochip_get_desc(gc, p->chip_hwnum); in gpiod_find()
4172 struct gpio_chip *gc; in gpiod_hog() local
4177 gc = gpiod_to_chip(desc); in gpiod_hog()
4180 local_desc = gpiochip_request_own_desc(gc, hwnum, name, in gpiod_hog()
4185 name, gc->label, hwnum, ret); in gpiod_hog()
4202 * @gc: gpio chip to act on
4204 static void gpiochip_free_hogs(struct gpio_chip *gc) in gpiochip_free_hogs() argument
4208 for (id = 0; id < gc->ngpio; id++) { in gpiochip_free_hogs()
4209 if (test_bit(FLAG_IS_HOGGED, &gc->gpiodev->descs[id].flags)) in gpiochip_free_hogs()
4210 gpiochip_free_own_desc(&gc->gpiodev->descs[id]); in gpiochip_free_hogs()
4233 struct gpio_chip *gc; in gpiod_get_array() local
4253 gc = gpiod_to_chip(desc); in gpiod_get_array()
4261 bitmap_size = BITS_TO_LONGS(gc->ngpio > count ? in gpiod_get_array()
4262 gc->ngpio : count); in gpiod_get_array()
4285 array_info->chip = gc; in gpiod_get_array()
4293 if (array_info && array_info->chip != gc) { in gpiod_get_array()
4318 if (gpiochip_line_is_open_drain(gc, descs->ndescs) || in gpiod_get_array()
4319 gpiochip_line_is_open_source(gc, descs->ndescs)) in gpiod_get_array()
4426 struct gpio_chip *gc = gdev->chip; in gpiolib_dbg_show() local
4449 gc->get ? (gc->get(gc, i) ? "hi" : "lo") : "? ", in gpiolib_dbg_show()
4501 struct gpio_chip *gc = gdev->chip; in gpiolib_seq_show() local
4504 if (!gc) { in gpiolib_seq_show()
4513 parent = gc->parent; in gpiolib_seq_show()
4518 if (gc->label) in gpiolib_seq_show()
4519 seq_printf(s, ", %s", gc->label); in gpiolib_seq_show()
4520 if (gc->can_sleep) in gpiolib_seq_show()
4524 if (gc->dbg_show) in gpiolib_seq_show()
4525 gc->dbg_show(s, gc); in gpiolib_seq_show()