Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] usbcore: register root hub in usb_add_hcd

This patch makes usbcore automatically allocate and register the root hub
device for a new host controller when the controller is registered. This
way the HCDs don't all have to include the same boilerplate code. As a
pleasant side benefit, the register_root_hub routine can now be made
static and not EXPORTed.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Alan Stern and committed by
Greg Kroah-Hartman
8ec8d20b bc96c0ad

+49 -26
+49 -23
drivers/usb/core/hcd.c
··· 832 832 } 833 833 834 834 /** 835 - * usb_hcd_register_root_hub - called by HCD to register its root hub 835 + * register_root_hub - called by usb_add_hcd() to register a root hub 836 836 * @usb_dev: the usb root hub device to be registered. 837 837 * @hcd: host controller for this root hub 838 838 * 839 - * The USB host controller calls this function to register the root hub 840 - * properly with the USB subsystem. It sets up the device properly in 841 - * the device tree and stores the root_hub pointer in the bus structure, 842 - * then calls usb_new_device() to register the usb device. It also 843 - * assigns the root hub's USB address (always 1). 839 + * This function registers the root hub with the USB subsystem. It sets up 840 + * the device properly in the device tree and stores the root_hub pointer 841 + * in the bus structure, then calls usb_new_device() to register the usb 842 + * device. It also assigns the root hub's USB address (always 1). 844 843 */ 845 - int usb_hcd_register_root_hub (struct usb_device *usb_dev, struct usb_hcd *hcd) 844 + static int register_root_hub (struct usb_device *usb_dev, 845 + struct usb_hcd *hcd) 846 846 { 847 847 struct device *parent_dev = hcd->self.controller; 848 848 const int devnum = 1; 849 849 int retval; 850 - 851 - /* hcd->driver->start() reported can_wakeup, probably with 852 - * assistance from board's boot firmware. 853 - * NOTE: normal devices won't enable wakeup by default. 854 - */ 855 - if (hcd->can_wakeup) 856 - dev_dbg (parent_dev, "supports USB remote wakeup\n"); 857 - hcd->remote_wakeup = hcd->can_wakeup; 858 850 859 851 usb_dev->devnum = devnum; 860 852 usb_dev->bus->devnum_next = devnum + 1; ··· 890 898 891 899 return retval; 892 900 } 893 - EXPORT_SYMBOL_GPL(usb_hcd_register_root_hub); 894 901 895 902 void usb_enable_root_hub_irq (struct usb_bus *bus) 896 903 { ··· 1715 1724 int usb_add_hcd(struct usb_hcd *hcd, 1716 1725 unsigned int irqnum, unsigned long irqflags) 1717 1726 { 1718 - int retval; 1727 + int retval; 1728 + struct usb_device *rhdev; 1719 1729 1720 1730 dev_info(hcd->self.controller, "%s\n", hcd->product_desc); 1721 1731 ··· 1732 1740 } 1733 1741 1734 1742 if ((retval = usb_register_bus(&hcd->self)) < 0) 1735 - goto err1; 1743 + goto err_register_bus; 1736 1744 1737 1745 if (hcd->driver->irq) { 1738 1746 char buf[8], *bufp = buf; ··· 1749 1757 hcd->irq_descr, hcd)) != 0) { 1750 1758 dev_err(hcd->self.controller, 1751 1759 "request interrupt %s failed\n", bufp); 1752 - goto err2; 1760 + goto err_request_irq; 1753 1761 } 1754 1762 hcd->irq = irqnum; 1755 1763 dev_info(hcd->self.controller, "irq %s, %s 0x%08llx\n", bufp, ··· 1765 1773 (unsigned long long)hcd->rsrc_start); 1766 1774 } 1767 1775 1776 + /* Allocate the root hub before calling hcd->driver->start(), 1777 + * but don't register it until afterward so that the hardware 1778 + * is running. 1779 + */ 1780 + if ((rhdev = usb_alloc_dev(NULL, &hcd->self, 0)) == NULL) { 1781 + dev_err(hcd->self.controller, "unable to allocate root hub\n"); 1782 + retval = -ENOMEM; 1783 + goto err_allocate_root_hub; 1784 + } 1785 + rhdev->speed = (hcd->driver->flags & HCD_USB2) ? USB_SPEED_HIGH : 1786 + USB_SPEED_FULL; 1787 + 1788 + /* Although in principle hcd->driver->start() might need to use rhdev, 1789 + * none of the current drivers do. 1790 + */ 1768 1791 if ((retval = hcd->driver->start(hcd)) < 0) { 1769 1792 dev_err(hcd->self.controller, "startup error %d\n", retval); 1770 - goto err3; 1793 + goto err_hcd_driver_start; 1771 1794 } 1795 + 1796 + /* hcd->driver->start() reported can_wakeup, probably with 1797 + * assistance from board's boot firmware. 1798 + * NOTE: normal devices won't enable wakeup by default. 1799 + */ 1800 + if (hcd->can_wakeup) 1801 + dev_dbg(hcd->self.controller, "supports USB remote wakeup\n"); 1802 + hcd->remote_wakeup = hcd->can_wakeup; 1803 + 1804 + if ((retval = register_root_hub(rhdev, hcd)) != 0) 1805 + goto err_register_root_hub; 1772 1806 1773 1807 if (hcd->uses_new_polling && hcd->poll_rh) 1774 1808 usb_hcd_poll_rh_status(hcd); 1775 1809 return retval; 1776 1810 1777 - err3: 1811 + err_register_root_hub: 1812 + hcd->driver->stop(hcd); 1813 + 1814 + err_hcd_driver_start: 1815 + usb_put_dev(rhdev); 1816 + 1817 + err_allocate_root_hub: 1778 1818 if (hcd->irq >= 0) 1779 1819 free_irq(irqnum, hcd); 1780 - err2: 1820 + 1821 + err_request_irq: 1781 1822 usb_deregister_bus(&hcd->self); 1782 - err1: 1823 + 1824 + err_register_bus: 1783 1825 hcd_buffer_destroy(hcd); 1784 1826 return retval; 1785 1827 }
-3
drivers/usb/core/hcd.h
··· 353 353 354 354 extern struct usb_bus *usb_alloc_bus (struct usb_operations *); 355 355 356 - extern int usb_hcd_register_root_hub (struct usb_device *usb_dev, 357 - struct usb_hcd *hcd); 358 - 359 356 extern void usb_hcd_resume_root_hub (struct usb_hcd *hcd); 360 357 361 358 extern void usb_set_device_state(struct usb_device *udev,