diff options
Diffstat (limited to 'drivers/usb/musb/musb_core.c')
-rw-r--r-- | drivers/usb/musb/musb_core.c | 137 |
1 files changed, 48 insertions, 89 deletions
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index 37a261a6bb6a..29a24ced6748 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c | |||
@@ -380,7 +380,6 @@ static void musb_otg_timer_func(unsigned long data) | |||
380 | dev_dbg(musb->controller, "HNP: Unhandled mode %s\n", | 380 | dev_dbg(musb->controller, "HNP: Unhandled mode %s\n", |
381 | usb_otg_state_string(musb->xceiv->state)); | 381 | usb_otg_state_string(musb->xceiv->state)); |
382 | } | 382 | } |
383 | musb->ignore_disconnect = 0; | ||
384 | spin_unlock_irqrestore(&musb->lock, flags); | 383 | spin_unlock_irqrestore(&musb->lock, flags); |
385 | } | 384 | } |
386 | 385 | ||
@@ -389,7 +388,7 @@ static void musb_otg_timer_func(unsigned long data) | |||
389 | */ | 388 | */ |
390 | void musb_hnp_stop(struct musb *musb) | 389 | void musb_hnp_stop(struct musb *musb) |
391 | { | 390 | { |
392 | struct usb_hcd *hcd = musb_to_hcd(musb); | 391 | struct usb_hcd *hcd = musb->hcd; |
393 | void __iomem *mbase = musb->mregs; | 392 | void __iomem *mbase = musb->mregs; |
394 | u8 reg; | 393 | u8 reg; |
395 | 394 | ||
@@ -404,7 +403,8 @@ void musb_hnp_stop(struct musb *musb) | |||
404 | break; | 403 | break; |
405 | case OTG_STATE_B_HOST: | 404 | case OTG_STATE_B_HOST: |
406 | dev_dbg(musb->controller, "HNP: Disabling HR\n"); | 405 | dev_dbg(musb->controller, "HNP: Disabling HR\n"); |
407 | hcd->self.is_b_host = 0; | 406 | if (hcd) |
407 | hcd->self.is_b_host = 0; | ||
408 | musb->xceiv->state = OTG_STATE_B_PERIPHERAL; | 408 | musb->xceiv->state = OTG_STATE_B_PERIPHERAL; |
409 | MUSB_DEV_MODE(musb); | 409 | MUSB_DEV_MODE(musb); |
410 | reg = musb_readb(mbase, MUSB_POWER); | 410 | reg = musb_readb(mbase, MUSB_POWER); |
@@ -484,7 +484,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, | |||
484 | 484 | ||
485 | musb->xceiv->state = OTG_STATE_A_HOST; | 485 | musb->xceiv->state = OTG_STATE_A_HOST; |
486 | musb->is_active = 1; | 486 | musb->is_active = 1; |
487 | usb_hcd_resume_root_hub(musb_to_hcd(musb)); | 487 | musb_host_resume_root_hub(musb); |
488 | break; | 488 | break; |
489 | case OTG_STATE_B_WAIT_ACON: | 489 | case OTG_STATE_B_WAIT_ACON: |
490 | musb->xceiv->state = OTG_STATE_B_PERIPHERAL; | 490 | musb->xceiv->state = OTG_STATE_B_PERIPHERAL; |
@@ -501,7 +501,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, | |||
501 | case OTG_STATE_A_SUSPEND: | 501 | case OTG_STATE_A_SUSPEND: |
502 | /* possibly DISCONNECT is upcoming */ | 502 | /* possibly DISCONNECT is upcoming */ |
503 | musb->xceiv->state = OTG_STATE_A_HOST; | 503 | musb->xceiv->state = OTG_STATE_A_HOST; |
504 | usb_hcd_resume_root_hub(musb_to_hcd(musb)); | 504 | musb_host_resume_root_hub(musb); |
505 | break; | 505 | break; |
506 | case OTG_STATE_B_WAIT_ACON: | 506 | case OTG_STATE_B_WAIT_ACON: |
507 | case OTG_STATE_B_PERIPHERAL: | 507 | case OTG_STATE_B_PERIPHERAL: |
@@ -643,7 +643,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, | |||
643 | * undesired detour through A_WAIT_BCON. | 643 | * undesired detour through A_WAIT_BCON. |
644 | */ | 644 | */ |
645 | musb_hnp_stop(musb); | 645 | musb_hnp_stop(musb); |
646 | usb_hcd_resume_root_hub(musb_to_hcd(musb)); | 646 | musb_host_resume_root_hub(musb); |
647 | musb_root_disconnect(musb); | 647 | musb_root_disconnect(musb); |
648 | musb_platform_try_idle(musb, jiffies | 648 | musb_platform_try_idle(musb, jiffies |
649 | + msecs_to_jiffies(musb->a_wait_bcon | 649 | + msecs_to_jiffies(musb->a_wait_bcon |
@@ -685,7 +685,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, | |||
685 | } | 685 | } |
686 | 686 | ||
687 | if (int_usb & MUSB_INTR_CONNECT) { | 687 | if (int_usb & MUSB_INTR_CONNECT) { |
688 | struct usb_hcd *hcd = musb_to_hcd(musb); | 688 | struct usb_hcd *hcd = musb->hcd; |
689 | 689 | ||
690 | handled = IRQ_HANDLED; | 690 | handled = IRQ_HANDLED; |
691 | musb->is_active = 1; | 691 | musb->is_active = 1; |
@@ -726,31 +726,27 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, | |||
726 | dev_dbg(musb->controller, "HNP: CONNECT, now b_host\n"); | 726 | dev_dbg(musb->controller, "HNP: CONNECT, now b_host\n"); |
727 | b_host: | 727 | b_host: |
728 | musb->xceiv->state = OTG_STATE_B_HOST; | 728 | musb->xceiv->state = OTG_STATE_B_HOST; |
729 | hcd->self.is_b_host = 1; | 729 | if (musb->hcd) |
730 | musb->ignore_disconnect = 0; | 730 | musb->hcd->self.is_b_host = 1; |
731 | del_timer(&musb->otg_timer); | 731 | del_timer(&musb->otg_timer); |
732 | break; | 732 | break; |
733 | default: | 733 | default: |
734 | if ((devctl & MUSB_DEVCTL_VBUS) | 734 | if ((devctl & MUSB_DEVCTL_VBUS) |
735 | == (3 << MUSB_DEVCTL_VBUS_SHIFT)) { | 735 | == (3 << MUSB_DEVCTL_VBUS_SHIFT)) { |
736 | musb->xceiv->state = OTG_STATE_A_HOST; | 736 | musb->xceiv->state = OTG_STATE_A_HOST; |
737 | hcd->self.is_b_host = 0; | 737 | if (hcd) |
738 | hcd->self.is_b_host = 0; | ||
738 | } | 739 | } |
739 | break; | 740 | break; |
740 | } | 741 | } |
741 | 742 | ||
742 | /* poke the root hub */ | 743 | musb_host_poke_root_hub(musb); |
743 | MUSB_HST_MODE(musb); | ||
744 | if (hcd->status_urb) | ||
745 | usb_hcd_poll_rh_status(hcd); | ||
746 | else | ||
747 | usb_hcd_resume_root_hub(hcd); | ||
748 | 744 | ||
749 | dev_dbg(musb->controller, "CONNECT (%s) devctl %02x\n", | 745 | dev_dbg(musb->controller, "CONNECT (%s) devctl %02x\n", |
750 | usb_otg_state_string(musb->xceiv->state), devctl); | 746 | usb_otg_state_string(musb->xceiv->state), devctl); |
751 | } | 747 | } |
752 | 748 | ||
753 | if ((int_usb & MUSB_INTR_DISCONNECT) && !musb->ignore_disconnect) { | 749 | if (int_usb & MUSB_INTR_DISCONNECT) { |
754 | dev_dbg(musb->controller, "DISCONNECT (%s) as %s, devctl %02x\n", | 750 | dev_dbg(musb->controller, "DISCONNECT (%s) as %s, devctl %02x\n", |
755 | usb_otg_state_string(musb->xceiv->state), | 751 | usb_otg_state_string(musb->xceiv->state), |
756 | MUSB_MODE(musb), devctl); | 752 | MUSB_MODE(musb), devctl); |
@@ -759,7 +755,7 @@ b_host: | |||
759 | switch (musb->xceiv->state) { | 755 | switch (musb->xceiv->state) { |
760 | case OTG_STATE_A_HOST: | 756 | case OTG_STATE_A_HOST: |
761 | case OTG_STATE_A_SUSPEND: | 757 | case OTG_STATE_A_SUSPEND: |
762 | usb_hcd_resume_root_hub(musb_to_hcd(musb)); | 758 | musb_host_resume_root_hub(musb); |
763 | musb_root_disconnect(musb); | 759 | musb_root_disconnect(musb); |
764 | if (musb->a_wait_bcon != 0) | 760 | if (musb->a_wait_bcon != 0) |
765 | musb_platform_try_idle(musb, jiffies | 761 | musb_platform_try_idle(musb, jiffies |
@@ -772,7 +768,8 @@ b_host: | |||
772 | * in hnp_stop() is currently not used... | 768 | * in hnp_stop() is currently not used... |
773 | */ | 769 | */ |
774 | musb_root_disconnect(musb); | 770 | musb_root_disconnect(musb); |
775 | musb_to_hcd(musb)->self.is_b_host = 0; | 771 | if (musb->hcd) |
772 | musb->hcd->self.is_b_host = 0; | ||
776 | musb->xceiv->state = OTG_STATE_B_PERIPHERAL; | 773 | musb->xceiv->state = OTG_STATE_B_PERIPHERAL; |
777 | MUSB_DEV_MODE(musb); | 774 | MUSB_DEV_MODE(musb); |
778 | musb_g_disconnect(musb); | 775 | musb_g_disconnect(musb); |
@@ -818,11 +815,6 @@ b_host: | |||
818 | usb_otg_state_string(musb->xceiv->state)); | 815 | usb_otg_state_string(musb->xceiv->state)); |
819 | switch (musb->xceiv->state) { | 816 | switch (musb->xceiv->state) { |
820 | case OTG_STATE_A_SUSPEND: | 817 | case OTG_STATE_A_SUSPEND: |
821 | /* We need to ignore disconnect on suspend | ||
822 | * otherwise tusb 2.0 won't reconnect after a | ||
823 | * power cycle, which breaks otg compliance. | ||
824 | */ | ||
825 | musb->ignore_disconnect = 1; | ||
826 | musb_g_reset(musb); | 818 | musb_g_reset(musb); |
827 | /* FALLTHROUGH */ | 819 | /* FALLTHROUGH */ |
828 | case OTG_STATE_A_WAIT_BCON: /* OPT TD.4.7-900ms */ | 820 | case OTG_STATE_A_WAIT_BCON: /* OPT TD.4.7-900ms */ |
@@ -834,7 +826,6 @@ b_host: | |||
834 | + msecs_to_jiffies(TA_WAIT_BCON(musb))); | 826 | + msecs_to_jiffies(TA_WAIT_BCON(musb))); |
835 | break; | 827 | break; |
836 | case OTG_STATE_A_PERIPHERAL: | 828 | case OTG_STATE_A_PERIPHERAL: |
837 | musb->ignore_disconnect = 0; | ||
838 | del_timer(&musb->otg_timer); | 829 | del_timer(&musb->otg_timer); |
839 | musb_g_reset(musb); | 830 | musb_g_reset(musb); |
840 | break; | 831 | break; |
@@ -909,51 +900,6 @@ b_host: | |||
909 | 900 | ||
910 | /*-------------------------------------------------------------------------*/ | 901 | /*-------------------------------------------------------------------------*/ |
911 | 902 | ||
912 | /* | ||
913 | * Program the HDRC to start (enable interrupts, dma, etc.). | ||
914 | */ | ||
915 | void musb_start(struct musb *musb) | ||
916 | { | ||
917 | void __iomem *regs = musb->mregs; | ||
918 | u8 devctl = musb_readb(regs, MUSB_DEVCTL); | ||
919 | |||
920 | dev_dbg(musb->controller, "<== devctl %02x\n", devctl); | ||
921 | |||
922 | /* Set INT enable registers, enable interrupts */ | ||
923 | musb->intrtxe = musb->epmask; | ||
924 | musb_writew(regs, MUSB_INTRTXE, musb->intrtxe); | ||
925 | musb->intrrxe = musb->epmask & 0xfffe; | ||
926 | musb_writew(regs, MUSB_INTRRXE, musb->intrrxe); | ||
927 | musb_writeb(regs, MUSB_INTRUSBE, 0xf7); | ||
928 | |||
929 | musb_writeb(regs, MUSB_TESTMODE, 0); | ||
930 | |||
931 | /* put into basic highspeed mode and start session */ | ||
932 | musb_writeb(regs, MUSB_POWER, MUSB_POWER_ISOUPDATE | ||
933 | | MUSB_POWER_HSENAB | ||
934 | /* ENSUSPEND wedges tusb */ | ||
935 | /* | MUSB_POWER_ENSUSPEND */ | ||
936 | ); | ||
937 | |||
938 | musb->is_active = 0; | ||
939 | devctl = musb_readb(regs, MUSB_DEVCTL); | ||
940 | devctl &= ~MUSB_DEVCTL_SESSION; | ||
941 | |||
942 | /* session started after: | ||
943 | * (a) ID-grounded irq, host mode; | ||
944 | * (b) vbus present/connect IRQ, peripheral mode; | ||
945 | * (c) peripheral initiates, using SRP | ||
946 | */ | ||
947 | if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) | ||
948 | musb->is_active = 1; | ||
949 | else | ||
950 | devctl |= MUSB_DEVCTL_SESSION; | ||
951 | |||
952 | musb_platform_enable(musb); | ||
953 | musb_writeb(regs, MUSB_DEVCTL, devctl); | ||
954 | } | ||
955 | |||
956 | |||
957 | static void musb_generic_disable(struct musb *musb) | 903 | static void musb_generic_disable(struct musb *musb) |
958 | { | 904 | { |
959 | void __iomem *mbase = musb->mregs; | 905 | void __iomem *mbase = musb->mregs; |
@@ -1007,6 +953,7 @@ static void musb_shutdown(struct platform_device *pdev) | |||
1007 | 953 | ||
1008 | pm_runtime_get_sync(musb->controller); | 954 | pm_runtime_get_sync(musb->controller); |
1009 | 955 | ||
956 | musb_host_cleanup(musb); | ||
1010 | musb_gadget_cleanup(musb); | 957 | musb_gadget_cleanup(musb); |
1011 | 958 | ||
1012 | spin_lock_irqsave(&musb->lock, flags); | 959 | spin_lock_irqsave(&musb->lock, flags); |
@@ -1763,24 +1710,18 @@ static struct musb *allocate_instance(struct device *dev, | |||
1763 | struct musb *musb; | 1710 | struct musb *musb; |
1764 | struct musb_hw_ep *ep; | 1711 | struct musb_hw_ep *ep; |
1765 | int epnum; | 1712 | int epnum; |
1766 | struct usb_hcd *hcd; | 1713 | int ret; |
1767 | 1714 | ||
1768 | hcd = usb_create_hcd(&musb_hc_driver, dev, dev_name(dev)); | 1715 | musb = devm_kzalloc(dev, sizeof(*musb), GFP_KERNEL); |
1769 | if (!hcd) | 1716 | if (!musb) |
1770 | return NULL; | 1717 | return NULL; |
1771 | /* usbcore sets dev->driver_data to hcd, and sometimes uses that... */ | ||
1772 | 1718 | ||
1773 | musb = hcd_to_musb(hcd); | ||
1774 | INIT_LIST_HEAD(&musb->control); | 1719 | INIT_LIST_HEAD(&musb->control); |
1775 | INIT_LIST_HEAD(&musb->in_bulk); | 1720 | INIT_LIST_HEAD(&musb->in_bulk); |
1776 | INIT_LIST_HEAD(&musb->out_bulk); | 1721 | INIT_LIST_HEAD(&musb->out_bulk); |
1777 | 1722 | ||
1778 | hcd->uses_new_polling = 1; | ||
1779 | hcd->has_tt = 1; | ||
1780 | |||
1781 | musb->vbuserr_retry = VBUSERR_RETRY_COUNT; | 1723 | musb->vbuserr_retry = VBUSERR_RETRY_COUNT; |
1782 | musb->a_wait_bcon = OTG_TIME_A_WAIT_BCON; | 1724 | musb->a_wait_bcon = OTG_TIME_A_WAIT_BCON; |
1783 | dev_set_drvdata(dev, musb); | ||
1784 | musb->mregs = mbase; | 1725 | musb->mregs = mbase; |
1785 | musb->ctrl_base = mbase; | 1726 | musb->ctrl_base = mbase; |
1786 | musb->nIrq = -ENODEV; | 1727 | musb->nIrq = -ENODEV; |
@@ -1795,7 +1736,16 @@ static struct musb *allocate_instance(struct device *dev, | |||
1795 | 1736 | ||
1796 | musb->controller = dev; | 1737 | musb->controller = dev; |
1797 | 1738 | ||
1739 | ret = musb_host_alloc(musb); | ||
1740 | if (ret < 0) | ||
1741 | goto err_free; | ||
1742 | |||
1743 | dev_set_drvdata(dev, musb); | ||
1744 | |||
1798 | return musb; | 1745 | return musb; |
1746 | |||
1747 | err_free: | ||
1748 | return NULL; | ||
1799 | } | 1749 | } |
1800 | 1750 | ||
1801 | static void musb_free(struct musb *musb) | 1751 | static void musb_free(struct musb *musb) |
@@ -1821,7 +1771,7 @@ static void musb_free(struct musb *musb) | |||
1821 | dma_controller_destroy(c); | 1771 | dma_controller_destroy(c); |
1822 | } | 1772 | } |
1823 | 1773 | ||
1824 | usb_put_hcd(musb_to_hcd(musb)); | 1774 | musb_host_free(musb); |
1825 | } | 1775 | } |
1826 | 1776 | ||
1827 | /* | 1777 | /* |
@@ -1838,7 +1788,6 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl) | |||
1838 | int status; | 1788 | int status; |
1839 | struct musb *musb; | 1789 | struct musb *musb; |
1840 | struct musb_hdrc_platform_data *plat = dev->platform_data; | 1790 | struct musb_hdrc_platform_data *plat = dev->platform_data; |
1841 | struct usb_hcd *hcd; | ||
1842 | 1791 | ||
1843 | /* The driver might handle more features than the board; OK. | 1792 | /* The driver might handle more features than the board; OK. |
1844 | * Fail when the board needs a feature that's not enabled. | 1793 | * Fail when the board needs a feature that's not enabled. |
@@ -1864,6 +1813,7 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl) | |||
1864 | musb->board_set_power = plat->set_power; | 1813 | musb->board_set_power = plat->set_power; |
1865 | musb->min_power = plat->min_power; | 1814 | musb->min_power = plat->min_power; |
1866 | musb->ops = plat->platform_ops; | 1815 | musb->ops = plat->platform_ops; |
1816 | musb->port_mode = plat->mode; | ||
1867 | 1817 | ||
1868 | /* The musb_platform_init() call: | 1818 | /* The musb_platform_init() call: |
1869 | * - adjusts musb->mregs | 1819 | * - adjusts musb->mregs |
@@ -1939,13 +1889,6 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl) | |||
1939 | musb->irq_wake = 0; | 1889 | musb->irq_wake = 0; |
1940 | } | 1890 | } |
1941 | 1891 | ||
1942 | /* host side needs more setup */ | ||
1943 | hcd = musb_to_hcd(musb); | ||
1944 | otg_set_host(musb->xceiv->otg, &hcd->self); | ||
1945 | hcd->self.otg_port = 1; | ||
1946 | musb->xceiv->otg->host = &hcd->self; | ||
1947 | hcd->power_budget = 2 * (plat->power ? : 250); | ||
1948 | |||
1949 | /* program PHY to use external vBus if required */ | 1892 | /* program PHY to use external vBus if required */ |
1950 | if (plat->extvbus) { | 1893 | if (plat->extvbus) { |
1951 | u8 busctl = musb_read_ulpi_buscontrol(musb->mregs); | 1894 | u8 busctl = musb_read_ulpi_buscontrol(musb->mregs); |
@@ -1961,7 +1904,23 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl) | |||
1961 | musb->xceiv->state = OTG_STATE_B_IDLE; | 1904 | musb->xceiv->state = OTG_STATE_B_IDLE; |
1962 | } | 1905 | } |
1963 | 1906 | ||
1964 | status = musb_gadget_setup(musb); | 1907 | switch (musb->port_mode) { |
1908 | case MUSB_PORT_MODE_HOST: | ||
1909 | status = musb_host_setup(musb, plat->power); | ||
1910 | break; | ||
1911 | case MUSB_PORT_MODE_GADGET: | ||
1912 | status = musb_gadget_setup(musb); | ||
1913 | break; | ||
1914 | case MUSB_PORT_MODE_DUAL_ROLE: | ||
1915 | status = musb_host_setup(musb, plat->power); | ||
1916 | if (status < 0) | ||
1917 | goto fail3; | ||
1918 | status = musb_gadget_setup(musb); | ||
1919 | break; | ||
1920 | default: | ||
1921 | dev_err(dev, "unsupported port mode %d\n", musb->port_mode); | ||
1922 | break; | ||
1923 | } | ||
1965 | 1924 | ||
1966 | if (status < 0) | 1925 | if (status < 0) |
1967 | goto fail3; | 1926 | goto fail3; |