blob: e641cd971453c2b6cb622ae1ff2c36d38cd7f831 [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;
Mike Isely0b7c2c92008-08-31 20:57:54 -030068 struct device_attribute attr_def;
Kay Sievers54bd5b62007-10-08 16:26:13 -030069 struct device_attribute attr_enum;
70 struct device_attribute attr_bits;
71 struct device_attribute attr_val;
72 struct device_attribute attr_custom;
Mike Iselyd8554972006-06-26 20:58:46 -030073 struct pvr2_ctrl *cptr;
Mike Iselyf90fe7a2008-05-26 06:00:47 -030074 int ctl_id;
Mike Iselyd8554972006-06-26 20:58:46 -030075 struct pvr2_sysfs *chptr;
76 struct pvr2_sysfs_ctl_item *item_next;
Mike Isely33213962006-06-25 20:04:40 -030077 struct attribute *attr_gen[7];
Mike Iselyd8554972006-06-26 20:58:46 -030078 struct attribute_group grp;
Mike Isely08d41802006-07-22 21:26:30 -030079 int created_ok;
Mike Iselyd8554972006-06-26 20:58:46 -030080 char name[80];
81};
82
83struct pvr2_sysfs_class {
84 struct class class;
85};
86
Mike Iselyf90fe7a2008-05-26 06:00:47 -030087static ssize_t show_name(struct device *class_dev,
88 struct device_attribute *attr,
89 char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -030090{
Mike Iselyf90fe7a2008-05-26 06:00:47 -030091 struct pvr2_sysfs_ctl_item *cip;
Mike Iselyd8554972006-06-26 20:58:46 -030092 const char *name;
Mike Iselyf90fe7a2008-05-26 06:00:47 -030093 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);
Mike Iselyd8554972006-06-26 20:58:46 -030097 if (!name) return -EINVAL;
Mike Iselyf90fe7a2008-05-26 06:00:47 -030098 return scnprintf(buf, PAGE_SIZE, "%s\n", name);
Mike Iselyd8554972006-06-26 20:58:46 -030099}
100
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300101static ssize_t show_type(struct device *class_dev,
102 struct device_attribute *attr,
103 char *buf)
Mike Isely33213962006-06-25 20:04:40 -0300104{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300105 struct pvr2_sysfs_ctl_item *cip;
Mike Isely33213962006-06-25 20:04:40 -0300106 const char *name;
107 enum pvr2_ctl_type tp;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300108 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_type);
109 tp = pvr2_ctrl_get_type(cip->cptr);
Mike Isely33213962006-06-25 20:04:40 -0300110 switch (tp) {
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;
116 }
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300117 pvr2_sysfs_trace("pvr2_sysfs(%p) show_type(cid=%d) is %s",
118 cip->chptr, cip->ctl_id, name);
Mike Isely33213962006-06-25 20:04:40 -0300119 if (!name) return -EINVAL;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300120 return scnprintf(buf, PAGE_SIZE, "%s\n", name);
Mike Isely33213962006-06-25 20:04:40 -0300121}
122
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300123static ssize_t show_min(struct device *class_dev,
124 struct device_attribute *attr,
125 char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300126{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300127 struct pvr2_sysfs_ctl_item *cip;
Mike Iselyd8554972006-06-26 20:58:46 -0300128 long val;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300129 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);
Mike Iselyd8554972006-06-26 20:58:46 -0300134}
135
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300136static ssize_t show_max(struct device *class_dev,
137 struct device_attribute *attr,
138 char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300139{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300140 struct pvr2_sysfs_ctl_item *cip;
Mike Iselyd8554972006-06-26 20:58:46 -0300141 long val;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300142 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);
Mike Iselyd8554972006-06-26 20:58:46 -0300147}
148
Mike Isely0b7c2c92008-08-31 20:57:54 -0300149static ssize_t show_def(struct device *class_dev,
150 struct device_attribute *attr,
151 char *buf)
152{
153 struct pvr2_sysfs_ctl_item *cip;
154 int val;
155 int ret;
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);
160 if (ret < 0) {
Mike Isely0b7c2c92008-08-31 20:57:54 -0300161 return ret;
162 }
163 return scnprintf(buf, PAGE_SIZE, "%d\n", val);
164}
165
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300166static ssize_t show_val_norm(struct device *class_dev,
167 struct device_attribute *attr,
168 char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300169{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300170 struct pvr2_sysfs_ctl_item *cip;
171 int val;
172 int ret;
Mike Iselyd8554972006-06-26 20:58:46 -0300173 unsigned int cnt = 0;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300174 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_val);
175 ret = pvr2_ctrl_get_value(cip->cptr, &val);
Mike Iselyd8554972006-06-26 20:58:46 -0300176 if (ret < 0) return ret;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300177 ret = pvr2_ctrl_value_to_sym(cip->cptr, ~0, val,
178 buf, PAGE_SIZE - 1, &cnt);
Mike Iselyd8554972006-06-26 20:58:46 -0300179 pvr2_sysfs_trace("pvr2_sysfs(%p) show_val_norm(cid=%d) is %.*s (%d)",
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300180 cip->chptr, cip->ctl_id, cnt, buf, val);
Mike Iselyd8554972006-06-26 20:58:46 -0300181 buf[cnt] = '\n';
182 return cnt+1;
183}
184
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300185static ssize_t show_val_custom(struct device *class_dev,
186 struct device_attribute *attr,
187 char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300188{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300189 struct pvr2_sysfs_ctl_item *cip;
190 int val;
191 int ret;
Mike Iselyd8554972006-06-26 20:58:46 -0300192 unsigned int cnt = 0;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300193 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_custom);
194 ret = pvr2_ctrl_get_value(cip->cptr, &val);
Mike Iselyd8554972006-06-26 20:58:46 -0300195 if (ret < 0) return ret;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300196 ret = pvr2_ctrl_custom_value_to_sym(cip->cptr, ~0, val,
197 buf, PAGE_SIZE - 1, &cnt);
Mike Iselyd8554972006-06-26 20:58:46 -0300198 pvr2_sysfs_trace("pvr2_sysfs(%p) show_val_custom(cid=%d) is %.*s (%d)",
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300199 cip->chptr, cip->ctl_id, cnt, buf, val);
Mike Iselyd8554972006-06-26 20:58:46 -0300200 buf[cnt] = '\n';
201 return cnt+1;
202}
203
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300204static ssize_t show_enum(struct device *class_dev,
205 struct device_attribute *attr,
206 char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300207{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300208 struct pvr2_sysfs_ctl_item *cip;
Mike Iselyd8554972006-06-26 20:58:46 -0300209 long val;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300210 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);
Mike Iselyd8554972006-06-26 20:58:46 -0300213 bcnt = 0;
214 for (val = 0; val < ecnt; val++) {
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300215 pvr2_ctrl_get_valname(cip->cptr, val, buf + bcnt,
216 PAGE_SIZE - bcnt, &ccnt);
Mike Isely45886772006-06-25 20:04:13 -0300217 if (!ccnt) continue;
Mike Iselyd8554972006-06-26 20:58:46 -0300218 bcnt += ccnt;
219 if (bcnt >= PAGE_SIZE) break;
220 buf[bcnt] = '\n';
221 bcnt++;
222 }
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300223 pvr2_sysfs_trace("pvr2_sysfs(%p) show_enum(cid=%d)",
224 cip->chptr, cip->ctl_id);
Mike Iselyd8554972006-06-26 20:58:46 -0300225 return bcnt;
226}
227
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300228static ssize_t show_bits(struct device *class_dev,
229 struct device_attribute *attr,
230 char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300231{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300232 struct pvr2_sysfs_ctl_item *cip;
233 int valid_bits, msk;
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);
Mike Iselyd8554972006-06-26 20:58:46 -0300237 bcnt = 0;
238 for (msk = 1; valid_bits; msk <<= 1) {
239 if (!(msk & valid_bits)) continue;
240 valid_bits &= ~msk;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300241 pvr2_ctrl_get_valname(cip->cptr, msk, buf + bcnt,
242 PAGE_SIZE - bcnt, &ccnt);
Mike Iselyd8554972006-06-26 20:58:46 -0300243 bcnt += ccnt;
244 if (bcnt >= PAGE_SIZE) break;
245 buf[bcnt] = '\n';
246 bcnt++;
247 }
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300248 pvr2_sysfs_trace("pvr2_sysfs(%p) show_bits(cid=%d)",
249 cip->chptr, cip->ctl_id);
Mike Iselyd8554972006-06-26 20:58:46 -0300250 return bcnt;
251}
252
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300253static int store_val_any(struct pvr2_sysfs_ctl_item *cip, int customfl,
Mike Iselyd8554972006-06-26 20:58:46 -0300254 const char *buf,unsigned int count)
255{
Mike Iselyd8554972006-06-26 20:58:46 -0300256 int ret;
257 int mask,val;
Mike Iselyd8554972006-06-26 20:58:46 -0300258 if (customfl) {
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300259 ret = pvr2_ctrl_custom_sym_to_value(cip->cptr, buf, count,
260 &mask, &val);
Mike Iselyd8554972006-06-26 20:58:46 -0300261 } else {
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300262 ret = pvr2_ctrl_sym_to_value(cip->cptr, buf, count,
263 &mask, &val);
Mike Iselyd8554972006-06-26 20:58:46 -0300264 }
265 if (ret < 0) return ret;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300266 ret = pvr2_ctrl_set_mask_value(cip->cptr, mask, val);
267 pvr2_hdw_commit_ctl(cip->chptr->channel.hdw);
Mike Iselyd8554972006-06-26 20:58:46 -0300268 return ret;
269}
270
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300271static ssize_t store_val_norm(struct device *class_dev,
272 struct device_attribute *attr,
273 const char *buf, size_t count)
Mike Iselyd8554972006-06-26 20:58:46 -0300274{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300275 struct pvr2_sysfs_ctl_item *cip;
Mike Iselyd8554972006-06-26 20:58:46 -0300276 int ret;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300277 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_val);
Mike Iselybedbbf82008-04-22 14:45:38 -0300278 pvr2_sysfs_trace("pvr2_sysfs(%p) store_val_norm(cid=%d) \"%.*s\"",
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300279 cip->chptr, cip->ctl_id, (int)count, buf);
280 ret = store_val_any(cip, 0, buf, count);
Mike Iselyd8554972006-06-26 20:58:46 -0300281 if (!ret) ret = count;
282 return ret;
283}
284
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300285static ssize_t store_val_custom(struct device *class_dev,
286 struct device_attribute *attr,
287 const char *buf, size_t count)
Mike Iselyd8554972006-06-26 20:58:46 -0300288{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300289 struct pvr2_sysfs_ctl_item *cip;
Mike Iselyd8554972006-06-26 20:58:46 -0300290 int ret;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300291 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_custom);
Mike Iselybedbbf82008-04-22 14:45:38 -0300292 pvr2_sysfs_trace("pvr2_sysfs(%p) store_val_custom(cid=%d) \"%.*s\"",
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300293 cip->chptr, cip->ctl_id, (int)count, buf);
294 ret = store_val_any(cip, 1, buf, count);
Mike Iselyd8554972006-06-26 20:58:46 -0300295 if (!ret) ret = count;
296 return ret;
297}
298
Mike Iselyd8554972006-06-26 20:58:46 -0300299static void pvr2_sysfs_add_control(struct pvr2_sysfs *sfp,int ctl_id)
300{
301 struct pvr2_sysfs_ctl_item *cip;
Mike Iselyd8554972006-06-26 20:58:46 -0300302 struct pvr2_ctrl *cptr;
303 unsigned int cnt,acnt;
Mike Isely08d41802006-07-22 21:26:30 -0300304 int ret;
Mike Iselyd8554972006-06-26 20:58:46 -0300305
Mike Iselyd8554972006-06-26 20:58:46 -0300306 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,ctl_id);
307 if (!cptr) return;
308
Mike Iselyca545f72007-01-20 00:37:11 -0300309 cip = kzalloc(sizeof(*cip),GFP_KERNEL);
Mike Iselyd8554972006-06-26 20:58:46 -0300310 if (!cip) return;
Mike Iselyd8554972006-06-26 20:58:46 -0300311 pvr2_sysfs_trace("Creating pvr2_sysfs_ctl_item id=%p",cip);
312
313 cip->cptr = cptr;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300314 cip->ctl_id = ctl_id;
Mike Iselyd8554972006-06-26 20:58:46 -0300315
316 cip->chptr = sfp;
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300317 cip->item_next = NULL;
Mike Iselyd8554972006-06-26 20:58:46 -0300318 if (sfp->item_last) {
319 sfp->item_last->item_next = cip;
320 } else {
321 sfp->item_first = cip;
322 }
323 sfp->item_last = cip;
324
Mike Iselyd8554972006-06-26 20:58:46 -0300325 cip->attr_name.attr.name = "name";
326 cip->attr_name.attr.mode = S_IRUGO;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300327 cip->attr_name.show = show_name;
Mike Iselyd8554972006-06-26 20:58:46 -0300328
Mike Isely33213962006-06-25 20:04:40 -0300329 cip->attr_type.attr.name = "type";
330 cip->attr_type.attr.mode = S_IRUGO;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300331 cip->attr_type.show = show_type;
Mike Isely33213962006-06-25 20:04:40 -0300332
Mike Iselyd8554972006-06-26 20:58:46 -0300333 cip->attr_min.attr.name = "min_val";
334 cip->attr_min.attr.mode = S_IRUGO;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300335 cip->attr_min.show = show_min;
Mike Iselyd8554972006-06-26 20:58:46 -0300336
Mike Iselyd8554972006-06-26 20:58:46 -0300337 cip->attr_max.attr.name = "max_val";
338 cip->attr_max.attr.mode = S_IRUGO;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300339 cip->attr_max.show = show_max;
Mike Iselyd8554972006-06-26 20:58:46 -0300340
Mike Isely0b7c2c92008-08-31 20:57:54 -0300341 cip->attr_def.attr.name = "def_val";
342 cip->attr_def.attr.mode = S_IRUGO;
343 cip->attr_def.show = show_def;
344
Mike Iselyd8554972006-06-26 20:58:46 -0300345 cip->attr_val.attr.name = "cur_val";
346 cip->attr_val.attr.mode = S_IRUGO;
347
Mike Iselyd8554972006-06-26 20:58:46 -0300348 cip->attr_custom.attr.name = "custom_val";
349 cip->attr_custom.attr.mode = S_IRUGO;
350
Mike Iselyd8554972006-06-26 20:58:46 -0300351 cip->attr_enum.attr.name = "enum_val";
352 cip->attr_enum.attr.mode = S_IRUGO;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300353 cip->attr_enum.show = show_enum;
Mike Iselyd8554972006-06-26 20:58:46 -0300354
Mike Iselyd8554972006-06-26 20:58:46 -0300355 cip->attr_bits.attr.name = "bit_val";
356 cip->attr_bits.attr.mode = S_IRUGO;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300357 cip->attr_bits.show = show_bits;
Mike Iselyd8554972006-06-26 20:58:46 -0300358
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;
362 }
363
364 acnt = 0;
365 cip->attr_gen[acnt++] = &cip->attr_name.attr;
Mike Isely33213962006-06-25 20:04:40 -0300366 cip->attr_gen[acnt++] = &cip->attr_type.attr;
Mike Iselyd8554972006-06-26 20:58:46 -0300367 cip->attr_gen[acnt++] = &cip->attr_val.attr;
Mike Isely0b7c2c92008-08-31 20:57:54 -0300368 cip->attr_gen[acnt++] = &cip->attr_def.attr;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300369 cip->attr_val.show = show_val_norm;
370 cip->attr_val.store = store_val_norm;
Mike Iselyd8554972006-06-26 20:58:46 -0300371 if (pvr2_ctrl_has_custom_symbols(cptr)) {
372 cip->attr_gen[acnt++] = &cip->attr_custom.attr;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300373 cip->attr_custom.show = show_val_custom;
374 cip->attr_custom.store = store_val_custom;
Mike Iselyd8554972006-06-26 20:58:46 -0300375 }
376 switch (pvr2_ctrl_get_type(cptr)) {
377 case pvr2_ctl_enum:
378 // Control is an enumeration
379 cip->attr_gen[acnt++] = &cip->attr_enum.attr;
380 break;
381 case pvr2_ctl_int:
382 // Control is an integer
383 cip->attr_gen[acnt++] = &cip->attr_min.attr;
384 cip->attr_gen[acnt++] = &cip->attr_max.attr;
385 break;
386 case pvr2_ctl_bitmask:
387 // Control is an bitmask
388 cip->attr_gen[acnt++] = &cip->attr_bits.attr;
389 break;
390 default: break;
391 }
392
393 cnt = scnprintf(cip->name,sizeof(cip->name)-1,"ctl_%s",
394 pvr2_ctrl_get_name(cptr));
395 cip->name[cnt] = 0;
396 cip->grp.name = cip->name;
397 cip->grp.attrs = cip->attr_gen;
398
Mike Isely08d41802006-07-22 21:26:30 -0300399 ret = sysfs_create_group(&sfp->class_dev->kobj,&cip->grp);
400 if (ret) {
Mike Isely49844c22008-04-09 05:44:57 -0300401 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
402 "sysfs_create_group error: %d",
403 ret);
Mike Isely08d41802006-07-22 21:26:30 -0300404 return;
405 }
406 cip->created_ok = !0;
Mike Iselyd8554972006-06-26 20:58:46 -0300407}
408
409#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
Trent Piephoc726b652007-10-08 19:05:28 -0300410static ssize_t debuginfo_show(struct device *, struct device_attribute *,
411 char *);
412static ssize_t debugcmd_show(struct device *, struct device_attribute *,
413 char *);
414static ssize_t debugcmd_store(struct device *, struct device_attribute *,
415 const char *, size_t count);
Mike Iselyd8554972006-06-26 20:58:46 -0300416
417static void pvr2_sysfs_add_debugifc(struct pvr2_sysfs *sfp)
418{
419 struct pvr2_sysfs_debugifc *dip;
Michael Krufky3117bee2006-07-19 13:23:38 -0300420 int ret;
421
Mike Iselyca545f72007-01-20 00:37:11 -0300422 dip = kzalloc(sizeof(*dip),GFP_KERNEL);
Mike Iselyd8554972006-06-26 20:58:46 -0300423 if (!dip) return;
Mike Iselyd8554972006-06-26 20:58:46 -0300424 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;
Mike Iselyd8554972006-06-26 20:58:46 -0300428 dip->attr_debuginfo.attr.name = "debuginfo";
429 dip->attr_debuginfo.attr.mode = S_IRUGO;
430 dip->attr_debuginfo.show = debuginfo_show;
431 sfp->debugifc = dip;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300432 ret = device_create_file(sfp->class_dev,&dip->attr_debugcmd);
Mike Isely08d41802006-07-22 21:26:30 -0300433 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300434 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
435 "device_create_file error: %d",
436 ret);
Mike Isely08d41802006-07-22 21:26:30 -0300437 } else {
438 dip->debugcmd_created_ok = !0;
439 }
Kay Sievers54bd5b62007-10-08 16:26:13 -0300440 ret = device_create_file(sfp->class_dev,&dip->attr_debuginfo);
Mike Isely08d41802006-07-22 21:26:30 -0300441 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300442 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
443 "device_create_file error: %d",
444 ret);
Mike Isely08d41802006-07-22 21:26:30 -0300445 } else {
446 dip->debuginfo_created_ok = !0;
447 }
Mike Iselyd8554972006-06-26 20:58:46 -0300448}
449
450
451static void pvr2_sysfs_tear_down_debugifc(struct pvr2_sysfs *sfp)
452{
453 if (!sfp->debugifc) return;
Mike Isely08d41802006-07-22 21:26:30 -0300454 if (sfp->debugifc->debuginfo_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300455 device_remove_file(sfp->class_dev,
Mike Isely08d41802006-07-22 21:26:30 -0300456 &sfp->debugifc->attr_debuginfo);
457 }
458 if (sfp->debugifc->debugcmd_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300459 device_remove_file(sfp->class_dev,
Mike Isely08d41802006-07-22 21:26:30 -0300460 &sfp->debugifc->attr_debugcmd);
461 }
Mike Iselyd8554972006-06-26 20:58:46 -0300462 kfree(sfp->debugifc);
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300463 sfp->debugifc = NULL;
Mike Iselyd8554972006-06-26 20:58:46 -0300464}
465#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
466
467
468static void pvr2_sysfs_add_controls(struct pvr2_sysfs *sfp)
469{
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);
474 }
475}
476
477
478static void pvr2_sysfs_tear_down_controls(struct pvr2_sysfs *sfp)
479{
480 struct pvr2_sysfs_ctl_item *cip1,*cip2;
481 for (cip1 = sfp->item_first; cip1; cip1 = cip2) {
482 cip2 = cip1->item_next;
Mike Isely08d41802006-07-22 21:26:30 -0300483 if (cip1->created_ok) {
484 sysfs_remove_group(&sfp->class_dev->kobj,&cip1->grp);
485 }
Mike Iselyd8554972006-06-26 20:58:46 -0300486 pvr2_sysfs_trace("Destroying pvr2_sysfs_ctl_item id=%p",cip1);
487 kfree(cip1);
488 }
489}
490
491
492static void pvr2_sysfs_class_release(struct class *class)
493{
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);
497 kfree(clp);
498}
499
500
Kay Sievers54bd5b62007-10-08 16:26:13 -0300501static void pvr2_sysfs_release(struct device *class_dev)
Mike Iselyd8554972006-06-26 20:58:46 -0300502{
503 pvr2_sysfs_trace("Releasing class_dev id=%p",class_dev);
504 kfree(class_dev);
505}
506
507
508static void class_dev_destroy(struct pvr2_sysfs *sfp)
509{
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);
Mike Isely78a47102007-11-26 01:58:20 -0300515 if (sfp->hdw_desc_created_ok) {
516 device_remove_file(sfp->class_dev,
517 &sfp->attr_hdw_desc);
518 }
519 if (sfp->hdw_name_created_ok) {
520 device_remove_file(sfp->class_dev,
521 &sfp->attr_hdw_name);
522 }
Mike Isely31a18542007-04-08 01:11:47 -0300523 if (sfp->bus_info_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300524 device_remove_file(sfp->class_dev,
Mike Isely31a18542007-04-08 01:11:47 -0300525 &sfp->attr_bus_info);
526 }
Mike Isely08d41802006-07-22 21:26:30 -0300527 if (sfp->v4l_minor_number_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300528 device_remove_file(sfp->class_dev,
Mike Isely08d41802006-07-22 21:26:30 -0300529 &sfp->attr_v4l_minor_number);
530 }
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300531 if (sfp->v4l_radio_minor_number_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300532 device_remove_file(sfp->class_dev,
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300533 &sfp->attr_v4l_radio_minor_number);
534 }
Mike Isely08d41802006-07-22 21:26:30 -0300535 if (sfp->unit_number_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300536 device_remove_file(sfp->class_dev,
Mike Isely08d41802006-07-22 21:26:30 -0300537 &sfp->attr_unit_number);
538 }
Mike Iselyd8554972006-06-26 20:58:46 -0300539 pvr2_sysfs_trace("Destroying class_dev id=%p",sfp->class_dev);
Kay Sievers54bd5b62007-10-08 16:26:13 -0300540 sfp->class_dev->driver_data = NULL;
541 device_unregister(sfp->class_dev);
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300542 sfp->class_dev = NULL;
Mike Iselyd8554972006-06-26 20:58:46 -0300543}
544
545
Kay Sievers54bd5b62007-10-08 16:26:13 -0300546static ssize_t v4l_minor_number_show(struct device *class_dev,
547 struct device_attribute *attr, char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300548{
549 struct pvr2_sysfs *sfp;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300550 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -0300551 if (!sfp) return -EINVAL;
552 return scnprintf(buf,PAGE_SIZE,"%d\n",
Mike Iselyfd5a75f2006-12-27 23:11:22 -0300553 pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw,
Mike Isely80793842006-12-27 23:12:28 -0300554 pvr2_v4l_type_video));
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300555}
556
557
Kay Sievers54bd5b62007-10-08 16:26:13 -0300558static ssize_t bus_info_show(struct device *class_dev,
559 struct device_attribute *attr, char *buf)
Mike Isely31a18542007-04-08 01:11:47 -0300560{
561 struct pvr2_sysfs *sfp;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300562 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Isely31a18542007-04-08 01:11:47 -0300563 if (!sfp) return -EINVAL;
564 return scnprintf(buf,PAGE_SIZE,"%s\n",
565 pvr2_hdw_get_bus_info(sfp->channel.hdw));
566}
567
568
Mike Isely78a47102007-11-26 01:58:20 -0300569static ssize_t hdw_name_show(struct device *class_dev,
570 struct device_attribute *attr, char *buf)
571{
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));
577}
578
579
580static ssize_t hdw_desc_show(struct device *class_dev,
581 struct device_attribute *attr, char *buf)
582{
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));
588}
589
590
Kay Sievers54bd5b62007-10-08 16:26:13 -0300591static ssize_t v4l_radio_minor_number_show(struct device *class_dev,
592 struct device_attribute *attr,
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300593 char *buf)
594{
595 struct pvr2_sysfs *sfp;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300596 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300597 if (!sfp) return -EINVAL;
598 return scnprintf(buf,PAGE_SIZE,"%d\n",
Mike Iselyfd5a75f2006-12-27 23:11:22 -0300599 pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw,
Mike Isely80793842006-12-27 23:12:28 -0300600 pvr2_v4l_type_radio));
Mike Iselyd8554972006-06-26 20:58:46 -0300601}
602
603
Kay Sievers54bd5b62007-10-08 16:26:13 -0300604static ssize_t unit_number_show(struct device *class_dev,
605 struct device_attribute *attr, char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300606{
607 struct pvr2_sysfs *sfp;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300608 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -0300609 if (!sfp) return -EINVAL;
610 return scnprintf(buf,PAGE_SIZE,"%d\n",
611 pvr2_hdw_get_unit_number(sfp->channel.hdw));
612}
613
614
615static void class_dev_create(struct pvr2_sysfs *sfp,
616 struct pvr2_sysfs_class *class_ptr)
617{
618 struct usb_device *usb_dev;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300619 struct device *class_dev;
Michael Krufky3117bee2006-07-19 13:23:38 -0300620 int ret;
621
Mike Iselyd8554972006-06-26 20:58:46 -0300622 usb_dev = pvr2_hdw_get_dev(sfp->channel.hdw);
623 if (!usb_dev) return;
Mike Iselyca545f72007-01-20 00:37:11 -0300624 class_dev = kzalloc(sizeof(*class_dev),GFP_KERNEL);
Mike Iselyd8554972006-06-26 20:58:46 -0300625 if (!class_dev) return;
Mike Iselyd8554972006-06-26 20:58:46 -0300626
627 pvr2_sysfs_trace("Creating class_dev id=%p",class_dev);
628
629 class_dev->class = &class_ptr->class;
630 if (pvr2_hdw_get_sn(sfp->channel.hdw)) {
Kay Sieversaf128a12008-10-30 00:51:46 -0300631 dev_set_name(class_dev, "sn-%lu",
Mike Iselyd8554972006-06-26 20:58:46 -0300632 pvr2_hdw_get_sn(sfp->channel.hdw));
633 } else if (pvr2_hdw_get_unit_number(sfp->channel.hdw) >= 0) {
Kay Sieversaf128a12008-10-30 00:51:46 -0300634 dev_set_name(class_dev, "unit-%c",
Mike Iselyd8554972006-06-26 20:58:46 -0300635 pvr2_hdw_get_unit_number(sfp->channel.hdw) + 'a');
636 } else {
637 kfree(class_dev);
638 return;
639 }
640
Kay Sievers54bd5b62007-10-08 16:26:13 -0300641 class_dev->parent = &usb_dev->dev;
Mike Iselyd8554972006-06-26 20:58:46 -0300642
643 sfp->class_dev = class_dev;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300644 class_dev->driver_data = sfp;
645 ret = device_register(class_dev);
Michael Krufky3117bee2006-07-19 13:23:38 -0300646 if (ret) {
Mike Isely49844c22008-04-09 05:44:57 -0300647 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
648 "device_register failed");
Michael Krufky3117bee2006-07-19 13:23:38 -0300649 kfree(class_dev);
650 return;
651 }
Mike Iselyd8554972006-06-26 20:58:46 -0300652
Mike Iselyd8554972006-06-26 20:58:46 -0300653 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;
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300656 sfp->attr_v4l_minor_number.store = NULL;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300657 ret = device_create_file(sfp->class_dev,
Mike Isely08d41802006-07-22 21:26:30 -0300658 &sfp->attr_v4l_minor_number);
659 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300660 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
661 "device_create_file error: %d",
662 ret);
Mike Isely08d41802006-07-22 21:26:30 -0300663 } else {
664 sfp->v4l_minor_number_created_ok = !0;
665 }
Michael Krufky3117bee2006-07-19 13:23:38 -0300666
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300667 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;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300671 ret = device_create_file(sfp->class_dev,
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300672 &sfp->attr_v4l_radio_minor_number);
673 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300674 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
675 "device_create_file error: %d",
676 ret);
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300677 } else {
678 sfp->v4l_radio_minor_number_created_ok = !0;
679 }
680
Mike Iselyd8554972006-06-26 20:58:46 -0300681 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;
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300684 sfp->attr_unit_number.store = NULL;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300685 ret = device_create_file(sfp->class_dev,&sfp->attr_unit_number);
Mike Isely08d41802006-07-22 21:26:30 -0300686 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300687 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
688 "device_create_file error: %d",
689 ret);
Mike Isely08d41802006-07-22 21:26:30 -0300690 } else {
691 sfp->unit_number_created_ok = !0;
692 }
Mike Iselyd8554972006-06-26 20:58:46 -0300693
Mike Isely31a18542007-04-08 01:11:47 -0300694 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;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300698 ret = device_create_file(sfp->class_dev,
Mike Isely31a18542007-04-08 01:11:47 -0300699 &sfp->attr_bus_info);
700 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300701 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
702 "device_create_file error: %d",
703 ret);
Mike Isely31a18542007-04-08 01:11:47 -0300704 } else {
705 sfp->bus_info_created_ok = !0;
706 }
707
Mike Isely78a47102007-11-26 01:58:20 -0300708 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);
714 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300715 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
716 "device_create_file error: %d",
717 ret);
Mike Isely78a47102007-11-26 01:58:20 -0300718 } else {
719 sfp->hdw_name_created_ok = !0;
720 }
721
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);
728 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300729 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
730 "device_create_file error: %d",
731 ret);
Mike Isely78a47102007-11-26 01:58:20 -0300732 } else {
733 sfp->hdw_desc_created_ok = !0;
734 }
735
Mike Iselyd8554972006-06-26 20:58:46 -0300736 pvr2_sysfs_add_controls(sfp);
737#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
738 pvr2_sysfs_add_debugifc(sfp);
739#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
740}
741
742
743static void pvr2_sysfs_internal_check(struct pvr2_channel *chp)
744{
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);
751 kfree(sfp);
752}
753
754
755struct pvr2_sysfs *pvr2_sysfs_create(struct pvr2_context *mp,
756 struct pvr2_sysfs_class *class_ptr)
757{
758 struct pvr2_sysfs *sfp;
Mike Iselyca545f72007-01-20 00:37:11 -0300759 sfp = kzalloc(sizeof(*sfp),GFP_KERNEL);
Mike Iselyd8554972006-06-26 20:58:46 -0300760 if (!sfp) return sfp;
Mike Iselyd8554972006-06-26 20:58:46 -0300761 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;
764
765 class_dev_create(sfp,class_ptr);
766 return sfp;
767}
768
769
Mike Iselyd8554972006-06-26 20:58:46 -0300770
771struct pvr2_sysfs_class *pvr2_sysfs_class_create(void)
772{
773 struct pvr2_sysfs_class *clp;
Mike Iselyca545f72007-01-20 00:37:11 -0300774 clp = kzalloc(sizeof(*clp),GFP_KERNEL);
Mike Iselyd8554972006-06-26 20:58:46 -0300775 if (!clp) return clp;
Mike Iselyd8554972006-06-26 20:58:46 -0300776 pvr2_sysfs_trace("Creating pvr2_sysfs_class id=%p",clp);
777 clp->class.name = "pvrusb2";
778 clp->class.class_release = pvr2_sysfs_class_release;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300779 clp->class.dev_release = pvr2_sysfs_release;
Mike Iselyd8554972006-06-26 20:58:46 -0300780 if (class_register(&clp->class)) {
781 pvr2_sysfs_trace(
782 "Registration failed for pvr2_sysfs_class id=%p",clp);
783 kfree(clp);
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300784 clp = NULL;
Mike Iselyd8554972006-06-26 20:58:46 -0300785 }
786 return clp;
787}
788
789
790void pvr2_sysfs_class_destroy(struct pvr2_sysfs_class *clp)
791{
792 class_unregister(&clp->class);
793}
794
795
796#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
Trent Piephoc726b652007-10-08 19:05:28 -0300797static ssize_t debuginfo_show(struct device *class_dev,
798 struct device_attribute *attr, char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300799{
800 struct pvr2_sysfs *sfp;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300801 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -0300802 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);
805}
806
807
Trent Piephoc726b652007-10-08 19:05:28 -0300808static ssize_t debugcmd_show(struct device *class_dev,
809 struct device_attribute *attr, char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300810{
811 struct pvr2_sysfs *sfp;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300812 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -0300813 if (!sfp) return -EINVAL;
814 return pvr2_debugifc_print_status(sfp->channel.hdw,buf,PAGE_SIZE);
815}
816
817
Kay Sievers54bd5b62007-10-08 16:26:13 -0300818static ssize_t debugcmd_store(struct device *class_dev,
Trent Piephoc726b652007-10-08 19:05:28 -0300819 struct device_attribute *attr,
Kay Sievers54bd5b62007-10-08 16:26:13 -0300820 const char *buf, size_t count)
Mike Iselyd8554972006-06-26 20:58:46 -0300821{
822 struct pvr2_sysfs *sfp;
823 int ret;
824
Kay Sievers54bd5b62007-10-08 16:26:13 -0300825 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -0300826 if (!sfp) return -EINVAL;
827
828 ret = pvr2_debugifc_docmd(sfp->channel.hdw,buf,count);
829 if (ret < 0) return ret;
830 return count;
831}
832#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
833
834
835/*
836 Stuff for Emacs to see, in order to encourage consistent editing style:
837 *** Local Variables: ***
838 *** mode: c ***
839 *** fill-column: 75 ***
840 *** tab-width: 8 ***
841 *** c-basic-offset: 8 ***
842 *** End: ***
843 */