Lines Matching +full:signal +full:- +full:group

1 // SPDX-License-Identifier: GPL-2.0
20 #include "counter-sysfs.h"
28 * struct counter_attribute - Counter sysfs attribute
30 * @l: node to add Counter attribute to attribute group list
48 * struct counter_attribute_group - container for attribute group
49 * @name: name of the attribute group
62 [COUNTER_FUNCTION_PULSE_DIRECTION] = "pulse-direction",
90 [COUNTER_COUNT_MODE_NON_RECYCLE] = "non-recycle",
91 [COUNTER_COUNT_MODE_MODULO_N] = "modulo-n"
107 switch (a->scope) { in counter_comp_u8_show()
109 err = a->comp.device_u8_read(counter, &data); in counter_comp_u8_show()
112 err = a->comp.signal_u8_read(counter, a->parent, &data); in counter_comp_u8_show()
115 err = a->comp.count_u8_read(counter, a->parent, &data); in counter_comp_u8_show()
118 return -EINVAL; in counter_comp_u8_show()
123 if (a->comp.type == COUNTER_COMP_BOOL) in counter_comp_u8_show()
140 if (a->comp.type == COUNTER_COMP_BOOL) { in counter_comp_u8_store()
148 switch (a->scope) { in counter_comp_u8_store()
150 err = a->comp.device_u8_write(counter, data); in counter_comp_u8_store()
153 err = a->comp.signal_u8_write(counter, a->parent, data); in counter_comp_u8_store()
156 err = a->comp.count_u8_write(counter, a->parent, data); in counter_comp_u8_store()
159 return -EINVAL; in counter_comp_u8_store()
172 const struct counter_available *const avail = a->comp.priv; in counter_comp_u32_show()
176 switch (a->scope) { in counter_comp_u32_show()
178 err = a->comp.device_u32_read(counter, &data); in counter_comp_u32_show()
181 err = a->comp.signal_u32_read(counter, a->parent, &data); in counter_comp_u32_show()
184 if (a->comp.type == COUNTER_COMP_SYNAPSE_ACTION) in counter_comp_u32_show()
185 err = a->comp.action_read(counter, a->parent, in counter_comp_u32_show()
186 a->comp.priv, &data); in counter_comp_u32_show()
188 err = a->comp.count_u32_read(counter, a->parent, &data); in counter_comp_u32_show()
191 return -EINVAL; in counter_comp_u32_show()
196 switch (a->comp.type) { in counter_comp_u32_show()
204 return sysfs_emit(buf, "%s\n", avail->strs[data]); in counter_comp_u32_show()
228 return -EINVAL; in counter_find_enum()
237 struct counter_count *const count = a->parent; in counter_comp_u32_store()
238 struct counter_synapse *const synapse = a->comp.priv; in counter_comp_u32_store()
239 const struct counter_available *const avail = a->comp.priv; in counter_comp_u32_store()
243 switch (a->comp.type) { in counter_comp_u32_store()
245 err = counter_find_enum(&data, count->functions_list, in counter_comp_u32_store()
246 count->num_functions, buf, in counter_comp_u32_store()
250 err = counter_find_enum(&data, synapse->actions_list, in counter_comp_u32_store()
251 synapse->num_actions, buf, in counter_comp_u32_store()
255 err = __sysfs_match_string(avail->strs, avail->num_items, buf); in counter_comp_u32_store()
259 err = counter_find_enum(&data, avail->enums, avail->num_items, in counter_comp_u32_store()
263 err = counter_find_enum(&data, avail->enums, avail->num_items, in counter_comp_u32_store()
273 switch (a->scope) { in counter_comp_u32_store()
275 err = a->comp.device_u32_write(counter, data); in counter_comp_u32_store()
278 err = a->comp.signal_u32_write(counter, a->parent, data); in counter_comp_u32_store()
281 if (a->comp.type == COUNTER_COMP_SYNAPSE_ACTION) in counter_comp_u32_store()
282 err = a->comp.action_write(counter, count, synapse, in counter_comp_u32_store()
285 err = a->comp.count_u32_write(counter, count, data); in counter_comp_u32_store()
288 return -EINVAL; in counter_comp_u32_store()
304 switch (a->scope) { in counter_comp_u64_show()
306 err = a->comp.device_u64_read(counter, &data); in counter_comp_u64_show()
309 err = a->comp.signal_u64_read(counter, a->parent, &data); in counter_comp_u64_show()
312 err = a->comp.count_u64_read(counter, a->parent, &data); in counter_comp_u64_show()
315 return -EINVAL; in counter_comp_u64_show()
336 switch (a->scope) { in counter_comp_u64_store()
338 err = a->comp.device_u64_write(counter, data); in counter_comp_u64_store()
341 err = a->comp.signal_u64_write(counter, a->parent, data); in counter_comp_u64_store()
344 err = a->comp.count_u64_write(counter, a->parent, data); in counter_comp_u64_store()
347 return -EINVAL; in counter_comp_u64_store()
361 const struct counter_array *const element = a->comp.priv; in counter_comp_array_u32_show()
365 if (a->scope != COUNTER_SCOPE_SIGNAL || in counter_comp_array_u32_show()
366 element->type != COUNTER_COMP_SIGNAL_POLARITY) in counter_comp_array_u32_show()
367 return -EINVAL; in counter_comp_array_u32_show()
369 err = a->comp.signal_array_u32_read(counter, a->parent, element->idx, in counter_comp_array_u32_show()
383 const struct counter_array *const element = a->comp.priv; in counter_comp_array_u32_store()
387 if (element->type != COUNTER_COMP_SIGNAL_POLARITY || in counter_comp_array_u32_store()
388 a->scope != COUNTER_SCOPE_SIGNAL) in counter_comp_array_u32_store()
389 return -EINVAL; in counter_comp_array_u32_store()
391 err = counter_find_enum(&data, element->avail->enums, in counter_comp_array_u32_store()
392 element->avail->num_items, buf, in counter_comp_array_u32_store()
397 err = a->comp.signal_array_u32_write(counter, a->parent, element->idx, in counter_comp_array_u32_store()
411 const struct counter_array *const element = a->comp.priv; in counter_comp_array_u64_show()
415 switch (a->scope) { in counter_comp_array_u64_show()
417 err = a->comp.device_array_u64_read(counter, element->idx, in counter_comp_array_u64_show()
421 err = a->comp.signal_array_u64_read(counter, a->parent, in counter_comp_array_u64_show()
422 element->idx, &data); in counter_comp_array_u64_show()
425 err = a->comp.count_array_u64_read(counter, a->parent, in counter_comp_array_u64_show()
426 element->idx, &data); in counter_comp_array_u64_show()
429 return -EINVAL; in counter_comp_array_u64_show()
443 const struct counter_array *const element = a->comp.priv; in counter_comp_array_u64_store()
451 switch (a->scope) { in counter_comp_array_u64_store()
453 err = a->comp.device_array_u64_write(counter, element->idx, in counter_comp_array_u64_store()
457 err = a->comp.signal_array_u64_write(counter, a->parent, in counter_comp_array_u64_store()
458 element->idx, data); in counter_comp_array_u64_store()
461 err = a->comp.count_array_u64_write(counter, a->parent, in counter_comp_array_u64_store()
462 element->idx, data); in counter_comp_array_u64_store()
465 return -EINVAL; in counter_comp_array_u64_store()
492 for (index = 0; index < avail->num_items; index++) in strs_available_show()
493 len += sysfs_emit_at(buf, len, "%s\n", avail->strs[index]); in strs_available_show()
503 const struct counter_count *const count = a->parent; in counter_comp_available_show()
504 const struct counter_synapse *const synapse = a->comp.priv; in counter_comp_available_show()
505 const struct counter_available *const avail = a->comp.priv; in counter_comp_available_show()
507 switch (a->comp.type) { in counter_comp_available_show()
509 return enums_available_show(count->functions_list, in counter_comp_available_show()
510 count->num_functions, in counter_comp_available_show()
513 return enums_available_show(synapse->actions_list, in counter_comp_available_show()
514 synapse->num_actions, in counter_comp_available_show()
519 return enums_available_show(avail->enums, avail->num_items, in counter_comp_available_show()
522 return -EINVAL; in counter_comp_available_show()
527 struct counter_attribute_group *const group, in counter_avail_attr_create() argument
535 return -ENOMEM; in counter_avail_attr_create()
538 counter_attr->comp.type = comp->type; in counter_avail_attr_create()
539 counter_attr->comp.priv = comp->priv; in counter_avail_attr_create()
540 counter_attr->parent = parent; in counter_avail_attr_create()
543 dev_attr = &counter_attr->dev_attr; in counter_avail_attr_create()
544 sysfs_attr_init(&dev_attr->attr); in counter_avail_attr_create()
547 dev_attr->attr.name = devm_kasprintf(dev, GFP_KERNEL, "%s_available", in counter_avail_attr_create()
548 comp->name); in counter_avail_attr_create()
549 if (!dev_attr->attr.name) in counter_avail_attr_create()
550 return -ENOMEM; in counter_avail_attr_create()
551 dev_attr->attr.mode = 0444; in counter_avail_attr_create()
552 dev_attr->show = counter_comp_available_show; in counter_avail_attr_create()
555 list_add(&counter_attr->l, &group->attr_list); in counter_avail_attr_create()
556 group->num_attr++; in counter_avail_attr_create()
562 struct counter_attribute_group *const group, in counter_attr_create() argument
567 const struct counter_array *const array = comp->priv; in counter_attr_create()
573 return -ENOMEM; in counter_attr_create()
576 counter_attr->comp = *comp; in counter_attr_create()
577 counter_attr->scope = scope; in counter_attr_create()
578 counter_attr->parent = parent; in counter_attr_create()
581 dev_attr = &counter_attr->dev_attr; in counter_attr_create()
582 sysfs_attr_init(&dev_attr->attr); in counter_attr_create()
583 dev_attr->attr.name = comp->name; in counter_attr_create()
584 switch (comp->type) { in counter_attr_create()
587 if (comp->device_u8_read) { in counter_attr_create()
588 dev_attr->attr.mode |= 0444; in counter_attr_create()
589 dev_attr->show = counter_comp_u8_show; in counter_attr_create()
591 if (comp->device_u8_write) { in counter_attr_create()
592 dev_attr->attr.mode |= 0200; in counter_attr_create()
593 dev_attr->store = counter_comp_u8_store; in counter_attr_create()
603 if (comp->device_u32_read) { in counter_attr_create()
604 dev_attr->attr.mode |= 0444; in counter_attr_create()
605 dev_attr->show = counter_comp_u32_show; in counter_attr_create()
607 if (comp->device_u32_write) { in counter_attr_create()
608 dev_attr->attr.mode |= 0200; in counter_attr_create()
609 dev_attr->store = counter_comp_u32_store; in counter_attr_create()
613 if (comp->device_u64_read) { in counter_attr_create()
614 dev_attr->attr.mode |= 0444; in counter_attr_create()
615 dev_attr->show = counter_comp_u64_show; in counter_attr_create()
617 if (comp->device_u64_write) { in counter_attr_create()
618 dev_attr->attr.mode |= 0200; in counter_attr_create()
619 dev_attr->store = counter_comp_u64_store; in counter_attr_create()
623 switch (array->type) { in counter_attr_create()
625 if (comp->signal_array_u32_read) { in counter_attr_create()
626 dev_attr->attr.mode |= 0444; in counter_attr_create()
627 dev_attr->show = counter_comp_array_u32_show; in counter_attr_create()
629 if (comp->signal_array_u32_write) { in counter_attr_create()
630 dev_attr->attr.mode |= 0200; in counter_attr_create()
631 dev_attr->store = counter_comp_array_u32_store; in counter_attr_create()
635 if (comp->device_array_u64_read) { in counter_attr_create()
636 dev_attr->attr.mode |= 0444; in counter_attr_create()
637 dev_attr->show = counter_comp_array_u64_show; in counter_attr_create()
639 if (comp->device_array_u64_write) { in counter_attr_create()
640 dev_attr->attr.mode |= 0200; in counter_attr_create()
641 dev_attr->store = counter_comp_array_u64_store; in counter_attr_create()
645 return -EINVAL; in counter_attr_create()
649 return -EINVAL; in counter_attr_create()
653 list_add(&counter_attr->l, &group->attr_list); in counter_attr_create()
654 group->num_attr++; in counter_attr_create()
657 switch (comp->type) { in counter_attr_create()
662 return counter_avail_attr_create(dev, group, comp, parent); in counter_attr_create()
671 return sysfs_emit(buf, "%s\n", to_counter_attribute(attr)->comp.name); in counter_comp_name_show()
675 struct counter_attribute_group *const group, in counter_name_attr_create() argument
682 return -ENOMEM; in counter_name_attr_create()
685 counter_attr->comp.name = name; in counter_name_attr_create()
688 sysfs_attr_init(&counter_attr->dev_attr.attr); in counter_name_attr_create()
689 counter_attr->dev_attr.attr.name = "name"; in counter_name_attr_create()
690 counter_attr->dev_attr.attr.mode = 0444; in counter_name_attr_create()
691 counter_attr->dev_attr.show = counter_comp_name_show; in counter_name_attr_create()
694 list_add(&counter_attr->l, &group->attr_list); in counter_name_attr_create()
695 group->num_attr++; in counter_name_attr_create()
703 const size_t id = (size_t)to_counter_attribute(attr)->comp.priv; in counter_comp_id_show()
709 struct counter_attribute_group *const group, in counter_comp_id_attr_create() argument
717 return -ENOMEM; in counter_comp_id_attr_create()
722 return -ENOMEM; in counter_comp_id_attr_create()
725 counter_attr->comp.priv = (void *)id; in counter_comp_id_attr_create()
728 sysfs_attr_init(&counter_attr->dev_attr.attr); in counter_comp_id_attr_create()
729 counter_attr->dev_attr.attr.name = name; in counter_comp_id_attr_create()
730 counter_attr->dev_attr.attr.mode = 0444; in counter_comp_id_attr_create()
731 counter_attr->dev_attr.show = counter_comp_id_show; in counter_comp_id_attr_create()
734 list_add(&counter_attr->l, &group->attr_list); in counter_comp_id_attr_create()
735 group->num_attr++; in counter_comp_id_attr_create()
741 struct counter_attribute_group *const group, in counter_ext_attrs_create() argument
749 err = counter_attr_create(dev, group, ext, scope, parent); in counter_ext_attrs_create()
754 return counter_comp_id_attr_create(dev, group, ext->name, id); in counter_ext_attrs_create()
758 struct counter_attribute_group *const group, in counter_array_attrs_create() argument
763 const struct counter_array *const array = comp->priv; in counter_array_attrs_create()
770 for (idx = 0; idx < array->length; idx++) { in counter_array_attrs_create()
772 ext.name = devm_kasprintf(dev, GFP_KERNEL, "%s%zu", comp->name, in counter_array_attrs_create()
775 return -ENOMEM; in counter_array_attrs_create()
780 return -ENOMEM; in counter_array_attrs_create()
781 element->type = array->type; in counter_array_attrs_create()
782 element->avail = array->avail; in counter_array_attrs_create()
783 element->idx = idx; in counter_array_attrs_create()
787 err = counter_ext_attrs_create(dev, group, &ext, scope, parent, in counter_array_attrs_create()
797 struct counter_attribute_group *const group, in counter_sysfs_exts_add() argument
812 if (ext->type == COUNTER_COMP_ARRAY) { in counter_sysfs_exts_add()
813 err = counter_array_attrs_create(dev, group, ext, scope, in counter_sysfs_exts_add()
815 array = ext->priv; in counter_sysfs_exts_add()
816 id += array->length; in counter_sysfs_exts_add()
818 err = counter_ext_attrs_create(dev, group, ext, scope, in counter_sysfs_exts_add()
831 .name = "signal",
836 struct counter_signal *const signal) in counter_signal_attrs_create() argument
839 struct device *const dev = &counter->dev; in counter_signal_attrs_create()
843 /* Create main Signal attribute */ in counter_signal_attrs_create()
845 comp.signal_u32_read = counter->ops->signal_read; in counter_signal_attrs_create()
846 err = counter_attr_create(dev, cattr_group, &comp, scope, signal); in counter_signal_attrs_create()
850 /* Create Signal name attribute */ in counter_signal_attrs_create()
851 err = counter_name_attr_create(dev, cattr_group, signal->name); in counter_signal_attrs_create()
855 /* Add Signal extensions */ in counter_signal_attrs_create()
856 return counter_sysfs_exts_add(dev, cattr_group, signal->ext, in counter_signal_attrs_create()
857 signal->num_ext, scope, signal); in counter_signal_attrs_create()
866 /* Add each Signal */ in counter_sysfs_signals_add()
867 for (i = 0; i < counter->num_signals; i++) { in counter_sysfs_signals_add()
868 /* Generate Signal attribute directory name */ in counter_sysfs_signals_add()
869 groups[i].name = devm_kasprintf(&counter->dev, GFP_KERNEL, in counter_sysfs_signals_add()
870 "signal%zu", i); in counter_sysfs_signals_add()
872 return -ENOMEM; in counter_sysfs_signals_add()
874 /* Create all attributes associated with Signal */ in counter_sysfs_signals_add()
876 counter->signals + i); in counter_sysfs_signals_add()
885 struct counter_attribute_group *const group, in counter_sysfs_synapses_add() argument
891 for (i = 0; i < count->num_synapses; i++) { in counter_sysfs_synapses_add()
892 struct device *const dev = &counter->dev; in counter_sysfs_synapses_add()
898 synapse = count->synapses + i; in counter_sysfs_synapses_add()
901 id = synapse->signal - counter->signals; in counter_sysfs_synapses_add()
902 comp.name = devm_kasprintf(dev, GFP_KERNEL, "signal%zu_action", in counter_sysfs_synapses_add()
905 return -ENOMEM; in counter_sysfs_synapses_add()
909 comp.action_read = counter->ops->action_read; in counter_sysfs_synapses_add()
910 comp.action_write = counter->ops->action_write; in counter_sysfs_synapses_add()
912 err = counter_attr_create(dev, group, &comp, in counter_sysfs_synapses_add()
918 err = counter_comp_id_attr_create(dev, group, comp.name, i); in counter_sysfs_synapses_add()
939 struct device *const dev = &counter->dev; in counter_count_attrs_create()
945 comp.count_u64_read = counter->ops->count_read; in counter_count_attrs_create()
946 comp.count_u64_write = counter->ops->count_write; in counter_count_attrs_create()
952 err = counter_name_attr_create(dev, cattr_group, count->name); in counter_count_attrs_create()
958 comp.count_u32_read = counter->ops->function_read; in counter_count_attrs_create()
959 comp.count_u32_write = counter->ops->function_write; in counter_count_attrs_create()
965 return counter_sysfs_exts_add(dev, cattr_group, count->ext, in counter_count_attrs_create()
966 count->num_ext, scope, count); in counter_count_attrs_create()
977 for (i = 0; i < counter->num_counts; i++) { in counter_sysfs_counts_add()
978 count = counter->counts + i; in counter_sysfs_counts_add()
981 groups[i].name = devm_kasprintf(&counter->dev, GFP_KERNEL, in counter_sysfs_counts_add()
984 return -ENOMEM; in counter_sysfs_counts_add()
1002 *val = counter->num_signals; in counter_num_signals_read()
1008 *val = counter->num_counts; in counter_num_counts_read()
1015 *val = kfifo_size(&counter->events); in counter_events_queue_size_read()
1032 mutex_lock(&counter->events_out_lock); in counter_events_queue_size_write()
1033 spin_lock_irqsave(&counter->events_in_lock, flags); in counter_events_queue_size_write()
1034 kfifo_free(&counter->events); in counter_events_queue_size_write()
1035 counter->events.kfifo = events.kfifo; in counter_events_queue_size_write()
1036 spin_unlock_irqrestore(&counter->events_in_lock, flags); in counter_events_queue_size_write()
1037 mutex_unlock(&counter->events_out_lock); in counter_events_queue_size_write()
1057 struct device *const dev = &counter->dev; in counter_sysfs_attr_add()
1064 cattr_group += counter->num_signals; in counter_sysfs_attr_add()
1070 cattr_group += counter->num_counts; in counter_sysfs_attr_add()
1073 err = counter_name_attr_create(dev, cattr_group, counter->name); in counter_sysfs_attr_add()
1096 return counter_sysfs_exts_add(dev, cattr_group, counter->ext, in counter_sysfs_attr_add()
1097 counter->num_ext, scope, NULL); in counter_sysfs_attr_add()
1103 * counter_sysfs_add - Adds Counter sysfs attributes to the device structure
1107 * structure for later registration to the system. Resource-managed memory
1114 struct device *const dev = &counter->dev; in counter_sysfs_add()
1115 const size_t num_groups = counter->num_signals + counter->num_counts + 1; in counter_sysfs_add()
1126 return -ENOMEM; in counter_sysfs_add()
1137 /* Allocate attribute group pointers for association with device */ in counter_sysfs_add()
1138 dev->groups = devm_kcalloc(dev, num_groups + 1, sizeof(*dev->groups), in counter_sysfs_add()
1140 if (!dev->groups) in counter_sysfs_add()
1141 return -ENOMEM; in counter_sysfs_add()
1146 return -ENOMEM; in counter_sysfs_add()
1148 /* Prepare each group of attributes for association */ in counter_sysfs_add()
1158 return -ENOMEM; in counter_sysfs_add()
1160 /* Add attribute pointers to attribute group */ in counter_sysfs_add()
1163 groups[i].attrs[j++] = &p->dev_attr.attr; in counter_sysfs_add()
1165 /* Associate attribute group */ in counter_sysfs_add()
1166 dev->groups[i] = &groups[i]; in counter_sysfs_add()