Lines Matching refs:gdev
128 label = srcu_dereference_check(desc->label, &desc->gdev->desc_srcu, in gpiod_get_label()
129 srcu_read_lock_held(&desc->gdev->desc_srcu)); in gpiod_get_label()
160 call_srcu(&desc->gdev->desc_srcu, &old->rh, desc_free_label); in desc_set_label()
175 struct gpio_device *gdev; in gpio_to_desc() local
178 list_for_each_entry_srcu(gdev, &gpio_devices, list, in gpio_to_desc()
180 if (gdev->base <= gpio && in gpio_to_desc()
181 gdev->base + gdev->ngpio > gpio) in gpio_to_desc()
182 return &gdev->descs[gpio - gdev->base]; in gpio_to_desc()
214 gpio_device_get_desc(struct gpio_device *gdev, unsigned int hwnum) in gpio_device_get_desc() argument
216 if (hwnum >= gdev->ngpio) in gpio_device_get_desc()
219 return &gdev->descs[array_index_nospec(hwnum, gdev->ngpio)]; in gpio_device_get_desc()
235 return desc->gdev->base + (desc - &desc->gdev->descs[0]); in desc_to_gpio()
249 return desc - &desc->gdev->descs[0]; in gpiod_hwgpio()
270 return gpio_device_get_chip(desc->gdev); in gpiod_to_chip()
291 return desc->gdev; in gpiod_to_gpio_device()
302 int gpio_device_get_base(struct gpio_device *gdev) in gpio_device_get_base() argument
304 return gdev->base; in gpio_device_get_base()
316 const char *gpio_device_get_label(struct gpio_device *gdev) in gpio_device_get_label() argument
318 return gdev->label; in gpio_device_get_label()
338 struct gpio_chip *gpio_device_get_chip(struct gpio_device *gdev) in gpio_device_get_chip() argument
340 return rcu_dereference_check(gdev->chip, 1); in gpio_device_get_chip()
348 struct gpio_device *gdev; in gpiochip_find_base_unlocked() local
350 list_for_each_entry_srcu(gdev, &gpio_devices, list, in gpiochip_find_base_unlocked()
353 if (gdev->base >= base + ngpio) in gpiochip_find_base_unlocked()
356 base = gdev->base + gdev->ngpio; in gpiochip_find_base_unlocked()
496 static int gpiodev_add_to_list_unlocked(struct gpio_device *gdev) in gpiodev_add_to_list_unlocked() argument
504 list_add_tail_rcu(&gdev->list, &gpio_devices); in gpiodev_add_to_list_unlocked()
509 if (gdev->base + gdev->ngpio <= next->base) { in gpiodev_add_to_list_unlocked()
511 list_add_rcu(&gdev->list, &gpio_devices); in gpiodev_add_to_list_unlocked()
516 if (prev->base + prev->ngpio <= gdev->base) { in gpiodev_add_to_list_unlocked()
518 list_add_tail_rcu(&gdev->list, &gpio_devices); in gpiodev_add_to_list_unlocked()
528 if (prev->base + prev->ngpio <= gdev->base in gpiodev_add_to_list_unlocked()
529 && gdev->base + gdev->ngpio <= next->base) { in gpiodev_add_to_list_unlocked()
530 list_add_rcu(&gdev->list, &prev->list); in gpiodev_add_to_list_unlocked()
548 struct gpio_device *gdev; in gpio_name_to_desc() local
557 list_for_each_entry_srcu(gdev, &gpio_devices, list, in gpio_name_to_desc()
559 guard(srcu)(&gdev->srcu); in gpio_name_to_desc()
561 gc = srcu_dereference(gdev->chip, &gdev->srcu); in gpio_name_to_desc()
584 struct gpio_device *gdev = gc->gpiodev; in gpiochip_set_desc_names() local
593 dev_warn(&gdev->dev, in gpiochip_set_desc_names()
600 gdev->descs[i].name = gc->names[i]; in gpiochip_set_desc_names()
614 struct gpio_device *gdev = chip->gpiodev; in gpiochip_set_names() local
615 struct device *dev = &gdev->dev; in gpiochip_set_names()
672 gdev->descs[i].name = names[chip->offset + i]; in gpiochip_set_names()
866 struct gpio_device *gdev = to_gpio_device(dev); in gpiodev_release() local
869 synchronize_srcu(&gdev->desc_srcu); in gpiodev_release()
870 cleanup_srcu_struct(&gdev->desc_srcu); in gpiodev_release()
872 ida_free(&gpio_ida, gdev->id); in gpiodev_release()
873 kfree_const(gdev->label); in gpiodev_release()
874 kfree(gdev->descs); in gpiodev_release()
875 cleanup_srcu_struct(&gdev->srcu); in gpiodev_release()
876 kfree(gdev); in gpiodev_release()
885 #define gcdev_register(gdev, devt) gpiolib_cdev_register((gdev), (devt)) argument
886 #define gcdev_unregister(gdev) gpiolib_cdev_unregister((gdev)) argument
892 #define gcdev_register(gdev, devt) device_add(&(gdev)->dev) argument
893 #define gcdev_unregister(gdev) device_del(&(gdev)->dev) argument
896 static int gpiochip_setup_dev(struct gpio_device *gdev) in gpiochip_setup_dev() argument
898 struct fwnode_handle *fwnode = dev_fwnode(&gdev->dev); in gpiochip_setup_dev()
901 device_initialize(&gdev->dev); in gpiochip_setup_dev()
910 ret = gcdev_register(gdev, gpio_devt); in gpiochip_setup_dev()
914 ret = gpiochip_sysfs_register(gdev); in gpiochip_setup_dev()
918 dev_dbg(&gdev->dev, "registered GPIOs %u to %u on %s\n", gdev->base, in gpiochip_setup_dev()
919 gdev->base + gdev->ngpio - 1, gdev->label); in gpiochip_setup_dev()
924 gcdev_unregister(gdev); in gpiochip_setup_dev()
960 struct gpio_device *gdev; in gpiochip_setup_devs() local
965 list_for_each_entry_srcu(gdev, &gpio_devices, list, in gpiochip_setup_devs()
967 ret = gpiochip_setup_dev(gdev); in gpiochip_setup_devs()
969 dev_err(&gdev->dev, in gpiochip_setup_devs()
1046 struct gpio_device *gdev; in gpiochip_add_data_with_key() local
1055 gdev = kzalloc(sizeof(*gdev), GFP_KERNEL); in gpiochip_add_data_with_key()
1056 if (!gdev) in gpiochip_add_data_with_key()
1059 gdev->dev.type = &gpio_dev_type; in gpiochip_add_data_with_key()
1060 gdev->dev.bus = &gpio_bus_type; in gpiochip_add_data_with_key()
1061 gdev->dev.parent = gc->parent; in gpiochip_add_data_with_key()
1062 rcu_assign_pointer(gdev->chip, gc); in gpiochip_add_data_with_key()
1064 gc->gpiodev = gdev; in gpiochip_add_data_with_key()
1067 device_set_node(&gdev->dev, gpiochip_choose_fwnode(gc)); in gpiochip_add_data_with_key()
1072 gdev->id = ret; in gpiochip_add_data_with_key()
1074 ret = dev_set_name(&gdev->dev, GPIOCHIP_NAME "%d", gdev->id); in gpiochip_add_data_with_key()
1079 gdev->owner = gc->parent->driver->owner; in gpiochip_add_data_with_key()
1082 gdev->owner = gc->owner; in gpiochip_add_data_with_key()
1084 gdev->owner = THIS_MODULE; in gpiochip_add_data_with_key()
1086 ret = gpiochip_get_ngpios(gc, &gdev->dev); in gpiochip_add_data_with_key()
1090 gdev->descs = kcalloc(gc->ngpio, sizeof(*gdev->descs), GFP_KERNEL); in gpiochip_add_data_with_key()
1091 if (!gdev->descs) { in gpiochip_add_data_with_key()
1096 gdev->label = kstrdup_const(gc->label ?: "unknown", GFP_KERNEL); in gpiochip_add_data_with_key()
1097 if (!gdev->label) { in gpiochip_add_data_with_key()
1102 gdev->ngpio = gc->ngpio; in gpiochip_add_data_with_key()
1103 gdev->can_sleep = gc->can_sleep; in gpiochip_add_data_with_key()
1105 rwlock_init(&gdev->line_state_lock); in gpiochip_add_data_with_key()
1106 RAW_INIT_NOTIFIER_HEAD(&gdev->line_state_notifier); in gpiochip_add_data_with_key()
1107 BLOCKING_INIT_NOTIFIER_HEAD(&gdev->device_notifier); in gpiochip_add_data_with_key()
1109 ret = init_srcu_struct(&gdev->srcu); in gpiochip_add_data_with_key()
1113 ret = init_srcu_struct(&gdev->desc_srcu); in gpiochip_add_data_with_key()
1142 dev_warn(&gdev->dev, in gpiochip_add_data_with_key()
1146 gdev->base = base; in gpiochip_add_data_with_key()
1148 ret = gpiodev_add_to_list_unlocked(gdev); in gpiochip_add_data_with_key()
1156 INIT_LIST_HEAD(&gdev->pin_ranges); in gpiochip_add_data_with_key()
1171 struct gpio_desc *desc = &gdev->descs[desc_index]; in gpiochip_add_data_with_key()
1173 desc->gdev = gdev; in gpiochip_add_data_with_key()
1214 ret = gpio_device_setup_shared(gdev); in gpiochip_add_data_with_key()
1227 ret = gpiochip_setup_dev(gdev); in gpiochip_add_data_with_key()
1235 gpio_device_teardown_shared(gdev); in gpiochip_add_data_with_key()
1250 list_del_rcu(&gdev->list); in gpiochip_add_data_with_key()
1252 if (gdev->dev.release) { in gpiochip_add_data_with_key()
1254 gpio_device_put(gdev); in gpiochip_add_data_with_key()
1258 cleanup_srcu_struct(&gdev->desc_srcu); in gpiochip_add_data_with_key()
1260 cleanup_srcu_struct(&gdev->srcu); in gpiochip_add_data_with_key()
1262 kfree_const(gdev->label); in gpiochip_add_data_with_key()
1264 kfree(gdev->descs); in gpiochip_add_data_with_key()
1266 kfree(dev_name(&gdev->dev)); in gpiochip_add_data_with_key()
1268 ida_free(&gpio_ida, gdev->id); in gpiochip_add_data_with_key()
1270 kfree(gdev); in gpiochip_add_data_with_key()
1290 struct gpio_device *gdev = gc->gpiodev; in gpiochip_remove() local
1293 gpiochip_sysfs_unregister(gdev); in gpiochip_remove()
1298 list_del_rcu(&gdev->list); in gpiochip_remove()
1302 rcu_assign_pointer(gdev->chip, NULL); in gpiochip_remove()
1303 synchronize_srcu(&gdev->srcu); in gpiochip_remove()
1304 gpio_device_teardown_shared(gdev); in gpiochip_remove()
1322 gcdev_unregister(gdev); in gpiochip_remove()
1323 gpio_device_put(gdev); in gpiochip_remove()
1352 struct gpio_device *gdev; in gpio_device_find() local
1359 list_for_each_entry_srcu(gdev, &gpio_devices, list, in gpio_device_find()
1361 if (!device_is_registered(&gdev->dev)) in gpio_device_find()
1364 guard(srcu)(&gdev->srcu); in gpio_device_find()
1366 gc = srcu_dereference(gdev->chip, &gdev->srcu); in gpio_device_find()
1369 return gpio_device_get(gdev); in gpio_device_find()
1423 struct gpio_device *gpio_device_get(struct gpio_device *gdev) in gpio_device_get() argument
1425 return to_gpio_device(get_device(&gdev->dev)); in gpio_device_get()
1434 void gpio_device_put(struct gpio_device *gdev) in gpio_device_put() argument
1436 put_device(&gdev->dev); in gpio_device_put()
1451 struct device *gpio_device_to_device(struct gpio_device *gdev) in gpio_device_to_device() argument
1453 return &gdev->dev; in gpio_device_to_device()
2333 struct gpio_device *gdev = gc->gpiodev; in gpiochip_add_pingroup_range() local
2344 pin_range->range.base = gdev->base + gpio_offset; in gpiochip_add_pingroup_range()
2361 list_add_tail(&pin_range->node, &gdev->pin_ranges); in gpiochip_add_pingroup_range()
2394 struct gpio_device *gdev = gc->gpiodev; in gpiochip_add_pin_range_with_pins() local
2405 pin_range->range.base = gdev->base + gpio_offset; in gpiochip_add_pin_range_with_pins()
2426 list_add_tail(&pin_range->node, &gdev->pin_ranges); in gpiochip_add_pin_range_with_pins()
2439 struct gpio_device *gdev = gc->gpiodev; in gpiochip_remove_pin_ranges() local
2441 list_for_each_entry_safe(pin_range, tmp, &gdev->pin_ranges, node) { in gpiochip_remove_pin_ranges()
2504 if (try_module_get(desc->gdev->owner)) { in gpiod_request()
2507 module_put(desc->gdev->owner); in gpiod_request()
2509 gpio_device_get(desc->gdev); in gpiod_request()
2559 module_put(desc->gdev->owner); in gpiod_free()
2560 gpio_device_put(desc->gdev); in gpiod_free()
2587 guard(srcu)(&desc->gdev->desc_srcu); in gpiochip_dup_line_label()
2720 struct device *dev = &desc->gdev->dev; in gpio_set_config_with_argument_optional()
3306 struct gpio_device *gdev; in gpiod_get_raw_value_commit() local
3311 gdev = desc->gdev; in gpiod_get_raw_value_commit()
3313 guard(srcu)(&gdev->srcu); in gpiod_get_raw_value_commit()
3315 gc = srcu_dereference(gdev->chip, &gdev->srcu); in gpiod_get_raw_value_commit()
3354 static bool gpio_device_chip_cmp(struct gpio_device *gdev, struct gpio_chip *gc) in gpio_device_chip_cmp() argument
3356 guard(srcu)(&gdev->srcu); in gpio_device_chip_cmp()
3358 return gc == srcu_dereference(gdev->chip, &gdev->srcu); in gpio_device_chip_cmp()
3379 WARN_ON(array_info->gdev->can_sleep); in gpiod_get_array_value_complex()
3381 guard(srcu)(&array_info->gdev->srcu); in gpiod_get_array_value_complex()
3382 gc = srcu_dereference(array_info->gdev->chip, in gpiod_get_array_value_complex()
3383 &array_info->gdev->srcu); in gpiod_get_array_value_complex()
3448 gpio_device_chip_cmp(desc_array[i]->gdev, guard.gc)); in gpiod_get_array_value_complex()
3498 WARN_ON(desc->gdev->can_sleep); in gpiod_get_raw_value()
3520 WARN_ON(desc->gdev->can_sleep); in gpiod_get_value()
3718 WARN_ON(array_info->gdev->can_sleep); in gpiod_set_array_value_complex()
3726 guard(srcu)(&array_info->gdev->srcu); in gpiod_set_array_value_complex()
3727 gc = srcu_dereference(array_info->gdev->chip, in gpiod_set_array_value_complex()
3728 &array_info->gdev->srcu); in gpiod_set_array_value_complex()
3817 gpio_device_chip_cmp(desc_array[i]->gdev, guard.gc)); in gpiod_set_array_value_complex()
3851 WARN_ON(desc->gdev->can_sleep); in gpiod_set_raw_value()
3899 WARN_ON(desc->gdev->can_sleep); in gpiod_set_value()
3971 return desc->gdev->can_sleep; in gpiod_cansleep()
4026 struct gpio_device *gdev; in gpiod_to_irq() local
4035 gdev = desc->gdev; in gpiod_to_irq()
4037 guard(srcu)(&gdev->srcu); in gpiod_to_irq()
4038 gc = srcu_dereference(gdev->chip, &gdev->srcu); in gpiod_to_irq()
4441 guard(read_lock_irqsave)(&desc->gdev->line_state_lock); in gpiod_line_state_notify()
4443 raw_notifier_call_chain(&desc->gdev->line_state_notifier, action, desc); in gpiod_line_state_notify()
4489 struct gpio_device *gdev __free(gpio_device_put) = in gpiod_add_hogs()
4491 if (gdev) in gpiod_add_hogs()
4492 gpiochip_machine_hog(gpio_device_get_chip(gdev), hog); in gpiod_add_hogs()
4565 struct gpio_device *gdev __free(gpio_device_put) = in gpio_desc_table_match()
4567 if (!gdev) { in gpio_desc_table_match()
4580 gc = gpio_device_get_chip(gdev); in gpio_desc_table_match()
4590 desc = gpio_device_get_desc(gdev, p->chip_hwnum); in gpio_desc_table_match()
5032 struct gpio_device *gdev = desc->gdev; in gpiod_hog() local
5052 name, gdev->label, hwnum, ret); in gpiod_hog()
5096 struct gpio_device *gdev; in gpiod_get_array() local
5120 gdev = gpiod_to_gpio_device(desc); in gpiod_get_array()
5128 bitmap_size = BITS_TO_LONGS(gdev->ngpio > count ? in gpiod_get_array()
5129 gdev->ngpio : count); in gpiod_get_array()
5149 array_info->gdev = gdev; in gpiod_get_array()
5162 if (array_info->gdev != gdev) { in gpiod_get_array()
5200 array_info->gdev->label, array_info->size, in gpiod_get_array()
5326 static void gpiolib_dbg_show(struct seq_file *s, struct gpio_device *gdev) in gpiolib_dbg_show() argument
5335 guard(srcu)(&gdev->srcu); in gpiolib_dbg_show()
5337 gc = srcu_dereference(gdev->chip, &gdev->srcu); in gpiolib_dbg_show()
5344 guard(srcu)(&desc->gdev->desc_srcu); in gpiolib_dbg_show()
5374 struct gpio_device *gdev; in gpiolib_seq_start() local
5388 list_for_each_entry_srcu(gdev, &gpio_devices, list, in gpiolib_seq_start()
5391 return gdev; in gpiolib_seq_start()
5400 struct gpio_device *gdev = v, *next; in gpiolib_seq_next() local
5402 next = list_entry_rcu(gdev->list.next, struct gpio_device, list); in gpiolib_seq_next()
5403 gdev = &next->list == &gpio_devices ? NULL : next; in gpiolib_seq_next()
5407 return gdev; in gpiolib_seq_next()
5425 struct gpio_device *gdev = v; in gpiolib_seq_show() local
5432 guard(srcu)(&gdev->srcu); in gpiolib_seq_show()
5434 gc = srcu_dereference(gdev->chip, &gdev->srcu); in gpiolib_seq_show()
5436 seq_printf(s, "%s: (dangling chip)\n", dev_name(&gdev->dev)); in gpiolib_seq_show()
5440 seq_printf(s, "%s: %u GPIOs", dev_name(&gdev->dev), gdev->ngpio); in gpiolib_seq_show()
5455 gpiolib_dbg_show(s, gdev); in gpiolib_seq_show()