Lines Matching refs:gdev
113 label = srcu_dereference_check(desc->label, &desc->gdev->desc_srcu, in gpiod_get_label()
114 srcu_read_lock_held(&desc->gdev->desc_srcu)); in gpiod_get_label()
145 call_srcu(&desc->gdev->desc_srcu, &old->rh, desc_free_label); in desc_set_label()
160 struct gpio_device *gdev; in gpio_to_desc() local
163 list_for_each_entry_srcu(gdev, &gpio_devices, list, in gpio_to_desc()
165 if (gdev->base <= gpio && in gpio_to_desc()
166 gdev->base + gdev->ngpio > gpio) in gpio_to_desc()
167 return &gdev->descs[gpio - gdev->base]; in gpio_to_desc()
199 gpio_device_get_desc(struct gpio_device *gdev, unsigned int hwnum) in gpio_device_get_desc() argument
201 if (hwnum >= gdev->ngpio) in gpio_device_get_desc()
204 return &gdev->descs[array_index_nospec(hwnum, gdev->ngpio)]; in gpio_device_get_desc()
220 return desc->gdev->base + (desc - &desc->gdev->descs[0]); in desc_to_gpio()
242 return gpio_device_get_chip(desc->gdev); in gpiod_to_chip()
263 return desc->gdev; in gpiod_to_gpio_device()
274 int gpio_device_get_base(struct gpio_device *gdev) in gpio_device_get_base() argument
276 return gdev->base; in gpio_device_get_base()
288 const char *gpio_device_get_label(struct gpio_device *gdev) in gpio_device_get_label() argument
290 return gdev->label; in gpio_device_get_label()
310 struct gpio_chip *gpio_device_get_chip(struct gpio_device *gdev) in gpio_device_get_chip() argument
312 return rcu_dereference_check(gdev->chip, 1); in gpio_device_get_chip()
320 struct gpio_device *gdev; in gpiochip_find_base_unlocked() local
322 list_for_each_entry_srcu(gdev, &gpio_devices, list, in gpiochip_find_base_unlocked()
325 if (gdev->base >= base + ngpio) in gpiochip_find_base_unlocked()
328 base = gdev->base + gdev->ngpio; in gpiochip_find_base_unlocked()
409 static int gpiodev_add_to_list_unlocked(struct gpio_device *gdev) in gpiodev_add_to_list_unlocked() argument
417 list_add_tail_rcu(&gdev->list, &gpio_devices); in gpiodev_add_to_list_unlocked()
422 if (gdev->base + gdev->ngpio <= next->base) { in gpiodev_add_to_list_unlocked()
424 list_add_rcu(&gdev->list, &gpio_devices); in gpiodev_add_to_list_unlocked()
429 if (prev->base + prev->ngpio <= gdev->base) { in gpiodev_add_to_list_unlocked()
431 list_add_tail_rcu(&gdev->list, &gpio_devices); in gpiodev_add_to_list_unlocked()
441 if (prev->base + prev->ngpio <= gdev->base in gpiodev_add_to_list_unlocked()
442 && gdev->base + gdev->ngpio <= next->base) { in gpiodev_add_to_list_unlocked()
443 list_add_rcu(&gdev->list, &prev->list); in gpiodev_add_to_list_unlocked()
461 struct gpio_device *gdev; in gpio_name_to_desc() local
470 list_for_each_entry_srcu(gdev, &gpio_devices, list, in gpio_name_to_desc()
472 guard(srcu)(&gdev->srcu); in gpio_name_to_desc()
474 gc = srcu_dereference(gdev->chip, &gdev->srcu); in gpio_name_to_desc()
497 struct gpio_device *gdev = gc->gpiodev; in gpiochip_set_desc_names() local
506 dev_warn(&gdev->dev, in gpiochip_set_desc_names()
513 gdev->descs[i].name = gc->names[i]; in gpiochip_set_desc_names()
527 struct gpio_device *gdev = chip->gpiodev; in gpiochip_set_names() local
528 struct device *dev = &gdev->dev; in gpiochip_set_names()
585 gdev->descs[i].name = names[chip->offset + i]; in gpiochip_set_names()
718 struct gpio_device *gdev = to_gpio_device(dev); in gpiodev_release() local
721 synchronize_srcu(&gdev->desc_srcu); in gpiodev_release()
722 cleanup_srcu_struct(&gdev->desc_srcu); in gpiodev_release()
724 ida_free(&gpio_ida, gdev->id); in gpiodev_release()
725 kfree_const(gdev->label); in gpiodev_release()
726 kfree(gdev->descs); in gpiodev_release()
727 cleanup_srcu_struct(&gdev->srcu); in gpiodev_release()
728 kfree(gdev); in gpiodev_release()
737 #define gcdev_register(gdev, devt) gpiolib_cdev_register((gdev), (devt)) argument
738 #define gcdev_unregister(gdev) gpiolib_cdev_unregister((gdev)) argument
744 #define gcdev_register(gdev, devt) device_add(&(gdev)->dev) argument
745 #define gcdev_unregister(gdev) device_del(&(gdev)->dev) argument
748 static int gpiochip_setup_dev(struct gpio_device *gdev) in gpiochip_setup_dev() argument
750 struct fwnode_handle *fwnode = dev_fwnode(&gdev->dev); in gpiochip_setup_dev()
753 device_initialize(&gdev->dev); in gpiochip_setup_dev()
762 ret = gcdev_register(gdev, gpio_devt); in gpiochip_setup_dev()
766 ret = gpiochip_sysfs_register(gdev); in gpiochip_setup_dev()
770 dev_dbg(&gdev->dev, "registered GPIOs %u to %u on %s\n", gdev->base, in gpiochip_setup_dev()
771 gdev->base + gdev->ngpio - 1, gdev->label); in gpiochip_setup_dev()
776 gcdev_unregister(gdev); in gpiochip_setup_dev()
814 struct gpio_device *gdev; in gpiochip_setup_devs() local
819 list_for_each_entry_srcu(gdev, &gpio_devices, list, in gpiochip_setup_devs()
821 ret = gpiochip_setup_dev(gdev); in gpiochip_setup_devs()
823 dev_err(&gdev->dev, in gpiochip_setup_devs()
884 struct gpio_device *gdev; in gpiochip_add_data_with_key() local
893 gdev = kzalloc(sizeof(*gdev), GFP_KERNEL); in gpiochip_add_data_with_key()
894 if (!gdev) in gpiochip_add_data_with_key()
897 gdev->dev.type = &gpio_dev_type; in gpiochip_add_data_with_key()
898 gdev->dev.bus = &gpio_bus_type; in gpiochip_add_data_with_key()
899 gdev->dev.parent = gc->parent; in gpiochip_add_data_with_key()
900 rcu_assign_pointer(gdev->chip, gc); in gpiochip_add_data_with_key()
902 gc->gpiodev = gdev; in gpiochip_add_data_with_key()
910 device_set_node(&gdev->dev, gc->fwnode); in gpiochip_add_data_with_key()
912 device_set_node(&gdev->dev, dev_fwnode(gc->parent)); in gpiochip_add_data_with_key()
914 gdev->id = ida_alloc(&gpio_ida, GFP_KERNEL); in gpiochip_add_data_with_key()
915 if (gdev->id < 0) { in gpiochip_add_data_with_key()
916 ret = gdev->id; in gpiochip_add_data_with_key()
920 ret = dev_set_name(&gdev->dev, GPIOCHIP_NAME "%d", gdev->id); in gpiochip_add_data_with_key()
925 gdev->owner = gc->parent->driver->owner; in gpiochip_add_data_with_key()
928 gdev->owner = gc->owner; in gpiochip_add_data_with_key()
930 gdev->owner = THIS_MODULE; in gpiochip_add_data_with_key()
932 ret = gpiochip_get_ngpios(gc, &gdev->dev); in gpiochip_add_data_with_key()
936 gdev->descs = kcalloc(gc->ngpio, sizeof(*gdev->descs), GFP_KERNEL); in gpiochip_add_data_with_key()
937 if (!gdev->descs) { in gpiochip_add_data_with_key()
942 gdev->label = kstrdup_const(gc->label ?: "unknown", GFP_KERNEL); in gpiochip_add_data_with_key()
943 if (!gdev->label) { in gpiochip_add_data_with_key()
948 gdev->ngpio = gc->ngpio; in gpiochip_add_data_with_key()
949 gdev->can_sleep = gc->can_sleep; in gpiochip_add_data_with_key()
976 dev_warn(&gdev->dev, in gpiochip_add_data_with_key()
980 gdev->base = base; in gpiochip_add_data_with_key()
982 ret = gpiodev_add_to_list_unlocked(gdev); in gpiochip_add_data_with_key()
990 gdev->descs[desc_index].gdev = gdev; in gpiochip_add_data_with_key()
992 BLOCKING_INIT_NOTIFIER_HEAD(&gdev->line_state_notifier); in gpiochip_add_data_with_key()
993 BLOCKING_INIT_NOTIFIER_HEAD(&gdev->device_notifier); in gpiochip_add_data_with_key()
995 ret = init_srcu_struct(&gdev->srcu); in gpiochip_add_data_with_key()
999 ret = init_srcu_struct(&gdev->desc_srcu); in gpiochip_add_data_with_key()
1004 INIT_LIST_HEAD(&gdev->pin_ranges); in gpiochip_add_data_with_key()
1019 struct gpio_desc *desc = &gdev->descs[desc_index]; in gpiochip_add_data_with_key()
1063 ret = gpiochip_setup_dev(gdev); in gpiochip_add_data_with_key()
1082 cleanup_srcu_struct(&gdev->desc_srcu); in gpiochip_add_data_with_key()
1084 cleanup_srcu_struct(&gdev->srcu); in gpiochip_add_data_with_key()
1087 list_del_rcu(&gdev->list); in gpiochip_add_data_with_key()
1089 if (gdev->dev.release) { in gpiochip_add_data_with_key()
1091 gpio_device_put(gdev); in gpiochip_add_data_with_key()
1095 kfree_const(gdev->label); in gpiochip_add_data_with_key()
1097 kfree(gdev->descs); in gpiochip_add_data_with_key()
1099 kfree(dev_name(&gdev->dev)); in gpiochip_add_data_with_key()
1101 ida_free(&gpio_ida, gdev->id); in gpiochip_add_data_with_key()
1103 kfree(gdev); in gpiochip_add_data_with_key()
1123 struct gpio_device *gdev = gc->gpiodev; in gpiochip_remove() local
1126 gpiochip_sysfs_unregister(gdev); in gpiochip_remove()
1130 list_del_rcu(&gdev->list); in gpiochip_remove()
1134 rcu_assign_pointer(gdev->chip, NULL); in gpiochip_remove()
1135 synchronize_srcu(&gdev->srcu); in gpiochip_remove()
1153 gcdev_unregister(gdev); in gpiochip_remove()
1154 gpio_device_put(gdev); in gpiochip_remove()
1183 struct gpio_device *gdev; in gpio_device_find() local
1195 list_for_each_entry_srcu(gdev, &gpio_devices, list, in gpio_device_find()
1197 if (!device_is_registered(&gdev->dev)) in gpio_device_find()
1200 guard(srcu)(&gdev->srcu); in gpio_device_find()
1202 gc = srcu_dereference(gdev->chip, &gdev->srcu); in gpio_device_find()
1205 return gpio_device_get(gdev); in gpio_device_find()
1259 struct gpio_device *gpio_device_get(struct gpio_device *gdev) in gpio_device_get() argument
1261 return to_gpio_device(get_device(&gdev->dev)); in gpio_device_get()
1270 void gpio_device_put(struct gpio_device *gdev) in gpio_device_put() argument
1272 put_device(&gdev->dev); in gpio_device_put()
1287 struct device *gpio_device_to_device(struct gpio_device *gdev) in gpio_device_to_device() argument
1289 return &gdev->dev; in gpio_device_to_device()
2158 struct gpio_device *gdev = gc->gpiodev; in gpiochip_add_pingroup_range() local
2171 pin_range->range.base = gdev->base + gpio_offset; in gpiochip_add_pingroup_range()
2188 list_add_tail(&pin_range->node, &gdev->pin_ranges); in gpiochip_add_pingroup_range()
2216 struct gpio_device *gdev = gc->gpiodev; in gpiochip_add_pin_range() local
2229 pin_range->range.base = gdev->base + gpio_offset; in gpiochip_add_pin_range()
2245 list_add_tail(&pin_range->node, &gdev->pin_ranges); in gpiochip_add_pin_range()
2258 struct gpio_device *gdev = gc->gpiodev; in gpiochip_remove_pin_ranges() local
2260 list_for_each_entry_safe(pin_range, tmp, &gdev->pin_ranges, node) { in gpiochip_remove_pin_ranges()
2352 if (try_module_get(desc->gdev->owner)) { in gpiod_request()
2355 module_put(desc->gdev->owner); in gpiod_request()
2357 gpio_device_get(desc->gdev); in gpiod_request()
2405 module_put(desc->gdev->owner); in gpiod_free()
2406 gpio_device_put(desc->gdev); in gpiod_free()
2433 guard(srcu)(&desc->gdev->desc_srcu); in gpiochip_dup_line_label()
2550 struct device *dev = &desc->gdev->dev; in gpio_set_config_with_argument_optional()
3008 struct gpio_device *gdev; in gpiod_get_raw_value_commit() local
3013 gdev = desc->gdev; in gpiod_get_raw_value_commit()
3015 guard(srcu)(&gdev->srcu); in gpiod_get_raw_value_commit()
3017 gc = srcu_dereference(gdev->chip, &gdev->srcu); in gpiod_get_raw_value_commit()
3047 static bool gpio_device_chip_cmp(struct gpio_device *gdev, struct gpio_chip *gc) in gpio_device_chip_cmp() argument
3049 guard(srcu)(&gdev->srcu); in gpio_device_chip_cmp()
3051 return gc == srcu_dereference(gdev->chip, &gdev->srcu); in gpio_device_chip_cmp()
3135 gpio_device_chip_cmp(desc_array[i]->gdev, guard.gc)); in gpiod_get_array_value_complex()
3185 WARN_ON(desc->gdev->can_sleep); in gpiod_get_raw_value()
3207 WARN_ON(desc->gdev->can_sleep); in gpiod_get_value()
3465 gpio_device_chip_cmp(desc_array[i]->gdev, guard.gc)); in gpiod_set_array_value_complex()
3493 WARN_ON(desc->gdev->can_sleep); in gpiod_set_raw_value()
3534 WARN_ON(desc->gdev->can_sleep); in gpiod_set_value()
3606 return desc->gdev->can_sleep; in gpiod_cansleep()
3635 struct gpio_device *gdev; in gpiod_to_irq() local
3647 gdev = desc->gdev; in gpiod_to_irq()
3649 guard(srcu)(&gdev->srcu); in gpiod_to_irq()
3650 gc = srcu_dereference(gdev->chip, &gdev->srcu); in gpiod_to_irq()
4050 blocking_notifier_call_chain(&desc->gdev->line_state_notifier, in gpiod_line_state_notify()
4099 struct gpio_device *gdev __free(gpio_device_put) = in gpiod_add_hogs()
4101 if (gdev) in gpiod_add_hogs()
4102 gpiochip_machine_hog(gpio_device_get_chip(gdev), hog); in gpiod_add_hogs()
4181 struct gpio_device *gdev __free(gpio_device_put) = in gpiod_find()
4183 if (!gdev) { in gpiod_find()
4196 gc = gpio_device_get_chip(gdev); in gpiod_find()
4206 desc = gpio_device_get_desc(gdev, p->chip_hwnum); in gpiod_find()
4582 struct gpio_device *gdev = desc->gdev; in gpiod_hog() local
4602 name, gdev->label, hwnum, ret); in gpiod_hog()
4875 static void gpiolib_dbg_show(struct seq_file *s, struct gpio_device *gdev) in gpiolib_dbg_show() argument
4878 unsigned int gpio = gdev->base; in gpiolib_dbg_show()
4883 guard(srcu)(&gdev->srcu); in gpiolib_dbg_show()
4885 gc = srcu_dereference(gdev->chip, &gdev->srcu); in gpiolib_dbg_show()
4892 guard(srcu)(&desc->gdev->desc_srcu); in gpiolib_dbg_show()
4921 struct gpio_device *gdev; in gpiolib_seq_start() local
4933 list_for_each_entry_srcu(gdev, &gpio_devices, list, in gpiolib_seq_start()
4936 return gdev; in gpiolib_seq_start()
4945 struct gpio_device *gdev = v, *next; in gpiolib_seq_next() local
4947 next = list_entry_rcu(gdev->list.next, struct gpio_device, list); in gpiolib_seq_next()
4948 gdev = &next->list == &gpio_devices ? NULL : next; in gpiolib_seq_next()
4952 return gdev; in gpiolib_seq_next()
4966 struct gpio_device *gdev = v; in gpiolib_seq_show() local
4970 guard(srcu)(&gdev->srcu); in gpiolib_seq_show()
4972 gc = srcu_dereference(gdev->chip, &gdev->srcu); in gpiolib_seq_show()
4976 dev_name(&gdev->dev)); in gpiolib_seq_show()
4981 dev_name(&gdev->dev), in gpiolib_seq_show()
4982 gdev->base, gdev->base + gdev->ngpio - 1); in gpiolib_seq_show()
4997 gpiolib_dbg_show(s, gdev); in gpiolib_seq_show()