aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/Makefile2
-rw-r--r--drivers/hid/usbhid/hid-core.c14
-rw-r--r--drivers/net/usb/cdc_mbim.c5
-rw-r--r--drivers/net/usb/qmi_wwan.c5
-rw-r--r--drivers/net/usb/smsc75xx.c6
-rw-r--r--drivers/net/usb/smsc95xx.c6
-rw-r--r--drivers/power/Kconfig2
-rw-r--r--drivers/power/pda_power.c14
-rw-r--r--drivers/staging/Kconfig2
-rw-r--r--drivers/staging/Makefile1
-rw-r--r--drivers/usb/Kconfig2
-rw-r--r--drivers/usb/Makefile4
-rw-r--r--drivers/usb/chipidea/Makefile2
-rw-r--r--drivers/usb/chipidea/ci.h19
-rw-r--r--drivers/usb/chipidea/ci13xxx_imx.c12
-rw-r--r--drivers/usb/chipidea/ci13xxx_imx.h3
-rw-r--r--drivers/usb/chipidea/ci13xxx_pci.c6
-rw-r--r--drivers/usb/chipidea/core.c66
-rw-r--r--drivers/usb/chipidea/debug.c888
-rw-r--r--drivers/usb/chipidea/debug.h34
-rw-r--r--drivers/usb/chipidea/udc.c299
-rw-r--r--drivers/usb/chipidea/udc.h4
-rw-r--r--drivers/usb/chipidea/usbmisc_imx.c261
-rw-r--r--drivers/usb/chipidea/usbmisc_imx6q.c162
-rw-r--r--drivers/usb/class/cdc-acm.c8
-rw-r--r--drivers/usb/class/cdc-wdm.c19
-rw-r--r--drivers/usb/core/Kconfig32
-rw-r--r--drivers/usb/core/driver.c25
-rw-r--r--drivers/usb/core/generic.c2
-rw-r--r--drivers/usb/core/hcd-pci.c214
-rw-r--r--drivers/usb/core/hcd.c10
-rw-r--r--drivers/usb/core/hub.c136
-rw-r--r--drivers/usb/core/port.c4
-rw-r--r--drivers/usb/core/quirks.c16
-rw-r--r--drivers/usb/core/sysfs.c4
-rw-r--r--drivers/usb/core/urb.c5
-rw-r--r--drivers/usb/core/usb.c4
-rw-r--r--drivers/usb/core/usb.h2
-rw-r--r--drivers/usb/dwc3/Kconfig1
-rw-r--r--drivers/usb/dwc3/core.c201
-rw-r--r--drivers/usb/dwc3/core.h72
-rw-r--r--drivers/usb/dwc3/debugfs.c52
-rw-r--r--drivers/usb/dwc3/dwc3-exynos.c98
-rw-r--r--drivers/usb/dwc3/dwc3-omap.c245
-rw-r--r--drivers/usb/dwc3/dwc3-pci.c38
-rw-r--r--drivers/usb/dwc3/ep0.c33
-rw-r--r--drivers/usb/dwc3/gadget.c321
-rw-r--r--drivers/usb/gadget/Kconfig18
-rw-r--r--drivers/usb/gadget/Makefile13
-rw-r--r--drivers/usb/gadget/acm_ms.c15
-rw-r--r--drivers/usb/gadget/amd5536udc.c16
-rw-r--r--drivers/usb/gadget/amd5536udc.h1
-rw-r--r--drivers/usb/gadget/at91_udc.c14
-rw-r--r--drivers/usb/gadget/atmel_usba_udc.c44
-rw-r--r--drivers/usb/gadget/atmel_usba_udc.h6
-rw-r--r--drivers/usb/gadget/bcm63xx_udc.c23
-rw-r--r--drivers/usb/gadget/cdc2.c27
-rw-r--r--drivers/usb/gadget/composite.c1
-rw-r--r--drivers/usb/gadget/configfs.c1003
-rw-r--r--drivers/usb/gadget/dummy_hcd.c19
-rw-r--r--drivers/usb/gadget/ether.c20
-rw-r--r--drivers/usb/gadget/f_acm.c137
-rw-r--r--drivers/usb/gadget/f_ecm.c4
-rw-r--r--drivers/usb/gadget/f_eem.c3
-rw-r--r--drivers/usb/gadget/f_ncm.c4
-rw-r--r--drivers/usb/gadget/f_obex.c226
-rw-r--r--drivers/usb/gadget/f_rndis.c3
-rw-r--r--drivers/usb/gadget/f_serial.c174
-rw-r--r--drivers/usb/gadget/f_subset.c4
-rw-r--r--drivers/usb/gadget/f_uvc.c262
-rw-r--r--drivers/usb/gadget/f_uvc.h12
-rw-r--r--drivers/usb/gadget/fsl_qe_udc.c18
-rw-r--r--drivers/usb/gadget/fsl_udc_core.c83
-rw-r--r--drivers/usb/gadget/fusb300_udc.c46
-rw-r--r--drivers/usb/gadget/fusb300_udc.h2
-rw-r--r--drivers/usb/gadget/g_ffs.c35
-rw-r--r--drivers/usb/gadget/goku_udc.c20
-rw-r--r--drivers/usb/gadget/goku_udc.h3
-rw-r--r--drivers/usb/gadget/imx_udc.c16
-rw-r--r--drivers/usb/gadget/lpc32xx_udc.c51
-rw-r--r--drivers/usb/gadget/m66592-udc.c17
-rw-r--r--drivers/usb/gadget/multi.c29
-rw-r--r--drivers/usb/gadget/mv_u3d_core.c65
-rw-r--r--drivers/usb/gadget/mv_udc.h3
-rw-r--r--drivers/usb/gadget/mv_udc_core.c117
-rw-r--r--drivers/usb/gadget/ncm.c13
-rw-r--r--drivers/usb/gadget/net2272.c25
-rw-r--r--drivers/usb/gadget/net2280.c25
-rw-r--r--drivers/usb/gadget/nokia.c95
-rw-r--r--drivers/usb/gadget/omap_udc.c21
-rw-r--r--drivers/usb/gadget/pch_udc.c21
-rw-r--r--drivers/usb/gadget/pxa25x_udc.c16
-rw-r--r--drivers/usb/gadget/pxa27x_udc.c51
-rw-r--r--drivers/usb/gadget/r8a66597-udc.c14
-rw-r--r--drivers/usb/gadget/s3c-hsotg.c78
-rw-r--r--drivers/usb/gadget/s3c-hsudc.c16
-rw-r--r--drivers/usb/gadget/s3c2410_udc.c15
-rw-r--r--drivers/usb/gadget/serial.c59
-rw-r--r--drivers/usb/gadget/u_ether.c32
-rw-r--r--drivers/usb/gadget/u_ether.h27
-rw-r--r--drivers/usb/gadget/u_serial.h1
-rw-r--r--drivers/usb/gadget/udc-core.c90
-rw-r--r--drivers/usb/gadget/uvc.h3
-rw-r--r--drivers/usb/gadget/uvc_queue.c538
-rw-r--r--drivers/usb/gadget/uvc_queue.h32
-rw-r--r--drivers/usb/gadget/uvc_v4l2.c71
-rw-r--r--drivers/usb/gadget/uvc_video.c31
-rw-r--r--drivers/usb/host/Kconfig5
-rw-r--r--drivers/usb/host/Makefile1
-rw-r--r--drivers/usb/host/ehci-dbg.c15
-rw-r--r--drivers/usb/host/ehci-fsl.c9
-rw-r--r--drivers/usb/host/ehci-hcd.c74
-rw-r--r--drivers/usb/host/ehci-hub.c23
-rw-r--r--drivers/usb/host/ehci-msm.c2
-rw-r--r--drivers/usb/host/ehci-mv.c56
-rw-r--r--drivers/usb/host/ehci-mxc.c8
-rw-r--r--drivers/usb/host/ehci-omap.c331
-rw-r--r--drivers/usb/host/ehci-orion.c4
-rw-r--r--drivers/usb/host/ehci-pci.c12
-rw-r--r--drivers/usb/host/ehci-platform.c34
-rw-r--r--drivers/usb/host/ehci-ps3.c1
-rw-r--r--drivers/usb/host/ehci-q.c241
-rw-r--r--drivers/usb/host/ehci-s5p.c13
-rw-r--r--drivers/usb/host/ehci-sched.c40
-rw-r--r--drivers/usb/host/ehci-sh.c5
-rw-r--r--drivers/usb/host/ehci-spear.c4
-rw-r--r--drivers/usb/host/ehci-tegra.c24
-rw-r--r--drivers/usb/host/ehci-timer.c72
-rw-r--r--drivers/usb/host/ehci-vt8500.c150
-rw-r--r--drivers/usb/host/ehci.h16
-rw-r--r--drivers/usb/host/ohci-exynos.c2
-rw-r--r--drivers/usb/host/ohci-hub.c6
-rw-r--r--drivers/usb/host/ohci-omap3.c24
-rw-r--r--drivers/usb/host/sl811-hcd.c2
-rw-r--r--drivers/usb/host/u132-hcd.c9
-rw-r--r--drivers/usb/host/xhci-hub.c2
-rw-r--r--drivers/usb/host/xhci.c4
-rw-r--r--drivers/usb/misc/appledisplay.c1
-rw-r--r--drivers/usb/misc/sisusbvga/sisusb.c2
-rw-r--r--drivers/usb/misc/usb3503.c13
-rw-r--r--drivers/usb/musb/Kconfig6
-rw-r--r--drivers/usb/musb/am35x.c8
-rw-r--r--drivers/usb/musb/blackfin.c6
-rw-r--r--drivers/usb/musb/cppi_dma.c17
-rw-r--r--drivers/usb/musb/da8xx.c8
-rw-r--r--drivers/usb/musb/davinci.c4
-rw-r--r--drivers/usb/musb/musb_core.c71
-rw-r--r--drivers/usb/musb/musb_dsps.c14
-rw-r--r--drivers/usb/musb/musb_gadget.c156
-rw-r--r--drivers/usb/musb/musb_gadget_ep0.c6
-rw-r--r--drivers/usb/musb/musb_host.c119
-rw-r--r--drivers/usb/musb/musb_virthub.c4
-rw-r--r--drivers/usb/musb/omap2430.c32
-rw-r--r--drivers/usb/musb/tusb6010.c14
-rw-r--r--drivers/usb/musb/ux500.c106
-rw-r--r--drivers/usb/musb/ux500_dma.c24
-rw-r--r--drivers/usb/otg/Kconfig141
-rw-r--r--drivers/usb/otg/Makefile24
-rw-r--r--drivers/usb/otg/ab8500-usb.c596
-rw-r--r--drivers/usb/phy/Kconfig180
-rw-r--r--drivers/usb/phy/Makefile35
-rw-r--r--drivers/usb/phy/isp1301.c71
-rw-r--r--drivers/usb/phy/phy-ab8500-usb.c924
-rw-r--r--drivers/usb/phy/phy-fsl-usb.c (renamed from drivers/usb/otg/fsl_otg.c)34
-rw-r--r--drivers/usb/phy/phy-fsl-usb.h (renamed from drivers/usb/otg/fsl_otg.h)0
-rw-r--r--drivers/usb/phy/phy-fsm-usb.c (renamed from drivers/usb/otg/otg_fsm.c)4
-rw-r--r--drivers/usb/phy/phy-fsm-usb.h (renamed from drivers/usb/otg/otg_fsm.h)0
-rw-r--r--drivers/usb/phy/phy-gpio-vbus-usb.c (renamed from drivers/usb/otg/gpio_vbus.c)9
-rw-r--r--drivers/usb/phy/phy-isp1301-omap.c (renamed from drivers/usb/otg/isp1301_omap.c)10
-rw-r--r--drivers/usb/phy/phy-isp1301.c162
-rw-r--r--drivers/usb/phy/phy-msm-usb.c (renamed from drivers/usb/otg/msm_otg.c)0
-rw-r--r--drivers/usb/phy/phy-mv-u3d-usb.c (renamed from drivers/usb/phy/mv_u3d_phy.c)4
-rw-r--r--drivers/usb/phy/phy-mv-u3d-usb.h (renamed from drivers/usb/phy/mv_u3d_phy.h)0
-rw-r--r--drivers/usb/phy/phy-mv-usb.c (renamed from drivers/usb/otg/mv_otg.c)30
-rw-r--r--drivers/usb/phy/phy-mv-usb.h (renamed from drivers/usb/otg/mv_otg.h)3
-rw-r--r--drivers/usb/phy/phy-mxs-usb.c (renamed from drivers/usb/otg/mxs-phy.c)41
-rw-r--r--drivers/usb/phy/phy-nop.c (renamed from drivers/usb/otg/nop-usb-xceiv.c)143
-rw-r--r--drivers/usb/phy/phy-omap-control.c (renamed from drivers/usb/phy/omap-control-usb.c)0
-rw-r--r--drivers/usb/phy/phy-omap-usb2.c (renamed from drivers/usb/phy/omap-usb2.c)0
-rw-r--r--drivers/usb/phy/phy-omap-usb3.c (renamed from drivers/usb/phy/omap-usb3.c)0
-rw-r--r--drivers/usb/phy/phy-rcar-usb.c (renamed from drivers/usb/phy/rcar-phy.c)0
-rw-r--r--drivers/usb/phy/phy-samsung-usb.c236
-rw-r--r--drivers/usb/phy/phy-samsung-usb.h327
-rw-r--r--drivers/usb/phy/phy-samsung-usb2.c509
-rw-r--r--drivers/usb/phy/phy-samsung-usb3.c347
-rw-r--r--drivers/usb/phy/phy-tegra-usb.c (renamed from drivers/usb/phy/tegra_usb_phy.c)0
-rw-r--r--drivers/usb/phy/phy-twl4030-usb.c (renamed from drivers/usb/otg/twl4030-usb.c)178
-rw-r--r--drivers/usb/phy/phy-twl6030-usb.c (renamed from drivers/usb/otg/twl6030-usb.c)15
-rw-r--r--drivers/usb/phy/phy-ulpi-viewport.c (renamed from drivers/usb/otg/ulpi_viewport.c)0
-rw-r--r--drivers/usb/phy/phy-ulpi.c (renamed from drivers/usb/otg/ulpi.c)0
-rw-r--r--drivers/usb/phy/phy.c (renamed from drivers/usb/otg/otg.c)62
-rw-r--r--drivers/usb/phy/samsung-usbphy.c928
-rw-r--r--drivers/usb/renesas_usbhs/fifo.c1
-rw-r--r--drivers/usb/renesas_usbhs/fifo.h2
-rw-r--r--drivers/usb/renesas_usbhs/mod_gadget.c24
-rw-r--r--drivers/usb/serial/ark3116.c87
-rw-r--r--drivers/usb/serial/bus.c5
-rw-r--r--drivers/usb/serial/ch341.c30
-rw-r--r--drivers/usb/serial/cp210x.c6
-rw-r--r--drivers/usb/serial/cyberjack.c19
-rw-r--r--drivers/usb/serial/cypress_m8.c94
-rw-r--r--drivers/usb/serial/digi_acceleport.c95
-rw-r--r--drivers/usb/serial/f81232.c13
-rw-r--r--drivers/usb/serial/ftdi_sio.c121
-rw-r--r--drivers/usb/serial/garmin_gps.c10
-rw-r--r--drivers/usb/serial/generic.c144
-rw-r--r--drivers/usb/serial/io_edgeport.c76
-rw-r--r--drivers/usb/serial/io_tables.h12
-rw-r--r--drivers/usb/serial/io_ti.c94
-rw-r--r--drivers/usb/serial/iuu_phoenix.c21
-rw-r--r--drivers/usb/serial/keyspan.c96
-rw-r--r--drivers/usb/serial/keyspan_pda.c19
-rw-r--r--drivers/usb/serial/kl5kusb105.c30
-rw-r--r--drivers/usb/serial/mct_u232.c94
-rw-r--r--drivers/usb/serial/metro-usb.c5
-rw-r--r--drivers/usb/serial/mos7720.c68
-rw-r--r--drivers/usb/serial/mos7840.c157
-rw-r--r--drivers/usb/serial/opticon.c18
-rw-r--r--drivers/usb/serial/oti6858.c30
-rw-r--r--drivers/usb/serial/pl2303.c39
-rw-r--r--drivers/usb/serial/quatech2.c104
-rw-r--r--drivers/usb/serial/sierra.c39
-rw-r--r--drivers/usb/serial/spcp8x5.c301
-rw-r--r--drivers/usb/serial/ssu100.c100
-rw-r--r--drivers/usb/serial/ti_usb_3410_5052.c69
-rw-r--r--drivers/usb/serial/usb-serial.c232
-rw-r--r--drivers/usb/serial/usb_wwan.c25
-rw-r--r--drivers/usb/serial/visor.c16
-rw-r--r--drivers/usb/storage/isd200.c3
-rw-r--r--drivers/usb/storage/onetouch.c4
-rw-r--r--drivers/usb/usb-common.c47
-rw-r--r--drivers/usb/usb-skeleton.c32
232 files changed, 8380 insertions, 8004 deletions
diff --git a/drivers/Makefile b/drivers/Makefile
index dce39a95fa71..3c200a243af0 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -79,7 +79,7 @@ obj-$(CONFIG_ATA_OVER_ETH) += block/aoe/
79obj-$(CONFIG_PARIDE) += block/paride/ 79obj-$(CONFIG_PARIDE) += block/paride/
80obj-$(CONFIG_TC) += tc/ 80obj-$(CONFIG_TC) += tc/
81obj-$(CONFIG_UWB) += uwb/ 81obj-$(CONFIG_UWB) += uwb/
82obj-$(CONFIG_USB_OTG_UTILS) += usb/ 82obj-$(CONFIG_USB_PHY) += usb/
83obj-$(CONFIG_USB) += usb/ 83obj-$(CONFIG_USB) += usb/
84obj-$(CONFIG_PCI) += usb/ 84obj-$(CONFIG_PCI) += usb/
85obj-$(CONFIG_USB_GADGET) += usb/ 85obj-$(CONFIG_USB_GADGET) += usb/
diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index 8e0c4bf94ebc..1f9e56bfeaa0 100644
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -1493,7 +1493,7 @@ static int hid_suspend(struct usb_interface *intf, pm_message_t message)
1493{ 1493{
1494 struct hid_device *hid = usb_get_intfdata(intf); 1494 struct hid_device *hid = usb_get_intfdata(intf);
1495 struct usbhid_device *usbhid = hid->driver_data; 1495 struct usbhid_device *usbhid = hid->driver_data;
1496 int status; 1496 int status = 0;
1497 bool driver_suspended = false; 1497 bool driver_suspended = false;
1498 1498
1499 if (PMSG_IS_AUTO(message)) { 1499 if (PMSG_IS_AUTO(message)) {
@@ -1520,19 +1520,15 @@ static int hid_suspend(struct usb_interface *intf, pm_message_t message)
1520 } 1520 }
1521 1521
1522 } else { 1522 } else {
1523 if (hid->driver && hid->driver->suspend) { 1523 /* TODO: resume() might need to handle suspend failure */
1524 if (hid->driver && hid->driver->suspend)
1524 status = hid->driver->suspend(hid, message); 1525 status = hid->driver->suspend(hid, message);
1525 if (status < 0)
1526 return status;
1527 }
1528 driver_suspended = true; 1526 driver_suspended = true;
1529 spin_lock_irq(&usbhid->lock); 1527 spin_lock_irq(&usbhid->lock);
1530 set_bit(HID_SUSPENDED, &usbhid->iofl); 1528 set_bit(HID_SUSPENDED, &usbhid->iofl);
1531 spin_unlock_irq(&usbhid->lock); 1529 spin_unlock_irq(&usbhid->lock);
1532 if (usbhid_wait_io(hid) < 0) { 1530 if (usbhid_wait_io(hid) < 0)
1533 status = -EIO; 1531 status = -EIO;
1534 goto failed;
1535 }
1536 } 1532 }
1537 1533
1538 hid_cancel_delayed_stuff(usbhid); 1534 hid_cancel_delayed_stuff(usbhid);
@@ -1544,7 +1540,7 @@ static int hid_suspend(struct usb_interface *intf, pm_message_t message)
1544 goto failed; 1540 goto failed;
1545 } 1541 }
1546 dev_dbg(&intf->dev, "suspend\n"); 1542 dev_dbg(&intf->dev, "suspend\n");
1547 return 0; 1543 return status;
1548 1544
1549 failed: 1545 failed:
1550 hid_resume_common(hid, driver_suspended); 1546 hid_resume_common(hid, driver_suspended);
diff --git a/drivers/net/usb/cdc_mbim.c b/drivers/net/usb/cdc_mbim.c
index 16c842997291..673e3624713e 100644
--- a/drivers/net/usb/cdc_mbim.c
+++ b/drivers/net/usb/cdc_mbim.c
@@ -323,6 +323,11 @@ static int cdc_mbim_suspend(struct usb_interface *intf, pm_message_t message)
323 goto error; 323 goto error;
324 } 324 }
325 325
326 /*
327 * Both usbnet_suspend() and subdriver->suspend() MUST return 0
328 * in system sleep context, otherwise, the resume callback has
329 * to recover device from previous suspend failure.
330 */
326 ret = usbnet_suspend(intf, message); 331 ret = usbnet_suspend(intf, message);
327 if (ret < 0) 332 if (ret < 0)
328 goto error; 333 goto error;
diff --git a/drivers/net/usb/qmi_wwan.c b/drivers/net/usb/qmi_wwan.c
index 968d5d50751d..bdceb7411de3 100644
--- a/drivers/net/usb/qmi_wwan.c
+++ b/drivers/net/usb/qmi_wwan.c
@@ -271,6 +271,11 @@ static int qmi_wwan_suspend(struct usb_interface *intf, pm_message_t message)
271 struct qmi_wwan_state *info = (void *)&dev->data; 271 struct qmi_wwan_state *info = (void *)&dev->data;
272 int ret; 272 int ret;
273 273
274 /*
275 * Both usbnet_suspend() and subdriver->suspend() MUST return 0
276 * in system sleep context, otherwise, the resume callback has
277 * to recover device from previous suspend failure.
278 */
274 ret = usbnet_suspend(intf, message); 279 ret = usbnet_suspend(intf, message);
275 if (ret < 0) 280 if (ret < 0)
276 goto err; 281 goto err;
diff --git a/drivers/net/usb/smsc75xx.c b/drivers/net/usb/smsc75xx.c
index 1a15ec14c386..75409748c774 100644
--- a/drivers/net/usb/smsc75xx.c
+++ b/drivers/net/usb/smsc75xx.c
@@ -2015,7 +2015,11 @@ static int smsc75xx_suspend(struct usb_interface *intf, pm_message_t message)
2015 ret = smsc75xx_enter_suspend0(dev); 2015 ret = smsc75xx_enter_suspend0(dev);
2016 2016
2017done: 2017done:
2018 if (ret) 2018 /*
2019 * TODO: resume() might need to handle the suspend failure
2020 * in system sleep
2021 */
2022 if (ret && PMSG_IS_AUTO(message))
2019 usbnet_resume(intf); 2023 usbnet_resume(intf);
2020 return ret; 2024 return ret;
2021} 2025}
diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c
index e6d2dea1373c..3f38ba868f61 100644
--- a/drivers/net/usb/smsc95xx.c
+++ b/drivers/net/usb/smsc95xx.c
@@ -1660,7 +1660,11 @@ static int smsc95xx_suspend(struct usb_interface *intf, pm_message_t message)
1660 ret = smsc95xx_enter_suspend0(dev); 1660 ret = smsc95xx_enter_suspend0(dev);
1661 1661
1662done: 1662done:
1663 if (ret) 1663 /*
1664 * TODO: resume() might need to handle the suspend failure
1665 * in system sleep
1666 */
1667 if (ret && PMSG_IS_AUTO(message))
1664 usbnet_resume(intf); 1668 usbnet_resume(intf);
1665 return ret; 1669 return ret;
1666} 1670}
diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index 9e00c389e777..ffe02fb7cbc7 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -254,7 +254,7 @@ config BATTERY_RX51
254 254
255config CHARGER_ISP1704 255config CHARGER_ISP1704
256 tristate "ISP1704 USB Charger Detection" 256 tristate "ISP1704 USB Charger Detection"
257 depends on USB_OTG_UTILS 257 depends on USB_PHY
258 help 258 help
259 Say Y to enable support for USB Charger Detection with 259 Say Y to enable support for USB Charger Detection with
260 ISP1707/ISP1704 USB transceivers. 260 ISP1707/ISP1704 USB transceivers.
diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
index 7df7c5facc10..0c52e2a0d90c 100644
--- a/drivers/power/pda_power.c
+++ b/drivers/power/pda_power.c
@@ -35,7 +35,7 @@ static struct timer_list supply_timer;
35static struct timer_list polling_timer; 35static struct timer_list polling_timer;
36static int polling; 36static int polling;
37 37
38#ifdef CONFIG_USB_OTG_UTILS 38#if IS_ENABLED(CONFIG_USB_PHY)
39static struct usb_phy *transceiver; 39static struct usb_phy *transceiver;
40static struct notifier_block otg_nb; 40static struct notifier_block otg_nb;
41#endif 41#endif
@@ -218,7 +218,7 @@ static void polling_timer_func(unsigned long unused)
218 jiffies + msecs_to_jiffies(pdata->polling_interval)); 218 jiffies + msecs_to_jiffies(pdata->polling_interval));
219} 219}
220 220
221#ifdef CONFIG_USB_OTG_UTILS 221#if IS_ENABLED(CONFIG_USB_PHY)
222static int otg_is_usb_online(void) 222static int otg_is_usb_online(void)
223{ 223{
224 return (transceiver->last_event == USB_EVENT_VBUS || 224 return (transceiver->last_event == USB_EVENT_VBUS ||
@@ -315,7 +315,7 @@ static int pda_power_probe(struct platform_device *pdev)
315 pda_psy_usb.num_supplicants = pdata->num_supplicants; 315 pda_psy_usb.num_supplicants = pdata->num_supplicants;
316 } 316 }
317 317
318#ifdef CONFIG_USB_OTG_UTILS 318#if IS_ENABLED(CONFIG_USB_PHY)
319 transceiver = usb_get_phy(USB_PHY_TYPE_USB2); 319 transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
320 if (!IS_ERR_OR_NULL(transceiver)) { 320 if (!IS_ERR_OR_NULL(transceiver)) {
321 if (!pdata->is_usb_online) 321 if (!pdata->is_usb_online)
@@ -367,7 +367,7 @@ static int pda_power_probe(struct platform_device *pdev)
367 } 367 }
368 } 368 }
369 369
370#ifdef CONFIG_USB_OTG_UTILS 370#if IS_ENABLED(CONFIG_USB_PHY)
371 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) { 371 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
372 otg_nb.notifier_call = otg_handle_notification; 372 otg_nb.notifier_call = otg_handle_notification;
373 ret = usb_register_notifier(transceiver, &otg_nb); 373 ret = usb_register_notifier(transceiver, &otg_nb);
@@ -391,7 +391,7 @@ static int pda_power_probe(struct platform_device *pdev)
391 391
392 return 0; 392 return 0;
393 393
394#ifdef CONFIG_USB_OTG_UTILS 394#if IS_ENABLED(CONFIG_USB_PHY)
395otg_reg_notifier_failed: 395otg_reg_notifier_failed:
396 if (pdata->is_usb_online && usb_irq) 396 if (pdata->is_usb_online && usb_irq)
397 free_irq(usb_irq->start, &pda_psy_usb); 397 free_irq(usb_irq->start, &pda_psy_usb);
@@ -402,7 +402,7 @@ usb_irq_failed:
402usb_supply_failed: 402usb_supply_failed:
403 if (pdata->is_ac_online && ac_irq) 403 if (pdata->is_ac_online && ac_irq)
404 free_irq(ac_irq->start, &pda_psy_ac); 404 free_irq(ac_irq->start, &pda_psy_ac);
405#ifdef CONFIG_USB_OTG_UTILS 405#if IS_ENABLED(CONFIG_USB_PHY)
406 if (!IS_ERR_OR_NULL(transceiver)) 406 if (!IS_ERR_OR_NULL(transceiver))
407 usb_put_phy(transceiver); 407 usb_put_phy(transceiver);
408#endif 408#endif
@@ -437,7 +437,7 @@ static int pda_power_remove(struct platform_device *pdev)
437 power_supply_unregister(&pda_psy_usb); 437 power_supply_unregister(&pda_psy_usb);
438 if (pdata->is_ac_online) 438 if (pdata->is_ac_online)
439 power_supply_unregister(&pda_psy_ac); 439 power_supply_unregister(&pda_psy_ac);
440#ifdef CONFIG_USB_OTG_UTILS 440#if IS_ENABLED(CONFIG_USB_PHY)
441 if (!IS_ERR_OR_NULL(transceiver)) 441 if (!IS_ERR_OR_NULL(transceiver))
442 usb_put_phy(transceiver); 442 usb_put_phy(transceiver);
443#endif 443#endif
diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
index 093f10c88cce..659855cecda5 100644
--- a/drivers/staging/Kconfig
+++ b/drivers/staging/Kconfig
@@ -116,8 +116,6 @@ source "drivers/staging/android/Kconfig"
116 116
117source "drivers/staging/ozwpan/Kconfig" 117source "drivers/staging/ozwpan/Kconfig"
118 118
119source "drivers/staging/ccg/Kconfig"
120
121source "drivers/staging/gdm72xx/Kconfig" 119source "drivers/staging/gdm72xx/Kconfig"
122 120
123source "drivers/staging/csr/Kconfig" 121source "drivers/staging/csr/Kconfig"
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
index fa41b04cf4cb..b367ea876854 100644
--- a/drivers/staging/Makefile
+++ b/drivers/staging/Makefile
@@ -50,7 +50,6 @@ obj-$(CONFIG_TOUCHSCREEN_SYNAPTICS_I2C_RMI4) += ste_rmi4/
50obj-$(CONFIG_MFD_NVEC) += nvec/ 50obj-$(CONFIG_MFD_NVEC) += nvec/
51obj-$(CONFIG_ANDROID) += android/ 51obj-$(CONFIG_ANDROID) += android/
52obj-$(CONFIG_USB_WPAN_HCD) += ozwpan/ 52obj-$(CONFIG_USB_WPAN_HCD) += ozwpan/
53obj-$(CONFIG_USB_G_CCG) += ccg/
54obj-$(CONFIG_WIMAX_GDM72XX) += gdm72xx/ 53obj-$(CONFIG_WIMAX_GDM72XX) += gdm72xx/
55obj-$(CONFIG_CSR_WIFI) += csr/ 54obj-$(CONFIG_CSR_WIFI) += csr/
56obj-$(CONFIG_OMAP_BANDGAP) += omap-thermal/ 55obj-$(CONFIG_OMAP_BANDGAP) += omap-thermal/
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index 640ae6c6d2d2..2c481b808276 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -186,6 +186,4 @@ source "drivers/usb/atm/Kconfig"
186 186
187source "drivers/usb/gadget/Kconfig" 187source "drivers/usb/gadget/Kconfig"
188 188
189source "drivers/usb/otg/Kconfig"
190
191endif # USB_SUPPORT 189endif # USB_SUPPORT
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index 8f5ebced5df0..c41feba8d5c0 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -6,8 +6,6 @@
6 6
7obj-$(CONFIG_USB) += core/ 7obj-$(CONFIG_USB) += core/
8 8
9obj-$(CONFIG_USB_OTG_UTILS) += otg/
10
11obj-$(CONFIG_USB_DWC3) += dwc3/ 9obj-$(CONFIG_USB_DWC3) += dwc3/
12 10
13obj-$(CONFIG_USB_MON) += mon/ 11obj-$(CONFIG_USB_MON) += mon/
@@ -46,7 +44,7 @@ obj-$(CONFIG_USB_MICROTEK) += image/
46obj-$(CONFIG_USB_SERIAL) += serial/ 44obj-$(CONFIG_USB_SERIAL) += serial/
47 45
48obj-$(CONFIG_USB) += misc/ 46obj-$(CONFIG_USB) += misc/
49obj-$(CONFIG_USB_OTG_UTILS) += phy/ 47obj-$(CONFIG_USB_PHY) += phy/
50obj-$(CONFIG_EARLY_PRINTK_DBGP) += early/ 48obj-$(CONFIG_EARLY_PRINTK_DBGP) += early/
51 49
52obj-$(CONFIG_USB_ATM) += atm/ 50obj-$(CONFIG_USB_ATM) += atm/
diff --git a/drivers/usb/chipidea/Makefile b/drivers/usb/chipidea/Makefile
index d92ca325b104..4ab83e98219b 100644
--- a/drivers/usb/chipidea/Makefile
+++ b/drivers/usb/chipidea/Makefile
@@ -17,5 +17,5 @@ ifneq ($(CONFIG_PCI),)
17endif 17endif
18 18
19ifneq ($(CONFIG_OF_DEVICE),) 19ifneq ($(CONFIG_OF_DEVICE),)
20 obj-$(CONFIG_USB_CHIPIDEA) += ci13xxx_imx.o usbmisc_imx6q.o 20 obj-$(CONFIG_USB_CHIPIDEA) += ci13xxx_imx.o usbmisc_imx.o
21endif 21endif
diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h
index e25d1263da13..b0a6bce064ca 100644
--- a/drivers/usb/chipidea/ci.h
+++ b/drivers/usb/chipidea/ci.h
@@ -21,6 +21,7 @@
21/****************************************************************************** 21/******************************************************************************
22 * DEFINE 22 * DEFINE
23 *****************************************************************************/ 23 *****************************************************************************/
24#define TD_PAGE_COUNT 5
24#define CI13XXX_PAGE_SIZE 4096ul /* page size for TD's */ 25#define CI13XXX_PAGE_SIZE 4096ul /* page size for TD's */
25#define ENDPT_MAX 32 26#define ENDPT_MAX 32
26 27
@@ -129,6 +130,7 @@ struct hw_bank {
129 * @vbus_active: is VBUS active 130 * @vbus_active: is VBUS active
130 * @transceiver: pointer to USB PHY, if any 131 * @transceiver: pointer to USB PHY, if any
131 * @hcd: pointer to usb_hcd for ehci host driver 132 * @hcd: pointer to usb_hcd for ehci host driver
133 * @debugfs: root dentry for this controller in debugfs
132 */ 134 */
133struct ci13xxx { 135struct ci13xxx {
134 struct device *dev; 136 struct device *dev;
@@ -139,7 +141,6 @@ struct ci13xxx {
139 enum ci_role role; 141 enum ci_role role;
140 bool is_otg; 142 bool is_otg;
141 struct work_struct work; 143 struct work_struct work;
142 struct work_struct vbus_work;
143 struct workqueue_struct *wq; 144 struct workqueue_struct *wq;
144 145
145 struct dma_pool *qh_pool; 146 struct dma_pool *qh_pool;
@@ -165,6 +166,7 @@ struct ci13xxx {
165 bool global_phy; 166 bool global_phy;
166 struct usb_phy *transceiver; 167 struct usb_phy *transceiver;
167 struct usb_hcd *hcd; 168 struct usb_hcd *hcd;
169 struct dentry *debugfs;
168}; 170};
169 171
170static inline struct ci_role_driver *ci_role(struct ci13xxx *ci) 172static inline struct ci_role_driver *ci_role(struct ci13xxx *ci)
@@ -234,19 +236,6 @@ enum ci13xxx_regs {
234}; 236};
235 237
236/** 238/**
237 * ffs_nr: find first (least significant) bit set
238 * @x: the word to search
239 *
240 * This function returns bit number (instead of position)
241 */
242static inline int ffs_nr(u32 x)
243{
244 int n = ffs(x);
245
246 return n ? n-1 : 32;
247}
248
249/**
250 * hw_read: reads from a hw register 239 * hw_read: reads from a hw register
251 * @reg: register index 240 * @reg: register index
252 * @mask: bitfield mask 241 * @mask: bitfield mask
@@ -304,7 +293,7 @@ static inline u32 hw_test_and_write(struct ci13xxx *ci, enum ci13xxx_regs reg,
304 u32 val = hw_read(ci, reg, ~0); 293 u32 val = hw_read(ci, reg, ~0);
305 294
306 hw_write(ci, reg, mask, data); 295 hw_write(ci, reg, mask, data);
307 return (val & mask) >> ffs_nr(mask); 296 return (val & mask) >> __ffs(mask);
308} 297}
309 298
310int hw_device_reset(struct ci13xxx *ci, u32 mode); 299int hw_device_reset(struct ci13xxx *ci, u32 mode);
diff --git a/drivers/usb/chipidea/ci13xxx_imx.c b/drivers/usb/chipidea/ci13xxx_imx.c
index 8c291220be7f..8faec9dbbb84 100644
--- a/drivers/usb/chipidea/ci13xxx_imx.c
+++ b/drivers/usb/chipidea/ci13xxx_imx.c
@@ -79,6 +79,9 @@ int usbmisc_get_init_data(struct device *dev, struct usbmisc_usb_device *usbdev)
79 if (of_find_property(np, "disable-over-current", NULL)) 79 if (of_find_property(np, "disable-over-current", NULL))
80 usbdev->disable_oc = 1; 80 usbdev->disable_oc = 1;
81 81
82 if (of_find_property(np, "external-vbus-divider", NULL))
83 usbdev->evdo = 1;
84
82 return 0; 85 return 0;
83} 86}
84EXPORT_SYMBOL_GPL(usbmisc_get_init_data); 87EXPORT_SYMBOL_GPL(usbmisc_get_init_data);
@@ -202,6 +205,15 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
202 goto err; 205 goto err;
203 } 206 }
204 207
208 if (usbmisc_ops && usbmisc_ops->post) {
209 ret = usbmisc_ops->post(&pdev->dev);
210 if (ret) {
211 dev_err(&pdev->dev,
212 "usbmisc post failed, ret=%d\n", ret);
213 goto put_np;
214 }
215 }
216
205 data->ci_pdev = plat_ci; 217 data->ci_pdev = plat_ci;
206 platform_set_drvdata(pdev, data); 218 platform_set_drvdata(pdev, data);
207 219
diff --git a/drivers/usb/chipidea/ci13xxx_imx.h b/drivers/usb/chipidea/ci13xxx_imx.h
index 9cd2e910b1ca..550bfa457620 100644
--- a/drivers/usb/chipidea/ci13xxx_imx.h
+++ b/drivers/usb/chipidea/ci13xxx_imx.h
@@ -13,6 +13,8 @@
13struct usbmisc_ops { 13struct usbmisc_ops {
14 /* It's called once when probe a usb device */ 14 /* It's called once when probe a usb device */
15 int (*init)(struct device *dev); 15 int (*init)(struct device *dev);
16 /* It's called once after adding a usb device */
17 int (*post)(struct device *dev);
16}; 18};
17 19
18struct usbmisc_usb_device { 20struct usbmisc_usb_device {
@@ -20,6 +22,7 @@ struct usbmisc_usb_device {
20 int index; 22 int index;
21 23
22 unsigned int disable_oc:1; /* over current detect disabled */ 24 unsigned int disable_oc:1; /* over current detect disabled */
25 unsigned int evdo:1; /* set external vbus divider option */
23}; 26};
24 27
25int usbmisc_set_ops(const struct usbmisc_ops *ops); 28int usbmisc_set_ops(const struct usbmisc_ops *ops);
diff --git a/drivers/usb/chipidea/ci13xxx_pci.c b/drivers/usb/chipidea/ci13xxx_pci.c
index 9b227e39299a..4e1fc61b9d95 100644
--- a/drivers/usb/chipidea/ci13xxx_pci.c
+++ b/drivers/usb/chipidea/ci13xxx_pci.c
@@ -23,17 +23,17 @@
23/****************************************************************************** 23/******************************************************************************
24 * PCI block 24 * PCI block
25 *****************************************************************************/ 25 *****************************************************************************/
26struct ci13xxx_platform_data pci_platdata = { 26static struct ci13xxx_platform_data pci_platdata = {
27 .name = UDC_DRIVER_NAME, 27 .name = UDC_DRIVER_NAME,
28 .capoffset = DEF_CAPOFFSET, 28 .capoffset = DEF_CAPOFFSET,
29}; 29};
30 30
31struct ci13xxx_platform_data langwell_pci_platdata = { 31static struct ci13xxx_platform_data langwell_pci_platdata = {
32 .name = UDC_DRIVER_NAME, 32 .name = UDC_DRIVER_NAME,
33 .capoffset = 0, 33 .capoffset = 0,
34}; 34};
35 35
36struct ci13xxx_platform_data penwell_pci_platdata = { 36static struct ci13xxx_platform_data penwell_pci_platdata = {
37 .name = UDC_DRIVER_NAME, 37 .name = UDC_DRIVER_NAME,
38 .capoffset = 0, 38 .capoffset = 0,
39 .power_budget = 200, 39 .power_budget = 200,
diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
index 57cae1f897b2..450107e5f657 100644
--- a/drivers/usb/chipidea/core.c
+++ b/drivers/usb/chipidea/core.c
@@ -51,15 +51,12 @@
51 */ 51 */
52#include <linux/delay.h> 52#include <linux/delay.h>
53#include <linux/device.h> 53#include <linux/device.h>
54#include <linux/dmapool.h>
55#include <linux/dma-mapping.h> 54#include <linux/dma-mapping.h>
56#include <linux/init.h>
57#include <linux/platform_device.h> 55#include <linux/platform_device.h>
58#include <linux/module.h> 56#include <linux/module.h>
59#include <linux/idr.h> 57#include <linux/idr.h>
60#include <linux/interrupt.h> 58#include <linux/interrupt.h>
61#include <linux/io.h> 59#include <linux/io.h>
62#include <linux/irq.h>
63#include <linux/kernel.h> 60#include <linux/kernel.h>
64#include <linux/slab.h> 61#include <linux/slab.h>
65#include <linux/pm_runtime.h> 62#include <linux/pm_runtime.h>
@@ -158,7 +155,7 @@ int hw_port_test_set(struct ci13xxx *ci, u8 mode)
158 if (mode > TEST_MODE_MAX) 155 if (mode > TEST_MODE_MAX)
159 return -EINVAL; 156 return -EINVAL;
160 157
161 hw_write(ci, OP_PORTSC, PORTSC_PTC, mode << ffs_nr(PORTSC_PTC)); 158 hw_write(ci, OP_PORTSC, PORTSC_PTC, mode << __ffs(PORTSC_PTC));
162 return 0; 159 return 0;
163} 160}
164 161
@@ -169,7 +166,7 @@ int hw_port_test_set(struct ci13xxx *ci, u8 mode)
169 */ 166 */
170u8 hw_port_test_get(struct ci13xxx *ci) 167u8 hw_port_test_get(struct ci13xxx *ci)
171{ 168{
172 return hw_read(ci, OP_PORTSC, PORTSC_PTC) >> ffs_nr(PORTSC_PTC); 169 return hw_read(ci, OP_PORTSC, PORTSC_PTC) >> __ffs(PORTSC_PTC);
173} 170}
174 171
175static int hw_device_init(struct ci13xxx *ci, void __iomem *base) 172static int hw_device_init(struct ci13xxx *ci, void __iomem *base)
@@ -181,11 +178,11 @@ static int hw_device_init(struct ci13xxx *ci, void __iomem *base)
181 178
182 ci->hw_bank.cap = ci->hw_bank.abs; 179 ci->hw_bank.cap = ci->hw_bank.abs;
183 ci->hw_bank.cap += ci->platdata->capoffset; 180 ci->hw_bank.cap += ci->platdata->capoffset;
184 ci->hw_bank.op = ci->hw_bank.cap + ioread8(ci->hw_bank.cap); 181 ci->hw_bank.op = ci->hw_bank.cap + (ioread32(ci->hw_bank.cap) & 0xff);
185 182
186 hw_alloc_regmap(ci, false); 183 hw_alloc_regmap(ci, false);
187 reg = hw_read(ci, CAP_HCCPARAMS, HCCPARAMS_LEN) >> 184 reg = hw_read(ci, CAP_HCCPARAMS, HCCPARAMS_LEN) >>
188 ffs_nr(HCCPARAMS_LEN); 185 __ffs(HCCPARAMS_LEN);
189 ci->hw_bank.lpm = reg; 186 ci->hw_bank.lpm = reg;
190 hw_alloc_regmap(ci, !!reg); 187 hw_alloc_regmap(ci, !!reg);
191 ci->hw_bank.size = ci->hw_bank.op - ci->hw_bank.abs; 188 ci->hw_bank.size = ci->hw_bank.op - ci->hw_bank.abs;
@@ -193,7 +190,7 @@ static int hw_device_init(struct ci13xxx *ci, void __iomem *base)
193 ci->hw_bank.size /= sizeof(u32); 190 ci->hw_bank.size /= sizeof(u32);
194 191
195 reg = hw_read(ci, CAP_DCCPARAMS, DCCPARAMS_DEN) >> 192 reg = hw_read(ci, CAP_DCCPARAMS, DCCPARAMS_DEN) >>
196 ffs_nr(DCCPARAMS_DEN); 193 __ffs(DCCPARAMS_DEN);
197 ci->hw_ep_max = reg * 2; /* cache hw ENDPT_MAX */ 194 ci->hw_ep_max = reg * 2; /* cache hw ENDPT_MAX */
198 195
199 if (ci->hw_ep_max > ENDPT_MAX) 196 if (ci->hw_ep_max > ENDPT_MAX)
@@ -283,38 +280,6 @@ static void ci_role_work(struct work_struct *work)
283 } 280 }
284} 281}
285 282
286static ssize_t show_role(struct device *dev, struct device_attribute *attr,
287 char *buf)
288{
289 struct ci13xxx *ci = dev_get_drvdata(dev);
290
291 return sprintf(buf, "%s\n", ci_role(ci)->name);
292}
293
294static ssize_t store_role(struct device *dev, struct device_attribute *attr,
295 const char *buf, size_t count)
296{
297 struct ci13xxx *ci = dev_get_drvdata(dev);
298 enum ci_role role;
299 int ret;
300
301 for (role = CI_ROLE_HOST; role < CI_ROLE_END; role++)
302 if (ci->roles[role] && !strcmp(buf, ci->roles[role]->name))
303 break;
304
305 if (role == CI_ROLE_END || role == ci->role)
306 return -EINVAL;
307
308 ci_role_stop(ci);
309 ret = ci_role_start(ci, role);
310 if (ret)
311 return ret;
312
313 return count;
314}
315
316static DEVICE_ATTR(role, S_IRUSR | S_IWUSR, show_role, store_role);
317
318static irqreturn_t ci_irq(int irq, void *data) 283static irqreturn_t ci_irq(int irq, void *data)
319{ 284{
320 struct ci13xxx *ci = data; 285 struct ci13xxx *ci = data;
@@ -410,11 +375,9 @@ static int ci_hdrc_probe(struct platform_device *pdev)
410 return -ENODEV; 375 return -ENODEV;
411 } 376 }
412 377
413 base = devm_request_and_ioremap(dev, res); 378 base = devm_ioremap_resource(dev, res);
414 if (!base) { 379 if (IS_ERR(base))
415 dev_err(dev, "can't request and ioremap resource\n"); 380 return PTR_ERR(base);
416 return -ENOMEM;
417 }
418 381
419 ci = devm_kzalloc(dev, sizeof(*ci), GFP_KERNEL); 382 ci = devm_kzalloc(dev, sizeof(*ci), GFP_KERNEL);
420 if (!ci) { 383 if (!ci) {
@@ -489,17 +452,14 @@ static int ci_hdrc_probe(struct platform_device *pdev)
489 if (ret) 452 if (ret)
490 goto stop; 453 goto stop;
491 454
492 ret = device_create_file(dev, &dev_attr_role);
493 if (ret)
494 goto rm_attr;
495
496 if (ci->is_otg) 455 if (ci->is_otg)
497 hw_write(ci, OP_OTGSC, OTGSC_IDIE, OTGSC_IDIE); 456 hw_write(ci, OP_OTGSC, OTGSC_IDIE, OTGSC_IDIE);
498 457
499 return ret; 458 ret = dbg_create_files(ci);
459 if (!ret)
460 return 0;
500 461
501rm_attr: 462 free_irq(ci->irq, ci);
502 device_remove_file(dev, &dev_attr_role);
503stop: 463stop:
504 ci_role_stop(ci); 464 ci_role_stop(ci);
505rm_wq: 465rm_wq:
@@ -513,9 +473,9 @@ static int ci_hdrc_remove(struct platform_device *pdev)
513{ 473{
514 struct ci13xxx *ci = platform_get_drvdata(pdev); 474 struct ci13xxx *ci = platform_get_drvdata(pdev);
515 475
476 dbg_remove_files(ci);
516 flush_workqueue(ci->wq); 477 flush_workqueue(ci->wq);
517 destroy_workqueue(ci->wq); 478 destroy_workqueue(ci->wq);
518 device_remove_file(ci->dev, &dev_attr_role);
519 free_irq(ci->irq, ci); 479 free_irq(ci->irq, ci);
520 ci_role_stop(ci); 480 ci_role_stop(ci);
521 481
diff --git a/drivers/usb/chipidea/debug.c b/drivers/usb/chipidea/debug.c
index a62c4a47d52c..36a7063a6cba 100644
--- a/drivers/usb/chipidea/debug.c
+++ b/drivers/usb/chipidea/debug.c
@@ -1,590 +1,126 @@
1#include <linux/delay.h>
2#include <linux/device.h>
3#include <linux/dmapool.h>
4#include <linux/dma-mapping.h>
5#include <linux/init.h>
6#include <linux/platform_device.h>
7#include <linux/module.h>
8#include <linux/interrupt.h>
9#include <linux/io.h>
10#include <linux/irq.h>
11#include <linux/kernel.h> 1#include <linux/kernel.h>
12#include <linux/slab.h> 2#include <linux/device.h>
13#include <linux/pm_runtime.h> 3#include <linux/types.h>
4#include <linux/spinlock.h>
5#include <linux/debugfs.h>
6#include <linux/seq_file.h>
7#include <linux/uaccess.h>
14#include <linux/usb/ch9.h> 8#include <linux/usb/ch9.h>
15#include <linux/usb/gadget.h> 9#include <linux/usb/gadget.h>
16#include <linux/usb/otg.h>
17#include <linux/usb/chipidea.h>
18 10
19#include "ci.h" 11#include "ci.h"
20#include "udc.h" 12#include "udc.h"
21#include "bits.h" 13#include "bits.h"
22#include "debug.h" 14#include "debug.h"
23 15
24/* Interrupt statistics */
25#define ISR_MASK 0x1F
26static struct isr_statistics {
27 u32 test;
28 u32 ui;
29 u32 uei;
30 u32 pci;
31 u32 uri;
32 u32 sli;
33 u32 none;
34 struct {
35 u32 cnt;
36 u32 buf[ISR_MASK+1];
37 u32 idx;
38 } hndl;
39} isr_statistics;
40
41void dbg_interrupt(u32 intmask)
42{
43 if (!intmask) {
44 isr_statistics.none++;
45 return;
46 }
47
48 isr_statistics.hndl.buf[isr_statistics.hndl.idx++] = intmask;
49 isr_statistics.hndl.idx &= ISR_MASK;
50 isr_statistics.hndl.cnt++;
51
52 if (USBi_URI & intmask)
53 isr_statistics.uri++;
54 if (USBi_PCI & intmask)
55 isr_statistics.pci++;
56 if (USBi_UEI & intmask)
57 isr_statistics.uei++;
58 if (USBi_UI & intmask)
59 isr_statistics.ui++;
60 if (USBi_SLI & intmask)
61 isr_statistics.sli++;
62}
63
64/** 16/**
65 * hw_register_read: reads all device registers (execute without interruption) 17 * ci_device_show: prints information about device capabilities and status
66 * @buf: destination buffer
67 * @size: buffer size
68 *
69 * This function returns number of registers read
70 */ 18 */
71static size_t hw_register_read(struct ci13xxx *ci, u32 *buf, size_t size) 19static int ci_device_show(struct seq_file *s, void *data)
72{ 20{
73 unsigned i; 21 struct ci13xxx *ci = s->private;
74
75 if (size > ci->hw_bank.size)
76 size = ci->hw_bank.size;
77
78 for (i = 0; i < size; i++)
79 buf[i] = hw_read(ci, i * sizeof(u32), ~0);
80
81 return size;
82}
83
84/**
85 * hw_register_write: writes to register
86 * @addr: register address
87 * @data: register value
88 *
89 * This function returns an error code
90 */
91static int hw_register_write(struct ci13xxx *ci, u16 addr, u32 data)
92{
93 /* align */
94 addr /= sizeof(u32);
95
96 if (addr >= ci->hw_bank.size)
97 return -EINVAL;
98
99 /* align */
100 addr *= sizeof(u32);
101
102 hw_write(ci, addr, ~0, data);
103 return 0;
104}
105
106/**
107 * hw_intr_clear: disables interrupt & clears interrupt status (execute without
108 * interruption)
109 * @n: interrupt bit
110 *
111 * This function returns an error code
112 */
113static int hw_intr_clear(struct ci13xxx *ci, int n)
114{
115 if (n >= REG_BITS)
116 return -EINVAL;
117
118 hw_write(ci, OP_USBINTR, BIT(n), 0);
119 hw_write(ci, OP_USBSTS, BIT(n), BIT(n));
120 return 0;
121}
122
123/**
124 * hw_intr_force: enables interrupt & forces interrupt status (execute without
125 * interruption)
126 * @n: interrupt bit
127 *
128 * This function returns an error code
129 */
130static int hw_intr_force(struct ci13xxx *ci, int n)
131{
132 if (n >= REG_BITS)
133 return -EINVAL;
134
135 hw_write(ci, CAP_TESTMODE, TESTMODE_FORCE, TESTMODE_FORCE);
136 hw_write(ci, OP_USBINTR, BIT(n), BIT(n));
137 hw_write(ci, OP_USBSTS, BIT(n), BIT(n));
138 hw_write(ci, CAP_TESTMODE, TESTMODE_FORCE, 0);
139 return 0;
140}
141
142/**
143 * show_device: prints information about device capabilities and status
144 *
145 * Check "device.h" for details
146 */
147static ssize_t show_device(struct device *dev, struct device_attribute *attr,
148 char *buf)
149{
150 struct ci13xxx *ci = container_of(dev, struct ci13xxx, gadget.dev);
151 struct usb_gadget *gadget = &ci->gadget; 22 struct usb_gadget *gadget = &ci->gadget;
152 int n = 0;
153 23
154 if (attr == NULL || buf == NULL) { 24 seq_printf(s, "speed = %d\n", gadget->speed);
155 dev_err(ci->dev, "[%s] EINVAL\n", __func__); 25 seq_printf(s, "max_speed = %d\n", gadget->max_speed);
26 seq_printf(s, "is_otg = %d\n", gadget->is_otg);
27 seq_printf(s, "is_a_peripheral = %d\n", gadget->is_a_peripheral);
28 seq_printf(s, "b_hnp_enable = %d\n", gadget->b_hnp_enable);
29 seq_printf(s, "a_hnp_support = %d\n", gadget->a_hnp_support);
30 seq_printf(s, "a_alt_hnp_support = %d\n", gadget->a_alt_hnp_support);
31 seq_printf(s, "name = %s\n",
32 (gadget->name ? gadget->name : ""));
33
34 if (!ci->driver)
156 return 0; 35 return 0;
157 }
158
159 n += scnprintf(buf + n, PAGE_SIZE - n, "speed = %d\n",
160 gadget->speed);
161 n += scnprintf(buf + n, PAGE_SIZE - n, "max_speed = %d\n",
162 gadget->max_speed);
163 n += scnprintf(buf + n, PAGE_SIZE - n, "is_otg = %d\n",
164 gadget->is_otg);
165 n += scnprintf(buf + n, PAGE_SIZE - n, "is_a_peripheral = %d\n",
166 gadget->is_a_peripheral);
167 n += scnprintf(buf + n, PAGE_SIZE - n, "b_hnp_enable = %d\n",
168 gadget->b_hnp_enable);
169 n += scnprintf(buf + n, PAGE_SIZE - n, "a_hnp_support = %d\n",
170 gadget->a_hnp_support);
171 n += scnprintf(buf + n, PAGE_SIZE - n, "a_alt_hnp_support = %d\n",
172 gadget->a_alt_hnp_support);
173 n += scnprintf(buf + n, PAGE_SIZE - n, "name = %s\n",
174 (gadget->name ? gadget->name : ""));
175
176 return n;
177}
178static DEVICE_ATTR(device, S_IRUSR, show_device, NULL);
179
180/**
181 * show_driver: prints information about attached gadget (if any)
182 *
183 * Check "device.h" for details
184 */
185static ssize_t show_driver(struct device *dev, struct device_attribute *attr,
186 char *buf)
187{
188 struct ci13xxx *ci = container_of(dev, struct ci13xxx, gadget.dev);
189 struct usb_gadget_driver *driver = ci->driver;
190 int n = 0;
191
192 if (attr == NULL || buf == NULL) {
193 dev_err(dev, "[%s] EINVAL\n", __func__);
194 return 0;
195 }
196
197 if (driver == NULL)
198 return scnprintf(buf, PAGE_SIZE,
199 "There is no gadget attached!\n");
200 36
201 n += scnprintf(buf + n, PAGE_SIZE - n, "function = %s\n", 37 seq_printf(s, "gadget function = %s\n",
202 (driver->function ? driver->function : "")); 38 (ci->driver->function ? ci->driver->function : ""));
203 n += scnprintf(buf + n, PAGE_SIZE - n, "max speed = %d\n", 39 seq_printf(s, "gadget max speed = %d\n", ci->driver->max_speed);
204 driver->max_speed);
205 40
206 return n; 41 return 0;
207}
208static DEVICE_ATTR(driver, S_IRUSR, show_driver, NULL);
209
210/* Maximum event message length */
211#define DBG_DATA_MSG 64UL
212
213/* Maximum event messages */
214#define DBG_DATA_MAX 128UL
215
216/* Event buffer descriptor */
217static struct {
218 char (buf[DBG_DATA_MAX])[DBG_DATA_MSG]; /* buffer */
219 unsigned idx; /* index */
220 unsigned tty; /* print to console? */
221 rwlock_t lck; /* lock */
222} dbg_data = {
223 .idx = 0,
224 .tty = 0,
225 .lck = __RW_LOCK_UNLOCKED(dbg_data.lck)
226};
227
228/**
229 * dbg_dec: decrements debug event index
230 * @idx: buffer index
231 */
232static void dbg_dec(unsigned *idx)
233{
234 *idx = (*idx - 1) & (DBG_DATA_MAX-1);
235}
236
237/**
238 * dbg_inc: increments debug event index
239 * @idx: buffer index
240 */
241static void dbg_inc(unsigned *idx)
242{
243 *idx = (*idx + 1) & (DBG_DATA_MAX-1);
244}
245
246/**
247 * dbg_print: prints the common part of the event
248 * @addr: endpoint address
249 * @name: event name
250 * @status: status
251 * @extra: extra information
252 */
253static void dbg_print(u8 addr, const char *name, int status, const char *extra)
254{
255 struct timeval tval;
256 unsigned int stamp;
257 unsigned long flags;
258
259 write_lock_irqsave(&dbg_data.lck, flags);
260
261 do_gettimeofday(&tval);
262 stamp = tval.tv_sec & 0xFFFF; /* 2^32 = 4294967296. Limit to 4096s */
263 stamp = stamp * 1000000 + tval.tv_usec;
264
265 scnprintf(dbg_data.buf[dbg_data.idx], DBG_DATA_MSG,
266 "%04X\t? %02X %-7.7s %4i ?\t%s\n",
267 stamp, addr, name, status, extra);
268
269 dbg_inc(&dbg_data.idx);
270
271 write_unlock_irqrestore(&dbg_data.lck, flags);
272
273 if (dbg_data.tty != 0)
274 pr_notice("%04X\t? %02X %-7.7s %4i ?\t%s\n",
275 stamp, addr, name, status, extra);
276}
277
278/**
279 * dbg_done: prints a DONE event
280 * @addr: endpoint address
281 * @td: transfer descriptor
282 * @status: status
283 */
284void dbg_done(u8 addr, const u32 token, int status)
285{
286 char msg[DBG_DATA_MSG];
287
288 scnprintf(msg, sizeof(msg), "%d %02X",
289 (int)(token & TD_TOTAL_BYTES) >> ffs_nr(TD_TOTAL_BYTES),
290 (int)(token & TD_STATUS) >> ffs_nr(TD_STATUS));
291 dbg_print(addr, "DONE", status, msg);
292}
293
294/**
295 * dbg_event: prints a generic event
296 * @addr: endpoint address
297 * @name: event name
298 * @status: status
299 */
300void dbg_event(u8 addr, const char *name, int status)
301{
302 if (name != NULL)
303 dbg_print(addr, name, status, "");
304}
305
306/*
307 * dbg_queue: prints a QUEUE event
308 * @addr: endpoint address
309 * @req: USB request
310 * @status: status
311 */
312void dbg_queue(u8 addr, const struct usb_request *req, int status)
313{
314 char msg[DBG_DATA_MSG];
315
316 if (req != NULL) {
317 scnprintf(msg, sizeof(msg),
318 "%d %d", !req->no_interrupt, req->length);
319 dbg_print(addr, "QUEUE", status, msg);
320 }
321}
322
323/**
324 * dbg_setup: prints a SETUP event
325 * @addr: endpoint address
326 * @req: setup request
327 */
328void dbg_setup(u8 addr, const struct usb_ctrlrequest *req)
329{
330 char msg[DBG_DATA_MSG];
331
332 if (req != NULL) {
333 scnprintf(msg, sizeof(msg),
334 "%02X %02X %04X %04X %d", req->bRequestType,
335 req->bRequest, le16_to_cpu(req->wValue),
336 le16_to_cpu(req->wIndex), le16_to_cpu(req->wLength));
337 dbg_print(addr, "SETUP", 0, msg);
338 }
339} 42}
340 43
341/** 44static int ci_device_open(struct inode *inode, struct file *file)
342 * show_events: displays the event buffer
343 *
344 * Check "device.h" for details
345 */
346static ssize_t show_events(struct device *dev, struct device_attribute *attr,
347 char *buf)
348{ 45{
349 unsigned long flags; 46 return single_open(file, ci_device_show, inode->i_private);
350 unsigned i, j, n = 0;
351
352 if (attr == NULL || buf == NULL) {
353 dev_err(dev->parent, "[%s] EINVAL\n", __func__);
354 return 0;
355 }
356
357 read_lock_irqsave(&dbg_data.lck, flags);
358
359 i = dbg_data.idx;
360 for (dbg_dec(&i); i != dbg_data.idx; dbg_dec(&i)) {
361 n += strlen(dbg_data.buf[i]);
362 if (n >= PAGE_SIZE) {
363 n -= strlen(dbg_data.buf[i]);
364 break;
365 }
366 }
367 for (j = 0, dbg_inc(&i); j < n; dbg_inc(&i))
368 j += scnprintf(buf + j, PAGE_SIZE - j,
369 "%s", dbg_data.buf[i]);
370
371 read_unlock_irqrestore(&dbg_data.lck, flags);
372
373 return n;
374} 47}
375 48
376/** 49static const struct file_operations ci_device_fops = {
377 * store_events: configure if events are going to be also printed to console 50 .open = ci_device_open,
378 * 51 .read = seq_read,
379 * Check "device.h" for details 52 .llseek = seq_lseek,
380 */ 53 .release = single_release,
381static ssize_t store_events(struct device *dev, struct device_attribute *attr, 54};
382 const char *buf, size_t count)
383{
384 unsigned tty;
385
386 if (attr == NULL || buf == NULL) {
387 dev_err(dev, "[%s] EINVAL\n", __func__);
388 goto done;
389 }
390
391 if (sscanf(buf, "%u", &tty) != 1 || tty > 1) {
392 dev_err(dev, "<1|0>: enable|disable console log\n");
393 goto done;
394 }
395
396 dbg_data.tty = tty;
397 dev_info(dev, "tty = %u", dbg_data.tty);
398
399 done:
400 return count;
401}
402static DEVICE_ATTR(events, S_IRUSR | S_IWUSR, show_events, store_events);
403 55
404/** 56/**
405 * show_inters: interrupt status, enable status and historic 57 * ci_port_test_show: reads port test mode
406 *
407 * Check "device.h" for details
408 */ 58 */
409static ssize_t show_inters(struct device *dev, struct device_attribute *attr, 59static int ci_port_test_show(struct seq_file *s, void *data)
410 char *buf)
411{ 60{
412 struct ci13xxx *ci = container_of(dev, struct ci13xxx, gadget.dev); 61 struct ci13xxx *ci = s->private;
413 unsigned long flags; 62 unsigned long flags;
414 u32 intr; 63 unsigned mode;
415 unsigned i, j, n = 0;
416
417 if (attr == NULL || buf == NULL) {
418 dev_err(ci->dev, "[%s] EINVAL\n", __func__);
419 return 0;
420 }
421 64
422 spin_lock_irqsave(&ci->lock, flags); 65 spin_lock_irqsave(&ci->lock, flags);
423 66 mode = hw_port_test_get(ci);
424 /*n += scnprintf(buf + n, PAGE_SIZE - n,
425 "status = %08x\n", hw_read_intr_status(ci));
426 n += scnprintf(buf + n, PAGE_SIZE - n,
427 "enable = %08x\n", hw_read_intr_enable(ci));*/
428
429 n += scnprintf(buf + n, PAGE_SIZE - n, "*test = %d\n",
430 isr_statistics.test);
431 n += scnprintf(buf + n, PAGE_SIZE - n, "? ui = %d\n",
432 isr_statistics.ui);
433 n += scnprintf(buf + n, PAGE_SIZE - n, "? uei = %d\n",
434 isr_statistics.uei);
435 n += scnprintf(buf + n, PAGE_SIZE - n, "? pci = %d\n",
436 isr_statistics.pci);
437 n += scnprintf(buf + n, PAGE_SIZE - n, "? uri = %d\n",
438 isr_statistics.uri);
439 n += scnprintf(buf + n, PAGE_SIZE - n, "? sli = %d\n",
440 isr_statistics.sli);
441 n += scnprintf(buf + n, PAGE_SIZE - n, "*none = %d\n",
442 isr_statistics.none);
443 n += scnprintf(buf + n, PAGE_SIZE - n, "*hndl = %d\n",
444 isr_statistics.hndl.cnt);
445
446 for (i = isr_statistics.hndl.idx, j = 0; j <= ISR_MASK; j++, i++) {
447 i &= ISR_MASK;
448 intr = isr_statistics.hndl.buf[i];
449
450 if (USBi_UI & intr)
451 n += scnprintf(buf + n, PAGE_SIZE - n, "ui ");
452 intr &= ~USBi_UI;
453 if (USBi_UEI & intr)
454 n += scnprintf(buf + n, PAGE_SIZE - n, "uei ");
455 intr &= ~USBi_UEI;
456 if (USBi_PCI & intr)
457 n += scnprintf(buf + n, PAGE_SIZE - n, "pci ");
458 intr &= ~USBi_PCI;
459 if (USBi_URI & intr)
460 n += scnprintf(buf + n, PAGE_SIZE - n, "uri ");
461 intr &= ~USBi_URI;
462 if (USBi_SLI & intr)
463 n += scnprintf(buf + n, PAGE_SIZE - n, "sli ");
464 intr &= ~USBi_SLI;
465 if (intr)
466 n += scnprintf(buf + n, PAGE_SIZE - n, "??? ");
467 if (isr_statistics.hndl.buf[i])
468 n += scnprintf(buf + n, PAGE_SIZE - n, "\n");
469 }
470
471 spin_unlock_irqrestore(&ci->lock, flags); 67 spin_unlock_irqrestore(&ci->lock, flags);
472 68
473 return n; 69 seq_printf(s, "mode = %u\n", mode);
474}
475
476/**
477 * store_inters: enable & force or disable an individual interrutps
478 * (to be used for test purposes only)
479 *
480 * Check "device.h" for details
481 */
482static ssize_t store_inters(struct device *dev, struct device_attribute *attr,
483 const char *buf, size_t count)
484{
485 struct ci13xxx *ci = container_of(dev, struct ci13xxx, gadget.dev);
486 unsigned long flags;
487 unsigned en, bit;
488
489 if (attr == NULL || buf == NULL) {
490 dev_err(ci->dev, "EINVAL\n");
491 goto done;
492 }
493 70
494 if (sscanf(buf, "%u %u", &en, &bit) != 2 || en > 1) { 71 return 0;
495 dev_err(ci->dev, "<1|0> <bit>: enable|disable interrupt\n");
496 goto done;
497 }
498
499 spin_lock_irqsave(&ci->lock, flags);
500 if (en) {
501 if (hw_intr_force(ci, bit))
502 dev_err(dev, "invalid bit number\n");
503 else
504 isr_statistics.test++;
505 } else {
506 if (hw_intr_clear(ci, bit))
507 dev_err(dev, "invalid bit number\n");
508 }
509 spin_unlock_irqrestore(&ci->lock, flags);
510
511 done:
512 return count;
513} 72}
514static DEVICE_ATTR(inters, S_IRUSR | S_IWUSR, show_inters, store_inters);
515 73
516/** 74/**
517 * show_port_test: reads port test mode 75 * ci_port_test_write: writes port test mode
518 *
519 * Check "device.h" for details
520 */ 76 */
521static ssize_t show_port_test(struct device *dev, 77static ssize_t ci_port_test_write(struct file *file, const char __user *ubuf,
522 struct device_attribute *attr, char *buf) 78 size_t count, loff_t *ppos)
523{ 79{
524 struct ci13xxx *ci = container_of(dev, struct ci13xxx, gadget.dev); 80 struct seq_file *s = file->private_data;
81 struct ci13xxx *ci = s->private;
525 unsigned long flags; 82 unsigned long flags;
526 unsigned mode; 83 unsigned mode;
84 char buf[32];
85 int ret;
527 86
528 if (attr == NULL || buf == NULL) { 87 if (copy_from_user(buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
529 dev_err(ci->dev, "EINVAL\n"); 88 return -EFAULT;
530 return 0; 89
531 } 90 if (sscanf(buf, "%u", &mode) != 1)
91 return -EINVAL;
532 92
533 spin_lock_irqsave(&ci->lock, flags); 93 spin_lock_irqsave(&ci->lock, flags);
534 mode = hw_port_test_get(ci); 94 ret = hw_port_test_set(ci, mode);
535 spin_unlock_irqrestore(&ci->lock, flags); 95 spin_unlock_irqrestore(&ci->lock, flags);
536 96
537 return scnprintf(buf, PAGE_SIZE, "mode = %u\n", mode); 97 return ret ? ret : count;
538} 98}
539 99
540/** 100static int ci_port_test_open(struct inode *inode, struct file *file)
541 * store_port_test: writes port test mode
542 *
543 * Check "device.h" for details
544 */
545static ssize_t store_port_test(struct device *dev,
546 struct device_attribute *attr,
547 const char *buf, size_t count)
548{ 101{
549 struct ci13xxx *ci = container_of(dev, struct ci13xxx, gadget.dev); 102 return single_open(file, ci_port_test_show, inode->i_private);
550 unsigned long flags;
551 unsigned mode;
552
553 if (attr == NULL || buf == NULL) {
554 dev_err(ci->dev, "[%s] EINVAL\n", __func__);
555 goto done;
556 }
557
558 if (sscanf(buf, "%u", &mode) != 1) {
559 dev_err(ci->dev, "<mode>: set port test mode");
560 goto done;
561 }
562
563 spin_lock_irqsave(&ci->lock, flags);
564 if (hw_port_test_set(ci, mode))
565 dev_err(ci->dev, "invalid mode\n");
566 spin_unlock_irqrestore(&ci->lock, flags);
567
568 done:
569 return count;
570} 103}
571static DEVICE_ATTR(port_test, S_IRUSR | S_IWUSR, 104
572 show_port_test, store_port_test); 105static const struct file_operations ci_port_test_fops = {
106 .open = ci_port_test_open,
107 .write = ci_port_test_write,
108 .read = seq_read,
109 .llseek = seq_lseek,
110 .release = single_release,
111};
573 112
574/** 113/**
575 * show_qheads: DMA contents of all queue heads 114 * ci_qheads_show: DMA contents of all queue heads
576 *
577 * Check "device.h" for details
578 */ 115 */
579static ssize_t show_qheads(struct device *dev, struct device_attribute *attr, 116static int ci_qheads_show(struct seq_file *s, void *data)
580 char *buf)
581{ 117{
582 struct ci13xxx *ci = container_of(dev, struct ci13xxx, gadget.dev); 118 struct ci13xxx *ci = s->private;
583 unsigned long flags; 119 unsigned long flags;
584 unsigned i, j, n = 0; 120 unsigned i, j;
585 121
586 if (attr == NULL || buf == NULL) { 122 if (ci->role != CI_ROLE_GADGET) {
587 dev_err(ci->dev, "[%s] EINVAL\n", __func__); 123 seq_printf(s, "not in gadget mode\n");
588 return 0; 124 return 0;
589 } 125 }
590 126
@@ -593,209 +129,173 @@ static ssize_t show_qheads(struct device *dev, struct device_attribute *attr,
593 struct ci13xxx_ep *mEpRx = &ci->ci13xxx_ep[i]; 129 struct ci13xxx_ep *mEpRx = &ci->ci13xxx_ep[i];
594 struct ci13xxx_ep *mEpTx = 130 struct ci13xxx_ep *mEpTx =
595 &ci->ci13xxx_ep[i + ci->hw_ep_max/2]; 131 &ci->ci13xxx_ep[i + ci->hw_ep_max/2];
596 n += scnprintf(buf + n, PAGE_SIZE - n, 132 seq_printf(s, "EP=%02i: RX=%08X TX=%08X\n",
597 "EP=%02i: RX=%08X TX=%08X\n", 133 i, (u32)mEpRx->qh.dma, (u32)mEpTx->qh.dma);
598 i, (u32)mEpRx->qh.dma, (u32)mEpTx->qh.dma); 134 for (j = 0; j < (sizeof(struct ci13xxx_qh)/sizeof(u32)); j++)
599 for (j = 0; j < (sizeof(struct ci13xxx_qh)/sizeof(u32)); j++) { 135 seq_printf(s, " %04X: %08X %08X\n", j,
600 n += scnprintf(buf + n, PAGE_SIZE - n, 136 *((u32 *)mEpRx->qh.ptr + j),
601 " %04X: %08X %08X\n", j, 137 *((u32 *)mEpTx->qh.ptr + j));
602 *((u32 *)mEpRx->qh.ptr + j),
603 *((u32 *)mEpTx->qh.ptr + j));
604 }
605 } 138 }
606 spin_unlock_irqrestore(&ci->lock, flags); 139 spin_unlock_irqrestore(&ci->lock, flags);
607 140
608 return n; 141 return 0;
142}
143
144static int ci_qheads_open(struct inode *inode, struct file *file)
145{
146 return single_open(file, ci_qheads_show, inode->i_private);
609} 147}
610static DEVICE_ATTR(qheads, S_IRUSR, show_qheads, NULL); 148
149static const struct file_operations ci_qheads_fops = {
150 .open = ci_qheads_open,
151 .read = seq_read,
152 .llseek = seq_lseek,
153 .release = single_release,
154};
611 155
612/** 156/**
613 * show_registers: dumps all registers 157 * ci_requests_show: DMA contents of all requests currently queued (all endpts)
614 *
615 * Check "device.h" for details
616 */ 158 */
617#define DUMP_ENTRIES 512 159static int ci_requests_show(struct seq_file *s, void *data)
618static ssize_t show_registers(struct device *dev,
619 struct device_attribute *attr, char *buf)
620{ 160{
621 struct ci13xxx *ci = container_of(dev, struct ci13xxx, gadget.dev); 161 struct ci13xxx *ci = s->private;
622 unsigned long flags; 162 unsigned long flags;
623 u32 *dump; 163 struct list_head *ptr = NULL;
624 unsigned i, k, n = 0; 164 struct ci13xxx_req *req = NULL;
625 165 unsigned i, j, qsize = sizeof(struct ci13xxx_td)/sizeof(u32);
626 if (attr == NULL || buf == NULL) {
627 dev_err(ci->dev, "[%s] EINVAL\n", __func__);
628 return 0;
629 }
630 166
631 dump = kmalloc(sizeof(u32) * DUMP_ENTRIES, GFP_KERNEL); 167 if (ci->role != CI_ROLE_GADGET) {
632 if (!dump) { 168 seq_printf(s, "not in gadget mode\n");
633 dev_err(ci->dev, "%s: out of memory\n", __func__);
634 return 0; 169 return 0;
635 } 170 }
636 171
637 spin_lock_irqsave(&ci->lock, flags); 172 spin_lock_irqsave(&ci->lock, flags);
638 k = hw_register_read(ci, dump, DUMP_ENTRIES); 173 for (i = 0; i < ci->hw_ep_max; i++)
639 spin_unlock_irqrestore(&ci->lock, flags); 174 list_for_each(ptr, &ci->ci13xxx_ep[i].qh.queue) {
175 req = list_entry(ptr, struct ci13xxx_req, queue);
640 176
641 for (i = 0; i < k; i++) { 177 seq_printf(s, "EP=%02i: TD=%08X %s\n",
642 n += scnprintf(buf + n, PAGE_SIZE - n, 178 i % (ci->hw_ep_max / 2), (u32)req->dma,
643 "reg[0x%04X] = 0x%08X\n", 179 ((i < ci->hw_ep_max/2) ? "RX" : "TX"));
644 i * (unsigned)sizeof(u32), dump[i]); 180
645 } 181 for (j = 0; j < qsize; j++)
646 kfree(dump); 182 seq_printf(s, " %04X: %08X\n", j,
183 *((u32 *)req->ptr + j));
184 }
185 spin_unlock_irqrestore(&ci->lock, flags);
647 186
648 return n; 187 return 0;
649} 188}
650 189
651/** 190static int ci_requests_open(struct inode *inode, struct file *file)
652 * store_registers: writes value to register address
653 *
654 * Check "device.h" for details
655 */
656static ssize_t store_registers(struct device *dev,
657 struct device_attribute *attr,
658 const char *buf, size_t count)
659{ 191{
660 struct ci13xxx *ci = container_of(dev, struct ci13xxx, gadget.dev); 192 return single_open(file, ci_requests_show, inode->i_private);
661 unsigned long addr, data, flags; 193}
662 194
663 if (attr == NULL || buf == NULL) { 195static const struct file_operations ci_requests_fops = {
664 dev_err(ci->dev, "[%s] EINVAL\n", __func__); 196 .open = ci_requests_open,
665 goto done; 197 .read = seq_read,
666 } 198 .llseek = seq_lseek,
199 .release = single_release,
200};
667 201
668 if (sscanf(buf, "%li %li", &addr, &data) != 2) { 202static int ci_role_show(struct seq_file *s, void *data)
669 dev_err(ci->dev, 203{
670 "<addr> <data>: write data to register address\n"); 204 struct ci13xxx *ci = s->private;
671 goto done;
672 }
673 205
674 spin_lock_irqsave(&ci->lock, flags); 206 seq_printf(s, "%s\n", ci_role(ci)->name);
675 if (hw_register_write(ci, addr, data))
676 dev_err(ci->dev, "invalid address range\n");
677 spin_unlock_irqrestore(&ci->lock, flags);
678 207
679 done: 208 return 0;
680 return count;
681} 209}
682static DEVICE_ATTR(registers, S_IRUSR | S_IWUSR,
683 show_registers, store_registers);
684 210
685/** 211static ssize_t ci_role_write(struct file *file, const char __user *ubuf,
686 * show_requests: DMA contents of all requests currently queued (all endpts) 212 size_t count, loff_t *ppos)
687 *
688 * Check "device.h" for details
689 */
690static ssize_t show_requests(struct device *dev, struct device_attribute *attr,
691 char *buf)
692{ 213{
693 struct ci13xxx *ci = container_of(dev, struct ci13xxx, gadget.dev); 214 struct seq_file *s = file->private_data;
694 unsigned long flags; 215 struct ci13xxx *ci = s->private;
695 struct list_head *ptr = NULL; 216 enum ci_role role;
696 struct ci13xxx_req *req = NULL; 217 char buf[8];
697 unsigned i, j, n = 0, qSize = sizeof(struct ci13xxx_td)/sizeof(u32); 218 int ret;
698 219
699 if (attr == NULL || buf == NULL) { 220 if (copy_from_user(buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
700 dev_err(ci->dev, "[%s] EINVAL\n", __func__); 221 return -EFAULT;
701 return 0; 222
702 } 223 for (role = CI_ROLE_HOST; role < CI_ROLE_END; role++)
224 if (ci->roles[role] &&
225 !strncmp(buf, ci->roles[role]->name,
226 strlen(ci->roles[role]->name)))
227 break;
703 228
704 spin_lock_irqsave(&ci->lock, flags); 229 if (role == CI_ROLE_END || role == ci->role)
705 for (i = 0; i < ci->hw_ep_max; i++) 230 return -EINVAL;
706 list_for_each(ptr, &ci->ci13xxx_ep[i].qh.queue)
707 {
708 req = list_entry(ptr, struct ci13xxx_req, queue);
709 231
710 n += scnprintf(buf + n, PAGE_SIZE - n, 232 ci_role_stop(ci);
711 "EP=%02i: TD=%08X %s\n", 233 ret = ci_role_start(ci, role);
712 i % ci->hw_ep_max/2, (u32)req->dma,
713 ((i < ci->hw_ep_max/2) ? "RX" : "TX"));
714 234
715 for (j = 0; j < qSize; j++) 235 return ret ? ret : count;
716 n += scnprintf(buf + n, PAGE_SIZE - n, 236}
717 " %04X: %08X\n", j,
718 *((u32 *)req->ptr + j));
719 }
720 spin_unlock_irqrestore(&ci->lock, flags);
721 237
722 return n; 238static int ci_role_open(struct inode *inode, struct file *file)
239{
240 return single_open(file, ci_role_show, inode->i_private);
723} 241}
724static DEVICE_ATTR(requests, S_IRUSR, show_requests, NULL); 242
243static const struct file_operations ci_role_fops = {
244 .open = ci_role_open,
245 .write = ci_role_write,
246 .read = seq_read,
247 .llseek = seq_lseek,
248 .release = single_release,
249};
725 250
726/** 251/**
727 * dbg_create_files: initializes the attribute interface 252 * dbg_create_files: initializes the attribute interface
728 * @dev: device 253 * @ci: device
729 * 254 *
730 * This function returns an error code 255 * This function returns an error code
731 */ 256 */
732int dbg_create_files(struct device *dev) 257int dbg_create_files(struct ci13xxx *ci)
733{ 258{
734 int retval = 0; 259 struct dentry *dent;
735 260
736 if (dev == NULL) 261 ci->debugfs = debugfs_create_dir(dev_name(ci->dev), NULL);
737 return -EINVAL; 262 if (!ci->debugfs)
738 retval = device_create_file(dev, &dev_attr_device); 263 return -ENOMEM;
739 if (retval) 264
740 goto done; 265 dent = debugfs_create_file("device", S_IRUGO, ci->debugfs, ci,
741 retval = device_create_file(dev, &dev_attr_driver); 266 &ci_device_fops);
742 if (retval) 267 if (!dent)
743 goto rm_device; 268 goto err;
744 retval = device_create_file(dev, &dev_attr_events); 269
745 if (retval) 270 dent = debugfs_create_file("port_test", S_IRUGO | S_IWUSR, ci->debugfs,
746 goto rm_driver; 271 ci, &ci_port_test_fops);
747 retval = device_create_file(dev, &dev_attr_inters); 272 if (!dent)
748 if (retval) 273 goto err;
749 goto rm_events; 274
750 retval = device_create_file(dev, &dev_attr_port_test); 275 dent = debugfs_create_file("qheads", S_IRUGO, ci->debugfs, ci,
751 if (retval) 276 &ci_qheads_fops);
752 goto rm_inters; 277 if (!dent)
753 retval = device_create_file(dev, &dev_attr_qheads); 278 goto err;
754 if (retval) 279
755 goto rm_port_test; 280 dent = debugfs_create_file("requests", S_IRUGO, ci->debugfs, ci,
756 retval = device_create_file(dev, &dev_attr_registers); 281 &ci_requests_fops);
757 if (retval) 282 if (!dent)
758 goto rm_qheads; 283 goto err;
759 retval = device_create_file(dev, &dev_attr_requests); 284
760 if (retval) 285 dent = debugfs_create_file("role", S_IRUGO | S_IWUSR, ci->debugfs, ci,
761 goto rm_registers; 286 &ci_role_fops);
762 return 0; 287 if (dent)
763 288 return 0;
764 rm_registers: 289err:
765 device_remove_file(dev, &dev_attr_registers); 290 debugfs_remove_recursive(ci->debugfs);
766 rm_qheads: 291 return -ENOMEM;
767 device_remove_file(dev, &dev_attr_qheads);
768 rm_port_test:
769 device_remove_file(dev, &dev_attr_port_test);
770 rm_inters:
771 device_remove_file(dev, &dev_attr_inters);
772 rm_events:
773 device_remove_file(dev, &dev_attr_events);
774 rm_driver:
775 device_remove_file(dev, &dev_attr_driver);
776 rm_device:
777 device_remove_file(dev, &dev_attr_device);
778 done:
779 return retval;
780} 292}
781 293
782/** 294/**
783 * dbg_remove_files: destroys the attribute interface 295 * dbg_remove_files: destroys the attribute interface
784 * @dev: device 296 * @ci: device
785 *
786 * This function returns an error code
787 */ 297 */
788int dbg_remove_files(struct device *dev) 298void dbg_remove_files(struct ci13xxx *ci)
789{ 299{
790 if (dev == NULL) 300 debugfs_remove_recursive(ci->debugfs);
791 return -EINVAL;
792 device_remove_file(dev, &dev_attr_requests);
793 device_remove_file(dev, &dev_attr_registers);
794 device_remove_file(dev, &dev_attr_qheads);
795 device_remove_file(dev, &dev_attr_port_test);
796 device_remove_file(dev, &dev_attr_inters);
797 device_remove_file(dev, &dev_attr_events);
798 device_remove_file(dev, &dev_attr_driver);
799 device_remove_file(dev, &dev_attr_device);
800 return 0;
801} 301}
diff --git a/drivers/usb/chipidea/debug.h b/drivers/usb/chipidea/debug.h
index 80d96865775c..7ca6ca0a24a5 100644
--- a/drivers/usb/chipidea/debug.h
+++ b/drivers/usb/chipidea/debug.h
@@ -14,42 +14,16 @@
14#define __DRIVERS_USB_CHIPIDEA_DEBUG_H 14#define __DRIVERS_USB_CHIPIDEA_DEBUG_H
15 15
16#ifdef CONFIG_USB_CHIPIDEA_DEBUG 16#ifdef CONFIG_USB_CHIPIDEA_DEBUG
17void dbg_interrupt(u32 intmask); 17int dbg_create_files(struct ci13xxx *ci);
18void dbg_done(u8 addr, const u32 token, int status); 18void dbg_remove_files(struct ci13xxx *ci);
19void dbg_event(u8 addr, const char *name, int status);
20void dbg_queue(u8 addr, const struct usb_request *req, int status);
21void dbg_setup(u8 addr, const struct usb_ctrlrequest *req);
22int dbg_create_files(struct device *dev);
23int dbg_remove_files(struct device *dev);
24#else 19#else
25static inline void dbg_interrupt(u32 intmask) 20static inline int dbg_create_files(struct ci13xxx *ci)
26{
27}
28
29static inline void dbg_done(u8 addr, const u32 token, int status)
30{
31}
32
33static inline void dbg_event(u8 addr, const char *name, int status)
34{
35}
36
37static inline void dbg_queue(u8 addr, const struct usb_request *req, int status)
38{
39}
40
41static inline void dbg_setup(u8 addr, const struct usb_ctrlrequest *req)
42{
43}
44
45static inline int dbg_create_files(struct device *dev)
46{ 21{
47 return 0; 22 return 0;
48} 23}
49 24
50static inline int dbg_remove_files(struct device *dev) 25static inline void dbg_remove_files(struct ci13xxx *ci)
51{ 26{
52 return 0;
53} 27}
54#endif 28#endif
55 29
diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index f64fbea1cf20..519ead2443c5 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -13,14 +13,8 @@
13#include <linux/delay.h> 13#include <linux/delay.h>
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>
17#include <linux/err.h> 16#include <linux/err.h>
18#include <linux/init.h> 17#include <linux/irqreturn.h>
19#include <linux/platform_device.h>
20#include <linux/module.h>
21#include <linux/interrupt.h>
22#include <linux/io.h>
23#include <linux/irq.h>
24#include <linux/kernel.h> 18#include <linux/kernel.h>
25#include <linux/slab.h> 19#include <linux/slab.h>
26#include <linux/pm_runtime.h> 20#include <linux/pm_runtime.h>
@@ -146,7 +140,7 @@ static int hw_ep_enable(struct ci13xxx *ci, int num, int dir, int type)
146 140
147 if (dir) { 141 if (dir) {
148 mask = ENDPTCTRL_TXT; /* type */ 142 mask = ENDPTCTRL_TXT; /* type */
149 data = type << ffs_nr(mask); 143 data = type << __ffs(mask);
150 144
151 mask |= ENDPTCTRL_TXS; /* unstall */ 145 mask |= ENDPTCTRL_TXS; /* unstall */
152 mask |= ENDPTCTRL_TXR; /* reset data toggle */ 146 mask |= ENDPTCTRL_TXR; /* reset data toggle */
@@ -155,7 +149,7 @@ static int hw_ep_enable(struct ci13xxx *ci, int num, int dir, int type)
155 data |= ENDPTCTRL_TXE; 149 data |= ENDPTCTRL_TXE;
156 } else { 150 } else {
157 mask = ENDPTCTRL_RXT; /* type */ 151 mask = ENDPTCTRL_RXT; /* type */
158 data = type << ffs_nr(mask); 152 data = type << __ffs(mask);
159 153
160 mask |= ENDPTCTRL_RXS; /* unstall */ 154 mask |= ENDPTCTRL_RXS; /* unstall */
161 mask |= ENDPTCTRL_RXR; /* reset data toggle */ 155 mask |= ENDPTCTRL_RXR; /* reset data toggle */
@@ -305,18 +299,6 @@ static u32 hw_test_and_clear_intr_active(struct ci13xxx *ci)
305 return reg; 299 return reg;
306} 300}
307 301
308static void hw_enable_vbus_intr(struct ci13xxx *ci)
309{
310 hw_write(ci, OP_OTGSC, OTGSC_AVVIS, OTGSC_AVVIS);
311 hw_write(ci, OP_OTGSC, OTGSC_AVVIE, OTGSC_AVVIE);
312 queue_work(ci->wq, &ci->vbus_work);
313}
314
315static void hw_disable_vbus_intr(struct ci13xxx *ci)
316{
317 hw_write(ci, OP_OTGSC, OTGSC_AVVIE, 0);
318}
319
320/** 302/**
321 * hw_test_and_clear_setup_guard: test & clear setup guard (execute without 303 * hw_test_and_clear_setup_guard: test & clear setup guard (execute without
322 * interruption) 304 * interruption)
@@ -349,7 +331,7 @@ static int hw_test_and_set_setup_guard(struct ci13xxx *ci)
349static void hw_usb_set_address(struct ci13xxx *ci, u8 value) 331static void hw_usb_set_address(struct ci13xxx *ci, u8 value)
350{ 332{
351 hw_write(ci, OP_DEVICEADDR, DEVICEADDR_USBADR, 333 hw_write(ci, OP_DEVICEADDR, DEVICEADDR_USBADR,
352 value << ffs_nr(DEVICEADDR_USBADR)); 334 value << __ffs(DEVICEADDR_USBADR));
353} 335}
354 336
355/** 337/**
@@ -383,16 +365,6 @@ static int hw_usb_reset(struct ci13xxx *ci)
383 return 0; 365 return 0;
384} 366}
385 367
386static void vbus_work(struct work_struct *work)
387{
388 struct ci13xxx *ci = container_of(work, struct ci13xxx, vbus_work);
389
390 if (hw_read(ci, OP_OTGSC, OTGSC_AVV))
391 usb_gadget_vbus_connect(&ci->gadget);
392 else
393 usb_gadget_vbus_disconnect(&ci->gadget);
394}
395
396/****************************************************************************** 368/******************************************************************************
397 * UTIL block 369 * UTIL block
398 *****************************************************************************/ 370 *****************************************************************************/
@@ -432,10 +404,10 @@ static int _hardware_enqueue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq)
432 return -ENOMEM; 404 return -ENOMEM;
433 405
434 memset(mReq->zptr, 0, sizeof(*mReq->zptr)); 406 memset(mReq->zptr, 0, sizeof(*mReq->zptr));
435 mReq->zptr->next = TD_TERMINATE; 407 mReq->zptr->next = cpu_to_le32(TD_TERMINATE);
436 mReq->zptr->token = TD_STATUS_ACTIVE; 408 mReq->zptr->token = cpu_to_le32(TD_STATUS_ACTIVE);
437 if (!mReq->req.no_interrupt) 409 if (!mReq->req.no_interrupt)
438 mReq->zptr->token |= TD_IOC; 410 mReq->zptr->token |= cpu_to_le32(TD_IOC);
439 } 411 }
440 ret = usb_gadget_map_request(&ci->gadget, &mReq->req, mEp->dir); 412 ret = usb_gadget_map_request(&ci->gadget, &mReq->req, mEp->dir);
441 if (ret) 413 if (ret)
@@ -446,32 +418,37 @@ static int _hardware_enqueue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq)
446 * TODO - handle requests which spawns into several TDs 418 * TODO - handle requests which spawns into several TDs
447 */ 419 */
448 memset(mReq->ptr, 0, sizeof(*mReq->ptr)); 420 memset(mReq->ptr, 0, sizeof(*mReq->ptr));
449 mReq->ptr->token = length << ffs_nr(TD_TOTAL_BYTES); 421 mReq->ptr->token = cpu_to_le32(length << __ffs(TD_TOTAL_BYTES));
450 mReq->ptr->token &= TD_TOTAL_BYTES; 422 mReq->ptr->token &= cpu_to_le32(TD_TOTAL_BYTES);
451 mReq->ptr->token |= TD_STATUS_ACTIVE; 423 mReq->ptr->token |= cpu_to_le32(TD_STATUS_ACTIVE);
452 if (mReq->zptr) { 424 if (mReq->zptr) {
453 mReq->ptr->next = mReq->zdma; 425 mReq->ptr->next = cpu_to_le32(mReq->zdma);
454 } else { 426 } else {
455 mReq->ptr->next = TD_TERMINATE; 427 mReq->ptr->next = cpu_to_le32(TD_TERMINATE);
456 if (!mReq->req.no_interrupt) 428 if (!mReq->req.no_interrupt)
457 mReq->ptr->token |= TD_IOC; 429 mReq->ptr->token |= cpu_to_le32(TD_IOC);
430 }
431 mReq->ptr->page[0] = cpu_to_le32(mReq->req.dma);
432 for (i = 1; i < TD_PAGE_COUNT; i++) {
433 u32 page = mReq->req.dma + i * CI13XXX_PAGE_SIZE;
434 page &= ~TD_RESERVED_MASK;
435 mReq->ptr->page[i] = cpu_to_le32(page);
458 } 436 }
459 mReq->ptr->page[0] = mReq->req.dma; 437
460 for (i = 1; i < 5; i++) 438 wmb();
461 mReq->ptr->page[i] =
462 (mReq->req.dma + i * CI13XXX_PAGE_SIZE) & ~TD_RESERVED_MASK;
463 439
464 if (!list_empty(&mEp->qh.queue)) { 440 if (!list_empty(&mEp->qh.queue)) {
465 struct ci13xxx_req *mReqPrev; 441 struct ci13xxx_req *mReqPrev;
466 int n = hw_ep_bit(mEp->num, mEp->dir); 442 int n = hw_ep_bit(mEp->num, mEp->dir);
467 int tmp_stat; 443 int tmp_stat;
444 u32 next = mReq->dma & TD_ADDR_MASK;
468 445
469 mReqPrev = list_entry(mEp->qh.queue.prev, 446 mReqPrev = list_entry(mEp->qh.queue.prev,
470 struct ci13xxx_req, queue); 447 struct ci13xxx_req, queue);
471 if (mReqPrev->zptr) 448 if (mReqPrev->zptr)
472 mReqPrev->zptr->next = mReq->dma & TD_ADDR_MASK; 449 mReqPrev->zptr->next = cpu_to_le32(next);
473 else 450 else
474 mReqPrev->ptr->next = mReq->dma & TD_ADDR_MASK; 451 mReqPrev->ptr->next = cpu_to_le32(next);
475 wmb(); 452 wmb();
476 if (hw_read(ci, OP_ENDPTPRIME, BIT(n))) 453 if (hw_read(ci, OP_ENDPTPRIME, BIT(n)))
477 goto done; 454 goto done;
@@ -485,9 +462,9 @@ static int _hardware_enqueue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq)
485 } 462 }
486 463
487 /* QH configuration */ 464 /* QH configuration */
488 mEp->qh.ptr->td.next = mReq->dma; /* TERMINATE = 0 */ 465 mEp->qh.ptr->td.next = cpu_to_le32(mReq->dma); /* TERMINATE = 0 */
489 mEp->qh.ptr->td.token &= ~TD_STATUS; /* clear status */ 466 mEp->qh.ptr->td.token &=
490 mEp->qh.ptr->cap |= QH_ZLT; 467 cpu_to_le32(~(TD_STATUS_HALTED|TD_STATUS_ACTIVE));
491 468
492 wmb(); /* synchronize before ep prime */ 469 wmb(); /* synchronize before ep prime */
493 470
@@ -506,14 +483,16 @@ done:
506 */ 483 */
507static int _hardware_dequeue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq) 484static int _hardware_dequeue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq)
508{ 485{
486 u32 tmptoken = le32_to_cpu(mReq->ptr->token);
487
509 if (mReq->req.status != -EALREADY) 488 if (mReq->req.status != -EALREADY)
510 return -EINVAL; 489 return -EINVAL;
511 490
512 if ((TD_STATUS_ACTIVE & mReq->ptr->token) != 0) 491 if ((TD_STATUS_ACTIVE & tmptoken) != 0)
513 return -EBUSY; 492 return -EBUSY;
514 493
515 if (mReq->zptr) { 494 if (mReq->zptr) {
516 if ((TD_STATUS_ACTIVE & mReq->zptr->token) != 0) 495 if ((cpu_to_le32(TD_STATUS_ACTIVE) & mReq->zptr->token) != 0)
517 return -EBUSY; 496 return -EBUSY;
518 dma_pool_free(mEp->td_pool, mReq->zptr, mReq->zdma); 497 dma_pool_free(mEp->td_pool, mReq->zptr, mReq->zdma);
519 mReq->zptr = NULL; 498 mReq->zptr = NULL;
@@ -523,7 +502,7 @@ static int _hardware_dequeue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq)
523 502
524 usb_gadget_unmap_request(&mEp->ci->gadget, &mReq->req, mEp->dir); 503 usb_gadget_unmap_request(&mEp->ci->gadget, &mReq->req, mEp->dir);
525 504
526 mReq->req.status = mReq->ptr->token & TD_STATUS; 505 mReq->req.status = tmptoken & TD_STATUS;
527 if ((TD_STATUS_HALTED & mReq->req.status) != 0) 506 if ((TD_STATUS_HALTED & mReq->req.status) != 0)
528 mReq->req.status = -1; 507 mReq->req.status = -1;
529 else if ((TD_STATUS_DT_ERR & mReq->req.status) != 0) 508 else if ((TD_STATUS_DT_ERR & mReq->req.status) != 0)
@@ -531,8 +510,8 @@ static int _hardware_dequeue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq)
531 else if ((TD_STATUS_TR_ERR & mReq->req.status) != 0) 510 else if ((TD_STATUS_TR_ERR & mReq->req.status) != 0)
532 mReq->req.status = -1; 511 mReq->req.status = -1;
533 512
534 mReq->req.actual = mReq->ptr->token & TD_TOTAL_BYTES; 513 mReq->req.actual = tmptoken & TD_TOTAL_BYTES;
535 mReq->req.actual >>= ffs_nr(TD_TOTAL_BYTES); 514 mReq->req.actual >>= __ffs(TD_TOTAL_BYTES);
536 mReq->req.actual = mReq->req.length - mReq->req.actual; 515 mReq->req.actual = mReq->req.length - mReq->req.actual;
537 mReq->req.actual = mReq->req.status ? 0 : mReq->req.actual; 516 mReq->req.actual = mReq->req.status ? 0 : mReq->req.actual;
538 517
@@ -561,6 +540,12 @@ __acquires(mEp->lock)
561 struct ci13xxx_req *mReq = \ 540 struct ci13xxx_req *mReq = \
562 list_entry(mEp->qh.queue.next, 541 list_entry(mEp->qh.queue.next,
563 struct ci13xxx_req, queue); 542 struct ci13xxx_req, queue);
543
544 if (mReq->zptr) {
545 dma_pool_free(mEp->td_pool, mReq->zptr, mReq->zdma);
546 mReq->zptr = NULL;
547 }
548
564 list_del_init(&mReq->queue); 549 list_del_init(&mReq->queue);
565 mReq->req.status = -ESHUTDOWN; 550 mReq->req.status = -ESHUTDOWN;
566 551
@@ -629,8 +614,6 @@ __acquires(ci->lock)
629{ 614{
630 int retval; 615 int retval;
631 616
632 dbg_event(0xFF, "BUS RST", 0);
633
634 spin_unlock(&ci->lock); 617 spin_unlock(&ci->lock);
635 retval = _gadget_stop_activity(&ci->gadget); 618 retval = _gadget_stop_activity(&ci->gadget);
636 if (retval) 619 if (retval)
@@ -668,6 +651,59 @@ static void isr_get_status_complete(struct usb_ep *ep, struct usb_request *req)
668} 651}
669 652
670/** 653/**
654 * _ep_queue: queues (submits) an I/O request to an endpoint
655 *
656 * Caller must hold lock
657 */
658static int _ep_queue(struct usb_ep *ep, struct usb_request *req,
659 gfp_t __maybe_unused gfp_flags)
660{
661 struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep);
662 struct ci13xxx_req *mReq = container_of(req, struct ci13xxx_req, req);
663 struct ci13xxx *ci = mEp->ci;
664 int retval = 0;
665
666 if (ep == NULL || req == NULL || mEp->ep.desc == NULL)
667 return -EINVAL;
668
669 if (mEp->type == USB_ENDPOINT_XFER_CONTROL) {
670 if (req->length)
671 mEp = (ci->ep0_dir == RX) ?
672 ci->ep0out : ci->ep0in;
673 if (!list_empty(&mEp->qh.queue)) {
674 _ep_nuke(mEp);
675 retval = -EOVERFLOW;
676 dev_warn(mEp->ci->dev, "endpoint ctrl %X nuked\n",
677 _usb_addr(mEp));
678 }
679 }
680
681 /* first nuke then test link, e.g. previous status has not sent */
682 if (!list_empty(&mReq->queue)) {
683 dev_err(mEp->ci->dev, "request already in queue\n");
684 return -EBUSY;
685 }
686
687 if (req->length > (TD_PAGE_COUNT - 1) * CI13XXX_PAGE_SIZE) {
688 dev_err(mEp->ci->dev, "request bigger than one td\n");
689 return -EMSGSIZE;
690 }
691
692 /* push request */
693 mReq->req.status = -EINPROGRESS;
694 mReq->req.actual = 0;
695
696 retval = _hardware_enqueue(mEp, mReq);
697
698 if (retval == -EALREADY)
699 retval = 0;
700 if (!retval)
701 list_add_tail(&mReq->queue, &mEp->qh.queue);
702
703 return retval;
704}
705
706/**
671 * isr_get_status_response: get_status request response 707 * isr_get_status_response: get_status request response
672 * @ci: ci struct 708 * @ci: ci struct
673 * @setup: setup request packet 709 * @setup: setup request packet
@@ -714,9 +750,7 @@ __acquires(mEp->lock)
714 } 750 }
715 /* else do nothing; reserved for future use */ 751 /* else do nothing; reserved for future use */
716 752
717 spin_unlock(mEp->lock); 753 retval = _ep_queue(&mEp->ep, req, gfp_flags);
718 retval = usb_ep_queue(&mEp->ep, req, gfp_flags);
719 spin_lock(mEp->lock);
720 if (retval) 754 if (retval)
721 goto err_free_buf; 755 goto err_free_buf;
722 756
@@ -763,8 +797,6 @@ isr_setup_status_complete(struct usb_ep *ep, struct usb_request *req)
763 * This function returns an error code 797 * This function returns an error code
764 */ 798 */
765static int isr_setup_status_phase(struct ci13xxx *ci) 799static int isr_setup_status_phase(struct ci13xxx *ci)
766__releases(mEp->lock)
767__acquires(mEp->lock)
768{ 800{
769 int retval; 801 int retval;
770 struct ci13xxx_ep *mEp; 802 struct ci13xxx_ep *mEp;
@@ -773,9 +805,7 @@ __acquires(mEp->lock)
773 ci->status->context = ci; 805 ci->status->context = ci;
774 ci->status->complete = isr_setup_status_complete; 806 ci->status->complete = isr_setup_status_complete;
775 807
776 spin_unlock(mEp->lock); 808 retval = _ep_queue(&mEp->ep, ci->status, GFP_ATOMIC);
777 retval = usb_ep_queue(&mEp->ep, ci->status, GFP_ATOMIC);
778 spin_lock(mEp->lock);
779 809
780 return retval; 810 return retval;
781} 811}
@@ -801,7 +831,6 @@ __acquires(mEp->lock)
801 if (retval < 0) 831 if (retval < 0)
802 break; 832 break;
803 list_del_init(&mReq->queue); 833 list_del_init(&mReq->queue);
804 dbg_done(_usb_addr(mEp), mReq->ptr->token, retval);
805 if (mReq->req.complete != NULL) { 834 if (mReq->req.complete != NULL) {
806 spin_unlock(mEp->lock); 835 spin_unlock(mEp->lock);
807 if ((mEp->type == USB_ENDPOINT_XFER_CONTROL) && 836 if ((mEp->type == USB_ENDPOINT_XFER_CONTROL) &&
@@ -814,8 +843,6 @@ __acquires(mEp->lock)
814 843
815 if (retval == -EBUSY) 844 if (retval == -EBUSY)
816 retval = 0; 845 retval = 0;
817 if (retval < 0)
818 dbg_event(_usb_addr(mEp), "DONE", retval);
819 846
820 return retval; 847 return retval;
821} 848}
@@ -847,8 +874,6 @@ __acquires(ci->lock)
847 if (err > 0) /* needs status phase */ 874 if (err > 0) /* needs status phase */
848 err = isr_setup_status_phase(ci); 875 err = isr_setup_status_phase(ci);
849 if (err < 0) { 876 if (err < 0) {
850 dbg_event(_usb_addr(mEp),
851 "ERROR", err);
852 spin_unlock(&ci->lock); 877 spin_unlock(&ci->lock);
853 if (usb_ep_set_halt(&mEp->ep)) 878 if (usb_ep_set_halt(&mEp->ep))
854 dev_err(ci->dev, 879 dev_err(ci->dev,
@@ -884,8 +909,6 @@ __acquires(ci->lock)
884 909
885 ci->ep0_dir = (type & USB_DIR_IN) ? TX : RX; 910 ci->ep0_dir = (type & USB_DIR_IN) ? TX : RX;
886 911
887 dbg_setup(_usb_addr(mEp), &req);
888
889 switch (req.bRequest) { 912 switch (req.bRequest) {
890 case USB_REQ_CLEAR_FEATURE: 913 case USB_REQ_CLEAR_FEATURE:
891 if (type == (USB_DIR_OUT|USB_RECIP_ENDPOINT) && 914 if (type == (USB_DIR_OUT|USB_RECIP_ENDPOINT) &&
@@ -997,8 +1020,6 @@ delegate:
997 } 1020 }
998 1021
999 if (err < 0) { 1022 if (err < 0) {
1000 dbg_event(_usb_addr(mEp), "ERROR", err);
1001
1002 spin_unlock(&ci->lock); 1023 spin_unlock(&ci->lock);
1003 if (usb_ep_set_halt(&mEp->ep)) 1024 if (usb_ep_set_halt(&mEp->ep))
1004 dev_err(ci->dev, "error: ep_set_halt\n"); 1025 dev_err(ci->dev, "error: ep_set_halt\n");
@@ -1021,6 +1042,7 @@ static int ep_enable(struct usb_ep *ep,
1021 struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep); 1042 struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep);
1022 int retval = 0; 1043 int retval = 0;
1023 unsigned long flags; 1044 unsigned long flags;
1045 u32 cap = 0;
1024 1046
1025 if (ep == NULL || desc == NULL) 1047 if (ep == NULL || desc == NULL)
1026 return -EINVAL; 1048 return -EINVAL;
@@ -1040,20 +1062,15 @@ static int ep_enable(struct usb_ep *ep,
1040 1062
1041 mEp->ep.maxpacket = usb_endpoint_maxp(desc); 1063 mEp->ep.maxpacket = usb_endpoint_maxp(desc);
1042 1064
1043 dbg_event(_usb_addr(mEp), "ENABLE", 0);
1044
1045 mEp->qh.ptr->cap = 0;
1046
1047 if (mEp->type == USB_ENDPOINT_XFER_CONTROL) 1065 if (mEp->type == USB_ENDPOINT_XFER_CONTROL)
1048 mEp->qh.ptr->cap |= QH_IOS; 1066 cap |= QH_IOS;
1049 else if (mEp->type == USB_ENDPOINT_XFER_ISOC) 1067 if (mEp->num)
1050 mEp->qh.ptr->cap &= ~QH_MULT; 1068 cap |= QH_ZLT;
1051 else 1069 cap |= (mEp->ep.maxpacket << __ffs(QH_MAX_PKT)) & QH_MAX_PKT;
1052 mEp->qh.ptr->cap &= ~QH_ZLT; 1070
1071 mEp->qh.ptr->cap = cpu_to_le32(cap);
1053 1072
1054 mEp->qh.ptr->cap |= 1073 mEp->qh.ptr->td.next |= cpu_to_le32(TD_TERMINATE); /* needed? */
1055 (mEp->ep.maxpacket << ffs_nr(QH_MAX_PKT)) & QH_MAX_PKT;
1056 mEp->qh.ptr->td.next |= TD_TERMINATE; /* needed? */
1057 1074
1058 /* 1075 /*
1059 * Enable endpoints in the HW other than ep0 as ep0 1076 * Enable endpoints in the HW other than ep0 as ep0
@@ -1088,8 +1105,6 @@ static int ep_disable(struct usb_ep *ep)
1088 1105
1089 direction = mEp->dir; 1106 direction = mEp->dir;
1090 do { 1107 do {
1091 dbg_event(_usb_addr(mEp), "DISABLE", 0);
1092
1093 retval |= _ep_nuke(mEp); 1108 retval |= _ep_nuke(mEp);
1094 retval |= hw_ep_disable(mEp->ci, mEp->num, mEp->dir); 1109 retval |= hw_ep_disable(mEp->ci, mEp->num, mEp->dir);
1095 1110
@@ -1129,8 +1144,6 @@ static struct usb_request *ep_alloc_request(struct usb_ep *ep, gfp_t gfp_flags)
1129 } 1144 }
1130 } 1145 }
1131 1146
1132 dbg_event(_usb_addr(mEp), "ALLOC", mReq == NULL);
1133
1134 return (mReq == NULL) ? NULL : &mReq->req; 1147 return (mReq == NULL) ? NULL : &mReq->req;
1135} 1148}
1136 1149
@@ -1158,8 +1171,6 @@ static void ep_free_request(struct usb_ep *ep, struct usb_request *req)
1158 dma_pool_free(mEp->td_pool, mReq->ptr, mReq->dma); 1171 dma_pool_free(mEp->td_pool, mReq->ptr, mReq->dma);
1159 kfree(mReq); 1172 kfree(mReq);
1160 1173
1161 dbg_event(_usb_addr(mEp), "FREE", 0);
1162
1163 spin_unlock_irqrestore(mEp->lock, flags); 1174 spin_unlock_irqrestore(mEp->lock, flags);
1164} 1175}
1165 1176
@@ -1172,8 +1183,6 @@ static int ep_queue(struct usb_ep *ep, struct usb_request *req,
1172 gfp_t __maybe_unused gfp_flags) 1183 gfp_t __maybe_unused gfp_flags)
1173{ 1184{
1174 struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep); 1185 struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep);
1175 struct ci13xxx_req *mReq = container_of(req, struct ci13xxx_req, req);
1176 struct ci13xxx *ci = mEp->ci;
1177 int retval = 0; 1186 int retval = 0;
1178 unsigned long flags; 1187 unsigned long flags;
1179 1188
@@ -1181,48 +1190,7 @@ static int ep_queue(struct usb_ep *ep, struct usb_request *req,
1181 return -EINVAL; 1190 return -EINVAL;
1182 1191
1183 spin_lock_irqsave(mEp->lock, flags); 1192 spin_lock_irqsave(mEp->lock, flags);
1184 1193 retval = _ep_queue(ep, req, gfp_flags);
1185 if (mEp->type == USB_ENDPOINT_XFER_CONTROL) {
1186 if (req->length)
1187 mEp = (ci->ep0_dir == RX) ?
1188 ci->ep0out : ci->ep0in;
1189 if (!list_empty(&mEp->qh.queue)) {
1190 _ep_nuke(mEp);
1191 retval = -EOVERFLOW;
1192 dev_warn(mEp->ci->dev, "endpoint ctrl %X nuked\n",
1193 _usb_addr(mEp));
1194 }
1195 }
1196
1197 /* first nuke then test link, e.g. previous status has not sent */
1198 if (!list_empty(&mReq->queue)) {
1199 retval = -EBUSY;
1200 dev_err(mEp->ci->dev, "request already in queue\n");
1201 goto done;
1202 }
1203
1204 if (req->length > 4 * CI13XXX_PAGE_SIZE) {
1205 req->length = 4 * CI13XXX_PAGE_SIZE;
1206 retval = -EMSGSIZE;
1207 dev_warn(mEp->ci->dev, "request length truncated\n");
1208 }
1209
1210 dbg_queue(_usb_addr(mEp), req, retval);
1211
1212 /* push request */
1213 mReq->req.status = -EINPROGRESS;
1214 mReq->req.actual = 0;
1215
1216 retval = _hardware_enqueue(mEp, mReq);
1217
1218 if (retval == -EALREADY) {
1219 dbg_event(_usb_addr(mEp), "QUEUE", retval);
1220 retval = 0;
1221 }
1222 if (!retval)
1223 list_add_tail(&mReq->queue, &mEp->qh.queue);
1224
1225 done:
1226 spin_unlock_irqrestore(mEp->lock, flags); 1194 spin_unlock_irqrestore(mEp->lock, flags);
1227 return retval; 1195 return retval;
1228} 1196}
@@ -1245,8 +1213,6 @@ static int ep_dequeue(struct usb_ep *ep, struct usb_request *req)
1245 1213
1246 spin_lock_irqsave(mEp->lock, flags); 1214 spin_lock_irqsave(mEp->lock, flags);
1247 1215
1248 dbg_event(_usb_addr(mEp), "DEQUEUE", 0);
1249
1250 hw_ep_flush(mEp->ci, mEp->num, mEp->dir); 1216 hw_ep_flush(mEp->ci, mEp->num, mEp->dir);
1251 1217
1252 /* pop request */ 1218 /* pop request */
@@ -1293,7 +1259,6 @@ static int ep_set_halt(struct usb_ep *ep, int value)
1293 1259
1294 direction = mEp->dir; 1260 direction = mEp->dir;
1295 do { 1261 do {
1296 dbg_event(_usb_addr(mEp), "HALT", value);
1297 retval |= hw_ep_set_halt(mEp->ci, mEp->num, mEp->dir, value); 1262 retval |= hw_ep_set_halt(mEp->ci, mEp->num, mEp->dir, value);
1298 1263
1299 if (!value) 1264 if (!value)
@@ -1322,10 +1287,7 @@ static int ep_set_wedge(struct usb_ep *ep)
1322 return -EINVAL; 1287 return -EINVAL;
1323 1288
1324 spin_lock_irqsave(mEp->lock, flags); 1289 spin_lock_irqsave(mEp->lock, flags);
1325
1326 dbg_event(_usb_addr(mEp), "WEDGE", 0);
1327 mEp->wedge = 1; 1290 mEp->wedge = 1;
1328
1329 spin_unlock_irqrestore(mEp->lock, flags); 1291 spin_unlock_irqrestore(mEp->lock, flags);
1330 1292
1331 return usb_ep_set_halt(ep); 1293 return usb_ep_set_halt(ep);
@@ -1348,7 +1310,6 @@ static void ep_fifo_flush(struct usb_ep *ep)
1348 1310
1349 spin_lock_irqsave(mEp->lock, flags); 1311 spin_lock_irqsave(mEp->lock, flags);
1350 1312
1351 dbg_event(_usb_addr(mEp), "FFLUSH", 0);
1352 hw_ep_flush(mEp->ci, mEp->num, mEp->dir); 1313 hw_ep_flush(mEp->ci, mEp->num, mEp->dir);
1353 1314
1354 spin_unlock_irqrestore(mEp->lock, flags); 1315 spin_unlock_irqrestore(mEp->lock, flags);
@@ -1392,7 +1353,6 @@ static int ci13xxx_vbus_session(struct usb_gadget *_gadget, int is_active)
1392 if (is_active) { 1353 if (is_active) {
1393 pm_runtime_get_sync(&_gadget->dev); 1354 pm_runtime_get_sync(&_gadget->dev);
1394 hw_device_reset(ci, USBMODE_CM_DC); 1355 hw_device_reset(ci, USBMODE_CM_DC);
1395 hw_enable_vbus_intr(ci);
1396 hw_device_state(ci, ci->ep0out->qh.dma); 1356 hw_device_state(ci, ci->ep0out->qh.dma);
1397 } else { 1357 } else {
1398 hw_device_state(ci, 0); 1358 hw_device_state(ci, 0);
@@ -1567,10 +1527,8 @@ static int ci13xxx_start(struct usb_gadget *gadget,
1567 pm_runtime_get_sync(&ci->gadget.dev); 1527 pm_runtime_get_sync(&ci->gadget.dev);
1568 if (ci->platdata->flags & CI13XXX_PULLUP_ON_VBUS) { 1528 if (ci->platdata->flags & CI13XXX_PULLUP_ON_VBUS) {
1569 if (ci->vbus_active) { 1529 if (ci->vbus_active) {
1570 if (ci->platdata->flags & CI13XXX_REGS_SHARED) { 1530 if (ci->platdata->flags & CI13XXX_REGS_SHARED)
1571 hw_device_reset(ci, USBMODE_CM_DC); 1531 hw_device_reset(ci, USBMODE_CM_DC);
1572 hw_enable_vbus_intr(ci);
1573 }
1574 } else { 1532 } else {
1575 pm_runtime_put_sync(&ci->gadget.dev); 1533 pm_runtime_put_sync(&ci->gadget.dev);
1576 goto done; 1534 goto done;
@@ -1642,7 +1600,6 @@ static irqreturn_t udc_irq(struct ci13xxx *ci)
1642 } 1600 }
1643 } 1601 }
1644 intr = hw_test_and_clear_intr_active(ci); 1602 intr = hw_test_and_clear_intr_active(ci);
1645 dbg_interrupt(intr);
1646 1603
1647 if (intr) { 1604 if (intr) {
1648 /* order defines priority - do NOT change it */ 1605 /* order defines priority - do NOT change it */
@@ -1676,29 +1633,12 @@ static irqreturn_t udc_irq(struct ci13xxx *ci)
1676 } else { 1633 } else {
1677 retval = IRQ_NONE; 1634 retval = IRQ_NONE;
1678 } 1635 }
1679
1680 intr = hw_read(ci, OP_OTGSC, ~0);
1681 hw_write(ci, OP_OTGSC, ~0, intr);
1682
1683 if (intr & (OTGSC_AVVIE & OTGSC_AVVIS))
1684 queue_work(ci->wq, &ci->vbus_work);
1685
1686 spin_unlock(&ci->lock); 1636 spin_unlock(&ci->lock);
1687 1637
1688 return retval; 1638 return retval;
1689} 1639}
1690 1640
1691/** 1641/**
1692 * udc_release: driver release function
1693 * @dev: device
1694 *
1695 * Currently does nothing
1696 */
1697static void udc_release(struct device *dev)
1698{
1699}
1700
1701/**
1702 * udc_start: initialize gadget role 1642 * udc_start: initialize gadget role
1703 * @ci: chipidea controller 1643 * @ci: chipidea controller
1704 */ 1644 */
@@ -1717,12 +1657,6 @@ static int udc_start(struct ci13xxx *ci)
1717 1657
1718 INIT_LIST_HEAD(&ci->gadget.ep_list); 1658 INIT_LIST_HEAD(&ci->gadget.ep_list);
1719 1659
1720 dev_set_name(&ci->gadget.dev, "gadget");
1721 ci->gadget.dev.dma_mask = dev->dma_mask;
1722 ci->gadget.dev.coherent_dma_mask = dev->coherent_dma_mask;
1723 ci->gadget.dev.parent = dev;
1724 ci->gadget.dev.release = udc_release;
1725
1726 /* alloc resources */ 1660 /* alloc resources */
1727 ci->qh_pool = dma_pool_create("ci13xxx_qh", dev, 1661 ci->qh_pool = dma_pool_create("ci13xxx_qh", dev,
1728 sizeof(struct ci13xxx_qh), 1662 sizeof(struct ci13xxx_qh),
@@ -1758,24 +1692,13 @@ static int udc_start(struct ci13xxx *ci)
1758 retval = hw_device_reset(ci, USBMODE_CM_DC); 1692 retval = hw_device_reset(ci, USBMODE_CM_DC);
1759 if (retval) 1693 if (retval)
1760 goto put_transceiver; 1694 goto put_transceiver;
1761 hw_enable_vbus_intr(ci);
1762 }
1763
1764 retval = device_register(&ci->gadget.dev);
1765 if (retval) {
1766 put_device(&ci->gadget.dev);
1767 goto put_transceiver;
1768 } 1695 }
1769 1696
1770 retval = dbg_create_files(ci->dev);
1771 if (retval)
1772 goto unreg_device;
1773
1774 if (!IS_ERR_OR_NULL(ci->transceiver)) { 1697 if (!IS_ERR_OR_NULL(ci->transceiver)) {
1775 retval = otg_set_peripheral(ci->transceiver->otg, 1698 retval = otg_set_peripheral(ci->transceiver->otg,
1776 &ci->gadget); 1699 &ci->gadget);
1777 if (retval) 1700 if (retval)
1778 goto remove_dbg; 1701 goto put_transceiver;
1779 } 1702 }
1780 1703
1781 retval = usb_add_gadget_udc(dev, &ci->gadget); 1704 retval = usb_add_gadget_udc(dev, &ci->gadget);
@@ -1795,10 +1718,6 @@ remove_trans:
1795 } 1718 }
1796 1719
1797 dev_err(dev, "error = %i\n", retval); 1720 dev_err(dev, "error = %i\n", retval);
1798remove_dbg:
1799 dbg_remove_files(ci->dev);
1800unreg_device:
1801 device_unregister(&ci->gadget.dev);
1802put_transceiver: 1721put_transceiver:
1803 if (!IS_ERR_OR_NULL(ci->transceiver) && ci->global_phy) 1722 if (!IS_ERR_OR_NULL(ci->transceiver) && ci->global_phy)
1804 usb_put_phy(ci->transceiver); 1723 usb_put_phy(ci->transceiver);
@@ -1821,9 +1740,6 @@ static void udc_stop(struct ci13xxx *ci)
1821 if (ci == NULL) 1740 if (ci == NULL)
1822 return; 1741 return;
1823 1742
1824 hw_disable_vbus_intr(ci);
1825 cancel_work_sync(&ci->vbus_work);
1826
1827 usb_del_gadget_udc(&ci->gadget); 1743 usb_del_gadget_udc(&ci->gadget);
1828 1744
1829 destroy_eps(ci); 1745 destroy_eps(ci);
@@ -1836,8 +1752,6 @@ static void udc_stop(struct ci13xxx *ci)
1836 if (ci->global_phy) 1752 if (ci->global_phy)
1837 usb_put_phy(ci->transceiver); 1753 usb_put_phy(ci->transceiver);
1838 } 1754 }
1839 dbg_remove_files(ci->dev);
1840 device_unregister(&ci->gadget.dev);
1841 /* my kobject is dynamic, I swear! */ 1755 /* my kobject is dynamic, I swear! */
1842 memset(&ci->gadget, 0, sizeof(ci->gadget)); 1756 memset(&ci->gadget, 0, sizeof(ci->gadget));
1843} 1757}
@@ -1864,7 +1778,6 @@ int ci_hdrc_gadget_init(struct ci13xxx *ci)
1864 rdrv->irq = udc_irq; 1778 rdrv->irq = udc_irq;
1865 rdrv->name = "gadget"; 1779 rdrv->name = "gadget";
1866 ci->roles[CI_ROLE_GADGET] = rdrv; 1780 ci->roles[CI_ROLE_GADGET] = rdrv;
1867 INIT_WORK(&ci->vbus_work, vbus_work);
1868 1781
1869 return 0; 1782 return 0;
1870} 1783}
diff --git a/drivers/usb/chipidea/udc.h b/drivers/usb/chipidea/udc.h
index 4ff2384d7ca8..d12e8b59b110 100644
--- a/drivers/usb/chipidea/udc.h
+++ b/drivers/usb/chipidea/udc.h
@@ -40,7 +40,7 @@ struct ci13xxx_td {
40#define TD_CURR_OFFSET (0x0FFFUL << 0) 40#define TD_CURR_OFFSET (0x0FFFUL << 0)
41#define TD_FRAME_NUM (0x07FFUL << 0) 41#define TD_FRAME_NUM (0x07FFUL << 0)
42#define TD_RESERVED_MASK (0x0FFFUL << 0) 42#define TD_RESERVED_MASK (0x0FFFUL << 0)
43} __attribute__ ((packed)); 43} __attribute__ ((packed, aligned(4)));
44 44
45/* DMA layout of queue heads */ 45/* DMA layout of queue heads */
46struct ci13xxx_qh { 46struct ci13xxx_qh {
@@ -57,7 +57,7 @@ struct ci13xxx_qh {
57 /* 9 */ 57 /* 9 */
58 u32 RESERVED; 58 u32 RESERVED;
59 struct usb_ctrlrequest setup; 59 struct usb_ctrlrequest setup;
60} __attribute__ ((packed)); 60} __attribute__ ((packed, aligned(4)));
61 61
62/** 62/**
63 * struct ci13xxx_req - usb request representation 63 * struct ci13xxx_req - usb request representation
diff --git a/drivers/usb/chipidea/usbmisc_imx.c b/drivers/usb/chipidea/usbmisc_imx.c
new file mode 100644
index 000000000000..714a6bd810ed
--- /dev/null
+++ b/drivers/usb/chipidea/usbmisc_imx.c
@@ -0,0 +1,261 @@
1/*
2 * Copyright 2012 Freescale Semiconductor, Inc.
3 *
4 * The code contained herein is licensed under the GNU General Public
5 * License. You may obtain a copy of the GNU General Public License
6 * Version 2 or later at the following locations:
7 *
8 * http://www.opensource.org/licenses/gpl-license.html
9 * http://www.gnu.org/copyleft/gpl.html
10 */
11
12#include <linux/module.h>
13#include <linux/of_platform.h>
14#include <linux/clk.h>
15#include <linux/err.h>
16#include <linux/io.h>
17#include <linux/delay.h>
18
19#include "ci13xxx_imx.h"
20
21#define USB_DEV_MAX 4
22
23#define MX25_USB_PHY_CTRL_OFFSET 0x08
24#define MX25_BM_EXTERNAL_VBUS_DIVIDER BIT(23)
25
26#define MX53_USB_OTG_PHY_CTRL_0_OFFSET 0x08
27#define MX53_USB_UH2_CTRL_OFFSET 0x14
28#define MX53_USB_UH3_CTRL_OFFSET 0x18
29#define MX53_BM_OVER_CUR_DIS_H1 BIT(5)
30#define MX53_BM_OVER_CUR_DIS_OTG BIT(8)
31#define MX53_BM_OVER_CUR_DIS_UHx BIT(30)
32
33#define MX6_BM_OVER_CUR_DIS BIT(7)
34
35struct imx_usbmisc {
36 void __iomem *base;
37 spinlock_t lock;
38 struct clk *clk;
39 struct usbmisc_usb_device usbdev[USB_DEV_MAX];
40 const struct usbmisc_ops *ops;
41};
42
43static struct imx_usbmisc *usbmisc;
44
45static struct usbmisc_usb_device *get_usbdev(struct device *dev)
46{
47 int i, ret;
48
49 for (i = 0; i < USB_DEV_MAX; i++) {
50 if (usbmisc->usbdev[i].dev == dev)
51 return &usbmisc->usbdev[i];
52 else if (!usbmisc->usbdev[i].dev)
53 break;
54 }
55
56 if (i >= USB_DEV_MAX)
57 return ERR_PTR(-EBUSY);
58
59 ret = usbmisc_get_init_data(dev, &usbmisc->usbdev[i]);
60 if (ret)
61 return ERR_PTR(ret);
62
63 return &usbmisc->usbdev[i];
64}
65
66static int usbmisc_imx25_post(struct device *dev)
67{
68 struct usbmisc_usb_device *usbdev;
69 void __iomem *reg;
70 unsigned long flags;
71 u32 val;
72
73 usbdev = get_usbdev(dev);
74 if (IS_ERR(usbdev))
75 return PTR_ERR(usbdev);
76
77 reg = usbmisc->base + MX25_USB_PHY_CTRL_OFFSET;
78
79 if (usbdev->evdo) {
80 spin_lock_irqsave(&usbmisc->lock, flags);
81 val = readl(reg);
82 writel(val | MX25_BM_EXTERNAL_VBUS_DIVIDER, reg);
83 spin_unlock_irqrestore(&usbmisc->lock, flags);
84 usleep_range(5000, 10000); /* needed to stabilize voltage */
85 }
86
87 return 0;
88}
89
90static int usbmisc_imx53_init(struct device *dev)
91{
92 struct usbmisc_usb_device *usbdev;
93 void __iomem *reg = NULL;
94 unsigned long flags;
95 u32 val = 0;
96
97 usbdev = get_usbdev(dev);
98 if (IS_ERR(usbdev))
99 return PTR_ERR(usbdev);
100
101 if (usbdev->disable_oc) {
102 spin_lock_irqsave(&usbmisc->lock, flags);
103 switch (usbdev->index) {
104 case 0:
105 reg = usbmisc->base + MX53_USB_OTG_PHY_CTRL_0_OFFSET;
106 val = readl(reg) | MX53_BM_OVER_CUR_DIS_OTG;
107 break;
108 case 1:
109 reg = usbmisc->base + MX53_USB_OTG_PHY_CTRL_0_OFFSET;
110 val = readl(reg) | MX53_BM_OVER_CUR_DIS_H1;
111 break;
112 case 2:
113 reg = usbmisc->base + MX53_USB_UH2_CTRL_OFFSET;
114 val = readl(reg) | MX53_BM_OVER_CUR_DIS_UHx;
115 break;
116 case 3:
117 reg = usbmisc->base + MX53_USB_UH3_CTRL_OFFSET;
118 val = readl(reg) | MX53_BM_OVER_CUR_DIS_UHx;
119 break;
120 }
121 if (reg && val)
122 writel(val, reg);
123 spin_unlock_irqrestore(&usbmisc->lock, flags);
124 }
125
126 return 0;
127}
128
129static int usbmisc_imx6q_init(struct device *dev)
130{
131
132 struct usbmisc_usb_device *usbdev;
133 unsigned long flags;
134 u32 reg;
135
136 usbdev = get_usbdev(dev);
137 if (IS_ERR(usbdev))
138 return PTR_ERR(usbdev);
139
140 if (usbdev->disable_oc) {
141 spin_lock_irqsave(&usbmisc->lock, flags);
142 reg = readl(usbmisc->base + usbdev->index * 4);
143 writel(reg | MX6_BM_OVER_CUR_DIS,
144 usbmisc->base + usbdev->index * 4);
145 spin_unlock_irqrestore(&usbmisc->lock, flags);
146 }
147
148 return 0;
149}
150
151static const struct usbmisc_ops imx25_usbmisc_ops = {
152 .post = usbmisc_imx25_post,
153};
154
155static const struct usbmisc_ops imx53_usbmisc_ops = {
156 .init = usbmisc_imx53_init,
157};
158
159static const struct usbmisc_ops imx6q_usbmisc_ops = {
160 .init = usbmisc_imx6q_init,
161};
162
163static const struct of_device_id usbmisc_imx_dt_ids[] = {
164 {
165 .compatible = "fsl,imx25-usbmisc",
166 .data = &imx25_usbmisc_ops,
167 },
168 {
169 .compatible = "fsl,imx53-usbmisc",
170 .data = &imx53_usbmisc_ops,
171 },
172 {
173 .compatible = "fsl,imx6q-usbmisc",
174 .data = &imx6q_usbmisc_ops,
175 },
176 { /* sentinel */ }
177};
178
179static int usbmisc_imx_probe(struct platform_device *pdev)
180{
181 struct resource *res;
182 struct imx_usbmisc *data;
183 int ret;
184 struct of_device_id *tmp_dev;
185
186 if (usbmisc)
187 return -EBUSY;
188
189 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
190 if (!data)
191 return -ENOMEM;
192
193 spin_lock_init(&data->lock);
194
195 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
196 data->base = devm_ioremap_resource(&pdev->dev, res);
197 if (IS_ERR(data->base))
198 return PTR_ERR(data->base);
199
200 data->clk = devm_clk_get(&pdev->dev, NULL);
201 if (IS_ERR(data->clk)) {
202 dev_err(&pdev->dev,
203 "failed to get clock, err=%ld\n", PTR_ERR(data->clk));
204 return PTR_ERR(data->clk);
205 }
206
207 ret = clk_prepare_enable(data->clk);
208 if (ret) {
209 dev_err(&pdev->dev,
210 "clk_prepare_enable failed, err=%d\n", ret);
211 return ret;
212 }
213
214 tmp_dev = (struct of_device_id *)
215 of_match_device(usbmisc_imx_dt_ids, &pdev->dev);
216 data->ops = (const struct usbmisc_ops *)tmp_dev->data;
217 usbmisc = data;
218 ret = usbmisc_set_ops(data->ops);
219 if (ret) {
220 usbmisc = NULL;
221 clk_disable_unprepare(data->clk);
222 return ret;
223 }
224
225 return 0;
226}
227
228static int usbmisc_imx_remove(struct platform_device *pdev)
229{
230 usbmisc_unset_ops(usbmisc->ops);
231 clk_disable_unprepare(usbmisc->clk);
232 usbmisc = NULL;
233 return 0;
234}
235
236static struct platform_driver usbmisc_imx_driver = {
237 .probe = usbmisc_imx_probe,
238 .remove = usbmisc_imx_remove,
239 .driver = {
240 .name = "usbmisc_imx",
241 .owner = THIS_MODULE,
242 .of_match_table = usbmisc_imx_dt_ids,
243 },
244};
245
246int usbmisc_imx_drv_init(void)
247{
248 return platform_driver_register(&usbmisc_imx_driver);
249}
250subsys_initcall(usbmisc_imx_drv_init);
251
252void usbmisc_imx_drv_exit(void)
253{
254 platform_driver_unregister(&usbmisc_imx_driver);
255}
256module_exit(usbmisc_imx_drv_exit);
257
258MODULE_ALIAS("platform:usbmisc-imx");
259MODULE_LICENSE("GPL v2");
260MODULE_DESCRIPTION("driver for imx usb non-core registers");
261MODULE_AUTHOR("Richard Zhao <richard.zhao@freescale.com>");
diff --git a/drivers/usb/chipidea/usbmisc_imx6q.c b/drivers/usb/chipidea/usbmisc_imx6q.c
deleted file mode 100644
index a1bce391e825..000000000000
--- a/drivers/usb/chipidea/usbmisc_imx6q.c
+++ /dev/null
@@ -1,162 +0,0 @@
1/*
2 * Copyright 2012 Freescale Semiconductor, Inc.
3 *
4 * The code contained herein is licensed under the GNU General Public
5 * License. You may obtain a copy of the GNU General Public License
6 * Version 2 or later at the following locations:
7 *
8 * http://www.opensource.org/licenses/gpl-license.html
9 * http://www.gnu.org/copyleft/gpl.html
10 */
11
12#include <linux/module.h>
13#include <linux/of_platform.h>
14#include <linux/clk.h>
15#include <linux/err.h>
16#include <linux/io.h>
17
18#include "ci13xxx_imx.h"
19
20#define USB_DEV_MAX 4
21
22#define BM_OVER_CUR_DIS BIT(7)
23
24struct imx6q_usbmisc {
25 void __iomem *base;
26 spinlock_t lock;
27 struct clk *clk;
28 struct usbmisc_usb_device usbdev[USB_DEV_MAX];
29};
30
31static struct imx6q_usbmisc *usbmisc;
32
33static struct usbmisc_usb_device *get_usbdev(struct device *dev)
34{
35 int i, ret;
36
37 for (i = 0; i < USB_DEV_MAX; i++) {
38 if (usbmisc->usbdev[i].dev == dev)
39 return &usbmisc->usbdev[i];
40 else if (!usbmisc->usbdev[i].dev)
41 break;
42 }
43
44 if (i >= USB_DEV_MAX)
45 return ERR_PTR(-EBUSY);
46
47 ret = usbmisc_get_init_data(dev, &usbmisc->usbdev[i]);
48 if (ret)
49 return ERR_PTR(ret);
50
51 return &usbmisc->usbdev[i];
52}
53
54static int usbmisc_imx6q_init(struct device *dev)
55{
56
57 struct usbmisc_usb_device *usbdev;
58 unsigned long flags;
59 u32 reg;
60
61 usbdev = get_usbdev(dev);
62 if (IS_ERR(usbdev))
63 return PTR_ERR(usbdev);
64
65 if (usbdev->disable_oc) {
66 spin_lock_irqsave(&usbmisc->lock, flags);
67 reg = readl(usbmisc->base + usbdev->index * 4);
68 writel(reg | BM_OVER_CUR_DIS,
69 usbmisc->base + usbdev->index * 4);
70 spin_unlock_irqrestore(&usbmisc->lock, flags);
71 }
72
73 return 0;
74}
75
76static const struct usbmisc_ops imx6q_usbmisc_ops = {
77 .init = usbmisc_imx6q_init,
78};
79
80static const struct of_device_id usbmisc_imx6q_dt_ids[] = {
81 { .compatible = "fsl,imx6q-usbmisc"},
82 { /* sentinel */ }
83};
84
85static int usbmisc_imx6q_probe(struct platform_device *pdev)
86{
87 struct resource *res;
88 struct imx6q_usbmisc *data;
89 int ret;
90
91 if (usbmisc)
92 return -EBUSY;
93
94 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
95 if (!data)
96 return -ENOMEM;
97
98 spin_lock_init(&data->lock);
99
100 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
101 data->base = devm_ioremap_resource(&pdev->dev, res);
102 if (IS_ERR(data->base))
103 return PTR_ERR(data->base);
104
105 data->clk = devm_clk_get(&pdev->dev, NULL);
106 if (IS_ERR(data->clk)) {
107 dev_err(&pdev->dev,
108 "failed to get clock, err=%ld\n", PTR_ERR(data->clk));
109 return PTR_ERR(data->clk);
110 }
111
112 ret = clk_prepare_enable(data->clk);
113 if (ret) {
114 dev_err(&pdev->dev,
115 "clk_prepare_enable failed, err=%d\n", ret);
116 return ret;
117 }
118
119 ret = usbmisc_set_ops(&imx6q_usbmisc_ops);
120 if (ret) {
121 clk_disable_unprepare(data->clk);
122 return ret;
123 }
124
125 usbmisc = data;
126
127 return 0;
128}
129
130static int usbmisc_imx6q_remove(struct platform_device *pdev)
131{
132 usbmisc_unset_ops(&imx6q_usbmisc_ops);
133 clk_disable_unprepare(usbmisc->clk);
134 return 0;
135}
136
137static struct platform_driver usbmisc_imx6q_driver = {
138 .probe = usbmisc_imx6q_probe,
139 .remove = usbmisc_imx6q_remove,
140 .driver = {
141 .name = "usbmisc_imx6q",
142 .owner = THIS_MODULE,
143 .of_match_table = usbmisc_imx6q_dt_ids,
144 },
145};
146
147int __init usbmisc_imx6q_drv_init(void)
148{
149 return platform_driver_register(&usbmisc_imx6q_driver);
150}
151subsys_initcall(usbmisc_imx6q_drv_init);
152
153void __exit usbmisc_imx6q_drv_exit(void)
154{
155 platform_driver_unregister(&usbmisc_imx6q_driver);
156}
157module_exit(usbmisc_imx6q_drv_exit);
158
159MODULE_ALIAS("platform:usbmisc-imx6q");
160MODULE_LICENSE("GPL v2");
161MODULE_DESCRIPTION("driver for imx6q usb non-core registers");
162MODULE_AUTHOR("Richard Zhao <richard.zhao@freescale.com>");
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 387dc6c8ad25..6d4e0b96f89d 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -839,14 +839,6 @@ static int acm_tty_ioctl(struct tty_struct *tty,
839 return rv; 839 return rv;
840} 840}
841 841
842static const __u32 acm_tty_speed[] = {
843 0, 50, 75, 110, 134, 150, 200, 300, 600,
844 1200, 1800, 2400, 4800, 9600, 19200, 38400,
845 57600, 115200, 230400, 460800, 500000, 576000,
846 921600, 1000000, 1152000, 1500000, 2000000,
847 2500000, 3000000, 3500000, 4000000
848};
849
850static void acm_tty_set_termios(struct tty_struct *tty, 842static void acm_tty_set_termios(struct tty_struct *tty,
851 struct ktermios *termios_old) 843 struct ktermios *termios_old)
852{ 844{
diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
index 122d056d96d5..8a230f0ef77c 100644
--- a/drivers/usb/class/cdc-wdm.c
+++ b/drivers/usb/class/cdc-wdm.c
@@ -13,6 +13,7 @@
13 */ 13 */
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/errno.h> 15#include <linux/errno.h>
16#include <linux/ioctl.h>
16#include <linux/slab.h> 17#include <linux/slab.h>
17#include <linux/module.h> 18#include <linux/module.h>
18#include <linux/mutex.h> 19#include <linux/mutex.h>
@@ -644,6 +645,22 @@ static int wdm_release(struct inode *inode, struct file *file)
644 return 0; 645 return 0;
645} 646}
646 647
648static long wdm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
649{
650 struct wdm_device *desc = file->private_data;
651 int rv = 0;
652
653 switch (cmd) {
654 case IOCTL_WDM_MAX_COMMAND:
655 if (copy_to_user((void __user *)arg, &desc->wMaxCommand, sizeof(desc->wMaxCommand)))
656 rv = -EFAULT;
657 break;
658 default:
659 rv = -ENOTTY;
660 }
661 return rv;
662}
663
647static const struct file_operations wdm_fops = { 664static const struct file_operations wdm_fops = {
648 .owner = THIS_MODULE, 665 .owner = THIS_MODULE,
649 .read = wdm_read, 666 .read = wdm_read,
@@ -652,6 +669,8 @@ static const struct file_operations wdm_fops = {
652 .flush = wdm_flush, 669 .flush = wdm_flush,
653 .release = wdm_release, 670 .release = wdm_release,
654 .poll = wdm_poll, 671 .poll = wdm_poll,
672 .unlocked_ioctl = wdm_ioctl,
673 .compat_ioctl = wdm_ioctl,
655 .llseek = noop_llseek, 674 .llseek = noop_llseek,
656}; 675};
657 676
diff --git a/drivers/usb/core/Kconfig b/drivers/usb/core/Kconfig
index f70c1a1694ad..7b7305e3abc8 100644
--- a/drivers/usb/core/Kconfig
+++ b/drivers/usb/core/Kconfig
@@ -27,6 +27,22 @@ config USB_ANNOUNCE_NEW_DEVICES
27comment "Miscellaneous USB options" 27comment "Miscellaneous USB options"
28 depends on USB 28 depends on USB
29 29
30config USB_DEFAULT_PERSIST
31 bool "Enable USB persist by default"
32 depends on USB
33 default y
34 help
35 Say N here if you don't want USB power session persistance
36 enabled by default. If you say N it will make suspended USB
37 devices that lose power get reenumerated as if they had been
38 unplugged, causing any mounted filesystems to be lost. The
39 persist feature can still be enabled for individual devices
40 through the power/persist sysfs node. See
41 Documentation/usb/persist.txt for more info.
42
43 If you have any questions about this, say Y here, only say N
44 if you know exactly what you are doing.
45
30config USB_DYNAMIC_MINORS 46config USB_DYNAMIC_MINORS
31 bool "Dynamic USB minor allocation" 47 bool "Dynamic USB minor allocation"
32 depends on USB 48 depends on USB
@@ -38,22 +54,6 @@ config USB_DYNAMIC_MINORS
38 54
39 If you are unsure about this, say N here. 55 If you are unsure about this, say N here.
40 56
41config USB_SUSPEND
42 bool "USB runtime power management (autosuspend) and wakeup"
43 depends on USB && PM_RUNTIME
44 help
45 If you say Y here, you can use driver calls or the sysfs
46 "power/control" file to enable or disable autosuspend for
47 individual USB peripherals (see
48 Documentation/usb/power-management.txt for more details).
49
50 Also, USB "remote wakeup" signaling is supported, whereby some
51 USB devices (like keyboards and network adapters) can wake up
52 their parent hub. That wakeup cascades up the USB tree, and
53 could wake the system from states like suspend-to-RAM.
54
55 If you are unsure about this, say N here.
56
57config USB_OTG 57config USB_OTG
58 bool "OTG support" 58 bool "OTG support"
59 depends on USB 59 depends on USB
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index d938b2b99e31..6eab440e1542 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -1196,9 +1196,14 @@ done:
1196 * 1196 *
1197 * This is the central routine for suspending USB devices. It calls the 1197 * This is the central routine for suspending USB devices. It calls the
1198 * suspend methods for all the interface drivers in @udev and then calls 1198 * suspend methods for all the interface drivers in @udev and then calls
1199 * the suspend method for @udev itself. If an error occurs at any stage, 1199 * the suspend method for @udev itself. When the routine is called in
1200 * all the interfaces which were suspended are resumed so that they remain 1200 * autosuspend, if an error occurs at any stage, all the interfaces
1201 * in the same state as the device. 1201 * which were suspended are resumed so that they remain in the same
1202 * state as the device, but when called from system sleep, all error
1203 * from suspend methods of interfaces and the non-root-hub device itself
1204 * are simply ignored, so all suspended interfaces are only resumed
1205 * to the device's state when @udev is root-hub and its suspend method
1206 * returns failure.
1202 * 1207 *
1203 * Autosuspend requests originating from a child device or an interface 1208 * Autosuspend requests originating from a child device or an interface
1204 * driver may be made without the protection of @udev's device lock, but 1209 * driver may be made without the protection of @udev's device lock, but
@@ -1248,10 +1253,12 @@ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg)
1248 1253
1249 /* If the suspend failed, resume interfaces that did get suspended */ 1254 /* If the suspend failed, resume interfaces that did get suspended */
1250 if (status != 0) { 1255 if (status != 0) {
1251 msg.event ^= (PM_EVENT_SUSPEND | PM_EVENT_RESUME); 1256 if (udev->actconfig) {
1252 while (++i < n) { 1257 msg.event ^= (PM_EVENT_SUSPEND | PM_EVENT_RESUME);
1253 intf = udev->actconfig->interface[i]; 1258 while (++i < n) {
1254 usb_resume_interface(udev, intf, msg, 0); 1259 intf = udev->actconfig->interface[i];
1260 usb_resume_interface(udev, intf, msg, 0);
1261 }
1255 } 1262 }
1256 1263
1257 /* If the suspend succeeded then prevent any more URB submissions 1264 /* If the suspend succeeded then prevent any more URB submissions
@@ -1407,7 +1414,7 @@ int usb_resume(struct device *dev, pm_message_t msg)
1407 1414
1408#endif /* CONFIG_PM */ 1415#endif /* CONFIG_PM */
1409 1416
1410#ifdef CONFIG_USB_SUSPEND 1417#ifdef CONFIG_PM_RUNTIME
1411 1418
1412/** 1419/**
1413 * usb_enable_autosuspend - allow a USB device to be autosuspended 1420 * usb_enable_autosuspend - allow a USB device to be autosuspended
@@ -1775,7 +1782,7 @@ int usb_set_usb2_hardware_lpm(struct usb_device *udev, int enable)
1775 return ret; 1782 return ret;
1776} 1783}
1777 1784
1778#endif /* CONFIG_USB_SUSPEND */ 1785#endif /* CONFIG_PM_RUNTIME */
1779 1786
1780struct bus_type usb_bus_type = { 1787struct bus_type usb_bus_type = {
1781 .name = "usb", 1788 .name = "usb",
diff --git a/drivers/usb/core/generic.c b/drivers/usb/core/generic.c
index 271e761f563e..acbfeb0a0119 100644
--- a/drivers/usb/core/generic.c
+++ b/drivers/usb/core/generic.c
@@ -169,7 +169,7 @@ static int generic_probe(struct usb_device *udev)
169 c = usb_choose_configuration(udev); 169 c = usb_choose_configuration(udev);
170 if (c >= 0) { 170 if (c >= 0) {
171 err = usb_set_configuration(udev, c); 171 err = usb_set_configuration(udev, c);
172 if (err) { 172 if (err && err != -ENODEV) {
173 dev_err(&udev->dev, "can't set config #%d, error %d\n", 173 dev_err(&udev->dev, "can't set config #%d, error %d\n",
174 c, err); 174 c, err);
175 /* This need not be fatal. The user can try to 175 /* This need not be fatal. The user can try to
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c
index 2b487d4797bd..caeb8d6d39fb 100644
--- a/drivers/usb/core/hcd-pci.c
+++ b/drivers/usb/core/hcd-pci.c
@@ -37,119 +37,123 @@
37 37
38/* PCI-based HCs are common, but plenty of non-PCI HCs are used too */ 38/* PCI-based HCs are common, but plenty of non-PCI HCs are used too */
39 39
40#ifdef CONFIG_PM_SLEEP 40/*
41 41 * Coordinate handoffs between EHCI and companion controllers
42/* Coordinate handoffs between EHCI and companion controllers 42 * during EHCI probing and system resume.
43 * during system resume
44 */ 43 */
45 44
46static DEFINE_MUTEX(companions_mutex); 45static DECLARE_RWSEM(companions_rwsem);
47 46
48#define CL_UHCI PCI_CLASS_SERIAL_USB_UHCI 47#define CL_UHCI PCI_CLASS_SERIAL_USB_UHCI
49#define CL_OHCI PCI_CLASS_SERIAL_USB_OHCI 48#define CL_OHCI PCI_CLASS_SERIAL_USB_OHCI
50#define CL_EHCI PCI_CLASS_SERIAL_USB_EHCI 49#define CL_EHCI PCI_CLASS_SERIAL_USB_EHCI
51 50
52enum companion_action { 51static inline int is_ohci_or_uhci(struct pci_dev *pdev)
53 SET_HS_COMPANION, CLEAR_HS_COMPANION, WAIT_FOR_COMPANIONS 52{
54}; 53 return pdev->class == CL_OHCI || pdev->class == CL_UHCI;
54}
55
56typedef void (*companion_fn)(struct pci_dev *pdev, struct usb_hcd *hcd,
57 struct pci_dev *companion, struct usb_hcd *companion_hcd);
55 58
56static void companion_common(struct pci_dev *pdev, struct usb_hcd *hcd, 59/* Iterate over PCI devices in the same slot as pdev and call fn for each */
57 enum companion_action action) 60static void for_each_companion(struct pci_dev *pdev, struct usb_hcd *hcd,
61 companion_fn fn)
58{ 62{
59 struct pci_dev *companion; 63 struct pci_dev *companion;
60 struct usb_hcd *companion_hcd; 64 struct usb_hcd *companion_hcd;
61 unsigned int slot = PCI_SLOT(pdev->devfn); 65 unsigned int slot = PCI_SLOT(pdev->devfn);
62 66
63 /* Iterate through other PCI functions in the same slot. 67 /*
64 * If pdev is OHCI or UHCI then we are looking for EHCI, and 68 * Iterate through other PCI functions in the same slot.
65 * vice versa. 69 * If the function's drvdata isn't set then it isn't bound to
70 * a USB host controller driver, so skip it.
66 */ 71 */
67 companion = NULL; 72 companion = NULL;
68 for_each_pci_dev(companion) { 73 for_each_pci_dev(companion) {
69 if (companion->bus != pdev->bus || 74 if (companion->bus != pdev->bus ||
70 PCI_SLOT(companion->devfn) != slot) 75 PCI_SLOT(companion->devfn) != slot)
71 continue; 76 continue;
72
73 companion_hcd = pci_get_drvdata(companion); 77 companion_hcd = pci_get_drvdata(companion);
74 if (!companion_hcd) 78 if (!companion_hcd)
75 continue; 79 continue;
76 80 fn(pdev, hcd, companion, companion_hcd);
77 /* For SET_HS_COMPANION, store a pointer to the EHCI bus in
78 * the OHCI/UHCI companion bus structure.
79 * For CLEAR_HS_COMPANION, clear the pointer to the EHCI bus
80 * in the OHCI/UHCI companion bus structure.
81 * For WAIT_FOR_COMPANIONS, wait until the OHCI/UHCI
82 * companion controllers have fully resumed.
83 */
84
85 if ((pdev->class == CL_OHCI || pdev->class == CL_UHCI) &&
86 companion->class == CL_EHCI) {
87 /* action must be SET_HS_COMPANION */
88 dev_dbg(&companion->dev, "HS companion for %s\n",
89 dev_name(&pdev->dev));
90 hcd->self.hs_companion = &companion_hcd->self;
91
92 } else if (pdev->class == CL_EHCI &&
93 (companion->class == CL_OHCI ||
94 companion->class == CL_UHCI)) {
95 switch (action) {
96 case SET_HS_COMPANION:
97 dev_dbg(&pdev->dev, "HS companion for %s\n",
98 dev_name(&companion->dev));
99 companion_hcd->self.hs_companion = &hcd->self;
100 break;
101 case CLEAR_HS_COMPANION:
102 companion_hcd->self.hs_companion = NULL;
103 break;
104 case WAIT_FOR_COMPANIONS:
105 device_pm_wait_for_dev(&pdev->dev,
106 &companion->dev);
107 break;
108 }
109 }
110 } 81 }
111} 82}
112 83
113static void set_hs_companion(struct pci_dev *pdev, struct usb_hcd *hcd) 84/*
85 * We're about to add an EHCI controller, which will unceremoniously grab
86 * all the port connections away from its companions. To prevent annoying
87 * error messages, lock the companion's root hub and gracefully unconfigure
88 * it beforehand. Leave it locked until the EHCI controller is all set.
89 */
90static void ehci_pre_add(struct pci_dev *pdev, struct usb_hcd *hcd,
91 struct pci_dev *companion, struct usb_hcd *companion_hcd)
114{ 92{
115 mutex_lock(&companions_mutex); 93 struct usb_device *udev;
116 dev_set_drvdata(&pdev->dev, hcd); 94
117 companion_common(pdev, hcd, SET_HS_COMPANION); 95 if (is_ohci_or_uhci(companion)) {
118 mutex_unlock(&companions_mutex); 96 udev = companion_hcd->self.root_hub;
97 usb_lock_device(udev);
98 usb_set_configuration(udev, 0);
99 }
119} 100}
120 101
121static void clear_hs_companion(struct pci_dev *pdev, struct usb_hcd *hcd) 102/*
103 * Adding the EHCI controller has either succeeded or failed. Set the
104 * companion pointer accordingly, and in either case, reconfigure and
105 * unlock the root hub.
106 */
107static void ehci_post_add(struct pci_dev *pdev, struct usb_hcd *hcd,
108 struct pci_dev *companion, struct usb_hcd *companion_hcd)
122{ 109{
123 mutex_lock(&companions_mutex); 110 struct usb_device *udev;
124 dev_set_drvdata(&pdev->dev, NULL);
125 111
126 /* If pdev is OHCI or UHCI, just clear its hs_companion pointer */ 112 if (is_ohci_or_uhci(companion)) {
127 if (pdev->class == CL_OHCI || pdev->class == CL_UHCI) 113 if (dev_get_drvdata(&pdev->dev)) { /* Succeeded */
128 hcd->self.hs_companion = NULL; 114 dev_dbg(&pdev->dev, "HS companion for %s\n",
115 dev_name(&companion->dev));
116 companion_hcd->self.hs_companion = &hcd->self;
117 }
118 udev = companion_hcd->self.root_hub;
119 usb_set_configuration(udev, 1);
120 usb_unlock_device(udev);
121 }
122}
129 123
130 /* Otherwise search for companion buses and clear their pointers */ 124/*
131 else 125 * We just added a non-EHCI controller. Find the EHCI controller to
132 companion_common(pdev, hcd, CLEAR_HS_COMPANION); 126 * which it is a companion, and store a pointer to the bus structure.
133 mutex_unlock(&companions_mutex); 127 */
128static void non_ehci_add(struct pci_dev *pdev, struct usb_hcd *hcd,
129 struct pci_dev *companion, struct usb_hcd *companion_hcd)
130{
131 if (is_ohci_or_uhci(pdev) && companion->class == CL_EHCI) {
132 dev_dbg(&pdev->dev, "FS/LS companion for %s\n",
133 dev_name(&companion->dev));
134 hcd->self.hs_companion = &companion_hcd->self;
135 }
134} 136}
135 137
136static void wait_for_companions(struct pci_dev *pdev, struct usb_hcd *hcd) 138/* We are removing an EHCI controller. Clear the companions' pointers. */
139static void ehci_remove(struct pci_dev *pdev, struct usb_hcd *hcd,
140 struct pci_dev *companion, struct usb_hcd *companion_hcd)
137{ 141{
138 /* Only EHCI controllers need to wait. 142 if (is_ohci_or_uhci(companion))
139 * No locking is needed because a controller cannot be resumed 143 companion_hcd->self.hs_companion = NULL;
140 * while one of its companions is getting unbound.
141 */
142 if (pdev->class == CL_EHCI)
143 companion_common(pdev, hcd, WAIT_FOR_COMPANIONS);
144} 144}
145 145
146#else /* !CONFIG_PM_SLEEP */ 146#ifdef CONFIG_PM
147 147
148static inline void set_hs_companion(struct pci_dev *d, struct usb_hcd *h) {} 148/* An EHCI controller must wait for its companions before resuming. */
149static inline void clear_hs_companion(struct pci_dev *d, struct usb_hcd *h) {} 149static void ehci_wait_for_companions(struct pci_dev *pdev, struct usb_hcd *hcd,
150static inline void wait_for_companions(struct pci_dev *d, struct usb_hcd *h) {} 150 struct pci_dev *companion, struct usb_hcd *companion_hcd)
151{
152 if (is_ohci_or_uhci(companion))
153 device_pm_wait_for_dev(&pdev->dev, &companion->dev);
154}
151 155
152#endif /* !CONFIG_PM_SLEEP */ 156#endif /* CONFIG_PM */
153 157
154/*-------------------------------------------------------------------------*/ 158/*-------------------------------------------------------------------------*/
155 159
@@ -217,7 +221,7 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
217 driver->description)) { 221 driver->description)) {
218 dev_dbg(&dev->dev, "controller already in use\n"); 222 dev_dbg(&dev->dev, "controller already in use\n");
219 retval = -EBUSY; 223 retval = -EBUSY;
220 goto clear_companion; 224 goto put_hcd;
221 } 225 }
222 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len); 226 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
223 if (hcd->regs == NULL) { 227 if (hcd->regs == NULL) {
@@ -244,16 +248,35 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
244 if (region == PCI_ROM_RESOURCE) { 248 if (region == PCI_ROM_RESOURCE) {
245 dev_dbg(&dev->dev, "no i/o regions available\n"); 249 dev_dbg(&dev->dev, "no i/o regions available\n");
246 retval = -EBUSY; 250 retval = -EBUSY;
247 goto clear_companion; 251 goto put_hcd;
248 } 252 }
249 } 253 }
250 254
251 pci_set_master(dev); 255 pci_set_master(dev);
252 256
253 retval = usb_add_hcd(hcd, hcd_irq, IRQF_SHARED); 257 /* Note: dev_set_drvdata must be called while holding the rwsem */
258 if (dev->class == CL_EHCI) {
259 down_write(&companions_rwsem);
260 dev_set_drvdata(&dev->dev, hcd);
261 for_each_companion(dev, hcd, ehci_pre_add);
262 retval = usb_add_hcd(hcd, hcd_irq, IRQF_SHARED);
263 if (retval != 0)
264 dev_set_drvdata(&dev->dev, NULL);
265 for_each_companion(dev, hcd, ehci_post_add);
266 up_write(&companions_rwsem);
267 } else {
268 down_read(&companions_rwsem);
269 dev_set_drvdata(&dev->dev, hcd);
270 retval = usb_add_hcd(hcd, hcd_irq, IRQF_SHARED);
271 if (retval != 0)
272 dev_set_drvdata(&dev->dev, NULL);
273 else
274 for_each_companion(dev, hcd, non_ehci_add);
275 up_read(&companions_rwsem);
276 }
277
254 if (retval != 0) 278 if (retval != 0)
255 goto unmap_registers; 279 goto unmap_registers;
256 set_hs_companion(dev, hcd);
257 280
258 if (pci_dev_run_wake(dev)) 281 if (pci_dev_run_wake(dev))
259 pm_runtime_put_noidle(&dev->dev); 282 pm_runtime_put_noidle(&dev->dev);
@@ -266,8 +289,7 @@ release_mem_region:
266 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 289 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
267 } else 290 } else
268 release_region(hcd->rsrc_start, hcd->rsrc_len); 291 release_region(hcd->rsrc_start, hcd->rsrc_len);
269clear_companion: 292put_hcd:
270 clear_hs_companion(dev, hcd);
271 usb_put_hcd(hcd); 293 usb_put_hcd(hcd);
272disable_pci: 294disable_pci:
273 pci_disable_device(dev); 295 pci_disable_device(dev);
@@ -310,14 +332,29 @@ void usb_hcd_pci_remove(struct pci_dev *dev)
310 usb_hcd_irq(0, hcd); 332 usb_hcd_irq(0, hcd);
311 local_irq_enable(); 333 local_irq_enable();
312 334
313 usb_remove_hcd(hcd); 335 /* Note: dev_set_drvdata must be called while holding the rwsem */
336 if (dev->class == CL_EHCI) {
337 down_write(&companions_rwsem);
338 for_each_companion(dev, hcd, ehci_remove);
339 usb_remove_hcd(hcd);
340 dev_set_drvdata(&dev->dev, NULL);
341 up_write(&companions_rwsem);
342 } else {
343 /* Not EHCI; just clear the companion pointer */
344 down_read(&companions_rwsem);
345 hcd->self.hs_companion = NULL;
346 usb_remove_hcd(hcd);
347 dev_set_drvdata(&dev->dev, NULL);
348 up_read(&companions_rwsem);
349 }
350
314 if (hcd->driver->flags & HCD_MEMORY) { 351 if (hcd->driver->flags & HCD_MEMORY) {
315 iounmap(hcd->regs); 352 iounmap(hcd->regs);
316 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 353 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
317 } else { 354 } else {
318 release_region(hcd->rsrc_start, hcd->rsrc_len); 355 release_region(hcd->rsrc_start, hcd->rsrc_len);
319 } 356 }
320 clear_hs_companion(dev, hcd); 357
321 usb_put_hcd(hcd); 358 usb_put_hcd(hcd);
322 pci_disable_device(dev); 359 pci_disable_device(dev);
323} 360}
@@ -463,8 +500,15 @@ static int resume_common(struct device *dev, int event)
463 pci_set_master(pci_dev); 500 pci_set_master(pci_dev);
464 501
465 if (hcd->driver->pci_resume && !HCD_DEAD(hcd)) { 502 if (hcd->driver->pci_resume && !HCD_DEAD(hcd)) {
466 if (event != PM_EVENT_AUTO_RESUME) 503
467 wait_for_companions(pci_dev, hcd); 504 /*
505 * Only EHCI controllers have to wait for their companions.
506 * No locking is needed because PCI controller drivers do not
507 * get unbound during system resume.
508 */
509 if (pci_dev->class == CL_EHCI && event != PM_EVENT_AUTO_RESUME)
510 for_each_companion(pci_dev, hcd,
511 ehci_wait_for_companions);
468 512
469 retval = hcd->driver->pci_resume(hcd, 513 retval = hcd->driver->pci_resume(hcd,
470 event == PM_EVENT_RESTORE); 514 event == PM_EVENT_RESTORE);
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index f9ec44cbb82f..d53547d2e4c7 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -2125,7 +2125,7 @@ int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg)
2125 2125
2126#endif /* CONFIG_PM */ 2126#endif /* CONFIG_PM */
2127 2127
2128#ifdef CONFIG_USB_SUSPEND 2128#ifdef CONFIG_PM_RUNTIME
2129 2129
2130/* Workqueue routine for root-hub remote wakeup */ 2130/* Workqueue routine for root-hub remote wakeup */
2131static void hcd_resume_work(struct work_struct *work) 2131static void hcd_resume_work(struct work_struct *work)
@@ -2160,7 +2160,7 @@ void usb_hcd_resume_root_hub (struct usb_hcd *hcd)
2160} 2160}
2161EXPORT_SYMBOL_GPL(usb_hcd_resume_root_hub); 2161EXPORT_SYMBOL_GPL(usb_hcd_resume_root_hub);
2162 2162
2163#endif /* CONFIG_USB_SUSPEND */ 2163#endif /* CONFIG_PM_RUNTIME */
2164 2164
2165/*-------------------------------------------------------------------------*/ 2165/*-------------------------------------------------------------------------*/
2166 2166
@@ -2336,7 +2336,7 @@ struct usb_hcd *usb_create_shared_hcd(const struct hc_driver *driver,
2336 init_timer(&hcd->rh_timer); 2336 init_timer(&hcd->rh_timer);
2337 hcd->rh_timer.function = rh_timer_func; 2337 hcd->rh_timer.function = rh_timer_func;
2338 hcd->rh_timer.data = (unsigned long) hcd; 2338 hcd->rh_timer.data = (unsigned long) hcd;
2339#ifdef CONFIG_USB_SUSPEND 2339#ifdef CONFIG_PM_RUNTIME
2340 INIT_WORK(&hcd->wakeup_work, hcd_resume_work); 2340 INIT_WORK(&hcd->wakeup_work, hcd_resume_work);
2341#endif 2341#endif
2342 2342
@@ -2590,7 +2590,7 @@ error_create_attr_group:
2590 hcd->rh_registered = 0; 2590 hcd->rh_registered = 0;
2591 spin_unlock_irq(&hcd_root_hub_lock); 2591 spin_unlock_irq(&hcd_root_hub_lock);
2592 2592
2593#ifdef CONFIG_USB_SUSPEND 2593#ifdef CONFIG_PM_RUNTIME
2594 cancel_work_sync(&hcd->wakeup_work); 2594 cancel_work_sync(&hcd->wakeup_work);
2595#endif 2595#endif
2596 mutex_lock(&usb_bus_list_lock); 2596 mutex_lock(&usb_bus_list_lock);
@@ -2645,7 +2645,7 @@ void usb_remove_hcd(struct usb_hcd *hcd)
2645 hcd->rh_registered = 0; 2645 hcd->rh_registered = 0;
2646 spin_unlock_irq (&hcd_root_hub_lock); 2646 spin_unlock_irq (&hcd_root_hub_lock);
2647 2647
2648#ifdef CONFIG_USB_SUSPEND 2648#ifdef CONFIG_PM_RUNTIME
2649 cancel_work_sync(&hcd->wakeup_work); 2649 cancel_work_sync(&hcd->wakeup_work);
2650#endif 2650#endif
2651 2651
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 5480352f984d..feef9351463d 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -555,8 +555,9 @@ static int hub_port_status(struct usb_hub *hub, int port1,
555 mutex_lock(&hub->status_mutex); 555 mutex_lock(&hub->status_mutex);
556 ret = get_port_status(hub->hdev, port1, &hub->status->port); 556 ret = get_port_status(hub->hdev, port1, &hub->status->port);
557 if (ret < 4) { 557 if (ret < 4) {
558 dev_err(hub->intfdev, 558 if (ret != -ENODEV)
559 "%s failed (err = %d)\n", __func__, ret); 559 dev_err(hub->intfdev,
560 "%s failed (err = %d)\n", __func__, ret);
560 if (ret >= 0) 561 if (ret >= 0)
561 ret = -EIO; 562 ret = -EIO;
562 } else { 563 } else {
@@ -699,7 +700,7 @@ static void hub_tt_work(struct work_struct *work)
699 /* drop lock so HCD can concurrently report other TT errors */ 700 /* drop lock so HCD can concurrently report other TT errors */
700 spin_unlock_irqrestore (&hub->tt.lock, flags); 701 spin_unlock_irqrestore (&hub->tt.lock, flags);
701 status = hub_clear_tt_buffer (hdev, clear->devinfo, clear->tt); 702 status = hub_clear_tt_buffer (hdev, clear->devinfo, clear->tt);
702 if (status) 703 if (status && status != -ENODEV)
703 dev_err (&hdev->dev, 704 dev_err (&hdev->dev,
704 "clear tt %d (%04x) error %d\n", 705 "clear tt %d (%04x) error %d\n",
705 clear->tt, clear->devinfo, status); 706 clear->tt, clear->devinfo, status);
@@ -837,10 +838,11 @@ static int hub_hub_status(struct usb_hub *hub,
837 838
838 mutex_lock(&hub->status_mutex); 839 mutex_lock(&hub->status_mutex);
839 ret = get_hub_status(hub->hdev, &hub->status->hub); 840 ret = get_hub_status(hub->hdev, &hub->status->hub);
840 if (ret < 0) 841 if (ret < 0) {
841 dev_err (hub->intfdev, 842 if (ret != -ENODEV)
842 "%s failed (err = %d)\n", __func__, ret); 843 dev_err(hub->intfdev,
843 else { 844 "%s failed (err = %d)\n", __func__, ret);
845 } else {
844 *status = le16_to_cpu(hub->status->hub.wHubStatus); 846 *status = le16_to_cpu(hub->status->hub.wHubStatus);
845 *change = le16_to_cpu(hub->status->hub.wHubChange); 847 *change = le16_to_cpu(hub->status->hub.wHubChange);
846 ret = 0; 848 ret = 0;
@@ -877,11 +879,8 @@ static int hub_usb3_port_disable(struct usb_hub *hub, int port1)
877 return -EINVAL; 879 return -EINVAL;
878 880
879 ret = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_SS_DISABLED); 881 ret = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_SS_DISABLED);
880 if (ret) { 882 if (ret)
881 dev_err(hub->intfdev, "cannot disable port %d (err = %d)\n",
882 port1, ret);
883 return ret; 883 return ret;
884 }
885 884
886 /* Wait for the link to enter the disabled state. */ 885 /* Wait for the link to enter the disabled state. */
887 for (total_time = 0; ; total_time += HUB_DEBOUNCE_STEP) { 886 for (total_time = 0; ; total_time += HUB_DEBOUNCE_STEP) {
@@ -918,7 +917,7 @@ static int hub_port_disable(struct usb_hub *hub, int port1, int set_state)
918 ret = usb_clear_port_feature(hdev, port1, 917 ret = usb_clear_port_feature(hdev, port1,
919 USB_PORT_FEAT_ENABLE); 918 USB_PORT_FEAT_ENABLE);
920 } 919 }
921 if (ret) 920 if (ret && ret != -ENODEV)
922 dev_err(hub->intfdev, "cannot disable port %d (err = %d)\n", 921 dev_err(hub->intfdev, "cannot disable port %d (err = %d)\n",
923 port1, ret); 922 port1, ret);
924 return ret; 923 return ret;
@@ -1317,6 +1316,10 @@ static int hub_configure(struct usb_hub *hub,
1317 message = "hub has too many ports!"; 1316 message = "hub has too many ports!";
1318 ret = -ENODEV; 1317 ret = -ENODEV;
1319 goto fail; 1318 goto fail;
1319 } else if (hub->descriptor->bNbrPorts == 0) {
1320 message = "hub doesn't have any ports!";
1321 ret = -ENODEV;
1322 goto fail;
1320 } 1323 }
1321 1324
1322 hdev->maxchild = hub->descriptor->bNbrPorts; 1325 hdev->maxchild = hub->descriptor->bNbrPorts;
@@ -2192,8 +2195,9 @@ static int usb_enumerate_device(struct usb_device *udev)
2192 if (udev->config == NULL) { 2195 if (udev->config == NULL) {
2193 err = usb_get_configuration(udev); 2196 err = usb_get_configuration(udev);
2194 if (err < 0) { 2197 if (err < 0) {
2195 dev_err(&udev->dev, "can't read configurations, error %d\n", 2198 if (err != -ENODEV)
2196 err); 2199 dev_err(&udev->dev, "can't read configurations, error %d\n",
2200 err);
2197 return err; 2201 return err;
2198 } 2202 }
2199 } 2203 }
@@ -2640,14 +2644,16 @@ static int hub_port_reset(struct usb_hub *hub, int port1,
2640 status = set_port_feature(hub->hdev, port1, (warm ? 2644 status = set_port_feature(hub->hdev, port1, (warm ?
2641 USB_PORT_FEAT_BH_PORT_RESET : 2645 USB_PORT_FEAT_BH_PORT_RESET :
2642 USB_PORT_FEAT_RESET)); 2646 USB_PORT_FEAT_RESET));
2643 if (status) { 2647 if (status == -ENODEV) {
2648 ; /* The hub is gone */
2649 } else if (status) {
2644 dev_err(hub->intfdev, 2650 dev_err(hub->intfdev,
2645 "cannot %sreset port %d (err = %d)\n", 2651 "cannot %sreset port %d (err = %d)\n",
2646 warm ? "warm " : "", port1, status); 2652 warm ? "warm " : "", port1, status);
2647 } else { 2653 } else {
2648 status = hub_port_wait_reset(hub, port1, udev, delay, 2654 status = hub_port_wait_reset(hub, port1, udev, delay,
2649 warm); 2655 warm);
2650 if (status && status != -ENOTCONN) 2656 if (status && status != -ENOTCONN && status != -ENODEV)
2651 dev_dbg(hub->intfdev, 2657 dev_dbg(hub->intfdev,
2652 "port_wait_reset: err = %d\n", 2658 "port_wait_reset: err = %d\n",
2653 status); 2659 status);
@@ -2821,7 +2827,7 @@ void usb_enable_ltm(struct usb_device *udev)
2821} 2827}
2822EXPORT_SYMBOL_GPL(usb_enable_ltm); 2828EXPORT_SYMBOL_GPL(usb_enable_ltm);
2823 2829
2824#ifdef CONFIG_USB_SUSPEND 2830#ifdef CONFIG_PM
2825/* 2831/*
2826 * usb_disable_function_remotewakeup - disable usb3.0 2832 * usb_disable_function_remotewakeup - disable usb3.0
2827 * device's function remote wakeup 2833 * device's function remote wakeup
@@ -2880,9 +2886,11 @@ static int usb_disable_function_remotewakeup(struct usb_device *udev)
2880 * Linux (2.6) currently has NO mechanisms to initiate that: no khubd 2886 * Linux (2.6) currently has NO mechanisms to initiate that: no khubd
2881 * timer, no SRP, no requests through sysfs. 2887 * timer, no SRP, no requests through sysfs.
2882 * 2888 *
2883 * If CONFIG_USB_SUSPEND isn't enabled, devices only really suspend when 2889 * If Runtime PM isn't enabled or used, non-SuperSpeed devices really get
2884 * the root hub for their bus goes into global suspend ... so we don't 2890 * suspended only when their bus goes into global suspend (i.e., the root
2885 * (falsely) update the device power state to say it suspended. 2891 * hub is suspended). Nevertheless, we change @udev->state to
2892 * USB_STATE_SUSPENDED as this is the device's "logical" state. The actual
2893 * upstream port setting is stored in @udev->port_is_suspended.
2886 * 2894 *
2887 * Returns 0 on success, else negative errno. 2895 * Returns 0 on success, else negative errno.
2888 */ 2896 */
@@ -2893,6 +2901,7 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg)
2893 enum pm_qos_flags_status pm_qos_stat; 2901 enum pm_qos_flags_status pm_qos_stat;
2894 int port1 = udev->portnum; 2902 int port1 = udev->portnum;
2895 int status; 2903 int status;
2904 bool really_suspend = true;
2896 2905
2897 /* enable remote wakeup when appropriate; this lets the device 2906 /* enable remote wakeup when appropriate; this lets the device
2898 * wake up the upstream hub (including maybe the root hub). 2907 * wake up the upstream hub (including maybe the root hub).
@@ -2949,9 +2958,19 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg)
2949 /* see 7.1.7.6 */ 2958 /* see 7.1.7.6 */
2950 if (hub_is_superspeed(hub->hdev)) 2959 if (hub_is_superspeed(hub->hdev))
2951 status = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_U3); 2960 status = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_U3);
2952 else 2961 else if (PMSG_IS_AUTO(msg))
2953 status = set_port_feature(hub->hdev, port1, 2962 status = set_port_feature(hub->hdev, port1,
2954 USB_PORT_FEAT_SUSPEND); 2963 USB_PORT_FEAT_SUSPEND);
2964 /*
2965 * For system suspend, we do not need to enable the suspend feature
2966 * on individual USB-2 ports. The devices will automatically go
2967 * into suspend a few ms after the root hub stops sending packets.
2968 * The USB 2.0 spec calls this "global suspend".
2969 */
2970 else {
2971 really_suspend = false;
2972 status = 0;
2973 }
2955 if (status) { 2974 if (status) {
2956 dev_dbg(hub->intfdev, "can't suspend port %d, status %d\n", 2975 dev_dbg(hub->intfdev, "can't suspend port %d, status %d\n",
2957 port1, status); 2976 port1, status);
@@ -2987,8 +3006,10 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg)
2987 (PMSG_IS_AUTO(msg) ? "auto-" : ""), 3006 (PMSG_IS_AUTO(msg) ? "auto-" : ""),
2988 udev->do_remote_wakeup); 3007 udev->do_remote_wakeup);
2989 usb_set_device_state(udev, USB_STATE_SUSPENDED); 3008 usb_set_device_state(udev, USB_STATE_SUSPENDED);
2990 udev->port_is_suspended = 1; 3009 if (really_suspend) {
2991 msleep(10); 3010 udev->port_is_suspended = 1;
3011 msleep(10);
3012 }
2992 } 3013 }
2993 3014
2994 /* 3015 /*
@@ -3226,6 +3247,10 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg)
3226 return status; 3247 return status;
3227} 3248}
3228 3249
3250#endif /* CONFIG_PM */
3251
3252#ifdef CONFIG_PM_RUNTIME
3253
3229/* caller has locked udev */ 3254/* caller has locked udev */
3230int usb_remote_wakeup(struct usb_device *udev) 3255int usb_remote_wakeup(struct usb_device *udev)
3231{ 3256{
@@ -3242,38 +3267,6 @@ int usb_remote_wakeup(struct usb_device *udev)
3242 return status; 3267 return status;
3243} 3268}
3244 3269
3245#else /* CONFIG_USB_SUSPEND */
3246
3247/* When CONFIG_USB_SUSPEND isn't set, we never suspend or resume any ports. */
3248
3249int usb_port_suspend(struct usb_device *udev, pm_message_t msg)
3250{
3251 return 0;
3252}
3253
3254/* However we may need to do a reset-resume */
3255
3256int usb_port_resume(struct usb_device *udev, pm_message_t msg)
3257{
3258 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent);
3259 int port1 = udev->portnum;
3260 int status;
3261 u16 portchange, portstatus;
3262
3263 status = hub_port_status(hub, port1, &portstatus, &portchange);
3264 status = check_port_resume_type(udev,
3265 hub, port1, status, portchange, portstatus);
3266
3267 if (status) {
3268 dev_dbg(&udev->dev, "can't resume, status %d\n", status);
3269 hub_port_logical_disconnect(hub, port1);
3270 } else if (udev->reset_resume) {
3271 dev_dbg(&udev->dev, "reset-resume\n");
3272 status = usb_reset_and_verify_device(udev);
3273 }
3274 return status;
3275}
3276
3277#endif 3270#endif
3278 3271
3279static int check_ports_changed(struct usb_hub *hub) 3272static int check_ports_changed(struct usb_hub *hub)
@@ -4090,9 +4083,9 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
4090 goto fail; 4083 goto fail;
4091 } 4084 }
4092 if (r) { 4085 if (r) {
4093 dev_err(&udev->dev, 4086 if (r != -ENODEV)
4094 "device descriptor read/64, error %d\n", 4087 dev_err(&udev->dev, "device descriptor read/64, error %d\n",
4095 r); 4088 r);
4096 retval = -EMSGSIZE; 4089 retval = -EMSGSIZE;
4097 continue; 4090 continue;
4098 } 4091 }
@@ -4112,9 +4105,9 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
4112 msleep(200); 4105 msleep(200);
4113 } 4106 }
4114 if (retval < 0) { 4107 if (retval < 0) {
4115 dev_err(&udev->dev, 4108 if (retval != -ENODEV)
4116 "device not accepting address %d, error %d\n", 4109 dev_err(&udev->dev, "device not accepting address %d, error %d\n",
4117 devnum, retval); 4110 devnum, retval);
4118 goto fail; 4111 goto fail;
4119 } 4112 }
4120 if (udev->speed == USB_SPEED_SUPER) { 4113 if (udev->speed == USB_SPEED_SUPER) {
@@ -4136,7 +4129,8 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
4136 4129
4137 retval = usb_get_device_descriptor(udev, 8); 4130 retval = usb_get_device_descriptor(udev, 8);
4138 if (retval < 8) { 4131 if (retval < 8) {
4139 dev_err(&udev->dev, 4132 if (retval != -ENODEV)
4133 dev_err(&udev->dev,
4140 "device descriptor read/8, error %d\n", 4134 "device descriptor read/8, error %d\n",
4141 retval); 4135 retval);
4142 if (retval >= 0) 4136 if (retval >= 0)
@@ -4190,8 +4184,9 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
4190 4184
4191 retval = usb_get_device_descriptor(udev, USB_DT_DEVICE_SIZE); 4185 retval = usb_get_device_descriptor(udev, USB_DT_DEVICE_SIZE);
4192 if (retval < (signed)sizeof(udev->descriptor)) { 4186 if (retval < (signed)sizeof(udev->descriptor)) {
4193 dev_err(&udev->dev, "device descriptor read/all, error %d\n", 4187 if (retval != -ENODEV)
4194 retval); 4188 dev_err(&udev->dev, "device descriptor read/all, error %d\n",
4189 retval);
4195 if (retval >= 0) 4190 if (retval >= 0)
4196 retval = -ENOMSG; 4191 retval = -ENOMSG;
4197 goto fail; 4192 goto fail;
@@ -4333,7 +4328,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
4333 if (portstatus & USB_PORT_STAT_ENABLE) { 4328 if (portstatus & USB_PORT_STAT_ENABLE) {
4334 status = 0; /* Nothing to do */ 4329 status = 0; /* Nothing to do */
4335 4330
4336#ifdef CONFIG_USB_SUSPEND 4331#ifdef CONFIG_PM_RUNTIME
4337 } else if (udev->state == USB_STATE_SUSPENDED && 4332 } else if (udev->state == USB_STATE_SUSPENDED &&
4338 udev->persist_enabled) { 4333 udev->persist_enabled) {
4339 /* For a suspended device, treat this as a 4334 /* For a suspended device, treat this as a
@@ -4373,7 +4368,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
4373 USB_PORT_STAT_C_ENABLE)) { 4368 USB_PORT_STAT_C_ENABLE)) {
4374 status = hub_port_debounce_be_stable(hub, port1); 4369 status = hub_port_debounce_be_stable(hub, port1);
4375 if (status < 0) { 4370 if (status < 0) {
4376 if (printk_ratelimit()) 4371 if (status != -ENODEV && printk_ratelimit())
4377 dev_err(hub_dev, "connect-debounce failed, " 4372 dev_err(hub_dev, "connect-debounce failed, "
4378 "port %d disabled\n", port1); 4373 "port %d disabled\n", port1);
4379 portstatus &= ~USB_PORT_STAT_CONNECTION; 4374 portstatus &= ~USB_PORT_STAT_CONNECTION;
@@ -4402,6 +4397,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
4402 else 4397 else
4403 unit_load = 100; 4398 unit_load = 100;
4404 4399
4400 status = 0;
4405 for (i = 0; i < SET_CONFIG_TRIES; i++) { 4401 for (i = 0; i < SET_CONFIG_TRIES; i++) {
4406 4402
4407 /* reallocate for each attempt, since references 4403 /* reallocate for each attempt, since references
@@ -4526,9 +4522,11 @@ loop:
4526 } 4522 }
4527 if (hub->hdev->parent || 4523 if (hub->hdev->parent ||
4528 !hcd->driver->port_handed_over || 4524 !hcd->driver->port_handed_over ||
4529 !(hcd->driver->port_handed_over)(hcd, port1)) 4525 !(hcd->driver->port_handed_over)(hcd, port1)) {
4530 dev_err(hub_dev, "unable to enumerate USB device on port %d\n", 4526 if (status != -ENOTCONN && status != -ENODEV)
4531 port1); 4527 dev_err(hub_dev, "unable to enumerate USB device on port %d\n",
4528 port1);
4529 }
4532 4530
4533done: 4531done:
4534 hub_port_disable(hub, port1, 1); 4532 hub_port_disable(hub, port1, 1);
diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c
index 65d4e55552c6..b8bad294eeb8 100644
--- a/drivers/usb/core/port.c
+++ b/drivers/usb/core/port.c
@@ -70,7 +70,7 @@ static void usb_port_device_release(struct device *dev)
70 kfree(port_dev); 70 kfree(port_dev);
71} 71}
72 72
73#ifdef CONFIG_USB_SUSPEND 73#ifdef CONFIG_PM_RUNTIME
74static int usb_port_runtime_resume(struct device *dev) 74static int usb_port_runtime_resume(struct device *dev)
75{ 75{
76 struct usb_port *port_dev = to_usb_port(dev); 76 struct usb_port *port_dev = to_usb_port(dev);
@@ -138,7 +138,7 @@ static int usb_port_runtime_suspend(struct device *dev)
138#endif 138#endif
139 139
140static const struct dev_pm_ops usb_port_pm_ops = { 140static const struct dev_pm_ops usb_port_pm_ops = {
141#ifdef CONFIG_USB_SUSPEND 141#ifdef CONFIG_PM_RUNTIME
142 .runtime_suspend = usb_port_runtime_suspend, 142 .runtime_suspend = usb_port_runtime_suspend,
143 .runtime_resume = usb_port_runtime_resume, 143 .runtime_resume = usb_port_runtime_resume,
144 .runtime_idle = pm_generic_runtime_idle, 144 .runtime_idle = pm_generic_runtime_idle,
diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c
index 3113c1d71442..ab5638d9c707 100644
--- a/drivers/usb/core/quirks.c
+++ b/drivers/usb/core/quirks.c
@@ -201,20 +201,14 @@ void usb_detect_quirks(struct usb_device *udev)
201 dev_dbg(&udev->dev, "USB quirks for this device: %x\n", 201 dev_dbg(&udev->dev, "USB quirks for this device: %x\n",
202 udev->quirks); 202 udev->quirks);
203 203
204 /* For the present, all devices default to USB-PERSIST enabled */ 204#ifdef CONFIG_USB_DEFAULT_PERSIST
205#if 0 /* was: #ifdef CONFIG_PM */ 205 if (!(udev->quirks & USB_QUIRK_RESET))
206 /* Hubs are automatically enabled for USB-PERSIST */
207 if (udev->descriptor.bDeviceClass == USB_CLASS_HUB)
208 udev->persist_enabled = 1; 206 udev->persist_enabled = 1;
209
210#else 207#else
211 /* In the absence of PM, we can safely enable USB-PERSIST 208 /* Hubs are automatically enabled for USB-PERSIST */
212 * for all devices. It will affect things like hub resets 209 if (udev->descriptor.bDeviceClass == USB_CLASS_HUB)
213 * and EMF-related port disables.
214 */
215 if (!(udev->quirks & USB_QUIRK_RESET))
216 udev->persist_enabled = 1; 210 udev->persist_enabled = 1;
217#endif /* CONFIG_PM */ 211#endif /* CONFIG_USB_DEFAULT_PERSIST */
218} 212}
219 213
220void usb_detect_interface_quirks(struct usb_device *udev) 214void usb_detect_interface_quirks(struct usb_device *udev)
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index 3f81a3dc6867..aa38db44818a 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -338,7 +338,7 @@ static void remove_persist_attributes(struct device *dev)
338 338
339#endif /* CONFIG_PM */ 339#endif /* CONFIG_PM */
340 340
341#ifdef CONFIG_USB_SUSPEND 341#ifdef CONFIG_PM_RUNTIME
342 342
343static ssize_t 343static ssize_t
344show_connected_duration(struct device *dev, struct device_attribute *attr, 344show_connected_duration(struct device *dev, struct device_attribute *attr,
@@ -544,7 +544,7 @@ static void remove_power_attributes(struct device *dev)
544#define add_power_attributes(dev) 0 544#define add_power_attributes(dev) 0
545#define remove_power_attributes(dev) do {} while (0) 545#define remove_power_attributes(dev) do {} while (0)
546 546
547#endif /* CONFIG_USB_SUSPEND */ 547#endif /* CONFIG_PM_RUNTIME */
548 548
549 549
550/* Descriptor fields */ 550/* Descriptor fields */
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c
index e0d9d948218c..16927fa88fbd 100644
--- a/drivers/usb/core/urb.c
+++ b/drivers/usb/core/urb.c
@@ -683,10 +683,13 @@ EXPORT_SYMBOL_GPL(usb_kill_urb);
683void usb_poison_urb(struct urb *urb) 683void usb_poison_urb(struct urb *urb)
684{ 684{
685 might_sleep(); 685 might_sleep();
686 if (!(urb && urb->dev && urb->ep)) 686 if (!urb)
687 return; 687 return;
688 atomic_inc(&urb->reject); 688 atomic_inc(&urb->reject);
689 689
690 if (!urb->dev || !urb->ep)
691 return;
692
690 usb_hcd_unlink_urb(urb, -ENOENT); 693 usb_hcd_unlink_urb(urb, -ENOENT);
691 wait_event(usb_kill_urb_queue, atomic_read(&urb->use_count) == 0); 694 wait_event(usb_kill_urb_queue, atomic_read(&urb->use_count) == 0);
692} 695}
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index f81b92572735..03eb7ae8fc1a 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -49,7 +49,7 @@ const char *usbcore_name = "usbcore";
49 49
50static bool nousb; /* Disable USB when built into kernel image */ 50static bool nousb; /* Disable USB when built into kernel image */
51 51
52#ifdef CONFIG_USB_SUSPEND 52#ifdef CONFIG_PM_RUNTIME
53static int usb_autosuspend_delay = 2; /* Default delay value, 53static int usb_autosuspend_delay = 2; /* Default delay value,
54 * in seconds */ 54 * in seconds */
55module_param_named(autosuspend, usb_autosuspend_delay, int, 0644); 55module_param_named(autosuspend, usb_autosuspend_delay, int, 0644);
@@ -307,7 +307,7 @@ static const struct dev_pm_ops usb_device_pm_ops = {
307 .thaw = usb_dev_thaw, 307 .thaw = usb_dev_thaw,
308 .poweroff = usb_dev_poweroff, 308 .poweroff = usb_dev_poweroff,
309 .restore = usb_dev_restore, 309 .restore = usb_dev_restore,
310#ifdef CONFIG_USB_SUSPEND 310#ifdef CONFIG_PM_RUNTIME
311 .runtime_suspend = usb_runtime_suspend, 311 .runtime_suspend = usb_runtime_suspend,
312 .runtime_resume = usb_runtime_resume, 312 .runtime_resume = usb_runtime_resume,
313 .runtime_idle = usb_runtime_idle, 313 .runtime_idle = usb_runtime_idle,
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h
index a7f20bde0e5e..823857767a16 100644
--- a/drivers/usb/core/usb.h
+++ b/drivers/usb/core/usb.h
@@ -93,7 +93,7 @@ static inline int usb_port_resume(struct usb_device *udev, pm_message_t msg)
93 93
94#endif 94#endif
95 95
96#ifdef CONFIG_USB_SUSPEND 96#ifdef CONFIG_PM_RUNTIME
97 97
98extern void usb_autosuspend_device(struct usb_device *udev); 98extern void usb_autosuspend_device(struct usb_device *udev);
99extern int usb_autoresume_device(struct usb_device *udev); 99extern int usb_autoresume_device(struct usb_device *udev);
diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig
index 68e9a2c5a01a..ea5ee9c21c35 100644
--- a/drivers/usb/dwc3/Kconfig
+++ b/drivers/usb/dwc3/Kconfig
@@ -1,7 +1,6 @@
1config USB_DWC3 1config USB_DWC3
2 tristate "DesignWare USB3 DRD Core Support" 2 tristate "DesignWare USB3 DRD Core Support"
3 depends on (USB || USB_GADGET) && GENERIC_HARDIRQS 3 depends on (USB || USB_GADGET) && GENERIC_HARDIRQS
4 select USB_OTG_UTILS
5 select USB_XHCI_PLATFORM if USB_SUPPORT && USB_XHCI_HCD 4 select USB_XHCI_PLATFORM if USB_SUPPORT && USB_XHCI_HCD
6 help 5 help
7 Say Y or M here if your system has a Dual Role SuperSpeed 6 Say Y or M here if your system has a Dual Role SuperSpeed
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index ffa6b004a84b..c35d49d39b76 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -140,7 +140,8 @@ static void dwc3_free_one_event_buffer(struct dwc3 *dwc,
140 * Returns a pointer to the allocated event buffer structure on success 140 * Returns a pointer to the allocated event buffer structure on success
141 * otherwise ERR_PTR(errno). 141 * otherwise ERR_PTR(errno).
142 */ 142 */
143static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc, unsigned length) 143static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc,
144 unsigned length)
144{ 145{
145 struct dwc3_event_buffer *evt; 146 struct dwc3_event_buffer *evt;
146 147
@@ -259,6 +260,17 @@ static void dwc3_event_buffers_cleanup(struct dwc3 *dwc)
259 } 260 }
260} 261}
261 262
263static void dwc3_core_num_eps(struct dwc3 *dwc)
264{
265 struct dwc3_hwparams *parms = &dwc->hwparams;
266
267 dwc->num_in_eps = DWC3_NUM_IN_EPS(parms);
268 dwc->num_out_eps = DWC3_NUM_EPS(parms) - dwc->num_in_eps;
269
270 dev_vdbg(dwc->dev, "found %d IN and %d OUT endpoints\n",
271 dwc->num_in_eps, dwc->num_out_eps);
272}
273
262static void dwc3_cache_hwparams(struct dwc3 *dwc) 274static void dwc3_cache_hwparams(struct dwc3 *dwc)
263{ 275{
264 struct dwc3_hwparams *parms = &dwc->hwparams; 276 struct dwc3_hwparams *parms = &dwc->hwparams;
@@ -335,13 +347,9 @@ static int dwc3_core_init(struct dwc3 *dwc)
335 if (dwc->revision < DWC3_REVISION_190A) 347 if (dwc->revision < DWC3_REVISION_190A)
336 reg |= DWC3_GCTL_U2RSTECN; 348 reg |= DWC3_GCTL_U2RSTECN;
337 349
338 dwc3_writel(dwc->regs, DWC3_GCTL, reg); 350 dwc3_core_num_eps(dwc);
339 351
340 ret = dwc3_event_buffers_setup(dwc); 352 dwc3_writel(dwc->regs, DWC3_GCTL, reg);
341 if (ret) {
342 dev_err(dwc->dev, "failed to setup event buffers\n");
343 goto err0;
344 }
345 353
346 return 0; 354 return 0;
347 355
@@ -351,8 +359,6 @@ err0:
351 359
352static void dwc3_core_exit(struct dwc3 *dwc) 360static void dwc3_core_exit(struct dwc3 *dwc)
353{ 361{
354 dwc3_event_buffers_cleanup(dwc);
355
356 usb_phy_shutdown(dwc->usb2_phy); 362 usb_phy_shutdown(dwc->usb2_phy);
357 usb_phy_shutdown(dwc->usb3_phy); 363 usb_phy_shutdown(dwc->usb3_phy);
358} 364}
@@ -428,12 +434,32 @@ static int dwc3_probe(struct platform_device *pdev)
428 dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3); 434 dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3);
429 } 435 }
430 436
431 if (IS_ERR_OR_NULL(dwc->usb2_phy)) { 437 if (IS_ERR(dwc->usb2_phy)) {
438 ret = PTR_ERR(dwc->usb2_phy);
439
440 /*
441 * if -ENXIO is returned, it means PHY layer wasn't
442 * enabled, so it makes no sense to return -EPROBE_DEFER
443 * in that case, since no PHY driver will ever probe.
444 */
445 if (ret == -ENXIO)
446 return ret;
447
432 dev_err(dev, "no usb2 phy configured\n"); 448 dev_err(dev, "no usb2 phy configured\n");
433 return -EPROBE_DEFER; 449 return -EPROBE_DEFER;
434 } 450 }
435 451
436 if (IS_ERR_OR_NULL(dwc->usb3_phy)) { 452 if (IS_ERR(dwc->usb3_phy)) {
453 ret = PTR_ERR(dwc->usb2_phy);
454
455 /*
456 * if -ENXIO is returned, it means PHY layer wasn't
457 * enabled, so it makes no sense to return -EPROBE_DEFER
458 * in that case, since no PHY driver will ever probe.
459 */
460 if (ret == -ENXIO)
461 return ret;
462
437 dev_err(dev, "no usb3 phy configured\n"); 463 dev_err(dev, "no usb3 phy configured\n");
438 return -EPROBE_DEFER; 464 return -EPROBE_DEFER;
439 } 465 }
@@ -448,6 +474,10 @@ static int dwc3_probe(struct platform_device *pdev)
448 dwc->regs_size = resource_size(res); 474 dwc->regs_size = resource_size(res);
449 dwc->dev = dev; 475 dwc->dev = dev;
450 476
477 dev->dma_mask = dev->parent->dma_mask;
478 dev->dma_parms = dev->parent->dma_parms;
479 dma_set_coherent_mask(dev, dev->parent->coherent_dma_mask);
480
451 if (!strncmp("super", maximum_speed, 5)) 481 if (!strncmp("super", maximum_speed, 5))
452 dwc->maximum_speed = DWC3_DCFG_SUPERSPEED; 482 dwc->maximum_speed = DWC3_DCFG_SUPERSPEED;
453 else if (!strncmp("high", maximum_speed, 4)) 483 else if (!strncmp("high", maximum_speed, 4))
@@ -480,7 +510,18 @@ static int dwc3_probe(struct platform_device *pdev)
480 goto err0; 510 goto err0;
481 } 511 }
482 512
483 mode = DWC3_MODE(dwc->hwparams.hwparams0); 513 ret = dwc3_event_buffers_setup(dwc);
514 if (ret) {
515 dev_err(dwc->dev, "failed to setup event buffers\n");
516 goto err1;
517 }
518
519 if (IS_ENABLED(CONFIG_USB_DWC3_HOST))
520 mode = DWC3_MODE_HOST;
521 else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET))
522 mode = DWC3_MODE_DEVICE;
523 else
524 mode = DWC3_MODE_DRD;
484 525
485 switch (mode) { 526 switch (mode) {
486 case DWC3_MODE_DEVICE: 527 case DWC3_MODE_DEVICE:
@@ -488,7 +529,7 @@ static int dwc3_probe(struct platform_device *pdev)
488 ret = dwc3_gadget_init(dwc); 529 ret = dwc3_gadget_init(dwc);
489 if (ret) { 530 if (ret) {
490 dev_err(dev, "failed to initialize gadget\n"); 531 dev_err(dev, "failed to initialize gadget\n");
491 goto err1; 532 goto err2;
492 } 533 }
493 break; 534 break;
494 case DWC3_MODE_HOST: 535 case DWC3_MODE_HOST:
@@ -496,7 +537,7 @@ static int dwc3_probe(struct platform_device *pdev)
496 ret = dwc3_host_init(dwc); 537 ret = dwc3_host_init(dwc);
497 if (ret) { 538 if (ret) {
498 dev_err(dev, "failed to initialize host\n"); 539 dev_err(dev, "failed to initialize host\n");
499 goto err1; 540 goto err2;
500 } 541 }
501 break; 542 break;
502 case DWC3_MODE_DRD: 543 case DWC3_MODE_DRD:
@@ -504,32 +545,32 @@ static int dwc3_probe(struct platform_device *pdev)
504 ret = dwc3_host_init(dwc); 545 ret = dwc3_host_init(dwc);
505 if (ret) { 546 if (ret) {
506 dev_err(dev, "failed to initialize host\n"); 547 dev_err(dev, "failed to initialize host\n");
507 goto err1; 548 goto err2;
508 } 549 }
509 550
510 ret = dwc3_gadget_init(dwc); 551 ret = dwc3_gadget_init(dwc);
511 if (ret) { 552 if (ret) {
512 dev_err(dev, "failed to initialize gadget\n"); 553 dev_err(dev, "failed to initialize gadget\n");
513 goto err1; 554 goto err2;
514 } 555 }
515 break; 556 break;
516 default: 557 default:
517 dev_err(dev, "Unsupported mode of operation %d\n", mode); 558 dev_err(dev, "Unsupported mode of operation %d\n", mode);
518 goto err1; 559 goto err2;
519 } 560 }
520 dwc->mode = mode; 561 dwc->mode = mode;
521 562
522 ret = dwc3_debugfs_init(dwc); 563 ret = dwc3_debugfs_init(dwc);
523 if (ret) { 564 if (ret) {
524 dev_err(dev, "failed to initialize debugfs\n"); 565 dev_err(dev, "failed to initialize debugfs\n");
525 goto err2; 566 goto err3;
526 } 567 }
527 568
528 pm_runtime_allow(dev); 569 pm_runtime_allow(dev);
529 570
530 return 0; 571 return 0;
531 572
532err2: 573err3:
533 switch (mode) { 574 switch (mode) {
534 case DWC3_MODE_DEVICE: 575 case DWC3_MODE_DEVICE:
535 dwc3_gadget_exit(dwc); 576 dwc3_gadget_exit(dwc);
@@ -546,6 +587,9 @@ err2:
546 break; 587 break;
547 } 588 }
548 589
590err2:
591 dwc3_event_buffers_cleanup(dwc);
592
549err1: 593err1:
550 dwc3_core_exit(dwc); 594 dwc3_core_exit(dwc);
551 595
@@ -583,12 +627,130 @@ static int dwc3_remove(struct platform_device *pdev)
583 break; 627 break;
584 } 628 }
585 629
630 dwc3_event_buffers_cleanup(dwc);
586 dwc3_free_event_buffers(dwc); 631 dwc3_free_event_buffers(dwc);
587 dwc3_core_exit(dwc); 632 dwc3_core_exit(dwc);
588 633
589 return 0; 634 return 0;
590} 635}
591 636
637#ifdef CONFIG_PM_SLEEP
638static int dwc3_prepare(struct device *dev)
639{
640 struct dwc3 *dwc = dev_get_drvdata(dev);
641 unsigned long flags;
642
643 spin_lock_irqsave(&dwc->lock, flags);
644
645 switch (dwc->mode) {
646 case DWC3_MODE_DEVICE:
647 case DWC3_MODE_DRD:
648 dwc3_gadget_prepare(dwc);
649 /* FALLTHROUGH */
650 case DWC3_MODE_HOST:
651 default:
652 dwc3_event_buffers_cleanup(dwc);
653 break;
654 }
655
656 spin_unlock_irqrestore(&dwc->lock, flags);
657
658 return 0;
659}
660
661static void dwc3_complete(struct device *dev)
662{
663 struct dwc3 *dwc = dev_get_drvdata(dev);
664 unsigned long flags;
665
666 spin_lock_irqsave(&dwc->lock, flags);
667
668 switch (dwc->mode) {
669 case DWC3_MODE_DEVICE:
670 case DWC3_MODE_DRD:
671 dwc3_gadget_complete(dwc);
672 /* FALLTHROUGH */
673 case DWC3_MODE_HOST:
674 default:
675 dwc3_event_buffers_setup(dwc);
676 break;
677 }
678
679 spin_unlock_irqrestore(&dwc->lock, flags);
680}
681
682static int dwc3_suspend(struct device *dev)
683{
684 struct dwc3 *dwc = dev_get_drvdata(dev);
685 unsigned long flags;
686
687 spin_lock_irqsave(&dwc->lock, flags);
688
689 switch (dwc->mode) {
690 case DWC3_MODE_DEVICE:
691 case DWC3_MODE_DRD:
692 dwc3_gadget_suspend(dwc);
693 /* FALLTHROUGH */
694 case DWC3_MODE_HOST:
695 default:
696 /* do nothing */
697 break;
698 }
699
700 dwc->gctl = dwc3_readl(dwc->regs, DWC3_GCTL);
701 spin_unlock_irqrestore(&dwc->lock, flags);
702
703 usb_phy_shutdown(dwc->usb3_phy);
704 usb_phy_shutdown(dwc->usb2_phy);
705
706 return 0;
707}
708
709static int dwc3_resume(struct device *dev)
710{
711 struct dwc3 *dwc = dev_get_drvdata(dev);
712 unsigned long flags;
713
714 usb_phy_init(dwc->usb3_phy);
715 usb_phy_init(dwc->usb2_phy);
716 msleep(100);
717
718 spin_lock_irqsave(&dwc->lock, flags);
719
720 dwc3_writel(dwc->regs, DWC3_GCTL, dwc->gctl);
721
722 switch (dwc->mode) {
723 case DWC3_MODE_DEVICE:
724 case DWC3_MODE_DRD:
725 dwc3_gadget_resume(dwc);
726 /* FALLTHROUGH */
727 case DWC3_MODE_HOST:
728 default:
729 /* do nothing */
730 break;
731 }
732
733 spin_unlock_irqrestore(&dwc->lock, flags);
734
735 pm_runtime_disable(dev);
736 pm_runtime_set_active(dev);
737 pm_runtime_enable(dev);
738
739 return 0;
740}
741
742static const struct dev_pm_ops dwc3_dev_pm_ops = {
743 .prepare = dwc3_prepare,
744 .complete = dwc3_complete,
745
746 SET_SYSTEM_SLEEP_PM_OPS(dwc3_suspend, dwc3_resume)
747};
748
749#define DWC3_PM_OPS &(dwc3_dev_pm_ops)
750#else
751#define DWC3_PM_OPS NULL
752#endif
753
592#ifdef CONFIG_OF 754#ifdef CONFIG_OF
593static const struct of_device_id of_dwc3_match[] = { 755static const struct of_device_id of_dwc3_match[] = {
594 { 756 {
@@ -605,6 +767,7 @@ static struct platform_driver dwc3_driver = {
605 .driver = { 767 .driver = {
606 .name = "dwc3", 768 .name = "dwc3",
607 .of_match_table = of_match_ptr(of_dwc3_match), 769 .of_match_table = of_match_ptr(of_dwc3_match),
770 .pm = DWC3_PM_OPS,
608 }, 771 },
609}; 772};
610 773
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index b41750660235..b69d322e3cab 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -154,8 +154,9 @@
154/* OTG Registers */ 154/* OTG Registers */
155#define DWC3_OCFG 0xcc00 155#define DWC3_OCFG 0xcc00
156#define DWC3_OCTL 0xcc04 156#define DWC3_OCTL 0xcc04
157#define DWC3_OEVTEN 0xcc08 157#define DWC3_OEVT 0xcc08
158#define DWC3_OSTS 0xcc0C 158#define DWC3_OEVTEN 0xcc0C
159#define DWC3_OSTS 0xcc10
159 160
160/* Bit fields */ 161/* Bit fields */
161 162
@@ -369,6 +370,9 @@ struct dwc3_trb;
369 * @list: a list of event buffers 370 * @list: a list of event buffers
370 * @buf: _THE_ buffer 371 * @buf: _THE_ buffer
371 * @length: size of this buffer 372 * @length: size of this buffer
373 * @lpos: event offset
374 * @count: cache of last read event count register
375 * @flags: flags related to this event buffer
372 * @dma: dma_addr_t 376 * @dma: dma_addr_t
373 * @dwc: pointer to DWC controller 377 * @dwc: pointer to DWC controller
374 */ 378 */
@@ -376,6 +380,10 @@ struct dwc3_event_buffer {
376 void *buf; 380 void *buf;
377 unsigned length; 381 unsigned length;
378 unsigned int lpos; 382 unsigned int lpos;
383 unsigned int count;
384 unsigned int flags;
385
386#define DWC3_EVENT_PENDING BIT(0)
379 387
380 dma_addr_t dma; 388 dma_addr_t dma;
381 389
@@ -487,12 +495,6 @@ enum dwc3_link_state {
487 DWC3_LINK_STATE_MASK = 0x0f, 495 DWC3_LINK_STATE_MASK = 0x0f,
488}; 496};
489 497
490enum dwc3_device_state {
491 DWC3_DEFAULT_STATE,
492 DWC3_ADDRESS_STATE,
493 DWC3_CONFIGURED_STATE,
494};
495
496/* TRB Length, PCM and Status */ 498/* TRB Length, PCM and Status */
497#define DWC3_TRB_SIZE_MASK (0x00ffffff) 499#define DWC3_TRB_SIZE_MASK (0x00ffffff)
498#define DWC3_TRB_SIZE_LENGTH(n) ((n) & DWC3_TRB_SIZE_MASK) 500#define DWC3_TRB_SIZE_LENGTH(n) ((n) & DWC3_TRB_SIZE_MASK)
@@ -574,6 +576,14 @@ struct dwc3_hwparams {
574/* HWPARAMS1 */ 576/* HWPARAMS1 */
575#define DWC3_NUM_INT(n) (((n) & (0x3f << 15)) >> 15) 577#define DWC3_NUM_INT(n) (((n) & (0x3f << 15)) >> 15)
576 578
579/* HWPARAMS3 */
580#define DWC3_NUM_IN_EPS_MASK (0x1f << 18)
581#define DWC3_NUM_EPS_MASK (0x3f << 12)
582#define DWC3_NUM_EPS(p) (((p)->hwparams3 & \
583 (DWC3_NUM_EPS_MASK)) >> 12)
584#define DWC3_NUM_IN_EPS(p) (((p)->hwparams3 & \
585 (DWC3_NUM_IN_EPS_MASK)) >> 18)
586
577/* HWPARAMS7 */ 587/* HWPARAMS7 */
578#define DWC3_RAM1_DEPTH(n) ((n) & 0xffff) 588#define DWC3_RAM1_DEPTH(n) ((n) & 0xffff)
579 589
@@ -618,7 +628,6 @@ struct dwc3_scratchpad_array {
618 * @gadget_driver: pointer to the gadget driver 628 * @gadget_driver: pointer to the gadget driver
619 * @regs: base address for our registers 629 * @regs: base address for our registers
620 * @regs_size: address space size 630 * @regs_size: address space size
621 * @irq: IRQ number
622 * @num_event_buffers: calculated number of event buffers 631 * @num_event_buffers: calculated number of event buffers
623 * @u1u2: only used on revisions <1.83a for workaround 632 * @u1u2: only used on revisions <1.83a for workaround
624 * @maximum_speed: maximum speed requested (mainly for testing purposes) 633 * @maximum_speed: maximum speed requested (mainly for testing purposes)
@@ -626,6 +635,8 @@ struct dwc3_scratchpad_array {
626 * @mode: mode of operation 635 * @mode: mode of operation
627 * @usb2_phy: pointer to USB2 PHY 636 * @usb2_phy: pointer to USB2 PHY
628 * @usb3_phy: pointer to USB3 PHY 637 * @usb3_phy: pointer to USB3 PHY
638 * @dcfg: saved contents of DCFG register
639 * @gctl: saved contents of GCTL register
629 * @is_selfpowered: true when we are selfpowered 640 * @is_selfpowered: true when we are selfpowered
630 * @three_stage_setup: set if we perform a three phase setup 641 * @three_stage_setup: set if we perform a three phase setup
631 * @ep0_bounced: true when we used bounce buffer 642 * @ep0_bounced: true when we used bounce buffer
@@ -639,6 +650,8 @@ struct dwc3_scratchpad_array {
639 * @u2pel: parameter from Set SEL request. 650 * @u2pel: parameter from Set SEL request.
640 * @u1sel: parameter from Set SEL request. 651 * @u1sel: parameter from Set SEL request.
641 * @u1pel: parameter from Set SEL request. 652 * @u1pel: parameter from Set SEL request.
653 * @num_out_eps: number of out endpoints
654 * @num_in_eps: number of in endpoints
642 * @ep0_next_event: hold the next expected event 655 * @ep0_next_event: hold the next expected event
643 * @ep0state: state of endpoint zero 656 * @ep0state: state of endpoint zero
644 * @link_state: link state 657 * @link_state: link state
@@ -656,8 +669,10 @@ struct dwc3 {
656 dma_addr_t ep0_trb_addr; 669 dma_addr_t ep0_trb_addr;
657 dma_addr_t ep0_bounce_addr; 670 dma_addr_t ep0_bounce_addr;
658 struct dwc3_request ep0_usb_req; 671 struct dwc3_request ep0_usb_req;
672
659 /* device lock */ 673 /* device lock */
660 spinlock_t lock; 674 spinlock_t lock;
675
661 struct device *dev; 676 struct device *dev;
662 677
663 struct platform_device *xhci; 678 struct platform_device *xhci;
@@ -675,6 +690,10 @@ struct dwc3 {
675 void __iomem *regs; 690 void __iomem *regs;
676 size_t regs_size; 691 size_t regs_size;
677 692
693 /* used for suspend/resume */
694 u32 dcfg;
695 u32 gctl;
696
678 u32 num_event_buffers; 697 u32 num_event_buffers;
679 u32 u1u2; 698 u32 u1u2;
680 u32 maximum_speed; 699 u32 maximum_speed;
@@ -694,6 +713,9 @@ struct dwc3 {
694#define DWC3_REVISION_202A 0x5533202a 713#define DWC3_REVISION_202A 0x5533202a
695#define DWC3_REVISION_210A 0x5533210a 714#define DWC3_REVISION_210A 0x5533210a
696#define DWC3_REVISION_220A 0x5533220a 715#define DWC3_REVISION_220A 0x5533220a
716#define DWC3_REVISION_230A 0x5533230a
717#define DWC3_REVISION_240A 0x5533240a
718#define DWC3_REVISION_250A 0x5533250a
697 719
698 unsigned is_selfpowered:1; 720 unsigned is_selfpowered:1;
699 unsigned three_stage_setup:1; 721 unsigned three_stage_setup:1;
@@ -704,11 +726,11 @@ struct dwc3 {
704 unsigned delayed_status:1; 726 unsigned delayed_status:1;
705 unsigned needs_fifo_resize:1; 727 unsigned needs_fifo_resize:1;
706 unsigned resize_fifos:1; 728 unsigned resize_fifos:1;
729 unsigned pullups_connected:1;
707 730
708 enum dwc3_ep0_next ep0_next_event; 731 enum dwc3_ep0_next ep0_next_event;
709 enum dwc3_ep0_state ep0state; 732 enum dwc3_ep0_state ep0state;
710 enum dwc3_link_state link_state; 733 enum dwc3_link_state link_state;
711 enum dwc3_device_state dev_state;
712 734
713 u16 isoch_delay; 735 u16 isoch_delay;
714 u16 u2sel; 736 u16 u2sel;
@@ -718,6 +740,9 @@ struct dwc3 {
718 740
719 u8 speed; 741 u8 speed;
720 742
743 u8 num_out_eps;
744 u8 num_in_eps;
745
721 void *mem; 746 void *mem;
722 747
723 struct dwc3_hwparams hwparams; 748 struct dwc3_hwparams hwparams;
@@ -884,4 +909,31 @@ static inline void dwc3_gadget_exit(struct dwc3 *dwc)
884{ } 909{ }
885#endif 910#endif
886 911
912/* power management interface */
913#if !IS_ENABLED(CONFIG_USB_DWC3_HOST)
914int dwc3_gadget_prepare(struct dwc3 *dwc);
915void dwc3_gadget_complete(struct dwc3 *dwc);
916int dwc3_gadget_suspend(struct dwc3 *dwc);
917int dwc3_gadget_resume(struct dwc3 *dwc);
918#else
919static inline int dwc3_gadget_prepare(struct dwc3 *dwc)
920{
921 return 0;
922}
923
924static inline void dwc3_gadget_complete(struct dwc3 *dwc)
925{
926}
927
928static inline int dwc3_gadget_suspend(struct dwc3 *dwc)
929{
930 return 0;
931}
932
933static inline int dwc3_gadget_resume(struct dwc3 *dwc)
934{
935 return 0;
936}
937#endif /* !IS_ENABLED(CONFIG_USB_DWC3_HOST) */
938
887#endif /* __DRIVERS_USB_DWC3_CORE_H */ 939#endif /* __DRIVERS_USB_DWC3_CORE_H */
diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c
index 4a752e730c5f..9e9f122162f2 100644
--- a/drivers/usb/dwc3/debugfs.c
+++ b/drivers/usb/dwc3/debugfs.c
@@ -59,7 +59,7 @@
59 .offset = DWC3_ ##nm - DWC3_GLOBALS_REGS_START, \ 59 .offset = DWC3_ ##nm - DWC3_GLOBALS_REGS_START, \
60} 60}
61 61
62static struct debugfs_reg32 dwc3_regs[] = { 62static const struct debugfs_reg32 dwc3_regs[] = {
63 dump_register(GSBUSCFG0), 63 dump_register(GSBUSCFG0),
64 dump_register(GSBUSCFG1), 64 dump_register(GSBUSCFG1),
65 dump_register(GTXTHRCFG), 65 dump_register(GTXTHRCFG),
@@ -372,6 +372,7 @@ static struct debugfs_reg32 dwc3_regs[] = {
372 372
373 dump_register(OCFG), 373 dump_register(OCFG),
374 dump_register(OCTL), 374 dump_register(OCTL),
375 dump_register(OEVT),
375 dump_register(OEVTEN), 376 dump_register(OEVTEN),
376 dump_register(OSTS), 377 dump_register(OSTS),
377}; 378};
@@ -577,8 +578,14 @@ static int dwc3_link_state_show(struct seq_file *s, void *unused)
577 case DWC3_LINK_STATE_LPBK: 578 case DWC3_LINK_STATE_LPBK:
578 seq_printf(s, "Loopback\n"); 579 seq_printf(s, "Loopback\n");
579 break; 580 break;
581 case DWC3_LINK_STATE_RESET:
582 seq_printf(s, "Reset\n");
583 break;
584 case DWC3_LINK_STATE_RESUME:
585 seq_printf(s, "Resume\n");
586 break;
580 default: 587 default:
581 seq_printf(s, "UNKNOWN %d\n", reg); 588 seq_printf(s, "UNKNOWN %d\n", state);
582 } 589 }
583 590
584 return 0; 591 return 0;
@@ -661,28 +668,31 @@ int dwc3_debugfs_init(struct dwc3 *dwc)
661 goto err1; 668 goto err1;
662 } 669 }
663 670
664#if IS_ENABLED(CONFIG_USB_DWC3_GADGET) 671 if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)) {
665 file = debugfs_create_file("mode", S_IRUGO | S_IWUSR, root, 672 file = debugfs_create_file("mode", S_IRUGO | S_IWUSR, root,
666 dwc, &dwc3_mode_fops); 673 dwc, &dwc3_mode_fops);
667 if (!file) { 674 if (!file) {
668 ret = -ENOMEM; 675 ret = -ENOMEM;
669 goto err1; 676 goto err1;
670 } 677 }
671
672 file = debugfs_create_file("testmode", S_IRUGO | S_IWUSR, root,
673 dwc, &dwc3_testmode_fops);
674 if (!file) {
675 ret = -ENOMEM;
676 goto err1;
677 } 678 }
678 679
679 file = debugfs_create_file("link_state", S_IRUGO | S_IWUSR, root, 680 if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE) ||
680 dwc, &dwc3_link_state_fops); 681 IS_ENABLED(CONFIG_USB_DWC3_GADGET)) {
681 if (!file) { 682 file = debugfs_create_file("testmode", S_IRUGO | S_IWUSR, root,
682 ret = -ENOMEM; 683 dwc, &dwc3_testmode_fops);
683 goto err1; 684 if (!file) {
685 ret = -ENOMEM;
686 goto err1;
687 }
688
689 file = debugfs_create_file("link_state", S_IRUGO | S_IWUSR, root,
690 dwc, &dwc3_link_state_fops);
691 if (!file) {
692 ret = -ENOMEM;
693 goto err1;
694 }
684 } 695 }
685#endif
686 696
687 return 0; 697 return 0;
688 698
diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c
index b082bec7343e..a8afe6e26621 100644
--- a/drivers/usb/dwc3/dwc3-exynos.c
+++ b/drivers/usb/dwc3/dwc3-exynos.c
@@ -22,9 +22,9 @@
22#include <linux/usb/otg.h> 22#include <linux/usb/otg.h>
23#include <linux/usb/nop-usb-xceiv.h> 23#include <linux/usb/nop-usb-xceiv.h>
24#include <linux/of.h> 24#include <linux/of.h>
25#include <linux/of_platform.h>
25 26
26struct dwc3_exynos { 27struct dwc3_exynos {
27 struct platform_device *dwc3;
28 struct platform_device *usb2_phy; 28 struct platform_device *usb2_phy;
29 struct platform_device *usb3_phy; 29 struct platform_device *usb3_phy;
30 struct device *dev; 30 struct device *dev;
@@ -86,21 +86,30 @@ err1:
86 return ret; 86 return ret;
87} 87}
88 88
89static int dwc3_exynos_remove_child(struct device *dev, void *unused)
90{
91 struct platform_device *pdev = to_platform_device(dev);
92
93 platform_device_unregister(pdev);
94
95 return 0;
96}
97
89static u64 dwc3_exynos_dma_mask = DMA_BIT_MASK(32); 98static u64 dwc3_exynos_dma_mask = DMA_BIT_MASK(32);
90 99
91static int dwc3_exynos_probe(struct platform_device *pdev) 100static int dwc3_exynos_probe(struct platform_device *pdev)
92{ 101{
93 struct platform_device *dwc3;
94 struct dwc3_exynos *exynos; 102 struct dwc3_exynos *exynos;
95 struct clk *clk; 103 struct clk *clk;
96 struct device *dev = &pdev->dev; 104 struct device *dev = &pdev->dev;
105 struct device_node *node = dev->of_node;
97 106
98 int ret = -ENOMEM; 107 int ret = -ENOMEM;
99 108
100 exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL); 109 exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL);
101 if (!exynos) { 110 if (!exynos) {
102 dev_err(dev, "not enough memory\n"); 111 dev_err(dev, "not enough memory\n");
103 return -ENOMEM; 112 goto err1;
104 } 113 }
105 114
106 /* 115 /*
@@ -108,21 +117,15 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
108 * Since shared usb code relies on it, set it here for now. 117 * Since shared usb code relies on it, set it here for now.
109 * Once we move to full device tree support this will vanish off. 118 * Once we move to full device tree support this will vanish off.
110 */ 119 */
111 if (!pdev->dev.dma_mask) 120 if (!dev->dma_mask)
112 pdev->dev.dma_mask = &dwc3_exynos_dma_mask; 121 dev->dma_mask = &dwc3_exynos_dma_mask;
113 122
114 platform_set_drvdata(pdev, exynos); 123 platform_set_drvdata(pdev, exynos);
115 124
116 ret = dwc3_exynos_register_phys(exynos); 125 ret = dwc3_exynos_register_phys(exynos);
117 if (ret) { 126 if (ret) {
118 dev_err(dev, "couldn't register PHYs\n"); 127 dev_err(dev, "couldn't register PHYs\n");
119 return ret; 128 goto err1;
120 }
121
122 dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO);
123 if (!dwc3) {
124 dev_err(dev, "couldn't allocate dwc3 device\n");
125 return -ENOMEM;
126 } 129 }
127 130
128 clk = devm_clk_get(dev, "usbdrd30"); 131 clk = devm_clk_get(dev, "usbdrd30");
@@ -132,37 +135,28 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
132 goto err1; 135 goto err1;
133 } 136 }
134 137
135 dma_set_coherent_mask(&dwc3->dev, dev->coherent_dma_mask);
136
137 dwc3->dev.parent = dev;
138 dwc3->dev.dma_mask = dev->dma_mask;
139 dwc3->dev.dma_parms = dev->dma_parms;
140 exynos->dwc3 = dwc3;
141 exynos->dev = dev; 138 exynos->dev = dev;
142 exynos->clk = clk; 139 exynos->clk = clk;
143 140
144 clk_enable(exynos->clk); 141 clk_prepare_enable(exynos->clk);
145 142
146 ret = platform_device_add_resources(dwc3, pdev->resource, 143 if (node) {
147 pdev->num_resources); 144 ret = of_platform_populate(node, NULL, NULL, dev);
148 if (ret) { 145 if (ret) {
149 dev_err(dev, "couldn't add resources to dwc3 device\n"); 146 dev_err(dev, "failed to add dwc3 core\n");
150 goto err2; 147 goto err2;
151 } 148 }
152 149 } else {
153 ret = platform_device_add(dwc3); 150 dev_err(dev, "no device node, failed to add dwc3 core\n");
154 if (ret) { 151 ret = -ENODEV;
155 dev_err(dev, "failed to register dwc3 device\n");
156 goto err2; 152 goto err2;
157 } 153 }
158 154
159 return 0; 155 return 0;
160 156
161err2: 157err2:
162 clk_disable(clk); 158 clk_disable_unprepare(clk);
163err1: 159err1:
164 platform_device_put(dwc3);
165
166 return ret; 160 return ret;
167} 161}
168 162
@@ -170,11 +164,11 @@ static int dwc3_exynos_remove(struct platform_device *pdev)
170{ 164{
171 struct dwc3_exynos *exynos = platform_get_drvdata(pdev); 165 struct dwc3_exynos *exynos = platform_get_drvdata(pdev);
172 166
173 platform_device_unregister(exynos->dwc3);
174 platform_device_unregister(exynos->usb2_phy); 167 platform_device_unregister(exynos->usb2_phy);
175 platform_device_unregister(exynos->usb3_phy); 168 platform_device_unregister(exynos->usb3_phy);
169 device_for_each_child(&pdev->dev, NULL, dwc3_exynos_remove_child);
176 170
177 clk_disable(exynos->clk); 171 clk_disable_unprepare(exynos->clk);
178 172
179 return 0; 173 return 0;
180} 174}
@@ -187,12 +181,46 @@ static const struct of_device_id exynos_dwc3_match[] = {
187MODULE_DEVICE_TABLE(of, exynos_dwc3_match); 181MODULE_DEVICE_TABLE(of, exynos_dwc3_match);
188#endif 182#endif
189 183
184#ifdef CONFIG_PM_SLEEP
185static int dwc3_exynos_suspend(struct device *dev)
186{
187 struct dwc3_exynos *exynos = dev_get_drvdata(dev);
188
189 clk_disable(exynos->clk);
190
191 return 0;
192}
193
194static int dwc3_exynos_resume(struct device *dev)
195{
196 struct dwc3_exynos *exynos = dev_get_drvdata(dev);
197
198 clk_enable(exynos->clk);
199
200 /* runtime set active to reflect active state. */
201 pm_runtime_disable(dev);
202 pm_runtime_set_active(dev);
203 pm_runtime_enable(dev);
204
205 return 0;
206}
207
208static const struct dev_pm_ops dwc3_exynos_dev_pm_ops = {
209 SET_SYSTEM_SLEEP_PM_OPS(dwc3_exynos_suspend, dwc3_exynos_resume)
210};
211
212#define DEV_PM_OPS (&dwc3_exynos_dev_pm_ops)
213#else
214#define DEV_PM_OPS NULL
215#endif /* CONFIG_PM_SLEEP */
216
190static struct platform_driver dwc3_exynos_driver = { 217static struct platform_driver dwc3_exynos_driver = {
191 .probe = dwc3_exynos_probe, 218 .probe = dwc3_exynos_probe,
192 .remove = dwc3_exynos_remove, 219 .remove = dwc3_exynos_remove,
193 .driver = { 220 .driver = {
194 .name = "exynos-dwc3", 221 .name = "exynos-dwc3",
195 .of_match_table = of_match_ptr(exynos_dwc3_match), 222 .of_match_table = of_match_ptr(exynos_dwc3_match),
223 .pm = DEV_PM_OPS,
196 }, 224 },
197}; 225};
198 226
diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c
index afa05e3c9cf4..34638b92500d 100644
--- a/drivers/usb/dwc3/dwc3-omap.c
+++ b/drivers/usb/dwc3/dwc3-omap.c
@@ -52,7 +52,6 @@
52#include <linux/of_platform.h> 52#include <linux/of_platform.h>
53 53
54#include <linux/usb/otg.h> 54#include <linux/usb/otg.h>
55#include <linux/usb/nop-usb-xceiv.h>
56 55
57/* 56/*
58 * All these registers belong to OMAP's Wrapper around the 57 * All these registers belong to OMAP's Wrapper around the
@@ -117,20 +116,17 @@ struct dwc3_omap {
117 /* device lock */ 116 /* device lock */
118 spinlock_t lock; 117 spinlock_t lock;
119 118
120 struct platform_device *usb2_phy;
121 struct platform_device *usb3_phy;
122 struct device *dev; 119 struct device *dev;
123 120
124 int irq; 121 int irq;
125 void __iomem *base; 122 void __iomem *base;
126 123
127 void *context; 124 u32 utmi_otg_status;
128 u32 resource_size;
129 125
130 u32 dma_status:1; 126 u32 dma_status:1;
131}; 127};
132 128
133struct dwc3_omap *_omap; 129static struct dwc3_omap *_omap;
134 130
135static inline u32 dwc3_omap_readl(void __iomem *base, u32 offset) 131static inline u32 dwc3_omap_readl(void __iomem *base, u32 offset)
136{ 132{
@@ -142,11 +138,14 @@ static inline void dwc3_omap_writel(void __iomem *base, u32 offset, u32 value)
142 writel(value, base + offset); 138 writel(value, base + offset);
143} 139}
144 140
145void dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status) 141int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status)
146{ 142{
147 u32 val; 143 u32 val;
148 struct dwc3_omap *omap = _omap; 144 struct dwc3_omap *omap = _omap;
149 145
146 if (!omap)
147 return -EPROBE_DEFER;
148
150 switch (status) { 149 switch (status) {
151 case OMAP_DWC3_ID_GROUND: 150 case OMAP_DWC3_ID_GROUND:
152 dev_dbg(omap->dev, "ID GND\n"); 151 dev_dbg(omap->dev, "ID GND\n");
@@ -189,63 +188,9 @@ void dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status)
189 dev_dbg(omap->dev, "ID float\n"); 188 dev_dbg(omap->dev, "ID float\n");
190 } 189 }
191 190
192 return;
193}
194EXPORT_SYMBOL_GPL(dwc3_omap_mailbox);
195
196static int dwc3_omap_register_phys(struct dwc3_omap *omap)
197{
198 struct nop_usb_xceiv_platform_data pdata;
199 struct platform_device *pdev;
200 int ret;
201
202 memset(&pdata, 0x00, sizeof(pdata));
203
204 pdev = platform_device_alloc("nop_usb_xceiv", PLATFORM_DEVID_AUTO);
205 if (!pdev)
206 return -ENOMEM;
207
208 omap->usb2_phy = pdev;
209 pdata.type = USB_PHY_TYPE_USB2;
210
211 ret = platform_device_add_data(omap->usb2_phy, &pdata, sizeof(pdata));
212 if (ret)
213 goto err1;
214
215 pdev = platform_device_alloc("nop_usb_xceiv", PLATFORM_DEVID_AUTO);
216 if (!pdev) {
217 ret = -ENOMEM;
218 goto err1;
219 }
220
221 omap->usb3_phy = pdev;
222 pdata.type = USB_PHY_TYPE_USB3;
223
224 ret = platform_device_add_data(omap->usb3_phy, &pdata, sizeof(pdata));
225 if (ret)
226 goto err2;
227
228 ret = platform_device_add(omap->usb2_phy);
229 if (ret)
230 goto err2;
231
232 ret = platform_device_add(omap->usb3_phy);
233 if (ret)
234 goto err3;
235
236 return 0; 191 return 0;
237
238err3:
239 platform_device_del(omap->usb2_phy);
240
241err2:
242 platform_device_put(omap->usb3_phy);
243
244err1:
245 platform_device_put(omap->usb2_phy);
246
247 return ret;
248} 192}
193EXPORT_SYMBOL_GPL(dwc3_omap_mailbox);
249 194
250static irqreturn_t dwc3_omap_interrupt(int irq, void *_omap) 195static irqreturn_t dwc3_omap_interrupt(int irq, void *_omap)
251{ 196{
@@ -307,24 +252,57 @@ static int dwc3_omap_remove_core(struct device *dev, void *c)
307 return 0; 252 return 0;
308} 253}
309 254
255static void dwc3_omap_enable_irqs(struct dwc3_omap *omap)
256{
257 u32 reg;
258
259 /* enable all IRQs */
260 reg = USBOTGSS_IRQO_COREIRQ_ST;
261 dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_0, reg);
262
263 reg = (USBOTGSS_IRQ1_OEVT |
264 USBOTGSS_IRQ1_DRVVBUS_RISE |
265 USBOTGSS_IRQ1_CHRGVBUS_RISE |
266 USBOTGSS_IRQ1_DISCHRGVBUS_RISE |
267 USBOTGSS_IRQ1_IDPULLUP_RISE |
268 USBOTGSS_IRQ1_DRVVBUS_FALL |
269 USBOTGSS_IRQ1_CHRGVBUS_FALL |
270 USBOTGSS_IRQ1_DISCHRGVBUS_FALL |
271 USBOTGSS_IRQ1_IDPULLUP_FALL);
272
273 dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_1, reg);
274}
275
276static void dwc3_omap_disable_irqs(struct dwc3_omap *omap)
277{
278 /* disable all IRQs */
279 dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_1, 0x00);
280 dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_0, 0x00);
281}
282
283static u64 dwc3_omap_dma_mask = DMA_BIT_MASK(32);
284
310static int dwc3_omap_probe(struct platform_device *pdev) 285static int dwc3_omap_probe(struct platform_device *pdev)
311{ 286{
312 struct dwc3_omap_data *pdata = pdev->dev.platform_data;
313 struct device_node *node = pdev->dev.of_node; 287 struct device_node *node = pdev->dev.of_node;
314 288
315 struct dwc3_omap *omap; 289 struct dwc3_omap *omap;
316 struct resource *res; 290 struct resource *res;
317 struct device *dev = &pdev->dev; 291 struct device *dev = &pdev->dev;
318 292
319 int size;
320 int ret = -ENOMEM; 293 int ret = -ENOMEM;
321 int irq; 294 int irq;
322 295
323 const u32 *utmi_mode; 296 int utmi_mode = 0;
297
324 u32 reg; 298 u32 reg;
325 299
326 void __iomem *base; 300 void __iomem *base;
327 void *context; 301
302 if (!node) {
303 dev_err(dev, "device node not found\n");
304 return -EINVAL;
305 }
328 306
329 omap = devm_kzalloc(dev, sizeof(*omap), GFP_KERNEL); 307 omap = devm_kzalloc(dev, sizeof(*omap), GFP_KERNEL);
330 if (!omap) { 308 if (!omap) {
@@ -334,13 +312,13 @@ static int dwc3_omap_probe(struct platform_device *pdev)
334 312
335 platform_set_drvdata(pdev, omap); 313 platform_set_drvdata(pdev, omap);
336 314
337 irq = platform_get_irq(pdev, 1); 315 irq = platform_get_irq(pdev, 0);
338 if (irq < 0) { 316 if (irq < 0) {
339 dev_err(dev, "missing IRQ resource\n"); 317 dev_err(dev, "missing IRQ resource\n");
340 return -EINVAL; 318 return -EINVAL;
341 } 319 }
342 320
343 res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 321 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
344 if (!res) { 322 if (!res) {
345 dev_err(dev, "missing memory base resource\n"); 323 dev_err(dev, "missing memory base resource\n");
346 return -EINVAL; 324 return -EINVAL;
@@ -352,25 +330,12 @@ static int dwc3_omap_probe(struct platform_device *pdev)
352 return -ENOMEM; 330 return -ENOMEM;
353 } 331 }
354 332
355 ret = dwc3_omap_register_phys(omap);
356 if (ret) {
357 dev_err(dev, "couldn't register PHYs\n");
358 return ret;
359 }
360
361 context = devm_kzalloc(dev, resource_size(res), GFP_KERNEL);
362 if (!context) {
363 dev_err(dev, "couldn't allocate dwc3 context memory\n");
364 return -ENOMEM;
365 }
366
367 spin_lock_init(&omap->lock); 333 spin_lock_init(&omap->lock);
368 334
369 omap->resource_size = resource_size(res);
370 omap->context = context;
371 omap->dev = dev; 335 omap->dev = dev;
372 omap->irq = irq; 336 omap->irq = irq;
373 omap->base = base; 337 omap->base = base;
338 dev->dma_mask = &dwc3_omap_dma_mask;
374 339
375 /* 340 /*
376 * REVISIT if we ever have two instances of the wrapper, we will be 341 * REVISIT if we ever have two instances of the wrapper, we will be
@@ -387,25 +352,17 @@ static int dwc3_omap_probe(struct platform_device *pdev)
387 352
388 reg = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS); 353 reg = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS);
389 354
390 utmi_mode = of_get_property(node, "utmi-mode", &size); 355 of_property_read_u32(node, "utmi-mode", &utmi_mode);
391 if (utmi_mode && size == sizeof(*utmi_mode)) { 356
392 reg |= *utmi_mode; 357 switch (utmi_mode) {
393 } else { 358 case DWC3_OMAP_UTMI_MODE_SW:
394 if (!pdata) { 359 reg |= USBOTGSS_UTMI_OTG_STATUS_SW_MODE;
395 dev_dbg(dev, "missing platform data\n"); 360 break;
396 } else { 361 case DWC3_OMAP_UTMI_MODE_HW:
397 switch (pdata->utmi_mode) { 362 reg &= ~USBOTGSS_UTMI_OTG_STATUS_SW_MODE;
398 case DWC3_OMAP_UTMI_MODE_SW: 363 break;
399 reg |= USBOTGSS_UTMI_OTG_STATUS_SW_MODE; 364 default:
400 break; 365 dev_dbg(dev, "UNKNOWN utmi mode %d\n", utmi_mode);
401 case DWC3_OMAP_UTMI_MODE_HW:
402 reg &= ~USBOTGSS_UTMI_OTG_STATUS_SW_MODE;
403 break;
404 default:
405 dev_dbg(dev, "UNKNOWN utmi mode %d\n",
406 pdata->utmi_mode);
407 }
408 }
409 } 366 }
410 367
411 dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, reg); 368 dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, reg);
@@ -422,29 +379,12 @@ static int dwc3_omap_probe(struct platform_device *pdev)
422 return ret; 379 return ret;
423 } 380 }
424 381
425 /* enable all IRQs */ 382 dwc3_omap_enable_irqs(omap);
426 reg = USBOTGSS_IRQO_COREIRQ_ST;
427 dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_0, reg);
428 383
429 reg = (USBOTGSS_IRQ1_OEVT | 384 ret = of_platform_populate(node, NULL, NULL, dev);
430 USBOTGSS_IRQ1_DRVVBUS_RISE | 385 if (ret) {
431 USBOTGSS_IRQ1_CHRGVBUS_RISE | 386 dev_err(&pdev->dev, "failed to create dwc3 core\n");
432 USBOTGSS_IRQ1_DISCHRGVBUS_RISE | 387 return ret;
433 USBOTGSS_IRQ1_IDPULLUP_RISE |
434 USBOTGSS_IRQ1_DRVVBUS_FALL |
435 USBOTGSS_IRQ1_CHRGVBUS_FALL |
436 USBOTGSS_IRQ1_DISCHRGVBUS_FALL |
437 USBOTGSS_IRQ1_IDPULLUP_FALL);
438
439 dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_1, reg);
440
441 if (node) {
442 ret = of_platform_populate(node, NULL, NULL, dev);
443 if (ret) {
444 dev_err(&pdev->dev,
445 "failed to add create dwc3 core\n");
446 return ret;
447 }
448 } 388 }
449 389
450 return 0; 390 return 0;
@@ -454,8 +394,7 @@ static int dwc3_omap_remove(struct platform_device *pdev)
454{ 394{
455 struct dwc3_omap *omap = platform_get_drvdata(pdev); 395 struct dwc3_omap *omap = platform_get_drvdata(pdev);
456 396
457 platform_device_unregister(omap->usb2_phy); 397 dwc3_omap_disable_irqs(omap);
458 platform_device_unregister(omap->usb3_phy);
459 pm_runtime_put_sync(&pdev->dev); 398 pm_runtime_put_sync(&pdev->dev);
460 pm_runtime_disable(&pdev->dev); 399 pm_runtime_disable(&pdev->dev);
461 device_for_each_child(&pdev->dev, NULL, dwc3_omap_remove_core); 400 device_for_each_child(&pdev->dev, NULL, dwc3_omap_remove_core);
@@ -465,18 +404,72 @@ static int dwc3_omap_remove(struct platform_device *pdev)
465 404
466static const struct of_device_id of_dwc3_match[] = { 405static const struct of_device_id of_dwc3_match[] = {
467 { 406 {
468 "ti,dwc3", 407 .compatible = "ti,dwc3"
469 }, 408 },
470 { }, 409 { },
471}; 410};
472MODULE_DEVICE_TABLE(of, of_dwc3_match); 411MODULE_DEVICE_TABLE(of, of_dwc3_match);
473 412
413#ifdef CONFIG_PM_SLEEP
414static int dwc3_omap_prepare(struct device *dev)
415{
416 struct dwc3_omap *omap = dev_get_drvdata(dev);
417
418 dwc3_omap_disable_irqs(omap);
419
420 return 0;
421}
422
423static void dwc3_omap_complete(struct device *dev)
424{
425 struct dwc3_omap *omap = dev_get_drvdata(dev);
426
427 dwc3_omap_enable_irqs(omap);
428}
429
430static int dwc3_omap_suspend(struct device *dev)
431{
432 struct dwc3_omap *omap = dev_get_drvdata(dev);
433
434 omap->utmi_otg_status = dwc3_omap_readl(omap->base,
435 USBOTGSS_UTMI_OTG_STATUS);
436
437 return 0;
438}
439
440static int dwc3_omap_resume(struct device *dev)
441{
442 struct dwc3_omap *omap = dev_get_drvdata(dev);
443
444 dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS,
445 omap->utmi_otg_status);
446
447 pm_runtime_disable(dev);
448 pm_runtime_set_active(dev);
449 pm_runtime_enable(dev);
450
451 return 0;
452}
453
454static const struct dev_pm_ops dwc3_omap_dev_pm_ops = {
455 .prepare = dwc3_omap_prepare,
456 .complete = dwc3_omap_complete,
457
458 SET_SYSTEM_SLEEP_PM_OPS(dwc3_omap_suspend, dwc3_omap_resume)
459};
460
461#define DEV_PM_OPS (&dwc3_omap_dev_pm_ops)
462#else
463#define DEV_PM_OPS NULL
464#endif /* CONFIG_PM_SLEEP */
465
474static struct platform_driver dwc3_omap_driver = { 466static struct platform_driver dwc3_omap_driver = {
475 .probe = dwc3_omap_probe, 467 .probe = dwc3_omap_probe,
476 .remove = dwc3_omap_remove, 468 .remove = dwc3_omap_remove,
477 .driver = { 469 .driver = {
478 .name = "omap-dwc3", 470 .name = "omap-dwc3",
479 .of_match_table = of_dwc3_match, 471 .of_match_table = of_dwc3_match,
472 .pm = DEV_PM_OPS,
480 }, 473 },
481}; 474};
482 475
diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c
index e8d77689a322..227d4a7acad7 100644
--- a/drivers/usb/dwc3/dwc3-pci.c
+++ b/drivers/usb/dwc3/dwc3-pci.c
@@ -212,11 +212,49 @@ static DEFINE_PCI_DEVICE_TABLE(dwc3_pci_id_table) = {
212}; 212};
213MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table); 213MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table);
214 214
215#ifdef CONFIG_PM
216static int dwc3_pci_suspend(struct device *dev)
217{
218 struct pci_dev *pci = to_pci_dev(dev);
219
220 pci_disable_device(pci);
221
222 return 0;
223}
224
225static int dwc3_pci_resume(struct device *dev)
226{
227 struct pci_dev *pci = to_pci_dev(dev);
228 int ret;
229
230 ret = pci_enable_device(pci);
231 if (ret) {
232 dev_err(dev, "can't re-enable device --> %d\n", ret);
233 return ret;
234 }
235
236 pci_set_master(pci);
237
238 return 0;
239}
240
241static const struct dev_pm_ops dwc3_pci_dev_pm_ops = {
242 SET_SYSTEM_SLEEP_PM_OPS(dwc3_pci_suspend, dwc3_pci_resume)
243};
244
245#define DEV_PM_OPS (&dwc3_pci_dev_pm_ops)
246#else
247#define DEV_PM_OPS NULL
248#endif /* CONFIG_PM */
249
215static struct pci_driver dwc3_pci_driver = { 250static struct pci_driver dwc3_pci_driver = {
216 .name = "dwc3-pci", 251 .name = "dwc3-pci",
217 .id_table = dwc3_pci_id_table, 252 .id_table = dwc3_pci_id_table,
218 .probe = dwc3_pci_probe, 253 .probe = dwc3_pci_probe,
219 .remove = dwc3_pci_remove, 254 .remove = dwc3_pci_remove,
255 .driver = {
256 .pm = DEV_PM_OPS,
257 },
220}; 258};
221 259
222MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>"); 260MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index 1d139ca05ef1..5acbb948b704 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -394,10 +394,13 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc,
394 u32 wIndex; 394 u32 wIndex;
395 u32 reg; 395 u32 reg;
396 int ret; 396 int ret;
397 enum usb_device_state state;
397 398
398 wValue = le16_to_cpu(ctrl->wValue); 399 wValue = le16_to_cpu(ctrl->wValue);
399 wIndex = le16_to_cpu(ctrl->wIndex); 400 wIndex = le16_to_cpu(ctrl->wIndex);
400 recip = ctrl->bRequestType & USB_RECIP_MASK; 401 recip = ctrl->bRequestType & USB_RECIP_MASK;
402 state = dwc->gadget.state;
403
401 switch (recip) { 404 switch (recip) {
402 case USB_RECIP_DEVICE: 405 case USB_RECIP_DEVICE:
403 406
@@ -409,7 +412,7 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc,
409 * default control pipe 412 * default control pipe
410 */ 413 */
411 case USB_DEVICE_U1_ENABLE: 414 case USB_DEVICE_U1_ENABLE:
412 if (dwc->dev_state != DWC3_CONFIGURED_STATE) 415 if (state != USB_STATE_CONFIGURED)
413 return -EINVAL; 416 return -EINVAL;
414 if (dwc->speed != DWC3_DSTS_SUPERSPEED) 417 if (dwc->speed != DWC3_DSTS_SUPERSPEED)
415 return -EINVAL; 418 return -EINVAL;
@@ -423,7 +426,7 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc,
423 break; 426 break;
424 427
425 case USB_DEVICE_U2_ENABLE: 428 case USB_DEVICE_U2_ENABLE:
426 if (dwc->dev_state != DWC3_CONFIGURED_STATE) 429 if (state != USB_STATE_CONFIGURED)
427 return -EINVAL; 430 return -EINVAL;
428 if (dwc->speed != DWC3_DSTS_SUPERSPEED) 431 if (dwc->speed != DWC3_DSTS_SUPERSPEED)
429 return -EINVAL; 432 return -EINVAL;
@@ -493,6 +496,7 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc,
493 496
494static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) 497static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
495{ 498{
499 enum usb_device_state state = dwc->gadget.state;
496 u32 addr; 500 u32 addr;
497 u32 reg; 501 u32 reg;
498 502
@@ -502,7 +506,7 @@ static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
502 return -EINVAL; 506 return -EINVAL;
503 } 507 }
504 508
505 if (dwc->dev_state == DWC3_CONFIGURED_STATE) { 509 if (state == USB_STATE_CONFIGURED) {
506 dev_dbg(dwc->dev, "trying to set address when configured\n"); 510 dev_dbg(dwc->dev, "trying to set address when configured\n");
507 return -EINVAL; 511 return -EINVAL;
508 } 512 }
@@ -513,9 +517,9 @@ static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
513 dwc3_writel(dwc->regs, DWC3_DCFG, reg); 517 dwc3_writel(dwc->regs, DWC3_DCFG, reg);
514 518
515 if (addr) 519 if (addr)
516 dwc->dev_state = DWC3_ADDRESS_STATE; 520 usb_gadget_set_state(&dwc->gadget, USB_STATE_ADDRESS);
517 else 521 else
518 dwc->dev_state = DWC3_DEFAULT_STATE; 522 usb_gadget_set_state(&dwc->gadget, USB_STATE_DEFAULT);
519 523
520 return 0; 524 return 0;
521} 525}
@@ -532,6 +536,7 @@ static int dwc3_ep0_delegate_req(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
532 536
533static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) 537static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
534{ 538{
539 enum usb_device_state state = dwc->gadget.state;
535 u32 cfg; 540 u32 cfg;
536 int ret; 541 int ret;
537 u32 reg; 542 u32 reg;
@@ -539,16 +544,18 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
539 dwc->start_config_issued = false; 544 dwc->start_config_issued = false;
540 cfg = le16_to_cpu(ctrl->wValue); 545 cfg = le16_to_cpu(ctrl->wValue);
541 546
542 switch (dwc->dev_state) { 547 switch (state) {
543 case DWC3_DEFAULT_STATE: 548 case USB_STATE_DEFAULT:
544 return -EINVAL; 549 return -EINVAL;
545 break; 550 break;
546 551
547 case DWC3_ADDRESS_STATE: 552 case USB_STATE_ADDRESS:
548 ret = dwc3_ep0_delegate_req(dwc, ctrl); 553 ret = dwc3_ep0_delegate_req(dwc, ctrl);
549 /* if the cfg matches and the cfg is non zero */ 554 /* if the cfg matches and the cfg is non zero */
550 if (cfg && (!ret || (ret == USB_GADGET_DELAYED_STATUS))) { 555 if (cfg && (!ret || (ret == USB_GADGET_DELAYED_STATUS))) {
551 dwc->dev_state = DWC3_CONFIGURED_STATE; 556 usb_gadget_set_state(&dwc->gadget,
557 USB_STATE_CONFIGURED);
558
552 /* 559 /*
553 * Enable transition to U1/U2 state when 560 * Enable transition to U1/U2 state when
554 * nothing is pending from application. 561 * nothing is pending from application.
@@ -562,10 +569,11 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
562 } 569 }
563 break; 570 break;
564 571
565 case DWC3_CONFIGURED_STATE: 572 case USB_STATE_CONFIGURED:
566 ret = dwc3_ep0_delegate_req(dwc, ctrl); 573 ret = dwc3_ep0_delegate_req(dwc, ctrl);
567 if (!cfg) 574 if (!cfg)
568 dwc->dev_state = DWC3_ADDRESS_STATE; 575 usb_gadget_set_state(&dwc->gadget,
576 USB_STATE_ADDRESS);
569 break; 577 break;
570 default: 578 default:
571 ret = -EINVAL; 579 ret = -EINVAL;
@@ -620,10 +628,11 @@ static void dwc3_ep0_set_sel_cmpl(struct usb_ep *ep, struct usb_request *req)
620static int dwc3_ep0_set_sel(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) 628static int dwc3_ep0_set_sel(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
621{ 629{
622 struct dwc3_ep *dep; 630 struct dwc3_ep *dep;
631 enum usb_device_state state = dwc->gadget.state;
623 u16 wLength; 632 u16 wLength;
624 u16 wValue; 633 u16 wValue;
625 634
626 if (dwc->dev_state == DWC3_DEFAULT_STATE) 635 if (state == USB_STATE_DEFAULT)
627 return -EINVAL; 636 return -EINVAL;
628 637
629 wValue = le16_to_cpu(ctrl->wValue); 638 wValue = le16_to_cpu(ctrl->wValue);
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 82e160e96fca..2b6e7e001207 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -1425,8 +1425,10 @@ static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on)
1425 if (dwc->revision >= DWC3_REVISION_194A) 1425 if (dwc->revision >= DWC3_REVISION_194A)
1426 reg &= ~DWC3_DCTL_KEEP_CONNECT; 1426 reg &= ~DWC3_DCTL_KEEP_CONNECT;
1427 reg |= DWC3_DCTL_RUN_STOP; 1427 reg |= DWC3_DCTL_RUN_STOP;
1428 dwc->pullups_connected = true;
1428 } else { 1429 } else {
1429 reg &= ~DWC3_DCTL_RUN_STOP; 1430 reg &= ~DWC3_DCTL_RUN_STOP;
1431 dwc->pullups_connected = false;
1430 } 1432 }
1431 1433
1432 dwc3_writel(dwc->regs, DWC3_DCTL, reg); 1434 dwc3_writel(dwc->regs, DWC3_DCTL, reg);
@@ -1469,6 +1471,33 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on)
1469 return ret; 1471 return ret;
1470} 1472}
1471 1473
1474static void dwc3_gadget_enable_irq(struct dwc3 *dwc)
1475{
1476 u32 reg;
1477
1478 /* Enable all but Start and End of Frame IRQs */
1479 reg = (DWC3_DEVTEN_VNDRDEVTSTRCVEDEN |
1480 DWC3_DEVTEN_EVNTOVERFLOWEN |
1481 DWC3_DEVTEN_CMDCMPLTEN |
1482 DWC3_DEVTEN_ERRTICERREN |
1483 DWC3_DEVTEN_WKUPEVTEN |
1484 DWC3_DEVTEN_ULSTCNGEN |
1485 DWC3_DEVTEN_CONNECTDONEEN |
1486 DWC3_DEVTEN_USBRSTEN |
1487 DWC3_DEVTEN_DISCONNEVTEN);
1488
1489 dwc3_writel(dwc->regs, DWC3_DEVTEN, reg);
1490}
1491
1492static void dwc3_gadget_disable_irq(struct dwc3 *dwc)
1493{
1494 /* mask all interrupts */
1495 dwc3_writel(dwc->regs, DWC3_DEVTEN, 0x00);
1496}
1497
1498static irqreturn_t dwc3_interrupt(int irq, void *_dwc);
1499static irqreturn_t dwc3_thread_interrupt(int irq, void *_dwc);
1500
1472static int dwc3_gadget_start(struct usb_gadget *g, 1501static int dwc3_gadget_start(struct usb_gadget *g,
1473 struct usb_gadget_driver *driver) 1502 struct usb_gadget_driver *driver)
1474{ 1503{
@@ -1476,6 +1505,7 @@ static int dwc3_gadget_start(struct usb_gadget *g,
1476 struct dwc3_ep *dep; 1505 struct dwc3_ep *dep;
1477 unsigned long flags; 1506 unsigned long flags;
1478 int ret = 0; 1507 int ret = 0;
1508 int irq;
1479 u32 reg; 1509 u32 reg;
1480 1510
1481 spin_lock_irqsave(&dwc->lock, flags); 1511 spin_lock_irqsave(&dwc->lock, flags);
@@ -1489,7 +1519,6 @@ static int dwc3_gadget_start(struct usb_gadget *g,
1489 } 1519 }
1490 1520
1491 dwc->gadget_driver = driver; 1521 dwc->gadget_driver = driver;
1492 dwc->gadget.dev.driver = &driver->driver;
1493 1522
1494 reg = dwc3_readl(dwc->regs, DWC3_DCFG); 1523 reg = dwc3_readl(dwc->regs, DWC3_DCFG);
1495 reg &= ~(DWC3_DCFG_SPEED_MASK); 1524 reg &= ~(DWC3_DCFG_SPEED_MASK);
@@ -1536,6 +1565,17 @@ static int dwc3_gadget_start(struct usb_gadget *g,
1536 dwc->ep0state = EP0_SETUP_PHASE; 1565 dwc->ep0state = EP0_SETUP_PHASE;
1537 dwc3_ep0_out_start(dwc); 1566 dwc3_ep0_out_start(dwc);
1538 1567
1568 irq = platform_get_irq(to_platform_device(dwc->dev), 0);
1569 ret = request_threaded_irq(irq, dwc3_interrupt, dwc3_thread_interrupt,
1570 IRQF_SHARED | IRQF_ONESHOT, "dwc3", dwc);
1571 if (ret) {
1572 dev_err(dwc->dev, "failed to request irq #%d --> %d\n",
1573 irq, ret);
1574 goto err1;
1575 }
1576
1577 dwc3_gadget_enable_irq(dwc);
1578
1539 spin_unlock_irqrestore(&dwc->lock, flags); 1579 spin_unlock_irqrestore(&dwc->lock, flags);
1540 1580
1541 return 0; 1581 return 0;
@@ -1554,14 +1594,18 @@ static int dwc3_gadget_stop(struct usb_gadget *g,
1554{ 1594{
1555 struct dwc3 *dwc = gadget_to_dwc(g); 1595 struct dwc3 *dwc = gadget_to_dwc(g);
1556 unsigned long flags; 1596 unsigned long flags;
1597 int irq;
1557 1598
1558 spin_lock_irqsave(&dwc->lock, flags); 1599 spin_lock_irqsave(&dwc->lock, flags);
1559 1600
1601 dwc3_gadget_disable_irq(dwc);
1602 irq = platform_get_irq(to_platform_device(dwc->dev), 0);
1603 free_irq(irq, dwc);
1604
1560 __dwc3_gadget_ep_disable(dwc->eps[0]); 1605 __dwc3_gadget_ep_disable(dwc->eps[0]);
1561 __dwc3_gadget_ep_disable(dwc->eps[1]); 1606 __dwc3_gadget_ep_disable(dwc->eps[1]);
1562 1607
1563 dwc->gadget_driver = NULL; 1608 dwc->gadget_driver = NULL;
1564 dwc->gadget.dev.driver = NULL;
1565 1609
1566 spin_unlock_irqrestore(&dwc->lock, flags); 1610 spin_unlock_irqrestore(&dwc->lock, flags);
1567 1611
@@ -1579,14 +1623,15 @@ static const struct usb_gadget_ops dwc3_gadget_ops = {
1579 1623
1580/* -------------------------------------------------------------------------- */ 1624/* -------------------------------------------------------------------------- */
1581 1625
1582static int dwc3_gadget_init_endpoints(struct dwc3 *dwc) 1626static int dwc3_gadget_init_hw_endpoints(struct dwc3 *dwc,
1627 u8 num, u32 direction)
1583{ 1628{
1584 struct dwc3_ep *dep; 1629 struct dwc3_ep *dep;
1585 u8 epnum; 1630 u8 i;
1586 1631
1587 INIT_LIST_HEAD(&dwc->gadget.ep_list); 1632 for (i = 0; i < num; i++) {
1633 u8 epnum = (i << 1) | (!!direction);
1588 1634
1589 for (epnum = 0; epnum < DWC3_ENDPOINTS_NUM; epnum++) {
1590 dep = kzalloc(sizeof(*dep), GFP_KERNEL); 1635 dep = kzalloc(sizeof(*dep), GFP_KERNEL);
1591 if (!dep) { 1636 if (!dep) {
1592 dev_err(dwc->dev, "can't allocate endpoint %d\n", 1637 dev_err(dwc->dev, "can't allocate endpoint %d\n",
@@ -1600,6 +1645,7 @@ static int dwc3_gadget_init_endpoints(struct dwc3 *dwc)
1600 1645
1601 snprintf(dep->name, sizeof(dep->name), "ep%d%s", epnum >> 1, 1646 snprintf(dep->name, sizeof(dep->name), "ep%d%s", epnum >> 1,
1602 (epnum & 1) ? "in" : "out"); 1647 (epnum & 1) ? "in" : "out");
1648
1603 dep->endpoint.name = dep->name; 1649 dep->endpoint.name = dep->name;
1604 dep->direction = (epnum & 1); 1650 dep->direction = (epnum & 1);
1605 1651
@@ -1630,6 +1676,27 @@ static int dwc3_gadget_init_endpoints(struct dwc3 *dwc)
1630 return 0; 1676 return 0;
1631} 1677}
1632 1678
1679static int dwc3_gadget_init_endpoints(struct dwc3 *dwc)
1680{
1681 int ret;
1682
1683 INIT_LIST_HEAD(&dwc->gadget.ep_list);
1684
1685 ret = dwc3_gadget_init_hw_endpoints(dwc, dwc->num_out_eps, 0);
1686 if (ret < 0) {
1687 dev_vdbg(dwc->dev, "failed to allocate OUT endpoints\n");
1688 return ret;
1689 }
1690
1691 ret = dwc3_gadget_init_hw_endpoints(dwc, dwc->num_in_eps, 1);
1692 if (ret < 0) {
1693 dev_vdbg(dwc->dev, "failed to allocate IN endpoints\n");
1694 return ret;
1695 }
1696
1697 return 0;
1698}
1699
1633static void dwc3_gadget_free_endpoints(struct dwc3 *dwc) 1700static void dwc3_gadget_free_endpoints(struct dwc3 *dwc)
1634{ 1701{
1635 struct dwc3_ep *dep; 1702 struct dwc3_ep *dep;
@@ -1637,6 +1704,9 @@ static void dwc3_gadget_free_endpoints(struct dwc3 *dwc)
1637 1704
1638 for (epnum = 0; epnum < DWC3_ENDPOINTS_NUM; epnum++) { 1705 for (epnum = 0; epnum < DWC3_ENDPOINTS_NUM; epnum++) {
1639 dep = dwc->eps[epnum]; 1706 dep = dwc->eps[epnum];
1707 if (!dep)
1708 continue;
1709
1640 dwc3_free_trb_pool(dep); 1710 dwc3_free_trb_pool(dep);
1641 1711
1642 if (epnum != 0 && epnum != 1) 1712 if (epnum != 0 && epnum != 1)
@@ -1646,12 +1716,8 @@ static void dwc3_gadget_free_endpoints(struct dwc3 *dwc)
1646 } 1716 }
1647} 1717}
1648 1718
1649static void dwc3_gadget_release(struct device *dev)
1650{
1651 dev_dbg(dev, "%s\n", __func__);
1652}
1653
1654/* -------------------------------------------------------------------------- */ 1719/* -------------------------------------------------------------------------- */
1720
1655static int __dwc3_cleanup_done_trbs(struct dwc3 *dwc, struct dwc3_ep *dep, 1721static int __dwc3_cleanup_done_trbs(struct dwc3 *dwc, struct dwc3_ep *dep,
1656 struct dwc3_request *req, struct dwc3_trb *trb, 1722 struct dwc3_request *req, struct dwc3_trb *trb,
1657 const struct dwc3_event_depevt *event, int status) 1723 const struct dwc3_event_depevt *event, int status)
@@ -1975,6 +2041,9 @@ static void dwc3_stop_active_transfers(struct dwc3 *dwc)
1975 struct dwc3_ep *dep; 2041 struct dwc3_ep *dep;
1976 2042
1977 dep = dwc->eps[epnum]; 2043 dep = dwc->eps[epnum];
2044 if (!dep)
2045 continue;
2046
1978 if (!(dep->flags & DWC3_EP_ENABLED)) 2047 if (!(dep->flags & DWC3_EP_ENABLED))
1979 continue; 2048 continue;
1980 2049
@@ -1992,6 +2061,8 @@ static void dwc3_clear_stall_all_ep(struct dwc3 *dwc)
1992 int ret; 2061 int ret;
1993 2062
1994 dep = dwc->eps[epnum]; 2063 dep = dwc->eps[epnum];
2064 if (!dep)
2065 continue;
1995 2066
1996 if (!(dep->flags & DWC3_EP_STALL)) 2067 if (!(dep->flags & DWC3_EP_STALL))
1997 continue; 2068 continue;
@@ -2091,7 +2162,7 @@ static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc)
2091 } 2162 }
2092 2163
2093 /* after reset -> Default State */ 2164 /* after reset -> Default State */
2094 dwc->dev_state = DWC3_DEFAULT_STATE; 2165 usb_gadget_set_state(&dwc->gadget, USB_STATE_DEFAULT);
2095 2166
2096 /* Recent versions support automatic phy suspend and don't need this */ 2167 /* Recent versions support automatic phy suspend and don't need this */
2097 if (dwc->revision < DWC3_REVISION_194A) { 2168 if (dwc->revision < DWC3_REVISION_194A) {
@@ -2277,6 +2348,34 @@ static void dwc3_gadget_linksts_change_interrupt(struct dwc3 *dwc,
2277 unsigned int evtinfo) 2348 unsigned int evtinfo)
2278{ 2349{
2279 enum dwc3_link_state next = evtinfo & DWC3_LINK_STATE_MASK; 2350 enum dwc3_link_state next = evtinfo & DWC3_LINK_STATE_MASK;
2351 unsigned int pwropt;
2352
2353 /*
2354 * WORKAROUND: DWC3 < 2.50a have an issue when configured without
2355 * Hibernation mode enabled which would show up when device detects
2356 * host-initiated U3 exit.
2357 *
2358 * In that case, device will generate a Link State Change Interrupt
2359 * from U3 to RESUME which is only necessary if Hibernation is
2360 * configured in.
2361 *
2362 * There are no functional changes due to such spurious event and we
2363 * just need to ignore it.
2364 *
2365 * Refers to:
2366 *
2367 * STAR#9000570034 RTL: SS Resume event generated in non-Hibernation
2368 * operational mode
2369 */
2370 pwropt = DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1);
2371 if ((dwc->revision < DWC3_REVISION_250A) &&
2372 (pwropt != DWC3_GHWPARAMS1_EN_PWROPT_HIB)) {
2373 if ((dwc->link_state == DWC3_LINK_STATE_U3) &&
2374 (next == DWC3_LINK_STATE_RESUME)) {
2375 dev_vdbg(dwc->dev, "ignoring transition U3 -> Resume\n");
2376 return;
2377 }
2378 }
2280 2379
2281 /* 2380 /*
2282 * WORKAROUND: DWC3 Revisions <1.83a have an issue which, depending 2381 * WORKAROUND: DWC3 Revisions <1.83a have an issue which, depending
@@ -2387,40 +2486,73 @@ static void dwc3_process_event_entry(struct dwc3 *dwc,
2387 } 2486 }
2388} 2487}
2389 2488
2489static irqreturn_t dwc3_thread_interrupt(int irq, void *_dwc)
2490{
2491 struct dwc3 *dwc = _dwc;
2492 unsigned long flags;
2493 irqreturn_t ret = IRQ_NONE;
2494 int i;
2495
2496 spin_lock_irqsave(&dwc->lock, flags);
2497
2498 for (i = 0; i < dwc->num_event_buffers; i++) {
2499 struct dwc3_event_buffer *evt;
2500 int left;
2501
2502 evt = dwc->ev_buffs[i];
2503 left = evt->count;
2504
2505 if (!(evt->flags & DWC3_EVENT_PENDING))
2506 continue;
2507
2508 while (left > 0) {
2509 union dwc3_event event;
2510
2511 event.raw = *(u32 *) (evt->buf + evt->lpos);
2512
2513 dwc3_process_event_entry(dwc, &event);
2514
2515 /*
2516 * FIXME we wrap around correctly to the next entry as
2517 * almost all entries are 4 bytes in size. There is one
2518 * entry which has 12 bytes which is a regular entry
2519 * followed by 8 bytes data. ATM I don't know how
2520 * things are organized if we get next to the a
2521 * boundary so I worry about that once we try to handle
2522 * that.
2523 */
2524 evt->lpos = (evt->lpos + 4) % DWC3_EVENT_BUFFERS_SIZE;
2525 left -= 4;
2526
2527 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(i), 4);
2528 }
2529
2530 evt->count = 0;
2531 evt->flags &= ~DWC3_EVENT_PENDING;
2532 ret = IRQ_HANDLED;
2533 }
2534
2535 spin_unlock_irqrestore(&dwc->lock, flags);
2536
2537 return ret;
2538}
2539
2390static irqreturn_t dwc3_process_event_buf(struct dwc3 *dwc, u32 buf) 2540static irqreturn_t dwc3_process_event_buf(struct dwc3 *dwc, u32 buf)
2391{ 2541{
2392 struct dwc3_event_buffer *evt; 2542 struct dwc3_event_buffer *evt;
2393 int left;
2394 u32 count; 2543 u32 count;
2395 2544
2545 evt = dwc->ev_buffs[buf];
2546
2396 count = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(buf)); 2547 count = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(buf));
2397 count &= DWC3_GEVNTCOUNT_MASK; 2548 count &= DWC3_GEVNTCOUNT_MASK;
2398 if (!count) 2549 if (!count)
2399 return IRQ_NONE; 2550 return IRQ_NONE;
2400 2551
2401 evt = dwc->ev_buffs[buf]; 2552 evt->count = count;
2402 left = count; 2553 evt->flags |= DWC3_EVENT_PENDING;
2403
2404 while (left > 0) {
2405 union dwc3_event event;
2406
2407 event.raw = *(u32 *) (evt->buf + evt->lpos);
2408 2554
2409 dwc3_process_event_entry(dwc, &event); 2555 return IRQ_WAKE_THREAD;
2410 /*
2411 * XXX we wrap around correctly to the next entry as almost all
2412 * entries are 4 bytes in size. There is one entry which has 12
2413 * bytes which is a regular entry followed by 8 bytes data. ATM
2414 * I don't know how things are organized if were get next to the
2415 * a boundary so I worry about that once we try to handle that.
2416 */
2417 evt->lpos = (evt->lpos + 4) % DWC3_EVENT_BUFFERS_SIZE;
2418 left -= 4;
2419
2420 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(buf), 4);
2421 }
2422
2423 return IRQ_HANDLED;
2424} 2556}
2425 2557
2426static irqreturn_t dwc3_interrupt(int irq, void *_dwc) 2558static irqreturn_t dwc3_interrupt(int irq, void *_dwc)
@@ -2435,7 +2567,7 @@ static irqreturn_t dwc3_interrupt(int irq, void *_dwc)
2435 irqreturn_t status; 2567 irqreturn_t status;
2436 2568
2437 status = dwc3_process_event_buf(dwc, i); 2569 status = dwc3_process_event_buf(dwc, i);
2438 if (status == IRQ_HANDLED) 2570 if (status == IRQ_WAKE_THREAD)
2439 ret = status; 2571 ret = status;
2440 } 2572 }
2441 2573
@@ -2454,7 +2586,6 @@ int dwc3_gadget_init(struct dwc3 *dwc)
2454{ 2586{
2455 u32 reg; 2587 u32 reg;
2456 int ret; 2588 int ret;
2457 int irq;
2458 2589
2459 dwc->ctrl_req = dma_alloc_coherent(dwc->dev, sizeof(*dwc->ctrl_req), 2590 dwc->ctrl_req = dma_alloc_coherent(dwc->dev, sizeof(*dwc->ctrl_req),
2460 &dwc->ctrl_req_addr, GFP_KERNEL); 2591 &dwc->ctrl_req_addr, GFP_KERNEL);
@@ -2488,19 +2619,10 @@ int dwc3_gadget_init(struct dwc3 *dwc)
2488 goto err3; 2619 goto err3;
2489 } 2620 }
2490 2621
2491 dev_set_name(&dwc->gadget.dev, "gadget");
2492
2493 dwc->gadget.ops = &dwc3_gadget_ops; 2622 dwc->gadget.ops = &dwc3_gadget_ops;
2494 dwc->gadget.max_speed = USB_SPEED_SUPER; 2623 dwc->gadget.max_speed = USB_SPEED_SUPER;
2495 dwc->gadget.speed = USB_SPEED_UNKNOWN; 2624 dwc->gadget.speed = USB_SPEED_UNKNOWN;
2496 dwc->gadget.dev.parent = dwc->dev;
2497 dwc->gadget.sg_supported = true; 2625 dwc->gadget.sg_supported = true;
2498
2499 dma_set_coherent_mask(&dwc->gadget.dev, dwc->dev->coherent_dma_mask);
2500
2501 dwc->gadget.dev.dma_parms = dwc->dev->dma_parms;
2502 dwc->gadget.dev.dma_mask = dwc->dev->dma_mask;
2503 dwc->gadget.dev.release = dwc3_gadget_release;
2504 dwc->gadget.name = "dwc3-gadget"; 2626 dwc->gadget.name = "dwc3-gadget";
2505 2627
2506 /* 2628 /*
@@ -2512,60 +2634,24 @@ int dwc3_gadget_init(struct dwc3 *dwc)
2512 if (ret) 2634 if (ret)
2513 goto err4; 2635 goto err4;
2514 2636
2515 irq = platform_get_irq(to_platform_device(dwc->dev), 0);
2516
2517 ret = request_irq(irq, dwc3_interrupt, IRQF_SHARED,
2518 "dwc3", dwc);
2519 if (ret) {
2520 dev_err(dwc->dev, "failed to request irq #%d --> %d\n",
2521 irq, ret);
2522 goto err5;
2523 }
2524
2525 reg = dwc3_readl(dwc->regs, DWC3_DCFG); 2637 reg = dwc3_readl(dwc->regs, DWC3_DCFG);
2526 reg |= DWC3_DCFG_LPM_CAP; 2638 reg |= DWC3_DCFG_LPM_CAP;
2527 dwc3_writel(dwc->regs, DWC3_DCFG, reg); 2639 dwc3_writel(dwc->regs, DWC3_DCFG, reg);
2528 2640
2529 /* Enable all but Start and End of Frame IRQs */ 2641 /* Enable USB2 LPM and automatic phy suspend only on recent versions */
2530 reg = (DWC3_DEVTEN_VNDRDEVTSTRCVEDEN |
2531 DWC3_DEVTEN_EVNTOVERFLOWEN |
2532 DWC3_DEVTEN_CMDCMPLTEN |
2533 DWC3_DEVTEN_ERRTICERREN |
2534 DWC3_DEVTEN_WKUPEVTEN |
2535 DWC3_DEVTEN_ULSTCNGEN |
2536 DWC3_DEVTEN_CONNECTDONEEN |
2537 DWC3_DEVTEN_USBRSTEN |
2538 DWC3_DEVTEN_DISCONNEVTEN);
2539 dwc3_writel(dwc->regs, DWC3_DEVTEN, reg);
2540
2541 /* automatic phy suspend only on recent versions */
2542 if (dwc->revision >= DWC3_REVISION_194A) { 2642 if (dwc->revision >= DWC3_REVISION_194A) {
2543 dwc3_gadget_usb2_phy_suspend(dwc, false); 2643 dwc3_gadget_usb2_phy_suspend(dwc, false);
2544 dwc3_gadget_usb3_phy_suspend(dwc, false); 2644 dwc3_gadget_usb3_phy_suspend(dwc, false);
2545 } 2645 }
2546 2646
2547 ret = device_register(&dwc->gadget.dev);
2548 if (ret) {
2549 dev_err(dwc->dev, "failed to register gadget device\n");
2550 put_device(&dwc->gadget.dev);
2551 goto err6;
2552 }
2553
2554 ret = usb_add_gadget_udc(dwc->dev, &dwc->gadget); 2647 ret = usb_add_gadget_udc(dwc->dev, &dwc->gadget);
2555 if (ret) { 2648 if (ret) {
2556 dev_err(dwc->dev, "failed to register udc\n"); 2649 dev_err(dwc->dev, "failed to register udc\n");
2557 goto err7; 2650 goto err5;
2558 } 2651 }
2559 2652
2560 return 0; 2653 return 0;
2561 2654
2562err7:
2563 device_unregister(&dwc->gadget.dev);
2564
2565err6:
2566 dwc3_writel(dwc->regs, DWC3_DEVTEN, 0x00);
2567 free_irq(irq, dwc);
2568
2569err5: 2655err5:
2570 dwc3_gadget_free_endpoints(dwc); 2656 dwc3_gadget_free_endpoints(dwc);
2571 2657
@@ -2588,15 +2674,11 @@ err0:
2588 return ret; 2674 return ret;
2589} 2675}
2590 2676
2677/* -------------------------------------------------------------------------- */
2678
2591void dwc3_gadget_exit(struct dwc3 *dwc) 2679void dwc3_gadget_exit(struct dwc3 *dwc)
2592{ 2680{
2593 int irq;
2594
2595 usb_del_gadget_udc(&dwc->gadget); 2681 usb_del_gadget_udc(&dwc->gadget);
2596 irq = platform_get_irq(to_platform_device(dwc->dev), 0);
2597
2598 dwc3_writel(dwc->regs, DWC3_DEVTEN, 0x00);
2599 free_irq(irq, dwc);
2600 2682
2601 dwc3_gadget_free_endpoints(dwc); 2683 dwc3_gadget_free_endpoints(dwc);
2602 2684
@@ -2610,6 +2692,63 @@ void dwc3_gadget_exit(struct dwc3 *dwc)
2610 2692
2611 dma_free_coherent(dwc->dev, sizeof(*dwc->ctrl_req), 2693 dma_free_coherent(dwc->dev, sizeof(*dwc->ctrl_req),
2612 dwc->ctrl_req, dwc->ctrl_req_addr); 2694 dwc->ctrl_req, dwc->ctrl_req_addr);
2695}
2613 2696
2614 device_unregister(&dwc->gadget.dev); 2697int dwc3_gadget_prepare(struct dwc3 *dwc)
2698{
2699 if (dwc->pullups_connected)
2700 dwc3_gadget_disable_irq(dwc);
2701
2702 return 0;
2703}
2704
2705void dwc3_gadget_complete(struct dwc3 *dwc)
2706{
2707 if (dwc->pullups_connected) {
2708 dwc3_gadget_enable_irq(dwc);
2709 dwc3_gadget_run_stop(dwc, true);
2710 }
2711}
2712
2713int dwc3_gadget_suspend(struct dwc3 *dwc)
2714{
2715 __dwc3_gadget_ep_disable(dwc->eps[0]);
2716 __dwc3_gadget_ep_disable(dwc->eps[1]);
2717
2718 dwc->dcfg = dwc3_readl(dwc->regs, DWC3_DCFG);
2719
2720 return 0;
2721}
2722
2723int dwc3_gadget_resume(struct dwc3 *dwc)
2724{
2725 struct dwc3_ep *dep;
2726 int ret;
2727
2728 /* Start with SuperSpeed Default */
2729 dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(512);
2730
2731 dep = dwc->eps[0];
2732 ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL, false);
2733 if (ret)
2734 goto err0;
2735
2736 dep = dwc->eps[1];
2737 ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL, false);
2738 if (ret)
2739 goto err1;
2740
2741 /* begin to receive SETUP packets */
2742 dwc->ep0state = EP0_SETUP_PHASE;
2743 dwc3_ep0_out_start(dwc);
2744
2745 dwc3_writel(dwc->regs, DWC3_DCFG, dwc->dcfg);
2746
2747 return 0;
2748
2749err1:
2750 __dwc3_gadget_ep_disable(dwc->eps[0]);
2751
2752err0:
2753 return ret;
2615} 2754}
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index c7525b1cad74..a61d981cbd15 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -196,7 +196,6 @@ config USB_OMAP
196 tristate "OMAP USB Device Controller" 196 tristate "OMAP USB Device Controller"
197 depends on ARCH_OMAP1 197 depends on ARCH_OMAP1
198 select ISP1301_OMAP if MACH_OMAP_H2 || MACH_OMAP_H3 || MACH_OMAP_H4_OTG 198 select ISP1301_OMAP if MACH_OMAP_H2 || MACH_OMAP_H3 || MACH_OMAP_H4_OTG
199 select USB_OTG_UTILS if ARCH_OMAP
200 help 199 help
201 Many Texas Instruments OMAP processors have flexible full 200 Many Texas Instruments OMAP processors have flexible full
202 speed USB device controllers, with support for up to 30 201 speed USB device controllers, with support for up to 30
@@ -211,7 +210,6 @@ config USB_OMAP
211config USB_PXA25X 210config USB_PXA25X
212 tristate "PXA 25x or IXP 4xx" 211 tristate "PXA 25x or IXP 4xx"
213 depends on (ARCH_PXA && PXA25x) || ARCH_IXP4XX 212 depends on (ARCH_PXA && PXA25x) || ARCH_IXP4XX
214 select USB_OTG_UTILS
215 help 213 help
216 Intel's PXA 25x series XScale ARM-5TE processors include 214 Intel's PXA 25x series XScale ARM-5TE processors include
217 an integrated full speed USB 1.1 device controller. The 215 an integrated full speed USB 1.1 device controller. The
@@ -259,8 +257,6 @@ config USB_RENESAS_USBHS_UDC
259 257
260config USB_PXA27X 258config USB_PXA27X
261 tristate "PXA 27x" 259 tristate "PXA 27x"
262 depends on ARCH_PXA && (PXA27x || PXA3xx)
263 select USB_OTG_UTILS
264 help 260 help
265 Intel's PXA 27x series XScale ARM v5TE processors include 261 Intel's PXA 27x series XScale ARM v5TE processors include
266 an integrated full speed USB 1.1 device controller. 262 an integrated full speed USB 1.1 device controller.
@@ -329,9 +325,6 @@ config USB_MV_UDC
329 325
330config USB_MV_U3D 326config USB_MV_U3D
331 tristate "MARVELL PXA2128 USB 3.0 controller" 327 tristate "MARVELL PXA2128 USB 3.0 controller"
332 depends on CPU_MMP3
333 select USB_GADGET_DUALSPEED
334 select USB_GADGET_SUPERSPEED
335 help 328 help
336 MARVELL PXA2128 Processor series include a super speed USB3.0 device 329 MARVELL PXA2128 Processor series include a super speed USB3.0 device
337 controller, which support super speed USB peripheral. 330 controller, which support super speed USB peripheral.
@@ -501,6 +494,7 @@ endmenu
501# composite based drivers 494# composite based drivers
502config USB_LIBCOMPOSITE 495config USB_LIBCOMPOSITE
503 tristate 496 tristate
497 select CONFIGFS_FS
504 depends on USB_GADGET 498 depends on USB_GADGET
505 499
506config USB_F_ACM 500config USB_F_ACM
@@ -512,6 +506,12 @@ config USB_F_SS_LB
512config USB_U_SERIAL 506config USB_U_SERIAL
513 tristate 507 tristate
514 508
509config USB_F_SERIAL
510 tristate
511
512config USB_F_OBEX
513 tristate
514
515choice 515choice
516 tristate "USB Gadget Drivers" 516 tristate "USB Gadget Drivers"
517 default USB_ETH 517 default USB_ETH
@@ -766,6 +766,8 @@ config USB_G_SERIAL
766 depends on TTY 766 depends on TTY
767 select USB_U_SERIAL 767 select USB_U_SERIAL
768 select USB_F_ACM 768 select USB_F_ACM
769 select USB_F_SERIAL
770 select USB_F_OBEX
769 select USB_LIBCOMPOSITE 771 select USB_LIBCOMPOSITE
770 help 772 help
771 The Serial Gadget talks to the Linux-USB generic serial driver. 773 The Serial Gadget talks to the Linux-USB generic serial driver.
@@ -839,6 +841,7 @@ config USB_G_NOKIA
839 depends on PHONET 841 depends on PHONET
840 select USB_LIBCOMPOSITE 842 select USB_LIBCOMPOSITE
841 select USB_U_SERIAL 843 select USB_U_SERIAL
844 select USB_F_ACM
842 help 845 help
843 The Nokia composite gadget provides support for acm, obex 846 The Nokia composite gadget provides support for acm, obex
844 and phonet in only one composite gadget driver. 847 and phonet in only one composite gadget driver.
@@ -957,6 +960,7 @@ config USB_G_WEBCAM
957 tristate "USB Webcam Gadget" 960 tristate "USB Webcam Gadget"
958 depends on VIDEO_DEV 961 depends on VIDEO_DEV
959 select USB_LIBCOMPOSITE 962 select USB_LIBCOMPOSITE
963 select VIDEOBUF2_VMALLOC
960 help 964 help
961 The Webcam Gadget acts as a composite USB Audio and Video Class 965 The Webcam Gadget acts as a composite USB Audio and Video Class
962 device. It provides a userspace API to process UVC control requests 966 device. It provides a userspace API to process UVC control requests
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 82fb22511356..6afd16659e78 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -6,7 +6,7 @@ ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG
6obj-$(CONFIG_USB_GADGET) += udc-core.o 6obj-$(CONFIG_USB_GADGET) += udc-core.o
7obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o 7obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o
8libcomposite-y := usbstring.o config.o epautoconf.o 8libcomposite-y := usbstring.o config.o epautoconf.o
9libcomposite-y += composite.o functions.o 9libcomposite-y += composite.o functions.o configfs.o
10obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o 10obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o
11obj-$(CONFIG_USB_NET2272) += net2272.o 11obj-$(CONFIG_USB_NET2272) += net2272.o
12obj-$(CONFIG_USB_NET2280) += net2280.o 12obj-$(CONFIG_USB_NET2280) += net2280.o
@@ -36,10 +36,15 @@ obj-$(CONFIG_USB_FUSB300) += fusb300_udc.o
36obj-$(CONFIG_USB_MV_U3D) += mv_u3d_core.o 36obj-$(CONFIG_USB_MV_U3D) += mv_u3d_core.o
37 37
38# USB Functions 38# USB Functions
39obj-$(CONFIG_USB_F_ACM) += f_acm.o 39usb_f_acm-y := f_acm.o
40f_ss_lb-y := f_loopback.o f_sourcesink.o 40obj-$(CONFIG_USB_F_ACM) += usb_f_acm.o
41obj-$(CONFIG_USB_F_SS_LB) += f_ss_lb.o 41usb_f_ss_lb-y := f_loopback.o f_sourcesink.o
42obj-$(CONFIG_USB_F_SS_LB) += usb_f_ss_lb.o
42obj-$(CONFIG_USB_U_SERIAL) += u_serial.o 43obj-$(CONFIG_USB_U_SERIAL) += u_serial.o
44usb_f_serial-y := f_serial.o
45obj-$(CONFIG_USB_F_SERIAL) += usb_f_serial.o
46usb_f_obex-y := f_obex.o
47obj-$(CONFIG_USB_F_OBEX) += usb_f_obex.o
43 48
44# 49#
45# USB gadget drivers 50# USB gadget drivers
diff --git a/drivers/usb/gadget/acm_ms.c b/drivers/usb/gadget/acm_ms.c
index 8f2b0e391534..4b947bb50f62 100644
--- a/drivers/usb/gadget/acm_ms.c
+++ b/drivers/usb/gadget/acm_ms.c
@@ -109,7 +109,6 @@ FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data);
109static struct fsg_common fsg_common; 109static struct fsg_common fsg_common;
110 110
111/*-------------------------------------------------------------------------*/ 111/*-------------------------------------------------------------------------*/
112static unsigned char tty_line;
113static struct usb_function *f_acm; 112static struct usb_function *f_acm;
114static struct usb_function_instance *f_acm_inst; 113static struct usb_function_instance *f_acm_inst;
115/* 114/*
@@ -117,7 +116,6 @@ static struct usb_function_instance *f_acm_inst;
117 */ 116 */
118static int __init acm_ms_do_config(struct usb_configuration *c) 117static int __init acm_ms_do_config(struct usb_configuration *c)
119{ 118{
120 struct f_serial_opts *opts;
121 int status; 119 int status;
122 120
123 if (gadget_is_otg(c->cdev->gadget)) { 121 if (gadget_is_otg(c->cdev->gadget)) {
@@ -129,9 +127,6 @@ static int __init acm_ms_do_config(struct usb_configuration *c)
129 if (IS_ERR(f_acm_inst)) 127 if (IS_ERR(f_acm_inst))
130 return PTR_ERR(f_acm_inst); 128 return PTR_ERR(f_acm_inst);
131 129
132 opts = container_of(f_acm_inst, struct f_serial_opts, func_inst);
133 opts->port_num = tty_line;
134
135 f_acm = usb_get_function(f_acm_inst); 130 f_acm = usb_get_function(f_acm_inst);
136 if (IS_ERR(f_acm)) { 131 if (IS_ERR(f_acm)) {
137 status = PTR_ERR(f_acm); 132 status = PTR_ERR(f_acm);
@@ -171,16 +166,11 @@ static int __init acm_ms_bind(struct usb_composite_dev *cdev)
171 int status; 166 int status;
172 void *retp; 167 void *retp;
173 168
174 /* set up serial link layer */
175 status = gserial_alloc_line(&tty_line);
176 if (status < 0)
177 return status;
178
179 /* set up mass storage function */ 169 /* set up mass storage function */
180 retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data); 170 retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data);
181 if (IS_ERR(retp)) { 171 if (IS_ERR(retp)) {
182 status = PTR_ERR(retp); 172 status = PTR_ERR(retp);
183 goto fail0; 173 return PTR_ERR(retp);
184 } 174 }
185 175
186 /* 176 /*
@@ -207,8 +197,6 @@ static int __init acm_ms_bind(struct usb_composite_dev *cdev)
207 /* error recovery */ 197 /* error recovery */
208fail1: 198fail1:
209 fsg_common_put(&fsg_common); 199 fsg_common_put(&fsg_common);
210fail0:
211 gserial_free_line(tty_line);
212 return status; 200 return status;
213} 201}
214 202
@@ -216,7 +204,6 @@ static int __exit acm_ms_unbind(struct usb_composite_dev *cdev)
216{ 204{
217 usb_put_function(f_acm); 205 usb_put_function(f_acm);
218 usb_put_function_instance(f_acm_inst); 206 usb_put_function_instance(f_acm_inst);
219 gserial_free_line(tty_line);
220 return 0; 207 return 0;
221} 208}
222 209
diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c
index 75973f33a4c8..f52dcfe8f545 100644
--- a/drivers/usb/gadget/amd5536udc.c
+++ b/drivers/usb/gadget/amd5536udc.c
@@ -1922,7 +1922,6 @@ static int amd5536_udc_start(struct usb_gadget *g,
1922 1922
1923 driver->driver.bus = NULL; 1923 driver->driver.bus = NULL;
1924 dev->driver = driver; 1924 dev->driver = driver;
1925 dev->gadget.dev.driver = &driver->driver;
1926 1925
1927 /* Some gadget drivers use both ep0 directions. 1926 /* Some gadget drivers use both ep0 directions.
1928 * NOTE: to gadget driver, ep0 is just one endpoint... 1927 * NOTE: to gadget driver, ep0 is just one endpoint...
@@ -1973,7 +1972,6 @@ static int amd5536_udc_stop(struct usb_gadget *g,
1973 shutdown(dev, driver); 1972 shutdown(dev, driver);
1974 spin_unlock_irqrestore(&dev->lock, flags); 1973 spin_unlock_irqrestore(&dev->lock, flags);
1975 1974
1976 dev->gadget.dev.driver = NULL;
1977 dev->driver = NULL; 1975 dev->driver = NULL;
1978 1976
1979 /* set SD */ 1977 /* set SD */
@@ -3080,7 +3078,6 @@ static void udc_pci_remove(struct pci_dev *pdev)
3080 if (dev->active) 3078 if (dev->active)
3081 pci_disable_device(pdev); 3079 pci_disable_device(pdev);
3082 3080
3083 device_unregister(&dev->gadget.dev);
3084 pci_set_drvdata(pdev, NULL); 3081 pci_set_drvdata(pdev, NULL);
3085 3082
3086 udc_remove(dev); 3083 udc_remove(dev);
@@ -3245,8 +3242,6 @@ static int udc_pci_probe(
3245 dev->phys_addr = resource; 3242 dev->phys_addr = resource;
3246 dev->irq = pdev->irq; 3243 dev->irq = pdev->irq;
3247 dev->pdev = pdev; 3244 dev->pdev = pdev;
3248 dev->gadget.dev.parent = &pdev->dev;
3249 dev->gadget.dev.dma_mask = pdev->dev.dma_mask;
3250 3245
3251 /* general probing */ 3246 /* general probing */
3252 if (udc_probe(dev) == 0) 3247 if (udc_probe(dev) == 0)
@@ -3273,7 +3268,6 @@ static int udc_probe(struct udc *dev)
3273 dev->gadget.ops = &udc_ops; 3268 dev->gadget.ops = &udc_ops;
3274 3269
3275 dev_set_name(&dev->gadget.dev, "gadget"); 3270 dev_set_name(&dev->gadget.dev, "gadget");
3276 dev->gadget.dev.release = gadget_release;
3277 dev->gadget.name = name; 3271 dev->gadget.name = name;
3278 dev->gadget.max_speed = USB_SPEED_HIGH; 3272 dev->gadget.max_speed = USB_SPEED_HIGH;
3279 3273
@@ -3297,17 +3291,11 @@ static int udc_probe(struct udc *dev)
3297 "driver version: %s(for Geode5536 B1)\n", tmp); 3291 "driver version: %s(for Geode5536 B1)\n", tmp);
3298 udc = dev; 3292 udc = dev;
3299 3293
3300 retval = usb_add_gadget_udc(&udc->pdev->dev, &dev->gadget); 3294 retval = usb_add_gadget_udc_release(&udc->pdev->dev, &dev->gadget,
3295 gadget_release);
3301 if (retval) 3296 if (retval)
3302 goto finished; 3297 goto finished;
3303 3298
3304 retval = device_register(&dev->gadget.dev);
3305 if (retval) {
3306 usb_del_gadget_udc(&dev->gadget);
3307 put_device(&dev->gadget.dev);
3308 goto finished;
3309 }
3310
3311 /* timer init */ 3299 /* timer init */
3312 init_timer(&udc_timer); 3300 init_timer(&udc_timer);
3313 udc_timer.function = udc_timer_function; 3301 udc_timer.function = udc_timer_function;
diff --git a/drivers/usb/gadget/amd5536udc.h b/drivers/usb/gadget/amd5536udc.h
index f1bf32e6b8d8..6744d3b83109 100644
--- a/drivers/usb/gadget/amd5536udc.h
+++ b/drivers/usb/gadget/amd5536udc.h
@@ -472,7 +472,6 @@ struct udc_request {
472 472
473 /* flags */ 473 /* flags */
474 unsigned dma_going : 1, 474 unsigned dma_going : 1,
475 dma_mapping : 1,
476 dma_done : 1; 475 dma_done : 1;
477 /* phys. address */ 476 /* phys. address */
478 dma_addr_t td_phys; 477 dma_addr_t td_phys;
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index 45dd2929a671..a690d64217f4 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -1631,7 +1631,6 @@ static int at91_start(struct usb_gadget *gadget,
1631 1631
1632 udc = container_of(gadget, struct at91_udc, gadget); 1632 udc = container_of(gadget, struct at91_udc, gadget);
1633 udc->driver = driver; 1633 udc->driver = driver;
1634 udc->gadget.dev.driver = &driver->driver;
1635 udc->gadget.dev.of_node = udc->pdev->dev.of_node; 1634 udc->gadget.dev.of_node = udc->pdev->dev.of_node;
1636 udc->enabled = 1; 1635 udc->enabled = 1;
1637 udc->selfpowered = 1; 1636 udc->selfpowered = 1;
@@ -1652,7 +1651,6 @@ static int at91_stop(struct usb_gadget *gadget,
1652 at91_udp_write(udc, AT91_UDP_IDR, ~0); 1651 at91_udp_write(udc, AT91_UDP_IDR, ~0);
1653 spin_unlock_irqrestore(&udc->lock, flags); 1652 spin_unlock_irqrestore(&udc->lock, flags);
1654 1653
1655 udc->gadget.dev.driver = NULL;
1656 udc->driver = NULL; 1654 udc->driver = NULL;
1657 1655
1658 DBG("unbound from %s\n", driver->driver.name); 1656 DBG("unbound from %s\n", driver->driver.name);
@@ -1780,13 +1778,7 @@ static int at91udc_probe(struct platform_device *pdev)
1780 DBG("clocks missing\n"); 1778 DBG("clocks missing\n");
1781 retval = -ENODEV; 1779 retval = -ENODEV;
1782 /* NOTE: we "know" here that refcounts on these are NOPs */ 1780 /* NOTE: we "know" here that refcounts on these are NOPs */
1783 goto fail0b; 1781 goto fail1;
1784 }
1785
1786 retval = device_register(&udc->gadget.dev);
1787 if (retval < 0) {
1788 put_device(&udc->gadget.dev);
1789 goto fail0b;
1790 } 1782 }
1791 1783
1792 /* don't do anything until we have both gadget driver and VBUS */ 1784 /* don't do anything until we have both gadget driver and VBUS */
@@ -1857,8 +1849,6 @@ fail3:
1857fail2: 1849fail2:
1858 free_irq(udc->udp_irq, udc); 1850 free_irq(udc->udp_irq, udc);
1859fail1: 1851fail1:
1860 device_unregister(&udc->gadget.dev);
1861fail0b:
1862 iounmap(udc->udp_baseaddr); 1852 iounmap(udc->udp_baseaddr);
1863fail0a: 1853fail0a:
1864 if (cpu_is_at91rm9200()) 1854 if (cpu_is_at91rm9200())
@@ -1892,8 +1882,6 @@ static int __exit at91udc_remove(struct platform_device *pdev)
1892 gpio_free(udc->board.vbus_pin); 1882 gpio_free(udc->board.vbus_pin);
1893 } 1883 }
1894 free_irq(udc->udp_irq, udc); 1884 free_irq(udc->udp_irq, udc);
1895 device_unregister(&udc->gadget.dev);
1896
1897 iounmap(udc->udp_baseaddr); 1885 iounmap(udc->udp_baseaddr);
1898 1886
1899 if (cpu_is_at91rm9200()) 1887 if (cpu_is_at91rm9200())
diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c
index b66130c97269..f2a970f75bfa 100644
--- a/drivers/usb/gadget/atmel_usba_udc.c
+++ b/drivers/usb/gadget/atmel_usba_udc.c
@@ -489,13 +489,8 @@ request_complete(struct usba_ep *ep, struct usba_request *req, int status)
489 if (req->req.status == -EINPROGRESS) 489 if (req->req.status == -EINPROGRESS)
490 req->req.status = status; 490 req->req.status = status;
491 491
492 if (req->mapped) { 492 if (req->using_dma)
493 dma_unmap_single( 493 usb_gadget_unmap_request(&udc->gadget, &req->req, ep->is_in);
494 &udc->pdev->dev, req->req.dma, req->req.length,
495 ep->is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
496 req->req.dma = DMA_ADDR_INVALID;
497 req->mapped = 0;
498 }
499 494
500 DBG(DBG_GADGET | DBG_REQ, 495 DBG(DBG_GADGET | DBG_REQ,
501 "%s: req %p complete: status %d, actual %u\n", 496 "%s: req %p complete: status %d, actual %u\n",
@@ -684,7 +679,6 @@ usba_ep_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags)
684 return NULL; 679 return NULL;
685 680
686 INIT_LIST_HEAD(&req->queue); 681 INIT_LIST_HEAD(&req->queue);
687 req->req.dma = DMA_ADDR_INVALID;
688 682
689 return &req->req; 683 return &req->req;
690} 684}
@@ -717,20 +711,11 @@ static int queue_dma(struct usba_udc *udc, struct usba_ep *ep,
717 return -EINVAL; 711 return -EINVAL;
718 } 712 }
719 713
720 req->using_dma = 1; 714 ret = usb_gadget_map_request(&udc->gadget, &req->req, ep->is_in);
721 715 if (ret)
722 if (req->req.dma == DMA_ADDR_INVALID) { 716 return ret;
723 req->req.dma = dma_map_single(
724 &udc->pdev->dev, req->req.buf, req->req.length,
725 ep->is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
726 req->mapped = 1;
727 } else {
728 dma_sync_single_for_device(
729 &udc->pdev->dev, req->req.dma, req->req.length,
730 ep->is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
731 req->mapped = 0;
732 }
733 717
718 req->using_dma = 1;
734 req->ctrl = USBA_BF(DMA_BUF_LEN, req->req.length) 719 req->ctrl = USBA_BF(DMA_BUF_LEN, req->req.length)
735 | USBA_DMA_CH_EN | USBA_DMA_END_BUF_IE 720 | USBA_DMA_CH_EN | USBA_DMA_END_BUF_IE
736 | USBA_DMA_END_TR_EN | USBA_DMA_END_TR_IE; 721 | USBA_DMA_END_TR_EN | USBA_DMA_END_TR_IE;
@@ -1799,7 +1784,6 @@ static int atmel_usba_start(struct usb_gadget *gadget,
1799 1784
1800 udc->devstatus = 1 << USB_DEVICE_SELF_POWERED; 1785 udc->devstatus = 1 << USB_DEVICE_SELF_POWERED;
1801 udc->driver = driver; 1786 udc->driver = driver;
1802 udc->gadget.dev.driver = &driver->driver;
1803 spin_unlock_irqrestore(&udc->lock, flags); 1787 spin_unlock_irqrestore(&udc->lock, flags);
1804 1788
1805 clk_enable(udc->pclk); 1789 clk_enable(udc->pclk);
@@ -1841,7 +1825,6 @@ static int atmel_usba_stop(struct usb_gadget *gadget,
1841 toggle_bias(0); 1825 toggle_bias(0);
1842 usba_writel(udc, CTRL, USBA_DISABLE_MASK); 1826 usba_writel(udc, CTRL, USBA_DISABLE_MASK);
1843 1827
1844 udc->gadget.dev.driver = NULL;
1845 udc->driver = NULL; 1828 udc->driver = NULL;
1846 1829
1847 clk_disable(udc->hclk); 1830 clk_disable(udc->hclk);
@@ -1900,10 +1883,6 @@ static int __init usba_udc_probe(struct platform_device *pdev)
1900 dev_info(&pdev->dev, "FIFO at 0x%08lx mapped at %p\n", 1883 dev_info(&pdev->dev, "FIFO at 0x%08lx mapped at %p\n",
1901 (unsigned long)fifo->start, udc->fifo); 1884 (unsigned long)fifo->start, udc->fifo);
1902 1885
1903 device_initialize(&udc->gadget.dev);
1904 udc->gadget.dev.parent = &pdev->dev;
1905 udc->gadget.dev.dma_mask = pdev->dev.dma_mask;
1906
1907 platform_set_drvdata(pdev, udc); 1886 platform_set_drvdata(pdev, udc);
1908 1887
1909 /* Make sure we start from a clean slate */ 1888 /* Make sure we start from a clean slate */
@@ -1962,12 +1941,6 @@ static int __init usba_udc_probe(struct platform_device *pdev)
1962 } 1941 }
1963 udc->irq = irq; 1942 udc->irq = irq;
1964 1943
1965 ret = device_add(&udc->gadget.dev);
1966 if (ret) {
1967 dev_dbg(&pdev->dev, "Could not add gadget: %d\n", ret);
1968 goto err_device_add;
1969 }
1970
1971 if (gpio_is_valid(pdata->vbus_pin)) { 1944 if (gpio_is_valid(pdata->vbus_pin)) {
1972 if (!gpio_request(pdata->vbus_pin, "atmel_usba_udc")) { 1945 if (!gpio_request(pdata->vbus_pin, "atmel_usba_udc")) {
1973 udc->vbus_pin = pdata->vbus_pin; 1946 udc->vbus_pin = pdata->vbus_pin;
@@ -2007,9 +1980,6 @@ err_add_udc:
2007 gpio_free(udc->vbus_pin); 1980 gpio_free(udc->vbus_pin);
2008 } 1981 }
2009 1982
2010 device_unregister(&udc->gadget.dev);
2011
2012err_device_add:
2013 free_irq(irq, udc); 1983 free_irq(irq, udc);
2014err_request_irq: 1984err_request_irq:
2015 kfree(usba_ep); 1985 kfree(usba_ep);
@@ -2053,8 +2023,6 @@ static int __exit usba_udc_remove(struct platform_device *pdev)
2053 clk_put(udc->hclk); 2023 clk_put(udc->hclk);
2054 clk_put(udc->pclk); 2024 clk_put(udc->pclk);
2055 2025
2056 device_unregister(&udc->gadget.dev);
2057
2058 return 0; 2026 return 0;
2059} 2027}
2060 2028
diff --git a/drivers/usb/gadget/atmel_usba_udc.h b/drivers/usb/gadget/atmel_usba_udc.h
index 9791259cbda7..d65a61851d3d 100644
--- a/drivers/usb/gadget/atmel_usba_udc.h
+++ b/drivers/usb/gadget/atmel_usba_udc.h
@@ -216,12 +216,6 @@
216#define EP0_EPT_SIZE USBA_EPT_SIZE_64 216#define EP0_EPT_SIZE USBA_EPT_SIZE_64
217#define EP0_NR_BANKS 1 217#define EP0_NR_BANKS 1
218 218
219/*
220 * REVISIT: Try to eliminate this value. Can we rely on req->mapped to
221 * provide this information?
222 */
223#define DMA_ADDR_INVALID (~(dma_addr_t)0)
224
225#define FIFO_IOMEM_ID 0 219#define FIFO_IOMEM_ID 0
226#define CTRL_IOMEM_ID 1 220#define CTRL_IOMEM_ID 1
227 221
diff --git a/drivers/usb/gadget/bcm63xx_udc.c b/drivers/usb/gadget/bcm63xx_udc.c
index 8cc8253f1100..6e6518264c42 100644
--- a/drivers/usb/gadget/bcm63xx_udc.c
+++ b/drivers/usb/gadget/bcm63xx_udc.c
@@ -1819,7 +1819,6 @@ static int bcm63xx_udc_start(struct usb_gadget *gadget,
1819 1819
1820 udc->driver = driver; 1820 udc->driver = driver;
1821 driver->driver.bus = NULL; 1821 driver->driver.bus = NULL;
1822 udc->gadget.dev.driver = &driver->driver;
1823 udc->gadget.dev.of_node = udc->dev->of_node; 1822 udc->gadget.dev.of_node = udc->dev->of_node;
1824 1823
1825 spin_unlock_irqrestore(&udc->lock, flags); 1824 spin_unlock_irqrestore(&udc->lock, flags);
@@ -1841,7 +1840,6 @@ static int bcm63xx_udc_stop(struct usb_gadget *gadget,
1841 spin_lock_irqsave(&udc->lock, flags); 1840 spin_lock_irqsave(&udc->lock, flags);
1842 1841
1843 udc->driver = NULL; 1842 udc->driver = NULL;
1844 udc->gadget.dev.driver = NULL;
1845 1843
1846 /* 1844 /*
1847 * If we switch the PHY too abruptly after dropping D+, the host 1845 * If we switch the PHY too abruptly after dropping D+, the host
@@ -2306,17 +2304,6 @@ static void bcm63xx_udc_cleanup_debugfs(struct bcm63xx_udc *udc)
2306 ***********************************************************************/ 2304 ***********************************************************************/
2307 2305
2308/** 2306/**
2309 * bcm63xx_udc_gadget_release - Called from device_release().
2310 * @dev: Unused.
2311 *
2312 * We get a warning if this function doesn't exist, but it's empty because
2313 * we don't have to free any of the memory allocated with the devm_* APIs.
2314 */
2315static void bcm63xx_udc_gadget_release(struct device *dev)
2316{
2317}
2318
2319/**
2320 * bcm63xx_udc_probe - Initialize a new instance of the UDC. 2307 * bcm63xx_udc_probe - Initialize a new instance of the UDC.
2321 * @pdev: Platform device struct from the bcm63xx BSP code. 2308 * @pdev: Platform device struct from the bcm63xx BSP code.
2322 * 2309 *
@@ -2368,13 +2355,9 @@ static int bcm63xx_udc_probe(struct platform_device *pdev)
2368 2355
2369 spin_lock_init(&udc->lock); 2356 spin_lock_init(&udc->lock);
2370 INIT_WORK(&udc->ep0_wq, bcm63xx_ep0_process); 2357 INIT_WORK(&udc->ep0_wq, bcm63xx_ep0_process);
2371 dev_set_name(&udc->gadget.dev, "gadget");
2372 2358
2373 udc->gadget.ops = &bcm63xx_udc_ops; 2359 udc->gadget.ops = &bcm63xx_udc_ops;
2374 udc->gadget.name = dev_name(dev); 2360 udc->gadget.name = dev_name(dev);
2375 udc->gadget.dev.parent = dev;
2376 udc->gadget.dev.release = bcm63xx_udc_gadget_release;
2377 udc->gadget.dev.dma_mask = dev->dma_mask;
2378 2361
2379 if (!pd->use_fullspeed && !use_fullspeed) 2362 if (!pd->use_fullspeed && !use_fullspeed)
2380 udc->gadget.max_speed = USB_SPEED_HIGH; 2363 udc->gadget.max_speed = USB_SPEED_HIGH;
@@ -2414,17 +2397,12 @@ static int bcm63xx_udc_probe(struct platform_device *pdev)
2414 } 2397 }
2415 } 2398 }
2416 2399
2417 rc = device_register(&udc->gadget.dev);
2418 if (rc)
2419 goto out_uninit;
2420
2421 bcm63xx_udc_init_debugfs(udc); 2400 bcm63xx_udc_init_debugfs(udc);
2422 rc = usb_add_gadget_udc(dev, &udc->gadget); 2401 rc = usb_add_gadget_udc(dev, &udc->gadget);
2423 if (!rc) 2402 if (!rc)
2424 return 0; 2403 return 0;
2425 2404
2426 bcm63xx_udc_cleanup_debugfs(udc); 2405 bcm63xx_udc_cleanup_debugfs(udc);
2427 device_unregister(&udc->gadget.dev);
2428out_uninit: 2406out_uninit:
2429 bcm63xx_uninit_udc_hw(udc); 2407 bcm63xx_uninit_udc_hw(udc);
2430 return rc; 2408 return rc;
@@ -2440,7 +2418,6 @@ static int bcm63xx_udc_remove(struct platform_device *pdev)
2440 2418
2441 bcm63xx_udc_cleanup_debugfs(udc); 2419 bcm63xx_udc_cleanup_debugfs(udc);
2442 usb_del_gadget_udc(&udc->gadget); 2420 usb_del_gadget_udc(&udc->gadget);
2443 device_unregister(&udc->gadget.dev);
2444 BUG_ON(udc->driver); 2421 BUG_ON(udc->driver);
2445 2422
2446 platform_set_drvdata(pdev, NULL); 2423 platform_set_drvdata(pdev, NULL);
diff --git a/drivers/usb/gadget/cdc2.c b/drivers/usb/gadget/cdc2.c
index a7d6f7026757..c6ee6f1558c3 100644
--- a/drivers/usb/gadget/cdc2.c
+++ b/drivers/usb/gadget/cdc2.c
@@ -103,18 +103,16 @@ static struct usb_gadget_strings *dev_strings[] = {
103}; 103};
104 104
105static u8 hostaddr[ETH_ALEN]; 105static u8 hostaddr[ETH_ALEN];
106 106static struct eth_dev *the_dev;
107/*-------------------------------------------------------------------------*/ 107/*-------------------------------------------------------------------------*/
108static struct usb_function *f_acm; 108static struct usb_function *f_acm;
109static struct usb_function_instance *fi_serial; 109static struct usb_function_instance *fi_serial;
110 110
111static unsigned char tty_line;
112/* 111/*
113 * We _always_ have both CDC ECM and CDC ACM functions. 112 * We _always_ have both CDC ECM and CDC ACM functions.
114 */ 113 */
115static int __init cdc_do_config(struct usb_configuration *c) 114static int __init cdc_do_config(struct usb_configuration *c)
116{ 115{
117 struct f_serial_opts *opts;
118 int status; 116 int status;
119 117
120 if (gadget_is_otg(c->cdev->gadget)) { 118 if (gadget_is_otg(c->cdev->gadget)) {
@@ -122,7 +120,7 @@ static int __init cdc_do_config(struct usb_configuration *c)
122 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 120 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
123 } 121 }
124 122
125 status = ecm_bind_config(c, hostaddr); 123 status = ecm_bind_config(c, hostaddr, the_dev);
126 if (status < 0) 124 if (status < 0)
127 return status; 125 return status;
128 126
@@ -130,9 +128,6 @@ static int __init cdc_do_config(struct usb_configuration *c)
130 if (IS_ERR(fi_serial)) 128 if (IS_ERR(fi_serial))
131 return PTR_ERR(fi_serial); 129 return PTR_ERR(fi_serial);
132 130
133 opts = container_of(fi_serial, struct f_serial_opts, func_inst);
134 opts->port_num = tty_line;
135
136 f_acm = usb_get_function(fi_serial); 131 f_acm = usb_get_function(fi_serial);
137 if (IS_ERR(f_acm)) 132 if (IS_ERR(f_acm))
138 goto err_func_acm; 133 goto err_func_acm;
@@ -169,14 +164,9 @@ static int __init cdc_bind(struct usb_composite_dev *cdev)
169 } 164 }
170 165
171 /* set up network link layer */ 166 /* set up network link layer */
172 status = gether_setup(cdev->gadget, hostaddr); 167 the_dev = gether_setup(cdev->gadget, hostaddr);
173 if (status < 0) 168 if (IS_ERR(the_dev))
174 return status; 169 return PTR_ERR(the_dev);
175
176 /* set up serial link layer */
177 status = gserial_alloc_line(&tty_line);
178 if (status < 0)
179 goto fail0;
180 170
181 /* Allocate string descriptor numbers ... note that string 171 /* Allocate string descriptor numbers ... note that string
182 * contents can be overridden by the composite_dev glue. 172 * contents can be overridden by the composite_dev glue.
@@ -200,9 +190,7 @@ static int __init cdc_bind(struct usb_composite_dev *cdev)
200 return 0; 190 return 0;
201 191
202fail1: 192fail1:
203 gserial_free_line(tty_line); 193 gether_cleanup(the_dev);
204fail0:
205 gether_cleanup();
206 return status; 194 return status;
207} 195}
208 196
@@ -210,8 +198,7 @@ static int __exit cdc_unbind(struct usb_composite_dev *cdev)
210{ 198{
211 usb_put_function(f_acm); 199 usb_put_function(f_acm);
212 usb_put_function_instance(fi_serial); 200 usb_put_function_instance(fi_serial);
213 gserial_free_line(tty_line); 201 gether_cleanup(the_dev);
214 gether_cleanup();
215 return 0; 202 return 0;
216} 203}
217 204
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index c0d62b278610..55f4df60f327 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -1637,6 +1637,7 @@ void composite_dev_cleanup(struct usb_composite_dev *cdev)
1637 kfree(cdev->req->buf); 1637 kfree(cdev->req->buf);
1638 usb_ep_free_request(cdev->gadget->ep0, cdev->req); 1638 usb_ep_free_request(cdev->gadget->ep0, cdev->req);
1639 } 1639 }
1640 cdev->next_string_id = 0;
1640 device_remove_file(&cdev->gadget->dev, &dev_attr_suspended); 1641 device_remove_file(&cdev->gadget->dev, &dev_attr_suspended);
1641} 1642}
1642 1643
diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
new file mode 100644
index 000000000000..a34633a898a1
--- /dev/null
+++ b/drivers/usb/gadget/configfs.c
@@ -0,0 +1,1003 @@
1#include <linux/configfs.h>
2#include <linux/module.h>
3#include <linux/slab.h>
4#include <linux/device.h>
5#include <linux/usb/composite.h>
6#include <linux/usb/gadget_configfs.h>
7
8int check_user_usb_string(const char *name,
9 struct usb_gadget_strings *stringtab_dev)
10{
11 unsigned primary_lang;
12 unsigned sub_lang;
13 u16 num;
14 int ret;
15
16 ret = kstrtou16(name, 0, &num);
17 if (ret)
18 return ret;
19
20 primary_lang = num & 0x3ff;
21 sub_lang = num >> 10;
22
23 /* simple sanity check for valid langid */
24 switch (primary_lang) {
25 case 0:
26 case 0x62 ... 0xfe:
27 case 0x100 ... 0x3ff:
28 return -EINVAL;
29 }
30 if (!sub_lang)
31 return -EINVAL;
32
33 stringtab_dev->language = num;
34 return 0;
35}
36
37#define MAX_NAME_LEN 40
38#define MAX_USB_STRING_LANGS 2
39
40struct gadget_info {
41 struct config_group group;
42 struct config_group functions_group;
43 struct config_group configs_group;
44 struct config_group strings_group;
45 struct config_group *default_groups[4];
46
47 struct mutex lock;
48 struct usb_gadget_strings *gstrings[MAX_USB_STRING_LANGS + 1];
49 struct list_head string_list;
50 struct list_head available_func;
51
52 const char *udc_name;
53#ifdef CONFIG_USB_OTG
54 struct usb_otg_descriptor otg;
55#endif
56 struct usb_composite_driver composite;
57 struct usb_composite_dev cdev;
58};
59
60struct config_usb_cfg {
61 struct config_group group;
62 struct config_group strings_group;
63 struct config_group *default_groups[2];
64 struct list_head string_list;
65 struct usb_configuration c;
66 struct list_head func_list;
67 struct usb_gadget_strings *gstrings[MAX_USB_STRING_LANGS + 1];
68};
69
70struct gadget_strings {
71 struct usb_gadget_strings stringtab_dev;
72 struct usb_string strings[USB_GADGET_FIRST_AVAIL_IDX];
73 char *manufacturer;
74 char *product;
75 char *serialnumber;
76
77 struct config_group group;
78 struct list_head list;
79};
80
81struct gadget_config_name {
82 struct usb_gadget_strings stringtab_dev;
83 struct usb_string strings;
84 char *configuration;
85
86 struct config_group group;
87 struct list_head list;
88};
89
90static int usb_string_copy(const char *s, char **s_copy)
91{
92 int ret;
93 char *str;
94 char *copy = *s_copy;
95 ret = strlen(s);
96 if (ret > 126)
97 return -EOVERFLOW;
98
99 str = kstrdup(s, GFP_KERNEL);
100 if (!str)
101 return -ENOMEM;
102 if (str[ret - 1] == '\n')
103 str[ret - 1] = '\0';
104 kfree(copy);
105 *s_copy = str;
106 return 0;
107}
108
109CONFIGFS_ATTR_STRUCT(gadget_info);
110CONFIGFS_ATTR_STRUCT(config_usb_cfg);
111
112#define GI_DEVICE_DESC_ITEM_ATTR(name) \
113 static struct gadget_info_attribute gadget_cdev_desc_##name = \
114 __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \
115 gadget_dev_desc_##name##_show, \
116 gadget_dev_desc_##name##_store)
117
118#define GI_DEVICE_DESC_SIMPLE_R_u8(__name) \
119 static ssize_t gadget_dev_desc_##__name##_show(struct gadget_info *gi, \
120 char *page) \
121{ \
122 return sprintf(page, "0x%02x\n", gi->cdev.desc.__name); \
123}
124
125#define GI_DEVICE_DESC_SIMPLE_R_u16(__name) \
126 static ssize_t gadget_dev_desc_##__name##_show(struct gadget_info *gi, \
127 char *page) \
128{ \
129 return sprintf(page, "0x%04x\n", le16_to_cpup(&gi->cdev.desc.__name)); \
130}
131
132
133#define GI_DEVICE_DESC_SIMPLE_W_u8(_name) \
134 static ssize_t gadget_dev_desc_##_name##_store(struct gadget_info *gi, \
135 const char *page, size_t len) \
136{ \
137 u8 val; \
138 int ret; \
139 ret = kstrtou8(page, 0, &val); \
140 if (ret) \
141 return ret; \
142 gi->cdev.desc._name = val; \
143 return len; \
144}
145
146#define GI_DEVICE_DESC_SIMPLE_W_u16(_name) \
147 static ssize_t gadget_dev_desc_##_name##_store(struct gadget_info *gi, \
148 const char *page, size_t len) \
149{ \
150 u16 val; \
151 int ret; \
152 ret = kstrtou16(page, 0, &val); \
153 if (ret) \
154 return ret; \
155 gi->cdev.desc._name = cpu_to_le16p(&val); \
156 return len; \
157}
158
159#define GI_DEVICE_DESC_SIMPLE_RW(_name, _type) \
160 GI_DEVICE_DESC_SIMPLE_R_##_type(_name) \
161 GI_DEVICE_DESC_SIMPLE_W_##_type(_name)
162
163GI_DEVICE_DESC_SIMPLE_R_u16(bcdUSB);
164GI_DEVICE_DESC_SIMPLE_RW(bDeviceClass, u8);
165GI_DEVICE_DESC_SIMPLE_RW(bDeviceSubClass, u8);
166GI_DEVICE_DESC_SIMPLE_RW(bDeviceProtocol, u8);
167GI_DEVICE_DESC_SIMPLE_RW(bMaxPacketSize0, u8);
168GI_DEVICE_DESC_SIMPLE_RW(idVendor, u16);
169GI_DEVICE_DESC_SIMPLE_RW(idProduct, u16);
170GI_DEVICE_DESC_SIMPLE_R_u16(bcdDevice);
171
172static ssize_t is_valid_bcd(u16 bcd_val)
173{
174 if ((bcd_val & 0xf) > 9)
175 return -EINVAL;
176 if (((bcd_val >> 4) & 0xf) > 9)
177 return -EINVAL;
178 if (((bcd_val >> 8) & 0xf) > 9)
179 return -EINVAL;
180 if (((bcd_val >> 12) & 0xf) > 9)
181 return -EINVAL;
182 return 0;
183}
184
185static ssize_t gadget_dev_desc_bcdDevice_store(struct gadget_info *gi,
186 const char *page, size_t len)
187{
188 u16 bcdDevice;
189 int ret;
190
191 ret = kstrtou16(page, 0, &bcdDevice);
192 if (ret)
193 return ret;
194 ret = is_valid_bcd(bcdDevice);
195 if (ret)
196 return ret;
197
198 gi->cdev.desc.bcdDevice = cpu_to_le16(bcdDevice);
199 return len;
200}
201
202static ssize_t gadget_dev_desc_bcdUSB_store(struct gadget_info *gi,
203 const char *page, size_t len)
204{
205 u16 bcdUSB;
206 int ret;
207
208 ret = kstrtou16(page, 0, &bcdUSB);
209 if (ret)
210 return ret;
211 ret = is_valid_bcd(bcdUSB);
212 if (ret)
213 return ret;
214
215 gi->cdev.desc.bcdUSB = cpu_to_le16(bcdUSB);
216 return len;
217}
218
219static ssize_t gadget_dev_desc_UDC_show(struct gadget_info *gi, char *page)
220{
221 return sprintf(page, "%s\n", gi->udc_name ?: "");
222}
223
224static int unregister_gadget(struct gadget_info *gi)
225{
226 int ret;
227
228 if (!gi->udc_name)
229 return -ENODEV;
230
231 ret = usb_gadget_unregister_driver(&gi->composite.gadget_driver);
232 if (ret)
233 return ret;
234 kfree(gi->udc_name);
235 gi->udc_name = NULL;
236 return 0;
237}
238
239static ssize_t gadget_dev_desc_UDC_store(struct gadget_info *gi,
240 const char *page, size_t len)
241{
242 char *name;
243 int ret;
244
245 name = kstrdup(page, GFP_KERNEL);
246 if (!name)
247 return -ENOMEM;
248 if (name[len - 1] == '\n')
249 name[len - 1] = '\0';
250
251 mutex_lock(&gi->lock);
252
253 if (!strlen(name)) {
254 ret = unregister_gadget(gi);
255 if (ret)
256 goto err;
257 } else {
258 if (gi->udc_name) {
259 ret = -EBUSY;
260 goto err;
261 }
262 ret = udc_attach_driver(name, &gi->composite.gadget_driver);
263 if (ret)
264 goto err;
265 gi->udc_name = name;
266 }
267 mutex_unlock(&gi->lock);
268 return len;
269err:
270 kfree(name);
271 mutex_unlock(&gi->lock);
272 return ret;
273}
274
275GI_DEVICE_DESC_ITEM_ATTR(bDeviceClass);
276GI_DEVICE_DESC_ITEM_ATTR(bDeviceSubClass);
277GI_DEVICE_DESC_ITEM_ATTR(bDeviceProtocol);
278GI_DEVICE_DESC_ITEM_ATTR(bMaxPacketSize0);
279GI_DEVICE_DESC_ITEM_ATTR(idVendor);
280GI_DEVICE_DESC_ITEM_ATTR(idProduct);
281GI_DEVICE_DESC_ITEM_ATTR(bcdDevice);
282GI_DEVICE_DESC_ITEM_ATTR(bcdUSB);
283GI_DEVICE_DESC_ITEM_ATTR(UDC);
284
285static struct configfs_attribute *gadget_root_attrs[] = {
286 &gadget_cdev_desc_bDeviceClass.attr,
287 &gadget_cdev_desc_bDeviceSubClass.attr,
288 &gadget_cdev_desc_bDeviceProtocol.attr,
289 &gadget_cdev_desc_bMaxPacketSize0.attr,
290 &gadget_cdev_desc_idVendor.attr,
291 &gadget_cdev_desc_idProduct.attr,
292 &gadget_cdev_desc_bcdDevice.attr,
293 &gadget_cdev_desc_bcdUSB.attr,
294 &gadget_cdev_desc_UDC.attr,
295 NULL,
296};
297
298static inline struct gadget_info *to_gadget_info(struct config_item *item)
299{
300 return container_of(to_config_group(item), struct gadget_info, group);
301}
302
303static inline struct gadget_strings *to_gadget_strings(struct config_item *item)
304{
305 return container_of(to_config_group(item), struct gadget_strings,
306 group);
307}
308
309static inline struct gadget_config_name *to_gadget_config_name(
310 struct config_item *item)
311{
312 return container_of(to_config_group(item), struct gadget_config_name,
313 group);
314}
315
316static inline struct config_usb_cfg *to_config_usb_cfg(struct config_item *item)
317{
318 return container_of(to_config_group(item), struct config_usb_cfg,
319 group);
320}
321
322static inline struct usb_function_instance *to_usb_function_instance(
323 struct config_item *item)
324{
325 return container_of(to_config_group(item),
326 struct usb_function_instance, group);
327}
328
329static void gadget_info_attr_release(struct config_item *item)
330{
331 struct gadget_info *gi = to_gadget_info(item);
332
333 WARN_ON(!list_empty(&gi->cdev.configs));
334 WARN_ON(!list_empty(&gi->string_list));
335 WARN_ON(!list_empty(&gi->available_func));
336 kfree(gi->composite.gadget_driver.function);
337 kfree(gi);
338}
339
340CONFIGFS_ATTR_OPS(gadget_info);
341
342static struct configfs_item_operations gadget_root_item_ops = {
343 .release = gadget_info_attr_release,
344 .show_attribute = gadget_info_attr_show,
345 .store_attribute = gadget_info_attr_store,
346};
347
348static void gadget_config_attr_release(struct config_item *item)
349{
350 struct config_usb_cfg *cfg = to_config_usb_cfg(item);
351
352 WARN_ON(!list_empty(&cfg->c.functions));
353 list_del(&cfg->c.list);
354 kfree(cfg->c.label);
355 kfree(cfg);
356}
357
358static int config_usb_cfg_link(
359 struct config_item *usb_cfg_ci,
360 struct config_item *usb_func_ci)
361{
362 struct config_usb_cfg *cfg = to_config_usb_cfg(usb_cfg_ci);
363 struct usb_composite_dev *cdev = cfg->c.cdev;
364 struct gadget_info *gi = container_of(cdev, struct gadget_info, cdev);
365
366 struct config_group *group = to_config_group(usb_func_ci);
367 struct usb_function_instance *fi = container_of(group,
368 struct usb_function_instance, group);
369 struct usb_function_instance *a_fi;
370 struct usb_function *f;
371 int ret;
372
373 mutex_lock(&gi->lock);
374 /*
375 * Make sure this function is from within our _this_ gadget and not
376 * from another gadget or a random directory.
377 * Also a function instance can only be linked once.
378 */
379 list_for_each_entry(a_fi, &gi->available_func, cfs_list) {
380 if (a_fi == fi)
381 break;
382 }
383 if (a_fi != fi) {
384 ret = -EINVAL;
385 goto out;
386 }
387
388 list_for_each_entry(f, &cfg->func_list, list) {
389 if (f->fi == fi) {
390 ret = -EEXIST;
391 goto out;
392 }
393 }
394
395 f = usb_get_function(fi);
396 if (IS_ERR(f)) {
397 ret = PTR_ERR(f);
398 goto out;
399 }
400
401 /* stash the function until we bind it to the gadget */
402 list_add_tail(&f->list, &cfg->func_list);
403 ret = 0;
404out:
405 mutex_unlock(&gi->lock);
406 return ret;
407}
408
409static int config_usb_cfg_unlink(
410 struct config_item *usb_cfg_ci,
411 struct config_item *usb_func_ci)
412{
413 struct config_usb_cfg *cfg = to_config_usb_cfg(usb_cfg_ci);
414 struct usb_composite_dev *cdev = cfg->c.cdev;
415 struct gadget_info *gi = container_of(cdev, struct gadget_info, cdev);
416
417 struct config_group *group = to_config_group(usb_func_ci);
418 struct usb_function_instance *fi = container_of(group,
419 struct usb_function_instance, group);
420 struct usb_function *f;
421
422 /*
423 * ideally I would like to forbid to unlink functions while a gadget is
424 * bound to an UDC. Since this isn't possible at the moment, we simply
425 * force an unbind, the function is available here and then we can
426 * remove the function.
427 */
428 mutex_lock(&gi->lock);
429 if (gi->udc_name)
430 unregister_gadget(gi);
431 WARN_ON(gi->udc_name);
432
433 list_for_each_entry(f, &cfg->func_list, list) {
434 if (f->fi == fi) {
435 list_del(&f->list);
436 usb_put_function(f);
437 mutex_unlock(&gi->lock);
438 return 0;
439 }
440 }
441 mutex_unlock(&gi->lock);
442 __WARN_printf("Unable to locate function to unbind\n");
443 return 0;
444}
445
446CONFIGFS_ATTR_OPS(config_usb_cfg);
447
448static struct configfs_item_operations gadget_config_item_ops = {
449 .release = gadget_config_attr_release,
450 .show_attribute = config_usb_cfg_attr_show,
451 .store_attribute = config_usb_cfg_attr_store,
452 .allow_link = config_usb_cfg_link,
453 .drop_link = config_usb_cfg_unlink,
454};
455
456
457static ssize_t gadget_config_desc_MaxPower_show(struct config_usb_cfg *cfg,
458 char *page)
459{
460 return sprintf(page, "%u\n", cfg->c.MaxPower);
461}
462
463static ssize_t gadget_config_desc_MaxPower_store(struct config_usb_cfg *cfg,
464 const char *page, size_t len)
465{
466 u16 val;
467 int ret;
468 ret = kstrtou16(page, 0, &val);
469 if (ret)
470 return ret;
471 if (DIV_ROUND_UP(val, 8) > 0xff)
472 return -ERANGE;
473 cfg->c.MaxPower = val;
474 return len;
475}
476
477static ssize_t gadget_config_desc_bmAttributes_show(struct config_usb_cfg *cfg,
478 char *page)
479{
480 return sprintf(page, "0x%02x\n", cfg->c.bmAttributes);
481}
482
483static ssize_t gadget_config_desc_bmAttributes_store(struct config_usb_cfg *cfg,
484 const char *page, size_t len)
485{
486 u8 val;
487 int ret;
488 ret = kstrtou8(page, 0, &val);
489 if (ret)
490 return ret;
491 if (!(val & USB_CONFIG_ATT_ONE))
492 return -EINVAL;
493 if (val & ~(USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER |
494 USB_CONFIG_ATT_WAKEUP))
495 return -EINVAL;
496 cfg->c.bmAttributes = val;
497 return len;
498}
499
500#define CFG_CONFIG_DESC_ITEM_ATTR(name) \
501 static struct config_usb_cfg_attribute gadget_usb_cfg_##name = \
502 __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \
503 gadget_config_desc_##name##_show, \
504 gadget_config_desc_##name##_store)
505
506CFG_CONFIG_DESC_ITEM_ATTR(MaxPower);
507CFG_CONFIG_DESC_ITEM_ATTR(bmAttributes);
508
509static struct configfs_attribute *gadget_config_attrs[] = {
510 &gadget_usb_cfg_MaxPower.attr,
511 &gadget_usb_cfg_bmAttributes.attr,
512 NULL,
513};
514
515static struct config_item_type gadget_config_type = {
516 .ct_item_ops = &gadget_config_item_ops,
517 .ct_attrs = gadget_config_attrs,
518 .ct_owner = THIS_MODULE,
519};
520
521static struct config_item_type gadget_root_type = {
522 .ct_item_ops = &gadget_root_item_ops,
523 .ct_attrs = gadget_root_attrs,
524 .ct_owner = THIS_MODULE,
525};
526
527static void composite_init_dev(struct usb_composite_dev *cdev)
528{
529 spin_lock_init(&cdev->lock);
530 INIT_LIST_HEAD(&cdev->configs);
531 INIT_LIST_HEAD(&cdev->gstrings);
532}
533
534static struct config_group *function_make(
535 struct config_group *group,
536 const char *name)
537{
538 struct gadget_info *gi;
539 struct usb_function_instance *fi;
540 char buf[MAX_NAME_LEN];
541 char *func_name;
542 char *instance_name;
543 int ret;
544
545 ret = snprintf(buf, MAX_NAME_LEN, "%s", name);
546 if (ret >= MAX_NAME_LEN)
547 return ERR_PTR(-ENAMETOOLONG);
548
549 func_name = buf;
550 instance_name = strchr(func_name, '.');
551 if (!instance_name) {
552 pr_err("Unable to locate . in FUNC.INSTANCE\n");
553 return ERR_PTR(-EINVAL);
554 }
555 *instance_name = '\0';
556 instance_name++;
557
558 fi = usb_get_function_instance(func_name);
559 if (IS_ERR(fi))
560 return ERR_PTR(PTR_ERR(fi));
561
562 ret = config_item_set_name(&fi->group.cg_item, name);
563 if (ret) {
564 usb_put_function_instance(fi);
565 return ERR_PTR(ret);
566 }
567
568 gi = container_of(group, struct gadget_info, functions_group);
569
570 mutex_lock(&gi->lock);
571 list_add_tail(&fi->cfs_list, &gi->available_func);
572 mutex_unlock(&gi->lock);
573 return &fi->group;
574}
575
576static void function_drop(
577 struct config_group *group,
578 struct config_item *item)
579{
580 struct usb_function_instance *fi = to_usb_function_instance(item);
581 struct gadget_info *gi;
582
583 gi = container_of(group, struct gadget_info, functions_group);
584
585 mutex_lock(&gi->lock);
586 list_del(&fi->cfs_list);
587 mutex_unlock(&gi->lock);
588 config_item_put(item);
589}
590
591static struct configfs_group_operations functions_ops = {
592 .make_group = &function_make,
593 .drop_item = &function_drop,
594};
595
596static struct config_item_type functions_type = {
597 .ct_group_ops = &functions_ops,
598 .ct_owner = THIS_MODULE,
599};
600
601CONFIGFS_ATTR_STRUCT(gadget_config_name);
602GS_STRINGS_RW(gadget_config_name, configuration);
603
604static struct configfs_attribute *gadget_config_name_langid_attrs[] = {
605 &gadget_config_name_configuration.attr,
606 NULL,
607};
608
609static void gadget_config_name_attr_release(struct config_item *item)
610{
611 struct gadget_config_name *cn = to_gadget_config_name(item);
612
613 kfree(cn->configuration);
614
615 list_del(&cn->list);
616 kfree(cn);
617}
618
619USB_CONFIG_STRING_RW_OPS(gadget_config_name);
620USB_CONFIG_STRINGS_LANG(gadget_config_name, config_usb_cfg);
621
622static struct config_group *config_desc_make(
623 struct config_group *group,
624 const char *name)
625{
626 struct gadget_info *gi;
627 struct config_usb_cfg *cfg;
628 char buf[MAX_NAME_LEN];
629 char *num_str;
630 u8 num;
631 int ret;
632
633 gi = container_of(group, struct gadget_info, configs_group);
634 ret = snprintf(buf, MAX_NAME_LEN, "%s", name);
635 if (ret >= MAX_NAME_LEN)
636 return ERR_PTR(-ENAMETOOLONG);
637
638 num_str = strchr(buf, '.');
639 if (!num_str) {
640 pr_err("Unable to locate . in name.bConfigurationValue\n");
641 return ERR_PTR(-EINVAL);
642 }
643
644 *num_str = '\0';
645 num_str++;
646
647 if (!strlen(buf))
648 return ERR_PTR(-EINVAL);
649
650 ret = kstrtou8(num_str, 0, &num);
651 if (ret)
652 return ERR_PTR(ret);
653
654 cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
655 if (!cfg)
656 return ERR_PTR(-ENOMEM);
657 cfg->c.label = kstrdup(buf, GFP_KERNEL);
658 if (!cfg->c.label) {
659 ret = -ENOMEM;
660 goto err;
661 }
662 cfg->c.bConfigurationValue = num;
663 cfg->c.MaxPower = CONFIG_USB_GADGET_VBUS_DRAW;
664 cfg->c.bmAttributes = USB_CONFIG_ATT_ONE;
665 INIT_LIST_HEAD(&cfg->string_list);
666 INIT_LIST_HEAD(&cfg->func_list);
667
668 cfg->group.default_groups = cfg->default_groups;
669 cfg->default_groups[0] = &cfg->strings_group;
670
671 config_group_init_type_name(&cfg->group, name,
672 &gadget_config_type);
673 config_group_init_type_name(&cfg->strings_group, "strings",
674 &gadget_config_name_strings_type);
675
676 ret = usb_add_config_only(&gi->cdev, &cfg->c);
677 if (ret)
678 goto err;
679
680 return &cfg->group;
681err:
682 kfree(cfg->c.label);
683 kfree(cfg);
684 return ERR_PTR(ret);
685}
686
687static void config_desc_drop(
688 struct config_group *group,
689 struct config_item *item)
690{
691 config_item_put(item);
692}
693
694static struct configfs_group_operations config_desc_ops = {
695 .make_group = &config_desc_make,
696 .drop_item = &config_desc_drop,
697};
698
699static struct config_item_type config_desc_type = {
700 .ct_group_ops = &config_desc_ops,
701 .ct_owner = THIS_MODULE,
702};
703
704CONFIGFS_ATTR_STRUCT(gadget_strings);
705GS_STRINGS_RW(gadget_strings, manufacturer);
706GS_STRINGS_RW(gadget_strings, product);
707GS_STRINGS_RW(gadget_strings, serialnumber);
708
709static struct configfs_attribute *gadget_strings_langid_attrs[] = {
710 &gadget_strings_manufacturer.attr,
711 &gadget_strings_product.attr,
712 &gadget_strings_serialnumber.attr,
713 NULL,
714};
715
716static void gadget_strings_attr_release(struct config_item *item)
717{
718 struct gadget_strings *gs = to_gadget_strings(item);
719
720 kfree(gs->manufacturer);
721 kfree(gs->product);
722 kfree(gs->serialnumber);
723
724 list_del(&gs->list);
725 kfree(gs);
726}
727
728USB_CONFIG_STRING_RW_OPS(gadget_strings);
729USB_CONFIG_STRINGS_LANG(gadget_strings, gadget_info);
730
731static int configfs_do_nothing(struct usb_composite_dev *cdev)
732{
733 __WARN();
734 return -EINVAL;
735}
736
737int composite_dev_prepare(struct usb_composite_driver *composite,
738 struct usb_composite_dev *dev);
739
740static void purge_configs_funcs(struct gadget_info *gi)
741{
742 struct usb_configuration *c;
743
744 list_for_each_entry(c, &gi->cdev.configs, list) {
745 struct usb_function *f, *tmp;
746 struct config_usb_cfg *cfg;
747
748 cfg = container_of(c, struct config_usb_cfg, c);
749
750 list_for_each_entry_safe(f, tmp, &c->functions, list) {
751
752 list_move_tail(&f->list, &cfg->func_list);
753 if (f->unbind) {
754 dev_err(&gi->cdev.gadget->dev, "unbind function"
755 " '%s'/%p\n", f->name, f);
756 f->unbind(c, f);
757 }
758 }
759 c->next_interface_id = 0;
760 c->superspeed = 0;
761 c->highspeed = 0;
762 c->fullspeed = 0;
763 }
764}
765
766static int configfs_composite_bind(struct usb_gadget *gadget,
767 struct usb_gadget_driver *gdriver)
768{
769 struct usb_composite_driver *composite = to_cdriver(gdriver);
770 struct gadget_info *gi = container_of(composite,
771 struct gadget_info, composite);
772 struct usb_composite_dev *cdev = &gi->cdev;
773 struct usb_configuration *c;
774 struct usb_string *s;
775 unsigned i;
776 int ret;
777
778 /* the gi->lock is hold by the caller */
779 cdev->gadget = gadget;
780 set_gadget_data(gadget, cdev);
781 ret = composite_dev_prepare(composite, cdev);
782 if (ret)
783 return ret;
784 /* and now the gadget bind */
785 ret = -EINVAL;
786
787 if (list_empty(&gi->cdev.configs)) {
788 pr_err("Need atleast one configuration in %s.\n",
789 gi->composite.name);
790 goto err_comp_cleanup;
791 }
792
793
794 list_for_each_entry(c, &gi->cdev.configs, list) {
795 struct config_usb_cfg *cfg;
796
797 cfg = container_of(c, struct config_usb_cfg, c);
798 if (list_empty(&cfg->func_list)) {
799 pr_err("Config %s/%d of %s needs atleast one function.\n",
800 c->label, c->bConfigurationValue,
801 gi->composite.name);
802 goto err_comp_cleanup;
803 }
804 }
805
806 /* init all strings */
807 if (!list_empty(&gi->string_list)) {
808 struct gadget_strings *gs;
809
810 i = 0;
811 list_for_each_entry(gs, &gi->string_list, list) {
812
813 gi->gstrings[i] = &gs->stringtab_dev;
814 gs->stringtab_dev.strings = gs->strings;
815 gs->strings[USB_GADGET_MANUFACTURER_IDX].s =
816 gs->manufacturer;
817 gs->strings[USB_GADGET_PRODUCT_IDX].s = gs->product;
818 gs->strings[USB_GADGET_SERIAL_IDX].s = gs->serialnumber;
819 i++;
820 }
821 gi->gstrings[i] = NULL;
822 s = usb_gstrings_attach(&gi->cdev, gi->gstrings,
823 USB_GADGET_FIRST_AVAIL_IDX);
824 if (IS_ERR(s))
825 goto err_comp_cleanup;
826
827 gi->cdev.desc.iManufacturer = s[USB_GADGET_MANUFACTURER_IDX].id;
828 gi->cdev.desc.iProduct = s[USB_GADGET_PRODUCT_IDX].id;
829 gi->cdev.desc.iSerialNumber = s[USB_GADGET_SERIAL_IDX].id;
830 }
831
832 /* Go through all configs, attach all functions */
833 list_for_each_entry(c, &gi->cdev.configs, list) {
834 struct config_usb_cfg *cfg;
835 struct usb_function *f;
836 struct usb_function *tmp;
837 struct gadget_config_name *cn;
838
839 cfg = container_of(c, struct config_usb_cfg, c);
840 if (!list_empty(&cfg->string_list)) {
841 i = 0;
842 list_for_each_entry(cn, &cfg->string_list, list) {
843 cfg->gstrings[i] = &cn->stringtab_dev;
844 cn->stringtab_dev.strings = &cn->strings;
845 cn->strings.s = cn->configuration;
846 i++;
847 }
848 cfg->gstrings[i] = NULL;
849 s = usb_gstrings_attach(&gi->cdev, cfg->gstrings, 1);
850 if (IS_ERR(s))
851 goto err_comp_cleanup;
852 c->iConfiguration = s[0].id;
853 }
854
855 list_for_each_entry_safe(f, tmp, &cfg->func_list, list) {
856 list_del(&f->list);
857 ret = usb_add_function(c, f);
858 if (ret)
859 goto err_purge_funcs;
860 }
861 usb_ep_autoconfig_reset(cdev->gadget);
862 }
863 usb_ep_autoconfig_reset(cdev->gadget);
864 return 0;
865
866err_purge_funcs:
867 purge_configs_funcs(gi);
868err_comp_cleanup:
869 composite_dev_cleanup(cdev);
870 return ret;
871}
872
873static void configfs_composite_unbind(struct usb_gadget *gadget)
874{
875 struct usb_composite_dev *cdev;
876 struct gadget_info *gi;
877
878 /* the gi->lock is hold by the caller */
879
880 cdev = get_gadget_data(gadget);
881 gi = container_of(cdev, struct gadget_info, cdev);
882
883 purge_configs_funcs(gi);
884 composite_dev_cleanup(cdev);
885 usb_ep_autoconfig_reset(cdev->gadget);
886 cdev->gadget = NULL;
887 set_gadget_data(gadget, NULL);
888}
889
890static const struct usb_gadget_driver configfs_driver_template = {
891 .bind = configfs_composite_bind,
892 .unbind = configfs_composite_unbind,
893
894 .setup = composite_setup,
895 .disconnect = composite_disconnect,
896
897 .max_speed = USB_SPEED_SUPER,
898 .driver = {
899 .owner = THIS_MODULE,
900 .name = "configfs-gadget",
901 },
902};
903
904static struct config_group *gadgets_make(
905 struct config_group *group,
906 const char *name)
907{
908 struct gadget_info *gi;
909
910 gi = kzalloc(sizeof(*gi), GFP_KERNEL);
911 if (!gi)
912 return ERR_PTR(-ENOMEM);
913
914 gi->group.default_groups = gi->default_groups;
915 gi->group.default_groups[0] = &gi->functions_group;
916 gi->group.default_groups[1] = &gi->configs_group;
917 gi->group.default_groups[2] = &gi->strings_group;
918
919 config_group_init_type_name(&gi->functions_group, "functions",
920 &functions_type);
921 config_group_init_type_name(&gi->configs_group, "configs",
922 &config_desc_type);
923 config_group_init_type_name(&gi->strings_group, "strings",
924 &gadget_strings_strings_type);
925
926 gi->composite.bind = configfs_do_nothing;
927 gi->composite.unbind = configfs_do_nothing;
928 gi->composite.suspend = NULL;
929 gi->composite.resume = NULL;
930 gi->composite.max_speed = USB_SPEED_SUPER;
931
932 mutex_init(&gi->lock);
933 INIT_LIST_HEAD(&gi->string_list);
934 INIT_LIST_HEAD(&gi->available_func);
935
936 composite_init_dev(&gi->cdev);
937 gi->cdev.desc.bLength = USB_DT_DEVICE_SIZE;
938 gi->cdev.desc.bDescriptorType = USB_DT_DEVICE;
939 gi->cdev.desc.bcdDevice = cpu_to_le16(get_default_bcdDevice());
940
941 gi->composite.gadget_driver = configfs_driver_template;
942
943 gi->composite.gadget_driver.function = kstrdup(name, GFP_KERNEL);
944 gi->composite.name = gi->composite.gadget_driver.function;
945
946 if (!gi->composite.gadget_driver.function)
947 goto err;
948
949#ifdef CONFIG_USB_OTG
950 gi->otg.bLength = sizeof(struct usb_otg_descriptor);
951 gi->otg.bDescriptorType = USB_DT_OTG;
952 gi->otg.bmAttributes = USB_OTG_SRP | USB_OTG_HNP;
953#endif
954
955 config_group_init_type_name(&gi->group, name,
956 &gadget_root_type);
957 return &gi->group;
958err:
959 kfree(gi);
960 return ERR_PTR(-ENOMEM);
961}
962
963static void gadgets_drop(struct config_group *group, struct config_item *item)
964{
965 config_item_put(item);
966}
967
968static struct configfs_group_operations gadgets_ops = {
969 .make_group = &gadgets_make,
970 .drop_item = &gadgets_drop,
971};
972
973static struct config_item_type gadgets_type = {
974 .ct_group_ops = &gadgets_ops,
975 .ct_owner = THIS_MODULE,
976};
977
978static struct configfs_subsystem gadget_subsys = {
979 .su_group = {
980 .cg_item = {
981 .ci_namebuf = "usb_gadget",
982 .ci_type = &gadgets_type,
983 },
984 },
985 .su_mutex = __MUTEX_INITIALIZER(gadget_subsys.su_mutex),
986};
987
988static int __init gadget_cfs_init(void)
989{
990 int ret;
991
992 config_group_init(&gadget_subsys.su_group);
993
994 ret = configfs_register_subsystem(&gadget_subsys);
995 return ret;
996}
997module_init(gadget_cfs_init);
998
999static void __exit gadget_cfs_exit(void)
1000{
1001 configfs_unregister_subsystem(&gadget_subsys);
1002}
1003module_exit(gadget_cfs_exit);
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index 8cf0c0f6fa1f..a792e322f4f1 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -912,7 +912,6 @@ static int dummy_udc_start(struct usb_gadget *g,
912 dum->devstatus = 0; 912 dum->devstatus = 0;
913 913
914 dum->driver = driver; 914 dum->driver = driver;
915 dum->gadget.dev.driver = &driver->driver;
916 dev_dbg(udc_dev(dum), "binding gadget driver '%s'\n", 915 dev_dbg(udc_dev(dum), "binding gadget driver '%s'\n",
917 driver->driver.name); 916 driver->driver.name);
918 return 0; 917 return 0;
@@ -927,7 +926,6 @@ static int dummy_udc_stop(struct usb_gadget *g,
927 dev_dbg(udc_dev(dum), "unregister gadget driver '%s'\n", 926 dev_dbg(udc_dev(dum), "unregister gadget driver '%s'\n",
928 driver->driver.name); 927 driver->driver.name);
929 928
930 dum->gadget.dev.driver = NULL;
931 dum->driver = NULL; 929 dum->driver = NULL;
932 930
933 return 0; 931 return 0;
@@ -937,11 +935,6 @@ static int dummy_udc_stop(struct usb_gadget *g,
937 935
938/* The gadget structure is stored inside the hcd structure and will be 936/* The gadget structure is stored inside the hcd structure and will be
939 * released along with it. */ 937 * released along with it. */
940static void dummy_gadget_release(struct device *dev)
941{
942 return;
943}
944
945static void init_dummy_udc_hw(struct dummy *dum) 938static void init_dummy_udc_hw(struct dummy *dum)
946{ 939{
947 int i; 940 int i;
@@ -984,15 +977,7 @@ static int dummy_udc_probe(struct platform_device *pdev)
984 dum->gadget.ops = &dummy_ops; 977 dum->gadget.ops = &dummy_ops;
985 dum->gadget.max_speed = USB_SPEED_SUPER; 978 dum->gadget.max_speed = USB_SPEED_SUPER;
986 979
987 dev_set_name(&dum->gadget.dev, "gadget");
988 dum->gadget.dev.parent = &pdev->dev; 980 dum->gadget.dev.parent = &pdev->dev;
989 dum->gadget.dev.release = dummy_gadget_release;
990 rc = device_register(&dum->gadget.dev);
991 if (rc < 0) {
992 put_device(&dum->gadget.dev);
993 return rc;
994 }
995
996 init_dummy_udc_hw(dum); 981 init_dummy_udc_hw(dum);
997 982
998 rc = usb_add_gadget_udc(&pdev->dev, &dum->gadget); 983 rc = usb_add_gadget_udc(&pdev->dev, &dum->gadget);
@@ -1008,7 +993,6 @@ static int dummy_udc_probe(struct platform_device *pdev)
1008err_dev: 993err_dev:
1009 usb_del_gadget_udc(&dum->gadget); 994 usb_del_gadget_udc(&dum->gadget);
1010err_udc: 995err_udc:
1011 device_unregister(&dum->gadget.dev);
1012 return rc; 996 return rc;
1013} 997}
1014 998
@@ -1019,7 +1003,6 @@ static int dummy_udc_remove(struct platform_device *pdev)
1019 usb_del_gadget_udc(&dum->gadget); 1003 usb_del_gadget_udc(&dum->gadget);
1020 platform_set_drvdata(pdev, NULL); 1004 platform_set_drvdata(pdev, NULL);
1021 device_remove_file(&dum->gadget.dev, &dev_attr_function); 1005 device_remove_file(&dum->gadget.dev, &dev_attr_function);
1022 device_unregister(&dum->gadget.dev);
1023 return 0; 1006 return 0;
1024} 1007}
1025 1008
@@ -1923,7 +1906,7 @@ done:
1923} 1906}
1924 1907
1925/* usb 3.0 root hub device descriptor */ 1908/* usb 3.0 root hub device descriptor */
1926struct { 1909static struct {
1927 struct usb_bos_descriptor bos; 1910 struct usb_bos_descriptor bos;
1928 struct usb_ss_cap_descriptor ss_cap; 1911 struct usb_ss_cap_descriptor ss_cap;
1929} __packed usb3_bos_desc = { 1912} __packed usb3_bos_desc = {
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 18c3f423706e..56c8ecae9bc3 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -207,7 +207,7 @@ static struct usb_gadget_strings *dev_strings[] = {
207}; 207};
208 208
209static u8 hostaddr[ETH_ALEN]; 209static u8 hostaddr[ETH_ALEN];
210 210static struct eth_dev *the_dev;
211/*-------------------------------------------------------------------------*/ 211/*-------------------------------------------------------------------------*/
212 212
213/* 213/*
@@ -224,7 +224,7 @@ static int __init rndis_do_config(struct usb_configuration *c)
224 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 224 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
225 } 225 }
226 226
227 return rndis_bind_config(c, hostaddr); 227 return rndis_bind_config(c, hostaddr, the_dev);
228} 228}
229 229
230static struct usb_configuration rndis_config_driver = { 230static struct usb_configuration rndis_config_driver = {
@@ -257,11 +257,11 @@ static int __init eth_do_config(struct usb_configuration *c)
257 } 257 }
258 258
259 if (use_eem) 259 if (use_eem)
260 return eem_bind_config(c); 260 return eem_bind_config(c, the_dev);
261 else if (can_support_ecm(c->cdev->gadget)) 261 else if (can_support_ecm(c->cdev->gadget))
262 return ecm_bind_config(c, hostaddr); 262 return ecm_bind_config(c, hostaddr, the_dev);
263 else 263 else
264 return geth_bind_config(c, hostaddr); 264 return geth_bind_config(c, hostaddr, the_dev);
265} 265}
266 266
267static struct usb_configuration eth_config_driver = { 267static struct usb_configuration eth_config_driver = {
@@ -279,9 +279,9 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
279 int status; 279 int status;
280 280
281 /* set up network link layer */ 281 /* set up network link layer */
282 status = gether_setup(cdev->gadget, hostaddr); 282 the_dev = gether_setup(cdev->gadget, hostaddr);
283 if (status < 0) 283 if (IS_ERR(the_dev))
284 return status; 284 return PTR_ERR(the_dev);
285 285
286 /* set up main config label and device descriptor */ 286 /* set up main config label and device descriptor */
287 if (use_eem) { 287 if (use_eem) {
@@ -338,13 +338,13 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
338 return 0; 338 return 0;
339 339
340fail: 340fail:
341 gether_cleanup(); 341 gether_cleanup(the_dev);
342 return status; 342 return status;
343} 343}
344 344
345static int __exit eth_unbind(struct usb_composite_dev *cdev) 345static int __exit eth_unbind(struct usb_composite_dev *cdev)
346{ 346{
347 gether_cleanup(); 347 gether_cleanup(the_dev);
348 return 0; 348 return 0;
349} 349}
350 350
diff --git a/drivers/usb/gadget/f_acm.c b/drivers/usb/gadget/f_acm.c
index 1ae180baa597..4b7e33e5d9c6 100644
--- a/drivers/usb/gadget/f_acm.c
+++ b/drivers/usb/gadget/f_acm.c
@@ -715,13 +715,31 @@ fail:
715 return status; 715 return status;
716} 716}
717 717
718static struct f_acm *acm_alloc_basic_func(void) 718static void acm_unbind(struct usb_configuration *c, struct usb_function *f)
719{
720 struct f_acm *acm = func_to_acm(f);
721
722 acm_string_defs[0].id = 0;
723 usb_free_all_descriptors(f);
724 if (acm->notify_req)
725 gs_free_req(acm->notify, acm->notify_req);
726}
727
728static void acm_free_func(struct usb_function *f)
729{
730 struct f_acm *acm = func_to_acm(f);
731
732 kfree(acm);
733}
734
735static struct usb_function *acm_alloc_func(struct usb_function_instance *fi)
719{ 736{
720 struct f_acm *acm; 737 struct f_serial_opts *opts;
738 struct f_acm *acm;
721 739
722 acm = kzalloc(sizeof(*acm), GFP_KERNEL); 740 acm = kzalloc(sizeof(*acm), GFP_KERNEL);
723 if (!acm) 741 if (!acm)
724 return NULL; 742 return ERR_PTR(-ENOMEM);
725 743
726 spin_lock_init(&acm->lock); 744 spin_lock_init(&acm->lock);
727 745
@@ -730,109 +748,100 @@ static struct f_acm *acm_alloc_basic_func(void)
730 acm->port.send_break = acm_send_break; 748 acm->port.send_break = acm_send_break;
731 749
732 acm->port.func.name = "acm"; 750 acm->port.func.name = "acm";
751 acm->port.func.strings = acm_strings;
733 /* descriptors are per-instance copies */ 752 /* descriptors are per-instance copies */
734 acm->port.func.bind = acm_bind; 753 acm->port.func.bind = acm_bind;
735 acm->port.func.set_alt = acm_set_alt; 754 acm->port.func.set_alt = acm_set_alt;
736 acm->port.func.setup = acm_setup; 755 acm->port.func.setup = acm_setup;
737 acm->port.func.disable = acm_disable; 756 acm->port.func.disable = acm_disable;
738 757
739 return acm; 758 opts = container_of(fi, struct f_serial_opts, func_inst);
759 acm->port_num = opts->port_num;
760 acm->port.func.unbind = acm_unbind;
761 acm->port.func.free_func = acm_free_func;
762
763 return &acm->port.func;
740} 764}
741 765
742#ifdef USB_FACM_INCLUDED 766static inline struct f_serial_opts *to_f_serial_opts(struct config_item *item)
743static void
744acm_old_unbind(struct usb_configuration *c, struct usb_function *f)
745{ 767{
746 struct f_acm *acm = func_to_acm(f); 768 return container_of(to_config_group(item), struct f_serial_opts,
747 769 func_inst.group);
748 usb_free_all_descriptors(f);
749 if (acm->notify_req)
750 gs_free_req(acm->notify, acm->notify_req);
751 kfree(acm);
752} 770}
753 771
754/** 772CONFIGFS_ATTR_STRUCT(f_serial_opts);
755 * acm_bind_config - add a CDC ACM function to a configuration 773static ssize_t f_acm_attr_show(struct config_item *item,
756 * @c: the configuration to support the CDC ACM instance 774 struct configfs_attribute *attr,
757 * @port_num: /dev/ttyGS* port this interface will use 775 char *page)
758 * Context: single threaded during gadget setup
759 *
760 * Returns zero on success, else negative errno.
761 *
762 */
763int acm_bind_config(struct usb_configuration *c, u8 port_num)
764{ 776{
765 struct f_acm *acm; 777 struct f_serial_opts *opts = to_f_serial_opts(item);
766 int status; 778 struct f_serial_opts_attribute *f_serial_opts_attr =
767 779 container_of(attr, struct f_serial_opts_attribute, attr);
768 /* allocate and initialize one new instance */ 780 ssize_t ret = 0;
769 acm = acm_alloc_basic_func(); 781
770 if (!acm) 782 if (f_serial_opts_attr->show)
771 return -ENOMEM; 783 ret = f_serial_opts_attr->show(opts, page);
772 784 return ret;
773 acm->port_num = port_num;
774 acm->port.func.unbind = acm_old_unbind;
775
776 status = usb_add_function(c, &acm->port.func);
777 if (status)
778 kfree(acm);
779 return status;
780} 785}
781 786
782#else 787static void acm_attr_release(struct config_item *item)
783
784static void acm_unbind(struct usb_configuration *c, struct usb_function *f)
785{ 788{
786 struct f_acm *acm = func_to_acm(f); 789 struct f_serial_opts *opts = to_f_serial_opts(item);
787 790
788 acm_string_defs[0].id = 0; 791 usb_put_function_instance(&opts->func_inst);
789 usb_free_all_descriptors(f);
790 if (acm->notify_req)
791 gs_free_req(acm->notify, acm->notify_req);
792} 792}
793 793
794static void acm_free_func(struct usb_function *f) 794static struct configfs_item_operations acm_item_ops = {
795{ 795 .release = acm_attr_release,
796 struct f_acm *acm = func_to_acm(f); 796 .show_attribute = f_acm_attr_show,
797};
797 798
798 kfree(acm); 799static ssize_t f_acm_port_num_show(struct f_serial_opts *opts, char *page)
800{
801 return sprintf(page, "%u\n", opts->port_num);
799} 802}
800 803
801static struct usb_function *acm_alloc_func(struct usb_function_instance *fi) 804static struct f_serial_opts_attribute f_acm_port_num =
802{ 805 __CONFIGFS_ATTR_RO(port_num, f_acm_port_num_show);
803 struct f_serial_opts *opts;
804 struct f_acm *acm;
805 806
806 acm = acm_alloc_basic_func();
807 if (!acm)
808 return ERR_PTR(-ENOMEM);
809 807
810 opts = container_of(fi, struct f_serial_opts, func_inst); 808static struct configfs_attribute *acm_attrs[] = {
811 acm->port_num = opts->port_num; 809 &f_acm_port_num.attr,
812 acm->port.func.unbind = acm_unbind; 810 NULL,
813 acm->port.func.free_func = acm_free_func; 811};
814 812
815 return &acm->port.func; 813static struct config_item_type acm_func_type = {
816} 814 .ct_item_ops = &acm_item_ops,
815 .ct_attrs = acm_attrs,
816 .ct_owner = THIS_MODULE,
817};
817 818
818static void acm_free_instance(struct usb_function_instance *fi) 819static void acm_free_instance(struct usb_function_instance *fi)
819{ 820{
820 struct f_serial_opts *opts; 821 struct f_serial_opts *opts;
821 822
822 opts = container_of(fi, struct f_serial_opts, func_inst); 823 opts = container_of(fi, struct f_serial_opts, func_inst);
824 gserial_free_line(opts->port_num);
823 kfree(opts); 825 kfree(opts);
824} 826}
825 827
826static struct usb_function_instance *acm_alloc_instance(void) 828static struct usb_function_instance *acm_alloc_instance(void)
827{ 829{
828 struct f_serial_opts *opts; 830 struct f_serial_opts *opts;
831 int ret;
829 832
830 opts = kzalloc(sizeof(*opts), GFP_KERNEL); 833 opts = kzalloc(sizeof(*opts), GFP_KERNEL);
831 if (!opts) 834 if (!opts)
832 return ERR_PTR(-ENOMEM); 835 return ERR_PTR(-ENOMEM);
833 opts->func_inst.free_func_inst = acm_free_instance; 836 opts->func_inst.free_func_inst = acm_free_instance;
837 ret = gserial_alloc_line(&opts->port_num);
838 if (ret) {
839 kfree(opts);
840 return ERR_PTR(ret);
841 }
842 config_group_init_type_name(&opts->func_inst.group, "",
843 &acm_func_type);
834 return &opts->func_inst; 844 return &opts->func_inst;
835} 845}
836DECLARE_USB_FUNCTION_INIT(acm, acm_alloc_instance, acm_alloc_func); 846DECLARE_USB_FUNCTION_INIT(acm, acm_alloc_instance, acm_alloc_func);
837MODULE_LICENSE("GPL"); 847MODULE_LICENSE("GPL");
838#endif
diff --git a/drivers/usb/gadget/f_ecm.c b/drivers/usb/gadget/f_ecm.c
index 83420a310fb7..d893d6929079 100644
--- a/drivers/usb/gadget/f_ecm.c
+++ b/drivers/usb/gadget/f_ecm.c
@@ -824,7 +824,8 @@ ecm_unbind(struct usb_configuration *c, struct usb_function *f)
824 * for calling @gether_cleanup() before module unload. 824 * for calling @gether_cleanup() before module unload.
825 */ 825 */
826int 826int
827ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) 827ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
828 struct eth_dev *dev)
828{ 829{
829 struct f_ecm *ecm; 830 struct f_ecm *ecm;
830 int status; 831 int status;
@@ -852,6 +853,7 @@ ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
852 snprintf(ecm->ethaddr, sizeof ecm->ethaddr, "%pm", ethaddr); 853 snprintf(ecm->ethaddr, sizeof ecm->ethaddr, "%pm", ethaddr);
853 ecm_string_defs[1].s = ecm->ethaddr; 854 ecm_string_defs[1].s = ecm->ethaddr;
854 855
856 ecm->port.ioport = dev;
855 ecm->port.cdc_filter = DEFAULT_FILTER; 857 ecm->port.cdc_filter = DEFAULT_FILTER;
856 858
857 ecm->port.func.name = "cdc_ethernet"; 859 ecm->port.func.name = "cdc_ethernet";
diff --git a/drivers/usb/gadget/f_eem.c b/drivers/usb/gadget/f_eem.c
index cf0ebee85563..f4e0bbef602a 100644
--- a/drivers/usb/gadget/f_eem.c
+++ b/drivers/usb/gadget/f_eem.c
@@ -528,7 +528,7 @@ error:
528 * Caller must have called @gether_setup(). Caller is also responsible 528 * Caller must have called @gether_setup(). Caller is also responsible
529 * for calling @gether_cleanup() before module unload. 529 * for calling @gether_cleanup() before module unload.
530 */ 530 */
531int __init eem_bind_config(struct usb_configuration *c) 531int __init eem_bind_config(struct usb_configuration *c, struct eth_dev *dev)
532{ 532{
533 struct f_eem *eem; 533 struct f_eem *eem;
534 int status; 534 int status;
@@ -549,6 +549,7 @@ int __init eem_bind_config(struct usb_configuration *c)
549 if (!eem) 549 if (!eem)
550 return -ENOMEM; 550 return -ENOMEM;
551 551
552 eem->port.ioport = dev;
552 eem->port.cdc_filter = DEFAULT_FILTER; 553 eem->port.cdc_filter = DEFAULT_FILTER;
553 554
554 eem->port.func.name = "cdc_eem"; 555 eem->port.func.name = "cdc_eem";
diff --git a/drivers/usb/gadget/f_ncm.c b/drivers/usb/gadget/f_ncm.c
index 5e7557e23ecc..ee19bc8d0040 100644
--- a/drivers/usb/gadget/f_ncm.c
+++ b/drivers/usb/gadget/f_ncm.c
@@ -1287,7 +1287,8 @@ ncm_unbind(struct usb_configuration *c, struct usb_function *f)
1287 * Caller must have called @gether_setup(). Caller is also responsible 1287 * Caller must have called @gether_setup(). Caller is also responsible
1288 * for calling @gether_cleanup() before module unload. 1288 * for calling @gether_cleanup() before module unload.
1289 */ 1289 */
1290int __init ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) 1290int __init ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
1291 struct eth_dev *dev)
1291{ 1292{
1292 struct f_ncm *ncm; 1293 struct f_ncm *ncm;
1293 int status; 1294 int status;
@@ -1321,6 +1322,7 @@ int __init ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
1321 1322
1322 spin_lock_init(&ncm->lock); 1323 spin_lock_init(&ncm->lock);
1323 ncm_reset_values(ncm); 1324 ncm_reset_values(ncm);
1325 ncm->port.ioport = dev;
1324 ncm->port.is_fixed = true; 1326 ncm->port.is_fixed = true;
1325 1327
1326 ncm->port.func.name = "cdc_network"; 1328 ncm->port.func.name = "cdc_network";
diff --git a/drivers/usb/gadget/f_obex.c b/drivers/usb/gadget/f_obex.c
index 36a004563b82..29a348a2a294 100644
--- a/drivers/usb/gadget/f_obex.c
+++ b/drivers/usb/gadget/f_obex.c
@@ -72,7 +72,7 @@ static struct usb_gadget_strings *obex_strings[] = {
72 72
73/*-------------------------------------------------------------------------*/ 73/*-------------------------------------------------------------------------*/
74 74
75static struct usb_interface_descriptor obex_control_intf __initdata = { 75static struct usb_interface_descriptor obex_control_intf = {
76 .bLength = sizeof(obex_control_intf), 76 .bLength = sizeof(obex_control_intf),
77 .bDescriptorType = USB_DT_INTERFACE, 77 .bDescriptorType = USB_DT_INTERFACE,
78 .bInterfaceNumber = 0, 78 .bInterfaceNumber = 0,
@@ -83,7 +83,7 @@ static struct usb_interface_descriptor obex_control_intf __initdata = {
83 .bInterfaceSubClass = USB_CDC_SUBCLASS_OBEX, 83 .bInterfaceSubClass = USB_CDC_SUBCLASS_OBEX,
84}; 84};
85 85
86static struct usb_interface_descriptor obex_data_nop_intf __initdata = { 86static struct usb_interface_descriptor obex_data_nop_intf = {
87 .bLength = sizeof(obex_data_nop_intf), 87 .bLength = sizeof(obex_data_nop_intf),
88 .bDescriptorType = USB_DT_INTERFACE, 88 .bDescriptorType = USB_DT_INTERFACE,
89 .bInterfaceNumber = 1, 89 .bInterfaceNumber = 1,
@@ -93,7 +93,7 @@ static struct usb_interface_descriptor obex_data_nop_intf __initdata = {
93 .bInterfaceClass = USB_CLASS_CDC_DATA, 93 .bInterfaceClass = USB_CLASS_CDC_DATA,
94}; 94};
95 95
96static struct usb_interface_descriptor obex_data_intf __initdata = { 96static struct usb_interface_descriptor obex_data_intf = {
97 .bLength = sizeof(obex_data_intf), 97 .bLength = sizeof(obex_data_intf),
98 .bDescriptorType = USB_DT_INTERFACE, 98 .bDescriptorType = USB_DT_INTERFACE,
99 .bInterfaceNumber = 2, 99 .bInterfaceNumber = 2,
@@ -103,14 +103,14 @@ static struct usb_interface_descriptor obex_data_intf __initdata = {
103 .bInterfaceClass = USB_CLASS_CDC_DATA, 103 .bInterfaceClass = USB_CLASS_CDC_DATA,
104}; 104};
105 105
106static struct usb_cdc_header_desc obex_cdc_header_desc __initdata = { 106static struct usb_cdc_header_desc obex_cdc_header_desc = {
107 .bLength = sizeof(obex_cdc_header_desc), 107 .bLength = sizeof(obex_cdc_header_desc),
108 .bDescriptorType = USB_DT_CS_INTERFACE, 108 .bDescriptorType = USB_DT_CS_INTERFACE,
109 .bDescriptorSubType = USB_CDC_HEADER_TYPE, 109 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
110 .bcdCDC = cpu_to_le16(0x0120), 110 .bcdCDC = cpu_to_le16(0x0120),
111}; 111};
112 112
113static struct usb_cdc_union_desc obex_cdc_union_desc __initdata = { 113static struct usb_cdc_union_desc obex_cdc_union_desc = {
114 .bLength = sizeof(obex_cdc_union_desc), 114 .bLength = sizeof(obex_cdc_union_desc),
115 .bDescriptorType = USB_DT_CS_INTERFACE, 115 .bDescriptorType = USB_DT_CS_INTERFACE,
116 .bDescriptorSubType = USB_CDC_UNION_TYPE, 116 .bDescriptorSubType = USB_CDC_UNION_TYPE,
@@ -118,7 +118,7 @@ static struct usb_cdc_union_desc obex_cdc_union_desc __initdata = {
118 .bSlaveInterface0 = 2, 118 .bSlaveInterface0 = 2,
119}; 119};
120 120
121static struct usb_cdc_obex_desc obex_desc __initdata = { 121static struct usb_cdc_obex_desc obex_desc = {
122 .bLength = sizeof(obex_desc), 122 .bLength = sizeof(obex_desc),
123 .bDescriptorType = USB_DT_CS_INTERFACE, 123 .bDescriptorType = USB_DT_CS_INTERFACE,
124 .bDescriptorSubType = USB_CDC_OBEX_TYPE, 124 .bDescriptorSubType = USB_CDC_OBEX_TYPE,
@@ -127,7 +127,7 @@ static struct usb_cdc_obex_desc obex_desc __initdata = {
127 127
128/* High-Speed Support */ 128/* High-Speed Support */
129 129
130static struct usb_endpoint_descriptor obex_hs_ep_out_desc __initdata = { 130static struct usb_endpoint_descriptor obex_hs_ep_out_desc = {
131 .bLength = USB_DT_ENDPOINT_SIZE, 131 .bLength = USB_DT_ENDPOINT_SIZE,
132 .bDescriptorType = USB_DT_ENDPOINT, 132 .bDescriptorType = USB_DT_ENDPOINT,
133 133
@@ -136,7 +136,7 @@ static struct usb_endpoint_descriptor obex_hs_ep_out_desc __initdata = {
136 .wMaxPacketSize = cpu_to_le16(512), 136 .wMaxPacketSize = cpu_to_le16(512),
137}; 137};
138 138
139static struct usb_endpoint_descriptor obex_hs_ep_in_desc __initdata = { 139static struct usb_endpoint_descriptor obex_hs_ep_in_desc = {
140 .bLength = USB_DT_ENDPOINT_SIZE, 140 .bLength = USB_DT_ENDPOINT_SIZE,
141 .bDescriptorType = USB_DT_ENDPOINT, 141 .bDescriptorType = USB_DT_ENDPOINT,
142 142
@@ -145,7 +145,7 @@ static struct usb_endpoint_descriptor obex_hs_ep_in_desc __initdata = {
145 .wMaxPacketSize = cpu_to_le16(512), 145 .wMaxPacketSize = cpu_to_le16(512),
146}; 146};
147 147
148static struct usb_descriptor_header *hs_function[] __initdata = { 148static struct usb_descriptor_header *hs_function[] = {
149 (struct usb_descriptor_header *) &obex_control_intf, 149 (struct usb_descriptor_header *) &obex_control_intf,
150 (struct usb_descriptor_header *) &obex_cdc_header_desc, 150 (struct usb_descriptor_header *) &obex_cdc_header_desc,
151 (struct usb_descriptor_header *) &obex_desc, 151 (struct usb_descriptor_header *) &obex_desc,
@@ -160,7 +160,7 @@ static struct usb_descriptor_header *hs_function[] __initdata = {
160 160
161/* Full-Speed Support */ 161/* Full-Speed Support */
162 162
163static struct usb_endpoint_descriptor obex_fs_ep_in_desc __initdata = { 163static struct usb_endpoint_descriptor obex_fs_ep_in_desc = {
164 .bLength = USB_DT_ENDPOINT_SIZE, 164 .bLength = USB_DT_ENDPOINT_SIZE,
165 .bDescriptorType = USB_DT_ENDPOINT, 165 .bDescriptorType = USB_DT_ENDPOINT,
166 166
@@ -168,7 +168,7 @@ static struct usb_endpoint_descriptor obex_fs_ep_in_desc __initdata = {
168 .bmAttributes = USB_ENDPOINT_XFER_BULK, 168 .bmAttributes = USB_ENDPOINT_XFER_BULK,
169}; 169};
170 170
171static struct usb_endpoint_descriptor obex_fs_ep_out_desc __initdata = { 171static struct usb_endpoint_descriptor obex_fs_ep_out_desc = {
172 .bLength = USB_DT_ENDPOINT_SIZE, 172 .bLength = USB_DT_ENDPOINT_SIZE,
173 .bDescriptorType = USB_DT_ENDPOINT, 173 .bDescriptorType = USB_DT_ENDPOINT,
174 174
@@ -176,7 +176,7 @@ static struct usb_endpoint_descriptor obex_fs_ep_out_desc __initdata = {
176 .bmAttributes = USB_ENDPOINT_XFER_BULK, 176 .bmAttributes = USB_ENDPOINT_XFER_BULK,
177}; 177};
178 178
179static struct usb_descriptor_header *fs_function[] __initdata = { 179static struct usb_descriptor_header *fs_function[] = {
180 (struct usb_descriptor_header *) &obex_control_intf, 180 (struct usb_descriptor_header *) &obex_control_intf,
181 (struct usb_descriptor_header *) &obex_cdc_header_desc, 181 (struct usb_descriptor_header *) &obex_cdc_header_desc,
182 (struct usb_descriptor_header *) &obex_desc, 182 (struct usb_descriptor_header *) &obex_desc,
@@ -290,14 +290,43 @@ static void obex_disconnect(struct gserial *g)
290 290
291/*-------------------------------------------------------------------------*/ 291/*-------------------------------------------------------------------------*/
292 292
293static int __init 293/* Some controllers can't support CDC OBEX ... */
294obex_bind(struct usb_configuration *c, struct usb_function *f) 294static inline bool can_support_obex(struct usb_configuration *c)
295{
296 /* Since the first interface is a NOP, we can ignore the
297 * issue of multi-interface support on most controllers.
298 *
299 * Altsettings are mandatory, however...
300 */
301 if (!gadget_supports_altsettings(c->cdev->gadget))
302 return false;
303
304 /* everything else is *probably* fine ... */
305 return true;
306}
307
308static int obex_bind(struct usb_configuration *c, struct usb_function *f)
295{ 309{
296 struct usb_composite_dev *cdev = c->cdev; 310 struct usb_composite_dev *cdev = c->cdev;
297 struct f_obex *obex = func_to_obex(f); 311 struct f_obex *obex = func_to_obex(f);
298 int status; 312 int status;
299 struct usb_ep *ep; 313 struct usb_ep *ep;
300 314
315 if (!can_support_obex(c))
316 return -EINVAL;
317
318 if (obex_string_defs[OBEX_CTRL_IDX].id == 0) {
319 status = usb_string_ids_tab(c->cdev, obex_string_defs);
320 if (status < 0)
321 return status;
322 obex_control_intf.iInterface =
323 obex_string_defs[OBEX_CTRL_IDX].id;
324
325 status = obex_string_defs[OBEX_DATA_IDX].id;
326 obex_data_nop_intf.iInterface = status;
327 obex_data_intf.iInterface = status;
328 }
329
301 /* allocate instance-specific interface IDs, and patch descriptors */ 330 /* allocate instance-specific interface IDs, and patch descriptors */
302 331
303 status = usb_interface_id(c, f); 332 status = usb_interface_id(c, f);
@@ -376,29 +405,16 @@ fail:
376 return status; 405 return status;
377} 406}
378 407
408#ifdef USBF_OBEX_INCLUDED
409
379static void 410static void
380obex_unbind(struct usb_configuration *c, struct usb_function *f) 411obex_old_unbind(struct usb_configuration *c, struct usb_function *f)
381{ 412{
382 obex_string_defs[OBEX_CTRL_IDX].id = 0; 413 obex_string_defs[OBEX_CTRL_IDX].id = 0;
383 usb_free_all_descriptors(f); 414 usb_free_all_descriptors(f);
384 kfree(func_to_obex(f)); 415 kfree(func_to_obex(f));
385} 416}
386 417
387/* Some controllers can't support CDC OBEX ... */
388static inline bool can_support_obex(struct usb_configuration *c)
389{
390 /* Since the first interface is a NOP, we can ignore the
391 * issue of multi-interface support on most controllers.
392 *
393 * Altsettings are mandatory, however...
394 */
395 if (!gadget_supports_altsettings(c->cdev->gadget))
396 return false;
397
398 /* everything else is *probably* fine ... */
399 return true;
400}
401
402/** 418/**
403 * obex_bind_config - add a CDC OBEX function to a configuration 419 * obex_bind_config - add a CDC OBEX function to a configuration
404 * @c: the configuration to support the CDC OBEX instance 420 * @c: the configuration to support the CDC OBEX instance
@@ -412,21 +428,6 @@ int __init obex_bind_config(struct usb_configuration *c, u8 port_num)
412 struct f_obex *obex; 428 struct f_obex *obex;
413 int status; 429 int status;
414 430
415 if (!can_support_obex(c))
416 return -EINVAL;
417
418 if (obex_string_defs[OBEX_CTRL_IDX].id == 0) {
419 status = usb_string_ids_tab(c->cdev, obex_string_defs);
420 if (status < 0)
421 return status;
422 obex_control_intf.iInterface =
423 obex_string_defs[OBEX_CTRL_IDX].id;
424
425 status = obex_string_defs[OBEX_DATA_IDX].id;
426 obex_data_nop_intf.iInterface = status;
427 obex_data_intf.iInterface = status;
428 }
429
430 /* allocate and initialize one new instance */ 431 /* allocate and initialize one new instance */
431 obex = kzalloc(sizeof *obex, GFP_KERNEL); 432 obex = kzalloc(sizeof *obex, GFP_KERNEL);
432 if (!obex) 433 if (!obex)
@@ -441,7 +442,7 @@ int __init obex_bind_config(struct usb_configuration *c, u8 port_num)
441 obex->port.func.strings = obex_strings; 442 obex->port.func.strings = obex_strings;
442 /* descriptors are per-instance copies */ 443 /* descriptors are per-instance copies */
443 obex->port.func.bind = obex_bind; 444 obex->port.func.bind = obex_bind;
444 obex->port.func.unbind = obex_unbind; 445 obex->port.func.unbind = obex_old_unbind;
445 obex->port.func.set_alt = obex_set_alt; 446 obex->port.func.set_alt = obex_set_alt;
446 obex->port.func.get_alt = obex_get_alt; 447 obex->port.func.get_alt = obex_get_alt;
447 obex->port.func.disable = obex_disable; 448 obex->port.func.disable = obex_disable;
@@ -453,5 +454,138 @@ int __init obex_bind_config(struct usb_configuration *c, u8 port_num)
453 return status; 454 return status;
454} 455}
455 456
457#else
458
459static inline struct f_serial_opts *to_f_serial_opts(struct config_item *item)
460{
461 return container_of(to_config_group(item), struct f_serial_opts,
462 func_inst.group);
463}
464
465CONFIGFS_ATTR_STRUCT(f_serial_opts);
466static ssize_t f_obex_attr_show(struct config_item *item,
467 struct configfs_attribute *attr,
468 char *page)
469{
470 struct f_serial_opts *opts = to_f_serial_opts(item);
471 struct f_serial_opts_attribute *f_serial_opts_attr =
472 container_of(attr, struct f_serial_opts_attribute, attr);
473 ssize_t ret = 0;
474
475 if (f_serial_opts_attr->show)
476 ret = f_serial_opts_attr->show(opts, page);
477
478 return ret;
479}
480
481static void obex_attr_release(struct config_item *item)
482{
483 struct f_serial_opts *opts = to_f_serial_opts(item);
484
485 usb_put_function_instance(&opts->func_inst);
486}
487
488static struct configfs_item_operations obex_item_ops = {
489 .release = obex_attr_release,
490 .show_attribute = f_obex_attr_show,
491};
492
493static ssize_t f_obex_port_num_show(struct f_serial_opts *opts, char *page)
494{
495 return sprintf(page, "%u\n", opts->port_num);
496}
497
498static struct f_serial_opts_attribute f_obex_port_num =
499 __CONFIGFS_ATTR_RO(port_num, f_obex_port_num_show);
500
501static struct configfs_attribute *acm_attrs[] = {
502 &f_obex_port_num.attr,
503 NULL,
504};
505
506static struct config_item_type obex_func_type = {
507 .ct_item_ops = &obex_item_ops,
508 .ct_attrs = acm_attrs,
509 .ct_owner = THIS_MODULE,
510};
511
512static void obex_free_inst(struct usb_function_instance *f)
513{
514 struct f_serial_opts *opts;
515
516 opts = container_of(f, struct f_serial_opts, func_inst);
517 gserial_free_line(opts->port_num);
518 kfree(opts);
519}
520
521static struct usb_function_instance *obex_alloc_inst(void)
522{
523 struct f_serial_opts *opts;
524 int ret;
525
526 opts = kzalloc(sizeof(*opts), GFP_KERNEL);
527 if (!opts)
528 return ERR_PTR(-ENOMEM);
529
530 opts->func_inst.free_func_inst = obex_free_inst;
531 ret = gserial_alloc_line(&opts->port_num);
532 if (ret) {
533 kfree(opts);
534 return ERR_PTR(ret);
535 }
536 config_group_init_type_name(&opts->func_inst.group, "",
537 &obex_func_type);
538
539 return &opts->func_inst;
540}
541
542static void obex_free(struct usb_function *f)
543{
544 struct f_obex *obex;
545
546 obex = func_to_obex(f);
547 kfree(obex);
548}
549
550static void obex_unbind(struct usb_configuration *c, struct usb_function *f)
551{
552 obex_string_defs[OBEX_CTRL_IDX].id = 0;
553 usb_free_all_descriptors(f);
554}
555
556struct usb_function *obex_alloc(struct usb_function_instance *fi)
557{
558 struct f_obex *obex;
559 struct f_serial_opts *opts;
560
561 /* allocate and initialize one new instance */
562 obex = kzalloc(sizeof(*obex), GFP_KERNEL);
563 if (!obex)
564 return ERR_PTR(-ENOMEM);
565
566 opts = container_of(fi, struct f_serial_opts, func_inst);
567
568 obex->port_num = opts->port_num;
569
570 obex->port.connect = obex_connect;
571 obex->port.disconnect = obex_disconnect;
572
573 obex->port.func.name = "obex";
574 obex->port.func.strings = obex_strings;
575 /* descriptors are per-instance copies */
576 obex->port.func.bind = obex_bind;
577 obex->port.func.unbind = obex_unbind;
578 obex->port.func.set_alt = obex_set_alt;
579 obex->port.func.get_alt = obex_get_alt;
580 obex->port.func.disable = obex_disable;
581 obex->port.func.free_func = obex_free;
582
583 return &obex->port.func;
584}
585
586DECLARE_USB_FUNCTION_INIT(obex, obex_alloc_inst, obex_alloc);
587
588#endif
589
456MODULE_AUTHOR("Felipe Balbi"); 590MODULE_AUTHOR("Felipe Balbi");
457MODULE_LICENSE("GPL"); 591MODULE_LICENSE("GPL");
diff --git a/drivers/usb/gadget/f_rndis.c b/drivers/usb/gadget/f_rndis.c
index cc9c49c57c80..36e8c44d8e5e 100644
--- a/drivers/usb/gadget/f_rndis.c
+++ b/drivers/usb/gadget/f_rndis.c
@@ -813,7 +813,7 @@ static inline bool can_support_rndis(struct usb_configuration *c)
813 813
814int 814int
815rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], 815rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
816 u32 vendorID, const char *manufacturer) 816 u32 vendorID, const char *manufacturer, struct eth_dev *dev)
817{ 817{
818 struct f_rndis *rndis; 818 struct f_rndis *rndis;
819 int status; 819 int status;
@@ -846,6 +846,7 @@ rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
846 rndis->vendorID = vendorID; 846 rndis->vendorID = vendorID;
847 rndis->manufacturer = manufacturer; 847 rndis->manufacturer = manufacturer;
848 848
849 rndis->port.ioport = dev;
849 /* RNDIS activates when the host changes this filter */ 850 /* RNDIS activates when the host changes this filter */
850 rndis->port.cdc_filter = 0; 851 rndis->port.cdc_filter = 0;
851 852
diff --git a/drivers/usb/gadget/f_serial.c b/drivers/usb/gadget/f_serial.c
index da33cfb3031d..981113c9924d 100644
--- a/drivers/usb/gadget/f_serial.c
+++ b/drivers/usb/gadget/f_serial.c
@@ -12,6 +12,7 @@
12 12
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/module.h>
15#include <linux/device.h> 16#include <linux/device.h>
16 17
17#include "u_serial.h" 18#include "u_serial.h"
@@ -42,7 +43,7 @@ static inline struct f_gser *func_to_gser(struct usb_function *f)
42 43
43/* interface descriptor: */ 44/* interface descriptor: */
44 45
45static struct usb_interface_descriptor gser_interface_desc __initdata = { 46static struct usb_interface_descriptor gser_interface_desc = {
46 .bLength = USB_DT_INTERFACE_SIZE, 47 .bLength = USB_DT_INTERFACE_SIZE,
47 .bDescriptorType = USB_DT_INTERFACE, 48 .bDescriptorType = USB_DT_INTERFACE,
48 /* .bInterfaceNumber = DYNAMIC */ 49 /* .bInterfaceNumber = DYNAMIC */
@@ -55,21 +56,21 @@ static struct usb_interface_descriptor gser_interface_desc __initdata = {
55 56
56/* full speed support: */ 57/* full speed support: */
57 58
58static struct usb_endpoint_descriptor gser_fs_in_desc __initdata = { 59static struct usb_endpoint_descriptor gser_fs_in_desc = {
59 .bLength = USB_DT_ENDPOINT_SIZE, 60 .bLength = USB_DT_ENDPOINT_SIZE,
60 .bDescriptorType = USB_DT_ENDPOINT, 61 .bDescriptorType = USB_DT_ENDPOINT,
61 .bEndpointAddress = USB_DIR_IN, 62 .bEndpointAddress = USB_DIR_IN,
62 .bmAttributes = USB_ENDPOINT_XFER_BULK, 63 .bmAttributes = USB_ENDPOINT_XFER_BULK,
63}; 64};
64 65
65static struct usb_endpoint_descriptor gser_fs_out_desc __initdata = { 66static struct usb_endpoint_descriptor gser_fs_out_desc = {
66 .bLength = USB_DT_ENDPOINT_SIZE, 67 .bLength = USB_DT_ENDPOINT_SIZE,
67 .bDescriptorType = USB_DT_ENDPOINT, 68 .bDescriptorType = USB_DT_ENDPOINT,
68 .bEndpointAddress = USB_DIR_OUT, 69 .bEndpointAddress = USB_DIR_OUT,
69 .bmAttributes = USB_ENDPOINT_XFER_BULK, 70 .bmAttributes = USB_ENDPOINT_XFER_BULK,
70}; 71};
71 72
72static struct usb_descriptor_header *gser_fs_function[] __initdata = { 73static struct usb_descriptor_header *gser_fs_function[] = {
73 (struct usb_descriptor_header *) &gser_interface_desc, 74 (struct usb_descriptor_header *) &gser_interface_desc,
74 (struct usb_descriptor_header *) &gser_fs_in_desc, 75 (struct usb_descriptor_header *) &gser_fs_in_desc,
75 (struct usb_descriptor_header *) &gser_fs_out_desc, 76 (struct usb_descriptor_header *) &gser_fs_out_desc,
@@ -78,47 +79,47 @@ static struct usb_descriptor_header *gser_fs_function[] __initdata = {
78 79
79/* high speed support: */ 80/* high speed support: */
80 81
81static struct usb_endpoint_descriptor gser_hs_in_desc __initdata = { 82static struct usb_endpoint_descriptor gser_hs_in_desc = {
82 .bLength = USB_DT_ENDPOINT_SIZE, 83 .bLength = USB_DT_ENDPOINT_SIZE,
83 .bDescriptorType = USB_DT_ENDPOINT, 84 .bDescriptorType = USB_DT_ENDPOINT,
84 .bmAttributes = USB_ENDPOINT_XFER_BULK, 85 .bmAttributes = USB_ENDPOINT_XFER_BULK,
85 .wMaxPacketSize = cpu_to_le16(512), 86 .wMaxPacketSize = cpu_to_le16(512),
86}; 87};
87 88
88static struct usb_endpoint_descriptor gser_hs_out_desc __initdata = { 89static struct usb_endpoint_descriptor gser_hs_out_desc = {
89 .bLength = USB_DT_ENDPOINT_SIZE, 90 .bLength = USB_DT_ENDPOINT_SIZE,
90 .bDescriptorType = USB_DT_ENDPOINT, 91 .bDescriptorType = USB_DT_ENDPOINT,
91 .bmAttributes = USB_ENDPOINT_XFER_BULK, 92 .bmAttributes = USB_ENDPOINT_XFER_BULK,
92 .wMaxPacketSize = cpu_to_le16(512), 93 .wMaxPacketSize = cpu_to_le16(512),
93}; 94};
94 95
95static struct usb_descriptor_header *gser_hs_function[] __initdata = { 96static struct usb_descriptor_header *gser_hs_function[] = {
96 (struct usb_descriptor_header *) &gser_interface_desc, 97 (struct usb_descriptor_header *) &gser_interface_desc,
97 (struct usb_descriptor_header *) &gser_hs_in_desc, 98 (struct usb_descriptor_header *) &gser_hs_in_desc,
98 (struct usb_descriptor_header *) &gser_hs_out_desc, 99 (struct usb_descriptor_header *) &gser_hs_out_desc,
99 NULL, 100 NULL,
100}; 101};
101 102
102static struct usb_endpoint_descriptor gser_ss_in_desc __initdata = { 103static struct usb_endpoint_descriptor gser_ss_in_desc = {
103 .bLength = USB_DT_ENDPOINT_SIZE, 104 .bLength = USB_DT_ENDPOINT_SIZE,
104 .bDescriptorType = USB_DT_ENDPOINT, 105 .bDescriptorType = USB_DT_ENDPOINT,
105 .bmAttributes = USB_ENDPOINT_XFER_BULK, 106 .bmAttributes = USB_ENDPOINT_XFER_BULK,
106 .wMaxPacketSize = cpu_to_le16(1024), 107 .wMaxPacketSize = cpu_to_le16(1024),
107}; 108};
108 109
109static struct usb_endpoint_descriptor gser_ss_out_desc __initdata = { 110static struct usb_endpoint_descriptor gser_ss_out_desc = {
110 .bLength = USB_DT_ENDPOINT_SIZE, 111 .bLength = USB_DT_ENDPOINT_SIZE,
111 .bDescriptorType = USB_DT_ENDPOINT, 112 .bDescriptorType = USB_DT_ENDPOINT,
112 .bmAttributes = USB_ENDPOINT_XFER_BULK, 113 .bmAttributes = USB_ENDPOINT_XFER_BULK,
113 .wMaxPacketSize = cpu_to_le16(1024), 114 .wMaxPacketSize = cpu_to_le16(1024),
114}; 115};
115 116
116static struct usb_ss_ep_comp_descriptor gser_ss_bulk_comp_desc __initdata = { 117static struct usb_ss_ep_comp_descriptor gser_ss_bulk_comp_desc = {
117 .bLength = sizeof gser_ss_bulk_comp_desc, 118 .bLength = sizeof gser_ss_bulk_comp_desc,
118 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 119 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
119}; 120};
120 121
121static struct usb_descriptor_header *gser_ss_function[] __initdata = { 122static struct usb_descriptor_header *gser_ss_function[] = {
122 (struct usb_descriptor_header *) &gser_interface_desc, 123 (struct usb_descriptor_header *) &gser_interface_desc,
123 (struct usb_descriptor_header *) &gser_ss_in_desc, 124 (struct usb_descriptor_header *) &gser_ss_in_desc,
124 (struct usb_descriptor_header *) &gser_ss_bulk_comp_desc, 125 (struct usb_descriptor_header *) &gser_ss_bulk_comp_desc,
@@ -183,14 +184,25 @@ static void gser_disable(struct usb_function *f)
183 184
184/* serial function driver setup/binding */ 185/* serial function driver setup/binding */
185 186
186static int __init 187static int gser_bind(struct usb_configuration *c, struct usb_function *f)
187gser_bind(struct usb_configuration *c, struct usb_function *f)
188{ 188{
189 struct usb_composite_dev *cdev = c->cdev; 189 struct usb_composite_dev *cdev = c->cdev;
190 struct f_gser *gser = func_to_gser(f); 190 struct f_gser *gser = func_to_gser(f);
191 int status; 191 int status;
192 struct usb_ep *ep; 192 struct usb_ep *ep;
193 193
194 /* REVISIT might want instance-specific strings to help
195 * distinguish instances ...
196 */
197
198 /* maybe allocate device-global string ID */
199 if (gser_string_defs[0].id == 0) {
200 status = usb_string_id(c->cdev);
201 if (status < 0)
202 return status;
203 gser_string_defs[0].id = status;
204 }
205
194 /* allocate instance-specific interface IDs */ 206 /* allocate instance-specific interface IDs */
195 status = usb_interface_id(c, f); 207 status = usb_interface_id(c, f);
196 if (status < 0) 208 if (status < 0)
@@ -246,44 +258,115 @@ fail:
246 return status; 258 return status;
247} 259}
248 260
249static void 261static inline struct f_serial_opts *to_f_serial_opts(struct config_item *item)
250gser_unbind(struct usb_configuration *c, struct usb_function *f)
251{ 262{
252 usb_free_all_descriptors(f); 263 return container_of(to_config_group(item), struct f_serial_opts,
253 kfree(func_to_gser(f)); 264 func_inst.group);
254} 265}
255 266
256/** 267CONFIGFS_ATTR_STRUCT(f_serial_opts);
257 * gser_bind_config - add a generic serial function to a configuration 268static ssize_t f_serial_attr_show(struct config_item *item,
258 * @c: the configuration to support the serial instance 269 struct configfs_attribute *attr,
259 * @port_num: /dev/ttyGS* port this interface will use 270 char *page)
260 * Context: single threaded during gadget setup
261 *
262 * Returns zero on success, else negative errno.
263 */
264int __init gser_bind_config(struct usb_configuration *c, u8 port_num)
265{ 271{
266 struct f_gser *gser; 272 struct f_serial_opts *opts = to_f_serial_opts(item);
267 int status; 273 struct f_serial_opts_attribute *f_serial_opts_attr =
274 container_of(attr, struct f_serial_opts_attribute, attr);
275 ssize_t ret = 0;
268 276
269 /* REVISIT might want instance-specific strings to help 277 if (f_serial_opts_attr->show)
270 * distinguish instances ... 278 ret = f_serial_opts_attr->show(opts, page);
271 */
272 279
273 /* maybe allocate device-global string ID */ 280 return ret;
274 if (gser_string_defs[0].id == 0) { 281}
275 status = usb_string_id(c->cdev); 282
276 if (status < 0) 283static void serial_attr_release(struct config_item *item)
277 return status; 284{
278 gser_string_defs[0].id = status; 285 struct f_serial_opts *opts = to_f_serial_opts(item);
286
287 usb_put_function_instance(&opts->func_inst);
288}
289
290static struct configfs_item_operations serial_item_ops = {
291 .release = serial_attr_release,
292 .show_attribute = f_serial_attr_show,
293};
294
295static ssize_t f_serial_port_num_show(struct f_serial_opts *opts, char *page)
296{
297 return sprintf(page, "%u\n", opts->port_num);
298}
299
300static struct f_serial_opts_attribute f_serial_port_num =
301 __CONFIGFS_ATTR_RO(port_num, f_serial_port_num_show);
302
303static struct configfs_attribute *acm_attrs[] = {
304 &f_serial_port_num.attr,
305 NULL,
306};
307
308static struct config_item_type serial_func_type = {
309 .ct_item_ops = &serial_item_ops,
310 .ct_attrs = acm_attrs,
311 .ct_owner = THIS_MODULE,
312};
313
314static void gser_free_inst(struct usb_function_instance *f)
315{
316 struct f_serial_opts *opts;
317
318 opts = container_of(f, struct f_serial_opts, func_inst);
319 gserial_free_line(opts->port_num);
320 kfree(opts);
321}
322
323static struct usb_function_instance *gser_alloc_inst(void)
324{
325 struct f_serial_opts *opts;
326 int ret;
327
328 opts = kzalloc(sizeof(*opts), GFP_KERNEL);
329 if (!opts)
330 return ERR_PTR(-ENOMEM);
331
332 opts->func_inst.free_func_inst = gser_free_inst;
333 ret = gserial_alloc_line(&opts->port_num);
334 if (ret) {
335 kfree(opts);
336 return ERR_PTR(ret);
279 } 337 }
338 config_group_init_type_name(&opts->func_inst.group, "",
339 &serial_func_type);
340
341 return &opts->func_inst;
342}
343
344static void gser_free(struct usb_function *f)
345{
346 struct f_gser *serial;
347
348 serial = func_to_gser(f);
349 kfree(serial);
350}
351
352static void gser_unbind(struct usb_configuration *c, struct usb_function *f)
353{
354 usb_free_all_descriptors(f);
355}
356
357struct usb_function *gser_alloc(struct usb_function_instance *fi)
358{
359 struct f_gser *gser;
360 struct f_serial_opts *opts;
280 361
281 /* allocate and initialize one new instance */ 362 /* allocate and initialize one new instance */
282 gser = kzalloc(sizeof *gser, GFP_KERNEL); 363 gser = kzalloc(sizeof(*gser), GFP_KERNEL);
283 if (!gser) 364 if (!gser)
284 return -ENOMEM; 365 return ERR_PTR(-ENOMEM);
285 366
286 gser->port_num = port_num; 367 opts = container_of(fi, struct f_serial_opts, func_inst);
368
369 gser->port_num = opts->port_num;
287 370
288 gser->port.func.name = "gser"; 371 gser->port.func.name = "gser";
289 gser->port.func.strings = gser_strings; 372 gser->port.func.strings = gser_strings;
@@ -291,9 +374,12 @@ int __init gser_bind_config(struct usb_configuration *c, u8 port_num)
291 gser->port.func.unbind = gser_unbind; 374 gser->port.func.unbind = gser_unbind;
292 gser->port.func.set_alt = gser_set_alt; 375 gser->port.func.set_alt = gser_set_alt;
293 gser->port.func.disable = gser_disable; 376 gser->port.func.disable = gser_disable;
377 gser->port.func.free_func = gser_free;
294 378
295 status = usb_add_function(c, &gser->port.func); 379 return &gser->port.func;
296 if (status)
297 kfree(gser);
298 return status;
299} 380}
381
382DECLARE_USB_FUNCTION_INIT(gser, gser_alloc_inst, gser_alloc);
383MODULE_LICENSE("GPL");
384MODULE_AUTHOR("Al Borchers");
385MODULE_AUTHOR("David Brownell");
diff --git a/drivers/usb/gadget/f_subset.c b/drivers/usb/gadget/f_subset.c
index f172bd152fbb..185d6f5e4e4d 100644
--- a/drivers/usb/gadget/f_subset.c
+++ b/drivers/usb/gadget/f_subset.c
@@ -380,7 +380,8 @@ geth_unbind(struct usb_configuration *c, struct usb_function *f)
380 * Caller must have called @gether_setup(). Caller is also responsible 380 * Caller must have called @gether_setup(). Caller is also responsible
381 * for calling @gether_cleanup() before module unload. 381 * for calling @gether_cleanup() before module unload.
382 */ 382 */
383int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) 383int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
384 struct eth_dev *dev)
384{ 385{
385 struct f_gether *geth; 386 struct f_gether *geth;
386 int status; 387 int status;
@@ -406,6 +407,7 @@ int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
406 snprintf(geth->ethaddr, sizeof geth->ethaddr, "%pm", ethaddr); 407 snprintf(geth->ethaddr, sizeof geth->ethaddr, "%pm", ethaddr);
407 geth_string_defs[1].s = geth->ethaddr; 408 geth_string_defs[1].s = geth->ethaddr;
408 409
410 geth->port.ioport = dev;
409 geth->port.cdc_filter = DEFAULT_FILTER; 411 geth->port.cdc_filter = DEFAULT_FILTER;
410 412
411 geth->port.func.name = "cdc_subset"; 413 geth->port.func.name = "cdc_subset";
diff --git a/drivers/usb/gadget/f_uvc.c b/drivers/usb/gadget/f_uvc.c
index 92efd6ec48af..38dcedddc52c 100644
--- a/drivers/usb/gadget/f_uvc.c
+++ b/drivers/usb/gadget/f_uvc.c
@@ -33,19 +33,15 @@ unsigned int uvc_gadget_trace_param;
33/*-------------------------------------------------------------------------*/ 33/*-------------------------------------------------------------------------*/
34 34
35/* module parameters specific to the Video streaming endpoint */ 35/* module parameters specific to the Video streaming endpoint */
36static unsigned streaming_interval = 1; 36static unsigned int streaming_interval = 1;
37module_param(streaming_interval, uint, S_IRUGO|S_IWUSR); 37module_param(streaming_interval, uint, S_IRUGO|S_IWUSR);
38MODULE_PARM_DESC(streaming_interval, "1 - 16"); 38MODULE_PARM_DESC(streaming_interval, "1 - 16");
39 39
40static unsigned streaming_maxpacket = 1024; 40static unsigned int streaming_maxpacket = 1024;
41module_param(streaming_maxpacket, uint, S_IRUGO|S_IWUSR); 41module_param(streaming_maxpacket, uint, S_IRUGO|S_IWUSR);
42MODULE_PARM_DESC(streaming_maxpacket, "0 - 1023 (fs), 0 - 1024 (hs/ss)"); 42MODULE_PARM_DESC(streaming_maxpacket, "1 - 1023 (FS), 1 - 3072 (hs/ss)");
43 43
44static unsigned streaming_mult; 44static unsigned int streaming_maxburst;
45module_param(streaming_mult, uint, S_IRUGO|S_IWUSR);
46MODULE_PARM_DESC(streaming_mult, "0 - 2 (hs/ss only)");
47
48static unsigned streaming_maxburst;
49module_param(streaming_maxburst, uint, S_IRUGO|S_IWUSR); 45module_param(streaming_maxburst, uint, S_IRUGO|S_IWUSR);
50MODULE_PARM_DESC(streaming_maxburst, "0 - 15 (ss only)"); 46MODULE_PARM_DESC(streaming_maxburst, "0 - 15 (ss only)");
51 47
@@ -55,13 +51,11 @@ MODULE_PARM_DESC(streaming_maxburst, "0 - 15 (ss only)");
55 51
56/* string IDs are assigned dynamically */ 52/* string IDs are assigned dynamically */
57 53
58#define UVC_STRING_ASSOCIATION_IDX 0 54#define UVC_STRING_CONTROL_IDX 0
59#define UVC_STRING_CONTROL_IDX 1 55#define UVC_STRING_STREAMING_IDX 1
60#define UVC_STRING_STREAMING_IDX 2
61 56
62static struct usb_string uvc_en_us_strings[] = { 57static struct usb_string uvc_en_us_strings[] = {
63 [UVC_STRING_ASSOCIATION_IDX].s = "UVC Camera", 58 [UVC_STRING_CONTROL_IDX].s = "UVC Camera",
64 [UVC_STRING_CONTROL_IDX].s = "Video Control",
65 [UVC_STRING_STREAMING_IDX].s = "Video Streaming", 59 [UVC_STRING_STREAMING_IDX].s = "Video Streaming",
66 { } 60 { }
67}; 61};
@@ -79,7 +73,7 @@ static struct usb_gadget_strings *uvc_function_strings[] = {
79#define UVC_INTF_VIDEO_CONTROL 0 73#define UVC_INTF_VIDEO_CONTROL 0
80#define UVC_INTF_VIDEO_STREAMING 1 74#define UVC_INTF_VIDEO_STREAMING 1
81 75
82#define STATUS_BYTECOUNT 16 /* 16 bytes status */ 76#define UVC_STATUS_MAX_PACKET_SIZE 16 /* 16 bytes status */
83 77
84static struct usb_interface_assoc_descriptor uvc_iad __initdata = { 78static struct usb_interface_assoc_descriptor uvc_iad __initdata = {
85 .bLength = sizeof(uvc_iad), 79 .bLength = sizeof(uvc_iad),
@@ -104,20 +98,29 @@ static struct usb_interface_descriptor uvc_control_intf __initdata = {
104 .iInterface = 0, 98 .iInterface = 0,
105}; 99};
106 100
107static struct usb_endpoint_descriptor uvc_fs_control_ep __initdata = { 101static struct usb_endpoint_descriptor uvc_control_ep __initdata = {
108 .bLength = USB_DT_ENDPOINT_SIZE, 102 .bLength = USB_DT_ENDPOINT_SIZE,
109 .bDescriptorType = USB_DT_ENDPOINT, 103 .bDescriptorType = USB_DT_ENDPOINT,
110 .bEndpointAddress = USB_DIR_IN, 104 .bEndpointAddress = USB_DIR_IN,
111 .bmAttributes = USB_ENDPOINT_XFER_INT, 105 .bmAttributes = USB_ENDPOINT_XFER_INT,
112 .wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT), 106 .wMaxPacketSize = cpu_to_le16(UVC_STATUS_MAX_PACKET_SIZE),
113 .bInterval = 8, 107 .bInterval = 8,
114}; 108};
115 109
110static struct usb_ss_ep_comp_descriptor uvc_ss_control_comp __initdata = {
111 .bLength = sizeof(uvc_ss_control_comp),
112 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
113 /* The following 3 values can be tweaked if necessary. */
114 .bMaxBurst = 0,
115 .bmAttributes = 0,
116 .wBytesPerInterval = cpu_to_le16(UVC_STATUS_MAX_PACKET_SIZE),
117};
118
116static struct uvc_control_endpoint_descriptor uvc_control_cs_ep __initdata = { 119static struct uvc_control_endpoint_descriptor uvc_control_cs_ep __initdata = {
117 .bLength = UVC_DT_CONTROL_ENDPOINT_SIZE, 120 .bLength = UVC_DT_CONTROL_ENDPOINT_SIZE,
118 .bDescriptorType = USB_DT_CS_ENDPOINT, 121 .bDescriptorType = USB_DT_CS_ENDPOINT,
119 .bDescriptorSubType = UVC_EP_INTERRUPT, 122 .bDescriptorSubType = UVC_EP_INTERRUPT,
120 .wMaxTransferSize = cpu_to_le16(STATUS_BYTECOUNT), 123 .wMaxTransferSize = cpu_to_le16(UVC_STATUS_MAX_PACKET_SIZE),
121}; 124};
122 125
123static struct usb_interface_descriptor uvc_streaming_intf_alt0 __initdata = { 126static struct usb_interface_descriptor uvc_streaming_intf_alt0 __initdata = {
@@ -144,63 +147,53 @@ static struct usb_interface_descriptor uvc_streaming_intf_alt1 __initdata = {
144 .iInterface = 0, 147 .iInterface = 0,
145}; 148};
146 149
147static struct usb_endpoint_descriptor uvc_fs_streaming_ep = { 150static struct usb_endpoint_descriptor uvc_fs_streaming_ep __initdata = {
148 .bLength = USB_DT_ENDPOINT_SIZE, 151 .bLength = USB_DT_ENDPOINT_SIZE,
149 .bDescriptorType = USB_DT_ENDPOINT, 152 .bDescriptorType = USB_DT_ENDPOINT,
150 .bEndpointAddress = USB_DIR_IN, 153 .bEndpointAddress = USB_DIR_IN,
151 .bmAttributes = USB_ENDPOINT_XFER_ISOC, 154 .bmAttributes = USB_ENDPOINT_SYNC_ASYNC
152 .wMaxPacketSize = cpu_to_le16(512), 155 | USB_ENDPOINT_XFER_ISOC,
153 .bInterval = 1, 156 /* The wMaxPacketSize and bInterval values will be initialized from
157 * module parameters.
158 */
159 .wMaxPacketSize = 0,
160 .bInterval = 0,
154}; 161};
155 162
156static struct usb_endpoint_descriptor uvc_hs_streaming_ep = { 163static struct usb_endpoint_descriptor uvc_hs_streaming_ep __initdata = {
157 .bLength = USB_DT_ENDPOINT_SIZE, 164 .bLength = USB_DT_ENDPOINT_SIZE,
158 .bDescriptorType = USB_DT_ENDPOINT, 165 .bDescriptorType = USB_DT_ENDPOINT,
159 .bEndpointAddress = USB_DIR_IN, 166 .bEndpointAddress = USB_DIR_IN,
160 .bmAttributes = USB_ENDPOINT_XFER_ISOC, 167 .bmAttributes = USB_ENDPOINT_SYNC_ASYNC
161 .wMaxPacketSize = cpu_to_le16(1024), 168 | USB_ENDPOINT_XFER_ISOC,
162 .bInterval = 1, 169 /* The wMaxPacketSize and bInterval values will be initialized from
163}; 170 * module parameters.
164 171 */
165/* super speed support */ 172 .wMaxPacketSize = 0,
166static struct usb_endpoint_descriptor uvc_ss_control_ep __initdata = { 173 .bInterval = 0,
167 .bLength = USB_DT_ENDPOINT_SIZE,
168 .bDescriptorType = USB_DT_ENDPOINT,
169
170 .bEndpointAddress = USB_DIR_IN,
171 .bmAttributes = USB_ENDPOINT_XFER_INT,
172 .wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT),
173 .bInterval = 8,
174};
175
176static struct usb_ss_ep_comp_descriptor uvc_ss_control_comp __initdata = {
177 .bLength = sizeof uvc_ss_control_comp,
178 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
179
180 /* the following 3 values can be tweaked if necessary */
181 /* .bMaxBurst = 0, */
182 /* .bmAttributes = 0, */
183 .wBytesPerInterval = cpu_to_le16(STATUS_BYTECOUNT),
184}; 174};
185 175
186static struct usb_endpoint_descriptor uvc_ss_streaming_ep __initdata = { 176static struct usb_endpoint_descriptor uvc_ss_streaming_ep __initdata = {
187 .bLength = USB_DT_ENDPOINT_SIZE, 177 .bLength = USB_DT_ENDPOINT_SIZE,
188 .bDescriptorType = USB_DT_ENDPOINT, 178 .bDescriptorType = USB_DT_ENDPOINT,
189 179
190 .bEndpointAddress = USB_DIR_IN, 180 .bEndpointAddress = USB_DIR_IN,
191 .bmAttributes = USB_ENDPOINT_XFER_ISOC, 181 .bmAttributes = USB_ENDPOINT_SYNC_ASYNC
192 .wMaxPacketSize = cpu_to_le16(1024), 182 | USB_ENDPOINT_XFER_ISOC,
193 .bInterval = 4, 183 /* The wMaxPacketSize and bInterval values will be initialized from
184 * module parameters.
185 */
186 .wMaxPacketSize = 0,
187 .bInterval = 0,
194}; 188};
195 189
196static struct usb_ss_ep_comp_descriptor uvc_ss_streaming_comp = { 190static struct usb_ss_ep_comp_descriptor uvc_ss_streaming_comp __initdata = {
197 .bLength = sizeof uvc_ss_streaming_comp, 191 .bLength = sizeof(uvc_ss_streaming_comp),
198 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 192 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
199 193 /* The following 3 values can be tweaked if necessary. */
200 /* the following 3 values can be tweaked if necessary */ 194 .bMaxBurst = 0,
201 .bMaxBurst = 0, 195 .bmAttributes = 0,
202 .bmAttributes = 0, 196 .wBytesPerInterval = cpu_to_le16(1024),
203 .wBytesPerInterval = cpu_to_le16(1024),
204}; 197};
205 198
206static const struct usb_descriptor_header * const uvc_fs_streaming[] = { 199static const struct usb_descriptor_header * const uvc_fs_streaming[] = {
@@ -273,6 +266,13 @@ uvc_function_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
273 return 0; 266 return 0;
274} 267}
275 268
269void uvc_function_setup_continue(struct uvc_device *uvc)
270{
271 struct usb_composite_dev *cdev = uvc->func.config->cdev;
272
273 usb_composite_setup_continue(cdev);
274}
275
276static int 276static int
277uvc_function_get_alt(struct usb_function *f, unsigned interface) 277uvc_function_get_alt(struct usb_function *f, unsigned interface)
278{ 278{
@@ -335,7 +335,7 @@ uvc_function_set_alt(struct usb_function *f, unsigned interface, unsigned alt)
335 v4l2_event_queue(uvc->vdev, &v4l2_event); 335 v4l2_event_queue(uvc->vdev, &v4l2_event);
336 336
337 uvc->state = UVC_STATE_CONNECTED; 337 uvc->state = UVC_STATE_CONNECTED;
338 break; 338 return 0;
339 339
340 case 1: 340 case 1:
341 if (uvc->state != UVC_STATE_CONNECTED) 341 if (uvc->state != UVC_STATE_CONNECTED)
@@ -352,15 +352,11 @@ uvc_function_set_alt(struct usb_function *f, unsigned interface, unsigned alt)
352 memset(&v4l2_event, 0, sizeof(v4l2_event)); 352 memset(&v4l2_event, 0, sizeof(v4l2_event));
353 v4l2_event.type = UVC_EVENT_STREAMON; 353 v4l2_event.type = UVC_EVENT_STREAMON;
354 v4l2_event_queue(uvc->vdev, &v4l2_event); 354 v4l2_event_queue(uvc->vdev, &v4l2_event);
355 355 return USB_GADGET_DELAYED_STATUS;
356 uvc->state = UVC_STATE_STREAMING;
357 break;
358 356
359 default: 357 default:
360 return -EINVAL; 358 return -EINVAL;
361 } 359 }
362
363 return 0;
364} 360}
365 361
366static void 362static void
@@ -454,7 +450,6 @@ uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed)
454 const struct uvc_descriptor_header * const *uvc_streaming_cls; 450 const struct uvc_descriptor_header * const *uvc_streaming_cls;
455 const struct usb_descriptor_header * const *uvc_streaming_std; 451 const struct usb_descriptor_header * const *uvc_streaming_std;
456 const struct usb_descriptor_header * const *src; 452 const struct usb_descriptor_header * const *src;
457 static struct usb_endpoint_descriptor *uvc_control_ep;
458 struct usb_descriptor_header **dst; 453 struct usb_descriptor_header **dst;
459 struct usb_descriptor_header **hdr; 454 struct usb_descriptor_header **hdr;
460 unsigned int control_size; 455 unsigned int control_size;
@@ -468,14 +463,12 @@ uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed)
468 uvc_control_desc = uvc->desc.ss_control; 463 uvc_control_desc = uvc->desc.ss_control;
469 uvc_streaming_cls = uvc->desc.ss_streaming; 464 uvc_streaming_cls = uvc->desc.ss_streaming;
470 uvc_streaming_std = uvc_ss_streaming; 465 uvc_streaming_std = uvc_ss_streaming;
471 uvc_control_ep = &uvc_ss_control_ep;
472 break; 466 break;
473 467
474 case USB_SPEED_HIGH: 468 case USB_SPEED_HIGH:
475 uvc_control_desc = uvc->desc.fs_control; 469 uvc_control_desc = uvc->desc.fs_control;
476 uvc_streaming_cls = uvc->desc.hs_streaming; 470 uvc_streaming_cls = uvc->desc.hs_streaming;
477 uvc_streaming_std = uvc_hs_streaming; 471 uvc_streaming_std = uvc_hs_streaming;
478 uvc_control_ep = &uvc_fs_control_ep;
479 break; 472 break;
480 473
481 case USB_SPEED_FULL: 474 case USB_SPEED_FULL:
@@ -483,7 +476,6 @@ uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed)
483 uvc_control_desc = uvc->desc.fs_control; 476 uvc_control_desc = uvc->desc.fs_control;
484 uvc_streaming_cls = uvc->desc.fs_streaming; 477 uvc_streaming_cls = uvc->desc.fs_streaming;
485 uvc_streaming_std = uvc_fs_streaming; 478 uvc_streaming_std = uvc_fs_streaming;
486 uvc_control_ep = &uvc_fs_control_ep;
487 break; 479 break;
488 } 480 }
489 481
@@ -494,6 +486,7 @@ uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed)
494 * Class-specific UVC control descriptors 486 * Class-specific UVC control descriptors
495 * uvc_control_ep 487 * uvc_control_ep
496 * uvc_control_cs_ep 488 * uvc_control_cs_ep
489 * uvc_ss_control_comp (for SS only)
497 * uvc_streaming_intf_alt0 490 * uvc_streaming_intf_alt0
498 * Class-specific UVC streaming descriptors 491 * Class-specific UVC streaming descriptors
499 * uvc_{fs|hs}_streaming 492 * uvc_{fs|hs}_streaming
@@ -503,7 +496,7 @@ uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed)
503 control_size = 0; 496 control_size = 0;
504 streaming_size = 0; 497 streaming_size = 0;
505 bytes = uvc_iad.bLength + uvc_control_intf.bLength 498 bytes = uvc_iad.bLength + uvc_control_intf.bLength
506 + uvc_control_ep->bLength + uvc_control_cs_ep.bLength 499 + uvc_control_ep.bLength + uvc_control_cs_ep.bLength
507 + uvc_streaming_intf_alt0.bLength; 500 + uvc_streaming_intf_alt0.bLength;
508 501
509 if (speed == USB_SPEED_SUPER) { 502 if (speed == USB_SPEED_SUPER) {
@@ -514,13 +507,13 @@ uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed)
514 } 507 }
515 508
516 for (src = (const struct usb_descriptor_header **)uvc_control_desc; 509 for (src = (const struct usb_descriptor_header **)uvc_control_desc;
517 *src; ++src) { 510 *src; ++src) {
518 control_size += (*src)->bLength; 511 control_size += (*src)->bLength;
519 bytes += (*src)->bLength; 512 bytes += (*src)->bLength;
520 n_desc++; 513 n_desc++;
521 } 514 }
522 for (src = (const struct usb_descriptor_header **)uvc_streaming_cls; 515 for (src = (const struct usb_descriptor_header **)uvc_streaming_cls;
523 *src; ++src) { 516 *src; ++src) {
524 streaming_size += (*src)->bLength; 517 streaming_size += (*src)->bLength;
525 bytes += (*src)->bLength; 518 bytes += (*src)->bLength;
526 n_desc++; 519 n_desc++;
@@ -549,7 +542,7 @@ uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed)
549 uvc_control_header->bInCollection = 1; 542 uvc_control_header->bInCollection = 1;
550 uvc_control_header->baInterfaceNr[0] = uvc->streaming_intf; 543 uvc_control_header->baInterfaceNr[0] = uvc->streaming_intf;
551 544
552 UVC_COPY_DESCRIPTOR(mem, dst, uvc_control_ep); 545 UVC_COPY_DESCRIPTOR(mem, dst, &uvc_control_ep);
553 if (speed == USB_SPEED_SUPER) 546 if (speed == USB_SPEED_SUPER)
554 UVC_COPY_DESCRIPTOR(mem, dst, &uvc_ss_control_comp); 547 UVC_COPY_DESCRIPTOR(mem, dst, &uvc_ss_control_comp);
555 548
@@ -560,8 +553,7 @@ uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed)
560 UVC_COPY_DESCRIPTORS(mem, dst, 553 UVC_COPY_DESCRIPTORS(mem, dst,
561 (const struct usb_descriptor_header**)uvc_streaming_cls); 554 (const struct usb_descriptor_header**)uvc_streaming_cls);
562 uvc_streaming_header->wTotalLength = cpu_to_le16(streaming_size); 555 uvc_streaming_header->wTotalLength = cpu_to_le16(streaming_size);
563 uvc_streaming_header->bEndpointAddress = 556 uvc_streaming_header->bEndpointAddress = uvc->video.ep->address;
564 uvc_fs_streaming_ep.bEndpointAddress;
565 557
566 UVC_COPY_DESCRIPTORS(mem, dst, uvc_streaming_std); 558 UVC_COPY_DESCRIPTORS(mem, dst, uvc_streaming_std);
567 559
@@ -581,7 +573,7 @@ uvc_function_unbind(struct usb_configuration *c, struct usb_function *f)
581 uvc->control_ep->driver_data = NULL; 573 uvc->control_ep->driver_data = NULL;
582 uvc->video.ep->driver_data = NULL; 574 uvc->video.ep->driver_data = NULL;
583 575
584 uvc_en_us_strings[UVC_STRING_ASSOCIATION_IDX].id = 0; 576 uvc_en_us_strings[UVC_STRING_CONTROL_IDX].id = 0;
585 usb_ep_free_request(cdev->gadget->ep0, uvc->control_req); 577 usb_ep_free_request(cdev->gadget->ep0, uvc->control_req);
586 kfree(uvc->control_buf); 578 kfree(uvc->control_buf);
587 579
@@ -595,31 +587,52 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f)
595{ 587{
596 struct usb_composite_dev *cdev = c->cdev; 588 struct usb_composite_dev *cdev = c->cdev;
597 struct uvc_device *uvc = to_uvc(f); 589 struct uvc_device *uvc = to_uvc(f);
590 unsigned int max_packet_mult;
591 unsigned int max_packet_size;
598 struct usb_ep *ep; 592 struct usb_ep *ep;
599 int ret = -EINVAL; 593 int ret = -EINVAL;
600 594
601 INFO(cdev, "uvc_function_bind\n"); 595 INFO(cdev, "uvc_function_bind\n");
602 596
603 /* sanity check the streaming endpoint module parameters */ 597 /* Sanity check the streaming endpoint module parameters.
604 if (streaming_interval < 1)
605 streaming_interval = 1;
606 if (streaming_interval > 16)
607 streaming_interval = 16;
608 if (streaming_mult > 2)
609 streaming_mult = 2;
610 if (streaming_maxburst > 15)
611 streaming_maxburst = 15;
612
613 /*
614 * fill in the FS video streaming specific descriptors from the
615 * module parameters
616 */ 598 */
617 uvc_fs_streaming_ep.wMaxPacketSize = streaming_maxpacket > 1023 ? 599 streaming_interval = clamp(streaming_interval, 1U, 16U);
618 1023 : streaming_maxpacket; 600 streaming_maxpacket = clamp(streaming_maxpacket, 1U, 3072U);
601 streaming_maxburst = min(streaming_maxburst, 15U);
602
603 /* Fill in the FS/HS/SS Video Streaming specific descriptors from the
604 * module parameters.
605 *
606 * NOTE: We assume that the user knows what they are doing and won't
607 * give parameters that their UDC doesn't support.
608 */
609 if (streaming_maxpacket <= 1024) {
610 max_packet_mult = 1;
611 max_packet_size = streaming_maxpacket;
612 } else if (streaming_maxpacket <= 2048) {
613 max_packet_mult = 2;
614 max_packet_size = streaming_maxpacket / 2;
615 } else {
616 max_packet_mult = 3;
617 max_packet_size = streaming_maxpacket / 3;
618 }
619
620 uvc_fs_streaming_ep.wMaxPacketSize = min(streaming_maxpacket, 1023U);
619 uvc_fs_streaming_ep.bInterval = streaming_interval; 621 uvc_fs_streaming_ep.bInterval = streaming_interval;
620 622
623 uvc_hs_streaming_ep.wMaxPacketSize = max_packet_size;
624 uvc_hs_streaming_ep.wMaxPacketSize |= ((max_packet_mult - 1) << 11);
625 uvc_hs_streaming_ep.bInterval = streaming_interval;
626
627 uvc_ss_streaming_ep.wMaxPacketSize = max_packet_size;
628 uvc_ss_streaming_ep.bInterval = streaming_interval;
629 uvc_ss_streaming_comp.bmAttributes = max_packet_mult - 1;
630 uvc_ss_streaming_comp.bMaxBurst = streaming_maxburst;
631 uvc_ss_streaming_comp.wBytesPerInterval =
632 max_packet_size * max_packet_mult * streaming_maxburst;
633
621 /* Allocate endpoints. */ 634 /* Allocate endpoints. */
622 ep = usb_ep_autoconfig(cdev->gadget, &uvc_fs_control_ep); 635 ep = usb_ep_autoconfig(cdev->gadget, &uvc_control_ep);
623 if (!ep) { 636 if (!ep) {
624 INFO(cdev, "Unable to allocate control EP\n"); 637 INFO(cdev, "Unable to allocate control EP\n");
625 goto error; 638 goto error;
@@ -627,7 +640,14 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f)
627 uvc->control_ep = ep; 640 uvc->control_ep = ep;
628 ep->driver_data = uvc; 641 ep->driver_data = uvc;
629 642
630 ep = usb_ep_autoconfig(cdev->gadget, &uvc_fs_streaming_ep); 643 if (gadget_is_superspeed(c->cdev->gadget))
644 ep = usb_ep_autoconfig_ss(cdev->gadget, &uvc_ss_streaming_ep,
645 &uvc_ss_streaming_comp);
646 else if (gadget_is_dualspeed(cdev->gadget))
647 ep = usb_ep_autoconfig(cdev->gadget, &uvc_hs_streaming_ep);
648 else
649 ep = usb_ep_autoconfig(cdev->gadget, &uvc_fs_streaming_ep);
650
631 if (!ep) { 651 if (!ep) {
632 INFO(cdev, "Unable to allocate streaming EP\n"); 652 INFO(cdev, "Unable to allocate streaming EP\n");
633 goto error; 653 goto error;
@@ -635,6 +655,10 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f)
635 uvc->video.ep = ep; 655 uvc->video.ep = ep;
636 ep->driver_data = uvc; 656 ep->driver_data = uvc;
637 657
658 uvc_fs_streaming_ep.bEndpointAddress = uvc->video.ep->address;
659 uvc_hs_streaming_ep.bEndpointAddress = uvc->video.ep->address;
660 uvc_ss_streaming_ep.bEndpointAddress = uvc->video.ep->address;
661
638 /* Allocate interface IDs. */ 662 /* Allocate interface IDs. */
639 if ((ret = usb_interface_id(c, f)) < 0) 663 if ((ret = usb_interface_id(c, f)) < 0)
640 goto error; 664 goto error;
@@ -648,37 +672,6 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f)
648 uvc_streaming_intf_alt1.bInterfaceNumber = ret; 672 uvc_streaming_intf_alt1.bInterfaceNumber = ret;
649 uvc->streaming_intf = ret; 673 uvc->streaming_intf = ret;
650 674
651 /* sanity check the streaming endpoint module parameters */
652 if (streaming_maxpacket > 1024)
653 streaming_maxpacket = 1024;
654 /*
655 * Fill in the HS descriptors from the module parameters for the Video
656 * Streaming endpoint.
657 * NOTE: We assume that the user knows what they are doing and won't
658 * give parameters that their UDC doesn't support.
659 */
660 uvc_hs_streaming_ep.wMaxPacketSize = streaming_maxpacket;
661 uvc_hs_streaming_ep.wMaxPacketSize |= streaming_mult << 11;
662 uvc_hs_streaming_ep.bInterval = streaming_interval;
663 uvc_hs_streaming_ep.bEndpointAddress =
664 uvc_fs_streaming_ep.bEndpointAddress;
665
666 /*
667 * Fill in the SS descriptors from the module parameters for the Video
668 * Streaming endpoint.
669 * NOTE: We assume that the user knows what they are doing and won't
670 * give parameters that their UDC doesn't support.
671 */
672 uvc_ss_streaming_ep.wMaxPacketSize = streaming_maxpacket;
673 uvc_ss_streaming_ep.bInterval = streaming_interval;
674 uvc_ss_streaming_comp.bmAttributes = streaming_mult;
675 uvc_ss_streaming_comp.bMaxBurst = streaming_maxburst;
676 uvc_ss_streaming_comp.wBytesPerInterval =
677 streaming_maxpacket * (streaming_mult + 1) *
678 (streaming_maxburst + 1);
679 uvc_ss_streaming_ep.bEndpointAddress =
680 uvc_fs_streaming_ep.bEndpointAddress;
681
682 /* Copy descriptors */ 675 /* Copy descriptors */
683 f->fs_descriptors = uvc_copy_descriptors(uvc, USB_SPEED_FULL); 676 f->fs_descriptors = uvc_copy_descriptors(uvc, USB_SPEED_FULL);
684 if (gadget_is_dualspeed(cdev->gadget)) 677 if (gadget_is_dualspeed(cdev->gadget))
@@ -775,23 +768,23 @@ uvc_bind_config(struct usb_configuration *c,
775 768
776 /* Validate the descriptors. */ 769 /* Validate the descriptors. */
777 if (fs_control == NULL || fs_control[0] == NULL || 770 if (fs_control == NULL || fs_control[0] == NULL ||
778 fs_control[0]->bDescriptorSubType != UVC_VC_HEADER) 771 fs_control[0]->bDescriptorSubType != UVC_VC_HEADER)
779 goto error; 772 goto error;
780 773
781 if (ss_control == NULL || ss_control[0] == NULL || 774 if (ss_control == NULL || ss_control[0] == NULL ||
782 ss_control[0]->bDescriptorSubType != UVC_VC_HEADER) 775 ss_control[0]->bDescriptorSubType != UVC_VC_HEADER)
783 goto error; 776 goto error;
784 777
785 if (fs_streaming == NULL || fs_streaming[0] == NULL || 778 if (fs_streaming == NULL || fs_streaming[0] == NULL ||
786 fs_streaming[0]->bDescriptorSubType != UVC_VS_INPUT_HEADER) 779 fs_streaming[0]->bDescriptorSubType != UVC_VS_INPUT_HEADER)
787 goto error; 780 goto error;
788 781
789 if (hs_streaming == NULL || hs_streaming[0] == NULL || 782 if (hs_streaming == NULL || hs_streaming[0] == NULL ||
790 hs_streaming[0]->bDescriptorSubType != UVC_VS_INPUT_HEADER) 783 hs_streaming[0]->bDescriptorSubType != UVC_VS_INPUT_HEADER)
791 goto error; 784 goto error;
792 785
793 if (ss_streaming == NULL || ss_streaming[0] == NULL || 786 if (ss_streaming == NULL || ss_streaming[0] == NULL ||
794 ss_streaming[0]->bDescriptorSubType != UVC_VS_INPUT_HEADER) 787 ss_streaming[0]->bDescriptorSubType != UVC_VS_INPUT_HEADER)
795 goto error; 788 goto error;
796 789
797 uvc->desc.fs_control = fs_control; 790 uvc->desc.fs_control = fs_control;
@@ -800,13 +793,16 @@ uvc_bind_config(struct usb_configuration *c,
800 uvc->desc.hs_streaming = hs_streaming; 793 uvc->desc.hs_streaming = hs_streaming;
801 uvc->desc.ss_streaming = ss_streaming; 794 uvc->desc.ss_streaming = ss_streaming;
802 795
803 /* Allocate string descriptor numbers. */ 796 /* String descriptors are global, we only need to allocate string IDs
804 if (uvc_en_us_strings[UVC_STRING_ASSOCIATION_IDX].id == 0) { 797 * for the first UVC function. UVC functions beyond the first (if any)
798 * will reuse the same IDs.
799 */
800 if (uvc_en_us_strings[UVC_STRING_CONTROL_IDX].id == 0) {
805 ret = usb_string_ids_tab(c->cdev, uvc_en_us_strings); 801 ret = usb_string_ids_tab(c->cdev, uvc_en_us_strings);
806 if (ret) 802 if (ret)
807 goto error; 803 goto error;
808 uvc_iad.iFunction = 804 uvc_iad.iFunction =
809 uvc_en_us_strings[UVC_STRING_ASSOCIATION_IDX].id; 805 uvc_en_us_strings[UVC_STRING_CONTROL_IDX].id;
810 uvc_control_intf.iInterface = 806 uvc_control_intf.iInterface =
811 uvc_en_us_strings[UVC_STRING_CONTROL_IDX].id; 807 uvc_en_us_strings[UVC_STRING_CONTROL_IDX].id;
812 ret = uvc_en_us_strings[UVC_STRING_STREAMING_IDX].id; 808 ret = uvc_en_us_strings[UVC_STRING_STREAMING_IDX].id;
diff --git a/drivers/usb/gadget/f_uvc.h b/drivers/usb/gadget/f_uvc.h
index c3d258d30188..ec52752f7326 100644
--- a/drivers/usb/gadget/f_uvc.h
+++ b/drivers/usb/gadget/f_uvc.h
@@ -16,12 +16,12 @@
16#include <linux/usb/composite.h> 16#include <linux/usb/composite.h>
17#include <linux/usb/video.h> 17#include <linux/usb/video.h>
18 18
19extern int uvc_bind_config(struct usb_configuration *c, 19int uvc_bind_config(struct usb_configuration *c,
20 const struct uvc_descriptor_header * const *fs_control, 20 const struct uvc_descriptor_header * const *fs_control,
21 const struct uvc_descriptor_header * const *hs_control, 21 const struct uvc_descriptor_header * const *hs_control,
22 const struct uvc_descriptor_header * const *fs_streaming, 22 const struct uvc_descriptor_header * const *fs_streaming,
23 const struct uvc_descriptor_header * const *hs_streaming, 23 const struct uvc_descriptor_header * const *hs_streaming,
24 const struct uvc_descriptor_header * const *ss_streaming); 24 const struct uvc_descriptor_header * const *ss_streaming);
25 25
26#endif /* _F_UVC_H_ */ 26#endif /* _F_UVC_H_ */
27 27
diff --git a/drivers/usb/gadget/fsl_qe_udc.c b/drivers/usb/gadget/fsl_qe_udc.c
index 034477ce77c6..9a7ee3347e4d 100644
--- a/drivers/usb/gadget/fsl_qe_udc.c
+++ b/drivers/usb/gadget/fsl_qe_udc.c
@@ -2296,7 +2296,6 @@ static int fsl_qe_start(struct usb_gadget *gadget,
2296 driver->driver.bus = NULL; 2296 driver->driver.bus = NULL;
2297 /* hook up the driver */ 2297 /* hook up the driver */
2298 udc->driver = driver; 2298 udc->driver = driver;
2299 udc->gadget.dev.driver = &driver->driver;
2300 udc->gadget.speed = driver->max_speed; 2299 udc->gadget.speed = driver->max_speed;
2301 2300
2302 /* Enable IRQ reg and Set usbcmd reg EN bit */ 2301 /* Enable IRQ reg and Set usbcmd reg EN bit */
@@ -2338,7 +2337,6 @@ static int fsl_qe_stop(struct usb_gadget *gadget,
2338 nuke(loop_ep, -ESHUTDOWN); 2337 nuke(loop_ep, -ESHUTDOWN);
2339 spin_unlock_irqrestore(&udc->lock, flags); 2338 spin_unlock_irqrestore(&udc->lock, flags);
2340 2339
2341 udc->gadget.dev.driver = NULL;
2342 udc->driver = NULL; 2340 udc->driver = NULL;
2343 2341
2344 dev_info(udc->dev, "unregistered gadget driver '%s'\r\n", 2342 dev_info(udc->dev, "unregistered gadget driver '%s'\r\n",
@@ -2523,12 +2521,6 @@ static int qe_udc_probe(struct platform_device *ofdev)
2523 2521
2524 /* name: Identifies the controller hardware type. */ 2522 /* name: Identifies the controller hardware type. */
2525 udc->gadget.name = driver_name; 2523 udc->gadget.name = driver_name;
2526
2527 device_initialize(&udc->gadget.dev);
2528
2529 dev_set_name(&udc->gadget.dev, "gadget");
2530
2531 udc->gadget.dev.release = qe_udc_release;
2532 udc->gadget.dev.parent = &ofdev->dev; 2524 udc->gadget.dev.parent = &ofdev->dev;
2533 2525
2534 /* initialize qe_ep struct */ 2526 /* initialize qe_ep struct */
@@ -2592,22 +2584,17 @@ static int qe_udc_probe(struct platform_device *ofdev)
2592 goto err5; 2584 goto err5;
2593 } 2585 }
2594 2586
2595 ret = device_add(&udc->gadget.dev); 2587 ret = usb_add_gadget_udc_release(&ofdev->dev, &udc->gadget,
2588 qe_udc_release);
2596 if (ret) 2589 if (ret)
2597 goto err6; 2590 goto err6;
2598 2591
2599 ret = usb_add_gadget_udc(&ofdev->dev, &udc->gadget);
2600 if (ret)
2601 goto err7;
2602
2603 dev_set_drvdata(&ofdev->dev, udc); 2592 dev_set_drvdata(&ofdev->dev, udc);
2604 dev_info(udc->dev, 2593 dev_info(udc->dev,
2605 "%s USB controller initialized as device\n", 2594 "%s USB controller initialized as device\n",
2606 (udc->soc_type == PORT_QE) ? "QE" : "CPM"); 2595 (udc->soc_type == PORT_QE) ? "QE" : "CPM");
2607 return 0; 2596 return 0;
2608 2597
2609err7:
2610 device_unregister(&udc->gadget.dev);
2611err6: 2598err6:
2612 free_irq(udc->usb_irq, udc); 2599 free_irq(udc->usb_irq, udc);
2613err5: 2600err5:
@@ -2702,7 +2689,6 @@ static int qe_udc_remove(struct platform_device *ofdev)
2702 2689
2703 iounmap(udc->usb_regs); 2690 iounmap(udc->usb_regs);
2704 2691
2705 device_unregister(&udc->gadget.dev);
2706 /* wait for release() of gadget.dev to free udc */ 2692 /* wait for release() of gadget.dev to free udc */
2707 wait_for_completion(&done); 2693 wait_for_completion(&done);
2708 2694
diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index 04d5fef1440c..7c2a101d19ac 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -185,20 +185,7 @@ static void done(struct fsl_ep *ep, struct fsl_req *req, int status)
185 dma_pool_free(udc->td_pool, curr_td, curr_td->td_dma); 185 dma_pool_free(udc->td_pool, curr_td, curr_td->td_dma);
186 } 186 }
187 187
188 if (req->mapped) { 188 usb_gadget_unmap_request(&ep->udc->gadget, &req->req, ep_is_in(ep));
189 dma_unmap_single(ep->udc->gadget.dev.parent,
190 req->req.dma, req->req.length,
191 ep_is_in(ep)
192 ? DMA_TO_DEVICE
193 : DMA_FROM_DEVICE);
194 req->req.dma = DMA_ADDR_INVALID;
195 req->mapped = 0;
196 } else
197 dma_sync_single_for_cpu(ep->udc->gadget.dev.parent,
198 req->req.dma, req->req.length,
199 ep_is_in(ep)
200 ? DMA_TO_DEVICE
201 : DMA_FROM_DEVICE);
202 189
203 if (status && (status != -ESHUTDOWN)) 190 if (status && (status != -ESHUTDOWN))
204 VDBG("complete %s req %p stat %d len %u/%u", 191 VDBG("complete %s req %p stat %d len %u/%u",
@@ -888,6 +875,7 @@ fsl_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
888 struct fsl_req *req = container_of(_req, struct fsl_req, req); 875 struct fsl_req *req = container_of(_req, struct fsl_req, req);
889 struct fsl_udc *udc; 876 struct fsl_udc *udc;
890 unsigned long flags; 877 unsigned long flags;
878 int ret;
891 879
892 /* catch various bogus parameters */ 880 /* catch various bogus parameters */
893 if (!_req || !req->req.complete || !req->req.buf 881 if (!_req || !req->req.complete || !req->req.buf
@@ -910,22 +898,9 @@ fsl_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
910 898
911 req->ep = ep; 899 req->ep = ep;
912 900
913 /* map virtual address to hardware */ 901 ret = usb_gadget_map_request(&ep->udc->gadget, &req->req, ep_is_in(ep));
914 if (req->req.dma == DMA_ADDR_INVALID) { 902 if (ret)
915 req->req.dma = dma_map_single(ep->udc->gadget.dev.parent, 903 return ret;
916 req->req.buf,
917 req->req.length, ep_is_in(ep)
918 ? DMA_TO_DEVICE
919 : DMA_FROM_DEVICE);
920 req->mapped = 1;
921 } else {
922 dma_sync_single_for_device(ep->udc->gadget.dev.parent,
923 req->req.dma, req->req.length,
924 ep_is_in(ep)
925 ? DMA_TO_DEVICE
926 : DMA_FROM_DEVICE);
927 req->mapped = 0;
928 }
929 904
930 req->req.status = -EINPROGRESS; 905 req->req.status = -EINPROGRESS;
931 req->req.actual = 0; 906 req->req.actual = 0;
@@ -1290,6 +1265,7 @@ static int ep0_prime_status(struct fsl_udc *udc, int direction)
1290{ 1265{
1291 struct fsl_req *req = udc->status_req; 1266 struct fsl_req *req = udc->status_req;
1292 struct fsl_ep *ep; 1267 struct fsl_ep *ep;
1268 int ret;
1293 1269
1294 if (direction == EP_DIR_IN) 1270 if (direction == EP_DIR_IN)
1295 udc->ep0_dir = USB_DIR_IN; 1271 udc->ep0_dir = USB_DIR_IN;
@@ -1307,10 +1283,9 @@ static int ep0_prime_status(struct fsl_udc *udc, int direction)
1307 req->req.complete = NULL; 1283 req->req.complete = NULL;
1308 req->dtd_count = 0; 1284 req->dtd_count = 0;
1309 1285
1310 req->req.dma = dma_map_single(ep->udc->gadget.dev.parent, 1286 ret = usb_gadget_map_request(&ep->udc->gadget, &req->req, ep_is_in(ep));
1311 req->req.buf, req->req.length, 1287 if (ret)
1312 ep_is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 1288 return ret;
1313 req->mapped = 1;
1314 1289
1315 if (fsl_req_to_dtd(req, GFP_ATOMIC) == 0) 1290 if (fsl_req_to_dtd(req, GFP_ATOMIC) == 0)
1316 fsl_queue_td(ep, req); 1291 fsl_queue_td(ep, req);
@@ -1353,6 +1328,7 @@ static void ch9getstatus(struct fsl_udc *udc, u8 request_type, u16 value,
1353 u16 tmp = 0; /* Status, cpu endian */ 1328 u16 tmp = 0; /* Status, cpu endian */
1354 struct fsl_req *req; 1329 struct fsl_req *req;
1355 struct fsl_ep *ep; 1330 struct fsl_ep *ep;
1331 int ret;
1356 1332
1357 ep = &udc->eps[0]; 1333 ep = &udc->eps[0];
1358 1334
@@ -1390,10 +1366,9 @@ static void ch9getstatus(struct fsl_udc *udc, u8 request_type, u16 value,
1390 req->req.complete = NULL; 1366 req->req.complete = NULL;
1391 req->dtd_count = 0; 1367 req->dtd_count = 0;
1392 1368
1393 req->req.dma = dma_map_single(ep->udc->gadget.dev.parent, 1369 ret = usb_gadget_map_request(&ep->udc->gadget, &req->req, ep_is_in(ep));
1394 req->req.buf, req->req.length, 1370 if (ret)
1395 ep_is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 1371 goto stall;
1396 req->mapped = 1;
1397 1372
1398 /* prime the data phase */ 1373 /* prime the data phase */
1399 if ((fsl_req_to_dtd(req, GFP_ATOMIC) == 0)) 1374 if ((fsl_req_to_dtd(req, GFP_ATOMIC) == 0))
@@ -1964,7 +1939,6 @@ static int fsl_udc_start(struct usb_gadget *g,
1964 driver->driver.bus = NULL; 1939 driver->driver.bus = NULL;
1965 /* hook up the driver */ 1940 /* hook up the driver */
1966 udc_controller->driver = driver; 1941 udc_controller->driver = driver;
1967 udc_controller->gadget.dev.driver = &driver->driver;
1968 spin_unlock_irqrestore(&udc_controller->lock, flags); 1942 spin_unlock_irqrestore(&udc_controller->lock, flags);
1969 1943
1970 if (!IS_ERR_OR_NULL(udc_controller->transceiver)) { 1944 if (!IS_ERR_OR_NULL(udc_controller->transceiver)) {
@@ -1980,7 +1954,6 @@ static int fsl_udc_start(struct usb_gadget *g,
1980 if (retval < 0) { 1954 if (retval < 0) {
1981 ERR("can't bind to transceiver\n"); 1955 ERR("can't bind to transceiver\n");
1982 driver->unbind(&udc_controller->gadget); 1956 driver->unbind(&udc_controller->gadget);
1983 udc_controller->gadget.dev.driver = 0;
1984 udc_controller->driver = 0; 1957 udc_controller->driver = 0;
1985 return retval; 1958 return retval;
1986 } 1959 }
@@ -2023,7 +1996,6 @@ static int fsl_udc_stop(struct usb_gadget *g,
2023 nuke(loop_ep, -ESHUTDOWN); 1996 nuke(loop_ep, -ESHUTDOWN);
2024 spin_unlock_irqrestore(&udc_controller->lock, flags); 1997 spin_unlock_irqrestore(&udc_controller->lock, flags);
2025 1998
2026 udc_controller->gadget.dev.driver = NULL;
2027 udc_controller->driver = NULL; 1999 udc_controller->driver = NULL;
2028 2000
2029 return 0; 2001 return 0;
@@ -2521,12 +2493,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
2521 2493
2522 /* Setup gadget.dev and register with kernel */ 2494 /* Setup gadget.dev and register with kernel */
2523 dev_set_name(&udc_controller->gadget.dev, "gadget"); 2495 dev_set_name(&udc_controller->gadget.dev, "gadget");
2524 udc_controller->gadget.dev.release = fsl_udc_release;
2525 udc_controller->gadget.dev.parent = &pdev->dev;
2526 udc_controller->gadget.dev.of_node = pdev->dev.of_node; 2496 udc_controller->gadget.dev.of_node = pdev->dev.of_node;
2527 ret = device_register(&udc_controller->gadget.dev);
2528 if (ret < 0)
2529 goto err_free_irq;
2530 2497
2531 if (!IS_ERR_OR_NULL(udc_controller->transceiver)) 2498 if (!IS_ERR_OR_NULL(udc_controller->transceiver))
2532 udc_controller->gadget.is_otg = 1; 2499 udc_controller->gadget.is_otg = 1;
@@ -2559,10 +2526,11 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
2559 DTD_ALIGNMENT, UDC_DMA_BOUNDARY); 2526 DTD_ALIGNMENT, UDC_DMA_BOUNDARY);
2560 if (udc_controller->td_pool == NULL) { 2527 if (udc_controller->td_pool == NULL) {
2561 ret = -ENOMEM; 2528 ret = -ENOMEM;
2562 goto err_unregister; 2529 goto err_free_irq;
2563 } 2530 }
2564 2531
2565 ret = usb_add_gadget_udc(&pdev->dev, &udc_controller->gadget); 2532 ret = usb_add_gadget_udc_release(&pdev->dev, &udc_controller->gadget,
2533 fsl_udc_release);
2566 if (ret) 2534 if (ret)
2567 goto err_del_udc; 2535 goto err_del_udc;
2568 2536
@@ -2571,8 +2539,6 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
2571 2539
2572err_del_udc: 2540err_del_udc:
2573 dma_pool_destroy(udc_controller->td_pool); 2541 dma_pool_destroy(udc_controller->td_pool);
2574err_unregister:
2575 device_unregister(&udc_controller->gadget.dev);
2576err_free_irq: 2542err_free_irq:
2577 free_irq(udc_controller->irq, udc_controller); 2543 free_irq(udc_controller->irq, udc_controller);
2578err_iounmap: 2544err_iounmap:
@@ -2622,7 +2588,6 @@ static int __exit fsl_udc_remove(struct platform_device *pdev)
2622 if (pdata->operating_mode == FSL_USB2_DR_DEVICE) 2588 if (pdata->operating_mode == FSL_USB2_DR_DEVICE)
2623 release_mem_region(res->start, resource_size(res)); 2589 release_mem_region(res->start, resource_size(res));
2624 2590
2625 device_unregister(&udc_controller->gadget.dev);
2626 /* free udc --wait for the release() finished */ 2591 /* free udc --wait for the release() finished */
2627 wait_for_completion(&done); 2592 wait_for_completion(&done);
2628 2593
@@ -2747,21 +2712,7 @@ static struct platform_driver udc_driver = {
2747 }, 2712 },
2748}; 2713};
2749 2714
2750static int __init udc_init(void) 2715module_platform_driver_probe(udc_driver, fsl_udc_probe);
2751{
2752 printk(KERN_INFO "%s (%s)\n", driver_desc, DRIVER_VERSION);
2753 return platform_driver_probe(&udc_driver, fsl_udc_probe);
2754}
2755
2756module_init(udc_init);
2757
2758static void __exit udc_exit(void)
2759{
2760 platform_driver_unregister(&udc_driver);
2761 printk(KERN_WARNING "%s unregistered\n", driver_desc);
2762}
2763
2764module_exit(udc_exit);
2765 2716
2766MODULE_DESCRIPTION(DRIVER_DESC); 2717MODULE_DESCRIPTION(DRIVER_DESC);
2767MODULE_AUTHOR(DRIVER_AUTHOR); 2718MODULE_AUTHOR(DRIVER_AUTHOR);
diff --git a/drivers/usb/gadget/fusb300_udc.c b/drivers/usb/gadget/fusb300_udc.c
index 066cb89376de..cec8871b77f9 100644
--- a/drivers/usb/gadget/fusb300_udc.c
+++ b/drivers/usb/gadget/fusb300_udc.c
@@ -394,7 +394,7 @@ static void fusb300_clear_epnstall(struct fusb300 *fusb300, u8 ep)
394 394
395 if (reg & FUSB300_EPSET0_STL) { 395 if (reg & FUSB300_EPSET0_STL) {
396 printk(KERN_DEBUG "EP%d stall... Clear!!\n", ep); 396 printk(KERN_DEBUG "EP%d stall... Clear!!\n", ep);
397 reg &= ~FUSB300_EPSET0_STL; 397 reg |= FUSB300_EPSET0_STL_CLR;
398 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET0(ep)); 398 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET0(ep));
399 } 399 }
400} 400}
@@ -930,33 +930,33 @@ static void fusb300_wait_idma_finished(struct fusb300_ep *ep)
930 930
931 fusb300_clear_int(ep->fusb300, FUSB300_OFFSET_IGR0, 931 fusb300_clear_int(ep->fusb300, FUSB300_OFFSET_IGR0,
932 FUSB300_IGR0_EPn_PRD_INT(ep->epnum)); 932 FUSB300_IGR0_EPn_PRD_INT(ep->epnum));
933 return;
934
933IDMA_RESET: 935IDMA_RESET:
934 fusb300_clear_int(ep->fusb300, FUSB300_OFFSET_IGER0, 936 reg = ioread32(ep->fusb300->reg + FUSB300_OFFSET_IGER0);
935 FUSB300_IGER0_EEPn_PRD_INT(ep->epnum)); 937 reg &= ~FUSB300_IGER0_EEPn_PRD_INT(ep->epnum);
938 iowrite32(reg, ep->fusb300->reg + FUSB300_OFFSET_IGER0);
936} 939}
937 940
938static void fusb300_set_idma(struct fusb300_ep *ep, 941static void fusb300_set_idma(struct fusb300_ep *ep,
939 struct fusb300_request *req) 942 struct fusb300_request *req)
940{ 943{
941 dma_addr_t d; 944 int ret;
942
943 d = dma_map_single(NULL, req->req.buf, req->req.length, DMA_TO_DEVICE);
944 945
945 if (dma_mapping_error(NULL, d)) { 946 ret = usb_gadget_map_request(&ep->fusb300->gadget,
946 printk(KERN_DEBUG "dma_mapping_error\n"); 947 &req->req, DMA_TO_DEVICE);
948 if (ret)
947 return; 949 return;
948 }
949
950 dma_sync_single_for_device(NULL, d, req->req.length, DMA_TO_DEVICE);
951 950
952 fusb300_enable_bit(ep->fusb300, FUSB300_OFFSET_IGER0, 951 fusb300_enable_bit(ep->fusb300, FUSB300_OFFSET_IGER0,
953 FUSB300_IGER0_EEPn_PRD_INT(ep->epnum)); 952 FUSB300_IGER0_EEPn_PRD_INT(ep->epnum));
954 953
955 fusb300_fill_idma_prdtbl(ep, d, req->req.length); 954 fusb300_fill_idma_prdtbl(ep, req->req.dma, req->req.length);
956 /* check idma is done */ 955 /* check idma is done */
957 fusb300_wait_idma_finished(ep); 956 fusb300_wait_idma_finished(ep);
958 957
959 dma_unmap_single(NULL, d, req->req.length, DMA_TO_DEVICE); 958 usb_gadget_unmap_request(&ep->fusb300->gadget,
959 &req->req, DMA_TO_DEVICE);
960} 960}
961 961
962static void in_ep_fifo_handler(struct fusb300_ep *ep) 962static void in_ep_fifo_handler(struct fusb300_ep *ep)
@@ -1316,7 +1316,6 @@ static int fusb300_udc_start(struct usb_gadget *g,
1316 /* hook up the driver */ 1316 /* hook up the driver */
1317 driver->driver.bus = NULL; 1317 driver->driver.bus = NULL;
1318 fusb300->driver = driver; 1318 fusb300->driver = driver;
1319 fusb300->gadget.dev.driver = &driver->driver;
1320 1319
1321 return 0; 1320 return 0;
1322} 1321}
@@ -1327,7 +1326,6 @@ static int fusb300_udc_stop(struct usb_gadget *g,
1327 struct fusb300 *fusb300 = to_fusb300(g); 1326 struct fusb300 *fusb300 = to_fusb300(g);
1328 1327
1329 driver->unbind(&fusb300->gadget); 1328 driver->unbind(&fusb300->gadget);
1330 fusb300->gadget.dev.driver = NULL;
1331 1329
1332 init_controller(fusb300); 1330 init_controller(fusb300);
1333 fusb300->driver = NULL; 1331 fusb300->driver = NULL;
@@ -1422,14 +1420,7 @@ static int __init fusb300_probe(struct platform_device *pdev)
1422 1420
1423 fusb300->gadget.ops = &fusb300_gadget_ops; 1421 fusb300->gadget.ops = &fusb300_gadget_ops;
1424 1422
1425 device_initialize(&fusb300->gadget.dev);
1426
1427 dev_set_name(&fusb300->gadget.dev, "gadget");
1428
1429 fusb300->gadget.max_speed = USB_SPEED_HIGH; 1423 fusb300->gadget.max_speed = USB_SPEED_HIGH;
1430 fusb300->gadget.dev.parent = &pdev->dev;
1431 fusb300->gadget.dev.dma_mask = pdev->dev.dma_mask;
1432 fusb300->gadget.dev.release = pdev->dev.release;
1433 fusb300->gadget.name = udc_name; 1424 fusb300->gadget.name = udc_name;
1434 fusb300->reg = reg; 1425 fusb300->reg = reg;
1435 1426
@@ -1478,19 +1469,10 @@ static int __init fusb300_probe(struct platform_device *pdev)
1478 if (ret) 1469 if (ret)
1479 goto err_add_udc; 1470 goto err_add_udc;
1480 1471
1481 ret = device_add(&fusb300->gadget.dev);
1482 if (ret) {
1483 pr_err("device_add error (%d)\n", ret);
1484 goto err_add_device;
1485 }
1486
1487 dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION); 1472 dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION);
1488 1473
1489 return 0; 1474 return 0;
1490 1475
1491err_add_device:
1492 usb_del_gadget_udc(&fusb300->gadget);
1493
1494err_add_udc: 1476err_add_udc:
1495 fusb300_free_request(&fusb300->ep[0]->ep, fusb300->ep0_req); 1477 fusb300_free_request(&fusb300->ep[0]->ep, fusb300->ep0_req);
1496 1478
diff --git a/drivers/usb/gadget/fusb300_udc.h b/drivers/usb/gadget/fusb300_udc.h
index 6ba444ae8dd5..ae811d8d38b4 100644
--- a/drivers/usb/gadget/fusb300_udc.h
+++ b/drivers/usb/gadget/fusb300_udc.h
@@ -111,8 +111,8 @@
111/* 111/*
112 * * EPn Setting 0 (EPn_SET0, offset = 020H+(n-1)*30H, n=1~15 ) 112 * * EPn Setting 0 (EPn_SET0, offset = 020H+(n-1)*30H, n=1~15 )
113 * */ 113 * */
114#define FUSB300_EPSET0_STL_CLR (1 << 3)
114#define FUSB300_EPSET0_CLRSEQNUM (1 << 2) 115#define FUSB300_EPSET0_CLRSEQNUM (1 << 2)
115#define FUSB300_EPSET0_EPn_TX0BYTE (1 << 1)
116#define FUSB300_EPSET0_STL (1 << 0) 116#define FUSB300_EPSET0_STL (1 << 0)
117 117
118/* 118/*
diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c
index 3b343b23e4b0..787a78e92aa2 100644
--- a/drivers/usb/gadget/g_ffs.c
+++ b/drivers/usb/gadget/g_ffs.c
@@ -13,7 +13,6 @@
13#define pr_fmt(fmt) "g_ffs: " fmt 13#define pr_fmt(fmt) "g_ffs: " fmt
14 14
15#include <linux/module.h> 15#include <linux/module.h>
16
17/* 16/*
18 * kbuild is not very cooperative with respect to linking separately 17 * kbuild is not very cooperative with respect to linking separately
19 * compiled library objects into one module. So for now we won't use 18 * compiled library objects into one module. So for now we won't use
@@ -38,13 +37,16 @@
38# include "u_ether.c" 37# include "u_ether.c"
39 38
40static u8 gfs_hostaddr[ETH_ALEN]; 39static u8 gfs_hostaddr[ETH_ALEN];
40static struct eth_dev *the_dev;
41# ifdef CONFIG_USB_FUNCTIONFS_ETH 41# ifdef CONFIG_USB_FUNCTIONFS_ETH
42static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); 42static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
43 struct eth_dev *dev);
43# endif 44# endif
44#else 45#else
45# define gether_cleanup() do { } while (0) 46# define the_dev NULL
46# define gether_setup(gadget, hostaddr) ((int)0) 47# define gether_cleanup(dev) do { } while (0)
47# define gfs_hostaddr NULL 48# define gfs_hostaddr NULL
49struct eth_dev;
48#endif 50#endif
49 51
50#include "f_fs.c" 52#include "f_fs.c"
@@ -137,7 +139,8 @@ static struct usb_gadget_strings *gfs_dev_strings[] = {
137 139
138struct gfs_configuration { 140struct gfs_configuration {
139 struct usb_configuration c; 141 struct usb_configuration c;
140 int (*eth)(struct usb_configuration *c, u8 *ethaddr); 142 int (*eth)(struct usb_configuration *c, u8 *ethaddr,
143 struct eth_dev *dev);
141} gfs_configurations[] = { 144} gfs_configurations[] = {
142#ifdef CONFIG_USB_FUNCTIONFS_RNDIS 145#ifdef CONFIG_USB_FUNCTIONFS_RNDIS
143 { 146 {
@@ -346,10 +349,13 @@ static int gfs_bind(struct usb_composite_dev *cdev)
346 349
347 if (missing_funcs) 350 if (missing_funcs)
348 return -ENODEV; 351 return -ENODEV;
349 352#if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS
350 ret = gether_setup(cdev->gadget, gfs_hostaddr); 353 the_dev = gether_setup(cdev->gadget, gfs_hostaddr);
351 if (unlikely(ret < 0)) 354#endif
355 if (IS_ERR(the_dev)) {
356 ret = PTR_ERR(the_dev);
352 goto error_quick; 357 goto error_quick;
358 }
353 gfs_ether_setup = true; 359 gfs_ether_setup = true;
354 360
355 ret = usb_string_ids_tab(cdev, gfs_strings); 361 ret = usb_string_ids_tab(cdev, gfs_strings);
@@ -386,7 +392,7 @@ error_unbind:
386 for (i = 0; i < func_num; i++) 392 for (i = 0; i < func_num; i++)
387 functionfs_unbind(ffs_tab[i].ffs_data); 393 functionfs_unbind(ffs_tab[i].ffs_data);
388error: 394error:
389 gether_cleanup(); 395 gether_cleanup(the_dev);
390error_quick: 396error_quick:
391 gfs_ether_setup = false; 397 gfs_ether_setup = false;
392 return ret; 398 return ret;
@@ -410,7 +416,7 @@ static int gfs_unbind(struct usb_composite_dev *cdev)
410 * do...? 416 * do...?
411 */ 417 */
412 if (gfs_ether_setup) 418 if (gfs_ether_setup)
413 gether_cleanup(); 419 gether_cleanup(the_dev);
414 gfs_ether_setup = false; 420 gfs_ether_setup = false;
415 421
416 for (i = func_num; i--; ) 422 for (i = func_num; i--; )
@@ -440,7 +446,7 @@ static int gfs_do_config(struct usb_configuration *c)
440 } 446 }
441 447
442 if (gc->eth) { 448 if (gc->eth) {
443 ret = gc->eth(c, gfs_hostaddr); 449 ret = gc->eth(c, gfs_hostaddr, the_dev);
444 if (unlikely(ret < 0)) 450 if (unlikely(ret < 0))
445 return ret; 451 return ret;
446 } 452 }
@@ -469,11 +475,12 @@ static int gfs_do_config(struct usb_configuration *c)
469 475
470#ifdef CONFIG_USB_FUNCTIONFS_ETH 476#ifdef CONFIG_USB_FUNCTIONFS_ETH
471 477
472static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) 478static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
479 struct eth_dev *dev)
473{ 480{
474 return can_support_ecm(c->cdev->gadget) 481 return can_support_ecm(c->cdev->gadget)
475 ? ecm_bind_config(c, ethaddr) 482 ? ecm_bind_config(c, ethaddr, dev)
476 : geth_bind_config(c, ethaddr); 483 : geth_bind_config(c, ethaddr, dev);
477} 484}
478 485
479#endif 486#endif
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c
index 85742d4c67df..991aba390d9d 100644
--- a/drivers/usb/gadget/goku_udc.c
+++ b/drivers/usb/gadget/goku_udc.c
@@ -51,8 +51,6 @@
51#define DRIVER_DESC "TC86C001 USB Device Controller" 51#define DRIVER_DESC "TC86C001 USB Device Controller"
52#define DRIVER_VERSION "30-Oct 2003" 52#define DRIVER_VERSION "30-Oct 2003"
53 53
54#define DMA_ADDR_INVALID (~(dma_addr_t)0)
55
56static const char driver_name [] = "goku_udc"; 54static const char driver_name [] = "goku_udc";
57static const char driver_desc [] = DRIVER_DESC; 55static const char driver_desc [] = DRIVER_DESC;
58 56
@@ -275,7 +273,6 @@ goku_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags)
275 if (!req) 273 if (!req)
276 return NULL; 274 return NULL;
277 275
278 req->req.dma = DMA_ADDR_INVALID;
279 INIT_LIST_HEAD(&req->queue); 276 INIT_LIST_HEAD(&req->queue);
280 return &req->req; 277 return &req->req;
281} 278}
@@ -1354,7 +1351,6 @@ static int goku_udc_start(struct usb_gadget *g,
1354 /* hook up the driver */ 1351 /* hook up the driver */
1355 driver->driver.bus = NULL; 1352 driver->driver.bus = NULL;
1356 dev->driver = driver; 1353 dev->driver = driver;
1357 dev->gadget.dev.driver = &driver->driver;
1358 1354
1359 /* 1355 /*
1360 * then enable host detection and ep0; and we're ready 1356 * then enable host detection and ep0; and we're ready
@@ -1394,7 +1390,6 @@ static int goku_udc_stop(struct usb_gadget *g,
1394 dev->driver = NULL; 1390 dev->driver = NULL;
1395 stop_activity(dev, driver); 1391 stop_activity(dev, driver);
1396 spin_unlock_irqrestore(&dev->lock, flags); 1392 spin_unlock_irqrestore(&dev->lock, flags);
1397 dev->gadget.dev.driver = NULL;
1398 1393
1399 return 0; 1394 return 0;
1400} 1395}
@@ -1716,8 +1711,6 @@ static void goku_remove(struct pci_dev *pdev)
1716 pci_resource_len (pdev, 0)); 1711 pci_resource_len (pdev, 0));
1717 if (dev->enabled) 1712 if (dev->enabled)
1718 pci_disable_device(pdev); 1713 pci_disable_device(pdev);
1719 if (dev->registered)
1720 device_unregister(&dev->gadget.dev);
1721 1714
1722 pci_set_drvdata(pdev, NULL); 1715 pci_set_drvdata(pdev, NULL);
1723 dev->regs = NULL; 1716 dev->regs = NULL;
@@ -1756,10 +1749,6 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1756 dev->gadget.max_speed = USB_SPEED_FULL; 1749 dev->gadget.max_speed = USB_SPEED_FULL;
1757 1750
1758 /* the "gadget" abstracts/virtualizes the controller */ 1751 /* the "gadget" abstracts/virtualizes the controller */
1759 dev_set_name(&dev->gadget.dev, "gadget");
1760 dev->gadget.dev.parent = &pdev->dev;
1761 dev->gadget.dev.dma_mask = pdev->dev.dma_mask;
1762 dev->gadget.dev.release = gadget_release;
1763 dev->gadget.name = driver_name; 1752 dev->gadget.name = driver_name;
1764 1753
1765 /* now all the pci goodies ... */ 1754 /* now all the pci goodies ... */
@@ -1810,13 +1799,8 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1810 create_proc_read_entry(proc_node_name, 0, NULL, udc_proc_read, dev); 1799 create_proc_read_entry(proc_node_name, 0, NULL, udc_proc_read, dev);
1811#endif 1800#endif
1812 1801
1813 retval = device_register(&dev->gadget.dev); 1802 retval = usb_add_gadget_udc_release(&pdev->dev, &dev->gadget,
1814 if (retval) { 1803 gadget_release);
1815 put_device(&dev->gadget.dev);
1816 goto err;
1817 }
1818 dev->registered = 1;
1819 retval = usb_add_gadget_udc(&pdev->dev, &dev->gadget);
1820 if (retval) 1804 if (retval)
1821 goto err; 1805 goto err;
1822 1806
diff --git a/drivers/usb/gadget/goku_udc.h b/drivers/usb/gadget/goku_udc.h
index b4470d2b1d86..86d2adafe149 100644
--- a/drivers/usb/gadget/goku_udc.h
+++ b/drivers/usb/gadget/goku_udc.h
@@ -250,8 +250,7 @@ struct goku_udc {
250 got_region:1, 250 got_region:1,
251 req_config:1, 251 req_config:1,
252 configured:1, 252 configured:1,
253 enabled:1, 253 enabled:1;
254 registered:1;
255 254
256 /* pci state used to access those endpoints */ 255 /* pci state used to access those endpoints */
257 struct pci_dev *pdev; 256 struct pci_dev *pdev;
diff --git a/drivers/usb/gadget/imx_udc.c b/drivers/usb/gadget/imx_udc.c
index 5bd930d779b9..b5cebd6b0d7a 100644
--- a/drivers/usb/gadget/imx_udc.c
+++ b/drivers/usb/gadget/imx_udc.c
@@ -1338,7 +1338,6 @@ static int imx_udc_start(struct usb_gadget *gadget,
1338 imx_usb = container_of(gadget, struct imx_udc_struct, gadget); 1338 imx_usb = container_of(gadget, struct imx_udc_struct, gadget);
1339 /* first hook up the driver ... */ 1339 /* first hook up the driver ... */
1340 imx_usb->driver = driver; 1340 imx_usb->driver = driver;
1341 imx_usb->gadget.dev.driver = &driver->driver;
1342 1341
1343 D_INI(imx_usb->dev, "<%s> registered gadget driver '%s'\n", 1342 D_INI(imx_usb->dev, "<%s> registered gadget driver '%s'\n",
1344 __func__, driver->driver.name); 1343 __func__, driver->driver.name);
@@ -1358,7 +1357,6 @@ static int imx_udc_stop(struct usb_gadget *gadget,
1358 imx_udc_disable(imx_usb); 1357 imx_udc_disable(imx_usb);
1359 del_timer(&imx_usb->timer); 1358 del_timer(&imx_usb->timer);
1360 1359
1361 imx_usb->gadget.dev.driver = NULL;
1362 imx_usb->driver = NULL; 1360 imx_usb->driver = NULL;
1363 1361
1364 D_INI(imx_usb->dev, "<%s> unregistered gadget driver '%s'\n", 1362 D_INI(imx_usb->dev, "<%s> unregistered gadget driver '%s'\n",
@@ -1461,15 +1459,6 @@ static int __init imx_udc_probe(struct platform_device *pdev)
1461 imx_usb->clk = clk; 1459 imx_usb->clk = clk;
1462 imx_usb->dev = &pdev->dev; 1460 imx_usb->dev = &pdev->dev;
1463 1461
1464 device_initialize(&imx_usb->gadget.dev);
1465
1466 imx_usb->gadget.dev.parent = &pdev->dev;
1467 imx_usb->gadget.dev.dma_mask = pdev->dev.dma_mask;
1468
1469 ret = device_add(&imx_usb->gadget.dev);
1470 if (retval)
1471 goto fail4;
1472
1473 platform_set_drvdata(pdev, imx_usb); 1462 platform_set_drvdata(pdev, imx_usb);
1474 1463
1475 usb_init_data(imx_usb); 1464 usb_init_data(imx_usb);
@@ -1481,11 +1470,9 @@ static int __init imx_udc_probe(struct platform_device *pdev)
1481 1470
1482 ret = usb_add_gadget_udc(&pdev->dev, &imx_usb->gadget); 1471 ret = usb_add_gadget_udc(&pdev->dev, &imx_usb->gadget);
1483 if (ret) 1472 if (ret)
1484 goto fail5; 1473 goto fail4;
1485 1474
1486 return 0; 1475 return 0;
1487fail5:
1488 device_unregister(&imx_usb->gadget.dev);
1489fail4: 1476fail4:
1490 for (i = 0; i < IMX_USB_NB_EP + 1; i++) 1477 for (i = 0; i < IMX_USB_NB_EP + 1; i++)
1491 free_irq(imx_usb->usbd_int[i], imx_usb); 1478 free_irq(imx_usb->usbd_int[i], imx_usb);
@@ -1509,7 +1496,6 @@ static int __exit imx_udc_remove(struct platform_device *pdev)
1509 int i; 1496 int i;
1510 1497
1511 usb_del_gadget_udc(&imx_usb->gadget); 1498 usb_del_gadget_udc(&imx_usb->gadget);
1512 device_unregister(&imx_usb->gadget.dev);
1513 imx_udc_disable(imx_usb); 1499 imx_udc_disable(imx_usb);
1514 del_timer(&imx_usb->timer); 1500 del_timer(&imx_usb->timer);
1515 1501
diff --git a/drivers/usb/gadget/lpc32xx_udc.c b/drivers/usb/gadget/lpc32xx_udc.c
index aa04089d6899..b943d8cdfbf7 100644
--- a/drivers/usb/gadget/lpc32xx_udc.c
+++ b/drivers/usb/gadget/lpc32xx_udc.c
@@ -1469,23 +1469,7 @@ static void done(struct lpc32xx_ep *ep, struct lpc32xx_request *req, int status)
1469 status = req->req.status; 1469 status = req->req.status;
1470 1470
1471 if (ep->lep) { 1471 if (ep->lep) {
1472 enum dma_data_direction direction; 1472 usb_gadget_unmap_request(&udc->gadget, &req->req, ep->is_in);
1473
1474 if (ep->is_in)
1475 direction = DMA_TO_DEVICE;
1476 else
1477 direction = DMA_FROM_DEVICE;
1478
1479 if (req->mapped) {
1480 dma_unmap_single(ep->udc->gadget.dev.parent,
1481 req->req.dma, req->req.length,
1482 direction);
1483 req->req.dma = 0;
1484 req->mapped = 0;
1485 } else
1486 dma_sync_single_for_cpu(ep->udc->gadget.dev.parent,
1487 req->req.dma, req->req.length,
1488 direction);
1489 1473
1490 /* Free DDs */ 1474 /* Free DDs */
1491 udc_dd_free(udc, req->dd_desc_ptr); 1475 udc_dd_free(udc, req->dd_desc_ptr);
@@ -1841,26 +1825,11 @@ static int lpc32xx_ep_queue(struct usb_ep *_ep,
1841 } 1825 }
1842 1826
1843 if (ep->lep) { 1827 if (ep->lep) {
1844 enum dma_data_direction direction;
1845 struct lpc32xx_usbd_dd_gad *dd; 1828 struct lpc32xx_usbd_dd_gad *dd;
1846 1829
1847 /* Map DMA pointer */ 1830 status = usb_gadget_map_request(&udc->gadget, _req, ep->is_in);
1848 if (ep->is_in) 1831 if (status)
1849 direction = DMA_TO_DEVICE; 1832 return status;
1850 else
1851 direction = DMA_FROM_DEVICE;
1852
1853 if (req->req.dma == 0) {
1854 req->req.dma = dma_map_single(
1855 ep->udc->gadget.dev.parent,
1856 req->req.buf, req->req.length, direction);
1857 req->mapped = 1;
1858 } else {
1859 dma_sync_single_for_device(
1860 ep->udc->gadget.dev.parent, req->req.dma,
1861 req->req.length, direction);
1862 req->mapped = 0;
1863 }
1864 1833
1865 /* For the request, build a list of DDs */ 1834 /* For the request, build a list of DDs */
1866 dd = udc_dd_alloc(udc); 1835 dd = udc_dd_alloc(udc);
@@ -2977,7 +2946,6 @@ static int lpc32xx_start(struct usb_gadget *gadget,
2977 } 2946 }
2978 2947
2979 udc->driver = driver; 2948 udc->driver = driver;
2980 udc->gadget.dev.driver = &driver->driver;
2981 udc->gadget.dev.of_node = udc->dev->of_node; 2949 udc->gadget.dev.of_node = udc->dev->of_node;
2982 udc->enabled = 1; 2950 udc->enabled = 1;
2983 udc->selfpowered = 1; 2951 udc->selfpowered = 1;
@@ -3026,7 +2994,6 @@ static int lpc32xx_stop(struct usb_gadget *gadget,
3026 } 2994 }
3027 2995
3028 udc->enabled = 0; 2996 udc->enabled = 0;
3029 udc->gadget.dev.driver = NULL;
3030 udc->driver = NULL; 2997 udc->driver = NULL;
3031 2998
3032 return 0; 2999 return 0;
@@ -3248,12 +3215,6 @@ static int __init lpc32xx_udc_probe(struct platform_device *pdev)
3248 udc_disable(udc); 3215 udc_disable(udc);
3249 udc_reinit(udc); 3216 udc_reinit(udc);
3250 3217
3251 retval = device_register(&udc->gadget.dev);
3252 if (retval < 0) {
3253 dev_err(udc->dev, "Device registration failure\n");
3254 goto dev_register_fail;
3255 }
3256
3257 /* Request IRQs - low and high priority USB device IRQs are routed to 3218 /* Request IRQs - low and high priority USB device IRQs are routed to
3258 * the same handler, while the DMA interrupt is routed elsewhere */ 3219 * the same handler, while the DMA interrupt is routed elsewhere */
3259 retval = request_irq(udc->udp_irq[IRQ_USB_LP], lpc32xx_usb_lp_irq, 3220 retval = request_irq(udc->udp_irq[IRQ_USB_LP], lpc32xx_usb_lp_irq,
@@ -3320,8 +3281,6 @@ irq_dev_fail:
3320irq_hp_fail: 3281irq_hp_fail:
3321 free_irq(udc->udp_irq[IRQ_USB_LP], udc); 3282 free_irq(udc->udp_irq[IRQ_USB_LP], udc);
3322irq_lp_fail: 3283irq_lp_fail:
3323 device_unregister(&udc->gadget.dev);
3324dev_register_fail:
3325 dma_pool_destroy(udc->dd_cache); 3284 dma_pool_destroy(udc->dd_cache);
3326dma_alloc_fail: 3285dma_alloc_fail:
3327 dma_free_coherent(&pdev->dev, UDCA_BUFF_SIZE, 3286 dma_free_coherent(&pdev->dev, UDCA_BUFF_SIZE,
@@ -3376,8 +3335,6 @@ static int lpc32xx_udc_remove(struct platform_device *pdev)
3376 free_irq(udc->udp_irq[IRQ_USB_HP], udc); 3335 free_irq(udc->udp_irq[IRQ_USB_HP], udc);
3377 free_irq(udc->udp_irq[IRQ_USB_LP], udc); 3336 free_irq(udc->udp_irq[IRQ_USB_LP], udc);
3378 3337
3379 device_unregister(&udc->gadget.dev);
3380
3381 clk_disable(udc->usb_otg_clk); 3338 clk_disable(udc->usb_otg_clk);
3382 clk_put(udc->usb_otg_clk); 3339 clk_put(udc->usb_otg_clk);
3383 clk_disable(udc->usb_slv_clk); 3340 clk_disable(udc->usb_slv_clk);
diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c
index c1b8c2dd808d..866ef0999247 100644
--- a/drivers/usb/gadget/m66592-udc.c
+++ b/drivers/usb/gadget/m66592-udc.c
@@ -1471,7 +1471,6 @@ static int m66592_udc_start(struct usb_gadget *g,
1471 /* hook up the driver */ 1471 /* hook up the driver */
1472 driver->driver.bus = NULL; 1472 driver->driver.bus = NULL;
1473 m66592->driver = driver; 1473 m66592->driver = driver;
1474 m66592->gadget.dev.driver = &driver->driver;
1475 1474
1476 m66592_bset(m66592, M66592_VBSE | M66592_URST, M66592_INTENB0); 1475 m66592_bset(m66592, M66592_VBSE | M66592_URST, M66592_INTENB0);
1477 if (m66592_read(m66592, M66592_INTSTS0) & M66592_VBSTS) { 1476 if (m66592_read(m66592, M66592_INTSTS0) & M66592_VBSTS) {
@@ -1494,7 +1493,6 @@ static int m66592_udc_stop(struct usb_gadget *g,
1494 m66592_bclr(m66592, M66592_VBSE | M66592_URST, M66592_INTENB0); 1493 m66592_bclr(m66592, M66592_VBSE | M66592_URST, M66592_INTENB0);
1495 1494
1496 driver->unbind(&m66592->gadget); 1495 driver->unbind(&m66592->gadget);
1497 m66592->gadget.dev.driver = NULL;
1498 1496
1499 init_controller(m66592); 1497 init_controller(m66592);
1500 disable_controller(m66592); 1498 disable_controller(m66592);
@@ -1538,7 +1536,6 @@ static int __exit m66592_remove(struct platform_device *pdev)
1538 struct m66592 *m66592 = dev_get_drvdata(&pdev->dev); 1536 struct m66592 *m66592 = dev_get_drvdata(&pdev->dev);
1539 1537
1540 usb_del_gadget_udc(&m66592->gadget); 1538 usb_del_gadget_udc(&m66592->gadget);
1541 device_del(&m66592->gadget.dev);
1542 1539
1543 del_timer_sync(&m66592->timer); 1540 del_timer_sync(&m66592->timer);
1544 iounmap(m66592->reg); 1541 iounmap(m66592->reg);
@@ -1608,12 +1605,7 @@ static int __init m66592_probe(struct platform_device *pdev)
1608 dev_set_drvdata(&pdev->dev, m66592); 1605 dev_set_drvdata(&pdev->dev, m66592);
1609 1606
1610 m66592->gadget.ops = &m66592_gadget_ops; 1607 m66592->gadget.ops = &m66592_gadget_ops;
1611 device_initialize(&m66592->gadget.dev);
1612 dev_set_name(&m66592->gadget.dev, "gadget");
1613 m66592->gadget.max_speed = USB_SPEED_HIGH; 1608 m66592->gadget.max_speed = USB_SPEED_HIGH;
1614 m66592->gadget.dev.parent = &pdev->dev;
1615 m66592->gadget.dev.dma_mask = pdev->dev.dma_mask;
1616 m66592->gadget.dev.release = pdev->dev.release;
1617 m66592->gadget.name = udc_name; 1609 m66592->gadget.name = udc_name;
1618 1610
1619 init_timer(&m66592->timer); 1611 init_timer(&m66592->timer);
@@ -1674,12 +1666,6 @@ static int __init m66592_probe(struct platform_device *pdev)
1674 1666
1675 init_controller(m66592); 1667 init_controller(m66592);
1676 1668
1677 ret = device_add(&m66592->gadget.dev);
1678 if (ret) {
1679 pr_err("device_add error (%d)\n", ret);
1680 goto err_device_add;
1681 }
1682
1683 ret = usb_add_gadget_udc(&pdev->dev, &m66592->gadget); 1669 ret = usb_add_gadget_udc(&pdev->dev, &m66592->gadget);
1684 if (ret) 1670 if (ret)
1685 goto err_add_udc; 1671 goto err_add_udc;
@@ -1688,9 +1674,6 @@ static int __init m66592_probe(struct platform_device *pdev)
1688 return 0; 1674 return 0;
1689 1675
1690err_add_udc: 1676err_add_udc:
1691 device_del(&m66592->gadget.dev);
1692
1693err_device_add:
1694 m66592_free_request(&m66592->ep[0].ep, m66592->ep0_req); 1677 m66592_free_request(&m66592->ep[0].ep, m66592->ep0_req);
1695 1678
1696clean_up3: 1679clean_up3:
diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c
index 20bbbf917fc2..a74ebefc7682 100644
--- a/drivers/usb/gadget/multi.c
+++ b/drivers/usb/gadget/multi.c
@@ -135,8 +135,8 @@ static struct fsg_common fsg_common;
135 135
136static u8 hostaddr[ETH_ALEN]; 136static u8 hostaddr[ETH_ALEN];
137 137
138static unsigned char tty_line;
139static struct usb_function_instance *fi_acm; 138static struct usb_function_instance *fi_acm;
139static struct eth_dev *the_dev;
140 140
141/********** RNDIS **********/ 141/********** RNDIS **********/
142 142
@@ -152,7 +152,7 @@ static __init int rndis_do_config(struct usb_configuration *c)
152 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 152 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
153 } 153 }
154 154
155 ret = rndis_bind_config(c, hostaddr); 155 ret = rndis_bind_config(c, hostaddr, the_dev);
156 if (ret < 0) 156 if (ret < 0)
157 return ret; 157 return ret;
158 158
@@ -214,7 +214,7 @@ static __init int cdc_do_config(struct usb_configuration *c)
214 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 214 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
215 } 215 }
216 216
217 ret = ecm_bind_config(c, hostaddr); 217 ret = ecm_bind_config(c, hostaddr, the_dev);
218 if (ret < 0) 218 if (ret < 0)
219 return ret; 219 return ret;
220 220
@@ -269,7 +269,6 @@ static int cdc_config_register(struct usb_composite_dev *cdev)
269static int __ref multi_bind(struct usb_composite_dev *cdev) 269static int __ref multi_bind(struct usb_composite_dev *cdev)
270{ 270{
271 struct usb_gadget *gadget = cdev->gadget; 271 struct usb_gadget *gadget = cdev->gadget;
272 struct f_serial_opts *opts;
273 int status; 272 int status;
274 273
275 if (!can_support_ecm(cdev->gadget)) { 274 if (!can_support_ecm(cdev->gadget)) {
@@ -279,24 +278,17 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
279 } 278 }
280 279
281 /* set up network link layer */ 280 /* set up network link layer */
282 status = gether_setup(cdev->gadget, hostaddr); 281 the_dev = gether_setup(cdev->gadget, hostaddr);
283 if (status < 0) 282 if (IS_ERR(the_dev))
284 return status; 283 return PTR_ERR(the_dev);
285 284
286 /* set up serial link layer */ 285 /* set up serial link layer */
287 status = gserial_alloc_line(&tty_line);
288 if (status < 0)
289 goto fail0;
290
291 fi_acm = usb_get_function_instance("acm"); 286 fi_acm = usb_get_function_instance("acm");
292 if (IS_ERR(fi_acm)) { 287 if (IS_ERR(fi_acm)) {
293 status = PTR_ERR(fi_acm); 288 status = PTR_ERR(fi_acm);
294 goto fail0dot5; 289 goto fail0;
295 } 290 }
296 291
297 opts = container_of(fi_acm, struct f_serial_opts, func_inst);
298 opts->port_num = tty_line;
299
300 /* set up mass storage function */ 292 /* set up mass storage function */
301 { 293 {
302 void *retp; 294 void *retp;
@@ -334,10 +326,8 @@ fail2:
334 fsg_common_put(&fsg_common); 326 fsg_common_put(&fsg_common);
335fail1: 327fail1:
336 usb_put_function_instance(fi_acm); 328 usb_put_function_instance(fi_acm);
337fail0dot5:
338 gserial_free_line(tty_line);
339fail0: 329fail0:
340 gether_cleanup(); 330 gether_cleanup(the_dev);
341 return status; 331 return status;
342} 332}
343 333
@@ -350,8 +340,7 @@ static int __exit multi_unbind(struct usb_composite_dev *cdev)
350 usb_put_function(f_acm_rndis); 340 usb_put_function(f_acm_rndis);
351#endif 341#endif
352 usb_put_function_instance(fi_acm); 342 usb_put_function_instance(fi_acm);
353 gserial_free_line(tty_line); 343 gether_cleanup(the_dev);
354 gether_cleanup();
355 return 0; 344 return 0;
356} 345}
357 346
diff --git a/drivers/usb/gadget/mv_u3d_core.c b/drivers/usb/gadget/mv_u3d_core.c
index b5cea273c957..58288e9cf728 100644
--- a/drivers/usb/gadget/mv_u3d_core.c
+++ b/drivers/usb/gadget/mv_u3d_core.c
@@ -30,9 +30,6 @@
30#include <linux/platform_device.h> 30#include <linux/platform_device.h>
31#include <linux/platform_data/mv_usb.h> 31#include <linux/platform_data/mv_usb.h>
32#include <linux/clk.h> 32#include <linux/clk.h>
33#include <asm/system.h>
34#include <asm/unaligned.h>
35#include <asm/byteorder.h>
36 33
37#include "mv_u3d.h" 34#include "mv_u3d.h"
38 35
@@ -125,7 +122,7 @@ static int mv_u3d_process_ep_req(struct mv_u3d *u3d, int index,
125 struct mv_u3d_trb *curr_trb; 122 struct mv_u3d_trb *curr_trb;
126 dma_addr_t cur_deq_lo; 123 dma_addr_t cur_deq_lo;
127 struct mv_u3d_ep_context *curr_ep_context; 124 struct mv_u3d_ep_context *curr_ep_context;
128 int trb_complete, actual, remaining_length; 125 int trb_complete, actual, remaining_length = 0;
129 int direction, ep_num; 126 int direction, ep_num;
130 int retval = 0; 127 int retval = 0;
131 u32 tmp, status, length; 128 u32 tmp, status, length;
@@ -189,6 +186,8 @@ static int mv_u3d_process_ep_req(struct mv_u3d *u3d, int index,
189 */ 186 */
190static 187static
191void mv_u3d_done(struct mv_u3d_ep *ep, struct mv_u3d_req *req, int status) 188void mv_u3d_done(struct mv_u3d_ep *ep, struct mv_u3d_req *req, int status)
189 __releases(&ep->udc->lock)
190 __acquires(&ep->udc->lock)
192{ 191{
193 struct mv_u3d *u3d = (struct mv_u3d *)ep->u3d; 192 struct mv_u3d *u3d = (struct mv_u3d *)ep->u3d;
194 193
@@ -812,19 +811,19 @@ mv_u3d_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
812 return 0; 811 return 0;
813 } 812 }
814 813
815 dev_dbg(u3d->dev, "%s: %s, req: 0x%x\n", 814 dev_dbg(u3d->dev, "%s: %s, req: 0x%p\n",
816 __func__, _ep->name, (u32)req); 815 __func__, _ep->name, req);
817 816
818 /* catch various bogus parameters */ 817 /* catch various bogus parameters */
819 if (!req->req.complete || !req->req.buf 818 if (!req->req.complete || !req->req.buf
820 || !list_empty(&req->queue)) { 819 || !list_empty(&req->queue)) {
821 dev_err(u3d->dev, 820 dev_err(u3d->dev,
822 "%s, bad params, _req: 0x%x," 821 "%s, bad params, _req: 0x%p,"
823 "req->req.complete: 0x%x, req->req.buf: 0x%x," 822 "req->req.complete: 0x%p, req->req.buf: 0x%p,"
824 "list_empty: 0x%x\n", 823 "list_empty: 0x%x\n",
825 __func__, (u32)_req, 824 __func__, _req,
826 (u32)req->req.complete, (u32)req->req.buf, 825 req->req.complete, req->req.buf,
827 (u32)list_empty(&req->queue)); 826 list_empty(&req->queue));
828 return -EINVAL; 827 return -EINVAL;
829 } 828 }
830 if (unlikely(!ep->ep.desc)) { 829 if (unlikely(!ep->ep.desc)) {
@@ -905,7 +904,7 @@ static int mv_u3d_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
905 struct mv_u3d_req, queue); 904 struct mv_u3d_req, queue);
906 905
907 /* Point first TRB of next request to the EP context. */ 906 /* Point first TRB of next request to the EP context. */
908 iowrite32((u32) next_req->trb_head, 907 iowrite32((unsigned long) next_req->trb_head,
909 &ep_context->trb_addr_lo); 908 &ep_context->trb_addr_lo);
910 } else { 909 } else {
911 struct mv_u3d_ep_context *ep_context; 910 struct mv_u3d_ep_context *ep_context;
@@ -1264,7 +1263,6 @@ static int mv_u3d_start(struct usb_gadget *g,
1264 /* hook up the driver ... */ 1263 /* hook up the driver ... */
1265 driver->driver.bus = NULL; 1264 driver->driver.bus = NULL;
1266 u3d->driver = driver; 1265 u3d->driver = driver;
1267 u3d->gadget.dev.driver = &driver->driver;
1268 1266
1269 u3d->ep0_dir = USB_DIR_OUT; 1267 u3d->ep0_dir = USB_DIR_OUT;
1270 1268
@@ -1302,7 +1300,6 @@ static int mv_u3d_stop(struct usb_gadget *g,
1302 1300
1303 spin_unlock_irqrestore(&u3d->lock, flags); 1301 spin_unlock_irqrestore(&u3d->lock, flags);
1304 1302
1305 u3d->gadget.dev.driver = NULL;
1306 u3d->driver = NULL; 1303 u3d->driver = NULL;
1307 1304
1308 return 0; 1305 return 0;
@@ -1525,6 +1522,8 @@ static int mv_u3d_is_set_configuration(struct usb_ctrlrequest *setup)
1525 1522
1526static void mv_u3d_handle_setup_packet(struct mv_u3d *u3d, u8 ep_num, 1523static void mv_u3d_handle_setup_packet(struct mv_u3d *u3d, u8 ep_num,
1527 struct usb_ctrlrequest *setup) 1524 struct usb_ctrlrequest *setup)
1525 __releases(&u3c->lock)
1526 __acquires(&u3c->lock)
1528{ 1527{
1529 bool delegate = false; 1528 bool delegate = false;
1530 1529
@@ -1758,11 +1757,6 @@ static irqreturn_t mv_u3d_irq(int irq, void *dev)
1758 return IRQ_HANDLED; 1757 return IRQ_HANDLED;
1759} 1758}
1760 1759
1761static void mv_u3d_gadget_release(struct device *dev)
1762{
1763 dev_dbg(dev, "%s\n", __func__);
1764}
1765
1766static int mv_u3d_remove(struct platform_device *dev) 1760static int mv_u3d_remove(struct platform_device *dev)
1767{ 1761{
1768 struct mv_u3d *u3d = platform_get_drvdata(dev); 1762 struct mv_u3d *u3d = platform_get_drvdata(dev);
@@ -1792,8 +1786,6 @@ static int mv_u3d_remove(struct platform_device *dev)
1792 1786
1793 clk_put(u3d->clk); 1787 clk_put(u3d->clk);
1794 1788
1795 device_unregister(&u3d->gadget.dev);
1796
1797 platform_set_drvdata(dev, NULL); 1789 platform_set_drvdata(dev, NULL);
1798 1790
1799 kfree(u3d); 1791 kfree(u3d);
@@ -1829,7 +1821,7 @@ static int mv_u3d_probe(struct platform_device *dev)
1829 u3d->dev = &dev->dev; 1821 u3d->dev = &dev->dev;
1830 u3d->vbus = pdata->vbus; 1822 u3d->vbus = pdata->vbus;
1831 1823
1832 u3d->clk = clk_get(&dev->dev, pdata->clkname[0]); 1824 u3d->clk = clk_get(&dev->dev, NULL);
1833 if (IS_ERR(u3d->clk)) { 1825 if (IS_ERR(u3d->clk)) {
1834 retval = PTR_ERR(u3d->clk); 1826 retval = PTR_ERR(u3d->clk);
1835 goto err_get_clk; 1827 goto err_get_clk;
@@ -1849,8 +1841,9 @@ static int mv_u3d_probe(struct platform_device *dev)
1849 retval = -EBUSY; 1841 retval = -EBUSY;
1850 goto err_map_cap_regs; 1842 goto err_map_cap_regs;
1851 } else { 1843 } else {
1852 dev_dbg(&dev->dev, "cap_regs address: 0x%x/0x%x\n", 1844 dev_dbg(&dev->dev, "cap_regs address: 0x%lx/0x%lx\n",
1853 (unsigned int)r->start, (unsigned int)u3d->cap_regs); 1845 (unsigned long) r->start,
1846 (unsigned long) u3d->cap_regs);
1854 } 1847 }
1855 1848
1856 /* we will access controller register, so enable the u3d controller */ 1849 /* we will access controller register, so enable the u3d controller */
@@ -1864,10 +1857,10 @@ static int mv_u3d_probe(struct platform_device *dev)
1864 } 1857 }
1865 } 1858 }
1866 1859
1867 u3d->op_regs = (struct mv_u3d_op_regs __iomem *)((u32)u3d->cap_regs 1860 u3d->op_regs = (struct mv_u3d_op_regs __iomem *)(u3d->cap_regs
1868 + MV_U3D_USB3_OP_REGS_OFFSET); 1861 + MV_U3D_USB3_OP_REGS_OFFSET);
1869 1862
1870 u3d->vuc_regs = (struct mv_u3d_vuc_regs __iomem *)((u32)u3d->cap_regs 1863 u3d->vuc_regs = (struct mv_u3d_vuc_regs __iomem *)(u3d->cap_regs
1871 + ioread32(&u3d->cap_regs->vuoff)); 1864 + ioread32(&u3d->cap_regs->vuoff));
1872 1865
1873 u3d->max_eps = 16; 1866 u3d->max_eps = 16;
@@ -1957,16 +1950,8 @@ static int mv_u3d_probe(struct platform_device *dev)
1957 u3d->gadget.speed = USB_SPEED_UNKNOWN; /* speed */ 1950 u3d->gadget.speed = USB_SPEED_UNKNOWN; /* speed */
1958 1951
1959 /* the "gadget" abstracts/virtualizes the controller */ 1952 /* the "gadget" abstracts/virtualizes the controller */
1960 dev_set_name(&u3d->gadget.dev, "gadget");
1961 u3d->gadget.dev.parent = &dev->dev;
1962 u3d->gadget.dev.dma_mask = dev->dev.dma_mask;
1963 u3d->gadget.dev.release = mv_u3d_gadget_release;
1964 u3d->gadget.name = driver_name; /* gadget name */ 1953 u3d->gadget.name = driver_name; /* gadget name */
1965 1954
1966 retval = device_register(&u3d->gadget.dev);
1967 if (retval)
1968 goto err_register_gadget_device;
1969
1970 mv_u3d_eps_init(u3d); 1955 mv_u3d_eps_init(u3d);
1971 1956
1972 /* external vbus detection */ 1957 /* external vbus detection */
@@ -1991,8 +1976,6 @@ static int mv_u3d_probe(struct platform_device *dev)
1991 return 0; 1976 return 0;
1992 1977
1993err_unregister: 1978err_unregister:
1994 device_unregister(&u3d->gadget.dev);
1995err_register_gadget_device:
1996 free_irq(u3d->irq, &dev->dev); 1979 free_irq(u3d->irq, &dev->dev);
1997err_request_irq: 1980err_request_irq:
1998err_get_irq: 1981err_get_irq:
@@ -2021,7 +2004,7 @@ err_pdata:
2021 return retval; 2004 return retval;
2022} 2005}
2023 2006
2024#ifdef CONFIG_PM 2007#ifdef CONFIG_PM_SLEEP
2025static int mv_u3d_suspend(struct device *dev) 2008static int mv_u3d_suspend(struct device *dev)
2026{ 2009{
2027 struct mv_u3d *u3d = dev_get_drvdata(dev); 2010 struct mv_u3d *u3d = dev_get_drvdata(dev);
@@ -2064,10 +2047,10 @@ static int mv_u3d_resume(struct device *dev)
2064 2047
2065 return 0; 2048 return 0;
2066} 2049}
2067
2068SIMPLE_DEV_PM_OPS(mv_u3d_pm_ops, mv_u3d_suspend, mv_u3d_resume);
2069#endif 2050#endif
2070 2051
2052static SIMPLE_DEV_PM_OPS(mv_u3d_pm_ops, mv_u3d_suspend, mv_u3d_resume);
2053
2071static void mv_u3d_shutdown(struct platform_device *dev) 2054static void mv_u3d_shutdown(struct platform_device *dev)
2072{ 2055{
2073 struct mv_u3d *u3d = dev_get_drvdata(&dev->dev); 2056 struct mv_u3d *u3d = dev_get_drvdata(&dev->dev);
@@ -2080,14 +2063,12 @@ static void mv_u3d_shutdown(struct platform_device *dev)
2080 2063
2081static struct platform_driver mv_u3d_driver = { 2064static struct platform_driver mv_u3d_driver = {
2082 .probe = mv_u3d_probe, 2065 .probe = mv_u3d_probe,
2083 .remove = __exit_p(mv_u3d_remove), 2066 .remove = mv_u3d_remove,
2084 .shutdown = mv_u3d_shutdown, 2067 .shutdown = mv_u3d_shutdown,
2085 .driver = { 2068 .driver = {
2086 .owner = THIS_MODULE, 2069 .owner = THIS_MODULE,
2087 .name = "mv-u3d", 2070 .name = "mv-u3d",
2088#ifdef CONFIG_PM
2089 .pm = &mv_u3d_pm_ops, 2071 .pm = &mv_u3d_pm_ops,
2090#endif
2091 }, 2072 },
2092}; 2073};
2093 2074
diff --git a/drivers/usb/gadget/mv_udc.h b/drivers/usb/gadget/mv_udc.h
index 9073436d8b24..be77f207dbaf 100644
--- a/drivers/usb/gadget/mv_udc.h
+++ b/drivers/usb/gadget/mv_udc.h
@@ -222,8 +222,7 @@ struct mv_udc {
222 struct mv_usb_platform_data *pdata; 222 struct mv_usb_platform_data *pdata;
223 223
224 /* some SOC has mutiple clock sources for USB*/ 224 /* some SOC has mutiple clock sources for USB*/
225 unsigned int clknum; 225 struct clk *clk;
226 struct clk *clk[0];
227}; 226};
228 227
229/* endpoint data structure */ 228/* endpoint data structure */
diff --git a/drivers/usb/gadget/mv_udc_core.c b/drivers/usb/gadget/mv_udc_core.c
index c8cf959057fe..c2a57023e467 100644
--- a/drivers/usb/gadget/mv_udc_core.c
+++ b/drivers/usb/gadget/mv_udc_core.c
@@ -212,6 +212,8 @@ static int process_ep_req(struct mv_udc *udc, int index,
212 * request is still in progress. 212 * request is still in progress.
213 */ 213 */
214static void done(struct mv_ep *ep, struct mv_req *req, int status) 214static void done(struct mv_ep *ep, struct mv_req *req, int status)
215 __releases(&ep->udc->lock)
216 __acquires(&ep->udc->lock)
215{ 217{
216 struct mv_udc *udc = NULL; 218 struct mv_udc *udc = NULL;
217 unsigned char stopped = ep->stopped; 219 unsigned char stopped = ep->stopped;
@@ -237,18 +239,7 @@ static void done(struct mv_ep *ep, struct mv_req *req, int status)
237 dma_pool_free(udc->dtd_pool, curr_td, curr_td->td_dma); 239 dma_pool_free(udc->dtd_pool, curr_td, curr_td->td_dma);
238 } 240 }
239 241
240 if (req->mapped) { 242 usb_gadget_unmap_request(&udc->gadget, &req->req, ep_dir(ep));
241 dma_unmap_single(ep->udc->gadget.dev.parent,
242 req->req.dma, req->req.length,
243 ((ep_dir(ep) == EP_DIR_IN) ?
244 DMA_TO_DEVICE : DMA_FROM_DEVICE));
245 req->req.dma = DMA_ADDR_INVALID;
246 req->mapped = 0;
247 } else
248 dma_sync_single_for_cpu(ep->udc->gadget.dev.parent,
249 req->req.dma, req->req.length,
250 ((ep_dir(ep) == EP_DIR_IN) ?
251 DMA_TO_DEVICE : DMA_FROM_DEVICE));
252 243
253 if (status && (status != -ESHUTDOWN)) 244 if (status && (status != -ESHUTDOWN))
254 dev_info(&udc->dev->dev, "complete %s req %p stat %d len %u/%u", 245 dev_info(&udc->dev->dev, "complete %s req %p stat %d len %u/%u",
@@ -732,21 +723,9 @@ mv_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
732 req->ep = ep; 723 req->ep = ep;
733 724
734 /* map virtual address to hardware */ 725 /* map virtual address to hardware */
735 if (req->req.dma == DMA_ADDR_INVALID) { 726 retval = usb_gadget_map_request(&udc->gadget, _req, ep_dir(ep));
736 req->req.dma = dma_map_single(ep->udc->gadget.dev.parent, 727 if (retval)
737 req->req.buf, 728 return retval;
738 req->req.length, ep_dir(ep)
739 ? DMA_TO_DEVICE
740 : DMA_FROM_DEVICE);
741 req->mapped = 1;
742 } else {
743 dma_sync_single_for_device(ep->udc->gadget.dev.parent,
744 req->req.dma, req->req.length,
745 ep_dir(ep)
746 ? DMA_TO_DEVICE
747 : DMA_FROM_DEVICE);
748 req->mapped = 0;
749 }
750 729
751 req->req.status = -EINPROGRESS; 730 req->req.status = -EINPROGRESS;
752 req->req.actual = 0; 731 req->req.actual = 0;
@@ -780,18 +759,7 @@ mv_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
780 return 0; 759 return 0;
781 760
782err_unmap_dma: 761err_unmap_dma:
783 if (req->mapped) { 762 usb_gadget_unmap_request(&udc->gadget, _req, ep_dir(ep));
784 dma_unmap_single(ep->udc->gadget.dev.parent,
785 req->req.dma, req->req.length,
786 ((ep_dir(ep) == EP_DIR_IN) ?
787 DMA_TO_DEVICE : DMA_FROM_DEVICE));
788 req->req.dma = DMA_ADDR_INVALID;
789 req->mapped = 0;
790 } else
791 dma_sync_single_for_cpu(ep->udc->gadget.dev.parent,
792 req->req.dma, req->req.length,
793 ((ep_dir(ep) == EP_DIR_IN) ?
794 DMA_TO_DEVICE : DMA_FROM_DEVICE));
795 763
796 return retval; 764 return retval;
797} 765}
@@ -1006,18 +974,12 @@ static struct usb_ep_ops mv_ep_ops = {
1006 974
1007static void udc_clock_enable(struct mv_udc *udc) 975static void udc_clock_enable(struct mv_udc *udc)
1008{ 976{
1009 unsigned int i; 977 clk_prepare_enable(udc->clk);
1010
1011 for (i = 0; i < udc->clknum; i++)
1012 clk_prepare_enable(udc->clk[i]);
1013} 978}
1014 979
1015static void udc_clock_disable(struct mv_udc *udc) 980static void udc_clock_disable(struct mv_udc *udc)
1016{ 981{
1017 unsigned int i; 982 clk_disable_unprepare(udc->clk);
1018
1019 for (i = 0; i < udc->clknum; i++)
1020 clk_disable_unprepare(udc->clk[i]);
1021} 983}
1022 984
1023static void udc_stop(struct mv_udc *udc) 985static void udc_stop(struct mv_udc *udc)
@@ -1386,7 +1348,6 @@ static int mv_udc_start(struct usb_gadget *gadget,
1386 /* hook up the driver ... */ 1348 /* hook up the driver ... */
1387 driver->driver.bus = NULL; 1349 driver->driver.bus = NULL;
1388 udc->driver = driver; 1350 udc->driver = driver;
1389 udc->gadget.dev.driver = &driver->driver;
1390 1351
1391 udc->usb_state = USB_STATE_ATTACHED; 1352 udc->usb_state = USB_STATE_ATTACHED;
1392 udc->ep0_state = WAIT_FOR_SETUP; 1353 udc->ep0_state = WAIT_FOR_SETUP;
@@ -1401,7 +1362,6 @@ static int mv_udc_start(struct usb_gadget *gadget,
1401 dev_err(&udc->dev->dev, 1362 dev_err(&udc->dev->dev,
1402 "unable to register peripheral to otg\n"); 1363 "unable to register peripheral to otg\n");
1403 udc->driver = NULL; 1364 udc->driver = NULL;
1404 udc->gadget.dev.driver = NULL;
1405 return retval; 1365 return retval;
1406 } 1366 }
1407 } 1367 }
@@ -1437,7 +1397,6 @@ static int mv_udc_stop(struct usb_gadget *gadget,
1437 spin_unlock_irqrestore(&udc->lock, flags); 1397 spin_unlock_irqrestore(&udc->lock, flags);
1438 1398
1439 /* unbind gadget driver */ 1399 /* unbind gadget driver */
1440 udc->gadget.dev.driver = NULL;
1441 udc->driver = NULL; 1400 udc->driver = NULL;
1442 1401
1443 return 0; 1402 return 0;
@@ -1528,14 +1487,7 @@ udc_prime_status(struct mv_udc *udc, u8 direction, u16 status, bool empty)
1528 1487
1529 return 0; 1488 return 0;
1530out: 1489out:
1531 if (req->mapped) { 1490 usb_gadget_unmap_request(&udc->gadget, &req->req, ep_dir(ep));
1532 dma_unmap_single(ep->udc->gadget.dev.parent,
1533 req->req.dma, req->req.length,
1534 ((ep_dir(ep) == EP_DIR_IN) ?
1535 DMA_TO_DEVICE : DMA_FROM_DEVICE));
1536 req->req.dma = DMA_ADDR_INVALID;
1537 req->mapped = 0;
1538 }
1539 1491
1540 return retval; 1492 return retval;
1541} 1493}
@@ -1695,6 +1647,8 @@ out:
1695 1647
1696static void handle_setup_packet(struct mv_udc *udc, u8 ep_num, 1648static void handle_setup_packet(struct mv_udc *udc, u8 ep_num,
1697 struct usb_ctrlrequest *setup) 1649 struct usb_ctrlrequest *setup)
1650 __releases(&ep->udc->lock)
1651 __acquires(&ep->udc->lock)
1698{ 1652{
1699 bool delegate = false; 1653 bool delegate = false;
1700 1654
@@ -1891,7 +1845,7 @@ static void irq_process_tr_complete(struct mv_udc *udc)
1891 } 1845 }
1892} 1846}
1893 1847
1894void irq_process_reset(struct mv_udc *udc) 1848static void irq_process_reset(struct mv_udc *udc)
1895{ 1849{
1896 u32 tmp; 1850 u32 tmp;
1897 unsigned int loops; 1851 unsigned int loops;
@@ -2138,8 +2092,6 @@ static int mv_udc_remove(struct platform_device *pdev)
2138 2092
2139 mv_udc_disable(udc); 2093 mv_udc_disable(udc);
2140 2094
2141 device_unregister(&udc->gadget.dev);
2142
2143 /* free dev, wait for the release() finished */ 2095 /* free dev, wait for the release() finished */
2144 wait_for_completion(udc->done); 2096 wait_for_completion(udc->done);
2145 2097
@@ -2151,7 +2103,6 @@ static int mv_udc_probe(struct platform_device *pdev)
2151 struct mv_usb_platform_data *pdata = pdev->dev.platform_data; 2103 struct mv_usb_platform_data *pdata = pdev->dev.platform_data;
2152 struct mv_udc *udc; 2104 struct mv_udc *udc;
2153 int retval = 0; 2105 int retval = 0;
2154 int clk_i = 0;
2155 struct resource *r; 2106 struct resource *r;
2156 size_t size; 2107 size_t size;
2157 2108
@@ -2160,8 +2111,7 @@ static int mv_udc_probe(struct platform_device *pdev)
2160 return -ENODEV; 2111 return -ENODEV;
2161 } 2112 }
2162 2113
2163 size = sizeof(*udc) + sizeof(struct clk *) * pdata->clknum; 2114 udc = devm_kzalloc(&pdev->dev, sizeof(*udc), GFP_KERNEL);
2164 udc = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
2165 if (udc == NULL) { 2115 if (udc == NULL) {
2166 dev_err(&pdev->dev, "failed to allocate memory for udc\n"); 2116 dev_err(&pdev->dev, "failed to allocate memory for udc\n");
2167 return -ENOMEM; 2117 return -ENOMEM;
@@ -2173,26 +2123,24 @@ static int mv_udc_probe(struct platform_device *pdev)
2173 2123
2174 udc->dev = pdev; 2124 udc->dev = pdev;
2175 2125
2176#ifdef CONFIG_USB_OTG_UTILS
2177 if (pdata->mode == MV_USB_MODE_OTG) { 2126 if (pdata->mode == MV_USB_MODE_OTG) {
2178 udc->transceiver = devm_usb_get_phy(&pdev->dev, 2127 udc->transceiver = devm_usb_get_phy(&pdev->dev,
2179 USB_PHY_TYPE_USB2); 2128 USB_PHY_TYPE_USB2);
2180 if (IS_ERR_OR_NULL(udc->transceiver)) { 2129 if (IS_ERR(udc->transceiver)) {
2130 retval = PTR_ERR(udc->transceiver);
2131
2132 if (retval == -ENXIO)
2133 return retval;
2134
2181 udc->transceiver = NULL; 2135 udc->transceiver = NULL;
2182 return -ENODEV; 2136 return -EPROBE_DEFER;
2183 } 2137 }
2184 } 2138 }
2185#endif
2186 2139
2187 udc->clknum = pdata->clknum; 2140 /* udc only have one sysclk. */
2188 for (clk_i = 0; clk_i < udc->clknum; clk_i++) { 2141 udc->clk = devm_clk_get(&pdev->dev, NULL);
2189 udc->clk[clk_i] = devm_clk_get(&pdev->dev, 2142 if (IS_ERR(udc->clk))
2190 pdata->clkname[clk_i]); 2143 return PTR_ERR(udc->clk);
2191 if (IS_ERR(udc->clk[clk_i])) {
2192 retval = PTR_ERR(udc->clk[clk_i]);
2193 return retval;
2194 }
2195 }
2196 2144
2197 r = platform_get_resource_byname(udc->dev, IORESOURCE_MEM, "capregs"); 2145 r = platform_get_resource_byname(udc->dev, IORESOURCE_MEM, "capregs");
2198 if (r == NULL) { 2146 if (r == NULL) {
@@ -2311,16 +2259,8 @@ static int mv_udc_probe(struct platform_device *pdev)
2311 udc->gadget.max_speed = USB_SPEED_HIGH; /* support dual speed */ 2259 udc->gadget.max_speed = USB_SPEED_HIGH; /* support dual speed */
2312 2260
2313 /* the "gadget" abstracts/virtualizes the controller */ 2261 /* the "gadget" abstracts/virtualizes the controller */
2314 dev_set_name(&udc->gadget.dev, "gadget");
2315 udc->gadget.dev.parent = &pdev->dev;
2316 udc->gadget.dev.dma_mask = pdev->dev.dma_mask;
2317 udc->gadget.dev.release = gadget_release;
2318 udc->gadget.name = driver_name; /* gadget name */ 2262 udc->gadget.name = driver_name; /* gadget name */
2319 2263
2320 retval = device_register(&udc->gadget.dev);
2321 if (retval)
2322 goto err_destroy_dma;
2323
2324 eps_init(udc); 2264 eps_init(udc);
2325 2265
2326 /* VBUS detect: we can disable/enable clock on demand.*/ 2266 /* VBUS detect: we can disable/enable clock on demand.*/
@@ -2342,7 +2282,7 @@ static int mv_udc_probe(struct platform_device *pdev)
2342 if (!udc->qwork) { 2282 if (!udc->qwork) {
2343 dev_err(&pdev->dev, "cannot create workqueue\n"); 2283 dev_err(&pdev->dev, "cannot create workqueue\n");
2344 retval = -ENOMEM; 2284 retval = -ENOMEM;
2345 goto err_unregister; 2285 goto err_destroy_dma;
2346 } 2286 }
2347 2287
2348 INIT_WORK(&udc->vbus_work, mv_udc_vbus_work); 2288 INIT_WORK(&udc->vbus_work, mv_udc_vbus_work);
@@ -2358,7 +2298,8 @@ static int mv_udc_probe(struct platform_device *pdev)
2358 else 2298 else
2359 udc->vbus_active = 1; 2299 udc->vbus_active = 1;
2360 2300
2361 retval = usb_add_gadget_udc(&pdev->dev, &udc->gadget); 2301 retval = usb_add_gadget_udc_release(&pdev->dev, &udc->gadget,
2302 gadget_release);
2362 if (retval) 2303 if (retval)
2363 goto err_create_workqueue; 2304 goto err_create_workqueue;
2364 2305
@@ -2370,8 +2311,6 @@ static int mv_udc_probe(struct platform_device *pdev)
2370 2311
2371err_create_workqueue: 2312err_create_workqueue:
2372 destroy_workqueue(udc->qwork); 2313 destroy_workqueue(udc->qwork);
2373err_unregister:
2374 device_unregister(&udc->gadget.dev);
2375err_destroy_dma: 2314err_destroy_dma:
2376 dma_pool_destroy(udc->dtd_pool); 2315 dma_pool_destroy(udc->dtd_pool);
2377err_free_dma: 2316err_free_dma:
diff --git a/drivers/usb/gadget/ncm.c b/drivers/usb/gadget/ncm.c
index a22ad9af0565..3b02fd4649ce 100644
--- a/drivers/usb/gadget/ncm.c
+++ b/drivers/usb/gadget/ncm.c
@@ -111,6 +111,7 @@ static struct usb_gadget_strings *dev_strings[] = {
111 NULL, 111 NULL,
112}; 112};
113 113
114struct eth_dev *the_dev;
114static u8 hostaddr[ETH_ALEN]; 115static u8 hostaddr[ETH_ALEN];
115 116
116/*-------------------------------------------------------------------------*/ 117/*-------------------------------------------------------------------------*/
@@ -124,7 +125,7 @@ static int __init ncm_do_config(struct usb_configuration *c)
124 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 125 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
125 } 126 }
126 127
127 return ncm_bind_config(c, hostaddr); 128 return ncm_bind_config(c, hostaddr, the_dev);
128} 129}
129 130
130static struct usb_configuration ncm_config_driver = { 131static struct usb_configuration ncm_config_driver = {
@@ -143,9 +144,9 @@ static int __init gncm_bind(struct usb_composite_dev *cdev)
143 int status; 144 int status;
144 145
145 /* set up network link layer */ 146 /* set up network link layer */
146 status = gether_setup(cdev->gadget, hostaddr); 147 the_dev = gether_setup(cdev->gadget, hostaddr);
147 if (status < 0) 148 if (IS_ERR(the_dev))
148 return status; 149 return PTR_ERR(the_dev);
149 150
150 /* Allocate string descriptor numbers ... note that string 151 /* Allocate string descriptor numbers ... note that string
151 * contents can be overridden by the composite_dev glue. 152 * contents can be overridden by the composite_dev glue.
@@ -168,13 +169,13 @@ static int __init gncm_bind(struct usb_composite_dev *cdev)
168 return 0; 169 return 0;
169 170
170fail: 171fail:
171 gether_cleanup(); 172 gether_cleanup(the_dev);
172 return status; 173 return status;
173} 174}
174 175
175static int __exit gncm_unbind(struct usb_composite_dev *cdev) 176static int __exit gncm_unbind(struct usb_composite_dev *cdev)
176{ 177{
177 gether_cleanup(); 178 gether_cleanup(the_dev);
178 return 0; 179 return 0;
179} 180}
180 181
diff --git a/drivers/usb/gadget/net2272.c b/drivers/usb/gadget/net2272.c
index 32524b631959..f1e50a3e322d 100644
--- a/drivers/usb/gadget/net2272.c
+++ b/drivers/usb/gadget/net2272.c
@@ -58,7 +58,6 @@ static const char * const ep_name[] = {
58 "ep-a", "ep-b", "ep-c", 58 "ep-a", "ep-b", "ep-c",
59}; 59};
60 60
61#define DMA_ADDR_INVALID (~(dma_addr_t)0)
62#ifdef CONFIG_USB_NET2272_DMA 61#ifdef CONFIG_USB_NET2272_DMA
63/* 62/*
64 * use_dma: the NET2272 can use an external DMA controller. 63 * use_dma: the NET2272 can use an external DMA controller.
@@ -341,7 +340,6 @@ net2272_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags)
341 if (!req) 340 if (!req)
342 return NULL; 341 return NULL;
343 342
344 req->req.dma = DMA_ADDR_INVALID;
345 INIT_LIST_HEAD(&req->queue); 343 INIT_LIST_HEAD(&req->queue);
346 344
347 return &req->req; 345 return &req->req;
@@ -913,7 +911,7 @@ net2272_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
913 } 911 }
914 } 912 }
915 } 913 }
916 if (likely(req != 0)) 914 if (likely(req))
917 list_add_tail(&req->queue, &ep->queue); 915 list_add_tail(&req->queue, &ep->queue);
918 916
919 if (likely(!list_empty(&ep->queue))) 917 if (likely(!list_empty(&ep->queue)))
@@ -1467,7 +1465,6 @@ static int net2272_start(struct usb_gadget *_gadget,
1467 dev->softconnect = 1; 1465 dev->softconnect = 1;
1468 driver->driver.bus = NULL; 1466 driver->driver.bus = NULL;
1469 dev->driver = driver; 1467 dev->driver = driver;
1470 dev->gadget.dev.driver = &driver->driver;
1471 1468
1472 /* ... then enable host detection and ep0; and we're ready 1469 /* ... then enable host detection and ep0; and we're ready
1473 * for set_configuration as well as eventual disconnect. 1470 * for set_configuration as well as eventual disconnect.
@@ -1517,7 +1514,6 @@ static int net2272_stop(struct usb_gadget *_gadget,
1517 stop_activity(dev, driver); 1514 stop_activity(dev, driver);
1518 spin_unlock_irqrestore(&dev->lock, flags); 1515 spin_unlock_irqrestore(&dev->lock, flags);
1519 1516
1520 dev->gadget.dev.driver = NULL;
1521 dev->driver = NULL; 1517 dev->driver = NULL;
1522 1518
1523 dev_dbg(dev->dev, "unregistered driver '%s'\n", driver->driver.name); 1519 dev_dbg(dev->dev, "unregistered driver '%s'\n", driver->driver.name);
@@ -1549,7 +1545,7 @@ net2272_handle_dma(struct net2272_ep *ep)
1549 | (ep->dev->dma_eot_polarity << EOT_POLARITY) 1545 | (ep->dev->dma_eot_polarity << EOT_POLARITY)
1550 | (ep->dev->dma_dack_polarity << DACK_POLARITY) 1546 | (ep->dev->dma_dack_polarity << DACK_POLARITY)
1551 | (ep->dev->dma_dreq_polarity << DREQ_POLARITY) 1547 | (ep->dev->dma_dreq_polarity << DREQ_POLARITY)
1552 | ((ep->dma >> 1) << DMA_ENDPOINT_SELECT)); 1548 | (ep->dma << DMA_ENDPOINT_SELECT));
1553 1549
1554 ep->dev->dma_busy = 0; 1550 ep->dev->dma_busy = 0;
1555 1551
@@ -1622,7 +1618,7 @@ net2272_handle_ep(struct net2272_ep *ep)
1622 ep->irqs++; 1618 ep->irqs++;
1623 1619
1624 dev_vdbg(ep->dev->dev, "%s ack ep_stat0 %02x, ep_stat1 %02x, req %p\n", 1620 dev_vdbg(ep->dev->dev, "%s ack ep_stat0 %02x, ep_stat1 %02x, req %p\n",
1625 ep->ep.name, stat0, stat1, req ? &req->req : 0); 1621 ep->ep.name, stat0, stat1, req ? &req->req : NULL);
1626 1622
1627 net2272_ep_write(ep, EP_STAT0, stat0 & 1623 net2272_ep_write(ep, EP_STAT0, stat0 &
1628 ~((1 << NAK_OUT_PACKETS) 1624 ~((1 << NAK_OUT_PACKETS)
@@ -2216,7 +2212,6 @@ net2272_remove(struct net2272 *dev)
2216 free_irq(dev->irq, dev); 2212 free_irq(dev->irq, dev);
2217 iounmap(dev->base_addr); 2213 iounmap(dev->base_addr);
2218 2214
2219 device_unregister(&dev->gadget.dev);
2220 device_remove_file(dev->dev, &dev_attr_registers); 2215 device_remove_file(dev->dev, &dev_attr_registers);
2221 2216
2222 dev_info(dev->dev, "unbind\n"); 2217 dev_info(dev->dev, "unbind\n");
@@ -2243,10 +2238,6 @@ static struct net2272 *net2272_probe_init(struct device *dev, unsigned int irq)
2243 ret->gadget.max_speed = USB_SPEED_HIGH; 2238 ret->gadget.max_speed = USB_SPEED_HIGH;
2244 2239
2245 /* the "gadget" abstracts/virtualizes the controller */ 2240 /* the "gadget" abstracts/virtualizes the controller */
2246 dev_set_name(&ret->gadget.dev, "gadget");
2247 ret->gadget.dev.parent = dev;
2248 ret->gadget.dev.dma_mask = dev->dma_mask;
2249 ret->gadget.dev.release = net2272_gadget_release;
2250 ret->gadget.name = driver_name; 2241 ret->gadget.name = driver_name;
2251 2242
2252 return ret; 2243 return ret;
@@ -2282,14 +2273,12 @@ net2272_probe_fin(struct net2272 *dev, unsigned int irqflags)
2282 dma_mode_string()); 2273 dma_mode_string());
2283 dev_info(dev->dev, "version: %s\n", driver_vers); 2274 dev_info(dev->dev, "version: %s\n", driver_vers);
2284 2275
2285 ret = device_register(&dev->gadget.dev);
2286 if (ret)
2287 goto err_irq;
2288 ret = device_create_file(dev->dev, &dev_attr_registers); 2276 ret = device_create_file(dev->dev, &dev_attr_registers);
2289 if (ret) 2277 if (ret)
2290 goto err_dev_reg; 2278 goto err_irq;
2291 2279
2292 ret = usb_add_gadget_udc(dev->dev, &dev->gadget); 2280 ret = usb_add_gadget_udc_release(dev->dev, &dev->gadget,
2281 net2272_gadget_release);
2293 if (ret) 2282 if (ret)
2294 goto err_add_udc; 2283 goto err_add_udc;
2295 2284
@@ -2297,8 +2286,6 @@ net2272_probe_fin(struct net2272 *dev, unsigned int irqflags)
2297 2286
2298err_add_udc: 2287err_add_udc:
2299 device_remove_file(dev->dev, &dev_attr_registers); 2288 device_remove_file(dev->dev, &dev_attr_registers);
2300 err_dev_reg:
2301 device_unregister(&dev->gadget.dev);
2302 err_irq: 2289 err_irq:
2303 free_irq(dev->irq, dev); 2290 free_irq(dev->irq, dev);
2304 err: 2291 err:
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c
index 3bd0f992fb49..fbd006ab31d3 100644
--- a/drivers/usb/gadget/net2280.c
+++ b/drivers/usb/gadget/net2280.c
@@ -65,7 +65,6 @@
65#define DRIVER_DESC "PLX NET228x USB Peripheral Controller" 65#define DRIVER_DESC "PLX NET228x USB Peripheral Controller"
66#define DRIVER_VERSION "2005 Sept 27" 66#define DRIVER_VERSION "2005 Sept 27"
67 67
68#define DMA_ADDR_INVALID (~(dma_addr_t)0)
69#define EP_DONTUSE 13 /* nonzero */ 68#define EP_DONTUSE 13 /* nonzero */
70 69
71#define USE_RDK_LEDS /* GPIO pins control three LEDs */ 70#define USE_RDK_LEDS /* GPIO pins control three LEDs */
@@ -406,7 +405,6 @@ net2280_alloc_request (struct usb_ep *_ep, gfp_t gfp_flags)
406 if (!req) 405 if (!req)
407 return NULL; 406 return NULL;
408 407
409 req->req.dma = DMA_ADDR_INVALID;
410 INIT_LIST_HEAD (&req->queue); 408 INIT_LIST_HEAD (&req->queue);
411 409
412 /* this dma descriptor may be swapped with the previous dummy */ 410 /* this dma descriptor may be swapped with the previous dummy */
@@ -420,7 +418,6 @@ net2280_alloc_request (struct usb_ep *_ep, gfp_t gfp_flags)
420 return NULL; 418 return NULL;
421 } 419 }
422 td->dmacount = 0; /* not VALID */ 420 td->dmacount = 0; /* not VALID */
423 td->dmaaddr = cpu_to_le32 (DMA_ADDR_INVALID);
424 td->dmadesc = td->dmaaddr; 421 td->dmadesc = td->dmaaddr;
425 req->td = td; 422 req->td = td;
426 } 423 }
@@ -1896,7 +1893,6 @@ static int net2280_start(struct usb_gadget *_gadget,
1896 dev->softconnect = 1; 1893 dev->softconnect = 1;
1897 driver->driver.bus = NULL; 1894 driver->driver.bus = NULL;
1898 dev->driver = driver; 1895 dev->driver = driver;
1899 dev->gadget.dev.driver = &driver->driver;
1900 1896
1901 retval = device_create_file (&dev->pdev->dev, &dev_attr_function); 1897 retval = device_create_file (&dev->pdev->dev, &dev_attr_function);
1902 if (retval) goto err_unbind; 1898 if (retval) goto err_unbind;
@@ -1924,7 +1920,6 @@ static int net2280_start(struct usb_gadget *_gadget,
1924err_func: 1920err_func:
1925 device_remove_file (&dev->pdev->dev, &dev_attr_function); 1921 device_remove_file (&dev->pdev->dev, &dev_attr_function);
1926err_unbind: 1922err_unbind:
1927 dev->gadget.dev.driver = NULL;
1928 dev->driver = NULL; 1923 dev->driver = NULL;
1929 return retval; 1924 return retval;
1930} 1925}
@@ -1967,7 +1962,6 @@ static int net2280_stop(struct usb_gadget *_gadget,
1967 stop_activity (dev, driver); 1962 stop_activity (dev, driver);
1968 spin_unlock_irqrestore (&dev->lock, flags); 1963 spin_unlock_irqrestore (&dev->lock, flags);
1969 1964
1970 dev->gadget.dev.driver = NULL;
1971 dev->driver = NULL; 1965 dev->driver = NULL;
1972 1966
1973 net2280_led_active (dev, 0); 1967 net2280_led_active (dev, 0);
@@ -2072,7 +2066,7 @@ static void handle_ep_small (struct net2280_ep *ep)
2072 return; 2066 return;
2073 2067
2074 /* manual DMA queue advance after short OUT */ 2068 /* manual DMA queue advance after short OUT */
2075 if (likely (ep->dma != 0)) { 2069 if (likely (ep->dma)) {
2076 if (t & (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT)) { 2070 if (t & (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT)) {
2077 u32 count; 2071 u32 count;
2078 int stopped = ep->stopped; 2072 int stopped = ep->stopped;
@@ -2330,7 +2324,7 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2330 /* hw handles device and interface status */ 2324 /* hw handles device and interface status */
2331 if (u.r.bRequestType != (USB_DIR_IN|USB_RECIP_ENDPOINT)) 2325 if (u.r.bRequestType != (USB_DIR_IN|USB_RECIP_ENDPOINT))
2332 goto delegate; 2326 goto delegate;
2333 if ((e = get_ep_by_addr (dev, w_index)) == 0 2327 if ((e = get_ep_by_addr (dev, w_index)) == NULL
2334 || w_length > 2) 2328 || w_length > 2)
2335 goto do_stall; 2329 goto do_stall;
2336 2330
@@ -2358,7 +2352,7 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2358 if (w_value != USB_ENDPOINT_HALT 2352 if (w_value != USB_ENDPOINT_HALT
2359 || w_length != 0) 2353 || w_length != 0)
2360 goto do_stall; 2354 goto do_stall;
2361 if ((e = get_ep_by_addr (dev, w_index)) == 0) 2355 if ((e = get_ep_by_addr (dev, w_index)) == NULL)
2362 goto do_stall; 2356 goto do_stall;
2363 if (e->wedged) { 2357 if (e->wedged) {
2364 VDEBUG(dev, "%s wedged, halt not cleared\n", 2358 VDEBUG(dev, "%s wedged, halt not cleared\n",
@@ -2380,7 +2374,7 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2380 if (w_value != USB_ENDPOINT_HALT 2374 if (w_value != USB_ENDPOINT_HALT
2381 || w_length != 0) 2375 || w_length != 0)
2382 goto do_stall; 2376 goto do_stall;
2383 if ((e = get_ep_by_addr (dev, w_index)) == 0) 2377 if ((e = get_ep_by_addr (dev, w_index)) == NULL)
2384 goto do_stall; 2378 goto do_stall;
2385 if (e->ep.name == ep0name) 2379 if (e->ep.name == ep0name)
2386 goto do_stall; 2380 goto do_stall;
@@ -2685,7 +2679,6 @@ static void net2280_remove (struct pci_dev *pdev)
2685 pci_resource_len (pdev, 0)); 2679 pci_resource_len (pdev, 0));
2686 if (dev->enabled) 2680 if (dev->enabled)
2687 pci_disable_device (pdev); 2681 pci_disable_device (pdev);
2688 device_unregister (&dev->gadget.dev);
2689 device_remove_file (&pdev->dev, &dev_attr_registers); 2682 device_remove_file (&pdev->dev, &dev_attr_registers);
2690 pci_set_drvdata (pdev, NULL); 2683 pci_set_drvdata (pdev, NULL);
2691 2684
@@ -2717,10 +2710,6 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id)
2717 dev->gadget.max_speed = USB_SPEED_HIGH; 2710 dev->gadget.max_speed = USB_SPEED_HIGH;
2718 2711
2719 /* the "gadget" abstracts/virtualizes the controller */ 2712 /* the "gadget" abstracts/virtualizes the controller */
2720 dev_set_name(&dev->gadget.dev, "gadget");
2721 dev->gadget.dev.parent = &pdev->dev;
2722 dev->gadget.dev.dma_mask = pdev->dev.dma_mask;
2723 dev->gadget.dev.release = gadget_release;
2724 dev->gadget.name = driver_name; 2713 dev->gadget.name = driver_name;
2725 2714
2726 /* now all the pci goodies ... */ 2715 /* now all the pci goodies ... */
@@ -2802,7 +2791,6 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id)
2802 goto done; 2791 goto done;
2803 } 2792 }
2804 td->dmacount = 0; /* not VALID */ 2793 td->dmacount = 0; /* not VALID */
2805 td->dmaaddr = cpu_to_le32 (DMA_ADDR_INVALID);
2806 td->dmadesc = td->dmaaddr; 2794 td->dmadesc = td->dmaaddr;
2807 dev->ep [i].dummy = td; 2795 dev->ep [i].dummy = td;
2808 } 2796 }
@@ -2829,12 +2817,11 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id)
2829 use_dma 2817 use_dma
2830 ? (use_dma_chaining ? "chaining" : "enabled") 2818 ? (use_dma_chaining ? "chaining" : "enabled")
2831 : "disabled"); 2819 : "disabled");
2832 retval = device_register (&dev->gadget.dev);
2833 if (retval) goto done;
2834 retval = device_create_file (&pdev->dev, &dev_attr_registers); 2820 retval = device_create_file (&pdev->dev, &dev_attr_registers);
2835 if (retval) goto done; 2821 if (retval) goto done;
2836 2822
2837 retval = usb_add_gadget_udc(&pdev->dev, &dev->gadget); 2823 retval = usb_add_gadget_udc_release(&pdev->dev, &dev->gadget,
2824 gadget_release);
2838 if (retval) 2825 if (retval)
2839 goto done; 2826 goto done;
2840 return 0; 2827 return 0;
diff --git a/drivers/usb/gadget/nokia.c b/drivers/usb/gadget/nokia.c
index def37403989a..3b344b41a167 100644
--- a/drivers/usb/gadget/nokia.c
+++ b/drivers/usb/gadget/nokia.c
@@ -37,11 +37,9 @@
37 * the runtime footprint, and giving us at least some parts of what 37 * the runtime footprint, and giving us at least some parts of what
38 * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 38 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
39 */ 39 */
40#define USB_FACM_INCLUDED 40#define USBF_OBEX_INCLUDED
41#include "f_acm.c"
42#include "f_ecm.c" 41#include "f_ecm.c"
43#include "f_obex.c" 42#include "f_obex.c"
44#include "f_serial.c"
45#include "f_phonet.c" 43#include "f_phonet.c"
46#include "u_ether.c" 44#include "u_ether.c"
47 45
@@ -98,20 +96,40 @@ MODULE_AUTHOR("Felipe Balbi");
98MODULE_LICENSE("GPL"); 96MODULE_LICENSE("GPL");
99 97
100/*-------------------------------------------------------------------------*/ 98/*-------------------------------------------------------------------------*/
101 99static struct usb_function *f_acm_cfg1;
100static struct usb_function *f_acm_cfg2;
102static u8 hostaddr[ETH_ALEN]; 101static u8 hostaddr[ETH_ALEN];
102static struct eth_dev *the_dev;
103 103
104enum { 104enum {
105 TTY_PORT_OBEX0, 105 TTY_PORT_OBEX0,
106 TTY_PORT_OBEX1, 106 TTY_PORT_OBEX1,
107 TTY_PORT_ACM,
108 TTY_PORTS_MAX, 107 TTY_PORTS_MAX,
109}; 108};
110 109
111static unsigned char tty_lines[TTY_PORTS_MAX]; 110static unsigned char tty_lines[TTY_PORTS_MAX];
112 111
112static struct usb_configuration nokia_config_500ma_driver = {
113 .label = "Bus Powered",
114 .bConfigurationValue = 1,
115 /* .iConfiguration = DYNAMIC */
116 .bmAttributes = USB_CONFIG_ATT_ONE,
117 .MaxPower = 500,
118};
119
120static struct usb_configuration nokia_config_100ma_driver = {
121 .label = "Self Powered",
122 .bConfigurationValue = 2,
123 /* .iConfiguration = DYNAMIC */
124 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
125 .MaxPower = 100,
126};
127
128static struct usb_function_instance *fi_acm;
129
113static int __init nokia_bind_config(struct usb_configuration *c) 130static int __init nokia_bind_config(struct usb_configuration *c)
114{ 131{
132 struct usb_function *f_acm;
115 int status = 0; 133 int status = 0;
116 134
117 status = phonet_bind_config(c); 135 status = phonet_bind_config(c);
@@ -126,33 +144,32 @@ static int __init nokia_bind_config(struct usb_configuration *c)
126 if (status) 144 if (status)
127 printk(KERN_DEBUG "could not bind obex config %d\n", 0); 145 printk(KERN_DEBUG "could not bind obex config %d\n", 0);
128 146
129 status = acm_bind_config(c, tty_lines[TTY_PORT_ACM]); 147 f_acm = usb_get_function(fi_acm);
130 if (status) 148 if (IS_ERR(f_acm))
131 printk(KERN_DEBUG "could not bind acm config\n"); 149 return PTR_ERR(f_acm);
132 150
133 status = ecm_bind_config(c, hostaddr); 151 status = usb_add_function(c, f_acm);
134 if (status) 152 if (status)
135 printk(KERN_DEBUG "could not bind ecm config\n"); 153 goto err_conf;
154
155 status = ecm_bind_config(c, hostaddr, the_dev);
156 if (status) {
157 pr_debug("could not bind ecm config %d\n", status);
158 goto err_ecm;
159 }
160 if (c == &nokia_config_500ma_driver)
161 f_acm_cfg1 = f_acm;
162 else
163 f_acm_cfg2 = f_acm;
136 164
137 return status; 165 return status;
166err_ecm:
167 usb_remove_function(c, f_acm);
168err_conf:
169 usb_put_function(f_acm);
170 return status;
138} 171}
139 172
140static struct usb_configuration nokia_config_500ma_driver = {
141 .label = "Bus Powered",
142 .bConfigurationValue = 1,
143 /* .iConfiguration = DYNAMIC */
144 .bmAttributes = USB_CONFIG_ATT_ONE,
145 .MaxPower = 500,
146};
147
148static struct usb_configuration nokia_config_100ma_driver = {
149 .label = "Self Powered",
150 .bConfigurationValue = 2,
151 /* .iConfiguration = DYNAMIC */
152 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
153 .MaxPower = 100,
154};
155
156static int __init nokia_bind(struct usb_composite_dev *cdev) 173static int __init nokia_bind(struct usb_composite_dev *cdev)
157{ 174{
158 struct usb_gadget *gadget = cdev->gadget; 175 struct usb_gadget *gadget = cdev->gadget;
@@ -169,9 +186,11 @@ static int __init nokia_bind(struct usb_composite_dev *cdev)
169 goto err_ether; 186 goto err_ether;
170 } 187 }
171 188
172 status = gether_setup(cdev->gadget, hostaddr); 189 the_dev = gether_setup(cdev->gadget, hostaddr);
173 if (status < 0) 190 if (IS_ERR(the_dev)) {
191 status = PTR_ERR(the_dev);
174 goto err_ether; 192 goto err_ether;
193 }
175 194
176 status = usb_string_ids_tab(cdev, strings_dev); 195 status = usb_string_ids_tab(cdev, strings_dev);
177 if (status < 0) 196 if (status < 0)
@@ -185,24 +204,32 @@ static int __init nokia_bind(struct usb_composite_dev *cdev)
185 if (!gadget_supports_altsettings(gadget)) 204 if (!gadget_supports_altsettings(gadget))
186 goto err_usb; 205 goto err_usb;
187 206
207 fi_acm = usb_get_function_instance("acm");
208 if (IS_ERR(fi_acm))
209 goto err_usb;
210
188 /* finally register the configuration */ 211 /* finally register the configuration */
189 status = usb_add_config(cdev, &nokia_config_500ma_driver, 212 status = usb_add_config(cdev, &nokia_config_500ma_driver,
190 nokia_bind_config); 213 nokia_bind_config);
191 if (status < 0) 214 if (status < 0)
192 goto err_usb; 215 goto err_acm_inst;
193 216
194 status = usb_add_config(cdev, &nokia_config_100ma_driver, 217 status = usb_add_config(cdev, &nokia_config_100ma_driver,
195 nokia_bind_config); 218 nokia_bind_config);
196 if (status < 0) 219 if (status < 0)
197 goto err_usb; 220 goto err_put_cfg1;
198 221
199 usb_composite_overwrite_options(cdev, &coverwrite); 222 usb_composite_overwrite_options(cdev, &coverwrite);
200 dev_info(&gadget->dev, "%s\n", NOKIA_LONG_NAME); 223 dev_info(&gadget->dev, "%s\n", NOKIA_LONG_NAME);
201 224
202 return 0; 225 return 0;
203 226
227err_put_cfg1:
228 usb_put_function(f_acm_cfg1);
229err_acm_inst:
230 usb_put_function_instance(fi_acm);
204err_usb: 231err_usb:
205 gether_cleanup(); 232 gether_cleanup(the_dev);
206err_ether: 233err_ether:
207 cur_line--; 234 cur_line--;
208 while (cur_line >= 0) 235 while (cur_line >= 0)
@@ -217,12 +244,15 @@ static int __exit nokia_unbind(struct usb_composite_dev *cdev)
217{ 244{
218 int i; 245 int i;
219 246
247 usb_put_function(f_acm_cfg1);
248 usb_put_function(f_acm_cfg2);
249 usb_put_function_instance(fi_acm);
220 gphonet_cleanup(); 250 gphonet_cleanup();
221 251
222 for (i = 0; i < TTY_PORTS_MAX; i++) 252 for (i = 0; i < TTY_PORTS_MAX; i++)
223 gserial_free_line(tty_lines[i]); 253 gserial_free_line(tty_lines[i]);
224 254
225 gether_cleanup(); 255 gether_cleanup(the_dev);
226 256
227 return 0; 257 return 0;
228} 258}
@@ -247,4 +277,3 @@ static void __exit nokia_cleanup(void)
247 usb_composite_unregister(&nokia_driver); 277 usb_composite_unregister(&nokia_driver);
248} 278}
249module_exit(nokia_cleanup); 279module_exit(nokia_cleanup);
250
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c
index f8445653577f..b8ed74a823cb 100644
--- a/drivers/usb/gadget/omap_udc.c
+++ b/drivers/usb/gadget/omap_udc.c
@@ -2067,7 +2067,6 @@ static int omap_udc_start(struct usb_gadget *g,
2067 /* hook up the driver */ 2067 /* hook up the driver */
2068 driver->driver.bus = NULL; 2068 driver->driver.bus = NULL;
2069 udc->driver = driver; 2069 udc->driver = driver;
2070 udc->gadget.dev.driver = &driver->driver;
2071 spin_unlock_irqrestore(&udc->lock, flags); 2070 spin_unlock_irqrestore(&udc->lock, flags);
2072 2071
2073 if (udc->dc_clk != NULL) 2072 if (udc->dc_clk != NULL)
@@ -2083,7 +2082,6 @@ static int omap_udc_start(struct usb_gadget *g,
2083 ERR("can't bind to transceiver\n"); 2082 ERR("can't bind to transceiver\n");
2084 if (driver->unbind) { 2083 if (driver->unbind) {
2085 driver->unbind(&udc->gadget); 2084 driver->unbind(&udc->gadget);
2086 udc->gadget.dev.driver = NULL;
2087 udc->driver = NULL; 2085 udc->driver = NULL;
2088 } 2086 }
2089 goto done; 2087 goto done;
@@ -2129,7 +2127,6 @@ static int omap_udc_stop(struct usb_gadget *g,
2129 udc_quiesce(udc); 2127 udc_quiesce(udc);
2130 spin_unlock_irqrestore(&udc->lock, flags); 2128 spin_unlock_irqrestore(&udc->lock, flags);
2131 2129
2132 udc->gadget.dev.driver = NULL;
2133 udc->driver = NULL; 2130 udc->driver = NULL;
2134 2131
2135 if (udc->dc_clk != NULL) 2132 if (udc->dc_clk != NULL)
@@ -2631,14 +2628,6 @@ omap_udc_setup(struct platform_device *odev, struct usb_phy *xceiv)
2631 udc->gadget.speed = USB_SPEED_UNKNOWN; 2628 udc->gadget.speed = USB_SPEED_UNKNOWN;
2632 udc->gadget.max_speed = USB_SPEED_FULL; 2629 udc->gadget.max_speed = USB_SPEED_FULL;
2633 udc->gadget.name = driver_name; 2630 udc->gadget.name = driver_name;
2634
2635 device_initialize(&udc->gadget.dev);
2636 dev_set_name(&udc->gadget.dev, "gadget");
2637 udc->gadget.dev.release = omap_udc_release;
2638 udc->gadget.dev.parent = &odev->dev;
2639 if (use_dma)
2640 udc->gadget.dev.dma_mask = odev->dev.dma_mask;
2641
2642 udc->transceiver = xceiv; 2631 udc->transceiver = xceiv;
2643 2632
2644 /* ep0 is special; put it right after the SETUP buffer */ 2633 /* ep0 is special; put it right after the SETUP buffer */
@@ -2912,14 +2901,13 @@ bad_on_1710:
2912 } 2901 }
2913 2902
2914 create_proc_file(); 2903 create_proc_file();
2915 status = device_add(&udc->gadget.dev); 2904 status = usb_add_gadget_udc_release(&pdev->dev, &udc->gadget,
2905 omap_udc_release);
2916 if (status) 2906 if (status)
2917 goto cleanup4; 2907 goto cleanup4;
2918 2908
2919 status = usb_add_gadget_udc(&pdev->dev, &udc->gadget); 2909 return 0;
2920 if (!status) 2910
2921 return status;
2922 /* If fail, fall through */
2923cleanup4: 2911cleanup4:
2924 remove_proc_file(); 2912 remove_proc_file();
2925 2913
@@ -2990,7 +2978,6 @@ static int omap_udc_remove(struct platform_device *pdev)
2990 release_mem_region(pdev->resource[0].start, 2978 release_mem_region(pdev->resource[0].start,
2991 pdev->resource[0].end - pdev->resource[0].start + 1); 2979 pdev->resource[0].end - pdev->resource[0].start + 1);
2992 2980
2993 device_unregister(&udc->gadget.dev);
2994 wait_for_completion(&done); 2981 wait_for_completion(&done);
2995 2982
2996 return 0; 2983 return 0;
diff --git a/drivers/usb/gadget/pch_udc.c b/drivers/usb/gadget/pch_udc.c
index a787a8ef672b..24174e1d1564 100644
--- a/drivers/usb/gadget/pch_udc.c
+++ b/drivers/usb/gadget/pch_udc.c
@@ -358,7 +358,6 @@ struct pch_udc_dev {
358 prot_stall:1, 358 prot_stall:1,
359 irq_registered:1, 359 irq_registered:1,
360 mem_region:1, 360 mem_region:1,
361 registered:1,
362 suspended:1, 361 suspended:1,
363 connected:1, 362 connected:1,
364 vbus_session:1, 363 vbus_session:1,
@@ -1441,6 +1440,8 @@ static void pch_vbus_gpio_free(struct pch_udc_dev *dev)
1441 */ 1440 */
1442static void complete_req(struct pch_udc_ep *ep, struct pch_udc_request *req, 1441static void complete_req(struct pch_udc_ep *ep, struct pch_udc_request *req,
1443 int status) 1442 int status)
1443 __releases(&dev->lock)
1444 __acquires(&dev->lock)
1444{ 1445{
1445 struct pch_udc_dev *dev; 1446 struct pch_udc_dev *dev;
1446 unsigned halted = ep->halted; 1447 unsigned halted = ep->halted;
@@ -2382,6 +2383,8 @@ static void pch_udc_svc_control_in(struct pch_udc_dev *dev)
2382 * @dev: Reference to the device structure 2383 * @dev: Reference to the device structure
2383 */ 2384 */
2384static void pch_udc_svc_control_out(struct pch_udc_dev *dev) 2385static void pch_udc_svc_control_out(struct pch_udc_dev *dev)
2386 __releases(&dev->lock)
2387 __acquires(&dev->lock)
2385{ 2388{
2386 u32 stat; 2389 u32 stat;
2387 int setup_supported; 2390 int setup_supported;
@@ -2989,7 +2992,6 @@ static int pch_udc_start(struct usb_gadget *g,
2989 2992
2990 driver->driver.bus = NULL; 2993 driver->driver.bus = NULL;
2991 dev->driver = driver; 2994 dev->driver = driver;
2992 dev->gadget.dev.driver = &driver->driver;
2993 2995
2994 /* get ready for ep0 traffic */ 2996 /* get ready for ep0 traffic */
2995 pch_udc_setup_ep0(dev); 2997 pch_udc_setup_ep0(dev);
@@ -3010,7 +3012,6 @@ static int pch_udc_stop(struct usb_gadget *g,
3010 pch_udc_disable_interrupts(dev, UDC_DEVINT_MSK); 3012 pch_udc_disable_interrupts(dev, UDC_DEVINT_MSK);
3011 3013
3012 /* Assures that there are no pending requests with this driver */ 3014 /* Assures that there are no pending requests with this driver */
3013 dev->gadget.dev.driver = NULL;
3014 dev->driver = NULL; 3015 dev->driver = NULL;
3015 dev->connected = 0; 3016 dev->connected = 0;
3016 3017
@@ -3078,8 +3079,6 @@ static void pch_udc_remove(struct pci_dev *pdev)
3078 pci_resource_len(pdev, PCH_UDC_PCI_BAR)); 3079 pci_resource_len(pdev, PCH_UDC_PCI_BAR));
3079 if (dev->active) 3080 if (dev->active)
3080 pci_disable_device(pdev); 3081 pci_disable_device(pdev);
3081 if (dev->registered)
3082 device_unregister(&dev->gadget.dev);
3083 kfree(dev); 3082 kfree(dev);
3084 pci_set_drvdata(pdev, NULL); 3083 pci_set_drvdata(pdev, NULL);
3085} 3084}
@@ -3196,21 +3195,13 @@ static int pch_udc_probe(struct pci_dev *pdev,
3196 if (retval) 3195 if (retval)
3197 goto finished; 3196 goto finished;
3198 3197
3199 dev_set_name(&dev->gadget.dev, "gadget");
3200 dev->gadget.dev.parent = &pdev->dev;
3201 dev->gadget.dev.dma_mask = pdev->dev.dma_mask;
3202 dev->gadget.dev.release = gadget_release;
3203 dev->gadget.name = KBUILD_MODNAME; 3198 dev->gadget.name = KBUILD_MODNAME;
3204 dev->gadget.max_speed = USB_SPEED_HIGH; 3199 dev->gadget.max_speed = USB_SPEED_HIGH;
3205 3200
3206 retval = device_register(&dev->gadget.dev);
3207 if (retval)
3208 goto finished;
3209 dev->registered = 1;
3210
3211 /* Put the device in disconnected state till a driver is bound */ 3201 /* Put the device in disconnected state till a driver is bound */
3212 pch_udc_set_disconnect(dev); 3202 pch_udc_set_disconnect(dev);
3213 retval = usb_add_gadget_udc(&pdev->dev, &dev->gadget); 3203 retval = usb_add_gadget_udc_release(&pdev->dev, &dev->gadget,
3204 gadget_release);
3214 if (retval) 3205 if (retval)
3215 goto finished; 3206 goto finished;
3216 return 0; 3207 return 0;
diff --git a/drivers/usb/gadget/pxa25x_udc.c b/drivers/usb/gadget/pxa25x_udc.c
index d0f37484b6b0..ef47495dec8f 100644
--- a/drivers/usb/gadget/pxa25x_udc.c
+++ b/drivers/usb/gadget/pxa25x_udc.c
@@ -1263,7 +1263,6 @@ static int pxa25x_udc_start(struct usb_gadget *g,
1263 1263
1264 /* first hook up the driver ... */ 1264 /* first hook up the driver ... */
1265 dev->driver = driver; 1265 dev->driver = driver;
1266 dev->gadget.dev.driver = &driver->driver;
1267 dev->pullup = 1; 1266 dev->pullup = 1;
1268 1267
1269 /* ... then enable host detection and ep0; and we're ready 1268 /* ... then enable host detection and ep0; and we're ready
@@ -1325,7 +1324,6 @@ static int pxa25x_udc_stop(struct usb_gadget*g,
1325 if (!IS_ERR_OR_NULL(dev->transceiver)) 1324 if (!IS_ERR_OR_NULL(dev->transceiver))
1326 (void) otg_set_peripheral(dev->transceiver->otg, NULL); 1325 (void) otg_set_peripheral(dev->transceiver->otg, NULL);
1327 1326
1328 dev->gadget.dev.driver = NULL;
1329 dev->driver = NULL; 1327 dev->driver = NULL;
1330 1328
1331 dump_state(dev); 1329 dump_state(dev);
@@ -2138,17 +2136,6 @@ static int __init pxa25x_udc_probe(struct platform_device *pdev)
2138 dev->timer.function = udc_watchdog; 2136 dev->timer.function = udc_watchdog;
2139 dev->timer.data = (unsigned long) dev; 2137 dev->timer.data = (unsigned long) dev;
2140 2138
2141 device_initialize(&dev->gadget.dev);
2142 dev->gadget.dev.parent = &pdev->dev;
2143 dev->gadget.dev.dma_mask = pdev->dev.dma_mask;
2144
2145 retval = device_add(&dev->gadget.dev);
2146 if (retval) {
2147 dev->driver = NULL;
2148 dev->gadget.dev.driver = NULL;
2149 goto err_device_add;
2150 }
2151
2152 the_controller = dev; 2139 the_controller = dev;
2153 platform_set_drvdata(pdev, dev); 2140 platform_set_drvdata(pdev, dev);
2154 2141
@@ -2199,8 +2186,6 @@ lubbock_fail0:
2199 free_irq(irq, dev); 2186 free_irq(irq, dev);
2200#endif 2187#endif
2201 err_irq1: 2188 err_irq1:
2202 device_unregister(&dev->gadget.dev);
2203 err_device_add:
2204 if (gpio_is_valid(dev->mach->gpio_pullup)) 2189 if (gpio_is_valid(dev->mach->gpio_pullup))
2205 gpio_free(dev->mach->gpio_pullup); 2190 gpio_free(dev->mach->gpio_pullup);
2206 err_gpio_pullup: 2191 err_gpio_pullup:
@@ -2226,7 +2211,6 @@ static int __exit pxa25x_udc_remove(struct platform_device *pdev)
2226 return -EBUSY; 2211 return -EBUSY;
2227 2212
2228 usb_del_gadget_udc(&dev->gadget); 2213 usb_del_gadget_udc(&dev->gadget);
2229 device_unregister(&dev->gadget.dev);
2230 dev->pullup = 0; 2214 dev->pullup = 0;
2231 pullup(dev); 2215 pullup(dev);
2232 2216
diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c
index 2fc867652ef5..6b4c7d95853f 100644
--- a/drivers/usb/gadget/pxa27x_udc.c
+++ b/drivers/usb/gadget/pxa27x_udc.c
@@ -24,14 +24,12 @@
24#include <linux/gpio.h> 24#include <linux/gpio.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/prefetch.h> 26#include <linux/prefetch.h>
27 27#include <linux/byteorder/generic.h>
28#include <asm/byteorder.h> 28#include <linux/platform_data/pxa2xx_udc.h>
29#include <mach/hardware.h>
30 29
31#include <linux/usb.h> 30#include <linux/usb.h>
32#include <linux/usb/ch9.h> 31#include <linux/usb/ch9.h>
33#include <linux/usb/gadget.h> 32#include <linux/usb/gadget.h>
34#include <mach/udc.h>
35 33
36#include "pxa27x_udc.h" 34#include "pxa27x_udc.h"
37 35
@@ -611,7 +609,7 @@ static void inc_ep_stats_bytes(struct pxa_ep *ep, int count, int is_in)
611 * 609 *
612 * Find the physical pxa27x ep, and setup its UDCCR 610 * Find the physical pxa27x ep, and setup its UDCCR
613 */ 611 */
614static __init void pxa_ep_setup(struct pxa_ep *ep) 612static void pxa_ep_setup(struct pxa_ep *ep)
615{ 613{
616 u32 new_udccr; 614 u32 new_udccr;
617 615
@@ -633,7 +631,7 @@ static __init void pxa_ep_setup(struct pxa_ep *ep)
633 * 631 *
634 * Setup all pxa physical endpoints, except ep0 632 * Setup all pxa physical endpoints, except ep0
635 */ 633 */
636static __init void pxa_eps_setup(struct pxa_udc *dev) 634static void pxa_eps_setup(struct pxa_udc *dev)
637{ 635{
638 unsigned int i; 636 unsigned int i;
639 637
@@ -1718,7 +1716,7 @@ static void udc_disable(struct pxa_udc *udc)
1718 * Initializes gadget endpoint list, endpoints locks. No action is taken 1716 * Initializes gadget endpoint list, endpoints locks. No action is taken
1719 * on the hardware. 1717 * on the hardware.
1720 */ 1718 */
1721static __init void udc_init_data(struct pxa_udc *dev) 1719static void udc_init_data(struct pxa_udc *dev)
1722{ 1720{
1723 int i; 1721 int i;
1724 struct pxa_ep *ep; 1722 struct pxa_ep *ep;
@@ -1811,7 +1809,6 @@ static int pxa27x_udc_start(struct usb_gadget *g,
1811 1809
1812 /* first hook up the driver ... */ 1810 /* first hook up the driver ... */
1813 udc->driver = driver; 1811 udc->driver = driver;
1814 udc->gadget.dev.driver = &driver->driver;
1815 dplus_pullup(udc, 1); 1812 dplus_pullup(udc, 1);
1816 1813
1817 if (!IS_ERR_OR_NULL(udc->transceiver)) { 1814 if (!IS_ERR_OR_NULL(udc->transceiver)) {
@@ -1829,7 +1826,6 @@ static int pxa27x_udc_start(struct usb_gadget *g,
1829 1826
1830fail: 1827fail:
1831 udc->driver = NULL; 1828 udc->driver = NULL;
1832 udc->gadget.dev.driver = NULL;
1833 return retval; 1829 return retval;
1834} 1830}
1835 1831
@@ -1871,7 +1867,6 @@ static int pxa27x_udc_stop(struct usb_gadget *g,
1871 1867
1872 udc->driver = NULL; 1868 udc->driver = NULL;
1873 1869
1874
1875 if (!IS_ERR_OR_NULL(udc->transceiver)) 1870 if (!IS_ERR_OR_NULL(udc->transceiver))
1876 return otg_set_peripheral(udc->transceiver->otg, NULL); 1871 return otg_set_peripheral(udc->transceiver->otg, NULL);
1877 return 0; 1872 return 0;
@@ -2413,7 +2408,7 @@ static struct pxa_udc memory = {
2413 * Perform basic init : allocates udc clock, creates sysfs files, requests 2408 * Perform basic init : allocates udc clock, creates sysfs files, requests
2414 * irq. 2409 * irq.
2415 */ 2410 */
2416static int __init pxa_udc_probe(struct platform_device *pdev) 2411static int pxa_udc_probe(struct platform_device *pdev)
2417{ 2412{
2418 struct resource *regs; 2413 struct resource *regs;
2419 struct pxa_udc *udc = &memory; 2414 struct pxa_udc *udc = &memory;
@@ -2456,9 +2451,6 @@ static int __init pxa_udc_probe(struct platform_device *pdev)
2456 goto err_map; 2451 goto err_map;
2457 } 2452 }
2458 2453
2459 device_initialize(&udc->gadget.dev);
2460 udc->gadget.dev.parent = &pdev->dev;
2461 udc->gadget.dev.dma_mask = NULL;
2462 udc->vbus_sensed = 0; 2454 udc->vbus_sensed = 0;
2463 2455
2464 the_controller = udc; 2456 the_controller = udc;
@@ -2475,12 +2467,6 @@ static int __init pxa_udc_probe(struct platform_device *pdev)
2475 goto err_irq; 2467 goto err_irq;
2476 } 2468 }
2477 2469
2478 retval = device_add(&udc->gadget.dev);
2479 if (retval) {
2480 dev_err(udc->dev, "device_add error %d\n", retval);
2481 goto err_dev_add;
2482 }
2483
2484 retval = usb_add_gadget_udc(&pdev->dev, &udc->gadget); 2470 retval = usb_add_gadget_udc(&pdev->dev, &udc->gadget);
2485 if (retval) 2471 if (retval)
2486 goto err_add_udc; 2472 goto err_add_udc;
@@ -2490,8 +2476,6 @@ static int __init pxa_udc_probe(struct platform_device *pdev)
2490 return 0; 2476 return 0;
2491 2477
2492err_add_udc: 2478err_add_udc:
2493 device_unregister(&udc->gadget.dev);
2494err_dev_add:
2495 free_irq(udc->irq, udc); 2479 free_irq(udc->irq, udc);
2496err_irq: 2480err_irq:
2497 iounmap(udc->regs); 2481 iounmap(udc->regs);
@@ -2506,13 +2490,12 @@ err_clk:
2506 * pxa_udc_remove - removes the udc device driver 2490 * pxa_udc_remove - removes the udc device driver
2507 * @_dev: platform device 2491 * @_dev: platform device
2508 */ 2492 */
2509static int __exit pxa_udc_remove(struct platform_device *_dev) 2493static int pxa_udc_remove(struct platform_device *_dev)
2510{ 2494{
2511 struct pxa_udc *udc = platform_get_drvdata(_dev); 2495 struct pxa_udc *udc = platform_get_drvdata(_dev);
2512 int gpio = udc->mach->gpio_pullup; 2496 int gpio = udc->mach->gpio_pullup;
2513 2497
2514 usb_del_gadget_udc(&udc->gadget); 2498 usb_del_gadget_udc(&udc->gadget);
2515 device_del(&udc->gadget.dev);
2516 usb_gadget_unregister_driver(udc->driver); 2499 usb_gadget_unregister_driver(udc->driver);
2517 free_irq(udc->irq, udc); 2500 free_irq(udc->irq, udc);
2518 pxa_cleanup_debugfs(udc); 2501 pxa_cleanup_debugfs(udc);
@@ -2625,7 +2608,8 @@ static struct platform_driver udc_driver = {
2625 .name = "pxa27x-udc", 2608 .name = "pxa27x-udc",
2626 .owner = THIS_MODULE, 2609 .owner = THIS_MODULE,
2627 }, 2610 },
2628 .remove = __exit_p(pxa_udc_remove), 2611 .probe = pxa_udc_probe,
2612 .remove = pxa_udc_remove,
2629 .shutdown = pxa_udc_shutdown, 2613 .shutdown = pxa_udc_shutdown,
2630#ifdef CONFIG_PM 2614#ifdef CONFIG_PM
2631 .suspend = pxa_udc_suspend, 2615 .suspend = pxa_udc_suspend,
@@ -2633,22 +2617,7 @@ static struct platform_driver udc_driver = {
2633#endif 2617#endif
2634}; 2618};
2635 2619
2636static int __init udc_init(void) 2620module_platform_driver(udc_driver);
2637{
2638 if (!cpu_is_pxa27x() && !cpu_is_pxa3xx())
2639 return -ENODEV;
2640
2641 printk(KERN_INFO "%s: version %s\n", driver_name, DRIVER_VERSION);
2642 return platform_driver_probe(&udc_driver, pxa_udc_probe);
2643}
2644module_init(udc_init);
2645
2646
2647static void __exit udc_exit(void)
2648{
2649 platform_driver_unregister(&udc_driver);
2650}
2651module_exit(udc_exit);
2652 2621
2653MODULE_DESCRIPTION(DRIVER_DESC); 2622MODULE_DESCRIPTION(DRIVER_DESC);
2654MODULE_AUTHOR("Robert Jarzmik"); 2623MODULE_AUTHOR("Robert Jarzmik");
diff --git a/drivers/usb/gadget/r8a66597-udc.c b/drivers/usb/gadget/r8a66597-udc.c
index f46a1b77ce3e..0b742d171843 100644
--- a/drivers/usb/gadget/r8a66597-udc.c
+++ b/drivers/usb/gadget/r8a66597-udc.c
@@ -1837,7 +1837,6 @@ static int __exit r8a66597_remove(struct platform_device *pdev)
1837 clk_put(r8a66597->clk); 1837 clk_put(r8a66597->clk);
1838 } 1838 }
1839 1839
1840 device_unregister(&r8a66597->gadget.dev);
1841 kfree(r8a66597); 1840 kfree(r8a66597);
1842 return 0; 1841 return 0;
1843} 1842}
@@ -1915,17 +1914,8 @@ static int __init r8a66597_probe(struct platform_device *pdev)
1915 r8a66597->irq_sense_low = irq_trigger == IRQF_TRIGGER_LOW; 1914 r8a66597->irq_sense_low = irq_trigger == IRQF_TRIGGER_LOW;
1916 1915
1917 r8a66597->gadget.ops = &r8a66597_gadget_ops; 1916 r8a66597->gadget.ops = &r8a66597_gadget_ops;
1918 dev_set_name(&r8a66597->gadget.dev, "gadget");
1919 r8a66597->gadget.max_speed = USB_SPEED_HIGH; 1917 r8a66597->gadget.max_speed = USB_SPEED_HIGH;
1920 r8a66597->gadget.dev.parent = &pdev->dev;
1921 r8a66597->gadget.dev.dma_mask = pdev->dev.dma_mask;
1922 r8a66597->gadget.dev.release = pdev->dev.release;
1923 r8a66597->gadget.name = udc_name; 1918 r8a66597->gadget.name = udc_name;
1924 ret = device_register(&r8a66597->gadget.dev);
1925 if (ret < 0) {
1926 dev_err(&pdev->dev, "device_register failed\n");
1927 goto clean_up;
1928 }
1929 1919
1930 init_timer(&r8a66597->timer); 1920 init_timer(&r8a66597->timer);
1931 r8a66597->timer.function = r8a66597_timer; 1921 r8a66597->timer.function = r8a66597_timer;
@@ -1939,7 +1929,7 @@ static int __init r8a66597_probe(struct platform_device *pdev)
1939 dev_err(&pdev->dev, "cannot get clock \"%s\"\n", 1929 dev_err(&pdev->dev, "cannot get clock \"%s\"\n",
1940 clk_name); 1930 clk_name);
1941 ret = PTR_ERR(r8a66597->clk); 1931 ret = PTR_ERR(r8a66597->clk);
1942 goto clean_up_dev; 1932 goto clean_up;
1943 } 1933 }
1944 clk_enable(r8a66597->clk); 1934 clk_enable(r8a66597->clk);
1945 } 1935 }
@@ -2007,8 +1997,6 @@ clean_up2:
2007 clk_disable(r8a66597->clk); 1997 clk_disable(r8a66597->clk);
2008 clk_put(r8a66597->clk); 1998 clk_put(r8a66597->clk);
2009 } 1999 }
2010clean_up_dev:
2011 device_unregister(&r8a66597->gadget.dev);
2012clean_up: 2000clean_up:
2013 if (r8a66597) { 2001 if (r8a66597) {
2014 if (r8a66597->sudmac_reg) 2002 if (r8a66597->sudmac_reg)
diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c
index c26564f29a2c..a3cdc32115d5 100644
--- a/drivers/usb/gadget/s3c-hsotg.c
+++ b/drivers/usb/gadget/s3c-hsotg.c
@@ -39,8 +39,6 @@
39 39
40#include "s3c-hsotg.h" 40#include "s3c-hsotg.h"
41 41
42#define DMA_ADDR_INVALID (~((dma_addr_t)0))
43
44static const char * const s3c_hsotg_supply_names[] = { 42static const char * const s3c_hsotg_supply_names[] = {
45 "vusb_d", /* digital USB supply, 1.2V */ 43 "vusb_d", /* digital USB supply, 1.2V */
46 "vusb_a", /* analog USB supply, 1.1V */ 44 "vusb_a", /* analog USB supply, 1.1V */
@@ -405,7 +403,6 @@ static struct usb_request *s3c_hsotg_ep_alloc_request(struct usb_ep *ep,
405 403
406 INIT_LIST_HEAD(&req->queue); 404 INIT_LIST_HEAD(&req->queue);
407 405
408 req->req.dma = DMA_ADDR_INVALID;
409 return &req->req; 406 return &req->req;
410} 407}
411 408
@@ -435,24 +432,12 @@ static void s3c_hsotg_unmap_dma(struct s3c_hsotg *hsotg,
435 struct s3c_hsotg_req *hs_req) 432 struct s3c_hsotg_req *hs_req)
436{ 433{
437 struct usb_request *req = &hs_req->req; 434 struct usb_request *req = &hs_req->req;
438 enum dma_data_direction dir;
439
440 dir = hs_ep->dir_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
441 435
442 /* ignore this if we're not moving any data */ 436 /* ignore this if we're not moving any data */
443 if (hs_req->req.length == 0) 437 if (hs_req->req.length == 0)
444 return; 438 return;
445 439
446 if (hs_req->mapped) { 440 usb_gadget_unmap_request(&hsotg->gadget, hs_req, hs_ep->dir_in);
447 /* we mapped this, so unmap and remove the dma */
448
449 dma_unmap_single(hsotg->dev, req->dma, req->length, dir);
450
451 req->dma = DMA_ADDR_INVALID;
452 hs_req->mapped = 0;
453 } else {
454 dma_sync_single_for_cpu(hsotg->dev, req->dma, req->length, dir);
455 }
456} 441}
457 442
458/** 443/**
@@ -852,37 +837,16 @@ static int s3c_hsotg_map_dma(struct s3c_hsotg *hsotg,
852 struct s3c_hsotg_ep *hs_ep, 837 struct s3c_hsotg_ep *hs_ep,
853 struct usb_request *req) 838 struct usb_request *req)
854{ 839{
855 enum dma_data_direction dir;
856 struct s3c_hsotg_req *hs_req = our_req(req); 840 struct s3c_hsotg_req *hs_req = our_req(req);
857 841 int ret;
858 dir = hs_ep->dir_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
859 842
860 /* if the length is zero, ignore the DMA data */ 843 /* if the length is zero, ignore the DMA data */
861 if (hs_req->req.length == 0) 844 if (hs_req->req.length == 0)
862 return 0; 845 return 0;
863 846
864 if (req->dma == DMA_ADDR_INVALID) { 847 ret = usb_gadget_map_request(&hsotg->gadget, req, hs_ep->dir_in);
865 dma_addr_t dma; 848 if (ret)
866 849 goto dma_error;
867 dma = dma_map_single(hsotg->dev, req->buf, req->length, dir);
868
869 if (unlikely(dma_mapping_error(hsotg->dev, dma)))
870 goto dma_error;
871
872 if (dma & 3) {
873 dev_err(hsotg->dev, "%s: unaligned dma buffer\n",
874 __func__);
875
876 dma_unmap_single(hsotg->dev, dma, req->length, dir);
877 return -EINVAL;
878 }
879
880 hs_req->mapped = 1;
881 req->dma = dma;
882 } else {
883 dma_sync_single_for_cpu(hsotg->dev, req->dma, req->length, dir);
884 hs_req->mapped = 0;
885 }
886 850
887 return 0; 851 return 0;
888 852
@@ -2961,9 +2925,7 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,
2961 2925
2962 driver->driver.bus = NULL; 2926 driver->driver.bus = NULL;
2963 hsotg->driver = driver; 2927 hsotg->driver = driver;
2964 hsotg->gadget.dev.driver = &driver->driver;
2965 hsotg->gadget.dev.of_node = hsotg->dev->of_node; 2928 hsotg->gadget.dev.of_node = hsotg->dev->of_node;
2966 hsotg->gadget.dev.dma_mask = hsotg->dev->dma_mask;
2967 hsotg->gadget.speed = USB_SPEED_UNKNOWN; 2929 hsotg->gadget.speed = USB_SPEED_UNKNOWN;
2968 2930
2969 ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies), 2931 ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies),
@@ -2979,7 +2941,6 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,
2979 2941
2980err: 2942err:
2981 hsotg->driver = NULL; 2943 hsotg->driver = NULL;
2982 hsotg->gadget.dev.driver = NULL;
2983 return ret; 2944 return ret;
2984} 2945}
2985 2946
@@ -3014,7 +2975,6 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,
3014 2975
3015 hsotg->driver = NULL; 2976 hsotg->driver = NULL;
3016 hsotg->gadget.speed = USB_SPEED_UNKNOWN; 2977 hsotg->gadget.speed = USB_SPEED_UNKNOWN;
3017 hsotg->gadget.dev.driver = NULL;
3018 2978
3019 spin_unlock_irqrestore(&hsotg->lock, flags); 2979 spin_unlock_irqrestore(&hsotg->lock, flags);
3020 2980
@@ -3484,16 +3444,6 @@ static void s3c_hsotg_delete_debug(struct s3c_hsotg *hsotg)
3484} 3444}
3485 3445
3486/** 3446/**
3487 * s3c_hsotg_release - release callback for hsotg device
3488 * @dev: Device to for which release is called
3489 *
3490 * Nothing to do as the resource is allocated using devm_ API.
3491 */
3492static void s3c_hsotg_release(struct device *dev)
3493{
3494}
3495
3496/**
3497 * s3c_hsotg_probe - probe function for hsotg driver 3447 * s3c_hsotg_probe - probe function for hsotg driver
3498 * @pdev: The platform information for the driver 3448 * @pdev: The platform information for the driver
3499 */ 3449 */
@@ -3517,7 +3467,7 @@ static int s3c_hsotg_probe(struct platform_device *pdev)
3517 } 3467 }
3518 3468
3519 phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); 3469 phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2);
3520 if (IS_ERR_OR_NULL(phy)) { 3470 if (IS_ERR(phy)) {
3521 /* Fallback for pdata */ 3471 /* Fallback for pdata */
3522 plat = pdev->dev.platform_data; 3472 plat = pdev->dev.platform_data;
3523 if (!plat) { 3473 if (!plat) {
@@ -3567,18 +3517,10 @@ static int s3c_hsotg_probe(struct platform_device *pdev)
3567 3517
3568 dev_info(dev, "regs %p, irq %d\n", hsotg->regs, hsotg->irq); 3518 dev_info(dev, "regs %p, irq %d\n", hsotg->regs, hsotg->irq);
3569 3519
3570 device_initialize(&hsotg->gadget.dev);
3571
3572 dev_set_name(&hsotg->gadget.dev, "gadget");
3573
3574 hsotg->gadget.max_speed = USB_SPEED_HIGH; 3520 hsotg->gadget.max_speed = USB_SPEED_HIGH;
3575 hsotg->gadget.ops = &s3c_hsotg_gadget_ops; 3521 hsotg->gadget.ops = &s3c_hsotg_gadget_ops;
3576 hsotg->gadget.name = dev_name(dev); 3522 hsotg->gadget.name = dev_name(dev);
3577 3523
3578 hsotg->gadget.dev.parent = dev;
3579 hsotg->gadget.dev.dma_mask = dev->dma_mask;
3580 hsotg->gadget.dev.release = s3c_hsotg_release;
3581
3582 /* reset the system */ 3524 /* reset the system */
3583 3525
3584 clk_prepare_enable(hsotg->clk); 3526 clk_prepare_enable(hsotg->clk);
@@ -3658,12 +3600,6 @@ static int s3c_hsotg_probe(struct platform_device *pdev)
3658 3600
3659 s3c_hsotg_phy_disable(hsotg); 3601 s3c_hsotg_phy_disable(hsotg);
3660 3602
3661 ret = device_add(&hsotg->gadget.dev);
3662 if (ret) {
3663 put_device(&hsotg->gadget.dev);
3664 goto err_ep_mem;
3665 }
3666
3667 ret = usb_add_gadget_udc(&pdev->dev, &hsotg->gadget); 3603 ret = usb_add_gadget_udc(&pdev->dev, &hsotg->gadget);
3668 if (ret) 3604 if (ret)
3669 goto err_ep_mem; 3605 goto err_ep_mem;
@@ -3702,10 +3638,8 @@ static int s3c_hsotg_remove(struct platform_device *pdev)
3702 } 3638 }
3703 3639
3704 s3c_hsotg_phy_disable(hsotg); 3640 s3c_hsotg_phy_disable(hsotg);
3705
3706 clk_disable_unprepare(hsotg->clk); 3641 clk_disable_unprepare(hsotg->clk);
3707 3642
3708 device_unregister(&hsotg->gadget.dev);
3709 return 0; 3643 return 0;
3710} 3644}
3711 3645
diff --git a/drivers/usb/gadget/s3c-hsudc.c b/drivers/usb/gadget/s3c-hsudc.c
index 458965a1b138..b1f0771fbd3d 100644
--- a/drivers/usb/gadget/s3c-hsudc.c
+++ b/drivers/usb/gadget/s3c-hsudc.c
@@ -283,7 +283,6 @@ static void s3c_hsudc_nuke_ep(struct s3c_hsudc_ep *hsep, int status)
283/** 283/**
284 * s3c_hsudc_stop_activity - Stop activity on all endpoints. 284 * s3c_hsudc_stop_activity - Stop activity on all endpoints.
285 * @hsudc: Device controller for which EP activity is to be stopped. 285 * @hsudc: Device controller for which EP activity is to be stopped.
286 * @driver: Reference to the gadget driver which is currently active.
287 * 286 *
288 * All the endpoints are stopped and any pending transfer requests if any on 287 * All the endpoints are stopped and any pending transfer requests if any on
289 * the endpoint are terminated. 288 * the endpoint are terminated.
@@ -1154,7 +1153,6 @@ static int s3c_hsudc_start(struct usb_gadget *gadget,
1154 return -EBUSY; 1153 return -EBUSY;
1155 1154
1156 hsudc->driver = driver; 1155 hsudc->driver = driver;
1157 hsudc->gadget.dev.driver = &driver->driver;
1158 1156
1159 ret = regulator_bulk_enable(ARRAY_SIZE(hsudc->supplies), 1157 ret = regulator_bulk_enable(ARRAY_SIZE(hsudc->supplies),
1160 hsudc->supplies); 1158 hsudc->supplies);
@@ -1190,7 +1188,6 @@ err_otg:
1190 regulator_bulk_disable(ARRAY_SIZE(hsudc->supplies), hsudc->supplies); 1188 regulator_bulk_disable(ARRAY_SIZE(hsudc->supplies), hsudc->supplies);
1191err_supplies: 1189err_supplies:
1192 hsudc->driver = NULL; 1190 hsudc->driver = NULL;
1193 hsudc->gadget.dev.driver = NULL;
1194 return ret; 1191 return ret;
1195} 1192}
1196 1193
@@ -1208,7 +1205,6 @@ static int s3c_hsudc_stop(struct usb_gadget *gadget,
1208 1205
1209 spin_lock_irqsave(&hsudc->lock, flags); 1206 spin_lock_irqsave(&hsudc->lock, flags);
1210 hsudc->driver = NULL; 1207 hsudc->driver = NULL;
1211 hsudc->gadget.dev.driver = NULL;
1212 hsudc->gadget.speed = USB_SPEED_UNKNOWN; 1208 hsudc->gadget.speed = USB_SPEED_UNKNOWN;
1213 s3c_hsudc_uninit_phy(); 1209 s3c_hsudc_uninit_phy();
1214 1210
@@ -1303,15 +1299,10 @@ static int s3c_hsudc_probe(struct platform_device *pdev)
1303 1299
1304 spin_lock_init(&hsudc->lock); 1300 spin_lock_init(&hsudc->lock);
1305 1301
1306 dev_set_name(&hsudc->gadget.dev, "gadget");
1307
1308 hsudc->gadget.max_speed = USB_SPEED_HIGH; 1302 hsudc->gadget.max_speed = USB_SPEED_HIGH;
1309 hsudc->gadget.ops = &s3c_hsudc_gadget_ops; 1303 hsudc->gadget.ops = &s3c_hsudc_gadget_ops;
1310 hsudc->gadget.name = dev_name(dev); 1304 hsudc->gadget.name = dev_name(dev);
1311 hsudc->gadget.dev.parent = dev;
1312 hsudc->gadget.dev.dma_mask = dev->dma_mask;
1313 hsudc->gadget.ep0 = &hsudc->ep[0].ep; 1305 hsudc->gadget.ep0 = &hsudc->ep[0].ep;
1314
1315 hsudc->gadget.is_otg = 0; 1306 hsudc->gadget.is_otg = 0;
1316 hsudc->gadget.is_a_peripheral = 0; 1307 hsudc->gadget.is_a_peripheral = 0;
1317 hsudc->gadget.speed = USB_SPEED_UNKNOWN; 1308 hsudc->gadget.speed = USB_SPEED_UNKNOWN;
@@ -1345,12 +1336,6 @@ static int s3c_hsudc_probe(struct platform_device *pdev)
1345 disable_irq(hsudc->irq); 1336 disable_irq(hsudc->irq);
1346 local_irq_enable(); 1337 local_irq_enable();
1347 1338
1348 ret = device_register(&hsudc->gadget.dev);
1349 if (ret) {
1350 put_device(&hsudc->gadget.dev);
1351 goto err_add_device;
1352 }
1353
1354 ret = usb_add_gadget_udc(&pdev->dev, &hsudc->gadget); 1339 ret = usb_add_gadget_udc(&pdev->dev, &hsudc->gadget);
1355 if (ret) 1340 if (ret)
1356 goto err_add_udc; 1341 goto err_add_udc;
@@ -1359,7 +1344,6 @@ static int s3c_hsudc_probe(struct platform_device *pdev)
1359 1344
1360 return 0; 1345 return 0;
1361err_add_udc: 1346err_add_udc:
1362 device_unregister(&hsudc->gadget.dev);
1363err_add_device: 1347err_add_device:
1364 clk_disable(hsudc->uclk); 1348 clk_disable(hsudc->uclk);
1365err_res: 1349err_res:
diff --git a/drivers/usb/gadget/s3c2410_udc.c b/drivers/usb/gadget/s3c2410_udc.c
index 08f89652533b..d0e75e1b3ccb 100644
--- a/drivers/usb/gadget/s3c2410_udc.c
+++ b/drivers/usb/gadget/s3c2410_udc.c
@@ -1674,7 +1674,6 @@ static int s3c2410_udc_start(struct usb_gadget *g,
1674 1674
1675 /* Hook the driver */ 1675 /* Hook the driver */
1676 udc->driver = driver; 1676 udc->driver = driver;
1677 udc->gadget.dev.driver = &driver->driver;
1678 1677
1679 /* Enable udc */ 1678 /* Enable udc */
1680 s3c2410_udc_enable(udc); 1679 s3c2410_udc_enable(udc);
@@ -1824,17 +1823,6 @@ static int s3c2410_udc_probe(struct platform_device *pdev)
1824 goto err_mem; 1823 goto err_mem;
1825 } 1824 }
1826 1825
1827 device_initialize(&udc->gadget.dev);
1828 udc->gadget.dev.parent = &pdev->dev;
1829 udc->gadget.dev.dma_mask = pdev->dev.dma_mask;
1830
1831 /* Bind the driver */
1832 retval = device_add(&udc->gadget.dev);
1833 if (retval) {
1834 dev_err(&udc->gadget.dev, "Error in device_add() : %d\n", retval);
1835 goto err_device_add;
1836 }
1837
1838 the_controller = udc; 1826 the_controller = udc;
1839 platform_set_drvdata(pdev, udc); 1827 platform_set_drvdata(pdev, udc);
1840 1828
@@ -1923,8 +1911,6 @@ err_gpio_claim:
1923err_int: 1911err_int:
1924 free_irq(IRQ_USBD, udc); 1912 free_irq(IRQ_USBD, udc);
1925err_map: 1913err_map:
1926 device_unregister(&udc->gadget.dev);
1927err_device_add:
1928 iounmap(base_addr); 1914 iounmap(base_addr);
1929err_mem: 1915err_mem:
1930 release_mem_region(rsrc_start, rsrc_len); 1916 release_mem_region(rsrc_start, rsrc_len);
@@ -1946,7 +1932,6 @@ static int s3c2410_udc_remove(struct platform_device *pdev)
1946 return -EBUSY; 1932 return -EBUSY;
1947 1933
1948 usb_del_gadget_udc(&udc->gadget); 1934 usb_del_gadget_udc(&udc->gadget);
1949 device_unregister(&udc->gadget.dev);
1950 debugfs_remove(udc->regs_info); 1935 debugfs_remove(udc->regs_info);
1951 1936
1952 if (udc_info && !udc_info->udc_command && 1937 if (udc_info && !udc_info->udc_command &&
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index 68d7bb06ebcb..1f5f978d35d5 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -12,6 +12,7 @@
12 12
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/device.h> 14#include <linux/device.h>
15#include <linux/module.h>
15#include <linux/tty.h> 16#include <linux/tty.h>
16#include <linux/tty_flip.h> 17#include <linux/tty_flip.h>
17 18
@@ -28,18 +29,6 @@
28#define GS_VERSION_NAME GS_LONG_NAME " " GS_VERSION_STR 29#define GS_VERSION_NAME GS_LONG_NAME " " GS_VERSION_STR
29 30
30/*-------------------------------------------------------------------------*/ 31/*-------------------------------------------------------------------------*/
31
32/*
33 * Kbuild is not very cooperative with respect to linking separately
34 * compiled library objects into one module. So for now we won't use
35 * separate compilation ... ensuring init/exit sections work to shrink
36 * the runtime footprint, and giving us at least some parts of what
37 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
38 */
39#include "f_obex.c"
40#include "f_serial.c"
41
42/*-------------------------------------------------------------------------*/
43USB_GADGET_COMPOSITE_OPTIONS(); 32USB_GADGET_COMPOSITE_OPTIONS();
44 33
45/* Thanks to NetChip Technologies for donating this product ID. 34/* Thanks to NetChip Technologies for donating this product ID.
@@ -126,27 +115,6 @@ module_param(n_ports, uint, 0);
126MODULE_PARM_DESC(n_ports, "number of ports to create, default=1"); 115MODULE_PARM_DESC(n_ports, "number of ports to create, default=1");
127 116
128/*-------------------------------------------------------------------------*/ 117/*-------------------------------------------------------------------------*/
129static unsigned char tty_lines[MAX_U_SERIAL_PORTS];
130
131static int __init serial_bind_obex_config(struct usb_configuration *c)
132{
133 unsigned i;
134 int status = 0;
135
136 for (i = 0; i < n_ports && status == 0; i++)
137 status = obex_bind_config(c, tty_lines[i]);
138 return status;
139}
140
141static int __init serial_bind_gser_config(struct usb_configuration *c)
142{
143 unsigned i;
144 int status = 0;
145
146 for (i = 0; i < n_ports && status == 0; i++)
147 status = gser_bind_config(c, tty_lines[i]);
148 return status;
149}
150 118
151static struct usb_configuration serial_config_driver = { 119static struct usb_configuration serial_config_driver = {
152 /* .label = f(use_acm) */ 120 /* .label = f(use_acm) */
@@ -169,15 +137,12 @@ static int serial_register_ports(struct usb_composite_dev *cdev,
169 goto out; 137 goto out;
170 138
171 for (i = 0; i < n_ports; i++) { 139 for (i = 0; i < n_ports; i++) {
172 struct f_serial_opts *opts;
173 140
174 fi_serial[i] = usb_get_function_instance(f_name); 141 fi_serial[i] = usb_get_function_instance(f_name);
175 if (IS_ERR(fi_serial[i])) { 142 if (IS_ERR(fi_serial[i])) {
176 ret = PTR_ERR(fi_serial[i]); 143 ret = PTR_ERR(fi_serial[i]);
177 goto fail; 144 goto fail;
178 } 145 }
179 opts = container_of(fi_serial[i], struct f_serial_opts, func_inst);
180 opts->port_num = tty_lines[i];
181 146
182 f_serial[i] = usb_get_function(fi_serial[i]); 147 f_serial[i] = usb_get_function(fi_serial[i]);
183 if (IS_ERR(f_serial[i])) { 148 if (IS_ERR(f_serial[i])) {
@@ -212,13 +177,6 @@ out:
212static int __init gs_bind(struct usb_composite_dev *cdev) 177static int __init gs_bind(struct usb_composite_dev *cdev)
213{ 178{
214 int status; 179 int status;
215 int cur_line;
216
217 for (cur_line = 0; cur_line < n_ports; cur_line++) {
218 status = gserial_alloc_line(&tty_lines[cur_line]);
219 if (status)
220 goto fail;
221 }
222 180
223 /* Allocate string descriptor numbers ... note that string 181 /* Allocate string descriptor numbers ... note that string
224 * contents can be overridden by the composite_dev glue. 182 * contents can be overridden by the composite_dev glue.
@@ -243,11 +201,12 @@ static int __init gs_bind(struct usb_composite_dev *cdev)
243 "acm"); 201 "acm");
244 usb_ep_autoconfig_reset(cdev->gadget); 202 usb_ep_autoconfig_reset(cdev->gadget);
245 } else if (use_obex) 203 } else if (use_obex)
246 status = usb_add_config(cdev, &serial_config_driver, 204 status = serial_register_ports(cdev, &serial_config_driver,
247 serial_bind_obex_config); 205 "obex");
248 else 206 else {
249 status = usb_add_config(cdev, &serial_config_driver, 207 status = serial_register_ports(cdev, &serial_config_driver,
250 serial_bind_gser_config); 208 "gser");
209 }
251 if (status < 0) 210 if (status < 0)
252 goto fail; 211 goto fail;
253 212
@@ -257,9 +216,6 @@ static int __init gs_bind(struct usb_composite_dev *cdev)
257 return 0; 216 return 0;
258 217
259fail: 218fail:
260 cur_line--;
261 while (cur_line >= 0)
262 gserial_free_line(tty_lines[cur_line--]);
263 return status; 219 return status;
264} 220}
265 221
@@ -270,7 +226,6 @@ static int gs_unbind(struct usb_composite_dev *cdev)
270 for (i = 0; i < n_ports; i++) { 226 for (i = 0; i < n_ports; i++) {
271 usb_put_function(f_serial[i]); 227 usb_put_function(f_serial[i]);
272 usb_put_function_instance(fi_serial[i]); 228 usb_put_function_instance(fi_serial[i]);
273 gserial_free_line(tty_lines[i]);
274 } 229 }
275 return 0; 230 return 0;
276} 231}
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c
index a0aa721d8b21..4b76124ce96b 100644
--- a/drivers/usb/gadget/u_ether.c
+++ b/drivers/usb/gadget/u_ether.c
@@ -50,7 +50,6 @@
50 50
51struct eth_dev { 51struct eth_dev {
52 /* lock is held while accessing port_usb 52 /* lock is held while accessing port_usb
53 * or updating its backlink port_usb->ioport
54 */ 53 */
55 spinlock_t lock; 54 spinlock_t lock;
56 struct gether *port_usb; 55 struct gether *port_usb;
@@ -729,8 +728,6 @@ static int get_ether_addr(const char *str, u8 *dev_addr)
729 return 1; 728 return 1;
730} 729}
731 730
732static struct eth_dev *the_dev;
733
734static const struct net_device_ops eth_netdev_ops = { 731static const struct net_device_ops eth_netdev_ops = {
735 .ndo_open = eth_open, 732 .ndo_open = eth_open,
736 .ndo_stop = eth_stop, 733 .ndo_stop = eth_stop,
@@ -758,19 +755,16 @@ static struct device_type gadget_type = {
758 * 755 *
759 * Returns negative errno, or zero on success 756 * Returns negative errno, or zero on success
760 */ 757 */
761int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN], 758struct eth_dev *gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN],
762 const char *netname) 759 const char *netname)
763{ 760{
764 struct eth_dev *dev; 761 struct eth_dev *dev;
765 struct net_device *net; 762 struct net_device *net;
766 int status; 763 int status;
767 764
768 if (the_dev)
769 return -EBUSY;
770
771 net = alloc_etherdev(sizeof *dev); 765 net = alloc_etherdev(sizeof *dev);
772 if (!net) 766 if (!net)
773 return -ENOMEM; 767 return ERR_PTR(-ENOMEM);
774 768
775 dev = netdev_priv(net); 769 dev = netdev_priv(net);
776 spin_lock_init(&dev->lock); 770 spin_lock_init(&dev->lock);
@@ -807,12 +801,11 @@ int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN],
807 if (status < 0) { 801 if (status < 0) {
808 dev_dbg(&g->dev, "register_netdev failed, %d\n", status); 802 dev_dbg(&g->dev, "register_netdev failed, %d\n", status);
809 free_netdev(net); 803 free_netdev(net);
804 dev = ERR_PTR(status);
810 } else { 805 } else {
811 INFO(dev, "MAC %pM\n", net->dev_addr); 806 INFO(dev, "MAC %pM\n", net->dev_addr);
812 INFO(dev, "HOST MAC %pM\n", dev->host_mac); 807 INFO(dev, "HOST MAC %pM\n", dev->host_mac);
813 808
814 the_dev = dev;
815
816 /* two kinds of host-initiated state changes: 809 /* two kinds of host-initiated state changes:
817 * - iff DATA transfer is active, carrier is "on" 810 * - iff DATA transfer is active, carrier is "on"
818 * - tx queueing enabled if open *and* carrier is "on" 811 * - tx queueing enabled if open *and* carrier is "on"
@@ -820,7 +813,7 @@ int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN],
820 netif_carrier_off(net); 813 netif_carrier_off(net);
821 } 814 }
822 815
823 return status; 816 return dev;
824} 817}
825 818
826/** 819/**
@@ -829,19 +822,16 @@ int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN],
829 * 822 *
830 * This is called to free all resources allocated by @gether_setup(). 823 * This is called to free all resources allocated by @gether_setup().
831 */ 824 */
832void gether_cleanup(void) 825void gether_cleanup(struct eth_dev *dev)
833{ 826{
834 if (!the_dev) 827 if (!dev)
835 return; 828 return;
836 829
837 unregister_netdev(the_dev->net); 830 unregister_netdev(dev->net);
838 flush_work(&the_dev->work); 831 flush_work(&dev->work);
839 free_netdev(the_dev->net); 832 free_netdev(dev->net);
840
841 the_dev = NULL;
842} 833}
843 834
844
845/** 835/**
846 * gether_connect - notify network layer that USB link is active 836 * gether_connect - notify network layer that USB link is active
847 * @link: the USB link, set up with endpoints, descriptors matching 837 * @link: the USB link, set up with endpoints, descriptors matching
@@ -860,7 +850,7 @@ void gether_cleanup(void)
860 */ 850 */
861struct net_device *gether_connect(struct gether *link) 851struct net_device *gether_connect(struct gether *link)
862{ 852{
863 struct eth_dev *dev = the_dev; 853 struct eth_dev *dev = link->ioport;
864 int result = 0; 854 int result = 0;
865 855
866 if (!dev) 856 if (!dev)
@@ -895,7 +885,6 @@ struct net_device *gether_connect(struct gether *link)
895 885
896 spin_lock(&dev->lock); 886 spin_lock(&dev->lock);
897 dev->port_usb = link; 887 dev->port_usb = link;
898 link->ioport = dev;
899 if (netif_running(dev->net)) { 888 if (netif_running(dev->net)) {
900 if (link->open) 889 if (link->open)
901 link->open(link); 890 link->open(link);
@@ -989,6 +978,5 @@ void gether_disconnect(struct gether *link)
989 978
990 spin_lock(&dev->lock); 979 spin_lock(&dev->lock);
991 dev->port_usb = NULL; 980 dev->port_usb = NULL;
992 link->ioport = NULL;
993 spin_unlock(&dev->lock); 981 spin_unlock(&dev->lock);
994} 982}
diff --git a/drivers/usb/gadget/u_ether.h b/drivers/usb/gadget/u_ether.h
index 6f4a1623d854..02522338a708 100644
--- a/drivers/usb/gadget/u_ether.h
+++ b/drivers/usb/gadget/u_ether.h
@@ -21,6 +21,7 @@
21 21
22#include "gadget_chips.h" 22#include "gadget_chips.h"
23 23
24struct eth_dev;
24 25
25/* 26/*
26 * This represents the USB side of an "ethernet" link, managed by a USB 27 * This represents the USB side of an "ethernet" link, managed by a USB
@@ -70,7 +71,7 @@ struct gether {
70 |USB_CDC_PACKET_TYPE_DIRECTED) 71 |USB_CDC_PACKET_TYPE_DIRECTED)
71 72
72/* variant of gether_setup that allows customizing network device name */ 73/* variant of gether_setup that allows customizing network device name */
73int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN], 74struct eth_dev *gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN],
74 const char *netname); 75 const char *netname);
75 76
76/* netdev setup/teardown as directed by the gadget driver */ 77/* netdev setup/teardown as directed by the gadget driver */
@@ -86,12 +87,13 @@ int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN],
86 * 87 *
87 * Returns negative errno, or zero on success 88 * Returns negative errno, or zero on success
88 */ 89 */
89static inline int gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN]) 90static inline struct eth_dev *gether_setup(struct usb_gadget *g,
91 u8 ethaddr[ETH_ALEN])
90{ 92{
91 return gether_setup_name(g, ethaddr, "usb"); 93 return gether_setup_name(g, ethaddr, "usb");
92} 94}
93 95
94void gether_cleanup(void); 96void gether_cleanup(struct eth_dev *dev);
95 97
96/* connect/disconnect is handled by individual functions */ 98/* connect/disconnect is handled by individual functions */
97struct net_device *gether_connect(struct gether *); 99struct net_device *gether_connect(struct gether *);
@@ -111,21 +113,24 @@ static inline bool can_support_ecm(struct usb_gadget *gadget)
111} 113}
112 114
113/* each configuration may bind one instance of an ethernet link */ 115/* each configuration may bind one instance of an ethernet link */
114int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); 116int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
115int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); 117 struct eth_dev *dev);
116int ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); 118int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
117int eem_bind_config(struct usb_configuration *c); 119 struct eth_dev *dev);
120int ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
121 struct eth_dev *dev);
122int eem_bind_config(struct usb_configuration *c, struct eth_dev *dev);
118 123
119#ifdef USB_ETH_RNDIS 124#ifdef USB_ETH_RNDIS
120 125
121int rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], 126int rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
122 u32 vendorID, const char *manufacturer); 127 u32 vendorID, const char *manufacturer, struct eth_dev *dev);
123 128
124#else 129#else
125 130
126static inline int 131static inline int
127rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], 132rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
128 u32 vendorID, const char *manufacturer) 133 u32 vendorID, const char *manufacturer, struct eth_dev *dev)
129{ 134{
130 return 0; 135 return 0;
131} 136}
@@ -145,9 +150,9 @@ rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
145 * for calling @gether_cleanup() before module unload. 150 * for calling @gether_cleanup() before module unload.
146 */ 151 */
147static inline int rndis_bind_config(struct usb_configuration *c, 152static inline int rndis_bind_config(struct usb_configuration *c,
148 u8 ethaddr[ETH_ALEN]) 153 u8 ethaddr[ETH_ALEN], struct eth_dev *dev)
149{ 154{
150 return rndis_bind_config_vendor(c, ethaddr, 0, NULL); 155 return rndis_bind_config_vendor(c, ethaddr, 0, NULL, dev);
151} 156}
152 157
153 158
diff --git a/drivers/usb/gadget/u_serial.h b/drivers/usb/gadget/u_serial.h
index 66ce73a00509..c20210c0babd 100644
--- a/drivers/usb/gadget/u_serial.h
+++ b/drivers/usb/gadget/u_serial.h
@@ -65,7 +65,6 @@ int gserial_connect(struct gserial *, u8 port_num);
65void gserial_disconnect(struct gserial *); 65void gserial_disconnect(struct gserial *);
66 66
67/* functions are bound to configurations by a config or gadget driver */ 67/* functions are bound to configurations by a config or gadget driver */
68int acm_bind_config(struct usb_configuration *c, u8 port_num);
69int gser_bind_config(struct usb_configuration *c, u8 port_num); 68int gser_bind_config(struct usb_configuration *c, u8 port_num);
70int obex_bind_config(struct usb_configuration *c, u8 port_num); 69int obex_bind_config(struct usb_configuration *c, u8 port_num);
71 70
diff --git a/drivers/usb/gadget/udc-core.c b/drivers/usb/gadget/udc-core.c
index f8f62c3ed65e..ffd8fa541101 100644
--- a/drivers/usb/gadget/udc-core.c
+++ b/drivers/usb/gadget/udc-core.c
@@ -101,6 +101,16 @@ EXPORT_SYMBOL_GPL(usb_gadget_unmap_request);
101 101
102/* ------------------------------------------------------------------------- */ 102/* ------------------------------------------------------------------------- */
103 103
104void usb_gadget_set_state(struct usb_gadget *gadget,
105 enum usb_device_state state)
106{
107 gadget->state = state;
108 sysfs_notify(&gadget->dev.kobj, NULL, "status");
109}
110EXPORT_SYMBOL_GPL(usb_gadget_set_state);
111
112/* ------------------------------------------------------------------------- */
113
104/** 114/**
105 * usb_gadget_udc_start - tells usb device controller to start up 115 * usb_gadget_udc_start - tells usb device controller to start up
106 * @gadget: The gadget we want to get started 116 * @gadget: The gadget we want to get started
@@ -156,15 +166,23 @@ static void usb_udc_release(struct device *dev)
156} 166}
157 167
158static const struct attribute_group *usb_udc_attr_groups[]; 168static const struct attribute_group *usb_udc_attr_groups[];
169
170static void usb_udc_nop_release(struct device *dev)
171{
172 dev_vdbg(dev, "%s\n", __func__);
173}
174
159/** 175/**
160 * usb_add_gadget_udc - adds a new gadget to the udc class driver list 176 * usb_add_gadget_udc_release - adds a new gadget to the udc class driver list
161 * @parent: the parent device to this udc. Usually the controller 177 * @parent: the parent device to this udc. Usually the controller driver's
162 * driver's device. 178 * device.
163 * @gadget: the gadget to be added to the list 179 * @gadget: the gadget to be added to the list.
180 * @release: a gadget release function.
164 * 181 *
165 * Returns zero on success, negative errno otherwise. 182 * Returns zero on success, negative errno otherwise.
166 */ 183 */
167int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget) 184int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget,
185 void (*release)(struct device *dev))
168{ 186{
169 struct usb_udc *udc; 187 struct usb_udc *udc;
170 int ret = -ENOMEM; 188 int ret = -ENOMEM;
@@ -173,6 +191,22 @@ int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget)
173 if (!udc) 191 if (!udc)
174 goto err1; 192 goto err1;
175 193
194 dev_set_name(&gadget->dev, "gadget");
195 gadget->dev.parent = parent;
196
197 dma_set_coherent_mask(&gadget->dev, parent->coherent_dma_mask);
198 gadget->dev.dma_parms = parent->dma_parms;
199 gadget->dev.dma_mask = parent->dma_mask;
200
201 if (release)
202 gadget->dev.release = release;
203 else
204 gadget->dev.release = usb_udc_nop_release;
205
206 ret = device_register(&gadget->dev);
207 if (ret)
208 goto err2;
209
176 device_initialize(&udc->dev); 210 device_initialize(&udc->dev);
177 udc->dev.release = usb_udc_release; 211 udc->dev.release = usb_udc_release;
178 udc->dev.class = udc_class; 212 udc->dev.class = udc_class;
@@ -180,7 +214,7 @@ int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget)
180 udc->dev.parent = parent; 214 udc->dev.parent = parent;
181 ret = dev_set_name(&udc->dev, "%s", kobject_name(&parent->kobj)); 215 ret = dev_set_name(&udc->dev, "%s", kobject_name(&parent->kobj));
182 if (ret) 216 if (ret)
183 goto err2; 217 goto err3;
184 218
185 udc->gadget = gadget; 219 udc->gadget = gadget;
186 220
@@ -189,21 +223,42 @@ int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget)
189 223
190 ret = device_add(&udc->dev); 224 ret = device_add(&udc->dev);
191 if (ret) 225 if (ret)
192 goto err3; 226 goto err4;
227
228 usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED);
193 229
194 mutex_unlock(&udc_lock); 230 mutex_unlock(&udc_lock);
195 231
196 return 0; 232 return 0;
197err3: 233
234err4:
198 list_del(&udc->list); 235 list_del(&udc->list);
199 mutex_unlock(&udc_lock); 236 mutex_unlock(&udc_lock);
200 237
201err2: 238err3:
202 put_device(&udc->dev); 239 put_device(&udc->dev);
203 240
241err2:
242 put_device(&gadget->dev);
243 kfree(udc);
244
204err1: 245err1:
205 return ret; 246 return ret;
206} 247}
248EXPORT_SYMBOL_GPL(usb_add_gadget_udc_release);
249
250/**
251 * usb_add_gadget_udc - adds a new gadget to the udc class driver list
252 * @parent: the parent device to this udc. Usually the controller
253 * driver's device.
254 * @gadget: the gadget to be added to the list
255 *
256 * Returns zero on success, negative errno otherwise.
257 */
258int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget)
259{
260 return usb_add_gadget_udc_release(parent, gadget, NULL);
261}
207EXPORT_SYMBOL_GPL(usb_add_gadget_udc); 262EXPORT_SYMBOL_GPL(usb_add_gadget_udc);
208 263
209static void usb_gadget_remove_driver(struct usb_udc *udc) 264static void usb_gadget_remove_driver(struct usb_udc *udc)
@@ -220,6 +275,7 @@ static void usb_gadget_remove_driver(struct usb_udc *udc)
220 275
221 udc->driver = NULL; 276 udc->driver = NULL;
222 udc->dev.driver = NULL; 277 udc->dev.driver = NULL;
278 udc->gadget->dev.driver = NULL;
223} 279}
224 280
225/** 281/**
@@ -254,6 +310,7 @@ found:
254 310
255 kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE); 311 kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE);
256 device_unregister(&udc->dev); 312 device_unregister(&udc->dev);
313 device_unregister(&gadget->dev);
257} 314}
258EXPORT_SYMBOL_GPL(usb_del_gadget_udc); 315EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
259 316
@@ -268,6 +325,7 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *dri
268 325
269 udc->driver = driver; 326 udc->driver = driver;
270 udc->dev.driver = &driver->driver; 327 udc->dev.driver = &driver->driver;
328 udc->gadget->dev.driver = &driver->driver;
271 329
272 ret = driver->bind(udc->gadget, driver); 330 ret = driver->bind(udc->gadget, driver);
273 if (ret) 331 if (ret)
@@ -286,6 +344,7 @@ err1:
286 udc->driver->function, ret); 344 udc->driver->function, ret);
287 udc->driver = NULL; 345 udc->driver = NULL;
288 udc->dev.driver = NULL; 346 udc->dev.driver = NULL;
347 udc->gadget->dev.driver = NULL;
289 return ret; 348 return ret;
290} 349}
291 350
@@ -395,6 +454,16 @@ static ssize_t usb_udc_softconn_store(struct device *dev,
395} 454}
396static DEVICE_ATTR(soft_connect, S_IWUSR, NULL, usb_udc_softconn_store); 455static DEVICE_ATTR(soft_connect, S_IWUSR, NULL, usb_udc_softconn_store);
397 456
457static ssize_t usb_gadget_state_show(struct device *dev,
458 struct device_attribute *attr, char *buf)
459{
460 struct usb_udc *udc = container_of(dev, struct usb_udc, dev);
461 struct usb_gadget *gadget = udc->gadget;
462
463 return sprintf(buf, "%s\n", usb_state_string(gadget->state));
464}
465static DEVICE_ATTR(state, S_IRUGO, usb_gadget_state_show, NULL);
466
398#define USB_UDC_SPEED_ATTR(name, param) \ 467#define USB_UDC_SPEED_ATTR(name, param) \
399ssize_t usb_udc_##param##_show(struct device *dev, \ 468ssize_t usb_udc_##param##_show(struct device *dev, \
400 struct device_attribute *attr, char *buf) \ 469 struct device_attribute *attr, char *buf) \
@@ -403,7 +472,7 @@ ssize_t usb_udc_##param##_show(struct device *dev, \
403 return snprintf(buf, PAGE_SIZE, "%s\n", \ 472 return snprintf(buf, PAGE_SIZE, "%s\n", \
404 usb_speed_string(udc->gadget->param)); \ 473 usb_speed_string(udc->gadget->param)); \
405} \ 474} \
406static DEVICE_ATTR(name, S_IRUSR, usb_udc_##param##_show, NULL) 475static DEVICE_ATTR(name, S_IRUGO, usb_udc_##param##_show, NULL)
407 476
408static USB_UDC_SPEED_ATTR(current_speed, speed); 477static USB_UDC_SPEED_ATTR(current_speed, speed);
409static USB_UDC_SPEED_ATTR(maximum_speed, max_speed); 478static USB_UDC_SPEED_ATTR(maximum_speed, max_speed);
@@ -428,6 +497,7 @@ static USB_UDC_ATTR(a_alt_hnp_support);
428static struct attribute *usb_udc_attrs[] = { 497static struct attribute *usb_udc_attrs[] = {
429 &dev_attr_srp.attr, 498 &dev_attr_srp.attr,
430 &dev_attr_soft_connect.attr, 499 &dev_attr_soft_connect.attr,
500 &dev_attr_state.attr,
431 &dev_attr_current_speed.attr, 501 &dev_attr_current_speed.attr,
432 &dev_attr_maximum_speed.attr, 502 &dev_attr_maximum_speed.attr,
433 503
diff --git a/drivers/usb/gadget/uvc.h b/drivers/usb/gadget/uvc.h
index 93b0c1191115..817e9e19cecf 100644
--- a/drivers/usb/gadget/uvc.h
+++ b/drivers/usb/gadget/uvc.h
@@ -98,8 +98,6 @@ extern unsigned int uvc_gadget_trace_param;
98#define DRIVER_VERSION "0.1.0" 98#define DRIVER_VERSION "0.1.0"
99#define DRIVER_VERSION_NUMBER KERNEL_VERSION(0, 1, 0) 99#define DRIVER_VERSION_NUMBER KERNEL_VERSION(0, 1, 0)
100 100
101#define DMA_ADDR_INVALID (~(dma_addr_t)0)
102
103#define UVC_NUM_REQUESTS 4 101#define UVC_NUM_REQUESTS 4
104#define UVC_MAX_REQUEST_SIZE 64 102#define UVC_MAX_REQUEST_SIZE 64
105#define UVC_MAX_EVENTS 4 103#define UVC_MAX_EVENTS 4
@@ -190,6 +188,7 @@ struct uvc_file_handle
190 * Functions 188 * Functions
191 */ 189 */
192 190
191extern void uvc_function_setup_continue(struct uvc_device *uvc);
193extern void uvc_endpoint_stream(struct uvc_device *dev); 192extern void uvc_endpoint_stream(struct uvc_device *dev);
194 193
195extern void uvc_function_connect(struct uvc_device *uvc); 194extern void uvc_function_connect(struct uvc_device *uvc);
diff --git a/drivers/usb/gadget/uvc_queue.c b/drivers/usb/gadget/uvc_queue.c
index 104ae9c81251..7ce27e35550b 100644
--- a/drivers/usb/gadget/uvc_queue.c
+++ b/drivers/usb/gadget/uvc_queue.c
@@ -10,6 +10,7 @@
10 * (at your option) any later version. 10 * (at your option) any later version.
11 */ 11 */
12 12
13#include <linux/atomic.h>
13#include <linux/kernel.h> 14#include <linux/kernel.h>
14#include <linux/mm.h> 15#include <linux/mm.h>
15#include <linux/list.h> 16#include <linux/list.h>
@@ -18,7 +19,8 @@
18#include <linux/videodev2.h> 19#include <linux/videodev2.h>
19#include <linux/vmalloc.h> 20#include <linux/vmalloc.h>
20#include <linux/wait.h> 21#include <linux/wait.h>
21#include <linux/atomic.h> 22
23#include <media/videobuf2-vmalloc.h>
22 24
23#include "uvc.h" 25#include "uvc.h"
24 26
@@ -28,330 +30,175 @@
28 * Video queues is initialized by uvc_queue_init(). The function performs 30 * Video queues is initialized by uvc_queue_init(). The function performs
29 * basic initialization of the uvc_video_queue struct and never fails. 31 * basic initialization of the uvc_video_queue struct and never fails.
30 * 32 *
31 * Video buffer allocation and freeing are performed by uvc_alloc_buffers and 33 * Video buffers are managed by videobuf2. The driver uses a mutex to protect
32 * uvc_free_buffers respectively. The former acquires the video queue lock, 34 * the videobuf2 queue operations by serializing calls to videobuf2 and a
33 * while the later must be called with the lock held (so that allocation can 35 * spinlock to protect the IRQ queue that holds the buffers to be processed by
34 * free previously allocated buffers). Trying to free buffers that are mapped 36 * the driver.
35 * to user space will return -EBUSY.
36 *
37 * Video buffers are managed using two queues. However, unlike most USB video
38 * drivers that use an in queue and an out queue, we use a main queue to hold
39 * all queued buffers (both 'empty' and 'done' buffers), and an irq queue to
40 * hold empty buffers. This design (copied from video-buf) minimizes locking
41 * in interrupt, as only one queue is shared between interrupt and user
42 * contexts.
43 *
44 * Use cases
45 * ---------
46 *
47 * Unless stated otherwise, all operations that modify the irq buffers queue
48 * are protected by the irq spinlock.
49 *
50 * 1. The user queues the buffers, starts streaming and dequeues a buffer.
51 *
52 * The buffers are added to the main and irq queues. Both operations are
53 * protected by the queue lock, and the later is protected by the irq
54 * spinlock as well.
55 *
56 * The completion handler fetches a buffer from the irq queue and fills it
57 * with video data. If no buffer is available (irq queue empty), the handler
58 * returns immediately.
59 *
60 * When the buffer is full, the completion handler removes it from the irq
61 * queue, marks it as ready (UVC_BUF_STATE_DONE) and wakes its wait queue.
62 * At that point, any process waiting on the buffer will be woken up. If a
63 * process tries to dequeue a buffer after it has been marked ready, the
64 * dequeing will succeed immediately.
65 *
66 * 2. Buffers are queued, user is waiting on a buffer and the device gets
67 * disconnected.
68 *
69 * When the device is disconnected, the kernel calls the completion handler
70 * with an appropriate status code. The handler marks all buffers in the
71 * irq queue as being erroneous (UVC_BUF_STATE_ERROR) and wakes them up so
72 * that any process waiting on a buffer gets woken up.
73 *
74 * Waking up up the first buffer on the irq list is not enough, as the
75 * process waiting on the buffer might restart the dequeue operation
76 * immediately.
77 *
78 */ 37 */
79 38
80static void 39/* -----------------------------------------------------------------------------
81uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type) 40 * videobuf2 queue operations
82{
83 mutex_init(&queue->mutex);
84 spin_lock_init(&queue->irqlock);
85 INIT_LIST_HEAD(&queue->mainqueue);
86 INIT_LIST_HEAD(&queue->irqqueue);
87 queue->type = type;
88}
89
90/*
91 * Free the video buffers.
92 *
93 * This function must be called with the queue lock held.
94 */ 41 */
95static int uvc_free_buffers(struct uvc_video_queue *queue) 42
43static int uvc_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
44 unsigned int *nbuffers, unsigned int *nplanes,
45 unsigned int sizes[], void *alloc_ctxs[])
96{ 46{
97 unsigned int i; 47 struct uvc_video_queue *queue = vb2_get_drv_priv(vq);
48 struct uvc_video *video = container_of(queue, struct uvc_video, queue);
98 49
99 for (i = 0; i < queue->count; ++i) { 50 if (*nbuffers > UVC_MAX_VIDEO_BUFFERS)
100 if (queue->buffer[i].vma_use_count != 0) 51 *nbuffers = UVC_MAX_VIDEO_BUFFERS;
101 return -EBUSY;
102 }
103 52
104 if (queue->count) { 53 *nplanes = 1;
105 vfree(queue->mem); 54
106 queue->count = 0; 55 sizes[0] = video->imagesize;
107 }
108 56
109 return 0; 57 return 0;
110} 58}
111 59
112/* 60static int uvc_buffer_prepare(struct vb2_buffer *vb)
113 * Allocate the video buffers.
114 *
115 * Pages are reserved to make sure they will not be swapped, as they will be
116 * filled in the URB completion handler.
117 *
118 * Buffers will be individually mapped, so they must all be page aligned.
119 */
120static int
121uvc_alloc_buffers(struct uvc_video_queue *queue, unsigned int nbuffers,
122 unsigned int buflength)
123{ 61{
124 unsigned int bufsize = PAGE_ALIGN(buflength); 62 struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2_queue);
125 unsigned int i; 63 struct uvc_buffer *buf = container_of(vb, struct uvc_buffer, buf);
126 void *mem = NULL;
127 int ret;
128 64
129 if (nbuffers > UVC_MAX_VIDEO_BUFFERS) 65 if (vb->v4l2_buf.type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
130 nbuffers = UVC_MAX_VIDEO_BUFFERS; 66 vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0)) {
67 uvc_trace(UVC_TRACE_CAPTURE, "[E] Bytes used out of bounds.\n");
68 return -EINVAL;
69 }
131 70
132 mutex_lock(&queue->mutex); 71 if (unlikely(queue->flags & UVC_QUEUE_DISCONNECTED))
72 return -ENODEV;
133 73
134 if ((ret = uvc_free_buffers(queue)) < 0) 74 buf->state = UVC_BUF_STATE_QUEUED;
135 goto done; 75 buf->mem = vb2_plane_vaddr(vb, 0);
76 buf->length = vb2_plane_size(vb, 0);
77 if (vb->v4l2_buf.type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
78 buf->bytesused = 0;
79 else
80 buf->bytesused = vb2_get_plane_payload(vb, 0);
136 81
137 /* Bail out if no buffers should be allocated. */ 82 return 0;
138 if (nbuffers == 0) 83}
139 goto done;
140 84
141 /* Decrement the number of buffers until allocation succeeds. */ 85static void uvc_buffer_queue(struct vb2_buffer *vb)
142 for (; nbuffers > 0; --nbuffers) { 86{
143 mem = vmalloc_32(nbuffers * bufsize); 87 struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2_queue);
144 if (mem != NULL) 88 struct uvc_buffer *buf = container_of(vb, struct uvc_buffer, buf);
145 break; 89 unsigned long flags;
146 }
147 90
148 if (mem == NULL) { 91 spin_lock_irqsave(&queue->irqlock, flags);
149 ret = -ENOMEM;
150 goto done;
151 }
152 92
153 for (i = 0; i < nbuffers; ++i) { 93 if (likely(!(queue->flags & UVC_QUEUE_DISCONNECTED))) {
154 memset(&queue->buffer[i], 0, sizeof queue->buffer[i]); 94 list_add_tail(&buf->queue, &queue->irqqueue);
155 queue->buffer[i].buf.index = i; 95 } else {
156 queue->buffer[i].buf.m.offset = i * bufsize; 96 /* If the device is disconnected return the buffer to userspace
157 queue->buffer[i].buf.length = buflength; 97 * directly. The next QBUF call will fail with -ENODEV.
158 queue->buffer[i].buf.type = queue->type; 98 */
159 queue->buffer[i].buf.sequence = 0; 99 buf->state = UVC_BUF_STATE_ERROR;
160 queue->buffer[i].buf.field = V4L2_FIELD_NONE; 100 vb2_buffer_done(&buf->buf, VB2_BUF_STATE_ERROR);
161 queue->buffer[i].buf.memory = V4L2_MEMORY_MMAP;
162 queue->buffer[i].buf.flags = 0;
163 init_waitqueue_head(&queue->buffer[i].wait);
164 } 101 }
165 102
166 queue->mem = mem; 103 spin_unlock_irqrestore(&queue->irqlock, flags);
167 queue->count = nbuffers;
168 queue->buf_size = bufsize;
169 ret = nbuffers;
170
171done:
172 mutex_unlock(&queue->mutex);
173 return ret;
174} 104}
175 105
176static void __uvc_query_buffer(struct uvc_buffer *buf, 106static struct vb2_ops uvc_queue_qops = {
177 struct v4l2_buffer *v4l2_buf) 107 .queue_setup = uvc_queue_setup,
178{ 108 .buf_prepare = uvc_buffer_prepare,
179 memcpy(v4l2_buf, &buf->buf, sizeof *v4l2_buf); 109 .buf_queue = uvc_buffer_queue,
180 110};
181 if (buf->vma_use_count)
182 v4l2_buf->flags |= V4L2_BUF_FLAG_MAPPED;
183
184 switch (buf->state) {
185 case UVC_BUF_STATE_ERROR:
186 case UVC_BUF_STATE_DONE:
187 v4l2_buf->flags |= V4L2_BUF_FLAG_DONE;
188 break;
189 case UVC_BUF_STATE_QUEUED:
190 case UVC_BUF_STATE_ACTIVE:
191 v4l2_buf->flags |= V4L2_BUF_FLAG_QUEUED;
192 break;
193 case UVC_BUF_STATE_IDLE:
194 default:
195 break;
196 }
197}
198 111
199static int 112static int uvc_queue_init(struct uvc_video_queue *queue,
200uvc_query_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *v4l2_buf) 113 enum v4l2_buf_type type)
201{ 114{
202 int ret = 0; 115 int ret;
203 116
204 mutex_lock(&queue->mutex); 117 queue->queue.type = type;
205 if (v4l2_buf->index >= queue->count) { 118 queue->queue.io_modes = VB2_MMAP | VB2_USERPTR;
206 ret = -EINVAL; 119 queue->queue.drv_priv = queue;
207 goto done; 120 queue->queue.buf_struct_size = sizeof(struct uvc_buffer);
208 } 121 queue->queue.ops = &uvc_queue_qops;
122 queue->queue.mem_ops = &vb2_vmalloc_memops;
123 ret = vb2_queue_init(&queue->queue);
124 if (ret)
125 return ret;
126
127 mutex_init(&queue->mutex);
128 spin_lock_init(&queue->irqlock);
129 INIT_LIST_HEAD(&queue->irqqueue);
130 queue->flags = 0;
209 131
210 __uvc_query_buffer(&queue->buffer[v4l2_buf->index], v4l2_buf); 132 return 0;
133}
211 134
212done: 135/*
136 * Free the video buffers.
137 */
138static void uvc_free_buffers(struct uvc_video_queue *queue)
139{
140 mutex_lock(&queue->mutex);
141 vb2_queue_release(&queue->queue);
213 mutex_unlock(&queue->mutex); 142 mutex_unlock(&queue->mutex);
214 return ret;
215} 143}
216 144
217/* 145/*
218 * Queue a video buffer. Attempting to queue a buffer that has already been 146 * Allocate the video buffers.
219 * queued will return -EINVAL.
220 */ 147 */
221static int 148static int uvc_alloc_buffers(struct uvc_video_queue *queue,
222uvc_queue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *v4l2_buf) 149 struct v4l2_requestbuffers *rb)
223{ 150{
224 struct uvc_buffer *buf; 151 int ret;
225 unsigned long flags;
226 int ret = 0;
227 152
228 uvc_trace(UVC_TRACE_CAPTURE, "Queuing buffer %u.\n", v4l2_buf->index); 153 mutex_lock(&queue->mutex);
154 ret = vb2_reqbufs(&queue->queue, rb);
155 mutex_unlock(&queue->mutex);
229 156
230 if (v4l2_buf->type != queue->type || 157 return ret ? ret : rb->count;
231 v4l2_buf->memory != V4L2_MEMORY_MMAP) { 158}
232 uvc_trace(UVC_TRACE_CAPTURE, "[E] Invalid buffer type (%u) "
233 "and/or memory (%u).\n", v4l2_buf->type,
234 v4l2_buf->memory);
235 return -EINVAL;
236 }
237 159
238 mutex_lock(&queue->mutex); 160static int uvc_query_buffer(struct uvc_video_queue *queue,
239 if (v4l2_buf->index >= queue->count) { 161 struct v4l2_buffer *buf)
240 uvc_trace(UVC_TRACE_CAPTURE, "[E] Out of range index.\n"); 162{
241 ret = -EINVAL; 163 int ret;
242 goto done;
243 }
244 164
245 buf = &queue->buffer[v4l2_buf->index]; 165 mutex_lock(&queue->mutex);
246 if (buf->state != UVC_BUF_STATE_IDLE) { 166 ret = vb2_querybuf(&queue->queue, buf);
247 uvc_trace(UVC_TRACE_CAPTURE, "[E] Invalid buffer state " 167 mutex_unlock(&queue->mutex);
248 "(%u).\n", buf->state);
249 ret = -EINVAL;
250 goto done;
251 }
252 168
253 if (v4l2_buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT && 169 return ret;
254 v4l2_buf->bytesused > buf->buf.length) { 170}
255 uvc_trace(UVC_TRACE_CAPTURE, "[E] Bytes used out of bounds.\n");
256 ret = -EINVAL;
257 goto done;
258 }
259 171
260 if (v4l2_buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) 172static int uvc_queue_buffer(struct uvc_video_queue *queue,
261 buf->buf.bytesused = 0; 173 struct v4l2_buffer *buf)
262 else 174{
263 buf->buf.bytesused = v4l2_buf->bytesused; 175 unsigned long flags;
176 int ret;
264 177
178 mutex_lock(&queue->mutex);
179 ret = vb2_qbuf(&queue->queue, buf);
265 spin_lock_irqsave(&queue->irqlock, flags); 180 spin_lock_irqsave(&queue->irqlock, flags);
266 if (queue->flags & UVC_QUEUE_DISCONNECTED) {
267 spin_unlock_irqrestore(&queue->irqlock, flags);
268 ret = -ENODEV;
269 goto done;
270 }
271 buf->state = UVC_BUF_STATE_QUEUED;
272
273 ret = (queue->flags & UVC_QUEUE_PAUSED) != 0; 181 ret = (queue->flags & UVC_QUEUE_PAUSED) != 0;
274 queue->flags &= ~UVC_QUEUE_PAUSED; 182 queue->flags &= ~UVC_QUEUE_PAUSED;
275
276 list_add_tail(&buf->stream, &queue->mainqueue);
277 list_add_tail(&buf->queue, &queue->irqqueue);
278 spin_unlock_irqrestore(&queue->irqlock, flags); 183 spin_unlock_irqrestore(&queue->irqlock, flags);
279
280done:
281 mutex_unlock(&queue->mutex); 184 mutex_unlock(&queue->mutex);
282 return ret;
283}
284 185
285static int uvc_queue_waiton(struct uvc_buffer *buf, int nonblocking) 186 return ret;
286{
287 if (nonblocking) {
288 return (buf->state != UVC_BUF_STATE_QUEUED &&
289 buf->state != UVC_BUF_STATE_ACTIVE)
290 ? 0 : -EAGAIN;
291 }
292
293 return wait_event_interruptible(buf->wait,
294 buf->state != UVC_BUF_STATE_QUEUED &&
295 buf->state != UVC_BUF_STATE_ACTIVE);
296} 187}
297 188
298/* 189/*
299 * Dequeue a video buffer. If nonblocking is false, block until a buffer is 190 * Dequeue a video buffer. If nonblocking is false, block until a buffer is
300 * available. 191 * available.
301 */ 192 */
302static int 193static int uvc_dequeue_buffer(struct uvc_video_queue *queue,
303uvc_dequeue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *v4l2_buf, 194 struct v4l2_buffer *buf, int nonblocking)
304 int nonblocking)
305{ 195{
306 struct uvc_buffer *buf; 196 int ret;
307 int ret = 0;
308
309 if (v4l2_buf->type != queue->type ||
310 v4l2_buf->memory != V4L2_MEMORY_MMAP) {
311 uvc_trace(UVC_TRACE_CAPTURE, "[E] Invalid buffer type (%u) "
312 "and/or memory (%u).\n", v4l2_buf->type,
313 v4l2_buf->memory);
314 return -EINVAL;
315 }
316 197
317 mutex_lock(&queue->mutex); 198 mutex_lock(&queue->mutex);
318 if (list_empty(&queue->mainqueue)) { 199 ret = vb2_dqbuf(&queue->queue, buf, nonblocking);
319 uvc_trace(UVC_TRACE_CAPTURE, "[E] Empty buffer queue.\n");
320 ret = -EINVAL;
321 goto done;
322 }
323
324 buf = list_first_entry(&queue->mainqueue, struct uvc_buffer, stream);
325 if ((ret = uvc_queue_waiton(buf, nonblocking)) < 0)
326 goto done;
327
328 uvc_trace(UVC_TRACE_CAPTURE, "Dequeuing buffer %u (%u, %u bytes).\n",
329 buf->buf.index, buf->state, buf->buf.bytesused);
330
331 switch (buf->state) {
332 case UVC_BUF_STATE_ERROR:
333 uvc_trace(UVC_TRACE_CAPTURE, "[W] Corrupted data "
334 "(transmission error).\n");
335 ret = -EIO;
336 case UVC_BUF_STATE_DONE:
337 buf->state = UVC_BUF_STATE_IDLE;
338 break;
339
340 case UVC_BUF_STATE_IDLE:
341 case UVC_BUF_STATE_QUEUED:
342 case UVC_BUF_STATE_ACTIVE:
343 default:
344 uvc_trace(UVC_TRACE_CAPTURE, "[E] Invalid buffer state %u "
345 "(driver bug?).\n", buf->state);
346 ret = -EINVAL;
347 goto done;
348 }
349
350 list_del(&buf->stream);
351 __uvc_query_buffer(buf, v4l2_buf);
352
353done:
354 mutex_unlock(&queue->mutex); 200 mutex_unlock(&queue->mutex);
201
355 return ret; 202 return ret;
356} 203}
357 204
@@ -361,105 +208,47 @@ done:
361 * This function implements video queue polling and is intended to be used by 208 * This function implements video queue polling and is intended to be used by
362 * the device poll handler. 209 * the device poll handler.
363 */ 210 */
364static unsigned int 211static unsigned int uvc_queue_poll(struct uvc_video_queue *queue,
365uvc_queue_poll(struct uvc_video_queue *queue, struct file *file, 212 struct file *file, poll_table *wait)
366 poll_table *wait)
367{ 213{
368 struct uvc_buffer *buf; 214 unsigned int ret;
369 unsigned int mask = 0;
370 215
371 mutex_lock(&queue->mutex); 216 mutex_lock(&queue->mutex);
372 if (list_empty(&queue->mainqueue)) 217 ret = vb2_poll(&queue->queue, file, wait);
373 goto done;
374
375 buf = list_first_entry(&queue->mainqueue, struct uvc_buffer, stream);
376
377 poll_wait(file, &buf->wait, wait);
378 if (buf->state == UVC_BUF_STATE_DONE ||
379 buf->state == UVC_BUF_STATE_ERROR)
380 mask |= POLLOUT | POLLWRNORM;
381
382done:
383 mutex_unlock(&queue->mutex); 218 mutex_unlock(&queue->mutex);
384 return mask;
385}
386 219
387/* 220 return ret;
388 * VMA operations.
389 */
390static void uvc_vm_open(struct vm_area_struct *vma)
391{
392 struct uvc_buffer *buffer = vma->vm_private_data;
393 buffer->vma_use_count++;
394} 221}
395 222
396static void uvc_vm_close(struct vm_area_struct *vma) 223static int uvc_queue_mmap(struct uvc_video_queue *queue,
224 struct vm_area_struct *vma)
397{ 225{
398 struct uvc_buffer *buffer = vma->vm_private_data; 226 int ret;
399 buffer->vma_use_count--;
400}
401 227
402static struct vm_operations_struct uvc_vm_ops = { 228 mutex_lock(&queue->mutex);
403 .open = uvc_vm_open, 229 ret = vb2_mmap(&queue->queue, vma);
404 .close = uvc_vm_close, 230 mutex_unlock(&queue->mutex);
405}; 231
232 return ret;
233}
406 234
235#ifndef CONFIG_MMU
407/* 236/*
408 * Memory-map a buffer. 237 * Get unmapped area.
409 * 238 *
410 * This function implements video buffer memory mapping and is intended to be 239 * NO-MMU arch need this function to make mmap() work correctly.
411 * used by the device mmap handler.
412 */ 240 */
413static int 241static unsigned long uvc_queue_get_unmapped_area(struct uvc_video_queue *queue,
414uvc_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *vma) 242 unsigned long pgoff)
415{ 243{
416 struct uvc_buffer *uninitialized_var(buffer); 244 unsigned long ret;
417 struct page *page;
418 unsigned long addr, start, size;
419 unsigned int i;
420 int ret = 0;
421
422 start = vma->vm_start;
423 size = vma->vm_end - vma->vm_start;
424 245
425 mutex_lock(&queue->mutex); 246 mutex_lock(&queue->mutex);
426 247 ret = vb2_get_unmapped_area(&queue->queue, 0, 0, pgoff, 0);
427 for (i = 0; i < queue->count; ++i) {
428 buffer = &queue->buffer[i];
429 if ((buffer->buf.m.offset >> PAGE_SHIFT) == vma->vm_pgoff)
430 break;
431 }
432
433 if (i == queue->count || size != queue->buf_size) {
434 ret = -EINVAL;
435 goto done;
436 }
437
438 /*
439 * VM_IO marks the area as being an mmaped region for I/O to a
440 * device. It also prevents the region from being core dumped.
441 */
442 vma->vm_flags |= VM_IO;
443
444 addr = (unsigned long)queue->mem + buffer->buf.m.offset;
445 while (size > 0) {
446 page = vmalloc_to_page((void *)addr);
447 if ((ret = vm_insert_page(vma, start, page)) < 0)
448 goto done;
449
450 start += PAGE_SIZE;
451 addr += PAGE_SIZE;
452 size -= PAGE_SIZE;
453 }
454
455 vma->vm_ops = &uvc_vm_ops;
456 vma->vm_private_data = buffer;
457 uvc_vm_open(vma);
458
459done:
460 mutex_unlock(&queue->mutex); 248 mutex_unlock(&queue->mutex);
461 return ret; 249 return ret;
462} 250}
251#endif
463 252
464/* 253/*
465 * Cancel the video buffers queue. 254 * Cancel the video buffers queue.
@@ -484,7 +273,7 @@ static void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect)
484 queue); 273 queue);
485 list_del(&buf->queue); 274 list_del(&buf->queue);
486 buf->state = UVC_BUF_STATE_ERROR; 275 buf->state = UVC_BUF_STATE_ERROR;
487 wake_up(&buf->wait); 276 vb2_buffer_done(&buf->buf, VB2_BUF_STATE_ERROR);
488 } 277 }
489 /* This must be protected by the irqlock spinlock to avoid race 278 /* This must be protected by the irqlock spinlock to avoid race
490 * conditions between uvc_queue_buffer and the disconnection event that 279 * conditions between uvc_queue_buffer and the disconnection event that
@@ -516,26 +305,33 @@ static void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect)
516 */ 305 */
517static int uvc_queue_enable(struct uvc_video_queue *queue, int enable) 306static int uvc_queue_enable(struct uvc_video_queue *queue, int enable)
518{ 307{
519 unsigned int i; 308 unsigned long flags;
520 int ret = 0; 309 int ret = 0;
521 310
522 mutex_lock(&queue->mutex); 311 mutex_lock(&queue->mutex);
523 if (enable) { 312 if (enable) {
524 if (uvc_queue_streaming(queue)) { 313 ret = vb2_streamon(&queue->queue, queue->queue.type);
525 ret = -EBUSY; 314 if (ret < 0)
526 goto done; 315 goto done;
527 } 316
528 queue->sequence = 0; 317 queue->sequence = 0;
529 queue->flags |= UVC_QUEUE_STREAMING;
530 queue->buf_used = 0; 318 queue->buf_used = 0;
531 } else { 319 } else {
532 uvc_queue_cancel(queue, 0); 320 ret = vb2_streamoff(&queue->queue, queue->queue.type);
533 INIT_LIST_HEAD(&queue->mainqueue); 321 if (ret < 0)
322 goto done;
534 323
535 for (i = 0; i < queue->count; ++i) 324 spin_lock_irqsave(&queue->irqlock, flags);
536 queue->buffer[i].state = UVC_BUF_STATE_IDLE; 325 INIT_LIST_HEAD(&queue->irqqueue);
537 326
538 queue->flags &= ~UVC_QUEUE_STREAMING; 327 /*
328 * FIXME: We need to clear the DISCONNECTED flag to ensure that
329 * applications will be able to queue buffers for the next
330 * streaming run. However, clearing it here doesn't guarantee
331 * that the device will be reconnected in the meantime.
332 */
333 queue->flags &= ~UVC_QUEUE_DISCONNECTED;
334 spin_unlock_irqrestore(&queue->irqlock, flags);
539 } 335 }
540 336
541done: 337done:
@@ -544,15 +340,15 @@ done:
544} 340}
545 341
546/* called with &queue_irqlock held.. */ 342/* called with &queue_irqlock held.. */
547static struct uvc_buffer * 343static struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
548uvc_queue_next_buffer(struct uvc_video_queue *queue, struct uvc_buffer *buf) 344 struct uvc_buffer *buf)
549{ 345{
550 struct uvc_buffer *nextbuf; 346 struct uvc_buffer *nextbuf;
551 347
552 if ((queue->flags & UVC_QUEUE_DROP_INCOMPLETE) && 348 if ((queue->flags & UVC_QUEUE_DROP_INCOMPLETE) &&
553 buf->buf.length != buf->buf.bytesused) { 349 buf->length != buf->bytesused) {
554 buf->state = UVC_BUF_STATE_QUEUED; 350 buf->state = UVC_BUF_STATE_QUEUED;
555 buf->buf.bytesused = 0; 351 vb2_set_plane_payload(&buf->buf, 0, 0);
556 return buf; 352 return buf;
557 } 353 }
558 354
@@ -563,10 +359,18 @@ uvc_queue_next_buffer(struct uvc_video_queue *queue, struct uvc_buffer *buf)
563 else 359 else
564 nextbuf = NULL; 360 nextbuf = NULL;
565 361
566 buf->buf.sequence = queue->sequence++; 362 /*
567 do_gettimeofday(&buf->buf.timestamp); 363 * FIXME: with videobuf2, the sequence number or timestamp fields
364 * are valid only for video capture devices and the UVC gadget usually
365 * is a video output device. Keeping these until the specs are clear on
366 * this aspect.
367 */
368 buf->buf.v4l2_buf.sequence = queue->sequence++;
369 do_gettimeofday(&buf->buf.v4l2_buf.timestamp);
370
371 vb2_set_plane_payload(&buf->buf, 0, buf->bytesused);
372 vb2_buffer_done(&buf->buf, VB2_BUF_STATE_DONE);
568 373
569 wake_up(&buf->wait);
570 return nextbuf; 374 return nextbuf;
571} 375}
572 376
diff --git a/drivers/usb/gadget/uvc_queue.h b/drivers/usb/gadget/uvc_queue.h
index 1812a8ecc5d0..8e76ce982f1e 100644
--- a/drivers/usb/gadget/uvc_queue.h
+++ b/drivers/usb/gadget/uvc_queue.h
@@ -6,6 +6,7 @@
6#include <linux/kernel.h> 6#include <linux/kernel.h>
7#include <linux/poll.h> 7#include <linux/poll.h>
8#include <linux/videodev2.h> 8#include <linux/videodev2.h>
9#include <media/videobuf2-core.h>
9 10
10/* Maximum frame size in bytes, for sanity checking. */ 11/* Maximum frame size in bytes, for sanity checking. */
11#define UVC_MAX_FRAME_SIZE (16*1024*1024) 12#define UVC_MAX_FRAME_SIZE (16*1024*1024)
@@ -25,42 +26,35 @@ enum uvc_buffer_state {
25}; 26};
26 27
27struct uvc_buffer { 28struct uvc_buffer {
28 unsigned long vma_use_count; 29 struct vb2_buffer buf;
29 struct list_head stream;
30
31 /* Touched by interrupt handler. */
32 struct v4l2_buffer buf;
33 struct list_head queue; 30 struct list_head queue;
34 wait_queue_head_t wait; 31
35 enum uvc_buffer_state state; 32 enum uvc_buffer_state state;
33 void *mem;
34 unsigned int length;
35 unsigned int bytesused;
36}; 36};
37 37
38#define UVC_QUEUE_STREAMING (1 << 0) 38#define UVC_QUEUE_DISCONNECTED (1 << 0)
39#define UVC_QUEUE_DISCONNECTED (1 << 1) 39#define UVC_QUEUE_DROP_INCOMPLETE (1 << 1)
40#define UVC_QUEUE_DROP_INCOMPLETE (1 << 2) 40#define UVC_QUEUE_PAUSED (1 << 2)
41#define UVC_QUEUE_PAUSED (1 << 3)
42 41
43struct uvc_video_queue { 42struct uvc_video_queue {
44 enum v4l2_buf_type type; 43 struct vb2_queue queue;
44 struct mutex mutex; /* Protects queue */
45 45
46 void *mem;
47 unsigned int flags; 46 unsigned int flags;
48 __u32 sequence; 47 __u32 sequence;
49 48
50 unsigned int count;
51 unsigned int buf_size;
52 unsigned int buf_used; 49 unsigned int buf_used;
53 struct uvc_buffer buffer[UVC_MAX_VIDEO_BUFFERS];
54 struct mutex mutex; /* protects buffers and mainqueue */
55 spinlock_t irqlock; /* protects irqqueue */
56 50
57 struct list_head mainqueue; 51 spinlock_t irqlock; /* Protects flags and irqqueue */
58 struct list_head irqqueue; 52 struct list_head irqqueue;
59}; 53};
60 54
61static inline int uvc_queue_streaming(struct uvc_video_queue *queue) 55static inline int uvc_queue_streaming(struct uvc_video_queue *queue)
62{ 56{
63 return queue->flags & UVC_QUEUE_STREAMING; 57 return vb2_is_streaming(&queue->queue);
64} 58}
65 59
66#endif /* __KERNEL__ */ 60#endif /* __KERNEL__ */
diff --git a/drivers/usb/gadget/uvc_v4l2.c b/drivers/usb/gadget/uvc_v4l2.c
index 2ca9386d655b..ad48e81155e2 100644
--- a/drivers/usb/gadget/uvc_v4l2.c
+++ b/drivers/usb/gadget/uvc_v4l2.c
@@ -41,9 +41,8 @@ uvc_send_response(struct uvc_device *uvc, struct uvc_request_data *data)
41 41
42 req->length = min_t(unsigned int, uvc->event_length, data->length); 42 req->length = min_t(unsigned int, uvc->event_length, data->length);
43 req->zero = data->length < uvc->event_length; 43 req->zero = data->length < uvc->event_length;
44 req->dma = DMA_ADDR_INVALID;
45 44
46 memcpy(req->buf, data->data, data->length); 45 memcpy(req->buf, data->data, req->length);
47 46
48 return usb_ep_queue(cdev->gadget->ep0, req, GFP_KERNEL); 47 return usb_ep_queue(cdev->gadget->ep0, req, GFP_KERNEL);
49} 48}
@@ -148,16 +147,13 @@ uvc_v4l2_release(struct file *file)
148 uvc_function_disconnect(uvc); 147 uvc_function_disconnect(uvc);
149 148
150 uvc_video_enable(video, 0); 149 uvc_video_enable(video, 0);
151 mutex_lock(&video->queue.mutex); 150 uvc_free_buffers(&video->queue);
152 if (uvc_free_buffers(&video->queue) < 0)
153 printk(KERN_ERR "uvc_v4l2_release: Unable to free "
154 "buffers.\n");
155 mutex_unlock(&video->queue.mutex);
156 151
157 file->private_data = NULL; 152 file->private_data = NULL;
158 v4l2_fh_del(&handle->vfh); 153 v4l2_fh_del(&handle->vfh);
159 v4l2_fh_exit(&handle->vfh); 154 v4l2_fh_exit(&handle->vfh);
160 kfree(handle); 155 kfree(handle);
156
161 return 0; 157 return 0;
162} 158}
163 159
@@ -178,9 +174,9 @@ uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
178 struct v4l2_capability *cap = arg; 174 struct v4l2_capability *cap = arg;
179 175
180 memset(cap, 0, sizeof *cap); 176 memset(cap, 0, sizeof *cap);
181 strncpy(cap->driver, "g_uvc", sizeof(cap->driver)); 177 strlcpy(cap->driver, "g_uvc", sizeof(cap->driver));
182 strncpy(cap->card, cdev->gadget->name, sizeof(cap->card)); 178 strlcpy(cap->card, cdev->gadget->name, sizeof(cap->card));
183 strncpy(cap->bus_info, dev_name(&cdev->gadget->dev), 179 strlcpy(cap->bus_info, dev_name(&cdev->gadget->dev),
184 sizeof cap->bus_info); 180 sizeof cap->bus_info);
185 cap->version = DRIVER_VERSION_NUMBER; 181 cap->version = DRIVER_VERSION_NUMBER;
186 cap->capabilities = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING; 182 cap->capabilities = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
@@ -192,7 +188,7 @@ uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
192 { 188 {
193 struct v4l2_format *fmt = arg; 189 struct v4l2_format *fmt = arg;
194 190
195 if (fmt->type != video->queue.type) 191 if (fmt->type != video->queue.queue.type)
196 return -EINVAL; 192 return -EINVAL;
197 193
198 return uvc_v4l2_get_format(video, fmt); 194 return uvc_v4l2_get_format(video, fmt);
@@ -202,7 +198,7 @@ uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
202 { 198 {
203 struct v4l2_format *fmt = arg; 199 struct v4l2_format *fmt = arg;
204 200
205 if (fmt->type != video->queue.type) 201 if (fmt->type != video->queue.queue.type)
206 return -EINVAL; 202 return -EINVAL;
207 203
208 return uvc_v4l2_set_format(video, fmt); 204 return uvc_v4l2_set_format(video, fmt);
@@ -213,16 +209,13 @@ uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
213 { 209 {
214 struct v4l2_requestbuffers *rb = arg; 210 struct v4l2_requestbuffers *rb = arg;
215 211
216 if (rb->type != video->queue.type || 212 if (rb->type != video->queue.queue.type)
217 rb->memory != V4L2_MEMORY_MMAP)
218 return -EINVAL; 213 return -EINVAL;
219 214
220 ret = uvc_alloc_buffers(&video->queue, rb->count, 215 ret = uvc_alloc_buffers(&video->queue, rb);
221 video->imagesize);
222 if (ret < 0) 216 if (ret < 0)
223 return ret; 217 return ret;
224 218
225 rb->count = ret;
226 ret = 0; 219 ret = 0;
227 break; 220 break;
228 } 221 }
@@ -231,9 +224,6 @@ uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
231 { 224 {
232 struct v4l2_buffer *buf = arg; 225 struct v4l2_buffer *buf = arg;
233 226
234 if (buf->type != video->queue.type)
235 return -EINVAL;
236
237 return uvc_query_buffer(&video->queue, buf); 227 return uvc_query_buffer(&video->queue, buf);
238 } 228 }
239 229
@@ -251,24 +241,36 @@ uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
251 { 241 {
252 int *type = arg; 242 int *type = arg;
253 243
254 if (*type != video->queue.type) 244 if (*type != video->queue.queue.type)
255 return -EINVAL; 245 return -EINVAL;
256 246
257 return uvc_video_enable(video, 1); 247 /* Enable UVC video. */
248 ret = uvc_video_enable(video, 1);
249 if (ret < 0)
250 return ret;
251
252 /*
253 * Complete the alternate setting selection setup phase now that
254 * userspace is ready to provide video frames.
255 */
256 uvc_function_setup_continue(uvc);
257 uvc->state = UVC_STATE_STREAMING;
258
259 return 0;
258 } 260 }
259 261
260 case VIDIOC_STREAMOFF: 262 case VIDIOC_STREAMOFF:
261 { 263 {
262 int *type = arg; 264 int *type = arg;
263 265
264 if (*type != video->queue.type) 266 if (*type != video->queue.queue.type)
265 return -EINVAL; 267 return -EINVAL;
266 268
267 return uvc_video_enable(video, 0); 269 return uvc_video_enable(video, 0);
268 } 270 }
269 271
270 /* Events */ 272 /* Events */
271 case VIDIOC_DQEVENT: 273 case VIDIOC_DQEVENT:
272 { 274 {
273 struct v4l2_event *event = arg; 275 struct v4l2_event *event = arg;
274 276
@@ -333,17 +335,21 @@ uvc_v4l2_poll(struct file *file, poll_table *wait)
333{ 335{
334 struct video_device *vdev = video_devdata(file); 336 struct video_device *vdev = video_devdata(file);
335 struct uvc_device *uvc = video_get_drvdata(vdev); 337 struct uvc_device *uvc = video_get_drvdata(vdev);
336 struct uvc_file_handle *handle = to_uvc_file_handle(file->private_data);
337 unsigned int mask = 0;
338 338
339 poll_wait(file, &handle->vfh.wait, wait); 339 return uvc_queue_poll(&uvc->video.queue, file, wait);
340 if (v4l2_event_pending(&handle->vfh)) 340}
341 mask |= POLLPRI;
342 341
343 mask |= uvc_queue_poll(&uvc->video.queue, file, wait); 342#ifndef CONFIG_MMU
343static unsigned long uvc_v4l2_get_unmapped_area(struct file *file,
344 unsigned long addr, unsigned long len, unsigned long pgoff,
345 unsigned long flags)
346{
347 struct video_device *vdev = video_devdata(file);
348 struct uvc_device *uvc = video_get_drvdata(vdev);
344 349
345 return mask; 350 return uvc_queue_get_unmapped_area(&uvc->video.queue, pgoff);
346} 351}
352#endif
347 353
348static struct v4l2_file_operations uvc_v4l2_fops = { 354static struct v4l2_file_operations uvc_v4l2_fops = {
349 .owner = THIS_MODULE, 355 .owner = THIS_MODULE,
@@ -352,5 +358,8 @@ static struct v4l2_file_operations uvc_v4l2_fops = {
352 .ioctl = uvc_v4l2_ioctl, 358 .ioctl = uvc_v4l2_ioctl,
353 .mmap = uvc_v4l2_mmap, 359 .mmap = uvc_v4l2_mmap,
354 .poll = uvc_v4l2_poll, 360 .poll = uvc_v4l2_poll,
361#ifndef CONFIG_MMU
362 .get_unmapped_area = uvc_v4l2_get_unmapped_area,
363#endif
355}; 364};
356 365
diff --git a/drivers/usb/gadget/uvc_video.c b/drivers/usb/gadget/uvc_video.c
index b0e53a8ea4f7..71e896d4c5ae 100644
--- a/drivers/usb/gadget/uvc_video.c
+++ b/drivers/usb/gadget/uvc_video.c
@@ -32,7 +32,7 @@ uvc_video_encode_header(struct uvc_video *video, struct uvc_buffer *buf,
32 data[0] = 2; 32 data[0] = 2;
33 data[1] = UVC_STREAM_EOH | video->fid; 33 data[1] = UVC_STREAM_EOH | video->fid;
34 34
35 if (buf->buf.bytesused - video->queue.buf_used <= len - 2) 35 if (buf->bytesused - video->queue.buf_used <= len - 2)
36 data[1] |= UVC_STREAM_EOF; 36 data[1] |= UVC_STREAM_EOF;
37 37
38 return 2; 38 return 2;
@@ -47,8 +47,8 @@ uvc_video_encode_data(struct uvc_video *video, struct uvc_buffer *buf,
47 void *mem; 47 void *mem;
48 48
49 /* Copy video data to the USB buffer. */ 49 /* Copy video data to the USB buffer. */
50 mem = queue->mem + buf->buf.m.offset + queue->buf_used; 50 mem = buf->mem + queue->buf_used;
51 nbytes = min((unsigned int)len, buf->buf.bytesused - queue->buf_used); 51 nbytes = min((unsigned int)len, buf->bytesused - queue->buf_used);
52 52
53 memcpy(data, mem, nbytes); 53 memcpy(data, mem, nbytes);
54 queue->buf_used += nbytes; 54 queue->buf_used += nbytes;
@@ -82,7 +82,7 @@ uvc_video_encode_bulk(struct usb_request *req, struct uvc_video *video,
82 req->length = video->req_size - len; 82 req->length = video->req_size - len;
83 req->zero = video->payload_size == video->max_payload_size; 83 req->zero = video->payload_size == video->max_payload_size;
84 84
85 if (buf->buf.bytesused == video->queue.buf_used) { 85 if (buf->bytesused == video->queue.buf_used) {
86 video->queue.buf_used = 0; 86 video->queue.buf_used = 0;
87 buf->state = UVC_BUF_STATE_DONE; 87 buf->state = UVC_BUF_STATE_DONE;
88 uvc_queue_next_buffer(&video->queue, buf); 88 uvc_queue_next_buffer(&video->queue, buf);
@@ -92,7 +92,7 @@ uvc_video_encode_bulk(struct usb_request *req, struct uvc_video *video,
92 } 92 }
93 93
94 if (video->payload_size == video->max_payload_size || 94 if (video->payload_size == video->max_payload_size ||
95 buf->buf.bytesused == video->queue.buf_used) 95 buf->bytesused == video->queue.buf_used)
96 video->payload_size = 0; 96 video->payload_size = 0;
97} 97}
98 98
@@ -115,7 +115,7 @@ uvc_video_encode_isoc(struct usb_request *req, struct uvc_video *video,
115 115
116 req->length = video->req_size - len; 116 req->length = video->req_size - len;
117 117
118 if (buf->buf.bytesused == video->queue.buf_used) { 118 if (buf->bytesused == video->queue.buf_used) {
119 video->queue.buf_used = 0; 119 video->queue.buf_used = 0;
120 buf->state = UVC_BUF_STATE_DONE; 120 buf->state = UVC_BUF_STATE_DONE;
121 uvc_queue_next_buffer(&video->queue, buf); 121 uvc_queue_next_buffer(&video->queue, buf);
@@ -161,6 +161,7 @@ static void
161uvc_video_complete(struct usb_ep *ep, struct usb_request *req) 161uvc_video_complete(struct usb_ep *ep, struct usb_request *req)
162{ 162{
163 struct uvc_video *video = req->context; 163 struct uvc_video *video = req->context;
164 struct uvc_video_queue *queue = &video->queue;
164 struct uvc_buffer *buf; 165 struct uvc_buffer *buf;
165 unsigned long flags; 166 unsigned long flags;
166 int ret; 167 int ret;
@@ -169,13 +170,15 @@ uvc_video_complete(struct usb_ep *ep, struct usb_request *req)
169 case 0: 170 case 0:
170 break; 171 break;
171 172
172 case -ESHUTDOWN: 173 case -ESHUTDOWN: /* disconnect from host. */
173 printk(KERN_INFO "VS request cancelled.\n"); 174 printk(KERN_INFO "VS request cancelled.\n");
175 uvc_queue_cancel(queue, 1);
174 goto requeue; 176 goto requeue;
175 177
176 default: 178 default:
177 printk(KERN_INFO "VS request completed with status %d.\n", 179 printk(KERN_INFO "VS request completed with status %d.\n",
178 req->status); 180 req->status);
181 uvc_queue_cancel(queue, 0);
179 goto requeue; 182 goto requeue;
180 } 183 }
181 184
@@ -229,13 +232,18 @@ uvc_video_free_requests(struct uvc_video *video)
229static int 232static int
230uvc_video_alloc_requests(struct uvc_video *video) 233uvc_video_alloc_requests(struct uvc_video *video)
231{ 234{
235 unsigned int req_size;
232 unsigned int i; 236 unsigned int i;
233 int ret = -ENOMEM; 237 int ret = -ENOMEM;
234 238
235 BUG_ON(video->req_size); 239 BUG_ON(video->req_size);
236 240
241 req_size = video->ep->maxpacket
242 * max_t(unsigned int, video->ep->maxburst, 1)
243 * (video->ep->mult + 1);
244
237 for (i = 0; i < UVC_NUM_REQUESTS; ++i) { 245 for (i = 0; i < UVC_NUM_REQUESTS; ++i) {
238 video->req_buffer[i] = kmalloc(video->ep->maxpacket, GFP_KERNEL); 246 video->req_buffer[i] = kmalloc(req_size, GFP_KERNEL);
239 if (video->req_buffer[i] == NULL) 247 if (video->req_buffer[i] == NULL)
240 goto error; 248 goto error;
241 249
@@ -245,14 +253,14 @@ uvc_video_alloc_requests(struct uvc_video *video)
245 253
246 video->req[i]->buf = video->req_buffer[i]; 254 video->req[i]->buf = video->req_buffer[i];
247 video->req[i]->length = 0; 255 video->req[i]->length = 0;
248 video->req[i]->dma = DMA_ADDR_INVALID;
249 video->req[i]->complete = uvc_video_complete; 256 video->req[i]->complete = uvc_video_complete;
250 video->req[i]->context = video; 257 video->req[i]->context = video;
251 258
252 list_add_tail(&video->req[i]->list, &video->req_free); 259 list_add_tail(&video->req[i]->list, &video->req_free);
253 } 260 }
254 261
255 video->req_size = video->ep->maxpacket; 262 video->req_size = req_size;
263
256 return 0; 264 return 0;
257 265
258error: 266error:
@@ -309,7 +317,8 @@ uvc_video_pump(struct uvc_video *video)
309 video->encode(req, video, buf); 317 video->encode(req, video, buf);
310 318
311 /* Queue the USB request */ 319 /* Queue the USB request */
312 if ((ret = usb_ep_queue(video->ep, req, GFP_KERNEL)) < 0) { 320 ret = usb_ep_queue(video->ep, req, GFP_ATOMIC);
321 if (ret < 0) {
313 printk(KERN_INFO "Failed to queue request (%d)\n", ret); 322 printk(KERN_INFO "Failed to queue request (%d)\n", ret);
314 usb_ep_set_halt(video->ep); 323 usb_ep_set_halt(video->ep);
315 spin_unlock_irqrestore(&video->queue.irqlock, flags); 324 spin_unlock_irqrestore(&video->queue.irqlock, flags);
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index c59a1126926f..f7af0984743b 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -155,8 +155,9 @@ config USB_EHCI_MXC
155 Variation of ARC USB block used in some Freescale chips. 155 Variation of ARC USB block used in some Freescale chips.
156 156
157config USB_EHCI_HCD_OMAP 157config USB_EHCI_HCD_OMAP
158 bool "EHCI support for OMAP3 and later chips" 158 tristate "EHCI support for OMAP3 and later chips"
159 depends on USB_EHCI_HCD && ARCH_OMAP 159 depends on USB_EHCI_HCD && ARCH_OMAP
160 select NOP_USB_XCEIV
160 default y 161 default y
161 ---help--- 162 ---help---
162 Enables support for the on-chip EHCI controller on 163 Enables support for the on-chip EHCI controller on
@@ -179,6 +180,7 @@ config USB_EHCI_TEGRA
179 boolean "NVIDIA Tegra HCD support" 180 boolean "NVIDIA Tegra HCD support"
180 depends on USB_EHCI_HCD && ARCH_TEGRA 181 depends on USB_EHCI_HCD && ARCH_TEGRA
181 select USB_EHCI_ROOT_HUB_TT 182 select USB_EHCI_ROOT_HUB_TT
183 select USB_PHY
182 help 184 help
183 This driver enables support for the internal USB Host Controllers 185 This driver enables support for the internal USB Host Controllers
184 found in NVIDIA Tegra SoCs. The controllers are EHCI compliant. 186 found in NVIDIA Tegra SoCs. The controllers are EHCI compliant.
@@ -300,7 +302,6 @@ config USB_OHCI_HCD
300 tristate "OHCI HCD support" 302 tristate "OHCI HCD support"
301 depends on USB && USB_ARCH_HAS_OHCI 303 depends on USB && USB_ARCH_HAS_OHCI
302 select ISP1301_OMAP if MACH_OMAP_H2 || MACH_OMAP_H3 304 select ISP1301_OMAP if MACH_OMAP_H2 || MACH_OMAP_H3
303 select USB_OTG_UTILS if ARCH_OMAP
304 depends on USB_ISP1301 || !ARCH_LPC32XX 305 depends on USB_ISP1301 || !ARCH_LPC32XX
305 ---help--- 306 ---help---
306 The Open Host Controller Interface (OHCI) is a standard for accessing 307 The Open Host Controller Interface (OHCI) is a standard for accessing
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index 001fbff2fdef..56de4106c8b3 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -27,6 +27,7 @@ obj-$(CONFIG_USB_EHCI_HCD) += ehci-hcd.o
27obj-$(CONFIG_USB_EHCI_PCI) += ehci-pci.o 27obj-$(CONFIG_USB_EHCI_PCI) += ehci-pci.o
28obj-$(CONFIG_USB_EHCI_HCD_PLATFORM) += ehci-platform.o 28obj-$(CONFIG_USB_EHCI_HCD_PLATFORM) += ehci-platform.o
29obj-$(CONFIG_USB_EHCI_MXC) += ehci-mxc.o 29obj-$(CONFIG_USB_EHCI_MXC) += ehci-mxc.o
30obj-$(CONFIG_USB_EHCI_HCD_OMAP) += ehci-omap.o
30 31
31obj-$(CONFIG_USB_OXU210HP_HCD) += oxu210hp-hcd.o 32obj-$(CONFIG_USB_OXU210HP_HCD) += oxu210hp-hcd.o
32obj-$(CONFIG_USB_ISP116X_HCD) += isp116x-hcd.o 33obj-$(CONFIG_USB_ISP116X_HCD) += isp116x-hcd.o
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c
index 70b496dc18a0..5429d2645bbc 100644
--- a/drivers/usb/host/ehci-dbg.c
+++ b/drivers/usb/host/ehci-dbg.c
@@ -510,14 +510,16 @@ static ssize_t fill_async_buffer(struct debug_buffer *buf)
510 spin_lock_irqsave (&ehci->lock, flags); 510 spin_lock_irqsave (&ehci->lock, flags);
511 for (qh = ehci->async->qh_next.qh; size > 0 && qh; qh = qh->qh_next.qh) 511 for (qh = ehci->async->qh_next.qh; size > 0 && qh; qh = qh->qh_next.qh)
512 qh_lines (ehci, qh, &next, &size); 512 qh_lines (ehci, qh, &next, &size);
513 if (ehci->async_unlink && size > 0) { 513 if (!list_empty(&ehci->async_unlink) && size > 0) {
514 temp = scnprintf(next, size, "\nunlink =\n"); 514 temp = scnprintf(next, size, "\nunlink =\n");
515 size -= temp; 515 size -= temp;
516 next += temp; 516 next += temp;
517 517
518 for (qh = ehci->async_unlink; size > 0 && qh; 518 list_for_each_entry(qh, &ehci->async_unlink, unlink_node) {
519 qh = qh->unlink_next) 519 if (size <= 0)
520 qh_lines (ehci, qh, &next, &size); 520 break;
521 qh_lines(ehci, qh, &next, &size);
522 }
521 } 523 }
522 spin_unlock_irqrestore (&ehci->lock, flags); 524 spin_unlock_irqrestore (&ehci->lock, flags);
523 525
@@ -814,9 +816,10 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf)
814 } 816 }
815 } 817 }
816 818
817 if (ehci->async_unlink) { 819 if (!list_empty(&ehci->async_unlink)) {
818 temp = scnprintf(next, size, "async unlink qh %p\n", 820 temp = scnprintf(next, size, "async unlink qh %p\n",
819 ehci->async_unlink); 821 list_first_entry(&ehci->async_unlink,
822 struct ehci_qh, unlink_node));
820 size -= temp; 823 size -= temp;
821 next += temp; 824 next += temp;
822 } 825 }
diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
index d81d2fcbff18..3be3df233a0e 100644
--- a/drivers/usb/host/ehci-fsl.c
+++ b/drivers/usb/host/ehci-fsl.c
@@ -370,6 +370,15 @@ static int ehci_fsl_setup(struct usb_hcd *hcd)
370 /* EHCI registers start at offset 0x100 */ 370 /* EHCI registers start at offset 0x100 */
371 ehci->caps = hcd->regs + 0x100; 371 ehci->caps = hcd->regs + 0x100;
372 372
373#ifdef CONFIG_PPC_83xx
374 /*
375 * Deal with MPC834X that need port power to be cycled after the power
376 * fault condition is removed. Otherwise the state machine does not
377 * reflect PORTSC[CSC] correctly.
378 */
379 ehci->need_oc_pp_cycle = 1;
380#endif
381
373 hcd->has_tt = 1; 382 hcd->has_tt = 1;
374 383
375 retval = ehci_setup(hcd); 384 retval = ehci_setup(hcd);
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 416a6dce5e11..b12b97d2ccaf 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -482,6 +482,9 @@ static int ehci_init(struct usb_hcd *hcd)
482 * periodic_size can shrink by USBCMD update if hcc_params allows. 482 * periodic_size can shrink by USBCMD update if hcc_params allows.
483 */ 483 */
484 ehci->periodic_size = DEFAULT_I_TDPS; 484 ehci->periodic_size = DEFAULT_I_TDPS;
485 INIT_LIST_HEAD(&ehci->async_unlink);
486 INIT_LIST_HEAD(&ehci->async_idle);
487 INIT_LIST_HEAD(&ehci->intr_unlink);
485 INIT_LIST_HEAD(&ehci->intr_qh_list); 488 INIT_LIST_HEAD(&ehci->intr_qh_list);
486 INIT_LIST_HEAD(&ehci->cached_itd_list); 489 INIT_LIST_HEAD(&ehci->cached_itd_list);
487 INIT_LIST_HEAD(&ehci->cached_sitd_list); 490 INIT_LIST_HEAD(&ehci->cached_sitd_list);
@@ -749,7 +752,7 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
749 /* guard against (alleged) silicon errata */ 752 /* guard against (alleged) silicon errata */
750 if (cmd & CMD_IAAD) 753 if (cmd & CMD_IAAD)
751 ehci_dbg(ehci, "IAA with IAAD still set?\n"); 754 ehci_dbg(ehci, "IAA with IAAD still set?\n");
752 if (ehci->async_iaa) 755 if (ehci->iaa_in_progress)
753 COUNT(ehci->stats.iaa); 756 COUNT(ehci->stats.iaa);
754 end_unlink_async(ehci); 757 end_unlink_async(ehci);
755 } 758 }
@@ -757,7 +760,7 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
757 /* remote wakeup [4.3.1] */ 760 /* remote wakeup [4.3.1] */
758 if (status & STS_PCD) { 761 if (status & STS_PCD) {
759 unsigned i = HCS_N_PORTS (ehci->hcs_params); 762 unsigned i = HCS_N_PORTS (ehci->hcs_params);
760 u32 ppcd = 0; 763 u32 ppcd = ~0;
761 764
762 /* kick root hub later */ 765 /* kick root hub later */
763 pcd_status = status; 766 pcd_status = status;
@@ -774,7 +777,7 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
774 int pstatus; 777 int pstatus;
775 778
776 /* leverage per-port change bits feature */ 779 /* leverage per-port change bits feature */
777 if (ehci->has_ppcd && !(ppcd & (1 << i))) 780 if (!(ppcd & (1 << i)))
778 continue; 781 continue;
779 pstatus = ehci_readl(ehci, 782 pstatus = ehci_readl(ehci,
780 &ehci->regs->port_status[i]); 783 &ehci->regs->port_status[i]);
@@ -896,17 +899,24 @@ static int ehci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
896 if (rc) 899 if (rc)
897 goto done; 900 goto done;
898 901
899 switch (usb_pipetype (urb->pipe)) { 902 if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
900 // case PIPE_CONTROL: 903 /*
901 // case PIPE_BULK: 904 * We don't expedite dequeue for isochronous URBs.
902 default: 905 * Just wait until they complete normally or their
906 * time slot expires.
907 */
908 } else {
903 qh = (struct ehci_qh *) urb->hcpriv; 909 qh = (struct ehci_qh *) urb->hcpriv;
904 if (!qh) 910 qh->exception = 1;
905 break;
906 switch (qh->qh_state) { 911 switch (qh->qh_state) {
907 case QH_STATE_LINKED: 912 case QH_STATE_LINKED:
913 if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)
914 start_unlink_intr(ehci, qh);
915 else
916 start_unlink_async(ehci, qh);
917 break;
908 case QH_STATE_COMPLETING: 918 case QH_STATE_COMPLETING:
909 start_unlink_async(ehci, qh); 919 qh->dequeue_during_giveback = 1;
910 break; 920 break;
911 case QH_STATE_UNLINK: 921 case QH_STATE_UNLINK:
912 case QH_STATE_UNLINK_WAIT: 922 case QH_STATE_UNLINK_WAIT:
@@ -917,33 +927,6 @@ static int ehci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
917 qh_completions(ehci, qh); 927 qh_completions(ehci, qh);
918 break; 928 break;
919 } 929 }
920 break;
921
922 case PIPE_INTERRUPT:
923 qh = (struct ehci_qh *) urb->hcpriv;
924 if (!qh)
925 break;
926 switch (qh->qh_state) {
927 case QH_STATE_LINKED:
928 case QH_STATE_COMPLETING:
929 start_unlink_intr(ehci, qh);
930 break;
931 case QH_STATE_IDLE:
932 qh_completions (ehci, qh);
933 break;
934 default:
935 ehci_dbg (ehci, "bogus qh %p state %d\n",
936 qh, qh->qh_state);
937 goto done;
938 }
939 break;
940
941 case PIPE_ISOCHRONOUS:
942 // itd or sitd ...
943
944 // wait till next completion, do it then.
945 // completion irqs can wait up to 1024 msec,
946 break;
947 } 930 }
948done: 931done:
949 spin_unlock_irqrestore (&ehci->lock, flags); 932 spin_unlock_irqrestore (&ehci->lock, flags);
@@ -984,6 +967,7 @@ rescan:
984 goto done; 967 goto done;
985 } 968 }
986 969
970 qh->exception = 1;
987 if (ehci->rh_state < EHCI_RH_RUNNING) 971 if (ehci->rh_state < EHCI_RH_RUNNING)
988 qh->qh_state = QH_STATE_IDLE; 972 qh->qh_state = QH_STATE_IDLE;
989 switch (qh->qh_state) { 973 switch (qh->qh_state) {
@@ -1052,13 +1036,12 @@ ehci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
1052 usb_settoggle(qh->dev, epnum, is_out, 0); 1036 usb_settoggle(qh->dev, epnum, is_out, 0);
1053 if (!list_empty(&qh->qtd_list)) { 1037 if (!list_empty(&qh->qtd_list)) {
1054 WARN_ONCE(1, "clear_halt for a busy endpoint\n"); 1038 WARN_ONCE(1, "clear_halt for a busy endpoint\n");
1055 } else if (qh->qh_state == QH_STATE_LINKED || 1039 } else {
1056 qh->qh_state == QH_STATE_COMPLETING) {
1057
1058 /* The toggle value in the QH can't be updated 1040 /* The toggle value in the QH can't be updated
1059 * while the QH is active. Unlink it now; 1041 * while the QH is active. Unlink it now;
1060 * re-linking will call qh_refresh(). 1042 * re-linking will call qh_refresh().
1061 */ 1043 */
1044 qh->exception = 1;
1062 if (eptype == USB_ENDPOINT_XFER_BULK) 1045 if (eptype == USB_ENDPOINT_XFER_BULK)
1063 start_unlink_async(ehci, qh); 1046 start_unlink_async(ehci, qh);
1064 else 1047 else
@@ -1251,11 +1234,6 @@ MODULE_LICENSE ("GPL");
1251#define PLATFORM_DRIVER ehci_hcd_sh_driver 1234#define PLATFORM_DRIVER ehci_hcd_sh_driver
1252#endif 1235#endif
1253 1236
1254#ifdef CONFIG_USB_EHCI_HCD_OMAP
1255#include "ehci-omap.c"
1256#define PLATFORM_DRIVER ehci_hcd_omap_driver
1257#endif
1258
1259#ifdef CONFIG_PPC_PS3 1237#ifdef CONFIG_PPC_PS3
1260#include "ehci-ps3.c" 1238#include "ehci-ps3.c"
1261#define PS3_SYSTEM_BUS_DRIVER ps3_ehci_driver 1239#define PS3_SYSTEM_BUS_DRIVER ps3_ehci_driver
@@ -1291,11 +1269,6 @@ MODULE_LICENSE ("GPL");
1291#define PLATFORM_DRIVER ehci_octeon_driver 1269#define PLATFORM_DRIVER ehci_octeon_driver
1292#endif 1270#endif
1293 1271
1294#ifdef CONFIG_ARCH_VT8500
1295#include "ehci-vt8500.c"
1296#define PLATFORM_DRIVER vt8500_ehci_driver
1297#endif
1298
1299#ifdef CONFIG_PLAT_SPEAR 1272#ifdef CONFIG_PLAT_SPEAR
1300#include "ehci-spear.c" 1273#include "ehci-spear.c"
1301#define PLATFORM_DRIVER spear_ehci_hcd_driver 1274#define PLATFORM_DRIVER spear_ehci_hcd_driver
@@ -1345,6 +1318,7 @@ MODULE_LICENSE ("GPL");
1345 !IS_ENABLED(CONFIG_USB_EHCI_HCD_PLATFORM) && \ 1318 !IS_ENABLED(CONFIG_USB_EHCI_HCD_PLATFORM) && \
1346 !IS_ENABLED(CONFIG_USB_CHIPIDEA_HOST) && \ 1319 !IS_ENABLED(CONFIG_USB_CHIPIDEA_HOST) && \
1347 !IS_ENABLED(CONFIG_USB_EHCI_MXC) && \ 1320 !IS_ENABLED(CONFIG_USB_EHCI_MXC) && \
1321 !IS_ENABLED(CONFIG_USB_EHCI_HCD_OMAP) && \
1348 !defined(PLATFORM_DRIVER) && \ 1322 !defined(PLATFORM_DRIVER) && \
1349 !defined(PS3_SYSTEM_BUS_DRIVER) && \ 1323 !defined(PS3_SYSTEM_BUS_DRIVER) && \
1350 !defined(OF_PLATFORM_DRIVER) && \ 1324 !defined(OF_PLATFORM_DRIVER) && \
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index 7d06e77f6c4f..9ab4a4d9768a 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -464,7 +464,7 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
464 while (i--) { 464 while (i--) {
465 temp = ehci_readl(ehci, &ehci->regs->port_status [i]); 465 temp = ehci_readl(ehci, &ehci->regs->port_status [i]);
466 if (test_bit(i, &resume_needed)) { 466 if (test_bit(i, &resume_needed)) {
467 temp &= ~(PORT_RWC_BITS | PORT_RESUME); 467 temp &= ~(PORT_RWC_BITS | PORT_SUSPEND | PORT_RESUME);
468 ehci_writel(ehci, temp, &ehci->regs->port_status [i]); 468 ehci_writel(ehci, temp, &ehci->regs->port_status [i]);
469 ehci_vdbg (ehci, "resumed port %d\n", i + 1); 469 ehci_vdbg (ehci, "resumed port %d\n", i + 1);
470 } 470 }
@@ -590,7 +590,7 @@ ehci_hub_status_data (struct usb_hcd *hcd, char *buf)
590 u32 mask; 590 u32 mask;
591 int ports, i, retval = 1; 591 int ports, i, retval = 1;
592 unsigned long flags; 592 unsigned long flags;
593 u32 ppcd = 0; 593 u32 ppcd = ~0;
594 594
595 /* init status to no-changes */ 595 /* init status to no-changes */
596 buf [0] = 0; 596 buf [0] = 0;
@@ -628,9 +628,10 @@ ehci_hub_status_data (struct usb_hcd *hcd, char *buf)
628 628
629 for (i = 0; i < ports; i++) { 629 for (i = 0; i < ports; i++) {
630 /* leverage per-port change bits feature */ 630 /* leverage per-port change bits feature */
631 if (ehci->has_ppcd && !(ppcd & (1 << i))) 631 if (ppcd & (1 << i))
632 continue; 632 temp = ehci_readl(ehci, &ehci->regs->port_status[i]);
633 temp = ehci_readl(ehci, &ehci->regs->port_status [i]); 633 else
634 temp = 0;
634 635
635 /* 636 /*
636 * Return status information even for ports with OWNER set. 637 * Return status information even for ports with OWNER set.
@@ -839,7 +840,8 @@ static int ehci_hub_control (
839 * power switching; they're allowed to just limit the 840 * power switching; they're allowed to just limit the
840 * current. khubd will turn the power back on. 841 * current. khubd will turn the power back on.
841 */ 842 */
842 if ((temp & PORT_OC) && HCS_PPC(ehci->hcs_params)) { 843 if (((temp & PORT_OC) || (ehci->need_oc_pp_cycle))
844 && HCS_PPC(ehci->hcs_params)) {
843 ehci_writel(ehci, 845 ehci_writel(ehci,
844 temp & ~(PORT_RWC_BITS | PORT_POWER), 846 temp & ~(PORT_RWC_BITS | PORT_POWER),
845 status_reg); 847 status_reg);
@@ -870,10 +872,9 @@ static int ehci_hub_control (
870 usb_hcd_end_port_resume(&hcd->self, wIndex); 872 usb_hcd_end_port_resume(&hcd->self, wIndex);
871 873
872 /* stop resume signaling */ 874 /* stop resume signaling */
873 temp = ehci_readl(ehci, status_reg); 875 temp &= ~(PORT_RWC_BITS |
874 ehci_writel(ehci, 876 PORT_SUSPEND | PORT_RESUME);
875 temp & ~(PORT_RWC_BITS | PORT_RESUME), 877 ehci_writel(ehci, temp, status_reg);
876 status_reg);
877 clear_bit(wIndex, &ehci->resuming_ports); 878 clear_bit(wIndex, &ehci->resuming_ports);
878 retval = handshake(ehci, status_reg, 879 retval = handshake(ehci, status_reg,
879 PORT_RESUME, 0, 2000 /* 2msec */); 880 PORT_RESUME, 0, 2000 /* 2msec */);
@@ -883,7 +884,7 @@ static int ehci_hub_control (
883 wIndex + 1, retval); 884 wIndex + 1, retval);
884 goto error; 885 goto error;
885 } 886 }
886 temp &= ~(PORT_SUSPEND|PORT_RESUME|(3<<10)); 887 temp = ehci_readl(ehci, status_reg);
887 } 888 }
888 } 889 }
889 890
diff --git a/drivers/usb/host/ehci-msm.c b/drivers/usb/host/ehci-msm.c
index 88a49c87e748..ebf410311957 100644
--- a/drivers/usb/host/ehci-msm.c
+++ b/drivers/usb/host/ehci-msm.c
@@ -145,7 +145,7 @@ static int ehci_msm_probe(struct platform_device *pdev)
145 * management. 145 * management.
146 */ 146 */
147 phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); 147 phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
148 if (IS_ERR_OR_NULL(phy)) { 148 if (IS_ERR(phy)) {
149 dev_err(&pdev->dev, "unable to find transceiver\n"); 149 dev_err(&pdev->dev, "unable to find transceiver\n");
150 ret = -ENODEV; 150 ret = -ENODEV;
151 goto put_hcd; 151 goto put_hcd;
diff --git a/drivers/usb/host/ehci-mv.c b/drivers/usb/host/ehci-mv.c
index 3065809546b1..402062973f03 100644
--- a/drivers/usb/host/ehci-mv.c
+++ b/drivers/usb/host/ehci-mv.c
@@ -33,25 +33,17 @@ struct ehci_hcd_mv {
33 33
34 struct mv_usb_platform_data *pdata; 34 struct mv_usb_platform_data *pdata;
35 35
36 /* clock source and total clock number */ 36 struct clk *clk;
37 unsigned int clknum;
38 struct clk *clk[0];
39}; 37};
40 38
41static void ehci_clock_enable(struct ehci_hcd_mv *ehci_mv) 39static void ehci_clock_enable(struct ehci_hcd_mv *ehci_mv)
42{ 40{
43 unsigned int i; 41 clk_prepare_enable(ehci_mv->clk);
44
45 for (i = 0; i < ehci_mv->clknum; i++)
46 clk_prepare_enable(ehci_mv->clk[i]);
47} 42}
48 43
49static void ehci_clock_disable(struct ehci_hcd_mv *ehci_mv) 44static void ehci_clock_disable(struct ehci_hcd_mv *ehci_mv)
50{ 45{
51 unsigned int i; 46 clk_disable_unprepare(ehci_mv->clk);
52
53 for (i = 0; i < ehci_mv->clknum; i++)
54 clk_disable_unprepare(ehci_mv->clk[i]);
55} 47}
56 48
57static int mv_ehci_enable(struct ehci_hcd_mv *ehci_mv) 49static int mv_ehci_enable(struct ehci_hcd_mv *ehci_mv)
@@ -144,9 +136,8 @@ static int mv_ehci_probe(struct platform_device *pdev)
144 struct ehci_hcd *ehci; 136 struct ehci_hcd *ehci;
145 struct ehci_hcd_mv *ehci_mv; 137 struct ehci_hcd_mv *ehci_mv;
146 struct resource *r; 138 struct resource *r;
147 int clk_i, retval = -ENODEV; 139 int retval = -ENODEV;
148 u32 offset; 140 u32 offset;
149 size_t size;
150 141
151 if (!pdata) { 142 if (!pdata) {
152 dev_err(&pdev->dev, "missing platform_data\n"); 143 dev_err(&pdev->dev, "missing platform_data\n");
@@ -160,8 +151,7 @@ static int mv_ehci_probe(struct platform_device *pdev)
160 if (!hcd) 151 if (!hcd)
161 return -ENOMEM; 152 return -ENOMEM;
162 153
163 size = sizeof(*ehci_mv) + sizeof(struct clk *) * pdata->clknum; 154 ehci_mv = devm_kzalloc(&pdev->dev, sizeof(*ehci_mv), GFP_KERNEL);
164 ehci_mv = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
165 if (ehci_mv == NULL) { 155 if (ehci_mv == NULL) {
166 dev_err(&pdev->dev, "cannot allocate ehci_hcd_mv\n"); 156 dev_err(&pdev->dev, "cannot allocate ehci_hcd_mv\n");
167 retval = -ENOMEM; 157 retval = -ENOMEM;
@@ -172,16 +162,11 @@ static int mv_ehci_probe(struct platform_device *pdev)
172 ehci_mv->pdata = pdata; 162 ehci_mv->pdata = pdata;
173 ehci_mv->hcd = hcd; 163 ehci_mv->hcd = hcd;
174 164
175 ehci_mv->clknum = pdata->clknum; 165 ehci_mv->clk = devm_clk_get(&pdev->dev, NULL);
176 for (clk_i = 0; clk_i < ehci_mv->clknum; clk_i++) { 166 if (IS_ERR(ehci_mv->clk)) {
177 ehci_mv->clk[clk_i] = 167 dev_err(&pdev->dev, "error getting clock\n");
178 devm_clk_get(&pdev->dev, pdata->clkname[clk_i]); 168 retval = PTR_ERR(ehci_mv->clk);
179 if (IS_ERR(ehci_mv->clk[clk_i])) { 169 goto err_clear_drvdata;
180 dev_err(&pdev->dev, "error get clck \"%s\"\n",
181 pdata->clkname[clk_i]);
182 retval = PTR_ERR(ehci_mv->clk[clk_i]);
183 goto err_clear_drvdata;
184 }
185 } 170 }
186 171
187 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "phyregs"); 172 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "phyregs");
@@ -225,7 +210,7 @@ static int mv_ehci_probe(struct platform_device *pdev)
225 (void __iomem *) ((unsigned long) ehci_mv->cap_regs + offset); 210 (void __iomem *) ((unsigned long) ehci_mv->cap_regs + offset);
226 211
227 hcd->rsrc_start = r->start; 212 hcd->rsrc_start = r->start;
228 hcd->rsrc_len = r->end - r->start + 1; 213 hcd->rsrc_len = resource_size(r);
229 hcd->regs = ehci_mv->op_regs; 214 hcd->regs = ehci_mv->op_regs;
230 215
231 hcd->irq = platform_get_irq(pdev, 0); 216 hcd->irq = platform_get_irq(pdev, 0);
@@ -240,12 +225,16 @@ static int mv_ehci_probe(struct platform_device *pdev)
240 225
241 ehci_mv->mode = pdata->mode; 226 ehci_mv->mode = pdata->mode;
242 if (ehci_mv->mode == MV_USB_MODE_OTG) { 227 if (ehci_mv->mode == MV_USB_MODE_OTG) {
243#ifdef CONFIG_USB_OTG_UTILS
244 ehci_mv->otg = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); 228 ehci_mv->otg = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
245 if (IS_ERR_OR_NULL(ehci_mv->otg)) { 229 if (IS_ERR(ehci_mv->otg)) {
246 dev_err(&pdev->dev, 230 retval = PTR_ERR(ehci_mv->otg);
247 "unable to find transceiver\n"); 231
248 retval = -ENODEV; 232 if (retval == -ENXIO)
233 dev_info(&pdev->dev, "MV_USB_MODE_OTG "
234 "must have CONFIG_USB_PHY enabled\n");
235 else
236 dev_err(&pdev->dev,
237 "unable to find transceiver\n");
249 goto err_disable_clk; 238 goto err_disable_clk;
250 } 239 }
251 240
@@ -258,11 +247,6 @@ static int mv_ehci_probe(struct platform_device *pdev)
258 } 247 }
259 /* otg will enable clock before use as host */ 248 /* otg will enable clock before use as host */
260 mv_ehci_disable(ehci_mv); 249 mv_ehci_disable(ehci_mv);
261#else
262 dev_info(&pdev->dev, "MV_USB_MODE_OTG "
263 "must have CONFIG_USB_OTG_UTILS enabled\n");
264 goto err_disable_clk;
265#endif
266 } else { 250 } else {
267 if (pdata->set_vbus) 251 if (pdata->set_vbus)
268 pdata->set_vbus(1); 252 pdata->set_vbus(1);
diff --git a/drivers/usb/host/ehci-mxc.c b/drivers/usb/host/ehci-mxc.c
index e9301fb97eaa..a38c8c8e5b0d 100644
--- a/drivers/usb/host/ehci-mxc.c
+++ b/drivers/usb/host/ehci-mxc.c
@@ -28,11 +28,7 @@
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/usb.h> 29#include <linux/usb.h>
30#include <linux/usb/hcd.h> 30#include <linux/usb/hcd.h>
31
32#include <linux/platform_data/usb-ehci-mxc.h> 31#include <linux/platform_data/usb-ehci-mxc.h>
33
34#include <asm/mach-types.h>
35
36#include "ehci.h" 32#include "ehci.h"
37 33
38#define DRIVER_DESC "Freescale On-Chip EHCI Host driver" 34#define DRIVER_DESC "Freescale On-Chip EHCI Host driver"
@@ -61,8 +57,6 @@ static int ehci_mxc_drv_probe(struct platform_device *pdev)
61 struct device *dev = &pdev->dev; 57 struct device *dev = &pdev->dev;
62 struct ehci_hcd *ehci; 58 struct ehci_hcd *ehci;
63 59
64 dev_info(&pdev->dev, "initializing i.MX USB Controller\n");
65
66 if (!pdata) { 60 if (!pdata) {
67 dev_err(dev, "No platform data given, bailing out.\n"); 61 dev_err(dev, "No platform data given, bailing out.\n");
68 return -EINVAL; 62 return -EINVAL;
@@ -178,7 +172,7 @@ err_alloc:
178 return ret; 172 return ret;
179} 173}
180 174
181static int __exit ehci_mxc_drv_remove(struct platform_device *pdev) 175static int ehci_mxc_drv_remove(struct platform_device *pdev)
182{ 176{
183 struct mxc_usbh_platform_data *pdata = pdev->dev.platform_data; 177 struct mxc_usbh_platform_data *pdata = pdev->dev.platform_data;
184 struct usb_hcd *hcd = platform_get_drvdata(pdev); 178 struct usb_hcd *hcd = platform_get_drvdata(pdev);
diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c
index 0555ee42d7cb..5de3e43ded50 100644
--- a/drivers/usb/host/ehci-omap.c
+++ b/drivers/usb/host/ehci-omap.c
@@ -4,10 +4,11 @@
4 * Bus Glue for the EHCI controllers in OMAP3/4 4 * Bus Glue for the EHCI controllers in OMAP3/4
5 * Tested on several OMAP3 boards, and OMAP4 Pandaboard 5 * Tested on several OMAP3 boards, and OMAP4 Pandaboard
6 * 6 *
7 * Copyright (C) 2007-2011 Texas Instruments, Inc. 7 * Copyright (C) 2007-2013 Texas Instruments, Inc.
8 * Author: Vikram Pandita <vikram.pandita@ti.com> 8 * Author: Vikram Pandita <vikram.pandita@ti.com>
9 * Author: Anand Gadiyar <gadiyar@ti.com> 9 * Author: Anand Gadiyar <gadiyar@ti.com>
10 * Author: Keshava Munegowda <keshava_mgowda@ti.com> 10 * Author: Keshava Munegowda <keshava_mgowda@ti.com>
11 * Author: Roger Quadros <rogerq@ti.com>
11 * 12 *
12 * Copyright (C) 2009 Nokia Corporation 13 * Copyright (C) 2009 Nokia Corporation
13 * Contact: Felipe Balbi <felipe.balbi@nokia.com> 14 * Contact: Felipe Balbi <felipe.balbi@nokia.com>
@@ -28,21 +29,23 @@
28 * along with this program; if not, write to the Free Software 29 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 * 31 *
31 * TODO (last updated Feb 27, 2010):
32 * - add kernel-doc
33 * - enable AUTOIDLE
34 * - add suspend/resume
35 * - add HSIC and TLL support
36 * - convert to use hwmod and runtime PM
37 */ 32 */
38 33
34#include <linux/kernel.h>
35#include <linux/module.h>
36#include <linux/io.h>
39#include <linux/platform_device.h> 37#include <linux/platform_device.h>
40#include <linux/slab.h> 38#include <linux/slab.h>
41#include <linux/usb/ulpi.h> 39#include <linux/usb/ulpi.h>
42#include <linux/regulator/consumer.h>
43#include <linux/pm_runtime.h> 40#include <linux/pm_runtime.h>
44#include <linux/gpio.h> 41#include <linux/gpio.h>
45#include <linux/clk.h> 42#include <linux/clk.h>
43#include <linux/usb.h>
44#include <linux/usb/hcd.h>
45#include <linux/of.h>
46#include <linux/dma-mapping.h>
47
48#include "ehci.h"
46 49
47#include <linux/platform_data/usb-omap.h> 50#include <linux/platform_data/usb-omap.h>
48 51
@@ -57,10 +60,16 @@
57#define EHCI_INSNREG05_ULPI_EXTREGADD_SHIFT 8 60#define EHCI_INSNREG05_ULPI_EXTREGADD_SHIFT 8
58#define EHCI_INSNREG05_ULPI_WRDATA_SHIFT 0 61#define EHCI_INSNREG05_ULPI_WRDATA_SHIFT 0
59 62
60/*-------------------------------------------------------------------------*/ 63#define DRIVER_DESC "OMAP-EHCI Host Controller driver"
64
65static const char hcd_name[] = "ehci-omap";
61 66
62static const struct hc_driver ehci_omap_hc_driver; 67/*-------------------------------------------------------------------------*/
63 68
69struct omap_hcd {
70 struct usb_phy *phy[OMAP3_HS_USB_PORTS]; /* one PHY for each port */
71 int nports;
72};
64 73
65static inline void ehci_write(void __iomem *base, u32 reg, u32 val) 74static inline void ehci_write(void __iomem *base, u32 reg, u32 val)
66{ 75{
@@ -72,99 +81,16 @@ static inline u32 ehci_read(void __iomem *base, u32 reg)
72 return __raw_readl(base + reg); 81 return __raw_readl(base + reg);
73} 82}
74 83
84/* configure so an HC device and id are always provided */
85/* always called with process context; sleeping is OK */
75 86
76static void omap_ehci_soft_phy_reset(struct usb_hcd *hcd, u8 port) 87static struct hc_driver __read_mostly ehci_omap_hc_driver;
77{
78 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
79 unsigned reg = 0;
80
81 reg = ULPI_FUNC_CTRL_RESET
82 /* FUNCTION_CTRL_SET register */
83 | (ULPI_SET(ULPI_FUNC_CTRL) << EHCI_INSNREG05_ULPI_REGADD_SHIFT)
84 /* Write */
85 | (2 << EHCI_INSNREG05_ULPI_OPSEL_SHIFT)
86 /* PORTn */
87 | ((port + 1) << EHCI_INSNREG05_ULPI_PORTSEL_SHIFT)
88 /* start ULPI access*/
89 | (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT);
90
91 ehci_write(hcd->regs, EHCI_INSNREG05_ULPI, reg);
92
93 /* Wait for ULPI access completion */
94 while ((ehci_read(hcd->regs, EHCI_INSNREG05_ULPI)
95 & (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT))) {
96 cpu_relax();
97
98 if (time_after(jiffies, timeout)) {
99 dev_dbg(hcd->self.controller,
100 "phy reset operation timed out\n");
101 break;
102 }
103 }
104}
105
106static int omap_ehci_init(struct usb_hcd *hcd)
107{
108 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
109 int rc;
110 struct usbhs_omap_platform_data *pdata;
111
112 pdata = hcd->self.controller->platform_data;
113
114 /* Hold PHYs in reset while initializing EHCI controller */
115 if (pdata->phy_reset) {
116 if (gpio_is_valid(pdata->reset_gpio_port[0]))
117 gpio_set_value_cansleep(pdata->reset_gpio_port[0], 0);
118
119 if (gpio_is_valid(pdata->reset_gpio_port[1]))
120 gpio_set_value_cansleep(pdata->reset_gpio_port[1], 0);
121
122 /* Hold the PHY in RESET for enough time till DIR is high */
123 udelay(10);
124 }
125
126 /* Soft reset the PHY using PHY reset command over ULPI */
127 if (pdata->port_mode[0] == OMAP_EHCI_PORT_MODE_PHY)
128 omap_ehci_soft_phy_reset(hcd, 0);
129 if (pdata->port_mode[1] == OMAP_EHCI_PORT_MODE_PHY)
130 omap_ehci_soft_phy_reset(hcd, 1);
131
132 /* we know this is the memory we want, no need to ioremap again */
133 ehci->caps = hcd->regs;
134
135 rc = ehci_setup(hcd);
136
137 if (pdata->phy_reset) {
138 /* Hold the PHY in RESET for enough time till
139 * PHY is settled and ready
140 */
141 udelay(10);
142
143 if (gpio_is_valid(pdata->reset_gpio_port[0]))
144 gpio_set_value_cansleep(pdata->reset_gpio_port[0], 1);
145
146 if (gpio_is_valid(pdata->reset_gpio_port[1]))
147 gpio_set_value_cansleep(pdata->reset_gpio_port[1], 1);
148 }
149
150 return rc;
151}
152 88
153static void disable_put_regulator( 89static const struct ehci_driver_overrides ehci_omap_overrides __initdata = {
154 struct usbhs_omap_platform_data *pdata) 90 .extra_priv_size = sizeof(struct omap_hcd),
155{ 91};
156 int i;
157
158 for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) {
159 if (pdata->regulator[i]) {
160 regulator_disable(pdata->regulator[i]);
161 regulator_put(pdata->regulator[i]);
162 }
163 }
164}
165 92
166/* configure so an HC device and id are always provided */ 93static u64 omap_ehci_dma_mask = DMA_BIT_MASK(32);
167/* always called with process context; sleeping is OK */
168 94
169/** 95/**
170 * ehci_hcd_omap_probe - initialize TI-based HCDs 96 * ehci_hcd_omap_probe - initialize TI-based HCDs
@@ -175,15 +101,15 @@ static void disable_put_regulator(
175 */ 101 */
176static int ehci_hcd_omap_probe(struct platform_device *pdev) 102static int ehci_hcd_omap_probe(struct platform_device *pdev)
177{ 103{
178 struct device *dev = &pdev->dev; 104 struct device *dev = &pdev->dev;
179 struct usbhs_omap_platform_data *pdata = dev->platform_data; 105 struct usbhs_omap_platform_data *pdata = dev->platform_data;
180 struct resource *res; 106 struct resource *res;
181 struct usb_hcd *hcd; 107 struct usb_hcd *hcd;
182 void __iomem *regs; 108 void __iomem *regs;
183 int ret = -ENODEV; 109 int ret = -ENODEV;
184 int irq; 110 int irq;
185 int i; 111 int i;
186 char supply[7]; 112 struct omap_hcd *omap;
187 113
188 if (usb_disabled()) 114 if (usb_disabled())
189 return -ENODEV; 115 return -ENODEV;
@@ -193,52 +119,74 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
193 return -ENODEV; 119 return -ENODEV;
194 } 120 }
195 121
196 irq = platform_get_irq_byname(pdev, "ehci-irq"); 122 /* For DT boot, get platform data from parent. i.e. usbhshost */
197 if (irq < 0) { 123 if (dev->of_node) {
198 dev_err(dev, "EHCI irq failed\n"); 124 pdata = dev->parent->platform_data;
199 return -ENODEV; 125 dev->platform_data = pdata;
200 } 126 }
201 127
202 res = platform_get_resource_byname(pdev, 128 if (!pdata) {
203 IORESOURCE_MEM, "ehci"); 129 dev_err(dev, "Missing platform data\n");
204 if (!res) {
205 dev_err(dev, "UHH EHCI get resource failed\n");
206 return -ENODEV; 130 return -ENODEV;
207 } 131 }
208 132
209 regs = ioremap(res->start, resource_size(res)); 133 irq = platform_get_irq(pdev, 0);
210 if (!regs) { 134 if (irq < 0) {
211 dev_err(dev, "UHH EHCI ioremap failed\n"); 135 dev_err(dev, "EHCI irq failed\n");
212 return -ENOMEM; 136 return -ENODEV;
213 } 137 }
214 138
139 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
140 regs = devm_ioremap_resource(dev, res);
141 if (IS_ERR(regs))
142 return PTR_ERR(regs);
143
144 /*
145 * Right now device-tree probed devices don't get dma_mask set.
146 * Since shared usb code relies on it, set it here for now.
147 * Once we have dma capability bindings this can go away.
148 */
149 if (!pdev->dev.dma_mask)
150 pdev->dev.dma_mask = &omap_ehci_dma_mask;
151
215 hcd = usb_create_hcd(&ehci_omap_hc_driver, dev, 152 hcd = usb_create_hcd(&ehci_omap_hc_driver, dev,
216 dev_name(dev)); 153 dev_name(dev));
217 if (!hcd) { 154 if (!hcd) {
218 dev_err(dev, "failed to create hcd with err %d\n", ret); 155 dev_err(dev, "Failed to create HCD\n");
219 ret = -ENOMEM; 156 return -ENOMEM;
220 goto err_io;
221 } 157 }
222 158
223 hcd->rsrc_start = res->start; 159 hcd->rsrc_start = res->start;
224 hcd->rsrc_len = resource_size(res); 160 hcd->rsrc_len = resource_size(res);
225 hcd->regs = regs; 161 hcd->regs = regs;
226 162 hcd_to_ehci(hcd)->caps = regs;
227 /* get ehci regulator and enable */ 163
228 for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) { 164 omap = (struct omap_hcd *)hcd_to_ehci(hcd)->priv;
229 if (pdata->port_mode[i] != OMAP_EHCI_PORT_MODE_PHY) { 165 omap->nports = pdata->nports;
230 pdata->regulator[i] = NULL; 166
231 continue; 167 platform_set_drvdata(pdev, hcd);
232 } 168
233 snprintf(supply, sizeof(supply), "hsusb%d", i); 169 /* get the PHY devices if needed */
234 pdata->regulator[i] = regulator_get(dev, supply); 170 for (i = 0 ; i < omap->nports ; i++) {
235 if (IS_ERR(pdata->regulator[i])) { 171 struct usb_phy *phy;
236 pdata->regulator[i] = NULL; 172
237 dev_dbg(dev, 173 /* get the PHY device */
238 "failed to get ehci port%d regulator\n", i); 174 if (dev->of_node)
239 } else { 175 phy = devm_usb_get_phy_by_phandle(dev, "phys", i);
240 regulator_enable(pdata->regulator[i]); 176 else
177 phy = devm_usb_get_phy_dev(dev, i);
178 if (IS_ERR(phy) || !phy) {
179 /* Don't bail out if PHY is not absolutely necessary */
180 if (pdata->port_mode[i] != OMAP_EHCI_PORT_MODE_PHY)
181 continue;
182
183 ret = IS_ERR(phy) ? PTR_ERR(phy) : -ENODEV;
184 dev_err(dev, "Can't get PHY device for port %d: %d\n",
185 i, ret);
186 goto err_phy;
241 } 187 }
188
189 omap->phy[i] = phy;
242 } 190 }
243 191
244 pm_runtime_enable(dev); 192 pm_runtime_enable(dev);
@@ -262,16 +210,34 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
262 goto err_pm_runtime; 210 goto err_pm_runtime;
263 } 211 }
264 212
213 /*
214 * Bring PHYs out of reset.
215 * Even though HSIC mode is a PHY-less mode, the reset
216 * line exists between the chips and can be modelled
217 * as a PHY device for reset control.
218 */
219 for (i = 0; i < omap->nports; i++) {
220 if (!omap->phy[i])
221 continue;
222
223 usb_phy_init(omap->phy[i]);
224 /* bring PHY out of suspend */
225 usb_phy_set_suspend(omap->phy[i], 0);
226 }
265 227
266 return 0; 228 return 0;
267 229
268err_pm_runtime: 230err_pm_runtime:
269 disable_put_regulator(pdata);
270 pm_runtime_put_sync(dev); 231 pm_runtime_put_sync(dev);
232
233err_phy:
234 for (i = 0; i < omap->nports; i++) {
235 if (omap->phy[i])
236 usb_phy_shutdown(omap->phy[i]);
237 }
238
271 usb_put_hcd(hcd); 239 usb_put_hcd(hcd);
272 240
273err_io:
274 iounmap(regs);
275 return ret; 241 return ret;
276} 242}
277 243
@@ -286,14 +252,19 @@ err_io:
286 */ 252 */
287static int ehci_hcd_omap_remove(struct platform_device *pdev) 253static int ehci_hcd_omap_remove(struct platform_device *pdev)
288{ 254{
289 struct device *dev = &pdev->dev; 255 struct device *dev = &pdev->dev;
290 struct usb_hcd *hcd = dev_get_drvdata(dev); 256 struct usb_hcd *hcd = dev_get_drvdata(dev);
257 struct omap_hcd *omap = (struct omap_hcd *)hcd_to_ehci(hcd)->priv;
258 int i;
291 259
292 usb_remove_hcd(hcd); 260 usb_remove_hcd(hcd);
293 disable_put_regulator(dev->platform_data);
294 iounmap(hcd->regs);
295 usb_put_hcd(hcd);
296 261
262 for (i = 0; i < omap->nports; i++) {
263 if (omap->phy[i])
264 usb_phy_shutdown(omap->phy[i]);
265 }
266
267 usb_put_hcd(hcd);
297 pm_runtime_put_sync(dev); 268 pm_runtime_put_sync(dev);
298 pm_runtime_disable(dev); 269 pm_runtime_disable(dev);
299 270
@@ -308,6 +279,13 @@ static void ehci_hcd_omap_shutdown(struct platform_device *pdev)
308 hcd->driver->shutdown(hcd); 279 hcd->driver->shutdown(hcd);
309} 280}
310 281
282static const struct of_device_id omap_ehci_dt_ids[] = {
283 { .compatible = "ti,ehci-omap" },
284 { }
285};
286
287MODULE_DEVICE_TABLE(of, omap_ehci_dt_ids);
288
311static struct platform_driver ehci_hcd_omap_driver = { 289static struct platform_driver ehci_hcd_omap_driver = {
312 .probe = ehci_hcd_omap_probe, 290 .probe = ehci_hcd_omap_probe,
313 .remove = ehci_hcd_omap_remove, 291 .remove = ehci_hcd_omap_remove,
@@ -315,56 +293,35 @@ static struct platform_driver ehci_hcd_omap_driver = {
315 /*.suspend = ehci_hcd_omap_suspend, */ 293 /*.suspend = ehci_hcd_omap_suspend, */
316 /*.resume = ehci_hcd_omap_resume, */ 294 /*.resume = ehci_hcd_omap_resume, */
317 .driver = { 295 .driver = {
318 .name = "ehci-omap", 296 .name = hcd_name,
297 .of_match_table = of_match_ptr(omap_ehci_dt_ids),
319 } 298 }
320}; 299};
321 300
322/*-------------------------------------------------------------------------*/ 301/*-------------------------------------------------------------------------*/
323 302
324static const struct hc_driver ehci_omap_hc_driver = { 303static int __init ehci_omap_init(void)
325 .description = hcd_name, 304{
326 .product_desc = "OMAP-EHCI Host Controller", 305 if (usb_disabled())
327 .hcd_priv_size = sizeof(struct ehci_hcd), 306 return -ENODEV;
328
329 /*
330 * generic hardware linkage
331 */
332 .irq = ehci_irq,
333 .flags = HCD_MEMORY | HCD_USB2,
334
335 /*
336 * basic lifecycle operations
337 */
338 .reset = omap_ehci_init,
339 .start = ehci_run,
340 .stop = ehci_stop,
341 .shutdown = ehci_shutdown,
342
343 /*
344 * managing i/o requests and associated device resources
345 */
346 .urb_enqueue = ehci_urb_enqueue,
347 .urb_dequeue = ehci_urb_dequeue,
348 .endpoint_disable = ehci_endpoint_disable,
349 .endpoint_reset = ehci_endpoint_reset,
350 307
351 /* 308 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
352 * scheduling support
353 */
354 .get_frame_number = ehci_get_frame,
355 309
356 /* 310 ehci_init_driver(&ehci_omap_hc_driver, &ehci_omap_overrides);
357 * root hub support 311 return platform_driver_register(&ehci_hcd_omap_driver);
358 */ 312}
359 .hub_status_data = ehci_hub_status_data, 313module_init(ehci_omap_init);
360 .hub_control = ehci_hub_control,
361 .bus_suspend = ehci_bus_suspend,
362 .bus_resume = ehci_bus_resume,
363 314
364 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, 315static void __exit ehci_omap_cleanup(void)
365}; 316{
317 platform_driver_unregister(&ehci_hcd_omap_driver);
318}
319module_exit(ehci_omap_cleanup);
366 320
367MODULE_ALIAS("platform:ehci-omap"); 321MODULE_ALIAS("platform:ehci-omap");
368MODULE_AUTHOR("Texas Instruments, Inc."); 322MODULE_AUTHOR("Texas Instruments, Inc.");
369MODULE_AUTHOR("Felipe Balbi <felipe.balbi@nokia.com>"); 323MODULE_AUTHOR("Felipe Balbi <felipe.balbi@nokia.com>");
324MODULE_AUTHOR("Roger Quadros <rogerq@ti.com>");
370 325
326MODULE_DESCRIPTION(DRIVER_DESC);
327MODULE_LICENSE("GPL");
diff --git a/drivers/usb/host/ehci-orion.c b/drivers/usb/host/ehci-orion.c
index 914a3ecfb5d3..38c45fb3357e 100644
--- a/drivers/usb/host/ehci-orion.c
+++ b/drivers/usb/host/ehci-orion.c
@@ -305,7 +305,7 @@ err1:
305 return err; 305 return err;
306} 306}
307 307
308static int __exit ehci_orion_drv_remove(struct platform_device *pdev) 308static int ehci_orion_drv_remove(struct platform_device *pdev)
309{ 309{
310 struct usb_hcd *hcd = platform_get_drvdata(pdev); 310 struct usb_hcd *hcd = platform_get_drvdata(pdev);
311 struct clk *clk; 311 struct clk *clk;
@@ -333,7 +333,7 @@ MODULE_DEVICE_TABLE(of, ehci_orion_dt_ids);
333 333
334static struct platform_driver ehci_orion_driver = { 334static struct platform_driver ehci_orion_driver = {
335 .probe = ehci_orion_drv_probe, 335 .probe = ehci_orion_drv_probe,
336 .remove = __exit_p(ehci_orion_drv_remove), 336 .remove = ehci_orion_drv_remove,
337 .shutdown = usb_hcd_platform_shutdown, 337 .shutdown = usb_hcd_platform_shutdown,
338 .driver = { 338 .driver = {
339 .name = "orion-ehci", 339 .name = "orion-ehci",
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
index 170b9399e09f..a573d5ff9adc 100644
--- a/drivers/usb/host/ehci-pci.c
+++ b/drivers/usb/host/ehci-pci.c
@@ -292,17 +292,7 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
292 } 292 }
293 } 293 }
294 294
295#ifdef CONFIG_USB_SUSPEND 295#ifdef CONFIG_PM_RUNTIME
296 /* REVISIT: the controller works fine for wakeup iff the root hub
297 * itself is "globally" suspended, but usbcore currently doesn't
298 * understand such things.
299 *
300 * System suspend currently expects to be able to suspend the entire
301 * device tree, device-at-a-time. If we failed selective suspend
302 * reports, system suspend would fail; so the root hub code must claim
303 * success. That's lying to usbcore, and it matters for runtime
304 * PM scenarios with selective suspend and remote wakeup...
305 */
306 if (ehci->no_selective_suspend && device_can_wakeup(&pdev->dev)) 296 if (ehci->no_selective_suspend && device_can_wakeup(&pdev->dev))
307 ehci_warn(ehci, "selective suspend/wakeup unavailable\n"); 297 ehci_warn(ehci, "selective suspend/wakeup unavailable\n");
308#endif 298#endif
diff --git a/drivers/usb/host/ehci-platform.c b/drivers/usb/host/ehci-platform.c
index ca7506390542..cda0fa9613e7 100644
--- a/drivers/usb/host/ehci-platform.c
+++ b/drivers/usb/host/ehci-platform.c
@@ -18,11 +18,13 @@
18 * 18 *
19 * Licensed under the GNU/GPL. See COPYING for details. 19 * Licensed under the GNU/GPL. See COPYING for details.
20 */ 20 */
21#include <linux/dma-mapping.h>
21#include <linux/err.h> 22#include <linux/err.h>
22#include <linux/kernel.h> 23#include <linux/kernel.h>
23#include <linux/hrtimer.h> 24#include <linux/hrtimer.h>
24#include <linux/io.h> 25#include <linux/io.h>
25#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/of.h>
26#include <linux/platform_device.h> 28#include <linux/platform_device.h>
27#include <linux/usb.h> 29#include <linux/usb.h>
28#include <linux/usb/hcd.h> 30#include <linux/usb/hcd.h>
@@ -62,22 +64,32 @@ static const struct ehci_driver_overrides platform_overrides __initdata = {
62 .reset = ehci_platform_reset, 64 .reset = ehci_platform_reset,
63}; 65};
64 66
67static struct usb_ehci_pdata ehci_platform_defaults;
68
65static int ehci_platform_probe(struct platform_device *dev) 69static int ehci_platform_probe(struct platform_device *dev)
66{ 70{
67 struct usb_hcd *hcd; 71 struct usb_hcd *hcd;
68 struct resource *res_mem; 72 struct resource *res_mem;
69 struct usb_ehci_pdata *pdata = dev->dev.platform_data; 73 struct usb_ehci_pdata *pdata;
70 int irq; 74 int irq;
71 int err = -ENOMEM; 75 int err = -ENOMEM;
72 76
73 if (!pdata) {
74 WARN_ON(1);
75 return -ENODEV;
76 }
77
78 if (usb_disabled()) 77 if (usb_disabled())
79 return -ENODEV; 78 return -ENODEV;
80 79
80 /*
81 * use reasonable defaults so platforms don't have to provide these.
82 * with DT probing on ARM, none of these are set.
83 */
84 if (!dev->dev.platform_data)
85 dev->dev.platform_data = &ehci_platform_defaults;
86 if (!dev->dev.dma_mask)
87 dev->dev.dma_mask = &dev->dev.coherent_dma_mask;
88 if (!dev->dev.coherent_dma_mask)
89 dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
90
91 pdata = dev->dev.platform_data;
92
81 irq = platform_get_irq(dev, 0); 93 irq = platform_get_irq(dev, 0);
82 if (irq < 0) { 94 if (irq < 0) {
83 dev_err(&dev->dev, "no irq provided"); 95 dev_err(&dev->dev, "no irq provided");
@@ -139,6 +151,9 @@ static int ehci_platform_remove(struct platform_device *dev)
139 if (pdata->power_off) 151 if (pdata->power_off)
140 pdata->power_off(dev); 152 pdata->power_off(dev);
141 153
154 if (pdata == &ehci_platform_defaults)
155 dev->dev.platform_data = NULL;
156
142 return 0; 157 return 0;
143} 158}
144 159
@@ -183,6 +198,12 @@ static int ehci_platform_resume(struct device *dev)
183#define ehci_platform_resume NULL 198#define ehci_platform_resume NULL
184#endif /* CONFIG_PM */ 199#endif /* CONFIG_PM */
185 200
201static const struct of_device_id vt8500_ehci_ids[] = {
202 { .compatible = "via,vt8500-ehci", },
203 { .compatible = "wm,prizm-ehci", },
204 {}
205};
206
186static const struct platform_device_id ehci_platform_table[] = { 207static const struct platform_device_id ehci_platform_table[] = {
187 { "ehci-platform", 0 }, 208 { "ehci-platform", 0 },
188 { } 209 { }
@@ -203,6 +224,7 @@ static struct platform_driver ehci_platform_driver = {
203 .owner = THIS_MODULE, 224 .owner = THIS_MODULE,
204 .name = "ehci-platform", 225 .name = "ehci-platform",
205 .pm = &ehci_platform_pm_ops, 226 .pm = &ehci_platform_pm_ops,
227 .of_match_table = of_match_ptr(vt8500_ehci_ids),
206 } 228 }
207}; 229};
208 230
diff --git a/drivers/usb/host/ehci-ps3.c b/drivers/usb/host/ehci-ps3.c
index df5925a4f0db..fd983771b025 100644
--- a/drivers/usb/host/ehci-ps3.c
+++ b/drivers/usb/host/ehci-ps3.c
@@ -221,7 +221,6 @@ static int ps3_ehci_remove(struct ps3_system_bus_device *dev)
221 221
222 tmp = hcd->irq; 222 tmp = hcd->irq;
223 223
224 ehci_shutdown(hcd);
225 usb_remove_hcd(hcd); 224 usb_remove_hcd(hcd);
226 225
227 ps3_system_bus_set_drvdata(dev, NULL); 226 ps3_system_bus_set_drvdata(dev, NULL);
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index 23d136904285..d34b399b78e2 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -90,7 +90,7 @@ qh_update (struct ehci_hcd *ehci, struct ehci_qh *qh, struct ehci_qtd *qtd)
90 struct ehci_qh_hw *hw = qh->hw; 90 struct ehci_qh_hw *hw = qh->hw;
91 91
92 /* writes to an active overlay are unsafe */ 92 /* writes to an active overlay are unsafe */
93 BUG_ON(qh->qh_state != QH_STATE_IDLE); 93 WARN_ON(qh->qh_state != QH_STATE_IDLE);
94 94
95 hw->hw_qtd_next = QTD_NEXT(ehci, qtd->qtd_dma); 95 hw->hw_qtd_next = QTD_NEXT(ehci, qtd->qtd_dma);
96 hw->hw_alt_next = EHCI_LIST_END(ehci); 96 hw->hw_alt_next = EHCI_LIST_END(ehci);
@@ -123,26 +123,19 @@ qh_refresh (struct ehci_hcd *ehci, struct ehci_qh *qh)
123{ 123{
124 struct ehci_qtd *qtd; 124 struct ehci_qtd *qtd;
125 125
126 if (list_empty (&qh->qtd_list)) 126 qtd = list_entry(qh->qtd_list.next, struct ehci_qtd, qtd_list);
127 qtd = qh->dummy;
128 else {
129 qtd = list_entry (qh->qtd_list.next,
130 struct ehci_qtd, qtd_list);
131 /*
132 * first qtd may already be partially processed.
133 * If we come here during unlink, the QH overlay region
134 * might have reference to the just unlinked qtd. The
135 * qtd is updated in qh_completions(). Update the QH
136 * overlay here.
137 */
138 if (qh->hw->hw_token & ACTIVE_BIT(ehci)) {
139 qh->hw->hw_qtd_next = qtd->hw_next;
140 qtd = NULL;
141 }
142 }
143 127
144 if (qtd) 128 /*
145 qh_update (ehci, qh, qtd); 129 * first qtd may already be partially processed.
130 * If we come here during unlink, the QH overlay region
131 * might have reference to the just unlinked qtd. The
132 * qtd is updated in qh_completions(). Update the QH
133 * overlay here.
134 */
135 if (qh->hw->hw_token & ACTIVE_BIT(ehci))
136 qh->hw->hw_qtd_next = qtd->hw_next;
137 else
138 qh_update(ehci, qh, qtd);
146} 139}
147 140
148/*-------------------------------------------------------------------------*/ 141/*-------------------------------------------------------------------------*/
@@ -299,8 +292,8 @@ static int qh_schedule (struct ehci_hcd *ehci, struct ehci_qh *qh);
299 292
300/* 293/*
301 * Process and free completed qtds for a qh, returning URBs to drivers. 294 * Process and free completed qtds for a qh, returning URBs to drivers.
302 * Chases up to qh->hw_current. Returns number of completions called, 295 * Chases up to qh->hw_current. Returns nonzero if the caller should
303 * indicating how much "real" work we did. 296 * unlink qh.
304 */ 297 */
305static unsigned 298static unsigned
306qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh) 299qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
@@ -309,13 +302,9 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
309 struct list_head *entry, *tmp; 302 struct list_head *entry, *tmp;
310 int last_status; 303 int last_status;
311 int stopped; 304 int stopped;
312 unsigned count = 0;
313 u8 state; 305 u8 state;
314 struct ehci_qh_hw *hw = qh->hw; 306 struct ehci_qh_hw *hw = qh->hw;
315 307
316 if (unlikely (list_empty (&qh->qtd_list)))
317 return count;
318
319 /* completions (or tasks on other cpus) must never clobber HALT 308 /* completions (or tasks on other cpus) must never clobber HALT
320 * till we've gone through and cleaned everything up, even when 309 * till we've gone through and cleaned everything up, even when
321 * they add urbs to this qh's queue or mark them for unlinking. 310 * they add urbs to this qh's queue or mark them for unlinking.
@@ -333,7 +322,7 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
333 rescan: 322 rescan:
334 last = NULL; 323 last = NULL;
335 last_status = -EINPROGRESS; 324 last_status = -EINPROGRESS;
336 qh->needs_rescan = 0; 325 qh->dequeue_during_giveback = 0;
337 326
338 /* remove de-activated QTDs from front of queue. 327 /* remove de-activated QTDs from front of queue.
339 * after faults (including short reads), cleanup this urb 328 * after faults (including short reads), cleanup this urb
@@ -352,7 +341,6 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
352 if (last) { 341 if (last) {
353 if (likely (last->urb != urb)) { 342 if (likely (last->urb != urb)) {
354 ehci_urb_done(ehci, last->urb, last_status); 343 ehci_urb_done(ehci, last->urb, last_status);
355 count++;
356 last_status = -EINPROGRESS; 344 last_status = -EINPROGRESS;
357 } 345 }
358 ehci_qtd_free (ehci, last); 346 ehci_qtd_free (ehci, last);
@@ -526,23 +514,16 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
526 /* last urb's completion might still need calling */ 514 /* last urb's completion might still need calling */
527 if (likely (last != NULL)) { 515 if (likely (last != NULL)) {
528 ehci_urb_done(ehci, last->urb, last_status); 516 ehci_urb_done(ehci, last->urb, last_status);
529 count++;
530 ehci_qtd_free (ehci, last); 517 ehci_qtd_free (ehci, last);
531 } 518 }
532 519
533 /* Do we need to rescan for URBs dequeued during a giveback? */ 520 /* Do we need to rescan for URBs dequeued during a giveback? */
534 if (unlikely(qh->needs_rescan)) { 521 if (unlikely(qh->dequeue_during_giveback)) {
535 /* If the QH is already unlinked, do the rescan now. */ 522 /* If the QH is already unlinked, do the rescan now. */
536 if (state == QH_STATE_IDLE) 523 if (state == QH_STATE_IDLE)
537 goto rescan; 524 goto rescan;
538 525
539 /* Otherwise we have to wait until the QH is fully unlinked. 526 /* Otherwise the caller must unlink the QH. */
540 * Our caller will start an unlink if qh->needs_rescan is
541 * set. But if an unlink has already started, nothing needs
542 * to be done.
543 */
544 if (state != QH_STATE_LINKED)
545 qh->needs_rescan = 0;
546 } 527 }
547 528
548 /* restore original state; caller must unlink or relink */ 529 /* restore original state; caller must unlink or relink */
@@ -551,33 +532,23 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
551 /* be sure the hardware's done with the qh before refreshing 532 /* be sure the hardware's done with the qh before refreshing
552 * it after fault cleanup, or recovering from silicon wrongly 533 * it after fault cleanup, or recovering from silicon wrongly
553 * overlaying the dummy qtd (which reduces DMA chatter). 534 * overlaying the dummy qtd (which reduces DMA chatter).
535 *
536 * We won't refresh a QH that's linked (after the HC
537 * stopped the queue). That avoids a race:
538 * - HC reads first part of QH;
539 * - CPU updates that first part and the token;
540 * - HC reads rest of that QH, including token
541 * Result: HC gets an inconsistent image, and then
542 * DMAs to/from the wrong memory (corrupting it).
543 *
544 * That should be rare for interrupt transfers,
545 * except maybe high bandwidth ...
554 */ 546 */
555 if (stopped != 0 || hw->hw_qtd_next == EHCI_LIST_END(ehci)) { 547 if (stopped != 0 || hw->hw_qtd_next == EHCI_LIST_END(ehci))
556 switch (state) { 548 qh->exception = 1;
557 case QH_STATE_IDLE:
558 qh_refresh(ehci, qh);
559 break;
560 case QH_STATE_LINKED:
561 /* We won't refresh a QH that's linked (after the HC
562 * stopped the queue). That avoids a race:
563 * - HC reads first part of QH;
564 * - CPU updates that first part and the token;
565 * - HC reads rest of that QH, including token
566 * Result: HC gets an inconsistent image, and then
567 * DMAs to/from the wrong memory (corrupting it).
568 *
569 * That should be rare for interrupt transfers,
570 * except maybe high bandwidth ...
571 */
572 549
573 /* Tell the caller to start an unlink */ 550 /* Let the caller know if the QH needs to be unlinked. */
574 qh->needs_rescan = 1; 551 return qh->exception;
575 break;
576 /* otherwise, unlink already started */
577 }
578 }
579
580 return count;
581} 552}
582 553
583/*-------------------------------------------------------------------------*/ 554/*-------------------------------------------------------------------------*/
@@ -957,14 +928,13 @@ done:
957 928
958 /* NOTE: if (PIPE_INTERRUPT) { scheduler sets s-mask } */ 929 /* NOTE: if (PIPE_INTERRUPT) { scheduler sets s-mask } */
959 930
960 /* init as live, toggle clear, advance to dummy */ 931 /* init as live, toggle clear */
961 qh->qh_state = QH_STATE_IDLE; 932 qh->qh_state = QH_STATE_IDLE;
962 hw = qh->hw; 933 hw = qh->hw;
963 hw->hw_info1 = cpu_to_hc32(ehci, info1); 934 hw->hw_info1 = cpu_to_hc32(ehci, info1);
964 hw->hw_info2 = cpu_to_hc32(ehci, info2); 935 hw->hw_info2 = cpu_to_hc32(ehci, info2);
965 qh->is_out = !is_input; 936 qh->is_out = !is_input;
966 usb_settoggle (urb->dev, usb_pipeendpoint (urb->pipe), !is_input, 1); 937 usb_settoggle (urb->dev, usb_pipeendpoint (urb->pipe), !is_input, 1);
967 qh_refresh (ehci, qh);
968 return qh; 938 return qh;
969} 939}
970 940
@@ -988,8 +958,9 @@ static void disable_async(struct ehci_hcd *ehci)
988 if (--ehci->async_count) 958 if (--ehci->async_count)
989 return; 959 return;
990 960
991 /* The async schedule and async_unlink list are supposed to be empty */ 961 /* The async schedule and unlink lists are supposed to be empty */
992 WARN_ON(ehci->async->qh_next.qh || ehci->async_unlink); 962 WARN_ON(ehci->async->qh_next.qh || !list_empty(&ehci->async_unlink) ||
963 !list_empty(&ehci->async_idle));
993 964
994 /* Don't turn off the schedule until ASS is 1 */ 965 /* Don't turn off the schedule until ASS is 1 */
995 ehci_poll_ASS(ehci); 966 ehci_poll_ASS(ehci);
@@ -1020,8 +991,9 @@ static void qh_link_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
1020 head->qh_next.qh = qh; 991 head->qh_next.qh = qh;
1021 head->hw->hw_next = dma; 992 head->hw->hw_next = dma;
1022 993
1023 qh->xacterrs = 0;
1024 qh->qh_state = QH_STATE_LINKED; 994 qh->qh_state = QH_STATE_LINKED;
995 qh->xacterrs = 0;
996 qh->exception = 0;
1025 /* qtd completions reported later by interrupt */ 997 /* qtd completions reported later by interrupt */
1026 998
1027 enable_async(ehci); 999 enable_async(ehci);
@@ -1179,11 +1151,7 @@ static void single_unlink_async(struct ehci_hcd *ehci, struct ehci_qh *qh)
1179 1151
1180 /* Add to the end of the list of QHs waiting for the next IAAD */ 1152 /* Add to the end of the list of QHs waiting for the next IAAD */
1181 qh->qh_state = QH_STATE_UNLINK_WAIT; 1153 qh->qh_state = QH_STATE_UNLINK_WAIT;
1182 if (ehci->async_unlink) 1154 list_add_tail(&qh->unlink_node, &ehci->async_unlink);
1183 ehci->async_unlink_last->unlink_next = qh;
1184 else
1185 ehci->async_unlink = qh;
1186 ehci->async_unlink_last = qh;
1187 1155
1188 /* Unlink it from the schedule */ 1156 /* Unlink it from the schedule */
1189 prev = ehci->async; 1157 prev = ehci->async;
@@ -1196,44 +1164,19 @@ static void single_unlink_async(struct ehci_hcd *ehci, struct ehci_qh *qh)
1196 ehci->qh_scan_next = qh->qh_next.qh; 1164 ehci->qh_scan_next = qh->qh_next.qh;
1197} 1165}
1198 1166
1199static void start_iaa_cycle(struct ehci_hcd *ehci, bool nested) 1167static void start_iaa_cycle(struct ehci_hcd *ehci)
1200{ 1168{
1201 /* 1169 /* Do nothing if an IAA cycle is already running */
1202 * Do nothing if an IAA cycle is already running or 1170 if (ehci->iaa_in_progress)
1203 * if one will be started shortly.
1204 */
1205 if (ehci->async_iaa || ehci->async_unlinking)
1206 return; 1171 return;
1172 ehci->iaa_in_progress = true;
1207 1173
1208 /* If the controller isn't running, we don't have to wait for it */ 1174 /* If the controller isn't running, we don't have to wait for it */
1209 if (unlikely(ehci->rh_state < EHCI_RH_RUNNING)) { 1175 if (unlikely(ehci->rh_state < EHCI_RH_RUNNING)) {
1210 1176 end_unlink_async(ehci);
1211 /* Do all the waiting QHs */
1212 ehci->async_iaa = ehci->async_unlink;
1213 ehci->async_unlink = NULL;
1214
1215 if (!nested) /* Avoid recursion */
1216 end_unlink_async(ehci);
1217 1177
1218 /* Otherwise start a new IAA cycle */ 1178 /* Otherwise start a new IAA cycle */
1219 } else if (likely(ehci->rh_state == EHCI_RH_RUNNING)) { 1179 } else if (likely(ehci->rh_state == EHCI_RH_RUNNING)) {
1220 struct ehci_qh *qh;
1221
1222 /* Do only the first waiting QH (nVidia bug?) */
1223 qh = ehci->async_unlink;
1224
1225 /*
1226 * Intel (?) bug: The HC can write back the overlay region
1227 * even after the IAA interrupt occurs. In self-defense,
1228 * always go through two IAA cycles for each QH.
1229 */
1230 if (qh->qh_state == QH_STATE_UNLINK_WAIT) {
1231 qh->qh_state = QH_STATE_UNLINK;
1232 } else {
1233 ehci->async_iaa = qh;
1234 ehci->async_unlink = qh->unlink_next;
1235 qh->unlink_next = NULL;
1236 }
1237 1180
1238 /* Make sure the unlinks are all visible to the hardware */ 1181 /* Make sure the unlinks are all visible to the hardware */
1239 wmb(); 1182 wmb();
@@ -1250,36 +1193,73 @@ static void start_iaa_cycle(struct ehci_hcd *ehci, bool nested)
1250static void end_unlink_async(struct ehci_hcd *ehci) 1193static void end_unlink_async(struct ehci_hcd *ehci)
1251{ 1194{
1252 struct ehci_qh *qh; 1195 struct ehci_qh *qh;
1196 bool early_exit;
1253 1197
1254 if (ehci->has_synopsys_hc_bug) 1198 if (ehci->has_synopsys_hc_bug)
1255 ehci_writel(ehci, (u32) ehci->async->qh_dma, 1199 ehci_writel(ehci, (u32) ehci->async->qh_dma,
1256 &ehci->regs->async_next); 1200 &ehci->regs->async_next);
1257 1201
1202 /* The current IAA cycle has ended */
1203 ehci->iaa_in_progress = false;
1204
1205 if (list_empty(&ehci->async_unlink))
1206 return;
1207 qh = list_first_entry(&ehci->async_unlink, struct ehci_qh,
1208 unlink_node); /* QH whose IAA cycle just ended */
1209
1210 /*
1211 * If async_unlinking is set then this routine is already running,
1212 * either on the stack or on another CPU.
1213 */
1214 early_exit = ehci->async_unlinking;
1215
1216 /* If the controller isn't running, process all the waiting QHs */
1217 if (ehci->rh_state < EHCI_RH_RUNNING)
1218 list_splice_tail_init(&ehci->async_unlink, &ehci->async_idle);
1219
1220 /*
1221 * Intel (?) bug: The HC can write back the overlay region even
1222 * after the IAA interrupt occurs. In self-defense, always go
1223 * through two IAA cycles for each QH.
1224 */
1225 else if (qh->qh_state == QH_STATE_UNLINK_WAIT) {
1226 qh->qh_state = QH_STATE_UNLINK;
1227 early_exit = true;
1228 }
1229
1230 /* Otherwise process only the first waiting QH (NVIDIA bug?) */
1231 else
1232 list_move_tail(&qh->unlink_node, &ehci->async_idle);
1233
1234 /* Start a new IAA cycle if any QHs are waiting for it */
1235 if (!list_empty(&ehci->async_unlink))
1236 start_iaa_cycle(ehci);
1237
1238 /*
1239 * Don't allow nesting or concurrent calls,
1240 * or wait for the second IAA cycle for the next QH.
1241 */
1242 if (early_exit)
1243 return;
1244
1258 /* Process the idle QHs */ 1245 /* Process the idle QHs */
1259 restart:
1260 ehci->async_unlinking = true; 1246 ehci->async_unlinking = true;
1261 while (ehci->async_iaa) { 1247 while (!list_empty(&ehci->async_idle)) {
1262 qh = ehci->async_iaa; 1248 qh = list_first_entry(&ehci->async_idle, struct ehci_qh,
1263 ehci->async_iaa = qh->unlink_next; 1249 unlink_node);
1264 qh->unlink_next = NULL; 1250 list_del(&qh->unlink_node);
1265 1251
1266 qh->qh_state = QH_STATE_IDLE; 1252 qh->qh_state = QH_STATE_IDLE;
1267 qh->qh_next.qh = NULL; 1253 qh->qh_next.qh = NULL;
1268 1254
1269 qh_completions(ehci, qh); 1255 if (!list_empty(&qh->qtd_list))
1256 qh_completions(ehci, qh);
1270 if (!list_empty(&qh->qtd_list) && 1257 if (!list_empty(&qh->qtd_list) &&
1271 ehci->rh_state == EHCI_RH_RUNNING) 1258 ehci->rh_state == EHCI_RH_RUNNING)
1272 qh_link_async(ehci, qh); 1259 qh_link_async(ehci, qh);
1273 disable_async(ehci); 1260 disable_async(ehci);
1274 } 1261 }
1275 ehci->async_unlinking = false; 1262 ehci->async_unlinking = false;
1276
1277 /* Start a new IAA cycle if any QHs are waiting for it */
1278 if (ehci->async_unlink) {
1279 start_iaa_cycle(ehci, true);
1280 if (unlikely(ehci->rh_state < EHCI_RH_RUNNING))
1281 goto restart;
1282 }
1283} 1263}
1284 1264
1285static void start_unlink_async(struct ehci_hcd *ehci, struct ehci_qh *qh); 1265static void start_unlink_async(struct ehci_hcd *ehci, struct ehci_qh *qh);
@@ -1288,7 +1268,6 @@ static void unlink_empty_async(struct ehci_hcd *ehci)
1288{ 1268{
1289 struct ehci_qh *qh; 1269 struct ehci_qh *qh;
1290 struct ehci_qh *qh_to_unlink = NULL; 1270 struct ehci_qh *qh_to_unlink = NULL;
1291 bool check_unlinks_later = false;
1292 int count = 0; 1271 int count = 0;
1293 1272
1294 /* Find the last async QH which has been empty for a timer cycle */ 1273 /* Find the last async QH which has been empty for a timer cycle */
@@ -1296,15 +1275,13 @@ static void unlink_empty_async(struct ehci_hcd *ehci)
1296 if (list_empty(&qh->qtd_list) && 1275 if (list_empty(&qh->qtd_list) &&
1297 qh->qh_state == QH_STATE_LINKED) { 1276 qh->qh_state == QH_STATE_LINKED) {
1298 ++count; 1277 ++count;
1299 if (qh->unlink_cycle == ehci->async_unlink_cycle) 1278 if (qh->unlink_cycle != ehci->async_unlink_cycle)
1300 check_unlinks_later = true;
1301 else
1302 qh_to_unlink = qh; 1279 qh_to_unlink = qh;
1303 } 1280 }
1304 } 1281 }
1305 1282
1306 /* If nothing else is being unlinked, unlink the last empty QH */ 1283 /* If nothing else is being unlinked, unlink the last empty QH */
1307 if (!ehci->async_iaa && !ehci->async_unlink && qh_to_unlink) { 1284 if (list_empty(&ehci->async_unlink) && qh_to_unlink) {
1308 start_unlink_async(ehci, qh_to_unlink); 1285 start_unlink_async(ehci, qh_to_unlink);
1309 --count; 1286 --count;
1310 } 1287 }
@@ -1317,7 +1294,7 @@ static void unlink_empty_async(struct ehci_hcd *ehci)
1317} 1294}
1318 1295
1319/* The root hub is suspended; unlink all the async QHs */ 1296/* The root hub is suspended; unlink all the async QHs */
1320static void unlink_empty_async_suspended(struct ehci_hcd *ehci) 1297static void __maybe_unused unlink_empty_async_suspended(struct ehci_hcd *ehci)
1321{ 1298{
1322 struct ehci_qh *qh; 1299 struct ehci_qh *qh;
1323 1300
@@ -1326,7 +1303,7 @@ static void unlink_empty_async_suspended(struct ehci_hcd *ehci)
1326 WARN_ON(!list_empty(&qh->qtd_list)); 1303 WARN_ON(!list_empty(&qh->qtd_list));
1327 single_unlink_async(ehci, qh); 1304 single_unlink_async(ehci, qh);
1328 } 1305 }
1329 start_iaa_cycle(ehci, false); 1306 start_iaa_cycle(ehci);
1330} 1307}
1331 1308
1332/* makes sure the async qh will become idle */ 1309/* makes sure the async qh will become idle */
@@ -1334,19 +1311,12 @@ static void unlink_empty_async_suspended(struct ehci_hcd *ehci)
1334 1311
1335static void start_unlink_async(struct ehci_hcd *ehci, struct ehci_qh *qh) 1312static void start_unlink_async(struct ehci_hcd *ehci, struct ehci_qh *qh)
1336{ 1313{
1337 /* 1314 /* If the QH isn't linked then there's nothing we can do. */
1338 * If the QH isn't linked then there's nothing we can do 1315 if (qh->qh_state != QH_STATE_LINKED)
1339 * unless we were called during a giveback, in which case
1340 * qh_completions() has to deal with it.
1341 */
1342 if (qh->qh_state != QH_STATE_LINKED) {
1343 if (qh->qh_state == QH_STATE_COMPLETING)
1344 qh->needs_rescan = 1;
1345 return; 1316 return;
1346 }
1347 1317
1348 single_unlink_async(ehci, qh); 1318 single_unlink_async(ehci, qh);
1349 start_iaa_cycle(ehci, false); 1319 start_iaa_cycle(ehci);
1350} 1320}
1351 1321
1352/*-------------------------------------------------------------------------*/ 1322/*-------------------------------------------------------------------------*/
@@ -1360,7 +1330,7 @@ static void scan_async (struct ehci_hcd *ehci)
1360 while (ehci->qh_scan_next) { 1330 while (ehci->qh_scan_next) {
1361 qh = ehci->qh_scan_next; 1331 qh = ehci->qh_scan_next;
1362 ehci->qh_scan_next = qh->qh_next.qh; 1332 ehci->qh_scan_next = qh->qh_next.qh;
1363 rescan: 1333
1364 /* clean any finished work for this qh */ 1334 /* clean any finished work for this qh */
1365 if (!list_empty(&qh->qtd_list)) { 1335 if (!list_empty(&qh->qtd_list)) {
1366 int temp; 1336 int temp;
@@ -1373,14 +1343,13 @@ static void scan_async (struct ehci_hcd *ehci)
1373 * in single_unlink_async(). 1343 * in single_unlink_async().
1374 */ 1344 */
1375 temp = qh_completions(ehci, qh); 1345 temp = qh_completions(ehci, qh);
1376 if (qh->needs_rescan) { 1346 if (unlikely(temp)) {
1377 start_unlink_async(ehci, qh); 1347 start_unlink_async(ehci, qh);
1378 } else if (list_empty(&qh->qtd_list) 1348 } else if (list_empty(&qh->qtd_list)
1379 && qh->qh_state == QH_STATE_LINKED) { 1349 && qh->qh_state == QH_STATE_LINKED) {
1380 qh->unlink_cycle = ehci->async_unlink_cycle; 1350 qh->unlink_cycle = ehci->async_unlink_cycle;
1381 check_unlinks_later = true; 1351 check_unlinks_later = true;
1382 } else if (temp != 0) 1352 }
1383 goto rescan;
1384 } 1353 }
1385 } 1354 }
1386 1355
diff --git a/drivers/usb/host/ehci-s5p.c b/drivers/usb/host/ehci-s5p.c
index 20ebf6a8b7f4..43a2a16732f5 100644
--- a/drivers/usb/host/ehci-s5p.c
+++ b/drivers/usb/host/ehci-s5p.c
@@ -92,20 +92,21 @@ static void s5p_ehci_phy_disable(struct s5p_ehci_hcd *s5p_ehci)
92 92
93static void s5p_setup_vbus_gpio(struct platform_device *pdev) 93static void s5p_setup_vbus_gpio(struct platform_device *pdev)
94{ 94{
95 struct device *dev = &pdev->dev;
95 int err; 96 int err;
96 int gpio; 97 int gpio;
97 98
98 if (!pdev->dev.of_node) 99 if (!dev->of_node)
99 return; 100 return;
100 101
101 gpio = of_get_named_gpio(pdev->dev.of_node, 102 gpio = of_get_named_gpio(dev->of_node, "samsung,vbus-gpio", 0);
102 "samsung,vbus-gpio", 0);
103 if (!gpio_is_valid(gpio)) 103 if (!gpio_is_valid(gpio))
104 return; 104 return;
105 105
106 err = gpio_request_one(gpio, GPIOF_OUT_INIT_HIGH, "ehci_vbus_gpio"); 106 err = devm_gpio_request_one(dev, gpio, GPIOF_OUT_INIT_HIGH,
107 "ehci_vbus_gpio");
107 if (err) 108 if (err)
108 dev_err(&pdev->dev, "can't request ehci vbus gpio %d", gpio); 109 dev_err(dev, "can't request ehci vbus gpio %d", gpio);
109} 110}
110 111
111static u64 ehci_s5p_dma_mask = DMA_BIT_MASK(32); 112static u64 ehci_s5p_dma_mask = DMA_BIT_MASK(32);
@@ -139,7 +140,7 @@ static int s5p_ehci_probe(struct platform_device *pdev)
139 return -ENOMEM; 140 return -ENOMEM;
140 141
141 phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); 142 phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
142 if (IS_ERR_OR_NULL(phy)) { 143 if (IS_ERR(phy)) {
143 /* Fallback to pdata */ 144 /* Fallback to pdata */
144 if (!pdata) { 145 if (!pdata) {
145 dev_warn(&pdev->dev, "no platform data or transceiver defined\n"); 146 dev_warn(&pdev->dev, "no platform data or transceiver defined\n");
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index 010f686d8881..acff5b8f6e89 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -539,6 +539,7 @@ static void qh_link_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh)
539 } 539 }
540 qh->qh_state = QH_STATE_LINKED; 540 qh->qh_state = QH_STATE_LINKED;
541 qh->xacterrs = 0; 541 qh->xacterrs = 0;
542 qh->exception = 0;
542 543
543 /* update per-qh bandwidth for usbfs */ 544 /* update per-qh bandwidth for usbfs */
544 ehci_to_hcd(ehci)->self.bandwidth_allocated += qh->period 545 ehci_to_hcd(ehci)->self.bandwidth_allocated += qh->period
@@ -602,15 +603,9 @@ static void qh_unlink_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh)
602 603
603static void start_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh) 604static void start_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh)
604{ 605{
605 /* If the QH isn't linked then there's nothing we can do 606 /* If the QH isn't linked then there's nothing we can do. */
606 * unless we were called during a giveback, in which case 607 if (qh->qh_state != QH_STATE_LINKED)
607 * qh_completions() has to deal with it.
608 */
609 if (qh->qh_state != QH_STATE_LINKED) {
610 if (qh->qh_state == QH_STATE_COMPLETING)
611 qh->needs_rescan = 1;
612 return; 608 return;
613 }
614 609
615 qh_unlink_periodic (ehci, qh); 610 qh_unlink_periodic (ehci, qh);
616 611
@@ -625,17 +620,13 @@ static void start_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh)
625 qh->unlink_cycle = ehci->intr_unlink_cycle; 620 qh->unlink_cycle = ehci->intr_unlink_cycle;
626 621
627 /* New entries go at the end of the intr_unlink list */ 622 /* New entries go at the end of the intr_unlink list */
628 if (ehci->intr_unlink) 623 list_add_tail(&qh->unlink_node, &ehci->intr_unlink);
629 ehci->intr_unlink_last->unlink_next = qh;
630 else
631 ehci->intr_unlink = qh;
632 ehci->intr_unlink_last = qh;
633 624
634 if (ehci->intr_unlinking) 625 if (ehci->intr_unlinking)
635 ; /* Avoid recursive calls */ 626 ; /* Avoid recursive calls */
636 else if (ehci->rh_state < EHCI_RH_RUNNING) 627 else if (ehci->rh_state < EHCI_RH_RUNNING)
637 ehci_handle_intr_unlinks(ehci); 628 ehci_handle_intr_unlinks(ehci);
638 else if (ehci->intr_unlink == qh) { 629 else if (ehci->intr_unlink.next == &qh->unlink_node) {
639 ehci_enable_event(ehci, EHCI_HRTIMER_UNLINK_INTR, true); 630 ehci_enable_event(ehci, EHCI_HRTIMER_UNLINK_INTR, true);
640 ++ehci->intr_unlink_cycle; 631 ++ehci->intr_unlink_cycle;
641 } 632 }
@@ -649,7 +640,8 @@ static void end_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh)
649 qh->qh_state = QH_STATE_IDLE; 640 qh->qh_state = QH_STATE_IDLE;
650 hw->hw_next = EHCI_LIST_END(ehci); 641 hw->hw_next = EHCI_LIST_END(ehci);
651 642
652 qh_completions(ehci, qh); 643 if (!list_empty(&qh->qtd_list))
644 qh_completions(ehci, qh);
653 645
654 /* reschedule QH iff another request is queued */ 646 /* reschedule QH iff another request is queued */
655 if (!list_empty(&qh->qtd_list) && ehci->rh_state == EHCI_RH_RUNNING) { 647 if (!list_empty(&qh->qtd_list) && ehci->rh_state == EHCI_RH_RUNNING) {
@@ -792,7 +784,6 @@ static int qh_schedule(struct ehci_hcd *ehci, struct ehci_qh *qh)
792 unsigned frame; /* 0..(qh->period - 1), or NO_FRAME */ 784 unsigned frame; /* 0..(qh->period - 1), or NO_FRAME */
793 struct ehci_qh_hw *hw = qh->hw; 785 struct ehci_qh_hw *hw = qh->hw;
794 786
795 qh_refresh(ehci, qh);
796 hw->hw_next = EHCI_LIST_END(ehci); 787 hw->hw_next = EHCI_LIST_END(ehci);
797 frame = qh->start; 788 frame = qh->start;
798 789
@@ -844,8 +835,6 @@ static int qh_schedule(struct ehci_hcd *ehci, struct ehci_qh *qh)
844 } else 835 } else
845 ehci_dbg (ehci, "reused qh %p schedule\n", qh); 836 ehci_dbg (ehci, "reused qh %p schedule\n", qh);
846 837
847 /* stuff into the periodic schedule */
848 qh_link_periodic(ehci, qh);
849done: 838done:
850 return status; 839 return status;
851} 840}
@@ -891,6 +880,12 @@ static int intr_submit (
891 qh = qh_append_tds(ehci, urb, qtd_list, epnum, &urb->ep->hcpriv); 880 qh = qh_append_tds(ehci, urb, qtd_list, epnum, &urb->ep->hcpriv);
892 BUG_ON (qh == NULL); 881 BUG_ON (qh == NULL);
893 882
883 /* stuff into the periodic schedule */
884 if (qh->qh_state == QH_STATE_IDLE) {
885 qh_refresh(ehci, qh);
886 qh_link_periodic(ehci, qh);
887 }
888
894 /* ... update usbfs periodic stats */ 889 /* ... update usbfs periodic stats */
895 ehci_to_hcd(ehci)->self.bandwidth_int_reqs++; 890 ehci_to_hcd(ehci)->self.bandwidth_int_reqs++;
896 891
@@ -911,7 +906,7 @@ static void scan_intr(struct ehci_hcd *ehci)
911 906
912 list_for_each_entry_safe(qh, ehci->qh_scan_next, &ehci->intr_qh_list, 907 list_for_each_entry_safe(qh, ehci->qh_scan_next, &ehci->intr_qh_list,
913 intr_node) { 908 intr_node) {
914 rescan: 909
915 /* clean any finished work for this qh */ 910 /* clean any finished work for this qh */
916 if (!list_empty(&qh->qtd_list)) { 911 if (!list_empty(&qh->qtd_list)) {
917 int temp; 912 int temp;
@@ -924,12 +919,9 @@ static void scan_intr(struct ehci_hcd *ehci)
924 * in qh_unlink_periodic(). 919 * in qh_unlink_periodic().
925 */ 920 */
926 temp = qh_completions(ehci, qh); 921 temp = qh_completions(ehci, qh);
927 if (unlikely(qh->needs_rescan || 922 if (unlikely(temp || (list_empty(&qh->qtd_list) &&
928 (list_empty(&qh->qtd_list) && 923 qh->qh_state == QH_STATE_LINKED)))
929 qh->qh_state == QH_STATE_LINKED)))
930 start_unlink_intr(ehci, qh); 924 start_unlink_intr(ehci, qh);
931 else if (temp != 0)
932 goto rescan;
933 } 925 }
934 } 926 }
935} 927}
diff --git a/drivers/usb/host/ehci-sh.c b/drivers/usb/host/ehci-sh.c
index 3565a300f401..b44d716ddc82 100644
--- a/drivers/usb/host/ehci-sh.c
+++ b/drivers/usb/host/ehci-sh.c
@@ -77,7 +77,6 @@ static const struct hc_driver ehci_sh_hc_driver = {
77 77
78static int ehci_hcd_sh_probe(struct platform_device *pdev) 78static int ehci_hcd_sh_probe(struct platform_device *pdev)
79{ 79{
80 const struct hc_driver *driver = &ehci_sh_hc_driver;
81 struct resource *res; 80 struct resource *res;
82 struct ehci_sh_priv *priv; 81 struct ehci_sh_priv *priv;
83 struct ehci_sh_platdata *pdata; 82 struct ehci_sh_platdata *pdata;
@@ -170,7 +169,7 @@ fail_create_hcd:
170 return ret; 169 return ret;
171} 170}
172 171
173static int __exit ehci_hcd_sh_remove(struct platform_device *pdev) 172static int ehci_hcd_sh_remove(struct platform_device *pdev)
174{ 173{
175 struct ehci_sh_priv *priv = platform_get_drvdata(pdev); 174 struct ehci_sh_priv *priv = platform_get_drvdata(pdev);
176 struct usb_hcd *hcd = priv->hcd; 175 struct usb_hcd *hcd = priv->hcd;
@@ -196,7 +195,7 @@ static void ehci_hcd_sh_shutdown(struct platform_device *pdev)
196 195
197static struct platform_driver ehci_hcd_sh_driver = { 196static struct platform_driver ehci_hcd_sh_driver = {
198 .probe = ehci_hcd_sh_probe, 197 .probe = ehci_hcd_sh_probe,
199 .remove = __exit_p(ehci_hcd_sh_remove), 198 .remove = ehci_hcd_sh_remove,
200 .shutdown = ehci_hcd_sh_shutdown, 199 .shutdown = ehci_hcd_sh_shutdown,
201 .driver = { 200 .driver = {
202 .name = "sh_ehci", 201 .name = "sh_ehci",
diff --git a/drivers/usb/host/ehci-spear.c b/drivers/usb/host/ehci-spear.c
index 466c1bb5b967..210bb676f22f 100644
--- a/drivers/usb/host/ehci-spear.c
+++ b/drivers/usb/host/ehci-spear.c
@@ -78,7 +78,7 @@ static const struct hc_driver ehci_spear_hc_driver = {
78 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, 78 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
79}; 79};
80 80
81#ifdef CONFIG_PM 81#ifdef CONFIG_PM_SLEEP
82static int ehci_spear_drv_suspend(struct device *dev) 82static int ehci_spear_drv_suspend(struct device *dev)
83{ 83{
84 struct usb_hcd *hcd = dev_get_drvdata(dev); 84 struct usb_hcd *hcd = dev_get_drvdata(dev);
@@ -94,7 +94,7 @@ static int ehci_spear_drv_resume(struct device *dev)
94 ehci_resume(hcd, false); 94 ehci_resume(hcd, false);
95 return 0; 95 return 0;
96} 96}
97#endif /* CONFIG_PM */ 97#endif /* CONFIG_PM_SLEEP */
98 98
99static SIMPLE_DEV_PM_OPS(ehci_spear_pm_ops, ehci_spear_drv_suspend, 99static SIMPLE_DEV_PM_OPS(ehci_spear_pm_ops, ehci_spear_drv_suspend,
100 ehci_spear_drv_resume); 100 ehci_spear_drv_resume);
diff --git a/drivers/usb/host/ehci-tegra.c b/drivers/usb/host/ehci-tegra.c
index 568aecc7075b..ed201ae879cb 100644
--- a/drivers/usb/host/ehci-tegra.c
+++ b/drivers/usb/host/ehci-tegra.c
@@ -28,6 +28,7 @@
28#include <linux/pm_runtime.h> 28#include <linux/pm_runtime.h>
29#include <linux/usb/ehci_def.h> 29#include <linux/usb/ehci_def.h>
30#include <linux/usb/tegra_usb_phy.h> 30#include <linux/usb/tegra_usb_phy.h>
31#include <linux/clk/tegra.h>
31 32
32#define TEGRA_USB_BASE 0xC5000000 33#define TEGRA_USB_BASE 0xC5000000
33#define TEGRA_USB2_BASE 0xC5004000 34#define TEGRA_USB2_BASE 0xC5004000
@@ -691,6 +692,10 @@ static int tegra_ehci_probe(struct platform_device *pdev)
691 if (err) 692 if (err)
692 goto fail_clk; 693 goto fail_clk;
693 694
695 tegra_periph_reset_assert(tegra->clk);
696 udelay(1);
697 tegra_periph_reset_deassert(tegra->clk);
698
694 tegra->needs_double_reset = of_property_read_bool(pdev->dev.of_node, 699 tegra->needs_double_reset = of_property_read_bool(pdev->dev.of_node,
695 "nvidia,needs-double-reset"); 700 "nvidia,needs-double-reset");
696 701
@@ -755,7 +760,7 @@ static int tegra_ehci_probe(struct platform_device *pdev)
755 err = usb_phy_set_suspend(hcd->phy, 0); 760 err = usb_phy_set_suspend(hcd->phy, 0);
756 if (err) { 761 if (err) {
757 dev_err(&pdev->dev, "Failed to power on the phy\n"); 762 dev_err(&pdev->dev, "Failed to power on the phy\n");
758 goto fail; 763 goto fail_phy;
759 } 764 }
760 765
761 tegra->host_resumed = 1; 766 tegra->host_resumed = 1;
@@ -765,17 +770,17 @@ static int tegra_ehci_probe(struct platform_device *pdev)
765 if (!irq) { 770 if (!irq) {
766 dev_err(&pdev->dev, "Failed to get IRQ\n"); 771 dev_err(&pdev->dev, "Failed to get IRQ\n");
767 err = -ENODEV; 772 err = -ENODEV;
768 goto fail; 773 goto fail_phy;
769 } 774 }
770 775
771#ifdef CONFIG_USB_OTG_UTILS
772 if (pdata->operating_mode == TEGRA_USB_OTG) { 776 if (pdata->operating_mode == TEGRA_USB_OTG) {
773 tegra->transceiver = 777 tegra->transceiver =
774 devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); 778 devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
775 if (!IS_ERR_OR_NULL(tegra->transceiver)) 779 if (!IS_ERR(tegra->transceiver))
776 otg_set_host(tegra->transceiver->otg, &hcd->self); 780 otg_set_host(tegra->transceiver->otg, &hcd->self);
781 } else {
782 tegra->transceiver = ERR_PTR(-ENODEV);
777 } 783 }
778#endif
779 784
780 err = usb_add_hcd(hcd, irq, IRQF_SHARED); 785 err = usb_add_hcd(hcd, irq, IRQF_SHARED);
781 if (err) { 786 if (err) {
@@ -794,10 +799,9 @@ static int tegra_ehci_probe(struct platform_device *pdev)
794 return err; 799 return err;
795 800
796fail: 801fail:
797#ifdef CONFIG_USB_OTG_UTILS 802 if (!IS_ERR(tegra->transceiver))
798 if (!IS_ERR_OR_NULL(tegra->transceiver))
799 otg_set_host(tegra->transceiver->otg, NULL); 803 otg_set_host(tegra->transceiver->otg, NULL);
800#endif 804fail_phy:
801 usb_phy_shutdown(hcd->phy); 805 usb_phy_shutdown(hcd->phy);
802fail_io: 806fail_io:
803 clk_disable_unprepare(tegra->clk); 807 clk_disable_unprepare(tegra->clk);
@@ -815,10 +819,8 @@ static int tegra_ehci_remove(struct platform_device *pdev)
815 pm_runtime_disable(&pdev->dev); 819 pm_runtime_disable(&pdev->dev);
816 pm_runtime_put_noidle(&pdev->dev); 820 pm_runtime_put_noidle(&pdev->dev);
817 821
818#ifdef CONFIG_USB_OTG_UTILS 822 if (!IS_ERR(tegra->transceiver))
819 if (!IS_ERR_OR_NULL(tegra->transceiver))
820 otg_set_host(tegra->transceiver->otg, NULL); 823 otg_set_host(tegra->transceiver->otg, NULL);
821#endif
822 824
823 usb_phy_shutdown(hcd->phy); 825 usb_phy_shutdown(hcd->phy);
824 usb_remove_hcd(hcd); 826 usb_remove_hcd(hcd);
diff --git a/drivers/usb/host/ehci-timer.c b/drivers/usb/host/ehci-timer.c
index c3fa1305f830..11e5b32f73e9 100644
--- a/drivers/usb/host/ehci-timer.c
+++ b/drivers/usb/host/ehci-timer.c
@@ -113,8 +113,8 @@ static void ehci_poll_ASS(struct ehci_hcd *ehci)
113 113
114 if (want != actual) { 114 if (want != actual) {
115 115
116 /* Poll again later, but give up after about 20 ms */ 116 /* Poll again later, but give up after about 2-4 ms */
117 if (ehci->ASS_poll_count++ < 20) { 117 if (ehci->ASS_poll_count++ < 2) {
118 ehci_enable_event(ehci, EHCI_HRTIMER_POLL_ASS, true); 118 ehci_enable_event(ehci, EHCI_HRTIMER_POLL_ASS, true);
119 return; 119 return;
120 } 120 }
@@ -159,8 +159,8 @@ static void ehci_poll_PSS(struct ehci_hcd *ehci)
159 159
160 if (want != actual) { 160 if (want != actual) {
161 161
162 /* Poll again later, but give up after about 20 ms */ 162 /* Poll again later, but give up after about 2-4 ms */
163 if (ehci->PSS_poll_count++ < 20) { 163 if (ehci->PSS_poll_count++ < 2) {
164 ehci_enable_event(ehci, EHCI_HRTIMER_POLL_PSS, true); 164 ehci_enable_event(ehci, EHCI_HRTIMER_POLL_PSS, true);
165 return; 165 return;
166 } 166 }
@@ -229,18 +229,19 @@ static void ehci_handle_intr_unlinks(struct ehci_hcd *ehci)
229 * process all the QHs on the list. 229 * process all the QHs on the list.
230 */ 230 */
231 ehci->intr_unlinking = true; 231 ehci->intr_unlinking = true;
232 while (ehci->intr_unlink) { 232 while (!list_empty(&ehci->intr_unlink)) {
233 struct ehci_qh *qh = ehci->intr_unlink; 233 struct ehci_qh *qh;
234 234
235 qh = list_first_entry(&ehci->intr_unlink, struct ehci_qh,
236 unlink_node);
235 if (!stopped && qh->unlink_cycle == ehci->intr_unlink_cycle) 237 if (!stopped && qh->unlink_cycle == ehci->intr_unlink_cycle)
236 break; 238 break;
237 ehci->intr_unlink = qh->unlink_next; 239 list_del(&qh->unlink_node);
238 qh->unlink_next = NULL;
239 end_unlink_intr(ehci, qh); 240 end_unlink_intr(ehci, qh);
240 } 241 }
241 242
242 /* Handle remaining entries later */ 243 /* Handle remaining entries later */
243 if (ehci->intr_unlink) { 244 if (!list_empty(&ehci->intr_unlink)) {
244 ehci_enable_event(ehci, EHCI_HRTIMER_UNLINK_INTR, true); 245 ehci_enable_event(ehci, EHCI_HRTIMER_UNLINK_INTR, true);
245 ++ehci->intr_unlink_cycle; 246 ++ehci->intr_unlink_cycle;
246 } 247 }
@@ -295,8 +296,7 @@ static void end_free_itds(struct ehci_hcd *ehci)
295/* Handle lost (or very late) IAA interrupts */ 296/* Handle lost (or very late) IAA interrupts */
296static void ehci_iaa_watchdog(struct ehci_hcd *ehci) 297static void ehci_iaa_watchdog(struct ehci_hcd *ehci)
297{ 298{
298 if (ehci->rh_state != EHCI_RH_RUNNING) 299 u32 cmd, status;
299 return;
300 300
301 /* 301 /*
302 * Lost IAA irqs wedge things badly; seen first with a vt8235. 302 * Lost IAA irqs wedge things badly; seen first with a vt8235.
@@ -304,34 +304,32 @@ static void ehci_iaa_watchdog(struct ehci_hcd *ehci)
304 * (a) SMP races against real IAA firing and retriggering, and 304 * (a) SMP races against real IAA firing and retriggering, and
305 * (b) clean HC shutdown, when IAA watchdog was pending. 305 * (b) clean HC shutdown, when IAA watchdog was pending.
306 */ 306 */
307 if (1) { 307 if (!ehci->iaa_in_progress || ehci->rh_state != EHCI_RH_RUNNING)
308 u32 cmd, status; 308 return;
309 309
310 /* If we get here, IAA is *REALLY* late. It's barely 310 /* If we get here, IAA is *REALLY* late. It's barely
311 * conceivable that the system is so busy that CMD_IAAD 311 * conceivable that the system is so busy that CMD_IAAD
312 * is still legitimately set, so let's be sure it's 312 * is still legitimately set, so let's be sure it's
313 * clear before we read STS_IAA. (The HC should clear 313 * clear before we read STS_IAA. (The HC should clear
314 * CMD_IAAD when it sets STS_IAA.) 314 * CMD_IAAD when it sets STS_IAA.)
315 */ 315 */
316 cmd = ehci_readl(ehci, &ehci->regs->command); 316 cmd = ehci_readl(ehci, &ehci->regs->command);
317
318 /*
319 * If IAA is set here it either legitimately triggered
320 * after the watchdog timer expired (_way_ late, so we'll
321 * still count it as lost) ... or a silicon erratum:
322 * - VIA seems to set IAA without triggering the IRQ;
323 * - IAAD potentially cleared without setting IAA.
324 */
325 status = ehci_readl(ehci, &ehci->regs->status);
326 if ((status & STS_IAA) || !(cmd & CMD_IAAD)) {
327 COUNT(ehci->stats.lost_iaa);
328 ehci_writel(ehci, STS_IAA, &ehci->regs->status);
329 }
330 317
331 ehci_vdbg(ehci, "IAA watchdog: status %x cmd %x\n", 318 /*
332 status, cmd); 319 * If IAA is set here it either legitimately triggered
333 end_unlink_async(ehci); 320 * after the watchdog timer expired (_way_ late, so we'll
321 * still count it as lost) ... or a silicon erratum:
322 * - VIA seems to set IAA without triggering the IRQ;
323 * - IAAD potentially cleared without setting IAA.
324 */
325 status = ehci_readl(ehci, &ehci->regs->status);
326 if ((status & STS_IAA) || !(cmd & CMD_IAAD)) {
327 COUNT(ehci->stats.lost_iaa);
328 ehci_writel(ehci, STS_IAA, &ehci->regs->status);
334 } 329 }
330
331 ehci_dbg(ehci, "IAA watchdog: status %x cmd %x\n", status, cmd);
332 end_unlink_async(ehci);
335} 333}
336 334
337 335
diff --git a/drivers/usb/host/ehci-vt8500.c b/drivers/usb/host/ehci-vt8500.c
deleted file mode 100644
index 7ecf709610ba..000000000000
--- a/drivers/usb/host/ehci-vt8500.c
+++ /dev/null
@@ -1,150 +0,0 @@
1/*
2 * drivers/usb/host/ehci-vt8500.c
3 *
4 * Copyright (C) 2010 Alexey Charkov <alchark@gmail.com>
5 *
6 * Based on ehci-au1xxx.c
7 *
8 * This software is licensed under the terms of the GNU General Public
9 * License version 2, as published by the Free Software Foundation, and
10 * may be copied, distributed, and modified under those terms.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 */
18
19#include <linux/err.h>
20#include <linux/of.h>
21#include <linux/platform_device.h>
22
23static const struct hc_driver vt8500_ehci_hc_driver = {
24 .description = hcd_name,
25 .product_desc = "VT8500 EHCI",
26 .hcd_priv_size = sizeof(struct ehci_hcd),
27
28 /*
29 * generic hardware linkage
30 */
31 .irq = ehci_irq,
32 .flags = HCD_MEMORY | HCD_USB2,
33
34 /*
35 * basic lifecycle operations
36 */
37 .reset = ehci_setup,
38 .start = ehci_run,
39 .stop = ehci_stop,
40 .shutdown = ehci_shutdown,
41
42 /*
43 * managing i/o requests and associated device resources
44 */
45 .urb_enqueue = ehci_urb_enqueue,
46 .urb_dequeue = ehci_urb_dequeue,
47 .endpoint_disable = ehci_endpoint_disable,
48 .endpoint_reset = ehci_endpoint_reset,
49
50 /*
51 * scheduling support
52 */
53 .get_frame_number = ehci_get_frame,
54
55 /*
56 * root hub support
57 */
58 .hub_status_data = ehci_hub_status_data,
59 .hub_control = ehci_hub_control,
60 .bus_suspend = ehci_bus_suspend,
61 .bus_resume = ehci_bus_resume,
62 .relinquish_port = ehci_relinquish_port,
63 .port_handed_over = ehci_port_handed_over,
64
65 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
66};
67
68static u64 vt8500_ehci_dma_mask = DMA_BIT_MASK(32);
69
70static int vt8500_ehci_drv_probe(struct platform_device *pdev)
71{
72 struct usb_hcd *hcd;
73 struct ehci_hcd *ehci;
74 struct resource *res;
75 int ret;
76
77 if (usb_disabled())
78 return -ENODEV;
79
80 /*
81 * Right now device-tree probed devices don't get dma_mask set.
82 * Since shared usb code relies on it, set it here for now.
83 * Once we have dma capability bindings this can go away.
84 */
85 if (!pdev->dev.dma_mask)
86 pdev->dev.dma_mask = &vt8500_ehci_dma_mask;
87
88 if (pdev->resource[1].flags != IORESOURCE_IRQ) {
89 pr_debug("resource[1] is not IORESOURCE_IRQ");
90 return -ENOMEM;
91 }
92 hcd = usb_create_hcd(&vt8500_ehci_hc_driver, &pdev->dev, "VT8500");
93 if (!hcd)
94 return -ENOMEM;
95
96 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
97 hcd->rsrc_start = res->start;
98 hcd->rsrc_len = resource_size(res);
99
100 hcd->regs = devm_ioremap_resource(&pdev->dev, res);
101 if (IS_ERR(hcd->regs)) {
102 ret = PTR_ERR(hcd->regs);
103 goto err1;
104 }
105
106 ehci = hcd_to_ehci(hcd);
107 ehci->caps = hcd->regs;
108
109 ret = usb_add_hcd(hcd, pdev->resource[1].start,
110 IRQF_SHARED);
111 if (ret == 0) {
112 platform_set_drvdata(pdev, hcd);
113 return ret;
114 }
115
116err1:
117 usb_put_hcd(hcd);
118 return ret;
119}
120
121static int vt8500_ehci_drv_remove(struct platform_device *pdev)
122{
123 struct usb_hcd *hcd = platform_get_drvdata(pdev);
124
125 usb_remove_hcd(hcd);
126 usb_put_hcd(hcd);
127 platform_set_drvdata(pdev, NULL);
128
129 return 0;
130}
131
132static const struct of_device_id vt8500_ehci_ids[] = {
133 { .compatible = "via,vt8500-ehci", },
134 { .compatible = "wm,prizm-ehci", },
135 {}
136};
137
138static struct platform_driver vt8500_ehci_driver = {
139 .probe = vt8500_ehci_drv_probe,
140 .remove = vt8500_ehci_drv_remove,
141 .shutdown = usb_hcd_platform_shutdown,
142 .driver = {
143 .name = "vt8500-ehci",
144 .owner = THIS_MODULE,
145 .of_match_table = of_match_ptr(vt8500_ehci_ids),
146 }
147};
148
149MODULE_ALIAS("platform:vt8500-ehci");
150MODULE_DEVICE_TABLE(of, vt8500_ehci_ids);
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h
index 36c3a8210595..7c978b23520d 100644
--- a/drivers/usb/host/ehci.h
+++ b/drivers/usb/host/ehci.h
@@ -121,6 +121,7 @@ struct ehci_hcd { /* one per controller */
121 bool scanning:1; 121 bool scanning:1;
122 bool need_rescan:1; 122 bool need_rescan:1;
123 bool intr_unlinking:1; 123 bool intr_unlinking:1;
124 bool iaa_in_progress:1;
124 bool async_unlinking:1; 125 bool async_unlinking:1;
125 bool shutdown:1; 126 bool shutdown:1;
126 struct ehci_qh *qh_scan_next; 127 struct ehci_qh *qh_scan_next;
@@ -128,9 +129,8 @@ struct ehci_hcd { /* one per controller */
128 /* async schedule support */ 129 /* async schedule support */
129 struct ehci_qh *async; 130 struct ehci_qh *async;
130 struct ehci_qh *dummy; /* For AMD quirk use */ 131 struct ehci_qh *dummy; /* For AMD quirk use */
131 struct ehci_qh *async_unlink; 132 struct list_head async_unlink;
132 struct ehci_qh *async_unlink_last; 133 struct list_head async_idle;
133 struct ehci_qh *async_iaa;
134 unsigned async_unlink_cycle; 134 unsigned async_unlink_cycle;
135 unsigned async_count; /* async activity count */ 135 unsigned async_count; /* async activity count */
136 136
@@ -143,8 +143,7 @@ struct ehci_hcd { /* one per controller */
143 unsigned i_thresh; /* uframes HC might cache */ 143 unsigned i_thresh; /* uframes HC might cache */
144 144
145 union ehci_shadow *pshadow; /* mirror hw periodic table */ 145 union ehci_shadow *pshadow; /* mirror hw periodic table */
146 struct ehci_qh *intr_unlink; 146 struct list_head intr_unlink;
147 struct ehci_qh *intr_unlink_last;
148 unsigned intr_unlink_cycle; 147 unsigned intr_unlink_cycle;
149 unsigned now_frame; /* frame from HC hardware */ 148 unsigned now_frame; /* frame from HC hardware */
150 unsigned last_iso_frame; /* last frame scanned for iso */ 149 unsigned last_iso_frame; /* last frame scanned for iso */
@@ -200,6 +199,7 @@ struct ehci_hcd { /* one per controller */
200 unsigned use_dummy_qh:1; /* AMD Frame List table quirk*/ 199 unsigned use_dummy_qh:1; /* AMD Frame List table quirk*/
201 unsigned has_synopsys_hc_bug:1; /* Synopsys HC */ 200 unsigned has_synopsys_hc_bug:1; /* Synopsys HC */
202 unsigned frame_index_bug:1; /* MosChip (AKA NetMos) */ 201 unsigned frame_index_bug:1; /* MosChip (AKA NetMos) */
202 unsigned need_oc_pp_cycle:1; /* MPC834X port power */
203 203
204 /* required for usb32 quirk */ 204 /* required for usb32 quirk */
205 #define OHCI_CTRL_HCFS (3 << 6) 205 #define OHCI_CTRL_HCFS (3 << 6)
@@ -380,11 +380,10 @@ struct ehci_qh {
380 struct list_head qtd_list; /* sw qtd list */ 380 struct list_head qtd_list; /* sw qtd list */
381 struct list_head intr_node; /* list of intr QHs */ 381 struct list_head intr_node; /* list of intr QHs */
382 struct ehci_qtd *dummy; 382 struct ehci_qtd *dummy;
383 struct ehci_qh *unlink_next; /* next on unlink list */ 383 struct list_head unlink_node;
384 384
385 unsigned unlink_cycle; 385 unsigned unlink_cycle;
386 386
387 u8 needs_rescan; /* Dequeue during giveback */
388 u8 qh_state; 387 u8 qh_state;
389#define QH_STATE_LINKED 1 /* HC sees this */ 388#define QH_STATE_LINKED 1 /* HC sees this */
390#define QH_STATE_UNLINK 2 /* HC may still see this */ 389#define QH_STATE_UNLINK 2 /* HC may still see this */
@@ -407,6 +406,9 @@ struct ehci_qh {
407 struct usb_device *dev; /* access to TT */ 406 struct usb_device *dev; /* access to TT */
408 unsigned is_out:1; /* bulk or intr OUT */ 407 unsigned is_out:1; /* bulk or intr OUT */
409 unsigned clearing_tt:1; /* Clear-TT-Buf in progress */ 408 unsigned clearing_tt:1; /* Clear-TT-Buf in progress */
409 unsigned dequeue_during_giveback:1;
410 unsigned exception:1; /* got a fault, or an unlink
411 was requested */
410}; 412};
411 413
412/*-------------------------------------------------------------------------*/ 414/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/host/ohci-exynos.c b/drivers/usb/host/ohci-exynos.c
index e3b7e85120e4..4b469e050208 100644
--- a/drivers/usb/host/ohci-exynos.c
+++ b/drivers/usb/host/ohci-exynos.c
@@ -128,7 +128,7 @@ static int exynos_ohci_probe(struct platform_device *pdev)
128 return -ENOMEM; 128 return -ENOMEM;
129 129
130 phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); 130 phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
131 if (IS_ERR_OR_NULL(phy)) { 131 if (IS_ERR(phy)) {
132 /* Fallback to pdata */ 132 /* Fallback to pdata */
133 if (!pdata) { 133 if (!pdata) {
134 dev_warn(&pdev->dev, "no platform data or transceiver defined\n"); 134 dev_warn(&pdev->dev, "no platform data or transceiver defined\n");
diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c
index db09dae7b557..60ff4220e8b4 100644
--- a/drivers/usb/host/ohci-hub.c
+++ b/drivers/usb/host/ohci-hub.c
@@ -580,14 +580,8 @@ static int ohci_start_port_reset (struct usb_hcd *hcd, unsigned port)
580 580
581/* See usb 7.1.7.5: root hubs must issue at least 50 msec reset signaling, 581/* See usb 7.1.7.5: root hubs must issue at least 50 msec reset signaling,
582 * not necessarily continuous ... to guard against resume signaling. 582 * not necessarily continuous ... to guard against resume signaling.
583 * The short timeout is safe for non-root hubs, and is backward-compatible
584 * with earlier Linux hosts.
585 */ 583 */
586#ifdef CONFIG_USB_SUSPEND
587#define PORT_RESET_MSEC 50 584#define PORT_RESET_MSEC 50
588#else
589#define PORT_RESET_MSEC 10
590#endif
591 585
592/* this timer value might be vendor-specific ... */ 586/* this timer value might be vendor-specific ... */
593#define PORT_RESET_HW_MSEC 10 587#define PORT_RESET_HW_MSEC 10
diff --git a/drivers/usb/host/ohci-omap3.c b/drivers/usb/host/ohci-omap3.c
index eb35d9630237..ddfc31427bc0 100644
--- a/drivers/usb/host/ohci-omap3.c
+++ b/drivers/usb/host/ohci-omap3.c
@@ -31,6 +31,8 @@
31 31
32#include <linux/platform_device.h> 32#include <linux/platform_device.h>
33#include <linux/pm_runtime.h> 33#include <linux/pm_runtime.h>
34#include <linux/of.h>
35#include <linux/dma-mapping.h>
34 36
35/*-------------------------------------------------------------------------*/ 37/*-------------------------------------------------------------------------*/
36 38
@@ -112,6 +114,8 @@ static const struct hc_driver ohci_omap3_hc_driver = {
112 114
113/*-------------------------------------------------------------------------*/ 115/*-------------------------------------------------------------------------*/
114 116
117static u64 omap_ohci_dma_mask = DMA_BIT_MASK(32);
118
115/* 119/*
116 * configure so an HC device and id are always provided 120 * configure so an HC device and id are always provided
117 * always called with process context; sleeping is OK 121 * always called with process context; sleeping is OK
@@ -141,14 +145,13 @@ static int ohci_hcd_omap3_probe(struct platform_device *pdev)
141 return -ENODEV; 145 return -ENODEV;
142 } 146 }
143 147
144 irq = platform_get_irq_byname(pdev, "ohci-irq"); 148 irq = platform_get_irq(pdev, 0);
145 if (irq < 0) { 149 if (irq < 0) {
146 dev_err(dev, "OHCI irq failed\n"); 150 dev_err(dev, "OHCI irq failed\n");
147 return -ENODEV; 151 return -ENODEV;
148 } 152 }
149 153
150 res = platform_get_resource_byname(pdev, 154 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
151 IORESOURCE_MEM, "ohci");
152 if (!res) { 155 if (!res) {
153 dev_err(dev, "UHH OHCI get resource failed\n"); 156 dev_err(dev, "UHH OHCI get resource failed\n");
154 return -ENOMEM; 157 return -ENOMEM;
@@ -160,6 +163,13 @@ static int ohci_hcd_omap3_probe(struct platform_device *pdev)
160 return -ENOMEM; 163 return -ENOMEM;
161 } 164 }
162 165
166 /*
167 * Right now device-tree probed devices don't get dma_mask set.
168 * Since shared usb code relies on it, set it here for now.
169 * Once we have dma capability bindings this can go away.
170 */
171 if (!pdev->dev.dma_mask)
172 pdev->dev.dma_mask = &omap_ohci_dma_mask;
163 173
164 hcd = usb_create_hcd(&ohci_omap3_hc_driver, dev, 174 hcd = usb_create_hcd(&ohci_omap3_hc_driver, dev,
165 dev_name(dev)); 175 dev_name(dev));
@@ -229,12 +239,20 @@ static void ohci_hcd_omap3_shutdown(struct platform_device *pdev)
229 hcd->driver->shutdown(hcd); 239 hcd->driver->shutdown(hcd);
230} 240}
231 241
242static const struct of_device_id omap_ohci_dt_ids[] = {
243 { .compatible = "ti,ohci-omap3" },
244 { }
245};
246
247MODULE_DEVICE_TABLE(of, omap_ohci_dt_ids);
248
232static struct platform_driver ohci_hcd_omap3_driver = { 249static struct platform_driver ohci_hcd_omap3_driver = {
233 .probe = ohci_hcd_omap3_probe, 250 .probe = ohci_hcd_omap3_probe,
234 .remove = ohci_hcd_omap3_remove, 251 .remove = ohci_hcd_omap3_remove,
235 .shutdown = ohci_hcd_omap3_shutdown, 252 .shutdown = ohci_hcd_omap3_shutdown,
236 .driver = { 253 .driver = {
237 .name = "ohci-omap3", 254 .name = "ohci-omap3",
255 .of_match_table = of_match_ptr(omap_ohci_dt_ids),
238 }, 256 },
239}; 257};
240 258
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c
index d62f0404baaa..15ed7e8d887f 100644
--- a/drivers/usb/host/sl811-hcd.c
+++ b/drivers/usb/host/sl811-hcd.c
@@ -1755,7 +1755,7 @@ sl811h_probe(struct platform_device *dev)
1755 1755
1756/* for this device there's no useful distinction between the controller 1756/* for this device there's no useful distinction between the controller
1757 * and its root hub, except that the root hub only gets direct PM calls 1757 * and its root hub, except that the root hub only gets direct PM calls
1758 * when CONFIG_USB_SUSPEND is enabled. 1758 * when CONFIG_PM_RUNTIME is enabled.
1759 */ 1759 */
1760 1760
1761static int 1761static int
diff --git a/drivers/usb/host/u132-hcd.c b/drivers/usb/host/u132-hcd.c
index 5efdffe32365..5c124bf5d018 100644
--- a/drivers/usb/host/u132-hcd.c
+++ b/drivers/usb/host/u132-hcd.c
@@ -3141,10 +3141,11 @@ static int u132_probe(struct platform_device *pdev)
3141 3141
3142 3142
3143#ifdef CONFIG_PM 3143#ifdef CONFIG_PM
3144/* for this device there's no useful distinction between the controller 3144/*
3145* and its root hub, except that the root hub only gets direct PM calls 3145 * for this device there's no useful distinction between the controller
3146* when CONFIG_USB_SUSPEND is enabled. 3146 * and its root hub, except that the root hub only gets direct PM calls
3147*/ 3147 * when CONFIG_PM_RUNTIME is enabled.
3148 */
3148static int u132_suspend(struct platform_device *pdev, pm_message_t state) 3149static int u132_suspend(struct platform_device *pdev, pm_message_t state)
3149{ 3150{
3150 struct usb_hcd *hcd = platform_get_drvdata(pdev); 3151 struct usb_hcd *hcd = platform_get_drvdata(pdev);
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 68914429482f..187a3ec1069a 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -1075,7 +1075,7 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
1075 set_bit(port_index, &bus_state->bus_suspended); 1075 set_bit(port_index, &bus_state->bus_suspended);
1076 } 1076 }
1077 /* USB core sets remote wake mask for USB 3.0 hubs, 1077 /* USB core sets remote wake mask for USB 3.0 hubs,
1078 * including the USB 3.0 roothub, but only if CONFIG_USB_SUSPEND 1078 * including the USB 3.0 roothub, but only if CONFIG_PM_RUNTIME
1079 * is enabled, so also enable remote wake here. 1079 * is enabled, so also enable remote wake here.
1080 */ 1080 */
1081 if (hcd->self.root_hub->do_remote_wakeup) { 1081 if (hcd->self.root_hub->do_remote_wakeup) {
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 53b8f89a0b1c..5156b720a53a 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -3801,7 +3801,7 @@ int xhci_find_raw_port_number(struct usb_hcd *hcd, int port1)
3801 return raw_port; 3801 return raw_port;
3802} 3802}
3803 3803
3804#ifdef CONFIG_USB_SUSPEND 3804#ifdef CONFIG_PM_RUNTIME
3805 3805
3806/* BESL to HIRD Encoding array for USB2 LPM */ 3806/* BESL to HIRD Encoding array for USB2 LPM */
3807static int xhci_besl_encoding[16] = {125, 150, 200, 300, 400, 500, 1000, 2000, 3807static int xhci_besl_encoding[16] = {125, 150, 200, 300, 400, 500, 1000, 2000,
@@ -4051,7 +4051,7 @@ int xhci_update_device(struct usb_hcd *hcd, struct usb_device *udev)
4051 return 0; 4051 return 0;
4052} 4052}
4053 4053
4054#endif /* CONFIG_USB_SUSPEND */ 4054#endif /* CONFIG_PM_RUNTIME */
4055 4055
4056/*---------------------- USB 3.0 Link PM functions ------------------------*/ 4056/*---------------------- USB 3.0 Link PM functions ------------------------*/
4057 4057
diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
index 0fc6e5fc745f..ba6a5d6e618e 100644
--- a/drivers/usb/misc/appledisplay.c
+++ b/drivers/usb/misc/appledisplay.c
@@ -63,6 +63,7 @@ static const struct usb_device_id appledisplay_table[] = {
63 { APPLEDISPLAY_DEVICE(0x9219) }, 63 { APPLEDISPLAY_DEVICE(0x9219) },
64 { APPLEDISPLAY_DEVICE(0x921c) }, 64 { APPLEDISPLAY_DEVICE(0x921c) },
65 { APPLEDISPLAY_DEVICE(0x921d) }, 65 { APPLEDISPLAY_DEVICE(0x921d) },
66 { APPLEDISPLAY_DEVICE(0x9236) },
66 67
67 /* Terminating entry */ 68 /* Terminating entry */
68 { } 69 { }
diff --git a/drivers/usb/misc/sisusbvga/sisusb.c b/drivers/usb/misc/sisusbvga/sisusb.c
index dd573abd2d1e..c21386ec5d35 100644
--- a/drivers/usb/misc/sisusbvga/sisusb.c
+++ b/drivers/usb/misc/sisusbvga/sisusb.c
@@ -3084,7 +3084,7 @@ static int sisusb_probe(struct usb_interface *intf,
3084 3084
3085 /* Allocate memory for our private */ 3085 /* Allocate memory for our private */
3086 if (!(sisusb = kzalloc(sizeof(*sisusb), GFP_KERNEL))) { 3086 if (!(sisusb = kzalloc(sizeof(*sisusb), GFP_KERNEL))) {
3087 dev_err(&sisusb->sisusb_dev->dev, "Failed to allocate memory for private data\n"); 3087 dev_err(&dev->dev, "Failed to allocate memory for private data\n");
3088 return -ENOMEM; 3088 return -ENOMEM;
3089 } 3089 }
3090 kref_init(&sisusb->kref); 3090 kref_init(&sisusb->kref);
diff --git a/drivers/usb/misc/usb3503.c b/drivers/usb/misc/usb3503.c
index f713f6aeb6e5..d3a1cce1bf9c 100644
--- a/drivers/usb/misc/usb3503.c
+++ b/drivers/usb/misc/usb3503.c
@@ -307,18 +307,7 @@ static struct i2c_driver usb3503_driver = {
307 .id_table = usb3503_id, 307 .id_table = usb3503_id,
308}; 308};
309 309
310static int __init usb3503_init(void) 310module_i2c_driver(usb3503_driver);
311{
312 return i2c_add_driver(&usb3503_driver);
313}
314
315static void __exit usb3503_exit(void)
316{
317 i2c_del_driver(&usb3503_driver);
318}
319
320module_init(usb3503_init);
321module_exit(usb3503_exit);
322 311
323MODULE_AUTHOR("Dongjin Kim <tobetter@gmail.com>"); 312MODULE_AUTHOR("Dongjin Kim <tobetter@gmail.com>");
324MODULE_DESCRIPTION("USB3503 USB HUB driver"); 313MODULE_DESCRIPTION("USB3503 USB HUB driver");
diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
index 05e51432dd2f..47442d35b6fc 100644
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -7,7 +7,6 @@
7config USB_MUSB_HDRC 7config USB_MUSB_HDRC
8 tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, ...)' 8 tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, ...)'
9 depends on USB && USB_GADGET 9 depends on USB && USB_GADGET
10 select USB_OTG_UTILS
11 help 10 help
12 Say Y here if your system has a dual role high speed USB 11 Say Y here if your system has a dual role high speed USB
13 controller based on the Mentor Graphics silicon IP. Then 12 controller based on the Mentor Graphics silicon IP. Then
@@ -34,10 +33,12 @@ choice
34config USB_MUSB_DAVINCI 33config USB_MUSB_DAVINCI
35 tristate "DaVinci" 34 tristate "DaVinci"
36 depends on ARCH_DAVINCI_DMx 35 depends on ARCH_DAVINCI_DMx
36 depends on BROKEN
37 37
38config USB_MUSB_DA8XX 38config USB_MUSB_DA8XX
39 tristate "DA8xx/OMAP-L1x" 39 tristate "DA8xx/OMAP-L1x"
40 depends on ARCH_DAVINCI_DA8XX 40 depends on ARCH_DAVINCI_DA8XX
41 depends on BROKEN
41 42
42config USB_MUSB_TUSB6010 43config USB_MUSB_TUSB6010
43 tristate "TUSB6010" 44 tristate "TUSB6010"
@@ -53,7 +54,6 @@ config USB_MUSB_AM35X
53 54
54config USB_MUSB_DSPS 55config USB_MUSB_DSPS
55 tristate "TI DSPS platforms" 56 tristate "TI DSPS platforms"
56 depends on SOC_TI81XX || SOC_AM33XX
57 57
58config USB_MUSB_BLACKFIN 58config USB_MUSB_BLACKFIN
59 tristate "Blackfin" 59 tristate "Blackfin"
@@ -61,12 +61,12 @@ config USB_MUSB_BLACKFIN
61 61
62config USB_MUSB_UX500 62config USB_MUSB_UX500
63 tristate "U8500 and U5500" 63 tristate "U8500 and U5500"
64 depends on (ARCH_U8500 && AB8500_USB)
65 64
66endchoice 65endchoice
67 66
68choice 67choice
69 prompt 'MUSB DMA mode' 68 prompt 'MUSB DMA mode'
69 default MUSB_PIO_ONLY if ARCH_MULTIPLATFORM
70 default USB_UX500_DMA if USB_MUSB_UX500 70 default USB_UX500_DMA if USB_MUSB_UX500
71 default USB_INVENTRA_DMA if USB_MUSB_OMAP2PLUS || USB_MUSB_BLACKFIN 71 default USB_INVENTRA_DMA if USB_MUSB_OMAP2PLUS || USB_MUSB_BLACKFIN
72 default USB_TI_CPPI_DMA if USB_MUSB_DAVINCI 72 default USB_TI_CPPI_DMA if USB_MUSB_DAVINCI
diff --git a/drivers/usb/musb/am35x.c b/drivers/usb/musb/am35x.c
index 59eea219034a..2231850c0625 100644
--- a/drivers/usb/musb/am35x.c
+++ b/drivers/usb/musb/am35x.c
@@ -149,7 +149,7 @@ static void otg_timer(unsigned long _musb)
149 */ 149 */
150 devctl = musb_readb(mregs, MUSB_DEVCTL); 150 devctl = musb_readb(mregs, MUSB_DEVCTL);
151 dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl, 151 dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl,
152 otg_state_string(musb->xceiv->state)); 152 usb_otg_state_string(musb->xceiv->state));
153 153
154 spin_lock_irqsave(&musb->lock, flags); 154 spin_lock_irqsave(&musb->lock, flags);
155 switch (musb->xceiv->state) { 155 switch (musb->xceiv->state) {
@@ -195,7 +195,7 @@ static void am35x_musb_try_idle(struct musb *musb, unsigned long timeout)
195 if (musb->is_active || (musb->a_wait_bcon == 0 && 195 if (musb->is_active || (musb->a_wait_bcon == 0 &&
196 musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) { 196 musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) {
197 dev_dbg(musb->controller, "%s active, deleting timer\n", 197 dev_dbg(musb->controller, "%s active, deleting timer\n",
198 otg_state_string(musb->xceiv->state)); 198 usb_otg_state_string(musb->xceiv->state));
199 del_timer(&otg_workaround); 199 del_timer(&otg_workaround);
200 last_timer = jiffies; 200 last_timer = jiffies;
201 return; 201 return;
@@ -208,7 +208,7 @@ static void am35x_musb_try_idle(struct musb *musb, unsigned long timeout)
208 last_timer = timeout; 208 last_timer = timeout;
209 209
210 dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", 210 dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n",
211 otg_state_string(musb->xceiv->state), 211 usb_otg_state_string(musb->xceiv->state),
212 jiffies_to_msecs(timeout - jiffies)); 212 jiffies_to_msecs(timeout - jiffies));
213 mod_timer(&otg_workaround, timeout); 213 mod_timer(&otg_workaround, timeout);
214} 214}
@@ -298,7 +298,7 @@ static irqreturn_t am35x_musb_interrupt(int irq, void *hci)
298 /* NOTE: this must complete power-on within 100 ms. */ 298 /* NOTE: this must complete power-on within 100 ms. */
299 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", 299 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n",
300 drvvbus ? "on" : "off", 300 drvvbus ? "on" : "off",
301 otg_state_string(musb->xceiv->state), 301 usb_otg_state_string(musb->xceiv->state),
302 err ? " ERROR" : "", 302 err ? " ERROR" : "",
303 devctl); 303 devctl);
304 ret = IRQ_HANDLED; 304 ret = IRQ_HANDLED;
diff --git a/drivers/usb/musb/blackfin.c b/drivers/usb/musb/blackfin.c
index dbb31b30c7fa..5e63b160db0c 100644
--- a/drivers/usb/musb/blackfin.c
+++ b/drivers/usb/musb/blackfin.c
@@ -280,13 +280,13 @@ static void musb_conn_timer_handler(unsigned long _musb)
280 break; 280 break;
281 default: 281 default:
282 dev_dbg(musb->controller, "%s state not handled\n", 282 dev_dbg(musb->controller, "%s state not handled\n",
283 otg_state_string(musb->xceiv->state)); 283 usb_otg_state_string(musb->xceiv->state));
284 break; 284 break;
285 } 285 }
286 spin_unlock_irqrestore(&musb->lock, flags); 286 spin_unlock_irqrestore(&musb->lock, flags);
287 287
288 dev_dbg(musb->controller, "state is %s\n", 288 dev_dbg(musb->controller, "state is %s\n",
289 otg_state_string(musb->xceiv->state)); 289 usb_otg_state_string(musb->xceiv->state));
290} 290}
291 291
292static void bfin_musb_enable(struct musb *musb) 292static void bfin_musb_enable(struct musb *musb)
@@ -307,7 +307,7 @@ static void bfin_musb_set_vbus(struct musb *musb, int is_on)
307 307
308 dev_dbg(musb->controller, "VBUS %s, devctl %02x " 308 dev_dbg(musb->controller, "VBUS %s, devctl %02x "
309 /* otg %3x conf %08x prcm %08x */ "\n", 309 /* otg %3x conf %08x prcm %08x */ "\n",
310 otg_state_string(musb->xceiv->state), 310 usb_otg_state_string(musb->xceiv->state),
311 musb_readb(musb->mregs, MUSB_DEVCTL)); 311 musb_readb(musb->mregs, MUSB_DEVCTL));
312} 312}
313 313
diff --git a/drivers/usb/musb/cppi_dma.c b/drivers/usb/musb/cppi_dma.c
index f522000e8f06..9db211ee15b5 100644
--- a/drivers/usb/musb/cppi_dma.c
+++ b/drivers/usb/musb/cppi_dma.c
@@ -435,7 +435,6 @@ cppi_rndis_update(struct cppi_channel *c, int is_rx,
435 } 435 }
436} 436}
437 437
438#ifdef CONFIG_USB_MUSB_DEBUG
439static void cppi_dump_rxbd(const char *tag, struct cppi_descriptor *bd) 438static void cppi_dump_rxbd(const char *tag, struct cppi_descriptor *bd)
440{ 439{
441 pr_debug("RXBD/%s %08x: " 440 pr_debug("RXBD/%s %08x: "
@@ -444,21 +443,16 @@ static void cppi_dump_rxbd(const char *tag, struct cppi_descriptor *bd)
444 bd->hw_next, bd->hw_bufp, bd->hw_off_len, 443 bd->hw_next, bd->hw_bufp, bd->hw_off_len,
445 bd->hw_options); 444 bd->hw_options);
446} 445}
447#endif
448 446
449static void cppi_dump_rxq(int level, const char *tag, struct cppi_channel *rx) 447static void cppi_dump_rxq(int level, const char *tag, struct cppi_channel *rx)
450{ 448{
451#ifdef CONFIG_USB_MUSB_DEBUG
452 struct cppi_descriptor *bd; 449 struct cppi_descriptor *bd;
453 450
454 if (!_dbg_level(level))
455 return;
456 cppi_dump_rx(level, rx, tag); 451 cppi_dump_rx(level, rx, tag);
457 if (rx->last_processed) 452 if (rx->last_processed)
458 cppi_dump_rxbd("last", rx->last_processed); 453 cppi_dump_rxbd("last", rx->last_processed);
459 for (bd = rx->head; bd; bd = bd->next) 454 for (bd = rx->head; bd; bd = bd->next)
460 cppi_dump_rxbd("active", bd); 455 cppi_dump_rxbd("active", bd);
461#endif
462} 456}
463 457
464 458
@@ -784,6 +778,7 @@ cppi_next_rx_segment(struct musb *musb, struct cppi_channel *rx, int onepacket)
784 void __iomem *tibase = musb->ctrl_base; 778 void __iomem *tibase = musb->ctrl_base;
785 int is_rndis = 0; 779 int is_rndis = 0;
786 struct cppi_rx_stateram __iomem *rx_ram = rx->state_ram; 780 struct cppi_rx_stateram __iomem *rx_ram = rx->state_ram;
781 struct cppi_descriptor *d;
787 782
788 if (onepacket) { 783 if (onepacket) {
789 /* almost every USB driver, host or peripheral side */ 784 /* almost every USB driver, host or peripheral side */
@@ -897,14 +892,8 @@ cppi_next_rx_segment(struct musb *musb, struct cppi_channel *rx, int onepacket)
897 bd->hw_options |= CPPI_SOP_SET; 892 bd->hw_options |= CPPI_SOP_SET;
898 tail->hw_options |= CPPI_EOP_SET; 893 tail->hw_options |= CPPI_EOP_SET;
899 894
900#ifdef CONFIG_USB_MUSB_DEBUG 895 for (d = rx->head; d; d = d->next)
901 if (_dbg_level(5)) { 896 cppi_dump_rxbd("S", d);
902 struct cppi_descriptor *d;
903
904 for (d = rx->head; d; d = d->next)
905 cppi_dump_rxbd("S", d);
906 }
907#endif
908 897
909 /* in case the preceding transfer left some state... */ 898 /* in case the preceding transfer left some state... */
910 tail = rx->last_processed; 899 tail = rx->last_processed;
diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 41613a2b35e8..b903b744a224 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -198,7 +198,7 @@ static void otg_timer(unsigned long _musb)
198 */ 198 */
199 devctl = musb_readb(mregs, MUSB_DEVCTL); 199 devctl = musb_readb(mregs, MUSB_DEVCTL);
200 dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl, 200 dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl,
201 otg_state_string(musb->xceiv->state)); 201 usb_otg_state_string(musb->xceiv->state));
202 202
203 spin_lock_irqsave(&musb->lock, flags); 203 spin_lock_irqsave(&musb->lock, flags);
204 switch (musb->xceiv->state) { 204 switch (musb->xceiv->state) {
@@ -267,7 +267,7 @@ static void da8xx_musb_try_idle(struct musb *musb, unsigned long timeout)
267 if (musb->is_active || (musb->a_wait_bcon == 0 && 267 if (musb->is_active || (musb->a_wait_bcon == 0 &&
268 musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) { 268 musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) {
269 dev_dbg(musb->controller, "%s active, deleting timer\n", 269 dev_dbg(musb->controller, "%s active, deleting timer\n",
270 otg_state_string(musb->xceiv->state)); 270 usb_otg_state_string(musb->xceiv->state));
271 del_timer(&otg_workaround); 271 del_timer(&otg_workaround);
272 last_timer = jiffies; 272 last_timer = jiffies;
273 return; 273 return;
@@ -280,7 +280,7 @@ static void da8xx_musb_try_idle(struct musb *musb, unsigned long timeout)
280 last_timer = timeout; 280 last_timer = timeout;
281 281
282 dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", 282 dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n",
283 otg_state_string(musb->xceiv->state), 283 usb_otg_state_string(musb->xceiv->state),
284 jiffies_to_msecs(timeout - jiffies)); 284 jiffies_to_msecs(timeout - jiffies));
285 mod_timer(&otg_workaround, timeout); 285 mod_timer(&otg_workaround, timeout);
286} 286}
@@ -360,7 +360,7 @@ static irqreturn_t da8xx_musb_interrupt(int irq, void *hci)
360 360
361 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", 361 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n",
362 drvvbus ? "on" : "off", 362 drvvbus ? "on" : "off",
363 otg_state_string(musb->xceiv->state), 363 usb_otg_state_string(musb->xceiv->state),
364 err ? " ERROR" : "", 364 err ? " ERROR" : "",
365 devctl); 365 devctl);
366 ret = IRQ_HANDLED; 366 ret = IRQ_HANDLED;
diff --git a/drivers/usb/musb/davinci.c b/drivers/usb/musb/davinci.c
index e040d9103735..bea6cc35471c 100644
--- a/drivers/usb/musb/davinci.c
+++ b/drivers/usb/musb/davinci.c
@@ -215,7 +215,7 @@ static void otg_timer(unsigned long _musb)
215 */ 215 */
216 devctl = musb_readb(mregs, MUSB_DEVCTL); 216 devctl = musb_readb(mregs, MUSB_DEVCTL);
217 dev_dbg(musb->controller, "poll devctl %02x (%s)\n", devctl, 217 dev_dbg(musb->controller, "poll devctl %02x (%s)\n", devctl,
218 otg_state_string(musb->xceiv->state)); 218 usb_otg_state_string(musb->xceiv->state));
219 219
220 spin_lock_irqsave(&musb->lock, flags); 220 spin_lock_irqsave(&musb->lock, flags);
221 switch (musb->xceiv->state) { 221 switch (musb->xceiv->state) {
@@ -349,7 +349,7 @@ static irqreturn_t davinci_musb_interrupt(int irq, void *__hci)
349 davinci_musb_source_power(musb, drvvbus, 0); 349 davinci_musb_source_power(musb, drvvbus, 0);
350 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", 350 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n",
351 drvvbus ? "on" : "off", 351 drvvbus ? "on" : "off",
352 otg_state_string(musb->xceiv->state), 352 usb_otg_state_string(musb->xceiv->state),
353 err ? " ERROR" : "", 353 err ? " ERROR" : "",
354 devctl); 354 devctl);
355 retval = IRQ_HANDLED; 355 retval = IRQ_HANDLED;
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index daec6e0f7e38..37a261a6bb6a 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -372,13 +372,13 @@ static void musb_otg_timer_func(unsigned long data)
372 case OTG_STATE_A_SUSPEND: 372 case OTG_STATE_A_SUSPEND:
373 case OTG_STATE_A_WAIT_BCON: 373 case OTG_STATE_A_WAIT_BCON:
374 dev_dbg(musb->controller, "HNP: %s timeout\n", 374 dev_dbg(musb->controller, "HNP: %s timeout\n",
375 otg_state_string(musb->xceiv->state)); 375 usb_otg_state_string(musb->xceiv->state));
376 musb_platform_set_vbus(musb, 0); 376 musb_platform_set_vbus(musb, 0);
377 musb->xceiv->state = OTG_STATE_A_WAIT_VFALL; 377 musb->xceiv->state = OTG_STATE_A_WAIT_VFALL;
378 break; 378 break;
379 default: 379 default:
380 dev_dbg(musb->controller, "HNP: Unhandled mode %s\n", 380 dev_dbg(musb->controller, "HNP: Unhandled mode %s\n",
381 otg_state_string(musb->xceiv->state)); 381 usb_otg_state_string(musb->xceiv->state));
382 } 382 }
383 musb->ignore_disconnect = 0; 383 musb->ignore_disconnect = 0;
384 spin_unlock_irqrestore(&musb->lock, flags); 384 spin_unlock_irqrestore(&musb->lock, flags);
@@ -393,13 +393,14 @@ void musb_hnp_stop(struct musb *musb)
393 void __iomem *mbase = musb->mregs; 393 void __iomem *mbase = musb->mregs;
394 u8 reg; 394 u8 reg;
395 395
396 dev_dbg(musb->controller, "HNP: stop from %s\n", otg_state_string(musb->xceiv->state)); 396 dev_dbg(musb->controller, "HNP: stop from %s\n",
397 usb_otg_state_string(musb->xceiv->state));
397 398
398 switch (musb->xceiv->state) { 399 switch (musb->xceiv->state) {
399 case OTG_STATE_A_PERIPHERAL: 400 case OTG_STATE_A_PERIPHERAL:
400 musb_g_disconnect(musb); 401 musb_g_disconnect(musb);
401 dev_dbg(musb->controller, "HNP: back to %s\n", 402 dev_dbg(musb->controller, "HNP: back to %s\n",
402 otg_state_string(musb->xceiv->state)); 403 usb_otg_state_string(musb->xceiv->state));
403 break; 404 break;
404 case OTG_STATE_B_HOST: 405 case OTG_STATE_B_HOST:
405 dev_dbg(musb->controller, "HNP: Disabling HR\n"); 406 dev_dbg(musb->controller, "HNP: Disabling HR\n");
@@ -413,7 +414,7 @@ void musb_hnp_stop(struct musb *musb)
413 break; 414 break;
414 default: 415 default:
415 dev_dbg(musb->controller, "HNP: Stopping in unknown state %s\n", 416 dev_dbg(musb->controller, "HNP: Stopping in unknown state %s\n",
416 otg_state_string(musb->xceiv->state)); 417 usb_otg_state_string(musb->xceiv->state));
417 } 418 }
418 419
419 /* 420 /*
@@ -451,7 +452,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
451 */ 452 */
452 if (int_usb & MUSB_INTR_RESUME) { 453 if (int_usb & MUSB_INTR_RESUME) {
453 handled = IRQ_HANDLED; 454 handled = IRQ_HANDLED;
454 dev_dbg(musb->controller, "RESUME (%s)\n", otg_state_string(musb->xceiv->state)); 455 dev_dbg(musb->controller, "RESUME (%s)\n", usb_otg_state_string(musb->xceiv->state));
455 456
456 if (devctl & MUSB_DEVCTL_HM) { 457 if (devctl & MUSB_DEVCTL_HM) {
457 void __iomem *mbase = musb->mregs; 458 void __iomem *mbase = musb->mregs;
@@ -493,7 +494,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
493 default: 494 default:
494 WARNING("bogus %s RESUME (%s)\n", 495 WARNING("bogus %s RESUME (%s)\n",
495 "host", 496 "host",
496 otg_state_string(musb->xceiv->state)); 497 usb_otg_state_string(musb->xceiv->state));
497 } 498 }
498 } else { 499 } else {
499 switch (musb->xceiv->state) { 500 switch (musb->xceiv->state) {
@@ -522,7 +523,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
522 default: 523 default:
523 WARNING("bogus %s RESUME (%s)\n", 524 WARNING("bogus %s RESUME (%s)\n",
524 "peripheral", 525 "peripheral",
525 otg_state_string(musb->xceiv->state)); 526 usb_otg_state_string(musb->xceiv->state));
526 } 527 }
527 } 528 }
528 } 529 }
@@ -538,7 +539,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
538 } 539 }
539 540
540 dev_dbg(musb->controller, "SESSION_REQUEST (%s)\n", 541 dev_dbg(musb->controller, "SESSION_REQUEST (%s)\n",
541 otg_state_string(musb->xceiv->state)); 542 usb_otg_state_string(musb->xceiv->state));
542 543
543 /* IRQ arrives from ID pin sense or (later, if VBUS power 544 /* IRQ arrives from ID pin sense or (later, if VBUS power
544 * is removed) SRP. responses are time critical: 545 * is removed) SRP. responses are time critical:
@@ -602,8 +603,9 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
602 break; 603 break;
603 } 604 }
604 605
605 dev_dbg(musb->controller, "VBUS_ERROR in %s (%02x, %s), retry #%d, port1 %08x\n", 606 dev_printk(ignore ? KERN_DEBUG : KERN_ERR, musb->controller,
606 otg_state_string(musb->xceiv->state), 607 "VBUS_ERROR in %s (%02x, %s), retry #%d, port1 %08x\n",
608 usb_otg_state_string(musb->xceiv->state),
607 devctl, 609 devctl,
608 ({ char *s; 610 ({ char *s;
609 switch (devctl & MUSB_DEVCTL_VBUS) { 611 switch (devctl & MUSB_DEVCTL_VBUS) {
@@ -628,7 +630,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
628 630
629 if (int_usb & MUSB_INTR_SUSPEND) { 631 if (int_usb & MUSB_INTR_SUSPEND) {
630 dev_dbg(musb->controller, "SUSPEND (%s) devctl %02x\n", 632 dev_dbg(musb->controller, "SUSPEND (%s) devctl %02x\n",
631 otg_state_string(musb->xceiv->state), devctl); 633 usb_otg_state_string(musb->xceiv->state), devctl);
632 handled = IRQ_HANDLED; 634 handled = IRQ_HANDLED;
633 635
634 switch (musb->xceiv->state) { 636 switch (musb->xceiv->state) {
@@ -745,12 +747,12 @@ b_host:
745 usb_hcd_resume_root_hub(hcd); 747 usb_hcd_resume_root_hub(hcd);
746 748
747 dev_dbg(musb->controller, "CONNECT (%s) devctl %02x\n", 749 dev_dbg(musb->controller, "CONNECT (%s) devctl %02x\n",
748 otg_state_string(musb->xceiv->state), devctl); 750 usb_otg_state_string(musb->xceiv->state), devctl);
749 } 751 }
750 752
751 if ((int_usb & MUSB_INTR_DISCONNECT) && !musb->ignore_disconnect) { 753 if ((int_usb & MUSB_INTR_DISCONNECT) && !musb->ignore_disconnect) {
752 dev_dbg(musb->controller, "DISCONNECT (%s) as %s, devctl %02x\n", 754 dev_dbg(musb->controller, "DISCONNECT (%s) as %s, devctl %02x\n",
753 otg_state_string(musb->xceiv->state), 755 usb_otg_state_string(musb->xceiv->state),
754 MUSB_MODE(musb), devctl); 756 MUSB_MODE(musb), devctl);
755 handled = IRQ_HANDLED; 757 handled = IRQ_HANDLED;
756 758
@@ -787,7 +789,7 @@ b_host:
787 break; 789 break;
788 default: 790 default:
789 WARNING("unhandled DISCONNECT transition (%s)\n", 791 WARNING("unhandled DISCONNECT transition (%s)\n",
790 otg_state_string(musb->xceiv->state)); 792 usb_otg_state_string(musb->xceiv->state));
791 break; 793 break;
792 } 794 }
793 } 795 }
@@ -813,7 +815,7 @@ b_host:
813 } 815 }
814 } else { 816 } else {
815 dev_dbg(musb->controller, "BUS RESET as %s\n", 817 dev_dbg(musb->controller, "BUS RESET as %s\n",
816 otg_state_string(musb->xceiv->state)); 818 usb_otg_state_string(musb->xceiv->state));
817 switch (musb->xceiv->state) { 819 switch (musb->xceiv->state) {
818 case OTG_STATE_A_SUSPEND: 820 case OTG_STATE_A_SUSPEND:
819 /* We need to ignore disconnect on suspend 821 /* We need to ignore disconnect on suspend
@@ -826,7 +828,7 @@ b_host:
826 case OTG_STATE_A_WAIT_BCON: /* OPT TD.4.7-900ms */ 828 case OTG_STATE_A_WAIT_BCON: /* OPT TD.4.7-900ms */
827 /* never use invalid T(a_wait_bcon) */ 829 /* never use invalid T(a_wait_bcon) */
828 dev_dbg(musb->controller, "HNP: in %s, %d msec timeout\n", 830 dev_dbg(musb->controller, "HNP: in %s, %d msec timeout\n",
829 otg_state_string(musb->xceiv->state), 831 usb_otg_state_string(musb->xceiv->state),
830 TA_WAIT_BCON(musb)); 832 TA_WAIT_BCON(musb));
831 mod_timer(&musb->otg_timer, jiffies 833 mod_timer(&musb->otg_timer, jiffies
832 + msecs_to_jiffies(TA_WAIT_BCON(musb))); 834 + msecs_to_jiffies(TA_WAIT_BCON(musb)));
@@ -838,7 +840,7 @@ b_host:
838 break; 840 break;
839 case OTG_STATE_B_WAIT_ACON: 841 case OTG_STATE_B_WAIT_ACON:
840 dev_dbg(musb->controller, "HNP: RESET (%s), to b_peripheral\n", 842 dev_dbg(musb->controller, "HNP: RESET (%s), to b_peripheral\n",
841 otg_state_string(musb->xceiv->state)); 843 usb_otg_state_string(musb->xceiv->state));
842 musb->xceiv->state = OTG_STATE_B_PERIPHERAL; 844 musb->xceiv->state = OTG_STATE_B_PERIPHERAL;
843 musb_g_reset(musb); 845 musb_g_reset(musb);
844 break; 846 break;
@@ -850,7 +852,7 @@ b_host:
850 break; 852 break;
851 default: 853 default:
852 dev_dbg(musb->controller, "Unhandled BUS RESET as %s\n", 854 dev_dbg(musb->controller, "Unhandled BUS RESET as %s\n",
853 otg_state_string(musb->xceiv->state)); 855 usb_otg_state_string(musb->xceiv->state));
854 } 856 }
855 } 857 }
856 } 858 }
@@ -1632,7 +1634,7 @@ musb_mode_show(struct device *dev, struct device_attribute *attr, char *buf)
1632 int ret = -EINVAL; 1634 int ret = -EINVAL;
1633 1635
1634 spin_lock_irqsave(&musb->lock, flags); 1636 spin_lock_irqsave(&musb->lock, flags);
1635 ret = sprintf(buf, "%s\n", otg_state_string(musb->xceiv->state)); 1637 ret = sprintf(buf, "%s\n", usb_otg_state_string(musb->xceiv->state));
1636 spin_unlock_irqrestore(&musb->lock, flags); 1638 spin_unlock_irqrestore(&musb->lock, flags);
1637 1639
1638 return ret; 1640 return ret;
@@ -1951,9 +1953,13 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
1951 musb_write_ulpi_buscontrol(musb->mregs, busctl); 1953 musb_write_ulpi_buscontrol(musb->mregs, busctl);
1952 } 1954 }
1953 1955
1954 MUSB_DEV_MODE(musb); 1956 if (musb->xceiv->otg->default_a) {
1955 musb->xceiv->otg->default_a = 0; 1957 MUSB_HST_MODE(musb);
1956 musb->xceiv->state = OTG_STATE_B_IDLE; 1958 musb->xceiv->state = OTG_STATE_A_IDLE;
1959 } else {
1960 MUSB_DEV_MODE(musb);
1961 musb->xceiv->state = OTG_STATE_B_IDLE;
1962 }
1957 1963
1958 status = musb_gadget_setup(musb); 1964 status = musb_gadget_setup(musb);
1959 1965
@@ -2008,7 +2014,6 @@ static int musb_probe(struct platform_device *pdev)
2008{ 2014{
2009 struct device *dev = &pdev->dev; 2015 struct device *dev = &pdev->dev;
2010 int irq = platform_get_irq_byname(pdev, "mc"); 2016 int irq = platform_get_irq_byname(pdev, "mc");
2011 int status;
2012 struct resource *iomem; 2017 struct resource *iomem;
2013 void __iomem *base; 2018 void __iomem *base;
2014 2019
@@ -2016,24 +2021,17 @@ static int musb_probe(struct platform_device *pdev)
2016 if (!iomem || irq <= 0) 2021 if (!iomem || irq <= 0)
2017 return -ENODEV; 2022 return -ENODEV;
2018 2023
2019 base = ioremap(iomem->start, resource_size(iomem)); 2024 base = devm_ioremap_resource(dev, iomem);
2020 if (!base) { 2025 if (IS_ERR(base))
2021 dev_err(dev, "ioremap failed\n"); 2026 return PTR_ERR(base);
2022 return -ENOMEM;
2023 }
2024 2027
2025 status = musb_init_controller(dev, irq, base); 2028 return musb_init_controller(dev, irq, base);
2026 if (status < 0)
2027 iounmap(base);
2028
2029 return status;
2030} 2029}
2031 2030
2032static int musb_remove(struct platform_device *pdev) 2031static int musb_remove(struct platform_device *pdev)
2033{ 2032{
2034 struct device *dev = &pdev->dev; 2033 struct device *dev = &pdev->dev;
2035 struct musb *musb = dev_to_musb(dev); 2034 struct musb *musb = dev_to_musb(dev);
2036 void __iomem *ctrl_base = musb->ctrl_base;
2037 2035
2038 /* this gets called on rmmod. 2036 /* this gets called on rmmod.
2039 * - Host mode: host may still be active 2037 * - Host mode: host may still be active
@@ -2044,7 +2042,6 @@ static int musb_remove(struct platform_device *pdev)
2044 musb_shutdown(pdev); 2042 musb_shutdown(pdev);
2045 2043
2046 musb_free(musb); 2044 musb_free(musb);
2047 iounmap(ctrl_base);
2048 device_init_wakeup(dev, 0); 2045 device_init_wakeup(dev, 0);
2049#ifndef CONFIG_MUSB_PIO_ONLY 2046#ifndef CONFIG_MUSB_PIO_ONLY
2050 dma_set_mask(dev, *dev->parent->dma_mask); 2047 dma_set_mask(dev, *dev->parent->dma_mask);
@@ -2293,8 +2290,6 @@ static int __init musb_init(void)
2293 if (usb_disabled()) 2290 if (usb_disabled())
2294 return 0; 2291 return 0;
2295 2292
2296 pr_info("%s: version " MUSB_VERSION ", ?dma?, otg (peripheral+host)\n",
2297 musb_driver_name);
2298 return platform_driver_register(&musb_driver); 2293 return platform_driver_register(&musb_driver);
2299} 2294}
2300module_init(musb_init); 2295module_init(musb_init);
diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c
index 6bb89715b637..3a18e44e9391 100644
--- a/drivers/usb/musb/musb_dsps.c
+++ b/drivers/usb/musb/musb_dsps.c
@@ -38,6 +38,7 @@
38#include <linux/module.h> 38#include <linux/module.h>
39#include <linux/usb/nop-usb-xceiv.h> 39#include <linux/usb/nop-usb-xceiv.h>
40#include <linux/platform_data/usb-omap.h> 40#include <linux/platform_data/usb-omap.h>
41#include <linux/sizes.h>
41 42
42#include <linux/of.h> 43#include <linux/of.h>
43#include <linux/of_device.h> 44#include <linux/of_device.h>
@@ -224,7 +225,7 @@ static void otg_timer(unsigned long _musb)
224 */ 225 */
225 devctl = dsps_readb(mregs, MUSB_DEVCTL); 226 devctl = dsps_readb(mregs, MUSB_DEVCTL);
226 dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl, 227 dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl,
227 otg_state_string(musb->xceiv->state)); 228 usb_otg_state_string(musb->xceiv->state));
228 229
229 spin_lock_irqsave(&musb->lock, flags); 230 spin_lock_irqsave(&musb->lock, flags);
230 switch (musb->xceiv->state) { 231 switch (musb->xceiv->state) {
@@ -273,7 +274,7 @@ static void dsps_musb_try_idle(struct musb *musb, unsigned long timeout)
273 if (musb->is_active || (musb->a_wait_bcon == 0 && 274 if (musb->is_active || (musb->a_wait_bcon == 0 &&
274 musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) { 275 musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) {
275 dev_dbg(musb->controller, "%s active, deleting timer\n", 276 dev_dbg(musb->controller, "%s active, deleting timer\n",
276 otg_state_string(musb->xceiv->state)); 277 usb_otg_state_string(musb->xceiv->state));
277 del_timer(&glue->timer[pdev->id]); 278 del_timer(&glue->timer[pdev->id]);
278 glue->last_timer[pdev->id] = jiffies; 279 glue->last_timer[pdev->id] = jiffies;
279 return; 280 return;
@@ -288,7 +289,7 @@ static void dsps_musb_try_idle(struct musb *musb, unsigned long timeout)
288 glue->last_timer[pdev->id] = timeout; 289 glue->last_timer[pdev->id] = timeout;
289 290
290 dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", 291 dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n",
291 otg_state_string(musb->xceiv->state), 292 usb_otg_state_string(musb->xceiv->state),
292 jiffies_to_msecs(timeout - jiffies)); 293 jiffies_to_msecs(timeout - jiffies));
293 mod_timer(&glue->timer[pdev->id], timeout); 294 mod_timer(&glue->timer[pdev->id], timeout);
294} 295}
@@ -334,7 +335,7 @@ static irqreturn_t dsps_interrupt(int irq, void *hci)
334 * value but DEVCTL.BDEVICE is invalid without DEVCTL.SESSION set. 335 * value but DEVCTL.BDEVICE is invalid without DEVCTL.SESSION set.
335 * Also, DRVVBUS pulses for SRP (but not at 5V) ... 336 * Also, DRVVBUS pulses for SRP (but not at 5V) ...
336 */ 337 */
337 if (usbintr & MUSB_INTR_BABBLE) 338 if (is_host_active(musb) && usbintr & MUSB_INTR_BABBLE)
338 pr_info("CAUTION: musb: Babble Interrupt Occurred\n"); 339 pr_info("CAUTION: musb: Babble Interrupt Occurred\n");
339 340
340 if (usbintr & ((1 << wrp->drvvbus) << wrp->usb_shift)) { 341 if (usbintr & ((1 << wrp->drvvbus) << wrp->usb_shift)) {
@@ -377,7 +378,7 @@ static irqreturn_t dsps_interrupt(int irq, void *hci)
377 /* NOTE: this must complete power-on within 100 ms. */ 378 /* NOTE: this must complete power-on within 100 ms. */
378 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", 379 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n",
379 drvvbus ? "on" : "off", 380 drvvbus ? "on" : "off",
380 otg_state_string(musb->xceiv->state), 381 usb_otg_state_string(musb->xceiv->state),
381 err ? " ERROR" : "", 382 err ? " ERROR" : "",
382 devctl); 383 devctl);
383 ret = IRQ_HANDLED; 384 ret = IRQ_HANDLED;
@@ -596,14 +597,13 @@ err0:
596 597
597static int dsps_probe(struct platform_device *pdev) 598static int dsps_probe(struct platform_device *pdev)
598{ 599{
599 struct device_node *np = pdev->dev.of_node;
600 const struct of_device_id *match; 600 const struct of_device_id *match;
601 const struct dsps_musb_wrapper *wrp; 601 const struct dsps_musb_wrapper *wrp;
602 struct dsps_glue *glue; 602 struct dsps_glue *glue;
603 struct resource *iomem; 603 struct resource *iomem;
604 int ret, i; 604 int ret, i;
605 605
606 match = of_match_node(musb_dsps_of_match, np); 606 match = of_match_node(musb_dsps_of_match, pdev->dev.of_node);
607 if (!match) { 607 if (!match) {
608 dev_err(&pdev->dev, "fail to get matching of_match struct\n"); 608 dev_err(&pdev->dev, "fail to get matching of_match struct\n");
609 ret = -EINVAL; 609 ret = -EINVAL;
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 83eddedcd9be..ba7092349fa9 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -46,48 +46,6 @@
46#include "musb_core.h" 46#include "musb_core.h"
47 47
48 48
49/* MUSB PERIPHERAL status 3-mar-2006:
50 *
51 * - EP0 seems solid. It passes both USBCV and usbtest control cases.
52 * Minor glitches:
53 *
54 * + remote wakeup to Linux hosts work, but saw USBCV failures;
55 * in one test run (operator error?)
56 * + endpoint halt tests -- in both usbtest and usbcv -- seem
57 * to break when dma is enabled ... is something wrongly
58 * clearing SENDSTALL?
59 *
60 * - Mass storage behaved ok when last tested. Network traffic patterns
61 * (with lots of short transfers etc) need retesting; they turn up the
62 * worst cases of the DMA, since short packets are typical but are not
63 * required.
64 *
65 * - TX/IN
66 * + both pio and dma behave in with network and g_zero tests
67 * + no cppi throughput issues other than no-hw-queueing
68 * + failed with FLAT_REG (DaVinci)
69 * + seems to behave with double buffering, PIO -and- CPPI
70 * + with gadgetfs + AIO, requests got lost?
71 *
72 * - RX/OUT
73 * + both pio and dma behave in with network and g_zero tests
74 * + dma is slow in typical case (short_not_ok is clear)
75 * + double buffering ok with PIO
76 * + double buffering *FAILS* with CPPI, wrong data bytes sometimes
77 * + request lossage observed with gadgetfs
78 *
79 * - ISO not tested ... might work, but only weakly isochronous
80 *
81 * - Gadget driver disabling of softconnect during bind() is ignored; so
82 * drivers can't hold off host requests until userspace is ready.
83 * (Workaround: they can turn it off later.)
84 *
85 * - PORTABILITY (assumes PIO works):
86 * + DaVinci, basically works with cppi dma
87 * + OMAP 2430, ditto with mentor dma
88 * + TUSB 6010, platform-specific dma in the works
89 */
90
91/* ----------------------------------------------------------------------- */ 49/* ----------------------------------------------------------------------- */
92 50
93#define is_buffer_mapped(req) (is_dma_capable() && \ 51#define is_buffer_mapped(req) (is_dma_capable() && \
@@ -280,41 +238,6 @@ static inline int max_ep_writesize(struct musb *musb, struct musb_ep *ep)
280 return ep->packet_sz; 238 return ep->packet_sz;
281} 239}
282 240
283
284#ifdef CONFIG_USB_INVENTRA_DMA
285
286/* Peripheral tx (IN) using Mentor DMA works as follows:
287 Only mode 0 is used for transfers <= wPktSize,
288 mode 1 is used for larger transfers,
289
290 One of the following happens:
291 - Host sends IN token which causes an endpoint interrupt
292 -> TxAvail
293 -> if DMA is currently busy, exit.
294 -> if queue is non-empty, txstate().
295
296 - Request is queued by the gadget driver.
297 -> if queue was previously empty, txstate()
298
299 txstate()
300 -> start
301 /\ -> setup DMA
302 | (data is transferred to the FIFO, then sent out when
303 | IN token(s) are recd from Host.
304 | -> DMA interrupt on completion
305 | calls TxAvail.
306 | -> stop DMA, ~DMAENAB,
307 | -> set TxPktRdy for last short pkt or zlp
308 | -> Complete Request
309 | -> Continue next request (call txstate)
310 |___________________________________|
311
312 * Non-Mentor DMA engines can of course work differently, such as by
313 * upleveling from irq-per-packet to irq-per-buffer.
314 */
315
316#endif
317
318/* 241/*
319 * An endpoint is transmitting data. This can be called either from 242 * An endpoint is transmitting data. This can be called either from
320 * the IRQ routine or from ep.queue() to kickstart a request on an 243 * the IRQ routine or from ep.queue() to kickstart a request on an
@@ -621,37 +544,6 @@ void musb_g_tx(struct musb *musb, u8 epnum)
621 544
622/* ------------------------------------------------------------ */ 545/* ------------------------------------------------------------ */
623 546
624#ifdef CONFIG_USB_INVENTRA_DMA
625
626/* Peripheral rx (OUT) using Mentor DMA works as follows:
627 - Only mode 0 is used.
628
629 - Request is queued by the gadget class driver.
630 -> if queue was previously empty, rxstate()
631
632 - Host sends OUT token which causes an endpoint interrupt
633 /\ -> RxReady
634 | -> if request queued, call rxstate
635 | /\ -> setup DMA
636 | | -> DMA interrupt on completion
637 | | -> RxReady
638 | | -> stop DMA
639 | | -> ack the read
640 | | -> if data recd = max expected
641 | | by the request, or host
642 | | sent a short packet,
643 | | complete the request,
644 | | and start the next one.
645 | |_____________________________________|
646 | else just wait for the host
647 | to send the next OUT token.
648 |__________________________________________________|
649
650 * Non-Mentor DMA engines can of course work differently.
651 */
652
653#endif
654
655/* 547/*
656 * Context: controller locked, IRQs blocked, endpoint selected 548 * Context: controller locked, IRQs blocked, endpoint selected
657 */ 549 */
@@ -740,7 +632,7 @@ static void rxstate(struct musb *musb, struct musb_request *req)
740 struct dma_controller *c; 632 struct dma_controller *c;
741 struct dma_channel *channel; 633 struct dma_channel *channel;
742 int use_dma = 0; 634 int use_dma = 0;
743 int transfer_size; 635 unsigned int transfer_size;
744 636
745 c = musb->dma_controller; 637 c = musb->dma_controller;
746 channel = musb_ep->dma; 638 channel = musb_ep->dma;
@@ -782,10 +674,11 @@ static void rxstate(struct musb *musb, struct musb_request *req)
782 csr | MUSB_RXCSR_DMAMODE); 674 csr | MUSB_RXCSR_DMAMODE);
783 musb_writew(epio, MUSB_RXCSR, csr); 675 musb_writew(epio, MUSB_RXCSR, csr);
784 676
785 transfer_size = min(request->length - request->actual, 677 transfer_size = min_t(unsigned int,
678 request->length -
679 request->actual,
786 channel->max_len); 680 channel->max_len);
787 musb_ep->dma->desired_mode = 1; 681 musb_ep->dma->desired_mode = 1;
788
789 } else { 682 } else {
790 if (!musb_ep->hb_mult && 683 if (!musb_ep->hb_mult &&
791 musb_ep->hw_ep->rx_double_buffered) 684 musb_ep->hw_ep->rx_double_buffered)
@@ -815,7 +708,7 @@ static void rxstate(struct musb *musb, struct musb_request *req)
815 708
816 struct dma_controller *c; 709 struct dma_controller *c;
817 struct dma_channel *channel; 710 struct dma_channel *channel;
818 int transfer_size = 0; 711 unsigned int transfer_size = 0;
819 712
820 c = musb->dma_controller; 713 c = musb->dma_controller;
821 channel = musb_ep->dma; 714 channel = musb_ep->dma;
@@ -824,11 +717,13 @@ static void rxstate(struct musb *musb, struct musb_request *req)
824 if (fifo_count < musb_ep->packet_sz) 717 if (fifo_count < musb_ep->packet_sz)
825 transfer_size = fifo_count; 718 transfer_size = fifo_count;
826 else if (request->short_not_ok) 719 else if (request->short_not_ok)
827 transfer_size = min(request->length - 720 transfer_size = min_t(unsigned int,
721 request->length -
828 request->actual, 722 request->actual,
829 channel->max_len); 723 channel->max_len);
830 else 724 else
831 transfer_size = min(request->length - 725 transfer_size = min_t(unsigned int,
726 request->length -
832 request->actual, 727 request->actual,
833 (unsigned)fifo_count); 728 (unsigned)fifo_count);
834 729
@@ -1681,7 +1576,7 @@ static int musb_gadget_wakeup(struct usb_gadget *gadget)
1681 goto done; 1576 goto done;
1682 default: 1577 default:
1683 dev_dbg(musb->controller, "Unhandled wake: %s\n", 1578 dev_dbg(musb->controller, "Unhandled wake: %s\n",
1684 otg_state_string(musb->xceiv->state)); 1579 usb_otg_state_string(musb->xceiv->state));
1685 goto done; 1580 goto done;
1686 } 1581 }
1687 1582
@@ -1801,13 +1696,6 @@ static const struct usb_gadget_ops musb_gadget_operations = {
1801 * all peripheral ports are external... 1696 * all peripheral ports are external...
1802 */ 1697 */
1803 1698
1804static void musb_gadget_release(struct device *dev)
1805{
1806 /* kref_put(WHAT) */
1807 dev_dbg(dev, "%s\n", __func__);
1808}
1809
1810
1811static void 1699static void
1812init_peripheral_ep(struct musb *musb, struct musb_ep *ep, u8 epnum, int is_in) 1700init_peripheral_ep(struct musb *musb, struct musb_ep *ep, u8 epnum, int is_in)
1813{ 1701{
@@ -1892,12 +1780,7 @@ int musb_gadget_setup(struct musb *musb)
1892 musb->g.speed = USB_SPEED_UNKNOWN; 1780 musb->g.speed = USB_SPEED_UNKNOWN;
1893 1781
1894 /* this "gadget" abstracts/virtualizes the controller */ 1782 /* this "gadget" abstracts/virtualizes the controller */
1895 dev_set_name(&musb->g.dev, "gadget");
1896 musb->g.dev.parent = musb->controller;
1897 musb->g.dev.dma_mask = musb->controller->dma_mask;
1898 musb->g.dev.release = musb_gadget_release;
1899 musb->g.name = musb_driver_name; 1783 musb->g.name = musb_driver_name;
1900
1901 musb->g.is_otg = 1; 1784 musb->g.is_otg = 1;
1902 1785
1903 musb_g_init_endpoints(musb); 1786 musb_g_init_endpoints(musb);
@@ -1905,11 +1788,6 @@ int musb_gadget_setup(struct musb *musb)
1905 musb->is_active = 0; 1788 musb->is_active = 0;
1906 musb_platform_try_idle(musb, 0); 1789 musb_platform_try_idle(musb, 0);
1907 1790
1908 status = device_register(&musb->g.dev);
1909 if (status != 0) {
1910 put_device(&musb->g.dev);
1911 return status;
1912 }
1913 status = usb_add_gadget_udc(musb->controller, &musb->g); 1791 status = usb_add_gadget_udc(musb->controller, &musb->g);
1914 if (status) 1792 if (status)
1915 goto err; 1793 goto err;
@@ -1924,8 +1802,6 @@ err:
1924void musb_gadget_cleanup(struct musb *musb) 1802void musb_gadget_cleanup(struct musb *musb)
1925{ 1803{
1926 usb_del_gadget_udc(&musb->g); 1804 usb_del_gadget_udc(&musb->g);
1927 if (musb->g.dev.parent)
1928 device_unregister(&musb->g.dev);
1929} 1805}
1930 1806
1931/* 1807/*
@@ -1977,9 +1853,8 @@ static int musb_gadget_start(struct usb_gadget *g,
1977 goto err; 1853 goto err;
1978 } 1854 }
1979 1855
1980 if ((musb->xceiv->last_event == USB_EVENT_ID) 1856 if (musb->xceiv->last_event == USB_EVENT_ID)
1981 && otg->set_vbus) 1857 musb_platform_set_vbus(musb, 1);
1982 otg_set_vbus(otg, 1);
1983 1858
1984 hcd->self.uses_pio_for_control = 1; 1859 hcd->self.uses_pio_for_control = 1;
1985 1860
@@ -2063,6 +1938,7 @@ static int musb_gadget_stop(struct usb_gadget *g,
2063 dev_dbg(musb->controller, "unregistering driver %s\n", driver->function); 1938 dev_dbg(musb->controller, "unregistering driver %s\n", driver->function);
2064 1939
2065 musb->is_active = 0; 1940 musb->is_active = 0;
1941 musb->gadget_driver = NULL;
2066 musb_platform_try_idle(musb, 0); 1942 musb_platform_try_idle(musb, 0);
2067 spin_unlock_irqrestore(&musb->lock, flags); 1943 spin_unlock_irqrestore(&musb->lock, flags);
2068 1944
@@ -2099,7 +1975,7 @@ void musb_g_resume(struct musb *musb)
2099 break; 1975 break;
2100 default: 1976 default:
2101 WARNING("unhandled RESUME transition (%s)\n", 1977 WARNING("unhandled RESUME transition (%s)\n",
2102 otg_state_string(musb->xceiv->state)); 1978 usb_otg_state_string(musb->xceiv->state));
2103 } 1979 }
2104} 1980}
2105 1981
@@ -2129,7 +2005,7 @@ void musb_g_suspend(struct musb *musb)
2129 * A_PERIPHERAL may need care too 2005 * A_PERIPHERAL may need care too
2130 */ 2006 */
2131 WARNING("unhandled SUSPEND transition (%s)\n", 2007 WARNING("unhandled SUSPEND transition (%s)\n",
2132 otg_state_string(musb->xceiv->state)); 2008 usb_otg_state_string(musb->xceiv->state));
2133 } 2009 }
2134} 2010}
2135 2011
@@ -2163,7 +2039,7 @@ void musb_g_disconnect(struct musb *musb)
2163 switch (musb->xceiv->state) { 2039 switch (musb->xceiv->state) {
2164 default: 2040 default:
2165 dev_dbg(musb->controller, "Unhandled disconnect %s, setting a_idle\n", 2041 dev_dbg(musb->controller, "Unhandled disconnect %s, setting a_idle\n",
2166 otg_state_string(musb->xceiv->state)); 2042 usb_otg_state_string(musb->xceiv->state));
2167 musb->xceiv->state = OTG_STATE_A_IDLE; 2043 musb->xceiv->state = OTG_STATE_A_IDLE;
2168 MUSB_HST_MODE(musb); 2044 MUSB_HST_MODE(musb);
2169 break; 2045 break;
diff --git a/drivers/usb/musb/musb_gadget_ep0.c b/drivers/usb/musb/musb_gadget_ep0.c
index c9c1ac4e075f..2af45a0c8930 100644
--- a/drivers/usb/musb/musb_gadget_ep0.c
+++ b/drivers/usb/musb/musb_gadget_ep0.c
@@ -505,8 +505,10 @@ static void ep0_rxstate(struct musb *musb)
505 req->status = -EOVERFLOW; 505 req->status = -EOVERFLOW;
506 count = len; 506 count = len;
507 } 507 }
508 musb_read_fifo(&musb->endpoints[0], count, buf); 508 if (count > 0) {
509 req->actual += count; 509 musb_read_fifo(&musb->endpoints[0], count, buf);
510 req->actual += count;
511 }
510 csr = MUSB_CSR0_P_SVDRXPKTRDY; 512 csr = MUSB_CSR0_P_SVDRXPKTRDY;
511 if (count < 64 || req->actual == req->length) { 513 if (count < 64 || req->actual == req->length) {
512 musb->ep0_state = MUSB_EP0_STAGE_STATUSIN; 514 musb->ep0_state = MUSB_EP0_STAGE_STATUSIN;
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index 1ce1fcf3f3e7..8914dec49f01 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -2453,7 +2453,7 @@ static int musb_bus_suspend(struct usb_hcd *hcd)
2453 2453
2454 if (musb->is_active) { 2454 if (musb->is_active) {
2455 WARNING("trying to suspend as %s while active\n", 2455 WARNING("trying to suspend as %s while active\n",
2456 otg_state_string(musb->xceiv->state)); 2456 usb_otg_state_string(musb->xceiv->state));
2457 return -EBUSY; 2457 return -EBUSY;
2458 } else 2458 } else
2459 return 0; 2459 return 0;
@@ -2465,6 +2465,118 @@ static int musb_bus_resume(struct usb_hcd *hcd)
2465 return 0; 2465 return 0;
2466} 2466}
2467 2467
2468
2469#ifndef CONFIG_MUSB_PIO_ONLY
2470
2471#define MUSB_USB_DMA_ALIGN 4
2472
2473struct musb_temp_buffer {
2474 void *kmalloc_ptr;
2475 void *old_xfer_buffer;
2476 u8 data[0];
2477};
2478
2479static void musb_free_temp_buffer(struct urb *urb)
2480{
2481 enum dma_data_direction dir;
2482 struct musb_temp_buffer *temp;
2483
2484 if (!(urb->transfer_flags & URB_ALIGNED_TEMP_BUFFER))
2485 return;
2486
2487 dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
2488
2489 temp = container_of(urb->transfer_buffer, struct musb_temp_buffer,
2490 data);
2491
2492 if (dir == DMA_FROM_DEVICE) {
2493 memcpy(temp->old_xfer_buffer, temp->data,
2494 urb->transfer_buffer_length);
2495 }
2496 urb->transfer_buffer = temp->old_xfer_buffer;
2497 kfree(temp->kmalloc_ptr);
2498
2499 urb->transfer_flags &= ~URB_ALIGNED_TEMP_BUFFER;
2500}
2501
2502static int musb_alloc_temp_buffer(struct urb *urb, gfp_t mem_flags)
2503{
2504 enum dma_data_direction dir;
2505 struct musb_temp_buffer *temp;
2506 void *kmalloc_ptr;
2507 size_t kmalloc_size;
2508
2509 if (urb->num_sgs || urb->sg ||
2510 urb->transfer_buffer_length == 0 ||
2511 !((uintptr_t)urb->transfer_buffer & (MUSB_USB_DMA_ALIGN - 1)))
2512 return 0;
2513
2514 dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
2515
2516 /* Allocate a buffer with enough padding for alignment */
2517 kmalloc_size = urb->transfer_buffer_length +
2518 sizeof(struct musb_temp_buffer) + MUSB_USB_DMA_ALIGN - 1;
2519
2520 kmalloc_ptr = kmalloc(kmalloc_size, mem_flags);
2521 if (!kmalloc_ptr)
2522 return -ENOMEM;
2523
2524 /* Position our struct temp_buffer such that data is aligned */
2525 temp = PTR_ALIGN(kmalloc_ptr, MUSB_USB_DMA_ALIGN);
2526
2527
2528 temp->kmalloc_ptr = kmalloc_ptr;
2529 temp->old_xfer_buffer = urb->transfer_buffer;
2530 if (dir == DMA_TO_DEVICE)
2531 memcpy(temp->data, urb->transfer_buffer,
2532 urb->transfer_buffer_length);
2533 urb->transfer_buffer = temp->data;
2534
2535 urb->transfer_flags |= URB_ALIGNED_TEMP_BUFFER;
2536
2537 return 0;
2538}
2539
2540static int musb_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
2541 gfp_t mem_flags)
2542{
2543 struct musb *musb = hcd_to_musb(hcd);
2544 int ret;
2545
2546 /*
2547 * The DMA engine in RTL1.8 and above cannot handle
2548 * DMA addresses that are not aligned to a 4 byte boundary.
2549 * For such engine implemented (un)map_urb_for_dma hooks.
2550 * Do not use these hooks for RTL<1.8
2551 */
2552 if (musb->hwvers < MUSB_HWVERS_1800)
2553 return usb_hcd_map_urb_for_dma(hcd, urb, mem_flags);
2554
2555 ret = musb_alloc_temp_buffer(urb, mem_flags);
2556 if (ret)
2557 return ret;
2558
2559 ret = usb_hcd_map_urb_for_dma(hcd, urb, mem_flags);
2560 if (ret)
2561 musb_free_temp_buffer(urb);
2562
2563 return ret;
2564}
2565
2566static void musb_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
2567{
2568 struct musb *musb = hcd_to_musb(hcd);
2569
2570 usb_hcd_unmap_urb_for_dma(hcd, urb);
2571
2572 /* Do not use this hook for RTL<1.8 (see description above) */
2573 if (musb->hwvers < MUSB_HWVERS_1800)
2574 return;
2575
2576 musb_free_temp_buffer(urb);
2577}
2578#endif /* !CONFIG_MUSB_PIO_ONLY */
2579
2468const struct hc_driver musb_hc_driver = { 2580const struct hc_driver musb_hc_driver = {
2469 .description = "musb-hcd", 2581 .description = "musb-hcd",
2470 .product_desc = "MUSB HDRC host driver", 2582 .product_desc = "MUSB HDRC host driver",
@@ -2484,6 +2596,11 @@ const struct hc_driver musb_hc_driver = {
2484 .urb_dequeue = musb_urb_dequeue, 2596 .urb_dequeue = musb_urb_dequeue,
2485 .endpoint_disable = musb_h_disable, 2597 .endpoint_disable = musb_h_disable,
2486 2598
2599#ifndef CONFIG_MUSB_PIO_ONLY
2600 .map_urb_for_dma = musb_map_urb_for_dma,
2601 .unmap_urb_for_dma = musb_unmap_urb_for_dma,
2602#endif
2603
2487 .hub_status_data = musb_hub_status_data, 2604 .hub_status_data = musb_hub_status_data,
2488 .hub_control = musb_hub_control, 2605 .hub_control = musb_hub_control,
2489 .bus_suspend = musb_bus_suspend, 2606 .bus_suspend = musb_bus_suspend,
diff --git a/drivers/usb/musb/musb_virthub.c b/drivers/usb/musb/musb_virthub.c
index f70579154ded..ef7d11045f56 100644
--- a/drivers/usb/musb/musb_virthub.c
+++ b/drivers/usb/musb/musb_virthub.c
@@ -95,7 +95,7 @@ static void musb_port_suspend(struct musb *musb, bool do_suspend)
95 break; 95 break;
96 default: 96 default:
97 dev_dbg(musb->controller, "bogus rh suspend? %s\n", 97 dev_dbg(musb->controller, "bogus rh suspend? %s\n",
98 otg_state_string(musb->xceiv->state)); 98 usb_otg_state_string(musb->xceiv->state));
99 } 99 }
100 } else if (power & MUSB_POWER_SUSPENDM) { 100 } else if (power & MUSB_POWER_SUSPENDM) {
101 power &= ~MUSB_POWER_SUSPENDM; 101 power &= ~MUSB_POWER_SUSPENDM;
@@ -203,7 +203,7 @@ void musb_root_disconnect(struct musb *musb)
203 break; 203 break;
204 default: 204 default:
205 dev_dbg(musb->controller, "host disconnect (%s)\n", 205 dev_dbg(musb->controller, "host disconnect (%s)\n",
206 otg_state_string(musb->xceiv->state)); 206 usb_otg_state_string(musb->xceiv->state));
207 } 207 }
208} 208}
209 209
diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index 1a42a458f2c4..3551f1a30c65 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -117,7 +117,7 @@ static void omap2430_musb_try_idle(struct musb *musb, unsigned long timeout)
117 if (musb->is_active || ((musb->a_wait_bcon == 0) 117 if (musb->is_active || ((musb->a_wait_bcon == 0)
118 && (musb->xceiv->state == OTG_STATE_A_WAIT_BCON))) { 118 && (musb->xceiv->state == OTG_STATE_A_WAIT_BCON))) {
119 dev_dbg(musb->controller, "%s active, deleting timer\n", 119 dev_dbg(musb->controller, "%s active, deleting timer\n",
120 otg_state_string(musb->xceiv->state)); 120 usb_otg_state_string(musb->xceiv->state));
121 del_timer(&musb_idle_timer); 121 del_timer(&musb_idle_timer);
122 last_timer = jiffies; 122 last_timer = jiffies;
123 return; 123 return;
@@ -134,7 +134,7 @@ static void omap2430_musb_try_idle(struct musb *musb, unsigned long timeout)
134 last_timer = timeout; 134 last_timer = timeout;
135 135
136 dev_dbg(musb->controller, "%s inactive, for idle timer for %lu ms\n", 136 dev_dbg(musb->controller, "%s inactive, for idle timer for %lu ms\n",
137 otg_state_string(musb->xceiv->state), 137 usb_otg_state_string(musb->xceiv->state),
138 (unsigned long)jiffies_to_msecs(timeout - jiffies)); 138 (unsigned long)jiffies_to_msecs(timeout - jiffies));
139 mod_timer(&musb_idle_timer, timeout); 139 mod_timer(&musb_idle_timer, timeout);
140} 140}
@@ -174,8 +174,7 @@ static void omap2430_musb_set_vbus(struct musb *musb, int is_on)
174 } 174 }
175 } 175 }
176 176
177 if (otg->set_vbus) 177 otg_set_vbus(otg, 1);
178 otg_set_vbus(otg, 1);
179 } else { 178 } else {
180 musb->is_active = 1; 179 musb->is_active = 1;
181 otg->default_a = 1; 180 otg->default_a = 1;
@@ -200,7 +199,7 @@ static void omap2430_musb_set_vbus(struct musb *musb, int is_on)
200 199
201 dev_dbg(musb->controller, "VBUS %s, devctl %02x " 200 dev_dbg(musb->controller, "VBUS %s, devctl %02x "
202 /* otg %3x conf %08x prcm %08x */ "\n", 201 /* otg %3x conf %08x prcm %08x */ "\n",
203 otg_state_string(musb->xceiv->state), 202 usb_otg_state_string(musb->xceiv->state),
204 musb_readb(musb->mregs, MUSB_DEVCTL)); 203 musb_readb(musb->mregs, MUSB_DEVCTL));
205} 204}
206 205
@@ -292,14 +291,14 @@ static void omap_musb_set_mailbox(struct omap2430_glue *glue)
292 291
293 musb->xceiv->last_event = USB_EVENT_NONE; 292 musb->xceiv->last_event = USB_EVENT_NONE;
294 if (musb->gadget_driver) { 293 if (musb->gadget_driver) {
294 omap2430_musb_set_vbus(musb, 0);
295 pm_runtime_mark_last_busy(dev); 295 pm_runtime_mark_last_busy(dev);
296 pm_runtime_put_autosuspend(dev); 296 pm_runtime_put_autosuspend(dev);
297 } 297 }
298 298
299 if (data->interface_type == MUSB_INTERFACE_UTMI) { 299 if (data->interface_type == MUSB_INTERFACE_UTMI)
300 if (musb->xceiv->otg->set_vbus) 300 otg_set_vbus(musb->xceiv->otg, 0);
301 otg_set_vbus(musb->xceiv->otg, 0); 301
302 }
303 omap_control_usb_set_mode(glue->control_otghs, 302 omap_control_usb_set_mode(glue->control_otghs,
304 USB_MODE_DISCONNECT); 303 USB_MODE_DISCONNECT);
305 break; 304 break;
@@ -355,7 +354,12 @@ static int omap2430_musb_init(struct musb *musb)
355 else 354 else
356 musb->xceiv = devm_usb_get_phy_dev(dev, 0); 355 musb->xceiv = devm_usb_get_phy_dev(dev, 0);
357 356
358 if (IS_ERR_OR_NULL(musb->xceiv)) { 357 if (IS_ERR(musb->xceiv)) {
358 status = PTR_ERR(musb->xceiv);
359
360 if (status == -ENXIO)
361 return status;
362
359 pr_err("HS USB OTG: no transceiver configured\n"); 363 pr_err("HS USB OTG: no transceiver configured\n");
360 return -EPROBE_DEFER; 364 return -EPROBE_DEFER;
361 } 365 }
@@ -393,6 +397,8 @@ static int omap2430_musb_init(struct musb *musb)
393 if (glue->status != OMAP_MUSB_UNKNOWN) 397 if (glue->status != OMAP_MUSB_UNKNOWN)
394 omap_musb_set_mailbox(glue); 398 omap_musb_set_mailbox(glue);
395 399
400 usb_phy_init(musb->xceiv);
401
396 pm_runtime_put_noidle(musb->controller); 402 pm_runtime_put_noidle(musb->controller);
397 return 0; 403 return 0;
398 404
@@ -526,10 +532,10 @@ static int omap2430_probe(struct platform_device *pdev)
526 } 532 }
527 533
528 of_property_read_u32(np, "mode", (u32 *)&pdata->mode); 534 of_property_read_u32(np, "mode", (u32 *)&pdata->mode);
529 of_property_read_u32(np, "interface_type", 535 of_property_read_u32(np, "interface-type",
530 (u32 *)&data->interface_type); 536 (u32 *)&data->interface_type);
531 of_property_read_u32(np, "num_eps", (u32 *)&config->num_eps); 537 of_property_read_u32(np, "num-eps", (u32 *)&config->num_eps);
532 of_property_read_u32(np, "ram_bits", (u32 *)&config->ram_bits); 538 of_property_read_u32(np, "ram-bits", (u32 *)&config->ram_bits);
533 of_property_read_u32(np, "power", (u32 *)&pdata->power); 539 of_property_read_u32(np, "power", (u32 *)&pdata->power);
534 config->multipoint = of_property_read_bool(np, "multipoint"); 540 config->multipoint = of_property_read_bool(np, "multipoint");
535 pdata->has_mailbox = of_property_read_bool(np, 541 pdata->has_mailbox = of_property_read_bool(np,
diff --git a/drivers/usb/musb/tusb6010.c b/drivers/usb/musb/tusb6010.c
index 464bd23cccda..7369ba33c94f 100644
--- a/drivers/usb/musb/tusb6010.c
+++ b/drivers/usb/musb/tusb6010.c
@@ -423,7 +423,7 @@ static void musb_do_idle(unsigned long _musb)
423 && (musb->idle_timeout == 0 423 && (musb->idle_timeout == 0
424 || time_after(jiffies, musb->idle_timeout))) { 424 || time_after(jiffies, musb->idle_timeout))) {
425 dev_dbg(musb->controller, "Nothing connected %s, turning off VBUS\n", 425 dev_dbg(musb->controller, "Nothing connected %s, turning off VBUS\n",
426 otg_state_string(musb->xceiv->state)); 426 usb_otg_state_string(musb->xceiv->state));
427 } 427 }
428 /* FALLTHROUGH */ 428 /* FALLTHROUGH */
429 case OTG_STATE_A_IDLE: 429 case OTG_STATE_A_IDLE:
@@ -478,7 +478,7 @@ static void tusb_musb_try_idle(struct musb *musb, unsigned long timeout)
478 if (musb->is_active || ((musb->a_wait_bcon == 0) 478 if (musb->is_active || ((musb->a_wait_bcon == 0)
479 && (musb->xceiv->state == OTG_STATE_A_WAIT_BCON))) { 479 && (musb->xceiv->state == OTG_STATE_A_WAIT_BCON))) {
480 dev_dbg(musb->controller, "%s active, deleting timer\n", 480 dev_dbg(musb->controller, "%s active, deleting timer\n",
481 otg_state_string(musb->xceiv->state)); 481 usb_otg_state_string(musb->xceiv->state));
482 del_timer(&musb_idle_timer); 482 del_timer(&musb_idle_timer);
483 last_timer = jiffies; 483 last_timer = jiffies;
484 return; 484 return;
@@ -495,7 +495,7 @@ static void tusb_musb_try_idle(struct musb *musb, unsigned long timeout)
495 last_timer = timeout; 495 last_timer = timeout;
496 496
497 dev_dbg(musb->controller, "%s inactive, for idle timer for %lu ms\n", 497 dev_dbg(musb->controller, "%s inactive, for idle timer for %lu ms\n",
498 otg_state_string(musb->xceiv->state), 498 usb_otg_state_string(musb->xceiv->state),
499 (unsigned long)jiffies_to_msecs(timeout - jiffies)); 499 (unsigned long)jiffies_to_msecs(timeout - jiffies));
500 mod_timer(&musb_idle_timer, timeout); 500 mod_timer(&musb_idle_timer, timeout);
501} 501}
@@ -571,7 +571,7 @@ static void tusb_musb_set_vbus(struct musb *musb, int is_on)
571 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); 571 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
572 572
573 dev_dbg(musb->controller, "VBUS %s, devctl %02x otg %3x conf %08x prcm %08x\n", 573 dev_dbg(musb->controller, "VBUS %s, devctl %02x otg %3x conf %08x prcm %08x\n",
574 otg_state_string(musb->xceiv->state), 574 usb_otg_state_string(musb->xceiv->state),
575 musb_readb(musb->mregs, MUSB_DEVCTL), 575 musb_readb(musb->mregs, MUSB_DEVCTL),
576 musb_readl(tbase, TUSB_DEV_OTG_STAT), 576 musb_readl(tbase, TUSB_DEV_OTG_STAT),
577 conf, prcm); 577 conf, prcm);
@@ -678,13 +678,13 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *tbase)
678 musb->is_active = 0; 678 musb->is_active = 0;
679 } 679 }
680 dev_dbg(musb->controller, "vbus change, %s, otg %03x\n", 680 dev_dbg(musb->controller, "vbus change, %s, otg %03x\n",
681 otg_state_string(musb->xceiv->state), otg_stat); 681 usb_otg_state_string(musb->xceiv->state), otg_stat);
682 idle_timeout = jiffies + (1 * HZ); 682 idle_timeout = jiffies + (1 * HZ);
683 schedule_work(&musb->irq_work); 683 schedule_work(&musb->irq_work);
684 684
685 } else /* A-dev state machine */ { 685 } else /* A-dev state machine */ {
686 dev_dbg(musb->controller, "vbus change, %s, otg %03x\n", 686 dev_dbg(musb->controller, "vbus change, %s, otg %03x\n",
687 otg_state_string(musb->xceiv->state), otg_stat); 687 usb_otg_state_string(musb->xceiv->state), otg_stat);
688 688
689 switch (musb->xceiv->state) { 689 switch (musb->xceiv->state) {
690 case OTG_STATE_A_IDLE: 690 case OTG_STATE_A_IDLE:
@@ -733,7 +733,7 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *tbase)
733 u8 devctl; 733 u8 devctl;
734 734
735 dev_dbg(musb->controller, "%s timer, %03x\n", 735 dev_dbg(musb->controller, "%s timer, %03x\n",
736 otg_state_string(musb->xceiv->state), otg_stat); 736 usb_otg_state_string(musb->xceiv->state), otg_stat);
737 737
738 switch (musb->xceiv->state) { 738 switch (musb->xceiv->state) {
739 case OTG_STATE_A_WAIT_VRISE: 739 case OTG_STATE_A_WAIT_VRISE:
diff --git a/drivers/usb/musb/ux500.c b/drivers/usb/musb/ux500.c
index 13a392913769..2c80004e0a83 100644
--- a/drivers/usb/musb/ux500.c
+++ b/drivers/usb/musb/ux500.c
@@ -26,6 +26,7 @@
26#include <linux/err.h> 26#include <linux/err.h>
27#include <linux/io.h> 27#include <linux/io.h>
28#include <linux/platform_device.h> 28#include <linux/platform_device.h>
29#include <linux/usb/musb-ux500.h>
29 30
30#include "musb_core.h" 31#include "musb_core.h"
31 32
@@ -36,6 +37,98 @@ struct ux500_glue {
36}; 37};
37#define glue_to_musb(g) platform_get_drvdata(g->musb) 38#define glue_to_musb(g) platform_get_drvdata(g->musb)
38 39
40static void ux500_musb_set_vbus(struct musb *musb, int is_on)
41{
42 u8 devctl;
43 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
44 /* HDRC controls CPEN, but beware current surges during device
45 * connect. They can trigger transient overcurrent conditions
46 * that must be ignored.
47 */
48
49 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
50
51 if (is_on) {
52 if (musb->xceiv->state == OTG_STATE_A_IDLE) {
53 /* start the session */
54 devctl |= MUSB_DEVCTL_SESSION;
55 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
56 /*
57 * Wait for the musb to set as A device to enable the
58 * VBUS
59 */
60 while (musb_readb(musb->mregs, MUSB_DEVCTL) & 0x80) {
61
62 if (time_after(jiffies, timeout)) {
63 dev_err(musb->controller,
64 "configured as A device timeout");
65 break;
66 }
67 }
68
69 } else {
70 musb->is_active = 1;
71 musb->xceiv->otg->default_a = 1;
72 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE;
73 devctl |= MUSB_DEVCTL_SESSION;
74 MUSB_HST_MODE(musb);
75 }
76 } else {
77 musb->is_active = 0;
78
79 /* NOTE: we're skipping A_WAIT_VFALL -> A_IDLE and jumping
80 * right to B_IDLE...
81 */
82 musb->xceiv->otg->default_a = 0;
83 devctl &= ~MUSB_DEVCTL_SESSION;
84 MUSB_DEV_MODE(musb);
85 }
86 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
87
88 /*
89 * Devctl values will be updated after vbus goes below
90 * session_valid. The time taken depends on the capacitance
91 * on VBUS line. The max discharge time can be upto 1 sec
92 * as per the spec. Typically on our platform, it is 200ms
93 */
94 if (!is_on)
95 mdelay(200);
96
97 dev_dbg(musb->controller, "VBUS %s, devctl %02x\n",
98 usb_otg_state_string(musb->xceiv->state),
99 musb_readb(musb->mregs, MUSB_DEVCTL));
100}
101
102static int musb_otg_notifications(struct notifier_block *nb,
103 unsigned long event, void *unused)
104{
105 struct musb *musb = container_of(nb, struct musb, nb);
106
107 dev_dbg(musb->controller, "musb_otg_notifications %ld %s\n",
108 event, usb_otg_state_string(musb->xceiv->state));
109
110 switch (event) {
111 case UX500_MUSB_ID:
112 dev_dbg(musb->controller, "ID GND\n");
113 ux500_musb_set_vbus(musb, 1);
114 break;
115 case UX500_MUSB_VBUS:
116 dev_dbg(musb->controller, "VBUS Connect\n");
117 break;
118 case UX500_MUSB_NONE:
119 dev_dbg(musb->controller, "VBUS Disconnect\n");
120 if (is_host_active(musb))
121 ux500_musb_set_vbus(musb, 0);
122 else
123 musb->xceiv->state = OTG_STATE_B_IDLE;
124 break;
125 default:
126 dev_dbg(musb->controller, "ID float\n");
127 return NOTIFY_DONE;
128 }
129 return NOTIFY_OK;
130}
131
39static irqreturn_t ux500_musb_interrupt(int irq, void *__hci) 132static irqreturn_t ux500_musb_interrupt(int irq, void *__hci)
40{ 133{
41 unsigned long flags; 134 unsigned long flags;
@@ -58,12 +151,21 @@ static irqreturn_t ux500_musb_interrupt(int irq, void *__hci)
58 151
59static int ux500_musb_init(struct musb *musb) 152static int ux500_musb_init(struct musb *musb)
60{ 153{
154 int status;
155
61 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); 156 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
62 if (IS_ERR_OR_NULL(musb->xceiv)) { 157 if (IS_ERR_OR_NULL(musb->xceiv)) {
63 pr_err("HS USB OTG: no transceiver configured\n"); 158 pr_err("HS USB OTG: no transceiver configured\n");
64 return -EPROBE_DEFER; 159 return -EPROBE_DEFER;
65 } 160 }
66 161
162 musb->nb.notifier_call = musb_otg_notifications;
163 status = usb_register_notifier(musb->xceiv, &musb->nb);
164 if (status < 0) {
165 dev_dbg(musb->controller, "notification register failed\n");
166 return status;
167 }
168
67 musb->isr = ux500_musb_interrupt; 169 musb->isr = ux500_musb_interrupt;
68 170
69 return 0; 171 return 0;
@@ -71,6 +173,8 @@ static int ux500_musb_init(struct musb *musb)
71 173
72static int ux500_musb_exit(struct musb *musb) 174static int ux500_musb_exit(struct musb *musb)
73{ 175{
176 usb_unregister_notifier(musb->xceiv, &musb->nb);
177
74 usb_put_phy(musb->xceiv); 178 usb_put_phy(musb->xceiv);
75 179
76 return 0; 180 return 0;
@@ -79,6 +183,8 @@ static int ux500_musb_exit(struct musb *musb)
79static const struct musb_platform_ops ux500_ops = { 183static const struct musb_platform_ops ux500_ops = {
80 .init = ux500_musb_init, 184 .init = ux500_musb_init,
81 .exit = ux500_musb_exit, 185 .exit = ux500_musb_exit,
186
187 .set_vbus = ux500_musb_set_vbus,
82}; 188};
83 189
84static int ux500_probe(struct platform_device *pdev) 190static int ux500_probe(struct platform_device *pdev)
diff --git a/drivers/usb/musb/ux500_dma.c b/drivers/usb/musb/ux500_dma.c
index 039e567dd3b6..338120641145 100644
--- a/drivers/usb/musb/ux500_dma.c
+++ b/drivers/usb/musb/ux500_dma.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * drivers/usb/musb/ux500_dma.c 2 * drivers/usb/musb/ux500_dma.c
3 * 3 *
4 * U8500 and U5500 DMA support code 4 * U8500 DMA support code
5 * 5 *
6 * Copyright (C) 2009 STMicroelectronics 6 * Copyright (C) 2009 STMicroelectronics
7 * Copyright (C) 2011 ST-Ericsson SA 7 * Copyright (C) 2011 ST-Ericsson SA
@@ -30,6 +30,7 @@
30#include <linux/dma-mapping.h> 30#include <linux/dma-mapping.h>
31#include <linux/dmaengine.h> 31#include <linux/dmaengine.h>
32#include <linux/pfn.h> 32#include <linux/pfn.h>
33#include <linux/sizes.h>
33#include <linux/platform_data/usb-musb-ux500.h> 34#include <linux/platform_data/usb-musb-ux500.h>
34#include "musb_core.h" 35#include "musb_core.h"
35 36
@@ -56,7 +57,7 @@ struct ux500_dma_controller {
56}; 57};
57 58
58/* Work function invoked from DMA callback to handle rx transfers. */ 59/* Work function invoked from DMA callback to handle rx transfers. */
59void ux500_dma_callback(void *private_data) 60static void ux500_dma_callback(void *private_data)
60{ 61{
61 struct dma_channel *channel = private_data; 62 struct dma_channel *channel = private_data;
62 struct ux500_dma_channel *ux500_channel = channel->private_data; 63 struct ux500_dma_channel *ux500_channel = channel->private_data;
@@ -93,8 +94,9 @@ static bool ux500_configure_channel(struct dma_channel *channel,
93 struct musb *musb = ux500_channel->controller->private_data; 94 struct musb *musb = ux500_channel->controller->private_data;
94 95
95 dev_dbg(musb->controller, 96 dev_dbg(musb->controller,
96 "packet_sz=%d, mode=%d, dma_addr=0x%x, len=%d is_tx=%d\n", 97 "packet_sz=%d, mode=%d, dma_addr=0x%llu, len=%d is_tx=%d\n",
97 packet_sz, mode, dma_addr, len, ux500_channel->is_tx); 98 packet_sz, mode, (unsigned long long) dma_addr,
99 len, ux500_channel->is_tx);
98 100
99 ux500_channel->cur_len = len; 101 ux500_channel->cur_len = len;
100 102
@@ -191,7 +193,7 @@ static int ux500_dma_is_compatible(struct dma_channel *channel,
191 u16 maxpacket, void *buf, u32 length) 193 u16 maxpacket, void *buf, u32 length)
192{ 194{
193 if ((maxpacket & 0x3) || 195 if ((maxpacket & 0x3) ||
194 ((int)buf & 0x3) || 196 ((unsigned long int) buf & 0x3) ||
195 (length < 512) || 197 (length < 512) ||
196 (length & 0x3)) 198 (length & 0x3))
197 return false; 199 return false;
@@ -372,12 +374,17 @@ struct dma_controller *dma_controller_create(struct musb *musb, void __iomem *ba
372 374
373 controller = kzalloc(sizeof(*controller), GFP_KERNEL); 375 controller = kzalloc(sizeof(*controller), GFP_KERNEL);
374 if (!controller) 376 if (!controller)
375 return NULL; 377 goto kzalloc_fail;
376 378
377 controller->private_data = musb; 379 controller->private_data = musb;
378 380
379 /* Save physical address for DMA controller. */ 381 /* Save physical address for DMA controller. */
380 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 382 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
383 if (!iomem) {
384 dev_err(musb->controller, "no memory resource defined\n");
385 goto plat_get_fail;
386 }
387
381 controller->phy_base = (dma_addr_t) iomem->start; 388 controller->phy_base = (dma_addr_t) iomem->start;
382 389
383 controller->controller.start = ux500_dma_controller_start; 390 controller->controller.start = ux500_dma_controller_start;
@@ -389,4 +396,9 @@ struct dma_controller *dma_controller_create(struct musb *musb, void __iomem *ba
389 controller->controller.is_compatible = ux500_dma_is_compatible; 396 controller->controller.is_compatible = ux500_dma_is_compatible;
390 397
391 return &controller->controller; 398 return &controller->controller;
399
400plat_get_fail:
401 kfree(controller);
402kzalloc_fail:
403 return NULL;
392} 404}
diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig
deleted file mode 100644
index 37962c99ff1e..000000000000
--- a/drivers/usb/otg/Kconfig
+++ /dev/null
@@ -1,141 +0,0 @@
1#
2# USB OTG infrastructure may be needed for peripheral-only, host-only,
3# or OTG-capable configurations when OTG transceivers or controllers
4# are used.
5#
6
7comment "OTG and related infrastructure"
8
9config USB_OTG_UTILS
10 bool
11 help
12 Select this to make sure the build includes objects from
13 the OTG infrastructure directory.
14
15if USB || USB_GADGET
16
17#
18# USB Transceiver Drivers
19#
20config USB_GPIO_VBUS
21 tristate "GPIO based peripheral-only VBUS sensing 'transceiver'"
22 depends on GENERIC_GPIO
23 select USB_OTG_UTILS
24 help
25 Provides simple GPIO VBUS sensing for controllers with an
26 internal transceiver via the usb_phy interface, and
27 optionally control of a D+ pullup GPIO as well as a VBUS
28 current limit regulator.
29
30config ISP1301_OMAP
31 tristate "Philips ISP1301 with OMAP OTG"
32 depends on I2C && ARCH_OMAP_OTG
33 select USB_OTG_UTILS
34 help
35 If you say yes here you get support for the Philips ISP1301
36 USB-On-The-Go transceiver working with the OMAP OTG controller.
37 The ISP1301 is a full speed USB transceiver which is used in
38 products including H2, H3, and H4 development boards for Texas
39 Instruments OMAP processors.
40
41 This driver can also be built as a module. If so, the module
42 will be called isp1301_omap.
43
44config USB_ULPI
45 bool "Generic ULPI Transceiver Driver"
46 depends on ARM
47 select USB_OTG_UTILS
48 help
49 Enable this to support ULPI connected USB OTG transceivers which
50 are likely found on embedded boards.
51
52config USB_ULPI_VIEWPORT
53 bool
54 depends on USB_ULPI
55 help
56 Provides read/write operations to the ULPI phy register set for
57 controllers with a viewport register (e.g. Chipidea/ARC controllers).
58
59config TWL4030_USB
60 tristate "TWL4030 USB Transceiver Driver"
61 depends on TWL4030_CORE && REGULATOR_TWL4030 && USB_MUSB_OMAP2PLUS
62 select USB_OTG_UTILS
63 help
64 Enable this to support the USB OTG transceiver on TWL4030
65 family chips (including the TWL5030 and TPS659x0 devices).
66 This transceiver supports high and full speed devices plus,
67 in host mode, low speed.
68
69config TWL6030_USB
70 tristate "TWL6030 USB Transceiver Driver"
71 depends on TWL4030_CORE && OMAP_USB2 && USB_MUSB_OMAP2PLUS
72 select USB_OTG_UTILS
73 help
74 Enable this to support the USB OTG transceiver on TWL6030
75 family chips. This TWL6030 transceiver has the VBUS and ID GND
76 and OTG SRP events capabilities. For all other transceiver functionality
77 UTMI PHY is embedded in OMAP4430. The internal PHY configurations APIs
78 are hooked to this driver through platform_data structure.
79 The definition of internal PHY APIs are in the mach-omap2 layer.
80
81config NOP_USB_XCEIV
82 tristate "NOP USB Transceiver Driver"
83 select USB_OTG_UTILS
84 help
85 This driver is to be used by all the usb transceiver which are either
86 built-in with usb ip or which are autonomous and doesn't require any
87 phy programming such as ISP1x04 etc.
88
89config USB_MSM_OTG
90 tristate "OTG support for Qualcomm on-chip USB controller"
91 depends on (USB || USB_GADGET) && ARCH_MSM
92 select USB_OTG_UTILS
93 help
94 Enable this to support the USB OTG transceiver on MSM chips. It
95 handles PHY initialization, clock management, and workarounds
96 required after resetting the hardware and power management.
97 This driver is required even for peripheral only or host only
98 mode configurations.
99 This driver is not supported on boards like trout which
100 has an external PHY.
101
102config AB8500_USB
103 tristate "AB8500 USB Transceiver Driver"
104 depends on AB8500_CORE
105 select USB_OTG_UTILS
106 help
107 Enable this to support the USB OTG transceiver in AB8500 chip.
108 This transceiver supports high and full speed devices plus,
109 in host mode, low speed.
110
111config FSL_USB2_OTG
112 bool "Freescale USB OTG Transceiver Driver"
113 depends on USB_EHCI_FSL && USB_FSL_USB2 && USB_SUSPEND
114 select USB_OTG
115 select USB_OTG_UTILS
116 help
117 Enable this to support Freescale USB OTG transceiver.
118
119config USB_MXS_PHY
120 tristate "Freescale MXS USB PHY support"
121 depends on ARCH_MXC || ARCH_MXS
122 select STMP_DEVICE
123 select USB_OTG_UTILS
124 help
125 Enable this to support the Freescale MXS USB PHY.
126
127 MXS Phy is used by some of the i.MX SoCs, for example imx23/28/6x.
128
129config USB_MV_OTG
130 tristate "Marvell USB OTG support"
131 depends on USB_EHCI_MV && USB_MV_UDC && USB_SUSPEND
132 select USB_OTG
133 select USB_OTG_UTILS
134 help
135 Say Y here if you want to build Marvell USB OTG transciever
136 driver in kernel (including PXA and MMP series). This driver
137 implements role switch between EHCI host driver and gadget driver.
138
139 To compile this driver as a module, choose M here.
140
141endif # USB || OTG
diff --git a/drivers/usb/otg/Makefile b/drivers/usb/otg/Makefile
deleted file mode 100644
index a844b8d35d14..000000000000
--- a/drivers/usb/otg/Makefile
+++ /dev/null
@@ -1,24 +0,0 @@
1#
2# OTG infrastructure and transceiver drivers
3#
4
5ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG
6ccflags-$(CONFIG_USB_GADGET_DEBUG) += -DDEBUG
7
8# infrastructure
9obj-$(CONFIG_USB_OTG_UTILS) += otg.o
10
11# transceiver drivers
12obj-$(CONFIG_USB_GPIO_VBUS) += gpio_vbus.o
13obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o
14obj-$(CONFIG_TWL4030_USB) += twl4030-usb.o
15obj-$(CONFIG_TWL6030_USB) += twl6030-usb.o
16obj-$(CONFIG_NOP_USB_XCEIV) += nop-usb-xceiv.o
17obj-$(CONFIG_USB_ULPI) += ulpi.o
18obj-$(CONFIG_USB_ULPI_VIEWPORT) += ulpi_viewport.o
19obj-$(CONFIG_USB_MSM_OTG) += msm_otg.o
20obj-$(CONFIG_AB8500_USB) += ab8500-usb.o
21fsl_usb2_otg-objs := fsl_otg.o otg_fsm.o
22obj-$(CONFIG_FSL_USB2_OTG) += fsl_usb2_otg.o
23obj-$(CONFIG_USB_MXS_PHY) += mxs-phy.o
24obj-$(CONFIG_USB_MV_OTG) += mv_otg.o
diff --git a/drivers/usb/otg/ab8500-usb.c b/drivers/usb/otg/ab8500-usb.c
deleted file mode 100644
index 2d86f26a0183..000000000000
--- a/drivers/usb/otg/ab8500-usb.c
+++ /dev/null
@@ -1,596 +0,0 @@
1/*
2 * drivers/usb/otg/ab8500_usb.c
3 *
4 * USB transceiver driver for AB8500 chip
5 *
6 * Copyright (C) 2010 ST-Ericsson AB
7 * Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include <linux/module.h>
26#include <linux/platform_device.h>
27#include <linux/usb/otg.h>
28#include <linux/slab.h>
29#include <linux/notifier.h>
30#include <linux/interrupt.h>
31#include <linux/delay.h>
32#include <linux/mfd/abx500.h>
33#include <linux/mfd/abx500/ab8500.h>
34
35#define AB8500_MAIN_WD_CTRL_REG 0x01
36#define AB8500_USB_LINE_STAT_REG 0x80
37#define AB8500_USB_PHY_CTRL_REG 0x8A
38
39#define AB8500_BIT_OTG_STAT_ID (1 << 0)
40#define AB8500_BIT_PHY_CTRL_HOST_EN (1 << 0)
41#define AB8500_BIT_PHY_CTRL_DEVICE_EN (1 << 1)
42#define AB8500_BIT_WD_CTRL_ENABLE (1 << 0)
43#define AB8500_BIT_WD_CTRL_KICK (1 << 1)
44
45#define AB8500_V1x_LINK_STAT_WAIT (HZ/10)
46#define AB8500_WD_KICK_DELAY_US 100 /* usec */
47#define AB8500_WD_V11_DISABLE_DELAY_US 100 /* usec */
48#define AB8500_WD_V10_DISABLE_DELAY_MS 100 /* ms */
49
50/* Usb line status register */
51enum ab8500_usb_link_status {
52 USB_LINK_NOT_CONFIGURED = 0,
53 USB_LINK_STD_HOST_NC,
54 USB_LINK_STD_HOST_C_NS,
55 USB_LINK_STD_HOST_C_S,
56 USB_LINK_HOST_CHG_NM,
57 USB_LINK_HOST_CHG_HS,
58 USB_LINK_HOST_CHG_HS_CHIRP,
59 USB_LINK_DEDICATED_CHG,
60 USB_LINK_ACA_RID_A,
61 USB_LINK_ACA_RID_B,
62 USB_LINK_ACA_RID_C_NM,
63 USB_LINK_ACA_RID_C_HS,
64 USB_LINK_ACA_RID_C_HS_CHIRP,
65 USB_LINK_HM_IDGND,
66 USB_LINK_RESERVED,
67 USB_LINK_NOT_VALID_LINK
68};
69
70struct ab8500_usb {
71 struct usb_phy phy;
72 struct device *dev;
73 int irq_num_id_rise;
74 int irq_num_id_fall;
75 int irq_num_vbus_rise;
76 int irq_num_vbus_fall;
77 int irq_num_link_status;
78 unsigned vbus_draw;
79 struct delayed_work dwork;
80 struct work_struct phy_dis_work;
81 unsigned long link_status_wait;
82 int rev;
83};
84
85static inline struct ab8500_usb *phy_to_ab(struct usb_phy *x)
86{
87 return container_of(x, struct ab8500_usb, phy);
88}
89
90static void ab8500_usb_wd_workaround(struct ab8500_usb *ab)
91{
92 abx500_set_register_interruptible(ab->dev,
93 AB8500_SYS_CTRL2_BLOCK,
94 AB8500_MAIN_WD_CTRL_REG,
95 AB8500_BIT_WD_CTRL_ENABLE);
96
97 udelay(AB8500_WD_KICK_DELAY_US);
98
99 abx500_set_register_interruptible(ab->dev,
100 AB8500_SYS_CTRL2_BLOCK,
101 AB8500_MAIN_WD_CTRL_REG,
102 (AB8500_BIT_WD_CTRL_ENABLE
103 | AB8500_BIT_WD_CTRL_KICK));
104
105 if (ab->rev > 0x10) /* v1.1 v2.0 */
106 udelay(AB8500_WD_V11_DISABLE_DELAY_US);
107 else /* v1.0 */
108 msleep(AB8500_WD_V10_DISABLE_DELAY_MS);
109
110 abx500_set_register_interruptible(ab->dev,
111 AB8500_SYS_CTRL2_BLOCK,
112 AB8500_MAIN_WD_CTRL_REG,
113 0);
114}
115
116static void ab8500_usb_phy_ctrl(struct ab8500_usb *ab, bool sel_host,
117 bool enable)
118{
119 u8 ctrl_reg;
120 abx500_get_register_interruptible(ab->dev,
121 AB8500_USB,
122 AB8500_USB_PHY_CTRL_REG,
123 &ctrl_reg);
124 if (sel_host) {
125 if (enable)
126 ctrl_reg |= AB8500_BIT_PHY_CTRL_HOST_EN;
127 else
128 ctrl_reg &= ~AB8500_BIT_PHY_CTRL_HOST_EN;
129 } else {
130 if (enable)
131 ctrl_reg |= AB8500_BIT_PHY_CTRL_DEVICE_EN;
132 else
133 ctrl_reg &= ~AB8500_BIT_PHY_CTRL_DEVICE_EN;
134 }
135
136 abx500_set_register_interruptible(ab->dev,
137 AB8500_USB,
138 AB8500_USB_PHY_CTRL_REG,
139 ctrl_reg);
140
141 /* Needed to enable the phy.*/
142 if (enable)
143 ab8500_usb_wd_workaround(ab);
144}
145
146#define ab8500_usb_host_phy_en(ab) ab8500_usb_phy_ctrl(ab, true, true)
147#define ab8500_usb_host_phy_dis(ab) ab8500_usb_phy_ctrl(ab, true, false)
148#define ab8500_usb_peri_phy_en(ab) ab8500_usb_phy_ctrl(ab, false, true)
149#define ab8500_usb_peri_phy_dis(ab) ab8500_usb_phy_ctrl(ab, false, false)
150
151static int ab8500_usb_link_status_update(struct ab8500_usb *ab)
152{
153 u8 reg;
154 enum ab8500_usb_link_status lsts;
155 void *v = NULL;
156 enum usb_phy_events event;
157
158 abx500_get_register_interruptible(ab->dev,
159 AB8500_USB,
160 AB8500_USB_LINE_STAT_REG,
161 &reg);
162
163 lsts = (reg >> 3) & 0x0F;
164
165 switch (lsts) {
166 case USB_LINK_NOT_CONFIGURED:
167 case USB_LINK_RESERVED:
168 case USB_LINK_NOT_VALID_LINK:
169 /* TODO: Disable regulators. */
170 ab8500_usb_host_phy_dis(ab);
171 ab8500_usb_peri_phy_dis(ab);
172 ab->phy.state = OTG_STATE_B_IDLE;
173 ab->phy.otg->default_a = false;
174 ab->vbus_draw = 0;
175 event = USB_EVENT_NONE;
176 break;
177
178 case USB_LINK_STD_HOST_NC:
179 case USB_LINK_STD_HOST_C_NS:
180 case USB_LINK_STD_HOST_C_S:
181 case USB_LINK_HOST_CHG_NM:
182 case USB_LINK_HOST_CHG_HS:
183 case USB_LINK_HOST_CHG_HS_CHIRP:
184 if (ab->phy.otg->gadget) {
185 /* TODO: Enable regulators. */
186 ab8500_usb_peri_phy_en(ab);
187 v = ab->phy.otg->gadget;
188 }
189 event = USB_EVENT_VBUS;
190 break;
191
192 case USB_LINK_HM_IDGND:
193 if (ab->phy.otg->host) {
194 /* TODO: Enable regulators. */
195 ab8500_usb_host_phy_en(ab);
196 v = ab->phy.otg->host;
197 }
198 ab->phy.state = OTG_STATE_A_IDLE;
199 ab->phy.otg->default_a = true;
200 event = USB_EVENT_ID;
201 break;
202
203 case USB_LINK_ACA_RID_A:
204 case USB_LINK_ACA_RID_B:
205 /* TODO */
206 case USB_LINK_ACA_RID_C_NM:
207 case USB_LINK_ACA_RID_C_HS:
208 case USB_LINK_ACA_RID_C_HS_CHIRP:
209 case USB_LINK_DEDICATED_CHG:
210 /* TODO: vbus_draw */
211 event = USB_EVENT_CHARGER;
212 break;
213 }
214
215 atomic_notifier_call_chain(&ab->phy.notifier, event, v);
216
217 return 0;
218}
219
220static void ab8500_usb_delayed_work(struct work_struct *work)
221{
222 struct ab8500_usb *ab = container_of(work, struct ab8500_usb,
223 dwork.work);
224
225 ab8500_usb_link_status_update(ab);
226}
227
228static irqreturn_t ab8500_usb_v1x_common_irq(int irq, void *data)
229{
230 struct ab8500_usb *ab = (struct ab8500_usb *) data;
231
232 /* Wait for link status to become stable. */
233 schedule_delayed_work(&ab->dwork, ab->link_status_wait);
234
235 return IRQ_HANDLED;
236}
237
238static irqreturn_t ab8500_usb_v1x_vbus_fall_irq(int irq, void *data)
239{
240 struct ab8500_usb *ab = (struct ab8500_usb *) data;
241
242 /* Link status will not be updated till phy is disabled. */
243 ab8500_usb_peri_phy_dis(ab);
244
245 /* Wait for link status to become stable. */
246 schedule_delayed_work(&ab->dwork, ab->link_status_wait);
247
248 return IRQ_HANDLED;
249}
250
251static irqreturn_t ab8500_usb_v20_irq(int irq, void *data)
252{
253 struct ab8500_usb *ab = (struct ab8500_usb *) data;
254
255 ab8500_usb_link_status_update(ab);
256
257 return IRQ_HANDLED;
258}
259
260static void ab8500_usb_phy_disable_work(struct work_struct *work)
261{
262 struct ab8500_usb *ab = container_of(work, struct ab8500_usb,
263 phy_dis_work);
264
265 if (!ab->phy.otg->host)
266 ab8500_usb_host_phy_dis(ab);
267
268 if (!ab->phy.otg->gadget)
269 ab8500_usb_peri_phy_dis(ab);
270}
271
272static int ab8500_usb_set_power(struct usb_phy *phy, unsigned mA)
273{
274 struct ab8500_usb *ab;
275
276 if (!phy)
277 return -ENODEV;
278
279 ab = phy_to_ab(phy);
280
281 ab->vbus_draw = mA;
282
283 if (mA)
284 atomic_notifier_call_chain(&ab->phy.notifier,
285 USB_EVENT_ENUMERATED, ab->phy.otg->gadget);
286 return 0;
287}
288
289/* TODO: Implement some way for charging or other drivers to read
290 * ab->vbus_draw.
291 */
292
293static int ab8500_usb_set_suspend(struct usb_phy *x, int suspend)
294{
295 /* TODO */
296 return 0;
297}
298
299static int ab8500_usb_set_peripheral(struct usb_otg *otg,
300 struct usb_gadget *gadget)
301{
302 struct ab8500_usb *ab;
303
304 if (!otg)
305 return -ENODEV;
306
307 ab = phy_to_ab(otg->phy);
308
309 /* Some drivers call this function in atomic context.
310 * Do not update ab8500 registers directly till this
311 * is fixed.
312 */
313
314 if (!gadget) {
315 /* TODO: Disable regulators. */
316 otg->gadget = NULL;
317 schedule_work(&ab->phy_dis_work);
318 } else {
319 otg->gadget = gadget;
320 otg->phy->state = OTG_STATE_B_IDLE;
321
322 /* Phy will not be enabled if cable is already
323 * plugged-in. Schedule to enable phy.
324 * Use same delay to avoid any race condition.
325 */
326 schedule_delayed_work(&ab->dwork, ab->link_status_wait);
327 }
328
329 return 0;
330}
331
332static int ab8500_usb_set_host(struct usb_otg *otg, struct usb_bus *host)
333{
334 struct ab8500_usb *ab;
335
336 if (!otg)
337 return -ENODEV;
338
339 ab = phy_to_ab(otg->phy);
340
341 /* Some drivers call this function in atomic context.
342 * Do not update ab8500 registers directly till this
343 * is fixed.
344 */
345
346 if (!host) {
347 /* TODO: Disable regulators. */
348 otg->host = NULL;
349 schedule_work(&ab->phy_dis_work);
350 } else {
351 otg->host = host;
352 /* Phy will not be enabled if cable is already
353 * plugged-in. Schedule to enable phy.
354 * Use same delay to avoid any race condition.
355 */
356 schedule_delayed_work(&ab->dwork, ab->link_status_wait);
357 }
358
359 return 0;
360}
361
362static void ab8500_usb_irq_free(struct ab8500_usb *ab)
363{
364 if (ab->rev < 0x20) {
365 free_irq(ab->irq_num_id_rise, ab);
366 free_irq(ab->irq_num_id_fall, ab);
367 free_irq(ab->irq_num_vbus_rise, ab);
368 free_irq(ab->irq_num_vbus_fall, ab);
369 } else {
370 free_irq(ab->irq_num_link_status, ab);
371 }
372}
373
374static int ab8500_usb_v1x_res_setup(struct platform_device *pdev,
375 struct ab8500_usb *ab)
376{
377 int err;
378
379 ab->irq_num_id_rise = platform_get_irq_byname(pdev, "ID_WAKEUP_R");
380 if (ab->irq_num_id_rise < 0) {
381 dev_err(&pdev->dev, "ID rise irq not found\n");
382 return ab->irq_num_id_rise;
383 }
384 err = request_threaded_irq(ab->irq_num_id_rise, NULL,
385 ab8500_usb_v1x_common_irq,
386 IRQF_NO_SUSPEND | IRQF_SHARED,
387 "usb-id-rise", ab);
388 if (err < 0) {
389 dev_err(ab->dev, "request_irq failed for ID rise irq\n");
390 goto fail0;
391 }
392
393 ab->irq_num_id_fall = platform_get_irq_byname(pdev, "ID_WAKEUP_F");
394 if (ab->irq_num_id_fall < 0) {
395 dev_err(&pdev->dev, "ID fall irq not found\n");
396 return ab->irq_num_id_fall;
397 }
398 err = request_threaded_irq(ab->irq_num_id_fall, NULL,
399 ab8500_usb_v1x_common_irq,
400 IRQF_NO_SUSPEND | IRQF_SHARED,
401 "usb-id-fall", ab);
402 if (err < 0) {
403 dev_err(ab->dev, "request_irq failed for ID fall irq\n");
404 goto fail1;
405 }
406
407 ab->irq_num_vbus_rise = platform_get_irq_byname(pdev, "VBUS_DET_R");
408 if (ab->irq_num_vbus_rise < 0) {
409 dev_err(&pdev->dev, "VBUS rise irq not found\n");
410 return ab->irq_num_vbus_rise;
411 }
412 err = request_threaded_irq(ab->irq_num_vbus_rise, NULL,
413 ab8500_usb_v1x_common_irq,
414 IRQF_NO_SUSPEND | IRQF_SHARED,
415 "usb-vbus-rise", ab);
416 if (err < 0) {
417 dev_err(ab->dev, "request_irq failed for Vbus rise irq\n");
418 goto fail2;
419 }
420
421 ab->irq_num_vbus_fall = platform_get_irq_byname(pdev, "VBUS_DET_F");
422 if (ab->irq_num_vbus_fall < 0) {
423 dev_err(&pdev->dev, "VBUS fall irq not found\n");
424 return ab->irq_num_vbus_fall;
425 }
426 err = request_threaded_irq(ab->irq_num_vbus_fall, NULL,
427 ab8500_usb_v1x_vbus_fall_irq,
428 IRQF_NO_SUSPEND | IRQF_SHARED,
429 "usb-vbus-fall", ab);
430 if (err < 0) {
431 dev_err(ab->dev, "request_irq failed for Vbus fall irq\n");
432 goto fail3;
433 }
434
435 return 0;
436fail3:
437 free_irq(ab->irq_num_vbus_rise, ab);
438fail2:
439 free_irq(ab->irq_num_id_fall, ab);
440fail1:
441 free_irq(ab->irq_num_id_rise, ab);
442fail0:
443 return err;
444}
445
446static int ab8500_usb_v2_res_setup(struct platform_device *pdev,
447 struct ab8500_usb *ab)
448{
449 int err;
450
451 ab->irq_num_link_status = platform_get_irq_byname(pdev,
452 "USB_LINK_STATUS");
453 if (ab->irq_num_link_status < 0) {
454 dev_err(&pdev->dev, "Link status irq not found\n");
455 return ab->irq_num_link_status;
456 }
457
458 err = request_threaded_irq(ab->irq_num_link_status, NULL,
459 ab8500_usb_v20_irq,
460 IRQF_NO_SUSPEND | IRQF_SHARED,
461 "usb-link-status", ab);
462 if (err < 0) {
463 dev_err(ab->dev,
464 "request_irq failed for link status irq\n");
465 return err;
466 }
467
468 return 0;
469}
470
471static int ab8500_usb_probe(struct platform_device *pdev)
472{
473 struct ab8500_usb *ab;
474 struct usb_otg *otg;
475 int err;
476 int rev;
477
478 rev = abx500_get_chip_id(&pdev->dev);
479 if (rev < 0) {
480 dev_err(&pdev->dev, "Chip id read failed\n");
481 return rev;
482 } else if (rev < 0x10) {
483 dev_err(&pdev->dev, "Unsupported AB8500 chip\n");
484 return -ENODEV;
485 }
486
487 ab = kzalloc(sizeof *ab, GFP_KERNEL);
488 if (!ab)
489 return -ENOMEM;
490
491 otg = kzalloc(sizeof *otg, GFP_KERNEL);
492 if (!otg) {
493 kfree(ab);
494 return -ENOMEM;
495 }
496
497 ab->dev = &pdev->dev;
498 ab->rev = rev;
499 ab->phy.dev = ab->dev;
500 ab->phy.otg = otg;
501 ab->phy.label = "ab8500";
502 ab->phy.set_suspend = ab8500_usb_set_suspend;
503 ab->phy.set_power = ab8500_usb_set_power;
504 ab->phy.state = OTG_STATE_UNDEFINED;
505
506 otg->phy = &ab->phy;
507 otg->set_host = ab8500_usb_set_host;
508 otg->set_peripheral = ab8500_usb_set_peripheral;
509
510 platform_set_drvdata(pdev, ab);
511
512 ATOMIC_INIT_NOTIFIER_HEAD(&ab->phy.notifier);
513
514 /* v1: Wait for link status to become stable.
515 * all: Updates form set_host and set_peripheral as they are atomic.
516 */
517 INIT_DELAYED_WORK(&ab->dwork, ab8500_usb_delayed_work);
518
519 /* all: Disable phy when called from set_host and set_peripheral */
520 INIT_WORK(&ab->phy_dis_work, ab8500_usb_phy_disable_work);
521
522 if (ab->rev < 0x20) {
523 err = ab8500_usb_v1x_res_setup(pdev, ab);
524 ab->link_status_wait = AB8500_V1x_LINK_STAT_WAIT;
525 } else {
526 err = ab8500_usb_v2_res_setup(pdev, ab);
527 }
528
529 if (err < 0)
530 goto fail0;
531
532 err = usb_add_phy(&ab->phy, USB_PHY_TYPE_USB2);
533 if (err) {
534 dev_err(&pdev->dev, "Can't register transceiver\n");
535 goto fail1;
536 }
537
538 dev_info(&pdev->dev, "AB8500 usb driver initialized\n");
539
540 return 0;
541fail1:
542 ab8500_usb_irq_free(ab);
543fail0:
544 kfree(otg);
545 kfree(ab);
546 return err;
547}
548
549static int ab8500_usb_remove(struct platform_device *pdev)
550{
551 struct ab8500_usb *ab = platform_get_drvdata(pdev);
552
553 ab8500_usb_irq_free(ab);
554
555 cancel_delayed_work_sync(&ab->dwork);
556
557 cancel_work_sync(&ab->phy_dis_work);
558
559 usb_remove_phy(&ab->phy);
560
561 ab8500_usb_host_phy_dis(ab);
562 ab8500_usb_peri_phy_dis(ab);
563
564 platform_set_drvdata(pdev, NULL);
565
566 kfree(ab->phy.otg);
567 kfree(ab);
568
569 return 0;
570}
571
572static struct platform_driver ab8500_usb_driver = {
573 .probe = ab8500_usb_probe,
574 .remove = ab8500_usb_remove,
575 .driver = {
576 .name = "ab8500-usb",
577 .owner = THIS_MODULE,
578 },
579};
580
581static int __init ab8500_usb_init(void)
582{
583 return platform_driver_register(&ab8500_usb_driver);
584}
585subsys_initcall(ab8500_usb_init);
586
587static void __exit ab8500_usb_exit(void)
588{
589 platform_driver_unregister(&ab8500_usb_driver);
590}
591module_exit(ab8500_usb_exit);
592
593MODULE_ALIAS("platform:ab8500_usb");
594MODULE_AUTHOR("ST-Ericsson AB");
595MODULE_DESCRIPTION("AB8500 usb transceiver driver");
596MODULE_LICENSE("GPL");
diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig
index 90549382eba5..3a7fec957ca7 100644
--- a/drivers/usb/phy/Kconfig
+++ b/drivers/usb/phy/Kconfig
@@ -1,13 +1,74 @@
1# 1#
2# Physical Layer USB driver configuration 2# Physical Layer USB driver configuration
3# 3#
4comment "USB Physical Layer drivers" 4menuconfig USB_PHY
5 depends on USB || USB_GADGET 5 tristate "USB Physical Layer drivers"
6 help
7 USB controllers (those which are host, device or DRD) need a
8 device to handle the physical layer signalling, commonly called
9 a PHY.
10
11 The following drivers add support for such PHY devices.
12
13if USB_PHY
14
15#
16# USB Transceiver Drivers
17#
18config AB8500_USB
19 tristate "AB8500 USB Transceiver Driver"
20 depends on AB8500_CORE
21 help
22 Enable this to support the USB OTG transceiver in AB8500 chip.
23 This transceiver supports high and full speed devices plus,
24 in host mode, low speed.
25
26config FSL_USB2_OTG
27 bool "Freescale USB OTG Transceiver Driver"
28 depends on USB_EHCI_FSL && USB_FSL_USB2 && USB_SUSPEND
29 select USB_OTG
30 help
31 Enable this to support Freescale USB OTG transceiver.
32
33config ISP1301_OMAP
34 tristate "Philips ISP1301 with OMAP OTG"
35 depends on I2C && ARCH_OMAP_OTG
36 help
37 If you say yes here you get support for the Philips ISP1301
38 USB-On-The-Go transceiver working with the OMAP OTG controller.
39 The ISP1301 is a full speed USB transceiver which is used in
40 products including H2, H3, and H4 development boards for Texas
41 Instruments OMAP processors.
42
43 This driver can also be built as a module. If so, the module
44 will be called isp1301_omap.
45
46config MV_U3D_PHY
47 bool "Marvell USB 3.0 PHY controller Driver"
48 depends on CPU_MMP3
49 help
50 Enable this to support Marvell USB 3.0 phy controller for Marvell
51 SoC.
52
53config NOP_USB_XCEIV
54 tristate "NOP USB Transceiver Driver"
55 help
56 This driver is to be used by all the usb transceiver which are either
57 built-in with usb ip or which are autonomous and doesn't require any
58 phy programming such as ISP1x04 etc.
59
60config OMAP_CONTROL_USB
61 tristate "OMAP CONTROL USB Driver"
62 help
63 Enable this to add support for the USB part present in the control
64 module. This driver has API to power on the USB2 PHY and to write to
65 the mailbox. The mailbox is present only in omap4 and the register to
66 power on the USB2 PHY is present in OMAP4 and OMAP5. OMAP5 has an
67 additional register to power on USB3 PHY.
6 68
7config OMAP_USB2 69config OMAP_USB2
8 tristate "OMAP USB2 PHY Driver" 70 tristate "OMAP USB2 PHY Driver"
9 depends on ARCH_OMAP2PLUS 71 depends on ARCH_OMAP2PLUS
10 select USB_OTG_UTILS
11 select OMAP_CONTROL_USB 72 select OMAP_CONTROL_USB
12 help 73 help
13 Enable this to support the transceiver that is part of SOC. This 74 Enable this to support the transceiver that is part of SOC. This
@@ -17,7 +78,6 @@ config OMAP_USB2
17 78
18config OMAP_USB3 79config OMAP_USB3
19 tristate "OMAP USB3 PHY Driver" 80 tristate "OMAP USB3 PHY Driver"
20 select USB_OTG_UTILS
21 select OMAP_CONTROL_USB 81 select OMAP_CONTROL_USB
22 help 82 help
23 Enable this to support the USB3 PHY that is part of SOC. This 83 Enable this to support the USB3 PHY that is part of SOC. This
@@ -25,14 +85,55 @@ config OMAP_USB3
25 This driver interacts with the "OMAP Control USB Driver" to power 85 This driver interacts with the "OMAP Control USB Driver" to power
26 on/off the PHY. 86 on/off the PHY.
27 87
28config OMAP_CONTROL_USB 88config SAMSUNG_USBPHY
29 tristate "OMAP CONTROL USB Driver" 89 tristate "Samsung USB PHY Driver"
30 help 90 help
31 Enable this to add support for the USB part present in the control 91 Enable this to support Samsung USB phy helper driver for Samsung SoCs.
32 module. This driver has API to power on the USB2 PHY and to write to 92 This driver provides common interface to interact, for Samsung USB 2.0 PHY
33 the mailbox. The mailbox is present only in omap4 and the register to 93 driver and later for Samsung USB 3.0 PHY driver.
34 power on the USB2 PHY is present in OMAP4 and OMAP5. OMAP5 has an 94
35 additional register to power on USB3 PHY. 95config SAMSUNG_USB2PHY
96 tristate "Samsung USB 2.0 PHY controller Driver"
97 select SAMSUNG_USBPHY
98 help
99 Enable this to support Samsung USB 2.0 (High Speed) PHY controller
100 driver for Samsung SoCs.
101
102config SAMSUNG_USB3PHY
103 tristate "Samsung USB 3.0 PHY controller Driver"
104 select SAMSUNG_USBPHY
105 help
106 Enable this to support Samsung USB 3.0 (Super Speed) phy controller
107 for samsung SoCs.
108
109config TWL4030_USB
110 tristate "TWL4030 USB Transceiver Driver"
111 depends on TWL4030_CORE && REGULATOR_TWL4030 && USB_MUSB_OMAP2PLUS
112 help
113 Enable this to support the USB OTG transceiver on TWL4030
114 family chips (including the TWL5030 and TPS659x0 devices).
115 This transceiver supports high and full speed devices plus,
116 in host mode, low speed.
117
118config TWL6030_USB
119 tristate "TWL6030 USB Transceiver Driver"
120 depends on TWL4030_CORE && OMAP_USB2 && USB_MUSB_OMAP2PLUS
121 help
122 Enable this to support the USB OTG transceiver on TWL6030
123 family chips. This TWL6030 transceiver has the VBUS and ID GND
124 and OTG SRP events capabilities. For all other transceiver functionality
125 UTMI PHY is embedded in OMAP4430. The internal PHY configurations APIs
126 are hooked to this driver through platform_data structure.
127 The definition of internal PHY APIs are in the mach-omap2 layer.
128
129config USB_GPIO_VBUS
130 tristate "GPIO based peripheral-only VBUS sensing 'transceiver'"
131 depends on GENERIC_GPIO
132 help
133 Provides simple GPIO VBUS sensing for controllers with an
134 internal transceiver via the usb_phy interface, and
135 optionally control of a D+ pullup GPIO as well as a VBUS
136 current limit regulator.
36 137
37config USB_ISP1301 138config USB_ISP1301
38 tristate "NXP ISP1301 USB transceiver support" 139 tristate "NXP ISP1301 USB transceiver support"
@@ -47,18 +148,41 @@ config USB_ISP1301
47 To compile this driver as a module, choose M here: the 148 To compile this driver as a module, choose M here: the
48 module will be called isp1301. 149 module will be called isp1301.
49 150
50config MV_U3D_PHY 151config USB_MSM_OTG
51 bool "Marvell USB 3.0 PHY controller Driver" 152 tristate "OTG support for Qualcomm on-chip USB controller"
52 depends on USB_MV_U3D 153 depends on (USB || USB_GADGET) && ARCH_MSM
53 select USB_OTG_UTILS
54 help 154 help
55 Enable this to support Marvell USB 3.0 phy controller for Marvell 155 Enable this to support the USB OTG transceiver on MSM chips. It
56 SoC. 156 handles PHY initialization, clock management, and workarounds
157 required after resetting the hardware and power management.
158 This driver is required even for peripheral only or host only
159 mode configurations.
160 This driver is not supported on boards like trout which
161 has an external PHY.
162
163config USB_MV_OTG
164 tristate "Marvell USB OTG support"
165 depends on USB_EHCI_MV && USB_MV_UDC && USB_SUSPEND
166 select USB_OTG
167 help
168 Say Y here if you want to build Marvell USB OTG transciever
169 driver in kernel (including PXA and MMP series). This driver
170 implements role switch between EHCI host driver and gadget driver.
171
172 To compile this driver as a module, choose M here.
173
174config USB_MXS_PHY
175 tristate "Freescale MXS USB PHY support"
176 depends on ARCH_MXC || ARCH_MXS
177 select STMP_DEVICE
178 help
179 Enable this to support the Freescale MXS USB PHY.
180
181 MXS Phy is used by some of the i.MX SoCs, for example imx23/28/6x.
57 182
58config USB_RCAR_PHY 183config USB_RCAR_PHY
59 tristate "Renesas R-Car USB phy support" 184 tristate "Renesas R-Car USB phy support"
60 depends on USB || USB_GADGET 185 depends on USB || USB_GADGET
61 select USB_OTG_UTILS
62 help 186 help
63 Say Y here to add support for the Renesas R-Car USB phy driver. 187 Say Y here to add support for the Renesas R-Car USB phy driver.
64 This chip is typically used as USB phy for USB host, gadget. 188 This chip is typically used as USB phy for USB host, gadget.
@@ -67,10 +191,18 @@ config USB_RCAR_PHY
67 To compile this driver as a module, choose M here: the 191 To compile this driver as a module, choose M here: the
68 module will be called rcar-phy. 192 module will be called rcar-phy.
69 193
70config SAMSUNG_USBPHY 194config USB_ULPI
71 bool "Samsung USB PHY controller Driver" 195 bool "Generic ULPI Transceiver Driver"
72 depends on USB_S3C_HSOTG || USB_EHCI_S5P || USB_OHCI_EXYNOS 196 depends on ARM
73 select USB_OTG_UTILS 197 help
198 Enable this to support ULPI connected USB OTG transceivers which
199 are likely found on embedded boards.
200
201config USB_ULPI_VIEWPORT
202 bool
203 depends on USB_ULPI
74 help 204 help
75 Enable this to support Samsung USB phy controller for samsung 205 Provides read/write operations to the ULPI phy register set for
76 SoCs. 206 controllers with a viewport register (e.g. Chipidea/ARC controllers).
207
208endif # USB_PHY
diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile
index b13faa193e0c..33863c09f3dc 100644
--- a/drivers/usb/phy/Makefile
+++ b/drivers/usb/phy/Makefile
@@ -4,11 +4,30 @@
4 4
5ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG 5ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG
6 6
7obj-$(CONFIG_OMAP_USB2) += omap-usb2.o 7obj-$(CONFIG_USB_PHY) += phy.o
8obj-$(CONFIG_OMAP_USB3) += omap-usb3.o 8
9obj-$(CONFIG_OMAP_CONTROL_USB) += omap-control-usb.o 9# transceiver drivers, keep the list sorted
10obj-$(CONFIG_USB_ISP1301) += isp1301.o 10
11obj-$(CONFIG_MV_U3D_PHY) += mv_u3d_phy.o 11obj-$(CONFIG_AB8500_USB) += phy-ab8500-usb.o
12obj-$(CONFIG_USB_EHCI_TEGRA) += tegra_usb_phy.o 12phy-fsl-usb2-objs := phy-fsl-usb.o phy-fsm-usb.o
13obj-$(CONFIG_USB_RCAR_PHY) += rcar-phy.o 13obj-$(CONFIG_FSL_USB2_OTG) += phy-fsl-usb2.o
14obj-$(CONFIG_SAMSUNG_USBPHY) += samsung-usbphy.o 14obj-$(CONFIG_ISP1301_OMAP) += phy-isp1301.omap.o
15obj-$(CONFIG_MV_U3D_PHY) += phy-mv-u3d-usb.o
16obj-$(CONFIG_NOP_USB_XCEIV) += phy-nop.o
17obj-$(CONFIG_OMAP_CONTROL_USB) += phy-omap-control.o
18obj-$(CONFIG_OMAP_USB2) += phy-omap-usb2.o
19obj-$(CONFIG_OMAP_USB3) += phy-omap-usb3.o
20obj-$(CONFIG_SAMSUNG_USBPHY) += phy-samsung-usb.o
21obj-$(CONFIG_SAMSUNG_USB2PHY) += phy-samsung-usb2.o
22obj-$(CONFIG_SAMSUNG_USB3PHY) += phy-samsung-usb3.o
23obj-$(CONFIG_TWL4030_USB) += phy-twl4030-usb.o
24obj-$(CONFIG_TWL6030_USB) += phy-twl6030-usb.o
25obj-$(CONFIG_USB_EHCI_TEGRA) += phy-tegra-usb.o
26obj-$(CONFIG_USB_GPIO_VBUS) += phy-gpio-vbus-usb.o
27obj-$(CONFIG_USB_ISP1301) += phy-isp1301.o
28obj-$(CONFIG_USB_MSM_OTG) += phy-msm-usb.o
29obj-$(CONFIG_USB_MV_OTG) += phy-mv-usb.o
30obj-$(CONFIG_USB_MXS_PHY) += phy-mxs-usb.o
31obj-$(CONFIG_USB_RCAR_PHY) += phy-rcar-usb.o
32obj-$(CONFIG_USB_ULPI) += phy-ulpi.o
33obj-$(CONFIG_USB_ULPI_VIEWPORT) += phy-ulpi-viewport.o
diff --git a/drivers/usb/phy/isp1301.c b/drivers/usb/phy/isp1301.c
deleted file mode 100644
index 18dbf7e37607..000000000000
--- a/drivers/usb/phy/isp1301.c
+++ /dev/null
@@ -1,71 +0,0 @@
1/*
2 * NXP ISP1301 USB transceiver driver
3 *
4 * Copyright (C) 2012 Roland Stigge
5 *
6 * Author: Roland Stigge <stigge@antcom.de>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#include <linux/module.h>
14#include <linux/i2c.h>
15
16#define DRV_NAME "isp1301"
17
18static const struct i2c_device_id isp1301_id[] = {
19 { "isp1301", 0 },
20 { }
21};
22
23static struct i2c_client *isp1301_i2c_client;
24
25static int isp1301_probe(struct i2c_client *client,
26 const struct i2c_device_id *i2c_id)
27{
28 isp1301_i2c_client = client;
29 return 0;
30}
31
32static int isp1301_remove(struct i2c_client *client)
33{
34 return 0;
35}
36
37static struct i2c_driver isp1301_driver = {
38 .driver = {
39 .name = DRV_NAME,
40 },
41 .probe = isp1301_probe,
42 .remove = isp1301_remove,
43 .id_table = isp1301_id,
44};
45
46module_i2c_driver(isp1301_driver);
47
48static int match(struct device *dev, void *data)
49{
50 struct device_node *node = (struct device_node *)data;
51 return (dev->of_node == node) &&
52 (dev->driver == &isp1301_driver.driver);
53}
54
55struct i2c_client *isp1301_get_client(struct device_node *node)
56{
57 if (node) { /* reference of ISP1301 I2C node via DT */
58 struct device *dev = bus_find_device(&i2c_bus_type, NULL,
59 node, match);
60 if (!dev)
61 return NULL;
62 return to_i2c_client(dev);
63 } else { /* non-DT: only one ISP1301 chip supported */
64 return isp1301_i2c_client;
65 }
66}
67EXPORT_SYMBOL_GPL(isp1301_get_client);
68
69MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
70MODULE_DESCRIPTION("NXP ISP1301 USB transceiver driver");
71MODULE_LICENSE("GPL");
diff --git a/drivers/usb/phy/phy-ab8500-usb.c b/drivers/usb/phy/phy-ab8500-usb.c
new file mode 100644
index 000000000000..4acef26a2ef5
--- /dev/null
+++ b/drivers/usb/phy/phy-ab8500-usb.c
@@ -0,0 +1,924 @@
1/*
2 * drivers/usb/otg/ab8500_usb.c
3 *
4 * USB transceiver driver for AB8500 chip
5 *
6 * Copyright (C) 2010 ST-Ericsson AB
7 * Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include <linux/module.h>
26#include <linux/platform_device.h>
27#include <linux/usb/otg.h>
28#include <linux/slab.h>
29#include <linux/notifier.h>
30#include <linux/interrupt.h>
31#include <linux/delay.h>
32#include <linux/mfd/abx500.h>
33#include <linux/mfd/abx500/ab8500.h>
34#include <linux/usb/musb-ux500.h>
35#include <linux/regulator/consumer.h>
36#include <linux/pinctrl/consumer.h>
37
38/* Bank AB8500_SYS_CTRL2_BLOCK */
39#define AB8500_MAIN_WD_CTRL_REG 0x01
40
41/* Bank AB8500_USB */
42#define AB8500_USB_LINE_STAT_REG 0x80
43#define AB8505_USB_LINE_STAT_REG 0x94
44#define AB8500_USB_PHY_CTRL_REG 0x8A
45
46/* Bank AB8500_DEVELOPMENT */
47#define AB8500_BANK12_ACCESS 0x00
48
49/* Bank AB8500_DEBUG */
50#define AB8500_USB_PHY_TUNE1 0x05
51#define AB8500_USB_PHY_TUNE2 0x06
52#define AB8500_USB_PHY_TUNE3 0x07
53
54#define AB8500_BIT_OTG_STAT_ID (1 << 0)
55#define AB8500_BIT_PHY_CTRL_HOST_EN (1 << 0)
56#define AB8500_BIT_PHY_CTRL_DEVICE_EN (1 << 1)
57#define AB8500_BIT_WD_CTRL_ENABLE (1 << 0)
58#define AB8500_BIT_WD_CTRL_KICK (1 << 1)
59
60#define AB8500_WD_KICK_DELAY_US 100 /* usec */
61#define AB8500_WD_V11_DISABLE_DELAY_US 100 /* usec */
62#define AB8500_V20_31952_DISABLE_DELAY_US 100 /* usec */
63
64/* Usb line status register */
65enum ab8500_usb_link_status {
66 USB_LINK_NOT_CONFIGURED_8500 = 0,
67 USB_LINK_STD_HOST_NC_8500,
68 USB_LINK_STD_HOST_C_NS_8500,
69 USB_LINK_STD_HOST_C_S_8500,
70 USB_LINK_HOST_CHG_NM_8500,
71 USB_LINK_HOST_CHG_HS_8500,
72 USB_LINK_HOST_CHG_HS_CHIRP_8500,
73 USB_LINK_DEDICATED_CHG_8500,
74 USB_LINK_ACA_RID_A_8500,
75 USB_LINK_ACA_RID_B_8500,
76 USB_LINK_ACA_RID_C_NM_8500,
77 USB_LINK_ACA_RID_C_HS_8500,
78 USB_LINK_ACA_RID_C_HS_CHIRP_8500,
79 USB_LINK_HM_IDGND_8500,
80 USB_LINK_RESERVED_8500,
81 USB_LINK_NOT_VALID_LINK_8500,
82};
83
84enum ab8505_usb_link_status {
85 USB_LINK_NOT_CONFIGURED_8505 = 0,
86 USB_LINK_STD_HOST_NC_8505,
87 USB_LINK_STD_HOST_C_NS_8505,
88 USB_LINK_STD_HOST_C_S_8505,
89 USB_LINK_CDP_8505,
90 USB_LINK_RESERVED0_8505,
91 USB_LINK_RESERVED1_8505,
92 USB_LINK_DEDICATED_CHG_8505,
93 USB_LINK_ACA_RID_A_8505,
94 USB_LINK_ACA_RID_B_8505,
95 USB_LINK_ACA_RID_C_NM_8505,
96 USB_LINK_RESERVED2_8505,
97 USB_LINK_RESERVED3_8505,
98 USB_LINK_HM_IDGND_8505,
99 USB_LINK_CHARGERPORT_NOT_OK_8505,
100 USB_LINK_CHARGER_DM_HIGH_8505,
101 USB_LINK_PHYEN_NO_VBUS_NO_IDGND_8505,
102 USB_LINK_STD_UPSTREAM_NO_IDGNG_NO_VBUS_8505,
103 USB_LINK_STD_UPSTREAM_8505,
104 USB_LINK_CHARGER_SE1_8505,
105 USB_LINK_CARKIT_CHGR_1_8505,
106 USB_LINK_CARKIT_CHGR_2_8505,
107 USB_LINK_ACA_DOCK_CHGR_8505,
108 USB_LINK_SAMSUNG_BOOT_CBL_PHY_EN_8505,
109 USB_LINK_SAMSUNG_BOOT_CBL_PHY_DISB_8505,
110 USB_LINK_SAMSUNG_UART_CBL_PHY_EN_8505,
111 USB_LINK_SAMSUNG_UART_CBL_PHY_DISB_8505,
112 USB_LINK_MOTOROLA_FACTORY_CBL_PHY_EN_8505,
113};
114
115enum ab8500_usb_mode {
116 USB_IDLE = 0,
117 USB_PERIPHERAL,
118 USB_HOST,
119 USB_DEDICATED_CHG
120};
121
122struct ab8500_usb {
123 struct usb_phy phy;
124 struct device *dev;
125 struct ab8500 *ab8500;
126 unsigned vbus_draw;
127 struct work_struct phy_dis_work;
128 enum ab8500_usb_mode mode;
129 struct regulator *v_ape;
130 struct regulator *v_musb;
131 struct regulator *v_ulpi;
132 int saved_v_ulpi;
133 int previous_link_status_state;
134 struct pinctrl *pinctrl;
135 struct pinctrl_state *pins_sleep;
136};
137
138static inline struct ab8500_usb *phy_to_ab(struct usb_phy *x)
139{
140 return container_of(x, struct ab8500_usb, phy);
141}
142
143static void ab8500_usb_wd_workaround(struct ab8500_usb *ab)
144{
145 abx500_set_register_interruptible(ab->dev,
146 AB8500_SYS_CTRL2_BLOCK,
147 AB8500_MAIN_WD_CTRL_REG,
148 AB8500_BIT_WD_CTRL_ENABLE);
149
150 udelay(AB8500_WD_KICK_DELAY_US);
151
152 abx500_set_register_interruptible(ab->dev,
153 AB8500_SYS_CTRL2_BLOCK,
154 AB8500_MAIN_WD_CTRL_REG,
155 (AB8500_BIT_WD_CTRL_ENABLE
156 | AB8500_BIT_WD_CTRL_KICK));
157
158 udelay(AB8500_WD_V11_DISABLE_DELAY_US);
159
160 abx500_set_register_interruptible(ab->dev,
161 AB8500_SYS_CTRL2_BLOCK,
162 AB8500_MAIN_WD_CTRL_REG,
163 0);
164}
165
166static void ab8500_usb_regulator_enable(struct ab8500_usb *ab)
167{
168 int ret, volt;
169
170 ret = regulator_enable(ab->v_ape);
171 if (ret)
172 dev_err(ab->dev, "Failed to enable v-ape\n");
173
174 if (!is_ab8500_2p0_or_earlier(ab->ab8500)) {
175 ab->saved_v_ulpi = regulator_get_voltage(ab->v_ulpi);
176 if (ab->saved_v_ulpi < 0)
177 dev_err(ab->dev, "Failed to get v_ulpi voltage\n");
178
179 ret = regulator_set_voltage(ab->v_ulpi, 1300000, 1350000);
180 if (ret < 0)
181 dev_err(ab->dev, "Failed to set the Vintcore to 1.3V, ret=%d\n",
182 ret);
183
184 ret = regulator_set_optimum_mode(ab->v_ulpi, 28000);
185 if (ret < 0)
186 dev_err(ab->dev, "Failed to set optimum mode (ret=%d)\n",
187 ret);
188 }
189
190 ret = regulator_enable(ab->v_ulpi);
191 if (ret)
192 dev_err(ab->dev, "Failed to enable vddulpivio18\n");
193
194 if (!is_ab8500_2p0_or_earlier(ab->ab8500)) {
195 volt = regulator_get_voltage(ab->v_ulpi);
196 if ((volt != 1300000) && (volt != 1350000))
197 dev_err(ab->dev, "Vintcore is not set to 1.3V volt=%d\n",
198 volt);
199 }
200
201 ret = regulator_enable(ab->v_musb);
202 if (ret)
203 dev_err(ab->dev, "Failed to enable musb_1v8\n");
204}
205
206static void ab8500_usb_regulator_disable(struct ab8500_usb *ab)
207{
208 int ret;
209
210 regulator_disable(ab->v_musb);
211
212 regulator_disable(ab->v_ulpi);
213
214 /* USB is not the only consumer of Vintcore, restore old settings */
215 if (!is_ab8500_2p0_or_earlier(ab->ab8500)) {
216 if (ab->saved_v_ulpi > 0) {
217 ret = regulator_set_voltage(ab->v_ulpi,
218 ab->saved_v_ulpi, ab->saved_v_ulpi);
219 if (ret < 0)
220 dev_err(ab->dev, "Failed to set the Vintcore to %duV, ret=%d\n",
221 ab->saved_v_ulpi, ret);
222 }
223
224 ret = regulator_set_optimum_mode(ab->v_ulpi, 0);
225 if (ret < 0)
226 dev_err(ab->dev, "Failed to set optimum mode (ret=%d)\n",
227 ret);
228 }
229
230 regulator_disable(ab->v_ape);
231}
232
233static void ab8500_usb_wd_linkstatus(struct ab8500_usb *ab, u8 bit)
234{
235 /* Workaround for v2.0 bug # 31952 */
236 if (is_ab8500_2p0(ab->ab8500)) {
237 abx500_mask_and_set_register_interruptible(ab->dev,
238 AB8500_USB, AB8500_USB_PHY_CTRL_REG,
239 bit, bit);
240 udelay(AB8500_V20_31952_DISABLE_DELAY_US);
241 }
242}
243
244static void ab8500_usb_phy_enable(struct ab8500_usb *ab, bool sel_host)
245{
246 u8 bit;
247 bit = sel_host ? AB8500_BIT_PHY_CTRL_HOST_EN :
248 AB8500_BIT_PHY_CTRL_DEVICE_EN;
249
250 /* mux and configure USB pins to DEFAULT state */
251 ab->pinctrl = pinctrl_get_select(ab->dev, PINCTRL_STATE_DEFAULT);
252 if (IS_ERR(ab->pinctrl))
253 dev_err(ab->dev, "could not get/set default pinstate\n");
254
255 ab8500_usb_regulator_enable(ab);
256
257 abx500_mask_and_set_register_interruptible(ab->dev,
258 AB8500_USB, AB8500_USB_PHY_CTRL_REG,
259 bit, bit);
260}
261
262static void ab8500_usb_phy_disable(struct ab8500_usb *ab, bool sel_host)
263{
264 u8 bit;
265 bit = sel_host ? AB8500_BIT_PHY_CTRL_HOST_EN :
266 AB8500_BIT_PHY_CTRL_DEVICE_EN;
267
268 ab8500_usb_wd_linkstatus(ab, bit);
269
270 abx500_mask_and_set_register_interruptible(ab->dev,
271 AB8500_USB, AB8500_USB_PHY_CTRL_REG,
272 bit, 0);
273
274 /* Needed to disable the phy.*/
275 ab8500_usb_wd_workaround(ab);
276
277 ab8500_usb_regulator_disable(ab);
278
279 if (!IS_ERR(ab->pinctrl)) {
280 /* configure USB pins to SLEEP state */
281 ab->pins_sleep = pinctrl_lookup_state(ab->pinctrl,
282 PINCTRL_STATE_SLEEP);
283
284 if (IS_ERR(ab->pins_sleep))
285 dev_dbg(ab->dev, "could not get sleep pinstate\n");
286 else if (pinctrl_select_state(ab->pinctrl, ab->pins_sleep))
287 dev_err(ab->dev, "could not set pins to sleep state\n");
288
289 /* as USB pins are shared with idddet, release them to allow
290 * iddet to request them
291 */
292 pinctrl_put(ab->pinctrl);
293 }
294}
295
296#define ab8500_usb_host_phy_en(ab) ab8500_usb_phy_enable(ab, true)
297#define ab8500_usb_host_phy_dis(ab) ab8500_usb_phy_disable(ab, true)
298#define ab8500_usb_peri_phy_en(ab) ab8500_usb_phy_enable(ab, false)
299#define ab8500_usb_peri_phy_dis(ab) ab8500_usb_phy_disable(ab, false)
300
301static int ab8505_usb_link_status_update(struct ab8500_usb *ab,
302 enum ab8505_usb_link_status lsts)
303{
304 enum ux500_musb_vbus_id_status event = 0;
305
306 dev_dbg(ab->dev, "ab8505_usb_link_status_update %d\n", lsts);
307
308 /*
309 * Spurious link_status interrupts are seen at the time of
310 * disconnection of a device in RIDA state
311 */
312 if (ab->previous_link_status_state == USB_LINK_ACA_RID_A_8505 &&
313 (lsts == USB_LINK_STD_HOST_NC_8505))
314 return 0;
315
316 ab->previous_link_status_state = lsts;
317
318 switch (lsts) {
319 case USB_LINK_ACA_RID_B_8505:
320 event = UX500_MUSB_RIDB;
321 case USB_LINK_NOT_CONFIGURED_8505:
322 case USB_LINK_RESERVED0_8505:
323 case USB_LINK_RESERVED1_8505:
324 case USB_LINK_RESERVED2_8505:
325 case USB_LINK_RESERVED3_8505:
326 ab->mode = USB_IDLE;
327 ab->phy.otg->default_a = false;
328 ab->vbus_draw = 0;
329 if (event != UX500_MUSB_RIDB)
330 event = UX500_MUSB_NONE;
331 /*
332 * Fallback to default B_IDLE as nothing
333 * is connected
334 */
335 ab->phy.state = OTG_STATE_B_IDLE;
336 break;
337
338 case USB_LINK_ACA_RID_C_NM_8505:
339 event = UX500_MUSB_RIDC;
340 case USB_LINK_STD_HOST_NC_8505:
341 case USB_LINK_STD_HOST_C_NS_8505:
342 case USB_LINK_STD_HOST_C_S_8505:
343 case USB_LINK_CDP_8505:
344 if (ab->mode == USB_IDLE) {
345 ab->mode = USB_PERIPHERAL;
346 ab8500_usb_peri_phy_en(ab);
347 atomic_notifier_call_chain(&ab->phy.notifier,
348 UX500_MUSB_PREPARE, &ab->vbus_draw);
349 }
350 if (event != UX500_MUSB_RIDC)
351 event = UX500_MUSB_VBUS;
352 break;
353
354 case USB_LINK_ACA_RID_A_8505:
355 case USB_LINK_ACA_DOCK_CHGR_8505:
356 event = UX500_MUSB_RIDA;
357 case USB_LINK_HM_IDGND_8505:
358 if (ab->mode == USB_IDLE) {
359 ab->mode = USB_HOST;
360 ab8500_usb_host_phy_en(ab);
361 atomic_notifier_call_chain(&ab->phy.notifier,
362 UX500_MUSB_PREPARE, &ab->vbus_draw);
363 }
364 ab->phy.otg->default_a = true;
365 if (event != UX500_MUSB_RIDA)
366 event = UX500_MUSB_ID;
367 atomic_notifier_call_chain(&ab->phy.notifier,
368 event, &ab->vbus_draw);
369 break;
370
371 case USB_LINK_DEDICATED_CHG_8505:
372 ab->mode = USB_DEDICATED_CHG;
373 event = UX500_MUSB_CHARGER;
374 atomic_notifier_call_chain(&ab->phy.notifier,
375 event, &ab->vbus_draw);
376 break;
377
378 default:
379 break;
380 }
381
382 return 0;
383}
384
385static int ab8500_usb_link_status_update(struct ab8500_usb *ab,
386 enum ab8500_usb_link_status lsts)
387{
388 enum ux500_musb_vbus_id_status event = 0;
389
390 dev_dbg(ab->dev, "ab8500_usb_link_status_update %d\n", lsts);
391
392 /*
393 * Spurious link_status interrupts are seen in case of a
394 * disconnection of a device in IDGND and RIDA stage
395 */
396 if (ab->previous_link_status_state == USB_LINK_HM_IDGND_8500 &&
397 (lsts == USB_LINK_STD_HOST_C_NS_8500 ||
398 lsts == USB_LINK_STD_HOST_NC_8500))
399 return 0;
400
401 if (ab->previous_link_status_state == USB_LINK_ACA_RID_A_8500 &&
402 lsts == USB_LINK_STD_HOST_NC_8500)
403 return 0;
404
405 ab->previous_link_status_state = lsts;
406
407 switch (lsts) {
408 case USB_LINK_ACA_RID_B_8500:
409 event = UX500_MUSB_RIDB;
410 case USB_LINK_NOT_CONFIGURED_8500:
411 case USB_LINK_NOT_VALID_LINK_8500:
412 ab->mode = USB_IDLE;
413 ab->phy.otg->default_a = false;
414 ab->vbus_draw = 0;
415 if (event != UX500_MUSB_RIDB)
416 event = UX500_MUSB_NONE;
417 /* Fallback to default B_IDLE as nothing is connected */
418 ab->phy.state = OTG_STATE_B_IDLE;
419 break;
420
421 case USB_LINK_ACA_RID_C_NM_8500:
422 case USB_LINK_ACA_RID_C_HS_8500:
423 case USB_LINK_ACA_RID_C_HS_CHIRP_8500:
424 event = UX500_MUSB_RIDC;
425 case USB_LINK_STD_HOST_NC_8500:
426 case USB_LINK_STD_HOST_C_NS_8500:
427 case USB_LINK_STD_HOST_C_S_8500:
428 case USB_LINK_HOST_CHG_NM_8500:
429 case USB_LINK_HOST_CHG_HS_8500:
430 case USB_LINK_HOST_CHG_HS_CHIRP_8500:
431 if (ab->mode == USB_IDLE) {
432 ab->mode = USB_PERIPHERAL;
433 ab8500_usb_peri_phy_en(ab);
434 atomic_notifier_call_chain(&ab->phy.notifier,
435 UX500_MUSB_PREPARE, &ab->vbus_draw);
436 }
437 if (event != UX500_MUSB_RIDC)
438 event = UX500_MUSB_VBUS;
439 break;
440
441 case USB_LINK_ACA_RID_A_8500:
442 event = UX500_MUSB_RIDA;
443 case USB_LINK_HM_IDGND_8500:
444 if (ab->mode == USB_IDLE) {
445 ab->mode = USB_HOST;
446 ab8500_usb_host_phy_en(ab);
447 atomic_notifier_call_chain(&ab->phy.notifier,
448 UX500_MUSB_PREPARE, &ab->vbus_draw);
449 }
450 ab->phy.otg->default_a = true;
451 if (event != UX500_MUSB_RIDA)
452 event = UX500_MUSB_ID;
453 atomic_notifier_call_chain(&ab->phy.notifier,
454 event, &ab->vbus_draw);
455 break;
456
457 case USB_LINK_DEDICATED_CHG_8500:
458 ab->mode = USB_DEDICATED_CHG;
459 event = UX500_MUSB_CHARGER;
460 atomic_notifier_call_chain(&ab->phy.notifier,
461 event, &ab->vbus_draw);
462 break;
463
464 case USB_LINK_RESERVED_8500:
465 break;
466 }
467
468 return 0;
469}
470
471/*
472 * Connection Sequence:
473 * 1. Link Status Interrupt
474 * 2. Enable AB clock
475 * 3. Enable AB regulators
476 * 4. Enable USB phy
477 * 5. Reset the musb controller
478 * 6. Switch the ULPI GPIO pins to fucntion mode
479 * 7. Enable the musb Peripheral5 clock
480 * 8. Restore MUSB context
481 */
482static int abx500_usb_link_status_update(struct ab8500_usb *ab)
483{
484 u8 reg;
485 int ret = 0;
486
487 if (is_ab8500(ab->ab8500)) {
488 enum ab8500_usb_link_status lsts;
489
490 abx500_get_register_interruptible(ab->dev,
491 AB8500_USB, AB8500_USB_LINE_STAT_REG, &reg);
492 lsts = (reg >> 3) & 0x0F;
493 ret = ab8500_usb_link_status_update(ab, lsts);
494 } else if (is_ab8505(ab->ab8500)) {
495 enum ab8505_usb_link_status lsts;
496
497 abx500_get_register_interruptible(ab->dev,
498 AB8500_USB, AB8505_USB_LINE_STAT_REG, &reg);
499 lsts = (reg >> 3) & 0x1F;
500 ret = ab8505_usb_link_status_update(ab, lsts);
501 }
502
503 return ret;
504}
505
506/*
507 * Disconnection Sequence:
508 * 1. Disconect Interrupt
509 * 2. Disable regulators
510 * 3. Disable AB clock
511 * 4. Disable the Phy
512 * 5. Link Status Interrupt
513 * 6. Disable Musb Clock
514 */
515static irqreturn_t ab8500_usb_disconnect_irq(int irq, void *data)
516{
517 struct ab8500_usb *ab = (struct ab8500_usb *) data;
518 enum usb_phy_events event = UX500_MUSB_NONE;
519
520 /* Link status will not be updated till phy is disabled. */
521 if (ab->mode == USB_HOST) {
522 ab->phy.otg->default_a = false;
523 ab->vbus_draw = 0;
524 atomic_notifier_call_chain(&ab->phy.notifier,
525 event, &ab->vbus_draw);
526 ab8500_usb_host_phy_dis(ab);
527 ab->mode = USB_IDLE;
528 }
529
530 if (ab->mode == USB_PERIPHERAL) {
531 atomic_notifier_call_chain(&ab->phy.notifier,
532 event, &ab->vbus_draw);
533 ab8500_usb_peri_phy_dis(ab);
534 atomic_notifier_call_chain(&ab->phy.notifier,
535 UX500_MUSB_CLEAN, &ab->vbus_draw);
536 ab->mode = USB_IDLE;
537 ab->phy.otg->default_a = false;
538 ab->vbus_draw = 0;
539 }
540
541 if (is_ab8500_2p0(ab->ab8500)) {
542 if (ab->mode == USB_DEDICATED_CHG) {
543 ab8500_usb_wd_linkstatus(ab,
544 AB8500_BIT_PHY_CTRL_DEVICE_EN);
545 abx500_mask_and_set_register_interruptible(ab->dev,
546 AB8500_USB, AB8500_USB_PHY_CTRL_REG,
547 AB8500_BIT_PHY_CTRL_DEVICE_EN, 0);
548 }
549 }
550
551 return IRQ_HANDLED;
552}
553
554static irqreturn_t ab8500_usb_link_status_irq(int irq, void *data)
555{
556 struct ab8500_usb *ab = (struct ab8500_usb *) data;
557
558 abx500_usb_link_status_update(ab);
559
560 return IRQ_HANDLED;
561}
562
563static void ab8500_usb_phy_disable_work(struct work_struct *work)
564{
565 struct ab8500_usb *ab = container_of(work, struct ab8500_usb,
566 phy_dis_work);
567
568 if (!ab->phy.otg->host)
569 ab8500_usb_host_phy_dis(ab);
570
571 if (!ab->phy.otg->gadget)
572 ab8500_usb_peri_phy_dis(ab);
573}
574
575static unsigned ab8500_eyediagram_workaroud(struct ab8500_usb *ab, unsigned mA)
576{
577 /*
578 * AB8500 V2 has eye diagram issues when drawing more than 100mA from
579 * VBUS. Set charging current to 100mA in case of standard host
580 */
581 if (is_ab8500_2p0_or_earlier(ab->ab8500))
582 if (mA > 100)
583 mA = 100;
584
585 return mA;
586}
587
588static int ab8500_usb_set_power(struct usb_phy *phy, unsigned mA)
589{
590 struct ab8500_usb *ab;
591
592 if (!phy)
593 return -ENODEV;
594
595 ab = phy_to_ab(phy);
596
597 mA = ab8500_eyediagram_workaroud(ab, mA);
598
599 ab->vbus_draw = mA;
600
601 atomic_notifier_call_chain(&ab->phy.notifier,
602 UX500_MUSB_VBUS, &ab->vbus_draw);
603
604 return 0;
605}
606
607static int ab8500_usb_set_suspend(struct usb_phy *x, int suspend)
608{
609 /* TODO */
610 return 0;
611}
612
613static int ab8500_usb_set_peripheral(struct usb_otg *otg,
614 struct usb_gadget *gadget)
615{
616 struct ab8500_usb *ab;
617
618 if (!otg)
619 return -ENODEV;
620
621 ab = phy_to_ab(otg->phy);
622
623 ab->phy.otg->gadget = gadget;
624
625 /* Some drivers call this function in atomic context.
626 * Do not update ab8500 registers directly till this
627 * is fixed.
628 */
629
630 if ((ab->mode != USB_IDLE) && (!gadget)) {
631 ab->mode = USB_IDLE;
632 schedule_work(&ab->phy_dis_work);
633 }
634
635 return 0;
636}
637
638static int ab8500_usb_set_host(struct usb_otg *otg, struct usb_bus *host)
639{
640 struct ab8500_usb *ab;
641
642 if (!otg)
643 return -ENODEV;
644
645 ab = phy_to_ab(otg->phy);
646
647 ab->phy.otg->host = host;
648
649 /* Some drivers call this function in atomic context.
650 * Do not update ab8500 registers directly till this
651 * is fixed.
652 */
653
654 if ((ab->mode != USB_IDLE) && (!host)) {
655 ab->mode = USB_IDLE;
656 schedule_work(&ab->phy_dis_work);
657 }
658
659 return 0;
660}
661
662static int ab8500_usb_regulator_get(struct ab8500_usb *ab)
663{
664 int err;
665
666 ab->v_ape = devm_regulator_get(ab->dev, "v-ape");
667 if (IS_ERR(ab->v_ape)) {
668 dev_err(ab->dev, "Could not get v-ape supply\n");
669 err = PTR_ERR(ab->v_ape);
670 return err;
671 }
672
673 ab->v_ulpi = devm_regulator_get(ab->dev, "vddulpivio18");
674 if (IS_ERR(ab->v_ulpi)) {
675 dev_err(ab->dev, "Could not get vddulpivio18 supply\n");
676 err = PTR_ERR(ab->v_ulpi);
677 return err;
678 }
679
680 ab->v_musb = devm_regulator_get(ab->dev, "musb_1v8");
681 if (IS_ERR(ab->v_musb)) {
682 dev_err(ab->dev, "Could not get musb_1v8 supply\n");
683 err = PTR_ERR(ab->v_musb);
684 return err;
685 }
686
687 return 0;
688}
689
690static int ab8500_usb_irq_setup(struct platform_device *pdev,
691 struct ab8500_usb *ab)
692{
693 int err;
694 int irq;
695
696 irq = platform_get_irq_byname(pdev, "USB_LINK_STATUS");
697 if (irq < 0) {
698 dev_err(&pdev->dev, "Link status irq not found\n");
699 return irq;
700 }
701 err = devm_request_threaded_irq(&pdev->dev, irq, NULL,
702 ab8500_usb_link_status_irq,
703 IRQF_NO_SUSPEND | IRQF_SHARED, "usb-link-status", ab);
704 if (err < 0) {
705 dev_err(ab->dev, "request_irq failed for link status irq\n");
706 return err;
707 }
708
709 irq = platform_get_irq_byname(pdev, "ID_WAKEUP_F");
710 if (irq < 0) {
711 dev_err(&pdev->dev, "ID fall irq not found\n");
712 return irq;
713 }
714 err = devm_request_threaded_irq(&pdev->dev, irq, NULL,
715 ab8500_usb_disconnect_irq,
716 IRQF_NO_SUSPEND | IRQF_SHARED, "usb-id-fall", ab);
717 if (err < 0) {
718 dev_err(ab->dev, "request_irq failed for ID fall irq\n");
719 return err;
720 }
721
722 irq = platform_get_irq_byname(pdev, "VBUS_DET_F");
723 if (irq < 0) {
724 dev_err(&pdev->dev, "VBUS fall irq not found\n");
725 return irq;
726 }
727 err = devm_request_threaded_irq(&pdev->dev, irq, NULL,
728 ab8500_usb_disconnect_irq,
729 IRQF_NO_SUSPEND | IRQF_SHARED, "usb-vbus-fall", ab);
730 if (err < 0) {
731 dev_err(ab->dev, "request_irq failed for Vbus fall irq\n");
732 return err;
733 }
734
735 return 0;
736}
737
738static int ab8500_usb_probe(struct platform_device *pdev)
739{
740 struct ab8500_usb *ab;
741 struct ab8500 *ab8500;
742 struct usb_otg *otg;
743 int err;
744 int rev;
745
746 ab8500 = dev_get_drvdata(pdev->dev.parent);
747 rev = abx500_get_chip_id(&pdev->dev);
748
749 if (is_ab8500_1p1_or_earlier(ab8500)) {
750 dev_err(&pdev->dev, "Unsupported AB8500 chip rev=%d\n", rev);
751 return -ENODEV;
752 }
753
754 ab = devm_kzalloc(&pdev->dev, sizeof(*ab), GFP_KERNEL);
755 if (!ab)
756 return -ENOMEM;
757
758 otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL);
759 if (!otg)
760 return -ENOMEM;
761
762 ab->dev = &pdev->dev;
763 ab->ab8500 = ab8500;
764 ab->phy.dev = ab->dev;
765 ab->phy.otg = otg;
766 ab->phy.label = "ab8500";
767 ab->phy.set_suspend = ab8500_usb_set_suspend;
768 ab->phy.set_power = ab8500_usb_set_power;
769 ab->phy.state = OTG_STATE_UNDEFINED;
770
771 otg->phy = &ab->phy;
772 otg->set_host = ab8500_usb_set_host;
773 otg->set_peripheral = ab8500_usb_set_peripheral;
774
775 platform_set_drvdata(pdev, ab);
776
777 ATOMIC_INIT_NOTIFIER_HEAD(&ab->phy.notifier);
778
779 /* all: Disable phy when called from set_host and set_peripheral */
780 INIT_WORK(&ab->phy_dis_work, ab8500_usb_phy_disable_work);
781
782 err = ab8500_usb_regulator_get(ab);
783 if (err)
784 return err;
785
786 err = ab8500_usb_irq_setup(pdev, ab);
787 if (err < 0)
788 return err;
789
790 err = usb_add_phy(&ab->phy, USB_PHY_TYPE_USB2);
791 if (err) {
792 dev_err(&pdev->dev, "Can't register transceiver\n");
793 return err;
794 }
795
796 /* Phy tuning values for AB8500 */
797 if (!is_ab8500_2p0_or_earlier(ab->ab8500)) {
798 /* Enable the PBT/Bank 0x12 access */
799 err = abx500_set_register_interruptible(ab->dev,
800 AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, 0x01);
801 if (err < 0)
802 dev_err(ab->dev, "Failed to enable bank12 access err=%d\n",
803 err);
804
805 err = abx500_set_register_interruptible(ab->dev,
806 AB8500_DEBUG, AB8500_USB_PHY_TUNE1, 0xC8);
807 if (err < 0)
808 dev_err(ab->dev, "Failed to set PHY_TUNE1 register err=%d\n",
809 err);
810
811 err = abx500_set_register_interruptible(ab->dev,
812 AB8500_DEBUG, AB8500_USB_PHY_TUNE2, 0x00);
813 if (err < 0)
814 dev_err(ab->dev, "Failed to set PHY_TUNE2 register err=%d\n",
815 err);
816
817 err = abx500_set_register_interruptible(ab->dev,
818 AB8500_DEBUG, AB8500_USB_PHY_TUNE3, 0x78);
819 if (err < 0)
820 dev_err(ab->dev, "Failed to set PHY_TUNE3 regester err=%d\n",
821 err);
822
823 /* Switch to normal mode/disable Bank 0x12 access */
824 err = abx500_set_register_interruptible(ab->dev,
825 AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, 0x00);
826 if (err < 0)
827 dev_err(ab->dev, "Failed to switch bank12 access err=%d\n",
828 err);
829 }
830
831 /* Phy tuning values for AB8505 */
832 if (is_ab8505(ab->ab8500)) {
833 /* Enable the PBT/Bank 0x12 access */
834 err = abx500_mask_and_set_register_interruptible(ab->dev,
835 AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS,
836 0x01, 0x01);
837 if (err < 0)
838 dev_err(ab->dev, "Failed to enable bank12 access err=%d\n",
839 err);
840
841 err = abx500_mask_and_set_register_interruptible(ab->dev,
842 AB8500_DEBUG, AB8500_USB_PHY_TUNE1,
843 0xC8, 0xC8);
844 if (err < 0)
845 dev_err(ab->dev, "Failed to set PHY_TUNE1 register err=%d\n",
846 err);
847
848 err = abx500_mask_and_set_register_interruptible(ab->dev,
849 AB8500_DEBUG, AB8500_USB_PHY_TUNE2,
850 0x60, 0x60);
851 if (err < 0)
852 dev_err(ab->dev, "Failed to set PHY_TUNE2 register err=%d\n",
853 err);
854
855 err = abx500_mask_and_set_register_interruptible(ab->dev,
856 AB8500_DEBUG, AB8500_USB_PHY_TUNE3,
857 0xFC, 0x80);
858
859 if (err < 0)
860 dev_err(ab->dev, "Failed to set PHY_TUNE3 regester err=%d\n",
861 err);
862
863 /* Switch to normal mode/disable Bank 0x12 access */
864 err = abx500_mask_and_set_register_interruptible(ab->dev,
865 AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS,
866 0x00, 0x00);
867 if (err < 0)
868 dev_err(ab->dev, "Failed to switch bank12 access err=%d\n",
869 err);
870 }
871
872 /* Needed to enable ID detection. */
873 ab8500_usb_wd_workaround(ab);
874
875 abx500_usb_link_status_update(ab);
876
877 dev_info(&pdev->dev, "revision 0x%2x driver initialized\n", rev);
878
879 return 0;
880}
881
882static int ab8500_usb_remove(struct platform_device *pdev)
883{
884 struct ab8500_usb *ab = platform_get_drvdata(pdev);
885
886 cancel_work_sync(&ab->phy_dis_work);
887
888 usb_remove_phy(&ab->phy);
889
890 if (ab->mode == USB_HOST)
891 ab8500_usb_host_phy_dis(ab);
892 else if (ab->mode == USB_PERIPHERAL)
893 ab8500_usb_peri_phy_dis(ab);
894
895 platform_set_drvdata(pdev, NULL);
896
897 return 0;
898}
899
900static struct platform_driver ab8500_usb_driver = {
901 .probe = ab8500_usb_probe,
902 .remove = ab8500_usb_remove,
903 .driver = {
904 .name = "ab8500-usb",
905 .owner = THIS_MODULE,
906 },
907};
908
909static int __init ab8500_usb_init(void)
910{
911 return platform_driver_register(&ab8500_usb_driver);
912}
913subsys_initcall(ab8500_usb_init);
914
915static void __exit ab8500_usb_exit(void)
916{
917 platform_driver_unregister(&ab8500_usb_driver);
918}
919module_exit(ab8500_usb_exit);
920
921MODULE_ALIAS("platform:ab8500_usb");
922MODULE_AUTHOR("ST-Ericsson AB");
923MODULE_DESCRIPTION("AB8500 usb transceiver driver");
924MODULE_LICENSE("GPL");
diff --git a/drivers/usb/otg/fsl_otg.c b/drivers/usb/phy/phy-fsl-usb.c
index d16adb41eb21..97b9308507c3 100644
--- a/drivers/usb/otg/fsl_otg.c
+++ b/drivers/usb/phy/phy-fsl-usb.c
@@ -43,7 +43,7 @@
43 43
44#include <asm/unaligned.h> 44#include <asm/unaligned.h>
45 45
46#include "fsl_otg.h" 46#include "phy-fsl-usb.h"
47 47
48#define DRIVER_VERSION "Rev. 1.55" 48#define DRIVER_VERSION "Rev. 1.55"
49#define DRIVER_AUTHOR "Jerry Huang/Li Yang" 49#define DRIVER_AUTHOR "Jerry Huang/Li Yang"
@@ -361,28 +361,18 @@ int fsl_otg_init_timers(struct otg_fsm *fsm)
361void fsl_otg_uninit_timers(void) 361void fsl_otg_uninit_timers(void)
362{ 362{
363 /* FSM used timers */ 363 /* FSM used timers */
364 if (a_wait_vrise_tmr != NULL) 364 kfree(a_wait_vrise_tmr);
365 kfree(a_wait_vrise_tmr); 365 kfree(a_wait_bcon_tmr);
366 if (a_wait_bcon_tmr != NULL) 366 kfree(a_aidl_bdis_tmr);
367 kfree(a_wait_bcon_tmr); 367 kfree(b_ase0_brst_tmr);
368 if (a_aidl_bdis_tmr != NULL) 368 kfree(b_se0_srp_tmr);
369 kfree(a_aidl_bdis_tmr); 369 kfree(b_srp_fail_tmr);
370 if (b_ase0_brst_tmr != NULL) 370 kfree(a_wait_enum_tmr);
371 kfree(b_ase0_brst_tmr);
372 if (b_se0_srp_tmr != NULL)
373 kfree(b_se0_srp_tmr);
374 if (b_srp_fail_tmr != NULL)
375 kfree(b_srp_fail_tmr);
376 if (a_wait_enum_tmr != NULL)
377 kfree(a_wait_enum_tmr);
378 371
379 /* device driver used timers */ 372 /* device driver used timers */
380 if (b_srp_wait_tmr != NULL) 373 kfree(b_srp_wait_tmr);
381 kfree(b_srp_wait_tmr); 374 kfree(b_data_pulse_tmr);
382 if (b_data_pulse_tmr != NULL) 375 kfree(b_vbus_pulse_tmr);
383 kfree(b_data_pulse_tmr);
384 if (b_vbus_pulse_tmr != NULL)
385 kfree(b_vbus_pulse_tmr);
386} 376}
387 377
388/* Add timer to timer list */ 378/* Add timer to timer list */
@@ -1002,7 +992,7 @@ static int show_fsl_usb2_otg_state(struct device *dev,
1002 /* State */ 992 /* State */
1003 t = scnprintf(next, size, 993 t = scnprintf(next, size,
1004 "OTG state: %s\n\n", 994 "OTG state: %s\n\n",
1005 otg_state_string(fsl_otg_dev->phy.state)); 995 usb_otg_state_string(fsl_otg_dev->phy.state));
1006 size -= t; 996 size -= t;
1007 next += t; 997 next += t;
1008 998
diff --git a/drivers/usb/otg/fsl_otg.h b/drivers/usb/phy/phy-fsl-usb.h
index ca266280895d..ca266280895d 100644
--- a/drivers/usb/otg/fsl_otg.h
+++ b/drivers/usb/phy/phy-fsl-usb.h
diff --git a/drivers/usb/otg/otg_fsm.c b/drivers/usb/phy/phy-fsm-usb.c
index ade131a8ae5e..c520b3548e7c 100644
--- a/drivers/usb/otg/otg_fsm.c
+++ b/drivers/usb/phy/phy-fsm-usb.c
@@ -29,7 +29,7 @@
29#include <linux/usb/gadget.h> 29#include <linux/usb/gadget.h>
30#include <linux/usb/otg.h> 30#include <linux/usb/otg.h>
31 31
32#include "otg_fsm.h" 32#include "phy-otg-fsm.h"
33 33
34/* Change USB protocol when there is a protocol change */ 34/* Change USB protocol when there is a protocol change */
35static int otg_set_protocol(struct otg_fsm *fsm, int protocol) 35static int otg_set_protocol(struct otg_fsm *fsm, int protocol)
@@ -119,7 +119,7 @@ int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state)
119 state_changed = 1; 119 state_changed = 1;
120 if (fsm->otg->phy->state == new_state) 120 if (fsm->otg->phy->state == new_state)
121 return 0; 121 return 0;
122 VDBG("Set state: %s\n", otg_state_string(new_state)); 122 VDBG("Set state: %s\n", usb_otg_state_string(new_state));
123 otg_leave_state(fsm, fsm->otg->phy->state); 123 otg_leave_state(fsm, fsm->otg->phy->state);
124 switch (new_state) { 124 switch (new_state) {
125 case OTG_STATE_B_IDLE: 125 case OTG_STATE_B_IDLE:
diff --git a/drivers/usb/otg/otg_fsm.h b/drivers/usb/phy/phy-fsm-usb.h
index c30a2e1d9e46..c30a2e1d9e46 100644
--- a/drivers/usb/otg/otg_fsm.h
+++ b/drivers/usb/phy/phy-fsm-usb.h
diff --git a/drivers/usb/otg/gpio_vbus.c b/drivers/usb/phy/phy-gpio-vbus-usb.c
index a7d4ac591982..4c76074e518d 100644
--- a/drivers/usb/otg/gpio_vbus.c
+++ b/drivers/usb/phy/phy-gpio-vbus-usb.c
@@ -61,6 +61,7 @@ static void set_vbus_draw(struct gpio_vbus_data *gpio_vbus, unsigned mA)
61{ 61{
62 struct regulator *vbus_draw = gpio_vbus->vbus_draw; 62 struct regulator *vbus_draw = gpio_vbus->vbus_draw;
63 int enabled; 63 int enabled;
64 int ret;
64 65
65 if (!vbus_draw) 66 if (!vbus_draw)
66 return; 67 return;
@@ -69,12 +70,16 @@ static void set_vbus_draw(struct gpio_vbus_data *gpio_vbus, unsigned mA)
69 if (mA) { 70 if (mA) {
70 regulator_set_current_limit(vbus_draw, 0, 1000 * mA); 71 regulator_set_current_limit(vbus_draw, 0, 1000 * mA);
71 if (!enabled) { 72 if (!enabled) {
72 regulator_enable(vbus_draw); 73 ret = regulator_enable(vbus_draw);
74 if (ret < 0)
75 return;
73 gpio_vbus->vbus_draw_enabled = 1; 76 gpio_vbus->vbus_draw_enabled = 1;
74 } 77 }
75 } else { 78 } else {
76 if (enabled) { 79 if (enabled) {
77 regulator_disable(vbus_draw); 80 ret = regulator_disable(vbus_draw);
81 if (ret < 0)
82 return;
78 gpio_vbus->vbus_draw_enabled = 0; 83 gpio_vbus->vbus_draw_enabled = 0;
79 } 84 }
80 } 85 }
diff --git a/drivers/usb/otg/isp1301_omap.c b/drivers/usb/phy/phy-isp1301-omap.c
index af9cb11626b2..ae481afcb3ec 100644
--- a/drivers/usb/otg/isp1301_omap.c
+++ b/drivers/usb/phy/phy-isp1301-omap.c
@@ -236,7 +236,7 @@ isp1301_clear_bits(struct isp1301 *isp, u8 reg, u8 bits)
236 236
237static inline const char *state_name(struct isp1301 *isp) 237static inline const char *state_name(struct isp1301 *isp)
238{ 238{
239 return otg_state_string(isp->phy.state); 239 return usb_otg_state_string(isp->phy.state);
240} 240}
241 241
242/*-------------------------------------------------------------------------*/ 242/*-------------------------------------------------------------------------*/
@@ -481,7 +481,7 @@ static void check_state(struct isp1301 *isp, const char *tag)
481 if (isp->phy.state == state && !extra) 481 if (isp->phy.state == state && !extra)
482 return; 482 return;
483 pr_debug("otg: %s FSM %s/%02x, %s, %06x\n", tag, 483 pr_debug("otg: %s FSM %s/%02x, %s, %06x\n", tag,
484 otg_state_string(state), fsm, state_name(isp), 484 usb_otg_state_string(state), fsm, state_name(isp),
485 omap_readl(OTG_CTRL)); 485 omap_readl(OTG_CTRL));
486} 486}
487 487
@@ -1077,7 +1077,7 @@ static void isp_update_otg(struct isp1301 *isp, u8 stat)
1077 1077
1078 if (state != isp->phy.state) 1078 if (state != isp->phy.state)
1079 pr_debug(" isp, %s -> %s\n", 1079 pr_debug(" isp, %s -> %s\n",
1080 otg_state_string(state), state_name(isp)); 1080 usb_otg_state_string(state), state_name(isp));
1081 1081
1082#ifdef CONFIG_USB_OTG 1082#ifdef CONFIG_USB_OTG
1083 /* update the OTG controller state to match the isp1301; may 1083 /* update the OTG controller state to match the isp1301; may
@@ -1212,7 +1212,7 @@ static void isp1301_release(struct device *dev)
1212 1212
1213static struct isp1301 *the_transceiver; 1213static struct isp1301 *the_transceiver;
1214 1214
1215static int __exit isp1301_remove(struct i2c_client *i2c) 1215static int isp1301_remove(struct i2c_client *i2c)
1216{ 1216{
1217 struct isp1301 *isp; 1217 struct isp1301 *isp;
1218 1218
@@ -1634,7 +1634,7 @@ static struct i2c_driver isp1301_driver = {
1634 .name = "isp1301_omap", 1634 .name = "isp1301_omap",
1635 }, 1635 },
1636 .probe = isp1301_probe, 1636 .probe = isp1301_probe,
1637 .remove = __exit_p(isp1301_remove), 1637 .remove = isp1301_remove,
1638 .id_table = isp1301_id, 1638 .id_table = isp1301_id,
1639}; 1639};
1640 1640
diff --git a/drivers/usb/phy/phy-isp1301.c b/drivers/usb/phy/phy-isp1301.c
new file mode 100644
index 000000000000..225ae6c97eeb
--- /dev/null
+++ b/drivers/usb/phy/phy-isp1301.c
@@ -0,0 +1,162 @@
1/*
2 * NXP ISP1301 USB transceiver driver
3 *
4 * Copyright (C) 2012 Roland Stigge
5 *
6 * Author: Roland Stigge <stigge@antcom.de>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#include <linux/module.h>
14#include <linux/mutex.h>
15#include <linux/i2c.h>
16#include <linux/usb/phy.h>
17#include <linux/usb/isp1301.h>
18
19#define DRV_NAME "isp1301"
20
21struct isp1301 {
22 struct usb_phy phy;
23 struct mutex mutex;
24
25 struct i2c_client *client;
26};
27
28#define phy_to_isp(p) (container_of((p), struct isp1301, phy))
29
30static const struct i2c_device_id isp1301_id[] = {
31 { "isp1301", 0 },
32 { }
33};
34
35static struct i2c_client *isp1301_i2c_client;
36
37static int __isp1301_write(struct isp1301 *isp, u8 reg, u8 value, u8 clear)
38{
39 return i2c_smbus_write_byte_data(isp->client, reg | clear, value);
40}
41
42static int isp1301_write(struct isp1301 *isp, u8 reg, u8 value)
43{
44 return __isp1301_write(isp, reg, value, 0);
45}
46
47static int isp1301_clear(struct isp1301 *isp, u8 reg, u8 value)
48{
49 return __isp1301_write(isp, reg, value, ISP1301_I2C_REG_CLEAR_ADDR);
50}
51
52static int isp1301_phy_init(struct usb_phy *phy)
53{
54 struct isp1301 *isp = phy_to_isp(phy);
55
56 /* Disable transparent UART mode first */
57 isp1301_clear(isp, ISP1301_I2C_MODE_CONTROL_1, MC1_UART_EN);
58 isp1301_clear(isp, ISP1301_I2C_MODE_CONTROL_1, ~MC1_SPEED_REG);
59 isp1301_write(isp, ISP1301_I2C_MODE_CONTROL_1, MC1_SPEED_REG);
60 isp1301_clear(isp, ISP1301_I2C_MODE_CONTROL_2, ~0);
61 isp1301_write(isp, ISP1301_I2C_MODE_CONTROL_2, (MC2_BI_DI | MC2_PSW_EN
62 | MC2_SPD_SUSP_CTRL));
63
64 isp1301_clear(isp, ISP1301_I2C_OTG_CONTROL_1, ~0);
65 isp1301_write(isp, ISP1301_I2C_MODE_CONTROL_1, MC1_DAT_SE0);
66 isp1301_write(isp, ISP1301_I2C_OTG_CONTROL_1, (OTG1_DM_PULLDOWN
67 | OTG1_DP_PULLDOWN));
68 isp1301_clear(isp, ISP1301_I2C_OTG_CONTROL_1, (OTG1_DM_PULLUP
69 | OTG1_DP_PULLUP));
70
71 /* mask all interrupts */
72 isp1301_clear(isp, ISP1301_I2C_INTERRUPT_LATCH, ~0);
73 isp1301_clear(isp, ISP1301_I2C_INTERRUPT_FALLING, ~0);
74 isp1301_clear(isp, ISP1301_I2C_INTERRUPT_RISING, ~0);
75
76 return 0;
77}
78
79static int isp1301_phy_set_vbus(struct usb_phy *phy, int on)
80{
81 struct isp1301 *isp = phy_to_isp(phy);
82
83 if (on)
84 isp1301_write(isp, ISP1301_I2C_OTG_CONTROL_1, OTG1_VBUS_DRV);
85 else
86 isp1301_clear(isp, ISP1301_I2C_OTG_CONTROL_1, OTG1_VBUS_DRV);
87
88 return 0;
89}
90
91static int isp1301_probe(struct i2c_client *client,
92 const struct i2c_device_id *i2c_id)
93{
94 struct isp1301 *isp;
95 struct usb_phy *phy;
96
97 isp = devm_kzalloc(&client->dev, sizeof(*isp), GFP_KERNEL);
98 if (!isp)
99 return -ENOMEM;
100
101 isp->client = client;
102 mutex_init(&isp->mutex);
103
104 phy = &isp->phy;
105 phy->label = DRV_NAME;
106 phy->init = isp1301_phy_init;
107 phy->set_vbus = isp1301_phy_set_vbus;
108 phy->type = USB_PHY_TYPE_USB2;
109
110 i2c_set_clientdata(client, isp);
111 usb_add_phy_dev(phy);
112
113 isp1301_i2c_client = client;
114
115 return 0;
116}
117
118static int isp1301_remove(struct i2c_client *client)
119{
120 struct isp1301 *isp = i2c_get_clientdata(client);
121
122 usb_remove_phy(&isp->phy);
123 isp1301_i2c_client = NULL;
124
125 return 0;
126}
127
128static struct i2c_driver isp1301_driver = {
129 .driver = {
130 .name = DRV_NAME,
131 },
132 .probe = isp1301_probe,
133 .remove = isp1301_remove,
134 .id_table = isp1301_id,
135};
136
137module_i2c_driver(isp1301_driver);
138
139static int match(struct device *dev, void *data)
140{
141 struct device_node *node = (struct device_node *)data;
142 return (dev->of_node == node) &&
143 (dev->driver == &isp1301_driver.driver);
144}
145
146struct i2c_client *isp1301_get_client(struct device_node *node)
147{
148 if (node) { /* reference of ISP1301 I2C node via DT */
149 struct device *dev = bus_find_device(&i2c_bus_type, NULL,
150 node, match);
151 if (!dev)
152 return NULL;
153 return to_i2c_client(dev);
154 } else { /* non-DT: only one ISP1301 chip supported */
155 return isp1301_i2c_client;
156 }
157}
158EXPORT_SYMBOL_GPL(isp1301_get_client);
159
160MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
161MODULE_DESCRIPTION("NXP ISP1301 USB transceiver driver");
162MODULE_LICENSE("GPL");
diff --git a/drivers/usb/otg/msm_otg.c b/drivers/usb/phy/phy-msm-usb.c
index 749fbf41fb6f..749fbf41fb6f 100644
--- a/drivers/usb/otg/msm_otg.c
+++ b/drivers/usb/phy/phy-msm-usb.c
diff --git a/drivers/usb/phy/mv_u3d_phy.c b/drivers/usb/phy/phy-mv-u3d-usb.c
index 9d8599122aa9..f7838a43347c 100644
--- a/drivers/usb/phy/mv_u3d_phy.c
+++ b/drivers/usb/phy/phy-mv-u3d-usb.c
@@ -15,7 +15,7 @@
15#include <linux/usb/otg.h> 15#include <linux/usb/otg.h>
16#include <linux/platform_data/mv_usb.h> 16#include <linux/platform_data/mv_usb.h>
17 17
18#include "mv_u3d_phy.h" 18#include "phy-mv-u3d-usb.h"
19 19
20/* 20/*
21 * struct mv_u3d_phy - transceiver driver state 21 * struct mv_u3d_phy - transceiver driver state
@@ -313,7 +313,7 @@ err:
313 return ret; 313 return ret;
314} 314}
315 315
316static int __exit mv_u3d_phy_remove(struct platform_device *pdev) 316static int mv_u3d_phy_remove(struct platform_device *pdev)
317{ 317{
318 struct mv_u3d_phy *mv_u3d_phy = platform_get_drvdata(pdev); 318 struct mv_u3d_phy *mv_u3d_phy = platform_get_drvdata(pdev);
319 319
diff --git a/drivers/usb/phy/mv_u3d_phy.h b/drivers/usb/phy/phy-mv-u3d-usb.h
index 2a658cb9a527..2a658cb9a527 100644
--- a/drivers/usb/phy/mv_u3d_phy.h
+++ b/drivers/usb/phy/phy-mv-u3d-usb.h
diff --git a/drivers/usb/otg/mv_otg.c b/drivers/usb/phy/phy-mv-usb.c
index b6a9be31133b..c987bbe27851 100644
--- a/drivers/usb/otg/mv_otg.c
+++ b/drivers/usb/phy/phy-mv-usb.c
@@ -27,7 +27,7 @@
27#include <linux/usb/hcd.h> 27#include <linux/usb/hcd.h>
28#include <linux/platform_data/mv_usb.h> 28#include <linux/platform_data/mv_usb.h>
29 29
30#include "mv_otg.h" 30#include "phy-mv-usb.h"
31 31
32#define DRIVER_DESC "Marvell USB OTG transceiver driver" 32#define DRIVER_DESC "Marvell USB OTG transceiver driver"
33#define DRIVER_VERSION "Jan 20, 2010" 33#define DRIVER_VERSION "Jan 20, 2010"
@@ -237,18 +237,12 @@ static void mv_otg_start_periphrals(struct mv_otg *mvotg, int on)
237 237
238static void otg_clock_enable(struct mv_otg *mvotg) 238static void otg_clock_enable(struct mv_otg *mvotg)
239{ 239{
240 unsigned int i; 240 clk_prepare_enable(mvotg->clk);
241
242 for (i = 0; i < mvotg->clknum; i++)
243 clk_prepare_enable(mvotg->clk[i]);
244} 241}
245 242
246static void otg_clock_disable(struct mv_otg *mvotg) 243static void otg_clock_disable(struct mv_otg *mvotg)
247{ 244{
248 unsigned int i; 245 clk_disable_unprepare(mvotg->clk);
249
250 for (i = 0; i < mvotg->clknum; i++)
251 clk_disable_unprepare(mvotg->clk[i]);
252} 246}
253 247
254static int mv_otg_enable_internal(struct mv_otg *mvotg) 248static int mv_otg_enable_internal(struct mv_otg *mvotg)
@@ -684,16 +678,14 @@ static int mv_otg_probe(struct platform_device *pdev)
684 struct mv_otg *mvotg; 678 struct mv_otg *mvotg;
685 struct usb_otg *otg; 679 struct usb_otg *otg;
686 struct resource *r; 680 struct resource *r;
687 int retval = 0, clk_i, i; 681 int retval = 0, i;
688 size_t size;
689 682
690 if (pdata == NULL) { 683 if (pdata == NULL) {
691 dev_err(&pdev->dev, "failed to get platform data\n"); 684 dev_err(&pdev->dev, "failed to get platform data\n");
692 return -ENODEV; 685 return -ENODEV;
693 } 686 }
694 687
695 size = sizeof(*mvotg) + sizeof(struct clk *) * pdata->clknum; 688 mvotg = devm_kzalloc(&pdev->dev, sizeof(*mvotg), GFP_KERNEL);
696 mvotg = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
697 if (!mvotg) { 689 if (!mvotg) {
698 dev_err(&pdev->dev, "failed to allocate memory!\n"); 690 dev_err(&pdev->dev, "failed to allocate memory!\n");
699 return -ENOMEM; 691 return -ENOMEM;
@@ -708,15 +700,9 @@ static int mv_otg_probe(struct platform_device *pdev)
708 mvotg->pdev = pdev; 700 mvotg->pdev = pdev;
709 mvotg->pdata = pdata; 701 mvotg->pdata = pdata;
710 702
711 mvotg->clknum = pdata->clknum; 703 mvotg->clk = devm_clk_get(&pdev->dev, NULL);
712 for (clk_i = 0; clk_i < mvotg->clknum; clk_i++) { 704 if (IS_ERR(mvotg->clk))
713 mvotg->clk[clk_i] = devm_clk_get(&pdev->dev, 705 return PTR_ERR(mvotg->clk);
714 pdata->clkname[clk_i]);
715 if (IS_ERR(mvotg->clk[clk_i])) {
716 retval = PTR_ERR(mvotg->clk[clk_i]);
717 return retval;
718 }
719 }
720 706
721 mvotg->qwork = create_singlethread_workqueue("mv_otg_queue"); 707 mvotg->qwork = create_singlethread_workqueue("mv_otg_queue");
722 if (!mvotg->qwork) { 708 if (!mvotg->qwork) {
diff --git a/drivers/usb/otg/mv_otg.h b/drivers/usb/phy/phy-mv-usb.h
index 8a9e351b36ba..551da6eb0ba8 100644
--- a/drivers/usb/otg/mv_otg.h
+++ b/drivers/usb/phy/phy-mv-usb.h
@@ -158,8 +158,7 @@ struct mv_otg {
158 158
159 unsigned int active; 159 unsigned int active;
160 unsigned int clock_gating; 160 unsigned int clock_gating;
161 unsigned int clknum; 161 struct clk *clk;
162 struct clk *clk[0];
163}; 162};
164 163
165#endif 164#endif
diff --git a/drivers/usb/otg/mxs-phy.c b/drivers/usb/phy/phy-mxs-usb.c
index b0d9f119c749..9d4381e64d51 100644
--- a/drivers/usb/otg/mxs-phy.c
+++ b/drivers/usb/phy/phy-mxs-usb.c
@@ -48,12 +48,12 @@ static void mxs_phy_hw_init(struct mxs_phy *mxs_phy)
48 stmp_reset_block(base + HW_USBPHY_CTRL); 48 stmp_reset_block(base + HW_USBPHY_CTRL);
49 49
50 /* Power up the PHY */ 50 /* Power up the PHY */
51 writel_relaxed(0, base + HW_USBPHY_PWD); 51 writel(0, base + HW_USBPHY_PWD);
52 52
53 /* enable FS/LS device */ 53 /* enable FS/LS device */
54 writel_relaxed(BM_USBPHY_CTRL_ENUTMILEVEL2 | 54 writel(BM_USBPHY_CTRL_ENUTMILEVEL2 |
55 BM_USBPHY_CTRL_ENUTMILEVEL3, 55 BM_USBPHY_CTRL_ENUTMILEVEL3,
56 base + HW_USBPHY_CTRL_SET); 56 base + HW_USBPHY_CTRL_SET);
57} 57}
58 58
59static int mxs_phy_init(struct usb_phy *phy) 59static int mxs_phy_init(struct usb_phy *phy)
@@ -70,8 +70,8 @@ static void mxs_phy_shutdown(struct usb_phy *phy)
70{ 70{
71 struct mxs_phy *mxs_phy = to_mxs_phy(phy); 71 struct mxs_phy *mxs_phy = to_mxs_phy(phy);
72 72
73 writel_relaxed(BM_USBPHY_CTRL_CLKGATE, 73 writel(BM_USBPHY_CTRL_CLKGATE,
74 phy->io_priv + HW_USBPHY_CTRL_SET); 74 phy->io_priv + HW_USBPHY_CTRL_SET);
75 75
76 clk_disable_unprepare(mxs_phy->clk); 76 clk_disable_unprepare(mxs_phy->clk);
77} 77}
@@ -81,15 +81,15 @@ static int mxs_phy_suspend(struct usb_phy *x, int suspend)
81 struct mxs_phy *mxs_phy = to_mxs_phy(x); 81 struct mxs_phy *mxs_phy = to_mxs_phy(x);
82 82
83 if (suspend) { 83 if (suspend) {
84 writel_relaxed(0xffffffff, x->io_priv + HW_USBPHY_PWD); 84 writel(0xffffffff, x->io_priv + HW_USBPHY_PWD);
85 writel_relaxed(BM_USBPHY_CTRL_CLKGATE, 85 writel(BM_USBPHY_CTRL_CLKGATE,
86 x->io_priv + HW_USBPHY_CTRL_SET); 86 x->io_priv + HW_USBPHY_CTRL_SET);
87 clk_disable_unprepare(mxs_phy->clk); 87 clk_disable_unprepare(mxs_phy->clk);
88 } else { 88 } else {
89 clk_prepare_enable(mxs_phy->clk); 89 clk_prepare_enable(mxs_phy->clk);
90 writel_relaxed(BM_USBPHY_CTRL_CLKGATE, 90 writel(BM_USBPHY_CTRL_CLKGATE,
91 x->io_priv + HW_USBPHY_CTRL_CLR); 91 x->io_priv + HW_USBPHY_CTRL_CLR);
92 writel_relaxed(0, x->io_priv + HW_USBPHY_PWD); 92 writel(0, x->io_priv + HW_USBPHY_PWD);
93 } 93 }
94 94
95 return 0; 95 return 0;
@@ -102,8 +102,8 @@ static int mxs_phy_on_connect(struct usb_phy *phy,
102 (speed == USB_SPEED_HIGH) ? "high" : "non-high"); 102 (speed == USB_SPEED_HIGH) ? "high" : "non-high");
103 103
104 if (speed == USB_SPEED_HIGH) 104 if (speed == USB_SPEED_HIGH)
105 writel_relaxed(BM_USBPHY_CTRL_ENHOSTDISCONDETECT, 105 writel(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
106 phy->io_priv + HW_USBPHY_CTRL_SET); 106 phy->io_priv + HW_USBPHY_CTRL_SET);
107 107
108 return 0; 108 return 0;
109} 109}
@@ -115,8 +115,8 @@ static int mxs_phy_on_disconnect(struct usb_phy *phy,
115 (speed == USB_SPEED_HIGH) ? "high" : "non-high"); 115 (speed == USB_SPEED_HIGH) ? "high" : "non-high");
116 116
117 if (speed == USB_SPEED_HIGH) 117 if (speed == USB_SPEED_HIGH)
118 writel_relaxed(BM_USBPHY_CTRL_ENHOSTDISCONDETECT, 118 writel(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
119 phy->io_priv + HW_USBPHY_CTRL_CLR); 119 phy->io_priv + HW_USBPHY_CTRL_CLR);
120 120
121 return 0; 121 return 0;
122} 122}
@@ -127,6 +127,7 @@ static int mxs_phy_probe(struct platform_device *pdev)
127 void __iomem *base; 127 void __iomem *base;
128 struct clk *clk; 128 struct clk *clk;
129 struct mxs_phy *mxs_phy; 129 struct mxs_phy *mxs_phy;
130 int ret;
130 131
131 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 132 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
132 if (!res) { 133 if (!res) {
@@ -166,11 +167,19 @@ static int mxs_phy_probe(struct platform_device *pdev)
166 167
167 platform_set_drvdata(pdev, &mxs_phy->phy); 168 platform_set_drvdata(pdev, &mxs_phy->phy);
168 169
170 ret = usb_add_phy_dev(&mxs_phy->phy);
171 if (ret)
172 return ret;
173
169 return 0; 174 return 0;
170} 175}
171 176
172static int mxs_phy_remove(struct platform_device *pdev) 177static int mxs_phy_remove(struct platform_device *pdev)
173{ 178{
179 struct mxs_phy *mxs_phy = platform_get_drvdata(pdev);
180
181 usb_remove_phy(&mxs_phy->phy);
182
174 platform_set_drvdata(pdev, NULL); 183 platform_set_drvdata(pdev, NULL);
175 184
176 return 0; 185 return 0;
diff --git a/drivers/usb/otg/nop-usb-xceiv.c b/drivers/usb/phy/phy-nop.c
index a3ce24b94a73..2b10cc969bbb 100644
--- a/drivers/usb/otg/nop-usb-xceiv.c
+++ b/drivers/usb/phy/phy-nop.c
@@ -32,10 +32,16 @@
32#include <linux/usb/otg.h> 32#include <linux/usb/otg.h>
33#include <linux/usb/nop-usb-xceiv.h> 33#include <linux/usb/nop-usb-xceiv.h>
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/clk.h>
36#include <linux/regulator/consumer.h>
37#include <linux/of.h>
35 38
36struct nop_usb_xceiv { 39struct nop_usb_xceiv {
37 struct usb_phy phy; 40 struct usb_phy phy;
38 struct device *dev; 41 struct device *dev;
42 struct clk *clk;
43 struct regulator *vcc;
44 struct regulator *reset;
39}; 45};
40 46
41static struct platform_device *pd; 47static struct platform_device *pd;
@@ -64,6 +70,46 @@ static int nop_set_suspend(struct usb_phy *x, int suspend)
64 return 0; 70 return 0;
65} 71}
66 72
73static int nop_init(struct usb_phy *phy)
74{
75 struct nop_usb_xceiv *nop = dev_get_drvdata(phy->dev);
76
77 if (!IS_ERR(nop->vcc)) {
78 if (regulator_enable(nop->vcc))
79 dev_err(phy->dev, "Failed to enable power\n");
80 }
81
82 if (!IS_ERR(nop->clk))
83 clk_enable(nop->clk);
84
85 if (!IS_ERR(nop->reset)) {
86 /* De-assert RESET */
87 if (regulator_enable(nop->reset))
88 dev_err(phy->dev, "Failed to de-assert reset\n");
89 }
90
91 return 0;
92}
93
94static void nop_shutdown(struct usb_phy *phy)
95{
96 struct nop_usb_xceiv *nop = dev_get_drvdata(phy->dev);
97
98 if (!IS_ERR(nop->reset)) {
99 /* Assert RESET */
100 if (regulator_disable(nop->reset))
101 dev_err(phy->dev, "Failed to assert reset\n");
102 }
103
104 if (!IS_ERR(nop->clk))
105 clk_disable(nop->clk);
106
107 if (!IS_ERR(nop->vcc)) {
108 if (regulator_disable(nop->vcc))
109 dev_err(phy->dev, "Failed to disable power\n");
110 }
111}
112
67static int nop_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget) 113static int nop_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget)
68{ 114{
69 if (!otg) 115 if (!otg)
@@ -95,39 +141,96 @@ static int nop_set_host(struct usb_otg *otg, struct usb_bus *host)
95 141
96static int nop_usb_xceiv_probe(struct platform_device *pdev) 142static int nop_usb_xceiv_probe(struct platform_device *pdev)
97{ 143{
144 struct device *dev = &pdev->dev;
98 struct nop_usb_xceiv_platform_data *pdata = pdev->dev.platform_data; 145 struct nop_usb_xceiv_platform_data *pdata = pdev->dev.platform_data;
99 struct nop_usb_xceiv *nop; 146 struct nop_usb_xceiv *nop;
100 enum usb_phy_type type = USB_PHY_TYPE_USB2; 147 enum usb_phy_type type = USB_PHY_TYPE_USB2;
101 int err; 148 int err;
149 u32 clk_rate = 0;
150 bool needs_vcc = false;
151 bool needs_reset = false;
102 152
103 nop = kzalloc(sizeof *nop, GFP_KERNEL); 153 nop = devm_kzalloc(&pdev->dev, sizeof(*nop), GFP_KERNEL);
104 if (!nop) 154 if (!nop)
105 return -ENOMEM; 155 return -ENOMEM;
106 156
107 nop->phy.otg = kzalloc(sizeof *nop->phy.otg, GFP_KERNEL); 157 nop->phy.otg = devm_kzalloc(&pdev->dev, sizeof(*nop->phy.otg),
108 if (!nop->phy.otg) { 158 GFP_KERNEL);
109 kfree(nop); 159 if (!nop->phy.otg)
110 return -ENOMEM; 160 return -ENOMEM;
111 }
112 161
113 if (pdata) 162 if (dev->of_node) {
163 struct device_node *node = dev->of_node;
164
165 if (of_property_read_u32(node, "clock-frequency", &clk_rate))
166 clk_rate = 0;
167
168 needs_vcc = of_property_read_bool(node, "vcc-supply");
169 needs_reset = of_property_read_bool(node, "reset-supply");
170
171 } else if (pdata) {
114 type = pdata->type; 172 type = pdata->type;
173 clk_rate = pdata->clk_rate;
174 needs_vcc = pdata->needs_vcc;
175 needs_reset = pdata->needs_reset;
176 }
177
178 nop->clk = devm_clk_get(&pdev->dev, "main_clk");
179 if (IS_ERR(nop->clk)) {
180 dev_dbg(&pdev->dev, "Can't get phy clock: %ld\n",
181 PTR_ERR(nop->clk));
182 }
183
184 if (!IS_ERR(nop->clk) && clk_rate) {
185 err = clk_set_rate(nop->clk, clk_rate);
186 if (err) {
187 dev_err(&pdev->dev, "Error setting clock rate\n");
188 return err;
189 }
190 }
191
192 if (!IS_ERR(nop->clk)) {
193 err = clk_prepare(nop->clk);
194 if (err) {
195 dev_err(&pdev->dev, "Error preparing clock\n");
196 return err;
197 }
198 }
199
200 nop->vcc = devm_regulator_get(&pdev->dev, "vcc");
201 if (IS_ERR(nop->vcc)) {
202 dev_dbg(&pdev->dev, "Error getting vcc regulator: %ld\n",
203 PTR_ERR(nop->vcc));
204 if (needs_vcc)
205 return -EPROBE_DEFER;
206 }
207
208 nop->reset = devm_regulator_get(&pdev->dev, "reset");
209 if (IS_ERR(nop->reset)) {
210 dev_dbg(&pdev->dev, "Error getting reset regulator: %ld\n",
211 PTR_ERR(nop->reset));
212 if (needs_reset)
213 return -EPROBE_DEFER;
214 }
115 215
116 nop->dev = &pdev->dev; 216 nop->dev = &pdev->dev;
117 nop->phy.dev = nop->dev; 217 nop->phy.dev = nop->dev;
118 nop->phy.label = "nop-xceiv"; 218 nop->phy.label = "nop-xceiv";
119 nop->phy.set_suspend = nop_set_suspend; 219 nop->phy.set_suspend = nop_set_suspend;
220 nop->phy.init = nop_init;
221 nop->phy.shutdown = nop_shutdown;
120 nop->phy.state = OTG_STATE_UNDEFINED; 222 nop->phy.state = OTG_STATE_UNDEFINED;
223 nop->phy.type = type;
121 224
122 nop->phy.otg->phy = &nop->phy; 225 nop->phy.otg->phy = &nop->phy;
123 nop->phy.otg->set_host = nop_set_host; 226 nop->phy.otg->set_host = nop_set_host;
124 nop->phy.otg->set_peripheral = nop_set_peripheral; 227 nop->phy.otg->set_peripheral = nop_set_peripheral;
125 228
126 err = usb_add_phy(&nop->phy, type); 229 err = usb_add_phy_dev(&nop->phy);
127 if (err) { 230 if (err) {
128 dev_err(&pdev->dev, "can't register transceiver, err: %d\n", 231 dev_err(&pdev->dev, "can't register transceiver, err: %d\n",
129 err); 232 err);
130 goto exit; 233 goto err_add;
131 } 234 }
132 235
133 platform_set_drvdata(pdev, nop); 236 platform_set_drvdata(pdev, nop);
@@ -135,9 +238,10 @@ static int nop_usb_xceiv_probe(struct platform_device *pdev)
135 ATOMIC_INIT_NOTIFIER_HEAD(&nop->phy.notifier); 238 ATOMIC_INIT_NOTIFIER_HEAD(&nop->phy.notifier);
136 239
137 return 0; 240 return 0;
138exit: 241
139 kfree(nop->phy.otg); 242err_add:
140 kfree(nop); 243 if (!IS_ERR(nop->clk))
244 clk_unprepare(nop->clk);
141 return err; 245 return err;
142} 246}
143 247
@@ -145,21 +249,30 @@ static int nop_usb_xceiv_remove(struct platform_device *pdev)
145{ 249{
146 struct nop_usb_xceiv *nop = platform_get_drvdata(pdev); 250 struct nop_usb_xceiv *nop = platform_get_drvdata(pdev);
147 251
252 if (!IS_ERR(nop->clk))
253 clk_unprepare(nop->clk);
254
148 usb_remove_phy(&nop->phy); 255 usb_remove_phy(&nop->phy);
149 256
150 platform_set_drvdata(pdev, NULL); 257 platform_set_drvdata(pdev, NULL);
151 kfree(nop->phy.otg);
152 kfree(nop);
153 258
154 return 0; 259 return 0;
155} 260}
156 261
262static const struct of_device_id nop_xceiv_dt_ids[] = {
263 { .compatible = "usb-nop-xceiv" },
264 { }
265};
266
267MODULE_DEVICE_TABLE(of, nop_xceiv_dt_ids);
268
157static struct platform_driver nop_usb_xceiv_driver = { 269static struct platform_driver nop_usb_xceiv_driver = {
158 .probe = nop_usb_xceiv_probe, 270 .probe = nop_usb_xceiv_probe,
159 .remove = nop_usb_xceiv_remove, 271 .remove = nop_usb_xceiv_remove,
160 .driver = { 272 .driver = {
161 .name = "nop_usb_xceiv", 273 .name = "nop_usb_xceiv",
162 .owner = THIS_MODULE, 274 .owner = THIS_MODULE,
275 .of_match_table = of_match_ptr(nop_xceiv_dt_ids),
163 }, 276 },
164}; 277};
165 278
diff --git a/drivers/usb/phy/omap-control-usb.c b/drivers/usb/phy/phy-omap-control.c
index 1419ceda9759..1419ceda9759 100644
--- a/drivers/usb/phy/omap-control-usb.c
+++ b/drivers/usb/phy/phy-omap-control.c
diff --git a/drivers/usb/phy/omap-usb2.c b/drivers/usb/phy/phy-omap-usb2.c
index 844ab68f08d0..844ab68f08d0 100644
--- a/drivers/usb/phy/omap-usb2.c
+++ b/drivers/usb/phy/phy-omap-usb2.c
diff --git a/drivers/usb/phy/omap-usb3.c b/drivers/usb/phy/phy-omap-usb3.c
index a6e60b1e102e..a6e60b1e102e 100644
--- a/drivers/usb/phy/omap-usb3.c
+++ b/drivers/usb/phy/phy-omap-usb3.c
diff --git a/drivers/usb/phy/rcar-phy.c b/drivers/usb/phy/phy-rcar-usb.c
index a35681b0c501..a35681b0c501 100644
--- a/drivers/usb/phy/rcar-phy.c
+++ b/drivers/usb/phy/phy-rcar-usb.c
diff --git a/drivers/usb/phy/phy-samsung-usb.c b/drivers/usb/phy/phy-samsung-usb.c
new file mode 100644
index 000000000000..7b118ee5f5e4
--- /dev/null
+++ b/drivers/usb/phy/phy-samsung-usb.c
@@ -0,0 +1,236 @@
1/* linux/drivers/usb/phy/phy-samsung-usb.c
2 *
3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
5 *
6 * Author: Praveen Paneri <p.paneri@samsung.com>
7 *
8 * Samsung USB-PHY helper driver with common function calls;
9 * interacts with Samsung USB 2.0 PHY controller driver and later
10 * with Samsung USB 3.0 PHY driver.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 */
21
22#include <linux/module.h>
23#include <linux/platform_device.h>
24#include <linux/clk.h>
25#include <linux/device.h>
26#include <linux/err.h>
27#include <linux/io.h>
28#include <linux/of.h>
29#include <linux/of_address.h>
30#include <linux/usb/samsung_usb_phy.h>
31
32#include "phy-samsung-usb.h"
33
34int samsung_usbphy_parse_dt(struct samsung_usbphy *sphy)
35{
36 struct device_node *usbphy_sys;
37
38 /* Getting node for system controller interface for usb-phy */
39 usbphy_sys = of_get_child_by_name(sphy->dev->of_node, "usbphy-sys");
40 if (!usbphy_sys) {
41 dev_err(sphy->dev, "No sys-controller interface for usb-phy\n");
42 return -ENODEV;
43 }
44
45 sphy->pmuregs = of_iomap(usbphy_sys, 0);
46
47 if (sphy->pmuregs == NULL) {
48 dev_err(sphy->dev, "Can't get usb-phy pmu control register\n");
49 goto err0;
50 }
51
52 sphy->sysreg = of_iomap(usbphy_sys, 1);
53
54 /*
55 * Not returning error code here, since this situation is not fatal.
56 * Few SoCs may not have this switch available
57 */
58 if (sphy->sysreg == NULL)
59 dev_warn(sphy->dev, "Can't get usb-phy sysreg cfg register\n");
60
61 of_node_put(usbphy_sys);
62
63 return 0;
64
65err0:
66 of_node_put(usbphy_sys);
67 return -ENXIO;
68}
69EXPORT_SYMBOL_GPL(samsung_usbphy_parse_dt);
70
71/*
72 * Set isolation here for phy.
73 * Here 'on = true' would mean USB PHY block is isolated, hence
74 * de-activated and vice-versa.
75 */
76void samsung_usbphy_set_isolation(struct samsung_usbphy *sphy, bool on)
77{
78 void __iomem *reg = NULL;
79 u32 reg_val;
80 u32 en_mask = 0;
81
82 if (!sphy->pmuregs) {
83 dev_warn(sphy->dev, "Can't set pmu isolation\n");
84 return;
85 }
86
87 switch (sphy->drv_data->cpu_type) {
88 case TYPE_S3C64XX:
89 /*
90 * Do nothing: We will add here once S3C64xx goes for DT support
91 */
92 break;
93 case TYPE_EXYNOS4210:
94 /*
95 * Fall through since exynos4210 and exynos5250 have similar
96 * register architecture: two separate registers for host and
97 * device phy control with enable bit at position 0.
98 */
99 case TYPE_EXYNOS5250:
100 if (sphy->phy_type == USB_PHY_TYPE_DEVICE) {
101 reg = sphy->pmuregs +
102 sphy->drv_data->devphy_reg_offset;
103 en_mask = sphy->drv_data->devphy_en_mask;
104 } else if (sphy->phy_type == USB_PHY_TYPE_HOST) {
105 reg = sphy->pmuregs +
106 sphy->drv_data->hostphy_reg_offset;
107 en_mask = sphy->drv_data->hostphy_en_mask;
108 }
109 break;
110 default:
111 dev_err(sphy->dev, "Invalid SoC type\n");
112 return;
113 }
114
115 reg_val = readl(reg);
116
117 if (on)
118 reg_val &= ~en_mask;
119 else
120 reg_val |= en_mask;
121
122 writel(reg_val, reg);
123}
124EXPORT_SYMBOL_GPL(samsung_usbphy_set_isolation);
125
126/*
127 * Configure the mode of working of usb-phy here: HOST/DEVICE.
128 */
129void samsung_usbphy_cfg_sel(struct samsung_usbphy *sphy)
130{
131 u32 reg;
132
133 if (!sphy->sysreg) {
134 dev_warn(sphy->dev, "Can't configure specified phy mode\n");
135 return;
136 }
137
138 reg = readl(sphy->sysreg);
139
140 if (sphy->phy_type == USB_PHY_TYPE_DEVICE)
141 reg &= ~EXYNOS_USB20PHY_CFG_HOST_LINK;
142 else if (sphy->phy_type == USB_PHY_TYPE_HOST)
143 reg |= EXYNOS_USB20PHY_CFG_HOST_LINK;
144
145 writel(reg, sphy->sysreg);
146}
147EXPORT_SYMBOL_GPL(samsung_usbphy_cfg_sel);
148
149/*
150 * PHYs are different for USB Device and USB Host.
151 * This make sure that correct PHY type is selected before
152 * any operation on PHY.
153 */
154int samsung_usbphy_set_type(struct usb_phy *phy,
155 enum samsung_usb_phy_type phy_type)
156{
157 struct samsung_usbphy *sphy = phy_to_sphy(phy);
158
159 sphy->phy_type = phy_type;
160
161 return 0;
162}
163EXPORT_SYMBOL_GPL(samsung_usbphy_set_type);
164
165/*
166 * Returns reference clock frequency selection value
167 */
168int samsung_usbphy_get_refclk_freq(struct samsung_usbphy *sphy)
169{
170 struct clk *ref_clk;
171 int refclk_freq = 0;
172
173 /*
174 * In exynos5250 USB host and device PHY use
175 * external crystal clock XXTI
176 */
177 if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250)
178 ref_clk = devm_clk_get(sphy->dev, "ext_xtal");
179 else
180 ref_clk = devm_clk_get(sphy->dev, "xusbxti");
181 if (IS_ERR(ref_clk)) {
182 dev_err(sphy->dev, "Failed to get reference clock\n");
183 return PTR_ERR(ref_clk);
184 }
185
186 if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250) {
187 /* set clock frequency for PLL */
188 switch (clk_get_rate(ref_clk)) {
189 case 9600 * KHZ:
190 refclk_freq = FSEL_CLKSEL_9600K;
191 break;
192 case 10 * MHZ:
193 refclk_freq = FSEL_CLKSEL_10M;
194 break;
195 case 12 * MHZ:
196 refclk_freq = FSEL_CLKSEL_12M;
197 break;
198 case 19200 * KHZ:
199 refclk_freq = FSEL_CLKSEL_19200K;
200 break;
201 case 20 * MHZ:
202 refclk_freq = FSEL_CLKSEL_20M;
203 break;
204 case 50 * MHZ:
205 refclk_freq = FSEL_CLKSEL_50M;
206 break;
207 case 24 * MHZ:
208 default:
209 /* default reference clock */
210 refclk_freq = FSEL_CLKSEL_24M;
211 break;
212 }
213 } else {
214 switch (clk_get_rate(ref_clk)) {
215 case 12 * MHZ:
216 refclk_freq = PHYCLK_CLKSEL_12M;
217 break;
218 case 24 * MHZ:
219 refclk_freq = PHYCLK_CLKSEL_24M;
220 break;
221 case 48 * MHZ:
222 refclk_freq = PHYCLK_CLKSEL_48M;
223 break;
224 default:
225 if (sphy->drv_data->cpu_type == TYPE_S3C64XX)
226 refclk_freq = PHYCLK_CLKSEL_48M;
227 else
228 refclk_freq = PHYCLK_CLKSEL_24M;
229 break;
230 }
231 }
232 clk_put(ref_clk);
233
234 return refclk_freq;
235}
236EXPORT_SYMBOL_GPL(samsung_usbphy_get_refclk_freq);
diff --git a/drivers/usb/phy/phy-samsung-usb.h b/drivers/usb/phy/phy-samsung-usb.h
new file mode 100644
index 000000000000..70a9cae5e37f
--- /dev/null
+++ b/drivers/usb/phy/phy-samsung-usb.h
@@ -0,0 +1,327 @@
1/* linux/drivers/usb/phy/phy-samsung-usb.h
2 *
3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
5 *
6 * Samsung USB-PHY transceiver; talks to S3C HS OTG controller, EHCI-S5P and
7 * OHCI-EXYNOS controllers.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */
18
19#include <linux/usb/phy.h>
20
21/* Register definitions */
22
23#define SAMSUNG_PHYPWR (0x00)
24
25#define PHYPWR_NORMAL_MASK (0x19 << 0)
26#define PHYPWR_OTG_DISABLE (0x1 << 4)
27#define PHYPWR_ANALOG_POWERDOWN (0x1 << 3)
28#define PHYPWR_FORCE_SUSPEND (0x1 << 1)
29/* For Exynos4 */
30#define PHYPWR_NORMAL_MASK_PHY0 (0x39 << 0)
31#define PHYPWR_SLEEP_PHY0 (0x1 << 5)
32
33#define SAMSUNG_PHYCLK (0x04)
34
35#define PHYCLK_MODE_USB11 (0x1 << 6)
36#define PHYCLK_EXT_OSC (0x1 << 5)
37#define PHYCLK_COMMON_ON_N (0x1 << 4)
38#define PHYCLK_ID_PULL (0x1 << 2)
39#define PHYCLK_CLKSEL_MASK (0x3 << 0)
40#define PHYCLK_CLKSEL_48M (0x0 << 0)
41#define PHYCLK_CLKSEL_12M (0x2 << 0)
42#define PHYCLK_CLKSEL_24M (0x3 << 0)
43
44#define SAMSUNG_RSTCON (0x08)
45
46#define RSTCON_PHYLINK_SWRST (0x1 << 2)
47#define RSTCON_HLINK_SWRST (0x1 << 1)
48#define RSTCON_SWRST (0x1 << 0)
49
50/* EXYNOS5 */
51#define EXYNOS5_PHY_HOST_CTRL0 (0x00)
52
53#define HOST_CTRL0_PHYSWRSTALL (0x1 << 31)
54
55#define HOST_CTRL0_REFCLKSEL_MASK (0x3 << 19)
56#define HOST_CTRL0_REFCLKSEL_XTAL (0x0 << 19)
57#define HOST_CTRL0_REFCLKSEL_EXTL (0x1 << 19)
58#define HOST_CTRL0_REFCLKSEL_CLKCORE (0x2 << 19)
59
60#define HOST_CTRL0_FSEL_MASK (0x7 << 16)
61#define HOST_CTRL0_FSEL(_x) ((_x) << 16)
62
63#define FSEL_CLKSEL_50M (0x7)
64#define FSEL_CLKSEL_24M (0x5)
65#define FSEL_CLKSEL_20M (0x4)
66#define FSEL_CLKSEL_19200K (0x3)
67#define FSEL_CLKSEL_12M (0x2)
68#define FSEL_CLKSEL_10M (0x1)
69#define FSEL_CLKSEL_9600K (0x0)
70
71#define HOST_CTRL0_TESTBURNIN (0x1 << 11)
72#define HOST_CTRL0_RETENABLE (0x1 << 10)
73#define HOST_CTRL0_COMMONON_N (0x1 << 9)
74#define HOST_CTRL0_SIDDQ (0x1 << 6)
75#define HOST_CTRL0_FORCESLEEP (0x1 << 5)
76#define HOST_CTRL0_FORCESUSPEND (0x1 << 4)
77#define HOST_CTRL0_WORDINTERFACE (0x1 << 3)
78#define HOST_CTRL0_UTMISWRST (0x1 << 2)
79#define HOST_CTRL0_LINKSWRST (0x1 << 1)
80#define HOST_CTRL0_PHYSWRST (0x1 << 0)
81
82#define EXYNOS5_PHY_HOST_TUNE0 (0x04)
83
84#define EXYNOS5_PHY_HSIC_CTRL1 (0x10)
85
86#define EXYNOS5_PHY_HSIC_TUNE1 (0x14)
87
88#define EXYNOS5_PHY_HSIC_CTRL2 (0x20)
89
90#define EXYNOS5_PHY_HSIC_TUNE2 (0x24)
91
92#define HSIC_CTRL_REFCLKSEL_MASK (0x3 << 23)
93#define HSIC_CTRL_REFCLKSEL (0x2 << 23)
94
95#define HSIC_CTRL_REFCLKDIV_MASK (0x7f << 16)
96#define HSIC_CTRL_REFCLKDIV(_x) ((_x) << 16)
97#define HSIC_CTRL_REFCLKDIV_12 (0x24 << 16)
98#define HSIC_CTRL_REFCLKDIV_15 (0x1c << 16)
99#define HSIC_CTRL_REFCLKDIV_16 (0x1a << 16)
100#define HSIC_CTRL_REFCLKDIV_19_2 (0x15 << 16)
101#define HSIC_CTRL_REFCLKDIV_20 (0x14 << 16)
102
103#define HSIC_CTRL_SIDDQ (0x1 << 6)
104#define HSIC_CTRL_FORCESLEEP (0x1 << 5)
105#define HSIC_CTRL_FORCESUSPEND (0x1 << 4)
106#define HSIC_CTRL_WORDINTERFACE (0x1 << 3)
107#define HSIC_CTRL_UTMISWRST (0x1 << 2)
108#define HSIC_CTRL_PHYSWRST (0x1 << 0)
109
110#define EXYNOS5_PHY_HOST_EHCICTRL (0x30)
111
112#define HOST_EHCICTRL_ENAINCRXALIGN (0x1 << 29)
113#define HOST_EHCICTRL_ENAINCR4 (0x1 << 28)
114#define HOST_EHCICTRL_ENAINCR8 (0x1 << 27)
115#define HOST_EHCICTRL_ENAINCR16 (0x1 << 26)
116
117#define EXYNOS5_PHY_HOST_OHCICTRL (0x34)
118
119#define HOST_OHCICTRL_SUSPLGCY (0x1 << 3)
120#define HOST_OHCICTRL_APPSTARTCLK (0x1 << 2)
121#define HOST_OHCICTRL_CNTSEL (0x1 << 1)
122#define HOST_OHCICTRL_CLKCKTRST (0x1 << 0)
123
124#define EXYNOS5_PHY_OTG_SYS (0x38)
125
126#define OTG_SYS_PHYLINK_SWRESET (0x1 << 14)
127#define OTG_SYS_LINKSWRST_UOTG (0x1 << 13)
128#define OTG_SYS_PHY0_SWRST (0x1 << 12)
129
130#define OTG_SYS_REFCLKSEL_MASK (0x3 << 9)
131#define OTG_SYS_REFCLKSEL_XTAL (0x0 << 9)
132#define OTG_SYS_REFCLKSEL_EXTL (0x1 << 9)
133#define OTG_SYS_REFCLKSEL_CLKCORE (0x2 << 9)
134
135#define OTG_SYS_IDPULLUP_UOTG (0x1 << 8)
136#define OTG_SYS_COMMON_ON (0x1 << 7)
137
138#define OTG_SYS_FSEL_MASK (0x7 << 4)
139#define OTG_SYS_FSEL(_x) ((_x) << 4)
140
141#define OTG_SYS_FORCESLEEP (0x1 << 3)
142#define OTG_SYS_OTGDISABLE (0x1 << 2)
143#define OTG_SYS_SIDDQ_UOTG (0x1 << 1)
144#define OTG_SYS_FORCESUSPEND (0x1 << 0)
145
146#define EXYNOS5_PHY_OTG_TUNE (0x40)
147
148/* EXYNOS5: USB 3.0 DRD */
149#define EXYNOS5_DRD_LINKSYSTEM (0x04)
150
151#define LINKSYSTEM_FLADJ_MASK (0x3f << 1)
152#define LINKSYSTEM_FLADJ(_x) ((_x) << 1)
153#define LINKSYSTEM_XHCI_VERSION_CONTROL (0x1 << 27)
154
155#define EXYNOS5_DRD_PHYUTMI (0x08)
156
157#define PHYUTMI_OTGDISABLE (0x1 << 6)
158#define PHYUTMI_FORCESUSPEND (0x1 << 1)
159#define PHYUTMI_FORCESLEEP (0x1 << 0)
160
161#define EXYNOS5_DRD_PHYPIPE (0x0c)
162
163#define EXYNOS5_DRD_PHYCLKRST (0x10)
164
165#define PHYCLKRST_SSC_REFCLKSEL_MASK (0xff << 23)
166#define PHYCLKRST_SSC_REFCLKSEL(_x) ((_x) << 23)
167
168#define PHYCLKRST_SSC_RANGE_MASK (0x03 << 21)
169#define PHYCLKRST_SSC_RANGE(_x) ((_x) << 21)
170
171#define PHYCLKRST_SSC_EN (0x1 << 20)
172#define PHYCLKRST_REF_SSP_EN (0x1 << 19)
173#define PHYCLKRST_REF_CLKDIV2 (0x1 << 18)
174
175#define PHYCLKRST_MPLL_MULTIPLIER_MASK (0x7f << 11)
176#define PHYCLKRST_MPLL_MULTIPLIER_100MHZ_REF (0x19 << 11)
177#define PHYCLKRST_MPLL_MULTIPLIER_50M_REF (0x02 << 11)
178#define PHYCLKRST_MPLL_MULTIPLIER_24MHZ_REF (0x68 << 11)
179#define PHYCLKRST_MPLL_MULTIPLIER_20MHZ_REF (0x7d << 11)
180#define PHYCLKRST_MPLL_MULTIPLIER_19200KHZ_REF (0x02 << 11)
181
182#define PHYCLKRST_FSEL_MASK (0x3f << 5)
183#define PHYCLKRST_FSEL(_x) ((_x) << 5)
184#define PHYCLKRST_FSEL_PAD_100MHZ (0x27 << 5)
185#define PHYCLKRST_FSEL_PAD_24MHZ (0x2a << 5)
186#define PHYCLKRST_FSEL_PAD_20MHZ (0x31 << 5)
187#define PHYCLKRST_FSEL_PAD_19_2MHZ (0x38 << 5)
188
189#define PHYCLKRST_RETENABLEN (0x1 << 4)
190
191#define PHYCLKRST_REFCLKSEL_MASK (0x03 << 2)
192#define PHYCLKRST_REFCLKSEL_PAD_REFCLK (0x2 << 2)
193#define PHYCLKRST_REFCLKSEL_EXT_REFCLK (0x3 << 2)
194
195#define PHYCLKRST_PORTRESET (0x1 << 1)
196#define PHYCLKRST_COMMONONN (0x1 << 0)
197
198#define EXYNOS5_DRD_PHYREG0 (0x14)
199#define EXYNOS5_DRD_PHYREG1 (0x18)
200
201#define EXYNOS5_DRD_PHYPARAM0 (0x1c)
202
203#define PHYPARAM0_REF_USE_PAD (0x1 << 31)
204#define PHYPARAM0_REF_LOSLEVEL_MASK (0x1f << 26)
205#define PHYPARAM0_REF_LOSLEVEL (0x9 << 26)
206
207#define EXYNOS5_DRD_PHYPARAM1 (0x20)
208
209#define PHYPARAM1_PCS_TXDEEMPH_MASK (0x1f << 0)
210#define PHYPARAM1_PCS_TXDEEMPH (0x1c)
211
212#define EXYNOS5_DRD_PHYTERM (0x24)
213
214#define EXYNOS5_DRD_PHYTEST (0x28)
215
216#define PHYTEST_POWERDOWN_SSP (0x1 << 3)
217#define PHYTEST_POWERDOWN_HSP (0x1 << 2)
218
219#define EXYNOS5_DRD_PHYADP (0x2c)
220
221#define EXYNOS5_DRD_PHYBATCHG (0x30)
222
223#define PHYBATCHG_UTMI_CLKSEL (0x1 << 2)
224
225#define EXYNOS5_DRD_PHYRESUME (0x34)
226#define EXYNOS5_DRD_LINKPORT (0x44)
227
228#ifndef MHZ
229#define MHZ (1000*1000)
230#endif
231
232#ifndef KHZ
233#define KHZ (1000)
234#endif
235
236#define EXYNOS_USBHOST_PHY_CTRL_OFFSET (0x4)
237#define S3C64XX_USBPHY_ENABLE (0x1 << 16)
238#define EXYNOS_USBPHY_ENABLE (0x1 << 0)
239#define EXYNOS_USB20PHY_CFG_HOST_LINK (0x1 << 0)
240
241enum samsung_cpu_type {
242 TYPE_S3C64XX,
243 TYPE_EXYNOS4210,
244 TYPE_EXYNOS5250,
245};
246
247/*
248 * struct samsung_usbphy_drvdata - driver data for various SoC variants
249 * @cpu_type: machine identifier
250 * @devphy_en_mask: device phy enable mask for PHY CONTROL register
251 * @hostphy_en_mask: host phy enable mask for PHY CONTROL register
252 * @devphy_reg_offset: offset to DEVICE PHY CONTROL register from
253 * mapped address of system controller.
254 * @hostphy_reg_offset: offset to HOST PHY CONTROL register from
255 * mapped address of system controller.
256 *
257 * Here we have a separate mask for device type phy.
258 * Having different masks for host and device type phy helps
259 * in setting independent masks in case of SoCs like S5PV210,
260 * in which PHY0 and PHY1 enable bits belong to same register
261 * placed at position 0 and 1 respectively.
262 * Although for newer SoCs like exynos these bits belong to
263 * different registers altogether placed at position 0.
264 */
265struct samsung_usbphy_drvdata {
266 int cpu_type;
267 int devphy_en_mask;
268 int hostphy_en_mask;
269 u32 devphy_reg_offset;
270 u32 hostphy_reg_offset;
271};
272
273/*
274 * struct samsung_usbphy - transceiver driver state
275 * @phy: transceiver structure
276 * @plat: platform data
277 * @dev: The parent device supplied to the probe function
278 * @clk: usb phy clock
279 * @regs: usb phy controller registers memory base
280 * @pmuregs: USB device PHY_CONTROL register memory base
281 * @sysreg: USB2.0 PHY_CFG register memory base
282 * @ref_clk_freq: reference clock frequency selection
283 * @drv_data: driver data available for different SoCs
284 * @phy_type: Samsung SoCs specific phy types: #HOST
285 * #DEVICE
286 * @phy_usage: usage count for phy
287 * @lock: lock for phy operations
288 */
289struct samsung_usbphy {
290 struct usb_phy phy;
291 struct samsung_usbphy_data *plat;
292 struct device *dev;
293 struct clk *clk;
294 void __iomem *regs;
295 void __iomem *pmuregs;
296 void __iomem *sysreg;
297 int ref_clk_freq;
298 const struct samsung_usbphy_drvdata *drv_data;
299 enum samsung_usb_phy_type phy_type;
300 atomic_t phy_usage;
301 spinlock_t lock;
302};
303
304#define phy_to_sphy(x) container_of((x), struct samsung_usbphy, phy)
305
306static const struct of_device_id samsung_usbphy_dt_match[];
307
308static inline const struct samsung_usbphy_drvdata
309*samsung_usbphy_get_driver_data(struct platform_device *pdev)
310{
311 if (pdev->dev.of_node) {
312 const struct of_device_id *match;
313 match = of_match_node(samsung_usbphy_dt_match,
314 pdev->dev.of_node);
315 return match->data;
316 }
317
318 return (struct samsung_usbphy_drvdata *)
319 platform_get_device_id(pdev)->driver_data;
320}
321
322extern int samsung_usbphy_parse_dt(struct samsung_usbphy *sphy);
323extern void samsung_usbphy_set_isolation(struct samsung_usbphy *sphy, bool on);
324extern void samsung_usbphy_cfg_sel(struct samsung_usbphy *sphy);
325extern int samsung_usbphy_set_type(struct usb_phy *phy,
326 enum samsung_usb_phy_type phy_type);
327extern int samsung_usbphy_get_refclk_freq(struct samsung_usbphy *sphy);
diff --git a/drivers/usb/phy/phy-samsung-usb2.c b/drivers/usb/phy/phy-samsung-usb2.c
new file mode 100644
index 000000000000..45ffe036dacc
--- /dev/null
+++ b/drivers/usb/phy/phy-samsung-usb2.c
@@ -0,0 +1,509 @@
1/* linux/drivers/usb/phy/phy-samsung-usb2.c
2 *
3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
5 *
6 * Author: Praveen Paneri <p.paneri@samsung.com>
7 *
8 * Samsung USB2.0 PHY transceiver; talks to S3C HS OTG controller, EHCI-S5P and
9 * OHCI-EXYNOS controllers.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21#include <linux/module.h>
22#include <linux/platform_device.h>
23#include <linux/clk.h>
24#include <linux/delay.h>
25#include <linux/device.h>
26#include <linux/err.h>
27#include <linux/io.h>
28#include <linux/of.h>
29#include <linux/usb/otg.h>
30#include <linux/usb/samsung_usb_phy.h>
31#include <linux/platform_data/samsung-usbphy.h>
32
33#include "phy-samsung-usb.h"
34
35static int samsung_usbphy_set_host(struct usb_otg *otg, struct usb_bus *host)
36{
37 if (!otg)
38 return -ENODEV;
39
40 if (!otg->host)
41 otg->host = host;
42
43 return 0;
44}
45
46static bool exynos5_phyhost_is_on(void __iomem *regs)
47{
48 u32 reg;
49
50 reg = readl(regs + EXYNOS5_PHY_HOST_CTRL0);
51
52 return !(reg & HOST_CTRL0_SIDDQ);
53}
54
55static void samsung_exynos5_usb2phy_enable(struct samsung_usbphy *sphy)
56{
57 void __iomem *regs = sphy->regs;
58 u32 phyclk = sphy->ref_clk_freq;
59 u32 phyhost;
60 u32 phyotg;
61 u32 phyhsic;
62 u32 ehcictrl;
63 u32 ohcictrl;
64
65 /*
66 * phy_usage helps in keeping usage count for phy
67 * so that the first consumer enabling the phy is also
68 * the last consumer to disable it.
69 */
70
71 atomic_inc(&sphy->phy_usage);
72
73 if (exynos5_phyhost_is_on(regs)) {
74 dev_info(sphy->dev, "Already power on PHY\n");
75 return;
76 }
77
78 /* Host configuration */
79 phyhost = readl(regs + EXYNOS5_PHY_HOST_CTRL0);
80
81 /* phy reference clock configuration */
82 phyhost &= ~HOST_CTRL0_FSEL_MASK;
83 phyhost |= HOST_CTRL0_FSEL(phyclk);
84
85 /* host phy reset */
86 phyhost &= ~(HOST_CTRL0_PHYSWRST |
87 HOST_CTRL0_PHYSWRSTALL |
88 HOST_CTRL0_SIDDQ |
89 /* Enable normal mode of operation */
90 HOST_CTRL0_FORCESUSPEND |
91 HOST_CTRL0_FORCESLEEP);
92
93 /* Link reset */
94 phyhost |= (HOST_CTRL0_LINKSWRST |
95 HOST_CTRL0_UTMISWRST |
96 /* COMMON Block configuration during suspend */
97 HOST_CTRL0_COMMONON_N);
98 writel(phyhost, regs + EXYNOS5_PHY_HOST_CTRL0);
99 udelay(10);
100 phyhost &= ~(HOST_CTRL0_LINKSWRST |
101 HOST_CTRL0_UTMISWRST);
102 writel(phyhost, regs + EXYNOS5_PHY_HOST_CTRL0);
103
104 /* OTG configuration */
105 phyotg = readl(regs + EXYNOS5_PHY_OTG_SYS);
106
107 /* phy reference clock configuration */
108 phyotg &= ~OTG_SYS_FSEL_MASK;
109 phyotg |= OTG_SYS_FSEL(phyclk);
110
111 /* Enable normal mode of operation */
112 phyotg &= ~(OTG_SYS_FORCESUSPEND |
113 OTG_SYS_SIDDQ_UOTG |
114 OTG_SYS_FORCESLEEP |
115 OTG_SYS_REFCLKSEL_MASK |
116 /* COMMON Block configuration during suspend */
117 OTG_SYS_COMMON_ON);
118
119 /* OTG phy & link reset */
120 phyotg |= (OTG_SYS_PHY0_SWRST |
121 OTG_SYS_LINKSWRST_UOTG |
122 OTG_SYS_PHYLINK_SWRESET |
123 OTG_SYS_OTGDISABLE |
124 /* Set phy refclk */
125 OTG_SYS_REFCLKSEL_CLKCORE);
126
127 writel(phyotg, regs + EXYNOS5_PHY_OTG_SYS);
128 udelay(10);
129 phyotg &= ~(OTG_SYS_PHY0_SWRST |
130 OTG_SYS_LINKSWRST_UOTG |
131 OTG_SYS_PHYLINK_SWRESET);
132 writel(phyotg, regs + EXYNOS5_PHY_OTG_SYS);
133
134 /* HSIC phy configuration */
135 phyhsic = (HSIC_CTRL_REFCLKDIV_12 |
136 HSIC_CTRL_REFCLKSEL |
137 HSIC_CTRL_PHYSWRST);
138 writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL1);
139 writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL2);
140 udelay(10);
141 phyhsic &= ~HSIC_CTRL_PHYSWRST;
142 writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL1);
143 writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL2);
144
145 udelay(80);
146
147 /* enable EHCI DMA burst */
148 ehcictrl = readl(regs + EXYNOS5_PHY_HOST_EHCICTRL);
149 ehcictrl |= (HOST_EHCICTRL_ENAINCRXALIGN |
150 HOST_EHCICTRL_ENAINCR4 |
151 HOST_EHCICTRL_ENAINCR8 |
152 HOST_EHCICTRL_ENAINCR16);
153 writel(ehcictrl, regs + EXYNOS5_PHY_HOST_EHCICTRL);
154
155 /* set ohci_suspend_on_n */
156 ohcictrl = readl(regs + EXYNOS5_PHY_HOST_OHCICTRL);
157 ohcictrl |= HOST_OHCICTRL_SUSPLGCY;
158 writel(ohcictrl, regs + EXYNOS5_PHY_HOST_OHCICTRL);
159}
160
161static void samsung_usb2phy_enable(struct samsung_usbphy *sphy)
162{
163 void __iomem *regs = sphy->regs;
164 u32 phypwr;
165 u32 phyclk;
166 u32 rstcon;
167
168 /* set clock frequency for PLL */
169 phyclk = sphy->ref_clk_freq;
170 phypwr = readl(regs + SAMSUNG_PHYPWR);
171 rstcon = readl(regs + SAMSUNG_RSTCON);
172
173 switch (sphy->drv_data->cpu_type) {
174 case TYPE_S3C64XX:
175 phyclk &= ~PHYCLK_COMMON_ON_N;
176 phypwr &= ~PHYPWR_NORMAL_MASK;
177 rstcon |= RSTCON_SWRST;
178 break;
179 case TYPE_EXYNOS4210:
180 phypwr &= ~PHYPWR_NORMAL_MASK_PHY0;
181 rstcon |= RSTCON_SWRST;
182 default:
183 break;
184 }
185
186 writel(phyclk, regs + SAMSUNG_PHYCLK);
187 /* Configure PHY0 for normal operation*/
188 writel(phypwr, regs + SAMSUNG_PHYPWR);
189 /* reset all ports of PHY and Link */
190 writel(rstcon, regs + SAMSUNG_RSTCON);
191 udelay(10);
192 rstcon &= ~RSTCON_SWRST;
193 writel(rstcon, regs + SAMSUNG_RSTCON);
194}
195
196static void samsung_exynos5_usb2phy_disable(struct samsung_usbphy *sphy)
197{
198 void __iomem *regs = sphy->regs;
199 u32 phyhost;
200 u32 phyotg;
201 u32 phyhsic;
202
203 if (atomic_dec_return(&sphy->phy_usage) > 0) {
204 dev_info(sphy->dev, "still being used\n");
205 return;
206 }
207
208 phyhsic = (HSIC_CTRL_REFCLKDIV_12 |
209 HSIC_CTRL_REFCLKSEL |
210 HSIC_CTRL_SIDDQ |
211 HSIC_CTRL_FORCESLEEP |
212 HSIC_CTRL_FORCESUSPEND);
213 writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL1);
214 writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL2);
215
216 phyhost = readl(regs + EXYNOS5_PHY_HOST_CTRL0);
217 phyhost |= (HOST_CTRL0_SIDDQ |
218 HOST_CTRL0_FORCESUSPEND |
219 HOST_CTRL0_FORCESLEEP |
220 HOST_CTRL0_PHYSWRST |
221 HOST_CTRL0_PHYSWRSTALL);
222 writel(phyhost, regs + EXYNOS5_PHY_HOST_CTRL0);
223
224 phyotg = readl(regs + EXYNOS5_PHY_OTG_SYS);
225 phyotg |= (OTG_SYS_FORCESUSPEND |
226 OTG_SYS_SIDDQ_UOTG |
227 OTG_SYS_FORCESLEEP);
228 writel(phyotg, regs + EXYNOS5_PHY_OTG_SYS);
229}
230
231static void samsung_usb2phy_disable(struct samsung_usbphy *sphy)
232{
233 void __iomem *regs = sphy->regs;
234 u32 phypwr;
235
236 phypwr = readl(regs + SAMSUNG_PHYPWR);
237
238 switch (sphy->drv_data->cpu_type) {
239 case TYPE_S3C64XX:
240 phypwr |= PHYPWR_NORMAL_MASK;
241 break;
242 case TYPE_EXYNOS4210:
243 phypwr |= PHYPWR_NORMAL_MASK_PHY0;
244 default:
245 break;
246 }
247
248 /* Disable analog and otg block power */
249 writel(phypwr, regs + SAMSUNG_PHYPWR);
250}
251
252/*
253 * The function passed to the usb driver for phy initialization
254 */
255static int samsung_usb2phy_init(struct usb_phy *phy)
256{
257 struct samsung_usbphy *sphy;
258 struct usb_bus *host = NULL;
259 unsigned long flags;
260 int ret = 0;
261
262 sphy = phy_to_sphy(phy);
263
264 host = phy->otg->host;
265
266 /* Enable the phy clock */
267 ret = clk_prepare_enable(sphy->clk);
268 if (ret) {
269 dev_err(sphy->dev, "%s: clk_prepare_enable failed\n", __func__);
270 return ret;
271 }
272
273 spin_lock_irqsave(&sphy->lock, flags);
274
275 if (host) {
276 /* setting default phy-type for USB 2.0 */
277 if (!strstr(dev_name(host->controller), "ehci") ||
278 !strstr(dev_name(host->controller), "ohci"))
279 samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_HOST);
280 } else {
281 samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_DEVICE);
282 }
283
284 /* Disable phy isolation */
285 if (sphy->plat && sphy->plat->pmu_isolation)
286 sphy->plat->pmu_isolation(false);
287 else
288 samsung_usbphy_set_isolation(sphy, false);
289
290 /* Selecting Host/OTG mode; After reset USB2.0PHY_CFG: HOST */
291 samsung_usbphy_cfg_sel(sphy);
292
293 /* Initialize usb phy registers */
294 if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250)
295 samsung_exynos5_usb2phy_enable(sphy);
296 else
297 samsung_usb2phy_enable(sphy);
298
299 spin_unlock_irqrestore(&sphy->lock, flags);
300
301 /* Disable the phy clock */
302 clk_disable_unprepare(sphy->clk);
303
304 return ret;
305}
306
307/*
308 * The function passed to the usb driver for phy shutdown
309 */
310static void samsung_usb2phy_shutdown(struct usb_phy *phy)
311{
312 struct samsung_usbphy *sphy;
313 struct usb_bus *host = NULL;
314 unsigned long flags;
315
316 sphy = phy_to_sphy(phy);
317
318 host = phy->otg->host;
319
320 if (clk_prepare_enable(sphy->clk)) {
321 dev_err(sphy->dev, "%s: clk_prepare_enable failed\n", __func__);
322 return;
323 }
324
325 spin_lock_irqsave(&sphy->lock, flags);
326
327 if (host) {
328 /* setting default phy-type for USB 2.0 */
329 if (!strstr(dev_name(host->controller), "ehci") ||
330 !strstr(dev_name(host->controller), "ohci"))
331 samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_HOST);
332 } else {
333 samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_DEVICE);
334 }
335
336 /* De-initialize usb phy registers */
337 if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250)
338 samsung_exynos5_usb2phy_disable(sphy);
339 else
340 samsung_usb2phy_disable(sphy);
341
342 /* Enable phy isolation */
343 if (sphy->plat && sphy->plat->pmu_isolation)
344 sphy->plat->pmu_isolation(true);
345 else
346 samsung_usbphy_set_isolation(sphy, true);
347
348 spin_unlock_irqrestore(&sphy->lock, flags);
349
350 clk_disable_unprepare(sphy->clk);
351}
352
353static int samsung_usb2phy_probe(struct platform_device *pdev)
354{
355 struct samsung_usbphy *sphy;
356 struct usb_otg *otg;
357 struct samsung_usbphy_data *pdata = pdev->dev.platform_data;
358 const struct samsung_usbphy_drvdata *drv_data;
359 struct device *dev = &pdev->dev;
360 struct resource *phy_mem;
361 void __iomem *phy_base;
362 struct clk *clk;
363 int ret;
364
365 phy_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
366 if (!phy_mem) {
367 dev_err(dev, "%s: missing mem resource\n", __func__);
368 return -ENODEV;
369 }
370
371 phy_base = devm_ioremap_resource(dev, phy_mem);
372 if (IS_ERR(phy_base))
373 return PTR_ERR(phy_base);
374
375 sphy = devm_kzalloc(dev, sizeof(*sphy), GFP_KERNEL);
376 if (!sphy)
377 return -ENOMEM;
378
379 otg = devm_kzalloc(dev, sizeof(*otg), GFP_KERNEL);
380 if (!otg)
381 return -ENOMEM;
382
383 drv_data = samsung_usbphy_get_driver_data(pdev);
384
385 if (drv_data->cpu_type == TYPE_EXYNOS5250)
386 clk = devm_clk_get(dev, "usbhost");
387 else
388 clk = devm_clk_get(dev, "otg");
389
390 if (IS_ERR(clk)) {
391 dev_err(dev, "Failed to get otg clock\n");
392 return PTR_ERR(clk);
393 }
394
395 sphy->dev = dev;
396
397 if (dev->of_node) {
398 ret = samsung_usbphy_parse_dt(sphy);
399 if (ret < 0)
400 return ret;
401 } else {
402 if (!pdata) {
403 dev_err(dev, "no platform data specified\n");
404 return -EINVAL;
405 }
406 }
407
408 sphy->plat = pdata;
409 sphy->regs = phy_base;
410 sphy->clk = clk;
411 sphy->drv_data = drv_data;
412 sphy->phy.dev = sphy->dev;
413 sphy->phy.label = "samsung-usb2phy";
414 sphy->phy.init = samsung_usb2phy_init;
415 sphy->phy.shutdown = samsung_usb2phy_shutdown;
416 sphy->ref_clk_freq = samsung_usbphy_get_refclk_freq(sphy);
417
418 sphy->phy.otg = otg;
419 sphy->phy.otg->phy = &sphy->phy;
420 sphy->phy.otg->set_host = samsung_usbphy_set_host;
421
422 spin_lock_init(&sphy->lock);
423
424 platform_set_drvdata(pdev, sphy);
425
426 return usb_add_phy(&sphy->phy, USB_PHY_TYPE_USB2);
427}
428
429static int samsung_usb2phy_remove(struct platform_device *pdev)
430{
431 struct samsung_usbphy *sphy = platform_get_drvdata(pdev);
432
433 usb_remove_phy(&sphy->phy);
434
435 if (sphy->pmuregs)
436 iounmap(sphy->pmuregs);
437 if (sphy->sysreg)
438 iounmap(sphy->sysreg);
439
440 return 0;
441}
442
443static const struct samsung_usbphy_drvdata usb2phy_s3c64xx = {
444 .cpu_type = TYPE_S3C64XX,
445 .devphy_en_mask = S3C64XX_USBPHY_ENABLE,
446};
447
448static const struct samsung_usbphy_drvdata usb2phy_exynos4 = {
449 .cpu_type = TYPE_EXYNOS4210,
450 .devphy_en_mask = EXYNOS_USBPHY_ENABLE,
451 .hostphy_en_mask = EXYNOS_USBPHY_ENABLE,
452};
453
454static struct samsung_usbphy_drvdata usb2phy_exynos5 = {
455 .cpu_type = TYPE_EXYNOS5250,
456 .hostphy_en_mask = EXYNOS_USBPHY_ENABLE,
457 .hostphy_reg_offset = EXYNOS_USBHOST_PHY_CTRL_OFFSET,
458};
459
460#ifdef CONFIG_OF
461static const struct of_device_id samsung_usbphy_dt_match[] = {
462 {
463 .compatible = "samsung,s3c64xx-usb2phy",
464 .data = &usb2phy_s3c64xx,
465 }, {
466 .compatible = "samsung,exynos4210-usb2phy",
467 .data = &usb2phy_exynos4,
468 }, {
469 .compatible = "samsung,exynos5250-usb2phy",
470 .data = &usb2phy_exynos5
471 },
472 {},
473};
474MODULE_DEVICE_TABLE(of, samsung_usbphy_dt_match);
475#endif
476
477static struct platform_device_id samsung_usbphy_driver_ids[] = {
478 {
479 .name = "s3c64xx-usb2phy",
480 .driver_data = (unsigned long)&usb2phy_s3c64xx,
481 }, {
482 .name = "exynos4210-usb2phy",
483 .driver_data = (unsigned long)&usb2phy_exynos4,
484 }, {
485 .name = "exynos5250-usb2phy",
486 .driver_data = (unsigned long)&usb2phy_exynos5,
487 },
488 {},
489};
490
491MODULE_DEVICE_TABLE(platform, samsung_usbphy_driver_ids);
492
493static struct platform_driver samsung_usb2phy_driver = {
494 .probe = samsung_usb2phy_probe,
495 .remove = samsung_usb2phy_remove,
496 .id_table = samsung_usbphy_driver_ids,
497 .driver = {
498 .name = "samsung-usb2phy",
499 .owner = THIS_MODULE,
500 .of_match_table = of_match_ptr(samsung_usbphy_dt_match),
501 },
502};
503
504module_platform_driver(samsung_usb2phy_driver);
505
506MODULE_DESCRIPTION("Samsung USB 2.0 phy controller");
507MODULE_AUTHOR("Praveen Paneri <p.paneri@samsung.com>");
508MODULE_LICENSE("GPL");
509MODULE_ALIAS("platform:samsung-usb2phy");
diff --git a/drivers/usb/phy/phy-samsung-usb3.c b/drivers/usb/phy/phy-samsung-usb3.c
new file mode 100644
index 000000000000..133f3d0c554f
--- /dev/null
+++ b/drivers/usb/phy/phy-samsung-usb3.c
@@ -0,0 +1,347 @@
1/* linux/drivers/usb/phy/phy-samsung-usb3.c
2 *
3 * Copyright (c) 2013 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
5 *
6 * Author: Vivek Gautam <gautam.vivek@samsung.com>
7 *
8 * Samsung USB 3.0 PHY transceiver; talks to DWC3 controller.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */
19
20#include <linux/module.h>
21#include <linux/platform_device.h>
22#include <linux/clk.h>
23#include <linux/delay.h>
24#include <linux/err.h>
25#include <linux/io.h>
26#include <linux/of.h>
27#include <linux/usb/samsung_usb_phy.h>
28#include <linux/platform_data/samsung-usbphy.h>
29
30#include "phy-samsung-usb.h"
31
32/*
33 * Sets the phy clk as EXTREFCLK (XXTI) which is internal clock from clock core.
34 */
35static u32 samsung_usb3phy_set_refclk(struct samsung_usbphy *sphy)
36{
37 u32 reg;
38 u32 refclk;
39
40 refclk = sphy->ref_clk_freq;
41
42 reg = PHYCLKRST_REFCLKSEL_EXT_REFCLK |
43 PHYCLKRST_FSEL(refclk);
44
45 switch (refclk) {
46 case FSEL_CLKSEL_50M:
47 reg |= (PHYCLKRST_MPLL_MULTIPLIER_50M_REF |
48 PHYCLKRST_SSC_REFCLKSEL(0x00));
49 break;
50 case FSEL_CLKSEL_20M:
51 reg |= (PHYCLKRST_MPLL_MULTIPLIER_20MHZ_REF |
52 PHYCLKRST_SSC_REFCLKSEL(0x00));
53 break;
54 case FSEL_CLKSEL_19200K:
55 reg |= (PHYCLKRST_MPLL_MULTIPLIER_19200KHZ_REF |
56 PHYCLKRST_SSC_REFCLKSEL(0x88));
57 break;
58 case FSEL_CLKSEL_24M:
59 default:
60 reg |= (PHYCLKRST_MPLL_MULTIPLIER_24MHZ_REF |
61 PHYCLKRST_SSC_REFCLKSEL(0x88));
62 break;
63 }
64
65 return reg;
66}
67
68static int samsung_exynos5_usb3phy_enable(struct samsung_usbphy *sphy)
69{
70 void __iomem *regs = sphy->regs;
71 u32 phyparam0;
72 u32 phyparam1;
73 u32 linksystem;
74 u32 phybatchg;
75 u32 phytest;
76 u32 phyclkrst;
77
78 /* Reset USB 3.0 PHY */
79 writel(0x0, regs + EXYNOS5_DRD_PHYREG0);
80
81 phyparam0 = readl(regs + EXYNOS5_DRD_PHYPARAM0);
82 /* Select PHY CLK source */
83 phyparam0 &= ~PHYPARAM0_REF_USE_PAD;
84 /* Set Loss-of-Signal Detector sensitivity */
85 phyparam0 &= ~PHYPARAM0_REF_LOSLEVEL_MASK;
86 phyparam0 |= PHYPARAM0_REF_LOSLEVEL;
87 writel(phyparam0, regs + EXYNOS5_DRD_PHYPARAM0);
88
89 writel(0x0, regs + EXYNOS5_DRD_PHYRESUME);
90
91 /*
92 * Setting the Frame length Adj value[6:1] to default 0x20
93 * See xHCI 1.0 spec, 5.2.4
94 */
95 linksystem = LINKSYSTEM_XHCI_VERSION_CONTROL |
96 LINKSYSTEM_FLADJ(0x20);
97 writel(linksystem, regs + EXYNOS5_DRD_LINKSYSTEM);
98
99 phyparam1 = readl(regs + EXYNOS5_DRD_PHYPARAM1);
100 /* Set Tx De-Emphasis level */
101 phyparam1 &= ~PHYPARAM1_PCS_TXDEEMPH_MASK;
102 phyparam1 |= PHYPARAM1_PCS_TXDEEMPH;
103 writel(phyparam1, regs + EXYNOS5_DRD_PHYPARAM1);
104
105 phybatchg = readl(regs + EXYNOS5_DRD_PHYBATCHG);
106 phybatchg |= PHYBATCHG_UTMI_CLKSEL;
107 writel(phybatchg, regs + EXYNOS5_DRD_PHYBATCHG);
108
109 /* PHYTEST POWERDOWN Control */
110 phytest = readl(regs + EXYNOS5_DRD_PHYTEST);
111 phytest &= ~(PHYTEST_POWERDOWN_SSP |
112 PHYTEST_POWERDOWN_HSP);
113 writel(phytest, regs + EXYNOS5_DRD_PHYTEST);
114
115 /* UTMI Power Control */
116 writel(PHYUTMI_OTGDISABLE, regs + EXYNOS5_DRD_PHYUTMI);
117
118 phyclkrst = samsung_usb3phy_set_refclk(sphy);
119
120 phyclkrst |= PHYCLKRST_PORTRESET |
121 /* Digital power supply in normal operating mode */
122 PHYCLKRST_RETENABLEN |
123 /* Enable ref clock for SS function */
124 PHYCLKRST_REF_SSP_EN |
125 /* Enable spread spectrum */
126 PHYCLKRST_SSC_EN |
127 /* Power down HS Bias and PLL blocks in suspend mode */
128 PHYCLKRST_COMMONONN;
129
130 writel(phyclkrst, regs + EXYNOS5_DRD_PHYCLKRST);
131
132 udelay(10);
133
134 phyclkrst &= ~(PHYCLKRST_PORTRESET);
135 writel(phyclkrst, regs + EXYNOS5_DRD_PHYCLKRST);
136
137 return 0;
138}
139
140static void samsung_exynos5_usb3phy_disable(struct samsung_usbphy *sphy)
141{
142 u32 phyutmi;
143 u32 phyclkrst;
144 u32 phytest;
145 void __iomem *regs = sphy->regs;
146
147 phyutmi = PHYUTMI_OTGDISABLE |
148 PHYUTMI_FORCESUSPEND |
149 PHYUTMI_FORCESLEEP;
150 writel(phyutmi, regs + EXYNOS5_DRD_PHYUTMI);
151
152 /* Resetting the PHYCLKRST enable bits to reduce leakage current */
153 phyclkrst = readl(regs + EXYNOS5_DRD_PHYCLKRST);
154 phyclkrst &= ~(PHYCLKRST_REF_SSP_EN |
155 PHYCLKRST_SSC_EN |
156 PHYCLKRST_COMMONONN);
157 writel(phyclkrst, regs + EXYNOS5_DRD_PHYCLKRST);
158
159 /* Control PHYTEST to remove leakage current */
160 phytest = readl(regs + EXYNOS5_DRD_PHYTEST);
161 phytest |= (PHYTEST_POWERDOWN_SSP |
162 PHYTEST_POWERDOWN_HSP);
163 writel(phytest, regs + EXYNOS5_DRD_PHYTEST);
164}
165
166static int samsung_usb3phy_init(struct usb_phy *phy)
167{
168 struct samsung_usbphy *sphy;
169 unsigned long flags;
170 int ret = 0;
171
172 sphy = phy_to_sphy(phy);
173
174 /* Enable the phy clock */
175 ret = clk_prepare_enable(sphy->clk);
176 if (ret) {
177 dev_err(sphy->dev, "%s: clk_prepare_enable failed\n", __func__);
178 return ret;
179 }
180
181 spin_lock_irqsave(&sphy->lock, flags);
182
183 /* setting default phy-type for USB 3.0 */
184 samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_DEVICE);
185
186 /* Disable phy isolation */
187 samsung_usbphy_set_isolation(sphy, false);
188
189 /* Initialize usb phy registers */
190 samsung_exynos5_usb3phy_enable(sphy);
191
192 spin_unlock_irqrestore(&sphy->lock, flags);
193
194 /* Disable the phy clock */
195 clk_disable_unprepare(sphy->clk);
196
197 return ret;
198}
199
200/*
201 * The function passed to the usb driver for phy shutdown
202 */
203static void samsung_usb3phy_shutdown(struct usb_phy *phy)
204{
205 struct samsung_usbphy *sphy;
206 unsigned long flags;
207
208 sphy = phy_to_sphy(phy);
209
210 if (clk_prepare_enable(sphy->clk)) {
211 dev_err(sphy->dev, "%s: clk_prepare_enable failed\n", __func__);
212 return;
213 }
214
215 spin_lock_irqsave(&sphy->lock, flags);
216
217 /* setting default phy-type for USB 3.0 */
218 samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_DEVICE);
219
220 /* De-initialize usb phy registers */
221 samsung_exynos5_usb3phy_disable(sphy);
222
223 /* Enable phy isolation */
224 samsung_usbphy_set_isolation(sphy, true);
225
226 spin_unlock_irqrestore(&sphy->lock, flags);
227
228 clk_disable_unprepare(sphy->clk);
229}
230
231static int samsung_usb3phy_probe(struct platform_device *pdev)
232{
233 struct samsung_usbphy *sphy;
234 struct samsung_usbphy_data *pdata = pdev->dev.platform_data;
235 struct device *dev = &pdev->dev;
236 struct resource *phy_mem;
237 void __iomem *phy_base;
238 struct clk *clk;
239 int ret;
240
241 phy_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
242 if (!phy_mem) {
243 dev_err(dev, "%s: missing mem resource\n", __func__);
244 return -ENODEV;
245 }
246
247 phy_base = devm_ioremap_resource(dev, phy_mem);
248 if (IS_ERR(phy_base))
249 return PTR_ERR(phy_base);
250
251 sphy = devm_kzalloc(dev, sizeof(*sphy), GFP_KERNEL);
252 if (!sphy)
253 return -ENOMEM;
254
255 clk = devm_clk_get(dev, "usbdrd30");
256 if (IS_ERR(clk)) {
257 dev_err(dev, "Failed to get device clock\n");
258 return PTR_ERR(clk);
259 }
260
261 sphy->dev = dev;
262
263 if (dev->of_node) {
264 ret = samsung_usbphy_parse_dt(sphy);
265 if (ret < 0)
266 return ret;
267 } else {
268 if (!pdata) {
269 dev_err(dev, "no platform data specified\n");
270 return -EINVAL;
271 }
272 }
273
274 sphy->plat = pdata;
275 sphy->regs = phy_base;
276 sphy->clk = clk;
277 sphy->phy.dev = sphy->dev;
278 sphy->phy.label = "samsung-usb3phy";
279 sphy->phy.init = samsung_usb3phy_init;
280 sphy->phy.shutdown = samsung_usb3phy_shutdown;
281 sphy->drv_data = samsung_usbphy_get_driver_data(pdev);
282 sphy->ref_clk_freq = samsung_usbphy_get_refclk_freq(sphy);
283
284 spin_lock_init(&sphy->lock);
285
286 platform_set_drvdata(pdev, sphy);
287
288 return usb_add_phy(&sphy->phy, USB_PHY_TYPE_USB3);
289}
290
291static int samsung_usb3phy_remove(struct platform_device *pdev)
292{
293 struct samsung_usbphy *sphy = platform_get_drvdata(pdev);
294
295 usb_remove_phy(&sphy->phy);
296
297 if (sphy->pmuregs)
298 iounmap(sphy->pmuregs);
299 if (sphy->sysreg)
300 iounmap(sphy->sysreg);
301
302 return 0;
303}
304
305static struct samsung_usbphy_drvdata usb3phy_exynos5 = {
306 .cpu_type = TYPE_EXYNOS5250,
307 .devphy_en_mask = EXYNOS_USBPHY_ENABLE,
308};
309
310#ifdef CONFIG_OF
311static const struct of_device_id samsung_usbphy_dt_match[] = {
312 {
313 .compatible = "samsung,exynos5250-usb3phy",
314 .data = &usb3phy_exynos5
315 },
316 {},
317};
318MODULE_DEVICE_TABLE(of, samsung_usbphy_dt_match);
319#endif
320
321static struct platform_device_id samsung_usbphy_driver_ids[] = {
322 {
323 .name = "exynos5250-usb3phy",
324 .driver_data = (unsigned long)&usb3phy_exynos5,
325 },
326 {},
327};
328
329MODULE_DEVICE_TABLE(platform, samsung_usbphy_driver_ids);
330
331static struct platform_driver samsung_usb3phy_driver = {
332 .probe = samsung_usb3phy_probe,
333 .remove = samsung_usb3phy_remove,
334 .id_table = samsung_usbphy_driver_ids,
335 .driver = {
336 .name = "samsung-usb3phy",
337 .owner = THIS_MODULE,
338 .of_match_table = of_match_ptr(samsung_usbphy_dt_match),
339 },
340};
341
342module_platform_driver(samsung_usb3phy_driver);
343
344MODULE_DESCRIPTION("Samsung USB 3.0 phy controller");
345MODULE_AUTHOR("Vivek Gautam <gautam.vivek@samsung.com>");
346MODULE_LICENSE("GPL");
347MODULE_ALIAS("platform:samsung-usb3phy");
diff --git a/drivers/usb/phy/tegra_usb_phy.c b/drivers/usb/phy/phy-tegra-usb.c
index 5487d38481af..5487d38481af 100644
--- a/drivers/usb/phy/tegra_usb_phy.c
+++ b/drivers/usb/phy/phy-tegra-usb.c
diff --git a/drivers/usb/otg/twl4030-usb.c b/drivers/usb/phy/phy-twl4030-usb.c
index a994715a3101..8f78d2d40722 100644
--- a/drivers/usb/otg/twl4030-usb.c
+++ b/drivers/usb/phy/phy-twl4030-usb.c
@@ -163,6 +163,8 @@ struct twl4030_usb {
163 bool vbus_supplied; 163 bool vbus_supplied;
164 u8 asleep; 164 u8 asleep;
165 bool irq_enabled; 165 bool irq_enabled;
166
167 struct delayed_work id_workaround_work;
166}; 168};
167 169
168/* internal define on top of container_of */ 170/* internal define on top of container_of */
@@ -246,6 +248,25 @@ twl4030_usb_clear_bits(struct twl4030_usb *twl, u8 reg, u8 bits)
246 248
247/*-------------------------------------------------------------------------*/ 249/*-------------------------------------------------------------------------*/
248 250
251static bool twl4030_is_driving_vbus(struct twl4030_usb *twl)
252{
253 int ret;
254
255 ret = twl4030_usb_read(twl, PHY_CLK_CTRL_STS);
256 if (ret < 0 || !(ret & PHY_DPLL_CLK))
257 /*
258 * if clocks are off, registers are not updated,
259 * but we can assume we don't drive VBUS in this case
260 */
261 return false;
262
263 ret = twl4030_usb_read(twl, ULPI_OTG_CTRL);
264 if (ret < 0)
265 return false;
266
267 return (ret & (ULPI_OTG_DRVVBUS | ULPI_OTG_CHRGVBUS)) ? true : false;
268}
269
249static enum omap_musb_vbus_id_status 270static enum omap_musb_vbus_id_status
250 twl4030_usb_linkstat(struct twl4030_usb *twl) 271 twl4030_usb_linkstat(struct twl4030_usb *twl)
251{ 272{
@@ -268,13 +289,19 @@ static enum omap_musb_vbus_id_status
268 if (status < 0) 289 if (status < 0)
269 dev_err(twl->dev, "USB link status err %d\n", status); 290 dev_err(twl->dev, "USB link status err %d\n", status);
270 else if (status & (BIT(7) | BIT(2))) { 291 else if (status & (BIT(7) | BIT(2))) {
271 if (status & (BIT(7))) 292 if (status & BIT(7)) {
272 twl->vbus_supplied = true; 293 if (twl4030_is_driving_vbus(twl))
294 status &= ~BIT(7);
295 else
296 twl->vbus_supplied = true;
297 }
273 298
274 if (status & BIT(2)) 299 if (status & BIT(2))
275 linkstat = OMAP_MUSB_ID_GROUND; 300 linkstat = OMAP_MUSB_ID_GROUND;
276 else 301 else if (status & BIT(7))
277 linkstat = OMAP_MUSB_VBUS_VALID; 302 linkstat = OMAP_MUSB_VBUS_VALID;
303 else
304 linkstat = OMAP_MUSB_VBUS_OFF;
278 } else { 305 } else {
279 if (twl->linkstat != OMAP_MUSB_UNKNOWN) 306 if (twl->linkstat != OMAP_MUSB_UNKNOWN)
280 linkstat = OMAP_MUSB_VBUS_OFF; 307 linkstat = OMAP_MUSB_VBUS_OFF;
@@ -287,10 +314,6 @@ static enum omap_musb_vbus_id_status
287 * are registered, and that both are active... 314 * are registered, and that both are active...
288 */ 315 */
289 316
290 spin_lock_irq(&twl->lock);
291 twl->linkstat = linkstat;
292 spin_unlock_irq(&twl->lock);
293
294 return linkstat; 317 return linkstat;
295} 318}
296 319
@@ -361,9 +384,17 @@ static void __twl4030_phy_power(struct twl4030_usb *twl, int on)
361 384
362static void twl4030_phy_power(struct twl4030_usb *twl, int on) 385static void twl4030_phy_power(struct twl4030_usb *twl, int on)
363{ 386{
387 int ret;
388
364 if (on) { 389 if (on) {
365 regulator_enable(twl->usb3v1); 390 ret = regulator_enable(twl->usb3v1);
366 regulator_enable(twl->usb1v8); 391 if (ret)
392 dev_err(twl->dev, "Failed to enable usb3v1\n");
393
394 ret = regulator_enable(twl->usb1v8);
395 if (ret)
396 dev_err(twl->dev, "Failed to enable usb1v8\n");
397
367 /* 398 /*
368 * Disabling usb3v1 regulator (= writing 0 to VUSB3V1_DEV_GRP 399 * Disabling usb3v1 regulator (= writing 0 to VUSB3V1_DEV_GRP
369 * in twl4030) resets the VUSB_DEDICATED2 register. This reset 400 * in twl4030) resets the VUSB_DEDICATED2 register. This reset
@@ -372,7 +403,11 @@ static void twl4030_phy_power(struct twl4030_usb *twl, int on)
372 * is re-activated. This ensures that VUSB3V1 is really active. 403 * is re-activated. This ensures that VUSB3V1 is really active.
373 */ 404 */
374 twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB_DEDICATED2); 405 twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB_DEDICATED2);
375 regulator_enable(twl->usb1v5); 406
407 ret = regulator_enable(twl->usb1v5);
408 if (ret)
409 dev_err(twl->dev, "Failed to enable usb1v5\n");
410
376 __twl4030_phy_power(twl, 1); 411 __twl4030_phy_power(twl, 1);
377 twl4030_usb_write(twl, PHY_CLK_CTRL, 412 twl4030_usb_write(twl, PHY_CLK_CTRL,
378 twl4030_usb_read(twl, PHY_CLK_CTRL) | 413 twl4030_usb_read(twl, PHY_CLK_CTRL) |
@@ -412,6 +447,16 @@ static void twl4030_phy_resume(struct twl4030_usb *twl)
412 __twl4030_phy_resume(twl); 447 __twl4030_phy_resume(twl);
413 twl->asleep = 0; 448 twl->asleep = 0;
414 dev_dbg(twl->dev, "%s\n", __func__); 449 dev_dbg(twl->dev, "%s\n", __func__);
450
451 /*
452 * XXX When VBUS gets driven after musb goes to A mode,
453 * ID_PRES related interrupts no longer arrive, why?
454 * Register itself is updated fine though, so we must poll.
455 */
456 if (twl->linkstat == OMAP_MUSB_ID_GROUND) {
457 cancel_delayed_work(&twl->id_workaround_work);
458 schedule_delayed_work(&twl->id_workaround_work, HZ);
459 }
415} 460}
416 461
417static int twl4030_usb_ldo_init(struct twl4030_usb *twl) 462static int twl4030_usb_ldo_init(struct twl4030_usb *twl)
@@ -432,7 +477,7 @@ static int twl4030_usb_ldo_init(struct twl4030_usb *twl)
432 /* Initialize 3.1V regulator */ 477 /* Initialize 3.1V regulator */
433 twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB3V1_DEV_GRP); 478 twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB3V1_DEV_GRP);
434 479
435 twl->usb3v1 = regulator_get(twl->dev, "usb3v1"); 480 twl->usb3v1 = devm_regulator_get(twl->dev, "usb3v1");
436 if (IS_ERR(twl->usb3v1)) 481 if (IS_ERR(twl->usb3v1))
437 return -ENODEV; 482 return -ENODEV;
438 483
@@ -441,18 +486,18 @@ static int twl4030_usb_ldo_init(struct twl4030_usb *twl)
441 /* Initialize 1.5V regulator */ 486 /* Initialize 1.5V regulator */
442 twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB1V5_DEV_GRP); 487 twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB1V5_DEV_GRP);
443 488
444 twl->usb1v5 = regulator_get(twl->dev, "usb1v5"); 489 twl->usb1v5 = devm_regulator_get(twl->dev, "usb1v5");
445 if (IS_ERR(twl->usb1v5)) 490 if (IS_ERR(twl->usb1v5))
446 goto fail1; 491 return -ENODEV;
447 492
448 twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB1V5_TYPE); 493 twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB1V5_TYPE);
449 494
450 /* Initialize 1.8V regulator */ 495 /* Initialize 1.8V regulator */
451 twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB1V8_DEV_GRP); 496 twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB1V8_DEV_GRP);
452 497
453 twl->usb1v8 = regulator_get(twl->dev, "usb1v8"); 498 twl->usb1v8 = devm_regulator_get(twl->dev, "usb1v8");
454 if (IS_ERR(twl->usb1v8)) 499 if (IS_ERR(twl->usb1v8))
455 goto fail2; 500 return -ENODEV;
456 501
457 twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB1V8_TYPE); 502 twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB1V8_TYPE);
458 503
@@ -461,14 +506,6 @@ static int twl4030_usb_ldo_init(struct twl4030_usb *twl)
461 TWL4030_PM_MASTER_PROTECT_KEY); 506 TWL4030_PM_MASTER_PROTECT_KEY);
462 507
463 return 0; 508 return 0;
464
465fail2:
466 regulator_put(twl->usb1v5);
467 twl->usb1v5 = NULL;
468fail1:
469 regulator_put(twl->usb3v1);
470 twl->usb3v1 = NULL;
471 return -ENODEV;
472} 509}
473 510
474static ssize_t twl4030_usb_vbus_show(struct device *dev, 511static ssize_t twl4030_usb_vbus_show(struct device *dev,
@@ -491,9 +528,18 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
491{ 528{
492 struct twl4030_usb *twl = _twl; 529 struct twl4030_usb *twl = _twl;
493 enum omap_musb_vbus_id_status status; 530 enum omap_musb_vbus_id_status status;
531 bool status_changed = false;
494 532
495 status = twl4030_usb_linkstat(twl); 533 status = twl4030_usb_linkstat(twl);
496 if (status > 0) { 534
535 spin_lock_irq(&twl->lock);
536 if (status >= 0 && status != twl->linkstat) {
537 twl->linkstat = status;
538 status_changed = true;
539 }
540 spin_unlock_irq(&twl->lock);
541
542 if (status_changed) {
497 /* FIXME add a set_power() method so that B-devices can 543 /* FIXME add a set_power() method so that B-devices can
498 * configure the charger appropriately. It's not always 544 * configure the charger appropriately. It's not always
499 * correct to consume VBUS power, and how much current to 545 * correct to consume VBUS power, and how much current to
@@ -505,37 +551,62 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
505 * USB_LINK_VBUS state. musb_hdrc won't care until it 551 * USB_LINK_VBUS state. musb_hdrc won't care until it
506 * starts to handle softconnect right. 552 * starts to handle softconnect right.
507 */ 553 */
508 if (status == OMAP_MUSB_VBUS_OFF || 554 omap_musb_mailbox(status);
509 status == OMAP_MUSB_ID_FLOAT)
510 twl4030_phy_suspend(twl, 0);
511 else
512 twl4030_phy_resume(twl);
513
514 omap_musb_mailbox(twl->linkstat);
515 } 555 }
516 sysfs_notify(&twl->dev->kobj, NULL, "vbus"); 556 sysfs_notify(&twl->dev->kobj, NULL, "vbus");
517 557
518 return IRQ_HANDLED; 558 return IRQ_HANDLED;
519} 559}
520 560
521static void twl4030_usb_phy_init(struct twl4030_usb *twl) 561static void twl4030_id_workaround_work(struct work_struct *work)
522{ 562{
563 struct twl4030_usb *twl = container_of(work, struct twl4030_usb,
564 id_workaround_work.work);
523 enum omap_musb_vbus_id_status status; 565 enum omap_musb_vbus_id_status status;
566 bool status_changed = false;
524 567
525 status = twl4030_usb_linkstat(twl); 568 status = twl4030_usb_linkstat(twl);
526 if (status > 0) {
527 if (status == OMAP_MUSB_VBUS_OFF ||
528 status == OMAP_MUSB_ID_FLOAT) {
529 __twl4030_phy_power(twl, 0);
530 twl->asleep = 1;
531 } else {
532 __twl4030_phy_resume(twl);
533 twl->asleep = 0;
534 }
535 569
536 omap_musb_mailbox(twl->linkstat); 570 spin_lock_irq(&twl->lock);
571 if (status >= 0 && status != twl->linkstat) {
572 twl->linkstat = status;
573 status_changed = true;
574 }
575 spin_unlock_irq(&twl->lock);
576
577 if (status_changed) {
578 dev_dbg(twl->dev, "handle missing status change to %d\n",
579 status);
580 omap_musb_mailbox(status);
537 } 581 }
582
583 /* don't schedule during sleep - irq works right then */
584 if (status == OMAP_MUSB_ID_GROUND && !twl->asleep) {
585 cancel_delayed_work(&twl->id_workaround_work);
586 schedule_delayed_work(&twl->id_workaround_work, HZ);
587 }
588}
589
590static int twl4030_usb_phy_init(struct usb_phy *phy)
591{
592 struct twl4030_usb *twl = phy_to_twl(phy);
593 enum omap_musb_vbus_id_status status;
594
595 /*
596 * Start in sleep state, we'll get called through set_suspend()
597 * callback when musb is runtime resumed and it's time to start.
598 */
599 __twl4030_phy_power(twl, 0);
600 twl->asleep = 1;
601
602 status = twl4030_usb_linkstat(twl);
603 twl->linkstat = status;
604
605 if (status == OMAP_MUSB_ID_GROUND || status == OMAP_MUSB_VBUS_VALID)
606 omap_musb_mailbox(twl->linkstat);
607
538 sysfs_notify(&twl->dev->kobj, NULL, "vbus"); 608 sysfs_notify(&twl->dev->kobj, NULL, "vbus");
609 return 0;
539} 610}
540 611
541static int twl4030_set_suspend(struct usb_phy *x, int suspend) 612static int twl4030_set_suspend(struct usb_phy *x, int suspend)
@@ -612,6 +683,7 @@ static int twl4030_usb_probe(struct platform_device *pdev)
612 twl->phy.otg = otg; 683 twl->phy.otg = otg;
613 twl->phy.type = USB_PHY_TYPE_USB2; 684 twl->phy.type = USB_PHY_TYPE_USB2;
614 twl->phy.set_suspend = twl4030_set_suspend; 685 twl->phy.set_suspend = twl4030_set_suspend;
686 twl->phy.init = twl4030_usb_phy_init;
615 687
616 otg->phy = &twl->phy; 688 otg->phy = &twl->phy;
617 otg->set_host = twl4030_set_host; 689 otg->set_host = twl4030_set_host;
@@ -620,6 +692,8 @@ static int twl4030_usb_probe(struct platform_device *pdev)
620 /* init spinlock for workqueue */ 692 /* init spinlock for workqueue */
621 spin_lock_init(&twl->lock); 693 spin_lock_init(&twl->lock);
622 694
695 INIT_DELAYED_WORK(&twl->id_workaround_work, twl4030_id_workaround_work);
696
623 err = twl4030_usb_ldo_init(twl); 697 err = twl4030_usb_ldo_init(twl);
624 if (err) { 698 if (err) {
625 dev_err(&pdev->dev, "ldo init failed\n"); 699 dev_err(&pdev->dev, "ldo init failed\n");
@@ -640,30 +714,25 @@ static int twl4030_usb_probe(struct platform_device *pdev)
640 * need both handles, otherwise just one suffices. 714 * need both handles, otherwise just one suffices.
641 */ 715 */
642 twl->irq_enabled = true; 716 twl->irq_enabled = true;
643 status = request_threaded_irq(twl->irq, NULL, twl4030_usb_irq, 717 status = devm_request_threaded_irq(twl->dev, twl->irq, NULL,
644 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING | 718 twl4030_usb_irq, IRQF_TRIGGER_FALLING |
645 IRQF_ONESHOT, "twl4030_usb", twl); 719 IRQF_TRIGGER_RISING | IRQF_ONESHOT, "twl4030_usb", twl);
646 if (status < 0) { 720 if (status < 0) {
647 dev_dbg(&pdev->dev, "can't get IRQ %d, err %d\n", 721 dev_dbg(&pdev->dev, "can't get IRQ %d, err %d\n",
648 twl->irq, status); 722 twl->irq, status);
649 return status; 723 return status;
650 } 724 }
651 725
652 /* Power down phy or make it work according to
653 * current link state.
654 */
655 twl4030_usb_phy_init(twl);
656
657 dev_info(&pdev->dev, "Initialized TWL4030 USB module\n"); 726 dev_info(&pdev->dev, "Initialized TWL4030 USB module\n");
658 return 0; 727 return 0;
659} 728}
660 729
661static int __exit twl4030_usb_remove(struct platform_device *pdev) 730static int twl4030_usb_remove(struct platform_device *pdev)
662{ 731{
663 struct twl4030_usb *twl = platform_get_drvdata(pdev); 732 struct twl4030_usb *twl = platform_get_drvdata(pdev);
664 int val; 733 int val;
665 734
666 free_irq(twl->irq, twl); 735 cancel_delayed_work(&twl->id_workaround_work);
667 device_remove_file(twl->dev, &dev_attr_vbus); 736 device_remove_file(twl->dev, &dev_attr_vbus);
668 737
669 /* set transceiver mode to power on defaults */ 738 /* set transceiver mode to power on defaults */
@@ -685,9 +754,6 @@ static int __exit twl4030_usb_remove(struct platform_device *pdev)
685 754
686 if (!twl->asleep) 755 if (!twl->asleep)
687 twl4030_phy_power(twl, 0); 756 twl4030_phy_power(twl, 0);
688 regulator_put(twl->usb1v5);
689 regulator_put(twl->usb1v8);
690 regulator_put(twl->usb3v1);
691 757
692 return 0; 758 return 0;
693} 759}
@@ -702,7 +768,7 @@ MODULE_DEVICE_TABLE(of, twl4030_usb_id_table);
702 768
703static struct platform_driver twl4030_usb_driver = { 769static struct platform_driver twl4030_usb_driver = {
704 .probe = twl4030_usb_probe, 770 .probe = twl4030_usb_probe,
705 .remove = __exit_p(twl4030_usb_remove), 771 .remove = twl4030_usb_remove,
706 .driver = { 772 .driver = {
707 .name = "twl4030_usb", 773 .name = "twl4030_usb",
708 .owner = THIS_MODULE, 774 .owner = THIS_MODULE,
diff --git a/drivers/usb/otg/twl6030-usb.c b/drivers/usb/phy/phy-twl6030-usb.c
index 8cd6cf49bdbd..9de7ada90a8b 100644
--- a/drivers/usb/otg/twl6030-usb.c
+++ b/drivers/usb/phy/phy-twl6030-usb.c
@@ -211,6 +211,7 @@ static irqreturn_t twl6030_usb_irq(int irq, void *_twl)
211 struct twl6030_usb *twl = _twl; 211 struct twl6030_usb *twl = _twl;
212 enum omap_musb_vbus_id_status status = OMAP_MUSB_UNKNOWN; 212 enum omap_musb_vbus_id_status status = OMAP_MUSB_UNKNOWN;
213 u8 vbus_state, hw_state; 213 u8 vbus_state, hw_state;
214 int ret;
214 215
215 hw_state = twl6030_readb(twl, TWL6030_MODULE_ID0, STS_HW_CONDITIONS); 216 hw_state = twl6030_readb(twl, TWL6030_MODULE_ID0, STS_HW_CONDITIONS);
216 217
@@ -218,7 +219,10 @@ static irqreturn_t twl6030_usb_irq(int irq, void *_twl)
218 CONTROLLER_STAT1); 219 CONTROLLER_STAT1);
219 if (!(hw_state & STS_USB_ID)) { 220 if (!(hw_state & STS_USB_ID)) {
220 if (vbus_state & VBUS_DET) { 221 if (vbus_state & VBUS_DET) {
221 regulator_enable(twl->usb3v3); 222 ret = regulator_enable(twl->usb3v3);
223 if (ret)
224 dev_err(twl->dev, "Failed to enable usb3v3\n");
225
222 twl->asleep = 1; 226 twl->asleep = 1;
223 status = OMAP_MUSB_VBUS_VALID; 227 status = OMAP_MUSB_VBUS_VALID;
224 twl->linkstat = status; 228 twl->linkstat = status;
@@ -245,12 +249,15 @@ static irqreturn_t twl6030_usbotg_irq(int irq, void *_twl)
245 struct twl6030_usb *twl = _twl; 249 struct twl6030_usb *twl = _twl;
246 enum omap_musb_vbus_id_status status = OMAP_MUSB_UNKNOWN; 250 enum omap_musb_vbus_id_status status = OMAP_MUSB_UNKNOWN;
247 u8 hw_state; 251 u8 hw_state;
252 int ret;
248 253
249 hw_state = twl6030_readb(twl, TWL6030_MODULE_ID0, STS_HW_CONDITIONS); 254 hw_state = twl6030_readb(twl, TWL6030_MODULE_ID0, STS_HW_CONDITIONS);
250 255
251 if (hw_state & STS_USB_ID) { 256 if (hw_state & STS_USB_ID) {
257 ret = regulator_enable(twl->usb3v3);
258 if (ret)
259 dev_err(twl->dev, "Failed to enable usb3v3\n");
252 260
253 regulator_enable(twl->usb3v3);
254 twl->asleep = 1; 261 twl->asleep = 1;
255 twl6030_writeb(twl, TWL_MODULE_USB, 0x1, USB_ID_INT_EN_HI_CLR); 262 twl6030_writeb(twl, TWL_MODULE_USB, 0x1, USB_ID_INT_EN_HI_CLR);
256 twl6030_writeb(twl, TWL_MODULE_USB, 0x10, USB_ID_INT_EN_HI_SET); 263 twl6030_writeb(twl, TWL_MODULE_USB, 0x10, USB_ID_INT_EN_HI_SET);
@@ -393,7 +400,7 @@ static int twl6030_usb_probe(struct platform_device *pdev)
393 return 0; 400 return 0;
394} 401}
395 402
396static int __exit twl6030_usb_remove(struct platform_device *pdev) 403static int twl6030_usb_remove(struct platform_device *pdev)
397{ 404{
398 struct twl6030_usb *twl = platform_get_drvdata(pdev); 405 struct twl6030_usb *twl = platform_get_drvdata(pdev);
399 406
@@ -420,7 +427,7 @@ MODULE_DEVICE_TABLE(of, twl6030_usb_id_table);
420 427
421static struct platform_driver twl6030_usb_driver = { 428static struct platform_driver twl6030_usb_driver = {
422 .probe = twl6030_usb_probe, 429 .probe = twl6030_usb_probe,
423 .remove = __exit_p(twl6030_usb_remove), 430 .remove = twl6030_usb_remove,
424 .driver = { 431 .driver = {
425 .name = "twl6030_usb", 432 .name = "twl6030_usb",
426 .owner = THIS_MODULE, 433 .owner = THIS_MODULE,
diff --git a/drivers/usb/otg/ulpi_viewport.c b/drivers/usb/phy/phy-ulpi-viewport.c
index c5ba7e5423fc..c5ba7e5423fc 100644
--- a/drivers/usb/otg/ulpi_viewport.c
+++ b/drivers/usb/phy/phy-ulpi-viewport.c
diff --git a/drivers/usb/otg/ulpi.c b/drivers/usb/phy/phy-ulpi.c
index 217339dd7a90..217339dd7a90 100644
--- a/drivers/usb/otg/ulpi.c
+++ b/drivers/usb/phy/phy-ulpi.c
diff --git a/drivers/usb/otg/otg.c b/drivers/usb/phy/phy.c
index 2bd03d261a50..f52c006417ff 100644
--- a/drivers/usb/otg/otg.c
+++ b/drivers/usb/phy/phy.c
@@ -1,14 +1,13 @@
1/* 1/*
2 * otg.c -- USB OTG utility code 2 * phy.c -- USB phy handling
3 * 3 *
4 * Copyright (C) 2004 Texas Instruments 4 * Copyright (C) 2004-2013 Texas Instruments
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or 8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version. 9 * (at your option) any later version.
10 */ 10 */
11
12#include <linux/kernel.h> 11#include <linux/kernel.h>
13#include <linux/export.h> 12#include <linux/export.h>
14#include <linux/err.h> 13#include <linux/err.h>
@@ -17,7 +16,7 @@
17#include <linux/slab.h> 16#include <linux/slab.h>
18#include <linux/of.h> 17#include <linux/of.h>
19 18
20#include <linux/usb/otg.h> 19#include <linux/usb/phy.h>
21 20
22static LIST_HEAD(phy_list); 21static LIST_HEAD(phy_list);
23static LIST_HEAD(phy_bind_list); 22static LIST_HEAD(phy_bind_list);
@@ -110,7 +109,7 @@ struct usb_phy *devm_usb_get_phy(struct device *dev, enum usb_phy_type type)
110 109
111 return phy; 110 return phy;
112} 111}
113EXPORT_SYMBOL(devm_usb_get_phy); 112EXPORT_SYMBOL_GPL(devm_usb_get_phy);
114 113
115/** 114/**
116 * usb_get_phy - find the USB PHY 115 * usb_get_phy - find the USB PHY
@@ -143,7 +142,7 @@ err0:
143 142
144 return phy; 143 return phy;
145} 144}
146EXPORT_SYMBOL(usb_get_phy); 145EXPORT_SYMBOL_GPL(usb_get_phy);
147 146
148 /** 147 /**
149 * devm_usb_get_phy_by_phandle - find the USB PHY by phandle 148 * devm_usb_get_phy_by_phandle - find the USB PHY by phandle
@@ -207,7 +206,7 @@ err0:
207 206
208 return phy; 207 return phy;
209} 208}
210EXPORT_SYMBOL(devm_usb_get_phy_by_phandle); 209EXPORT_SYMBOL_GPL(devm_usb_get_phy_by_phandle);
211 210
212/** 211/**
213 * usb_get_phy_dev - find the USB PHY 212 * usb_get_phy_dev - find the USB PHY
@@ -240,7 +239,7 @@ err0:
240 239
241 return phy; 240 return phy;
242} 241}
243EXPORT_SYMBOL(usb_get_phy_dev); 242EXPORT_SYMBOL_GPL(usb_get_phy_dev);
244 243
245/** 244/**
246 * devm_usb_get_phy_dev - find the USB PHY using device ptr and index 245 * devm_usb_get_phy_dev - find the USB PHY using device ptr and index
@@ -270,7 +269,7 @@ struct usb_phy *devm_usb_get_phy_dev(struct device *dev, u8 index)
270 269
271 return phy; 270 return phy;
272} 271}
273EXPORT_SYMBOL(devm_usb_get_phy_dev); 272EXPORT_SYMBOL_GPL(devm_usb_get_phy_dev);
274 273
275/** 274/**
276 * devm_usb_put_phy - release the USB PHY 275 * devm_usb_put_phy - release the USB PHY
@@ -289,7 +288,7 @@ void devm_usb_put_phy(struct device *dev, struct usb_phy *phy)
289 r = devres_destroy(dev, devm_usb_phy_release, devm_usb_phy_match, phy); 288 r = devres_destroy(dev, devm_usb_phy_release, devm_usb_phy_match, phy);
290 dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n"); 289 dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n");
291} 290}
292EXPORT_SYMBOL(devm_usb_put_phy); 291EXPORT_SYMBOL_GPL(devm_usb_put_phy);
293 292
294/** 293/**
295 * usb_put_phy - release the USB PHY 294 * usb_put_phy - release the USB PHY
@@ -308,7 +307,7 @@ void usb_put_phy(struct usb_phy *x)
308 module_put(owner); 307 module_put(owner);
309 } 308 }
310} 309}
311EXPORT_SYMBOL(usb_put_phy); 310EXPORT_SYMBOL_GPL(usb_put_phy);
312 311
313/** 312/**
314 * usb_add_phy - declare the USB PHY 313 * usb_add_phy - declare the USB PHY
@@ -348,7 +347,7 @@ out:
348 spin_unlock_irqrestore(&phy_lock, flags); 347 spin_unlock_irqrestore(&phy_lock, flags);
349 return ret; 348 return ret;
350} 349}
351EXPORT_SYMBOL(usb_add_phy); 350EXPORT_SYMBOL_GPL(usb_add_phy);
352 351
353/** 352/**
354 * usb_add_phy_dev - declare the USB PHY 353 * usb_add_phy_dev - declare the USB PHY
@@ -378,7 +377,7 @@ int usb_add_phy_dev(struct usb_phy *x)
378 spin_unlock_irqrestore(&phy_lock, flags); 377 spin_unlock_irqrestore(&phy_lock, flags);
379 return 0; 378 return 0;
380} 379}
381EXPORT_SYMBOL(usb_add_phy_dev); 380EXPORT_SYMBOL_GPL(usb_add_phy_dev);
382 381
383/** 382/**
384 * usb_remove_phy - remove the OTG PHY 383 * usb_remove_phy - remove the OTG PHY
@@ -400,7 +399,7 @@ void usb_remove_phy(struct usb_phy *x)
400 } 399 }
401 spin_unlock_irqrestore(&phy_lock, flags); 400 spin_unlock_irqrestore(&phy_lock, flags);
402} 401}
403EXPORT_SYMBOL(usb_remove_phy); 402EXPORT_SYMBOL_GPL(usb_remove_phy);
404 403
405/** 404/**
406 * usb_bind_phy - bind the phy and the controller that uses the phy 405 * usb_bind_phy - bind the phy and the controller that uses the phy
@@ -437,38 +436,3 @@ int __init usb_bind_phy(const char *dev_name, u8 index,
437 return 0; 436 return 0;
438} 437}
439EXPORT_SYMBOL_GPL(usb_bind_phy); 438EXPORT_SYMBOL_GPL(usb_bind_phy);
440
441const char *otg_state_string(enum usb_otg_state state)
442{
443 switch (state) {
444 case OTG_STATE_A_IDLE:
445 return "a_idle";
446 case OTG_STATE_A_WAIT_VRISE:
447 return "a_wait_vrise";
448 case OTG_STATE_A_WAIT_BCON:
449 return "a_wait_bcon";
450 case OTG_STATE_A_HOST:
451 return "a_host";
452 case OTG_STATE_A_SUSPEND:
453 return "a_suspend";
454 case OTG_STATE_A_PERIPHERAL:
455 return "a_peripheral";
456 case OTG_STATE_A_WAIT_VFALL:
457 return "a_wait_vfall";
458 case OTG_STATE_A_VBUS_ERR:
459 return "a_vbus_err";
460 case OTG_STATE_B_IDLE:
461 return "b_idle";
462 case OTG_STATE_B_SRP_INIT:
463 return "b_srp_init";
464 case OTG_STATE_B_PERIPHERAL:
465 return "b_peripheral";
466 case OTG_STATE_B_WAIT_ACON:
467 return "b_wait_acon";
468 case OTG_STATE_B_HOST:
469 return "b_host";
470 default:
471 return "UNDEFINED";
472 }
473}
474EXPORT_SYMBOL(otg_state_string);
diff --git a/drivers/usb/phy/samsung-usbphy.c b/drivers/usb/phy/samsung-usbphy.c
deleted file mode 100644
index 967101ec15fd..000000000000
--- a/drivers/usb/phy/samsung-usbphy.c
+++ /dev/null
@@ -1,928 +0,0 @@
1/* linux/drivers/usb/phy/samsung-usbphy.c
2 *
3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
5 *
6 * Author: Praveen Paneri <p.paneri@samsung.com>
7 *
8 * Samsung USB2.0 PHY transceiver; talks to S3C HS OTG controller, EHCI-S5P and
9 * OHCI-EXYNOS controllers.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21#include <linux/module.h>
22#include <linux/platform_device.h>
23#include <linux/clk.h>
24#include <linux/delay.h>
25#include <linux/device.h>
26#include <linux/err.h>
27#include <linux/io.h>
28#include <linux/of.h>
29#include <linux/of_address.h>
30#include <linux/usb/otg.h>
31#include <linux/usb/samsung_usb_phy.h>
32#include <linux/platform_data/samsung-usbphy.h>
33
34/* Register definitions */
35
36#define SAMSUNG_PHYPWR (0x00)
37
38#define PHYPWR_NORMAL_MASK (0x19 << 0)
39#define PHYPWR_OTG_DISABLE (0x1 << 4)
40#define PHYPWR_ANALOG_POWERDOWN (0x1 << 3)
41#define PHYPWR_FORCE_SUSPEND (0x1 << 1)
42/* For Exynos4 */
43#define PHYPWR_NORMAL_MASK_PHY0 (0x39 << 0)
44#define PHYPWR_SLEEP_PHY0 (0x1 << 5)
45
46#define SAMSUNG_PHYCLK (0x04)
47
48#define PHYCLK_MODE_USB11 (0x1 << 6)
49#define PHYCLK_EXT_OSC (0x1 << 5)
50#define PHYCLK_COMMON_ON_N (0x1 << 4)
51#define PHYCLK_ID_PULL (0x1 << 2)
52#define PHYCLK_CLKSEL_MASK (0x3 << 0)
53#define PHYCLK_CLKSEL_48M (0x0 << 0)
54#define PHYCLK_CLKSEL_12M (0x2 << 0)
55#define PHYCLK_CLKSEL_24M (0x3 << 0)
56
57#define SAMSUNG_RSTCON (0x08)
58
59#define RSTCON_PHYLINK_SWRST (0x1 << 2)
60#define RSTCON_HLINK_SWRST (0x1 << 1)
61#define RSTCON_SWRST (0x1 << 0)
62
63/* EXYNOS5 */
64#define EXYNOS5_PHY_HOST_CTRL0 (0x00)
65
66#define HOST_CTRL0_PHYSWRSTALL (0x1 << 31)
67
68#define HOST_CTRL0_REFCLKSEL_MASK (0x3 << 19)
69#define HOST_CTRL0_REFCLKSEL_XTAL (0x0 << 19)
70#define HOST_CTRL0_REFCLKSEL_EXTL (0x1 << 19)
71#define HOST_CTRL0_REFCLKSEL_CLKCORE (0x2 << 19)
72
73#define HOST_CTRL0_FSEL_MASK (0x7 << 16)
74#define HOST_CTRL0_FSEL(_x) ((_x) << 16)
75
76#define FSEL_CLKSEL_50M (0x7)
77#define FSEL_CLKSEL_24M (0x5)
78#define FSEL_CLKSEL_20M (0x4)
79#define FSEL_CLKSEL_19200K (0x3)
80#define FSEL_CLKSEL_12M (0x2)
81#define FSEL_CLKSEL_10M (0x1)
82#define FSEL_CLKSEL_9600K (0x0)
83
84#define HOST_CTRL0_TESTBURNIN (0x1 << 11)
85#define HOST_CTRL0_RETENABLE (0x1 << 10)
86#define HOST_CTRL0_COMMONON_N (0x1 << 9)
87#define HOST_CTRL0_SIDDQ (0x1 << 6)
88#define HOST_CTRL0_FORCESLEEP (0x1 << 5)
89#define HOST_CTRL0_FORCESUSPEND (0x1 << 4)
90#define HOST_CTRL0_WORDINTERFACE (0x1 << 3)
91#define HOST_CTRL0_UTMISWRST (0x1 << 2)
92#define HOST_CTRL0_LINKSWRST (0x1 << 1)
93#define HOST_CTRL0_PHYSWRST (0x1 << 0)
94
95#define EXYNOS5_PHY_HOST_TUNE0 (0x04)
96
97#define EXYNOS5_PHY_HSIC_CTRL1 (0x10)
98
99#define EXYNOS5_PHY_HSIC_TUNE1 (0x14)
100
101#define EXYNOS5_PHY_HSIC_CTRL2 (0x20)
102
103#define EXYNOS5_PHY_HSIC_TUNE2 (0x24)
104
105#define HSIC_CTRL_REFCLKSEL_MASK (0x3 << 23)
106#define HSIC_CTRL_REFCLKSEL (0x2 << 23)
107
108#define HSIC_CTRL_REFCLKDIV_MASK (0x7f << 16)
109#define HSIC_CTRL_REFCLKDIV(_x) ((_x) << 16)
110#define HSIC_CTRL_REFCLKDIV_12 (0x24 << 16)
111#define HSIC_CTRL_REFCLKDIV_15 (0x1c << 16)
112#define HSIC_CTRL_REFCLKDIV_16 (0x1a << 16)
113#define HSIC_CTRL_REFCLKDIV_19_2 (0x15 << 16)
114#define HSIC_CTRL_REFCLKDIV_20 (0x14 << 16)
115
116#define HSIC_CTRL_SIDDQ (0x1 << 6)
117#define HSIC_CTRL_FORCESLEEP (0x1 << 5)
118#define HSIC_CTRL_FORCESUSPEND (0x1 << 4)
119#define HSIC_CTRL_WORDINTERFACE (0x1 << 3)
120#define HSIC_CTRL_UTMISWRST (0x1 << 2)
121#define HSIC_CTRL_PHYSWRST (0x1 << 0)
122
123#define EXYNOS5_PHY_HOST_EHCICTRL (0x30)
124
125#define HOST_EHCICTRL_ENAINCRXALIGN (0x1 << 29)
126#define HOST_EHCICTRL_ENAINCR4 (0x1 << 28)
127#define HOST_EHCICTRL_ENAINCR8 (0x1 << 27)
128#define HOST_EHCICTRL_ENAINCR16 (0x1 << 26)
129
130#define EXYNOS5_PHY_HOST_OHCICTRL (0x34)
131
132#define HOST_OHCICTRL_SUSPLGCY (0x1 << 3)
133#define HOST_OHCICTRL_APPSTARTCLK (0x1 << 2)
134#define HOST_OHCICTRL_CNTSEL (0x1 << 1)
135#define HOST_OHCICTRL_CLKCKTRST (0x1 << 0)
136
137#define EXYNOS5_PHY_OTG_SYS (0x38)
138
139#define OTG_SYS_PHYLINK_SWRESET (0x1 << 14)
140#define OTG_SYS_LINKSWRST_UOTG (0x1 << 13)
141#define OTG_SYS_PHY0_SWRST (0x1 << 12)
142
143#define OTG_SYS_REFCLKSEL_MASK (0x3 << 9)
144#define OTG_SYS_REFCLKSEL_XTAL (0x0 << 9)
145#define OTG_SYS_REFCLKSEL_EXTL (0x1 << 9)
146#define OTG_SYS_REFCLKSEL_CLKCORE (0x2 << 9)
147
148#define OTG_SYS_IDPULLUP_UOTG (0x1 << 8)
149#define OTG_SYS_COMMON_ON (0x1 << 7)
150
151#define OTG_SYS_FSEL_MASK (0x7 << 4)
152#define OTG_SYS_FSEL(_x) ((_x) << 4)
153
154#define OTG_SYS_FORCESLEEP (0x1 << 3)
155#define OTG_SYS_OTGDISABLE (0x1 << 2)
156#define OTG_SYS_SIDDQ_UOTG (0x1 << 1)
157#define OTG_SYS_FORCESUSPEND (0x1 << 0)
158
159#define EXYNOS5_PHY_OTG_TUNE (0x40)
160
161#ifndef MHZ
162#define MHZ (1000*1000)
163#endif
164
165#ifndef KHZ
166#define KHZ (1000)
167#endif
168
169#define EXYNOS_USBHOST_PHY_CTRL_OFFSET (0x4)
170#define S3C64XX_USBPHY_ENABLE (0x1 << 16)
171#define EXYNOS_USBPHY_ENABLE (0x1 << 0)
172#define EXYNOS_USB20PHY_CFG_HOST_LINK (0x1 << 0)
173
174enum samsung_cpu_type {
175 TYPE_S3C64XX,
176 TYPE_EXYNOS4210,
177 TYPE_EXYNOS5250,
178};
179
180/*
181 * struct samsung_usbphy_drvdata - driver data for various SoC variants
182 * @cpu_type: machine identifier
183 * @devphy_en_mask: device phy enable mask for PHY CONTROL register
184 * @hostphy_en_mask: host phy enable mask for PHY CONTROL register
185 * @devphy_reg_offset: offset to DEVICE PHY CONTROL register from
186 * mapped address of system controller.
187 * @hostphy_reg_offset: offset to HOST PHY CONTROL register from
188 * mapped address of system controller.
189 *
190 * Here we have a separate mask for device type phy.
191 * Having different masks for host and device type phy helps
192 * in setting independent masks in case of SoCs like S5PV210,
193 * in which PHY0 and PHY1 enable bits belong to same register
194 * placed at position 0 and 1 respectively.
195 * Although for newer SoCs like exynos these bits belong to
196 * different registers altogether placed at position 0.
197 */
198struct samsung_usbphy_drvdata {
199 int cpu_type;
200 int devphy_en_mask;
201 int hostphy_en_mask;
202 u32 devphy_reg_offset;
203 u32 hostphy_reg_offset;
204};
205
206/*
207 * struct samsung_usbphy - transceiver driver state
208 * @phy: transceiver structure
209 * @plat: platform data
210 * @dev: The parent device supplied to the probe function
211 * @clk: usb phy clock
212 * @regs: usb phy controller registers memory base
213 * @pmuregs: USB device PHY_CONTROL register memory base
214 * @sysreg: USB2.0 PHY_CFG register memory base
215 * @ref_clk_freq: reference clock frequency selection
216 * @drv_data: driver data available for different SoCs
217 * @phy_type: Samsung SoCs specific phy types: #HOST
218 * #DEVICE
219 * @phy_usage: usage count for phy
220 * @lock: lock for phy operations
221 */
222struct samsung_usbphy {
223 struct usb_phy phy;
224 struct samsung_usbphy_data *plat;
225 struct device *dev;
226 struct clk *clk;
227 void __iomem *regs;
228 void __iomem *pmuregs;
229 void __iomem *sysreg;
230 int ref_clk_freq;
231 const struct samsung_usbphy_drvdata *drv_data;
232 enum samsung_usb_phy_type phy_type;
233 atomic_t phy_usage;
234 spinlock_t lock;
235};
236
237#define phy_to_sphy(x) container_of((x), struct samsung_usbphy, phy)
238
239int samsung_usbphy_set_host(struct usb_otg *otg, struct usb_bus *host)
240{
241 if (!otg)
242 return -ENODEV;
243
244 if (!otg->host)
245 otg->host = host;
246
247 return 0;
248}
249
250static int samsung_usbphy_parse_dt(struct samsung_usbphy *sphy)
251{
252 struct device_node *usbphy_sys;
253
254 /* Getting node for system controller interface for usb-phy */
255 usbphy_sys = of_get_child_by_name(sphy->dev->of_node, "usbphy-sys");
256 if (!usbphy_sys) {
257 dev_err(sphy->dev, "No sys-controller interface for usb-phy\n");
258 return -ENODEV;
259 }
260
261 sphy->pmuregs = of_iomap(usbphy_sys, 0);
262
263 if (sphy->pmuregs == NULL) {
264 dev_err(sphy->dev, "Can't get usb-phy pmu control register\n");
265 goto err0;
266 }
267
268 sphy->sysreg = of_iomap(usbphy_sys, 1);
269
270 /*
271 * Not returning error code here, since this situation is not fatal.
272 * Few SoCs may not have this switch available
273 */
274 if (sphy->sysreg == NULL)
275 dev_warn(sphy->dev, "Can't get usb-phy sysreg cfg register\n");
276
277 of_node_put(usbphy_sys);
278
279 return 0;
280
281err0:
282 of_node_put(usbphy_sys);
283 return -ENXIO;
284}
285
286/*
287 * Set isolation here for phy.
288 * Here 'on = true' would mean USB PHY block is isolated, hence
289 * de-activated and vice-versa.
290 */
291static void samsung_usbphy_set_isolation(struct samsung_usbphy *sphy, bool on)
292{
293 void __iomem *reg = NULL;
294 u32 reg_val;
295 u32 en_mask = 0;
296
297 if (!sphy->pmuregs) {
298 dev_warn(sphy->dev, "Can't set pmu isolation\n");
299 return;
300 }
301
302 switch (sphy->drv_data->cpu_type) {
303 case TYPE_S3C64XX:
304 /*
305 * Do nothing: We will add here once S3C64xx goes for DT support
306 */
307 break;
308 case TYPE_EXYNOS4210:
309 /*
310 * Fall through since exynos4210 and exynos5250 have similar
311 * register architecture: two separate registers for host and
312 * device phy control with enable bit at position 0.
313 */
314 case TYPE_EXYNOS5250:
315 if (sphy->phy_type == USB_PHY_TYPE_DEVICE) {
316 reg = sphy->pmuregs +
317 sphy->drv_data->devphy_reg_offset;
318 en_mask = sphy->drv_data->devphy_en_mask;
319 } else if (sphy->phy_type == USB_PHY_TYPE_HOST) {
320 reg = sphy->pmuregs +
321 sphy->drv_data->hostphy_reg_offset;
322 en_mask = sphy->drv_data->hostphy_en_mask;
323 }
324 break;
325 default:
326 dev_err(sphy->dev, "Invalid SoC type\n");
327 return;
328 }
329
330 reg_val = readl(reg);
331
332 if (on)
333 reg_val &= ~en_mask;
334 else
335 reg_val |= en_mask;
336
337 writel(reg_val, reg);
338}
339
340/*
341 * Configure the mode of working of usb-phy here: HOST/DEVICE.
342 */
343static void samsung_usbphy_cfg_sel(struct samsung_usbphy *sphy)
344{
345 u32 reg;
346
347 if (!sphy->sysreg) {
348 dev_warn(sphy->dev, "Can't configure specified phy mode\n");
349 return;
350 }
351
352 reg = readl(sphy->sysreg);
353
354 if (sphy->phy_type == USB_PHY_TYPE_DEVICE)
355 reg &= ~EXYNOS_USB20PHY_CFG_HOST_LINK;
356 else if (sphy->phy_type == USB_PHY_TYPE_HOST)
357 reg |= EXYNOS_USB20PHY_CFG_HOST_LINK;
358
359 writel(reg, sphy->sysreg);
360}
361
362/*
363 * PHYs are different for USB Device and USB Host.
364 * This make sure that correct PHY type is selected before
365 * any operation on PHY.
366 */
367static int samsung_usbphy_set_type(struct usb_phy *phy,
368 enum samsung_usb_phy_type phy_type)
369{
370 struct samsung_usbphy *sphy = phy_to_sphy(phy);
371
372 sphy->phy_type = phy_type;
373
374 return 0;
375}
376
377/*
378 * Returns reference clock frequency selection value
379 */
380static int samsung_usbphy_get_refclk_freq(struct samsung_usbphy *sphy)
381{
382 struct clk *ref_clk;
383 int refclk_freq = 0;
384
385 /*
386 * In exynos5250 USB host and device PHY use
387 * external crystal clock XXTI
388 */
389 if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250)
390 ref_clk = clk_get(sphy->dev, "ext_xtal");
391 else
392 ref_clk = clk_get(sphy->dev, "xusbxti");
393 if (IS_ERR(ref_clk)) {
394 dev_err(sphy->dev, "Failed to get reference clock\n");
395 return PTR_ERR(ref_clk);
396 }
397
398 if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250) {
399 /* set clock frequency for PLL */
400 switch (clk_get_rate(ref_clk)) {
401 case 9600 * KHZ:
402 refclk_freq = FSEL_CLKSEL_9600K;
403 break;
404 case 10 * MHZ:
405 refclk_freq = FSEL_CLKSEL_10M;
406 break;
407 case 12 * MHZ:
408 refclk_freq = FSEL_CLKSEL_12M;
409 break;
410 case 19200 * KHZ:
411 refclk_freq = FSEL_CLKSEL_19200K;
412 break;
413 case 20 * MHZ:
414 refclk_freq = FSEL_CLKSEL_20M;
415 break;
416 case 50 * MHZ:
417 refclk_freq = FSEL_CLKSEL_50M;
418 break;
419 case 24 * MHZ:
420 default:
421 /* default reference clock */
422 refclk_freq = FSEL_CLKSEL_24M;
423 break;
424 }
425 } else {
426 switch (clk_get_rate(ref_clk)) {
427 case 12 * MHZ:
428 refclk_freq = PHYCLK_CLKSEL_12M;
429 break;
430 case 24 * MHZ:
431 refclk_freq = PHYCLK_CLKSEL_24M;
432 break;
433 case 48 * MHZ:
434 refclk_freq = PHYCLK_CLKSEL_48M;
435 break;
436 default:
437 if (sphy->drv_data->cpu_type == TYPE_S3C64XX)
438 refclk_freq = PHYCLK_CLKSEL_48M;
439 else
440 refclk_freq = PHYCLK_CLKSEL_24M;
441 break;
442 }
443 }
444 clk_put(ref_clk);
445
446 return refclk_freq;
447}
448
449static bool exynos5_phyhost_is_on(void *regs)
450{
451 u32 reg;
452
453 reg = readl(regs + EXYNOS5_PHY_HOST_CTRL0);
454
455 return !(reg & HOST_CTRL0_SIDDQ);
456}
457
458static void samsung_exynos5_usbphy_enable(struct samsung_usbphy *sphy)
459{
460 void __iomem *regs = sphy->regs;
461 u32 phyclk = sphy->ref_clk_freq;
462 u32 phyhost;
463 u32 phyotg;
464 u32 phyhsic;
465 u32 ehcictrl;
466 u32 ohcictrl;
467
468 /*
469 * phy_usage helps in keeping usage count for phy
470 * so that the first consumer enabling the phy is also
471 * the last consumer to disable it.
472 */
473
474 atomic_inc(&sphy->phy_usage);
475
476 if (exynos5_phyhost_is_on(regs)) {
477 dev_info(sphy->dev, "Already power on PHY\n");
478 return;
479 }
480
481 /* Host configuration */
482 phyhost = readl(regs + EXYNOS5_PHY_HOST_CTRL0);
483
484 /* phy reference clock configuration */
485 phyhost &= ~HOST_CTRL0_FSEL_MASK;
486 phyhost |= HOST_CTRL0_FSEL(phyclk);
487
488 /* host phy reset */
489 phyhost &= ~(HOST_CTRL0_PHYSWRST |
490 HOST_CTRL0_PHYSWRSTALL |
491 HOST_CTRL0_SIDDQ |
492 /* Enable normal mode of operation */
493 HOST_CTRL0_FORCESUSPEND |
494 HOST_CTRL0_FORCESLEEP);
495
496 /* Link reset */
497 phyhost |= (HOST_CTRL0_LINKSWRST |
498 HOST_CTRL0_UTMISWRST |
499 /* COMMON Block configuration during suspend */
500 HOST_CTRL0_COMMONON_N);
501 writel(phyhost, regs + EXYNOS5_PHY_HOST_CTRL0);
502 udelay(10);
503 phyhost &= ~(HOST_CTRL0_LINKSWRST |
504 HOST_CTRL0_UTMISWRST);
505 writel(phyhost, regs + EXYNOS5_PHY_HOST_CTRL0);
506
507 /* OTG configuration */
508 phyotg = readl(regs + EXYNOS5_PHY_OTG_SYS);
509
510 /* phy reference clock configuration */
511 phyotg &= ~OTG_SYS_FSEL_MASK;
512 phyotg |= OTG_SYS_FSEL(phyclk);
513
514 /* Enable normal mode of operation */
515 phyotg &= ~(OTG_SYS_FORCESUSPEND |
516 OTG_SYS_SIDDQ_UOTG |
517 OTG_SYS_FORCESLEEP |
518 OTG_SYS_REFCLKSEL_MASK |
519 /* COMMON Block configuration during suspend */
520 OTG_SYS_COMMON_ON);
521
522 /* OTG phy & link reset */
523 phyotg |= (OTG_SYS_PHY0_SWRST |
524 OTG_SYS_LINKSWRST_UOTG |
525 OTG_SYS_PHYLINK_SWRESET |
526 OTG_SYS_OTGDISABLE |
527 /* Set phy refclk */
528 OTG_SYS_REFCLKSEL_CLKCORE);
529
530 writel(phyotg, regs + EXYNOS5_PHY_OTG_SYS);
531 udelay(10);
532 phyotg &= ~(OTG_SYS_PHY0_SWRST |
533 OTG_SYS_LINKSWRST_UOTG |
534 OTG_SYS_PHYLINK_SWRESET);
535 writel(phyotg, regs + EXYNOS5_PHY_OTG_SYS);
536
537 /* HSIC phy configuration */
538 phyhsic = (HSIC_CTRL_REFCLKDIV_12 |
539 HSIC_CTRL_REFCLKSEL |
540 HSIC_CTRL_PHYSWRST);
541 writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL1);
542 writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL2);
543 udelay(10);
544 phyhsic &= ~HSIC_CTRL_PHYSWRST;
545 writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL1);
546 writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL2);
547
548 udelay(80);
549
550 /* enable EHCI DMA burst */
551 ehcictrl = readl(regs + EXYNOS5_PHY_HOST_EHCICTRL);
552 ehcictrl |= (HOST_EHCICTRL_ENAINCRXALIGN |
553 HOST_EHCICTRL_ENAINCR4 |
554 HOST_EHCICTRL_ENAINCR8 |
555 HOST_EHCICTRL_ENAINCR16);
556 writel(ehcictrl, regs + EXYNOS5_PHY_HOST_EHCICTRL);
557
558 /* set ohci_suspend_on_n */
559 ohcictrl = readl(regs + EXYNOS5_PHY_HOST_OHCICTRL);
560 ohcictrl |= HOST_OHCICTRL_SUSPLGCY;
561 writel(ohcictrl, regs + EXYNOS5_PHY_HOST_OHCICTRL);
562}
563
564static void samsung_usbphy_enable(struct samsung_usbphy *sphy)
565{
566 void __iomem *regs = sphy->regs;
567 u32 phypwr;
568 u32 phyclk;
569 u32 rstcon;
570
571 /* set clock frequency for PLL */
572 phyclk = sphy->ref_clk_freq;
573 phypwr = readl(regs + SAMSUNG_PHYPWR);
574 rstcon = readl(regs + SAMSUNG_RSTCON);
575
576 switch (sphy->drv_data->cpu_type) {
577 case TYPE_S3C64XX:
578 phyclk &= ~PHYCLK_COMMON_ON_N;
579 phypwr &= ~PHYPWR_NORMAL_MASK;
580 rstcon |= RSTCON_SWRST;
581 break;
582 case TYPE_EXYNOS4210:
583 phypwr &= ~PHYPWR_NORMAL_MASK_PHY0;
584 rstcon |= RSTCON_SWRST;
585 default:
586 break;
587 }
588
589 writel(phyclk, regs + SAMSUNG_PHYCLK);
590 /* Configure PHY0 for normal operation*/
591 writel(phypwr, regs + SAMSUNG_PHYPWR);
592 /* reset all ports of PHY and Link */
593 writel(rstcon, regs + SAMSUNG_RSTCON);
594 udelay(10);
595 rstcon &= ~RSTCON_SWRST;
596 writel(rstcon, regs + SAMSUNG_RSTCON);
597}
598
599static void samsung_exynos5_usbphy_disable(struct samsung_usbphy *sphy)
600{
601 void __iomem *regs = sphy->regs;
602 u32 phyhost;
603 u32 phyotg;
604 u32 phyhsic;
605
606 if (atomic_dec_return(&sphy->phy_usage) > 0) {
607 dev_info(sphy->dev, "still being used\n");
608 return;
609 }
610
611 phyhsic = (HSIC_CTRL_REFCLKDIV_12 |
612 HSIC_CTRL_REFCLKSEL |
613 HSIC_CTRL_SIDDQ |
614 HSIC_CTRL_FORCESLEEP |
615 HSIC_CTRL_FORCESUSPEND);
616 writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL1);
617 writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL2);
618
619 phyhost = readl(regs + EXYNOS5_PHY_HOST_CTRL0);
620 phyhost |= (HOST_CTRL0_SIDDQ |
621 HOST_CTRL0_FORCESUSPEND |
622 HOST_CTRL0_FORCESLEEP |
623 HOST_CTRL0_PHYSWRST |
624 HOST_CTRL0_PHYSWRSTALL);
625 writel(phyhost, regs + EXYNOS5_PHY_HOST_CTRL0);
626
627 phyotg = readl(regs + EXYNOS5_PHY_OTG_SYS);
628 phyotg |= (OTG_SYS_FORCESUSPEND |
629 OTG_SYS_SIDDQ_UOTG |
630 OTG_SYS_FORCESLEEP);
631 writel(phyotg, regs + EXYNOS5_PHY_OTG_SYS);
632}
633
634static void samsung_usbphy_disable(struct samsung_usbphy *sphy)
635{
636 void __iomem *regs = sphy->regs;
637 u32 phypwr;
638
639 phypwr = readl(regs + SAMSUNG_PHYPWR);
640
641 switch (sphy->drv_data->cpu_type) {
642 case TYPE_S3C64XX:
643 phypwr |= PHYPWR_NORMAL_MASK;
644 break;
645 case TYPE_EXYNOS4210:
646 phypwr |= PHYPWR_NORMAL_MASK_PHY0;
647 default:
648 break;
649 }
650
651 /* Disable analog and otg block power */
652 writel(phypwr, regs + SAMSUNG_PHYPWR);
653}
654
655/*
656 * The function passed to the usb driver for phy initialization
657 */
658static int samsung_usbphy_init(struct usb_phy *phy)
659{
660 struct samsung_usbphy *sphy;
661 struct usb_bus *host = NULL;
662 unsigned long flags;
663 int ret = 0;
664
665 sphy = phy_to_sphy(phy);
666
667 host = phy->otg->host;
668
669 /* Enable the phy clock */
670 ret = clk_prepare_enable(sphy->clk);
671 if (ret) {
672 dev_err(sphy->dev, "%s: clk_prepare_enable failed\n", __func__);
673 return ret;
674 }
675
676 spin_lock_irqsave(&sphy->lock, flags);
677
678 if (host) {
679 /* setting default phy-type for USB 2.0 */
680 if (!strstr(dev_name(host->controller), "ehci") ||
681 !strstr(dev_name(host->controller), "ohci"))
682 samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_HOST);
683 } else {
684 samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_DEVICE);
685 }
686
687 /* Disable phy isolation */
688 if (sphy->plat && sphy->plat->pmu_isolation)
689 sphy->plat->pmu_isolation(false);
690 else
691 samsung_usbphy_set_isolation(sphy, false);
692
693 /* Selecting Host/OTG mode; After reset USB2.0PHY_CFG: HOST */
694 samsung_usbphy_cfg_sel(sphy);
695
696 /* Initialize usb phy registers */
697 if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250)
698 samsung_exynos5_usbphy_enable(sphy);
699 else
700 samsung_usbphy_enable(sphy);
701
702 spin_unlock_irqrestore(&sphy->lock, flags);
703
704 /* Disable the phy clock */
705 clk_disable_unprepare(sphy->clk);
706
707 return ret;
708}
709
710/*
711 * The function passed to the usb driver for phy shutdown
712 */
713static void samsung_usbphy_shutdown(struct usb_phy *phy)
714{
715 struct samsung_usbphy *sphy;
716 struct usb_bus *host = NULL;
717 unsigned long flags;
718
719 sphy = phy_to_sphy(phy);
720
721 host = phy->otg->host;
722
723 if (clk_prepare_enable(sphy->clk)) {
724 dev_err(sphy->dev, "%s: clk_prepare_enable failed\n", __func__);
725 return;
726 }
727
728 spin_lock_irqsave(&sphy->lock, flags);
729
730 if (host) {
731 /* setting default phy-type for USB 2.0 */
732 if (!strstr(dev_name(host->controller), "ehci") ||
733 !strstr(dev_name(host->controller), "ohci"))
734 samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_HOST);
735 } else {
736 samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_DEVICE);
737 }
738
739 /* De-initialize usb phy registers */
740 if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250)
741 samsung_exynos5_usbphy_disable(sphy);
742 else
743 samsung_usbphy_disable(sphy);
744
745 /* Enable phy isolation */
746 if (sphy->plat && sphy->plat->pmu_isolation)
747 sphy->plat->pmu_isolation(true);
748 else
749 samsung_usbphy_set_isolation(sphy, true);
750
751 spin_unlock_irqrestore(&sphy->lock, flags);
752
753 clk_disable_unprepare(sphy->clk);
754}
755
756static const struct of_device_id samsung_usbphy_dt_match[];
757
758static inline const struct samsung_usbphy_drvdata
759*samsung_usbphy_get_driver_data(struct platform_device *pdev)
760{
761 if (pdev->dev.of_node) {
762 const struct of_device_id *match;
763 match = of_match_node(samsung_usbphy_dt_match,
764 pdev->dev.of_node);
765 return match->data;
766 }
767
768 return (struct samsung_usbphy_drvdata *)
769 platform_get_device_id(pdev)->driver_data;
770}
771
772static int samsung_usbphy_probe(struct platform_device *pdev)
773{
774 struct samsung_usbphy *sphy;
775 struct usb_otg *otg;
776 struct samsung_usbphy_data *pdata = pdev->dev.platform_data;
777 const struct samsung_usbphy_drvdata *drv_data;
778 struct device *dev = &pdev->dev;
779 struct resource *phy_mem;
780 void __iomem *phy_base;
781 struct clk *clk;
782 int ret;
783
784 phy_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
785 if (!phy_mem) {
786 dev_err(dev, "%s: missing mem resource\n", __func__);
787 return -ENODEV;
788 }
789
790 phy_base = devm_ioremap_resource(dev, phy_mem);
791 if (IS_ERR(phy_base))
792 return PTR_ERR(phy_base);
793
794 sphy = devm_kzalloc(dev, sizeof(*sphy), GFP_KERNEL);
795 if (!sphy)
796 return -ENOMEM;
797
798 otg = devm_kzalloc(dev, sizeof(*otg), GFP_KERNEL);
799 if (!otg)
800 return -ENOMEM;
801
802 drv_data = samsung_usbphy_get_driver_data(pdev);
803
804 if (drv_data->cpu_type == TYPE_EXYNOS5250)
805 clk = devm_clk_get(dev, "usbhost");
806 else
807 clk = devm_clk_get(dev, "otg");
808
809 if (IS_ERR(clk)) {
810 dev_err(dev, "Failed to get otg clock\n");
811 return PTR_ERR(clk);
812 }
813
814 sphy->dev = dev;
815
816 if (dev->of_node) {
817 ret = samsung_usbphy_parse_dt(sphy);
818 if (ret < 0)
819 return ret;
820 } else {
821 if (!pdata) {
822 dev_err(dev, "no platform data specified\n");
823 return -EINVAL;
824 }
825 }
826
827 sphy->plat = pdata;
828 sphy->regs = phy_base;
829 sphy->clk = clk;
830 sphy->drv_data = drv_data;
831 sphy->phy.dev = sphy->dev;
832 sphy->phy.label = "samsung-usbphy";
833 sphy->phy.init = samsung_usbphy_init;
834 sphy->phy.shutdown = samsung_usbphy_shutdown;
835 sphy->ref_clk_freq = samsung_usbphy_get_refclk_freq(sphy);
836
837 sphy->phy.otg = otg;
838 sphy->phy.otg->phy = &sphy->phy;
839 sphy->phy.otg->set_host = samsung_usbphy_set_host;
840
841 spin_lock_init(&sphy->lock);
842
843 platform_set_drvdata(pdev, sphy);
844
845 return usb_add_phy(&sphy->phy, USB_PHY_TYPE_USB2);
846}
847
848static int samsung_usbphy_remove(struct platform_device *pdev)
849{
850 struct samsung_usbphy *sphy = platform_get_drvdata(pdev);
851
852 usb_remove_phy(&sphy->phy);
853
854 if (sphy->pmuregs)
855 iounmap(sphy->pmuregs);
856 if (sphy->sysreg)
857 iounmap(sphy->sysreg);
858
859 return 0;
860}
861
862static const struct samsung_usbphy_drvdata usbphy_s3c64xx = {
863 .cpu_type = TYPE_S3C64XX,
864 .devphy_en_mask = S3C64XX_USBPHY_ENABLE,
865};
866
867static const struct samsung_usbphy_drvdata usbphy_exynos4 = {
868 .cpu_type = TYPE_EXYNOS4210,
869 .devphy_en_mask = EXYNOS_USBPHY_ENABLE,
870 .hostphy_en_mask = EXYNOS_USBPHY_ENABLE,
871};
872
873static struct samsung_usbphy_drvdata usbphy_exynos5 = {
874 .cpu_type = TYPE_EXYNOS5250,
875 .hostphy_en_mask = EXYNOS_USBPHY_ENABLE,
876 .hostphy_reg_offset = EXYNOS_USBHOST_PHY_CTRL_OFFSET,
877};
878
879#ifdef CONFIG_OF
880static const struct of_device_id samsung_usbphy_dt_match[] = {
881 {
882 .compatible = "samsung,s3c64xx-usbphy",
883 .data = &usbphy_s3c64xx,
884 }, {
885 .compatible = "samsung,exynos4210-usbphy",
886 .data = &usbphy_exynos4,
887 }, {
888 .compatible = "samsung,exynos5250-usbphy",
889 .data = &usbphy_exynos5
890 },
891 {},
892};
893MODULE_DEVICE_TABLE(of, samsung_usbphy_dt_match);
894#endif
895
896static struct platform_device_id samsung_usbphy_driver_ids[] = {
897 {
898 .name = "s3c64xx-usbphy",
899 .driver_data = (unsigned long)&usbphy_s3c64xx,
900 }, {
901 .name = "exynos4210-usbphy",
902 .driver_data = (unsigned long)&usbphy_exynos4,
903 }, {
904 .name = "exynos5250-usbphy",
905 .driver_data = (unsigned long)&usbphy_exynos5,
906 },
907 {},
908};
909
910MODULE_DEVICE_TABLE(platform, samsung_usbphy_driver_ids);
911
912static struct platform_driver samsung_usbphy_driver = {
913 .probe = samsung_usbphy_probe,
914 .remove = samsung_usbphy_remove,
915 .id_table = samsung_usbphy_driver_ids,
916 .driver = {
917 .name = "samsung-usbphy",
918 .owner = THIS_MODULE,
919 .of_match_table = of_match_ptr(samsung_usbphy_dt_match),
920 },
921};
922
923module_platform_driver(samsung_usbphy_driver);
924
925MODULE_DESCRIPTION("Samsung USB phy controller");
926MODULE_AUTHOR("Praveen Paneri <p.paneri@samsung.com>");
927MODULE_LICENSE("GPL");
928MODULE_ALIAS("platform:samsung-usbphy");
diff --git a/drivers/usb/renesas_usbhs/fifo.c b/drivers/usb/renesas_usbhs/fifo.c
index 9538f0feafe2..45b94019aec8 100644
--- a/drivers/usb/renesas_usbhs/fifo.c
+++ b/drivers/usb/renesas_usbhs/fifo.c
@@ -32,7 +32,6 @@
32 */ 32 */
33void usbhs_pkt_init(struct usbhs_pkt *pkt) 33void usbhs_pkt_init(struct usbhs_pkt *pkt)
34{ 34{
35 pkt->dma = DMA_ADDR_INVALID;
36 INIT_LIST_HEAD(&pkt->node); 35 INIT_LIST_HEAD(&pkt->node);
37} 36}
38 37
diff --git a/drivers/usb/renesas_usbhs/fifo.h b/drivers/usb/renesas_usbhs/fifo.h
index c31731a843d1..a168a1760fce 100644
--- a/drivers/usb/renesas_usbhs/fifo.h
+++ b/drivers/usb/renesas_usbhs/fifo.h
@@ -23,8 +23,6 @@
23#include <asm/dma.h> 23#include <asm/dma.h>
24#include "pipe.h" 24#include "pipe.h"
25 25
26#define DMA_ADDR_INVALID (~(dma_addr_t)0)
27
28struct usbhs_fifo { 26struct usbhs_fifo {
29 char *name; 27 char *name;
30 u32 port; /* xFIFO */ 28 u32 port; /* xFIFO */
diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c b/drivers/usb/renesas_usbhs/mod_gadget.c
index 78fca978b2d0..ed4949faa70d 100644
--- a/drivers/usb/renesas_usbhs/mod_gadget.c
+++ b/drivers/usb/renesas_usbhs/mod_gadget.c
@@ -230,7 +230,7 @@ static int usbhsg_recip_handler_std_clear_endpoint(struct usbhs_priv *priv,
230 return 0; 230 return 0;
231} 231}
232 232
233struct usbhsg_recip_handle req_clear_feature = { 233static struct usbhsg_recip_handle req_clear_feature = {
234 .name = "clear feature", 234 .name = "clear feature",
235 .device = usbhsg_recip_handler_std_control_done, 235 .device = usbhsg_recip_handler_std_control_done,
236 .interface = usbhsg_recip_handler_std_control_done, 236 .interface = usbhsg_recip_handler_std_control_done,
@@ -271,7 +271,7 @@ static int usbhsg_recip_handler_std_set_endpoint(struct usbhs_priv *priv,
271 return 0; 271 return 0;
272} 272}
273 273
274struct usbhsg_recip_handle req_set_feature = { 274static struct usbhsg_recip_handle req_set_feature = {
275 .name = "set feature", 275 .name = "set feature",
276 .device = usbhsg_recip_handler_std_set_device, 276 .device = usbhsg_recip_handler_std_set_device,
277 .interface = usbhsg_recip_handler_std_control_done, 277 .interface = usbhsg_recip_handler_std_control_done,
@@ -372,7 +372,7 @@ static int usbhsg_recip_handler_std_get_endpoint(struct usbhs_priv *priv,
372 return 0; 372 return 0;
373} 373}
374 374
375struct usbhsg_recip_handle req_get_status = { 375static struct usbhsg_recip_handle req_get_status = {
376 .name = "get status", 376 .name = "get status",
377 .device = usbhsg_recip_handler_std_get_device, 377 .device = usbhsg_recip_handler_std_get_device,
378 .interface = usbhsg_recip_handler_std_get_interface, 378 .interface = usbhsg_recip_handler_std_get_interface,
@@ -845,7 +845,6 @@ static int usbhsg_gadget_start(struct usb_gadget *gadget,
845 845
846 /* first hook up the driver ... */ 846 /* first hook up the driver ... */
847 gpriv->driver = driver; 847 gpriv->driver = driver;
848 gpriv->gadget.dev.driver = &driver->driver;
849 848
850 return usbhsg_try_start(priv, USBHSG_STATUS_REGISTERD); 849 return usbhsg_try_start(priv, USBHSG_STATUS_REGISTERD);
851} 850}
@@ -861,7 +860,6 @@ static int usbhsg_gadget_stop(struct usb_gadget *gadget,
861 return -EINVAL; 860 return -EINVAL;
862 861
863 usbhsg_try_stop(priv, USBHSG_STATUS_REGISTERD); 862 usbhsg_try_stop(priv, USBHSG_STATUS_REGISTERD);
864 gpriv->gadget.dev.driver = NULL;
865 gpriv->driver = NULL; 863 gpriv->driver = NULL;
866 864
867 return 0; 865 return 0;
@@ -925,11 +923,6 @@ static int usbhsg_stop(struct usbhs_priv *priv)
925 return usbhsg_try_stop(priv, USBHSG_STATUS_STARTED); 923 return usbhsg_try_stop(priv, USBHSG_STATUS_STARTED);
926} 924}
927 925
928static void usbhs_mod_gadget_release(struct device *pdev)
929{
930 /* do nothing */
931}
932
933int usbhs_mod_gadget_probe(struct usbhs_priv *priv) 926int usbhs_mod_gadget_probe(struct usbhs_priv *priv)
934{ 927{
935 struct usbhsg_gpriv *gpriv; 928 struct usbhsg_gpriv *gpriv;
@@ -976,15 +969,10 @@ int usbhs_mod_gadget_probe(struct usbhs_priv *priv)
976 /* 969 /*
977 * init gadget 970 * init gadget
978 */ 971 */
979 dev_set_name(&gpriv->gadget.dev, "gadget");
980 gpriv->gadget.dev.parent = dev; 972 gpriv->gadget.dev.parent = dev;
981 gpriv->gadget.dev.release = usbhs_mod_gadget_release;
982 gpriv->gadget.name = "renesas_usbhs_udc"; 973 gpriv->gadget.name = "renesas_usbhs_udc";
983 gpriv->gadget.ops = &usbhsg_gadget_ops; 974 gpriv->gadget.ops = &usbhsg_gadget_ops;
984 gpriv->gadget.max_speed = USB_SPEED_HIGH; 975 gpriv->gadget.max_speed = USB_SPEED_HIGH;
985 ret = device_register(&gpriv->gadget.dev);
986 if (ret < 0)
987 goto err_add_udc;
988 976
989 INIT_LIST_HEAD(&gpriv->gadget.ep_list); 977 INIT_LIST_HEAD(&gpriv->gadget.ep_list);
990 978
@@ -1014,15 +1002,13 @@ int usbhs_mod_gadget_probe(struct usbhs_priv *priv)
1014 1002
1015 ret = usb_add_gadget_udc(dev, &gpriv->gadget); 1003 ret = usb_add_gadget_udc(dev, &gpriv->gadget);
1016 if (ret) 1004 if (ret)
1017 goto err_register; 1005 goto err_add_udc;
1018 1006
1019 1007
1020 dev_info(dev, "gadget probed\n"); 1008 dev_info(dev, "gadget probed\n");
1021 1009
1022 return 0; 1010 return 0;
1023 1011
1024err_register:
1025 device_unregister(&gpriv->gadget.dev);
1026err_add_udc: 1012err_add_udc:
1027 kfree(gpriv->uep); 1013 kfree(gpriv->uep);
1028 1014
@@ -1038,8 +1024,6 @@ void usbhs_mod_gadget_remove(struct usbhs_priv *priv)
1038 1024
1039 usb_del_gadget_udc(&gpriv->gadget); 1025 usb_del_gadget_udc(&gpriv->gadget);
1040 1026
1041 device_unregister(&gpriv->gadget.dev);
1042
1043 kfree(gpriv->uep); 1027 kfree(gpriv->uep);
1044 kfree(gpriv); 1028 kfree(gpriv);
1045} 1029}
diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c
index 4775f8209e55..3b16118cbf62 100644
--- a/drivers/usb/serial/ark3116.c
+++ b/drivers/usb/serial/ark3116.c
@@ -62,7 +62,6 @@ static int is_irda(struct usb_serial *serial)
62} 62}
63 63
64struct ark3116_private { 64struct ark3116_private {
65 struct async_icount icount;
66 int irda; /* 1 for irda device */ 65 int irda; /* 1 for irda device */
67 66
68 /* protects hw register updates */ 67 /* protects hw register updates */
@@ -341,18 +340,15 @@ static void ark3116_close(struct usb_serial_port *port)
341{ 340{
342 struct usb_serial *serial = port->serial; 341 struct usb_serial *serial = port->serial;
343 342
344 if (serial->dev) { 343 /* disable DMA */
345 /* disable DMA */ 344 ark3116_write_reg(serial, UART_FCR, 0);
346 ark3116_write_reg(serial, UART_FCR, 0);
347
348 /* deactivate interrupts */
349 ark3116_write_reg(serial, UART_IER, 0);
350 345
351 usb_serial_generic_close(port); 346 /* deactivate interrupts */
352 if (serial->num_interrupt_in) 347 ark3116_write_reg(serial, UART_IER, 0);
353 usb_kill_urb(port->interrupt_in_urb);
354 }
355 348
349 usb_serial_generic_close(port);
350 if (serial->num_interrupt_in)
351 usb_kill_urb(port->interrupt_in_urb);
356} 352}
357 353
358static int ark3116_open(struct tty_struct *tty, struct usb_serial_port *port) 354static int ark3116_open(struct tty_struct *tty, struct usb_serial_port *port)
@@ -405,31 +401,10 @@ err_out:
405 return result; 401 return result;
406} 402}
407 403
408static int ark3116_get_icount(struct tty_struct *tty,
409 struct serial_icounter_struct *icount)
410{
411 struct usb_serial_port *port = tty->driver_data;
412 struct ark3116_private *priv = usb_get_serial_port_data(port);
413 struct async_icount cnow = priv->icount;
414 icount->cts = cnow.cts;
415 icount->dsr = cnow.dsr;
416 icount->rng = cnow.rng;
417 icount->dcd = cnow.dcd;
418 icount->rx = cnow.rx;
419 icount->tx = cnow.tx;
420 icount->frame = cnow.frame;
421 icount->overrun = cnow.overrun;
422 icount->parity = cnow.parity;
423 icount->brk = cnow.brk;
424 icount->buf_overrun = cnow.buf_overrun;
425 return 0;
426}
427
428static int ark3116_ioctl(struct tty_struct *tty, 404static int ark3116_ioctl(struct tty_struct *tty,
429 unsigned int cmd, unsigned long arg) 405 unsigned int cmd, unsigned long arg)
430{ 406{
431 struct usb_serial_port *port = tty->driver_data; 407 struct usb_serial_port *port = tty->driver_data;
432 struct ark3116_private *priv = usb_get_serial_port_data(port);
433 struct serial_struct serstruct; 408 struct serial_struct serstruct;
434 void __user *user_arg = (void __user *)arg; 409 void __user *user_arg = (void __user *)arg;
435 410
@@ -451,33 +426,6 @@ static int ark3116_ioctl(struct tty_struct *tty,
451 if (copy_from_user(&serstruct, user_arg, sizeof(serstruct))) 426 if (copy_from_user(&serstruct, user_arg, sizeof(serstruct)))
452 return -EFAULT; 427 return -EFAULT;
453 return 0; 428 return 0;
454 case TIOCMIWAIT:
455 for (;;) {
456 struct async_icount prev = priv->icount;
457 interruptible_sleep_on(&port->delta_msr_wait);
458 /* see if a signal did it */
459 if (signal_pending(current))
460 return -ERESTARTSYS;
461
462 if (port->serial->disconnected)
463 return -EIO;
464
465 if ((prev.rng == priv->icount.rng) &&
466 (prev.dsr == priv->icount.dsr) &&
467 (prev.dcd == priv->icount.dcd) &&
468 (prev.cts == priv->icount.cts))
469 return -EIO;
470 if ((arg & TIOCM_RNG &&
471 (prev.rng != priv->icount.rng)) ||
472 (arg & TIOCM_DSR &&
473 (prev.dsr != priv->icount.dsr)) ||
474 (arg & TIOCM_CD &&
475 (prev.dcd != priv->icount.dcd)) ||
476 (arg & TIOCM_CTS &&
477 (prev.cts != priv->icount.cts)))
478 return 0;
479 }
480 break;
481 } 429 }
482 430
483 return -ENOIOCTLCMD; 431 return -ENOIOCTLCMD;
@@ -575,14 +523,14 @@ static void ark3116_update_msr(struct usb_serial_port *port, __u8 msr)
575 if (msr & UART_MSR_ANY_DELTA) { 523 if (msr & UART_MSR_ANY_DELTA) {
576 /* update input line counters */ 524 /* update input line counters */
577 if (msr & UART_MSR_DCTS) 525 if (msr & UART_MSR_DCTS)
578 priv->icount.cts++; 526 port->icount.cts++;
579 if (msr & UART_MSR_DDSR) 527 if (msr & UART_MSR_DDSR)
580 priv->icount.dsr++; 528 port->icount.dsr++;
581 if (msr & UART_MSR_DDCD) 529 if (msr & UART_MSR_DDCD)
582 priv->icount.dcd++; 530 port->icount.dcd++;
583 if (msr & UART_MSR_TERI) 531 if (msr & UART_MSR_TERI)
584 priv->icount.rng++; 532 port->icount.rng++;
585 wake_up_interruptible(&port->delta_msr_wait); 533 wake_up_interruptible(&port->port.delta_msr_wait);
586 } 534 }
587} 535}
588 536
@@ -598,13 +546,13 @@ static void ark3116_update_lsr(struct usb_serial_port *port, __u8 lsr)
598 546
599 if (lsr&UART_LSR_BRK_ERROR_BITS) { 547 if (lsr&UART_LSR_BRK_ERROR_BITS) {
600 if (lsr & UART_LSR_BI) 548 if (lsr & UART_LSR_BI)
601 priv->icount.brk++; 549 port->icount.brk++;
602 if (lsr & UART_LSR_FE) 550 if (lsr & UART_LSR_FE)
603 priv->icount.frame++; 551 port->icount.frame++;
604 if (lsr & UART_LSR_PE) 552 if (lsr & UART_LSR_PE)
605 priv->icount.parity++; 553 port->icount.parity++;
606 if (lsr & UART_LSR_OE) 554 if (lsr & UART_LSR_OE)
607 priv->icount.overrun++; 555 port->icount.overrun++;
608 } 556 }
609} 557}
610 558
@@ -722,7 +670,8 @@ static struct usb_serial_driver ark3116_device = {
722 .ioctl = ark3116_ioctl, 670 .ioctl = ark3116_ioctl,
723 .tiocmget = ark3116_tiocmget, 671 .tiocmget = ark3116_tiocmget,
724 .tiocmset = ark3116_tiocmset, 672 .tiocmset = ark3116_tiocmset,
725 .get_icount = ark3116_get_icount, 673 .tiocmiwait = usb_serial_generic_tiocmiwait,
674 .get_icount = usb_serial_generic_get_icount,
726 .open = ark3116_open, 675 .open = ark3116_open,
727 .close = ark3116_close, 676 .close = ark3116_close,
728 .break_ctl = ark3116_break_ctl, 677 .break_ctl = ark3116_break_ctl,
diff --git a/drivers/usb/serial/bus.c b/drivers/usb/serial/bus.c
index 37decb13d7eb..3c4db6d196c6 100644
--- a/drivers/usb/serial/bus.c
+++ b/drivers/usb/serial/bus.c
@@ -106,14 +106,15 @@ static int usb_serial_device_remove(struct device *dev)
106 /* make sure suspend/resume doesn't race against port_remove */ 106 /* make sure suspend/resume doesn't race against port_remove */
107 usb_autopm_get_interface(port->serial->interface); 107 usb_autopm_get_interface(port->serial->interface);
108 108
109 minor = port->number;
110 tty_unregister_device(usb_serial_tty_driver, minor);
111
109 device_remove_file(&port->dev, &dev_attr_port_number); 112 device_remove_file(&port->dev, &dev_attr_port_number);
110 113
111 driver = port->serial->type; 114 driver = port->serial->type;
112 if (driver->port_remove) 115 if (driver->port_remove)
113 retval = driver->port_remove(port); 116 retval = driver->port_remove(port);
114 117
115 minor = port->number;
116 tty_unregister_device(usb_serial_tty_driver, minor);
117 dev_info(dev, "%s converter now disconnected from ttyUSB%d\n", 118 dev_info(dev, "%s converter now disconnected from ttyUSB%d\n",
118 driver->description, minor); 119 driver->description, minor);
119 120
diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c
index 07d4650a32ab..c2a4171ab9cb 100644
--- a/drivers/usb/serial/ch341.c
+++ b/drivers/usb/serial/ch341.c
@@ -296,7 +296,6 @@ static void ch341_dtr_rts(struct usb_serial_port *port, int on)
296 priv->line_control &= ~(CH341_BIT_RTS | CH341_BIT_DTR); 296 priv->line_control &= ~(CH341_BIT_RTS | CH341_BIT_DTR);
297 spin_unlock_irqrestore(&priv->lock, flags); 297 spin_unlock_irqrestore(&priv->lock, flags);
298 ch341_set_handshake(port->serial->dev, priv->line_control); 298 ch341_set_handshake(port->serial->dev, priv->line_control);
299 wake_up_interruptible(&port->delta_msr_wait);
300} 299}
301 300
302static void ch341_close(struct usb_serial_port *port) 301static void ch341_close(struct usb_serial_port *port)
@@ -489,7 +488,7 @@ static void ch341_read_int_callback(struct urb *urb)
489 tty_kref_put(tty); 488 tty_kref_put(tty);
490 } 489 }
491 490
492 wake_up_interruptible(&port->delta_msr_wait); 491 wake_up_interruptible(&port->port.delta_msr_wait);
493 } 492 }
494 493
495exit: 494exit:
@@ -500,8 +499,9 @@ exit:
500 __func__, status); 499 __func__, status);
501} 500}
502 501
503static int wait_modem_info(struct usb_serial_port *port, unsigned int arg) 502static int ch341_tiocmiwait(struct tty_struct *tty, unsigned long arg)
504{ 503{
504 struct usb_serial_port *port = tty->driver_data;
505 struct ch341_private *priv = usb_get_serial_port_data(port); 505 struct ch341_private *priv = usb_get_serial_port_data(port);
506 unsigned long flags; 506 unsigned long flags;
507 u8 prevstatus; 507 u8 prevstatus;
@@ -515,7 +515,7 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
515 spin_unlock_irqrestore(&priv->lock, flags); 515 spin_unlock_irqrestore(&priv->lock, flags);
516 516
517 while (!multi_change) { 517 while (!multi_change) {
518 interruptible_sleep_on(&port->delta_msr_wait); 518 interruptible_sleep_on(&port->port.delta_msr_wait);
519 /* see if a signal did it */ 519 /* see if a signal did it */
520 if (signal_pending(current)) 520 if (signal_pending(current))
521 return -ERESTARTSYS; 521 return -ERESTARTSYS;
@@ -542,26 +542,6 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
542 return 0; 542 return 0;
543} 543}
544 544
545static int ch341_ioctl(struct tty_struct *tty,
546 unsigned int cmd, unsigned long arg)
547{
548 struct usb_serial_port *port = tty->driver_data;
549
550 dev_dbg(&port->dev, "%s (%d) cmd = 0x%04x\n", __func__, port->number, cmd);
551
552 switch (cmd) {
553 case TIOCMIWAIT:
554 dev_dbg(&port->dev, "%s (%d) TIOCMIWAIT\n", __func__, port->number);
555 return wait_modem_info(port, arg);
556
557 default:
558 dev_dbg(&port->dev, "%s not supported = 0x%04x\n", __func__, cmd);
559 break;
560 }
561
562 return -ENOIOCTLCMD;
563}
564
565static int ch341_tiocmget(struct tty_struct *tty) 545static int ch341_tiocmget(struct tty_struct *tty)
566{ 546{
567 struct usb_serial_port *port = tty->driver_data; 547 struct usb_serial_port *port = tty->driver_data;
@@ -611,11 +591,11 @@ static struct usb_serial_driver ch341_device = {
611 .dtr_rts = ch341_dtr_rts, 591 .dtr_rts = ch341_dtr_rts,
612 .carrier_raised = ch341_carrier_raised, 592 .carrier_raised = ch341_carrier_raised,
613 .close = ch341_close, 593 .close = ch341_close,
614 .ioctl = ch341_ioctl,
615 .set_termios = ch341_set_termios, 594 .set_termios = ch341_set_termios,
616 .break_ctl = ch341_break_ctl, 595 .break_ctl = ch341_break_ctl,
617 .tiocmget = ch341_tiocmget, 596 .tiocmget = ch341_tiocmget,
618 .tiocmset = ch341_tiocmset, 597 .tiocmset = ch341_tiocmset,
598 .tiocmiwait = ch341_tiocmiwait,
619 .read_int_callback = ch341_read_int_callback, 599 .read_int_callback = ch341_read_int_callback,
620 .port_probe = ch341_port_probe, 600 .port_probe = ch341_port_probe,
621 .port_remove = ch341_port_remove, 601 .port_remove = ch341_port_remove,
diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index 4747d1c328ff..2c659553c07c 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -462,11 +462,7 @@ static int cp210x_open(struct tty_struct *tty, struct usb_serial_port *port)
462static void cp210x_close(struct usb_serial_port *port) 462static void cp210x_close(struct usb_serial_port *port)
463{ 463{
464 usb_serial_generic_close(port); 464 usb_serial_generic_close(port);
465 465 cp210x_set_config_single(port, CP210X_IFC_ENABLE, UART_DISABLE);
466 mutex_lock(&port->serial->disc_mutex);
467 if (!port->serial->disconnected)
468 cp210x_set_config_single(port, CP210X_IFC_ENABLE, UART_DISABLE);
469 mutex_unlock(&port->serial->disc_mutex);
470} 466}
471 467
472/* 468/*
diff --git a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c
index 629bd2894506..781426230d69 100644
--- a/drivers/usb/serial/cyberjack.c
+++ b/drivers/usb/serial/cyberjack.c
@@ -51,7 +51,6 @@
51#define CYBERJACK_PRODUCT_ID 0x0100 51#define CYBERJACK_PRODUCT_ID 0x0100
52 52
53/* Function prototypes */ 53/* Function prototypes */
54static void cyberjack_disconnect(struct usb_serial *serial);
55static int cyberjack_port_probe(struct usb_serial_port *port); 54static int cyberjack_port_probe(struct usb_serial_port *port);
56static int cyberjack_port_remove(struct usb_serial_port *port); 55static int cyberjack_port_remove(struct usb_serial_port *port);
57static int cyberjack_open(struct tty_struct *tty, 56static int cyberjack_open(struct tty_struct *tty,
@@ -79,7 +78,6 @@ static struct usb_serial_driver cyberjack_device = {
79 .description = "Reiner SCT Cyberjack USB card reader", 78 .description = "Reiner SCT Cyberjack USB card reader",
80 .id_table = id_table, 79 .id_table = id_table,
81 .num_ports = 1, 80 .num_ports = 1,
82 .disconnect = cyberjack_disconnect,
83 .port_probe = cyberjack_port_probe, 81 .port_probe = cyberjack_port_probe,
84 .port_remove = cyberjack_port_remove, 82 .port_remove = cyberjack_port_remove,
85 .open = cyberjack_open, 83 .open = cyberjack_open,
@@ -130,20 +128,14 @@ static int cyberjack_port_remove(struct usb_serial_port *port)
130{ 128{
131 struct cyberjack_private *priv; 129 struct cyberjack_private *priv;
132 130
131 usb_kill_urb(port->interrupt_in_urb);
132
133 priv = usb_get_serial_port_data(port); 133 priv = usb_get_serial_port_data(port);
134 kfree(priv); 134 kfree(priv);
135 135
136 return 0; 136 return 0;
137} 137}
138 138
139static void cyberjack_disconnect(struct usb_serial *serial)
140{
141 int i;
142
143 for (i = 0; i < serial->num_ports; ++i)
144 usb_kill_urb(serial->port[i]->interrupt_in_urb);
145}
146
147static int cyberjack_open(struct tty_struct *tty, 139static int cyberjack_open(struct tty_struct *tty,
148 struct usb_serial_port *port) 140 struct usb_serial_port *port)
149{ 141{
@@ -166,11 +158,8 @@ static int cyberjack_open(struct tty_struct *tty,
166 158
167static void cyberjack_close(struct usb_serial_port *port) 159static void cyberjack_close(struct usb_serial_port *port)
168{ 160{
169 if (port->serial->dev) { 161 usb_kill_urb(port->write_urb);
170 /* shutdown any bulk reads that might be going on */ 162 usb_kill_urb(port->read_urb);
171 usb_kill_urb(port->write_urb);
172 usb_kill_urb(port->read_urb);
173 }
174} 163}
175 164
176static int cyberjack_write(struct tty_struct *tty, 165static int cyberjack_write(struct tty_struct *tty,
diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c
index ba7352e4187e..d341555d37d8 100644
--- a/drivers/usb/serial/cypress_m8.c
+++ b/drivers/usb/serial/cypress_m8.c
@@ -129,13 +129,12 @@ static int cypress_write(struct tty_struct *tty, struct usb_serial_port *port,
129 const unsigned char *buf, int count); 129 const unsigned char *buf, int count);
130static void cypress_send(struct usb_serial_port *port); 130static void cypress_send(struct usb_serial_port *port);
131static int cypress_write_room(struct tty_struct *tty); 131static int cypress_write_room(struct tty_struct *tty);
132static int cypress_ioctl(struct tty_struct *tty,
133 unsigned int cmd, unsigned long arg);
134static void cypress_set_termios(struct tty_struct *tty, 132static void cypress_set_termios(struct tty_struct *tty,
135 struct usb_serial_port *port, struct ktermios *old); 133 struct usb_serial_port *port, struct ktermios *old);
136static int cypress_tiocmget(struct tty_struct *tty); 134static int cypress_tiocmget(struct tty_struct *tty);
137static int cypress_tiocmset(struct tty_struct *tty, 135static int cypress_tiocmset(struct tty_struct *tty,
138 unsigned int set, unsigned int clear); 136 unsigned int set, unsigned int clear);
137static int cypress_tiocmiwait(struct tty_struct *tty, unsigned long arg);
139static int cypress_chars_in_buffer(struct tty_struct *tty); 138static int cypress_chars_in_buffer(struct tty_struct *tty);
140static void cypress_throttle(struct tty_struct *tty); 139static void cypress_throttle(struct tty_struct *tty);
141static void cypress_unthrottle(struct tty_struct *tty); 140static void cypress_unthrottle(struct tty_struct *tty);
@@ -158,10 +157,10 @@ static struct usb_serial_driver cypress_earthmate_device = {
158 .dtr_rts = cypress_dtr_rts, 157 .dtr_rts = cypress_dtr_rts,
159 .write = cypress_write, 158 .write = cypress_write,
160 .write_room = cypress_write_room, 159 .write_room = cypress_write_room,
161 .ioctl = cypress_ioctl,
162 .set_termios = cypress_set_termios, 160 .set_termios = cypress_set_termios,
163 .tiocmget = cypress_tiocmget, 161 .tiocmget = cypress_tiocmget,
164 .tiocmset = cypress_tiocmset, 162 .tiocmset = cypress_tiocmset,
163 .tiocmiwait = cypress_tiocmiwait,
165 .chars_in_buffer = cypress_chars_in_buffer, 164 .chars_in_buffer = cypress_chars_in_buffer,
166 .throttle = cypress_throttle, 165 .throttle = cypress_throttle,
167 .unthrottle = cypress_unthrottle, 166 .unthrottle = cypress_unthrottle,
@@ -184,10 +183,10 @@ static struct usb_serial_driver cypress_hidcom_device = {
184 .dtr_rts = cypress_dtr_rts, 183 .dtr_rts = cypress_dtr_rts,
185 .write = cypress_write, 184 .write = cypress_write,
186 .write_room = cypress_write_room, 185 .write_room = cypress_write_room,
187 .ioctl = cypress_ioctl,
188 .set_termios = cypress_set_termios, 186 .set_termios = cypress_set_termios,
189 .tiocmget = cypress_tiocmget, 187 .tiocmget = cypress_tiocmget,
190 .tiocmset = cypress_tiocmset, 188 .tiocmset = cypress_tiocmset,
189 .tiocmiwait = cypress_tiocmiwait,
191 .chars_in_buffer = cypress_chars_in_buffer, 190 .chars_in_buffer = cypress_chars_in_buffer,
192 .throttle = cypress_throttle, 191 .throttle = cypress_throttle,
193 .unthrottle = cypress_unthrottle, 192 .unthrottle = cypress_unthrottle,
@@ -210,10 +209,10 @@ static struct usb_serial_driver cypress_ca42v2_device = {
210 .dtr_rts = cypress_dtr_rts, 209 .dtr_rts = cypress_dtr_rts,
211 .write = cypress_write, 210 .write = cypress_write,
212 .write_room = cypress_write_room, 211 .write_room = cypress_write_room,
213 .ioctl = cypress_ioctl,
214 .set_termios = cypress_set_termios, 212 .set_termios = cypress_set_termios,
215 .tiocmget = cypress_tiocmget, 213 .tiocmget = cypress_tiocmget,
216 .tiocmset = cypress_tiocmset, 214 .tiocmset = cypress_tiocmset,
215 .tiocmiwait = cypress_tiocmiwait,
217 .chars_in_buffer = cypress_chars_in_buffer, 216 .chars_in_buffer = cypress_chars_in_buffer,
218 .throttle = cypress_throttle, 217 .throttle = cypress_throttle,
219 .unthrottle = cypress_unthrottle, 218 .unthrottle = cypress_unthrottle,
@@ -633,12 +632,6 @@ static void cypress_close(struct usb_serial_port *port)
633 struct cypress_private *priv = usb_get_serial_port_data(port); 632 struct cypress_private *priv = usb_get_serial_port_data(port);
634 unsigned long flags; 633 unsigned long flags;
635 634
636 /* writing is potentially harmful, lock must be taken */
637 mutex_lock(&port->serial->disc_mutex);
638 if (port->serial->disconnected) {
639 mutex_unlock(&port->serial->disc_mutex);
640 return;
641 }
642 spin_lock_irqsave(&priv->lock, flags); 635 spin_lock_irqsave(&priv->lock, flags);
643 kfifo_reset_out(&priv->write_fifo); 636 kfifo_reset_out(&priv->write_fifo);
644 spin_unlock_irqrestore(&priv->lock, flags); 637 spin_unlock_irqrestore(&priv->lock, flags);
@@ -650,7 +643,6 @@ static void cypress_close(struct usb_serial_port *port)
650 if (stats) 643 if (stats)
651 dev_info(&port->dev, "Statistics: %d Bytes In | %d Bytes Out | %d Commands Issued\n", 644 dev_info(&port->dev, "Statistics: %d Bytes In | %d Bytes Out | %d Commands Issued\n",
652 priv->bytes_in, priv->bytes_out, priv->cmd_count); 645 priv->bytes_in, priv->bytes_out, priv->cmd_count);
653 mutex_unlock(&port->serial->disc_mutex);
654} /* cypress_close */ 646} /* cypress_close */
655 647
656 648
@@ -855,55 +847,43 @@ static int cypress_tiocmset(struct tty_struct *tty,
855} 847}
856 848
857 849
858static int cypress_ioctl(struct tty_struct *tty, 850static int cypress_tiocmiwait(struct tty_struct *tty, unsigned long arg)
859 unsigned int cmd, unsigned long arg)
860{ 851{
861 struct usb_serial_port *port = tty->driver_data; 852 struct usb_serial_port *port = tty->driver_data;
862 struct cypress_private *priv = usb_get_serial_port_data(port); 853 struct cypress_private *priv = usb_get_serial_port_data(port);
863 854 char diff;
864 dev_dbg(&port->dev, "%s - port %d, cmd 0x%.4x\n", __func__, port->number, cmd); 855
865 856 for (;;) {
866 switch (cmd) { 857 interruptible_sleep_on(&port->port.delta_msr_wait);
867 /* This code comes from drivers/char/serial.c and ftdi_sio.c */ 858 /* see if a signal did it */
868 case TIOCMIWAIT: 859 if (signal_pending(current))
869 for (;;) { 860 return -ERESTARTSYS;
870 interruptible_sleep_on(&port->delta_msr_wait); 861
871 /* see if a signal did it */ 862 if (port->serial->disconnected)
872 if (signal_pending(current)) 863 return -EIO;
873 return -ERESTARTSYS; 864
874 865 diff = priv->diff_status;
875 if (port->serial->disconnected) 866 if (diff == 0)
876 return -EIO; 867 return -EIO; /* no change => error */
877 868
878 { 869 /* consume all events */
879 char diff = priv->diff_status; 870 priv->diff_status = 0;
880 if (diff == 0) 871
881 return -EIO; /* no change => error */ 872 /* return 0 if caller wanted to know about
882 873 these bits */
883 /* consume all events */ 874 if (((arg & TIOCM_RNG) && (diff & UART_RI)) ||
884 priv->diff_status = 0; 875 ((arg & TIOCM_DSR) && (diff & UART_DSR)) ||
885 876 ((arg & TIOCM_CD) && (diff & UART_CD)) ||
886 /* return 0 if caller wanted to know about 877 ((arg & TIOCM_CTS) && (diff & UART_CTS)))
887 these bits */ 878 return 0;
888 if (((arg & TIOCM_RNG) && (diff & UART_RI)) || 879 /* otherwise caller can't care less about what
889 ((arg & TIOCM_DSR) && (diff & UART_DSR)) || 880 * happened, and so we continue to wait for
890 ((arg & TIOCM_CD) && (diff & UART_CD)) || 881 * more events.
891 ((arg & TIOCM_CTS) && (diff & UART_CTS))) 882 */
892 return 0;
893 /* otherwise caller can't care less about what
894 * happened, and so we continue to wait for
895 * more events.
896 */
897 }
898 }
899 return 0;
900 default:
901 break;
902 } 883 }
903 dev_dbg(&port->dev, "%s - arg not supported - it was 0x%04x - check include/asm/ioctls.h\n", __func__, cmd);
904 return -ENOIOCTLCMD;
905} /* cypress_ioctl */
906 884
885 return 0;
886}
907 887
908static void cypress_set_termios(struct tty_struct *tty, 888static void cypress_set_termios(struct tty_struct *tty,
909 struct usb_serial_port *port, struct ktermios *old_termios) 889 struct usb_serial_port *port, struct ktermios *old_termios)
@@ -1189,7 +1169,7 @@ static void cypress_read_int_callback(struct urb *urb)
1189 if (priv->current_status != priv->prev_status) { 1169 if (priv->current_status != priv->prev_status) {
1190 priv->diff_status |= priv->current_status ^ 1170 priv->diff_status |= priv->current_status ^
1191 priv->prev_status; 1171 priv->prev_status;
1192 wake_up_interruptible(&port->delta_msr_wait); 1172 wake_up_interruptible(&port->port.delta_msr_wait);
1193 priv->prev_status = priv->current_status; 1173 priv->prev_status = priv->current_status;
1194 } 1174 }
1195 spin_unlock_irqrestore(&priv->lock, flags); 1175 spin_unlock_irqrestore(&priv->lock, flags);
diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c
index ebe45fa0ed50..32873b406402 100644
--- a/drivers/usb/serial/digi_acceleport.c
+++ b/drivers/usb/serial/digi_acceleport.c
@@ -196,7 +196,6 @@ struct digi_port {
196 unsigned char dp_out_buf[DIGI_OUT_BUF_SIZE]; 196 unsigned char dp_out_buf[DIGI_OUT_BUF_SIZE];
197 int dp_write_urb_in_use; 197 int dp_write_urb_in_use;
198 unsigned int dp_modem_signals; 198 unsigned int dp_modem_signals;
199 wait_queue_head_t dp_modem_change_wait;
200 int dp_transmit_idle; 199 int dp_transmit_idle;
201 wait_queue_head_t dp_transmit_idle_wait; 200 wait_queue_head_t dp_transmit_idle_wait;
202 int dp_throttled; 201 int dp_throttled;
@@ -1149,53 +1148,51 @@ static void digi_close(struct usb_serial_port *port)
1149 if (port->serial->disconnected) 1148 if (port->serial->disconnected)
1150 goto exit; 1149 goto exit;
1151 1150
1152 if (port->serial->dev) { 1151 /* FIXME: Transmit idle belongs in the wait_unti_sent path */
1153 /* FIXME: Transmit idle belongs in the wait_unti_sent path */ 1152 digi_transmit_idle(port, DIGI_CLOSE_TIMEOUT);
1154 digi_transmit_idle(port, DIGI_CLOSE_TIMEOUT); 1153
1155 1154 /* disable input flow control */
1156 /* disable input flow control */ 1155 buf[0] = DIGI_CMD_SET_INPUT_FLOW_CONTROL;
1157 buf[0] = DIGI_CMD_SET_INPUT_FLOW_CONTROL; 1156 buf[1] = priv->dp_port_num;
1158 buf[1] = priv->dp_port_num; 1157 buf[2] = DIGI_DISABLE;
1159 buf[2] = DIGI_DISABLE; 1158 buf[3] = 0;
1160 buf[3] = 0; 1159
1161 1160 /* disable output flow control */
1162 /* disable output flow control */ 1161 buf[4] = DIGI_CMD_SET_OUTPUT_FLOW_CONTROL;
1163 buf[4] = DIGI_CMD_SET_OUTPUT_FLOW_CONTROL; 1162 buf[5] = priv->dp_port_num;
1164 buf[5] = priv->dp_port_num; 1163 buf[6] = DIGI_DISABLE;
1165 buf[6] = DIGI_DISABLE; 1164 buf[7] = 0;
1166 buf[7] = 0; 1165
1167 1166 /* disable reading modem signals automatically */
1168 /* disable reading modem signals automatically */ 1167 buf[8] = DIGI_CMD_READ_INPUT_SIGNALS;
1169 buf[8] = DIGI_CMD_READ_INPUT_SIGNALS; 1168 buf[9] = priv->dp_port_num;
1170 buf[9] = priv->dp_port_num; 1169 buf[10] = DIGI_DISABLE;
1171 buf[10] = DIGI_DISABLE; 1170 buf[11] = 0;
1172 buf[11] = 0; 1171
1173 1172 /* disable receive */
1174 /* disable receive */ 1173 buf[12] = DIGI_CMD_RECEIVE_ENABLE;
1175 buf[12] = DIGI_CMD_RECEIVE_ENABLE; 1174 buf[13] = priv->dp_port_num;
1176 buf[13] = priv->dp_port_num; 1175 buf[14] = DIGI_DISABLE;
1177 buf[14] = DIGI_DISABLE; 1176 buf[15] = 0;
1178 buf[15] = 0; 1177
1179 1178 /* flush fifos */
1180 /* flush fifos */ 1179 buf[16] = DIGI_CMD_IFLUSH_FIFO;
1181 buf[16] = DIGI_CMD_IFLUSH_FIFO; 1180 buf[17] = priv->dp_port_num;
1182 buf[17] = priv->dp_port_num; 1181 buf[18] = DIGI_FLUSH_TX | DIGI_FLUSH_RX;
1183 buf[18] = DIGI_FLUSH_TX | DIGI_FLUSH_RX; 1182 buf[19] = 0;
1184 buf[19] = 0; 1183
1185 1184 ret = digi_write_oob_command(port, buf, 20, 0);
1186 ret = digi_write_oob_command(port, buf, 20, 0); 1185 if (ret != 0)
1187 if (ret != 0) 1186 dev_dbg(&port->dev, "digi_close: write oob failed, ret=%d\n",
1188 dev_dbg(&port->dev, "digi_close: write oob failed, ret=%d\n", ret); 1187 ret);
1189 1188 /* wait for final commands on oob port to complete */
1190 /* wait for final commands on oob port to complete */ 1189 prepare_to_wait(&priv->dp_flush_wait, &wait,
1191 prepare_to_wait(&priv->dp_flush_wait, &wait, 1190 TASK_INTERRUPTIBLE);
1192 TASK_INTERRUPTIBLE); 1191 schedule_timeout(DIGI_CLOSE_TIMEOUT);
1193 schedule_timeout(DIGI_CLOSE_TIMEOUT); 1192 finish_wait(&priv->dp_flush_wait, &wait);
1194 finish_wait(&priv->dp_flush_wait, &wait); 1193
1195 1194 /* shutdown any outstanding bulk writes */
1196 /* shutdown any outstanding bulk writes */ 1195 usb_kill_urb(port->write_urb);
1197 usb_kill_urb(port->write_urb);
1198 }
1199exit: 1196exit:
1200 spin_lock_irq(&priv->dp_port_lock); 1197 spin_lock_irq(&priv->dp_port_lock);
1201 priv->dp_write_urb_in_use = 0; 1198 priv->dp_write_urb_in_use = 0;
@@ -1252,7 +1249,6 @@ static int digi_port_init(struct usb_serial_port *port, unsigned port_num)
1252 1249
1253 spin_lock_init(&priv->dp_port_lock); 1250 spin_lock_init(&priv->dp_port_lock);
1254 priv->dp_port_num = port_num; 1251 priv->dp_port_num = port_num;
1255 init_waitqueue_head(&priv->dp_modem_change_wait);
1256 init_waitqueue_head(&priv->dp_transmit_idle_wait); 1252 init_waitqueue_head(&priv->dp_transmit_idle_wait);
1257 init_waitqueue_head(&priv->dp_flush_wait); 1253 init_waitqueue_head(&priv->dp_flush_wait);
1258 init_waitqueue_head(&priv->dp_close_wait); 1254 init_waitqueue_head(&priv->dp_close_wait);
@@ -1543,7 +1539,6 @@ static int digi_read_oob_callback(struct urb *urb)
1543 else 1539 else
1544 priv->dp_modem_signals &= ~TIOCM_CD; 1540 priv->dp_modem_signals &= ~TIOCM_CD;
1545 1541
1546 wake_up_interruptible(&priv->dp_modem_change_wait);
1547 spin_unlock(&priv->dp_port_lock); 1542 spin_unlock(&priv->dp_port_lock);
1548 } else if (opcode == DIGI_CMD_TRANSMIT_IDLE) { 1543 } else if (opcode == DIGI_CMD_TRANSMIT_IDLE) {
1549 spin_lock(&priv->dp_port_lock); 1544 spin_lock(&priv->dp_port_lock);
diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c
index a172ad5c5ce8..090b411d893f 100644
--- a/drivers/usb/serial/f81232.c
+++ b/drivers/usb/serial/f81232.c
@@ -110,7 +110,7 @@ static void f81232_process_read_urb(struct urb *urb)
110 line_status = priv->line_status; 110 line_status = priv->line_status;
111 priv->line_status &= ~UART_STATE_TRANSIENT_MASK; 111 priv->line_status &= ~UART_STATE_TRANSIENT_MASK;
112 spin_unlock_irqrestore(&priv->lock, flags); 112 spin_unlock_irqrestore(&priv->lock, flags);
113 wake_up_interruptible(&port->delta_msr_wait); 113 wake_up_interruptible(&port->port.delta_msr_wait);
114 114
115 if (!urb->actual_length) 115 if (!urb->actual_length)
116 return; 116 return;
@@ -242,8 +242,9 @@ static int f81232_carrier_raised(struct usb_serial_port *port)
242 return 0; 242 return 0;
243} 243}
244 244
245static int wait_modem_info(struct usb_serial_port *port, unsigned int arg) 245static int f81232_tiocmiwait(struct tty_struct *tty, unsigned long arg)
246{ 246{
247 struct usb_serial_port *port = tty->driver_data;
247 struct f81232_private *priv = usb_get_serial_port_data(port); 248 struct f81232_private *priv = usb_get_serial_port_data(port);
248 unsigned long flags; 249 unsigned long flags;
249 unsigned int prevstatus; 250 unsigned int prevstatus;
@@ -255,7 +256,7 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
255 spin_unlock_irqrestore(&priv->lock, flags); 256 spin_unlock_irqrestore(&priv->lock, flags);
256 257
257 while (1) { 258 while (1) {
258 interruptible_sleep_on(&port->delta_msr_wait); 259 interruptible_sleep_on(&port->port.delta_msr_wait);
259 /* see if a signal did it */ 260 /* see if a signal did it */
260 if (signal_pending(current)) 261 if (signal_pending(current))
261 return -ERESTARTSYS; 262 return -ERESTARTSYS;
@@ -302,11 +303,6 @@ static int f81232_ioctl(struct tty_struct *tty,
302 return -EFAULT; 303 return -EFAULT;
303 304
304 return 0; 305 return 0;
305
306 case TIOCMIWAIT:
307 dev_dbg(&port->dev, "%s (%d) TIOCMIWAIT\n", __func__,
308 port->number);
309 return wait_modem_info(port, arg);
310 default: 306 default:
311 dev_dbg(&port->dev, "%s not supported = 0x%04x\n", 307 dev_dbg(&port->dev, "%s not supported = 0x%04x\n",
312 __func__, cmd); 308 __func__, cmd);
@@ -358,6 +354,7 @@ static struct usb_serial_driver f81232_device = {
358 .set_termios = f81232_set_termios, 354 .set_termios = f81232_set_termios,
359 .tiocmget = f81232_tiocmget, 355 .tiocmget = f81232_tiocmget,
360 .tiocmset = f81232_tiocmset, 356 .tiocmset = f81232_tiocmset,
357 .tiocmiwait = f81232_tiocmiwait,
361 .process_read_urb = f81232_process_read_urb, 358 .process_read_urb = f81232_process_read_urb,
362 .read_int_callback = f81232_read_int_callback, 359 .read_int_callback = f81232_read_int_callback,
363 .port_probe = f81232_port_probe, 360 .port_probe = f81232_port_probe,
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 9886180e45f1..778c54dd3dff 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * USB FTDI SIO driver 2 * USB FTDI SIO driver
3 * 3 *
4 * Copyright (C) 2009 - 2010 4 * Copyright (C) 2009 - 2013
5 * Johan Hovold (jhovold@gmail.com) 5 * Johan Hovold (jhovold@gmail.com)
6 * Copyright (C) 1999 - 2001 6 * Copyright (C) 1999 - 2001
7 * Greg Kroah-Hartman (greg@kroah.com) 7 * Greg Kroah-Hartman (greg@kroah.com)
@@ -55,7 +55,6 @@ static __u16 vendor = FTDI_VID;
55static __u16 product; 55static __u16 product;
56 56
57struct ftdi_private { 57struct ftdi_private {
58 struct kref kref;
59 enum ftdi_chip_type chip_type; 58 enum ftdi_chip_type chip_type;
60 /* type of device, either SIO or FT8U232AM */ 59 /* type of device, either SIO or FT8U232AM */
61 int baud_base; /* baud base clock for divisor setting */ 60 int baud_base; /* baud base clock for divisor setting */
@@ -68,7 +67,6 @@ struct ftdi_private {
68 */ 67 */
69 int flags; /* some ASYNC_xxxx flags are supported */ 68 int flags; /* some ASYNC_xxxx flags are supported */
70 unsigned long last_dtr_rts; /* saved modem control outputs */ 69 unsigned long last_dtr_rts; /* saved modem control outputs */
71 struct async_icount icount;
72 char prev_status; /* Used for TIOCMIWAIT */ 70 char prev_status; /* Used for TIOCMIWAIT */
73 char transmit_empty; /* If transmitter is empty or not */ 71 char transmit_empty; /* If transmitter is empty or not */
74 __u16 interface; /* FT2232C, FT2232H or FT4232H port interface 72 __u16 interface; /* FT2232C, FT2232H or FT4232H port interface
@@ -911,7 +909,6 @@ static int ftdi_sio_probe(struct usb_serial *serial,
911static int ftdi_sio_port_probe(struct usb_serial_port *port); 909static int ftdi_sio_port_probe(struct usb_serial_port *port);
912static int ftdi_sio_port_remove(struct usb_serial_port *port); 910static int ftdi_sio_port_remove(struct usb_serial_port *port);
913static int ftdi_open(struct tty_struct *tty, struct usb_serial_port *port); 911static int ftdi_open(struct tty_struct *tty, struct usb_serial_port *port);
914static void ftdi_close(struct usb_serial_port *port);
915static void ftdi_dtr_rts(struct usb_serial_port *port, int on); 912static void ftdi_dtr_rts(struct usb_serial_port *port, int on);
916static void ftdi_process_read_urb(struct urb *urb); 913static void ftdi_process_read_urb(struct urb *urb);
917static int ftdi_prepare_write_buffer(struct usb_serial_port *port, 914static int ftdi_prepare_write_buffer(struct usb_serial_port *port,
@@ -921,8 +918,6 @@ static void ftdi_set_termios(struct tty_struct *tty,
921static int ftdi_tiocmget(struct tty_struct *tty); 918static int ftdi_tiocmget(struct tty_struct *tty);
922static int ftdi_tiocmset(struct tty_struct *tty, 919static int ftdi_tiocmset(struct tty_struct *tty,
923 unsigned int set, unsigned int clear); 920 unsigned int set, unsigned int clear);
924static int ftdi_get_icount(struct tty_struct *tty,
925 struct serial_icounter_struct *icount);
926static int ftdi_ioctl(struct tty_struct *tty, 921static int ftdi_ioctl(struct tty_struct *tty,
927 unsigned int cmd, unsigned long arg); 922 unsigned int cmd, unsigned long arg);
928static void ftdi_break_ctl(struct tty_struct *tty, int break_state); 923static void ftdi_break_ctl(struct tty_struct *tty, int break_state);
@@ -951,7 +946,6 @@ static struct usb_serial_driver ftdi_sio_device = {
951 .port_probe = ftdi_sio_port_probe, 946 .port_probe = ftdi_sio_port_probe,
952 .port_remove = ftdi_sio_port_remove, 947 .port_remove = ftdi_sio_port_remove,
953 .open = ftdi_open, 948 .open = ftdi_open,
954 .close = ftdi_close,
955 .dtr_rts = ftdi_dtr_rts, 949 .dtr_rts = ftdi_dtr_rts,
956 .throttle = usb_serial_generic_throttle, 950 .throttle = usb_serial_generic_throttle,
957 .unthrottle = usb_serial_generic_unthrottle, 951 .unthrottle = usb_serial_generic_unthrottle,
@@ -959,7 +953,8 @@ static struct usb_serial_driver ftdi_sio_device = {
959 .prepare_write_buffer = ftdi_prepare_write_buffer, 953 .prepare_write_buffer = ftdi_prepare_write_buffer,
960 .tiocmget = ftdi_tiocmget, 954 .tiocmget = ftdi_tiocmget,
961 .tiocmset = ftdi_tiocmset, 955 .tiocmset = ftdi_tiocmset,
962 .get_icount = ftdi_get_icount, 956 .tiocmiwait = usb_serial_generic_tiocmiwait,
957 .get_icount = usb_serial_generic_get_icount,
963 .ioctl = ftdi_ioctl, 958 .ioctl = ftdi_ioctl,
964 .set_termios = ftdi_set_termios, 959 .set_termios = ftdi_set_termios,
965 .break_ctl = ftdi_break_ctl, 960 .break_ctl = ftdi_break_ctl,
@@ -1688,7 +1683,6 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port)
1688 return -ENOMEM; 1683 return -ENOMEM;
1689 } 1684 }
1690 1685
1691 kref_init(&priv->kref);
1692 mutex_init(&priv->cfg_lock); 1686 mutex_init(&priv->cfg_lock);
1693 1687
1694 priv->flags = ASYNC_LOW_LATENCY; 1688 priv->flags = ASYNC_LOW_LATENCY;
@@ -1826,22 +1820,13 @@ static int ftdi_mtxorb_hack_setup(struct usb_serial *serial)
1826 return 0; 1820 return 0;
1827} 1821}
1828 1822
1829static void ftdi_sio_priv_release(struct kref *k)
1830{
1831 struct ftdi_private *priv = container_of(k, struct ftdi_private, kref);
1832
1833 kfree(priv);
1834}
1835
1836static int ftdi_sio_port_remove(struct usb_serial_port *port) 1823static int ftdi_sio_port_remove(struct usb_serial_port *port)
1837{ 1824{
1838 struct ftdi_private *priv = usb_get_serial_port_data(port); 1825 struct ftdi_private *priv = usb_get_serial_port_data(port);
1839 1826
1840 wake_up_interruptible(&port->delta_msr_wait);
1841
1842 remove_sysfs_attrs(port); 1827 remove_sysfs_attrs(port);
1843 1828
1844 kref_put(&priv->kref, ftdi_sio_priv_release); 1829 kfree(priv);
1845 1830
1846 return 0; 1831 return 0;
1847} 1832}
@@ -1851,7 +1836,6 @@ static int ftdi_open(struct tty_struct *tty, struct usb_serial_port *port)
1851 struct ktermios dummy; 1836 struct ktermios dummy;
1852 struct usb_device *dev = port->serial->dev; 1837 struct usb_device *dev = port->serial->dev;
1853 struct ftdi_private *priv = usb_get_serial_port_data(port); 1838 struct ftdi_private *priv = usb_get_serial_port_data(port);
1854 int result;
1855 1839
1856 /* No error checking for this (will get errors later anyway) */ 1840 /* No error checking for this (will get errors later anyway) */
1857 /* See ftdi_sio.h for description of what is reset */ 1841 /* See ftdi_sio.h for description of what is reset */
@@ -1870,12 +1854,7 @@ static int ftdi_open(struct tty_struct *tty, struct usb_serial_port *port)
1870 ftdi_set_termios(tty, port, &dummy); 1854 ftdi_set_termios(tty, port, &dummy);
1871 } 1855 }
1872 1856
1873 /* Start reading from the device */ 1857 return usb_serial_generic_open(tty, port);
1874 result = usb_serial_generic_open(tty, port);
1875 if (!result)
1876 kref_get(&priv->kref);
1877
1878 return result;
1879} 1858}
1880 1859
1881static void ftdi_dtr_rts(struct usb_serial_port *port, int on) 1860static void ftdi_dtr_rts(struct usb_serial_port *port, int on)
@@ -1900,19 +1879,6 @@ static void ftdi_dtr_rts(struct usb_serial_port *port, int on)
1900 clear_mctrl(port, TIOCM_DTR | TIOCM_RTS); 1879 clear_mctrl(port, TIOCM_DTR | TIOCM_RTS);
1901} 1880}
1902 1881
1903/*
1904 * usbserial:__serial_close only calls ftdi_close if the point is open
1905 *
1906 * This only gets called when it is the last close
1907 */
1908static void ftdi_close(struct usb_serial_port *port)
1909{
1910 struct ftdi_private *priv = usb_get_serial_port_data(port);
1911
1912 usb_serial_generic_close(port);
1913 kref_put(&priv->kref, ftdi_sio_priv_release);
1914}
1915
1916/* The SIO requires the first byte to have: 1882/* The SIO requires the first byte to have:
1917 * B0 1 1883 * B0 1
1918 * B1 0 1884 * B1 0
@@ -1940,7 +1906,7 @@ static int ftdi_prepare_write_buffer(struct usb_serial_port *port,
1940 c = kfifo_out(&port->write_fifo, &buffer[i + 1], len); 1906 c = kfifo_out(&port->write_fifo, &buffer[i + 1], len);
1941 if (!c) 1907 if (!c)
1942 break; 1908 break;
1943 priv->icount.tx += c; 1909 port->icount.tx += c;
1944 buffer[i] = (c << 2) + 1; 1910 buffer[i] = (c << 2) + 1;
1945 count += c + 1; 1911 count += c + 1;
1946 } 1912 }
@@ -1948,7 +1914,7 @@ static int ftdi_prepare_write_buffer(struct usb_serial_port *port,
1948 } else { 1914 } else {
1949 count = kfifo_out_locked(&port->write_fifo, dest, size, 1915 count = kfifo_out_locked(&port->write_fifo, dest, size,
1950 &port->lock); 1916 &port->lock);
1951 priv->icount.tx += count; 1917 port->icount.tx += count;
1952 } 1918 }
1953 1919
1954 return count; 1920 return count;
@@ -1977,15 +1943,15 @@ static int ftdi_process_packet(struct usb_serial_port *port,
1977 char diff_status = status ^ priv->prev_status; 1943 char diff_status = status ^ priv->prev_status;
1978 1944
1979 if (diff_status & FTDI_RS0_CTS) 1945 if (diff_status & FTDI_RS0_CTS)
1980 priv->icount.cts++; 1946 port->icount.cts++;
1981 if (diff_status & FTDI_RS0_DSR) 1947 if (diff_status & FTDI_RS0_DSR)
1982 priv->icount.dsr++; 1948 port->icount.dsr++;
1983 if (diff_status & FTDI_RS0_RI) 1949 if (diff_status & FTDI_RS0_RI)
1984 priv->icount.rng++; 1950 port->icount.rng++;
1985 if (diff_status & FTDI_RS0_RLSD) 1951 if (diff_status & FTDI_RS0_RLSD)
1986 priv->icount.dcd++; 1952 port->icount.dcd++;
1987 1953
1988 wake_up_interruptible(&port->delta_msr_wait); 1954 wake_up_interruptible(&port->port.delta_msr_wait);
1989 priv->prev_status = status; 1955 priv->prev_status = status;
1990 } 1956 }
1991 1957
@@ -1995,18 +1961,18 @@ static int ftdi_process_packet(struct usb_serial_port *port,
1995 * over framing errors */ 1961 * over framing errors */
1996 if (packet[1] & FTDI_RS_BI) { 1962 if (packet[1] & FTDI_RS_BI) {
1997 flag = TTY_BREAK; 1963 flag = TTY_BREAK;
1998 priv->icount.brk++; 1964 port->icount.brk++;
1999 usb_serial_handle_break(port); 1965 usb_serial_handle_break(port);
2000 } else if (packet[1] & FTDI_RS_PE) { 1966 } else if (packet[1] & FTDI_RS_PE) {
2001 flag = TTY_PARITY; 1967 flag = TTY_PARITY;
2002 priv->icount.parity++; 1968 port->icount.parity++;
2003 } else if (packet[1] & FTDI_RS_FE) { 1969 } else if (packet[1] & FTDI_RS_FE) {
2004 flag = TTY_FRAME; 1970 flag = TTY_FRAME;
2005 priv->icount.frame++; 1971 port->icount.frame++;
2006 } 1972 }
2007 /* Overrun is special, not associated with a char */ 1973 /* Overrun is special, not associated with a char */
2008 if (packet[1] & FTDI_RS_OE) { 1974 if (packet[1] & FTDI_RS_OE) {
2009 priv->icount.overrun++; 1975 port->icount.overrun++;
2010 tty_insert_flip_char(&port->port, 0, TTY_OVERRUN); 1976 tty_insert_flip_char(&port->port, 0, TTY_OVERRUN);
2011 } 1977 }
2012 } 1978 }
@@ -2020,7 +1986,7 @@ static int ftdi_process_packet(struct usb_serial_port *port,
2020 len -= 2; 1986 len -= 2;
2021 if (!len) 1987 if (!len)
2022 return 0; /* status only */ 1988 return 0; /* status only */
2023 priv->icount.rx += len; 1989 port->icount.rx += len;
2024 ch = packet + 2; 1990 ch = packet + 2;
2025 1991
2026 if (port->port.console && port->sysrq) { 1992 if (port->port.console && port->sysrq) {
@@ -2384,34 +2350,10 @@ static int ftdi_tiocmset(struct tty_struct *tty,
2384 return update_mctrl(port, set, clear); 2350 return update_mctrl(port, set, clear);
2385} 2351}
2386 2352
2387static int ftdi_get_icount(struct tty_struct *tty,
2388 struct serial_icounter_struct *icount)
2389{
2390 struct usb_serial_port *port = tty->driver_data;
2391 struct ftdi_private *priv = usb_get_serial_port_data(port);
2392 struct async_icount *ic = &priv->icount;
2393
2394 icount->cts = ic->cts;
2395 icount->dsr = ic->dsr;
2396 icount->rng = ic->rng;
2397 icount->dcd = ic->dcd;
2398 icount->tx = ic->tx;
2399 icount->rx = ic->rx;
2400 icount->frame = ic->frame;
2401 icount->parity = ic->parity;
2402 icount->overrun = ic->overrun;
2403 icount->brk = ic->brk;
2404 icount->buf_overrun = ic->buf_overrun;
2405 return 0;
2406}
2407
2408static int ftdi_ioctl(struct tty_struct *tty, 2353static int ftdi_ioctl(struct tty_struct *tty,
2409 unsigned int cmd, unsigned long arg) 2354 unsigned int cmd, unsigned long arg)
2410{ 2355{
2411 struct usb_serial_port *port = tty->driver_data; 2356 struct usb_serial_port *port = tty->driver_data;
2412 struct ftdi_private *priv = usb_get_serial_port_data(port);
2413 struct async_icount cnow;
2414 struct async_icount cprev;
2415 2357
2416 dev_dbg(&port->dev, "%s cmd 0x%04x\n", __func__, cmd); 2358 dev_dbg(&port->dev, "%s cmd 0x%04x\n", __func__, cmd);
2417 2359
@@ -2425,35 +2367,6 @@ static int ftdi_ioctl(struct tty_struct *tty,
2425 case TIOCSSERIAL: /* sets serial port data */ 2367 case TIOCSSERIAL: /* sets serial port data */
2426 return set_serial_info(tty, port, 2368 return set_serial_info(tty, port,
2427 (struct serial_struct __user *) arg); 2369 (struct serial_struct __user *) arg);
2428
2429 /*
2430 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
2431 * - mask passed in arg for lines of interest
2432 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
2433 * Caller should use TIOCGICOUNT to see which one it was.
2434 *
2435 * This code is borrowed from linux/drivers/char/serial.c
2436 */
2437 case TIOCMIWAIT:
2438 cprev = priv->icount;
2439 for (;;) {
2440 interruptible_sleep_on(&port->delta_msr_wait);
2441 /* see if a signal did it */
2442 if (signal_pending(current))
2443 return -ERESTARTSYS;
2444
2445 if (port->serial->disconnected)
2446 return -EIO;
2447
2448 cnow = priv->icount;
2449 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
2450 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
2451 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
2452 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
2453 return 0;
2454 }
2455 cprev = cnow;
2456 }
2457 case TIOCSERGETLSR: 2370 case TIOCSERGETLSR:
2458 return get_lsr_info(port, (struct serial_struct __user *)arg); 2371 return get_lsr_info(port, (struct serial_struct __user *)arg);
2459 break; 2372 break;
diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c
index 81caf5623ee2..b110c573ea85 100644
--- a/drivers/usb/serial/garmin_gps.c
+++ b/drivers/usb/serial/garmin_gps.c
@@ -946,16 +946,12 @@ static int garmin_open(struct tty_struct *tty, struct usb_serial_port *port)
946 946
947static void garmin_close(struct usb_serial_port *port) 947static void garmin_close(struct usb_serial_port *port)
948{ 948{
949 struct usb_serial *serial = port->serial;
950 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); 949 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
951 950
952 dev_dbg(&port->dev, "%s - port %d - mode=%d state=%d flags=0x%X\n", 951 dev_dbg(&port->dev, "%s - port %d - mode=%d state=%d flags=0x%X\n",
953 __func__, port->number, garmin_data_p->mode, 952 __func__, port->number, garmin_data_p->mode,
954 garmin_data_p->state, garmin_data_p->flags); 953 garmin_data_p->state, garmin_data_p->flags);
955 954
956 if (!serial)
957 return;
958
959 garmin_clear(garmin_data_p); 955 garmin_clear(garmin_data_p);
960 956
961 /* shutdown our urbs */ 957 /* shutdown our urbs */
@@ -1185,17 +1181,11 @@ static void garmin_read_bulk_callback(struct urb *urb)
1185{ 1181{
1186 unsigned long flags; 1182 unsigned long flags;
1187 struct usb_serial_port *port = urb->context; 1183 struct usb_serial_port *port = urb->context;
1188 struct usb_serial *serial = port->serial;
1189 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); 1184 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1190 unsigned char *data = urb->transfer_buffer; 1185 unsigned char *data = urb->transfer_buffer;
1191 int status = urb->status; 1186 int status = urb->status;
1192 int retval; 1187 int retval;
1193 1188
1194 if (!serial) {
1195 dev_dbg(&urb->dev->dev, "%s - bad serial pointer, exiting\n", __func__);
1196 return;
1197 }
1198
1199 if (status) { 1189 if (status) {
1200 dev_dbg(&urb->dev->dev, "%s - nonzero read bulk status received: %d\n", 1190 dev_dbg(&urb->dev->dev, "%s - nonzero read bulk status received: %d\n",
1201 __func__, status); 1191 __func__, status);
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index 4c5c23f1cae5..297665fdd16d 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * USB Serial Converter Generic functions 2 * USB Serial Converter Generic functions
3 * 3 *
4 * Copyright (C) 2010 - 2011 Johan Hovold (jhovold@gmail.com) 4 * Copyright (C) 2010 - 2013 Johan Hovold (jhovold@gmail.com)
5 * Copyright (C) 1999 - 2002 Greg Kroah-Hartman (greg@kroah.com) 5 * Copyright (C) 1999 - 2002 Greg Kroah-Hartman (greg@kroah.com)
6 * 6 *
7 * This program is free software; you can redistribute it and/or 7 * This program is free software; you can redistribute it and/or
@@ -45,8 +45,6 @@ struct usb_serial_driver usb_serial_generic_device = {
45 }, 45 },
46 .id_table = generic_device_ids, 46 .id_table = generic_device_ids,
47 .num_ports = 1, 47 .num_ports = 1,
48 .disconnect = usb_serial_generic_disconnect,
49 .release = usb_serial_generic_release,
50 .throttle = usb_serial_generic_throttle, 48 .throttle = usb_serial_generic_throttle,
51 .unthrottle = usb_serial_generic_unthrottle, 49 .unthrottle = usb_serial_generic_unthrottle,
52 .resume = usb_serial_generic_resume, 50 .resume = usb_serial_generic_resume,
@@ -102,32 +100,23 @@ int usb_serial_generic_open(struct tty_struct *tty, struct usb_serial_port *port
102} 100}
103EXPORT_SYMBOL_GPL(usb_serial_generic_open); 101EXPORT_SYMBOL_GPL(usb_serial_generic_open);
104 102
105static void generic_cleanup(struct usb_serial_port *port) 103void usb_serial_generic_close(struct usb_serial_port *port)
106{ 104{
107 struct usb_serial *serial = port->serial;
108 unsigned long flags; 105 unsigned long flags;
109 int i; 106 int i;
110 107
111 if (serial->dev) { 108 if (port->bulk_out_size) {
112 /* shutdown any bulk transfers that might be going on */ 109 for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i)
113 if (port->bulk_out_size) { 110 usb_kill_urb(port->write_urbs[i]);
114 for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i)
115 usb_kill_urb(port->write_urbs[i]);
116 111
117 spin_lock_irqsave(&port->lock, flags); 112 spin_lock_irqsave(&port->lock, flags);
118 kfifo_reset_out(&port->write_fifo); 113 kfifo_reset_out(&port->write_fifo);
119 spin_unlock_irqrestore(&port->lock, flags); 114 spin_unlock_irqrestore(&port->lock, flags);
120 } 115 }
121 if (port->bulk_in_size) { 116 if (port->bulk_in_size) {
122 for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) 117 for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i)
123 usb_kill_urb(port->read_urbs[i]); 118 usb_kill_urb(port->read_urbs[i]);
124 }
125 } 119 }
126}
127
128void usb_serial_generic_close(struct usb_serial_port *port)
129{
130 generic_cleanup(port);
131} 120}
132EXPORT_SYMBOL_GPL(usb_serial_generic_close); 121EXPORT_SYMBOL_GPL(usb_serial_generic_close);
133 122
@@ -272,8 +261,7 @@ static int usb_serial_generic_submit_read_urb(struct usb_serial_port *port,
272 if (!test_and_clear_bit(index, &port->read_urbs_free)) 261 if (!test_and_clear_bit(index, &port->read_urbs_free))
273 return 0; 262 return 0;
274 263
275 dev_dbg(&port->dev, "%s - port %d, urb %d\n", __func__, 264 dev_dbg(&port->dev, "%s - urb %d\n", __func__, index);
276 port->number, index);
277 265
278 res = usb_submit_urb(port->read_urbs[index], mem_flags); 266 res = usb_submit_urb(port->read_urbs[index], mem_flags);
279 if (res) { 267 if (res) {
@@ -347,8 +335,8 @@ void usb_serial_generic_read_bulk_callback(struct urb *urb)
347 } 335 }
348 set_bit(i, &port->read_urbs_free); 336 set_bit(i, &port->read_urbs_free);
349 337
350 dev_dbg(&port->dev, "%s - port %d, urb %d, len %d\n", 338 dev_dbg(&port->dev, "%s - urb %d, len %d\n", __func__, i,
351 __func__, port->number, i, urb->actual_length); 339 urb->actual_length);
352 340
353 if (urb->status) { 341 if (urb->status) {
354 dev_dbg(&port->dev, "%s - non-zero urb status: %d\n", 342 dev_dbg(&port->dev, "%s - non-zero urb status: %d\n",
@@ -430,6 +418,91 @@ void usb_serial_generic_unthrottle(struct tty_struct *tty)
430} 418}
431EXPORT_SYMBOL_GPL(usb_serial_generic_unthrottle); 419EXPORT_SYMBOL_GPL(usb_serial_generic_unthrottle);
432 420
421static bool usb_serial_generic_msr_changed(struct tty_struct *tty,
422 unsigned long arg, struct async_icount *cprev)
423{
424 struct usb_serial_port *port = tty->driver_data;
425 struct async_icount cnow;
426 unsigned long flags;
427 bool ret;
428
429 /*
430 * Use tty-port initialised flag to detect all hangups including the
431 * one generated at USB-device disconnect.
432 *
433 * FIXME: Remove hupping check once tty_port_hangup calls shutdown
434 * (which clears the initialised flag) before wake up.
435 */
436 if (test_bit(TTY_HUPPING, &tty->flags))
437 return true;
438 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags))
439 return true;
440
441 spin_lock_irqsave(&port->lock, flags);
442 cnow = port->icount; /* atomic copy*/
443 spin_unlock_irqrestore(&port->lock, flags);
444
445 ret = ((arg & TIOCM_RNG) && (cnow.rng != cprev->rng)) ||
446 ((arg & TIOCM_DSR) && (cnow.dsr != cprev->dsr)) ||
447 ((arg & TIOCM_CD) && (cnow.dcd != cprev->dcd)) ||
448 ((arg & TIOCM_CTS) && (cnow.cts != cprev->cts));
449
450 *cprev = cnow;
451
452 return ret;
453}
454
455int usb_serial_generic_tiocmiwait(struct tty_struct *tty, unsigned long arg)
456{
457 struct usb_serial_port *port = tty->driver_data;
458 struct async_icount cnow;
459 unsigned long flags;
460 int ret;
461
462 spin_lock_irqsave(&port->lock, flags);
463 cnow = port->icount; /* atomic copy */
464 spin_unlock_irqrestore(&port->lock, flags);
465
466 ret = wait_event_interruptible(port->port.delta_msr_wait,
467 usb_serial_generic_msr_changed(tty, arg, &cnow));
468 if (!ret) {
469 if (test_bit(TTY_HUPPING, &tty->flags))
470 ret = -EIO;
471 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags))
472 ret = -EIO;
473 }
474
475 return ret;
476}
477EXPORT_SYMBOL_GPL(usb_serial_generic_tiocmiwait);
478
479int usb_serial_generic_get_icount(struct tty_struct *tty,
480 struct serial_icounter_struct *icount)
481{
482 struct usb_serial_port *port = tty->driver_data;
483 struct async_icount cnow;
484 unsigned long flags;
485
486 spin_lock_irqsave(&port->lock, flags);
487 cnow = port->icount; /* atomic copy */
488 spin_unlock_irqrestore(&port->lock, flags);
489
490 icount->cts = cnow.cts;
491 icount->dsr = cnow.dsr;
492 icount->rng = cnow.rng;
493 icount->dcd = cnow.dcd;
494 icount->tx = cnow.tx;
495 icount->rx = cnow.rx;
496 icount->frame = cnow.frame;
497 icount->parity = cnow.parity;
498 icount->overrun = cnow.overrun;
499 icount->brk = cnow.brk;
500 icount->buf_overrun = cnow.buf_overrun;
501
502 return 0;
503}
504EXPORT_SYMBOL_GPL(usb_serial_generic_get_icount);
505
433#ifdef CONFIG_MAGIC_SYSRQ 506#ifdef CONFIG_MAGIC_SYSRQ
434int usb_serial_handle_sysrq_char(struct usb_serial_port *port, unsigned int ch) 507int usb_serial_handle_sysrq_char(struct usb_serial_port *port, unsigned int ch)
435{ 508{
@@ -473,8 +546,7 @@ void usb_serial_handle_dcd_change(struct usb_serial_port *usb_port,
473{ 546{
474 struct tty_port *port = &usb_port->port; 547 struct tty_port *port = &usb_port->port;
475 548
476 dev_dbg(&usb_port->dev, "%s - port %d, status %d\n", __func__, 549 dev_dbg(&usb_port->dev, "%s - status %d\n", __func__, status);
477 usb_port->number, status);
478 550
479 if (status) 551 if (status)
480 wake_up_interruptible(&port->open_wait); 552 wake_up_interruptible(&port->open_wait);
@@ -510,17 +582,3 @@ int usb_serial_generic_resume(struct usb_serial *serial)
510 return c ? -EIO : 0; 582 return c ? -EIO : 0;
511} 583}
512EXPORT_SYMBOL_GPL(usb_serial_generic_resume); 584EXPORT_SYMBOL_GPL(usb_serial_generic_resume);
513
514void usb_serial_generic_disconnect(struct usb_serial *serial)
515{
516 int i;
517
518 /* stop reads and writes on all ports */
519 for (i = 0; i < serial->num_ports; ++i)
520 generic_cleanup(serial->port[i]);
521}
522EXPORT_SYMBOL_GPL(usb_serial_generic_disconnect);
523
524void usb_serial_generic_release(struct usb_serial *serial)
525{
526}
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c
index efd8b978128c..ff9a6ef8477f 100644
--- a/drivers/usb/serial/io_edgeport.c
+++ b/drivers/usb/serial/io_edgeport.c
@@ -111,7 +111,6 @@ struct edgeport_port {
111 wait_queue_head_t wait_open; /* for handling sleeping while waiting for open to finish */ 111 wait_queue_head_t wait_open; /* for handling sleeping while waiting for open to finish */
112 wait_queue_head_t wait_command; /* for handling sleeping while waiting for command to finish */ 112 wait_queue_head_t wait_command; /* for handling sleeping while waiting for command to finish */
113 113
114 struct async_icount icount;
115 struct usb_serial_port *port; /* loop back to the owner of this object */ 114 struct usb_serial_port *port; /* loop back to the owner of this object */
116}; 115};
117 116
@@ -215,8 +214,6 @@ static void edge_break(struct tty_struct *tty, int break_state);
215static int edge_tiocmget(struct tty_struct *tty); 214static int edge_tiocmget(struct tty_struct *tty);
216static int edge_tiocmset(struct tty_struct *tty, 215static int edge_tiocmset(struct tty_struct *tty,
217 unsigned int set, unsigned int clear); 216 unsigned int set, unsigned int clear);
218static int edge_get_icount(struct tty_struct *tty,
219 struct serial_icounter_struct *icount);
220static int edge_startup(struct usb_serial *serial); 217static int edge_startup(struct usb_serial *serial);
221static void edge_disconnect(struct usb_serial *serial); 218static void edge_disconnect(struct usb_serial *serial);
222static void edge_release(struct usb_serial *serial); 219static void edge_release(struct usb_serial *serial);
@@ -885,9 +882,6 @@ static int edge_open(struct tty_struct *tty, struct usb_serial_port *port)
885 init_waitqueue_head(&edge_port->wait_chase); 882 init_waitqueue_head(&edge_port->wait_chase);
886 init_waitqueue_head(&edge_port->wait_command); 883 init_waitqueue_head(&edge_port->wait_command);
887 884
888 /* initialize our icount structure */
889 memset(&(edge_port->icount), 0x00, sizeof(edge_port->icount));
890
891 /* initialize our port settings */ 885 /* initialize our port settings */
892 edge_port->txCredits = 0; /* Can't send any data yet */ 886 edge_port->txCredits = 0; /* Can't send any data yet */
893 /* Must always set this bit to enable ints! */ 887 /* Must always set this bit to enable ints! */
@@ -1314,7 +1308,7 @@ static void send_more_port_data(struct edgeport_serial *edge_serial,
1314 1308
1315 /* decrement the number of credits we have by the number we just sent */ 1309 /* decrement the number of credits we have by the number we just sent */
1316 edge_port->txCredits -= count; 1310 edge_port->txCredits -= count;
1317 edge_port->icount.tx += count; 1311 edge_port->port->icount.tx += count;
1318 1312
1319 status = usb_submit_urb(urb, GFP_ATOMIC); 1313 status = usb_submit_urb(urb, GFP_ATOMIC);
1320 if (status) { 1314 if (status) {
@@ -1326,7 +1320,7 @@ static void send_more_port_data(struct edgeport_serial *edge_serial,
1326 1320
1327 /* revert the credits as something bad happened. */ 1321 /* revert the credits as something bad happened. */
1328 edge_port->txCredits += count; 1322 edge_port->txCredits += count;
1329 edge_port->icount.tx -= count; 1323 edge_port->port->icount.tx -= count;
1330 } 1324 }
1331 dev_dbg(dev, "%s wrote %d byte(s) TxCredit %d, Fifo %d\n", 1325 dev_dbg(dev, "%s wrote %d byte(s) TxCredit %d, Fifo %d\n",
1332 __func__, count, edge_port->txCredits, fifo->count); 1326 __func__, count, edge_port->txCredits, fifo->count);
@@ -1588,31 +1582,6 @@ static int edge_tiocmget(struct tty_struct *tty)
1588 return result; 1582 return result;
1589} 1583}
1590 1584
1591static int edge_get_icount(struct tty_struct *tty,
1592 struct serial_icounter_struct *icount)
1593{
1594 struct usb_serial_port *port = tty->driver_data;
1595 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1596 struct async_icount cnow;
1597 cnow = edge_port->icount;
1598
1599 icount->cts = cnow.cts;
1600 icount->dsr = cnow.dsr;
1601 icount->rng = cnow.rng;
1602 icount->dcd = cnow.dcd;
1603 icount->rx = cnow.rx;
1604 icount->tx = cnow.tx;
1605 icount->frame = cnow.frame;
1606 icount->overrun = cnow.overrun;
1607 icount->parity = cnow.parity;
1608 icount->brk = cnow.brk;
1609 icount->buf_overrun = cnow.buf_overrun;
1610
1611 dev_dbg(&port->dev, "%s (%d) TIOCGICOUNT RX=%d, TX=%d\n", __func__,
1612 port->number, icount->rx, icount->tx);
1613 return 0;
1614}
1615
1616static int get_serial_info(struct edgeport_port *edge_port, 1585static int get_serial_info(struct edgeport_port *edge_port,
1617 struct serial_struct __user *retinfo) 1586 struct serial_struct __user *retinfo)
1618{ 1587{
@@ -1649,8 +1618,6 @@ static int edge_ioctl(struct tty_struct *tty,
1649 struct usb_serial_port *port = tty->driver_data; 1618 struct usb_serial_port *port = tty->driver_data;
1650 DEFINE_WAIT(wait); 1619 DEFINE_WAIT(wait);
1651 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1620 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1652 struct async_icount cnow;
1653 struct async_icount cprev;
1654 1621
1655 dev_dbg(&port->dev, "%s - port %d, cmd = 0x%x\n", __func__, port->number, cmd); 1622 dev_dbg(&port->dev, "%s - port %d, cmd = 0x%x\n", __func__, port->number, cmd);
1656 1623
@@ -1662,37 +1629,6 @@ static int edge_ioctl(struct tty_struct *tty,
1662 case TIOCGSERIAL: 1629 case TIOCGSERIAL:
1663 dev_dbg(&port->dev, "%s (%d) TIOCGSERIAL\n", __func__, port->number); 1630 dev_dbg(&port->dev, "%s (%d) TIOCGSERIAL\n", __func__, port->number);
1664 return get_serial_info(edge_port, (struct serial_struct __user *) arg); 1631 return get_serial_info(edge_port, (struct serial_struct __user *) arg);
1665
1666 case TIOCMIWAIT:
1667 dev_dbg(&port->dev, "%s (%d) TIOCMIWAIT\n", __func__, port->number);
1668 cprev = edge_port->icount;
1669 while (1) {
1670 prepare_to_wait(&port->delta_msr_wait,
1671 &wait, TASK_INTERRUPTIBLE);
1672 schedule();
1673 finish_wait(&port->delta_msr_wait, &wait);
1674 /* see if a signal did it */
1675 if (signal_pending(current))
1676 return -ERESTARTSYS;
1677
1678 if (port->serial->disconnected)
1679 return -EIO;
1680
1681 cnow = edge_port->icount;
1682 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
1683 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
1684 return -EIO; /* no change => error */
1685 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
1686 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
1687 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
1688 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
1689 return 0;
1690 }
1691 cprev = cnow;
1692 }
1693 /* NOTREACHED */
1694 break;
1695
1696 } 1632 }
1697 return -ENOIOCTLCMD; 1633 return -ENOIOCTLCMD;
1698} 1634}
@@ -1866,7 +1802,7 @@ static void process_rcvd_data(struct edgeport_serial *edge_serial,
1866 edge_serial->rxPort); 1802 edge_serial->rxPort);
1867 edge_tty_recv(edge_port->port, buffer, 1803 edge_tty_recv(edge_port->port, buffer,
1868 rxLen); 1804 rxLen);
1869 edge_port->icount.rx += rxLen; 1805 edge_port->port->icount.rx += rxLen;
1870 } 1806 }
1871 buffer += rxLen; 1807 buffer += rxLen;
1872 } 1808 }
@@ -2042,7 +1978,7 @@ static void handle_new_msr(struct edgeport_port *edge_port, __u8 newMsr)
2042 1978
2043 if (newMsr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR | 1979 if (newMsr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR |
2044 EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) { 1980 EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) {
2045 icount = &edge_port->icount; 1981 icount = &edge_port->port->icount;
2046 1982
2047 /* update input line counters */ 1983 /* update input line counters */
2048 if (newMsr & EDGEPORT_MSR_DELTA_CTS) 1984 if (newMsr & EDGEPORT_MSR_DELTA_CTS)
@@ -2053,7 +1989,7 @@ static void handle_new_msr(struct edgeport_port *edge_port, __u8 newMsr)
2053 icount->dcd++; 1989 icount->dcd++;
2054 if (newMsr & EDGEPORT_MSR_DELTA_RI) 1990 if (newMsr & EDGEPORT_MSR_DELTA_RI)
2055 icount->rng++; 1991 icount->rng++;
2056 wake_up_interruptible(&edge_port->port->delta_msr_wait); 1992 wake_up_interruptible(&edge_port->port->port.delta_msr_wait);
2057 } 1993 }
2058 1994
2059 /* Save the new modem status */ 1995 /* Save the new modem status */
@@ -2088,7 +2024,7 @@ static void handle_new_lsr(struct edgeport_port *edge_port, __u8 lsrData,
2088 edge_tty_recv(edge_port->port, &data, 1); 2024 edge_tty_recv(edge_port->port, &data, 1);
2089 2025
2090 /* update input line counters */ 2026 /* update input line counters */
2091 icount = &edge_port->icount; 2027 icount = &edge_port->port->icount;
2092 if (newLsr & LSR_BREAK) 2028 if (newLsr & LSR_BREAK)
2093 icount->brk++; 2029 icount->brk++;
2094 if (newLsr & LSR_OVER_ERR) 2030 if (newLsr & LSR_OVER_ERR)
diff --git a/drivers/usb/serial/io_tables.h b/drivers/usb/serial/io_tables.h
index 1511dd0ad324..ae5fac5656c9 100644
--- a/drivers/usb/serial/io_tables.h
+++ b/drivers/usb/serial/io_tables.h
@@ -116,7 +116,8 @@ static struct usb_serial_driver edgeport_2port_device = {
116 .set_termios = edge_set_termios, 116 .set_termios = edge_set_termios,
117 .tiocmget = edge_tiocmget, 117 .tiocmget = edge_tiocmget,
118 .tiocmset = edge_tiocmset, 118 .tiocmset = edge_tiocmset,
119 .get_icount = edge_get_icount, 119 .tiocmiwait = usb_serial_generic_tiocmiwait,
120 .get_icount = usb_serial_generic_get_icount,
120 .write = edge_write, 121 .write = edge_write,
121 .write_room = edge_write_room, 122 .write_room = edge_write_room,
122 .chars_in_buffer = edge_chars_in_buffer, 123 .chars_in_buffer = edge_chars_in_buffer,
@@ -147,7 +148,8 @@ static struct usb_serial_driver edgeport_4port_device = {
147 .set_termios = edge_set_termios, 148 .set_termios = edge_set_termios,
148 .tiocmget = edge_tiocmget, 149 .tiocmget = edge_tiocmget,
149 .tiocmset = edge_tiocmset, 150 .tiocmset = edge_tiocmset,
150 .get_icount = edge_get_icount, 151 .tiocmiwait = usb_serial_generic_tiocmiwait,
152 .get_icount = usb_serial_generic_get_icount,
151 .write = edge_write, 153 .write = edge_write,
152 .write_room = edge_write_room, 154 .write_room = edge_write_room,
153 .chars_in_buffer = edge_chars_in_buffer, 155 .chars_in_buffer = edge_chars_in_buffer,
@@ -178,7 +180,8 @@ static struct usb_serial_driver edgeport_8port_device = {
178 .set_termios = edge_set_termios, 180 .set_termios = edge_set_termios,
179 .tiocmget = edge_tiocmget, 181 .tiocmget = edge_tiocmget,
180 .tiocmset = edge_tiocmset, 182 .tiocmset = edge_tiocmset,
181 .get_icount = edge_get_icount, 183 .tiocmiwait = usb_serial_generic_tiocmiwait,
184 .get_icount = usb_serial_generic_get_icount,
182 .write = edge_write, 185 .write = edge_write,
183 .write_room = edge_write_room, 186 .write_room = edge_write_room,
184 .chars_in_buffer = edge_chars_in_buffer, 187 .chars_in_buffer = edge_chars_in_buffer,
@@ -209,7 +212,8 @@ static struct usb_serial_driver epic_device = {
209 .set_termios = edge_set_termios, 212 .set_termios = edge_set_termios,
210 .tiocmget = edge_tiocmget, 213 .tiocmget = edge_tiocmget,
211 .tiocmset = edge_tiocmset, 214 .tiocmset = edge_tiocmset,
212 .get_icount = edge_get_icount, 215 .tiocmiwait = usb_serial_generic_tiocmiwait,
216 .get_icount = usb_serial_generic_get_icount,
213 .write = edge_write, 217 .write = edge_write,
214 .write_room = edge_write_room, 218 .write_room = edge_write_room,
215 .chars_in_buffer = edge_chars_in_buffer, 219 .chars_in_buffer = edge_chars_in_buffer,
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index 7777172206de..f2a1601775b1 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -86,7 +86,7 @@ struct edgeport_port {
86 int baud_rate; 86 int baud_rate;
87 int close_pending; 87 int close_pending;
88 int lsr_event; 88 int lsr_event;
89 struct async_icount icount; 89
90 struct edgeport_serial *edge_serial; 90 struct edgeport_serial *edge_serial;
91 struct usb_serial_port *port; 91 struct usb_serial_port *port;
92 __u8 bUartMode; /* Port type, 0: RS232, etc. */ 92 __u8 bUartMode; /* Port type, 0: RS232, etc. */
@@ -206,7 +206,7 @@ static int restart_read(struct edgeport_port *edge_port);
206 206
207static void edge_set_termios(struct tty_struct *tty, 207static void edge_set_termios(struct tty_struct *tty,
208 struct usb_serial_port *port, struct ktermios *old_termios); 208 struct usb_serial_port *port, struct ktermios *old_termios);
209static void edge_send(struct tty_struct *tty); 209static void edge_send(struct usb_serial_port *port, struct tty_struct *tty);
210 210
211/* sysfs attributes */ 211/* sysfs attributes */
212static int edge_create_sysfs_attrs(struct usb_serial_port *port); 212static int edge_create_sysfs_attrs(struct usb_serial_port *port);
@@ -1445,7 +1445,7 @@ static void handle_new_msr(struct edgeport_port *edge_port, __u8 msr)
1445 1445
1446 if (msr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR | 1446 if (msr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR |
1447 EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) { 1447 EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) {
1448 icount = &edge_port->icount; 1448 icount = &edge_port->port->icount;
1449 1449
1450 /* update input line counters */ 1450 /* update input line counters */
1451 if (msr & EDGEPORT_MSR_DELTA_CTS) 1451 if (msr & EDGEPORT_MSR_DELTA_CTS)
@@ -1456,7 +1456,7 @@ static void handle_new_msr(struct edgeport_port *edge_port, __u8 msr)
1456 icount->dcd++; 1456 icount->dcd++;
1457 if (msr & EDGEPORT_MSR_DELTA_RI) 1457 if (msr & EDGEPORT_MSR_DELTA_RI)
1458 icount->rng++; 1458 icount->rng++;
1459 wake_up_interruptible(&edge_port->port->delta_msr_wait); 1459 wake_up_interruptible(&edge_port->port->port.delta_msr_wait);
1460 } 1460 }
1461 1461
1462 /* Save the new modem status */ 1462 /* Save the new modem status */
@@ -1498,7 +1498,7 @@ static void handle_new_lsr(struct edgeport_port *edge_port, int lsr_data,
1498 edge_tty_recv(edge_port->port, &data, 1); 1498 edge_tty_recv(edge_port->port, &data, 1);
1499 1499
1500 /* update input line counters */ 1500 /* update input line counters */
1501 icount = &edge_port->icount; 1501 icount = &edge_port->port->icount;
1502 if (new_lsr & LSR_BREAK) 1502 if (new_lsr & LSR_BREAK)
1503 icount->brk++; 1503 icount->brk++;
1504 if (new_lsr & LSR_OVER_ERR) 1504 if (new_lsr & LSR_OVER_ERR)
@@ -1657,7 +1657,7 @@ static void edge_bulk_in_callback(struct urb *urb)
1657 else 1657 else
1658 edge_tty_recv(edge_port->port, data, 1658 edge_tty_recv(edge_port->port, data,
1659 urb->actual_length); 1659 urb->actual_length);
1660 edge_port->icount.rx += urb->actual_length; 1660 edge_port->port->icount.rx += urb->actual_length;
1661 } 1661 }
1662 1662
1663exit: 1663exit:
@@ -1712,7 +1712,7 @@ static void edge_bulk_out_callback(struct urb *urb)
1712 1712
1713 /* send any buffered data */ 1713 /* send any buffered data */
1714 tty = tty_port_tty_get(&port->port); 1714 tty = tty_port_tty_get(&port->port);
1715 edge_send(tty); 1715 edge_send(port, tty);
1716 tty_kref_put(tty); 1716 tty_kref_put(tty);
1717} 1717}
1718 1718
@@ -1750,8 +1750,6 @@ static int edge_open(struct tty_struct *tty, struct usb_serial_port *port)
1750 1750
1751 dev = port->serial->dev; 1751 dev = port->serial->dev;
1752 1752
1753 memset(&(edge_port->icount), 0x00, sizeof(edge_port->icount));
1754
1755 /* turn off loopback */ 1753 /* turn off loopback */
1756 status = ti_do_config(edge_port, UMPC_SET_CLR_LOOPBACK, 0); 1754 status = ti_do_config(edge_port, UMPC_SET_CLR_LOOPBACK, 0);
1757 if (status) { 1755 if (status) {
@@ -1909,21 +1907,10 @@ static void edge_close(struct usb_serial_port *port)
1909 kfifo_reset_out(&edge_port->write_fifo); 1907 kfifo_reset_out(&edge_port->write_fifo);
1910 spin_unlock_irqrestore(&edge_port->ep_lock, flags); 1908 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
1911 1909
1912 /* assuming we can still talk to the device,
1913 * send a close port command to it */
1914 dev_dbg(&port->dev, "%s - send umpc_close_port\n", __func__); 1910 dev_dbg(&port->dev, "%s - send umpc_close_port\n", __func__);
1915 port_number = port->number - port->serial->minor; 1911 port_number = port->number - port->serial->minor;
1916 1912 send_cmd(serial->dev, UMPC_CLOSE_PORT,
1917 mutex_lock(&serial->disc_mutex); 1913 (__u8)(UMPM_UART1_PORT + port_number), 0, NULL, 0);
1918 if (!serial->disconnected) {
1919 send_cmd(serial->dev,
1920 UMPC_CLOSE_PORT,
1921 (__u8)(UMPM_UART1_PORT + port_number),
1922 0,
1923 NULL,
1924 0);
1925 }
1926 mutex_unlock(&serial->disc_mutex);
1927 1914
1928 mutex_lock(&edge_serial->es_lock); 1915 mutex_lock(&edge_serial->es_lock);
1929 --edge_port->edge_serial->num_ports_open; 1916 --edge_port->edge_serial->num_ports_open;
@@ -1953,14 +1940,13 @@ static int edge_write(struct tty_struct *tty, struct usb_serial_port *port,
1953 1940
1954 count = kfifo_in_locked(&edge_port->write_fifo, data, count, 1941 count = kfifo_in_locked(&edge_port->write_fifo, data, count,
1955 &edge_port->ep_lock); 1942 &edge_port->ep_lock);
1956 edge_send(tty); 1943 edge_send(port, tty);
1957 1944
1958 return count; 1945 return count;
1959} 1946}
1960 1947
1961static void edge_send(struct tty_struct *tty) 1948static void edge_send(struct usb_serial_port *port, struct tty_struct *tty)
1962{ 1949{
1963 struct usb_serial_port *port = tty->driver_data;
1964 int count, result; 1950 int count, result;
1965 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1951 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1966 unsigned long flags; 1952 unsigned long flags;
@@ -1999,7 +1985,7 @@ static void edge_send(struct tty_struct *tty)
1999 edge_port->ep_write_urb_in_use = 0; 1985 edge_port->ep_write_urb_in_use = 0;
2000 /* TODO: reschedule edge_send */ 1986 /* TODO: reschedule edge_send */
2001 } else 1987 } else
2002 edge_port->icount.tx += count; 1988 edge_port->port->icount.tx += count;
2003 1989
2004 /* wakeup any process waiting for writes to complete */ 1990 /* wakeup any process waiting for writes to complete */
2005 /* there is now more room in the buffer for new writes */ 1991 /* there is now more room in the buffer for new writes */
@@ -2360,27 +2346,6 @@ static int edge_tiocmget(struct tty_struct *tty)
2360 return result; 2346 return result;
2361} 2347}
2362 2348
2363static int edge_get_icount(struct tty_struct *tty,
2364 struct serial_icounter_struct *icount)
2365{
2366 struct usb_serial_port *port = tty->driver_data;
2367 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2368 struct async_icount *ic = &edge_port->icount;
2369
2370 icount->cts = ic->cts;
2371 icount->dsr = ic->dsr;
2372 icount->rng = ic->rng;
2373 icount->dcd = ic->dcd;
2374 icount->tx = ic->tx;
2375 icount->rx = ic->rx;
2376 icount->frame = ic->frame;
2377 icount->parity = ic->parity;
2378 icount->overrun = ic->overrun;
2379 icount->brk = ic->brk;
2380 icount->buf_overrun = ic->buf_overrun;
2381 return 0;
2382}
2383
2384static int get_serial_info(struct edgeport_port *edge_port, 2349static int get_serial_info(struct edgeport_port *edge_port,
2385 struct serial_struct __user *retinfo) 2350 struct serial_struct __user *retinfo)
2386{ 2351{
@@ -2416,8 +2381,6 @@ static int edge_ioctl(struct tty_struct *tty,
2416{ 2381{
2417 struct usb_serial_port *port = tty->driver_data; 2382 struct usb_serial_port *port = tty->driver_data;
2418 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2383 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2419 struct async_icount cnow;
2420 struct async_icount cprev;
2421 2384
2422 dev_dbg(&port->dev, "%s - port %d, cmd = 0x%x\n", __func__, port->number, cmd); 2385 dev_dbg(&port->dev, "%s - port %d, cmd = 0x%x\n", __func__, port->number, cmd);
2423 2386
@@ -2426,32 +2389,6 @@ static int edge_ioctl(struct tty_struct *tty,
2426 dev_dbg(&port->dev, "%s - TIOCGSERIAL\n", __func__); 2389 dev_dbg(&port->dev, "%s - TIOCGSERIAL\n", __func__);
2427 return get_serial_info(edge_port, 2390 return get_serial_info(edge_port,
2428 (struct serial_struct __user *) arg); 2391 (struct serial_struct __user *) arg);
2429 case TIOCMIWAIT:
2430 dev_dbg(&port->dev, "%s - TIOCMIWAIT\n", __func__);
2431 cprev = edge_port->icount;
2432 while (1) {
2433 interruptible_sleep_on(&port->delta_msr_wait);
2434 /* see if a signal did it */
2435 if (signal_pending(current))
2436 return -ERESTARTSYS;
2437
2438 if (port->serial->disconnected)
2439 return -EIO;
2440
2441 cnow = edge_port->icount;
2442 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2443 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
2444 return -EIO; /* no change => error */
2445 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
2446 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
2447 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
2448 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
2449 return 0;
2450 }
2451 cprev = cnow;
2452 }
2453 /* not reached */
2454 break;
2455 } 2392 }
2456 return -ENOIOCTLCMD; 2393 return -ENOIOCTLCMD;
2457} 2394}
@@ -2546,7 +2483,6 @@ static int edge_port_remove(struct usb_serial_port *port)
2546 struct edgeport_port *edge_port; 2483 struct edgeport_port *edge_port;
2547 2484
2548 edge_port = usb_get_serial_port_data(port); 2485 edge_port = usb_get_serial_port_data(port);
2549
2550 edge_remove_sysfs_attrs(port); 2486 edge_remove_sysfs_attrs(port);
2551 kfifo_free(&edge_port->write_fifo); 2487 kfifo_free(&edge_port->write_fifo);
2552 kfree(edge_port); 2488 kfree(edge_port);
@@ -2618,7 +2554,8 @@ static struct usb_serial_driver edgeport_1port_device = {
2618 .set_termios = edge_set_termios, 2554 .set_termios = edge_set_termios,
2619 .tiocmget = edge_tiocmget, 2555 .tiocmget = edge_tiocmget,
2620 .tiocmset = edge_tiocmset, 2556 .tiocmset = edge_tiocmset,
2621 .get_icount = edge_get_icount, 2557 .tiocmiwait = usb_serial_generic_tiocmiwait,
2558 .get_icount = usb_serial_generic_get_icount,
2622 .write = edge_write, 2559 .write = edge_write,
2623 .write_room = edge_write_room, 2560 .write_room = edge_write_room,
2624 .chars_in_buffer = edge_chars_in_buffer, 2561 .chars_in_buffer = edge_chars_in_buffer,
@@ -2649,7 +2586,8 @@ static struct usb_serial_driver edgeport_2port_device = {
2649 .set_termios = edge_set_termios, 2586 .set_termios = edge_set_termios,
2650 .tiocmget = edge_tiocmget, 2587 .tiocmget = edge_tiocmget,
2651 .tiocmset = edge_tiocmset, 2588 .tiocmset = edge_tiocmset,
2652 .get_icount = edge_get_icount, 2589 .tiocmiwait = usb_serial_generic_tiocmiwait,
2590 .get_icount = usb_serial_generic_get_icount,
2653 .write = edge_write, 2591 .write = edge_write,
2654 .write_room = edge_write_room, 2592 .write_room = edge_write_room,
2655 .chars_in_buffer = edge_chars_in_buffer, 2593 .chars_in_buffer = edge_chars_in_buffer,
diff --git a/drivers/usb/serial/iuu_phoenix.c b/drivers/usb/serial/iuu_phoenix.c
index ff77027160aa..9d74c278b7b5 100644
--- a/drivers/usb/serial/iuu_phoenix.c
+++ b/drivers/usb/serial/iuu_phoenix.c
@@ -55,7 +55,6 @@ static void read_rxcmd_callback(struct urb *urb);
55 55
56struct iuu_private { 56struct iuu_private {
57 spinlock_t lock; /* store irq state */ 57 spinlock_t lock; /* store irq state */
58 wait_queue_head_t delta_msr_wait;
59 u8 line_status; 58 u8 line_status;
60 int tiostatus; /* store IUART SIGNAL for tiocmget call */ 59 int tiostatus; /* store IUART SIGNAL for tiocmget call */
61 u8 reset; /* if 1 reset is needed */ 60 u8 reset; /* if 1 reset is needed */
@@ -94,7 +93,6 @@ static int iuu_port_probe(struct usb_serial_port *port)
94 93
95 priv->vcc = vcc_default; 94 priv->vcc = vcc_default;
96 spin_lock_init(&priv->lock); 95 spin_lock_init(&priv->lock);
97 init_waitqueue_head(&priv->delta_msr_wait);
98 96
99 usb_set_serial_port_data(port, priv); 97 usb_set_serial_port_data(port, priv);
100 98
@@ -944,22 +942,13 @@ static void iuu_set_termios(struct tty_struct *tty,
944static void iuu_close(struct usb_serial_port *port) 942static void iuu_close(struct usb_serial_port *port)
945{ 943{
946 /* iuu_led (port,255,0,0,0); */ 944 /* iuu_led (port,255,0,0,0); */
947 struct usb_serial *serial;
948
949 serial = port->serial;
950 if (!serial)
951 return;
952 945
953 iuu_uart_off(port); 946 iuu_uart_off(port);
954 if (serial->dev) { 947
955 /* free writebuf */ 948 usb_kill_urb(port->write_urb);
956 /* shutdown our urbs */ 949 usb_kill_urb(port->read_urb);
957 dev_dbg(&port->dev, "%s - shutting down urbs\n", __func__); 950
958 usb_kill_urb(port->write_urb); 951 iuu_led(port, 0, 0, 0xF000, 0xFF);
959 usb_kill_urb(port->read_urb);
960 usb_kill_urb(port->interrupt_in_urb);
961 iuu_led(port, 0, 0, 0xF000, 0xFF);
962 }
963} 952}
964 953
965static void iuu_init_termios(struct tty_struct *tty) 954static void iuu_init_termios(struct tty_struct *tty)
diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c
index 1fd1935c8316..025310bc358a 100644
--- a/drivers/usb/serial/keyspan.c
+++ b/drivers/usb/serial/keyspan.c
@@ -726,45 +726,45 @@ static void usa49wg_indat_callback(struct urb *urb)
726 i = 0; 726 i = 0;
727 len = 0; 727 len = 0;
728 728
729 if (urb->actual_length) { 729 while (i < urb->actual_length) {
730 while (i < urb->actual_length) {
731 730
732 /* Check port number from message*/ 731 /* Check port number from message */
733 if (data[i] >= serial->num_ports) { 732 if (data[i] >= serial->num_ports) {
734 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n", 733 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n",
735 __func__, data[i]); 734 __func__, data[i]);
736 return; 735 return;
737 } 736 }
738 port = serial->port[data[i++]]; 737 port = serial->port[data[i++]];
739 len = data[i++]; 738 len = data[i++];
740 739
741 /* 0x80 bit is error flag */ 740 /* 0x80 bit is error flag */
742 if ((data[i] & 0x80) == 0) { 741 if ((data[i] & 0x80) == 0) {
743 /* no error on any byte */ 742 /* no error on any byte */
744 i++; 743 i++;
745 for (x = 1; x < len ; ++x) 744 for (x = 1; x < len && i < urb->actual_length; ++x)
746 tty_insert_flip_char(&port->port, 745 tty_insert_flip_char(&port->port,
747 data[i++], 0); 746 data[i++], 0);
748 } else { 747 } else {
749 /* 748 /*
750 * some bytes had errors, every byte has status 749 * some bytes had errors, every byte has status
751 */ 750 */
752 for (x = 0; x + 1 < len; x += 2) { 751 for (x = 0; x + 1 < len &&
753 int stat = data[i], flag = 0; 752 i + 1 < urb->actual_length; x += 2) {
754 if (stat & RXERROR_OVERRUN) 753 int stat = data[i], flag = 0;
755 flag |= TTY_OVERRUN; 754
756 if (stat & RXERROR_FRAMING) 755 if (stat & RXERROR_OVERRUN)
757 flag |= TTY_FRAME; 756 flag |= TTY_OVERRUN;
758 if (stat & RXERROR_PARITY) 757 if (stat & RXERROR_FRAMING)
759 flag |= TTY_PARITY; 758 flag |= TTY_FRAME;
760 /* XXX should handle break (0x10) */ 759 if (stat & RXERROR_PARITY)
761 tty_insert_flip_char(&port->port, 760 flag |= TTY_PARITY;
762 data[i+1], flag); 761 /* XXX should handle break (0x10) */
763 i += 2; 762 tty_insert_flip_char(&port->port, data[i+1],
764 } 763 flag);
764 i += 2;
765 } 765 }
766 tty_flip_buffer_push(&port->port);
767 } 766 }
767 tty_flip_buffer_push(&port->port);
768 } 768 }
769 769
770 /* Resubmit urb so we continue receiving */ 770 /* Resubmit urb so we continue receiving */
@@ -1115,7 +1115,6 @@ static void keyspan_dtr_rts(struct usb_serial_port *port, int on)
1115static void keyspan_close(struct usb_serial_port *port) 1115static void keyspan_close(struct usb_serial_port *port)
1116{ 1116{
1117 int i; 1117 int i;
1118 struct usb_serial *serial = port->serial;
1119 struct keyspan_port_private *p_priv; 1118 struct keyspan_port_private *p_priv;
1120 1119
1121 p_priv = usb_get_serial_port_data(port); 1120 p_priv = usb_get_serial_port_data(port);
@@ -1123,28 +1122,17 @@ static void keyspan_close(struct usb_serial_port *port)
1123 p_priv->rts_state = 0; 1122 p_priv->rts_state = 0;
1124 p_priv->dtr_state = 0; 1123 p_priv->dtr_state = 0;
1125 1124
1126 if (serial->dev) { 1125 keyspan_send_setup(port, 2);
1127 keyspan_send_setup(port, 2); 1126 /* pilot-xfer seems to work best with this delay */
1128 /* pilot-xfer seems to work best with this delay */ 1127 mdelay(100);
1129 mdelay(100);
1130 /* keyspan_set_termios(port, NULL); */
1131 }
1132
1133 /*while (p_priv->outcont_urb->status == -EINPROGRESS) {
1134 dev_dbg(&port->dev, "%s - urb in progress\n", __func__);
1135 }*/
1136 1128
1137 p_priv->out_flip = 0; 1129 p_priv->out_flip = 0;
1138 p_priv->in_flip = 0; 1130 p_priv->in_flip = 0;
1139 1131
1140 if (serial->dev) { 1132 stop_urb(p_priv->inack_urb);
1141 /* Stop reading/writing urbs */ 1133 for (i = 0; i < 2; i++) {
1142 stop_urb(p_priv->inack_urb); 1134 stop_urb(p_priv->in_urbs[i]);
1143 /* stop_urb(p_priv->outcont_urb); */ 1135 stop_urb(p_priv->out_urbs[i]);
1144 for (i = 0; i < 2; i++) {
1145 stop_urb(p_priv->in_urbs[i]);
1146 stop_urb(p_priv->out_urbs[i]);
1147 }
1148 } 1136 }
1149} 1137}
1150 1138
diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c
index 3b17d5d13dc8..da3b29eb605c 100644
--- a/drivers/usb/serial/keyspan_pda.c
+++ b/drivers/usb/serial/keyspan_pda.c
@@ -595,12 +595,10 @@ static void keyspan_pda_dtr_rts(struct usb_serial_port *port, int on)
595{ 595{
596 struct usb_serial *serial = port->serial; 596 struct usb_serial *serial = port->serial;
597 597
598 if (serial->dev) { 598 if (on)
599 if (on) 599 keyspan_pda_set_modem_info(serial, (1 << 7) | (1 << 2));
600 keyspan_pda_set_modem_info(serial, (1<<7) | (1<< 2)); 600 else
601 else 601 keyspan_pda_set_modem_info(serial, 0);
602 keyspan_pda_set_modem_info(serial, 0);
603 }
604} 602}
605 603
606 604
@@ -651,13 +649,8 @@ error:
651} 649}
652static void keyspan_pda_close(struct usb_serial_port *port) 650static void keyspan_pda_close(struct usb_serial_port *port)
653{ 651{
654 struct usb_serial *serial = port->serial; 652 usb_kill_urb(port->write_urb);
655 653 usb_kill_urb(port->interrupt_in_urb);
656 if (serial->dev) {
657 /* shutdown our bulk reads and writes */
658 usb_kill_urb(port->write_urb);
659 usb_kill_urb(port->interrupt_in_urb);
660 }
661} 654}
662 655
663 656
diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c
index 769d910ae0a5..1b4054fe52a5 100644
--- a/drivers/usb/serial/kl5kusb105.c
+++ b/drivers/usb/serial/kl5kusb105.c
@@ -341,28 +341,20 @@ static void klsi_105_close(struct usb_serial_port *port)
341{ 341{
342 int rc; 342 int rc;
343 343
344 mutex_lock(&port->serial->disc_mutex); 344 /* send READ_OFF */
345 if (!port->serial->disconnected) { 345 rc = usb_control_msg(port->serial->dev,
346 /* send READ_OFF */ 346 usb_sndctrlpipe(port->serial->dev, 0),
347 rc = usb_control_msg(port->serial->dev, 347 KL5KUSB105A_SIO_CONFIGURE,
348 usb_sndctrlpipe(port->serial->dev, 0), 348 USB_TYPE_VENDOR | USB_DIR_OUT,
349 KL5KUSB105A_SIO_CONFIGURE, 349 KL5KUSB105A_SIO_CONFIGURE_READ_OFF,
350 USB_TYPE_VENDOR | USB_DIR_OUT, 350 0, /* index */
351 KL5KUSB105A_SIO_CONFIGURE_READ_OFF, 351 NULL, 0,
352 0, /* index */ 352 KLSI_TIMEOUT);
353 NULL, 0, 353 if (rc < 0)
354 KLSI_TIMEOUT); 354 dev_err(&port->dev, "failed to disable read: %d\n", rc);
355 if (rc < 0)
356 dev_err(&port->dev,
357 "Disabling read failed (error = %d)\n", rc);
358 }
359 mutex_unlock(&port->serial->disc_mutex);
360 355
361 /* shutdown our bulk reads and writes */ 356 /* shutdown our bulk reads and writes */
362 usb_serial_generic_close(port); 357 usb_serial_generic_close(port);
363
364 /* wgg - do I need this? I think so. */
365 usb_kill_urb(port->interrupt_in_urb);
366} 358}
367 359
368/* We need to write a complete 64-byte data block and encode the 360/* We need to write a complete 64-byte data block and encode the
diff --git a/drivers/usb/serial/mct_u232.c b/drivers/usb/serial/mct_u232.c
index 06d5a60be2c4..3353c9ed7721 100644
--- a/drivers/usb/serial/mct_u232.c
+++ b/drivers/usb/serial/mct_u232.c
@@ -35,7 +35,6 @@
35#include <linux/usb.h> 35#include <linux/usb.h>
36#include <linux/usb/serial.h> 36#include <linux/usb/serial.h>
37#include <linux/serial.h> 37#include <linux/serial.h>
38#include <linux/ioctl.h>
39#include "mct_u232.h" 38#include "mct_u232.h"
40 39
41#define DRIVER_AUTHOR "Wolfgang Grandegger <wolfgang@ces.ch>" 40#define DRIVER_AUTHOR "Wolfgang Grandegger <wolfgang@ces.ch>"
@@ -57,10 +56,6 @@ static void mct_u232_break_ctl(struct tty_struct *tty, int break_state);
57static int mct_u232_tiocmget(struct tty_struct *tty); 56static int mct_u232_tiocmget(struct tty_struct *tty);
58static int mct_u232_tiocmset(struct tty_struct *tty, 57static int mct_u232_tiocmset(struct tty_struct *tty,
59 unsigned int set, unsigned int clear); 58 unsigned int set, unsigned int clear);
60static int mct_u232_ioctl(struct tty_struct *tty,
61 unsigned int cmd, unsigned long arg);
62static int mct_u232_get_icount(struct tty_struct *tty,
63 struct serial_icounter_struct *icount);
64static void mct_u232_throttle(struct tty_struct *tty); 59static void mct_u232_throttle(struct tty_struct *tty);
65static void mct_u232_unthrottle(struct tty_struct *tty); 60static void mct_u232_unthrottle(struct tty_struct *tty);
66 61
@@ -95,11 +90,11 @@ static struct usb_serial_driver mct_u232_device = {
95 .break_ctl = mct_u232_break_ctl, 90 .break_ctl = mct_u232_break_ctl,
96 .tiocmget = mct_u232_tiocmget, 91 .tiocmget = mct_u232_tiocmget,
97 .tiocmset = mct_u232_tiocmset, 92 .tiocmset = mct_u232_tiocmset,
93 .tiocmiwait = usb_serial_generic_tiocmiwait,
98 .attach = mct_u232_startup, 94 .attach = mct_u232_startup,
99 .port_probe = mct_u232_port_probe, 95 .port_probe = mct_u232_port_probe,
100 .port_remove = mct_u232_port_remove, 96 .port_remove = mct_u232_port_remove,
101 .ioctl = mct_u232_ioctl, 97 .get_icount = usb_serial_generic_get_icount,
102 .get_icount = mct_u232_get_icount,
103}; 98};
104 99
105static struct usb_serial_driver * const serial_drivers[] = { 100static struct usb_serial_driver * const serial_drivers[] = {
@@ -113,7 +108,6 @@ struct mct_u232_private {
113 unsigned char last_lsr; /* Line Status Register */ 108 unsigned char last_lsr; /* Line Status Register */
114 unsigned char last_msr; /* Modem Status Register */ 109 unsigned char last_msr; /* Modem Status Register */
115 unsigned int rx_flags; /* Throttling flags */ 110 unsigned int rx_flags; /* Throttling flags */
116 struct async_icount icount;
117}; 111};
118 112
119#define THROTTLED 0x01 113#define THROTTLED 0x01
@@ -570,7 +564,7 @@ static void mct_u232_read_int_callback(struct urb *urb)
570 /* Record Control Line states */ 564 /* Record Control Line states */
571 mct_u232_msr_to_state(port, &priv->control_state, priv->last_msr); 565 mct_u232_msr_to_state(port, &priv->control_state, priv->last_msr);
572 566
573 mct_u232_msr_to_icount(&priv->icount, priv->last_msr); 567 mct_u232_msr_to_icount(&port->icount, priv->last_msr);
574 568
575#if 0 569#if 0
576 /* Not yet handled. See belkin_sa.c for further information */ 570 /* Not yet handled. See belkin_sa.c for further information */
@@ -598,7 +592,7 @@ static void mct_u232_read_int_callback(struct urb *urb)
598 tty_kref_put(tty); 592 tty_kref_put(tty);
599 } 593 }
600#endif 594#endif
601 wake_up_interruptible(&port->delta_msr_wait); 595 wake_up_interruptible(&port->port.delta_msr_wait);
602 spin_unlock_irqrestore(&priv->lock, flags); 596 spin_unlock_irqrestore(&priv->lock, flags);
603exit: 597exit:
604 retval = usb_submit_urb(urb, GFP_ATOMIC); 598 retval = usb_submit_urb(urb, GFP_ATOMIC);
@@ -786,86 +780,6 @@ static void mct_u232_unthrottle(struct tty_struct *tty)
786 } 780 }
787} 781}
788 782
789static int mct_u232_ioctl(struct tty_struct *tty,
790 unsigned int cmd, unsigned long arg)
791{
792 DEFINE_WAIT(wait);
793 struct usb_serial_port *port = tty->driver_data;
794 struct mct_u232_private *mct_u232_port = usb_get_serial_port_data(port);
795 struct async_icount cnow, cprev;
796 unsigned long flags;
797
798 dev_dbg(&port->dev, "%s - cmd = 0x%x\n", __func__, cmd);
799
800 switch (cmd) {
801
802 case TIOCMIWAIT:
803
804 dev_dbg(&port->dev, "%s TIOCMIWAIT", __func__);
805
806 spin_lock_irqsave(&mct_u232_port->lock, flags);
807 cprev = mct_u232_port->icount;
808 spin_unlock_irqrestore(&mct_u232_port->lock, flags);
809 for ( ; ; ) {
810 prepare_to_wait(&port->delta_msr_wait,
811 &wait, TASK_INTERRUPTIBLE);
812 schedule();
813 finish_wait(&port->delta_msr_wait, &wait);
814 /* see if a signal did it */
815 if (signal_pending(current))
816 return -ERESTARTSYS;
817
818 if (port->serial->disconnected)
819 return -EIO;
820
821 spin_lock_irqsave(&mct_u232_port->lock, flags);
822 cnow = mct_u232_port->icount;
823 spin_unlock_irqrestore(&mct_u232_port->lock, flags);
824 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
825 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
826 return -EIO; /* no change => error */
827 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
828 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
829 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
830 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
831 return 0;
832 }
833 cprev = cnow;
834 }
835
836 }
837 return -ENOIOCTLCMD;
838}
839
840static int mct_u232_get_icount(struct tty_struct *tty,
841 struct serial_icounter_struct *icount)
842{
843 struct usb_serial_port *port = tty->driver_data;
844 struct mct_u232_private *mct_u232_port = usb_get_serial_port_data(port);
845 struct async_icount *ic = &mct_u232_port->icount;
846 unsigned long flags;
847
848 spin_lock_irqsave(&mct_u232_port->lock, flags);
849
850 icount->cts = ic->cts;
851 icount->dsr = ic->dsr;
852 icount->rng = ic->rng;
853 icount->dcd = ic->dcd;
854 icount->rx = ic->rx;
855 icount->tx = ic->tx;
856 icount->frame = ic->frame;
857 icount->overrun = ic->overrun;
858 icount->parity = ic->parity;
859 icount->brk = ic->brk;
860 icount->buf_overrun = ic->buf_overrun;
861
862 spin_unlock_irqrestore(&mct_u232_port->lock, flags);
863
864 dev_dbg(&port->dev, "%s TIOCGICOUNT RX=%d, TX=%d\n",
865 __func__, icount->rx, icount->tx);
866 return 0;
867}
868
869module_usb_serial_driver(serial_drivers, id_table); 783module_usb_serial_driver(serial_drivers, id_table);
870 784
871MODULE_AUTHOR(DRIVER_AUTHOR); 785MODULE_AUTHOR(DRIVER_AUTHOR);
diff --git a/drivers/usb/serial/metro-usb.c b/drivers/usb/serial/metro-usb.c
index bf3c7a23553e..47e247759eb0 100644
--- a/drivers/usb/serial/metro-usb.c
+++ b/drivers/usb/serial/metro-usb.c
@@ -177,10 +177,7 @@ static void metrousb_cleanup(struct usb_serial_port *port)
177 usb_unlink_urb(port->interrupt_in_urb); 177 usb_unlink_urb(port->interrupt_in_urb);
178 usb_kill_urb(port->interrupt_in_urb); 178 usb_kill_urb(port->interrupt_in_urb);
179 179
180 mutex_lock(&port->serial->disc_mutex); 180 metrousb_send_unidirectional_cmd(UNI_CMD_CLOSE, port);
181 if (!port->serial->disconnected)
182 metrousb_send_unidirectional_cmd(UNI_CMD_CLOSE, port);
183 mutex_unlock(&port->serial->disc_mutex);
184} 181}
185 182
186static int metrousb_open(struct tty_struct *tty, struct usb_serial_port *port) 183static int metrousb_open(struct tty_struct *tty, struct usb_serial_port *port)
diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c
index e0ebec3b5d6a..fc506bb71315 100644
--- a/drivers/usb/serial/mos7720.c
+++ b/drivers/usb/serial/mos7720.c
@@ -62,7 +62,6 @@ struct moschip_port {
62 __u8 shadowMCR; /* last MCR value received */ 62 __u8 shadowMCR; /* last MCR value received */
63 __u8 shadowMSR; /* last MSR value received */ 63 __u8 shadowMSR; /* last MSR value received */
64 char open; 64 char open;
65 struct async_icount icount;
66 struct usb_serial_port *port; /* loop back to the owner */ 65 struct usb_serial_port *port; /* loop back to the owner */
67 struct urb *write_urb_pool[NUM_URBS]; 66 struct urb *write_urb_pool[NUM_URBS];
68}; 67};
@@ -1075,9 +1074,6 @@ static int mos7720_open(struct tty_struct *tty, struct usb_serial_port *port)
1075 dev_err(&port->dev, "%s - Error %d submitting read urb\n", 1074 dev_err(&port->dev, "%s - Error %d submitting read urb\n",
1076 __func__, response); 1075 __func__, response);
1077 1076
1078 /* initialize our icount structure */
1079 memset(&(mos7720_port->icount), 0x00, sizeof(mos7720_port->icount));
1080
1081 /* initialize our port settings */ 1077 /* initialize our port settings */
1082 mos7720_port->shadowMCR = UART_MCR_OUT2; /* Must set to enable ints! */ 1078 mos7720_port->shadowMCR = UART_MCR_OUT2; /* Must set to enable ints! */
1083 1079
@@ -1144,16 +1140,9 @@ static void mos7720_close(struct usb_serial_port *port)
1144 usb_kill_urb(port->write_urb); 1140 usb_kill_urb(port->write_urb);
1145 usb_kill_urb(port->read_urb); 1141 usb_kill_urb(port->read_urb);
1146 1142
1147 mutex_lock(&serial->disc_mutex); 1143 write_mos_reg(serial, port->number - port->serial->minor, MCR, 0x00);
1148 /* these commands must not be issued if the device has 1144 write_mos_reg(serial, port->number - port->serial->minor, IER, 0x00);
1149 * been disconnected */ 1145
1150 if (!serial->disconnected) {
1151 write_mos_reg(serial, port->number - port->serial->minor,
1152 MCR, 0x00);
1153 write_mos_reg(serial, port->number - port->serial->minor,
1154 IER, 0x00);
1155 }
1156 mutex_unlock(&serial->disc_mutex);
1157 mos7720_port->open = 0; 1146 mos7720_port->open = 0;
1158} 1147}
1159 1148
@@ -1803,33 +1792,6 @@ static int mos7720_tiocmset(struct tty_struct *tty,
1803 return 0; 1792 return 0;
1804} 1793}
1805 1794
1806static int mos7720_get_icount(struct tty_struct *tty,
1807 struct serial_icounter_struct *icount)
1808{
1809 struct usb_serial_port *port = tty->driver_data;
1810 struct moschip_port *mos7720_port;
1811 struct async_icount cnow;
1812
1813 mos7720_port = usb_get_serial_port_data(port);
1814 cnow = mos7720_port->icount;
1815
1816 icount->cts = cnow.cts;
1817 icount->dsr = cnow.dsr;
1818 icount->rng = cnow.rng;
1819 icount->dcd = cnow.dcd;
1820 icount->rx = cnow.rx;
1821 icount->tx = cnow.tx;
1822 icount->frame = cnow.frame;
1823 icount->overrun = cnow.overrun;
1824 icount->parity = cnow.parity;
1825 icount->brk = cnow.brk;
1826 icount->buf_overrun = cnow.buf_overrun;
1827
1828 dev_dbg(&port->dev, "%s TIOCGICOUNT RX=%d, TX=%d\n", __func__,
1829 icount->rx, icount->tx);
1830 return 0;
1831}
1832
1833static int set_modem_info(struct moschip_port *mos7720_port, unsigned int cmd, 1795static int set_modem_info(struct moschip_port *mos7720_port, unsigned int cmd,
1834 unsigned int __user *value) 1796 unsigned int __user *value)
1835{ 1797{
@@ -1905,8 +1867,6 @@ static int mos7720_ioctl(struct tty_struct *tty,
1905{ 1867{
1906 struct usb_serial_port *port = tty->driver_data; 1868 struct usb_serial_port *port = tty->driver_data;
1907 struct moschip_port *mos7720_port; 1869 struct moschip_port *mos7720_port;
1908 struct async_icount cnow;
1909 struct async_icount cprev;
1910 1870
1911 mos7720_port = usb_get_serial_port_data(port); 1871 mos7720_port = usb_get_serial_port_data(port);
1912 if (mos7720_port == NULL) 1872 if (mos7720_port == NULL)
@@ -1931,27 +1891,6 @@ static int mos7720_ioctl(struct tty_struct *tty,
1931 dev_dbg(&port->dev, "%s TIOCGSERIAL\n", __func__); 1891 dev_dbg(&port->dev, "%s TIOCGSERIAL\n", __func__);
1932 return get_serial_info(mos7720_port, 1892 return get_serial_info(mos7720_port,
1933 (struct serial_struct __user *)arg); 1893 (struct serial_struct __user *)arg);
1934
1935 case TIOCMIWAIT:
1936 dev_dbg(&port->dev, "%s TIOCMIWAIT\n", __func__);
1937 cprev = mos7720_port->icount;
1938 while (1) {
1939 if (signal_pending(current))
1940 return -ERESTARTSYS;
1941 cnow = mos7720_port->icount;
1942 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
1943 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
1944 return -EIO; /* no change => error */
1945 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
1946 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
1947 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
1948 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
1949 return 0;
1950 }
1951 cprev = cnow;
1952 }
1953 /* NOTREACHED */
1954 break;
1955 } 1894 }
1956 1895
1957 return -ENOIOCTLCMD; 1896 return -ENOIOCTLCMD;
@@ -2107,7 +2046,6 @@ static struct usb_serial_driver moschip7720_2port_driver = {
2107 .ioctl = mos7720_ioctl, 2046 .ioctl = mos7720_ioctl,
2108 .tiocmget = mos7720_tiocmget, 2047 .tiocmget = mos7720_tiocmget,
2109 .tiocmset = mos7720_tiocmset, 2048 .tiocmset = mos7720_tiocmset,
2110 .get_icount = mos7720_get_icount,
2111 .set_termios = mos7720_set_termios, 2049 .set_termios = mos7720_set_termios,
2112 .write = mos7720_write, 2050 .write = mos7720_write,
2113 .write_room = mos7720_write_room, 2051 .write_room = mos7720_write_room,
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index b8051fa61911..f0b4e5c01e13 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -219,8 +219,6 @@ struct moschip_port {
219 char open; 219 char open;
220 char open_ports; 220 char open_ports;
221 wait_queue_head_t wait_chase; /* for handling sleeping while waiting for chase to finish */ 221 wait_queue_head_t wait_chase; /* for handling sleeping while waiting for chase to finish */
222 int delta_msr_cond;
223 struct async_icount icount;
224 struct usb_serial_port *port; /* loop back to the owner of this object */ 222 struct usb_serial_port *port; /* loop back to the owner of this object */
225 223
226 /* Offsets */ 224 /* Offsets */
@@ -399,32 +397,22 @@ static void mos7840_handle_new_msr(struct moschip_port *port, __u8 new_msr)
399 struct moschip_port *mos7840_port; 397 struct moschip_port *mos7840_port;
400 struct async_icount *icount; 398 struct async_icount *icount;
401 mos7840_port = port; 399 mos7840_port = port;
402 icount = &mos7840_port->icount;
403 if (new_msr & 400 if (new_msr &
404 (MOS_MSR_DELTA_CTS | MOS_MSR_DELTA_DSR | MOS_MSR_DELTA_RI | 401 (MOS_MSR_DELTA_CTS | MOS_MSR_DELTA_DSR | MOS_MSR_DELTA_RI |
405 MOS_MSR_DELTA_CD)) { 402 MOS_MSR_DELTA_CD)) {
406 icount = &mos7840_port->icount; 403 icount = &mos7840_port->port->icount;
407 404
408 /* update input line counters */ 405 /* update input line counters */
409 if (new_msr & MOS_MSR_DELTA_CTS) { 406 if (new_msr & MOS_MSR_DELTA_CTS)
410 icount->cts++; 407 icount->cts++;
411 smp_wmb(); 408 if (new_msr & MOS_MSR_DELTA_DSR)
412 }
413 if (new_msr & MOS_MSR_DELTA_DSR) {
414 icount->dsr++; 409 icount->dsr++;
415 smp_wmb(); 410 if (new_msr & MOS_MSR_DELTA_CD)
416 }
417 if (new_msr & MOS_MSR_DELTA_CD) {
418 icount->dcd++; 411 icount->dcd++;
419 smp_wmb(); 412 if (new_msr & MOS_MSR_DELTA_RI)
420 }
421 if (new_msr & MOS_MSR_DELTA_RI) {
422 icount->rng++; 413 icount->rng++;
423 smp_wmb();
424 }
425 414
426 mos7840_port->delta_msr_cond = 1; 415 wake_up_interruptible(&port->port->port.delta_msr_wait);
427 wake_up_interruptible(&port->port->delta_msr_wait);
428 } 416 }
429} 417}
430 418
@@ -442,23 +430,15 @@ static void mos7840_handle_new_lsr(struct moschip_port *port, __u8 new_lsr)
442 } 430 }
443 431
444 /* update input line counters */ 432 /* update input line counters */
445 icount = &port->icount; 433 icount = &port->port->icount;
446 if (new_lsr & SERIAL_LSR_BI) { 434 if (new_lsr & SERIAL_LSR_BI)
447 icount->brk++; 435 icount->brk++;
448 smp_wmb(); 436 if (new_lsr & SERIAL_LSR_OE)
449 }
450 if (new_lsr & SERIAL_LSR_OE) {
451 icount->overrun++; 437 icount->overrun++;
452 smp_wmb(); 438 if (new_lsr & SERIAL_LSR_PE)
453 }
454 if (new_lsr & SERIAL_LSR_PE) {
455 icount->parity++; 439 icount->parity++;
456 smp_wmb(); 440 if (new_lsr & SERIAL_LSR_FE)
457 }
458 if (new_lsr & SERIAL_LSR_FE) {
459 icount->frame++; 441 icount->frame++;
460 smp_wmb();
461 }
462} 442}
463 443
464/************************************************************************/ 444/************************************************************************/
@@ -777,9 +757,8 @@ static void mos7840_bulk_in_callback(struct urb *urb)
777 struct tty_port *tport = &mos7840_port->port->port; 757 struct tty_port *tport = &mos7840_port->port->port;
778 tty_insert_flip_string(tport, data, urb->actual_length); 758 tty_insert_flip_string(tport, data, urb->actual_length);
779 tty_flip_buffer_push(tport); 759 tty_flip_buffer_push(tport);
780 mos7840_port->icount.rx += urb->actual_length; 760 port->icount.rx += urb->actual_length;
781 smp_wmb(); 761 dev_dbg(&port->dev, "icount.rx is %d:\n", port->icount.rx);
782 dev_dbg(&port->dev, "mos7840_port->icount.rx is %d:\n", mos7840_port->icount.rx);
783 } 762 }
784 763
785 if (!mos7840_port->read_urb) { 764 if (!mos7840_port->read_urb) {
@@ -1130,17 +1109,12 @@ static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port)
1130 /* initialize our wait queues */ 1109 /* initialize our wait queues */
1131 init_waitqueue_head(&mos7840_port->wait_chase); 1110 init_waitqueue_head(&mos7840_port->wait_chase);
1132 1111
1133 /* initialize our icount structure */
1134 memset(&(mos7840_port->icount), 0x00, sizeof(mos7840_port->icount));
1135
1136 /* initialize our port settings */ 1112 /* initialize our port settings */
1137 /* Must set to enable ints! */ 1113 /* Must set to enable ints! */
1138 mos7840_port->shadowMCR = MCR_MASTER_IE; 1114 mos7840_port->shadowMCR = MCR_MASTER_IE;
1139 /* send a open port command */ 1115 /* send a open port command */
1140 mos7840_port->open = 1; 1116 mos7840_port->open = 1;
1141 /* mos7840_change_port_settings(mos7840_port,old_termios); */ 1117 /* mos7840_change_port_settings(mos7840_port,old_termios); */
1142 mos7840_port->icount.tx = 0;
1143 mos7840_port->icount.rx = 0;
1144 1118
1145 return 0; 1119 return 0;
1146} 1120}
@@ -1223,25 +1197,10 @@ static void mos7840_close(struct usb_serial_port *port)
1223 } 1197 }
1224 } 1198 }
1225 1199
1226 /* While closing port, shutdown all bulk read, write * 1200 usb_kill_urb(mos7840_port->write_urb);
1227 * and interrupt read if they exists */ 1201 usb_kill_urb(mos7840_port->read_urb);
1228 if (serial->dev) { 1202 mos7840_port->read_urb_busy = false;
1229 if (mos7840_port->write_urb) { 1203
1230 dev_dbg(&port->dev, "%s", "Shutdown bulk write\n");
1231 usb_kill_urb(mos7840_port->write_urb);
1232 }
1233 if (mos7840_port->read_urb) {
1234 dev_dbg(&port->dev, "%s", "Shutdown bulk read\n");
1235 usb_kill_urb(mos7840_port->read_urb);
1236 mos7840_port->read_urb_busy = false;
1237 }
1238 if ((&mos7840_port->control_urb)) {
1239 dev_dbg(&port->dev, "%s", "Shutdown control read\n");
1240 /*/ usb_kill_urb (mos7840_port->control_urb); */
1241 }
1242 }
1243/* if(mos7840_port->ctrl_buf != NULL) */
1244/* kfree(mos7840_port->ctrl_buf); */
1245 port0->open_ports--; 1204 port0->open_ports--;
1246 dev_dbg(&port->dev, "%s in close%d:in port%d\n", __func__, port0->open_ports, port->number); 1205 dev_dbg(&port->dev, "%s in close%d:in port%d\n", __func__, port0->open_ports, port->number);
1247 if (port0->open_ports == 0) { 1206 if (port0->open_ports == 0) {
@@ -1253,8 +1212,7 @@ static void mos7840_close(struct usb_serial_port *port)
1253 1212
1254 if (mos7840_port->write_urb) { 1213 if (mos7840_port->write_urb) {
1255 /* if this urb had a transfer buffer already (old tx) free it */ 1214 /* if this urb had a transfer buffer already (old tx) free it */
1256 if (mos7840_port->write_urb->transfer_buffer != NULL) 1215 kfree(mos7840_port->write_urb->transfer_buffer);
1257 kfree(mos7840_port->write_urb->transfer_buffer);
1258 usb_free_urb(mos7840_port->write_urb); 1216 usb_free_urb(mos7840_port->write_urb);
1259 } 1217 }
1260 1218
@@ -1331,9 +1289,8 @@ static void mos7840_break(struct tty_struct *tty, int break_state)
1331 if (mos7840_port == NULL) 1289 if (mos7840_port == NULL)
1332 return; 1290 return;
1333 1291
1334 if (serial->dev) 1292 /* flush and block until tx is empty */
1335 /* flush and block until tx is empty */ 1293 mos7840_block_until_chase_response(tty, mos7840_port);
1336 mos7840_block_until_chase_response(tty, mos7840_port);
1337 1294
1338 if (break_state == -1) 1295 if (break_state == -1)
1339 data = mos7840_port->shadowLCR | LCR_SET_BREAK; 1296 data = mos7840_port->shadowLCR | LCR_SET_BREAK;
@@ -1523,9 +1480,8 @@ static int mos7840_write(struct tty_struct *tty, struct usb_serial_port *port,
1523 goto exit; 1480 goto exit;
1524 } 1481 }
1525 bytes_sent = transfer_size; 1482 bytes_sent = transfer_size;
1526 mos7840_port->icount.tx += transfer_size; 1483 port->icount.tx += transfer_size;
1527 smp_wmb(); 1484 dev_dbg(&port->dev, "icount.tx is %d:\n", port->icount.tx);
1528 dev_dbg(&port->dev, "mos7840_port->icount.tx is %d:\n", mos7840_port->icount.tx);
1529exit: 1485exit:
1530 return bytes_sent; 1486 return bytes_sent;
1531 1487
@@ -2144,34 +2100,6 @@ static int mos7840_get_serial_info(struct moschip_port *mos7840_port,
2144 return 0; 2100 return 0;
2145} 2101}
2146 2102
2147static int mos7840_get_icount(struct tty_struct *tty,
2148 struct serial_icounter_struct *icount)
2149{
2150 struct usb_serial_port *port = tty->driver_data;
2151 struct moschip_port *mos7840_port;
2152 struct async_icount cnow;
2153
2154 mos7840_port = mos7840_get_port_private(port);
2155 cnow = mos7840_port->icount;
2156
2157 smp_rmb();
2158 icount->cts = cnow.cts;
2159 icount->dsr = cnow.dsr;
2160 icount->rng = cnow.rng;
2161 icount->dcd = cnow.dcd;
2162 icount->rx = cnow.rx;
2163 icount->tx = cnow.tx;
2164 icount->frame = cnow.frame;
2165 icount->overrun = cnow.overrun;
2166 icount->parity = cnow.parity;
2167 icount->brk = cnow.brk;
2168 icount->buf_overrun = cnow.buf_overrun;
2169
2170 dev_dbg(&port->dev, "%s TIOCGICOUNT RX=%d, TX=%d\n", __func__,
2171 icount->rx, icount->tx);
2172 return 0;
2173}
2174
2175/***************************************************************************** 2103/*****************************************************************************
2176 * SerialIoctl 2104 * SerialIoctl
2177 * this function handles any ioctl calls to the driver 2105 * this function handles any ioctl calls to the driver
@@ -2184,9 +2112,6 @@ static int mos7840_ioctl(struct tty_struct *tty,
2184 void __user *argp = (void __user *)arg; 2112 void __user *argp = (void __user *)arg;
2185 struct moschip_port *mos7840_port; 2113 struct moschip_port *mos7840_port;
2186 2114
2187 struct async_icount cnow;
2188 struct async_icount cprev;
2189
2190 if (mos7840_port_paranoia_check(port, __func__)) 2115 if (mos7840_port_paranoia_check(port, __func__))
2191 return -1; 2116 return -1;
2192 2117
@@ -2211,41 +2136,6 @@ static int mos7840_ioctl(struct tty_struct *tty,
2211 case TIOCSSERIAL: 2136 case TIOCSSERIAL:
2212 dev_dbg(&port->dev, "%s TIOCSSERIAL\n", __func__); 2137 dev_dbg(&port->dev, "%s TIOCSSERIAL\n", __func__);
2213 break; 2138 break;
2214
2215 case TIOCMIWAIT:
2216 dev_dbg(&port->dev, "%s TIOCMIWAIT\n", __func__);
2217 cprev = mos7840_port->icount;
2218 while (1) {
2219 /* interruptible_sleep_on(&mos7840_port->delta_msr_wait); */
2220 mos7840_port->delta_msr_cond = 0;
2221 wait_event_interruptible(port->delta_msr_wait,
2222 (port->serial->disconnected ||
2223 mos7840_port->
2224 delta_msr_cond == 1));
2225
2226 /* see if a signal did it */
2227 if (signal_pending(current))
2228 return -ERESTARTSYS;
2229
2230 if (port->serial->disconnected)
2231 return -EIO;
2232
2233 cnow = mos7840_port->icount;
2234 smp_rmb();
2235 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2236 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
2237 return -EIO; /* no change => error */
2238 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
2239 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
2240 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
2241 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
2242 return 0;
2243 }
2244 cprev = cnow;
2245 }
2246 /* NOTREACHED */
2247 break;
2248
2249 default: 2139 default:
2250 break; 2140 break;
2251 } 2141 }
@@ -2592,7 +2482,8 @@ static struct usb_serial_driver moschip7840_4port_device = {
2592 .break_ctl = mos7840_break, 2482 .break_ctl = mos7840_break,
2593 .tiocmget = mos7840_tiocmget, 2483 .tiocmget = mos7840_tiocmget,
2594 .tiocmset = mos7840_tiocmset, 2484 .tiocmset = mos7840_tiocmset,
2595 .get_icount = mos7840_get_icount, 2485 .tiocmiwait = usb_serial_generic_tiocmiwait,
2486 .get_icount = usb_serial_generic_get_icount,
2596 .port_probe = mos7840_port_probe, 2487 .port_probe = mos7840_port_probe,
2597 .port_remove = mos7840_port_remove, 2488 .port_remove = mos7840_port_remove,
2598 .read_bulk_callback = mos7840_bulk_in_callback, 2489 .read_bulk_callback = mos7840_bulk_in_callback,
diff --git a/drivers/usb/serial/opticon.c b/drivers/usb/serial/opticon.c
index e13e1a4d3e1e..5f4b0cd0f6e9 100644
--- a/drivers/usb/serial/opticon.c
+++ b/drivers/usb/serial/opticon.c
@@ -120,7 +120,10 @@ static int send_control_msg(struct usb_serial_port *port, u8 requesttype,
120 0, 0, buffer, 1, 0); 120 0, 0, buffer, 1, 0);
121 kfree(buffer); 121 kfree(buffer);
122 122
123 return retval; 123 if (retval < 0)
124 return retval;
125
126 return 0;
124} 127}
125 128
126static int opticon_open(struct tty_struct *tty, struct usb_serial_port *port) 129static int opticon_open(struct tty_struct *tty, struct usb_serial_port *port)
@@ -306,7 +309,6 @@ static int opticon_tiocmset(struct tty_struct *tty,
306 unsigned int set, unsigned int clear) 309 unsigned int set, unsigned int clear)
307{ 310{
308 struct usb_serial_port *port = tty->driver_data; 311 struct usb_serial_port *port = tty->driver_data;
309 struct usb_serial *serial = port->serial;
310 struct opticon_private *priv = usb_get_serial_port_data(port); 312 struct opticon_private *priv = usb_get_serial_port_data(port);
311 unsigned long flags; 313 unsigned long flags;
312 bool rts; 314 bool rts;
@@ -327,15 +329,11 @@ static int opticon_tiocmset(struct tty_struct *tty,
327 if (!changed) 329 if (!changed)
328 return 0; 330 return 0;
329 331
330 /* Send the new RTS state to the connected device */ 332 ret = send_control_msg(port, CONTROL_RTS, !rts);
331 mutex_lock(&serial->disc_mutex); 333 if (ret)
332 if (!serial->disconnected) 334 return usb_translate_errors(ret);
333 ret = send_control_msg(port, CONTROL_RTS, !rts);
334 else
335 ret = -ENODEV;
336 mutex_unlock(&serial->disc_mutex);
337 335
338 return ret; 336 return 0;
339} 337}
340 338
341static int get_serial_info(struct usb_serial_port *port, 339static int get_serial_info(struct usb_serial_port *port,
diff --git a/drivers/usb/serial/oti6858.c b/drivers/usb/serial/oti6858.c
index 87c71ccfee87..7e3e0782e51f 100644
--- a/drivers/usb/serial/oti6858.c
+++ b/drivers/usb/serial/oti6858.c
@@ -124,8 +124,6 @@ static void oti6858_close(struct usb_serial_port *port);
124static void oti6858_set_termios(struct tty_struct *tty, 124static void oti6858_set_termios(struct tty_struct *tty,
125 struct usb_serial_port *port, struct ktermios *old); 125 struct usb_serial_port *port, struct ktermios *old);
126static void oti6858_init_termios(struct tty_struct *tty); 126static void oti6858_init_termios(struct tty_struct *tty);
127static int oti6858_ioctl(struct tty_struct *tty,
128 unsigned int cmd, unsigned long arg);
129static void oti6858_read_int_callback(struct urb *urb); 127static void oti6858_read_int_callback(struct urb *urb);
130static void oti6858_read_bulk_callback(struct urb *urb); 128static void oti6858_read_bulk_callback(struct urb *urb);
131static void oti6858_write_bulk_callback(struct urb *urb); 129static void oti6858_write_bulk_callback(struct urb *urb);
@@ -136,6 +134,7 @@ static int oti6858_chars_in_buffer(struct tty_struct *tty);
136static int oti6858_tiocmget(struct tty_struct *tty); 134static int oti6858_tiocmget(struct tty_struct *tty);
137static int oti6858_tiocmset(struct tty_struct *tty, 135static int oti6858_tiocmset(struct tty_struct *tty,
138 unsigned int set, unsigned int clear); 136 unsigned int set, unsigned int clear);
137static int oti6858_tiocmiwait(struct tty_struct *tty, unsigned long arg);
139static int oti6858_port_probe(struct usb_serial_port *port); 138static int oti6858_port_probe(struct usb_serial_port *port);
140static int oti6858_port_remove(struct usb_serial_port *port); 139static int oti6858_port_remove(struct usb_serial_port *port);
141 140
@@ -150,11 +149,11 @@ static struct usb_serial_driver oti6858_device = {
150 .open = oti6858_open, 149 .open = oti6858_open,
151 .close = oti6858_close, 150 .close = oti6858_close,
152 .write = oti6858_write, 151 .write = oti6858_write,
153 .ioctl = oti6858_ioctl,
154 .set_termios = oti6858_set_termios, 152 .set_termios = oti6858_set_termios,
155 .init_termios = oti6858_init_termios, 153 .init_termios = oti6858_init_termios,
156 .tiocmget = oti6858_tiocmget, 154 .tiocmget = oti6858_tiocmget,
157 .tiocmset = oti6858_tiocmset, 155 .tiocmset = oti6858_tiocmset,
156 .tiocmiwait = oti6858_tiocmiwait,
158 .read_bulk_callback = oti6858_read_bulk_callback, 157 .read_bulk_callback = oti6858_read_bulk_callback,
159 .read_int_callback = oti6858_read_int_callback, 158 .read_int_callback = oti6858_read_int_callback,
160 .write_bulk_callback = oti6858_write_bulk_callback, 159 .write_bulk_callback = oti6858_write_bulk_callback,
@@ -650,8 +649,9 @@ static int oti6858_tiocmget(struct tty_struct *tty)
650 return result; 649 return result;
651} 650}
652 651
653static int wait_modem_info(struct usb_serial_port *port, unsigned int arg) 652static int oti6858_tiocmiwait(struct tty_struct *tty, unsigned long arg)
654{ 653{
654 struct usb_serial_port *port = tty->driver_data;
655 struct oti6858_private *priv = usb_get_serial_port_data(port); 655 struct oti6858_private *priv = usb_get_serial_port_data(port);
656 unsigned long flags; 656 unsigned long flags;
657 unsigned int prev, status; 657 unsigned int prev, status;
@@ -662,7 +662,7 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
662 spin_unlock_irqrestore(&priv->lock, flags); 662 spin_unlock_irqrestore(&priv->lock, flags);
663 663
664 while (1) { 664 while (1) {
665 wait_event_interruptible(port->delta_msr_wait, 665 wait_event_interruptible(port->port.delta_msr_wait,
666 port->serial->disconnected || 666 port->serial->disconnected ||
667 priv->status.pin_state != prev); 667 priv->status.pin_state != prev);
668 if (signal_pending(current)) 668 if (signal_pending(current))
@@ -689,24 +689,6 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
689 return 0; 689 return 0;
690} 690}
691 691
692static int oti6858_ioctl(struct tty_struct *tty,
693 unsigned int cmd, unsigned long arg)
694{
695 struct usb_serial_port *port = tty->driver_data;
696
697 dev_dbg(&port->dev, "%s(cmd = 0x%04x, arg = 0x%08lx)\n", __func__, cmd, arg);
698
699 switch (cmd) {
700 case TIOCMIWAIT:
701 dev_dbg(&port->dev, "%s(): TIOCMIWAIT\n", __func__);
702 return wait_modem_info(port, arg);
703 default:
704 dev_dbg(&port->dev, "%s(): 0x%04x not supported\n", __func__, cmd);
705 break;
706 }
707 return -ENOIOCTLCMD;
708}
709
710static void oti6858_read_int_callback(struct urb *urb) 692static void oti6858_read_int_callback(struct urb *urb)
711{ 693{
712 struct usb_serial_port *port = urb->context; 694 struct usb_serial_port *port = urb->context;
@@ -765,7 +747,7 @@ static void oti6858_read_int_callback(struct urb *urb)
765 747
766 if (!priv->transient) { 748 if (!priv->transient) {
767 if (xs->pin_state != priv->status.pin_state) 749 if (xs->pin_state != priv->status.pin_state)
768 wake_up_interruptible(&port->delta_msr_wait); 750 wake_up_interruptible(&port->port.delta_msr_wait);
769 memcpy(&priv->status, xs, OTI6858_CTRL_PKT_SIZE); 751 memcpy(&priv->status, xs, OTI6858_CTRL_PKT_SIZE);
770 } 752 }
771 753
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index 3b10018d89a3..7151659367a0 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -149,7 +149,7 @@ static int pl2303_vendor_read(__u16 value, __u16 index,
149 int res = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 149 int res = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
150 VENDOR_READ_REQUEST, VENDOR_READ_REQUEST_TYPE, 150 VENDOR_READ_REQUEST, VENDOR_READ_REQUEST_TYPE,
151 value, index, buf, 1, 100); 151 value, index, buf, 1, 100);
152 dev_dbg(&serial->dev->dev, "0x%x:0x%x:0x%x:0x%x %d - %x\n", 152 dev_dbg(&serial->interface->dev, "0x%x:0x%x:0x%x:0x%x %d - %x\n",
153 VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, value, index, 153 VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, value, index,
154 res, buf[0]); 154 res, buf[0]);
155 return res; 155 return res;
@@ -161,7 +161,7 @@ static int pl2303_vendor_write(__u16 value, __u16 index,
161 int res = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 161 int res = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
162 VENDOR_WRITE_REQUEST, VENDOR_WRITE_REQUEST_TYPE, 162 VENDOR_WRITE_REQUEST, VENDOR_WRITE_REQUEST_TYPE,
163 value, index, NULL, 0, 100); 163 value, index, NULL, 0, 100);
164 dev_dbg(&serial->dev->dev, "0x%x:0x%x:0x%x:0x%x %d\n", 164 dev_dbg(&serial->interface->dev, "0x%x:0x%x:0x%x:0x%x %d\n",
165 VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, value, index, 165 VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, value, index,
166 res); 166 res);
167 return res; 167 return res;
@@ -248,14 +248,15 @@ static int pl2303_port_remove(struct usb_serial_port *port)
248 return 0; 248 return 0;
249} 249}
250 250
251static int set_control_lines(struct usb_device *dev, u8 value) 251static int pl2303_set_control_lines(struct usb_serial_port *port, u8 value)
252{ 252{
253 struct usb_device *dev = port->serial->dev;
253 int retval; 254 int retval;
254 255
255 retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 256 retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
256 SET_CONTROL_REQUEST, SET_CONTROL_REQUEST_TYPE, 257 SET_CONTROL_REQUEST, SET_CONTROL_REQUEST_TYPE,
257 value, 0, NULL, 0, 100); 258 value, 0, NULL, 0, 100);
258 dev_dbg(&dev->dev, "%s - value = %d, retval = %d\n", __func__, 259 dev_dbg(&port->dev, "%s - value = %d, retval = %d\n", __func__,
259 value, retval); 260 value, retval);
260 return retval; 261 return retval;
261} 262}
@@ -437,7 +438,7 @@ static void pl2303_set_termios(struct tty_struct *tty,
437 if (control != priv->line_control) { 438 if (control != priv->line_control) {
438 control = priv->line_control; 439 control = priv->line_control;
439 spin_unlock_irqrestore(&priv->lock, flags); 440 spin_unlock_irqrestore(&priv->lock, flags);
440 set_control_lines(serial->dev, control); 441 pl2303_set_control_lines(port, control);
441 } else { 442 } else {
442 spin_unlock_irqrestore(&priv->lock, flags); 443 spin_unlock_irqrestore(&priv->lock, flags);
443 } 444 }
@@ -480,7 +481,7 @@ static void pl2303_dtr_rts(struct usb_serial_port *port, int on)
480 priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS); 481 priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS);
481 control = priv->line_control; 482 control = priv->line_control;
482 spin_unlock_irqrestore(&priv->lock, flags); 483 spin_unlock_irqrestore(&priv->lock, flags);
483 set_control_lines(port->serial->dev, control); 484 pl2303_set_control_lines(port, control);
484} 485}
485 486
486static void pl2303_close(struct usb_serial_port *port) 487static void pl2303_close(struct usb_serial_port *port)
@@ -530,7 +531,6 @@ static int pl2303_tiocmset(struct tty_struct *tty,
530 unsigned int set, unsigned int clear) 531 unsigned int set, unsigned int clear)
531{ 532{
532 struct usb_serial_port *port = tty->driver_data; 533 struct usb_serial_port *port = tty->driver_data;
533 struct usb_serial *serial = port->serial;
534 struct pl2303_private *priv = usb_get_serial_port_data(port); 534 struct pl2303_private *priv = usb_get_serial_port_data(port);
535 unsigned long flags; 535 unsigned long flags;
536 u8 control; 536 u8 control;
@@ -548,14 +548,11 @@ static int pl2303_tiocmset(struct tty_struct *tty,
548 control = priv->line_control; 548 control = priv->line_control;
549 spin_unlock_irqrestore(&priv->lock, flags); 549 spin_unlock_irqrestore(&priv->lock, flags);
550 550
551 mutex_lock(&serial->disc_mutex); 551 ret = pl2303_set_control_lines(port, control);
552 if (!serial->disconnected) 552 if (ret)
553 ret = set_control_lines(serial->dev, control); 553 return usb_translate_errors(ret);
554 else
555 ret = -ENODEV;
556 mutex_unlock(&serial->disc_mutex);
557 554
558 return ret; 555 return 0;
559} 556}
560 557
561static int pl2303_tiocmget(struct tty_struct *tty) 558static int pl2303_tiocmget(struct tty_struct *tty)
@@ -592,8 +589,9 @@ static int pl2303_carrier_raised(struct usb_serial_port *port)
592 return 0; 589 return 0;
593} 590}
594 591
595static int wait_modem_info(struct usb_serial_port *port, unsigned int arg) 592static int pl2303_tiocmiwait(struct tty_struct *tty, unsigned long arg)
596{ 593{
594 struct usb_serial_port *port = tty->driver_data;
597 struct pl2303_private *priv = usb_get_serial_port_data(port); 595 struct pl2303_private *priv = usb_get_serial_port_data(port);
598 unsigned long flags; 596 unsigned long flags;
599 unsigned int prevstatus; 597 unsigned int prevstatus;
@@ -605,7 +603,7 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
605 spin_unlock_irqrestore(&priv->lock, flags); 603 spin_unlock_irqrestore(&priv->lock, flags);
606 604
607 while (1) { 605 while (1) {
608 interruptible_sleep_on(&port->delta_msr_wait); 606 interruptible_sleep_on(&port->port.delta_msr_wait);
609 /* see if a signal did it */ 607 /* see if a signal did it */
610 if (signal_pending(current)) 608 if (signal_pending(current))
611 return -ERESTARTSYS; 609 return -ERESTARTSYS;
@@ -651,10 +649,6 @@ static int pl2303_ioctl(struct tty_struct *tty,
651 return -EFAULT; 649 return -EFAULT;
652 650
653 return 0; 651 return 0;
654
655 case TIOCMIWAIT:
656 dev_dbg(&port->dev, "%s TIOCMIWAIT\n", __func__);
657 return wait_modem_info(port, arg);
658 default: 652 default:
659 dev_dbg(&port->dev, "%s not supported = 0x%04x\n", __func__, cmd); 653 dev_dbg(&port->dev, "%s not supported = 0x%04x\n", __func__, cmd);
660 break; 654 break;
@@ -720,7 +714,7 @@ static void pl2303_update_line_status(struct usb_serial_port *port,
720 spin_unlock_irqrestore(&priv->lock, flags); 714 spin_unlock_irqrestore(&priv->lock, flags);
721 if (priv->line_status & UART_BREAK_ERROR) 715 if (priv->line_status & UART_BREAK_ERROR)
722 usb_serial_handle_break(port); 716 usb_serial_handle_break(port);
723 wake_up_interruptible(&port->delta_msr_wait); 717 wake_up_interruptible(&port->port.delta_msr_wait);
724 718
725 tty = tty_port_tty_get(&port->port); 719 tty = tty_port_tty_get(&port->port);
726 if (!tty) 720 if (!tty)
@@ -784,7 +778,7 @@ static void pl2303_process_read_urb(struct urb *urb)
784 line_status = priv->line_status; 778 line_status = priv->line_status;
785 priv->line_status &= ~UART_STATE_TRANSIENT_MASK; 779 priv->line_status &= ~UART_STATE_TRANSIENT_MASK;
786 spin_unlock_irqrestore(&priv->lock, flags); 780 spin_unlock_irqrestore(&priv->lock, flags);
787 wake_up_interruptible(&port->delta_msr_wait); 781 wake_up_interruptible(&port->port.delta_msr_wait);
788 782
789 if (!urb->actual_length) 783 if (!urb->actual_length)
790 return; 784 return;
@@ -835,6 +829,7 @@ static struct usb_serial_driver pl2303_device = {
835 .set_termios = pl2303_set_termios, 829 .set_termios = pl2303_set_termios,
836 .tiocmget = pl2303_tiocmget, 830 .tiocmget = pl2303_tiocmget,
837 .tiocmset = pl2303_tiocmset, 831 .tiocmset = pl2303_tiocmset,
832 .tiocmiwait = pl2303_tiocmiwait,
838 .process_read_urb = pl2303_process_read_urb, 833 .process_read_urb = pl2303_process_read_urb,
839 .read_int_callback = pl2303_read_int_callback, 834 .read_int_callback = pl2303_read_int_callback,
840 .attach = pl2303_startup, 835 .attach = pl2303_startup,
diff --git a/drivers/usb/serial/quatech2.c b/drivers/usb/serial/quatech2.c
index 75f125ddb0c9..3c278521f7e2 100644
--- a/drivers/usb/serial/quatech2.c
+++ b/drivers/usb/serial/quatech2.c
@@ -128,8 +128,6 @@ struct qt2_port_private {
128 u8 shadowLSR; 128 u8 shadowLSR;
129 u8 shadowMSR; 129 u8 shadowMSR;
130 130
131 struct async_icount icount;
132
133 struct usb_serial_port *port; 131 struct usb_serial_port *port;
134}; 132};
135 133
@@ -424,12 +422,6 @@ static void qt2_close(struct usb_serial_port *port)
424 port_priv->urb_in_use = false; 422 port_priv->urb_in_use = false;
425 spin_unlock_irqrestore(&port_priv->urb_lock, flags); 423 spin_unlock_irqrestore(&port_priv->urb_lock, flags);
426 424
427 mutex_lock(&port->serial->disc_mutex);
428 if (port->serial->disconnected) {
429 mutex_unlock(&port->serial->disc_mutex);
430 return;
431 }
432
433 /* flush the port transmit buffer */ 425 /* flush the port transmit buffer */
434 i = usb_control_msg(serial->dev, 426 i = usb_control_msg(serial->dev,
435 usb_rcvctrlpipe(serial->dev, 0), 427 usb_rcvctrlpipe(serial->dev, 0),
@@ -460,8 +452,6 @@ static void qt2_close(struct usb_serial_port *port)
460 if (i < 0) 452 if (i < 0)
461 dev_err(&port->dev, "%s - close port failed %i\n", 453 dev_err(&port->dev, "%s - close port failed %i\n",
462 __func__, i); 454 __func__, i);
463
464 mutex_unlock(&port->serial->disc_mutex);
465} 455}
466 456
467static void qt2_disconnect(struct usb_serial *serial) 457static void qt2_disconnect(struct usb_serial *serial)
@@ -494,71 +484,6 @@ static int get_serial_info(struct usb_serial_port *port,
494 return 0; 484 return 0;
495} 485}
496 486
497static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
498{
499 struct qt2_port_private *priv = usb_get_serial_port_data(port);
500 struct async_icount prev, cur;
501 unsigned long flags;
502
503 spin_lock_irqsave(&priv->lock, flags);
504 prev = priv->icount;
505 spin_unlock_irqrestore(&priv->lock, flags);
506
507 while (1) {
508 wait_event_interruptible(port->delta_msr_wait,
509 (port->serial->disconnected ||
510 (priv->icount.rng != prev.rng) ||
511 (priv->icount.dsr != prev.dsr) ||
512 (priv->icount.dcd != prev.dcd) ||
513 (priv->icount.cts != prev.cts)));
514
515 if (signal_pending(current))
516 return -ERESTARTSYS;
517
518 if (port->serial->disconnected)
519 return -EIO;
520
521 spin_lock_irqsave(&priv->lock, flags);
522 cur = priv->icount;
523 spin_unlock_irqrestore(&priv->lock, flags);
524
525 if ((prev.rng == cur.rng) &&
526 (prev.dsr == cur.dsr) &&
527 (prev.dcd == cur.dcd) &&
528 (prev.cts == cur.cts))
529 return -EIO;
530
531 if ((arg & TIOCM_RNG && (prev.rng != cur.rng)) ||
532 (arg & TIOCM_DSR && (prev.dsr != cur.dsr)) ||
533 (arg & TIOCM_CD && (prev.dcd != cur.dcd)) ||
534 (arg & TIOCM_CTS && (prev.cts != cur.cts)))
535 return 0;
536 }
537 return 0;
538}
539
540static int qt2_get_icount(struct tty_struct *tty,
541 struct serial_icounter_struct *icount)
542{
543 struct usb_serial_port *port = tty->driver_data;
544 struct qt2_port_private *priv = usb_get_serial_port_data(port);
545 struct async_icount cnow = priv->icount;
546
547 icount->cts = cnow.cts;
548 icount->dsr = cnow.dsr;
549 icount->rng = cnow.rng;
550 icount->dcd = cnow.dcd;
551 icount->rx = cnow.rx;
552 icount->tx = cnow.tx;
553 icount->frame = cnow.frame;
554 icount->overrun = cnow.overrun;
555 icount->parity = cnow.parity;
556 icount->brk = cnow.brk;
557 icount->buf_overrun = cnow.buf_overrun;
558
559 return 0;
560}
561
562static int qt2_ioctl(struct tty_struct *tty, 487static int qt2_ioctl(struct tty_struct *tty,
563 unsigned int cmd, unsigned long arg) 488 unsigned int cmd, unsigned long arg)
564{ 489{
@@ -568,10 +493,6 @@ static int qt2_ioctl(struct tty_struct *tty,
568 case TIOCGSERIAL: 493 case TIOCGSERIAL:
569 return get_serial_info(port, 494 return get_serial_info(port,
570 (struct serial_struct __user *)arg); 495 (struct serial_struct __user *)arg);
571
572 case TIOCMIWAIT:
573 return wait_modem_info(port, arg);
574
575 default: 496 default:
576 break; 497 break;
577 } 498 }
@@ -664,9 +585,7 @@ void qt2_process_read_urb(struct urb *urb)
664 __func__); 585 __func__);
665 break; 586 break;
666 } 587 }
667 588 tty_flip_buffer_push(&port->port);
668 if (port_priv->is_open)
669 tty_flip_buffer_push(&port->port);
670 589
671 newport = *(ch + 3); 590 newport = *(ch + 3);
672 591
@@ -709,8 +628,7 @@ void qt2_process_read_urb(struct urb *urb)
709 tty_insert_flip_string(&port->port, ch, 1); 628 tty_insert_flip_string(&port->port, ch, 1);
710 } 629 }
711 630
712 if (port_priv->is_open) 631 tty_flip_buffer_push(&port->port);
713 tty_flip_buffer_push(&port->port);
714} 632}
715 633
716static void qt2_write_bulk_callback(struct urb *urb) 634static void qt2_write_bulk_callback(struct urb *urb)
@@ -961,18 +879,15 @@ static void qt2_update_msr(struct usb_serial_port *port, unsigned char *ch)
961 if (newMSR & UART_MSR_ANY_DELTA) { 879 if (newMSR & UART_MSR_ANY_DELTA) {
962 /* update input line counters */ 880 /* update input line counters */
963 if (newMSR & UART_MSR_DCTS) 881 if (newMSR & UART_MSR_DCTS)
964 port_priv->icount.cts++; 882 port->icount.cts++;
965
966 if (newMSR & UART_MSR_DDSR) 883 if (newMSR & UART_MSR_DDSR)
967 port_priv->icount.dsr++; 884 port->icount.dsr++;
968
969 if (newMSR & UART_MSR_DDCD) 885 if (newMSR & UART_MSR_DDCD)
970 port_priv->icount.dcd++; 886 port->icount.dcd++;
971
972 if (newMSR & UART_MSR_TERI) 887 if (newMSR & UART_MSR_TERI)
973 port_priv->icount.rng++; 888 port->icount.rng++;
974 889
975 wake_up_interruptible(&port->delta_msr_wait); 890 wake_up_interruptible(&port->port.delta_msr_wait);
976 } 891 }
977} 892}
978 893
@@ -992,7 +907,7 @@ static void qt2_update_lsr(struct usb_serial_port *port, unsigned char *ch)
992 port_priv->shadowLSR = newLSR; 907 port_priv->shadowLSR = newLSR;
993 spin_unlock_irqrestore(&port_priv->lock, flags); 908 spin_unlock_irqrestore(&port_priv->lock, flags);
994 909
995 icount = &port_priv->icount; 910 icount = &port->icount;
996 911
997 if (newLSR & UART_LSR_BRK_ERROR_BITS) { 912 if (newLSR & UART_LSR_BRK_ERROR_BITS) {
998 913
@@ -1102,7 +1017,8 @@ static struct usb_serial_driver qt2_device = {
1102 .break_ctl = qt2_break_ctl, 1017 .break_ctl = qt2_break_ctl,
1103 .tiocmget = qt2_tiocmget, 1018 .tiocmget = qt2_tiocmget,
1104 .tiocmset = qt2_tiocmset, 1019 .tiocmset = qt2_tiocmset,
1105 .get_icount = qt2_get_icount, 1020 .tiocmiwait = usb_serial_generic_tiocmiwait,
1021 .get_icount = usb_serial_generic_get_icount,
1106 .ioctl = qt2_ioctl, 1022 .ioctl = qt2_ioctl,
1107 .set_termios = qt2_set_termios, 1023 .set_termios = qt2_set_termios,
1108}; 1024};
diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c
index c13f6e747748..2b06481dc85c 100644
--- a/drivers/usb/serial/sierra.c
+++ b/drivers/usb/serial/sierra.c
@@ -778,30 +778,25 @@ static void sierra_close(struct usb_serial_port *port)
778 portdata->rts_state = 0; 778 portdata->rts_state = 0;
779 portdata->dtr_state = 0; 779 portdata->dtr_state = 0;
780 780
781 if (serial->dev) { 781 mutex_lock(&serial->disc_mutex);
782 mutex_lock(&serial->disc_mutex); 782 if (!serial->disconnected) {
783 if (!serial->disconnected) { 783 serial->interface->needs_remote_wakeup = 0;
784 serial->interface->needs_remote_wakeup = 0; 784 /* odd error handling due to pm counters */
785 /* odd error handling due to pm counters */ 785 if (!usb_autopm_get_interface(serial->interface))
786 if (!usb_autopm_get_interface(serial->interface)) 786 sierra_send_setup(port);
787 sierra_send_setup(port); 787 else
788 else 788 usb_autopm_get_interface_no_resume(serial->interface);
789 usb_autopm_get_interface_no_resume(serial->interface);
790
791 }
792 mutex_unlock(&serial->disc_mutex);
793 spin_lock_irq(&intfdata->susp_lock);
794 portdata->opened = 0;
795 spin_unlock_irq(&intfdata->susp_lock);
796 789
790 }
791 mutex_unlock(&serial->disc_mutex);
792 spin_lock_irq(&intfdata->susp_lock);
793 portdata->opened = 0;
794 spin_unlock_irq(&intfdata->susp_lock);
797 795
798 /* Stop reading urbs */ 796 sierra_stop_rx_urbs(port);
799 sierra_stop_rx_urbs(port); 797 for (i = 0; i < portdata->num_in_urbs; i++) {
800 /* .. and release them */ 798 sierra_release_urb(portdata->in_urbs[i]);
801 for (i = 0; i < portdata->num_in_urbs; i++) { 799 portdata->in_urbs[i] = NULL;
802 sierra_release_urb(portdata->in_urbs[i]);
803 portdata->in_urbs[i] = NULL;
804 }
805 } 800 }
806} 801}
807 802
diff --git a/drivers/usb/serial/spcp8x5.c b/drivers/usb/serial/spcp8x5.c
index 549ef68ff5fa..cf3df793c2b7 100644
--- a/drivers/usb/serial/spcp8x5.c
+++ b/drivers/usb/serial/spcp8x5.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * spcp8x5 USB to serial adaptor driver 2 * spcp8x5 USB to serial adaptor driver
3 * 3 *
4 * Copyright (C) 2010 Johan Hovold (jhovold@gmail.com) 4 * Copyright (C) 2010-2013 Johan Hovold (jhovold@gmail.com)
5 * Copyright (C) 2006 Linxb (xubin.lin@worldplus.com.cn) 5 * Copyright (C) 2006 Linxb (xubin.lin@worldplus.com.cn)
6 * Copyright (C) 2006 S1 Corp. 6 * Copyright (C) 2006 S1 Corp.
7 * 7 *
@@ -13,8 +13,6 @@
13 * it under the terms of the GNU General Public License as published by 13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or 14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version. 15 * (at your option) any later version.
16 *
17 *
18 */ 16 */
19#include <linux/kernel.h> 17#include <linux/kernel.h>
20#include <linux/errno.h> 18#include <linux/errno.h>
@@ -28,7 +26,10 @@
28#include <linux/usb.h> 26#include <linux/usb.h>
29#include <linux/usb/serial.h> 27#include <linux/usb/serial.h>
30 28
31#define DRIVER_DESC "SPCP8x5 USB to serial adaptor driver" 29#define DRIVER_DESC "SPCP8x5 USB to serial adaptor driver"
30
31#define SPCP825_QUIRK_NO_UART_STATUS 0x01
32#define SPCP825_QUIRK_NO_WORK_MODE 0x02
32 33
33#define SPCP8x5_007_VID 0x04FC 34#define SPCP8x5_007_VID 0x04FC
34#define SPCP8x5_007_PID 0x0201 35#define SPCP8x5_007_PID 0x0201
@@ -46,13 +47,15 @@ static const struct usb_device_id id_table[] = {
46 { USB_DEVICE(SPCP8x5_INTERMATIC_VID, SPCP8x5_INTERMATIC_PID)}, 47 { USB_DEVICE(SPCP8x5_INTERMATIC_VID, SPCP8x5_INTERMATIC_PID)},
47 { USB_DEVICE(SPCP8x5_835_VID, SPCP8x5_835_PID)}, 48 { USB_DEVICE(SPCP8x5_835_VID, SPCP8x5_835_PID)},
48 { USB_DEVICE(SPCP8x5_008_VID, SPCP8x5_008_PID)}, 49 { USB_DEVICE(SPCP8x5_008_VID, SPCP8x5_008_PID)},
49 { USB_DEVICE(SPCP8x5_007_VID, SPCP8x5_007_PID)}, 50 { USB_DEVICE(SPCP8x5_007_VID, SPCP8x5_007_PID),
51 .driver_info = SPCP825_QUIRK_NO_UART_STATUS |
52 SPCP825_QUIRK_NO_WORK_MODE },
50 { } /* Terminating entry */ 53 { } /* Terminating entry */
51}; 54};
52MODULE_DEVICE_TABLE(usb, id_table); 55MODULE_DEVICE_TABLE(usb, id_table);
53 56
54struct spcp8x5_usb_ctrl_arg { 57struct spcp8x5_usb_ctrl_arg {
55 u8 type; 58 u8 type;
56 u8 cmd; 59 u8 cmd;
57 u8 cmd_type; 60 u8 cmd_type;
58 u16 value; 61 u16 value;
@@ -138,49 +141,33 @@ struct spcp8x5_usb_ctrl_arg {
138#define UART_OVERRUN_ERROR 0x40 141#define UART_OVERRUN_ERROR 0x40
139#define UART_CTS 0x80 142#define UART_CTS 0x80
140 143
141enum spcp8x5_type {
142 SPCP825_007_TYPE,
143 SPCP825_008_TYPE,
144 SPCP825_PHILIP_TYPE,
145 SPCP825_INTERMATIC_TYPE,
146 SPCP835_TYPE,
147};
148
149struct spcp8x5_private { 144struct spcp8x5_private {
150 spinlock_t lock; 145 unsigned quirks;
151 enum spcp8x5_type type; 146 spinlock_t lock;
152 u8 line_control; 147 u8 line_control;
153 u8 line_status;
154}; 148};
155 149
150static int spcp8x5_probe(struct usb_serial *serial,
151 const struct usb_device_id *id)
152{
153 usb_set_serial_data(serial, (void *)id);
154
155 return 0;
156}
157
156static int spcp8x5_port_probe(struct usb_serial_port *port) 158static int spcp8x5_port_probe(struct usb_serial_port *port)
157{ 159{
158 struct usb_serial *serial = port->serial; 160 const struct usb_device_id *id = usb_get_serial_data(port->serial);
159 struct spcp8x5_private *priv; 161 struct spcp8x5_private *priv;
160 enum spcp8x5_type type = SPCP825_007_TYPE;
161 u16 product = le16_to_cpu(serial->dev->descriptor.idProduct);
162
163 if (product == 0x0201)
164 type = SPCP825_007_TYPE;
165 else if (product == 0x0231)
166 type = SPCP835_TYPE;
167 else if (product == 0x0235)
168 type = SPCP825_008_TYPE;
169 else if (product == 0x0204)
170 type = SPCP825_INTERMATIC_TYPE;
171 else if (product == 0x0471 &&
172 serial->dev->descriptor.idVendor == cpu_to_le16(0x081e))
173 type = SPCP825_PHILIP_TYPE;
174 dev_dbg(&serial->dev->dev, "device type = %d\n", (int)type);
175 162
176 priv = kzalloc(sizeof(*priv), GFP_KERNEL); 163 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
177 if (!priv) 164 if (!priv)
178 return -ENOMEM; 165 return -ENOMEM;
179 166
180 spin_lock_init(&priv->lock); 167 spin_lock_init(&priv->lock);
181 priv->type = type; 168 priv->quirks = id->driver_info;
182 169
183 usb_set_serial_port_data(port , priv); 170 usb_set_serial_port_data(port, priv);
184 171
185 return 0; 172 return 0;
186} 173}
@@ -195,86 +182,79 @@ static int spcp8x5_port_remove(struct usb_serial_port *port)
195 return 0; 182 return 0;
196} 183}
197 184
198/* set the modem control line of the device. 185static int spcp8x5_set_ctrl_line(struct usb_serial_port *port, u8 mcr)
199 * NOTE spcp825-007 not supported this */
200static int spcp8x5_set_ctrlLine(struct usb_device *dev, u8 value,
201 enum spcp8x5_type type)
202{ 186{
187 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
188 struct usb_device *dev = port->serial->dev;
203 int retval; 189 int retval;
204 u8 mcr = 0 ;
205 190
206 if (type == SPCP825_007_TYPE) 191 if (priv->quirks & SPCP825_QUIRK_NO_UART_STATUS)
207 return -EPERM; 192 return -EPERM;
208 193
209 mcr = (unsigned short)value;
210 retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 194 retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
211 SET_UART_STATUS_TYPE, SET_UART_STATUS, 195 SET_UART_STATUS_TYPE, SET_UART_STATUS,
212 mcr, 0x04, NULL, 0, 100); 196 mcr, 0x04, NULL, 0, 100);
213 if (retval != 0) 197 if (retval != 0) {
214 dev_dbg(&dev->dev, "usb_control_msg return %#x\n", retval); 198 dev_err(&port->dev, "failed to set control lines: %d\n",
199 retval);
200 }
215 return retval; 201 return retval;
216} 202}
217 203
218/* get the modem status register of the device 204static int spcp8x5_get_msr(struct usb_serial_port *port, u8 *status)
219 * NOTE spcp825-007 not supported this */
220static int spcp8x5_get_msr(struct usb_device *dev, u8 *status,
221 enum spcp8x5_type type)
222{ 205{
223 u8 *status_buffer; 206 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
207 struct usb_device *dev = port->serial->dev;
208 u8 *buf;
224 int ret; 209 int ret;
225 210
226 /* I return Permited not support here but seem inval device 211 if (priv->quirks & SPCP825_QUIRK_NO_UART_STATUS)
227 * is more fix */
228 if (type == SPCP825_007_TYPE)
229 return -EPERM; 212 return -EPERM;
230 if (status == NULL)
231 return -EINVAL;
232 213
233 status_buffer = kmalloc(1, GFP_KERNEL); 214 buf = kzalloc(1, GFP_KERNEL);
234 if (!status_buffer) 215 if (!buf)
235 return -ENOMEM; 216 return -ENOMEM;
236 status_buffer[0] = status[0];
237 217
238 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), 218 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
239 GET_UART_STATUS, GET_UART_STATUS_TYPE, 219 GET_UART_STATUS, GET_UART_STATUS_TYPE,
240 0, GET_UART_STATUS_MSR, status_buffer, 1, 100); 220 0, GET_UART_STATUS_MSR, buf, 1, 100);
241 if (ret < 0) 221 if (ret < 0)
242 dev_dbg(&dev->dev, "Get MSR = 0x%p failed (error = %d)", 222 dev_err(&port->dev, "failed to get modem status: %d", ret);
243 status_buffer, ret);
244 223
245 dev_dbg(&dev->dev, "0xc0:0x22:0:6 %d - 0x%p ", ret, status_buffer); 224 dev_dbg(&port->dev, "0xc0:0x22:0:6 %d - 0x02%x", ret, *buf);
246 status[0] = status_buffer[0]; 225 *status = *buf;
247 kfree(status_buffer); 226 kfree(buf);
248 227
249 return ret; 228 return ret;
250} 229}
251 230
252/* select the work mode. 231static void spcp8x5_set_work_mode(struct usb_serial_port *port, u16 value,
253 * NOTE this function not supported by spcp825-007 */ 232 u16 index)
254static void spcp8x5_set_workMode(struct usb_device *dev, u16 value,
255 u16 index, enum spcp8x5_type type)
256{ 233{
234 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
235 struct usb_device *dev = port->serial->dev;
257 int ret; 236 int ret;
258 237
259 /* I return Permited not support here but seem inval device 238 if (priv->quirks & SPCP825_QUIRK_NO_WORK_MODE)
260 * is more fix */
261 if (type == SPCP825_007_TYPE)
262 return; 239 return;
263 240
264 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 241 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
265 SET_WORKING_MODE_TYPE, SET_WORKING_MODE, 242 SET_WORKING_MODE_TYPE, SET_WORKING_MODE,
266 value, index, NULL, 0, 100); 243 value, index, NULL, 0, 100);
267 dev_dbg(&dev->dev, "value = %#x , index = %#x\n", value, index); 244 dev_dbg(&port->dev, "value = %#x , index = %#x\n", value, index);
268 if (ret < 0) 245 if (ret < 0)
269 dev_dbg(&dev->dev, 246 dev_err(&port->dev, "failed to set work mode: %d\n", ret);
270 "RTSCTS usb_control_msg(enable flowctrl) = %d\n", ret);
271} 247}
272 248
273static int spcp8x5_carrier_raised(struct usb_serial_port *port) 249static int spcp8x5_carrier_raised(struct usb_serial_port *port)
274{ 250{
275 struct spcp8x5_private *priv = usb_get_serial_port_data(port); 251 u8 msr;
276 if (priv->line_status & MSR_STATUS_LINE_DCD) 252 int ret;
253
254 ret = spcp8x5_get_msr(port, &msr);
255 if (ret || msr & MSR_STATUS_LINE_DCD)
277 return 1; 256 return 1;
257
278 return 0; 258 return 0;
279} 259}
280 260
@@ -293,20 +273,17 @@ static void spcp8x5_dtr_rts(struct usb_serial_port *port, int on)
293 | MCR_CONTROL_LINE_RTS); 273 | MCR_CONTROL_LINE_RTS);
294 control = priv->line_control; 274 control = priv->line_control;
295 spin_unlock_irqrestore(&priv->lock, flags); 275 spin_unlock_irqrestore(&priv->lock, flags);
296 spcp8x5_set_ctrlLine(port->serial->dev, control , priv->type); 276 spcp8x5_set_ctrl_line(port, control);
297} 277}
298 278
299static void spcp8x5_init_termios(struct tty_struct *tty) 279static void spcp8x5_init_termios(struct tty_struct *tty)
300{ 280{
301 /* for the 1st time call this function */
302 tty->termios = tty_std_termios; 281 tty->termios = tty_std_termios;
303 tty->termios.c_cflag = B115200 | CS8 | CREAD | HUPCL | CLOCAL; 282 tty->termios.c_cflag = B115200 | CS8 | CREAD | HUPCL | CLOCAL;
304 tty->termios.c_ispeed = 115200; 283 tty->termios.c_ispeed = 115200;
305 tty->termios.c_ospeed = 115200; 284 tty->termios.c_ospeed = 115200;
306} 285}
307 286
308/* set the serial param for transfer. we should check if we really need to
309 * transfer. if we set flow control we should do this too. */
310static void spcp8x5_set_termios(struct tty_struct *tty, 287static void spcp8x5_set_termios(struct tty_struct *tty,
311 struct usb_serial_port *port, struct ktermios *old_termios) 288 struct usb_serial_port *port, struct ktermios *old_termios)
312{ 289{
@@ -321,7 +298,6 @@ static void spcp8x5_set_termios(struct tty_struct *tty,
321 int i; 298 int i;
322 u8 control; 299 u8 control;
323 300
324
325 /* check that they really want us to change something */ 301 /* check that they really want us to change something */
326 if (!tty_termios_hw_change(&tty->termios, old_termios)) 302 if (!tty_termios_hw_change(&tty->termios, old_termios))
327 return; 303 return;
@@ -337,7 +313,7 @@ static void spcp8x5_set_termios(struct tty_struct *tty,
337 if (control != priv->line_control) { 313 if (control != priv->line_control) {
338 control = priv->line_control; 314 control = priv->line_control;
339 spin_unlock_irqrestore(&priv->lock, flags); 315 spin_unlock_irqrestore(&priv->lock, flags);
340 spcp8x5_set_ctrlLine(serial->dev, control , priv->type); 316 spcp8x5_set_ctrl_line(port, control);
341 } else { 317 } else {
342 spin_unlock_irqrestore(&priv->lock, flags); 318 spin_unlock_irqrestore(&priv->lock, flags);
343 } 319 }
@@ -397,9 +373,9 @@ static void spcp8x5_set_termios(struct tty_struct *tty,
397 if (cflag & PARENB) { 373 if (cflag & PARENB) {
398 buf[1] |= (cflag & PARODD) ? 374 buf[1] |= (cflag & PARODD) ?
399 SET_UART_FORMAT_PAR_ODD : SET_UART_FORMAT_PAR_EVEN ; 375 SET_UART_FORMAT_PAR_ODD : SET_UART_FORMAT_PAR_EVEN ;
400 } else 376 } else {
401 buf[1] |= SET_UART_FORMAT_PAR_NONE; 377 buf[1] |= SET_UART_FORMAT_PAR_NONE;
402 378 }
403 uartdata = buf[0] | buf[1]<<8; 379 uartdata = buf[0] | buf[1]<<8;
404 380
405 i = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 381 i = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
@@ -412,22 +388,16 @@ static void spcp8x5_set_termios(struct tty_struct *tty,
412 388
413 if (cflag & CRTSCTS) { 389 if (cflag & CRTSCTS) {
414 /* enable hardware flow control */ 390 /* enable hardware flow control */
415 spcp8x5_set_workMode(serial->dev, 0x000a, 391 spcp8x5_set_work_mode(port, 0x000a, SET_WORKING_MODE_U2C);
416 SET_WORKING_MODE_U2C, priv->type);
417 } 392 }
418} 393}
419 394
420/* open the serial port. do some usb system call. set termios and get the line
421 * status of the device. */
422static int spcp8x5_open(struct tty_struct *tty, struct usb_serial_port *port) 395static int spcp8x5_open(struct tty_struct *tty, struct usb_serial_port *port)
423{ 396{
424 struct ktermios tmp_termios; 397 struct ktermios tmp_termios;
425 struct usb_serial *serial = port->serial; 398 struct usb_serial *serial = port->serial;
426 struct spcp8x5_private *priv = usb_get_serial_port_data(port); 399 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
427 int ret; 400 int ret;
428 unsigned long flags;
429 u8 status = 0x30;
430 /* status 0x30 means DSR and CTS = 1 other CDC RI and delta = 0 */
431 401
432 usb_clear_halt(serial->dev, port->write_urb->pipe); 402 usb_clear_halt(serial->dev, port->write_urb->pipe);
433 usb_clear_halt(serial->dev, port->read_urb->pipe); 403 usb_clear_halt(serial->dev, port->read_urb->pipe);
@@ -438,142 +408,16 @@ static int spcp8x5_open(struct tty_struct *tty, struct usb_serial_port *port)
438 if (ret) 408 if (ret)
439 return ret; 409 return ret;
440 410
441 spcp8x5_set_ctrlLine(serial->dev, priv->line_control , priv->type); 411 spcp8x5_set_ctrl_line(port, priv->line_control);
442 412
443 /* Setup termios */
444 if (tty) 413 if (tty)
445 spcp8x5_set_termios(tty, port, &tmp_termios); 414 spcp8x5_set_termios(tty, port, &tmp_termios);
446 415
447 spcp8x5_get_msr(serial->dev, &status, priv->type);
448
449 /* may be we should update uart status here but now we did not do */
450 spin_lock_irqsave(&priv->lock, flags);
451 priv->line_status = status & 0xf0 ;
452 spin_unlock_irqrestore(&priv->lock, flags);
453
454 port->port.drain_delay = 256; 416 port->port.drain_delay = 256;
455 417
456 return usb_serial_generic_open(tty, port); 418 return usb_serial_generic_open(tty, port);
457} 419}
458 420
459static void spcp8x5_process_read_urb(struct urb *urb)
460{
461 struct usb_serial_port *port = urb->context;
462 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
463 unsigned char *data = urb->transfer_buffer;
464 unsigned long flags;
465 u8 status;
466 char tty_flag;
467
468 /* get tty_flag from status */
469 tty_flag = TTY_NORMAL;
470
471 spin_lock_irqsave(&priv->lock, flags);
472 status = priv->line_status;
473 priv->line_status &= ~UART_STATE_TRANSIENT_MASK;
474 spin_unlock_irqrestore(&priv->lock, flags);
475 /* wake up the wait for termios */
476 wake_up_interruptible(&port->delta_msr_wait);
477
478 if (!urb->actual_length)
479 return;
480
481
482 if (status & UART_STATE_TRANSIENT_MASK) {
483 /* break takes precedence over parity, which takes precedence
484 * over framing errors */
485 if (status & UART_BREAK_ERROR)
486 tty_flag = TTY_BREAK;
487 else if (status & UART_PARITY_ERROR)
488 tty_flag = TTY_PARITY;
489 else if (status & UART_FRAME_ERROR)
490 tty_flag = TTY_FRAME;
491 dev_dbg(&port->dev, "tty_flag = %d\n", tty_flag);
492
493 /* overrun is special, not associated with a char */
494 if (status & UART_OVERRUN_ERROR)
495 tty_insert_flip_char(&port->port, 0, TTY_OVERRUN);
496
497 if (status & UART_DCD) {
498 struct tty_struct *tty = tty_port_tty_get(&port->port);
499 if (tty) {
500 usb_serial_handle_dcd_change(port, tty,
501 priv->line_status & MSR_STATUS_LINE_DCD);
502 tty_kref_put(tty);
503 }
504 }
505 }
506
507 tty_insert_flip_string_fixed_flag(&port->port, data, tty_flag,
508 urb->actual_length);
509 tty_flip_buffer_push(&port->port);
510}
511
512static int spcp8x5_wait_modem_info(struct usb_serial_port *port,
513 unsigned int arg)
514{
515 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
516 unsigned long flags;
517 unsigned int prevstatus;
518 unsigned int status;
519 unsigned int changed;
520
521 spin_lock_irqsave(&priv->lock, flags);
522 prevstatus = priv->line_status;
523 spin_unlock_irqrestore(&priv->lock, flags);
524
525 while (1) {
526 /* wake up in bulk read */
527 interruptible_sleep_on(&port->delta_msr_wait);
528
529 /* see if a signal did it */
530 if (signal_pending(current))
531 return -ERESTARTSYS;
532
533 if (port->serial->disconnected)
534 return -EIO;
535
536 spin_lock_irqsave(&priv->lock, flags);
537 status = priv->line_status;
538 spin_unlock_irqrestore(&priv->lock, flags);
539
540 changed = prevstatus^status;
541
542 if (((arg & TIOCM_RNG) && (changed & MSR_STATUS_LINE_RI)) ||
543 ((arg & TIOCM_DSR) && (changed & MSR_STATUS_LINE_DSR)) ||
544 ((arg & TIOCM_CD) && (changed & MSR_STATUS_LINE_DCD)) ||
545 ((arg & TIOCM_CTS) && (changed & MSR_STATUS_LINE_CTS)))
546 return 0;
547
548 prevstatus = status;
549 }
550 /* NOTREACHED */
551 return 0;
552}
553
554static int spcp8x5_ioctl(struct tty_struct *tty,
555 unsigned int cmd, unsigned long arg)
556{
557 struct usb_serial_port *port = tty->driver_data;
558
559 dev_dbg(&port->dev, "%s (%d) cmd = 0x%04x\n", __func__,
560 port->number, cmd);
561
562 switch (cmd) {
563 case TIOCMIWAIT:
564 dev_dbg(&port->dev, "%s (%d) TIOCMIWAIT\n", __func__,
565 port->number);
566 return spcp8x5_wait_modem_info(port, arg);
567
568 default:
569 dev_dbg(&port->dev, "%s not supported = 0x%04x", __func__,
570 cmd);
571 break;
572 }
573
574 return -ENOIOCTLCMD;
575}
576
577static int spcp8x5_tiocmset(struct tty_struct *tty, 421static int spcp8x5_tiocmset(struct tty_struct *tty,
578 unsigned int set, unsigned int clear) 422 unsigned int set, unsigned int clear)
579{ 423{
@@ -594,7 +438,7 @@ static int spcp8x5_tiocmset(struct tty_struct *tty,
594 control = priv->line_control; 438 control = priv->line_control;
595 spin_unlock_irqrestore(&priv->lock, flags); 439 spin_unlock_irqrestore(&priv->lock, flags);
596 440
597 return spcp8x5_set_ctrlLine(port->serial->dev, control , priv->type); 441 return spcp8x5_set_ctrl_line(port, control);
598} 442}
599 443
600static int spcp8x5_tiocmget(struct tty_struct *tty) 444static int spcp8x5_tiocmget(struct tty_struct *tty)
@@ -603,12 +447,15 @@ static int spcp8x5_tiocmget(struct tty_struct *tty)
603 struct spcp8x5_private *priv = usb_get_serial_port_data(port); 447 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
604 unsigned long flags; 448 unsigned long flags;
605 unsigned int mcr; 449 unsigned int mcr;
606 unsigned int status; 450 u8 status;
607 unsigned int result; 451 unsigned int result;
608 452
453 result = spcp8x5_get_msr(port, &status);
454 if (result)
455 return result;
456
609 spin_lock_irqsave(&priv->lock, flags); 457 spin_lock_irqsave(&priv->lock, flags);
610 mcr = priv->line_control; 458 mcr = priv->line_control;
611 status = priv->line_status;
612 spin_unlock_irqrestore(&priv->lock, flags); 459 spin_unlock_irqrestore(&priv->lock, flags);
613 460
614 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) 461 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0)
@@ -621,7 +468,6 @@ static int spcp8x5_tiocmget(struct tty_struct *tty)
621 return result; 468 return result;
622} 469}
623 470
624/* All of the device info needed for the spcp8x5 SIO serial converter */
625static struct usb_serial_driver spcp8x5_device = { 471static struct usb_serial_driver spcp8x5_device = {
626 .driver = { 472 .driver = {
627 .owner = THIS_MODULE, 473 .owner = THIS_MODULE,
@@ -629,17 +475,16 @@ static struct usb_serial_driver spcp8x5_device = {
629 }, 475 },
630 .id_table = id_table, 476 .id_table = id_table,
631 .num_ports = 1, 477 .num_ports = 1,
632 .open = spcp8x5_open, 478 .open = spcp8x5_open,
633 .dtr_rts = spcp8x5_dtr_rts, 479 .dtr_rts = spcp8x5_dtr_rts,
634 .carrier_raised = spcp8x5_carrier_raised, 480 .carrier_raised = spcp8x5_carrier_raised,
635 .set_termios = spcp8x5_set_termios, 481 .set_termios = spcp8x5_set_termios,
636 .init_termios = spcp8x5_init_termios, 482 .init_termios = spcp8x5_init_termios,
637 .ioctl = spcp8x5_ioctl, 483 .tiocmget = spcp8x5_tiocmget,
638 .tiocmget = spcp8x5_tiocmget, 484 .tiocmset = spcp8x5_tiocmset,
639 .tiocmset = spcp8x5_tiocmset, 485 .probe = spcp8x5_probe,
640 .port_probe = spcp8x5_port_probe, 486 .port_probe = spcp8x5_port_probe,
641 .port_remove = spcp8x5_port_remove, 487 .port_remove = spcp8x5_port_remove,
642 .process_read_urb = spcp8x5_process_read_urb,
643}; 488};
644 489
645static struct usb_serial_driver * const serial_drivers[] = { 490static struct usb_serial_driver * const serial_drivers[] = {
diff --git a/drivers/usb/serial/ssu100.c b/drivers/usb/serial/ssu100.c
index 4b2a19757b4d..5b62dbbdf996 100644
--- a/drivers/usb/serial/ssu100.c
+++ b/drivers/usb/serial/ssu100.c
@@ -61,7 +61,6 @@ struct ssu100_port_private {
61 spinlock_t status_lock; 61 spinlock_t status_lock;
62 u8 shadowLSR; 62 u8 shadowLSR;
63 u8 shadowMSR; 63 u8 shadowMSR;
64 struct async_icount icount;
65}; 64};
66 65
67static inline int ssu100_control_msg(struct usb_device *dev, 66static inline int ssu100_control_msg(struct usb_device *dev,
@@ -315,11 +314,6 @@ static int ssu100_open(struct tty_struct *tty, struct usb_serial_port *port)
315 return usb_serial_generic_open(tty, port); 314 return usb_serial_generic_open(tty, port);
316} 315}
317 316
318static void ssu100_close(struct usb_serial_port *port)
319{
320 usb_serial_generic_close(port);
321}
322
323static int get_serial_info(struct usb_serial_port *port, 317static int get_serial_info(struct usb_serial_port *port,
324 struct serial_struct __user *retinfo) 318 struct serial_struct __user *retinfo)
325{ 319{
@@ -343,73 +337,6 @@ static int get_serial_info(struct usb_serial_port *port,
343 return 0; 337 return 0;
344} 338}
345 339
346static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
347{
348 struct ssu100_port_private *priv = usb_get_serial_port_data(port);
349 struct async_icount prev, cur;
350 unsigned long flags;
351
352 spin_lock_irqsave(&priv->status_lock, flags);
353 prev = priv->icount;
354 spin_unlock_irqrestore(&priv->status_lock, flags);
355
356 while (1) {
357 wait_event_interruptible(port->delta_msr_wait,
358 (port->serial->disconnected ||
359 (priv->icount.rng != prev.rng) ||
360 (priv->icount.dsr != prev.dsr) ||
361 (priv->icount.dcd != prev.dcd) ||
362 (priv->icount.cts != prev.cts)));
363
364 if (signal_pending(current))
365 return -ERESTARTSYS;
366
367 if (port->serial->disconnected)
368 return -EIO;
369
370 spin_lock_irqsave(&priv->status_lock, flags);
371 cur = priv->icount;
372 spin_unlock_irqrestore(&priv->status_lock, flags);
373
374 if ((prev.rng == cur.rng) &&
375 (prev.dsr == cur.dsr) &&
376 (prev.dcd == cur.dcd) &&
377 (prev.cts == cur.cts))
378 return -EIO;
379
380 if ((arg & TIOCM_RNG && (prev.rng != cur.rng)) ||
381 (arg & TIOCM_DSR && (prev.dsr != cur.dsr)) ||
382 (arg & TIOCM_CD && (prev.dcd != cur.dcd)) ||
383 (arg & TIOCM_CTS && (prev.cts != cur.cts)))
384 return 0;
385 }
386 return 0;
387}
388
389static int ssu100_get_icount(struct tty_struct *tty,
390 struct serial_icounter_struct *icount)
391{
392 struct usb_serial_port *port = tty->driver_data;
393 struct ssu100_port_private *priv = usb_get_serial_port_data(port);
394 struct async_icount cnow = priv->icount;
395
396 icount->cts = cnow.cts;
397 icount->dsr = cnow.dsr;
398 icount->rng = cnow.rng;
399 icount->dcd = cnow.dcd;
400 icount->rx = cnow.rx;
401 icount->tx = cnow.tx;
402 icount->frame = cnow.frame;
403 icount->overrun = cnow.overrun;
404 icount->parity = cnow.parity;
405 icount->brk = cnow.brk;
406 icount->buf_overrun = cnow.buf_overrun;
407
408 return 0;
409}
410
411
412
413static int ssu100_ioctl(struct tty_struct *tty, 340static int ssu100_ioctl(struct tty_struct *tty,
414 unsigned int cmd, unsigned long arg) 341 unsigned int cmd, unsigned long arg)
415{ 342{
@@ -421,10 +348,6 @@ static int ssu100_ioctl(struct tty_struct *tty,
421 case TIOCGSERIAL: 348 case TIOCGSERIAL:
422 return get_serial_info(port, 349 return get_serial_info(port,
423 (struct serial_struct __user *) arg); 350 (struct serial_struct __user *) arg);
424
425 case TIOCMIWAIT:
426 return wait_modem_info(port, arg);
427
428 default: 351 default:
429 break; 352 break;
430 } 353 }
@@ -532,14 +455,14 @@ static void ssu100_update_msr(struct usb_serial_port *port, u8 msr)
532 if (msr & UART_MSR_ANY_DELTA) { 455 if (msr & UART_MSR_ANY_DELTA) {
533 /* update input line counters */ 456 /* update input line counters */
534 if (msr & UART_MSR_DCTS) 457 if (msr & UART_MSR_DCTS)
535 priv->icount.cts++; 458 port->icount.cts++;
536 if (msr & UART_MSR_DDSR) 459 if (msr & UART_MSR_DDSR)
537 priv->icount.dsr++; 460 port->icount.dsr++;
538 if (msr & UART_MSR_DDCD) 461 if (msr & UART_MSR_DDCD)
539 priv->icount.dcd++; 462 port->icount.dcd++;
540 if (msr & UART_MSR_TERI) 463 if (msr & UART_MSR_TERI)
541 priv->icount.rng++; 464 port->icount.rng++;
542 wake_up_interruptible(&port->delta_msr_wait); 465 wake_up_interruptible(&port->port.delta_msr_wait);
543 } 466 }
544} 467}
545 468
@@ -558,22 +481,22 @@ static void ssu100_update_lsr(struct usb_serial_port *port, u8 lsr,
558 /* we always want to update icount, but we only want to 481 /* we always want to update icount, but we only want to
559 * update tty_flag for one case */ 482 * update tty_flag for one case */
560 if (lsr & UART_LSR_BI) { 483 if (lsr & UART_LSR_BI) {
561 priv->icount.brk++; 484 port->icount.brk++;
562 *tty_flag = TTY_BREAK; 485 *tty_flag = TTY_BREAK;
563 usb_serial_handle_break(port); 486 usb_serial_handle_break(port);
564 } 487 }
565 if (lsr & UART_LSR_PE) { 488 if (lsr & UART_LSR_PE) {
566 priv->icount.parity++; 489 port->icount.parity++;
567 if (*tty_flag == TTY_NORMAL) 490 if (*tty_flag == TTY_NORMAL)
568 *tty_flag = TTY_PARITY; 491 *tty_flag = TTY_PARITY;
569 } 492 }
570 if (lsr & UART_LSR_FE) { 493 if (lsr & UART_LSR_FE) {
571 priv->icount.frame++; 494 port->icount.frame++;
572 if (*tty_flag == TTY_NORMAL) 495 if (*tty_flag == TTY_NORMAL)
573 *tty_flag = TTY_FRAME; 496 *tty_flag = TTY_FRAME;
574 } 497 }
575 if (lsr & UART_LSR_OE){ 498 if (lsr & UART_LSR_OE){
576 priv->icount.overrun++; 499 port->icount.overrun++;
577 if (*tty_flag == TTY_NORMAL) 500 if (*tty_flag == TTY_NORMAL)
578 *tty_flag = TTY_OVERRUN; 501 *tty_flag = TTY_OVERRUN;
579 } 502 }
@@ -630,7 +553,6 @@ static struct usb_serial_driver ssu100_device = {
630 .id_table = id_table, 553 .id_table = id_table,
631 .num_ports = 1, 554 .num_ports = 1,
632 .open = ssu100_open, 555 .open = ssu100_open,
633 .close = ssu100_close,
634 .attach = ssu100_attach, 556 .attach = ssu100_attach,
635 .port_probe = ssu100_port_probe, 557 .port_probe = ssu100_port_probe,
636 .port_remove = ssu100_port_remove, 558 .port_remove = ssu100_port_remove,
@@ -638,10 +560,10 @@ static struct usb_serial_driver ssu100_device = {
638 .process_read_urb = ssu100_process_read_urb, 560 .process_read_urb = ssu100_process_read_urb,
639 .tiocmget = ssu100_tiocmget, 561 .tiocmget = ssu100_tiocmget,
640 .tiocmset = ssu100_tiocmset, 562 .tiocmset = ssu100_tiocmset,
641 .get_icount = ssu100_get_icount, 563 .tiocmiwait = usb_serial_generic_tiocmiwait,
564 .get_icount = usb_serial_generic_get_icount,
642 .ioctl = ssu100_ioctl, 565 .ioctl = ssu100_ioctl,
643 .set_termios = ssu100_set_termios, 566 .set_termios = ssu100_set_termios,
644 .disconnect = usb_serial_generic_disconnect,
645}; 567};
646 568
647static struct usb_serial_driver * const serial_drivers[] = { 569static struct usb_serial_driver * const serial_drivers[] = {
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c
index 73deb029fc05..07268591b0d1 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -73,7 +73,6 @@ struct ti_port {
73 unsigned int tp_uart_base_addr; 73 unsigned int tp_uart_base_addr;
74 int tp_flags; 74 int tp_flags;
75 int tp_closing_wait;/* in .01 secs */ 75 int tp_closing_wait;/* in .01 secs */
76 struct async_icount tp_icount;
77 wait_queue_head_t tp_write_wait; 76 wait_queue_head_t tp_write_wait;
78 struct ti_device *tp_tdev; 77 struct ti_device *tp_tdev;
79 struct usb_serial_port *tp_port; 78 struct usb_serial_port *tp_port;
@@ -108,8 +107,6 @@ static void ti_throttle(struct tty_struct *tty);
108static void ti_unthrottle(struct tty_struct *tty); 107static void ti_unthrottle(struct tty_struct *tty);
109static int ti_ioctl(struct tty_struct *tty, 108static int ti_ioctl(struct tty_struct *tty,
110 unsigned int cmd, unsigned long arg); 109 unsigned int cmd, unsigned long arg);
111static int ti_get_icount(struct tty_struct *tty,
112 struct serial_icounter_struct *icount);
113static void ti_set_termios(struct tty_struct *tty, 110static void ti_set_termios(struct tty_struct *tty,
114 struct usb_serial_port *port, struct ktermios *old_termios); 111 struct usb_serial_port *port, struct ktermios *old_termios);
115static int ti_tiocmget(struct tty_struct *tty); 112static int ti_tiocmget(struct tty_struct *tty);
@@ -235,7 +232,8 @@ static struct usb_serial_driver ti_1port_device = {
235 .set_termios = ti_set_termios, 232 .set_termios = ti_set_termios,
236 .tiocmget = ti_tiocmget, 233 .tiocmget = ti_tiocmget,
237 .tiocmset = ti_tiocmset, 234 .tiocmset = ti_tiocmset,
238 .get_icount = ti_get_icount, 235 .tiocmiwait = usb_serial_generic_tiocmiwait,
236 .get_icount = usb_serial_generic_get_icount,
239 .break_ctl = ti_break, 237 .break_ctl = ti_break,
240 .read_int_callback = ti_interrupt_callback, 238 .read_int_callback = ti_interrupt_callback,
241 .read_bulk_callback = ti_bulk_in_callback, 239 .read_bulk_callback = ti_bulk_in_callback,
@@ -265,7 +263,8 @@ static struct usb_serial_driver ti_2port_device = {
265 .set_termios = ti_set_termios, 263 .set_termios = ti_set_termios,
266 .tiocmget = ti_tiocmget, 264 .tiocmget = ti_tiocmget,
267 .tiocmset = ti_tiocmset, 265 .tiocmset = ti_tiocmset,
268 .get_icount = ti_get_icount, 266 .tiocmiwait = usb_serial_generic_tiocmiwait,
267 .get_icount = usb_serial_generic_get_icount,
269 .break_ctl = ti_break, 268 .break_ctl = ti_break,
270 .read_int_callback = ti_interrupt_callback, 269 .read_int_callback = ti_interrupt_callback,
271 .read_bulk_callback = ti_bulk_in_callback, 270 .read_bulk_callback = ti_bulk_in_callback,
@@ -480,8 +479,6 @@ static int ti_open(struct tty_struct *tty, struct usb_serial_port *port)
480 479
481 port_number = port->number - port->serial->minor; 480 port_number = port->number - port->serial->minor;
482 481
483 memset(&(tport->tp_icount), 0x00, sizeof(tport->tp_icount));
484
485 tport->tp_msr = 0; 482 tport->tp_msr = 0;
486 tport->tp_shadow_mcr |= (TI_MCR_RTS | TI_MCR_DTR); 483 tport->tp_shadow_mcr |= (TI_MCR_RTS | TI_MCR_DTR);
487 484
@@ -731,38 +728,11 @@ static void ti_unthrottle(struct tty_struct *tty)
731 } 728 }
732} 729}
733 730
734static int ti_get_icount(struct tty_struct *tty,
735 struct serial_icounter_struct *icount)
736{
737 struct usb_serial_port *port = tty->driver_data;
738 struct ti_port *tport = usb_get_serial_port_data(port);
739 struct async_icount cnow = tport->tp_icount;
740
741 dev_dbg(&port->dev, "%s - TIOCGICOUNT RX=%d, TX=%d\n", __func__,
742 cnow.rx, cnow.tx);
743
744 icount->cts = cnow.cts;
745 icount->dsr = cnow.dsr;
746 icount->rng = cnow.rng;
747 icount->dcd = cnow.dcd;
748 icount->rx = cnow.rx;
749 icount->tx = cnow.tx;
750 icount->frame = cnow.frame;
751 icount->overrun = cnow.overrun;
752 icount->parity = cnow.parity;
753 icount->brk = cnow.brk;
754 icount->buf_overrun = cnow.buf_overrun;
755
756 return 0;
757}
758
759static int ti_ioctl(struct tty_struct *tty, 731static int ti_ioctl(struct tty_struct *tty,
760 unsigned int cmd, unsigned long arg) 732 unsigned int cmd, unsigned long arg)
761{ 733{
762 struct usb_serial_port *port = tty->driver_data; 734 struct usb_serial_port *port = tty->driver_data;
763 struct ti_port *tport = usb_get_serial_port_data(port); 735 struct ti_port *tport = usb_get_serial_port_data(port);
764 struct async_icount cnow;
765 struct async_icount cprev;
766 736
767 dev_dbg(&port->dev, "%s - cmd = 0x%04X\n", __func__, cmd); 737 dev_dbg(&port->dev, "%s - cmd = 0x%04X\n", __func__, cmd);
768 738
@@ -778,29 +748,6 @@ static int ti_ioctl(struct tty_struct *tty,
778 dev_dbg(&port->dev, "%s - TIOCSSERIAL\n", __func__); 748 dev_dbg(&port->dev, "%s - TIOCSSERIAL\n", __func__);
779 return ti_set_serial_info(tty, tport, 749 return ti_set_serial_info(tty, tport,
780 (struct serial_struct __user *)arg); 750 (struct serial_struct __user *)arg);
781 case TIOCMIWAIT:
782 dev_dbg(&port->dev, "%s - TIOCMIWAIT\n", __func__);
783 cprev = tport->tp_icount;
784 while (1) {
785 interruptible_sleep_on(&port->delta_msr_wait);
786 if (signal_pending(current))
787 return -ERESTARTSYS;
788
789 if (port->serial->disconnected)
790 return -EIO;
791
792 cnow = tport->tp_icount;
793 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
794 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
795 return -EIO; /* no change => error */
796 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
797 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
798 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
799 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)))
800 return 0;
801 cprev = cnow;
802 }
803 break;
804 } 751 }
805 return -ENOIOCTLCMD; 752 return -ENOIOCTLCMD;
806} 753}
@@ -1156,7 +1103,7 @@ static void ti_bulk_in_callback(struct urb *urb)
1156 else 1103 else
1157 ti_recv(port, urb->transfer_buffer, urb->actual_length); 1104 ti_recv(port, urb->transfer_buffer, urb->actual_length);
1158 spin_lock(&tport->tp_lock); 1105 spin_lock(&tport->tp_lock);
1159 tport->tp_icount.rx += urb->actual_length; 1106 port->icount.rx += urb->actual_length;
1160 spin_unlock(&tport->tp_lock); 1107 spin_unlock(&tport->tp_lock);
1161 } 1108 }
1162 1109
@@ -1265,7 +1212,7 @@ static void ti_send(struct ti_port *tport)
1265 /* TODO: reschedule ti_send */ 1212 /* TODO: reschedule ti_send */
1266 } else { 1213 } else {
1267 spin_lock_irqsave(&tport->tp_lock, flags); 1214 spin_lock_irqsave(&tport->tp_lock, flags);
1268 tport->tp_icount.tx += count; 1215 port->icount.tx += count;
1269 spin_unlock_irqrestore(&tport->tp_lock, flags); 1216 spin_unlock_irqrestore(&tport->tp_lock, flags);
1270 } 1217 }
1271 1218
@@ -1385,7 +1332,7 @@ static void ti_handle_new_msr(struct ti_port *tport, __u8 msr)
1385 1332
1386 if (msr & TI_MSR_DELTA_MASK) { 1333 if (msr & TI_MSR_DELTA_MASK) {
1387 spin_lock_irqsave(&tport->tp_lock, flags); 1334 spin_lock_irqsave(&tport->tp_lock, flags);
1388 icount = &tport->tp_icount; 1335 icount = &tport->tp_port->icount;
1389 if (msr & TI_MSR_DELTA_CTS) 1336 if (msr & TI_MSR_DELTA_CTS)
1390 icount->cts++; 1337 icount->cts++;
1391 if (msr & TI_MSR_DELTA_DSR) 1338 if (msr & TI_MSR_DELTA_DSR)
@@ -1394,7 +1341,7 @@ static void ti_handle_new_msr(struct ti_port *tport, __u8 msr)
1394 icount->dcd++; 1341 icount->dcd++;
1395 if (msr & TI_MSR_DELTA_RI) 1342 if (msr & TI_MSR_DELTA_RI)
1396 icount->rng++; 1343 icount->rng++;
1397 wake_up_interruptible(&tport->tp_port->delta_msr_wait); 1344 wake_up_interruptible(&tport->tp_port->port.delta_msr_wait);
1398 spin_unlock_irqrestore(&tport->tp_lock, flags); 1345 spin_unlock_irqrestore(&tport->tp_lock, flags);
1399 } 1346 }
1400 1347
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 5d9b178484fd..5eb96df8de05 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -1,6 +1,7 @@
1/* 1/*
2 * USB Serial Converter driver 2 * USB Serial Converter driver
3 * 3 *
4 * Copyright (C) 2009 - 2013 Johan Hovold (jhovold@gmail.com)
4 * Copyright (C) 1999 - 2012 Greg Kroah-Hartman (greg@kroah.com) 5 * Copyright (C) 1999 - 2012 Greg Kroah-Hartman (greg@kroah.com)
5 * Copyright (C) 2000 Peter Berger (pberger@brimson.com) 6 * Copyright (C) 2000 Peter Berger (pberger@brimson.com)
6 * Copyright (C) 2000 Al Borchers (borchers@steinerpoint.com) 7 * Copyright (C) 2000 Al Borchers (borchers@steinerpoint.com)
@@ -14,7 +15,6 @@
14 * 15 *
15 * See Documentation/usb/usb-serial.txt for more information on using this 16 * See Documentation/usb/usb-serial.txt for more information on using this
16 * driver 17 * driver
17 *
18 */ 18 */
19 19
20#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 20#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
@@ -49,7 +49,6 @@
49 drivers depend on it. 49 drivers depend on it.
50*/ 50*/
51 51
52/* initially all NULL */
53static struct usb_serial *serial_table[SERIAL_TTY_MINORS]; 52static struct usb_serial *serial_table[SERIAL_TTY_MINORS];
54static DEFINE_MUTEX(table_lock); 53static DEFINE_MUTEX(table_lock);
55static LIST_HEAD(usb_serial_driver_list); 54static LIST_HEAD(usb_serial_driver_list);
@@ -139,7 +138,7 @@ static void destroy_serial(struct kref *kref)
139 if (serial->minor != SERIAL_TTY_NO_MINOR) 138 if (serial->minor != SERIAL_TTY_NO_MINOR)
140 return_serial(serial); 139 return_serial(serial);
141 140
142 if (serial->attached) 141 if (serial->attached && serial->type->release)
143 serial->type->release(serial); 142 serial->type->release(serial);
144 143
145 /* Now that nothing is using the ports, they can be freed */ 144 /* Now that nothing is using the ports, they can be freed */
@@ -225,7 +224,7 @@ static int serial_install(struct tty_driver *driver, struct tty_struct *tty)
225 return retval; 224 return retval;
226} 225}
227 226
228static int serial_activate(struct tty_port *tport, struct tty_struct *tty) 227static int serial_port_activate(struct tty_port *tport, struct tty_struct *tty)
229{ 228{
230 struct usb_serial_port *port = 229 struct usb_serial_port *port =
231 container_of(tport, struct usb_serial_port, port); 230 container_of(tport, struct usb_serial_port, port);
@@ -249,30 +248,27 @@ static int serial_open(struct tty_struct *tty, struct file *filp)
249{ 248{
250 struct usb_serial_port *port = tty->driver_data; 249 struct usb_serial_port *port = tty->driver_data;
251 250
252 dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number); 251 dev_dbg(tty->dev, "%s\n", __func__);
252
253 return tty_port_open(&port->port, tty, filp); 253 return tty_port_open(&port->port, tty, filp);
254} 254}
255 255
256/** 256/**
257 * serial_down - shut down hardware 257 * serial_port_shutdown - shut down hardware
258 * @tport: tty port to shut down 258 * @tport: tty port to shut down
259 * 259 *
260 * Shut down a USB serial port unless it is the console. We never 260 * Shut down a USB serial port. Serialized against activate by the
261 * shut down the console hardware as it will always be in use. Serialized 261 * tport mutex and kept to matching open/close pairs
262 * against activate by the tport mutex and kept to matching open/close pairs
263 * of calls by the ASYNCB_INITIALIZED flag. 262 * of calls by the ASYNCB_INITIALIZED flag.
263 *
264 * Not called if tty is console.
264 */ 265 */
265static void serial_down(struct tty_port *tport) 266static void serial_port_shutdown(struct tty_port *tport)
266{ 267{
267 struct usb_serial_port *port = 268 struct usb_serial_port *port =
268 container_of(tport, struct usb_serial_port, port); 269 container_of(tport, struct usb_serial_port, port);
269 struct usb_serial_driver *drv = port->serial->type; 270 struct usb_serial_driver *drv = port->serial->type;
270 /* 271
271 * The console is magical. Do not hang up the console hardware
272 * or there will be tears.
273 */
274 if (port->port.console)
275 return;
276 if (drv->close) 272 if (drv->close)
277 drv->close(port); 273 drv->close(port);
278} 274}
@@ -281,7 +277,8 @@ static void serial_hangup(struct tty_struct *tty)
281{ 277{
282 struct usb_serial_port *port = tty->driver_data; 278 struct usb_serial_port *port = tty->driver_data;
283 279
284 dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number); 280 dev_dbg(tty->dev, "%s\n", __func__);
281
285 tty_port_hangup(&port->port); 282 tty_port_hangup(&port->port);
286} 283}
287 284
@@ -289,7 +286,8 @@ static void serial_close(struct tty_struct *tty, struct file *filp)
289{ 286{
290 struct usb_serial_port *port = tty->driver_data; 287 struct usb_serial_port *port = tty->driver_data;
291 288
292 dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number); 289 dev_dbg(tty->dev, "%s\n", __func__);
290
293 tty_port_close(&port->port, tty, filp); 291 tty_port_close(&port->port, tty, filp);
294} 292}
295 293
@@ -308,14 +306,14 @@ static void serial_cleanup(struct tty_struct *tty)
308 struct usb_serial *serial; 306 struct usb_serial *serial;
309 struct module *owner; 307 struct module *owner;
310 308
309 dev_dbg(tty->dev, "%s\n", __func__);
310
311 /* The console is magical. Do not hang up the console hardware 311 /* The console is magical. Do not hang up the console hardware
312 * or there will be tears. 312 * or there will be tears.
313 */ 313 */
314 if (port->port.console) 314 if (port->port.console)
315 return; 315 return;
316 316
317 dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number);
318
319 tty->driver_data = NULL; 317 tty->driver_data = NULL;
320 318
321 serial = port->serial; 319 serial = port->serial;
@@ -339,10 +337,8 @@ static int serial_write(struct tty_struct *tty, const unsigned char *buf,
339 if (port->serial->dev->state == USB_STATE_NOTATTACHED) 337 if (port->serial->dev->state == USB_STATE_NOTATTACHED)
340 goto exit; 338 goto exit;
341 339
342 dev_dbg(tty->dev, "%s - port %d, %d byte(s)\n", __func__, 340 dev_dbg(tty->dev, "%s - %d byte(s)\n", __func__, count);
343 port->number, count);
344 341
345 /* pass on to the driver specific version of this function */
346 retval = port->serial->type->write(tty, port, buf, count); 342 retval = port->serial->type->write(tty, port, buf, count);
347 if (retval < 0) 343 if (retval < 0)
348 retval = usb_translate_errors(retval); 344 retval = usb_translate_errors(retval);
@@ -354,8 +350,8 @@ static int serial_write_room(struct tty_struct *tty)
354{ 350{
355 struct usb_serial_port *port = tty->driver_data; 351 struct usb_serial_port *port = tty->driver_data;
356 352
357 dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number); 353 dev_dbg(tty->dev, "%s\n", __func__);
358 /* pass on to the driver specific version of this function */ 354
359 return port->serial->type->write_room(tty); 355 return port->serial->type->write_room(tty);
360} 356}
361 357
@@ -365,7 +361,7 @@ static int serial_chars_in_buffer(struct tty_struct *tty)
365 struct usb_serial *serial = port->serial; 361 struct usb_serial *serial = port->serial;
366 int count = 0; 362 int count = 0;
367 363
368 dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number); 364 dev_dbg(tty->dev, "%s\n", __func__);
369 365
370 mutex_lock(&serial->disc_mutex); 366 mutex_lock(&serial->disc_mutex);
371 /* if the device was unplugged then any remaining characters 367 /* if the device was unplugged then any remaining characters
@@ -383,9 +379,8 @@ static void serial_throttle(struct tty_struct *tty)
383{ 379{
384 struct usb_serial_port *port = tty->driver_data; 380 struct usb_serial_port *port = tty->driver_data;
385 381
386 dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number); 382 dev_dbg(tty->dev, "%s\n", __func__);
387 383
388 /* pass on to the driver specific version of this function */
389 if (port->serial->type->throttle) 384 if (port->serial->type->throttle)
390 port->serial->type->throttle(tty); 385 port->serial->type->throttle(tty);
391} 386}
@@ -394,9 +389,8 @@ static void serial_unthrottle(struct tty_struct *tty)
394{ 389{
395 struct usb_serial_port *port = tty->driver_data; 390 struct usb_serial_port *port = tty->driver_data;
396 391
397 dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number); 392 dev_dbg(tty->dev, "%s\n", __func__);
398 393
399 /* pass on to the driver specific version of this function */
400 if (port->serial->type->unthrottle) 394 if (port->serial->type->unthrottle)
401 port->serial->type->unthrottle(tty); 395 port->serial->type->unthrottle(tty);
402} 396}
@@ -407,15 +401,20 @@ static int serial_ioctl(struct tty_struct *tty,
407 struct usb_serial_port *port = tty->driver_data; 401 struct usb_serial_port *port = tty->driver_data;
408 int retval = -ENODEV; 402 int retval = -ENODEV;
409 403
410 dev_dbg(tty->dev, "%s - port %d, cmd 0x%.4x\n", __func__, 404 dev_dbg(tty->dev, "%s - cmd 0x%.4x\n", __func__, cmd);
411 port->number, cmd); 405
406 switch (cmd) {
407 case TIOCMIWAIT:
408 if (port->serial->type->tiocmiwait)
409 retval = port->serial->type->tiocmiwait(tty, arg);
410 break;
411 default:
412 if (port->serial->type->ioctl)
413 retval = port->serial->type->ioctl(tty, cmd, arg);
414 else
415 retval = -ENOIOCTLCMD;
416 }
412 417
413 /* pass on to the driver specific version of this function
414 if it is available */
415 if (port->serial->type->ioctl) {
416 retval = port->serial->type->ioctl(tty, cmd, arg);
417 } else
418 retval = -ENOIOCTLCMD;
419 return retval; 418 return retval;
420} 419}
421 420
@@ -423,10 +422,8 @@ static void serial_set_termios(struct tty_struct *tty, struct ktermios *old)
423{ 422{
424 struct usb_serial_port *port = tty->driver_data; 423 struct usb_serial_port *port = tty->driver_data;
425 424
426 dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number); 425 dev_dbg(tty->dev, "%s\n", __func__);
427 426
428 /* pass on to the driver specific version of this function
429 if it is available */
430 if (port->serial->type->set_termios) 427 if (port->serial->type->set_termios)
431 port->serial->type->set_termios(tty, port, old); 428 port->serial->type->set_termios(tty, port, old);
432 else 429 else
@@ -437,12 +434,11 @@ static int serial_break(struct tty_struct *tty, int break_state)
437{ 434{
438 struct usb_serial_port *port = tty->driver_data; 435 struct usb_serial_port *port = tty->driver_data;
439 436
440 dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number); 437 dev_dbg(tty->dev, "%s\n", __func__);
441 438
442 /* pass on to the driver specific version of this function
443 if it is available */
444 if (port->serial->type->break_ctl) 439 if (port->serial->type->break_ctl)
445 port->serial->type->break_ctl(tty, break_state); 440 port->serial->type->break_ctl(tty, break_state);
441
446 return 0; 442 return 0;
447} 443}
448 444
@@ -496,7 +492,7 @@ static int serial_tiocmget(struct tty_struct *tty)
496{ 492{
497 struct usb_serial_port *port = tty->driver_data; 493 struct usb_serial_port *port = tty->driver_data;
498 494
499 dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number); 495 dev_dbg(tty->dev, "%s\n", __func__);
500 496
501 if (port->serial->type->tiocmget) 497 if (port->serial->type->tiocmget)
502 return port->serial->type->tiocmget(tty); 498 return port->serial->type->tiocmget(tty);
@@ -508,7 +504,7 @@ static int serial_tiocmset(struct tty_struct *tty,
508{ 504{
509 struct usb_serial_port *port = tty->driver_data; 505 struct usb_serial_port *port = tty->driver_data;
510 506
511 dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number); 507 dev_dbg(tty->dev, "%s\n", __func__);
512 508
513 if (port->serial->type->tiocmset) 509 if (port->serial->type->tiocmset)
514 return port->serial->type->tiocmset(tty, set, clear); 510 return port->serial->type->tiocmset(tty, set, clear);
@@ -520,7 +516,7 @@ static int serial_get_icount(struct tty_struct *tty,
520{ 516{
521 struct usb_serial_port *port = tty->driver_data; 517 struct usb_serial_port *port = tty->driver_data;
522 518
523 dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number); 519 dev_dbg(tty->dev, "%s\n", __func__);
524 520
525 if (port->serial->type->get_icount) 521 if (port->serial->type->get_icount)
526 return port->serial->type->get_icount(tty, icount); 522 return port->serial->type->get_icount(tty, icount);
@@ -548,49 +544,45 @@ static void usb_serial_port_work(struct work_struct *work)
548 if (!tty) 544 if (!tty)
549 return; 545 return;
550 546
551 dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number); 547 dev_dbg(tty->dev, "%s\n", __func__);
552 548
553 tty_wakeup(tty); 549 tty_wakeup(tty);
554 tty_kref_put(tty); 550 tty_kref_put(tty);
555} 551}
556 552
557static void kill_traffic(struct usb_serial_port *port) 553static void usb_serial_port_poison_urbs(struct usb_serial_port *port)
558{ 554{
559 int i; 555 int i;
560 556
561 for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) 557 for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i)
562 usb_kill_urb(port->read_urbs[i]); 558 usb_poison_urb(port->read_urbs[i]);
563 for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i) 559 for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i)
564 usb_kill_urb(port->write_urbs[i]); 560 usb_poison_urb(port->write_urbs[i]);
565 /* 561
566 * This is tricky. 562 usb_poison_urb(port->interrupt_in_urb);
567 * Some drivers submit the read_urb in the 563 usb_poison_urb(port->interrupt_out_urb);
568 * handler for the write_urb or vice versa 564}
569 * this order determines the order in which 565
570 * usb_kill_urb() must be used to reliably 566static void usb_serial_port_unpoison_urbs(struct usb_serial_port *port)
571 * kill the URBs. As it is unknown here, 567{
572 * both orders must be used in turn. 568 int i;
573 * The call below is not redundant. 569
574 */ 570 for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i)
575 usb_kill_urb(port->read_urb); 571 usb_unpoison_urb(port->read_urbs[i]);
576 usb_kill_urb(port->interrupt_in_urb); 572 for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i)
577 usb_kill_urb(port->interrupt_out_urb); 573 usb_unpoison_urb(port->write_urbs[i]);
574
575 usb_unpoison_urb(port->interrupt_in_urb);
576 usb_unpoison_urb(port->interrupt_out_urb);
578} 577}
579 578
580static void port_release(struct device *dev) 579static void usb_serial_port_release(struct device *dev)
581{ 580{
582 struct usb_serial_port *port = to_usb_serial_port(dev); 581 struct usb_serial_port *port = to_usb_serial_port(dev);
583 int i; 582 int i;
584 583
585 dev_dbg(dev, "%s\n", __func__); 584 dev_dbg(dev, "%s\n", __func__);
586 585
587 /*
588 * Stop all the traffic before cancelling the work, so that
589 * nobody will restart it by calling usb_serial_port_softint.
590 */
591 kill_traffic(port);
592 cancel_work_sync(&port->work);
593
594 usb_free_urb(port->interrupt_in_urb); 586 usb_free_urb(port->interrupt_in_urb);
595 usb_free_urb(port->interrupt_out_urb); 587 usb_free_urb(port->interrupt_out_urb);
596 for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) { 588 for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) {
@@ -615,10 +607,8 @@ static struct usb_serial *create_serial(struct usb_device *dev,
615 struct usb_serial *serial; 607 struct usb_serial *serial;
616 608
617 serial = kzalloc(sizeof(*serial), GFP_KERNEL); 609 serial = kzalloc(sizeof(*serial), GFP_KERNEL);
618 if (!serial) { 610 if (!serial)
619 dev_err(&dev->dev, "%s - out of memory\n", __func__);
620 return NULL; 611 return NULL;
621 }
622 serial->dev = usb_get_dev(dev); 612 serial->dev = usb_get_dev(dev);
623 serial->type = driver; 613 serial->type = driver;
624 serial->interface = usb_get_intf(interface); 614 serial->interface = usb_get_intf(interface);
@@ -681,7 +671,7 @@ static struct usb_serial_driver *search_serial_device(
681 return NULL; 671 return NULL;
682} 672}
683 673
684static int serial_carrier_raised(struct tty_port *port) 674static int serial_port_carrier_raised(struct tty_port *port)
685{ 675{
686 struct usb_serial_port *p = container_of(port, struct usb_serial_port, port); 676 struct usb_serial_port *p = container_of(port, struct usb_serial_port, port);
687 struct usb_serial_driver *drv = p->serial->type; 677 struct usb_serial_driver *drv = p->serial->type;
@@ -692,7 +682,7 @@ static int serial_carrier_raised(struct tty_port *port)
692 return 1; 682 return 1;
693} 683}
694 684
695static void serial_dtr_rts(struct tty_port *port, int on) 685static void serial_port_dtr_rts(struct tty_port *port, int on)
696{ 686{
697 struct usb_serial_port *p = container_of(port, struct usb_serial_port, port); 687 struct usb_serial_port *p = container_of(port, struct usb_serial_port, port);
698 struct usb_serial *serial = p->serial; 688 struct usb_serial *serial = p->serial;
@@ -712,10 +702,10 @@ static void serial_dtr_rts(struct tty_port *port, int on)
712} 702}
713 703
714static const struct tty_port_operations serial_port_ops = { 704static const struct tty_port_operations serial_port_ops = {
715 .carrier_raised = serial_carrier_raised, 705 .carrier_raised = serial_port_carrier_raised,
716 .dtr_rts = serial_dtr_rts, 706 .dtr_rts = serial_port_dtr_rts,
717 .activate = serial_activate, 707 .activate = serial_port_activate,
718 .shutdown = serial_down, 708 .shutdown = serial_port_shutdown,
719}; 709};
720 710
721static int usb_serial_probe(struct usb_interface *interface, 711static int usb_serial_probe(struct usb_interface *interface,
@@ -762,7 +752,6 @@ static int usb_serial_probe(struct usb_interface *interface,
762 serial = create_serial(dev, interface, type); 752 serial = create_serial(dev, interface, type);
763 if (!serial) { 753 if (!serial) {
764 module_put(type->driver.owner); 754 module_put(type->driver.owner);
765 dev_err(ddev, "%s - out of memory\n", __func__);
766 return -ENOMEM; 755 return -ENOMEM;
767 } 756 }
768 757
@@ -903,7 +892,6 @@ static int usb_serial_probe(struct usb_interface *interface,
903 port->port.ops = &serial_port_ops; 892 port->port.ops = &serial_port_ops;
904 port->serial = serial; 893 port->serial = serial;
905 spin_lock_init(&port->lock); 894 spin_lock_init(&port->lock);
906 init_waitqueue_head(&port->delta_msr_wait);
907 /* Keep this for private driver use for the moment but 895 /* Keep this for private driver use for the moment but
908 should probably go away */ 896 should probably go away */
909 INIT_WORK(&port->work, usb_serial_port_work); 897 INIT_WORK(&port->work, usb_serial_port_work);
@@ -911,7 +899,7 @@ static int usb_serial_probe(struct usb_interface *interface,
911 port->dev.parent = &interface->dev; 899 port->dev.parent = &interface->dev;
912 port->dev.driver = NULL; 900 port->dev.driver = NULL;
913 port->dev.bus = &usb_serial_bus_type; 901 port->dev.bus = &usb_serial_bus_type;
914 port->dev.release = &port_release; 902 port->dev.release = &usb_serial_port_release;
915 device_initialize(&port->dev); 903 device_initialize(&port->dev);
916 } 904 }
917 905
@@ -927,16 +915,12 @@ static int usb_serial_probe(struct usb_interface *interface,
927 for (j = 0; j < ARRAY_SIZE(port->read_urbs); ++j) { 915 for (j = 0; j < ARRAY_SIZE(port->read_urbs); ++j) {
928 set_bit(j, &port->read_urbs_free); 916 set_bit(j, &port->read_urbs_free);
929 port->read_urbs[j] = usb_alloc_urb(0, GFP_KERNEL); 917 port->read_urbs[j] = usb_alloc_urb(0, GFP_KERNEL);
930 if (!port->read_urbs[j]) { 918 if (!port->read_urbs[j])
931 dev_err(ddev, "No free urbs available\n");
932 goto probe_error; 919 goto probe_error;
933 }
934 port->bulk_in_buffers[j] = kmalloc(buffer_size, 920 port->bulk_in_buffers[j] = kmalloc(buffer_size,
935 GFP_KERNEL); 921 GFP_KERNEL);
936 if (!port->bulk_in_buffers[j]) { 922 if (!port->bulk_in_buffers[j])
937 dev_err(ddev, "Couldn't allocate bulk_in_buffer\n");
938 goto probe_error; 923 goto probe_error;
939 }
940 usb_fill_bulk_urb(port->read_urbs[j], dev, 924 usb_fill_bulk_urb(port->read_urbs[j], dev,
941 usb_rcvbulkpipe(dev, 925 usb_rcvbulkpipe(dev,
942 endpoint->bEndpointAddress), 926 endpoint->bEndpointAddress),
@@ -963,16 +947,12 @@ static int usb_serial_probe(struct usb_interface *interface,
963 for (j = 0; j < ARRAY_SIZE(port->write_urbs); ++j) { 947 for (j = 0; j < ARRAY_SIZE(port->write_urbs); ++j) {
964 set_bit(j, &port->write_urbs_free); 948 set_bit(j, &port->write_urbs_free);
965 port->write_urbs[j] = usb_alloc_urb(0, GFP_KERNEL); 949 port->write_urbs[j] = usb_alloc_urb(0, GFP_KERNEL);
966 if (!port->write_urbs[j]) { 950 if (!port->write_urbs[j])
967 dev_err(ddev, "No free urbs available\n");
968 goto probe_error; 951 goto probe_error;
969 }
970 port->bulk_out_buffers[j] = kmalloc(buffer_size, 952 port->bulk_out_buffers[j] = kmalloc(buffer_size,
971 GFP_KERNEL); 953 GFP_KERNEL);
972 if (!port->bulk_out_buffers[j]) { 954 if (!port->bulk_out_buffers[j])
973 dev_err(ddev, "Couldn't allocate bulk_out_buffer\n");
974 goto probe_error; 955 goto probe_error;
975 }
976 usb_fill_bulk_urb(port->write_urbs[j], dev, 956 usb_fill_bulk_urb(port->write_urbs[j], dev,
977 usb_sndbulkpipe(dev, 957 usb_sndbulkpipe(dev,
978 endpoint->bEndpointAddress), 958 endpoint->bEndpointAddress),
@@ -990,19 +970,15 @@ static int usb_serial_probe(struct usb_interface *interface,
990 endpoint = interrupt_in_endpoint[i]; 970 endpoint = interrupt_in_endpoint[i];
991 port = serial->port[i]; 971 port = serial->port[i];
992 port->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL); 972 port->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL);
993 if (!port->interrupt_in_urb) { 973 if (!port->interrupt_in_urb)
994 dev_err(ddev, "No free urbs available\n");
995 goto probe_error; 974 goto probe_error;
996 }
997 buffer_size = usb_endpoint_maxp(endpoint); 975 buffer_size = usb_endpoint_maxp(endpoint);
998 port->interrupt_in_endpointAddress = 976 port->interrupt_in_endpointAddress =
999 endpoint->bEndpointAddress; 977 endpoint->bEndpointAddress;
1000 port->interrupt_in_buffer = kmalloc(buffer_size, 978 port->interrupt_in_buffer = kmalloc(buffer_size,
1001 GFP_KERNEL); 979 GFP_KERNEL);
1002 if (!port->interrupt_in_buffer) { 980 if (!port->interrupt_in_buffer)
1003 dev_err(ddev, "Couldn't allocate interrupt_in_buffer\n");
1004 goto probe_error; 981 goto probe_error;
1005 }
1006 usb_fill_int_urb(port->interrupt_in_urb, dev, 982 usb_fill_int_urb(port->interrupt_in_urb, dev,
1007 usb_rcvintpipe(dev, 983 usb_rcvintpipe(dev,
1008 endpoint->bEndpointAddress), 984 endpoint->bEndpointAddress),
@@ -1019,20 +995,16 @@ static int usb_serial_probe(struct usb_interface *interface,
1019 endpoint = interrupt_out_endpoint[i]; 995 endpoint = interrupt_out_endpoint[i];
1020 port = serial->port[i]; 996 port = serial->port[i];
1021 port->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL); 997 port->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL);
1022 if (!port->interrupt_out_urb) { 998 if (!port->interrupt_out_urb)
1023 dev_err(ddev, "No free urbs available\n");
1024 goto probe_error; 999 goto probe_error;
1025 }
1026 buffer_size = usb_endpoint_maxp(endpoint); 1000 buffer_size = usb_endpoint_maxp(endpoint);
1027 port->interrupt_out_size = buffer_size; 1001 port->interrupt_out_size = buffer_size;
1028 port->interrupt_out_endpointAddress = 1002 port->interrupt_out_endpointAddress =
1029 endpoint->bEndpointAddress; 1003 endpoint->bEndpointAddress;
1030 port->interrupt_out_buffer = kmalloc(buffer_size, 1004 port->interrupt_out_buffer = kmalloc(buffer_size,
1031 GFP_KERNEL); 1005 GFP_KERNEL);
1032 if (!port->interrupt_out_buffer) { 1006 if (!port->interrupt_out_buffer)
1033 dev_err(ddev, "Couldn't allocate interrupt_out_buffer\n");
1034 goto probe_error; 1007 goto probe_error;
1035 }
1036 usb_fill_int_urb(port->interrupt_out_urb, dev, 1008 usb_fill_int_urb(port->interrupt_out_urb, dev,
1037 usb_sndintpipe(dev, 1009 usb_sndintpipe(dev,
1038 endpoint->bEndpointAddress), 1010 endpoint->bEndpointAddress),
@@ -1121,13 +1093,15 @@ static void usb_serial_disconnect(struct usb_interface *interface)
1121 tty_vhangup(tty); 1093 tty_vhangup(tty);
1122 tty_kref_put(tty); 1094 tty_kref_put(tty);
1123 } 1095 }
1124 kill_traffic(port); 1096 usb_serial_port_poison_urbs(port);
1097 wake_up_interruptible(&port->port.delta_msr_wait);
1125 cancel_work_sync(&port->work); 1098 cancel_work_sync(&port->work);
1126 if (device_is_registered(&port->dev)) 1099 if (device_is_registered(&port->dev))
1127 device_del(&port->dev); 1100 device_del(&port->dev);
1128 } 1101 }
1129 } 1102 }
1130 serial->type->disconnect(serial); 1103 if (serial->type->disconnect)
1104 serial->type->disconnect(serial);
1131 1105
1132 /* let the last holder of this object cause it to be cleaned up */ 1106 /* let the last holder of this object cause it to be cleaned up */
1133 usb_serial_put(serial); 1107 usb_serial_put(serial);
@@ -1142,6 +1116,11 @@ int usb_serial_suspend(struct usb_interface *intf, pm_message_t message)
1142 1116
1143 serial->suspending = 1; 1117 serial->suspending = 1;
1144 1118
1119 /*
1120 * serial->type->suspend() MUST return 0 in system sleep context,
1121 * otherwise, the resume callback has to recover device from
1122 * previous suspend failure.
1123 */
1145 if (serial->type->suspend) { 1124 if (serial->type->suspend) {
1146 r = serial->type->suspend(serial, message); 1125 r = serial->type->suspend(serial, message);
1147 if (r < 0) { 1126 if (r < 0) {
@@ -1153,7 +1132,7 @@ int usb_serial_suspend(struct usb_interface *intf, pm_message_t message)
1153 for (i = 0; i < serial->num_ports; ++i) { 1132 for (i = 0; i < serial->num_ports; ++i) {
1154 port = serial->port[i]; 1133 port = serial->port[i];
1155 if (port) 1134 if (port)
1156 kill_traffic(port); 1135 usb_serial_port_poison_urbs(port);
1157 } 1136 }
1158 1137
1159err_out: 1138err_out:
@@ -1161,11 +1140,25 @@ err_out:
1161} 1140}
1162EXPORT_SYMBOL(usb_serial_suspend); 1141EXPORT_SYMBOL(usb_serial_suspend);
1163 1142
1143static void usb_serial_unpoison_port_urbs(struct usb_serial *serial)
1144{
1145 struct usb_serial_port *port;
1146 int i;
1147
1148 for (i = 0; i < serial->num_ports; ++i) {
1149 port = serial->port[i];
1150 if (port)
1151 usb_serial_port_unpoison_urbs(port);
1152 }
1153}
1154
1164int usb_serial_resume(struct usb_interface *intf) 1155int usb_serial_resume(struct usb_interface *intf)
1165{ 1156{
1166 struct usb_serial *serial = usb_get_intfdata(intf); 1157 struct usb_serial *serial = usb_get_intfdata(intf);
1167 int rv; 1158 int rv;
1168 1159
1160 usb_serial_unpoison_port_urbs(serial);
1161
1169 serial->suspending = 0; 1162 serial->suspending = 0;
1170 if (serial->type->resume) 1163 if (serial->type->resume)
1171 rv = serial->type->resume(serial); 1164 rv = serial->type->resume(serial);
@@ -1181,6 +1174,8 @@ static int usb_serial_reset_resume(struct usb_interface *intf)
1181 struct usb_serial *serial = usb_get_intfdata(intf); 1174 struct usb_serial *serial = usb_get_intfdata(intf);
1182 int rv; 1175 int rv;
1183 1176
1177 usb_serial_unpoison_port_urbs(serial);
1178
1184 serial->suspending = 0; 1179 serial->suspending = 0;
1185 if (serial->type->reset_resume) 1180 if (serial->type->reset_resume)
1186 rv = serial->type->reset_resume(serial); 1181 rv = serial->type->reset_resume(serial);
@@ -1317,12 +1312,12 @@ module_exit(usb_serial_exit);
1317 do { \ 1312 do { \
1318 if (!type->function) { \ 1313 if (!type->function) { \
1319 type->function = usb_serial_generic_##function; \ 1314 type->function = usb_serial_generic_##function; \
1320 pr_debug("Had to override the " #function \ 1315 pr_debug("%s: using generic " #function "\n", \
1321 " usb serial operation with the generic one.");\ 1316 type->driver.name); \
1322 } \ 1317 } \
1323 } while (0) 1318 } while (0)
1324 1319
1325static void fixup_generic(struct usb_serial_driver *device) 1320static void usb_serial_operations_init(struct usb_serial_driver *device)
1326{ 1321{
1327 set_to_generic_if_null(device, open); 1322 set_to_generic_if_null(device, open);
1328 set_to_generic_if_null(device, write); 1323 set_to_generic_if_null(device, write);
@@ -1331,8 +1326,6 @@ static void fixup_generic(struct usb_serial_driver *device)
1331 set_to_generic_if_null(device, chars_in_buffer); 1326 set_to_generic_if_null(device, chars_in_buffer);
1332 set_to_generic_if_null(device, read_bulk_callback); 1327 set_to_generic_if_null(device, read_bulk_callback);
1333 set_to_generic_if_null(device, write_bulk_callback); 1328 set_to_generic_if_null(device, write_bulk_callback);
1334 set_to_generic_if_null(device, disconnect);
1335 set_to_generic_if_null(device, release);
1336 set_to_generic_if_null(device, process_read_urb); 1329 set_to_generic_if_null(device, process_read_urb);
1337 set_to_generic_if_null(device, prepare_write_buffer); 1330 set_to_generic_if_null(device, prepare_write_buffer);
1338} 1331}
@@ -1344,8 +1337,6 @@ static int usb_serial_register(struct usb_serial_driver *driver)
1344 if (usb_disabled()) 1337 if (usb_disabled())
1345 return -ENODEV; 1338 return -ENODEV;
1346 1339
1347 fixup_generic(driver);
1348
1349 if (!driver->description) 1340 if (!driver->description)
1350 driver->description = driver->driver.name; 1341 driver->description = driver->driver.name;
1351 if (!driver->usb_driver) { 1342 if (!driver->usb_driver) {
@@ -1354,6 +1345,8 @@ static int usb_serial_register(struct usb_serial_driver *driver)
1354 return -EINVAL; 1345 return -EINVAL;
1355 } 1346 }
1356 1347
1348 usb_serial_operations_init(driver);
1349
1357 /* Add this device to our list of devices */ 1350 /* Add this device to our list of devices */
1358 mutex_lock(&table_lock); 1351 mutex_lock(&table_lock);
1359 list_add(&driver->driver_list, &usb_serial_driver_list); 1352 list_add(&driver->driver_list, &usb_serial_driver_list);
@@ -1471,7 +1464,6 @@ void usb_serial_deregister_drivers(struct usb_serial_driver *const serial_driver
1471} 1464}
1472EXPORT_SYMBOL_GPL(usb_serial_deregister_drivers); 1465EXPORT_SYMBOL_GPL(usb_serial_deregister_drivers);
1473 1466
1474/* Module information */
1475MODULE_AUTHOR(DRIVER_AUTHOR); 1467MODULE_AUTHOR(DRIVER_AUTHOR);
1476MODULE_DESCRIPTION(DRIVER_DESC); 1468MODULE_DESCRIPTION(DRIVER_DESC);
1477MODULE_LICENSE("GPL"); 1469MODULE_LICENSE("GPL");
diff --git a/drivers/usb/serial/usb_wwan.c b/drivers/usb/serial/usb_wwan.c
index 571965aa1cc0..ece326ef63a0 100644
--- a/drivers/usb/serial/usb_wwan.c
+++ b/drivers/usb/serial/usb_wwan.c
@@ -421,20 +421,19 @@ void usb_wwan_close(struct usb_serial_port *port)
421 421
422 portdata = usb_get_serial_port_data(port); 422 portdata = usb_get_serial_port_data(port);
423 423
424 if (serial->dev) { 424 /* Stop reading/writing urbs */
425 /* Stop reading/writing urbs */ 425 spin_lock_irq(&intfdata->susp_lock);
426 spin_lock_irq(&intfdata->susp_lock); 426 portdata->opened = 0;
427 portdata->opened = 0; 427 spin_unlock_irq(&intfdata->susp_lock);
428 spin_unlock_irq(&intfdata->susp_lock);
429 428
430 for (i = 0; i < N_IN_URB; i++) 429 for (i = 0; i < N_IN_URB; i++)
431 usb_kill_urb(portdata->in_urbs[i]); 430 usb_kill_urb(portdata->in_urbs[i]);
432 for (i = 0; i < N_OUT_URB; i++) 431 for (i = 0; i < N_OUT_URB; i++)
433 usb_kill_urb(portdata->out_urbs[i]); 432 usb_kill_urb(portdata->out_urbs[i]);
434 /* balancing - important as an error cannot be handled*/ 433
435 usb_autopm_get_interface_no_resume(serial->interface); 434 /* balancing - important as an error cannot be handled*/
436 serial->interface->needs_remote_wakeup = 0; 435 usb_autopm_get_interface_no_resume(serial->interface);
437 } 436 serial->interface->needs_remote_wakeup = 0;
438} 437}
439EXPORT_SYMBOL(usb_wwan_close); 438EXPORT_SYMBOL(usb_wwan_close);
440 439
diff --git a/drivers/usb/serial/visor.c b/drivers/usb/serial/visor.c
index 1129aa73c23e..7573ec8a084f 100644
--- a/drivers/usb/serial/visor.c
+++ b/drivers/usb/serial/visor.c
@@ -257,24 +257,18 @@ static void visor_close(struct usb_serial_port *port)
257{ 257{
258 unsigned char *transfer_buffer; 258 unsigned char *transfer_buffer;
259 259
260 /* shutdown our urbs */
261 usb_serial_generic_close(port); 260 usb_serial_generic_close(port);
262 usb_kill_urb(port->interrupt_in_urb); 261 usb_kill_urb(port->interrupt_in_urb);
263 262
264 mutex_lock(&port->serial->disc_mutex); 263 transfer_buffer = kmalloc(0x12, GFP_KERNEL);
265 if (!port->serial->disconnected) { 264 if (!transfer_buffer)
266 /* Try to send shutdown message, unless the device is gone */ 265 return;
267 transfer_buffer = kmalloc(0x12, GFP_KERNEL); 266 usb_control_msg(port->serial->dev,
268 if (transfer_buffer) {
269 usb_control_msg(port->serial->dev,
270 usb_rcvctrlpipe(port->serial->dev, 0), 267 usb_rcvctrlpipe(port->serial->dev, 0),
271 VISOR_CLOSE_NOTIFICATION, 0xc2, 268 VISOR_CLOSE_NOTIFICATION, 0xc2,
272 0x0000, 0x0000, 269 0x0000, 0x0000,
273 transfer_buffer, 0x12, 300); 270 transfer_buffer, 0x12, 300);
274 kfree(transfer_buffer); 271 kfree(transfer_buffer);
275 }
276 }
277 mutex_unlock(&port->serial->disc_mutex);
278} 272}
279 273
280static void visor_read_int_callback(struct urb *urb) 274static void visor_read_int_callback(struct urb *urb)
diff --git a/drivers/usb/storage/isd200.c b/drivers/usb/storage/isd200.c
index ecea47877364..06a3d22db685 100644
--- a/drivers/usb/storage/isd200.c
+++ b/drivers/usb/storage/isd200.c
@@ -1457,8 +1457,7 @@ static int isd200_init_info(struct us_data *us)
1457 retStatus = ISD200_ERROR; 1457 retStatus = ISD200_ERROR;
1458 else { 1458 else {
1459 info->id = kzalloc(ATA_ID_WORDS * 2, GFP_KERNEL); 1459 info->id = kzalloc(ATA_ID_WORDS * 2, GFP_KERNEL);
1460 info->RegsBuf = (unsigned char *) 1460 info->RegsBuf = kmalloc(sizeof(info->ATARegs), GFP_KERNEL);
1461 kmalloc(sizeof(info->ATARegs), GFP_KERNEL);
1462 info->srb.sense_buffer = 1461 info->srb.sense_buffer =
1463 kmalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL); 1462 kmalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL);
1464 if (!info->id || !info->RegsBuf || !info->srb.sense_buffer) { 1463 if (!info->id || !info->RegsBuf || !info->srb.sense_buffer) {
diff --git a/drivers/usb/storage/onetouch.c b/drivers/usb/storage/onetouch.c
index cb79de61f4c8..26964895c88b 100644
--- a/drivers/usb/storage/onetouch.c
+++ b/drivers/usb/storage/onetouch.c
@@ -195,6 +195,7 @@ static int onetouch_connect_input(struct us_data *ss)
195 195
196 pipe = usb_rcvintpipe(udev, endpoint->bEndpointAddress); 196 pipe = usb_rcvintpipe(udev, endpoint->bEndpointAddress);
197 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe)); 197 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
198 maxp = min(maxp, ONETOUCH_PKT_LEN);
198 199
199 onetouch = kzalloc(sizeof(struct usb_onetouch), GFP_KERNEL); 200 onetouch = kzalloc(sizeof(struct usb_onetouch), GFP_KERNEL);
200 input_dev = input_allocate_device(); 201 input_dev = input_allocate_device();
@@ -245,8 +246,7 @@ static int onetouch_connect_input(struct us_data *ss)
245 input_dev->open = usb_onetouch_open; 246 input_dev->open = usb_onetouch_open;
246 input_dev->close = usb_onetouch_close; 247 input_dev->close = usb_onetouch_close;
247 248
248 usb_fill_int_urb(onetouch->irq, udev, pipe, onetouch->data, 249 usb_fill_int_urb(onetouch->irq, udev, pipe, onetouch->data, maxp,
249 (maxp > 8 ? 8 : maxp),
250 usb_onetouch_irq, onetouch, endpoint->bInterval); 250 usb_onetouch_irq, onetouch, endpoint->bInterval);
251 onetouch->irq->transfer_dma = onetouch->data_dma; 251 onetouch->irq->transfer_dma = onetouch->data_dma;
252 onetouch->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 252 onetouch->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
diff --git a/drivers/usb/usb-common.c b/drivers/usb/usb-common.c
index d29503e954ab..0db0a919d72b 100644
--- a/drivers/usb/usb-common.c
+++ b/drivers/usb/usb-common.c
@@ -14,6 +14,32 @@
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/usb/ch9.h> 16#include <linux/usb/ch9.h>
17#include <linux/usb/otg.h>
18
19const char *usb_otg_state_string(enum usb_otg_state state)
20{
21 static const char *const names[] = {
22 [OTG_STATE_A_IDLE] = "a_idle",
23 [OTG_STATE_A_WAIT_VRISE] = "a_wait_vrise",
24 [OTG_STATE_A_WAIT_BCON] = "a_wait_bcon",
25 [OTG_STATE_A_HOST] = "a_host",
26 [OTG_STATE_A_SUSPEND] = "a_suspend",
27 [OTG_STATE_A_PERIPHERAL] = "a_peripheral",
28 [OTG_STATE_A_WAIT_VFALL] = "a_wait_vfall",
29 [OTG_STATE_A_VBUS_ERR] = "a_vbus_err",
30 [OTG_STATE_B_IDLE] = "b_idle",
31 [OTG_STATE_B_SRP_INIT] = "b_srp_init",
32 [OTG_STATE_B_PERIPHERAL] = "b_peripheral",
33 [OTG_STATE_B_WAIT_ACON] = "b_wait_acon",
34 [OTG_STATE_B_HOST] = "b_host",
35 };
36
37 if (state < 0 || state >= ARRAY_SIZE(names))
38 return "UNDEFINED";
39
40 return names[state];
41}
42EXPORT_SYMBOL_GPL(usb_otg_state_string);
17 43
18const char *usb_speed_string(enum usb_device_speed speed) 44const char *usb_speed_string(enum usb_device_speed speed)
19{ 45{
@@ -32,4 +58,25 @@ const char *usb_speed_string(enum usb_device_speed speed)
32} 58}
33EXPORT_SYMBOL_GPL(usb_speed_string); 59EXPORT_SYMBOL_GPL(usb_speed_string);
34 60
61const char *usb_state_string(enum usb_device_state state)
62{
63 static const char *const names[] = {
64 [USB_STATE_NOTATTACHED] = "not attached",
65 [USB_STATE_ATTACHED] = "attached",
66 [USB_STATE_POWERED] = "powered",
67 [USB_STATE_RECONNECTING] = "reconnecting",
68 [USB_STATE_UNAUTHENTICATED] = "unauthenticated",
69 [USB_STATE_DEFAULT] = "default",
70 [USB_STATE_ADDRESS] = "addresssed",
71 [USB_STATE_CONFIGURED] = "configured",
72 [USB_STATE_SUSPENDED] = "suspended",
73 };
74
75 if (state < 0 || state >= ARRAY_SIZE(names))
76 return "UNKNOWN";
77
78 return names[state];
79}
80EXPORT_SYMBOL_GPL(usb_state_string);
81
35MODULE_LICENSE("GPL"); 82MODULE_LICENSE("GPL");
diff --git a/drivers/usb/usb-skeleton.c b/drivers/usb/usb-skeleton.c
index ce310170829f..7ed3b039dbe8 100644
--- a/drivers/usb/usb-skeleton.c
+++ b/drivers/usb/usb-skeleton.c
@@ -61,11 +61,10 @@ struct usb_skel {
61 __u8 bulk_out_endpointAddr; /* the address of the bulk out endpoint */ 61 __u8 bulk_out_endpointAddr; /* the address of the bulk out endpoint */
62 int errors; /* the last request tanked */ 62 int errors; /* the last request tanked */
63 bool ongoing_read; /* a read is going on */ 63 bool ongoing_read; /* a read is going on */
64 bool processed_urb; /* indicates we haven't processed the urb */
65 spinlock_t err_lock; /* lock for errors */ 64 spinlock_t err_lock; /* lock for errors */
66 struct kref kref; 65 struct kref kref;
67 struct mutex io_mutex; /* synchronize I/O with disconnect */ 66 struct mutex io_mutex; /* synchronize I/O with disconnect */
68 struct completion bulk_in_completion; /* to wait for an ongoing read */ 67 wait_queue_head_t bulk_in_wait; /* to wait for an ongoing read */
69}; 68};
70#define to_skel_dev(d) container_of(d, struct usb_skel, kref) 69#define to_skel_dev(d) container_of(d, struct usb_skel, kref)
71 70
@@ -185,7 +184,7 @@ static void skel_read_bulk_callback(struct urb *urb)
185 dev->ongoing_read = 0; 184 dev->ongoing_read = 0;
186 spin_unlock(&dev->err_lock); 185 spin_unlock(&dev->err_lock);
187 186
188 complete(&dev->bulk_in_completion); 187 wake_up_interruptible(&dev->bulk_in_wait);
189} 188}
190 189
191static int skel_do_read_io(struct usb_skel *dev, size_t count) 190static int skel_do_read_io(struct usb_skel *dev, size_t count)
@@ -206,13 +205,16 @@ static int skel_do_read_io(struct usb_skel *dev, size_t count)
206 dev->ongoing_read = 1; 205 dev->ongoing_read = 1;
207 spin_unlock_irq(&dev->err_lock); 206 spin_unlock_irq(&dev->err_lock);
208 207
208 /* submit bulk in urb, which means no data to deliver */
209 dev->bulk_in_filled = 0;
210 dev->bulk_in_copied = 0;
211
209 /* do it */ 212 /* do it */
210 rv = usb_submit_urb(dev->bulk_in_urb, GFP_KERNEL); 213 rv = usb_submit_urb(dev->bulk_in_urb, GFP_KERNEL);
211 if (rv < 0) { 214 if (rv < 0) {
212 dev_err(&dev->interface->dev, 215 dev_err(&dev->interface->dev,
213 "%s - failed submitting read urb, error %d\n", 216 "%s - failed submitting read urb, error %d\n",
214 __func__, rv); 217 __func__, rv);
215 dev->bulk_in_filled = 0;
216 rv = (rv == -ENOMEM) ? rv : -EIO; 218 rv = (rv == -ENOMEM) ? rv : -EIO;
217 spin_lock_irq(&dev->err_lock); 219 spin_lock_irq(&dev->err_lock);
218 dev->ongoing_read = 0; 220 dev->ongoing_read = 0;
@@ -261,25 +263,9 @@ retry:
261 * IO may take forever 263 * IO may take forever
262 * hence wait in an interruptible state 264 * hence wait in an interruptible state
263 */ 265 */
264 rv = wait_for_completion_interruptible(&dev->bulk_in_completion); 266 rv = wait_event_interruptible(dev->bulk_in_wait, (!dev->ongoing_read));
265 if (rv < 0) 267 if (rv < 0)
266 goto exit; 268 goto exit;
267 /*
268 * by waiting we also semiprocessed the urb
269 * we must finish now
270 */
271 dev->bulk_in_copied = 0;
272 dev->processed_urb = 1;
273 }
274
275 if (!dev->processed_urb) {
276 /*
277 * the URB hasn't been processed
278 * do it now
279 */
280 wait_for_completion(&dev->bulk_in_completion);
281 dev->bulk_in_copied = 0;
282 dev->processed_urb = 1;
283 } 269 }
284 270
285 /* errors must be reported */ 271 /* errors must be reported */
@@ -289,8 +275,6 @@ retry:
289 dev->errors = 0; 275 dev->errors = 0;
290 /* to preserve notifications about reset */ 276 /* to preserve notifications about reset */
291 rv = (rv == -EPIPE) ? rv : -EIO; 277 rv = (rv == -EPIPE) ? rv : -EIO;
292 /* no data to deliver */
293 dev->bulk_in_filled = 0;
294 /* report it */ 278 /* report it */
295 goto exit; 279 goto exit;
296 } 280 }
@@ -526,7 +510,7 @@ static int skel_probe(struct usb_interface *interface,
526 mutex_init(&dev->io_mutex); 510 mutex_init(&dev->io_mutex);
527 spin_lock_init(&dev->err_lock); 511 spin_lock_init(&dev->err_lock);
528 init_usb_anchor(&dev->submitted); 512 init_usb_anchor(&dev->submitted);
529 init_completion(&dev->bulk_in_completion); 513 init_waitqueue_head(&dev->bulk_in_wait);
530 514
531 dev->udev = usb_get_dev(interface_to_usbdev(interface)); 515 dev->udev = usb_get_dev(interface_to_usbdev(interface));
532 dev->interface = interface; 516 dev->interface = interface;