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