|
@@ -248,6 +248,41 @@ static void remove_persist_attributes(struct device *dev)
|
|
|
|
|
|
#ifdef CONFIG_USB_SUSPEND
|
|
#ifdef CONFIG_USB_SUSPEND
|
|
|
|
|
|
|
|
+static ssize_t
|
|
|
|
+show_connected_duration(struct device *dev, struct device_attribute *attr,
|
|
|
|
+ char *buf)
|
|
|
|
+{
|
|
|
|
+ struct usb_device *udev = to_usb_device(dev);
|
|
|
|
+
|
|
|
|
+ return sprintf(buf, "%u\n",
|
|
|
|
+ jiffies_to_msecs(jiffies - udev->connect_time));
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static DEVICE_ATTR(connected_duration, S_IRUGO, show_connected_duration, NULL);
|
|
|
|
+
|
|
|
|
+/*
|
|
|
|
+ * If the device is resumed, the last time the device was suspended has
|
|
|
|
+ * been pre-subtracted from active_duration. We add the current time to
|
|
|
|
+ * get the duration that the device was actually active.
|
|
|
|
+ *
|
|
|
|
+ * If the device is suspended, the active_duration is up-to-date.
|
|
|
|
+ */
|
|
|
|
+static ssize_t
|
|
|
|
+show_active_duration(struct device *dev, struct device_attribute *attr,
|
|
|
|
+ char *buf)
|
|
|
|
+{
|
|
|
|
+ struct usb_device *udev = to_usb_device(dev);
|
|
|
|
+ int duration;
|
|
|
|
+
|
|
|
|
+ if (udev->state != USB_STATE_SUSPENDED)
|
|
|
|
+ duration = jiffies_to_msecs(jiffies + udev->active_duration);
|
|
|
|
+ else
|
|
|
|
+ duration = jiffies_to_msecs(udev->active_duration);
|
|
|
|
+ return sprintf(buf, "%u\n", duration);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static DEVICE_ATTR(active_duration, S_IRUGO, show_active_duration, NULL);
|
|
|
|
+
|
|
static ssize_t
|
|
static ssize_t
|
|
show_autosuspend(struct device *dev, struct device_attribute *attr, char *buf)
|
|
show_autosuspend(struct device *dev, struct device_attribute *attr, char *buf)
|
|
{
|
|
{
|
|
@@ -365,12 +400,26 @@ static int add_power_attributes(struct device *dev)
|
|
rc = sysfs_add_file_to_group(&dev->kobj,
|
|
rc = sysfs_add_file_to_group(&dev->kobj,
|
|
&dev_attr_level.attr,
|
|
&dev_attr_level.attr,
|
|
power_group);
|
|
power_group);
|
|
|
|
+ if (rc == 0)
|
|
|
|
+ rc = sysfs_add_file_to_group(&dev->kobj,
|
|
|
|
+ &dev_attr_connected_duration.attr,
|
|
|
|
+ power_group);
|
|
|
|
+ if (rc == 0)
|
|
|
|
+ rc = sysfs_add_file_to_group(&dev->kobj,
|
|
|
|
+ &dev_attr_active_duration.attr,
|
|
|
|
+ power_group);
|
|
}
|
|
}
|
|
return rc;
|
|
return rc;
|
|
}
|
|
}
|
|
|
|
|
|
static void remove_power_attributes(struct device *dev)
|
|
static void remove_power_attributes(struct device *dev)
|
|
{
|
|
{
|
|
|
|
+ sysfs_remove_file_from_group(&dev->kobj,
|
|
|
|
+ &dev_attr_active_duration.attr,
|
|
|
|
+ power_group);
|
|
|
|
+ sysfs_remove_file_from_group(&dev->kobj,
|
|
|
|
+ &dev_attr_connected_duration.attr,
|
|
|
|
+ power_group);
|
|
sysfs_remove_file_from_group(&dev->kobj,
|
|
sysfs_remove_file_from_group(&dev->kobj,
|
|
&dev_attr_level.attr,
|
|
&dev_attr_level.attr,
|
|
power_group);
|
|
power_group);
|