From 352396c43add1154c9b44ba66f03b01d6199bab6 Mon Sep 17 00:00:00 2001 From: Pavankumar Kondeti Date: Wed, 7 Dec 2011 13:32:40 +0530 Subject: [PATCH] USB: android: Provide sysfs file for enabling remote wakeup capability USB device can specify remote wakeup capability in the configuration descriptor. Host may select remote wakeup feature before suspending the device. Remote wakeup capability is disabled by default in android gadget. Provide sysfs file for enabling remote wakeup capability. User space can enable/disable this capability based on the selected composition. This will also allow testing suspend/resume chapter 9 tests with remote wakeup enabled. Change-Id: Ib24aa6c05ace697564ebe5940e62e8f65db4d7c3 Signed-off-by: Pavankumar Kondeti --- drivers/usb/gadget/android.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/usb/gadget/android.c b/drivers/usb/gadget/android.c index c8807993131..af6f3513dbb 100644 --- a/drivers/usb/gadget/android.c +++ b/drivers/usb/gadget/android.c @@ -1090,6 +1090,32 @@ static int android_enable_function(struct android_dev *dev, char *name) /*-------------------------------------------------------------------------*/ /* /sys/class/android_usb/android%d/ interface */ +static ssize_t remote_wakeup_show(struct device *pdev, + struct device_attribute *attr, char *buf) +{ + return snprintf(buf, PAGE_SIZE, "%d\n", + !!(android_config_driver.bmAttributes & + USB_CONFIG_ATT_WAKEUP)); +} + +static ssize_t remote_wakeup_store(struct device *pdev, + struct device_attribute *attr, const char *buff, size_t size) +{ + int enable = 0; + + sscanf(buff, "%d", &enable); + + pr_debug("android_usb: %s remote wakeup\n", + enable ? "enabling" : "disabling"); + + if (enable) + android_config_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; + else + android_config_driver.bmAttributes &= ~USB_CONFIG_ATT_WAKEUP; + + return size; +} + static ssize_t functions_show(struct device *pdev, struct device_attribute *attr, char *buf) { @@ -1245,6 +1271,8 @@ DESCRIPTOR_STRING_ATTR(iSerial, serial_string) static DEVICE_ATTR(functions, S_IRUGO | S_IWUSR, functions_show, functions_store); static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, enable_show, enable_store); static DEVICE_ATTR(state, S_IRUGO, state_show, NULL); +static DEVICE_ATTR(remote_wakeup, S_IRUGO | S_IWUSR, + remote_wakeup_show, remote_wakeup_store); static struct device_attribute *android_usb_attributes[] = { &dev_attr_idVendor, @@ -1259,6 +1287,7 @@ static struct device_attribute *android_usb_attributes[] = { &dev_attr_functions, &dev_attr_enable, &dev_attr_state, + &dev_attr_remote_wakeup, NULL };