Lines Matching +full:attr +full:- +full:cnt +full:- +full:name

1 // SPDX-License-Identifier: GPL-2.0-only
9 #include "pvrusb2-sysfs.h"
10 #include "pvrusb2-hdw.h"
11 #include "pvrusb2-debug.h"
13 #include "pvrusb2-debugifc.h"
66 char name[80]; member
70 struct device_attribute *attr, in show_name() argument
74 const char *name; in show_name() local
75 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_name); in show_name()
76 name = pvr2_ctrl_get_desc(cip->cptr); in show_name()
78 cip->chptr, cip->ctl_id, name); in show_name()
79 if (!name) return -EINVAL; in show_name()
80 return sysfs_emit(buf, "%s\n", name); in show_name()
84 struct device_attribute *attr, in show_type() argument
88 const char *name; in show_type() local
90 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_type); in show_type()
91 tp = pvr2_ctrl_get_type(cip->cptr); in show_type()
93 case pvr2_ctl_int: name = "integer"; break; in show_type()
94 case pvr2_ctl_enum: name = "enum"; break; in show_type()
95 case pvr2_ctl_bitmask: name = "bitmask"; break; in show_type()
96 case pvr2_ctl_bool: name = "boolean"; break; in show_type()
97 default: name = "?"; break; in show_type()
100 cip->chptr, cip->ctl_id, name); in show_type()
101 return sysfs_emit(buf, "%s\n", name); in show_type()
105 struct device_attribute *attr, in show_min() argument
110 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_min); in show_min()
111 val = pvr2_ctrl_get_min(cip->cptr); in show_min()
113 cip->chptr, cip->ctl_id, val); in show_min()
118 struct device_attribute *attr, in show_max() argument
123 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_max); in show_max()
124 val = pvr2_ctrl_get_max(cip->cptr); in show_max()
126 cip->chptr, cip->ctl_id, val); in show_max()
131 struct device_attribute *attr, in show_def() argument
137 unsigned int cnt = 0; in show_def() local
138 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_def); in show_def()
139 ret = pvr2_ctrl_get_def(cip->cptr, &val); in show_def()
141 ret = pvr2_ctrl_value_to_sym(cip->cptr, ~0, val, in show_def()
142 buf, PAGE_SIZE - 1, &cnt); in show_def()
144 cip->chptr, cip->ctl_id, cnt, buf, val); in show_def()
145 buf[cnt] = '\n'; in show_def()
146 return cnt + 1; in show_def()
150 struct device_attribute *attr, in show_val_norm() argument
156 unsigned int cnt = 0; in show_val_norm() local
157 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_val); in show_val_norm()
158 ret = pvr2_ctrl_get_value(cip->cptr, &val); in show_val_norm()
160 ret = pvr2_ctrl_value_to_sym(cip->cptr, ~0, val, in show_val_norm()
161 buf, PAGE_SIZE - 1, &cnt); in show_val_norm()
163 cip->chptr, cip->ctl_id, cnt, buf, val); in show_val_norm()
164 buf[cnt] = '\n'; in show_val_norm()
165 return cnt+1; in show_val_norm()
169 struct device_attribute *attr, in show_val_custom() argument
175 unsigned int cnt = 0; in show_val_custom() local
176 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_custom); in show_val_custom()
177 ret = pvr2_ctrl_get_value(cip->cptr, &val); in show_val_custom()
179 ret = pvr2_ctrl_custom_value_to_sym(cip->cptr, ~0, val, in show_val_custom()
180 buf, PAGE_SIZE - 1, &cnt); in show_val_custom()
182 cip->chptr, cip->ctl_id, cnt, buf, val); in show_val_custom()
183 buf[cnt] = '\n'; in show_val_custom()
184 return cnt+1; in show_val_custom()
188 struct device_attribute *attr, in show_enum() argument
194 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_enum); in show_enum()
195 ecnt = pvr2_ctrl_get_cnt(cip->cptr); in show_enum()
198 pvr2_ctrl_get_valname(cip->cptr, val, buf + bcnt, in show_enum()
199 PAGE_SIZE - bcnt, &ccnt); in show_enum()
207 cip->chptr, cip->ctl_id); in show_enum()
212 struct device_attribute *attr, in show_bits() argument
218 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_bits); in show_bits()
219 valid_bits = pvr2_ctrl_get_mask(cip->cptr); in show_bits()
224 pvr2_ctrl_get_valname(cip->cptr, msk, buf + bcnt, in show_bits()
225 PAGE_SIZE - bcnt, &ccnt); in show_bits()
232 cip->chptr, cip->ctl_id); in show_bits()
242 ret = pvr2_ctrl_custom_sym_to_value(cip->cptr, buf, count, in store_val_any()
245 ret = pvr2_ctrl_sym_to_value(cip->cptr, buf, count, in store_val_any()
249 ret = pvr2_ctrl_set_mask_value(cip->cptr, mask, val); in store_val_any()
250 pvr2_hdw_commit_ctl(cip->chptr->channel.hdw); in store_val_any()
255 struct device_attribute *attr, in store_val_norm() argument
260 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_val); in store_val_norm()
262 cip->chptr, cip->ctl_id, (int)count, buf); in store_val_norm()
269 struct device_attribute *attr, in store_val_custom() argument
274 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_custom); in store_val_custom()
276 cip->chptr, cip->ctl_id, (int)count, buf); in store_val_custom()
286 unsigned int cnt,acnt; in pvr2_sysfs_add_control() local
289 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,ctl_id); in pvr2_sysfs_add_control()
296 cip->cptr = cptr; in pvr2_sysfs_add_control()
297 cip->ctl_id = ctl_id; in pvr2_sysfs_add_control()
299 cip->chptr = sfp; in pvr2_sysfs_add_control()
300 cip->item_next = NULL; in pvr2_sysfs_add_control()
301 if (sfp->item_last) { in pvr2_sysfs_add_control()
302 sfp->item_last->item_next = cip; in pvr2_sysfs_add_control()
304 sfp->item_first = cip; in pvr2_sysfs_add_control()
306 sfp->item_last = cip; in pvr2_sysfs_add_control()
308 sysfs_attr_init(&cip->attr_name.attr); in pvr2_sysfs_add_control()
309 cip->attr_name.attr.name = "name"; in pvr2_sysfs_add_control()
310 cip->attr_name.attr.mode = S_IRUGO; in pvr2_sysfs_add_control()
311 cip->attr_name.show = show_name; in pvr2_sysfs_add_control()
313 sysfs_attr_init(&cip->attr_type.attr); in pvr2_sysfs_add_control()
314 cip->attr_type.attr.name = "type"; in pvr2_sysfs_add_control()
315 cip->attr_type.attr.mode = S_IRUGO; in pvr2_sysfs_add_control()
316 cip->attr_type.show = show_type; in pvr2_sysfs_add_control()
318 sysfs_attr_init(&cip->attr_min.attr); in pvr2_sysfs_add_control()
319 cip->attr_min.attr.name = "min_val"; in pvr2_sysfs_add_control()
320 cip->attr_min.attr.mode = S_IRUGO; in pvr2_sysfs_add_control()
321 cip->attr_min.show = show_min; in pvr2_sysfs_add_control()
323 sysfs_attr_init(&cip->attr_max.attr); in pvr2_sysfs_add_control()
324 cip->attr_max.attr.name = "max_val"; in pvr2_sysfs_add_control()
325 cip->attr_max.attr.mode = S_IRUGO; in pvr2_sysfs_add_control()
326 cip->attr_max.show = show_max; in pvr2_sysfs_add_control()
328 sysfs_attr_init(&cip->attr_def.attr); in pvr2_sysfs_add_control()
329 cip->attr_def.attr.name = "def_val"; in pvr2_sysfs_add_control()
330 cip->attr_def.attr.mode = S_IRUGO; in pvr2_sysfs_add_control()
331 cip->attr_def.show = show_def; in pvr2_sysfs_add_control()
333 sysfs_attr_init(&cip->attr_val.attr); in pvr2_sysfs_add_control()
334 cip->attr_val.attr.name = "cur_val"; in pvr2_sysfs_add_control()
335 cip->attr_val.attr.mode = S_IRUGO; in pvr2_sysfs_add_control()
337 sysfs_attr_init(&cip->attr_custom.attr); in pvr2_sysfs_add_control()
338 cip->attr_custom.attr.name = "custom_val"; in pvr2_sysfs_add_control()
339 cip->attr_custom.attr.mode = S_IRUGO; in pvr2_sysfs_add_control()
341 sysfs_attr_init(&cip->attr_enum.attr); in pvr2_sysfs_add_control()
342 cip->attr_enum.attr.name = "enum_val"; in pvr2_sysfs_add_control()
343 cip->attr_enum.attr.mode = S_IRUGO; in pvr2_sysfs_add_control()
344 cip->attr_enum.show = show_enum; in pvr2_sysfs_add_control()
346 sysfs_attr_init(&cip->attr_bits.attr); in pvr2_sysfs_add_control()
347 cip->attr_bits.attr.name = "bit_val"; in pvr2_sysfs_add_control()
348 cip->attr_bits.attr.mode = S_IRUGO; in pvr2_sysfs_add_control()
349 cip->attr_bits.show = show_bits; in pvr2_sysfs_add_control()
352 cip->attr_val.attr.mode |= S_IWUSR|S_IWGRP; in pvr2_sysfs_add_control()
353 cip->attr_custom.attr.mode |= S_IWUSR|S_IWGRP; in pvr2_sysfs_add_control()
357 cip->attr_gen[acnt++] = &cip->attr_name.attr; in pvr2_sysfs_add_control()
358 cip->attr_gen[acnt++] = &cip->attr_type.attr; in pvr2_sysfs_add_control()
359 cip->attr_gen[acnt++] = &cip->attr_val.attr; in pvr2_sysfs_add_control()
360 cip->attr_gen[acnt++] = &cip->attr_def.attr; in pvr2_sysfs_add_control()
361 cip->attr_val.show = show_val_norm; in pvr2_sysfs_add_control()
362 cip->attr_val.store = store_val_norm; in pvr2_sysfs_add_control()
364 cip->attr_gen[acnt++] = &cip->attr_custom.attr; in pvr2_sysfs_add_control()
365 cip->attr_custom.show = show_val_custom; in pvr2_sysfs_add_control()
366 cip->attr_custom.store = store_val_custom; in pvr2_sysfs_add_control()
371 cip->attr_gen[acnt++] = &cip->attr_enum.attr; in pvr2_sysfs_add_control()
375 cip->attr_gen[acnt++] = &cip->attr_min.attr; in pvr2_sysfs_add_control()
376 cip->attr_gen[acnt++] = &cip->attr_max.attr; in pvr2_sysfs_add_control()
380 cip->attr_gen[acnt++] = &cip->attr_bits.attr; in pvr2_sysfs_add_control()
385 cnt = scnprintf(cip->name,sizeof(cip->name)-1,"ctl_%s", in pvr2_sysfs_add_control()
387 cip->name[cnt] = 0; in pvr2_sysfs_add_control()
388 cip->grp.name = cip->name; in pvr2_sysfs_add_control()
389 cip->grp.attrs = cip->attr_gen; in pvr2_sysfs_add_control()
391 ret = sysfs_create_group(&sfp->class_dev->kobj,&cip->grp); in pvr2_sysfs_add_control()
398 cip->created_ok = !0; in pvr2_sysfs_add_control()
416 sysfs_attr_init(&dip->attr_debugcmd.attr); in pvr2_sysfs_add_debugifc()
417 dip->attr_debugcmd.attr.name = "debugcmd"; in pvr2_sysfs_add_debugifc()
418 dip->attr_debugcmd.attr.mode = S_IRUGO|S_IWUSR|S_IWGRP; in pvr2_sysfs_add_debugifc()
419 dip->attr_debugcmd.show = debugcmd_show; in pvr2_sysfs_add_debugifc()
420 dip->attr_debugcmd.store = debugcmd_store; in pvr2_sysfs_add_debugifc()
421 sysfs_attr_init(&dip->attr_debuginfo.attr); in pvr2_sysfs_add_debugifc()
422 dip->attr_debuginfo.attr.name = "debuginfo"; in pvr2_sysfs_add_debugifc()
423 dip->attr_debuginfo.attr.mode = S_IRUGO; in pvr2_sysfs_add_debugifc()
424 dip->attr_debuginfo.show = debuginfo_show; in pvr2_sysfs_add_debugifc()
425 sfp->debugifc = dip; in pvr2_sysfs_add_debugifc()
426 ret = device_create_file(sfp->class_dev,&dip->attr_debugcmd); in pvr2_sysfs_add_debugifc()
432 dip->debugcmd_created_ok = !0; in pvr2_sysfs_add_debugifc()
434 ret = device_create_file(sfp->class_dev,&dip->attr_debuginfo); in pvr2_sysfs_add_debugifc()
440 dip->debuginfo_created_ok = !0; in pvr2_sysfs_add_debugifc()
447 if (!sfp->debugifc) return; in pvr2_sysfs_tear_down_debugifc()
448 if (sfp->debugifc->debuginfo_created_ok) { in pvr2_sysfs_tear_down_debugifc()
449 device_remove_file(sfp->class_dev, in pvr2_sysfs_tear_down_debugifc()
450 &sfp->debugifc->attr_debuginfo); in pvr2_sysfs_tear_down_debugifc()
452 if (sfp->debugifc->debugcmd_created_ok) { in pvr2_sysfs_tear_down_debugifc()
453 device_remove_file(sfp->class_dev, in pvr2_sysfs_tear_down_debugifc()
454 &sfp->debugifc->attr_debugcmd); in pvr2_sysfs_tear_down_debugifc()
456 kfree(sfp->debugifc); in pvr2_sysfs_tear_down_debugifc()
457 sfp->debugifc = NULL; in pvr2_sysfs_tear_down_debugifc()
464 unsigned int idx,cnt; in pvr2_sysfs_add_controls() local
465 cnt = pvr2_hdw_get_ctrl_count(sfp->channel.hdw); in pvr2_sysfs_add_controls()
466 for (idx = 0; idx < cnt; idx++) { in pvr2_sysfs_add_controls()
475 for (cip1 = sfp->item_first; cip1; cip1 = cip2) { in pvr2_sysfs_tear_down_controls()
476 cip2 = cip1->item_next; in pvr2_sysfs_tear_down_controls()
477 if (cip1->created_ok) { in pvr2_sysfs_tear_down_controls()
478 sysfs_remove_group(&sfp->class_dev->kobj,&cip1->grp); in pvr2_sysfs_tear_down_controls()
494 .name = "pvrusb2",
502 if (!sfp->class_dev) return; in class_dev_destroy()
507 if (sfp->hdw_desc_created_ok) { in class_dev_destroy()
508 device_remove_file(sfp->class_dev, in class_dev_destroy()
509 &sfp->attr_hdw_desc); in class_dev_destroy()
511 if (sfp->hdw_name_created_ok) { in class_dev_destroy()
512 device_remove_file(sfp->class_dev, in class_dev_destroy()
513 &sfp->attr_hdw_name); in class_dev_destroy()
515 if (sfp->bus_info_created_ok) { in class_dev_destroy()
516 device_remove_file(sfp->class_dev, in class_dev_destroy()
517 &sfp->attr_bus_info); in class_dev_destroy()
519 if (sfp->v4l_minor_number_created_ok) { in class_dev_destroy()
520 device_remove_file(sfp->class_dev, in class_dev_destroy()
521 &sfp->attr_v4l_minor_number); in class_dev_destroy()
523 if (sfp->v4l_radio_minor_number_created_ok) { in class_dev_destroy()
524 device_remove_file(sfp->class_dev, in class_dev_destroy()
525 &sfp->attr_v4l_radio_minor_number); in class_dev_destroy()
527 if (sfp->unit_number_created_ok) { in class_dev_destroy()
528 device_remove_file(sfp->class_dev, in class_dev_destroy()
529 &sfp->attr_unit_number); in class_dev_destroy()
531 pvr2_sysfs_trace("Destroying class_dev id=%p",sfp->class_dev); in class_dev_destroy()
532 dev_set_drvdata(sfp->class_dev, NULL); in class_dev_destroy()
533 dev = sfp->class_dev->parent; in class_dev_destroy()
534 sfp->class_dev->parent = NULL; in class_dev_destroy()
536 device_unregister(sfp->class_dev); in class_dev_destroy()
537 sfp->class_dev = NULL; in class_dev_destroy()
542 struct device_attribute *attr, char *buf) in v4l_minor_number_show() argument
546 if (!sfp) return -EINVAL; in v4l_minor_number_show()
548 pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw, in v4l_minor_number_show()
554 struct device_attribute *attr, char *buf) in bus_info_show() argument
558 if (!sfp) return -EINVAL; in bus_info_show()
560 pvr2_hdw_get_bus_info(sfp->channel.hdw)); in bus_info_show()
565 struct device_attribute *attr, char *buf) in hdw_name_show() argument
569 if (!sfp) return -EINVAL; in hdw_name_show()
571 pvr2_hdw_get_type(sfp->channel.hdw)); in hdw_name_show()
576 struct device_attribute *attr, char *buf) in hdw_desc_show() argument
580 if (!sfp) return -EINVAL; in hdw_desc_show()
582 pvr2_hdw_get_desc(sfp->channel.hdw)); in hdw_desc_show()
587 struct device_attribute *attr, in v4l_radio_minor_number_show() argument
592 if (!sfp) return -EINVAL; in v4l_radio_minor_number_show()
594 pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw, in v4l_radio_minor_number_show()
600 struct device_attribute *attr, char *buf) in unit_number_show() argument
604 if (!sfp) return -EINVAL; in unit_number_show()
606 pvr2_hdw_get_unit_number(sfp->channel.hdw)); in unit_number_show()
616 usb_dev = pvr2_hdw_get_dev(sfp->channel.hdw); in class_dev_create()
623 class_dev->class = &pvr2_class; in class_dev_create()
626 pvr2_hdw_get_device_identifier(sfp->channel.hdw)); in class_dev_create()
628 class_dev->parent = get_device(&usb_dev->dev); in class_dev_create()
630 sfp->class_dev = class_dev; in class_dev_create()
640 sysfs_attr_init(&sfp->attr_v4l_minor_number.attr); in class_dev_create()
641 sfp->attr_v4l_minor_number.attr.name = "v4l_minor_number"; in class_dev_create()
642 sfp->attr_v4l_minor_number.attr.mode = S_IRUGO; in class_dev_create()
643 sfp->attr_v4l_minor_number.show = v4l_minor_number_show; in class_dev_create()
644 sfp->attr_v4l_minor_number.store = NULL; in class_dev_create()
645 ret = device_create_file(sfp->class_dev, in class_dev_create()
646 &sfp->attr_v4l_minor_number); in class_dev_create()
652 sfp->v4l_minor_number_created_ok = !0; in class_dev_create()
655 sysfs_attr_init(&sfp->attr_v4l_radio_minor_number.attr); in class_dev_create()
656 sfp->attr_v4l_radio_minor_number.attr.name = "v4l_radio_minor_number"; in class_dev_create()
657 sfp->attr_v4l_radio_minor_number.attr.mode = S_IRUGO; in class_dev_create()
658 sfp->attr_v4l_radio_minor_number.show = v4l_radio_minor_number_show; in class_dev_create()
659 sfp->attr_v4l_radio_minor_number.store = NULL; in class_dev_create()
660 ret = device_create_file(sfp->class_dev, in class_dev_create()
661 &sfp->attr_v4l_radio_minor_number); in class_dev_create()
667 sfp->v4l_radio_minor_number_created_ok = !0; in class_dev_create()
670 sysfs_attr_init(&sfp->attr_unit_number.attr); in class_dev_create()
671 sfp->attr_unit_number.attr.name = "unit_number"; in class_dev_create()
672 sfp->attr_unit_number.attr.mode = S_IRUGO; in class_dev_create()
673 sfp->attr_unit_number.show = unit_number_show; in class_dev_create()
674 sfp->attr_unit_number.store = NULL; in class_dev_create()
675 ret = device_create_file(sfp->class_dev,&sfp->attr_unit_number); in class_dev_create()
681 sfp->unit_number_created_ok = !0; in class_dev_create()
684 sysfs_attr_init(&sfp->attr_bus_info.attr); in class_dev_create()
685 sfp->attr_bus_info.attr.name = "bus_info_str"; in class_dev_create()
686 sfp->attr_bus_info.attr.mode = S_IRUGO; in class_dev_create()
687 sfp->attr_bus_info.show = bus_info_show; in class_dev_create()
688 sfp->attr_bus_info.store = NULL; in class_dev_create()
689 ret = device_create_file(sfp->class_dev, in class_dev_create()
690 &sfp->attr_bus_info); in class_dev_create()
696 sfp->bus_info_created_ok = !0; in class_dev_create()
699 sysfs_attr_init(&sfp->attr_hdw_name.attr); in class_dev_create()
700 sfp->attr_hdw_name.attr.name = "device_hardware_type"; in class_dev_create()
701 sfp->attr_hdw_name.attr.mode = S_IRUGO; in class_dev_create()
702 sfp->attr_hdw_name.show = hdw_name_show; in class_dev_create()
703 sfp->attr_hdw_name.store = NULL; in class_dev_create()
704 ret = device_create_file(sfp->class_dev, in class_dev_create()
705 &sfp->attr_hdw_name); in class_dev_create()
711 sfp->hdw_name_created_ok = !0; in class_dev_create()
714 sysfs_attr_init(&sfp->attr_hdw_desc.attr); in class_dev_create()
715 sfp->attr_hdw_desc.attr.name = "device_hardware_description"; in class_dev_create()
716 sfp->attr_hdw_desc.attr.mode = S_IRUGO; in class_dev_create()
717 sfp->attr_hdw_desc.show = hdw_desc_show; in class_dev_create()
718 sfp->attr_hdw_desc.store = NULL; in class_dev_create()
719 ret = device_create_file(sfp->class_dev, in class_dev_create()
720 &sfp->attr_hdw_desc); in class_dev_create()
726 sfp->hdw_desc_created_ok = !0; in class_dev_create()
740 if (!sfp->channel.mc_head->disconnect_flag) return; in pvr2_sysfs_internal_check()
743 pvr2_channel_done(&sfp->channel); in pvr2_sysfs_internal_check()
755 pvr2_channel_init(&sfp->channel,mp); in pvr2_sysfs_create()
756 sfp->channel.check_func = pvr2_sysfs_internal_check; in pvr2_sysfs_create()
777 struct device_attribute *attr, char *buf) in debuginfo_show() argument
781 if (!sfp) return -EINVAL; in debuginfo_show()
782 pvr2_hdw_trigger_module_log(sfp->channel.hdw); in debuginfo_show()
783 return pvr2_debugifc_print_info(sfp->channel.hdw,buf,PAGE_SIZE); in debuginfo_show()
788 struct device_attribute *attr, char *buf) in debugcmd_show() argument
792 if (!sfp) return -EINVAL; in debugcmd_show()
793 return pvr2_debugifc_print_status(sfp->channel.hdw,buf,PAGE_SIZE); in debugcmd_show()
798 struct device_attribute *attr, in debugcmd_store() argument
805 if (!sfp) return -EINVAL; in debugcmd_store()
807 ret = pvr2_debugifc_docmd(sfp->channel.hdw,buf,count); in debugcmd_store()