aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Garrett <mjg@redhat.com>2012-02-03 17:11:54 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-02-09 11:40:11 -0500
commit0846e7e9856c0928223447d9349a877202a63f24 (patch)
tree1ef6df58927568478e17396855c579ad45aa9fee
parentaf74d2dae8f85a0e90a30594beb507f5d954fa3f (diff)
usb: Add support for indicating whether a port is removable
Userspace may want to make policy decisions based on whether or not a given USB device is removable. Add a per-device member and support for exposing it in sysfs. Information sources to populate it will be added later. Signed-off-by: Matthew Garrett <mjg@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--Documentation/ABI/testing/sysfs-bus-usb11
-rw-r--r--drivers/usb/core/sysfs.c23
-rw-r--r--include/linux/usb.h8
3 files changed, 42 insertions, 0 deletions
diff --git a/Documentation/ABI/testing/sysfs-bus-usb b/Documentation/ABI/testing/sysfs-bus-usb
index b4f548792e32..7c22a532fdfb 100644
--- a/Documentation/ABI/testing/sysfs-bus-usb
+++ b/Documentation/ABI/testing/sysfs-bus-usb
@@ -182,3 +182,14 @@ Description:
182 USB2 hardware LPM is enabled for the device. Developer can 182 USB2 hardware LPM is enabled for the device. Developer can
183 write y/Y/1 or n/N/0 to the file to enable/disable the 183 write y/Y/1 or n/N/0 to the file to enable/disable the
184 feature. 184 feature.
185
186What: /sys/bus/usb/devices/.../removable
187Date: February 2012
188Contact: Matthew Garrett <mjg@redhat.com>
189Description:
190 Some information about whether a given USB device is
191 physically fixed to the platform can be inferred from a
192 combination of hub decriptor bits and platform-specific data
193 such as ACPI. This file will read either "removable" or
194 "fixed" if the information is available, and "unknown"
195 otherwise. \ No newline at end of file
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index 9e491ca2e5c4..566d9f94f735 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -230,6 +230,28 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
230} 230}
231static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL); 231static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
232 232
233static ssize_t
234show_removable(struct device *dev, struct device_attribute *attr, char *buf)
235{
236 struct usb_device *udev;
237 char *state;
238
239 udev = to_usb_device(dev);
240
241 switch (udev->removable) {
242 case USB_DEVICE_REMOVABLE:
243 state = "removable";
244 break;
245 case USB_DEVICE_FIXED:
246 state = "fixed";
247 break;
248 default:
249 state = "unknown";
250 }
251
252 return sprintf(buf, "%s\n", state);
253}
254static DEVICE_ATTR(removable, S_IRUGO, show_removable, NULL);
233 255
234#ifdef CONFIG_PM 256#ifdef CONFIG_PM
235 257
@@ -626,6 +648,7 @@ static struct attribute *dev_attrs[] = {
626 &dev_attr_avoid_reset_quirk.attr, 648 &dev_attr_avoid_reset_quirk.attr,
627 &dev_attr_authorized.attr, 649 &dev_attr_authorized.attr,
628 &dev_attr_remove.attr, 650 &dev_attr_remove.attr,
651 &dev_attr_removable.attr,
629 NULL, 652 NULL,
630}; 653};
631static struct attribute_group dev_attr_grp = { 654static struct attribute_group dev_attr_grp = {
diff --git a/include/linux/usb.h b/include/linux/usb.h
index 27a4e16d2bf1..b2eb3a47caf5 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -376,6 +376,12 @@ struct usb_bus {
376 376
377struct usb_tt; 377struct usb_tt;
378 378
379enum usb_device_removable {
380 USB_DEVICE_REMOVABLE_UNKNOWN = 0,
381 USB_DEVICE_REMOVABLE,
382 USB_DEVICE_FIXED,
383};
384
379/** 385/**
380 * struct usb_device - kernel's representation of a USB device 386 * struct usb_device - kernel's representation of a USB device
381 * @devnum: device number; address on a USB bus 387 * @devnum: device number; address on a USB bus
@@ -432,6 +438,7 @@ struct usb_tt;
432 * @wusb_dev: if this is a Wireless USB device, link to the WUSB 438 * @wusb_dev: if this is a Wireless USB device, link to the WUSB
433 * specific data for the device. 439 * specific data for the device.
434 * @slot_id: Slot ID assigned by xHCI 440 * @slot_id: Slot ID assigned by xHCI
441 * @removable: Device can be physically removed from this port
435 * 442 *
436 * Notes: 443 * Notes:
437 * Usbcore drivers should not set usbdev->state directly. Instead use 444 * Usbcore drivers should not set usbdev->state directly. Instead use
@@ -509,6 +516,7 @@ struct usb_device {
509#endif 516#endif
510 struct wusb_dev *wusb_dev; 517 struct wusb_dev *wusb_dev;
511 int slot_id; 518 int slot_id;
519 enum usb_device_removable removable;
512}; 520};
513#define to_usb_device(d) container_of(d, struct usb_device, dev) 521#define to_usb_device(d) container_of(d, struct usb_device, dev)
514 522