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