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);
163 return scnprintf(buf, PAGE_SIZE, "%d\n", val);
166 static ssize_t show_val_norm(struct device *class_dev,
167 struct device_attribute *attr,
170 struct pvr2_sysfs_ctl_item *cip;
173 unsigned int cnt = 0;
174 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_val);
175 ret = pvr2_ctrl_get_value(cip->cptr, &val);
176 if (ret < 0) return ret;
177 ret = pvr2_ctrl_value_to_sym(cip->cptr, ~0, val,
178 buf, PAGE_SIZE - 1, &cnt);
179 pvr2_sysfs_trace("pvr2_sysfs(%p) show_val_norm(cid=%d) is %.*s (%d)",
180 cip->chptr, cip->ctl_id, cnt, buf, val);
185 static ssize_t show_val_custom(struct device *class_dev,
186 struct device_attribute *attr,
189 struct pvr2_sysfs_ctl_item *cip;
192 unsigned int cnt = 0;
193 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_custom);
194 ret = pvr2_ctrl_get_value(cip->cptr, &val);
195 if (ret < 0) return ret;
196 ret = pvr2_ctrl_custom_value_to_sym(cip->cptr, ~0, val,
197 buf, PAGE_SIZE - 1, &cnt);
198 pvr2_sysfs_trace("pvr2_sysfs(%p) show_val_custom(cid=%d) is %.*s (%d)",
199 cip->chptr, cip->ctl_id, cnt, buf, val);
204 static ssize_t show_enum(struct device *class_dev,
205 struct device_attribute *attr,
208 struct pvr2_sysfs_ctl_item *cip;
210 unsigned int bcnt, ccnt, ecnt;
211 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_enum);
212 ecnt = pvr2_ctrl_get_cnt(cip->cptr);
214 for (val = 0; val < ecnt; val++) {
215 pvr2_ctrl_get_valname(cip->cptr, val, buf + bcnt,
216 PAGE_SIZE - bcnt, &ccnt);
219 if (bcnt >= PAGE_SIZE) break;
223 pvr2_sysfs_trace("pvr2_sysfs(%p) show_enum(cid=%d)",
224 cip->chptr, cip->ctl_id);
228 static ssize_t show_bits(struct device *class_dev,
229 struct device_attribute *attr,
232 struct pvr2_sysfs_ctl_item *cip;
234 unsigned int bcnt, ccnt;
235 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_bits);
236 valid_bits = pvr2_ctrl_get_mask(cip->cptr);
238 for (msk = 1; valid_bits; msk <<= 1) {
239 if (!(msk & valid_bits)) continue;
241 pvr2_ctrl_get_valname(cip->cptr, msk, buf + bcnt,
242 PAGE_SIZE - bcnt, &ccnt);
244 if (bcnt >= PAGE_SIZE) break;
248 pvr2_sysfs_trace("pvr2_sysfs(%p) show_bits(cid=%d)",
249 cip->chptr, cip->ctl_id);
253 static int store_val_any(struct pvr2_sysfs_ctl_item *cip, int customfl,
254 const char *buf,unsigned int count)
259 ret = pvr2_ctrl_custom_sym_to_value(cip->cptr, buf, count,
262 ret = pvr2_ctrl_sym_to_value(cip->cptr, buf, count,
265 if (ret < 0) return ret;
266 ret = pvr2_ctrl_set_mask_value(cip->cptr, mask, val);
267 pvr2_hdw_commit_ctl(cip->chptr->channel.hdw);
271 static ssize_t store_val_norm(struct device *class_dev,
272 struct device_attribute *attr,
273 const char *buf, size_t count)
275 struct pvr2_sysfs_ctl_item *cip;
277 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_val);
278 pvr2_sysfs_trace("pvr2_sysfs(%p) store_val_norm(cid=%d) \"%.*s\"",
279 cip->chptr, cip->ctl_id, (int)count, buf);
280 ret = store_val_any(cip, 0, buf, count);
281 if (!ret) ret = count;
285 static ssize_t store_val_custom(struct device *class_dev,
286 struct device_attribute *attr,
287 const char *buf, size_t count)
289 struct pvr2_sysfs_ctl_item *cip;
291 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_custom);
292 pvr2_sysfs_trace("pvr2_sysfs(%p) store_val_custom(cid=%d) \"%.*s\"",
293 cip->chptr, cip->ctl_id, (int)count, buf);
294 ret = store_val_any(cip, 1, buf, count);
295 if (!ret) ret = count;
299 static void pvr2_sysfs_add_control(struct pvr2_sysfs *sfp,int ctl_id)
301 struct pvr2_sysfs_ctl_item *cip;
302 struct pvr2_ctrl *cptr;
303 unsigned int cnt,acnt;
306 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,ctl_id);
309 cip = kzalloc(sizeof(*cip),GFP_KERNEL);
311 pvr2_sysfs_trace("Creating pvr2_sysfs_ctl_item id=%p",cip);
314 cip->ctl_id = ctl_id;
317 cip->item_next = NULL;
318 if (sfp->item_last) {
319 sfp->item_last->item_next = cip;
321 sfp->item_first = cip;
323 sfp->item_last = cip;
325 cip->attr_name.attr.name = "name";
326 cip->attr_name.attr.mode = S_IRUGO;
327 cip->attr_name.show = show_name;
329 cip->attr_type.attr.name = "type";
330 cip->attr_type.attr.mode = S_IRUGO;
331 cip->attr_type.show = show_type;
333 cip->attr_min.attr.name = "min_val";
334 cip->attr_min.attr.mode = S_IRUGO;
335 cip->attr_min.show = show_min;
337 cip->attr_max.attr.name = "max_val";
338 cip->attr_max.attr.mode = S_IRUGO;
339 cip->attr_max.show = show_max;
341 cip->attr_def.attr.name = "def_val";
342 cip->attr_def.attr.mode = S_IRUGO;
343 cip->attr_def.show = show_def;
345 cip->attr_val.attr.name = "cur_val";
346 cip->attr_val.attr.mode = S_IRUGO;
348 cip->attr_custom.attr.name = "custom_val";
349 cip->attr_custom.attr.mode = S_IRUGO;
351 cip->attr_enum.attr.name = "enum_val";
352 cip->attr_enum.attr.mode = S_IRUGO;
353 cip->attr_enum.show = show_enum;
355 cip->attr_bits.attr.name = "bit_val";
356 cip->attr_bits.attr.mode = S_IRUGO;
357 cip->attr_bits.show = show_bits;
359 if (pvr2_ctrl_is_writable(cptr)) {
360 cip->attr_val.attr.mode |= S_IWUSR|S_IWGRP;
361 cip->attr_custom.attr.mode |= S_IWUSR|S_IWGRP;
365 cip->attr_gen[acnt++] = &cip->attr_name.attr;
366 cip->attr_gen[acnt++] = &cip->attr_type.attr;
367 cip->attr_gen[acnt++] = &cip->attr_val.attr;
368 cip->attr_gen[acnt++] = &cip->attr_def.attr;
369 cip->attr_val.show = show_val_norm;
370 cip->attr_val.store = store_val_norm;
371 if (pvr2_ctrl_has_custom_symbols(cptr)) {
372 cip->attr_gen[acnt++] = &cip->attr_custom.attr;
373 cip->attr_custom.show = show_val_custom;
374 cip->attr_custom.store = store_val_custom;
376 switch (pvr2_ctrl_get_type(cptr)) {
378 // Control is an enumeration
379 cip->attr_gen[acnt++] = &cip->attr_enum.attr;
382 // Control is an integer
383 cip->attr_gen[acnt++] = &cip->attr_min.attr;
384 cip->attr_gen[acnt++] = &cip->attr_max.attr;
386 case pvr2_ctl_bitmask:
387 // Control is an bitmask
388 cip->attr_gen[acnt++] = &cip->attr_bits.attr;
393 cnt = scnprintf(cip->name,sizeof(cip->name)-1,"ctl_%s",
394 pvr2_ctrl_get_name(cptr));
396 cip->grp.name = cip->name;
397 cip->grp.attrs = cip->attr_gen;
399 ret = sysfs_create_group(&sfp->class_dev->kobj,&cip->grp);
401 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
402 "sysfs_create_group error: %d",
406 cip->created_ok = !0;
409 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
410 static ssize_t debuginfo_show(struct device *, struct device_attribute *,
412 static ssize_t debugcmd_show(struct device *, struct device_attribute *,
414 static ssize_t debugcmd_store(struct device *, struct device_attribute *,
415 const char *, size_t count);
417 static void pvr2_sysfs_add_debugifc(struct pvr2_sysfs *sfp)
419 struct pvr2_sysfs_debugifc *dip;
422 dip = kzalloc(sizeof(*dip),GFP_KERNEL);
424 dip->attr_debugcmd.attr.name = "debugcmd";
425 dip->attr_debugcmd.attr.mode = S_IRUGO|S_IWUSR|S_IWGRP;
426 dip->attr_debugcmd.show = debugcmd_show;
427 dip->attr_debugcmd.store = debugcmd_store;
428 dip->attr_debuginfo.attr.name = "debuginfo";
429 dip->attr_debuginfo.attr.mode = S_IRUGO;
430 dip->attr_debuginfo.show = debuginfo_show;
432 ret = device_create_file(sfp->class_dev,&dip->attr_debugcmd);
434 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
435 "device_create_file error: %d",
438 dip->debugcmd_created_ok = !0;
440 ret = device_create_file(sfp->class_dev,&dip->attr_debuginfo);
442 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
443 "device_create_file error: %d",
446 dip->debuginfo_created_ok = !0;
451 static void pvr2_sysfs_tear_down_debugifc(struct pvr2_sysfs *sfp)
453 if (!sfp->debugifc) return;
454 if (sfp->debugifc->debuginfo_created_ok) {
455 device_remove_file(sfp->class_dev,
456 &sfp->debugifc->attr_debuginfo);
458 if (sfp->debugifc->debugcmd_created_ok) {
459 device_remove_file(sfp->class_dev,
460 &sfp->debugifc->attr_debugcmd);
462 kfree(sfp->debugifc);
463 sfp->debugifc = NULL;
465 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
468 static void pvr2_sysfs_add_controls(struct pvr2_sysfs *sfp)
470 unsigned int idx,cnt;
471 cnt = pvr2_hdw_get_ctrl_count(sfp->channel.hdw);
472 for (idx = 0; idx < cnt; idx++) {
473 pvr2_sysfs_add_control(sfp,idx);
478 static void pvr2_sysfs_tear_down_controls(struct pvr2_sysfs *sfp)
480 struct pvr2_sysfs_ctl_item *cip1,*cip2;
481 for (cip1 = sfp->item_first; cip1; cip1 = cip2) {
482 cip2 = cip1->item_next;
483 if (cip1->created_ok) {
484 sysfs_remove_group(&sfp->class_dev->kobj,&cip1->grp);
486 pvr2_sysfs_trace("Destroying pvr2_sysfs_ctl_item id=%p",cip1);
492 static void pvr2_sysfs_class_release(struct class *class)
494 struct pvr2_sysfs_class *clp;
495 clp = container_of(class,struct pvr2_sysfs_class,class);
496 pvr2_sysfs_trace("Destroying pvr2_sysfs_class id=%p",clp);
501 static void pvr2_sysfs_release(struct device *class_dev)
503 pvr2_sysfs_trace("Releasing class_dev id=%p",class_dev);
508 static void class_dev_destroy(struct pvr2_sysfs *sfp)
510 if (!sfp->class_dev) return;
511 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
512 pvr2_sysfs_tear_down_debugifc(sfp);
513 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
514 pvr2_sysfs_tear_down_controls(sfp);
515 if (sfp->hdw_desc_created_ok) {
516 device_remove_file(sfp->class_dev,
517 &sfp->attr_hdw_desc);
519 if (sfp->hdw_name_created_ok) {
520 device_remove_file(sfp->class_dev,
521 &sfp->attr_hdw_name);
523 if (sfp->bus_info_created_ok) {
524 device_remove_file(sfp->class_dev,
525 &sfp->attr_bus_info);
527 if (sfp->v4l_minor_number_created_ok) {
528 device_remove_file(sfp->class_dev,
529 &sfp->attr_v4l_minor_number);
531 if (sfp->v4l_radio_minor_number_created_ok) {
532 device_remove_file(sfp->class_dev,
533 &sfp->attr_v4l_radio_minor_number);
535 if (sfp->unit_number_created_ok) {
536 device_remove_file(sfp->class_dev,
537 &sfp->attr_unit_number);
539 pvr2_sysfs_trace("Destroying class_dev id=%p",sfp->class_dev);
540 sfp->class_dev->driver_data = NULL;
541 device_unregister(sfp->class_dev);
542 sfp->class_dev = NULL;
546 static ssize_t v4l_minor_number_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,"%d\n",
553 pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw,
554 pvr2_v4l_type_video));
558 static ssize_t bus_info_show(struct device *class_dev,
559 struct device_attribute *attr, char *buf)
561 struct pvr2_sysfs *sfp;
562 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
563 if (!sfp) return -EINVAL;
564 return scnprintf(buf,PAGE_SIZE,"%s\n",
565 pvr2_hdw_get_bus_info(sfp->channel.hdw));
569 static ssize_t hdw_name_show(struct device *class_dev,
570 struct device_attribute *attr, char *buf)
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,"%s\n",
576 pvr2_hdw_get_type(sfp->channel.hdw));
580 static ssize_t hdw_desc_show(struct device *class_dev,
581 struct device_attribute *attr, char *buf)
583 struct pvr2_sysfs *sfp;
584 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
585 if (!sfp) return -EINVAL;
586 return scnprintf(buf,PAGE_SIZE,"%s\n",
587 pvr2_hdw_get_desc(sfp->channel.hdw));
591 static ssize_t v4l_radio_minor_number_show(struct device *class_dev,
592 struct device_attribute *attr,
595 struct pvr2_sysfs *sfp;
596 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
597 if (!sfp) return -EINVAL;
598 return scnprintf(buf,PAGE_SIZE,"%d\n",
599 pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw,
600 pvr2_v4l_type_radio));
604 static ssize_t unit_number_show(struct device *class_dev,
605 struct device_attribute *attr, char *buf)
607 struct pvr2_sysfs *sfp;
608 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
609 if (!sfp) return -EINVAL;
610 return scnprintf(buf,PAGE_SIZE,"%d\n",
611 pvr2_hdw_get_unit_number(sfp->channel.hdw));
615 static void class_dev_create(struct pvr2_sysfs *sfp,
616 struct pvr2_sysfs_class *class_ptr)
618 struct usb_device *usb_dev;
619 struct device *class_dev;
622 usb_dev = pvr2_hdw_get_dev(sfp->channel.hdw);
623 if (!usb_dev) return;
624 class_dev = kzalloc(sizeof(*class_dev),GFP_KERNEL);
625 if (!class_dev) return;
627 pvr2_sysfs_trace("Creating class_dev id=%p",class_dev);
629 class_dev->class = &class_ptr->class;
630 if (pvr2_hdw_get_sn(sfp->channel.hdw)) {
631 dev_set_name(class_dev, "sn-%lu",
632 pvr2_hdw_get_sn(sfp->channel.hdw));
633 } else if (pvr2_hdw_get_unit_number(sfp->channel.hdw) >= 0) {
634 dev_set_name(class_dev, "unit-%c",
635 pvr2_hdw_get_unit_number(sfp->channel.hdw) + 'a');
641 class_dev->parent = &usb_dev->dev;
643 sfp->class_dev = class_dev;
644 class_dev->driver_data = sfp;
645 ret = device_register(class_dev);
647 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
648 "device_register failed");
653 sfp->attr_v4l_minor_number.attr.name = "v4l_minor_number";
654 sfp->attr_v4l_minor_number.attr.mode = S_IRUGO;
655 sfp->attr_v4l_minor_number.show = v4l_minor_number_show;
656 sfp->attr_v4l_minor_number.store = NULL;
657 ret = device_create_file(sfp->class_dev,
658 &sfp->attr_v4l_minor_number);
660 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
661 "device_create_file error: %d",
664 sfp->v4l_minor_number_created_ok = !0;
667 sfp->attr_v4l_radio_minor_number.attr.name = "v4l_radio_minor_number";
668 sfp->attr_v4l_radio_minor_number.attr.mode = S_IRUGO;
669 sfp->attr_v4l_radio_minor_number.show = v4l_radio_minor_number_show;
670 sfp->attr_v4l_radio_minor_number.store = NULL;
671 ret = device_create_file(sfp->class_dev,
672 &sfp->attr_v4l_radio_minor_number);
674 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
675 "device_create_file error: %d",
678 sfp->v4l_radio_minor_number_created_ok = !0;
681 sfp->attr_unit_number.attr.name = "unit_number";
682 sfp->attr_unit_number.attr.mode = S_IRUGO;
683 sfp->attr_unit_number.show = unit_number_show;
684 sfp->attr_unit_number.store = NULL;
685 ret = device_create_file(sfp->class_dev,&sfp->attr_unit_number);
687 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
688 "device_create_file error: %d",
691 sfp->unit_number_created_ok = !0;
694 sfp->attr_bus_info.attr.name = "bus_info_str";
695 sfp->attr_bus_info.attr.mode = S_IRUGO;
696 sfp->attr_bus_info.show = bus_info_show;
697 sfp->attr_bus_info.store = NULL;
698 ret = device_create_file(sfp->class_dev,
699 &sfp->attr_bus_info);
701 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
702 "device_create_file error: %d",
705 sfp->bus_info_created_ok = !0;
708 sfp->attr_hdw_name.attr.name = "device_hardware_type";
709 sfp->attr_hdw_name.attr.mode = S_IRUGO;
710 sfp->attr_hdw_name.show = hdw_name_show;
711 sfp->attr_hdw_name.store = NULL;
712 ret = device_create_file(sfp->class_dev,
713 &sfp->attr_hdw_name);
715 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
716 "device_create_file error: %d",
719 sfp->hdw_name_created_ok = !0;
722 sfp->attr_hdw_desc.attr.name = "device_hardware_description";
723 sfp->attr_hdw_desc.attr.mode = S_IRUGO;
724 sfp->attr_hdw_desc.show = hdw_desc_show;
725 sfp->attr_hdw_desc.store = NULL;
726 ret = device_create_file(sfp->class_dev,
727 &sfp->attr_hdw_desc);
729 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
730 "device_create_file error: %d",
733 sfp->hdw_desc_created_ok = !0;
736 pvr2_sysfs_add_controls(sfp);
737 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
738 pvr2_sysfs_add_debugifc(sfp);
739 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
743 static void pvr2_sysfs_internal_check(struct pvr2_channel *chp)
745 struct pvr2_sysfs *sfp;
746 sfp = container_of(chp,struct pvr2_sysfs,channel);
747 if (!sfp->channel.mc_head->disconnect_flag) return;
748 pvr2_trace(PVR2_TRACE_STRUCT,"Destroying pvr2_sysfs id=%p",sfp);
749 class_dev_destroy(sfp);
750 pvr2_channel_done(&sfp->channel);
755 struct pvr2_sysfs *pvr2_sysfs_create(struct pvr2_context *mp,
756 struct pvr2_sysfs_class *class_ptr)
758 struct pvr2_sysfs *sfp;
759 sfp = kzalloc(sizeof(*sfp),GFP_KERNEL);
760 if (!sfp) return sfp;
761 pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr2_sysfs id=%p",sfp);
762 pvr2_channel_init(&sfp->channel,mp);
763 sfp->channel.check_func = pvr2_sysfs_internal_check;
765 class_dev_create(sfp,class_ptr);
771 struct pvr2_sysfs_class *pvr2_sysfs_class_create(void)
773 struct pvr2_sysfs_class *clp;
774 clp = kzalloc(sizeof(*clp),GFP_KERNEL);
775 if (!clp) return clp;
776 pvr2_sysfs_trace("Creating pvr2_sysfs_class id=%p",clp);
777 clp->class.name = "pvrusb2";
778 clp->class.class_release = pvr2_sysfs_class_release;
779 clp->class.dev_release = pvr2_sysfs_release;
780 if (class_register(&clp->class)) {
782 "Registration failed for pvr2_sysfs_class id=%p",clp);
790 void pvr2_sysfs_class_destroy(struct pvr2_sysfs_class *clp)
792 class_unregister(&clp->class);
796 #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
797 static ssize_t debuginfo_show(struct device *class_dev,
798 struct device_attribute *attr, char *buf)
800 struct pvr2_sysfs *sfp;
801 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
802 if (!sfp) return -EINVAL;
803 pvr2_hdw_trigger_module_log(sfp->channel.hdw);
804 return pvr2_debugifc_print_info(sfp->channel.hdw,buf,PAGE_SIZE);
808 static ssize_t debugcmd_show(struct device *class_dev,
809 struct device_attribute *attr, char *buf)
811 struct pvr2_sysfs *sfp;
812 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
813 if (!sfp) return -EINVAL;
814 return pvr2_debugifc_print_status(sfp->channel.hdw,buf,PAGE_SIZE);
818 static ssize_t debugcmd_store(struct device *class_dev,
819 struct device_attribute *attr,
820 const char *buf, size_t count)
822 struct pvr2_sysfs *sfp;
825 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
826 if (!sfp) return -EINVAL;
828 ret = pvr2_debugifc_docmd(sfp->channel.hdw,buf,count);
829 if (ret < 0) return ret;
832 #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
836 Stuff for Emacs to see, in order to encourage consistent editing style:
837 *** Local Variables: ***
839 *** fill-column: 75 ***
841 *** c-basic-offset: 8 ***