Skip to content

Commit

Permalink
USB: Composite framework: Add suspended sysfs entry
Browse files Browse the repository at this point in the history
This patch adds a sysfs entry (/sys/devices/platform/_UDC_/gadget/suspended) to
show the suspend state of an USB composite gadget.

Signed-off-by: Fabien Chouteau <fabien.chouteau@barco.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Fabien Chouteau authored and Greg Kroah-Hartman committed May 20, 2010
1 parent 326b481 commit f48cf80
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Documentation/ABI/testing/sysfs-devices-platform-_UDC_-gadget
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
What: /sys/devices/platform/_UDC_/gadget/suspended
Date: April 2010
Contact: Fabien Chouteau <fabien.chouteau@barco.com>
Description:
Show the suspend state of an USB composite gadget.
1 -> suspended
0 -> resumed

(_UDC_ is the name of the USB Device Controller driver)
21 changes: 21 additions & 0 deletions drivers/usb/gadget/composite.c
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,18 @@ static void composite_disconnect(struct usb_gadget *gadget)

/*-------------------------------------------------------------------------*/

static ssize_t composite_show_suspended(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct usb_gadget *gadget = dev_to_usb_gadget(dev);
struct usb_composite_dev *cdev = get_gadget_data(gadget);

return sprintf(buf, "%d\n", cdev->suspended);
}

static DEVICE_ATTR(suspended, 0444, composite_show_suspended, NULL);

static void /* __init_or_exit */
composite_unbind(struct usb_gadget *gadget)
{
Expand Down Expand Up @@ -944,6 +956,7 @@ composite_unbind(struct usb_gadget *gadget)
}
kfree(cdev);
set_gadget_data(gadget, NULL);
device_remove_file(&gadget->dev, &dev_attr_suspended);
composite = NULL;
}

Expand Down Expand Up @@ -1036,6 +1049,10 @@ static int __init composite_bind(struct usb_gadget *gadget)
string_override(composite->strings,
cdev->desc.iSerialNumber, iSerialNumber);

status = device_create_file(&gadget->dev, &dev_attr_suspended);
if (status)
goto fail;

INFO(cdev, "%s ready\n", composite->name);
return 0;

Expand Down Expand Up @@ -1064,6 +1081,8 @@ composite_suspend(struct usb_gadget *gadget)
}
if (composite->suspend)
composite->suspend(cdev);

cdev->suspended = 1;
}

static void
Expand All @@ -1084,6 +1103,8 @@ composite_resume(struct usb_gadget *gadget)
f->resume(f);
}
}

cdev->suspended = 0;
}

/*-------------------------------------------------------------------------*/
Expand Down
1 change: 1 addition & 0 deletions include/linux/usb/composite.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ struct usb_composite_dev {

/* private: */
/* internals */
unsigned int suspended:1;
struct usb_device_descriptor desc;
struct list_head configs;
struct usb_composite_driver *driver;
Expand Down
4 changes: 4 additions & 0 deletions include/linux/usb/gadget.h
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,10 @@ static inline void set_gadget_data(struct usb_gadget *gadget, void *data)
{ dev_set_drvdata(&gadget->dev, data); }
static inline void *get_gadget_data(struct usb_gadget *gadget)
{ return dev_get_drvdata(&gadget->dev); }
static inline struct usb_gadget *dev_to_usb_gadget(struct device *dev)
{
return container_of(dev, struct usb_gadget, dev);
}

/* iterates the non-control endpoints; 'tmp' is a struct usb_ep pointer */
#define gadget_for_each_ep(tmp,gadget) \
Expand Down

0 comments on commit f48cf80

Please sign in to comment.