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