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 sysfs_ops kops;
43 struct kobj_type ktype;
44 struct class_device_attribute attr_v4l_minor_number;
45 struct class_device_attribute attr_unit_number;
46 int v4l_minor_number_created_ok;
47 int unit_number_created_ok;
50 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
51 struct pvr2_sysfs_debugifc {
52 struct class_device_attribute attr_debugcmd;
53 struct class_device_attribute attr_debuginfo;
54 int debugcmd_created_ok;
55 int debuginfo_created_ok;
57 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
59 struct pvr2_sysfs_ctl_item {
60 struct class_device_attribute attr_name;
61 struct class_device_attribute attr_type;
62 struct class_device_attribute attr_min;
63 struct class_device_attribute attr_max;
64 struct class_device_attribute attr_enum;
65 struct class_device_attribute attr_bits;
66 struct class_device_attribute attr_val;
67 struct class_device_attribute attr_custom;
68 struct pvr2_ctrl *cptr;
69 struct pvr2_sysfs *chptr;
70 struct pvr2_sysfs_ctl_item *item_next;
71 struct attribute *attr_gen[7];
72 struct attribute_group grp;
77 struct pvr2_sysfs_class {
81 static ssize_t show_name(int id,struct class_device *class_dev,char *buf)
83 struct pvr2_ctrl *cptr;
84 struct pvr2_sysfs *sfp;
87 sfp = (struct pvr2_sysfs *)class_dev->class_data;
88 if (!sfp) return -EINVAL;
89 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
90 if (!cptr) return -EINVAL;
92 name = pvr2_ctrl_get_desc(cptr);
93 pvr2_sysfs_trace("pvr2_sysfs(%p) show_name(cid=%d) is %s",sfp,id,name);
95 if (!name) return -EINVAL;
97 return scnprintf(buf,PAGE_SIZE,"%s\n",name);
100 static ssize_t show_type(int id,struct class_device *class_dev,char *buf)
102 struct pvr2_ctrl *cptr;
103 struct pvr2_sysfs *sfp;
105 enum pvr2_ctl_type tp;
107 sfp = (struct pvr2_sysfs *)class_dev->class_data;
108 if (!sfp) return -EINVAL;
109 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
110 if (!cptr) return -EINVAL;
112 tp = pvr2_ctrl_get_type(cptr);
114 case pvr2_ctl_int: name = "integer"; break;
115 case pvr2_ctl_enum: name = "enum"; break;
116 case pvr2_ctl_bitmask: name = "bitmask"; break;
117 case pvr2_ctl_bool: name = "boolean"; break;
118 default: name = "?"; break;
120 pvr2_sysfs_trace("pvr2_sysfs(%p) show_type(cid=%d) is %s",sfp,id,name);
122 if (!name) return -EINVAL;
124 return scnprintf(buf,PAGE_SIZE,"%s\n",name);
127 static ssize_t show_min(int id,struct class_device *class_dev,char *buf)
129 struct pvr2_ctrl *cptr;
130 struct pvr2_sysfs *sfp;
133 sfp = (struct pvr2_sysfs *)class_dev->class_data;
134 if (!sfp) return -EINVAL;
135 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
136 if (!cptr) return -EINVAL;
137 val = pvr2_ctrl_get_min(cptr);
139 pvr2_sysfs_trace("pvr2_sysfs(%p) show_min(cid=%d) is %ld",sfp,id,val);
141 return scnprintf(buf,PAGE_SIZE,"%ld\n",val);
144 static ssize_t show_max(int id,struct class_device *class_dev,char *buf)
146 struct pvr2_ctrl *cptr;
147 struct pvr2_sysfs *sfp;
150 sfp = (struct pvr2_sysfs *)class_dev->class_data;
151 if (!sfp) return -EINVAL;
152 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
153 if (!cptr) return -EINVAL;
154 val = pvr2_ctrl_get_max(cptr);
156 pvr2_sysfs_trace("pvr2_sysfs(%p) show_max(cid=%d) is %ld",sfp,id,val);
158 return scnprintf(buf,PAGE_SIZE,"%ld\n",val);
161 static ssize_t show_val_norm(int id,struct class_device *class_dev,char *buf)
163 struct pvr2_ctrl *cptr;
164 struct pvr2_sysfs *sfp;
166 unsigned int cnt = 0;
168 sfp = (struct pvr2_sysfs *)class_dev->class_data;
169 if (!sfp) return -EINVAL;
170 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
171 if (!cptr) return -EINVAL;
173 ret = pvr2_ctrl_get_value(cptr,&val);
174 if (ret < 0) return ret;
176 ret = pvr2_ctrl_value_to_sym(cptr,~0,val,
177 buf,PAGE_SIZE-1,&cnt);
179 pvr2_sysfs_trace("pvr2_sysfs(%p) show_val_norm(cid=%d) is %.*s (%d)",
185 static ssize_t show_val_custom(int id,struct class_device *class_dev,char *buf)
187 struct pvr2_ctrl *cptr;
188 struct pvr2_sysfs *sfp;
190 unsigned int cnt = 0;
192 sfp = (struct pvr2_sysfs *)class_dev->class_data;
193 if (!sfp) return -EINVAL;
194 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
195 if (!cptr) return -EINVAL;
197 ret = pvr2_ctrl_get_value(cptr,&val);
198 if (ret < 0) return ret;
200 ret = pvr2_ctrl_custom_value_to_sym(cptr,~0,val,
201 buf,PAGE_SIZE-1,&cnt);
203 pvr2_sysfs_trace("pvr2_sysfs(%p) show_val_custom(cid=%d) is %.*s (%d)",
209 static ssize_t show_enum(int id,struct class_device *class_dev,char *buf)
211 struct pvr2_ctrl *cptr;
212 struct pvr2_sysfs *sfp;
214 unsigned int bcnt,ccnt,ecnt;
216 sfp = (struct pvr2_sysfs *)class_dev->class_data;
217 if (!sfp) return -EINVAL;
218 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
219 if (!cptr) return -EINVAL;
220 ecnt = pvr2_ctrl_get_cnt(cptr);
222 for (val = 0; val < ecnt; val++) {
223 pvr2_ctrl_get_valname(cptr,val,buf+bcnt,PAGE_SIZE-bcnt,&ccnt);
226 if (bcnt >= PAGE_SIZE) break;
230 pvr2_sysfs_trace("pvr2_sysfs(%p) show_enum(cid=%d)",sfp,id);
234 static ssize_t show_bits(int id,struct class_device *class_dev,char *buf)
236 struct pvr2_ctrl *cptr;
237 struct pvr2_sysfs *sfp;
239 unsigned int bcnt,ccnt;
241 sfp = (struct pvr2_sysfs *)class_dev->class_data;
242 if (!sfp) return -EINVAL;
243 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
244 if (!cptr) return -EINVAL;
245 valid_bits = pvr2_ctrl_get_mask(cptr);
247 for (msk = 1; valid_bits; msk <<= 1) {
248 if (!(msk & valid_bits)) continue;
250 pvr2_ctrl_get_valname(cptr,msk,buf+bcnt,PAGE_SIZE-bcnt,&ccnt);
252 if (bcnt >= PAGE_SIZE) break;
256 pvr2_sysfs_trace("pvr2_sysfs(%p) show_bits(cid=%d)",sfp,id);
260 static int store_val_any(int id,int customfl,struct pvr2_sysfs *sfp,
261 const char *buf,unsigned int count)
263 struct pvr2_ctrl *cptr;
267 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
269 ret = pvr2_ctrl_custom_sym_to_value(cptr,buf,count,&mask,&val);
271 ret = pvr2_ctrl_sym_to_value(cptr,buf,count,&mask,&val);
273 if (ret < 0) return ret;
274 ret = pvr2_ctrl_set_mask_value(cptr,mask,val);
275 pvr2_hdw_commit_ctl(sfp->channel.hdw);
279 static ssize_t store_val_norm(int id,struct class_device *class_dev,
280 const char *buf,size_t count)
282 struct pvr2_sysfs *sfp;
284 sfp = (struct pvr2_sysfs *)class_dev->class_data;
285 ret = store_val_any(id,0,sfp,buf,count);
286 if (!ret) ret = count;
290 static ssize_t store_val_custom(int id,struct class_device *class_dev,
291 const char *buf,size_t count)
293 struct pvr2_sysfs *sfp;
295 sfp = (struct pvr2_sysfs *)class_dev->class_data;
296 ret = store_val_any(id,1,sfp,buf,count);
297 if (!ret) ret = count;
302 Mike Isely <isely@pobox.com> 30-April-2005
304 This next batch of horrible preprocessor hackery is needed because the
305 kernel's class_device_attribute mechanism fails to pass the actual
306 attribute through to the show / store functions, which means we have no
307 way to package up any attribute-specific parameters, like for example the
308 control id. So we work around this brain-damage by encoding the control
309 id into the show / store functions themselves and pick the function based
310 on the control id we're setting up. These macros try to ease the pain.
314 #define CREATE_SHOW_INSTANCE(sf_name,ctl_id) \
315 static ssize_t sf_name##_##ctl_id(struct class_device *class_dev,char *buf) \
316 { return sf_name(ctl_id,class_dev,buf); }
318 #define CREATE_STORE_INSTANCE(sf_name,ctl_id) \
319 static ssize_t sf_name##_##ctl_id(struct class_device *class_dev,const char *buf,size_t count) \
320 { return sf_name(ctl_id,class_dev,buf,count); }
322 #define CREATE_BATCH(ctl_id) \
323 CREATE_SHOW_INSTANCE(show_name,ctl_id) \
324 CREATE_SHOW_INSTANCE(show_type,ctl_id) \
325 CREATE_SHOW_INSTANCE(show_min,ctl_id) \
326 CREATE_SHOW_INSTANCE(show_max,ctl_id) \
327 CREATE_SHOW_INSTANCE(show_val_norm,ctl_id) \
328 CREATE_SHOW_INSTANCE(show_val_custom,ctl_id) \
329 CREATE_SHOW_INSTANCE(show_enum,ctl_id) \
330 CREATE_SHOW_INSTANCE(show_bits,ctl_id) \
331 CREATE_STORE_INSTANCE(store_val_norm,ctl_id) \
332 CREATE_STORE_INSTANCE(store_val_custom,ctl_id) \
395 struct pvr2_sysfs_func_set {
396 ssize_t (*show_name)(struct class_device *,char *);
397 ssize_t (*show_type)(struct class_device *,char *);
398 ssize_t (*show_min)(struct class_device *,char *);
399 ssize_t (*show_max)(struct class_device *,char *);
400 ssize_t (*show_enum)(struct class_device *,char *);
401 ssize_t (*show_bits)(struct class_device *,char *);
402 ssize_t (*show_val_norm)(struct class_device *,char *);
403 ssize_t (*store_val_norm)(struct class_device *,
404 const char *,size_t);
405 ssize_t (*show_val_custom)(struct class_device *,char *);
406 ssize_t (*store_val_custom)(struct class_device *,
407 const char *,size_t);
410 #define INIT_BATCH(ctl_id) \
412 .show_name = show_name_##ctl_id, \
413 .show_type = show_type_##ctl_id, \
414 .show_min = show_min_##ctl_id, \
415 .show_max = show_max_##ctl_id, \
416 .show_enum = show_enum_##ctl_id, \
417 .show_bits = show_bits_##ctl_id, \
418 .show_val_norm = show_val_norm_##ctl_id, \
419 .store_val_norm = store_val_norm_##ctl_id, \
420 .show_val_custom = show_val_custom_##ctl_id, \
421 .store_val_custom = store_val_custom_##ctl_id, \
424 static struct pvr2_sysfs_func_set funcs[] = {
488 static void pvr2_sysfs_add_control(struct pvr2_sysfs *sfp,int ctl_id)
490 struct pvr2_sysfs_ctl_item *cip;
491 struct pvr2_sysfs_func_set *fp;
492 struct pvr2_ctrl *cptr;
493 unsigned int cnt,acnt;
496 if ((ctl_id < 0) || (ctl_id >= (sizeof(funcs)/sizeof(funcs[0])))) {
501 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,ctl_id);
504 cip = kmalloc(sizeof(*cip),GFP_KERNEL);
506 memset(cip,0,sizeof(*cip));
507 pvr2_sysfs_trace("Creating pvr2_sysfs_ctl_item id=%p",cip);
512 cip->item_next = NULL;
513 if (sfp->item_last) {
514 sfp->item_last->item_next = cip;
516 sfp->item_first = cip;
518 sfp->item_last = cip;
520 cip->attr_name.attr.owner = THIS_MODULE;
521 cip->attr_name.attr.name = "name";
522 cip->attr_name.attr.mode = S_IRUGO;
523 cip->attr_name.show = fp->show_name;
525 cip->attr_type.attr.owner = THIS_MODULE;
526 cip->attr_type.attr.name = "type";
527 cip->attr_type.attr.mode = S_IRUGO;
528 cip->attr_type.show = fp->show_type;
530 cip->attr_min.attr.owner = THIS_MODULE;
531 cip->attr_min.attr.name = "min_val";
532 cip->attr_min.attr.mode = S_IRUGO;
533 cip->attr_min.show = fp->show_min;
535 cip->attr_max.attr.owner = THIS_MODULE;
536 cip->attr_max.attr.name = "max_val";
537 cip->attr_max.attr.mode = S_IRUGO;
538 cip->attr_max.show = fp->show_max;
540 cip->attr_val.attr.owner = THIS_MODULE;
541 cip->attr_val.attr.name = "cur_val";
542 cip->attr_val.attr.mode = S_IRUGO;
544 cip->attr_custom.attr.owner = THIS_MODULE;
545 cip->attr_custom.attr.name = "custom_val";
546 cip->attr_custom.attr.mode = S_IRUGO;
548 cip->attr_enum.attr.owner = THIS_MODULE;
549 cip->attr_enum.attr.name = "enum_val";
550 cip->attr_enum.attr.mode = S_IRUGO;
551 cip->attr_enum.show = fp->show_enum;
553 cip->attr_bits.attr.owner = THIS_MODULE;
554 cip->attr_bits.attr.name = "bit_val";
555 cip->attr_bits.attr.mode = S_IRUGO;
556 cip->attr_bits.show = fp->show_bits;
558 if (pvr2_ctrl_is_writable(cptr)) {
559 cip->attr_val.attr.mode |= S_IWUSR|S_IWGRP;
560 cip->attr_custom.attr.mode |= S_IWUSR|S_IWGRP;
564 cip->attr_gen[acnt++] = &cip->attr_name.attr;
565 cip->attr_gen[acnt++] = &cip->attr_type.attr;
566 cip->attr_gen[acnt++] = &cip->attr_val.attr;
567 cip->attr_val.show = fp->show_val_norm;
568 cip->attr_val.store = fp->store_val_norm;
569 if (pvr2_ctrl_has_custom_symbols(cptr)) {
570 cip->attr_gen[acnt++] = &cip->attr_custom.attr;
571 cip->attr_custom.show = fp->show_val_custom;
572 cip->attr_custom.store = fp->store_val_custom;
574 switch (pvr2_ctrl_get_type(cptr)) {
576 // Control is an enumeration
577 cip->attr_gen[acnt++] = &cip->attr_enum.attr;
580 // Control is an integer
581 cip->attr_gen[acnt++] = &cip->attr_min.attr;
582 cip->attr_gen[acnt++] = &cip->attr_max.attr;
584 case pvr2_ctl_bitmask:
585 // Control is an bitmask
586 cip->attr_gen[acnt++] = &cip->attr_bits.attr;
591 cnt = scnprintf(cip->name,sizeof(cip->name)-1,"ctl_%s",
592 pvr2_ctrl_get_name(cptr));
594 cip->grp.name = cip->name;
595 cip->grp.attrs = cip->attr_gen;
597 ret = sysfs_create_group(&sfp->class_dev->kobj,&cip->grp);
599 printk(KERN_WARNING "%s: sysfs_create_group error: %d\n",
603 cip->created_ok = !0;
606 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
607 static ssize_t debuginfo_show(struct class_device *,char *);
608 static ssize_t debugcmd_show(struct class_device *,char *);
609 static ssize_t debugcmd_store(struct class_device *,const char *,size_t count);
611 static void pvr2_sysfs_add_debugifc(struct pvr2_sysfs *sfp)
613 struct pvr2_sysfs_debugifc *dip;
616 dip = kmalloc(sizeof(*dip),GFP_KERNEL);
618 memset(dip,0,sizeof(*dip));
619 dip->attr_debugcmd.attr.owner = THIS_MODULE;
620 dip->attr_debugcmd.attr.name = "debugcmd";
621 dip->attr_debugcmd.attr.mode = S_IRUGO|S_IWUSR|S_IWGRP;
622 dip->attr_debugcmd.show = debugcmd_show;
623 dip->attr_debugcmd.store = debugcmd_store;
624 dip->attr_debuginfo.attr.owner = THIS_MODULE;
625 dip->attr_debuginfo.attr.name = "debuginfo";
626 dip->attr_debuginfo.attr.mode = S_IRUGO;
627 dip->attr_debuginfo.show = debuginfo_show;
629 ret = class_device_create_file(sfp->class_dev,&dip->attr_debugcmd);
631 printk(KERN_WARNING "%s: class_device_create_file error: %d\n",
634 dip->debugcmd_created_ok = !0;
636 ret = class_device_create_file(sfp->class_dev,&dip->attr_debuginfo);
638 printk(KERN_WARNING "%s: class_device_create_file error: %d\n",
641 dip->debuginfo_created_ok = !0;
646 static void pvr2_sysfs_tear_down_debugifc(struct pvr2_sysfs *sfp)
648 if (!sfp->debugifc) return;
649 if (sfp->debugifc->debuginfo_created_ok) {
650 class_device_remove_file(sfp->class_dev,
651 &sfp->debugifc->attr_debuginfo);
653 if (sfp->debugifc->debugcmd_created_ok) {
654 class_device_remove_file(sfp->class_dev,
655 &sfp->debugifc->attr_debugcmd);
657 kfree(sfp->debugifc);
658 sfp->debugifc = NULL;
660 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
663 static void pvr2_sysfs_add_controls(struct pvr2_sysfs *sfp)
665 unsigned int idx,cnt;
666 cnt = pvr2_hdw_get_ctrl_count(sfp->channel.hdw);
667 for (idx = 0; idx < cnt; idx++) {
668 pvr2_sysfs_add_control(sfp,idx);
673 static void pvr2_sysfs_tear_down_controls(struct pvr2_sysfs *sfp)
675 struct pvr2_sysfs_ctl_item *cip1,*cip2;
676 for (cip1 = sfp->item_first; cip1; cip1 = cip2) {
677 cip2 = cip1->item_next;
678 if (cip1->created_ok) {
679 sysfs_remove_group(&sfp->class_dev->kobj,&cip1->grp);
681 pvr2_sysfs_trace("Destroying pvr2_sysfs_ctl_item id=%p",cip1);
687 static void pvr2_sysfs_class_release(struct class *class)
689 struct pvr2_sysfs_class *clp;
690 clp = container_of(class,struct pvr2_sysfs_class,class);
691 pvr2_sysfs_trace("Destroying pvr2_sysfs_class id=%p",clp);
696 static void pvr2_sysfs_release(struct class_device *class_dev)
698 pvr2_sysfs_trace("Releasing class_dev id=%p",class_dev);
703 static void class_dev_destroy(struct pvr2_sysfs *sfp)
705 if (!sfp->class_dev) return;
706 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
707 pvr2_sysfs_tear_down_debugifc(sfp);
708 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
709 pvr2_sysfs_tear_down_controls(sfp);
710 if (sfp->v4l_minor_number_created_ok) {
711 class_device_remove_file(sfp->class_dev,
712 &sfp->attr_v4l_minor_number);
714 if (sfp->unit_number_created_ok) {
715 class_device_remove_file(sfp->class_dev,
716 &sfp->attr_unit_number);
718 pvr2_sysfs_trace("Destroying class_dev id=%p",sfp->class_dev);
719 sfp->class_dev->class_data = NULL;
720 class_device_unregister(sfp->class_dev);
721 sfp->class_dev = NULL;
725 static ssize_t v4l_minor_number_show(struct class_device *class_dev,char *buf)
727 struct pvr2_sysfs *sfp;
728 sfp = (struct pvr2_sysfs *)class_dev->class_data;
729 if (!sfp) return -EINVAL;
730 return scnprintf(buf,PAGE_SIZE,"%d\n",
731 pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw));
735 static ssize_t unit_number_show(struct class_device *class_dev,char *buf)
737 struct pvr2_sysfs *sfp;
738 sfp = (struct pvr2_sysfs *)class_dev->class_data;
739 if (!sfp) return -EINVAL;
740 return scnprintf(buf,PAGE_SIZE,"%d\n",
741 pvr2_hdw_get_unit_number(sfp->channel.hdw));
745 static void class_dev_create(struct pvr2_sysfs *sfp,
746 struct pvr2_sysfs_class *class_ptr)
748 struct usb_device *usb_dev;
749 struct class_device *class_dev;
752 usb_dev = pvr2_hdw_get_dev(sfp->channel.hdw);
753 if (!usb_dev) return;
754 class_dev = kmalloc(sizeof(*class_dev),GFP_KERNEL);
755 if (!class_dev) return;
756 memset(class_dev,0,sizeof(*class_dev));
758 pvr2_sysfs_trace("Creating class_dev id=%p",class_dev);
760 class_dev->class = &class_ptr->class;
761 if (pvr2_hdw_get_sn(sfp->channel.hdw)) {
762 snprintf(class_dev->class_id,BUS_ID_SIZE,"sn-%lu",
763 pvr2_hdw_get_sn(sfp->channel.hdw));
764 } else if (pvr2_hdw_get_unit_number(sfp->channel.hdw) >= 0) {
765 snprintf(class_dev->class_id,BUS_ID_SIZE,"unit-%c",
766 pvr2_hdw_get_unit_number(sfp->channel.hdw) + 'a');
772 class_dev->dev = &usb_dev->dev;
774 sfp->class_dev = class_dev;
775 class_dev->class_data = sfp;
776 ret = class_device_register(class_dev);
778 printk(KERN_ERR "%s: class_device_register failed\n",
784 sfp->attr_v4l_minor_number.attr.owner = THIS_MODULE;
785 sfp->attr_v4l_minor_number.attr.name = "v4l_minor_number";
786 sfp->attr_v4l_minor_number.attr.mode = S_IRUGO;
787 sfp->attr_v4l_minor_number.show = v4l_minor_number_show;
788 sfp->attr_v4l_minor_number.store = NULL;
789 ret = class_device_create_file(sfp->class_dev,
790 &sfp->attr_v4l_minor_number);
792 printk(KERN_WARNING "%s: class_device_create_file error: %d\n",
795 sfp->v4l_minor_number_created_ok = !0;
798 sfp->attr_unit_number.attr.owner = THIS_MODULE;
799 sfp->attr_unit_number.attr.name = "unit_number";
800 sfp->attr_unit_number.attr.mode = S_IRUGO;
801 sfp->attr_unit_number.show = unit_number_show;
802 sfp->attr_unit_number.store = NULL;
803 ret = class_device_create_file(sfp->class_dev,&sfp->attr_unit_number);
805 printk(KERN_WARNING "%s: class_device_create_file error: %d\n",
808 sfp->unit_number_created_ok = !0;
811 pvr2_sysfs_add_controls(sfp);
812 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
813 pvr2_sysfs_add_debugifc(sfp);
814 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
818 static void pvr2_sysfs_internal_check(struct pvr2_channel *chp)
820 struct pvr2_sysfs *sfp;
821 sfp = container_of(chp,struct pvr2_sysfs,channel);
822 if (!sfp->channel.mc_head->disconnect_flag) return;
823 pvr2_trace(PVR2_TRACE_STRUCT,"Destroying pvr2_sysfs id=%p",sfp);
824 class_dev_destroy(sfp);
825 pvr2_channel_done(&sfp->channel);
830 struct pvr2_sysfs *pvr2_sysfs_create(struct pvr2_context *mp,
831 struct pvr2_sysfs_class *class_ptr)
833 struct pvr2_sysfs *sfp;
834 sfp = kmalloc(sizeof(*sfp),GFP_KERNEL);
835 if (!sfp) return sfp;
836 memset(sfp,0,sizeof(*sfp));
837 pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr2_sysfs id=%p",sfp);
838 pvr2_channel_init(&sfp->channel,mp);
839 sfp->channel.check_func = pvr2_sysfs_internal_check;
841 class_dev_create(sfp,class_ptr);
846 static int pvr2_sysfs_hotplug(struct class_device *cd,char **envp,
847 int numenvp,char *buf,int size)
849 /* Even though we don't do anything here, we still need this function
850 because sysfs will still try to call it. */
854 struct pvr2_sysfs_class *pvr2_sysfs_class_create(void)
856 struct pvr2_sysfs_class *clp;
857 clp = kmalloc(sizeof(*clp),GFP_KERNEL);
858 if (!clp) return clp;
859 memset(clp,0,sizeof(*clp));
860 pvr2_sysfs_trace("Creating pvr2_sysfs_class id=%p",clp);
861 clp->class.name = "pvrusb2";
862 clp->class.class_release = pvr2_sysfs_class_release;
863 clp->class.release = pvr2_sysfs_release;
864 clp->class.uevent = pvr2_sysfs_hotplug;
865 if (class_register(&clp->class)) {
867 "Registration failed for pvr2_sysfs_class id=%p",clp);
875 void pvr2_sysfs_class_destroy(struct pvr2_sysfs_class *clp)
877 class_unregister(&clp->class);
881 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
882 static ssize_t debuginfo_show(struct class_device *class_dev,char *buf)
884 struct pvr2_sysfs *sfp;
885 sfp = (struct pvr2_sysfs *)class_dev->class_data;
886 if (!sfp) return -EINVAL;
887 pvr2_hdw_trigger_module_log(sfp->channel.hdw);
888 return pvr2_debugifc_print_info(sfp->channel.hdw,buf,PAGE_SIZE);
892 static ssize_t debugcmd_show(struct class_device *class_dev,char *buf)
894 struct pvr2_sysfs *sfp;
895 sfp = (struct pvr2_sysfs *)class_dev->class_data;
896 if (!sfp) return -EINVAL;
897 return pvr2_debugifc_print_status(sfp->channel.hdw,buf,PAGE_SIZE);
901 static ssize_t debugcmd_store(struct class_device *class_dev,
902 const char *buf,size_t count)
904 struct pvr2_sysfs *sfp;
907 sfp = (struct pvr2_sysfs *)class_dev->class_data;
908 if (!sfp) return -EINVAL;
910 ret = pvr2_debugifc_docmd(sfp->channel.hdw,buf,count);
911 if (ret < 0) return ret;
914 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
918 Stuff for Emacs to see, in order to encourage consistent editing style:
919 *** Local Variables: ***
921 *** fill-column: 75 ***
923 *** c-basic-offset: 8 ***