usb: Register usb port's acpi power resources
authorLan Tianyu <tianyu.lan@intel.com>
Tue, 22 Jan 2013 20:26:27 +0000 (04:26 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 25 Jan 2013 18:07:59 +0000 (10:07 -0800)
This patch is to register usb port's acpi power resources. Create
link between usb port device and its acpi power resource.

Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/core/port.c
drivers/usb/core/usb-acpi.c
drivers/usb/core/usb.h

index fe5959f..153e799 100644 (file)
@@ -66,6 +66,7 @@ static void usb_port_device_release(struct device *dev)
 {
        struct usb_port *port_dev = to_usb_port(dev);
 
+       usb_acpi_unregister_power_resources(dev);
        kfree(port_dev);
 }
 
@@ -95,6 +96,10 @@ int usb_hub_create_port_device(struct usb_hub *hub, int port1)
        if (retval)
                goto error_register;
 
+       retval = usb_acpi_register_power_resources(&port_dev->dev);
+       if (retval && retval != -ENODEV)
+               dev_warn(&port_dev->dev, "the port can't register its ACPI power resource.\n");
+
        return 0;
 
 error_register:
index cef4252..8d304b0 100644 (file)
@@ -216,6 +216,24 @@ static struct acpi_bus_type usb_acpi_bus = {
        .find_device = usb_acpi_find_device,
 };
 
+int usb_acpi_register_power_resources(struct device *dev)
+{
+       acpi_handle port_handle = DEVICE_ACPI_HANDLE(dev);
+
+       if (!port_handle)
+               return -ENODEV;
+
+       return acpi_power_resource_register_device(dev, port_handle);
+}
+
+void usb_acpi_unregister_power_resources(struct device *dev)
+{
+       acpi_handle port_handle = DEVICE_ACPI_HANDLE(dev);
+
+       if (port_handle)
+               acpi_power_resource_unregister_device(dev, port_handle);
+}
+
 int usb_acpi_register(void)
 {
        return register_acpi_bus_type(&usb_acpi_bus);
index a7f20bd..601b044 100644 (file)
@@ -191,7 +191,13 @@ extern int usb_acpi_register(void);
 extern void usb_acpi_unregister(void);
 extern acpi_handle usb_get_hub_port_acpi_handle(struct usb_device *hdev,
        int port1);
+extern int usb_acpi_register_power_resources(struct device *dev);
+extern void usb_acpi_unregister_power_resources(struct device *dev);
 #else
 static inline int usb_acpi_register(void) { return 0; };
 static inline void usb_acpi_unregister(void) { };
+static inline int usb_acpi_register_power_resources(struct device *dev)
+       { return 0; };
+static inline void usb_acpi_unregister_power_resources(struct device *dev)
+       { };
 #endif