Lines Matching refs: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,
179 return gpio_device_get_desc(gc->gpiodev, hwnum);
367 if (!guard.gc)
381 if (!guard.gc->get_direction)
384 ret = guard.gc->get_direction(guard.gc, offset);
463 struct gpio_chip *gc;
474 gc = srcu_dereference(gdev->chip, &gdev->srcu);
475 if (!gc)
478 for_each_gpio_desc(gc, 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)
497 struct gpio_device *gdev = gc->gpiodev;
501 for (i = 0; i != gc->ngpio; ++i) {
504 gpio = gpio_name_to_desc(gc->names[i]);
508 gc->names[i]);
512 for (i = 0; i != gc->ngpio; ++i)
513 gdev->descs[i].name = gc->names[i];
593 static unsigned long *gpiochip_allocate_mask(struct gpio_chip *gc)
597 p = bitmap_alloc(gc->ngpio, GFP_KERNEL);
602 bitmap_fill(p, gc->ngpio);
613 static unsigned int gpiochip_count_reserved_ranges(struct gpio_chip *gc)
615 struct device *dev = &gc->gpiodev->dev;
626 static int gpiochip_apply_reserved_ranges(struct gpio_chip *gc)
628 struct device *dev = &gc->gpiodev->dev;
633 size = gpiochip_count_reserved_ranges(gc);
652 if (start >= gc->ngpio || start + count > gc->ngpio)
655 bitmap_clear(gc->valid_mask, start, count);
662 static int gpiochip_init_valid_mask(struct gpio_chip *gc)
666 if (!(gpiochip_count_reserved_ranges(gc) || gc->init_valid_mask))
669 gc->valid_mask = gpiochip_allocate_mask(gc);
670 if (!gc->valid_mask)
673 ret = gpiochip_apply_reserved_ranges(gc);
677 if (gc->init_valid_mask)
678 return gc->init_valid_mask(gc,
679 gc->valid_mask,
680 gc->ngpio);
685 static void gpiochip_free_valid_mask(struct gpio_chip *gc)
687 gpiochip_free_mask(&gc->valid_mask);
690 static int gpiochip_add_pin_ranges(struct gpio_chip *gc)
697 if (device_property_present(&gc->gpiodev->dev, "gpio-ranges"))
700 if (gc->add_pin_ranges)
701 return gc->add_pin_ranges(gc);
706 bool gpiochip_line_is_valid(const struct gpio_chip *gc,
710 if (likely(!gc->valid_mask))
712 return test_bit(offset, gc->valid_mask);
747 static void gpiochip_free_remaining_irqs(struct gpio_chip *gc)
751 for_each_gpio_desc_with_flag(gc, desc, FLAG_USED_AS_IRQ)
819 static void gpiochip_machine_hog(struct gpio_chip *gc, struct gpiod_hog *hog)
824 desc = gpiochip_get_desc(gc, hog->chip_hwnum);
826 chip_err(gc, "%s: unable to get GPIO desc: %ld\n", __func__,
834 __func__, gc->label, hog->chip_hwnum, rv);
837 static void machine_gpiochip_add(struct gpio_chip *gc)
844 if (!strcmp(gc->label, hog->chip_label))
845 gpiochip_machine_hog(gc, hog);
867 static void gpiochip_set_data(struct gpio_chip *gc, void *data)
869 gc->gpiodev->data = data;
874 * @gc: GPIO chip
879 void *gpiochip_get_data(struct gpio_chip *gc)
881 return gc->gpiodev->data;
885 int gpiochip_get_ngpios(struct gpio_chip *gc, struct device *dev)
887 u32 ngpios = gc->ngpio;
903 gc->ngpio = ngpios;
906 if (gc->ngpio == 0) {
911 if (gc->ngpio > FASTPATH_NGPIO)
913 gc->ngpio, FASTPATH_NGPIO);
919 int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
938 gdev->dev.parent = gc->parent;
939 rcu_assign_pointer(gdev->chip, gc);
941 gc->gpiodev = gdev;
942 gpiochip_set_data(gc, data);
948 if (gc->fwnode)
949 device_set_node(&gdev->dev, gc->fwnode);
950 else if (gc->parent)
951 device_set_node(&gdev->dev, dev_fwnode(gc->parent));
963 if (gc->parent && gc->parent->driver)
964 gdev->owner = gc->parent->driver->owner;
965 else if (gc->owner)
967 gdev->owner = gc->owner;
971 ret = gpiochip_get_ngpios(gc, &gdev->dev);
975 gdev->descs = kcalloc(gc->ngpio, sizeof(*gdev->descs), GFP_KERNEL);
981 gdev->label = kstrdup_const(gc->label ?: "unknown", GFP_KERNEL);
987 gdev->ngpio = gc->ngpio;
988 gdev->can_sleep = gc->can_sleep;
998 base = gc->base;
1000 base = gpiochip_find_base_unlocked(gc->ngpio);
1013 gc->base = base;
1023 chip_err(gc, "GPIO integer space overlap, cannot add chip\n");
1044 if (gc->names)
1045 gpiochip_set_desc_names(gc);
1047 ret = gpiochip_set_names(gc);
1051 ret = gpiochip_init_valid_mask(gc);
1055 for (desc_index = 0; desc_index < gc->ngpio; desc_index++) {
1067 if (gc->get_direction && gpiochip_line_is_valid(gc, desc_index))
1069 !gc->get_direction(gc, desc_index));
1072 &desc->flags, !gc->direction_input);
1075 ret = of_gpiochip_add(gc);
1079 ret = gpiochip_add_pin_ranges(gc);
1083 acpi_gpiochip_add(gc);
1085 machine_gpiochip_add(gc);
1087 ret = gpiochip_irqchip_init_valid_mask(gc);
1091 ret = gpiochip_irqchip_init_hw(gc);
1095 ret = gpiochip_add_irqchip(gc, lock_key, request_key);
1115 gpiochip_irqchip_remove(gc);
1117 gpiochip_irqchip_free_valid_mask(gc);
1119 gpiochip_free_hogs(gc);
1120 acpi_gpiochip_remove(gc);
1121 gpiochip_remove_pin_ranges(gc);
1123 of_gpiochip_remove(gc);
1125 gpiochip_free_valid_mask(gc);
1153 base, base + (int)gc->ngpio - 1,
1154 gc->label ? : "generic", ret);
1162 * @gc: the chip to unregister
1166 void gpiochip_remove(struct gpio_chip *gc)
1168 struct gpio_device *gdev = gc->gpiodev;
1172 gpiochip_free_hogs(gc);
1173 gpiochip_free_remaining_irqs(gc);
1182 gpiochip_irqchip_remove(gc);
1183 acpi_gpiochip_remove(gc);
1184 of_gpiochip_remove(gc);
1185 gpiochip_remove_pin_ranges(gc);
1186 gpiochip_free_valid_mask(gc);
1191 gpiochip_set_data(gc, NULL);
1226 int (*match)(struct gpio_chip *gc,
1230 struct gpio_chip *gc;
1243 gc = srcu_dereference(gdev->chip, &gdev->srcu);
1245 if (gc && match(gc, data))
1253 static int gpio_chip_match_by_label(struct gpio_chip *gc, const void *label)
1255 return gc->label && !strcmp(gc->label, label);
1273 static int gpio_chip_match_by_fwnode(struct gpio_chip *gc, const void *fwnode)
1275 return device_match_fwnode(&gc->gpiodev->dev, fwnode);
1340 static int gpiochip_irqchip_init_hw(struct gpio_chip *gc)
1342 struct gpio_irq_chip *girq = &gc->irq;
1347 return girq->init_hw(gc);
1350 static int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gc)
1352 struct gpio_irq_chip *girq = &gc->irq;
1357 girq->valid_mask = gpiochip_allocate_mask(gc);
1361 girq->init_valid_mask(gc, girq->valid_mask, gc->ngpio);
1366 static void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gc)
1368 gpiochip_free_mask(&gc->irq.valid_mask);
1371 static bool gpiochip_irqchip_irq_valid(const struct gpio_chip *gc,
1374 if (!gpiochip_line_is_valid(gc, offset))
1377 if (likely(!gc->irq.valid_mask))
1379 return test_bit(offset, gc->irq.valid_mask);
1387 * @gc: the gpiochip to set the irqchip hierarchical handler to
1391 static void gpiochip_set_hierarchical_irqchip(struct gpio_chip *gc,
1395 if (is_of_node(gc->irq.fwnode))
1406 if (is_fwnode_irqchip(gc->irq.fwnode)) {
1410 for (i = 0; i < gc->ngpio; i++) {
1414 struct gpio_irq_chip *girq = &gc->irq;
1422 ret = girq->child_to_parent_hwirq(gc, i,
1427 chip_err(gc, "skip set-up on hwirq %d\n",
1432 fwspec.fwnode = gc->irq.fwnode;
1434 fwspec.param[0] = girq->child_offset_to_irq(gc, i);
1438 ret = irq_domain_alloc_irqs(gc->irq.domain, 1,
1441 chip_err(gc,
1449 chip_err(gc, "%s unknown fwnode type proceed anyway\n", __func__);
1482 struct gpio_chip *gc = d->host_data;
1489 struct gpio_irq_chip *girq = &gc->irq;
1498 ret = gc->irq.child_irq_domain_ops.translate(d, fwspec, &hwirq, &type);
1502 chip_dbg(gc, "allocate IRQ %d, hwirq %lu\n", irq, hwirq);
1504 ret = girq->child_to_parent_hwirq(gc, hwirq, type,
1507 chip_err(gc, "can't look up hwirq %lu\n", hwirq);
1510 chip_dbg(gc, "found parent hwirq %u\n", parent_hwirq);
1519 gc->irq.chip,
1520 gc,
1526 ret = girq->populate_parent_alloc_arg(gc, &gpio_parent_fwspec,
1531 chip_dbg(gc, "alloc_irqs_parent for %d parent hwirq %d\n",
1533 irq_set_lockdep_class(irq, gc->irq.lock_key, gc->irq.request_key);
1542 chip_err(gc,
1549 static unsigned int gpiochip_child_offset_to_irq_noop(struct gpio_chip *gc,
1571 struct gpio_chip *gc = domain->host_data;
1574 return gpiochip_lock_as_irq(gc, hwirq);
1589 struct gpio_chip *gc = domain->host_data;
1592 return gpiochip_unlock_as_irq(gc, hwirq);
1614 static struct irq_domain *gpiochip_hierarchy_create_domain(struct gpio_chip *gc)
1618 if (!gc->irq.child_to_parent_hwirq ||
1619 !gc->irq.fwnode) {
1620 chip_err(gc, "missing irqdomain vital data\n");
1624 if (!gc->irq.child_offset_to_irq)
1625 gc->irq.child_offset_to_irq = gpiochip_child_offset_to_irq_noop;
1627 if (!gc->irq.populate_parent_alloc_arg)
1628 gc->irq.populate_parent_alloc_arg =
1631 gpiochip_hierarchy_setup_domain_ops(&gc->irq.child_irq_domain_ops);
1634 gc->irq.parent_domain,
1636 gc->ngpio,
1637 gc->irq.fwnode,
1638 &gc->irq.child_irq_domain_ops,
1639 gc);
1644 gpiochip_set_hierarchical_irqchip(gc, gc->irq.chip);
1649 static bool gpiochip_hierarchy_is_hierarchical(struct gpio_chip *gc)
1651 return !!gc->irq.parent_domain;
1654 int gpiochip_populate_parent_fwspec_twocell(struct gpio_chip *gc,
1661 fwspec->fwnode = gc->irq.parent_domain->fwnode;
1670 int gpiochip_populate_parent_fwspec_fourcell(struct gpio_chip *gc,
1677 fwspec->fwnode = gc->irq.parent_domain->fwnode;
1690 static struct irq_domain *gpiochip_hierarchy_create_domain(struct gpio_chip *gc)
1695 static bool gpiochip_hierarchy_is_hierarchical(struct gpio_chip *gc)
1718 struct gpio_chip *gc = d->host_data;
1721 if (!gpiochip_irqchip_irq_valid(gc, hwirq))
1724 irq_set_chip_data(irq, gc);
1729 irq_set_lockdep_class(irq, gc->irq.lock_key, gc->irq.request_key);
1730 irq_set_chip_and_handler(irq, gc->irq.chip, gc->irq.handler);
1732 if (gc->irq.threaded)
1736 if (gc->irq.num_parents == 1)
1737 ret = irq_set_parent(irq, gc->irq.parents[0]);
1738 else if (gc->irq.map)
1739 ret = irq_set_parent(irq, gc->irq.map[hwirq]);
1748 if (gc->irq.default_type != IRQ_TYPE_NONE)
1749 irq_set_irq_type(irq, gc->irq.default_type);
1756 struct gpio_chip *gc = d->host_data;
1758 if (gc->irq.threaded)
1771 static struct irq_domain *gpiochip_simple_create_domain(struct gpio_chip *gc)
1773 struct fwnode_handle *fwnode = dev_fwnode(&gc->gpiodev->dev);
1776 domain = irq_domain_create_simple(fwnode, gc->ngpio, gc->irq.first,
1777 &gpiochip_domain_ops, gc);
1784 static int gpiochip_to_irq(struct gpio_chip *gc, unsigned int offset)
1786 struct irq_domain *domain = gc->irq.domain;
1794 if (!gc->irq.initialized)
1798 if (!gpiochip_irqchip_irq_valid(gc, offset))
1807 spec.param[0] = gc->irq.child_offset_to_irq(gc, offset);
1819 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
1822 return gpiochip_reqres_irq(gc, hwirq);
1828 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
1831 gpiochip_relres_irq(gc, hwirq);
1837 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
1840 if (gc->irq.irq_mask)
1841 gc->irq.irq_mask(d);
1842 gpiochip_disable_irq(gc, hwirq);
1847 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
1850 gpiochip_enable_irq(gc, hwirq);
1851 if (gc->irq.irq_unmask)
1852 gc->irq.irq_unmask(d);
1857 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
1860 gpiochip_enable_irq(gc, hwirq);
1861 gc->irq.irq_enable(d);
1866 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
1869 gc->irq.irq_disable(d);
1870 gpiochip_disable_irq(gc, hwirq);
1873 static void gpiochip_set_irq_hooks(struct gpio_chip *gc)
1875 struct irq_chip *irqchip = gc->irq.chip;
1880 chip_warn(gc, "not an immutable chip, please consider fixing it!\n");
1887 if (WARN_ON(gc->irq.irq_enable))
1896 chip_info(gc,
1902 gc->irq.irq_disable = irqchip->irq_disable;
1905 gc->irq.irq_mask = irqchip->irq_mask;
1910 gc->irq.irq_enable = irqchip->irq_enable;
1913 gc->irq.irq_unmask = irqchip->irq_unmask;
1918 static int gpiochip_irqchip_add_allocated_domain(struct gpio_chip *gc,
1925 if (gc->to_irq)
1926 chip_warn(gc, "to_irq is redefined in %s and you shouldn't rely on it\n", __func__);
1928 gc->to_irq = gpiochip_to_irq;
1929 gc->irq.domain = domain;
1930 gc->irq.domain_is_allocated_externally = allocated_externally;
1934 * gc->irq.initialized before adding irqdomain.
1938 gc->irq.initialized = true;
1945 * @gc: the GPIO chip to add the IRQ chip to
1952 static int gpiochip_add_irqchip(struct gpio_chip *gc,
1956 struct fwnode_handle *fwnode = dev_fwnode(&gc->gpiodev->dev);
1957 struct irq_chip *irqchip = gc->irq.chip;
1966 if (gc->irq.parent_handler && gc->can_sleep) {
1967 chip_err(gc, "you cannot have chained interrupts on a chip that may sleep\n");
1971 type = gc->irq.default_type;
1982 gc->irq.default_type = type;
1983 gc->irq.lock_key = lock_key;
1984 gc->irq.request_key = request_key;
1987 if (gpiochip_hierarchy_is_hierarchical(gc)) {
1988 domain = gpiochip_hierarchy_create_domain(gc);
1990 domain = gpiochip_simple_create_domain(gc);
1995 if (gc->irq.parent_handler) {
1996 for (i = 0; i < gc->irq.num_parents; i++) {
1999 if (gc->irq.per_parent_data)
2000 data = gc->irq.parent_handler_data_array[i];
2002 data = gc->irq.parent_handler_data ?: gc;
2009 irq_set_chained_handler_and_data(gc->irq.parents[i],
2010 gc->irq.parent_handler,
2015 gpiochip_set_irq_hooks(gc);
2017 ret = gpiochip_irqchip_add_allocated_domain(gc, domain, false);
2021 acpi_gpiochip_request_interrupts(gc);
2028 * @gc: the gpiochip to remove the irqchip from
2032 static void gpiochip_irqchip_remove(struct gpio_chip *gc)
2034 struct irq_chip *irqchip = gc->irq.chip;
2037 acpi_gpiochip_free_interrupts(gc);
2039 if (irqchip && gc->irq.parent_handler) {
2040 struct gpio_irq_chip *irq = &gc->irq;
2049 if (!gc->irq.domain_is_allocated_externally && gc->irq.domain) {
2052 for (offset = 0; offset < gc->ngpio; offset++) {
2053 if (!gpiochip_irqchip_irq_valid(gc, offset))
2056 irq = irq_find_mapping(gc->irq.domain, offset);
2060 irq_domain_remove(gc->irq.domain);
2069 irqchip->irq_enable = gc->irq.irq_enable;
2070 irqchip->irq_disable = gc->irq.irq_disable;
2073 gc->irq.irq_enable = NULL;
2074 gc->irq.irq_disable = NULL;
2075 gc->irq.chip = NULL;
2077 gpiochip_irqchip_free_valid_mask(gc);
2082 * @gc: the gpiochip to add the irqchip to
2090 int gpiochip_irqchip_add_domain(struct gpio_chip *gc,
2093 return gpiochip_irqchip_add_allocated_domain(gc, domain, true);
2099 static inline int gpiochip_add_irqchip(struct gpio_chip *gc,
2105 static void gpiochip_irqchip_remove(struct gpio_chip *gc) {}
2107 static inline int gpiochip_irqchip_init_hw(struct gpio_chip *gc)
2112 static inline int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gc)
2116 static inline void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gc)
2123 * @gc: the gpiochip owning the GPIO
2129 int gpiochip_generic_request(struct gpio_chip *gc, unsigned int offset)
2132 if (list_empty(&gc->gpiodev->pin_ranges))
2136 return pinctrl_gpio_request(gc, offset);
2142 * @gc: the gpiochip to request the gpio function for
2145 void gpiochip_generic_free(struct gpio_chip *gc, unsigned int offset)
2148 if (list_empty(&gc->gpiodev->pin_ranges))
2152 pinctrl_gpio_free(gc, offset);
2158 * @gc: the gpiochip owning the GPIO
2165 int gpiochip_generic_config(struct gpio_chip *gc, unsigned int offset,
2169 if (list_empty(&gc->gpiodev->pin_ranges))
2173 return pinctrl_gpio_set_config(gc, offset, config);
2181 * @gc: the gpiochip to add the range for
2194 int gpiochip_add_pingroup_range(struct gpio_chip *gc,
2199 struct gpio_device *gdev = gc->gpiodev;
2204 chip_err(gc, "failed to allocate pin ranges\n");
2210 pin_range->range.gc = gc;
2211 pin_range->range.name = gc->label;
2225 chip_dbg(gc, "created GPIO range %d->%d ==> %s PINGRP %s\n",
2237 * @gc: the gpiochip to add the range for
2252 int gpiochip_add_pin_range(struct gpio_chip *gc, const char *pinctl_name,
2257 struct gpio_device *gdev = gc->gpiodev;
2262 chip_err(gc, "failed to allocate pin ranges\n");
2268 pin_range->range.gc = gc;
2269 pin_range->range.name = gc->label;
2277 chip_err(gc, "could not create pin range\n");
2281 chip_dbg(gc, "created GPIO range %d->%d ==> %s PIN %d->%d\n",
2294 * @gc: the chip to remove all the mappings for
2296 void gpiochip_remove_pin_ranges(struct gpio_chip *gc)
2299 struct gpio_device *gdev = gc->gpiodev;
2322 if (!guard.gc)
2332 if (guard.gc->request) {
2334 if (gpiochip_line_is_valid(guard.gc, offset))
2335 ret = guard.gc->request(guard.gc, offset);
2342 if (guard.gc->get_direction)
2417 if (guard.gc && test_bit(FLAG_REQUESTED, &flags)) {
2418 if (guard.gc->free)
2419 guard.gc->free(guard.gc, gpio_chip_hwgpio(desc));
2454 * @gc: GPIO chip controlling this line.
2464 char *gpiochip_dup_line_label(struct gpio_chip *gc, unsigned int offset)
2469 desc = gpiochip_get_desc(gc, offset);
2493 * @gc: GPIO chip
2512 struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *gc,
2518 struct gpio_desc *desc = gpiochip_get_desc(gc, hwnum);
2523 chip_err(gc, "failed to get GPIO %s descriptor\n", name);
2534 chip_err(gc, "setup of own GPIO %s failed\n", name);
2573 if (!guard.gc)
2576 if (!guard.gc->set_config)
2579 ret = guard.gc->set_config(guard.gc, gpio_chip_hwgpio(desc), config);
2714 if (!guard.gc)
2722 if (!guard.gc->get && guard.gc->direction_input) {
2735 if (guard.gc->direction_input) {
2736 ret = guard.gc->direction_input(guard.gc,
2738 } else if (guard.gc->get_direction) {
2739 dir = guard.gc->get_direction(guard.gc,
2766 if (!guard.gc)
2774 if (!guard.gc->set && !guard.gc->direction_output) {
2781 if (guard.gc->direction_output) {
2782 ret = guard.gc->direction_output(guard.gc,
2786 if (guard.gc->get_direction) {
2787 dir = guard.gc->get_direction(guard.gc,
2803 guard.gc->set(guard.gc, gpio_chip_hwgpio(desc), val);
2944 if (!guard.gc)
2947 if (!guard.gc->en_hw_timestamp) {
2952 ret = guard.gc->en_hw_timestamp(guard.gc,
2977 if (!guard.gc)
2980 if (!guard.gc->dis_hw_timestamp) {
2985 ret = guard.gc->dis_hw_timestamp(guard.gc, gpio_chip_hwgpio(desc),
3099 static int gpio_chip_get_value(struct gpio_chip *gc, const struct gpio_desc *desc)
3101 return gc->get ? gc->get(gc, gpio_chip_hwgpio(desc)) : -EIO;
3129 struct gpio_chip *gc;
3137 gc = srcu_dereference(gdev->chip, &gdev->srcu);
3138 if (!gc)
3141 value = gpio_chip_get_value(gc, desc);
3147 static int gpio_chip_get_multiple(struct gpio_chip *gc,
3150 lockdep_assert_held(&gc->gpiodev->srcu);
3152 if (gc->get_multiple)
3153 return gc->get_multiple(gc, mask, bits);
3154 if (gc->get) {
3157 for_each_set_bit(i, mask, gc->ngpio) {
3158 value = gc->get(gc, i);
3169 static bool gpio_device_chip_cmp(struct gpio_device *gdev, struct gpio_chip *gc)
3173 return gc == srcu_dereference(gdev->chip, &gdev->srcu);
3182 struct gpio_chip *gc;
3197 gc = srcu_dereference(array_info->gdev->chip,
3199 if (!gc)
3202 ret = gpio_chip_get_multiple(gc, array_info->get_mask,
3225 if (!guard.gc)
3228 if (likely(guard.gc->ngpio <= FASTPATH_NGPIO)) {
3234 mask = bitmap_alloc(guard.gc->ngpio, flags);
3238 bits = bitmap_alloc(guard.gc->ngpio, flags);
3245 bitmap_zero(mask, guard.gc->ngpio);
3248 WARN_ON(guard.gc->can_sleep);
3263 gpio_device_chip_cmp(desc_array[i]->gdev, guard.gc));
3265 ret = gpio_chip_get_multiple(guard.gc, mask, bits);
3416 if (!guard.gc)
3420 ret = guard.gc->direction_input(guard.gc, offset);
3422 ret = guard.gc->direction_output(guard.gc, offset, 0);
3443 if (!guard.gc)
3447 ret = guard.gc->direction_output(guard.gc, offset, 1);
3451 ret = guard.gc->direction_input(guard.gc, offset);
3463 if (!guard.gc)
3467 guard.gc->set(guard.gc, gpio_chip_hwgpio(desc), value);
3480 static void gpio_chip_set_multiple(struct gpio_chip *gc,
3483 lockdep_assert_held(&gc->gpiodev->srcu);
3485 if (gc->set_multiple) {
3486 gc->set_multiple(gc, mask, bits);
3491 for_each_set_bit(i, mask, gc->ngpio)
3492 gc->set(gc, i, test_bit(i, bits));
3502 struct gpio_chip *gc;
3517 gc = srcu_dereference(array_info->gdev->chip,
3519 if (!gc)
3526 gpio_chip_set_multiple(gc, array_info->set_mask, value_bitmap);
3542 if (!guard.gc)
3545 if (likely(guard.gc->ngpio <= FASTPATH_NGPIO)) {
3551 mask = bitmap_alloc(guard.gc->ngpio, flags);
3555 bits = bitmap_alloc(guard.gc->ngpio, flags);
3562 bitmap_zero(mask, guard.gc->ngpio);
3565 WARN_ON(guard.gc->can_sleep);
3601 gpio_device_chip_cmp(desc_array[i]->gdev, guard.gc));
3604 gpio_chip_set_multiple(guard.gc, mask, bits);
3778 struct gpio_chip *gc;
3792 gc = srcu_dereference(gdev->chip, &gdev->srcu);
3793 if (!gc)
3797 if (gc->to_irq) {
3798 int retirq = gc->to_irq(gc, offset);
3807 if (gc->irq.chip) {
3822 * @gc: the chip the GPIO to lock belongs to
3831 int gpiochip_lock_as_irq(struct gpio_chip *gc, unsigned int offset)
3835 desc = gpiochip_get_desc(gc, offset);
3843 if (!gc->can_sleep && gc->get_direction) {
3847 chip_err(gc, "%s: cannot get GPIO direction\n",
3856 chip_err(gc,
3871 * @gc: the chip the GPIO to lock belongs to
3877 void gpiochip_unlock_as_irq(struct gpio_chip *gc, unsigned int offset)
3881 desc = gpiochip_get_desc(gc, offset);
3890 void gpiochip_disable_irq(struct gpio_chip *gc, unsigned int offset)
3892 struct gpio_desc *desc = gpiochip_get_desc(gc, offset);
3900 void gpiochip_enable_irq(struct gpio_chip *gc, unsigned int offset)
3902 struct gpio_desc *desc = gpiochip_get_desc(gc, offset);
3917 bool gpiochip_line_is_irq(struct gpio_chip *gc, unsigned int offset)
3919 if (offset >= gc->ngpio)
3922 return test_bit(FLAG_USED_AS_IRQ, &gc->gpiodev->descs[offset].flags);
3926 int gpiochip_reqres_irq(struct gpio_chip *gc, unsigned int offset)
3930 if (!try_module_get(gc->gpiodev->owner))
3933 ret = gpiochip_lock_as_irq(gc, offset);
3935 chip_err(gc, "unable to lock HW IRQ %u for IRQ\n", offset);
3936 module_put(gc->gpiodev->owner);
3943 void gpiochip_relres_irq(struct gpio_chip *gc, unsigned int offset)
3945 gpiochip_unlock_as_irq(gc, offset);
3946 module_put(gc->gpiodev->owner);
3950 bool gpiochip_line_is_open_drain(struct gpio_chip *gc, unsigned int offset)
3952 if (offset >= gc->ngpio)
3955 return test_bit(FLAG_OPEN_DRAIN, &gc->gpiodev->descs[offset].flags);
3959 bool gpiochip_line_is_open_source(struct gpio_chip *gc, unsigned int offset)
3961 if (offset >= gc->ngpio)
3964 return test_bit(FLAG_OPEN_SOURCE, &gc->gpiodev->descs[offset].flags);
3968 bool gpiochip_line_is_persistent(struct gpio_chip *gc, unsigned int offset)
3970 if (offset >= gc->ngpio)
3973 return !test_bit(FLAG_TRANSITORY, &gc->gpiodev->descs[offset].flags);
4295 struct gpio_chip *gc;
4339 gc = gpio_device_get_chip(gdev);
4341 if (gc->ngpio <= p->chip_hwnum) {
4344 idx, p->chip_hwnum, gc->ngpio - 1,
4345 gc->label);
4731 if (!guard.gc)
4739 local_desc = gpiochip_request_own_desc(guard.gc, hwnum, name,
4759 * @gc: gpio chip to act on
4761 static void gpiochip_free_hogs(struct gpio_chip *gc)
4765 for_each_gpio_desc_with_flag(gc, desc, FLAG_IS_HOGGED)
5025 struct gpio_chip *gc;
5030 gc = srcu_dereference(gdev->chip, &gdev->srcu);
5031 if (!gc) {
5036 for_each_gpio_desc(gc, desc) {
5042 value = gpio_chip_get_value(gc, desc);
5112 struct gpio_chip *gc;
5120 gc = srcu_dereference(gdev->chip, &gdev->srcu);
5121 if (!gc) {
5128 parent = gc->parent;
5133 if (gc->label)
5134 seq_printf(s, ", %s", gc->label);
5135 if (gc->can_sleep)
5139 if (gc->dbg_show)
5140 gc->dbg_show(s, gc);