diff options
author | Alan Stern <stern@rowland.harvard.edu> | 2007-05-30 15:35:16 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2007-07-12 19:34:29 -0400 |
commit | 624d6c0732d2c4ac00945ad79dbb6ff39ba90ee3 (patch) | |
tree | 411f9288fcc640a1ae935144e950ad44765157ba | |
parent | 686314cfbdac21c9019c0e04487b5d940db62406 (diff) |
USB: remove excess code from hub.c
This patch (as917) removes a now-unnecessary level of subroutine
nesting from hub.c. Since usb_port_suspend() does nothing but call
hub_port_suspend(), and usb_port_resume() does nothing but call
hub_port_resume(), there's no reason to keep the routines separate.
Also included in the patch are a few cosmetic changes involving
whitespace and use of braces.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r-- | drivers/usb/core/hub.c | 175 |
1 files changed, 71 insertions, 104 deletions
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index ac1ef1527dd2..ca3dbf84e800 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c | |||
@@ -1625,6 +1625,19 @@ static int hub_port_reset(struct usb_hub *hub, int port1, | |||
1625 | #ifdef CONFIG_USB_SUSPEND | 1625 | #ifdef CONFIG_USB_SUSPEND |
1626 | 1626 | ||
1627 | /* | 1627 | /* |
1628 | * usb_port_suspend - suspend a usb device's upstream port | ||
1629 | * @udev: device that's no longer in active use, not a root hub | ||
1630 | * Context: must be able to sleep; device not locked; pm locks held | ||
1631 | * | ||
1632 | * Suspends a USB device that isn't in active use, conserving power. | ||
1633 | * Devices may wake out of a suspend, if anything important happens, | ||
1634 | * using the remote wakeup mechanism. They may also be taken out of | ||
1635 | * suspend by the host, using usb_port_resume(). It's also routine | ||
1636 | * to disconnect devices while they are suspended. | ||
1637 | * | ||
1638 | * This only affects the USB hardware for a device; its interfaces | ||
1639 | * (and, for hubs, child devices) must already have been suspended. | ||
1640 | * | ||
1628 | * Selective port suspend reduces power; most suspended devices draw | 1641 | * Selective port suspend reduces power; most suspended devices draw |
1629 | * less than 500 uA. It's also used in OTG, along with remote wakeup. | 1642 | * less than 500 uA. It's also used in OTG, along with remote wakeup. |
1630 | * All devices below the suspended port are also suspended. | 1643 | * All devices below the suspended port are also suspended. |
@@ -1633,11 +1646,35 @@ static int hub_port_reset(struct usb_hub *hub, int port1, | |||
1633 | * also support "remote wakeup", where the device can activate the USB | 1646 | * also support "remote wakeup", where the device can activate the USB |
1634 | * tree above them to deliver data, such as a keypress or packet. In | 1647 | * tree above them to deliver data, such as a keypress or packet. In |
1635 | * some cases, this wakes the USB host. | 1648 | * some cases, this wakes the USB host. |
1649 | * | ||
1650 | * Suspending OTG devices may trigger HNP, if that's been enabled | ||
1651 | * between a pair of dual-role devices. That will change roles, such | ||
1652 | * as from A-Host to A-Peripheral or from B-Host back to B-Peripheral. | ||
1653 | * | ||
1654 | * Devices on USB hub ports have only one "suspend" state, corresponding | ||
1655 | * to ACPI D2, "may cause the device to lose some context". | ||
1656 | * State transitions include: | ||
1657 | * | ||
1658 | * - suspend, resume ... when the VBUS power link stays live | ||
1659 | * - suspend, disconnect ... VBUS lost | ||
1660 | * | ||
1661 | * Once VBUS drop breaks the circuit, the port it's using has to go through | ||
1662 | * normal re-enumeration procedures, starting with enabling VBUS power. | ||
1663 | * Other than re-initializing the hub (plug/unplug, except for root hubs), | ||
1664 | * Linux (2.6) currently has NO mechanisms to initiate that: no khubd | ||
1665 | * timer, no SRP, no requests through sysfs. | ||
1666 | * | ||
1667 | * If CONFIG_USB_SUSPEND isn't enabled, devices only really suspend when | ||
1668 | * the root hub for their bus goes into global suspend ... so we don't | ||
1669 | * (falsely) update the device power state to say it suspended. | ||
1670 | * | ||
1671 | * Returns 0 on success, else negative errno. | ||
1636 | */ | 1672 | */ |
1637 | static int hub_port_suspend(struct usb_hub *hub, int port1, | 1673 | int usb_port_suspend(struct usb_device *udev) |
1638 | struct usb_device *udev) | ||
1639 | { | 1674 | { |
1640 | int status; | 1675 | struct usb_hub *hub = hdev_to_hub(udev->parent); |
1676 | int port1 = udev->portnum; | ||
1677 | int status; | ||
1641 | 1678 | ||
1642 | // dev_dbg(hub->intfdev, "suspend port %d\n", port1); | 1679 | // dev_dbg(hub->intfdev, "suspend port %d\n", port1); |
1643 | 1680 | ||
@@ -1654,17 +1691,15 @@ static int hub_port_suspend(struct usb_hub *hub, int port1, | |||
1654 | NULL, 0, | 1691 | NULL, 0, |
1655 | USB_CTRL_SET_TIMEOUT); | 1692 | USB_CTRL_SET_TIMEOUT); |
1656 | if (status) | 1693 | if (status) |
1657 | dev_dbg(&udev->dev, | 1694 | dev_dbg(&udev->dev, "won't remote wakeup, status %d\n", |
1658 | "won't remote wakeup, status %d\n", | 1695 | status); |
1659 | status); | ||
1660 | } | 1696 | } |
1661 | 1697 | ||
1662 | /* see 7.1.7.6 */ | 1698 | /* see 7.1.7.6 */ |
1663 | status = set_port_feature(hub->hdev, port1, USB_PORT_FEAT_SUSPEND); | 1699 | status = set_port_feature(hub->hdev, port1, USB_PORT_FEAT_SUSPEND); |
1664 | if (status) { | 1700 | if (status) { |
1665 | dev_dbg(hub->intfdev, | 1701 | dev_dbg(hub->intfdev, "can't suspend port %d, status %d\n", |
1666 | "can't suspend port %d, status %d\n", | 1702 | port1, status); |
1667 | port1, status); | ||
1668 | /* paranoia: "should not happen" */ | 1703 | /* paranoia: "should not happen" */ |
1669 | (void) usb_control_msg(udev, usb_sndctrlpipe(udev, 0), | 1704 | (void) usb_control_msg(udev, usb_sndctrlpipe(udev, 0), |
1670 | USB_REQ_CLEAR_FEATURE, USB_RECIP_DEVICE, | 1705 | USB_REQ_CLEAR_FEATURE, USB_RECIP_DEVICE, |
@@ -1682,52 +1717,6 @@ static int hub_port_suspend(struct usb_hub *hub, int port1, | |||
1682 | } | 1717 | } |
1683 | 1718 | ||
1684 | /* | 1719 | /* |
1685 | * usb_port_suspend - suspend a usb device's upstream port | ||
1686 | * @udev: device that's no longer in active use | ||
1687 | * Context: must be able to sleep; device not locked; pm locks held | ||
1688 | * | ||
1689 | * Suspends a USB device that isn't in active use, conserving power. | ||
1690 | * Devices may wake out of a suspend, if anything important happens, | ||
1691 | * using the remote wakeup mechanism. They may also be taken out of | ||
1692 | * suspend by the host, using usb_port_resume(). It's also routine | ||
1693 | * to disconnect devices while they are suspended. | ||
1694 | * | ||
1695 | * This only affects the USB hardware for a device; its interfaces | ||
1696 | * (and, for hubs, child devices) must already have been suspended. | ||
1697 | * | ||
1698 | * Suspending OTG devices may trigger HNP, if that's been enabled | ||
1699 | * between a pair of dual-role devices. That will change roles, such | ||
1700 | * as from A-Host to A-Peripheral or from B-Host back to B-Peripheral. | ||
1701 | * | ||
1702 | * Devices on USB hub ports have only one "suspend" state, corresponding | ||
1703 | * to ACPI D2, "may cause the device to lose some context". | ||
1704 | * State transitions include: | ||
1705 | * | ||
1706 | * - suspend, resume ... when the VBUS power link stays live | ||
1707 | * - suspend, disconnect ... VBUS lost | ||
1708 | * | ||
1709 | * Once VBUS drop breaks the circuit, the port it's using has to go through | ||
1710 | * normal re-enumeration procedures, starting with enabling VBUS power. | ||
1711 | * Other than re-initializing the hub (plug/unplug, except for root hubs), | ||
1712 | * Linux (2.6) currently has NO mechanisms to initiate that: no khubd | ||
1713 | * timer, no SRP, no requests through sysfs. | ||
1714 | * | ||
1715 | * If CONFIG_USB_SUSPEND isn't enabled, devices only really suspend when | ||
1716 | * the root hub for their bus goes into global suspend ... so we don't | ||
1717 | * (falsely) update the device power state to say it suspended. | ||
1718 | * | ||
1719 | * Returns 0 on success, else negative errno. | ||
1720 | */ | ||
1721 | int usb_port_suspend(struct usb_device *udev) | ||
1722 | { | ||
1723 | int status = 0; | ||
1724 | |||
1725 | status = hub_port_suspend(hdev_to_hub(udev->parent), | ||
1726 | udev->portnum, udev); | ||
1727 | return status; | ||
1728 | } | ||
1729 | |||
1730 | /* | ||
1731 | * If the USB "suspend" state is in use (rather than "global suspend"), | 1720 | * If the USB "suspend" state is in use (rather than "global suspend"), |
1732 | * many devices will be individually taken out of suspend state using | 1721 | * many devices will be individually taken out of suspend state using |
1733 | * special" resume" signaling. These routines kick in shortly after | 1722 | * special" resume" signaling. These routines kick in shortly after |
@@ -1760,11 +1749,10 @@ static int finish_port_resume(struct usb_device *udev) | |||
1760 | if (status >= 0) | 1749 | if (status >= 0) |
1761 | status = (status == 2 ? 0 : -ENODEV); | 1750 | status = (status == 2 ? 0 : -ENODEV); |
1762 | 1751 | ||
1763 | if (status) | 1752 | if (status) { |
1764 | dev_dbg(&udev->dev, | 1753 | dev_dbg(&udev->dev, "gone after usb resume? status %d\n", |
1765 | "gone after usb resume? status %d\n", | 1754 | status); |
1766 | status); | 1755 | } else if (udev->actconfig) { |
1767 | else if (udev->actconfig) { | ||
1768 | le16_to_cpus(&devstatus); | 1756 | le16_to_cpus(&devstatus); |
1769 | if (devstatus & (1 << USB_DEVICE_REMOTE_WAKEUP)) { | 1757 | if (devstatus & (1 << USB_DEVICE_REMOTE_WAKEUP)) { |
1770 | status = usb_control_msg(udev, | 1758 | status = usb_control_msg(udev, |
@@ -1783,11 +1771,25 @@ static int finish_port_resume(struct usb_device *udev) | |||
1783 | return status; | 1771 | return status; |
1784 | } | 1772 | } |
1785 | 1773 | ||
1786 | static int | 1774 | /* |
1787 | hub_port_resume(struct usb_hub *hub, int port1, struct usb_device *udev) | 1775 | * usb_port_resume - re-activate a suspended usb device's upstream port |
1776 | * @udev: device to re-activate, not a root hub | ||
1777 | * Context: must be able to sleep; device not locked; pm locks held | ||
1778 | * | ||
1779 | * This will re-activate the suspended device, increasing power usage | ||
1780 | * while letting drivers communicate again with its endpoints. | ||
1781 | * USB resume explicitly guarantees that the power session between | ||
1782 | * the host and the device is the same as it was when the device | ||
1783 | * suspended. | ||
1784 | * | ||
1785 | * Returns 0 on success, else negative errno. | ||
1786 | */ | ||
1787 | int usb_port_resume(struct usb_device *udev) | ||
1788 | { | 1788 | { |
1789 | int status; | 1789 | struct usb_hub *hub = hdev_to_hub(udev->parent); |
1790 | u16 portchange, portstatus; | 1790 | int port1 = udev->portnum; |
1791 | int status; | ||
1792 | u16 portchange, portstatus; | ||
1791 | 1793 | ||
1792 | /* Skip the initial Clear-Suspend step for a remote wakeup */ | 1794 | /* Skip the initial Clear-Suspend step for a remote wakeup */ |
1793 | status = hub_port_status(hub, port1, &portstatus, &portchange); | 1795 | status = hub_port_status(hub, port1, &portstatus, &portchange); |
@@ -1802,9 +1804,8 @@ hub_port_resume(struct usb_hub *hub, int port1, struct usb_device *udev) | |||
1802 | status = clear_port_feature(hub->hdev, | 1804 | status = clear_port_feature(hub->hdev, |
1803 | port1, USB_PORT_FEAT_SUSPEND); | 1805 | port1, USB_PORT_FEAT_SUSPEND); |
1804 | if (status) { | 1806 | if (status) { |
1805 | dev_dbg(hub->intfdev, | 1807 | dev_dbg(hub->intfdev, "can't resume port %d, status %d\n", |
1806 | "can't resume port %d, status %d\n", | 1808 | port1, status); |
1807 | port1, status); | ||
1808 | } else { | 1809 | } else { |
1809 | /* drive resume for at least 20 msec */ | 1810 | /* drive resume for at least 20 msec */ |
1810 | dev_dbg(&udev->dev, "usb %sresume\n", | 1811 | dev_dbg(&udev->dev, "usb %sresume\n", |
@@ -1839,8 +1840,10 @@ SuspendCleared: | |||
1839 | status = finish_port_resume(udev); | 1840 | status = finish_port_resume(udev); |
1840 | } | 1841 | } |
1841 | } | 1842 | } |
1842 | if (status < 0) | 1843 | if (status < 0) { |
1844 | dev_dbg(&udev->dev, "can't resume, status %d\n", status); | ||
1843 | hub_port_logical_disconnect(hub, port1); | 1845 | hub_port_logical_disconnect(hub, port1); |
1846 | } | ||
1844 | 1847 | ||
1845 | clear_bit(port1, hub->busy_bits); | 1848 | clear_bit(port1, hub->busy_bits); |
1846 | if (!hub->hdev->parent && !hub->busy_bits[0]) | 1849 | if (!hub->hdev->parent && !hub->busy_bits[0]) |
@@ -1849,30 +1852,6 @@ SuspendCleared: | |||
1849 | return status; | 1852 | return status; |
1850 | } | 1853 | } |
1851 | 1854 | ||
1852 | /* | ||
1853 | * usb_port_resume - re-activate a suspended usb device's upstream port | ||
1854 | * @udev: device to re-activate | ||
1855 | * Context: must be able to sleep; device not locked; pm locks held | ||
1856 | * | ||
1857 | * This will re-activate the suspended device, increasing power usage | ||
1858 | * while letting drivers communicate again with its endpoints. | ||
1859 | * USB resume explicitly guarantees that the power session between | ||
1860 | * the host and the device is the same as it was when the device | ||
1861 | * suspended. | ||
1862 | * | ||
1863 | * Returns 0 on success, else negative errno. | ||
1864 | */ | ||
1865 | int usb_port_resume(struct usb_device *udev) | ||
1866 | { | ||
1867 | int status; | ||
1868 | |||
1869 | status = hub_port_resume(hdev_to_hub(udev->parent), | ||
1870 | udev->portnum, udev); | ||
1871 | if (status < 0) | ||
1872 | dev_dbg(&udev->dev, "can't resume, status %d\n", status); | ||
1873 | return status; | ||
1874 | } | ||
1875 | |||
1876 | static int remote_wakeup(struct usb_device *udev) | 1855 | static int remote_wakeup(struct usb_device *udev) |
1877 | { | 1856 | { |
1878 | int status = 0; | 1857 | int status = 0; |
@@ -1896,18 +1875,6 @@ int usb_port_suspend(struct usb_device *udev) | |||
1896 | return 0; | 1875 | return 0; |
1897 | } | 1876 | } |
1898 | 1877 | ||
1899 | static inline int | ||
1900 | finish_port_resume(struct usb_device *udev) | ||
1901 | { | ||
1902 | return 0; | ||
1903 | } | ||
1904 | |||
1905 | static inline int | ||
1906 | hub_port_resume(struct usb_hub *hub, int port1, struct usb_device *udev) | ||
1907 | { | ||
1908 | return 0; | ||
1909 | } | ||
1910 | |||
1911 | int usb_port_resume(struct usb_device *udev) | 1878 | int usb_port_resume(struct usb_device *udev) |
1912 | { | 1879 | { |
1913 | return 0; | 1880 | return 0; |