blob: 0ff7a836a8a2493e926ad102664a7814333d026a [file] [log] [blame]
Mike Iselyd8554972006-06-26 20:58:46 -03001/*
2 *
3 * $Id$
4 *
5 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
Mike Iselyd8554972006-06-26 20:58:46 -030022#include <linux/string.h>
23#include <linux/slab.h>
Mike Iselyd8554972006-06-26 20:58:46 -030024#include "pvrusb2-sysfs.h"
25#include "pvrusb2-hdw.h"
26#include "pvrusb2-debug.h"
27#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
28#include "pvrusb2-debugifc.h"
29#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
30
31#define pvr2_sysfs_trace(...) pvr2_trace(PVR2_TRACE_SYSFS,__VA_ARGS__)
32
33struct pvr2_sysfs {
34 struct pvr2_channel channel;
Kay Sievers54bd5b62007-10-08 16:26:13 -030035 struct device *class_dev;
Mike Iselyd8554972006-06-26 20:58:46 -030036#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
37 struct pvr2_sysfs_debugifc *debugifc;
38#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
39 struct pvr2_sysfs_ctl_item *item_first;
40 struct pvr2_sysfs_ctl_item *item_last;
Kay Sievers54bd5b62007-10-08 16:26:13 -030041 struct device_attribute attr_v4l_minor_number;
42 struct device_attribute attr_v4l_radio_minor_number;
43 struct device_attribute attr_unit_number;
44 struct device_attribute attr_bus_info;
Mike Isely78a47102007-11-26 01:58:20 -030045 struct device_attribute attr_hdw_name;
46 struct device_attribute attr_hdw_desc;
Mike Isely08d41802006-07-22 21:26:30 -030047 int v4l_minor_number_created_ok;
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -030048 int v4l_radio_minor_number_created_ok;
Mike Isely08d41802006-07-22 21:26:30 -030049 int unit_number_created_ok;
Mike Isely31a18542007-04-08 01:11:47 -030050 int bus_info_created_ok;
Mike Isely78a47102007-11-26 01:58:20 -030051 int hdw_name_created_ok;
52 int hdw_desc_created_ok;
Mike Iselyd8554972006-06-26 20:58:46 -030053};
54
55#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
56struct pvr2_sysfs_debugifc {
Kay Sievers54bd5b62007-10-08 16:26:13 -030057 struct device_attribute attr_debugcmd;
58 struct device_attribute attr_debuginfo;
Mike Isely08d41802006-07-22 21:26:30 -030059 int debugcmd_created_ok;
60 int debuginfo_created_ok;
Mike Iselyd8554972006-06-26 20:58:46 -030061};
62#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
63
64struct pvr2_sysfs_ctl_item {
Kay Sievers54bd5b62007-10-08 16:26:13 -030065 struct device_attribute attr_name;
66 struct device_attribute attr_type;
67 struct device_attribute attr_min;
68 struct device_attribute attr_max;
69 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;
74 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
Kay Sievers54bd5b62007-10-08 16:26:13 -030086static ssize_t show_name(int id,struct device *class_dev,char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -030087{
88 struct pvr2_ctrl *cptr;
89 struct pvr2_sysfs *sfp;
90 const char *name;
91
Kay Sievers54bd5b62007-10-08 16:26:13 -030092 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -030093 if (!sfp) return -EINVAL;
94 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
95 if (!cptr) return -EINVAL;
96
97 name = pvr2_ctrl_get_desc(cptr);
98 pvr2_sysfs_trace("pvr2_sysfs(%p) show_name(cid=%d) is %s",sfp,id,name);
99
100 if (!name) return -EINVAL;
101
102 return scnprintf(buf,PAGE_SIZE,"%s\n",name);
103}
104
Kay Sievers54bd5b62007-10-08 16:26:13 -0300105static ssize_t show_type(int id,struct device *class_dev,char *buf)
Mike Isely33213962006-06-25 20:04:40 -0300106{
107 struct pvr2_ctrl *cptr;
108 struct pvr2_sysfs *sfp;
109 const char *name;
110 enum pvr2_ctl_type tp;
111
Kay Sievers54bd5b62007-10-08 16:26:13 -0300112 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Isely33213962006-06-25 20:04:40 -0300113 if (!sfp) return -EINVAL;
114 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
115 if (!cptr) return -EINVAL;
116
117 tp = pvr2_ctrl_get_type(cptr);
118 switch (tp) {
119 case pvr2_ctl_int: name = "integer"; break;
120 case pvr2_ctl_enum: name = "enum"; break;
121 case pvr2_ctl_bitmask: name = "bitmask"; break;
122 case pvr2_ctl_bool: name = "boolean"; break;
123 default: name = "?"; break;
124 }
125 pvr2_sysfs_trace("pvr2_sysfs(%p) show_type(cid=%d) is %s",sfp,id,name);
126
127 if (!name) return -EINVAL;
128
129 return scnprintf(buf,PAGE_SIZE,"%s\n",name);
130}
131
Kay Sievers54bd5b62007-10-08 16:26:13 -0300132static ssize_t show_min(int id,struct device *class_dev,char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300133{
134 struct pvr2_ctrl *cptr;
135 struct pvr2_sysfs *sfp;
136 long val;
137
Kay Sievers54bd5b62007-10-08 16:26:13 -0300138 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -0300139 if (!sfp) return -EINVAL;
140 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
141 if (!cptr) return -EINVAL;
142 val = pvr2_ctrl_get_min(cptr);
143
144 pvr2_sysfs_trace("pvr2_sysfs(%p) show_min(cid=%d) is %ld",sfp,id,val);
145
146 return scnprintf(buf,PAGE_SIZE,"%ld\n",val);
147}
148
Kay Sievers54bd5b62007-10-08 16:26:13 -0300149static ssize_t show_max(int id,struct device *class_dev,char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300150{
151 struct pvr2_ctrl *cptr;
152 struct pvr2_sysfs *sfp;
153 long val;
154
Kay Sievers54bd5b62007-10-08 16:26:13 -0300155 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -0300156 if (!sfp) return -EINVAL;
157 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
158 if (!cptr) return -EINVAL;
159 val = pvr2_ctrl_get_max(cptr);
160
161 pvr2_sysfs_trace("pvr2_sysfs(%p) show_max(cid=%d) is %ld",sfp,id,val);
162
163 return scnprintf(buf,PAGE_SIZE,"%ld\n",val);
164}
165
Kay Sievers54bd5b62007-10-08 16:26:13 -0300166static ssize_t show_val_norm(int id,struct device *class_dev,char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300167{
168 struct pvr2_ctrl *cptr;
169 struct pvr2_sysfs *sfp;
170 int val,ret;
171 unsigned int cnt = 0;
172
Kay Sievers54bd5b62007-10-08 16:26:13 -0300173 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -0300174 if (!sfp) return -EINVAL;
175 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
176 if (!cptr) return -EINVAL;
177
178 ret = pvr2_ctrl_get_value(cptr,&val);
179 if (ret < 0) return ret;
180
181 ret = pvr2_ctrl_value_to_sym(cptr,~0,val,
182 buf,PAGE_SIZE-1,&cnt);
183
184 pvr2_sysfs_trace("pvr2_sysfs(%p) show_val_norm(cid=%d) is %.*s (%d)",
185 sfp,id,cnt,buf,val);
186 buf[cnt] = '\n';
187 return cnt+1;
188}
189
Kay Sievers54bd5b62007-10-08 16:26:13 -0300190static ssize_t show_val_custom(int id,struct device *class_dev,char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300191{
192 struct pvr2_ctrl *cptr;
193 struct pvr2_sysfs *sfp;
194 int val,ret;
195 unsigned int cnt = 0;
196
Kay Sievers54bd5b62007-10-08 16:26:13 -0300197 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -0300198 if (!sfp) return -EINVAL;
199 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
200 if (!cptr) return -EINVAL;
201
202 ret = pvr2_ctrl_get_value(cptr,&val);
203 if (ret < 0) return ret;
204
205 ret = pvr2_ctrl_custom_value_to_sym(cptr,~0,val,
206 buf,PAGE_SIZE-1,&cnt);
207
208 pvr2_sysfs_trace("pvr2_sysfs(%p) show_val_custom(cid=%d) is %.*s (%d)",
209 sfp,id,cnt,buf,val);
210 buf[cnt] = '\n';
211 return cnt+1;
212}
213
Kay Sievers54bd5b62007-10-08 16:26:13 -0300214static ssize_t show_enum(int id,struct device *class_dev,char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300215{
216 struct pvr2_ctrl *cptr;
217 struct pvr2_sysfs *sfp;
218 long val;
219 unsigned int bcnt,ccnt,ecnt;
220
Kay Sievers54bd5b62007-10-08 16:26:13 -0300221 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -0300222 if (!sfp) return -EINVAL;
223 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
224 if (!cptr) return -EINVAL;
225 ecnt = pvr2_ctrl_get_cnt(cptr);
226 bcnt = 0;
227 for (val = 0; val < ecnt; val++) {
228 pvr2_ctrl_get_valname(cptr,val,buf+bcnt,PAGE_SIZE-bcnt,&ccnt);
Mike Isely45886772006-06-25 20:04:13 -0300229 if (!ccnt) continue;
Mike Iselyd8554972006-06-26 20:58:46 -0300230 bcnt += ccnt;
231 if (bcnt >= PAGE_SIZE) break;
232 buf[bcnt] = '\n';
233 bcnt++;
234 }
235 pvr2_sysfs_trace("pvr2_sysfs(%p) show_enum(cid=%d)",sfp,id);
236 return bcnt;
237}
238
Kay Sievers54bd5b62007-10-08 16:26:13 -0300239static ssize_t show_bits(int id,struct device *class_dev,char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300240{
241 struct pvr2_ctrl *cptr;
242 struct pvr2_sysfs *sfp;
243 int valid_bits,msk;
244 unsigned int bcnt,ccnt;
245
Kay Sievers54bd5b62007-10-08 16:26:13 -0300246 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -0300247 if (!sfp) return -EINVAL;
248 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
249 if (!cptr) return -EINVAL;
250 valid_bits = pvr2_ctrl_get_mask(cptr);
251 bcnt = 0;
252 for (msk = 1; valid_bits; msk <<= 1) {
253 if (!(msk & valid_bits)) continue;
254 valid_bits &= ~msk;
255 pvr2_ctrl_get_valname(cptr,msk,buf+bcnt,PAGE_SIZE-bcnt,&ccnt);
256 bcnt += ccnt;
257 if (bcnt >= PAGE_SIZE) break;
258 buf[bcnt] = '\n';
259 bcnt++;
260 }
261 pvr2_sysfs_trace("pvr2_sysfs(%p) show_bits(cid=%d)",sfp,id);
262 return bcnt;
263}
264
265static int store_val_any(int id,int customfl,struct pvr2_sysfs *sfp,
266 const char *buf,unsigned int count)
267{
268 struct pvr2_ctrl *cptr;
269 int ret;
270 int mask,val;
271
272 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
273 if (customfl) {
274 ret = pvr2_ctrl_custom_sym_to_value(cptr,buf,count,&mask,&val);
275 } else {
276 ret = pvr2_ctrl_sym_to_value(cptr,buf,count,&mask,&val);
277 }
278 if (ret < 0) return ret;
279 ret = pvr2_ctrl_set_mask_value(cptr,mask,val);
280 pvr2_hdw_commit_ctl(sfp->channel.hdw);
281 return ret;
282}
283
Kay Sievers54bd5b62007-10-08 16:26:13 -0300284static ssize_t store_val_norm(int id,struct device *class_dev,
Mike Iselyd8554972006-06-26 20:58:46 -0300285 const char *buf,size_t count)
286{
287 struct pvr2_sysfs *sfp;
288 int ret;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300289 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselybedbbf82008-04-22 14:45:38 -0300290 pvr2_sysfs_trace("pvr2_sysfs(%p) store_val_norm(cid=%d) \"%.*s\"",
Mike Iselya2401d92008-03-08 04:02:20 -0300291 sfp,id,(int)count,buf);
Mike Iselyd8554972006-06-26 20:58:46 -0300292 ret = store_val_any(id,0,sfp,buf,count);
293 if (!ret) ret = count;
294 return ret;
295}
296
Kay Sievers54bd5b62007-10-08 16:26:13 -0300297static ssize_t store_val_custom(int id,struct device *class_dev,
Mike Iselyd8554972006-06-26 20:58:46 -0300298 const char *buf,size_t count)
299{
300 struct pvr2_sysfs *sfp;
301 int ret;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300302 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselybedbbf82008-04-22 14:45:38 -0300303 pvr2_sysfs_trace("pvr2_sysfs(%p) store_val_custom(cid=%d) \"%.*s\"",
Mike Iselya2401d92008-03-08 04:02:20 -0300304 sfp,id,(int)count,buf);
Mike Iselyd8554972006-06-26 20:58:46 -0300305 ret = store_val_any(id,1,sfp,buf,count);
306 if (!ret) ret = count;
307 return ret;
308}
309
310/*
311 Mike Isely <isely@pobox.com> 30-April-2005
312
313 This next batch of horrible preprocessor hackery is needed because the
Kay Sievers54bd5b62007-10-08 16:26:13 -0300314 kernel's device_attribute mechanism fails to pass the actual
Mike Iselyd8554972006-06-26 20:58:46 -0300315 attribute through to the show / store functions, which means we have no
316 way to package up any attribute-specific parameters, like for example the
317 control id. So we work around this brain-damage by encoding the control
318 id into the show / store functions themselves and pick the function based
319 on the control id we're setting up. These macros try to ease the pain.
320 Yuck.
321*/
322
323#define CREATE_SHOW_INSTANCE(sf_name,ctl_id) \
Kay Sievers54bd5b62007-10-08 16:26:13 -0300324static ssize_t sf_name##_##ctl_id(struct device *class_dev, \
325struct device_attribute *attr, char *buf) \
Mike Iselyd8554972006-06-26 20:58:46 -0300326{ return sf_name(ctl_id,class_dev,buf); }
327
328#define CREATE_STORE_INSTANCE(sf_name,ctl_id) \
Kay Sievers54bd5b62007-10-08 16:26:13 -0300329static ssize_t sf_name##_##ctl_id(struct device *class_dev, \
330struct device_attribute *attr, const char *buf, size_t count) \
Mike Iselyd8554972006-06-26 20:58:46 -0300331{ return sf_name(ctl_id,class_dev,buf,count); }
332
333#define CREATE_BATCH(ctl_id) \
334CREATE_SHOW_INSTANCE(show_name,ctl_id) \
Mike Isely33213962006-06-25 20:04:40 -0300335CREATE_SHOW_INSTANCE(show_type,ctl_id) \
Mike Iselyd8554972006-06-26 20:58:46 -0300336CREATE_SHOW_INSTANCE(show_min,ctl_id) \
337CREATE_SHOW_INSTANCE(show_max,ctl_id) \
338CREATE_SHOW_INSTANCE(show_val_norm,ctl_id) \
339CREATE_SHOW_INSTANCE(show_val_custom,ctl_id) \
340CREATE_SHOW_INSTANCE(show_enum,ctl_id) \
341CREATE_SHOW_INSTANCE(show_bits,ctl_id) \
342CREATE_STORE_INSTANCE(store_val_norm,ctl_id) \
343CREATE_STORE_INSTANCE(store_val_custom,ctl_id) \
344
345CREATE_BATCH(0)
346CREATE_BATCH(1)
347CREATE_BATCH(2)
348CREATE_BATCH(3)
349CREATE_BATCH(4)
350CREATE_BATCH(5)
351CREATE_BATCH(6)
352CREATE_BATCH(7)
353CREATE_BATCH(8)
354CREATE_BATCH(9)
355CREATE_BATCH(10)
356CREATE_BATCH(11)
357CREATE_BATCH(12)
358CREATE_BATCH(13)
359CREATE_BATCH(14)
360CREATE_BATCH(15)
361CREATE_BATCH(16)
362CREATE_BATCH(17)
363CREATE_BATCH(18)
364CREATE_BATCH(19)
365CREATE_BATCH(20)
366CREATE_BATCH(21)
367CREATE_BATCH(22)
368CREATE_BATCH(23)
369CREATE_BATCH(24)
370CREATE_BATCH(25)
371CREATE_BATCH(26)
372CREATE_BATCH(27)
373CREATE_BATCH(28)
374CREATE_BATCH(29)
375CREATE_BATCH(30)
376CREATE_BATCH(31)
377CREATE_BATCH(32)
378CREATE_BATCH(33)
Mike Isely39481992006-06-25 20:04:20 -0300379CREATE_BATCH(34)
380CREATE_BATCH(35)
381CREATE_BATCH(36)
382CREATE_BATCH(37)
383CREATE_BATCH(38)
384CREATE_BATCH(39)
385CREATE_BATCH(40)
386CREATE_BATCH(41)
387CREATE_BATCH(42)
388CREATE_BATCH(43)
389CREATE_BATCH(44)
390CREATE_BATCH(45)
391CREATE_BATCH(46)
392CREATE_BATCH(47)
393CREATE_BATCH(48)
394CREATE_BATCH(49)
395CREATE_BATCH(50)
396CREATE_BATCH(51)
397CREATE_BATCH(52)
398CREATE_BATCH(53)
399CREATE_BATCH(54)
400CREATE_BATCH(55)
401CREATE_BATCH(56)
402CREATE_BATCH(57)
403CREATE_BATCH(58)
404CREATE_BATCH(59)
Mike Iselyd8554972006-06-26 20:58:46 -0300405
406struct pvr2_sysfs_func_set {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300407 ssize_t (*show_name)(struct device *,
408 struct device_attribute *attr, char *);
409 ssize_t (*show_type)(struct device *,
410 struct device_attribute *attr, char *);
411 ssize_t (*show_min)(struct device *,
412 struct device_attribute *attr, char *);
413 ssize_t (*show_max)(struct device *,
414 struct device_attribute *attr, char *);
415 ssize_t (*show_enum)(struct device *,
416 struct device_attribute *attr, char *);
417 ssize_t (*show_bits)(struct device *,
418 struct device_attribute *attr, char *);
419 ssize_t (*show_val_norm)(struct device *,
420 struct device_attribute *attr, char *);
421 ssize_t (*store_val_norm)(struct device *,
422 struct device_attribute *attr,
Mike Iselyd8554972006-06-26 20:58:46 -0300423 const char *,size_t);
Kay Sievers54bd5b62007-10-08 16:26:13 -0300424 ssize_t (*show_val_custom)(struct device *,
425 struct device_attribute *attr, char *);
426 ssize_t (*store_val_custom)(struct device *,
427 struct device_attribute *attr,
Mike Iselyd8554972006-06-26 20:58:46 -0300428 const char *,size_t);
429};
430
431#define INIT_BATCH(ctl_id) \
432[ctl_id] = { \
433 .show_name = show_name_##ctl_id, \
Mike Isely33213962006-06-25 20:04:40 -0300434 .show_type = show_type_##ctl_id, \
Mike Iselyd8554972006-06-26 20:58:46 -0300435 .show_min = show_min_##ctl_id, \
436 .show_max = show_max_##ctl_id, \
437 .show_enum = show_enum_##ctl_id, \
438 .show_bits = show_bits_##ctl_id, \
439 .show_val_norm = show_val_norm_##ctl_id, \
440 .store_val_norm = store_val_norm_##ctl_id, \
441 .show_val_custom = show_val_custom_##ctl_id, \
442 .store_val_custom = store_val_custom_##ctl_id, \
443} \
444
445static struct pvr2_sysfs_func_set funcs[] = {
446 INIT_BATCH(0),
447 INIT_BATCH(1),
448 INIT_BATCH(2),
449 INIT_BATCH(3),
450 INIT_BATCH(4),
451 INIT_BATCH(5),
452 INIT_BATCH(6),
453 INIT_BATCH(7),
454 INIT_BATCH(8),
455 INIT_BATCH(9),
456 INIT_BATCH(10),
457 INIT_BATCH(11),
458 INIT_BATCH(12),
459 INIT_BATCH(13),
460 INIT_BATCH(14),
461 INIT_BATCH(15),
462 INIT_BATCH(16),
463 INIT_BATCH(17),
464 INIT_BATCH(18),
465 INIT_BATCH(19),
466 INIT_BATCH(20),
467 INIT_BATCH(21),
468 INIT_BATCH(22),
469 INIT_BATCH(23),
470 INIT_BATCH(24),
471 INIT_BATCH(25),
472 INIT_BATCH(26),
473 INIT_BATCH(27),
474 INIT_BATCH(28),
475 INIT_BATCH(29),
476 INIT_BATCH(30),
477 INIT_BATCH(31),
478 INIT_BATCH(32),
479 INIT_BATCH(33),
Mike Isely39481992006-06-25 20:04:20 -0300480 INIT_BATCH(34),
481 INIT_BATCH(35),
482 INIT_BATCH(36),
483 INIT_BATCH(37),
484 INIT_BATCH(38),
485 INIT_BATCH(39),
486 INIT_BATCH(40),
487 INIT_BATCH(41),
488 INIT_BATCH(42),
489 INIT_BATCH(43),
490 INIT_BATCH(44),
491 INIT_BATCH(45),
492 INIT_BATCH(46),
493 INIT_BATCH(47),
494 INIT_BATCH(48),
495 INIT_BATCH(49),
496 INIT_BATCH(50),
497 INIT_BATCH(51),
498 INIT_BATCH(52),
499 INIT_BATCH(53),
500 INIT_BATCH(54),
501 INIT_BATCH(55),
502 INIT_BATCH(56),
503 INIT_BATCH(57),
504 INIT_BATCH(58),
505 INIT_BATCH(59),
Mike Iselyd8554972006-06-26 20:58:46 -0300506};
507
508
509static void pvr2_sysfs_add_control(struct pvr2_sysfs *sfp,int ctl_id)
510{
511 struct pvr2_sysfs_ctl_item *cip;
512 struct pvr2_sysfs_func_set *fp;
513 struct pvr2_ctrl *cptr;
514 unsigned int cnt,acnt;
Mike Isely08d41802006-07-22 21:26:30 -0300515 int ret;
Mike Iselyd8554972006-06-26 20:58:46 -0300516
Ahmed S. Darwisheca8ebf2007-01-20 00:35:03 -0300517 if ((ctl_id < 0) || (ctl_id >= ARRAY_SIZE(funcs))) {
Mike Iselyd8554972006-06-26 20:58:46 -0300518 return;
519 }
520
521 fp = funcs + ctl_id;
522 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,ctl_id);
523 if (!cptr) return;
524
Mike Iselyca545f72007-01-20 00:37:11 -0300525 cip = kzalloc(sizeof(*cip),GFP_KERNEL);
Mike Iselyd8554972006-06-26 20:58:46 -0300526 if (!cip) return;
Mike Iselyd8554972006-06-26 20:58:46 -0300527 pvr2_sysfs_trace("Creating pvr2_sysfs_ctl_item id=%p",cip);
528
529 cip->cptr = cptr;
530
531 cip->chptr = sfp;
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300532 cip->item_next = NULL;
Mike Iselyd8554972006-06-26 20:58:46 -0300533 if (sfp->item_last) {
534 sfp->item_last->item_next = cip;
535 } else {
536 sfp->item_first = cip;
537 }
538 sfp->item_last = cip;
539
Mike Iselyd8554972006-06-26 20:58:46 -0300540 cip->attr_name.attr.name = "name";
541 cip->attr_name.attr.mode = S_IRUGO;
542 cip->attr_name.show = fp->show_name;
543
Mike Isely33213962006-06-25 20:04:40 -0300544 cip->attr_type.attr.name = "type";
545 cip->attr_type.attr.mode = S_IRUGO;
546 cip->attr_type.show = fp->show_type;
547
Mike Iselyd8554972006-06-26 20:58:46 -0300548 cip->attr_min.attr.name = "min_val";
549 cip->attr_min.attr.mode = S_IRUGO;
550 cip->attr_min.show = fp->show_min;
551
Mike Iselyd8554972006-06-26 20:58:46 -0300552 cip->attr_max.attr.name = "max_val";
553 cip->attr_max.attr.mode = S_IRUGO;
554 cip->attr_max.show = fp->show_max;
555
Mike Iselyd8554972006-06-26 20:58:46 -0300556 cip->attr_val.attr.name = "cur_val";
557 cip->attr_val.attr.mode = S_IRUGO;
558
Mike Iselyd8554972006-06-26 20:58:46 -0300559 cip->attr_custom.attr.name = "custom_val";
560 cip->attr_custom.attr.mode = S_IRUGO;
561
Mike Iselyd8554972006-06-26 20:58:46 -0300562 cip->attr_enum.attr.name = "enum_val";
563 cip->attr_enum.attr.mode = S_IRUGO;
564 cip->attr_enum.show = fp->show_enum;
565
Mike Iselyd8554972006-06-26 20:58:46 -0300566 cip->attr_bits.attr.name = "bit_val";
567 cip->attr_bits.attr.mode = S_IRUGO;
568 cip->attr_bits.show = fp->show_bits;
569
570 if (pvr2_ctrl_is_writable(cptr)) {
571 cip->attr_val.attr.mode |= S_IWUSR|S_IWGRP;
572 cip->attr_custom.attr.mode |= S_IWUSR|S_IWGRP;
573 }
574
575 acnt = 0;
576 cip->attr_gen[acnt++] = &cip->attr_name.attr;
Mike Isely33213962006-06-25 20:04:40 -0300577 cip->attr_gen[acnt++] = &cip->attr_type.attr;
Mike Iselyd8554972006-06-26 20:58:46 -0300578 cip->attr_gen[acnt++] = &cip->attr_val.attr;
579 cip->attr_val.show = fp->show_val_norm;
580 cip->attr_val.store = fp->store_val_norm;
581 if (pvr2_ctrl_has_custom_symbols(cptr)) {
582 cip->attr_gen[acnt++] = &cip->attr_custom.attr;
583 cip->attr_custom.show = fp->show_val_custom;
584 cip->attr_custom.store = fp->store_val_custom;
585 }
586 switch (pvr2_ctrl_get_type(cptr)) {
587 case pvr2_ctl_enum:
588 // Control is an enumeration
589 cip->attr_gen[acnt++] = &cip->attr_enum.attr;
590 break;
591 case pvr2_ctl_int:
592 // Control is an integer
593 cip->attr_gen[acnt++] = &cip->attr_min.attr;
594 cip->attr_gen[acnt++] = &cip->attr_max.attr;
595 break;
596 case pvr2_ctl_bitmask:
597 // Control is an bitmask
598 cip->attr_gen[acnt++] = &cip->attr_bits.attr;
599 break;
600 default: break;
601 }
602
603 cnt = scnprintf(cip->name,sizeof(cip->name)-1,"ctl_%s",
604 pvr2_ctrl_get_name(cptr));
605 cip->name[cnt] = 0;
606 cip->grp.name = cip->name;
607 cip->grp.attrs = cip->attr_gen;
608
Mike Isely08d41802006-07-22 21:26:30 -0300609 ret = sysfs_create_group(&sfp->class_dev->kobj,&cip->grp);
610 if (ret) {
Mike Isely49844c22008-04-09 05:44:57 -0300611 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
612 "sysfs_create_group error: %d",
613 ret);
Mike Isely08d41802006-07-22 21:26:30 -0300614 return;
615 }
616 cip->created_ok = !0;
Mike Iselyd8554972006-06-26 20:58:46 -0300617}
618
619#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
Trent Piephoc726b652007-10-08 19:05:28 -0300620static ssize_t debuginfo_show(struct device *, struct device_attribute *,
621 char *);
622static ssize_t debugcmd_show(struct device *, struct device_attribute *,
623 char *);
624static ssize_t debugcmd_store(struct device *, struct device_attribute *,
625 const char *, size_t count);
Mike Iselyd8554972006-06-26 20:58:46 -0300626
627static void pvr2_sysfs_add_debugifc(struct pvr2_sysfs *sfp)
628{
629 struct pvr2_sysfs_debugifc *dip;
Michael Krufky3117bee2006-07-19 13:23:38 -0300630 int ret;
631
Mike Iselyca545f72007-01-20 00:37:11 -0300632 dip = kzalloc(sizeof(*dip),GFP_KERNEL);
Mike Iselyd8554972006-06-26 20:58:46 -0300633 if (!dip) return;
Mike Iselyd8554972006-06-26 20:58:46 -0300634 dip->attr_debugcmd.attr.name = "debugcmd";
635 dip->attr_debugcmd.attr.mode = S_IRUGO|S_IWUSR|S_IWGRP;
636 dip->attr_debugcmd.show = debugcmd_show;
637 dip->attr_debugcmd.store = debugcmd_store;
Mike Iselyd8554972006-06-26 20:58:46 -0300638 dip->attr_debuginfo.attr.name = "debuginfo";
639 dip->attr_debuginfo.attr.mode = S_IRUGO;
640 dip->attr_debuginfo.show = debuginfo_show;
641 sfp->debugifc = dip;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300642 ret = device_create_file(sfp->class_dev,&dip->attr_debugcmd);
Mike Isely08d41802006-07-22 21:26:30 -0300643 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300644 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
645 "device_create_file error: %d",
646 ret);
Mike Isely08d41802006-07-22 21:26:30 -0300647 } else {
648 dip->debugcmd_created_ok = !0;
649 }
Kay Sievers54bd5b62007-10-08 16:26:13 -0300650 ret = device_create_file(sfp->class_dev,&dip->attr_debuginfo);
Mike Isely08d41802006-07-22 21:26:30 -0300651 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300652 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
653 "device_create_file error: %d",
654 ret);
Mike Isely08d41802006-07-22 21:26:30 -0300655 } else {
656 dip->debuginfo_created_ok = !0;
657 }
Mike Iselyd8554972006-06-26 20:58:46 -0300658}
659
660
661static void pvr2_sysfs_tear_down_debugifc(struct pvr2_sysfs *sfp)
662{
663 if (!sfp->debugifc) return;
Mike Isely08d41802006-07-22 21:26:30 -0300664 if (sfp->debugifc->debuginfo_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300665 device_remove_file(sfp->class_dev,
Mike Isely08d41802006-07-22 21:26:30 -0300666 &sfp->debugifc->attr_debuginfo);
667 }
668 if (sfp->debugifc->debugcmd_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300669 device_remove_file(sfp->class_dev,
Mike Isely08d41802006-07-22 21:26:30 -0300670 &sfp->debugifc->attr_debugcmd);
671 }
Mike Iselyd8554972006-06-26 20:58:46 -0300672 kfree(sfp->debugifc);
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300673 sfp->debugifc = NULL;
Mike Iselyd8554972006-06-26 20:58:46 -0300674}
675#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
676
677
678static void pvr2_sysfs_add_controls(struct pvr2_sysfs *sfp)
679{
680 unsigned int idx,cnt;
681 cnt = pvr2_hdw_get_ctrl_count(sfp->channel.hdw);
682 for (idx = 0; idx < cnt; idx++) {
683 pvr2_sysfs_add_control(sfp,idx);
684 }
685}
686
687
688static void pvr2_sysfs_tear_down_controls(struct pvr2_sysfs *sfp)
689{
690 struct pvr2_sysfs_ctl_item *cip1,*cip2;
691 for (cip1 = sfp->item_first; cip1; cip1 = cip2) {
692 cip2 = cip1->item_next;
Mike Isely08d41802006-07-22 21:26:30 -0300693 if (cip1->created_ok) {
694 sysfs_remove_group(&sfp->class_dev->kobj,&cip1->grp);
695 }
Mike Iselyd8554972006-06-26 20:58:46 -0300696 pvr2_sysfs_trace("Destroying pvr2_sysfs_ctl_item id=%p",cip1);
697 kfree(cip1);
698 }
699}
700
701
702static void pvr2_sysfs_class_release(struct class *class)
703{
704 struct pvr2_sysfs_class *clp;
705 clp = container_of(class,struct pvr2_sysfs_class,class);
706 pvr2_sysfs_trace("Destroying pvr2_sysfs_class id=%p",clp);
707 kfree(clp);
708}
709
710
Kay Sievers54bd5b62007-10-08 16:26:13 -0300711static void pvr2_sysfs_release(struct device *class_dev)
Mike Iselyd8554972006-06-26 20:58:46 -0300712{
713 pvr2_sysfs_trace("Releasing class_dev id=%p",class_dev);
714 kfree(class_dev);
715}
716
717
718static void class_dev_destroy(struct pvr2_sysfs *sfp)
719{
720 if (!sfp->class_dev) return;
721#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
722 pvr2_sysfs_tear_down_debugifc(sfp);
723#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
724 pvr2_sysfs_tear_down_controls(sfp);
Mike Isely78a47102007-11-26 01:58:20 -0300725 if (sfp->hdw_desc_created_ok) {
726 device_remove_file(sfp->class_dev,
727 &sfp->attr_hdw_desc);
728 }
729 if (sfp->hdw_name_created_ok) {
730 device_remove_file(sfp->class_dev,
731 &sfp->attr_hdw_name);
732 }
Mike Isely31a18542007-04-08 01:11:47 -0300733 if (sfp->bus_info_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300734 device_remove_file(sfp->class_dev,
Mike Isely31a18542007-04-08 01:11:47 -0300735 &sfp->attr_bus_info);
736 }
Mike Isely08d41802006-07-22 21:26:30 -0300737 if (sfp->v4l_minor_number_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300738 device_remove_file(sfp->class_dev,
Mike Isely08d41802006-07-22 21:26:30 -0300739 &sfp->attr_v4l_minor_number);
740 }
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300741 if (sfp->v4l_radio_minor_number_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300742 device_remove_file(sfp->class_dev,
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300743 &sfp->attr_v4l_radio_minor_number);
744 }
Mike Isely08d41802006-07-22 21:26:30 -0300745 if (sfp->unit_number_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300746 device_remove_file(sfp->class_dev,
Mike Isely08d41802006-07-22 21:26:30 -0300747 &sfp->attr_unit_number);
748 }
Mike Iselyd8554972006-06-26 20:58:46 -0300749 pvr2_sysfs_trace("Destroying class_dev id=%p",sfp->class_dev);
Kay Sievers54bd5b62007-10-08 16:26:13 -0300750 sfp->class_dev->driver_data = NULL;
751 device_unregister(sfp->class_dev);
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300752 sfp->class_dev = NULL;
Mike Iselyd8554972006-06-26 20:58:46 -0300753}
754
755
Kay Sievers54bd5b62007-10-08 16:26:13 -0300756static ssize_t v4l_minor_number_show(struct device *class_dev,
757 struct device_attribute *attr, char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300758{
759 struct pvr2_sysfs *sfp;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300760 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -0300761 if (!sfp) return -EINVAL;
762 return scnprintf(buf,PAGE_SIZE,"%d\n",
Mike Iselyfd5a75f2006-12-27 23:11:22 -0300763 pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw,
Mike Isely80793842006-12-27 23:12:28 -0300764 pvr2_v4l_type_video));
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300765}
766
767
Kay Sievers54bd5b62007-10-08 16:26:13 -0300768static ssize_t bus_info_show(struct device *class_dev,
769 struct device_attribute *attr, char *buf)
Mike Isely31a18542007-04-08 01:11:47 -0300770{
771 struct pvr2_sysfs *sfp;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300772 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Isely31a18542007-04-08 01:11:47 -0300773 if (!sfp) return -EINVAL;
774 return scnprintf(buf,PAGE_SIZE,"%s\n",
775 pvr2_hdw_get_bus_info(sfp->channel.hdw));
776}
777
778
Mike Isely78a47102007-11-26 01:58:20 -0300779static ssize_t hdw_name_show(struct device *class_dev,
780 struct device_attribute *attr, char *buf)
781{
782 struct pvr2_sysfs *sfp;
783 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
784 if (!sfp) return -EINVAL;
785 return scnprintf(buf,PAGE_SIZE,"%s\n",
786 pvr2_hdw_get_type(sfp->channel.hdw));
787}
788
789
790static ssize_t hdw_desc_show(struct device *class_dev,
791 struct device_attribute *attr, char *buf)
792{
793 struct pvr2_sysfs *sfp;
794 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
795 if (!sfp) return -EINVAL;
796 return scnprintf(buf,PAGE_SIZE,"%s\n",
797 pvr2_hdw_get_desc(sfp->channel.hdw));
798}
799
800
Kay Sievers54bd5b62007-10-08 16:26:13 -0300801static ssize_t v4l_radio_minor_number_show(struct device *class_dev,
802 struct device_attribute *attr,
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300803 char *buf)
804{
805 struct pvr2_sysfs *sfp;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300806 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300807 if (!sfp) return -EINVAL;
808 return scnprintf(buf,PAGE_SIZE,"%d\n",
Mike Iselyfd5a75f2006-12-27 23:11:22 -0300809 pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw,
Mike Isely80793842006-12-27 23:12:28 -0300810 pvr2_v4l_type_radio));
Mike Iselyd8554972006-06-26 20:58:46 -0300811}
812
813
Kay Sievers54bd5b62007-10-08 16:26:13 -0300814static ssize_t unit_number_show(struct device *class_dev,
815 struct device_attribute *attr, char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300816{
817 struct pvr2_sysfs *sfp;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300818 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -0300819 if (!sfp) return -EINVAL;
820 return scnprintf(buf,PAGE_SIZE,"%d\n",
821 pvr2_hdw_get_unit_number(sfp->channel.hdw));
822}
823
824
825static void class_dev_create(struct pvr2_sysfs *sfp,
826 struct pvr2_sysfs_class *class_ptr)
827{
828 struct usb_device *usb_dev;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300829 struct device *class_dev;
Michael Krufky3117bee2006-07-19 13:23:38 -0300830 int ret;
831
Mike Iselyd8554972006-06-26 20:58:46 -0300832 usb_dev = pvr2_hdw_get_dev(sfp->channel.hdw);
833 if (!usb_dev) return;
Mike Iselyca545f72007-01-20 00:37:11 -0300834 class_dev = kzalloc(sizeof(*class_dev),GFP_KERNEL);
Mike Iselyd8554972006-06-26 20:58:46 -0300835 if (!class_dev) return;
Mike Iselyd8554972006-06-26 20:58:46 -0300836
837 pvr2_sysfs_trace("Creating class_dev id=%p",class_dev);
838
839 class_dev->class = &class_ptr->class;
840 if (pvr2_hdw_get_sn(sfp->channel.hdw)) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300841 snprintf(class_dev->bus_id, BUS_ID_SIZE, "sn-%lu",
Mike Iselyd8554972006-06-26 20:58:46 -0300842 pvr2_hdw_get_sn(sfp->channel.hdw));
843 } else if (pvr2_hdw_get_unit_number(sfp->channel.hdw) >= 0) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300844 snprintf(class_dev->bus_id, BUS_ID_SIZE, "unit-%c",
Mike Iselyd8554972006-06-26 20:58:46 -0300845 pvr2_hdw_get_unit_number(sfp->channel.hdw) + 'a');
846 } else {
847 kfree(class_dev);
848 return;
849 }
850
Kay Sievers54bd5b62007-10-08 16:26:13 -0300851 class_dev->parent = &usb_dev->dev;
Mike Iselyd8554972006-06-26 20:58:46 -0300852
853 sfp->class_dev = class_dev;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300854 class_dev->driver_data = sfp;
855 ret = device_register(class_dev);
Michael Krufky3117bee2006-07-19 13:23:38 -0300856 if (ret) {
Mike Isely49844c22008-04-09 05:44:57 -0300857 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
858 "device_register failed");
Michael Krufky3117bee2006-07-19 13:23:38 -0300859 kfree(class_dev);
860 return;
861 }
Mike Iselyd8554972006-06-26 20:58:46 -0300862
Mike Iselyd8554972006-06-26 20:58:46 -0300863 sfp->attr_v4l_minor_number.attr.name = "v4l_minor_number";
864 sfp->attr_v4l_minor_number.attr.mode = S_IRUGO;
865 sfp->attr_v4l_minor_number.show = v4l_minor_number_show;
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300866 sfp->attr_v4l_minor_number.store = NULL;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300867 ret = device_create_file(sfp->class_dev,
Mike Isely08d41802006-07-22 21:26:30 -0300868 &sfp->attr_v4l_minor_number);
869 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300870 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
871 "device_create_file error: %d",
872 ret);
Mike Isely08d41802006-07-22 21:26:30 -0300873 } else {
874 sfp->v4l_minor_number_created_ok = !0;
875 }
Michael Krufky3117bee2006-07-19 13:23:38 -0300876
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300877 sfp->attr_v4l_radio_minor_number.attr.name = "v4l_radio_minor_number";
878 sfp->attr_v4l_radio_minor_number.attr.mode = S_IRUGO;
879 sfp->attr_v4l_radio_minor_number.show = v4l_radio_minor_number_show;
880 sfp->attr_v4l_radio_minor_number.store = NULL;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300881 ret = device_create_file(sfp->class_dev,
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300882 &sfp->attr_v4l_radio_minor_number);
883 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300884 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
885 "device_create_file error: %d",
886 ret);
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300887 } else {
888 sfp->v4l_radio_minor_number_created_ok = !0;
889 }
890
Mike Iselyd8554972006-06-26 20:58:46 -0300891 sfp->attr_unit_number.attr.name = "unit_number";
892 sfp->attr_unit_number.attr.mode = S_IRUGO;
893 sfp->attr_unit_number.show = unit_number_show;
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300894 sfp->attr_unit_number.store = NULL;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300895 ret = device_create_file(sfp->class_dev,&sfp->attr_unit_number);
Mike Isely08d41802006-07-22 21:26:30 -0300896 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300897 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
898 "device_create_file error: %d",
899 ret);
Mike Isely08d41802006-07-22 21:26:30 -0300900 } else {
901 sfp->unit_number_created_ok = !0;
902 }
Mike Iselyd8554972006-06-26 20:58:46 -0300903
Mike Isely31a18542007-04-08 01:11:47 -0300904 sfp->attr_bus_info.attr.name = "bus_info_str";
905 sfp->attr_bus_info.attr.mode = S_IRUGO;
906 sfp->attr_bus_info.show = bus_info_show;
907 sfp->attr_bus_info.store = NULL;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300908 ret = device_create_file(sfp->class_dev,
Mike Isely31a18542007-04-08 01:11:47 -0300909 &sfp->attr_bus_info);
910 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300911 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
912 "device_create_file error: %d",
913 ret);
Mike Isely31a18542007-04-08 01:11:47 -0300914 } else {
915 sfp->bus_info_created_ok = !0;
916 }
917
Mike Isely78a47102007-11-26 01:58:20 -0300918 sfp->attr_hdw_name.attr.name = "device_hardware_type";
919 sfp->attr_hdw_name.attr.mode = S_IRUGO;
920 sfp->attr_hdw_name.show = hdw_name_show;
921 sfp->attr_hdw_name.store = NULL;
922 ret = device_create_file(sfp->class_dev,
923 &sfp->attr_hdw_name);
924 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300925 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
926 "device_create_file error: %d",
927 ret);
Mike Isely78a47102007-11-26 01:58:20 -0300928 } else {
929 sfp->hdw_name_created_ok = !0;
930 }
931
932 sfp->attr_hdw_desc.attr.name = "device_hardware_description";
933 sfp->attr_hdw_desc.attr.mode = S_IRUGO;
934 sfp->attr_hdw_desc.show = hdw_desc_show;
935 sfp->attr_hdw_desc.store = NULL;
936 ret = device_create_file(sfp->class_dev,
937 &sfp->attr_hdw_desc);
938 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300939 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
940 "device_create_file error: %d",
941 ret);
Mike Isely78a47102007-11-26 01:58:20 -0300942 } else {
943 sfp->hdw_desc_created_ok = !0;
944 }
945
Mike Iselyd8554972006-06-26 20:58:46 -0300946 pvr2_sysfs_add_controls(sfp);
947#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
948 pvr2_sysfs_add_debugifc(sfp);
949#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
950}
951
952
953static void pvr2_sysfs_internal_check(struct pvr2_channel *chp)
954{
955 struct pvr2_sysfs *sfp;
956 sfp = container_of(chp,struct pvr2_sysfs,channel);
957 if (!sfp->channel.mc_head->disconnect_flag) return;
958 pvr2_trace(PVR2_TRACE_STRUCT,"Destroying pvr2_sysfs id=%p",sfp);
959 class_dev_destroy(sfp);
960 pvr2_channel_done(&sfp->channel);
961 kfree(sfp);
962}
963
964
965struct pvr2_sysfs *pvr2_sysfs_create(struct pvr2_context *mp,
966 struct pvr2_sysfs_class *class_ptr)
967{
968 struct pvr2_sysfs *sfp;
Mike Iselyca545f72007-01-20 00:37:11 -0300969 sfp = kzalloc(sizeof(*sfp),GFP_KERNEL);
Mike Iselyd8554972006-06-26 20:58:46 -0300970 if (!sfp) return sfp;
Mike Iselyd8554972006-06-26 20:58:46 -0300971 pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr2_sysfs id=%p",sfp);
972 pvr2_channel_init(&sfp->channel,mp);
973 sfp->channel.check_func = pvr2_sysfs_internal_check;
974
975 class_dev_create(sfp,class_ptr);
976 return sfp;
977}
978
979
Mike Iselyd8554972006-06-26 20:58:46 -0300980
981struct pvr2_sysfs_class *pvr2_sysfs_class_create(void)
982{
983 struct pvr2_sysfs_class *clp;
Mike Iselyca545f72007-01-20 00:37:11 -0300984 clp = kzalloc(sizeof(*clp),GFP_KERNEL);
Mike Iselyd8554972006-06-26 20:58:46 -0300985 if (!clp) return clp;
Mike Iselyd8554972006-06-26 20:58:46 -0300986 pvr2_sysfs_trace("Creating pvr2_sysfs_class id=%p",clp);
987 clp->class.name = "pvrusb2";
988 clp->class.class_release = pvr2_sysfs_class_release;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300989 clp->class.dev_release = pvr2_sysfs_release;
Mike Iselyd8554972006-06-26 20:58:46 -0300990 if (class_register(&clp->class)) {
991 pvr2_sysfs_trace(
992 "Registration failed for pvr2_sysfs_class id=%p",clp);
993 kfree(clp);
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300994 clp = NULL;
Mike Iselyd8554972006-06-26 20:58:46 -0300995 }
996 return clp;
997}
998
999
1000void pvr2_sysfs_class_destroy(struct pvr2_sysfs_class *clp)
1001{
1002 class_unregister(&clp->class);
1003}
1004
1005
1006#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
Trent Piephoc726b652007-10-08 19:05:28 -03001007static ssize_t debuginfo_show(struct device *class_dev,
1008 struct device_attribute *attr, char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -03001009{
1010 struct pvr2_sysfs *sfp;
Kay Sievers54bd5b62007-10-08 16:26:13 -03001011 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -03001012 if (!sfp) return -EINVAL;
1013 pvr2_hdw_trigger_module_log(sfp->channel.hdw);
1014 return pvr2_debugifc_print_info(sfp->channel.hdw,buf,PAGE_SIZE);
1015}
1016
1017
Trent Piephoc726b652007-10-08 19:05:28 -03001018static ssize_t debugcmd_show(struct device *class_dev,
1019 struct device_attribute *attr, char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -03001020{
1021 struct pvr2_sysfs *sfp;
Kay Sievers54bd5b62007-10-08 16:26:13 -03001022 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -03001023 if (!sfp) return -EINVAL;
1024 return pvr2_debugifc_print_status(sfp->channel.hdw,buf,PAGE_SIZE);
1025}
1026
1027
Kay Sievers54bd5b62007-10-08 16:26:13 -03001028static ssize_t debugcmd_store(struct device *class_dev,
Trent Piephoc726b652007-10-08 19:05:28 -03001029 struct device_attribute *attr,
Kay Sievers54bd5b62007-10-08 16:26:13 -03001030 const char *buf, size_t count)
Mike Iselyd8554972006-06-26 20:58:46 -03001031{
1032 struct pvr2_sysfs *sfp;
1033 int ret;
1034
Kay Sievers54bd5b62007-10-08 16:26:13 -03001035 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -03001036 if (!sfp) return -EINVAL;
1037
1038 ret = pvr2_debugifc_docmd(sfp->channel.hdw,buf,count);
1039 if (ret < 0) return ret;
1040 return count;
1041}
1042#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
1043
1044
1045/*
1046 Stuff for Emacs to see, in order to encourage consistent editing style:
1047 *** Local Variables: ***
1048 *** mode: c ***
1049 *** fill-column: 75 ***
1050 *** tab-width: 8 ***
1051 *** c-basic-offset: 8 ***
1052 *** End: ***
1053 */