blob: 46a8c39ba03028fc07ecd7392d2fd44522779869 [file] [log] [blame]
Mike Iselyd8554972006-06-26 20:58:46 -03001/*
2 *
Mike Iselyd8554972006-06-26 20:58:46 -03003 *
4 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
5 *
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
9 *
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.
14 *
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
18 *
19 */
20
Mike Iselyd8554972006-06-26 20:58:46 -030021#include <linux/string.h>
22#include <linux/slab.h>
Mike Iselyd8554972006-06-26 20:58:46 -030023#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 */
29
30#define pvr2_sysfs_trace(...) pvr2_trace(PVR2_TRACE_SYSFS,__VA_ARGS__)
31
32struct pvr2_sysfs {
33 struct pvr2_channel channel;
Kay Sievers54bd5b62007-10-08 16:26:13 -030034 struct device *class_dev;
Mike Iselyd8554972006-06-26 20:58:46 -030035#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;
Kay Sievers54bd5b62007-10-08 16:26:13 -030040 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;
Mike Isely78a47102007-11-26 01:58:20 -030044 struct device_attribute attr_hdw_name;
45 struct device_attribute attr_hdw_desc;
Mike Isely08d41802006-07-22 21:26:30 -030046 int v4l_minor_number_created_ok;
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -030047 int v4l_radio_minor_number_created_ok;
Mike Isely08d41802006-07-22 21:26:30 -030048 int unit_number_created_ok;
Mike Isely31a18542007-04-08 01:11:47 -030049 int bus_info_created_ok;
Mike Isely78a47102007-11-26 01:58:20 -030050 int hdw_name_created_ok;
51 int hdw_desc_created_ok;
Mike Iselyd8554972006-06-26 20:58:46 -030052};
53
54#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
55struct pvr2_sysfs_debugifc {
Kay Sievers54bd5b62007-10-08 16:26:13 -030056 struct device_attribute attr_debugcmd;
57 struct device_attribute attr_debuginfo;
Mike Isely08d41802006-07-22 21:26:30 -030058 int debugcmd_created_ok;
59 int debuginfo_created_ok;
Mike Iselyd8554972006-06-26 20:58:46 -030060};
61#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
62
63struct pvr2_sysfs_ctl_item {
Kay Sievers54bd5b62007-10-08 16:26:13 -030064 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;
Mike Iselyd8554972006-06-26 20:58:46 -030072 struct pvr2_ctrl *cptr;
Mike Iselyf90fe7a2008-05-26 06:00:47 -030073 int ctl_id;
Mike Iselyd8554972006-06-26 20:58:46 -030074 struct pvr2_sysfs *chptr;
75 struct pvr2_sysfs_ctl_item *item_next;
Mike Isely33213962006-06-25 20:04:40 -030076 struct attribute *attr_gen[7];
Mike Iselyd8554972006-06-26 20:58:46 -030077 struct attribute_group grp;
Mike Isely08d41802006-07-22 21:26:30 -030078 int created_ok;
Mike Iselyd8554972006-06-26 20:58:46 -030079 char name[80];
80};
81
82struct pvr2_sysfs_class {
83 struct class class;
84};
85
Mike Iselyf90fe7a2008-05-26 06:00:47 -030086static ssize_t show_name(struct device *class_dev,
87 struct device_attribute *attr,
88 char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -030089{
Mike Iselyf90fe7a2008-05-26 06:00:47 -030090 struct pvr2_sysfs_ctl_item *cip;
Mike Iselyd8554972006-06-26 20:58:46 -030091 const char *name;
Mike Iselyf90fe7a2008-05-26 06:00:47 -030092 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);
Mike Iselyd8554972006-06-26 20:58:46 -030096 if (!name) return -EINVAL;
Mike Iselyf90fe7a2008-05-26 06:00:47 -030097 return scnprintf(buf, PAGE_SIZE, "%s\n", name);
Mike Iselyd8554972006-06-26 20:58:46 -030098}
99
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300100static ssize_t show_type(struct device *class_dev,
101 struct device_attribute *attr,
102 char *buf)
Mike Isely33213962006-06-25 20:04:40 -0300103{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300104 struct pvr2_sysfs_ctl_item *cip;
Mike Isely33213962006-06-25 20:04:40 -0300105 const char *name;
106 enum pvr2_ctl_type tp;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300107 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_type);
108 tp = pvr2_ctrl_get_type(cip->cptr);
Mike Isely33213962006-06-25 20:04:40 -0300109 switch (tp) {
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;
115 }
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300116 pvr2_sysfs_trace("pvr2_sysfs(%p) show_type(cid=%d) is %s",
117 cip->chptr, cip->ctl_id, name);
Mike Isely33213962006-06-25 20:04:40 -0300118 if (!name) return -EINVAL;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300119 return scnprintf(buf, PAGE_SIZE, "%s\n", name);
Mike Isely33213962006-06-25 20:04:40 -0300120}
121
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300122static ssize_t show_min(struct device *class_dev,
123 struct device_attribute *attr,
124 char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300125{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300126 struct pvr2_sysfs_ctl_item *cip;
Mike Iselyd8554972006-06-26 20:58:46 -0300127 long val;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300128 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);
Mike Iselyd8554972006-06-26 20:58:46 -0300133}
134
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300135static ssize_t show_max(struct device *class_dev,
136 struct device_attribute *attr,
137 char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300138{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300139 struct pvr2_sysfs_ctl_item *cip;
Mike Iselyd8554972006-06-26 20:58:46 -0300140 long val;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300141 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);
Mike Iselyd8554972006-06-26 20:58:46 -0300146}
147
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300148static ssize_t show_val_norm(struct device *class_dev,
149 struct device_attribute *attr,
150 char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300151{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300152 struct pvr2_sysfs_ctl_item *cip;
153 int val;
154 int ret;
Mike Iselyd8554972006-06-26 20:58:46 -0300155 unsigned int cnt = 0;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300156 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_val);
157 ret = pvr2_ctrl_get_value(cip->cptr, &val);
Mike Iselyd8554972006-06-26 20:58:46 -0300158 if (ret < 0) return ret;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300159 ret = pvr2_ctrl_value_to_sym(cip->cptr, ~0, val,
160 buf, PAGE_SIZE - 1, &cnt);
Mike Iselyd8554972006-06-26 20:58:46 -0300161 pvr2_sysfs_trace("pvr2_sysfs(%p) show_val_norm(cid=%d) is %.*s (%d)",
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300162 cip->chptr, cip->ctl_id, cnt, buf, val);
Mike Iselyd8554972006-06-26 20:58:46 -0300163 buf[cnt] = '\n';
164 return cnt+1;
165}
166
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300167static ssize_t show_val_custom(struct device *class_dev,
168 struct device_attribute *attr,
169 char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300170{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300171 struct pvr2_sysfs_ctl_item *cip;
172 int val;
173 int ret;
Mike Iselyd8554972006-06-26 20:58:46 -0300174 unsigned int cnt = 0;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300175 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_custom);
176 ret = pvr2_ctrl_get_value(cip->cptr, &val);
Mike Iselyd8554972006-06-26 20:58:46 -0300177 if (ret < 0) return ret;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300178 ret = pvr2_ctrl_custom_value_to_sym(cip->cptr, ~0, val,
179 buf, PAGE_SIZE - 1, &cnt);
Mike Iselyd8554972006-06-26 20:58:46 -0300180 pvr2_sysfs_trace("pvr2_sysfs(%p) show_val_custom(cid=%d) is %.*s (%d)",
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300181 cip->chptr, cip->ctl_id, cnt, buf, val);
Mike Iselyd8554972006-06-26 20:58:46 -0300182 buf[cnt] = '\n';
183 return cnt+1;
184}
185
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300186static ssize_t show_enum(struct device *class_dev,
187 struct device_attribute *attr,
188 char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300189{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300190 struct pvr2_sysfs_ctl_item *cip;
Mike Iselyd8554972006-06-26 20:58:46 -0300191 long val;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300192 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);
Mike Iselyd8554972006-06-26 20:58:46 -0300195 bcnt = 0;
196 for (val = 0; val < ecnt; val++) {
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300197 pvr2_ctrl_get_valname(cip->cptr, val, buf + bcnt,
198 PAGE_SIZE - bcnt, &ccnt);
Mike Isely45886772006-06-25 20:04:13 -0300199 if (!ccnt) continue;
Mike Iselyd8554972006-06-26 20:58:46 -0300200 bcnt += ccnt;
201 if (bcnt >= PAGE_SIZE) break;
202 buf[bcnt] = '\n';
203 bcnt++;
204 }
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300205 pvr2_sysfs_trace("pvr2_sysfs(%p) show_enum(cid=%d)",
206 cip->chptr, cip->ctl_id);
Mike Iselyd8554972006-06-26 20:58:46 -0300207 return bcnt;
208}
209
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300210static ssize_t show_bits(struct device *class_dev,
211 struct device_attribute *attr,
212 char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300213{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300214 struct pvr2_sysfs_ctl_item *cip;
215 int valid_bits, msk;
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);
Mike Iselyd8554972006-06-26 20:58:46 -0300219 bcnt = 0;
220 for (msk = 1; valid_bits; msk <<= 1) {
221 if (!(msk & valid_bits)) continue;
222 valid_bits &= ~msk;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300223 pvr2_ctrl_get_valname(cip->cptr, msk, buf + bcnt,
224 PAGE_SIZE - bcnt, &ccnt);
Mike Iselyd8554972006-06-26 20:58:46 -0300225 bcnt += ccnt;
226 if (bcnt >= PAGE_SIZE) break;
227 buf[bcnt] = '\n';
228 bcnt++;
229 }
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300230 pvr2_sysfs_trace("pvr2_sysfs(%p) show_bits(cid=%d)",
231 cip->chptr, cip->ctl_id);
Mike Iselyd8554972006-06-26 20:58:46 -0300232 return bcnt;
233}
234
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300235static int store_val_any(struct pvr2_sysfs_ctl_item *cip, int customfl,
Mike Iselyd8554972006-06-26 20:58:46 -0300236 const char *buf,unsigned int count)
237{
Mike Iselyd8554972006-06-26 20:58:46 -0300238 int ret;
239 int mask,val;
Mike Iselyd8554972006-06-26 20:58:46 -0300240 if (customfl) {
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300241 ret = pvr2_ctrl_custom_sym_to_value(cip->cptr, buf, count,
242 &mask, &val);
Mike Iselyd8554972006-06-26 20:58:46 -0300243 } else {
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300244 ret = pvr2_ctrl_sym_to_value(cip->cptr, buf, count,
245 &mask, &val);
Mike Iselyd8554972006-06-26 20:58:46 -0300246 }
247 if (ret < 0) return ret;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300248 ret = pvr2_ctrl_set_mask_value(cip->cptr, mask, val);
249 pvr2_hdw_commit_ctl(cip->chptr->channel.hdw);
Mike Iselyd8554972006-06-26 20:58:46 -0300250 return ret;
251}
252
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300253static ssize_t store_val_norm(struct device *class_dev,
254 struct device_attribute *attr,
255 const char *buf, size_t count)
Mike Iselyd8554972006-06-26 20:58:46 -0300256{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300257 struct pvr2_sysfs_ctl_item *cip;
Mike Iselyd8554972006-06-26 20:58:46 -0300258 int ret;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300259 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_val);
Mike Iselybedbbf82008-04-22 14:45:38 -0300260 pvr2_sysfs_trace("pvr2_sysfs(%p) store_val_norm(cid=%d) \"%.*s\"",
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300261 cip->chptr, cip->ctl_id, (int)count, buf);
262 ret = store_val_any(cip, 0, buf, count);
Mike Iselyd8554972006-06-26 20:58:46 -0300263 if (!ret) ret = count;
264 return ret;
265}
266
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300267static ssize_t store_val_custom(struct device *class_dev,
268 struct device_attribute *attr,
269 const char *buf, size_t count)
Mike Iselyd8554972006-06-26 20:58:46 -0300270{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300271 struct pvr2_sysfs_ctl_item *cip;
Mike Iselyd8554972006-06-26 20:58:46 -0300272 int ret;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300273 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_custom);
Mike Iselybedbbf82008-04-22 14:45:38 -0300274 pvr2_sysfs_trace("pvr2_sysfs(%p) store_val_custom(cid=%d) \"%.*s\"",
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300275 cip->chptr, cip->ctl_id, (int)count, buf);
276 ret = store_val_any(cip, 1, buf, count);
Mike Iselyd8554972006-06-26 20:58:46 -0300277 if (!ret) ret = count;
278 return ret;
279}
280
Mike Iselyd8554972006-06-26 20:58:46 -0300281static void pvr2_sysfs_add_control(struct pvr2_sysfs *sfp,int ctl_id)
282{
283 struct pvr2_sysfs_ctl_item *cip;
Mike Iselyd8554972006-06-26 20:58:46 -0300284 struct pvr2_ctrl *cptr;
285 unsigned int cnt,acnt;
Mike Isely08d41802006-07-22 21:26:30 -0300286 int ret;
Mike Iselyd8554972006-06-26 20:58:46 -0300287
Mike Iselyd8554972006-06-26 20:58:46 -0300288 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,ctl_id);
289 if (!cptr) return;
290
Mike Iselyca545f72007-01-20 00:37:11 -0300291 cip = kzalloc(sizeof(*cip),GFP_KERNEL);
Mike Iselyd8554972006-06-26 20:58:46 -0300292 if (!cip) return;
Mike Iselyd8554972006-06-26 20:58:46 -0300293 pvr2_sysfs_trace("Creating pvr2_sysfs_ctl_item id=%p",cip);
294
295 cip->cptr = cptr;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300296 cip->ctl_id = ctl_id;
Mike Iselyd8554972006-06-26 20:58:46 -0300297
298 cip->chptr = sfp;
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300299 cip->item_next = NULL;
Mike Iselyd8554972006-06-26 20:58:46 -0300300 if (sfp->item_last) {
301 sfp->item_last->item_next = cip;
302 } else {
303 sfp->item_first = cip;
304 }
305 sfp->item_last = cip;
306
Mike Iselyd8554972006-06-26 20:58:46 -0300307 cip->attr_name.attr.name = "name";
308 cip->attr_name.attr.mode = S_IRUGO;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300309 cip->attr_name.show = show_name;
Mike Iselyd8554972006-06-26 20:58:46 -0300310
Mike Isely33213962006-06-25 20:04:40 -0300311 cip->attr_type.attr.name = "type";
312 cip->attr_type.attr.mode = S_IRUGO;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300313 cip->attr_type.show = show_type;
Mike Isely33213962006-06-25 20:04:40 -0300314
Mike Iselyd8554972006-06-26 20:58:46 -0300315 cip->attr_min.attr.name = "min_val";
316 cip->attr_min.attr.mode = S_IRUGO;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300317 cip->attr_min.show = show_min;
Mike Iselyd8554972006-06-26 20:58:46 -0300318
Mike Iselyd8554972006-06-26 20:58:46 -0300319 cip->attr_max.attr.name = "max_val";
320 cip->attr_max.attr.mode = S_IRUGO;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300321 cip->attr_max.show = show_max;
Mike Iselyd8554972006-06-26 20:58:46 -0300322
Mike Iselyd8554972006-06-26 20:58:46 -0300323 cip->attr_val.attr.name = "cur_val";
324 cip->attr_val.attr.mode = S_IRUGO;
325
Mike Iselyd8554972006-06-26 20:58:46 -0300326 cip->attr_custom.attr.name = "custom_val";
327 cip->attr_custom.attr.mode = S_IRUGO;
328
Mike Iselyd8554972006-06-26 20:58:46 -0300329 cip->attr_enum.attr.name = "enum_val";
330 cip->attr_enum.attr.mode = S_IRUGO;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300331 cip->attr_enum.show = show_enum;
Mike Iselyd8554972006-06-26 20:58:46 -0300332
Mike Iselyd8554972006-06-26 20:58:46 -0300333 cip->attr_bits.attr.name = "bit_val";
334 cip->attr_bits.attr.mode = S_IRUGO;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300335 cip->attr_bits.show = show_bits;
Mike Iselyd8554972006-06-26 20:58:46 -0300336
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;
340 }
341
342 acnt = 0;
343 cip->attr_gen[acnt++] = &cip->attr_name.attr;
Mike Isely33213962006-06-25 20:04:40 -0300344 cip->attr_gen[acnt++] = &cip->attr_type.attr;
Mike Iselyd8554972006-06-26 20:58:46 -0300345 cip->attr_gen[acnt++] = &cip->attr_val.attr;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300346 cip->attr_val.show = show_val_norm;
347 cip->attr_val.store = store_val_norm;
Mike Iselyd8554972006-06-26 20:58:46 -0300348 if (pvr2_ctrl_has_custom_symbols(cptr)) {
349 cip->attr_gen[acnt++] = &cip->attr_custom.attr;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300350 cip->attr_custom.show = show_val_custom;
351 cip->attr_custom.store = store_val_custom;
Mike Iselyd8554972006-06-26 20:58:46 -0300352 }
353 switch (pvr2_ctrl_get_type(cptr)) {
354 case pvr2_ctl_enum:
355 // Control is an enumeration
356 cip->attr_gen[acnt++] = &cip->attr_enum.attr;
357 break;
358 case pvr2_ctl_int:
359 // Control is an integer
360 cip->attr_gen[acnt++] = &cip->attr_min.attr;
361 cip->attr_gen[acnt++] = &cip->attr_max.attr;
362 break;
363 case pvr2_ctl_bitmask:
364 // Control is an bitmask
365 cip->attr_gen[acnt++] = &cip->attr_bits.attr;
366 break;
367 default: break;
368 }
369
370 cnt = scnprintf(cip->name,sizeof(cip->name)-1,"ctl_%s",
371 pvr2_ctrl_get_name(cptr));
372 cip->name[cnt] = 0;
373 cip->grp.name = cip->name;
374 cip->grp.attrs = cip->attr_gen;
375
Mike Isely08d41802006-07-22 21:26:30 -0300376 ret = sysfs_create_group(&sfp->class_dev->kobj,&cip->grp);
377 if (ret) {
Mike Isely49844c22008-04-09 05:44:57 -0300378 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
379 "sysfs_create_group error: %d",
380 ret);
Mike Isely08d41802006-07-22 21:26:30 -0300381 return;
382 }
383 cip->created_ok = !0;
Mike Iselyd8554972006-06-26 20:58:46 -0300384}
385
386#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
Trent Piephoc726b652007-10-08 19:05:28 -0300387static ssize_t debuginfo_show(struct device *, struct device_attribute *,
388 char *);
389static ssize_t debugcmd_show(struct device *, struct device_attribute *,
390 char *);
391static ssize_t debugcmd_store(struct device *, struct device_attribute *,
392 const char *, size_t count);
Mike Iselyd8554972006-06-26 20:58:46 -0300393
394static void pvr2_sysfs_add_debugifc(struct pvr2_sysfs *sfp)
395{
396 struct pvr2_sysfs_debugifc *dip;
Michael Krufky3117bee2006-07-19 13:23:38 -0300397 int ret;
398
Mike Iselyca545f72007-01-20 00:37:11 -0300399 dip = kzalloc(sizeof(*dip),GFP_KERNEL);
Mike Iselyd8554972006-06-26 20:58:46 -0300400 if (!dip) return;
Mike Iselyd8554972006-06-26 20:58:46 -0300401 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;
Mike Iselyd8554972006-06-26 20:58:46 -0300405 dip->attr_debuginfo.attr.name = "debuginfo";
406 dip->attr_debuginfo.attr.mode = S_IRUGO;
407 dip->attr_debuginfo.show = debuginfo_show;
408 sfp->debugifc = dip;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300409 ret = device_create_file(sfp->class_dev,&dip->attr_debugcmd);
Mike Isely08d41802006-07-22 21:26:30 -0300410 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300411 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
412 "device_create_file error: %d",
413 ret);
Mike Isely08d41802006-07-22 21:26:30 -0300414 } else {
415 dip->debugcmd_created_ok = !0;
416 }
Kay Sievers54bd5b62007-10-08 16:26:13 -0300417 ret = device_create_file(sfp->class_dev,&dip->attr_debuginfo);
Mike Isely08d41802006-07-22 21:26:30 -0300418 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300419 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
420 "device_create_file error: %d",
421 ret);
Mike Isely08d41802006-07-22 21:26:30 -0300422 } else {
423 dip->debuginfo_created_ok = !0;
424 }
Mike Iselyd8554972006-06-26 20:58:46 -0300425}
426
427
428static void pvr2_sysfs_tear_down_debugifc(struct pvr2_sysfs *sfp)
429{
430 if (!sfp->debugifc) return;
Mike Isely08d41802006-07-22 21:26:30 -0300431 if (sfp->debugifc->debuginfo_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300432 device_remove_file(sfp->class_dev,
Mike Isely08d41802006-07-22 21:26:30 -0300433 &sfp->debugifc->attr_debuginfo);
434 }
435 if (sfp->debugifc->debugcmd_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300436 device_remove_file(sfp->class_dev,
Mike Isely08d41802006-07-22 21:26:30 -0300437 &sfp->debugifc->attr_debugcmd);
438 }
Mike Iselyd8554972006-06-26 20:58:46 -0300439 kfree(sfp->debugifc);
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300440 sfp->debugifc = NULL;
Mike Iselyd8554972006-06-26 20:58:46 -0300441}
442#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
443
444
445static void pvr2_sysfs_add_controls(struct pvr2_sysfs *sfp)
446{
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);
451 }
452}
453
454
455static void pvr2_sysfs_tear_down_controls(struct pvr2_sysfs *sfp)
456{
457 struct pvr2_sysfs_ctl_item *cip1,*cip2;
458 for (cip1 = sfp->item_first; cip1; cip1 = cip2) {
459 cip2 = cip1->item_next;
Mike Isely08d41802006-07-22 21:26:30 -0300460 if (cip1->created_ok) {
461 sysfs_remove_group(&sfp->class_dev->kobj,&cip1->grp);
462 }
Mike Iselyd8554972006-06-26 20:58:46 -0300463 pvr2_sysfs_trace("Destroying pvr2_sysfs_ctl_item id=%p",cip1);
464 kfree(cip1);
465 }
466}
467
468
469static void pvr2_sysfs_class_release(struct class *class)
470{
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);
474 kfree(clp);
475}
476
477
Kay Sievers54bd5b62007-10-08 16:26:13 -0300478static void pvr2_sysfs_release(struct device *class_dev)
Mike Iselyd8554972006-06-26 20:58:46 -0300479{
480 pvr2_sysfs_trace("Releasing class_dev id=%p",class_dev);
481 kfree(class_dev);
482}
483
484
485static void class_dev_destroy(struct pvr2_sysfs *sfp)
486{
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);
Mike Isely78a47102007-11-26 01:58:20 -0300492 if (sfp->hdw_desc_created_ok) {
493 device_remove_file(sfp->class_dev,
494 &sfp->attr_hdw_desc);
495 }
496 if (sfp->hdw_name_created_ok) {
497 device_remove_file(sfp->class_dev,
498 &sfp->attr_hdw_name);
499 }
Mike Isely31a18542007-04-08 01:11:47 -0300500 if (sfp->bus_info_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300501 device_remove_file(sfp->class_dev,
Mike Isely31a18542007-04-08 01:11:47 -0300502 &sfp->attr_bus_info);
503 }
Mike Isely08d41802006-07-22 21:26:30 -0300504 if (sfp->v4l_minor_number_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300505 device_remove_file(sfp->class_dev,
Mike Isely08d41802006-07-22 21:26:30 -0300506 &sfp->attr_v4l_minor_number);
507 }
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300508 if (sfp->v4l_radio_minor_number_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300509 device_remove_file(sfp->class_dev,
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300510 &sfp->attr_v4l_radio_minor_number);
511 }
Mike Isely08d41802006-07-22 21:26:30 -0300512 if (sfp->unit_number_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300513 device_remove_file(sfp->class_dev,
Mike Isely08d41802006-07-22 21:26:30 -0300514 &sfp->attr_unit_number);
515 }
Mike Iselyd8554972006-06-26 20:58:46 -0300516 pvr2_sysfs_trace("Destroying class_dev id=%p",sfp->class_dev);
Kay Sievers54bd5b62007-10-08 16:26:13 -0300517 sfp->class_dev->driver_data = NULL;
518 device_unregister(sfp->class_dev);
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300519 sfp->class_dev = NULL;
Mike Iselyd8554972006-06-26 20:58:46 -0300520}
521
522
Kay Sievers54bd5b62007-10-08 16:26:13 -0300523static ssize_t v4l_minor_number_show(struct device *class_dev,
524 struct device_attribute *attr, char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300525{
526 struct pvr2_sysfs *sfp;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300527 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -0300528 if (!sfp) return -EINVAL;
529 return scnprintf(buf,PAGE_SIZE,"%d\n",
Mike Iselyfd5a75f2006-12-27 23:11:22 -0300530 pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw,
Mike Isely80793842006-12-27 23:12:28 -0300531 pvr2_v4l_type_video));
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300532}
533
534
Kay Sievers54bd5b62007-10-08 16:26:13 -0300535static ssize_t bus_info_show(struct device *class_dev,
536 struct device_attribute *attr, char *buf)
Mike Isely31a18542007-04-08 01:11:47 -0300537{
538 struct pvr2_sysfs *sfp;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300539 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Isely31a18542007-04-08 01:11:47 -0300540 if (!sfp) return -EINVAL;
541 return scnprintf(buf,PAGE_SIZE,"%s\n",
542 pvr2_hdw_get_bus_info(sfp->channel.hdw));
543}
544
545
Mike Isely78a47102007-11-26 01:58:20 -0300546static ssize_t hdw_name_show(struct device *class_dev,
547 struct device_attribute *attr, char *buf)
548{
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));
554}
555
556
557static ssize_t hdw_desc_show(struct device *class_dev,
558 struct device_attribute *attr, char *buf)
559{
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));
565}
566
567
Kay Sievers54bd5b62007-10-08 16:26:13 -0300568static ssize_t v4l_radio_minor_number_show(struct device *class_dev,
569 struct device_attribute *attr,
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300570 char *buf)
571{
572 struct pvr2_sysfs *sfp;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300573 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300574 if (!sfp) return -EINVAL;
575 return scnprintf(buf,PAGE_SIZE,"%d\n",
Mike Iselyfd5a75f2006-12-27 23:11:22 -0300576 pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw,
Mike Isely80793842006-12-27 23:12:28 -0300577 pvr2_v4l_type_radio));
Mike Iselyd8554972006-06-26 20:58:46 -0300578}
579
580
Kay Sievers54bd5b62007-10-08 16:26:13 -0300581static ssize_t unit_number_show(struct device *class_dev,
582 struct device_attribute *attr, char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300583{
584 struct pvr2_sysfs *sfp;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300585 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -0300586 if (!sfp) return -EINVAL;
587 return scnprintf(buf,PAGE_SIZE,"%d\n",
588 pvr2_hdw_get_unit_number(sfp->channel.hdw));
589}
590
591
592static void class_dev_create(struct pvr2_sysfs *sfp,
593 struct pvr2_sysfs_class *class_ptr)
594{
595 struct usb_device *usb_dev;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300596 struct device *class_dev;
Michael Krufky3117bee2006-07-19 13:23:38 -0300597 int ret;
598
Mike Iselyd8554972006-06-26 20:58:46 -0300599 usb_dev = pvr2_hdw_get_dev(sfp->channel.hdw);
600 if (!usb_dev) return;
Mike Iselyca545f72007-01-20 00:37:11 -0300601 class_dev = kzalloc(sizeof(*class_dev),GFP_KERNEL);
Mike Iselyd8554972006-06-26 20:58:46 -0300602 if (!class_dev) return;
Mike Iselyd8554972006-06-26 20:58:46 -0300603
604 pvr2_sysfs_trace("Creating class_dev id=%p",class_dev);
605
606 class_dev->class = &class_ptr->class;
607 if (pvr2_hdw_get_sn(sfp->channel.hdw)) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300608 snprintf(class_dev->bus_id, BUS_ID_SIZE, "sn-%lu",
Mike Iselyd8554972006-06-26 20:58:46 -0300609 pvr2_hdw_get_sn(sfp->channel.hdw));
610 } else if (pvr2_hdw_get_unit_number(sfp->channel.hdw) >= 0) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300611 snprintf(class_dev->bus_id, BUS_ID_SIZE, "unit-%c",
Mike Iselyd8554972006-06-26 20:58:46 -0300612 pvr2_hdw_get_unit_number(sfp->channel.hdw) + 'a');
613 } else {
614 kfree(class_dev);
615 return;
616 }
617
Kay Sievers54bd5b62007-10-08 16:26:13 -0300618 class_dev->parent = &usb_dev->dev;
Mike Iselyd8554972006-06-26 20:58:46 -0300619
620 sfp->class_dev = class_dev;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300621 class_dev->driver_data = sfp;
622 ret = device_register(class_dev);
Michael Krufky3117bee2006-07-19 13:23:38 -0300623 if (ret) {
Mike Isely49844c22008-04-09 05:44:57 -0300624 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
625 "device_register failed");
Michael Krufky3117bee2006-07-19 13:23:38 -0300626 kfree(class_dev);
627 return;
628 }
Mike Iselyd8554972006-06-26 20:58:46 -0300629
Mike Iselyd8554972006-06-26 20:58:46 -0300630 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;
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300633 sfp->attr_v4l_minor_number.store = NULL;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300634 ret = device_create_file(sfp->class_dev,
Mike Isely08d41802006-07-22 21:26:30 -0300635 &sfp->attr_v4l_minor_number);
636 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300637 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
638 "device_create_file error: %d",
639 ret);
Mike Isely08d41802006-07-22 21:26:30 -0300640 } else {
641 sfp->v4l_minor_number_created_ok = !0;
642 }
Michael Krufky3117bee2006-07-19 13:23:38 -0300643
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300644 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;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300648 ret = device_create_file(sfp->class_dev,
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300649 &sfp->attr_v4l_radio_minor_number);
650 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300651 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
652 "device_create_file error: %d",
653 ret);
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300654 } else {
655 sfp->v4l_radio_minor_number_created_ok = !0;
656 }
657
Mike Iselyd8554972006-06-26 20:58:46 -0300658 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;
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300661 sfp->attr_unit_number.store = NULL;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300662 ret = device_create_file(sfp->class_dev,&sfp->attr_unit_number);
Mike Isely08d41802006-07-22 21:26:30 -0300663 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300664 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
665 "device_create_file error: %d",
666 ret);
Mike Isely08d41802006-07-22 21:26:30 -0300667 } else {
668 sfp->unit_number_created_ok = !0;
669 }
Mike Iselyd8554972006-06-26 20:58:46 -0300670
Mike Isely31a18542007-04-08 01:11:47 -0300671 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;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300675 ret = device_create_file(sfp->class_dev,
Mike Isely31a18542007-04-08 01:11:47 -0300676 &sfp->attr_bus_info);
677 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300678 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
679 "device_create_file error: %d",
680 ret);
Mike Isely31a18542007-04-08 01:11:47 -0300681 } else {
682 sfp->bus_info_created_ok = !0;
683 }
684
Mike Isely78a47102007-11-26 01:58:20 -0300685 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);
691 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300692 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
693 "device_create_file error: %d",
694 ret);
Mike Isely78a47102007-11-26 01:58:20 -0300695 } else {
696 sfp->hdw_name_created_ok = !0;
697 }
698
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);
705 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300706 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
707 "device_create_file error: %d",
708 ret);
Mike Isely78a47102007-11-26 01:58:20 -0300709 } else {
710 sfp->hdw_desc_created_ok = !0;
711 }
712
Mike Iselyd8554972006-06-26 20:58:46 -0300713 pvr2_sysfs_add_controls(sfp);
714#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
715 pvr2_sysfs_add_debugifc(sfp);
716#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
717}
718
719
720static void pvr2_sysfs_internal_check(struct pvr2_channel *chp)
721{
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);
728 kfree(sfp);
729}
730
731
732struct pvr2_sysfs *pvr2_sysfs_create(struct pvr2_context *mp,
733 struct pvr2_sysfs_class *class_ptr)
734{
735 struct pvr2_sysfs *sfp;
Mike Iselyca545f72007-01-20 00:37:11 -0300736 sfp = kzalloc(sizeof(*sfp),GFP_KERNEL);
Mike Iselyd8554972006-06-26 20:58:46 -0300737 if (!sfp) return sfp;
Mike Iselyd8554972006-06-26 20:58:46 -0300738 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;
741
742 class_dev_create(sfp,class_ptr);
743 return sfp;
744}
745
746
Mike Iselyd8554972006-06-26 20:58:46 -0300747
748struct pvr2_sysfs_class *pvr2_sysfs_class_create(void)
749{
750 struct pvr2_sysfs_class *clp;
Mike Iselyca545f72007-01-20 00:37:11 -0300751 clp = kzalloc(sizeof(*clp),GFP_KERNEL);
Mike Iselyd8554972006-06-26 20:58:46 -0300752 if (!clp) return clp;
Mike Iselyd8554972006-06-26 20:58:46 -0300753 pvr2_sysfs_trace("Creating pvr2_sysfs_class id=%p",clp);
754 clp->class.name = "pvrusb2";
755 clp->class.class_release = pvr2_sysfs_class_release;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300756 clp->class.dev_release = pvr2_sysfs_release;
Mike Iselyd8554972006-06-26 20:58:46 -0300757 if (class_register(&clp->class)) {
758 pvr2_sysfs_trace(
759 "Registration failed for pvr2_sysfs_class id=%p",clp);
760 kfree(clp);
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300761 clp = NULL;
Mike Iselyd8554972006-06-26 20:58:46 -0300762 }
763 return clp;
764}
765
766
767void pvr2_sysfs_class_destroy(struct pvr2_sysfs_class *clp)
768{
769 class_unregister(&clp->class);
770}
771
772
773#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
Trent Piephoc726b652007-10-08 19:05:28 -0300774static ssize_t debuginfo_show(struct device *class_dev,
775 struct device_attribute *attr, char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300776{
777 struct pvr2_sysfs *sfp;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300778 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -0300779 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);
782}
783
784
Trent Piephoc726b652007-10-08 19:05:28 -0300785static ssize_t debugcmd_show(struct device *class_dev,
786 struct device_attribute *attr, char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300787{
788 struct pvr2_sysfs *sfp;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300789 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -0300790 if (!sfp) return -EINVAL;
791 return pvr2_debugifc_print_status(sfp->channel.hdw,buf,PAGE_SIZE);
792}
793
794
Kay Sievers54bd5b62007-10-08 16:26:13 -0300795static ssize_t debugcmd_store(struct device *class_dev,
Trent Piephoc726b652007-10-08 19:05:28 -0300796 struct device_attribute *attr,
Kay Sievers54bd5b62007-10-08 16:26:13 -0300797 const char *buf, size_t count)
Mike Iselyd8554972006-06-26 20:58:46 -0300798{
799 struct pvr2_sysfs *sfp;
800 int ret;
801
Kay Sievers54bd5b62007-10-08 16:26:13 -0300802 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -0300803 if (!sfp) return -EINVAL;
804
805 ret = pvr2_debugifc_docmd(sfp->channel.hdw,buf,count);
806 if (ret < 0) return ret;
807 return count;
808}
809#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
810
811
812/*
813 Stuff for Emacs to see, in order to encourage consistent editing style:
814 *** Local Variables: ***
815 *** mode: c ***
816 *** fill-column: 75 ***
817 *** tab-width: 8 ***
818 *** c-basic-offset: 8 ***
819 *** End: ***
820 */