Lines Matching refs:gc

101 static void gpiochip_free_hogs(struct gpio_chip *gc);
102 static int gpiochip_add_irqchip(struct gpio_chip *gc,
105 static void gpiochip_irqchip_remove(struct gpio_chip *gc);
106 static int gpiochip_irqchip_init_hw(struct gpio_chip *gc);
107 static int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gc);
108 static void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gc);
152 * @gc: GPIO chip
159 struct gpio_desc *gpiochip_get_desc(struct gpio_chip *gc,
162 struct gpio_device *gdev = gc->gpiodev;
235 struct gpio_chip *gc;
239 gc = gpiod_to_chip(desc);
250 if (!gc->get_direction)
253 ret = gc->get_direction(gc, offset);
347 * Take the names from gc->names and assign them to their GPIO descriptors.
354 static int gpiochip_set_desc_names(struct gpio_chip *gc)
356 struct gpio_device *gdev = gc->gpiodev;
360 for (i = 0; i != gc->ngpio; ++i) {
363 gpio = gpio_name_to_desc(gc->names[i]);
367 gc->names[i]);
371 for (i = 0; i != gc->ngpio; ++i)
372 gdev->descs[i].name = gc->names[i];
454 static unsigned long *gpiochip_allocate_mask(struct gpio_chip *gc)
458 p = bitmap_alloc(gc->ngpio, GFP_KERNEL);
463 bitmap_fill(p, gc->ngpio);
474 static unsigned int gpiochip_count_reserved_ranges(struct gpio_chip *gc)
476 struct device *dev = &gc->gpiodev->dev;
487 static int gpiochip_apply_reserved_ranges(struct gpio_chip *gc)
489 struct device *dev = &gc->gpiodev->dev;
494 size = gpiochip_count_reserved_ranges(gc);
513 if (start >= gc->ngpio || start + count > gc->ngpio)
516 bitmap_clear(gc->valid_mask, start, count);
523 static int gpiochip_init_valid_mask(struct gpio_chip *gc)
527 if (!(gpiochip_count_reserved_ranges(gc) || gc->init_valid_mask))
530 gc->valid_mask = gpiochip_allocate_mask(gc);
531 if (!gc->valid_mask)
534 ret = gpiochip_apply_reserved_ranges(gc);
538 if (gc->init_valid_mask)
539 return gc->init_valid_mask(gc,
540 gc->valid_mask,
541 gc->ngpio);
546 static void gpiochip_free_valid_mask(struct gpio_chip *gc)
548 gpiochip_free_mask(&gc->valid_mask);
551 static int gpiochip_add_pin_ranges(struct gpio_chip *gc)
558 if (device_property_present(&gc->gpiodev->dev, "gpio-ranges"))
561 if (gc->add_pin_ranges)
562 return gc->add_pin_ranges(gc);
567 bool gpiochip_line_is_valid(const struct gpio_chip *gc,
571 if (likely(!gc->valid_mask))
573 return test_bit(offset, gc->valid_mask);
637 static void gpiochip_machine_hog(struct gpio_chip *gc, struct gpiod_hog *hog)
642 desc = gpiochip_get_desc(gc, hog->chip_hwnum);
644 chip_err(gc, "%s: unable to get GPIO desc: %ld\n", __func__,
655 __func__, gc->label, hog->chip_hwnum, rv);
658 static void machine_gpiochip_add(struct gpio_chip *gc)
665 if (!strcmp(gc->label, hog->chip_label))
666 gpiochip_machine_hog(gc, hog);
685 static void gpiochip_set_data(struct gpio_chip *gc, void *data)
687 gc->gpiodev->data = data;
692 * @gc: GPIO chip
697 void *gpiochip_get_data(struct gpio_chip *gc)
699 return gc->gpiodev->data;
703 int gpiochip_get_ngpios(struct gpio_chip *gc, struct device *dev)
705 u32 ngpios = gc->ngpio;
721 gc->ngpio = ngpios;
724 if (gc->ngpio == 0) {
725 chip_err(gc, "tried to insert a GPIO chip with zero lines\n");
729 if (gc->ngpio > FASTPATH_NGPIO)
730 chip_warn(gc, "line cnt %u is greater than fast path cnt %u\n",
731 gc->ngpio, FASTPATH_NGPIO);
737 int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
755 gdev->dev.parent = gc->parent;
756 gdev->chip = gc;
758 gc->gpiodev = gdev;
759 gpiochip_set_data(gc, data);
765 if (gc->fwnode)
766 device_set_node(&gdev->dev, gc->fwnode);
767 else if (gc->parent)
768 device_set_node(&gdev->dev, dev_fwnode(gc->parent));
781 if (gc->parent && gc->parent->driver)
782 gdev->owner = gc->parent->driver->owner;
783 else if (gc->owner)
785 gdev->owner = gc->owner;
789 ret = gpiochip_get_ngpios(gc, &gdev->dev);
793 gdev->descs = kcalloc(gc->ngpio, sizeof(*gdev->descs), GFP_KERNEL);
799 gdev->label = kstrdup_const(gc->label ?: "unknown", GFP_KERNEL);
805 gdev->ngpio = gc->ngpio;
816 base = gc->base;
818 base = gpiochip_find_base(gc->ngpio);
831 gc->base = base;
841 chip_err(gc, "GPIO integer space overlap, cannot add chip\n");
845 for (i = 0; i < gc->ngpio; i++)
858 if (gc->names) {
859 ret = gpiochip_set_desc_names(gc);
863 ret = gpiochip_set_names(gc);
867 ret = gpiochip_init_valid_mask(gc);
871 ret = of_gpiochip_add(gc);
875 for (i = 0; i < gc->ngpio; i++) {
878 if (gc->get_direction && gpiochip_line_is_valid(gc, i)) {
880 &desc->flags, !gc->get_direction(gc, i));
883 &desc->flags, !gc->direction_input);
887 ret = gpiochip_add_pin_ranges(gc);
891 acpi_gpiochip_add(gc);
893 machine_gpiochip_add(gc);
895 ret = gpiochip_irqchip_init_valid_mask(gc);
899 ret = gpiochip_irqchip_init_hw(gc);
903 ret = gpiochip_add_irqchip(gc, lock_key, request_key);
923 gpiochip_irqchip_remove(gc);
925 gpiochip_irqchip_free_valid_mask(gc);
927 gpiochip_free_hogs(gc);
928 acpi_gpiochip_remove(gc);
929 gpiochip_remove_pin_ranges(gc);
931 of_gpiochip_remove(gc);
933 gpiochip_free_valid_mask(gc);
957 base, base + (int)gc->ngpio - 1,
958 gc->label ? : "generic", ret);
966 * @gc: the chip to unregister
970 void gpiochip_remove(struct gpio_chip *gc)
972 struct gpio_device *gdev = gc->gpiodev;
980 gpiochip_free_hogs(gc);
983 gpiochip_irqchip_remove(gc);
984 acpi_gpiochip_remove(gc);
985 of_gpiochip_remove(gc);
986 gpiochip_remove_pin_ranges(gc);
987 gpiochip_free_valid_mask(gc);
992 gpiochip_set_data(gc, NULL);
996 if (gpiochip_is_requested(gc, i))
1023 int (*match)(struct gpio_chip *gc,
1027 struct gpio_chip *gc = NULL;
1031 gc = gdev->chip;
1035 return gc;
1061 int (*match)(struct gpio_chip *gc,
1084 static int gpiochip_match_name(struct gpio_chip *gc, void *data)
1088 return !strcmp(gc->label, name);
1126 static int gpiochip_irqchip_init_hw(struct gpio_chip *gc)
1128 struct gpio_irq_chip *girq = &gc->irq;
1133 return girq->init_hw(gc);
1136 static int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gc)
1138 struct gpio_irq_chip *girq = &gc->irq;
1143 girq->valid_mask = gpiochip_allocate_mask(gc);
1147 girq->init_valid_mask(gc, girq->valid_mask, gc->ngpio);
1152 static void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gc)
1154 gpiochip_free_mask(&gc->irq.valid_mask);
1157 bool gpiochip_irqchip_irq_valid(const struct gpio_chip *gc,
1160 if (!gpiochip_line_is_valid(gc, offset))
1163 if (likely(!gc->irq.valid_mask))
1165 return test_bit(offset, gc->irq.valid_mask);
1174 * @gc: the gpiochip to set the irqchip hierarchical handler to
1178 static void gpiochip_set_hierarchical_irqchip(struct gpio_chip *gc,
1182 if (is_of_node(gc->irq.fwnode))
1193 if (is_fwnode_irqchip(gc->irq.fwnode)) {
1197 for (i = 0; i < gc->ngpio; i++) {
1201 struct gpio_irq_chip *girq = &gc->irq;
1209 ret = girq->child_to_parent_hwirq(gc, i,
1214 chip_err(gc, "skip set-up on hwirq %d\n",
1219 fwspec.fwnode = gc->irq.fwnode;
1221 fwspec.param[0] = girq->child_offset_to_irq(gc, i);
1225 ret = irq_domain_alloc_irqs(gc->irq.domain, 1,
1228 chip_err(gc,
1236 chip_err(gc, "%s unknown fwnode type proceed anyway\n", __func__);
1269 struct gpio_chip *gc = d->host_data;
1276 struct gpio_irq_chip *girq = &gc->irq;
1285 ret = gc->irq.child_irq_domain_ops.translate(d, fwspec, &hwirq, &type);
1289 chip_dbg(gc, "allocate IRQ %d, hwirq %lu\n", irq, hwirq);
1291 ret = girq->child_to_parent_hwirq(gc, hwirq, type,
1294 chip_err(gc, "can't look up hwirq %lu\n", hwirq);
1297 chip_dbg(gc, "found parent hwirq %u\n", parent_hwirq);
1306 gc->irq.chip,
1307 gc,
1313 ret = girq->populate_parent_alloc_arg(gc, &gpio_parent_fwspec,
1318 chip_dbg(gc, "alloc_irqs_parent for %d parent hwirq %d\n",
1320 irq_set_lockdep_class(irq, gc->irq.lock_key, gc->irq.request_key);
1329 chip_err(gc,
1336 static unsigned int gpiochip_child_offset_to_irq_noop(struct gpio_chip *gc,
1361 static struct irq_domain *gpiochip_hierarchy_create_domain(struct gpio_chip *gc)
1365 if (!gc->irq.child_to_parent_hwirq ||
1366 !gc->irq.fwnode) {
1367 chip_err(gc, "missing irqdomain vital data\n");
1371 if (!gc->irq.child_offset_to_irq)
1372 gc->irq.child_offset_to_irq = gpiochip_child_offset_to_irq_noop;
1374 if (!gc->irq.populate_parent_alloc_arg)
1375 gc->irq.populate_parent_alloc_arg =
1378 gpiochip_hierarchy_setup_domain_ops(&gc->irq.child_irq_domain_ops);
1381 gc->irq.parent_domain,
1383 gc->ngpio,
1384 gc->irq.fwnode,
1385 &gc->irq.child_irq_domain_ops,
1386 gc);
1391 gpiochip_set_hierarchical_irqchip(gc, gc->irq.chip);
1396 static bool gpiochip_hierarchy_is_hierarchical(struct gpio_chip *gc)
1398 return !!gc->irq.parent_domain;
1401 int gpiochip_populate_parent_fwspec_twocell(struct gpio_chip *gc,
1408 fwspec->fwnode = gc->irq.parent_domain->fwnode;
1417 int gpiochip_populate_parent_fwspec_fourcell(struct gpio_chip *gc,
1424 fwspec->fwnode = gc->irq.parent_domain->fwnode;
1437 static struct irq_domain *gpiochip_hierarchy_create_domain(struct gpio_chip *gc)
1442 static bool gpiochip_hierarchy_is_hierarchical(struct gpio_chip *gc)
1461 struct gpio_chip *gc = d->host_data;
1464 if (!gpiochip_irqchip_irq_valid(gc, hwirq))
1467 irq_set_chip_data(irq, gc);
1472 irq_set_lockdep_class(irq, gc->irq.lock_key, gc->irq.request_key);
1473 irq_set_chip_and_handler(irq, gc->irq.chip, gc->irq.handler);
1475 if (gc->irq.threaded)
1479 if (gc->irq.num_parents == 1)
1480 ret = irq_set_parent(irq, gc->irq.parents[0]);
1481 else if (gc->irq.map)
1482 ret = irq_set_parent(irq, gc->irq.map[hwirq]);
1491 if (gc->irq.default_type != IRQ_TYPE_NONE)
1492 irq_set_irq_type(irq, gc->irq.default_type);
1500 struct gpio_chip *gc = d->host_data;
1502 if (gc->irq.threaded)
1516 static struct irq_domain *gpiochip_simple_create_domain(struct gpio_chip *gc)
1518 struct fwnode_handle *fwnode = dev_fwnode(&gc->gpiodev->dev);
1521 domain = irq_domain_create_simple(fwnode, gc->ngpio, gc->irq.first,
1522 &gpiochip_domain_ops, gc);
1547 struct gpio_chip *gc = domain->host_data;
1550 return gpiochip_lock_as_irq(gc, hwirq);
1566 struct gpio_chip *gc = domain->host_data;
1569 return gpiochip_unlock_as_irq(gc, hwirq);
1573 static int gpiochip_to_irq(struct gpio_chip *gc, unsigned int offset)
1575 struct irq_domain *domain = gc->irq.domain;
1583 if (!gc->irq.initialized)
1587 if (!gpiochip_irqchip_irq_valid(gc, offset))
1596 spec.param[0] = gc->irq.child_offset_to_irq(gc, offset);
1608 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
1611 return gpiochip_reqres_irq(gc, hwirq);
1617 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
1620 gpiochip_relres_irq(gc, hwirq);
1626 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
1629 if (gc->irq.irq_mask)
1630 gc->irq.irq_mask(d);
1631 gpiochip_disable_irq(gc, hwirq);
1636 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
1639 gpiochip_enable_irq(gc, hwirq);
1640 if (gc->irq.irq_unmask)
1641 gc->irq.irq_unmask(d);
1646 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
1649 gpiochip_enable_irq(gc, hwirq);
1650 gc->irq.irq_enable(d);
1655 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
1658 gc->irq.irq_disable(d);
1659 gpiochip_disable_irq(gc, hwirq);
1662 static void gpiochip_set_irq_hooks(struct gpio_chip *gc)
1664 struct irq_chip *irqchip = gc->irq.chip;
1669 chip_warn(gc, "not an immutable chip, please consider fixing it!\n");
1676 if (WARN_ON(gc->irq.irq_enable))
1685 chip_info(gc,
1691 gc->irq.irq_disable = irqchip->irq_disable;
1694 gc->irq.irq_mask = irqchip->irq_mask;
1699 gc->irq.irq_enable = irqchip->irq_enable;
1702 gc->irq.irq_unmask = irqchip->irq_unmask;
1707 static int gpiochip_irqchip_add_allocated_domain(struct gpio_chip *gc,
1714 if (gc->to_irq)
1715 chip_warn(gc, "to_irq is redefined in %s and you shouldn't rely on it\n", __func__);
1717 gc->to_irq = gpiochip_to_irq;
1718 gc->irq.domain = domain;
1719 gc->irq.domain_is_allocated_externally = allocated_externally;
1723 * gc->irq.initialized before adding irqdomain.
1727 gc->irq.initialized = true;
1734 * @gc: the GPIO chip to add the IRQ chip to
1738 static int gpiochip_add_irqchip(struct gpio_chip *gc,
1742 struct fwnode_handle *fwnode = dev_fwnode(&gc->gpiodev->dev);
1743 struct irq_chip *irqchip = gc->irq.chip;
1752 if (gc->irq.parent_handler && gc->can_sleep) {
1753 chip_err(gc, "you cannot have chained interrupts on a chip that may sleep\n");
1757 type = gc->irq.default_type;
1768 gc->irq.default_type = type;
1769 gc->irq.lock_key = lock_key;
1770 gc->irq.request_key = request_key;
1773 if (gpiochip_hierarchy_is_hierarchical(gc)) {
1774 domain = gpiochip_hierarchy_create_domain(gc);
1776 domain = gpiochip_simple_create_domain(gc);
1781 if (gc->irq.parent_handler) {
1782 for (i = 0; i < gc->irq.num_parents; i++) {
1785 if (gc->irq.per_parent_data)
1786 data = gc->irq.parent_handler_data_array[i];
1788 data = gc->irq.parent_handler_data ?: gc;
1795 irq_set_chained_handler_and_data(gc->irq.parents[i],
1796 gc->irq.parent_handler,
1801 gpiochip_set_irq_hooks(gc);
1803 ret = gpiochip_irqchip_add_allocated_domain(gc, domain, false);
1807 acpi_gpiochip_request_interrupts(gc);
1814 * @gc: the gpiochip to remove the irqchip from
1818 static void gpiochip_irqchip_remove(struct gpio_chip *gc)
1820 struct irq_chip *irqchip = gc->irq.chip;
1823 acpi_gpiochip_free_interrupts(gc);
1825 if (irqchip && gc->irq.parent_handler) {
1826 struct gpio_irq_chip *irq = &gc->irq;
1835 if (!gc->irq.domain_is_allocated_externally && gc->irq.domain) {
1838 for (offset = 0; offset < gc->ngpio; offset++) {
1839 if (!gpiochip_irqchip_irq_valid(gc, offset))
1842 irq = irq_find_mapping(gc->irq.domain, offset);
1846 irq_domain_remove(gc->irq.domain);
1855 irqchip->irq_enable = gc->irq.irq_enable;
1856 irqchip->irq_disable = gc->irq.irq_disable;
1859 gc->irq.irq_enable = NULL;
1860 gc->irq.irq_disable = NULL;
1861 gc->irq.chip = NULL;
1863 gpiochip_irqchip_free_valid_mask(gc);
1868 * @gc: the gpiochip to add the irqchip to
1873 int gpiochip_irqchip_add_domain(struct gpio_chip *gc,
1876 return gpiochip_irqchip_add_allocated_domain(gc, domain, true);
1882 static inline int gpiochip_add_irqchip(struct gpio_chip *gc,
1888 static void gpiochip_irqchip_remove(struct gpio_chip *gc) {}
1890 static inline int gpiochip_irqchip_init_hw(struct gpio_chip *gc)
1895 static inline int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gc)
1899 static inline void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gc)
1906 * @gc: the gpiochip owning the GPIO
1909 int gpiochip_generic_request(struct gpio_chip *gc, unsigned int offset)
1912 if (list_empty(&gc->gpiodev->pin_ranges))
1916 return pinctrl_gpio_request(gc->gpiodev->base + offset);
1922 * @gc: the gpiochip to request the gpio function for
1925 void gpiochip_generic_free(struct gpio_chip *gc, unsigned int offset)
1928 if (list_empty(&gc->gpiodev->pin_ranges))
1932 pinctrl_gpio_free(gc->gpiodev->base + offset);
1938 * @gc: the gpiochip owning the GPIO
1942 int gpiochip_generic_config(struct gpio_chip *gc, unsigned int offset,
1945 return pinctrl_gpio_set_config(gc->gpiodev->base + offset, config);
1953 * @gc: the gpiochip to add the range for
1963 int gpiochip_add_pingroup_range(struct gpio_chip *gc,
1968 struct gpio_device *gdev = gc->gpiodev;
1973 chip_err(gc, "failed to allocate pin ranges\n");
1979 pin_range->range.gc = gc;
1980 pin_range->range.name = gc->label;
1994 chip_dbg(gc, "created GPIO range %d->%d ==> %s PINGRP %s\n",
2006 * @gc: the gpiochip to add the range for
2021 int gpiochip_add_pin_range(struct gpio_chip *gc, const char *pinctl_name,
2026 struct gpio_device *gdev = gc->gpiodev;
2031 chip_err(gc, "failed to allocate pin ranges\n");
2037 pin_range->range.gc = gc;
2038 pin_range->range.name = gc->label;
2046 chip_err(gc, "could not create pin range\n");
2050 chip_dbg(gc, "created GPIO range %d->%d ==> %s PIN %d->%d\n",
2063 * @gc: the chip to remove all the mappings for
2065 void gpiochip_remove_pin_ranges(struct gpio_chip *gc)
2068 struct gpio_device *gdev = gc->gpiodev;
2087 struct gpio_chip *gc = desc->gdev->chip;
2111 if (gc->request) {
2112 /* gc->request may sleep */
2115 if (gpiochip_line_is_valid(gc, offset))
2116 ret = gc->request(gc, offset);
2127 if (gc->get_direction) {
2128 /* gc->get_direction may sleep */
2204 struct gpio_chip *gc;
2210 gc = desc->gdev->chip;
2211 if (gc && test_bit(FLAG_REQUESTED, &desc->flags)) {
2212 if (gc->free) {
2214 might_sleep_if(gc->can_sleep);
2215 gc->free(gc, gpio_chip_hwgpio(desc));
2263 * @gc: controller managing the signal
2274 const char *gpiochip_is_requested(struct gpio_chip *gc, unsigned int offset)
2278 desc = gpiochip_get_desc(gc, offset);
2290 * @gc: GPIO chip
2309 struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *gc,
2315 struct gpio_desc *desc = gpiochip_get_desc(gc, hwnum);
2319 chip_err(gc, "failed to get GPIO descriptor\n");
2329 chip_err(gc, "setup of own GPIO %s failed\n", label);
2362 static int gpio_do_set_config(struct gpio_chip *gc, unsigned int offset,
2365 if (!gc->set_config)
2368 return gc->set_config(gc, offset, config);
2375 struct gpio_chip *gc = desc->gdev->chip;
2379 return gpio_do_set_config(gc, gpio_chip_hwgpio(desc), config);
2466 struct gpio_chip *gc;
2470 gc = desc->gdev->chip;
2477 if (!gc->get && gc->direction_input) {
2490 if (gc->direction_input) {
2491 ret = gc->direction_input(gc, gpio_chip_hwgpio(desc));
2492 } else if (gc->get_direction &&
2493 (gc->get_direction(gc, gpio_chip_hwgpio(desc)) != 1)) {
2512 struct gpio_chip *gc = desc->gdev->chip;
2521 if (!gc->set && !gc->direction_output) {
2528 if (gc->direction_output) {
2529 ret = gc->direction_output(gc, gpio_chip_hwgpio(desc), val);
2532 if (gc->get_direction &&
2533 gc->get_direction(gc, gpio_chip_hwgpio(desc))) {
2543 gc->set(gc, gpio_chip_hwgpio(desc), val);
2655 struct gpio_chip *gc;
2659 gc = desc->gdev->chip;
2660 if (!gc->en_hw_timestamp) {
2665 ret = gc->en_hw_timestamp(gc, gpio_chip_hwgpio(desc), flags);
2684 struct gpio_chip *gc;
2688 gc = desc->gdev->chip;
2689 if (!gc->dis_hw_timestamp) {
2694 ret = gc->dis_hw_timestamp(gc, gpio_chip_hwgpio(desc), flags);
2713 struct gpio_chip *gc;
2716 gc = desc->gdev->chip;
2718 return gpio_do_set_config(gc, gpio_chip_hwgpio(desc), config);
2788 static int gpio_chip_get_value(struct gpio_chip *gc, const struct gpio_desc *desc)
2790 return gc->get ? gc->get(gc, gpio_chip_hwgpio(desc)) : -EIO;
2817 struct gpio_chip *gc;
2820 gc = desc->gdev->chip;
2821 value = gpio_chip_get_value(gc, desc);
2827 static int gpio_chip_get_multiple(struct gpio_chip *gc,
2830 if (gc->get_multiple)
2831 return gc->get_multiple(gc, mask, bits);
2832 if (gc->get) {
2835 for_each_set_bit(i, mask, gc->ngpio) {
2836 value = gc->get(gc, i);
2883 struct gpio_chip *gc = desc_array[i]->gdev->chip;
2889 if (likely(gc->ngpio <= FASTPATH_NGPIO)) {
2895 mask = bitmap_alloc(gc->ngpio, flags);
2899 bits = bitmap_alloc(gc->ngpio, flags);
2906 bitmap_zero(mask, gc->ngpio);
2909 WARN_ON(gc->can_sleep);
2924 (desc_array[i]->gdev->chip == gc));
2926 ret = gpio_chip_get_multiple(gc, mask, bits);
3068 struct gpio_chip *gc = desc->gdev->chip;
3072 ret = gc->direction_input(gc, offset);
3074 ret = gc->direction_output(gc, offset, 0);
3093 struct gpio_chip *gc = desc->gdev->chip;
3097 ret = gc->direction_output(gc, offset, 1);
3101 ret = gc->direction_input(gc, offset);
3112 struct gpio_chip *gc;
3114 gc = desc->gdev->chip;
3116 gc->set(gc, gpio_chip_hwgpio(desc), value);
3129 static void gpio_chip_set_multiple(struct gpio_chip *gc,
3132 if (gc->set_multiple) {
3133 gc->set_multiple(gc, mask, bits);
3138 for_each_set_bit(i, mask, gc->ngpio)
3139 gc->set(gc, i, test_bit(i, bits));
3177 struct gpio_chip *gc = desc_array[i]->gdev->chip;
3183 if (likely(gc->ngpio <= FASTPATH_NGPIO)) {
3189 mask = bitmap_alloc(gc->ngpio, flags);
3193 bits = bitmap_alloc(gc->ngpio, flags);
3200 bitmap_zero(mask, gc->ngpio);
3203 WARN_ON(gc->can_sleep);
3239 (desc_array[i]->gdev->chip == gc));
3242 gpio_chip_set_multiple(gc, mask, bits);
3406 struct gpio_chip *gc;
3417 gc = desc->gdev->chip;
3419 if (gc->to_irq) {
3420 int retirq = gc->to_irq(gc, offset);
3429 if (gc->irq.chip) {
3444 * @gc: the chip the GPIO to lock belongs to
3450 int gpiochip_lock_as_irq(struct gpio_chip *gc, unsigned int offset)
3454 desc = gpiochip_get_desc(gc, offset);
3462 if (!gc->can_sleep && gc->get_direction) {
3466 chip_err(gc, "%s: cannot get GPIO direction\n",
3475 chip_err(gc,
3498 * @gc: the chip the GPIO to lock belongs to
3504 void gpiochip_unlock_as_irq(struct gpio_chip *gc, unsigned int offset)
3508 desc = gpiochip_get_desc(gc, offset);
3521 void gpiochip_disable_irq(struct gpio_chip *gc, unsigned int offset)
3523 struct gpio_desc *desc = gpiochip_get_desc(gc, offset);
3531 void gpiochip_enable_irq(struct gpio_chip *gc, unsigned int offset)
3533 struct gpio_desc *desc = gpiochip_get_desc(gc, offset);
3548 bool gpiochip_line_is_irq(struct gpio_chip *gc, unsigned int offset)
3550 if (offset >= gc->ngpio)
3553 return test_bit(FLAG_USED_AS_IRQ, &gc->gpiodev->descs[offset].flags);
3557 int gpiochip_reqres_irq(struct gpio_chip *gc, unsigned int offset)
3561 if (!try_module_get(gc->gpiodev->owner))
3564 ret = gpiochip_lock_as_irq(gc, offset);
3566 chip_err(gc, "unable to lock HW IRQ %u for IRQ\n", offset);
3567 module_put(gc->gpiodev->owner);
3574 void gpiochip_relres_irq(struct gpio_chip *gc, unsigned int offset)
3576 gpiochip_unlock_as_irq(gc, offset);
3577 module_put(gc->gpiodev->owner);
3581 bool gpiochip_line_is_open_drain(struct gpio_chip *gc, unsigned int offset)
3583 if (offset >= gc->ngpio)
3586 return test_bit(FLAG_OPEN_DRAIN, &gc->gpiodev->descs[offset].flags);
3590 bool gpiochip_line_is_open_source(struct gpio_chip *gc, unsigned int offset)
3592 if (offset >= gc->ngpio)
3595 return test_bit(FLAG_OPEN_SOURCE, &gc->gpiodev->descs[offset].flags);
3599 bool gpiochip_line_is_persistent(struct gpio_chip *gc, unsigned int offset)
3601 if (offset >= gc->ngpio)
3604 return !test_bit(FLAG_TRANSITORY, &gc->gpiodev->descs[offset].flags);
3848 struct gpio_chip *gc;
3860 gc = find_chip_by_name(hog->chip_label);
3861 if (gc)
3862 gpiochip_machine_hog(gc, hog);
3923 struct gpio_chip *gc;
3945 gc = find_chip_by_name(p->key);
3947 if (!gc) {
3960 if (gc->ngpio <= p->chip_hwnum) {
3963 idx, p->chip_hwnum, gc->ngpio - 1,
3964 gc->label);
3968 desc = gpiochip_get_desc(gc, p->chip_hwnum);
4315 struct gpio_chip *gc;
4320 gc = gpiod_to_chip(desc);
4323 local_desc = gpiochip_request_own_desc(gc, hwnum, name,
4328 name, gc->label, hwnum, ret);
4345 * @gc: gpio chip to act on
4347 static void gpiochip_free_hogs(struct gpio_chip *gc)
4351 for_each_gpio_desc_with_flag(gc, desc, FLAG_IS_HOGGED)
4374 struct gpio_chip *gc;
4396 gc = gpiod_to_chip(desc);
4404 bitmap_size = BITS_TO_LONGS(gc->ngpio > count ?
4405 gc->ngpio : count);
4425 array_info->chip = gc;
4438 if (array_info->chip != gc) {
4462 if (gpiochip_line_is_open_drain(gc, descs->ndescs) ||
4463 gpiochip_line_is_open_source(gc, descs->ndescs))
4598 struct gpio_chip *gc = gdev->chip;
4606 for_each_gpio_desc(gc, desc) {
4610 value = gpio_chip_get_value(gc, desc);
4672 struct gpio_chip *gc = gdev->chip;
4675 if (!gc) {
4684 parent = gc->parent;
4689 if (gc->label)
4690 seq_printf(s, ", %s", gc->label);
4691 if (gc->can_sleep)
4695 if (gc->dbg_show)
4696 gc->dbg_show(s, gc);