blob: 7bc6d090358ee707173cbb332667a9a2d41f5077 [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 *
Mike Iselyd8554972006-06-26 20:58:46 -030015 */
16
Mike Iselyd8554972006-06-26 20:58:46 -030017#include <linux/string.h>
18#include <linux/slab.h>
Mike Iselyd8554972006-06-26 20:58:46 -030019#include "pvrusb2-sysfs.h"
20#include "pvrusb2-hdw.h"
21#include "pvrusb2-debug.h"
22#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
23#include "pvrusb2-debugifc.h"
24#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
25
26#define pvr2_sysfs_trace(...) pvr2_trace(PVR2_TRACE_SYSFS,__VA_ARGS__)
27
28struct pvr2_sysfs {
29 struct pvr2_channel channel;
Kay Sievers54bd5b62007-10-08 16:26:13 -030030 struct device *class_dev;
Mike Iselyd8554972006-06-26 20:58:46 -030031#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
32 struct pvr2_sysfs_debugifc *debugifc;
33#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
34 struct pvr2_sysfs_ctl_item *item_first;
35 struct pvr2_sysfs_ctl_item *item_last;
Kay Sievers54bd5b62007-10-08 16:26:13 -030036 struct device_attribute attr_v4l_minor_number;
37 struct device_attribute attr_v4l_radio_minor_number;
38 struct device_attribute attr_unit_number;
39 struct device_attribute attr_bus_info;
Mike Isely78a47102007-11-26 01:58:20 -030040 struct device_attribute attr_hdw_name;
41 struct device_attribute attr_hdw_desc;
Mike Isely08d41802006-07-22 21:26:30 -030042 int v4l_minor_number_created_ok;
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -030043 int v4l_radio_minor_number_created_ok;
Mike Isely08d41802006-07-22 21:26:30 -030044 int unit_number_created_ok;
Mike Isely31a18542007-04-08 01:11:47 -030045 int bus_info_created_ok;
Mike Isely78a47102007-11-26 01:58:20 -030046 int hdw_name_created_ok;
47 int hdw_desc_created_ok;
Mike Iselyd8554972006-06-26 20:58:46 -030048};
49
50#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
51struct pvr2_sysfs_debugifc {
Kay Sievers54bd5b62007-10-08 16:26:13 -030052 struct device_attribute attr_debugcmd;
53 struct device_attribute attr_debuginfo;
Mike Isely08d41802006-07-22 21:26:30 -030054 int debugcmd_created_ok;
55 int debuginfo_created_ok;
Mike Iselyd8554972006-06-26 20:58:46 -030056};
57#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
58
59struct pvr2_sysfs_ctl_item {
Kay Sievers54bd5b62007-10-08 16:26:13 -030060 struct device_attribute attr_name;
61 struct device_attribute attr_type;
62 struct device_attribute attr_min;
63 struct device_attribute attr_max;
Mike Isely0b7c2c92008-08-31 20:57:54 -030064 struct device_attribute attr_def;
Kay Sievers54bd5b62007-10-08 16:26:13 -030065 struct device_attribute attr_enum;
66 struct device_attribute attr_bits;
67 struct device_attribute attr_val;
68 struct device_attribute attr_custom;
Mike Iselyd8554972006-06-26 20:58:46 -030069 struct pvr2_ctrl *cptr;
Mike Iselyf90fe7a2008-05-26 06:00:47 -030070 int ctl_id;
Mike Iselyd8554972006-06-26 20:58:46 -030071 struct pvr2_sysfs *chptr;
72 struct pvr2_sysfs_ctl_item *item_next;
Mike Isely7a6ac342010-05-15 00:28:44 -030073 struct attribute *attr_gen[8];
Mike Iselyd8554972006-06-26 20:58:46 -030074 struct attribute_group grp;
Mike Isely08d41802006-07-22 21:26:30 -030075 int created_ok;
Mike Iselyd8554972006-06-26 20:58:46 -030076 char name[80];
77};
78
79struct pvr2_sysfs_class {
80 struct class class;
81};
82
Mike Iselyf90fe7a2008-05-26 06:00:47 -030083static ssize_t show_name(struct device *class_dev,
84 struct device_attribute *attr,
85 char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -030086{
Mike Iselyf90fe7a2008-05-26 06:00:47 -030087 struct pvr2_sysfs_ctl_item *cip;
Mike Iselyd8554972006-06-26 20:58:46 -030088 const char *name;
Mike Iselyf90fe7a2008-05-26 06:00:47 -030089 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_name);
90 name = pvr2_ctrl_get_desc(cip->cptr);
91 pvr2_sysfs_trace("pvr2_sysfs(%p) show_name(cid=%d) is %s",
92 cip->chptr, cip->ctl_id, name);
Mike Iselyd8554972006-06-26 20:58:46 -030093 if (!name) return -EINVAL;
Mike Iselyf90fe7a2008-05-26 06:00:47 -030094 return scnprintf(buf, PAGE_SIZE, "%s\n", name);
Mike Iselyd8554972006-06-26 20:58:46 -030095}
96
Mike Iselyf90fe7a2008-05-26 06:00:47 -030097static ssize_t show_type(struct device *class_dev,
98 struct device_attribute *attr,
99 char *buf)
Mike Isely33213962006-06-25 20:04:40 -0300100{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300101 struct pvr2_sysfs_ctl_item *cip;
Mike Isely33213962006-06-25 20:04:40 -0300102 const char *name;
103 enum pvr2_ctl_type tp;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300104 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_type);
105 tp = pvr2_ctrl_get_type(cip->cptr);
Mike Isely33213962006-06-25 20:04:40 -0300106 switch (tp) {
107 case pvr2_ctl_int: name = "integer"; break;
108 case pvr2_ctl_enum: name = "enum"; break;
109 case pvr2_ctl_bitmask: name = "bitmask"; break;
110 case pvr2_ctl_bool: name = "boolean"; break;
111 default: name = "?"; break;
112 }
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300113 pvr2_sysfs_trace("pvr2_sysfs(%p) show_type(cid=%d) is %s",
114 cip->chptr, cip->ctl_id, name);
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300115 return scnprintf(buf, PAGE_SIZE, "%s\n", name);
Mike Isely33213962006-06-25 20:04:40 -0300116}
117
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300118static ssize_t show_min(struct device *class_dev,
119 struct device_attribute *attr,
120 char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300121{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300122 struct pvr2_sysfs_ctl_item *cip;
Mike Iselyd8554972006-06-26 20:58:46 -0300123 long val;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300124 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_min);
125 val = pvr2_ctrl_get_min(cip->cptr);
126 pvr2_sysfs_trace("pvr2_sysfs(%p) show_min(cid=%d) is %ld",
127 cip->chptr, cip->ctl_id, val);
128 return scnprintf(buf, PAGE_SIZE, "%ld\n", val);
Mike Iselyd8554972006-06-26 20:58:46 -0300129}
130
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300131static ssize_t show_max(struct device *class_dev,
132 struct device_attribute *attr,
133 char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300134{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300135 struct pvr2_sysfs_ctl_item *cip;
Mike Iselyd8554972006-06-26 20:58:46 -0300136 long val;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300137 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_max);
138 val = pvr2_ctrl_get_max(cip->cptr);
139 pvr2_sysfs_trace("pvr2_sysfs(%p) show_max(cid=%d) is %ld",
140 cip->chptr, cip->ctl_id, val);
141 return scnprintf(buf, PAGE_SIZE, "%ld\n", val);
Mike Iselyd8554972006-06-26 20:58:46 -0300142}
143
Mike Isely0b7c2c92008-08-31 20:57:54 -0300144static ssize_t show_def(struct device *class_dev,
145 struct device_attribute *attr,
146 char *buf)
147{
148 struct pvr2_sysfs_ctl_item *cip;
149 int val;
150 int ret;
Mike Isely7bf56f92009-04-01 01:51:53 -0300151 unsigned int cnt = 0;
Mike Isely0b7c2c92008-08-31 20:57:54 -0300152 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_def);
153 ret = pvr2_ctrl_get_def(cip->cptr, &val);
Mike Isely7bf56f92009-04-01 01:51:53 -0300154 if (ret < 0) return ret;
155 ret = pvr2_ctrl_value_to_sym(cip->cptr, ~0, val,
156 buf, PAGE_SIZE - 1, &cnt);
157 pvr2_sysfs_trace("pvr2_sysfs(%p) show_def(cid=%d) is %.*s (%d)",
158 cip->chptr, cip->ctl_id, cnt, buf, val);
159 buf[cnt] = '\n';
160 return cnt + 1;
Mike Isely0b7c2c92008-08-31 20:57:54 -0300161}
162
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300163static ssize_t show_val_norm(struct device *class_dev,
164 struct device_attribute *attr,
165 char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300166{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300167 struct pvr2_sysfs_ctl_item *cip;
168 int val;
169 int ret;
Mike Iselyd8554972006-06-26 20:58:46 -0300170 unsigned int cnt = 0;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300171 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_val);
172 ret = pvr2_ctrl_get_value(cip->cptr, &val);
Mike Iselyd8554972006-06-26 20:58:46 -0300173 if (ret < 0) return ret;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300174 ret = pvr2_ctrl_value_to_sym(cip->cptr, ~0, val,
175 buf, PAGE_SIZE - 1, &cnt);
Mike Iselyd8554972006-06-26 20:58:46 -0300176 pvr2_sysfs_trace("pvr2_sysfs(%p) show_val_norm(cid=%d) is %.*s (%d)",
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300177 cip->chptr, cip->ctl_id, cnt, buf, val);
Mike Iselyd8554972006-06-26 20:58:46 -0300178 buf[cnt] = '\n';
179 return cnt+1;
180}
181
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300182static ssize_t show_val_custom(struct device *class_dev,
183 struct device_attribute *attr,
184 char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300185{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300186 struct pvr2_sysfs_ctl_item *cip;
187 int val;
188 int ret;
Mike Iselyd8554972006-06-26 20:58:46 -0300189 unsigned int cnt = 0;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300190 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_custom);
191 ret = pvr2_ctrl_get_value(cip->cptr, &val);
Mike Iselyd8554972006-06-26 20:58:46 -0300192 if (ret < 0) return ret;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300193 ret = pvr2_ctrl_custom_value_to_sym(cip->cptr, ~0, val,
194 buf, PAGE_SIZE - 1, &cnt);
Mike Iselyd8554972006-06-26 20:58:46 -0300195 pvr2_sysfs_trace("pvr2_sysfs(%p) show_val_custom(cid=%d) is %.*s (%d)",
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300196 cip->chptr, cip->ctl_id, cnt, buf, val);
Mike Iselyd8554972006-06-26 20:58:46 -0300197 buf[cnt] = '\n';
198 return cnt+1;
199}
200
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300201static ssize_t show_enum(struct device *class_dev,
202 struct device_attribute *attr,
203 char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300204{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300205 struct pvr2_sysfs_ctl_item *cip;
Mike Iselyd8554972006-06-26 20:58:46 -0300206 long val;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300207 unsigned int bcnt, ccnt, ecnt;
208 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_enum);
209 ecnt = pvr2_ctrl_get_cnt(cip->cptr);
Mike Iselyd8554972006-06-26 20:58:46 -0300210 bcnt = 0;
211 for (val = 0; val < ecnt; val++) {
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300212 pvr2_ctrl_get_valname(cip->cptr, val, buf + bcnt,
213 PAGE_SIZE - bcnt, &ccnt);
Mike Isely45886772006-06-25 20:04:13 -0300214 if (!ccnt) continue;
Mike Iselyd8554972006-06-26 20:58:46 -0300215 bcnt += ccnt;
216 if (bcnt >= PAGE_SIZE) break;
217 buf[bcnt] = '\n';
218 bcnt++;
219 }
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300220 pvr2_sysfs_trace("pvr2_sysfs(%p) show_enum(cid=%d)",
221 cip->chptr, cip->ctl_id);
Mike Iselyd8554972006-06-26 20:58:46 -0300222 return bcnt;
223}
224
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300225static ssize_t show_bits(struct device *class_dev,
226 struct device_attribute *attr,
227 char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300228{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300229 struct pvr2_sysfs_ctl_item *cip;
230 int valid_bits, msk;
231 unsigned int bcnt, ccnt;
232 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_bits);
233 valid_bits = pvr2_ctrl_get_mask(cip->cptr);
Mike Iselyd8554972006-06-26 20:58:46 -0300234 bcnt = 0;
235 for (msk = 1; valid_bits; msk <<= 1) {
236 if (!(msk & valid_bits)) continue;
237 valid_bits &= ~msk;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300238 pvr2_ctrl_get_valname(cip->cptr, msk, buf + bcnt,
239 PAGE_SIZE - bcnt, &ccnt);
Mike Iselyd8554972006-06-26 20:58:46 -0300240 bcnt += ccnt;
241 if (bcnt >= PAGE_SIZE) break;
242 buf[bcnt] = '\n';
243 bcnt++;
244 }
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300245 pvr2_sysfs_trace("pvr2_sysfs(%p) show_bits(cid=%d)",
246 cip->chptr, cip->ctl_id);
Mike Iselyd8554972006-06-26 20:58:46 -0300247 return bcnt;
248}
249
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300250static int store_val_any(struct pvr2_sysfs_ctl_item *cip, int customfl,
Mike Iselyd8554972006-06-26 20:58:46 -0300251 const char *buf,unsigned int count)
252{
Mike Iselyd8554972006-06-26 20:58:46 -0300253 int ret;
254 int mask,val;
Mike Iselyd8554972006-06-26 20:58:46 -0300255 if (customfl) {
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300256 ret = pvr2_ctrl_custom_sym_to_value(cip->cptr, buf, count,
257 &mask, &val);
Mike Iselyd8554972006-06-26 20:58:46 -0300258 } else {
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300259 ret = pvr2_ctrl_sym_to_value(cip->cptr, buf, count,
260 &mask, &val);
Mike Iselyd8554972006-06-26 20:58:46 -0300261 }
262 if (ret < 0) return ret;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300263 ret = pvr2_ctrl_set_mask_value(cip->cptr, mask, val);
264 pvr2_hdw_commit_ctl(cip->chptr->channel.hdw);
Mike Iselyd8554972006-06-26 20:58:46 -0300265 return ret;
266}
267
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300268static ssize_t store_val_norm(struct device *class_dev,
269 struct device_attribute *attr,
270 const char *buf, size_t count)
Mike Iselyd8554972006-06-26 20:58:46 -0300271{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300272 struct pvr2_sysfs_ctl_item *cip;
Mike Iselyd8554972006-06-26 20:58:46 -0300273 int ret;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300274 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_val);
Mike Iselybedbbf82008-04-22 14:45:38 -0300275 pvr2_sysfs_trace("pvr2_sysfs(%p) store_val_norm(cid=%d) \"%.*s\"",
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300276 cip->chptr, cip->ctl_id, (int)count, buf);
277 ret = store_val_any(cip, 0, buf, count);
Mike Iselyd8554972006-06-26 20:58:46 -0300278 if (!ret) ret = count;
279 return ret;
280}
281
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300282static ssize_t store_val_custom(struct device *class_dev,
283 struct device_attribute *attr,
284 const char *buf, size_t count)
Mike Iselyd8554972006-06-26 20:58:46 -0300285{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300286 struct pvr2_sysfs_ctl_item *cip;
Mike Iselyd8554972006-06-26 20:58:46 -0300287 int ret;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300288 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_custom);
Mike Iselybedbbf82008-04-22 14:45:38 -0300289 pvr2_sysfs_trace("pvr2_sysfs(%p) store_val_custom(cid=%d) \"%.*s\"",
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300290 cip->chptr, cip->ctl_id, (int)count, buf);
291 ret = store_val_any(cip, 1, buf, count);
Mike Iselyd8554972006-06-26 20:58:46 -0300292 if (!ret) ret = count;
293 return ret;
294}
295
Mike Iselyd8554972006-06-26 20:58:46 -0300296static void pvr2_sysfs_add_control(struct pvr2_sysfs *sfp,int ctl_id)
297{
298 struct pvr2_sysfs_ctl_item *cip;
Mike Iselyd8554972006-06-26 20:58:46 -0300299 struct pvr2_ctrl *cptr;
300 unsigned int cnt,acnt;
Mike Isely08d41802006-07-22 21:26:30 -0300301 int ret;
Mike Iselyd8554972006-06-26 20:58:46 -0300302
Mike Iselyd8554972006-06-26 20:58:46 -0300303 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,ctl_id);
304 if (!cptr) return;
305
Mike Iselyca545f72007-01-20 00:37:11 -0300306 cip = kzalloc(sizeof(*cip),GFP_KERNEL);
Mike Iselyd8554972006-06-26 20:58:46 -0300307 if (!cip) return;
Mike Iselyd8554972006-06-26 20:58:46 -0300308 pvr2_sysfs_trace("Creating pvr2_sysfs_ctl_item id=%p",cip);
309
310 cip->cptr = cptr;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300311 cip->ctl_id = ctl_id;
Mike Iselyd8554972006-06-26 20:58:46 -0300312
313 cip->chptr = sfp;
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300314 cip->item_next = NULL;
Mike Iselyd8554972006-06-26 20:58:46 -0300315 if (sfp->item_last) {
316 sfp->item_last->item_next = cip;
317 } else {
318 sfp->item_first = cip;
319 }
320 sfp->item_last = cip;
321
Mike Isely19a0a292011-02-13 17:57:19 -0300322 sysfs_attr_init(&cip->attr_name.attr);
Mike Iselyd8554972006-06-26 20:58:46 -0300323 cip->attr_name.attr.name = "name";
324 cip->attr_name.attr.mode = S_IRUGO;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300325 cip->attr_name.show = show_name;
Mike Iselyd8554972006-06-26 20:58:46 -0300326
Mike Isely19a0a292011-02-13 17:57:19 -0300327 sysfs_attr_init(&cip->attr_type.attr);
Mike Isely33213962006-06-25 20:04:40 -0300328 cip->attr_type.attr.name = "type";
329 cip->attr_type.attr.mode = S_IRUGO;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300330 cip->attr_type.show = show_type;
Mike Isely33213962006-06-25 20:04:40 -0300331
Mike Isely19a0a292011-02-13 17:57:19 -0300332 sysfs_attr_init(&cip->attr_min.attr);
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 Isely19a0a292011-02-13 17:57:19 -0300337 sysfs_attr_init(&cip->attr_max.attr);
Mike Iselyd8554972006-06-26 20:58:46 -0300338 cip->attr_max.attr.name = "max_val";
339 cip->attr_max.attr.mode = S_IRUGO;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300340 cip->attr_max.show = show_max;
Mike Iselyd8554972006-06-26 20:58:46 -0300341
Mike Isely19a0a292011-02-13 17:57:19 -0300342 sysfs_attr_init(&cip->attr_def.attr);
Mike Isely0b7c2c92008-08-31 20:57:54 -0300343 cip->attr_def.attr.name = "def_val";
344 cip->attr_def.attr.mode = S_IRUGO;
345 cip->attr_def.show = show_def;
346
Mike Isely19a0a292011-02-13 17:57:19 -0300347 sysfs_attr_init(&cip->attr_val.attr);
Mike Iselyd8554972006-06-26 20:58:46 -0300348 cip->attr_val.attr.name = "cur_val";
349 cip->attr_val.attr.mode = S_IRUGO;
350
Mike Isely19a0a292011-02-13 17:57:19 -0300351 sysfs_attr_init(&cip->attr_custom.attr);
Mike Iselyd8554972006-06-26 20:58:46 -0300352 cip->attr_custom.attr.name = "custom_val";
353 cip->attr_custom.attr.mode = S_IRUGO;
354
Mike Isely19a0a292011-02-13 17:57:19 -0300355 sysfs_attr_init(&cip->attr_enum.attr);
Mike Iselyd8554972006-06-26 20:58:46 -0300356 cip->attr_enum.attr.name = "enum_val";
357 cip->attr_enum.attr.mode = S_IRUGO;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300358 cip->attr_enum.show = show_enum;
Mike Iselyd8554972006-06-26 20:58:46 -0300359
Mike Isely19a0a292011-02-13 17:57:19 -0300360 sysfs_attr_init(&cip->attr_bits.attr);
Mike Iselyd8554972006-06-26 20:58:46 -0300361 cip->attr_bits.attr.name = "bit_val";
362 cip->attr_bits.attr.mode = S_IRUGO;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300363 cip->attr_bits.show = show_bits;
Mike Iselyd8554972006-06-26 20:58:46 -0300364
365 if (pvr2_ctrl_is_writable(cptr)) {
366 cip->attr_val.attr.mode |= S_IWUSR|S_IWGRP;
367 cip->attr_custom.attr.mode |= S_IWUSR|S_IWGRP;
368 }
369
370 acnt = 0;
371 cip->attr_gen[acnt++] = &cip->attr_name.attr;
Mike Isely33213962006-06-25 20:04:40 -0300372 cip->attr_gen[acnt++] = &cip->attr_type.attr;
Mike Iselyd8554972006-06-26 20:58:46 -0300373 cip->attr_gen[acnt++] = &cip->attr_val.attr;
Mike Isely0b7c2c92008-08-31 20:57:54 -0300374 cip->attr_gen[acnt++] = &cip->attr_def.attr;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300375 cip->attr_val.show = show_val_norm;
376 cip->attr_val.store = store_val_norm;
Mike Iselyd8554972006-06-26 20:58:46 -0300377 if (pvr2_ctrl_has_custom_symbols(cptr)) {
378 cip->attr_gen[acnt++] = &cip->attr_custom.attr;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300379 cip->attr_custom.show = show_val_custom;
380 cip->attr_custom.store = store_val_custom;
Mike Iselyd8554972006-06-26 20:58:46 -0300381 }
382 switch (pvr2_ctrl_get_type(cptr)) {
383 case pvr2_ctl_enum:
384 // Control is an enumeration
385 cip->attr_gen[acnt++] = &cip->attr_enum.attr;
386 break;
387 case pvr2_ctl_int:
388 // Control is an integer
389 cip->attr_gen[acnt++] = &cip->attr_min.attr;
390 cip->attr_gen[acnt++] = &cip->attr_max.attr;
391 break;
392 case pvr2_ctl_bitmask:
393 // Control is an bitmask
394 cip->attr_gen[acnt++] = &cip->attr_bits.attr;
395 break;
396 default: break;
397 }
398
399 cnt = scnprintf(cip->name,sizeof(cip->name)-1,"ctl_%s",
400 pvr2_ctrl_get_name(cptr));
401 cip->name[cnt] = 0;
402 cip->grp.name = cip->name;
403 cip->grp.attrs = cip->attr_gen;
404
Mike Isely08d41802006-07-22 21:26:30 -0300405 ret = sysfs_create_group(&sfp->class_dev->kobj,&cip->grp);
406 if (ret) {
Mike Isely49844c22008-04-09 05:44:57 -0300407 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
408 "sysfs_create_group error: %d",
409 ret);
Mike Isely08d41802006-07-22 21:26:30 -0300410 return;
411 }
412 cip->created_ok = !0;
Mike Iselyd8554972006-06-26 20:58:46 -0300413}
414
415#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
Trent Piephoc726b652007-10-08 19:05:28 -0300416static ssize_t debuginfo_show(struct device *, struct device_attribute *,
417 char *);
418static ssize_t debugcmd_show(struct device *, struct device_attribute *,
419 char *);
420static ssize_t debugcmd_store(struct device *, struct device_attribute *,
421 const char *, size_t count);
Mike Iselyd8554972006-06-26 20:58:46 -0300422
423static void pvr2_sysfs_add_debugifc(struct pvr2_sysfs *sfp)
424{
425 struct pvr2_sysfs_debugifc *dip;
Michael Krufky3117bee2006-07-19 13:23:38 -0300426 int ret;
427
Mike Iselyca545f72007-01-20 00:37:11 -0300428 dip = kzalloc(sizeof(*dip),GFP_KERNEL);
Mike Iselyd8554972006-06-26 20:58:46 -0300429 if (!dip) return;
Wolfram Sang12765512010-04-06 14:34:52 -0700430 sysfs_attr_init(&dip->attr_debugcmd.attr);
Mike Iselyd8554972006-06-26 20:58:46 -0300431 dip->attr_debugcmd.attr.name = "debugcmd";
432 dip->attr_debugcmd.attr.mode = S_IRUGO|S_IWUSR|S_IWGRP;
433 dip->attr_debugcmd.show = debugcmd_show;
434 dip->attr_debugcmd.store = debugcmd_store;
Wolfram Sang12765512010-04-06 14:34:52 -0700435 sysfs_attr_init(&dip->attr_debuginfo.attr);
Mike Iselyd8554972006-06-26 20:58:46 -0300436 dip->attr_debuginfo.attr.name = "debuginfo";
437 dip->attr_debuginfo.attr.mode = S_IRUGO;
438 dip->attr_debuginfo.show = debuginfo_show;
439 sfp->debugifc = dip;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300440 ret = device_create_file(sfp->class_dev,&dip->attr_debugcmd);
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->debugcmd_created_ok = !0;
447 }
Kay Sievers54bd5b62007-10-08 16:26:13 -0300448 ret = device_create_file(sfp->class_dev,&dip->attr_debuginfo);
Mike Isely08d41802006-07-22 21:26:30 -0300449 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300450 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
451 "device_create_file error: %d",
452 ret);
Mike Isely08d41802006-07-22 21:26:30 -0300453 } else {
454 dip->debuginfo_created_ok = !0;
455 }
Mike Iselyd8554972006-06-26 20:58:46 -0300456}
457
458
459static void pvr2_sysfs_tear_down_debugifc(struct pvr2_sysfs *sfp)
460{
461 if (!sfp->debugifc) return;
Mike Isely08d41802006-07-22 21:26:30 -0300462 if (sfp->debugifc->debuginfo_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300463 device_remove_file(sfp->class_dev,
Mike Isely08d41802006-07-22 21:26:30 -0300464 &sfp->debugifc->attr_debuginfo);
465 }
466 if (sfp->debugifc->debugcmd_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300467 device_remove_file(sfp->class_dev,
Mike Isely08d41802006-07-22 21:26:30 -0300468 &sfp->debugifc->attr_debugcmd);
469 }
Mike Iselyd8554972006-06-26 20:58:46 -0300470 kfree(sfp->debugifc);
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300471 sfp->debugifc = NULL;
Mike Iselyd8554972006-06-26 20:58:46 -0300472}
473#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
474
475
476static void pvr2_sysfs_add_controls(struct pvr2_sysfs *sfp)
477{
478 unsigned int idx,cnt;
479 cnt = pvr2_hdw_get_ctrl_count(sfp->channel.hdw);
480 for (idx = 0; idx < cnt; idx++) {
481 pvr2_sysfs_add_control(sfp,idx);
482 }
483}
484
485
486static void pvr2_sysfs_tear_down_controls(struct pvr2_sysfs *sfp)
487{
488 struct pvr2_sysfs_ctl_item *cip1,*cip2;
489 for (cip1 = sfp->item_first; cip1; cip1 = cip2) {
490 cip2 = cip1->item_next;
Mike Isely08d41802006-07-22 21:26:30 -0300491 if (cip1->created_ok) {
492 sysfs_remove_group(&sfp->class_dev->kobj,&cip1->grp);
493 }
Mike Iselyd8554972006-06-26 20:58:46 -0300494 pvr2_sysfs_trace("Destroying pvr2_sysfs_ctl_item id=%p",cip1);
495 kfree(cip1);
496 }
497}
498
499
500static void pvr2_sysfs_class_release(struct class *class)
501{
502 struct pvr2_sysfs_class *clp;
503 clp = container_of(class,struct pvr2_sysfs_class,class);
504 pvr2_sysfs_trace("Destroying pvr2_sysfs_class id=%p",clp);
505 kfree(clp);
506}
507
508
Kay Sievers54bd5b62007-10-08 16:26:13 -0300509static void pvr2_sysfs_release(struct device *class_dev)
Mike Iselyd8554972006-06-26 20:58:46 -0300510{
511 pvr2_sysfs_trace("Releasing class_dev id=%p",class_dev);
512 kfree(class_dev);
513}
514
515
516static void class_dev_destroy(struct pvr2_sysfs *sfp)
517{
Mike Isely28c4a5e2010-05-15 00:23:46 -0300518 struct device *dev;
Mike Iselyd8554972006-06-26 20:58:46 -0300519 if (!sfp->class_dev) return;
520#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
521 pvr2_sysfs_tear_down_debugifc(sfp);
522#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
523 pvr2_sysfs_tear_down_controls(sfp);
Mike Isely78a47102007-11-26 01:58:20 -0300524 if (sfp->hdw_desc_created_ok) {
525 device_remove_file(sfp->class_dev,
526 &sfp->attr_hdw_desc);
527 }
528 if (sfp->hdw_name_created_ok) {
529 device_remove_file(sfp->class_dev,
530 &sfp->attr_hdw_name);
531 }
Mike Isely31a18542007-04-08 01:11:47 -0300532 if (sfp->bus_info_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300533 device_remove_file(sfp->class_dev,
Mike Isely31a18542007-04-08 01:11:47 -0300534 &sfp->attr_bus_info);
535 }
Mike Isely08d41802006-07-22 21:26:30 -0300536 if (sfp->v4l_minor_number_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300537 device_remove_file(sfp->class_dev,
Mike Isely08d41802006-07-22 21:26:30 -0300538 &sfp->attr_v4l_minor_number);
539 }
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300540 if (sfp->v4l_radio_minor_number_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300541 device_remove_file(sfp->class_dev,
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300542 &sfp->attr_v4l_radio_minor_number);
543 }
Mike Isely08d41802006-07-22 21:26:30 -0300544 if (sfp->unit_number_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300545 device_remove_file(sfp->class_dev,
Mike Isely08d41802006-07-22 21:26:30 -0300546 &sfp->attr_unit_number);
547 }
Mike Iselyd8554972006-06-26 20:58:46 -0300548 pvr2_sysfs_trace("Destroying class_dev id=%p",sfp->class_dev);
Greg Kroah-Hartman79510cd2009-04-30 14:43:31 -0700549 dev_set_drvdata(sfp->class_dev, NULL);
Mike Isely28c4a5e2010-05-15 00:23:46 -0300550 dev = sfp->class_dev->parent;
551 sfp->class_dev->parent = NULL;
552 put_device(dev);
Kay Sievers54bd5b62007-10-08 16:26:13 -0300553 device_unregister(sfp->class_dev);
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300554 sfp->class_dev = NULL;
Mike Iselyd8554972006-06-26 20:58:46 -0300555}
556
557
Kay Sievers54bd5b62007-10-08 16:26:13 -0300558static ssize_t v4l_minor_number_show(struct device *class_dev,
559 struct device_attribute *attr, char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300560{
561 struct pvr2_sysfs *sfp;
Greg Kroah-Hartman79510cd2009-04-30 14:43:31 -0700562 sfp = dev_get_drvdata(class_dev);
Mike Iselyd8554972006-06-26 20:58:46 -0300563 if (!sfp) return -EINVAL;
564 return scnprintf(buf,PAGE_SIZE,"%d\n",
Mike Iselyfd5a75f2006-12-27 23:11:22 -0300565 pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw,
Mike Isely80793842006-12-27 23:12:28 -0300566 pvr2_v4l_type_video));
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300567}
568
569
Kay Sievers54bd5b62007-10-08 16:26:13 -0300570static ssize_t bus_info_show(struct device *class_dev,
571 struct device_attribute *attr, char *buf)
Mike Isely31a18542007-04-08 01:11:47 -0300572{
573 struct pvr2_sysfs *sfp;
Greg Kroah-Hartman79510cd2009-04-30 14:43:31 -0700574 sfp = dev_get_drvdata(class_dev);
Mike Isely31a18542007-04-08 01:11:47 -0300575 if (!sfp) return -EINVAL;
576 return scnprintf(buf,PAGE_SIZE,"%s\n",
577 pvr2_hdw_get_bus_info(sfp->channel.hdw));
578}
579
580
Mike Isely78a47102007-11-26 01:58:20 -0300581static ssize_t hdw_name_show(struct device *class_dev,
582 struct device_attribute *attr, char *buf)
583{
584 struct pvr2_sysfs *sfp;
Greg Kroah-Hartman79510cd2009-04-30 14:43:31 -0700585 sfp = dev_get_drvdata(class_dev);
Mike Isely78a47102007-11-26 01:58:20 -0300586 if (!sfp) return -EINVAL;
587 return scnprintf(buf,PAGE_SIZE,"%s\n",
588 pvr2_hdw_get_type(sfp->channel.hdw));
589}
590
591
592static ssize_t hdw_desc_show(struct device *class_dev,
593 struct device_attribute *attr, char *buf)
594{
595 struct pvr2_sysfs *sfp;
Greg Kroah-Hartman79510cd2009-04-30 14:43:31 -0700596 sfp = dev_get_drvdata(class_dev);
Mike Isely78a47102007-11-26 01:58:20 -0300597 if (!sfp) return -EINVAL;
598 return scnprintf(buf,PAGE_SIZE,"%s\n",
599 pvr2_hdw_get_desc(sfp->channel.hdw));
600}
601
602
Kay Sievers54bd5b62007-10-08 16:26:13 -0300603static ssize_t v4l_radio_minor_number_show(struct device *class_dev,
604 struct device_attribute *attr,
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300605 char *buf)
606{
607 struct pvr2_sysfs *sfp;
Greg Kroah-Hartman79510cd2009-04-30 14:43:31 -0700608 sfp = dev_get_drvdata(class_dev);
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300609 if (!sfp) return -EINVAL;
610 return scnprintf(buf,PAGE_SIZE,"%d\n",
Mike Iselyfd5a75f2006-12-27 23:11:22 -0300611 pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw,
Mike Isely80793842006-12-27 23:12:28 -0300612 pvr2_v4l_type_radio));
Mike Iselyd8554972006-06-26 20:58:46 -0300613}
614
615
Kay Sievers54bd5b62007-10-08 16:26:13 -0300616static ssize_t unit_number_show(struct device *class_dev,
617 struct device_attribute *attr, char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300618{
619 struct pvr2_sysfs *sfp;
Greg Kroah-Hartman79510cd2009-04-30 14:43:31 -0700620 sfp = dev_get_drvdata(class_dev);
Mike Iselyd8554972006-06-26 20:58:46 -0300621 if (!sfp) return -EINVAL;
622 return scnprintf(buf,PAGE_SIZE,"%d\n",
623 pvr2_hdw_get_unit_number(sfp->channel.hdw));
624}
625
626
627static void class_dev_create(struct pvr2_sysfs *sfp,
628 struct pvr2_sysfs_class *class_ptr)
629{
630 struct usb_device *usb_dev;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300631 struct device *class_dev;
Michael Krufky3117bee2006-07-19 13:23:38 -0300632 int ret;
633
Mike Iselyd8554972006-06-26 20:58:46 -0300634 usb_dev = pvr2_hdw_get_dev(sfp->channel.hdw);
635 if (!usb_dev) return;
Mike Iselyca545f72007-01-20 00:37:11 -0300636 class_dev = kzalloc(sizeof(*class_dev),GFP_KERNEL);
Mike Iselyd8554972006-06-26 20:58:46 -0300637 if (!class_dev) return;
Mike Iselyd8554972006-06-26 20:58:46 -0300638
639 pvr2_sysfs_trace("Creating class_dev id=%p",class_dev);
640
641 class_dev->class = &class_ptr->class;
Mike Isely28c4a5e2010-05-15 00:23:46 -0300642
Mike Isely730e92c2009-01-14 04:24:20 -0300643 dev_set_name(class_dev, "%s",
644 pvr2_hdw_get_device_identifier(sfp->channel.hdw));
Mike Iselyd8554972006-06-26 20:58:46 -0300645
Mike Isely28c4a5e2010-05-15 00:23:46 -0300646 class_dev->parent = get_device(&usb_dev->dev);
Mike Iselyd8554972006-06-26 20:58:46 -0300647
648 sfp->class_dev = class_dev;
Greg Kroah-Hartman79510cd2009-04-30 14:43:31 -0700649 dev_set_drvdata(class_dev, sfp);
Kay Sievers54bd5b62007-10-08 16:26:13 -0300650 ret = device_register(class_dev);
Michael Krufky3117bee2006-07-19 13:23:38 -0300651 if (ret) {
Mike Isely49844c22008-04-09 05:44:57 -0300652 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
653 "device_register failed");
Vasiliy Kulikova519d70e2010-11-19 15:41:49 -0300654 put_device(class_dev);
Michael Krufky3117bee2006-07-19 13:23:38 -0300655 return;
656 }
Mike Iselyd8554972006-06-26 20:58:46 -0300657
Wolfram Sang12765512010-04-06 14:34:52 -0700658 sysfs_attr_init(&sfp->attr_v4l_minor_number.attr);
Mike Iselyd8554972006-06-26 20:58:46 -0300659 sfp->attr_v4l_minor_number.attr.name = "v4l_minor_number";
660 sfp->attr_v4l_minor_number.attr.mode = S_IRUGO;
661 sfp->attr_v4l_minor_number.show = v4l_minor_number_show;
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300662 sfp->attr_v4l_minor_number.store = NULL;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300663 ret = device_create_file(sfp->class_dev,
Mike Isely08d41802006-07-22 21:26:30 -0300664 &sfp->attr_v4l_minor_number);
665 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300666 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
667 "device_create_file error: %d",
668 ret);
Mike Isely08d41802006-07-22 21:26:30 -0300669 } else {
670 sfp->v4l_minor_number_created_ok = !0;
671 }
Michael Krufky3117bee2006-07-19 13:23:38 -0300672
Wolfram Sang12765512010-04-06 14:34:52 -0700673 sysfs_attr_init(&sfp->attr_v4l_radio_minor_number.attr);
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300674 sfp->attr_v4l_radio_minor_number.attr.name = "v4l_radio_minor_number";
675 sfp->attr_v4l_radio_minor_number.attr.mode = S_IRUGO;
676 sfp->attr_v4l_radio_minor_number.show = v4l_radio_minor_number_show;
677 sfp->attr_v4l_radio_minor_number.store = NULL;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300678 ret = device_create_file(sfp->class_dev,
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300679 &sfp->attr_v4l_radio_minor_number);
680 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300681 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
682 "device_create_file error: %d",
683 ret);
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300684 } else {
685 sfp->v4l_radio_minor_number_created_ok = !0;
686 }
687
Wolfram Sang12765512010-04-06 14:34:52 -0700688 sysfs_attr_init(&sfp->attr_unit_number.attr);
Mike Iselyd8554972006-06-26 20:58:46 -0300689 sfp->attr_unit_number.attr.name = "unit_number";
690 sfp->attr_unit_number.attr.mode = S_IRUGO;
691 sfp->attr_unit_number.show = unit_number_show;
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300692 sfp->attr_unit_number.store = NULL;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300693 ret = device_create_file(sfp->class_dev,&sfp->attr_unit_number);
Mike Isely08d41802006-07-22 21:26:30 -0300694 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300695 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
696 "device_create_file error: %d",
697 ret);
Mike Isely08d41802006-07-22 21:26:30 -0300698 } else {
699 sfp->unit_number_created_ok = !0;
700 }
Mike Iselyd8554972006-06-26 20:58:46 -0300701
Wolfram Sang12765512010-04-06 14:34:52 -0700702 sysfs_attr_init(&sfp->attr_bus_info.attr);
Mike Isely31a18542007-04-08 01:11:47 -0300703 sfp->attr_bus_info.attr.name = "bus_info_str";
704 sfp->attr_bus_info.attr.mode = S_IRUGO;
705 sfp->attr_bus_info.show = bus_info_show;
706 sfp->attr_bus_info.store = NULL;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300707 ret = device_create_file(sfp->class_dev,
Mike Isely31a18542007-04-08 01:11:47 -0300708 &sfp->attr_bus_info);
709 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300710 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
711 "device_create_file error: %d",
712 ret);
Mike Isely31a18542007-04-08 01:11:47 -0300713 } else {
714 sfp->bus_info_created_ok = !0;
715 }
716
Wolfram Sang12765512010-04-06 14:34:52 -0700717 sysfs_attr_init(&sfp->attr_hdw_name.attr);
Mike Isely78a47102007-11-26 01:58:20 -0300718 sfp->attr_hdw_name.attr.name = "device_hardware_type";
719 sfp->attr_hdw_name.attr.mode = S_IRUGO;
720 sfp->attr_hdw_name.show = hdw_name_show;
721 sfp->attr_hdw_name.store = NULL;
722 ret = device_create_file(sfp->class_dev,
723 &sfp->attr_hdw_name);
724 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300725 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
726 "device_create_file error: %d",
727 ret);
Mike Isely78a47102007-11-26 01:58:20 -0300728 } else {
729 sfp->hdw_name_created_ok = !0;
730 }
731
Wolfram Sang12765512010-04-06 14:34:52 -0700732 sysfs_attr_init(&sfp->attr_hdw_desc.attr);
Mike Isely78a47102007-11-26 01:58:20 -0300733 sfp->attr_hdw_desc.attr.name = "device_hardware_description";
734 sfp->attr_hdw_desc.attr.mode = S_IRUGO;
735 sfp->attr_hdw_desc.show = hdw_desc_show;
736 sfp->attr_hdw_desc.store = NULL;
737 ret = device_create_file(sfp->class_dev,
738 &sfp->attr_hdw_desc);
739 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300740 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
741 "device_create_file error: %d",
742 ret);
Mike Isely78a47102007-11-26 01:58:20 -0300743 } else {
744 sfp->hdw_desc_created_ok = !0;
745 }
746
Mike Iselyd8554972006-06-26 20:58:46 -0300747 pvr2_sysfs_add_controls(sfp);
748#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
749 pvr2_sysfs_add_debugifc(sfp);
750#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
751}
752
753
754static void pvr2_sysfs_internal_check(struct pvr2_channel *chp)
755{
756 struct pvr2_sysfs *sfp;
757 sfp = container_of(chp,struct pvr2_sysfs,channel);
758 if (!sfp->channel.mc_head->disconnect_flag) return;
759 pvr2_trace(PVR2_TRACE_STRUCT,"Destroying pvr2_sysfs id=%p",sfp);
760 class_dev_destroy(sfp);
761 pvr2_channel_done(&sfp->channel);
762 kfree(sfp);
763}
764
765
766struct pvr2_sysfs *pvr2_sysfs_create(struct pvr2_context *mp,
767 struct pvr2_sysfs_class *class_ptr)
768{
769 struct pvr2_sysfs *sfp;
Mike Iselyca545f72007-01-20 00:37:11 -0300770 sfp = kzalloc(sizeof(*sfp),GFP_KERNEL);
Mike Iselyd8554972006-06-26 20:58:46 -0300771 if (!sfp) return sfp;
Mike Iselyd8554972006-06-26 20:58:46 -0300772 pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr2_sysfs id=%p",sfp);
773 pvr2_channel_init(&sfp->channel,mp);
774 sfp->channel.check_func = pvr2_sysfs_internal_check;
775
776 class_dev_create(sfp,class_ptr);
777 return sfp;
778}
779
780
Mike Iselyd8554972006-06-26 20:58:46 -0300781
782struct pvr2_sysfs_class *pvr2_sysfs_class_create(void)
783{
784 struct pvr2_sysfs_class *clp;
Mike Iselyca545f72007-01-20 00:37:11 -0300785 clp = kzalloc(sizeof(*clp),GFP_KERNEL);
Mike Iselyd8554972006-06-26 20:58:46 -0300786 if (!clp) return clp;
Mike Isely28c4a5e2010-05-15 00:23:46 -0300787 pvr2_sysfs_trace("Creating and registering pvr2_sysfs_class id=%p",
788 clp);
Mike Iselyd8554972006-06-26 20:58:46 -0300789 clp->class.name = "pvrusb2";
790 clp->class.class_release = pvr2_sysfs_class_release;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300791 clp->class.dev_release = pvr2_sysfs_release;
Mike Iselyd8554972006-06-26 20:58:46 -0300792 if (class_register(&clp->class)) {
793 pvr2_sysfs_trace(
794 "Registration failed for pvr2_sysfs_class id=%p",clp);
795 kfree(clp);
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300796 clp = NULL;
Mike Iselyd8554972006-06-26 20:58:46 -0300797 }
798 return clp;
799}
800
801
802void pvr2_sysfs_class_destroy(struct pvr2_sysfs_class *clp)
803{
Mike Isely28c4a5e2010-05-15 00:23:46 -0300804 pvr2_sysfs_trace("Unregistering pvr2_sysfs_class id=%p", clp);
Mike Iselyd8554972006-06-26 20:58:46 -0300805 class_unregister(&clp->class);
806}
807
808
809#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
Trent Piephoc726b652007-10-08 19:05:28 -0300810static ssize_t debuginfo_show(struct device *class_dev,
811 struct device_attribute *attr, char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300812{
813 struct pvr2_sysfs *sfp;
Greg Kroah-Hartman79510cd2009-04-30 14:43:31 -0700814 sfp = dev_get_drvdata(class_dev);
Mike Iselyd8554972006-06-26 20:58:46 -0300815 if (!sfp) return -EINVAL;
816 pvr2_hdw_trigger_module_log(sfp->channel.hdw);
817 return pvr2_debugifc_print_info(sfp->channel.hdw,buf,PAGE_SIZE);
818}
819
820
Trent Piephoc726b652007-10-08 19:05:28 -0300821static ssize_t debugcmd_show(struct device *class_dev,
822 struct device_attribute *attr, char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300823{
824 struct pvr2_sysfs *sfp;
Greg Kroah-Hartman79510cd2009-04-30 14:43:31 -0700825 sfp = dev_get_drvdata(class_dev);
Mike Iselyd8554972006-06-26 20:58:46 -0300826 if (!sfp) return -EINVAL;
827 return pvr2_debugifc_print_status(sfp->channel.hdw,buf,PAGE_SIZE);
828}
829
830
Kay Sievers54bd5b62007-10-08 16:26:13 -0300831static ssize_t debugcmd_store(struct device *class_dev,
Trent Piephoc726b652007-10-08 19:05:28 -0300832 struct device_attribute *attr,
Kay Sievers54bd5b62007-10-08 16:26:13 -0300833 const char *buf, size_t count)
Mike Iselyd8554972006-06-26 20:58:46 -0300834{
835 struct pvr2_sysfs *sfp;
836 int ret;
837
Greg Kroah-Hartman79510cd2009-04-30 14:43:31 -0700838 sfp = dev_get_drvdata(class_dev);
Mike Iselyd8554972006-06-26 20:58:46 -0300839 if (!sfp) return -EINVAL;
840
841 ret = pvr2_debugifc_docmd(sfp->channel.hdw,buf,count);
842 if (ret < 0) return ret;
843 return count;
844}
845#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */