21 #include <linux/string.h>
22 #include <linux/slab.h>
26 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
30 #define pvr2_sysfs_trace(...) pvr2_trace(PVR2_TRACE_SYSFS,__VA_ARGS__)
35 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
36 struct pvr2_sysfs_debugifc *debugifc;
54 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
55 struct pvr2_sysfs_debugifc {
58 int debugcmd_created_ok;
59 int debuginfo_created_ok;
115 default: name =
"?";
break;
119 if (!name)
return -
EINVAL;
156 unsigned int cnt = 0;
159 if (ret < 0)
return ret;
175 unsigned int cnt = 0;
178 if (ret < 0)
return ret;
194 unsigned int cnt = 0;
197 if (ret < 0)
return ret;
212 unsigned int bcnt,
ccnt, ecnt;
216 for (val = 0; val < ecnt; val++) {
236 unsigned int bcnt, ccnt;
240 for (msk = 1; valid_bits; msk <<= 1) {
241 if (!(msk & valid_bits))
continue;
256 const char *buf,
unsigned int count)
267 if (ret < 0)
return ret;
275 const char *buf,
size_t count)
282 ret = store_val_any(cip, 0, buf, count);
283 if (!ret) ret =
count;
289 const char *buf,
size_t count)
296 ret = store_val_any(cip, 1, buf, count);
297 if (!ret) ret =
count;
305 unsigned int cnt,acnt;
338 cip->
attr_min.attr.name =
"min_val";
343 cip->
attr_max.attr.name =
"max_val";
348 cip->
attr_def.attr.name =
"def_val";
353 cip->
attr_val.attr.name =
"cur_val";
381 cip->
attr_val.store = store_val_norm;
413 "sysfs_create_group error: %d",
420 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
426 const char *,
size_t count);
428 static void pvr2_sysfs_add_debugifc(
struct pvr2_sysfs *sfp)
430 struct pvr2_sysfs_debugifc *dip;
436 dip->attr_debugcmd.attr.name =
"debugcmd";
438 dip->attr_debugcmd.show = debugcmd_show;
439 dip->attr_debugcmd.store = debugcmd_store;
441 dip->attr_debuginfo.attr.name =
"debuginfo";
442 dip->attr_debuginfo.attr.mode =
S_IRUGO;
443 dip->attr_debuginfo.show = debuginfo_show;
448 "device_create_file error: %d",
451 dip->debugcmd_created_ok = !0;
456 "device_create_file error: %d",
459 dip->debuginfo_created_ok = !0;
464 static void pvr2_sysfs_tear_down_debugifc(
struct pvr2_sysfs *sfp)
466 if (!sfp->debugifc)
return;
467 if (sfp->debugifc->debuginfo_created_ok) {
469 &sfp->debugifc->attr_debuginfo);
471 if (sfp->debugifc->debugcmd_created_ok) {
473 &sfp->debugifc->attr_debugcmd);
475 kfree(sfp->debugifc);
476 sfp->debugifc =
NULL;
481 static void pvr2_sysfs_add_controls(
struct pvr2_sysfs *sfp)
485 for (idx = 0; idx <
cnt; idx++) {
486 pvr2_sysfs_add_control(sfp,idx);
491 static void pvr2_sysfs_tear_down_controls(
struct pvr2_sysfs *sfp)
494 for (cip1 = sfp->
item_first; cip1; cip1 = cip2) {
505 static void pvr2_sysfs_class_release(
struct class *
class)
514 static void pvr2_sysfs_release(
struct device *class_dev)
521 static void class_dev_destroy(
struct pvr2_sysfs *sfp)
525 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
526 pvr2_sysfs_tear_down_debugifc(sfp);
528 pvr2_sysfs_tear_down_controls(sfp);
563 static ssize_t v4l_minor_number_show(
struct device *class_dev,
608 static ssize_t v4l_radio_minor_number_show(
struct device *class_dev,
632 static void class_dev_create(
struct pvr2_sysfs *sfp,
635 struct usb_device *usb_dev;
640 if (!usb_dev)
return;
641 class_dev = kzalloc(
sizeof(*class_dev),
GFP_KERNEL);
642 if (!class_dev)
return;
658 "device_register failed");
672 "device_create_file error: %d",
687 "device_create_file error: %d",
701 "device_create_file error: %d",
716 "device_create_file error: %d",
731 "device_create_file error: %d",
738 sfp->
attr_hdw_desc.attr.name =
"device_hardware_description";
746 "device_create_file error: %d",
752 pvr2_sysfs_add_controls(sfp);
753 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
754 pvr2_sysfs_add_debugifc(sfp);
759 static void pvr2_sysfs_internal_check(
struct pvr2_channel *chp)
763 if (!sfp->
channel.mc_head->disconnect_flag)
return;
765 class_dev_destroy(sfp);
776 if (!sfp)
return sfp;
779 sfp->
channel.check_func = pvr2_sysfs_internal_check;
781 class_dev_create(sfp,class_ptr);
791 if (!clp)
return clp;
794 clp->
class.name =
"pvrusb2";
795 clp->
class.class_release = pvr2_sysfs_class_release;
796 clp->
class.dev_release = pvr2_sysfs_release;
799 "Registration failed for pvr2_sysfs_class id=%p",clp);
814 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
838 const char *buf,
size_t count)
847 if (ret < 0)
return ret;