5 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <linux/string.h>
23 #include <linux/slab.h>
24 #include <asm/semaphore.h>
25 #include "pvrusb2-sysfs.h"
26 #include "pvrusb2-hdw.h"
27 #include "pvrusb2-debug.h"
28 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
29 #include "pvrusb2-debugifc.h"
30 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
32 #define pvr2_sysfs_trace(...) pvr2_trace(PVR2_TRACE_SYSFS,__VA_ARGS__)
35 struct pvr2_channel channel;
36 struct class_device *class_dev;
37 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
38 struct pvr2_sysfs_debugifc *debugifc;
39 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
40 struct pvr2_sysfs_ctl_item *item_first;
41 struct pvr2_sysfs_ctl_item *item_last;
42 struct class_device_attribute attr_v4l_minor_number;
43 struct class_device_attribute attr_unit_number;
44 int v4l_minor_number_created_ok;
45 int unit_number_created_ok;
48 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
49 struct pvr2_sysfs_debugifc {
50 struct class_device_attribute attr_debugcmd;
51 struct class_device_attribute attr_debuginfo;
52 int debugcmd_created_ok;
53 int debuginfo_created_ok;
55 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
57 struct pvr2_sysfs_ctl_item {
58 struct class_device_attribute attr_name;
59 struct class_device_attribute attr_type;
60 struct class_device_attribute attr_min;
61 struct class_device_attribute attr_max;
62 struct class_device_attribute attr_enum;
63 struct class_device_attribute attr_bits;
64 struct class_device_attribute attr_val;
65 struct class_device_attribute attr_custom;
66 struct pvr2_ctrl *cptr;
67 struct pvr2_sysfs *chptr;
68 struct pvr2_sysfs_ctl_item *item_next;
69 struct attribute *attr_gen[7];
70 struct attribute_group grp;
75 struct pvr2_sysfs_class {
79 static ssize_t show_name(int id,struct class_device *class_dev,char *buf)
81 struct pvr2_ctrl *cptr;
82 struct pvr2_sysfs *sfp;
85 sfp = (struct pvr2_sysfs *)class_dev->class_data;
86 if (!sfp) return -EINVAL;
87 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
88 if (!cptr) return -EINVAL;
90 name = pvr2_ctrl_get_desc(cptr);
91 pvr2_sysfs_trace("pvr2_sysfs(%p) show_name(cid=%d) is %s",sfp,id,name);
93 if (!name) return -EINVAL;
95 return scnprintf(buf,PAGE_SIZE,"%s\n",name);
98 static ssize_t show_type(int id,struct class_device *class_dev,char *buf)
100 struct pvr2_ctrl *cptr;
101 struct pvr2_sysfs *sfp;
103 enum pvr2_ctl_type tp;
105 sfp = (struct pvr2_sysfs *)class_dev->class_data;
106 if (!sfp) return -EINVAL;
107 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
108 if (!cptr) return -EINVAL;
110 tp = pvr2_ctrl_get_type(cptr);
112 case pvr2_ctl_int: name = "integer"; break;
113 case pvr2_ctl_enum: name = "enum"; break;
114 case pvr2_ctl_bitmask: name = "bitmask"; break;
115 case pvr2_ctl_bool: name = "boolean"; break;
116 default: name = "?"; break;
118 pvr2_sysfs_trace("pvr2_sysfs(%p) show_type(cid=%d) is %s",sfp,id,name);
120 if (!name) return -EINVAL;
122 return scnprintf(buf,PAGE_SIZE,"%s\n",name);
125 static ssize_t show_min(int id,struct class_device *class_dev,char *buf)
127 struct pvr2_ctrl *cptr;
128 struct pvr2_sysfs *sfp;
131 sfp = (struct pvr2_sysfs *)class_dev->class_data;
132 if (!sfp) return -EINVAL;
133 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
134 if (!cptr) return -EINVAL;
135 val = pvr2_ctrl_get_min(cptr);
137 pvr2_sysfs_trace("pvr2_sysfs(%p) show_min(cid=%d) is %ld",sfp,id,val);
139 return scnprintf(buf,PAGE_SIZE,"%ld\n",val);
142 static ssize_t show_max(int id,struct class_device *class_dev,char *buf)
144 struct pvr2_ctrl *cptr;
145 struct pvr2_sysfs *sfp;
148 sfp = (struct pvr2_sysfs *)class_dev->class_data;
149 if (!sfp) return -EINVAL;
150 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
151 if (!cptr) return -EINVAL;
152 val = pvr2_ctrl_get_max(cptr);
154 pvr2_sysfs_trace("pvr2_sysfs(%p) show_max(cid=%d) is %ld",sfp,id,val);
156 return scnprintf(buf,PAGE_SIZE,"%ld\n",val);
159 static ssize_t show_val_norm(int id,struct class_device *class_dev,char *buf)
161 struct pvr2_ctrl *cptr;
162 struct pvr2_sysfs *sfp;
164 unsigned int cnt = 0;
166 sfp = (struct pvr2_sysfs *)class_dev->class_data;
167 if (!sfp) return -EINVAL;
168 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
169 if (!cptr) return -EINVAL;
171 ret = pvr2_ctrl_get_value(cptr,&val);
172 if (ret < 0) return ret;
174 ret = pvr2_ctrl_value_to_sym(cptr,~0,val,
175 buf,PAGE_SIZE-1,&cnt);
177 pvr2_sysfs_trace("pvr2_sysfs(%p) show_val_norm(cid=%d) is %.*s (%d)",
183 static ssize_t show_val_custom(int id,struct class_device *class_dev,char *buf)
185 struct pvr2_ctrl *cptr;
186 struct pvr2_sysfs *sfp;
188 unsigned int cnt = 0;
190 sfp = (struct pvr2_sysfs *)class_dev->class_data;
191 if (!sfp) return -EINVAL;
192 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
193 if (!cptr) return -EINVAL;
195 ret = pvr2_ctrl_get_value(cptr,&val);
196 if (ret < 0) return ret;
198 ret = pvr2_ctrl_custom_value_to_sym(cptr,~0,val,
199 buf,PAGE_SIZE-1,&cnt);
201 pvr2_sysfs_trace("pvr2_sysfs(%p) show_val_custom(cid=%d) is %.*s (%d)",
207 static ssize_t show_enum(int id,struct class_device *class_dev,char *buf)
209 struct pvr2_ctrl *cptr;
210 struct pvr2_sysfs *sfp;
212 unsigned int bcnt,ccnt,ecnt;
214 sfp = (struct pvr2_sysfs *)class_dev->class_data;
215 if (!sfp) return -EINVAL;
216 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
217 if (!cptr) return -EINVAL;
218 ecnt = pvr2_ctrl_get_cnt(cptr);
220 for (val = 0; val < ecnt; val++) {
221 pvr2_ctrl_get_valname(cptr,val,buf+bcnt,PAGE_SIZE-bcnt,&ccnt);
224 if (bcnt >= PAGE_SIZE) break;
228 pvr2_sysfs_trace("pvr2_sysfs(%p) show_enum(cid=%d)",sfp,id);
232 static ssize_t show_bits(int id,struct class_device *class_dev,char *buf)
234 struct pvr2_ctrl *cptr;
235 struct pvr2_sysfs *sfp;
237 unsigned int bcnt,ccnt;
239 sfp = (struct pvr2_sysfs *)class_dev->class_data;
240 if (!sfp) return -EINVAL;
241 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
242 if (!cptr) return -EINVAL;
243 valid_bits = pvr2_ctrl_get_mask(cptr);
245 for (msk = 1; valid_bits; msk <<= 1) {
246 if (!(msk & valid_bits)) continue;
248 pvr2_ctrl_get_valname(cptr,msk,buf+bcnt,PAGE_SIZE-bcnt,&ccnt);
250 if (bcnt >= PAGE_SIZE) break;
254 pvr2_sysfs_trace("pvr2_sysfs(%p) show_bits(cid=%d)",sfp,id);
258 static int store_val_any(int id,int customfl,struct pvr2_sysfs *sfp,
259 const char *buf,unsigned int count)
261 struct pvr2_ctrl *cptr;
265 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
267 ret = pvr2_ctrl_custom_sym_to_value(cptr,buf,count,&mask,&val);
269 ret = pvr2_ctrl_sym_to_value(cptr,buf,count,&mask,&val);
271 if (ret < 0) return ret;
272 ret = pvr2_ctrl_set_mask_value(cptr,mask,val);
273 pvr2_hdw_commit_ctl(sfp->channel.hdw);
277 static ssize_t store_val_norm(int id,struct class_device *class_dev,
278 const char *buf,size_t count)
280 struct pvr2_sysfs *sfp;
282 sfp = (struct pvr2_sysfs *)class_dev->class_data;
283 ret = store_val_any(id,0,sfp,buf,count);
284 if (!ret) ret = count;
288 static ssize_t store_val_custom(int id,struct class_device *class_dev,
289 const char *buf,size_t count)
291 struct pvr2_sysfs *sfp;
293 sfp = (struct pvr2_sysfs *)class_dev->class_data;
294 ret = store_val_any(id,1,sfp,buf,count);
295 if (!ret) ret = count;
300 Mike Isely <isely@pobox.com> 30-April-2005
302 This next batch of horrible preprocessor hackery is needed because the
303 kernel's class_device_attribute mechanism fails to pass the actual
304 attribute through to the show / store functions, which means we have no
305 way to package up any attribute-specific parameters, like for example the
306 control id. So we work around this brain-damage by encoding the control
307 id into the show / store functions themselves and pick the function based
308 on the control id we're setting up. These macros try to ease the pain.
312 #define CREATE_SHOW_INSTANCE(sf_name,ctl_id) \
313 static ssize_t sf_name##_##ctl_id(struct class_device *class_dev,char *buf) \
314 { return sf_name(ctl_id,class_dev,buf); }
316 #define CREATE_STORE_INSTANCE(sf_name,ctl_id) \
317 static ssize_t sf_name##_##ctl_id(struct class_device *class_dev,const char *buf,size_t count) \
318 { return sf_name(ctl_id,class_dev,buf,count); }
320 #define CREATE_BATCH(ctl_id) \
321 CREATE_SHOW_INSTANCE(show_name,ctl_id) \
322 CREATE_SHOW_INSTANCE(show_type,ctl_id) \
323 CREATE_SHOW_INSTANCE(show_min,ctl_id) \
324 CREATE_SHOW_INSTANCE(show_max,ctl_id) \
325 CREATE_SHOW_INSTANCE(show_val_norm,ctl_id) \
326 CREATE_SHOW_INSTANCE(show_val_custom,ctl_id) \
327 CREATE_SHOW_INSTANCE(show_enum,ctl_id) \
328 CREATE_SHOW_INSTANCE(show_bits,ctl_id) \
329 CREATE_STORE_INSTANCE(store_val_norm,ctl_id) \
330 CREATE_STORE_INSTANCE(store_val_custom,ctl_id) \
393 struct pvr2_sysfs_func_set {
394 ssize_t (*show_name)(struct class_device *,char *);
395 ssize_t (*show_type)(struct class_device *,char *);
396 ssize_t (*show_min)(struct class_device *,char *);
397 ssize_t (*show_max)(struct class_device *,char *);
398 ssize_t (*show_enum)(struct class_device *,char *);
399 ssize_t (*show_bits)(struct class_device *,char *);
400 ssize_t (*show_val_norm)(struct class_device *,char *);
401 ssize_t (*store_val_norm)(struct class_device *,
402 const char *,size_t);
403 ssize_t (*show_val_custom)(struct class_device *,char *);
404 ssize_t (*store_val_custom)(struct class_device *,
405 const char *,size_t);
408 #define INIT_BATCH(ctl_id) \
410 .show_name = show_name_##ctl_id, \
411 .show_type = show_type_##ctl_id, \
412 .show_min = show_min_##ctl_id, \
413 .show_max = show_max_##ctl_id, \
414 .show_enum = show_enum_##ctl_id, \
415 .show_bits = show_bits_##ctl_id, \
416 .show_val_norm = show_val_norm_##ctl_id, \
417 .store_val_norm = store_val_norm_##ctl_id, \
418 .show_val_custom = show_val_custom_##ctl_id, \
419 .store_val_custom = store_val_custom_##ctl_id, \
422 static struct pvr2_sysfs_func_set funcs[] = {
486 static void pvr2_sysfs_add_control(struct pvr2_sysfs *sfp,int ctl_id)
488 struct pvr2_sysfs_ctl_item *cip;
489 struct pvr2_sysfs_func_set *fp;
490 struct pvr2_ctrl *cptr;
491 unsigned int cnt,acnt;
494 if ((ctl_id < 0) || (ctl_id >= (sizeof(funcs)/sizeof(funcs[0])))) {
499 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,ctl_id);
502 cip = kmalloc(sizeof(*cip),GFP_KERNEL);
504 memset(cip,0,sizeof(*cip));
505 pvr2_sysfs_trace("Creating pvr2_sysfs_ctl_item id=%p",cip);
510 cip->item_next = NULL;
511 if (sfp->item_last) {
512 sfp->item_last->item_next = cip;
514 sfp->item_first = cip;
516 sfp->item_last = cip;
518 cip->attr_name.attr.owner = THIS_MODULE;
519 cip->attr_name.attr.name = "name";
520 cip->attr_name.attr.mode = S_IRUGO;
521 cip->attr_name.show = fp->show_name;
523 cip->attr_type.attr.owner = THIS_MODULE;
524 cip->attr_type.attr.name = "type";
525 cip->attr_type.attr.mode = S_IRUGO;
526 cip->attr_type.show = fp->show_type;
528 cip->attr_min.attr.owner = THIS_MODULE;
529 cip->attr_min.attr.name = "min_val";
530 cip->attr_min.attr.mode = S_IRUGO;
531 cip->attr_min.show = fp->show_min;
533 cip->attr_max.attr.owner = THIS_MODULE;
534 cip->attr_max.attr.name = "max_val";
535 cip->attr_max.attr.mode = S_IRUGO;
536 cip->attr_max.show = fp->show_max;
538 cip->attr_val.attr.owner = THIS_MODULE;
539 cip->attr_val.attr.name = "cur_val";
540 cip->attr_val.attr.mode = S_IRUGO;
542 cip->attr_custom.attr.owner = THIS_MODULE;
543 cip->attr_custom.attr.name = "custom_val";
544 cip->attr_custom.attr.mode = S_IRUGO;
546 cip->attr_enum.attr.owner = THIS_MODULE;
547 cip->attr_enum.attr.name = "enum_val";
548 cip->attr_enum.attr.mode = S_IRUGO;
549 cip->attr_enum.show = fp->show_enum;
551 cip->attr_bits.attr.owner = THIS_MODULE;
552 cip->attr_bits.attr.name = "bit_val";
553 cip->attr_bits.attr.mode = S_IRUGO;
554 cip->attr_bits.show = fp->show_bits;
556 if (pvr2_ctrl_is_writable(cptr)) {
557 cip->attr_val.attr.mode |= S_IWUSR|S_IWGRP;
558 cip->attr_custom.attr.mode |= S_IWUSR|S_IWGRP;
562 cip->attr_gen[acnt++] = &cip->attr_name.attr;
563 cip->attr_gen[acnt++] = &cip->attr_type.attr;
564 cip->attr_gen[acnt++] = &cip->attr_val.attr;
565 cip->attr_val.show = fp->show_val_norm;
566 cip->attr_val.store = fp->store_val_norm;
567 if (pvr2_ctrl_has_custom_symbols(cptr)) {
568 cip->attr_gen[acnt++] = &cip->attr_custom.attr;
569 cip->attr_custom.show = fp->show_val_custom;
570 cip->attr_custom.store = fp->store_val_custom;
572 switch (pvr2_ctrl_get_type(cptr)) {
574 // Control is an enumeration
575 cip->attr_gen[acnt++] = &cip->attr_enum.attr;
578 // Control is an integer
579 cip->attr_gen[acnt++] = &cip->attr_min.attr;
580 cip->attr_gen[acnt++] = &cip->attr_max.attr;
582 case pvr2_ctl_bitmask:
583 // Control is an bitmask
584 cip->attr_gen[acnt++] = &cip->attr_bits.attr;
589 cnt = scnprintf(cip->name,sizeof(cip->name)-1,"ctl_%s",
590 pvr2_ctrl_get_name(cptr));
592 cip->grp.name = cip->name;
593 cip->grp.attrs = cip->attr_gen;
595 ret = sysfs_create_group(&sfp->class_dev->kobj,&cip->grp);
597 printk(KERN_WARNING "%s: sysfs_create_group error: %d\n",
601 cip->created_ok = !0;
604 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
605 static ssize_t debuginfo_show(struct class_device *,char *);
606 static ssize_t debugcmd_show(struct class_device *,char *);
607 static ssize_t debugcmd_store(struct class_device *,const char *,size_t count);
609 static void pvr2_sysfs_add_debugifc(struct pvr2_sysfs *sfp)
611 struct pvr2_sysfs_debugifc *dip;
614 dip = kmalloc(sizeof(*dip),GFP_KERNEL);
616 memset(dip,0,sizeof(*dip));
617 dip->attr_debugcmd.attr.owner = THIS_MODULE;
618 dip->attr_debugcmd.attr.name = "debugcmd";
619 dip->attr_debugcmd.attr.mode = S_IRUGO|S_IWUSR|S_IWGRP;
620 dip->attr_debugcmd.show = debugcmd_show;
621 dip->attr_debugcmd.store = debugcmd_store;
622 dip->attr_debuginfo.attr.owner = THIS_MODULE;
623 dip->attr_debuginfo.attr.name = "debuginfo";
624 dip->attr_debuginfo.attr.mode = S_IRUGO;
625 dip->attr_debuginfo.show = debuginfo_show;
627 ret = class_device_create_file(sfp->class_dev,&dip->attr_debugcmd);
629 printk(KERN_WARNING "%s: class_device_create_file error: %d\n",
632 dip->debugcmd_created_ok = !0;
634 ret = class_device_create_file(sfp->class_dev,&dip->attr_debuginfo);
636 printk(KERN_WARNING "%s: class_device_create_file error: %d\n",
639 dip->debuginfo_created_ok = !0;
644 static void pvr2_sysfs_tear_down_debugifc(struct pvr2_sysfs *sfp)
646 if (!sfp->debugifc) return;
647 if (sfp->debugifc->debuginfo_created_ok) {
648 class_device_remove_file(sfp->class_dev,
649 &sfp->debugifc->attr_debuginfo);
651 if (sfp->debugifc->debugcmd_created_ok) {
652 class_device_remove_file(sfp->class_dev,
653 &sfp->debugifc->attr_debugcmd);
655 kfree(sfp->debugifc);
656 sfp->debugifc = NULL;
658 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
661 static void pvr2_sysfs_add_controls(struct pvr2_sysfs *sfp)
663 unsigned int idx,cnt;
664 cnt = pvr2_hdw_get_ctrl_count(sfp->channel.hdw);
665 for (idx = 0; idx < cnt; idx++) {
666 pvr2_sysfs_add_control(sfp,idx);
671 static void pvr2_sysfs_tear_down_controls(struct pvr2_sysfs *sfp)
673 struct pvr2_sysfs_ctl_item *cip1,*cip2;
674 for (cip1 = sfp->item_first; cip1; cip1 = cip2) {
675 cip2 = cip1->item_next;
676 if (cip1->created_ok) {
677 sysfs_remove_group(&sfp->class_dev->kobj,&cip1->grp);
679 pvr2_sysfs_trace("Destroying pvr2_sysfs_ctl_item id=%p",cip1);
685 static void pvr2_sysfs_class_release(struct class *class)
687 struct pvr2_sysfs_class *clp;
688 clp = container_of(class,struct pvr2_sysfs_class,class);
689 pvr2_sysfs_trace("Destroying pvr2_sysfs_class id=%p",clp);
694 static void pvr2_sysfs_release(struct class_device *class_dev)
696 pvr2_sysfs_trace("Releasing class_dev id=%p",class_dev);
701 static void class_dev_destroy(struct pvr2_sysfs *sfp)
703 if (!sfp->class_dev) return;
704 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
705 pvr2_sysfs_tear_down_debugifc(sfp);
706 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
707 pvr2_sysfs_tear_down_controls(sfp);
708 if (sfp->v4l_minor_number_created_ok) {
709 class_device_remove_file(sfp->class_dev,
710 &sfp->attr_v4l_minor_number);
712 if (sfp->unit_number_created_ok) {
713 class_device_remove_file(sfp->class_dev,
714 &sfp->attr_unit_number);
716 pvr2_sysfs_trace("Destroying class_dev id=%p",sfp->class_dev);
717 sfp->class_dev->class_data = NULL;
718 class_device_unregister(sfp->class_dev);
719 sfp->class_dev = NULL;
723 static ssize_t v4l_minor_number_show(struct class_device *class_dev,char *buf)
725 struct pvr2_sysfs *sfp;
726 sfp = (struct pvr2_sysfs *)class_dev->class_data;
727 if (!sfp) return -EINVAL;
728 return scnprintf(buf,PAGE_SIZE,"%d\n",
729 pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw));
733 static ssize_t unit_number_show(struct class_device *class_dev,char *buf)
735 struct pvr2_sysfs *sfp;
736 sfp = (struct pvr2_sysfs *)class_dev->class_data;
737 if (!sfp) return -EINVAL;
738 return scnprintf(buf,PAGE_SIZE,"%d\n",
739 pvr2_hdw_get_unit_number(sfp->channel.hdw));
743 static void class_dev_create(struct pvr2_sysfs *sfp,
744 struct pvr2_sysfs_class *class_ptr)
746 struct usb_device *usb_dev;
747 struct class_device *class_dev;
750 usb_dev = pvr2_hdw_get_dev(sfp->channel.hdw);
751 if (!usb_dev) return;
752 class_dev = kmalloc(sizeof(*class_dev),GFP_KERNEL);
753 if (!class_dev) return;
754 memset(class_dev,0,sizeof(*class_dev));
756 pvr2_sysfs_trace("Creating class_dev id=%p",class_dev);
758 class_dev->class = &class_ptr->class;
759 if (pvr2_hdw_get_sn(sfp->channel.hdw)) {
760 snprintf(class_dev->class_id,BUS_ID_SIZE,"sn-%lu",
761 pvr2_hdw_get_sn(sfp->channel.hdw));
762 } else if (pvr2_hdw_get_unit_number(sfp->channel.hdw) >= 0) {
763 snprintf(class_dev->class_id,BUS_ID_SIZE,"unit-%c",
764 pvr2_hdw_get_unit_number(sfp->channel.hdw) + 'a');
770 class_dev->dev = &usb_dev->dev;
772 sfp->class_dev = class_dev;
773 class_dev->class_data = sfp;
774 ret = class_device_register(class_dev);
776 printk(KERN_ERR "%s: class_device_register failed\n",
782 sfp->attr_v4l_minor_number.attr.owner = THIS_MODULE;
783 sfp->attr_v4l_minor_number.attr.name = "v4l_minor_number";
784 sfp->attr_v4l_minor_number.attr.mode = S_IRUGO;
785 sfp->attr_v4l_minor_number.show = v4l_minor_number_show;
786 sfp->attr_v4l_minor_number.store = NULL;
787 ret = class_device_create_file(sfp->class_dev,
788 &sfp->attr_v4l_minor_number);
790 printk(KERN_WARNING "%s: class_device_create_file error: %d\n",
793 sfp->v4l_minor_number_created_ok = !0;
796 sfp->attr_unit_number.attr.owner = THIS_MODULE;
797 sfp->attr_unit_number.attr.name = "unit_number";
798 sfp->attr_unit_number.attr.mode = S_IRUGO;
799 sfp->attr_unit_number.show = unit_number_show;
800 sfp->attr_unit_number.store = NULL;
801 ret = class_device_create_file(sfp->class_dev,&sfp->attr_unit_number);
803 printk(KERN_WARNING "%s: class_device_create_file error: %d\n",
806 sfp->unit_number_created_ok = !0;
809 pvr2_sysfs_add_controls(sfp);
810 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
811 pvr2_sysfs_add_debugifc(sfp);
812 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
816 static void pvr2_sysfs_internal_check(struct pvr2_channel *chp)
818 struct pvr2_sysfs *sfp;
819 sfp = container_of(chp,struct pvr2_sysfs,channel);
820 if (!sfp->channel.mc_head->disconnect_flag) return;
821 pvr2_trace(PVR2_TRACE_STRUCT,"Destroying pvr2_sysfs id=%p",sfp);
822 class_dev_destroy(sfp);
823 pvr2_channel_done(&sfp->channel);
828 struct pvr2_sysfs *pvr2_sysfs_create(struct pvr2_context *mp,
829 struct pvr2_sysfs_class *class_ptr)
831 struct pvr2_sysfs *sfp;
832 sfp = kmalloc(sizeof(*sfp),GFP_KERNEL);
833 if (!sfp) return sfp;
834 memset(sfp,0,sizeof(*sfp));
835 pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr2_sysfs id=%p",sfp);
836 pvr2_channel_init(&sfp->channel,mp);
837 sfp->channel.check_func = pvr2_sysfs_internal_check;
839 class_dev_create(sfp,class_ptr);
844 static int pvr2_sysfs_hotplug(struct class_device *cd,char **envp,
845 int numenvp,char *buf,int size)
847 /* Even though we don't do anything here, we still need this function
848 because sysfs will still try to call it. */
852 struct pvr2_sysfs_class *pvr2_sysfs_class_create(void)
854 struct pvr2_sysfs_class *clp;
855 clp = kmalloc(sizeof(*clp),GFP_KERNEL);
856 if (!clp) return clp;
857 memset(clp,0,sizeof(*clp));
858 pvr2_sysfs_trace("Creating pvr2_sysfs_class id=%p",clp);
859 clp->class.name = "pvrusb2";
860 clp->class.class_release = pvr2_sysfs_class_release;
861 clp->class.release = pvr2_sysfs_release;
862 clp->class.uevent = pvr2_sysfs_hotplug;
863 if (class_register(&clp->class)) {
865 "Registration failed for pvr2_sysfs_class id=%p",clp);
873 void pvr2_sysfs_class_destroy(struct pvr2_sysfs_class *clp)
875 class_unregister(&clp->class);
879 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
880 static ssize_t debuginfo_show(struct class_device *class_dev,char *buf)
882 struct pvr2_sysfs *sfp;
883 sfp = (struct pvr2_sysfs *)class_dev->class_data;
884 if (!sfp) return -EINVAL;
885 pvr2_hdw_trigger_module_log(sfp->channel.hdw);
886 return pvr2_debugifc_print_info(sfp->channel.hdw,buf,PAGE_SIZE);
890 static ssize_t debugcmd_show(struct class_device *class_dev,char *buf)
892 struct pvr2_sysfs *sfp;
893 sfp = (struct pvr2_sysfs *)class_dev->class_data;
894 if (!sfp) return -EINVAL;
895 return pvr2_debugifc_print_status(sfp->channel.hdw,buf,PAGE_SIZE);
899 static ssize_t debugcmd_store(struct class_device *class_dev,
900 const char *buf,size_t count)
902 struct pvr2_sysfs *sfp;
905 sfp = (struct pvr2_sysfs *)class_dev->class_data;
906 if (!sfp) return -EINVAL;
908 ret = pvr2_debugifc_docmd(sfp->channel.hdw,buf,count);
909 if (ret < 0) return ret;
912 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
916 Stuff for Emacs to see, in order to encourage consistent editing style:
917 *** Local Variables: ***
919 *** fill-column: 75 ***
921 *** c-basic-offset: 8 ***