From: Lan Tianyu <tianyu.lan-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
To: lenb-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org
Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-acpi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
stern-nwvwT67g6+6dFdvTe/nMLpVzexx5G7lz@public.gmane.org,
sarah.a.sharp-VuQAYsv1563Yd54FQh9/CA@public.gmane.org,
mjg59-1xO5oi07KQx4cg9Nei1l7Q@public.gmane.org,
mfm-Oo0r1OC9pj9iLUuM0BA3LQ@public.gmane.org,
Lan Tianyu <tianyu.lan-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Subject: [Resend PATCH V3 8/8] usb/acpi: add usb check for the connect type of usb port
Date: Fri, 11 May 2012 16:08:32 +0800 [thread overview]
Message-ID: <1336723712-7686-9-git-send-email-tianyu.lan@intel.com> (raw)
In-Reply-To: <1336723712-7686-1-git-send-email-tianyu.lan-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
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.
Signed-off-by: Lan Tianyu <tianyu.lan-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
---
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(-)
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 338f01b..9632bc3 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -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;
+}
diff --git a/drivers/usb/core/usb-acpi.c b/drivers/usb/core/usb-acpi.c
index 004f3d7..07182bb 100644
--- a/drivers/usb/core/usb-acpi.c
+++ b/drivers/usb/core/usb-acpi.c
@@ -19,20 +19,32 @@
#include "usb.h"
-static int usb_acpi_check_upc(struct usb_device *udev, acpi_handle handle)
+static int usb_acpi_check_port_connect_type(struct usb_device *hdev,
+ acpi_handle handle, int port1)
{
acpi_status status;
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
union acpi_object *upc;
+ struct acpi_pld pld;
int ret = 0;
- status = acpi_evaluate_object(handle, "_UPC", NULL, &buffer);
+ /**
+ * 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.
+ */
+ status = acpi_get_physical_device_location(handle, &pld);
+ if (ACPI_FAILURE(status))
+ return -ENODEV;
+ 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;
@@ -40,38 +52,24 @@ static int usb_acpi_check_upc(struct usb_device *udev, acpi_handle handle)
}
if (upc->package.elements[0].integer.value)
- udev->removable = USB_DEVICE_REMOVABLE;
- else
- udev->removable = USB_DEVICE_FIXED;
+ usb_set_hub_port_connect_type(hdev, port1,
+ pld.user_visible ?
+ USB_PORT_CONNECT_TYPE_HOT_PLUG :
+ USB_PORT_CONNECT_TYPE_HARD_WIRED);
+ else if (!pld.user_visible)
+ usb_set_hub_port_connect_type(hdev, port1, USB_PORT_NOT_USED);
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;
struct device *parent;
acpi_handle *parent_handle;
+ enum usb_port_connect_type type;
if (!is_usb_device(dev))
return -ENODEV;
@@ -97,14 +95,18 @@ 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);
+ 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;
+ }
return 0;
}
@@ -137,6 +139,7 @@ int usb_acpi_bind_hub_ports(struct usb_device *hdev)
continue;
usb_set_hub_port_platform_data(hdev, i,
(unsigned long)port_handle);
+ usb_acpi_check_port_connect_type(hdev, port_handle, i);
}
return 0;
}
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h
index d69d5f6..26fcabc1 100644
--- a/drivers/usb/core/usb.h
+++ b/drivers/usb/core/usb.h
@@ -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);
diff --git a/include/linux/usb.h b/include/linux/usb.h
index 69163a0..2256b78 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -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
--
1.7.6.rc2.8.g28eb
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2012-05-11 8:08 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-11 8:08 [Resend PATCH V3 0/8] usb/acpi: Add binding usb device with acpi Lan Tianyu
[not found] ` <1336723712-7686-1-git-send-email-tianyu.lan-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2012-05-11 8:08 ` [Resend PATCH V3 1/8] ACPI: Add stubs for (un)register_acpi_bus_type Lan Tianyu
2012-05-11 8:08 ` [Resend PATCH V3 2/8] ACPI: Add _PLD support Lan Tianyu
2012-05-11 8:08 ` [Resend PATCH V3 6/8] usb: move struct usb_device->children to struct usb_hub_port->child Lan Tianyu
2012-05-12 0:10 ` Greg KH
[not found] ` <20120512001027.GA25600-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2012-05-12 15:31 ` Lan Tianyu
2012-05-11 8:08 ` Lan Tianyu [this message]
2012-05-11 8:08 ` [Resend PATCH V3 3/8] usb: Bind devices to ACPI devices when possible Lan Tianyu
2012-05-11 8:08 ` [Resend PATCH V3 4/8] usb: Set device removable state based on ACPI USB data Lan Tianyu
2012-05-11 8:08 ` [Resend PATCH V3 5/8] usb: add struct usb_hub_port to store port related members Lan Tianyu
2012-05-11 8:08 ` [Resend PATCH V3 7/8] usb/acpi: add the support of usb hub ports' acpi binding without attached devices Lan Tianyu
[not found] ` <1336723712-7686-8-git-send-email-tianyu.lan-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2012-05-12 0:15 ` Greg KH
2012-05-12 16:00 ` Lan Tianyu
2012-05-12 16:26 ` Greg KH
2012-05-12 0:26 ` [Resend PATCH V3 0/8] usb/acpi: Add binding usb device with acpi Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1336723712-7686-9-git-send-email-tianyu.lan@intel.com \
--to=tianyu.lan-ral2jqcrhueavxtiumwx3w@public.gmane.org \
--cc=gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org \
--cc=lenb-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=linux-acpi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mfm-Oo0r1OC9pj9iLUuM0BA3LQ@public.gmane.org \
--cc=mjg59-1xO5oi07KQx4cg9Nei1l7Q@public.gmane.org \
--cc=sarah.a.sharp-VuQAYsv1563Yd54FQh9/CA@public.gmane.org \
--cc=stern-nwvwT67g6+6dFdvTe/nMLpVzexx5G7lz@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).