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/config.h>
23 #include <linux/string.h>
24 #include <linux/slab.h>
25 #include <asm/semaphore.h>
26 #include "pvrusb2-sysfs.h"
27 #include "pvrusb2-hdw.h"
28 #include "pvrusb2-debug.h"
29 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
30 #include "pvrusb2-debugifc.h"
31 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
33 #define pvr2_sysfs_trace(...) pvr2_trace(PVR2_TRACE_SYSFS,__VA_ARGS__)
36 struct pvr2_channel channel;
37 struct class_device *class_dev;
38 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
39 struct pvr2_sysfs_debugifc *debugifc;
40 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
41 struct pvr2_sysfs_ctl_item *item_first;
42 struct pvr2_sysfs_ctl_item *item_last;
43 struct sysfs_ops kops;
44 struct kobj_type ktype;
45 struct class_device_attribute attr_v4l_minor_number;
46 struct class_device_attribute attr_unit_number;
49 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
50 struct pvr2_sysfs_debugifc {
51 struct class_device_attribute attr_debugcmd;
52 struct class_device_attribute attr_debuginfo;
54 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
56 struct pvr2_sysfs_ctl_item {
57 struct class_device_attribute attr_name;
58 struct class_device_attribute attr_min;
59 struct class_device_attribute attr_max;
60 struct class_device_attribute attr_enum;
61 struct class_device_attribute attr_bits;
62 struct class_device_attribute attr_val;
63 struct class_device_attribute attr_custom;
64 struct pvr2_ctrl *cptr;
65 struct pvr2_sysfs *chptr;
66 struct pvr2_sysfs_ctl_item *item_next;
67 struct attribute *attr_gen[6];
68 struct attribute_group grp;
72 struct pvr2_sysfs_class {
76 static ssize_t show_name(int id,struct class_device *class_dev,char *buf)
78 struct pvr2_ctrl *cptr;
79 struct pvr2_sysfs *sfp;
82 sfp = (struct pvr2_sysfs *)class_dev->class_data;
83 if (!sfp) return -EINVAL;
84 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
85 if (!cptr) return -EINVAL;
87 name = pvr2_ctrl_get_desc(cptr);
88 pvr2_sysfs_trace("pvr2_sysfs(%p) show_name(cid=%d) is %s",sfp,id,name);
90 if (!name) return -EINVAL;
92 return scnprintf(buf,PAGE_SIZE,"%s\n",name);
95 static ssize_t show_min(int id,struct class_device *class_dev,char *buf)
97 struct pvr2_ctrl *cptr;
98 struct pvr2_sysfs *sfp;
101 sfp = (struct pvr2_sysfs *)class_dev->class_data;
102 if (!sfp) return -EINVAL;
103 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
104 if (!cptr) return -EINVAL;
105 val = pvr2_ctrl_get_min(cptr);
107 pvr2_sysfs_trace("pvr2_sysfs(%p) show_min(cid=%d) is %ld",sfp,id,val);
109 return scnprintf(buf,PAGE_SIZE,"%ld\n",val);
112 static ssize_t show_max(int id,struct class_device *class_dev,char *buf)
114 struct pvr2_ctrl *cptr;
115 struct pvr2_sysfs *sfp;
118 sfp = (struct pvr2_sysfs *)class_dev->class_data;
119 if (!sfp) return -EINVAL;
120 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
121 if (!cptr) return -EINVAL;
122 val = pvr2_ctrl_get_max(cptr);
124 pvr2_sysfs_trace("pvr2_sysfs(%p) show_max(cid=%d) is %ld",sfp,id,val);
126 return scnprintf(buf,PAGE_SIZE,"%ld\n",val);
129 static ssize_t show_val_norm(int id,struct class_device *class_dev,char *buf)
131 struct pvr2_ctrl *cptr;
132 struct pvr2_sysfs *sfp;
134 unsigned int cnt = 0;
136 sfp = (struct pvr2_sysfs *)class_dev->class_data;
137 if (!sfp) return -EINVAL;
138 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
139 if (!cptr) return -EINVAL;
141 ret = pvr2_ctrl_get_value(cptr,&val);
142 if (ret < 0) return ret;
144 ret = pvr2_ctrl_value_to_sym(cptr,~0,val,
145 buf,PAGE_SIZE-1,&cnt);
147 pvr2_sysfs_trace("pvr2_sysfs(%p) show_val_norm(cid=%d) is %.*s (%d)",
153 static ssize_t show_val_custom(int id,struct class_device *class_dev,char *buf)
155 struct pvr2_ctrl *cptr;
156 struct pvr2_sysfs *sfp;
158 unsigned int cnt = 0;
160 sfp = (struct pvr2_sysfs *)class_dev->class_data;
161 if (!sfp) return -EINVAL;
162 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
163 if (!cptr) return -EINVAL;
165 ret = pvr2_ctrl_get_value(cptr,&val);
166 if (ret < 0) return ret;
168 ret = pvr2_ctrl_custom_value_to_sym(cptr,~0,val,
169 buf,PAGE_SIZE-1,&cnt);
171 pvr2_sysfs_trace("pvr2_sysfs(%p) show_val_custom(cid=%d) is %.*s (%d)",
177 static ssize_t show_enum(int id,struct class_device *class_dev,char *buf)
179 struct pvr2_ctrl *cptr;
180 struct pvr2_sysfs *sfp;
182 unsigned int bcnt,ccnt,ecnt;
184 sfp = (struct pvr2_sysfs *)class_dev->class_data;
185 if (!sfp) return -EINVAL;
186 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
187 if (!cptr) return -EINVAL;
188 ecnt = pvr2_ctrl_get_cnt(cptr);
190 for (val = 0; val < ecnt; val++) {
191 pvr2_ctrl_get_valname(cptr,val,buf+bcnt,PAGE_SIZE-bcnt,&ccnt);
194 if (bcnt >= PAGE_SIZE) break;
198 pvr2_sysfs_trace("pvr2_sysfs(%p) show_enum(cid=%d)",sfp,id);
202 static ssize_t show_bits(int id,struct class_device *class_dev,char *buf)
204 struct pvr2_ctrl *cptr;
205 struct pvr2_sysfs *sfp;
207 unsigned int bcnt,ccnt;
209 sfp = (struct pvr2_sysfs *)class_dev->class_data;
210 if (!sfp) return -EINVAL;
211 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
212 if (!cptr) return -EINVAL;
213 valid_bits = pvr2_ctrl_get_mask(cptr);
215 for (msk = 1; valid_bits; msk <<= 1) {
216 if (!(msk & valid_bits)) continue;
218 pvr2_ctrl_get_valname(cptr,msk,buf+bcnt,PAGE_SIZE-bcnt,&ccnt);
220 if (bcnt >= PAGE_SIZE) break;
224 pvr2_sysfs_trace("pvr2_sysfs(%p) show_bits(cid=%d)",sfp,id);
228 static int store_val_any(int id,int customfl,struct pvr2_sysfs *sfp,
229 const char *buf,unsigned int count)
231 struct pvr2_ctrl *cptr;
235 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
237 ret = pvr2_ctrl_custom_sym_to_value(cptr,buf,count,&mask,&val);
239 ret = pvr2_ctrl_sym_to_value(cptr,buf,count,&mask,&val);
241 if (ret < 0) return ret;
242 ret = pvr2_ctrl_set_mask_value(cptr,mask,val);
243 pvr2_hdw_commit_ctl(sfp->channel.hdw);
247 static ssize_t store_val_norm(int id,struct class_device *class_dev,
248 const char *buf,size_t count)
250 struct pvr2_sysfs *sfp;
252 sfp = (struct pvr2_sysfs *)class_dev->class_data;
253 ret = store_val_any(id,0,sfp,buf,count);
254 if (!ret) ret = count;
258 static ssize_t store_val_custom(int id,struct class_device *class_dev,
259 const char *buf,size_t count)
261 struct pvr2_sysfs *sfp;
263 sfp = (struct pvr2_sysfs *)class_dev->class_data;
264 ret = store_val_any(id,1,sfp,buf,count);
265 if (!ret) ret = count;
270 Mike Isely <isely@pobox.com> 30-April-2005
272 This next batch of horrible preprocessor hackery is needed because the
273 kernel's class_device_attribute mechanism fails to pass the actual
274 attribute through to the show / store functions, which means we have no
275 way to package up any attribute-specific parameters, like for example the
276 control id. So we work around this brain-damage by encoding the control
277 id into the show / store functions themselves and pick the function based
278 on the control id we're setting up. These macros try to ease the pain.
282 #define CREATE_SHOW_INSTANCE(sf_name,ctl_id) \
283 static ssize_t sf_name##_##ctl_id(struct class_device *class_dev,char *buf) \
284 { return sf_name(ctl_id,class_dev,buf); }
286 #define CREATE_STORE_INSTANCE(sf_name,ctl_id) \
287 static ssize_t sf_name##_##ctl_id(struct class_device *class_dev,const char *buf,size_t count) \
288 { return sf_name(ctl_id,class_dev,buf,count); }
290 #define CREATE_BATCH(ctl_id) \
291 CREATE_SHOW_INSTANCE(show_name,ctl_id) \
292 CREATE_SHOW_INSTANCE(show_min,ctl_id) \
293 CREATE_SHOW_INSTANCE(show_max,ctl_id) \
294 CREATE_SHOW_INSTANCE(show_val_norm,ctl_id) \
295 CREATE_SHOW_INSTANCE(show_val_custom,ctl_id) \
296 CREATE_SHOW_INSTANCE(show_enum,ctl_id) \
297 CREATE_SHOW_INSTANCE(show_bits,ctl_id) \
298 CREATE_STORE_INSTANCE(store_val_norm,ctl_id) \
299 CREATE_STORE_INSTANCE(store_val_custom,ctl_id) \
336 struct pvr2_sysfs_func_set {
337 ssize_t (*show_name)(struct class_device *,char *);
338 ssize_t (*show_min)(struct class_device *,char *);
339 ssize_t (*show_max)(struct class_device *,char *);
340 ssize_t (*show_enum)(struct class_device *,char *);
341 ssize_t (*show_bits)(struct class_device *,char *);
342 ssize_t (*show_val_norm)(struct class_device *,char *);
343 ssize_t (*store_val_norm)(struct class_device *,
344 const char *,size_t);
345 ssize_t (*show_val_custom)(struct class_device *,char *);
346 ssize_t (*store_val_custom)(struct class_device *,
347 const char *,size_t);
350 #define INIT_BATCH(ctl_id) \
352 .show_name = show_name_##ctl_id, \
353 .show_min = show_min_##ctl_id, \
354 .show_max = show_max_##ctl_id, \
355 .show_enum = show_enum_##ctl_id, \
356 .show_bits = show_bits_##ctl_id, \
357 .show_val_norm = show_val_norm_##ctl_id, \
358 .store_val_norm = store_val_norm_##ctl_id, \
359 .show_val_custom = show_val_custom_##ctl_id, \
360 .store_val_custom = store_val_custom_##ctl_id, \
363 static struct pvr2_sysfs_func_set funcs[] = {
401 static void pvr2_sysfs_add_control(struct pvr2_sysfs *sfp,int ctl_id)
403 struct pvr2_sysfs_ctl_item *cip;
404 struct pvr2_sysfs_func_set *fp;
405 struct pvr2_ctrl *cptr;
406 unsigned int cnt,acnt;
408 if ((ctl_id < 0) || (ctl_id >= (sizeof(funcs)/sizeof(funcs[0])))) {
413 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,ctl_id);
416 cip = kmalloc(sizeof(*cip),GFP_KERNEL);
418 memset(cip,0,sizeof(*cip));
419 pvr2_sysfs_trace("Creating pvr2_sysfs_ctl_item id=%p",cip);
425 if (sfp->item_last) {
426 sfp->item_last->item_next = cip;
428 sfp->item_first = cip;
430 sfp->item_last = cip;
432 cip->attr_name.attr.owner = THIS_MODULE;
433 cip->attr_name.attr.name = "name";
434 cip->attr_name.attr.mode = S_IRUGO;
435 cip->attr_name.show = fp->show_name;
437 cip->attr_min.attr.owner = THIS_MODULE;
438 cip->attr_min.attr.name = "min_val";
439 cip->attr_min.attr.mode = S_IRUGO;
440 cip->attr_min.show = fp->show_min;
442 cip->attr_max.attr.owner = THIS_MODULE;
443 cip->attr_max.attr.name = "max_val";
444 cip->attr_max.attr.mode = S_IRUGO;
445 cip->attr_max.show = fp->show_max;
447 cip->attr_val.attr.owner = THIS_MODULE;
448 cip->attr_val.attr.name = "cur_val";
449 cip->attr_val.attr.mode = S_IRUGO;
451 cip->attr_custom.attr.owner = THIS_MODULE;
452 cip->attr_custom.attr.name = "custom_val";
453 cip->attr_custom.attr.mode = S_IRUGO;
455 cip->attr_enum.attr.owner = THIS_MODULE;
456 cip->attr_enum.attr.name = "enum_val";
457 cip->attr_enum.attr.mode = S_IRUGO;
458 cip->attr_enum.show = fp->show_enum;
460 cip->attr_bits.attr.owner = THIS_MODULE;
461 cip->attr_bits.attr.name = "bit_val";
462 cip->attr_bits.attr.mode = S_IRUGO;
463 cip->attr_bits.show = fp->show_bits;
465 if (pvr2_ctrl_is_writable(cptr)) {
466 cip->attr_val.attr.mode |= S_IWUSR|S_IWGRP;
467 cip->attr_custom.attr.mode |= S_IWUSR|S_IWGRP;
471 cip->attr_gen[acnt++] = &cip->attr_name.attr;
472 cip->attr_gen[acnt++] = &cip->attr_val.attr;
473 cip->attr_val.show = fp->show_val_norm;
474 cip->attr_val.store = fp->store_val_norm;
475 if (pvr2_ctrl_has_custom_symbols(cptr)) {
476 cip->attr_gen[acnt++] = &cip->attr_custom.attr;
477 cip->attr_custom.show = fp->show_val_custom;
478 cip->attr_custom.store = fp->store_val_custom;
480 switch (pvr2_ctrl_get_type(cptr)) {
482 // Control is an enumeration
483 cip->attr_gen[acnt++] = &cip->attr_enum.attr;
486 // Control is an integer
487 cip->attr_gen[acnt++] = &cip->attr_min.attr;
488 cip->attr_gen[acnt++] = &cip->attr_max.attr;
490 case pvr2_ctl_bitmask:
491 // Control is an bitmask
492 cip->attr_gen[acnt++] = &cip->attr_bits.attr;
497 cnt = scnprintf(cip->name,sizeof(cip->name)-1,"ctl_%s",
498 pvr2_ctrl_get_name(cptr));
500 cip->grp.name = cip->name;
501 cip->grp.attrs = cip->attr_gen;
503 sysfs_create_group(&sfp->class_dev->kobj,&cip->grp);
506 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
507 static ssize_t debuginfo_show(struct class_device *,char *);
508 static ssize_t debugcmd_show(struct class_device *,char *);
509 static ssize_t debugcmd_store(struct class_device *,const char *,size_t count);
511 static void pvr2_sysfs_add_debugifc(struct pvr2_sysfs *sfp)
513 struct pvr2_sysfs_debugifc *dip;
514 dip = kmalloc(sizeof(*dip),GFP_KERNEL);
516 memset(dip,0,sizeof(*dip));
517 dip->attr_debugcmd.attr.owner = THIS_MODULE;
518 dip->attr_debugcmd.attr.name = "debugcmd";
519 dip->attr_debugcmd.attr.mode = S_IRUGO|S_IWUSR|S_IWGRP;
520 dip->attr_debugcmd.show = debugcmd_show;
521 dip->attr_debugcmd.store = debugcmd_store;
522 dip->attr_debuginfo.attr.owner = THIS_MODULE;
523 dip->attr_debuginfo.attr.name = "debuginfo";
524 dip->attr_debuginfo.attr.mode = S_IRUGO;
525 dip->attr_debuginfo.show = debuginfo_show;
527 class_device_create_file(sfp->class_dev,&dip->attr_debugcmd);
528 class_device_create_file(sfp->class_dev,&dip->attr_debuginfo);
532 static void pvr2_sysfs_tear_down_debugifc(struct pvr2_sysfs *sfp)
534 if (!sfp->debugifc) return;
535 class_device_remove_file(sfp->class_dev,
536 &sfp->debugifc->attr_debuginfo);
537 class_device_remove_file(sfp->class_dev,&sfp->debugifc->attr_debugcmd);
538 kfree(sfp->debugifc);
541 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
544 static void pvr2_sysfs_add_controls(struct pvr2_sysfs *sfp)
546 unsigned int idx,cnt;
547 cnt = pvr2_hdw_get_ctrl_count(sfp->channel.hdw);
548 for (idx = 0; idx < cnt; idx++) {
549 pvr2_sysfs_add_control(sfp,idx);
554 static void pvr2_sysfs_tear_down_controls(struct pvr2_sysfs *sfp)
556 struct pvr2_sysfs_ctl_item *cip1,*cip2;
557 for (cip1 = sfp->item_first; cip1; cip1 = cip2) {
558 cip2 = cip1->item_next;
559 sysfs_remove_group(&sfp->class_dev->kobj,&cip1->grp);
560 pvr2_sysfs_trace("Destroying pvr2_sysfs_ctl_item id=%p",cip1);
566 static void pvr2_sysfs_class_release(struct class *class)
568 struct pvr2_sysfs_class *clp;
569 clp = container_of(class,struct pvr2_sysfs_class,class);
570 pvr2_sysfs_trace("Destroying pvr2_sysfs_class id=%p",clp);
575 static void pvr2_sysfs_release(struct class_device *class_dev)
577 pvr2_sysfs_trace("Releasing class_dev id=%p",class_dev);
582 static void class_dev_destroy(struct pvr2_sysfs *sfp)
584 if (!sfp->class_dev) return;
585 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
586 pvr2_sysfs_tear_down_debugifc(sfp);
587 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
588 pvr2_sysfs_tear_down_controls(sfp);
589 class_device_remove_file(sfp->class_dev,&sfp->attr_v4l_minor_number);
590 class_device_remove_file(sfp->class_dev,&sfp->attr_unit_number);
591 pvr2_sysfs_trace("Destroying class_dev id=%p",sfp->class_dev);
592 sfp->class_dev->class_data = 0;
593 class_device_unregister(sfp->class_dev);
598 static ssize_t v4l_minor_number_show(struct class_device *class_dev,char *buf)
600 struct pvr2_sysfs *sfp;
601 sfp = (struct pvr2_sysfs *)class_dev->class_data;
602 if (!sfp) return -EINVAL;
603 return scnprintf(buf,PAGE_SIZE,"%d\n",
604 pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw));
608 static ssize_t unit_number_show(struct class_device *class_dev,char *buf)
610 struct pvr2_sysfs *sfp;
611 sfp = (struct pvr2_sysfs *)class_dev->class_data;
612 if (!sfp) return -EINVAL;
613 return scnprintf(buf,PAGE_SIZE,"%d\n",
614 pvr2_hdw_get_unit_number(sfp->channel.hdw));
618 static void class_dev_create(struct pvr2_sysfs *sfp,
619 struct pvr2_sysfs_class *class_ptr)
621 struct usb_device *usb_dev;
622 struct class_device *class_dev;
623 usb_dev = pvr2_hdw_get_dev(sfp->channel.hdw);
624 if (!usb_dev) return;
625 class_dev = kmalloc(sizeof(*class_dev),GFP_KERNEL);
626 if (!class_dev) return;
627 memset(class_dev,0,sizeof(*class_dev));
629 pvr2_sysfs_trace("Creating class_dev id=%p",class_dev);
631 class_dev->class = &class_ptr->class;
632 if (pvr2_hdw_get_sn(sfp->channel.hdw)) {
633 snprintf(class_dev->class_id,BUS_ID_SIZE,"sn-%lu",
634 pvr2_hdw_get_sn(sfp->channel.hdw));
635 } else if (pvr2_hdw_get_unit_number(sfp->channel.hdw) >= 0) {
636 snprintf(class_dev->class_id,BUS_ID_SIZE,"unit-%c",
637 pvr2_hdw_get_unit_number(sfp->channel.hdw) + 'a');
643 class_dev->dev = &usb_dev->dev;
645 sfp->class_dev = class_dev;
646 class_dev->class_data = sfp;
647 class_device_register(class_dev);
649 sfp->attr_v4l_minor_number.attr.owner = THIS_MODULE;
650 sfp->attr_v4l_minor_number.attr.name = "v4l_minor_number";
651 sfp->attr_v4l_minor_number.attr.mode = S_IRUGO;
652 sfp->attr_v4l_minor_number.show = v4l_minor_number_show;
653 sfp->attr_v4l_minor_number.store = 0;
654 class_device_create_file(sfp->class_dev,&sfp->attr_v4l_minor_number);
655 sfp->attr_unit_number.attr.owner = THIS_MODULE;
656 sfp->attr_unit_number.attr.name = "unit_number";
657 sfp->attr_unit_number.attr.mode = S_IRUGO;
658 sfp->attr_unit_number.show = unit_number_show;
659 sfp->attr_unit_number.store = 0;
660 class_device_create_file(sfp->class_dev,&sfp->attr_unit_number);
662 pvr2_sysfs_add_controls(sfp);
663 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
664 pvr2_sysfs_add_debugifc(sfp);
665 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
669 static void pvr2_sysfs_internal_check(struct pvr2_channel *chp)
671 struct pvr2_sysfs *sfp;
672 sfp = container_of(chp,struct pvr2_sysfs,channel);
673 if (!sfp->channel.mc_head->disconnect_flag) return;
674 pvr2_trace(PVR2_TRACE_STRUCT,"Destroying pvr2_sysfs id=%p",sfp);
675 class_dev_destroy(sfp);
676 pvr2_channel_done(&sfp->channel);
681 struct pvr2_sysfs *pvr2_sysfs_create(struct pvr2_context *mp,
682 struct pvr2_sysfs_class *class_ptr)
684 struct pvr2_sysfs *sfp;
685 sfp = kmalloc(sizeof(*sfp),GFP_KERNEL);
686 if (!sfp) return sfp;
687 memset(sfp,0,sizeof(*sfp));
688 pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr2_sysfs id=%p",sfp);
689 pvr2_channel_init(&sfp->channel,mp);
690 sfp->channel.check_func = pvr2_sysfs_internal_check;
692 class_dev_create(sfp,class_ptr);
697 static int pvr2_sysfs_hotplug(struct class_device *cd,char **envp,
698 int numenvp,char *buf,int size)
700 /* Even though we don't do anything here, we still need this function
701 because sysfs will still try to call it. */
705 struct pvr2_sysfs_class *pvr2_sysfs_class_create(void)
707 struct pvr2_sysfs_class *clp;
708 clp = kmalloc(sizeof(*clp),GFP_KERNEL);
709 if (!clp) return clp;
710 memset(clp,0,sizeof(*clp));
711 pvr2_sysfs_trace("Creating pvr2_sysfs_class id=%p",clp);
712 clp->class.name = "pvrusb2";
713 clp->class.class_release = pvr2_sysfs_class_release;
714 clp->class.release = pvr2_sysfs_release;
715 clp->class.uevent = pvr2_sysfs_hotplug;
716 if (class_register(&clp->class)) {
718 "Registration failed for pvr2_sysfs_class id=%p",clp);
726 void pvr2_sysfs_class_destroy(struct pvr2_sysfs_class *clp)
728 class_unregister(&clp->class);
732 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
733 static ssize_t debuginfo_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 pvr2_hdw_trigger_module_log(sfp->channel.hdw);
739 return pvr2_debugifc_print_info(sfp->channel.hdw,buf,PAGE_SIZE);
743 static ssize_t debugcmd_show(struct class_device *class_dev,char *buf)
745 struct pvr2_sysfs *sfp;
746 sfp = (struct pvr2_sysfs *)class_dev->class_data;
747 if (!sfp) return -EINVAL;
748 return pvr2_debugifc_print_status(sfp->channel.hdw,buf,PAGE_SIZE);
752 static ssize_t debugcmd_store(struct class_device *class_dev,
753 const char *buf,size_t count)
755 struct pvr2_sysfs *sfp;
758 sfp = (struct pvr2_sysfs *)class_dev->class_data;
759 if (!sfp) return -EINVAL;
761 ret = pvr2_debugifc_docmd(sfp->channel.hdw,buf,count);
762 if (ret < 0) return ret;
765 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
769 Stuff for Emacs to see, in order to encourage consistent editing style:
770 *** Local Variables: ***
772 *** fill-column: 75 ***
774 *** c-basic-offset: 8 ***