Lines Matching full:gc
95 static void gpiochip_free_hogs(struct gpio_chip *gc);
96 static int gpiochip_add_irqchip(struct gpio_chip *gc,
99 static void gpiochip_irqchip_remove(struct gpio_chip *gc);
100 static int gpiochip_irqchip_init_hw(struct gpio_chip *gc);
101 static int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gc);
102 static void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gc);
176 struct gpio_desc *gpiochip_get_desc(struct gpio_chip *gc, in gpiochip_get_desc() argument
179 return gpio_device_get_desc(gc->gpiodev, hwnum); in gpiochip_get_desc()
367 if (!guard.gc) in gpiod_get_direction()
381 if (!guard.gc->get_direction) in gpiod_get_direction()
384 ret = guard.gc->get_direction(guard.gc, offset); in gpiod_get_direction()
463 struct gpio_chip *gc; in gpio_name_to_desc() local
474 gc = srcu_dereference(gdev->chip, &gdev->srcu); in gpio_name_to_desc()
475 if (!gc) in gpio_name_to_desc()
478 for_each_gpio_desc(gc, desc) { in gpio_name_to_desc()
488 * Take the names from gc->names and assign them to their GPIO descriptors.
495 static void gpiochip_set_desc_names(struct gpio_chip *gc) in gpiochip_set_desc_names() argument
497 struct gpio_device *gdev = gc->gpiodev; in gpiochip_set_desc_names()
501 for (i = 0; i != gc->ngpio; ++i) { in gpiochip_set_desc_names()
504 gpio = gpio_name_to_desc(gc->names[i]); in gpiochip_set_desc_names()
508 gc->names[i]); in gpiochip_set_desc_names()
512 for (i = 0; i != gc->ngpio; ++i) in gpiochip_set_desc_names()
513 gdev->descs[i].name = gc->names[i]; in gpiochip_set_desc_names()
593 static unsigned long *gpiochip_allocate_mask(struct gpio_chip *gc) in gpiochip_allocate_mask() argument
597 p = bitmap_alloc(gc->ngpio, GFP_KERNEL); in gpiochip_allocate_mask()
602 bitmap_fill(p, gc->ngpio); in gpiochip_allocate_mask()
613 static unsigned int gpiochip_count_reserved_ranges(struct gpio_chip *gc) in gpiochip_count_reserved_ranges() argument
615 struct device *dev = &gc->gpiodev->dev; in gpiochip_count_reserved_ranges()
626 static int gpiochip_apply_reserved_ranges(struct gpio_chip *gc) in gpiochip_apply_reserved_ranges() argument
628 struct device *dev = &gc->gpiodev->dev; in gpiochip_apply_reserved_ranges()
633 size = gpiochip_count_reserved_ranges(gc); in gpiochip_apply_reserved_ranges()
652 if (start >= gc->ngpio || start + count > gc->ngpio) in gpiochip_apply_reserved_ranges()
655 bitmap_clear(gc->valid_mask, start, count); in gpiochip_apply_reserved_ranges()
662 static int gpiochip_init_valid_mask(struct gpio_chip *gc) in gpiochip_init_valid_mask() argument
666 if (!(gpiochip_count_reserved_ranges(gc) || gc->init_valid_mask)) in gpiochip_init_valid_mask()
669 gc->valid_mask = gpiochip_allocate_mask(gc); in gpiochip_init_valid_mask()
670 if (!gc->valid_mask) in gpiochip_init_valid_mask()
673 ret = gpiochip_apply_reserved_ranges(gc); in gpiochip_init_valid_mask()
677 if (gc->init_valid_mask) in gpiochip_init_valid_mask()
678 return gc->init_valid_mask(gc, in gpiochip_init_valid_mask()
679 gc->valid_mask, in gpiochip_init_valid_mask()
680 gc->ngpio); in gpiochip_init_valid_mask()
685 static void gpiochip_free_valid_mask(struct gpio_chip *gc) in gpiochip_free_valid_mask() argument
687 gpiochip_free_mask(&gc->valid_mask); in gpiochip_free_valid_mask()
690 static int gpiochip_add_pin_ranges(struct gpio_chip *gc) in gpiochip_add_pin_ranges() argument
697 if (device_property_present(&gc->gpiodev->dev, "gpio-ranges")) in gpiochip_add_pin_ranges()
700 if (gc->add_pin_ranges) in gpiochip_add_pin_ranges()
701 return gc->add_pin_ranges(gc); in gpiochip_add_pin_ranges()
706 bool gpiochip_line_is_valid(const struct gpio_chip *gc, in gpiochip_line_is_valid() argument
710 if (likely(!gc->valid_mask)) in gpiochip_line_is_valid()
712 return test_bit(offset, gc->valid_mask); in gpiochip_line_is_valid()
780 static void gpiochip_machine_hog(struct gpio_chip *gc, struct gpiod_hog *hog) in gpiochip_machine_hog() argument
785 desc = gpiochip_get_desc(gc, hog->chip_hwnum); in gpiochip_machine_hog()
787 chip_err(gc, "%s: unable to get GPIO desc: %ld\n", __func__, in gpiochip_machine_hog()
795 __func__, gc->label, hog->chip_hwnum, rv); in gpiochip_machine_hog()
798 static void machine_gpiochip_add(struct gpio_chip *gc) in machine_gpiochip_add() argument
805 if (!strcmp(gc->label, hog->chip_label)) in machine_gpiochip_add()
806 gpiochip_machine_hog(gc, hog); in machine_gpiochip_add()
828 static void gpiochip_set_data(struct gpio_chip *gc, void *data) in gpiochip_set_data() argument
830 gc->gpiodev->data = data; in gpiochip_set_data()
835 * @gc: GPIO chip
840 void *gpiochip_get_data(struct gpio_chip *gc) in gpiochip_get_data() argument
842 return gc->gpiodev->data; in gpiochip_get_data()
846 int gpiochip_get_ngpios(struct gpio_chip *gc, struct device *dev) in gpiochip_get_ngpios() argument
848 u32 ngpios = gc->ngpio; in gpiochip_get_ngpios()
864 gc->ngpio = ngpios; in gpiochip_get_ngpios()
867 if (gc->ngpio == 0) { in gpiochip_get_ngpios()
868 chip_err(gc, "tried to insert a GPIO chip with zero lines\n"); in gpiochip_get_ngpios()
872 if (gc->ngpio > FASTPATH_NGPIO) in gpiochip_get_ngpios()
873 chip_warn(gc, "line cnt %u is greater than fast path cnt %u\n", in gpiochip_get_ngpios()
874 gc->ngpio, FASTPATH_NGPIO); in gpiochip_get_ngpios()
880 int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, in gpiochip_add_data_with_key() argument
899 gdev->dev.parent = gc->parent; in gpiochip_add_data_with_key()
900 rcu_assign_pointer(gdev->chip, gc); in gpiochip_add_data_with_key()
902 gc->gpiodev = gdev; in gpiochip_add_data_with_key()
903 gpiochip_set_data(gc, data); in gpiochip_add_data_with_key()
909 if (gc->fwnode) in gpiochip_add_data_with_key()
910 device_set_node(&gdev->dev, gc->fwnode); in gpiochip_add_data_with_key()
911 else if (gc->parent) in gpiochip_add_data_with_key()
912 device_set_node(&gdev->dev, dev_fwnode(gc->parent)); in gpiochip_add_data_with_key()
924 if (gc->parent && gc->parent->driver) in gpiochip_add_data_with_key()
925 gdev->owner = gc->parent->driver->owner; in gpiochip_add_data_with_key()
926 else if (gc->owner) in gpiochip_add_data_with_key()
928 gdev->owner = gc->owner; in gpiochip_add_data_with_key()
932 ret = gpiochip_get_ngpios(gc, &gdev->dev); in gpiochip_add_data_with_key()
936 gdev->descs = kcalloc(gc->ngpio, sizeof(*gdev->descs), GFP_KERNEL); in gpiochip_add_data_with_key()
942 gdev->label = kstrdup_const(gc->label ?: "unknown", GFP_KERNEL); in gpiochip_add_data_with_key()
948 gdev->ngpio = gc->ngpio; in gpiochip_add_data_with_key()
949 gdev->can_sleep = gc->can_sleep; in gpiochip_add_data_with_key()
959 base = gc->base; in gpiochip_add_data_with_key()
961 base = gpiochip_find_base_unlocked(gc->ngpio); in gpiochip_add_data_with_key()
974 gc->base = base; in gpiochip_add_data_with_key()
984 chip_err(gc, "GPIO integer space overlap, cannot add chip\n"); in gpiochip_add_data_with_key()
989 for (desc_index = 0; desc_index < gc->ngpio; desc_index++) in gpiochip_add_data_with_key()
1007 if (gc->names) in gpiochip_add_data_with_key()
1008 gpiochip_set_desc_names(gc); in gpiochip_add_data_with_key()
1010 ret = gpiochip_set_names(gc); in gpiochip_add_data_with_key()
1014 ret = gpiochip_init_valid_mask(gc); in gpiochip_add_data_with_key()
1018 for (desc_index = 0; desc_index < gc->ngpio; desc_index++) { in gpiochip_add_data_with_key()
1021 if (gc->get_direction && gpiochip_line_is_valid(gc, desc_index)) { in gpiochip_add_data_with_key()
1023 &desc->flags, !gc->get_direction(gc, desc_index)); in gpiochip_add_data_with_key()
1026 &desc->flags, !gc->direction_input); in gpiochip_add_data_with_key()
1030 ret = of_gpiochip_add(gc); in gpiochip_add_data_with_key()
1034 ret = gpiochip_add_pin_ranges(gc); in gpiochip_add_data_with_key()
1038 acpi_gpiochip_add(gc); in gpiochip_add_data_with_key()
1040 machine_gpiochip_add(gc); in gpiochip_add_data_with_key()
1042 ret = gpiochip_irqchip_init_valid_mask(gc); in gpiochip_add_data_with_key()
1046 ret = gpiochip_irqchip_init_hw(gc); in gpiochip_add_data_with_key()
1050 ret = gpiochip_add_irqchip(gc, lock_key, request_key); in gpiochip_add_data_with_key()
1070 gpiochip_irqchip_remove(gc); in gpiochip_add_data_with_key()
1072 gpiochip_irqchip_free_valid_mask(gc); in gpiochip_add_data_with_key()
1074 gpiochip_free_hogs(gc); in gpiochip_add_data_with_key()
1075 acpi_gpiochip_remove(gc); in gpiochip_add_data_with_key()
1076 gpiochip_remove_pin_ranges(gc); in gpiochip_add_data_with_key()
1078 of_gpiochip_remove(gc); in gpiochip_add_data_with_key()
1080 gpiochip_free_valid_mask(gc); in gpiochip_add_data_with_key()
1108 base, base + (int)gc->ngpio - 1, in gpiochip_add_data_with_key()
1109 gc->label ? : "generic", ret); in gpiochip_add_data_with_key()
1117 * @gc: the chip to unregister
1121 void gpiochip_remove(struct gpio_chip *gc) in gpiochip_remove() argument
1123 struct gpio_device *gdev = gc->gpiodev; in gpiochip_remove()
1127 gpiochip_free_hogs(gc); in gpiochip_remove()
1136 gpiochip_irqchip_remove(gc); in gpiochip_remove()
1137 acpi_gpiochip_remove(gc); in gpiochip_remove()
1138 of_gpiochip_remove(gc); in gpiochip_remove()
1139 gpiochip_remove_pin_ranges(gc); in gpiochip_remove()
1140 gpiochip_free_valid_mask(gc); in gpiochip_remove()
1145 gpiochip_set_data(gc, NULL); in gpiochip_remove()
1180 int (*match)(struct gpio_chip *gc, in gpio_device_find() argument
1184 struct gpio_chip *gc; in gpio_device_find() local
1202 gc = srcu_dereference(gdev->chip, &gdev->srcu); in gpio_device_find()
1204 if (gc && match(gc, data)) in gpio_device_find()
1212 static int gpio_chip_match_by_label(struct gpio_chip *gc, const void *label) in gpio_chip_match_by_label() argument
1214 return gc->label && !strcmp(gc->label, label); in gpio_chip_match_by_label()
1232 static int gpio_chip_match_by_fwnode(struct gpio_chip *gc, const void *fwnode) in gpio_chip_match_by_fwnode() argument
1234 return device_match_fwnode(&gc->gpiodev->dev, fwnode); in gpio_chip_match_by_fwnode()
1299 static int gpiochip_irqchip_init_hw(struct gpio_chip *gc) in gpiochip_irqchip_init_hw() argument
1301 struct gpio_irq_chip *girq = &gc->irq; in gpiochip_irqchip_init_hw()
1306 return girq->init_hw(gc); in gpiochip_irqchip_init_hw()
1309 static int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gc) in gpiochip_irqchip_init_valid_mask() argument
1311 struct gpio_irq_chip *girq = &gc->irq; in gpiochip_irqchip_init_valid_mask()
1316 girq->valid_mask = gpiochip_allocate_mask(gc); in gpiochip_irqchip_init_valid_mask()
1320 girq->init_valid_mask(gc, girq->valid_mask, gc->ngpio); in gpiochip_irqchip_init_valid_mask()
1325 static void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gc) in gpiochip_irqchip_free_valid_mask() argument
1327 gpiochip_free_mask(&gc->irq.valid_mask); in gpiochip_irqchip_free_valid_mask()
1330 static bool gpiochip_irqchip_irq_valid(const struct gpio_chip *gc, in gpiochip_irqchip_irq_valid() argument
1333 if (!gpiochip_line_is_valid(gc, offset)) in gpiochip_irqchip_irq_valid()
1336 if (likely(!gc->irq.valid_mask)) in gpiochip_irqchip_irq_valid()
1338 return test_bit(offset, gc->irq.valid_mask); in gpiochip_irqchip_irq_valid()
1346 * @gc: the gpiochip to set the irqchip hierarchical handler to
1350 static void gpiochip_set_hierarchical_irqchip(struct gpio_chip *gc, in gpiochip_set_hierarchical_irqchip() argument
1354 if (is_of_node(gc->irq.fwnode)) in gpiochip_set_hierarchical_irqchip()
1365 if (is_fwnode_irqchip(gc->irq.fwnode)) { in gpiochip_set_hierarchical_irqchip()
1369 for (i = 0; i < gc->ngpio; i++) { in gpiochip_set_hierarchical_irqchip()
1373 struct gpio_irq_chip *girq = &gc->irq; in gpiochip_set_hierarchical_irqchip()
1381 ret = girq->child_to_parent_hwirq(gc, i, in gpiochip_set_hierarchical_irqchip()
1386 chip_err(gc, "skip set-up on hwirq %d\n", in gpiochip_set_hierarchical_irqchip()
1391 fwspec.fwnode = gc->irq.fwnode; in gpiochip_set_hierarchical_irqchip()
1393 fwspec.param[0] = girq->child_offset_to_irq(gc, i); in gpiochip_set_hierarchical_irqchip()
1397 ret = irq_domain_alloc_irqs(gc->irq.domain, 1, in gpiochip_set_hierarchical_irqchip()
1400 chip_err(gc, in gpiochip_set_hierarchical_irqchip()
1408 chip_err(gc, "%s unknown fwnode type proceed anyway\n", __func__); in gpiochip_set_hierarchical_irqchip()
1441 struct gpio_chip *gc = d->host_data; in gpiochip_hierarchy_irq_domain_alloc() local
1448 struct gpio_irq_chip *girq = &gc->irq; in gpiochip_hierarchy_irq_domain_alloc()
1457 ret = gc->irq.child_irq_domain_ops.translate(d, fwspec, &hwirq, &type); in gpiochip_hierarchy_irq_domain_alloc()
1461 chip_dbg(gc, "allocate IRQ %d, hwirq %lu\n", irq, hwirq); in gpiochip_hierarchy_irq_domain_alloc()
1463 ret = girq->child_to_parent_hwirq(gc, hwirq, type, in gpiochip_hierarchy_irq_domain_alloc()
1466 chip_err(gc, "can't look up hwirq %lu\n", hwirq); in gpiochip_hierarchy_irq_domain_alloc()
1469 chip_dbg(gc, "found parent hwirq %u\n", parent_hwirq); in gpiochip_hierarchy_irq_domain_alloc()
1478 gc->irq.chip, in gpiochip_hierarchy_irq_domain_alloc()
1479 gc, in gpiochip_hierarchy_irq_domain_alloc()
1485 ret = girq->populate_parent_alloc_arg(gc, &gpio_parent_fwspec, in gpiochip_hierarchy_irq_domain_alloc()
1490 chip_dbg(gc, "alloc_irqs_parent for %d parent hwirq %d\n", in gpiochip_hierarchy_irq_domain_alloc()
1492 irq_set_lockdep_class(irq, gc->irq.lock_key, gc->irq.request_key); in gpiochip_hierarchy_irq_domain_alloc()
1501 chip_err(gc, in gpiochip_hierarchy_irq_domain_alloc()
1508 static unsigned int gpiochip_child_offset_to_irq_noop(struct gpio_chip *gc, in gpiochip_child_offset_to_irq_noop() argument
1530 struct gpio_chip *gc = domain->host_data; in gpiochip_irq_domain_activate() local
1533 return gpiochip_lock_as_irq(gc, hwirq); in gpiochip_irq_domain_activate()
1548 struct gpio_chip *gc = domain->host_data; in gpiochip_irq_domain_deactivate() local
1551 return gpiochip_unlock_as_irq(gc, hwirq); in gpiochip_irq_domain_deactivate()
1573 static struct irq_domain *gpiochip_hierarchy_create_domain(struct gpio_chip *gc) in gpiochip_hierarchy_create_domain() argument
1577 if (!gc->irq.child_to_parent_hwirq || in gpiochip_hierarchy_create_domain()
1578 !gc->irq.fwnode) { in gpiochip_hierarchy_create_domain()
1579 chip_err(gc, "missing irqdomain vital data\n"); in gpiochip_hierarchy_create_domain()
1583 if (!gc->irq.child_offset_to_irq) in gpiochip_hierarchy_create_domain()
1584 gc->irq.child_offset_to_irq = gpiochip_child_offset_to_irq_noop; in gpiochip_hierarchy_create_domain()
1586 if (!gc->irq.populate_parent_alloc_arg) in gpiochip_hierarchy_create_domain()
1587 gc->irq.populate_parent_alloc_arg = in gpiochip_hierarchy_create_domain()
1590 gpiochip_hierarchy_setup_domain_ops(&gc->irq.child_irq_domain_ops); in gpiochip_hierarchy_create_domain()
1593 gc->irq.parent_domain, in gpiochip_hierarchy_create_domain()
1595 gc->ngpio, in gpiochip_hierarchy_create_domain()
1596 gc->irq.fwnode, in gpiochip_hierarchy_create_domain()
1597 &gc->irq.child_irq_domain_ops, in gpiochip_hierarchy_create_domain()
1598 gc); in gpiochip_hierarchy_create_domain()
1603 gpiochip_set_hierarchical_irqchip(gc, gc->irq.chip); in gpiochip_hierarchy_create_domain()
1608 static bool gpiochip_hierarchy_is_hierarchical(struct gpio_chip *gc) in gpiochip_hierarchy_is_hierarchical() argument
1610 return !!gc->irq.parent_domain; in gpiochip_hierarchy_is_hierarchical()
1613 int gpiochip_populate_parent_fwspec_twocell(struct gpio_chip *gc, in gpiochip_populate_parent_fwspec_twocell() argument
1620 fwspec->fwnode = gc->irq.parent_domain->fwnode; in gpiochip_populate_parent_fwspec_twocell()
1629 int gpiochip_populate_parent_fwspec_fourcell(struct gpio_chip *gc, in gpiochip_populate_parent_fwspec_fourcell() argument
1636 fwspec->fwnode = gc->irq.parent_domain->fwnode; in gpiochip_populate_parent_fwspec_fourcell()
1649 static struct irq_domain *gpiochip_hierarchy_create_domain(struct gpio_chip *gc) in gpiochip_hierarchy_create_domain() argument
1654 static bool gpiochip_hierarchy_is_hierarchical(struct gpio_chip *gc) in gpiochip_hierarchy_is_hierarchical() argument
1677 struct gpio_chip *gc = d->host_data; in gpiochip_irq_map() local
1680 if (!gpiochip_irqchip_irq_valid(gc, hwirq)) in gpiochip_irq_map()
1683 irq_set_chip_data(irq, gc); in gpiochip_irq_map()
1688 irq_set_lockdep_class(irq, gc->irq.lock_key, gc->irq.request_key); in gpiochip_irq_map()
1689 irq_set_chip_and_handler(irq, gc->irq.chip, gc->irq.handler); in gpiochip_irq_map()
1691 if (gc->irq.threaded) in gpiochip_irq_map()
1695 if (gc->irq.num_parents == 1) in gpiochip_irq_map()
1696 ret = irq_set_parent(irq, gc->irq.parents[0]); in gpiochip_irq_map()
1697 else if (gc->irq.map) in gpiochip_irq_map()
1698 ret = irq_set_parent(irq, gc->irq.map[hwirq]); in gpiochip_irq_map()
1707 if (gc->irq.default_type != IRQ_TYPE_NONE) in gpiochip_irq_map()
1708 irq_set_irq_type(irq, gc->irq.default_type); in gpiochip_irq_map()
1715 struct gpio_chip *gc = d->host_data; in gpiochip_irq_unmap() local
1717 if (gc->irq.threaded) in gpiochip_irq_unmap()
1730 static struct irq_domain *gpiochip_simple_create_domain(struct gpio_chip *gc) in gpiochip_simple_create_domain() argument
1732 struct fwnode_handle *fwnode = dev_fwnode(&gc->gpiodev->dev); in gpiochip_simple_create_domain()
1735 domain = irq_domain_create_simple(fwnode, gc->ngpio, gc->irq.first, in gpiochip_simple_create_domain()
1736 &gpiochip_domain_ops, gc); in gpiochip_simple_create_domain()
1743 static int gpiochip_to_irq(struct gpio_chip *gc, unsigned int offset) in gpiochip_to_irq() argument
1745 struct irq_domain *domain = gc->irq.domain; in gpiochip_to_irq()
1753 if (!gc->irq.initialized) in gpiochip_to_irq()
1757 if (!gpiochip_irqchip_irq_valid(gc, offset)) in gpiochip_to_irq()
1766 spec.param[0] = gc->irq.child_offset_to_irq(gc, offset); in gpiochip_to_irq()
1778 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); in gpiochip_irq_reqres() local
1781 return gpiochip_reqres_irq(gc, hwirq); in gpiochip_irq_reqres()
1787 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); in gpiochip_irq_relres() local
1790 gpiochip_relres_irq(gc, hwirq); in gpiochip_irq_relres()
1796 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); in gpiochip_irq_mask() local
1799 if (gc->irq.irq_mask) in gpiochip_irq_mask()
1800 gc->irq.irq_mask(d); in gpiochip_irq_mask()
1801 gpiochip_disable_irq(gc, hwirq); in gpiochip_irq_mask()
1806 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); in gpiochip_irq_unmask() local
1809 gpiochip_enable_irq(gc, hwirq); in gpiochip_irq_unmask()
1810 if (gc->irq.irq_unmask) in gpiochip_irq_unmask()
1811 gc->irq.irq_unmask(d); in gpiochip_irq_unmask()
1816 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); in gpiochip_irq_enable() local
1819 gpiochip_enable_irq(gc, hwirq); in gpiochip_irq_enable()
1820 gc->irq.irq_enable(d); in gpiochip_irq_enable()
1825 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); in gpiochip_irq_disable() local
1828 gc->irq.irq_disable(d); in gpiochip_irq_disable()
1829 gpiochip_disable_irq(gc, hwirq); in gpiochip_irq_disable()
1832 static void gpiochip_set_irq_hooks(struct gpio_chip *gc) in gpiochip_set_irq_hooks() argument
1834 struct irq_chip *irqchip = gc->irq.chip; in gpiochip_set_irq_hooks()
1839 chip_warn(gc, "not an immutable chip, please consider fixing it!\n"); in gpiochip_set_irq_hooks()
1846 if (WARN_ON(gc->irq.irq_enable)) in gpiochip_set_irq_hooks()
1855 chip_info(gc, in gpiochip_set_irq_hooks()
1861 gc->irq.irq_disable = irqchip->irq_disable; in gpiochip_set_irq_hooks()
1864 gc->irq.irq_mask = irqchip->irq_mask; in gpiochip_set_irq_hooks()
1869 gc->irq.irq_enable = irqchip->irq_enable; in gpiochip_set_irq_hooks()
1872 gc->irq.irq_unmask = irqchip->irq_unmask; in gpiochip_set_irq_hooks()
1877 static int gpiochip_irqchip_add_allocated_domain(struct gpio_chip *gc, in gpiochip_irqchip_add_allocated_domain() argument
1884 if (gc->to_irq) in gpiochip_irqchip_add_allocated_domain()
1885 chip_warn(gc, "to_irq is redefined in %s and you shouldn't rely on it\n", __func__); in gpiochip_irqchip_add_allocated_domain()
1887 gc->to_irq = gpiochip_to_irq; in gpiochip_irqchip_add_allocated_domain()
1888 gc->irq.domain = domain; in gpiochip_irqchip_add_allocated_domain()
1889 gc->irq.domain_is_allocated_externally = allocated_externally; in gpiochip_irqchip_add_allocated_domain()
1893 * gc->irq.initialized before adding irqdomain. in gpiochip_irqchip_add_allocated_domain()
1897 gc->irq.initialized = true; in gpiochip_irqchip_add_allocated_domain()
1904 * @gc: the GPIO chip to add the IRQ chip to
1911 static int gpiochip_add_irqchip(struct gpio_chip *gc, in gpiochip_add_irqchip() argument
1915 struct fwnode_handle *fwnode = dev_fwnode(&gc->gpiodev->dev); in gpiochip_add_irqchip()
1916 struct irq_chip *irqchip = gc->irq.chip; in gpiochip_add_irqchip()
1925 if (gc->irq.parent_handler && gc->can_sleep) { in gpiochip_add_irqchip()
1926 chip_err(gc, "you cannot have chained interrupts on a chip that may sleep\n"); in gpiochip_add_irqchip()
1930 type = gc->irq.default_type; in gpiochip_add_irqchip()
1941 gc->irq.default_type = type; in gpiochip_add_irqchip()
1942 gc->irq.lock_key = lock_key; in gpiochip_add_irqchip()
1943 gc->irq.request_key = request_key; in gpiochip_add_irqchip()
1946 if (gpiochip_hierarchy_is_hierarchical(gc)) { in gpiochip_add_irqchip()
1947 domain = gpiochip_hierarchy_create_domain(gc); in gpiochip_add_irqchip()
1949 domain = gpiochip_simple_create_domain(gc); in gpiochip_add_irqchip()
1954 if (gc->irq.parent_handler) { in gpiochip_add_irqchip()
1955 for (i = 0; i < gc->irq.num_parents; i++) { in gpiochip_add_irqchip()
1958 if (gc->irq.per_parent_data) in gpiochip_add_irqchip()
1959 data = gc->irq.parent_handler_data_array[i]; in gpiochip_add_irqchip()
1961 data = gc->irq.parent_handler_data ?: gc; in gpiochip_add_irqchip()
1968 irq_set_chained_handler_and_data(gc->irq.parents[i], in gpiochip_add_irqchip()
1969 gc->irq.parent_handler, in gpiochip_add_irqchip()
1974 gpiochip_set_irq_hooks(gc); in gpiochip_add_irqchip()
1976 ret = gpiochip_irqchip_add_allocated_domain(gc, domain, false); in gpiochip_add_irqchip()
1980 acpi_gpiochip_request_interrupts(gc); in gpiochip_add_irqchip()
1987 * @gc: the gpiochip to remove the irqchip from
1991 static void gpiochip_irqchip_remove(struct gpio_chip *gc) in gpiochip_irqchip_remove() argument
1993 struct irq_chip *irqchip = gc->irq.chip; in gpiochip_irqchip_remove()
1996 acpi_gpiochip_free_interrupts(gc); in gpiochip_irqchip_remove()
1998 if (irqchip && gc->irq.parent_handler) { in gpiochip_irqchip_remove()
1999 struct gpio_irq_chip *irq = &gc->irq; in gpiochip_irqchip_remove()
2008 if (!gc->irq.domain_is_allocated_externally && gc->irq.domain) { in gpiochip_irqchip_remove()
2011 for (offset = 0; offset < gc->ngpio; offset++) { in gpiochip_irqchip_remove()
2012 if (!gpiochip_irqchip_irq_valid(gc, offset)) in gpiochip_irqchip_remove()
2015 irq = irq_find_mapping(gc->irq.domain, offset); in gpiochip_irqchip_remove()
2019 irq_domain_remove(gc->irq.domain); in gpiochip_irqchip_remove()
2028 irqchip->irq_enable = gc->irq.irq_enable; in gpiochip_irqchip_remove()
2029 irqchip->irq_disable = gc->irq.irq_disable; in gpiochip_irqchip_remove()
2032 gc->irq.irq_enable = NULL; in gpiochip_irqchip_remove()
2033 gc->irq.irq_disable = NULL; in gpiochip_irqchip_remove()
2034 gc->irq.chip = NULL; in gpiochip_irqchip_remove()
2036 gpiochip_irqchip_free_valid_mask(gc); in gpiochip_irqchip_remove()
2041 * @gc: the gpiochip to add the irqchip to
2049 int gpiochip_irqchip_add_domain(struct gpio_chip *gc, in gpiochip_irqchip_add_domain() argument
2052 return gpiochip_irqchip_add_allocated_domain(gc, domain, true); in gpiochip_irqchip_add_domain()
2058 static inline int gpiochip_add_irqchip(struct gpio_chip *gc, in gpiochip_add_irqchip() argument
2064 static void gpiochip_irqchip_remove(struct gpio_chip *gc) {} in gpiochip_irqchip_remove() argument
2066 static inline int gpiochip_irqchip_init_hw(struct gpio_chip *gc) in gpiochip_irqchip_init_hw() argument
2071 static inline int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gc) in gpiochip_irqchip_init_valid_mask() argument
2075 static inline void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gc) in gpiochip_irqchip_free_valid_mask() argument
2082 * @gc: the gpiochip owning the GPIO
2088 int gpiochip_generic_request(struct gpio_chip *gc, unsigned int offset) in gpiochip_generic_request() argument
2091 if (list_empty(&gc->gpiodev->pin_ranges)) in gpiochip_generic_request()
2095 return pinctrl_gpio_request(gc, offset); in gpiochip_generic_request()
2101 * @gc: the gpiochip to request the gpio function for
2104 void gpiochip_generic_free(struct gpio_chip *gc, unsigned int offset) in gpiochip_generic_free() argument
2107 if (list_empty(&gc->gpiodev->pin_ranges)) in gpiochip_generic_free()
2111 pinctrl_gpio_free(gc, offset); in gpiochip_generic_free()
2117 * @gc: the gpiochip owning the GPIO
2124 int gpiochip_generic_config(struct gpio_chip *gc, unsigned int offset, in gpiochip_generic_config() argument
2128 if (list_empty(&gc->gpiodev->pin_ranges)) in gpiochip_generic_config()
2132 return pinctrl_gpio_set_config(gc, offset, config); in gpiochip_generic_config()
2140 * @gc: the gpiochip to add the range for
2153 int gpiochip_add_pingroup_range(struct gpio_chip *gc, in gpiochip_add_pingroup_range() argument
2158 struct gpio_device *gdev = gc->gpiodev; in gpiochip_add_pingroup_range()
2163 chip_err(gc, "failed to allocate pin ranges\n"); in gpiochip_add_pingroup_range()
2169 pin_range->range.gc = gc; in gpiochip_add_pingroup_range()
2170 pin_range->range.name = gc->label; in gpiochip_add_pingroup_range()
2184 chip_dbg(gc, "created GPIO range %d->%d ==> %s PINGRP %s\n", in gpiochip_add_pingroup_range()
2196 * @gc: the gpiochip to add the range for
2211 int gpiochip_add_pin_range(struct gpio_chip *gc, const char *pinctl_name, in gpiochip_add_pin_range() argument
2216 struct gpio_device *gdev = gc->gpiodev; in gpiochip_add_pin_range()
2221 chip_err(gc, "failed to allocate pin ranges\n"); in gpiochip_add_pin_range()
2227 pin_range->range.gc = gc; in gpiochip_add_pin_range()
2228 pin_range->range.name = gc->label; in gpiochip_add_pin_range()
2236 chip_err(gc, "could not create pin range\n"); in gpiochip_add_pin_range()
2240 chip_dbg(gc, "created GPIO range %d->%d ==> %s PIN %d->%d\n", in gpiochip_add_pin_range()
2253 * @gc: the chip to remove all the mappings for
2255 void gpiochip_remove_pin_ranges(struct gpio_chip *gc) in gpiochip_remove_pin_ranges() argument
2258 struct gpio_device *gdev = gc->gpiodev; in gpiochip_remove_pin_ranges()
2281 if (!guard.gc) in gpiod_request_commit()
2291 if (guard.gc->request) { in gpiod_request_commit()
2293 if (gpiochip_line_is_valid(guard.gc, offset)) in gpiod_request_commit()
2294 ret = guard.gc->request(guard.gc, offset); in gpiod_request_commit()
2301 if (guard.gc->get_direction) in gpiod_request_commit()
2376 if (guard.gc && test_bit(FLAG_REQUESTED, &flags)) { in gpiod_free_commit()
2377 if (guard.gc->free) in gpiod_free_commit()
2378 guard.gc->free(guard.gc, gpio_chip_hwgpio(desc)); in gpiod_free_commit()
2411 * @gc: GPIO chip controlling this line.
2421 char *gpiochip_dup_line_label(struct gpio_chip *gc, unsigned int offset) in gpiochip_dup_line_label() argument
2426 desc = gpiochip_get_desc(gc, offset); in gpiochip_dup_line_label()
2450 * @gc: GPIO chip
2469 struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *gc, in gpiochip_request_own_desc() argument
2475 struct gpio_desc *desc = gpiochip_get_desc(gc, hwnum); in gpiochip_request_own_desc()
2480 chip_err(gc, "failed to get GPIO %s descriptor\n", name); in gpiochip_request_own_desc()
2491 chip_err(gc, "setup of own GPIO %s failed\n", name); in gpiochip_request_own_desc()
2523 static int gpio_do_set_config(struct gpio_chip *gc, unsigned int offset, in gpio_do_set_config() argument
2526 if (!gc->set_config) in gpio_do_set_config()
2529 return gc->set_config(gc, offset, config); in gpio_do_set_config()
2539 if (!guard.gc) in gpio_set_config_with_argument()
2543 return gpio_do_set_config(guard.gc, gpio_chip_hwgpio(desc), config); in gpio_set_config_with_argument()
2640 if (!guard.gc) in gpiod_direction_input()
2648 if (!guard.gc->get && guard.gc->direction_input) { in gpiod_direction_input()
2661 if (guard.gc->direction_input) { in gpiod_direction_input()
2662 ret = guard.gc->direction_input(guard.gc, in gpiod_direction_input()
2664 } else if (guard.gc->get_direction && in gpiod_direction_input()
2665 (guard.gc->get_direction(guard.gc, in gpiod_direction_input()
2688 if (!guard.gc) in gpiod_direction_output_raw_commit()
2696 if (!guard.gc->set && !guard.gc->direction_output) { in gpiod_direction_output_raw_commit()
2703 if (guard.gc->direction_output) { in gpiod_direction_output_raw_commit()
2704 ret = guard.gc->direction_output(guard.gc, in gpiod_direction_output_raw_commit()
2708 if (guard.gc->get_direction && in gpiod_direction_output_raw_commit()
2709 guard.gc->get_direction(guard.gc, gpio_chip_hwgpio(desc))) { in gpiod_direction_output_raw_commit()
2719 guard.gc->set(guard.gc, gpio_chip_hwgpio(desc), val); in gpiod_direction_output_raw_commit()
2842 if (!guard.gc) in gpiod_enable_hw_timestamp_ns()
2845 if (!guard.gc->en_hw_timestamp) { in gpiod_enable_hw_timestamp_ns()
2850 ret = guard.gc->en_hw_timestamp(guard.gc, in gpiod_enable_hw_timestamp_ns()
2875 if (!guard.gc) in gpiod_disable_hw_timestamp_ns()
2878 if (!guard.gc->dis_hw_timestamp) { in gpiod_disable_hw_timestamp_ns()
2883 ret = guard.gc->dis_hw_timestamp(guard.gc, gpio_chip_hwgpio(desc), in gpiod_disable_hw_timestamp_ns()
2906 if (!guard.gc) in gpiod_set_config()
2909 return gpio_do_set_config(guard.gc, gpio_chip_hwgpio(desc), config); in gpiod_set_config()
2979 static int gpio_chip_get_value(struct gpio_chip *gc, const struct gpio_desc *desc) in gpio_chip_get_value() argument
2981 return gc->get ? gc->get(gc, gpio_chip_hwgpio(desc)) : -EIO; in gpio_chip_get_value()
3009 struct gpio_chip *gc; in gpiod_get_raw_value_commit() local
3017 gc = srcu_dereference(gdev->chip, &gdev->srcu); in gpiod_get_raw_value_commit()
3018 if (!gc) in gpiod_get_raw_value_commit()
3021 value = gpio_chip_get_value(gc, desc); in gpiod_get_raw_value_commit()
3027 static int gpio_chip_get_multiple(struct gpio_chip *gc, in gpio_chip_get_multiple() argument
3030 if (gc->get_multiple) in gpio_chip_get_multiple()
3031 return gc->get_multiple(gc, mask, bits); in gpio_chip_get_multiple()
3032 if (gc->get) { in gpio_chip_get_multiple()
3035 for_each_set_bit(i, mask, gc->ngpio) { in gpio_chip_get_multiple()
3036 value = gc->get(gc, i); in gpio_chip_get_multiple()
3047 static bool gpio_device_chip_cmp(struct gpio_device *gdev, struct gpio_chip *gc) in gpio_device_chip_cmp() argument
3051 return gc == srcu_dereference(gdev->chip, &gdev->srcu); in gpio_device_chip_cmp()
3097 if (!guard.gc) in gpiod_get_array_value_complex()
3100 if (likely(guard.gc->ngpio <= FASTPATH_NGPIO)) { in gpiod_get_array_value_complex()
3106 mask = bitmap_alloc(guard.gc->ngpio, flags); in gpiod_get_array_value_complex()
3110 bits = bitmap_alloc(guard.gc->ngpio, flags); in gpiod_get_array_value_complex()
3117 bitmap_zero(mask, guard.gc->ngpio); in gpiod_get_array_value_complex()
3120 WARN_ON(guard.gc->can_sleep); in gpiod_get_array_value_complex()
3135 gpio_device_chip_cmp(desc_array[i]->gdev, guard.gc)); in gpiod_get_array_value_complex()
3137 ret = gpio_chip_get_multiple(guard.gc, mask, bits); in gpiod_get_array_value_complex()
3288 if (!guard.gc) in gpio_set_open_drain_value_commit()
3292 ret = guard.gc->direction_input(guard.gc, offset); in gpio_set_open_drain_value_commit()
3294 ret = guard.gc->direction_output(guard.gc, offset, 0); in gpio_set_open_drain_value_commit()
3315 if (!guard.gc) in gpio_set_open_source_value_commit()
3319 ret = guard.gc->direction_output(guard.gc, offset, 1); in gpio_set_open_source_value_commit()
3323 ret = guard.gc->direction_input(guard.gc, offset); in gpio_set_open_source_value_commit()
3335 if (!guard.gc) in gpiod_set_raw_value_commit()
3339 guard.gc->set(guard.gc, gpio_chip_hwgpio(desc), value); in gpiod_set_raw_value_commit()
3352 static void gpio_chip_set_multiple(struct gpio_chip *gc, in gpio_chip_set_multiple() argument
3355 if (gc->set_multiple) { in gpio_chip_set_multiple()
3356 gc->set_multiple(gc, mask, bits); in gpio_chip_set_multiple()
3361 for_each_set_bit(i, mask, gc->ngpio) in gpio_chip_set_multiple()
3362 gc->set(gc, i, test_bit(i, bits)); in gpio_chip_set_multiple()
3406 if (!guard.gc) in gpiod_set_array_value_complex()
3409 if (likely(guard.gc->ngpio <= FASTPATH_NGPIO)) { in gpiod_set_array_value_complex()
3415 mask = bitmap_alloc(guard.gc->ngpio, flags); in gpiod_set_array_value_complex()
3419 bits = bitmap_alloc(guard.gc->ngpio, flags); in gpiod_set_array_value_complex()
3426 bitmap_zero(mask, guard.gc->ngpio); in gpiod_set_array_value_complex()
3429 WARN_ON(guard.gc->can_sleep); in gpiod_set_array_value_complex()
3465 gpio_device_chip_cmp(desc_array[i]->gdev, guard.gc)); in gpiod_set_array_value_complex()
3468 gpio_chip_set_multiple(guard.gc, mask, bits); in gpiod_set_array_value_complex()
3636 struct gpio_chip *gc; in gpiod_to_irq() local
3650 gc = srcu_dereference(gdev->chip, &gdev->srcu); in gpiod_to_irq()
3651 if (!gc) in gpiod_to_irq()
3655 if (gc->to_irq) { in gpiod_to_irq()
3656 int retirq = gc->to_irq(gc, offset); in gpiod_to_irq()
3665 if (gc->irq.chip) { in gpiod_to_irq()
3680 * @gc: the chip the GPIO to lock belongs to
3689 int gpiochip_lock_as_irq(struct gpio_chip *gc, unsigned int offset) in gpiochip_lock_as_irq() argument
3693 desc = gpiochip_get_desc(gc, offset); in gpiochip_lock_as_irq()
3701 if (!gc->can_sleep && gc->get_direction) { in gpiochip_lock_as_irq()
3705 chip_err(gc, "%s: cannot get GPIO direction\n", in gpiochip_lock_as_irq()
3714 chip_err(gc, in gpiochip_lock_as_irq()
3729 * @gc: the chip the GPIO to lock belongs to
3735 void gpiochip_unlock_as_irq(struct gpio_chip *gc, unsigned int offset) in gpiochip_unlock_as_irq() argument
3739 desc = gpiochip_get_desc(gc, offset); in gpiochip_unlock_as_irq()
3748 void gpiochip_disable_irq(struct gpio_chip *gc, unsigned int offset) in gpiochip_disable_irq() argument
3750 struct gpio_desc *desc = gpiochip_get_desc(gc, offset); in gpiochip_disable_irq()
3758 void gpiochip_enable_irq(struct gpio_chip *gc, unsigned int offset) in gpiochip_enable_irq() argument
3760 struct gpio_desc *desc = gpiochip_get_desc(gc, offset); in gpiochip_enable_irq()
3775 bool gpiochip_line_is_irq(struct gpio_chip *gc, unsigned int offset) in gpiochip_line_is_irq() argument
3777 if (offset >= gc->ngpio) in gpiochip_line_is_irq()
3780 return test_bit(FLAG_USED_AS_IRQ, &gc->gpiodev->descs[offset].flags); in gpiochip_line_is_irq()
3784 int gpiochip_reqres_irq(struct gpio_chip *gc, unsigned int offset) in gpiochip_reqres_irq() argument
3788 if (!try_module_get(gc->gpiodev->owner)) in gpiochip_reqres_irq()
3791 ret = gpiochip_lock_as_irq(gc, offset); in gpiochip_reqres_irq()
3793 chip_err(gc, "unable to lock HW IRQ %u for IRQ\n", offset); in gpiochip_reqres_irq()
3794 module_put(gc->gpiodev->owner); in gpiochip_reqres_irq()
3801 void gpiochip_relres_irq(struct gpio_chip *gc, unsigned int offset) in gpiochip_relres_irq() argument
3803 gpiochip_unlock_as_irq(gc, offset); in gpiochip_relres_irq()
3804 module_put(gc->gpiodev->owner); in gpiochip_relres_irq()
3808 bool gpiochip_line_is_open_drain(struct gpio_chip *gc, unsigned int offset) in gpiochip_line_is_open_drain() argument
3810 if (offset >= gc->ngpio) in gpiochip_line_is_open_drain()
3813 return test_bit(FLAG_OPEN_DRAIN, &gc->gpiodev->descs[offset].flags); in gpiochip_line_is_open_drain()
3817 bool gpiochip_line_is_open_source(struct gpio_chip *gc, unsigned int offset) in gpiochip_line_is_open_source() argument
3819 if (offset >= gc->ngpio) in gpiochip_line_is_open_source()
3822 return test_bit(FLAG_OPEN_SOURCE, &gc->gpiodev->descs[offset].flags); in gpiochip_line_is_open_source()
3826 bool gpiochip_line_is_persistent(struct gpio_chip *gc, unsigned int offset) in gpiochip_line_is_persistent() argument
3828 if (offset >= gc->ngpio) in gpiochip_line_is_persistent()
3831 return !test_bit(FLAG_TRANSITORY, &gc->gpiodev->descs[offset].flags); in gpiochip_line_is_persistent()
4152 struct gpio_chip *gc; in gpiod_find() local
4196 gc = gpio_device_get_chip(gdev); in gpiod_find()
4198 if (gc->ngpio <= p->chip_hwnum) { in gpiod_find()
4201 idx, p->chip_hwnum, gc->ngpio - 1, in gpiod_find()
4202 gc->label); in gpiod_find()
4588 if (!guard.gc) in gpiod_hog()
4596 local_desc = gpiochip_request_own_desc(guard.gc, hwnum, name, in gpiod_hog()
4616 * @gc: gpio chip to act on
4618 static void gpiochip_free_hogs(struct gpio_chip *gc) in gpiochip_free_hogs() argument
4622 for_each_gpio_desc_with_flag(gc, desc, FLAG_IS_HOGGED) in gpiochip_free_hogs()
4647 struct gpio_chip *gc; in gpiod_get_array() local
4669 gc = gpiod_to_chip(desc); in gpiod_get_array()
4677 bitmap_size = BITS_TO_LONGS(gc->ngpio > count ? in gpiod_get_array()
4678 gc->ngpio : count); in gpiod_get_array()
4698 array_info->chip = gc; in gpiod_get_array()
4711 if (array_info->chip != gc) { in gpiod_get_array()
4735 if (gpiochip_line_is_open_drain(gc, descs->ndescs) || in gpiod_get_array()
4736 gpiochip_line_is_open_source(gc, descs->ndescs)) in gpiod_get_array()
4880 struct gpio_chip *gc; in gpiolib_dbg_show() local
4885 gc = srcu_dereference(gdev->chip, &gdev->srcu); in gpiolib_dbg_show()
4886 if (!gc) { in gpiolib_dbg_show()
4891 for_each_gpio_desc(gc, desc) { in gpiolib_dbg_show()
4897 value = gpio_chip_get_value(gc, desc); in gpiolib_dbg_show()
4967 struct gpio_chip *gc; in gpiolib_seq_show() local
4972 gc = srcu_dereference(gdev->chip, &gdev->srcu); in gpiolib_seq_show()
4973 if (!gc) { in gpiolib_seq_show()
4983 parent = gc->parent; in gpiolib_seq_show()
4988 if (gc->label) in gpiolib_seq_show()
4989 seq_printf(s, ", %s", gc->label); in gpiolib_seq_show()
4990 if (gc->can_sleep) in gpiolib_seq_show()
4994 if (gc->dbg_show) in gpiolib_seq_show()
4995 gc->dbg_show(s, gc); in gpiolib_seq_show()