[RFC PATCH 1/5] usb: Register usb port's acpi power resources

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch is to register usb port's acpi power resources. Create
link between usb port device and its acpi power resource.

Signed-off-by: Lan Tianyu <tianyu.lan@xxxxxxxxx>
---
 drivers/usb/core/hub.c      |    3 ++-
 drivers/usb/core/usb-acpi.c |   23 +++++++++++++++++++++++
 drivers/usb/core/usb.h      |    6 ++++++
 3 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 55c086e..d0e1f08 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -2072,7 +2072,7 @@ void usb_disconnect(struct usb_device **pdev)
 	spin_unlock_irq(&device_state_lock);
 
 	hub_free_dev(udev);
-
+	usb_acpi_unregister_power_resources(udev);
 	put_device(&udev->dev);
 }
 
@@ -2365,6 +2365,7 @@ int usb_new_device(struct usb_device *udev)
 	(void) usb_create_ep_devs(&udev->dev, &udev->ep0, udev);
 	usb_mark_last_busy(udev);
 	pm_runtime_put_sync_autosuspend(&udev->dev);
+	usb_acpi_register_power_resources(udev);
 	return err;
 
 fail:
diff --git a/drivers/usb/core/usb-acpi.c b/drivers/usb/core/usb-acpi.c
index cef4252..7388df3 100644
--- a/drivers/usb/core/usb-acpi.c
+++ b/drivers/usb/core/usb-acpi.c
@@ -216,6 +216,29 @@ static struct acpi_bus_type usb_acpi_bus = {
 	.find_device = usb_acpi_find_device,
 };
 
+int usb_acpi_register_power_resources(struct usb_device *udev)
+{
+	acpi_handle port_handle = DEVICE_ACPI_HANDLE(&udev->dev);
+
+	if (!port_handle)
+		return -ENODEV;
+
+	if (acpi_power_resource_register_device(&udev->dev, port_handle) < 0)
+		return -ENODEV;
+	return 0;
+}
+
+int usb_acpi_unregister_power_resources(struct usb_device *udev)
+{
+	acpi_handle port_handle = DEVICE_ACPI_HANDLE(&udev->dev);
+
+	if (!port_handle)
+		return -ENODEV;
+
+	acpi_power_resource_register_device(&udev->dev, port_handle);
+	return 0;
+}
+
 int usb_acpi_register(void)
 {
 	return register_acpi_bus_type(&usb_acpi_bus);
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h
index 1633f6e..0de01a6 100644
--- a/drivers/usb/core/usb.h
+++ b/drivers/usb/core/usb.h
@@ -175,7 +175,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 usb_device *udev);
+extern int usb_acpi_unregister_power_resources(struct usb_device *udev);
 #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 usb_device *udev)
+	{ return 0; }
+static inline int usb_acpi_unregister_power_resources(struct usb_device *udev)
+	{ return 0; }
 #endif
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux