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_def;
69 struct device_attribute attr_enum;
70 struct device_attribute attr_bits;
71 struct device_attribute attr_val;
72 struct device_attribute attr_custom;
73 struct pvr2_ctrl *cptr;
75 struct pvr2_sysfs *chptr;
76 struct pvr2_sysfs_ctl_item *item_next;
77 struct attribute *attr_gen[7];
78 struct attribute_group grp;
83 struct pvr2_sysfs_class {
87 static ssize_t show_name(struct device *class_dev,
88 struct device_attribute *attr,
91 struct pvr2_sysfs_ctl_item *cip;
93 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_name);
94 name = pvr2_ctrl_get_desc(cip->cptr);
95 pvr2_sysfs_trace("pvr2_sysfs(%p) show_name(cid=%d) is %s",
96 cip->chptr, cip->ctl_id, name);
97 if (!name) return -EINVAL;
98 return scnprintf(buf, PAGE_SIZE, "%s\n", name);
101 static ssize_t show_type(struct device *class_dev,
102 struct device_attribute *attr,
105 struct pvr2_sysfs_ctl_item *cip;
107 enum pvr2_ctl_type tp;
108 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_type);
109 tp = pvr2_ctrl_get_type(cip->cptr);
111 case pvr2_ctl_int: name = "integer"; break;
112 case pvr2_ctl_enum: name = "enum"; break;
113 case pvr2_ctl_bitmask: name = "bitmask"; break;
114 case pvr2_ctl_bool: name = "boolean"; break;
115 default: name = "?"; break;
117 pvr2_sysfs_trace("pvr2_sysfs(%p) show_type(cid=%d) is %s",
118 cip->chptr, cip->ctl_id, name);
119 if (!name) return -EINVAL;
120 return scnprintf(buf, PAGE_SIZE, "%s\n", name);
123 static ssize_t show_min(struct device *class_dev,
124 struct device_attribute *attr,
127 struct pvr2_sysfs_ctl_item *cip;
129 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_min);
130 val = pvr2_ctrl_get_min(cip->cptr);
131 pvr2_sysfs_trace("pvr2_sysfs(%p) show_min(cid=%d) is %ld",
132 cip->chptr, cip->ctl_id, val);
133 return scnprintf(buf, PAGE_SIZE, "%ld\n", val);
136 static ssize_t show_max(struct device *class_dev,
137 struct device_attribute *attr,
140 struct pvr2_sysfs_ctl_item *cip;
142 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_max);
143 val = pvr2_ctrl_get_max(cip->cptr);
144 pvr2_sysfs_trace("pvr2_sysfs(%p) show_max(cid=%d) is %ld",
145 cip->chptr, cip->ctl_id, val);
146 return scnprintf(buf, PAGE_SIZE, "%ld\n", val);
149 static ssize_t show_def(struct device *class_dev,
150 struct device_attribute *attr,
153 struct pvr2_sysfs_ctl_item *cip;
156 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_def);
157 ret = pvr2_ctrl_get_def(cip->cptr, &val);
158 pvr2_sysfs_trace("pvr2_sysfs(%p) show_def(cid=%d) is %d, stat=%d",
159 cip->chptr, cip->ctl_id, val, ret);
161 /* Keep checkpatch.pl quiet */
164 return scnprintf(buf, PAGE_SIZE, "%d\n", val);
167 static ssize_t show_val_norm(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_val);
176 ret = pvr2_ctrl_get_value(cip->cptr, &val);
177 if (ret < 0) return ret;
178 ret = pvr2_ctrl_value_to_sym(cip->cptr, ~0, val,
179 buf, PAGE_SIZE - 1, &cnt);
180 pvr2_sysfs_trace("pvr2_sysfs(%p) show_val_norm(cid=%d) is %.*s (%d)",
181 cip->chptr, cip->ctl_id, cnt, buf, val);
186 static ssize_t show_val_custom(struct device *class_dev,
187 struct device_attribute *attr,
190 struct pvr2_sysfs_ctl_item *cip;
193 unsigned int cnt = 0;
194 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_custom);
195 ret = pvr2_ctrl_get_value(cip->cptr, &val);
196 if (ret < 0) return ret;
197 ret = pvr2_ctrl_custom_value_to_sym(cip->cptr, ~0, val,
198 buf, PAGE_SIZE - 1, &cnt);
199 pvr2_sysfs_trace("pvr2_sysfs(%p) show_val_custom(cid=%d) is %.*s (%d)",
200 cip->chptr, cip->ctl_id, cnt, buf, val);
205 static ssize_t show_enum(struct device *class_dev,
206 struct device_attribute *attr,
209 struct pvr2_sysfs_ctl_item *cip;
211 unsigned int bcnt, ccnt, ecnt;
212 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_enum);
213 ecnt = pvr2_ctrl_get_cnt(cip->cptr);
215 for (val = 0; val < ecnt; val++) {
216 pvr2_ctrl_get_valname(cip->cptr, val, buf + bcnt,
217 PAGE_SIZE - bcnt, &ccnt);
220 if (bcnt >= PAGE_SIZE) break;
224 pvr2_sysfs_trace("pvr2_sysfs(%p) show_enum(cid=%d)",
225 cip->chptr, cip->ctl_id);
229 static ssize_t show_bits(struct device *class_dev,
230 struct device_attribute *attr,
233 struct pvr2_sysfs_ctl_item *cip;
235 unsigned int bcnt, ccnt;
236 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_bits);
237 valid_bits = pvr2_ctrl_get_mask(cip->cptr);
239 for (msk = 1; valid_bits; msk <<= 1) {
240 if (!(msk & valid_bits)) continue;
242 pvr2_ctrl_get_valname(cip->cptr, msk, buf + bcnt,
243 PAGE_SIZE - bcnt, &ccnt);
245 if (bcnt >= PAGE_SIZE) break;
249 pvr2_sysfs_trace("pvr2_sysfs(%p) show_bits(cid=%d)",
250 cip->chptr, cip->ctl_id);
254 static int store_val_any(struct pvr2_sysfs_ctl_item *cip, int customfl,
255 const char *buf,unsigned int count)
260 ret = pvr2_ctrl_custom_sym_to_value(cip->cptr, buf, count,
263 ret = pvr2_ctrl_sym_to_value(cip->cptr, buf, count,
266 if (ret < 0) return ret;
267 ret = pvr2_ctrl_set_mask_value(cip->cptr, mask, val);
268 pvr2_hdw_commit_ctl(cip->chptr->channel.hdw);
272 static ssize_t store_val_norm(struct device *class_dev,
273 struct device_attribute *attr,
274 const char *buf, size_t count)
276 struct pvr2_sysfs_ctl_item *cip;
278 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_val);
279 pvr2_sysfs_trace("pvr2_sysfs(%p) store_val_norm(cid=%d) \"%.*s\"",
280 cip->chptr, cip->ctl_id, (int)count, buf);
281 ret = store_val_any(cip, 0, buf, count);
282 if (!ret) ret = count;
286 static ssize_t store_val_custom(struct device *class_dev,
287 struct device_attribute *attr,
288 const char *buf, size_t count)
290 struct pvr2_sysfs_ctl_item *cip;
292 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_custom);
293 pvr2_sysfs_trace("pvr2_sysfs(%p) store_val_custom(cid=%d) \"%.*s\"",
294 cip->chptr, cip->ctl_id, (int)count, buf);
295 ret = store_val_any(cip, 1, buf, count);
296 if (!ret) ret = count;
300 static void pvr2_sysfs_add_control(struct pvr2_sysfs *sfp,int ctl_id)
302 struct pvr2_sysfs_ctl_item *cip;
303 struct pvr2_ctrl *cptr;
304 unsigned int cnt,acnt;
307 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,ctl_id);
310 cip = kzalloc(sizeof(*cip),GFP_KERNEL);
312 pvr2_sysfs_trace("Creating pvr2_sysfs_ctl_item id=%p",cip);
315 cip->ctl_id = ctl_id;
318 cip->item_next = NULL;
319 if (sfp->item_last) {
320 sfp->item_last->item_next = cip;
322 sfp->item_first = cip;
324 sfp->item_last = cip;
326 cip->attr_name.attr.name = "name";
327 cip->attr_name.attr.mode = S_IRUGO;
328 cip->attr_name.show = show_name;
330 cip->attr_type.attr.name = "type";
331 cip->attr_type.attr.mode = S_IRUGO;
332 cip->attr_type.show = show_type;
334 cip->attr_min.attr.name = "min_val";
335 cip->attr_min.attr.mode = S_IRUGO;
336 cip->attr_min.show = show_min;
338 cip->attr_max.attr.name = "max_val";
339 cip->attr_max.attr.mode = S_IRUGO;
340 cip->attr_max.show = show_max;
342 cip->attr_def.attr.name = "def_val";
343 cip->attr_def.attr.mode = S_IRUGO;
344 cip->attr_def.show = show_def;
346 cip->attr_val.attr.name = "cur_val";
347 cip->attr_val.attr.mode = S_IRUGO;
349 cip->attr_custom.attr.name = "custom_val";
350 cip->attr_custom.attr.mode = S_IRUGO;
352 cip->attr_enum.attr.name = "enum_val";
353 cip->attr_enum.attr.mode = S_IRUGO;
354 cip->attr_enum.show = show_enum;
356 cip->attr_bits.attr.name = "bit_val";
357 cip->attr_bits.attr.mode = S_IRUGO;
358 cip->attr_bits.show = show_bits;
360 if (pvr2_ctrl_is_writable(cptr)) {
361 cip->attr_val.attr.mode |= S_IWUSR|S_IWGRP;
362 cip->attr_custom.attr.mode |= S_IWUSR|S_IWGRP;
366 cip->attr_gen[acnt++] = &cip->attr_name.attr;
367 cip->attr_gen[acnt++] = &cip->attr_type.attr;
368 cip->attr_gen[acnt++] = &cip->attr_val.attr;
369 cip->attr_gen[acnt++] = &cip->attr_def.attr;
370 cip->attr_val.show = show_val_norm;
371 cip->attr_val.store = store_val_norm;
372 if (pvr2_ctrl_has_custom_symbols(cptr)) {
373 cip->attr_gen[acnt++] = &cip->attr_custom.attr;
374 cip->attr_custom.show = show_val_custom;
375 cip->attr_custom.store = store_val_custom;
377 switch (pvr2_ctrl_get_type(cptr)) {
379 // Control is an enumeration
380 cip->attr_gen[acnt++] = &cip->attr_enum.attr;
383 // Control is an integer
384 cip->attr_gen[acnt++] = &cip->attr_min.attr;
385 cip->attr_gen[acnt++] = &cip->attr_max.attr;
387 case pvr2_ctl_bitmask:
388 // Control is an bitmask
389 cip->attr_gen[acnt++] = &cip->attr_bits.attr;
394 cnt = scnprintf(cip->name,sizeof(cip->name)-1,"ctl_%s",
395 pvr2_ctrl_get_name(cptr));
397 cip->grp.name = cip->name;
398 cip->grp.attrs = cip->attr_gen;
400 ret = sysfs_create_group(&sfp->class_dev->kobj,&cip->grp);
402 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
403 "sysfs_create_group error: %d",
407 cip->created_ok = !0;
410 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
411 static ssize_t debuginfo_show(struct device *, struct device_attribute *,
413 static ssize_t debugcmd_show(struct device *, struct device_attribute *,
415 static ssize_t debugcmd_store(struct device *, struct device_attribute *,
416 const char *, size_t count);
418 static void pvr2_sysfs_add_debugifc(struct pvr2_sysfs *sfp)
420 struct pvr2_sysfs_debugifc *dip;
423 dip = kzalloc(sizeof(*dip),GFP_KERNEL);
425 dip->attr_debugcmd.attr.name = "debugcmd";
426 dip->attr_debugcmd.attr.mode = S_IRUGO|S_IWUSR|S_IWGRP;
427 dip->attr_debugcmd.show = debugcmd_show;
428 dip->attr_debugcmd.store = debugcmd_store;
429 dip->attr_debuginfo.attr.name = "debuginfo";
430 dip->attr_debuginfo.attr.mode = S_IRUGO;
431 dip->attr_debuginfo.show = debuginfo_show;
433 ret = device_create_file(sfp->class_dev,&dip->attr_debugcmd);
435 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
436 "device_create_file error: %d",
439 dip->debugcmd_created_ok = !0;
441 ret = device_create_file(sfp->class_dev,&dip->attr_debuginfo);
443 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
444 "device_create_file error: %d",
447 dip->debuginfo_created_ok = !0;
452 static void pvr2_sysfs_tear_down_debugifc(struct pvr2_sysfs *sfp)
454 if (!sfp->debugifc) return;
455 if (sfp->debugifc->debuginfo_created_ok) {
456 device_remove_file(sfp->class_dev,
457 &sfp->debugifc->attr_debuginfo);
459 if (sfp->debugifc->debugcmd_created_ok) {
460 device_remove_file(sfp->class_dev,
461 &sfp->debugifc->attr_debugcmd);
463 kfree(sfp->debugifc);
464 sfp->debugifc = NULL;
466 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
469 static void pvr2_sysfs_add_controls(struct pvr2_sysfs *sfp)
471 unsigned int idx,cnt;
472 cnt = pvr2_hdw_get_ctrl_count(sfp->channel.hdw);
473 for (idx = 0; idx < cnt; idx++) {
474 pvr2_sysfs_add_control(sfp,idx);
479 static void pvr2_sysfs_tear_down_controls(struct pvr2_sysfs *sfp)
481 struct pvr2_sysfs_ctl_item *cip1,*cip2;
482 for (cip1 = sfp->item_first; cip1; cip1 = cip2) {
483 cip2 = cip1->item_next;
484 if (cip1->created_ok) {
485 sysfs_remove_group(&sfp->class_dev->kobj,&cip1->grp);
487 pvr2_sysfs_trace("Destroying pvr2_sysfs_ctl_item id=%p",cip1);
493 static void pvr2_sysfs_class_release(struct class *class)
495 struct pvr2_sysfs_class *clp;
496 clp = container_of(class,struct pvr2_sysfs_class,class);
497 pvr2_sysfs_trace("Destroying pvr2_sysfs_class id=%p",clp);
502 static void pvr2_sysfs_release(struct device *class_dev)
504 pvr2_sysfs_trace("Releasing class_dev id=%p",class_dev);
509 static void class_dev_destroy(struct pvr2_sysfs *sfp)
511 if (!sfp->class_dev) return;
512 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
513 pvr2_sysfs_tear_down_debugifc(sfp);
514 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
515 pvr2_sysfs_tear_down_controls(sfp);
516 if (sfp->hdw_desc_created_ok) {
517 device_remove_file(sfp->class_dev,
518 &sfp->attr_hdw_desc);
520 if (sfp->hdw_name_created_ok) {
521 device_remove_file(sfp->class_dev,
522 &sfp->attr_hdw_name);
524 if (sfp->bus_info_created_ok) {
525 device_remove_file(sfp->class_dev,
526 &sfp->attr_bus_info);
528 if (sfp->v4l_minor_number_created_ok) {
529 device_remove_file(sfp->class_dev,
530 &sfp->attr_v4l_minor_number);
532 if (sfp->v4l_radio_minor_number_created_ok) {
533 device_remove_file(sfp->class_dev,
534 &sfp->attr_v4l_radio_minor_number);
536 if (sfp->unit_number_created_ok) {
537 device_remove_file(sfp->class_dev,
538 &sfp->attr_unit_number);
540 pvr2_sysfs_trace("Destroying class_dev id=%p",sfp->class_dev);
541 sfp->class_dev->driver_data = NULL;
542 device_unregister(sfp->class_dev);
543 sfp->class_dev = NULL;
547 static ssize_t v4l_minor_number_show(struct device *class_dev,
548 struct device_attribute *attr, char *buf)
550 struct pvr2_sysfs *sfp;
551 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
552 if (!sfp) return -EINVAL;
553 return scnprintf(buf,PAGE_SIZE,"%d\n",
554 pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw,
555 pvr2_v4l_type_video));
559 static ssize_t bus_info_show(struct device *class_dev,
560 struct device_attribute *attr, char *buf)
562 struct pvr2_sysfs *sfp;
563 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
564 if (!sfp) return -EINVAL;
565 return scnprintf(buf,PAGE_SIZE,"%s\n",
566 pvr2_hdw_get_bus_info(sfp->channel.hdw));
570 static ssize_t hdw_name_show(struct device *class_dev,
571 struct device_attribute *attr, char *buf)
573 struct pvr2_sysfs *sfp;
574 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
575 if (!sfp) return -EINVAL;
576 return scnprintf(buf,PAGE_SIZE,"%s\n",
577 pvr2_hdw_get_type(sfp->channel.hdw));
581 static ssize_t hdw_desc_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,"%s\n",
588 pvr2_hdw_get_desc(sfp->channel.hdw));
592 static ssize_t v4l_radio_minor_number_show(struct device *class_dev,
593 struct device_attribute *attr,
596 struct pvr2_sysfs *sfp;
597 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
598 if (!sfp) return -EINVAL;
599 return scnprintf(buf,PAGE_SIZE,"%d\n",
600 pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw,
601 pvr2_v4l_type_radio));
605 static ssize_t unit_number_show(struct device *class_dev,
606 struct device_attribute *attr, char *buf)
608 struct pvr2_sysfs *sfp;
609 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
610 if (!sfp) return -EINVAL;
611 return scnprintf(buf,PAGE_SIZE,"%d\n",
612 pvr2_hdw_get_unit_number(sfp->channel.hdw));
616 static void class_dev_create(struct pvr2_sysfs *sfp,
617 struct pvr2_sysfs_class *class_ptr)
619 struct usb_device *usb_dev;
620 struct device *class_dev;
623 usb_dev = pvr2_hdw_get_dev(sfp->channel.hdw);
624 if (!usb_dev) return;
625 class_dev = kzalloc(sizeof(*class_dev),GFP_KERNEL);
626 if (!class_dev) return;
628 pvr2_sysfs_trace("Creating class_dev id=%p",class_dev);
630 class_dev->class = &class_ptr->class;
631 if (pvr2_hdw_get_sn(sfp->channel.hdw)) {
632 snprintf(class_dev->bus_id, BUS_ID_SIZE, "sn-%lu",
633 pvr2_hdw_get_sn(sfp->channel.hdw));
634 } else if (pvr2_hdw_get_unit_number(sfp->channel.hdw) >= 0) {
635 snprintf(class_dev->bus_id, BUS_ID_SIZE, "unit-%c",
636 pvr2_hdw_get_unit_number(sfp->channel.hdw) + 'a');
642 class_dev->parent = &usb_dev->dev;
644 sfp->class_dev = class_dev;
645 class_dev->driver_data = sfp;
646 ret = device_register(class_dev);
648 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
649 "device_register failed");
654 sfp->attr_v4l_minor_number.attr.name = "v4l_minor_number";
655 sfp->attr_v4l_minor_number.attr.mode = S_IRUGO;
656 sfp->attr_v4l_minor_number.show = v4l_minor_number_show;
657 sfp->attr_v4l_minor_number.store = NULL;
658 ret = device_create_file(sfp->class_dev,
659 &sfp->attr_v4l_minor_number);
661 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
662 "device_create_file error: %d",
665 sfp->v4l_minor_number_created_ok = !0;
668 sfp->attr_v4l_radio_minor_number.attr.name = "v4l_radio_minor_number";
669 sfp->attr_v4l_radio_minor_number.attr.mode = S_IRUGO;
670 sfp->attr_v4l_radio_minor_number.show = v4l_radio_minor_number_show;
671 sfp->attr_v4l_radio_minor_number.store = NULL;
672 ret = device_create_file(sfp->class_dev,
673 &sfp->attr_v4l_radio_minor_number);
675 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
676 "device_create_file error: %d",
679 sfp->v4l_radio_minor_number_created_ok = !0;
682 sfp->attr_unit_number.attr.name = "unit_number";
683 sfp->attr_unit_number.attr.mode = S_IRUGO;
684 sfp->attr_unit_number.show = unit_number_show;
685 sfp->attr_unit_number.store = NULL;
686 ret = device_create_file(sfp->class_dev,&sfp->attr_unit_number);
688 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
689 "device_create_file error: %d",
692 sfp->unit_number_created_ok = !0;
695 sfp->attr_bus_info.attr.name = "bus_info_str";
696 sfp->attr_bus_info.attr.mode = S_IRUGO;
697 sfp->attr_bus_info.show = bus_info_show;
698 sfp->attr_bus_info.store = NULL;
699 ret = device_create_file(sfp->class_dev,
700 &sfp->attr_bus_info);
702 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
703 "device_create_file error: %d",
706 sfp->bus_info_created_ok = !0;
709 sfp->attr_hdw_name.attr.name = "device_hardware_type";
710 sfp->attr_hdw_name.attr.mode = S_IRUGO;
711 sfp->attr_hdw_name.show = hdw_name_show;
712 sfp->attr_hdw_name.store = NULL;
713 ret = device_create_file(sfp->class_dev,
714 &sfp->attr_hdw_name);
716 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
717 "device_create_file error: %d",
720 sfp->hdw_name_created_ok = !0;
723 sfp->attr_hdw_desc.attr.name = "device_hardware_description";
724 sfp->attr_hdw_desc.attr.mode = S_IRUGO;
725 sfp->attr_hdw_desc.show = hdw_desc_show;
726 sfp->attr_hdw_desc.store = NULL;
727 ret = device_create_file(sfp->class_dev,
728 &sfp->attr_hdw_desc);
730 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
731 "device_create_file error: %d",
734 sfp->hdw_desc_created_ok = !0;
737 pvr2_sysfs_add_controls(sfp);
738 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
739 pvr2_sysfs_add_debugifc(sfp);
740 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
744 static void pvr2_sysfs_internal_check(struct pvr2_channel *chp)
746 struct pvr2_sysfs *sfp;
747 sfp = container_of(chp,struct pvr2_sysfs,channel);
748 if (!sfp->channel.mc_head->disconnect_flag) return;
749 pvr2_trace(PVR2_TRACE_STRUCT,"Destroying pvr2_sysfs id=%p",sfp);
750 class_dev_destroy(sfp);
751 pvr2_channel_done(&sfp->channel);
756 struct pvr2_sysfs *pvr2_sysfs_create(struct pvr2_context *mp,
757 struct pvr2_sysfs_class *class_ptr)
759 struct pvr2_sysfs *sfp;
760 sfp = kzalloc(sizeof(*sfp),GFP_KERNEL);
761 if (!sfp) return sfp;
762 pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr2_sysfs id=%p",sfp);
763 pvr2_channel_init(&sfp->channel,mp);
764 sfp->channel.check_func = pvr2_sysfs_internal_check;
766 class_dev_create(sfp,class_ptr);
772 struct pvr2_sysfs_class *pvr2_sysfs_class_create(void)
774 struct pvr2_sysfs_class *clp;
775 clp = kzalloc(sizeof(*clp),GFP_KERNEL);
776 if (!clp) return clp;
777 pvr2_sysfs_trace("Creating pvr2_sysfs_class id=%p",clp);
778 clp->class.name = "pvrusb2";
779 clp->class.class_release = pvr2_sysfs_class_release;
780 clp->class.dev_release = pvr2_sysfs_release;
781 if (class_register(&clp->class)) {
783 "Registration failed for pvr2_sysfs_class id=%p",clp);
791 void pvr2_sysfs_class_destroy(struct pvr2_sysfs_class *clp)
793 class_unregister(&clp->class);
797 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
798 static ssize_t debuginfo_show(struct device *class_dev,
799 struct device_attribute *attr, char *buf)
801 struct pvr2_sysfs *sfp;
802 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
803 if (!sfp) return -EINVAL;
804 pvr2_hdw_trigger_module_log(sfp->channel.hdw);
805 return pvr2_debugifc_print_info(sfp->channel.hdw,buf,PAGE_SIZE);
809 static ssize_t debugcmd_show(struct device *class_dev,
810 struct device_attribute *attr, char *buf)
812 struct pvr2_sysfs *sfp;
813 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
814 if (!sfp) return -EINVAL;
815 return pvr2_debugifc_print_status(sfp->channel.hdw,buf,PAGE_SIZE);
819 static ssize_t debugcmd_store(struct device *class_dev,
820 struct device_attribute *attr,
821 const char *buf, size_t count)
823 struct pvr2_sysfs *sfp;
826 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
827 if (!sfp) return -EINVAL;
829 ret = pvr2_debugifc_docmd(sfp->channel.hdw,buf,count);
830 if (ret < 0) return ret;
833 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
837 Stuff for Emacs to see, in order to encourage consistent editing style:
838 *** Local Variables: ***
840 *** fill-column: 75 ***
842 *** c-basic-offset: 8 ***