blob: 7a1cd878e31a70f8423bbdf6810914fa2ec3192c [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>
24#include <asm/semaphore.h>
25#include "pvrusb2-sysfs.h"
26#include "pvrusb2-hdw.h"
27#include "pvrusb2-debug.h"
28#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
29#include "pvrusb2-debugifc.h"
30#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
31
32#define pvr2_sysfs_trace(...) pvr2_trace(PVR2_TRACE_SYSFS,__VA_ARGS__)
33
34struct pvr2_sysfs {
35 struct pvr2_channel channel;
Kay Sievers54bd5b62007-10-08 16:26:13 -030036 struct device *class_dev;
Mike Iselyd8554972006-06-26 20:58:46 -030037#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
38 struct pvr2_sysfs_debugifc *debugifc;
39#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
40 struct pvr2_sysfs_ctl_item *item_first;
41 struct pvr2_sysfs_ctl_item *item_last;
Kay Sievers54bd5b62007-10-08 16:26:13 -030042 struct device_attribute attr_v4l_minor_number;
43 struct device_attribute attr_v4l_radio_minor_number;
44 struct device_attribute attr_unit_number;
45 struct device_attribute attr_bus_info;
Mike Isely78a47102007-11-26 01:58:20 -030046 struct device_attribute attr_hdw_name;
47 struct device_attribute attr_hdw_desc;
Mike Isely08d41802006-07-22 21:26:30 -030048 int v4l_minor_number_created_ok;
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -030049 int v4l_radio_minor_number_created_ok;
Mike Isely08d41802006-07-22 21:26:30 -030050 int unit_number_created_ok;
Mike Isely31a18542007-04-08 01:11:47 -030051 int bus_info_created_ok;
Mike Isely78a47102007-11-26 01:58:20 -030052 int hdw_name_created_ok;
53 int hdw_desc_created_ok;
Mike Iselyd8554972006-06-26 20:58:46 -030054};
55
56#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
57struct pvr2_sysfs_debugifc {
Kay Sievers54bd5b62007-10-08 16:26:13 -030058 struct device_attribute attr_debugcmd;
59 struct device_attribute attr_debuginfo;
Mike Isely08d41802006-07-22 21:26:30 -030060 int debugcmd_created_ok;
61 int debuginfo_created_ok;
Mike Iselyd8554972006-06-26 20:58:46 -030062};
63#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
64
65struct pvr2_sysfs_ctl_item {
Kay Sievers54bd5b62007-10-08 16:26:13 -030066 struct device_attribute attr_name;
67 struct device_attribute attr_type;
68 struct device_attribute attr_min;
69 struct device_attribute attr_max;
70 struct device_attribute attr_enum;
71 struct device_attribute attr_bits;
72 struct device_attribute attr_val;
73 struct device_attribute attr_custom;
Mike Iselyd8554972006-06-26 20:58:46 -030074 struct pvr2_ctrl *cptr;
75 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
Kay Sievers54bd5b62007-10-08 16:26:13 -030087static ssize_t show_name(int id,struct device *class_dev,char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -030088{
89 struct pvr2_ctrl *cptr;
90 struct pvr2_sysfs *sfp;
91 const char *name;
92
Kay Sievers54bd5b62007-10-08 16:26:13 -030093 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -030094 if (!sfp) return -EINVAL;
95 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
96 if (!cptr) return -EINVAL;
97
98 name = pvr2_ctrl_get_desc(cptr);
99 pvr2_sysfs_trace("pvr2_sysfs(%p) show_name(cid=%d) is %s",sfp,id,name);
100
101 if (!name) return -EINVAL;
102
103 return scnprintf(buf,PAGE_SIZE,"%s\n",name);
104}
105
Kay Sievers54bd5b62007-10-08 16:26:13 -0300106static ssize_t show_type(int id,struct device *class_dev,char *buf)
Mike Isely33213962006-06-25 20:04:40 -0300107{
108 struct pvr2_ctrl *cptr;
109 struct pvr2_sysfs *sfp;
110 const char *name;
111 enum pvr2_ctl_type tp;
112
Kay Sievers54bd5b62007-10-08 16:26:13 -0300113 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Isely33213962006-06-25 20:04:40 -0300114 if (!sfp) return -EINVAL;
115 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
116 if (!cptr) return -EINVAL;
117
118 tp = pvr2_ctrl_get_type(cptr);
119 switch (tp) {
120 case pvr2_ctl_int: name = "integer"; break;
121 case pvr2_ctl_enum: name = "enum"; break;
122 case pvr2_ctl_bitmask: name = "bitmask"; break;
123 case pvr2_ctl_bool: name = "boolean"; break;
124 default: name = "?"; break;
125 }
126 pvr2_sysfs_trace("pvr2_sysfs(%p) show_type(cid=%d) is %s",sfp,id,name);
127
128 if (!name) return -EINVAL;
129
130 return scnprintf(buf,PAGE_SIZE,"%s\n",name);
131}
132
Kay Sievers54bd5b62007-10-08 16:26:13 -0300133static ssize_t show_min(int id,struct device *class_dev,char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300134{
135 struct pvr2_ctrl *cptr;
136 struct pvr2_sysfs *sfp;
137 long val;
138
Kay Sievers54bd5b62007-10-08 16:26:13 -0300139 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -0300140 if (!sfp) return -EINVAL;
141 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
142 if (!cptr) return -EINVAL;
143 val = pvr2_ctrl_get_min(cptr);
144
145 pvr2_sysfs_trace("pvr2_sysfs(%p) show_min(cid=%d) is %ld",sfp,id,val);
146
147 return scnprintf(buf,PAGE_SIZE,"%ld\n",val);
148}
149
Kay Sievers54bd5b62007-10-08 16:26:13 -0300150static ssize_t show_max(int id,struct device *class_dev,char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300151{
152 struct pvr2_ctrl *cptr;
153 struct pvr2_sysfs *sfp;
154 long val;
155
Kay Sievers54bd5b62007-10-08 16:26:13 -0300156 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -0300157 if (!sfp) return -EINVAL;
158 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
159 if (!cptr) return -EINVAL;
160 val = pvr2_ctrl_get_max(cptr);
161
162 pvr2_sysfs_trace("pvr2_sysfs(%p) show_max(cid=%d) is %ld",sfp,id,val);
163
164 return scnprintf(buf,PAGE_SIZE,"%ld\n",val);
165}
166
Kay Sievers54bd5b62007-10-08 16:26:13 -0300167static ssize_t show_val_norm(int id,struct device *class_dev,char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300168{
169 struct pvr2_ctrl *cptr;
170 struct pvr2_sysfs *sfp;
171 int val,ret;
172 unsigned int cnt = 0;
173
Kay Sievers54bd5b62007-10-08 16:26:13 -0300174 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -0300175 if (!sfp) return -EINVAL;
176 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
177 if (!cptr) return -EINVAL;
178
179 ret = pvr2_ctrl_get_value(cptr,&val);
180 if (ret < 0) return ret;
181
182 ret = pvr2_ctrl_value_to_sym(cptr,~0,val,
183 buf,PAGE_SIZE-1,&cnt);
184
185 pvr2_sysfs_trace("pvr2_sysfs(%p) show_val_norm(cid=%d) is %.*s (%d)",
186 sfp,id,cnt,buf,val);
187 buf[cnt] = '\n';
188 return cnt+1;
189}
190
Kay Sievers54bd5b62007-10-08 16:26:13 -0300191static ssize_t show_val_custom(int id,struct device *class_dev,char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300192{
193 struct pvr2_ctrl *cptr;
194 struct pvr2_sysfs *sfp;
195 int val,ret;
196 unsigned int cnt = 0;
197
Kay Sievers54bd5b62007-10-08 16:26:13 -0300198 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -0300199 if (!sfp) return -EINVAL;
200 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
201 if (!cptr) return -EINVAL;
202
203 ret = pvr2_ctrl_get_value(cptr,&val);
204 if (ret < 0) return ret;
205
206 ret = pvr2_ctrl_custom_value_to_sym(cptr,~0,val,
207 buf,PAGE_SIZE-1,&cnt);
208
209 pvr2_sysfs_trace("pvr2_sysfs(%p) show_val_custom(cid=%d) is %.*s (%d)",
210 sfp,id,cnt,buf,val);
211 buf[cnt] = '\n';
212 return cnt+1;
213}
214
Kay Sievers54bd5b62007-10-08 16:26:13 -0300215static ssize_t show_enum(int id,struct device *class_dev,char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300216{
217 struct pvr2_ctrl *cptr;
218 struct pvr2_sysfs *sfp;
219 long val;
220 unsigned int bcnt,ccnt,ecnt;
221
Kay Sievers54bd5b62007-10-08 16:26:13 -0300222 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -0300223 if (!sfp) return -EINVAL;
224 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
225 if (!cptr) return -EINVAL;
226 ecnt = pvr2_ctrl_get_cnt(cptr);
227 bcnt = 0;
228 for (val = 0; val < ecnt; val++) {
229 pvr2_ctrl_get_valname(cptr,val,buf+bcnt,PAGE_SIZE-bcnt,&ccnt);
Mike Isely45886772006-06-25 20:04:13 -0300230 if (!ccnt) continue;
Mike Iselyd8554972006-06-26 20:58:46 -0300231 bcnt += ccnt;
232 if (bcnt >= PAGE_SIZE) break;
233 buf[bcnt] = '\n';
234 bcnt++;
235 }
236 pvr2_sysfs_trace("pvr2_sysfs(%p) show_enum(cid=%d)",sfp,id);
237 return bcnt;
238}
239
Kay Sievers54bd5b62007-10-08 16:26:13 -0300240static ssize_t show_bits(int id,struct device *class_dev,char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300241{
242 struct pvr2_ctrl *cptr;
243 struct pvr2_sysfs *sfp;
244 int valid_bits,msk;
245 unsigned int bcnt,ccnt;
246
Kay Sievers54bd5b62007-10-08 16:26:13 -0300247 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -0300248 if (!sfp) return -EINVAL;
249 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
250 if (!cptr) return -EINVAL;
251 valid_bits = pvr2_ctrl_get_mask(cptr);
252 bcnt = 0;
253 for (msk = 1; valid_bits; msk <<= 1) {
254 if (!(msk & valid_bits)) continue;
255 valid_bits &= ~msk;
256 pvr2_ctrl_get_valname(cptr,msk,buf+bcnt,PAGE_SIZE-bcnt,&ccnt);
257 bcnt += ccnt;
258 if (bcnt >= PAGE_SIZE) break;
259 buf[bcnt] = '\n';
260 bcnt++;
261 }
262 pvr2_sysfs_trace("pvr2_sysfs(%p) show_bits(cid=%d)",sfp,id);
263 return bcnt;
264}
265
266static int store_val_any(int id,int customfl,struct pvr2_sysfs *sfp,
267 const char *buf,unsigned int count)
268{
269 struct pvr2_ctrl *cptr;
270 int ret;
271 int mask,val;
272
273 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
274 if (customfl) {
275 ret = pvr2_ctrl_custom_sym_to_value(cptr,buf,count,&mask,&val);
276 } else {
277 ret = pvr2_ctrl_sym_to_value(cptr,buf,count,&mask,&val);
278 }
279 if (ret < 0) return ret;
280 ret = pvr2_ctrl_set_mask_value(cptr,mask,val);
281 pvr2_hdw_commit_ctl(sfp->channel.hdw);
282 return ret;
283}
284
Kay Sievers54bd5b62007-10-08 16:26:13 -0300285static ssize_t store_val_norm(int id,struct device *class_dev,
Mike Iselyd8554972006-06-26 20:58:46 -0300286 const char *buf,size_t count)
287{
288 struct pvr2_sysfs *sfp;
289 int ret;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300290 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -0300291 ret = store_val_any(id,0,sfp,buf,count);
292 if (!ret) ret = count;
293 return ret;
294}
295
Kay Sievers54bd5b62007-10-08 16:26:13 -0300296static ssize_t store_val_custom(int id,struct device *class_dev,
Mike Iselyd8554972006-06-26 20:58:46 -0300297 const char *buf,size_t count)
298{
299 struct pvr2_sysfs *sfp;
300 int ret;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300301 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -0300302 ret = store_val_any(id,1,sfp,buf,count);
303 if (!ret) ret = count;
304 return ret;
305}
306
307/*
308 Mike Isely <isely@pobox.com> 30-April-2005
309
310 This next batch of horrible preprocessor hackery is needed because the
Kay Sievers54bd5b62007-10-08 16:26:13 -0300311 kernel's device_attribute mechanism fails to pass the actual
Mike Iselyd8554972006-06-26 20:58:46 -0300312 attribute through to the show / store functions, which means we have no
313 way to package up any attribute-specific parameters, like for example the
314 control id. So we work around this brain-damage by encoding the control
315 id into the show / store functions themselves and pick the function based
316 on the control id we're setting up. These macros try to ease the pain.
317 Yuck.
318*/
319
320#define CREATE_SHOW_INSTANCE(sf_name,ctl_id) \
Kay Sievers54bd5b62007-10-08 16:26:13 -0300321static ssize_t sf_name##_##ctl_id(struct device *class_dev, \
322struct device_attribute *attr, char *buf) \
Mike Iselyd8554972006-06-26 20:58:46 -0300323{ return sf_name(ctl_id,class_dev,buf); }
324
325#define CREATE_STORE_INSTANCE(sf_name,ctl_id) \
Kay Sievers54bd5b62007-10-08 16:26:13 -0300326static ssize_t sf_name##_##ctl_id(struct device *class_dev, \
327struct device_attribute *attr, const char *buf, size_t count) \
Mike Iselyd8554972006-06-26 20:58:46 -0300328{ return sf_name(ctl_id,class_dev,buf,count); }
329
330#define CREATE_BATCH(ctl_id) \
331CREATE_SHOW_INSTANCE(show_name,ctl_id) \
Mike Isely33213962006-06-25 20:04:40 -0300332CREATE_SHOW_INSTANCE(show_type,ctl_id) \
Mike Iselyd8554972006-06-26 20:58:46 -0300333CREATE_SHOW_INSTANCE(show_min,ctl_id) \
334CREATE_SHOW_INSTANCE(show_max,ctl_id) \
335CREATE_SHOW_INSTANCE(show_val_norm,ctl_id) \
336CREATE_SHOW_INSTANCE(show_val_custom,ctl_id) \
337CREATE_SHOW_INSTANCE(show_enum,ctl_id) \
338CREATE_SHOW_INSTANCE(show_bits,ctl_id) \
339CREATE_STORE_INSTANCE(store_val_norm,ctl_id) \
340CREATE_STORE_INSTANCE(store_val_custom,ctl_id) \
341
342CREATE_BATCH(0)
343CREATE_BATCH(1)
344CREATE_BATCH(2)
345CREATE_BATCH(3)
346CREATE_BATCH(4)
347CREATE_BATCH(5)
348CREATE_BATCH(6)
349CREATE_BATCH(7)
350CREATE_BATCH(8)
351CREATE_BATCH(9)
352CREATE_BATCH(10)
353CREATE_BATCH(11)
354CREATE_BATCH(12)
355CREATE_BATCH(13)
356CREATE_BATCH(14)
357CREATE_BATCH(15)
358CREATE_BATCH(16)
359CREATE_BATCH(17)
360CREATE_BATCH(18)
361CREATE_BATCH(19)
362CREATE_BATCH(20)
363CREATE_BATCH(21)
364CREATE_BATCH(22)
365CREATE_BATCH(23)
366CREATE_BATCH(24)
367CREATE_BATCH(25)
368CREATE_BATCH(26)
369CREATE_BATCH(27)
370CREATE_BATCH(28)
371CREATE_BATCH(29)
372CREATE_BATCH(30)
373CREATE_BATCH(31)
374CREATE_BATCH(32)
375CREATE_BATCH(33)
Mike Isely39481992006-06-25 20:04:20 -0300376CREATE_BATCH(34)
377CREATE_BATCH(35)
378CREATE_BATCH(36)
379CREATE_BATCH(37)
380CREATE_BATCH(38)
381CREATE_BATCH(39)
382CREATE_BATCH(40)
383CREATE_BATCH(41)
384CREATE_BATCH(42)
385CREATE_BATCH(43)
386CREATE_BATCH(44)
387CREATE_BATCH(45)
388CREATE_BATCH(46)
389CREATE_BATCH(47)
390CREATE_BATCH(48)
391CREATE_BATCH(49)
392CREATE_BATCH(50)
393CREATE_BATCH(51)
394CREATE_BATCH(52)
395CREATE_BATCH(53)
396CREATE_BATCH(54)
397CREATE_BATCH(55)
398CREATE_BATCH(56)
399CREATE_BATCH(57)
400CREATE_BATCH(58)
401CREATE_BATCH(59)
Mike Iselyd8554972006-06-26 20:58:46 -0300402
403struct pvr2_sysfs_func_set {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300404 ssize_t (*show_name)(struct device *,
405 struct device_attribute *attr, char *);
406 ssize_t (*show_type)(struct device *,
407 struct device_attribute *attr, char *);
408 ssize_t (*show_min)(struct device *,
409 struct device_attribute *attr, char *);
410 ssize_t (*show_max)(struct device *,
411 struct device_attribute *attr, char *);
412 ssize_t (*show_enum)(struct device *,
413 struct device_attribute *attr, char *);
414 ssize_t (*show_bits)(struct device *,
415 struct device_attribute *attr, char *);
416 ssize_t (*show_val_norm)(struct device *,
417 struct device_attribute *attr, char *);
418 ssize_t (*store_val_norm)(struct device *,
419 struct device_attribute *attr,
Mike Iselyd8554972006-06-26 20:58:46 -0300420 const char *,size_t);
Kay Sievers54bd5b62007-10-08 16:26:13 -0300421 ssize_t (*show_val_custom)(struct device *,
422 struct device_attribute *attr, char *);
423 ssize_t (*store_val_custom)(struct device *,
424 struct device_attribute *attr,
Mike Iselyd8554972006-06-26 20:58:46 -0300425 const char *,size_t);
426};
427
428#define INIT_BATCH(ctl_id) \
429[ctl_id] = { \
430 .show_name = show_name_##ctl_id, \
Mike Isely33213962006-06-25 20:04:40 -0300431 .show_type = show_type_##ctl_id, \
Mike Iselyd8554972006-06-26 20:58:46 -0300432 .show_min = show_min_##ctl_id, \
433 .show_max = show_max_##ctl_id, \
434 .show_enum = show_enum_##ctl_id, \
435 .show_bits = show_bits_##ctl_id, \
436 .show_val_norm = show_val_norm_##ctl_id, \
437 .store_val_norm = store_val_norm_##ctl_id, \
438 .show_val_custom = show_val_custom_##ctl_id, \
439 .store_val_custom = store_val_custom_##ctl_id, \
440} \
441
442static struct pvr2_sysfs_func_set funcs[] = {
443 INIT_BATCH(0),
444 INIT_BATCH(1),
445 INIT_BATCH(2),
446 INIT_BATCH(3),
447 INIT_BATCH(4),
448 INIT_BATCH(5),
449 INIT_BATCH(6),
450 INIT_BATCH(7),
451 INIT_BATCH(8),
452 INIT_BATCH(9),
453 INIT_BATCH(10),
454 INIT_BATCH(11),
455 INIT_BATCH(12),
456 INIT_BATCH(13),
457 INIT_BATCH(14),
458 INIT_BATCH(15),
459 INIT_BATCH(16),
460 INIT_BATCH(17),
461 INIT_BATCH(18),
462 INIT_BATCH(19),
463 INIT_BATCH(20),
464 INIT_BATCH(21),
465 INIT_BATCH(22),
466 INIT_BATCH(23),
467 INIT_BATCH(24),
468 INIT_BATCH(25),
469 INIT_BATCH(26),
470 INIT_BATCH(27),
471 INIT_BATCH(28),
472 INIT_BATCH(29),
473 INIT_BATCH(30),
474 INIT_BATCH(31),
475 INIT_BATCH(32),
476 INIT_BATCH(33),
Mike Isely39481992006-06-25 20:04:20 -0300477 INIT_BATCH(34),
478 INIT_BATCH(35),
479 INIT_BATCH(36),
480 INIT_BATCH(37),
481 INIT_BATCH(38),
482 INIT_BATCH(39),
483 INIT_BATCH(40),
484 INIT_BATCH(41),
485 INIT_BATCH(42),
486 INIT_BATCH(43),
487 INIT_BATCH(44),
488 INIT_BATCH(45),
489 INIT_BATCH(46),
490 INIT_BATCH(47),
491 INIT_BATCH(48),
492 INIT_BATCH(49),
493 INIT_BATCH(50),
494 INIT_BATCH(51),
495 INIT_BATCH(52),
496 INIT_BATCH(53),
497 INIT_BATCH(54),
498 INIT_BATCH(55),
499 INIT_BATCH(56),
500 INIT_BATCH(57),
501 INIT_BATCH(58),
502 INIT_BATCH(59),
Mike Iselyd8554972006-06-26 20:58:46 -0300503};
504
505
506static void pvr2_sysfs_add_control(struct pvr2_sysfs *sfp,int ctl_id)
507{
508 struct pvr2_sysfs_ctl_item *cip;
509 struct pvr2_sysfs_func_set *fp;
510 struct pvr2_ctrl *cptr;
511 unsigned int cnt,acnt;
Mike Isely08d41802006-07-22 21:26:30 -0300512 int ret;
Mike Iselyd8554972006-06-26 20:58:46 -0300513
Ahmed S. Darwisheca8ebf2007-01-20 00:35:03 -0300514 if ((ctl_id < 0) || (ctl_id >= ARRAY_SIZE(funcs))) {
Mike Iselyd8554972006-06-26 20:58:46 -0300515 return;
516 }
517
518 fp = funcs + ctl_id;
519 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,ctl_id);
520 if (!cptr) return;
521
Mike Iselyca545f72007-01-20 00:37:11 -0300522 cip = kzalloc(sizeof(*cip),GFP_KERNEL);
Mike Iselyd8554972006-06-26 20:58:46 -0300523 if (!cip) return;
Mike Iselyd8554972006-06-26 20:58:46 -0300524 pvr2_sysfs_trace("Creating pvr2_sysfs_ctl_item id=%p",cip);
525
526 cip->cptr = cptr;
527
528 cip->chptr = sfp;
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300529 cip->item_next = NULL;
Mike Iselyd8554972006-06-26 20:58:46 -0300530 if (sfp->item_last) {
531 sfp->item_last->item_next = cip;
532 } else {
533 sfp->item_first = cip;
534 }
535 sfp->item_last = cip;
536
Mike Iselyd8554972006-06-26 20:58:46 -0300537 cip->attr_name.attr.name = "name";
538 cip->attr_name.attr.mode = S_IRUGO;
539 cip->attr_name.show = fp->show_name;
540
Mike Isely33213962006-06-25 20:04:40 -0300541 cip->attr_type.attr.name = "type";
542 cip->attr_type.attr.mode = S_IRUGO;
543 cip->attr_type.show = fp->show_type;
544
Mike Iselyd8554972006-06-26 20:58:46 -0300545 cip->attr_min.attr.name = "min_val";
546 cip->attr_min.attr.mode = S_IRUGO;
547 cip->attr_min.show = fp->show_min;
548
Mike Iselyd8554972006-06-26 20:58:46 -0300549 cip->attr_max.attr.name = "max_val";
550 cip->attr_max.attr.mode = S_IRUGO;
551 cip->attr_max.show = fp->show_max;
552
Mike Iselyd8554972006-06-26 20:58:46 -0300553 cip->attr_val.attr.name = "cur_val";
554 cip->attr_val.attr.mode = S_IRUGO;
555
Mike Iselyd8554972006-06-26 20:58:46 -0300556 cip->attr_custom.attr.name = "custom_val";
557 cip->attr_custom.attr.mode = S_IRUGO;
558
Mike Iselyd8554972006-06-26 20:58:46 -0300559 cip->attr_enum.attr.name = "enum_val";
560 cip->attr_enum.attr.mode = S_IRUGO;
561 cip->attr_enum.show = fp->show_enum;
562
Mike Iselyd8554972006-06-26 20:58:46 -0300563 cip->attr_bits.attr.name = "bit_val";
564 cip->attr_bits.attr.mode = S_IRUGO;
565 cip->attr_bits.show = fp->show_bits;
566
567 if (pvr2_ctrl_is_writable(cptr)) {
568 cip->attr_val.attr.mode |= S_IWUSR|S_IWGRP;
569 cip->attr_custom.attr.mode |= S_IWUSR|S_IWGRP;
570 }
571
572 acnt = 0;
573 cip->attr_gen[acnt++] = &cip->attr_name.attr;
Mike Isely33213962006-06-25 20:04:40 -0300574 cip->attr_gen[acnt++] = &cip->attr_type.attr;
Mike Iselyd8554972006-06-26 20:58:46 -0300575 cip->attr_gen[acnt++] = &cip->attr_val.attr;
576 cip->attr_val.show = fp->show_val_norm;
577 cip->attr_val.store = fp->store_val_norm;
578 if (pvr2_ctrl_has_custom_symbols(cptr)) {
579 cip->attr_gen[acnt++] = &cip->attr_custom.attr;
580 cip->attr_custom.show = fp->show_val_custom;
581 cip->attr_custom.store = fp->store_val_custom;
582 }
583 switch (pvr2_ctrl_get_type(cptr)) {
584 case pvr2_ctl_enum:
585 // Control is an enumeration
586 cip->attr_gen[acnt++] = &cip->attr_enum.attr;
587 break;
588 case pvr2_ctl_int:
589 // Control is an integer
590 cip->attr_gen[acnt++] = &cip->attr_min.attr;
591 cip->attr_gen[acnt++] = &cip->attr_max.attr;
592 break;
593 case pvr2_ctl_bitmask:
594 // Control is an bitmask
595 cip->attr_gen[acnt++] = &cip->attr_bits.attr;
596 break;
597 default: break;
598 }
599
600 cnt = scnprintf(cip->name,sizeof(cip->name)-1,"ctl_%s",
601 pvr2_ctrl_get_name(cptr));
602 cip->name[cnt] = 0;
603 cip->grp.name = cip->name;
604 cip->grp.attrs = cip->attr_gen;
605
Mike Isely08d41802006-07-22 21:26:30 -0300606 ret = sysfs_create_group(&sfp->class_dev->kobj,&cip->grp);
607 if (ret) {
608 printk(KERN_WARNING "%s: sysfs_create_group error: %d\n",
609 __FUNCTION__, ret);
610 return;
611 }
612 cip->created_ok = !0;
Mike Iselyd8554972006-06-26 20:58:46 -0300613}
614
615#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
Trent Piephoc726b652007-10-08 19:05:28 -0300616static ssize_t debuginfo_show(struct device *, struct device_attribute *,
617 char *);
618static ssize_t debugcmd_show(struct device *, struct device_attribute *,
619 char *);
620static ssize_t debugcmd_store(struct device *, struct device_attribute *,
621 const char *, size_t count);
Mike Iselyd8554972006-06-26 20:58:46 -0300622
623static void pvr2_sysfs_add_debugifc(struct pvr2_sysfs *sfp)
624{
625 struct pvr2_sysfs_debugifc *dip;
Michael Krufky3117bee2006-07-19 13:23:38 -0300626 int ret;
627
Mike Iselyca545f72007-01-20 00:37:11 -0300628 dip = kzalloc(sizeof(*dip),GFP_KERNEL);
Mike Iselyd8554972006-06-26 20:58:46 -0300629 if (!dip) return;
Mike Iselyd8554972006-06-26 20:58:46 -0300630 dip->attr_debugcmd.attr.name = "debugcmd";
631 dip->attr_debugcmd.attr.mode = S_IRUGO|S_IWUSR|S_IWGRP;
632 dip->attr_debugcmd.show = debugcmd_show;
633 dip->attr_debugcmd.store = debugcmd_store;
Mike Iselyd8554972006-06-26 20:58:46 -0300634 dip->attr_debuginfo.attr.name = "debuginfo";
635 dip->attr_debuginfo.attr.mode = S_IRUGO;
636 dip->attr_debuginfo.show = debuginfo_show;
637 sfp->debugifc = dip;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300638 ret = device_create_file(sfp->class_dev,&dip->attr_debugcmd);
Mike Isely08d41802006-07-22 21:26:30 -0300639 if (ret < 0) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300640 printk(KERN_WARNING "%s: device_create_file error: %d\n",
Michael Krufky3117bee2006-07-19 13:23:38 -0300641 __FUNCTION__, ret);
Mike Isely08d41802006-07-22 21:26:30 -0300642 } else {
643 dip->debugcmd_created_ok = !0;
644 }
Kay Sievers54bd5b62007-10-08 16:26:13 -0300645 ret = device_create_file(sfp->class_dev,&dip->attr_debuginfo);
Mike Isely08d41802006-07-22 21:26:30 -0300646 if (ret < 0) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300647 printk(KERN_WARNING "%s: device_create_file error: %d\n",
Michael Krufky3117bee2006-07-19 13:23:38 -0300648 __FUNCTION__, ret);
Mike Isely08d41802006-07-22 21:26:30 -0300649 } else {
650 dip->debuginfo_created_ok = !0;
651 }
Mike Iselyd8554972006-06-26 20:58:46 -0300652}
653
654
655static void pvr2_sysfs_tear_down_debugifc(struct pvr2_sysfs *sfp)
656{
657 if (!sfp->debugifc) return;
Mike Isely08d41802006-07-22 21:26:30 -0300658 if (sfp->debugifc->debuginfo_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300659 device_remove_file(sfp->class_dev,
Mike Isely08d41802006-07-22 21:26:30 -0300660 &sfp->debugifc->attr_debuginfo);
661 }
662 if (sfp->debugifc->debugcmd_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300663 device_remove_file(sfp->class_dev,
Mike Isely08d41802006-07-22 21:26:30 -0300664 &sfp->debugifc->attr_debugcmd);
665 }
Mike Iselyd8554972006-06-26 20:58:46 -0300666 kfree(sfp->debugifc);
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300667 sfp->debugifc = NULL;
Mike Iselyd8554972006-06-26 20:58:46 -0300668}
669#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
670
671
672static void pvr2_sysfs_add_controls(struct pvr2_sysfs *sfp)
673{
674 unsigned int idx,cnt;
675 cnt = pvr2_hdw_get_ctrl_count(sfp->channel.hdw);
676 for (idx = 0; idx < cnt; idx++) {
677 pvr2_sysfs_add_control(sfp,idx);
678 }
679}
680
681
682static void pvr2_sysfs_tear_down_controls(struct pvr2_sysfs *sfp)
683{
684 struct pvr2_sysfs_ctl_item *cip1,*cip2;
685 for (cip1 = sfp->item_first; cip1; cip1 = cip2) {
686 cip2 = cip1->item_next;
Mike Isely08d41802006-07-22 21:26:30 -0300687 if (cip1->created_ok) {
688 sysfs_remove_group(&sfp->class_dev->kobj,&cip1->grp);
689 }
Mike Iselyd8554972006-06-26 20:58:46 -0300690 pvr2_sysfs_trace("Destroying pvr2_sysfs_ctl_item id=%p",cip1);
691 kfree(cip1);
692 }
693}
694
695
696static void pvr2_sysfs_class_release(struct class *class)
697{
698 struct pvr2_sysfs_class *clp;
699 clp = container_of(class,struct pvr2_sysfs_class,class);
700 pvr2_sysfs_trace("Destroying pvr2_sysfs_class id=%p",clp);
701 kfree(clp);
702}
703
704
Kay Sievers54bd5b62007-10-08 16:26:13 -0300705static void pvr2_sysfs_release(struct device *class_dev)
Mike Iselyd8554972006-06-26 20:58:46 -0300706{
707 pvr2_sysfs_trace("Releasing class_dev id=%p",class_dev);
708 kfree(class_dev);
709}
710
711
712static void class_dev_destroy(struct pvr2_sysfs *sfp)
713{
714 if (!sfp->class_dev) return;
715#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
716 pvr2_sysfs_tear_down_debugifc(sfp);
717#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
718 pvr2_sysfs_tear_down_controls(sfp);
Mike Isely78a47102007-11-26 01:58:20 -0300719 if (sfp->hdw_desc_created_ok) {
720 device_remove_file(sfp->class_dev,
721 &sfp->attr_hdw_desc);
722 }
723 if (sfp->hdw_name_created_ok) {
724 device_remove_file(sfp->class_dev,
725 &sfp->attr_hdw_name);
726 }
Mike Isely31a18542007-04-08 01:11:47 -0300727 if (sfp->bus_info_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300728 device_remove_file(sfp->class_dev,
Mike Isely31a18542007-04-08 01:11:47 -0300729 &sfp->attr_bus_info);
730 }
Mike Isely08d41802006-07-22 21:26:30 -0300731 if (sfp->v4l_minor_number_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300732 device_remove_file(sfp->class_dev,
Mike Isely08d41802006-07-22 21:26:30 -0300733 &sfp->attr_v4l_minor_number);
734 }
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300735 if (sfp->v4l_radio_minor_number_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300736 device_remove_file(sfp->class_dev,
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300737 &sfp->attr_v4l_radio_minor_number);
738 }
Mike Isely08d41802006-07-22 21:26:30 -0300739 if (sfp->unit_number_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300740 device_remove_file(sfp->class_dev,
Mike Isely08d41802006-07-22 21:26:30 -0300741 &sfp->attr_unit_number);
742 }
Mike Iselyd8554972006-06-26 20:58:46 -0300743 pvr2_sysfs_trace("Destroying class_dev id=%p",sfp->class_dev);
Kay Sievers54bd5b62007-10-08 16:26:13 -0300744 sfp->class_dev->driver_data = NULL;
745 device_unregister(sfp->class_dev);
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300746 sfp->class_dev = NULL;
Mike Iselyd8554972006-06-26 20:58:46 -0300747}
748
749
Kay Sievers54bd5b62007-10-08 16:26:13 -0300750static ssize_t v4l_minor_number_show(struct device *class_dev,
751 struct device_attribute *attr, char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300752{
753 struct pvr2_sysfs *sfp;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300754 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -0300755 if (!sfp) return -EINVAL;
756 return scnprintf(buf,PAGE_SIZE,"%d\n",
Mike Iselyfd5a75f2006-12-27 23:11:22 -0300757 pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw,
Mike Isely80793842006-12-27 23:12:28 -0300758 pvr2_v4l_type_video));
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300759}
760
761
Kay Sievers54bd5b62007-10-08 16:26:13 -0300762static ssize_t bus_info_show(struct device *class_dev,
763 struct device_attribute *attr, char *buf)
Mike Isely31a18542007-04-08 01:11:47 -0300764{
765 struct pvr2_sysfs *sfp;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300766 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Isely31a18542007-04-08 01:11:47 -0300767 if (!sfp) return -EINVAL;
768 return scnprintf(buf,PAGE_SIZE,"%s\n",
769 pvr2_hdw_get_bus_info(sfp->channel.hdw));
770}
771
772
Mike Isely78a47102007-11-26 01:58:20 -0300773static ssize_t hdw_name_show(struct device *class_dev,
774 struct device_attribute *attr, char *buf)
775{
776 struct pvr2_sysfs *sfp;
777 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
778 if (!sfp) return -EINVAL;
779 return scnprintf(buf,PAGE_SIZE,"%s\n",
780 pvr2_hdw_get_type(sfp->channel.hdw));
781}
782
783
784static ssize_t hdw_desc_show(struct device *class_dev,
785 struct device_attribute *attr, char *buf)
786{
787 struct pvr2_sysfs *sfp;
788 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
789 if (!sfp) return -EINVAL;
790 return scnprintf(buf,PAGE_SIZE,"%s\n",
791 pvr2_hdw_get_desc(sfp->channel.hdw));
792}
793
794
Kay Sievers54bd5b62007-10-08 16:26:13 -0300795static ssize_t v4l_radio_minor_number_show(struct device *class_dev,
796 struct device_attribute *attr,
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300797 char *buf)
798{
799 struct pvr2_sysfs *sfp;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300800 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300801 if (!sfp) return -EINVAL;
802 return scnprintf(buf,PAGE_SIZE,"%d\n",
Mike Iselyfd5a75f2006-12-27 23:11:22 -0300803 pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw,
Mike Isely80793842006-12-27 23:12:28 -0300804 pvr2_v4l_type_radio));
Mike Iselyd8554972006-06-26 20:58:46 -0300805}
806
807
Kay Sievers54bd5b62007-10-08 16:26:13 -0300808static ssize_t unit_number_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 scnprintf(buf,PAGE_SIZE,"%d\n",
815 pvr2_hdw_get_unit_number(sfp->channel.hdw));
816}
817
818
819static void class_dev_create(struct pvr2_sysfs *sfp,
820 struct pvr2_sysfs_class *class_ptr)
821{
822 struct usb_device *usb_dev;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300823 struct device *class_dev;
Michael Krufky3117bee2006-07-19 13:23:38 -0300824 int ret;
825
Mike Iselyd8554972006-06-26 20:58:46 -0300826 usb_dev = pvr2_hdw_get_dev(sfp->channel.hdw);
827 if (!usb_dev) return;
Mike Iselyca545f72007-01-20 00:37:11 -0300828 class_dev = kzalloc(sizeof(*class_dev),GFP_KERNEL);
Mike Iselyd8554972006-06-26 20:58:46 -0300829 if (!class_dev) return;
Mike Iselyd8554972006-06-26 20:58:46 -0300830
831 pvr2_sysfs_trace("Creating class_dev id=%p",class_dev);
832
833 class_dev->class = &class_ptr->class;
834 if (pvr2_hdw_get_sn(sfp->channel.hdw)) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300835 snprintf(class_dev->bus_id, BUS_ID_SIZE, "sn-%lu",
Mike Iselyd8554972006-06-26 20:58:46 -0300836 pvr2_hdw_get_sn(sfp->channel.hdw));
837 } else if (pvr2_hdw_get_unit_number(sfp->channel.hdw) >= 0) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300838 snprintf(class_dev->bus_id, BUS_ID_SIZE, "unit-%c",
Mike Iselyd8554972006-06-26 20:58:46 -0300839 pvr2_hdw_get_unit_number(sfp->channel.hdw) + 'a');
840 } else {
841 kfree(class_dev);
842 return;
843 }
844
Kay Sievers54bd5b62007-10-08 16:26:13 -0300845 class_dev->parent = &usb_dev->dev;
Mike Iselyd8554972006-06-26 20:58:46 -0300846
847 sfp->class_dev = class_dev;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300848 class_dev->driver_data = sfp;
849 ret = device_register(class_dev);
Michael Krufky3117bee2006-07-19 13:23:38 -0300850 if (ret) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300851 printk(KERN_ERR "%s: device_register failed\n",
Michael Krufky3117bee2006-07-19 13:23:38 -0300852 __FUNCTION__);
853 kfree(class_dev);
854 return;
855 }
Mike Iselyd8554972006-06-26 20:58:46 -0300856
Mike Iselyd8554972006-06-26 20:58:46 -0300857 sfp->attr_v4l_minor_number.attr.name = "v4l_minor_number";
858 sfp->attr_v4l_minor_number.attr.mode = S_IRUGO;
859 sfp->attr_v4l_minor_number.show = v4l_minor_number_show;
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300860 sfp->attr_v4l_minor_number.store = NULL;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300861 ret = device_create_file(sfp->class_dev,
Mike Isely08d41802006-07-22 21:26:30 -0300862 &sfp->attr_v4l_minor_number);
863 if (ret < 0) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300864 printk(KERN_WARNING "%s: device_create_file error: %d\n",
Michael Krufky3117bee2006-07-19 13:23:38 -0300865 __FUNCTION__, ret);
Mike Isely08d41802006-07-22 21:26:30 -0300866 } else {
867 sfp->v4l_minor_number_created_ok = !0;
868 }
Michael Krufky3117bee2006-07-19 13:23:38 -0300869
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300870 sfp->attr_v4l_radio_minor_number.attr.name = "v4l_radio_minor_number";
871 sfp->attr_v4l_radio_minor_number.attr.mode = S_IRUGO;
872 sfp->attr_v4l_radio_minor_number.show = v4l_radio_minor_number_show;
873 sfp->attr_v4l_radio_minor_number.store = NULL;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300874 ret = device_create_file(sfp->class_dev,
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300875 &sfp->attr_v4l_radio_minor_number);
876 if (ret < 0) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300877 printk(KERN_WARNING "%s: device_create_file error: %d\n",
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300878 __FUNCTION__, ret);
879 } else {
880 sfp->v4l_radio_minor_number_created_ok = !0;
881 }
882
Mike Iselyd8554972006-06-26 20:58:46 -0300883 sfp->attr_unit_number.attr.name = "unit_number";
884 sfp->attr_unit_number.attr.mode = S_IRUGO;
885 sfp->attr_unit_number.show = unit_number_show;
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300886 sfp->attr_unit_number.store = NULL;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300887 ret = device_create_file(sfp->class_dev,&sfp->attr_unit_number);
Mike Isely08d41802006-07-22 21:26:30 -0300888 if (ret < 0) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300889 printk(KERN_WARNING "%s: device_create_file error: %d\n",
Michael Krufky3117bee2006-07-19 13:23:38 -0300890 __FUNCTION__, ret);
Mike Isely08d41802006-07-22 21:26:30 -0300891 } else {
892 sfp->unit_number_created_ok = !0;
893 }
Mike Iselyd8554972006-06-26 20:58:46 -0300894
Mike Isely31a18542007-04-08 01:11:47 -0300895 sfp->attr_bus_info.attr.name = "bus_info_str";
896 sfp->attr_bus_info.attr.mode = S_IRUGO;
897 sfp->attr_bus_info.show = bus_info_show;
898 sfp->attr_bus_info.store = NULL;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300899 ret = device_create_file(sfp->class_dev,
Mike Isely31a18542007-04-08 01:11:47 -0300900 &sfp->attr_bus_info);
901 if (ret < 0) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300902 printk(KERN_WARNING "%s: device_create_file error: %d\n",
Mike Isely31a18542007-04-08 01:11:47 -0300903 __FUNCTION__, ret);
904 } else {
905 sfp->bus_info_created_ok = !0;
906 }
907
Mike Isely78a47102007-11-26 01:58:20 -0300908 sfp->attr_hdw_name.attr.name = "device_hardware_type";
909 sfp->attr_hdw_name.attr.mode = S_IRUGO;
910 sfp->attr_hdw_name.show = hdw_name_show;
911 sfp->attr_hdw_name.store = NULL;
912 ret = device_create_file(sfp->class_dev,
913 &sfp->attr_hdw_name);
914 if (ret < 0) {
915 printk(KERN_WARNING "%s: device_create_file error: %d\n",
916 __FUNCTION__, ret);
917 } else {
918 sfp->hdw_name_created_ok = !0;
919 }
920
921 sfp->attr_hdw_desc.attr.name = "device_hardware_description";
922 sfp->attr_hdw_desc.attr.mode = S_IRUGO;
923 sfp->attr_hdw_desc.show = hdw_desc_show;
924 sfp->attr_hdw_desc.store = NULL;
925 ret = device_create_file(sfp->class_dev,
926 &sfp->attr_hdw_desc);
927 if (ret < 0) {
928 printk(KERN_WARNING "%s: device_create_file error: %d\n",
929 __FUNCTION__, ret);
930 } else {
931 sfp->hdw_desc_created_ok = !0;
932 }
933
Mike Iselyd8554972006-06-26 20:58:46 -0300934 pvr2_sysfs_add_controls(sfp);
935#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
936 pvr2_sysfs_add_debugifc(sfp);
937#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
938}
939
940
941static void pvr2_sysfs_internal_check(struct pvr2_channel *chp)
942{
943 struct pvr2_sysfs *sfp;
944 sfp = container_of(chp,struct pvr2_sysfs,channel);
945 if (!sfp->channel.mc_head->disconnect_flag) return;
946 pvr2_trace(PVR2_TRACE_STRUCT,"Destroying pvr2_sysfs id=%p",sfp);
947 class_dev_destroy(sfp);
948 pvr2_channel_done(&sfp->channel);
949 kfree(sfp);
950}
951
952
953struct pvr2_sysfs *pvr2_sysfs_create(struct pvr2_context *mp,
954 struct pvr2_sysfs_class *class_ptr)
955{
956 struct pvr2_sysfs *sfp;
Mike Iselyca545f72007-01-20 00:37:11 -0300957 sfp = kzalloc(sizeof(*sfp),GFP_KERNEL);
Mike Iselyd8554972006-06-26 20:58:46 -0300958 if (!sfp) return sfp;
Mike Iselyd8554972006-06-26 20:58:46 -0300959 pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr2_sysfs id=%p",sfp);
960 pvr2_channel_init(&sfp->channel,mp);
961 sfp->channel.check_func = pvr2_sysfs_internal_check;
962
963 class_dev_create(sfp,class_ptr);
964 return sfp;
965}
966
967
Mike Iselyd8554972006-06-26 20:58:46 -0300968
969struct pvr2_sysfs_class *pvr2_sysfs_class_create(void)
970{
971 struct pvr2_sysfs_class *clp;
Mike Iselyca545f72007-01-20 00:37:11 -0300972 clp = kzalloc(sizeof(*clp),GFP_KERNEL);
Mike Iselyd8554972006-06-26 20:58:46 -0300973 if (!clp) return clp;
Mike Iselyd8554972006-06-26 20:58:46 -0300974 pvr2_sysfs_trace("Creating pvr2_sysfs_class id=%p",clp);
975 clp->class.name = "pvrusb2";
976 clp->class.class_release = pvr2_sysfs_class_release;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300977 clp->class.dev_release = pvr2_sysfs_release;
Mike Iselyd8554972006-06-26 20:58:46 -0300978 if (class_register(&clp->class)) {
979 pvr2_sysfs_trace(
980 "Registration failed for pvr2_sysfs_class id=%p",clp);
981 kfree(clp);
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300982 clp = NULL;
Mike Iselyd8554972006-06-26 20:58:46 -0300983 }
984 return clp;
985}
986
987
988void pvr2_sysfs_class_destroy(struct pvr2_sysfs_class *clp)
989{
990 class_unregister(&clp->class);
991}
992
993
994#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
Trent Piephoc726b652007-10-08 19:05:28 -0300995static ssize_t debuginfo_show(struct device *class_dev,
996 struct device_attribute *attr, char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300997{
998 struct pvr2_sysfs *sfp;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300999 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -03001000 if (!sfp) return -EINVAL;
1001 pvr2_hdw_trigger_module_log(sfp->channel.hdw);
1002 return pvr2_debugifc_print_info(sfp->channel.hdw,buf,PAGE_SIZE);
1003}
1004
1005
Trent Piephoc726b652007-10-08 19:05:28 -03001006static ssize_t debugcmd_show(struct device *class_dev,
1007 struct device_attribute *attr, char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -03001008{
1009 struct pvr2_sysfs *sfp;
Kay Sievers54bd5b62007-10-08 16:26:13 -03001010 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -03001011 if (!sfp) return -EINVAL;
1012 return pvr2_debugifc_print_status(sfp->channel.hdw,buf,PAGE_SIZE);
1013}
1014
1015
Kay Sievers54bd5b62007-10-08 16:26:13 -03001016static ssize_t debugcmd_store(struct device *class_dev,
Trent Piephoc726b652007-10-08 19:05:28 -03001017 struct device_attribute *attr,
Kay Sievers54bd5b62007-10-08 16:26:13 -03001018 const char *buf, size_t count)
Mike Iselyd8554972006-06-26 20:58:46 -03001019{
1020 struct pvr2_sysfs *sfp;
1021 int ret;
1022
Kay Sievers54bd5b62007-10-08 16:26:13 -03001023 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
Mike Iselyd8554972006-06-26 20:58:46 -03001024 if (!sfp) return -EINVAL;
1025
1026 ret = pvr2_debugifc_docmd(sfp->channel.hdw,buf,count);
1027 if (ret < 0) return ret;
1028 return count;
1029}
1030#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
1031
1032
1033/*
1034 Stuff for Emacs to see, in order to encourage consistent editing style:
1035 *** Local Variables: ***
1036 *** mode: c ***
1037 *** fill-column: 75 ***
1038 *** tab-width: 8 ***
1039 *** c-basic-offset: 8 ***
1040 *** End: ***
1041 */