Lines Matching refs:gc

91 static void gpiochip_free_hogs(struct gpio_chip *gc);
92 static int gpiochip_add_irqchip(struct gpio_chip *gc,
95 static void gpiochip_irqchip_remove(struct gpio_chip *gc);
96 static int gpiochip_irqchip_init_hw(struct gpio_chip *gc);
97 static int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gc);
98 static void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gc);
161 struct gpio_desc *gpiochip_get_desc(struct gpio_chip *gc,
164 return gpio_device_get_desc(gc->gpiodev, hwnum);
347 if (!guard.gc)
361 if (!guard.gc->get_direction)
364 ret = guard.gc->get_direction(guard.gc, offset);
440 struct gpio_chip *gc;
451 gc = srcu_dereference(gdev->chip, &gdev->srcu);
452 if (!gc)
455 for_each_gpio_desc(gc, desc) {
465 * Take the names from gc->names and assign them to their GPIO descriptors.
472 static int gpiochip_set_desc_names(struct gpio_chip *gc)
474 struct gpio_device *gdev = gc->gpiodev;
478 for (i = 0; i != gc->ngpio; ++i) {
481 gpio = gpio_name_to_desc(gc->names[i]);
485 gc->names[i]);
489 for (i = 0; i != gc->ngpio; ++i)
490 gdev->descs[i].name = gc->names[i];
572 static unsigned long *gpiochip_allocate_mask(struct gpio_chip *gc)
576 p = bitmap_alloc(gc->ngpio, GFP_KERNEL);
581 bitmap_fill(p, gc->ngpio);
592 static unsigned int gpiochip_count_reserved_ranges(struct gpio_chip *gc)
594 struct device *dev = &gc->gpiodev->dev;
605 static int gpiochip_apply_reserved_ranges(struct gpio_chip *gc)
607 struct device *dev = &gc->gpiodev->dev;
612 size = gpiochip_count_reserved_ranges(gc);
631 if (start >= gc->ngpio || start + count > gc->ngpio)
634 bitmap_clear(gc->valid_mask, start, count);
641 static int gpiochip_init_valid_mask(struct gpio_chip *gc)
645 if (!(gpiochip_count_reserved_ranges(gc) || gc->init_valid_mask))
648 gc->valid_mask = gpiochip_allocate_mask(gc);
649 if (!gc->valid_mask)
652 ret = gpiochip_apply_reserved_ranges(gc);
656 if (gc->init_valid_mask)
657 return gc->init_valid_mask(gc,
658 gc->valid_mask,
659 gc->ngpio);
664 static void gpiochip_free_valid_mask(struct gpio_chip *gc)
666 gpiochip_free_mask(&gc->valid_mask);
669 static int gpiochip_add_pin_ranges(struct gpio_chip *gc)
676 if (device_property_present(&gc->gpiodev->dev, "gpio-ranges"))
679 if (gc->add_pin_ranges)
680 return gc->add_pin_ranges(gc);
685 bool gpiochip_line_is_valid(const struct gpio_chip *gc,
689 if (likely(!gc->valid_mask))
691 return test_bit(offset, gc->valid_mask);
759 static void gpiochip_machine_hog(struct gpio_chip *gc, struct gpiod_hog *hog)
764 desc = gpiochip_get_desc(gc, hog->chip_hwnum);
766 chip_err(gc, "%s: unable to get GPIO desc: %ld\n", __func__,
774 __func__, gc->label, hog->chip_hwnum, rv);
777 static void machine_gpiochip_add(struct gpio_chip *gc)
784 if (!strcmp(gc->label, hog->chip_label))
785 gpiochip_machine_hog(gc, hog);
807 static void gpiochip_set_data(struct gpio_chip *gc, void *data)
809 gc->gpiodev->data = data;
814 * @gc: GPIO chip
819 void *gpiochip_get_data(struct gpio_chip *gc)
821 return gc->gpiodev->data;
825 int gpiochip_get_ngpios(struct gpio_chip *gc, struct device *dev)
827 u32 ngpios = gc->ngpio;
843 gc->ngpio = ngpios;
846 if (gc->ngpio == 0) {
847 chip_err(gc, "tried to insert a GPIO chip with zero lines\n");
851 if (gc->ngpio > FASTPATH_NGPIO)
852 chip_warn(gc, "line cnt %u is greater than fast path cnt %u\n",
853 gc->ngpio, FASTPATH_NGPIO);
859 int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
878 gdev->dev.parent = gc->parent;
879 rcu_assign_pointer(gdev->chip, gc);
881 gc->gpiodev = gdev;
882 gpiochip_set_data(gc, data);
888 if (gc->fwnode)
889 device_set_node(&gdev->dev, gc->fwnode);
890 else if (gc->parent)
891 device_set_node(&gdev->dev, dev_fwnode(gc->parent));
903 if (gc->parent && gc->parent->driver)
904 gdev->owner = gc->parent->driver->owner;
905 else if (gc->owner)
907 gdev->owner = gc->owner;
911 ret = gpiochip_get_ngpios(gc, &gdev->dev);
915 gdev->descs = kcalloc(gc->ngpio, sizeof(*gdev->descs), GFP_KERNEL);
921 gdev->label = kstrdup_const(gc->label ?: "unknown", GFP_KERNEL);
927 gdev->ngpio = gc->ngpio;
928 gdev->can_sleep = gc->can_sleep;
938 base = gc->base;
940 base = gpiochip_find_base_unlocked(gc->ngpio);
953 gc->base = base;
963 chip_err(gc, "GPIO integer space overlap, cannot add chip\n");
968 for (desc_index = 0; desc_index < gc->ngpio; desc_index++)
982 if (gc->names) {
983 ret = gpiochip_set_desc_names(gc);
987 ret = gpiochip_set_names(gc);
991 ret = gpiochip_init_valid_mask(gc);
995 for (desc_index = 0; desc_index < gc->ngpio; desc_index++) {
1002 if (gc->get_direction && gpiochip_line_is_valid(gc, desc_index)) {
1004 &desc->flags, !gc->get_direction(gc, desc_index));
1007 &desc->flags, !gc->direction_input);
1011 ret = of_gpiochip_add(gc);
1015 ret = gpiochip_add_pin_ranges(gc);
1019 acpi_gpiochip_add(gc);
1021 machine_gpiochip_add(gc);
1023 ret = gpiochip_irqchip_init_valid_mask(gc);
1027 ret = gpiochip_irqchip_init_hw(gc);
1031 ret = gpiochip_add_irqchip(gc, lock_key, request_key);
1051 gpiochip_irqchip_remove(gc);
1053 gpiochip_irqchip_free_valid_mask(gc);
1055 gpiochip_free_hogs(gc);
1056 acpi_gpiochip_remove(gc);
1057 gpiochip_remove_pin_ranges(gc);
1059 of_gpiochip_remove(gc);
1063 gpiochip_free_valid_mask(gc);
1089 base, base + (int)gc->ngpio - 1,
1090 gc->label ? : "generic", ret);
1098 * @gc: the chip to unregister
1102 void gpiochip_remove(struct gpio_chip *gc)
1104 struct gpio_device *gdev = gc->gpiodev;
1108 gpiochip_free_hogs(gc);
1117 gpiochip_irqchip_remove(gc);
1118 acpi_gpiochip_remove(gc);
1119 of_gpiochip_remove(gc);
1120 gpiochip_remove_pin_ranges(gc);
1121 gpiochip_free_valid_mask(gc);
1126 gpiochip_set_data(gc, NULL);
1161 int (*match)(struct gpio_chip *gc,
1165 struct gpio_chip *gc;
1183 gc = srcu_dereference(gdev->chip, &gdev->srcu);
1185 if (gc && match(gc, data))
1193 static int gpio_chip_match_by_label(struct gpio_chip *gc, const void *label)
1195 return gc->label && !strcmp(gc->label, label);
1213 static int gpio_chip_match_by_fwnode(struct gpio_chip *gc, const void *fwnode)
1215 return device_match_fwnode(&gc->gpiodev->dev, fwnode);
1280 static int gpiochip_irqchip_init_hw(struct gpio_chip *gc)
1282 struct gpio_irq_chip *girq = &gc->irq;
1287 return girq->init_hw(gc);
1290 static int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gc)
1292 struct gpio_irq_chip *girq = &gc->irq;
1297 girq->valid_mask = gpiochip_allocate_mask(gc);
1301 girq->init_valid_mask(gc, girq->valid_mask, gc->ngpio);
1306 static void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gc)
1308 gpiochip_free_mask(&gc->irq.valid_mask);
1311 static bool gpiochip_irqchip_irq_valid(const struct gpio_chip *gc,
1314 if (!gpiochip_line_is_valid(gc, offset))
1317 if (likely(!gc->irq.valid_mask))
1319 return test_bit(offset, gc->irq.valid_mask);
1327 * @gc: the gpiochip to set the irqchip hierarchical handler to
1331 static void gpiochip_set_hierarchical_irqchip(struct gpio_chip *gc,
1335 if (is_of_node(gc->irq.fwnode))
1346 if (is_fwnode_irqchip(gc->irq.fwnode)) {
1350 for (i = 0; i < gc->ngpio; i++) {
1354 struct gpio_irq_chip *girq = &gc->irq;
1362 ret = girq->child_to_parent_hwirq(gc, i,
1367 chip_err(gc, "skip set-up on hwirq %d\n",
1372 fwspec.fwnode = gc->irq.fwnode;
1374 fwspec.param[0] = girq->child_offset_to_irq(gc, i);
1378 ret = irq_domain_alloc_irqs(gc->irq.domain, 1,
1381 chip_err(gc,
1389 chip_err(gc, "%s unknown fwnode type proceed anyway\n", __func__);
1422 struct gpio_chip *gc = d->host_data;
1429 struct gpio_irq_chip *girq = &gc->irq;
1438 ret = gc->irq.child_irq_domain_ops.translate(d, fwspec, &hwirq, &type);
1442 chip_dbg(gc, "allocate IRQ %d, hwirq %lu\n", irq, hwirq);
1444 ret = girq->child_to_parent_hwirq(gc, hwirq, type,
1447 chip_err(gc, "can't look up hwirq %lu\n", hwirq);
1450 chip_dbg(gc, "found parent hwirq %u\n", parent_hwirq);
1459 gc->irq.chip,
1460 gc,
1466 ret = girq->populate_parent_alloc_arg(gc, &gpio_parent_fwspec,
1471 chip_dbg(gc, "alloc_irqs_parent for %d parent hwirq %d\n",
1473 irq_set_lockdep_class(irq, gc->irq.lock_key, gc->irq.request_key);
1482 chip_err(gc,
1489 static unsigned int gpiochip_child_offset_to_irq_noop(struct gpio_chip *gc,
1508 struct gpio_chip *gc = domain->host_data;
1511 return gpiochip_lock_as_irq(gc, hwirq);
1526 struct gpio_chip *gc = domain->host_data;
1529 return gpiochip_unlock_as_irq(gc, hwirq);
1551 static struct irq_domain *gpiochip_hierarchy_create_domain(struct gpio_chip *gc)
1555 if (!gc->irq.child_to_parent_hwirq ||
1556 !gc->irq.fwnode) {
1557 chip_err(gc, "missing irqdomain vital data\n");
1561 if (!gc->irq.child_offset_to_irq)
1562 gc->irq.child_offset_to_irq = gpiochip_child_offset_to_irq_noop;
1564 if (!gc->irq.populate_parent_alloc_arg)
1565 gc->irq.populate_parent_alloc_arg =
1568 gpiochip_hierarchy_setup_domain_ops(&gc->irq.child_irq_domain_ops);
1571 gc->irq.parent_domain,
1573 gc->ngpio,
1574 gc->irq.fwnode,
1575 &gc->irq.child_irq_domain_ops,
1576 gc);
1581 gpiochip_set_hierarchical_irqchip(gc, gc->irq.chip);
1586 static bool gpiochip_hierarchy_is_hierarchical(struct gpio_chip *gc)
1588 return !!gc->irq.parent_domain;
1591 int gpiochip_populate_parent_fwspec_twocell(struct gpio_chip *gc,
1598 fwspec->fwnode = gc->irq.parent_domain->fwnode;
1607 int gpiochip_populate_parent_fwspec_fourcell(struct gpio_chip *gc,
1614 fwspec->fwnode = gc->irq.parent_domain->fwnode;
1627 static struct irq_domain *gpiochip_hierarchy_create_domain(struct gpio_chip *gc)
1632 static bool gpiochip_hierarchy_is_hierarchical(struct gpio_chip *gc)
1652 struct gpio_chip *gc = d->host_data;
1655 if (!gpiochip_irqchip_irq_valid(gc, hwirq))
1658 irq_set_chip_data(irq, gc);
1663 irq_set_lockdep_class(irq, gc->irq.lock_key, gc->irq.request_key);
1664 irq_set_chip_and_handler(irq, gc->irq.chip, gc->irq.handler);
1666 if (gc->irq.threaded)
1670 if (gc->irq.num_parents == 1)
1671 ret = irq_set_parent(irq, gc->irq.parents[0]);
1672 else if (gc->irq.map)
1673 ret = irq_set_parent(irq, gc->irq.map[hwirq]);
1682 if (gc->irq.default_type != IRQ_TYPE_NONE)
1683 irq_set_irq_type(irq, gc->irq.default_type);
1690 struct gpio_chip *gc = d->host_data;
1692 if (gc->irq.threaded)
1705 static struct irq_domain *gpiochip_simple_create_domain(struct gpio_chip *gc)
1707 struct fwnode_handle *fwnode = dev_fwnode(&gc->gpiodev->dev);
1710 domain = irq_domain_create_simple(fwnode, gc->ngpio, gc->irq.first,
1711 &gpiochip_domain_ops, gc);
1718 static int gpiochip_to_irq(struct gpio_chip *gc, unsigned int offset)
1720 struct irq_domain *domain = gc->irq.domain;
1728 if (!gc->irq.initialized)
1732 if (!gpiochip_irqchip_irq_valid(gc, offset))
1741 spec.param[0] = gc->irq.child_offset_to_irq(gc, offset);
1753 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
1756 return gpiochip_reqres_irq(gc, hwirq);
1762 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
1765 gpiochip_relres_irq(gc, hwirq);
1771 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
1774 if (gc->irq.irq_mask)
1775 gc->irq.irq_mask(d);
1776 gpiochip_disable_irq(gc, hwirq);
1781 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
1784 gpiochip_enable_irq(gc, hwirq);
1785 if (gc->irq.irq_unmask)
1786 gc->irq.irq_unmask(d);
1791 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
1794 gpiochip_enable_irq(gc, hwirq);
1795 gc->irq.irq_enable(d);
1800 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
1803 gc->irq.irq_disable(d);
1804 gpiochip_disable_irq(gc, hwirq);
1807 static void gpiochip_set_irq_hooks(struct gpio_chip *gc)
1809 struct irq_chip *irqchip = gc->irq.chip;
1814 chip_warn(gc, "not an immutable chip, please consider fixing it!\n");
1821 if (WARN_ON(gc->irq.irq_enable))
1830 chip_info(gc,
1836 gc->irq.irq_disable = irqchip->irq_disable;
1839 gc->irq.irq_mask = irqchip->irq_mask;
1844 gc->irq.irq_enable = irqchip->irq_enable;
1847 gc->irq.irq_unmask = irqchip->irq_unmask;
1852 static int gpiochip_irqchip_add_allocated_domain(struct gpio_chip *gc,
1859 if (gc->to_irq)
1860 chip_warn(gc, "to_irq is redefined in %s and you shouldn't rely on it\n", __func__);
1862 gc->to_irq = gpiochip_to_irq;
1863 gc->irq.domain = domain;
1864 gc->irq.domain_is_allocated_externally = allocated_externally;
1868 * gc->irq.initialized before adding irqdomain.
1872 gc->irq.initialized = true;
1879 * @gc: the GPIO chip to add the IRQ chip to
1883 static int gpiochip_add_irqchip(struct gpio_chip *gc,
1887 struct fwnode_handle *fwnode = dev_fwnode(&gc->gpiodev->dev);
1888 struct irq_chip *irqchip = gc->irq.chip;
1897 if (gc->irq.parent_handler && gc->can_sleep) {
1898 chip_err(gc, "you cannot have chained interrupts on a chip that may sleep\n");
1902 type = gc->irq.default_type;
1913 gc->irq.default_type = type;
1914 gc->irq.lock_key = lock_key;
1915 gc->irq.request_key = request_key;
1918 if (gpiochip_hierarchy_is_hierarchical(gc)) {
1919 domain = gpiochip_hierarchy_create_domain(gc);
1921 domain = gpiochip_simple_create_domain(gc);
1926 if (gc->irq.parent_handler) {
1927 for (i = 0; i < gc->irq.num_parents; i++) {
1930 if (gc->irq.per_parent_data)
1931 data = gc->irq.parent_handler_data_array[i];
1933 data = gc->irq.parent_handler_data ?: gc;
1940 irq_set_chained_handler_and_data(gc->irq.parents[i],
1941 gc->irq.parent_handler,
1946 gpiochip_set_irq_hooks(gc);
1948 ret = gpiochip_irqchip_add_allocated_domain(gc, domain, false);
1952 acpi_gpiochip_request_interrupts(gc);
1959 * @gc: the gpiochip to remove the irqchip from
1963 static void gpiochip_irqchip_remove(struct gpio_chip *gc)
1965 struct irq_chip *irqchip = gc->irq.chip;
1968 acpi_gpiochip_free_interrupts(gc);
1970 if (irqchip && gc->irq.parent_handler) {
1971 struct gpio_irq_chip *irq = &gc->irq;
1980 if (!gc->irq.domain_is_allocated_externally && gc->irq.domain) {
1983 for (offset = 0; offset < gc->ngpio; offset++) {
1984 if (!gpiochip_irqchip_irq_valid(gc, offset))
1987 irq = irq_find_mapping(gc->irq.domain, offset);
1991 irq_domain_remove(gc->irq.domain);
2000 irqchip->irq_enable = gc->irq.irq_enable;
2001 irqchip->irq_disable = gc->irq.irq_disable;
2004 gc->irq.irq_enable = NULL;
2005 gc->irq.irq_disable = NULL;
2006 gc->irq.chip = NULL;
2008 gpiochip_irqchip_free_valid_mask(gc);
2013 * @gc: the gpiochip to add the irqchip to
2018 int gpiochip_irqchip_add_domain(struct gpio_chip *gc,
2021 return gpiochip_irqchip_add_allocated_domain(gc, domain, true);
2027 static inline int gpiochip_add_irqchip(struct gpio_chip *gc,
2033 static void gpiochip_irqchip_remove(struct gpio_chip *gc) {}
2035 static inline int gpiochip_irqchip_init_hw(struct gpio_chip *gc)
2040 static inline int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gc)
2044 static inline void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gc)
2051 * @gc: the gpiochip owning the GPIO
2054 int gpiochip_generic_request(struct gpio_chip *gc, unsigned int offset)
2057 if (list_empty(&gc->gpiodev->pin_ranges))
2061 return pinctrl_gpio_request(gc, offset);
2067 * @gc: the gpiochip to request the gpio function for
2070 void gpiochip_generic_free(struct gpio_chip *gc, unsigned int offset)
2073 if (list_empty(&gc->gpiodev->pin_ranges))
2077 pinctrl_gpio_free(gc, offset);
2083 * @gc: the gpiochip owning the GPIO
2087 int gpiochip_generic_config(struct gpio_chip *gc, unsigned int offset,
2091 if (list_empty(&gc->gpiodev->pin_ranges))
2095 return pinctrl_gpio_set_config(gc, offset, config);
2103 * @gc: the gpiochip to add the range for
2113 int gpiochip_add_pingroup_range(struct gpio_chip *gc,
2118 struct gpio_device *gdev = gc->gpiodev;
2123 chip_err(gc, "failed to allocate pin ranges\n");
2129 pin_range->range.gc = gc;
2130 pin_range->range.name = gc->label;
2144 chip_dbg(gc, "created GPIO range %d->%d ==> %s PINGRP %s\n",
2156 * @gc: the gpiochip to add the range for
2171 int gpiochip_add_pin_range(struct gpio_chip *gc, const char *pinctl_name,
2176 struct gpio_device *gdev = gc->gpiodev;
2181 chip_err(gc, "failed to allocate pin ranges\n");
2187 pin_range->range.gc = gc;
2188 pin_range->range.name = gc->label;
2196 chip_err(gc, "could not create pin range\n");
2200 chip_dbg(gc, "created GPIO range %d->%d ==> %s PIN %d->%d\n",
2213 * @gc: the chip to remove all the mappings for
2215 void gpiochip_remove_pin_ranges(struct gpio_chip *gc)
2218 struct gpio_device *gdev = gc->gpiodev;
2241 if (!guard.gc)
2251 if (guard.gc->request) {
2253 if (gpiochip_line_is_valid(guard.gc, offset))
2254 ret = guard.gc->request(guard.gc, offset);
2261 if (guard.gc->get_direction)
2336 if (guard.gc && test_bit(FLAG_REQUESTED, &flags)) {
2337 if (guard.gc->free)
2338 guard.gc->free(guard.gc, gpio_chip_hwgpio(desc));
2371 * @gc: GPIO chip controlling this line.
2381 char *gpiochip_dup_line_label(struct gpio_chip *gc, unsigned int offset)
2386 desc = gpiochip_get_desc(gc, offset);
2410 * @gc: GPIO chip
2429 struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *gc,
2435 struct gpio_desc *desc = gpiochip_get_desc(gc, hwnum);
2440 chip_err(gc, "failed to get GPIO %s descriptor\n", name);
2451 chip_err(gc, "setup of own GPIO %s failed\n", name);
2483 static int gpio_do_set_config(struct gpio_chip *gc, unsigned int offset,
2486 if (!gc->set_config)
2489 return gc->set_config(gc, offset, config);
2499 if (!guard.gc)
2503 return gpio_do_set_config(guard.gc, gpio_chip_hwgpio(desc), config);
2598 if (!guard.gc)
2606 if (!guard.gc->get && guard.gc->direction_input) {
2619 if (guard.gc->direction_input) {
2620 ret = guard.gc->direction_input(guard.gc,
2622 } else if (guard.gc->get_direction &&
2623 (guard.gc->get_direction(guard.gc,
2646 if (!guard.gc)
2654 if (!guard.gc->set && !guard.gc->direction_output) {
2661 if (guard.gc->direction_output) {
2662 ret = guard.gc->direction_output(guard.gc,
2666 if (guard.gc->get_direction &&
2667 guard.gc->get_direction(guard.gc, gpio_chip_hwgpio(desc))) {
2677 guard.gc->set(guard.gc, gpio_chip_hwgpio(desc), val);
2797 if (!guard.gc)
2800 if (!guard.gc->en_hw_timestamp) {
2805 ret = guard.gc->en_hw_timestamp(guard.gc,
2829 if (!guard.gc)
2832 if (!guard.gc->dis_hw_timestamp) {
2837 ret = guard.gc->dis_hw_timestamp(guard.gc, gpio_chip_hwgpio(desc),
2860 if (!guard.gc)
2863 return gpio_do_set_config(guard.gc, gpio_chip_hwgpio(desc), config);
2932 static int gpio_chip_get_value(struct gpio_chip *gc, const struct gpio_desc *desc)
2934 return gc->get ? gc->get(gc, gpio_chip_hwgpio(desc)) : -EIO;
2962 struct gpio_chip *gc;
2970 gc = srcu_dereference(gdev->chip, &gdev->srcu);
2971 if (!gc)
2974 value = gpio_chip_get_value(gc, desc);
2980 static int gpio_chip_get_multiple(struct gpio_chip *gc,
2983 if (gc->get_multiple)
2984 return gc->get_multiple(gc, mask, bits);
2985 if (gc->get) {
2988 for_each_set_bit(i, mask, gc->ngpio) {
2989 value = gc->get(gc, i);
3000 static bool gpio_device_chip_cmp(struct gpio_device *gdev, struct gpio_chip *gc)
3004 return gc == srcu_dereference(gdev->chip, &gdev->srcu);
3050 if (!guard.gc)
3053 if (likely(guard.gc->ngpio <= FASTPATH_NGPIO)) {
3059 mask = bitmap_alloc(guard.gc->ngpio, flags);
3063 bits = bitmap_alloc(guard.gc->ngpio, flags);
3070 bitmap_zero(mask, guard.gc->ngpio);
3073 WARN_ON(guard.gc->can_sleep);
3088 gpio_device_chip_cmp(desc_array[i]->gdev, guard.gc));
3090 ret = gpio_chip_get_multiple(guard.gc, mask, bits);
3234 if (!guard.gc)
3238 ret = guard.gc->direction_input(guard.gc, offset);
3240 ret = guard.gc->direction_output(guard.gc, offset, 0);
3261 if (!guard.gc)
3265 ret = guard.gc->direction_output(guard.gc, offset, 1);
3269 ret = guard.gc->direction_input(guard.gc, offset);
3281 if (!guard.gc)
3285 guard.gc->set(guard.gc, gpio_chip_hwgpio(desc), value);
3298 static void gpio_chip_set_multiple(struct gpio_chip *gc,
3301 if (gc->set_multiple) {
3302 gc->set_multiple(gc, mask, bits);
3307 for_each_set_bit(i, mask, gc->ngpio)
3308 gc->set(gc, i, test_bit(i, bits));
3352 if (!guard.gc)
3355 if (likely(guard.gc->ngpio <= FASTPATH_NGPIO)) {
3361 mask = bitmap_alloc(guard.gc->ngpio, flags);
3365 bits = bitmap_alloc(guard.gc->ngpio, flags);
3372 bitmap_zero(mask, guard.gc->ngpio);
3375 WARN_ON(guard.gc->can_sleep);
3411 gpio_device_chip_cmp(desc_array[i]->gdev, guard.gc));
3414 gpio_chip_set_multiple(guard.gc, mask, bits);
3571 struct gpio_chip *gc;
3585 gc = srcu_dereference(gdev->chip, &gdev->srcu);
3586 if (!gc)
3590 if (gc->to_irq) {
3591 int retirq = gc->to_irq(gc, offset);
3600 if (gc->irq.chip) {
3615 * @gc: the chip the GPIO to lock belongs to
3621 int gpiochip_lock_as_irq(struct gpio_chip *gc, unsigned int offset)
3625 desc = gpiochip_get_desc(gc, offset);
3633 if (!gc->can_sleep && gc->get_direction) {
3637 chip_err(gc, "%s: cannot get GPIO direction\n",
3646 chip_err(gc,
3661 * @gc: the chip the GPIO to lock belongs to
3667 void gpiochip_unlock_as_irq(struct gpio_chip *gc, unsigned int offset)
3671 desc = gpiochip_get_desc(gc, offset);
3680 void gpiochip_disable_irq(struct gpio_chip *gc, unsigned int offset)
3682 struct gpio_desc *desc = gpiochip_get_desc(gc, offset);
3690 void gpiochip_enable_irq(struct gpio_chip *gc, unsigned int offset)
3692 struct gpio_desc *desc = gpiochip_get_desc(gc, offset);
3707 bool gpiochip_line_is_irq(struct gpio_chip *gc, unsigned int offset)
3709 if (offset >= gc->ngpio)
3712 return test_bit(FLAG_USED_AS_IRQ, &gc->gpiodev->descs[offset].flags);
3716 int gpiochip_reqres_irq(struct gpio_chip *gc, unsigned int offset)
3720 if (!try_module_get(gc->gpiodev->owner))
3723 ret = gpiochip_lock_as_irq(gc, offset);
3725 chip_err(gc, "unable to lock HW IRQ %u for IRQ\n", offset);
3726 module_put(gc->gpiodev->owner);
3733 void gpiochip_relres_irq(struct gpio_chip *gc, unsigned int offset)
3735 gpiochip_unlock_as_irq(gc, offset);
3736 module_put(gc->gpiodev->owner);
3740 bool gpiochip_line_is_open_drain(struct gpio_chip *gc, unsigned int offset)
3742 if (offset >= gc->ngpio)
3745 return test_bit(FLAG_OPEN_DRAIN, &gc->gpiodev->descs[offset].flags);
3749 bool gpiochip_line_is_open_source(struct gpio_chip *gc, unsigned int offset)
3751 if (offset >= gc->ngpio)
3754 return test_bit(FLAG_OPEN_SOURCE, &gc->gpiodev->descs[offset].flags);
3758 bool gpiochip_line_is_persistent(struct gpio_chip *gc, unsigned int offset)
3760 if (offset >= gc->ngpio)
3763 return !test_bit(FLAG_TRANSITORY, &gc->gpiodev->descs[offset].flags);
4071 struct gpio_chip *gc;
4115 gc = gpio_device_get_chip(gdev);
4117 if (gc->ngpio <= p->chip_hwnum) {
4120 idx, p->chip_hwnum, gc->ngpio - 1,
4121 gc->label);
4488 if (!guard.gc)
4496 local_desc = gpiochip_request_own_desc(guard.gc, hwnum, name,
4516 * @gc: gpio chip to act on
4518 static void gpiochip_free_hogs(struct gpio_chip *gc)
4522 for_each_gpio_desc_with_flag(gc, desc, FLAG_IS_HOGGED)
4545 struct gpio_chip *gc;
4567 gc = gpiod_to_chip(desc);
4575 bitmap_size = BITS_TO_LONGS(gc->ngpio > count ?
4576 gc->ngpio : count);
4596 array_info->chip = gc;
4609 if (array_info->chip != gc) {
4633 if (gpiochip_line_is_open_drain(gc, descs->ndescs) ||
4634 gpiochip_line_is_open_source(gc, descs->ndescs))
4772 struct gpio_chip *gc;
4777 gc = srcu_dereference(gdev->chip, &gdev->srcu);
4778 if (!gc) {
4783 for_each_gpio_desc(gc, desc) {
4788 value = gpio_chip_get_value(gc, desc);
4857 struct gpio_chip *gc;
4862 gc = srcu_dereference(gdev->chip, &gdev->srcu);
4863 if (!gc) {
4873 parent = gc->parent;
4878 if (gc->label)
4879 seq_printf(s, ", %s", gc->label);
4880 if (gc->can_sleep)
4884 if (gc->dbg_show)
4885 gc->dbg_show(s, gc);