4 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <linux/string.h>
22 #include <linux/slab.h>
23 #include "pvrusb2-sysfs.h"
24 #include "pvrusb2-hdw.h"
25 #include "pvrusb2-debug.h"
26 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
27 #include "pvrusb2-debugifc.h"
28 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
30 #define pvr2_sysfs_trace(...) pvr2_trace(PVR2_TRACE_SYSFS,__VA_ARGS__)
33 struct pvr2_channel channel;
34 struct device *class_dev;
35 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
36 struct pvr2_sysfs_debugifc *debugifc;
37 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
38 struct pvr2_sysfs_ctl_item *item_first;
39 struct pvr2_sysfs_ctl_item *item_last;
40 struct device_attribute attr_v4l_minor_number;
41 struct device_attribute attr_v4l_radio_minor_number;
42 struct device_attribute attr_unit_number;
43 struct device_attribute attr_bus_info;
44 struct device_attribute attr_hdw_name;
45 struct device_attribute attr_hdw_desc;
46 int v4l_minor_number_created_ok;
47 int v4l_radio_minor_number_created_ok;
48 int unit_number_created_ok;
49 int bus_info_created_ok;
50 int hdw_name_created_ok;
51 int hdw_desc_created_ok;
54 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
55 struct pvr2_sysfs_debugifc {
56 struct device_attribute attr_debugcmd;
57 struct device_attribute attr_debuginfo;
58 int debugcmd_created_ok;
59 int debuginfo_created_ok;
61 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
63 struct pvr2_sysfs_ctl_item {
64 struct device_attribute attr_name;
65 struct device_attribute attr_type;
66 struct device_attribute attr_min;
67 struct device_attribute attr_max;
68 struct device_attribute attr_enum;
69 struct device_attribute attr_bits;
70 struct device_attribute attr_val;
71 struct device_attribute attr_custom;
72 struct pvr2_ctrl *cptr;
74 struct pvr2_sysfs *chptr;
75 struct pvr2_sysfs_ctl_item *item_next;
76 struct attribute *attr_gen[7];
77 struct attribute_group grp;
82 struct pvr2_sysfs_class {
86 static ssize_t show_name(struct device *class_dev,
87 struct device_attribute *attr,
90 struct pvr2_sysfs_ctl_item *cip;
92 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_name);
93 name = pvr2_ctrl_get_desc(cip->cptr);
94 pvr2_sysfs_trace("pvr2_sysfs(%p) show_name(cid=%d) is %s",
95 cip->chptr, cip->ctl_id, name);
96 if (!name) return -EINVAL;
97 return scnprintf(buf, PAGE_SIZE, "%s\n", name);
100 static ssize_t show_type(struct device *class_dev,
101 struct device_attribute *attr,
104 struct pvr2_sysfs_ctl_item *cip;
106 enum pvr2_ctl_type tp;
107 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_type);
108 tp = pvr2_ctrl_get_type(cip->cptr);
110 case pvr2_ctl_int: name = "integer"; break;
111 case pvr2_ctl_enum: name = "enum"; break;
112 case pvr2_ctl_bitmask: name = "bitmask"; break;
113 case pvr2_ctl_bool: name = "boolean"; break;
114 default: name = "?"; break;
116 pvr2_sysfs_trace("pvr2_sysfs(%p) show_type(cid=%d) is %s",
117 cip->chptr, cip->ctl_id, name);
118 if (!name) return -EINVAL;
119 return scnprintf(buf, PAGE_SIZE, "%s\n", name);
122 static ssize_t show_min(struct device *class_dev,
123 struct device_attribute *attr,
126 struct pvr2_sysfs_ctl_item *cip;
128 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_min);
129 val = pvr2_ctrl_get_min(cip->cptr);
130 pvr2_sysfs_trace("pvr2_sysfs(%p) show_min(cid=%d) is %ld",
131 cip->chptr, cip->ctl_id, val);
132 return scnprintf(buf, PAGE_SIZE, "%ld\n", val);
135 static ssize_t show_max(struct device *class_dev,
136 struct device_attribute *attr,
139 struct pvr2_sysfs_ctl_item *cip;
141 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_max);
142 val = pvr2_ctrl_get_max(cip->cptr);
143 pvr2_sysfs_trace("pvr2_sysfs(%p) show_max(cid=%d) is %ld",
144 cip->chptr, cip->ctl_id, val);
145 return scnprintf(buf, PAGE_SIZE, "%ld\n", val);
148 static ssize_t show_val_norm(struct device *class_dev,
149 struct device_attribute *attr,
152 struct pvr2_sysfs_ctl_item *cip;
155 unsigned int cnt = 0;
156 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_val);
157 ret = pvr2_ctrl_get_value(cip->cptr, &val);
158 if (ret < 0) return ret;
159 ret = pvr2_ctrl_value_to_sym(cip->cptr, ~0, val,
160 buf, PAGE_SIZE - 1, &cnt);
161 pvr2_sysfs_trace("pvr2_sysfs(%p) show_val_norm(cid=%d) is %.*s (%d)",
162 cip->chptr, cip->ctl_id, cnt, buf, val);
167 static ssize_t show_val_custom(struct device *class_dev,
168 struct device_attribute *attr,
171 struct pvr2_sysfs_ctl_item *cip;
174 unsigned int cnt = 0;
175 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_custom);
176 ret = pvr2_ctrl_get_value(cip->cptr, &val);
177 if (ret < 0) return ret;
178 ret = pvr2_ctrl_custom_value_to_sym(cip->cptr, ~0, val,
179 buf, PAGE_SIZE - 1, &cnt);
180 pvr2_sysfs_trace("pvr2_sysfs(%p) show_val_custom(cid=%d) is %.*s (%d)",
181 cip->chptr, cip->ctl_id, cnt, buf, val);
186 static ssize_t show_enum(struct device *class_dev,
187 struct device_attribute *attr,
190 struct pvr2_sysfs_ctl_item *cip;
192 unsigned int bcnt, ccnt, ecnt;
193 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_enum);
194 ecnt = pvr2_ctrl_get_cnt(cip->cptr);
196 for (val = 0; val < ecnt; val++) {
197 pvr2_ctrl_get_valname(cip->cptr, val, buf + bcnt,
198 PAGE_SIZE - bcnt, &ccnt);
201 if (bcnt >= PAGE_SIZE) break;
205 pvr2_sysfs_trace("pvr2_sysfs(%p) show_enum(cid=%d)",
206 cip->chptr, cip->ctl_id);
210 static ssize_t show_bits(struct device *class_dev,
211 struct device_attribute *attr,
214 struct pvr2_sysfs_ctl_item *cip;
216 unsigned int bcnt, ccnt;
217 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_bits);
218 valid_bits = pvr2_ctrl_get_mask(cip->cptr);
220 for (msk = 1; valid_bits; msk <<= 1) {
221 if (!(msk & valid_bits)) continue;
223 pvr2_ctrl_get_valname(cip->cptr, msk, buf + bcnt,
224 PAGE_SIZE - bcnt, &ccnt);
226 if (bcnt >= PAGE_SIZE) break;
230 pvr2_sysfs_trace("pvr2_sysfs(%p) show_bits(cid=%d)",
231 cip->chptr, cip->ctl_id);
235 static int store_val_any(struct pvr2_sysfs_ctl_item *cip, int customfl,
236 const char *buf,unsigned int count)
241 ret = pvr2_ctrl_custom_sym_to_value(cip->cptr, buf, count,
244 ret = pvr2_ctrl_sym_to_value(cip->cptr, buf, count,
247 if (ret < 0) return ret;
248 ret = pvr2_ctrl_set_mask_value(cip->cptr, mask, val);
249 pvr2_hdw_commit_ctl(cip->chptr->channel.hdw);
253 static ssize_t store_val_norm(struct device *class_dev,
254 struct device_attribute *attr,
255 const char *buf, size_t count)
257 struct pvr2_sysfs_ctl_item *cip;
259 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_val);
260 pvr2_sysfs_trace("pvr2_sysfs(%p) store_val_norm(cid=%d) \"%.*s\"",
261 cip->chptr, cip->ctl_id, (int)count, buf);
262 ret = store_val_any(cip, 0, buf, count);
263 if (!ret) ret = count;
267 static ssize_t store_val_custom(struct device *class_dev,
268 struct device_attribute *attr,
269 const char *buf, size_t count)
271 struct pvr2_sysfs_ctl_item *cip;
273 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_custom);
274 pvr2_sysfs_trace("pvr2_sysfs(%p) store_val_custom(cid=%d) \"%.*s\"",
275 cip->chptr, cip->ctl_id, (int)count, buf);
276 ret = store_val_any(cip, 1, buf, count);
277 if (!ret) ret = count;
281 static void pvr2_sysfs_add_control(struct pvr2_sysfs *sfp,int ctl_id)
283 struct pvr2_sysfs_ctl_item *cip;
284 struct pvr2_ctrl *cptr;
285 unsigned int cnt,acnt;
288 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,ctl_id);
291 cip = kzalloc(sizeof(*cip),GFP_KERNEL);
293 pvr2_sysfs_trace("Creating pvr2_sysfs_ctl_item id=%p",cip);
296 cip->ctl_id = ctl_id;
299 cip->item_next = NULL;
300 if (sfp->item_last) {
301 sfp->item_last->item_next = cip;
303 sfp->item_first = cip;
305 sfp->item_last = cip;
307 cip->attr_name.attr.name = "name";
308 cip->attr_name.attr.mode = S_IRUGO;
309 cip->attr_name.show = show_name;
311 cip->attr_type.attr.name = "type";
312 cip->attr_type.attr.mode = S_IRUGO;
313 cip->attr_type.show = show_type;
315 cip->attr_min.attr.name = "min_val";
316 cip->attr_min.attr.mode = S_IRUGO;
317 cip->attr_min.show = show_min;
319 cip->attr_max.attr.name = "max_val";
320 cip->attr_max.attr.mode = S_IRUGO;
321 cip->attr_max.show = show_max;
323 cip->attr_val.attr.name = "cur_val";
324 cip->attr_val.attr.mode = S_IRUGO;
326 cip->attr_custom.attr.name = "custom_val";
327 cip->attr_custom.attr.mode = S_IRUGO;
329 cip->attr_enum.attr.name = "enum_val";
330 cip->attr_enum.attr.mode = S_IRUGO;
331 cip->attr_enum.show = show_enum;
333 cip->attr_bits.attr.name = "bit_val";
334 cip->attr_bits.attr.mode = S_IRUGO;
335 cip->attr_bits.show = show_bits;
337 if (pvr2_ctrl_is_writable(cptr)) {
338 cip->attr_val.attr.mode |= S_IWUSR|S_IWGRP;
339 cip->attr_custom.attr.mode |= S_IWUSR|S_IWGRP;
343 cip->attr_gen[acnt++] = &cip->attr_name.attr;
344 cip->attr_gen[acnt++] = &cip->attr_type.attr;
345 cip->attr_gen[acnt++] = &cip->attr_val.attr;
346 cip->attr_val.show = show_val_norm;
347 cip->attr_val.store = store_val_norm;
348 if (pvr2_ctrl_has_custom_symbols(cptr)) {
349 cip->attr_gen[acnt++] = &cip->attr_custom.attr;
350 cip->attr_custom.show = show_val_custom;
351 cip->attr_custom.store = store_val_custom;
353 switch (pvr2_ctrl_get_type(cptr)) {
355 // Control is an enumeration
356 cip->attr_gen[acnt++] = &cip->attr_enum.attr;
359 // Control is an integer
360 cip->attr_gen[acnt++] = &cip->attr_min.attr;
361 cip->attr_gen[acnt++] = &cip->attr_max.attr;
363 case pvr2_ctl_bitmask:
364 // Control is an bitmask
365 cip->attr_gen[acnt++] = &cip->attr_bits.attr;
370 cnt = scnprintf(cip->name,sizeof(cip->name)-1,"ctl_%s",
371 pvr2_ctrl_get_name(cptr));
373 cip->grp.name = cip->name;
374 cip->grp.attrs = cip->attr_gen;
376 ret = sysfs_create_group(&sfp->class_dev->kobj,&cip->grp);
378 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
379 "sysfs_create_group error: %d",
383 cip->created_ok = !0;
386 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
387 static ssize_t debuginfo_show(struct device *, struct device_attribute *,
389 static ssize_t debugcmd_show(struct device *, struct device_attribute *,
391 static ssize_t debugcmd_store(struct device *, struct device_attribute *,
392 const char *, size_t count);
394 static void pvr2_sysfs_add_debugifc(struct pvr2_sysfs *sfp)
396 struct pvr2_sysfs_debugifc *dip;
399 dip = kzalloc(sizeof(*dip),GFP_KERNEL);
401 dip->attr_debugcmd.attr.name = "debugcmd";
402 dip->attr_debugcmd.attr.mode = S_IRUGO|S_IWUSR|S_IWGRP;
403 dip->attr_debugcmd.show = debugcmd_show;
404 dip->attr_debugcmd.store = debugcmd_store;
405 dip->attr_debuginfo.attr.name = "debuginfo";
406 dip->attr_debuginfo.attr.mode = S_IRUGO;
407 dip->attr_debuginfo.show = debuginfo_show;
409 ret = device_create_file(sfp->class_dev,&dip->attr_debugcmd);
411 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
412 "device_create_file error: %d",
415 dip->debugcmd_created_ok = !0;
417 ret = device_create_file(sfp->class_dev,&dip->attr_debuginfo);
419 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
420 "device_create_file error: %d",
423 dip->debuginfo_created_ok = !0;
428 static void pvr2_sysfs_tear_down_debugifc(struct pvr2_sysfs *sfp)
430 if (!sfp->debugifc) return;
431 if (sfp->debugifc->debuginfo_created_ok) {
432 device_remove_file(sfp->class_dev,
433 &sfp->debugifc->attr_debuginfo);
435 if (sfp->debugifc->debugcmd_created_ok) {
436 device_remove_file(sfp->class_dev,
437 &sfp->debugifc->attr_debugcmd);
439 kfree(sfp->debugifc);
440 sfp->debugifc = NULL;
442 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
445 static void pvr2_sysfs_add_controls(struct pvr2_sysfs *sfp)
447 unsigned int idx,cnt;
448 cnt = pvr2_hdw_get_ctrl_count(sfp->channel.hdw);
449 for (idx = 0; idx < cnt; idx++) {
450 pvr2_sysfs_add_control(sfp,idx);
455 static void pvr2_sysfs_tear_down_controls(struct pvr2_sysfs *sfp)
457 struct pvr2_sysfs_ctl_item *cip1,*cip2;
458 for (cip1 = sfp->item_first; cip1; cip1 = cip2) {
459 cip2 = cip1->item_next;
460 if (cip1->created_ok) {
461 sysfs_remove_group(&sfp->class_dev->kobj,&cip1->grp);
463 pvr2_sysfs_trace("Destroying pvr2_sysfs_ctl_item id=%p",cip1);
469 static void pvr2_sysfs_class_release(struct class *class)
471 struct pvr2_sysfs_class *clp;
472 clp = container_of(class,struct pvr2_sysfs_class,class);
473 pvr2_sysfs_trace("Destroying pvr2_sysfs_class id=%p",clp);
478 static void pvr2_sysfs_release(struct device *class_dev)
480 pvr2_sysfs_trace("Releasing class_dev id=%p",class_dev);
485 static void class_dev_destroy(struct pvr2_sysfs *sfp)
487 if (!sfp->class_dev) return;
488 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
489 pvr2_sysfs_tear_down_debugifc(sfp);
490 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
491 pvr2_sysfs_tear_down_controls(sfp);
492 if (sfp->hdw_desc_created_ok) {
493 device_remove_file(sfp->class_dev,
494 &sfp->attr_hdw_desc);
496 if (sfp->hdw_name_created_ok) {
497 device_remove_file(sfp->class_dev,
498 &sfp->attr_hdw_name);
500 if (sfp->bus_info_created_ok) {
501 device_remove_file(sfp->class_dev,
502 &sfp->attr_bus_info);
504 if (sfp->v4l_minor_number_created_ok) {
505 device_remove_file(sfp->class_dev,
506 &sfp->attr_v4l_minor_number);
508 if (sfp->v4l_radio_minor_number_created_ok) {
509 device_remove_file(sfp->class_dev,
510 &sfp->attr_v4l_radio_minor_number);
512 if (sfp->unit_number_created_ok) {
513 device_remove_file(sfp->class_dev,
514 &sfp->attr_unit_number);
516 pvr2_sysfs_trace("Destroying class_dev id=%p",sfp->class_dev);
517 sfp->class_dev->driver_data = NULL;
518 device_unregister(sfp->class_dev);
519 sfp->class_dev = NULL;
523 static ssize_t v4l_minor_number_show(struct device *class_dev,
524 struct device_attribute *attr, char *buf)
526 struct pvr2_sysfs *sfp;
527 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
528 if (!sfp) return -EINVAL;
529 return scnprintf(buf,PAGE_SIZE,"%d\n",
530 pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw,
531 pvr2_v4l_type_video));
535 static ssize_t bus_info_show(struct device *class_dev,
536 struct device_attribute *attr, char *buf)
538 struct pvr2_sysfs *sfp;
539 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
540 if (!sfp) return -EINVAL;
541 return scnprintf(buf,PAGE_SIZE,"%s\n",
542 pvr2_hdw_get_bus_info(sfp->channel.hdw));
546 static ssize_t hdw_name_show(struct device *class_dev,
547 struct device_attribute *attr, char *buf)
549 struct pvr2_sysfs *sfp;
550 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
551 if (!sfp) return -EINVAL;
552 return scnprintf(buf,PAGE_SIZE,"%s\n",
553 pvr2_hdw_get_type(sfp->channel.hdw));
557 static ssize_t hdw_desc_show(struct device *class_dev,
558 struct device_attribute *attr, char *buf)
560 struct pvr2_sysfs *sfp;
561 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
562 if (!sfp) return -EINVAL;
563 return scnprintf(buf,PAGE_SIZE,"%s\n",
564 pvr2_hdw_get_desc(sfp->channel.hdw));
568 static ssize_t v4l_radio_minor_number_show(struct device *class_dev,
569 struct device_attribute *attr,
572 struct pvr2_sysfs *sfp;
573 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
574 if (!sfp) return -EINVAL;
575 return scnprintf(buf,PAGE_SIZE,"%d\n",
576 pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw,
577 pvr2_v4l_type_radio));
581 static ssize_t unit_number_show(struct device *class_dev,
582 struct device_attribute *attr, char *buf)
584 struct pvr2_sysfs *sfp;
585 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
586 if (!sfp) return -EINVAL;
587 return scnprintf(buf,PAGE_SIZE,"%d\n",
588 pvr2_hdw_get_unit_number(sfp->channel.hdw));
592 static void class_dev_create(struct pvr2_sysfs *sfp,
593 struct pvr2_sysfs_class *class_ptr)
595 struct usb_device *usb_dev;
596 struct device *class_dev;
599 usb_dev = pvr2_hdw_get_dev(sfp->channel.hdw);
600 if (!usb_dev) return;
601 class_dev = kzalloc(sizeof(*class_dev),GFP_KERNEL);
602 if (!class_dev) return;
604 pvr2_sysfs_trace("Creating class_dev id=%p",class_dev);
606 class_dev->class = &class_ptr->class;
607 if (pvr2_hdw_get_sn(sfp->channel.hdw)) {
608 snprintf(class_dev->bus_id, BUS_ID_SIZE, "sn-%lu",
609 pvr2_hdw_get_sn(sfp->channel.hdw));
610 } else if (pvr2_hdw_get_unit_number(sfp->channel.hdw) >= 0) {
611 snprintf(class_dev->bus_id, BUS_ID_SIZE, "unit-%c",
612 pvr2_hdw_get_unit_number(sfp->channel.hdw) + 'a');
618 class_dev->parent = &usb_dev->dev;
620 sfp->class_dev = class_dev;
621 class_dev->driver_data = sfp;
622 ret = device_register(class_dev);
624 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
625 "device_register failed");
630 sfp->attr_v4l_minor_number.attr.name = "v4l_minor_number";
631 sfp->attr_v4l_minor_number.attr.mode = S_IRUGO;
632 sfp->attr_v4l_minor_number.show = v4l_minor_number_show;
633 sfp->attr_v4l_minor_number.store = NULL;
634 ret = device_create_file(sfp->class_dev,
635 &sfp->attr_v4l_minor_number);
637 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
638 "device_create_file error: %d",
641 sfp->v4l_minor_number_created_ok = !0;
644 sfp->attr_v4l_radio_minor_number.attr.name = "v4l_radio_minor_number";
645 sfp->attr_v4l_radio_minor_number.attr.mode = S_IRUGO;
646 sfp->attr_v4l_radio_minor_number.show = v4l_radio_minor_number_show;
647 sfp->attr_v4l_radio_minor_number.store = NULL;
648 ret = device_create_file(sfp->class_dev,
649 &sfp->attr_v4l_radio_minor_number);
651 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
652 "device_create_file error: %d",
655 sfp->v4l_radio_minor_number_created_ok = !0;
658 sfp->attr_unit_number.attr.name = "unit_number";
659 sfp->attr_unit_number.attr.mode = S_IRUGO;
660 sfp->attr_unit_number.show = unit_number_show;
661 sfp->attr_unit_number.store = NULL;
662 ret = device_create_file(sfp->class_dev,&sfp->attr_unit_number);
664 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
665 "device_create_file error: %d",
668 sfp->unit_number_created_ok = !0;
671 sfp->attr_bus_info.attr.name = "bus_info_str";
672 sfp->attr_bus_info.attr.mode = S_IRUGO;
673 sfp->attr_bus_info.show = bus_info_show;
674 sfp->attr_bus_info.store = NULL;
675 ret = device_create_file(sfp->class_dev,
676 &sfp->attr_bus_info);
678 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
679 "device_create_file error: %d",
682 sfp->bus_info_created_ok = !0;
685 sfp->attr_hdw_name.attr.name = "device_hardware_type";
686 sfp->attr_hdw_name.attr.mode = S_IRUGO;
687 sfp->attr_hdw_name.show = hdw_name_show;
688 sfp->attr_hdw_name.store = NULL;
689 ret = device_create_file(sfp->class_dev,
690 &sfp->attr_hdw_name);
692 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
693 "device_create_file error: %d",
696 sfp->hdw_name_created_ok = !0;
699 sfp->attr_hdw_desc.attr.name = "device_hardware_description";
700 sfp->attr_hdw_desc.attr.mode = S_IRUGO;
701 sfp->attr_hdw_desc.show = hdw_desc_show;
702 sfp->attr_hdw_desc.store = NULL;
703 ret = device_create_file(sfp->class_dev,
704 &sfp->attr_hdw_desc);
706 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
707 "device_create_file error: %d",
710 sfp->hdw_desc_created_ok = !0;
713 pvr2_sysfs_add_controls(sfp);
714 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
715 pvr2_sysfs_add_debugifc(sfp);
716 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
720 static void pvr2_sysfs_internal_check(struct pvr2_channel *chp)
722 struct pvr2_sysfs *sfp;
723 sfp = container_of(chp,struct pvr2_sysfs,channel);
724 if (!sfp->channel.mc_head->disconnect_flag) return;
725 pvr2_trace(PVR2_TRACE_STRUCT,"Destroying pvr2_sysfs id=%p",sfp);
726 class_dev_destroy(sfp);
727 pvr2_channel_done(&sfp->channel);
732 struct pvr2_sysfs *pvr2_sysfs_create(struct pvr2_context *mp,
733 struct pvr2_sysfs_class *class_ptr)
735 struct pvr2_sysfs *sfp;
736 sfp = kzalloc(sizeof(*sfp),GFP_KERNEL);
737 if (!sfp) return sfp;
738 pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr2_sysfs id=%p",sfp);
739 pvr2_channel_init(&sfp->channel,mp);
740 sfp->channel.check_func = pvr2_sysfs_internal_check;
742 class_dev_create(sfp,class_ptr);
748 struct pvr2_sysfs_class *pvr2_sysfs_class_create(void)
750 struct pvr2_sysfs_class *clp;
751 clp = kzalloc(sizeof(*clp),GFP_KERNEL);
752 if (!clp) return clp;
753 pvr2_sysfs_trace("Creating pvr2_sysfs_class id=%p",clp);
754 clp->class.name = "pvrusb2";
755 clp->class.class_release = pvr2_sysfs_class_release;
756 clp->class.dev_release = pvr2_sysfs_release;
757 if (class_register(&clp->class)) {
759 "Registration failed for pvr2_sysfs_class id=%p",clp);
767 void pvr2_sysfs_class_destroy(struct pvr2_sysfs_class *clp)
769 class_unregister(&clp->class);
773 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
774 static ssize_t debuginfo_show(struct device *class_dev,
775 struct device_attribute *attr, char *buf)
777 struct pvr2_sysfs *sfp;
778 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
779 if (!sfp) return -EINVAL;
780 pvr2_hdw_trigger_module_log(sfp->channel.hdw);
781 return pvr2_debugifc_print_info(sfp->channel.hdw,buf,PAGE_SIZE);
785 static ssize_t debugcmd_show(struct device *class_dev,
786 struct device_attribute *attr, char *buf)
788 struct pvr2_sysfs *sfp;
789 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
790 if (!sfp) return -EINVAL;
791 return pvr2_debugifc_print_status(sfp->channel.hdw,buf,PAGE_SIZE);
795 static ssize_t debugcmd_store(struct device *class_dev,
796 struct device_attribute *attr,
797 const char *buf, size_t count)
799 struct pvr2_sysfs *sfp;
802 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
803 if (!sfp) return -EINVAL;
805 ret = pvr2_debugifc_docmd(sfp->channel.hdw,buf,count);
806 if (ret < 0) return ret;
809 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
813 Stuff for Emacs to see, in order to encourage consistent editing style:
814 *** Local Variables: ***
816 *** fill-column: 75 ***
818 *** c-basic-offset: 8 ***