Lines Matching refs:gdev

127 	label = srcu_dereference_check(desc->label, &desc->gdev->desc_srcu,  in gpiod_get_label()
128 srcu_read_lock_held(&desc->gdev->desc_srcu)); in gpiod_get_label()
159 call_srcu(&desc->gdev->desc_srcu, &old->rh, desc_free_label); in desc_set_label()
174 struct gpio_device *gdev; in gpio_to_desc() local
177 list_for_each_entry_srcu(gdev, &gpio_devices, list, in gpio_to_desc()
179 if (gdev->base <= gpio && in gpio_to_desc()
180 gdev->base + gdev->ngpio > gpio) in gpio_to_desc()
181 return &gdev->descs[gpio - gdev->base]; in gpio_to_desc()
213 gpio_device_get_desc(struct gpio_device *gdev, unsigned int hwnum) in gpio_device_get_desc() argument
215 if (hwnum >= gdev->ngpio) in gpio_device_get_desc()
218 return &gdev->descs[array_index_nospec(hwnum, gdev->ngpio)]; in gpio_device_get_desc()
234 return desc->gdev->base + (desc - &desc->gdev->descs[0]); in desc_to_gpio()
256 return gpio_device_get_chip(desc->gdev); in gpiod_to_chip()
277 return desc->gdev; in gpiod_to_gpio_device()
288 int gpio_device_get_base(struct gpio_device *gdev) in gpio_device_get_base() argument
290 return gdev->base; in gpio_device_get_base()
302 const char *gpio_device_get_label(struct gpio_device *gdev) in gpio_device_get_label() argument
304 return gdev->label; in gpio_device_get_label()
324 struct gpio_chip *gpio_device_get_chip(struct gpio_device *gdev) in gpio_device_get_chip() argument
326 return rcu_dereference_check(gdev->chip, 1); in gpio_device_get_chip()
334 struct gpio_device *gdev; in gpiochip_find_base_unlocked() local
336 list_for_each_entry_srcu(gdev, &gpio_devices, list, in gpiochip_find_base_unlocked()
339 if (gdev->base >= base + ngpio) in gpiochip_find_base_unlocked()
342 base = gdev->base + gdev->ngpio; in gpiochip_find_base_unlocked()
485 static int gpiodev_add_to_list_unlocked(struct gpio_device *gdev) in gpiodev_add_to_list_unlocked() argument
493 list_add_tail_rcu(&gdev->list, &gpio_devices); in gpiodev_add_to_list_unlocked()
498 if (gdev->base + gdev->ngpio <= next->base) { in gpiodev_add_to_list_unlocked()
500 list_add_rcu(&gdev->list, &gpio_devices); in gpiodev_add_to_list_unlocked()
505 if (prev->base + prev->ngpio <= gdev->base) { in gpiodev_add_to_list_unlocked()
507 list_add_tail_rcu(&gdev->list, &gpio_devices); in gpiodev_add_to_list_unlocked()
517 if (prev->base + prev->ngpio <= gdev->base in gpiodev_add_to_list_unlocked()
518 && gdev->base + gdev->ngpio <= next->base) { in gpiodev_add_to_list_unlocked()
519 list_add_rcu(&gdev->list, &prev->list); in gpiodev_add_to_list_unlocked()
537 struct gpio_device *gdev; in gpio_name_to_desc() local
546 list_for_each_entry_srcu(gdev, &gpio_devices, list, in gpio_name_to_desc()
548 guard(srcu)(&gdev->srcu); in gpio_name_to_desc()
550 gc = srcu_dereference(gdev->chip, &gdev->srcu); in gpio_name_to_desc()
573 struct gpio_device *gdev = gc->gpiodev; in gpiochip_set_desc_names() local
582 dev_warn(&gdev->dev, in gpiochip_set_desc_names()
589 gdev->descs[i].name = gc->names[i]; in gpiochip_set_desc_names()
603 struct gpio_device *gdev = chip->gpiodev; in gpiochip_set_names() local
604 struct device *dev = &gdev->dev; in gpiochip_set_names()
661 gdev->descs[i].name = names[chip->offset + i]; in gpiochip_set_names()
855 struct gpio_device *gdev = to_gpio_device(dev); in gpiodev_release() local
858 synchronize_srcu(&gdev->desc_srcu); in gpiodev_release()
859 cleanup_srcu_struct(&gdev->desc_srcu); in gpiodev_release()
861 ida_free(&gpio_ida, gdev->id); in gpiodev_release()
862 kfree_const(gdev->label); in gpiodev_release()
863 kfree(gdev->descs); in gpiodev_release()
864 cleanup_srcu_struct(&gdev->srcu); in gpiodev_release()
865 kfree(gdev); in gpiodev_release()
874 #define gcdev_register(gdev, devt) gpiolib_cdev_register((gdev), (devt)) argument
875 #define gcdev_unregister(gdev) gpiolib_cdev_unregister((gdev)) argument
881 #define gcdev_register(gdev, devt) device_add(&(gdev)->dev) argument
882 #define gcdev_unregister(gdev) device_del(&(gdev)->dev) argument
885 static int gpiochip_setup_dev(struct gpio_device *gdev) in gpiochip_setup_dev() argument
887 struct fwnode_handle *fwnode = dev_fwnode(&gdev->dev); in gpiochip_setup_dev()
890 device_initialize(&gdev->dev); in gpiochip_setup_dev()
899 ret = gcdev_register(gdev, gpio_devt); in gpiochip_setup_dev()
903 ret = gpiochip_sysfs_register(gdev); in gpiochip_setup_dev()
907 dev_dbg(&gdev->dev, "registered GPIOs %u to %u on %s\n", gdev->base, in gpiochip_setup_dev()
908 gdev->base + gdev->ngpio - 1, gdev->label); in gpiochip_setup_dev()
913 gcdev_unregister(gdev); in gpiochip_setup_dev()
949 struct gpio_device *gdev; in gpiochip_setup_devs() local
954 list_for_each_entry_srcu(gdev, &gpio_devices, list, in gpiochip_setup_devs()
956 ret = gpiochip_setup_dev(gdev); in gpiochip_setup_devs()
958 dev_err(&gdev->dev, in gpiochip_setup_devs()
1035 struct gpio_device *gdev; in gpiochip_add_data_with_key() local
1044 gdev = kzalloc(sizeof(*gdev), GFP_KERNEL); in gpiochip_add_data_with_key()
1045 if (!gdev) in gpiochip_add_data_with_key()
1048 gdev->dev.type = &gpio_dev_type; in gpiochip_add_data_with_key()
1049 gdev->dev.bus = &gpio_bus_type; in gpiochip_add_data_with_key()
1050 gdev->dev.parent = gc->parent; in gpiochip_add_data_with_key()
1051 rcu_assign_pointer(gdev->chip, gc); in gpiochip_add_data_with_key()
1053 gc->gpiodev = gdev; in gpiochip_add_data_with_key()
1056 device_set_node(&gdev->dev, gpiochip_choose_fwnode(gc)); in gpiochip_add_data_with_key()
1061 gdev->id = ret; in gpiochip_add_data_with_key()
1063 ret = dev_set_name(&gdev->dev, GPIOCHIP_NAME "%d", gdev->id); in gpiochip_add_data_with_key()
1068 gdev->owner = gc->parent->driver->owner; in gpiochip_add_data_with_key()
1071 gdev->owner = gc->owner; in gpiochip_add_data_with_key()
1073 gdev->owner = THIS_MODULE; in gpiochip_add_data_with_key()
1075 ret = gpiochip_get_ngpios(gc, &gdev->dev); in gpiochip_add_data_with_key()
1079 gdev->descs = kcalloc(gc->ngpio, sizeof(*gdev->descs), GFP_KERNEL); in gpiochip_add_data_with_key()
1080 if (!gdev->descs) { in gpiochip_add_data_with_key()
1085 gdev->label = kstrdup_const(gc->label ?: "unknown", GFP_KERNEL); in gpiochip_add_data_with_key()
1086 if (!gdev->label) { in gpiochip_add_data_with_key()
1091 gdev->ngpio = gc->ngpio; in gpiochip_add_data_with_key()
1092 gdev->can_sleep = gc->can_sleep; in gpiochip_add_data_with_key()
1119 dev_warn(&gdev->dev, in gpiochip_add_data_with_key()
1123 gdev->base = base; in gpiochip_add_data_with_key()
1125 ret = gpiodev_add_to_list_unlocked(gdev); in gpiochip_add_data_with_key()
1132 rwlock_init(&gdev->line_state_lock); in gpiochip_add_data_with_key()
1133 RAW_INIT_NOTIFIER_HEAD(&gdev->line_state_notifier); in gpiochip_add_data_with_key()
1134 BLOCKING_INIT_NOTIFIER_HEAD(&gdev->device_notifier); in gpiochip_add_data_with_key()
1136 ret = init_srcu_struct(&gdev->srcu); in gpiochip_add_data_with_key()
1140 ret = init_srcu_struct(&gdev->desc_srcu); in gpiochip_add_data_with_key()
1145 INIT_LIST_HEAD(&gdev->pin_ranges); in gpiochip_add_data_with_key()
1160 struct gpio_desc *desc = &gdev->descs[desc_index]; in gpiochip_add_data_with_key()
1162 desc->gdev = gdev; in gpiochip_add_data_with_key()
1212 ret = gpiochip_setup_dev(gdev); in gpiochip_add_data_with_key()
1231 cleanup_srcu_struct(&gdev->desc_srcu); in gpiochip_add_data_with_key()
1233 cleanup_srcu_struct(&gdev->srcu); in gpiochip_add_data_with_key()
1236 list_del_rcu(&gdev->list); in gpiochip_add_data_with_key()
1238 if (gdev->dev.release) { in gpiochip_add_data_with_key()
1240 gpio_device_put(gdev); in gpiochip_add_data_with_key()
1244 kfree_const(gdev->label); in gpiochip_add_data_with_key()
1246 kfree(gdev->descs); in gpiochip_add_data_with_key()
1248 kfree(dev_name(&gdev->dev)); in gpiochip_add_data_with_key()
1250 ida_free(&gpio_ida, gdev->id); in gpiochip_add_data_with_key()
1252 kfree(gdev); in gpiochip_add_data_with_key()
1272 struct gpio_device *gdev = gc->gpiodev; in gpiochip_remove() local
1275 gpiochip_sysfs_unregister(gdev); in gpiochip_remove()
1280 list_del_rcu(&gdev->list); in gpiochip_remove()
1284 rcu_assign_pointer(gdev->chip, NULL); in gpiochip_remove()
1285 synchronize_srcu(&gdev->srcu); in gpiochip_remove()
1303 gcdev_unregister(gdev); in gpiochip_remove()
1304 gpio_device_put(gdev); in gpiochip_remove()
1333 struct gpio_device *gdev; in gpio_device_find() local
1340 list_for_each_entry_srcu(gdev, &gpio_devices, list, in gpio_device_find()
1342 if (!device_is_registered(&gdev->dev)) in gpio_device_find()
1345 guard(srcu)(&gdev->srcu); in gpio_device_find()
1347 gc = srcu_dereference(gdev->chip, &gdev->srcu); in gpio_device_find()
1350 return gpio_device_get(gdev); in gpio_device_find()
1404 struct gpio_device *gpio_device_get(struct gpio_device *gdev) in gpio_device_get() argument
1406 return to_gpio_device(get_device(&gdev->dev)); in gpio_device_get()
1415 void gpio_device_put(struct gpio_device *gdev) in gpio_device_put() argument
1417 put_device(&gdev->dev); in gpio_device_put()
1432 struct device *gpio_device_to_device(struct gpio_device *gdev) in gpio_device_to_device() argument
1434 return &gdev->dev; in gpio_device_to_device()
2315 struct gpio_device *gdev = gc->gpiodev; in gpiochip_add_pingroup_range() local
2328 pin_range->range.base = gdev->base + gpio_offset; in gpiochip_add_pingroup_range()
2345 list_add_tail(&pin_range->node, &gdev->pin_ranges); in gpiochip_add_pingroup_range()
2373 struct gpio_device *gdev = gc->gpiodev; in gpiochip_add_pin_range() local
2386 pin_range->range.base = gdev->base + gpio_offset; in gpiochip_add_pin_range()
2402 list_add_tail(&pin_range->node, &gdev->pin_ranges); in gpiochip_add_pin_range()
2415 struct gpio_device *gdev = gc->gpiodev; in gpiochip_remove_pin_ranges() local
2417 list_for_each_entry_safe(pin_range, tmp, &gdev->pin_ranges, node) { in gpiochip_remove_pin_ranges()
2480 if (try_module_get(desc->gdev->owner)) { in gpiod_request()
2483 module_put(desc->gdev->owner); in gpiod_request()
2485 gpio_device_get(desc->gdev); in gpiod_request()
2535 module_put(desc->gdev->owner); in gpiod_free()
2536 gpio_device_put(desc->gdev); in gpiod_free()
2563 guard(srcu)(&desc->gdev->desc_srcu); in gpiochip_dup_line_label()
2696 struct device *dev = &desc->gdev->dev; in gpio_set_config_with_argument_optional()
3282 struct gpio_device *gdev; in gpiod_get_raw_value_commit() local
3287 gdev = desc->gdev; in gpiod_get_raw_value_commit()
3289 guard(srcu)(&gdev->srcu); in gpiod_get_raw_value_commit()
3291 gc = srcu_dereference(gdev->chip, &gdev->srcu); in gpiod_get_raw_value_commit()
3330 static bool gpio_device_chip_cmp(struct gpio_device *gdev, struct gpio_chip *gc) in gpio_device_chip_cmp() argument
3332 guard(srcu)(&gdev->srcu); in gpio_device_chip_cmp()
3334 return gc == srcu_dereference(gdev->chip, &gdev->srcu); in gpio_device_chip_cmp()
3355 WARN_ON(array_info->gdev->can_sleep); in gpiod_get_array_value_complex()
3357 guard(srcu)(&array_info->gdev->srcu); in gpiod_get_array_value_complex()
3358 gc = srcu_dereference(array_info->gdev->chip, in gpiod_get_array_value_complex()
3359 &array_info->gdev->srcu); in gpiod_get_array_value_complex()
3424 gpio_device_chip_cmp(desc_array[i]->gdev, guard.gc)); in gpiod_get_array_value_complex()
3474 WARN_ON(desc->gdev->can_sleep); in gpiod_get_raw_value()
3496 WARN_ON(desc->gdev->can_sleep); in gpiod_get_value()
3694 WARN_ON(array_info->gdev->can_sleep); in gpiod_set_array_value_complex()
3702 guard(srcu)(&array_info->gdev->srcu); in gpiod_set_array_value_complex()
3703 gc = srcu_dereference(array_info->gdev->chip, in gpiod_set_array_value_complex()
3704 &array_info->gdev->srcu); in gpiod_set_array_value_complex()
3793 gpio_device_chip_cmp(desc_array[i]->gdev, guard.gc)); in gpiod_set_array_value_complex()
3827 WARN_ON(desc->gdev->can_sleep); in gpiod_set_raw_value()
3875 WARN_ON(desc->gdev->can_sleep); in gpiod_set_value()
3947 return desc->gdev->can_sleep; in gpiod_cansleep()
3982 struct gpio_device *gdev; in gpiod_to_irq() local
3991 gdev = desc->gdev; in gpiod_to_irq()
3993 guard(srcu)(&gdev->srcu); in gpiod_to_irq()
3994 gc = srcu_dereference(gdev->chip, &gdev->srcu); in gpiod_to_irq()
4397 guard(read_lock_irqsave)(&desc->gdev->line_state_lock); in gpiod_line_state_notify()
4399 raw_notifier_call_chain(&desc->gdev->line_state_notifier, action, desc); in gpiod_line_state_notify()
4445 struct gpio_device *gdev __free(gpio_device_put) = in gpiod_add_hogs()
4447 if (gdev) in gpiod_add_hogs()
4448 gpiochip_machine_hog(gpio_device_get_chip(gdev), hog); in gpiod_add_hogs()
4525 struct gpio_device *gdev __free(gpio_device_put) = in gpiod_find()
4527 if (!gdev) { in gpiod_find()
4540 gc = gpio_device_get_chip(gdev); in gpiod_find()
4550 desc = gpio_device_get_desc(gdev, p->chip_hwnum); in gpiod_find()
4926 struct gpio_device *gdev = desc->gdev; in gpiod_hog() local
4946 name, gdev->label, hwnum, ret); in gpiod_hog()
4990 struct gpio_device *gdev; in gpiod_get_array() local
5014 gdev = gpiod_to_gpio_device(desc); in gpiod_get_array()
5022 bitmap_size = BITS_TO_LONGS(gdev->ngpio > count ? in gpiod_get_array()
5023 gdev->ngpio : count); in gpiod_get_array()
5043 array_info->gdev = gdev; in gpiod_get_array()
5056 if (array_info->gdev != gdev) { in gpiod_get_array()
5094 array_info->gdev->label, array_info->size, in gpiod_get_array()
5220 static void gpiolib_dbg_show(struct seq_file *s, struct gpio_device *gdev) in gpiolib_dbg_show() argument
5229 guard(srcu)(&gdev->srcu); in gpiolib_dbg_show()
5231 gc = srcu_dereference(gdev->chip, &gdev->srcu); in gpiolib_dbg_show()
5238 guard(srcu)(&desc->gdev->desc_srcu); in gpiolib_dbg_show()
5268 struct gpio_device *gdev; in gpiolib_seq_start() local
5280 list_for_each_entry_srcu(gdev, &gpio_devices, list, in gpiolib_seq_start()
5283 return gdev; in gpiolib_seq_start()
5292 struct gpio_device *gdev = v, *next; in gpiolib_seq_next() local
5294 next = list_entry_rcu(gdev->list.next, struct gpio_device, list); in gpiolib_seq_next()
5295 gdev = &next->list == &gpio_devices ? NULL : next; in gpiolib_seq_next()
5299 return gdev; in gpiolib_seq_next()
5313 struct gpio_device *gdev = v; in gpiolib_seq_show() local
5320 guard(srcu)(&gdev->srcu); in gpiolib_seq_show()
5322 gc = srcu_dereference(gdev->chip, &gdev->srcu); in gpiolib_seq_show()
5324 seq_printf(s, "%s: (dangling chip)\n", dev_name(&gdev->dev)); in gpiolib_seq_show()
5328 seq_printf(s, "%s: %u GPIOs", dev_name(&gdev->dev), gdev->ngpio); in gpiolib_seq_show()
5343 gpiolib_dbg_show(s, gdev); in gpiolib_seq_show()