Lines Matching +full:signal +full:- +full:id
1 // SPDX-License-Identifier: GPL-2.0
32 [COUNTER_COUNT_MODE_NON_RECYCLE] = "non-recycle",
33 [COUNTER_COUNT_MODE_MODULO_N] = "modulo-n"
38 struct counter_signal *signal, void *priv, in counter_signal_enum_read() argument
45 if (!e->get) in counter_signal_enum_read()
46 return -EINVAL; in counter_signal_enum_read()
48 err = e->get(counter, signal, &index); in counter_signal_enum_read()
52 if (index >= e->num_items) in counter_signal_enum_read()
53 return -EINVAL; in counter_signal_enum_read()
55 return sprintf(buf, "%s\n", e->items[index]); in counter_signal_enum_read()
60 struct counter_signal *signal, void *priv, in counter_signal_enum_write() argument
67 if (!e->set) in counter_signal_enum_write()
68 return -EINVAL; in counter_signal_enum_write()
70 index = __sysfs_match_string(e->items, e->num_items, buf); in counter_signal_enum_write()
74 err = e->set(counter, signal, index); in counter_signal_enum_write()
83 struct counter_signal *signal, in counter_signal_enum_available_read() argument
90 if (!e->num_items) in counter_signal_enum_available_read()
93 for (i = 0; i < e->num_items; i++) in counter_signal_enum_available_read()
94 len += sprintf(buf + len, "%s\n", e->items[i]); in counter_signal_enum_available_read()
108 if (!e->get) in counter_count_enum_read()
109 return -EINVAL; in counter_count_enum_read()
111 err = e->get(counter, count, &index); in counter_count_enum_read()
115 if (index >= e->num_items) in counter_count_enum_read()
116 return -EINVAL; in counter_count_enum_read()
118 return sprintf(buf, "%s\n", e->items[index]); in counter_count_enum_read()
130 if (!e->set) in counter_count_enum_write()
131 return -EINVAL; in counter_count_enum_write()
133 index = __sysfs_match_string(e->items, e->num_items, buf); in counter_count_enum_write()
137 err = e->set(counter, count, index); in counter_count_enum_write()
153 if (!e->num_items) in counter_count_enum_available_read()
156 for (i = 0; i < e->num_items; i++) in counter_count_enum_available_read()
157 len += sprintf(buf + len, "%s\n", e->items[i]); in counter_count_enum_available_read()
170 if (!e->get) in counter_device_enum_read()
171 return -EINVAL; in counter_device_enum_read()
173 err = e->get(counter, &index); in counter_device_enum_read()
177 if (index >= e->num_items) in counter_device_enum_read()
178 return -EINVAL; in counter_device_enum_read()
180 return sprintf(buf, "%s\n", e->items[index]); in counter_device_enum_read()
191 if (!e->set) in counter_device_enum_write()
192 return -EINVAL; in counter_device_enum_write()
194 index = __sysfs_match_string(e->items, e->num_items, buf); in counter_device_enum_write()
198 err = e->set(counter, index); in counter_device_enum_write()
213 if (!e->num_items) in counter_device_enum_available_read()
216 for (i = 0; i < e->num_items; i++) in counter_device_enum_available_read()
217 len += sprintf(buf + len, "%s\n", e->items[i]); in counter_device_enum_available_read()
245 struct list_head *const attr_list = &parm->group->attr_list; in counter_attribute_create()
250 return -ENOMEM; in counter_attribute_create()
251 dev_attr = &counter_attr->dev_attr; in counter_attribute_create()
253 sysfs_attr_init(&dev_attr->attr); in counter_attribute_create()
256 dev_attr->attr.name = kasprintf(GFP_KERNEL, "%s%s", parm->prefix, in counter_attribute_create()
257 parm->name); in counter_attribute_create()
258 if (!dev_attr->attr.name) { in counter_attribute_create()
259 err = -ENOMEM; in counter_attribute_create()
262 if (parm->show) { in counter_attribute_create()
263 dev_attr->attr.mode |= 0444; in counter_attribute_create()
264 dev_attr->show = parm->show; in counter_attribute_create()
266 if (parm->store) { in counter_attribute_create()
267 dev_attr->attr.mode |= 0200; in counter_attribute_create()
268 dev_attr->store = parm->store; in counter_attribute_create()
272 counter_attr->component = parm->component; in counter_attribute_create()
275 list_add(&counter_attr->l, attr_list); in counter_attribute_create()
276 parm->group->num_attr++; in counter_attribute_create()
289 struct counter_signal *signal; member
302 const struct counter_signal_unit *const component = devattr->component; in counter_signal_show()
303 struct counter_signal *const signal = component->signal; in counter_signal_show() local
307 err = counter->ops->signal_read(counter, signal, &val); in counter_signal_show()
322 const struct counter_name_unit *const comp = to_counter_attr(attr)->component; in counter_device_attr_name_show()
324 return sprintf(buf, "%s\n", comp->name); in counter_device_attr_name_show()
342 return -ENOMEM; in counter_name_attribute_create()
343 name_comp->name = name; in counter_name_attribute_create()
345 /* Allocate Signal name attribute */ in counter_name_attribute_create()
364 struct counter_signal *signal; member
372 const struct counter_signal_ext_unit *const comp = devattr->component; in counter_signal_ext_show()
373 const struct counter_signal_ext *const ext = comp->ext; in counter_signal_ext_show()
375 return ext->read(dev_get_drvdata(dev), comp->signal, ext->priv, buf); in counter_signal_ext_show()
383 const struct counter_signal_ext_unit *const comp = devattr->component; in counter_signal_ext_store()
384 const struct counter_signal_ext *const ext = comp->ext; in counter_signal_ext_store()
386 return ext->write(dev_get_drvdata(dev), comp->signal, ext->priv, buf, in counter_signal_ext_store()
396 kfree(p->dev_attr.attr.name); in counter_device_attr_list_free()
397 kfree(p->component); in counter_device_attr_list_free()
398 list_del(&p->l); in counter_device_attr_list_free()
405 struct counter_signal *const signal) in counter_signal_ext_register() argument
407 const size_t num_ext = signal->num_ext; in counter_signal_ext_register()
416 ext = signal->ext + i; in counter_signal_ext_register()
421 err = -ENOMEM; in counter_signal_ext_register()
424 signal_ext_comp->signal = signal; in counter_signal_ext_register()
425 signal_ext_comp->ext = ext; in counter_signal_ext_register()
430 parm.name = ext->name; in counter_signal_ext_register()
431 parm.show = (ext->read) ? counter_signal_ext_show : NULL; in counter_signal_ext_register()
432 parm.store = (ext->write) ? counter_signal_ext_store : NULL; in counter_signal_ext_register()
444 counter_device_attr_list_free(&group->attr_list); in counter_signal_ext_register()
451 struct counter_signal *const signal) in counter_signal_attributes_create() argument
457 /* Allocate Signal attribute component */ in counter_signal_attributes_create()
460 return -ENOMEM; in counter_signal_attributes_create()
461 signal_comp->signal = signal; in counter_signal_attributes_create()
463 /* Create main Signal attribute */ in counter_signal_attributes_create()
466 parm.name = "signal"; in counter_signal_attributes_create()
467 parm.show = (counter->ops->signal_read) ? counter_signal_show : NULL; in counter_signal_attributes_create()
476 /* Create Signal name attribute */ in counter_signal_attributes_create()
477 err = counter_name_attribute_create(group, signal->name); in counter_signal_attributes_create()
481 /* Register Signal extension attributes */ in counter_signal_attributes_create()
482 err = counter_signal_ext_register(group, signal); in counter_signal_attributes_create()
489 counter_device_attr_list_free(&group->attr_list); in counter_signal_attributes_create()
497 const size_t num_signals = counter->num_signals; in counter_signals_register()
499 struct counter_signal *signal; in counter_signals_register() local
503 /* Register each Signal */ in counter_signals_register()
505 signal = counter->signals + i; in counter_signals_register()
507 /* Generate Signal attribute directory name */ in counter_signals_register()
508 name = kasprintf(GFP_KERNEL, "signal%d", signal->id); in counter_signals_register()
510 err = -ENOMEM; in counter_signals_register()
515 /* Create all attributes associated with Signal */ in counter_signals_register()
517 signal); in counter_signals_register()
528 } while (i--); in counter_signals_register()
550 const struct counter_action_unit *const component = devattr->component; in counter_action_show()
551 struct counter_count *const count = component->count; in counter_action_show()
552 struct counter_synapse *const synapse = component->synapse; in counter_action_show()
556 err = counter->ops->action_get(counter, count, synapse, &action_index); in counter_action_show()
560 synapse->action = action_index; in counter_action_show()
562 action = synapse->actions_list[action_index]; in counter_action_show()
571 const struct counter_action_unit *const component = devattr->component; in counter_action_store()
572 struct counter_synapse *const synapse = component->synapse; in counter_action_store()
574 const size_t num_actions = synapse->num_actions; in counter_action_store()
578 struct counter_count *const count = component->count; in counter_action_store()
582 action = synapse->actions_list[action_index]; in counter_action_store()
588 return -EINVAL; in counter_action_store()
590 err = counter->ops->action_set(counter, count, synapse, action_index); in counter_action_store()
594 synapse->action = action_index; in counter_action_store()
608 const struct counter_action_avail_unit *const component = devattr->component; in counter_synapse_action_available_show()
613 for (i = 0; i < component->num_actions; i++) { in counter_synapse_action_available_show()
614 action = component->actions_list[i]; in counter_synapse_action_available_show()
636 for (i = 0; i < count->num_synapses; i++) { in counter_synapses_register()
637 synapse = count->synapses + i; in counter_synapses_register()
640 prefix = kasprintf(GFP_KERNEL, "signal%d_", in counter_synapses_register()
641 synapse->signal->id); in counter_synapses_register()
643 err = -ENOMEM; in counter_synapses_register()
650 err = -ENOMEM; in counter_synapses_register()
653 action_comp->synapse = synapse; in counter_synapses_register()
654 action_comp->count = count; in counter_synapses_register()
660 parm.show = (counter->ops->action_get) ? counter_action_show : NULL; in counter_synapses_register()
661 parm.store = (counter->ops->action_set) ? counter_action_store : NULL; in counter_synapses_register()
672 err = -ENOMEM; in counter_synapses_register()
675 avail_comp->actions_list = synapse->actions_list; in counter_synapses_register()
676 avail_comp->num_actions = synapse->num_actions; in counter_synapses_register()
699 counter_device_attr_list_free(&group->attr_list); in counter_synapses_register()
713 const struct counter_count_unit *const component = devattr->component; in counter_count_show()
714 struct counter_count *const count = component->count; in counter_count_show()
718 err = counter->ops->count_read(counter, count, &val); in counter_count_show()
731 const struct counter_count_unit *const component = devattr->component; in counter_count_store()
732 struct counter_count *const count = component->count; in counter_count_store()
740 err = counter->ops->count_write(counter, count, val); in counter_count_store()
750 [COUNTER_COUNT_FUNCTION_PULSE_DIRECTION] = "pulse-direction",
764 const struct counter_count_unit *const component = devattr->component; in counter_function_show()
765 struct counter_count *const count = component->count; in counter_function_show()
769 err = counter->ops->function_get(counter, count, &func_index); in counter_function_show()
773 count->function = func_index; in counter_function_show()
775 function = count->functions_list[func_index]; in counter_function_show()
784 const struct counter_count_unit *const component = devattr->component; in counter_function_store()
785 struct counter_count *const count = component->count; in counter_function_store()
786 const size_t num_functions = count->num_functions; in counter_function_store()
794 function = count->functions_list[func_index]; in counter_function_store()
800 return -EINVAL; in counter_function_store()
802 err = counter->ops->function_set(counter, count, func_index); in counter_function_store()
806 count->function = func_index; in counter_function_store()
820 const struct counter_count_ext_unit *const comp = devattr->component; in counter_count_ext_show()
821 const struct counter_count_ext *const ext = comp->ext; in counter_count_ext_show()
823 return ext->read(dev_get_drvdata(dev), comp->count, ext->priv, buf); in counter_count_ext_show()
831 const struct counter_count_ext_unit *const comp = devattr->component; in counter_count_ext_store()
832 const struct counter_count_ext *const ext = comp->ext; in counter_count_ext_store()
834 return ext->write(dev_get_drvdata(dev), comp->count, ext->priv, buf, in counter_count_ext_store()
849 for (i = 0 ; i < count->num_ext; i++) { in counter_count_ext_register()
850 ext = count->ext + i; in counter_count_ext_register()
855 err = -ENOMEM; in counter_count_ext_register()
858 count_ext_comp->count = count; in counter_count_ext_register()
859 count_ext_comp->ext = ext; in counter_count_ext_register()
864 parm.name = ext->name; in counter_count_ext_register()
865 parm.show = (ext->read) ? counter_count_ext_show : NULL; in counter_count_ext_register()
866 parm.store = (ext->write) ? counter_count_ext_store : NULL; in counter_count_ext_register()
878 counter_device_attr_list_free(&group->attr_list); in counter_count_ext_register()
891 const struct counter_func_avail_unit *const component = devattr->component; in counter_count_function_available_show()
892 const enum counter_count_function *const func_list = component->functions_list; in counter_count_function_available_show()
893 const size_t num_functions = component->num_functions; in counter_count_function_available_show()
921 return -ENOMEM; in counter_count_attributes_create()
922 count_comp->count = count; in counter_count_attributes_create()
928 parm.show = (counter->ops->count_read) ? counter_count_show : NULL; in counter_count_attributes_create()
929 parm.store = (counter->ops->count_write) ? counter_count_store : NULL; in counter_count_attributes_create()
940 err = -ENOMEM; in counter_count_attributes_create()
943 func_comp->count = count; in counter_count_attributes_create()
949 parm.show = (counter->ops->function_get) ? counter_function_show : NULL; in counter_count_attributes_create()
950 parm.store = (counter->ops->function_set) ? counter_function_store : NULL; in counter_count_attributes_create()
961 err = -ENOMEM; in counter_count_attributes_create()
964 avail_comp->functions_list = count->functions_list; in counter_count_attributes_create()
965 avail_comp->num_functions = count->num_functions; in counter_count_attributes_create()
981 err = counter_name_attribute_create(group, count->name); in counter_count_attributes_create()
993 counter_device_attr_list_free(&group->attr_list); in counter_count_attributes_create()
1007 for (i = 0; i < counter->num_counts; i++) { in counter_counts_register()
1008 count = counter->counts + i; in counter_counts_register()
1011 name = kasprintf(GFP_KERNEL, "count%d", count->id); in counter_counts_register()
1013 err = -ENOMEM; in counter_counts_register()
1037 } while (i--); in counter_counts_register()
1049 const struct counter_size_unit *const comp = to_counter_attr(attr)->component; in counter_device_attr_size_show()
1051 return sprintf(buf, "%zu\n", comp->size); in counter_device_attr_size_show()
1065 return -ENOMEM; in counter_size_attribute_create()
1066 size_comp->size = size; in counter_size_attribute_create()
1093 const struct counter_ext_unit *const component = devattr->component; in counter_device_ext_show()
1094 const struct counter_device_ext *const ext = component->ext; in counter_device_ext_show()
1096 return ext->read(dev_get_drvdata(dev), ext->priv, buf); in counter_device_ext_show()
1104 const struct counter_ext_unit *const component = devattr->component; in counter_device_ext_store()
1105 const struct counter_device_ext *const ext = component->ext; in counter_device_ext_store()
1107 return ext->write(dev_get_drvdata(dev), ext->priv, buf, len); in counter_device_ext_store()
1120 for (i = 0 ; i < counter->num_ext; i++) { in counter_device_ext_register()
1124 err = -ENOMEM; in counter_device_ext_register()
1128 ext_comp->ext = counter->ext + i; in counter_device_ext_register()
1133 parm.name = counter->ext[i].name; in counter_device_ext_register()
1134 parm.show = (counter->ext[i].read) ? counter_device_ext_show : NULL; in counter_device_ext_register()
1135 parm.store = (counter->ext[i].write) ? counter_device_ext_store : NULL; in counter_device_ext_register()
1147 counter_device_attr_list_free(&group->attr_list); in counter_device_ext_register()
1158 err = counter_name_attribute_create(group, counter->name); in counter_global_attr_register()
1163 err = counter_size_attribute_create(group, counter->num_counts, in counter_global_attr_register()
1169 err = counter_size_attribute_create(group, counter->num_signals, in counter_global_attr_register()
1182 counter_device_attr_list_free(&group->attr_list); in counter_global_attr_register()
1198 kfree(group->attr_group.name); in counter_device_groups_list_free()
1199 kfree(group->attr_group.attrs); in counter_device_groups_list_free()
1200 counter_device_attr_list_free(&group->attr_list); in counter_device_groups_list_free()
1210 counter->num_signals + counter->num_counts + 1; in counter_device_groups_list_prepare()
1220 return -ENOMEM; in counter_device_groups_list_prepare()
1230 num_groups += counter->num_signals; in counter_device_groups_list_prepare()
1236 num_groups += counter->num_counts; in counter_device_groups_list_prepare()
1245 counter->device_state->groups_list = groups_list; in counter_device_groups_list_prepare()
1246 counter->device_state->num_groups = num_groups; in counter_device_groups_list_prepare()
1264 device_state->groups = kcalloc(device_state->num_groups + 1, in counter_device_groups_prepare()
1265 sizeof(*device_state->groups), in counter_device_groups_prepare()
1267 if (!device_state->groups) in counter_device_groups_prepare()
1268 return -ENOMEM; in counter_device_groups_prepare()
1271 for (i = 0; i < device_state->num_groups; i++) { in counter_device_groups_prepare()
1272 group = device_state->groups_list + i; in counter_device_groups_prepare()
1275 group->attr_group.attrs = kcalloc(group->num_attr + 1, in counter_device_groups_prepare()
1276 sizeof(*group->attr_group.attrs), GFP_KERNEL); in counter_device_groups_prepare()
1277 if (!group->attr_group.attrs) { in counter_device_groups_prepare()
1278 err = -ENOMEM; in counter_device_groups_prepare()
1284 list_for_each_entry(p, &group->attr_list, l) in counter_device_groups_prepare()
1285 group->attr_group.attrs[j++] = &p->dev_attr.attr; in counter_device_groups_prepare()
1288 device_state->groups[i] = &group->attr_group; in counter_device_groups_prepare()
1291 device_state->dev.groups = device_state->groups; in counter_device_groups_prepare()
1297 group = device_state->groups_list + i; in counter_device_groups_prepare()
1298 kfree(group->attr_group.attrs); in counter_device_groups_prepare()
1299 group->attr_group.attrs = NULL; in counter_device_groups_prepare()
1300 } while (i--); in counter_device_groups_prepare()
1301 kfree(device_state->groups); in counter_device_groups_prepare()
1305 /* Provides a unique ID for each counter device */
1311 struct counter_device_state *const device_state = counter->device_state; in counter_device_release()
1313 kfree(device_state->groups); in counter_device_release()
1314 counter_device_groups_list_free(device_state->groups_list, in counter_device_release()
1315 device_state->num_groups); in counter_device_release()
1316 ida_simple_remove(&counter_ida, device_state->id); in counter_device_release()
1330 * counter_register - register Counter to the system
1345 return -ENOMEM; in counter_register()
1346 counter->device_state = device_state; in counter_register()
1348 /* Acquire unique ID */ in counter_register()
1349 device_state->id = ida_simple_get(&counter_ida, 0, 0, GFP_KERNEL); in counter_register()
1350 if (device_state->id < 0) { in counter_register()
1351 err = device_state->id; in counter_register()
1356 device_state->dev.type = &counter_device_type; in counter_register()
1357 device_state->dev.bus = &counter_bus_type; in counter_register()
1358 if (counter->parent) { in counter_register()
1359 device_state->dev.parent = counter->parent; in counter_register()
1360 device_state->dev.of_node = counter->parent->of_node; in counter_register()
1362 dev_set_name(&device_state->dev, "counter%d", device_state->id); in counter_register()
1363 device_initialize(&device_state->dev); in counter_register()
1364 dev_set_drvdata(&device_state->dev, counter); in counter_register()
1377 err = device_add(&device_state->dev); in counter_register()
1384 kfree(device_state->groups); in counter_register()
1386 counter_device_groups_list_free(device_state->groups_list, in counter_register()
1387 device_state->num_groups); in counter_register()
1389 ida_simple_remove(&counter_ida, device_state->id); in counter_register()
1397 * counter_unregister - unregister Counter from the system
1405 device_del(&counter->device_state->dev); in counter_unregister()
1415 * devm_counter_register - Resource-managed counter_register
1437 return -ENOMEM; in devm_counter_register()
1464 * devm_counter_unregister - Resource-managed counter_unregister