aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-07-05 18:35:41 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-07-05 18:35:41 -0400
commitff9cce82772a78983b529e044d85884d3ec95fda (patch)
tree6491adac0538739a415f7b776d1865ce7ae5d1f7 /drivers/usb
parent933141509cefd64102a943d61d154c5c53bad889 (diff)
parentf8ecf829481b2cc7301a811da9d2df53ef174977 (diff)
Merge tag 'xceiv-for-v3.6' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-next
usb: phy: patches for v3.6 merge window We are starting to support multiple USB phys as we should thanks for Kishon's work. DeviceTree support for USB PHYs won't come until discussion with DeviceTree maintainer is finished. Together with that series, we have one fix for twl4030 which missed a IRQF_ONESHOT annotation when requesting a threaded IRQ without a top half handler, and removal of an unused variable compilation warning to isp1301_omap.
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/chipidea/udc.c17
-rw-r--r--drivers/usb/gadget/fsl_udc_core.c17
-rw-r--r--drivers/usb/gadget/mv_udc_core.c15
-rw-r--r--drivers/usb/gadget/omap_udc.c31
-rw-r--r--drivers/usb/gadget/pxa25x_udc.c17
-rw-r--r--drivers/usb/gadget/pxa27x_udc.c15
-rw-r--r--drivers/usb/gadget/s3c-hsudc.c13
-rw-r--r--drivers/usb/host/ehci-fsl.c11
-rw-r--r--drivers/usb/host/ehci-msm.c8
-rw-r--r--drivers/usb/host/ehci-mv.c13
-rw-r--r--drivers/usb/host/ehci-tegra.c13
-rw-r--r--drivers/usb/host/ohci-omap.c11
-rw-r--r--drivers/usb/musb/am35x.c7
-rw-r--r--drivers/usb/musb/blackfin.c7
-rw-r--r--drivers/usb/musb/da8xx.c7
-rw-r--r--drivers/usb/musb/davinci.c9
-rw-r--r--drivers/usb/musb/musb_core.c2
-rw-r--r--drivers/usb/musb/musb_core.h2
-rw-r--r--drivers/usb/musb/musb_dsps.c9
-rw-r--r--drivers/usb/musb/omap2430.c124
-rw-r--r--drivers/usb/musb/tusb6010.c9
-rw-r--r--drivers/usb/musb/ux500.c7
-rw-r--r--drivers/usb/otg/ab8500-usb.c4
-rw-r--r--drivers/usb/otg/fsl_otg.c6
-rw-r--r--drivers/usb/otg/gpio_vbus.c4
-rw-r--r--drivers/usb/otg/isp1301_omap.c19
-rw-r--r--drivers/usb/otg/msm_otg.c6
-rw-r--r--drivers/usb/otg/mv_otg.c6
-rw-r--r--drivers/usb/otg/nop-usb-xceiv.c4
-rw-r--r--drivers/usb/otg/otg.c181
-rw-r--r--drivers/usb/otg/twl4030-usb.c73
-rw-r--r--drivers/usb/otg/twl6030-usb.c69
32 files changed, 441 insertions, 295 deletions
diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index 51f96942dc5e..4688ab71bd27 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -14,6 +14,7 @@
14#include <linux/device.h> 14#include <linux/device.h>
15#include <linux/dmapool.h> 15#include <linux/dmapool.h>
16#include <linux/dma-mapping.h> 16#include <linux/dma-mapping.h>
17#include <linux/err.h>
17#include <linux/init.h> 18#include <linux/init.h>
18#include <linux/platform_device.h> 19#include <linux/platform_device.h>
19#include <linux/module.h> 20#include <linux/module.h>
@@ -1687,7 +1688,7 @@ static int udc_start(struct ci13xxx *udc)
1687 1688
1688 udc->gadget.ep0 = &udc->ep0in->ep; 1689 udc->gadget.ep0 = &udc->ep0in->ep;
1689 1690
1690 udc->transceiver = usb_get_transceiver(); 1691 udc->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
1691 1692
1692 if (udc->udc_driver->flags & CI13XXX_REQUIRE_TRANSCEIVER) { 1693 if (udc->udc_driver->flags & CI13XXX_REQUIRE_TRANSCEIVER) {
1693 if (udc->transceiver == NULL) { 1694 if (udc->transceiver == NULL) {
@@ -1712,7 +1713,7 @@ static int udc_start(struct ci13xxx *udc)
1712 if (retval) 1713 if (retval)
1713 goto unreg_device; 1714 goto unreg_device;
1714 1715
1715 if (udc->transceiver) { 1716 if (!IS_ERR_OR_NULL(udc->transceiver)) {
1716 retval = otg_set_peripheral(udc->transceiver->otg, 1717 retval = otg_set_peripheral(udc->transceiver->otg,
1717 &udc->gadget); 1718 &udc->gadget);
1718 if (retval) 1719 if (retval)
@@ -1729,9 +1730,9 @@ static int udc_start(struct ci13xxx *udc)
1729 return retval; 1730 return retval;
1730 1731
1731remove_trans: 1732remove_trans:
1732 if (udc->transceiver) { 1733 if (!IS_ERR_OR_NULL(udc->transceiver)) {
1733 otg_set_peripheral(udc->transceiver->otg, &udc->gadget); 1734 otg_set_peripheral(udc->transceiver->otg, &udc->gadget);
1734 usb_put_transceiver(udc->transceiver); 1735 usb_put_phy(udc->transceiver);
1735 } 1736 }
1736 1737
1737 dev_err(dev, "error = %i\n", retval); 1738 dev_err(dev, "error = %i\n", retval);
@@ -1740,8 +1741,8 @@ remove_dbg:
1740unreg_device: 1741unreg_device:
1741 device_unregister(&udc->gadget.dev); 1742 device_unregister(&udc->gadget.dev);
1742put_transceiver: 1743put_transceiver:
1743 if (udc->transceiver) 1744 if (!IS_ERR_OR_NULL(udc->transceiver))
1744 usb_put_transceiver(udc->transceiver); 1745 usb_put_phy(udc->transceiver);
1745free_pools: 1746free_pools:
1746 dma_pool_destroy(udc->td_pool); 1747 dma_pool_destroy(udc->td_pool);
1747free_qh_pool: 1748free_qh_pool:
@@ -1772,9 +1773,9 @@ static void udc_stop(struct ci13xxx *udc)
1772 dma_pool_destroy(udc->td_pool); 1773 dma_pool_destroy(udc->td_pool);
1773 dma_pool_destroy(udc->qh_pool); 1774 dma_pool_destroy(udc->qh_pool);
1774 1775
1775 if (udc->transceiver) { 1776 if (!IS_ERR_OR_NULL(udc->transceiver)) {
1776 otg_set_peripheral(udc->transceiver->otg, NULL); 1777 otg_set_peripheral(udc->transceiver->otg, NULL);
1777 usb_put_transceiver(udc->transceiver); 1778 usb_put_phy(udc->transceiver);
1778 } 1779 }
1779 dbg_remove_files(&udc->gadget.dev); 1780 dbg_remove_files(&udc->gadget.dev);
1780 device_unregister(&udc->gadget.dev); 1781 device_unregister(&udc->gadget.dev);
diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index a65ca0f5d8c4..3def828f85e7 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -24,6 +24,7 @@
24#include <linux/ioport.h> 24#include <linux/ioport.h>
25#include <linux/types.h> 25#include <linux/types.h>
26#include <linux/errno.h> 26#include <linux/errno.h>
27#include <linux/err.h>
27#include <linux/slab.h> 28#include <linux/slab.h>
28#include <linux/init.h> 29#include <linux/init.h>
29#include <linux/list.h> 30#include <linux/list.h>
@@ -1229,7 +1230,7 @@ static int fsl_vbus_draw(struct usb_gadget *gadget, unsigned mA)
1229 struct fsl_udc *udc; 1230 struct fsl_udc *udc;
1230 1231
1231 udc = container_of(gadget, struct fsl_udc, gadget); 1232 udc = container_of(gadget, struct fsl_udc, gadget);
1232 if (udc->transceiver) 1233 if (!IS_ERR_OR_NULL(udc->transceiver))
1233 return usb_phy_set_power(udc->transceiver, mA); 1234 return usb_phy_set_power(udc->transceiver, mA);
1234 return -ENOTSUPP; 1235 return -ENOTSUPP;
1235} 1236}
@@ -1983,13 +1984,13 @@ static int fsl_start(struct usb_gadget_driver *driver,
1983 goto out; 1984 goto out;
1984 } 1985 }
1985 1986
1986 if (udc_controller->transceiver) { 1987 if (!IS_ERR_OR_NULL(udc_controller->transceiver)) {
1987 /* Suspend the controller until OTG enable it */ 1988 /* Suspend the controller until OTG enable it */
1988 udc_controller->stopped = 1; 1989 udc_controller->stopped = 1;
1989 printk(KERN_INFO "Suspend udc for OTG auto detect\n"); 1990 printk(KERN_INFO "Suspend udc for OTG auto detect\n");
1990 1991
1991 /* connect to bus through transceiver */ 1992 /* connect to bus through transceiver */
1992 if (udc_controller->transceiver) { 1993 if (!IS_ERR_OR_NULL(udc_controller->transceiver)) {
1993 retval = otg_set_peripheral( 1994 retval = otg_set_peripheral(
1994 udc_controller->transceiver->otg, 1995 udc_controller->transceiver->otg,
1995 &udc_controller->gadget); 1996 &udc_controller->gadget);
@@ -2030,7 +2031,7 @@ static int fsl_stop(struct usb_gadget_driver *driver)
2030 if (!driver || driver != udc_controller->driver || !driver->unbind) 2031 if (!driver || driver != udc_controller->driver || !driver->unbind)
2031 return -EINVAL; 2032 return -EINVAL;
2032 2033
2033 if (udc_controller->transceiver) 2034 if (!IS_ERR_OR_NULL(udc_controller->transceiver))
2034 otg_set_peripheral(udc_controller->transceiver->otg, NULL); 2035 otg_set_peripheral(udc_controller->transceiver->otg, NULL);
2035 2036
2036 /* stop DR, disable intr */ 2037 /* stop DR, disable intr */
@@ -2455,8 +2456,8 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
2455 2456
2456#ifdef CONFIG_USB_OTG 2457#ifdef CONFIG_USB_OTG
2457 if (pdata->operating_mode == FSL_USB2_DR_OTG) { 2458 if (pdata->operating_mode == FSL_USB2_DR_OTG) {
2458 udc_controller->transceiver = usb_get_transceiver(); 2459 udc_controller->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
2459 if (!udc_controller->transceiver) { 2460 if (IS_ERR_OR_NULL(udc_controller->transceiver)) {
2460 ERR("Can't find OTG driver!\n"); 2461 ERR("Can't find OTG driver!\n");
2461 ret = -ENODEV; 2462 ret = -ENODEV;
2462 goto err_kfree; 2463 goto err_kfree;
@@ -2540,7 +2541,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
2540 goto err_free_irq; 2541 goto err_free_irq;
2541 } 2542 }
2542 2543
2543 if (!udc_controller->transceiver) { 2544 if (IS_ERR_OR_NULL(udc_controller->transceiver)) {
2544 /* initialize usb hw reg except for regs for EP, 2545 /* initialize usb hw reg except for regs for EP,
2545 * leave usbintr reg untouched */ 2546 * leave usbintr reg untouched */
2546 dr_controller_setup(udc_controller); 2547 dr_controller_setup(udc_controller);
@@ -2565,7 +2566,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
2565 if (ret < 0) 2566 if (ret < 0)
2566 goto err_free_irq; 2567 goto err_free_irq;
2567 2568
2568 if (udc_controller->transceiver) 2569 if (!IS_ERR_OR_NULL(udc_controller->transceiver))
2569 udc_controller->gadget.is_otg = 1; 2570 udc_controller->gadget.is_otg = 1;
2570 2571
2571 /* setup QH and epctrl for ep0 */ 2572 /* setup QH and epctrl for ep0 */
diff --git a/drivers/usb/gadget/mv_udc_core.c b/drivers/usb/gadget/mv_udc_core.c
index 117a4bba1b8c..75db2c306cea 100644
--- a/drivers/usb/gadget/mv_udc_core.c
+++ b/drivers/usb/gadget/mv_udc_core.c
@@ -19,6 +19,7 @@
19#include <linux/sched.h> 19#include <linux/sched.h>
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/errno.h> 21#include <linux/errno.h>
22#include <linux/err.h>
22#include <linux/init.h> 23#include <linux/init.h>
23#include <linux/timer.h> 24#include <linux/timer.h>
24#include <linux/list.h> 25#include <linux/list.h>
@@ -1381,7 +1382,7 @@ static int mv_udc_start(struct usb_gadget_driver *driver,
1381 return retval; 1382 return retval;
1382 } 1383 }
1383 1384
1384 if (udc->transceiver) { 1385 if (!IS_ERR_OR_NULL(udc->transceiver)) {
1385 retval = otg_set_peripheral(udc->transceiver->otg, 1386 retval = otg_set_peripheral(udc->transceiver->otg,
1386 &udc->gadget); 1387 &udc->gadget);
1387 if (retval) { 1388 if (retval) {
@@ -2107,7 +2108,7 @@ static int __devexit mv_udc_remove(struct platform_device *dev)
2107 * then vbus irq will not be requested in udc driver. 2108 * then vbus irq will not be requested in udc driver.
2108 */ 2109 */
2109 if (udc->pdata && udc->pdata->vbus 2110 if (udc->pdata && udc->pdata->vbus
2110 && udc->clock_gating && udc->transceiver == NULL) 2111 && udc->clock_gating && IS_ERR_OR_NULL(udc->transceiver))
2111 free_irq(udc->pdata->vbus->irq, &dev->dev); 2112 free_irq(udc->pdata->vbus->irq, &dev->dev);
2112 2113
2113 /* free memory allocated in probe */ 2114 /* free memory allocated in probe */
@@ -2180,7 +2181,7 @@ static int __devinit mv_udc_probe(struct platform_device *dev)
2180 2181
2181#ifdef CONFIG_USB_OTG_UTILS 2182#ifdef CONFIG_USB_OTG_UTILS
2182 if (pdata->mode == MV_USB_MODE_OTG) 2183 if (pdata->mode == MV_USB_MODE_OTG)
2183 udc->transceiver = usb_get_transceiver(); 2184 udc->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
2184#endif 2185#endif
2185 2186
2186 udc->clknum = pdata->clknum; 2187 udc->clknum = pdata->clknum;
@@ -2325,7 +2326,7 @@ static int __devinit mv_udc_probe(struct platform_device *dev)
2325 eps_init(udc); 2326 eps_init(udc);
2326 2327
2327 /* VBUS detect: we can disable/enable clock on demand.*/ 2328 /* VBUS detect: we can disable/enable clock on demand.*/
2328 if (udc->transceiver) 2329 if (!IS_ERR_OR_NULL(udc->transceiver))
2329 udc->clock_gating = 1; 2330 udc->clock_gating = 1;
2330 else if (pdata->vbus) { 2331 else if (pdata->vbus) {
2331 udc->clock_gating = 1; 2332 udc->clock_gating = 1;
@@ -2369,7 +2370,7 @@ static int __devinit mv_udc_probe(struct platform_device *dev)
2369 2370
2370err_unregister: 2371err_unregister:
2371 if (udc->pdata && udc->pdata->vbus 2372 if (udc->pdata && udc->pdata->vbus
2372 && udc->clock_gating && udc->transceiver == NULL) 2373 && udc->clock_gating && IS_ERR_OR_NULL(udc->transceiver))
2373 free_irq(pdata->vbus->irq, &dev->dev); 2374 free_irq(pdata->vbus->irq, &dev->dev);
2374 device_unregister(&udc->gadget.dev); 2375 device_unregister(&udc->gadget.dev);
2375err_free_irq: 2376err_free_irq:
@@ -2404,7 +2405,7 @@ static int mv_udc_suspend(struct device *_dev)
2404 struct mv_udc *udc = the_controller; 2405 struct mv_udc *udc = the_controller;
2405 2406
2406 /* if OTG is enabled, the following will be done in OTG driver*/ 2407 /* if OTG is enabled, the following will be done in OTG driver*/
2407 if (udc->transceiver) 2408 if (!IS_ERR_OR_NULL(udc->transceiver))
2408 return 0; 2409 return 0;
2409 2410
2410 if (udc->pdata->vbus && udc->pdata->vbus->poll) 2411 if (udc->pdata->vbus && udc->pdata->vbus->poll)
@@ -2437,7 +2438,7 @@ static int mv_udc_resume(struct device *_dev)
2437 int retval; 2438 int retval;
2438 2439
2439 /* if OTG is enabled, the following will be done in OTG driver*/ 2440 /* if OTG is enabled, the following will be done in OTG driver*/
2440 if (udc->transceiver) 2441 if (!IS_ERR_OR_NULL(udc->transceiver))
2441 return 0; 2442 return 0;
2442 2443
2443 if (!udc->clock_gating) { 2444 if (!udc->clock_gating) {
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c
index b26c7d68cc06..d7df89e72efe 100644
--- a/drivers/usb/gadget/omap_udc.c
+++ b/drivers/usb/gadget/omap_udc.c
@@ -35,6 +35,7 @@
35#include <linux/usb/otg.h> 35#include <linux/usb/otg.h>
36#include <linux/dma-mapping.h> 36#include <linux/dma-mapping.h>
37#include <linux/clk.h> 37#include <linux/clk.h>
38#include <linux/err.h>
38#include <linux/prefetch.h> 39#include <linux/prefetch.h>
39#include <linux/io.h> 40#include <linux/io.h>
40 41
@@ -1152,7 +1153,7 @@ static int omap_wakeup(struct usb_gadget *gadget)
1152 1153
1153 /* NOTE: non-OTG systems may use SRP TOO... */ 1154 /* NOTE: non-OTG systems may use SRP TOO... */
1154 } else if (!(udc->devstat & UDC_ATT)) { 1155 } else if (!(udc->devstat & UDC_ATT)) {
1155 if (udc->transceiver) 1156 if (!IS_ERR_OR_NULL(udc->transceiver))
1156 retval = otg_start_srp(udc->transceiver->otg); 1157 retval = otg_start_srp(udc->transceiver->otg);
1157 } 1158 }
1158 spin_unlock_irqrestore(&udc->lock, flags); 1159 spin_unlock_irqrestore(&udc->lock, flags);
@@ -1284,7 +1285,7 @@ static int omap_vbus_draw(struct usb_gadget *gadget, unsigned mA)
1284 struct omap_udc *udc; 1285 struct omap_udc *udc;
1285 1286
1286 udc = container_of(gadget, struct omap_udc, gadget); 1287 udc = container_of(gadget, struct omap_udc, gadget);
1287 if (udc->transceiver) 1288 if (!IS_ERR_OR_NULL(udc->transceiver))
1288 return usb_phy_set_power(udc->transceiver, mA); 1289 return usb_phy_set_power(udc->transceiver, mA);
1289 return -EOPNOTSUPP; 1290 return -EOPNOTSUPP;
1290} 1291}
@@ -1734,12 +1735,12 @@ static void devstate_irq(struct omap_udc *udc, u16 irq_src)
1734 if (devstat & UDC_ATT) { 1735 if (devstat & UDC_ATT) {
1735 udc->gadget.speed = USB_SPEED_FULL; 1736 udc->gadget.speed = USB_SPEED_FULL;
1736 VDBG("connect\n"); 1737 VDBG("connect\n");
1737 if (!udc->transceiver) 1738 if (IS_ERR_OR_NULL(udc->transceiver))
1738 pullup_enable(udc); 1739 pullup_enable(udc);
1739 /* if (driver->connect) call it */ 1740 /* if (driver->connect) call it */
1740 } else if (udc->gadget.speed != USB_SPEED_UNKNOWN) { 1741 } else if (udc->gadget.speed != USB_SPEED_UNKNOWN) {
1741 udc->gadget.speed = USB_SPEED_UNKNOWN; 1742 udc->gadget.speed = USB_SPEED_UNKNOWN;
1742 if (!udc->transceiver) 1743 if (IS_ERR_OR_NULL(udc->transceiver))
1743 pullup_disable(udc); 1744 pullup_disable(udc);
1744 DBG("disconnect, gadget %s\n", 1745 DBG("disconnect, gadget %s\n",
1745 udc->driver->driver.name); 1746 udc->driver->driver.name);
@@ -1779,12 +1780,12 @@ static void devstate_irq(struct omap_udc *udc, u16 irq_src)
1779 udc->driver->suspend(&udc->gadget); 1780 udc->driver->suspend(&udc->gadget);
1780 spin_lock(&udc->lock); 1781 spin_lock(&udc->lock);
1781 } 1782 }
1782 if (udc->transceiver) 1783 if (!IS_ERR_OR_NULL(udc->transceiver))
1783 usb_phy_set_suspend( 1784 usb_phy_set_suspend(
1784 udc->transceiver, 1); 1785 udc->transceiver, 1);
1785 } else { 1786 } else {
1786 VDBG("resume\n"); 1787 VDBG("resume\n");
1787 if (udc->transceiver) 1788 if (!IS_ERR_OR_NULL(udc->transceiver))
1788 usb_phy_set_suspend( 1789 usb_phy_set_suspend(
1789 udc->transceiver, 0); 1790 udc->transceiver, 0);
1790 if (udc->gadget.speed == USB_SPEED_FULL 1791 if (udc->gadget.speed == USB_SPEED_FULL
@@ -2092,7 +2093,7 @@ static int omap_udc_start(struct usb_gadget_driver *driver,
2092 omap_writew(UDC_IRQ_SRC_MASK, UDC_IRQ_SRC); 2093 omap_writew(UDC_IRQ_SRC_MASK, UDC_IRQ_SRC);
2093 2094
2094 /* connect to bus through transceiver */ 2095 /* connect to bus through transceiver */
2095 if (udc->transceiver) { 2096 if (!IS_ERR_OR_NULL(udc->transceiver)) {
2096 status = otg_set_peripheral(udc->transceiver->otg, 2097 status = otg_set_peripheral(udc->transceiver->otg,
2097 &udc->gadget); 2098 &udc->gadget);
2098 if (status < 0) { 2099 if (status < 0) {
@@ -2139,7 +2140,7 @@ static int omap_udc_stop(struct usb_gadget_driver *driver)
2139 if (machine_without_vbus_sense()) 2140 if (machine_without_vbus_sense())
2140 omap_vbus_session(&udc->gadget, 0); 2141 omap_vbus_session(&udc->gadget, 0);
2141 2142
2142 if (udc->transceiver) 2143 if (!IS_ERR_OR_NULL(udc->transceiver))
2143 (void) otg_set_peripheral(udc->transceiver->otg, NULL); 2144 (void) otg_set_peripheral(udc->transceiver->otg, NULL);
2144 else 2145 else
2145 pullup_disable(udc); 2146 pullup_disable(udc);
@@ -2829,8 +2830,8 @@ static int __devinit omap_udc_probe(struct platform_device *pdev)
2829 * use it. Except for OTG, we don't _need_ to talk to one; 2830 * use it. Except for OTG, we don't _need_ to talk to one;
2830 * but not having one probably means no VBUS detection. 2831 * but not having one probably means no VBUS detection.
2831 */ 2832 */
2832 xceiv = usb_get_transceiver(); 2833 xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
2833 if (xceiv) 2834 if (!IS_ERR_OR_NULL(xceiv))
2834 type = xceiv->label; 2835 type = xceiv->label;
2835 else if (config->otg) { 2836 else if (config->otg) {
2836 DBG("OTG requires external transceiver!\n"); 2837 DBG("OTG requires external transceiver!\n");
@@ -2854,7 +2855,7 @@ static int __devinit omap_udc_probe(struct platform_device *pdev)
2854 case 16: 2855 case 16:
2855 case 19: 2856 case 19:
2856 case 25: 2857 case 25:
2857 if (!xceiv) { 2858 if (IS_ERR_OR_NULL(xceiv)) {
2858 DBG("external transceiver not registered!\n"); 2859 DBG("external transceiver not registered!\n");
2859 type = "unknown"; 2860 type = "unknown";
2860 } 2861 }
@@ -2956,8 +2957,8 @@ cleanup1:
2956 udc = NULL; 2957 udc = NULL;
2957 2958
2958cleanup0: 2959cleanup0:
2959 if (xceiv) 2960 if (!IS_ERR_OR_NULL(xceiv))
2960 usb_put_transceiver(xceiv); 2961 usb_put_phy(xceiv);
2961 2962
2962 if (cpu_is_omap16xx() || cpu_is_omap7xx()) { 2963 if (cpu_is_omap16xx() || cpu_is_omap7xx()) {
2963 clk_disable(hhc_clk); 2964 clk_disable(hhc_clk);
@@ -2986,8 +2987,8 @@ static int __devexit omap_udc_remove(struct platform_device *pdev)
2986 udc->done = &done; 2987 udc->done = &done;
2987 2988
2988 pullup_disable(udc); 2989 pullup_disable(udc);
2989 if (udc->transceiver) { 2990 if (!IS_ERR_OR_NULL(udc->transceiver)) {
2990 usb_put_transceiver(udc->transceiver); 2991 usb_put_phy(udc->transceiver);
2991 udc->transceiver = NULL; 2992 udc->transceiver = NULL;
2992 } 2993 }
2993 omap_writew(0, UDC_SYSCON1); 2994 omap_writew(0, UDC_SYSCON1);
diff --git a/drivers/usb/gadget/pxa25x_udc.c b/drivers/usb/gadget/pxa25x_udc.c
index f7ff9e8e746a..53c093b941e5 100644
--- a/drivers/usb/gadget/pxa25x_udc.c
+++ b/drivers/usb/gadget/pxa25x_udc.c
@@ -21,6 +21,7 @@
21#include <linux/ioport.h> 21#include <linux/ioport.h>
22#include <linux/types.h> 22#include <linux/types.h>
23#include <linux/errno.h> 23#include <linux/errno.h>
24#include <linux/err.h>
24#include <linux/delay.h> 25#include <linux/delay.h>
25#include <linux/slab.h> 26#include <linux/slab.h>
26#include <linux/init.h> 27#include <linux/init.h>
@@ -993,7 +994,7 @@ static int pxa25x_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
993 994
994 udc = container_of(_gadget, struct pxa25x_udc, gadget); 995 udc = container_of(_gadget, struct pxa25x_udc, gadget);
995 996
996 if (udc->transceiver) 997 if (!IS_ERR_OR_NULL(udc->transceiver))
997 return usb_phy_set_power(udc->transceiver, mA); 998 return usb_phy_set_power(udc->transceiver, mA);
998 return -EOPNOTSUPP; 999 return -EOPNOTSUPP;
999} 1000}
@@ -1299,7 +1300,7 @@ fail:
1299 DMSG("registered gadget driver '%s'\n", driver->driver.name); 1300 DMSG("registered gadget driver '%s'\n", driver->driver.name);
1300 1301
1301 /* connect to bus through transceiver */ 1302 /* connect to bus through transceiver */
1302 if (dev->transceiver) { 1303 if (!IS_ERR_OR_NULL(dev->transceiver)) {
1303 retval = otg_set_peripheral(dev->transceiver->otg, 1304 retval = otg_set_peripheral(dev->transceiver->otg,
1304 &dev->gadget); 1305 &dev->gadget);
1305 if (retval) { 1306 if (retval) {
@@ -1359,7 +1360,7 @@ static int pxa25x_stop(struct usb_gadget_driver *driver)
1359 stop_activity(dev, driver); 1360 stop_activity(dev, driver);
1360 local_irq_enable(); 1361 local_irq_enable();
1361 1362
1362 if (dev->transceiver) 1363 if (!IS_ERR_OR_NULL(dev->transceiver))
1363 (void) otg_set_peripheral(dev->transceiver->otg, NULL); 1364 (void) otg_set_peripheral(dev->transceiver->otg, NULL);
1364 1365
1365 driver->unbind(&dev->gadget); 1366 driver->unbind(&dev->gadget);
@@ -2159,7 +2160,7 @@ static int __init pxa25x_udc_probe(struct platform_device *pdev)
2159 dev->dev = &pdev->dev; 2160 dev->dev = &pdev->dev;
2160 dev->mach = pdev->dev.platform_data; 2161 dev->mach = pdev->dev.platform_data;
2161 2162
2162 dev->transceiver = usb_get_transceiver(); 2163 dev->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
2163 2164
2164 if (gpio_is_valid(dev->mach->gpio_pullup)) { 2165 if (gpio_is_valid(dev->mach->gpio_pullup)) {
2165 if ((retval = gpio_request(dev->mach->gpio_pullup, 2166 if ((retval = gpio_request(dev->mach->gpio_pullup,
@@ -2237,8 +2238,8 @@ lubbock_fail0:
2237 if (gpio_is_valid(dev->mach->gpio_pullup)) 2238 if (gpio_is_valid(dev->mach->gpio_pullup))
2238 gpio_free(dev->mach->gpio_pullup); 2239 gpio_free(dev->mach->gpio_pullup);
2239 err_gpio_pullup: 2240 err_gpio_pullup:
2240 if (dev->transceiver) { 2241 if (!IS_ERR_OR_NULL(dev->transceiver)) {
2241 usb_put_transceiver(dev->transceiver); 2242 usb_put_phy(dev->transceiver);
2242 dev->transceiver = NULL; 2243 dev->transceiver = NULL;
2243 } 2244 }
2244 clk_put(dev->clk); 2245 clk_put(dev->clk);
@@ -2279,8 +2280,8 @@ static int __exit pxa25x_udc_remove(struct platform_device *pdev)
2279 2280
2280 clk_put(dev->clk); 2281 clk_put(dev->clk);
2281 2282
2282 if (dev->transceiver) { 2283 if (!IS_ERR_OR_NULL(dev->transceiver)) {
2283 usb_put_transceiver(dev->transceiver); 2284 usb_put_phy(dev->transceiver);
2284 dev->transceiver = NULL; 2285 dev->transceiver = NULL;
2285 } 2286 }
2286 2287
diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c
index 98acb3ab9e17..644b4305cb99 100644
--- a/drivers/usb/gadget/pxa27x_udc.c
+++ b/drivers/usb/gadget/pxa27x_udc.c
@@ -13,6 +13,7 @@
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/types.h> 14#include <linux/types.h>
15#include <linux/errno.h> 15#include <linux/errno.h>
16#include <linux/err.h>
16#include <linux/platform_device.h> 17#include <linux/platform_device.h>
17#include <linux/delay.h> 18#include <linux/delay.h>
18#include <linux/list.h> 19#include <linux/list.h>
@@ -1573,7 +1574,7 @@ static int should_enable_udc(struct pxa_udc *udc)
1573 int put_on; 1574 int put_on;
1574 1575
1575 put_on = ((udc->pullup_on) && (udc->driver)); 1576 put_on = ((udc->pullup_on) && (udc->driver));
1576 put_on &= ((udc->vbus_sensed) || (!udc->transceiver)); 1577 put_on &= ((udc->vbus_sensed) || (IS_ERR_OR_NULL(udc->transceiver)));
1577 return put_on; 1578 return put_on;
1578} 1579}
1579 1580
@@ -1594,7 +1595,7 @@ static int should_disable_udc(struct pxa_udc *udc)
1594 int put_off; 1595 int put_off;
1595 1596
1596 put_off = ((!udc->pullup_on) || (!udc->driver)); 1597 put_off = ((!udc->pullup_on) || (!udc->driver));
1597 put_off |= ((!udc->vbus_sensed) && (udc->transceiver)); 1598 put_off |= ((!udc->vbus_sensed) && (!IS_ERR_OR_NULL(udc->transceiver)));
1598 return put_off; 1599 return put_off;
1599} 1600}
1600 1601
@@ -1665,7 +1666,7 @@ static int pxa_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
1665 struct pxa_udc *udc; 1666 struct pxa_udc *udc;
1666 1667
1667 udc = to_gadget_udc(_gadget); 1668 udc = to_gadget_udc(_gadget);
1668 if (udc->transceiver) 1669 if (!IS_ERR_OR_NULL(udc->transceiver))
1669 return usb_phy_set_power(udc->transceiver, mA); 1670 return usb_phy_set_power(udc->transceiver, mA);
1670 return -EOPNOTSUPP; 1671 return -EOPNOTSUPP;
1671} 1672}
@@ -1834,7 +1835,7 @@ static int pxa27x_udc_start(struct usb_gadget_driver *driver,
1834 dev_dbg(udc->dev, "registered gadget driver '%s'\n", 1835 dev_dbg(udc->dev, "registered gadget driver '%s'\n",
1835 driver->driver.name); 1836 driver->driver.name);
1836 1837
1837 if (udc->transceiver) { 1838 if (!IS_ERR_OR_NULL(udc->transceiver)) {
1838 retval = otg_set_peripheral(udc->transceiver->otg, 1839 retval = otg_set_peripheral(udc->transceiver->otg,
1839 &udc->gadget); 1840 &udc->gadget);
1840 if (retval) { 1841 if (retval) {
@@ -1908,7 +1909,7 @@ static int pxa27x_udc_stop(struct usb_gadget_driver *driver)
1908 dev_info(udc->dev, "unregistered gadget driver '%s'\n", 1909 dev_info(udc->dev, "unregistered gadget driver '%s'\n",
1909 driver->driver.name); 1910 driver->driver.name);
1910 1911
1911 if (udc->transceiver) 1912 if (!IS_ERR_OR_NULL(udc->transceiver))
1912 return otg_set_peripheral(udc->transceiver->otg, NULL); 1913 return otg_set_peripheral(udc->transceiver->otg, NULL);
1913 return 0; 1914 return 0;
1914} 1915}
@@ -2464,7 +2465,7 @@ static int __init pxa_udc_probe(struct platform_device *pdev)
2464 2465
2465 udc->dev = &pdev->dev; 2466 udc->dev = &pdev->dev;
2466 udc->mach = pdev->dev.platform_data; 2467 udc->mach = pdev->dev.platform_data;
2467 udc->transceiver = usb_get_transceiver(); 2468 udc->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
2468 2469
2469 gpio = udc->mach->gpio_pullup; 2470 gpio = udc->mach->gpio_pullup;
2470 if (gpio_is_valid(gpio)) { 2471 if (gpio_is_valid(gpio)) {
@@ -2543,7 +2544,7 @@ static int __exit pxa_udc_remove(struct platform_device *_dev)
2543 if (gpio_is_valid(gpio)) 2544 if (gpio_is_valid(gpio))
2544 gpio_free(gpio); 2545 gpio_free(gpio);
2545 2546
2546 usb_put_transceiver(udc->transceiver); 2547 usb_put_phy(udc->transceiver);
2547 2548
2548 udc->transceiver = NULL; 2549 udc->transceiver = NULL;
2549 platform_set_drvdata(_dev, NULL); 2550 platform_set_drvdata(_dev, NULL);
diff --git a/drivers/usb/gadget/s3c-hsudc.c b/drivers/usb/gadget/s3c-hsudc.c
index 236b271871a0..e26a4e7ed2bf 100644
--- a/drivers/usb/gadget/s3c-hsudc.c
+++ b/drivers/usb/gadget/s3c-hsudc.c
@@ -24,6 +24,7 @@
24#include <linux/io.h> 24#include <linux/io.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/clk.h> 26#include <linux/clk.h>
27#include <linux/err.h>
27#include <linux/usb/ch9.h> 28#include <linux/usb/ch9.h>
28#include <linux/usb/gadget.h> 29#include <linux/usb/gadget.h>
29#include <linux/usb/otg.h> 30#include <linux/usb/otg.h>
@@ -1165,7 +1166,7 @@ static int s3c_hsudc_start(struct usb_gadget *gadget,
1165 } 1166 }
1166 1167
1167 /* connect to bus through transceiver */ 1168 /* connect to bus through transceiver */
1168 if (hsudc->transceiver) { 1169 if (!IS_ERR_OR_NULL(hsudc->transceiver)) {
1169 ret = otg_set_peripheral(hsudc->transceiver->otg, 1170 ret = otg_set_peripheral(hsudc->transceiver->otg,
1170 &hsudc->gadget); 1171 &hsudc->gadget);
1171 if (ret) { 1172 if (ret) {
@@ -1220,7 +1221,7 @@ static int s3c_hsudc_stop(struct usb_gadget *gadget,
1220 s3c_hsudc_stop_activity(hsudc); 1221 s3c_hsudc_stop_activity(hsudc);
1221 spin_unlock_irqrestore(&hsudc->lock, flags); 1222 spin_unlock_irqrestore(&hsudc->lock, flags);
1222 1223
1223 if (hsudc->transceiver) 1224 if (!IS_ERR_OR_NULL(hsudc->transceiver))
1224 (void) otg_set_peripheral(hsudc->transceiver->otg, NULL); 1225 (void) otg_set_peripheral(hsudc->transceiver->otg, NULL);
1225 1226
1226 disable_irq(hsudc->irq); 1227 disable_irq(hsudc->irq);
@@ -1249,7 +1250,7 @@ static int s3c_hsudc_vbus_draw(struct usb_gadget *gadget, unsigned mA)
1249 if (!hsudc) 1250 if (!hsudc)
1250 return -ENODEV; 1251 return -ENODEV;
1251 1252
1252 if (hsudc->transceiver) 1253 if (!IS_ERR_OR_NULL(hsudc->transceiver))
1253 return usb_phy_set_power(hsudc->transceiver, mA); 1254 return usb_phy_set_power(hsudc->transceiver, mA);
1254 1255
1255 return -EOPNOTSUPP; 1256 return -EOPNOTSUPP;
@@ -1282,7 +1283,7 @@ static int __devinit s3c_hsudc_probe(struct platform_device *pdev)
1282 hsudc->dev = dev; 1283 hsudc->dev = dev;
1283 hsudc->pd = pdev->dev.platform_data; 1284 hsudc->pd = pdev->dev.platform_data;
1284 1285
1285 hsudc->transceiver = usb_get_transceiver(); 1286 hsudc->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
1286 1287
1287 for (i = 0; i < ARRAY_SIZE(hsudc->supplies); i++) 1288 for (i = 0; i < ARRAY_SIZE(hsudc->supplies); i++)
1288 hsudc->supplies[i].supply = s3c_hsudc_supply_names[i]; 1289 hsudc->supplies[i].supply = s3c_hsudc_supply_names[i];
@@ -1385,8 +1386,8 @@ err_irq:
1385err_remap: 1386err_remap:
1386 release_mem_region(res->start, resource_size(res)); 1387 release_mem_region(res->start, resource_size(res));
1387err_res: 1388err_res:
1388 if (hsudc->transceiver) 1389 if (!IS_ERR_OR_NULL(hsudc->transceiver))
1389 usb_put_transceiver(hsudc->transceiver); 1390 usb_put_phy(hsudc->transceiver);
1390 1391
1391 regulator_bulk_free(ARRAY_SIZE(hsudc->supplies), hsudc->supplies); 1392 regulator_bulk_free(ARRAY_SIZE(hsudc->supplies), hsudc->supplies);
1392err_supplies: 1393err_supplies:
diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
index 3379945b095e..74914de8b9bf 100644
--- a/drivers/usb/host/ehci-fsl.c
+++ b/drivers/usb/host/ehci-fsl.c
@@ -27,6 +27,7 @@
27#include <linux/types.h> 27#include <linux/types.h>
28#include <linux/delay.h> 28#include <linux/delay.h>
29#include <linux/pm.h> 29#include <linux/pm.h>
30#include <linux/err.h>
30#include <linux/platform_device.h> 31#include <linux/platform_device.h>
31#include <linux/fsl_devices.h> 32#include <linux/fsl_devices.h>
32 33
@@ -142,15 +143,15 @@ static int usb_hcd_fsl_probe(const struct hc_driver *driver,
142 if (pdata->operating_mode == FSL_USB2_DR_OTG) { 143 if (pdata->operating_mode == FSL_USB2_DR_OTG) {
143 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 144 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
144 145
145 hcd->phy = usb_get_transceiver(); 146 hcd->phy = usb_get_phy(USB_PHY_TYPE_USB2);
146 dev_dbg(&pdev->dev, "hcd=0x%p ehci=0x%p, phy=0x%p\n", 147 dev_dbg(&pdev->dev, "hcd=0x%p ehci=0x%p, phy=0x%p\n",
147 hcd, ehci, hcd->phy); 148 hcd, ehci, hcd->phy);
148 149
149 if (hcd->phy) { 150 if (!IS_ERR_OR_NULL(hcd->phy)) {
150 retval = otg_set_host(hcd->phy->otg, 151 retval = otg_set_host(hcd->phy->otg,
151 &ehci_to_hcd(ehci)->self); 152 &ehci_to_hcd(ehci)->self);
152 if (retval) { 153 if (retval) {
153 usb_put_transceiver(hcd->phy); 154 usb_put_phy(hcd->phy);
154 goto err4; 155 goto err4;
155 } 156 }
156 } else { 157 } else {
@@ -191,9 +192,9 @@ static void usb_hcd_fsl_remove(struct usb_hcd *hcd,
191{ 192{
192 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data; 193 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
193 194
194 if (hcd->phy) { 195 if (!IS_ERR_OR_NULL(hcd->phy)) {
195 otg_set_host(hcd->phy->otg, NULL); 196 otg_set_host(hcd->phy->otg, NULL);
196 usb_put_transceiver(hcd->phy); 197 usb_put_phy(hcd->phy);
197 } 198 }
198 199
199 usb_remove_hcd(hcd); 200 usb_remove_hcd(hcd);
diff --git a/drivers/usb/host/ehci-msm.c b/drivers/usb/host/ehci-msm.c
index 9803a55fd5f4..6b4ffb598db1 100644
--- a/drivers/usb/host/ehci-msm.c
+++ b/drivers/usb/host/ehci-msm.c
@@ -145,8 +145,8 @@ static int ehci_msm_probe(struct platform_device *pdev)
145 * powering up VBUS, mapping of registers address space and power 145 * powering up VBUS, mapping of registers address space and power
146 * management. 146 * management.
147 */ 147 */
148 phy = usb_get_transceiver(); 148 phy = usb_get_phy(USB_PHY_TYPE_USB2);
149 if (!phy) { 149 if (IS_ERR_OR_NULL(phy)) {
150 dev_err(&pdev->dev, "unable to find transceiver\n"); 150 dev_err(&pdev->dev, "unable to find transceiver\n");
151 ret = -ENODEV; 151 ret = -ENODEV;
152 goto unmap; 152 goto unmap;
@@ -169,7 +169,7 @@ static int ehci_msm_probe(struct platform_device *pdev)
169 return 0; 169 return 0;
170 170
171put_transceiver: 171put_transceiver:
172 usb_put_transceiver(phy); 172 usb_put_phy(phy);
173unmap: 173unmap:
174 iounmap(hcd->regs); 174 iounmap(hcd->regs);
175put_hcd: 175put_hcd:
@@ -187,7 +187,7 @@ static int __devexit ehci_msm_remove(struct platform_device *pdev)
187 pm_runtime_set_suspended(&pdev->dev); 187 pm_runtime_set_suspended(&pdev->dev);
188 188
189 otg_set_host(phy->otg, NULL); 189 otg_set_host(phy->otg, NULL);
190 usb_put_transceiver(phy); 190 usb_put_phy(phy);
191 191
192 usb_put_hcd(hcd); 192 usb_put_hcd(hcd);
193 193
diff --git a/drivers/usb/host/ehci-mv.c b/drivers/usb/host/ehci-mv.c
index a936bbcff8f4..0e8c168ca24c 100644
--- a/drivers/usb/host/ehci-mv.c
+++ b/drivers/usb/host/ehci-mv.c
@@ -13,6 +13,7 @@
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/platform_device.h> 14#include <linux/platform_device.h>
15#include <linux/clk.h> 15#include <linux/clk.h>
16#include <linux/err.h>
16#include <linux/usb/otg.h> 17#include <linux/usb/otg.h>
17#include <linux/platform_data/mv_usb.h> 18#include <linux/platform_data/mv_usb.h>
18 19
@@ -253,8 +254,8 @@ static int mv_ehci_probe(struct platform_device *pdev)
253 ehci_mv->mode = pdata->mode; 254 ehci_mv->mode = pdata->mode;
254 if (ehci_mv->mode == MV_USB_MODE_OTG) { 255 if (ehci_mv->mode == MV_USB_MODE_OTG) {
255#ifdef CONFIG_USB_OTG_UTILS 256#ifdef CONFIG_USB_OTG_UTILS
256 ehci_mv->otg = usb_get_transceiver(); 257 ehci_mv->otg = usb_get_phy(USB_PHY_TYPE_USB2);
257 if (!ehci_mv->otg) { 258 if (IS_ERR_OR_NULL(ehci_mv->otg)) {
258 dev_err(&pdev->dev, 259 dev_err(&pdev->dev,
259 "unable to find transceiver\n"); 260 "unable to find transceiver\n");
260 retval = -ENODEV; 261 retval = -ENODEV;
@@ -302,8 +303,8 @@ err_set_vbus:
302 pdata->set_vbus(0); 303 pdata->set_vbus(0);
303#ifdef CONFIG_USB_OTG_UTILS 304#ifdef CONFIG_USB_OTG_UTILS
304err_put_transceiver: 305err_put_transceiver:
305 if (ehci_mv->otg) 306 if (!IS_ERR_OR_NULL(ehci_mv->otg))
306 usb_put_transceiver(ehci_mv->otg); 307 usb_put_phy(ehci_mv->otg);
307#endif 308#endif
308err_disable_clk: 309err_disable_clk:
309 mv_ehci_disable(ehci_mv); 310 mv_ehci_disable(ehci_mv);
@@ -331,9 +332,9 @@ static int mv_ehci_remove(struct platform_device *pdev)
331 if (hcd->rh_registered) 332 if (hcd->rh_registered)
332 usb_remove_hcd(hcd); 333 usb_remove_hcd(hcd);
333 334
334 if (ehci_mv->otg) { 335 if (!IS_ERR_OR_NULL(ehci_mv->otg)) {
335 otg_set_host(ehci_mv->otg->otg, NULL); 336 otg_set_host(ehci_mv->otg->otg, NULL);
336 usb_put_transceiver(ehci_mv->otg); 337 usb_put_phy(ehci_mv->otg);
337 } 338 }
338 339
339 if (ehci_mv->mode == MV_USB_MODE_HOST) { 340 if (ehci_mv->mode == MV_USB_MODE_HOST) {
diff --git a/drivers/usb/host/ehci-tegra.c b/drivers/usb/host/ehci-tegra.c
index 68548236ec42..477ecfa05154 100644
--- a/drivers/usb/host/ehci-tegra.c
+++ b/drivers/usb/host/ehci-tegra.c
@@ -17,6 +17,7 @@
17 */ 17 */
18 18
19#include <linux/clk.h> 19#include <linux/clk.h>
20#include <linux/err.h>
20#include <linux/platform_device.h> 21#include <linux/platform_device.h>
21#include <linux/platform_data/tegra_usb.h> 22#include <linux/platform_data/tegra_usb.h>
22#include <linux/irq.h> 23#include <linux/irq.h>
@@ -749,8 +750,8 @@ static int tegra_ehci_probe(struct platform_device *pdev)
749 750
750#ifdef CONFIG_USB_OTG_UTILS 751#ifdef CONFIG_USB_OTG_UTILS
751 if (pdata->operating_mode == TEGRA_USB_OTG) { 752 if (pdata->operating_mode == TEGRA_USB_OTG) {
752 tegra->transceiver = usb_get_transceiver(); 753 tegra->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
753 if (tegra->transceiver) 754 if (!IS_ERR_OR_NULL(tegra->transceiver))
754 otg_set_host(tegra->transceiver->otg, &hcd->self); 755 otg_set_host(tegra->transceiver->otg, &hcd->self);
755 } 756 }
756#endif 757#endif
@@ -773,9 +774,9 @@ static int tegra_ehci_probe(struct platform_device *pdev)
773 774
774fail: 775fail:
775#ifdef CONFIG_USB_OTG_UTILS 776#ifdef CONFIG_USB_OTG_UTILS
776 if (tegra->transceiver) { 777 if (!IS_ERR_OR_NULL(tegra->transceiver)) {
777 otg_set_host(tegra->transceiver->otg, NULL); 778 otg_set_host(tegra->transceiver->otg, NULL);
778 usb_put_transceiver(tegra->transceiver); 779 usb_put_phy(tegra->transceiver);
779 } 780 }
780#endif 781#endif
781 tegra_usb_phy_close(tegra->phy); 782 tegra_usb_phy_close(tegra->phy);
@@ -808,9 +809,9 @@ static int tegra_ehci_remove(struct platform_device *pdev)
808 pm_runtime_put_noidle(&pdev->dev); 809 pm_runtime_put_noidle(&pdev->dev);
809 810
810#ifdef CONFIG_USB_OTG_UTILS 811#ifdef CONFIG_USB_OTG_UTILS
811 if (tegra->transceiver) { 812 if (!IS_ERR_OR_NULL(tegra->transceiver)) {
812 otg_set_host(tegra->transceiver->otg, NULL); 813 otg_set_host(tegra->transceiver->otg, NULL);
813 usb_put_transceiver(tegra->transceiver); 814 usb_put_phy(tegra->transceiver);
814 } 815 }
815#endif 816#endif
816 817
diff --git a/drivers/usb/host/ohci-omap.c b/drivers/usb/host/ohci-omap.c
index eccddb461396..076d2018e6df 100644
--- a/drivers/usb/host/ohci-omap.c
+++ b/drivers/usb/host/ohci-omap.c
@@ -18,6 +18,7 @@
18#include <linux/jiffies.h> 18#include <linux/jiffies.h>
19#include <linux/platform_device.h> 19#include <linux/platform_device.h>
20#include <linux/clk.h> 20#include <linux/clk.h>
21#include <linux/err.h>
21#include <linux/gpio.h> 22#include <linux/gpio.h>
22 23
23#include <mach/hardware.h> 24#include <mach/hardware.h>
@@ -212,14 +213,14 @@ static int ohci_omap_init(struct usb_hcd *hcd)
212 213
213#ifdef CONFIG_USB_OTG 214#ifdef CONFIG_USB_OTG
214 if (need_transceiver) { 215 if (need_transceiver) {
215 hcd->phy = usb_get_transceiver(); 216 hcd->phy = usb_get_phy(USB_PHY_TYPE_USB2);
216 if (hcd->phy) { 217 if (!IS_ERR_OR_NULL(hcd->phy)) {
217 int status = otg_set_host(hcd->phy->otg, 218 int status = otg_set_host(hcd->phy->otg,
218 &ohci_to_hcd(ohci)->self); 219 &ohci_to_hcd(ohci)->self);
219 dev_dbg(hcd->self.controller, "init %s phy, status %d\n", 220 dev_dbg(hcd->self.controller, "init %s phy, status %d\n",
220 hcd->phy->label, status); 221 hcd->phy->label, status);
221 if (status) { 222 if (status) {
222 usb_put_transceiver(hcd->phy); 223 usb_put_phy(hcd->phy);
223 return status; 224 return status;
224 } 225 }
225 } else { 226 } else {
@@ -404,9 +405,9 @@ usb_hcd_omap_remove (struct usb_hcd *hcd, struct platform_device *pdev)
404 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 405 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
405 406
406 usb_remove_hcd(hcd); 407 usb_remove_hcd(hcd);
407 if (hcd->phy) { 408 if (!IS_ERR_OR_NULL(hcd->phy)) {
408 (void) otg_set_host(hcd->phy->otg, 0); 409 (void) otg_set_host(hcd->phy->otg, 0);
409 usb_put_transceiver(hcd->phy); 410 usb_put_phy(hcd->phy);
410 } 411 }
411 if (machine_is_omap_osk()) 412 if (machine_is_omap_osk())
412 gpio_free(9); 413 gpio_free(9);
diff --git a/drivers/usb/musb/am35x.c b/drivers/usb/musb/am35x.c
index 9f3eda91ea4d..7a95ab87ac00 100644
--- a/drivers/usb/musb/am35x.c
+++ b/drivers/usb/musb/am35x.c
@@ -29,6 +29,7 @@
29#include <linux/init.h> 29#include <linux/init.h>
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/clk.h> 31#include <linux/clk.h>
32#include <linux/err.h>
32#include <linux/io.h> 33#include <linux/io.h>
33#include <linux/platform_device.h> 34#include <linux/platform_device.h>
34#include <linux/dma-mapping.h> 35#include <linux/dma-mapping.h>
@@ -364,8 +365,8 @@ static int am35x_musb_init(struct musb *musb)
364 return -ENODEV; 365 return -ENODEV;
365 366
366 usb_nop_xceiv_register(); 367 usb_nop_xceiv_register();
367 musb->xceiv = usb_get_transceiver(); 368 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
368 if (!musb->xceiv) 369 if (IS_ERR_OR_NULL(musb->xceiv))
369 return -ENODEV; 370 return -ENODEV;
370 371
371 if (is_host_enabled(musb)) 372 if (is_host_enabled(musb))
@@ -406,7 +407,7 @@ static int am35x_musb_exit(struct musb *musb)
406 if (data->set_phy_power) 407 if (data->set_phy_power)
407 data->set_phy_power(0); 408 data->set_phy_power(0);
408 409
409 usb_put_transceiver(musb->xceiv); 410 usb_put_phy(musb->xceiv);
410 usb_nop_xceiv_unregister(); 411 usb_nop_xceiv_unregister();
411 412
412 return 0; 413 return 0;
diff --git a/drivers/usb/musb/blackfin.c b/drivers/usb/musb/blackfin.c
index a087ed6c3be9..428e6aa3e78a 100644
--- a/drivers/usb/musb/blackfin.c
+++ b/drivers/usb/musb/blackfin.c
@@ -15,6 +15,7 @@
15#include <linux/list.h> 15#include <linux/list.h>
16#include <linux/gpio.h> 16#include <linux/gpio.h>
17#include <linux/io.h> 17#include <linux/io.h>
18#include <linux/err.h>
18#include <linux/platform_device.h> 19#include <linux/platform_device.h>
19#include <linux/dma-mapping.h> 20#include <linux/dma-mapping.h>
20#include <linux/prefetch.h> 21#include <linux/prefetch.h>
@@ -415,8 +416,8 @@ static int bfin_musb_init(struct musb *musb)
415 gpio_direction_output(musb->config->gpio_vrsel, 0); 416 gpio_direction_output(musb->config->gpio_vrsel, 0);
416 417
417 usb_nop_xceiv_register(); 418 usb_nop_xceiv_register();
418 musb->xceiv = usb_get_transceiver(); 419 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
419 if (!musb->xceiv) { 420 if (IS_ERR_OR_NULL(musb->xceiv)) {
420 gpio_free(musb->config->gpio_vrsel); 421 gpio_free(musb->config->gpio_vrsel);
421 return -ENODEV; 422 return -ENODEV;
422 } 423 }
@@ -440,7 +441,7 @@ static int bfin_musb_exit(struct musb *musb)
440{ 441{
441 gpio_free(musb->config->gpio_vrsel); 442 gpio_free(musb->config->gpio_vrsel);
442 443
443 usb_put_transceiver(musb->xceiv); 444 usb_put_phy(musb->xceiv);
444 usb_nop_xceiv_unregister(); 445 usb_nop_xceiv_unregister();
445 return 0; 446 return 0;
446} 447}
diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 8bd9566f3fbb..0f9fcec4e1d3 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -29,6 +29,7 @@
29#include <linux/init.h> 29#include <linux/init.h>
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/clk.h> 31#include <linux/clk.h>
32#include <linux/err.h>
32#include <linux/io.h> 33#include <linux/io.h>
33#include <linux/platform_device.h> 34#include <linux/platform_device.h>
34#include <linux/dma-mapping.h> 35#include <linux/dma-mapping.h>
@@ -425,8 +426,8 @@ static int da8xx_musb_init(struct musb *musb)
425 goto fail; 426 goto fail;
426 427
427 usb_nop_xceiv_register(); 428 usb_nop_xceiv_register();
428 musb->xceiv = usb_get_transceiver(); 429 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
429 if (!musb->xceiv) 430 if (IS_ERR_OR_NULL(musb->xceiv))
430 goto fail; 431 goto fail;
431 432
432 if (is_host_enabled(musb)) 433 if (is_host_enabled(musb))
@@ -458,7 +459,7 @@ static int da8xx_musb_exit(struct musb *musb)
458 459
459 phy_off(); 460 phy_off();
460 461
461 usb_put_transceiver(musb->xceiv); 462 usb_put_phy(musb->xceiv);
462 usb_nop_xceiv_unregister(); 463 usb_nop_xceiv_unregister();
463 464
464 return 0; 465 return 0;
diff --git a/drivers/usb/musb/davinci.c b/drivers/usb/musb/davinci.c
index 9d63ba4d10d6..472c8b42d38b 100644
--- a/drivers/usb/musb/davinci.c
+++ b/drivers/usb/musb/davinci.c
@@ -28,6 +28,7 @@
28#include <linux/list.h> 28#include <linux/list.h>
29#include <linux/delay.h> 29#include <linux/delay.h>
30#include <linux/clk.h> 30#include <linux/clk.h>
31#include <linux/err.h>
31#include <linux/io.h> 32#include <linux/io.h>
32#include <linux/gpio.h> 33#include <linux/gpio.h>
33#include <linux/platform_device.h> 34#include <linux/platform_device.h>
@@ -385,8 +386,8 @@ static int davinci_musb_init(struct musb *musb)
385 u32 revision; 386 u32 revision;
386 387
387 usb_nop_xceiv_register(); 388 usb_nop_xceiv_register();
388 musb->xceiv = usb_get_transceiver(); 389 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
389 if (!musb->xceiv) 390 if (IS_ERR_OR_NULL(musb->xceiv))
390 goto unregister; 391 goto unregister;
391 392
392 musb->mregs += DAVINCI_BASE_OFFSET; 393 musb->mregs += DAVINCI_BASE_OFFSET;
@@ -444,7 +445,7 @@ static int davinci_musb_init(struct musb *musb)
444 return 0; 445 return 0;
445 446
446fail: 447fail:
447 usb_put_transceiver(musb->xceiv); 448 usb_put_phy(musb->xceiv);
448unregister: 449unregister:
449 usb_nop_xceiv_unregister(); 450 usb_nop_xceiv_unregister();
450 return -ENODEV; 451 return -ENODEV;
@@ -494,7 +495,7 @@ static int davinci_musb_exit(struct musb *musb)
494 495
495 phy_off(); 496 phy_off();
496 497
497 usb_put_transceiver(musb->xceiv); 498 usb_put_phy(musb->xceiv);
498 usb_nop_xceiv_unregister(); 499 usb_nop_xceiv_unregister();
499 500
500 return 0; 501 return 0;
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index db3dff854b71..26f1befb4896 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -1909,7 +1909,7 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
1909 /* The musb_platform_init() call: 1909 /* The musb_platform_init() call:
1910 * - adjusts musb->mregs and musb->isr if needed, 1910 * - adjusts musb->mregs and musb->isr if needed,
1911 * - may initialize an integrated tranceiver 1911 * - may initialize an integrated tranceiver
1912 * - initializes musb->xceiv, usually by otg_get_transceiver() 1912 * - initializes musb->xceiv, usually by otg_get_phy()
1913 * - stops powering VBUS 1913 * - stops powering VBUS
1914 * 1914 *
1915 * There are various transceiver configurations. Blackfin, 1915 * There are various transceiver configurations. Blackfin,
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index f4a40f001c88..dbcdeea30f09 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -327,7 +327,6 @@ struct musb {
327 327
328 irqreturn_t (*isr)(int, void *); 328 irqreturn_t (*isr)(int, void *);
329 struct work_struct irq_work; 329 struct work_struct irq_work;
330 struct work_struct otg_notifier_work;
331 u16 hwvers; 330 u16 hwvers;
332 331
333/* this hub status bit is reserved by USB 2.0 and not seen by usbcore */ 332/* this hub status bit is reserved by USB 2.0 and not seen by usbcore */
@@ -373,7 +372,6 @@ struct musb {
373 u16 int_tx; 372 u16 int_tx;
374 373
375 struct usb_phy *xceiv; 374 struct usb_phy *xceiv;
376 u8 xceiv_event;
377 375
378 int nIrq; 376 int nIrq;
379 unsigned irq_wake:1; 377 unsigned irq_wake:1;
diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c
index 23db42db761a..217808d9fbe1 100644
--- a/drivers/usb/musb/musb_dsps.c
+++ b/drivers/usb/musb/musb_dsps.c
@@ -31,6 +31,7 @@
31 31
32#include <linux/init.h> 32#include <linux/init.h>
33#include <linux/io.h> 33#include <linux/io.h>
34#include <linux/err.h>
34#include <linux/platform_device.h> 35#include <linux/platform_device.h>
35#include <linux/dma-mapping.h> 36#include <linux/dma-mapping.h>
36#include <linux/pm_runtime.h> 37#include <linux/pm_runtime.h>
@@ -376,8 +377,8 @@ static int dsps_musb_init(struct musb *musb)
376 377
377 /* NOP driver needs change if supporting dual instance */ 378 /* NOP driver needs change if supporting dual instance */
378 usb_nop_xceiv_register(); 379 usb_nop_xceiv_register();
379 musb->xceiv = usb_get_transceiver(); 380 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
380 if (!musb->xceiv) 381 if (IS_ERR_OR_NULL(musb->xceiv))
381 return -ENODEV; 382 return -ENODEV;
382 383
383 /* Returns zero if e.g. not clocked */ 384 /* Returns zero if e.g. not clocked */
@@ -409,7 +410,7 @@ static int dsps_musb_init(struct musb *musb)
409 410
410 return 0; 411 return 0;
411err0: 412err0:
412 usb_put_transceiver(musb->xceiv); 413 usb_put_phy(musb->xceiv);
413 usb_nop_xceiv_unregister(); 414 usb_nop_xceiv_unregister();
414 return status; 415 return status;
415} 416}
@@ -430,7 +431,7 @@ static int dsps_musb_exit(struct musb *musb)
430 data->set_phy_power(0); 431 data->set_phy_power(0);
431 432
432 /* NOP driver needs change if supporting dual instance */ 433 /* NOP driver needs change if supporting dual instance */
433 usb_put_transceiver(musb->xceiv); 434 usb_put_phy(musb->xceiv);
434 usb_nop_xceiv_unregister(); 435 usb_nop_xceiv_unregister();
435 436
436 return 0; 437 return 0;
diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index c7785e81254c..5fdb9da8dd56 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -34,6 +34,7 @@
34#include <linux/dma-mapping.h> 34#include <linux/dma-mapping.h>
35#include <linux/pm_runtime.h> 35#include <linux/pm_runtime.h>
36#include <linux/err.h> 36#include <linux/err.h>
37#include <linux/usb/musb-omap.h>
37 38
38#include "musb_core.h" 39#include "musb_core.h"
39#include "omap2430.h" 40#include "omap2430.h"
@@ -41,9 +42,13 @@
41struct omap2430_glue { 42struct omap2430_glue {
42 struct device *dev; 43 struct device *dev;
43 struct platform_device *musb; 44 struct platform_device *musb;
45 enum omap_musb_vbus_id_status status;
46 struct work_struct omap_musb_mailbox_work;
44}; 47};
45#define glue_to_musb(g) platform_get_drvdata(g->musb) 48#define glue_to_musb(g) platform_get_drvdata(g->musb)
46 49
50struct omap2430_glue *_glue;
51
47static struct timer_list musb_idle_timer; 52static struct timer_list musb_idle_timer;
48 53
49static void musb_do_idle(unsigned long _musb) 54static void musb_do_idle(unsigned long _musb)
@@ -223,50 +228,63 @@ static inline void omap2430_low_level_init(struct musb *musb)
223 musb_writel(musb->mregs, OTG_FORCESTDBY, l); 228 musb_writel(musb->mregs, OTG_FORCESTDBY, l);
224} 229}
225 230
226static int musb_otg_notifications(struct notifier_block *nb, 231void omap_musb_mailbox(enum omap_musb_vbus_id_status status)
227 unsigned long event, void *unused)
228{ 232{
229 struct musb *musb = container_of(nb, struct musb, nb); 233 struct omap2430_glue *glue = _glue;
234 struct musb *musb = glue_to_musb(glue);
230 235
231 musb->xceiv_event = event; 236 glue->status = status;
232 schedule_work(&musb->otg_notifier_work); 237 if (!musb) {
238 dev_err(glue->dev, "musb core is not yet ready\n");
239 return;
240 }
233 241
234 return NOTIFY_OK; 242 schedule_work(&glue->omap_musb_mailbox_work);
235} 243}
244EXPORT_SYMBOL_GPL(omap_musb_mailbox);
236 245
237static void musb_otg_notifier_work(struct work_struct *data_notifier_work) 246static void omap_musb_set_mailbox(struct omap2430_glue *glue)
238{ 247{
239 struct musb *musb = container_of(data_notifier_work, struct musb, otg_notifier_work); 248 struct musb *musb = glue_to_musb(glue);
240 struct device *dev = musb->controller; 249 struct device *dev = musb->controller;
241 struct musb_hdrc_platform_data *pdata = dev->platform_data; 250 struct musb_hdrc_platform_data *pdata = dev->platform_data;
242 struct omap_musb_board_data *data = pdata->board_data; 251 struct omap_musb_board_data *data = pdata->board_data;
252 struct usb_otg *otg = musb->xceiv->otg;
243 253
244 switch (musb->xceiv_event) { 254 switch (glue->status) {
245 case USB_EVENT_ID: 255 case OMAP_MUSB_ID_GROUND:
246 dev_dbg(musb->controller, "ID GND\n"); 256 dev_dbg(dev, "ID GND\n");
247 257
258 otg->default_a = true;
259 musb->xceiv->state = OTG_STATE_A_IDLE;
260 musb->xceiv->last_event = USB_EVENT_ID;
248 if (!is_otg_enabled(musb) || musb->gadget_driver) { 261 if (!is_otg_enabled(musb) || musb->gadget_driver) {
249 pm_runtime_get_sync(musb->controller); 262 pm_runtime_get_sync(dev);
250 usb_phy_init(musb->xceiv); 263 usb_phy_init(musb->xceiv);
251 omap2430_musb_set_vbus(musb, 1); 264 omap2430_musb_set_vbus(musb, 1);
252 } 265 }
253 break; 266 break;
254 267
255 case USB_EVENT_VBUS: 268 case OMAP_MUSB_VBUS_VALID:
256 dev_dbg(musb->controller, "VBUS Connect\n"); 269 dev_dbg(dev, "VBUS Connect\n");
257 270
271 otg->default_a = false;
272 musb->xceiv->state = OTG_STATE_B_IDLE;
273 musb->xceiv->last_event = USB_EVENT_VBUS;
258 if (musb->gadget_driver) 274 if (musb->gadget_driver)
259 pm_runtime_get_sync(musb->controller); 275 pm_runtime_get_sync(dev);
260 usb_phy_init(musb->xceiv); 276 usb_phy_init(musb->xceiv);
261 break; 277 break;
262 278
263 case USB_EVENT_NONE: 279 case OMAP_MUSB_ID_FLOAT:
264 dev_dbg(musb->controller, "VBUS Disconnect\n"); 280 case OMAP_MUSB_VBUS_OFF:
281 dev_dbg(dev, "VBUS Disconnect\n");
265 282
283 musb->xceiv->last_event = USB_EVENT_NONE;
266 if (is_otg_enabled(musb) || is_peripheral_enabled(musb)) 284 if (is_otg_enabled(musb) || is_peripheral_enabled(musb))
267 if (musb->gadget_driver) { 285 if (musb->gadget_driver) {
268 pm_runtime_mark_last_busy(musb->controller); 286 pm_runtime_mark_last_busy(dev);
269 pm_runtime_put_autosuspend(musb->controller); 287 pm_runtime_put_autosuspend(dev);
270 } 288 }
271 289
272 if (data->interface_type == MUSB_INTERFACE_UTMI) { 290 if (data->interface_type == MUSB_INTERFACE_UTMI) {
@@ -276,15 +294,24 @@ static void musb_otg_notifier_work(struct work_struct *data_notifier_work)
276 usb_phy_shutdown(musb->xceiv); 294 usb_phy_shutdown(musb->xceiv);
277 break; 295 break;
278 default: 296 default:
279 dev_dbg(musb->controller, "ID float\n"); 297 dev_dbg(dev, "ID float\n");
280 } 298 }
281} 299}
282 300
301
302static void omap_musb_mailbox_work(struct work_struct *mailbox_work)
303{
304 struct omap2430_glue *glue = container_of(mailbox_work,
305 struct omap2430_glue, omap_musb_mailbox_work);
306 omap_musb_set_mailbox(glue);
307}
308
283static int omap2430_musb_init(struct musb *musb) 309static int omap2430_musb_init(struct musb *musb)
284{ 310{
285 u32 l; 311 u32 l;
286 int status = 0; 312 int status = 0;
287 struct device *dev = musb->controller; 313 struct device *dev = musb->controller;
314 struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
288 struct musb_hdrc_platform_data *plat = dev->platform_data; 315 struct musb_hdrc_platform_data *plat = dev->platform_data;
289 struct omap_musb_board_data *data = plat->board_data; 316 struct omap_musb_board_data *data = plat->board_data;
290 317
@@ -292,14 +319,12 @@ static int omap2430_musb_init(struct musb *musb)
292 * up through ULPI. TWL4030-family PMICs include one, 319 * up through ULPI. TWL4030-family PMICs include one,
293 * which needs a driver, drivers aren't always needed. 320 * which needs a driver, drivers aren't always needed.
294 */ 321 */
295 musb->xceiv = usb_get_transceiver(); 322 musb->xceiv = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2);
296 if (!musb->xceiv) { 323 if (IS_ERR_OR_NULL(musb->xceiv)) {
297 pr_err("HS USB OTG: no transceiver configured\n"); 324 pr_err("HS USB OTG: no transceiver configured\n");
298 return -ENODEV; 325 return -ENODEV;
299 } 326 }
300 327
301 INIT_WORK(&musb->otg_notifier_work, musb_otg_notifier_work);
302
303 status = pm_runtime_get_sync(dev); 328 status = pm_runtime_get_sync(dev);
304 if (status < 0) { 329 if (status < 0) {
305 dev_err(dev, "pm_runtime_get_sync FAILED %d\n", status); 330 dev_err(dev, "pm_runtime_get_sync FAILED %d\n", status);
@@ -326,14 +351,11 @@ static int omap2430_musb_init(struct musb *musb)
326 musb_readl(musb->mregs, OTG_INTERFSEL), 351 musb_readl(musb->mregs, OTG_INTERFSEL),
327 musb_readl(musb->mregs, OTG_SIMENABLE)); 352 musb_readl(musb->mregs, OTG_SIMENABLE));
328 353
329 musb->nb.notifier_call = musb_otg_notifications;
330 status = usb_register_notifier(musb->xceiv, &musb->nb);
331
332 if (status)
333 dev_dbg(musb->controller, "notification register failed\n");
334
335 setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb); 354 setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb);
336 355
356 if (glue->status != OMAP_MUSB_UNKNOWN)
357 omap_musb_set_mailbox(glue);
358
337 pm_runtime_put_noidle(musb->controller); 359 pm_runtime_put_noidle(musb->controller);
338 return 0; 360 return 0;
339 361
@@ -346,12 +368,13 @@ static void omap2430_musb_enable(struct musb *musb)
346 u8 devctl; 368 u8 devctl;
347 unsigned long timeout = jiffies + msecs_to_jiffies(1000); 369 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
348 struct device *dev = musb->controller; 370 struct device *dev = musb->controller;
371 struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
349 struct musb_hdrc_platform_data *pdata = dev->platform_data; 372 struct musb_hdrc_platform_data *pdata = dev->platform_data;
350 struct omap_musb_board_data *data = pdata->board_data; 373 struct omap_musb_board_data *data = pdata->board_data;
351 374
352 switch (musb->xceiv->last_event) { 375 switch (glue->status) {
353 376
354 case USB_EVENT_ID: 377 case OMAP_MUSB_ID_GROUND:
355 usb_phy_init(musb->xceiv); 378 usb_phy_init(musb->xceiv);
356 if (data->interface_type != MUSB_INTERFACE_UTMI) 379 if (data->interface_type != MUSB_INTERFACE_UTMI)
357 break; 380 break;
@@ -370,7 +393,7 @@ static void omap2430_musb_enable(struct musb *musb)
370 } 393 }
371 break; 394 break;
372 395
373 case USB_EVENT_VBUS: 396 case OMAP_MUSB_VBUS_VALID:
374 usb_phy_init(musb->xceiv); 397 usb_phy_init(musb->xceiv);
375 break; 398 break;
376 399
@@ -381,17 +404,18 @@ static void omap2430_musb_enable(struct musb *musb)
381 404
382static void omap2430_musb_disable(struct musb *musb) 405static void omap2430_musb_disable(struct musb *musb)
383{ 406{
384 if (musb->xceiv->last_event) 407 struct device *dev = musb->controller;
408 struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
409
410 if (glue->status != OMAP_MUSB_UNKNOWN)
385 usb_phy_shutdown(musb->xceiv); 411 usb_phy_shutdown(musb->xceiv);
386} 412}
387 413
388static int omap2430_musb_exit(struct musb *musb) 414static int omap2430_musb_exit(struct musb *musb)
389{ 415{
390 del_timer_sync(&musb_idle_timer); 416 del_timer_sync(&musb_idle_timer);
391 cancel_work_sync(&musb->otg_notifier_work);
392 417
393 omap2430_low_level_exit(musb); 418 omap2430_low_level_exit(musb);
394 usb_put_transceiver(musb->xceiv);
395 419
396 return 0; 420 return 0;
397} 421}
@@ -418,7 +442,7 @@ static int __devinit omap2430_probe(struct platform_device *pdev)
418 struct omap2430_glue *glue; 442 struct omap2430_glue *glue;
419 int ret = -ENOMEM; 443 int ret = -ENOMEM;
420 444
421 glue = kzalloc(sizeof(*glue), GFP_KERNEL); 445 glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL);
422 if (!glue) { 446 if (!glue) {
423 dev_err(&pdev->dev, "failed to allocate glue context\n"); 447 dev_err(&pdev->dev, "failed to allocate glue context\n");
424 goto err0; 448 goto err0;
@@ -427,7 +451,7 @@ static int __devinit omap2430_probe(struct platform_device *pdev)
427 musb = platform_device_alloc("musb-hdrc", -1); 451 musb = platform_device_alloc("musb-hdrc", -1);
428 if (!musb) { 452 if (!musb) {
429 dev_err(&pdev->dev, "failed to allocate musb device\n"); 453 dev_err(&pdev->dev, "failed to allocate musb device\n");
430 goto err1; 454 goto err0;
431 } 455 }
432 456
433 musb->dev.parent = &pdev->dev; 457 musb->dev.parent = &pdev->dev;
@@ -436,22 +460,31 @@ static int __devinit omap2430_probe(struct platform_device *pdev)
436 460
437 glue->dev = &pdev->dev; 461 glue->dev = &pdev->dev;
438 glue->musb = musb; 462 glue->musb = musb;
463 glue->status = OMAP_MUSB_UNKNOWN;
439 464
440 pdata->platform_ops = &omap2430_ops; 465 pdata->platform_ops = &omap2430_ops;
441 466
442 platform_set_drvdata(pdev, glue); 467 platform_set_drvdata(pdev, glue);
443 468
469 /*
470 * REVISIT if we ever have two instances of the wrapper, we will be
471 * in big trouble
472 */
473 _glue = glue;
474
475 INIT_WORK(&glue->omap_musb_mailbox_work, omap_musb_mailbox_work);
476
444 ret = platform_device_add_resources(musb, pdev->resource, 477 ret = platform_device_add_resources(musb, pdev->resource,
445 pdev->num_resources); 478 pdev->num_resources);
446 if (ret) { 479 if (ret) {
447 dev_err(&pdev->dev, "failed to add resources\n"); 480 dev_err(&pdev->dev, "failed to add resources\n");
448 goto err2; 481 goto err1;
449 } 482 }
450 483
451 ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); 484 ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
452 if (ret) { 485 if (ret) {
453 dev_err(&pdev->dev, "failed to add platform_data\n"); 486 dev_err(&pdev->dev, "failed to add platform_data\n");
454 goto err2; 487 goto err1;
455 } 488 }
456 489
457 pm_runtime_enable(&pdev->dev); 490 pm_runtime_enable(&pdev->dev);
@@ -459,16 +492,13 @@ static int __devinit omap2430_probe(struct platform_device *pdev)
459 ret = platform_device_add(musb); 492 ret = platform_device_add(musb);
460 if (ret) { 493 if (ret) {
461 dev_err(&pdev->dev, "failed to register musb device\n"); 494 dev_err(&pdev->dev, "failed to register musb device\n");
462 goto err2; 495 goto err1;
463 } 496 }
464 497
465 return 0; 498 return 0;
466 499
467err2:
468 platform_device_put(musb);
469
470err1: 500err1:
471 kfree(glue); 501 platform_device_put(musb);
472 502
473err0: 503err0:
474 return ret; 504 return ret;
@@ -478,9 +508,9 @@ static int __devexit omap2430_remove(struct platform_device *pdev)
478{ 508{
479 struct omap2430_glue *glue = platform_get_drvdata(pdev); 509 struct omap2430_glue *glue = platform_get_drvdata(pdev);
480 510
511 cancel_work_sync(&glue->omap_musb_mailbox_work);
481 platform_device_del(glue->musb); 512 platform_device_del(glue->musb);
482 platform_device_put(glue->musb); 513 platform_device_put(glue->musb);
483 kfree(glue);
484 514
485 return 0; 515 return 0;
486} 516}
@@ -546,7 +576,7 @@ static int __init omap2430_init(void)
546{ 576{
547 return platform_driver_register(&omap2430_driver); 577 return platform_driver_register(&omap2430_driver);
548} 578}
549module_init(omap2430_init); 579subsys_initcall(omap2430_init);
550 580
551static void __exit omap2430_exit(void) 581static void __exit omap2430_exit(void)
552{ 582{
diff --git a/drivers/usb/musb/tusb6010.c b/drivers/usb/musb/tusb6010.c
index de1355946a83..1a1bd9cf40c5 100644
--- a/drivers/usb/musb/tusb6010.c
+++ b/drivers/usb/musb/tusb6010.c
@@ -17,6 +17,7 @@
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/errno.h> 19#include <linux/errno.h>
20#include <linux/err.h>
20#include <linux/init.h> 21#include <linux/init.h>
21#include <linux/prefetch.h> 22#include <linux/prefetch.h>
22#include <linux/usb.h> 23#include <linux/usb.h>
@@ -1078,8 +1079,8 @@ static int tusb_musb_init(struct musb *musb)
1078 int ret; 1079 int ret;
1079 1080
1080 usb_nop_xceiv_register(); 1081 usb_nop_xceiv_register();
1081 musb->xceiv = usb_get_transceiver(); 1082 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
1082 if (!musb->xceiv) 1083 if (IS_ERR_OR_NULL(musb->xceiv))
1083 return -ENODEV; 1084 return -ENODEV;
1084 1085
1085 pdev = to_platform_device(musb->controller); 1086 pdev = to_platform_device(musb->controller);
@@ -1130,7 +1131,7 @@ done:
1130 if (sync) 1131 if (sync)
1131 iounmap(sync); 1132 iounmap(sync);
1132 1133
1133 usb_put_transceiver(musb->xceiv); 1134 usb_put_phy(musb->xceiv);
1134 usb_nop_xceiv_unregister(); 1135 usb_nop_xceiv_unregister();
1135 } 1136 }
1136 return ret; 1137 return ret;
@@ -1146,7 +1147,7 @@ static int tusb_musb_exit(struct musb *musb)
1146 1147
1147 iounmap(musb->sync_va); 1148 iounmap(musb->sync_va);
1148 1149
1149 usb_put_transceiver(musb->xceiv); 1150 usb_put_phy(musb->xceiv);
1150 usb_nop_xceiv_unregister(); 1151 usb_nop_xceiv_unregister();
1151 return 0; 1152 return 0;
1152} 1153}
diff --git a/drivers/usb/musb/ux500.c b/drivers/usb/musb/ux500.c
index aa09dd417b94..a8c0fadce1b0 100644
--- a/drivers/usb/musb/ux500.c
+++ b/drivers/usb/musb/ux500.c
@@ -23,6 +23,7 @@
23#include <linux/kernel.h> 23#include <linux/kernel.h>
24#include <linux/init.h> 24#include <linux/init.h>
25#include <linux/clk.h> 25#include <linux/clk.h>
26#include <linux/err.h>
26#include <linux/io.h> 27#include <linux/io.h>
27#include <linux/platform_device.h> 28#include <linux/platform_device.h>
28 29
@@ -37,8 +38,8 @@ struct ux500_glue {
37 38
38static int ux500_musb_init(struct musb *musb) 39static int ux500_musb_init(struct musb *musb)
39{ 40{
40 musb->xceiv = usb_get_transceiver(); 41 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
41 if (!musb->xceiv) { 42 if (IS_ERR_OR_NULL(musb->xceiv)) {
42 pr_err("HS USB OTG: no transceiver configured\n"); 43 pr_err("HS USB OTG: no transceiver configured\n");
43 return -ENODEV; 44 return -ENODEV;
44 } 45 }
@@ -48,7 +49,7 @@ static int ux500_musb_init(struct musb *musb)
48 49
49static int ux500_musb_exit(struct musb *musb) 50static int ux500_musb_exit(struct musb *musb)
50{ 51{
51 usb_put_transceiver(musb->xceiv); 52 usb_put_phy(musb->xceiv);
52 53
53 return 0; 54 return 0;
54} 55}
diff --git a/drivers/usb/otg/ab8500-usb.c b/drivers/usb/otg/ab8500-usb.c
index a84af677dc59..ae8ad561f083 100644
--- a/drivers/usb/otg/ab8500-usb.c
+++ b/drivers/usb/otg/ab8500-usb.c
@@ -529,7 +529,7 @@ static int __devinit ab8500_usb_probe(struct platform_device *pdev)
529 if (err < 0) 529 if (err < 0)
530 goto fail0; 530 goto fail0;
531 531
532 err = usb_set_transceiver(&ab->phy); 532 err = usb_add_phy(&ab->phy, USB_PHY_TYPE_USB2);
533 if (err) { 533 if (err) {
534 dev_err(&pdev->dev, "Can't register transceiver\n"); 534 dev_err(&pdev->dev, "Can't register transceiver\n");
535 goto fail1; 535 goto fail1;
@@ -556,7 +556,7 @@ static int __devexit ab8500_usb_remove(struct platform_device *pdev)
556 556
557 cancel_work_sync(&ab->phy_dis_work); 557 cancel_work_sync(&ab->phy_dis_work);
558 558
559 usb_set_transceiver(NULL); 559 usb_remove_phy(&ab->phy);
560 560
561 ab8500_usb_host_phy_dis(ab); 561 ab8500_usb_host_phy_dis(ab);
562 ab8500_usb_peri_phy_dis(ab); 562 ab8500_usb_peri_phy_dis(ab);
diff --git a/drivers/usb/otg/fsl_otg.c b/drivers/usb/otg/fsl_otg.c
index be4a63e8302f..23c798cb2d7f 100644
--- a/drivers/usb/otg/fsl_otg.c
+++ b/drivers/usb/otg/fsl_otg.c
@@ -806,7 +806,7 @@ static int fsl_otg_conf(struct platform_device *pdev)
806 fsl_otg_dev = fsl_otg_tc; 806 fsl_otg_dev = fsl_otg_tc;
807 807
808 /* Store the otg transceiver */ 808 /* Store the otg transceiver */
809 status = usb_set_transceiver(&fsl_otg_tc->phy); 809 status = usb_add_phy(&fsl_otg_tc->phy, USB_PHY_TYPE_USB2);
810 if (status) { 810 if (status) {
811 pr_warn(FSL_OTG_NAME ": unable to register OTG transceiver.\n"); 811 pr_warn(FSL_OTG_NAME ": unable to register OTG transceiver.\n");
812 goto err; 812 goto err;
@@ -824,7 +824,7 @@ err:
824int usb_otg_start(struct platform_device *pdev) 824int usb_otg_start(struct platform_device *pdev)
825{ 825{
826 struct fsl_otg *p_otg; 826 struct fsl_otg *p_otg;
827 struct usb_phy *otg_trans = usb_get_transceiver(); 827 struct usb_phy *otg_trans = usb_get_phy(USB_PHY_TYPE_USB2);
828 struct otg_fsm *fsm; 828 struct otg_fsm *fsm;
829 int status; 829 int status;
830 struct resource *res; 830 struct resource *res;
@@ -1134,7 +1134,7 @@ static int __devexit fsl_otg_remove(struct platform_device *pdev)
1134{ 1134{
1135 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data; 1135 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
1136 1136
1137 usb_set_transceiver(NULL); 1137 usb_remove_phy(&fsl_otg_dev->phy);
1138 free_irq(fsl_otg_dev->irq, fsl_otg_dev); 1138 free_irq(fsl_otg_dev->irq, fsl_otg_dev);
1139 1139
1140 iounmap((void *)usb_dr_regs); 1140 iounmap((void *)usb_dr_regs);
diff --git a/drivers/usb/otg/gpio_vbus.c b/drivers/usb/otg/gpio_vbus.c
index bde6298a9693..a67ffe22179a 100644
--- a/drivers/usb/otg/gpio_vbus.c
+++ b/drivers/usb/otg/gpio_vbus.c
@@ -320,7 +320,7 @@ static int __init gpio_vbus_probe(struct platform_device *pdev)
320 } 320 }
321 321
322 /* only active when a gadget is registered */ 322 /* only active when a gadget is registered */
323 err = usb_set_transceiver(&gpio_vbus->phy); 323 err = usb_add_phy(&gpio_vbus->phy, USB_PHY_TYPE_USB2);
324 if (err) { 324 if (err) {
325 dev_err(&pdev->dev, "can't register transceiver, err: %d\n", 325 dev_err(&pdev->dev, "can't register transceiver, err: %d\n",
326 err); 326 err);
@@ -354,7 +354,7 @@ static int __exit gpio_vbus_remove(struct platform_device *pdev)
354 cancel_delayed_work_sync(&gpio_vbus->work); 354 cancel_delayed_work_sync(&gpio_vbus->work);
355 regulator_put(gpio_vbus->vbus_draw); 355 regulator_put(gpio_vbus->vbus_draw);
356 356
357 usb_set_transceiver(NULL); 357 usb_remove_phy(&gpio_vbus->phy);
358 358
359 free_irq(gpio_vbus->irq, pdev); 359 free_irq(gpio_vbus->irq, pdev);
360 if (gpio_is_valid(pdata->gpio_pullup)) 360 if (gpio_is_valid(pdata->gpio_pullup))
diff --git a/drivers/usb/otg/isp1301_omap.c b/drivers/usb/otg/isp1301_omap.c
index 70cf5d7bca48..75cea4ab0985 100644
--- a/drivers/usb/otg/isp1301_omap.c
+++ b/drivers/usb/otg/isp1301_omap.c
@@ -1336,9 +1336,6 @@ static int
1336isp1301_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget) 1336isp1301_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget)
1337{ 1337{
1338 struct isp1301 *isp = container_of(otg->phy, struct isp1301, phy); 1338 struct isp1301 *isp = container_of(otg->phy, struct isp1301, phy);
1339#ifndef CONFIG_USB_OTG
1340 u32 l;
1341#endif
1342 1339
1343 if (!otg || isp != the_transceiver) 1340 if (!otg || isp != the_transceiver)
1344 return -ENODEV; 1341 return -ENODEV;
@@ -1365,10 +1362,14 @@ isp1301_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget)
1365 otg->gadget = gadget; 1362 otg->gadget = gadget;
1366 // FIXME update its refcount 1363 // FIXME update its refcount
1367 1364
1368 l = omap_readl(OTG_CTRL) & OTG_CTRL_MASK; 1365 {
1369 l &= ~(OTG_XCEIV_OUTPUTS|OTG_CTRL_BITS); 1366 u32 l;
1370 l |= OTG_ID; 1367
1371 omap_writel(l, OTG_CTRL); 1368 l = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
1369 l &= ~(OTG_XCEIV_OUTPUTS|OTG_CTRL_BITS);
1370 l |= OTG_ID;
1371 omap_writel(l, OTG_CTRL);
1372 }
1372 1373
1373 power_up(isp); 1374 power_up(isp);
1374 isp->phy.state = OTG_STATE_B_IDLE; 1375 isp->phy.state = OTG_STATE_B_IDLE;
@@ -1610,7 +1611,7 @@ isp1301_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
1610 dev_dbg(&i2c->dev, "scheduled timer, %d min\n", TIMER_MINUTES); 1611 dev_dbg(&i2c->dev, "scheduled timer, %d min\n", TIMER_MINUTES);
1611#endif 1612#endif
1612 1613
1613 status = usb_set_transceiver(&isp->phy); 1614 status = usb_add_phy(&isp->phy, USB_PHY_TYPE_USB2);
1614 if (status < 0) 1615 if (status < 0)
1615 dev_err(&i2c->dev, "can't register transceiver, %d\n", 1616 dev_err(&i2c->dev, "can't register transceiver, %d\n",
1616 status); 1617 status);
@@ -1649,7 +1650,7 @@ subsys_initcall(isp_init);
1649static void __exit isp_exit(void) 1650static void __exit isp_exit(void)
1650{ 1651{
1651 if (the_transceiver) 1652 if (the_transceiver)
1652 usb_set_transceiver(NULL); 1653 usb_remove_phy(&the_transceiver->phy);
1653 i2c_del_driver(&isp1301_driver); 1654 i2c_del_driver(&isp1301_driver);
1654} 1655}
1655module_exit(isp_exit); 1656module_exit(isp_exit);
diff --git a/drivers/usb/otg/msm_otg.c b/drivers/usb/otg/msm_otg.c
index 1d0347c247d1..9f5fc906041a 100644
--- a/drivers/usb/otg/msm_otg.c
+++ b/drivers/usb/otg/msm_otg.c
@@ -1555,9 +1555,9 @@ static int __init msm_otg_probe(struct platform_device *pdev)
1555 phy->otg->set_host = msm_otg_set_host; 1555 phy->otg->set_host = msm_otg_set_host;
1556 phy->otg->set_peripheral = msm_otg_set_peripheral; 1556 phy->otg->set_peripheral = msm_otg_set_peripheral;
1557 1557
1558 ret = usb_set_transceiver(&motg->phy); 1558 ret = usb_add_phy(&motg->phy, USB_PHY_TYPE_USB2);
1559 if (ret) { 1559 if (ret) {
1560 dev_err(&pdev->dev, "usb_set_transceiver failed\n"); 1560 dev_err(&pdev->dev, "usb_add_phy failed\n");
1561 goto free_irq; 1561 goto free_irq;
1562 } 1562 }
1563 1563
@@ -1624,7 +1624,7 @@ static int __devexit msm_otg_remove(struct platform_device *pdev)
1624 device_init_wakeup(&pdev->dev, 0); 1624 device_init_wakeup(&pdev->dev, 0);
1625 pm_runtime_disable(&pdev->dev); 1625 pm_runtime_disable(&pdev->dev);
1626 1626
1627 usb_set_transceiver(NULL); 1627 usb_remove_phy(phy);
1628 free_irq(motg->irq, motg); 1628 free_irq(motg->irq, motg);
1629 1629
1630 /* 1630 /*
diff --git a/drivers/usb/otg/mv_otg.c b/drivers/usb/otg/mv_otg.c
index 6cc6c3ffbb83..3f124e8f5792 100644
--- a/drivers/usb/otg/mv_otg.c
+++ b/drivers/usb/otg/mv_otg.c
@@ -690,7 +690,7 @@ int mv_otg_remove(struct platform_device *pdev)
690 for (clk_i = 0; clk_i <= mvotg->clknum; clk_i++) 690 for (clk_i = 0; clk_i <= mvotg->clknum; clk_i++)
691 clk_put(mvotg->clk[clk_i]); 691 clk_put(mvotg->clk[clk_i]);
692 692
693 usb_set_transceiver(NULL); 693 usb_remove_phy(&mvotg->phy);
694 platform_set_drvdata(pdev, NULL); 694 platform_set_drvdata(pdev, NULL);
695 695
696 kfree(mvotg->phy.otg); 696 kfree(mvotg->phy.otg);
@@ -853,7 +853,7 @@ static int mv_otg_probe(struct platform_device *pdev)
853 goto err_disable_clk; 853 goto err_disable_clk;
854 } 854 }
855 855
856 retval = usb_set_transceiver(&mvotg->phy); 856 retval = usb_add_phy(&mvotg->phy, USB_PHY_TYPE_USB2);
857 if (retval < 0) { 857 if (retval < 0) {
858 dev_err(&pdev->dev, "can't register transceiver, %d\n", 858 dev_err(&pdev->dev, "can't register transceiver, %d\n",
859 retval); 859 retval);
@@ -880,7 +880,7 @@ static int mv_otg_probe(struct platform_device *pdev)
880 return 0; 880 return 0;
881 881
882err_set_transceiver: 882err_set_transceiver:
883 usb_set_transceiver(NULL); 883 usb_remove_phy(&mvotg->phy);
884err_free_irq: 884err_free_irq:
885 free_irq(mvotg->irq, mvotg); 885 free_irq(mvotg->irq, mvotg);
886err_disable_clk: 886err_disable_clk:
diff --git a/drivers/usb/otg/nop-usb-xceiv.c b/drivers/usb/otg/nop-usb-xceiv.c
index 58b26df6afd1..803f958f4133 100644
--- a/drivers/usb/otg/nop-usb-xceiv.c
+++ b/drivers/usb/otg/nop-usb-xceiv.c
@@ -117,7 +117,7 @@ static int __devinit nop_usb_xceiv_probe(struct platform_device *pdev)
117 nop->phy.otg->set_host = nop_set_host; 117 nop->phy.otg->set_host = nop_set_host;
118 nop->phy.otg->set_peripheral = nop_set_peripheral; 118 nop->phy.otg->set_peripheral = nop_set_peripheral;
119 119
120 err = usb_set_transceiver(&nop->phy); 120 err = usb_add_phy(&nop->phy, USB_PHY_TYPE_USB2);
121 if (err) { 121 if (err) {
122 dev_err(&pdev->dev, "can't register transceiver, err: %d\n", 122 dev_err(&pdev->dev, "can't register transceiver, err: %d\n",
123 err); 123 err);
@@ -139,7 +139,7 @@ static int __devexit nop_usb_xceiv_remove(struct platform_device *pdev)
139{ 139{
140 struct nop_usb_xceiv *nop = platform_get_drvdata(pdev); 140 struct nop_usb_xceiv *nop = platform_get_drvdata(pdev);
141 141
142 usb_set_transceiver(NULL); 142 usb_remove_phy(&nop->phy);
143 143
144 platform_set_drvdata(pdev, NULL); 144 platform_set_drvdata(pdev, NULL);
145 kfree(nop->phy.otg); 145 kfree(nop->phy.otg);
diff --git a/drivers/usb/otg/otg.c b/drivers/usb/otg/otg.c
index 801e597a1541..1bf60a22595c 100644
--- a/drivers/usb/otg/otg.c
+++ b/drivers/usb/otg/otg.c
@@ -11,60 +11,195 @@
11 11
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/export.h> 13#include <linux/export.h>
14#include <linux/err.h>
14#include <linux/device.h> 15#include <linux/device.h>
16#include <linux/slab.h>
15 17
16#include <linux/usb/otg.h> 18#include <linux/usb/otg.h>
17 19
18static struct usb_phy *phy; 20static LIST_HEAD(phy_list);
21static DEFINE_SPINLOCK(phy_lock);
22
23static struct usb_phy *__usb_find_phy(struct list_head *list,
24 enum usb_phy_type type)
25{
26 struct usb_phy *phy = NULL;
27
28 list_for_each_entry(phy, list, head) {
29 if (phy->type != type)
30 continue;
31
32 return phy;
33 }
34
35 return ERR_PTR(-ENODEV);
36}
37
38static void devm_usb_phy_release(struct device *dev, void *res)
39{
40 struct usb_phy *phy = *(struct usb_phy **)res;
41
42 usb_put_phy(phy);
43}
44
45static int devm_usb_phy_match(struct device *dev, void *res, void *match_data)
46{
47 return res == match_data;
48}
19 49
20/** 50/**
21 * usb_get_transceiver - find the (single) USB transceiver 51 * devm_usb_get_phy - find the USB PHY
52 * @dev - device that requests this phy
53 * @type - the type of the phy the controller requires
22 * 54 *
23 * Returns the transceiver driver, after getting a refcount to it; or 55 * Gets the phy using usb_get_phy(), and associates a device with it using
24 * null if there is no such transceiver. The caller is responsible for 56 * devres. On driver detach, release function is invoked on the devres data,
25 * calling usb_put_transceiver() to release that count. 57 * then, devres data is freed.
26 * 58 *
27 * For use by USB host and peripheral drivers. 59 * For use by USB host and peripheral drivers.
28 */ 60 */
29struct usb_phy *usb_get_transceiver(void) 61struct usb_phy *devm_usb_get_phy(struct device *dev, enum usb_phy_type type)
30{ 62{
31 if (phy) 63 struct usb_phy **ptr, *phy;
32 get_device(phy->dev); 64
65 ptr = devres_alloc(devm_usb_phy_release, sizeof(*ptr), GFP_KERNEL);
66 if (!ptr)
67 return NULL;
68
69 phy = usb_get_phy(type);
70 if (!IS_ERR(phy)) {
71 *ptr = phy;
72 devres_add(dev, ptr);
73 } else
74 devres_free(ptr);
75
76 return phy;
77}
78EXPORT_SYMBOL(devm_usb_get_phy);
79
80/**
81 * usb_get_phy - find the USB PHY
82 * @type - the type of the phy the controller requires
83 *
84 * Returns the phy driver, after getting a refcount to it; or
85 * -ENODEV if there is no such phy. The caller is responsible for
86 * calling usb_put_phy() to release that count.
87 *
88 * For use by USB host and peripheral drivers.
89 */
90struct usb_phy *usb_get_phy(enum usb_phy_type type)
91{
92 struct usb_phy *phy = NULL;
93 unsigned long flags;
94
95 spin_lock_irqsave(&phy_lock, flags);
96
97 phy = __usb_find_phy(&phy_list, type);
98 if (IS_ERR(phy)) {
99 pr_err("unable to find transceiver of type %s\n",
100 usb_phy_type_string(type));
101 goto err0;
102 }
103
104 get_device(phy->dev);
105
106err0:
107 spin_unlock_irqrestore(&phy_lock, flags);
108
33 return phy; 109 return phy;
34} 110}
35EXPORT_SYMBOL(usb_get_transceiver); 111EXPORT_SYMBOL(usb_get_phy);
112
113/**
114 * devm_usb_put_phy - release the USB PHY
115 * @dev - device that wants to release this phy
116 * @phy - the phy returned by devm_usb_get_phy()
117 *
118 * destroys the devres associated with this phy and invokes usb_put_phy
119 * to release the phy.
120 *
121 * For use by USB host and peripheral drivers.
122 */
123void devm_usb_put_phy(struct device *dev, struct usb_phy *phy)
124{
125 int r;
126
127 r = devres_destroy(dev, devm_usb_phy_release, devm_usb_phy_match, phy);
128 dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n");
129}
130EXPORT_SYMBOL(devm_usb_put_phy);
36 131
37/** 132/**
38 * usb_put_transceiver - release the (single) USB transceiver 133 * usb_put_phy - release the USB PHY
39 * @x: the transceiver returned by usb_get_transceiver() 134 * @x: the phy returned by usb_get_phy()
40 * 135 *
41 * Releases a refcount the caller received from usb_get_transceiver(). 136 * Releases a refcount the caller received from usb_get_phy().
42 * 137 *
43 * For use by USB host and peripheral drivers. 138 * For use by USB host and peripheral drivers.
44 */ 139 */
45void usb_put_transceiver(struct usb_phy *x) 140void usb_put_phy(struct usb_phy *x)
46{ 141{
47 if (x) 142 if (x)
48 put_device(x->dev); 143 put_device(x->dev);
49} 144}
50EXPORT_SYMBOL(usb_put_transceiver); 145EXPORT_SYMBOL(usb_put_phy);
51 146
52/** 147/**
53 * usb_set_transceiver - declare the (single) USB transceiver 148 * usb_add_phy - declare the USB PHY
54 * @x: the USB transceiver to be used; or NULL 149 * @x: the USB phy to be used; or NULL
150 * @type - the type of this PHY
55 * 151 *
56 * This call is exclusively for use by transceiver drivers, which 152 * This call is exclusively for use by phy drivers, which
57 * coordinate the activities of drivers for host and peripheral 153 * coordinate the activities of drivers for host and peripheral
58 * controllers, and in some cases for VBUS current regulation. 154 * controllers, and in some cases for VBUS current regulation.
59 */ 155 */
60int usb_set_transceiver(struct usb_phy *x) 156int usb_add_phy(struct usb_phy *x, enum usb_phy_type type)
157{
158 int ret = 0;
159 unsigned long flags;
160 struct usb_phy *phy;
161
162 if (x && x->type != USB_PHY_TYPE_UNDEFINED) {
163 dev_err(x->dev, "not accepting initialized PHY %s\n", x->label);
164 return -EINVAL;
165 }
166
167 spin_lock_irqsave(&phy_lock, flags);
168
169 list_for_each_entry(phy, &phy_list, head) {
170 if (phy->type == type) {
171 ret = -EBUSY;
172 dev_err(x->dev, "transceiver type %s already exists\n",
173 usb_phy_type_string(type));
174 goto out;
175 }
176 }
177
178 x->type = type;
179 list_add_tail(&x->head, &phy_list);
180
181out:
182 spin_unlock_irqrestore(&phy_lock, flags);
183 return ret;
184}
185EXPORT_SYMBOL(usb_add_phy);
186
187/**
188 * usb_remove_phy - remove the OTG PHY
189 * @x: the USB OTG PHY to be removed;
190 *
191 * This reverts the effects of usb_add_phy
192 */
193void usb_remove_phy(struct usb_phy *x)
61{ 194{
62 if (phy && x) 195 unsigned long flags;
63 return -EBUSY; 196
64 phy = x; 197 spin_lock_irqsave(&phy_lock, flags);
65 return 0; 198 if (x)
199 list_del(&x->head);
200 spin_unlock_irqrestore(&phy_lock, flags);
66} 201}
67EXPORT_SYMBOL(usb_set_transceiver); 202EXPORT_SYMBOL(usb_remove_phy);
68 203
69const char *otg_state_string(enum usb_otg_state state) 204const char *otg_state_string(enum usb_otg_state state)
70{ 205{
diff --git a/drivers/usb/otg/twl4030-usb.c b/drivers/usb/otg/twl4030-usb.c
index c4a86da858e2..523cad5bfea9 100644
--- a/drivers/usb/otg/twl4030-usb.c
+++ b/drivers/usb/otg/twl4030-usb.c
@@ -33,11 +33,11 @@
33#include <linux/io.h> 33#include <linux/io.h>
34#include <linux/delay.h> 34#include <linux/delay.h>
35#include <linux/usb/otg.h> 35#include <linux/usb/otg.h>
36#include <linux/usb/musb-omap.h>
36#include <linux/usb/ulpi.h> 37#include <linux/usb/ulpi.h>
37#include <linux/i2c/twl.h> 38#include <linux/i2c/twl.h>
38#include <linux/regulator/consumer.h> 39#include <linux/regulator/consumer.h>
39#include <linux/err.h> 40#include <linux/err.h>
40#include <linux/notifier.h>
41#include <linux/slab.h> 41#include <linux/slab.h>
42 42
43/* Register defines */ 43/* Register defines */
@@ -159,7 +159,7 @@ struct twl4030_usb {
159 enum twl4030_usb_mode usb_mode; 159 enum twl4030_usb_mode usb_mode;
160 160
161 int irq; 161 int irq;
162 u8 linkstat; 162 enum omap_musb_vbus_id_status linkstat;
163 bool vbus_supplied; 163 bool vbus_supplied;
164 u8 asleep; 164 u8 asleep;
165 bool irq_enabled; 165 bool irq_enabled;
@@ -246,11 +246,11 @@ twl4030_usb_clear_bits(struct twl4030_usb *twl, u8 reg, u8 bits)
246 246
247/*-------------------------------------------------------------------------*/ 247/*-------------------------------------------------------------------------*/
248 248
249static enum usb_phy_events twl4030_usb_linkstat(struct twl4030_usb *twl) 249static enum omap_musb_vbus_id_status
250 twl4030_usb_linkstat(struct twl4030_usb *twl)
250{ 251{
251 int status; 252 int status;
252 int linkstat = USB_EVENT_NONE; 253 enum omap_musb_vbus_id_status linkstat = OMAP_MUSB_UNKNOWN;
253 struct usb_otg *otg = twl->phy.otg;
254 254
255 twl->vbus_supplied = false; 255 twl->vbus_supplied = false;
256 256
@@ -273,30 +273,23 @@ static enum usb_phy_events twl4030_usb_linkstat(struct twl4030_usb *twl)
273 twl->vbus_supplied = true; 273 twl->vbus_supplied = true;
274 274
275 if (status & BIT(2)) 275 if (status & BIT(2))
276 linkstat = USB_EVENT_ID; 276 linkstat = OMAP_MUSB_ID_GROUND;
277 else 277 else
278 linkstat = USB_EVENT_VBUS; 278 linkstat = OMAP_MUSB_VBUS_VALID;
279 } else 279 } else {
280 linkstat = USB_EVENT_NONE; 280 if (twl->linkstat != OMAP_MUSB_UNKNOWN)
281 linkstat = OMAP_MUSB_VBUS_OFF;
282 }
281 283
282 dev_dbg(twl->dev, "HW_CONDITIONS 0x%02x/%d; link %d\n", 284 dev_dbg(twl->dev, "HW_CONDITIONS 0x%02x/%d; link %d\n",
283 status, status, linkstat); 285 status, status, linkstat);
284 286
285 twl->phy.last_event = linkstat;
286
287 /* REVISIT this assumes host and peripheral controllers 287 /* REVISIT this assumes host and peripheral controllers
288 * are registered, and that both are active... 288 * are registered, and that both are active...
289 */ 289 */
290 290
291 spin_lock_irq(&twl->lock); 291 spin_lock_irq(&twl->lock);
292 twl->linkstat = linkstat; 292 twl->linkstat = linkstat;
293 if (linkstat == USB_EVENT_ID) {
294 otg->default_a = true;
295 twl->phy.state = OTG_STATE_A_IDLE;
296 } else {
297 otg->default_a = false;
298 twl->phy.state = OTG_STATE_B_IDLE;
299 }
300 spin_unlock_irq(&twl->lock); 293 spin_unlock_irq(&twl->lock);
301 294
302 return linkstat; 295 return linkstat;
@@ -501,10 +494,10 @@ static DEVICE_ATTR(vbus, 0444, twl4030_usb_vbus_show, NULL);
501static irqreturn_t twl4030_usb_irq(int irq, void *_twl) 494static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
502{ 495{
503 struct twl4030_usb *twl = _twl; 496 struct twl4030_usb *twl = _twl;
504 int status; 497 enum omap_musb_vbus_id_status status;
505 498
506 status = twl4030_usb_linkstat(twl); 499 status = twl4030_usb_linkstat(twl);
507 if (status >= 0) { 500 if (status > 0) {
508 /* FIXME add a set_power() method so that B-devices can 501 /* FIXME add a set_power() method so that B-devices can
509 * configure the charger appropriately. It's not always 502 * configure the charger appropriately. It's not always
510 * correct to consume VBUS power, and how much current to 503 * correct to consume VBUS power, and how much current to
@@ -516,13 +509,13 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
516 * USB_LINK_VBUS state. musb_hdrc won't care until it 509 * USB_LINK_VBUS state. musb_hdrc won't care until it
517 * starts to handle softconnect right. 510 * starts to handle softconnect right.
518 */ 511 */
519 if (status == USB_EVENT_NONE) 512 if (status == OMAP_MUSB_VBUS_OFF ||
513 status == OMAP_MUSB_ID_FLOAT)
520 twl4030_phy_suspend(twl, 0); 514 twl4030_phy_suspend(twl, 0);
521 else 515 else
522 twl4030_phy_resume(twl); 516 twl4030_phy_resume(twl);
523 517
524 atomic_notifier_call_chain(&twl->phy.notifier, status, 518 omap_musb_mailbox(twl->linkstat);
525 twl->phy.otg->gadget);
526 } 519 }
527 sysfs_notify(&twl->dev->kobj, NULL, "vbus"); 520 sysfs_notify(&twl->dev->kobj, NULL, "vbus");
528 521
@@ -531,11 +524,12 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
531 524
532static void twl4030_usb_phy_init(struct twl4030_usb *twl) 525static void twl4030_usb_phy_init(struct twl4030_usb *twl)
533{ 526{
534 int status; 527 enum omap_musb_vbus_id_status status;
535 528
536 status = twl4030_usb_linkstat(twl); 529 status = twl4030_usb_linkstat(twl);
537 if (status >= 0) { 530 if (status > 0) {
538 if (status == USB_EVENT_NONE) { 531 if (status == OMAP_MUSB_VBUS_OFF ||
532 status == OMAP_MUSB_ID_FLOAT) {
539 __twl4030_phy_power(twl, 0); 533 __twl4030_phy_power(twl, 0);
540 twl->asleep = 1; 534 twl->asleep = 1;
541 } else { 535 } else {
@@ -543,8 +537,7 @@ static void twl4030_usb_phy_init(struct twl4030_usb *twl)
543 twl->asleep = 0; 537 twl->asleep = 0;
544 } 538 }
545 539
546 atomic_notifier_call_chain(&twl->phy.notifier, status, 540 omap_musb_mailbox(twl->linkstat);
547 twl->phy.otg->gadget);
548 } 541 }
549 sysfs_notify(&twl->dev->kobj, NULL, "vbus"); 542 sysfs_notify(&twl->dev->kobj, NULL, "vbus");
550} 543}
@@ -598,21 +591,20 @@ static int __devinit twl4030_usb_probe(struct platform_device *pdev)
598 return -EINVAL; 591 return -EINVAL;
599 } 592 }
600 593
601 twl = kzalloc(sizeof *twl, GFP_KERNEL); 594 twl = devm_kzalloc(&pdev->dev, sizeof *twl, GFP_KERNEL);
602 if (!twl) 595 if (!twl)
603 return -ENOMEM; 596 return -ENOMEM;
604 597
605 otg = kzalloc(sizeof *otg, GFP_KERNEL); 598 otg = devm_kzalloc(&pdev->dev, sizeof *otg, GFP_KERNEL);
606 if (!otg) { 599 if (!otg)
607 kfree(twl);
608 return -ENOMEM; 600 return -ENOMEM;
609 }
610 601
611 twl->dev = &pdev->dev; 602 twl->dev = &pdev->dev;
612 twl->irq = platform_get_irq(pdev, 0); 603 twl->irq = platform_get_irq(pdev, 0);
613 twl->usb_mode = pdata->usb_mode; 604 twl->usb_mode = pdata->usb_mode;
614 twl->vbus_supplied = false; 605 twl->vbus_supplied = false;
615 twl->asleep = 1; 606 twl->asleep = 1;
607 twl->linkstat = OMAP_MUSB_UNKNOWN;
616 608
617 twl->phy.dev = twl->dev; 609 twl->phy.dev = twl->dev;
618 twl->phy.label = "twl4030"; 610 twl->phy.label = "twl4030";
@@ -629,18 +621,14 @@ static int __devinit twl4030_usb_probe(struct platform_device *pdev)
629 err = twl4030_usb_ldo_init(twl); 621 err = twl4030_usb_ldo_init(twl);
630 if (err) { 622 if (err) {
631 dev_err(&pdev->dev, "ldo init failed\n"); 623 dev_err(&pdev->dev, "ldo init failed\n");
632 kfree(otg);
633 kfree(twl);
634 return err; 624 return err;
635 } 625 }
636 usb_set_transceiver(&twl->phy); 626 usb_add_phy(&twl->phy, USB_PHY_TYPE_USB2);
637 627
638 platform_set_drvdata(pdev, twl); 628 platform_set_drvdata(pdev, twl);
639 if (device_create_file(&pdev->dev, &dev_attr_vbus)) 629 if (device_create_file(&pdev->dev, &dev_attr_vbus))
640 dev_warn(&pdev->dev, "could not create sysfs file\n"); 630 dev_warn(&pdev->dev, "could not create sysfs file\n");
641 631
642 ATOMIC_INIT_NOTIFIER_HEAD(&twl->phy.notifier);
643
644 /* Our job is to use irqs and status from the power module 632 /* Our job is to use irqs and status from the power module
645 * to keep the transceiver disabled when nothing's connected. 633 * to keep the transceiver disabled when nothing's connected.
646 * 634 *
@@ -651,13 +639,11 @@ static int __devinit twl4030_usb_probe(struct platform_device *pdev)
651 */ 639 */
652 twl->irq_enabled = true; 640 twl->irq_enabled = true;
653 status = request_threaded_irq(twl->irq, NULL, twl4030_usb_irq, 641 status = request_threaded_irq(twl->irq, NULL, twl4030_usb_irq,
654 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, 642 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING |
655 "twl4030_usb", twl); 643 IRQF_ONESHOT, "twl4030_usb", twl);
656 if (status < 0) { 644 if (status < 0) {
657 dev_dbg(&pdev->dev, "can't get IRQ %d, err %d\n", 645 dev_dbg(&pdev->dev, "can't get IRQ %d, err %d\n",
658 twl->irq, status); 646 twl->irq, status);
659 kfree(otg);
660 kfree(twl);
661 return status; 647 return status;
662 } 648 }
663 649
@@ -701,9 +687,6 @@ static int __exit twl4030_usb_remove(struct platform_device *pdev)
701 regulator_put(twl->usb1v8); 687 regulator_put(twl->usb1v8);
702 regulator_put(twl->usb3v1); 688 regulator_put(twl->usb3v1);
703 689
704 kfree(twl->phy.otg);
705 kfree(twl);
706
707 return 0; 690 return 0;
708} 691}
709 692
diff --git a/drivers/usb/otg/twl6030-usb.c b/drivers/usb/otg/twl6030-usb.c
index 0eabb049b6a9..a3d0c0405cca 100644
--- a/drivers/usb/otg/twl6030-usb.c
+++ b/drivers/usb/otg/twl6030-usb.c
@@ -26,10 +26,10 @@
26#include <linux/platform_device.h> 26#include <linux/platform_device.h>
27#include <linux/io.h> 27#include <linux/io.h>
28#include <linux/usb/otg.h> 28#include <linux/usb/otg.h>
29#include <linux/usb/musb-omap.h>
29#include <linux/i2c/twl.h> 30#include <linux/i2c/twl.h>
30#include <linux/regulator/consumer.h> 31#include <linux/regulator/consumer.h>
31#include <linux/err.h> 32#include <linux/err.h>
32#include <linux/notifier.h>
33#include <linux/slab.h> 33#include <linux/slab.h>
34#include <linux/delay.h> 34#include <linux/delay.h>
35 35
@@ -100,7 +100,7 @@ struct twl6030_usb {
100 100
101 int irq1; 101 int irq1;
102 int irq2; 102 int irq2;
103 u8 linkstat; 103 enum omap_musb_vbus_id_status linkstat;
104 u8 asleep; 104 u8 asleep;
105 bool irq_enabled; 105 bool irq_enabled;
106 bool vbus_enable; 106 bool vbus_enable;
@@ -147,7 +147,7 @@ static int twl6030_phy_init(struct usb_phy *x)
147 dev = twl->dev; 147 dev = twl->dev;
148 pdata = dev->platform_data; 148 pdata = dev->platform_data;
149 149
150 if (twl->linkstat == USB_EVENT_ID) 150 if (twl->linkstat == OMAP_MUSB_ID_GROUND)
151 pdata->phy_power(twl->dev, 1, 1); 151 pdata->phy_power(twl->dev, 1, 1);
152 else 152 else
153 pdata->phy_power(twl->dev, 0, 1); 153 pdata->phy_power(twl->dev, 0, 1);
@@ -235,13 +235,13 @@ static ssize_t twl6030_usb_vbus_show(struct device *dev,
235 spin_lock_irqsave(&twl->lock, flags); 235 spin_lock_irqsave(&twl->lock, flags);
236 236
237 switch (twl->linkstat) { 237 switch (twl->linkstat) {
238 case USB_EVENT_VBUS: 238 case OMAP_MUSB_VBUS_VALID:
239 ret = snprintf(buf, PAGE_SIZE, "vbus\n"); 239 ret = snprintf(buf, PAGE_SIZE, "vbus\n");
240 break; 240 break;
241 case USB_EVENT_ID: 241 case OMAP_MUSB_ID_GROUND:
242 ret = snprintf(buf, PAGE_SIZE, "id\n"); 242 ret = snprintf(buf, PAGE_SIZE, "id\n");
243 break; 243 break;
244 case USB_EVENT_NONE: 244 case OMAP_MUSB_VBUS_OFF:
245 ret = snprintf(buf, PAGE_SIZE, "none\n"); 245 ret = snprintf(buf, PAGE_SIZE, "none\n");
246 break; 246 break;
247 default: 247 default:
@@ -256,8 +256,7 @@ static DEVICE_ATTR(vbus, 0444, twl6030_usb_vbus_show, NULL);
256static irqreturn_t twl6030_usb_irq(int irq, void *_twl) 256static irqreturn_t twl6030_usb_irq(int irq, void *_twl)
257{ 257{
258 struct twl6030_usb *twl = _twl; 258 struct twl6030_usb *twl = _twl;
259 struct usb_otg *otg = twl->phy.otg; 259 enum omap_musb_vbus_id_status status = OMAP_MUSB_UNKNOWN;
260 int status;
261 u8 vbus_state, hw_state; 260 u8 vbus_state, hw_state;
262 261
263 hw_state = twl6030_readb(twl, TWL6030_MODULE_ID0, STS_HW_CONDITIONS); 262 hw_state = twl6030_readb(twl, TWL6030_MODULE_ID0, STS_HW_CONDITIONS);
@@ -268,22 +267,18 @@ static irqreturn_t twl6030_usb_irq(int irq, void *_twl)
268 if (vbus_state & VBUS_DET) { 267 if (vbus_state & VBUS_DET) {
269 regulator_enable(twl->usb3v3); 268 regulator_enable(twl->usb3v3);
270 twl->asleep = 1; 269 twl->asleep = 1;
271 status = USB_EVENT_VBUS; 270 status = OMAP_MUSB_VBUS_VALID;
272 otg->default_a = false;
273 twl->phy.state = OTG_STATE_B_IDLE;
274 twl->linkstat = status; 271 twl->linkstat = status;
275 twl->phy.last_event = status; 272 omap_musb_mailbox(status);
276 atomic_notifier_call_chain(&twl->phy.notifier,
277 status, otg->gadget);
278 } else { 273 } else {
279 status = USB_EVENT_NONE; 274 if (twl->linkstat != OMAP_MUSB_UNKNOWN) {
280 twl->linkstat = status; 275 status = OMAP_MUSB_VBUS_OFF;
281 twl->phy.last_event = status; 276 twl->linkstat = status;
282 atomic_notifier_call_chain(&twl->phy.notifier, 277 omap_musb_mailbox(status);
283 status, otg->gadget); 278 if (twl->asleep) {
284 if (twl->asleep) { 279 regulator_disable(twl->usb3v3);
285 regulator_disable(twl->usb3v3); 280 twl->asleep = 0;
286 twl->asleep = 0; 281 }
287 } 282 }
288 } 283 }
289 } 284 }
@@ -295,8 +290,7 @@ static irqreturn_t twl6030_usb_irq(int irq, void *_twl)
295static irqreturn_t twl6030_usbotg_irq(int irq, void *_twl) 290static irqreturn_t twl6030_usbotg_irq(int irq, void *_twl)
296{ 291{
297 struct twl6030_usb *twl = _twl; 292 struct twl6030_usb *twl = _twl;
298 struct usb_otg *otg = twl->phy.otg; 293 enum omap_musb_vbus_id_status status = OMAP_MUSB_UNKNOWN;
299 int status = USB_EVENT_NONE;
300 u8 hw_state; 294 u8 hw_state;
301 295
302 hw_state = twl6030_readb(twl, TWL6030_MODULE_ID0, STS_HW_CONDITIONS); 296 hw_state = twl6030_readb(twl, TWL6030_MODULE_ID0, STS_HW_CONDITIONS);
@@ -307,13 +301,11 @@ static irqreturn_t twl6030_usbotg_irq(int irq, void *_twl)
307 twl->asleep = 1; 301 twl->asleep = 1;
308 twl6030_writeb(twl, TWL_MODULE_USB, 0x1, USB_ID_INT_EN_HI_CLR); 302 twl6030_writeb(twl, TWL_MODULE_USB, 0x1, USB_ID_INT_EN_HI_CLR);
309 twl6030_writeb(twl, TWL_MODULE_USB, 0x10, USB_ID_INT_EN_HI_SET); 303 twl6030_writeb(twl, TWL_MODULE_USB, 0x10, USB_ID_INT_EN_HI_SET);
310 status = USB_EVENT_ID; 304 status = OMAP_MUSB_ID_GROUND;
311 otg->default_a = true; 305 otg->default_a = true;
312 twl->phy.state = OTG_STATE_A_IDLE; 306 twl->phy.state = OTG_STATE_A_IDLE;
313 twl->linkstat = status; 307 twl->linkstat = status;
314 twl->phy.last_event = status; 308 omap_musb_mailbox(status);
315 atomic_notifier_call_chain(&twl->phy.notifier, status,
316 otg->gadget);
317 } else { 309 } else {
318 twl6030_writeb(twl, TWL_MODULE_USB, 0x10, USB_ID_INT_EN_HI_CLR); 310 twl6030_writeb(twl, TWL_MODULE_USB, 0x10, USB_ID_INT_EN_HI_CLR);
319 twl6030_writeb(twl, TWL_MODULE_USB, 0x1, USB_ID_INT_EN_HI_SET); 311 twl6030_writeb(twl, TWL_MODULE_USB, 0x1, USB_ID_INT_EN_HI_SET);
@@ -402,20 +394,19 @@ static int __devinit twl6030_usb_probe(struct platform_device *pdev)
402 struct device *dev = &pdev->dev; 394 struct device *dev = &pdev->dev;
403 pdata = dev->platform_data; 395 pdata = dev->platform_data;
404 396
405 twl = kzalloc(sizeof *twl, GFP_KERNEL); 397 twl = devm_kzalloc(dev, sizeof *twl, GFP_KERNEL);
406 if (!twl) 398 if (!twl)
407 return -ENOMEM; 399 return -ENOMEM;
408 400
409 otg = kzalloc(sizeof *otg, GFP_KERNEL); 401 otg = devm_kzalloc(dev, sizeof *otg, GFP_KERNEL);
410 if (!otg) { 402 if (!otg)
411 kfree(twl);
412 return -ENOMEM; 403 return -ENOMEM;
413 }
414 404
415 twl->dev = &pdev->dev; 405 twl->dev = &pdev->dev;
416 twl->irq1 = platform_get_irq(pdev, 0); 406 twl->irq1 = platform_get_irq(pdev, 0);
417 twl->irq2 = platform_get_irq(pdev, 1); 407 twl->irq2 = platform_get_irq(pdev, 1);
418 twl->features = pdata->features; 408 twl->features = pdata->features;
409 twl->linkstat = OMAP_MUSB_UNKNOWN;
419 410
420 twl->phy.dev = twl->dev; 411 twl->phy.dev = twl->dev;
421 twl->phy.label = "twl6030"; 412 twl->phy.label = "twl6030";
@@ -436,18 +427,14 @@ static int __devinit twl6030_usb_probe(struct platform_device *pdev)
436 err = twl6030_usb_ldo_init(twl); 427 err = twl6030_usb_ldo_init(twl);
437 if (err) { 428 if (err) {
438 dev_err(&pdev->dev, "ldo init failed\n"); 429 dev_err(&pdev->dev, "ldo init failed\n");
439 kfree(otg);
440 kfree(twl);
441 return err; 430 return err;
442 } 431 }
443 usb_set_transceiver(&twl->phy); 432 usb_add_phy(&twl->phy, USB_PHY_TYPE_USB2);
444 433
445 platform_set_drvdata(pdev, twl); 434 platform_set_drvdata(pdev, twl);
446 if (device_create_file(&pdev->dev, &dev_attr_vbus)) 435 if (device_create_file(&pdev->dev, &dev_attr_vbus))
447 dev_warn(&pdev->dev, "could not create sysfs file\n"); 436 dev_warn(&pdev->dev, "could not create sysfs file\n");
448 437
449 ATOMIC_INIT_NOTIFIER_HEAD(&twl->phy.notifier);
450
451 INIT_WORK(&twl->set_vbus_work, otg_set_vbus_work); 438 INIT_WORK(&twl->set_vbus_work, otg_set_vbus_work);
452 439
453 twl->irq_enabled = true; 440 twl->irq_enabled = true;
@@ -458,8 +445,6 @@ static int __devinit twl6030_usb_probe(struct platform_device *pdev)
458 dev_err(&pdev->dev, "can't get IRQ %d, err %d\n", 445 dev_err(&pdev->dev, "can't get IRQ %d, err %d\n",
459 twl->irq1, status); 446 twl->irq1, status);
460 device_remove_file(twl->dev, &dev_attr_vbus); 447 device_remove_file(twl->dev, &dev_attr_vbus);
461 kfree(otg);
462 kfree(twl);
463 return status; 448 return status;
464 } 449 }
465 450
@@ -471,8 +456,6 @@ static int __devinit twl6030_usb_probe(struct platform_device *pdev)
471 twl->irq2, status); 456 twl->irq2, status);
472 free_irq(twl->irq1, twl); 457 free_irq(twl->irq1, twl);
473 device_remove_file(twl->dev, &dev_attr_vbus); 458 device_remove_file(twl->dev, &dev_attr_vbus);
474 kfree(otg);
475 kfree(twl);
476 return status; 459 return status;
477 } 460 }
478 461
@@ -503,8 +486,6 @@ static int __exit twl6030_usb_remove(struct platform_device *pdev)
503 pdata->phy_exit(twl->dev); 486 pdata->phy_exit(twl->dev);
504 device_remove_file(twl->dev, &dev_attr_vbus); 487 device_remove_file(twl->dev, &dev_attr_vbus);
505 cancel_work_sync(&twl->set_vbus_work); 488 cancel_work_sync(&twl->set_vbus_work);
506 kfree(twl->phy.otg);
507 kfree(twl);
508 489
509 return 0; 490 return 0;
510} 491}