Commit d99f6b41 authored by Dan Williams's avatar Dan Williams Committed by Greg Kroah-Hartman

usb: rename usb_port device objects

The current port name "portX" is ambiguous.  Before adding more port
messages rename ports to "<hub-device-name>-portX"

This is an ABI change, but the suspicion is that it will go unnoticed as
the port power control implementation has been broken since its
introduction.  If however, someone was relying on the old name we can
add sysfs links from the old name to the new name.

Additionally, it unifies/simplifies port dev_printk messages and modifies
instances of:
	dev_XXX(hub->intfdev, ..."port %d"...
	dev_XXX(&hdev->dev, ..."port%d"...
into:
	dev_XXX(&port_dev->dev, ...

Now that the names are unique usb_port devices it would be nice if they
could be included in /sys/bus/usb.  However, it turns out that this
breaks 'lsusb -t'.  For now, create a dummy port driver so that print
messages are prefixed "usb 1-1-port3" rather than the
subsystem-ambiguous " 1-1-port3".

Finally, it corrects an odd usage of sscanf("port%d") in usb-acpi.c.
Suggested-by: default avatarAlan Stern <stern@rowland.harvard.edu>
Acked-by: default avatarAlan Stern <stern@rowland.harvard.edu>
Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 9262c19d
This diff is collapsed.
......@@ -152,6 +152,11 @@ struct device_type usb_port_device_type = {
.pm = &usb_port_pm_ops,
};
static struct device_driver usb_port_driver = {
.name = "usb",
.owner = THIS_MODULE,
};
int usb_hub_create_port_device(struct usb_hub *hub, int port1)
{
struct usb_port *port_dev = NULL;
......@@ -169,8 +174,9 @@ int usb_hub_create_port_device(struct usb_hub *hub, int port1)
port_dev->dev.parent = hub->intfdev;
port_dev->dev.groups = port_dev_group;
port_dev->dev.type = &usb_port_device_type;
dev_set_name(&port_dev->dev, "port%d", port1);
port_dev->dev.driver = &usb_port_driver;
dev_set_name(&port_dev->dev, "%s-port%d", dev_name(&hub->hdev->dev),
port1);
retval = device_register(&port_dev->dev);
if (retval)
goto error_register;
......
......@@ -17,7 +17,7 @@
#include <linux/pci.h>
#include <linux/usb/hcd.h>
#include "usb.h"
#include "hub.h"
/**
* usb_acpi_power_manageable - check whether usb port has
......@@ -55,13 +55,18 @@ EXPORT_SYMBOL_GPL(usb_acpi_power_manageable);
*/
int usb_acpi_set_power_state(struct usb_device *hdev, int index, bool enable)
{
struct usb_hub *hub = usb_hub_to_struct_hub(hdev);
struct usb_port *port_dev;
acpi_handle port_handle;
unsigned char state;
int port1 = index + 1;
int error = -EINVAL;
port_handle = (acpi_handle)usb_get_hub_port_acpi_handle(hdev,
port1);
if (!hub)
return -ENODEV;
port_dev = hub->ports[port1 - 1];
port_handle = (acpi_handle) usb_get_hub_port_acpi_handle(hdev, port1);
if (!port_handle)
return error;
......@@ -72,10 +77,9 @@ int usb_acpi_set_power_state(struct usb_device *hdev, int index, bool enable)
error = acpi_bus_set_power(port_handle, state);
if (!error)
dev_dbg(&hdev->dev, "The power of hub port %d was set to %d\n",
port1, enable);
dev_dbg(&port_dev->dev, "acpi: power was set to %d\n", enable);
else
dev_dbg(&hdev->dev, "The power of hub port failed to be set\n");
dev_dbg(&port_dev->dev, "acpi: power failed to be set\n");
return error;
}
......@@ -84,12 +88,17 @@ EXPORT_SYMBOL_GPL(usb_acpi_set_power_state);
static int usb_acpi_check_port_connect_type(struct usb_device *hdev,
acpi_handle handle, int port1)
{
acpi_status status;
enum usb_port_connect_type connect_type = USB_PORT_CONNECT_TYPE_UNKNOWN;
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
union acpi_object *upc;
struct usb_hub *hub = usb_hub_to_struct_hub(hdev);
struct acpi_pld_info *pld;
union acpi_object *upc;
acpi_status status;
int ret = 0;
if (!hub)
return 0;
/*
* According to ACPI Spec 9.13. PLD indicates whether usb port is
* user visible and _UPC indicates whether it is connectable. If
......@@ -112,13 +121,12 @@ static int usb_acpi_check_port_connect_type(struct usb_device *hdev,
if (upc->package.elements[0].integer.value)
if (pld->user_visible)
usb_set_hub_port_connect_type(hdev, port1,
USB_PORT_CONNECT_TYPE_HOT_PLUG);
connect_type = USB_PORT_CONNECT_TYPE_HOT_PLUG;
else
usb_set_hub_port_connect_type(hdev, port1,
USB_PORT_CONNECT_TYPE_HARD_WIRED);
connect_type = USB_PORT_CONNECT_TYPE_HARD_WIRED;
else if (!pld->user_visible)
usb_set_hub_port_connect_type(hdev, port1, USB_PORT_NOT_USED);
connect_type = USB_PORT_NOT_USED;
hub->ports[port1 - 1]->connect_type = connect_type;
out:
ACPI_FREE(pld);
......@@ -128,9 +136,9 @@ static int usb_acpi_check_port_connect_type(struct usb_device *hdev,
static struct acpi_device *usb_acpi_find_companion(struct device *dev)
{
int port1;
struct usb_device *udev;
acpi_handle *parent_handle;
int port_num;
/*
* In the ACPI DSDT table, only usb root hub and usb ports are
......@@ -147,16 +155,16 @@ static struct acpi_device *usb_acpi_find_companion(struct device *dev)
*/
if (is_usb_device(dev)) {
udev = to_usb_device(dev);
port1 = udev->portnum;
if (udev->parent) {
enum usb_port_connect_type type;
struct usb_hub *hub;
hub = usb_hub_to_struct_hub(udev->parent);
/*
* 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) {
switch (hub->ports[port1 - 1]->connect_type) {
case USB_PORT_CONNECT_TYPE_HOT_PLUG:
udev->removable = USB_DEVICE_REMOVABLE;
break;
......@@ -173,13 +181,14 @@ static struct acpi_device *usb_acpi_find_companion(struct device *dev)
/* root hub's parent is the usb hcd. */
return acpi_find_child_device(ACPI_COMPANION(dev->parent),
udev->portnum, false);
port1, false);
} else if (is_usb_port(dev)) {
struct usb_port *port_dev = to_usb_port(dev);
struct acpi_device *adev = NULL;
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);
port1 = port_dev->portnum;
/*
* The root hub ports' parent is the root hub. The non-root-hub
......@@ -188,12 +197,11 @@ static struct acpi_device *usb_acpi_find_companion(struct device *dev)
*/
if (!udev->parent) {
struct usb_hcd *hcd = bus_to_hcd(udev->bus);
int raw_port_num;
int raw;
raw_port_num = usb_hcd_find_raw_port_number(hcd,
port_num);
raw = usb_hcd_find_raw_port_number(hcd, port1);
adev = acpi_find_child_device(ACPI_COMPANION(&udev->dev),
raw_port_num, false);
raw, false);
if (!adev)
return NULL;
} else {
......@@ -204,11 +212,11 @@ static struct acpi_device *usb_acpi_find_companion(struct device *dev)
return NULL;
acpi_bus_get_device(parent_handle, &adev);
adev = acpi_find_child_device(adev, port_num, false);
adev = acpi_find_child_device(adev, port1, false);
if (!adev)
return NULL;
}
usb_acpi_check_port_connect_type(udev, adev->handle, port_num);
usb_acpi_check_port_connect_type(udev, adev->handle, port1);
return adev;
}
......
......@@ -175,10 +175,6 @@ 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 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);
extern void usb_hub_adjust_deviceremovable(struct usb_device *hdev,
struct usb_hub_descriptor *desc);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment