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