Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * drivers/usb/core/sysfs.c |
| 3 | * |
| 4 | * (C) Copyright 2002 David Brownell |
| 5 | * (C) Copyright 2002,2004 Greg Kroah-Hartman |
| 6 | * (C) Copyright 2002,2004 IBM Corp. |
| 7 | * |
| 8 | * All of the sysfs file attributes for usb devices and interfaces. |
| 9 | * |
| 10 | */ |
| 11 | |
| 12 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/kernel.h> |
Alan Stern | 2add522 | 2007-03-20 14:59:39 -0400 | [diff] [blame] | 14 | #include <linux/string.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/usb.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include "usb.h" |
| 17 | |
| 18 | /* Active configuration fields */ |
| 19 | #define usb_actconfig_show(field, multiplier, format_string) \ |
Oliver Neukum | 9251644 | 2007-01-23 15:55:28 -0500 | [diff] [blame] | 20 | static ssize_t show_##field(struct device *dev, \ |
Alan Stern | b724ae7 | 2005-10-24 15:36:00 -0400 | [diff] [blame] | 21 | struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | { \ |
| 23 | struct usb_device *udev; \ |
| 24 | struct usb_host_config *actconfig; \ |
| 25 | \ |
Oliver Neukum | 9251644 | 2007-01-23 15:55:28 -0500 | [diff] [blame] | 26 | udev = to_usb_device(dev); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | actconfig = udev->actconfig; \ |
| 28 | if (actconfig) \ |
Oliver Neukum | 9251644 | 2007-01-23 15:55:28 -0500 | [diff] [blame] | 29 | return sprintf(buf, format_string, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | actconfig->desc.field * multiplier); \ |
| 31 | else \ |
| 32 | return 0; \ |
| 33 | } \ |
| 34 | |
| 35 | #define usb_actconfig_attr(field, multiplier, format_string) \ |
| 36 | usb_actconfig_show(field, multiplier, format_string) \ |
| 37 | static DEVICE_ATTR(field, S_IRUGO, show_##field, NULL); |
| 38 | |
Oliver Neukum | 9251644 | 2007-01-23 15:55:28 -0500 | [diff] [blame] | 39 | usb_actconfig_attr(bNumInterfaces, 1, "%2d\n") |
| 40 | usb_actconfig_attr(bmAttributes, 1, "%2x\n") |
| 41 | usb_actconfig_attr(bMaxPower, 2, "%3dmA\n") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
Alan Stern | b724ae7 | 2005-10-24 15:36:00 -0400 | [diff] [blame] | 43 | static ssize_t show_configuration_string(struct device *dev, |
| 44 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | { |
| 46 | struct usb_device *udev; |
| 47 | struct usb_host_config *actconfig; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Oliver Neukum | 9251644 | 2007-01-23 15:55:28 -0500 | [diff] [blame] | 49 | udev = to_usb_device(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | actconfig = udev->actconfig; |
| 51 | if ((!actconfig) || (!actconfig->string)) |
| 52 | return 0; |
Alan Stern | 4f62efe | 2005-10-24 16:24:14 -0400 | [diff] [blame] | 53 | return sprintf(buf, "%s\n", actconfig->string); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | } |
| 55 | static DEVICE_ATTR(configuration, S_IRUGO, show_configuration_string, NULL); |
| 56 | |
| 57 | /* configuration value is always present, and r/w */ |
| 58 | usb_actconfig_show(bConfigurationValue, 1, "%u\n"); |
| 59 | |
| 60 | static ssize_t |
Oliver Neukum | 9251644 | 2007-01-23 15:55:28 -0500 | [diff] [blame] | 61 | set_bConfigurationValue(struct device *dev, struct device_attribute *attr, |
Alan Stern | b724ae7 | 2005-10-24 15:36:00 -0400 | [diff] [blame] | 62 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | { |
Oliver Neukum | 9251644 | 2007-01-23 15:55:28 -0500 | [diff] [blame] | 64 | struct usb_device *udev = to_usb_device(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | int config, value; |
| 66 | |
Alan Stern | 3f141e2a | 2007-02-08 16:40:43 -0500 | [diff] [blame] | 67 | if (sscanf(buf, "%d", &config) != 1 || config < -1 || config > 255) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | return -EINVAL; |
| 69 | usb_lock_device(udev); |
Oliver Neukum | 9251644 | 2007-01-23 15:55:28 -0500 | [diff] [blame] | 70 | value = usb_set_configuration(udev, config); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | usb_unlock_device(udev); |
| 72 | return (value < 0) ? value : count; |
| 73 | } |
| 74 | |
| 75 | static DEVICE_ATTR(bConfigurationValue, S_IRUGO | S_IWUSR, |
| 76 | show_bConfigurationValue, set_bConfigurationValue); |
| 77 | |
| 78 | /* String fields */ |
| 79 | #define usb_string_attr(name) \ |
Alan Stern | b724ae7 | 2005-10-24 15:36:00 -0400 | [diff] [blame] | 80 | static ssize_t show_##name(struct device *dev, \ |
| 81 | struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | { \ |
| 83 | struct usb_device *udev; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | \ |
Oliver Neukum | 9251644 | 2007-01-23 15:55:28 -0500 | [diff] [blame] | 85 | udev = to_usb_device(dev); \ |
Alan Stern | 4f62efe | 2005-10-24 16:24:14 -0400 | [diff] [blame] | 86 | return sprintf(buf, "%s\n", udev->name); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | } \ |
| 88 | static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL); |
| 89 | |
| 90 | usb_string_attr(product); |
| 91 | usb_string_attr(manufacturer); |
| 92 | usb_string_attr(serial); |
| 93 | |
| 94 | static ssize_t |
Oliver Neukum | 9251644 | 2007-01-23 15:55:28 -0500 | [diff] [blame] | 95 | show_speed(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | { |
| 97 | struct usb_device *udev; |
| 98 | char *speed; |
| 99 | |
Oliver Neukum | 9251644 | 2007-01-23 15:55:28 -0500 | [diff] [blame] | 100 | udev = to_usb_device(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
| 102 | switch (udev->speed) { |
| 103 | case USB_SPEED_LOW: |
| 104 | speed = "1.5"; |
| 105 | break; |
| 106 | case USB_SPEED_UNKNOWN: |
| 107 | case USB_SPEED_FULL: |
| 108 | speed = "12"; |
| 109 | break; |
| 110 | case USB_SPEED_HIGH: |
| 111 | speed = "480"; |
| 112 | break; |
| 113 | default: |
| 114 | speed = "unknown"; |
| 115 | } |
Oliver Neukum | 9251644 | 2007-01-23 15:55:28 -0500 | [diff] [blame] | 116 | return sprintf(buf, "%s\n", speed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | } |
| 118 | static DEVICE_ATTR(speed, S_IRUGO, show_speed, NULL); |
| 119 | |
| 120 | static ssize_t |
Alan Stern | 83f7d95 | 2007-04-25 15:15:43 -0400 | [diff] [blame] | 121 | show_busnum(struct device *dev, struct device_attribute *attr, char *buf) |
| 122 | { |
| 123 | struct usb_device *udev; |
| 124 | |
| 125 | udev = to_usb_device(dev); |
| 126 | return sprintf(buf, "%d\n", udev->bus->busnum); |
| 127 | } |
| 128 | static DEVICE_ATTR(busnum, S_IRUGO, show_busnum, NULL); |
| 129 | |
| 130 | static ssize_t |
Oliver Neukum | 9251644 | 2007-01-23 15:55:28 -0500 | [diff] [blame] | 131 | show_devnum(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | { |
| 133 | struct usb_device *udev; |
| 134 | |
Oliver Neukum | 9251644 | 2007-01-23 15:55:28 -0500 | [diff] [blame] | 135 | udev = to_usb_device(dev); |
| 136 | return sprintf(buf, "%d\n", udev->devnum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | } |
| 138 | static DEVICE_ATTR(devnum, S_IRUGO, show_devnum, NULL); |
| 139 | |
| 140 | static ssize_t |
Oliver Neukum | 9251644 | 2007-01-23 15:55:28 -0500 | [diff] [blame] | 141 | show_version(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | { |
| 143 | struct usb_device *udev; |
| 144 | u16 bcdUSB; |
| 145 | |
| 146 | udev = to_usb_device(dev); |
| 147 | bcdUSB = le16_to_cpu(udev->descriptor.bcdUSB); |
| 148 | return sprintf(buf, "%2x.%02x\n", bcdUSB >> 8, bcdUSB & 0xff); |
| 149 | } |
| 150 | static DEVICE_ATTR(version, S_IRUGO, show_version, NULL); |
| 151 | |
| 152 | static ssize_t |
Oliver Neukum | 9251644 | 2007-01-23 15:55:28 -0500 | [diff] [blame] | 153 | show_maxchild(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | { |
| 155 | struct usb_device *udev; |
| 156 | |
Oliver Neukum | 9251644 | 2007-01-23 15:55:28 -0500 | [diff] [blame] | 157 | udev = to_usb_device(dev); |
| 158 | return sprintf(buf, "%d\n", udev->maxchild); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | } |
| 160 | static DEVICE_ATTR(maxchild, S_IRUGO, show_maxchild, NULL); |
| 161 | |
Oliver Neukum | 7ceec1f | 2007-01-26 14:26:21 +0100 | [diff] [blame] | 162 | static ssize_t |
| 163 | show_quirks(struct device *dev, struct device_attribute *attr, char *buf) |
| 164 | { |
| 165 | struct usb_device *udev; |
| 166 | |
| 167 | udev = to_usb_device(dev); |
| 168 | return sprintf(buf, "0x%x\n", udev->quirks); |
| 169 | } |
| 170 | static DEVICE_ATTR(quirks, S_IRUGO, show_quirks, NULL); |
| 171 | |
Alan Stern | b41a60e | 2007-05-30 15:39:33 -0400 | [diff] [blame] | 172 | |
| 173 | #if defined(CONFIG_USB_PERSIST) || defined(CONFIG_USB_SUSPEND) |
| 174 | static const char power_group[] = "power"; |
| 175 | #endif |
| 176 | |
| 177 | #ifdef CONFIG_USB_PERSIST |
| 178 | |
| 179 | static ssize_t |
| 180 | show_persist(struct device *dev, struct device_attribute *attr, char *buf) |
| 181 | { |
| 182 | struct usb_device *udev = to_usb_device(dev); |
| 183 | |
| 184 | return sprintf(buf, "%d\n", udev->persist_enabled); |
| 185 | } |
| 186 | |
| 187 | static ssize_t |
| 188 | set_persist(struct device *dev, struct device_attribute *attr, |
| 189 | const char *buf, size_t count) |
| 190 | { |
| 191 | struct usb_device *udev = to_usb_device(dev); |
| 192 | int value; |
| 193 | |
| 194 | /* Hubs are always enabled for USB_PERSIST */ |
| 195 | if (udev->descriptor.bDeviceClass == USB_CLASS_HUB) |
| 196 | return -EPERM; |
| 197 | |
| 198 | if (sscanf(buf, "%d", &value) != 1) |
| 199 | return -EINVAL; |
| 200 | usb_pm_lock(udev); |
| 201 | udev->persist_enabled = !!value; |
| 202 | usb_pm_unlock(udev); |
| 203 | return count; |
| 204 | } |
| 205 | |
| 206 | static DEVICE_ATTR(persist, S_IRUGO | S_IWUSR, show_persist, set_persist); |
| 207 | |
| 208 | static int add_persist_attributes(struct device *dev) |
| 209 | { |
| 210 | int rc = 0; |
| 211 | |
| 212 | if (is_usb_device(dev)) { |
| 213 | struct usb_device *udev = to_usb_device(dev); |
| 214 | |
| 215 | /* Hubs are automatically enabled for USB_PERSIST */ |
| 216 | if (udev->descriptor.bDeviceClass == USB_CLASS_HUB) |
| 217 | udev->persist_enabled = 1; |
| 218 | rc = sysfs_add_file_to_group(&dev->kobj, |
| 219 | &dev_attr_persist.attr, |
| 220 | power_group); |
| 221 | } |
| 222 | return rc; |
| 223 | } |
| 224 | |
| 225 | static void remove_persist_attributes(struct device *dev) |
| 226 | { |
| 227 | sysfs_remove_file_from_group(&dev->kobj, |
| 228 | &dev_attr_persist.attr, |
| 229 | power_group); |
| 230 | } |
| 231 | |
| 232 | #else |
| 233 | |
| 234 | #define add_persist_attributes(dev) 0 |
| 235 | #define remove_persist_attributes(dev) do {} while (0) |
| 236 | |
| 237 | #endif /* CONFIG_USB_PERSIST */ |
| 238 | |
Alan Stern | 19c2623 | 2007-02-20 15:03:32 -0500 | [diff] [blame] | 239 | #ifdef CONFIG_USB_SUSPEND |
| 240 | |
| 241 | static ssize_t |
| 242 | show_autosuspend(struct device *dev, struct device_attribute *attr, char *buf) |
| 243 | { |
| 244 | struct usb_device *udev = to_usb_device(dev); |
| 245 | |
Alan Stern | eaafbc3 | 2007-03-13 16:39:15 -0400 | [diff] [blame] | 246 | return sprintf(buf, "%d\n", udev->autosuspend_delay / HZ); |
Alan Stern | 19c2623 | 2007-02-20 15:03:32 -0500 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | static ssize_t |
| 250 | set_autosuspend(struct device *dev, struct device_attribute *attr, |
| 251 | const char *buf, size_t count) |
| 252 | { |
| 253 | struct usb_device *udev = to_usb_device(dev); |
Alan Stern | eaafbc3 | 2007-03-13 16:39:15 -0400 | [diff] [blame] | 254 | int value; |
Alan Stern | 19c2623 | 2007-02-20 15:03:32 -0500 | [diff] [blame] | 255 | |
Alan Stern | eaafbc3 | 2007-03-13 16:39:15 -0400 | [diff] [blame] | 256 | if (sscanf(buf, "%d", &value) != 1 || value >= INT_MAX/HZ || |
| 257 | value <= - INT_MAX/HZ) |
Alan Stern | 19c2623 | 2007-02-20 15:03:32 -0500 | [diff] [blame] | 258 | return -EINVAL; |
| 259 | value *= HZ; |
| 260 | |
Alan Stern | 19c2623 | 2007-02-20 15:03:32 -0500 | [diff] [blame] | 261 | udev->autosuspend_delay = value; |
Alan Stern | eaafbc3 | 2007-03-13 16:39:15 -0400 | [diff] [blame] | 262 | if (value >= 0) |
Alan Stern | 19c2623 | 2007-02-20 15:03:32 -0500 | [diff] [blame] | 263 | usb_try_autosuspend_device(udev); |
Alan Stern | eaafbc3 | 2007-03-13 16:39:15 -0400 | [diff] [blame] | 264 | else { |
Alan Stern | 2add522 | 2007-03-20 14:59:39 -0400 | [diff] [blame] | 265 | if (usb_autoresume_device(udev) == 0) |
| 266 | usb_autosuspend_device(udev); |
Alan Stern | eaafbc3 | 2007-03-13 16:39:15 -0400 | [diff] [blame] | 267 | } |
Alan Stern | 19c2623 | 2007-02-20 15:03:32 -0500 | [diff] [blame] | 268 | return count; |
| 269 | } |
| 270 | |
| 271 | static DEVICE_ATTR(autosuspend, S_IRUGO | S_IWUSR, |
| 272 | show_autosuspend, set_autosuspend); |
| 273 | |
Alan Stern | 2add522 | 2007-03-20 14:59:39 -0400 | [diff] [blame] | 274 | static const char on_string[] = "on"; |
| 275 | static const char auto_string[] = "auto"; |
| 276 | static const char suspend_string[] = "suspend"; |
| 277 | |
| 278 | static ssize_t |
| 279 | show_level(struct device *dev, struct device_attribute *attr, char *buf) |
| 280 | { |
| 281 | struct usb_device *udev = to_usb_device(dev); |
| 282 | const char *p = auto_string; |
| 283 | |
| 284 | if (udev->state == USB_STATE_SUSPENDED) { |
| 285 | if (udev->autoresume_disabled) |
| 286 | p = suspend_string; |
| 287 | } else { |
| 288 | if (udev->autosuspend_disabled) |
| 289 | p = on_string; |
| 290 | } |
| 291 | return sprintf(buf, "%s\n", p); |
| 292 | } |
| 293 | |
| 294 | static ssize_t |
| 295 | set_level(struct device *dev, struct device_attribute *attr, |
| 296 | const char *buf, size_t count) |
| 297 | { |
| 298 | struct usb_device *udev = to_usb_device(dev); |
| 299 | int len = count; |
| 300 | char *cp; |
| 301 | int rc = 0; |
Alan Stern | dd86557 | 2007-05-22 11:38:19 -0400 | [diff] [blame] | 302 | int old_autosuspend_disabled, old_autoresume_disabled; |
Alan Stern | 2add522 | 2007-03-20 14:59:39 -0400 | [diff] [blame] | 303 | |
| 304 | cp = memchr(buf, '\n', count); |
| 305 | if (cp) |
| 306 | len = cp - buf; |
| 307 | |
| 308 | usb_lock_device(udev); |
Alan Stern | dd86557 | 2007-05-22 11:38:19 -0400 | [diff] [blame] | 309 | old_autosuspend_disabled = udev->autosuspend_disabled; |
| 310 | old_autoresume_disabled = udev->autoresume_disabled; |
Alan Stern | 2add522 | 2007-03-20 14:59:39 -0400 | [diff] [blame] | 311 | |
| 312 | /* Setting the flags without calling usb_pm_lock is a subject to |
| 313 | * races, but who cares... |
| 314 | */ |
| 315 | if (len == sizeof on_string - 1 && |
| 316 | strncmp(buf, on_string, len) == 0) { |
| 317 | udev->autosuspend_disabled = 1; |
| 318 | udev->autoresume_disabled = 0; |
| 319 | rc = usb_external_resume_device(udev); |
| 320 | |
| 321 | } else if (len == sizeof auto_string - 1 && |
| 322 | strncmp(buf, auto_string, len) == 0) { |
| 323 | udev->autosuspend_disabled = 0; |
| 324 | udev->autoresume_disabled = 0; |
| 325 | rc = usb_external_resume_device(udev); |
| 326 | |
| 327 | } else if (len == sizeof suspend_string - 1 && |
| 328 | strncmp(buf, suspend_string, len) == 0) { |
| 329 | udev->autosuspend_disabled = 0; |
| 330 | udev->autoresume_disabled = 1; |
| 331 | rc = usb_external_suspend_device(udev, PMSG_SUSPEND); |
| 332 | |
| 333 | } else |
| 334 | rc = -EINVAL; |
| 335 | |
Alan Stern | dd86557 | 2007-05-22 11:38:19 -0400 | [diff] [blame] | 336 | if (rc) { |
| 337 | udev->autosuspend_disabled = old_autosuspend_disabled; |
| 338 | udev->autoresume_disabled = old_autoresume_disabled; |
| 339 | } |
Alan Stern | 2add522 | 2007-03-20 14:59:39 -0400 | [diff] [blame] | 340 | usb_unlock_device(udev); |
| 341 | return (rc < 0 ? rc : count); |
| 342 | } |
| 343 | |
| 344 | static DEVICE_ATTR(level, S_IRUGO | S_IWUSR, show_level, set_level); |
| 345 | |
Alan Stern | 19c2623 | 2007-02-20 15:03:32 -0500 | [diff] [blame] | 346 | static int add_power_attributes(struct device *dev) |
| 347 | { |
| 348 | int rc = 0; |
| 349 | |
Alan Stern | 2add522 | 2007-03-20 14:59:39 -0400 | [diff] [blame] | 350 | if (is_usb_device(dev)) { |
Alan Stern | 19c2623 | 2007-02-20 15:03:32 -0500 | [diff] [blame] | 351 | rc = sysfs_add_file_to_group(&dev->kobj, |
| 352 | &dev_attr_autosuspend.attr, |
| 353 | power_group); |
Alan Stern | 2add522 | 2007-03-20 14:59:39 -0400 | [diff] [blame] | 354 | if (rc == 0) |
| 355 | rc = sysfs_add_file_to_group(&dev->kobj, |
| 356 | &dev_attr_level.attr, |
| 357 | power_group); |
| 358 | } |
Alan Stern | 19c2623 | 2007-02-20 15:03:32 -0500 | [diff] [blame] | 359 | return rc; |
| 360 | } |
| 361 | |
| 362 | static void remove_power_attributes(struct device *dev) |
| 363 | { |
| 364 | sysfs_remove_file_from_group(&dev->kobj, |
Alan Stern | 2add522 | 2007-03-20 14:59:39 -0400 | [diff] [blame] | 365 | &dev_attr_level.attr, |
| 366 | power_group); |
| 367 | sysfs_remove_file_from_group(&dev->kobj, |
Alan Stern | 19c2623 | 2007-02-20 15:03:32 -0500 | [diff] [blame] | 368 | &dev_attr_autosuspend.attr, |
| 369 | power_group); |
| 370 | } |
| 371 | |
| 372 | #else |
| 373 | |
| 374 | #define add_power_attributes(dev) 0 |
| 375 | #define remove_power_attributes(dev) do {} while (0) |
| 376 | |
| 377 | #endif /* CONFIG_USB_SUSPEND */ |
| 378 | |
Alan Stern | b41a60e | 2007-05-30 15:39:33 -0400 | [diff] [blame] | 379 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | /* Descriptor fields */ |
| 381 | #define usb_descriptor_attr_le16(field, format_string) \ |
| 382 | static ssize_t \ |
Oliver Neukum | 9251644 | 2007-01-23 15:55:28 -0500 | [diff] [blame] | 383 | show_##field(struct device *dev, struct device_attribute *attr, \ |
Alan Stern | b724ae7 | 2005-10-24 15:36:00 -0400 | [diff] [blame] | 384 | char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | { \ |
| 386 | struct usb_device *udev; \ |
| 387 | \ |
Oliver Neukum | 9251644 | 2007-01-23 15:55:28 -0500 | [diff] [blame] | 388 | udev = to_usb_device(dev); \ |
| 389 | return sprintf(buf, format_string, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | le16_to_cpu(udev->descriptor.field)); \ |
| 391 | } \ |
| 392 | static DEVICE_ATTR(field, S_IRUGO, show_##field, NULL); |
| 393 | |
| 394 | usb_descriptor_attr_le16(idVendor, "%04x\n") |
| 395 | usb_descriptor_attr_le16(idProduct, "%04x\n") |
| 396 | usb_descriptor_attr_le16(bcdDevice, "%04x\n") |
| 397 | |
| 398 | #define usb_descriptor_attr(field, format_string) \ |
| 399 | static ssize_t \ |
Oliver Neukum | 9251644 | 2007-01-23 15:55:28 -0500 | [diff] [blame] | 400 | show_##field(struct device *dev, struct device_attribute *attr, \ |
Alan Stern | b724ae7 | 2005-10-24 15:36:00 -0400 | [diff] [blame] | 401 | char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | { \ |
| 403 | struct usb_device *udev; \ |
| 404 | \ |
Oliver Neukum | 9251644 | 2007-01-23 15:55:28 -0500 | [diff] [blame] | 405 | udev = to_usb_device(dev); \ |
| 406 | return sprintf(buf, format_string, udev->descriptor.field); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | } \ |
| 408 | static DEVICE_ATTR(field, S_IRUGO, show_##field, NULL); |
| 409 | |
Oliver Neukum | 9251644 | 2007-01-23 15:55:28 -0500 | [diff] [blame] | 410 | usb_descriptor_attr(bDeviceClass, "%02x\n") |
| 411 | usb_descriptor_attr(bDeviceSubClass, "%02x\n") |
| 412 | usb_descriptor_attr(bDeviceProtocol, "%02x\n") |
| 413 | usb_descriptor_attr(bNumConfigurations, "%d\n") |
| 414 | usb_descriptor_attr(bMaxPacketSize0, "%d\n") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | |
| 416 | static struct attribute *dev_attrs[] = { |
| 417 | /* current configuration's attributes */ |
Alan Stern | b6eb2d8 | 2006-07-06 15:37:42 -0400 | [diff] [blame] | 418 | &dev_attr_configuration.attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | &dev_attr_bNumInterfaces.attr, |
| 420 | &dev_attr_bConfigurationValue.attr, |
| 421 | &dev_attr_bmAttributes.attr, |
| 422 | &dev_attr_bMaxPower.attr, |
| 423 | /* device attributes */ |
| 424 | &dev_attr_idVendor.attr, |
| 425 | &dev_attr_idProduct.attr, |
| 426 | &dev_attr_bcdDevice.attr, |
| 427 | &dev_attr_bDeviceClass.attr, |
| 428 | &dev_attr_bDeviceSubClass.attr, |
| 429 | &dev_attr_bDeviceProtocol.attr, |
| 430 | &dev_attr_bNumConfigurations.attr, |
Greg Kroah-Hartman | cf5910b | 2005-06-29 16:53:29 -0700 | [diff] [blame] | 431 | &dev_attr_bMaxPacketSize0.attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | &dev_attr_speed.attr, |
Alan Stern | 83f7d95 | 2007-04-25 15:15:43 -0400 | [diff] [blame] | 433 | &dev_attr_busnum.attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | &dev_attr_devnum.attr, |
| 435 | &dev_attr_version.attr, |
| 436 | &dev_attr_maxchild.attr, |
Oliver Neukum | 7ceec1f | 2007-01-26 14:26:21 +0100 | [diff] [blame] | 437 | &dev_attr_quirks.attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | NULL, |
| 439 | }; |
| 440 | static struct attribute_group dev_attr_grp = { |
| 441 | .attrs = dev_attrs, |
| 442 | }; |
| 443 | |
Alan Stern | 69d42a7 | 2007-07-12 17:06:23 -0400 | [diff] [blame] | 444 | /* Binary descriptors */ |
| 445 | |
| 446 | static ssize_t |
| 447 | read_descriptors(struct kobject *kobj, struct bin_attribute *attr, |
| 448 | char *buf, loff_t off, size_t count) |
| 449 | { |
| 450 | struct usb_device *udev = to_usb_device( |
| 451 | container_of(kobj, struct device, kobj)); |
| 452 | size_t nleft = count; |
| 453 | size_t srclen, n; |
| 454 | |
| 455 | usb_lock_device(udev); |
| 456 | |
| 457 | /* The binary attribute begins with the device descriptor */ |
| 458 | srclen = sizeof(struct usb_device_descriptor); |
| 459 | if (off < srclen) { |
| 460 | n = min_t(size_t, nleft, srclen - off); |
| 461 | memcpy(buf, off + (char *) &udev->descriptor, n); |
| 462 | nleft -= n; |
| 463 | buf += n; |
| 464 | off = 0; |
| 465 | } else { |
| 466 | off -= srclen; |
| 467 | } |
| 468 | |
| 469 | /* Then follows the raw descriptor entry for the current |
| 470 | * configuration (config plus subsidiary descriptors). |
| 471 | */ |
| 472 | if (udev->actconfig) { |
| 473 | int cfgno = udev->actconfig - udev->config; |
| 474 | |
| 475 | srclen = __le16_to_cpu(udev->actconfig->desc.wTotalLength); |
| 476 | if (off < srclen) { |
| 477 | n = min_t(size_t, nleft, srclen - off); |
| 478 | memcpy(buf, off + udev->rawdescriptors[cfgno], n); |
| 479 | nleft -= n; |
| 480 | } |
| 481 | } |
| 482 | usb_unlock_device(udev); |
| 483 | return count - nleft; |
| 484 | } |
| 485 | |
| 486 | static struct bin_attribute dev_bin_attr_descriptors = { |
| 487 | .attr = {.name = "descriptors", .mode = 0444}, |
| 488 | .read = read_descriptors, |
| 489 | .size = 18 + 65535, /* dev descr + max-size raw descriptor */ |
| 490 | }; |
| 491 | |
Greg Kroah-Hartman | 1b21d5e | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 492 | int usb_create_sysfs_dev_files(struct usb_device *udev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | { |
| 494 | struct device *dev = &udev->dev; |
Greg Kroah-Hartman | 1b21d5e | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 495 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | |
Greg Kroah-Hartman | 1b21d5e | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 497 | retval = sysfs_create_group(&dev->kobj, &dev_attr_grp); |
| 498 | if (retval) |
| 499 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | |
Alan Stern | 69d42a7 | 2007-07-12 17:06:23 -0400 | [diff] [blame] | 501 | retval = device_create_bin_file(dev, &dev_bin_attr_descriptors); |
| 502 | if (retval) |
| 503 | goto error; |
| 504 | |
Alan Stern | b41a60e | 2007-05-30 15:39:33 -0400 | [diff] [blame] | 505 | retval = add_persist_attributes(dev); |
| 506 | if (retval) |
| 507 | goto error; |
| 508 | |
Alan Stern | 19c2623 | 2007-02-20 15:03:32 -0500 | [diff] [blame] | 509 | retval = add_power_attributes(dev); |
| 510 | if (retval) |
| 511 | goto error; |
| 512 | |
Greg Kroah-Hartman | 1b21d5e | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 513 | if (udev->manufacturer) { |
Oliver Neukum | 9251644 | 2007-01-23 15:55:28 -0500 | [diff] [blame] | 514 | retval = device_create_file(dev, &dev_attr_manufacturer); |
Greg Kroah-Hartman | 1b21d5e | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 515 | if (retval) |
| 516 | goto error; |
| 517 | } |
| 518 | if (udev->product) { |
Oliver Neukum | 9251644 | 2007-01-23 15:55:28 -0500 | [diff] [blame] | 519 | retval = device_create_file(dev, &dev_attr_product); |
Greg Kroah-Hartman | 1b21d5e | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 520 | if (retval) |
| 521 | goto error; |
| 522 | } |
| 523 | if (udev->serial) { |
Oliver Neukum | 9251644 | 2007-01-23 15:55:28 -0500 | [diff] [blame] | 524 | retval = device_create_file(dev, &dev_attr_serial); |
Greg Kroah-Hartman | 1b21d5e | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 525 | if (retval) |
| 526 | goto error; |
| 527 | } |
| 528 | retval = usb_create_ep_files(dev, &udev->ep0, udev); |
| 529 | if (retval) |
| 530 | goto error; |
| 531 | return 0; |
| 532 | error: |
Alan Stern | aa084f3 | 2007-02-20 14:59:59 -0500 | [diff] [blame] | 533 | usb_remove_sysfs_dev_files(udev); |
Greg Kroah-Hartman | 1b21d5e | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 534 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | } |
| 536 | |
Oliver Neukum | 9251644 | 2007-01-23 15:55:28 -0500 | [diff] [blame] | 537 | void usb_remove_sysfs_dev_files(struct usb_device *udev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | { |
| 539 | struct device *dev = &udev->dev; |
| 540 | |
Alan Stern | be69e5b | 2005-10-25 15:56:06 -0400 | [diff] [blame] | 541 | usb_remove_ep_files(&udev->ep0); |
Alan Stern | aa084f3 | 2007-02-20 14:59:59 -0500 | [diff] [blame] | 542 | device_remove_file(dev, &dev_attr_manufacturer); |
| 543 | device_remove_file(dev, &dev_attr_product); |
| 544 | device_remove_file(dev, &dev_attr_serial); |
Alan Stern | 19c2623 | 2007-02-20 15:03:32 -0500 | [diff] [blame] | 545 | remove_power_attributes(dev); |
Alan Stern | b41a60e | 2007-05-30 15:39:33 -0400 | [diff] [blame] | 546 | remove_persist_attributes(dev); |
Alan Stern | 69d42a7 | 2007-07-12 17:06:23 -0400 | [diff] [blame] | 547 | device_remove_bin_file(dev, &dev_bin_attr_descriptors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | sysfs_remove_group(&dev->kobj, &dev_attr_grp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | } |
| 550 | |
Craig W. Nadler | 165fe97 | 2007-06-15 23:14:35 -0400 | [diff] [blame] | 551 | /* Interface Accociation Descriptor fields */ |
| 552 | #define usb_intf_assoc_attr(field, format_string) \ |
| 553 | static ssize_t \ |
| 554 | show_iad_##field (struct device *dev, struct device_attribute *attr, \ |
| 555 | char *buf) \ |
| 556 | { \ |
| 557 | struct usb_interface *intf = to_usb_interface (dev); \ |
| 558 | \ |
| 559 | return sprintf (buf, format_string, \ |
| 560 | intf->intf_assoc->field); \ |
| 561 | } \ |
| 562 | static DEVICE_ATTR(iad_##field, S_IRUGO, show_iad_##field, NULL); |
| 563 | |
| 564 | usb_intf_assoc_attr (bFirstInterface, "%02x\n") |
| 565 | usb_intf_assoc_attr (bInterfaceCount, "%02d\n") |
| 566 | usb_intf_assoc_attr (bFunctionClass, "%02x\n") |
| 567 | usb_intf_assoc_attr (bFunctionSubClass, "%02x\n") |
| 568 | usb_intf_assoc_attr (bFunctionProtocol, "%02x\n") |
| 569 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | /* Interface fields */ |
| 571 | #define usb_intf_attr(field, format_string) \ |
| 572 | static ssize_t \ |
Oliver Neukum | 9251644 | 2007-01-23 15:55:28 -0500 | [diff] [blame] | 573 | show_##field(struct device *dev, struct device_attribute *attr, \ |
Alan Stern | b724ae7 | 2005-10-24 15:36:00 -0400 | [diff] [blame] | 574 | char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | { \ |
Oliver Neukum | 9251644 | 2007-01-23 15:55:28 -0500 | [diff] [blame] | 576 | struct usb_interface *intf = to_usb_interface(dev); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | \ |
Oliver Neukum | 9251644 | 2007-01-23 15:55:28 -0500 | [diff] [blame] | 578 | return sprintf(buf, format_string, \ |
Alan Stern | b724ae7 | 2005-10-24 15:36:00 -0400 | [diff] [blame] | 579 | intf->cur_altsetting->desc.field); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | } \ |
| 581 | static DEVICE_ATTR(field, S_IRUGO, show_##field, NULL); |
| 582 | |
Oliver Neukum | 9251644 | 2007-01-23 15:55:28 -0500 | [diff] [blame] | 583 | usb_intf_attr(bInterfaceNumber, "%02x\n") |
| 584 | usb_intf_attr(bAlternateSetting, "%2d\n") |
| 585 | usb_intf_attr(bNumEndpoints, "%02x\n") |
| 586 | usb_intf_attr(bInterfaceClass, "%02x\n") |
| 587 | usb_intf_attr(bInterfaceSubClass, "%02x\n") |
| 588 | usb_intf_attr(bInterfaceProtocol, "%02x\n") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | |
Alan Stern | b724ae7 | 2005-10-24 15:36:00 -0400 | [diff] [blame] | 590 | static ssize_t show_interface_string(struct device *dev, |
| 591 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | { |
| 593 | struct usb_interface *intf; |
| 594 | struct usb_device *udev; |
| 595 | int len; |
| 596 | |
Oliver Neukum | 9251644 | 2007-01-23 15:55:28 -0500 | [diff] [blame] | 597 | intf = to_usb_interface(dev); |
| 598 | udev = interface_to_usbdev(intf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | len = snprintf(buf, 256, "%s", intf->cur_altsetting->string); |
| 600 | if (len < 0) |
| 601 | return 0; |
| 602 | buf[len] = '\n'; |
| 603 | buf[len+1] = 0; |
| 604 | return len+1; |
| 605 | } |
| 606 | static DEVICE_ATTR(interface, S_IRUGO, show_interface_string, NULL); |
| 607 | |
Alan Stern | b724ae7 | 2005-10-24 15:36:00 -0400 | [diff] [blame] | 608 | static ssize_t show_modalias(struct device *dev, |
| 609 | struct device_attribute *attr, char *buf) |
Greg KH | 360b52b | 2005-05-10 06:45:10 -0700 | [diff] [blame] | 610 | { |
| 611 | struct usb_interface *intf; |
| 612 | struct usb_device *udev; |
Greg Kroah-Hartman | 7521803 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 613 | struct usb_host_interface *alt; |
Greg KH | 360b52b | 2005-05-10 06:45:10 -0700 | [diff] [blame] | 614 | |
| 615 | intf = to_usb_interface(dev); |
| 616 | udev = interface_to_usbdev(intf); |
Greg Kroah-Hartman | 7521803 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 617 | alt = intf->cur_altsetting; |
Greg KH | 360b52b | 2005-05-10 06:45:10 -0700 | [diff] [blame] | 618 | |
Greg Kroah-Hartman | 7521803 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 619 | return sprintf(buf, "usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02X" |
| 620 | "ic%02Xisc%02Xip%02X\n", |
| 621 | le16_to_cpu(udev->descriptor.idVendor), |
| 622 | le16_to_cpu(udev->descriptor.idProduct), |
| 623 | le16_to_cpu(udev->descriptor.bcdDevice), |
| 624 | udev->descriptor.bDeviceClass, |
| 625 | udev->descriptor.bDeviceSubClass, |
| 626 | udev->descriptor.bDeviceProtocol, |
| 627 | alt->desc.bInterfaceClass, |
| 628 | alt->desc.bInterfaceSubClass, |
| 629 | alt->desc.bInterfaceProtocol); |
Greg KH | 360b52b | 2005-05-10 06:45:10 -0700 | [diff] [blame] | 630 | } |
| 631 | static DEVICE_ATTR(modalias, S_IRUGO, show_modalias, NULL); |
| 632 | |
Craig W. Nadler | 165fe97 | 2007-06-15 23:14:35 -0400 | [diff] [blame] | 633 | static struct attribute *intf_assoc_attrs[] = { |
| 634 | &dev_attr_iad_bFirstInterface.attr, |
| 635 | &dev_attr_iad_bInterfaceCount.attr, |
| 636 | &dev_attr_iad_bFunctionClass.attr, |
| 637 | &dev_attr_iad_bFunctionSubClass.attr, |
| 638 | &dev_attr_iad_bFunctionProtocol.attr, |
| 639 | NULL, |
| 640 | }; |
| 641 | static struct attribute_group intf_assoc_attr_grp = { |
| 642 | .attrs = intf_assoc_attrs, |
| 643 | }; |
| 644 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | static struct attribute *intf_attrs[] = { |
| 646 | &dev_attr_bInterfaceNumber.attr, |
| 647 | &dev_attr_bAlternateSetting.attr, |
| 648 | &dev_attr_bNumEndpoints.attr, |
| 649 | &dev_attr_bInterfaceClass.attr, |
| 650 | &dev_attr_bInterfaceSubClass.attr, |
| 651 | &dev_attr_bInterfaceProtocol.attr, |
Greg KH | 360b52b | 2005-05-10 06:45:10 -0700 | [diff] [blame] | 652 | &dev_attr_modalias.attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | NULL, |
| 654 | }; |
| 655 | static struct attribute_group intf_attr_grp = { |
| 656 | .attrs = intf_attrs, |
| 657 | }; |
| 658 | |
Alan Stern | 4f62efe | 2005-10-24 16:24:14 -0400 | [diff] [blame] | 659 | static inline void usb_create_intf_ep_files(struct usb_interface *intf, |
| 660 | struct usb_device *udev) |
Greg Kroah-Hartman | 094f1649 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 661 | { |
| 662 | struct usb_host_interface *iface_desc; |
| 663 | int i; |
| 664 | |
| 665 | iface_desc = intf->cur_altsetting; |
| 666 | for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) |
Greg Kroah-Hartman | 36679ea | 2006-06-14 12:14:34 -0700 | [diff] [blame] | 667 | usb_create_ep_files(&intf->dev, &iface_desc->endpoint[i], |
Alan Stern | 4f62efe | 2005-10-24 16:24:14 -0400 | [diff] [blame] | 668 | udev); |
Greg Kroah-Hartman | 094f1649 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 669 | } |
| 670 | |
Alan Stern | be69e5b | 2005-10-25 15:56:06 -0400 | [diff] [blame] | 671 | static inline void usb_remove_intf_ep_files(struct usb_interface *intf) |
Greg Kroah-Hartman | 094f1649 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 672 | { |
| 673 | struct usb_host_interface *iface_desc; |
| 674 | int i; |
| 675 | |
| 676 | iface_desc = intf->cur_altsetting; |
| 677 | for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) |
Alan Stern | be69e5b | 2005-10-25 15:56:06 -0400 | [diff] [blame] | 678 | usb_remove_ep_files(&iface_desc->endpoint[i]); |
Greg Kroah-Hartman | 094f1649 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 679 | } |
| 680 | |
Greg Kroah-Hartman | 1b21d5e | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 681 | int usb_create_sysfs_intf_files(struct usb_interface *intf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | { |
Alan Stern | aa084f3 | 2007-02-20 14:59:59 -0500 | [diff] [blame] | 683 | struct device *dev = &intf->dev; |
Alan Stern | 4f62efe | 2005-10-24 16:24:14 -0400 | [diff] [blame] | 684 | struct usb_device *udev = interface_to_usbdev(intf); |
| 685 | struct usb_host_interface *alt = intf->cur_altsetting; |
Greg Kroah-Hartman | 1b21d5e | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 686 | int retval; |
Alan Stern | 4f62efe | 2005-10-24 16:24:14 -0400 | [diff] [blame] | 687 | |
Alan Stern | aa084f3 | 2007-02-20 14:59:59 -0500 | [diff] [blame] | 688 | retval = sysfs_create_group(&dev->kobj, &intf_attr_grp); |
Greg Kroah-Hartman | 1b21d5e | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 689 | if (retval) |
Alan Stern | aa084f3 | 2007-02-20 14:59:59 -0500 | [diff] [blame] | 690 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | |
Alan Stern | 4f62efe | 2005-10-24 16:24:14 -0400 | [diff] [blame] | 692 | if (alt->string == NULL) |
| 693 | alt->string = usb_cache_string(udev, alt->desc.iInterface); |
| 694 | if (alt->string) |
Alan Stern | aa084f3 | 2007-02-20 14:59:59 -0500 | [diff] [blame] | 695 | retval = device_create_file(dev, &dev_attr_interface); |
Craig W. Nadler | 165fe97 | 2007-06-15 23:14:35 -0400 | [diff] [blame] | 696 | if (intf->intf_assoc) |
| 697 | retval = sysfs_create_group(&dev->kobj, &intf_assoc_attr_grp); |
Alan Stern | 4f62efe | 2005-10-24 16:24:14 -0400 | [diff] [blame] | 698 | usb_create_intf_ep_files(intf, udev); |
Greg Kroah-Hartman | 1b21d5e | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 699 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | } |
| 701 | |
Oliver Neukum | 9251644 | 2007-01-23 15:55:28 -0500 | [diff] [blame] | 702 | void usb_remove_sysfs_intf_files(struct usb_interface *intf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | { |
Alan Stern | aa084f3 | 2007-02-20 14:59:59 -0500 | [diff] [blame] | 704 | struct device *dev = &intf->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | |
Alan Stern | aa084f3 | 2007-02-20 14:59:59 -0500 | [diff] [blame] | 706 | usb_remove_intf_ep_files(intf); |
| 707 | device_remove_file(dev, &dev_attr_interface); |
| 708 | sysfs_remove_group(&dev->kobj, &intf_attr_grp); |
Craig W. Nadler | 165fe97 | 2007-06-15 23:14:35 -0400 | [diff] [blame] | 709 | sysfs_remove_group(&intf->dev.kobj, &intf_assoc_attr_grp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | } |