Skip to contentSkip to conversation

usb/acpi: Add binding usb device with acpi

PATCH RESEND In review Lan Tianyu 4 participants 15 messages May 11, 2012 – May 12, 2012 3 messages not in the archive

Subsystems (4)
lore
Share & tools
lore

Lan Tianyu

author
#0 lore raw

v3 cover usb/acpi: Add binding usb device with acpi

This patchset's purppose is to bind usb device with associated acpi node. The ACPI method "_PLD" and "_UPC" can be used to identify usb port's connect type(hot-plug, hard-wired and not-used). The patchset also can work on the port without device connected.

This patchset derives from following patches.

Quoted 1 line

From Matthew Garrett

[PATCH V2 2/4] ACPI: Add _PLD support
[PATCH V2 3/4] usb: Bind devices to ACPI devices when possible [PATCH v2 4/4] usb: Set device removable state based on ACPI USB data

Quoted 1 line

From Tianyu Lan

[PATCH V3 1/4] usb: add struct usb_hub_port to store port related members
[PATCH V3 2/4] usb: move struct usb_device->children to struct usb_hub_port->child [PATCH V3 3/4] usb/acpi: add the support of usb hub ports' acpi binding without attached devices. [PATCH V3 4/4] usb/acpi: add usb check for the connect type of usb port

Previously those patches was blocked by [PATCH V2 1/4] ACPI: Fix up _PLD methods. Current the final version of this patch has been integrated into ACPICA and released as:
6a99b1c94d053b3420eaa4a4bc8b2883dd90a2f9
ACPICA: Object repair code: Support to add Package wrappers

[Resend PATCH V3 1/8] ACPI: Add stubs for (un)register_acpi_bus_type [Resend PATCH V3 2/8] ACPI: Add _PLD support
[Resend PATCH V3 3/8] usb: Bind devices to ACPI devices when [Resend PATCH V3 4/8] usb: Set device removable state based on ACPI [Resend PATCH V3 5/8] usb: add struct usb_hub_port to store port [Resend PATCH V3 6/8] usb: move struct usb_device->children to [Resend PATCH V3 7/8] usb/acpi: add the support of usb hub ports' [Resend PATCH V3 8/8] usb/acpi: add usb check for the connect type

git diff --stat

 drivers/acpi/glue.c                  |    2 +
 drivers/acpi/utils.c                 |   30 +++++++
 drivers/staging/usbip/usbip_common.c |    3 +-
 drivers/usb/core/Makefile            |    1 +
 drivers/usb/core/devices.c           |    3 +-
 drivers/usb/core/hub.c               |  135 +++++++++++++++++++++---------
 drivers/usb/core/usb-acpi.c          |  155 ++++++++++++++++++++++++++++++++++
 drivers/usb/core/usb.c               |    6 ++
 drivers/usb/core/usb.h               |   19 ++++-
 drivers/usb/host/r8a66597-hcd.c      |    3 +-
 include/acpi/acpi_bus.h              |   36 ++++++++
 include/linux/usb.h                  |   11 ++-
 12 files changed, 358 insertions(+), 46 deletions(-)

Based on the usb-next tree
Lastest commit
commit d530296f63c039a5683db665acc5ecdb3b593eb2

Author: Greg Kroah-Hartman <[email protected]>
Date:   Thu May 10 14:35:21 2012 -0700

USB: serial: opticon: hook up suspend/resume callbacks

With a previous patch, the usb_driver suspend/resume callbacks got overridden and were never called if a usb_serial driver defined them. This patch fixes the opticon driver to move the suspend/resume callbacks into the usb_serial_driver structure where they will be properly called.

It then removes the unused usb_driver structure.

Cc Johan Hovold <[email protected]>
Cc Rusty Russell <[email protected]>
Cc Kuninori Morimoto <[email protected]>
Cc Julia Lawall <[email protected]>
Cc Alan Stern <[email protected]>

A message that is not in the archive (sent off-list or not yet received): 1336723712-7686-1-git-send-email-tianyu.lan-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org

#2 lore raw

PATCH RESEND v3 1/8 ACPI: Add stubs for (un)register_acpi_bus_type

From: Matthew Garrett <[email protected]>

It's unreasonable to have CONFIG_ACPI for these in drivers, so add some stub functions.

---
 drivers/acpi/glue.c     |    2 ++
 include/acpi/acpi_bus.h |    5 +++++
 2 files changed, 7 insertions(+), 0 deletions(-)
drivers/acpi/glue.c +2 -0
index 29a4a5c..1564e09 100644
@@ -69,6 +69,7 @@ static struct acpi_bus_type *acpi_get_bus_type(struct bus_type *type)
 	up_read(&bus_type_sem);
 	return ret;
 }
+EXPORT_SYMBOL_GPL(register_acpi_bus_type);
 
 static int acpi_find_bridge_device(struct device *dev, acpi_handle * handle)
 {
@@ -85,6 +86,7 @@ static int acpi_find_bridge_device(struct device *dev, acpi_handle * handle)
 	up_read(&bus_type_sem);
 	return ret;
 }
+EXPORT_SYMBOL_GPL(unregister_acpi_bus_type);
 
 /* Get device's handler per its address under its parent */
 struct acpi_find_child {
include/acpi/acpi_bus.h +5 -0
index f1c8ca6..c909984 100644
@@ -407,6 +407,11 @@ static inline int acpi_pm_device_sleep_wake(struct device *dev, bool enable)
 }
 #endif
 
+#else	/* CONFIG_ACPI */
+
+static int register_acpi_bus_type(struct acpi_bus_type *bus) { return 0; }
+static int unregister_acpi_bus_type(struct acpi_bus_type *bus) { return 0; }
+
 #endif				/* CONFIG_ACPI */
 
 #endif /*__ACPI_BUS_H__*/
Signature · 6 lines
1.7.6.rc2.8.g28eb

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw

PATCH RESEND v3 2/8 ACPI: Add _PLD support

In reply to a message not in the archive

From: Matthew Garrett <[email protected]>

Add a simple helper function to allow drivers to obtain the physical device location data.

---
 drivers/acpi/utils.c    |   30 ++++++++++++++++++++++++++++++
 include/acpi/acpi_bus.h |   31 +++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+), 0 deletions(-)
drivers/acpi/utils.c +30 -0
index b002a47..adbbc1c 100644
@@ -382,3 +382,33 @@ acpi_evaluate_reference(acpi_handle handle,
 }
 
 EXPORT_SYMBOL(acpi_evaluate_reference);
+
+acpi_status
+acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld *pld)
+{
+	acpi_status status;
+	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
+	union acpi_object *output;
+
+	status = acpi_evaluate_object(handle, "_PLD", NULL, &buffer);
+
+	if (ACPI_FAILURE(status))
+		return status;
+
+	output = buffer.pointer;
+
+	if (!output || output->type != ACPI_TYPE_PACKAGE
+	    || !output->package.count
+	    || output->package.elements[0].type != ACPI_TYPE_BUFFER
+	    || output->package.elements[0].buffer.length > sizeof(*pld)) {
+		status = AE_TYPE;
+		goto out;
+	}
+
+	memcpy(pld, output->package.elements[0].buffer.pointer,
+	       output->package.elements[0].buffer.length);
+out:
+	kfree(buffer.pointer);
+	return status;
+}
+EXPORT_SYMBOL(acpi_get_physical_device_location);
include/acpi/acpi_bus.h +31 -0
index c909984..b0d6282 100644
@@ -51,6 +51,37 @@ acpi_evaluate_reference(acpi_handle handle,
 			struct acpi_object_list *arguments,
 			struct acpi_handle_list *list);
 
+struct acpi_pld {
+	unsigned int revision:7; /* 0 */
+	unsigned int ignore_colour:1; /* 7 */
+	unsigned int colour:24; /* 8 */
+	unsigned int width:16; /* 32 */
+	unsigned int height:16; /* 48 */
+	unsigned int user_visible:1; /* 64 */
+	unsigned int dock:1; /* 65 */
+	unsigned int lid:1; /* 66 */
+	unsigned int panel:3; /* 67 */
+	unsigned int vertical_pos:2; /* 70 */
+	unsigned int horizontal_pos:2; /* 72 */
+	unsigned int shape:4; /* 74 */
+	unsigned int group_orientation:1; /* 78 */
+	unsigned int group_token:8; /* 79 */
+	unsigned int group_position:8; /* 87 */
+	unsigned int bay:1; /* 95 */
+	unsigned int ejectable:1; /* 96 */
+	unsigned int ospm_eject_required:1; /* 97 */
+	unsigned int cabinet_number:8; /* 98 */
+	unsigned int card_cage_number:8; /* 106 */
+	unsigned int reference:1; /* 114 */
+	unsigned int rotation:4; /* 115 */
+	unsigned int order:5; /* 119 */
+	unsigned int reserved:4; /* 124 */
+	unsigned int vertical_offset:16; /* 128 */
+	unsigned int horizontal_offset:16; /* 144 */
+} __attribute__((__packed__));
+
+acpi_status
+acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld *pld);
 #ifdef CONFIG_ACPI
 
 #include <linux/proc_fs.h>
Signature · 6 lines
1.7.6.rc2.8.g28eb

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#4 lore raw

PATCH RESEND v3 6/8 usb: move struct usb_device->children to struct usb_hub_port->child

In reply to a message not in the archive

Move child's pointer to the struct usb_hub_port since the child device is directly associated with the port. Provide usb_get_hub_child_device() to get child's pointer.

---
 drivers/staging/usbip/usbip_common.c |    3 +-
 drivers/usb/core/devices.c           |    3 +-
 drivers/usb/core/hub.c               |   67 ++++++++++++++++++++--------------
 drivers/usb/host/r8a66597-hcd.c      |    3 +-
 include/linux/usb.h                  |    4 +-
 5 files changed, 47 insertions(+), 33 deletions(-)
drivers/staging/usbip/usbip_common.c +1 -2
index 70f23026..95beb76 100644
@@ -157,8 +157,7 @@ static void usbip_dump_usb_device(struct usb_device *udev)
 	dev_dbg(dev, "have_langid %d, string_langid %d\n",
 		udev->have_langid, udev->string_langid);
 
-	dev_dbg(dev, "maxchild %d, children %p\n",
-		udev->maxchild, udev->children);
+	dev_dbg(dev, "maxchild %d\n", udev->maxchild);
 }
 
 static void usbip_dump_request_type(__u8 rt)
drivers/usb/core/devices.c +2 -1
index d956965..a83962b 100644
@@ -590,7 +590,8 @@ static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes,
 
 	/* Now look at all of this device's children. */
 	for (chix = 0; chix < usbdev->maxchild; chix++) {
-		struct usb_device *childdev = usbdev->children[chix];
+		struct usb_device *childdev =
+			usb_get_hub_child_device(usbdev, chix + 1);
 
 		if (childdev) {
 			usb_lock_device(childdev);
drivers/usb/core/hub.c +40 -27

216 lines not on this page · raw message

drivers/usb/host/r8a66597-hcd.c +2 -1
index c868be6..4c82fdf 100644
@@ -2040,7 +2040,8 @@ static void collect_usb_address_map(struct usb_device *udev, unsigned long *map)
 		map[udev->devnum/32] |= (1 << (udev->devnum % 32));
 
 	for (chix = 0; chix < udev->maxchild; chix++) {
-		struct usb_device *childdev = udev->children[chix];
+		struct usb_device *childdev =
+			usb_get_hub_child_device(udev, chix + 1);
 
 		if (childdev)
 			collect_usb_address_map(childdev, map);
include/linux/usb.h +2 -2
index 5483cd7..69163a0 100644
@@ -424,7 +424,6 @@ enum usb_device_removable {
  *	access from userspace
  * @usbfs_dentry: usbfs dentry entry for the device
  * @maxchild: number of ports if hub
- * @children: child devices - USB devices that are attached to this hub
  * @quirks: quirks of the whole device
  * @urbnum: number of URBs submitted for the whole device
  * @active_duration: total time device is not suspended
@@ -491,7 +490,6 @@ struct usb_device {
 	struct list_head filelist;
 
 	int maxchild;
-	struct usb_device **children;
 
 	u32 quirks;
 	atomic_t urbnum;
@@ -517,6 +515,8 @@ static inline struct usb_device *interface_to_usbdev(struct usb_interface *intf)
 
 extern struct usb_device *usb_get_dev(struct usb_device *dev);
 extern void usb_put_dev(struct usb_device *dev);
+extern struct usb_device *usb_get_hub_child_device(struct usb_device *hdev,
+	int port1);
 
 /* USB device locking */
 #define usb_lock_device(udev)		device_lock(&(udev)->dev)
Signature · 6 lines
1.7.6.rc2.8.g28eb

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
maintainer
#5 lore raw

Re: [Resend PATCH V3 6/8] usb: move struct usb_device->children to struct usb_hub_port->child

drivers/usb/core/hub.c void usb_queue_reset_device(struct usb_interface *iface) · line 4248

Quoted 10 lines · Lan Tianyu
drivers/usb/core/hub.c +10 -0
+struct usb_device *usb_get_hub_child_device(struct usb_device *hdev,
+	int port1)
+{
+	struct usb_hub *hub = hdev_to_hub(hdev);
+
+	if (!hub || port1 > hdev->maxchild || port1 < 1)
+		return NULL;
+	return hub->port_data[port1 - 1].child;
+}
+EXPORT_SYMBOL_GPL(usb_get_hub_child_device);

We need kerneldoc documentation for this new public function. Please send a follow-on patch that adds this.

thanks,

greg k-h

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw

Re: [Resend PATCH V3 6/8] usb: move struct usb_device->children to struct usb_hub_port->child

Quoted 14 lines · Greg KH

drivers/usb/core/hub.c void usb_queue_reset_device(struct usb_interface *iface) · line 4248

Quoted 10 lines · Lan Tianyu
drivers/usb/core/hub.c +10 -0
+struct usb_device *usb_get_hub_child_device(struct usb_device *hdev,
+	int port1)
+{
+	struct usb_hub *hub = hdev_to_hub(hdev);
+
+	if (!hub || port1>  hdev->maxchild || port1<  1)
+		return NULL;
+	return hub->port_data[port1 - 1].child;
+}
+EXPORT_SYMBOL_GPL(usb_get_hub_child_device);

We need kerneldoc documentation for this new public function. Please send a follow-on patch that adds this.

Ok. I will do it later.

Quoted 3 lines

thanks,

greg k-h

Signature · 8 lines
Best Regards
Tianyu Lan
linux kernel enabling team

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#8 lore raw

PATCH RESEND v3 8/8 usb/acpi: add usb check for the connect type of usb port

In reply to a message not in the archive

Check the connect type of usb port when getting the usb port's acpi_handle and store result into connect_type in the struct usb_hub_port.

Accoding to ACPI Spec 9.13. PLD indicates whether usb port is user visible and _UPC indicates whether it is connectable. If the port was visible and connectable, it could be freely connected and disconnected with USB devices. If no visible and connectable, a usb device is directly hard-wired to the port. If no visible and no connectable, the port would be not used.

When a device was found on the port, if the connect_type was hot-plug, then the device would be removable. If the connect_type was hard-wired, the device would be non-removable.

---
 drivers/usb/core/hub.c      |   21 +++++++++++++
 drivers/usb/core/usb-acpi.c |   67 ++++++++++++++++++++++--------------------
 drivers/usb/core/usb.h      |    4 ++
 include/linux/usb.h         |    7 ++++
 4 files changed, 67 insertions(+), 32 deletions(-)
drivers/usb/core/hub.c +21 -0
index 338f01b..9632bc3 100644
@@ -41,6 +41,7 @@ struct usb_hub_port {
 	void			*port_owner;
 	struct usb_device	*child;
 	unsigned long		platform_data;
+	enum usb_port_connect_type connect_type;
 };
 
 struct usb_hub {
@@ -4267,3 +4268,23 @@ unsigned long usb_get_hub_port_platform_data(struct usb_device *hdev, int port1)
 		return 0;
 	return hub->port_data[port1 - 1].platform_data;
 }
+
+void usb_set_hub_port_connect_type(struct usb_device *hdev, int port1,
+	enum usb_port_connect_type type)
+{
+	struct usb_hub *hub = hdev_to_hub(hdev);
+
+	if (!hub || port1 > hdev->maxchild || port1 < 1)
+		return;
+	hub->port_data[port1 - 1].connect_type = type;
+}
+
+enum usb_port_connect_type
+usb_get_hub_port_connect_type(struct usb_device *hdev,	int port1)
+{
+	struct usb_hub *hub = hdev_to_hub(hdev);
+
+	if (!hub || port1 > hdev->maxchild || port1 < 1)
+		return USB_PORT_CONNECT_TYPE_UNKNOWN;
+	return hub->port_data[port1 - 1].connect_type;
+}
drivers/usb/core/usb-acpi.c +35 -32

113 lines not on this page · raw message

drivers/usb/core/usb.h +4 -0
index d69d5f6..26fcabc1 100644
@@ -159,6 +159,10 @@ extern unsigned long usb_get_hub_port_platform_data(struct usb_device *hdev,
 	int port1);
 extern void usb_set_hub_port_platform_data(struct usb_device *hdev,
 	int port1, unsigned long data);
+extern enum usb_port_connect_type
+	usb_get_hub_port_connect_type(struct usb_device *hdev, int port1);
+extern void usb_set_hub_port_connect_type(struct usb_device *hdev, int port1,
+	enum usb_port_connect_type type);
 
 #ifdef CONFIG_ACPI
 extern int usb_acpi_register(void);
include/linux/usb.h +7 -0
index 69163a0..2256b78 100644
@@ -378,6 +378,13 @@ enum usb_device_removable {
 	USB_DEVICE_FIXED,
 };
 
+enum usb_port_connect_type {
+	USB_PORT_CONNECT_TYPE_UNKNOWN = 0,
+	USB_PORT_CONNECT_TYPE_HOT_PLUG,
+	USB_PORT_CONNECT_TYPE_HARD_WIRED,
+	USB_PORT_NOT_USED,
+};
+
 /**
  * struct usb_device - kernel's representation of a USB device
  * @devnum: device number; address on a USB bus
Signature · 6 lines
1.7.6.rc2.8.g28eb

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author
#9 lore raw

PATCH RESEND v3 3/8 usb: Bind devices to ACPI devices when possible

In reply to Lan Tianyu

From: Matthew Garrett <[email protected]>

Built-in USB devices will typically have a representation in the system ACPI tables. Add support for binding the two together so the USB code can make use of the associated methods.

---
 drivers/usb/core/Makefile   |    1 +
 drivers/usb/core/usb-acpi.c |   60 +++++++++++++++++++++++++++++++++++++++++++
 drivers/usb/core/usb.c      |    6 ++++
 drivers/usb/core/usb.h      |    7 +++++
 4 files changed, 74 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/core/usb-acpi.c
drivers/usb/core/Makefile +1 -0
index c4ea846..26059b9 100644
@@ -9,5 +9,6 @@ usbcore-y += config.o file.o buffer.o sysfs.o endpoint.o
 usbcore-y += devio.o notify.o generic.o quirks.o devices.o
 
 usbcore-$(CONFIG_PCI)		+= hcd-pci.o
+usbcore-$(CONFIG_ACPI)		+= usb-acpi.o
 
 obj-$(CONFIG_USB)		+= usbcore.o
drivers/usb/core/usb-acpi.c new file +60 -0

60 lines not on this page · raw message

drivers/usb/core/usb.c +6 -0
index 0ce862b..7998a67 100644
@@ -1015,6 +1015,9 @@ static int __init usb_init(void)
 	if (retval)
 		goto out;
 
+	retval = usb_acpi_register();
+	if (retval)
+		goto acpi_register_failed;
 	retval = bus_register(&usb_bus_type);
 	if (retval)
 		goto bus_register_failed;
@@ -1049,6 +1052,8 @@ major_init_failed:
 bus_notifier_failed:
 	bus_unregister(&usb_bus_type);
 bus_register_failed:
+	usb_acpi_unregister();
+acpi_register_failed:
 	usb_debugfs_cleanup();
 out:
 	return retval;
@@ -1070,6 +1075,7 @@ static void __exit usb_exit(void)
 	usb_hub_cleanup();
 	bus_unregister_notifier(&usb_bus_type, &usb_bus_nb);
 	bus_unregister(&usb_bus_type);
+	usb_acpi_unregister();
 	usb_debugfs_cleanup();
 }
 
drivers/usb/core/usb.h +7 -0
index 71648dc..5c5c538 100644
@@ -156,3 +156,10 @@ extern void usb_notify_remove_device(struct usb_device *udev);
 extern void usb_notify_add_bus(struct usb_bus *ubus);
 extern void usb_notify_remove_bus(struct usb_bus *ubus);
 
+#ifdef CONFIG_ACPI
+extern int usb_acpi_register(void);
+extern void usb_acpi_unregister(void);
+#else
+static inline int usb_acpi_register(void) { return 0; };
+static inline void usb_acpi_unregister(void) { };
+#endif
Signature · 1 line
1.7.6.rc2.8.g28eb
author
#10 lore raw

PATCH RESEND v3 4/8 usb: Set device removable state based on ACPI USB data

In reply to Lan Tianyu

From: Matthew Garrett <[email protected]>

ACPI offers two methods that allow us to infer whether or not a USB port is removable. The _PLD method gives us information on whether the port is "user visible" or not. If that's not present then we can fall back to the _UPC method which tells us whether or not a port is connectable.

---
 drivers/usb/core/usb-acpi.c |   57 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 57 insertions(+), 0 deletions(-)
drivers/usb/core/usb-acpi.c +57 -0
index cab5cb7..8947b20 100644
@@ -19,6 +19,54 @@
 
 #include "usb.h"
 
+static int usb_acpi_check_upc(struct usb_device *udev, acpi_handle handle)
+{
+	acpi_status status;
+	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
+	union acpi_object *upc;
+	int ret = 0;
+
+	status = acpi_evaluate_object(handle, "_UPC", NULL, &buffer);
+
+	if (ACPI_FAILURE(status))
+		return -ENODEV;
+
+	upc = buffer.pointer;
+
+	if (!upc || (upc->type != ACPI_TYPE_PACKAGE)
+		|| upc->package.count != 4) {
+		ret = -EINVAL;
+		goto out;
+	}
+
+	if (upc->package.elements[0].integer.value)
+		udev->removable = USB_DEVICE_REMOVABLE;
+	else
+		udev->removable = USB_DEVICE_FIXED;
+
+out:
+	kfree(upc);
+	return ret;
+}
+
+static int usb_acpi_check_pld(struct usb_device *udev, acpi_handle handle)
+{
+	acpi_status status;
+	struct acpi_pld pld;
+
+	status = acpi_get_physical_device_location(handle, &pld);
+
+	if (ACPI_FAILURE(status))
+		return -ENODEV;
+
+	if (pld.user_visible)
+		udev->removable = USB_DEVICE_REMOVABLE;
+	else
+		udev->removable = USB_DEVICE_FIXED;
+
+	return 0;
+}
+
 static int usb_acpi_find_device(struct device *dev, acpi_handle *handle)
 {
 	struct usb_device *udev;
@@ -40,6 +88,15 @@ static int usb_acpi_find_device(struct device *dev, acpi_handle *handle)
 	if (!*handle)
 		return -ENODEV;
 
+	/*
+	 * PLD will tell us whether a port is removable to the user or
+	 * not. If we don't get an answer from PLD (it's not present
+	 * or it's malformed) then try to infer it from UPC. If a
+	 * device isn't connectable then it's probably not removable.
+	 */
+	if (usb_acpi_check_pld(udev, *handle) != 0)
+		usb_acpi_check_upc(udev, *handle);
+
 	return 0;
 }
 
Signature · 1 line
1.7.6.rc2.8.g28eb
author
#11 lore raw

PATCH RESEND v3 5/8 usb: add struct usb_hub_port to store port related members.

In reply to Lan Tianyu

Add struct usb_hub_port pointer port_data in the struct usb_hub and allocate struct usb_hub_port perspectively for each ports to store private data.

---
 drivers/usb/core/hub.c |   29 ++++++++++++++++-------------
 1 files changed, 16 insertions(+), 13 deletions(-)
drivers/usb/core/hub.c +16 -13
index ec6c97d..0c17d5a 100644
@@ -37,6 +37,10 @@
 #endif
 #endif
 
+struct usb_hub_port {
+	void			*port_owner;
+};
+
 struct usb_hub {
 	struct device		*intfdev;	/* the "interface" device */
 	struct usb_device	*hdev;
@@ -81,7 +85,7 @@ struct usb_hub {
 	u8			indicator[USB_MAXCHILDREN];
 	struct delayed_work	leds;
 	struct delayed_work	init_work;
-	void			**port_owners;
+	struct usb_hub_port	*port_data;
 };
 
 static inline int hub_is_superspeed(struct usb_device *hdev)
@@ -1049,8 +1053,9 @@ static int hub_configure(struct usb_hub *hub,
 
 	hdev->children = kzalloc(hdev->maxchild *
 				sizeof(struct usb_device *), GFP_KERNEL);
-	hub->port_owners = kzalloc(hdev->maxchild * sizeof(void *), GFP_KERNEL);
-	if (!hdev->children || !hub->port_owners) {
+	hub->port_data = kzalloc(hdev->maxchild * sizeof(struct usb_hub_port),
+			GFP_KERNEL);
+	if (!hub->port_data || !hdev->children) {
 		ret = -ENOMEM;
 		goto fail;
 	}
@@ -1305,7 +1310,7 @@ static void hub_disconnect(struct usb_interface *intf)
 
 	usb_free_urb(hub->urb);
 	kfree(hdev->children);
-	kfree(hub->port_owners);
+	kfree(hub->port_data);
 	kfree(hub->descriptor);
 	kfree(hub->status);
 	kfree(hub->buffer);
@@ -1437,7 +1442,7 @@ static int find_port_owner(struct usb_device *hdev, unsigned port1,
 	/* This assumes that devices not managed by the hub driver
 	 * will always have maxchild equal to 0.
 	 */
-	*ppowner = &(hdev_to_hub(hdev)->port_owners[port1 - 1]);
+	*ppowner = &(hdev_to_hub(hdev)->port_data[port1 - 1].port_owner);
 	return 0;
 }
 
@@ -1472,16 +1477,14 @@ int usb_hub_release_port(struct usb_device *hdev, unsigned port1, void *owner)
 
 void usb_hub_release_all_ports(struct usb_device *hdev, void *owner)
 {
+	struct usb_hub *hub = hdev_to_hub(hdev);
 	int n;
-	void **powner;
 
-	n = find_port_owner(hdev, 1, &powner);
-	if (n == 0) {
-		for (; n < hdev->maxchild; (++n, ++powner)) {
-			if (*powner == owner)
-				*powner = NULL;
-		}
+	for (n = 0; n < hdev->maxchild; n++) {
+		if (hub->port_data[n].port_owner == owner)
+			hub->port_data[n].port_owner = NULL;
 	}
+
 }
 
 /* The caller must hold udev's lock */
@@ -1492,7 +1495,7 @@ bool usb_device_is_owned(struct usb_device *udev)
 	if (udev->state == USB_STATE_NOTATTACHED || !udev->parent)
 		return false;
 	hub = hdev_to_hub(udev->parent);
-	return !!hub->port_owners[udev->portnum - 1];
+	return !!hub->port_data[udev->portnum - 1].port_owner;
 }
 
 
Signature · 1 line
1.7.6.rc2.8.g28eb
author
#12 lore raw

PATCH RESEND v3 7/8 usb/acpi: add the support of usb hub ports' acpi binding without attached devices.

In reply to Lan Tianyu

The usb port is a device in the acpi table but it's not in the linux usb subsystem. USB hub port doesn't have struct device. So the acpi glue framework only can cover the usb port connected with usb device and store the acpi handle to struct device.archdata.acpi_handle. This patch adds the member platform_data in the struct usb_hub_port and gets the hub port's acpi_handle and store it in the port's platform_data to resolve no attached device no binding problem. The acpi method "_UPC" and "_PLD" can be accessed without attached device.

---
 drivers/usb/core/hub.c      |   20 ++++++++++++++++++++
 drivers/usb/core/usb-acpi.c |   37 ++++++++++++++++++++++++++++++++++++-
 drivers/usb/core/usb.h      |    6 ++++++
 3 files changed, 62 insertions(+), 1 deletions(-)
drivers/usb/core/hub.c +20 -0
index 6bf7124..338f01b 100644
@@ -40,6 +40,7 @@
 struct usb_hub_port {
 	void			*port_owner;
 	struct usb_device	*child;
+	unsigned long		platform_data;
 };
 
 struct usb_hub {
@@ -1263,6 +1264,7 @@ static int hub_configure(struct usb_hub *hub,
 	if (hub->has_indicators && blinkenlights)
 		hub->indicator [0] = INDICATOR_CYCLE;
 
+	usb_acpi_bind_hub_ports(hdev);
 	hub_activate(hub, HUB_INIT);
 	return 0;
 
@@ -4247,3 +4249,21 @@ struct usb_device *usb_get_hub_child_device(struct usb_device *hdev,
 }
 EXPORT_SYMBOL_GPL(usb_get_hub_child_device);
 
+void usb_set_hub_port_platform_data(struct usb_device *hdev, int port1,
+	unsigned long data)
+{
+	struct usb_hub *hub = hdev_to_hub(hdev);
+
+	if (!hub || port1 > hdev->maxchild || port1 < 1)
+		return;
+	hub->port_data[port1 - 1].platform_data = data;
+}
+
+unsigned long usb_get_hub_port_platform_data(struct usb_device *hdev, int port1)
+{
+	struct usb_hub *hub = hdev_to_hub(hdev);
+
+	if (!hub || port1 > hdev->maxchild || port1 < 1)
+		return 0;
+	return hub->port_data[port1 - 1].platform_data;
+}
drivers/usb/core/usb-acpi.c +36 -1
index 8947b20..004f3d7 100644
@@ -83,7 +83,16 @@ static int usb_acpi_find_device(struct device *dev, acpi_handle *handle)
 	if (!parent_handle)
 		return -ENODEV;
 
-	*handle = acpi_get_child(parent_handle, udev->portnum);
+	/**
+	 * The root hub's acpi handle is got from acpi method.
+	 * Other device's acpi handle can be got from the usb hub
+	 * port's platform_data.
+	 */
+	if (!udev->parent)
+		*handle = acpi_get_child(parent_handle, udev->portnum);
+	else
+		*handle = (acpi_handle)usb_get_hub_port_platform_data(
+				udev->parent, udev->portnum);
 
 	if (!*handle)
 		return -ENODEV;
@@ -106,6 +115,32 @@ static struct acpi_bus_type usb_acpi_bus = {
 	.find_device = usb_acpi_find_device,
 };
 
+int usb_acpi_bind_hub_ports(struct usb_device *hdev)
+{
+	acpi_handle hub_handle = NULL;
+	acpi_handle port_handle = NULL;
+	struct device *dev = &hdev->dev;
+	int i;
+
+	hub_handle = DEVICE_ACPI_HANDLE(dev);
+	if (!hub_handle)
+		return -ENODEV;
+
+	/**
+	 * The usb hub port is not a device in the usb subsystem but it is a device
+	 * in the acpi table. Store its acpi handle in the platform data of usb
+	 * hub port.
+	 */
+	for (i = 1; i <= hdev->maxchild; i++) {
+		port_handle = acpi_get_child(hub_handle, i);
+		if (!port_handle)
+			continue;
+		usb_set_hub_port_platform_data(hdev, i,
+			(unsigned long)port_handle);
+	}
+	return 0;
+}
+
 int usb_acpi_register(void)
 {
 	return register_acpi_bus_type(&usb_acpi_bus);
drivers/usb/core/usb.h +6 -0
index 5c5c538..d69d5f6 100644
@@ -155,11 +155,17 @@ extern void usb_notify_add_device(struct usb_device *udev);
 extern void usb_notify_remove_device(struct usb_device *udev);
 extern void usb_notify_add_bus(struct usb_bus *ubus);
 extern void usb_notify_remove_bus(struct usb_bus *ubus);
+extern unsigned long usb_get_hub_port_platform_data(struct usb_device *hdev,
+	int port1);
+extern void usb_set_hub_port_platform_data(struct usb_device *hdev,
+	int port1, unsigned long data);
 
 #ifdef CONFIG_ACPI
 extern int usb_acpi_register(void);
 extern void usb_acpi_unregister(void);
+extern int usb_acpi_bind_hub_ports(struct usb_device *hdev);
 #else
 static inline int usb_acpi_register(void) { return 0; };
 static inline void usb_acpi_unregister(void) { };
+static inline int usb_acpi_bind_hub_ports(struct usb_device *dev) { return 0; };
 #endif
Signature · 1 line
1.7.6.rc2.8.g28eb

A message that is not in the archive (sent off-list or not yet received): 1336723712-7686-8-git-send-email-tianyu.lan-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org

#14 lore raw

Re: [Resend PATCH V3 7/8] usb/acpi: add the support of usb hub ports' acpi binding without attached devices.

Quoted 8 lines · Lan Tianyu

The usb port is a device in the acpi table but it's not in the linux usb subsystem. USB hub port doesn't have struct device. So the acpi glue framework only can cover the usb port connected with usb device and store the acpi handle to struct device.archdata.acpi_handle. This patch adds the member platform_data in the struct usb_hub_port and gets the hub port's acpi_handle and store it in the port's platform_data to resolve no attached device no binding problem. The acpi method "_UPC" and "_PLD" can be accessed without attached device.

No, that's a hack. Please do this correctly and use the real structures here, not an unsigned long.

Why not make the hub a real struct device? That would solve this problem, right?

drivers/usb/core/hub.c line 43

Quoted 4 lines

struct usb_hub_port {

drivers/usb/core/hub.c +1 -0
 	void			*port_owner;
 	struct usb_device	*child;
+	unsigned long		platform_data;

Yeah, no, that's not ok, sorry. We use real pointers because we can, don't use opaque types here, where you are really putting a pointer in here. Be specific.

I'm not going to accept this patch, sorry. Please rework it, and I'm guessing, the one after this.

I'll go test the other patches in this series now...

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#15 lore raw

Re: [Resend PATCH V3 7/8] usb/acpi: add the support of usb hub ports' acpi binding without attached devices.

Quoted 9 lines · Greg KH
Quoted 8 lines · Lan Tianyu

The usb port is a device in the acpi table but it's not in the linux usb subsystem. USB hub port doesn't have struct device. So the acpi glue framework only can cover the usb port connected with usb device and store the acpi handle to struct device.archdata.acpi_handle. This patch adds the member platform_data in the struct usb_hub_port and gets the hub port's acpi_handle and store it in the port's platform_data to resolve no attached device no binding problem. The acpi method "_UPC" and "_PLD" can be accessed without attached device.

Quoted 5 lines

No, that's a hack. Please do this correctly and use the real structures here, not an unsigned long.

Why not make the hub a real struct device? That would solve this problem, right?

You mean make the hub ports a real struct device. Yeah. But that may be a little complex. The device tree and sys fs hierarchy will be changed.

drivers/usb/core/hub.c line 43

Quoted 4 lines
  struct usb_hub_port {
  	void			*port_owner;
  	struct usb_device	*child;
drivers/usb/core/hub.c +1 -0
+	unsigned long		platform_data;

How about this?

struct usb_hub_port {
void *port_owner;
struct usb_device *child;
+ #ifdef CONFIG_ACPI
+ acpi_handle port_acpi_handle;
+ #endif

Quoted 6 lines

Yeah, no, that's not ok, sorry. We use real pointers because we can, don't use opaque types here, where you are really putting a pointer in here. Be specific.

I'm not going to accept this patch, sorry. Please rework it, and I'm guessing, the one after this.

All right.

Quoted 1 line

I'll go test the other patches in this series now...

Great thanks for your patience to me(a freshman). :)

Quoted 1 line

greg k-h

Signature · 3 lines
Best Regards
Tianyu Lan
linux kernel enabling team
maintainer
#16 lore raw

Re: [Resend PATCH V3 7/8] usb/acpi: add the support of usb hub ports' acpi binding without attached devices.

Quoted 10 lines · Lan Tianyu
Quoted 9 lines · Greg KH
Quoted 8 lines · Lan Tianyu

The usb port is a device in the acpi table but it's not in the linux usb subsystem. USB hub port doesn't have struct device. So the acpi glue framework only can cover the usb port connected with usb device and store the acpi handle to struct device.archdata.acpi_handle. This patch adds the member platform_data in the struct usb_hub_port and gets the hub port's acpi_handle and store it in the port's platform_data to resolve no attached device no binding problem. The acpi method "_UPC" and "_PLD" can be accessed without attached device.

Quoted 7 lines
Quoted 5 lines

No, that's a hack. Please do this correctly and use the real structures here, not an unsigned long.

Why not make the hub a real struct device? That would solve this problem, right?

You mean make the hub ports a real struct device. Yeah. But that may be a little complex. The device tree and sys fs hierarchy will be changed.

heiarchy's can always be changed, nothing should rely on a specific location in a tree as things can move around, right? But be careful about udev, it might have some "what is the parent" rules about usb devices that think that usb devices are always in a tree.

Actually, a USB hub is a device, why not just put the port information on them, as sub devices. You don't have to hang the children USB devices off of those port devices, unless you test to find that everything works properly. That would not change any hiearchy in sysfs at all, right?

Review

Quoted 12 lines

drivers/usb/core/hub.c line 43

Quoted 4 lines

struct usb_hub_port {

drivers/usb/core/hub.c +1 -0
 	void			*port_owner;
 	struct usb_device	*child;
+	unsigned long		platform_data;

How about this?

struct usb_hub_port {

(quoted diff) +3 -0
 	void			*port_owner;
 	struct usb_device	*child;
+	#ifdef CONFIG_ACPI
+	acpi_handle		port_acpi_handle;
+	#endif

Ok, that's better, don't you agree? It shows exactly what you are trying to do here, and should ensure type safety.

greg k-h

maintainer
#17 lore raw
In reply to Lan Tianyu
Quoted 5 lines · Lan Tianyu

This patchset's purppose is to bind usb device with associated acpi node. The ACPI method "_PLD" and "_UPC" can be used to identify usb port's connect type(hot-plug, hard-wired and not-used). The patchset also can work on the port without device connected.

I've applied the first 6 of these patches, see the review comment on the 7th one for why I stopped there.

thanks,

greg k-h