Commit 08d41808362a3663c0856c9720ad940a61156fb5
Committed by
Mauro Carvalho Chehab
1 parent
d94fc9a08e
Exists in
master
and in
4 other branches
V4L/DVB (4373): Correctly handle sysfs error leg file removal in pvrusb2
Take note of which sysfs files / groups that the pvrusb2 successfully creates and only delete those specific items when tearing things down. (Previously we just blindly tore everything down every time.) Signed-off-by: Mike Isely <isely@pobox.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Showing 1 changed file with 50 additions and 12 deletions Inline Diff
drivers/media/video/pvrusb2/pvrusb2-sysfs.c
| 1 | /* | 1 | /* |
| 2 | * | 2 | * |
| 3 | * $Id$ | 3 | * $Id$ |
| 4 | * | 4 | * |
| 5 | * Copyright (C) 2005 Mike Isely <isely@pobox.com> | 5 | * Copyright (C) 2005 Mike Isely <isely@pobox.com> |
| 6 | * | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify | 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License | 9 | * the Free Software Foundation; either version 2 of the License |
| 10 | * | 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, | 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. | 14 | * GNU General Public License for more details. |
| 15 | * | 15 | * |
| 16 | * You should have received a copy of the GNU General Public License | 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software | 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | * | 19 | * |
| 20 | */ | 20 | */ |
| 21 | 21 | ||
| 22 | #include <linux/config.h> | 22 | #include <linux/config.h> |
| 23 | #include <linux/string.h> | 23 | #include <linux/string.h> |
| 24 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
| 25 | #include <asm/semaphore.h> | 25 | #include <asm/semaphore.h> |
| 26 | #include "pvrusb2-sysfs.h" | 26 | #include "pvrusb2-sysfs.h" |
| 27 | #include "pvrusb2-hdw.h" | 27 | #include "pvrusb2-hdw.h" |
| 28 | #include "pvrusb2-debug.h" | 28 | #include "pvrusb2-debug.h" |
| 29 | #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC | 29 | #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC |
| 30 | #include "pvrusb2-debugifc.h" | 30 | #include "pvrusb2-debugifc.h" |
| 31 | #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */ | 31 | #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */ |
| 32 | 32 | ||
| 33 | #define pvr2_sysfs_trace(...) pvr2_trace(PVR2_TRACE_SYSFS,__VA_ARGS__) | 33 | #define pvr2_sysfs_trace(...) pvr2_trace(PVR2_TRACE_SYSFS,__VA_ARGS__) |
| 34 | 34 | ||
| 35 | struct pvr2_sysfs { | 35 | struct pvr2_sysfs { |
| 36 | struct pvr2_channel channel; | 36 | struct pvr2_channel channel; |
| 37 | struct class_device *class_dev; | 37 | struct class_device *class_dev; |
| 38 | #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC | 38 | #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC |
| 39 | struct pvr2_sysfs_debugifc *debugifc; | 39 | struct pvr2_sysfs_debugifc *debugifc; |
| 40 | #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */ | 40 | #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */ |
| 41 | struct pvr2_sysfs_ctl_item *item_first; | 41 | struct pvr2_sysfs_ctl_item *item_first; |
| 42 | struct pvr2_sysfs_ctl_item *item_last; | 42 | struct pvr2_sysfs_ctl_item *item_last; |
| 43 | struct sysfs_ops kops; | 43 | struct sysfs_ops kops; |
| 44 | struct kobj_type ktype; | 44 | struct kobj_type ktype; |
| 45 | struct class_device_attribute attr_v4l_minor_number; | 45 | struct class_device_attribute attr_v4l_minor_number; |
| 46 | struct class_device_attribute attr_unit_number; | 46 | struct class_device_attribute attr_unit_number; |
| 47 | int v4l_minor_number_created_ok; | ||
| 48 | int unit_number_created_ok; | ||
| 47 | }; | 49 | }; |
| 48 | 50 | ||
| 49 | #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC | 51 | #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC |
| 50 | struct pvr2_sysfs_debugifc { | 52 | struct pvr2_sysfs_debugifc { |
| 51 | struct class_device_attribute attr_debugcmd; | 53 | struct class_device_attribute attr_debugcmd; |
| 52 | struct class_device_attribute attr_debuginfo; | 54 | struct class_device_attribute attr_debuginfo; |
| 55 | int debugcmd_created_ok; | ||
| 56 | int debuginfo_created_ok; | ||
| 53 | }; | 57 | }; |
| 54 | #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */ | 58 | #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */ |
| 55 | 59 | ||
| 56 | struct pvr2_sysfs_ctl_item { | 60 | struct pvr2_sysfs_ctl_item { |
| 57 | struct class_device_attribute attr_name; | 61 | struct class_device_attribute attr_name; |
| 58 | struct class_device_attribute attr_type; | 62 | struct class_device_attribute attr_type; |
| 59 | struct class_device_attribute attr_min; | 63 | struct class_device_attribute attr_min; |
| 60 | struct class_device_attribute attr_max; | 64 | struct class_device_attribute attr_max; |
| 61 | struct class_device_attribute attr_enum; | 65 | struct class_device_attribute attr_enum; |
| 62 | struct class_device_attribute attr_bits; | 66 | struct class_device_attribute attr_bits; |
| 63 | struct class_device_attribute attr_val; | 67 | struct class_device_attribute attr_val; |
| 64 | struct class_device_attribute attr_custom; | 68 | struct class_device_attribute attr_custom; |
| 65 | struct pvr2_ctrl *cptr; | 69 | struct pvr2_ctrl *cptr; |
| 66 | struct pvr2_sysfs *chptr; | 70 | struct pvr2_sysfs *chptr; |
| 67 | struct pvr2_sysfs_ctl_item *item_next; | 71 | struct pvr2_sysfs_ctl_item *item_next; |
| 68 | struct attribute *attr_gen[7]; | 72 | struct attribute *attr_gen[7]; |
| 69 | struct attribute_group grp; | 73 | struct attribute_group grp; |
| 74 | int created_ok; | ||
| 70 | char name[80]; | 75 | char name[80]; |
| 71 | }; | 76 | }; |
| 72 | 77 | ||
| 73 | struct pvr2_sysfs_class { | 78 | struct pvr2_sysfs_class { |
| 74 | struct class class; | 79 | struct class class; |
| 75 | }; | 80 | }; |
| 76 | 81 | ||
| 77 | static ssize_t show_name(int id,struct class_device *class_dev,char *buf) | 82 | static ssize_t show_name(int id,struct class_device *class_dev,char *buf) |
| 78 | { | 83 | { |
| 79 | struct pvr2_ctrl *cptr; | 84 | struct pvr2_ctrl *cptr; |
| 80 | struct pvr2_sysfs *sfp; | 85 | struct pvr2_sysfs *sfp; |
| 81 | const char *name; | 86 | const char *name; |
| 82 | 87 | ||
| 83 | sfp = (struct pvr2_sysfs *)class_dev->class_data; | 88 | sfp = (struct pvr2_sysfs *)class_dev->class_data; |
| 84 | if (!sfp) return -EINVAL; | 89 | if (!sfp) return -EINVAL; |
| 85 | cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id); | 90 | cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id); |
| 86 | if (!cptr) return -EINVAL; | 91 | if (!cptr) return -EINVAL; |
| 87 | 92 | ||
| 88 | name = pvr2_ctrl_get_desc(cptr); | 93 | name = pvr2_ctrl_get_desc(cptr); |
| 89 | pvr2_sysfs_trace("pvr2_sysfs(%p) show_name(cid=%d) is %s",sfp,id,name); | 94 | pvr2_sysfs_trace("pvr2_sysfs(%p) show_name(cid=%d) is %s",sfp,id,name); |
| 90 | 95 | ||
| 91 | if (!name) return -EINVAL; | 96 | if (!name) return -EINVAL; |
| 92 | 97 | ||
| 93 | return scnprintf(buf,PAGE_SIZE,"%s\n",name); | 98 | return scnprintf(buf,PAGE_SIZE,"%s\n",name); |
| 94 | } | 99 | } |
| 95 | 100 | ||
| 96 | static ssize_t show_type(int id,struct class_device *class_dev,char *buf) | 101 | static ssize_t show_type(int id,struct class_device *class_dev,char *buf) |
| 97 | { | 102 | { |
| 98 | struct pvr2_ctrl *cptr; | 103 | struct pvr2_ctrl *cptr; |
| 99 | struct pvr2_sysfs *sfp; | 104 | struct pvr2_sysfs *sfp; |
| 100 | const char *name; | 105 | const char *name; |
| 101 | enum pvr2_ctl_type tp; | 106 | enum pvr2_ctl_type tp; |
| 102 | 107 | ||
| 103 | sfp = (struct pvr2_sysfs *)class_dev->class_data; | 108 | sfp = (struct pvr2_sysfs *)class_dev->class_data; |
| 104 | if (!sfp) return -EINVAL; | 109 | if (!sfp) return -EINVAL; |
| 105 | cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id); | 110 | cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id); |
| 106 | if (!cptr) return -EINVAL; | 111 | if (!cptr) return -EINVAL; |
| 107 | 112 | ||
| 108 | tp = pvr2_ctrl_get_type(cptr); | 113 | tp = pvr2_ctrl_get_type(cptr); |
| 109 | switch (tp) { | 114 | switch (tp) { |
| 110 | case pvr2_ctl_int: name = "integer"; break; | 115 | case pvr2_ctl_int: name = "integer"; break; |
| 111 | case pvr2_ctl_enum: name = "enum"; break; | 116 | case pvr2_ctl_enum: name = "enum"; break; |
| 112 | case pvr2_ctl_bitmask: name = "bitmask"; break; | 117 | case pvr2_ctl_bitmask: name = "bitmask"; break; |
| 113 | case pvr2_ctl_bool: name = "boolean"; break; | 118 | case pvr2_ctl_bool: name = "boolean"; break; |
| 114 | default: name = "?"; break; | 119 | default: name = "?"; break; |
| 115 | } | 120 | } |
| 116 | pvr2_sysfs_trace("pvr2_sysfs(%p) show_type(cid=%d) is %s",sfp,id,name); | 121 | pvr2_sysfs_trace("pvr2_sysfs(%p) show_type(cid=%d) is %s",sfp,id,name); |
| 117 | 122 | ||
| 118 | if (!name) return -EINVAL; | 123 | if (!name) return -EINVAL; |
| 119 | 124 | ||
| 120 | return scnprintf(buf,PAGE_SIZE,"%s\n",name); | 125 | return scnprintf(buf,PAGE_SIZE,"%s\n",name); |
| 121 | } | 126 | } |
| 122 | 127 | ||
| 123 | static ssize_t show_min(int id,struct class_device *class_dev,char *buf) | 128 | static ssize_t show_min(int id,struct class_device *class_dev,char *buf) |
| 124 | { | 129 | { |
| 125 | struct pvr2_ctrl *cptr; | 130 | struct pvr2_ctrl *cptr; |
| 126 | struct pvr2_sysfs *sfp; | 131 | struct pvr2_sysfs *sfp; |
| 127 | long val; | 132 | long val; |
| 128 | 133 | ||
| 129 | sfp = (struct pvr2_sysfs *)class_dev->class_data; | 134 | sfp = (struct pvr2_sysfs *)class_dev->class_data; |
| 130 | if (!sfp) return -EINVAL; | 135 | if (!sfp) return -EINVAL; |
| 131 | cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id); | 136 | cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id); |
| 132 | if (!cptr) return -EINVAL; | 137 | if (!cptr) return -EINVAL; |
| 133 | val = pvr2_ctrl_get_min(cptr); | 138 | val = pvr2_ctrl_get_min(cptr); |
| 134 | 139 | ||
| 135 | pvr2_sysfs_trace("pvr2_sysfs(%p) show_min(cid=%d) is %ld",sfp,id,val); | 140 | pvr2_sysfs_trace("pvr2_sysfs(%p) show_min(cid=%d) is %ld",sfp,id,val); |
| 136 | 141 | ||
| 137 | return scnprintf(buf,PAGE_SIZE,"%ld\n",val); | 142 | return scnprintf(buf,PAGE_SIZE,"%ld\n",val); |
| 138 | } | 143 | } |
| 139 | 144 | ||
| 140 | static ssize_t show_max(int id,struct class_device *class_dev,char *buf) | 145 | static ssize_t show_max(int id,struct class_device *class_dev,char *buf) |
| 141 | { | 146 | { |
| 142 | struct pvr2_ctrl *cptr; | 147 | struct pvr2_ctrl *cptr; |
| 143 | struct pvr2_sysfs *sfp; | 148 | struct pvr2_sysfs *sfp; |
| 144 | long val; | 149 | long val; |
| 145 | 150 | ||
| 146 | sfp = (struct pvr2_sysfs *)class_dev->class_data; | 151 | sfp = (struct pvr2_sysfs *)class_dev->class_data; |
| 147 | if (!sfp) return -EINVAL; | 152 | if (!sfp) return -EINVAL; |
| 148 | cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id); | 153 | cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id); |
| 149 | if (!cptr) return -EINVAL; | 154 | if (!cptr) return -EINVAL; |
| 150 | val = pvr2_ctrl_get_max(cptr); | 155 | val = pvr2_ctrl_get_max(cptr); |
| 151 | 156 | ||
| 152 | pvr2_sysfs_trace("pvr2_sysfs(%p) show_max(cid=%d) is %ld",sfp,id,val); | 157 | pvr2_sysfs_trace("pvr2_sysfs(%p) show_max(cid=%d) is %ld",sfp,id,val); |
| 153 | 158 | ||
| 154 | return scnprintf(buf,PAGE_SIZE,"%ld\n",val); | 159 | return scnprintf(buf,PAGE_SIZE,"%ld\n",val); |
| 155 | } | 160 | } |
| 156 | 161 | ||
| 157 | static ssize_t show_val_norm(int id,struct class_device *class_dev,char *buf) | 162 | static ssize_t show_val_norm(int id,struct class_device *class_dev,char *buf) |
| 158 | { | 163 | { |
| 159 | struct pvr2_ctrl *cptr; | 164 | struct pvr2_ctrl *cptr; |
| 160 | struct pvr2_sysfs *sfp; | 165 | struct pvr2_sysfs *sfp; |
| 161 | int val,ret; | 166 | int val,ret; |
| 162 | unsigned int cnt = 0; | 167 | unsigned int cnt = 0; |
| 163 | 168 | ||
| 164 | sfp = (struct pvr2_sysfs *)class_dev->class_data; | 169 | sfp = (struct pvr2_sysfs *)class_dev->class_data; |
| 165 | if (!sfp) return -EINVAL; | 170 | if (!sfp) return -EINVAL; |
| 166 | cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id); | 171 | cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id); |
| 167 | if (!cptr) return -EINVAL; | 172 | if (!cptr) return -EINVAL; |
| 168 | 173 | ||
| 169 | ret = pvr2_ctrl_get_value(cptr,&val); | 174 | ret = pvr2_ctrl_get_value(cptr,&val); |
| 170 | if (ret < 0) return ret; | 175 | if (ret < 0) return ret; |
| 171 | 176 | ||
| 172 | ret = pvr2_ctrl_value_to_sym(cptr,~0,val, | 177 | ret = pvr2_ctrl_value_to_sym(cptr,~0,val, |
| 173 | buf,PAGE_SIZE-1,&cnt); | 178 | buf,PAGE_SIZE-1,&cnt); |
| 174 | 179 | ||
| 175 | pvr2_sysfs_trace("pvr2_sysfs(%p) show_val_norm(cid=%d) is %.*s (%d)", | 180 | pvr2_sysfs_trace("pvr2_sysfs(%p) show_val_norm(cid=%d) is %.*s (%d)", |
| 176 | sfp,id,cnt,buf,val); | 181 | sfp,id,cnt,buf,val); |
| 177 | buf[cnt] = '\n'; | 182 | buf[cnt] = '\n'; |
| 178 | return cnt+1; | 183 | return cnt+1; |
| 179 | } | 184 | } |
| 180 | 185 | ||
| 181 | static ssize_t show_val_custom(int id,struct class_device *class_dev,char *buf) | 186 | static ssize_t show_val_custom(int id,struct class_device *class_dev,char *buf) |
| 182 | { | 187 | { |
| 183 | struct pvr2_ctrl *cptr; | 188 | struct pvr2_ctrl *cptr; |
| 184 | struct pvr2_sysfs *sfp; | 189 | struct pvr2_sysfs *sfp; |
| 185 | int val,ret; | 190 | int val,ret; |
| 186 | unsigned int cnt = 0; | 191 | unsigned int cnt = 0; |
| 187 | 192 | ||
| 188 | sfp = (struct pvr2_sysfs *)class_dev->class_data; | 193 | sfp = (struct pvr2_sysfs *)class_dev->class_data; |
| 189 | if (!sfp) return -EINVAL; | 194 | if (!sfp) return -EINVAL; |
| 190 | cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id); | 195 | cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id); |
| 191 | if (!cptr) return -EINVAL; | 196 | if (!cptr) return -EINVAL; |
| 192 | 197 | ||
| 193 | ret = pvr2_ctrl_get_value(cptr,&val); | 198 | ret = pvr2_ctrl_get_value(cptr,&val); |
| 194 | if (ret < 0) return ret; | 199 | if (ret < 0) return ret; |
| 195 | 200 | ||
| 196 | ret = pvr2_ctrl_custom_value_to_sym(cptr,~0,val, | 201 | ret = pvr2_ctrl_custom_value_to_sym(cptr,~0,val, |
| 197 | buf,PAGE_SIZE-1,&cnt); | 202 | buf,PAGE_SIZE-1,&cnt); |
| 198 | 203 | ||
| 199 | pvr2_sysfs_trace("pvr2_sysfs(%p) show_val_custom(cid=%d) is %.*s (%d)", | 204 | pvr2_sysfs_trace("pvr2_sysfs(%p) show_val_custom(cid=%d) is %.*s (%d)", |
| 200 | sfp,id,cnt,buf,val); | 205 | sfp,id,cnt,buf,val); |
| 201 | buf[cnt] = '\n'; | 206 | buf[cnt] = '\n'; |
| 202 | return cnt+1; | 207 | return cnt+1; |
| 203 | } | 208 | } |
| 204 | 209 | ||
| 205 | static ssize_t show_enum(int id,struct class_device *class_dev,char *buf) | 210 | static ssize_t show_enum(int id,struct class_device *class_dev,char *buf) |
| 206 | { | 211 | { |
| 207 | struct pvr2_ctrl *cptr; | 212 | struct pvr2_ctrl *cptr; |
| 208 | struct pvr2_sysfs *sfp; | 213 | struct pvr2_sysfs *sfp; |
| 209 | long val; | 214 | long val; |
| 210 | unsigned int bcnt,ccnt,ecnt; | 215 | unsigned int bcnt,ccnt,ecnt; |
| 211 | 216 | ||
| 212 | sfp = (struct pvr2_sysfs *)class_dev->class_data; | 217 | sfp = (struct pvr2_sysfs *)class_dev->class_data; |
| 213 | if (!sfp) return -EINVAL; | 218 | if (!sfp) return -EINVAL; |
| 214 | cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id); | 219 | cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id); |
| 215 | if (!cptr) return -EINVAL; | 220 | if (!cptr) return -EINVAL; |
| 216 | ecnt = pvr2_ctrl_get_cnt(cptr); | 221 | ecnt = pvr2_ctrl_get_cnt(cptr); |
| 217 | bcnt = 0; | 222 | bcnt = 0; |
| 218 | for (val = 0; val < ecnt; val++) { | 223 | for (val = 0; val < ecnt; val++) { |
| 219 | pvr2_ctrl_get_valname(cptr,val,buf+bcnt,PAGE_SIZE-bcnt,&ccnt); | 224 | pvr2_ctrl_get_valname(cptr,val,buf+bcnt,PAGE_SIZE-bcnt,&ccnt); |
| 220 | if (!ccnt) continue; | 225 | if (!ccnt) continue; |
| 221 | bcnt += ccnt; | 226 | bcnt += ccnt; |
| 222 | if (bcnt >= PAGE_SIZE) break; | 227 | if (bcnt >= PAGE_SIZE) break; |
| 223 | buf[bcnt] = '\n'; | 228 | buf[bcnt] = '\n'; |
| 224 | bcnt++; | 229 | bcnt++; |
| 225 | } | 230 | } |
| 226 | pvr2_sysfs_trace("pvr2_sysfs(%p) show_enum(cid=%d)",sfp,id); | 231 | pvr2_sysfs_trace("pvr2_sysfs(%p) show_enum(cid=%d)",sfp,id); |
| 227 | return bcnt; | 232 | return bcnt; |
| 228 | } | 233 | } |
| 229 | 234 | ||
| 230 | static ssize_t show_bits(int id,struct class_device *class_dev,char *buf) | 235 | static ssize_t show_bits(int id,struct class_device *class_dev,char *buf) |
| 231 | { | 236 | { |
| 232 | struct pvr2_ctrl *cptr; | 237 | struct pvr2_ctrl *cptr; |
| 233 | struct pvr2_sysfs *sfp; | 238 | struct pvr2_sysfs *sfp; |
| 234 | int valid_bits,msk; | 239 | int valid_bits,msk; |
| 235 | unsigned int bcnt,ccnt; | 240 | unsigned int bcnt,ccnt; |
| 236 | 241 | ||
| 237 | sfp = (struct pvr2_sysfs *)class_dev->class_data; | 242 | sfp = (struct pvr2_sysfs *)class_dev->class_data; |
| 238 | if (!sfp) return -EINVAL; | 243 | if (!sfp) return -EINVAL; |
| 239 | cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id); | 244 | cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id); |
| 240 | if (!cptr) return -EINVAL; | 245 | if (!cptr) return -EINVAL; |
| 241 | valid_bits = pvr2_ctrl_get_mask(cptr); | 246 | valid_bits = pvr2_ctrl_get_mask(cptr); |
| 242 | bcnt = 0; | 247 | bcnt = 0; |
| 243 | for (msk = 1; valid_bits; msk <<= 1) { | 248 | for (msk = 1; valid_bits; msk <<= 1) { |
| 244 | if (!(msk & valid_bits)) continue; | 249 | if (!(msk & valid_bits)) continue; |
| 245 | valid_bits &= ~msk; | 250 | valid_bits &= ~msk; |
| 246 | pvr2_ctrl_get_valname(cptr,msk,buf+bcnt,PAGE_SIZE-bcnt,&ccnt); | 251 | pvr2_ctrl_get_valname(cptr,msk,buf+bcnt,PAGE_SIZE-bcnt,&ccnt); |
| 247 | bcnt += ccnt; | 252 | bcnt += ccnt; |
| 248 | if (bcnt >= PAGE_SIZE) break; | 253 | if (bcnt >= PAGE_SIZE) break; |
| 249 | buf[bcnt] = '\n'; | 254 | buf[bcnt] = '\n'; |
| 250 | bcnt++; | 255 | bcnt++; |
| 251 | } | 256 | } |
| 252 | pvr2_sysfs_trace("pvr2_sysfs(%p) show_bits(cid=%d)",sfp,id); | 257 | pvr2_sysfs_trace("pvr2_sysfs(%p) show_bits(cid=%d)",sfp,id); |
| 253 | return bcnt; | 258 | return bcnt; |
| 254 | } | 259 | } |
| 255 | 260 | ||
| 256 | static int store_val_any(int id,int customfl,struct pvr2_sysfs *sfp, | 261 | static int store_val_any(int id,int customfl,struct pvr2_sysfs *sfp, |
| 257 | const char *buf,unsigned int count) | 262 | const char *buf,unsigned int count) |
| 258 | { | 263 | { |
| 259 | struct pvr2_ctrl *cptr; | 264 | struct pvr2_ctrl *cptr; |
| 260 | int ret; | 265 | int ret; |
| 261 | int mask,val; | 266 | int mask,val; |
| 262 | 267 | ||
| 263 | cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id); | 268 | cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id); |
| 264 | if (customfl) { | 269 | if (customfl) { |
| 265 | ret = pvr2_ctrl_custom_sym_to_value(cptr,buf,count,&mask,&val); | 270 | ret = pvr2_ctrl_custom_sym_to_value(cptr,buf,count,&mask,&val); |
| 266 | } else { | 271 | } else { |
| 267 | ret = pvr2_ctrl_sym_to_value(cptr,buf,count,&mask,&val); | 272 | ret = pvr2_ctrl_sym_to_value(cptr,buf,count,&mask,&val); |
| 268 | } | 273 | } |
| 269 | if (ret < 0) return ret; | 274 | if (ret < 0) return ret; |
| 270 | ret = pvr2_ctrl_set_mask_value(cptr,mask,val); | 275 | ret = pvr2_ctrl_set_mask_value(cptr,mask,val); |
| 271 | pvr2_hdw_commit_ctl(sfp->channel.hdw); | 276 | pvr2_hdw_commit_ctl(sfp->channel.hdw); |
| 272 | return ret; | 277 | return ret; |
| 273 | } | 278 | } |
| 274 | 279 | ||
| 275 | static ssize_t store_val_norm(int id,struct class_device *class_dev, | 280 | static ssize_t store_val_norm(int id,struct class_device *class_dev, |
| 276 | const char *buf,size_t count) | 281 | const char *buf,size_t count) |
| 277 | { | 282 | { |
| 278 | struct pvr2_sysfs *sfp; | 283 | struct pvr2_sysfs *sfp; |
| 279 | int ret; | 284 | int ret; |
| 280 | sfp = (struct pvr2_sysfs *)class_dev->class_data; | 285 | sfp = (struct pvr2_sysfs *)class_dev->class_data; |
| 281 | ret = store_val_any(id,0,sfp,buf,count); | 286 | ret = store_val_any(id,0,sfp,buf,count); |
| 282 | if (!ret) ret = count; | 287 | if (!ret) ret = count; |
| 283 | return ret; | 288 | return ret; |
| 284 | } | 289 | } |
| 285 | 290 | ||
| 286 | static ssize_t store_val_custom(int id,struct class_device *class_dev, | 291 | static ssize_t store_val_custom(int id,struct class_device *class_dev, |
| 287 | const char *buf,size_t count) | 292 | const char *buf,size_t count) |
| 288 | { | 293 | { |
| 289 | struct pvr2_sysfs *sfp; | 294 | struct pvr2_sysfs *sfp; |
| 290 | int ret; | 295 | int ret; |
| 291 | sfp = (struct pvr2_sysfs *)class_dev->class_data; | 296 | sfp = (struct pvr2_sysfs *)class_dev->class_data; |
| 292 | ret = store_val_any(id,1,sfp,buf,count); | 297 | ret = store_val_any(id,1,sfp,buf,count); |
| 293 | if (!ret) ret = count; | 298 | if (!ret) ret = count; |
| 294 | return ret; | 299 | return ret; |
| 295 | } | 300 | } |
| 296 | 301 | ||
| 297 | /* | 302 | /* |
| 298 | Mike Isely <isely@pobox.com> 30-April-2005 | 303 | Mike Isely <isely@pobox.com> 30-April-2005 |
| 299 | 304 | ||
| 300 | This next batch of horrible preprocessor hackery is needed because the | 305 | This next batch of horrible preprocessor hackery is needed because the |
| 301 | kernel's class_device_attribute mechanism fails to pass the actual | 306 | kernel's class_device_attribute mechanism fails to pass the actual |
| 302 | attribute through to the show / store functions, which means we have no | 307 | attribute through to the show / store functions, which means we have no |
| 303 | way to package up any attribute-specific parameters, like for example the | 308 | way to package up any attribute-specific parameters, like for example the |
| 304 | control id. So we work around this brain-damage by encoding the control | 309 | control id. So we work around this brain-damage by encoding the control |
| 305 | id into the show / store functions themselves and pick the function based | 310 | id into the show / store functions themselves and pick the function based |
| 306 | on the control id we're setting up. These macros try to ease the pain. | 311 | on the control id we're setting up. These macros try to ease the pain. |
| 307 | Yuck. | 312 | Yuck. |
| 308 | */ | 313 | */ |
| 309 | 314 | ||
| 310 | #define CREATE_SHOW_INSTANCE(sf_name,ctl_id) \ | 315 | #define CREATE_SHOW_INSTANCE(sf_name,ctl_id) \ |
| 311 | static ssize_t sf_name##_##ctl_id(struct class_device *class_dev,char *buf) \ | 316 | static ssize_t sf_name##_##ctl_id(struct class_device *class_dev,char *buf) \ |
| 312 | { return sf_name(ctl_id,class_dev,buf); } | 317 | { return sf_name(ctl_id,class_dev,buf); } |
| 313 | 318 | ||
| 314 | #define CREATE_STORE_INSTANCE(sf_name,ctl_id) \ | 319 | #define CREATE_STORE_INSTANCE(sf_name,ctl_id) \ |
| 315 | static ssize_t sf_name##_##ctl_id(struct class_device *class_dev,const char *buf,size_t count) \ | 320 | static ssize_t sf_name##_##ctl_id(struct class_device *class_dev,const char *buf,size_t count) \ |
| 316 | { return sf_name(ctl_id,class_dev,buf,count); } | 321 | { return sf_name(ctl_id,class_dev,buf,count); } |
| 317 | 322 | ||
| 318 | #define CREATE_BATCH(ctl_id) \ | 323 | #define CREATE_BATCH(ctl_id) \ |
| 319 | CREATE_SHOW_INSTANCE(show_name,ctl_id) \ | 324 | CREATE_SHOW_INSTANCE(show_name,ctl_id) \ |
| 320 | CREATE_SHOW_INSTANCE(show_type,ctl_id) \ | 325 | CREATE_SHOW_INSTANCE(show_type,ctl_id) \ |
| 321 | CREATE_SHOW_INSTANCE(show_min,ctl_id) \ | 326 | CREATE_SHOW_INSTANCE(show_min,ctl_id) \ |
| 322 | CREATE_SHOW_INSTANCE(show_max,ctl_id) \ | 327 | CREATE_SHOW_INSTANCE(show_max,ctl_id) \ |
| 323 | CREATE_SHOW_INSTANCE(show_val_norm,ctl_id) \ | 328 | CREATE_SHOW_INSTANCE(show_val_norm,ctl_id) \ |
| 324 | CREATE_SHOW_INSTANCE(show_val_custom,ctl_id) \ | 329 | CREATE_SHOW_INSTANCE(show_val_custom,ctl_id) \ |
| 325 | CREATE_SHOW_INSTANCE(show_enum,ctl_id) \ | 330 | CREATE_SHOW_INSTANCE(show_enum,ctl_id) \ |
| 326 | CREATE_SHOW_INSTANCE(show_bits,ctl_id) \ | 331 | CREATE_SHOW_INSTANCE(show_bits,ctl_id) \ |
| 327 | CREATE_STORE_INSTANCE(store_val_norm,ctl_id) \ | 332 | CREATE_STORE_INSTANCE(store_val_norm,ctl_id) \ |
| 328 | CREATE_STORE_INSTANCE(store_val_custom,ctl_id) \ | 333 | CREATE_STORE_INSTANCE(store_val_custom,ctl_id) \ |
| 329 | 334 | ||
| 330 | CREATE_BATCH(0) | 335 | CREATE_BATCH(0) |
| 331 | CREATE_BATCH(1) | 336 | CREATE_BATCH(1) |
| 332 | CREATE_BATCH(2) | 337 | CREATE_BATCH(2) |
| 333 | CREATE_BATCH(3) | 338 | CREATE_BATCH(3) |
| 334 | CREATE_BATCH(4) | 339 | CREATE_BATCH(4) |
| 335 | CREATE_BATCH(5) | 340 | CREATE_BATCH(5) |
| 336 | CREATE_BATCH(6) | 341 | CREATE_BATCH(6) |
| 337 | CREATE_BATCH(7) | 342 | CREATE_BATCH(7) |
| 338 | CREATE_BATCH(8) | 343 | CREATE_BATCH(8) |
| 339 | CREATE_BATCH(9) | 344 | CREATE_BATCH(9) |
| 340 | CREATE_BATCH(10) | 345 | CREATE_BATCH(10) |
| 341 | CREATE_BATCH(11) | 346 | CREATE_BATCH(11) |
| 342 | CREATE_BATCH(12) | 347 | CREATE_BATCH(12) |
| 343 | CREATE_BATCH(13) | 348 | CREATE_BATCH(13) |
| 344 | CREATE_BATCH(14) | 349 | CREATE_BATCH(14) |
| 345 | CREATE_BATCH(15) | 350 | CREATE_BATCH(15) |
| 346 | CREATE_BATCH(16) | 351 | CREATE_BATCH(16) |
| 347 | CREATE_BATCH(17) | 352 | CREATE_BATCH(17) |
| 348 | CREATE_BATCH(18) | 353 | CREATE_BATCH(18) |
| 349 | CREATE_BATCH(19) | 354 | CREATE_BATCH(19) |
| 350 | CREATE_BATCH(20) | 355 | CREATE_BATCH(20) |
| 351 | CREATE_BATCH(21) | 356 | CREATE_BATCH(21) |
| 352 | CREATE_BATCH(22) | 357 | CREATE_BATCH(22) |
| 353 | CREATE_BATCH(23) | 358 | CREATE_BATCH(23) |
| 354 | CREATE_BATCH(24) | 359 | CREATE_BATCH(24) |
| 355 | CREATE_BATCH(25) | 360 | CREATE_BATCH(25) |
| 356 | CREATE_BATCH(26) | 361 | CREATE_BATCH(26) |
| 357 | CREATE_BATCH(27) | 362 | CREATE_BATCH(27) |
| 358 | CREATE_BATCH(28) | 363 | CREATE_BATCH(28) |
| 359 | CREATE_BATCH(29) | 364 | CREATE_BATCH(29) |
| 360 | CREATE_BATCH(30) | 365 | CREATE_BATCH(30) |
| 361 | CREATE_BATCH(31) | 366 | CREATE_BATCH(31) |
| 362 | CREATE_BATCH(32) | 367 | CREATE_BATCH(32) |
| 363 | CREATE_BATCH(33) | 368 | CREATE_BATCH(33) |
| 364 | CREATE_BATCH(34) | 369 | CREATE_BATCH(34) |
| 365 | CREATE_BATCH(35) | 370 | CREATE_BATCH(35) |
| 366 | CREATE_BATCH(36) | 371 | CREATE_BATCH(36) |
| 367 | CREATE_BATCH(37) | 372 | CREATE_BATCH(37) |
| 368 | CREATE_BATCH(38) | 373 | CREATE_BATCH(38) |
| 369 | CREATE_BATCH(39) | 374 | CREATE_BATCH(39) |
| 370 | CREATE_BATCH(40) | 375 | CREATE_BATCH(40) |
| 371 | CREATE_BATCH(41) | 376 | CREATE_BATCH(41) |
| 372 | CREATE_BATCH(42) | 377 | CREATE_BATCH(42) |
| 373 | CREATE_BATCH(43) | 378 | CREATE_BATCH(43) |
| 374 | CREATE_BATCH(44) | 379 | CREATE_BATCH(44) |
| 375 | CREATE_BATCH(45) | 380 | CREATE_BATCH(45) |
| 376 | CREATE_BATCH(46) | 381 | CREATE_BATCH(46) |
| 377 | CREATE_BATCH(47) | 382 | CREATE_BATCH(47) |
| 378 | CREATE_BATCH(48) | 383 | CREATE_BATCH(48) |
| 379 | CREATE_BATCH(49) | 384 | CREATE_BATCH(49) |
| 380 | CREATE_BATCH(50) | 385 | CREATE_BATCH(50) |
| 381 | CREATE_BATCH(51) | 386 | CREATE_BATCH(51) |
| 382 | CREATE_BATCH(52) | 387 | CREATE_BATCH(52) |
| 383 | CREATE_BATCH(53) | 388 | CREATE_BATCH(53) |
| 384 | CREATE_BATCH(54) | 389 | CREATE_BATCH(54) |
| 385 | CREATE_BATCH(55) | 390 | CREATE_BATCH(55) |
| 386 | CREATE_BATCH(56) | 391 | CREATE_BATCH(56) |
| 387 | CREATE_BATCH(57) | 392 | CREATE_BATCH(57) |
| 388 | CREATE_BATCH(58) | 393 | CREATE_BATCH(58) |
| 389 | CREATE_BATCH(59) | 394 | CREATE_BATCH(59) |
| 390 | 395 | ||
| 391 | struct pvr2_sysfs_func_set { | 396 | struct pvr2_sysfs_func_set { |
| 392 | ssize_t (*show_name)(struct class_device *,char *); | 397 | ssize_t (*show_name)(struct class_device *,char *); |
| 393 | ssize_t (*show_type)(struct class_device *,char *); | 398 | ssize_t (*show_type)(struct class_device *,char *); |
| 394 | ssize_t (*show_min)(struct class_device *,char *); | 399 | ssize_t (*show_min)(struct class_device *,char *); |
| 395 | ssize_t (*show_max)(struct class_device *,char *); | 400 | ssize_t (*show_max)(struct class_device *,char *); |
| 396 | ssize_t (*show_enum)(struct class_device *,char *); | 401 | ssize_t (*show_enum)(struct class_device *,char *); |
| 397 | ssize_t (*show_bits)(struct class_device *,char *); | 402 | ssize_t (*show_bits)(struct class_device *,char *); |
| 398 | ssize_t (*show_val_norm)(struct class_device *,char *); | 403 | ssize_t (*show_val_norm)(struct class_device *,char *); |
| 399 | ssize_t (*store_val_norm)(struct class_device *, | 404 | ssize_t (*store_val_norm)(struct class_device *, |
| 400 | const char *,size_t); | 405 | const char *,size_t); |
| 401 | ssize_t (*show_val_custom)(struct class_device *,char *); | 406 | ssize_t (*show_val_custom)(struct class_device *,char *); |
| 402 | ssize_t (*store_val_custom)(struct class_device *, | 407 | ssize_t (*store_val_custom)(struct class_device *, |
| 403 | const char *,size_t); | 408 | const char *,size_t); |
| 404 | }; | 409 | }; |
| 405 | 410 | ||
| 406 | #define INIT_BATCH(ctl_id) \ | 411 | #define INIT_BATCH(ctl_id) \ |
| 407 | [ctl_id] = { \ | 412 | [ctl_id] = { \ |
| 408 | .show_name = show_name_##ctl_id, \ | 413 | .show_name = show_name_##ctl_id, \ |
| 409 | .show_type = show_type_##ctl_id, \ | 414 | .show_type = show_type_##ctl_id, \ |
| 410 | .show_min = show_min_##ctl_id, \ | 415 | .show_min = show_min_##ctl_id, \ |
| 411 | .show_max = show_max_##ctl_id, \ | 416 | .show_max = show_max_##ctl_id, \ |
| 412 | .show_enum = show_enum_##ctl_id, \ | 417 | .show_enum = show_enum_##ctl_id, \ |
| 413 | .show_bits = show_bits_##ctl_id, \ | 418 | .show_bits = show_bits_##ctl_id, \ |
| 414 | .show_val_norm = show_val_norm_##ctl_id, \ | 419 | .show_val_norm = show_val_norm_##ctl_id, \ |
| 415 | .store_val_norm = store_val_norm_##ctl_id, \ | 420 | .store_val_norm = store_val_norm_##ctl_id, \ |
| 416 | .show_val_custom = show_val_custom_##ctl_id, \ | 421 | .show_val_custom = show_val_custom_##ctl_id, \ |
| 417 | .store_val_custom = store_val_custom_##ctl_id, \ | 422 | .store_val_custom = store_val_custom_##ctl_id, \ |
| 418 | } \ | 423 | } \ |
| 419 | 424 | ||
| 420 | static struct pvr2_sysfs_func_set funcs[] = { | 425 | static struct pvr2_sysfs_func_set funcs[] = { |
| 421 | INIT_BATCH(0), | 426 | INIT_BATCH(0), |
| 422 | INIT_BATCH(1), | 427 | INIT_BATCH(1), |
| 423 | INIT_BATCH(2), | 428 | INIT_BATCH(2), |
| 424 | INIT_BATCH(3), | 429 | INIT_BATCH(3), |
| 425 | INIT_BATCH(4), | 430 | INIT_BATCH(4), |
| 426 | INIT_BATCH(5), | 431 | INIT_BATCH(5), |
| 427 | INIT_BATCH(6), | 432 | INIT_BATCH(6), |
| 428 | INIT_BATCH(7), | 433 | INIT_BATCH(7), |
| 429 | INIT_BATCH(8), | 434 | INIT_BATCH(8), |
| 430 | INIT_BATCH(9), | 435 | INIT_BATCH(9), |
| 431 | INIT_BATCH(10), | 436 | INIT_BATCH(10), |
| 432 | INIT_BATCH(11), | 437 | INIT_BATCH(11), |
| 433 | INIT_BATCH(12), | 438 | INIT_BATCH(12), |
| 434 | INIT_BATCH(13), | 439 | INIT_BATCH(13), |
| 435 | INIT_BATCH(14), | 440 | INIT_BATCH(14), |
| 436 | INIT_BATCH(15), | 441 | INIT_BATCH(15), |
| 437 | INIT_BATCH(16), | 442 | INIT_BATCH(16), |
| 438 | INIT_BATCH(17), | 443 | INIT_BATCH(17), |
| 439 | INIT_BATCH(18), | 444 | INIT_BATCH(18), |
| 440 | INIT_BATCH(19), | 445 | INIT_BATCH(19), |
| 441 | INIT_BATCH(20), | 446 | INIT_BATCH(20), |
| 442 | INIT_BATCH(21), | 447 | INIT_BATCH(21), |
| 443 | INIT_BATCH(22), | 448 | INIT_BATCH(22), |
| 444 | INIT_BATCH(23), | 449 | INIT_BATCH(23), |
| 445 | INIT_BATCH(24), | 450 | INIT_BATCH(24), |
| 446 | INIT_BATCH(25), | 451 | INIT_BATCH(25), |
| 447 | INIT_BATCH(26), | 452 | INIT_BATCH(26), |
| 448 | INIT_BATCH(27), | 453 | INIT_BATCH(27), |
| 449 | INIT_BATCH(28), | 454 | INIT_BATCH(28), |
| 450 | INIT_BATCH(29), | 455 | INIT_BATCH(29), |
| 451 | INIT_BATCH(30), | 456 | INIT_BATCH(30), |
| 452 | INIT_BATCH(31), | 457 | INIT_BATCH(31), |
| 453 | INIT_BATCH(32), | 458 | INIT_BATCH(32), |
| 454 | INIT_BATCH(33), | 459 | INIT_BATCH(33), |
| 455 | INIT_BATCH(34), | 460 | INIT_BATCH(34), |
| 456 | INIT_BATCH(35), | 461 | INIT_BATCH(35), |
| 457 | INIT_BATCH(36), | 462 | INIT_BATCH(36), |
| 458 | INIT_BATCH(37), | 463 | INIT_BATCH(37), |
| 459 | INIT_BATCH(38), | 464 | INIT_BATCH(38), |
| 460 | INIT_BATCH(39), | 465 | INIT_BATCH(39), |
| 461 | INIT_BATCH(40), | 466 | INIT_BATCH(40), |
| 462 | INIT_BATCH(41), | 467 | INIT_BATCH(41), |
| 463 | INIT_BATCH(42), | 468 | INIT_BATCH(42), |
| 464 | INIT_BATCH(43), | 469 | INIT_BATCH(43), |
| 465 | INIT_BATCH(44), | 470 | INIT_BATCH(44), |
| 466 | INIT_BATCH(45), | 471 | INIT_BATCH(45), |
| 467 | INIT_BATCH(46), | 472 | INIT_BATCH(46), |
| 468 | INIT_BATCH(47), | 473 | INIT_BATCH(47), |
| 469 | INIT_BATCH(48), | 474 | INIT_BATCH(48), |
| 470 | INIT_BATCH(49), | 475 | INIT_BATCH(49), |
| 471 | INIT_BATCH(50), | 476 | INIT_BATCH(50), |
| 472 | INIT_BATCH(51), | 477 | INIT_BATCH(51), |
| 473 | INIT_BATCH(52), | 478 | INIT_BATCH(52), |
| 474 | INIT_BATCH(53), | 479 | INIT_BATCH(53), |
| 475 | INIT_BATCH(54), | 480 | INIT_BATCH(54), |
| 476 | INIT_BATCH(55), | 481 | INIT_BATCH(55), |
| 477 | INIT_BATCH(56), | 482 | INIT_BATCH(56), |
| 478 | INIT_BATCH(57), | 483 | INIT_BATCH(57), |
| 479 | INIT_BATCH(58), | 484 | INIT_BATCH(58), |
| 480 | INIT_BATCH(59), | 485 | INIT_BATCH(59), |
| 481 | }; | 486 | }; |
| 482 | 487 | ||
| 483 | 488 | ||
| 484 | static void pvr2_sysfs_add_control(struct pvr2_sysfs *sfp,int ctl_id) | 489 | static void pvr2_sysfs_add_control(struct pvr2_sysfs *sfp,int ctl_id) |
| 485 | { | 490 | { |
| 486 | struct pvr2_sysfs_ctl_item *cip; | 491 | struct pvr2_sysfs_ctl_item *cip; |
| 487 | struct pvr2_sysfs_func_set *fp; | 492 | struct pvr2_sysfs_func_set *fp; |
| 488 | struct pvr2_ctrl *cptr; | 493 | struct pvr2_ctrl *cptr; |
| 489 | unsigned int cnt,acnt; | 494 | unsigned int cnt,acnt; |
| 495 | int ret; | ||
| 490 | 496 | ||
| 491 | if ((ctl_id < 0) || (ctl_id >= (sizeof(funcs)/sizeof(funcs[0])))) { | 497 | if ((ctl_id < 0) || (ctl_id >= (sizeof(funcs)/sizeof(funcs[0])))) { |
| 492 | return; | 498 | return; |
| 493 | } | 499 | } |
| 494 | 500 | ||
| 495 | fp = funcs + ctl_id; | 501 | fp = funcs + ctl_id; |
| 496 | cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,ctl_id); | 502 | cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,ctl_id); |
| 497 | if (!cptr) return; | 503 | if (!cptr) return; |
| 498 | 504 | ||
| 499 | cip = kmalloc(sizeof(*cip),GFP_KERNEL); | 505 | cip = kmalloc(sizeof(*cip),GFP_KERNEL); |
| 500 | if (!cip) return; | 506 | if (!cip) return; |
| 501 | memset(cip,0,sizeof(*cip)); | 507 | memset(cip,0,sizeof(*cip)); |
| 502 | pvr2_sysfs_trace("Creating pvr2_sysfs_ctl_item id=%p",cip); | 508 | pvr2_sysfs_trace("Creating pvr2_sysfs_ctl_item id=%p",cip); |
| 503 | 509 | ||
| 504 | cip->cptr = cptr; | 510 | cip->cptr = cptr; |
| 505 | 511 | ||
| 506 | cip->chptr = sfp; | 512 | cip->chptr = sfp; |
| 507 | cip->item_next = NULL; | 513 | cip->item_next = NULL; |
| 508 | if (sfp->item_last) { | 514 | if (sfp->item_last) { |
| 509 | sfp->item_last->item_next = cip; | 515 | sfp->item_last->item_next = cip; |
| 510 | } else { | 516 | } else { |
| 511 | sfp->item_first = cip; | 517 | sfp->item_first = cip; |
| 512 | } | 518 | } |
| 513 | sfp->item_last = cip; | 519 | sfp->item_last = cip; |
| 514 | 520 | ||
| 515 | cip->attr_name.attr.owner = THIS_MODULE; | 521 | cip->attr_name.attr.owner = THIS_MODULE; |
| 516 | cip->attr_name.attr.name = "name"; | 522 | cip->attr_name.attr.name = "name"; |
| 517 | cip->attr_name.attr.mode = S_IRUGO; | 523 | cip->attr_name.attr.mode = S_IRUGO; |
| 518 | cip->attr_name.show = fp->show_name; | 524 | cip->attr_name.show = fp->show_name; |
| 519 | 525 | ||
| 520 | cip->attr_type.attr.owner = THIS_MODULE; | 526 | cip->attr_type.attr.owner = THIS_MODULE; |
| 521 | cip->attr_type.attr.name = "type"; | 527 | cip->attr_type.attr.name = "type"; |
| 522 | cip->attr_type.attr.mode = S_IRUGO; | 528 | cip->attr_type.attr.mode = S_IRUGO; |
| 523 | cip->attr_type.show = fp->show_type; | 529 | cip->attr_type.show = fp->show_type; |
| 524 | 530 | ||
| 525 | cip->attr_min.attr.owner = THIS_MODULE; | 531 | cip->attr_min.attr.owner = THIS_MODULE; |
| 526 | cip->attr_min.attr.name = "min_val"; | 532 | cip->attr_min.attr.name = "min_val"; |
| 527 | cip->attr_min.attr.mode = S_IRUGO; | 533 | cip->attr_min.attr.mode = S_IRUGO; |
| 528 | cip->attr_min.show = fp->show_min; | 534 | cip->attr_min.show = fp->show_min; |
| 529 | 535 | ||
| 530 | cip->attr_max.attr.owner = THIS_MODULE; | 536 | cip->attr_max.attr.owner = THIS_MODULE; |
| 531 | cip->attr_max.attr.name = "max_val"; | 537 | cip->attr_max.attr.name = "max_val"; |
| 532 | cip->attr_max.attr.mode = S_IRUGO; | 538 | cip->attr_max.attr.mode = S_IRUGO; |
| 533 | cip->attr_max.show = fp->show_max; | 539 | cip->attr_max.show = fp->show_max; |
| 534 | 540 | ||
| 535 | cip->attr_val.attr.owner = THIS_MODULE; | 541 | cip->attr_val.attr.owner = THIS_MODULE; |
| 536 | cip->attr_val.attr.name = "cur_val"; | 542 | cip->attr_val.attr.name = "cur_val"; |
| 537 | cip->attr_val.attr.mode = S_IRUGO; | 543 | cip->attr_val.attr.mode = S_IRUGO; |
| 538 | 544 | ||
| 539 | cip->attr_custom.attr.owner = THIS_MODULE; | 545 | cip->attr_custom.attr.owner = THIS_MODULE; |
| 540 | cip->attr_custom.attr.name = "custom_val"; | 546 | cip->attr_custom.attr.name = "custom_val"; |
| 541 | cip->attr_custom.attr.mode = S_IRUGO; | 547 | cip->attr_custom.attr.mode = S_IRUGO; |
| 542 | 548 | ||
| 543 | cip->attr_enum.attr.owner = THIS_MODULE; | 549 | cip->attr_enum.attr.owner = THIS_MODULE; |
| 544 | cip->attr_enum.attr.name = "enum_val"; | 550 | cip->attr_enum.attr.name = "enum_val"; |
| 545 | cip->attr_enum.attr.mode = S_IRUGO; | 551 | cip->attr_enum.attr.mode = S_IRUGO; |
| 546 | cip->attr_enum.show = fp->show_enum; | 552 | cip->attr_enum.show = fp->show_enum; |
| 547 | 553 | ||
| 548 | cip->attr_bits.attr.owner = THIS_MODULE; | 554 | cip->attr_bits.attr.owner = THIS_MODULE; |
| 549 | cip->attr_bits.attr.name = "bit_val"; | 555 | cip->attr_bits.attr.name = "bit_val"; |
| 550 | cip->attr_bits.attr.mode = S_IRUGO; | 556 | cip->attr_bits.attr.mode = S_IRUGO; |
| 551 | cip->attr_bits.show = fp->show_bits; | 557 | cip->attr_bits.show = fp->show_bits; |
| 552 | 558 | ||
| 553 | if (pvr2_ctrl_is_writable(cptr)) { | 559 | if (pvr2_ctrl_is_writable(cptr)) { |
| 554 | cip->attr_val.attr.mode |= S_IWUSR|S_IWGRP; | 560 | cip->attr_val.attr.mode |= S_IWUSR|S_IWGRP; |
| 555 | cip->attr_custom.attr.mode |= S_IWUSR|S_IWGRP; | 561 | cip->attr_custom.attr.mode |= S_IWUSR|S_IWGRP; |
| 556 | } | 562 | } |
| 557 | 563 | ||
| 558 | acnt = 0; | 564 | acnt = 0; |
| 559 | cip->attr_gen[acnt++] = &cip->attr_name.attr; | 565 | cip->attr_gen[acnt++] = &cip->attr_name.attr; |
| 560 | cip->attr_gen[acnt++] = &cip->attr_type.attr; | 566 | cip->attr_gen[acnt++] = &cip->attr_type.attr; |
| 561 | cip->attr_gen[acnt++] = &cip->attr_val.attr; | 567 | cip->attr_gen[acnt++] = &cip->attr_val.attr; |
| 562 | cip->attr_val.show = fp->show_val_norm; | 568 | cip->attr_val.show = fp->show_val_norm; |
| 563 | cip->attr_val.store = fp->store_val_norm; | 569 | cip->attr_val.store = fp->store_val_norm; |
| 564 | if (pvr2_ctrl_has_custom_symbols(cptr)) { | 570 | if (pvr2_ctrl_has_custom_symbols(cptr)) { |
| 565 | cip->attr_gen[acnt++] = &cip->attr_custom.attr; | 571 | cip->attr_gen[acnt++] = &cip->attr_custom.attr; |
| 566 | cip->attr_custom.show = fp->show_val_custom; | 572 | cip->attr_custom.show = fp->show_val_custom; |
| 567 | cip->attr_custom.store = fp->store_val_custom; | 573 | cip->attr_custom.store = fp->store_val_custom; |
| 568 | } | 574 | } |
| 569 | switch (pvr2_ctrl_get_type(cptr)) { | 575 | switch (pvr2_ctrl_get_type(cptr)) { |
| 570 | case pvr2_ctl_enum: | 576 | case pvr2_ctl_enum: |
| 571 | // Control is an enumeration | 577 | // Control is an enumeration |
| 572 | cip->attr_gen[acnt++] = &cip->attr_enum.attr; | 578 | cip->attr_gen[acnt++] = &cip->attr_enum.attr; |
| 573 | break; | 579 | break; |
| 574 | case pvr2_ctl_int: | 580 | case pvr2_ctl_int: |
| 575 | // Control is an integer | 581 | // Control is an integer |
| 576 | cip->attr_gen[acnt++] = &cip->attr_min.attr; | 582 | cip->attr_gen[acnt++] = &cip->attr_min.attr; |
| 577 | cip->attr_gen[acnt++] = &cip->attr_max.attr; | 583 | cip->attr_gen[acnt++] = &cip->attr_max.attr; |
| 578 | break; | 584 | break; |
| 579 | case pvr2_ctl_bitmask: | 585 | case pvr2_ctl_bitmask: |
| 580 | // Control is an bitmask | 586 | // Control is an bitmask |
| 581 | cip->attr_gen[acnt++] = &cip->attr_bits.attr; | 587 | cip->attr_gen[acnt++] = &cip->attr_bits.attr; |
| 582 | break; | 588 | break; |
| 583 | default: break; | 589 | default: break; |
| 584 | } | 590 | } |
| 585 | 591 | ||
| 586 | cnt = scnprintf(cip->name,sizeof(cip->name)-1,"ctl_%s", | 592 | cnt = scnprintf(cip->name,sizeof(cip->name)-1,"ctl_%s", |
| 587 | pvr2_ctrl_get_name(cptr)); | 593 | pvr2_ctrl_get_name(cptr)); |
| 588 | cip->name[cnt] = 0; | 594 | cip->name[cnt] = 0; |
| 589 | cip->grp.name = cip->name; | 595 | cip->grp.name = cip->name; |
| 590 | cip->grp.attrs = cip->attr_gen; | 596 | cip->grp.attrs = cip->attr_gen; |
| 591 | 597 | ||
| 592 | sysfs_create_group(&sfp->class_dev->kobj,&cip->grp); | 598 | ret = sysfs_create_group(&sfp->class_dev->kobj,&cip->grp); |
| 599 | if (ret) { | ||
| 600 | printk(KERN_WARNING "%s: sysfs_create_group error: %d\n", | ||
| 601 | __FUNCTION__, ret); | ||
| 602 | return; | ||
| 603 | } | ||
| 604 | cip->created_ok = !0; | ||
| 593 | } | 605 | } |
| 594 | 606 | ||
| 595 | #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC | 607 | #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC |
| 596 | static ssize_t debuginfo_show(struct class_device *,char *); | 608 | static ssize_t debuginfo_show(struct class_device *,char *); |
| 597 | static ssize_t debugcmd_show(struct class_device *,char *); | 609 | static ssize_t debugcmd_show(struct class_device *,char *); |
| 598 | static ssize_t debugcmd_store(struct class_device *,const char *,size_t count); | 610 | static ssize_t debugcmd_store(struct class_device *,const char *,size_t count); |
| 599 | 611 | ||
| 600 | static void pvr2_sysfs_add_debugifc(struct pvr2_sysfs *sfp) | 612 | static void pvr2_sysfs_add_debugifc(struct pvr2_sysfs *sfp) |
| 601 | { | 613 | { |
| 602 | struct pvr2_sysfs_debugifc *dip; | 614 | struct pvr2_sysfs_debugifc *dip; |
| 603 | int ret; | 615 | int ret; |
| 604 | 616 | ||
| 605 | dip = kmalloc(sizeof(*dip),GFP_KERNEL); | 617 | dip = kmalloc(sizeof(*dip),GFP_KERNEL); |
| 606 | if (!dip) return; | 618 | if (!dip) return; |
| 607 | memset(dip,0,sizeof(*dip)); | 619 | memset(dip,0,sizeof(*dip)); |
| 608 | dip->attr_debugcmd.attr.owner = THIS_MODULE; | 620 | dip->attr_debugcmd.attr.owner = THIS_MODULE; |
| 609 | dip->attr_debugcmd.attr.name = "debugcmd"; | 621 | dip->attr_debugcmd.attr.name = "debugcmd"; |
| 610 | dip->attr_debugcmd.attr.mode = S_IRUGO|S_IWUSR|S_IWGRP; | 622 | dip->attr_debugcmd.attr.mode = S_IRUGO|S_IWUSR|S_IWGRP; |
| 611 | dip->attr_debugcmd.show = debugcmd_show; | 623 | dip->attr_debugcmd.show = debugcmd_show; |
| 612 | dip->attr_debugcmd.store = debugcmd_store; | 624 | dip->attr_debugcmd.store = debugcmd_store; |
| 613 | dip->attr_debuginfo.attr.owner = THIS_MODULE; | 625 | dip->attr_debuginfo.attr.owner = THIS_MODULE; |
| 614 | dip->attr_debuginfo.attr.name = "debuginfo"; | 626 | dip->attr_debuginfo.attr.name = "debuginfo"; |
| 615 | dip->attr_debuginfo.attr.mode = S_IRUGO; | 627 | dip->attr_debuginfo.attr.mode = S_IRUGO; |
| 616 | dip->attr_debuginfo.show = debuginfo_show; | 628 | dip->attr_debuginfo.show = debuginfo_show; |
| 617 | sfp->debugifc = dip; | 629 | sfp->debugifc = dip; |
| 618 | ret = class_device_create_file(sfp->class_dev,&dip->attr_debugcmd); | 630 | ret = class_device_create_file(sfp->class_dev,&dip->attr_debugcmd); |
| 619 | if (ret < 0) | 631 | if (ret < 0) { |
| 620 | printk(KERN_WARNING "%s: class_device_create_file error: %d\n", | 632 | printk(KERN_WARNING "%s: class_device_create_file error: %d\n", |
| 621 | __FUNCTION__, ret); | 633 | __FUNCTION__, ret); |
| 634 | } else { | ||
| 635 | dip->debugcmd_created_ok = !0; | ||
| 636 | } | ||
| 622 | ret = class_device_create_file(sfp->class_dev,&dip->attr_debuginfo); | 637 | ret = class_device_create_file(sfp->class_dev,&dip->attr_debuginfo); |
| 623 | if (ret < 0) | 638 | if (ret < 0) { |
| 624 | printk(KERN_WARNING "%s: class_device_create_file error: %d\n", | 639 | printk(KERN_WARNING "%s: class_device_create_file error: %d\n", |
| 625 | __FUNCTION__, ret); | 640 | __FUNCTION__, ret); |
| 641 | } else { | ||
| 642 | dip->debuginfo_created_ok = !0; | ||
| 643 | } | ||
| 626 | } | 644 | } |
| 627 | 645 | ||
| 628 | 646 | ||
| 629 | static void pvr2_sysfs_tear_down_debugifc(struct pvr2_sysfs *sfp) | 647 | static void pvr2_sysfs_tear_down_debugifc(struct pvr2_sysfs *sfp) |
| 630 | { | 648 | { |
| 631 | if (!sfp->debugifc) return; | 649 | if (!sfp->debugifc) return; |
| 632 | class_device_remove_file(sfp->class_dev, | 650 | if (sfp->debugifc->debuginfo_created_ok) { |
| 633 | &sfp->debugifc->attr_debuginfo); | 651 | class_device_remove_file(sfp->class_dev, |
| 634 | class_device_remove_file(sfp->class_dev,&sfp->debugifc->attr_debugcmd); | 652 | &sfp->debugifc->attr_debuginfo); |
| 653 | } | ||
| 654 | if (sfp->debugifc->debugcmd_created_ok) { | ||
| 655 | class_device_remove_file(sfp->class_dev, | ||
| 656 | &sfp->debugifc->attr_debugcmd); | ||
| 657 | } | ||
| 635 | kfree(sfp->debugifc); | 658 | kfree(sfp->debugifc); |
| 636 | sfp->debugifc = NULL; | 659 | sfp->debugifc = NULL; |
| 637 | } | 660 | } |
| 638 | #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */ | 661 | #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */ |
| 639 | 662 | ||
| 640 | 663 | ||
| 641 | static void pvr2_sysfs_add_controls(struct pvr2_sysfs *sfp) | 664 | static void pvr2_sysfs_add_controls(struct pvr2_sysfs *sfp) |
| 642 | { | 665 | { |
| 643 | unsigned int idx,cnt; | 666 | unsigned int idx,cnt; |
| 644 | cnt = pvr2_hdw_get_ctrl_count(sfp->channel.hdw); | 667 | cnt = pvr2_hdw_get_ctrl_count(sfp->channel.hdw); |
| 645 | for (idx = 0; idx < cnt; idx++) { | 668 | for (idx = 0; idx < cnt; idx++) { |
| 646 | pvr2_sysfs_add_control(sfp,idx); | 669 | pvr2_sysfs_add_control(sfp,idx); |
| 647 | } | 670 | } |
| 648 | } | 671 | } |
| 649 | 672 | ||
| 650 | 673 | ||
| 651 | static void pvr2_sysfs_tear_down_controls(struct pvr2_sysfs *sfp) | 674 | static void pvr2_sysfs_tear_down_controls(struct pvr2_sysfs *sfp) |
| 652 | { | 675 | { |
| 653 | struct pvr2_sysfs_ctl_item *cip1,*cip2; | 676 | struct pvr2_sysfs_ctl_item *cip1,*cip2; |
| 654 | for (cip1 = sfp->item_first; cip1; cip1 = cip2) { | 677 | for (cip1 = sfp->item_first; cip1; cip1 = cip2) { |
| 655 | cip2 = cip1->item_next; | 678 | cip2 = cip1->item_next; |
| 656 | sysfs_remove_group(&sfp->class_dev->kobj,&cip1->grp); | 679 | if (cip1->created_ok) { |
| 680 | sysfs_remove_group(&sfp->class_dev->kobj,&cip1->grp); | ||
| 681 | } | ||
| 657 | pvr2_sysfs_trace("Destroying pvr2_sysfs_ctl_item id=%p",cip1); | 682 | pvr2_sysfs_trace("Destroying pvr2_sysfs_ctl_item id=%p",cip1); |
| 658 | kfree(cip1); | 683 | kfree(cip1); |
| 659 | } | 684 | } |
| 660 | } | 685 | } |
| 661 | 686 | ||
| 662 | 687 | ||
| 663 | static void pvr2_sysfs_class_release(struct class *class) | 688 | static void pvr2_sysfs_class_release(struct class *class) |
| 664 | { | 689 | { |
| 665 | struct pvr2_sysfs_class *clp; | 690 | struct pvr2_sysfs_class *clp; |
| 666 | clp = container_of(class,struct pvr2_sysfs_class,class); | 691 | clp = container_of(class,struct pvr2_sysfs_class,class); |
| 667 | pvr2_sysfs_trace("Destroying pvr2_sysfs_class id=%p",clp); | 692 | pvr2_sysfs_trace("Destroying pvr2_sysfs_class id=%p",clp); |
| 668 | kfree(clp); | 693 | kfree(clp); |
| 669 | } | 694 | } |
| 670 | 695 | ||
| 671 | 696 | ||
| 672 | static void pvr2_sysfs_release(struct class_device *class_dev) | 697 | static void pvr2_sysfs_release(struct class_device *class_dev) |
| 673 | { | 698 | { |
| 674 | pvr2_sysfs_trace("Releasing class_dev id=%p",class_dev); | 699 | pvr2_sysfs_trace("Releasing class_dev id=%p",class_dev); |
| 675 | kfree(class_dev); | 700 | kfree(class_dev); |
| 676 | } | 701 | } |
| 677 | 702 | ||
| 678 | 703 | ||
| 679 | static void class_dev_destroy(struct pvr2_sysfs *sfp) | 704 | static void class_dev_destroy(struct pvr2_sysfs *sfp) |
| 680 | { | 705 | { |
| 681 | if (!sfp->class_dev) return; | 706 | if (!sfp->class_dev) return; |
| 682 | #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC | 707 | #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC |
| 683 | pvr2_sysfs_tear_down_debugifc(sfp); | 708 | pvr2_sysfs_tear_down_debugifc(sfp); |
| 684 | #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */ | 709 | #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */ |
| 685 | pvr2_sysfs_tear_down_controls(sfp); | 710 | pvr2_sysfs_tear_down_controls(sfp); |
| 686 | class_device_remove_file(sfp->class_dev,&sfp->attr_v4l_minor_number); | 711 | if (sfp->v4l_minor_number_created_ok) { |
| 687 | class_device_remove_file(sfp->class_dev,&sfp->attr_unit_number); | 712 | class_device_remove_file(sfp->class_dev, |
| 713 | &sfp->attr_v4l_minor_number); | ||
| 714 | } | ||
| 715 | if (sfp->unit_number_created_ok) { | ||
| 716 | class_device_remove_file(sfp->class_dev, | ||
| 717 | &sfp->attr_unit_number); | ||
| 718 | } | ||
| 688 | pvr2_sysfs_trace("Destroying class_dev id=%p",sfp->class_dev); | 719 | pvr2_sysfs_trace("Destroying class_dev id=%p",sfp->class_dev); |
| 689 | sfp->class_dev->class_data = NULL; | 720 | sfp->class_dev->class_data = NULL; |
| 690 | class_device_unregister(sfp->class_dev); | 721 | class_device_unregister(sfp->class_dev); |
| 691 | sfp->class_dev = NULL; | 722 | sfp->class_dev = NULL; |
| 692 | } | 723 | } |
| 693 | 724 | ||
| 694 | 725 | ||
| 695 | static ssize_t v4l_minor_number_show(struct class_device *class_dev,char *buf) | 726 | static ssize_t v4l_minor_number_show(struct class_device *class_dev,char *buf) |
| 696 | { | 727 | { |
| 697 | struct pvr2_sysfs *sfp; | 728 | struct pvr2_sysfs *sfp; |
| 698 | sfp = (struct pvr2_sysfs *)class_dev->class_data; | 729 | sfp = (struct pvr2_sysfs *)class_dev->class_data; |
| 699 | if (!sfp) return -EINVAL; | 730 | if (!sfp) return -EINVAL; |
| 700 | return scnprintf(buf,PAGE_SIZE,"%d\n", | 731 | return scnprintf(buf,PAGE_SIZE,"%d\n", |
| 701 | pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw)); | 732 | pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw)); |
| 702 | } | 733 | } |
| 703 | 734 | ||
| 704 | 735 | ||
| 705 | static ssize_t unit_number_show(struct class_device *class_dev,char *buf) | 736 | static ssize_t unit_number_show(struct class_device *class_dev,char *buf) |
| 706 | { | 737 | { |
| 707 | struct pvr2_sysfs *sfp; | 738 | struct pvr2_sysfs *sfp; |
| 708 | sfp = (struct pvr2_sysfs *)class_dev->class_data; | 739 | sfp = (struct pvr2_sysfs *)class_dev->class_data; |
| 709 | if (!sfp) return -EINVAL; | 740 | if (!sfp) return -EINVAL; |
| 710 | return scnprintf(buf,PAGE_SIZE,"%d\n", | 741 | return scnprintf(buf,PAGE_SIZE,"%d\n", |
| 711 | pvr2_hdw_get_unit_number(sfp->channel.hdw)); | 742 | pvr2_hdw_get_unit_number(sfp->channel.hdw)); |
| 712 | } | 743 | } |
| 713 | 744 | ||
| 714 | 745 | ||
| 715 | static void class_dev_create(struct pvr2_sysfs *sfp, | 746 | static void class_dev_create(struct pvr2_sysfs *sfp, |
| 716 | struct pvr2_sysfs_class *class_ptr) | 747 | struct pvr2_sysfs_class *class_ptr) |
| 717 | { | 748 | { |
| 718 | struct usb_device *usb_dev; | 749 | struct usb_device *usb_dev; |
| 719 | struct class_device *class_dev; | 750 | struct class_device *class_dev; |
| 720 | int ret; | 751 | int ret; |
| 721 | 752 | ||
| 722 | usb_dev = pvr2_hdw_get_dev(sfp->channel.hdw); | 753 | usb_dev = pvr2_hdw_get_dev(sfp->channel.hdw); |
| 723 | if (!usb_dev) return; | 754 | if (!usb_dev) return; |
| 724 | class_dev = kmalloc(sizeof(*class_dev),GFP_KERNEL); | 755 | class_dev = kmalloc(sizeof(*class_dev),GFP_KERNEL); |
| 725 | if (!class_dev) return; | 756 | if (!class_dev) return; |
| 726 | memset(class_dev,0,sizeof(*class_dev)); | 757 | memset(class_dev,0,sizeof(*class_dev)); |
| 727 | 758 | ||
| 728 | pvr2_sysfs_trace("Creating class_dev id=%p",class_dev); | 759 | pvr2_sysfs_trace("Creating class_dev id=%p",class_dev); |
| 729 | 760 | ||
| 730 | class_dev->class = &class_ptr->class; | 761 | class_dev->class = &class_ptr->class; |
| 731 | if (pvr2_hdw_get_sn(sfp->channel.hdw)) { | 762 | if (pvr2_hdw_get_sn(sfp->channel.hdw)) { |
| 732 | snprintf(class_dev->class_id,BUS_ID_SIZE,"sn-%lu", | 763 | snprintf(class_dev->class_id,BUS_ID_SIZE,"sn-%lu", |
| 733 | pvr2_hdw_get_sn(sfp->channel.hdw)); | 764 | pvr2_hdw_get_sn(sfp->channel.hdw)); |
| 734 | } else if (pvr2_hdw_get_unit_number(sfp->channel.hdw) >= 0) { | 765 | } else if (pvr2_hdw_get_unit_number(sfp->channel.hdw) >= 0) { |
| 735 | snprintf(class_dev->class_id,BUS_ID_SIZE,"unit-%c", | 766 | snprintf(class_dev->class_id,BUS_ID_SIZE,"unit-%c", |
| 736 | pvr2_hdw_get_unit_number(sfp->channel.hdw) + 'a'); | 767 | pvr2_hdw_get_unit_number(sfp->channel.hdw) + 'a'); |
| 737 | } else { | 768 | } else { |
| 738 | kfree(class_dev); | 769 | kfree(class_dev); |
| 739 | return; | 770 | return; |
| 740 | } | 771 | } |
| 741 | 772 | ||
| 742 | class_dev->dev = &usb_dev->dev; | 773 | class_dev->dev = &usb_dev->dev; |
| 743 | 774 | ||
| 744 | sfp->class_dev = class_dev; | 775 | sfp->class_dev = class_dev; |
| 745 | class_dev->class_data = sfp; | 776 | class_dev->class_data = sfp; |
| 746 | ret = class_device_register(class_dev); | 777 | ret = class_device_register(class_dev); |
| 747 | if (ret) { | 778 | if (ret) { |
| 748 | printk(KERN_ERR "%s: class_device_register failed\n", | 779 | printk(KERN_ERR "%s: class_device_register failed\n", |
| 749 | __FUNCTION__); | 780 | __FUNCTION__); |
| 750 | kfree(class_dev); | 781 | kfree(class_dev); |
| 751 | return; | 782 | return; |
| 752 | } | 783 | } |
| 753 | 784 | ||
| 754 | sfp->attr_v4l_minor_number.attr.owner = THIS_MODULE; | 785 | sfp->attr_v4l_minor_number.attr.owner = THIS_MODULE; |
| 755 | sfp->attr_v4l_minor_number.attr.name = "v4l_minor_number"; | 786 | sfp->attr_v4l_minor_number.attr.name = "v4l_minor_number"; |
| 756 | sfp->attr_v4l_minor_number.attr.mode = S_IRUGO; | 787 | sfp->attr_v4l_minor_number.attr.mode = S_IRUGO; |
| 757 | sfp->attr_v4l_minor_number.show = v4l_minor_number_show; | 788 | sfp->attr_v4l_minor_number.show = v4l_minor_number_show; |
| 758 | sfp->attr_v4l_minor_number.store = NULL; | 789 | sfp->attr_v4l_minor_number.store = NULL; |
| 759 | ret = class_device_create_file(sfp->class_dev,&sfp->attr_v4l_minor_number); | 790 | ret = class_device_create_file(sfp->class_dev, |
| 760 | if (ret < 0) | 791 | &sfp->attr_v4l_minor_number); |
| 792 | if (ret < 0) { | ||
| 761 | printk(KERN_WARNING "%s: class_device_create_file error: %d\n", | 793 | printk(KERN_WARNING "%s: class_device_create_file error: %d\n", |
| 762 | __FUNCTION__, ret); | 794 | __FUNCTION__, ret); |
| 795 | } else { | ||
| 796 | sfp->v4l_minor_number_created_ok = !0; | ||
| 797 | } | ||
| 763 | 798 | ||
| 764 | sfp->attr_unit_number.attr.owner = THIS_MODULE; | 799 | sfp->attr_unit_number.attr.owner = THIS_MODULE; |
| 765 | sfp->attr_unit_number.attr.name = "unit_number"; | 800 | sfp->attr_unit_number.attr.name = "unit_number"; |
| 766 | sfp->attr_unit_number.attr.mode = S_IRUGO; | 801 | sfp->attr_unit_number.attr.mode = S_IRUGO; |
| 767 | sfp->attr_unit_number.show = unit_number_show; | 802 | sfp->attr_unit_number.show = unit_number_show; |
| 768 | sfp->attr_unit_number.store = NULL; | 803 | sfp->attr_unit_number.store = NULL; |
| 769 | ret = class_device_create_file(sfp->class_dev,&sfp->attr_unit_number); | 804 | ret = class_device_create_file(sfp->class_dev,&sfp->attr_unit_number); |
| 770 | if (ret < 0) | 805 | if (ret < 0) { |
| 771 | printk(KERN_WARNING "%s: class_device_create_file error: %d\n", | 806 | printk(KERN_WARNING "%s: class_device_create_file error: %d\n", |
| 772 | __FUNCTION__, ret); | 807 | __FUNCTION__, ret); |
| 808 | } else { | ||
| 809 | sfp->unit_number_created_ok = !0; | ||
| 810 | } | ||
| 773 | 811 | ||
| 774 | pvr2_sysfs_add_controls(sfp); | 812 | pvr2_sysfs_add_controls(sfp); |
| 775 | #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC | 813 | #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC |
| 776 | pvr2_sysfs_add_debugifc(sfp); | 814 | pvr2_sysfs_add_debugifc(sfp); |
| 777 | #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */ | 815 | #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */ |
| 778 | } | 816 | } |
| 779 | 817 | ||
| 780 | 818 | ||
| 781 | static void pvr2_sysfs_internal_check(struct pvr2_channel *chp) | 819 | static void pvr2_sysfs_internal_check(struct pvr2_channel *chp) |
| 782 | { | 820 | { |
| 783 | struct pvr2_sysfs *sfp; | 821 | struct pvr2_sysfs *sfp; |
| 784 | sfp = container_of(chp,struct pvr2_sysfs,channel); | 822 | sfp = container_of(chp,struct pvr2_sysfs,channel); |
| 785 | if (!sfp->channel.mc_head->disconnect_flag) return; | 823 | if (!sfp->channel.mc_head->disconnect_flag) return; |
| 786 | pvr2_trace(PVR2_TRACE_STRUCT,"Destroying pvr2_sysfs id=%p",sfp); | 824 | pvr2_trace(PVR2_TRACE_STRUCT,"Destroying pvr2_sysfs id=%p",sfp); |
| 787 | class_dev_destroy(sfp); | 825 | class_dev_destroy(sfp); |
| 788 | pvr2_channel_done(&sfp->channel); | 826 | pvr2_channel_done(&sfp->channel); |
| 789 | kfree(sfp); | 827 | kfree(sfp); |
| 790 | } | 828 | } |
| 791 | 829 | ||
| 792 | 830 | ||
| 793 | struct pvr2_sysfs *pvr2_sysfs_create(struct pvr2_context *mp, | 831 | struct pvr2_sysfs *pvr2_sysfs_create(struct pvr2_context *mp, |
| 794 | struct pvr2_sysfs_class *class_ptr) | 832 | struct pvr2_sysfs_class *class_ptr) |
| 795 | { | 833 | { |
| 796 | struct pvr2_sysfs *sfp; | 834 | struct pvr2_sysfs *sfp; |
| 797 | sfp = kmalloc(sizeof(*sfp),GFP_KERNEL); | 835 | sfp = kmalloc(sizeof(*sfp),GFP_KERNEL); |
| 798 | if (!sfp) return sfp; | 836 | if (!sfp) return sfp; |
| 799 | memset(sfp,0,sizeof(*sfp)); | 837 | memset(sfp,0,sizeof(*sfp)); |
| 800 | pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr2_sysfs id=%p",sfp); | 838 | pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr2_sysfs id=%p",sfp); |
| 801 | pvr2_channel_init(&sfp->channel,mp); | 839 | pvr2_channel_init(&sfp->channel,mp); |
| 802 | sfp->channel.check_func = pvr2_sysfs_internal_check; | 840 | sfp->channel.check_func = pvr2_sysfs_internal_check; |
| 803 | 841 | ||
| 804 | class_dev_create(sfp,class_ptr); | 842 | class_dev_create(sfp,class_ptr); |
| 805 | return sfp; | 843 | return sfp; |
| 806 | } | 844 | } |
| 807 | 845 | ||
| 808 | 846 | ||
| 809 | static int pvr2_sysfs_hotplug(struct class_device *cd,char **envp, | 847 | static int pvr2_sysfs_hotplug(struct class_device *cd,char **envp, |
| 810 | int numenvp,char *buf,int size) | 848 | int numenvp,char *buf,int size) |
| 811 | { | 849 | { |
| 812 | /* Even though we don't do anything here, we still need this function | 850 | /* Even though we don't do anything here, we still need this function |
| 813 | because sysfs will still try to call it. */ | 851 | because sysfs will still try to call it. */ |
| 814 | return 0; | 852 | return 0; |
| 815 | } | 853 | } |
| 816 | 854 | ||
| 817 | struct pvr2_sysfs_class *pvr2_sysfs_class_create(void) | 855 | struct pvr2_sysfs_class *pvr2_sysfs_class_create(void) |
| 818 | { | 856 | { |
| 819 | struct pvr2_sysfs_class *clp; | 857 | struct pvr2_sysfs_class *clp; |
| 820 | clp = kmalloc(sizeof(*clp),GFP_KERNEL); | 858 | clp = kmalloc(sizeof(*clp),GFP_KERNEL); |
| 821 | if (!clp) return clp; | 859 | if (!clp) return clp; |
| 822 | memset(clp,0,sizeof(*clp)); | 860 | memset(clp,0,sizeof(*clp)); |
| 823 | pvr2_sysfs_trace("Creating pvr2_sysfs_class id=%p",clp); | 861 | pvr2_sysfs_trace("Creating pvr2_sysfs_class id=%p",clp); |
| 824 | clp->class.name = "pvrusb2"; | 862 | clp->class.name = "pvrusb2"; |
| 825 | clp->class.class_release = pvr2_sysfs_class_release; | 863 | clp->class.class_release = pvr2_sysfs_class_release; |
| 826 | clp->class.release = pvr2_sysfs_release; | 864 | clp->class.release = pvr2_sysfs_release; |
| 827 | clp->class.uevent = pvr2_sysfs_hotplug; | 865 | clp->class.uevent = pvr2_sysfs_hotplug; |
| 828 | if (class_register(&clp->class)) { | 866 | if (class_register(&clp->class)) { |
| 829 | pvr2_sysfs_trace( | 867 | pvr2_sysfs_trace( |
| 830 | "Registration failed for pvr2_sysfs_class id=%p",clp); | 868 | "Registration failed for pvr2_sysfs_class id=%p",clp); |
| 831 | kfree(clp); | 869 | kfree(clp); |
| 832 | clp = NULL; | 870 | clp = NULL; |
| 833 | } | 871 | } |
| 834 | return clp; | 872 | return clp; |
| 835 | } | 873 | } |
| 836 | 874 | ||
| 837 | 875 | ||
| 838 | void pvr2_sysfs_class_destroy(struct pvr2_sysfs_class *clp) | 876 | void pvr2_sysfs_class_destroy(struct pvr2_sysfs_class *clp) |
| 839 | { | 877 | { |
| 840 | class_unregister(&clp->class); | 878 | class_unregister(&clp->class); |
| 841 | } | 879 | } |
| 842 | 880 | ||
| 843 | 881 | ||
| 844 | #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC | 882 | #ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC |
| 845 | static ssize_t debuginfo_show(struct class_device *class_dev,char *buf) | 883 | static ssize_t debuginfo_show(struct class_device *class_dev,char *buf) |
| 846 | { | 884 | { |
| 847 | struct pvr2_sysfs *sfp; | 885 | struct pvr2_sysfs *sfp; |
| 848 | sfp = (struct pvr2_sysfs *)class_dev->class_data; | 886 | sfp = (struct pvr2_sysfs *)class_dev->class_data; |
| 849 | if (!sfp) return -EINVAL; | 887 | if (!sfp) return -EINVAL; |
| 850 | pvr2_hdw_trigger_module_log(sfp->channel.hdw); | 888 | pvr2_hdw_trigger_module_log(sfp->channel.hdw); |
| 851 | return pvr2_debugifc_print_info(sfp->channel.hdw,buf,PAGE_SIZE); | 889 | return pvr2_debugifc_print_info(sfp->channel.hdw,buf,PAGE_SIZE); |
| 852 | } | 890 | } |
| 853 | 891 | ||
| 854 | 892 | ||
| 855 | static ssize_t debugcmd_show(struct class_device *class_dev,char *buf) | 893 | static ssize_t debugcmd_show(struct class_device *class_dev,char *buf) |
| 856 | { | 894 | { |
| 857 | struct pvr2_sysfs *sfp; | 895 | struct pvr2_sysfs *sfp; |
| 858 | sfp = (struct pvr2_sysfs *)class_dev->class_data; | 896 | sfp = (struct pvr2_sysfs *)class_dev->class_data; |
| 859 | if (!sfp) return -EINVAL; | 897 | if (!sfp) return -EINVAL; |
| 860 | return pvr2_debugifc_print_status(sfp->channel.hdw,buf,PAGE_SIZE); | 898 | return pvr2_debugifc_print_status(sfp->channel.hdw,buf,PAGE_SIZE); |
| 861 | } | 899 | } |
| 862 | 900 | ||
| 863 | 901 | ||
| 864 | static ssize_t debugcmd_store(struct class_device *class_dev, | 902 | static ssize_t debugcmd_store(struct class_device *class_dev, |
| 865 | const char *buf,size_t count) | 903 | const char *buf,size_t count) |
| 866 | { | 904 | { |
| 867 | struct pvr2_sysfs *sfp; | 905 | struct pvr2_sysfs *sfp; |
| 868 | int ret; | 906 | int ret; |
| 869 | 907 | ||
| 870 | sfp = (struct pvr2_sysfs *)class_dev->class_data; | 908 | sfp = (struct pvr2_sysfs *)class_dev->class_data; |
| 871 | if (!sfp) return -EINVAL; | 909 | if (!sfp) return -EINVAL; |
| 872 | 910 | ||
| 873 | ret = pvr2_debugifc_docmd(sfp->channel.hdw,buf,count); | 911 | ret = pvr2_debugifc_docmd(sfp->channel.hdw,buf,count); |
| 874 | if (ret < 0) return ret; | 912 | if (ret < 0) return ret; |
| 875 | return count; | 913 | return count; |
| 876 | } | 914 | } |
| 877 | #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */ | 915 | #endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */ |
| 878 | 916 | ||
| 879 | 917 | ||
| 880 | /* | 918 | /* |
| 881 | Stuff for Emacs to see, in order to encourage consistent editing style: | 919 | Stuff for Emacs to see, in order to encourage consistent editing style: |
| 882 | *** Local Variables: *** | 920 | *** Local Variables: *** |
| 883 | *** mode: c *** | 921 | *** mode: c *** |
| 884 | *** fill-column: 75 *** | 922 | *** fill-column: 75 *** |
| 885 | *** tab-width: 8 *** | 923 | *** tab-width: 8 *** |
| 886 | *** c-basic-offset: 8 *** | 924 | *** c-basic-offset: 8 *** |
| 887 | *** End: *** | 925 | *** End: *** |
| 888 | */ | 926 | */ |
| 889 | 927 |