diff options
Diffstat (limited to 'drivers/usb/core/hcd.c')
-rw-r--r-- | drivers/usb/core/hcd.c | 153 |
1 files changed, 85 insertions, 68 deletions
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index 0018bbc4de34..fbd938d4ea58 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c | |||
@@ -34,6 +34,7 @@ | |||
34 | #include <asm/scatterlist.h> | 34 | #include <asm/scatterlist.h> |
35 | #include <linux/device.h> | 35 | #include <linux/device.h> |
36 | #include <linux/dma-mapping.h> | 36 | #include <linux/dma-mapping.h> |
37 | #include <linux/mutex.h> | ||
37 | #include <asm/irq.h> | 38 | #include <asm/irq.h> |
38 | #include <asm/byteorder.h> | 39 | #include <asm/byteorder.h> |
39 | 40 | ||
@@ -93,7 +94,7 @@ struct usb_busmap { | |||
93 | static struct usb_busmap busmap; | 94 | static struct usb_busmap busmap; |
94 | 95 | ||
95 | /* used when updating list of hcds */ | 96 | /* used when updating list of hcds */ |
96 | DECLARE_MUTEX (usb_bus_list_lock); /* exported only for usbfs */ | 97 | DEFINE_MUTEX(usb_bus_list_lock); /* exported only for usbfs */ |
97 | EXPORT_SYMBOL_GPL (usb_bus_list_lock); | 98 | EXPORT_SYMBOL_GPL (usb_bus_list_lock); |
98 | 99 | ||
99 | /* used for controlling access to virtual root hubs */ | 100 | /* used for controlling access to virtual root hubs */ |
@@ -366,21 +367,39 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb) | |||
366 | 367 | ||
367 | /* DEVICE REQUESTS */ | 368 | /* DEVICE REQUESTS */ |
368 | 369 | ||
370 | /* The root hub's remote wakeup enable bit is implemented using | ||
371 | * driver model wakeup flags. If this system supports wakeup | ||
372 | * through USB, userspace may change the default "allow wakeup" | ||
373 | * policy through sysfs or these calls. | ||
374 | * | ||
375 | * Most root hubs support wakeup from downstream devices, for | ||
376 | * runtime power management (disabling USB clocks and reducing | ||
377 | * VBUS power usage). However, not all of them do so; silicon, | ||
378 | * board, and BIOS bugs here are not uncommon, so these can't | ||
379 | * be treated quite like external hubs. | ||
380 | * | ||
381 | * Likewise, not all root hubs will pass wakeup events upstream, | ||
382 | * to wake up the whole system. So don't assume root hub and | ||
383 | * controller capabilities are identical. | ||
384 | */ | ||
385 | |||
369 | case DeviceRequest | USB_REQ_GET_STATUS: | 386 | case DeviceRequest | USB_REQ_GET_STATUS: |
370 | tbuf [0] = (hcd->remote_wakeup << USB_DEVICE_REMOTE_WAKEUP) | 387 | tbuf [0] = (device_may_wakeup(&hcd->self.root_hub->dev) |
388 | << USB_DEVICE_REMOTE_WAKEUP) | ||
371 | | (1 << USB_DEVICE_SELF_POWERED); | 389 | | (1 << USB_DEVICE_SELF_POWERED); |
372 | tbuf [1] = 0; | 390 | tbuf [1] = 0; |
373 | len = 2; | 391 | len = 2; |
374 | break; | 392 | break; |
375 | case DeviceOutRequest | USB_REQ_CLEAR_FEATURE: | 393 | case DeviceOutRequest | USB_REQ_CLEAR_FEATURE: |
376 | if (wValue == USB_DEVICE_REMOTE_WAKEUP) | 394 | if (wValue == USB_DEVICE_REMOTE_WAKEUP) |
377 | hcd->remote_wakeup = 0; | 395 | device_set_wakeup_enable(&hcd->self.root_hub->dev, 0); |
378 | else | 396 | else |
379 | goto error; | 397 | goto error; |
380 | break; | 398 | break; |
381 | case DeviceOutRequest | USB_REQ_SET_FEATURE: | 399 | case DeviceOutRequest | USB_REQ_SET_FEATURE: |
382 | if (hcd->can_wakeup && wValue == USB_DEVICE_REMOTE_WAKEUP) | 400 | if (device_can_wakeup(&hcd->self.root_hub->dev) |
383 | hcd->remote_wakeup = 1; | 401 | && wValue == USB_DEVICE_REMOTE_WAKEUP) |
402 | device_set_wakeup_enable(&hcd->self.root_hub->dev, 1); | ||
384 | else | 403 | else |
385 | goto error; | 404 | goto error; |
386 | break; | 405 | break; |
@@ -409,7 +428,7 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb) | |||
409 | bufp = fs_rh_config_descriptor; | 428 | bufp = fs_rh_config_descriptor; |
410 | len = sizeof fs_rh_config_descriptor; | 429 | len = sizeof fs_rh_config_descriptor; |
411 | } | 430 | } |
412 | if (hcd->can_wakeup) | 431 | if (device_can_wakeup(&hcd->self.root_hub->dev)) |
413 | patch_wakeup = 1; | 432 | patch_wakeup = 1; |
414 | break; | 433 | break; |
415 | case USB_DT_STRING << 8: | 434 | case USB_DT_STRING << 8: |
@@ -761,14 +780,14 @@ static int usb_register_bus(struct usb_bus *bus) | |||
761 | { | 780 | { |
762 | int busnum; | 781 | int busnum; |
763 | 782 | ||
764 | down (&usb_bus_list_lock); | 783 | mutex_lock(&usb_bus_list_lock); |
765 | busnum = find_next_zero_bit (busmap.busmap, USB_MAXBUS, 1); | 784 | busnum = find_next_zero_bit (busmap.busmap, USB_MAXBUS, 1); |
766 | if (busnum < USB_MAXBUS) { | 785 | if (busnum < USB_MAXBUS) { |
767 | set_bit (busnum, busmap.busmap); | 786 | set_bit (busnum, busmap.busmap); |
768 | bus->busnum = busnum; | 787 | bus->busnum = busnum; |
769 | } else { | 788 | } else { |
770 | printk (KERN_ERR "%s: too many buses\n", usbcore_name); | 789 | printk (KERN_ERR "%s: too many buses\n", usbcore_name); |
771 | up(&usb_bus_list_lock); | 790 | mutex_unlock(&usb_bus_list_lock); |
772 | return -E2BIG; | 791 | return -E2BIG; |
773 | } | 792 | } |
774 | 793 | ||
@@ -776,7 +795,7 @@ static int usb_register_bus(struct usb_bus *bus) | |||
776 | bus->controller, "usb_host%d", busnum); | 795 | bus->controller, "usb_host%d", busnum); |
777 | if (IS_ERR(bus->class_dev)) { | 796 | if (IS_ERR(bus->class_dev)) { |
778 | clear_bit(busnum, busmap.busmap); | 797 | clear_bit(busnum, busmap.busmap); |
779 | up(&usb_bus_list_lock); | 798 | mutex_unlock(&usb_bus_list_lock); |
780 | return PTR_ERR(bus->class_dev); | 799 | return PTR_ERR(bus->class_dev); |
781 | } | 800 | } |
782 | 801 | ||
@@ -784,7 +803,7 @@ static int usb_register_bus(struct usb_bus *bus) | |||
784 | 803 | ||
785 | /* Add it to the local list of buses */ | 804 | /* Add it to the local list of buses */ |
786 | list_add (&bus->bus_list, &usb_bus_list); | 805 | list_add (&bus->bus_list, &usb_bus_list); |
787 | up (&usb_bus_list_lock); | 806 | mutex_unlock(&usb_bus_list_lock); |
788 | 807 | ||
789 | usb_notify_add_bus(bus); | 808 | usb_notify_add_bus(bus); |
790 | 809 | ||
@@ -809,9 +828,9 @@ static void usb_deregister_bus (struct usb_bus *bus) | |||
809 | * controller code, as well as having it call this when cleaning | 828 | * controller code, as well as having it call this when cleaning |
810 | * itself up | 829 | * itself up |
811 | */ | 830 | */ |
812 | down (&usb_bus_list_lock); | 831 | mutex_lock(&usb_bus_list_lock); |
813 | list_del (&bus->bus_list); | 832 | list_del (&bus->bus_list); |
814 | up (&usb_bus_list_lock); | 833 | mutex_unlock(&usb_bus_list_lock); |
815 | 834 | ||
816 | usb_notify_remove_bus(bus); | 835 | usb_notify_remove_bus(bus); |
817 | 836 | ||
@@ -822,18 +841,17 @@ static void usb_deregister_bus (struct usb_bus *bus) | |||
822 | 841 | ||
823 | /** | 842 | /** |
824 | * register_root_hub - called by usb_add_hcd() to register a root hub | 843 | * register_root_hub - called by usb_add_hcd() to register a root hub |
825 | * @usb_dev: the usb root hub device to be registered. | ||
826 | * @hcd: host controller for this root hub | 844 | * @hcd: host controller for this root hub |
827 | * | 845 | * |
828 | * This function registers the root hub with the USB subsystem. It sets up | 846 | * This function registers the root hub with the USB subsystem. It sets up |
829 | * the device properly in the device tree and stores the root_hub pointer | 847 | * the device properly in the device tree and then calls usb_new_device() |
830 | * in the bus structure, then calls usb_new_device() to register the usb | 848 | * to register the usb device. It also assigns the root hub's USB address |
831 | * device. It also assigns the root hub's USB address (always 1). | 849 | * (always 1). |
832 | */ | 850 | */ |
833 | static int register_root_hub (struct usb_device *usb_dev, | 851 | static int register_root_hub(struct usb_hcd *hcd) |
834 | struct usb_hcd *hcd) | ||
835 | { | 852 | { |
836 | struct device *parent_dev = hcd->self.controller; | 853 | struct device *parent_dev = hcd->self.controller; |
854 | struct usb_device *usb_dev = hcd->self.root_hub; | ||
837 | const int devnum = 1; | 855 | const int devnum = 1; |
838 | int retval; | 856 | int retval; |
839 | 857 | ||
@@ -844,14 +862,12 @@ static int register_root_hub (struct usb_device *usb_dev, | |||
844 | set_bit (devnum, usb_dev->bus->devmap.devicemap); | 862 | set_bit (devnum, usb_dev->bus->devmap.devicemap); |
845 | usb_set_device_state(usb_dev, USB_STATE_ADDRESS); | 863 | usb_set_device_state(usb_dev, USB_STATE_ADDRESS); |
846 | 864 | ||
847 | down (&usb_bus_list_lock); | 865 | mutex_lock(&usb_bus_list_lock); |
848 | usb_dev->bus->root_hub = usb_dev; | ||
849 | 866 | ||
850 | usb_dev->ep0.desc.wMaxPacketSize = __constant_cpu_to_le16(64); | 867 | usb_dev->ep0.desc.wMaxPacketSize = __constant_cpu_to_le16(64); |
851 | retval = usb_get_device_descriptor(usb_dev, USB_DT_DEVICE_SIZE); | 868 | retval = usb_get_device_descriptor(usb_dev, USB_DT_DEVICE_SIZE); |
852 | if (retval != sizeof usb_dev->descriptor) { | 869 | if (retval != sizeof usb_dev->descriptor) { |
853 | usb_dev->bus->root_hub = NULL; | 870 | mutex_unlock(&usb_bus_list_lock); |
854 | up (&usb_bus_list_lock); | ||
855 | dev_dbg (parent_dev, "can't read %s device descriptor %d\n", | 871 | dev_dbg (parent_dev, "can't read %s device descriptor %d\n", |
856 | usb_dev->dev.bus_id, retval); | 872 | usb_dev->dev.bus_id, retval); |
857 | return (retval < 0) ? retval : -EMSGSIZE; | 873 | return (retval < 0) ? retval : -EMSGSIZE; |
@@ -859,11 +875,10 @@ static int register_root_hub (struct usb_device *usb_dev, | |||
859 | 875 | ||
860 | retval = usb_new_device (usb_dev); | 876 | retval = usb_new_device (usb_dev); |
861 | if (retval) { | 877 | if (retval) { |
862 | usb_dev->bus->root_hub = NULL; | ||
863 | dev_err (parent_dev, "can't register root hub for %s, %d\n", | 878 | dev_err (parent_dev, "can't register root hub for %s, %d\n", |
864 | usb_dev->dev.bus_id, retval); | 879 | usb_dev->dev.bus_id, retval); |
865 | } | 880 | } |
866 | up (&usb_bus_list_lock); | 881 | mutex_unlock(&usb_bus_list_lock); |
867 | 882 | ||
868 | if (retval == 0) { | 883 | if (retval == 0) { |
869 | spin_lock_irq (&hcd_root_hub_lock); | 884 | spin_lock_irq (&hcd_root_hub_lock); |
@@ -1090,7 +1105,6 @@ static void urb_unlink (struct urb *urb) | |||
1090 | spin_lock_irqsave (&hcd_data_lock, flags); | 1105 | spin_lock_irqsave (&hcd_data_lock, flags); |
1091 | list_del_init (&urb->urb_list); | 1106 | list_del_init (&urb->urb_list); |
1092 | spin_unlock_irqrestore (&hcd_data_lock, flags); | 1107 | spin_unlock_irqrestore (&hcd_data_lock, flags); |
1093 | usb_put_dev (urb->dev); | ||
1094 | } | 1108 | } |
1095 | 1109 | ||
1096 | 1110 | ||
@@ -1130,7 +1144,6 @@ static int hcd_submit_urb (struct urb *urb, gfp_t mem_flags) | |||
1130 | case HC_STATE_RUNNING: | 1144 | case HC_STATE_RUNNING: |
1131 | case HC_STATE_RESUMING: | 1145 | case HC_STATE_RESUMING: |
1132 | doit: | 1146 | doit: |
1133 | usb_get_dev (urb->dev); | ||
1134 | list_add_tail (&urb->urb_list, &ep->urb_list); | 1147 | list_add_tail (&urb->urb_list, &ep->urb_list); |
1135 | status = 0; | 1148 | status = 0; |
1136 | break; | 1149 | break; |
@@ -1771,12 +1784,10 @@ int usb_add_hcd(struct usb_hcd *hcd, | |||
1771 | 1784 | ||
1772 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | 1785 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
1773 | 1786 | ||
1774 | /* till now HC has been in an indeterminate state ... */ | 1787 | /* HC is in reset state, but accessible. Now do the one-time init, |
1775 | if (hcd->driver->reset && (retval = hcd->driver->reset(hcd)) < 0) { | 1788 | * bottom up so that hcds can customize the root hubs before khubd |
1776 | dev_err(hcd->self.controller, "can't reset\n"); | 1789 | * starts talking to them. (Note, bus id is assigned early too.) |
1777 | return retval; | 1790 | */ |
1778 | } | ||
1779 | |||
1780 | if ((retval = hcd_buffer_create(hcd)) != 0) { | 1791 | if ((retval = hcd_buffer_create(hcd)) != 0) { |
1781 | dev_dbg(hcd->self.controller, "pool alloc failed\n"); | 1792 | dev_dbg(hcd->self.controller, "pool alloc failed\n"); |
1782 | return retval; | 1793 | return retval; |
@@ -1785,6 +1796,36 @@ int usb_add_hcd(struct usb_hcd *hcd, | |||
1785 | if ((retval = usb_register_bus(&hcd->self)) < 0) | 1796 | if ((retval = usb_register_bus(&hcd->self)) < 0) |
1786 | goto err_register_bus; | 1797 | goto err_register_bus; |
1787 | 1798 | ||
1799 | if ((rhdev = usb_alloc_dev(NULL, &hcd->self, 0)) == NULL) { | ||
1800 | dev_err(hcd->self.controller, "unable to allocate root hub\n"); | ||
1801 | retval = -ENOMEM; | ||
1802 | goto err_allocate_root_hub; | ||
1803 | } | ||
1804 | rhdev->speed = (hcd->driver->flags & HCD_USB2) ? USB_SPEED_HIGH : | ||
1805 | USB_SPEED_FULL; | ||
1806 | hcd->self.root_hub = rhdev; | ||
1807 | |||
1808 | /* "reset" is misnamed; its role is now one-time init. the controller | ||
1809 | * should already have been reset (and boot firmware kicked off etc). | ||
1810 | */ | ||
1811 | if (hcd->driver->reset && (retval = hcd->driver->reset(hcd)) < 0) { | ||
1812 | dev_err(hcd->self.controller, "can't setup\n"); | ||
1813 | goto err_hcd_driver_setup; | ||
1814 | } | ||
1815 | |||
1816 | /* wakeup flag init is in transition; for now we can't rely on PCI to | ||
1817 | * initialize these bits properly, so we let reset() override it. | ||
1818 | * This init should _precede_ the reset() once PCI behaves. | ||
1819 | */ | ||
1820 | device_init_wakeup(&rhdev->dev, | ||
1821 | device_can_wakeup(hcd->self.controller)); | ||
1822 | |||
1823 | /* NOTE: root hub and controller capabilities may not be the same */ | ||
1824 | if (device_can_wakeup(hcd->self.controller) | ||
1825 | && device_can_wakeup(&hcd->self.root_hub->dev)) | ||
1826 | dev_dbg(hcd->self.controller, "supports USB remote wakeup\n"); | ||
1827 | |||
1828 | /* enable irqs just before we start the controller */ | ||
1788 | if (hcd->driver->irq) { | 1829 | if (hcd->driver->irq) { |
1789 | char buf[8], *bufp = buf; | 1830 | char buf[8], *bufp = buf; |
1790 | 1831 | ||
@@ -1816,56 +1857,32 @@ int usb_add_hcd(struct usb_hcd *hcd, | |||
1816 | (unsigned long long)hcd->rsrc_start); | 1857 | (unsigned long long)hcd->rsrc_start); |
1817 | } | 1858 | } |
1818 | 1859 | ||
1819 | /* Allocate the root hub before calling hcd->driver->start(), | ||
1820 | * but don't register it until afterward so that the hardware | ||
1821 | * is running. | ||
1822 | */ | ||
1823 | if ((rhdev = usb_alloc_dev(NULL, &hcd->self, 0)) == NULL) { | ||
1824 | dev_err(hcd->self.controller, "unable to allocate root hub\n"); | ||
1825 | retval = -ENOMEM; | ||
1826 | goto err_allocate_root_hub; | ||
1827 | } | ||
1828 | |||
1829 | /* Although in principle hcd->driver->start() might need to use rhdev, | ||
1830 | * none of the current drivers do. | ||
1831 | */ | ||
1832 | if ((retval = hcd->driver->start(hcd)) < 0) { | 1860 | if ((retval = hcd->driver->start(hcd)) < 0) { |
1833 | dev_err(hcd->self.controller, "startup error %d\n", retval); | 1861 | dev_err(hcd->self.controller, "startup error %d\n", retval); |
1834 | goto err_hcd_driver_start; | 1862 | goto err_hcd_driver_start; |
1835 | } | 1863 | } |
1836 | 1864 | ||
1837 | /* hcd->driver->start() reported can_wakeup, probably with | 1865 | /* starting here, usbcore will pay attention to this root hub */ |
1838 | * assistance from board's boot firmware. | ||
1839 | * NOTE: normal devices won't enable wakeup by default. | ||
1840 | */ | ||
1841 | if (hcd->can_wakeup) | ||
1842 | dev_dbg(hcd->self.controller, "supports USB remote wakeup\n"); | ||
1843 | hcd->remote_wakeup = hcd->can_wakeup; | ||
1844 | |||
1845 | rhdev->speed = (hcd->driver->flags & HCD_USB2) ? USB_SPEED_HIGH : | ||
1846 | USB_SPEED_FULL; | ||
1847 | rhdev->bus_mA = min(500u, hcd->power_budget); | 1866 | rhdev->bus_mA = min(500u, hcd->power_budget); |
1848 | if ((retval = register_root_hub(rhdev, hcd)) != 0) | 1867 | if ((retval = register_root_hub(hcd)) != 0) |
1849 | goto err_register_root_hub; | 1868 | goto err_register_root_hub; |
1850 | 1869 | ||
1851 | if (hcd->uses_new_polling && hcd->poll_rh) | 1870 | if (hcd->uses_new_polling && hcd->poll_rh) |
1852 | usb_hcd_poll_rh_status(hcd); | 1871 | usb_hcd_poll_rh_status(hcd); |
1853 | return retval; | 1872 | return retval; |
1854 | 1873 | ||
1855 | err_register_root_hub: | 1874 | err_register_root_hub: |
1856 | hcd->driver->stop(hcd); | 1875 | hcd->driver->stop(hcd); |
1857 | 1876 | err_hcd_driver_start: | |
1858 | err_hcd_driver_start: | ||
1859 | usb_put_dev(rhdev); | ||
1860 | |||
1861 | err_allocate_root_hub: | ||
1862 | if (hcd->irq >= 0) | 1877 | if (hcd->irq >= 0) |
1863 | free_irq(irqnum, hcd); | 1878 | free_irq(irqnum, hcd); |
1864 | 1879 | err_request_irq: | |
1865 | err_request_irq: | 1880 | err_hcd_driver_setup: |
1881 | hcd->self.root_hub = NULL; | ||
1882 | usb_put_dev(rhdev); | ||
1883 | err_allocate_root_hub: | ||
1866 | usb_deregister_bus(&hcd->self); | 1884 | usb_deregister_bus(&hcd->self); |
1867 | 1885 | err_register_bus: | |
1868 | err_register_bus: | ||
1869 | hcd_buffer_destroy(hcd); | 1886 | hcd_buffer_destroy(hcd); |
1870 | return retval; | 1887 | return retval; |
1871 | } | 1888 | } |
@@ -1891,9 +1908,9 @@ void usb_remove_hcd(struct usb_hcd *hcd) | |||
1891 | hcd->rh_registered = 0; | 1908 | hcd->rh_registered = 0; |
1892 | spin_unlock_irq (&hcd_root_hub_lock); | 1909 | spin_unlock_irq (&hcd_root_hub_lock); |
1893 | 1910 | ||
1894 | down(&usb_bus_list_lock); | 1911 | mutex_lock(&usb_bus_list_lock); |
1895 | usb_disconnect(&hcd->self.root_hub); | 1912 | usb_disconnect(&hcd->self.root_hub); |
1896 | up(&usb_bus_list_lock); | 1913 | mutex_unlock(&usb_bus_list_lock); |
1897 | 1914 | ||
1898 | hcd->poll_rh = 0; | 1915 | hcd->poll_rh = 0; |
1899 | del_timer_sync(&hcd->rh_timer); | 1916 | del_timer_sync(&hcd->rh_timer); |