diff options
author | David Brownell <david-b@pacbell.net> | 2006-01-23 18:25:40 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2006-03-20 17:49:56 -0500 |
commit | b1e8f0a6a8805c971857cd10a65cf8caa4c1a672 (patch) | |
tree | 395b7a91cbd0d5eb10a4c7429d7db6255b097b48 | |
parent | 1c05ad4447e4ecbd61647c102fb6f2f5a6634ff3 (diff) |
[PATCH] USB: usbcore sets up root hubs earlier
Make the HCD initialization sequence more sane ... notably, setting up
root hubs before HCDs are asked to do their one-time init. Among other
things, that lets the HCDs do custom root hub init along with all the
other one-time initialization done in the (now misnamed) reset() method.
This also copies the controller wakeup flags into the root hub; it's
done a bit later than would be ideal, but that'll be necessary until
the PCI code initializes them correctly. (The PCI patch breaks on PPC
due to how it sequences PCI initialization.)
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r-- | drivers/usb/core/hcd.c | 104 |
1 files changed, 55 insertions, 49 deletions
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index 9223f2869674..6368562d73ca 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c | |||
@@ -823,18 +823,17 @@ static void usb_deregister_bus (struct usb_bus *bus) | |||
823 | 823 | ||
824 | /** | 824 | /** |
825 | * register_root_hub - called by usb_add_hcd() to register a root hub | 825 | * register_root_hub - called by usb_add_hcd() to register a root hub |
826 | * @usb_dev: the usb root hub device to be registered. | ||
827 | * @hcd: host controller for this root hub | 826 | * @hcd: host controller for this root hub |
828 | * | 827 | * |
829 | * This function registers the root hub with the USB subsystem. It sets up | 828 | * This function registers the root hub with the USB subsystem. It sets up |
830 | * the device properly in the device tree and stores the root_hub pointer | 829 | * the device properly in the device tree and then calls usb_new_device() |
831 | * in the bus structure, then calls usb_new_device() to register the usb | 830 | * to register the usb device. It also assigns the root hub's USB address |
832 | * device. It also assigns the root hub's USB address (always 1). | 831 | * (always 1). |
833 | */ | 832 | */ |
834 | static int register_root_hub (struct usb_device *usb_dev, | 833 | static int register_root_hub(struct usb_hcd *hcd) |
835 | struct usb_hcd *hcd) | ||
836 | { | 834 | { |
837 | struct device *parent_dev = hcd->self.controller; | 835 | struct device *parent_dev = hcd->self.controller; |
836 | struct usb_device *usb_dev = hcd->self.root_hub; | ||
838 | const int devnum = 1; | 837 | const int devnum = 1; |
839 | int retval; | 838 | int retval; |
840 | 839 | ||
@@ -846,12 +845,10 @@ static int register_root_hub (struct usb_device *usb_dev, | |||
846 | usb_set_device_state(usb_dev, USB_STATE_ADDRESS); | 845 | usb_set_device_state(usb_dev, USB_STATE_ADDRESS); |
847 | 846 | ||
848 | mutex_lock(&usb_bus_list_lock); | 847 | mutex_lock(&usb_bus_list_lock); |
849 | usb_dev->bus->root_hub = usb_dev; | ||
850 | 848 | ||
851 | usb_dev->ep0.desc.wMaxPacketSize = __constant_cpu_to_le16(64); | 849 | usb_dev->ep0.desc.wMaxPacketSize = __constant_cpu_to_le16(64); |
852 | retval = usb_get_device_descriptor(usb_dev, USB_DT_DEVICE_SIZE); | 850 | retval = usb_get_device_descriptor(usb_dev, USB_DT_DEVICE_SIZE); |
853 | if (retval != sizeof usb_dev->descriptor) { | 851 | if (retval != sizeof usb_dev->descriptor) { |
854 | usb_dev->bus->root_hub = NULL; | ||
855 | mutex_unlock(&usb_bus_list_lock); | 852 | mutex_unlock(&usb_bus_list_lock); |
856 | dev_dbg (parent_dev, "can't read %s device descriptor %d\n", | 853 | dev_dbg (parent_dev, "can't read %s device descriptor %d\n", |
857 | usb_dev->dev.bus_id, retval); | 854 | usb_dev->dev.bus_id, retval); |
@@ -860,7 +857,6 @@ static int register_root_hub (struct usb_device *usb_dev, | |||
860 | 857 | ||
861 | retval = usb_new_device (usb_dev); | 858 | retval = usb_new_device (usb_dev); |
862 | if (retval) { | 859 | if (retval) { |
863 | usb_dev->bus->root_hub = NULL; | ||
864 | dev_err (parent_dev, "can't register root hub for %s, %d\n", | 860 | dev_err (parent_dev, "can't register root hub for %s, %d\n", |
865 | usb_dev->dev.bus_id, retval); | 861 | usb_dev->dev.bus_id, retval); |
866 | } | 862 | } |
@@ -1772,12 +1768,10 @@ int usb_add_hcd(struct usb_hcd *hcd, | |||
1772 | 1768 | ||
1773 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | 1769 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
1774 | 1770 | ||
1775 | /* till now HC has been in an indeterminate state ... */ | 1771 | /* HC is in reset state, but accessible. Now do the one-time init, |
1776 | if (hcd->driver->reset && (retval = hcd->driver->reset(hcd)) < 0) { | 1772 | * bottom up so that hcds can customize the root hubs before khubd |
1777 | dev_err(hcd->self.controller, "can't reset\n"); | 1773 | * starts talking to them. (Note, bus id is assigned early too.) |
1778 | return retval; | 1774 | */ |
1779 | } | ||
1780 | |||
1781 | if ((retval = hcd_buffer_create(hcd)) != 0) { | 1775 | if ((retval = hcd_buffer_create(hcd)) != 0) { |
1782 | dev_dbg(hcd->self.controller, "pool alloc failed\n"); | 1776 | dev_dbg(hcd->self.controller, "pool alloc failed\n"); |
1783 | return retval; | 1777 | return retval; |
@@ -1786,6 +1780,42 @@ int usb_add_hcd(struct usb_hcd *hcd, | |||
1786 | if ((retval = usb_register_bus(&hcd->self)) < 0) | 1780 | if ((retval = usb_register_bus(&hcd->self)) < 0) |
1787 | goto err_register_bus; | 1781 | goto err_register_bus; |
1788 | 1782 | ||
1783 | if ((rhdev = usb_alloc_dev(NULL, &hcd->self, 0)) == NULL) { | ||
1784 | dev_err(hcd->self.controller, "unable to allocate root hub\n"); | ||
1785 | retval = -ENOMEM; | ||
1786 | goto err_allocate_root_hub; | ||
1787 | } | ||
1788 | rhdev->speed = (hcd->driver->flags & HCD_USB2) ? USB_SPEED_HIGH : | ||
1789 | USB_SPEED_FULL; | ||
1790 | hcd->self.root_hub = rhdev; | ||
1791 | |||
1792 | /* "reset" is misnamed; its role is now one-time init. the controller | ||
1793 | * should already have been reset (and boot firmware kicked off etc). | ||
1794 | */ | ||
1795 | if (hcd->driver->reset && (retval = hcd->driver->reset(hcd)) < 0) { | ||
1796 | dev_err(hcd->self.controller, "can't setup\n"); | ||
1797 | goto err_hcd_driver_setup; | ||
1798 | } | ||
1799 | |||
1800 | /* wakeup flag init is in transition; for now we can't rely on PCI to | ||
1801 | * initialize these bits properly, so we let reset() override it. | ||
1802 | * This init should _precede_ the reset() once PCI behaves. | ||
1803 | */ | ||
1804 | device_init_wakeup(&rhdev->dev, | ||
1805 | device_can_wakeup(hcd->self.controller)); | ||
1806 | |||
1807 | // ... all these hcd->*_wakeup flags will vanish | ||
1808 | hcd->can_wakeup = device_can_wakeup(hcd->self.controller); | ||
1809 | |||
1810 | /* hcd->driver->reset() reported can_wakeup, probably with | ||
1811 | * assistance from board's boot firmware. | ||
1812 | * NOTE: normal devices won't enable wakeup by default. | ||
1813 | */ | ||
1814 | if (hcd->can_wakeup) | ||
1815 | dev_dbg(hcd->self.controller, "supports USB remote wakeup\n"); | ||
1816 | hcd->remote_wakeup = hcd->can_wakeup; | ||
1817 | |||
1818 | /* enable irqs just before we start the controller */ | ||
1789 | if (hcd->driver->irq) { | 1819 | if (hcd->driver->irq) { |
1790 | char buf[8], *bufp = buf; | 1820 | char buf[8], *bufp = buf; |
1791 | 1821 | ||
@@ -1817,56 +1847,32 @@ int usb_add_hcd(struct usb_hcd *hcd, | |||
1817 | (unsigned long long)hcd->rsrc_start); | 1847 | (unsigned long long)hcd->rsrc_start); |
1818 | } | 1848 | } |
1819 | 1849 | ||
1820 | /* Allocate the root hub before calling hcd->driver->start(), | ||
1821 | * but don't register it until afterward so that the hardware | ||
1822 | * is running. | ||
1823 | */ | ||
1824 | if ((rhdev = usb_alloc_dev(NULL, &hcd->self, 0)) == NULL) { | ||
1825 | dev_err(hcd->self.controller, "unable to allocate root hub\n"); | ||
1826 | retval = -ENOMEM; | ||
1827 | goto err_allocate_root_hub; | ||
1828 | } | ||
1829 | |||
1830 | /* Although in principle hcd->driver->start() might need to use rhdev, | ||
1831 | * none of the current drivers do. | ||
1832 | */ | ||
1833 | if ((retval = hcd->driver->start(hcd)) < 0) { | 1850 | if ((retval = hcd->driver->start(hcd)) < 0) { |
1834 | dev_err(hcd->self.controller, "startup error %d\n", retval); | 1851 | dev_err(hcd->self.controller, "startup error %d\n", retval); |
1835 | goto err_hcd_driver_start; | 1852 | goto err_hcd_driver_start; |
1836 | } | 1853 | } |
1837 | 1854 | ||
1838 | /* hcd->driver->start() reported can_wakeup, probably with | 1855 | /* starting here, usbcore will pay attention to this root hub */ |
1839 | * assistance from board's boot firmware. | ||
1840 | * NOTE: normal devices won't enable wakeup by default. | ||
1841 | */ | ||
1842 | if (hcd->can_wakeup) | ||
1843 | dev_dbg(hcd->self.controller, "supports USB remote wakeup\n"); | ||
1844 | hcd->remote_wakeup = hcd->can_wakeup; | ||
1845 | |||
1846 | rhdev->speed = (hcd->driver->flags & HCD_USB2) ? USB_SPEED_HIGH : | ||
1847 | USB_SPEED_FULL; | ||
1848 | rhdev->bus_mA = min(500u, hcd->power_budget); | 1856 | rhdev->bus_mA = min(500u, hcd->power_budget); |
1849 | if ((retval = register_root_hub(rhdev, hcd)) != 0) | 1857 | if ((retval = register_root_hub(hcd)) != 0) |
1850 | goto err_register_root_hub; | 1858 | goto err_register_root_hub; |
1851 | 1859 | ||
1852 | if (hcd->uses_new_polling && hcd->poll_rh) | 1860 | if (hcd->uses_new_polling && hcd->poll_rh) |
1853 | usb_hcd_poll_rh_status(hcd); | 1861 | usb_hcd_poll_rh_status(hcd); |
1854 | return retval; | 1862 | return retval; |
1855 | 1863 | ||
1856 | err_register_root_hub: | 1864 | err_register_root_hub: |
1857 | hcd->driver->stop(hcd); | 1865 | hcd->driver->stop(hcd); |
1858 | 1866 | err_hcd_driver_start: | |
1859 | err_hcd_driver_start: | ||
1860 | usb_put_dev(rhdev); | ||
1861 | |||
1862 | err_allocate_root_hub: | ||
1863 | if (hcd->irq >= 0) | 1867 | if (hcd->irq >= 0) |
1864 | free_irq(irqnum, hcd); | 1868 | free_irq(irqnum, hcd); |
1865 | 1869 | err_request_irq: | |
1866 | err_request_irq: | 1870 | err_hcd_driver_setup: |
1871 | hcd->self.root_hub = NULL; | ||
1872 | usb_put_dev(rhdev); | ||
1873 | err_allocate_root_hub: | ||
1867 | usb_deregister_bus(&hcd->self); | 1874 | usb_deregister_bus(&hcd->self); |
1868 | 1875 | err_register_bus: | |
1869 | err_register_bus: | ||
1870 | hcd_buffer_destroy(hcd); | 1876 | hcd_buffer_destroy(hcd); |
1871 | return retval; | 1877 | return retval; |
1872 | } | 1878 | } |