Subject: [PATCH] usb, ACPI: Separate out usb_acpi_find_bridge

usb_acpi_find_device is for usb_device and it has usb_device_type and usb_bus_type.
So could remove not needed is_usb_device checking.

usb_acpi_find_bridge is for usb_port, and it has usb_port_device_type only.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Lan Tianyu <tianyu.lan@intel.com>
Cc: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Cc: Matthew Garrett <mjg@redhat.com>
Cc: Len Brown <len.brown@intel.com>

---
 drivers/usb/core/usb-acpi.c |  137 +++++++++++++++++++++++---------------------
 1 file changed, 72 insertions(+), 65 deletions(-)

Index: linux-2.6/drivers/usb/core/usb-acpi.c
===================================================================
--- linux-2.6.orig/drivers/usb/core/usb-acpi.c
+++ linux-2.6/drivers/usb/core/usb-acpi.c
@@ -125,93 +125,100 @@ out:
 	return ret;
 }
 
-static int usb_acpi_find_device(struct device *dev, acpi_handle *handle)
+/*
+ * In the ACPI DSDT table, only usb root hub and usb ports are
+ * acpi device nodes. The hierarchy like following.
+ * Device (EHC1)
+ *	Device (HUBN)
+ *		Device (PR01)
+ *			Device (PR11)
+ *			Device (PR12)
+ *			Device (PR13)
+ *			...
+ * So all binding process is divided into two parts. binding
+ * root hub and usb ports.
+ */
+
+static int usb_acpi_find_bridge(struct device *dev, acpi_handle *handle)
 {
 	struct usb_device *udev;
 	acpi_handle *parent_handle;
 	int port_num;
 
+	if (!is_usb_port(dev))
+		return -ENODEV;
+
+	sscanf(dev_name(dev), "port%d", &port_num);
+	/* Get the struct usb_device point of port's hub */
+	udev = to_usb_device(dev->parent->parent);
+
 	/*
-	 * In the ACPI DSDT table, only usb root hub and usb ports are
-	 * acpi device nodes. The hierarchy like following.
-	 * Device (EHC1)
-	 *	Device (HUBN)
-	 *		Device (PR01)
-	 *			Device (PR11)
-	 *			Device (PR12)
-	 *			Device (PR13)
-	 *			...
-	 * So all binding process is divided into two parts. binding
-	 * root hub and usb ports.
+	 * The root hub ports' parent is the root hub. The non-root-hub
+	 * ports' parent is the parent hub port which the hub is
+	 * connected to.
 	 */
-	if (is_usb_device(dev)) {
-		udev = to_usb_device(dev);
-		if (udev->parent) {
-			enum usb_port_connect_type type;
-
-			/*
-			 * According usb port's connect type to set usb device's
-			 * removability.
-			 */
-			type = usb_get_hub_port_connect_type(udev->parent,
-				udev->portnum);
-			switch (type) {
-			case USB_PORT_CONNECT_TYPE_HOT_PLUG:
-				udev->removable = USB_DEVICE_REMOVABLE;
-				break;
-			case USB_PORT_CONNECT_TYPE_HARD_WIRED:
-				udev->removable = USB_DEVICE_FIXED;
-				break;
-			default:
-				udev->removable = USB_DEVICE_REMOVABLE_UNKNOWN;
-				break;
-			}
-
+	if (!udev->parent) {
+		*handle = acpi_get_child(DEVICE_ACPI_HANDLE(&udev->dev),
+			port_num);
+		if (!*handle)
+			return -ENODEV;
+	} else {
+		parent_handle =
+			usb_get_hub_port_acpi_handle(udev->parent,
+			udev->portnum);
+		if (!parent_handle)
 			return -ENODEV;
-		}
 
-		/* root hub's parent is the usb hcd. */
-		parent_handle = DEVICE_ACPI_HANDLE(dev->parent);
-		*handle = acpi_get_child(parent_handle, udev->portnum);
+		*handle = acpi_get_child(parent_handle,	port_num);
 		if (!*handle)
 			return -ENODEV;
-		return 0;
-	} else if (is_usb_port(dev)) {
-		sscanf(dev_name(dev), "port%d", &port_num);
-		/* Get the struct usb_device point of port's hub */
-		udev = to_usb_device(dev->parent->parent);
+	}
+		usb_acpi_check_port_connect_type(udev, *handle, port_num);
+
+	return 0;
+}
+
+static int usb_acpi_find_device(struct device *dev, acpi_handle *handle)
+{
+	struct usb_device *udev;
+	acpi_handle *parent_handle;
+
+	udev = to_usb_device(dev);
+	if (udev->parent) {
+		enum usb_port_connect_type type;
 
 		/*
-		 * The root hub ports' parent is the root hub. The non-root-hub
-		 * ports' parent is the parent hub port which the hub is
-		 * connected to.
+		 * According usb port's connect type to set usb device's
+		 * removability.
 		 */
-		if (!udev->parent) {
-			*handle = acpi_get_child(DEVICE_ACPI_HANDLE(&udev->dev),
-				port_num);
-			if (!*handle)
-				return -ENODEV;
-		} else {
-			parent_handle =
-				usb_get_hub_port_acpi_handle(udev->parent,
-				udev->portnum);
-			if (!parent_handle)
-				return -ENODEV;
-
-			*handle = acpi_get_child(parent_handle,	port_num);
-			if (!*handle)
-				return -ENODEV;
+		type = usb_get_hub_port_connect_type(udev->parent,
+			udev->portnum);
+		switch (type) {
+		case USB_PORT_CONNECT_TYPE_HOT_PLUG:
+			udev->removable = USB_DEVICE_REMOVABLE;
+			break;
+		case USB_PORT_CONNECT_TYPE_HARD_WIRED:
+			udev->removable = USB_DEVICE_FIXED;
+			break;
+		default:
+			udev->removable = USB_DEVICE_REMOVABLE_UNKNOWN;
+			break;
 		}
-		usb_acpi_check_port_connect_type(udev, *handle, port_num);
-	} else
+
 		return -ENODEV;
+	}
 
+	/* root hub's parent is the usb hcd. */
+	parent_handle = DEVICE_ACPI_HANDLE(dev->parent);
+	*handle = acpi_get_child(parent_handle, udev->portnum);
+	if (!*handle)
+		return -ENODEV;
 	return 0;
 }
 
 static struct acpi_bus_type usb_acpi_bus = {
 	.bus = &usb_bus_type,
-	.find_bridge = usb_acpi_find_device,
+	.find_bridge = usb_acpi_find_bridge,
 	.find_device = usb_acpi_find_device,
 };
 
