aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/ABI/testing/sysfs-devices-platform-_UDC_-gadget9
-rw-r--r--drivers/usb/gadget/composite.c21
-rw-r--r--include/linux/usb/composite.h1
-rw-r--r--include/linux/usb/gadget.h4
4 files changed, 35 insertions, 0 deletions
diff --git a/Documentation/ABI/testing/sysfs-devices-platform-_UDC_-gadget b/Documentation/ABI/testing/sysfs-devices-platform-_UDC_-gadget
new file mode 100644
index 000000000000..34034027b13c
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-devices-platform-_UDC_-gadget
@@ -0,0 +1,9 @@
1What: /sys/devices/platform/_UDC_/gadget/suspended
2Date: April 2010
3Contact: Fabien Chouteau <fabien.chouteau@barco.com>
4Description:
5 Show the suspend state of an USB composite gadget.
6 1 -> suspended
7 0 -> resumed
8
9 (_UDC_ is the name of the USB Device Controller driver)
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 5465d8767f9a..f9aff1bbcb3e 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -898,6 +898,18 @@ static void composite_disconnect(struct usb_gadget *gadget)
898 898
899/*-------------------------------------------------------------------------*/ 899/*-------------------------------------------------------------------------*/
900 900
901static ssize_t composite_show_suspended(struct device *dev,
902 struct device_attribute *attr,
903 char *buf)
904{
905 struct usb_gadget *gadget = dev_to_usb_gadget(dev);
906 struct usb_composite_dev *cdev = get_gadget_data(gadget);
907
908 return sprintf(buf, "%d\n", cdev->suspended);
909}
910
911static DEVICE_ATTR(suspended, 0444, composite_show_suspended, NULL);
912
901static void /* __init_or_exit */ 913static void /* __init_or_exit */
902composite_unbind(struct usb_gadget *gadget) 914composite_unbind(struct usb_gadget *gadget)
903{ 915{
@@ -944,6 +956,7 @@ composite_unbind(struct usb_gadget *gadget)
944 } 956 }
945 kfree(cdev); 957 kfree(cdev);
946 set_gadget_data(gadget, NULL); 958 set_gadget_data(gadget, NULL);
959 device_remove_file(&gadget->dev, &dev_attr_suspended);
947 composite = NULL; 960 composite = NULL;
948} 961}
949 962
@@ -1036,6 +1049,10 @@ static int __init composite_bind(struct usb_gadget *gadget)
1036 string_override(composite->strings, 1049 string_override(composite->strings,
1037 cdev->desc.iSerialNumber, iSerialNumber); 1050 cdev->desc.iSerialNumber, iSerialNumber);
1038 1051
1052 status = device_create_file(&gadget->dev, &dev_attr_suspended);
1053 if (status)
1054 goto fail;
1055
1039 INFO(cdev, "%s ready\n", composite->name); 1056 INFO(cdev, "%s ready\n", composite->name);
1040 return 0; 1057 return 0;
1041 1058
@@ -1064,6 +1081,8 @@ composite_suspend(struct usb_gadget *gadget)
1064 } 1081 }
1065 if (composite->suspend) 1082 if (composite->suspend)
1066 composite->suspend(cdev); 1083 composite->suspend(cdev);
1084
1085 cdev->suspended = 1;
1067} 1086}
1068 1087
1069static void 1088static void
@@ -1084,6 +1103,8 @@ composite_resume(struct usb_gadget *gadget)
1084 f->resume(f); 1103 f->resume(f);
1085 } 1104 }
1086 } 1105 }
1106
1107 cdev->suspended = 0;
1087} 1108}
1088 1109
1089/*-------------------------------------------------------------------------*/ 1110/*-------------------------------------------------------------------------*/
diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h
index 738ea1a691cb..139353efad34 100644
--- a/include/linux/usb/composite.h
+++ b/include/linux/usb/composite.h
@@ -326,6 +326,7 @@ struct usb_composite_dev {
326 326
327 /* private: */ 327 /* private: */
328 /* internals */ 328 /* internals */
329 unsigned int suspended:1;
329 struct usb_device_descriptor desc; 330 struct usb_device_descriptor desc;
330 struct list_head configs; 331 struct list_head configs;
331 struct usb_composite_driver *driver; 332 struct usb_composite_driver *driver;
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index f4b7ca516cdd..db6141cdb77b 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -494,6 +494,10 @@ static inline void set_gadget_data(struct usb_gadget *gadget, void *data)
494 { dev_set_drvdata(&gadget->dev, data); } 494 { dev_set_drvdata(&gadget->dev, data); }
495static inline void *get_gadget_data(struct usb_gadget *gadget) 495static inline void *get_gadget_data(struct usb_gadget *gadget)
496 { return dev_get_drvdata(&gadget->dev); } 496 { return dev_get_drvdata(&gadget->dev); }
497static inline struct usb_gadget *dev_to_usb_gadget(struct device *dev)
498{
499 return container_of(dev, struct usb_gadget, dev);
500}
497 501
498/* iterates the non-control endpoints; 'tmp' is a struct usb_ep pointer */ 502/* iterates the non-control endpoints; 'tmp' is a struct usb_ep pointer */
499#define gadget_for_each_ep(tmp,gadget) \ 503#define gadget_for_each_ep(tmp,gadget) \