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