Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1 | /* |
| 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 Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 22 | #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 | |
| 34 | struct pvr2_sysfs { |
| 35 | struct pvr2_channel channel; |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 36 | struct device *class_dev; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 37 | #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 Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 42 | 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 Isely | 78a4710 | 2007-11-26 01:58:20 -0300 | [diff] [blame] | 46 | struct device_attribute attr_hdw_name; |
| 47 | struct device_attribute attr_hdw_desc; |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 48 | int v4l_minor_number_created_ok; |
Pantelis Koukousoulas | 2fdf3d9 | 2006-12-27 23:07:58 -0300 | [diff] [blame] | 49 | int v4l_radio_minor_number_created_ok; |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 50 | int unit_number_created_ok; |
Mike Isely | 31a1854 | 2007-04-08 01:11:47 -0300 | [diff] [blame] | 51 | int bus_info_created_ok; |
Mike Isely | 78a4710 | 2007-11-26 01:58:20 -0300 | [diff] [blame] | 52 | int hdw_name_created_ok; |
| 53 | int hdw_desc_created_ok; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC |
| 57 | struct pvr2_sysfs_debugifc { |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 58 | struct device_attribute attr_debugcmd; |
| 59 | struct device_attribute attr_debuginfo; |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 60 | int debugcmd_created_ok; |
| 61 | int debuginfo_created_ok; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 62 | }; |
| 63 | #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */ |
| 64 | |
| 65 | struct pvr2_sysfs_ctl_item { |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 66 | 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 Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 74 | struct pvr2_ctrl *cptr; |
| 75 | struct pvr2_sysfs *chptr; |
| 76 | struct pvr2_sysfs_ctl_item *item_next; |
Mike Isely | 3321396 | 2006-06-25 20:04:40 -0300 | [diff] [blame] | 77 | struct attribute *attr_gen[7]; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 78 | struct attribute_group grp; |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 79 | int created_ok; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 80 | char name[80]; |
| 81 | }; |
| 82 | |
| 83 | struct pvr2_sysfs_class { |
| 84 | struct class class; |
| 85 | }; |
| 86 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 87 | static ssize_t show_name(int id,struct device *class_dev,char *buf) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 88 | { |
| 89 | struct pvr2_ctrl *cptr; |
| 90 | struct pvr2_sysfs *sfp; |
| 91 | const char *name; |
| 92 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 93 | sfp = (struct pvr2_sysfs *)class_dev->driver_data; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 94 | 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 Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 106 | static ssize_t show_type(int id,struct device *class_dev,char *buf) |
Mike Isely | 3321396 | 2006-06-25 20:04:40 -0300 | [diff] [blame] | 107 | { |
| 108 | struct pvr2_ctrl *cptr; |
| 109 | struct pvr2_sysfs *sfp; |
| 110 | const char *name; |
| 111 | enum pvr2_ctl_type tp; |
| 112 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 113 | sfp = (struct pvr2_sysfs *)class_dev->driver_data; |
Mike Isely | 3321396 | 2006-06-25 20:04:40 -0300 | [diff] [blame] | 114 | 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 Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 133 | static ssize_t show_min(int id,struct device *class_dev,char *buf) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 134 | { |
| 135 | struct pvr2_ctrl *cptr; |
| 136 | struct pvr2_sysfs *sfp; |
| 137 | long val; |
| 138 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 139 | sfp = (struct pvr2_sysfs *)class_dev->driver_data; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 140 | 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 Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 150 | static ssize_t show_max(int id,struct device *class_dev,char *buf) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 151 | { |
| 152 | struct pvr2_ctrl *cptr; |
| 153 | struct pvr2_sysfs *sfp; |
| 154 | long val; |
| 155 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 156 | sfp = (struct pvr2_sysfs *)class_dev->driver_data; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 157 | 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 Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 167 | static ssize_t show_val_norm(int id,struct device *class_dev,char *buf) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 168 | { |
| 169 | struct pvr2_ctrl *cptr; |
| 170 | struct pvr2_sysfs *sfp; |
| 171 | int val,ret; |
| 172 | unsigned int cnt = 0; |
| 173 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 174 | sfp = (struct pvr2_sysfs *)class_dev->driver_data; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 175 | 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 Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 191 | static ssize_t show_val_custom(int id,struct device *class_dev,char *buf) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 192 | { |
| 193 | struct pvr2_ctrl *cptr; |
| 194 | struct pvr2_sysfs *sfp; |
| 195 | int val,ret; |
| 196 | unsigned int cnt = 0; |
| 197 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 198 | sfp = (struct pvr2_sysfs *)class_dev->driver_data; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 199 | 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 Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 215 | static ssize_t show_enum(int id,struct device *class_dev,char *buf) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 216 | { |
| 217 | struct pvr2_ctrl *cptr; |
| 218 | struct pvr2_sysfs *sfp; |
| 219 | long val; |
| 220 | unsigned int bcnt,ccnt,ecnt; |
| 221 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 222 | sfp = (struct pvr2_sysfs *)class_dev->driver_data; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 223 | 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 Isely | 4588677 | 2006-06-25 20:04:13 -0300 | [diff] [blame] | 230 | if (!ccnt) continue; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 231 | 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 Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 240 | static ssize_t show_bits(int id,struct device *class_dev,char *buf) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 241 | { |
| 242 | struct pvr2_ctrl *cptr; |
| 243 | struct pvr2_sysfs *sfp; |
| 244 | int valid_bits,msk; |
| 245 | unsigned int bcnt,ccnt; |
| 246 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 247 | sfp = (struct pvr2_sysfs *)class_dev->driver_data; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 248 | 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 | |
| 266 | static 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 Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 285 | static ssize_t store_val_norm(int id,struct device *class_dev, |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 286 | const char *buf,size_t count) |
| 287 | { |
| 288 | struct pvr2_sysfs *sfp; |
| 289 | int ret; |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 290 | sfp = (struct pvr2_sysfs *)class_dev->driver_data; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 291 | ret = store_val_any(id,0,sfp,buf,count); |
| 292 | if (!ret) ret = count; |
| 293 | return ret; |
| 294 | } |
| 295 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 296 | static ssize_t store_val_custom(int id,struct device *class_dev, |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 297 | const char *buf,size_t count) |
| 298 | { |
| 299 | struct pvr2_sysfs *sfp; |
| 300 | int ret; |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 301 | sfp = (struct pvr2_sysfs *)class_dev->driver_data; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 302 | 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 Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 311 | kernel's device_attribute mechanism fails to pass the actual |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 312 | 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 Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 321 | static ssize_t sf_name##_##ctl_id(struct device *class_dev, \ |
| 322 | struct device_attribute *attr, char *buf) \ |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 323 | { return sf_name(ctl_id,class_dev,buf); } |
| 324 | |
| 325 | #define CREATE_STORE_INSTANCE(sf_name,ctl_id) \ |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 326 | static ssize_t sf_name##_##ctl_id(struct device *class_dev, \ |
| 327 | struct device_attribute *attr, const char *buf, size_t count) \ |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 328 | { return sf_name(ctl_id,class_dev,buf,count); } |
| 329 | |
| 330 | #define CREATE_BATCH(ctl_id) \ |
| 331 | CREATE_SHOW_INSTANCE(show_name,ctl_id) \ |
Mike Isely | 3321396 | 2006-06-25 20:04:40 -0300 | [diff] [blame] | 332 | CREATE_SHOW_INSTANCE(show_type,ctl_id) \ |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 333 | CREATE_SHOW_INSTANCE(show_min,ctl_id) \ |
| 334 | CREATE_SHOW_INSTANCE(show_max,ctl_id) \ |
| 335 | CREATE_SHOW_INSTANCE(show_val_norm,ctl_id) \ |
| 336 | CREATE_SHOW_INSTANCE(show_val_custom,ctl_id) \ |
| 337 | CREATE_SHOW_INSTANCE(show_enum,ctl_id) \ |
| 338 | CREATE_SHOW_INSTANCE(show_bits,ctl_id) \ |
| 339 | CREATE_STORE_INSTANCE(store_val_norm,ctl_id) \ |
| 340 | CREATE_STORE_INSTANCE(store_val_custom,ctl_id) \ |
| 341 | |
| 342 | CREATE_BATCH(0) |
| 343 | CREATE_BATCH(1) |
| 344 | CREATE_BATCH(2) |
| 345 | CREATE_BATCH(3) |
| 346 | CREATE_BATCH(4) |
| 347 | CREATE_BATCH(5) |
| 348 | CREATE_BATCH(6) |
| 349 | CREATE_BATCH(7) |
| 350 | CREATE_BATCH(8) |
| 351 | CREATE_BATCH(9) |
| 352 | CREATE_BATCH(10) |
| 353 | CREATE_BATCH(11) |
| 354 | CREATE_BATCH(12) |
| 355 | CREATE_BATCH(13) |
| 356 | CREATE_BATCH(14) |
| 357 | CREATE_BATCH(15) |
| 358 | CREATE_BATCH(16) |
| 359 | CREATE_BATCH(17) |
| 360 | CREATE_BATCH(18) |
| 361 | CREATE_BATCH(19) |
| 362 | CREATE_BATCH(20) |
| 363 | CREATE_BATCH(21) |
| 364 | CREATE_BATCH(22) |
| 365 | CREATE_BATCH(23) |
| 366 | CREATE_BATCH(24) |
| 367 | CREATE_BATCH(25) |
| 368 | CREATE_BATCH(26) |
| 369 | CREATE_BATCH(27) |
| 370 | CREATE_BATCH(28) |
| 371 | CREATE_BATCH(29) |
| 372 | CREATE_BATCH(30) |
| 373 | CREATE_BATCH(31) |
| 374 | CREATE_BATCH(32) |
| 375 | CREATE_BATCH(33) |
Mike Isely | 3948199 | 2006-06-25 20:04:20 -0300 | [diff] [blame] | 376 | CREATE_BATCH(34) |
| 377 | CREATE_BATCH(35) |
| 378 | CREATE_BATCH(36) |
| 379 | CREATE_BATCH(37) |
| 380 | CREATE_BATCH(38) |
| 381 | CREATE_BATCH(39) |
| 382 | CREATE_BATCH(40) |
| 383 | CREATE_BATCH(41) |
| 384 | CREATE_BATCH(42) |
| 385 | CREATE_BATCH(43) |
| 386 | CREATE_BATCH(44) |
| 387 | CREATE_BATCH(45) |
| 388 | CREATE_BATCH(46) |
| 389 | CREATE_BATCH(47) |
| 390 | CREATE_BATCH(48) |
| 391 | CREATE_BATCH(49) |
| 392 | CREATE_BATCH(50) |
| 393 | CREATE_BATCH(51) |
| 394 | CREATE_BATCH(52) |
| 395 | CREATE_BATCH(53) |
| 396 | CREATE_BATCH(54) |
| 397 | CREATE_BATCH(55) |
| 398 | CREATE_BATCH(56) |
| 399 | CREATE_BATCH(57) |
| 400 | CREATE_BATCH(58) |
| 401 | CREATE_BATCH(59) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 402 | |
| 403 | struct pvr2_sysfs_func_set { |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 404 | 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 Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 420 | const char *,size_t); |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 421 | 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 Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 425 | const char *,size_t); |
| 426 | }; |
| 427 | |
| 428 | #define INIT_BATCH(ctl_id) \ |
| 429 | [ctl_id] = { \ |
| 430 | .show_name = show_name_##ctl_id, \ |
Mike Isely | 3321396 | 2006-06-25 20:04:40 -0300 | [diff] [blame] | 431 | .show_type = show_type_##ctl_id, \ |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 432 | .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 | |
| 442 | static 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 Isely | 3948199 | 2006-06-25 20:04:20 -0300 | [diff] [blame] | 477 | 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 Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 503 | }; |
| 504 | |
| 505 | |
| 506 | static 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 Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 512 | int ret; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 513 | |
Ahmed S. Darwish | eca8ebf | 2007-01-20 00:35:03 -0300 | [diff] [blame] | 514 | if ((ctl_id < 0) || (ctl_id >= ARRAY_SIZE(funcs))) { |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 515 | 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 Isely | ca545f7 | 2007-01-20 00:37:11 -0300 | [diff] [blame] | 522 | cip = kzalloc(sizeof(*cip),GFP_KERNEL); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 523 | if (!cip) return; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 524 | pvr2_sysfs_trace("Creating pvr2_sysfs_ctl_item id=%p",cip); |
| 525 | |
| 526 | cip->cptr = cptr; |
| 527 | |
| 528 | cip->chptr = sfp; |
Mike Isely | a0fd1cb | 2006-06-30 11:35:28 -0300 | [diff] [blame] | 529 | cip->item_next = NULL; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 530 | 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 Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 537 | cip->attr_name.attr.name = "name"; |
| 538 | cip->attr_name.attr.mode = S_IRUGO; |
| 539 | cip->attr_name.show = fp->show_name; |
| 540 | |
Mike Isely | 3321396 | 2006-06-25 20:04:40 -0300 | [diff] [blame] | 541 | cip->attr_type.attr.name = "type"; |
| 542 | cip->attr_type.attr.mode = S_IRUGO; |
| 543 | cip->attr_type.show = fp->show_type; |
| 544 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 545 | 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 Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 549 | 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 Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 553 | cip->attr_val.attr.name = "cur_val"; |
| 554 | cip->attr_val.attr.mode = S_IRUGO; |
| 555 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 556 | cip->attr_custom.attr.name = "custom_val"; |
| 557 | cip->attr_custom.attr.mode = S_IRUGO; |
| 558 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 559 | 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 Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 563 | 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 Isely | 3321396 | 2006-06-25 20:04:40 -0300 | [diff] [blame] | 574 | cip->attr_gen[acnt++] = &cip->attr_type.attr; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 575 | 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 Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 606 | 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 Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC |
Trent Piepho | c726b65 | 2007-10-08 19:05:28 -0300 | [diff] [blame] | 616 | static ssize_t debuginfo_show(struct device *, struct device_attribute *, |
| 617 | char *); |
| 618 | static ssize_t debugcmd_show(struct device *, struct device_attribute *, |
| 619 | char *); |
| 620 | static ssize_t debugcmd_store(struct device *, struct device_attribute *, |
| 621 | const char *, size_t count); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 622 | |
| 623 | static void pvr2_sysfs_add_debugifc(struct pvr2_sysfs *sfp) |
| 624 | { |
| 625 | struct pvr2_sysfs_debugifc *dip; |
Michael Krufky | 3117bee | 2006-07-19 13:23:38 -0300 | [diff] [blame] | 626 | int ret; |
| 627 | |
Mike Isely | ca545f7 | 2007-01-20 00:37:11 -0300 | [diff] [blame] | 628 | dip = kzalloc(sizeof(*dip),GFP_KERNEL); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 629 | if (!dip) return; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 630 | 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 Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 634 | 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 Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 638 | ret = device_create_file(sfp->class_dev,&dip->attr_debugcmd); |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 639 | if (ret < 0) { |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 640 | printk(KERN_WARNING "%s: device_create_file error: %d\n", |
Michael Krufky | 3117bee | 2006-07-19 13:23:38 -0300 | [diff] [blame] | 641 | __FUNCTION__, ret); |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 642 | } else { |
| 643 | dip->debugcmd_created_ok = !0; |
| 644 | } |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 645 | ret = device_create_file(sfp->class_dev,&dip->attr_debuginfo); |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 646 | if (ret < 0) { |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 647 | printk(KERN_WARNING "%s: device_create_file error: %d\n", |
Michael Krufky | 3117bee | 2006-07-19 13:23:38 -0300 | [diff] [blame] | 648 | __FUNCTION__, ret); |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 649 | } else { |
| 650 | dip->debuginfo_created_ok = !0; |
| 651 | } |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | |
| 655 | static void pvr2_sysfs_tear_down_debugifc(struct pvr2_sysfs *sfp) |
| 656 | { |
| 657 | if (!sfp->debugifc) return; |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 658 | if (sfp->debugifc->debuginfo_created_ok) { |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 659 | device_remove_file(sfp->class_dev, |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 660 | &sfp->debugifc->attr_debuginfo); |
| 661 | } |
| 662 | if (sfp->debugifc->debugcmd_created_ok) { |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 663 | device_remove_file(sfp->class_dev, |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 664 | &sfp->debugifc->attr_debugcmd); |
| 665 | } |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 666 | kfree(sfp->debugifc); |
Mike Isely | a0fd1cb | 2006-06-30 11:35:28 -0300 | [diff] [blame] | 667 | sfp->debugifc = NULL; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 668 | } |
| 669 | #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */ |
| 670 | |
| 671 | |
| 672 | static 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 | |
| 682 | static 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 Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 687 | if (cip1->created_ok) { |
| 688 | sysfs_remove_group(&sfp->class_dev->kobj,&cip1->grp); |
| 689 | } |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 690 | pvr2_sysfs_trace("Destroying pvr2_sysfs_ctl_item id=%p",cip1); |
| 691 | kfree(cip1); |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | |
| 696 | static 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 Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 705 | static void pvr2_sysfs_release(struct device *class_dev) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 706 | { |
| 707 | pvr2_sysfs_trace("Releasing class_dev id=%p",class_dev); |
| 708 | kfree(class_dev); |
| 709 | } |
| 710 | |
| 711 | |
| 712 | static 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 Isely | 78a4710 | 2007-11-26 01:58:20 -0300 | [diff] [blame] | 719 | 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 Isely | 31a1854 | 2007-04-08 01:11:47 -0300 | [diff] [blame] | 727 | if (sfp->bus_info_created_ok) { |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 728 | device_remove_file(sfp->class_dev, |
Mike Isely | 31a1854 | 2007-04-08 01:11:47 -0300 | [diff] [blame] | 729 | &sfp->attr_bus_info); |
| 730 | } |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 731 | if (sfp->v4l_minor_number_created_ok) { |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 732 | device_remove_file(sfp->class_dev, |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 733 | &sfp->attr_v4l_minor_number); |
| 734 | } |
Pantelis Koukousoulas | 2fdf3d9 | 2006-12-27 23:07:58 -0300 | [diff] [blame] | 735 | if (sfp->v4l_radio_minor_number_created_ok) { |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 736 | device_remove_file(sfp->class_dev, |
Pantelis Koukousoulas | 2fdf3d9 | 2006-12-27 23:07:58 -0300 | [diff] [blame] | 737 | &sfp->attr_v4l_radio_minor_number); |
| 738 | } |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 739 | if (sfp->unit_number_created_ok) { |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 740 | device_remove_file(sfp->class_dev, |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 741 | &sfp->attr_unit_number); |
| 742 | } |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 743 | pvr2_sysfs_trace("Destroying class_dev id=%p",sfp->class_dev); |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 744 | sfp->class_dev->driver_data = NULL; |
| 745 | device_unregister(sfp->class_dev); |
Mike Isely | a0fd1cb | 2006-06-30 11:35:28 -0300 | [diff] [blame] | 746 | sfp->class_dev = NULL; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 750 | static ssize_t v4l_minor_number_show(struct device *class_dev, |
| 751 | struct device_attribute *attr, char *buf) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 752 | { |
| 753 | struct pvr2_sysfs *sfp; |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 754 | sfp = (struct pvr2_sysfs *)class_dev->driver_data; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 755 | if (!sfp) return -EINVAL; |
| 756 | return scnprintf(buf,PAGE_SIZE,"%d\n", |
Mike Isely | fd5a75f | 2006-12-27 23:11:22 -0300 | [diff] [blame] | 757 | pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw, |
Mike Isely | 8079384 | 2006-12-27 23:12:28 -0300 | [diff] [blame] | 758 | pvr2_v4l_type_video)); |
Pantelis Koukousoulas | 2fdf3d9 | 2006-12-27 23:07:58 -0300 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 762 | static ssize_t bus_info_show(struct device *class_dev, |
| 763 | struct device_attribute *attr, char *buf) |
Mike Isely | 31a1854 | 2007-04-08 01:11:47 -0300 | [diff] [blame] | 764 | { |
| 765 | struct pvr2_sysfs *sfp; |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 766 | sfp = (struct pvr2_sysfs *)class_dev->driver_data; |
Mike Isely | 31a1854 | 2007-04-08 01:11:47 -0300 | [diff] [blame] | 767 | 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 Isely | 78a4710 | 2007-11-26 01:58:20 -0300 | [diff] [blame] | 773 | static 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 | |
| 784 | static 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 Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 795 | static ssize_t v4l_radio_minor_number_show(struct device *class_dev, |
| 796 | struct device_attribute *attr, |
Pantelis Koukousoulas | 2fdf3d9 | 2006-12-27 23:07:58 -0300 | [diff] [blame] | 797 | char *buf) |
| 798 | { |
| 799 | struct pvr2_sysfs *sfp; |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 800 | sfp = (struct pvr2_sysfs *)class_dev->driver_data; |
Pantelis Koukousoulas | 2fdf3d9 | 2006-12-27 23:07:58 -0300 | [diff] [blame] | 801 | if (!sfp) return -EINVAL; |
| 802 | return scnprintf(buf,PAGE_SIZE,"%d\n", |
Mike Isely | fd5a75f | 2006-12-27 23:11:22 -0300 | [diff] [blame] | 803 | pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw, |
Mike Isely | 8079384 | 2006-12-27 23:12:28 -0300 | [diff] [blame] | 804 | pvr2_v4l_type_radio)); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 808 | static ssize_t unit_number_show(struct device *class_dev, |
| 809 | struct device_attribute *attr, char *buf) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 810 | { |
| 811 | struct pvr2_sysfs *sfp; |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 812 | sfp = (struct pvr2_sysfs *)class_dev->driver_data; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 813 | if (!sfp) return -EINVAL; |
| 814 | return scnprintf(buf,PAGE_SIZE,"%d\n", |
| 815 | pvr2_hdw_get_unit_number(sfp->channel.hdw)); |
| 816 | } |
| 817 | |
| 818 | |
| 819 | static void class_dev_create(struct pvr2_sysfs *sfp, |
| 820 | struct pvr2_sysfs_class *class_ptr) |
| 821 | { |
| 822 | struct usb_device *usb_dev; |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 823 | struct device *class_dev; |
Michael Krufky | 3117bee | 2006-07-19 13:23:38 -0300 | [diff] [blame] | 824 | int ret; |
| 825 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 826 | usb_dev = pvr2_hdw_get_dev(sfp->channel.hdw); |
| 827 | if (!usb_dev) return; |
Mike Isely | ca545f7 | 2007-01-20 00:37:11 -0300 | [diff] [blame] | 828 | class_dev = kzalloc(sizeof(*class_dev),GFP_KERNEL); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 829 | if (!class_dev) return; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 830 | |
| 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 Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 835 | snprintf(class_dev->bus_id, BUS_ID_SIZE, "sn-%lu", |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 836 | pvr2_hdw_get_sn(sfp->channel.hdw)); |
| 837 | } else if (pvr2_hdw_get_unit_number(sfp->channel.hdw) >= 0) { |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 838 | snprintf(class_dev->bus_id, BUS_ID_SIZE, "unit-%c", |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 839 | pvr2_hdw_get_unit_number(sfp->channel.hdw) + 'a'); |
| 840 | } else { |
| 841 | kfree(class_dev); |
| 842 | return; |
| 843 | } |
| 844 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 845 | class_dev->parent = &usb_dev->dev; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 846 | |
| 847 | sfp->class_dev = class_dev; |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 848 | class_dev->driver_data = sfp; |
| 849 | ret = device_register(class_dev); |
Michael Krufky | 3117bee | 2006-07-19 13:23:38 -0300 | [diff] [blame] | 850 | if (ret) { |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 851 | printk(KERN_ERR "%s: device_register failed\n", |
Michael Krufky | 3117bee | 2006-07-19 13:23:38 -0300 | [diff] [blame] | 852 | __FUNCTION__); |
| 853 | kfree(class_dev); |
| 854 | return; |
| 855 | } |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 856 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 857 | 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 Isely | a0fd1cb | 2006-06-30 11:35:28 -0300 | [diff] [blame] | 860 | sfp->attr_v4l_minor_number.store = NULL; |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 861 | ret = device_create_file(sfp->class_dev, |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 862 | &sfp->attr_v4l_minor_number); |
| 863 | if (ret < 0) { |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 864 | printk(KERN_WARNING "%s: device_create_file error: %d\n", |
Michael Krufky | 3117bee | 2006-07-19 13:23:38 -0300 | [diff] [blame] | 865 | __FUNCTION__, ret); |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 866 | } else { |
| 867 | sfp->v4l_minor_number_created_ok = !0; |
| 868 | } |
Michael Krufky | 3117bee | 2006-07-19 13:23:38 -0300 | [diff] [blame] | 869 | |
Pantelis Koukousoulas | 2fdf3d9 | 2006-12-27 23:07:58 -0300 | [diff] [blame] | 870 | 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 Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 874 | ret = device_create_file(sfp->class_dev, |
Pantelis Koukousoulas | 2fdf3d9 | 2006-12-27 23:07:58 -0300 | [diff] [blame] | 875 | &sfp->attr_v4l_radio_minor_number); |
| 876 | if (ret < 0) { |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 877 | printk(KERN_WARNING "%s: device_create_file error: %d\n", |
Pantelis Koukousoulas | 2fdf3d9 | 2006-12-27 23:07:58 -0300 | [diff] [blame] | 878 | __FUNCTION__, ret); |
| 879 | } else { |
| 880 | sfp->v4l_radio_minor_number_created_ok = !0; |
| 881 | } |
| 882 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 883 | 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 Isely | a0fd1cb | 2006-06-30 11:35:28 -0300 | [diff] [blame] | 886 | sfp->attr_unit_number.store = NULL; |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 887 | ret = device_create_file(sfp->class_dev,&sfp->attr_unit_number); |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 888 | if (ret < 0) { |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 889 | printk(KERN_WARNING "%s: device_create_file error: %d\n", |
Michael Krufky | 3117bee | 2006-07-19 13:23:38 -0300 | [diff] [blame] | 890 | __FUNCTION__, ret); |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 891 | } else { |
| 892 | sfp->unit_number_created_ok = !0; |
| 893 | } |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 894 | |
Mike Isely | 31a1854 | 2007-04-08 01:11:47 -0300 | [diff] [blame] | 895 | 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 Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 899 | ret = device_create_file(sfp->class_dev, |
Mike Isely | 31a1854 | 2007-04-08 01:11:47 -0300 | [diff] [blame] | 900 | &sfp->attr_bus_info); |
| 901 | if (ret < 0) { |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 902 | printk(KERN_WARNING "%s: device_create_file error: %d\n", |
Mike Isely | 31a1854 | 2007-04-08 01:11:47 -0300 | [diff] [blame] | 903 | __FUNCTION__, ret); |
| 904 | } else { |
| 905 | sfp->bus_info_created_ok = !0; |
| 906 | } |
| 907 | |
Mike Isely | 78a4710 | 2007-11-26 01:58:20 -0300 | [diff] [blame] | 908 | 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 Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 934 | 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 | |
| 941 | static 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 | |
| 953 | struct pvr2_sysfs *pvr2_sysfs_create(struct pvr2_context *mp, |
| 954 | struct pvr2_sysfs_class *class_ptr) |
| 955 | { |
| 956 | struct pvr2_sysfs *sfp; |
Mike Isely | ca545f7 | 2007-01-20 00:37:11 -0300 | [diff] [blame] | 957 | sfp = kzalloc(sizeof(*sfp),GFP_KERNEL); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 958 | if (!sfp) return sfp; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 959 | 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 Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 968 | |
| 969 | struct pvr2_sysfs_class *pvr2_sysfs_class_create(void) |
| 970 | { |
| 971 | struct pvr2_sysfs_class *clp; |
Mike Isely | ca545f7 | 2007-01-20 00:37:11 -0300 | [diff] [blame] | 972 | clp = kzalloc(sizeof(*clp),GFP_KERNEL); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 973 | if (!clp) return clp; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 974 | 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 Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 977 | clp->class.dev_release = pvr2_sysfs_release; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 978 | if (class_register(&clp->class)) { |
| 979 | pvr2_sysfs_trace( |
| 980 | "Registration failed for pvr2_sysfs_class id=%p",clp); |
| 981 | kfree(clp); |
Mike Isely | a0fd1cb | 2006-06-30 11:35:28 -0300 | [diff] [blame] | 982 | clp = NULL; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 983 | } |
| 984 | return clp; |
| 985 | } |
| 986 | |
| 987 | |
| 988 | void 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 Piepho | c726b65 | 2007-10-08 19:05:28 -0300 | [diff] [blame] | 995 | static ssize_t debuginfo_show(struct device *class_dev, |
| 996 | struct device_attribute *attr, char *buf) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 997 | { |
| 998 | struct pvr2_sysfs *sfp; |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 999 | sfp = (struct pvr2_sysfs *)class_dev->driver_data; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1000 | 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 Piepho | c726b65 | 2007-10-08 19:05:28 -0300 | [diff] [blame] | 1006 | static ssize_t debugcmd_show(struct device *class_dev, |
| 1007 | struct device_attribute *attr, char *buf) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1008 | { |
| 1009 | struct pvr2_sysfs *sfp; |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 1010 | sfp = (struct pvr2_sysfs *)class_dev->driver_data; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1011 | if (!sfp) return -EINVAL; |
| 1012 | return pvr2_debugifc_print_status(sfp->channel.hdw,buf,PAGE_SIZE); |
| 1013 | } |
| 1014 | |
| 1015 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 1016 | static ssize_t debugcmd_store(struct device *class_dev, |
Trent Piepho | c726b65 | 2007-10-08 19:05:28 -0300 | [diff] [blame] | 1017 | struct device_attribute *attr, |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 1018 | const char *buf, size_t count) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1019 | { |
| 1020 | struct pvr2_sysfs *sfp; |
| 1021 | int ret; |
| 1022 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 1023 | sfp = (struct pvr2_sysfs *)class_dev->driver_data; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1024 | 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 | */ |