Lines Matching +full:lock +full:- +full:offset

1 // SPDX-License-Identifier: GPL-2.0-or-later
45 struct mutex lock; member
51 unsigned int offset; member
61 unsigned int offset, int value) in gpio_sim_apply_pull() argument
67 gc = &chip->gc; in gpio_sim_apply_pull()
68 desc = &gc->gpiodev->descs[offset]; in gpio_sim_apply_pull()
70 mutex_lock(&chip->lock); in gpio_sim_apply_pull()
72 if (test_bit(FLAG_REQUESTED, &desc->flags) && in gpio_sim_apply_pull()
73 !test_bit(FLAG_IS_OUT, &desc->flags)) { in gpio_sim_apply_pull()
74 if (value == !!test_bit(offset, chip->value_map)) in gpio_sim_apply_pull()
78 * This is fine - it just means, nobody is listening in gpio_sim_apply_pull()
83 irq = irq_find_mapping(chip->irq_sim, offset); in gpio_sim_apply_pull()
100 if (!test_bit(FLAG_REQUESTED, &desc->flags) || in gpio_sim_apply_pull()
101 !test_bit(FLAG_IS_OUT, &desc->flags)) in gpio_sim_apply_pull()
102 __assign_bit(offset, chip->value_map, value); in gpio_sim_apply_pull()
105 __assign_bit(offset, chip->pull_map, value); in gpio_sim_apply_pull()
106 mutex_unlock(&chip->lock); in gpio_sim_apply_pull()
110 static int gpio_sim_get(struct gpio_chip *gc, unsigned int offset) in gpio_sim_get() argument
115 mutex_lock(&chip->lock); in gpio_sim_get()
116 ret = !!test_bit(offset, chip->value_map); in gpio_sim_get()
117 mutex_unlock(&chip->lock); in gpio_sim_get()
122 static void gpio_sim_set(struct gpio_chip *gc, unsigned int offset, int value) in gpio_sim_set() argument
126 mutex_lock(&chip->lock); in gpio_sim_set()
127 __assign_bit(offset, chip->value_map, value); in gpio_sim_set()
128 mutex_unlock(&chip->lock); in gpio_sim_set()
136 mutex_lock(&chip->lock); in gpio_sim_get_multiple()
137 bitmap_replace(bits, bits, chip->value_map, mask, gc->ngpio); in gpio_sim_get_multiple()
138 mutex_unlock(&chip->lock); in gpio_sim_get_multiple()
148 mutex_lock(&chip->lock); in gpio_sim_set_multiple()
149 bitmap_replace(chip->value_map, chip->value_map, bits, mask, gc->ngpio); in gpio_sim_set_multiple()
150 mutex_unlock(&chip->lock); in gpio_sim_set_multiple()
154 unsigned int offset, int value) in gpio_sim_direction_output() argument
158 mutex_lock(&chip->lock); in gpio_sim_direction_output()
159 __clear_bit(offset, chip->direction_map); in gpio_sim_direction_output()
160 __assign_bit(offset, chip->value_map, value); in gpio_sim_direction_output()
161 mutex_unlock(&chip->lock); in gpio_sim_direction_output()
166 static int gpio_sim_direction_input(struct gpio_chip *gc, unsigned int offset) in gpio_sim_direction_input() argument
170 mutex_lock(&chip->lock); in gpio_sim_direction_input()
171 __set_bit(offset, chip->direction_map); in gpio_sim_direction_input()
172 mutex_unlock(&chip->lock); in gpio_sim_direction_input()
177 static int gpio_sim_get_direction(struct gpio_chip *gc, unsigned int offset) in gpio_sim_get_direction() argument
182 mutex_lock(&chip->lock); in gpio_sim_get_direction()
183 direction = !!test_bit(offset, chip->direction_map); in gpio_sim_get_direction()
184 mutex_unlock(&chip->lock); in gpio_sim_get_direction()
190 unsigned int offset, unsigned long config) in gpio_sim_set_config() argument
196 return gpio_sim_apply_pull(chip, offset, 1); in gpio_sim_set_config()
198 return gpio_sim_apply_pull(chip, offset, 0); in gpio_sim_set_config()
203 return -ENOTSUPP; in gpio_sim_set_config()
206 static int gpio_sim_to_irq(struct gpio_chip *gc, unsigned int offset) in gpio_sim_to_irq() argument
210 return irq_create_mapping(chip->irq_sim, offset); in gpio_sim_to_irq()
213 static void gpio_sim_free(struct gpio_chip *gc, unsigned int offset) in gpio_sim_free() argument
217 mutex_lock(&chip->lock); in gpio_sim_free()
218 __assign_bit(offset, chip->value_map, !!test_bit(offset, chip->pull_map)); in gpio_sim_free()
219 mutex_unlock(&chip->lock); in gpio_sim_free()
229 mutex_lock(&chip->lock); in gpio_sim_sysfs_val_show()
230 val = !!test_bit(line_attr->offset, chip->value_map); in gpio_sim_sysfs_val_show()
231 mutex_unlock(&chip->lock); in gpio_sim_sysfs_val_show()
241 * Not assigning this function will result in write() returning -EIO in gpio_sim_sysfs_val_store()
242 * which is confusing. Return -EPERM explicitly. in gpio_sim_sysfs_val_store()
244 return -EPERM; in gpio_sim_sysfs_val_store()
248 [0] = "pull-down",
249 [1] = "pull-up",
260 mutex_lock(&chip->lock); in gpio_sim_sysfs_pull_show()
261 pull = !!test_bit(line_attr->offset, chip->pull_map); in gpio_sim_sysfs_pull_show()
262 mutex_unlock(&chip->lock); in gpio_sim_sysfs_pull_show()
279 ret = gpio_sim_apply_pull(chip, line_attr->offset, pull); in gpio_sim_sysfs_pull_store()
288 struct mutex *lock = data; in gpio_sim_mutex_destroy() local
290 mutex_destroy(lock); in gpio_sim_mutex_destroy()
297 sysfs_remove_groups(&chip->gc.gpiodev->dev.kobj, chip->attr_groups); in gpio_sim_sysfs_remove()
304 unsigned int num_lines = chip->gc.ngpio; in gpio_sim_setup_sysfs()
305 struct device *dev = chip->gc.parent; in gpio_sim_setup_sysfs()
310 chip->attr_groups = devm_kcalloc(dev, sizeof(*chip->attr_groups), in gpio_sim_setup_sysfs()
312 if (!chip->attr_groups) in gpio_sim_setup_sysfs()
313 return -ENOMEM; in gpio_sim_setup_sysfs()
322 return -ENOMEM; in gpio_sim_setup_sysfs()
324 attr_group->name = devm_kasprintf(dev, GFP_KERNEL, in gpio_sim_setup_sysfs()
326 if (!attr_group->name) in gpio_sim_setup_sysfs()
327 return -ENOMEM; in gpio_sim_setup_sysfs()
329 val_attr->offset = pull_attr->offset = i; in gpio_sim_setup_sysfs()
331 val_dev_attr = &val_attr->dev_attr; in gpio_sim_setup_sysfs()
332 pull_dev_attr = &pull_attr->dev_attr; in gpio_sim_setup_sysfs()
334 sysfs_attr_init(&val_dev_attr->attr); in gpio_sim_setup_sysfs()
335 sysfs_attr_init(&pull_dev_attr->attr); in gpio_sim_setup_sysfs()
337 val_dev_attr->attr.name = "value"; in gpio_sim_setup_sysfs()
338 pull_dev_attr->attr.name = "pull"; in gpio_sim_setup_sysfs()
340 val_dev_attr->attr.mode = pull_dev_attr->attr.mode = 0644; in gpio_sim_setup_sysfs()
342 val_dev_attr->show = gpio_sim_sysfs_val_show; in gpio_sim_setup_sysfs()
343 val_dev_attr->store = gpio_sim_sysfs_val_store; in gpio_sim_setup_sysfs()
344 pull_dev_attr->show = gpio_sim_sysfs_pull_show; in gpio_sim_setup_sysfs()
345 pull_dev_attr->store = gpio_sim_sysfs_pull_store; in gpio_sim_setup_sysfs()
347 attrs[0] = &val_dev_attr->attr; in gpio_sim_setup_sysfs()
348 attrs[1] = &pull_dev_attr->attr; in gpio_sim_setup_sysfs()
350 attr_group->attrs = attrs; in gpio_sim_setup_sysfs()
351 chip->attr_groups[i] = attr_group; in gpio_sim_setup_sysfs()
354 ret = sysfs_create_groups(&chip->gc.gpiodev->dev.kobj, in gpio_sim_setup_sysfs()
355 chip->attr_groups); in gpio_sim_setup_sysfs()
374 ret = fwnode_property_read_string(swnode, "gpio-sim,label", &label); in gpio_sim_add_bank()
376 label = devm_kasprintf(dev, GFP_KERNEL, "%s-%s", in gpio_sim_add_bank()
379 return -ENOMEM; in gpio_sim_add_bank()
384 return -ENOMEM; in gpio_sim_add_bank()
386 chip->direction_map = devm_bitmap_alloc(dev, num_lines, GFP_KERNEL); in gpio_sim_add_bank()
387 if (!chip->direction_map) in gpio_sim_add_bank()
388 return -ENOMEM; in gpio_sim_add_bank()
391 bitmap_fill(chip->direction_map, num_lines); in gpio_sim_add_bank()
393 chip->value_map = devm_bitmap_zalloc(dev, num_lines, GFP_KERNEL); in gpio_sim_add_bank()
394 if (!chip->value_map) in gpio_sim_add_bank()
395 return -ENOMEM; in gpio_sim_add_bank()
397 chip->pull_map = devm_bitmap_zalloc(dev, num_lines, GFP_KERNEL); in gpio_sim_add_bank()
398 if (!chip->pull_map) in gpio_sim_add_bank()
399 return -ENOMEM; in gpio_sim_add_bank()
401 chip->irq_sim = devm_irq_domain_create_sim(dev, NULL, num_lines); in gpio_sim_add_bank()
402 if (IS_ERR(chip->irq_sim)) in gpio_sim_add_bank()
403 return PTR_ERR(chip->irq_sim); in gpio_sim_add_bank()
405 mutex_init(&chip->lock); in gpio_sim_add_bank()
407 &chip->lock); in gpio_sim_add_bank()
411 gc = &chip->gc; in gpio_sim_add_bank()
412 gc->base = -1; in gpio_sim_add_bank()
413 gc->ngpio = num_lines; in gpio_sim_add_bank()
414 gc->label = label; in gpio_sim_add_bank()
415 gc->owner = THIS_MODULE; in gpio_sim_add_bank()
416 gc->parent = dev; in gpio_sim_add_bank()
417 gc->fwnode = swnode; in gpio_sim_add_bank()
418 gc->get = gpio_sim_get; in gpio_sim_add_bank()
419 gc->set = gpio_sim_set; in gpio_sim_add_bank()
420 gc->get_multiple = gpio_sim_get_multiple; in gpio_sim_add_bank()
421 gc->set_multiple = gpio_sim_set_multiple; in gpio_sim_add_bank()
422 gc->direction_output = gpio_sim_direction_output; in gpio_sim_add_bank()
423 gc->direction_input = gpio_sim_direction_input; in gpio_sim_add_bank()
424 gc->get_direction = gpio_sim_get_direction; in gpio_sim_add_bank()
425 gc->set_config = gpio_sim_set_config; in gpio_sim_add_bank()
426 gc->to_irq = gpio_sim_to_irq; in gpio_sim_add_bank()
427 gc->free = gpio_sim_free; in gpio_sim_add_bank()
434 dev_set_drvdata(&gc->gpiodev->dev, chip); in gpio_sim_add_bank()
441 struct device *dev = &pdev->dev; in gpio_sim_probe()
457 { .compatible = "gpio-simulator" },
464 .name = "gpio-sim",
485 * attributes so we need another lock.
487 * We use this lock fo protecting all data structures owned by this
490 struct mutex lock; member
494 * and notify the user-space about any errors.
505 /* This is called with dev->lock already taken. */
515 snprintf(devname, sizeof(devname), "gpio-sim.%u", simdev->id); in gpio_sim_bus_notifier_call()
519 simdev->driver_bound = true; in gpio_sim_bus_notifier_call()
521 simdev->driver_bound = false; in gpio_sim_bus_notifier_call()
525 complete(&simdev->probe_completion); in gpio_sim_bus_notifier_call()
575 return bank->label && *bank->label; in gpio_sim_bank_has_label()
581 return bank->parent; in gpio_sim_bank_get_device()
592 unsigned int offset; member
609 struct gpio_sim_bank *bank = line->parent; in gpio_sim_line_get_device()
629 struct gpio_sim_line *line = hog->parent; in gpio_sim_hog_get_device()
636 return !!dev->pdev; in gpio_sim_device_is_live_unlocked()
660 mutex_lock(&dev->lock); in gpio_sim_device_config_dev_name_show()
661 pdev = dev->pdev; in gpio_sim_device_config_dev_name_show()
663 ret = sprintf(page, "%s\n", dev_name(&pdev->dev)); in gpio_sim_device_config_dev_name_show()
665 ret = sprintf(page, "gpio-sim.%d\n", dev->id); in gpio_sim_device_config_dev_name_show()
666 mutex_unlock(&dev->lock); in gpio_sim_device_config_dev_name_show()
679 mutex_lock(&dev->lock); in gpio_sim_device_config_live_show()
681 mutex_unlock(&dev->lock); in gpio_sim_device_config_live_show()
694 list_for_each_entry(line, &bank->line_list, siblings) { in gpio_sim_make_line_names()
695 if (line->name) { in gpio_sim_make_line_names()
696 if (line->offset > max_offset) in gpio_sim_make_line_names()
697 max_offset = line->offset; in gpio_sim_make_line_names()
709 * This is not an error - NULL means, there are no line in gpio_sim_make_line_names()
718 return ERR_PTR(-ENOMEM); in gpio_sim_make_line_names()
720 list_for_each_entry(line, &bank->line_list, siblings) in gpio_sim_make_line_names()
721 line_names[line->offset] = line->name; in gpio_sim_make_line_names()
730 if (!dev->hogs) in gpio_sim_remove_hogs()
733 gpiod_remove_hogs(dev->hogs); in gpio_sim_remove_hogs()
735 for (hog = dev->hogs; !hog->chip_label; hog++) { in gpio_sim_remove_hogs()
736 kfree(hog->chip_label); in gpio_sim_remove_hogs()
737 kfree(hog->line_name); in gpio_sim_remove_hogs()
740 kfree(dev->hogs); in gpio_sim_remove_hogs()
741 dev->hogs = NULL; in gpio_sim_remove_hogs()
751 list_for_each_entry(bank, &dev->bank_list, siblings) { in gpio_sim_add_hogs()
752 list_for_each_entry(line, &bank->line_list, siblings) { in gpio_sim_add_hogs()
753 if (line->hog) in gpio_sim_add_hogs()
762 dev->hogs = kcalloc(num_hogs + 1, sizeof(*dev->hogs), GFP_KERNEL); in gpio_sim_add_hogs()
763 if (!dev->hogs) in gpio_sim_add_hogs()
764 return -ENOMEM; in gpio_sim_add_hogs()
766 list_for_each_entry(bank, &dev->bank_list, siblings) { in gpio_sim_add_hogs()
767 list_for_each_entry(line, &bank->line_list, siblings) { in gpio_sim_add_hogs()
768 if (!line->hog) in gpio_sim_add_hogs()
771 hog = &dev->hogs[idx++]; in gpio_sim_add_hogs()
779 hog->chip_label = kstrdup(bank->label, in gpio_sim_add_hogs()
782 hog->chip_label = kasprintf(GFP_KERNEL, in gpio_sim_add_hogs()
783 "gpio-sim.%u-%s", in gpio_sim_add_hogs()
784 dev->id, in gpio_sim_add_hogs()
786 bank->swnode)); in gpio_sim_add_hogs()
787 if (!hog->chip_label) { in gpio_sim_add_hogs()
789 return -ENOMEM; in gpio_sim_add_hogs()
798 if (line->hog->name) { in gpio_sim_add_hogs()
799 hog->line_name = kstrdup(line->hog->name, in gpio_sim_add_hogs()
801 if (!hog->line_name) { in gpio_sim_add_hogs()
803 return -ENOMEM; in gpio_sim_add_hogs()
807 hog->chip_hwnum = line->offset; in gpio_sim_add_hogs()
808 hog->dflags = line->hog->dir; in gpio_sim_add_hogs()
812 gpiod_add_hogs(dev->hogs); in gpio_sim_add_hogs()
828 properties[prop_idx++] = PROPERTY_ENTRY_U32("ngpios", bank->num_lines); in gpio_sim_make_bank_swnode()
831 properties[prop_idx++] = PROPERTY_ENTRY_STRING("gpio-sim,label", in gpio_sim_make_bank_swnode()
832 bank->label); in gpio_sim_make_bank_swnode()
840 "gpio-line-names", in gpio_sim_make_bank_swnode()
862 list_for_each_entry(this, &dev->bank_list, siblings) { in gpio_sim_bank_labels_non_unique()
863 list_for_each_entry(pos, &dev->bank_list, siblings) { in gpio_sim_bank_labels_non_unique()
864 if (this == pos || (!this->label || !pos->label)) in gpio_sim_bank_labels_non_unique()
867 if (strcmp(this->label, pos->label) == 0) in gpio_sim_bank_labels_non_unique()
883 if (list_empty(&dev->bank_list)) in gpio_sim_device_activate_unlocked()
884 return -ENODATA; in gpio_sim_device_activate_unlocked()
887 * Non-unique GPIO device labels are a corner-case we don't support in gpio_sim_device_activate_unlocked()
892 return -EINVAL; in gpio_sim_device_activate_unlocked()
900 list_for_each_entry(bank, &dev->bank_list, siblings) { in gpio_sim_device_activate_unlocked()
901 bank->swnode = gpio_sim_make_bank_swnode(bank, swnode); in gpio_sim_device_activate_unlocked()
902 if (IS_ERR(bank->swnode)) { in gpio_sim_device_activate_unlocked()
903 ret = PTR_ERR(bank->swnode); in gpio_sim_device_activate_unlocked()
915 pdevinfo.name = "gpio-sim"; in gpio_sim_device_activate_unlocked()
917 pdevinfo.id = dev->id; in gpio_sim_device_activate_unlocked()
919 reinit_completion(&dev->probe_completion); in gpio_sim_device_activate_unlocked()
920 dev->driver_bound = false; in gpio_sim_device_activate_unlocked()
921 bus_register_notifier(&platform_bus_type, &dev->bus_notifier); in gpio_sim_device_activate_unlocked()
925 bus_unregister_notifier(&platform_bus_type, &dev->bus_notifier); in gpio_sim_device_activate_unlocked()
931 wait_for_completion(&dev->probe_completion); in gpio_sim_device_activate_unlocked()
932 bus_unregister_notifier(&platform_bus_type, &dev->bus_notifier); in gpio_sim_device_activate_unlocked()
934 if (!dev->driver_bound) { in gpio_sim_device_activate_unlocked()
939 return -ENXIO; in gpio_sim_device_activate_unlocked()
942 dev->pdev = pdev; in gpio_sim_device_activate_unlocked()
951 swnode = dev_fwnode(&dev->pdev->dev); in gpio_sim_device_deactivate_unlocked()
952 platform_device_unregister(dev->pdev); in gpio_sim_device_deactivate_unlocked()
954 dev->pdev = NULL; in gpio_sim_device_deactivate_unlocked()
970 mutex_lock(&dev->lock); in gpio_sim_device_config_live_store()
974 ret = -EPERM; in gpio_sim_device_config_live_store()
980 mutex_unlock(&dev->lock); in gpio_sim_device_config_live_store()
1003 if (dev->class) in gpio_sim_emit_chip_name()
1006 if (device_match_fwnode(dev, ctx->swnode)) in gpio_sim_emit_chip_name()
1007 return sprintf(ctx->page, "%s\n", dev_name(dev)); in gpio_sim_emit_chip_name()
1017 struct gpio_sim_chip_name_ctx ctx = { bank->swnode, page }; in gpio_sim_bank_config_chip_name_show()
1020 mutex_lock(&dev->lock); in gpio_sim_bank_config_chip_name_show()
1022 ret = device_for_each_child(&dev->pdev->dev, &ctx, in gpio_sim_bank_config_chip_name_show()
1026 mutex_unlock(&dev->lock); in gpio_sim_bank_config_chip_name_show()
1040 mutex_lock(&dev->lock); in gpio_sim_bank_config_label_show()
1041 ret = sprintf(page, "%s\n", bank->label ?: ""); in gpio_sim_bank_config_label_show()
1042 mutex_unlock(&dev->lock); in gpio_sim_bank_config_label_show()
1054 mutex_lock(&dev->lock); in gpio_sim_bank_config_label_store()
1057 mutex_unlock(&dev->lock); in gpio_sim_bank_config_label_store()
1058 return -EBUSY; in gpio_sim_bank_config_label_store()
1063 mutex_unlock(&dev->lock); in gpio_sim_bank_config_label_store()
1064 return -ENOMEM; in gpio_sim_bank_config_label_store()
1067 kfree(bank->label); in gpio_sim_bank_config_label_store()
1068 bank->label = trimmed; in gpio_sim_bank_config_label_store()
1070 mutex_unlock(&dev->lock); in gpio_sim_bank_config_label_store()
1083 mutex_lock(&dev->lock); in gpio_sim_bank_config_num_lines_show()
1084 ret = sprintf(page, "%u\n", bank->num_lines); in gpio_sim_bank_config_num_lines_show()
1085 mutex_unlock(&dev->lock); in gpio_sim_bank_config_num_lines_show()
1104 return -EINVAL; in gpio_sim_bank_config_num_lines_store()
1106 mutex_lock(&dev->lock); in gpio_sim_bank_config_num_lines_store()
1109 mutex_unlock(&dev->lock); in gpio_sim_bank_config_num_lines_store()
1110 return -EBUSY; in gpio_sim_bank_config_num_lines_store()
1113 bank->num_lines = num_lines; in gpio_sim_bank_config_num_lines_store()
1115 mutex_unlock(&dev->lock); in gpio_sim_bank_config_num_lines_store()
1135 mutex_lock(&dev->lock); in gpio_sim_line_config_name_show()
1136 ret = sprintf(page, "%s\n", line->name ?: ""); in gpio_sim_line_config_name_show()
1137 mutex_unlock(&dev->lock); in gpio_sim_line_config_name_show()
1149 mutex_lock(&dev->lock); in gpio_sim_line_config_name_store()
1152 mutex_unlock(&dev->lock); in gpio_sim_line_config_name_store()
1153 return -EBUSY; in gpio_sim_line_config_name_store()
1158 mutex_unlock(&dev->lock); in gpio_sim_line_config_name_store()
1159 return -ENOMEM; in gpio_sim_line_config_name_store()
1162 kfree(line->name); in gpio_sim_line_config_name_store()
1163 line->name = trimmed; in gpio_sim_line_config_name_store()
1165 mutex_unlock(&dev->lock); in gpio_sim_line_config_name_store()
1184 mutex_lock(&dev->lock); in gpio_sim_hog_config_name_show()
1185 ret = sprintf(page, "%s\n", hog->name ?: ""); in gpio_sim_hog_config_name_show()
1186 mutex_unlock(&dev->lock); in gpio_sim_hog_config_name_show()
1198 mutex_lock(&dev->lock); in gpio_sim_hog_config_name_store()
1201 mutex_unlock(&dev->lock); in gpio_sim_hog_config_name_store()
1202 return -EBUSY; in gpio_sim_hog_config_name_store()
1207 mutex_unlock(&dev->lock); in gpio_sim_hog_config_name_store()
1208 return -ENOMEM; in gpio_sim_hog_config_name_store()
1211 kfree(hog->name); in gpio_sim_hog_config_name_store()
1212 hog->name = trimmed; in gpio_sim_hog_config_name_store()
1214 mutex_unlock(&dev->lock); in gpio_sim_hog_config_name_store()
1229 mutex_lock(&dev->lock); in gpio_sim_hog_config_direction_show()
1230 dir = hog->dir; in gpio_sim_hog_config_direction_show()
1231 mutex_unlock(&dev->lock); in gpio_sim_hog_config_direction_show()
1238 repr = "output-high"; in gpio_sim_hog_config_direction_show()
1241 repr = "output-low"; in gpio_sim_hog_config_direction_show()
1246 return -EINVAL; in gpio_sim_hog_config_direction_show()
1261 mutex_lock(&dev->lock); in gpio_sim_hog_config_direction_store()
1264 mutex_unlock(&dev->lock); in gpio_sim_hog_config_direction_store()
1265 return -EBUSY; in gpio_sim_hog_config_direction_store()
1270 mutex_unlock(&dev->lock); in gpio_sim_hog_config_direction_store()
1271 return -ENOMEM; in gpio_sim_hog_config_direction_store()
1276 else if (strcmp(trimmed, "output-high") == 0) in gpio_sim_hog_config_direction_store()
1278 else if (strcmp(trimmed, "output-low") == 0) in gpio_sim_hog_config_direction_store()
1281 dir = -EINVAL; in gpio_sim_hog_config_direction_store()
1286 mutex_unlock(&dev->lock); in gpio_sim_hog_config_direction_store()
1290 hog->dir = dir; in gpio_sim_hog_config_direction_store()
1292 mutex_unlock(&dev->lock); in gpio_sim_hog_config_direction_store()
1308 struct gpio_sim_line *line = hog->parent; in gpio_sim_hog_config_item_release()
1311 mutex_lock(&dev->lock); in gpio_sim_hog_config_item_release()
1312 line->hog = NULL; in gpio_sim_hog_config_item_release()
1313 mutex_unlock(&dev->lock); in gpio_sim_hog_config_item_release()
1315 kfree(hog->name); in gpio_sim_hog_config_item_release()
1332 struct gpio_sim_line *line = to_gpio_sim_line(&group->cg_item); in gpio_sim_line_config_make_hog_item()
1337 return ERR_PTR(-EINVAL); in gpio_sim_line_config_make_hog_item()
1339 mutex_lock(&dev->lock); in gpio_sim_line_config_make_hog_item()
1343 mutex_unlock(&dev->lock); in gpio_sim_line_config_make_hog_item()
1344 return ERR_PTR(-ENOMEM); in gpio_sim_line_config_make_hog_item()
1347 config_item_init_type_name(&hog->item, name, in gpio_sim_line_config_make_hog_item()
1350 hog->dir = GPIOD_IN; in gpio_sim_line_config_make_hog_item()
1351 hog->name = NULL; in gpio_sim_line_config_make_hog_item()
1352 hog->parent = line; in gpio_sim_line_config_make_hog_item()
1353 line->hog = hog; in gpio_sim_line_config_make_hog_item()
1355 mutex_unlock(&dev->lock); in gpio_sim_line_config_make_hog_item()
1357 return &hog->item; in gpio_sim_line_config_make_hog_item()
1365 mutex_lock(&dev->lock); in gpio_sim_line_config_group_release()
1366 list_del(&line->siblings); in gpio_sim_line_config_group_release()
1367 mutex_unlock(&dev->lock); in gpio_sim_line_config_group_release()
1369 kfree(line->name); in gpio_sim_line_config_group_release()
1392 struct gpio_sim_bank *bank = to_gpio_sim_bank(&group->cg_item); in gpio_sim_bank_config_make_line_group()
1395 unsigned int offset; in gpio_sim_bank_config_make_line_group() local
1398 ret = sscanf(name, "line%u%n", &offset, &nchar); in gpio_sim_bank_config_make_line_group()
1400 return ERR_PTR(-EINVAL); in gpio_sim_bank_config_make_line_group()
1402 mutex_lock(&dev->lock); in gpio_sim_bank_config_make_line_group()
1405 mutex_unlock(&dev->lock); in gpio_sim_bank_config_make_line_group()
1406 return ERR_PTR(-EBUSY); in gpio_sim_bank_config_make_line_group()
1411 mutex_unlock(&dev->lock); in gpio_sim_bank_config_make_line_group()
1412 return ERR_PTR(-ENOMEM); in gpio_sim_bank_config_make_line_group()
1415 config_group_init_type_name(&line->group, name, in gpio_sim_bank_config_make_line_group()
1418 line->parent = bank; in gpio_sim_bank_config_make_line_group()
1419 line->offset = offset; in gpio_sim_bank_config_make_line_group()
1420 list_add_tail(&line->siblings, &bank->line_list); in gpio_sim_bank_config_make_line_group()
1422 mutex_unlock(&dev->lock); in gpio_sim_bank_config_make_line_group()
1424 return &line->group; in gpio_sim_bank_config_make_line_group()
1432 mutex_lock(&dev->lock); in gpio_sim_bank_config_group_release()
1433 list_del(&bank->siblings); in gpio_sim_bank_config_group_release()
1434 mutex_unlock(&dev->lock); in gpio_sim_bank_config_group_release()
1436 kfree(bank->label); in gpio_sim_bank_config_group_release()
1459 struct gpio_sim_device *dev = to_gpio_sim_device(&group->cg_item); in gpio_sim_device_config_make_bank_group()
1462 mutex_lock(&dev->lock); in gpio_sim_device_config_make_bank_group()
1465 mutex_unlock(&dev->lock); in gpio_sim_device_config_make_bank_group()
1466 return ERR_PTR(-EBUSY); in gpio_sim_device_config_make_bank_group()
1471 mutex_unlock(&dev->lock); in gpio_sim_device_config_make_bank_group()
1472 return ERR_PTR(-ENOMEM); in gpio_sim_device_config_make_bank_group()
1475 config_group_init_type_name(&bank->group, name, in gpio_sim_device_config_make_bank_group()
1477 bank->num_lines = 1; in gpio_sim_device_config_make_bank_group()
1478 bank->parent = dev; in gpio_sim_device_config_make_bank_group()
1479 INIT_LIST_HEAD(&bank->line_list); in gpio_sim_device_config_make_bank_group()
1480 list_add_tail(&bank->siblings, &dev->bank_list); in gpio_sim_device_config_make_bank_group()
1482 mutex_unlock(&dev->lock); in gpio_sim_device_config_make_bank_group()
1484 return &bank->group; in gpio_sim_device_config_make_bank_group()
1491 mutex_lock(&dev->lock); in gpio_sim_device_config_group_release()
1494 mutex_unlock(&dev->lock); in gpio_sim_device_config_group_release()
1496 mutex_destroy(&dev->lock); in gpio_sim_device_config_group_release()
1497 ida_free(&gpio_sim_ida, dev->id); in gpio_sim_device_config_group_release()
1524 return ERR_PTR(-ENOMEM); in gpio_sim_config_make_device_group()
1532 config_group_init_type_name(&dev->group, name, in gpio_sim_config_make_device_group()
1534 dev->id = id; in gpio_sim_config_make_device_group()
1535 mutex_init(&dev->lock); in gpio_sim_config_make_device_group()
1536 INIT_LIST_HEAD(&dev->bank_list); in gpio_sim_config_make_device_group()
1538 dev->bus_notifier.notifier_call = gpio_sim_bus_notifier_call; in gpio_sim_config_make_device_group()
1539 init_completion(&dev->probe_completion); in gpio_sim_config_make_device_group()
1541 return &dev->group; in gpio_sim_config_make_device_group()
1556 .ci_namebuf = "gpio-sim",