Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1 | /* |
| 2 | * |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2005 Mike Isely <isely@pobox.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 15 | */ |
| 16 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 17 | #include <linux/string.h> |
| 18 | #include <linux/slab.h> |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 19 | #include "pvrusb2-sysfs.h" |
| 20 | #include "pvrusb2-hdw.h" |
| 21 | #include "pvrusb2-debug.h" |
| 22 | #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC |
| 23 | #include "pvrusb2-debugifc.h" |
| 24 | #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */ |
| 25 | |
| 26 | #define pvr2_sysfs_trace(...) pvr2_trace(PVR2_TRACE_SYSFS,__VA_ARGS__) |
| 27 | |
| 28 | struct pvr2_sysfs { |
| 29 | struct pvr2_channel channel; |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 30 | struct device *class_dev; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 31 | #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC |
| 32 | struct pvr2_sysfs_debugifc *debugifc; |
| 33 | #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */ |
| 34 | struct pvr2_sysfs_ctl_item *item_first; |
| 35 | struct pvr2_sysfs_ctl_item *item_last; |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 36 | struct device_attribute attr_v4l_minor_number; |
| 37 | struct device_attribute attr_v4l_radio_minor_number; |
| 38 | struct device_attribute attr_unit_number; |
| 39 | struct device_attribute attr_bus_info; |
Mike Isely | 78a4710 | 2007-11-26 01:58:20 -0300 | [diff] [blame] | 40 | struct device_attribute attr_hdw_name; |
| 41 | struct device_attribute attr_hdw_desc; |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 42 | int v4l_minor_number_created_ok; |
Pantelis Koukousoulas | 2fdf3d9 | 2006-12-27 23:07:58 -0300 | [diff] [blame] | 43 | int v4l_radio_minor_number_created_ok; |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 44 | int unit_number_created_ok; |
Mike Isely | 31a1854 | 2007-04-08 01:11:47 -0300 | [diff] [blame] | 45 | int bus_info_created_ok; |
Mike Isely | 78a4710 | 2007-11-26 01:58:20 -0300 | [diff] [blame] | 46 | int hdw_name_created_ok; |
| 47 | int hdw_desc_created_ok; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC |
| 51 | struct pvr2_sysfs_debugifc { |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 52 | struct device_attribute attr_debugcmd; |
| 53 | struct device_attribute attr_debuginfo; |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 54 | int debugcmd_created_ok; |
| 55 | int debuginfo_created_ok; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 56 | }; |
| 57 | #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */ |
| 58 | |
| 59 | struct pvr2_sysfs_ctl_item { |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 60 | struct device_attribute attr_name; |
| 61 | struct device_attribute attr_type; |
| 62 | struct device_attribute attr_min; |
| 63 | struct device_attribute attr_max; |
Mike Isely | 0b7c2c9 | 2008-08-31 20:57:54 -0300 | [diff] [blame] | 64 | struct device_attribute attr_def; |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 65 | struct device_attribute attr_enum; |
| 66 | struct device_attribute attr_bits; |
| 67 | struct device_attribute attr_val; |
| 68 | struct device_attribute attr_custom; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 69 | struct pvr2_ctrl *cptr; |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 70 | int ctl_id; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 71 | struct pvr2_sysfs *chptr; |
| 72 | struct pvr2_sysfs_ctl_item *item_next; |
Mike Isely | 7a6ac34 | 2010-05-15 00:28:44 -0300 | [diff] [blame] | 73 | struct attribute *attr_gen[8]; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 74 | struct attribute_group grp; |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 75 | int created_ok; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 76 | char name[80]; |
| 77 | }; |
| 78 | |
| 79 | struct pvr2_sysfs_class { |
| 80 | struct class class; |
| 81 | }; |
| 82 | |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 83 | static ssize_t show_name(struct device *class_dev, |
| 84 | struct device_attribute *attr, |
| 85 | char *buf) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 86 | { |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 87 | struct pvr2_sysfs_ctl_item *cip; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 88 | const char *name; |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 89 | cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_name); |
| 90 | name = pvr2_ctrl_get_desc(cip->cptr); |
| 91 | pvr2_sysfs_trace("pvr2_sysfs(%p) show_name(cid=%d) is %s", |
| 92 | cip->chptr, cip->ctl_id, name); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 93 | if (!name) return -EINVAL; |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 94 | return scnprintf(buf, PAGE_SIZE, "%s\n", name); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 95 | } |
| 96 | |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 97 | static ssize_t show_type(struct device *class_dev, |
| 98 | struct device_attribute *attr, |
| 99 | char *buf) |
Mike Isely | 3321396 | 2006-06-25 20:04:40 -0300 | [diff] [blame] | 100 | { |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 101 | struct pvr2_sysfs_ctl_item *cip; |
Mike Isely | 3321396 | 2006-06-25 20:04:40 -0300 | [diff] [blame] | 102 | const char *name; |
| 103 | enum pvr2_ctl_type tp; |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 104 | cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_type); |
| 105 | tp = pvr2_ctrl_get_type(cip->cptr); |
Mike Isely | 3321396 | 2006-06-25 20:04:40 -0300 | [diff] [blame] | 106 | switch (tp) { |
| 107 | case pvr2_ctl_int: name = "integer"; break; |
| 108 | case pvr2_ctl_enum: name = "enum"; break; |
| 109 | case pvr2_ctl_bitmask: name = "bitmask"; break; |
| 110 | case pvr2_ctl_bool: name = "boolean"; break; |
| 111 | default: name = "?"; break; |
| 112 | } |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 113 | pvr2_sysfs_trace("pvr2_sysfs(%p) show_type(cid=%d) is %s", |
| 114 | cip->chptr, cip->ctl_id, name); |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 115 | return scnprintf(buf, PAGE_SIZE, "%s\n", name); |
Mike Isely | 3321396 | 2006-06-25 20:04:40 -0300 | [diff] [blame] | 116 | } |
| 117 | |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 118 | static ssize_t show_min(struct device *class_dev, |
| 119 | struct device_attribute *attr, |
| 120 | char *buf) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 121 | { |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 122 | struct pvr2_sysfs_ctl_item *cip; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 123 | long val; |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 124 | cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_min); |
| 125 | val = pvr2_ctrl_get_min(cip->cptr); |
| 126 | pvr2_sysfs_trace("pvr2_sysfs(%p) show_min(cid=%d) is %ld", |
| 127 | cip->chptr, cip->ctl_id, val); |
| 128 | return scnprintf(buf, PAGE_SIZE, "%ld\n", val); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 129 | } |
| 130 | |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 131 | static ssize_t show_max(struct device *class_dev, |
| 132 | struct device_attribute *attr, |
| 133 | char *buf) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 134 | { |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 135 | struct pvr2_sysfs_ctl_item *cip; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 136 | long val; |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 137 | cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_max); |
| 138 | val = pvr2_ctrl_get_max(cip->cptr); |
| 139 | pvr2_sysfs_trace("pvr2_sysfs(%p) show_max(cid=%d) is %ld", |
| 140 | cip->chptr, cip->ctl_id, val); |
| 141 | return scnprintf(buf, PAGE_SIZE, "%ld\n", val); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 142 | } |
| 143 | |
Mike Isely | 0b7c2c9 | 2008-08-31 20:57:54 -0300 | [diff] [blame] | 144 | static ssize_t show_def(struct device *class_dev, |
| 145 | struct device_attribute *attr, |
| 146 | char *buf) |
| 147 | { |
| 148 | struct pvr2_sysfs_ctl_item *cip; |
| 149 | int val; |
| 150 | int ret; |
Mike Isely | 7bf56f9 | 2009-04-01 01:51:53 -0300 | [diff] [blame] | 151 | unsigned int cnt = 0; |
Mike Isely | 0b7c2c9 | 2008-08-31 20:57:54 -0300 | [diff] [blame] | 152 | cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_def); |
| 153 | ret = pvr2_ctrl_get_def(cip->cptr, &val); |
Mike Isely | 7bf56f9 | 2009-04-01 01:51:53 -0300 | [diff] [blame] | 154 | if (ret < 0) return ret; |
| 155 | ret = pvr2_ctrl_value_to_sym(cip->cptr, ~0, val, |
| 156 | buf, PAGE_SIZE - 1, &cnt); |
| 157 | pvr2_sysfs_trace("pvr2_sysfs(%p) show_def(cid=%d) is %.*s (%d)", |
| 158 | cip->chptr, cip->ctl_id, cnt, buf, val); |
| 159 | buf[cnt] = '\n'; |
| 160 | return cnt + 1; |
Mike Isely | 0b7c2c9 | 2008-08-31 20:57:54 -0300 | [diff] [blame] | 161 | } |
| 162 | |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 163 | static ssize_t show_val_norm(struct device *class_dev, |
| 164 | struct device_attribute *attr, |
| 165 | char *buf) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 166 | { |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 167 | struct pvr2_sysfs_ctl_item *cip; |
| 168 | int val; |
| 169 | int ret; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 170 | unsigned int cnt = 0; |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 171 | cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_val); |
| 172 | ret = pvr2_ctrl_get_value(cip->cptr, &val); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 173 | if (ret < 0) return ret; |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 174 | ret = pvr2_ctrl_value_to_sym(cip->cptr, ~0, val, |
| 175 | buf, PAGE_SIZE - 1, &cnt); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 176 | pvr2_sysfs_trace("pvr2_sysfs(%p) show_val_norm(cid=%d) is %.*s (%d)", |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 177 | cip->chptr, cip->ctl_id, cnt, buf, val); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 178 | buf[cnt] = '\n'; |
| 179 | return cnt+1; |
| 180 | } |
| 181 | |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 182 | static ssize_t show_val_custom(struct device *class_dev, |
| 183 | struct device_attribute *attr, |
| 184 | char *buf) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 185 | { |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 186 | struct pvr2_sysfs_ctl_item *cip; |
| 187 | int val; |
| 188 | int ret; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 189 | unsigned int cnt = 0; |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 190 | cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_custom); |
| 191 | ret = pvr2_ctrl_get_value(cip->cptr, &val); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 192 | if (ret < 0) return ret; |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 193 | ret = pvr2_ctrl_custom_value_to_sym(cip->cptr, ~0, val, |
| 194 | buf, PAGE_SIZE - 1, &cnt); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 195 | pvr2_sysfs_trace("pvr2_sysfs(%p) show_val_custom(cid=%d) is %.*s (%d)", |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 196 | cip->chptr, cip->ctl_id, cnt, buf, val); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 197 | buf[cnt] = '\n'; |
| 198 | return cnt+1; |
| 199 | } |
| 200 | |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 201 | static ssize_t show_enum(struct device *class_dev, |
| 202 | struct device_attribute *attr, |
| 203 | char *buf) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 204 | { |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 205 | struct pvr2_sysfs_ctl_item *cip; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 206 | long val; |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 207 | unsigned int bcnt, ccnt, ecnt; |
| 208 | cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_enum); |
| 209 | ecnt = pvr2_ctrl_get_cnt(cip->cptr); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 210 | bcnt = 0; |
| 211 | for (val = 0; val < ecnt; val++) { |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 212 | pvr2_ctrl_get_valname(cip->cptr, val, buf + bcnt, |
| 213 | PAGE_SIZE - bcnt, &ccnt); |
Mike Isely | 4588677 | 2006-06-25 20:04:13 -0300 | [diff] [blame] | 214 | if (!ccnt) continue; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 215 | bcnt += ccnt; |
| 216 | if (bcnt >= PAGE_SIZE) break; |
| 217 | buf[bcnt] = '\n'; |
| 218 | bcnt++; |
| 219 | } |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 220 | pvr2_sysfs_trace("pvr2_sysfs(%p) show_enum(cid=%d)", |
| 221 | cip->chptr, cip->ctl_id); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 222 | return bcnt; |
| 223 | } |
| 224 | |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 225 | static ssize_t show_bits(struct device *class_dev, |
| 226 | struct device_attribute *attr, |
| 227 | char *buf) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 228 | { |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 229 | struct pvr2_sysfs_ctl_item *cip; |
| 230 | int valid_bits, msk; |
| 231 | unsigned int bcnt, ccnt; |
| 232 | cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_bits); |
| 233 | valid_bits = pvr2_ctrl_get_mask(cip->cptr); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 234 | bcnt = 0; |
| 235 | for (msk = 1; valid_bits; msk <<= 1) { |
| 236 | if (!(msk & valid_bits)) continue; |
| 237 | valid_bits &= ~msk; |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 238 | pvr2_ctrl_get_valname(cip->cptr, msk, buf + bcnt, |
| 239 | PAGE_SIZE - bcnt, &ccnt); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 240 | bcnt += ccnt; |
| 241 | if (bcnt >= PAGE_SIZE) break; |
| 242 | buf[bcnt] = '\n'; |
| 243 | bcnt++; |
| 244 | } |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 245 | pvr2_sysfs_trace("pvr2_sysfs(%p) show_bits(cid=%d)", |
| 246 | cip->chptr, cip->ctl_id); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 247 | return bcnt; |
| 248 | } |
| 249 | |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 250 | static int store_val_any(struct pvr2_sysfs_ctl_item *cip, int customfl, |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 251 | const char *buf,unsigned int count) |
| 252 | { |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 253 | int ret; |
| 254 | int mask,val; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 255 | if (customfl) { |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 256 | ret = pvr2_ctrl_custom_sym_to_value(cip->cptr, buf, count, |
| 257 | &mask, &val); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 258 | } else { |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 259 | ret = pvr2_ctrl_sym_to_value(cip->cptr, buf, count, |
| 260 | &mask, &val); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 261 | } |
| 262 | if (ret < 0) return ret; |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 263 | ret = pvr2_ctrl_set_mask_value(cip->cptr, mask, val); |
| 264 | pvr2_hdw_commit_ctl(cip->chptr->channel.hdw); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 265 | return ret; |
| 266 | } |
| 267 | |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 268 | static ssize_t store_val_norm(struct device *class_dev, |
| 269 | struct device_attribute *attr, |
| 270 | const char *buf, size_t count) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 271 | { |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 272 | struct pvr2_sysfs_ctl_item *cip; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 273 | int ret; |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 274 | cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_val); |
Mike Isely | bedbbf8 | 2008-04-22 14:45:38 -0300 | [diff] [blame] | 275 | pvr2_sysfs_trace("pvr2_sysfs(%p) store_val_norm(cid=%d) \"%.*s\"", |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 276 | cip->chptr, cip->ctl_id, (int)count, buf); |
| 277 | ret = store_val_any(cip, 0, buf, count); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 278 | if (!ret) ret = count; |
| 279 | return ret; |
| 280 | } |
| 281 | |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 282 | static ssize_t store_val_custom(struct device *class_dev, |
| 283 | struct device_attribute *attr, |
| 284 | const char *buf, size_t count) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 285 | { |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 286 | struct pvr2_sysfs_ctl_item *cip; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 287 | int ret; |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 288 | cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_custom); |
Mike Isely | bedbbf8 | 2008-04-22 14:45:38 -0300 | [diff] [blame] | 289 | pvr2_sysfs_trace("pvr2_sysfs(%p) store_val_custom(cid=%d) \"%.*s\"", |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 290 | cip->chptr, cip->ctl_id, (int)count, buf); |
| 291 | ret = store_val_any(cip, 1, buf, count); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 292 | if (!ret) ret = count; |
| 293 | return ret; |
| 294 | } |
| 295 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 296 | static void pvr2_sysfs_add_control(struct pvr2_sysfs *sfp,int ctl_id) |
| 297 | { |
| 298 | struct pvr2_sysfs_ctl_item *cip; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 299 | struct pvr2_ctrl *cptr; |
| 300 | unsigned int cnt,acnt; |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 301 | int ret; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 302 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 303 | cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,ctl_id); |
| 304 | if (!cptr) return; |
| 305 | |
Mike Isely | ca545f7 | 2007-01-20 00:37:11 -0300 | [diff] [blame] | 306 | cip = kzalloc(sizeof(*cip),GFP_KERNEL); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 307 | if (!cip) return; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 308 | pvr2_sysfs_trace("Creating pvr2_sysfs_ctl_item id=%p",cip); |
| 309 | |
| 310 | cip->cptr = cptr; |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 311 | cip->ctl_id = ctl_id; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 312 | |
| 313 | cip->chptr = sfp; |
Mike Isely | a0fd1cb | 2006-06-30 11:35:28 -0300 | [diff] [blame] | 314 | cip->item_next = NULL; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 315 | if (sfp->item_last) { |
| 316 | sfp->item_last->item_next = cip; |
| 317 | } else { |
| 318 | sfp->item_first = cip; |
| 319 | } |
| 320 | sfp->item_last = cip; |
| 321 | |
Mike Isely | 19a0a29 | 2011-02-13 17:57:19 -0300 | [diff] [blame] | 322 | sysfs_attr_init(&cip->attr_name.attr); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 323 | cip->attr_name.attr.name = "name"; |
| 324 | cip->attr_name.attr.mode = S_IRUGO; |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 325 | cip->attr_name.show = show_name; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 326 | |
Mike Isely | 19a0a29 | 2011-02-13 17:57:19 -0300 | [diff] [blame] | 327 | sysfs_attr_init(&cip->attr_type.attr); |
Mike Isely | 3321396 | 2006-06-25 20:04:40 -0300 | [diff] [blame] | 328 | cip->attr_type.attr.name = "type"; |
| 329 | cip->attr_type.attr.mode = S_IRUGO; |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 330 | cip->attr_type.show = show_type; |
Mike Isely | 3321396 | 2006-06-25 20:04:40 -0300 | [diff] [blame] | 331 | |
Mike Isely | 19a0a29 | 2011-02-13 17:57:19 -0300 | [diff] [blame] | 332 | sysfs_attr_init(&cip->attr_min.attr); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 333 | cip->attr_min.attr.name = "min_val"; |
| 334 | cip->attr_min.attr.mode = S_IRUGO; |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 335 | cip->attr_min.show = show_min; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 336 | |
Mike Isely | 19a0a29 | 2011-02-13 17:57:19 -0300 | [diff] [blame] | 337 | sysfs_attr_init(&cip->attr_max.attr); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 338 | cip->attr_max.attr.name = "max_val"; |
| 339 | cip->attr_max.attr.mode = S_IRUGO; |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 340 | cip->attr_max.show = show_max; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 341 | |
Mike Isely | 19a0a29 | 2011-02-13 17:57:19 -0300 | [diff] [blame] | 342 | sysfs_attr_init(&cip->attr_def.attr); |
Mike Isely | 0b7c2c9 | 2008-08-31 20:57:54 -0300 | [diff] [blame] | 343 | cip->attr_def.attr.name = "def_val"; |
| 344 | cip->attr_def.attr.mode = S_IRUGO; |
| 345 | cip->attr_def.show = show_def; |
| 346 | |
Mike Isely | 19a0a29 | 2011-02-13 17:57:19 -0300 | [diff] [blame] | 347 | sysfs_attr_init(&cip->attr_val.attr); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 348 | cip->attr_val.attr.name = "cur_val"; |
| 349 | cip->attr_val.attr.mode = S_IRUGO; |
| 350 | |
Mike Isely | 19a0a29 | 2011-02-13 17:57:19 -0300 | [diff] [blame] | 351 | sysfs_attr_init(&cip->attr_custom.attr); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 352 | cip->attr_custom.attr.name = "custom_val"; |
| 353 | cip->attr_custom.attr.mode = S_IRUGO; |
| 354 | |
Mike Isely | 19a0a29 | 2011-02-13 17:57:19 -0300 | [diff] [blame] | 355 | sysfs_attr_init(&cip->attr_enum.attr); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 356 | cip->attr_enum.attr.name = "enum_val"; |
| 357 | cip->attr_enum.attr.mode = S_IRUGO; |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 358 | cip->attr_enum.show = show_enum; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 359 | |
Mike Isely | 19a0a29 | 2011-02-13 17:57:19 -0300 | [diff] [blame] | 360 | sysfs_attr_init(&cip->attr_bits.attr); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 361 | cip->attr_bits.attr.name = "bit_val"; |
| 362 | cip->attr_bits.attr.mode = S_IRUGO; |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 363 | cip->attr_bits.show = show_bits; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 364 | |
| 365 | if (pvr2_ctrl_is_writable(cptr)) { |
| 366 | cip->attr_val.attr.mode |= S_IWUSR|S_IWGRP; |
| 367 | cip->attr_custom.attr.mode |= S_IWUSR|S_IWGRP; |
| 368 | } |
| 369 | |
| 370 | acnt = 0; |
| 371 | cip->attr_gen[acnt++] = &cip->attr_name.attr; |
Mike Isely | 3321396 | 2006-06-25 20:04:40 -0300 | [diff] [blame] | 372 | cip->attr_gen[acnt++] = &cip->attr_type.attr; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 373 | cip->attr_gen[acnt++] = &cip->attr_val.attr; |
Mike Isely | 0b7c2c9 | 2008-08-31 20:57:54 -0300 | [diff] [blame] | 374 | cip->attr_gen[acnt++] = &cip->attr_def.attr; |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 375 | cip->attr_val.show = show_val_norm; |
| 376 | cip->attr_val.store = store_val_norm; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 377 | if (pvr2_ctrl_has_custom_symbols(cptr)) { |
| 378 | cip->attr_gen[acnt++] = &cip->attr_custom.attr; |
Mike Isely | f90fe7a | 2008-05-26 06:00:47 -0300 | [diff] [blame] | 379 | cip->attr_custom.show = show_val_custom; |
| 380 | cip->attr_custom.store = store_val_custom; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 381 | } |
| 382 | switch (pvr2_ctrl_get_type(cptr)) { |
| 383 | case pvr2_ctl_enum: |
| 384 | // Control is an enumeration |
| 385 | cip->attr_gen[acnt++] = &cip->attr_enum.attr; |
| 386 | break; |
| 387 | case pvr2_ctl_int: |
| 388 | // Control is an integer |
| 389 | cip->attr_gen[acnt++] = &cip->attr_min.attr; |
| 390 | cip->attr_gen[acnt++] = &cip->attr_max.attr; |
| 391 | break; |
| 392 | case pvr2_ctl_bitmask: |
| 393 | // Control is an bitmask |
| 394 | cip->attr_gen[acnt++] = &cip->attr_bits.attr; |
| 395 | break; |
| 396 | default: break; |
| 397 | } |
| 398 | |
| 399 | cnt = scnprintf(cip->name,sizeof(cip->name)-1,"ctl_%s", |
| 400 | pvr2_ctrl_get_name(cptr)); |
| 401 | cip->name[cnt] = 0; |
| 402 | cip->grp.name = cip->name; |
| 403 | cip->grp.attrs = cip->attr_gen; |
| 404 | |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 405 | ret = sysfs_create_group(&sfp->class_dev->kobj,&cip->grp); |
| 406 | if (ret) { |
Mike Isely | 49844c2 | 2008-04-09 05:44:57 -0300 | [diff] [blame] | 407 | pvr2_trace(PVR2_TRACE_ERROR_LEGS, |
| 408 | "sysfs_create_group error: %d", |
| 409 | ret); |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 410 | return; |
| 411 | } |
| 412 | cip->created_ok = !0; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC |
Trent Piepho | c726b65 | 2007-10-08 19:05:28 -0300 | [diff] [blame] | 416 | static ssize_t debuginfo_show(struct device *, struct device_attribute *, |
| 417 | char *); |
| 418 | static ssize_t debugcmd_show(struct device *, struct device_attribute *, |
| 419 | char *); |
| 420 | static ssize_t debugcmd_store(struct device *, struct device_attribute *, |
| 421 | const char *, size_t count); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 422 | |
| 423 | static void pvr2_sysfs_add_debugifc(struct pvr2_sysfs *sfp) |
| 424 | { |
| 425 | struct pvr2_sysfs_debugifc *dip; |
Michael Krufky | 3117bee | 2006-07-19 13:23:38 -0300 | [diff] [blame] | 426 | int ret; |
| 427 | |
Mike Isely | ca545f7 | 2007-01-20 00:37:11 -0300 | [diff] [blame] | 428 | dip = kzalloc(sizeof(*dip),GFP_KERNEL); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 429 | if (!dip) return; |
Wolfram Sang | 1276551 | 2010-04-06 14:34:52 -0700 | [diff] [blame] | 430 | sysfs_attr_init(&dip->attr_debugcmd.attr); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 431 | dip->attr_debugcmd.attr.name = "debugcmd"; |
| 432 | dip->attr_debugcmd.attr.mode = S_IRUGO|S_IWUSR|S_IWGRP; |
| 433 | dip->attr_debugcmd.show = debugcmd_show; |
| 434 | dip->attr_debugcmd.store = debugcmd_store; |
Wolfram Sang | 1276551 | 2010-04-06 14:34:52 -0700 | [diff] [blame] | 435 | sysfs_attr_init(&dip->attr_debuginfo.attr); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 436 | dip->attr_debuginfo.attr.name = "debuginfo"; |
| 437 | dip->attr_debuginfo.attr.mode = S_IRUGO; |
| 438 | dip->attr_debuginfo.show = debuginfo_show; |
| 439 | sfp->debugifc = dip; |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 440 | ret = device_create_file(sfp->class_dev,&dip->attr_debugcmd); |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 441 | if (ret < 0) { |
Mike Isely | 49844c2 | 2008-04-09 05:44:57 -0300 | [diff] [blame] | 442 | pvr2_trace(PVR2_TRACE_ERROR_LEGS, |
| 443 | "device_create_file error: %d", |
| 444 | ret); |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 445 | } else { |
| 446 | dip->debugcmd_created_ok = !0; |
| 447 | } |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 448 | ret = device_create_file(sfp->class_dev,&dip->attr_debuginfo); |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 449 | if (ret < 0) { |
Mike Isely | 49844c2 | 2008-04-09 05:44:57 -0300 | [diff] [blame] | 450 | pvr2_trace(PVR2_TRACE_ERROR_LEGS, |
| 451 | "device_create_file error: %d", |
| 452 | ret); |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 453 | } else { |
| 454 | dip->debuginfo_created_ok = !0; |
| 455 | } |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | |
| 459 | static void pvr2_sysfs_tear_down_debugifc(struct pvr2_sysfs *sfp) |
| 460 | { |
| 461 | if (!sfp->debugifc) return; |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 462 | if (sfp->debugifc->debuginfo_created_ok) { |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 463 | device_remove_file(sfp->class_dev, |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 464 | &sfp->debugifc->attr_debuginfo); |
| 465 | } |
| 466 | if (sfp->debugifc->debugcmd_created_ok) { |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 467 | device_remove_file(sfp->class_dev, |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 468 | &sfp->debugifc->attr_debugcmd); |
| 469 | } |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 470 | kfree(sfp->debugifc); |
Mike Isely | a0fd1cb | 2006-06-30 11:35:28 -0300 | [diff] [blame] | 471 | sfp->debugifc = NULL; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 472 | } |
| 473 | #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */ |
| 474 | |
| 475 | |
| 476 | static void pvr2_sysfs_add_controls(struct pvr2_sysfs *sfp) |
| 477 | { |
| 478 | unsigned int idx,cnt; |
| 479 | cnt = pvr2_hdw_get_ctrl_count(sfp->channel.hdw); |
| 480 | for (idx = 0; idx < cnt; idx++) { |
| 481 | pvr2_sysfs_add_control(sfp,idx); |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | |
| 486 | static void pvr2_sysfs_tear_down_controls(struct pvr2_sysfs *sfp) |
| 487 | { |
| 488 | struct pvr2_sysfs_ctl_item *cip1,*cip2; |
| 489 | for (cip1 = sfp->item_first; cip1; cip1 = cip2) { |
| 490 | cip2 = cip1->item_next; |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 491 | if (cip1->created_ok) { |
| 492 | sysfs_remove_group(&sfp->class_dev->kobj,&cip1->grp); |
| 493 | } |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 494 | pvr2_sysfs_trace("Destroying pvr2_sysfs_ctl_item id=%p",cip1); |
| 495 | kfree(cip1); |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | |
| 500 | static void pvr2_sysfs_class_release(struct class *class) |
| 501 | { |
| 502 | struct pvr2_sysfs_class *clp; |
| 503 | clp = container_of(class,struct pvr2_sysfs_class,class); |
| 504 | pvr2_sysfs_trace("Destroying pvr2_sysfs_class id=%p",clp); |
| 505 | kfree(clp); |
| 506 | } |
| 507 | |
| 508 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 509 | static void pvr2_sysfs_release(struct device *class_dev) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 510 | { |
| 511 | pvr2_sysfs_trace("Releasing class_dev id=%p",class_dev); |
| 512 | kfree(class_dev); |
| 513 | } |
| 514 | |
| 515 | |
| 516 | static void class_dev_destroy(struct pvr2_sysfs *sfp) |
| 517 | { |
Mike Isely | 28c4a5e | 2010-05-15 00:23:46 -0300 | [diff] [blame] | 518 | struct device *dev; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 519 | if (!sfp->class_dev) return; |
| 520 | #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC |
| 521 | pvr2_sysfs_tear_down_debugifc(sfp); |
| 522 | #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */ |
| 523 | pvr2_sysfs_tear_down_controls(sfp); |
Mike Isely | 78a4710 | 2007-11-26 01:58:20 -0300 | [diff] [blame] | 524 | if (sfp->hdw_desc_created_ok) { |
| 525 | device_remove_file(sfp->class_dev, |
| 526 | &sfp->attr_hdw_desc); |
| 527 | } |
| 528 | if (sfp->hdw_name_created_ok) { |
| 529 | device_remove_file(sfp->class_dev, |
| 530 | &sfp->attr_hdw_name); |
| 531 | } |
Mike Isely | 31a1854 | 2007-04-08 01:11:47 -0300 | [diff] [blame] | 532 | if (sfp->bus_info_created_ok) { |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 533 | device_remove_file(sfp->class_dev, |
Mike Isely | 31a1854 | 2007-04-08 01:11:47 -0300 | [diff] [blame] | 534 | &sfp->attr_bus_info); |
| 535 | } |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 536 | if (sfp->v4l_minor_number_created_ok) { |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 537 | device_remove_file(sfp->class_dev, |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 538 | &sfp->attr_v4l_minor_number); |
| 539 | } |
Pantelis Koukousoulas | 2fdf3d9 | 2006-12-27 23:07:58 -0300 | [diff] [blame] | 540 | if (sfp->v4l_radio_minor_number_created_ok) { |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 541 | device_remove_file(sfp->class_dev, |
Pantelis Koukousoulas | 2fdf3d9 | 2006-12-27 23:07:58 -0300 | [diff] [blame] | 542 | &sfp->attr_v4l_radio_minor_number); |
| 543 | } |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 544 | if (sfp->unit_number_created_ok) { |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 545 | device_remove_file(sfp->class_dev, |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 546 | &sfp->attr_unit_number); |
| 547 | } |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 548 | pvr2_sysfs_trace("Destroying class_dev id=%p",sfp->class_dev); |
Greg Kroah-Hartman | 79510cd | 2009-04-30 14:43:31 -0700 | [diff] [blame] | 549 | dev_set_drvdata(sfp->class_dev, NULL); |
Mike Isely | 28c4a5e | 2010-05-15 00:23:46 -0300 | [diff] [blame] | 550 | dev = sfp->class_dev->parent; |
| 551 | sfp->class_dev->parent = NULL; |
| 552 | put_device(dev); |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 553 | device_unregister(sfp->class_dev); |
Mike Isely | a0fd1cb | 2006-06-30 11:35:28 -0300 | [diff] [blame] | 554 | sfp->class_dev = NULL; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 558 | static ssize_t v4l_minor_number_show(struct device *class_dev, |
| 559 | struct device_attribute *attr, char *buf) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 560 | { |
| 561 | struct pvr2_sysfs *sfp; |
Greg Kroah-Hartman | 79510cd | 2009-04-30 14:43:31 -0700 | [diff] [blame] | 562 | sfp = dev_get_drvdata(class_dev); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 563 | if (!sfp) return -EINVAL; |
| 564 | return scnprintf(buf,PAGE_SIZE,"%d\n", |
Mike Isely | fd5a75f | 2006-12-27 23:11:22 -0300 | [diff] [blame] | 565 | pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw, |
Mike Isely | 8079384 | 2006-12-27 23:12:28 -0300 | [diff] [blame] | 566 | pvr2_v4l_type_video)); |
Pantelis Koukousoulas | 2fdf3d9 | 2006-12-27 23:07:58 -0300 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 570 | static ssize_t bus_info_show(struct device *class_dev, |
| 571 | struct device_attribute *attr, char *buf) |
Mike Isely | 31a1854 | 2007-04-08 01:11:47 -0300 | [diff] [blame] | 572 | { |
| 573 | struct pvr2_sysfs *sfp; |
Greg Kroah-Hartman | 79510cd | 2009-04-30 14:43:31 -0700 | [diff] [blame] | 574 | sfp = dev_get_drvdata(class_dev); |
Mike Isely | 31a1854 | 2007-04-08 01:11:47 -0300 | [diff] [blame] | 575 | if (!sfp) return -EINVAL; |
| 576 | return scnprintf(buf,PAGE_SIZE,"%s\n", |
| 577 | pvr2_hdw_get_bus_info(sfp->channel.hdw)); |
| 578 | } |
| 579 | |
| 580 | |
Mike Isely | 78a4710 | 2007-11-26 01:58:20 -0300 | [diff] [blame] | 581 | static ssize_t hdw_name_show(struct device *class_dev, |
| 582 | struct device_attribute *attr, char *buf) |
| 583 | { |
| 584 | struct pvr2_sysfs *sfp; |
Greg Kroah-Hartman | 79510cd | 2009-04-30 14:43:31 -0700 | [diff] [blame] | 585 | sfp = dev_get_drvdata(class_dev); |
Mike Isely | 78a4710 | 2007-11-26 01:58:20 -0300 | [diff] [blame] | 586 | if (!sfp) return -EINVAL; |
| 587 | return scnprintf(buf,PAGE_SIZE,"%s\n", |
| 588 | pvr2_hdw_get_type(sfp->channel.hdw)); |
| 589 | } |
| 590 | |
| 591 | |
| 592 | static ssize_t hdw_desc_show(struct device *class_dev, |
| 593 | struct device_attribute *attr, char *buf) |
| 594 | { |
| 595 | struct pvr2_sysfs *sfp; |
Greg Kroah-Hartman | 79510cd | 2009-04-30 14:43:31 -0700 | [diff] [blame] | 596 | sfp = dev_get_drvdata(class_dev); |
Mike Isely | 78a4710 | 2007-11-26 01:58:20 -0300 | [diff] [blame] | 597 | if (!sfp) return -EINVAL; |
| 598 | return scnprintf(buf,PAGE_SIZE,"%s\n", |
| 599 | pvr2_hdw_get_desc(sfp->channel.hdw)); |
| 600 | } |
| 601 | |
| 602 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 603 | static ssize_t v4l_radio_minor_number_show(struct device *class_dev, |
| 604 | struct device_attribute *attr, |
Pantelis Koukousoulas | 2fdf3d9 | 2006-12-27 23:07:58 -0300 | [diff] [blame] | 605 | char *buf) |
| 606 | { |
| 607 | struct pvr2_sysfs *sfp; |
Greg Kroah-Hartman | 79510cd | 2009-04-30 14:43:31 -0700 | [diff] [blame] | 608 | sfp = dev_get_drvdata(class_dev); |
Pantelis Koukousoulas | 2fdf3d9 | 2006-12-27 23:07:58 -0300 | [diff] [blame] | 609 | if (!sfp) return -EINVAL; |
| 610 | return scnprintf(buf,PAGE_SIZE,"%d\n", |
Mike Isely | fd5a75f | 2006-12-27 23:11:22 -0300 | [diff] [blame] | 611 | pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw, |
Mike Isely | 8079384 | 2006-12-27 23:12:28 -0300 | [diff] [blame] | 612 | pvr2_v4l_type_radio)); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 616 | static ssize_t unit_number_show(struct device *class_dev, |
| 617 | struct device_attribute *attr, char *buf) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 618 | { |
| 619 | struct pvr2_sysfs *sfp; |
Greg Kroah-Hartman | 79510cd | 2009-04-30 14:43:31 -0700 | [diff] [blame] | 620 | sfp = dev_get_drvdata(class_dev); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 621 | if (!sfp) return -EINVAL; |
| 622 | return scnprintf(buf,PAGE_SIZE,"%d\n", |
| 623 | pvr2_hdw_get_unit_number(sfp->channel.hdw)); |
| 624 | } |
| 625 | |
| 626 | |
| 627 | static void class_dev_create(struct pvr2_sysfs *sfp, |
| 628 | struct pvr2_sysfs_class *class_ptr) |
| 629 | { |
| 630 | struct usb_device *usb_dev; |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 631 | struct device *class_dev; |
Michael Krufky | 3117bee | 2006-07-19 13:23:38 -0300 | [diff] [blame] | 632 | int ret; |
| 633 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 634 | usb_dev = pvr2_hdw_get_dev(sfp->channel.hdw); |
| 635 | if (!usb_dev) return; |
Mike Isely | ca545f7 | 2007-01-20 00:37:11 -0300 | [diff] [blame] | 636 | class_dev = kzalloc(sizeof(*class_dev),GFP_KERNEL); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 637 | if (!class_dev) return; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 638 | |
| 639 | pvr2_sysfs_trace("Creating class_dev id=%p",class_dev); |
| 640 | |
| 641 | class_dev->class = &class_ptr->class; |
Mike Isely | 28c4a5e | 2010-05-15 00:23:46 -0300 | [diff] [blame] | 642 | |
Mike Isely | 730e92c | 2009-01-14 04:24:20 -0300 | [diff] [blame] | 643 | dev_set_name(class_dev, "%s", |
| 644 | pvr2_hdw_get_device_identifier(sfp->channel.hdw)); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 645 | |
Mike Isely | 28c4a5e | 2010-05-15 00:23:46 -0300 | [diff] [blame] | 646 | class_dev->parent = get_device(&usb_dev->dev); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 647 | |
| 648 | sfp->class_dev = class_dev; |
Greg Kroah-Hartman | 79510cd | 2009-04-30 14:43:31 -0700 | [diff] [blame] | 649 | dev_set_drvdata(class_dev, sfp); |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 650 | ret = device_register(class_dev); |
Michael Krufky | 3117bee | 2006-07-19 13:23:38 -0300 | [diff] [blame] | 651 | if (ret) { |
Mike Isely | 49844c2 | 2008-04-09 05:44:57 -0300 | [diff] [blame] | 652 | pvr2_trace(PVR2_TRACE_ERROR_LEGS, |
| 653 | "device_register failed"); |
Vasiliy Kulikov | a519d70e | 2010-11-19 15:41:49 -0300 | [diff] [blame] | 654 | put_device(class_dev); |
Michael Krufky | 3117bee | 2006-07-19 13:23:38 -0300 | [diff] [blame] | 655 | return; |
| 656 | } |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 657 | |
Wolfram Sang | 1276551 | 2010-04-06 14:34:52 -0700 | [diff] [blame] | 658 | sysfs_attr_init(&sfp->attr_v4l_minor_number.attr); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 659 | sfp->attr_v4l_minor_number.attr.name = "v4l_minor_number"; |
| 660 | sfp->attr_v4l_minor_number.attr.mode = S_IRUGO; |
| 661 | sfp->attr_v4l_minor_number.show = v4l_minor_number_show; |
Mike Isely | a0fd1cb | 2006-06-30 11:35:28 -0300 | [diff] [blame] | 662 | sfp->attr_v4l_minor_number.store = NULL; |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 663 | ret = device_create_file(sfp->class_dev, |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 664 | &sfp->attr_v4l_minor_number); |
| 665 | if (ret < 0) { |
Mike Isely | 49844c2 | 2008-04-09 05:44:57 -0300 | [diff] [blame] | 666 | pvr2_trace(PVR2_TRACE_ERROR_LEGS, |
| 667 | "device_create_file error: %d", |
| 668 | ret); |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 669 | } else { |
| 670 | sfp->v4l_minor_number_created_ok = !0; |
| 671 | } |
Michael Krufky | 3117bee | 2006-07-19 13:23:38 -0300 | [diff] [blame] | 672 | |
Wolfram Sang | 1276551 | 2010-04-06 14:34:52 -0700 | [diff] [blame] | 673 | sysfs_attr_init(&sfp->attr_v4l_radio_minor_number.attr); |
Pantelis Koukousoulas | 2fdf3d9 | 2006-12-27 23:07:58 -0300 | [diff] [blame] | 674 | sfp->attr_v4l_radio_minor_number.attr.name = "v4l_radio_minor_number"; |
| 675 | sfp->attr_v4l_radio_minor_number.attr.mode = S_IRUGO; |
| 676 | sfp->attr_v4l_radio_minor_number.show = v4l_radio_minor_number_show; |
| 677 | sfp->attr_v4l_radio_minor_number.store = NULL; |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 678 | ret = device_create_file(sfp->class_dev, |
Pantelis Koukousoulas | 2fdf3d9 | 2006-12-27 23:07:58 -0300 | [diff] [blame] | 679 | &sfp->attr_v4l_radio_minor_number); |
| 680 | if (ret < 0) { |
Mike Isely | 49844c2 | 2008-04-09 05:44:57 -0300 | [diff] [blame] | 681 | pvr2_trace(PVR2_TRACE_ERROR_LEGS, |
| 682 | "device_create_file error: %d", |
| 683 | ret); |
Pantelis Koukousoulas | 2fdf3d9 | 2006-12-27 23:07:58 -0300 | [diff] [blame] | 684 | } else { |
| 685 | sfp->v4l_radio_minor_number_created_ok = !0; |
| 686 | } |
| 687 | |
Wolfram Sang | 1276551 | 2010-04-06 14:34:52 -0700 | [diff] [blame] | 688 | sysfs_attr_init(&sfp->attr_unit_number.attr); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 689 | sfp->attr_unit_number.attr.name = "unit_number"; |
| 690 | sfp->attr_unit_number.attr.mode = S_IRUGO; |
| 691 | sfp->attr_unit_number.show = unit_number_show; |
Mike Isely | a0fd1cb | 2006-06-30 11:35:28 -0300 | [diff] [blame] | 692 | sfp->attr_unit_number.store = NULL; |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 693 | ret = device_create_file(sfp->class_dev,&sfp->attr_unit_number); |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 694 | if (ret < 0) { |
Mike Isely | 49844c2 | 2008-04-09 05:44:57 -0300 | [diff] [blame] | 695 | pvr2_trace(PVR2_TRACE_ERROR_LEGS, |
| 696 | "device_create_file error: %d", |
| 697 | ret); |
Mike Isely | 08d4180 | 2006-07-22 21:26:30 -0300 | [diff] [blame] | 698 | } else { |
| 699 | sfp->unit_number_created_ok = !0; |
| 700 | } |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 701 | |
Wolfram Sang | 1276551 | 2010-04-06 14:34:52 -0700 | [diff] [blame] | 702 | sysfs_attr_init(&sfp->attr_bus_info.attr); |
Mike Isely | 31a1854 | 2007-04-08 01:11:47 -0300 | [diff] [blame] | 703 | sfp->attr_bus_info.attr.name = "bus_info_str"; |
| 704 | sfp->attr_bus_info.attr.mode = S_IRUGO; |
| 705 | sfp->attr_bus_info.show = bus_info_show; |
| 706 | sfp->attr_bus_info.store = NULL; |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 707 | ret = device_create_file(sfp->class_dev, |
Mike Isely | 31a1854 | 2007-04-08 01:11:47 -0300 | [diff] [blame] | 708 | &sfp->attr_bus_info); |
| 709 | if (ret < 0) { |
Mike Isely | 49844c2 | 2008-04-09 05:44:57 -0300 | [diff] [blame] | 710 | pvr2_trace(PVR2_TRACE_ERROR_LEGS, |
| 711 | "device_create_file error: %d", |
| 712 | ret); |
Mike Isely | 31a1854 | 2007-04-08 01:11:47 -0300 | [diff] [blame] | 713 | } else { |
| 714 | sfp->bus_info_created_ok = !0; |
| 715 | } |
| 716 | |
Wolfram Sang | 1276551 | 2010-04-06 14:34:52 -0700 | [diff] [blame] | 717 | sysfs_attr_init(&sfp->attr_hdw_name.attr); |
Mike Isely | 78a4710 | 2007-11-26 01:58:20 -0300 | [diff] [blame] | 718 | sfp->attr_hdw_name.attr.name = "device_hardware_type"; |
| 719 | sfp->attr_hdw_name.attr.mode = S_IRUGO; |
| 720 | sfp->attr_hdw_name.show = hdw_name_show; |
| 721 | sfp->attr_hdw_name.store = NULL; |
| 722 | ret = device_create_file(sfp->class_dev, |
| 723 | &sfp->attr_hdw_name); |
| 724 | if (ret < 0) { |
Mike Isely | 49844c2 | 2008-04-09 05:44:57 -0300 | [diff] [blame] | 725 | pvr2_trace(PVR2_TRACE_ERROR_LEGS, |
| 726 | "device_create_file error: %d", |
| 727 | ret); |
Mike Isely | 78a4710 | 2007-11-26 01:58:20 -0300 | [diff] [blame] | 728 | } else { |
| 729 | sfp->hdw_name_created_ok = !0; |
| 730 | } |
| 731 | |
Wolfram Sang | 1276551 | 2010-04-06 14:34:52 -0700 | [diff] [blame] | 732 | sysfs_attr_init(&sfp->attr_hdw_desc.attr); |
Mike Isely | 78a4710 | 2007-11-26 01:58:20 -0300 | [diff] [blame] | 733 | sfp->attr_hdw_desc.attr.name = "device_hardware_description"; |
| 734 | sfp->attr_hdw_desc.attr.mode = S_IRUGO; |
| 735 | sfp->attr_hdw_desc.show = hdw_desc_show; |
| 736 | sfp->attr_hdw_desc.store = NULL; |
| 737 | ret = device_create_file(sfp->class_dev, |
| 738 | &sfp->attr_hdw_desc); |
| 739 | if (ret < 0) { |
Mike Isely | 49844c2 | 2008-04-09 05:44:57 -0300 | [diff] [blame] | 740 | pvr2_trace(PVR2_TRACE_ERROR_LEGS, |
| 741 | "device_create_file error: %d", |
| 742 | ret); |
Mike Isely | 78a4710 | 2007-11-26 01:58:20 -0300 | [diff] [blame] | 743 | } else { |
| 744 | sfp->hdw_desc_created_ok = !0; |
| 745 | } |
| 746 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 747 | pvr2_sysfs_add_controls(sfp); |
| 748 | #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC |
| 749 | pvr2_sysfs_add_debugifc(sfp); |
| 750 | #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */ |
| 751 | } |
| 752 | |
| 753 | |
| 754 | static void pvr2_sysfs_internal_check(struct pvr2_channel *chp) |
| 755 | { |
| 756 | struct pvr2_sysfs *sfp; |
| 757 | sfp = container_of(chp,struct pvr2_sysfs,channel); |
| 758 | if (!sfp->channel.mc_head->disconnect_flag) return; |
| 759 | pvr2_trace(PVR2_TRACE_STRUCT,"Destroying pvr2_sysfs id=%p",sfp); |
| 760 | class_dev_destroy(sfp); |
| 761 | pvr2_channel_done(&sfp->channel); |
| 762 | kfree(sfp); |
| 763 | } |
| 764 | |
| 765 | |
| 766 | struct pvr2_sysfs *pvr2_sysfs_create(struct pvr2_context *mp, |
| 767 | struct pvr2_sysfs_class *class_ptr) |
| 768 | { |
| 769 | struct pvr2_sysfs *sfp; |
Mike Isely | ca545f7 | 2007-01-20 00:37:11 -0300 | [diff] [blame] | 770 | sfp = kzalloc(sizeof(*sfp),GFP_KERNEL); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 771 | if (!sfp) return sfp; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 772 | pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr2_sysfs id=%p",sfp); |
| 773 | pvr2_channel_init(&sfp->channel,mp); |
| 774 | sfp->channel.check_func = pvr2_sysfs_internal_check; |
| 775 | |
| 776 | class_dev_create(sfp,class_ptr); |
| 777 | return sfp; |
| 778 | } |
| 779 | |
| 780 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 781 | |
| 782 | struct pvr2_sysfs_class *pvr2_sysfs_class_create(void) |
| 783 | { |
| 784 | struct pvr2_sysfs_class *clp; |
Mike Isely | ca545f7 | 2007-01-20 00:37:11 -0300 | [diff] [blame] | 785 | clp = kzalloc(sizeof(*clp),GFP_KERNEL); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 786 | if (!clp) return clp; |
Mike Isely | 28c4a5e | 2010-05-15 00:23:46 -0300 | [diff] [blame] | 787 | pvr2_sysfs_trace("Creating and registering pvr2_sysfs_class id=%p", |
| 788 | clp); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 789 | clp->class.name = "pvrusb2"; |
| 790 | clp->class.class_release = pvr2_sysfs_class_release; |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 791 | clp->class.dev_release = pvr2_sysfs_release; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 792 | if (class_register(&clp->class)) { |
| 793 | pvr2_sysfs_trace( |
| 794 | "Registration failed for pvr2_sysfs_class id=%p",clp); |
| 795 | kfree(clp); |
Mike Isely | a0fd1cb | 2006-06-30 11:35:28 -0300 | [diff] [blame] | 796 | clp = NULL; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 797 | } |
| 798 | return clp; |
| 799 | } |
| 800 | |
| 801 | |
| 802 | void pvr2_sysfs_class_destroy(struct pvr2_sysfs_class *clp) |
| 803 | { |
Mike Isely | 28c4a5e | 2010-05-15 00:23:46 -0300 | [diff] [blame] | 804 | pvr2_sysfs_trace("Unregistering pvr2_sysfs_class id=%p", clp); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 805 | class_unregister(&clp->class); |
| 806 | } |
| 807 | |
| 808 | |
| 809 | #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC |
Trent Piepho | c726b65 | 2007-10-08 19:05:28 -0300 | [diff] [blame] | 810 | static ssize_t debuginfo_show(struct device *class_dev, |
| 811 | struct device_attribute *attr, char *buf) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 812 | { |
| 813 | struct pvr2_sysfs *sfp; |
Greg Kroah-Hartman | 79510cd | 2009-04-30 14:43:31 -0700 | [diff] [blame] | 814 | sfp = dev_get_drvdata(class_dev); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 815 | if (!sfp) return -EINVAL; |
| 816 | pvr2_hdw_trigger_module_log(sfp->channel.hdw); |
| 817 | return pvr2_debugifc_print_info(sfp->channel.hdw,buf,PAGE_SIZE); |
| 818 | } |
| 819 | |
| 820 | |
Trent Piepho | c726b65 | 2007-10-08 19:05:28 -0300 | [diff] [blame] | 821 | static ssize_t debugcmd_show(struct device *class_dev, |
| 822 | struct device_attribute *attr, char *buf) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 823 | { |
| 824 | struct pvr2_sysfs *sfp; |
Greg Kroah-Hartman | 79510cd | 2009-04-30 14:43:31 -0700 | [diff] [blame] | 825 | sfp = dev_get_drvdata(class_dev); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 826 | if (!sfp) return -EINVAL; |
| 827 | return pvr2_debugifc_print_status(sfp->channel.hdw,buf,PAGE_SIZE); |
| 828 | } |
| 829 | |
| 830 | |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 831 | static ssize_t debugcmd_store(struct device *class_dev, |
Trent Piepho | c726b65 | 2007-10-08 19:05:28 -0300 | [diff] [blame] | 832 | struct device_attribute *attr, |
Kay Sievers | 54bd5b6 | 2007-10-08 16:26:13 -0300 | [diff] [blame] | 833 | const char *buf, size_t count) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 834 | { |
| 835 | struct pvr2_sysfs *sfp; |
| 836 | int ret; |
| 837 | |
Greg Kroah-Hartman | 79510cd | 2009-04-30 14:43:31 -0700 | [diff] [blame] | 838 | sfp = dev_get_drvdata(class_dev); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 839 | if (!sfp) return -EINVAL; |
| 840 | |
| 841 | ret = pvr2_debugifc_docmd(sfp->channel.hdw,buf,count); |
| 842 | if (ret < 0) return ret; |
| 843 | return count; |
| 844 | } |
| 845 | #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */ |