blob: 71f50565f637c804f19fac089cf62af55134bf55 [file] [log] [blame]
Mike Iselyd8554972006-06-26 20:58:46 -03001/*
2 *
Mike Iselyd8554972006-06-26 20:58:46 -03003 *
4 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 */
20
Mike Iselyd8554972006-06-26 20:58:46 -030021#include <linux/string.h>
22#include <linux/slab.h>
Mike Iselyd8554972006-06-26 20:58:46 -030023#include "pvrusb2-sysfs.h"
24#include "pvrusb2-hdw.h"
25#include "pvrusb2-debug.h"
26#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
27#include "pvrusb2-debugifc.h"
28#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
29
30#define pvr2_sysfs_trace(...) pvr2_trace(PVR2_TRACE_SYSFS,__VA_ARGS__)
31
32struct pvr2_sysfs {
33 struct pvr2_channel channel;
Kay Sievers54bd5b62007-10-08 16:26:13 -030034 struct device *class_dev;
Mike Iselyd8554972006-06-26 20:58:46 -030035#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
36 struct pvr2_sysfs_debugifc *debugifc;
37#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
38 struct pvr2_sysfs_ctl_item *item_first;
39 struct pvr2_sysfs_ctl_item *item_last;
Kay Sievers54bd5b62007-10-08 16:26:13 -030040 struct device_attribute attr_v4l_minor_number;
41 struct device_attribute attr_v4l_radio_minor_number;
42 struct device_attribute attr_unit_number;
43 struct device_attribute attr_bus_info;
Mike Isely78a47102007-11-26 01:58:20 -030044 struct device_attribute attr_hdw_name;
45 struct device_attribute attr_hdw_desc;
Mike Isely08d41802006-07-22 21:26:30 -030046 int v4l_minor_number_created_ok;
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -030047 int v4l_radio_minor_number_created_ok;
Mike Isely08d41802006-07-22 21:26:30 -030048 int unit_number_created_ok;
Mike Isely31a18542007-04-08 01:11:47 -030049 int bus_info_created_ok;
Mike Isely78a47102007-11-26 01:58:20 -030050 int hdw_name_created_ok;
51 int hdw_desc_created_ok;
Mike Iselyd8554972006-06-26 20:58:46 -030052};
53
54#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
55struct pvr2_sysfs_debugifc {
Kay Sievers54bd5b62007-10-08 16:26:13 -030056 struct device_attribute attr_debugcmd;
57 struct device_attribute attr_debuginfo;
Mike Isely08d41802006-07-22 21:26:30 -030058 int debugcmd_created_ok;
59 int debuginfo_created_ok;
Mike Iselyd8554972006-06-26 20:58:46 -030060};
61#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
62
63struct pvr2_sysfs_ctl_item {
Kay Sievers54bd5b62007-10-08 16:26:13 -030064 struct device_attribute attr_name;
65 struct device_attribute attr_type;
66 struct device_attribute attr_min;
67 struct device_attribute attr_max;
Mike Isely0b7c2c92008-08-31 20:57:54 -030068 struct device_attribute attr_def;
Kay Sievers54bd5b62007-10-08 16:26:13 -030069 struct device_attribute attr_enum;
70 struct device_attribute attr_bits;
71 struct device_attribute attr_val;
72 struct device_attribute attr_custom;
Mike Iselyd8554972006-06-26 20:58:46 -030073 struct pvr2_ctrl *cptr;
Mike Iselyf90fe7a2008-05-26 06:00:47 -030074 int ctl_id;
Mike Iselyd8554972006-06-26 20:58:46 -030075 struct pvr2_sysfs *chptr;
76 struct pvr2_sysfs_ctl_item *item_next;
Mike Isely33213962006-06-25 20:04:40 -030077 struct attribute *attr_gen[7];
Mike Iselyd8554972006-06-26 20:58:46 -030078 struct attribute_group grp;
Mike Isely08d41802006-07-22 21:26:30 -030079 int created_ok;
Mike Iselyd8554972006-06-26 20:58:46 -030080 char name[80];
81};
82
83struct pvr2_sysfs_class {
84 struct class class;
85};
86
Mike Iselyf90fe7a2008-05-26 06:00:47 -030087static ssize_t show_name(struct device *class_dev,
88 struct device_attribute *attr,
89 char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -030090{
Mike Iselyf90fe7a2008-05-26 06:00:47 -030091 struct pvr2_sysfs_ctl_item *cip;
Mike Iselyd8554972006-06-26 20:58:46 -030092 const char *name;
Mike Iselyf90fe7a2008-05-26 06:00:47 -030093 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_name);
94 name = pvr2_ctrl_get_desc(cip->cptr);
95 pvr2_sysfs_trace("pvr2_sysfs(%p) show_name(cid=%d) is %s",
96 cip->chptr, cip->ctl_id, name);
Mike Iselyd8554972006-06-26 20:58:46 -030097 if (!name) return -EINVAL;
Mike Iselyf90fe7a2008-05-26 06:00:47 -030098 return scnprintf(buf, PAGE_SIZE, "%s\n", name);
Mike Iselyd8554972006-06-26 20:58:46 -030099}
100
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300101static ssize_t show_type(struct device *class_dev,
102 struct device_attribute *attr,
103 char *buf)
Mike Isely33213962006-06-25 20:04:40 -0300104{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300105 struct pvr2_sysfs_ctl_item *cip;
Mike Isely33213962006-06-25 20:04:40 -0300106 const char *name;
107 enum pvr2_ctl_type tp;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300108 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_type);
109 tp = pvr2_ctrl_get_type(cip->cptr);
Mike Isely33213962006-06-25 20:04:40 -0300110 switch (tp) {
111 case pvr2_ctl_int: name = "integer"; break;
112 case pvr2_ctl_enum: name = "enum"; break;
113 case pvr2_ctl_bitmask: name = "bitmask"; break;
114 case pvr2_ctl_bool: name = "boolean"; break;
115 default: name = "?"; break;
116 }
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300117 pvr2_sysfs_trace("pvr2_sysfs(%p) show_type(cid=%d) is %s",
118 cip->chptr, cip->ctl_id, name);
Mike Isely33213962006-06-25 20:04:40 -0300119 if (!name) return -EINVAL;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300120 return scnprintf(buf, PAGE_SIZE, "%s\n", name);
Mike Isely33213962006-06-25 20:04:40 -0300121}
122
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300123static ssize_t show_min(struct device *class_dev,
124 struct device_attribute *attr,
125 char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300126{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300127 struct pvr2_sysfs_ctl_item *cip;
Mike Iselyd8554972006-06-26 20:58:46 -0300128 long val;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300129 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_min);
130 val = pvr2_ctrl_get_min(cip->cptr);
131 pvr2_sysfs_trace("pvr2_sysfs(%p) show_min(cid=%d) is %ld",
132 cip->chptr, cip->ctl_id, val);
133 return scnprintf(buf, PAGE_SIZE, "%ld\n", val);
Mike Iselyd8554972006-06-26 20:58:46 -0300134}
135
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300136static ssize_t show_max(struct device *class_dev,
137 struct device_attribute *attr,
138 char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300139{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300140 struct pvr2_sysfs_ctl_item *cip;
Mike Iselyd8554972006-06-26 20:58:46 -0300141 long val;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300142 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_max);
143 val = pvr2_ctrl_get_max(cip->cptr);
144 pvr2_sysfs_trace("pvr2_sysfs(%p) show_max(cid=%d) is %ld",
145 cip->chptr, cip->ctl_id, val);
146 return scnprintf(buf, PAGE_SIZE, "%ld\n", val);
Mike Iselyd8554972006-06-26 20:58:46 -0300147}
148
Mike Isely0b7c2c92008-08-31 20:57:54 -0300149static ssize_t show_def(struct device *class_dev,
150 struct device_attribute *attr,
151 char *buf)
152{
153 struct pvr2_sysfs_ctl_item *cip;
154 int val;
155 int ret;
Mike Isely7bf56f92009-04-01 01:51:53 -0300156 unsigned int cnt = 0;
Mike Isely0b7c2c92008-08-31 20:57:54 -0300157 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_def);
158 ret = pvr2_ctrl_get_def(cip->cptr, &val);
Mike Isely7bf56f92009-04-01 01:51:53 -0300159 if (ret < 0) return ret;
160 ret = pvr2_ctrl_value_to_sym(cip->cptr, ~0, val,
161 buf, PAGE_SIZE - 1, &cnt);
162 pvr2_sysfs_trace("pvr2_sysfs(%p) show_def(cid=%d) is %.*s (%d)",
163 cip->chptr, cip->ctl_id, cnt, buf, val);
164 buf[cnt] = '\n';
165 return cnt + 1;
Mike Isely0b7c2c92008-08-31 20:57:54 -0300166}
167
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300168static ssize_t show_val_norm(struct device *class_dev,
169 struct device_attribute *attr,
170 char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300171{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300172 struct pvr2_sysfs_ctl_item *cip;
173 int val;
174 int ret;
Mike Iselyd8554972006-06-26 20:58:46 -0300175 unsigned int cnt = 0;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300176 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_val);
177 ret = pvr2_ctrl_get_value(cip->cptr, &val);
Mike Iselyd8554972006-06-26 20:58:46 -0300178 if (ret < 0) return ret;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300179 ret = pvr2_ctrl_value_to_sym(cip->cptr, ~0, val,
180 buf, PAGE_SIZE - 1, &cnt);
Mike Iselyd8554972006-06-26 20:58:46 -0300181 pvr2_sysfs_trace("pvr2_sysfs(%p) show_val_norm(cid=%d) is %.*s (%d)",
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300182 cip->chptr, cip->ctl_id, cnt, buf, val);
Mike Iselyd8554972006-06-26 20:58:46 -0300183 buf[cnt] = '\n';
184 return cnt+1;
185}
186
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300187static ssize_t show_val_custom(struct device *class_dev,
188 struct device_attribute *attr,
189 char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300190{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300191 struct pvr2_sysfs_ctl_item *cip;
192 int val;
193 int ret;
Mike Iselyd8554972006-06-26 20:58:46 -0300194 unsigned int cnt = 0;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300195 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_custom);
196 ret = pvr2_ctrl_get_value(cip->cptr, &val);
Mike Iselyd8554972006-06-26 20:58:46 -0300197 if (ret < 0) return ret;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300198 ret = pvr2_ctrl_custom_value_to_sym(cip->cptr, ~0, val,
199 buf, PAGE_SIZE - 1, &cnt);
Mike Iselyd8554972006-06-26 20:58:46 -0300200 pvr2_sysfs_trace("pvr2_sysfs(%p) show_val_custom(cid=%d) is %.*s (%d)",
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300201 cip->chptr, cip->ctl_id, cnt, buf, val);
Mike Iselyd8554972006-06-26 20:58:46 -0300202 buf[cnt] = '\n';
203 return cnt+1;
204}
205
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300206static ssize_t show_enum(struct device *class_dev,
207 struct device_attribute *attr,
208 char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300209{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300210 struct pvr2_sysfs_ctl_item *cip;
Mike Iselyd8554972006-06-26 20:58:46 -0300211 long val;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300212 unsigned int bcnt, ccnt, ecnt;
213 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_enum);
214 ecnt = pvr2_ctrl_get_cnt(cip->cptr);
Mike Iselyd8554972006-06-26 20:58:46 -0300215 bcnt = 0;
216 for (val = 0; val < ecnt; val++) {
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300217 pvr2_ctrl_get_valname(cip->cptr, val, buf + bcnt,
218 PAGE_SIZE - bcnt, &ccnt);
Mike Isely45886772006-06-25 20:04:13 -0300219 if (!ccnt) continue;
Mike Iselyd8554972006-06-26 20:58:46 -0300220 bcnt += ccnt;
221 if (bcnt >= PAGE_SIZE) break;
222 buf[bcnt] = '\n';
223 bcnt++;
224 }
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300225 pvr2_sysfs_trace("pvr2_sysfs(%p) show_enum(cid=%d)",
226 cip->chptr, cip->ctl_id);
Mike Iselyd8554972006-06-26 20:58:46 -0300227 return bcnt;
228}
229
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300230static ssize_t show_bits(struct device *class_dev,
231 struct device_attribute *attr,
232 char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300233{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300234 struct pvr2_sysfs_ctl_item *cip;
235 int valid_bits, msk;
236 unsigned int bcnt, ccnt;
237 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_bits);
238 valid_bits = pvr2_ctrl_get_mask(cip->cptr);
Mike Iselyd8554972006-06-26 20:58:46 -0300239 bcnt = 0;
240 for (msk = 1; valid_bits; msk <<= 1) {
241 if (!(msk & valid_bits)) continue;
242 valid_bits &= ~msk;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300243 pvr2_ctrl_get_valname(cip->cptr, msk, buf + bcnt,
244 PAGE_SIZE - bcnt, &ccnt);
Mike Iselyd8554972006-06-26 20:58:46 -0300245 bcnt += ccnt;
246 if (bcnt >= PAGE_SIZE) break;
247 buf[bcnt] = '\n';
248 bcnt++;
249 }
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300250 pvr2_sysfs_trace("pvr2_sysfs(%p) show_bits(cid=%d)",
251 cip->chptr, cip->ctl_id);
Mike Iselyd8554972006-06-26 20:58:46 -0300252 return bcnt;
253}
254
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300255static int store_val_any(struct pvr2_sysfs_ctl_item *cip, int customfl,
Mike Iselyd8554972006-06-26 20:58:46 -0300256 const char *buf,unsigned int count)
257{
Mike Iselyd8554972006-06-26 20:58:46 -0300258 int ret;
259 int mask,val;
Mike Iselyd8554972006-06-26 20:58:46 -0300260 if (customfl) {
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300261 ret = pvr2_ctrl_custom_sym_to_value(cip->cptr, buf, count,
262 &mask, &val);
Mike Iselyd8554972006-06-26 20:58:46 -0300263 } else {
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300264 ret = pvr2_ctrl_sym_to_value(cip->cptr, buf, count,
265 &mask, &val);
Mike Iselyd8554972006-06-26 20:58:46 -0300266 }
267 if (ret < 0) return ret;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300268 ret = pvr2_ctrl_set_mask_value(cip->cptr, mask, val);
269 pvr2_hdw_commit_ctl(cip->chptr->channel.hdw);
Mike Iselyd8554972006-06-26 20:58:46 -0300270 return ret;
271}
272
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300273static ssize_t store_val_norm(struct device *class_dev,
274 struct device_attribute *attr,
275 const char *buf, size_t count)
Mike Iselyd8554972006-06-26 20:58:46 -0300276{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300277 struct pvr2_sysfs_ctl_item *cip;
Mike Iselyd8554972006-06-26 20:58:46 -0300278 int ret;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300279 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_val);
Mike Iselybedbbf82008-04-22 14:45:38 -0300280 pvr2_sysfs_trace("pvr2_sysfs(%p) store_val_norm(cid=%d) \"%.*s\"",
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300281 cip->chptr, cip->ctl_id, (int)count, buf);
282 ret = store_val_any(cip, 0, buf, count);
Mike Iselyd8554972006-06-26 20:58:46 -0300283 if (!ret) ret = count;
284 return ret;
285}
286
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300287static ssize_t store_val_custom(struct device *class_dev,
288 struct device_attribute *attr,
289 const char *buf, size_t count)
Mike Iselyd8554972006-06-26 20:58:46 -0300290{
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300291 struct pvr2_sysfs_ctl_item *cip;
Mike Iselyd8554972006-06-26 20:58:46 -0300292 int ret;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300293 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_custom);
Mike Iselybedbbf82008-04-22 14:45:38 -0300294 pvr2_sysfs_trace("pvr2_sysfs(%p) store_val_custom(cid=%d) \"%.*s\"",
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300295 cip->chptr, cip->ctl_id, (int)count, buf);
296 ret = store_val_any(cip, 1, buf, count);
Mike Iselyd8554972006-06-26 20:58:46 -0300297 if (!ret) ret = count;
298 return ret;
299}
300
Mike Iselyd8554972006-06-26 20:58:46 -0300301static void pvr2_sysfs_add_control(struct pvr2_sysfs *sfp,int ctl_id)
302{
303 struct pvr2_sysfs_ctl_item *cip;
Mike Iselyd8554972006-06-26 20:58:46 -0300304 struct pvr2_ctrl *cptr;
305 unsigned int cnt,acnt;
Mike Isely08d41802006-07-22 21:26:30 -0300306 int ret;
Mike Iselyd8554972006-06-26 20:58:46 -0300307
Mike Iselyd8554972006-06-26 20:58:46 -0300308 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,ctl_id);
309 if (!cptr) return;
310
Mike Iselyca545f72007-01-20 00:37:11 -0300311 cip = kzalloc(sizeof(*cip),GFP_KERNEL);
Mike Iselyd8554972006-06-26 20:58:46 -0300312 if (!cip) return;
Mike Iselyd8554972006-06-26 20:58:46 -0300313 pvr2_sysfs_trace("Creating pvr2_sysfs_ctl_item id=%p",cip);
314
315 cip->cptr = cptr;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300316 cip->ctl_id = ctl_id;
Mike Iselyd8554972006-06-26 20:58:46 -0300317
318 cip->chptr = sfp;
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300319 cip->item_next = NULL;
Mike Iselyd8554972006-06-26 20:58:46 -0300320 if (sfp->item_last) {
321 sfp->item_last->item_next = cip;
322 } else {
323 sfp->item_first = cip;
324 }
325 sfp->item_last = cip;
326
Mike Iselyd8554972006-06-26 20:58:46 -0300327 cip->attr_name.attr.name = "name";
328 cip->attr_name.attr.mode = S_IRUGO;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300329 cip->attr_name.show = show_name;
Mike Iselyd8554972006-06-26 20:58:46 -0300330
Mike Isely33213962006-06-25 20:04:40 -0300331 cip->attr_type.attr.name = "type";
332 cip->attr_type.attr.mode = S_IRUGO;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300333 cip->attr_type.show = show_type;
Mike Isely33213962006-06-25 20:04:40 -0300334
Mike Iselyd8554972006-06-26 20:58:46 -0300335 cip->attr_min.attr.name = "min_val";
336 cip->attr_min.attr.mode = S_IRUGO;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300337 cip->attr_min.show = show_min;
Mike Iselyd8554972006-06-26 20:58:46 -0300338
Mike Iselyd8554972006-06-26 20:58:46 -0300339 cip->attr_max.attr.name = "max_val";
340 cip->attr_max.attr.mode = S_IRUGO;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300341 cip->attr_max.show = show_max;
Mike Iselyd8554972006-06-26 20:58:46 -0300342
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 Iselyd8554972006-06-26 20:58:46 -0300347 cip->attr_val.attr.name = "cur_val";
348 cip->attr_val.attr.mode = S_IRUGO;
349
Mike Iselyd8554972006-06-26 20:58:46 -0300350 cip->attr_custom.attr.name = "custom_val";
351 cip->attr_custom.attr.mode = S_IRUGO;
352
Mike Iselyd8554972006-06-26 20:58:46 -0300353 cip->attr_enum.attr.name = "enum_val";
354 cip->attr_enum.attr.mode = S_IRUGO;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300355 cip->attr_enum.show = show_enum;
Mike Iselyd8554972006-06-26 20:58:46 -0300356
Mike Iselyd8554972006-06-26 20:58:46 -0300357 cip->attr_bits.attr.name = "bit_val";
358 cip->attr_bits.attr.mode = S_IRUGO;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300359 cip->attr_bits.show = show_bits;
Mike Iselyd8554972006-06-26 20:58:46 -0300360
361 if (pvr2_ctrl_is_writable(cptr)) {
362 cip->attr_val.attr.mode |= S_IWUSR|S_IWGRP;
363 cip->attr_custom.attr.mode |= S_IWUSR|S_IWGRP;
364 }
365
366 acnt = 0;
367 cip->attr_gen[acnt++] = &cip->attr_name.attr;
Mike Isely33213962006-06-25 20:04:40 -0300368 cip->attr_gen[acnt++] = &cip->attr_type.attr;
Mike Iselyd8554972006-06-26 20:58:46 -0300369 cip->attr_gen[acnt++] = &cip->attr_val.attr;
Mike Isely0b7c2c92008-08-31 20:57:54 -0300370 cip->attr_gen[acnt++] = &cip->attr_def.attr;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300371 cip->attr_val.show = show_val_norm;
372 cip->attr_val.store = store_val_norm;
Mike Iselyd8554972006-06-26 20:58:46 -0300373 if (pvr2_ctrl_has_custom_symbols(cptr)) {
374 cip->attr_gen[acnt++] = &cip->attr_custom.attr;
Mike Iselyf90fe7a2008-05-26 06:00:47 -0300375 cip->attr_custom.show = show_val_custom;
376 cip->attr_custom.store = store_val_custom;
Mike Iselyd8554972006-06-26 20:58:46 -0300377 }
378 switch (pvr2_ctrl_get_type(cptr)) {
379 case pvr2_ctl_enum:
380 // Control is an enumeration
381 cip->attr_gen[acnt++] = &cip->attr_enum.attr;
382 break;
383 case pvr2_ctl_int:
384 // Control is an integer
385 cip->attr_gen[acnt++] = &cip->attr_min.attr;
386 cip->attr_gen[acnt++] = &cip->attr_max.attr;
387 break;
388 case pvr2_ctl_bitmask:
389 // Control is an bitmask
390 cip->attr_gen[acnt++] = &cip->attr_bits.attr;
391 break;
392 default: break;
393 }
394
395 cnt = scnprintf(cip->name,sizeof(cip->name)-1,"ctl_%s",
396 pvr2_ctrl_get_name(cptr));
397 cip->name[cnt] = 0;
398 cip->grp.name = cip->name;
399 cip->grp.attrs = cip->attr_gen;
400
Mike Isely08d41802006-07-22 21:26:30 -0300401 ret = sysfs_create_group(&sfp->class_dev->kobj,&cip->grp);
402 if (ret) {
Mike Isely49844c22008-04-09 05:44:57 -0300403 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
404 "sysfs_create_group error: %d",
405 ret);
Mike Isely08d41802006-07-22 21:26:30 -0300406 return;
407 }
408 cip->created_ok = !0;
Mike Iselyd8554972006-06-26 20:58:46 -0300409}
410
411#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
Trent Piephoc726b652007-10-08 19:05:28 -0300412static ssize_t debuginfo_show(struct device *, struct device_attribute *,
413 char *);
414static ssize_t debugcmd_show(struct device *, struct device_attribute *,
415 char *);
416static ssize_t debugcmd_store(struct device *, struct device_attribute *,
417 const char *, size_t count);
Mike Iselyd8554972006-06-26 20:58:46 -0300418
419static void pvr2_sysfs_add_debugifc(struct pvr2_sysfs *sfp)
420{
421 struct pvr2_sysfs_debugifc *dip;
Michael Krufky3117bee2006-07-19 13:23:38 -0300422 int ret;
423
Mike Iselyca545f72007-01-20 00:37:11 -0300424 dip = kzalloc(sizeof(*dip),GFP_KERNEL);
Mike Iselyd8554972006-06-26 20:58:46 -0300425 if (!dip) return;
Wolfram Sang12765512010-04-06 14:34:52 -0700426 sysfs_attr_init(&dip->attr_debugcmd.attr);
Mike Iselyd8554972006-06-26 20:58:46 -0300427 dip->attr_debugcmd.attr.name = "debugcmd";
428 dip->attr_debugcmd.attr.mode = S_IRUGO|S_IWUSR|S_IWGRP;
429 dip->attr_debugcmd.show = debugcmd_show;
430 dip->attr_debugcmd.store = debugcmd_store;
Wolfram Sang12765512010-04-06 14:34:52 -0700431 sysfs_attr_init(&dip->attr_debuginfo.attr);
Mike Iselyd8554972006-06-26 20:58:46 -0300432 dip->attr_debuginfo.attr.name = "debuginfo";
433 dip->attr_debuginfo.attr.mode = S_IRUGO;
434 dip->attr_debuginfo.show = debuginfo_show;
435 sfp->debugifc = dip;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300436 ret = device_create_file(sfp->class_dev,&dip->attr_debugcmd);
Mike Isely08d41802006-07-22 21:26:30 -0300437 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300438 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
439 "device_create_file error: %d",
440 ret);
Mike Isely08d41802006-07-22 21:26:30 -0300441 } else {
442 dip->debugcmd_created_ok = !0;
443 }
Kay Sievers54bd5b62007-10-08 16:26:13 -0300444 ret = device_create_file(sfp->class_dev,&dip->attr_debuginfo);
Mike Isely08d41802006-07-22 21:26:30 -0300445 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300446 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
447 "device_create_file error: %d",
448 ret);
Mike Isely08d41802006-07-22 21:26:30 -0300449 } else {
450 dip->debuginfo_created_ok = !0;
451 }
Mike Iselyd8554972006-06-26 20:58:46 -0300452}
453
454
455static void pvr2_sysfs_tear_down_debugifc(struct pvr2_sysfs *sfp)
456{
457 if (!sfp->debugifc) return;
Mike Isely08d41802006-07-22 21:26:30 -0300458 if (sfp->debugifc->debuginfo_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300459 device_remove_file(sfp->class_dev,
Mike Isely08d41802006-07-22 21:26:30 -0300460 &sfp->debugifc->attr_debuginfo);
461 }
462 if (sfp->debugifc->debugcmd_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_debugcmd);
465 }
Mike Iselyd8554972006-06-26 20:58:46 -0300466 kfree(sfp->debugifc);
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300467 sfp->debugifc = NULL;
Mike Iselyd8554972006-06-26 20:58:46 -0300468}
469#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
470
471
472static void pvr2_sysfs_add_controls(struct pvr2_sysfs *sfp)
473{
474 unsigned int idx,cnt;
475 cnt = pvr2_hdw_get_ctrl_count(sfp->channel.hdw);
476 for (idx = 0; idx < cnt; idx++) {
477 pvr2_sysfs_add_control(sfp,idx);
478 }
479}
480
481
482static void pvr2_sysfs_tear_down_controls(struct pvr2_sysfs *sfp)
483{
484 struct pvr2_sysfs_ctl_item *cip1,*cip2;
485 for (cip1 = sfp->item_first; cip1; cip1 = cip2) {
486 cip2 = cip1->item_next;
Mike Isely08d41802006-07-22 21:26:30 -0300487 if (cip1->created_ok) {
488 sysfs_remove_group(&sfp->class_dev->kobj,&cip1->grp);
489 }
Mike Iselyd8554972006-06-26 20:58:46 -0300490 pvr2_sysfs_trace("Destroying pvr2_sysfs_ctl_item id=%p",cip1);
491 kfree(cip1);
492 }
493}
494
495
496static void pvr2_sysfs_class_release(struct class *class)
497{
498 struct pvr2_sysfs_class *clp;
499 clp = container_of(class,struct pvr2_sysfs_class,class);
500 pvr2_sysfs_trace("Destroying pvr2_sysfs_class id=%p",clp);
501 kfree(clp);
502}
503
504
Kay Sievers54bd5b62007-10-08 16:26:13 -0300505static void pvr2_sysfs_release(struct device *class_dev)
Mike Iselyd8554972006-06-26 20:58:46 -0300506{
507 pvr2_sysfs_trace("Releasing class_dev id=%p",class_dev);
508 kfree(class_dev);
509}
510
511
512static void class_dev_destroy(struct pvr2_sysfs *sfp)
513{
514 if (!sfp->class_dev) return;
515#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
516 pvr2_sysfs_tear_down_debugifc(sfp);
517#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
518 pvr2_sysfs_tear_down_controls(sfp);
Mike Isely78a47102007-11-26 01:58:20 -0300519 if (sfp->hdw_desc_created_ok) {
520 device_remove_file(sfp->class_dev,
521 &sfp->attr_hdw_desc);
522 }
523 if (sfp->hdw_name_created_ok) {
524 device_remove_file(sfp->class_dev,
525 &sfp->attr_hdw_name);
526 }
Mike Isely31a18542007-04-08 01:11:47 -0300527 if (sfp->bus_info_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300528 device_remove_file(sfp->class_dev,
Mike Isely31a18542007-04-08 01:11:47 -0300529 &sfp->attr_bus_info);
530 }
Mike Isely08d41802006-07-22 21:26:30 -0300531 if (sfp->v4l_minor_number_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300532 device_remove_file(sfp->class_dev,
Mike Isely08d41802006-07-22 21:26:30 -0300533 &sfp->attr_v4l_minor_number);
534 }
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300535 if (sfp->v4l_radio_minor_number_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300536 device_remove_file(sfp->class_dev,
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300537 &sfp->attr_v4l_radio_minor_number);
538 }
Mike Isely08d41802006-07-22 21:26:30 -0300539 if (sfp->unit_number_created_ok) {
Kay Sievers54bd5b62007-10-08 16:26:13 -0300540 device_remove_file(sfp->class_dev,
Mike Isely08d41802006-07-22 21:26:30 -0300541 &sfp->attr_unit_number);
542 }
Mike Iselyd8554972006-06-26 20:58:46 -0300543 pvr2_sysfs_trace("Destroying class_dev id=%p",sfp->class_dev);
Greg Kroah-Hartman79510cd2009-04-30 14:43:31 -0700544 dev_set_drvdata(sfp->class_dev, NULL);
Kay Sievers54bd5b62007-10-08 16:26:13 -0300545 device_unregister(sfp->class_dev);
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300546 sfp->class_dev = NULL;
Mike Iselyd8554972006-06-26 20:58:46 -0300547}
548
549
Kay Sievers54bd5b62007-10-08 16:26:13 -0300550static ssize_t v4l_minor_number_show(struct device *class_dev,
551 struct device_attribute *attr, char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300552{
553 struct pvr2_sysfs *sfp;
Greg Kroah-Hartman79510cd2009-04-30 14:43:31 -0700554 sfp = dev_get_drvdata(class_dev);
Mike Iselyd8554972006-06-26 20:58:46 -0300555 if (!sfp) return -EINVAL;
556 return scnprintf(buf,PAGE_SIZE,"%d\n",
Mike Iselyfd5a75f2006-12-27 23:11:22 -0300557 pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw,
Mike Isely80793842006-12-27 23:12:28 -0300558 pvr2_v4l_type_video));
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300559}
560
561
Kay Sievers54bd5b62007-10-08 16:26:13 -0300562static ssize_t bus_info_show(struct device *class_dev,
563 struct device_attribute *attr, char *buf)
Mike Isely31a18542007-04-08 01:11:47 -0300564{
565 struct pvr2_sysfs *sfp;
Greg Kroah-Hartman79510cd2009-04-30 14:43:31 -0700566 sfp = dev_get_drvdata(class_dev);
Mike Isely31a18542007-04-08 01:11:47 -0300567 if (!sfp) return -EINVAL;
568 return scnprintf(buf,PAGE_SIZE,"%s\n",
569 pvr2_hdw_get_bus_info(sfp->channel.hdw));
570}
571
572
Mike Isely78a47102007-11-26 01:58:20 -0300573static ssize_t hdw_name_show(struct device *class_dev,
574 struct device_attribute *attr, char *buf)
575{
576 struct pvr2_sysfs *sfp;
Greg Kroah-Hartman79510cd2009-04-30 14:43:31 -0700577 sfp = dev_get_drvdata(class_dev);
Mike Isely78a47102007-11-26 01:58:20 -0300578 if (!sfp) return -EINVAL;
579 return scnprintf(buf,PAGE_SIZE,"%s\n",
580 pvr2_hdw_get_type(sfp->channel.hdw));
581}
582
583
584static ssize_t hdw_desc_show(struct device *class_dev,
585 struct device_attribute *attr, char *buf)
586{
587 struct pvr2_sysfs *sfp;
Greg Kroah-Hartman79510cd2009-04-30 14:43:31 -0700588 sfp = dev_get_drvdata(class_dev);
Mike Isely78a47102007-11-26 01:58:20 -0300589 if (!sfp) return -EINVAL;
590 return scnprintf(buf,PAGE_SIZE,"%s\n",
591 pvr2_hdw_get_desc(sfp->channel.hdw));
592}
593
594
Kay Sievers54bd5b62007-10-08 16:26:13 -0300595static ssize_t v4l_radio_minor_number_show(struct device *class_dev,
596 struct device_attribute *attr,
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300597 char *buf)
598{
599 struct pvr2_sysfs *sfp;
Greg Kroah-Hartman79510cd2009-04-30 14:43:31 -0700600 sfp = dev_get_drvdata(class_dev);
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300601 if (!sfp) return -EINVAL;
602 return scnprintf(buf,PAGE_SIZE,"%d\n",
Mike Iselyfd5a75f2006-12-27 23:11:22 -0300603 pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw,
Mike Isely80793842006-12-27 23:12:28 -0300604 pvr2_v4l_type_radio));
Mike Iselyd8554972006-06-26 20:58:46 -0300605}
606
607
Kay Sievers54bd5b62007-10-08 16:26:13 -0300608static ssize_t unit_number_show(struct device *class_dev,
609 struct device_attribute *attr, char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300610{
611 struct pvr2_sysfs *sfp;
Greg Kroah-Hartman79510cd2009-04-30 14:43:31 -0700612 sfp = dev_get_drvdata(class_dev);
Mike Iselyd8554972006-06-26 20:58:46 -0300613 if (!sfp) return -EINVAL;
614 return scnprintf(buf,PAGE_SIZE,"%d\n",
615 pvr2_hdw_get_unit_number(sfp->channel.hdw));
616}
617
618
619static void class_dev_create(struct pvr2_sysfs *sfp,
620 struct pvr2_sysfs_class *class_ptr)
621{
622 struct usb_device *usb_dev;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300623 struct device *class_dev;
Michael Krufky3117bee2006-07-19 13:23:38 -0300624 int ret;
625
Mike Iselyd8554972006-06-26 20:58:46 -0300626 usb_dev = pvr2_hdw_get_dev(sfp->channel.hdw);
627 if (!usb_dev) return;
Mike Iselyca545f72007-01-20 00:37:11 -0300628 class_dev = kzalloc(sizeof(*class_dev),GFP_KERNEL);
Mike Iselyd8554972006-06-26 20:58:46 -0300629 if (!class_dev) return;
Mike Iselyd8554972006-06-26 20:58:46 -0300630
631 pvr2_sysfs_trace("Creating class_dev id=%p",class_dev);
632
633 class_dev->class = &class_ptr->class;
Mike Isely730e92c2009-01-14 04:24:20 -0300634 dev_set_name(class_dev, "%s",
635 pvr2_hdw_get_device_identifier(sfp->channel.hdw));
Mike Iselyd8554972006-06-26 20:58:46 -0300636
Kay Sievers54bd5b62007-10-08 16:26:13 -0300637 class_dev->parent = &usb_dev->dev;
Mike Iselyd8554972006-06-26 20:58:46 -0300638
639 sfp->class_dev = class_dev;
Greg Kroah-Hartman79510cd2009-04-30 14:43:31 -0700640 dev_set_drvdata(class_dev, sfp);
Kay Sievers54bd5b62007-10-08 16:26:13 -0300641 ret = device_register(class_dev);
Michael Krufky3117bee2006-07-19 13:23:38 -0300642 if (ret) {
Mike Isely49844c22008-04-09 05:44:57 -0300643 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
644 "device_register failed");
Michael Krufky3117bee2006-07-19 13:23:38 -0300645 kfree(class_dev);
646 return;
647 }
Mike Iselyd8554972006-06-26 20:58:46 -0300648
Wolfram Sang12765512010-04-06 14:34:52 -0700649 sysfs_attr_init(&sfp->attr_v4l_minor_number.attr);
Mike Iselyd8554972006-06-26 20:58:46 -0300650 sfp->attr_v4l_minor_number.attr.name = "v4l_minor_number";
651 sfp->attr_v4l_minor_number.attr.mode = S_IRUGO;
652 sfp->attr_v4l_minor_number.show = v4l_minor_number_show;
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300653 sfp->attr_v4l_minor_number.store = NULL;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300654 ret = device_create_file(sfp->class_dev,
Mike Isely08d41802006-07-22 21:26:30 -0300655 &sfp->attr_v4l_minor_number);
656 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300657 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
658 "device_create_file error: %d",
659 ret);
Mike Isely08d41802006-07-22 21:26:30 -0300660 } else {
661 sfp->v4l_minor_number_created_ok = !0;
662 }
Michael Krufky3117bee2006-07-19 13:23:38 -0300663
Wolfram Sang12765512010-04-06 14:34:52 -0700664 sysfs_attr_init(&sfp->attr_v4l_radio_minor_number.attr);
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300665 sfp->attr_v4l_radio_minor_number.attr.name = "v4l_radio_minor_number";
666 sfp->attr_v4l_radio_minor_number.attr.mode = S_IRUGO;
667 sfp->attr_v4l_radio_minor_number.show = v4l_radio_minor_number_show;
668 sfp->attr_v4l_radio_minor_number.store = NULL;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300669 ret = device_create_file(sfp->class_dev,
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300670 &sfp->attr_v4l_radio_minor_number);
671 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300672 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
673 "device_create_file error: %d",
674 ret);
Pantelis Koukousoulas2fdf3d92006-12-27 23:07:58 -0300675 } else {
676 sfp->v4l_radio_minor_number_created_ok = !0;
677 }
678
Wolfram Sang12765512010-04-06 14:34:52 -0700679 sysfs_attr_init(&sfp->attr_unit_number.attr);
Mike Iselyd8554972006-06-26 20:58:46 -0300680 sfp->attr_unit_number.attr.name = "unit_number";
681 sfp->attr_unit_number.attr.mode = S_IRUGO;
682 sfp->attr_unit_number.show = unit_number_show;
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300683 sfp->attr_unit_number.store = NULL;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300684 ret = device_create_file(sfp->class_dev,&sfp->attr_unit_number);
Mike Isely08d41802006-07-22 21:26:30 -0300685 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300686 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
687 "device_create_file error: %d",
688 ret);
Mike Isely08d41802006-07-22 21:26:30 -0300689 } else {
690 sfp->unit_number_created_ok = !0;
691 }
Mike Iselyd8554972006-06-26 20:58:46 -0300692
Wolfram Sang12765512010-04-06 14:34:52 -0700693 sysfs_attr_init(&sfp->attr_bus_info.attr);
Mike Isely31a18542007-04-08 01:11:47 -0300694 sfp->attr_bus_info.attr.name = "bus_info_str";
695 sfp->attr_bus_info.attr.mode = S_IRUGO;
696 sfp->attr_bus_info.show = bus_info_show;
697 sfp->attr_bus_info.store = NULL;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300698 ret = device_create_file(sfp->class_dev,
Mike Isely31a18542007-04-08 01:11:47 -0300699 &sfp->attr_bus_info);
700 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300701 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
702 "device_create_file error: %d",
703 ret);
Mike Isely31a18542007-04-08 01:11:47 -0300704 } else {
705 sfp->bus_info_created_ok = !0;
706 }
707
Wolfram Sang12765512010-04-06 14:34:52 -0700708 sysfs_attr_init(&sfp->attr_hdw_name.attr);
Mike Isely78a47102007-11-26 01:58:20 -0300709 sfp->attr_hdw_name.attr.name = "device_hardware_type";
710 sfp->attr_hdw_name.attr.mode = S_IRUGO;
711 sfp->attr_hdw_name.show = hdw_name_show;
712 sfp->attr_hdw_name.store = NULL;
713 ret = device_create_file(sfp->class_dev,
714 &sfp->attr_hdw_name);
715 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300716 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
717 "device_create_file error: %d",
718 ret);
Mike Isely78a47102007-11-26 01:58:20 -0300719 } else {
720 sfp->hdw_name_created_ok = !0;
721 }
722
Wolfram Sang12765512010-04-06 14:34:52 -0700723 sysfs_attr_init(&sfp->attr_hdw_desc.attr);
Mike Isely78a47102007-11-26 01:58:20 -0300724 sfp->attr_hdw_desc.attr.name = "device_hardware_description";
725 sfp->attr_hdw_desc.attr.mode = S_IRUGO;
726 sfp->attr_hdw_desc.show = hdw_desc_show;
727 sfp->attr_hdw_desc.store = NULL;
728 ret = device_create_file(sfp->class_dev,
729 &sfp->attr_hdw_desc);
730 if (ret < 0) {
Mike Isely49844c22008-04-09 05:44:57 -0300731 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
732 "device_create_file error: %d",
733 ret);
Mike Isely78a47102007-11-26 01:58:20 -0300734 } else {
735 sfp->hdw_desc_created_ok = !0;
736 }
737
Mike Iselyd8554972006-06-26 20:58:46 -0300738 pvr2_sysfs_add_controls(sfp);
739#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
740 pvr2_sysfs_add_debugifc(sfp);
741#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
742}
743
744
745static void pvr2_sysfs_internal_check(struct pvr2_channel *chp)
746{
747 struct pvr2_sysfs *sfp;
748 sfp = container_of(chp,struct pvr2_sysfs,channel);
749 if (!sfp->channel.mc_head->disconnect_flag) return;
750 pvr2_trace(PVR2_TRACE_STRUCT,"Destroying pvr2_sysfs id=%p",sfp);
751 class_dev_destroy(sfp);
752 pvr2_channel_done(&sfp->channel);
753 kfree(sfp);
754}
755
756
757struct pvr2_sysfs *pvr2_sysfs_create(struct pvr2_context *mp,
758 struct pvr2_sysfs_class *class_ptr)
759{
760 struct pvr2_sysfs *sfp;
Mike Iselyca545f72007-01-20 00:37:11 -0300761 sfp = kzalloc(sizeof(*sfp),GFP_KERNEL);
Mike Iselyd8554972006-06-26 20:58:46 -0300762 if (!sfp) return sfp;
Mike Iselyd8554972006-06-26 20:58:46 -0300763 pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr2_sysfs id=%p",sfp);
764 pvr2_channel_init(&sfp->channel,mp);
765 sfp->channel.check_func = pvr2_sysfs_internal_check;
766
767 class_dev_create(sfp,class_ptr);
768 return sfp;
769}
770
771
Mike Iselyd8554972006-06-26 20:58:46 -0300772
773struct pvr2_sysfs_class *pvr2_sysfs_class_create(void)
774{
775 struct pvr2_sysfs_class *clp;
Mike Iselyca545f72007-01-20 00:37:11 -0300776 clp = kzalloc(sizeof(*clp),GFP_KERNEL);
Mike Iselyd8554972006-06-26 20:58:46 -0300777 if (!clp) return clp;
Mike Iselyd8554972006-06-26 20:58:46 -0300778 pvr2_sysfs_trace("Creating pvr2_sysfs_class id=%p",clp);
779 clp->class.name = "pvrusb2";
780 clp->class.class_release = pvr2_sysfs_class_release;
Kay Sievers54bd5b62007-10-08 16:26:13 -0300781 clp->class.dev_release = pvr2_sysfs_release;
Mike Iselyd8554972006-06-26 20:58:46 -0300782 if (class_register(&clp->class)) {
783 pvr2_sysfs_trace(
784 "Registration failed for pvr2_sysfs_class id=%p",clp);
785 kfree(clp);
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300786 clp = NULL;
Mike Iselyd8554972006-06-26 20:58:46 -0300787 }
788 return clp;
789}
790
791
792void pvr2_sysfs_class_destroy(struct pvr2_sysfs_class *clp)
793{
794 class_unregister(&clp->class);
795}
796
797
798#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
Trent Piephoc726b652007-10-08 19:05:28 -0300799static ssize_t debuginfo_show(struct device *class_dev,
800 struct device_attribute *attr, char *buf)
Mike Iselyd8554972006-06-26 20:58:46 -0300801{
802 struct pvr2_sysfs *sfp;
Greg Kroah-Hartman79510cd2009-04-30 14:43:31 -0700803 sfp = dev_get_drvdata(class_dev);
Mike Iselyd8554972006-06-26 20:58:46 -0300804 if (!sfp) return -EINVAL;
805 pvr2_hdw_trigger_module_log(sfp->channel.hdw);
806 return pvr2_debugifc_print_info(sfp->channel.hdw,buf,PAGE_SIZE);
807}
808
809
Trent Piephoc726b652007-10-08 19:05:28 -0300810static ssize_t debugcmd_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 return pvr2_debugifc_print_status(sfp->channel.hdw,buf,PAGE_SIZE);
817}
818
819
Kay Sievers54bd5b62007-10-08 16:26:13 -0300820static ssize_t debugcmd_store(struct device *class_dev,
Trent Piephoc726b652007-10-08 19:05:28 -0300821 struct device_attribute *attr,
Kay Sievers54bd5b62007-10-08 16:26:13 -0300822 const char *buf, size_t count)
Mike Iselyd8554972006-06-26 20:58:46 -0300823{
824 struct pvr2_sysfs *sfp;
825 int ret;
826
Greg Kroah-Hartman79510cd2009-04-30 14:43:31 -0700827 sfp = dev_get_drvdata(class_dev);
Mike Iselyd8554972006-06-26 20:58:46 -0300828 if (!sfp) return -EINVAL;
829
830 ret = pvr2_debugifc_docmd(sfp->channel.hdw,buf,count);
831 if (ret < 0) return ret;
832 return count;
833}
834#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
835
836
837/*
838 Stuff for Emacs to see, in order to encourage consistent editing style:
839 *** Local Variables: ***
840 *** mode: c ***
841 *** fill-column: 75 ***
842 *** tab-width: 8 ***
843 *** c-basic-offset: 8 ***
844 *** End: ***
845 */