From 394a10331a9e43100a8ee293255cfc428c7355ac Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Thu, 19 Feb 2015 12:34:41 +0700 Subject: USB: ch341: remove redundant close from open error path Remove redundant call to ch341_close from error path when submission of the interrupt urb fails in open. Signed-off-by: Johan Hovold diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c index 2d72aa3..79c56d93 100644 --- a/drivers/usb/serial/ch341.c +++ b/drivers/usb/serial/ch341.c @@ -328,7 +328,6 @@ static int ch341_open(struct tty_struct *tty, struct usb_serial_port *port) if (r) { dev_err(&port->dev, "%s - failed to submit interrupt urb: %d\n", __func__, r); - ch341_close(port); goto out; } -- cgit v0.10.2 From d5638fcf15bc65584877f00d4b0094cc4a66ad4e Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Mon, 2 Feb 2015 17:14:12 -0600 Subject: usb: musb: gadget: get rid of stop_activity() that function is pretty close to a no-op by now, all we need is a call to musb_stop(). Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c index b2d9040..4c481cd 100644 --- a/drivers/usb/musb/musb_gadget.c +++ b/drivers/usb/musb/musb_gadget.c @@ -1876,44 +1876,6 @@ err: return retval; } -static void stop_activity(struct musb *musb, struct usb_gadget_driver *driver) -{ - int i; - struct musb_hw_ep *hw_ep; - - /* don't disconnect if it's not connected */ - if (musb->g.speed == USB_SPEED_UNKNOWN) - driver = NULL; - else - musb->g.speed = USB_SPEED_UNKNOWN; - - /* deactivate the hardware */ - if (musb->softconnect) { - musb->softconnect = 0; - musb_pullup(musb, 0); - } - musb_stop(musb); - - /* killing any outstanding requests will quiesce the driver; - * then report disconnect - */ - if (driver) { - for (i = 0, hw_ep = musb->endpoints; - i < musb->nr_endpoints; - i++, hw_ep++) { - musb_ep_select(musb->mregs, i); - if (hw_ep->is_shared_fifo /* || !epnum */) { - nuke(&hw_ep->ep_in, -ESHUTDOWN); - } else { - if (hw_ep->max_packet_sz_tx) - nuke(&hw_ep->ep_in, -ESHUTDOWN); - if (hw_ep->max_packet_sz_rx) - nuke(&hw_ep->ep_out, -ESHUTDOWN); - } - } - } -} - /* * Unregister the gadget driver. Used by gadget drivers when * unregistering themselves from the controller. @@ -1940,7 +1902,7 @@ static int musb_gadget_stop(struct usb_gadget *g) (void) musb_gadget_vbus_draw(&musb->g, 0); musb->xceiv->otg->state = OTG_STATE_UNDEFINED; - stop_activity(musb, NULL); + musb_stop(musb); otg_set_peripheral(musb->xceiv->otg, NULL); musb->is_active = 0; -- cgit v0.10.2 From e3c93e1a3f35be4cf1493d3ccfb0c6d9209e4922 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Mon, 30 Dec 2013 12:33:53 -0600 Subject: usb: musb: core: fix TX/RX endpoint order As per Mentor Graphics' documentation, we should always handle TX endpoints before RX endpoints. This patch fixes that error while also updating some hard-to-read comments which were scattered around musb_interrupt(). This patch should be backported as far back as possible since this error has been in the driver since it's conception. Cc: Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index 067920f..461bfe8 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c @@ -1597,16 +1597,30 @@ irqreturn_t musb_interrupt(struct musb *musb) is_host_active(musb) ? "host" : "peripheral", musb->int_usb, musb->int_tx, musb->int_rx); - /* the core can interrupt us for multiple reasons; docs have - * a generic interrupt flowchart to follow + /** + * According to Mentor Graphics' documentation, flowchart on page 98, + * IRQ should be handled as follows: + * + * . Resume IRQ + * . Session Request IRQ + * . VBUS Error IRQ + * . Suspend IRQ + * . Connect IRQ + * . Disconnect IRQ + * . Reset/Babble IRQ + * . SOF IRQ (we're not using this one) + * . Endpoint 0 IRQ + * . TX Endpoints + * . RX Endpoints + * + * We will be following that flowchart in order to avoid any problems + * that might arise with internal Finite State Machine. */ + if (musb->int_usb) retval |= musb_stage0_irq(musb, musb->int_usb, devctl); - /* "stage 1" is handling endpoint irqs */ - - /* handle endpoint 0 first */ if (musb->int_tx & 1) { if (is_host_active(musb)) retval |= musb_h_ep0_irq(musb); @@ -1614,37 +1628,31 @@ irqreturn_t musb_interrupt(struct musb *musb) retval |= musb_g_ep0_irq(musb); } - /* RX on endpoints 1-15 */ - reg = musb->int_rx >> 1; + reg = musb->int_tx >> 1; ep_num = 1; while (reg) { if (reg & 1) { - /* musb_ep_select(musb->mregs, ep_num); */ - /* REVISIT just retval = ep->rx_irq(...) */ retval = IRQ_HANDLED; if (is_host_active(musb)) - musb_host_rx(musb, ep_num); + musb_host_tx(musb, ep_num); else - musb_g_rx(musb, ep_num); + musb_g_tx(musb, ep_num); } - reg >>= 1; ep_num++; } - /* TX on endpoints 1-15 */ - reg = musb->int_tx >> 1; + reg = musb->int_rx >> 1; ep_num = 1; while (reg) { if (reg & 1) { - /* musb_ep_select(musb->mregs, ep_num); */ - /* REVISIT just retval |= ep->tx_irq(...) */ retval = IRQ_HANDLED; if (is_host_active(musb)) - musb_host_tx(musb, ep_num); + musb_host_rx(musb, ep_num); else - musb_g_tx(musb, ep_num); + musb_g_rx(musb, ep_num); } + reg >>= 1; ep_num++; } -- cgit v0.10.2 From 31a0ede0de49a5897d7d97c68228ae79f86c38f0 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Mon, 30 Dec 2013 12:42:38 -0600 Subject: usb: musb: core: improve musb_interrupt() a bit instead of using manually spelled out bit-shits and iterate over each of the 16-bits (one for each endpoint) on each direction, we can make use of for_each_set_bit() which internally uses find_first_bit(). This makes the code slightly more readable while also making we only iterate over bits which are actually set. Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index 461bfe8..e59ae73 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c @@ -1587,9 +1587,12 @@ static int musb_core_init(u16 musb_type, struct musb *musb) irqreturn_t musb_interrupt(struct musb *musb) { irqreturn_t retval = IRQ_NONE; + unsigned long status; + unsigned long epnum; u8 devctl; - int ep_num; - u32 reg; + + if (!musb->int_usb && !musb->int_tx && !musb->int_rx) + return IRQ_NONE; devctl = musb_readb(musb->mregs, MUSB_DEVCTL); @@ -1618,43 +1621,36 @@ irqreturn_t musb_interrupt(struct musb *musb) */ if (musb->int_usb) - retval |= musb_stage0_irq(musb, musb->int_usb, - devctl); + retval |= musb_stage0_irq(musb, musb->int_usb, devctl); if (musb->int_tx & 1) { if (is_host_active(musb)) retval |= musb_h_ep0_irq(musb); else retval |= musb_g_ep0_irq(musb); + + /* we have just handled endpoint 0 IRQ, clear it */ + musb->int_tx &= ~BIT(0); } - reg = musb->int_tx >> 1; - ep_num = 1; - while (reg) { - if (reg & 1) { - retval = IRQ_HANDLED; - if (is_host_active(musb)) - musb_host_tx(musb, ep_num); - else - musb_g_tx(musb, ep_num); - } - reg >>= 1; - ep_num++; + status = musb->int_tx; + + for_each_set_bit(epnum, &status, 16) { + retval = IRQ_HANDLED; + if (is_host_active(musb)) + musb_host_tx(musb, epnum); + else + musb_g_tx(musb, epnum); } - reg = musb->int_rx >> 1; - ep_num = 1; - while (reg) { - if (reg & 1) { - retval = IRQ_HANDLED; - if (is_host_active(musb)) - musb_host_rx(musb, ep_num); - else - musb_g_rx(musb, ep_num); - } + status = musb->int_rx; - reg >>= 1; - ep_num++; + for_each_set_bit(epnum, &status, 16) { + retval = IRQ_HANDLED; + if (is_host_active(musb)) + musb_host_rx(musb, epnum); + else + musb_g_rx(musb, epnum); } return retval; -- cgit v0.10.2 From 3da1f6ee3563f84395e5d334349a4c9e25d8cbcb Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Tue, 2 Sep 2014 15:19:43 -0500 Subject: usb: dwc3: core: only reset res->start in case of error That trick is only needed if we end up with an error, so there's no point in messing that outside of an error path. In fact doing so causes problems when removing dwc3.ko, problems which commit c5a1fbc (usb: dwc3: dwc3-omap: Fix the crash on module removal) mistakenly tried to fix. Signed-off-by: Felipe Balbi diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 9f0e209..cd59e91 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -774,17 +774,13 @@ static int dwc3_probe(struct platform_device *pdev) * since it will be requested by the xhci-plat driver. */ regs = devm_ioremap_resource(dev, res); - if (IS_ERR(regs)) - return PTR_ERR(regs); + if (IS_ERR(regs)) { + ret = PTR_ERR(regs); + goto err0; + } dwc->regs = regs; dwc->regs_size = resource_size(res); - /* - * restore res->start back to its original value so that, - * in case the probe is deferred, we don't end up getting error in - * request the memory region the next time probe is called. - */ - res->start -= DWC3_GLOBALS_REGS_START; /* default to highest possible threshold */ lpm_nyet_threshold = 0xff; @@ -878,7 +874,7 @@ static int dwc3_probe(struct platform_device *pdev) ret = dwc3_core_get_phy(dwc); if (ret) - return ret; + goto err0; spin_lock_init(&dwc->lock); platform_set_drvdata(pdev, dwc); @@ -899,7 +895,7 @@ static int dwc3_probe(struct platform_device *pdev) if (ret) { dev_err(dwc->dev, "failed to allocate event buffers\n"); ret = -ENOMEM; - goto err0; + goto err1; } if (IS_ENABLED(CONFIG_USB_DWC3_HOST)) @@ -913,65 +909,81 @@ static int dwc3_probe(struct platform_device *pdev) ret = dwc3_core_init(dwc); if (ret) { dev_err(dev, "failed to initialize core\n"); - goto err0; + goto err1; } usb_phy_set_suspend(dwc->usb2_phy, 0); usb_phy_set_suspend(dwc->usb3_phy, 0); ret = phy_power_on(dwc->usb2_generic_phy); if (ret < 0) - goto err1; + goto err2; ret = phy_power_on(dwc->usb3_generic_phy); if (ret < 0) - goto err_usb2phy_power; + goto err3; ret = dwc3_event_buffers_setup(dwc); if (ret) { dev_err(dwc->dev, "failed to setup event buffers\n"); - goto err_usb3phy_power; + goto err4; } ret = dwc3_core_init_mode(dwc); if (ret) - goto err2; + goto err5; ret = dwc3_debugfs_init(dwc); if (ret) { dev_err(dev, "failed to initialize debugfs\n"); - goto err3; + goto err6; } pm_runtime_allow(dev); return 0; -err3: +err6: dwc3_core_exit_mode(dwc); -err2: +err5: dwc3_event_buffers_cleanup(dwc); -err_usb3phy_power: +err4: phy_power_off(dwc->usb3_generic_phy); -err_usb2phy_power: +err3: phy_power_off(dwc->usb2_generic_phy); -err1: +err2: usb_phy_set_suspend(dwc->usb2_phy, 1); usb_phy_set_suspend(dwc->usb3_phy, 1); dwc3_core_exit(dwc); -err0: +err1: dwc3_free_event_buffers(dwc); +err0: + /* + * restore res->start back to its original value so that, in case the + * probe is deferred, we don't end up getting error in request the + * memory region the next time probe is called. + */ + res->start -= DWC3_GLOBALS_REGS_START; + return ret; } static int dwc3_remove(struct platform_device *pdev) { struct dwc3 *dwc = platform_get_drvdata(pdev); + struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + + /* + * restore res->start back to its original value so that, in case the + * probe is deferred, we don't end up getting error in request the + * memory region the next time probe is called. + */ + res->start -= DWC3_GLOBALS_REGS_START; dwc3_debugfs_exit(dwc); dwc3_core_exit_mode(dwc); -- cgit v0.10.2 From 3d0184d087573b7606de45a8e4f01b6222caa47a Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Tue, 2 Sep 2014 14:12:26 -0500 Subject: usb: dwc3: omap: call of_platform_depopulate() instead This patch fixes a bug where removing dwc3-omap.ko would not trigger removal of dwc3.ko. of_platform_depopulate() already bakes an easy to use API for removing all our children which were populated during probe(); Let's use that one instead of cooking our own solution. Note that this is kind of a revert of commit c5a1fbc (usb: dwc3: dwc3-omap: Fix the crash on module removal) although we can't simply revert that because a direct call to platform_device_unregister would also be flakey. Signed-off-by: Felipe Balbi diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c index 52e0c4e..edba534 100644 --- a/drivers/usb/dwc3/dwc3-omap.c +++ b/drivers/usb/dwc3/dwc3-omap.c @@ -325,15 +325,6 @@ static irqreturn_t dwc3_omap_interrupt(int irq, void *_omap) return IRQ_HANDLED; } -static int dwc3_omap_remove_core(struct device *dev, void *c) -{ - struct platform_device *pdev = to_platform_device(dev); - - of_device_unregister(pdev); - - return 0; -} - static void dwc3_omap_enable_irqs(struct dwc3_omap *omap) { u32 reg; @@ -600,7 +591,7 @@ static int dwc3_omap_remove(struct platform_device *pdev) if (omap->extcon_id_dev.edev) extcon_unregister_interest(&omap->extcon_id_dev); dwc3_omap_disable_irqs(omap); - device_for_each_child(&pdev->dev, NULL, dwc3_omap_remove_core); + of_platform_depopulate(omap->dev); pm_runtime_put_sync(&pdev->dev); pm_runtime_disable(&pdev->dev); -- cgit v0.10.2 From 8f2c9544aba636134303105ecb164190a39dece4 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Thu, 4 Sep 2014 13:14:49 -0500 Subject: usb: dwc3: gadget: drop unnecessary loop when cleaning up TRBs Now that we're using XFERINPROGRESS for all endpoint types (except Control), we will *always* be completing one TRB at a time, so it's safe to remove the loop from dwc3_cleanup_done_reqs. Signed-off-by: Felipe Balbi diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index a03a485..8946c32 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1855,32 +1855,27 @@ static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, struct dwc3_ep *dep, unsigned int i; int ret; + req = next_request(&dep->req_queued); + if (!req) { + WARN_ON_ONCE(1); + return 1; + } + i = 0; do { - req = next_request(&dep->req_queued); - if (!req) { - WARN_ON_ONCE(1); - return 1; - } - i = 0; - do { - slot = req->start_slot + i; - if ((slot == DWC3_TRB_NUM - 1) && + slot = req->start_slot + i; + if ((slot == DWC3_TRB_NUM - 1) && usb_endpoint_xfer_isoc(dep->endpoint.desc)) - slot++; - slot %= DWC3_TRB_NUM; - trb = &dep->trb_pool[slot]; - - ret = __dwc3_cleanup_done_trbs(dwc, dep, req, trb, - event, status); - if (ret) - break; - }while (++i < req->request.num_mapped_sgs); - - dwc3_gadget_giveback(dep, req, status); + slot++; + slot %= DWC3_TRB_NUM; + trb = &dep->trb_pool[slot]; + ret = __dwc3_cleanup_done_trbs(dwc, dep, req, trb, + event, status); if (ret) break; - } while (1); + } while (++i < req->request.num_mapped_sgs); + + dwc3_gadget_giveback(dep, req, status); if (usb_endpoint_xfer_isoc(dep->endpoint.desc) && list_empty(&dep->req_queued)) { -- cgit v0.10.2 From 82ffb676c820629b7f1b62d15f6bc546f29a7025 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Sun, 1 Mar 2015 22:31:34 +0800 Subject: phy: berlin-usb: Use PTR_ERR_OR_ZERO PTR_ERR_OR_ZERO simplifies the code. Signed-off-by: Axel Lin Signed-off-by: Kishon Vijay Abraham I diff --git a/drivers/phy/phy-berlin-usb.c b/drivers/phy/phy-berlin-usb.c index c8a8d53..9f7cc7e 100644 --- a/drivers/phy/phy-berlin-usb.c +++ b/drivers/phy/phy-berlin-usb.c @@ -202,10 +202,7 @@ static int phy_berlin_usb_probe(struct platform_device *pdev) phy_provider = devm_of_phy_provider_register(&pdev->dev, of_phy_simple_xlate); - if (IS_ERR(phy_provider)) - return PTR_ERR(phy_provider); - - return 0; + return PTR_ERR_OR_ZERO(phy_provider); } static struct platform_driver phy_berlin_usb_driver = { -- cgit v0.10.2 From 8fd0ea395f96b1419083f850190f175d5ddd98e9 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Thu, 5 Mar 2015 09:33:38 +0800 Subject: phy: xgene: Use PTR_ERR_OR_ZERO Also remove unneeded goto and rc variable. Signed-off-by: Axel Lin Signed-off-by: Kishon Vijay Abraham I diff --git a/drivers/phy/phy-xgene.c b/drivers/phy/phy-xgene.c index 29214a3..bae9ccc 100644 --- a/drivers/phy/phy-xgene.c +++ b/drivers/phy/phy-xgene.c @@ -1657,7 +1657,6 @@ static int xgene_phy_probe(struct platform_device *pdev) struct phy_provider *phy_provider; struct xgene_phy_ctx *ctx; struct resource *res; - int rc = 0; u32 default_spd[] = DEFAULT_SATA_SPD_SEL; u32 default_txboost_gain[] = DEFAULT_SATA_TXBOOST_GAIN; u32 default_txeye_direction[] = DEFAULT_SATA_TXEYEDIRECTION; @@ -1676,10 +1675,8 @@ static int xgene_phy_probe(struct platform_device *pdev) res = platform_get_resource(pdev, IORESOURCE_MEM, 0); ctx->sds_base = devm_ioremap_resource(&pdev->dev, res); - if (IS_ERR(ctx->sds_base)) { - rc = PTR_ERR(ctx->sds_base); - goto error; - } + if (IS_ERR(ctx->sds_base)) + return PTR_ERR(ctx->sds_base); /* Retrieve optional clock */ ctx->clk = clk_get(&pdev->dev, NULL); @@ -1710,22 +1707,12 @@ static int xgene_phy_probe(struct platform_device *pdev) ctx->phy = devm_phy_create(ctx->dev, NULL, &xgene_phy_ops); if (IS_ERR(ctx->phy)) { dev_dbg(&pdev->dev, "Failed to create PHY\n"); - rc = PTR_ERR(ctx->phy); - goto error; + return PTR_ERR(ctx->phy); } phy_set_drvdata(ctx->phy, ctx); - phy_provider = devm_of_phy_provider_register(ctx->dev, - xgene_phy_xlate); - if (IS_ERR(phy_provider)) { - rc = PTR_ERR(phy_provider); - goto error; - } - - return 0; - -error: - return rc; + phy_provider = devm_of_phy_provider_register(ctx->dev, xgene_phy_xlate); + return PTR_ERR_OR_ZERO(phy_provider); } static const struct of_device_id xgene_phy_of_match[] = { -- cgit v0.10.2 From f8f55393b2860a2a5c97ff3b18c6ee02cef021c4 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Thu, 5 Mar 2015 09:40:41 +0800 Subject: phy: berlin-sata: Use devm_kcalloc at appropriate place Prefer devm_kcalloc over devm_kzalloc with multiply. Signed-off-by: Axel Lin Signed-off-by: Kishon Vijay Abraham I diff --git a/drivers/phy/phy-berlin-sata.c b/drivers/phy/phy-berlin-sata.c index 099eee8..6f3e06d 100644 --- a/drivers/phy/phy-berlin-sata.c +++ b/drivers/phy/phy-berlin-sata.c @@ -218,7 +218,7 @@ static int phy_berlin_sata_probe(struct platform_device *pdev) if (priv->nphys == 0) return -ENODEV; - priv->phys = devm_kzalloc(dev, priv->nphys * sizeof(*priv->phys), + priv->phys = devm_kcalloc(dev, priv->nphys, sizeof(*priv->phys), GFP_KERNEL); if (!priv->phys) return -ENOMEM; -- cgit v0.10.2 From 320c3fcec64a9e115a3d8a5d005d2fb21c15ef01 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Thu, 5 Mar 2015 09:44:06 +0800 Subject: phy: miphy28lp: Use PTR_ERR_OR_ZERO PTR_ERR_OR_ZERO simplifies the code. Signed-off-by: Axel Lin Acked-by: Gabriel Fernandez Signed-off-by: Kishon Vijay Abraham I diff --git a/drivers/phy/phy-miphy28lp.c b/drivers/phy/phy-miphy28lp.c index 9b2848e..174ffd0 100644 --- a/drivers/phy/phy-miphy28lp.c +++ b/drivers/phy/phy-miphy28lp.c @@ -1258,10 +1258,7 @@ static int miphy28lp_probe(struct platform_device *pdev) } provider = devm_of_phy_provider_register(&pdev->dev, miphy28lp_xlate); - if (IS_ERR(provider)) - return PTR_ERR(provider); - - return 0; + return PTR_ERR_OR_ZERO(provider); } static const struct of_device_id miphy28lp_of_match[] = { -- cgit v0.10.2 From 1f9ba767d5918796c7f32724777087f321fde30d Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Thu, 5 Mar 2015 18:18:45 +0800 Subject: phy: omap-control: Remove unneeded ifdef CONFIG_OF guard and of_match_ptr if !CONFIG_OF, the probe fails. This is a dt-only driver, so the ifdef CONFIG_OF guard and of_match_ptr are not needed. Signed-off-by: Axel Lin Signed-off-by: Kishon Vijay Abraham I diff --git a/drivers/phy/phy-omap-control.c b/drivers/phy/phy-omap-control.c index efe724f..a7653d9 100644 --- a/drivers/phy/phy-omap-control.c +++ b/drivers/phy/phy-omap-control.c @@ -216,7 +216,6 @@ void omap_control_usb_set_mode(struct device *dev, return; ctrl_phy = dev_get_drvdata(dev); - if (!ctrl_phy) { dev_err(dev, "Invalid control phy device\n"); return; @@ -241,8 +240,6 @@ void omap_control_usb_set_mode(struct device *dev, } EXPORT_SYMBOL_GPL(omap_control_usb_set_mode); -#ifdef CONFIG_OF - static const enum omap_control_phy_type otghs_data = OMAP_CTRL_TYPE_OTGHS; static const enum omap_control_phy_type usb2_data = OMAP_CTRL_TYPE_USB2; static const enum omap_control_phy_type pipe3_data = OMAP_CTRL_TYPE_PIPE3; @@ -278,8 +275,6 @@ static const struct of_device_id omap_control_phy_id_table[] = { {}, }; MODULE_DEVICE_TABLE(of, omap_control_phy_id_table); -#endif - static int omap_control_phy_probe(struct platform_device *pdev) { @@ -287,8 +282,7 @@ static int omap_control_phy_probe(struct platform_device *pdev) const struct of_device_id *of_id; struct omap_control_phy *control_phy; - of_id = of_match_device(of_match_ptr(omap_control_phy_id_table), - &pdev->dev); + of_id = of_match_device(omap_control_phy_id_table, &pdev->dev); if (!of_id) return -EINVAL; @@ -344,7 +338,7 @@ static struct platform_driver omap_control_phy_driver = { .probe = omap_control_phy_probe, .driver = { .name = "omap-control-phy", - .of_match_table = of_match_ptr(omap_control_phy_id_table), + .of_match_table = omap_control_phy_id_table, }, }; -- cgit v0.10.2 From 52a4a72a1ad675b66ec241c0e33ee6e50df63a93 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Thu, 5 Mar 2015 18:20:07 +0800 Subject: phy: omap-usb2: Remove unneeded ifdef CONFIG_OF guard and of_match_ptr if !CONFIG_OF, the probe fails. This is a dt-only driver, so the ifdef CONFIG_OF guard and of_match_ptr are not needed. Signed-off-by: Axel Lin Signed-off-by: Kishon Vijay Abraham I diff --git a/drivers/phy/phy-omap-usb2.c b/drivers/phy/phy-omap-usb2.c index 6f4aef3..18b33ce 100644 --- a/drivers/phy/phy-omap-usb2.c +++ b/drivers/phy/phy-omap-usb2.c @@ -144,7 +144,6 @@ static struct phy_ops ops = { .owner = THIS_MODULE, }; -#ifdef CONFIG_OF static const struct usb_phy_data omap_usb2_data = { .label = "omap_usb2", .flags = OMAP_USB2_HAS_START_SRP | OMAP_USB2_HAS_SET_VBUS, @@ -185,7 +184,6 @@ static const struct of_device_id omap_usb2_id_table[] = { {}, }; MODULE_DEVICE_TABLE(of, omap_usb2_id_table); -#endif static int omap_usb2_probe(struct platform_device *pdev) { @@ -200,7 +198,7 @@ static int omap_usb2_probe(struct platform_device *pdev) const struct of_device_id *of_id; struct usb_phy_data *phy_data; - of_id = of_match_device(of_match_ptr(omap_usb2_id_table), &pdev->dev); + of_id = of_match_device(omap_usb2_id_table, &pdev->dev); if (!of_id) return -EINVAL; @@ -377,7 +375,7 @@ static struct platform_driver omap_usb2_driver = { .driver = { .name = "omap-usb2", .pm = DEV_PM_OPS, - .of_match_table = of_match_ptr(omap_usb2_id_table), + .of_match_table = omap_usb2_id_table, }, }; -- cgit v0.10.2 From 298fe56ee2b9551ca8cd675e7a6ebaf1c03632f8 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Thu, 5 Mar 2015 18:20:53 +0800 Subject: phy: ti-pipe3: Remove unneeded ifdef CONFIG_OF guard and of_match_ptr if !CONFIG_OF, the probe fails. This is a dt-only driver, so the ifdef CONFIG_OF guard and of_match_ptr are not needed. Signed-off-by: Axel Lin Signed-off-by: Kishon Vijay Abraham I diff --git a/drivers/phy/phy-ti-pipe3.c b/drivers/phy/phy-ti-pipe3.c index 95c88f9..ad3fbc8 100644 --- a/drivers/phy/phy-ti-pipe3.c +++ b/drivers/phy/phy-ti-pipe3.c @@ -291,9 +291,7 @@ static struct phy_ops ops = { .owner = THIS_MODULE, }; -#ifdef CONFIG_OF static const struct of_device_id ti_pipe3_id_table[]; -#endif static int ti_pipe3_probe(struct platform_device *pdev) { @@ -315,8 +313,7 @@ static int ti_pipe3_probe(struct platform_device *pdev) spin_lock_init(&phy->lock); if (!of_device_is_compatible(node, "ti,phy-pipe3-pcie")) { - match = of_match_device(of_match_ptr(ti_pipe3_id_table), - &pdev->dev); + match = of_match_device(ti_pipe3_id_table, &pdev->dev); if (!match) return -EINVAL; @@ -574,7 +571,6 @@ static const struct dev_pm_ops ti_pipe3_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(ti_pipe3_suspend, ti_pipe3_resume) }; -#ifdef CONFIG_OF static const struct of_device_id ti_pipe3_id_table[] = { { .compatible = "ti,phy-usb3", @@ -594,7 +590,6 @@ static const struct of_device_id ti_pipe3_id_table[] = { {} }; MODULE_DEVICE_TABLE(of, ti_pipe3_id_table); -#endif static struct platform_driver ti_pipe3_driver = { .probe = ti_pipe3_probe, @@ -602,7 +597,7 @@ static struct platform_driver ti_pipe3_driver = { .driver = { .name = "ti-pipe3", .pm = &ti_pipe3_pm_ops, - .of_match_table = of_match_ptr(ti_pipe3_id_table), + .of_match_table = ti_pipe3_id_table, }, }; -- cgit v0.10.2 From 739ae3452d0ee199b3cfe5e52214d9ccd8e358ea Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 10 Mar 2015 17:05:33 +0800 Subject: phy: berlin-usb: Set drvdata for phy and use it At the context where we have pointer to struct phy, it's useful to call phy_get_drvdata() to get the address of priv. With this change, we can remove the to_phy_berlin_usb_priv() macro and remove *phy from struct phy_berlin_usb_priv. Signed-off-by: Axel Lin Signed-off-by: Kishon Vijay Abraham I diff --git a/drivers/phy/phy-berlin-usb.c b/drivers/phy/phy-berlin-usb.c index 9f7cc7e..c6fc95b 100644 --- a/drivers/phy/phy-berlin-usb.c +++ b/drivers/phy/phy-berlin-usb.c @@ -103,9 +103,6 @@ #define MODE_TEST_EN BIT(11) #define ANA_TEST_DC_CTRL(x) ((x) << 12) -#define to_phy_berlin_usb_priv(p) \ - container_of((p), struct phy_berlin_usb_priv, phy) - static const u32 phy_berlin_pll_dividers[] = { /* Berlin 2 */ CLK_REF_DIV(0xc) | FEEDBACK_CLK_DIV(0x54), @@ -115,14 +112,13 @@ static const u32 phy_berlin_pll_dividers[] = { struct phy_berlin_usb_priv { void __iomem *base; - struct phy *phy; struct reset_control *rst_ctrl; u32 pll_divider; }; static int phy_berlin_usb_power_on(struct phy *phy) { - struct phy_berlin_usb_priv *priv = dev_get_drvdata(phy->dev.parent); + struct phy_berlin_usb_priv *priv = phy_get_drvdata(phy); reset_control_reset(priv->rst_ctrl); @@ -175,6 +171,7 @@ static int phy_berlin_usb_probe(struct platform_device *pdev) of_match_device(phy_berlin_sata_of_match, &pdev->dev); struct phy_berlin_usb_priv *priv; struct resource *res; + struct phy *phy; struct phy_provider *phy_provider; priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); @@ -192,13 +189,14 @@ static int phy_berlin_usb_probe(struct platform_device *pdev) priv->pll_divider = *((u32 *)match->data); - priv->phy = devm_phy_create(&pdev->dev, NULL, &phy_berlin_usb_ops); - if (IS_ERR(priv->phy)) { + phy = devm_phy_create(&pdev->dev, NULL, &phy_berlin_usb_ops); + if (IS_ERR(phy)) { dev_err(&pdev->dev, "failed to create PHY\n"); - return PTR_ERR(priv->phy); + return PTR_ERR(phy); } platform_set_drvdata(pdev, priv); + phy_set_drvdata(phy, priv); phy_provider = devm_of_phy_provider_register(&pdev->dev, of_phy_simple_xlate); -- cgit v0.10.2 From 25140ce627f43df1d425d591ac3d360b48ae24e1 Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Sat, 21 Feb 2015 18:53:37 -0800 Subject: usb: gadget: udc: pxa27x_udc: Remove use of seq_printf return value The seq_printf return value, because it's frequently misused, will eventually be converted to void. See: commit 1f33c41c03da ("seq_file: Rename seq_overflow() to seq_has_overflowed() and make public") While there, simplify the error handler logic by returning immediately and remove the unnecessary labels. Tested-by: Robert Jarzmik Signed-off-by: Joe Perches Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/udc/pxa27x_udc.c b/drivers/usb/gadget/udc/pxa27x_udc.c index 6a855fc..486f754 100644 --- a/drivers/usb/gadget/udc/pxa27x_udc.c +++ b/drivers/usb/gadget/udc/pxa27x_udc.c @@ -93,50 +93,46 @@ static void handle_ep(struct pxa_ep *ep); static int state_dbg_show(struct seq_file *s, void *p) { struct pxa_udc *udc = s->private; - int pos = 0, ret; u32 tmp; - ret = -ENODEV; if (!udc->driver) - goto out; + return -ENODEV; /* basic device status */ - pos += seq_printf(s, DRIVER_DESC "\n" - "%s version: %s\nGadget driver: %s\n", - driver_name, DRIVER_VERSION, - udc->driver ? udc->driver->driver.name : "(none)"); + seq_printf(s, DRIVER_DESC "\n" + "%s version: %s\n" + "Gadget driver: %s\n", + driver_name, DRIVER_VERSION, + udc->driver ? udc->driver->driver.name : "(none)"); tmp = udc_readl(udc, UDCCR); - pos += seq_printf(s, - "udccr=0x%0x(%s%s%s%s%s%s%s%s%s%s), " - "con=%d,inter=%d,altinter=%d\n", tmp, - (tmp & UDCCR_OEN) ? " oen":"", - (tmp & UDCCR_AALTHNP) ? " aalthnp":"", - (tmp & UDCCR_AHNP) ? " rem" : "", - (tmp & UDCCR_BHNP) ? " rstir" : "", - (tmp & UDCCR_DWRE) ? " dwre" : "", - (tmp & UDCCR_SMAC) ? " smac" : "", - (tmp & UDCCR_EMCE) ? " emce" : "", - (tmp & UDCCR_UDR) ? " udr" : "", - (tmp & UDCCR_UDA) ? " uda" : "", - (tmp & UDCCR_UDE) ? " ude" : "", - (tmp & UDCCR_ACN) >> UDCCR_ACN_S, - (tmp & UDCCR_AIN) >> UDCCR_AIN_S, - (tmp & UDCCR_AAISN) >> UDCCR_AAISN_S); + seq_printf(s, + "udccr=0x%0x(%s%s%s%s%s%s%s%s%s%s), con=%d,inter=%d,altinter=%d\n", + tmp, + (tmp & UDCCR_OEN) ? " oen":"", + (tmp & UDCCR_AALTHNP) ? " aalthnp":"", + (tmp & UDCCR_AHNP) ? " rem" : "", + (tmp & UDCCR_BHNP) ? " rstir" : "", + (tmp & UDCCR_DWRE) ? " dwre" : "", + (tmp & UDCCR_SMAC) ? " smac" : "", + (tmp & UDCCR_EMCE) ? " emce" : "", + (tmp & UDCCR_UDR) ? " udr" : "", + (tmp & UDCCR_UDA) ? " uda" : "", + (tmp & UDCCR_UDE) ? " ude" : "", + (tmp & UDCCR_ACN) >> UDCCR_ACN_S, + (tmp & UDCCR_AIN) >> UDCCR_AIN_S, + (tmp & UDCCR_AAISN) >> UDCCR_AAISN_S); /* registers for device and ep0 */ - pos += seq_printf(s, "udcicr0=0x%08x udcicr1=0x%08x\n", - udc_readl(udc, UDCICR0), udc_readl(udc, UDCICR1)); - pos += seq_printf(s, "udcisr0=0x%08x udcisr1=0x%08x\n", - udc_readl(udc, UDCISR0), udc_readl(udc, UDCISR1)); - pos += seq_printf(s, "udcfnr=%d\n", udc_readl(udc, UDCFNR)); - pos += seq_printf(s, "irqs: reset=%lu, suspend=%lu, resume=%lu, " - "reconfig=%lu\n", - udc->stats.irqs_reset, udc->stats.irqs_suspend, - udc->stats.irqs_resume, udc->stats.irqs_reconfig); - - ret = 0; -out: - return ret; + seq_printf(s, "udcicr0=0x%08x udcicr1=0x%08x\n", + udc_readl(udc, UDCICR0), udc_readl(udc, UDCICR1)); + seq_printf(s, "udcisr0=0x%08x udcisr1=0x%08x\n", + udc_readl(udc, UDCISR0), udc_readl(udc, UDCISR1)); + seq_printf(s, "udcfnr=%d\n", udc_readl(udc, UDCFNR)); + seq_printf(s, "irqs: reset=%lu, suspend=%lu, resume=%lu, reconfig=%lu\n", + udc->stats.irqs_reset, udc->stats.irqs_suspend, + udc->stats.irqs_resume, udc->stats.irqs_reconfig); + + return 0; } static int queues_dbg_show(struct seq_file *s, void *p) @@ -144,75 +140,67 @@ static int queues_dbg_show(struct seq_file *s, void *p) struct pxa_udc *udc = s->private; struct pxa_ep *ep; struct pxa27x_request *req; - int pos = 0, i, maxpkt, ret; + int i, maxpkt; - ret = -ENODEV; if (!udc->driver) - goto out; + return -ENODEV; /* dump endpoint queues */ for (i = 0; i < NR_PXA_ENDPOINTS; i++) { ep = &udc->pxa_ep[i]; maxpkt = ep->fifo_size; - pos += seq_printf(s, "%-12s max_pkt=%d %s\n", - EPNAME(ep), maxpkt, "pio"); + seq_printf(s, "%-12s max_pkt=%d %s\n", + EPNAME(ep), maxpkt, "pio"); if (list_empty(&ep->queue)) { - pos += seq_printf(s, "\t(nothing queued)\n"); + seq_puts(s, "\t(nothing queued)\n"); continue; } list_for_each_entry(req, &ep->queue, queue) { - pos += seq_printf(s, "\treq %p len %d/%d buf %p\n", - &req->req, req->req.actual, - req->req.length, req->req.buf); + seq_printf(s, "\treq %p len %d/%d buf %p\n", + &req->req, req->req.actual, + req->req.length, req->req.buf); } } - ret = 0; -out: - return ret; + return 0; } static int eps_dbg_show(struct seq_file *s, void *p) { struct pxa_udc *udc = s->private; struct pxa_ep *ep; - int pos = 0, i, ret; + int i; u32 tmp; - ret = -ENODEV; if (!udc->driver) - goto out; + return -ENODEV; ep = &udc->pxa_ep[0]; tmp = udc_ep_readl(ep, UDCCSR); - pos += seq_printf(s, "udccsr0=0x%03x(%s%s%s%s%s%s%s)\n", tmp, - (tmp & UDCCSR0_SA) ? " sa" : "", - (tmp & UDCCSR0_RNE) ? " rne" : "", - (tmp & UDCCSR0_FST) ? " fst" : "", - (tmp & UDCCSR0_SST) ? " sst" : "", - (tmp & UDCCSR0_DME) ? " dme" : "", - (tmp & UDCCSR0_IPR) ? " ipr" : "", - (tmp & UDCCSR0_OPC) ? " opc" : ""); + seq_printf(s, "udccsr0=0x%03x(%s%s%s%s%s%s%s)\n", + tmp, + (tmp & UDCCSR0_SA) ? " sa" : "", + (tmp & UDCCSR0_RNE) ? " rne" : "", + (tmp & UDCCSR0_FST) ? " fst" : "", + (tmp & UDCCSR0_SST) ? " sst" : "", + (tmp & UDCCSR0_DME) ? " dme" : "", + (tmp & UDCCSR0_IPR) ? " ipr" : "", + (tmp & UDCCSR0_OPC) ? " opc" : ""); for (i = 0; i < NR_PXA_ENDPOINTS; i++) { ep = &udc->pxa_ep[i]; tmp = i? udc_ep_readl(ep, UDCCR) : udc_readl(udc, UDCCR); - pos += seq_printf(s, "%-12s: " - "IN %lu(%lu reqs), OUT %lu(%lu reqs), " - "irqs=%lu, udccr=0x%08x, udccsr=0x%03x, " - "udcbcr=%d\n", - EPNAME(ep), - ep->stats.in_bytes, ep->stats.in_ops, - ep->stats.out_bytes, ep->stats.out_ops, - ep->stats.irqs, - tmp, udc_ep_readl(ep, UDCCSR), - udc_ep_readl(ep, UDCBCR)); + seq_printf(s, "%-12s: IN %lu(%lu reqs), OUT %lu(%lu reqs), irqs=%lu, udccr=0x%08x, udccsr=0x%03x, udcbcr=%d\n", + EPNAME(ep), + ep->stats.in_bytes, ep->stats.in_ops, + ep->stats.out_bytes, ep->stats.out_ops, + ep->stats.irqs, + tmp, udc_ep_readl(ep, UDCCSR), + udc_ep_readl(ep, UDCBCR)); } - ret = 0; -out: - return ret; + return 0; } static int eps_dbg_open(struct inode *inode, struct file *file) -- cgit v0.10.2 From adf9c3c85615f41c08559086e0d9ecdc6cc9db71 Mon Sep 17 00:00:00 2001 From: Joseph Kogut Date: Mon, 16 Feb 2015 19:32:46 -0700 Subject: usb: move definition of PCI_VENDOR_ID_SYNOPSYS to linux/pci_ids.h Removed FIXME from usb/dwc3/dwc3-pci.c by moving definition of PCI_VENDOR_ID_SYNOPSYS shared with usb/dwc2 to linux/pci_ids.h. Signed-off-by: Joseph Kogut Signed-off-by: Felipe Balbi diff --git a/drivers/usb/dwc2/pci.c b/drivers/usb/dwc2/pci.c index a4e724b..6646adb 100644 --- a/drivers/usb/dwc2/pci.c +++ b/drivers/usb/dwc2/pci.c @@ -54,7 +54,6 @@ #include "core.h" #include "hcd.h" -#define PCI_VENDOR_ID_SYNOPSYS 0x16c3 #define PCI_PRODUCT_ID_HAPS_HSOTG 0xabc0 static const char dwc2_driver_name[] = "dwc2"; diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c index 8d95056..b773fb5 100644 --- a/drivers/usb/dwc3/dwc3-pci.c +++ b/drivers/usb/dwc3/dwc3-pci.c @@ -24,8 +24,6 @@ #include "platform_data.h" -/* FIXME define these in */ -#define PCI_VENDOR_ID_SYNOPSYS 0x16c3 #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 0xabcd #define PCI_DEVICE_ID_INTEL_BYT 0x0f37 #define PCI_DEVICE_ID_INTEL_MRFLD 0x119e diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h index e63c02a..38cff8f 100644 --- a/include/linux/pci_ids.h +++ b/include/linux/pci_ids.h @@ -2315,6 +2315,8 @@ #define PCI_VENDOR_ID_CENATEK 0x16CA #define PCI_DEVICE_ID_CENATEK_IDE 0x0001 +#define PCI_VENDOR_ID_SYNOPSYS 0x16c3 + #define PCI_VENDOR_ID_VITESSE 0x1725 #define PCI_DEVICE_ID_VITESSE_VSC7174 0x7174 -- cgit v0.10.2 From ab7580c1479f9cc9d6a70a5184687a4d807fc612 Mon Sep 17 00:00:00 2001 From: Sudeep Holla Date: Thu, 26 Feb 2015 11:47:57 +0000 Subject: usb: isp1760: add peripheral/device controller chip id As per the SAF1761 data sheet[0], the DcChipID register represents the hardware version number (0001h) and the chip ID (1582h) for the Peripheral Controller. However as per the ISP1761 data sheet[1], the DcChipID register represents the hardware version number (0015h) and the chip ID (8210h) for the Peripheral Controller. This patch adds support for both the chip ID values. [0] http://www.nxp.com/documents/data_sheet/SAF1761.pdf [1] http://pdf.datasheetcatalog.com/datasheets2/74/742102_1.pdf Cc: Felipe Balbi Cc: Laurent Pinchart Signed-off-by: Sudeep Holla Acked-by: Laurent Pinchart Signed-off-by: Felipe Balbi diff --git a/drivers/usb/isp1760/isp1760-udc.c b/drivers/usb/isp1760/isp1760-udc.c index 9612d79..6d618b3 100644 --- a/drivers/usb/isp1760/isp1760-udc.c +++ b/drivers/usb/isp1760/isp1760-udc.c @@ -1411,7 +1411,7 @@ static int isp1760_udc_init(struct isp1760_udc *udc) return -ENODEV; } - if (chipid != 0x00011582) { + if (chipid != 0x00011582 && chipid != 0x00158210) { dev_err(udc->isp->dev, "udc: invalid chip ID 0x%08x\n", chipid); return -ENODEV; } -- cgit v0.10.2 From 896f7ea37f53666a72080d0958213d12ae59deaa Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Wed, 25 Feb 2015 14:03:23 -0600 Subject: usb: musb: core: remove unnecessary logical comparison devctl & MUSB_DEVCTL_HM represents a single bit, just check for the bit, there's really no need to compare the result against 0. Tested-by: Bin Liu Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index e59ae73..8066dba 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c @@ -879,7 +879,7 @@ b_host: */ if (int_usb & MUSB_INTR_RESET) { handled = IRQ_HANDLED; - if ((devctl & MUSB_DEVCTL_HM) != 0) { + if (devctl & MUSB_DEVCTL_HM) { /* * Looks like non-HS BABBLE can be ignored, but * HS BABBLE is an error condition. For HS the solution -- cgit v0.10.2 From d57a27711939dcb289b3d17ac48fca99f0fd245d Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Wed, 25 Feb 2015 14:05:15 -0600 Subject: usb: musb: core: add missing curly braces no functional changes, clean up only. Tested-by: Bin Liu Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index 8066dba..21ab266 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c @@ -887,9 +887,9 @@ b_host: * caused BABBLE. When HS BABBLE happens we can only * stop the session. */ - if (devctl & (MUSB_DEVCTL_FSDEV | MUSB_DEVCTL_LSDEV)) + if (devctl & (MUSB_DEVCTL_FSDEV | MUSB_DEVCTL_LSDEV)) { dev_dbg(musb->controller, "BABBLE devctl: %02x\n", devctl); - else { + } else { ERR("Stopping host session -- babble\n"); musb_writeb(musb->mregs, MUSB_DEVCTL, 0); } -- cgit v0.10.2 From 28378d5ed5ca1221479d2f94c3b346691834822f Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Thu, 26 Feb 2015 10:54:27 -0600 Subject: usb: musb: core: fix highspeed check FSDEV is set for both HIGH and FULL speeds, the correct HIGHSPEED check is done through power register's HSMODE bit. Tested-by: Bin Liu Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index 21ab266..cf7b10e 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c @@ -880,16 +880,23 @@ b_host: if (int_usb & MUSB_INTR_RESET) { handled = IRQ_HANDLED; if (devctl & MUSB_DEVCTL_HM) { + u8 power = musb_readl(musb->mregs, MUSB_POWER); + /* * Looks like non-HS BABBLE can be ignored, but - * HS BABBLE is an error condition. For HS the solution - * is to avoid babble in the first place and fix what - * caused BABBLE. When HS BABBLE happens we can only - * stop the session. + * HS BABBLE is an error condition. + * + * For HS the solution is to avoid babble in the first + * place and fix what caused BABBLE. + * + * When HS BABBLE happens what we can depends on which + * platform MUSB is running, because some platforms + * implemented proprietary means for 'recovering' from + * Babble conditions. One such platform is AM335x. In + * most cases, however, the only thing we can do is drop + * the session. */ - if (devctl & (MUSB_DEVCTL_FSDEV | MUSB_DEVCTL_LSDEV)) { - dev_dbg(musb->controller, "BABBLE devctl: %02x\n", devctl); - } else { + if (power & MUSB_POWER_HSMODE) { ERR("Stopping host session -- babble\n"); musb_writeb(musb->mregs, MUSB_DEVCTL, 0); } -- cgit v0.10.2 From d0cddae7926f39e8fd488f62496cfebf7a5e757d Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Thu, 26 Feb 2015 10:55:13 -0600 Subject: usb: musb: dsps: return error code if reset fails if reset fails, we should return a *negative* error code, not a positive value. Tested-by: Bin Liu Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c index a900c98..af614f4 100644 --- a/drivers/usb/musb/musb_dsps.c +++ b/drivers/usb/musb/musb_dsps.c @@ -652,7 +652,7 @@ static int dsps_musb_reset(struct musb *musb) session_restart = 1; } - return !session_restart; + return session_restart ? 0 : -EPIPE; } static struct musb_platform_ops dsps_ops = { -- cgit v0.10.2 From d0fc0a20b5b7babe0fe1552204bd52505a4f93dd Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Wed, 25 Feb 2015 14:07:52 -0600 Subject: usb: musb: core: move babble recovery inside babble check There was already a proper place where we were checking for babble interrupts, move babble recovery there. Tested-by: Bin Liu Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index cf7b10e..9ea02d4 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c @@ -899,6 +899,12 @@ b_host: if (power & MUSB_POWER_HSMODE) { ERR("Stopping host session -- babble\n"); musb_writeb(musb->mregs, MUSB_DEVCTL, 0); + + if (is_host_active(musb)) { + musb_generic_disable(musb); + schedule_delayed_work(&musb->recover_work, + msecs_to_jiffies(100)); + } } } else { dev_dbg(musb->controller, "BUS RESET as %s\n", @@ -938,13 +944,6 @@ b_host: } } - /* handle babble condition */ - if (int_usb & MUSB_INTR_BABBLE && is_host_active(musb)) { - musb_generic_disable(musb); - schedule_delayed_work(&musb->recover_work, - msecs_to_jiffies(100)); - } - #if 0 /* REVISIT ... this would be for multiplexing periodic endpoints, or * supporting transfer phasing to prevent exceeding ISO bandwidth -- cgit v0.10.2 From 0acff6b83106ef699f17828caea6545bcc716f14 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Wed, 25 Feb 2015 14:14:15 -0600 Subject: usb: musb: core: break long line no functional changes, clean up only. Tested-by: Bin Liu Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index 9ea02d4..b5dfe83 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c @@ -534,7 +534,8 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, */ if (int_usb & MUSB_INTR_RESUME) { handled = IRQ_HANDLED; - dev_dbg(musb->controller, "RESUME (%s)\n", usb_otg_state_string(musb->xceiv->otg->state)); + dev_dbg(musb->controller, "RESUME (%s)\n", + usb_otg_state_string(musb->xceiv->otg->state)); if (devctl & MUSB_DEVCTL_HM) { void __iomem *mbase = musb->mregs; -- cgit v0.10.2 From 46571889ec435f1bf29d9094f062948b26630723 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Wed, 25 Feb 2015 14:30:55 -0600 Subject: usb: musb: core: remove unnecessary reg access from resume IRQ when musb is operating as host and a remote wakeup fires up, a resume interrupt will be raised. At that point SUSPENDM bit is automatically cleared and RESUME bit is automatically set. Remove those two from IRQ handler. Tested-by: Bin Liu Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index b5dfe83..3fb7d6e 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c @@ -538,27 +538,12 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, usb_otg_state_string(musb->xceiv->otg->state)); if (devctl & MUSB_DEVCTL_HM) { - void __iomem *mbase = musb->mregs; - u8 power; - switch (musb->xceiv->otg->state) { case OTG_STATE_A_SUSPEND: /* remote wakeup? later, GetPortStatus * will stop RESUME signaling */ - power = musb_readb(musb->mregs, MUSB_POWER); - if (power & MUSB_POWER_SUSPENDM) { - /* spurious */ - musb->int_usb &= ~MUSB_INTR_SUSPEND; - dev_dbg(musb->controller, "Spurious SUSPENDM\n"); - break; - } - - power &= ~MUSB_POWER_SUSPENDM; - musb_writeb(mbase, MUSB_POWER, - power | MUSB_POWER_RESUME); - musb->port1_status |= (USB_PORT_STAT_C_SUSPEND << 16) | MUSB_PORT_STAT_RESUME; -- cgit v0.10.2 From b2c7361bd07f94e6280507a20e0541870d5d7a1a Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Wed, 25 Feb 2015 14:48:50 -0600 Subject: usb: musb: core: there is no connect interrupt in peripheral mode MUSB does not generate a connect IRQ when working in peripheral mode. Tested-by: Bin Liu Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index 3fb7d6e..7ac6979 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c @@ -761,10 +761,6 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, musb->ep0_stage = MUSB_EP0_START; - /* flush endpoints when transitioning from Device Mode */ - if (is_peripheral_active(musb)) { - /* REVISIT HNP; just force disconnect */ - } musb->intrtxe = musb->epmask; musb_writew(musb->mregs, MUSB_INTRTXE, musb->intrtxe); musb->intrrxe = musb->epmask & 0xfffe; -- cgit v0.10.2 From 52b9e6eb07f739207bd7d4257fdfbb24592d096a Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Wed, 25 Feb 2015 16:04:39 -0600 Subject: usb: musb: dsps: remove babble check from dsps irq handler musb->int_usb already contains the correct information for musb-core to handle babble. In fact, this very check was just causing a nonsensical babble interrupt storm. With this I can get test.sh to run and, even though all tests fail with timeout, that's still better than locking up the system due to IRQ storm. Also, if I remove g_zero and load g_mass_storage, then everything works fine again. Tested-by: Bin Liu Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index 7ac6979..d7730c7 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c @@ -879,7 +879,7 @@ b_host: * the session. */ if (power & MUSB_POWER_HSMODE) { - ERR("Stopping host session -- babble\n"); + dev_err(musb->controller, "Babble\n"); musb_writeb(musb->mregs, MUSB_DEVCTL, 0); if (is_host_active(musb)) { diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c index af614f4..8f96e79d 100644 --- a/drivers/usb/musb/musb_dsps.c +++ b/drivers/usb/musb/musb_dsps.c @@ -330,28 +330,6 @@ static irqreturn_t dsps_interrupt(int irq, void *hci) dev_dbg(musb->controller, "usbintr (%x) epintr(%x)\n", usbintr, epintr); - /* - * DRVVBUS IRQs are the only proxy we have (a very poor one!) for - * DSPS IP's missing ID change IRQ. We need an ID change IRQ to - * switch appropriately between halves of the OTG state machine. - * Managing DEVCTL.SESSION per Mentor docs requires that we know its - * value but DEVCTL.BDEVICE is invalid without DEVCTL.SESSION set. - * Also, DRVVBUS pulses for SRP (but not at 5V) ... - */ - if (is_host_active(musb) && usbintr & MUSB_INTR_BABBLE) { - pr_info("CAUTION: musb: Babble Interrupt Occurred\n"); - - /* - * When a babble condition occurs, the musb controller removes - * the session and is no longer in host mode. Hence, all - * devices connected to its root hub get disconnected. - * - * Hand this error down to the musb core isr, so it can - * recover. - */ - musb->int_usb = MUSB_INTR_BABBLE | MUSB_INTR_DISCONNECT; - musb->int_tx = musb->int_rx = 0; - } if (usbintr & ((1 << wrp->drvvbus) << wrp->usb_shift)) { int drvvbus = dsps_readl(reg_base, wrp->status); -- cgit v0.10.2 From f860f0b1ea76b9f15d24db8fa98823eb15273afb Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Thu, 26 Feb 2015 11:01:03 -0600 Subject: usb: musb: dsps: check for the single bit We want to check if that particular bit is set. It could very well be that bootloader (or romcode) has fiddled with MUSB before us which could leave other bits set in this register. Tested-by: Bin Liu Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c index 8f96e79d..e210b75 100644 --- a/drivers/usb/musb/musb_dsps.c +++ b/drivers/usb/musb/musb_dsps.c @@ -475,7 +475,7 @@ static int dsps_musb_init(struct musb *musb) * logic enabled. */ val = dsps_readb(musb->mregs, MUSB_BABBLE_CTL); - if (val == MUSB_BABBLE_RCV_DISABLE) { + if (val & MUSB_BABBLE_RCV_DISABLE) { glue->sw_babble_enabled = true; val |= MUSB_BABBLE_SW_SESSION_CTRL; dsps_writeb(musb->mregs, MUSB_BABBLE_CTL, val); -- cgit v0.10.2 From a67cab72b87c7bb970bec8bc060a8946c5dfa1c5 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Thu, 26 Feb 2015 11:09:20 -0600 Subject: usb: musb: core: controller drops session automatically Whenever babble happens, MUSB controller will drop session automatically. The only case where it won't drop the session, is when we're running on AM335x and SW_SESSION_CTRL bit has been set. In that case, controller will not touch session bit so SW has a chance to recover from babble condition. Tested-by: Bin Liu Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index d7730c7..b86e975 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c @@ -880,7 +880,6 @@ b_host: */ if (power & MUSB_POWER_HSMODE) { dev_err(musb->controller, "Babble\n"); - musb_writeb(musb->mregs, MUSB_DEVCTL, 0); if (is_host_active(musb)) { musb_generic_disable(musb); -- cgit v0.10.2 From 3709ffca6485bd1b03b1fe2d9eb384dcf5db87a6 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Thu, 26 Feb 2015 11:11:33 -0600 Subject: usb: musb: dsps: add dsps_ prefix to sw_babble_control this makes it easier to filter function traces. No functional changes. Tested-by: Bin Liu Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c index e210b75..85ebfa2 100644 --- a/drivers/usb/musb/musb_dsps.c +++ b/drivers/usb/musb/musb_dsps.c @@ -549,7 +549,7 @@ static int dsps_musb_set_mode(struct musb *musb, u8 mode) return 0; } -static bool sw_babble_control(struct musb *musb) +static bool dsps_sw_babble_control(struct musb *musb) { u8 babble_ctl; bool session_restart = false; @@ -608,7 +608,7 @@ static int dsps_musb_reset(struct musb *musb) int session_restart = 0, error; if (glue->sw_babble_enabled) - session_restart = sw_babble_control(musb); + session_restart = dsps_sw_babble_control(musb); /* * In case of new silicon version babble condition can be recovered * without resetting the MUSB. But for older silicon versions, MUSB -- cgit v0.10.2 From e1eb3eb8b02c5be35ea1fedccc6c9c6d2c9b0165 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Thu, 26 Feb 2015 11:26:09 -0600 Subject: usb: musb: core: refactor IRQ enable/disable to separate functions sometimes we want to just mask/unmask interrupts without touching devctl register. For those cases, let's introduce musb_enable_interrupts and musb_disable_interrupts() Tested-by: Bin Liu Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index b86e975..8ae2426 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c @@ -507,7 +507,9 @@ void musb_hnp_stop(struct musb *musb) musb->port1_status &= ~(USB_PORT_STAT_C_CONNECTION << 16); } +static void musb_disable_interrupts(struct musb *musb); static void musb_generic_disable(struct musb *musb); + /* * Interrupt Service Routine to record USB "global" interrupts. * Since these do not happen often and signify things of @@ -977,7 +979,7 @@ b_host: /*-------------------------------------------------------------------------*/ -static void musb_generic_disable(struct musb *musb) +static void musb_disable_interrupts(struct musb *musb) { void __iomem *mbase = musb->mregs; u16 temp; @@ -989,16 +991,35 @@ static void musb_generic_disable(struct musb *musb) musb->intrrxe = 0; musb_writew(mbase, MUSB_INTRRXE, 0); - /* off */ - musb_writeb(mbase, MUSB_DEVCTL, 0); - /* flush pending interrupts */ temp = musb_readb(mbase, MUSB_INTRUSB); temp = musb_readw(mbase, MUSB_INTRTX); temp = musb_readw(mbase, MUSB_INTRRX); +} + +static void musb_enable_interrupts(struct musb *musb) +{ + void __iomem *regs = musb->mregs; + + /* Set INT enable registers, enable interrupts */ + musb->intrtxe = musb->epmask; + musb_writew(regs, MUSB_INTRTXE, musb->intrtxe); + musb->intrrxe = musb->epmask & 0xfffe; + musb_writew(regs, MUSB_INTRRXE, musb->intrrxe); + musb_writeb(regs, MUSB_INTRUSBE, 0xf7); } +static void musb_generic_disable(struct musb *musb) +{ + void __iomem *mbase = musb->mregs; + + musb_disable_interrupts(musb); + + /* off */ + musb_writeb(mbase, MUSB_DEVCTL, 0); +} + /* * Program the HDRC to start (enable interrupts, dma, etc.). */ @@ -1009,13 +1030,7 @@ void musb_start(struct musb *musb) dev_dbg(musb->controller, "<== devctl %02x\n", devctl); - /* Set INT enable registers, enable interrupts */ - musb->intrtxe = musb->epmask; - musb_writew(regs, MUSB_INTRTXE, musb->intrtxe); - musb->intrrxe = musb->epmask & 0xfffe; - musb_writew(regs, MUSB_INTRRXE, musb->intrrxe); - musb_writeb(regs, MUSB_INTRUSBE, 0xf7); - + musb_enable_interrupts(musb); musb_writeb(regs, MUSB_TESTMODE, 0); /* put into basic highspeed mode and start session */ -- cgit v0.10.2 From ba7ee8bb313c4a55066c4da30292aeb9abac82d8 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Thu, 26 Feb 2015 11:31:49 -0600 Subject: usb: musb: don't touch devctl from babble recovery We do *not* want to touch devctl at all when trying to recover from babble. All we want to do is mask IRQs until we're done without our babble recovery, at which point we will unmask IRQs. Tested-by: Bin Liu Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index 8ae2426..a4e524c 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c @@ -884,7 +884,7 @@ b_host: dev_err(musb->controller, "Babble\n"); if (is_host_active(musb)) { - musb_generic_disable(musb); + musb_disable_interrupts(musb); schedule_delayed_work(&musb->recover_work, msecs_to_jiffies(100)); } @@ -1838,8 +1838,10 @@ static void musb_recover_work(struct work_struct *data) int status, ret; ret = musb_platform_reset(musb); - if (ret) + if (ret) { + musb_enable_interrupts(musb); return; + } usb_phy_vbus_off(musb->xceiv); usleep_range(100, 200); -- cgit v0.10.2 From d5fa3e9f7398adf337f03fa3257d5e9b214078ee Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Thu, 26 Feb 2015 11:35:13 -0600 Subject: usb: musb: core: decrease delayed_work time When babble IRQ happens, we need to wait only 5.3us (320 cycles of 60MHz clock), we will give it some slack and schedule our work a 10 usecs into the future. Tested-by: Bin Liu Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index a4e524c..96d71fa2 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c @@ -886,7 +886,7 @@ b_host: if (is_host_active(musb)) { musb_disable_interrupts(musb); schedule_delayed_work(&musb->recover_work, - msecs_to_jiffies(100)); + usecs_to_jiffies(10)); } } } else { -- cgit v0.10.2 From 011d0dd5400b84e593eecfc4a17fcfb6c0c5ac60 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Thu, 26 Feb 2015 14:00:52 -0600 Subject: usb: musb: dsps: do not reset musb on babble All we have to do is, really, drop session bit and let the session restart. Big thanks goes to Bin Liu for inspiring this work. Tested-by: Bin Liu Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c index 85ebfa2..a159de1 100644 --- a/drivers/usb/musb/musb_dsps.c +++ b/drivers/usb/musb/musb_dsps.c @@ -604,31 +604,12 @@ static int dsps_musb_reset(struct musb *musb) { struct device *dev = musb->controller; struct dsps_glue *glue = dev_get_drvdata(dev->parent); - const struct dsps_musb_wrapper *wrp = glue->wrp; - int session_restart = 0, error; + int session_restart = 0; if (glue->sw_babble_enabled) session_restart = dsps_sw_babble_control(musb); - /* - * In case of new silicon version babble condition can be recovered - * without resetting the MUSB. But for older silicon versions, MUSB - * reset is needed - */ - if (session_restart || !glue->sw_babble_enabled) { - dev_info(musb->controller, "Restarting MUSB to recover from Babble\n"); - dsps_writel(musb->ctrl_base, wrp->control, (1 << wrp->reset)); - usleep_range(100, 200); - usb_phy_shutdown(musb->xceiv); - error = phy_power_off(musb->phy); - if (error) - dev_err(dev, "phy shutdown failed: %i\n", error); - usleep_range(100, 200); - usb_phy_init(musb->xceiv); - error = phy_power_on(musb->phy); - if (error) - dev_err(dev, "phy powerup failed: %i\n", error); + else session_restart = 1; - } return session_restart ? 0 : -EPIPE; } -- cgit v0.10.2 From b4dc38fd45b63e3da2bc98db5d283a15a637a2fa Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Thu, 26 Feb 2015 14:02:35 -0600 Subject: usb: musb: core: simplify musb_recover_work() we're not resetting musb at all, just restarting the session. This means we don't need to touch PHYs or VBUS or anything like that. Just make sure session bit is reenabled after MUSB dropped it. while at that, make sure to tell usbcore that we're dropping the session and, thus, disconnecting the device. Tested-by: Bin Liu Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index 96d71fa2..979bc2b 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c @@ -1835,7 +1835,8 @@ static void musb_irq_work(struct work_struct *data) static void musb_recover_work(struct work_struct *data) { struct musb *musb = container_of(data, struct musb, recover_work.work); - int status, ret; + int ret; + u8 devctl; ret = musb_platform_reset(musb); if (ret) { @@ -1843,23 +1844,25 @@ static void musb_recover_work(struct work_struct *data) return; } - usb_phy_vbus_off(musb->xceiv); - usleep_range(100, 200); + /* drop session bit */ + devctl = musb_readb(musb->mregs, MUSB_DEVCTL); + devctl &= ~MUSB_DEVCTL_SESSION; + musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); - usb_phy_vbus_on(musb->xceiv); - usleep_range(100, 200); + /* tell usbcore about it */ + musb_root_disconnect(musb); /* * When a babble condition occurs, the musb controller * removes the session bit and the endpoint config is lost. */ if (musb->dyn_fifo) - status = ep_config_from_table(musb); + ret = ep_config_from_table(musb); else - status = ep_config_from_hw(musb); + ret = ep_config_from_hw(musb); - /* start the session again */ - if (status == 0) + /* restart session */ + if (ret == 0) musb_start(musb); } -- cgit v0.10.2 From b28a6432405ca95b3da25630d79d2463c754a79c Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Thu, 26 Feb 2015 14:20:58 -0600 Subject: usb: musb: rename ->reset() to ->recover() recover is a much better name than reset, considering we don't really reset the IP, just run platform-specific babble recovery algorithm. while at that, also fix a typo in comment and add kdoc for recover memeber of platform_ops. Tested-by: Bin Liu Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index 979bc2b..bf97462 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c @@ -1838,7 +1838,7 @@ static void musb_recover_work(struct work_struct *data) int ret; u8 devctl; - ret = musb_platform_reset(musb); + ret = musb_platform_recover(musb); if (ret) { musb_enable_interrupts(musb); return; diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h index 5e65958..1e03c7e 100644 --- a/drivers/usb/musb/musb_core.h +++ b/drivers/usb/musb/musb_core.h @@ -160,7 +160,8 @@ struct musb_io; * @init: turns on clocks, sets up platform-specific registers, etc * @exit: undoes @init * @set_mode: forcefully changes operating mode - * @try_ilde: tries to idle the IP + * @try_idle: tries to idle the IP + * @recover: platform-specific babble recovery * @vbus_status: returns vbus status if possible * @set_vbus: forces vbus status * @adjust_channel_params: pre check for standard dma channel_program func @@ -196,7 +197,7 @@ struct musb_platform_ops { void (*write_fifo)(struct musb_hw_ep *hw_ep, u16 len, const u8 *buf); int (*set_mode)(struct musb *musb, u8 mode); void (*try_idle)(struct musb *musb, unsigned long timeout); - int (*reset)(struct musb *musb); + int (*recover)(struct musb *musb); int (*vbus_status)(struct musb *musb); void (*set_vbus)(struct musb *musb, int on); @@ -558,12 +559,12 @@ static inline void musb_platform_try_idle(struct musb *musb, musb->ops->try_idle(musb, timeout); } -static inline int musb_platform_reset(struct musb *musb) +static inline int musb_platform_recover(struct musb *musb) { - if (!musb->ops->reset) - return -EINVAL; + if (!musb->ops->recover) + return 0; - return musb->ops->reset(musb); + return musb->ops->recover(musb); } static inline int musb_platform_get_vbus_status(struct musb *musb) diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c index a159de1..30eb6ac 100644 --- a/drivers/usb/musb/musb_dsps.c +++ b/drivers/usb/musb/musb_dsps.c @@ -600,7 +600,7 @@ static bool dsps_sw_babble_control(struct musb *musb) return session_restart; } -static int dsps_musb_reset(struct musb *musb) +static int dsps_musb_recover(struct musb *musb) { struct device *dev = musb->controller; struct dsps_glue *glue = dev_get_drvdata(dev->parent); @@ -624,7 +624,7 @@ static struct musb_platform_ops dsps_ops = { .try_idle = dsps_musb_try_idle, .set_mode = dsps_musb_set_mode, - .reset = dsps_musb_reset, + .recover = dsps_musb_recover, }; static u64 musb_dmamask = DMA_BIT_MASK(32); -- cgit v0.10.2 From 83b8f5b8c07c8cbad8c14c7b8767e7219a6c1813 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Thu, 26 Feb 2015 14:27:12 -0600 Subject: usb: musb: core: drop recover_work that's not needed anymore. Everything that we call is irq-safe, so we might as well not have a delayed work for babble recovery. Tested-by: Bin Liu Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index bf97462..b410af6 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c @@ -509,6 +509,7 @@ void musb_hnp_stop(struct musb *musb) static void musb_disable_interrupts(struct musb *musb); static void musb_generic_disable(struct musb *musb); +static void musb_recover_from_babble(struct musb *musb); /* * Interrupt Service Routine to record USB "global" interrupts. @@ -885,8 +886,7 @@ b_host: if (is_host_active(musb)) { musb_disable_interrupts(musb); - schedule_delayed_work(&musb->recover_work, - usecs_to_jiffies(10)); + musb_recover_from_babble(musb); } } } else { @@ -1831,13 +1831,17 @@ static void musb_irq_work(struct work_struct *data) } } -/* Recover from babble interrupt conditions */ -static void musb_recover_work(struct work_struct *data) +static void musb_recover_from_babble(struct musb *musb) { - struct musb *musb = container_of(data, struct musb, recover_work.work); int ret; u8 devctl; + /* + * wait at least 320 cycles of 60MHz clock. That's 5.3us, we will give + * it some slack and wait for 10us. + */ + udelay(10); + ret = musb_platform_recover(musb); if (ret) { musb_enable_interrupts(musb); @@ -2098,7 +2102,6 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl) /* Init IRQ workqueue before request_irq */ INIT_WORK(&musb->irq_work, musb_irq_work); - INIT_DELAYED_WORK(&musb->recover_work, musb_recover_work); INIT_DELAYED_WORK(&musb->deassert_reset_work, musb_deassert_reset); INIT_DELAYED_WORK(&musb->finish_resume_work, musb_host_finish_resume); @@ -2194,7 +2197,6 @@ fail4: fail3: cancel_work_sync(&musb->irq_work); - cancel_delayed_work_sync(&musb->recover_work); cancel_delayed_work_sync(&musb->finish_resume_work); cancel_delayed_work_sync(&musb->deassert_reset_work); if (musb->dma_controller) @@ -2260,7 +2262,6 @@ static int musb_remove(struct platform_device *pdev) dma_controller_destroy(musb->dma_controller); cancel_work_sync(&musb->irq_work); - cancel_delayed_work_sync(&musb->recover_work); cancel_delayed_work_sync(&musb->finish_resume_work); cancel_delayed_work_sync(&musb->deassert_reset_work); musb_free(musb); diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h index 1e03c7e..3877249 100644 --- a/drivers/usb/musb/musb_core.h +++ b/drivers/usb/musb/musb_core.h @@ -301,7 +301,6 @@ struct musb { irqreturn_t (*isr)(int, void *); struct work_struct irq_work; - struct delayed_work recover_work; struct delayed_work deassert_reset_work; struct delayed_work finish_resume_work; u16 hwvers; -- cgit v0.10.2 From 06753fe115c517b715616ef7ef4f56b1b46ecc69 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Thu, 26 Feb 2015 14:33:41 -0600 Subject: usb: musb: core: remove unnecessary forward declaration no functional changes, cleanup only. Tested-by: Bin Liu Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index b410af6..ecf2219 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c @@ -508,7 +508,6 @@ void musb_hnp_stop(struct musb *musb) } static void musb_disable_interrupts(struct musb *musb); -static void musb_generic_disable(struct musb *musb); static void musb_recover_from_babble(struct musb *musb); /* -- cgit v0.10.2 From 0244336f812583299291e18b69a75be5674e819f Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Thu, 26 Feb 2015 14:42:19 -0600 Subject: usb: musb: core: disable irqs inside babble recovery There's no point is splitting those anymore. We're now also able to drop another forward declaration. Tested-by: Bin Liu Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index ecf2219..3916e73 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c @@ -507,7 +507,6 @@ void musb_hnp_stop(struct musb *musb) musb->port1_status &= ~(USB_PORT_STAT_C_CONNECTION << 16); } -static void musb_disable_interrupts(struct musb *musb); static void musb_recover_from_babble(struct musb *musb); /* @@ -883,10 +882,8 @@ b_host: if (power & MUSB_POWER_HSMODE) { dev_err(musb->controller, "Babble\n"); - if (is_host_active(musb)) { - musb_disable_interrupts(musb); + if (is_host_active(musb)) musb_recover_from_babble(musb); - } } } else { dev_dbg(musb->controller, "BUS RESET as %s\n", @@ -1835,6 +1832,8 @@ static void musb_recover_from_babble(struct musb *musb) int ret; u8 devctl; + musb_disable_interrupts(musb); + /* * wait at least 320 cycles of 60MHz clock. That's 5.3us, we will give * it some slack and wait for 10us. -- cgit v0.10.2 From 34754dec8ab83799a0a37f2a7ada8ce1e53d174b Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Thu, 26 Feb 2015 14:43:57 -0600 Subject: usb: musb: core: always try to recover from babble we can also have babble conditions with LS/FS and we also want to recover in that case. Because of that we will drop the check of HSMODE and always try to run babble recovery. Suggested-by: Bin Liu Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index 3916e73..a48b5a9 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c @@ -863,28 +863,18 @@ b_host: if (int_usb & MUSB_INTR_RESET) { handled = IRQ_HANDLED; if (devctl & MUSB_DEVCTL_HM) { - u8 power = musb_readl(musb->mregs, MUSB_POWER); - /* - * Looks like non-HS BABBLE can be ignored, but - * HS BABBLE is an error condition. - * - * For HS the solution is to avoid babble in the first - * place and fix what caused BABBLE. - * - * When HS BABBLE happens what we can depends on which + * When BABBLE happens what we can depends on which * platform MUSB is running, because some platforms * implemented proprietary means for 'recovering' from * Babble conditions. One such platform is AM335x. In - * most cases, however, the only thing we can do is drop - * the session. + * most cases, however, the only thing we can do is + * drop the session. */ - if (power & MUSB_POWER_HSMODE) { - dev_err(musb->controller, "Babble\n"); + dev_err(musb->controller, "Babble\n"); - if (is_host_active(musb)) - musb_recover_from_babble(musb); - } + if (is_host_active(musb)) + musb_recover_from_babble(musb); } else { dev_dbg(musb->controller, "BUS RESET as %s\n", usb_otg_state_string(musb->xceiv->otg->state)); -- cgit v0.10.2 From a285f40d80d440853ac908017d6d949ae2a7f88e Mon Sep 17 00:00:00 2001 From: Mian Yousaf Kaukab Date: Mon, 2 Feb 2015 10:55:23 +0100 Subject: usb: gadget: net2280: use ep_autoconfig compatible names in advance mode Each struct usb_ep added for net2280 can be used in either direction. Whereas, each struct usb_ep for usb3380 has fixed direction. Use ep_autoconf compatible names so that endpoint with correct direction can be selected. Name sequence is due to the logic in usb_reinit_338x() in ne[] and ep_reg_addr[]. Signed-off-by: Mian Yousaf Kaukab Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/udc/net2280.c b/drivers/usb/gadget/udc/net2280.c index d2c0bf6..b7024dc 100644 --- a/drivers/usb/gadget/udc/net2280.c +++ b/drivers/usb/gadget/udc/net2280.c @@ -80,6 +80,13 @@ static const char *const ep_name[] = { "ep-e", "ep-f", "ep-g", "ep-h", }; +/* Endpoint names for usb3380 advance mode */ +static const char *const ep_name_adv[] = { + ep0name, + "ep1in", "ep2out", "ep3in", "ep4out", + "ep1out", "ep2in", "ep3out", "ep4in", +}; + /* mode 0 == ep-{a,b,c,d} 1K fifo each * mode 1 == ep-{a,b} 2K fifo each, ep-{c,d} unavailable * mode 2 == ep-a 2K fifo, ep-{b,c} 1K each, ep-d unavailable @@ -1977,7 +1984,7 @@ static void usb_reinit_338x(struct net2280 *dev) for (i = 0; i < dev->n_ep; i++) { struct net2280_ep *ep = &dev->ep[i]; - ep->ep.name = ep_name[i]; + ep->ep.name = dev->enhanced_mode ? ep_name_adv[i] : ep_name[i]; ep->dev = dev; ep->num = i; -- cgit v0.10.2 From fb2a85dd933c2793f5aabeb84af8b3bc00c0c968 Mon Sep 17 00:00:00 2001 From: Mian Yousaf Kaukab Date: Mon, 2 Feb 2015 10:55:24 +0100 Subject: usb: gadget: net2280: remove fiforegs as it is unused Remove fiforegs from struct net2280 and net2280_ep as it is unused. By the way, ep->fiforegs = &dev->fiforegs[i] assignment is incorrect. It should be ep->fiforegs = &dev->fiforegs[ne[i]], but it doesn't matter now. Signed-off-by: Mian Yousaf Kaukab Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/udc/net2280.c b/drivers/usb/gadget/udc/net2280.c index b7024dc..d51430f 100644 --- a/drivers/usb/gadget/udc/net2280.c +++ b/drivers/usb/gadget/udc/net2280.c @@ -1996,11 +1996,9 @@ static void usb_reinit_338x(struct net2280 *dev) ep->regs = (struct net2280_ep_regs __iomem *) (((void __iomem *)&dev->epregs[ne[i]]) + ep_reg_addr[i]); - ep->fiforegs = &dev->fiforegs[i]; } else { ep->cfg = &dev->epregs[i]; ep->regs = &dev->epregs[i]; - ep->fiforegs = &dev->fiforegs[i]; } ep->fifo_size = (i != 0) ? 2048 : 512; @@ -3380,8 +3378,6 @@ static int net2280_probe(struct pci_dev *pdev, const struct pci_device_id *id) u32 usbstat; dev->usb_ext = (struct usb338x_usb_ext_regs __iomem *) (base + 0x00b4); - dev->fiforegs = (struct usb338x_fifo_regs __iomem *) - (base + 0x0500); dev->llregs = (struct usb338x_ll_regs __iomem *) (base + 0x0700); dev->ll_lfps_regs = (struct usb338x_ll_lfps_regs __iomem *) diff --git a/drivers/usb/gadget/udc/net2280.h b/drivers/usb/gadget/udc/net2280.h index ac8d5a2..4dff60d 100644 --- a/drivers/usb/gadget/udc/net2280.h +++ b/drivers/usb/gadget/udc/net2280.h @@ -96,7 +96,6 @@ struct net2280_ep { struct net2280_ep_regs __iomem *regs; struct net2280_dma_regs __iomem *dma; struct net2280_dma *dummy; - struct usb338x_fifo_regs __iomem *fiforegs; dma_addr_t td_dma; /* of dummy */ struct net2280 *dev; unsigned long irqs; @@ -181,7 +180,6 @@ struct net2280 { struct net2280_dma_regs __iomem *dma; struct net2280_dep_regs __iomem *dep; struct net2280_ep_regs __iomem *epregs; - struct usb338x_fifo_regs __iomem *fiforegs; struct usb338x_ll_regs __iomem *llregs; struct usb338x_ll_lfps_regs __iomem *ll_lfps_regs; struct usb338x_ll_tsn_regs __iomem *ll_tsn_regs; -- cgit v0.10.2 From 9ceafcc2b3ad48ad2ef42608f1505ecad515d144 Mon Sep 17 00:00:00 2001 From: Mian Yousaf Kaukab Date: Mon, 2 Feb 2015 10:55:25 +0100 Subject: usb: gadget: net2280: print error in ep_ops error paths Hopefully, these prints will help localize the problems faster. [ balbi@ti.com: removed 2 unnecessary OOM error messages ] Signed-off-by: Mian Yousaf Kaukab Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/udc/net2280.c b/drivers/usb/gadget/udc/net2280.c index d51430f..5a8f6b6 100644 --- a/drivers/usb/gadget/udc/net2280.c +++ b/drivers/usb/gadget/udc/net2280.c @@ -145,31 +145,44 @@ net2280_enable(struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) u32 max, tmp; unsigned long flags; static const u32 ep_key[9] = { 1, 0, 1, 0, 1, 1, 0, 1, 0 }; + int ret = 0; ep = container_of(_ep, struct net2280_ep, ep); if (!_ep || !desc || ep->desc || _ep->name == ep0name || - desc->bDescriptorType != USB_DT_ENDPOINT) + desc->bDescriptorType != USB_DT_ENDPOINT) { + pr_err("%s: failed at line=%d\n", __func__, __LINE__); return -EINVAL; + } dev = ep->dev; - if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) - return -ESHUTDOWN; + if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) { + ret = -ESHUTDOWN; + goto print_err; + } /* erratum 0119 workaround ties up an endpoint number */ - if ((desc->bEndpointAddress & 0x0f) == EP_DONTUSE) - return -EDOM; + if ((desc->bEndpointAddress & 0x0f) == EP_DONTUSE) { + ret = -EDOM; + goto print_err; + } if (dev->quirks & PLX_SUPERSPEED) { - if ((desc->bEndpointAddress & 0x0f) >= 0x0c) - return -EDOM; + if ((desc->bEndpointAddress & 0x0f) >= 0x0c) { + ret = -EDOM; + goto print_err; + } ep->is_in = !!usb_endpoint_dir_in(desc); - if (dev->enhanced_mode && ep->is_in && ep_key[ep->num]) - return -EINVAL; + if (dev->enhanced_mode && ep->is_in && ep_key[ep->num]) { + ret = -EINVAL; + goto print_err; + } } /* sanity check ep-e/ep-f since their fifos are small */ max = usb_endpoint_maxp(desc) & 0x1fff; - if (ep->num > 4 && max > 64 && (dev->quirks & PLX_LEGACY)) - return -ERANGE; + if (ep->num > 4 && max > 64 && (dev->quirks & PLX_LEGACY)) { + ret = -ERANGE; + goto print_err; + } spin_lock_irqsave(&dev->lock, flags); _ep->maxpacket = max & 0x7ff; @@ -199,7 +212,8 @@ net2280_enable(struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) (dev->gadget.speed == USB_SPEED_HIGH && max != 512) || (dev->gadget.speed == USB_SPEED_FULL && max > 64)) { spin_unlock_irqrestore(&dev->lock, flags); - return -ERANGE; + ret = -ERANGE; + goto print_err; } } ep->is_iso = (tmp == USB_ENDPOINT_XFER_ISOC); @@ -278,7 +292,11 @@ net2280_enable(struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) /* pci writes may still be posted */ spin_unlock_irqrestore(&dev->lock, flags); - return 0; + return ret; + +print_err: + dev_err(&ep->dev->pdev->dev, "%s: error=%d\n", __func__, ret); + return ret; } static int handshake(u32 __iomem *ptr, u32 mask, u32 done, int usec) @@ -433,9 +451,10 @@ static int net2280_disable(struct usb_ep *_ep) unsigned long flags; ep = container_of(_ep, struct net2280_ep, ep); - if (!_ep || !ep->desc || _ep->name == ep0name) + if (!_ep || !ep->desc || _ep->name == ep0name) { + pr_err("%s: Invalid ep=%p or ep->desc\n", __func__, _ep); return -EINVAL; - + } spin_lock_irqsave(&ep->dev->lock, flags); nuke(ep); @@ -465,8 +484,10 @@ static struct usb_request struct net2280_ep *ep; struct net2280_request *req; - if (!_ep) + if (!_ep) { + pr_err("%s: Invalid ep\n", __func__); return NULL; + } ep = container_of(_ep, struct net2280_ep, ep); req = kzalloc(sizeof(*req), gfp_flags); @@ -498,8 +519,11 @@ static void net2280_free_request(struct usb_ep *_ep, struct usb_request *_req) struct net2280_request *req; ep = container_of(_ep, struct net2280_ep, ep); - if (!_ep || !_req) + if (!_ep || !_req) { + dev_err(&ep->dev->pdev->dev, "%s: Inavlid ep=%p or req=%p\n", + __func__, _ep, _req); return; + } req = container_of(_req, struct net2280_request, req); WARN_ON(!list_empty(&req->queue)); @@ -903,35 +927,44 @@ net2280_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) struct net2280_ep *ep; struct net2280 *dev; unsigned long flags; + int ret = 0; /* we always require a cpu-view buffer, so that we can * always use pio (as fallback or whatever). */ - req = container_of(_req, struct net2280_request, req); - if (!_req || !_req->complete || !_req->buf || - !list_empty(&req->queue)) - return -EINVAL; - if (_req->length > (~0 & DMA_BYTE_COUNT_MASK)) - return -EDOM; ep = container_of(_ep, struct net2280_ep, ep); - if (!_ep || (!ep->desc && ep->num != 0)) + if (!_ep || (!ep->desc && ep->num != 0)) { + pr_err("%s: Invalid ep=%p or ep->desc\n", __func__, _ep); return -EINVAL; + } + req = container_of(_req, struct net2280_request, req); + if (!_req || !_req->complete || !_req->buf || + !list_empty(&req->queue)) { + ret = -EINVAL; + goto print_err; + } + if (_req->length > (~0 & DMA_BYTE_COUNT_MASK)) { + ret = -EDOM; + goto print_err; + } dev = ep->dev; - if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) - return -ESHUTDOWN; + if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) { + ret = -ESHUTDOWN; + goto print_err; + } /* FIXME implement PIO fallback for ZLPs with DMA */ - if (ep->dma && _req->length == 0) - return -EOPNOTSUPP; + if (ep->dma && _req->length == 0) { + ret = -EOPNOTSUPP; + goto print_err; + } /* set up dma mapping in case the caller didn't */ if (ep->dma) { - int ret; - ret = usb_gadget_map_request(&dev->gadget, _req, ep->is_in); if (ret) - return ret; + goto print_err; } ep_vdbg(dev, "%s queue req %p, len %d buf %p\n", @@ -1020,7 +1053,11 @@ done: spin_unlock_irqrestore(&dev->lock, flags); /* pci writes may still be posted */ - return 0; + return ret; + +print_err: + dev_err(&ep->dev->pdev->dev, "%s: error=%d\n", __func__, ret); + return ret; } static inline void @@ -1141,8 +1178,11 @@ static int net2280_dequeue(struct usb_ep *_ep, struct usb_request *_req) int stopped; ep = container_of(_ep, struct net2280_ep, ep); - if (!_ep || (!ep->desc && ep->num != 0) || !_req) + if (!_ep || (!ep->desc && ep->num != 0) || !_req) { + pr_err("%s: Invalid ep=%p or ep->desc or req=%p\n", + __func__, _ep, _req); return -EINVAL; + } spin_lock_irqsave(&ep->dev->lock, flags); stopped = ep->stopped; @@ -1164,6 +1204,8 @@ static int net2280_dequeue(struct usb_ep *_ep, struct usb_request *_req) } if (&req->req != _req) { spin_unlock_irqrestore(&ep->dev->lock, flags); + dev_err(&ep->dev->pdev->dev, "%s: Request mismatch\n", + __func__); return -EINVAL; } @@ -1221,20 +1263,28 @@ net2280_set_halt_and_wedge(struct usb_ep *_ep, int value, int wedged) int retval = 0; ep = container_of(_ep, struct net2280_ep, ep); - if (!_ep || (!ep->desc && ep->num != 0)) + if (!_ep || (!ep->desc && ep->num != 0)) { + pr_err("%s: Invalid ep=%p or ep->desc\n", __func__, _ep); return -EINVAL; - if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) - return -ESHUTDOWN; + } + if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) { + retval = -ESHUTDOWN; + goto print_err; + } if (ep->desc /* not ep0 */ && (ep->desc->bmAttributes & 0x03) - == USB_ENDPOINT_XFER_ISOC) - return -EINVAL; + == USB_ENDPOINT_XFER_ISOC) { + retval = -EINVAL; + goto print_err; + } spin_lock_irqsave(&ep->dev->lock, flags); - if (!list_empty(&ep->queue)) + if (!list_empty(&ep->queue)) { retval = -EAGAIN; - else if (ep->is_in && value && net2280_fifo_status(_ep) != 0) + goto print_unlock; + } else if (ep->is_in && value && net2280_fifo_status(_ep) != 0) { retval = -EAGAIN; - else { + goto print_unlock; + } else { ep_vdbg(ep->dev, "%s %s %s\n", _ep->name, value ? "set" : "clear", wedged ? "wedge" : "halt"); @@ -1258,6 +1308,12 @@ net2280_set_halt_and_wedge(struct usb_ep *_ep, int value, int wedged) spin_unlock_irqrestore(&ep->dev->lock, flags); return retval; + +print_unlock: + spin_unlock_irqrestore(&ep->dev->lock, flags); +print_err: + dev_err(&ep->dev->pdev->dev, "%s: error=%d\n", __func__, retval); + return retval; } static int net2280_set_halt(struct usb_ep *_ep, int value) @@ -1267,8 +1323,10 @@ static int net2280_set_halt(struct usb_ep *_ep, int value) static int net2280_set_wedge(struct usb_ep *_ep) { - if (!_ep || _ep->name == ep0name) + if (!_ep || _ep->name == ep0name) { + pr_err("%s: Invalid ep=%p or ep0\n", __func__, _ep); return -EINVAL; + } return net2280_set_halt_and_wedge(_ep, 1, 1); } @@ -1278,14 +1336,22 @@ static int net2280_fifo_status(struct usb_ep *_ep) u32 avail; ep = container_of(_ep, struct net2280_ep, ep); - if (!_ep || (!ep->desc && ep->num != 0)) + if (!_ep || (!ep->desc && ep->num != 0)) { + pr_err("%s: Invalid ep=%p or ep->desc\n", __func__, _ep); return -ENODEV; - if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) + } + if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) { + dev_err(&ep->dev->pdev->dev, + "%s: Invalid driver=%p or speed=%d\n", + __func__, ep->dev->driver, ep->dev->gadget.speed); return -ESHUTDOWN; + } avail = readl(&ep->regs->ep_avail) & (BIT(12) - 1); - if (avail > ep->fifo_size) + if (avail > ep->fifo_size) { + dev_err(&ep->dev->pdev->dev, "%s: Fifo overflow\n", __func__); return -EOVERFLOW; + } if (ep->is_in) avail = ep->fifo_size - avail; return avail; @@ -1296,10 +1362,16 @@ static void net2280_fifo_flush(struct usb_ep *_ep) struct net2280_ep *ep; ep = container_of(_ep, struct net2280_ep, ep); - if (!_ep || (!ep->desc && ep->num != 0)) + if (!_ep || (!ep->desc && ep->num != 0)) { + pr_err("%s: Invalid ep=%p or ep->desc\n", __func__, _ep); return; - if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) + } + if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) { + dev_err(&ep->dev->pdev->dev, + "%s: Invalid driver=%p or speed=%d\n", + __func__, ep->dev->driver, ep->dev->gadget.speed); return; + } writel(BIT(FIFO_FLUSH), &ep->regs->ep_stat); (void) readl(&ep->regs->ep_rsp); -- cgit v0.10.2 From 12366ef1942128d9bd8baa77e7eb4010b18fd676 Mon Sep 17 00:00:00 2001 From: Mian Yousaf Kaukab Date: Mon, 2 Feb 2015 10:55:26 +0100 Subject: usb: gadget: net2280: don't connect from udc_start net2280_start can be called with pullup disabled. Don't set softconnect flag in it. Let net2280_pullup handle the connection part. Signed-off-by: Mian Yousaf Kaukab Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/udc/net2280.c b/drivers/usb/gadget/udc/net2280.c index 5a8f6b6..5041e21 100644 --- a/drivers/usb/gadget/udc/net2280.c +++ b/drivers/usb/gadget/udc/net2280.c @@ -2263,7 +2263,6 @@ static int net2280_start(struct usb_gadget *_gadget, dev->ep[i].irqs = 0; /* hook up the driver ... */ - dev->softconnect = 1; driver->driver.bus = NULL; dev->driver = driver; -- cgit v0.10.2 From ccf5fb698155ee289b9257b0f1d6be3c7900ba0a Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Fri, 27 Feb 2015 09:44:51 -0600 Subject: usb: gadget: net2280: silence sparse warning Silence the following warning: drivers/usb/gadget/udc/net2280.c:3176:33: warning: context imbalance in 'handle_stat1_irqs' - unexpected unlock Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/udc/net2280.c b/drivers/usb/gadget/udc/net2280.c index 5041e21..9871b90 100644 --- a/drivers/usb/gadget/udc/net2280.c +++ b/drivers/usb/gadget/udc/net2280.c @@ -3128,6 +3128,8 @@ next_endpoints: BIT(PCI_RETRY_ABORT_INTERRUPT)) static void handle_stat1_irqs(struct net2280 *dev, u32 stat) +__releases(dev->lock) +__acquires(dev->lock) { struct net2280_ep *ep; u32 tmp, num, mask, scratch; -- cgit v0.10.2 From 1b61625f8b5d87caf9633d7dbfbaf1ea8270036d Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Fri, 27 Feb 2015 13:19:39 -0600 Subject: usb: musb: cppi41: decrease indentation level no functional changes, clean up only. Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_cppi41.c b/drivers/usb/musb/musb_cppi41.c index be84562..73ac983 100644 --- a/drivers/usb/musb/musb_cppi41.c +++ b/drivers/usb/musb/musb_cppi41.c @@ -225,10 +225,12 @@ static void cppi41_dma_callback(void *private_data) struct dma_channel *channel = private_data; struct cppi41_dma_channel *cppi41_channel = channel->private_data; struct musb_hw_ep *hw_ep = cppi41_channel->hw_ep; + struct cppi41_dma_controller *controller; struct musb *musb = hw_ep->musb; unsigned long flags; struct dma_tx_state txstate; u32 transferred; + int is_hs = 0; bool empty; spin_lock_irqsave(&musb->lock, flags); @@ -251,58 +253,58 @@ static void cppi41_dma_callback(void *private_data) empty = musb_is_tx_fifo_empty(hw_ep); if (empty) { cppi41_trans_done(cppi41_channel); - } else { - struct cppi41_dma_controller *controller; - int is_hs = 0; - /* - * On AM335x it has been observed that the TX interrupt fires - * too early that means the TXFIFO is not yet empty but the DMA - * engine says that it is done with the transfer. We don't - * receive a FIFO empty interrupt so the only thing we can do is - * to poll for the bit. On HS it usually takes 2us, on FS around - * 110us - 150us depending on the transfer size. - * We spin on HS (no longer than than 25us and setup a timer on - * FS to check for the bit and complete the transfer. - */ - controller = cppi41_channel->controller; + goto out; + } - if (is_host_active(musb)) { - if (musb->port1_status & USB_PORT_STAT_HIGH_SPEED) - is_hs = 1; - } else { - if (musb->g.speed == USB_SPEED_HIGH) - is_hs = 1; - } - if (is_hs) { - unsigned wait = 25; - - do { - empty = musb_is_tx_fifo_empty(hw_ep); - if (empty) - break; - wait--; - if (!wait) - break; - udelay(1); - } while (1); + /* + * On AM335x it has been observed that the TX interrupt fires + * too early that means the TXFIFO is not yet empty but the DMA + * engine says that it is done with the transfer. We don't + * receive a FIFO empty interrupt so the only thing we can do is + * to poll for the bit. On HS it usually takes 2us, on FS around + * 110us - 150us depending on the transfer size. + * We spin on HS (no longer than than 25us and setup a timer on + * FS to check for the bit and complete the transfer. + */ + controller = cppi41_channel->controller; + + if (is_host_active(musb)) { + if (musb->port1_status & USB_PORT_STAT_HIGH_SPEED) + is_hs = 1; + } else { + if (musb->g.speed == USB_SPEED_HIGH) + is_hs = 1; + } + if (is_hs) { + unsigned wait = 25; + do { empty = musb_is_tx_fifo_empty(hw_ep); - if (empty) { - cppi41_trans_done(cppi41_channel); - goto out; - } + if (empty) + break; + wait--; + if (!wait) + break; + udelay(1); + } while (1); + + empty = musb_is_tx_fifo_empty(hw_ep); + if (empty) { + cppi41_trans_done(cppi41_channel); + goto out; } - list_add_tail(&cppi41_channel->tx_check, - &controller->early_tx_list); - if (!hrtimer_is_queued(&controller->early_tx)) { - unsigned long usecs = cppi41_channel->total_len / 10; + } + list_add_tail(&cppi41_channel->tx_check, + &controller->early_tx_list); + if (!hrtimer_is_queued(&controller->early_tx)) { + unsigned long usecs = cppi41_channel->total_len / 10; - hrtimer_start_range_ns(&controller->early_tx, + hrtimer_start_range_ns(&controller->early_tx, ktime_set(0, usecs * NSEC_PER_USEC), 20 * NSEC_PER_USEC, HRTIMER_MODE_REL); - } } + out: spin_unlock_irqrestore(&musb->lock, flags); } -- cgit v0.10.2 From af63429cf046210d7313805b579dd779d10ad1c0 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Fri, 27 Feb 2015 13:21:14 -0600 Subject: usb: musb: cppi41: exit early when tx fifo is empty as soon as we find out tx fifo is empty, there's no need to break out of the loop just to have another branch to complete the transfer. We can just complete transfer and exit early. Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_cppi41.c b/drivers/usb/musb/musb_cppi41.c index 73ac983..4407f30 100644 --- a/drivers/usb/musb/musb_cppi41.c +++ b/drivers/usb/musb/musb_cppi41.c @@ -280,19 +280,15 @@ static void cppi41_dma_callback(void *private_data) do { empty = musb_is_tx_fifo_empty(hw_ep); - if (empty) - break; + if (empty) { + cppi41_trans_done(cppi41_channel); + goto out; + } wait--; if (!wait) break; udelay(1); } while (1); - - empty = musb_is_tx_fifo_empty(hw_ep); - if (empty) { - cppi41_trans_done(cppi41_channel); - goto out; - } } list_add_tail(&cppi41_channel->tx_check, &controller->early_tx_list); -- cgit v0.10.2 From 043f5b75dd2b1fbd45d5f367d50e5ae5b4afa955 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Fri, 27 Feb 2015 13:22:27 -0600 Subject: usb: musb: cppi41: do not call udelay() according to comment in code, HS completion will happen pretty fast, instead of using udelay(), let's just busy loop and drop a cpu_relax() where udelay() was. Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_cppi41.c b/drivers/usb/musb/musb_cppi41.c index 4407f30..9dc45a4 100644 --- a/drivers/usb/musb/musb_cppi41.c +++ b/drivers/usb/musb/musb_cppi41.c @@ -287,7 +287,7 @@ static void cppi41_dma_callback(void *private_data) wait--; if (!wait) break; - udelay(1); + cpu_relax(); } while (1); } list_add_tail(&cppi41_channel->tx_check, -- cgit v0.10.2 From 9e204d885a6d0ae3696284bacd86e2b94dd936c8 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Fri, 27 Feb 2015 19:02:41 -0600 Subject: usb: musb: dsps: use msecs_to_jiffies instead when polling, we were using n * HZ (where n is an integer in seconds), however HZ isn't always correct if we're using cpufreq. A better way is to use msecs_to_jiffies(n) (where n is now an integer in miliseconds). while at that, also rename poll_seconds to poll_timeout and change its type to unsigned int. Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c index 30eb6ac..9271450 100644 --- a/drivers/usb/musb/musb_dsps.c +++ b/drivers/usb/musb/musb_dsps.c @@ -119,7 +119,7 @@ struct dsps_musb_wrapper { unsigned iddig:5; unsigned iddig_mux:5; /* miscellaneous stuff */ - u8 poll_seconds; + unsigned poll_timeout; }; /* @@ -285,7 +285,8 @@ static void otg_timer(unsigned long _musb) } if (!(devctl & MUSB_DEVCTL_SESSION) && !skip_session) dsps_writeb(mregs, MUSB_DEVCTL, MUSB_DEVCTL_SESSION); - mod_timer(&glue->timer, jiffies + wrp->poll_seconds * HZ); + mod_timer(&glue->timer, jiffies + + msecs_to_jiffies(wrp->poll_timeout)); break; case OTG_STATE_A_WAIT_VFALL: musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; @@ -352,8 +353,8 @@ static irqreturn_t dsps_interrupt(int irq, void *hci) */ musb->int_usb &= ~MUSB_INTR_VBUSERROR; musb->xceiv->otg->state = OTG_STATE_A_WAIT_VFALL; - mod_timer(&glue->timer, - jiffies + wrp->poll_seconds * HZ); + mod_timer(&glue->timer, jiffies + + msecs_to_jiffies(wrp->poll_timeout)); WARNING("VBUS error workaround (delay coming)\n"); } else if (drvvbus) { MUSB_HST_MODE(musb); @@ -382,7 +383,8 @@ static irqreturn_t dsps_interrupt(int irq, void *hci) /* Poll for ID change in OTG port mode */ if (musb->xceiv->otg->state == OTG_STATE_B_IDLE && musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE) - mod_timer(&glue->timer, jiffies + wrp->poll_seconds * HZ); + mod_timer(&glue->timer, jiffies + + msecs_to_jiffies(wrp->poll_timeout)); out: spin_unlock_irqrestore(&musb->lock, flags); @@ -832,7 +834,7 @@ static const struct dsps_musb_wrapper am33xx_driver_data = { .rxep_shift = 16, .rxep_mask = 0xfffe, .rxep_bitmap = (0xfffe << 16), - .poll_seconds = 2, + .poll_timeout = 2000, /* ms */ }; static const struct of_device_id musb_dsps_of_match[] = { @@ -888,7 +890,8 @@ static int dsps_resume(struct device *dev) dsps_writel(mbase, wrp->rx_mode, glue->context.rx_mode); if (musb->xceiv->otg->state == OTG_STATE_B_IDLE && musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE) - mod_timer(&glue->timer, jiffies + wrp->poll_seconds * HZ); + mod_timer(&glue->timer, jiffies + + msecs_to_jiffies(wrp->poll_timeout)); return 0; } -- cgit v0.10.2 From ad78c918602cb7cce0fab5d5813213853a6f351d Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Fri, 27 Feb 2015 19:07:49 -0600 Subject: usb: musb: dsps: just start polling already there's no need to fake an IRQ, just check if VBUS is valid already. Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c index 9271450..baa757b 100644 --- a/drivers/usb/musb/musb_dsps.c +++ b/drivers/usb/musb/musb_dsps.c @@ -225,9 +225,8 @@ static void dsps_musb_enable(struct musb *musb) dsps_writel(reg_base, wrp->epintr_set, epmask); dsps_writel(reg_base, wrp->coreintr_set, coremask); - /* Force the DRVVBUS IRQ so we can start polling for ID change. */ - dsps_writel(reg_base, wrp->coreintr_set, - (1 << wrp->drvvbus) << wrp->usb_shift); + /* start polling for ID change. */ + mod_timer(&glue->timer, jiffies + msecs_to_jiffies(wrp->poll_timeout)); dsps_musb_try_idle(musb, 0); } -- cgit v0.10.2 From eac68e8f979b82d257eea0a4bbcda7b169d330bf Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Mon, 9 Mar 2015 15:06:12 +0100 Subject: usb: dwc3: make LPM configurable in DT This patch removes "Enable USB3 LPM Capability" option from Kconfig and adds snps,usb3_lpm_capable devicetree property instead of it. USB3 LPM (Link Power Management) capability is hardware property, and it's platform dependent, so if our hardware supports this feature, we want rather to configure it in devicetree than having it as Kconfig option. Signed-off-by: Robert Baldyga Signed-off-by: Felipe Balbi diff --git a/Documentation/devicetree/bindings/usb/dwc3.txt b/Documentation/devicetree/bindings/usb/dwc3.txt index cd7f045..5cc3643 100644 --- a/Documentation/devicetree/bindings/usb/dwc3.txt +++ b/Documentation/devicetree/bindings/usb/dwc3.txt @@ -14,6 +14,7 @@ Optional properties: - phys: from the *Generic PHY* bindings - phy-names: from the *Generic PHY* bindings - tx-fifo-resize: determines if the FIFO *has* to be reallocated. + - snps,usb3_lpm_capable: determines if platform is USB3 LPM capable - snps,disable_scramble_quirk: true when SW should disable data scrambling. Only really useful for FPGA builds. - snps,has-lpm-erratum: true when DWC3 was configured with LPM Erratum enabled diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig index edbf9c8..827c4f8 100644 --- a/drivers/usb/dwc3/Kconfig +++ b/drivers/usb/dwc3/Kconfig @@ -104,11 +104,4 @@ config USB_DWC3_DEBUG help Say Y here to enable debugging messages on DWC3 Driver. -config DWC3_HOST_USB3_LPM_ENABLE - bool "Enable USB3 LPM Capability" - depends on USB_DWC3_HOST=y || USB_DWC3_DUAL_ROLE=y - default n - help - Select this when you want to enable USB3 LPM with dwc3 xhci host. - endif diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index cd59e91..2bbab3d 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -804,6 +804,8 @@ static int dwc3_probe(struct platform_device *pdev) "snps,is-utmi-l1-suspend"); of_property_read_u8(node, "snps,hird-threshold", &hird_threshold); + dwc->usb3_lpm_capable = of_property_read_bool(node, + "snps,usb3_lpm_capable"); dwc->needs_fifo_resize = of_property_read_bool(node, "tx-fifo-resize"); @@ -844,6 +846,7 @@ static int dwc3_probe(struct platform_device *pdev) hird_threshold = pdata->hird_threshold; dwc->needs_fifo_resize = pdata->tx_fifo_resize; + dwc->usb3_lpm_capable = pdata->usb3_lpm_capable; dwc->dr_mode = pdata->dr_mode; dwc->disable_scramble_quirk = pdata->disable_scramble_quirk; diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index d201910..fdab715 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -689,6 +689,7 @@ struct dwc3_scratchpad_array { * @setup_packet_pending: true when there's a Setup Packet in FIFO. Workaround * @start_config_issued: true when StartConfig command has been issued * @three_stage_setup: set if we perform a three phase setup + * @usb3_lpm_capable: set if hadrware supports Link Power Management * @disable_scramble_quirk: set if we enable the disable scramble quirk * @u2exit_lfps_quirk: set if we enable u2exit lfps quirk * @u2ss_inp3_quirk: set if we enable P3 OK for U2/SS Inactive quirk @@ -812,6 +813,7 @@ struct dwc3 { unsigned setup_packet_pending:1; unsigned start_config_issued:1; unsigned three_stage_setup:1; + unsigned usb3_lpm_capable:1; unsigned disable_scramble_quirk:1; unsigned u2exit_lfps_quirk:1; diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c index 12bfd3c..c679f63 100644 --- a/drivers/usb/dwc3/host.c +++ b/drivers/usb/dwc3/host.c @@ -49,9 +49,7 @@ int dwc3_host_init(struct dwc3 *dwc) memset(&pdata, 0, sizeof(pdata)); -#ifdef CONFIG_DWC3_HOST_USB3_LPM_ENABLE - pdata.usb3_lpm_capable = 1; -#endif + pdata.usb3_lpm_capable = dwc->usb3_lpm_capable; ret = platform_device_add_data(xhci, &pdata, sizeof(pdata)); if (ret) { diff --git a/drivers/usb/dwc3/platform_data.h b/drivers/usb/dwc3/platform_data.h index a3a3b6d..a2bd464 100644 --- a/drivers/usb/dwc3/platform_data.h +++ b/drivers/usb/dwc3/platform_data.h @@ -24,6 +24,7 @@ struct dwc3_platform_data { enum usb_device_speed maximum_speed; enum usb_dr_mode dr_mode; bool tx_fifo_resize; + bool usb3_lpm_capable; unsigned is_utmi_l1_suspend:1; u8 hird_threshold; -- cgit v0.10.2 From 232c0102e84b7fce634c8902a5fa30ca2b3342ac Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Tue, 3 Mar 2015 10:52:04 +0100 Subject: usb: gadget: composite: don't try standard handling for non-standard requests If a non-standard request is processed and its parameters just happen to match those of some standard request, the logic of composite_setup() can be fooled, so don't even try any switch cases, just go to the proper place where unknown requests are handled. Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 13adfd1..9fb9231 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -1472,6 +1472,13 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) req->length = 0; gadget->ep0->driver_data = cdev; + /* + * Don't let non-standard requests match any of the cases below + * by accident. + */ + if ((ctrl->bRequestType & USB_TYPE_MASK) != USB_TYPE_STANDARD) + goto unknown; + switch (ctrl->bRequest) { /* we handle all standard USB descriptors */ -- cgit v0.10.2 From eb132ccbdec5df46e29c9814adf76075ce83576b Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Tue, 3 Mar 2015 10:52:05 +0100 Subject: usb: gadget: printer: enqueue printer's response for setup request Function-specific setup requests should be handled in such a way, that apart from filling in the data buffer, the requests are also actually enqueued: if function-specific setup is called from composte_setup(), the "usb_ep_queue()" block of code in composite_setup() is skipped. The printer function lacks this part and it results in e.g. get device id requests failing: the host expects some response, the device prepares it but does not equeue it for sending to the host, so the host finally asserts timeout. This patch adds enqueueing the prepared responses. Cc: # v3.4+ Fixes: 2e87edf49227: "usb: gadget: make g_printer use composite" Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c index 90545980..6385c19 100644 --- a/drivers/usb/gadget/legacy/printer.c +++ b/drivers/usb/gadget/legacy/printer.c @@ -1031,6 +1031,15 @@ unknown: break; } /* host either stalls (value < 0) or reports success */ + if (value >= 0) { + req->length = value; + req->zero = value < wLength; + value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC); + if (value < 0) { + ERROR(dev, "%s:%d Error!\n", __func__, __LINE__); + req->status = 0; + } + } return value; } -- cgit v0.10.2 From 050f571264154b2f5b4c3c4c1581ab365064ff28 Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Tue, 3 Mar 2015 10:52:06 +0100 Subject: usb: gadget: printer: remove unused and empty printer_unbind The unbind() method is optional is usb_composite_driver. In this particular driver the method does nothing so it can be removed. Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c index 6385c19..21ea317 100644 --- a/drivers/usb/gadget/legacy/printer.c +++ b/drivers/usb/gadget/legacy/printer.c @@ -1288,11 +1288,6 @@ fail: return status; } -static int printer_unbind(struct usb_composite_dev *cdev) -{ - return 0; -} - static int __init printer_bind(struct usb_composite_dev *cdev) { int ret; @@ -1317,7 +1312,6 @@ static __refdata struct usb_composite_driver printer_driver = { .strings = dev_strings, .max_speed = USB_SPEED_SUPER, .bind = printer_bind, - .unbind = printer_unbind, }; static int __init -- cgit v0.10.2 From c69b8186945c10d245586e9f9703486e9574170c Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Tue, 3 Mar 2015 10:52:07 +0100 Subject: usb: gadget: printer: eliminate random pointer dereference struct printer_dev contains 3 list heads: tx_reqs, rx_reqs and rx_buffers. There is just one instance of this structure in the driver and it is file static, and as such initialized with all zeros. If device_create() or cdev_add() fails then "goto fail" branch is taken, which results in printer_cfg_unbind() call. The latter checks if tx_reqs, rx_reqs and rx_buffers lists are empty. The check for emptiness is in fact a check whether the "next" member of struct list_head points to the head of the list. But the heads of the lists in question have not been initialized yet and, as mentioned above, contain all zeros, so list_empty() returns false and respective "while" loop body starts executing. Here, container_of() just subtracts the offset of a struct usb_request member from an address of this same member, which results in a value somewhere near 0 or 0xfff...ff. And the argument to list_del() dereferences such a pointer which causes a disaster. This patch moves respective INIT_LIST_HEAD() invocations to a point before "goto fail" branch can be taken. Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c index 21ea317..12247d3 100644 --- a/drivers/usb/gadget/legacy/printer.c +++ b/drivers/usb/gadget/legacy/printer.c @@ -1190,6 +1190,9 @@ static int __init printer_bind_config(struct usb_configuration *c) dev->function.unbind = printer_func_unbind; dev->function.set_alt = printer_func_set_alt; dev->function.disable = printer_func_disable; + INIT_LIST_HEAD(&dev->tx_reqs); + INIT_LIST_HEAD(&dev->rx_reqs); + INIT_LIST_HEAD(&dev->rx_buffers); status = usb_add_function(c, &dev->function); if (status) @@ -1233,11 +1236,8 @@ static int __init printer_bind_config(struct usb_configuration *c) spin_lock_init(&dev->lock); mutex_init(&dev->lock_printer_io); - INIT_LIST_HEAD(&dev->tx_reqs); INIT_LIST_HEAD(&dev->tx_reqs_active); - INIT_LIST_HEAD(&dev->rx_reqs); INIT_LIST_HEAD(&dev->rx_reqs_active); - INIT_LIST_HEAD(&dev->rx_buffers); init_waitqueue_head(&dev->rx_wait); init_waitqueue_head(&dev->tx_wait); init_waitqueue_head(&dev->tx_flush_wait); -- cgit v0.10.2 From f5bda0034fba942adf5555246e248ddb66c76052 Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Tue, 3 Mar 2015 10:52:08 +0100 Subject: usb: gadget: printer: revert usb_add_function() effect in error recovery Whenever the "goto fail" branch is taken, the effect of usb_add_function() should be reverted. Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c index 12247d3..eb02a6b 100644 --- a/drivers/usb/gadget/legacy/printer.c +++ b/drivers/usb/gadget/legacy/printer.c @@ -1285,6 +1285,7 @@ static int __init printer_bind_config(struct usb_configuration *c) fail: printer_cfg_unbind(c); + usb_remove_function(c, &dev->function); return status; } -- cgit v0.10.2 From 44b316525986252bb95d356419fc9e75f0532112 Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Tue, 3 Mar 2015 10:52:09 +0100 Subject: usb: gadget: printer: add missing error handling If cdev_add() in printer_bind_config() fails, care is taken to reverse the effects of initializations completed until the fail happens. But if printer_req_alloc() fails, it is just one of the two lists that is cleaned up while the effects of cdev_add() and device_create() are not reverted. This patch changes error handling so that at least as much cleanup is done as when a failure happens before printer_req_alloc() invocations. Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c index eb02a6b..bbcd6aa 100644 --- a/drivers/usb/gadget/legacy/printer.c +++ b/drivers/usb/gadget/legacy/printer.c @@ -1249,31 +1249,18 @@ static int __init printer_bind_config(struct usb_configuration *c) dev->current_rx_bytes = 0; dev->current_rx_buf = NULL; + status = -ENOMEM; for (i = 0; i < QLEN; i++) { req = printer_req_alloc(dev->in_ep, USB_BUFSIZE, GFP_KERNEL); - if (!req) { - while (!list_empty(&dev->tx_reqs)) { - req = container_of(dev->tx_reqs.next, - struct usb_request, list); - list_del(&req->list); - printer_req_free(dev->in_ep, req); - } - return -ENOMEM; - } + if (!req) + goto fail; list_add(&req->list, &dev->tx_reqs); } for (i = 0; i < QLEN; i++) { req = printer_req_alloc(dev->out_ep, USB_BUFSIZE, GFP_KERNEL); - if (!req) { - while (!list_empty(&dev->rx_reqs)) { - req = container_of(dev->rx_reqs.next, - struct usb_request, list); - list_del(&req->list); - printer_req_free(dev->out_ep, req); - } - return -ENOMEM; - } + if (!req) + goto fail; list_add(&req->list, &dev->rx_reqs); } -- cgit v0.10.2 From 44eccced2b9aafd1eced9fb4821f26b6dff26a25 Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Tue, 3 Mar 2015 10:52:10 +0100 Subject: usb: gadget: printer: eliminate pdev member of struct printer_dev The pdev member of struct printer_dev is not used outside printer_bind_config(), so it can just as well be a local variable there. Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c index bbcd6aa..a9c3e57 100644 --- a/drivers/usb/gadget/legacy/printer.c +++ b/drivers/usb/gadget/legacy/printer.c @@ -83,7 +83,6 @@ struct printer_dev { u8 printer_status; u8 reset_printer; struct cdev printer_cdev; - struct device *pdev; u8 printer_cdev_open; wait_queue_head_t wait; struct usb_function function; @@ -1175,6 +1174,7 @@ static int __init printer_bind_config(struct usb_configuration *c) { struct usb_gadget *gadget = c->cdev->gadget; struct printer_dev *dev; + struct device *pdev; int status = -ENOMEM; size_t len; u32 i; @@ -1199,11 +1199,11 @@ static int __init printer_bind_config(struct usb_configuration *c) return status; /* Setup the sysfs files for the printer gadget. */ - dev->pdev = device_create(usb_gadget_class, NULL, g_printer_devno, + pdev = device_create(usb_gadget_class, NULL, g_printer_devno, NULL, "g_printer"); - if (IS_ERR(dev->pdev)) { + if (IS_ERR(pdev)) { ERROR(dev, "Failed to create device: g_printer\n"); - status = PTR_ERR(dev->pdev); + status = PTR_ERR(pdev); goto fail; } -- cgit v0.10.2 From 406be2ccbadb5652f5894078d0e025d90683b3e9 Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Tue, 3 Mar 2015 10:52:11 +0100 Subject: usb: gadget: printer: follow the naming convention for usb_add_config callback Legacy gadgets, before converting them to the new function framework, used to use the name _do_config() for usb_add_config()'s callback. This patch changes the name so that it is easier to follow the convention. Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c index a9c3e57..c865833 100644 --- a/drivers/usb/gadget/legacy/printer.c +++ b/drivers/usb/gadget/legacy/printer.c @@ -1170,7 +1170,7 @@ static struct usb_configuration printer_cfg_driver = { .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER, }; -static int __init printer_bind_config(struct usb_configuration *c) +static int __init printer_do_config(struct usb_configuration *c) { struct usb_gadget *gadget = c->cdev->gadget; struct printer_dev *dev; @@ -1287,7 +1287,7 @@ static int __init printer_bind(struct usb_composite_dev *cdev) device_desc.iProduct = strings[USB_GADGET_PRODUCT_IDX].id; device_desc.iSerialNumber = strings[USB_GADGET_SERIAL_IDX].id; - ret = usb_add_config(cdev, &printer_cfg_driver, printer_bind_config); + ret = usb_add_config(cdev, &printer_cfg_driver, printer_do_config); if (ret) return ret; usb_composite_overwrite_options(cdev, &coverwrite); -- cgit v0.10.2 From ae2dd0de57a3f6b12e30e5552033a492d6d206f7 Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Tue, 3 Mar 2015 10:52:12 +0100 Subject: usb: gadget: printer: standardize printer_do_config Follow the convention of distributing source code between _do_config() and _bind_config(). Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c index c865833..494cd8a 100644 --- a/drivers/usb/gadget/legacy/printer.c +++ b/drivers/usb/gadget/legacy/printer.c @@ -1170,7 +1170,8 @@ static struct usb_configuration printer_cfg_driver = { .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER, }; -static int __init printer_do_config(struct usb_configuration *c) +static int f_printer_bind_config(struct usb_configuration *c, char *pnp_str, + unsigned q_len) { struct usb_gadget *gadget = c->cdev->gadget; struct printer_dev *dev; @@ -1180,8 +1181,6 @@ static int __init printer_do_config(struct usb_configuration *c) u32 i; struct usb_request *req; - usb_ep_autoconfig_reset(gadget); - dev = &usb_printer_gadget; dev->function.name = shortname; @@ -1219,21 +1218,13 @@ static int __init printer_do_config(struct usb_configuration *c) goto fail; } - if (iPNPstring) - strlcpy(&pnp_string[2], iPNPstring, (sizeof pnp_string)-2); + if (pnp_str) + strlcpy(&pnp_string[2], pnp_str, sizeof(pnp_string) - 2); len = strlen(pnp_string); pnp_string[0] = (len >> 8) & 0xFF; pnp_string[1] = len & 0xFF; - usb_gadget_set_selfpowered(gadget); - - if (gadget_is_otg(gadget)) { - otg_descriptor.bmAttributes |= USB_OTG_HNP; - printer_cfg_driver.descriptors = otg_desc; - printer_cfg_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; - } - spin_lock_init(&dev->lock); mutex_init(&dev->lock_printer_io); INIT_LIST_HEAD(&dev->tx_reqs_active); @@ -1250,14 +1241,14 @@ static int __init printer_do_config(struct usb_configuration *c) dev->current_rx_buf = NULL; status = -ENOMEM; - for (i = 0; i < QLEN; i++) { + for (i = 0; i < q_len; i++) { req = printer_req_alloc(dev->in_ep, USB_BUFSIZE, GFP_KERNEL); if (!req) goto fail; list_add(&req->list, &dev->tx_reqs); } - for (i = 0; i < QLEN; i++) { + for (i = 0; i < q_len; i++) { req = printer_req_alloc(dev->out_ep, USB_BUFSIZE, GFP_KERNEL); if (!req) goto fail; @@ -1276,6 +1267,24 @@ fail: return status; } +static int __init printer_do_config(struct usb_configuration *c) +{ + struct usb_gadget *gadget = c->cdev->gadget; + + usb_ep_autoconfig_reset(gadget); + + usb_gadget_set_selfpowered(gadget); + + if (gadget_is_otg(gadget)) { + otg_descriptor.bmAttributes |= USB_OTG_HNP; + printer_cfg_driver.descriptors = otg_desc; + printer_cfg_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; + } + + return f_printer_bind_config(c, iPNPstring, QLEN); + +} + static int __init printer_bind(struct usb_composite_dev *cdev) { int ret; -- cgit v0.10.2 From 4504b5a0b22e26a7213d9e08706303a790f5a400 Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Tue, 3 Mar 2015 10:52:13 +0100 Subject: usb: gadget: printer: move function-related bind code to function's bind In order to factor out a reusable f_printer.c, the code related to the function should be placed in functions related to the function. Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c index 494cd8a..c857044 100644 --- a/drivers/usb/gadget/legacy/printer.c +++ b/drivers/usb/gadget/legacy/printer.c @@ -85,6 +85,7 @@ struct printer_dev { struct cdev printer_cdev; u8 printer_cdev_open; wait_queue_head_t wait; + unsigned q_len; struct usb_function function; }; @@ -1045,18 +1046,25 @@ unknown: static int __init printer_func_bind(struct usb_configuration *c, struct usb_function *f) { + struct usb_gadget *gadget = c->cdev->gadget; struct printer_dev *dev = container_of(f, struct printer_dev, function); + struct device *pdev; struct usb_composite_dev *cdev = c->cdev; struct usb_ep *in_ep; struct usb_ep *out_ep = NULL; + struct usb_request *req; int id; int ret; + u32 i; id = usb_interface_id(c, f); if (id < 0) return id; intf_desc.bInterfaceNumber = id; + /* finish hookup to lower layer ... */ + dev->gadget = gadget; + /* all we really need is bulk IN/OUT */ in_ep = usb_ep_autoconfig(cdev->gadget, &fs_ep_in_desc); if (!in_ep) { @@ -1085,7 +1093,64 @@ autoconf_fail: dev->in_ep = in_ep; dev->out_ep = out_ep; + + ret = -ENOMEM; + for (i = 0; i < dev->q_len; i++) { + req = printer_req_alloc(dev->in_ep, USB_BUFSIZE, GFP_KERNEL); + if (!req) + goto fail_tx_reqs; + list_add(&req->list, &dev->tx_reqs); + } + + for (i = 0; i < dev->q_len; i++) { + req = printer_req_alloc(dev->out_ep, USB_BUFSIZE, GFP_KERNEL); + if (!req) + goto fail_rx_reqs; + list_add(&req->list, &dev->rx_reqs); + } + + /* Setup the sysfs files for the printer gadget. */ + pdev = device_create(usb_gadget_class, NULL, g_printer_devno, + NULL, "g_printer"); + if (IS_ERR(pdev)) { + ERROR(dev, "Failed to create device: g_printer\n"); + ret = PTR_ERR(pdev); + goto fail_rx_reqs; + } + + /* + * Register a character device as an interface to a user mode + * program that handles the printer specific functionality. + */ + cdev_init(&dev->printer_cdev, &printer_io_operations); + dev->printer_cdev.owner = THIS_MODULE; + ret = cdev_add(&dev->printer_cdev, g_printer_devno, 1); + if (ret) { + ERROR(dev, "Failed to open char device\n"); + goto fail_cdev_add; + } + return 0; + +fail_cdev_add: + device_destroy(usb_gadget_class, g_printer_devno); + +fail_rx_reqs: + while (!list_empty(&dev->rx_reqs)) { + req = container_of(dev->rx_reqs.next, struct usb_request, list); + list_del(&req->list); + printer_req_free(dev->out_ep, req); + } + +fail_tx_reqs: + while (!list_empty(&dev->tx_reqs)) { + req = container_of(dev->tx_reqs.next, struct usb_request, list); + list_del(&req->list); + printer_req_free(dev->in_ep, req); + } + + return ret; + } static void printer_func_unbind(struct usb_configuration *c, @@ -1173,13 +1238,9 @@ static struct usb_configuration printer_cfg_driver = { static int f_printer_bind_config(struct usb_configuration *c, char *pnp_str, unsigned q_len) { - struct usb_gadget *gadget = c->cdev->gadget; struct printer_dev *dev; - struct device *pdev; int status = -ENOMEM; size_t len; - u32 i; - struct usb_request *req; dev = &usb_printer_gadget; @@ -1193,31 +1254,11 @@ static int f_printer_bind_config(struct usb_configuration *c, char *pnp_str, INIT_LIST_HEAD(&dev->rx_reqs); INIT_LIST_HEAD(&dev->rx_buffers); + dev->q_len = q_len; status = usb_add_function(c, &dev->function); if (status) return status; - /* Setup the sysfs files for the printer gadget. */ - pdev = device_create(usb_gadget_class, NULL, g_printer_devno, - NULL, "g_printer"); - if (IS_ERR(pdev)) { - ERROR(dev, "Failed to create device: g_printer\n"); - status = PTR_ERR(pdev); - goto fail; - } - - /* - * Register a character device as an interface to a user mode - * program that handles the printer specific functionality. - */ - cdev_init(&dev->printer_cdev, &printer_io_operations); - dev->printer_cdev.owner = THIS_MODULE; - status = cdev_add(&dev->printer_cdev, g_printer_devno, 1); - if (status) { - ERROR(dev, "Failed to open char device\n"); - goto fail; - } - if (pnp_str) strlcpy(&pnp_string[2], pnp_str, sizeof(pnp_string) - 2); @@ -1240,31 +1281,8 @@ static int f_printer_bind_config(struct usb_configuration *c, char *pnp_str, dev->current_rx_bytes = 0; dev->current_rx_buf = NULL; - status = -ENOMEM; - for (i = 0; i < q_len; i++) { - req = printer_req_alloc(dev->in_ep, USB_BUFSIZE, GFP_KERNEL); - if (!req) - goto fail; - list_add(&req->list, &dev->tx_reqs); - } - - for (i = 0; i < q_len; i++) { - req = printer_req_alloc(dev->out_ep, USB_BUFSIZE, GFP_KERNEL); - if (!req) - goto fail; - list_add(&req->list, &dev->rx_reqs); - } - - /* finish hookup to lower layer ... */ - dev->gadget = gadget; - INFO(dev, "%s, version: " DRIVER_VERSION "\n", driver_desc); return 0; - -fail: - printer_cfg_unbind(c); - usb_remove_function(c, &dev->function); - return status; } static int __init printer_do_config(struct usb_configuration *c) -- cgit v0.10.2 From cee5cbff8d80ec2d10fe8070f229e95cc42443bf Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Tue, 3 Mar 2015 10:52:14 +0100 Subject: usb: gadget: printer: call usb_add_function() last Conversion to the new function interface requires splitting a _bind_config() function into two parts: allocation of container_of struct usb_function and invocation of usb_add_function(). This patch moves the latter to the end of the f_printer_bind_config() in order to enable conversion to the new interface. Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c index c857044..5dbb93a 100644 --- a/drivers/usb/gadget/legacy/printer.c +++ b/drivers/usb/gadget/legacy/printer.c @@ -1254,11 +1254,6 @@ static int f_printer_bind_config(struct usb_configuration *c, char *pnp_str, INIT_LIST_HEAD(&dev->rx_reqs); INIT_LIST_HEAD(&dev->rx_buffers); - dev->q_len = q_len; - status = usb_add_function(c, &dev->function); - if (status) - return status; - if (pnp_str) strlcpy(&pnp_string[2], pnp_str, sizeof(pnp_string) - 2); @@ -1280,7 +1275,11 @@ static int f_printer_bind_config(struct usb_configuration *c, char *pnp_str, dev->current_rx_req = NULL; dev->current_rx_bytes = 0; dev->current_rx_buf = NULL; + dev->q_len = q_len; + status = usb_add_function(c, &dev->function); + if (status) + return status; INFO(dev, "%s, version: " DRIVER_VERSION "\n", driver_desc); return 0; } -- cgit v0.10.2 From 991cd26249e775c07347ab4d62adfbc3284e7704 Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Tue, 3 Mar 2015 10:52:15 +0100 Subject: usb: gadget: printer: move function-related unbind code to function's unbind In order to factor out a reusable f_printer.c, the code related to the function should be placed in functions related to the function. printer_cfg_unbind() becomes empty, so it is removed. Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c index 5dbb93a..84e6cdd 100644 --- a/drivers/usb/gadget/legacy/printer.c +++ b/drivers/usb/gadget/legacy/printer.c @@ -1156,43 +1156,11 @@ fail_tx_reqs: static void printer_func_unbind(struct usb_configuration *c, struct usb_function *f) { - usb_free_all_descriptors(f); -} - -static int printer_func_set_alt(struct usb_function *f, - unsigned intf, unsigned alt) -{ - struct printer_dev *dev = container_of(f, struct printer_dev, function); - int ret = -ENOTSUPP; - - if (!alt) - ret = set_interface(dev, intf); - - return ret; -} - -static void printer_func_disable(struct usb_function *f) -{ - struct printer_dev *dev = container_of(f, struct printer_dev, function); - unsigned long flags; - - DBG(dev, "%s\n", __func__); - - spin_lock_irqsave(&dev->lock, flags); - printer_reset_interface(dev); - spin_unlock_irqrestore(&dev->lock, flags); -} - -static void printer_cfg_unbind(struct usb_configuration *c) -{ struct printer_dev *dev; struct usb_request *req; dev = &usb_printer_gadget; - DBG(dev, "%s\n", __func__); - - /* Remove sysfs files */ device_destroy(usb_gadget_class, g_printer_devno); /* Remove Character Device */ @@ -1226,11 +1194,35 @@ static void printer_cfg_unbind(struct usb_configuration *c) list_del(&req->list); printer_req_free(dev->out_ep, req); } + usb_free_all_descriptors(f); +} + +static int printer_func_set_alt(struct usb_function *f, + unsigned intf, unsigned alt) +{ + struct printer_dev *dev = container_of(f, struct printer_dev, function); + int ret = -ENOTSUPP; + + if (!alt) + ret = set_interface(dev, intf); + + return ret; +} + +static void printer_func_disable(struct usb_function *f) +{ + struct printer_dev *dev = container_of(f, struct printer_dev, function); + unsigned long flags; + + DBG(dev, "%s\n", __func__); + + spin_lock_irqsave(&dev->lock, flags); + printer_reset_interface(dev); + spin_unlock_irqrestore(&dev->lock, flags); } static struct usb_configuration printer_cfg_driver = { .label = "printer", - .unbind = printer_cfg_unbind, .bConfigurationValue = 1, .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER, }; -- cgit v0.10.2 From 085617a1eb865c2987c05652bf82d35f500ac4b4 Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Tue, 3 Mar 2015 10:52:16 +0100 Subject: usb: gadget: printer: define pnp string buffer length Avoid using magic numbers. Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c index 84e6cdd..db5e2f0 100644 --- a/drivers/usb/gadget/legacy/printer.c +++ b/drivers/usb/gadget/legacy/printer.c @@ -276,9 +276,11 @@ static inline struct usb_endpoint_descriptor *ep_desc(struct usb_gadget *gadget, /* descriptors that are built on-demand */ +#define PNP_STRING_LEN 1024 + static char product_desc [40] = DRIVER_DESC; static char serial_num [40] = "1"; -static char pnp_string [1024] = +static char pnp_string[PNP_STRING_LEN] = "XXMFG:linux;MDL:g_printer;CLS:PRINTER;SN:1;"; /* static strings, in UTF-8 */ @@ -1247,7 +1249,7 @@ static int f_printer_bind_config(struct usb_configuration *c, char *pnp_str, INIT_LIST_HEAD(&dev->rx_buffers); if (pnp_str) - strlcpy(&pnp_string[2], pnp_str, sizeof(pnp_string) - 2); + strlcpy(&pnp_string[2], pnp_str, PNP_STRING_LEN - 2); len = strlen(pnp_string); pnp_string[0] = (len >> 8) & 0xFF; -- cgit v0.10.2 From 5a84e6f608598dd691c0024eab50fffb96aca43b Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Tue, 3 Mar 2015 10:52:17 +0100 Subject: usb: gadget: printer: don't access file global pnp_string in function's code In order to factor out a reusable f_printer, the function's code should not use file global variables related to legacy printer gadget's implementation. Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c index db5e2f0..42c46da 100644 --- a/drivers/usb/gadget/legacy/printer.c +++ b/drivers/usb/gadget/legacy/printer.c @@ -86,6 +86,7 @@ struct printer_dev { u8 printer_cdev_open; wait_queue_head_t wait; unsigned q_len; + char *pnp_string; /* We don't own memory! */ struct usb_function function; }; @@ -994,10 +995,10 @@ static int printer_func_setup(struct usb_function *f, if ((wIndex>>8) != dev->interface) break; - value = (pnp_string[0]<<8)|pnp_string[1]; - memcpy(req->buf, pnp_string, value); + value = (dev->pnp_string[0] << 8) | dev->pnp_string[1]; + memcpy(req->buf, dev->pnp_string, value); DBG(dev, "1284 PNP String: %x %s\n", value, - &pnp_string[2]); + &dev->pnp_string[2]); break; case 1: /* Get Port Status */ @@ -1230,13 +1231,14 @@ static struct usb_configuration printer_cfg_driver = { }; static int f_printer_bind_config(struct usb_configuration *c, char *pnp_str, - unsigned q_len) + char *pnp_string, unsigned q_len) { struct printer_dev *dev; int status = -ENOMEM; size_t len; dev = &usb_printer_gadget; + dev->pnp_string = pnp_string; dev->function.name = shortname; dev->function.bind = printer_func_bind; @@ -1249,7 +1251,7 @@ static int f_printer_bind_config(struct usb_configuration *c, char *pnp_str, INIT_LIST_HEAD(&dev->rx_buffers); if (pnp_str) - strlcpy(&pnp_string[2], pnp_str, PNP_STRING_LEN - 2); + strlcpy(&dev->pnp_string[2], pnp_str, PNP_STRING_LEN - 2); len = strlen(pnp_string); pnp_string[0] = (len >> 8) & 0xFF; @@ -1292,7 +1294,7 @@ static int __init printer_do_config(struct usb_configuration *c) printer_cfg_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; } - return f_printer_bind_config(c, iPNPstring, QLEN); + return f_printer_bind_config(c, iPNPstring, pnp_string, QLEN); } -- cgit v0.10.2 From d82cd82edb98d727c6a0804a6e271e3081559404 Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Tue, 3 Mar 2015 10:52:18 +0100 Subject: usb: gadget: printer: add setup and cleanup functions Factor out gprinter_setup() and gprinter_cleanup() so that it is easy to change the place they are called from. Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c index 42c46da..83cea9a5c 100644 --- a/drivers/usb/gadget/legacy/printer.c +++ b/drivers/usb/gadget/legacy/printer.c @@ -1298,6 +1298,34 @@ static int __init printer_do_config(struct usb_configuration *c) } +static int gprinter_setup(void) +{ + int status; + + usb_gadget_class = class_create(THIS_MODULE, "usb_printer_gadget"); + if (IS_ERR(usb_gadget_class)) { + status = PTR_ERR(usb_gadget_class); + pr_err("unable to create usb_gadget class %d\n", status); + return status; + } + + status = alloc_chrdev_region(&g_printer_devno, 0, 1, + "USB printer gadget"); + if (status) { + pr_err("alloc_chrdev_region %d\n", status); + class_destroy(usb_gadget_class); + } + + return status; +} + +/* must be called with struct printer_dev's lock_printer_io held */ +static void gprinter_cleanup(void) +{ + unregister_chrdev_region(g_printer_devno, 1); + class_destroy(usb_gadget_class); +} + static int __init printer_bind(struct usb_composite_dev *cdev) { int ret; @@ -1329,20 +1357,9 @@ init(void) { int status; - usb_gadget_class = class_create(THIS_MODULE, "usb_printer_gadget"); - if (IS_ERR(usb_gadget_class)) { - status = PTR_ERR(usb_gadget_class); - pr_err("unable to create usb_gadget class %d\n", status); - return status; - } - - status = alloc_chrdev_region(&g_printer_devno, 0, 1, - "USB printer gadget"); - if (status) { - pr_err("alloc_chrdev_region %d\n", status); - class_destroy(usb_gadget_class); + status = gprinter_setup(); + if (status) return status; - } status = usb_composite_probe(&printer_driver); if (status) { @@ -1360,8 +1377,7 @@ cleanup(void) { mutex_lock(&usb_printer_gadget.lock_printer_io); usb_composite_unregister(&printer_driver); - unregister_chrdev_region(g_printer_devno, 1); - class_destroy(usb_gadget_class); + gprinter_cleanup(); mutex_unlock(&usb_printer_gadget.lock_printer_io); } module_exit(cleanup); -- cgit v0.10.2 From a844715d2fc44adc2da17f90b34cc0d0c1e81596 Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Tue, 3 Mar 2015 10:52:19 +0100 Subject: usb: gadget: printer: call gprinter_setup() from gadget's bind Call gprinter_setup() from gadget's bind instead of module's init. Call gprinter_cleaup() corerspondingly. This detaches printer function's logic from legacy printer gadget's implementation. Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c index 83cea9a5c..b7889b1 100644 --- a/drivers/usb/gadget/legacy/printer.c +++ b/drivers/usb/gadget/legacy/printer.c @@ -1330,45 +1330,47 @@ static int __init printer_bind(struct usb_composite_dev *cdev) { int ret; + ret = gprinter_setup(); + if (ret) + return ret; + ret = usb_string_ids_tab(cdev, strings); - if (ret < 0) + if (ret < 0) { + gprinter_cleanup(); return ret; + } device_desc.iManufacturer = strings[USB_GADGET_MANUFACTURER_IDX].id; device_desc.iProduct = strings[USB_GADGET_PRODUCT_IDX].id; device_desc.iSerialNumber = strings[USB_GADGET_SERIAL_IDX].id; ret = usb_add_config(cdev, &printer_cfg_driver, printer_do_config); - if (ret) + if (ret) { + gprinter_cleanup(); return ret; + } usb_composite_overwrite_options(cdev, &coverwrite); return ret; } +static int __exit printer_unbind(struct usb_composite_dev *cdev) +{ + gprinter_cleanup(); + return 0; +} + static __refdata struct usb_composite_driver printer_driver = { .name = shortname, .dev = &device_desc, .strings = dev_strings, .max_speed = USB_SPEED_SUPER, .bind = printer_bind, + .unbind = printer_unbind, }; static int __init init(void) { - int status; - - status = gprinter_setup(); - if (status) - return status; - - status = usb_composite_probe(&printer_driver); - if (status) { - class_destroy(usb_gadget_class); - unregister_chrdev_region(g_printer_devno, 1); - pr_err("usb_gadget_probe_driver %x\n", status); - } - - return status; + return usb_composite_probe(&printer_driver); } module_init(init); @@ -1377,7 +1379,6 @@ cleanup(void) { mutex_lock(&usb_printer_gadget.lock_printer_io); usb_composite_unregister(&printer_driver); - gprinter_cleanup(); mutex_unlock(&usb_printer_gadget.lock_printer_io); } module_exit(cleanup); -- cgit v0.10.2 From dec81cf1dcaac5b91de7cd32c96aadcb94840c7f Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Tue, 3 Mar 2015 10:52:20 +0100 Subject: usb: gadget: printer: eliminate file global printer_mutex The mutex is a legacy after semi-automatic Big Kernel Lock removal. printer_open() does its own locking, so no need to duplicate it. Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c index b7889b1..3206ebc 100644 --- a/drivers/usb/gadget/legacy/printer.c +++ b/drivers/usb/gadget/legacy/printer.c @@ -48,7 +48,6 @@ USB_GADGET_COMPOSITE_OPTIONS(); #define DRIVER_DESC "Printer Gadget" #define DRIVER_VERSION "2007 OCT 06" -static DEFINE_MUTEX(printer_mutex); static const char shortname [] = "printer"; static const char driver_desc [] = DRIVER_DESC; @@ -420,7 +419,6 @@ printer_open(struct inode *inode, struct file *fd) unsigned long flags; int ret = -EBUSY; - mutex_lock(&printer_mutex); dev = container_of(inode->i_cdev, struct printer_dev, printer_cdev); spin_lock_irqsave(&dev->lock, flags); @@ -436,7 +434,6 @@ printer_open(struct inode *inode, struct file *fd) spin_unlock_irqrestore(&dev->lock, flags); DBG(dev, "printer_open returned %x\n", ret); - mutex_unlock(&printer_mutex); return ret; } -- cgit v0.10.2 From 8fe20f661f3cfbb6778368eb3c73f8a6438ac640 Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Tue, 3 Mar 2015 10:52:21 +0100 Subject: usb: gadget: printer: don't access file global usb_printer_gadget in function's code The printer_dev can be recovered from printer_func_unbind() function's parameters. Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c index 3206ebc..806475c 100644 --- a/drivers/usb/gadget/legacy/printer.c +++ b/drivers/usb/gadget/legacy/printer.c @@ -1159,7 +1159,7 @@ static void printer_func_unbind(struct usb_configuration *c, struct printer_dev *dev; struct usb_request *req; - dev = &usb_printer_gadget; + dev = container_of(f, struct printer_dev, function); device_destroy(usb_gadget_class, g_printer_devno); -- cgit v0.10.2 From 143d53e10ecfeee7245341aa9c50515b5680ffd4 Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Tue, 3 Mar 2015 10:52:22 +0100 Subject: usb: gadget: printer: add container_of helper for printer_dev 5 uses of container_of() in the same context justify wrapping it in a static inline function. Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c index 806475c..955847f 100644 --- a/drivers/usb/gadget/legacy/printer.c +++ b/drivers/usb/gadget/legacy/printer.c @@ -89,6 +89,11 @@ struct printer_dev { struct usb_function function; }; +static inline struct printer_dev *func_to_printer(struct usb_function *f) +{ + return container_of(f, struct printer_dev, function); +} + static struct printer_dev usb_printer_gadget; /*-------------------------------------------------------------------------*/ @@ -973,7 +978,7 @@ static void printer_soft_reset(struct printer_dev *dev) static int printer_func_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl) { - struct printer_dev *dev = container_of(f, struct printer_dev, function); + struct printer_dev *dev = func_to_printer(f); struct usb_composite_dev *cdev = f->config->cdev; struct usb_request *req = cdev->req; int value = -EOPNOTSUPP; @@ -1047,7 +1052,7 @@ static int __init printer_func_bind(struct usb_configuration *c, struct usb_function *f) { struct usb_gadget *gadget = c->cdev->gadget; - struct printer_dev *dev = container_of(f, struct printer_dev, function); + struct printer_dev *dev = func_to_printer(f); struct device *pdev; struct usb_composite_dev *cdev = c->cdev; struct usb_ep *in_ep; @@ -1159,7 +1164,7 @@ static void printer_func_unbind(struct usb_configuration *c, struct printer_dev *dev; struct usb_request *req; - dev = container_of(f, struct printer_dev, function); + dev = func_to_printer(f); device_destroy(usb_gadget_class, g_printer_devno); @@ -1200,7 +1205,7 @@ static void printer_func_unbind(struct usb_configuration *c, static int printer_func_set_alt(struct usb_function *f, unsigned intf, unsigned alt) { - struct printer_dev *dev = container_of(f, struct printer_dev, function); + struct printer_dev *dev = func_to_printer(f); int ret = -ENOTSUPP; if (!alt) @@ -1211,7 +1216,7 @@ static int printer_func_set_alt(struct usb_function *f, static void printer_func_disable(struct usb_function *f) { - struct printer_dev *dev = container_of(f, struct printer_dev, function); + struct printer_dev *dev = func_to_printer(f); unsigned long flags; DBG(dev, "%s\n", __func__); -- cgit v0.10.2 From f563d230903210acc2336af58e422216b68ded76 Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Tue, 3 Mar 2015 10:52:23 +0100 Subject: usb: gadget: composite: add req_match method to usb_function Non-standard requests can encode the actual interface number in a non-standard way. For example composite_setup() assumes that it is w_index && 0xFF, but the printer function encodes the interface number in a context-dependet way (either w_index or w_index >> 8). This can lead to such requests being directed to wrong functions. This patch adds req_match() method to usb_function. Its purpose is to verify that a given request can be handled by a given function. If any function within a configuration provides the method and it returns true, then it is assumed that the right function is found. If a function uses req_match(), it should try as hard as possible to determine if the request is meant for it. If no functions in a configuration provide req_match or none of them returns true, then fall back to the usual approach. Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 9fb9231..4d25e11 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -1758,6 +1758,10 @@ unknown: * take such requests too, if that's ever needed: to work * in config 0, etc. */ + list_for_each_entry(f, &cdev->config->functions, list) + if (f->req_match && f->req_match(f, ctrl)) + goto try_fun_setup; + f = NULL; switch (ctrl->bRequestType & USB_RECIP_MASK) { case USB_RECIP_INTERFACE: if (!cdev->config || intf >= MAX_CONFIG_INTERFACES) @@ -1775,7 +1779,7 @@ unknown: f = NULL; break; } - +try_fun_setup: if (f && f->setup) value = f->setup(f, ctrl); else { diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h index 3d87def..2511469 100644 --- a/include/linux/usb/composite.h +++ b/include/linux/usb/composite.h @@ -148,6 +148,7 @@ struct usb_os_desc_table { * @disable: (REQUIRED) Indicates the function should be disabled. Reasons * include host resetting or reconfiguring the gadget, and disconnection. * @setup: Used for interface-specific control requests. + * @req_match: Tests if a given class request can be handled by this function. * @suspend: Notifies functions when the host stops sending USB traffic. * @resume: Notifies functions when the host restarts USB traffic. * @get_status: Returns function status as a reply to @@ -213,6 +214,8 @@ struct usb_function { void (*disable)(struct usb_function *); int (*setup)(struct usb_function *, const struct usb_ctrlrequest *); + bool (*req_match)(struct usb_function *, + const struct usb_ctrlrequest *); void (*suspend)(struct usb_function *); void (*resume)(struct usb_function *); -- cgit v0.10.2 From d7239f4c6daeb7a987a0e6f37a3ea24b37f7c208 Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Tue, 3 Mar 2015 10:52:24 +0100 Subject: usb: gadget: printer: name class specific requests Avoid using magic numbers. Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c index 955847f..78f5154 100644 --- a/drivers/usb/gadget/legacy/printer.c +++ b/drivers/usb/gadget/legacy/printer.c @@ -47,6 +47,9 @@ USB_GADGET_COMPOSITE_OPTIONS(); #define DRIVER_DESC "Printer Gadget" #define DRIVER_VERSION "2007 OCT 06" +#define GET_DEVICE_ID 0 +#define GET_PORT_STATUS 1 +#define SOFT_RESET 2 static const char shortname [] = "printer"; static const char driver_desc [] = DRIVER_DESC; @@ -992,7 +995,7 @@ static int printer_func_setup(struct usb_function *f, switch (ctrl->bRequestType&USB_TYPE_MASK) { case USB_TYPE_CLASS: switch (ctrl->bRequest) { - case 0: /* Get the IEEE-1284 PNP String */ + case GET_DEVICE_ID: /* Get the IEEE-1284 PNP String */ /* Only one printer interface is supported. */ if ((wIndex>>8) != dev->interface) break; @@ -1003,7 +1006,7 @@ static int printer_func_setup(struct usb_function *f, &dev->pnp_string[2]); break; - case 1: /* Get Port Status */ + case GET_PORT_STATUS: /* Get Port Status */ /* Only one printer interface is supported. */ if (wIndex != dev->interface) break; @@ -1012,7 +1015,7 @@ static int printer_func_setup(struct usb_function *f, value = min(wLength, (u16) 1); break; - case 2: /* Soft Reset */ + case SOFT_RESET: /* Soft Reset */ /* Only one printer interface is supported. */ if (wIndex != dev->interface) break; -- cgit v0.10.2 From 636bc0ed271d996e18365345e9c00fc712edc610 Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Tue, 3 Mar 2015 10:52:25 +0100 Subject: usb: gadget: printer: add req_match for printer function Verify that a given usb_ctrlrequest is meant for printer function. The following parts of the request are tested: - bmRequestType:Data transfer direction - bmRequestType:Type - bmRequestType:Recipient - bRequest - wValue for bRequest 1 and 2 - wLength Additionally, the request is considered meant for this function iff the decoded interface number matches dev->interface. Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c index 78f5154..c059af1 100644 --- a/drivers/usb/gadget/legacy/printer.c +++ b/drivers/usb/gadget/legacy/printer.c @@ -974,6 +974,41 @@ static void printer_soft_reset(struct printer_dev *dev) /*-------------------------------------------------------------------------*/ +static bool gprinter_req_match(struct usb_function *f, + const struct usb_ctrlrequest *ctrl) +{ + struct printer_dev *dev = func_to_printer(f); + u16 w_index = le16_to_cpu(ctrl->wIndex); + u16 w_value = le16_to_cpu(ctrl->wValue); + u16 w_length = le16_to_cpu(ctrl->wLength); + + if ((ctrl->bRequestType & USB_RECIP_MASK) != USB_RECIP_INTERFACE || + (ctrl->bRequestType & USB_TYPE_MASK) != USB_TYPE_CLASS) + return false; + + switch (ctrl->bRequest) { + case GET_DEVICE_ID: + w_index >>= 8; + if (w_length <= PNP_STRING_LEN && + (USB_DIR_IN & ctrl->bRequestType)) + break; + return false; + case GET_PORT_STATUS: + if (!w_value && w_length == 1 && + (USB_DIR_IN & ctrl->bRequestType)) + break; + return false; + case SOFT_RESET: + if (!w_value && !w_length && + (USB_DIR_OUT & ctrl->bRequestType)) + break; + /* fall through */ + default: + return false; + } + return w_index == dev->interface; +} + /* * The setup() callback implements all the ep0 functionality that's not * handled lower down. @@ -1251,6 +1286,7 @@ static int f_printer_bind_config(struct usb_configuration *c, char *pnp_str, dev->function.unbind = printer_func_unbind; dev->function.set_alt = printer_func_set_alt; dev->function.disable = printer_func_disable; + dev->function.req_match = gprinter_req_match; INIT_LIST_HEAD(&dev->tx_reqs); INIT_LIST_HEAD(&dev->rx_reqs); INIT_LIST_HEAD(&dev->rx_buffers); -- cgit v0.10.2 From 6dd8c2e69521ec9d7b23a741294702f844353f1a Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Tue, 3 Mar 2015 10:52:26 +0100 Subject: usb: gadget: printer: allocate printer_dev instances dynamically With all the obstacles removed it is possible to allow more than one instance of the printer function. Since the function requires allocating character device region, a maximum number of allowed instances is defined. Such an approach is used in f_acm and in f_hid. With multiple instances it does not make sense to depend on a lock_printer_io member of a dynamically allocated (and destroyed) struct printer_dev to clean up after all instances of the printer function. Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c index c059af1..d1f85f8 100644 --- a/drivers/usb/gadget/legacy/printer.c +++ b/drivers/usb/gadget/legacy/printer.c @@ -51,11 +51,12 @@ USB_GADGET_COMPOSITE_OPTIONS(); #define GET_PORT_STATUS 1 #define SOFT_RESET 2 +#define PRINTER_MINORS 4 + static const char shortname [] = "printer"; static const char driver_desc [] = DRIVER_DESC; -static dev_t g_printer_devno; - +static int major, minors; static struct class *usb_gadget_class; /*-------------------------------------------------------------------------*/ @@ -84,6 +85,7 @@ struct printer_dev { u8 *current_rx_buf; u8 printer_status; u8 reset_printer; + int minor; struct cdev printer_cdev; u8 printer_cdev_open; wait_queue_head_t wait; @@ -97,8 +99,6 @@ static inline struct printer_dev *func_to_printer(struct usb_function *f) return container_of(f, struct printer_dev, function); } -static struct printer_dev usb_printer_gadget; - /*-------------------------------------------------------------------------*/ /* DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!! @@ -1096,6 +1096,7 @@ static int __init printer_func_bind(struct usb_configuration *c, struct usb_ep *in_ep; struct usb_ep *out_ep = NULL; struct usb_request *req; + dev_t devt; int id; int ret; u32 i; @@ -1153,8 +1154,9 @@ autoconf_fail: } /* Setup the sysfs files for the printer gadget. */ - pdev = device_create(usb_gadget_class, NULL, g_printer_devno, - NULL, "g_printer"); + devt = MKDEV(major, dev->minor); + pdev = device_create(usb_gadget_class, NULL, devt, + NULL, "g_printer%d", dev->minor); if (IS_ERR(pdev)) { ERROR(dev, "Failed to create device: g_printer\n"); ret = PTR_ERR(pdev); @@ -1167,7 +1169,7 @@ autoconf_fail: */ cdev_init(&dev->printer_cdev, &printer_io_operations); dev->printer_cdev.owner = THIS_MODULE; - ret = cdev_add(&dev->printer_cdev, g_printer_devno, 1); + ret = cdev_add(&dev->printer_cdev, devt, 1); if (ret) { ERROR(dev, "Failed to open char device\n"); goto fail_cdev_add; @@ -1176,7 +1178,7 @@ autoconf_fail: return 0; fail_cdev_add: - device_destroy(usb_gadget_class, g_printer_devno); + device_destroy(usb_gadget_class, devt); fail_rx_reqs: while (!list_empty(&dev->rx_reqs)) { @@ -1204,7 +1206,7 @@ static void printer_func_unbind(struct usb_configuration *c, dev = func_to_printer(f); - device_destroy(usb_gadget_class, g_printer_devno); + device_destroy(usb_gadget_class, MKDEV(major, dev->minor)); /* Remove Character Device */ cdev_del(&dev->printer_cdev); @@ -1238,6 +1240,7 @@ static void printer_func_unbind(struct usb_configuration *c, printer_req_free(dev->out_ep, req); } usb_free_all_descriptors(f); + kfree(dev); } static int printer_func_set_alt(struct usb_function *f, @@ -1271,14 +1274,21 @@ static struct usb_configuration printer_cfg_driver = { }; static int f_printer_bind_config(struct usb_configuration *c, char *pnp_str, - char *pnp_string, unsigned q_len) + char *pnp_string, unsigned q_len, int minor) { struct printer_dev *dev; int status = -ENOMEM; size_t len; - dev = &usb_printer_gadget; + if (minor >= minors) + return -ENOENT; + + dev = kzalloc(sizeof(*dev), GFP_KERNEL); + if (!dev) + return -ENOMEM; + dev->pnp_string = pnp_string; + dev->minor = minor; dev->function.name = shortname; dev->function.bind = printer_func_bind; @@ -1315,8 +1325,10 @@ static int f_printer_bind_config(struct usb_configuration *c, char *pnp_str, dev->q_len = q_len; status = usb_add_function(c, &dev->function); - if (status) + if (status) { + kfree(dev); return status; + } INFO(dev, "%s, version: " DRIVER_VERSION "\n", driver_desc); return 0; } @@ -1335,43 +1347,51 @@ static int __init printer_do_config(struct usb_configuration *c) printer_cfg_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; } - return f_printer_bind_config(c, iPNPstring, pnp_string, QLEN); - + return f_printer_bind_config(c, iPNPstring, pnp_string, QLEN, 0); } -static int gprinter_setup(void) +static int gprinter_setup(int count) { int status; + dev_t devt; usb_gadget_class = class_create(THIS_MODULE, "usb_printer_gadget"); if (IS_ERR(usb_gadget_class)) { status = PTR_ERR(usb_gadget_class); + usb_gadget_class = NULL; pr_err("unable to create usb_gadget class %d\n", status); return status; } - status = alloc_chrdev_region(&g_printer_devno, 0, 1, - "USB printer gadget"); + status = alloc_chrdev_region(&devt, 0, count, "USB printer gadget"); if (status) { pr_err("alloc_chrdev_region %d\n", status); class_destroy(usb_gadget_class); + usb_gadget_class = NULL; + return status; } + major = MAJOR(devt); + minors = count; + return status; } -/* must be called with struct printer_dev's lock_printer_io held */ static void gprinter_cleanup(void) { - unregister_chrdev_region(g_printer_devno, 1); + if (major) { + unregister_chrdev_region(MKDEV(major, 0), minors); + major = minors = 0; + } class_destroy(usb_gadget_class); + usb_gadget_class = NULL; } static int __init printer_bind(struct usb_composite_dev *cdev) { int ret; - ret = gprinter_setup(); + ret = gprinter_setup(PRINTER_MINORS); if (ret) return ret; @@ -1418,9 +1438,7 @@ module_init(init); static void __exit cleanup(void) { - mutex_lock(&usb_printer_gadget.lock_printer_io); usb_composite_unregister(&printer_driver); - mutex_unlock(&usb_printer_gadget.lock_printer_io); } module_exit(cleanup); -- cgit v0.10.2 From b185f01a9ab7af586133be2555298e960237359b Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Tue, 3 Mar 2015 10:52:27 +0100 Subject: usb: gadget: printer: factor out f_printer The legacy printer gadget now contains both a reusable printer function and legacy gadget proper implementations interwoven, but logically separate. This patch factors out a reusable f_printer. Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/function/f_printer.c b/drivers/usb/gadget/function/f_printer.c new file mode 100644 index 0000000..0847972 --- /dev/null +++ b/drivers/usb/gadget/function/f_printer.c @@ -0,0 +1,1279 @@ +/* + * f_printer.c - USB printer function driver + * + * Copied from drivers/usb/gadget/legacy/printer.c, + * which was: + * + * printer.c -- Printer gadget driver + * + * Copyright (C) 2003-2005 David Brownell + * Copyright (C) 2006 Craig W. Nadler + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#define PNP_STRING_LEN 1024 +#define PRINTER_MINORS 4 +#define GET_DEVICE_ID 0 +#define GET_PORT_STATUS 1 +#define SOFT_RESET 2 + +static int major, minors; +static struct class *usb_gadget_class; + +/*-------------------------------------------------------------------------*/ + +struct printer_dev { + spinlock_t lock; /* lock this structure */ + /* lock buffer lists during read/write calls */ + struct mutex lock_printer_io; + struct usb_gadget *gadget; + s8 interface; + struct usb_ep *in_ep, *out_ep; + + struct list_head rx_reqs; /* List of free RX structs */ + struct list_head rx_reqs_active; /* List of Active RX xfers */ + struct list_head rx_buffers; /* List of completed xfers */ + /* wait until there is data to be read. */ + wait_queue_head_t rx_wait; + struct list_head tx_reqs; /* List of free TX structs */ + struct list_head tx_reqs_active; /* List of Active TX xfers */ + /* Wait until there are write buffers available to use. */ + wait_queue_head_t tx_wait; + /* Wait until all write buffers have been sent. */ + wait_queue_head_t tx_flush_wait; + struct usb_request *current_rx_req; + size_t current_rx_bytes; + u8 *current_rx_buf; + u8 printer_status; + u8 reset_printer; + int minor; + struct cdev printer_cdev; + u8 printer_cdev_open; + wait_queue_head_t wait; + unsigned q_len; + char *pnp_string; /* We don't own memory! */ + struct usb_function function; +}; + +static inline struct printer_dev *func_to_printer(struct usb_function *f) +{ + return container_of(f, struct printer_dev, function); +} + +/*-------------------------------------------------------------------------*/ + +/* + * DESCRIPTORS ... most are static, but strings and (full) configuration + * descriptors are built on demand. + */ + +/* holds our biggest descriptor */ +#define USB_DESC_BUFSIZE 256 +#define USB_BUFSIZE 8192 + +static struct usb_interface_descriptor intf_desc = { + .bLength = sizeof(intf_desc), + .bDescriptorType = USB_DT_INTERFACE, + .bNumEndpoints = 2, + .bInterfaceClass = USB_CLASS_PRINTER, + .bInterfaceSubClass = 1, /* Printer Sub-Class */ + .bInterfaceProtocol = 2, /* Bi-Directional */ + .iInterface = 0 +}; + +static struct usb_endpoint_descriptor fs_ep_in_desc = { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + .bEndpointAddress = USB_DIR_IN, + .bmAttributes = USB_ENDPOINT_XFER_BULK +}; + +static struct usb_endpoint_descriptor fs_ep_out_desc = { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + .bEndpointAddress = USB_DIR_OUT, + .bmAttributes = USB_ENDPOINT_XFER_BULK +}; + +static struct usb_descriptor_header *fs_printer_function[] = { + (struct usb_descriptor_header *) &intf_desc, + (struct usb_descriptor_header *) &fs_ep_in_desc, + (struct usb_descriptor_header *) &fs_ep_out_desc, + NULL +}; + +/* + * usb 2.0 devices need to expose both high speed and full speed + * descriptors, unless they only run at full speed. + */ + +static struct usb_endpoint_descriptor hs_ep_in_desc = { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + .bmAttributes = USB_ENDPOINT_XFER_BULK, + .wMaxPacketSize = cpu_to_le16(512) +}; + +static struct usb_endpoint_descriptor hs_ep_out_desc = { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + .bmAttributes = USB_ENDPOINT_XFER_BULK, + .wMaxPacketSize = cpu_to_le16(512) +}; + +static struct usb_qualifier_descriptor dev_qualifier = { + .bLength = sizeof(dev_qualifier), + .bDescriptorType = USB_DT_DEVICE_QUALIFIER, + .bcdUSB = cpu_to_le16(0x0200), + .bDeviceClass = USB_CLASS_PRINTER, + .bNumConfigurations = 1 +}; + +static struct usb_descriptor_header *hs_printer_function[] = { + (struct usb_descriptor_header *) &intf_desc, + (struct usb_descriptor_header *) &hs_ep_in_desc, + (struct usb_descriptor_header *) &hs_ep_out_desc, + NULL +}; + +/* + * Added endpoint descriptors for 3.0 devices + */ + +static struct usb_endpoint_descriptor ss_ep_in_desc = { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + .bmAttributes = USB_ENDPOINT_XFER_BULK, + .wMaxPacketSize = cpu_to_le16(1024), +}; + +static struct usb_ss_ep_comp_descriptor ss_ep_in_comp_desc = { + .bLength = sizeof(ss_ep_in_comp_desc), + .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, +}; + +static struct usb_endpoint_descriptor ss_ep_out_desc = { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + .bmAttributes = USB_ENDPOINT_XFER_BULK, + .wMaxPacketSize = cpu_to_le16(1024), +}; + +static struct usb_ss_ep_comp_descriptor ss_ep_out_comp_desc = { + .bLength = sizeof(ss_ep_out_comp_desc), + .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, +}; + +static struct usb_descriptor_header *ss_printer_function[] = { + (struct usb_descriptor_header *) &intf_desc, + (struct usb_descriptor_header *) &ss_ep_in_desc, + (struct usb_descriptor_header *) &ss_ep_in_comp_desc, + (struct usb_descriptor_header *) &ss_ep_out_desc, + (struct usb_descriptor_header *) &ss_ep_out_comp_desc, + NULL +}; + +/* maxpacket and other transfer characteristics vary by speed. */ +static inline struct usb_endpoint_descriptor *ep_desc(struct usb_gadget *gadget, + struct usb_endpoint_descriptor *fs, + struct usb_endpoint_descriptor *hs, + struct usb_endpoint_descriptor *ss) +{ + switch (gadget->speed) { + case USB_SPEED_SUPER: + return ss; + case USB_SPEED_HIGH: + return hs; + default: + return fs; + } +} + +/*-------------------------------------------------------------------------*/ + +static struct usb_request * +printer_req_alloc(struct usb_ep *ep, unsigned len, gfp_t gfp_flags) +{ + struct usb_request *req; + + req = usb_ep_alloc_request(ep, gfp_flags); + + if (req != NULL) { + req->length = len; + req->buf = kmalloc(len, gfp_flags); + if (req->buf == NULL) { + usb_ep_free_request(ep, req); + return NULL; + } + } + + return req; +} + +static void +printer_req_free(struct usb_ep *ep, struct usb_request *req) +{ + if (ep != NULL && req != NULL) { + kfree(req->buf); + usb_ep_free_request(ep, req); + } +} + +/*-------------------------------------------------------------------------*/ + +static void rx_complete(struct usb_ep *ep, struct usb_request *req) +{ + struct printer_dev *dev = ep->driver_data; + int status = req->status; + unsigned long flags; + + spin_lock_irqsave(&dev->lock, flags); + + list_del_init(&req->list); /* Remode from Active List */ + + switch (status) { + + /* normal completion */ + case 0: + if (req->actual > 0) { + list_add_tail(&req->list, &dev->rx_buffers); + DBG(dev, "G_Printer : rx length %d\n", req->actual); + } else { + list_add(&req->list, &dev->rx_reqs); + } + break; + + /* software-driven interface shutdown */ + case -ECONNRESET: /* unlink */ + case -ESHUTDOWN: /* disconnect etc */ + VDBG(dev, "rx shutdown, code %d\n", status); + list_add(&req->list, &dev->rx_reqs); + break; + + /* for hardware automagic (such as pxa) */ + case -ECONNABORTED: /* endpoint reset */ + DBG(dev, "rx %s reset\n", ep->name); + list_add(&req->list, &dev->rx_reqs); + break; + + /* data overrun */ + case -EOVERFLOW: + /* FALLTHROUGH */ + + default: + DBG(dev, "rx status %d\n", status); + list_add(&req->list, &dev->rx_reqs); + break; + } + + wake_up_interruptible(&dev->rx_wait); + spin_unlock_irqrestore(&dev->lock, flags); +} + +static void tx_complete(struct usb_ep *ep, struct usb_request *req) +{ + struct printer_dev *dev = ep->driver_data; + + switch (req->status) { + default: + VDBG(dev, "tx err %d\n", req->status); + /* FALLTHROUGH */ + case -ECONNRESET: /* unlink */ + case -ESHUTDOWN: /* disconnect etc */ + break; + case 0: + break; + } + + spin_lock(&dev->lock); + /* Take the request struct off the active list and put it on the + * free list. + */ + list_del_init(&req->list); + list_add(&req->list, &dev->tx_reqs); + wake_up_interruptible(&dev->tx_wait); + if (likely(list_empty(&dev->tx_reqs_active))) + wake_up_interruptible(&dev->tx_flush_wait); + + spin_unlock(&dev->lock); +} + +/*-------------------------------------------------------------------------*/ + +static int +printer_open(struct inode *inode, struct file *fd) +{ + struct printer_dev *dev; + unsigned long flags; + int ret = -EBUSY; + + dev = container_of(inode->i_cdev, struct printer_dev, printer_cdev); + + spin_lock_irqsave(&dev->lock, flags); + + if (!dev->printer_cdev_open) { + dev->printer_cdev_open = 1; + fd->private_data = dev; + ret = 0; + /* Change the printer status to show that it's on-line. */ + dev->printer_status |= PRINTER_SELECTED; + } + + spin_unlock_irqrestore(&dev->lock, flags); + + DBG(dev, "printer_open returned %x\n", ret); + return ret; +} + +static int +printer_close(struct inode *inode, struct file *fd) +{ + struct printer_dev *dev = fd->private_data; + unsigned long flags; + + spin_lock_irqsave(&dev->lock, flags); + dev->printer_cdev_open = 0; + fd->private_data = NULL; + /* Change printer status to show that the printer is off-line. */ + dev->printer_status &= ~PRINTER_SELECTED; + spin_unlock_irqrestore(&dev->lock, flags); + + DBG(dev, "printer_close\n"); + + return 0; +} + +/* This function must be called with interrupts turned off. */ +static void +setup_rx_reqs(struct printer_dev *dev) +{ + struct usb_request *req; + + while (likely(!list_empty(&dev->rx_reqs))) { + int error; + + req = container_of(dev->rx_reqs.next, + struct usb_request, list); + list_del_init(&req->list); + + /* The USB Host sends us whatever amount of data it wants to + * so we always set the length field to the full USB_BUFSIZE. + * If the amount of data is more than the read() caller asked + * for it will be stored in the request buffer until it is + * asked for by read(). + */ + req->length = USB_BUFSIZE; + req->complete = rx_complete; + + /* here, we unlock, and only unlock, to avoid deadlock. */ + spin_unlock(&dev->lock); + error = usb_ep_queue(dev->out_ep, req, GFP_ATOMIC); + spin_lock(&dev->lock); + if (error) { + DBG(dev, "rx submit --> %d\n", error); + list_add(&req->list, &dev->rx_reqs); + break; + } + /* if the req is empty, then add it into dev->rx_reqs_active. */ + else if (list_empty(&req->list)) + list_add(&req->list, &dev->rx_reqs_active); + } +} + +static ssize_t +printer_read(struct file *fd, char __user *buf, size_t len, loff_t *ptr) +{ + struct printer_dev *dev = fd->private_data; + unsigned long flags; + size_t size; + size_t bytes_copied; + struct usb_request *req; + /* This is a pointer to the current USB rx request. */ + struct usb_request *current_rx_req; + /* This is the number of bytes in the current rx buffer. */ + size_t current_rx_bytes; + /* This is a pointer to the current rx buffer. */ + u8 *current_rx_buf; + + if (len == 0) + return -EINVAL; + + DBG(dev, "printer_read trying to read %d bytes\n", (int)len); + + mutex_lock(&dev->lock_printer_io); + spin_lock_irqsave(&dev->lock, flags); + + /* We will use this flag later to check if a printer reset happened + * after we turn interrupts back on. + */ + dev->reset_printer = 0; + + setup_rx_reqs(dev); + + bytes_copied = 0; + current_rx_req = dev->current_rx_req; + current_rx_bytes = dev->current_rx_bytes; + current_rx_buf = dev->current_rx_buf; + dev->current_rx_req = NULL; + dev->current_rx_bytes = 0; + dev->current_rx_buf = NULL; + + /* Check if there is any data in the read buffers. Please note that + * current_rx_bytes is the number of bytes in the current rx buffer. + * If it is zero then check if there are any other rx_buffers that + * are on the completed list. We are only out of data if all rx + * buffers are empty. + */ + if ((current_rx_bytes == 0) && + (likely(list_empty(&dev->rx_buffers)))) { + /* Turn interrupts back on before sleeping. */ + spin_unlock_irqrestore(&dev->lock, flags); + + /* + * If no data is available check if this is a NON-Blocking + * call or not. + */ + if (fd->f_flags & (O_NONBLOCK|O_NDELAY)) { + mutex_unlock(&dev->lock_printer_io); + return -EAGAIN; + } + + /* Sleep until data is available */ + wait_event_interruptible(dev->rx_wait, + (likely(!list_empty(&dev->rx_buffers)))); + spin_lock_irqsave(&dev->lock, flags); + } + + /* We have data to return then copy it to the caller's buffer.*/ + while ((current_rx_bytes || likely(!list_empty(&dev->rx_buffers))) + && len) { + if (current_rx_bytes == 0) { + req = container_of(dev->rx_buffers.next, + struct usb_request, list); + list_del_init(&req->list); + + if (req->actual && req->buf) { + current_rx_req = req; + current_rx_bytes = req->actual; + current_rx_buf = req->buf; + } else { + list_add(&req->list, &dev->rx_reqs); + continue; + } + } + + /* Don't leave irqs off while doing memory copies */ + spin_unlock_irqrestore(&dev->lock, flags); + + if (len > current_rx_bytes) + size = current_rx_bytes; + else + size = len; + + size -= copy_to_user(buf, current_rx_buf, size); + bytes_copied += size; + len -= size; + buf += size; + + spin_lock_irqsave(&dev->lock, flags); + + /* We've disconnected or reset so return. */ + if (dev->reset_printer) { + list_add(¤t_rx_req->list, &dev->rx_reqs); + spin_unlock_irqrestore(&dev->lock, flags); + mutex_unlock(&dev->lock_printer_io); + return -EAGAIN; + } + + /* If we not returning all the data left in this RX request + * buffer then adjust the amount of data left in the buffer. + * Othewise if we are done with this RX request buffer then + * requeue it to get any incoming data from the USB host. + */ + if (size < current_rx_bytes) { + current_rx_bytes -= size; + current_rx_buf += size; + } else { + list_add(¤t_rx_req->list, &dev->rx_reqs); + current_rx_bytes = 0; + current_rx_buf = NULL; + current_rx_req = NULL; + } + } + + dev->current_rx_req = current_rx_req; + dev->current_rx_bytes = current_rx_bytes; + dev->current_rx_buf = current_rx_buf; + + spin_unlock_irqrestore(&dev->lock, flags); + mutex_unlock(&dev->lock_printer_io); + + DBG(dev, "printer_read returned %d bytes\n", (int)bytes_copied); + + if (bytes_copied) + return bytes_copied; + else + return -EAGAIN; +} + +static ssize_t +printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr) +{ + struct printer_dev *dev = fd->private_data; + unsigned long flags; + size_t size; /* Amount of data in a TX request. */ + size_t bytes_copied = 0; + struct usb_request *req; + + DBG(dev, "printer_write trying to send %d bytes\n", (int)len); + + if (len == 0) + return -EINVAL; + + mutex_lock(&dev->lock_printer_io); + spin_lock_irqsave(&dev->lock, flags); + + /* Check if a printer reset happens while we have interrupts on */ + dev->reset_printer = 0; + + /* Check if there is any available write buffers */ + if (likely(list_empty(&dev->tx_reqs))) { + /* Turn interrupts back on before sleeping. */ + spin_unlock_irqrestore(&dev->lock, flags); + + /* + * If write buffers are available check if this is + * a NON-Blocking call or not. + */ + if (fd->f_flags & (O_NONBLOCK|O_NDELAY)) { + mutex_unlock(&dev->lock_printer_io); + return -EAGAIN; + } + + /* Sleep until a write buffer is available */ + wait_event_interruptible(dev->tx_wait, + (likely(!list_empty(&dev->tx_reqs)))); + spin_lock_irqsave(&dev->lock, flags); + } + + while (likely(!list_empty(&dev->tx_reqs)) && len) { + + if (len > USB_BUFSIZE) + size = USB_BUFSIZE; + else + size = len; + + req = container_of(dev->tx_reqs.next, struct usb_request, + list); + list_del_init(&req->list); + + req->complete = tx_complete; + req->length = size; + + /* Check if we need to send a zero length packet. */ + if (len > size) + /* They will be more TX requests so no yet. */ + req->zero = 0; + else + /* If the data amount is not a multiple of the + * maxpacket size then send a zero length packet. + */ + req->zero = ((len % dev->in_ep->maxpacket) == 0); + + /* Don't leave irqs off while doing memory copies */ + spin_unlock_irqrestore(&dev->lock, flags); + + if (copy_from_user(req->buf, buf, size)) { + list_add(&req->list, &dev->tx_reqs); + mutex_unlock(&dev->lock_printer_io); + return bytes_copied; + } + + bytes_copied += size; + len -= size; + buf += size; + + spin_lock_irqsave(&dev->lock, flags); + + /* We've disconnected or reset so free the req and buffer */ + if (dev->reset_printer) { + list_add(&req->list, &dev->tx_reqs); + spin_unlock_irqrestore(&dev->lock, flags); + mutex_unlock(&dev->lock_printer_io); + return -EAGAIN; + } + + if (usb_ep_queue(dev->in_ep, req, GFP_ATOMIC)) { + list_add(&req->list, &dev->tx_reqs); + spin_unlock_irqrestore(&dev->lock, flags); + mutex_unlock(&dev->lock_printer_io); + return -EAGAIN; + } + + list_add(&req->list, &dev->tx_reqs_active); + + } + + spin_unlock_irqrestore(&dev->lock, flags); + mutex_unlock(&dev->lock_printer_io); + + DBG(dev, "printer_write sent %d bytes\n", (int)bytes_copied); + + if (bytes_copied) + return bytes_copied; + else + return -EAGAIN; +} + +static int +printer_fsync(struct file *fd, loff_t start, loff_t end, int datasync) +{ + struct printer_dev *dev = fd->private_data; + struct inode *inode = file_inode(fd); + unsigned long flags; + int tx_list_empty; + + mutex_lock(&inode->i_mutex); + spin_lock_irqsave(&dev->lock, flags); + tx_list_empty = (likely(list_empty(&dev->tx_reqs))); + spin_unlock_irqrestore(&dev->lock, flags); + + if (!tx_list_empty) { + /* Sleep until all data has been sent */ + wait_event_interruptible(dev->tx_flush_wait, + (likely(list_empty(&dev->tx_reqs_active)))); + } + mutex_unlock(&inode->i_mutex); + + return 0; +} + +static unsigned int +printer_poll(struct file *fd, poll_table *wait) +{ + struct printer_dev *dev = fd->private_data; + unsigned long flags; + int status = 0; + + mutex_lock(&dev->lock_printer_io); + spin_lock_irqsave(&dev->lock, flags); + setup_rx_reqs(dev); + spin_unlock_irqrestore(&dev->lock, flags); + mutex_unlock(&dev->lock_printer_io); + + poll_wait(fd, &dev->rx_wait, wait); + poll_wait(fd, &dev->tx_wait, wait); + + spin_lock_irqsave(&dev->lock, flags); + if (likely(!list_empty(&dev->tx_reqs))) + status |= POLLOUT | POLLWRNORM; + + if (likely(dev->current_rx_bytes) || + likely(!list_empty(&dev->rx_buffers))) + status |= POLLIN | POLLRDNORM; + + spin_unlock_irqrestore(&dev->lock, flags); + + return status; +} + +static long +printer_ioctl(struct file *fd, unsigned int code, unsigned long arg) +{ + struct printer_dev *dev = fd->private_data; + unsigned long flags; + int status = 0; + + DBG(dev, "printer_ioctl: cmd=0x%4.4x, arg=%lu\n", code, arg); + + /* handle ioctls */ + + spin_lock_irqsave(&dev->lock, flags); + + switch (code) { + case GADGET_GET_PRINTER_STATUS: + status = (int)dev->printer_status; + break; + case GADGET_SET_PRINTER_STATUS: + dev->printer_status = (u8)arg; + break; + default: + /* could not handle ioctl */ + DBG(dev, "printer_ioctl: ERROR cmd=0x%4.4xis not supported\n", + code); + status = -ENOTTY; + } + + spin_unlock_irqrestore(&dev->lock, flags); + + return status; +} + +/* used after endpoint configuration */ +static const struct file_operations printer_io_operations = { + .owner = THIS_MODULE, + .open = printer_open, + .read = printer_read, + .write = printer_write, + .fsync = printer_fsync, + .poll = printer_poll, + .unlocked_ioctl = printer_ioctl, + .release = printer_close, + .llseek = noop_llseek, +}; + +/*-------------------------------------------------------------------------*/ + +static int +set_printer_interface(struct printer_dev *dev) +{ + int result = 0; + + dev->in_ep->desc = ep_desc(dev->gadget, &fs_ep_in_desc, &hs_ep_in_desc, + &ss_ep_in_desc); + dev->in_ep->driver_data = dev; + + dev->out_ep->desc = ep_desc(dev->gadget, &fs_ep_out_desc, + &hs_ep_out_desc, &ss_ep_out_desc); + dev->out_ep->driver_data = dev; + + result = usb_ep_enable(dev->in_ep); + if (result != 0) { + DBG(dev, "enable %s --> %d\n", dev->in_ep->name, result); + goto done; + } + + result = usb_ep_enable(dev->out_ep); + if (result != 0) { + DBG(dev, "enable %s --> %d\n", dev->in_ep->name, result); + goto done; + } + +done: + /* on error, disable any endpoints */ + if (result != 0) { + (void) usb_ep_disable(dev->in_ep); + (void) usb_ep_disable(dev->out_ep); + dev->in_ep->desc = NULL; + dev->out_ep->desc = NULL; + } + + /* caller is responsible for cleanup on error */ + return result; +} + +static void printer_reset_interface(struct printer_dev *dev) +{ + if (dev->interface < 0) + return; + + DBG(dev, "%s\n", __func__); + + if (dev->in_ep->desc) + usb_ep_disable(dev->in_ep); + + if (dev->out_ep->desc) + usb_ep_disable(dev->out_ep); + + dev->in_ep->desc = NULL; + dev->out_ep->desc = NULL; + dev->interface = -1; +} + +/* Change our operational Interface. */ +static int set_interface(struct printer_dev *dev, unsigned number) +{ + int result = 0; + + /* Free the current interface */ + printer_reset_interface(dev); + + result = set_printer_interface(dev); + if (result) + printer_reset_interface(dev); + else + dev->interface = number; + + if (!result) + INFO(dev, "Using interface %x\n", number); + + return result; +} + +static void printer_soft_reset(struct printer_dev *dev) +{ + struct usb_request *req; + + INFO(dev, "Received Printer Reset Request\n"); + + if (usb_ep_disable(dev->in_ep)) + DBG(dev, "Failed to disable USB in_ep\n"); + if (usb_ep_disable(dev->out_ep)) + DBG(dev, "Failed to disable USB out_ep\n"); + + if (dev->current_rx_req != NULL) { + list_add(&dev->current_rx_req->list, &dev->rx_reqs); + dev->current_rx_req = NULL; + } + dev->current_rx_bytes = 0; + dev->current_rx_buf = NULL; + dev->reset_printer = 1; + + while (likely(!(list_empty(&dev->rx_buffers)))) { + req = container_of(dev->rx_buffers.next, struct usb_request, + list); + list_del_init(&req->list); + list_add(&req->list, &dev->rx_reqs); + } + + while (likely(!(list_empty(&dev->rx_reqs_active)))) { + req = container_of(dev->rx_buffers.next, struct usb_request, + list); + list_del_init(&req->list); + list_add(&req->list, &dev->rx_reqs); + } + + while (likely(!(list_empty(&dev->tx_reqs_active)))) { + req = container_of(dev->tx_reqs_active.next, + struct usb_request, list); + list_del_init(&req->list); + list_add(&req->list, &dev->tx_reqs); + } + + if (usb_ep_enable(dev->in_ep)) + DBG(dev, "Failed to enable USB in_ep\n"); + if (usb_ep_enable(dev->out_ep)) + DBG(dev, "Failed to enable USB out_ep\n"); + + wake_up_interruptible(&dev->rx_wait); + wake_up_interruptible(&dev->tx_wait); + wake_up_interruptible(&dev->tx_flush_wait); +} + +/*-------------------------------------------------------------------------*/ + +static bool gprinter_req_match(struct usb_function *f, + const struct usb_ctrlrequest *ctrl) +{ + struct printer_dev *dev = func_to_printer(f); + u16 w_index = le16_to_cpu(ctrl->wIndex); + u16 w_value = le16_to_cpu(ctrl->wValue); + u16 w_length = le16_to_cpu(ctrl->wLength); + + if ((ctrl->bRequestType & USB_RECIP_MASK) != USB_RECIP_INTERFACE || + (ctrl->bRequestType & USB_TYPE_MASK) != USB_TYPE_CLASS) + return false; + + switch (ctrl->bRequest) { + case GET_DEVICE_ID: + w_index >>= 8; + if (w_length <= PNP_STRING_LEN && + (USB_DIR_IN & ctrl->bRequestType)) + break; + return false; + case GET_PORT_STATUS: + if (!w_value && w_length == 1 && + (USB_DIR_IN & ctrl->bRequestType)) + break; + return false; + case SOFT_RESET: + if (!w_value && !w_length && + (USB_DIR_OUT & ctrl->bRequestType)) + break; + /* fall through */ + default: + return false; + } + return w_index == dev->interface; +} + +/* + * The setup() callback implements all the ep0 functionality that's not + * handled lower down. + */ +static int printer_func_setup(struct usb_function *f, + const struct usb_ctrlrequest *ctrl) +{ + struct printer_dev *dev = func_to_printer(f); + struct usb_composite_dev *cdev = f->config->cdev; + struct usb_request *req = cdev->req; + int value = -EOPNOTSUPP; + u16 wIndex = le16_to_cpu(ctrl->wIndex); + u16 wValue = le16_to_cpu(ctrl->wValue); + u16 wLength = le16_to_cpu(ctrl->wLength); + + DBG(dev, "ctrl req%02x.%02x v%04x i%04x l%d\n", + ctrl->bRequestType, ctrl->bRequest, wValue, wIndex, wLength); + + switch (ctrl->bRequestType&USB_TYPE_MASK) { + case USB_TYPE_CLASS: + switch (ctrl->bRequest) { + case GET_DEVICE_ID: /* Get the IEEE-1284 PNP String */ + /* Only one printer interface is supported. */ + if ((wIndex>>8) != dev->interface) + break; + + value = (dev->pnp_string[0] << 8) | dev->pnp_string[1]; + memcpy(req->buf, dev->pnp_string, value); + DBG(dev, "1284 PNP String: %x %s\n", value, + &dev->pnp_string[2]); + break; + + case GET_PORT_STATUS: /* Get Port Status */ + /* Only one printer interface is supported. */ + if (wIndex != dev->interface) + break; + + *(u8 *)req->buf = dev->printer_status; + value = min_t(u16, wLength, 1); + break; + + case SOFT_RESET: /* Soft Reset */ + /* Only one printer interface is supported. */ + if (wIndex != dev->interface) + break; + + printer_soft_reset(dev); + + value = 0; + break; + + default: + goto unknown; + } + break; + + default: +unknown: + VDBG(dev, + "unknown ctrl req%02x.%02x v%04x i%04x l%d\n", + ctrl->bRequestType, ctrl->bRequest, + wValue, wIndex, wLength); + break; + } + /* host either stalls (value < 0) or reports success */ + if (value >= 0) { + req->length = value; + req->zero = value < wLength; + value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC); + if (value < 0) { + ERROR(dev, "%s:%d Error!\n", __func__, __LINE__); + req->status = 0; + } + } + return value; +} + +static int __init printer_func_bind(struct usb_configuration *c, + struct usb_function *f) +{ + struct usb_gadget *gadget = c->cdev->gadget; + struct printer_dev *dev = func_to_printer(f); + struct device *pdev; + struct usb_composite_dev *cdev = c->cdev; + struct usb_ep *in_ep; + struct usb_ep *out_ep = NULL; + struct usb_request *req; + dev_t devt; + int id; + int ret; + u32 i; + + id = usb_interface_id(c, f); + if (id < 0) + return id; + intf_desc.bInterfaceNumber = id; + + /* finish hookup to lower layer ... */ + dev->gadget = gadget; + + /* all we really need is bulk IN/OUT */ + in_ep = usb_ep_autoconfig(cdev->gadget, &fs_ep_in_desc); + if (!in_ep) { +autoconf_fail: + dev_err(&cdev->gadget->dev, "can't autoconfigure on %s\n", + cdev->gadget->name); + return -ENODEV; + } + in_ep->driver_data = in_ep; /* claim */ + + out_ep = usb_ep_autoconfig(cdev->gadget, &fs_ep_out_desc); + if (!out_ep) + goto autoconf_fail; + out_ep->driver_data = out_ep; /* claim */ + + /* assumes that all endpoints are dual-speed */ + hs_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress; + hs_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress; + ss_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress; + ss_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress; + + ret = usb_assign_descriptors(f, fs_printer_function, + hs_printer_function, ss_printer_function); + if (ret) + return ret; + + dev->in_ep = in_ep; + dev->out_ep = out_ep; + + ret = -ENOMEM; + for (i = 0; i < dev->q_len; i++) { + req = printer_req_alloc(dev->in_ep, USB_BUFSIZE, GFP_KERNEL); + if (!req) + goto fail_tx_reqs; + list_add(&req->list, &dev->tx_reqs); + } + + for (i = 0; i < dev->q_len; i++) { + req = printer_req_alloc(dev->out_ep, USB_BUFSIZE, GFP_KERNEL); + if (!req) + goto fail_rx_reqs; + list_add(&req->list, &dev->rx_reqs); + } + + /* Setup the sysfs files for the printer gadget. */ + devt = MKDEV(major, dev->minor); + pdev = device_create(usb_gadget_class, NULL, devt, + NULL, "g_printer%d", dev->minor); + if (IS_ERR(pdev)) { + ERROR(dev, "Failed to create device: g_printer\n"); + ret = PTR_ERR(pdev); + goto fail_rx_reqs; + } + + /* + * Register a character device as an interface to a user mode + * program that handles the printer specific functionality. + */ + cdev_init(&dev->printer_cdev, &printer_io_operations); + dev->printer_cdev.owner = THIS_MODULE; + ret = cdev_add(&dev->printer_cdev, devt, 1); + if (ret) { + ERROR(dev, "Failed to open char device\n"); + goto fail_cdev_add; + } + + return 0; + +fail_cdev_add: + device_destroy(usb_gadget_class, devt); + +fail_rx_reqs: + while (!list_empty(&dev->rx_reqs)) { + req = container_of(dev->rx_reqs.next, struct usb_request, list); + list_del(&req->list); + printer_req_free(dev->out_ep, req); + } + +fail_tx_reqs: + while (!list_empty(&dev->tx_reqs)) { + req = container_of(dev->tx_reqs.next, struct usb_request, list); + list_del(&req->list); + printer_req_free(dev->in_ep, req); + } + + return ret; + +} + +static void printer_func_unbind(struct usb_configuration *c, + struct usb_function *f) +{ + struct printer_dev *dev; + struct usb_request *req; + + dev = func_to_printer(f); + + device_destroy(usb_gadget_class, MKDEV(major, dev->minor)); + + /* Remove Character Device */ + cdev_del(&dev->printer_cdev); + + /* we must already have been disconnected ... no i/o may be active */ + WARN_ON(!list_empty(&dev->tx_reqs_active)); + WARN_ON(!list_empty(&dev->rx_reqs_active)); + + /* Free all memory for this driver. */ + while (!list_empty(&dev->tx_reqs)) { + req = container_of(dev->tx_reqs.next, struct usb_request, + list); + list_del(&req->list); + printer_req_free(dev->in_ep, req); + } + + if (dev->current_rx_req != NULL) + printer_req_free(dev->out_ep, dev->current_rx_req); + + while (!list_empty(&dev->rx_reqs)) { + req = container_of(dev->rx_reqs.next, + struct usb_request, list); + list_del(&req->list); + printer_req_free(dev->out_ep, req); + } + + while (!list_empty(&dev->rx_buffers)) { + req = container_of(dev->rx_buffers.next, + struct usb_request, list); + list_del(&req->list); + printer_req_free(dev->out_ep, req); + } + usb_free_all_descriptors(f); + kfree(dev); +} + +static int printer_func_set_alt(struct usb_function *f, + unsigned intf, unsigned alt) +{ + struct printer_dev *dev = func_to_printer(f); + int ret = -ENOTSUPP; + + if (!alt) + ret = set_interface(dev, intf); + + return ret; +} + +static void printer_func_disable(struct usb_function *f) +{ + struct printer_dev *dev = func_to_printer(f); + unsigned long flags; + + DBG(dev, "%s\n", __func__); + + spin_lock_irqsave(&dev->lock, flags); + printer_reset_interface(dev); + spin_unlock_irqrestore(&dev->lock, flags); +} + +static int f_printer_bind_config(struct usb_configuration *c, char *pnp_str, + char *pnp_string, unsigned q_len, int minor) +{ + struct printer_dev *dev; + int status = -ENOMEM; + size_t len; + + if (minor >= minors) + return -ENOENT; + + dev = kzalloc(sizeof(*dev), GFP_KERNEL); + if (!dev) + return -ENOMEM; + + dev->pnp_string = pnp_string; + dev->minor = minor; + + dev->function.name = shortname; + dev->function.bind = printer_func_bind; + dev->function.setup = printer_func_setup; + dev->function.unbind = printer_func_unbind; + dev->function.set_alt = printer_func_set_alt; + dev->function.disable = printer_func_disable; + dev->function.req_match = gprinter_req_match; + INIT_LIST_HEAD(&dev->tx_reqs); + INIT_LIST_HEAD(&dev->rx_reqs); + INIT_LIST_HEAD(&dev->rx_buffers); + + if (pnp_str) + strlcpy(&dev->pnp_string[2], pnp_str, PNP_STRING_LEN - 2); + + len = strlen(pnp_string); + pnp_string[0] = (len >> 8) & 0xFF; + pnp_string[1] = len & 0xFF; + + spin_lock_init(&dev->lock); + mutex_init(&dev->lock_printer_io); + INIT_LIST_HEAD(&dev->tx_reqs_active); + INIT_LIST_HEAD(&dev->rx_reqs_active); + init_waitqueue_head(&dev->rx_wait); + init_waitqueue_head(&dev->tx_wait); + init_waitqueue_head(&dev->tx_flush_wait); + + dev->interface = -1; + dev->printer_cdev_open = 0; + dev->printer_status = PRINTER_NOT_ERROR; + dev->current_rx_req = NULL; + dev->current_rx_bytes = 0; + dev->current_rx_buf = NULL; + dev->q_len = q_len; + + status = usb_add_function(c, &dev->function); + if (status) { + kfree(dev); + return status; + } + + INFO(dev, "%s, version: " DRIVER_VERSION "\n", driver_desc); + return 0; +} + +static int gprinter_setup(int count) +{ + int status; + dev_t devt; + + usb_gadget_class = class_create(THIS_MODULE, "usb_printer_gadget"); + if (IS_ERR(usb_gadget_class)) { + status = PTR_ERR(usb_gadget_class); + usb_gadget_class = NULL; + pr_err("unable to create usb_gadget class %d\n", status); + return status; + } + + status = alloc_chrdev_region(&devt, 0, count, "USB printer gadget"); + if (status) { + pr_err("alloc_chrdev_region %d\n", status); + class_destroy(usb_gadget_class); + usb_gadget_class = NULL; + return status; + } + + major = MAJOR(devt); + minors = count; + + return status; +} + +static void gprinter_cleanup(void) +{ + if (major) { + unregister_chrdev_region(MKDEV(major, 0), minors); + major = minors = 0; + } + class_destroy(usb_gadget_class); + usb_gadget_class = NULL; +} diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c index d1f85f8..4d926d0 100644 --- a/drivers/usb/gadget/legacy/printer.c +++ b/drivers/usb/gadget/legacy/printer.c @@ -12,29 +12,7 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include -#include -#include -#include -#include #include #include @@ -46,58 +24,16 @@ USB_GADGET_COMPOSITE_OPTIONS(); #define DRIVER_DESC "Printer Gadget" -#define DRIVER_VERSION "2007 OCT 06" -#define GET_DEVICE_ID 0 -#define GET_PORT_STATUS 1 -#define SOFT_RESET 2 - -#define PRINTER_MINORS 4 +#define DRIVER_VERSION "2015 FEB 17" static const char shortname [] = "printer"; static const char driver_desc [] = DRIVER_DESC; -static int major, minors; -static struct class *usb_gadget_class; - -/*-------------------------------------------------------------------------*/ - -struct printer_dev { - spinlock_t lock; /* lock this structure */ - /* lock buffer lists during read/write calls */ - struct mutex lock_printer_io; - struct usb_gadget *gadget; - s8 interface; - struct usb_ep *in_ep, *out_ep; - - struct list_head rx_reqs; /* List of free RX structs */ - struct list_head rx_reqs_active; /* List of Active RX xfers */ - struct list_head rx_buffers; /* List of completed xfers */ - /* wait until there is data to be read. */ - wait_queue_head_t rx_wait; - struct list_head tx_reqs; /* List of free TX structs */ - struct list_head tx_reqs_active; /* List of Active TX xfers */ - /* Wait until there are write buffers available to use. */ - wait_queue_head_t tx_wait; - /* Wait until all write buffers have been sent. */ - wait_queue_head_t tx_flush_wait; - struct usb_request *current_rx_req; - size_t current_rx_bytes; - u8 *current_rx_buf; - u8 printer_status; - u8 reset_printer; - int minor; - struct cdev printer_cdev; - u8 printer_cdev_open; - wait_queue_head_t wait; - unsigned q_len; - char *pnp_string; /* We don't own memory! */ - struct usb_function function; -}; - -static inline struct printer_dev *func_to_printer(struct usb_function *f) -{ - return container_of(f, struct printer_dev, function); -} +/* + * This will be changed when f_printer is converted + * to the new function interface. + */ +#include "f_printer.c" /*-------------------------------------------------------------------------*/ @@ -135,10 +71,6 @@ module_param(qlen, uint, S_IRUGO|S_IWUSR); * descriptors are built on demand. */ -/* holds our biggest descriptor */ -#define USB_DESC_BUFSIZE 256 -#define USB_BUFSIZE 8192 - static struct usb_device_descriptor device_desc = { .bLength = sizeof device_desc, .bDescriptorType = USB_DT_DEVICE, @@ -151,108 +83,6 @@ static struct usb_device_descriptor device_desc = { .bNumConfigurations = 1 }; -static struct usb_interface_descriptor intf_desc = { - .bLength = sizeof intf_desc, - .bDescriptorType = USB_DT_INTERFACE, - .bNumEndpoints = 2, - .bInterfaceClass = USB_CLASS_PRINTER, - .bInterfaceSubClass = 1, /* Printer Sub-Class */ - .bInterfaceProtocol = 2, /* Bi-Directional */ - .iInterface = 0 -}; - -static struct usb_endpoint_descriptor fs_ep_in_desc = { - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = USB_DIR_IN, - .bmAttributes = USB_ENDPOINT_XFER_BULK -}; - -static struct usb_endpoint_descriptor fs_ep_out_desc = { - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = USB_DIR_OUT, - .bmAttributes = USB_ENDPOINT_XFER_BULK -}; - -static struct usb_descriptor_header *fs_printer_function[] = { - (struct usb_descriptor_header *) &intf_desc, - (struct usb_descriptor_header *) &fs_ep_in_desc, - (struct usb_descriptor_header *) &fs_ep_out_desc, - NULL -}; - -/* - * usb 2.0 devices need to expose both high speed and full speed - * descriptors, unless they only run at full speed. - */ - -static struct usb_endpoint_descriptor hs_ep_in_desc = { - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bmAttributes = USB_ENDPOINT_XFER_BULK, - .wMaxPacketSize = cpu_to_le16(512) -}; - -static struct usb_endpoint_descriptor hs_ep_out_desc = { - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bmAttributes = USB_ENDPOINT_XFER_BULK, - .wMaxPacketSize = cpu_to_le16(512) -}; - -static struct usb_qualifier_descriptor dev_qualifier = { - .bLength = sizeof dev_qualifier, - .bDescriptorType = USB_DT_DEVICE_QUALIFIER, - .bcdUSB = cpu_to_le16(0x0200), - .bDeviceClass = USB_CLASS_PRINTER, - .bNumConfigurations = 1 -}; - -static struct usb_descriptor_header *hs_printer_function[] = { - (struct usb_descriptor_header *) &intf_desc, - (struct usb_descriptor_header *) &hs_ep_in_desc, - (struct usb_descriptor_header *) &hs_ep_out_desc, - NULL -}; - -/* - * Added endpoint descriptors for 3.0 devices - */ - -static struct usb_endpoint_descriptor ss_ep_in_desc = { - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bmAttributes = USB_ENDPOINT_XFER_BULK, - .wMaxPacketSize = cpu_to_le16(1024), -}; - -static struct usb_ss_ep_comp_descriptor ss_ep_in_comp_desc = { - .bLength = sizeof(ss_ep_in_comp_desc), - .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, -}; - -static struct usb_endpoint_descriptor ss_ep_out_desc = { - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bmAttributes = USB_ENDPOINT_XFER_BULK, - .wMaxPacketSize = cpu_to_le16(1024), -}; - -static struct usb_ss_ep_comp_descriptor ss_ep_out_comp_desc = { - .bLength = sizeof(ss_ep_out_comp_desc), - .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, -}; - -static struct usb_descriptor_header *ss_printer_function[] = { - (struct usb_descriptor_header *) &intf_desc, - (struct usb_descriptor_header *) &ss_ep_in_desc, - (struct usb_descriptor_header *) &ss_ep_in_comp_desc, - (struct usb_descriptor_header *) &ss_ep_out_desc, - (struct usb_descriptor_header *) &ss_ep_out_comp_desc, - NULL -}; - static struct usb_otg_descriptor otg_descriptor = { .bLength = sizeof otg_descriptor, .bDescriptorType = USB_DT_OTG, @@ -264,28 +94,10 @@ static const struct usb_descriptor_header *otg_desc[] = { NULL, }; -/* maxpacket and other transfer characteristics vary by speed. */ -static inline struct usb_endpoint_descriptor *ep_desc(struct usb_gadget *gadget, - struct usb_endpoint_descriptor *fs, - struct usb_endpoint_descriptor *hs, - struct usb_endpoint_descriptor *ss) -{ - switch (gadget->speed) { - case USB_SPEED_SUPER: - return ss; - case USB_SPEED_HIGH: - return hs; - default: - return fs; - } -} - /*-------------------------------------------------------------------------*/ /* descriptors that are built on-demand */ -#define PNP_STRING_LEN 1024 - static char product_desc [40] = DRIVER_DESC; static char serial_num [40] = "1"; static char pnp_string[PNP_STRING_LEN] = @@ -309,1030 +121,12 @@ static struct usb_gadget_strings *dev_strings[] = { NULL, }; -/*-------------------------------------------------------------------------*/ - -static struct usb_request * -printer_req_alloc(struct usb_ep *ep, unsigned len, gfp_t gfp_flags) -{ - struct usb_request *req; - - req = usb_ep_alloc_request(ep, gfp_flags); - - if (req != NULL) { - req->length = len; - req->buf = kmalloc(len, gfp_flags); - if (req->buf == NULL) { - usb_ep_free_request(ep, req); - return NULL; - } - } - - return req; -} - -static void -printer_req_free(struct usb_ep *ep, struct usb_request *req) -{ - if (ep != NULL && req != NULL) { - kfree(req->buf); - usb_ep_free_request(ep, req); - } -} - -/*-------------------------------------------------------------------------*/ - -static void rx_complete(struct usb_ep *ep, struct usb_request *req) -{ - struct printer_dev *dev = ep->driver_data; - int status = req->status; - unsigned long flags; - - spin_lock_irqsave(&dev->lock, flags); - - list_del_init(&req->list); /* Remode from Active List */ - - switch (status) { - - /* normal completion */ - case 0: - if (req->actual > 0) { - list_add_tail(&req->list, &dev->rx_buffers); - DBG(dev, "G_Printer : rx length %d\n", req->actual); - } else { - list_add(&req->list, &dev->rx_reqs); - } - break; - - /* software-driven interface shutdown */ - case -ECONNRESET: /* unlink */ - case -ESHUTDOWN: /* disconnect etc */ - VDBG(dev, "rx shutdown, code %d\n", status); - list_add(&req->list, &dev->rx_reqs); - break; - - /* for hardware automagic (such as pxa) */ - case -ECONNABORTED: /* endpoint reset */ - DBG(dev, "rx %s reset\n", ep->name); - list_add(&req->list, &dev->rx_reqs); - break; - - /* data overrun */ - case -EOVERFLOW: - /* FALLTHROUGH */ - - default: - DBG(dev, "rx status %d\n", status); - list_add(&req->list, &dev->rx_reqs); - break; - } - - wake_up_interruptible(&dev->rx_wait); - spin_unlock_irqrestore(&dev->lock, flags); -} - -static void tx_complete(struct usb_ep *ep, struct usb_request *req) -{ - struct printer_dev *dev = ep->driver_data; - - switch (req->status) { - default: - VDBG(dev, "tx err %d\n", req->status); - /* FALLTHROUGH */ - case -ECONNRESET: /* unlink */ - case -ESHUTDOWN: /* disconnect etc */ - break; - case 0: - break; - } - - spin_lock(&dev->lock); - /* Take the request struct off the active list and put it on the - * free list. - */ - list_del_init(&req->list); - list_add(&req->list, &dev->tx_reqs); - wake_up_interruptible(&dev->tx_wait); - if (likely(list_empty(&dev->tx_reqs_active))) - wake_up_interruptible(&dev->tx_flush_wait); - - spin_unlock(&dev->lock); -} - -/*-------------------------------------------------------------------------*/ - -static int -printer_open(struct inode *inode, struct file *fd) -{ - struct printer_dev *dev; - unsigned long flags; - int ret = -EBUSY; - - dev = container_of(inode->i_cdev, struct printer_dev, printer_cdev); - - spin_lock_irqsave(&dev->lock, flags); - - if (!dev->printer_cdev_open) { - dev->printer_cdev_open = 1; - fd->private_data = dev; - ret = 0; - /* Change the printer status to show that it's on-line. */ - dev->printer_status |= PRINTER_SELECTED; - } - - spin_unlock_irqrestore(&dev->lock, flags); - - DBG(dev, "printer_open returned %x\n", ret); - return ret; -} - -static int -printer_close(struct inode *inode, struct file *fd) -{ - struct printer_dev *dev = fd->private_data; - unsigned long flags; - - spin_lock_irqsave(&dev->lock, flags); - dev->printer_cdev_open = 0; - fd->private_data = NULL; - /* Change printer status to show that the printer is off-line. */ - dev->printer_status &= ~PRINTER_SELECTED; - spin_unlock_irqrestore(&dev->lock, flags); - - DBG(dev, "printer_close\n"); - - return 0; -} - -/* This function must be called with interrupts turned off. */ -static void -setup_rx_reqs(struct printer_dev *dev) -{ - struct usb_request *req; - - while (likely(!list_empty(&dev->rx_reqs))) { - int error; - - req = container_of(dev->rx_reqs.next, - struct usb_request, list); - list_del_init(&req->list); - - /* The USB Host sends us whatever amount of data it wants to - * so we always set the length field to the full USB_BUFSIZE. - * If the amount of data is more than the read() caller asked - * for it will be stored in the request buffer until it is - * asked for by read(). - */ - req->length = USB_BUFSIZE; - req->complete = rx_complete; - - /* here, we unlock, and only unlock, to avoid deadlock. */ - spin_unlock(&dev->lock); - error = usb_ep_queue(dev->out_ep, req, GFP_ATOMIC); - spin_lock(&dev->lock); - if (error) { - DBG(dev, "rx submit --> %d\n", error); - list_add(&req->list, &dev->rx_reqs); - break; - } - /* if the req is empty, then add it into dev->rx_reqs_active. */ - else if (list_empty(&req->list)) { - list_add(&req->list, &dev->rx_reqs_active); - } - } -} - -static ssize_t -printer_read(struct file *fd, char __user *buf, size_t len, loff_t *ptr) -{ - struct printer_dev *dev = fd->private_data; - unsigned long flags; - size_t size; - size_t bytes_copied; - struct usb_request *req; - /* This is a pointer to the current USB rx request. */ - struct usb_request *current_rx_req; - /* This is the number of bytes in the current rx buffer. */ - size_t current_rx_bytes; - /* This is a pointer to the current rx buffer. */ - u8 *current_rx_buf; - - if (len == 0) - return -EINVAL; - - DBG(dev, "printer_read trying to read %d bytes\n", (int)len); - - mutex_lock(&dev->lock_printer_io); - spin_lock_irqsave(&dev->lock, flags); - - /* We will use this flag later to check if a printer reset happened - * after we turn interrupts back on. - */ - dev->reset_printer = 0; - - setup_rx_reqs(dev); - - bytes_copied = 0; - current_rx_req = dev->current_rx_req; - current_rx_bytes = dev->current_rx_bytes; - current_rx_buf = dev->current_rx_buf; - dev->current_rx_req = NULL; - dev->current_rx_bytes = 0; - dev->current_rx_buf = NULL; - - /* Check if there is any data in the read buffers. Please note that - * current_rx_bytes is the number of bytes in the current rx buffer. - * If it is zero then check if there are any other rx_buffers that - * are on the completed list. We are only out of data if all rx - * buffers are empty. - */ - if ((current_rx_bytes == 0) && - (likely(list_empty(&dev->rx_buffers)))) { - /* Turn interrupts back on before sleeping. */ - spin_unlock_irqrestore(&dev->lock, flags); - - /* - * If no data is available check if this is a NON-Blocking - * call or not. - */ - if (fd->f_flags & (O_NONBLOCK|O_NDELAY)) { - mutex_unlock(&dev->lock_printer_io); - return -EAGAIN; - } - - /* Sleep until data is available */ - wait_event_interruptible(dev->rx_wait, - (likely(!list_empty(&dev->rx_buffers)))); - spin_lock_irqsave(&dev->lock, flags); - } - - /* We have data to return then copy it to the caller's buffer.*/ - while ((current_rx_bytes || likely(!list_empty(&dev->rx_buffers))) - && len) { - if (current_rx_bytes == 0) { - req = container_of(dev->rx_buffers.next, - struct usb_request, list); - list_del_init(&req->list); - - if (req->actual && req->buf) { - current_rx_req = req; - current_rx_bytes = req->actual; - current_rx_buf = req->buf; - } else { - list_add(&req->list, &dev->rx_reqs); - continue; - } - } - - /* Don't leave irqs off while doing memory copies */ - spin_unlock_irqrestore(&dev->lock, flags); - - if (len > current_rx_bytes) - size = current_rx_bytes; - else - size = len; - - size -= copy_to_user(buf, current_rx_buf, size); - bytes_copied += size; - len -= size; - buf += size; - - spin_lock_irqsave(&dev->lock, flags); - - /* We've disconnected or reset so return. */ - if (dev->reset_printer) { - list_add(¤t_rx_req->list, &dev->rx_reqs); - spin_unlock_irqrestore(&dev->lock, flags); - mutex_unlock(&dev->lock_printer_io); - return -EAGAIN; - } - - /* If we not returning all the data left in this RX request - * buffer then adjust the amount of data left in the buffer. - * Othewise if we are done with this RX request buffer then - * requeue it to get any incoming data from the USB host. - */ - if (size < current_rx_bytes) { - current_rx_bytes -= size; - current_rx_buf += size; - } else { - list_add(¤t_rx_req->list, &dev->rx_reqs); - current_rx_bytes = 0; - current_rx_buf = NULL; - current_rx_req = NULL; - } - } - - dev->current_rx_req = current_rx_req; - dev->current_rx_bytes = current_rx_bytes; - dev->current_rx_buf = current_rx_buf; - - spin_unlock_irqrestore(&dev->lock, flags); - mutex_unlock(&dev->lock_printer_io); - - DBG(dev, "printer_read returned %d bytes\n", (int)bytes_copied); - - if (bytes_copied) - return bytes_copied; - else - return -EAGAIN; -} - -static ssize_t -printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr) -{ - struct printer_dev *dev = fd->private_data; - unsigned long flags; - size_t size; /* Amount of data in a TX request. */ - size_t bytes_copied = 0; - struct usb_request *req; - - DBG(dev, "printer_write trying to send %d bytes\n", (int)len); - - if (len == 0) - return -EINVAL; - - mutex_lock(&dev->lock_printer_io); - spin_lock_irqsave(&dev->lock, flags); - - /* Check if a printer reset happens while we have interrupts on */ - dev->reset_printer = 0; - - /* Check if there is any available write buffers */ - if (likely(list_empty(&dev->tx_reqs))) { - /* Turn interrupts back on before sleeping. */ - spin_unlock_irqrestore(&dev->lock, flags); - - /* - * If write buffers are available check if this is - * a NON-Blocking call or not. - */ - if (fd->f_flags & (O_NONBLOCK|O_NDELAY)) { - mutex_unlock(&dev->lock_printer_io); - return -EAGAIN; - } - - /* Sleep until a write buffer is available */ - wait_event_interruptible(dev->tx_wait, - (likely(!list_empty(&dev->tx_reqs)))); - spin_lock_irqsave(&dev->lock, flags); - } - - while (likely(!list_empty(&dev->tx_reqs)) && len) { - - if (len > USB_BUFSIZE) - size = USB_BUFSIZE; - else - size = len; - - req = container_of(dev->tx_reqs.next, struct usb_request, - list); - list_del_init(&req->list); - - req->complete = tx_complete; - req->length = size; - - /* Check if we need to send a zero length packet. */ - if (len > size) - /* They will be more TX requests so no yet. */ - req->zero = 0; - else - /* If the data amount is not a multple of the - * maxpacket size then send a zero length packet. - */ - req->zero = ((len % dev->in_ep->maxpacket) == 0); - - /* Don't leave irqs off while doing memory copies */ - spin_unlock_irqrestore(&dev->lock, flags); - - if (copy_from_user(req->buf, buf, size)) { - list_add(&req->list, &dev->tx_reqs); - mutex_unlock(&dev->lock_printer_io); - return bytes_copied; - } - - bytes_copied += size; - len -= size; - buf += size; - - spin_lock_irqsave(&dev->lock, flags); - - /* We've disconnected or reset so free the req and buffer */ - if (dev->reset_printer) { - list_add(&req->list, &dev->tx_reqs); - spin_unlock_irqrestore(&dev->lock, flags); - mutex_unlock(&dev->lock_printer_io); - return -EAGAIN; - } - - if (usb_ep_queue(dev->in_ep, req, GFP_ATOMIC)) { - list_add(&req->list, &dev->tx_reqs); - spin_unlock_irqrestore(&dev->lock, flags); - mutex_unlock(&dev->lock_printer_io); - return -EAGAIN; - } - - list_add(&req->list, &dev->tx_reqs_active); - - } - - spin_unlock_irqrestore(&dev->lock, flags); - mutex_unlock(&dev->lock_printer_io); - - DBG(dev, "printer_write sent %d bytes\n", (int)bytes_copied); - - if (bytes_copied) { - return bytes_copied; - } else { - return -EAGAIN; - } -} - -static int -printer_fsync(struct file *fd, loff_t start, loff_t end, int datasync) -{ - struct printer_dev *dev = fd->private_data; - struct inode *inode = file_inode(fd); - unsigned long flags; - int tx_list_empty; - - mutex_lock(&inode->i_mutex); - spin_lock_irqsave(&dev->lock, flags); - tx_list_empty = (likely(list_empty(&dev->tx_reqs))); - spin_unlock_irqrestore(&dev->lock, flags); - - if (!tx_list_empty) { - /* Sleep until all data has been sent */ - wait_event_interruptible(dev->tx_flush_wait, - (likely(list_empty(&dev->tx_reqs_active)))); - } - mutex_unlock(&inode->i_mutex); - - return 0; -} - -static unsigned int -printer_poll(struct file *fd, poll_table *wait) -{ - struct printer_dev *dev = fd->private_data; - unsigned long flags; - int status = 0; - - mutex_lock(&dev->lock_printer_io); - spin_lock_irqsave(&dev->lock, flags); - setup_rx_reqs(dev); - spin_unlock_irqrestore(&dev->lock, flags); - mutex_unlock(&dev->lock_printer_io); - - poll_wait(fd, &dev->rx_wait, wait); - poll_wait(fd, &dev->tx_wait, wait); - - spin_lock_irqsave(&dev->lock, flags); - if (likely(!list_empty(&dev->tx_reqs))) - status |= POLLOUT | POLLWRNORM; - - if (likely(dev->current_rx_bytes) || - likely(!list_empty(&dev->rx_buffers))) - status |= POLLIN | POLLRDNORM; - - spin_unlock_irqrestore(&dev->lock, flags); - - return status; -} - -static long -printer_ioctl(struct file *fd, unsigned int code, unsigned long arg) -{ - struct printer_dev *dev = fd->private_data; - unsigned long flags; - int status = 0; - - DBG(dev, "printer_ioctl: cmd=0x%4.4x, arg=%lu\n", code, arg); - - /* handle ioctls */ - - spin_lock_irqsave(&dev->lock, flags); - - switch (code) { - case GADGET_GET_PRINTER_STATUS: - status = (int)dev->printer_status; - break; - case GADGET_SET_PRINTER_STATUS: - dev->printer_status = (u8)arg; - break; - default: - /* could not handle ioctl */ - DBG(dev, "printer_ioctl: ERROR cmd=0x%4.4xis not supported\n", - code); - status = -ENOTTY; - } - - spin_unlock_irqrestore(&dev->lock, flags); - - return status; -} - -/* used after endpoint configuration */ -static const struct file_operations printer_io_operations = { - .owner = THIS_MODULE, - .open = printer_open, - .read = printer_read, - .write = printer_write, - .fsync = printer_fsync, - .poll = printer_poll, - .unlocked_ioctl = printer_ioctl, - .release = printer_close, - .llseek = noop_llseek, -}; - -/*-------------------------------------------------------------------------*/ - -static int -set_printer_interface(struct printer_dev *dev) -{ - int result = 0; - - dev->in_ep->desc = ep_desc(dev->gadget, &fs_ep_in_desc, &hs_ep_in_desc, - &ss_ep_in_desc); - dev->in_ep->driver_data = dev; - - dev->out_ep->desc = ep_desc(dev->gadget, &fs_ep_out_desc, - &hs_ep_out_desc, &ss_ep_out_desc); - dev->out_ep->driver_data = dev; - - result = usb_ep_enable(dev->in_ep); - if (result != 0) { - DBG(dev, "enable %s --> %d\n", dev->in_ep->name, result); - goto done; - } - - result = usb_ep_enable(dev->out_ep); - if (result != 0) { - DBG(dev, "enable %s --> %d\n", dev->in_ep->name, result); - goto done; - } - -done: - /* on error, disable any endpoints */ - if (result != 0) { - (void) usb_ep_disable(dev->in_ep); - (void) usb_ep_disable(dev->out_ep); - dev->in_ep->desc = NULL; - dev->out_ep->desc = NULL; - } - - /* caller is responsible for cleanup on error */ - return result; -} - -static void printer_reset_interface(struct printer_dev *dev) -{ - if (dev->interface < 0) - return; - - DBG(dev, "%s\n", __func__); - - if (dev->in_ep->desc) - usb_ep_disable(dev->in_ep); - - if (dev->out_ep->desc) - usb_ep_disable(dev->out_ep); - - dev->in_ep->desc = NULL; - dev->out_ep->desc = NULL; - dev->interface = -1; -} - -/* Change our operational Interface. */ -static int set_interface(struct printer_dev *dev, unsigned number) -{ - int result = 0; - - /* Free the current interface */ - printer_reset_interface(dev); - - result = set_printer_interface(dev); - if (result) - printer_reset_interface(dev); - else - dev->interface = number; - - if (!result) - INFO(dev, "Using interface %x\n", number); - - return result; -} - -static void printer_soft_reset(struct printer_dev *dev) -{ - struct usb_request *req; - - INFO(dev, "Received Printer Reset Request\n"); - - if (usb_ep_disable(dev->in_ep)) - DBG(dev, "Failed to disable USB in_ep\n"); - if (usb_ep_disable(dev->out_ep)) - DBG(dev, "Failed to disable USB out_ep\n"); - - if (dev->current_rx_req != NULL) { - list_add(&dev->current_rx_req->list, &dev->rx_reqs); - dev->current_rx_req = NULL; - } - dev->current_rx_bytes = 0; - dev->current_rx_buf = NULL; - dev->reset_printer = 1; - - while (likely(!(list_empty(&dev->rx_buffers)))) { - req = container_of(dev->rx_buffers.next, struct usb_request, - list); - list_del_init(&req->list); - list_add(&req->list, &dev->rx_reqs); - } - - while (likely(!(list_empty(&dev->rx_reqs_active)))) { - req = container_of(dev->rx_buffers.next, struct usb_request, - list); - list_del_init(&req->list); - list_add(&req->list, &dev->rx_reqs); - } - - while (likely(!(list_empty(&dev->tx_reqs_active)))) { - req = container_of(dev->tx_reqs_active.next, - struct usb_request, list); - list_del_init(&req->list); - list_add(&req->list, &dev->tx_reqs); - } - - if (usb_ep_enable(dev->in_ep)) - DBG(dev, "Failed to enable USB in_ep\n"); - if (usb_ep_enable(dev->out_ep)) - DBG(dev, "Failed to enable USB out_ep\n"); - - wake_up_interruptible(&dev->rx_wait); - wake_up_interruptible(&dev->tx_wait); - wake_up_interruptible(&dev->tx_flush_wait); -} - -/*-------------------------------------------------------------------------*/ - -static bool gprinter_req_match(struct usb_function *f, - const struct usb_ctrlrequest *ctrl) -{ - struct printer_dev *dev = func_to_printer(f); - u16 w_index = le16_to_cpu(ctrl->wIndex); - u16 w_value = le16_to_cpu(ctrl->wValue); - u16 w_length = le16_to_cpu(ctrl->wLength); - - if ((ctrl->bRequestType & USB_RECIP_MASK) != USB_RECIP_INTERFACE || - (ctrl->bRequestType & USB_TYPE_MASK) != USB_TYPE_CLASS) - return false; - - switch (ctrl->bRequest) { - case GET_DEVICE_ID: - w_index >>= 8; - if (w_length <= PNP_STRING_LEN && - (USB_DIR_IN & ctrl->bRequestType)) - break; - return false; - case GET_PORT_STATUS: - if (!w_value && w_length == 1 && - (USB_DIR_IN & ctrl->bRequestType)) - break; - return false; - case SOFT_RESET: - if (!w_value && !w_length && - (USB_DIR_OUT & ctrl->bRequestType)) - break; - /* fall through */ - default: - return false; - } - return w_index == dev->interface; -} - -/* - * The setup() callback implements all the ep0 functionality that's not - * handled lower down. - */ -static int printer_func_setup(struct usb_function *f, - const struct usb_ctrlrequest *ctrl) -{ - struct printer_dev *dev = func_to_printer(f); - struct usb_composite_dev *cdev = f->config->cdev; - struct usb_request *req = cdev->req; - int value = -EOPNOTSUPP; - u16 wIndex = le16_to_cpu(ctrl->wIndex); - u16 wValue = le16_to_cpu(ctrl->wValue); - u16 wLength = le16_to_cpu(ctrl->wLength); - - DBG(dev, "ctrl req%02x.%02x v%04x i%04x l%d\n", - ctrl->bRequestType, ctrl->bRequest, wValue, wIndex, wLength); - - switch (ctrl->bRequestType&USB_TYPE_MASK) { - case USB_TYPE_CLASS: - switch (ctrl->bRequest) { - case GET_DEVICE_ID: /* Get the IEEE-1284 PNP String */ - /* Only one printer interface is supported. */ - if ((wIndex>>8) != dev->interface) - break; - - value = (dev->pnp_string[0] << 8) | dev->pnp_string[1]; - memcpy(req->buf, dev->pnp_string, value); - DBG(dev, "1284 PNP String: %x %s\n", value, - &dev->pnp_string[2]); - break; - - case GET_PORT_STATUS: /* Get Port Status */ - /* Only one printer interface is supported. */ - if (wIndex != dev->interface) - break; - - *(u8 *)req->buf = dev->printer_status; - value = min(wLength, (u16) 1); - break; - - case SOFT_RESET: /* Soft Reset */ - /* Only one printer interface is supported. */ - if (wIndex != dev->interface) - break; - - printer_soft_reset(dev); - - value = 0; - break; - - default: - goto unknown; - } - break; - - default: -unknown: - VDBG(dev, - "unknown ctrl req%02x.%02x v%04x i%04x l%d\n", - ctrl->bRequestType, ctrl->bRequest, - wValue, wIndex, wLength); - break; - } - /* host either stalls (value < 0) or reports success */ - if (value >= 0) { - req->length = value; - req->zero = value < wLength; - value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC); - if (value < 0) { - ERROR(dev, "%s:%d Error!\n", __func__, __LINE__); - req->status = 0; - } - } - return value; -} - -static int __init printer_func_bind(struct usb_configuration *c, - struct usb_function *f) -{ - struct usb_gadget *gadget = c->cdev->gadget; - struct printer_dev *dev = func_to_printer(f); - struct device *pdev; - struct usb_composite_dev *cdev = c->cdev; - struct usb_ep *in_ep; - struct usb_ep *out_ep = NULL; - struct usb_request *req; - dev_t devt; - int id; - int ret; - u32 i; - - id = usb_interface_id(c, f); - if (id < 0) - return id; - intf_desc.bInterfaceNumber = id; - - /* finish hookup to lower layer ... */ - dev->gadget = gadget; - - /* all we really need is bulk IN/OUT */ - in_ep = usb_ep_autoconfig(cdev->gadget, &fs_ep_in_desc); - if (!in_ep) { -autoconf_fail: - dev_err(&cdev->gadget->dev, "can't autoconfigure on %s\n", - cdev->gadget->name); - return -ENODEV; - } - in_ep->driver_data = in_ep; /* claim */ - - out_ep = usb_ep_autoconfig(cdev->gadget, &fs_ep_out_desc); - if (!out_ep) - goto autoconf_fail; - out_ep->driver_data = out_ep; /* claim */ - - /* assumes that all endpoints are dual-speed */ - hs_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress; - hs_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress; - ss_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress; - ss_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress; - - ret = usb_assign_descriptors(f, fs_printer_function, - hs_printer_function, ss_printer_function); - if (ret) - return ret; - - dev->in_ep = in_ep; - dev->out_ep = out_ep; - - ret = -ENOMEM; - for (i = 0; i < dev->q_len; i++) { - req = printer_req_alloc(dev->in_ep, USB_BUFSIZE, GFP_KERNEL); - if (!req) - goto fail_tx_reqs; - list_add(&req->list, &dev->tx_reqs); - } - - for (i = 0; i < dev->q_len; i++) { - req = printer_req_alloc(dev->out_ep, USB_BUFSIZE, GFP_KERNEL); - if (!req) - goto fail_rx_reqs; - list_add(&req->list, &dev->rx_reqs); - } - - /* Setup the sysfs files for the printer gadget. */ - devt = MKDEV(major, dev->minor); - pdev = device_create(usb_gadget_class, NULL, devt, - NULL, "g_printer%d", dev->minor); - if (IS_ERR(pdev)) { - ERROR(dev, "Failed to create device: g_printer\n"); - ret = PTR_ERR(pdev); - goto fail_rx_reqs; - } - - /* - * Register a character device as an interface to a user mode - * program that handles the printer specific functionality. - */ - cdev_init(&dev->printer_cdev, &printer_io_operations); - dev->printer_cdev.owner = THIS_MODULE; - ret = cdev_add(&dev->printer_cdev, devt, 1); - if (ret) { - ERROR(dev, "Failed to open char device\n"); - goto fail_cdev_add; - } - - return 0; - -fail_cdev_add: - device_destroy(usb_gadget_class, devt); - -fail_rx_reqs: - while (!list_empty(&dev->rx_reqs)) { - req = container_of(dev->rx_reqs.next, struct usb_request, list); - list_del(&req->list); - printer_req_free(dev->out_ep, req); - } - -fail_tx_reqs: - while (!list_empty(&dev->tx_reqs)) { - req = container_of(dev->tx_reqs.next, struct usb_request, list); - list_del(&req->list); - printer_req_free(dev->in_ep, req); - } - - return ret; - -} - -static void printer_func_unbind(struct usb_configuration *c, - struct usb_function *f) -{ - struct printer_dev *dev; - struct usb_request *req; - - dev = func_to_printer(f); - - device_destroy(usb_gadget_class, MKDEV(major, dev->minor)); - - /* Remove Character Device */ - cdev_del(&dev->printer_cdev); - - /* we must already have been disconnected ... no i/o may be active */ - WARN_ON(!list_empty(&dev->tx_reqs_active)); - WARN_ON(!list_empty(&dev->rx_reqs_active)); - - /* Free all memory for this driver. */ - while (!list_empty(&dev->tx_reqs)) { - req = container_of(dev->tx_reqs.next, struct usb_request, - list); - list_del(&req->list); - printer_req_free(dev->in_ep, req); - } - - if (dev->current_rx_req != NULL) - printer_req_free(dev->out_ep, dev->current_rx_req); - - while (!list_empty(&dev->rx_reqs)) { - req = container_of(dev->rx_reqs.next, - struct usb_request, list); - list_del(&req->list); - printer_req_free(dev->out_ep, req); - } - - while (!list_empty(&dev->rx_buffers)) { - req = container_of(dev->rx_buffers.next, - struct usb_request, list); - list_del(&req->list); - printer_req_free(dev->out_ep, req); - } - usb_free_all_descriptors(f); - kfree(dev); -} - -static int printer_func_set_alt(struct usb_function *f, - unsigned intf, unsigned alt) -{ - struct printer_dev *dev = func_to_printer(f); - int ret = -ENOTSUPP; - - if (!alt) - ret = set_interface(dev, intf); - - return ret; -} - -static void printer_func_disable(struct usb_function *f) -{ - struct printer_dev *dev = func_to_printer(f); - unsigned long flags; - - DBG(dev, "%s\n", __func__); - - spin_lock_irqsave(&dev->lock, flags); - printer_reset_interface(dev); - spin_unlock_irqrestore(&dev->lock, flags); -} - static struct usb_configuration printer_cfg_driver = { .label = "printer", .bConfigurationValue = 1, .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER, }; -static int f_printer_bind_config(struct usb_configuration *c, char *pnp_str, - char *pnp_string, unsigned q_len, int minor) -{ - struct printer_dev *dev; - int status = -ENOMEM; - size_t len; - - if (minor >= minors) - return -ENOENT; - - dev = kzalloc(sizeof(*dev), GFP_KERNEL); - if (!dev) - return -ENOMEM; - - dev->pnp_string = pnp_string; - dev->minor = minor; - - dev->function.name = shortname; - dev->function.bind = printer_func_bind; - dev->function.setup = printer_func_setup; - dev->function.unbind = printer_func_unbind; - dev->function.set_alt = printer_func_set_alt; - dev->function.disable = printer_func_disable; - dev->function.req_match = gprinter_req_match; - INIT_LIST_HEAD(&dev->tx_reqs); - INIT_LIST_HEAD(&dev->rx_reqs); - INIT_LIST_HEAD(&dev->rx_buffers); - - if (pnp_str) - strlcpy(&dev->pnp_string[2], pnp_str, PNP_STRING_LEN - 2); - - len = strlen(pnp_string); - pnp_string[0] = (len >> 8) & 0xFF; - pnp_string[1] = len & 0xFF; - - spin_lock_init(&dev->lock); - mutex_init(&dev->lock_printer_io); - INIT_LIST_HEAD(&dev->tx_reqs_active); - INIT_LIST_HEAD(&dev->rx_reqs_active); - init_waitqueue_head(&dev->rx_wait); - init_waitqueue_head(&dev->tx_wait); - init_waitqueue_head(&dev->tx_flush_wait); - - dev->interface = -1; - dev->printer_cdev_open = 0; - dev->printer_status = PRINTER_NOT_ERROR; - dev->current_rx_req = NULL; - dev->current_rx_bytes = 0; - dev->current_rx_buf = NULL; - dev->q_len = q_len; - - status = usb_add_function(c, &dev->function); - if (status) { - kfree(dev); - return status; - } - INFO(dev, "%s, version: " DRIVER_VERSION "\n", driver_desc); - return 0; -} - static int __init printer_do_config(struct usb_configuration *c) { struct usb_gadget *gadget = c->cdev->gadget; @@ -1350,43 +144,6 @@ static int __init printer_do_config(struct usb_configuration *c) return f_printer_bind_config(c, iPNPstring, pnp_string, QLEN, 0); } -static int gprinter_setup(int count) -{ - int status; - dev_t devt; - - usb_gadget_class = class_create(THIS_MODULE, "usb_printer_gadget"); - if (IS_ERR(usb_gadget_class)) { - status = PTR_ERR(usb_gadget_class); - usb_gadget_class = NULL; - pr_err("unable to create usb_gadget class %d\n", status); - return status; - } - - status = alloc_chrdev_region(&devt, 0, count, "USB printer gadget"); - if (status) { - pr_err("alloc_chrdev_region %d\n", status); - class_destroy(usb_gadget_class); - usb_gadget_class = NULL; - return status; - } - - major = MAJOR(devt); - minors = count; - - return status; -} - -static void gprinter_cleanup(void) -{ - if (major) { - unregister_chrdev_region(MKDEV(major, 0), minors); - major = minors = 0; - } - class_destroy(usb_gadget_class); - usb_gadget_class = NULL; -} - static int __init printer_bind(struct usb_composite_dev *cdev) { int ret; -- cgit v0.10.2 From b26394bd567e5ebe57ec4dee7fe6cd14023c96e9 Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Tue, 3 Mar 2015 10:52:28 +0100 Subject: usb: gadget: f_printer: convert to new function interface with backward compatibility In order to add configfs support, a usb function must be converted to use the new interface. This patch converts the function to the new interface and provides backward compatiblity layer, which can be removed after all its users are converted to use the new interface. Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index b454d05..9d507cf 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig @@ -196,6 +196,9 @@ config USB_F_MIDI config USB_F_HID tristate +config USB_F_PRINTER + tristate + choice tristate "USB Gadget Drivers" default USB_ETH diff --git a/drivers/usb/gadget/function/Makefile b/drivers/usb/gadget/function/Makefile index f71b1aa..bd7def5 100644 --- a/drivers/usb/gadget/function/Makefile +++ b/drivers/usb/gadget/function/Makefile @@ -42,3 +42,5 @@ usb_f_midi-y := f_midi.o obj-$(CONFIG_USB_F_MIDI) += usb_f_midi.o usb_f_hid-y := f_hid.o obj-$(CONFIG_USB_F_HID) += usb_f_hid.o +usb_f_printer-y := f_printer.o +obj-$(CONFIG_USB_F_PRINTER) += usb_f_printer.o diff --git a/drivers/usb/gadget/function/f_printer.c b/drivers/usb/gadget/function/f_printer.c index 0847972..93f4d4e 100644 --- a/drivers/usb/gadget/function/f_printer.c +++ b/drivers/usb/gadget/function/f_printer.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -46,6 +47,8 @@ #include #include +#include "u_printer.h" + #define PNP_STRING_LEN 1024 #define PRINTER_MINORS 4 #define GET_DEVICE_ID 0 @@ -54,6 +57,10 @@ static int major, minors; static struct class *usb_gadget_class; +#ifndef USBF_PRINTER_INCLUDED +static DEFINE_IDA(printer_ida); +static DEFINE_MUTEX(printer_ida_lock); /* protects access do printer_ida */ +#endif /*-------------------------------------------------------------------------*/ @@ -999,7 +1006,7 @@ unknown: return value; } -static int __init printer_func_bind(struct usb_configuration *c, +static int printer_func_bind(struct usb_configuration *c, struct usb_function *f) { struct usb_gadget *gadget = c->cdev->gadget; @@ -1111,6 +1118,7 @@ fail_tx_reqs: } +#ifdef USBF_PRINTER_INCLUDED static void printer_func_unbind(struct usb_configuration *c, struct usb_function *f) { @@ -1155,6 +1163,7 @@ static void printer_func_unbind(struct usb_configuration *c, usb_free_all_descriptors(f); kfree(dev); } +#endif static int printer_func_set_alt(struct usb_function *f, unsigned intf, unsigned alt) @@ -1180,6 +1189,7 @@ static void printer_func_disable(struct usb_function *f) spin_unlock_irqrestore(&dev->lock, flags); } +#ifdef USBF_PRINTER_INCLUDED static int f_printer_bind_config(struct usb_configuration *c, char *pnp_str, char *pnp_string, unsigned q_len, int minor) { @@ -1240,6 +1250,179 @@ static int f_printer_bind_config(struct usb_configuration *c, char *pnp_str, INFO(dev, "%s, version: " DRIVER_VERSION "\n", driver_desc); return 0; } +#else +static inline int gprinter_get_minor(void) +{ + return ida_simple_get(&printer_ida, 0, 0, GFP_KERNEL); +} + +static inline void gprinter_put_minor(int minor) +{ + ida_simple_remove(&printer_ida, minor); +} + +static int gprinter_setup(int); +static void gprinter_cleanup(void); + +static void gprinter_free_inst(struct usb_function_instance *f) +{ + struct f_printer_opts *opts; + + opts = container_of(f, struct f_printer_opts, func_inst); + + mutex_lock(&printer_ida_lock); + + gprinter_put_minor(opts->minor); + if (idr_is_empty(&printer_ida.idr)) + gprinter_cleanup(); + + mutex_unlock(&printer_ida_lock); + + kfree(opts); +} + +static struct usb_function_instance *gprinter_alloc_inst(void) +{ + struct f_printer_opts *opts; + struct usb_function_instance *ret; + int status = 0; + + opts = kzalloc(sizeof(*opts), GFP_KERNEL); + if (!opts) + return ERR_PTR(-ENOMEM); + + opts->func_inst.free_func_inst = gprinter_free_inst; + ret = &opts->func_inst; + + mutex_lock(&printer_ida_lock); + + if (idr_is_empty(&printer_ida.idr)) { + status = gprinter_setup(PRINTER_MINORS); + if (status) { + ret = ERR_PTR(status); + kfree(opts); + goto unlock; + } + } + + opts->minor = gprinter_get_minor(); + if (opts->minor < 0) { + ret = ERR_PTR(opts->minor); + kfree(opts); + if (idr_is_empty(&printer_ida.idr)) + gprinter_cleanup(); + } + +unlock: + mutex_unlock(&printer_ida_lock); + return ret; +} + +static void gprinter_free(struct usb_function *f) +{ + struct printer_dev *dev = func_to_printer(f); + + kfree(dev); +} + +static void printer_func_unbind(struct usb_configuration *c, + struct usb_function *f) +{ + struct printer_dev *dev; + struct usb_request *req; + + dev = func_to_printer(f); + + device_destroy(usb_gadget_class, MKDEV(major, dev->minor)); + + /* Remove Character Device */ + cdev_del(&dev->printer_cdev); + + /* we must already have been disconnected ... no i/o may be active */ + WARN_ON(!list_empty(&dev->tx_reqs_active)); + WARN_ON(!list_empty(&dev->rx_reqs_active)); + + /* Free all memory for this driver. */ + while (!list_empty(&dev->tx_reqs)) { + req = container_of(dev->tx_reqs.next, struct usb_request, + list); + list_del(&req->list); + printer_req_free(dev->in_ep, req); + } + + if (dev->current_rx_req != NULL) + printer_req_free(dev->out_ep, dev->current_rx_req); + + while (!list_empty(&dev->rx_reqs)) { + req = container_of(dev->rx_reqs.next, + struct usb_request, list); + list_del(&req->list); + printer_req_free(dev->out_ep, req); + } + + while (!list_empty(&dev->rx_buffers)) { + req = container_of(dev->rx_buffers.next, + struct usb_request, list); + list_del(&req->list); + printer_req_free(dev->out_ep, req); + } + usb_free_all_descriptors(f); +} + +static struct usb_function *gprinter_alloc(struct usb_function_instance *fi) +{ + struct printer_dev *dev; + struct f_printer_opts *opts; + + opts = container_of(fi, struct f_printer_opts, func_inst); + + if (opts->minor >= minors) + return ERR_PTR(-ENOENT); + + dev = kzalloc(sizeof(*dev), GFP_KERNEL); + if (!dev) + return ERR_PTR(-ENOMEM); + + dev->minor = opts->minor; + dev->pnp_string = opts->pnp_string; + dev->q_len = opts->q_len; + + dev->function.name = "printer"; + dev->function.bind = printer_func_bind; + dev->function.setup = printer_func_setup; + dev->function.unbind = printer_func_unbind; + dev->function.set_alt = printer_func_set_alt; + dev->function.disable = printer_func_disable; + dev->function.req_match = gprinter_req_match; + dev->function.free_func = gprinter_free; + + INIT_LIST_HEAD(&dev->tx_reqs); + INIT_LIST_HEAD(&dev->rx_reqs); + INIT_LIST_HEAD(&dev->rx_buffers); + INIT_LIST_HEAD(&dev->tx_reqs_active); + INIT_LIST_HEAD(&dev->rx_reqs_active); + + spin_lock_init(&dev->lock); + mutex_init(&dev->lock_printer_io); + init_waitqueue_head(&dev->rx_wait); + init_waitqueue_head(&dev->tx_wait); + init_waitqueue_head(&dev->tx_flush_wait); + + dev->interface = -1; + dev->printer_cdev_open = 0; + dev->printer_status = PRINTER_NOT_ERROR; + dev->current_rx_req = NULL; + dev->current_rx_bytes = 0; + dev->current_rx_buf = NULL; + + return &dev->function; +} + +DECLARE_USB_FUNCTION_INIT(printer, gprinter_alloc_inst, gprinter_alloc); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Craig Nadler"); + +#endif static int gprinter_setup(int count) { diff --git a/drivers/usb/gadget/function/u_printer.h b/drivers/usb/gadget/function/u_printer.h new file mode 100644 index 0000000..b2338ca --- /dev/null +++ b/drivers/usb/gadget/function/u_printer.h @@ -0,0 +1,30 @@ +/* + * u_printer.h + * + * Utility definitions for the printer function + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * http://www.samsung.com + * + * Author: Andrzej Pietrasiewicz + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#ifndef U_PRINTER_H +#define U_PRINTER_H + +#include + +#define PNP_STRING_LEN 1024 + +struct f_printer_opts { + struct usb_function_instance func_inst; + int minor; + char pnp_string[PNP_STRING_LEN]; + unsigned q_len; +}; + +#endif /* U_PRINTER_H */ diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c index 4d926d0..770b504 100644 --- a/drivers/usb/gadget/legacy/printer.c +++ b/drivers/usb/gadget/legacy/printer.c @@ -33,6 +33,7 @@ static const char driver_desc [] = DRIVER_DESC; * This will be changed when f_printer is converted * to the new function interface. */ +#define USBF_PRINTER_INCLUDED #include "f_printer.c" /*-------------------------------------------------------------------------*/ -- cgit v0.10.2 From 69504f808d6770940f1404b6f6f43c50cfe0be72 Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Tue, 3 Mar 2015 10:52:29 +0100 Subject: usb: gadget: printer: convert to new interface of f_printer The goal is to remove the old function interface, so its (only) user must be converted to the new interface. Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/legacy/Kconfig b/drivers/usb/gadget/legacy/Kconfig index 113c87e..d5a7102 100644 --- a/drivers/usb/gadget/legacy/Kconfig +++ b/drivers/usb/gadget/legacy/Kconfig @@ -301,6 +301,7 @@ config USB_MIDI_GADGET config USB_G_PRINTER tristate "Printer Gadget" select USB_LIBCOMPOSITE + select USB_F_PRINTER help The Printer Gadget channels data between the USB host and a userspace program driving the print engine. The user space diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c index 770b504..a8050f8 100644 --- a/drivers/usb/gadget/legacy/printer.c +++ b/drivers/usb/gadget/legacy/printer.c @@ -29,12 +29,7 @@ USB_GADGET_COMPOSITE_OPTIONS(); static const char shortname [] = "printer"; static const char driver_desc [] = DRIVER_DESC; -/* - * This will be changed when f_printer is converted - * to the new function interface. - */ -#define USBF_PRINTER_INCLUDED -#include "f_printer.c" +#include "u_printer.h" /*-------------------------------------------------------------------------*/ @@ -65,6 +60,9 @@ module_param(qlen, uint, S_IRUGO|S_IWUSR); #define QLEN qlen +static struct usb_function_instance *fi_printer; +static struct usb_function *f_printer; + /*-------------------------------------------------------------------------*/ /* @@ -131,6 +129,7 @@ static struct usb_configuration printer_cfg_driver = { static int __init printer_do_config(struct usb_configuration *c) { struct usb_gadget *gadget = c->cdev->gadget; + int status = 0; usb_ep_autoconfig_reset(gadget); @@ -142,20 +141,41 @@ static int __init printer_do_config(struct usb_configuration *c) printer_cfg_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; } - return f_printer_bind_config(c, iPNPstring, pnp_string, QLEN, 0); + f_printer = usb_get_function(fi_printer); + if (IS_ERR(f_printer)) + return PTR_ERR(f_printer); + + status = usb_add_function(c, f_printer); + if (status < 0) + usb_put_function(f_printer); + + return status; } static int __init printer_bind(struct usb_composite_dev *cdev) { - int ret; + struct f_printer_opts *opts; + int ret, len; - ret = gprinter_setup(PRINTER_MINORS); - if (ret) - return ret; + fi_printer = usb_get_function_instance("printer"); + if (IS_ERR(fi_printer)) + return PTR_ERR(fi_printer); + + if (iPNPstring) + strlcpy(&pnp_string[2], iPNPstring, PNP_STRING_LEN - 2); + + len = strlen(pnp_string); + pnp_string[0] = (len >> 8) & 0xFF; + pnp_string[1] = len & 0xFF; + + opts = container_of(fi_printer, struct f_printer_opts, func_inst); + opts->minor = 0; + memcpy(opts->pnp_string, pnp_string, PNP_STRING_LEN); + opts->q_len = QLEN; ret = usb_string_ids_tab(cdev, strings); if (ret < 0) { - gprinter_cleanup(); + usb_put_function_instance(fi_printer); return ret; } device_desc.iManufacturer = strings[USB_GADGET_MANUFACTURER_IDX].id; @@ -164,7 +184,7 @@ static int __init printer_bind(struct usb_composite_dev *cdev) ret = usb_add_config(cdev, &printer_cfg_driver, printer_do_config); if (ret) { - gprinter_cleanup(); + usb_put_function_instance(fi_printer); return ret; } usb_composite_overwrite_options(cdev, &coverwrite); @@ -173,7 +193,9 @@ static int __init printer_bind(struct usb_composite_dev *cdev) static int __exit printer_unbind(struct usb_composite_dev *cdev) { - gprinter_cleanup(); + usb_put_function(f_printer); + usb_put_function_instance(fi_printer); + return 0; } -- cgit v0.10.2 From d85dc4824c5793f4b71225d7ba5b50e737045830 Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Tue, 3 Mar 2015 10:52:30 +0100 Subject: usb: gadget: f_printer: remove compatibility layer There are no old interface users left, so it can be removed. Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/function/f_printer.c b/drivers/usb/gadget/function/f_printer.c index 93f4d4e..7afe17d 100644 --- a/drivers/usb/gadget/function/f_printer.c +++ b/drivers/usb/gadget/function/f_printer.c @@ -57,10 +57,8 @@ static int major, minors; static struct class *usb_gadget_class; -#ifndef USBF_PRINTER_INCLUDED static DEFINE_IDA(printer_ida); static DEFINE_MUTEX(printer_ida_lock); /* protects access do printer_ida */ -#endif /*-------------------------------------------------------------------------*/ @@ -1118,53 +1116,6 @@ fail_tx_reqs: } -#ifdef USBF_PRINTER_INCLUDED -static void printer_func_unbind(struct usb_configuration *c, - struct usb_function *f) -{ - struct printer_dev *dev; - struct usb_request *req; - - dev = func_to_printer(f); - - device_destroy(usb_gadget_class, MKDEV(major, dev->minor)); - - /* Remove Character Device */ - cdev_del(&dev->printer_cdev); - - /* we must already have been disconnected ... no i/o may be active */ - WARN_ON(!list_empty(&dev->tx_reqs_active)); - WARN_ON(!list_empty(&dev->rx_reqs_active)); - - /* Free all memory for this driver. */ - while (!list_empty(&dev->tx_reqs)) { - req = container_of(dev->tx_reqs.next, struct usb_request, - list); - list_del(&req->list); - printer_req_free(dev->in_ep, req); - } - - if (dev->current_rx_req != NULL) - printer_req_free(dev->out_ep, dev->current_rx_req); - - while (!list_empty(&dev->rx_reqs)) { - req = container_of(dev->rx_reqs.next, - struct usb_request, list); - list_del(&req->list); - printer_req_free(dev->out_ep, req); - } - - while (!list_empty(&dev->rx_buffers)) { - req = container_of(dev->rx_buffers.next, - struct usb_request, list); - list_del(&req->list); - printer_req_free(dev->out_ep, req); - } - usb_free_all_descriptors(f); - kfree(dev); -} -#endif - static int printer_func_set_alt(struct usb_function *f, unsigned intf, unsigned alt) { @@ -1189,68 +1140,6 @@ static void printer_func_disable(struct usb_function *f) spin_unlock_irqrestore(&dev->lock, flags); } -#ifdef USBF_PRINTER_INCLUDED -static int f_printer_bind_config(struct usb_configuration *c, char *pnp_str, - char *pnp_string, unsigned q_len, int minor) -{ - struct printer_dev *dev; - int status = -ENOMEM; - size_t len; - - if (minor >= minors) - return -ENOENT; - - dev = kzalloc(sizeof(*dev), GFP_KERNEL); - if (!dev) - return -ENOMEM; - - dev->pnp_string = pnp_string; - dev->minor = minor; - - dev->function.name = shortname; - dev->function.bind = printer_func_bind; - dev->function.setup = printer_func_setup; - dev->function.unbind = printer_func_unbind; - dev->function.set_alt = printer_func_set_alt; - dev->function.disable = printer_func_disable; - dev->function.req_match = gprinter_req_match; - INIT_LIST_HEAD(&dev->tx_reqs); - INIT_LIST_HEAD(&dev->rx_reqs); - INIT_LIST_HEAD(&dev->rx_buffers); - - if (pnp_str) - strlcpy(&dev->pnp_string[2], pnp_str, PNP_STRING_LEN - 2); - - len = strlen(pnp_string); - pnp_string[0] = (len >> 8) & 0xFF; - pnp_string[1] = len & 0xFF; - - spin_lock_init(&dev->lock); - mutex_init(&dev->lock_printer_io); - INIT_LIST_HEAD(&dev->tx_reqs_active); - INIT_LIST_HEAD(&dev->rx_reqs_active); - init_waitqueue_head(&dev->rx_wait); - init_waitqueue_head(&dev->tx_wait); - init_waitqueue_head(&dev->tx_flush_wait); - - dev->interface = -1; - dev->printer_cdev_open = 0; - dev->printer_status = PRINTER_NOT_ERROR; - dev->current_rx_req = NULL; - dev->current_rx_bytes = 0; - dev->current_rx_buf = NULL; - dev->q_len = q_len; - - status = usb_add_function(c, &dev->function); - if (status) { - kfree(dev); - return status; - } - - INFO(dev, "%s, version: " DRIVER_VERSION "\n", driver_desc); - return 0; -} -#else static inline int gprinter_get_minor(void) { return ida_simple_get(&printer_ida, 0, 0, GFP_KERNEL); @@ -1422,8 +1311,6 @@ DECLARE_USB_FUNCTION_INIT(printer, gprinter_alloc_inst, gprinter_alloc); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Craig Nadler"); -#endif - static int gprinter_setup(int count) { int status; -- cgit v0.10.2 From a2a8e48a94c78c72b5dd1e4c8d190c5c54aca7a4 Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Tue, 3 Mar 2015 10:52:31 +0100 Subject: usb: gadget: printer: use module_usb_composite_driver helper macro Substitute some boilerplate code with a dedicated macro. Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c index a8050f8..d5b6ee7 100644 --- a/drivers/usb/gadget/legacy/printer.c +++ b/drivers/usb/gadget/legacy/printer.c @@ -208,19 +208,7 @@ static __refdata struct usb_composite_driver printer_driver = { .unbind = printer_unbind, }; -static int __init -init(void) -{ - return usb_composite_probe(&printer_driver); -} -module_init(init); - -static void __exit -cleanup(void) -{ - usb_composite_unregister(&printer_driver); -} -module_exit(cleanup); +module_usb_composite_driver(printer_driver); MODULE_DESCRIPTION(DRIVER_DESC); MODULE_AUTHOR("Craig Nadler"); -- cgit v0.10.2 From ee1cd515e889d222f5a7397fead0a9db1214edea Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Tue, 3 Mar 2015 10:52:32 +0100 Subject: usb: gadget: printer: add configfs support Add support for configfs interface so that f_printer can be used as a component of usb gadgets composed with it. Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Felipe Balbi diff --git a/Documentation/ABI/testing/configfs-usb-gadget-printer b/Documentation/ABI/testing/configfs-usb-gadget-printer new file mode 100644 index 0000000..6b0714e --- /dev/null +++ b/Documentation/ABI/testing/configfs-usb-gadget-printer @@ -0,0 +1,9 @@ +What: /config/usb-gadget/gadget/functions/printer.name +Date: Apr 2015 +KernelVersion: 4.1 +Description: + The attributes: + + pnp_string - Data to be passed to the host in pnp string + q_len - Number of requests per endpoint + diff --git a/Documentation/usb/gadget-testing.txt b/Documentation/usb/gadget-testing.txt index 076ac7b..f45b2bf 100644 --- a/Documentation/usb/gadget-testing.txt +++ b/Documentation/usb/gadget-testing.txt @@ -19,6 +19,7 @@ provided by gadgets. 16. UAC1 function 17. UAC2 function 18. UVC function +19. PRINTER function 1. ACM function @@ -726,3 +727,49 @@ with these patches: http://www.spinics.net/lists/linux-usb/msg99220.html host: luvcview -f yuv + +19. PRINTER function +==================== + +The function is provided by usb_f_printer.ko module. + +Function-specific configfs interface +------------------------------------ + +The function name to use when creating the function directory is "printer". +The printer function provides these attributes in its function directory: + + pnp_string - Data to be passed to the host in pnp string + q_len - Number of requests per endpoint + +Testing the PRINTER function +---------------------------- + +The most basic testing: + +device: run the gadget +# ls -l /devices/virtual/usb_printer_gadget/ + +should show g_printer. + +If udev is active, then /dev/g_printer should appear automatically. + +host: + +If udev is active, then e.g. /dev/usb/lp0 should appear. + +host->device transmission: + +device: +# cat /dev/g_printer +host: +# cat > /dev/usb/lp0 + +device->host transmission: + +# cat > /dev/g_printer +host: +# cat /dev/usb/lp0 + +More advanced testing can be done with the prn_example +described in Documentation/usb/gadget-printer.txt. diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index 9d507cf..3bb0e67 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig @@ -437,6 +437,19 @@ config USB_CONFIGFS_F_UVC device. It provides a userspace API to process UVC control requests and stream video data to the host. +config USB_CONFIGFS_F_PRINTER + bool "Printer function" + select USB_F_PRINTER + help + The Printer function channels data between the USB host and a + userspace program driving the print engine. The user space + program reads and writes the device file /dev/g_printer to + receive or send printer data. It can use ioctl calls to + the device file to get or set printer status. + + For more information, see Documentation/usb/gadget_printer.txt + which includes sample code for accessing the device file. + source "drivers/usb/gadget/legacy/Kconfig" endchoice diff --git a/drivers/usb/gadget/function/f_printer.c b/drivers/usb/gadget/function/f_printer.c index 7afe17d..757fcf0 100644 --- a/drivers/usb/gadget/function/f_printer.c +++ b/drivers/usb/gadget/function/f_printer.c @@ -1140,6 +1140,117 @@ static void printer_func_disable(struct usb_function *f) spin_unlock_irqrestore(&dev->lock, flags); } +static inline struct f_printer_opts +*to_f_printer_opts(struct config_item *item) +{ + return container_of(to_config_group(item), struct f_printer_opts, + func_inst.group); +} + +CONFIGFS_ATTR_STRUCT(f_printer_opts); +CONFIGFS_ATTR_OPS(f_printer_opts); + +static void printer_attr_release(struct config_item *item) +{ + struct f_printer_opts *opts = to_f_printer_opts(item); + + usb_put_function_instance(&opts->func_inst); +} + +static struct configfs_item_operations printer_item_ops = { + .release = printer_attr_release, + .show_attribute = f_printer_opts_attr_show, + .store_attribute = f_printer_opts_attr_store, +}; + +static ssize_t f_printer_opts_pnp_string_show(struct f_printer_opts *opts, + char *page) +{ + int result; + + mutex_lock(&opts->lock); + result = strlcpy(page, opts->pnp_string + 2, PNP_STRING_LEN - 2); + mutex_unlock(&opts->lock); + + return result; +} + +static ssize_t f_printer_opts_pnp_string_store(struct f_printer_opts *opts, + const char *page, size_t len) +{ + int result, l; + + mutex_lock(&opts->lock); + result = strlcpy(opts->pnp_string + 2, page, PNP_STRING_LEN - 2); + l = strlen(opts->pnp_string + 2) + 2; + opts->pnp_string[0] = (l >> 8) & 0xFF; + opts->pnp_string[1] = l & 0xFF; + mutex_unlock(&opts->lock); + + return result; +} + +static struct f_printer_opts_attribute f_printer_opts_pnp_string = + __CONFIGFS_ATTR(pnp_string, S_IRUGO | S_IWUSR, + f_printer_opts_pnp_string_show, + f_printer_opts_pnp_string_store); + +static ssize_t f_printer_opts_q_len_show(struct f_printer_opts *opts, + char *page) +{ + int result; + + mutex_lock(&opts->lock); + result = sprintf(page, "%d\n", opts->q_len); + mutex_unlock(&opts->lock); + + return result; +} + +static ssize_t f_printer_opts_q_len_store(struct f_printer_opts *opts, + const char *page, size_t len) +{ + int ret; + u16 num; + + mutex_lock(&opts->lock); + if (opts->refcnt) { + ret = -EBUSY; + goto end; + } + + ret = kstrtou16(page, 0, &num); + if (ret) + goto end; + + if (num > 65535) { + ret = -EINVAL; + goto end; + } + + opts->q_len = (unsigned)num; + ret = len; +end: + mutex_unlock(&opts->lock); + return ret; +} + +static struct f_printer_opts_attribute f_printer_opts_q_len = + __CONFIGFS_ATTR(q_len, S_IRUGO | S_IWUSR, f_printer_opts_q_len_show, + f_printer_opts_q_len_store); + +static struct configfs_attribute *printer_attrs[] = { + &f_printer_opts_pnp_string.attr, + &f_printer_opts_q_len.attr, + NULL, +}; + +static struct config_item_type printer_func_type = { + .ct_item_ops = &printer_item_ops, + .ct_attrs = printer_attrs, + .ct_owner = THIS_MODULE, +}; + static inline int gprinter_get_minor(void) { return ida_simple_get(&printer_ida, 0, 0, GFP_KERNEL); @@ -1180,6 +1291,7 @@ static struct usb_function_instance *gprinter_alloc_inst(void) if (!opts) return ERR_PTR(-ENOMEM); + mutex_init(&opts->lock); opts->func_inst.free_func_inst = gprinter_free_inst; ret = &opts->func_inst; @@ -1201,6 +1313,8 @@ static struct usb_function_instance *gprinter_alloc_inst(void) if (idr_is_empty(&printer_ida.idr)) gprinter_cleanup(); } + config_group_init_type_name(&opts->func_inst.group, "", + &printer_func_type); unlock: mutex_unlock(&printer_ida_lock); @@ -1210,8 +1324,13 @@ unlock: static void gprinter_free(struct usb_function *f) { struct printer_dev *dev = func_to_printer(f); + struct f_printer_opts *opts; + opts = container_of(f->fi, struct f_printer_opts, func_inst); kfree(dev); + mutex_lock(&opts->lock); + --opts->refcnt; + mutex_unlock(&opts->lock); } static void printer_func_unbind(struct usb_configuration *c, @@ -1265,16 +1384,23 @@ static struct usb_function *gprinter_alloc(struct usb_function_instance *fi) opts = container_of(fi, struct f_printer_opts, func_inst); - if (opts->minor >= minors) + mutex_lock(&opts->lock); + if (opts->minor >= minors) { + mutex_unlock(&opts->lock); return ERR_PTR(-ENOENT); + } dev = kzalloc(sizeof(*dev), GFP_KERNEL); - if (!dev) + if (!dev) { + mutex_unlock(&opts->lock); return ERR_PTR(-ENOMEM); + } + ++opts->refcnt; dev->minor = opts->minor; dev->pnp_string = opts->pnp_string; dev->q_len = opts->q_len; + mutex_unlock(&opts->lock); dev->function.name = "printer"; dev->function.bind = printer_func_bind; diff --git a/drivers/usb/gadget/function/u_printer.h b/drivers/usb/gadget/function/u_printer.h index b2338ca..0e2c49d 100644 --- a/drivers/usb/gadget/function/u_printer.h +++ b/drivers/usb/gadget/function/u_printer.h @@ -25,6 +25,13 @@ struct f_printer_opts { int minor; char pnp_string[PNP_STRING_LEN]; unsigned q_len; + + /* + * Protect the data from concurrent access by read/write + * and create symlink/remove symlink + */ + struct mutex lock; + int refcnt; }; #endif /* U_PRINTER_H */ -- cgit v0.10.2 From 983f3cabf6677340dd5b9aec5440b427b8c47ad9 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Wed, 11 Mar 2015 10:18:40 -0500 Subject: usb: musb: dsps: request phy using our device pointer musb shouldn't have of_node and phy phandle is passed to dsps device, not musb's. Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c index baa757b..a528d3b 100644 --- a/drivers/usb/musb/musb_dsps.c +++ b/drivers/usb/musb/musb_dsps.c @@ -432,7 +432,7 @@ static int dsps_musb_init(struct musb *musb) musb->ctrl_base = reg_base; /* NOP driver needs change if supporting dual instance */ - musb->xceiv = devm_usb_get_phy_by_phandle(dev, "phys", 0); + musb->xceiv = devm_usb_get_phy_by_phandle(dev->parent, "phys", 0); if (IS_ERR(musb->xceiv)) return PTR_ERR(musb->xceiv); -- cgit v0.10.2 From 33c300cb90a6c0072507a949f78c4728238a81f0 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Tue, 10 Mar 2015 10:42:12 -0500 Subject: usb: musb: dsps: don't fake of_node to musb core If we pass our own of_node to musb_core, at least pinctrl settings will be duplicated, meaning that pinctrl framework will try to select default pin state for musb_core when they were already requested by musb-dsps. A Warning will be printed however things will still work. Reported-by: Tony Lindgren Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c index a528d3b..09648b4 100644 --- a/drivers/usb/musb/musb_dsps.c +++ b/drivers/usb/musb/musb_dsps.c @@ -697,7 +697,6 @@ static int dsps_create_musb_pdev(struct dsps_glue *glue, musb->dev.parent = dev; musb->dev.dma_mask = &musb_dmamask; musb->dev.coherent_dma_mask = musb_dmamask; - musb->dev.of_node = of_node_get(dn); glue->musb = musb; -- cgit v0.10.2 From 06ed0de5188c9ef6553b2824b6cdd767ad46ece5 Mon Sep 17 00:00:00 2001 From: Masanari Iida Date: Tue, 10 Mar 2015 22:37:46 +0900 Subject: usb: gadget: Fix typo fond in Documentation/Docbook/gadget.xml This patch fix some spelling typo found in gadget.xml. It is because this file is generated from comments in sources, I had to fix comments in the source, instead of xml file itself. Signed-off-by: Masanari Iida Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 4d25e11..4e3447b 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -1161,11 +1161,11 @@ static struct usb_gadget_string_container *copy_gadget_strings( * This function will create a deep copy of usb_gadget_strings and usb_string * and attach it to the cdev. The actual string (usb_string.s) will not be * copied but only a referenced will be made. The struct usb_gadget_strings - * array may contain multiple languges and should be NULL terminated. + * array may contain multiple languages and should be NULL terminated. * The ->language pointer of each struct usb_gadget_strings has to contain the * same amount of entries. * For instance: sp[0] is en-US, sp[1] is es-ES. It is expected that the first - * usb_string entry of es-ES containts the translation of the first usb_string + * usb_string entry of es-ES contains the translation of the first usb_string * entry of en-US. Therefore both entries become the same id assign. */ struct usb_string *usb_gstrings_attach(struct usb_composite_dev *cdev, diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h index e2f00fd..02476b3 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -190,7 +190,7 @@ struct usb_ep { * @ep:the endpoint being configured * @maxpacket_limit:value of maximum packet size limit * - * This function shoud be used only in UDC drivers to initialize endpoint + * This function should be used only in UDC drivers to initialize endpoint * (usually in probe function). */ static inline void usb_ep_set_maxpacket_limit(struct usb_ep *ep, -- cgit v0.10.2 From fddc26f573e28dde62013cd5d8d5c60aa85e74a4 Mon Sep 17 00:00:00 2001 From: Tal Shorer Date: Fri, 6 Mar 2015 21:53:32 +0200 Subject: usb: gadget: f_mass_storage: use defined constant instead of numeric value replace numeric value with TYPE_NO_LUN (defined in ) Signed-off-by: Tal Shorer Acked-by: Michal Nazarewicz Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c index 811929c..6d5ca2b 100644 --- a/drivers/usb/gadget/function/f_mass_storage.c +++ b/drivers/usb/gadget/function/f_mass_storage.c @@ -1085,7 +1085,7 @@ static int do_inquiry(struct fsg_common *common, struct fsg_buffhd *bh) if (!curlun) { /* Unsupported LUNs are okay */ common->bad_lun_okay = 1; memset(buf, 0, 36); - buf[0] = 0x7f; /* Unsupported, no device-type */ + buf[0] = TYPE_NO_LUN; /* Unsupported, no device-type */ buf[4] = 31; /* Additional length */ return 36; } -- cgit v0.10.2 From 2b08977b8dcb18c75b4972184c9ab54937119cba Mon Sep 17 00:00:00 2001 From: Mickael Maison Date: Sun, 8 Mar 2015 19:24:02 +0000 Subject: usb: phy: ab8500: fixed comment typo Fixed a comment typo in drivers/usb/phy/phy-ab8500-usb.c Signed-off-by: Mickael Maison Signed-off-by: Felipe Balbi diff --git a/drivers/usb/phy/phy-ab8500-usb.c b/drivers/usb/phy/phy-ab8500-usb.c index 0b1bd23..59cccfa 100644 --- a/drivers/usb/phy/phy-ab8500-usb.c +++ b/drivers/usb/phy/phy-ab8500-usb.c @@ -893,7 +893,7 @@ static int abx500_usb_link_status_update(struct ab8500_usb *ab) /* * Disconnection Sequence: - * 1. Disconect Interrupt + * 1. Disconnect Interrupt * 2. Disable regulators * 3. Disable AB clock * 4. Disable the Phy -- cgit v0.10.2 From 656e7c36bd70e115266cf280e0ff049506ceb16c Mon Sep 17 00:00:00 2001 From: Mickael Maison Date: Sun, 8 Mar 2015 19:26:52 +0000 Subject: usb: phy: fixed comment typo Fixed a comment typo in drivers/usb/phy/of.c Signed-off-by: Mickael Maison Signed-off-by: Felipe Balbi diff --git a/drivers/usb/phy/of.c b/drivers/usb/phy/of.c index 7ea0154..66ffa82 100644 --- a/drivers/usb/phy/of.c +++ b/drivers/usb/phy/of.c @@ -27,7 +27,7 @@ static const char *const usbphy_modes[] = { * @np: Pointer to the given device_node * * The function gets phy interface string from property 'phy_type', - * and returns the correspondig enum usb_phy_interface + * and returns the corresponding enum usb_phy_interface */ enum usb_phy_interface of_usb_get_phy_mode(struct device_node *np) { -- cgit v0.10.2 From 227ab58cff3c26ec279598112887d6bcca677a0c Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Thu, 12 Feb 2015 18:54:04 +0100 Subject: usb: gadget: atmel_usba_udc: Fixed vbus_prev initial state If vbus gpio is high at init, we should set vbus_prev to true accordingly to the current vbus state. Without that, we skip the first vbus interrupt because the saved vbus state is not consistent. Signed-off-by: Sylvain Rochet Acked-by: Nicolas Ferre Acked-by: Boris Brezillon Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c b/drivers/usb/gadget/udc/atmel_usba_udc.c index d79cb35..e63c6fc 100644 --- a/drivers/usb/gadget/udc/atmel_usba_udc.c +++ b/drivers/usb/gadget/udc/atmel_usba_udc.c @@ -1811,6 +1811,8 @@ static int atmel_usba_start(struct usb_gadget *gadget, toggle_bias(udc, 1); usba_writel(udc, CTRL, USBA_ENABLE_MASK); usba_int_enb_set(udc, USBA_END_OF_RESET); + + udc->vbus_prev = 1; } spin_unlock_irqrestore(&udc->lock, flags); -- cgit v0.10.2 From bb0a203c3a4e37b4bbb1f8ef55a855618dbba265 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Thu, 12 Feb 2015 18:54:05 +0100 Subject: usb: gadget: atmel_usba_udc: Request an auto disabled Vbus signal IRQ Vbus IRQ handler needs a started UDC driver to work because it uses udc->driver, which is set by the UDC start handler. The previous way chosen was to return from interrupt if udc->driver is NULL using a spinlock around the check. We now request an auto disabled (IRQ_NOAUTOEN) Vbus signal IRQ instead of an auto enabled IRQ followed by disable_irq(). This way we remove the very small timeslot of enabled IRQ which existed previously between request() and disable(). We don't need anymore to check if udc->driver is NULL in IRQ handler. Signed-off-by: Sylvain Rochet Suggested-by: Boris Brezillon Acked-by: Boris Brezillon Acked-by: Nicolas Ferre Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c b/drivers/usb/gadget/udc/atmel_usba_udc.c index e63c6fc..bbbd5f1 100644 --- a/drivers/usb/gadget/udc/atmel_usba_udc.c +++ b/drivers/usb/gadget/udc/atmel_usba_udc.c @@ -1749,10 +1749,6 @@ static irqreturn_t usba_vbus_irq(int irq, void *devid) spin_lock(&udc->lock); - /* May happen if Vbus pin toggles during probe() */ - if (!udc->driver) - goto out; - vbus = vbus_is_present(udc); if (vbus != udc->vbus_prev) { if (vbus) { @@ -1773,7 +1769,6 @@ static irqreturn_t usba_vbus_irq(int irq, void *devid) udc->vbus_prev = vbus; } -out: spin_unlock(&udc->lock); return IRQ_HANDLED; @@ -2113,6 +2108,8 @@ static int usba_udc_probe(struct platform_device *pdev) if (gpio_is_valid(udc->vbus_pin)) { if (!devm_gpio_request(&pdev->dev, udc->vbus_pin, "atmel_usba_udc")) { + irq_set_status_flags(gpio_to_irq(udc->vbus_pin), + IRQ_NOAUTOEN); ret = devm_request_irq(&pdev->dev, gpio_to_irq(udc->vbus_pin), usba_vbus_irq, 0, @@ -2122,8 +2119,6 @@ static int usba_udc_probe(struct platform_device *pdev) dev_warn(&udc->pdev->dev, "failed to request vbus irq; " "assuming always on\n"); - } else { - disable_irq(gpio_to_irq(udc->vbus_pin)); } } else { /* gpio_request fail so use -EINVAL for gpio_is_valid */ -- cgit v0.10.2 From a64ef71ddc13fc76a6f4af8c61e0106a62004380 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Thu, 12 Feb 2015 18:54:06 +0100 Subject: usb: gadget: atmel_usba_udc: condition clocks to vbus state If USB PLL is not necessary for other USB drivers (e.g. OHCI and EHCI) we will reduce power consumption by switching off the USB PLL if no USB Host is currently connected to this USB Device. We are using Vbus GPIO signal to detect Host presence. If Vbus signal is not available then the device stays continuously clocked. Signed-off-by: Sylvain Rochet Acked-by: Nicolas Ferre Acked-by: Boris Brezillon Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c b/drivers/usb/gadget/udc/atmel_usba_udc.c index bbbd5f1..999e2f2 100644 --- a/drivers/usb/gadget/udc/atmel_usba_udc.c +++ b/drivers/usb/gadget/udc/atmel_usba_udc.c @@ -1739,7 +1739,72 @@ static irqreturn_t usba_udc_irq(int irq, void *devid) return IRQ_HANDLED; } -static irqreturn_t usba_vbus_irq(int irq, void *devid) +static int start_clock(struct usba_udc *udc) +{ + int ret; + + if (udc->clocked) + return 0; + + ret = clk_prepare_enable(udc->pclk); + if (ret) + return ret; + ret = clk_prepare_enable(udc->hclk); + if (ret) { + clk_disable_unprepare(udc->pclk); + return ret; + } + + udc->clocked = true; + return 0; +} + +static void stop_clock(struct usba_udc *udc) +{ + if (!udc->clocked) + return; + + clk_disable_unprepare(udc->hclk); + clk_disable_unprepare(udc->pclk); + + udc->clocked = false; +} + +static int usba_start(struct usba_udc *udc) +{ + unsigned long flags; + int ret; + + ret = start_clock(udc); + if (ret) + return ret; + + spin_lock_irqsave(&udc->lock, flags); + toggle_bias(udc, 1); + usba_writel(udc, CTRL, USBA_ENABLE_MASK); + usba_int_enb_set(udc, USBA_END_OF_RESET); + spin_unlock_irqrestore(&udc->lock, flags); + + return 0; +} + +static void usba_stop(struct usba_udc *udc) +{ + unsigned long flags; + + spin_lock_irqsave(&udc->lock, flags); + udc->gadget.speed = USB_SPEED_UNKNOWN; + reset_all_endpoints(udc); + + /* This will also disable the DP pullup */ + toggle_bias(udc, 0); + usba_writel(udc, CTRL, USBA_DISABLE_MASK); + spin_unlock_irqrestore(&udc->lock, flags); + + stop_clock(udc); +} + +static irqreturn_t usba_vbus_irq_thread(int irq, void *devid) { struct usba_udc *udc = devid; int vbus; @@ -1747,30 +1812,22 @@ static irqreturn_t usba_vbus_irq(int irq, void *devid) /* debounce */ udelay(10); - spin_lock(&udc->lock); + mutex_lock(&udc->vbus_mutex); vbus = vbus_is_present(udc); if (vbus != udc->vbus_prev) { if (vbus) { - toggle_bias(udc, 1); - usba_writel(udc, CTRL, USBA_ENABLE_MASK); - usba_int_enb_set(udc, USBA_END_OF_RESET); + usba_start(udc); } else { - udc->gadget.speed = USB_SPEED_UNKNOWN; - reset_all_endpoints(udc); - toggle_bias(udc, 0); - usba_writel(udc, CTRL, USBA_DISABLE_MASK); - if (udc->driver->disconnect) { - spin_unlock(&udc->lock); + usba_stop(udc); + + if (udc->driver->disconnect) udc->driver->disconnect(&udc->gadget); - spin_lock(&udc->lock); - } } udc->vbus_prev = vbus; } - spin_unlock(&udc->lock); - + mutex_unlock(&udc->vbus_mutex); return IRQ_HANDLED; } @@ -1782,57 +1839,47 @@ static int atmel_usba_start(struct usb_gadget *gadget, unsigned long flags; spin_lock_irqsave(&udc->lock, flags); - udc->devstatus = 1 << USB_DEVICE_SELF_POWERED; udc->driver = driver; spin_unlock_irqrestore(&udc->lock, flags); - ret = clk_prepare_enable(udc->pclk); - if (ret) - return ret; - ret = clk_prepare_enable(udc->hclk); - if (ret) { - clk_disable_unprepare(udc->pclk); - return ret; - } + mutex_lock(&udc->vbus_mutex); - udc->vbus_prev = 0; if (gpio_is_valid(udc->vbus_pin)) enable_irq(gpio_to_irq(udc->vbus_pin)); /* If Vbus is present, enable the controller and wait for reset */ - spin_lock_irqsave(&udc->lock, flags); - if (vbus_is_present(udc) && udc->vbus_prev == 0) { - toggle_bias(udc, 1); - usba_writel(udc, CTRL, USBA_ENABLE_MASK); - usba_int_enb_set(udc, USBA_END_OF_RESET); - - udc->vbus_prev = 1; + udc->vbus_prev = vbus_is_present(udc); + if (udc->vbus_prev) { + ret = usba_start(udc); + if (ret) + goto err; } - spin_unlock_irqrestore(&udc->lock, flags); + mutex_unlock(&udc->vbus_mutex); return 0; + +err: + if (gpio_is_valid(udc->vbus_pin)) + disable_irq(gpio_to_irq(udc->vbus_pin)); + + mutex_unlock(&udc->vbus_mutex); + + spin_lock_irqsave(&udc->lock, flags); + udc->devstatus &= ~(1 << USB_DEVICE_SELF_POWERED); + udc->driver = NULL; + spin_unlock_irqrestore(&udc->lock, flags); + return ret; } static int atmel_usba_stop(struct usb_gadget *gadget) { struct usba_udc *udc = container_of(gadget, struct usba_udc, gadget); - unsigned long flags; if (gpio_is_valid(udc->vbus_pin)) disable_irq(gpio_to_irq(udc->vbus_pin)); - spin_lock_irqsave(&udc->lock, flags); - udc->gadget.speed = USB_SPEED_UNKNOWN; - reset_all_endpoints(udc); - spin_unlock_irqrestore(&udc->lock, flags); - - /* This will also disable the DP pullup */ - toggle_bias(udc, 0); - usba_writel(udc, CTRL, USBA_DISABLE_MASK); - - clk_disable_unprepare(udc->hclk); - clk_disable_unprepare(udc->pclk); + usba_stop(udc); udc->driver = NULL; @@ -2054,6 +2101,7 @@ static int usba_udc_probe(struct platform_device *pdev) return PTR_ERR(hclk); spin_lock_init(&udc->lock); + mutex_init(&udc->vbus_mutex); udc->pdev = pdev; udc->pclk = pclk; udc->hclk = hclk; @@ -2110,9 +2158,9 @@ static int usba_udc_probe(struct platform_device *pdev) if (!devm_gpio_request(&pdev->dev, udc->vbus_pin, "atmel_usba_udc")) { irq_set_status_flags(gpio_to_irq(udc->vbus_pin), IRQ_NOAUTOEN); - ret = devm_request_irq(&pdev->dev, - gpio_to_irq(udc->vbus_pin), - usba_vbus_irq, 0, + ret = devm_request_threaded_irq(&pdev->dev, + gpio_to_irq(udc->vbus_pin), NULL, + usba_vbus_irq_thread, IRQF_ONESHOT, "atmel_usba_udc", udc); if (ret) { udc->vbus_pin = -ENODEV; diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.h b/drivers/usb/gadget/udc/atmel_usba_udc.h index 497cd18..085749a 100644 --- a/drivers/usb/gadget/udc/atmel_usba_udc.h +++ b/drivers/usb/gadget/udc/atmel_usba_udc.h @@ -313,6 +313,9 @@ struct usba_udc { /* Protect hw registers from concurrent modifications */ spinlock_t lock; + /* Mutex to prevent concurrent start or stop */ + struct mutex vbus_mutex; + void __iomem *regs; void __iomem *fifo; @@ -328,6 +331,7 @@ struct usba_udc { struct clk *hclk; struct usba_ep *usba_ep; bool bias_pulse_needed; + bool clocked; u16 devstatus; -- cgit v0.10.2 From 112bf24471b50f806cbcbead7bd485da70401b83 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Thu, 12 Feb 2015 18:54:07 +0100 Subject: usb: gadget: atmel_usba_udc: Add suspend/resume with wakeup support This patch add suspend/resume with wakeup support for Atmel USBA. On suspend: We stay continuously clocked if Vbus signal is not available. If Vbus signal is available we set the Vbus signal as a wake up source then we stop the USBA itself and all clocks used by USBA. On resume: We recover clocks and USBA if we stopped them. If a device is currently connected at resume time we enable the controller. Signed-off-by: Sylvain Rochet Acked-by: Boris Brezillon Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c b/drivers/usb/gadget/udc/atmel_usba_udc.c index 999e2f2..d019b6c 100644 --- a/drivers/usb/gadget/udc/atmel_usba_udc.c +++ b/drivers/usb/gadget/udc/atmel_usba_udc.c @@ -2177,6 +2177,7 @@ static int usba_udc_probe(struct platform_device *pdev) ret = usb_add_gadget_udc(&pdev->dev, &udc->gadget); if (ret) return ret; + device_init_wakeup(&pdev->dev, 1); usba_init_debugfs(udc); for (i = 1; i < udc->num_ep; i++) @@ -2192,6 +2193,7 @@ static int __exit usba_udc_remove(struct platform_device *pdev) udc = platform_get_drvdata(pdev); + device_init_wakeup(&pdev->dev, 0); usb_del_gadget_udc(&udc->gadget); for (i = 1; i < udc->num_ep; i++) @@ -2201,10 +2203,65 @@ static int __exit usba_udc_remove(struct platform_device *pdev) return 0; } +#ifdef CONFIG_PM +static int usba_udc_suspend(struct device *dev) +{ + struct usba_udc *udc = dev_get_drvdata(dev); + + /* Not started */ + if (!udc->driver) + return 0; + + mutex_lock(&udc->vbus_mutex); + + if (!device_may_wakeup(dev)) { + usba_stop(udc); + goto out; + } + + /* + * Device may wake up. We stay clocked if we failed + * to request vbus irq, assuming always on. + */ + if (gpio_is_valid(udc->vbus_pin)) { + usba_stop(udc); + enable_irq_wake(gpio_to_irq(udc->vbus_pin)); + } + +out: + mutex_unlock(&udc->vbus_mutex); + return 0; +} + +static int usba_udc_resume(struct device *dev) +{ + struct usba_udc *udc = dev_get_drvdata(dev); + + /* Not started */ + if (!udc->driver) + return 0; + + if (device_may_wakeup(dev) && gpio_is_valid(udc->vbus_pin)) + disable_irq_wake(gpio_to_irq(udc->vbus_pin)); + + /* If Vbus is present, enable the controller and wait for reset */ + mutex_lock(&udc->vbus_mutex); + udc->vbus_prev = vbus_is_present(udc); + if (udc->vbus_prev) + usba_start(udc); + mutex_unlock(&udc->vbus_mutex); + + return 0; +} +#endif + +static SIMPLE_DEV_PM_OPS(usba_udc_pm_ops, usba_udc_suspend, usba_udc_resume); + static struct platform_driver udc_driver = { .remove = __exit_p(usba_udc_remove), .driver = { .name = "atmel_usba_udc", + .pm = &usba_udc_pm_ops, .of_match_table = of_match_ptr(atmel_udc_dt_ids), }, }; -- cgit v0.10.2 From fa84acf0f6142e7f35da785e25ee978518ff21ac Mon Sep 17 00:00:00 2001 From: Rasmus Villemoes Date: Fri, 6 Feb 2015 00:42:00 +0100 Subject: usb: gadget: dummy-hcd: Remove utf8 from format string Not everybody uses a utf8 locale (unfortunately), so let's avoid non-ascii characters in the kernel log. Replace the 3-byte utf8 sequence with a 3-byte ascii equivalent. Signed-off-by: Rasmus Villemoes Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/udc/dummy_hcd.c b/drivers/usb/gadget/udc/dummy_hcd.c index 8dda484..7592db7 100644 --- a/drivers/usb/gadget/udc/dummy_hcd.c +++ b/drivers/usb/gadget/udc/dummy_hcd.c @@ -2631,7 +2631,7 @@ static int __init init(void) return -EINVAL; if (mod_data.num < 1 || mod_data.num > MAX_NUM_UDC) { - pr_err("Number of emulated UDC must be in range of 1…%d\n", + pr_err("Number of emulated UDC must be in range of 1...%d\n", MAX_NUM_UDC); return -EINVAL; } -- cgit v0.10.2 From f4e4f8dae3753685e577143e8116cbac52f13cc4 Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Tue, 10 Feb 2015 17:30:36 +0100 Subject: usb: gadget: f_hid: remove unnecessary usb_ep_dequeue() Function usb_ep_disable() causes completion of all requests queued for given endpoint, so there is no need to dequeue them after endpoint disabling. Signed-off-by: Robert Baldyga Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c index a2612fb..13dfc99 100644 --- a/drivers/usb/gadget/function/f_hid.c +++ b/drivers/usb/gadget/function/f_hid.c @@ -908,7 +908,6 @@ static void hidg_unbind(struct usb_configuration *c, struct usb_function *f) /* disable/free request and end point */ usb_ep_disable(hidg->in_ep); - usb_ep_dequeue(hidg->in_ep, hidg->req); kfree(hidg->req->buf); usb_ep_free_request(hidg->in_ep, hidg->req); -- cgit v0.10.2 From 168bdb88c3ab1f66c061a6220c18939ef20ba42e Mon Sep 17 00:00:00 2001 From: Fabio Estevam Date: Tue, 3 Feb 2015 19:18:17 -0200 Subject: usb: phy: phy-generic: No need to call gpiod_direction_output() twice Commit 9eb0797722895f4309b4 ("usb: phy: generic: fix the gpios to be optional") calls gpiod_direction_output() in the probe function, so there is no need to call it again, as we can simply call gpiod_set_value() directly. Also, in usb_gen_phy_shutdown() we can simply put the GPIO directly in its active level state and this allows us to simplify the nop_reset function to treat only the reset case. Signed-off-by: Fabio Estevam Signed-off-by: Felipe Balbi diff --git a/drivers/usb/phy/phy-generic.c b/drivers/usb/phy/phy-generic.c index 70be50b..deee68e 100644 --- a/drivers/usb/phy/phy-generic.c +++ b/drivers/usb/phy/phy-generic.c @@ -62,14 +62,14 @@ static int nop_set_suspend(struct usb_phy *x, int suspend) return 0; } -static void nop_reset_set(struct usb_phy_generic *nop, int asserted) +static void nop_reset(struct usb_phy_generic *nop) { if (!nop->gpiod_reset) return; - gpiod_direction_output(nop->gpiod_reset, !asserted); + gpiod_set_value(nop->gpiod_reset, 1); usleep_range(10000, 20000); - gpiod_set_value(nop->gpiod_reset, asserted); + gpiod_set_value(nop->gpiod_reset, 0); } /* interface to regulator framework */ @@ -151,8 +151,7 @@ int usb_gen_phy_init(struct usb_phy *phy) if (!IS_ERR(nop->clk)) clk_prepare_enable(nop->clk); - /* De-assert RESET */ - nop_reset_set(nop, 0); + nop_reset(nop); return 0; } @@ -162,8 +161,7 @@ void usb_gen_phy_shutdown(struct usb_phy *phy) { struct usb_phy_generic *nop = dev_get_drvdata(phy->dev); - /* Assert RESET */ - nop_reset_set(nop, 1); + gpiod_set_value(nop->gpiod_reset, 1); if (!IS_ERR(nop->clk)) clk_disable_unprepare(nop->clk); -- cgit v0.10.2 From 72a472d2f912292457d6e3579df342c1138f26d5 Mon Sep 17 00:00:00 2001 From: Takeyoshi Kikuchi Date: Mon, 2 Mar 2015 11:03:51 +0900 Subject: usb: musb: cppi41: fix condition to call cppi41_trans_done(). connect AR9271(USB wifi) to AM335x, and send a flood ping from Mac OSX, AR9271 is stopped. on USB bus, the following occurs. - OUT transaction is ACKed (NYET). - IN transaction is ACKed (512bytes). - PING-NAK transaction is continued for about 2 seconds (AR9271 timeout?). In current imprementation, IN-transaction is not completed because it checks the empty of TX-FIFO in cppi41_dma_callback(). As a result, communication to AR9271 stops. This patch modified to check the empty of TX-FIFO only when OUT-transaction. Signed-off-by: Takeyoshi Kikuchi Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_cppi41.c b/drivers/usb/musb/musb_cppi41.c index 9dc45a4..8bd8c5e 100644 --- a/drivers/usb/musb/musb_cppi41.c +++ b/drivers/usb/musb/musb_cppi41.c @@ -250,8 +250,10 @@ static void cppi41_dma_callback(void *private_data) transferred < cppi41_channel->packet_sz) cppi41_channel->prog_len = 0; - empty = musb_is_tx_fifo_empty(hw_ep); - if (empty) { + if (cppi41_channel->is_tx) + empty = musb_is_tx_fifo_empty(hw_ep); + + if (!cppi41_channel->is_tx || empty) { cppi41_trans_done(cppi41_channel); goto out; } -- cgit v0.10.2 From 005a64307d5d3ef895e7821df4cad7739bab392e Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Wed, 11 Mar 2015 10:07:47 +0800 Subject: usb: gadget: lpc32xxx_udc: Fix NULL dereference udc is then checked for NULL, if NULL, it is then dereferenced as udc->dev, it is found using Coccinelle. We simplify the code to fix this problem, and we delete some conditions at if {} which will never be met. Reported-by: Tapasweni Pathak Reported-by : Julia Lawall Signed-off-by: Peter Chen Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/udc/lpc32xx_udc.c b/drivers/usb/gadget/udc/lpc32xx_udc.c index 27fd413..3b6a785 100644 --- a/drivers/usb/gadget/udc/lpc32xx_udc.c +++ b/drivers/usb/gadget/udc/lpc32xx_udc.c @@ -1803,23 +1803,14 @@ static int lpc32xx_ep_queue(struct usb_ep *_ep, req = container_of(_req, struct lpc32xx_request, req); ep = container_of(_ep, struct lpc32xx_ep, ep); - if (!_req || !_req->complete || !_req->buf || + if (!_ep || !_req || !_req->complete || !_req->buf || !list_empty(&req->queue)) return -EINVAL; udc = ep->udc; - if (!_ep) { - dev_dbg(udc->dev, "invalid ep\n"); - return -EINVAL; - } - - - if ((!udc) || (!udc->driver) || - (udc->gadget.speed == USB_SPEED_UNKNOWN)) { - dev_dbg(udc->dev, "invalid device\n"); - return -EINVAL; - } + if (udc->gadget.speed == USB_SPEED_UNKNOWN) + return -EPIPE; if (ep->lep) { struct lpc32xx_usbd_dd_gad *dd; -- cgit v0.10.2 From 9024c495f35be735a917571406fab30a789c27d1 Mon Sep 17 00:00:00 2001 From: John Youn Date: Tue, 3 Mar 2015 17:17:49 -0800 Subject: usb: dwc2: pci: Add device mode to the dwc2-pci driver The pci driver now registers a platform driver, like in dwc3, and lets its probe function do all the initialization. This allows it to account for changes to the platform driver that were not added to the pci driver. Also future changes to the probe function don't have to be duplicated. This also has the effect of adding device and DRD mode to the pci driver. Tested on the Synopsys HAPS PCIe platform. Signed-off-by: John Youn Signed-off-by: Felipe Balbi diff --git a/drivers/usb/dwc2/Kconfig b/drivers/usb/dwc2/Kconfig index 76b9ba4..3db204f 100644 --- a/drivers/usb/dwc2/Kconfig +++ b/drivers/usb/dwc2/Kconfig @@ -59,11 +59,12 @@ config USB_DWC2_PLATFORM config USB_DWC2_PCI tristate "DWC2 PCI" - depends on USB_DWC2_HOST && PCI - default USB_DWC2_HOST + depends on PCI + default n + select USB_DWC2_PLATFORM help The Designware USB2.0 PCI interface module for controllers - connected to a PCI bus. This is only used for host mode. + connected to a PCI bus. config USB_DWC2_DEBUG bool "Enable Debugging Messages" diff --git a/drivers/usb/dwc2/pci.c b/drivers/usb/dwc2/pci.c index 6646adb..ae41961 100644 --- a/drivers/usb/dwc2/pci.c +++ b/drivers/usb/dwc2/pci.c @@ -50,112 +50,97 @@ #include #include - -#include "core.h" -#include "hcd.h" +#include +#include #define PCI_PRODUCT_ID_HAPS_HSOTG 0xabc0 -static const char dwc2_driver_name[] = "dwc2"; - -static const struct dwc2_core_params dwc2_module_params = { - .otg_cap = -1, - .otg_ver = -1, - .dma_enable = -1, - .dma_desc_enable = 0, - .speed = -1, - .enable_dynamic_fifo = -1, - .en_multiple_tx_fifo = -1, - .host_rx_fifo_size = 1024, - .host_nperio_tx_fifo_size = 256, - .host_perio_tx_fifo_size = 1024, - .max_transfer_size = 65535, - .max_packet_count = 511, - .host_channels = -1, - .phy_type = -1, - .phy_utmi_width = -1, - .phy_ulpi_ddr = -1, - .phy_ulpi_ext_vbus = -1, - .i2c_enable = -1, - .ulpi_fs_ls = -1, - .host_support_fs_ls_low_power = -1, - .host_ls_low_power_phy_clk = -1, - .ts_dline = -1, - .reload_ctl = -1, - .ahbcfg = -1, - .uframe_sched = -1, +static const char dwc2_driver_name[] = "dwc2-pci"; + +struct dwc2_pci_glue { + struct platform_device *dwc2; + struct platform_device *phy; }; -/** - * dwc2_driver_remove() - Called when the DWC_otg core is unregistered with the - * DWC_otg driver - * - * @dev: Bus device - * - * This routine is called, for example, when the rmmod command is executed. The - * device may or may not be electrically present. If it is present, the driver - * stops device processing. Any resources used on behalf of this device are - * freed. - */ -static void dwc2_driver_remove(struct pci_dev *dev) +static void dwc2_pci_remove(struct pci_dev *pci) { - struct dwc2_hsotg *hsotg = pci_get_drvdata(dev); + struct dwc2_pci_glue *glue = pci_get_drvdata(pci); - dwc2_hcd_remove(hsotg); - pci_disable_device(dev); + platform_device_unregister(glue->dwc2); + usb_phy_generic_unregister(glue->phy); + kfree(glue); + pci_set_drvdata(pci, NULL); } -/** - * dwc2_driver_probe() - Called when the DWC_otg core is bound to the DWC_otg - * driver - * - * @dev: Bus device - * - * This routine creates the driver components required to control the device - * (core, HCD, and PCD) and initializes the device. The driver components are - * stored in a dwc2_hsotg structure. A reference to the dwc2_hsotg is saved - * in the device private data. This allows the driver to access the dwc2_hsotg - * structure on subsequent calls to driver methods for this device. - */ -static int dwc2_driver_probe(struct pci_dev *dev, - const struct pci_device_id *id) +static int dwc2_pci_probe(struct pci_dev *pci, + const struct pci_device_id *id) { - struct dwc2_hsotg *hsotg; - int retval; + struct resource res[2]; + struct platform_device *dwc2; + struct platform_device *phy; + int ret; + struct device *dev = &pci->dev; + struct dwc2_pci_glue *glue; + + ret = pcim_enable_device(pci); + if (ret) { + dev_err(dev, "failed to enable pci device\n"); + return -ENODEV; + } + + pci_set_master(pci); - hsotg = devm_kzalloc(&dev->dev, sizeof(*hsotg), GFP_KERNEL); - if (!hsotg) + dwc2 = platform_device_alloc("dwc2", PLATFORM_DEVID_AUTO); + if (!dwc2) { + dev_err(dev, "couldn't allocate dwc2 device\n"); return -ENOMEM; + } - hsotg->dev = &dev->dev; - hsotg->regs = devm_ioremap_resource(&dev->dev, &dev->resource[0]); - if (IS_ERR(hsotg->regs)) - return PTR_ERR(hsotg->regs); + memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res)); - dev_dbg(&dev->dev, "mapped PA %08lx to VA %p\n", - (unsigned long)pci_resource_start(dev, 0), hsotg->regs); + res[0].start = pci_resource_start(pci, 0); + res[0].end = pci_resource_end(pci, 0); + res[0].name = "dwc2"; + res[0].flags = IORESOURCE_MEM; - if (pci_enable_device(dev) < 0) - return -ENODEV; + res[1].start = pci->irq; + res[1].name = "dwc2"; + res[1].flags = IORESOURCE_IRQ; - pci_set_master(dev); + ret = platform_device_add_resources(dwc2, res, ARRAY_SIZE(res)); + if (ret) { + dev_err(dev, "couldn't add resources to dwc2 device\n"); + return ret; + } - retval = devm_request_irq(hsotg->dev, dev->irq, - dwc2_handle_common_intr, IRQF_SHARED, - dev_name(hsotg->dev), hsotg); - if (retval) - return retval; + dwc2->dev.parent = dev; - spin_lock_init(&hsotg->lock); - retval = dwc2_hcd_init(hsotg, dev->irq, &dwc2_module_params); - if (retval) { - pci_disable_device(dev); - return retval; + phy = usb_phy_generic_register(); + if (IS_ERR(phy)) { + dev_err(dev, "error registering generic PHY (%ld)\n", + PTR_ERR(phy)); + return PTR_ERR(phy); } - pci_set_drvdata(dev, hsotg); + ret = platform_device_add(dwc2); + if (ret) { + dev_err(dev, "failed to register dwc2 device\n"); + goto err; + } + + glue = kzalloc(sizeof(*glue), GFP_KERNEL); + if (!glue) + return -ENOMEM; + + glue->phy = phy; + glue->dwc2 = dwc2; + pci_set_drvdata(pci, glue); - return retval; + return 0; +err: + usb_phy_generic_unregister(phy); + platform_device_put(dwc2); + return ret; } static const struct pci_device_id dwc2_pci_ids[] = { @@ -173,8 +158,8 @@ MODULE_DEVICE_TABLE(pci, dwc2_pci_ids); static struct pci_driver dwc2_pci_driver = { .name = dwc2_driver_name, .id_table = dwc2_pci_ids, - .probe = dwc2_driver_probe, - .remove = dwc2_driver_remove, + .probe = dwc2_pci_probe, + .remove = dwc2_pci_remove, }; module_pci_driver(dwc2_pci_driver); -- cgit v0.10.2 From e39af88f18dfe9a7938765c97ce9ed448915e6d5 Mon Sep 17 00:00:00 2001 From: Marek Szyprowski Date: Tue, 10 Mar 2015 13:41:10 +0100 Subject: usb: dwc2: rework initialization of host and gadget in dual-role mode If device is configured to work only in HOST or DEVICE mode, there is no point in initializing both subdrivers. This patch also fixes resource leakage if host subdriver fails to initialize. Acked-by: John Youn Signed-off-by: Marek Szyprowski Signed-off-by: Felipe Balbi diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index f74304b..836c012 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h @@ -593,6 +593,8 @@ struct dwc2_hsotg { struct dwc2_core_params *core_params; enum usb_otg_state op_state; enum usb_dr_mode dr_mode; + unsigned int hcd_enabled:1; + unsigned int gadget_enabled:1; struct phy *phy; struct usb_phy *uphy; diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c index ae095f0..185663e 100644 --- a/drivers/usb/dwc2/platform.c +++ b/drivers/usb/dwc2/platform.c @@ -121,8 +121,10 @@ static int dwc2_driver_remove(struct platform_device *dev) { struct dwc2_hsotg *hsotg = platform_get_drvdata(dev); - dwc2_hcd_remove(hsotg); - s3c_hsotg_remove(hsotg); + if (hsotg->hcd_enabled) + dwc2_hcd_remove(hsotg); + if (hsotg->gadget_enabled) + s3c_hsotg_remove(hsotg); return 0; } @@ -234,12 +236,23 @@ static int dwc2_driver_probe(struct platform_device *dev) spin_lock_init(&hsotg->lock); mutex_init(&hsotg->init_mutex); - retval = dwc2_gadget_init(hsotg, irq); - if (retval) - return retval; - retval = dwc2_hcd_init(hsotg, irq, params); - if (retval) - return retval; + + if (hsotg->dr_mode != USB_DR_MODE_HOST) { + retval = dwc2_gadget_init(hsotg, irq); + if (retval) + return retval; + hsotg->gadget_enabled = 1; + } + + if (hsotg->dr_mode != USB_DR_MODE_PERIPHERAL) { + retval = dwc2_hcd_init(hsotg, irq, params); + if (retval) { + if (hsotg->gadget_enabled) + s3c_hsotg_remove(hsotg); + return retval; + } + hsotg->hcd_enabled = 1; + } platform_set_drvdata(dev, hsotg); -- cgit v0.10.2 From 16d9efa4b3db0ab69605ff4d03d707d0210f4bf7 Mon Sep 17 00:00:00 2001 From: Scott Wood Date: Thu, 12 Mar 2015 16:46:01 -0500 Subject: usb: gadget: serial: %pf is only for function pointers Use %ps for actual addresses, otherwise you'll get bad output on arches like ppc64 where %pf expects a function descriptor (which is not what __builtin_return_address returns). Reviewed-by: Fabio Estevam Signed-off-by: Scott Wood Cc: linux-usb@vger.kernel.org CC: Sergei Shtylyov Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c index 491082a..89179ab 100644 --- a/drivers/usb/gadget/function/u_serial.c +++ b/drivers/usb/gadget/function/u_serial.c @@ -912,7 +912,7 @@ static int gs_put_char(struct tty_struct *tty, unsigned char ch) unsigned long flags; int status; - pr_vdebug("gs_put_char: (%d,%p) char=0x%x, called from %pf\n", + pr_vdebug("gs_put_char: (%d,%p) char=0x%x, called from %ps\n", port->port_num, tty, ch, __builtin_return_address(0)); spin_lock_irqsave(&port->port_lock, flags); -- cgit v0.10.2 From d4ae02cc904d916ea6b292e61b79fd3497054067 Mon Sep 17 00:00:00 2001 From: John Youn Date: Thu, 12 Mar 2015 10:04:42 -0700 Subject: usb: dwc2: pci: Select the generic PHY for dwc2-pci driver The dwc2-pci driver requires the generic PHY. This fixes undefined reference issues when it is not selected. Reported-by: kbuild test robot Signed-off-by: John Youn Signed-off-by: Felipe Balbi diff --git a/drivers/usb/dwc2/Kconfig b/drivers/usb/dwc2/Kconfig index 3db204f..1bcb36a 100644 --- a/drivers/usb/dwc2/Kconfig +++ b/drivers/usb/dwc2/Kconfig @@ -62,6 +62,7 @@ config USB_DWC2_PCI depends on PCI default n select USB_DWC2_PLATFORM + select NOP_USB_XCEIV help The Designware USB2.0 PCI interface module for controllers connected to a PCI bus. -- cgit v0.10.2 From fdb51e3d97552413c851bf8426ef69508389df88 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Fri, 13 Mar 2015 12:11:06 +0300 Subject: usb: gadget: printer: delete some dead code "num" is a u16 so it can't go higher than 65535. kstrtou16() has a range check built in so this is already handled. Signed-off-by: Dan Carpenter Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/function/f_printer.c b/drivers/usb/gadget/function/f_printer.c index 757fcf0..caa56de 100644 --- a/drivers/usb/gadget/function/f_printer.c +++ b/drivers/usb/gadget/function/f_printer.c @@ -1223,11 +1223,6 @@ static ssize_t f_printer_opts_q_len_store(struct f_printer_opts *opts, if (ret) goto end; - if (num > 65535) { - ret = -EINVAL; - goto end; - } - opts->q_len = (unsigned)num; ret = len; end: -- cgit v0.10.2 From 2bb2077ee607703771c35ed74837180760f9ce07 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Fri, 13 Mar 2015 12:11:42 +0300 Subject: usb: gadget: printer: use after free in gprinter_alloc_inst() There was a missing goto so we free "opts" and then dereference it. Fixes: ee1cd515e889 ('usb: gadget: printer: add configfs support') Signed-off-by: Dan Carpenter Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/function/f_printer.c b/drivers/usb/gadget/function/f_printer.c index caa56de..48882ec 100644 --- a/drivers/usb/gadget/function/f_printer.c +++ b/drivers/usb/gadget/function/f_printer.c @@ -1307,6 +1307,7 @@ static struct usb_function_instance *gprinter_alloc_inst(void) kfree(opts); if (idr_is_empty(&printer_ida.idr)) gprinter_cleanup(); + goto unlock; } config_group_init_type_name(&opts->func_inst.group, "", &printer_func_type); -- cgit v0.10.2 From fbdecad99c3f37346ed868fec0c3a9c2809f78e9 Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Fri, 13 Mar 2015 11:08:08 +0100 Subject: usb: gadget: f_printer: use non-zero flag for bitwise and USB_DIR_OUT happens to be zero, so the result of bitwise and is always 0. Consequently, break will never happen in the SOFT_RESET case. This patch uses a compatible condition with a non-zero USB_DIR_IN, which might or might not evaluate to zero. Reported-by: Dan Carpenter Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/function/f_printer.c b/drivers/usb/gadget/function/f_printer.c index 48882ec..44173df 100644 --- a/drivers/usb/gadget/function/f_printer.c +++ b/drivers/usb/gadget/function/f_printer.c @@ -918,7 +918,7 @@ static bool gprinter_req_match(struct usb_function *f, return false; case SOFT_RESET: if (!w_value && !w_length && - (USB_DIR_OUT & ctrl->bRequestType)) + !(USB_DIR_IN & ctrl->bRequestType)) break; /* fall through */ default: -- cgit v0.10.2 From 7a96b78464bd8ba72c1c3095c543c1402db59e35 Mon Sep 17 00:00:00 2001 From: Yoshihiro Shimoda Date: Thu, 12 Mar 2015 15:35:18 +0900 Subject: usb: renesas_usbhs: add the channel number in dma-names To connect the channel of USB-DMAC to USBHS DnFIFO number, this patch adds this channel/FIFO number in dma-names. Otherwise, this driver needs to add analysis code for device tree. Signed-off-by: Yoshihiro Shimoda Signed-off-by: Felipe Balbi diff --git a/Documentation/devicetree/bindings/usb/renesas_usbhs.txt b/Documentation/devicetree/bindings/usb/renesas_usbhs.txt index 61b045b..dc2a18f 100644 --- a/Documentation/devicetree/bindings/usb/renesas_usbhs.txt +++ b/Documentation/devicetree/bindings/usb/renesas_usbhs.txt @@ -15,7 +15,10 @@ Optional properties: - phys: phandle + phy specifier pair - phy-names: must be "usb" - dmas: Must contain a list of references to DMA specifiers. - - dma-names : Must contain a list of DMA names, "tx" or "rx". + - dma-names : Must contain a list of DMA names: + - tx0 ... tx + - rx0 ... rx + - This means DnFIFO in USBHS module. Example: usbhs: usb@e6590000 { diff --git a/drivers/usb/renesas_usbhs/fifo.c b/drivers/usb/renesas_usbhs/fifo.c index d891bff..28d10eb 100644 --- a/drivers/usb/renesas_usbhs/fifo.c +++ b/drivers/usb/renesas_usbhs/fifo.c @@ -1069,23 +1069,29 @@ static void usbhsf_dma_init_pdev(struct usbhs_fifo *fifo) &fifo->rx_slave); } -static void usbhsf_dma_init_dt(struct device *dev, struct usbhs_fifo *fifo) +static void usbhsf_dma_init_dt(struct device *dev, struct usbhs_fifo *fifo, + int channel) { - fifo->tx_chan = dma_request_slave_channel_reason(dev, "tx"); + char name[16]; + + snprintf(name, sizeof(name), "tx%d", channel); + fifo->tx_chan = dma_request_slave_channel_reason(dev, name); if (IS_ERR(fifo->tx_chan)) fifo->tx_chan = NULL; - fifo->rx_chan = dma_request_slave_channel_reason(dev, "rx"); + + snprintf(name, sizeof(name), "rx%d", channel); + fifo->rx_chan = dma_request_slave_channel_reason(dev, name); if (IS_ERR(fifo->rx_chan)) fifo->rx_chan = NULL; } -static void usbhsf_dma_init(struct usbhs_priv *priv, - struct usbhs_fifo *fifo) +static void usbhsf_dma_init(struct usbhs_priv *priv, struct usbhs_fifo *fifo, + int channel) { struct device *dev = usbhs_priv_to_dev(priv); if (dev->of_node) - usbhsf_dma_init_dt(dev, fifo); + usbhsf_dma_init_dt(dev, fifo, channel); else usbhsf_dma_init_pdev(fifo); @@ -1231,7 +1237,7 @@ do { \ usbhs_get_dparam(priv, d##channel##_tx_id); \ fifo->rx_slave.shdma_slave.slave_id = \ usbhs_get_dparam(priv, d##channel##_rx_id); \ - usbhsf_dma_init(priv, fifo); \ + usbhsf_dma_init(priv, fifo, channel); \ } while (0) #define USBHS_DFIFO_INIT(priv, fifo, channel) \ -- cgit v0.10.2 From 9b53d9af7aac09cf249d72bfbf15f08e47c4f7fe Mon Sep 17 00:00:00 2001 From: Yoshihiro Shimoda Date: Thu, 12 Mar 2015 15:35:19 +0900 Subject: usb: renesas_usbhs: fix the sequence in xfer_work() This patch fixes the setup sequence in xfer_work(). Otherwise, sometimes a usb transaction will get stuck. Signed-off-by: Yoshihiro Shimoda Signed-off-by: Felipe Balbi diff --git a/drivers/usb/renesas_usbhs/fifo.c b/drivers/usb/renesas_usbhs/fifo.c index 28d10eb..b737661 100644 --- a/drivers/usb/renesas_usbhs/fifo.c +++ b/drivers/usb/renesas_usbhs/fifo.c @@ -822,10 +822,10 @@ static void xfer_work(struct work_struct *work) fifo->name, usbhs_pipe_number(pipe), pkt->length, pkt->zero); usbhs_pipe_running(pipe, 1); - usbhs_pipe_set_trans_count_if_bulk(pipe, pkt->trans); - usbhs_pipe_enable(pipe); usbhsf_dma_start(pipe, fifo); + usbhs_pipe_set_trans_count_if_bulk(pipe, pkt->trans); dma_async_issue_pending(chan); + usbhs_pipe_enable(pipe); } /* -- cgit v0.10.2 From ab330cf3888d8e0779fa05a243d53ba9f53a7ba9 Mon Sep 17 00:00:00 2001 From: Yoshihiro Shimoda Date: Thu, 12 Mar 2015 15:35:20 +0900 Subject: usb: renesas_usbhs: add support for USB-DMAC Some Renesas SoCs have the USB-DMAC. It is able to terminate transfers when a short packet is received, even if less bytes than the transfer counter size have been received. Also, it is able to send a short packet even if the packet size is not multiples of 8bytes. Since the previous code has used the interruption of USBHS controller when receiving packets even if this driver has used a dmac, a lot of interruptions has happened. This patch will reduce such interruptions. This patch allows to use the USB-DMAC on R-Car H2 and M2. Signed-off-by: Yoshihiro Shimoda Signed-off-by: Felipe Balbi diff --git a/drivers/usb/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c index 4cf77d3..0f7e850 100644 --- a/drivers/usb/renesas_usbhs/common.c +++ b/drivers/usb/renesas_usbhs/common.c @@ -276,6 +276,16 @@ int usbhs_set_device_config(struct usbhs_priv *priv, int devnum, } /* + * interrupt functions + */ +void usbhs_xxxsts_clear(struct usbhs_priv *priv, u16 sts_reg, u16 bit) +{ + u16 pipe_mask = (u16)GENMASK(usbhs_get_dparam(priv, pipe_size), 0); + + usbhs_write(priv, sts_reg, ~(1 << bit) & pipe_mask); +} + +/* * local functions */ static void usbhsc_set_buswait(struct usbhs_priv *priv) @@ -487,6 +497,15 @@ static struct renesas_usbhs_platform_info *usbhs_parse_dt(struct device *dev) if (gpio > 0) dparam->enable_gpio = gpio; + switch (dparam->type) { + case USBHS_TYPE_R8A7790: + case USBHS_TYPE_R8A7791: + dparam->has_usb_dmac = 1; + break; + default: + break; + } + return info; } diff --git a/drivers/usb/renesas_usbhs/common.h b/drivers/usb/renesas_usbhs/common.h index fc96e92..8c5fc12 100644 --- a/drivers/usb/renesas_usbhs/common.h +++ b/drivers/usb/renesas_usbhs/common.h @@ -193,6 +193,7 @@ struct usbhs_priv; #define TYPE_BULK (1 << 14) #define TYPE_INT (2 << 14) #define TYPE_ISO (3 << 14) +#define BFRE (1 << 10) /* BRDY Interrupt Operation Spec. */ #define DBLB (1 << 9) /* Double Buffer Mode */ #define SHTNAK (1 << 7) /* Pipe Disable in Transfer End */ #define DIR_OUT (1 << 4) /* Transfer Direction */ @@ -216,6 +217,7 @@ struct usbhs_priv; #define ACLRM (1 << 9) /* Buffer Auto-Clear Mode */ #define SQCLR (1 << 8) /* Toggle Bit Clear */ #define SQSET (1 << 7) /* Toggle Bit Set */ +#define SQMON (1 << 6) /* Toggle Bit Check */ #define PBUSY (1 << 5) /* Pipe Busy */ #define PID_MASK (0x3) /* Response PID */ #define PID_NAK 0 @@ -324,6 +326,11 @@ int usbhs_set_device_config(struct usbhs_priv *priv, int devnum, u16 upphub, u16 hubport, u16 speed); /* + * interrupt functions + */ +void usbhs_xxxsts_clear(struct usbhs_priv *priv, u16 sts_reg, u16 bit); + +/* * data */ struct usbhs_priv *usbhs_pdev_to_priv(struct platform_device *pdev); diff --git a/drivers/usb/renesas_usbhs/fifo.c b/drivers/usb/renesas_usbhs/fifo.c index b737661..8597cf9 100644 --- a/drivers/usb/renesas_usbhs/fifo.c +++ b/drivers/usb/renesas_usbhs/fifo.c @@ -813,7 +813,8 @@ static void xfer_work(struct work_struct *work) desc->callback = usbhsf_dma_complete; desc->callback_param = pipe; - if (dmaengine_submit(desc) < 0) { + pkt->cookie = dmaengine_submit(desc); + if (pkt->cookie < 0) { dev_err(dev, "Failed to submit dma descriptor\n"); return; } @@ -838,6 +839,7 @@ static int usbhsf_dma_prepare_push(struct usbhs_pkt *pkt, int *is_done) struct usbhs_fifo *fifo; int len = pkt->length - pkt->actual; int ret; + uintptr_t align_mask; if (usbhs_pipe_is_busy(pipe)) return 0; @@ -847,10 +849,14 @@ static int usbhsf_dma_prepare_push(struct usbhs_pkt *pkt, int *is_done) usbhs_pipe_is_dcp(pipe)) goto usbhsf_pio_prepare_push; - if (len & 0x7) /* 8byte alignment */ + /* check data length if this driver don't use USB-DMAC */ + if (!usbhs_get_dparam(priv, has_usb_dmac) && len & 0x7) goto usbhsf_pio_prepare_push; - if ((uintptr_t)(pkt->buf + pkt->actual) & 0x7) /* 8byte alignment */ + /* check buffer alignment */ + align_mask = usbhs_get_dparam(priv, has_usb_dmac) ? + USBHS_USB_DMAC_XFER_SIZE - 1 : 0x7; + if ((uintptr_t)(pkt->buf + pkt->actual) & align_mask) goto usbhsf_pio_prepare_push; /* return at this time if the pipe is running */ @@ -924,7 +930,85 @@ struct usbhs_pkt_handle usbhs_fifo_dma_push_handler = { /* * DMA pop handler */ -static int usbhsf_dma_try_pop(struct usbhs_pkt *pkt, int *is_done) + +static int usbhsf_dma_prepare_pop_with_rx_irq(struct usbhs_pkt *pkt, + int *is_done) +{ + return usbhsf_prepare_pop(pkt, is_done); +} + +static int usbhsf_dma_prepare_pop_with_usb_dmac(struct usbhs_pkt *pkt, + int *is_done) +{ + struct usbhs_pipe *pipe = pkt->pipe; + struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); + struct usbhs_fifo *fifo; + int ret; + + if (usbhs_pipe_is_busy(pipe)) + return 0; + + /* use PIO if packet is less than pio_dma_border or pipe is DCP */ + if ((pkt->length < usbhs_get_dparam(priv, pio_dma_border)) || + usbhs_pipe_is_dcp(pipe)) + goto usbhsf_pio_prepare_pop; + + fifo = usbhsf_get_dma_fifo(priv, pkt); + if (!fifo) + goto usbhsf_pio_prepare_pop; + + if ((uintptr_t)pkt->buf & (USBHS_USB_DMAC_XFER_SIZE - 1)) + goto usbhsf_pio_prepare_pop; + + usbhs_pipe_config_change_bfre(pipe, 1); + + ret = usbhsf_fifo_select(pipe, fifo, 0); + if (ret < 0) + goto usbhsf_pio_prepare_pop; + + if (usbhsf_dma_map(pkt) < 0) + goto usbhsf_pio_prepare_pop_unselect; + + /* DMA */ + + /* + * usbhs_fifo_dma_pop_handler :: prepare + * enabled irq to come here. + * but it is no longer needed for DMA. disable it. + */ + usbhsf_rx_irq_ctrl(pipe, 0); + + pkt->trans = pkt->length; + + INIT_WORK(&pkt->work, xfer_work); + schedule_work(&pkt->work); + + return 0; + +usbhsf_pio_prepare_pop_unselect: + usbhsf_fifo_unselect(pipe, fifo); +usbhsf_pio_prepare_pop: + + /* + * change handler to PIO + */ + pkt->handler = &usbhs_fifo_pio_pop_handler; + usbhs_pipe_config_change_bfre(pipe, 0); + + return pkt->handler->prepare(pkt, is_done); +} + +static int usbhsf_dma_prepare_pop(struct usbhs_pkt *pkt, int *is_done) +{ + struct usbhs_priv *priv = usbhs_pipe_to_priv(pkt->pipe); + + if (usbhs_get_dparam(priv, has_usb_dmac)) + return usbhsf_dma_prepare_pop_with_usb_dmac(pkt, is_done); + else + return usbhsf_dma_prepare_pop_with_rx_irq(pkt, is_done); +} + +static int usbhsf_dma_try_pop_with_rx_irq(struct usbhs_pkt *pkt, int *is_done) { struct usbhs_pipe *pipe = pkt->pipe; struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); @@ -993,7 +1077,16 @@ usbhsf_pio_prepare_pop: return pkt->handler->try_run(pkt, is_done); } -static int usbhsf_dma_pop_done(struct usbhs_pkt *pkt, int *is_done) +static int usbhsf_dma_try_pop(struct usbhs_pkt *pkt, int *is_done) +{ + struct usbhs_priv *priv = usbhs_pipe_to_priv(pkt->pipe); + + BUG_ON(usbhs_get_dparam(priv, has_usb_dmac)); + + return usbhsf_dma_try_pop_with_rx_irq(pkt, is_done); +} + +static int usbhsf_dma_pop_done_with_rx_irq(struct usbhs_pkt *pkt, int *is_done) { struct usbhs_pipe *pipe = pkt->pipe; int maxp = usbhs_pipe_get_maxpacket(pipe); @@ -1017,8 +1110,68 @@ static int usbhsf_dma_pop_done(struct usbhs_pkt *pkt, int *is_done) return 0; } +static size_t usbhs_dma_calc_received_size(struct usbhs_pkt *pkt, + struct dma_chan *chan, int dtln) +{ + struct usbhs_pipe *pipe = pkt->pipe; + struct dma_tx_state state; + size_t received_size; + int maxp = usbhs_pipe_get_maxpacket(pipe); + + dmaengine_tx_status(chan, pkt->cookie, &state); + received_size = pkt->length - state.residue; + + if (dtln) { + received_size -= USBHS_USB_DMAC_XFER_SIZE; + received_size &= ~(maxp - 1); + received_size += dtln; + } + + return received_size; +} + +static int usbhsf_dma_pop_done_with_usb_dmac(struct usbhs_pkt *pkt, + int *is_done) +{ + struct usbhs_pipe *pipe = pkt->pipe; + struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); + struct usbhs_fifo *fifo = usbhs_pipe_to_fifo(pipe); + struct dma_chan *chan = usbhsf_dma_chan_get(fifo, pkt); + int rcv_len; + + /* + * Since the driver disables rx_irq in DMA mode, the interrupt handler + * cannot the BRDYSTS. So, the function clears it here because the + * driver may use PIO mode next time. + */ + usbhs_xxxsts_clear(priv, BRDYSTS, usbhs_pipe_number(pipe)); + + rcv_len = usbhsf_fifo_rcv_len(priv, fifo); + usbhsf_fifo_clear(pipe, fifo); + pkt->actual = usbhs_dma_calc_received_size(pkt, chan, rcv_len); + + usbhsf_dma_stop(pipe, fifo); + usbhsf_dma_unmap(pkt); + usbhsf_fifo_unselect(pipe, pipe->fifo); + + /* The driver can assume the rx transaction is always "done" */ + *is_done = 1; + + return 0; +} + +static int usbhsf_dma_pop_done(struct usbhs_pkt *pkt, int *is_done) +{ + struct usbhs_priv *priv = usbhs_pipe_to_priv(pkt->pipe); + + if (usbhs_get_dparam(priv, has_usb_dmac)) + return usbhsf_dma_pop_done_with_usb_dmac(pkt, is_done); + else + return usbhsf_dma_pop_done_with_rx_irq(pkt, is_done); +} + struct usbhs_pkt_handle usbhs_fifo_dma_pop_handler = { - .prepare = usbhsf_prepare_pop, + .prepare = usbhsf_dma_prepare_pop, .try_run = usbhsf_dma_try_pop, .dma_done = usbhsf_dma_pop_done }; diff --git a/drivers/usb/renesas_usbhs/fifo.h b/drivers/usb/renesas_usbhs/fifo.h index f07037c1..04d3f8a 100644 --- a/drivers/usb/renesas_usbhs/fifo.h +++ b/drivers/usb/renesas_usbhs/fifo.h @@ -58,6 +58,7 @@ struct usbhs_pkt { struct usbhs_pkt *pkt); struct work_struct work; dma_addr_t dma; + dma_cookie_t cookie; void *buf; int length; int trans; diff --git a/drivers/usb/renesas_usbhs/pipe.c b/drivers/usb/renesas_usbhs/pipe.c index 007f45a..4f9c335 100644 --- a/drivers/usb/renesas_usbhs/pipe.c +++ b/drivers/usb/renesas_usbhs/pipe.c @@ -84,6 +84,17 @@ static void __usbhsp_pipe_xxx_set(struct usbhs_pipe *pipe, usbhs_bset(priv, pipe_reg, mask, val); } +static u16 __usbhsp_pipe_xxx_get(struct usbhs_pipe *pipe, + u16 dcp_reg, u16 pipe_reg) +{ + struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); + + if (usbhs_pipe_is_dcp(pipe)) + return usbhs_read(priv, dcp_reg); + else + return usbhs_read(priv, pipe_reg); +} + /* * DCPCFG/PIPECFG functions */ @@ -92,6 +103,11 @@ static void usbhsp_pipe_cfg_set(struct usbhs_pipe *pipe, u16 mask, u16 val) __usbhsp_pipe_xxx_set(pipe, DCPCFG, PIPECFG, mask, val); } +static u16 usbhsp_pipe_cfg_get(struct usbhs_pipe *pipe) +{ + return __usbhsp_pipe_xxx_get(pipe, DCPCFG, PIPECFG); +} + /* * PIPEnTRN/PIPEnTRE functions */ @@ -616,6 +632,11 @@ void usbhs_pipe_data_sequence(struct usbhs_pipe *pipe, int sequence) usbhsp_pipectrl_set(pipe, mask, val); } +static int usbhs_pipe_get_data_sequence(struct usbhs_pipe *pipe) +{ + return !!(usbhsp_pipectrl_get(pipe) & SQMON); +} + void usbhs_pipe_clear(struct usbhs_pipe *pipe) { if (usbhs_pipe_is_dcp(pipe)) { @@ -626,6 +647,24 @@ void usbhs_pipe_clear(struct usbhs_pipe *pipe) } } +void usbhs_pipe_config_change_bfre(struct usbhs_pipe *pipe, int enable) +{ + int sequence; + + if (usbhs_pipe_is_dcp(pipe)) + return; + + usbhsp_pipe_select(pipe); + /* check if the driver needs to change the BFRE value */ + if (!(enable ^ !!(usbhsp_pipe_cfg_get(pipe) & BFRE))) + return; + + sequence = usbhs_pipe_get_data_sequence(pipe); + usbhsp_pipe_cfg_set(pipe, BFRE, enable ? BFRE : 0); + usbhs_pipe_clear(pipe); + usbhs_pipe_data_sequence(pipe, sequence); +} + static struct usbhs_pipe *usbhsp_get_pipe(struct usbhs_priv *priv, u32 type) { struct usbhs_pipe *pos, *pipe; diff --git a/drivers/usb/renesas_usbhs/pipe.h b/drivers/usb/renesas_usbhs/pipe.h index d24a059..b0bc7b6 100644 --- a/drivers/usb/renesas_usbhs/pipe.h +++ b/drivers/usb/renesas_usbhs/pipe.h @@ -97,6 +97,7 @@ void usbhs_pipe_set_trans_count_if_bulk(struct usbhs_pipe *pipe, int len); void usbhs_pipe_select_fifo(struct usbhs_pipe *pipe, struct usbhs_fifo *fifo); void usbhs_pipe_config_update(struct usbhs_pipe *pipe, u16 devsel, u16 epnum, u16 maxp); +void usbhs_pipe_config_change_bfre(struct usbhs_pipe *pipe, int enable); #define usbhs_pipe_sequence_data0(pipe) usbhs_pipe_data_sequence(pipe, 0) #define usbhs_pipe_sequence_data1(pipe) usbhs_pipe_data_sequence(pipe, 1) diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h index 9fd9e48..f06529c 100644 --- a/include/linux/usb/renesas_usbhs.h +++ b/include/linux/usb/renesas_usbhs.h @@ -165,6 +165,8 @@ struct renesas_usbhs_driver_param { */ u32 has_otg:1; /* for controlling PWEN/EXTLP */ u32 has_sudmac:1; /* for SUDMAC */ + u32 has_usb_dmac:1; /* for USB-DMAC */ +#define USBHS_USB_DMAC_XFER_SIZE 32 /* hardcode the xfer size */ }; #define USBHS_TYPE_R8A7790 1 -- cgit v0.10.2 From 46f5cace1cd0559c335dfd4a5b8f57456d1bd6a1 Mon Sep 17 00:00:00 2001 From: Stephen Boyd Date: Fri, 13 Mar 2015 11:09:42 -0700 Subject: usb: phy: msm: Remove dead code This code is no longer used now that mach-msm has been removed. Delete it. Cc: Felipe Balbi Cc: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org Cc: David Brown Cc: Bryan Huntsman Cc: Daniel Walker Signed-off-by: Stephen Boyd Signed-off-by: Felipe Balbi diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig index 52d3d58..2fb3828 100644 --- a/drivers/usb/phy/Kconfig +++ b/drivers/usb/phy/Kconfig @@ -139,7 +139,7 @@ config USB_ISP1301 config USB_MSM_OTG tristate "Qualcomm on-chip USB OTG controller support" - depends on (USB || USB_GADGET) && (ARCH_MSM || ARCH_QCOM || COMPILE_TEST) + depends on (USB || USB_GADGET) && (ARCH_QCOM || COMPILE_TEST) depends on RESET_CONTROLLER select USB_PHY help diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c index 000fd89..b50c45c 100644 --- a/drivers/usb/phy/phy-msm-usb.c +++ b/drivers/usb/phy/phy-msm-usb.c @@ -263,9 +263,7 @@ static int msm_otg_link_clk_reset(struct msm_otg *motg, bool assert) { int ret; - if (motg->pdata->link_clk_reset) - ret = motg->pdata->link_clk_reset(motg->clk, assert); - else if (assert) + if (assert) ret = reset_control_assert(motg->link_rst); else ret = reset_control_deassert(motg->link_rst); @@ -281,9 +279,7 @@ static int msm_otg_phy_clk_reset(struct msm_otg *motg) { int ret = 0; - if (motg->pdata->phy_clk_reset) - ret = motg->pdata->phy_clk_reset(motg->phy_reset_clk); - else if (motg->phy_rst) + if (motg->phy_rst) ret = reset_control_reset(motg->phy_rst); if (ret) @@ -1551,16 +1547,6 @@ static int msm_otg_probe(struct platform_device *pdev) phy = &motg->phy; phy->dev = &pdev->dev; - if (motg->pdata->phy_clk_reset) { - motg->phy_reset_clk = devm_clk_get(&pdev->dev, - np ? "phy" : "usb_phy_clk"); - - if (IS_ERR(motg->phy_reset_clk)) { - dev_err(&pdev->dev, "failed to get usb_phy_clk\n"); - return PTR_ERR(motg->phy_reset_clk); - } - } - motg->clk = devm_clk_get(&pdev->dev, np ? "core" : "usb_hs_clk"); if (IS_ERR(motg->clk)) { dev_err(&pdev->dev, "failed to get usb_hs_clk\n"); diff --git a/include/linux/usb/msm_hsusb.h b/include/linux/usb/msm_hsusb.h index b0a3924..7dbecf9 100644 --- a/include/linux/usb/msm_hsusb.h +++ b/include/linux/usb/msm_hsusb.h @@ -117,8 +117,6 @@ struct msm_otg_platform_data { enum otg_control_type otg_control; enum msm_usb_phy_type phy_type; void (*setup_gpio)(enum usb_otg_state state); - int (*link_clk_reset)(struct clk *link_clk, bool assert); - int (*phy_clk_reset)(struct clk *phy_clk); }; /** @@ -128,7 +126,6 @@ struct msm_otg_platform_data { * @irq: IRQ number assigned for HSUSB controller. * @clk: clock struct of usb_hs_clk. * @pclk: clock struct of usb_hs_pclk. - * @phy_reset_clk: clock struct of usb_phy_clk. * @core_clk: clock struct of usb_hs_core_clk. * @regs: ioremapped register base address. * @inputs: OTG state machine inputs(Id, SessValid etc). @@ -148,7 +145,6 @@ struct msm_otg { int irq; struct clk *clk; struct clk *pclk; - struct clk *phy_reset_clk; struct clk *core_clk; void __iomem *regs; #define ID 0 -- cgit v0.10.2 From d5d1e1bed4da02bd7a2352ab495721e31a7d95e4 Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Wed, 11 Feb 2015 12:44:41 +0800 Subject: usb: chipidea: udc: return immediately if re-enable non-empty endpoint Some gadget driver (like uac1) will try to enable endpoint again even the ep is not empty, it will cause the ep reset again and may affect the dTD list which has already queued. It returns -EBUSY immediately, and indicate the endpoint is in use. In this way, the ep's behavior will not be affected, and the gadget driver is also notified. Cc: Xuebing Wang Signed-off-by: Peter Chen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c index ff45104..5244542 100644 --- a/drivers/usb/chipidea/udc.c +++ b/drivers/usb/chipidea/udc.c @@ -1151,10 +1151,13 @@ static int ep_enable(struct usb_ep *ep, /* only internal SW should enable ctrl endpts */ - hwep->ep.desc = desc; - - if (!list_empty(&hwep->qh.queue)) + if (!list_empty(&hwep->qh.queue)) { dev_warn(hwep->ci->dev, "enabling a non-empty endpoint!\n"); + spin_unlock_irqrestore(hwep->lock, flags); + return -EBUSY; + } + + hwep->ep.desc = desc; hwep->dir = usb_endpoint_dir_in(desc) ? TX : RX; hwep->num = usb_endpoint_num(desc); -- cgit v0.10.2 From 560400875d56d6e5f589a25319febcb32238f004 Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Wed, 11 Feb 2015 12:44:42 +0800 Subject: usb: chipidea: imx: using common platform flag directly It is meaningless the glue layer driver has its own platform flag which is the same meaning with common platform flag. Signed-off-by: Peter Chen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c index 0f05de7..4216510 100644 --- a/drivers/usb/chipidea/ci_hdrc_imx.c +++ b/drivers/usb/chipidea/ci_hdrc_imx.c @@ -23,8 +23,6 @@ #include "ci.h" #include "ci_hdrc_imx.h" -#define CI_HDRC_IMX_IMX28_WRITE_FIX BIT(0) - struct ci_hdrc_imx_platform_flag { unsigned int flags; }; @@ -33,7 +31,7 @@ static const struct ci_hdrc_imx_platform_flag imx27_usb_data = { }; static const struct ci_hdrc_imx_platform_flag imx28_usb_data = { - .flags = CI_HDRC_IMX_IMX28_WRITE_FIX, + .flags = CI_HDRC_IMX28_WRITE_FIX, }; static const struct of_device_id ci_hdrc_imx_dt_ids[] = { @@ -145,9 +143,7 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev) } pdata.usb_phy = data->phy; - - if (imx_platform_flag->flags & CI_HDRC_IMX_IMX28_WRITE_FIX) - pdata.flags |= CI_HDRC_IMX28_WRITE_FIX; + pdata.flags |= imx_platform_flag->flags; ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); if (ret) -- cgit v0.10.2 From 73dea4a912b2bfe955305de4891018f9e71e399d Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Wed, 11 Feb 2015 12:44:43 +0800 Subject: usb: chipidea: usbmisc_imx: delete clock information All imx usb controller's non core registers uses the same clock gate with core registers, the usbmisc_imx is the library for imx glue driver, the glue keeps clock on when it calls usbmisc_imx API to change non-core register. Besides, we will support runtime pm in the future, it also needs to close this clock when the usb is not in use. Philipp Zabel also verifies it at imx6q platform, see http://www.spinics.net/lists/linux-usb/msg118491.html Cc: Philipp Zabel Signed-off-by: Peter Chen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/chipidea/usbmisc_imx.c b/drivers/usb/chipidea/usbmisc_imx.c index c3c6225..9385602 100644 --- a/drivers/usb/chipidea/usbmisc_imx.c +++ b/drivers/usb/chipidea/usbmisc_imx.c @@ -11,7 +11,6 @@ #include #include -#include #include #include #include @@ -69,7 +68,6 @@ struct usbmisc_ops { struct imx_usbmisc { void __iomem *base; spinlock_t lock; - struct clk *clk; const struct usbmisc_ops *ops; }; @@ -322,7 +320,6 @@ static int usbmisc_imx_probe(struct platform_device *pdev) { struct resource *res; struct imx_usbmisc *data; - int ret; struct of_device_id *tmp_dev; data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); @@ -336,20 +333,6 @@ static int usbmisc_imx_probe(struct platform_device *pdev) if (IS_ERR(data->base)) return PTR_ERR(data->base); - data->clk = devm_clk_get(&pdev->dev, NULL); - if (IS_ERR(data->clk)) { - dev_err(&pdev->dev, - "failed to get clock, err=%ld\n", PTR_ERR(data->clk)); - return PTR_ERR(data->clk); - } - - ret = clk_prepare_enable(data->clk); - if (ret) { - dev_err(&pdev->dev, - "clk_prepare_enable failed, err=%d\n", ret); - return ret; - } - tmp_dev = (struct of_device_id *) of_match_device(usbmisc_imx_dt_ids, &pdev->dev); data->ops = (const struct usbmisc_ops *)tmp_dev->data; @@ -360,8 +343,6 @@ static int usbmisc_imx_probe(struct platform_device *pdev) static int usbmisc_imx_remove(struct platform_device *pdev) { - struct imx_usbmisc *usbmisc = dev_get_drvdata(&pdev->dev); - clk_disable_unprepare(usbmisc->clk); return 0; } -- cgit v0.10.2 From a4cf1b14cfbc57a12ea2d997b93735a99f70d810 Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Wed, 11 Feb 2015 12:44:44 +0800 Subject: usb: chipidea: imx: simplify the usbmisc callers Move struct imx_usbmisc_data NULL pointer judgement from caller to each API, it can simplify the caller. Signed-off-by: Peter Chen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c index 4216510..353989e 100644 --- a/drivers/usb/chipidea/ci_hdrc_imx.c +++ b/drivers/usb/chipidea/ci_hdrc_imx.c @@ -149,13 +149,10 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev) if (ret) goto err_clk; - if (data->usbmisc_data) { - ret = imx_usbmisc_init(data->usbmisc_data); - if (ret) { - dev_err(&pdev->dev, "usbmisc init failed, ret=%d\n", - ret); - goto err_clk; - } + ret = imx_usbmisc_init(data->usbmisc_data); + if (ret) { + dev_err(&pdev->dev, "usbmisc init failed, ret=%d\n", ret); + goto err_clk; } data->ci_pdev = ci_hdrc_add_device(&pdev->dev, @@ -169,13 +166,10 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev) goto err_clk; } - if (data->usbmisc_data) { - ret = imx_usbmisc_init_post(data->usbmisc_data); - if (ret) { - dev_err(&pdev->dev, "usbmisc post failed, ret=%d\n", - ret); - goto disable_device; - } + ret = imx_usbmisc_init_post(data->usbmisc_data); + if (ret) { + dev_err(&pdev->dev, "usbmisc post failed, ret=%d\n", ret); + goto disable_device; } platform_set_drvdata(pdev, data); diff --git a/drivers/usb/chipidea/usbmisc_imx.c b/drivers/usb/chipidea/usbmisc_imx.c index 9385602..eb77e32 100644 --- a/drivers/usb/chipidea/usbmisc_imx.c +++ b/drivers/usb/chipidea/usbmisc_imx.c @@ -265,8 +265,12 @@ static const struct usbmisc_ops vf610_usbmisc_ops = { int imx_usbmisc_init(struct imx_usbmisc_data *data) { - struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); + struct imx_usbmisc *usbmisc; + + if (!data) + return 0; + usbmisc = dev_get_drvdata(data->dev); if (!usbmisc->ops->init) return 0; return usbmisc->ops->init(data); @@ -275,8 +279,12 @@ EXPORT_SYMBOL_GPL(imx_usbmisc_init); int imx_usbmisc_init_post(struct imx_usbmisc_data *data) { - struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); + struct imx_usbmisc *usbmisc; + + if (!data) + return 0; + usbmisc = dev_get_drvdata(data->dev); if (!usbmisc->ops->post) return 0; return usbmisc->ops->post(data); -- cgit v0.10.2 From 1f874edcb7318c5dd71025df9f3849715b4e4f71 Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Wed, 11 Feb 2015 12:44:45 +0800 Subject: usb: chipidea: add runtime power management support Add runtime power management support. Signed-off-by: Peter Chen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h index 65913d4..a0aeb8d 100644 --- a/drivers/usb/chipidea/ci.h +++ b/drivers/usb/chipidea/ci.h @@ -169,6 +169,9 @@ struct hw_bank { * @b_sess_valid_event: indicates there is a vbus event, and handled * at ci_otg_work * @imx28_write_fix: Freescale imx28 needs swp instruction for writing + * @supports_runtime_pm: if runtime pm is supported + * @in_lpm: if the core in low power mode + * @wakeup_int: if wakeup interrupt occur */ struct ci_hdrc { struct device *dev; @@ -211,6 +214,9 @@ struct ci_hdrc { bool id_event; bool b_sess_valid_event; bool imx28_write_fix; + bool supports_runtime_pm; + bool in_lpm; + bool wakeup_int; }; static inline struct ci_role_driver *ci_role(struct ci_hdrc *ci) diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c index a57dc88..63d2b39 100644 --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c @@ -491,6 +491,13 @@ static irqreturn_t ci_irq(int irq, void *data) irqreturn_t ret = IRQ_NONE; u32 otgsc = 0; + if (ci->in_lpm) { + disable_irq_nosync(irq); + ci->wakeup_int = true; + pm_runtime_get(ci->dev); + return IRQ_HANDLED; + } + if (ci->is_otg) { otgsc = hw_read_otgsc(ci, ~0); if (ci_otg_is_fsm_mode(ci)) { @@ -673,6 +680,8 @@ static int ci_hdrc_probe(struct platform_device *pdev) ci->platdata = dev_get_platdata(dev); ci->imx28_write_fix = !!(ci->platdata->flags & CI_HDRC_IMX28_WRITE_FIX); + ci->supports_runtime_pm = !!(ci->platdata->flags & + CI_HDRC_SUPPORTS_RUNTIME_PM); ret = hw_device_init(ci, base); if (ret < 0) { @@ -788,6 +797,14 @@ static int ci_hdrc_probe(struct platform_device *pdev) if (ret) goto stop; + if (ci->supports_runtime_pm) { + pm_runtime_set_active(&pdev->dev); + pm_runtime_enable(&pdev->dev); + pm_runtime_set_autosuspend_delay(&pdev->dev, 2000); + pm_runtime_mark_last_busy(ci->dev); + pm_runtime_use_autosuspend(&pdev->dev); + } + if (ci_otg_is_fsm_mode(ci)) ci_hdrc_otg_fsm_start(ci); @@ -807,6 +824,12 @@ static int ci_hdrc_remove(struct platform_device *pdev) { struct ci_hdrc *ci = platform_get_drvdata(pdev); + if (ci->supports_runtime_pm) { + pm_runtime_get_sync(&pdev->dev); + pm_runtime_disable(&pdev->dev); + pm_runtime_put_noidle(&pdev->dev); + } + dbg_remove_files(ci); ci_role_destroy(ci); ci_hdrc_enter_lpm(ci, true); @@ -815,13 +838,14 @@ static int ci_hdrc_remove(struct platform_device *pdev) return 0; } -#ifdef CONFIG_PM_SLEEP +#ifdef CONFIG_PM static void ci_controller_suspend(struct ci_hdrc *ci) { + disable_irq(ci->irq); ci_hdrc_enter_lpm(ci, true); - - if (ci->usb_phy) - usb_phy_set_suspend(ci->usb_phy, 1); + usb_phy_set_suspend(ci->usb_phy, 1); + ci->in_lpm = true; + enable_irq(ci->irq); } static int ci_controller_resume(struct device *dev) @@ -830,23 +854,49 @@ static int ci_controller_resume(struct device *dev) dev_dbg(dev, "at %s\n", __func__); - ci_hdrc_enter_lpm(ci, false); + if (!ci->in_lpm) { + WARN_ON(1); + return 0; + } + ci_hdrc_enter_lpm(ci, false); if (ci->usb_phy) { usb_phy_set_suspend(ci->usb_phy, 0); usb_phy_set_wakeup(ci->usb_phy, false); hw_wait_phy_stable(); } + ci->in_lpm = false; + if (ci->wakeup_int) { + ci->wakeup_int = false; + pm_runtime_mark_last_busy(ci->dev); + pm_runtime_put_autosuspend(ci->dev); + enable_irq(ci->irq); + } + return 0; } +#ifdef CONFIG_PM_SLEEP static int ci_suspend(struct device *dev) { struct ci_hdrc *ci = dev_get_drvdata(dev); if (ci->wq) flush_workqueue(ci->wq); + /* + * Controller needs to be active during suspend, otherwise the core + * may run resume when the parent is at suspend if other driver's + * suspend fails, it occurs before parent's suspend has not started, + * but the core suspend has finished. + */ + if (ci->in_lpm) + pm_runtime_resume(dev); + + if (ci->in_lpm) { + WARN_ON(1); + return 0; + } ci_controller_suspend(ci); @@ -855,13 +905,51 @@ static int ci_suspend(struct device *dev) static int ci_resume(struct device *dev) { - return ci_controller_resume(dev); + struct ci_hdrc *ci = dev_get_drvdata(dev); + int ret; + + ret = ci_controller_resume(dev); + if (ret) + return ret; + + if (ci->supports_runtime_pm) { + pm_runtime_disable(dev); + pm_runtime_set_active(dev); + pm_runtime_enable(dev); + } + + return ret; } #endif /* CONFIG_PM_SLEEP */ +static int ci_runtime_suspend(struct device *dev) +{ + struct ci_hdrc *ci = dev_get_drvdata(dev); + + dev_dbg(dev, "at %s\n", __func__); + + if (ci->in_lpm) { + WARN_ON(1); + return 0; + } + + usb_phy_set_wakeup(ci->usb_phy, true); + ci_controller_suspend(ci); + + return 0; +} + +static int ci_runtime_resume(struct device *dev) +{ + return ci_controller_resume(dev); +} + +#endif /* CONFIG_PM */ static const struct dev_pm_ops ci_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(ci_suspend, ci_resume) + SET_RUNTIME_PM_OPS(ci_runtime_suspend, ci_runtime_resume, NULL) }; + static struct platform_driver ci_hdrc_driver = { .probe = ci_hdrc_probe, .remove = ci_hdrc_remove, diff --git a/drivers/usb/chipidea/otg.c b/drivers/usb/chipidea/otg.c index a048b08..ad6c87a 100644 --- a/drivers/usb/chipidea/otg.c +++ b/drivers/usb/chipidea/otg.c @@ -96,6 +96,7 @@ static void ci_otg_work(struct work_struct *work) return; } + pm_runtime_get_sync(ci->dev); if (ci->id_event) { ci->id_event = false; ci_handle_id_switch(ci); @@ -104,6 +105,7 @@ static void ci_otg_work(struct work_struct *work) ci_handle_vbus_change(ci); } else dev_err(ci->dev, "unexpected event occurs at %s\n", __func__); + pm_runtime_put_sync(ci->dev); enable_irq(ci->irq); } diff --git a/include/linux/usb/chipidea.h b/include/linux/usb/chipidea.h index 535997a..39ba00f 100644 --- a/include/linux/usb/chipidea.h +++ b/include/linux/usb/chipidea.h @@ -19,6 +19,7 @@ struct ci_hdrc_platform_data { enum usb_phy_interface phy_mode; unsigned long flags; #define CI_HDRC_REGS_SHARED BIT(0) +#define CI_HDRC_SUPPORTS_RUNTIME_PM BIT(2) #define CI_HDRC_DISABLE_STREAMING BIT(3) /* * Only set it when DCCPARAMS.DC==1 and DCCPARAMS.HC==1, -- cgit v0.10.2 From f636cec559c6c01d6a262123446a142e1ae66890 Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Wed, 11 Feb 2015 12:44:46 +0800 Subject: usb: chipidea: usbmisc_imx: add .set_wakeup interface This API is used to enable/disable usb wakeup, only imx6 series are added, since I don't have other imx hardware on hand. Other imx users can add their API according to reference manual after testing. Signed-off-by: Peter Chen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/chipidea/ci_hdrc_imx.h b/drivers/usb/chipidea/ci_hdrc_imx.h index 4ed828f..635717e 100644 --- a/drivers/usb/chipidea/ci_hdrc_imx.h +++ b/drivers/usb/chipidea/ci_hdrc_imx.h @@ -22,5 +22,6 @@ struct imx_usbmisc_data { int imx_usbmisc_init(struct imx_usbmisc_data *); int imx_usbmisc_init_post(struct imx_usbmisc_data *); +int imx_usbmisc_set_wakeup(struct imx_usbmisc_data *, bool); #endif /* __DRIVER_USB_CHIPIDEA_CI_HDRC_IMX_H */ diff --git a/drivers/usb/chipidea/usbmisc_imx.c b/drivers/usb/chipidea/usbmisc_imx.c index eb77e32..90b7d7f 100644 --- a/drivers/usb/chipidea/usbmisc_imx.c +++ b/drivers/usb/chipidea/usbmisc_imx.c @@ -55,6 +55,10 @@ #define MX53_USB_PLL_DIV_24_MHZ 0x01 #define MX6_BM_OVER_CUR_DIS BIT(7) +#define MX6_BM_WAKEUP_ENABLE BIT(10) +#define MX6_BM_ID_WAKEUP BIT(16) +#define MX6_BM_VBUS_WAKEUP BIT(17) +#define MX6_BM_WAKEUP_INTR BIT(31) #define VF610_OVER_CUR_DIS BIT(7) @@ -63,6 +67,8 @@ struct usbmisc_ops { int (*init)(struct imx_usbmisc_data *data); /* It's called once after adding a usb device */ int (*post)(struct imx_usbmisc_data *data); + /* It's called when we need to enable/disable usb wakeup */ + int (*set_wakeup)(struct imx_usbmisc_data *data, bool enabled); }; struct imx_usbmisc { @@ -202,6 +208,35 @@ static int usbmisc_imx53_init(struct imx_usbmisc_data *data) return 0; } +static int usbmisc_imx6q_set_wakeup + (struct imx_usbmisc_data *data, bool enabled) +{ + struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); + unsigned long flags; + u32 val; + u32 wakeup_setting = (MX6_BM_WAKEUP_ENABLE | + MX6_BM_VBUS_WAKEUP | MX6_BM_ID_WAKEUP); + int ret = 0; + + if (data->index > 3) + return -EINVAL; + + spin_lock_irqsave(&usbmisc->lock, flags); + val = readl(usbmisc->base + data->index * 4); + if (enabled) { + val |= wakeup_setting; + writel(val, usbmisc->base + data->index * 4); + } else { + if (val & MX6_BM_WAKEUP_INTR) + pr_debug("wakeup int at ci_hdrc.%d\n", data->index); + val &= ~wakeup_setting; + writel(val, usbmisc->base + data->index * 4); + } + spin_unlock_irqrestore(&usbmisc->lock, flags); + + return ret; +} + static int usbmisc_imx6q_init(struct imx_usbmisc_data *data) { struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); @@ -219,6 +254,8 @@ static int usbmisc_imx6q_init(struct imx_usbmisc_data *data) spin_unlock_irqrestore(&usbmisc->lock, flags); } + usbmisc_imx6q_set_wakeup(data, false); + return 0; } @@ -256,6 +293,7 @@ static const struct usbmisc_ops imx53_usbmisc_ops = { }; static const struct usbmisc_ops imx6q_usbmisc_ops = { + .set_wakeup = usbmisc_imx6q_set_wakeup, .init = usbmisc_imx6q_init, }; @@ -291,6 +329,20 @@ int imx_usbmisc_init_post(struct imx_usbmisc_data *data) } EXPORT_SYMBOL_GPL(imx_usbmisc_init_post); +int imx_usbmisc_set_wakeup(struct imx_usbmisc_data *data, bool enabled) +{ + struct imx_usbmisc *usbmisc; + + if (!data) + return 0; + + usbmisc = dev_get_drvdata(data->dev); + if (!usbmisc->ops->set_wakeup) + return 0; + return usbmisc->ops->set_wakeup(data, enabled); +} +EXPORT_SYMBOL_GPL(imx_usbmisc_set_wakeup); + static const struct of_device_id usbmisc_imx_dt_ids[] = { { .compatible = "fsl,imx25-usbmisc", -- cgit v0.10.2 From e14db48dfcf3ab6ebea212e82dc56036a00b0d6b Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Wed, 11 Feb 2015 12:44:47 +0800 Subject: usb: chipidea: imx: add runtime power management support Add runtime pm support for imx, only imx6 series are supported and tested. Signed-off-by: Peter Chen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c index 353989e..5ad85fe 100644 --- a/drivers/usb/chipidea/ci_hdrc_imx.c +++ b/drivers/usb/chipidea/ci_hdrc_imx.c @@ -25,6 +25,7 @@ struct ci_hdrc_imx_platform_flag { unsigned int flags; + bool runtime_pm; }; static const struct ci_hdrc_imx_platform_flag imx27_usb_data = { @@ -34,9 +35,24 @@ static const struct ci_hdrc_imx_platform_flag imx28_usb_data = { .flags = CI_HDRC_IMX28_WRITE_FIX, }; +static const struct ci_hdrc_imx_platform_flag imx6q_usb_data = { + .flags = CI_HDRC_SUPPORTS_RUNTIME_PM, +}; + +static const struct ci_hdrc_imx_platform_flag imx6sl_usb_data = { + .flags = CI_HDRC_SUPPORTS_RUNTIME_PM, +}; + +static const struct ci_hdrc_imx_platform_flag imx6sx_usb_data = { + .flags = CI_HDRC_SUPPORTS_RUNTIME_PM, +}; + static const struct of_device_id ci_hdrc_imx_dt_ids[] = { { .compatible = "fsl,imx28-usb", .data = &imx28_usb_data}, { .compatible = "fsl,imx27-usb", .data = &imx27_usb_data}, + { .compatible = "fsl,imx6q-usb", .data = &imx6q_usb_data}, + { .compatible = "fsl,imx6sl-usb", .data = &imx6sl_usb_data}, + { .compatible = "fsl,imx6sx-usb", .data = &imx6sl_usb_data}, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, ci_hdrc_imx_dt_ids); @@ -46,6 +62,8 @@ struct ci_hdrc_imx_data { struct platform_device *ci_pdev; struct clk *clk; struct imx_usbmisc_data *usbmisc_data; + bool supports_runtime_pm; + bool in_lpm; }; /* Common functions shared by usbmisc drivers */ @@ -144,6 +162,8 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev) pdata.usb_phy = data->phy; pdata.flags |= imx_platform_flag->flags; + if (pdata.flags & CI_HDRC_SUPPORTS_RUNTIME_PM) + data->supports_runtime_pm = true; ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); if (ret) @@ -174,8 +194,10 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev) platform_set_drvdata(pdev, data); - pm_runtime_no_callbacks(&pdev->dev); - pm_runtime_enable(&pdev->dev); + if (data->supports_runtime_pm) { + pm_runtime_set_active(&pdev->dev); + pm_runtime_enable(&pdev->dev); + } return 0; @@ -190,14 +212,18 @@ static int ci_hdrc_imx_remove(struct platform_device *pdev) { struct ci_hdrc_imx_data *data = platform_get_drvdata(pdev); - pm_runtime_disable(&pdev->dev); + if (data->supports_runtime_pm) { + pm_runtime_get_sync(&pdev->dev); + pm_runtime_disable(&pdev->dev); + pm_runtime_put_noidle(&pdev->dev); + } ci_hdrc_remove_device(data->ci_pdev); clk_disable_unprepare(data->clk); return 0; } -#ifdef CONFIG_PM_SLEEP +#ifdef CONFIG_PM static int imx_controller_suspend(struct device *dev) { struct ci_hdrc_imx_data *data = dev_get_drvdata(dev); @@ -205,6 +231,7 @@ static int imx_controller_suspend(struct device *dev) dev_dbg(dev, "at %s\n", __func__); clk_disable_unprepare(data->clk); + data->in_lpm = true; return 0; } @@ -212,25 +239,92 @@ static int imx_controller_suspend(struct device *dev) static int imx_controller_resume(struct device *dev) { struct ci_hdrc_imx_data *data = dev_get_drvdata(dev); + int ret = 0; dev_dbg(dev, "at %s\n", __func__); - return clk_prepare_enable(data->clk); + if (!data->in_lpm) { + WARN_ON(1); + return 0; + } + + ret = clk_prepare_enable(data->clk); + if (ret) + return ret; + + data->in_lpm = false; + + ret = imx_usbmisc_set_wakeup(data->usbmisc_data, false); + if (ret) { + dev_err(dev, "usbmisc set_wakeup failed, ret=%d\n", ret); + goto clk_disable; + } + + return 0; + +clk_disable: + clk_disable_unprepare(data->clk); + return ret; } +#ifdef CONFIG_PM_SLEEP static int ci_hdrc_imx_suspend(struct device *dev) { + struct ci_hdrc_imx_data *data = dev_get_drvdata(dev); + + if (data->in_lpm) + /* The core's suspend doesn't run */ + return 0; + return imx_controller_suspend(dev); } static int ci_hdrc_imx_resume(struct device *dev) { - return imx_controller_resume(dev); + struct ci_hdrc_imx_data *data = dev_get_drvdata(dev); + int ret; + + ret = imx_controller_resume(dev); + if (!ret && data->supports_runtime_pm) { + pm_runtime_disable(dev); + pm_runtime_set_active(dev); + pm_runtime_enable(dev); + } + + return ret; } #endif /* CONFIG_PM_SLEEP */ +static int ci_hdrc_imx_runtime_suspend(struct device *dev) +{ + struct ci_hdrc_imx_data *data = dev_get_drvdata(dev); + int ret; + + if (data->in_lpm) { + WARN_ON(1); + return 0; + } + + ret = imx_usbmisc_set_wakeup(data->usbmisc_data, true); + if (ret) { + dev_err(dev, "usbmisc set_wakeup failed, ret=%d\n", ret); + return ret; + } + + return imx_controller_suspend(dev); +} + +static int ci_hdrc_imx_runtime_resume(struct device *dev) +{ + return imx_controller_resume(dev); +} + +#endif /* CONFIG_PM */ + static const struct dev_pm_ops ci_hdrc_imx_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(ci_hdrc_imx_suspend, ci_hdrc_imx_resume) + SET_RUNTIME_PM_OPS(ci_hdrc_imx_runtime_suspend, + ci_hdrc_imx_runtime_resume, NULL) }; static struct platform_driver ci_hdrc_imx_driver = { .probe = ci_hdrc_imx_probe, -- cgit v0.10.2 From f8efa7665e66c1e92fa10492a243cc0de4437ade Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Wed, 11 Feb 2015 12:44:48 +0800 Subject: usb: chipidea: add usb as system wakeup source The USB signal can be system wakeup source, this patch add the support, for how to enable it, see Documentation/usb/chipidea.txt. Since USB wakeup enable logic is vendor/platform specific, the glue layer needs to implement it to support this feature. Signed-off-by: Peter Chen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c index 63d2b39..6d9dc2d 100644 --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c @@ -808,6 +808,8 @@ static int ci_hdrc_probe(struct platform_device *pdev) if (ci_otg_is_fsm_mode(ci)) ci_hdrc_otg_fsm_start(ci); + device_set_wakeup_capable(&pdev->dev, true); + ret = dbg_create_files(ci); if (!ret) return 0; @@ -898,6 +900,11 @@ static int ci_suspend(struct device *dev) return 0; } + if (device_may_wakeup(dev)) { + usb_phy_set_wakeup(ci->usb_phy, true); + enable_irq_wake(ci->irq); + } + ci_controller_suspend(ci); return 0; @@ -908,6 +915,9 @@ static int ci_resume(struct device *dev) struct ci_hdrc *ci = dev_get_drvdata(dev); int ret; + if (device_may_wakeup(dev)) + disable_irq_wake(ci->irq); + ret = ci_controller_resume(dev); if (ret) return ret; -- cgit v0.10.2 From 6d6531104d20692190690ed73eaaac770c42aa49 Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Wed, 11 Feb 2015 12:44:49 +0800 Subject: usb: chipidea: imx: add usb as system wakeup source Enable USB as system wakeup source, and each platform needs to implement imx_usbmisc_set_wakeup in usbmisc_imx.c to support. Signed-off-by: Peter Chen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c index 5ad85fe..f7f9fd4 100644 --- a/drivers/usb/chipidea/ci_hdrc_imx.c +++ b/drivers/usb/chipidea/ci_hdrc_imx.c @@ -199,6 +199,8 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev) pm_runtime_enable(&pdev->dev); } + device_set_wakeup_capable(&pdev->dev, true); + return 0; disable_device: @@ -270,12 +272,23 @@ clk_disable: #ifdef CONFIG_PM_SLEEP static int ci_hdrc_imx_suspend(struct device *dev) { + int ret; + struct ci_hdrc_imx_data *data = dev_get_drvdata(dev); if (data->in_lpm) /* The core's suspend doesn't run */ return 0; + if (device_may_wakeup(dev)) { + ret = imx_usbmisc_set_wakeup(data->usbmisc_data, true); + if (ret) { + dev_err(dev, "usbmisc set_wakeup failed, ret=%d\n", + ret); + return ret; + } + } + return imx_controller_suspend(dev); } -- cgit v0.10.2 From 01e3ad863fc0f15b802c8a5247e1c252bd04f429 Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Wed, 11 Feb 2015 12:44:50 +0800 Subject: doc: usb: chipidea: add usb wakeup enable example Add the example for how to enable USB as system wakeup source. Signed-off-by: Peter Chen Signed-off-by: Greg Kroah-Hartman diff --git a/Documentation/usb/chipidea.txt b/Documentation/usb/chipidea.txt index 995c8bc..3f848c1 100644 --- a/Documentation/usb/chipidea.txt +++ b/Documentation/usb/chipidea.txt @@ -69,3 +69,24 @@ cat /sys/kernel/debug/ci_hdrc.0/registers ---------------------- "On-The-Go and Embedded Host Supplement to the USB Revision 2.0 Specification July 27, 2012 Revision 2.0 version 1.1a" + +2. How to enable USB as system wakeup source +----------------------------------- +Below is the example for how to enable USB as system wakeup source +at imx6 platform. + +2.1 Enable core's wakeup +echo enabled > /sys/bus/platform/devices/ci_hdrc.0/power/wakeup +2.2 Enable glue layer's wakeup +echo enabled > /sys/bus/platform/devices/2184000.usb/power/wakeup +2.3 Enable PHY's wakeup (optional) +echo enabled > /sys/bus/platform/devices/20c9000.usbphy/power/wakeup +2.4 Enable roothub's wakeup +echo enabled > /sys/bus/usb/devices/usb1/power/wakeup +2.5 Enable related device's wakeup +echo enabled > /sys/bus/usb/devices/1-1/power/wakeup + +If the system has only one usb port, and you want usb wakeup at this port, you +can use below script to enable usb wakeup. +for i in $(find /sys -name wakeup | grep usb);do echo enabled > $i;done; + -- cgit v0.10.2 From 2e37cfd8e0a0bb161a75ce2bc2302a1a1662fdb7 Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Wed, 11 Feb 2015 12:44:51 +0800 Subject: usb: chipidea: clear otg interrupt status for otg capable controller We need to do it for all otg capable controller, not only peripheral featured otg capable controller, otherwise, the host-only role, but otg capable controller may be responded by otg interrupt. Signed-off-by: Peter Chen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c index 6d9dc2d..2337354 100644 --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c @@ -649,8 +649,12 @@ static void ci_get_otg_capable(struct ci_hdrc *ci) ci->is_otg = (hw_read(ci, CAP_DCCPARAMS, DCCPARAMS_DC | DCCPARAMS_HC) == (DCCPARAMS_DC | DCCPARAMS_HC)); - if (ci->is_otg) + if (ci->is_otg) { dev_dbg(ci->dev, "It is OTG capable controller\n"); + /* Disable and clear all OTG irq */ + hw_write_otgsc(ci, OTGSC_INT_EN_BITS | OTGSC_INT_STATUS_BITS, + OTGSC_INT_STATUS_BITS); + } } static int ci_hdrc_probe(struct platform_device *pdev) @@ -749,9 +753,6 @@ static int ci_hdrc_probe(struct platform_device *pdev) } if (ci->is_otg && ci->roles[CI_ROLE_GADGET]) { - /* Disable and clear all OTG irq */ - hw_write_otgsc(ci, OTGSC_INT_EN_BITS | OTGSC_INT_STATUS_BITS, - OTGSC_INT_STATUS_BITS); ret = ci_hdrc_otg_init(ci); if (ret) { dev_err(dev, "init otg fails, ret = %d\n", ret); -- cgit v0.10.2 From b0e04f852ac1fffa85b73842e60125d68cd095df Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Wed, 11 Feb 2015 12:44:52 +0800 Subject: doc: usb: usbmisc-imx: add imx6sx compatible string Add compatible string for imx6sx-usbmisc. Signed-off-by: Peter Chen Signed-off-by: Greg Kroah-Hartman diff --git a/Documentation/devicetree/bindings/usb/usbmisc-imx.txt b/Documentation/devicetree/bindings/usb/usbmisc-imx.txt index c101a4b..3539d4e 100644 --- a/Documentation/devicetree/bindings/usb/usbmisc-imx.txt +++ b/Documentation/devicetree/bindings/usb/usbmisc-imx.txt @@ -5,6 +5,7 @@ Required properties: - compatible: Should be one of below: "fsl,imx6q-usbmisc" for imx6q "fsl,vf610-usbmisc" for Vybrid vf610 + "fsl,imx6sx-usbmisc" for imx6sx - reg: Should contain registers location and length Examples: -- cgit v0.10.2 From 8721a752cc1bf61be0a0d3f266abd71a270d3a38 Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Wed, 11 Feb 2015 12:44:53 +0800 Subject: usb: chipidea: usbmisc_imx: add imx6sx initialization routine Except the same process with earlier imx6, it has below two features: - Choose which vbus voltage as vbus wakeup source We choose B_SESSION_VALID as vbus wakeup source since when the system goes to suspend, the vbus comparator can't compare the vbus voltage for VBUS_VALID. - Disable dp/dm (linestate) change as wakeup source at device mode when the vbus is not there, we don't expect dp/dm change waking up usb controller at this situation. Signed-off-by: Peter Chen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/chipidea/usbmisc_imx.c b/drivers/usb/chipidea/usbmisc_imx.c index 90b7d7f..8af070f 100644 --- a/drivers/usb/chipidea/usbmisc_imx.c +++ b/drivers/usb/chipidea/usbmisc_imx.c @@ -58,7 +58,16 @@ #define MX6_BM_WAKEUP_ENABLE BIT(10) #define MX6_BM_ID_WAKEUP BIT(16) #define MX6_BM_VBUS_WAKEUP BIT(17) +#define MX6SX_BM_DPDM_WAKEUP_EN BIT(29) #define MX6_BM_WAKEUP_INTR BIT(31) +#define MX6_USB_OTG1_PHY_CTRL 0x18 +/* For imx6dql, it is host-only controller, for later imx6, it is otg's */ +#define MX6_USB_OTG2_PHY_CTRL 0x1c +#define MX6SX_USB_VBUS_WAKEUP_SOURCE(v) (v << 8) +#define MX6SX_USB_VBUS_WAKEUP_SOURCE_VBUS MX6SX_USB_VBUS_WAKEUP_SOURCE(0) +#define MX6SX_USB_VBUS_WAKEUP_SOURCE_AVALID MX6SX_USB_VBUS_WAKEUP_SOURCE(1) +#define MX6SX_USB_VBUS_WAKEUP_SOURCE_BVALID MX6SX_USB_VBUS_WAKEUP_SOURCE(2) +#define MX6SX_USB_VBUS_WAKEUP_SOURCE_SESS_END MX6SX_USB_VBUS_WAKEUP_SOURCE(3) #define VF610_OVER_CUR_DIS BIT(7) @@ -259,6 +268,35 @@ static int usbmisc_imx6q_init(struct imx_usbmisc_data *data) return 0; } +static int usbmisc_imx6sx_init(struct imx_usbmisc_data *data) +{ + void __iomem *reg = NULL; + unsigned long flags; + struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); + u32 val; + int ret = 0; + + usbmisc_imx6q_init(data); + + if (data->index == 0 || data->index == 1) { + reg = usbmisc->base + MX6_USB_OTG1_PHY_CTRL + data->index * 4; + spin_lock_irqsave(&usbmisc->lock, flags); + /* Set vbus wakeup source as bvalid */ + val = readl(reg); + writel(val | MX6SX_USB_VBUS_WAKEUP_SOURCE_BVALID, reg); + /* + * Disable dp/dm wakeup in device mode when vbus is + * not there. + */ + val = readl(usbmisc->base + data->index * 4); + writel(val & ~MX6SX_BM_DPDM_WAKEUP_EN, + usbmisc->base + data->index * 4); + spin_unlock_irqrestore(&usbmisc->lock, flags); + } + + return ret; +} + static int usbmisc_vf610_init(struct imx_usbmisc_data *data) { struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); @@ -301,6 +339,11 @@ static const struct usbmisc_ops vf610_usbmisc_ops = { .init = usbmisc_vf610_init, }; +static const struct usbmisc_ops imx6sx_usbmisc_ops = { + .set_wakeup = usbmisc_imx6q_set_wakeup, + .init = usbmisc_imx6sx_init, +}; + int imx_usbmisc_init(struct imx_usbmisc_data *data) { struct imx_usbmisc *usbmisc; @@ -372,6 +415,10 @@ static const struct of_device_id usbmisc_imx_dt_ids[] = { .compatible = "fsl,vf610-usbmisc", .data = &vf610_usbmisc_ops, }, + { + .compatible = "fsl,imx6sx-usbmisc", + .data = &imx6sx_usbmisc_ops, + }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, usbmisc_imx_dt_ids); -- cgit v0.10.2 From 655d32e9b2b2b912ff86de656eb620627b0df117 Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Wed, 11 Feb 2015 12:44:54 +0800 Subject: usb: chipidea: add identification registers access APIs Using hw_write_id_reg and hw_read_id_reg to write and read identification registers contents, they can be used to get controller information, change some system configurations, and so on. Reviewed-by: Stefan Agner Signed-off-by: Peter Chen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h index a0aeb8d..e53287a 100644 --- a/drivers/usb/chipidea/ci.h +++ b/drivers/usb/chipidea/ci.h @@ -29,6 +29,15 @@ /****************************************************************************** * REGISTERS *****************************************************************************/ +/* Identification Registers */ +#define ID_ID 0x0 +#define ID_HWGENERAL 0x4 +#define ID_HWHOST 0x8 +#define ID_HWDEVICE 0xc +#define ID_HWTXBUF 0x10 +#define ID_HWRXBUF 0x14 +#define ID_SBUSCFG 0x90 + /* register indices */ enum ci_hw_regs { CAP_CAPLENGTH, @@ -254,6 +263,36 @@ static inline void ci_role_stop(struct ci_hdrc *ci) } /** + * hw_read_id_reg: reads from a identification register + * @ci: the controller + * @offset: offset from the beginning of identification registers region + * @mask: bitfield mask + * + * This function returns register contents + */ +static inline u32 hw_read_id_reg(struct ci_hdrc *ci, u32 offset, u32 mask) +{ + return ioread32(ci->hw_bank.abs + offset) & mask; +} + +/** + * hw_write_id_reg: writes to a identification register + * @ci: the controller + * @offset: offset from the beginning of identification registers region + * @mask: bitfield mask + * @data: new value + */ +static inline void hw_write_id_reg(struct ci_hdrc *ci, u32 offset, + u32 mask, u32 data) +{ + if (~mask) + data = (ioread32(ci->hw_bank.abs + offset) & ~mask) + | (data & mask); + + iowrite32(data, ci->hw_bank.abs + offset); +} + +/** * hw_read: reads from a hw register * @ci: the controller * @reg: register index -- cgit v0.10.2 From cb271f3ce969a0fc4ecf9fc4b5a28852509714ed Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Wed, 11 Feb 2015 12:44:55 +0800 Subject: usb: chipidea: add chipidea revision information Define ci_get_revision API to know the controller revision information according to chipidea 1.1a, 2.0a and 2.5a spec. Besides, add one entry at struct ci_hdrc to indicate revision information, it can be used for adding different code for revisions, eg kinds of errata. Reviewed-by: Stefan Agner Signed-off-by: Peter Chen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/chipidea/bits.h b/drivers/usb/chipidea/bits.h index ca57e3d..e69424d 100644 --- a/drivers/usb/chipidea/bits.h +++ b/drivers/usb/chipidea/bits.h @@ -15,6 +15,16 @@ #include +/* + * ID + * For 1.x revision, bit24 - bit31 are reserved + * For 2.x revision, bit25 - bit28 are 0x2 + */ +#define TAG (0x1F << 16) +#define REVISION (0xF << 21) +#define VERSION (0xF << 25) +#define CIVERSION (0x7 << 29) + /* HCCPARAMS */ #define HCCPARAMS_LEN BIT(17) diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h index e53287a..c09381d 100644 --- a/drivers/usb/chipidea/ci.h +++ b/drivers/usb/chipidea/ci.h @@ -106,6 +106,18 @@ enum ci_role { CI_ROLE_END, }; +enum ci_revision { + CI_REVISION_1X = 10, /* Revision 1.x */ + CI_REVISION_20 = 20, /* Revision 2.0 */ + CI_REVISION_21, /* Revision 2.1 */ + CI_REVISION_22, /* Revision 2.2 */ + CI_REVISION_23, /* Revision 2.3 */ + CI_REVISION_24, /* Revision 2.4 */ + CI_REVISION_25, /* Revision 2.5 */ + CI_REVISION_25_PLUS, /* Revision above than 2.5 */ + CI_REVISION_UNKNOWN = 99, /* Unknown Revision */ +}; + /** * struct ci_role_driver - host/gadget role driver * @start: start this role @@ -181,6 +193,7 @@ struct hw_bank { * @supports_runtime_pm: if runtime pm is supported * @in_lpm: if the core in low power mode * @wakeup_int: if wakeup interrupt occur + * @rev: The revision number for controller */ struct ci_hdrc { struct device *dev; @@ -226,6 +239,7 @@ struct ci_hdrc { bool supports_runtime_pm; bool in_lpm; bool wakeup_int; + enum ci_revision rev; }; static inline struct ci_role_driver *ci_role(struct ci_hdrc *ci) diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c index 2337354..4b22d7c 100644 --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c @@ -137,6 +137,22 @@ static int hw_alloc_regmap(struct ci_hdrc *ci, bool is_lpm) return 0; } +static enum ci_revision ci_get_revision(struct ci_hdrc *ci) +{ + int ver = hw_read_id_reg(ci, ID_ID, VERSION) >> __ffs(VERSION); + enum ci_revision rev = CI_REVISION_UNKNOWN; + + if (ver == 0x2) { + rev = hw_read_id_reg(ci, ID_ID, REVISION) + >> __ffs(REVISION); + rev += CI_REVISION_20; + } else if (ver == 0x0) { + rev = CI_REVISION_1X; + } + + return rev; +} + /** * hw_read_intr_enable: returns interrupt enable register * @@ -251,8 +267,11 @@ static int hw_device_init(struct ci_hdrc *ci, void __iomem *base) /* Clear all interrupts status bits*/ hw_write(ci, OP_USBSTS, 0xffffffff, 0xffffffff); - dev_dbg(ci->dev, "ChipIdea HDRC found, lpm: %d; cap: %p op: %p\n", - ci->hw_bank.lpm, ci->hw_bank.cap, ci->hw_bank.op); + ci->rev = ci_get_revision(ci); + + dev_dbg(ci->dev, + "ChipIdea HDRC found, revision: %d, lpm: %d; cap: %p op: %p\n", + ci->rev, ci->hw_bank.lpm, ci->hw_bank.cap, ci->hw_bank.op); /* setup lock mode ? */ -- cgit v0.10.2 From 06bdfcdb139e95edbebeb719200de5d535afe526 Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Wed, 11 Feb 2015 12:44:56 +0800 Subject: usb: chipidea: Add errata for revision 2.40a At chipidea revision 2.40a, there is a below errata: 9000531823 B2-Medium Adding a dTD to a Primed Endpoint May Not Get Recognized Title: Adding a dTD to a Primed Endpoint May Not Get Recognized Impacted Configuration: All device mode configurations. Description: There is an issue with the add dTD tripwire semaphore (ATDTW bit in USBCMD register) that can cause the controller to ignore a dTD that is added to a primed endpoint. When this happens, the software can read the tripwire bit and the status bit at '1' even though the endpoint is unprimed. After executing a dTD, the device controller endpoint state machine executes a final read of the dTD terminate bit to check if the application added a dTD to the linked list at the last moment. This read is done in the finpkt_read_latest_next_td (44) state. After the read is performed, if the terminate bit is still set, the state machine moves to unprime the endpoint. The decision to unprime the endpoint is done in the checkqh_decision (59) state, based on the value of the terminate bit. Before reaching the checkqh_decision state, the state machine traverses the writeqhtd_status (57), writeqh_status (56), and release_prime_mask (42) states. As shown in the waveform, the ep_addtd_tripwire_clr signal is not set to clear the tripwire bit in these states. Workaround: The software must implement a periodic poll cycle, and check for each dTD pending on execution (Active = 1), if the enpoint is primed. It can do this by reading the corresponding bits in the ENDPTPRIME and ENDPTSTAT registers. If these bits are read at 0, the software needs to re-prime the endpoint by writing 1 to the corresponding bit in the ENDPTPRIME register. This can be done for every microframe, every frame or with a larger interval, depending on the urgency of transfer execution for the application. Tested-by: Stefan Agner Signed-off-by: Peter Chen Signed-off-by: Sanchayan Maity Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c index 5244542..4254792 100644 --- a/drivers/usb/chipidea/udc.c +++ b/drivers/usb/chipidea/udc.c @@ -522,6 +522,20 @@ static void free_pending_td(struct ci_hw_ep *hwep) kfree(pending); } +static int reprime_dtd(struct ci_hdrc *ci, struct ci_hw_ep *hwep, + struct td_node *node) +{ + hwep->qh.ptr->td.next = node->dma; + hwep->qh.ptr->td.token &= + cpu_to_le32(~(TD_STATUS_HALTED | TD_STATUS_ACTIVE)); + + /* Synchronize before ep prime */ + wmb(); + + return hw_ep_prime(ci, hwep->num, hwep->dir, + hwep->type == USB_ENDPOINT_XFER_CONTROL); +} + /** * _hardware_dequeue: handles a request at hardware level * @gadget: gadget @@ -535,6 +549,7 @@ static int _hardware_dequeue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq) struct td_node *node, *tmpnode; unsigned remaining_length; unsigned actual = hwreq->req.length; + struct ci_hdrc *ci = hwep->ci; if (hwreq->req.status != -EALREADY) return -EINVAL; @@ -544,6 +559,11 @@ static int _hardware_dequeue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq) list_for_each_entry_safe(node, tmpnode, &hwreq->tds, td) { tmptoken = le32_to_cpu(node->ptr->token); if ((TD_STATUS_ACTIVE & tmptoken) != 0) { + int n = hw_ep_bit(hwep->num, hwep->dir); + + if (ci->rev == CI_REVISION_24) + if (!hw_read(ci, OP_ENDPTSTAT, BIT(n))) + reprime_dtd(ci, hwep, node); hwreq->req.status = -EALREADY; return -EBUSY; } -- cgit v0.10.2 From 89200448a01d9d07a1ee5cc42e8b847f86cdaf7c Mon Sep 17 00:00:00 2001 From: Daniel Tang Date: Wed, 11 Feb 2015 12:44:57 +0800 Subject: Chipidea: TI-NSPIRE USB OTG hardware does not support high speed and must connect at full speed Signed-off-by: Daniel Tang Signed-off-by: Peter Chen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/chipidea/ci_hdrc_zevio.c b/drivers/usb/chipidea/ci_hdrc_zevio.c index d976fc1..1264de5 100644 --- a/drivers/usb/chipidea/ci_hdrc_zevio.c +++ b/drivers/usb/chipidea/ci_hdrc_zevio.c @@ -18,7 +18,7 @@ static struct ci_hdrc_platform_data ci_hdrc_zevio_platdata = { .name = "ci_hdrc_zevio", - .flags = CI_HDRC_REGS_SHARED, + .flags = CI_HDRC_REGS_SHARED | CI_HDRC_FORCE_FULLSPEED, .capoffset = DEF_CAPOFFSET, }; -- cgit v0.10.2 From 905276c4319174d52de0e45fc9b22f599497be47 Mon Sep 17 00:00:00 2001 From: Daniel Tang Date: Wed, 11 Feb 2015 12:44:58 +0800 Subject: Chipidea: Set connect-at-fullspeed bit when entering host mode if CI_HDRC_FORCE_FULLSPEED is set in the platform data PORTSC_PFSC is not set on entering host mode which means the USB OTG controller will attempt to enumerate USB devices at high speed even when the CI_HDRC_FORCE_FULLSPEED flag is set in the platform data. This patch ensures it is set right before host mode operations begin if needed. Signed-off-by: Daniel Tang Signed-off-by: Peter Chen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c index 48731d0..12edbd0 100644 --- a/drivers/usb/chipidea/host.c +++ b/drivers/usb/chipidea/host.c @@ -133,6 +133,9 @@ static int host_start(struct ci_hdrc *ci) if (ci->platdata->flags & CI_HDRC_DISABLE_STREAMING) hw_write(ci, OP_USBMODE, USBMODE_CI_SDIS, USBMODE_CI_SDIS); + if (ci->platdata->flags & CI_HDRC_FORCE_FULLSPEED) + hw_write(ci, OP_PORTSC, PORTSC_PFSC, PORTSC_PFSC); + return ret; put_hcd: -- cgit v0.10.2 From 78f0357ec8baa1ffe9c14b81f88cb0f3a5e1c15a Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Wed, 11 Feb 2015 12:44:59 +0800 Subject: usb: chipidea: host: add .bus_suspend quirk For chipidea, its resume sequence is not-EHCI compatible, see below description for FPR at portsc. So in order to send SoF in time for remote wakeup sequence(within 3ms), the RUN/STOP bit must be set before the resume signal is ended, but the usb resume code may run after resume signal is ended, so we had to set it at suspend path. Force Port Resume - RW. Default = 0b. 1= Resume detected/driven on port. 0=No resume (K-state) detected/driven on port. Host mode: Software sets this bit to one to drive resume signaling. The Controller sets this bit to '1' if a J-to-K transition is detected while the port is in the Suspend state. When this bit transitions to a '1' because a J-to-K transition is detected, the Port Change Detect bit in the USBSTS register is also set to '1'. This bit will automatically change to '0' after the resume sequence is complete. This behavior is different from EHCI where the controller driver is required to set this bit to a '0' after the resume duration is timed in the driver. Note that when the controller owns the port, the resume sequence follows the defined sequence documented in the USB Specification Revision 2.0. The resume signaling (Full-speed 'K') is driven on the port as long as this bit remains a '1'. This bit will remain a '1' until the port has switched to idle. Writing a '0' has no affect because the port controller will time the resume operation, clear the bit and the port control state switches to HS or FS idle. This field is '0' if Port Power(PP) is '0' in host mode. This bit is not-EHCI compatible. Acked-by: Alan Stern Signed-off-by: Peter Chen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c index 12edbd0..feb9f07 100644 --- a/drivers/usb/chipidea/host.c +++ b/drivers/usb/chipidea/host.c @@ -33,6 +33,7 @@ #include "host.h" static struct hc_driver __read_mostly ci_ehci_hc_driver; +static int (*orig_bus_suspend)(struct usb_hcd *hcd); struct ehci_ci_priv { struct regulator *reg_vbus; @@ -161,6 +162,47 @@ void ci_hdrc_host_destroy(struct ci_hdrc *ci) host_stop(ci); } +static int ci_ehci_bus_suspend(struct usb_hcd *hcd) +{ + struct ehci_hcd *ehci = hcd_to_ehci(hcd); + int port; + u32 tmp; + + int ret = orig_bus_suspend(hcd); + + if (ret) + return ret; + + port = HCS_N_PORTS(ehci->hcs_params); + while (port--) { + u32 __iomem *reg = &ehci->regs->port_status[port]; + u32 portsc = ehci_readl(ehci, reg); + + if (portsc & PORT_CONNECT) { + /* + * For chipidea, the resume signal will be ended + * automatically, so for remote wakeup case, the + * usbcmd.rs may not be set before the resume has + * ended if other resume paths consumes too much + * time (~24ms), in that case, the SOF will not + * send out within 3ms after resume ends, then the + * high speed device will enter full speed mode. + */ + + tmp = ehci_readl(ehci, &ehci->regs->command); + tmp |= CMD_RUN; + ehci_writel(ehci, tmp, &ehci->regs->command); + /* + * It needs a short delay between set RS bit and PHCD. + */ + usleep_range(150, 200); + break; + } + } + + return 0; +} + int ci_hdrc_host_init(struct ci_hdrc *ci) { struct ci_role_driver *rdrv; @@ -179,6 +221,8 @@ int ci_hdrc_host_init(struct ci_hdrc *ci) ci->roles[CI_ROLE_HOST] = rdrv; ehci_init_driver(&ci_ehci_hc_driver, &ehci_ci_overrides); + orig_bus_suspend = ci_ehci_hc_driver.bus_suspend; + ci_ehci_hc_driver.bus_suspend = ci_ehci_bus_suspend; return 0; } -- cgit v0.10.2 From ba1aff67f99a219b0c56bf7f10cea2c41cbd0583 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Wed, 11 Feb 2015 12:45:00 +0800 Subject: chipidea: pci: register nop PHY Since PHY for ChipIdea is optional (not all SoCs having PHY for ChipIdea should be programmed), we register 'nop' PHY for platforms that do not have programmable PHY. Acked-by: Felipe Balbi Signed-off-by: Andy Shevchenko Signed-off-by: Peter Chen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/chipidea/ci_hdrc_pci.c b/drivers/usb/chipidea/ci_hdrc_pci.c index 4df6694..773d150 100644 --- a/drivers/usb/chipidea/ci_hdrc_pci.c +++ b/drivers/usb/chipidea/ci_hdrc_pci.c @@ -16,10 +16,16 @@ #include #include #include +#include /* driver name */ #define UDC_DRIVER_NAME "ci_hdrc_pci" +struct ci_hdrc_pci { + struct platform_device *ci; + struct platform_device *phy; +}; + /****************************************************************************** * PCI block *****************************************************************************/ @@ -52,7 +58,7 @@ static int ci_hdrc_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) { struct ci_hdrc_platform_data *platdata = (void *)id->driver_data; - struct platform_device *plat_ci; + struct ci_hdrc_pci *ci; struct resource res[3]; int retval = 0, nres = 2; @@ -61,6 +67,10 @@ static int ci_hdrc_pci_probe(struct pci_dev *pdev, return -ENODEV; } + ci = devm_kzalloc(&pdev->dev, sizeof(*ci), GFP_KERNEL); + if (!ci) + return -ENOMEM; + retval = pcim_enable_device(pdev); if (retval) return retval; @@ -73,6 +83,11 @@ static int ci_hdrc_pci_probe(struct pci_dev *pdev, pci_set_master(pdev); pci_try_set_mwi(pdev); + /* register a nop PHY */ + ci->phy = usb_phy_generic_register(); + if (!ci->phy) + return -ENOMEM; + memset(res, 0, sizeof(res)); res[0].start = pci_resource_start(pdev, 0); res[0].end = pci_resource_end(pdev, 0); @@ -80,13 +95,14 @@ static int ci_hdrc_pci_probe(struct pci_dev *pdev, res[1].start = pdev->irq; res[1].flags = IORESOURCE_IRQ; - plat_ci = ci_hdrc_add_device(&pdev->dev, res, nres, platdata); - if (IS_ERR(plat_ci)) { + ci->ci = ci_hdrc_add_device(&pdev->dev, res, nres, platdata); + if (IS_ERR(ci->ci)) { dev_err(&pdev->dev, "ci_hdrc_add_device failed!\n"); - return PTR_ERR(plat_ci); + usb_phy_generic_unregister(ci->phy); + return PTR_ERR(ci->ci); } - pci_set_drvdata(pdev, plat_ci); + pci_set_drvdata(pdev, ci); return 0; } @@ -101,9 +117,10 @@ static int ci_hdrc_pci_probe(struct pci_dev *pdev, */ static void ci_hdrc_pci_remove(struct pci_dev *pdev) { - struct platform_device *plat_ci = pci_get_drvdata(pdev); + struct ci_hdrc_pci *ci = pci_get_drvdata(pdev); - ci_hdrc_remove_device(plat_ci); + ci_hdrc_remove_device(ci->ci); + usb_phy_generic_unregister(ci->phy); } /** -- cgit v0.10.2 From 6adb9b7b5fb64be3c3e4d57578ea1446da91a8f9 Mon Sep 17 00:00:00 2001 From: Li Jun Date: Wed, 11 Feb 2015 12:45:01 +0800 Subject: usb: chipidea: add a flag for turn on vbus early for host Some usb PHYs need power supply from vbus to make it work, eg mxs-phy, if there is no vbus, USB PHY will not in correct state when the controller starts to work, for host, this requires vbus should be turned on before setting port power(PP) of ehci, to work with this kind of USB PHY design, this patch adds a flag CI_HDRC_TURN_VBUS_EARLY_ON, can be checked by host driver to turn on vbus while start host. Signed-off-by: Li Jun Signed-off-by: Peter Chen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c index f7f9fd4..389f0e0 100644 --- a/drivers/usb/chipidea/ci_hdrc_imx.c +++ b/drivers/usb/chipidea/ci_hdrc_imx.c @@ -32,19 +32,23 @@ static const struct ci_hdrc_imx_platform_flag imx27_usb_data = { }; static const struct ci_hdrc_imx_platform_flag imx28_usb_data = { - .flags = CI_HDRC_IMX28_WRITE_FIX, + .flags = CI_HDRC_IMX28_WRITE_FIX | + CI_HDRC_TURN_VBUS_EARLY_ON, }; static const struct ci_hdrc_imx_platform_flag imx6q_usb_data = { - .flags = CI_HDRC_SUPPORTS_RUNTIME_PM, + .flags = CI_HDRC_SUPPORTS_RUNTIME_PM | + CI_HDRC_TURN_VBUS_EARLY_ON, }; static const struct ci_hdrc_imx_platform_flag imx6sl_usb_data = { - .flags = CI_HDRC_SUPPORTS_RUNTIME_PM, + .flags = CI_HDRC_SUPPORTS_RUNTIME_PM | + CI_HDRC_TURN_VBUS_EARLY_ON, }; static const struct ci_hdrc_imx_platform_flag imx6sx_usb_data = { - .flags = CI_HDRC_SUPPORTS_RUNTIME_PM, + .flags = CI_HDRC_SUPPORTS_RUNTIME_PM | + CI_HDRC_TURN_VBUS_EARLY_ON, }; static const struct of_device_id ci_hdrc_imx_dt_ids[] = { diff --git a/include/linux/usb/chipidea.h b/include/linux/usb/chipidea.h index 39ba00f..ab94f78 100644 --- a/include/linux/usb/chipidea.h +++ b/include/linux/usb/chipidea.h @@ -28,6 +28,7 @@ struct ci_hdrc_platform_data { #define CI_HDRC_DUAL_ROLE_NOT_OTG BIT(4) #define CI_HDRC_IMX28_WRITE_FIX BIT(5) #define CI_HDRC_FORCE_FULLSPEED BIT(6) +#define CI_HDRC_TURN_VBUS_EARLY_ON BIT(7) enum usb_dr_mode dr_mode; #define CI_HDRC_CONTROLLER_RESET_EVENT 0 #define CI_HDRC_CONTROLLER_STOPPED_EVENT 1 -- cgit v0.10.2 From 6594591741883e004aaba105951337878698b054 Mon Sep 17 00:00:00 2001 From: Li Jun Date: Wed, 11 Feb 2015 12:45:02 +0800 Subject: usb: chipidea: host: turn on vbus before add hcd if early vbus on is required If CI_HDRC_TURN_VBUS_EARLY_ON is set, turn on vbus before adding hcd, so it will not set reg_vbus of ehci_ci_priv, then vbus will not be handled by ehci core. Signed-off-by: Li Jun Signed-off-by: Peter Chen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c index feb9f07..21fe1a3 100644 --- a/drivers/usb/chipidea/host.c +++ b/drivers/usb/chipidea/host.c @@ -44,11 +44,10 @@ static int ehci_ci_portpower(struct usb_hcd *hcd, int portnum, bool enable) struct ehci_hcd *ehci = hcd_to_ehci(hcd); struct ehci_ci_priv *priv = (struct ehci_ci_priv *)ehci->priv; struct device *dev = hcd->self.controller; - struct ci_hdrc *ci = dev_get_drvdata(dev); int ret = 0; int port = HCS_N_PORTS(ehci->hcs_params); - if (priv->reg_vbus && !ci_otg_is_fsm_mode(ci)) { + if (priv->reg_vbus) { if (port > 1) { dev_warn(dev, "Not support multi-port regulator control\n"); @@ -114,12 +113,23 @@ static int host_start(struct ci_hdrc *ci) priv = (struct ehci_ci_priv *)ehci->priv; priv->reg_vbus = NULL; - if (ci->platdata->reg_vbus) - priv->reg_vbus = ci->platdata->reg_vbus; + if (ci->platdata->reg_vbus && !ci_otg_is_fsm_mode(ci)) { + if (ci->platdata->flags & CI_HDRC_TURN_VBUS_EARLY_ON) { + ret = regulator_enable(ci->platdata->reg_vbus); + if (ret) { + dev_err(ci->dev, + "Failed to enable vbus regulator, ret=%d\n", + ret); + goto put_hcd; + } + } else { + priv->reg_vbus = ci->platdata->reg_vbus; + } + } ret = usb_add_hcd(hcd, 0, 0); if (ret) { - goto put_hcd; + goto disable_reg; } else { struct usb_otg *otg = &ci->otg; @@ -139,6 +149,10 @@ static int host_start(struct ci_hdrc *ci) return ret; +disable_reg: + if (ci->platdata->reg_vbus && !ci_otg_is_fsm_mode(ci) && + (ci->platdata->flags & CI_HDRC_TURN_VBUS_EARLY_ON)) + regulator_disable(ci->platdata->reg_vbus); put_hcd: usb_put_hcd(hcd); @@ -152,6 +166,9 @@ static void host_stop(struct ci_hdrc *ci) if (hcd) { usb_remove_hcd(hcd); usb_put_hcd(hcd); + if (ci->platdata->reg_vbus && !ci_otg_is_fsm_mode(ci) && + (ci->platdata->flags & CI_HDRC_TURN_VBUS_EARLY_ON)) + regulator_disable(ci->platdata->reg_vbus); } } -- cgit v0.10.2 From 961ea496facda611eeb153d8133a4d40055e56ca Mon Sep 17 00:00:00 2001 From: Li Jun Date: Wed, 11 Feb 2015 12:45:03 +0800 Subject: usb: chipidea: support runtime power management for otg fsm mode This patch adds runtime power management support for otg fsm mode, since A-device in a_idle state cannot detect data pulse irq after suspended, here enable wakeup by connection before suspend to make it can be resumed by DP; and handle wakeup from that state like SRP. Signed-off-by: Li Jun Signed-off-by: Peter Chen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/chipidea/bits.h b/drivers/usb/chipidea/bits.h index e69424d..3cb9bda 100644 --- a/drivers/usb/chipidea/bits.h +++ b/drivers/usb/chipidea/bits.h @@ -63,6 +63,7 @@ #define PORTSC_HSP BIT(9) #define PORTSC_PP BIT(12) #define PORTSC_PTC (0x0FUL << 16) +#define PORTSC_WKCN BIT(20) #define PORTSC_PHCD(d) ((d) ? BIT(22) : BIT(23)) /* PTS and PTW for non lpm version only */ #define PORTSC_PFSC BIT(24) diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c index 4b22d7c..74fea4f 100644 --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c @@ -798,11 +798,11 @@ static int ci_hdrc_probe(struct platform_device *pdev) : CI_ROLE_GADGET; } - /* only update vbus status for peripheral */ - if (ci->role == CI_ROLE_GADGET) - ci_handle_vbus_change(ci); - if (!ci_otg_is_fsm_mode(ci)) { + /* only update vbus status for peripheral */ + if (ci->role == CI_ROLE_GADGET) + ci_handle_vbus_change(ci); + ret = ci_role_start(ci, ci->role); if (ret) { dev_err(dev, "can't start %s role\n", @@ -861,6 +861,33 @@ static int ci_hdrc_remove(struct platform_device *pdev) } #ifdef CONFIG_PM +/* Prepare wakeup by SRP before suspend */ +static void ci_otg_fsm_suspend_for_srp(struct ci_hdrc *ci) +{ + if ((ci->fsm.otg->state == OTG_STATE_A_IDLE) && + !hw_read_otgsc(ci, OTGSC_ID)) { + hw_write(ci, OP_PORTSC, PORTSC_W1C_BITS | PORTSC_PP, + PORTSC_PP); + hw_write(ci, OP_PORTSC, PORTSC_W1C_BITS | PORTSC_WKCN, + PORTSC_WKCN); + } +} + +/* Handle SRP when wakeup by data pulse */ +static void ci_otg_fsm_wakeup_by_srp(struct ci_hdrc *ci) +{ + if ((ci->fsm.otg->state == OTG_STATE_A_IDLE) && + (ci->fsm.a_bus_drop == 1) && (ci->fsm.a_bus_req == 0)) { + if (!hw_read_otgsc(ci, OTGSC_ID)) { + ci->fsm.a_srp_det = 1; + ci->fsm.a_bus_drop = 0; + } else { + ci->fsm.id = 1; + } + ci_otg_queue_work(ci); + } +} + static void ci_controller_suspend(struct ci_hdrc *ci) { disable_irq(ci->irq); @@ -894,6 +921,8 @@ static int ci_controller_resume(struct device *dev) pm_runtime_mark_last_busy(ci->dev); pm_runtime_put_autosuspend(ci->dev); enable_irq(ci->irq); + if (ci_otg_is_fsm_mode(ci)) + ci_otg_fsm_wakeup_by_srp(ci); } return 0; @@ -921,6 +950,9 @@ static int ci_suspend(struct device *dev) } if (device_may_wakeup(dev)) { + if (ci_otg_is_fsm_mode(ci)) + ci_otg_fsm_suspend_for_srp(ci); + usb_phy_set_wakeup(ci->usb_phy, true); enable_irq_wake(ci->irq); } @@ -963,6 +995,9 @@ static int ci_runtime_suspend(struct device *dev) return 0; } + if (ci_otg_is_fsm_mode(ci)) + ci_otg_fsm_suspend_for_srp(ci); + usb_phy_set_wakeup(ci->usb_phy, true); ci_controller_suspend(ci); diff --git a/drivers/usb/chipidea/otg_fsm.c b/drivers/usb/chipidea/otg_fsm.c index 562e581..e3cf5be 100644 --- a/drivers/usb/chipidea/otg_fsm.c +++ b/drivers/usb/chipidea/otg_fsm.c @@ -225,6 +225,9 @@ static void ci_otg_add_timer(struct ci_hdrc *ci, enum ci_otg_fsm_timer_index t) return; } + if (list_empty(active_timers)) + pm_runtime_get(ci->dev); + timer->count = timer->expires; list_add_tail(&timer->list, active_timers); @@ -241,17 +244,22 @@ static void ci_otg_del_timer(struct ci_hdrc *ci, enum ci_otg_fsm_timer_index t) struct ci_otg_fsm_timer *tmp_timer, *del_tmp; struct ci_otg_fsm_timer *timer = ci->fsm_timer->timer_list[t]; struct list_head *active_timers = &ci->fsm_timer->active_timers; + int flag = 0; if (t >= NUM_CI_OTG_FSM_TIMERS) return; list_for_each_entry_safe(tmp_timer, del_tmp, active_timers, list) - if (tmp_timer == timer) + if (tmp_timer == timer) { list_del(&timer->list); + flag = 1; + } /* Disable 1ms irq if there is no any active timer */ - if (list_empty(active_timers)) + if (list_empty(active_timers) && (flag == 1)) { hw_write_otgsc(ci, OTGSC_1MSIE, 0); + pm_runtime_put(ci->dev); + } } /* @@ -275,8 +283,10 @@ static inline int ci_otg_tick_timer(struct ci_hdrc *ci) } /* disable 1ms irq if there is no any timer active */ - if ((expired == 1) && list_empty(active_timers)) + if ((expired == 1) && list_empty(active_timers)) { hw_write_otgsc(ci, OTGSC_1MSIE, 0); + pm_runtime_put(ci->dev); + } return expired; } @@ -585,6 +595,7 @@ int ci_otg_fsm_work(struct ci_hdrc *ci) ci->fsm.otg->state < OTG_STATE_A_IDLE) return 0; + pm_runtime_get_sync(ci->dev); if (otg_statemachine(&ci->fsm)) { if (ci->fsm.otg->state == OTG_STATE_A_IDLE) { /* @@ -609,8 +620,13 @@ int ci_otg_fsm_work(struct ci_hdrc *ci) */ ci_otg_queue_work(ci); } + } else if (ci->fsm.otg->state == OTG_STATE_A_HOST) { + pm_runtime_mark_last_busy(ci->dev); + pm_runtime_put_autosuspend(ci->dev); + return 0; } } + pm_runtime_put_sync(ci->dev); return 0; } -- cgit v0.10.2 From 1dc6120ef7f003305d99ef12f598a6b05eacc38c Mon Sep 17 00:00:00 2001 From: "Lad, Prabhakar" Date: Wed, 4 Feb 2015 18:05:13 +0000 Subject: usb: host/sl811-hcd: fix sparse warning this patch fixes following sparse warning: sl811-hcd.c:1804:24: warning: symbol 'sl811h_driver' was not declared. Should it be static? Signed-off-by: Lad, Prabhakar Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c index 4f4ba1e..aceddfd 100644 --- a/drivers/usb/host/sl811-hcd.c +++ b/drivers/usb/host/sl811-hcd.c @@ -1801,7 +1801,7 @@ sl811h_resume(struct platform_device *dev) /* this driver is exported so sl811_cs can depend on it */ -struct platform_driver sl811h_driver = { +static struct platform_driver sl811h_driver = { .probe = sl811h_probe, .remove = sl811h_remove, -- cgit v0.10.2 From 9751afbbb02d7a1c0f57191b8423948344a7ed86 Mon Sep 17 00:00:00 2001 From: Nicholas Mc Guire Date: Fri, 6 Feb 2015 04:50:21 -0500 Subject: USB: image: use msecs_to_jiffies for time conversion This is only an API consolidation and should make things more readable it replaces var * HZ / 1000 by msecs_to_jiffies(var). Signed-off-by: Nicholas Mc Guire Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/image/mdc800.c b/drivers/usb/image/mdc800.c index a62865a..5cf2633 100644 --- a/drivers/usb/image/mdc800.c +++ b/drivers/usb/image/mdc800.c @@ -347,7 +347,8 @@ static int mdc800_usb_waitForIRQ (int mode, int msec) { mdc800->camera_request_ready=1+mode; - wait_event_timeout(mdc800->irq_wait, mdc800->irq_woken, msec*HZ/1000); + wait_event_timeout(mdc800->irq_wait, mdc800->irq_woken, + msecs_to_jiffies(msec)); mdc800->irq_woken = 0; if (mdc800->camera_request_ready>0) @@ -743,8 +744,9 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l mutex_unlock(&mdc800->io_lock); return len-left; } - wait_event_timeout(mdc800->download_wait, mdc800->downloaded, - TO_DOWNLOAD_GET_READY*HZ/1000); + wait_event_timeout(mdc800->download_wait, + mdc800->downloaded, + msecs_to_jiffies(TO_DOWNLOAD_GET_READY)); mdc800->downloaded = 0; if (mdc800->download_urb->status != 0) { @@ -867,7 +869,8 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s mutex_unlock(&mdc800->io_lock); return -EIO; } - wait_event_timeout(mdc800->write_wait, mdc800->written, TO_WRITE_GET_READY*HZ/1000); + wait_event_timeout(mdc800->write_wait, mdc800->written, + msecs_to_jiffies(TO_WRITE_GET_READY)); mdc800->written = 0; if (mdc800->state == WORKING) { -- cgit v0.10.2 From 8f7e9473ab62139c78eb834f53c4ec6bc22d111f Mon Sep 17 00:00:00 2001 From: Nicholas Mc Guire Date: Fri, 6 Feb 2015 04:58:31 -0500 Subject: USB: legotower: use msecs_to_jiffies for time conversion This is only an API consolidation and should make things more readable it replaces var * HZ / 1000 by msecs_to_jiffies(var). Signed-off-by: Nicholas Mc Guire Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c index 97cd9e2..7771be3 100644 --- a/drivers/usb/misc/legousbtower.c +++ b/drivers/usb/misc/legousbtower.c @@ -574,7 +574,7 @@ static ssize_t tower_read (struct file *file, char __user *buffer, size_t count, } if (read_timeout) { - timeout = jiffies + read_timeout * HZ / 1000; + timeout = jiffies + msecs_to_jiffies(read_timeout); } /* wait for data */ @@ -592,7 +592,7 @@ static ssize_t tower_read (struct file *file, char __user *buffer, size_t count, /* reset read timeout during read or write activity */ if (read_timeout && (dev->read_buffer_length || dev->interrupt_out_busy)) { - timeout = jiffies + read_timeout * HZ / 1000; + timeout = jiffies + msecs_to_jiffies(read_timeout); } /* check for read timeout */ if (read_timeout && time_after (jiffies, timeout)) { @@ -831,7 +831,7 @@ static int tower_probe (struct usb_interface *interface, const struct usb_device dev->read_buffer_length = 0; dev->read_packet_length = 0; spin_lock_init (&dev->read_buffer_lock); - dev->packet_timeout_jiffies = packet_timeout * HZ / 1000; + dev->packet_timeout_jiffies = msecs_to_jiffies(packet_timeout); dev->read_last_arrival = jiffies; init_waitqueue_head (&dev->read_wait); -- cgit v0.10.2 From e5401bf37a69620bdf079e4ee6c30a268f06f04b Mon Sep 17 00:00:00 2001 From: Lin Wang Date: Tue, 17 Mar 2015 18:32:21 +0200 Subject: xhci: unify cycle state toggling operation with 'XOR' Some toggling operation in xHCI driver still use conditional toggling: ring->cycle_state = (ring->cycle_state ? 0 : 1); Use XOR to invert the cycle state instead of a conditional toggle to unify cycle state toggling operation in xHCI driver. Signed-off-by: Lin Wang Signed-off-by: Mathias Nyman Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 5fb66db..da2ff50 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -238,7 +238,7 @@ static void inc_enq(struct xhci_hcd *xhci, struct xhci_ring *ring, /* Toggle the cycle bit after the last ring segment. */ if (last_trb_on_last_seg(xhci, ring, ring->enq_seg, next)) { - ring->cycle_state = (ring->cycle_state ? 0 : 1); + ring->cycle_state ^= 1; } } ring->enq_seg = ring->enq_seg->next; @@ -2809,7 +2809,7 @@ static int prepare_ring(struct xhci_hcd *xhci, struct xhci_ring *ep_ring, /* Toggle the cycle bit after the last ring segment. */ if (last_trb_on_last_seg(xhci, ring, ring->enq_seg, next)) { - ring->cycle_state = (ring->cycle_state ? 0 : 1); + ring->cycle_state ^= 1; } ring->enq_seg = ring->enq_seg->next; ring->enqueue = ring->enq_seg->trbs; -- cgit v0.10.2 From 7b8ef22ea547b80475ac7feab06fb15e0fc143d8 Mon Sep 17 00:00:00 2001 From: Maxime Ripard Date: Tue, 17 Mar 2015 18:32:22 +0200 Subject: usb: xhci: plat: Add USB phy support The Marvell Armada 385 AP needs a dumb phy in order to enable the USB3 VBUS. Add a call to retrieve a USB PHY to XHCI plat in order to support this. Signed-off-by: Maxime Ripard Signed-off-by: Mathias Nyman Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c index 0e11d61..783e819 100644 --- a/drivers/usb/host/xhci-plat.c +++ b/drivers/usb/host/xhci-plat.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -155,12 +156,27 @@ static int xhci_plat_probe(struct platform_device *pdev) if (HCC_MAX_PSA(xhci->hcc_params) >= 4) xhci->shared_hcd->can_do_streams = 1; + hcd->usb_phy = devm_usb_get_phy_by_phandle(&pdev->dev, "usb-phy", 0); + if (IS_ERR(hcd->usb_phy)) { + ret = PTR_ERR(hcd->usb_phy); + if (ret == -EPROBE_DEFER) + goto put_usb3_hcd; + hcd->usb_phy = NULL; + } else { + ret = usb_phy_init(hcd->usb_phy); + if (ret) + goto put_usb3_hcd; + } + ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED); if (ret) - goto put_usb3_hcd; + goto disable_usb_phy; return 0; +disable_usb_phy: + usb_phy_shutdown(hcd->usb_phy); + put_usb3_hcd: usb_put_hcd(xhci->shared_hcd); @@ -184,6 +200,7 @@ static int xhci_plat_remove(struct platform_device *dev) struct clk *clk = xhci->clk; usb_remove_hcd(xhci->shared_hcd); + usb_phy_shutdown(hcd->usb_phy); usb_put_hcd(xhci->shared_hcd); usb_remove_hcd(hcd); -- cgit v0.10.2 From b29582b15ff4049de5780e27a28ed7b3ded3f969 Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Thu, 5 Feb 2015 21:40:29 +0100 Subject: uwb/whci: Delete an unnecessary check before the function call "umc_device_unregister" The umc_device_unregister() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/uwb/whci.c b/drivers/uwb/whci.c index 46b7cfc..c3ee39a 100644 --- a/drivers/uwb/whci.c +++ b/drivers/uwb/whci.c @@ -133,8 +133,7 @@ static void whci_del_cap(struct whci_card *card, int n) { struct umc_dev *umc = card->devs[n]; - if (umc != NULL) - umc_device_unregister(umc); + umc_device_unregister(umc); } static int whci_n_caps(struct pci_dev *pci) -- cgit v0.10.2 From 28ed20755897b3726f07a0418c3d2fe17b3e5c86 Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Thu, 5 Feb 2015 16:54:12 +0100 Subject: USB: whci-hcd: Delete an unnecessary check before the function call "usb_put_hcd" The usb_put_hcd() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/host/whci/hcd.c b/drivers/usb/host/whci/hcd.c index d7b363a..43626c4 100644 --- a/drivers/usb/host/whci/hcd.c +++ b/drivers/usb/host/whci/hcd.c @@ -313,8 +313,7 @@ error_wusbhc_create: uwb_rc_put(wusbhc->uwb_rc); error: whc_clean_up(whc); - if (usb_hcd) - usb_put_hcd(usb_hcd); + usb_put_hcd(usb_hcd); return ret; } -- cgit v0.10.2 From 533726f736c2c32956d78ad6f49ffaada110cbfd Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Thu, 5 Feb 2015 16:33:09 +0100 Subject: ueagle-atm: Delete unnecessary checks before the function call "release_firmware" The release_firmware() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/atm/ueagle-atm.c b/drivers/usb/atm/ueagle-atm.c index 5a45937..888998a 100644 --- a/drivers/usb/atm/ueagle-atm.c +++ b/drivers/usb/atm/ueagle-atm.c @@ -952,7 +952,7 @@ static void uea_load_page_e1(struct work_struct *work) int i; /* reload firmware when reboot start and it's loaded already */ - if (ovl == 0 && pageno == 0 && sc->dsp_firm) { + if (ovl == 0 && pageno == 0) { release_firmware(sc->dsp_firm); sc->dsp_firm = NULL; } @@ -1074,7 +1074,7 @@ static void uea_load_page_e4(struct work_struct *work) uea_dbg(INS_TO_USBDEV(sc), "sending DSP page %u\n", pageno); /* reload firmware when reboot start and it's loaded already */ - if (pageno == 0 && sc->dsp_firm) { + if (pageno == 0) { release_firmware(sc->dsp_firm); sc->dsp_firm = NULL; } -- cgit v0.10.2 From c60b89aa3640ac4eb279213d93828a8100acb6b5 Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Thu, 5 Feb 2015 16:07:43 +0100 Subject: USB: appledisplay: Deletion of a check before backlight_device_unregister() The backlight_device_unregister() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c index b3d245e..a0a3827 100644 --- a/drivers/usb/misc/appledisplay.c +++ b/drivers/usb/misc/appledisplay.c @@ -329,7 +329,7 @@ error: pdata->urbdata, pdata->urb->transfer_dma); usb_free_urb(pdata->urb); } - if (pdata->bd && !IS_ERR(pdata->bd)) + if (!IS_ERR(pdata->bd)) backlight_device_unregister(pdata->bd); kfree(pdata->msgdata); } -- cgit v0.10.2 From c7b364f7dd82e8610373b8c6d788db867d7e99db Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 5 Feb 2015 14:36:25 +0100 Subject: USB: gadget: f_mass_storage: use static attribute groups for sysfs entries Instead of manual device_create_file() and device_remove_file() calls, assign the static attribute groups to the lun device to register. The RO or RW permissions for some entries are decided in is_visible callback. This simplifies the code (also the logic) and avoids the possible races, too. Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c index 811929c..49a2f19 100644 --- a/drivers/usb/gadget/function/f_mass_storage.c +++ b/drivers/usb/gadget/function/f_mass_storage.c @@ -2624,13 +2624,10 @@ static ssize_t file_store(struct device *dev, struct device_attribute *attr, return fsg_store_file(curlun, filesem, buf, count); } -static DEVICE_ATTR_RW(ro); static DEVICE_ATTR_RW(nofua); -static DEVICE_ATTR_RW(file); - -static struct device_attribute dev_attr_ro_cdrom = __ATTR_RO(ro); -static struct device_attribute dev_attr_file_nonremovable = __ATTR_RO(file); - +/* mode wil be set in fsg_lun_attr_is_visible() */ +static DEVICE_ATTR(ro, 0, ro_show, ro_store); +static DEVICE_ATTR(file, 0, file_show, file_store); /****************************** FSG COMMON ******************************/ @@ -2745,40 +2742,10 @@ error_release: } EXPORT_SYMBOL_GPL(fsg_common_set_num_buffers); -static inline void fsg_common_remove_sysfs(struct fsg_lun *lun) -{ - device_remove_file(&lun->dev, &dev_attr_nofua); - /* - * device_remove_file() => - * - * here the attr (e.g. dev_attr_ro) is only used to be passed to: - * - * sysfs_remove_file() => - * - * here e.g. both dev_attr_ro_cdrom and dev_attr_ro are in - * the same namespace and - * from here only attr->name is passed to: - * - * sysfs_hash_and_remove() - * - * attr->name is the same for dev_attr_ro_cdrom and - * dev_attr_ro - * attr->name is the same for dev_attr_file and - * dev_attr_file_nonremovable - * - * so we don't differentiate between removing e.g. dev_attr_ro_cdrom - * and dev_attr_ro - */ - device_remove_file(&lun->dev, &dev_attr_ro); - device_remove_file(&lun->dev, &dev_attr_file); -} - void fsg_common_remove_lun(struct fsg_lun *lun, bool sysfs) { - if (sysfs) { - fsg_common_remove_sysfs(lun); + if (sysfs) device_unregister(&lun->dev); - } fsg_lun_close(lun); kfree(lun); } @@ -2877,41 +2844,35 @@ int fsg_common_set_cdev(struct fsg_common *common, } EXPORT_SYMBOL_GPL(fsg_common_set_cdev); -static inline int fsg_common_add_sysfs(struct fsg_common *common, - struct fsg_lun *lun) -{ - int rc; +static struct attribute *fsg_lun_dev_attrs[] = { + &dev_attr_ro.attr, + &dev_attr_file.attr, + &dev_attr_nofua.attr, + NULL +}; - rc = device_register(&lun->dev); - if (rc) { - put_device(&lun->dev); - return rc; - } +static umode_t fsg_lun_dev_is_visible(struct kobject *kobj, + struct attribute *attr, int idx) +{ + struct device *dev = kobj_to_dev(kobj); + struct fsg_lun *lun = fsg_lun_from_dev(dev); - rc = device_create_file(&lun->dev, - lun->cdrom - ? &dev_attr_ro_cdrom - : &dev_attr_ro); - if (rc) - goto error; - rc = device_create_file(&lun->dev, - lun->removable - ? &dev_attr_file - : &dev_attr_file_nonremovable); - if (rc) - goto error; - rc = device_create_file(&lun->dev, &dev_attr_nofua); - if (rc) - goto error; + if (attr == &dev_attr_ro.attr) + return lun->cdrom ? S_IRUGO : (S_IWUSR | S_IRUGO); + if (attr == &dev_attr_file.attr) + return lun->removable ? (S_IWUSR | S_IRUGO) : S_IRUGO; + return attr->mode; +} - return 0; +static const struct attribute_group fsg_lun_dev_group = { + .attrs = fsg_lun_dev_attrs, + .is_visible = fsg_lun_dev_is_visible, +}; -error: - /* removing nonexistent files is a no-op */ - fsg_common_remove_sysfs(lun); - device_unregister(&lun->dev); - return rc; -} +static const struct attribute_group *fsg_lun_dev_groups[] = { + &fsg_lun_dev_group, + NULL +}; int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg, unsigned int id, const char *name, @@ -2949,13 +2910,15 @@ int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg, } else { lun->dev.release = fsg_lun_release; lun->dev.parent = &common->gadget->dev; + lun->dev.groups = fsg_lun_dev_groups; dev_set_drvdata(&lun->dev, &common->filesem); dev_set_name(&lun->dev, "%s", name); lun->name = dev_name(&lun->dev); - rc = fsg_common_add_sysfs(common, lun); + rc = device_register(&lun->dev); if (rc) { pr_info("failed to register LUN%d: %d\n", id, rc); + put_device(&lun->dev); goto error_sysfs; } } @@ -2988,10 +2951,8 @@ int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg, return 0; error_lun: - if (common->sysfs) { - fsg_common_remove_sysfs(lun); + if (common->sysfs) device_unregister(&lun->dev); - } fsg_lun_close(lun); common->luns[id] = NULL; error_sysfs: @@ -3077,8 +3038,6 @@ static void fsg_common_release(struct kref *ref) struct fsg_lun *lun = *lun_it; if (!lun) continue; - if (common->sysfs) - fsg_common_remove_sysfs(lun); fsg_lun_close(lun); if (common->sysfs) device_unregister(&lun->dev); -- cgit v0.10.2 From 0de846963586e6ba4133e273dcea66b2f0870db3 Mon Sep 17 00:00:00 2001 From: Bas Peters Date: Sat, 7 Feb 2015 23:42:42 +0100 Subject: drivers: usb: storage: alauda.c: properly place braces after function declarations This patch places braces on a new line following function declarations. Signed-off-by: Bas Peters Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/storage/alauda.c b/drivers/usb/storage/alauda.c index 62c2d9d..4b55ab6 100644 --- a/drivers/usb/storage/alauda.c +++ b/drivers/usb/storage/alauda.c @@ -207,7 +207,8 @@ static struct alauda_card_info alauda_card_ids[] = { { 0,} }; -static struct alauda_card_info *alauda_card_find_id(unsigned char id) { +static struct alauda_card_info *alauda_card_find_id(unsigned char id) +{ int i; for (i = 0; alauda_card_ids[i].id != 0; i++) @@ -223,7 +224,8 @@ static struct alauda_card_info *alauda_card_find_id(unsigned char id) { static unsigned char parity[256]; static unsigned char ecc2[256]; -static void nand_init_ecc(void) { +static void nand_init_ecc(void) +{ int i, j, a; parity[0] = 0; @@ -247,7 +249,8 @@ static void nand_init_ecc(void) { } /* compute 3-byte ecc on 256 bytes */ -static void nand_compute_ecc(unsigned char *data, unsigned char *ecc) { +static void nand_compute_ecc(unsigned char *data, unsigned char *ecc) +{ int i, j, a; unsigned char par = 0, bit, bits[8] = {0}; @@ -270,11 +273,13 @@ static void nand_compute_ecc(unsigned char *data, unsigned char *ecc) { ecc[2] = ecc2[par]; } -static int nand_compare_ecc(unsigned char *data, unsigned char *ecc) { +static int nand_compare_ecc(unsigned char *data, unsigned char *ecc) +{ return (data[0] == ecc[0] && data[1] == ecc[1] && data[2] == ecc[2]); } -static void nand_store_ecc(unsigned char *data, unsigned char *ecc) { +static void nand_store_ecc(unsigned char *data, unsigned char *ecc) +{ memcpy(data, ecc, 3); } -- cgit v0.10.2 From e9c585907f962a6ed55dc8382a0a606190c7cae0 Mon Sep 17 00:00:00 2001 From: Bas Peters Date: Sat, 7 Feb 2015 23:42:43 +0100 Subject: drivers: usb: storage: cypress_atacb.c: trivial checkpatch fixes Fixes errors thrown by checkpatch over a space issue and the incorrect indentation of a switch statement. Signed-off-by: Bas Peters Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/storage/cypress_atacb.c b/drivers/usb/storage/cypress_atacb.c index 8514a2d..b3466d1 100644 --- a/drivers/usb/storage/cypress_atacb.c +++ b/drivers/usb/storage/cypress_atacb.c @@ -96,13 +96,13 @@ static void cypress_atacb_passthrough(struct scsi_cmnd *srb, struct us_data *us) if (save_cmnd[1] >> 5) /* MULTIPLE_COUNT */ goto invalid_fld; /* check protocol */ - switch((save_cmnd[1] >> 1) & 0xf) { - case 3: /*no DATA */ - case 4: /* PIO in */ - case 5: /* PIO out */ - break; - default: - goto invalid_fld; + switch ((save_cmnd[1] >> 1) & 0xf) { + case 3: /*no DATA */ + case 4: /* PIO in */ + case 5: /* PIO out */ + break; + default: + goto invalid_fld; } /* first build the ATACB command */ @@ -132,8 +132,7 @@ static void cypress_atacb_passthrough(struct scsi_cmnd *srb, struct us_data *us) || save_cmnd[11]) goto invalid_fld; } - } - else { /* ATA12 */ + } else { /* ATA12 */ srb->cmnd[ 6] = save_cmnd[3]; /* features */ srb->cmnd[ 7] = save_cmnd[4]; /* sector count */ srb->cmnd[ 8] = save_cmnd[5]; /* lba low */ -- cgit v0.10.2 From 333c65bc8b2482dbbb46f4223381160333aaaddd Mon Sep 17 00:00:00 2001 From: Yannick Guerrini Date: Tue, 24 Feb 2015 16:42:45 +0100 Subject: usb: storage: Fix trivial typo in isd200_log_config() Change 'Supsend' to 'Suspend' Signed-off-by: Yannick Guerrini Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/storage/isd200.c b/drivers/usb/storage/isd200.c index 599d8bf..0761786 100644 --- a/drivers/usb/storage/isd200.c +++ b/drivers/usb/storage/isd200.c @@ -737,7 +737,7 @@ static void isd200_log_config(struct us_data *us, struct isd200_info *info) info->ConfigData.ATAExtraConfig & ATACFGE_CONF_DESC2); usb_stor_dbg(us, " Skip Device Boot: 0x%x\n", info->ConfigData.ATAExtraConfig & ATACFGE_SKIP_BOOT); - usb_stor_dbg(us, " ATA 3 State Supsend: 0x%x\n", + usb_stor_dbg(us, " ATA 3 State Suspend: 0x%x\n", info->ConfigData.ATAExtraConfig & ATACFGE_STATE_SUSPEND); usb_stor_dbg(us, " Descriptor Override: 0x%x\n", info->ConfigData.ATAExtraConfig & ATACFGE_DESC_OVERRIDE); -- cgit v0.10.2 From 8f116d1c12580b7c2349e3291d22621ee21b08a0 Mon Sep 17 00:00:00 2001 From: Zhangfei Gao Date: Thu, 12 Feb 2015 16:18:09 +0800 Subject: usb: load usb phy earlier USB PHY works proper is the base for the coming USB controller operation. With this patch, it can avoid the controller drivers which are linked earlier than USB PHY always being probed deferral. Look at drivers/Makefile, it links phy first with the similar method. Signed-off-by: Zhangfei Gao Acked-by: Peter Chen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile index 2f1e2aa..d8926c6 100644 --- a/drivers/usb/Makefile +++ b/drivers/usb/Makefile @@ -5,6 +5,7 @@ # Object files in subdirectories obj-$(CONFIG_USB) += core/ +obj-$(CONFIG_USB_SUPPORT) += phy/ obj-$(CONFIG_USB_DWC3) += dwc3/ obj-$(CONFIG_USB_DWC2) += dwc2/ @@ -48,7 +49,6 @@ obj-$(CONFIG_USB_MICROTEK) += image/ obj-$(CONFIG_USB_SERIAL) += serial/ obj-$(CONFIG_USB) += misc/ -obj-$(CONFIG_USB_SUPPORT) += phy/ obj-$(CONFIG_EARLY_PRINTK_DBGP) += early/ obj-$(CONFIG_USB_ATM) += atm/ -- cgit v0.10.2 From 26d4a1e9c4aaa7799a71524c871214bd7448d430 Mon Sep 17 00:00:00 2001 From: Sudeep Holla Date: Wed, 4 Mar 2015 17:07:57 +0000 Subject: usb: isp1760: fix possible deadlock in isp1760_udc_irq Use spin_{un,}lock_irq{save,restore} in isp1760_udc_{start,stop} to prevent following potentially deadlock scenario between isp1760_udc_{start,stop} and isp1760_udc_irq : ================================= [ INFO: inconsistent lock state ] 4.0.0-rc2-00004-gf7bb2ef60173 #51 Not tainted --------------------------------- inconsistent {HARDIRQ-ON-W} -> {IN-HARDIRQ-W} usage. in:imklog/2118 [HC1[1]:SC0[0]:HE0:SE1] takes: (&(&udc->lock)->rlock){?.+...}, at: [] isp1760_udc_irq+0x367/0x9dc {HARDIRQ-ON-W} state was registered at: [] _raw_spin_lock+0x23/0x30 [] isp1760_udc_start+0x23/0xf8 [] udc_bind_to_driver+0x71/0xb0 [] usb_gadget_probe_driver+0x53/0x9c [] usb_composite_probe+0x8a/0xa4 [libcomposite] [] 0xbf8311a7 [] do_one_initcall+0x8d/0x17c [] do_init_module+0x49/0x148 [] load_module+0xb7f/0xbc4 [] SyS_finit_module+0x51/0x74 [] ret_fast_syscall+0x1/0x68 irq event stamp: 4966 hardirqs last enabled at (4965): [] _raw_spin_unlock_irq+0x1f/0x24 hardirqs last disabled at (4966): [] __irq_svc+0x33/0x64 softirqs last enabled at (4458): [] __do_softirq+0x23d/0x2d0 softirqs last disabled at (4389): [] irq_exit+0xef/0x15c other info that might help us debug this: Possible unsafe locking scenario: CPU0 ---- lock(&(&udc->lock)->rlock); lock(&(&udc->lock)->rlock); *** DEADLOCK *** 1 lock held by in:imklog/2118: #0: (&f->f_pos_lock){+.+.+.}, at: [] __fdget_pos+0x31/0x34 Signed-off-by: Sudeep Holla Cc: Laurent Pinchart Cc: Greg Kroah-Hartman Cc: Felipe Balbi Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/isp1760/isp1760-udc.c b/drivers/usb/isp1760/isp1760-udc.c index 9612d79..19e6a17 100644 --- a/drivers/usb/isp1760/isp1760-udc.c +++ b/drivers/usb/isp1760/isp1760-udc.c @@ -1191,6 +1191,7 @@ static int isp1760_udc_start(struct usb_gadget *gadget, struct usb_gadget_driver *driver) { struct isp1760_udc *udc = gadget_to_udc(gadget); + unsigned long flags; /* The hardware doesn't support low speed. */ if (driver->max_speed < USB_SPEED_FULL) { @@ -1198,7 +1199,7 @@ static int isp1760_udc_start(struct usb_gadget *gadget, return -EINVAL; } - spin_lock(&udc->lock); + spin_lock_irqsave(&udc->lock, flags); if (udc->driver) { dev_err(udc->isp->dev, "UDC already has a gadget driver\n"); @@ -1208,7 +1209,7 @@ static int isp1760_udc_start(struct usb_gadget *gadget, udc->driver = driver; - spin_unlock(&udc->lock); + spin_unlock_irqrestore(&udc->lock, flags); dev_dbg(udc->isp->dev, "starting UDC with driver %s\n", driver->function); @@ -1232,6 +1233,7 @@ static int isp1760_udc_start(struct usb_gadget *gadget, static int isp1760_udc_stop(struct usb_gadget *gadget) { struct isp1760_udc *udc = gadget_to_udc(gadget); + unsigned long flags; dev_dbg(udc->isp->dev, "%s\n", __func__); @@ -1239,9 +1241,9 @@ static int isp1760_udc_stop(struct usb_gadget *gadget) isp1760_udc_write(udc, DC_MODE, 0); - spin_lock(&udc->lock); + spin_lock_irqsave(&udc->lock, flags); udc->driver = NULL; - spin_unlock(&udc->lock); + spin_unlock_irqrestore(&udc->lock, flags); return 0; } -- cgit v0.10.2 From 3370b0af910166e387cf4b3faeaa8b5f0cb53f29 Mon Sep 17 00:00:00 2001 From: Sudeep Holla Date: Thu, 26 Feb 2015 11:47:57 +0000 Subject: usb: isp1760: add peripheral/device controller chip id As per the SAF1761 data sheet[0], the DcChipID register represents the hardware version number (0001h) and the chip ID (1582h) for the Peripheral Controller. However as per the ISP1761 data sheet[1], the DcChipID register represents the hardware version number (0015h) and the chip ID (8210h) for the Peripheral Controller. This patch adds support for both the chip ID values. [0] http://www.nxp.com/documents/data_sheet/SAF1761.pdf [1] http://pdf.datasheetcatalog.com/datasheets2/74/742102_1.pdf Cc: Felipe Balbi Signed-off-by: Sudeep Holla Acked-by: Laurent Pinchart Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/isp1760/isp1760-udc.c b/drivers/usb/isp1760/isp1760-udc.c index 19e6a17..fbfbd59 100644 --- a/drivers/usb/isp1760/isp1760-udc.c +++ b/drivers/usb/isp1760/isp1760-udc.c @@ -1413,7 +1413,7 @@ static int isp1760_udc_init(struct isp1760_udc *udc) return -ENODEV; } - if (chipid != 0x00011582) { + if (chipid != 0x00011582 && chipid != 0x00158210) { dev_err(udc->isp->dev, "udc: invalid chip ID 0x%08x\n", chipid); return -ENODEV; } -- cgit v0.10.2 From f1f0b57db01d1045d163eeb05d5a4e7bd934561a Mon Sep 17 00:00:00 2001 From: Fabian Frederick Date: Mon, 16 Mar 2015 20:20:27 +0100 Subject: usb: gadget: constify of_device_id array of_device_id is always used as const. (See driver.of_match_table and open firmware functions) Signed-off-by: Fabian Frederick Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/gadget/udc/pxa27x_udc.c b/drivers/usb/gadget/udc/pxa27x_udc.c index 6a855fc..f0ae143 100644 --- a/drivers/usb/gadget/udc/pxa27x_udc.c +++ b/drivers/usb/gadget/udc/pxa27x_udc.c @@ -2399,7 +2399,7 @@ static struct pxa_udc memory = { }; #if defined(CONFIG_OF) -static struct of_device_id udc_pxa_dt_ids[] = { +static const struct of_device_id udc_pxa_dt_ids[] = { { .compatible = "marvell,pxa270-udc" }, {} }; -- cgit v0.10.2 From c5b68807c6563bf3882c94268ca09198d2e574ae Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sun, 15 Mar 2015 18:03:00 +0100 Subject: uwb: Remove umc bus legacy suspend/resume support There are currently no umc drivers implementing suspend/resume, so remove the legacy suspend/resume support from the framework. If a umc driver ever wants to implement suspend/resume they can use dev_pm_ops, which works out of the box without any additional support necessary from the bus itself. Signed-off-by: Lars-Peter Clausen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/uwb/umc-bus.c b/drivers/uwb/umc-bus.c index 88a290f..c857140 100644 --- a/drivers/uwb/umc-bus.c +++ b/drivers/uwb/umc-bus.c @@ -163,38 +163,6 @@ static int umc_device_remove(struct device *dev) return 0; } -static int umc_device_suspend(struct device *dev, pm_message_t state) -{ - struct umc_dev *umc; - struct umc_driver *umc_driver; - int err = 0; - - umc = to_umc_dev(dev); - - if (dev->driver) { - umc_driver = to_umc_driver(dev->driver); - if (umc_driver->suspend) - err = umc_driver->suspend(umc, state); - } - return err; -} - -static int umc_device_resume(struct device *dev) -{ - struct umc_dev *umc; - struct umc_driver *umc_driver; - int err = 0; - - umc = to_umc_dev(dev); - - if (dev->driver) { - umc_driver = to_umc_driver(dev->driver); - if (umc_driver->resume) - err = umc_driver->resume(umc); - } - return err; -} - static ssize_t capability_id_show(struct device *dev, struct device_attribute *attr, char *buf) { struct umc_dev *umc = to_umc_dev(dev); @@ -223,8 +191,6 @@ struct bus_type umc_bus_type = { .match = umc_bus_match, .probe = umc_device_probe, .remove = umc_device_remove, - .suspend = umc_device_suspend, - .resume = umc_device_resume, .dev_groups = umc_dev_groups, }; EXPORT_SYMBOL_GPL(umc_bus_type); diff --git a/include/linux/uwb/umc.h b/include/linux/uwb/umc.h index ba82f03..0211229 100644 --- a/include/linux/uwb/umc.h +++ b/include/linux/uwb/umc.h @@ -87,8 +87,6 @@ struct umc_driver { int (*probe)(struct umc_dev *); void (*remove)(struct umc_dev *); - int (*suspend)(struct umc_dev *, pm_message_t state); - int (*resume)(struct umc_dev *); int (*pre_reset)(struct umc_dev *); int (*post_reset)(struct umc_dev *); -- cgit v0.10.2 From ebfd44ffb78a0f06ea5437996153d5b1e017c2d7 Mon Sep 17 00:00:00 2001 From: Stephen Boyd Date: Fri, 13 Mar 2015 11:09:41 -0700 Subject: ehci-msm: Remove dead dependency This dependency no longer exists now that mach-msm has been removed. Delete it. Cc: Greg Kroah-Hartman Cc: Alan Stern Cc: linux-usb@vger.kernel.org Cc: David Brown Cc: Bryan Huntsman Cc: Daniel Walker Signed-off-by: Stephen Boyd Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig index 5ad60e4..197a6a3 100644 --- a/drivers/usb/host/Kconfig +++ b/drivers/usb/host/Kconfig @@ -198,7 +198,7 @@ config USB_EHCI_HCD_AT91 config USB_EHCI_MSM tristate "Support for Qualcomm QSD/MSM on-chip EHCI USB controller" - depends on ARCH_MSM || ARCH_QCOM + depends on ARCH_QCOM select USB_EHCI_ROOT_HUB_TT ---help--- Enables support for the USB Host controller present on the -- cgit v0.10.2 From 32fc9eb5b2dcebefb7fb4c8288c739c320362524 Mon Sep 17 00:00:00 2001 From: Stephen Boyd Date: Fri, 13 Mar 2015 11:09:42 -0700 Subject: usb: phy: msm: Remove dead code This code is no longer used now that mach-msm has been removed. Delete it. Cc: Felipe Balbi Cc: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org Cc: David Brown Cc: Bryan Huntsman Cc: Daniel Walker Signed-off-by: Stephen Boyd Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig index 52d3d58..2fb3828 100644 --- a/drivers/usb/phy/Kconfig +++ b/drivers/usb/phy/Kconfig @@ -139,7 +139,7 @@ config USB_ISP1301 config USB_MSM_OTG tristate "Qualcomm on-chip USB OTG controller support" - depends on (USB || USB_GADGET) && (ARCH_MSM || ARCH_QCOM || COMPILE_TEST) + depends on (USB || USB_GADGET) && (ARCH_QCOM || COMPILE_TEST) depends on RESET_CONTROLLER select USB_PHY help diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c index 000fd89..b50c45c 100644 --- a/drivers/usb/phy/phy-msm-usb.c +++ b/drivers/usb/phy/phy-msm-usb.c @@ -263,9 +263,7 @@ static int msm_otg_link_clk_reset(struct msm_otg *motg, bool assert) { int ret; - if (motg->pdata->link_clk_reset) - ret = motg->pdata->link_clk_reset(motg->clk, assert); - else if (assert) + if (assert) ret = reset_control_assert(motg->link_rst); else ret = reset_control_deassert(motg->link_rst); @@ -281,9 +279,7 @@ static int msm_otg_phy_clk_reset(struct msm_otg *motg) { int ret = 0; - if (motg->pdata->phy_clk_reset) - ret = motg->pdata->phy_clk_reset(motg->phy_reset_clk); - else if (motg->phy_rst) + if (motg->phy_rst) ret = reset_control_reset(motg->phy_rst); if (ret) @@ -1551,16 +1547,6 @@ static int msm_otg_probe(struct platform_device *pdev) phy = &motg->phy; phy->dev = &pdev->dev; - if (motg->pdata->phy_clk_reset) { - motg->phy_reset_clk = devm_clk_get(&pdev->dev, - np ? "phy" : "usb_phy_clk"); - - if (IS_ERR(motg->phy_reset_clk)) { - dev_err(&pdev->dev, "failed to get usb_phy_clk\n"); - return PTR_ERR(motg->phy_reset_clk); - } - } - motg->clk = devm_clk_get(&pdev->dev, np ? "core" : "usb_hs_clk"); if (IS_ERR(motg->clk)) { dev_err(&pdev->dev, "failed to get usb_hs_clk\n"); diff --git a/include/linux/usb/msm_hsusb.h b/include/linux/usb/msm_hsusb.h index b0a3924..7dbecf9 100644 --- a/include/linux/usb/msm_hsusb.h +++ b/include/linux/usb/msm_hsusb.h @@ -117,8 +117,6 @@ struct msm_otg_platform_data { enum otg_control_type otg_control; enum msm_usb_phy_type phy_type; void (*setup_gpio)(enum usb_otg_state state); - int (*link_clk_reset)(struct clk *link_clk, bool assert); - int (*phy_clk_reset)(struct clk *phy_clk); }; /** @@ -128,7 +126,6 @@ struct msm_otg_platform_data { * @irq: IRQ number assigned for HSUSB controller. * @clk: clock struct of usb_hs_clk. * @pclk: clock struct of usb_hs_pclk. - * @phy_reset_clk: clock struct of usb_phy_clk. * @core_clk: clock struct of usb_hs_core_clk. * @regs: ioremapped register base address. * @inputs: OTG state machine inputs(Id, SessValid etc). @@ -148,7 +145,6 @@ struct msm_otg { int irq; struct clk *clk; struct clk *pclk; - struct clk *phy_reset_clk; struct clk *core_clk; void __iomem *regs; #define ID 0 -- cgit v0.10.2 From 7252f1bfd4bc97ec4b5fa7adaf3a1a45c325635c Mon Sep 17 00:00:00 2001 From: Vincent Palatin Date: Sun, 15 Mar 2015 13:24:32 -0700 Subject: usb: dwc2: avoid leaking DMA channels on disconnection When the HCD is disconnected, the DMA transfers still in-flight were cleaned-up but the count of available DMA channels (e.g. available_host_channels) was not reset. The pool of DMA channels can be depleted when doing unclean disconnection of USB peripherals, and reaches the point where no transfer was possible until the next reboot/reload of the driver. Tested by putting a programmable USB mux on the port and randomly plugging/unpluging a USB HUB with USB mass-storage key, USB-audio and USB-ethernet dongle connected to its downstream ports, and also doing the disconnection early while the devices are still enumerating to get more URBs in-flight. After the patch, the devices are still enumerating after thousands of cycles, while the port was totally dead before. Signed-off-by: Vincent Palatin Acked-by: John Youn Signed-off-by: Felipe Balbi diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index c78c874..559b55e 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c @@ -257,6 +257,14 @@ static void dwc2_hcd_cleanup_channels(struct dwc2_hsotg *hsotg) */ channel->qh = NULL; } + /* All channels have been freed, mark them available */ + if (hsotg->core_params->uframe_sched > 0) { + hsotg->available_host_channels = + hsotg->core_params->host_channels; + } else { + hsotg->non_periodic_channels = 0; + hsotg->periodic_channels = 0; + } } /** -- cgit v0.10.2 From dfea9c94837d27e38c8cc85a3c1c7c268973c3c2 Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Fri, 6 Mar 2015 10:36:02 +0800 Subject: usb: udc: store usb_udc pointer in struct usb_gadget Instead of iterate to find usb_udc according to usb_gadget, this way is easier. Alan Stern suggests this way too: http://marc.info/?l=linux-usb&m=142168496528894&w=2 Acked-by: Alan Stern Signed-off-by: Peter Chen Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/udc/udc-core.c b/drivers/usb/gadget/udc/udc-core.c index 5a81cb0..bf7ed77 100644 --- a/drivers/usb/gadget/udc/udc-core.c +++ b/drivers/usb/gadget/udc/udc-core.c @@ -128,21 +128,11 @@ EXPORT_SYMBOL_GPL(usb_gadget_giveback_request); static void usb_gadget_state_work(struct work_struct *work) { - struct usb_gadget *gadget = work_to_gadget(work); - struct usb_udc *udc = NULL; - - mutex_lock(&udc_lock); - list_for_each_entry(udc, &udc_list, list) - if (udc->gadget == gadget) - goto found; - mutex_unlock(&udc_lock); + struct usb_gadget *gadget = work_to_gadget(work); + struct usb_udc *udc = gadget->udc; - return; - -found: - mutex_unlock(&udc_lock); - - sysfs_notify(&udc->dev.kobj, NULL, "state"); + if (udc) + sysfs_notify(&udc->dev.kobj, NULL, "state"); } void usb_gadget_set_state(struct usb_gadget *gadget, @@ -278,6 +268,7 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, goto err3; udc->gadget = gadget; + gadget->udc = udc; mutex_lock(&udc_lock); list_add_tail(&udc->list, &udc_list); @@ -348,21 +339,14 @@ static void usb_gadget_remove_driver(struct usb_udc *udc) */ void usb_del_gadget_udc(struct usb_gadget *gadget) { - struct usb_udc *udc = NULL; + struct usb_udc *udc = gadget->udc; - mutex_lock(&udc_lock); - list_for_each_entry(udc, &udc_list, list) - if (udc->gadget == gadget) - goto found; - - dev_err(gadget->dev.parent, "gadget not registered.\n"); - mutex_unlock(&udc_lock); - - return; + if (!udc) + return; -found: dev_vdbg(gadget->dev.parent, "unregistering gadget\n"); + mutex_lock(&udc_lock); list_del(&udc->list); mutex_unlock(&udc_lock); diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h index 02476b3..242c694 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -474,6 +474,7 @@ struct usb_dcd_config_params { struct usb_gadget; struct usb_gadget_driver; +struct usb_udc; /* the rest of the api to the controller hardware: device operations, * which don't involve endpoints (or i/o). @@ -496,6 +497,7 @@ struct usb_gadget_ops { /** * struct usb_gadget - represents a usb slave device * @work: (internal use) Workqueue to be used for sysfs_notify() + * @udc: struct usb_udc pointer for this gadget * @ops: Function pointers used to access hardware-specific operations. * @ep0: Endpoint zero, used when reading or writing responses to * driver setup() requests @@ -545,6 +547,7 @@ struct usb_gadget_ops { */ struct usb_gadget { struct work_struct work; + struct usb_udc *udc; /* readonly to gadget driver */ const struct usb_gadget_ops *ops; struct usb_ep *ep0; -- cgit v0.10.2 From 628ef0d273a69d889669a459fb4675c678ae0418 Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Fri, 6 Mar 2015 10:36:03 +0800 Subject: usb: udc: add usb_udc_vbus_handler This commit updates udc core vbus status, and try to connect or disconnect gadget. Signed-off-by: Peter Chen Acked-by: Alan Stern Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/udc/udc-core.c b/drivers/usb/gadget/udc/udc-core.c index bf7ed77..d69c355 100644 --- a/drivers/usb/gadget/udc/udc-core.c +++ b/drivers/usb/gadget/udc/udc-core.c @@ -35,6 +35,8 @@ * @dev - the child device to the actual controller * @gadget - the gadget. For use by the class code * @list - for use by the udc class driver + * @vbus - for udcs who care about vbus status, this value is real vbus status; + * for udcs who do not care about vbus status, this value is always true * * This represents the internal data structure which is used by the UDC-class * to hold information about udc driver and gadget together. @@ -44,6 +46,7 @@ struct usb_udc { struct usb_gadget *gadget; struct device dev; struct list_head list; + bool vbus; }; static struct class *udc_class; @@ -145,6 +148,34 @@ EXPORT_SYMBOL_GPL(usb_gadget_set_state); /* ------------------------------------------------------------------------- */ +static void usb_udc_connect_control(struct usb_udc *udc) +{ + if (udc->vbus) + usb_gadget_connect(udc->gadget); + else + usb_gadget_disconnect(udc->gadget); +} + +/** + * usb_udc_vbus_handler - updates the udc core vbus status, and try to + * connect or disconnect gadget + * @gadget: The gadget which vbus change occurs + * @status: The vbus status + * + * The udc driver calls it when it wants to connect or disconnect gadget + * according to vbus status. + */ +void usb_udc_vbus_handler(struct usb_gadget *gadget, bool status) +{ + struct usb_udc *udc = gadget->udc; + + if (udc) { + udc->vbus = status; + usb_udc_connect_control(udc); + } +} +EXPORT_SYMBOL_GPL(usb_udc_vbus_handler); + /** * usb_gadget_udc_reset - notifies the udc core that bus reset occurs * @gadget: The gadget which bus reset occurs @@ -278,6 +309,7 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, goto err4; usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED); + udc->vbus = true; mutex_unlock(&udc_lock); @@ -381,7 +413,7 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *dri driver->unbind(udc->gadget); goto err1; } - usb_gadget_connect(udc->gadget); + usb_udc_connect_control(udc); kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); return 0; diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h index 242c694..4f3dfb7 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -1032,6 +1032,10 @@ extern void usb_gadget_udc_reset(struct usb_gadget *gadget, extern void usb_gadget_giveback_request(struct usb_ep *ep, struct usb_request *req); +/*-------------------------------------------------------------------------*/ + +/* utility to update vbus status for udc core, it may be scheduled */ +extern void usb_udc_vbus_handler(struct usb_gadget *gadget, bool status); /*-------------------------------------------------------------------------*/ -- cgit v0.10.2 From 467a78c82ad5f9a3e3c80eb4ba17de6bb70e4f9b Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Fri, 6 Mar 2015 10:36:04 +0800 Subject: usb: chipidea: udc: apply new usb_udc_vbus_handler interface It can move all pullup/pulldown operation control to udc-core through usb_gadget_connect/usb_gadget_disconnect according to vbus status. Signed-off-by: Peter Chen Signed-off-by: Felipe Balbi diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c index ff45104..55a36e0 100644 --- a/drivers/usb/chipidea/udc.c +++ b/drivers/usb/chipidea/udc.c @@ -86,10 +86,8 @@ static int hw_device_state(struct ci_hdrc *ci, u32 dma) /* interrupt, error, port change, reset, sleep/suspend */ hw_write(ci, OP_USBINTR, ~0, USBi_UI|USBi_UEI|USBi_PCI|USBi_URI|USBi_SLI); - hw_write(ci, OP_USBCMD, USBCMD_RS, USBCMD_RS); } else { hw_write(ci, OP_USBINTR, ~0, 0); - hw_write(ci, OP_USBCMD, USBCMD_RS, 0); } return 0; } @@ -1474,7 +1472,9 @@ static int ci_udc_vbus_session(struct usb_gadget *_gadget, int is_active) hw_device_reset(ci); hw_device_state(ci, ci->ep0out->qh.dma); usb_gadget_set_state(_gadget, USB_STATE_POWERED); + usb_udc_vbus_handler(_gadget, true); } else { + usb_udc_vbus_handler(_gadget, false); if (ci->driver) ci->driver->disconnect(&ci->gadget); hw_device_state(ci, 0); @@ -1540,13 +1540,12 @@ static int ci_udc_pullup(struct usb_gadget *_gadget, int is_on) { struct ci_hdrc *ci = container_of(_gadget, struct ci_hdrc, gadget); - if (!ci->vbus_active) - return -EOPNOTSUPP; - + pm_runtime_get_sync(&ci->gadget.dev); if (is_on) hw_write(ci, OP_USBCMD, USBCMD_RS, USBCMD_RS); else hw_write(ci, OP_USBCMD, USBCMD_RS, 0); + pm_runtime_put_sync(&ci->gadget.dev); return 0; } @@ -1676,6 +1675,7 @@ static int ci_udc_start(struct usb_gadget *gadget, spin_lock_irqsave(&ci->lock, flags); hw_device_reset(ci); } else { + usb_udc_vbus_handler(&ci->gadget, false); pm_runtime_put_sync(&ci->gadget.dev); return retval; } -- cgit v0.10.2 From 869aee0f31429fa9d94d5aef539602b73ae0cf4b Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Thu, 12 Mar 2015 09:15:28 +0800 Subject: usb: phy: Find the right match in devm_usb_phy_match The res parameter passed to devm_usb_phy_match() is the location where the pointer to the usb_phy is stored, hence it needs to be dereferenced before comparing to the match data in order to find the correct match. Fixes: 410219dcd2ba ("usb: otg: utils: devres: Add API's to associate a device with the phy") Signed-off-by: Axel Lin Cc: # v3.6+ Signed-off-by: Felipe Balbi diff --git a/drivers/usb/phy/phy.c b/drivers/usb/phy/phy.c index 2f9735b..d1cd6b5 100644 --- a/drivers/usb/phy/phy.c +++ b/drivers/usb/phy/phy.c @@ -81,7 +81,9 @@ static void devm_usb_phy_release(struct device *dev, void *res) static int devm_usb_phy_match(struct device *dev, void *res, void *match_data) { - return res == match_data; + struct usb_phy **phy = res; + + return *phy == match_data; } /** -- cgit v0.10.2 From 990919cad55a8c38fc73b0a6a0c9e5e4e927a5f8 Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Thu, 12 Mar 2015 09:47:53 +0800 Subject: usb: common: otg-fsm: only signal connect after switching to peripheral We should signal connect (pull up dp) after we have already at peripheral mode, otherwise, the dp may be toggled due to we reset controller or do disconnect during the initialization for peripheral, then, the host may be confused during the enumeration, eg, it finds the reset can't succeed, but the device is still there, see below error message. hub 1-0:1.0: USB hub found hub 1-0:1.0: 1 port detected hub 1-0:1.0: cannot reset port 1 (err = -32) hub 1-0:1.0: cannot reset port 1 (err = -32) hub 1-0:1.0: cannot reset port 1 (err = -32) hub 1-0:1.0: cannot reset port 1 (err = -32) hub 1-0:1.0: cannot reset port 1 (err = -32) hub 1-0:1.0: Cannot enable port 1. Maybe the USB cable is bad? hub 1-0:1.0: cannot reset port 1 (err = -32) hub 1-0:1.0: cannot reset port 1 (err = -32) hub 1-0:1.0: cannot reset port 1 (err = -32) hub 1-0:1.0: cannot reset port 1 (err = -32) hub 1-0:1.0: cannot reset port 1 (err = -32) hub 1-0:1.0: Cannot enable port 1. Maybe the USB cable is bad? hub 1-0:1.0: cannot reset port 1 (err = -32) hub 1-0:1.0: cannot reset port 1 (err = -32) hub 1-0:1.0: cannot reset port 1 (err = -32) hub 1-0:1.0: cannot reset port 1 (err = -32) hub 1-0:1.0: cannot reset port 1 (err = -32) hub 1-0:1.0: Cannot enable port 1. Maybe the USB cable is bad? hub 1-0:1.0: cannot reset port 1 (err = -32) hub 1-0:1.0: cannot reset port 1 (err = -32) hub 1-0:1.0: cannot reset port 1 (err = -32) hub 1-0:1.0: cannot reset port 1 (err = -32) hub 1-0:1.0: cannot reset port 1 (err = -32) hub 1-0:1.0: Cannot enable port 1. Maybe the USB cable is bad? hub 1-0:1.0: unable to enumerate USB device on port 1 Fixes: the issue existed when the otg fsm code was added. Cc: # v3.16+ Signed-off-by: Peter Chen Signed-off-by: Felipe Balbi diff --git a/drivers/usb/common/usb-otg-fsm.c b/drivers/usb/common/usb-otg-fsm.c index c6b35b7..61d538a 100644 --- a/drivers/usb/common/usb-otg-fsm.c +++ b/drivers/usb/common/usb-otg-fsm.c @@ -150,9 +150,9 @@ static int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state) break; case OTG_STATE_B_PERIPHERAL: otg_chrg_vbus(fsm, 0); - otg_loc_conn(fsm, 1); otg_loc_sof(fsm, 0); otg_set_protocol(fsm, PROTO_GADGET); + otg_loc_conn(fsm, 1); break; case OTG_STATE_B_WAIT_ACON: otg_chrg_vbus(fsm, 0); @@ -213,10 +213,10 @@ static int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state) break; case OTG_STATE_A_PERIPHERAL: - otg_loc_conn(fsm, 1); otg_loc_sof(fsm, 0); otg_set_protocol(fsm, PROTO_GADGET); otg_drv_vbus(fsm, 1); + otg_loc_conn(fsm, 1); otg_add_timer(fsm, A_BIDL_ADIS); break; case OTG_STATE_A_WAIT_VFALL: -- cgit v0.10.2 From 00f30d29b497577954b20237b405e9d22b5286c2 Mon Sep 17 00:00:00 2001 From: Yoshihiro Shimoda Date: Mon, 16 Mar 2015 16:36:48 +0900 Subject: usb: renesas_usbhs: fix spinlock suspected in a gadget complete function According to the gadget.h, a "complete" function will always be called with interrupts disabled. However, sometimes usbhsg_queue_pop() function is called with interrupts enabled. So, this function should be held by usbhs_lock() to disable interruption. Also, this driver has to call spin_unlock() to avoid spinlock recursion by this driver before calling usb_gadget_giveback_request(). Otherwise, there is possible to cause a spinlock suspected in a gadget complete function. Signed-off-by: Yoshihiro Shimoda Signed-off-by: Felipe Balbi diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c b/drivers/usb/renesas_usbhs/mod_gadget.c index e0384af..dc2aa32 100644 --- a/drivers/usb/renesas_usbhs/mod_gadget.c +++ b/drivers/usb/renesas_usbhs/mod_gadget.c @@ -119,18 +119,34 @@ struct usbhsg_recip_handle { /* * queue push/pop */ -static void usbhsg_queue_pop(struct usbhsg_uep *uep, - struct usbhsg_request *ureq, - int status) +static void __usbhsg_queue_pop(struct usbhsg_uep *uep, + struct usbhsg_request *ureq, + int status) { struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep); struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep); struct device *dev = usbhsg_gpriv_to_dev(gpriv); + struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv); dev_dbg(dev, "pipe %d : queue pop\n", usbhs_pipe_number(pipe)); ureq->req.status = status; + spin_unlock(usbhs_priv_to_lock(priv)); usb_gadget_giveback_request(&uep->ep, &ureq->req); + spin_lock(usbhs_priv_to_lock(priv)); +} + +static void usbhsg_queue_pop(struct usbhsg_uep *uep, + struct usbhsg_request *ureq, + int status) +{ + struct usbhsg_gpriv *gpriv = usbhsg_uep_to_gpriv(uep); + struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv); + unsigned long flags; + + usbhs_lock(priv, flags); + __usbhsg_queue_pop(uep, ureq, status); + usbhs_unlock(priv, flags); } static void usbhsg_queue_done(struct usbhs_priv *priv, struct usbhs_pkt *pkt) -- cgit v0.10.2 From 557f3586aaac0202010eb70e00d2694437f0cb37 Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Mon, 16 Mar 2015 11:09:38 -0700 Subject: usb: gadget: goku_udc: Remove uses of seq_ return values The seq_printf/seq_puts/seq_putc return values, because they are frequently misused, will eventually be converted to void. See: commit 1f33c41c03da ("seq_file: Rename seq_overflow() to seq_has_overflowed() and make public") Miscellanea: o Coalesce formats, realign arguments o Create static functions for statement expression macros o Use c90 style comments instead of c99 Signed-off-by: Joe Perches Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/udc/goku_udc.c b/drivers/usb/gadget/udc/goku_udc.c index 5b9176e..9e8d842 100644 --- a/drivers/usb/gadget/udc/goku_udc.c +++ b/drivers/usb/gadget/udc/goku_udc.c @@ -1024,35 +1024,79 @@ static const char proc_node_name [] = "driver/udc"; static void dump_intmask(struct seq_file *m, const char *label, u32 mask) { /* int_status is the same format ... */ - seq_printf(m, - "%s %05X =" FOURBITS EIGHTBITS EIGHTBITS "\n", - label, mask, - (mask & INT_PWRDETECT) ? " power" : "", - (mask & INT_SYSERROR) ? " sys" : "", - (mask & INT_MSTRDEND) ? " in-dma" : "", - (mask & INT_MSTWRTMOUT) ? " wrtmo" : "", - - (mask & INT_MSTWREND) ? " out-dma" : "", - (mask & INT_MSTWRSET) ? " wrset" : "", - (mask & INT_ERR) ? " err" : "", - (mask & INT_SOF) ? " sof" : "", - - (mask & INT_EP3NAK) ? " ep3nak" : "", - (mask & INT_EP2NAK) ? " ep2nak" : "", - (mask & INT_EP1NAK) ? " ep1nak" : "", - (mask & INT_EP3DATASET) ? " ep3" : "", - - (mask & INT_EP2DATASET) ? " ep2" : "", - (mask & INT_EP1DATASET) ? " ep1" : "", - (mask & INT_STATUSNAK) ? " ep0snak" : "", - (mask & INT_STATUS) ? " ep0status" : "", - - (mask & INT_SETUP) ? " setup" : "", - (mask & INT_ENDPOINT0) ? " ep0" : "", - (mask & INT_USBRESET) ? " reset" : "", - (mask & INT_SUSPEND) ? " suspend" : ""); + seq_printf(m, "%s %05X =" FOURBITS EIGHTBITS EIGHTBITS "\n", + label, mask, + (mask & INT_PWRDETECT) ? " power" : "", + (mask & INT_SYSERROR) ? " sys" : "", + (mask & INT_MSTRDEND) ? " in-dma" : "", + (mask & INT_MSTWRTMOUT) ? " wrtmo" : "", + + (mask & INT_MSTWREND) ? " out-dma" : "", + (mask & INT_MSTWRSET) ? " wrset" : "", + (mask & INT_ERR) ? " err" : "", + (mask & INT_SOF) ? " sof" : "", + + (mask & INT_EP3NAK) ? " ep3nak" : "", + (mask & INT_EP2NAK) ? " ep2nak" : "", + (mask & INT_EP1NAK) ? " ep1nak" : "", + (mask & INT_EP3DATASET) ? " ep3" : "", + + (mask & INT_EP2DATASET) ? " ep2" : "", + (mask & INT_EP1DATASET) ? " ep1" : "", + (mask & INT_STATUSNAK) ? " ep0snak" : "", + (mask & INT_STATUS) ? " ep0status" : "", + + (mask & INT_SETUP) ? " setup" : "", + (mask & INT_ENDPOINT0) ? " ep0" : "", + (mask & INT_USBRESET) ? " reset" : "", + (mask & INT_SUSPEND) ? " suspend" : ""); +} + +static const char *udc_ep_state(enum ep0state state) +{ + switch (state) { + case EP0_DISCONNECT: + return "ep0_disconnect"; + case EP0_IDLE: + return "ep0_idle"; + case EP0_IN: + return "ep0_in"; + case EP0_OUT: + return "ep0_out"; + case EP0_STATUS: + return "ep0_status"; + case EP0_STALL: + return "ep0_stall"; + case EP0_SUSPEND: + return "ep0_suspend"; + } + + return "ep0_?"; } +static const char *udc_ep_status(u32 status) +{ + switch (status & EPxSTATUS_EP_MASK) { + case EPxSTATUS_EP_READY: + return "ready"; + case EPxSTATUS_EP_DATAIN: + return "packet"; + case EPxSTATUS_EP_FULL: + return "full"; + case EPxSTATUS_EP_TX_ERR: /* host will retry */ + return "tx_err"; + case EPxSTATUS_EP_RX_ERR: + return "rx_err"; + case EPxSTATUS_EP_BUSY: /* ep0 only */ + return "busy"; + case EPxSTATUS_EP_STALL: + return "stall"; + case EPxSTATUS_EP_INVALID: /* these "can't happen" */ + return "invalid"; + } + + return "?"; +} static int udc_proc_read(struct seq_file *m, void *v) { @@ -1068,29 +1112,18 @@ static int udc_proc_read(struct seq_file *m, void *v) tmp = readl(®s->power_detect); is_usb_connected = tmp & PW_DETECT; seq_printf(m, - "%s - %s\n" - "%s version: %s %s\n" - "Gadget driver: %s\n" - "Host %s, %s\n" - "\n", - pci_name(dev->pdev), driver_desc, - driver_name, DRIVER_VERSION, dmastr(), - dev->driver ? dev->driver->driver.name : "(none)", - is_usb_connected - ? ((tmp & PW_PULLUP) ? "full speed" : "powered") - : "disconnected", - ({const char *state; - switch(dev->ep0state){ - case EP0_DISCONNECT: state = "ep0_disconnect"; break; - case EP0_IDLE: state = "ep0_idle"; break; - case EP0_IN: state = "ep0_in"; break; - case EP0_OUT: state = "ep0_out"; break; - case EP0_STATUS: state = "ep0_status"; break; - case EP0_STALL: state = "ep0_stall"; break; - case EP0_SUSPEND: state = "ep0_suspend"; break; - default: state = "ep0_?"; break; - } state; }) - ); + "%s - %s\n" + "%s version: %s %s\n" + "Gadget driver: %s\n" + "Host %s, %s\n" + "\n", + pci_name(dev->pdev), driver_desc, + driver_name, DRIVER_VERSION, dmastr(), + dev->driver ? dev->driver->driver.name : "(none)", + is_usb_connected + ? ((tmp & PW_PULLUP) ? "full speed" : "powered") + : "disconnected", + udc_ep_state(dev->ep0state)); dump_intmask(m, "int_status", readl(®s->int_status)); dump_intmask(m, "int_enable", readl(®s->int_enable)); @@ -1099,31 +1132,30 @@ static int udc_proc_read(struct seq_file *m, void *v) goto done; /* registers for (active) device and ep0 */ - if (seq_printf(m, "\nirqs %lu\ndataset %02x " - "single.bcs %02x.%02x state %x addr %u\n", - dev->irqs, readl(®s->DataSet), - readl(®s->EPxSingle), readl(®s->EPxBCS), - readl(®s->UsbState), - readl(®s->address)) < 0) + seq_printf(m, "\nirqs %lu\ndataset %02x single.bcs %02x.%02x state %x addr %u\n", + dev->irqs, readl(®s->DataSet), + readl(®s->EPxSingle), readl(®s->EPxBCS), + readl(®s->UsbState), + readl(®s->address)); + if (seq_has_overflowed(m)) goto done; tmp = readl(®s->dma_master); - if (seq_printf(m, - "dma %03X =" EIGHTBITS "%s %s\n", tmp, - (tmp & MST_EOPB_DIS) ? " eopb-" : "", - (tmp & MST_EOPB_ENA) ? " eopb+" : "", - (tmp & MST_TIMEOUT_DIS) ? " tmo-" : "", - (tmp & MST_TIMEOUT_ENA) ? " tmo+" : "", - - (tmp & MST_RD_EOPB) ? " eopb" : "", - (tmp & MST_RD_RESET) ? " in_reset" : "", - (tmp & MST_WR_RESET) ? " out_reset" : "", - (tmp & MST_RD_ENA) ? " IN" : "", - - (tmp & MST_WR_ENA) ? " OUT" : "", - (tmp & MST_CONNECTION) - ? "ep1in/ep2out" - : "ep1out/ep2in") < 0) + seq_printf(m, "dma %03X =" EIGHTBITS "%s %s\n", + tmp, + (tmp & MST_EOPB_DIS) ? " eopb-" : "", + (tmp & MST_EOPB_ENA) ? " eopb+" : "", + (tmp & MST_TIMEOUT_DIS) ? " tmo-" : "", + (tmp & MST_TIMEOUT_ENA) ? " tmo+" : "", + + (tmp & MST_RD_EOPB) ? " eopb" : "", + (tmp & MST_RD_RESET) ? " in_reset" : "", + (tmp & MST_WR_RESET) ? " out_reset" : "", + (tmp & MST_RD_ENA) ? " IN" : "", + + (tmp & MST_WR_ENA) ? " OUT" : "", + (tmp & MST_CONNECTION) ? "ep1in/ep2out" : "ep1out/ep2in"); + if (seq_has_overflowed(m)) goto done; /* dump endpoint queues */ @@ -1135,44 +1167,23 @@ static int udc_proc_read(struct seq_file *m, void *v) continue; tmp = readl(ep->reg_status); - if (seq_printf(m, - "%s %s max %u %s, irqs %lu, " - "status %02x (%s) " FOURBITS "\n", - ep->ep.name, - ep->is_in ? "in" : "out", - ep->ep.maxpacket, - ep->dma ? "dma" : "pio", - ep->irqs, - tmp, ({ char *s; - switch (tmp & EPxSTATUS_EP_MASK) { - case EPxSTATUS_EP_READY: - s = "ready"; break; - case EPxSTATUS_EP_DATAIN: - s = "packet"; break; - case EPxSTATUS_EP_FULL: - s = "full"; break; - case EPxSTATUS_EP_TX_ERR: // host will retry - s = "tx_err"; break; - case EPxSTATUS_EP_RX_ERR: - s = "rx_err"; break; - case EPxSTATUS_EP_BUSY: /* ep0 only */ - s = "busy"; break; - case EPxSTATUS_EP_STALL: - s = "stall"; break; - case EPxSTATUS_EP_INVALID: // these "can't happen" - s = "invalid"; break; - default: - s = "?"; break; - } s; }), - (tmp & EPxSTATUS_TOGGLE) ? "data1" : "data0", - (tmp & EPxSTATUS_SUSPEND) ? " suspend" : "", - (tmp & EPxSTATUS_FIFO_DISABLE) ? " disable" : "", - (tmp & EPxSTATUS_STAGE_ERROR) ? " ep0stat" : "" - ) < 0) + seq_printf(m, "%s %s max %u %s, irqs %lu, status %02x (%s) " FOURBITS "\n", + ep->ep.name, + ep->is_in ? "in" : "out", + ep->ep.maxpacket, + ep->dma ? "dma" : "pio", + ep->irqs, + tmp, udc_ep_status(tmp), + (tmp & EPxSTATUS_TOGGLE) ? "data1" : "data0", + (tmp & EPxSTATUS_SUSPEND) ? " suspend" : "", + (tmp & EPxSTATUS_FIFO_DISABLE) ? " disable" : "", + (tmp & EPxSTATUS_STAGE_ERROR) ? " ep0stat" : ""); + if (seq_has_overflowed(m)) goto done; if (list_empty(&ep->queue)) { - if (seq_puts(m, "\t(nothing queued)\n") < 0) + seq_puts(m, "\t(nothing queued)\n"); + if (seq_has_overflowed(m)) goto done; continue; } @@ -1187,10 +1198,10 @@ static int udc_proc_read(struct seq_file *m, void *v) } else tmp = req->req.actual; - if (seq_printf(m, - "\treq %p len %u/%u buf %p\n", - &req->req, tmp, req->req.length, - req->req.buf) < 0) + seq_printf(m, "\treq %p len %u/%u buf %p\n", + &req->req, tmp, req->req.length, + req->req.buf); + if (seq_has_overflowed(m)) goto done; } } -- cgit v0.10.2 From 3463d795bf0f8d9b32d4deabaaffcb81a1abb92b Mon Sep 17 00:00:00 2001 From: Fabian Frederick Date: Mon, 16 Mar 2015 20:20:27 +0100 Subject: usb: gadget: constify of_device_id array of_device_id is always used as const. (See driver.of_match_table and open firmware functions) Signed-off-by: Fabian Frederick Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/udc/pxa27x_udc.c b/drivers/usb/gadget/udc/pxa27x_udc.c index 486f754..b51226a 100644 --- a/drivers/usb/gadget/udc/pxa27x_udc.c +++ b/drivers/usb/gadget/udc/pxa27x_udc.c @@ -2387,7 +2387,7 @@ static struct pxa_udc memory = { }; #if defined(CONFIG_OF) -static struct of_device_id udc_pxa_dt_ids[] = { +static const struct of_device_id udc_pxa_dt_ids[] = { { .compatible = "marvell,pxa270-udc" }, {} }; -- cgit v0.10.2 From b48cb02de37976ad2ebef201ad40aa40156f6daa Mon Sep 17 00:00:00 2001 From: John Youn Date: Mon, 16 Mar 2015 18:10:02 -0700 Subject: usb: dwc2: pci: Correctly compile dwc2-pci as a module or built-in The dwc2-pci driver should be compiled as a module when configured to do so. If the dwc2-pci is configured as a module but actually built-in, it can cause build errors due to the fact that the generic-phy will be allowed to compile as a module causing undefined references. Reported-by: Alan Cox Signed-off-by: John Youn Signed-off-by: Felipe Balbi diff --git a/drivers/usb/dwc2/Makefile b/drivers/usb/dwc2/Makefile index 8f75267..f07b425 100644 --- a/drivers/usb/dwc2/Makefile +++ b/drivers/usb/dwc2/Makefile @@ -19,10 +19,8 @@ endif # mode. The PCI bus interface module will called dwc2_pci.ko and the platform # interface module will be called dwc2_platform.ko. -ifneq ($(CONFIG_USB_DWC2_PCI),) - obj-$(CONFIG_USB_DWC2) += dwc2_pci.o - dwc2_pci-y := pci.o -endif +obj-$(CONFIG_USB_DWC2_PCI) += dwc2_pci.o +dwc2_pci-y := pci.o obj-$(CONFIG_USB_DWC2_PLATFORM) += dwc2_platform.o dwc2_platform-y := platform.o -- cgit v0.10.2 From a3dd3befd7cb7d445fcb7c51cd922bf89afe0762 Mon Sep 17 00:00:00 2001 From: Ben Dooks Date: Wed, 18 Mar 2015 15:53:09 +0000 Subject: usb: gadget: atmel_usba: use endian agnostic IO on ARM Change from using the __raw IO accesors to the endian agnostic versions of readl/writel_relaxed when not on AVR32. This fixes issues with running big endian on ARMv7. Signed-off-by: Ben Dooks -- CC: Nicolas Ferre CC: Felipe Balbi CC: Greg Kroah-Hartman CC: linux-usb@vger.kernel.org Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c b/drivers/usb/gadget/udc/atmel_usba_udc.c index d019b6c..4c01953 100644 --- a/drivers/usb/gadget/udc/atmel_usba_udc.c +++ b/drivers/usb/gadget/udc/atmel_usba_udc.c @@ -152,7 +152,7 @@ static int regs_dbg_open(struct inode *inode, struct file *file) spin_lock_irq(&udc->lock); for (i = 0; i < inode->i_size / 4; i++) - data[i] = __raw_readl(udc->regs + i * 4); + data[i] = usba_io_readl(udc->regs + i * 4); spin_unlock_irq(&udc->lock); file->private_data = data; @@ -1249,7 +1249,7 @@ static int handle_ep0_setup(struct usba_udc *udc, struct usba_ep *ep, if (crq->wLength != cpu_to_le16(sizeof(status))) goto stall; ep->state = DATA_STAGE_IN; - __raw_writew(status, ep->fifo); + usba_io_writew(status, ep->fifo); usba_ep_writel(ep, SET_STA, USBA_TX_PK_RDY); break; } diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.h b/drivers/usb/gadget/udc/atmel_usba_udc.h index 085749a..ea448a3 100644 --- a/drivers/usb/gadget/udc/atmel_usba_udc.h +++ b/drivers/usb/gadget/udc/atmel_usba_udc.h @@ -191,18 +191,28 @@ | USBA_BF(name, value)) /* Register access macros */ +#ifdef CONFIG_AVR32 +#define usba_io_readl __raw_readl +#define usba_io_writel __raw_writel +#define usba_io_writew __raw_writew +#else +#define usba_io_readl readl_relaxed +#define usba_io_writel writel_relaxed +#define usba_io_writew writew_relaxed +#endif + #define usba_readl(udc, reg) \ - __raw_readl((udc)->regs + USBA_##reg) + usba_io_readl((udc)->regs + USBA_##reg) #define usba_writel(udc, reg, value) \ - __raw_writel((value), (udc)->regs + USBA_##reg) + usba_io_writel((value), (udc)->regs + USBA_##reg) #define usba_ep_readl(ep, reg) \ - __raw_readl((ep)->ep_regs + USBA_EPT_##reg) + usba_io_readl((ep)->ep_regs + USBA_EPT_##reg) #define usba_ep_writel(ep, reg, value) \ - __raw_writel((value), (ep)->ep_regs + USBA_EPT_##reg) + usba_io_writel((value), (ep)->ep_regs + USBA_EPT_##reg) #define usba_dma_readl(ep, reg) \ - __raw_readl((ep)->dma_regs + USBA_DMA_##reg) + usba_io_readl((ep)->dma_regs + USBA_DMA_##reg) #define usba_dma_writel(ep, reg, value) \ - __raw_writel((value), (ep)->dma_regs + USBA_DMA_##reg) + usba_io_writel((value), (ep)->dma_regs + USBA_DMA_##reg) /* Calculate base address for a given endpoint or DMA controller */ #define USBA_EPT_BASE(x) (0x100 + (x) * 0x20) -- cgit v0.10.2 From f4b4976b6e3171d408d0f6e08b12189bf60d1d22 Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Tue, 24 Mar 2015 10:58:16 +0100 Subject: usb: gadget: f_printer: fix dependencies If f_printer is selected without legacy g_printer, it should depend on USB_CONFIGFS which pulls in libcomposite. Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Felipe Balbi diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index 3bb0e67..bcf83c0 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig @@ -440,6 +440,7 @@ config USB_CONFIGFS_F_UVC config USB_CONFIGFS_F_PRINTER bool "Printer function" select USB_F_PRINTER + depends on USB_CONFIGFS help The Printer function channels data between the USB host and a userspace program driving the print engine. The user space -- cgit v0.10.2 From 1ea276cbfc0201c9804f38474f3ec2c4488a2fc6 Mon Sep 17 00:00:00 2001 From: "Ivan T. Ivanov" Date: Sat, 21 Mar 2015 15:25:52 +0200 Subject: usb: phy: Fix USB_ULPI_VIEWPORT Kconfig dependency USB_ULPI_VIEWPORT didn't depend on USB_ULPI, while USB_ULPI is using non user selectable USB_ULPI_VIEWPORT. Fix this. Signed-off-by: Ivan T. Ivanov Signed-off-by: Felipe Balbi diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig index 2fb3828..2175678 100644 --- a/drivers/usb/phy/Kconfig +++ b/drivers/usb/phy/Kconfig @@ -202,13 +202,13 @@ config USB_RCAR_GEN2_PHY config USB_ULPI bool "Generic ULPI Transceiver Driver" depends on ARM || ARM64 + select USB_ULPI_VIEWPORT help Enable this to support ULPI connected USB OTG transceivers which are likely found on embedded boards. config USB_ULPI_VIEWPORT bool - depends on USB_ULPI help Provides read/write operations to the ULPI phy register set for controllers with a viewport register (e.g. Chipidea/ARC controllers). -- cgit v0.10.2 From 3e457371f436e89ce9239674828f9729a36b2595 Mon Sep 17 00:00:00 2001 From: Tony Lindgren Date: Thu, 19 Mar 2015 17:10:16 -0700 Subject: usb: musb: Fix fifo reads for dm816x with musb_dsps Looks like dm81xx can only do 32-bit fifo reads like am35x. Let's set up musb-dsps with a custom read_fifo function based on the compatible flag. Otherwise we can get the following errors when starting dhclient on a asix USB Ethernet adapter: asix 2-1:1.0 eth2: asix_rx_fixup() Bad Header Length 0xffff003c, offset 4 While at it, let's also remove pointless cast of the driver data. Cc: Bin Liu Cc: Brian Hutchinson Cc: George Cherian Cc: Sergei Shtylyov Signed-off-by: Tony Lindgren Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c index 09648b4..b23ad15 100644 --- a/drivers/usb/musb/musb_dsps.c +++ b/drivers/usb/musb/musb_dsps.c @@ -615,6 +615,24 @@ static int dsps_musb_recover(struct musb *musb) return session_restart ? 0 : -EPIPE; } +/* Similar to am35x, dm81xx support only 32-bit read operation */ +static void dsps_read_fifo32(struct musb_hw_ep *hw_ep, u16 len, u8 *dst) +{ + void __iomem *fifo = hw_ep->fifo; + + if (len >= 4) { + readsl(fifo, dst, len >> 2); + dst += len & ~0x03; + len &= 0x03; + } + + /* Read any remaining 1 to 3 bytes */ + if (len > 0) { + u32 val = musb_readl(fifo, 0); + memcpy(dst, &val, len); + } +} + static struct musb_platform_ops dsps_ops = { .quirks = MUSB_INDEXED_EP, .init = dsps_musb_init, @@ -761,6 +779,9 @@ static int dsps_probe(struct platform_device *pdev) } wrp = match->data; + if (of_device_is_compatible(pdev->dev.of_node, "ti,musb-dm816")) + dsps_ops.read_fifo = dsps_read_fifo32; + /* allocate glue */ glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); if (!glue) @@ -837,7 +858,9 @@ static const struct dsps_musb_wrapper am33xx_driver_data = { static const struct of_device_id musb_dsps_of_match[] = { { .compatible = "ti,musb-am33xx", - .data = (void *) &am33xx_driver_data, }, + .data = &am33xx_driver_data, }, + { .compatible = "ti,musb-dm816", + .data = &am33xx_driver_data, }, { }, }; MODULE_DEVICE_TABLE(of, musb_dsps_of_match); -- cgit v0.10.2 From 080de5ba390c54b7504c43b36ae21911acf66b30 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 17 Mar 2015 08:39:01 +0800 Subject: phy: stih41x-usb: Fixup stih41x_usb_phy_power_on failure path If stih41x_usb_phy_power_on() fails, we need to call clk_disable_unprepare() before return error. This is to ensure we have balanced clk_enable/disable calls. Signed-off-by: Axel Lin Acked-by: Patrice Chotard Signed-off-by: Kishon Vijay Abraham I diff --git a/drivers/phy/phy-stih41x-usb.c b/drivers/phy/phy-stih41x-usb.c index a603801..c093b47 100644 --- a/drivers/phy/phy-stih41x-usb.c +++ b/drivers/phy/phy-stih41x-usb.c @@ -87,8 +87,12 @@ static int stih41x_usb_phy_power_on(struct phy *phy) return ret; } - return regmap_update_bits(phy_dev->regmap, phy_dev->cfg->syscfg, - phy_dev->cfg->oscok, phy_dev->cfg->oscok); + ret = regmap_update_bits(phy_dev->regmap, phy_dev->cfg->syscfg, + phy_dev->cfg->oscok, phy_dev->cfg->oscok); + if (ret) + clk_disable_unprepare(phy_dev->clk); + + return ret; } static int stih41x_usb_phy_power_off(struct phy *phy) -- cgit v0.10.2 From d89a7f69d69409ffafad7affc1cc3085d2cd0dd8 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 3 Mar 2015 09:05:55 +0800 Subject: phy: qcom-ufs: Catch devm_phy_create failure in ufs_qcom_phy_generic_probe Current code does NULL test against return value of ufs_qcom_phy_generic_probe. However, in the case of devm_phy_create() failure, ufs_qcom_phy_generic_probe does not return NULL. Fix it. Signed-off-by: Axel Lin Signed-off-by: Kishon Vijay Abraham I diff --git a/drivers/phy/phy-qcom-ufs.c b/drivers/phy/phy-qcom-ufs.c index 44ee983..d95effe 100644 --- a/drivers/phy/phy-qcom-ufs.c +++ b/drivers/phy/phy-qcom-ufs.c @@ -101,6 +101,7 @@ struct phy *ufs_qcom_phy_generic_probe(struct platform_device *pdev, if (IS_ERR(generic_phy)) { err = PTR_ERR(generic_phy); dev_err(dev, "%s: failed to create phy %d\n", __func__, err); + generic_phy = NULL; goto out; } -- cgit v0.10.2 From 2be608561abfcceda4b35b71a0c1ec5088bb39b9 Mon Sep 17 00:00:00 2001 From: Jaewon Kim Date: Thu, 12 Mar 2015 19:11:13 +0900 Subject: phy: exynos5-usbdrd: Add to support for Exynos5433 SoC This patch adds driver data to support for Exynos5433 SoC. The Exynos5433 has one USB3.0 Host and USB3.0 DRD(Dual Role Device). Exynos5433 is simplar to Eyxnos7 but Exynos5433 have one more USB3.0 Host controller. Signed-off-by: Jaewon Kim Signed-off-by: Kishon Vijay Abraham I diff --git a/Documentation/devicetree/bindings/phy/samsung-phy.txt b/Documentation/devicetree/bindings/phy/samsung-phy.txt index 91e38cf..60c6f2a 100644 --- a/Documentation/devicetree/bindings/phy/samsung-phy.txt +++ b/Documentation/devicetree/bindings/phy/samsung-phy.txt @@ -128,6 +128,7 @@ Required properties: - compatible : Should be set to one of the following supported values: - "samsung,exynos5250-usbdrd-phy" - for exynos5250 SoC, - "samsung,exynos5420-usbdrd-phy" - for exynos5420 SoC. + - "samsung,exynos5433-usbdrd-phy" - for exynos5433 SoC. - "samsung,exynos7-usbdrd-phy" - for exynos7 SoC. - reg : Register offset and length of USB DRD PHY register set; - clocks: Clock IDs array as required by the controller @@ -139,7 +140,7 @@ Required properties: PHY operations, associated by phy name. It is used to determine bit values for clock settings register. For Exynos5420 this is given as 'sclk_usbphy30' in CMU. - - optional clocks: Exynos7 SoC has now following additional + - optional clocks: Exynos5433 & Exynos7 SoC has now following additional gate clocks available: - phy_pipe: for PIPE3 phy - phy_utmi: for UTMI+ phy diff --git a/drivers/phy/phy-exynos5-usbdrd.c b/drivers/phy/phy-exynos5-usbdrd.c index 0437401..597e7dd 100644 --- a/drivers/phy/phy-exynos5-usbdrd.c +++ b/drivers/phy/phy-exynos5-usbdrd.c @@ -624,6 +624,13 @@ static const struct exynos5_usbdrd_phy_drvdata exynos5250_usbdrd_phy = { .has_common_clk_gate = true, }; +static const struct exynos5_usbdrd_phy_drvdata exynos5433_usbdrd_phy = { + .phy_cfg = phy_cfg_exynos5, + .pmu_offset_usbdrd0_phy = EXYNOS5_USBDRD_PHY_CONTROL, + .pmu_offset_usbdrd1_phy = EXYNOS5433_USBHOST30_PHY_CONTROL, + .has_common_clk_gate = false, +}; + static const struct exynos5_usbdrd_phy_drvdata exynos7_usbdrd_phy = { .phy_cfg = phy_cfg_exynos5, .pmu_offset_usbdrd0_phy = EXYNOS5_USBDRD_PHY_CONTROL, @@ -638,6 +645,9 @@ static const struct of_device_id exynos5_usbdrd_phy_of_match[] = { .compatible = "samsung,exynos5420-usbdrd-phy", .data = &exynos5420_usbdrd_phy }, { + .compatible = "samsung,exynos5433-usbdrd-phy", + .data = &exynos5433_usbdrd_phy + }, { .compatible = "samsung,exynos7-usbdrd-phy", .data = &exynos7_usbdrd_phy }, diff --git a/include/linux/mfd/syscon/exynos5-pmu.h b/include/linux/mfd/syscon/exynos5-pmu.h index 00ef24b..9352adc 100644 --- a/include/linux/mfd/syscon/exynos5-pmu.h +++ b/include/linux/mfd/syscon/exynos5-pmu.h @@ -36,6 +36,9 @@ #define EXYNOS5420_MTCADC_PHY_CONTROL (0x724) #define EXYNOS5420_DPTX_PHY_CONTROL (0x728) +/* Exynos5433 specific register definitions */ +#define EXYNOS5433_USBHOST30_PHY_CONTROL (0x728) + #define EXYNOS5_PHY_ENABLE BIT(0) #define EXYNOS5_MIPI_PHY_S_RESETN BIT(1) -- cgit v0.10.2 From 7a504c935e42737e5ad40ea2f6f2d21b4dc27e81 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 17 Mar 2015 08:42:38 +0800 Subject: phy: samsung_usb2: Fixup samsung_usb2_phy_power_on/off paths Ensure we have balanced clk_prepare_enable/clk_disable_unprepare calls if .power_on or .power_off callbacks return error. Signed-off-by: Axel Lin Signed-off-by: Kishon Vijay Abraham I diff --git a/drivers/phy/phy-samsung-usb2.c b/drivers/phy/phy-samsung-usb2.c index 4a12f66..55b6994 100644 --- a/drivers/phy/phy-samsung-usb2.c +++ b/drivers/phy/phy-samsung-usb2.c @@ -37,10 +37,14 @@ static int samsung_usb2_phy_power_on(struct phy *phy) spin_lock(&drv->lock); ret = inst->cfg->power_on(inst); spin_unlock(&drv->lock); + if (ret) + goto err_power_on; } return 0; +err_power_on: + clk_disable_unprepare(drv->ref_clk); err_instance_clk: clk_disable_unprepare(drv->clk); err_main_clk: @@ -51,7 +55,7 @@ static int samsung_usb2_phy_power_off(struct phy *phy) { struct samsung_usb2_phy_instance *inst = phy_get_drvdata(phy); struct samsung_usb2_phy_driver *drv = inst->drv; - int ret = 0; + int ret; dev_dbg(drv->dev, "Request to power_off \"%s\" usb phy\n", inst->cfg->label); @@ -59,10 +63,12 @@ static int samsung_usb2_phy_power_off(struct phy *phy) spin_lock(&drv->lock); ret = inst->cfg->power_off(inst); spin_unlock(&drv->lock); + if (ret) + return ret; } clk_disable_unprepare(drv->ref_clk); clk_disable_unprepare(drv->clk); - return ret; + return 0; } static struct phy_ops samsung_usb2_phy_ops = { -- cgit v0.10.2 From 1fcefbdf06708a5811ffa8acc949714aee60ae13 Mon Sep 17 00:00:00 2001 From: kbuild test robot Date: Wed, 25 Mar 2015 07:23:52 +0100 Subject: usb: chipidea: usbmisc_imx: fix returnvar.cocci warnings drivers/usb/chipidea/usbmisc_imx.c:277:5-8: Unneeded variable: "ret". Return "0" on line 297 Removes unneeded variable used to store return value. Generated by: scripts/coccinelle/misc/returnvar.cocci Cc: Julia Lawall Signed-off-by: Peter Chen Signed-off-by: Fengguang Wu Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/chipidea/usbmisc_imx.c b/drivers/usb/chipidea/usbmisc_imx.c index 8af070f..140945c 100644 --- a/drivers/usb/chipidea/usbmisc_imx.c +++ b/drivers/usb/chipidea/usbmisc_imx.c @@ -274,7 +274,6 @@ static int usbmisc_imx6sx_init(struct imx_usbmisc_data *data) unsigned long flags; struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); u32 val; - int ret = 0; usbmisc_imx6q_init(data); @@ -294,7 +293,7 @@ static int usbmisc_imx6sx_init(struct imx_usbmisc_data *data) spin_unlock_irqrestore(&usbmisc->lock, flags); } - return ret; + return 0; } static int usbmisc_vf610_init(struct imx_usbmisc_data *data) -- cgit v0.10.2 From 66e3e591891da9899a8990792da080432531ffd4 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 19 Mar 2015 20:36:49 -0700 Subject: usb: Add driver for Altus Metrum ChaosKey device (v2) This is a hardware random number generator. The driver provides both a /dev/chaoskeyX entry and hooks the entropy source up to the kernel hwrng interface. More information about the device can be found at http://chaoskey.org The USB ID for ChaosKey was allocated from the OpenMoko USB vendor space and is visible as 'USBtrng' here: http://wiki.openmoko.org/wiki/USB_Product_IDs v2: Respond to review from Oliver Neukum * Delete extensive debug infrastructure and replace it with calls to dev_dbg. * Allocate I/O buffer separately from device structure to obey requirements for non-coherant architectures. * Initialize mutexes before registering device to ensure that open cannot be invoked before the device is ready to proceed. * Return number of bytes read instead of -EINTR when partial read operation is aborted due to a signal. * Make sure device mutex is unlocked in read error paths. * Add MAINTAINERS entry for the driver Signed-off-by: Keith Packard Cc: Oliver Neukum Signed-off-by: Greg Kroah-Hartman diff --git a/MAINTAINERS b/MAINTAINERS index 358eb01..059a9d4 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -10129,6 +10129,12 @@ S: Maintained F: drivers/net/usb/cdc_*.c F: include/uapi/linux/usb/cdc.h +USB CHAOSKEY DRIVER +M: Keith Packard +L: linux-usb@vger.kernel.org +S: Maintained +F: drivers/usb/misc/chaoskey.c + USB CYPRESS C67X00 DRIVER M: Peter Korsgaard L: linux-usb@vger.kernel.org diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig index 76d7720..8c331f1 100644 --- a/drivers/usb/misc/Kconfig +++ b/drivers/usb/misc/Kconfig @@ -255,3 +255,15 @@ config USB_LINK_LAYER_TEST This driver is for generating specific traffic for Super Speed Link Layer Test Device. Say Y only when you want to conduct USB Super Speed Link Layer Test for host controllers. + +config USB_CHAOSKEY + tristate "ChaosKey random number generator driver support" + help + Say Y here if you want to connect an AltusMetrum ChaosKey to + your computer's USB port. The ChaosKey is a hardware random + number generator which hooks into the kernel entropy pool to + ensure a large supply of entropy for /dev/random and + /dev/urandom and also provides direct access via /dev/chaoskeyX + + To compile this driver as a module, choose M here: the + module will be called chaoskey. diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile index 65b0402..45fd4ac 100644 --- a/drivers/usb/misc/Makefile +++ b/drivers/usb/misc/Makefile @@ -25,6 +25,7 @@ obj-$(CONFIG_USB_USS720) += uss720.o obj-$(CONFIG_USB_SEVSEG) += usbsevseg.o obj-$(CONFIG_USB_YUREX) += yurex.o obj-$(CONFIG_USB_HSIC_USB3503) += usb3503.o +obj-$(CONFIG_USB_CHAOSKEY) += chaoskey.o obj-$(CONFIG_USB_SISUSBVGA) += sisusbvga/ obj-$(CONFIG_USB_LINK_LAYER_TEST) += lvstest.o diff --git a/drivers/usb/misc/chaoskey.c b/drivers/usb/misc/chaoskey.c new file mode 100644 index 0000000..ef80ce9 --- /dev/null +++ b/drivers/usb/misc/chaoskey.c @@ -0,0 +1,530 @@ +/* + * chaoskey - driver for ChaosKey device from Altus Metrum. + * + * This device provides true random numbers using a noise source based + * on a reverse-biased p-n junction in avalanche breakdown. More + * details can be found at http://chaoskey.org + * + * The driver connects to the kernel hardware RNG interface to provide + * entropy for /dev/random and other kernel activities. It also offers + * a separate /dev/ entry to allow for direct access to the random + * bit stream. + * + * Copyright © 2015 Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + */ + +#include +#include +#include +#include +#include + +static struct usb_driver chaoskey_driver; +static struct usb_class_driver chaoskey_class; +static int chaoskey_rng_read(struct hwrng *rng, void *data, + size_t max, bool wait); + +#define usb_dbg(usb_if, format, arg...) \ + dev_dbg(&(usb_if)->dev, format, ## arg) + +#define usb_err(usb_if, format, arg...) \ + dev_err(&(usb_if)->dev, format, ## arg) + +/* Version Information */ +#define DRIVER_VERSION "v0.1" +#define DRIVER_AUTHOR "Keith Packard, keithp@keithp.com" +#define DRIVER_DESC "Altus Metrum ChaosKey driver" +#define DRIVER_SHORT "chaoskey" + +MODULE_VERSION(DRIVER_VERSION); +MODULE_AUTHOR(DRIVER_AUTHOR); +MODULE_DESCRIPTION(DRIVER_DESC); +MODULE_LICENSE("GPL"); + +#define CHAOSKEY_VENDOR_ID 0x1d50 /* OpenMoko */ +#define CHAOSKEY_PRODUCT_ID 0x60c6 /* ChaosKey */ + +#define CHAOSKEY_BUF_LEN 64 /* max size of USB full speed packet */ + +#define NAK_TIMEOUT (HZ) /* stall/wait timeout for device */ + +#ifdef CONFIG_USB_DYNAMIC_MINORS +#define USB_CHAOSKEY_MINOR_BASE 0 +#else + +/* IOWARRIOR_MINOR_BASE + 16, not official yet */ +#define USB_CHAOSKEY_MINOR_BASE 224 +#endif + +static const struct usb_device_id chaoskey_table[] = { + { USB_DEVICE(CHAOSKEY_VENDOR_ID, CHAOSKEY_PRODUCT_ID) }, + { }, +}; +MODULE_DEVICE_TABLE(usb, chaoskey_table); + +/* Driver-local specific stuff */ +struct chaoskey { + struct usb_interface *interface; + char in_ep; + struct mutex lock; + struct mutex rng_lock; + int open; /* open count */ + int present; /* device not disconnected */ + int size; /* size of buf */ + int valid; /* bytes of buf read */ + int used; /* bytes of buf consumed */ + char *name; /* product + serial */ + struct hwrng hwrng; /* Embedded struct for hwrng */ + int hwrng_registered; /* registered with hwrng API */ + wait_queue_head_t wait_q; /* for timeouts */ + char *buf; +}; + +static void chaoskey_free(struct chaoskey *dev) +{ + usb_dbg(dev->interface, "free"); + kfree(dev->name); + kfree(dev->buf); + kfree(dev); +} + +static int chaoskey_probe(struct usb_interface *interface, + const struct usb_device_id *id) +{ + struct usb_device *udev = interface_to_usbdev(interface); + struct usb_host_interface *altsetting = interface->cur_altsetting; + int i; + int in_ep = -1; + struct chaoskey *dev; + int result; + int size; + + usb_dbg(interface, "probe %s-%s", udev->product, udev->serial); + + /* Find the first bulk IN endpoint and its packet size */ + for (i = 0; i < altsetting->desc.bNumEndpoints; i++) { + if (usb_endpoint_is_bulk_in(&altsetting->endpoint[i].desc)) { + in_ep = altsetting->endpoint[i].desc.bEndpointAddress; + size = altsetting->endpoint[i].desc.wMaxPacketSize; + break; + } + } + + /* Validate endpoint and size */ + if (in_ep == -1) { + usb_dbg(interface, "no IN endpoint found"); + return -ENODEV; + } + if (size <= 0) { + usb_dbg(interface, "invalid size (%d)", size); + return -ENODEV; + } + + if (size > CHAOSKEY_BUF_LEN) { + usb_dbg(interface, "size reduced from %d to %d\n", + size, CHAOSKEY_BUF_LEN); + size = CHAOSKEY_BUF_LEN; + } + + /* Looks good, allocate and initialize */ + + dev = kzalloc(sizeof(struct chaoskey), GFP_KERNEL); + + if (dev == NULL) + return -ENOMEM; + + dev->buf = kmalloc(size, GFP_KERNEL); + + if (dev->buf == NULL) { + kfree(dev); + return -ENOMEM; + } + + /* Construct a name using the product and serial values. Each + * device needs a unique name for the hwrng code + */ + + if (udev->product && udev->serial) { + dev->name = kmalloc(strlen(udev->product) + 1 + + strlen(udev->serial) + 1, GFP_KERNEL); + if (dev->name == NULL) { + kfree(dev->buf); + kfree(dev); + return -ENOMEM; + } + + strcpy(dev->name, udev->product); + strcat(dev->name, "-"); + strcat(dev->name, udev->serial); + } + + dev->interface = interface; + + dev->in_ep = in_ep; + + dev->size = size; + dev->present = 1; + + init_waitqueue_head(&dev->wait_q); + + mutex_init(&dev->lock); + mutex_init(&dev->rng_lock); + + usb_set_intfdata(interface, dev); + + result = usb_register_dev(interface, &chaoskey_class); + if (result) { + usb_err(interface, "Unable to allocate minor number."); + usb_set_intfdata(interface, NULL); + chaoskey_free(dev); + return result; + } + + dev->hwrng.name = dev->name ? dev->name : chaoskey_driver.name; + dev->hwrng.read = chaoskey_rng_read; + + /* Set the 'quality' metric. Quality is measured in units of + * 1/1024's of a bit ("mills"). This should be set to 1024, + * but there is a bug in the hwrng core which masks it with + * 1023. + * + * The patch that has been merged to the crypto development + * tree for that bug limits the value to 1024 at most, so by + * setting this to 1024 + 1023, we get 1023 before the fix is + * merged and 1024 afterwards. We'll patch this driver once + * both bits of code are in the same tree. + */ + dev->hwrng.quality = 1024 + 1023; + + dev->hwrng_registered = (hwrng_register(&dev->hwrng) == 0); + if (!dev->hwrng_registered) + usb_err(interface, "Unable to register with hwrng"); + + usb_enable_autosuspend(udev); + + usb_dbg(interface, "chaoskey probe success, size %d", dev->size); + return 0; +} + +static void chaoskey_disconnect(struct usb_interface *interface) +{ + struct chaoskey *dev; + + usb_dbg(interface, "disconnect"); + dev = usb_get_intfdata(interface); + if (!dev) { + usb_dbg(interface, "disconnect failed - no dev"); + return; + } + + if (dev->hwrng_registered) + hwrng_unregister(&dev->hwrng); + + usb_deregister_dev(interface, &chaoskey_class); + + usb_set_intfdata(interface, NULL); + mutex_lock(&dev->lock); + + dev->present = 0; + + if (!dev->open) { + mutex_unlock(&dev->lock); + chaoskey_free(dev); + } else + mutex_unlock(&dev->lock); + + usb_dbg(interface, "disconnect done"); +} + +static int chaoskey_open(struct inode *inode, struct file *file) +{ + struct chaoskey *dev; + struct usb_interface *interface; + + /* get the interface from minor number and driver information */ + interface = usb_find_interface(&chaoskey_driver, iminor(inode)); + if (!interface) + return -ENODEV; + + usb_dbg(interface, "open"); + + dev = usb_get_intfdata(interface); + if (!dev) { + usb_dbg(interface, "open (dev)"); + return -ENODEV; + } + + file->private_data = dev; + mutex_lock(&dev->lock); + ++dev->open; + mutex_unlock(&dev->lock); + + usb_dbg(interface, "open success"); + return 0; +} + +static int chaoskey_release(struct inode *inode, struct file *file) +{ + struct chaoskey *dev = file->private_data; + struct usb_interface *interface; + + if (dev == NULL) + return -ENODEV; + + interface = dev->interface; + + usb_dbg(interface, "release"); + + mutex_lock(&dev->lock); + + usb_dbg(interface, "open count at release is %d", dev->open); + + if (dev->open <= 0) { + usb_dbg(interface, "invalid open count (%d)", dev->open); + mutex_unlock(&dev->lock); + return -ENODEV; + } + + --dev->open; + + if (!dev->present) { + if (dev->open == 0) { + mutex_unlock(&dev->lock); + chaoskey_free(dev); + } else + mutex_unlock(&dev->lock); + } else + mutex_unlock(&dev->lock); + + usb_dbg(interface, "release success"); + return 0; +} + +/* Fill the buffer. Called with dev->lock held + */ +static int _chaoskey_fill(struct chaoskey *dev) +{ + DEFINE_WAIT(wait); + int result; + int this_read; + struct usb_device *udev = interface_to_usbdev(dev->interface); + + usb_dbg(dev->interface, "fill"); + + /* Return immediately if someone called before the buffer was + * empty */ + if (dev->valid != dev->used) { + usb_dbg(dev->interface, "not empty yet (valid %d used %d)", + dev->valid, dev->used); + return 0; + } + + /* Bail if the device has been removed */ + if (!dev->present) { + usb_dbg(dev->interface, "device not present"); + return -ENODEV; + } + + /* Make sure the device is awake */ + result = usb_autopm_get_interface(dev->interface); + if (result) { + usb_dbg(dev->interface, "wakeup failed (result %d)", result); + return result; + } + + result = usb_bulk_msg(udev, + usb_rcvbulkpipe(udev, dev->in_ep), + dev->buf, dev->size, &this_read, + NAK_TIMEOUT); + + /* Let the device go back to sleep eventually */ + usb_autopm_put_interface(dev->interface); + + if (result == 0) { + dev->valid = this_read; + dev->used = 0; + } + + usb_dbg(dev->interface, "bulk_msg result %d this_read %d", + result, this_read); + + return result; +} + +static ssize_t chaoskey_read(struct file *file, + char __user *buffer, + size_t count, + loff_t *ppos) +{ + struct chaoskey *dev; + ssize_t read_count = 0; + int this_time; + int result = 0; + unsigned long remain; + + dev = file->private_data; + + if (dev == NULL || !dev->present) + return -ENODEV; + + usb_dbg(dev->interface, "read %zu", count); + + while (count > 0) { + + /* Grab the rng_lock briefly to ensure that the hwrng interface + * gets priority over other user access + */ + result = mutex_lock_interruptible(&dev->rng_lock); + if (result) + goto bail; + mutex_unlock(&dev->rng_lock); + + result = mutex_lock_interruptible(&dev->lock); + if (result) + goto bail; + if (dev->valid == dev->used) { + result = _chaoskey_fill(dev); + if (result) { + mutex_unlock(&dev->lock); + goto bail; + } + + /* Read returned zero bytes */ + if (dev->used == dev->valid) { + mutex_unlock(&dev->lock); + goto bail; + } + } + + this_time = dev->valid - dev->used; + if (this_time > count) + this_time = count; + + remain = copy_to_user(buffer, dev->buf + dev->used, this_time); + if (remain) { + result = -EFAULT; + + /* Consume the bytes that were copied so we don't leak + * data to user space + */ + dev->used += this_time - remain; + mutex_unlock(&dev->lock); + goto bail; + } + + count -= this_time; + read_count += this_time; + buffer += this_time; + dev->used += this_time; + mutex_unlock(&dev->lock); + } +bail: + if (read_count) { + usb_dbg(dev->interface, "read %zu bytes", read_count); + return read_count; + } + usb_dbg(dev->interface, "empty read, result %d", result); + return result; +} + +static int chaoskey_rng_read(struct hwrng *rng, void *data, + size_t max, bool wait) +{ + struct chaoskey *dev = container_of(rng, struct chaoskey, hwrng); + int this_time; + + usb_dbg(dev->interface, "rng_read max %zu wait %d", max, wait); + + if (!dev->present) { + usb_dbg(dev->interface, "device not present"); + return 0; + } + + /* Hold the rng_lock until we acquire the device lock so that + * this operation gets priority over other user access to the + * device + */ + mutex_lock(&dev->rng_lock); + + mutex_lock(&dev->lock); + + mutex_unlock(&dev->rng_lock); + + /* Try to fill the buffer if empty. It doesn't actually matter + * if _chaoskey_fill works; we'll just return zero bytes as + * the buffer will still be empty + */ + if (dev->valid == dev->used) + (void) _chaoskey_fill(dev); + + this_time = dev->valid - dev->used; + if (this_time > max) + this_time = max; + + memcpy(data, dev->buf, this_time); + + dev->used += this_time; + + mutex_unlock(&dev->lock); + + usb_dbg(dev->interface, "rng_read this_time %d\n", this_time); + return this_time; +} + +#ifdef CONFIG_PM +static int chaoskey_suspend(struct usb_interface *interface, + pm_message_t message) +{ + usb_dbg(interface, "suspend"); + return 0; +} + +static int chaoskey_resume(struct usb_interface *interface) +{ + usb_dbg(interface, "resume"); + return 0; +} +#else +#define chaoskey_suspend NULL +#define chaoskey_resume NULL +#endif + +/* file operation pointers */ +static const struct file_operations chaoskey_fops = { + .owner = THIS_MODULE, + .read = chaoskey_read, + .open = chaoskey_open, + .release = chaoskey_release, + .llseek = default_llseek, +}; + +/* class driver information */ +static struct usb_class_driver chaoskey_class = { + .name = "chaoskey%d", + .fops = &chaoskey_fops, + .minor_base = USB_CHAOSKEY_MINOR_BASE, +}; + +/* usb specific object needed to register this driver with the usb subsystem */ +static struct usb_driver chaoskey_driver = { + .name = DRIVER_SHORT, + .probe = chaoskey_probe, + .disconnect = chaoskey_disconnect, + .suspend = chaoskey_suspend, + .resume = chaoskey_resume, + .reset_resume = chaoskey_resume, + .id_table = chaoskey_table, + .supports_autosuspend = 1, +}; + +module_usb_driver(chaoskey_driver); + -- cgit v0.10.2 From 1da47f54ddaf99d2fa8b4319480d49b88ff5fc2c Mon Sep 17 00:00:00 2001 From: Viresh Kumar Date: Fri, 20 Mar 2015 09:04:40 +0530 Subject: USB: Use usb_disabled() consistently At few places we have used usb_disabled() and at other places used 'nousb' directly. Lets be consistent and use usb_disabled(); Signed-off-by: Viresh Kumar Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index b1fb9ae..0069517 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c @@ -1045,7 +1045,7 @@ static void usb_debugfs_cleanup(void) static int __init usb_init(void) { int retval; - if (nousb) { + if (usb_disabled()) { pr_info("%s: USB support disabled\n", usbcore_name); return 0; } @@ -1102,7 +1102,7 @@ out: static void __exit usb_exit(void) { /* This will matter if shutdown/reboot does exitcalls. */ - if (nousb) + if (usb_disabled()) return; usb_deregister_device_driver(&usb_generic_driver); -- cgit v0.10.2 From bb3247a34257a271b32d43244eabf71198f40ff0 Mon Sep 17 00:00:00 2001 From: Viresh Kumar Date: Fri, 20 Mar 2015 09:04:41 +0530 Subject: USB: Move usb_disabled() towards top of the file Move usb_disabled() and module_param()/core_param() towards the top of the file, where 'nousb' is defined, as they are all related. Signed-off-by: Viresh Kumar Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index 0069517..8d5b2f4 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c @@ -49,6 +49,22 @@ const char *usbcore_name = "usbcore"; static bool nousb; /* Disable USB when built into kernel image */ +/* To disable USB, kernel command line is 'nousb' not 'usbcore.nousb' */ +#ifdef MODULE +module_param(nousb, bool, 0444); +#else +core_param(nousb, nousb, bool, 0444); +#endif + +/* + * for external read access to + */ +int usb_disabled(void) +{ + return nousb; +} +EXPORT_SYMBOL_GPL(usb_disabled); + #ifdef CONFIG_PM static int usb_autosuspend_delay = 2; /* Default delay value, * in seconds */ @@ -964,22 +980,6 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in, EXPORT_SYMBOL_GPL(usb_buffer_unmap_sg); #endif -/* To disable USB, kernel command line is 'nousb' not 'usbcore.nousb' */ -#ifdef MODULE -module_param(nousb, bool, 0444); -#else -core_param(nousb, nousb, bool, 0444); -#endif - -/* - * for external read access to - */ -int usb_disabled(void) -{ - return nousb; -} -EXPORT_SYMBOL_GPL(usb_disabled); - /* * Notifications of device and interface registration */ -- cgit v0.10.2 From 24677af8693647d611448651f7df3ddc3211aa83 Mon Sep 17 00:00:00 2001 From: Thomas Petazzoni Date: Thu, 19 Mar 2015 15:01:07 +0100 Subject: usb: ehci-orion: add more constants for register values This commit adds new register values for the USB_CMD and USB_MODE registers, which allows to avoid the usage of a number of magic values in orion_usb_phy_v1_setup(). Signed-off-by: Thomas Petazzoni Acked-by: Alan Stern Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/host/ehci-orion.c b/drivers/usb/host/ehci-orion.c index f6eafec..bfcbb9a 100644 --- a/drivers/usb/host/ehci-orion.c +++ b/drivers/usb/host/ehci-orion.c @@ -29,7 +29,13 @@ #define wrl(off, val) writel_relaxed((val), hcd->regs + (off)) #define USB_CMD 0x140 +#define USB_CMD_RUN BIT(0) +#define USB_CMD_RESET BIT(1) #define USB_MODE 0x1a8 +#define USB_MODE_MASK GENMASK(1, 0) +#define USB_MODE_DEVICE 0x2 +#define USB_MODE_HOST 0x3 +#define USB_MODE_SDIS BIT(4) #define USB_CAUSE 0x310 #define USB_MASK 0x314 #define USB_WINDOW_CTRL(i) (0x320 + ((i) << 4)) @@ -69,8 +75,8 @@ static void orion_usb_phy_v1_setup(struct usb_hcd *hcd) /* * Reset controller */ - wrl(USB_CMD, rdl(USB_CMD) | 0x2); - while (rdl(USB_CMD) & 0x2); + wrl(USB_CMD, rdl(USB_CMD) | USB_CMD_RESET); + while (rdl(USB_CMD) & USB_CMD_RESET); /* * GL# USB-10: Set IPG for non start of frame packets @@ -112,16 +118,16 @@ static void orion_usb_phy_v1_setup(struct usb_hcd *hcd) /* * Stop and reset controller */ - wrl(USB_CMD, rdl(USB_CMD) & ~0x1); - wrl(USB_CMD, rdl(USB_CMD) | 0x2); - while (rdl(USB_CMD) & 0x2); + wrl(USB_CMD, rdl(USB_CMD) & ~USB_CMD_RUN); + wrl(USB_CMD, rdl(USB_CMD) | USB_CMD_RESET); + while (rdl(USB_CMD) & USB_CMD_RESET); /* * GL# USB-5 Streaming disable REG_USB_MODE[4]=1 * TBD: This need to be done after each reset! * GL# USB-4 Setup USB Host mode */ - wrl(USB_MODE, 0x13); + wrl(USB_MODE, USB_MODE_SDIS | USB_MODE_HOST); } static void -- cgit v0.10.2 From 8373856d94aae5adf25f9e3388747c53867f1ab0 Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Mon, 23 Mar 2015 19:57:36 +0800 Subject: MAINTAINERS: change my git address to kernel.org Signed-off-by: Peter Chen Signed-off-by: Greg Kroah-Hartman diff --git a/MAINTAINERS b/MAINTAINERS index 059a9d4..6700a98 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2518,7 +2518,7 @@ F: Documentation/zh_CN/ CHIPIDEA USB HIGH SPEED DUAL ROLE CONTROLLER M: Peter Chen -T: git git://github.com/hzpeterchen/linux-usb.git +T: git git://git.kernel.org/pub/scm/linux/kernel/git/peter.chen/usb.git L: linux-usb@vger.kernel.org S: Maintained F: drivers/usb/chipidea/ @@ -10215,7 +10215,7 @@ F: drivers/usb/host/ohci* USB OTG FSM (Finite State Machine) M: Peter Chen -T: git git://github.com/hzpeterchen/linux-usb.git +T: git git://git.kernel.org/pub/scm/linux/kernel/git/peter.chen/usb.git L: linux-usb@vger.kernel.org S: Maintained F: drivers/usb/common/usb-otg-fsm.c -- cgit v0.10.2 From 76cb03e7d5d7ba49175784dce961696da66c44cc Mon Sep 17 00:00:00 2001 From: Oliver Neukum Date: Fri, 20 Mar 2015 14:28:56 +0100 Subject: cdc-wdm: return correct error codes Lieing to user space is wrong. The real reason for a failure to write should be returned to user space. Signed-off-by: Oliver Neukum 0 Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c index a051a7a..f053b41 100644 --- a/drivers/usb/class/cdc-wdm.c +++ b/drivers/usb/class/cdc-wdm.c @@ -339,7 +339,7 @@ static ssize_t wdm_write desc->werr = 0; spin_unlock_irq(&desc->iuspin); if (we < 0) - return -EIO; + return usb_translate_errors(we); buf = kmalloc(count, GFP_KERNEL); if (!buf) { -- cgit v0.10.2 From c0ab6bb0597363532f178f3cd7b7fb527eef39e2 Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Wed, 18 Mar 2015 14:37:45 -0400 Subject: usb/misc/usb3503: Always read refclk frequency from DT This is necessary to set REF_SEL appropriately in uses where refclk is always available. Signed-off-by: Ben Gamari Acked-by: Marek Szyprowski Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/misc/usb3503.c b/drivers/usb/misc/usb3503.c index 258d2f5..64ff5b9 100644 --- a/drivers/usb/misc/usb3503.c +++ b/drivers/usb/misc/usb3503.c @@ -186,8 +186,31 @@ static int usb3503_probe(struct usb3503 *hub) hub->mode = pdata->initial_mode; } else if (np) { struct clk *clk; + u32 rate = 0; hub->port_off_mask = 0; + if (!of_property_read_u32(np, "refclk-frequency", &rate)) { + switch (rate) { + case 38400000: + case 26000000: + case 19200000: + case 12000000: + hub->secondary_ref_clk = 0; + break; + case 24000000: + case 27000000: + case 25000000: + case 50000000: + hub->secondary_ref_clk = 1; + break; + default: + dev_err(dev, + "unsupported reference clock rate (%d)\n", + (int) rate); + return -EINVAL; + } + } + clk = devm_clk_get(dev, "refclk"); if (IS_ERR(clk) && PTR_ERR(clk) != -ENOENT) { dev_err(dev, "unable to request refclk (%ld)\n", @@ -196,31 +219,9 @@ static int usb3503_probe(struct usb3503 *hub) } if (!IS_ERR(clk)) { - u32 rate = 0; hub->clk = clk; - if (!of_property_read_u32(np, "refclk-frequency", - &rate)) { - - switch (rate) { - case 38400000: - case 26000000: - case 19200000: - case 12000000: - hub->secondary_ref_clk = 0; - break; - case 24000000: - case 27000000: - case 25000000: - case 50000000: - hub->secondary_ref_clk = 1; - break; - default: - dev_err(dev, - "unsupported reference clock rate (%d)\n", - (int) rate); - return -EINVAL; - } + if (rate != 0) { err = clk_set_rate(hub->clk, rate); if (err) { dev_err(dev, -- cgit v0.10.2 From 36e59e0d70d6150e7a2155c54612ea875e88ce8d Mon Sep 17 00:00:00 2001 From: Oliver Neukum Date: Fri, 20 Mar 2015 09:24:24 +0100 Subject: cdc-acm: fix race between callback and unthrottle Abn URB may be may marked free only after the buffer has been processed or there is a small window during which it could be submitted on another CPU and overwrite an unprocessed buffer Signed-off-by: Oliver Neukum Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index 6836177..58241ec 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c @@ -417,25 +417,33 @@ static void acm_read_bulk_callback(struct urb *urb) struct acm_rb *rb = urb->context; struct acm *acm = rb->instance; unsigned long flags; + int status = urb->status; dev_vdbg(&acm->data->dev, "%s - urb %d, len %d\n", __func__, rb->index, urb->actual_length); - set_bit(rb->index, &acm->read_urbs_free); if (!acm->dev) { + set_bit(rb->index, &acm->read_urbs_free); dev_dbg(&acm->data->dev, "%s - disconnected\n", __func__); return; } if (urb->status) { + set_bit(rb->index, &acm->read_urbs_free); dev_dbg(&acm->data->dev, "%s - non-zero urb status: %d\n", - __func__, urb->status); + __func__, status); return; } usb_mark_last_busy(acm->dev); acm_process_read_urb(acm, urb); + /* + * Unthrottle may run on another CPU which needs to see events + * in the same order. Submission has an implict barrier + */ + smp_mb__before_atomic(); + set_bit(rb->index, &acm->read_urbs_free); /* throttle device if requested by tty */ spin_lock_irqsave(&acm->read_lock, flags); -- cgit v0.10.2 From 6c8074e90c7350f5e38caf1e8d73e98df4115403 Mon Sep 17 00:00:00 2001 From: Oliver Neukum Date: Fri, 20 Mar 2015 11:25:17 +0100 Subject: cdc-acm: surpress misleading message During the entry intro suspend a misleading message can be printed. Surpress it by checking the specific error. Signed-off-by: Oliver Neukum 0 Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index 58241ec..43cb058 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c @@ -360,7 +360,7 @@ static void acm_ctrl_irq(struct urb *urb) } exit: retval = usb_submit_urb(urb, GFP_ATOMIC); - if (retval) + if (retval && retval != -EPERM) dev_err(&acm->control->dev, "%s - usb_submit_urb failed: %d\n", __func__, retval); } -- cgit v0.10.2 From 4132cd02db180d018325e26bd145a509a14fcd6b Mon Sep 17 00:00:00 2001 From: Oliver Neukum Date: Fri, 20 Mar 2015 11:41:06 +0100 Subject: cdc-acm: convert to not directly using urb->status A step on the road to passing status as a parameter Signed-off-by: Oliver Neukum Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index 43cb058..3e15add 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c @@ -428,7 +428,7 @@ static void acm_read_bulk_callback(struct urb *urb) return; } - if (urb->status) { + if (status) { set_bit(rb->index, &acm->read_urbs_free); dev_dbg(&acm->data->dev, "%s - non-zero urb status: %d\n", __func__, status); @@ -462,13 +462,14 @@ static void acm_write_bulk(struct urb *urb) struct acm_wb *wb = urb->context; struct acm *acm = wb->instance; unsigned long flags; + int status = urb->status; - if (urb->status || (urb->actual_length != urb->transfer_buffer_length)) + if (status || (urb->actual_length != urb->transfer_buffer_length)) dev_vdbg(&acm->data->dev, "%s - len %d/%d, status %d\n", __func__, urb->actual_length, urb->transfer_buffer_length, - urb->status); + status); spin_lock_irqsave(&acm->write_lock, flags); acm_write_done(acm, wb); -- cgit v0.10.2 From 28965e17ee7a9591c241b831fee050d2391688c6 Mon Sep 17 00:00:00 2001 From: Oliver Neukum Date: Fri, 20 Mar 2015 14:29:18 +0100 Subject: cdc-wdm: unify error handling in write This makes sure the error handling path is the same for all error conditions, thus reducing code duplication. Signed-off-by: Oliver Neukum 0 Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c index f053b41..cdc93d0 100644 --- a/drivers/usb/class/cdc-wdm.c +++ b/drivers/usb/class/cdc-wdm.c @@ -349,30 +349,25 @@ static ssize_t wdm_write r = copy_from_user(buf, buffer, count); if (r > 0) { - kfree(buf); rv = -EFAULT; - goto outnl; + goto out_free_mem; } /* concurrent writes and disconnect */ r = mutex_lock_interruptible(&desc->wlock); rv = -ERESTARTSYS; - if (r) { - kfree(buf); - goto outnl; - } + if (r) + goto out_free_mem; if (test_bit(WDM_DISCONNECTING, &desc->flags)) { - kfree(buf); rv = -ENODEV; - goto outnp; + goto out_free_mem_lock; } r = usb_autopm_get_interface(desc->intf); if (r < 0) { - kfree(buf); rv = usb_translate_errors(r); - goto outnp; + goto out_free_mem_lock; } if (!(file->f_flags & O_NONBLOCK)) @@ -386,9 +381,8 @@ static ssize_t wdm_write r = -EIO; if (r < 0) { - kfree(buf); rv = r; - goto out; + goto out_free_mem_pm; } req = desc->orq; @@ -415,21 +409,28 @@ static ssize_t wdm_write rv = usb_submit_urb(desc->command, GFP_KERNEL); if (rv < 0) { - kfree(buf); desc->outbuf = NULL; clear_bit(WDM_IN_USE, &desc->flags); dev_err(&desc->intf->dev, "Tx URB error: %d\n", rv); rv = usb_translate_errors(rv); + goto out_free_mem_pm; } else { dev_dbg(&desc->intf->dev, "Tx URB has been submitted index=%d", req->wIndex); } -out: + usb_autopm_put_interface(desc->intf); -outnp: mutex_unlock(&desc->wlock); outnl: return rv < 0 ? rv : count; + +out_free_mem_pm: + usb_autopm_put_interface(desc->intf); +out_free_mem_lock: + mutex_unlock(&desc->wlock); +out_free_mem: + kfree(buf); + return rv; } /* -- cgit v0.10.2 From 323ece54e0761198946ecd0c2091f1d2bfdfcb64 Mon Sep 17 00:00:00 2001 From: Oliver Neukum Date: Fri, 20 Mar 2015 14:29:34 +0100 Subject: cdc-wdm: fix endianness bug in debug statements Values directly from descriptors given in debug statements must be converted to native endianness. Signed-off-by: Oliver Neukum CC: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c index cdc93d0..8e32b8d 100644 --- a/drivers/usb/class/cdc-wdm.c +++ b/drivers/usb/class/cdc-wdm.c @@ -245,7 +245,7 @@ static void wdm_int_callback(struct urb *urb) case USB_CDC_NOTIFY_RESPONSE_AVAILABLE: dev_dbg(&desc->intf->dev, "NOTIFY_RESPONSE_AVAILABLE received: index %d len %d", - dr->wIndex, dr->wLength); + le16_to_cpu(dr->wIndex), le16_to_cpu(dr->wLength)); break; case USB_CDC_NOTIFY_NETWORK_CONNECTION: @@ -262,7 +262,9 @@ static void wdm_int_callback(struct urb *urb) clear_bit(WDM_POLL_RUNNING, &desc->flags); dev_err(&desc->intf->dev, "unknown notification %d received: index %d len %d\n", - dr->bNotificationType, dr->wIndex, dr->wLength); + dr->bNotificationType, + le16_to_cpu(dr->wIndex), + le16_to_cpu(dr->wLength)); goto exit; } @@ -402,7 +404,7 @@ static ssize_t wdm_write USB_RECIP_INTERFACE); req->bRequest = USB_CDC_SEND_ENCAPSULATED_COMMAND; req->wValue = 0; - req->wIndex = desc->inum; + req->wIndex = desc->inum; /* already converted */ req->wLength = cpu_to_le16(count); set_bit(WDM_IN_USE, &desc->flags); desc->outbuf = buf; @@ -416,7 +418,7 @@ static ssize_t wdm_write goto out_free_mem_pm; } else { dev_dbg(&desc->intf->dev, "Tx URB has been submitted index=%d", - req->wIndex); + le16_to_cpu(req->wIndex)); } usb_autopm_put_interface(desc->intf); @@ -821,7 +823,7 @@ static int wdm_create(struct usb_interface *intf, struct usb_endpoint_descriptor desc->irq->bRequestType = (USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE); desc->irq->bRequest = USB_CDC_GET_ENCAPSULATED_RESPONSE; desc->irq->wValue = 0; - desc->irq->wIndex = desc->inum; + desc->irq->wIndex = desc->inum; /* already converted */ desc->irq->wLength = cpu_to_le16(desc->wMaxCommand); usb_fill_control_urb( -- cgit v0.10.2 From 85e8a0b9a3565c8185068b6b340cc8c6dd4411f4 Mon Sep 17 00:00:00 2001 From: Oliver Neukum Date: Mon, 23 Mar 2015 14:34:43 +0100 Subject: cdc-wdm: error returns need to be translated One more case of error codes not correctly being correctly returned to user space. Signed-off-by: Olive Neukum 0 Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c index 8e32b8d..61ea879 100644 --- a/drivers/usb/class/cdc-wdm.c +++ b/drivers/usb/class/cdc-wdm.c @@ -522,9 +522,9 @@ retry: spin_lock_irq(&desc->iuspin); if (desc->rerr) { /* read completed, error happened */ + rv = usb_translate_errors(desc->rerr); desc->rerr = 0; spin_unlock_irq(&desc->iuspin); - rv = -EIO; goto err; } /* -- cgit v0.10.2 From 963719c872a3a71bc2abf4d4899392acab93b09d Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Tue, 17 Mar 2015 17:15:47 +0100 Subject: USB: host: ohci-at91: remove useless uclk clock Now that the system clock driver is forwarding set_rate request to the parent clock, we can safely call clk_set_rate on the system clk and get rid of the uclk field. Signed-off-by: Boris Brezillon Acked-by: Alan Stern Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c index 7cce85a..15df00c 100644 --- a/drivers/usb/host/ohci-at91.c +++ b/drivers/usb/host/ohci-at91.c @@ -39,7 +39,6 @@ struct ohci_at91_priv { struct clk *iclk; struct clk *fclk; - struct clk *uclk; struct clk *hclk; bool clocked; bool wakeup; /* Saved wake-up state for resume */ @@ -64,10 +63,8 @@ static void at91_start_clock(struct ohci_at91_priv *ohci_at91) { if (ohci_at91->clocked) return; - if (IS_ENABLED(CONFIG_COMMON_CLK)) { - clk_set_rate(ohci_at91->uclk, 48000000); - clk_prepare_enable(ohci_at91->uclk); - } + + clk_set_rate(ohci_at91->fclk, 48000000); clk_prepare_enable(ohci_at91->hclk); clk_prepare_enable(ohci_at91->iclk); clk_prepare_enable(ohci_at91->fclk); @@ -78,11 +75,10 @@ static void at91_stop_clock(struct ohci_at91_priv *ohci_at91) { if (!ohci_at91->clocked) return; + clk_disable_unprepare(ohci_at91->fclk); clk_disable_unprepare(ohci_at91->iclk); clk_disable_unprepare(ohci_at91->hclk); - if (IS_ENABLED(CONFIG_COMMON_CLK)) - clk_disable_unprepare(ohci_at91->uclk); ohci_at91->clocked = false; } @@ -191,14 +187,6 @@ static int usb_hcd_at91_probe(const struct hc_driver *driver, retval = PTR_ERR(ohci_at91->hclk); goto err; } - if (IS_ENABLED(CONFIG_COMMON_CLK)) { - ohci_at91->uclk = devm_clk_get(dev, "usb_clk"); - if (IS_ERR(ohci_at91->uclk)) { - dev_err(dev, "failed to get uclk\n"); - retval = PTR_ERR(ohci_at91->uclk); - goto err; - } - } board = hcd->self.controller->platform_data; ohci = hcd_to_ohci(hcd); -- cgit v0.10.2 From 01ecd156905f6bbfe4f5bd278325071f9141726d Mon Sep 17 00:00:00 2001 From: Li Jun Date: Fri, 20 Mar 2015 16:28:04 +0800 Subject: usb: chipidea: otg: remove unnecessary B_SESS_VLD timer Since BSV irq is enabled for B-device all the time, so B_SESS_VLD timer is not required, and also no need to check BSV status when B_ASE0_BRST timer timeout. Signed-off-by: Li Jun Signed-off-by: Peter Chen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/chipidea/otg_fsm.c b/drivers/usb/chipidea/otg_fsm.c index e3cf5be..3014e2c 100644 --- a/drivers/usb/chipidea/otg_fsm.c +++ b/drivers/usb/chipidea/otg_fsm.c @@ -320,17 +320,6 @@ static void a_wait_vfall_tmout_func(void *ptr, unsigned long indicator) ci_otg_queue_work(ci); } -static void b_ase0_brst_tmout_func(void *ptr, unsigned long indicator) -{ - struct ci_hdrc *ci = (struct ci_hdrc *)ptr; - - set_tmout(ci, indicator); - if (!hw_read_otgsc(ci, OTGSC_BSV)) - ci->fsm.b_sess_vld = 0; - - ci_otg_queue_work(ci); -} - static void b_ssend_srp_tmout_func(void *ptr, unsigned long indicator) { struct ci_hdrc *ci = (struct ci_hdrc *)ptr; @@ -342,18 +331,6 @@ static void b_ssend_srp_tmout_func(void *ptr, unsigned long indicator) ci_otg_queue_work(ci); } -static void b_sess_vld_tmout_func(void *ptr, unsigned long indicator) -{ - struct ci_hdrc *ci = (struct ci_hdrc *)ptr; - - /* Check if A detached */ - if (!(hw_read_otgsc(ci, OTGSC_BSV))) { - ci->fsm.b_sess_vld = 0; - ci_otg_add_timer(ci, B_SSEND_SRP); - ci_otg_queue_work(ci); - } -} - static void b_data_pulse_end(void *ptr, unsigned long indicator) { struct ci_hdrc *ci = (struct ci_hdrc *)ptr; @@ -405,7 +382,7 @@ static int ci_otg_init_timers(struct ci_hdrc *ci) return -ENOMEM; ci->fsm_timer->timer_list[B_ASE0_BRST] = - otg_timer_initializer(ci, &b_ase0_brst_tmout_func, TB_ASE0_BRST, + otg_timer_initializer(ci, &set_tmout_and_fsm, TB_ASE0_BRST, (unsigned long)&fsm->b_ase0_brst_tmout); if (ci->fsm_timer->timer_list[B_ASE0_BRST] == NULL) return -ENOMEM; @@ -433,11 +410,6 @@ static int ci_otg_init_timers(struct ci_hdrc *ci) if (ci->fsm_timer->timer_list[B_DATA_PLS] == NULL) return -ENOMEM; - ci->fsm_timer->timer_list[B_SESS_VLD] = otg_timer_initializer(ci, - &b_sess_vld_tmout_func, TB_SESS_VLD, 0); - if (ci->fsm_timer->timer_list[B_SESS_VLD] == NULL) - return -ENOMEM; - return 0; } @@ -671,7 +643,6 @@ static void ci_otg_fsm_event(struct ci_hdrc *ci) fsm->a_conn = 0; fsm->b_bus_req = 0; ci_otg_queue_work(ci); - ci_otg_add_timer(ci, B_SESS_VLD); } break; case OTG_STATE_A_PERIPHERAL: diff --git a/drivers/usb/chipidea/otg_fsm.h b/drivers/usb/chipidea/otg_fsm.h index 94c085f..d0ad4f9 100644 --- a/drivers/usb/chipidea/otg_fsm.h +++ b/drivers/usb/chipidea/otg_fsm.h @@ -62,8 +62,6 @@ /* SSEND time before SRP */ #define TB_SSEND_SRP (1500) /* minimum 1.5 sec, section:5.1.2 */ -#define TB_SESS_VLD (1000) - enum ci_otg_fsm_timer_index { /* * CI specific timers, start from the end @@ -71,7 +69,6 @@ enum ci_otg_fsm_timer_index { */ B_DATA_PLS = NUM_OTG_FSM_TIMERS, B_SSEND_SRP, - B_SESS_VLD, NUM_CI_OTG_FSM_TIMERS, }; -- cgit v0.10.2 From 2f8a467a11aeec61f5077cd337b4efe74847e1d3 Mon Sep 17 00:00:00 2001 From: Li Jun Date: Fri, 20 Mar 2015 16:28:05 +0800 Subject: usb: otg-fsm: move 2 otg fsm timers definition to otg_fsm_timer B_DATA_PLS(data-line pulse time) and B_SSEND_SRP(session end to SRP init) are also from OTG&EH 2.0 Specification and they are not chipidea specific. Signed-off-by: Li Jun Signed-off-by: Peter Chen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/chipidea/otg_fsm.c b/drivers/usb/chipidea/otg_fsm.c index 3014e2c..ba2cb91 100644 --- a/drivers/usb/chipidea/otg_fsm.c +++ b/drivers/usb/chipidea/otg_fsm.c @@ -206,13 +206,13 @@ static struct attribute_group inputs_attr_group = { /* * Add timer to active timer list */ -static void ci_otg_add_timer(struct ci_hdrc *ci, enum ci_otg_fsm_timer_index t) +static void ci_otg_add_timer(struct ci_hdrc *ci, enum otg_fsm_timer t) { struct ci_otg_fsm_timer *tmp_timer; struct ci_otg_fsm_timer *timer = ci->fsm_timer->timer_list[t]; struct list_head *active_timers = &ci->fsm_timer->active_timers; - if (t >= NUM_CI_OTG_FSM_TIMERS) + if (t >= NUM_OTG_FSM_TIMERS) return; /* @@ -239,14 +239,14 @@ static void ci_otg_add_timer(struct ci_hdrc *ci, enum ci_otg_fsm_timer_index t) /* * Remove timer from active timer list */ -static void ci_otg_del_timer(struct ci_hdrc *ci, enum ci_otg_fsm_timer_index t) +static void ci_otg_del_timer(struct ci_hdrc *ci, enum otg_fsm_timer t) { struct ci_otg_fsm_timer *tmp_timer, *del_tmp; struct ci_otg_fsm_timer *timer = ci->fsm_timer->timer_list[t]; struct list_head *active_timers = &ci->fsm_timer->active_timers; int flag = 0; - if (t >= NUM_CI_OTG_FSM_TIMERS) + if (t >= NUM_OTG_FSM_TIMERS) return; list_for_each_entry_safe(tmp_timer, del_tmp, active_timers, list) diff --git a/drivers/usb/chipidea/otg_fsm.h b/drivers/usb/chipidea/otg_fsm.h index d0ad4f9..9e0fc4c 100644 --- a/drivers/usb/chipidea/otg_fsm.h +++ b/drivers/usb/chipidea/otg_fsm.h @@ -62,17 +62,6 @@ /* SSEND time before SRP */ #define TB_SSEND_SRP (1500) /* minimum 1.5 sec, section:5.1.2 */ -enum ci_otg_fsm_timer_index { - /* - * CI specific timers, start from the end - * of standard and auxiliary OTG timers - */ - B_DATA_PLS = NUM_OTG_FSM_TIMERS, - B_SSEND_SRP, - - NUM_CI_OTG_FSM_TIMERS, -}; - struct ci_otg_fsm_timer { unsigned long expires; /* Number of count increase to timeout */ unsigned long count; /* Tick counter */ @@ -82,7 +71,7 @@ struct ci_otg_fsm_timer { }; struct ci_otg_fsm_timer_list { - struct ci_otg_fsm_timer *timer_list[NUM_CI_OTG_FSM_TIMERS]; + struct ci_otg_fsm_timer *timer_list[NUM_OTG_FSM_TIMERS]; struct list_head active_timers; }; diff --git a/include/linux/usb/otg-fsm.h b/include/linux/usb/otg-fsm.h index b6ba1bf..f728f18 100644 --- a/include/linux/usb/otg-fsm.h +++ b/include/linux/usb/otg-fsm.h @@ -53,6 +53,8 @@ enum otg_fsm_timer { B_SE0_SRP, B_SRP_FAIL, A_WAIT_ENUM, + B_DATA_PLS, + B_SSEND_SRP, NUM_OTG_FSM_TIMERS, }; -- cgit v0.10.2 From 3a316ec4c91cfe03093d708369f9ab57000c96c3 Mon Sep 17 00:00:00 2001 From: Li Jun Date: Fri, 20 Mar 2015 16:28:06 +0800 Subject: usb: chipidea: use hrtimer for otg fsm timers Current otg fsm timers are using controller 1ms irq and count it, this patch is to replace it with hrtimer solution, use one hrtimer for all otg timers. Signed-off-by: Li Jun Signed-off-by: Peter Chen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h index c09381d..6d6200e 100644 --- a/drivers/usb/chipidea/ci.h +++ b/drivers/usb/chipidea/ci.h @@ -162,7 +162,10 @@ struct hw_bank { * @role: current role * @is_otg: if the device is otg-capable * @fsm: otg finite state machine - * @fsm_timer: pointer to timer list of otg fsm + * @otg_fsm_hrtimer: hrtimer for otg fsm timers + * @hr_timeouts: time out list for active otg fsm timers + * @enabled_otg_timer_bits: bits of enabled otg timers + * @next_otg_timer: next nearest enabled timer to be expired * @work: work for role changing * @wq: workqueue thread * @qh_pool: allocation pool for queue heads @@ -205,7 +208,10 @@ struct ci_hdrc { bool is_otg; struct usb_otg otg; struct otg_fsm fsm; - struct ci_otg_fsm_timer_list *fsm_timer; + struct hrtimer otg_fsm_hrtimer; + ktime_t hr_timeouts[NUM_OTG_FSM_TIMERS]; + unsigned enabled_otg_timer_bits; + enum otg_fsm_timer next_otg_timer; struct work_struct work; struct workqueue_struct *wq; diff --git a/drivers/usb/chipidea/otg_fsm.c b/drivers/usb/chipidea/otg_fsm.c index ba2cb91..083acf4 100644 --- a/drivers/usb/chipidea/otg_fsm.c +++ b/drivers/usb/chipidea/otg_fsm.c @@ -30,22 +30,6 @@ #include "otg.h" #include "otg_fsm.h" -static struct ci_otg_fsm_timer *otg_timer_initializer -(struct ci_hdrc *ci, void (*function)(void *, unsigned long), - unsigned long expires, unsigned long data) -{ - struct ci_otg_fsm_timer *timer; - - timer = devm_kzalloc(ci->dev, sizeof(struct ci_otg_fsm_timer), - GFP_KERNEL); - if (!timer) - return NULL; - timer->function = function; - timer->expires = expires; - timer->data = data; - return timer; -} - /* Add for otg: interact with user space app */ static ssize_t get_a_bus_req(struct device *dev, struct device_attribute *attr, char *buf) @@ -204,36 +188,48 @@ static struct attribute_group inputs_attr_group = { }; /* + * Keep this list in the same order as timers indexed + * by enum otg_fsm_timer in include/linux/usb/otg-fsm.h + */ +static unsigned otg_timer_ms[] = { + TA_WAIT_VRISE, + TA_WAIT_VFALL, + TA_WAIT_BCON, + TA_AIDL_BDIS, + TB_ASE0_BRST, + TA_BIDL_ADIS, + TB_SE0_SRP, + TB_SRP_FAIL, + 0, + TB_DATA_PLS, + TB_SSEND_SRP, +}; + +/* * Add timer to active timer list */ static void ci_otg_add_timer(struct ci_hdrc *ci, enum otg_fsm_timer t) { - struct ci_otg_fsm_timer *tmp_timer; - struct ci_otg_fsm_timer *timer = ci->fsm_timer->timer_list[t]; - struct list_head *active_timers = &ci->fsm_timer->active_timers; + unsigned long flags, timer_sec, timer_nsec; if (t >= NUM_OTG_FSM_TIMERS) return; - /* - * Check if the timer is already in the active list, - * if so update timer count - */ - list_for_each_entry(tmp_timer, active_timers, list) - if (tmp_timer == timer) { - timer->count = timer->expires; - return; - } - - if (list_empty(active_timers)) - pm_runtime_get(ci->dev); - - timer->count = timer->expires; - list_add_tail(&timer->list, active_timers); - - /* Enable 1ms irq */ - if (!(hw_read_otgsc(ci, OTGSC_1MSIE))) - hw_write_otgsc(ci, OTGSC_1MSIE, OTGSC_1MSIE); + spin_lock_irqsave(&ci->lock, flags); + timer_sec = otg_timer_ms[t] / MSEC_PER_SEC; + timer_nsec = (otg_timer_ms[t] % MSEC_PER_SEC) * NSEC_PER_MSEC; + ci->hr_timeouts[t] = ktime_add(ktime_get(), + ktime_set(timer_sec, timer_nsec)); + ci->enabled_otg_timer_bits |= (1 << t); + if ((ci->next_otg_timer == NUM_OTG_FSM_TIMERS) || + (ci->hr_timeouts[ci->next_otg_timer].tv64 > + ci->hr_timeouts[t].tv64)) { + ci->next_otg_timer = t; + hrtimer_start_range_ns(&ci->otg_fsm_hrtimer, + ci->hr_timeouts[t], NSEC_PER_MSEC, + HRTIMER_MODE_ABS); + } + spin_unlock_irqrestore(&ci->lock, flags); } /* @@ -241,174 +237,178 @@ static void ci_otg_add_timer(struct ci_hdrc *ci, enum otg_fsm_timer t) */ static void ci_otg_del_timer(struct ci_hdrc *ci, enum otg_fsm_timer t) { - struct ci_otg_fsm_timer *tmp_timer, *del_tmp; - struct ci_otg_fsm_timer *timer = ci->fsm_timer->timer_list[t]; - struct list_head *active_timers = &ci->fsm_timer->active_timers; - int flag = 0; + unsigned long flags, enabled_timer_bits; + enum otg_fsm_timer cur_timer, next_timer = NUM_OTG_FSM_TIMERS; - if (t >= NUM_OTG_FSM_TIMERS) + if ((t >= NUM_OTG_FSM_TIMERS) || + !(ci->enabled_otg_timer_bits & (1 << t))) return; - list_for_each_entry_safe(tmp_timer, del_tmp, active_timers, list) - if (tmp_timer == timer) { - list_del(&timer->list); - flag = 1; - } - - /* Disable 1ms irq if there is no any active timer */ - if (list_empty(active_timers) && (flag == 1)) { - hw_write_otgsc(ci, OTGSC_1MSIE, 0); - pm_runtime_put(ci->dev); - } -} - -/* - * Reduce timer count by 1, and find timeout conditions. - * Called by otg 1ms timer interrupt - */ -static inline int ci_otg_tick_timer(struct ci_hdrc *ci) -{ - struct ci_otg_fsm_timer *tmp_timer, *del_tmp; - struct list_head *active_timers = &ci->fsm_timer->active_timers; - int expired = 0; - - list_for_each_entry_safe(tmp_timer, del_tmp, active_timers, list) { - tmp_timer->count--; - /* check if timer expires */ - if (!tmp_timer->count) { - list_del(&tmp_timer->list); - tmp_timer->function(ci, tmp_timer->data); - expired = 1; + spin_lock_irqsave(&ci->lock, flags); + ci->enabled_otg_timer_bits &= ~(1 << t); + if (ci->next_otg_timer == t) { + if (ci->enabled_otg_timer_bits == 0) { + /* No enabled timers after delete it */ + hrtimer_cancel(&ci->otg_fsm_hrtimer); + ci->next_otg_timer = NUM_OTG_FSM_TIMERS; + } else { + /* Find the next timer */ + enabled_timer_bits = ci->enabled_otg_timer_bits; + for_each_set_bit(cur_timer, &enabled_timer_bits, + NUM_OTG_FSM_TIMERS) { + if ((next_timer == NUM_OTG_FSM_TIMERS) || + (ci->hr_timeouts[next_timer].tv64 < + ci->hr_timeouts[cur_timer].tv64)) + next_timer = cur_timer; + } } } - - /* disable 1ms irq if there is no any timer active */ - if ((expired == 1) && list_empty(active_timers)) { - hw_write_otgsc(ci, OTGSC_1MSIE, 0); - pm_runtime_put(ci->dev); + if (next_timer != NUM_OTG_FSM_TIMERS) { + ci->next_otg_timer = next_timer; + hrtimer_start_range_ns(&ci->otg_fsm_hrtimer, + ci->hr_timeouts[next_timer], NSEC_PER_MSEC, + HRTIMER_MODE_ABS); } - - return expired; + spin_unlock_irqrestore(&ci->lock, flags); } -/* The timeout callback function to set time out bit */ -static void set_tmout(void *ptr, unsigned long indicator) +/* OTG FSM timer handlers */ +static int a_wait_vrise_tmout(struct ci_hdrc *ci) { - *(int *)indicator = 1; + ci->fsm.a_wait_vrise_tmout = 1; + return 0; } -static void set_tmout_and_fsm(void *ptr, unsigned long indicator) +static int a_wait_vfall_tmout(struct ci_hdrc *ci) { - struct ci_hdrc *ci = (struct ci_hdrc *)ptr; - - set_tmout(ci, indicator); - - ci_otg_queue_work(ci); + ci->fsm.a_wait_vfall_tmout = 1; + return 0; } -static void a_wait_vfall_tmout_func(void *ptr, unsigned long indicator) +static int a_wait_bcon_tmout(struct ci_hdrc *ci) { - struct ci_hdrc *ci = (struct ci_hdrc *)ptr; + ci->fsm.a_wait_bcon_tmout = 1; + return 0; +} - set_tmout(ci, indicator); - /* Disable port power */ - hw_write(ci, OP_PORTSC, PORTSC_W1C_BITS | PORTSC_PP, 0); - /* Clear existing DP irq */ - hw_write_otgsc(ci, OTGSC_DPIS, OTGSC_DPIS); - /* Enable data pulse irq */ - hw_write_otgsc(ci, OTGSC_DPIE, OTGSC_DPIE); - ci_otg_queue_work(ci); +static int a_aidl_bdis_tmout(struct ci_hdrc *ci) +{ + ci->fsm.a_aidl_bdis_tmout = 1; + return 0; } -static void b_ssend_srp_tmout_func(void *ptr, unsigned long indicator) +static int b_ase0_brst_tmout(struct ci_hdrc *ci) { - struct ci_hdrc *ci = (struct ci_hdrc *)ptr; + ci->fsm.b_ase0_brst_tmout = 1; + return 0; +} - set_tmout(ci, indicator); +static int a_bidl_adis_tmout(struct ci_hdrc *ci) +{ + ci->fsm.a_bidl_adis_tmout = 1; + return 0; +} - /* only vbus fall below B_sess_vld in b_idle state */ - if (ci->fsm.otg->state == OTG_STATE_B_IDLE) - ci_otg_queue_work(ci); +static int b_se0_srp_tmout(struct ci_hdrc *ci) +{ + ci->fsm.b_se0_srp = 1; + return 0; } -static void b_data_pulse_end(void *ptr, unsigned long indicator) +static int b_srp_fail_tmout(struct ci_hdrc *ci) { - struct ci_hdrc *ci = (struct ci_hdrc *)ptr; + ci->fsm.b_srp_done = 1; + return 1; +} +static int b_data_pls_tmout(struct ci_hdrc *ci) +{ ci->fsm.b_srp_done = 1; ci->fsm.b_bus_req = 0; if (ci->fsm.power_up) ci->fsm.power_up = 0; - hw_write_otgsc(ci, OTGSC_HABA, 0); + pm_runtime_put(ci->dev); + return 0; +} - ci_otg_queue_work(ci); +static int b_ssend_srp_tmout(struct ci_hdrc *ci) +{ + ci->fsm.b_ssend_srp = 1; + /* only vbus fall below B_sess_vld in b_idle state */ + if (ci->fsm.otg->state == OTG_STATE_B_IDLE) + return 0; + else + return 1; +} + +/* + * Keep this list in the same order as timers indexed + * by enum otg_fsm_timer in include/linux/usb/otg-fsm.h + */ +static int (*otg_timer_handlers[])(struct ci_hdrc *) = { + a_wait_vrise_tmout, /* A_WAIT_VRISE */ + a_wait_vfall_tmout, /* A_WAIT_VFALL */ + a_wait_bcon_tmout, /* A_WAIT_BCON */ + a_aidl_bdis_tmout, /* A_AIDL_BDIS */ + b_ase0_brst_tmout, /* B_ASE0_BRST */ + a_bidl_adis_tmout, /* A_BIDL_ADIS */ + b_se0_srp_tmout, /* B_SE0_SRP */ + b_srp_fail_tmout, /* B_SRP_FAIL */ + NULL, /* A_WAIT_ENUM */ + b_data_pls_tmout, /* B_DATA_PLS */ + b_ssend_srp_tmout, /* B_SSEND_SRP */ +}; + +/* + * Enable the next nearest enabled timer if have + */ +static enum hrtimer_restart ci_otg_hrtimer_func(struct hrtimer *t) +{ + struct ci_hdrc *ci = container_of(t, struct ci_hdrc, otg_fsm_hrtimer); + ktime_t now, *timeout; + unsigned long enabled_timer_bits; + unsigned long flags; + enum otg_fsm_timer cur_timer, next_timer = NUM_OTG_FSM_TIMERS; + int ret = -EINVAL; + + spin_lock_irqsave(&ci->lock, flags); + enabled_timer_bits = ci->enabled_otg_timer_bits; + ci->next_otg_timer = NUM_OTG_FSM_TIMERS; + + now = ktime_get(); + for_each_set_bit(cur_timer, &enabled_timer_bits, NUM_OTG_FSM_TIMERS) { + if (now.tv64 >= ci->hr_timeouts[cur_timer].tv64) { + ci->enabled_otg_timer_bits &= ~(1 << cur_timer); + if (otg_timer_handlers[cur_timer]) + ret = otg_timer_handlers[cur_timer](ci); + } else { + if ((next_timer == NUM_OTG_FSM_TIMERS) || + (ci->hr_timeouts[cur_timer].tv64 < + ci->hr_timeouts[next_timer].tv64)) + next_timer = cur_timer; + } + } + /* Enable the next nearest timer */ + if (next_timer < NUM_OTG_FSM_TIMERS) { + timeout = &ci->hr_timeouts[next_timer]; + hrtimer_start_range_ns(&ci->otg_fsm_hrtimer, *timeout, + NSEC_PER_MSEC, HRTIMER_MODE_ABS); + ci->next_otg_timer = next_timer; + } + spin_unlock_irqrestore(&ci->lock, flags); + + if (!ret) + ci_otg_queue_work(ci); + + return HRTIMER_NORESTART; } /* Initialize timers */ static int ci_otg_init_timers(struct ci_hdrc *ci) { - struct otg_fsm *fsm = &ci->fsm; - - /* FSM used timers */ - ci->fsm_timer->timer_list[A_WAIT_VRISE] = - otg_timer_initializer(ci, &set_tmout_and_fsm, TA_WAIT_VRISE, - (unsigned long)&fsm->a_wait_vrise_tmout); - if (ci->fsm_timer->timer_list[A_WAIT_VRISE] == NULL) - return -ENOMEM; - - ci->fsm_timer->timer_list[A_WAIT_VFALL] = - otg_timer_initializer(ci, &a_wait_vfall_tmout_func, - TA_WAIT_VFALL, (unsigned long)&fsm->a_wait_vfall_tmout); - if (ci->fsm_timer->timer_list[A_WAIT_VFALL] == NULL) - return -ENOMEM; - - ci->fsm_timer->timer_list[A_WAIT_BCON] = - otg_timer_initializer(ci, &set_tmout_and_fsm, TA_WAIT_BCON, - (unsigned long)&fsm->a_wait_bcon_tmout); - if (ci->fsm_timer->timer_list[A_WAIT_BCON] == NULL) - return -ENOMEM; - - ci->fsm_timer->timer_list[A_AIDL_BDIS] = - otg_timer_initializer(ci, &set_tmout_and_fsm, TA_AIDL_BDIS, - (unsigned long)&fsm->a_aidl_bdis_tmout); - if (ci->fsm_timer->timer_list[A_AIDL_BDIS] == NULL) - return -ENOMEM; - - ci->fsm_timer->timer_list[A_BIDL_ADIS] = - otg_timer_initializer(ci, &set_tmout_and_fsm, TA_BIDL_ADIS, - (unsigned long)&fsm->a_bidl_adis_tmout); - if (ci->fsm_timer->timer_list[A_BIDL_ADIS] == NULL) - return -ENOMEM; - - ci->fsm_timer->timer_list[B_ASE0_BRST] = - otg_timer_initializer(ci, &set_tmout_and_fsm, TB_ASE0_BRST, - (unsigned long)&fsm->b_ase0_brst_tmout); - if (ci->fsm_timer->timer_list[B_ASE0_BRST] == NULL) - return -ENOMEM; - - ci->fsm_timer->timer_list[B_SE0_SRP] = - otg_timer_initializer(ci, &set_tmout_and_fsm, TB_SE0_SRP, - (unsigned long)&fsm->b_se0_srp); - if (ci->fsm_timer->timer_list[B_SE0_SRP] == NULL) - return -ENOMEM; - - ci->fsm_timer->timer_list[B_SSEND_SRP] = - otg_timer_initializer(ci, &b_ssend_srp_tmout_func, TB_SSEND_SRP, - (unsigned long)&fsm->b_ssend_srp); - if (ci->fsm_timer->timer_list[B_SSEND_SRP] == NULL) - return -ENOMEM; - - ci->fsm_timer->timer_list[B_SRP_FAIL] = - otg_timer_initializer(ci, &set_tmout, TB_SRP_FAIL, - (unsigned long)&fsm->b_srp_done); - if (ci->fsm_timer->timer_list[B_SRP_FAIL] == NULL) - return -ENOMEM; - - ci->fsm_timer->timer_list[B_DATA_PLS] = - otg_timer_initializer(ci, &b_data_pulse_end, TB_DATA_PLS, 0); - if (ci->fsm_timer->timer_list[B_DATA_PLS] == NULL) - return -ENOMEM; + hrtimer_init(&ci->otg_fsm_hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); + ci->otg_fsm_hrtimer.function = ci_otg_hrtimer_func; return 0; } @@ -512,6 +512,7 @@ static void ci_otg_start_pulse(struct otg_fsm *fsm) /* Hardware Assistant Data pulse */ hw_write_otgsc(ci, OTGSC_HADP, OTGSC_HADP); + pm_runtime_get(ci->dev); ci_otg_add_timer(ci, B_DATA_PLS); } @@ -579,8 +580,15 @@ int ci_otg_fsm_work(struct ci_hdrc *ci) * a_idle to a_wait_vrise when power up */ if ((ci->fsm.id) || (ci->id_event) || - (ci->fsm.power_up)) + (ci->fsm.power_up)) { ci_otg_queue_work(ci); + } else { + /* Enable data pulse irq */ + hw_write(ci, OP_PORTSC, PORTSC_W1C_BITS | + PORTSC_PP, 0); + hw_write_otgsc(ci, OTGSC_DPIS, OTGSC_DPIS); + hw_write_otgsc(ci, OTGSC_DPIE, OTGSC_DPIE); + } if (ci->id_event) ci->id_event = false; } else if (ci->fsm.otg->state == OTG_STATE_B_IDLE) { @@ -712,11 +720,7 @@ irqreturn_t ci_otg_fsm_irq(struct ci_hdrc *ci) fsm->id = (otgsc & OTGSC_ID) ? 1 : 0; if (otg_int_src) { - if (otg_int_src & OTGSC_1MSIS) { - hw_write_otgsc(ci, OTGSC_1MSIS, OTGSC_1MSIS); - retval = ci_otg_tick_timer(ci); - return IRQ_HANDLED; - } else if (otg_int_src & OTGSC_DPIS) { + if (otg_int_src & OTGSC_DPIS) { hw_write_otgsc(ci, OTGSC_DPIS, OTGSC_DPIS); fsm->a_srp_det = 1; fsm->a_bus_drop = 0; @@ -780,17 +784,13 @@ int ci_hdrc_otg_fsm_init(struct ci_hdrc *ci) mutex_init(&ci->fsm.lock); - ci->fsm_timer = devm_kzalloc(ci->dev, - sizeof(struct ci_otg_fsm_timer_list), GFP_KERNEL); - if (!ci->fsm_timer) - return -ENOMEM; - - INIT_LIST_HEAD(&ci->fsm_timer->active_timers); retval = ci_otg_init_timers(ci); if (retval) { dev_err(ci->dev, "Couldn't init OTG timers\n"); return retval; } + ci->enabled_otg_timer_bits = 0; + ci->next_otg_timer = NUM_OTG_FSM_TIMERS; retval = sysfs_create_group(&ci->dev->kobj, &inputs_attr_group); if (retval < 0) { diff --git a/drivers/usb/chipidea/otg_fsm.h b/drivers/usb/chipidea/otg_fsm.h index 9e0fc4c..2689375 100644 --- a/drivers/usb/chipidea/otg_fsm.h +++ b/drivers/usb/chipidea/otg_fsm.h @@ -62,19 +62,6 @@ /* SSEND time before SRP */ #define TB_SSEND_SRP (1500) /* minimum 1.5 sec, section:5.1.2 */ -struct ci_otg_fsm_timer { - unsigned long expires; /* Number of count increase to timeout */ - unsigned long count; /* Tick counter */ - void (*function)(void *, unsigned long); /* Timeout function */ - unsigned long data; /* Data passed to function */ - struct list_head list; -}; - -struct ci_otg_fsm_timer_list { - struct ci_otg_fsm_timer *timer_list[NUM_OTG_FSM_TIMERS]; - struct list_head active_timers; -}; - #ifdef CONFIG_USB_OTG_FSM int ci_hdrc_otg_fsm_init(struct ci_hdrc *ci); -- cgit v0.10.2 From d728189d10a0bea28ecb0e9acde1ea517112d090 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Fri, 20 Mar 2015 16:28:07 +0800 Subject: chipidea: introduce specific Kconfig options for glue drivers This patch introduces USB_CHIPIDEA_PCI and USB_CHIPIDEA_OF Kconfig options, one per each specific glue driver. This is needed to provide different dependencies they have. Signed-off-by: Andy Shevchenko Signed-off-by: Peter Chen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/chipidea/Kconfig b/drivers/usb/chipidea/Kconfig index 77b47d8..8b0edb9 100644 --- a/drivers/usb/chipidea/Kconfig +++ b/drivers/usb/chipidea/Kconfig @@ -10,6 +10,16 @@ config USB_CHIPIDEA if USB_CHIPIDEA +config USB_CHIPIDEA_OF + tristate + depends on OF + default USB_CHIPIDEA + +config USB_CHIPIDEA_PCI + tristate + depends on PCI + default USB_CHIPIDEA + config USB_CHIPIDEA_UDC bool "ChipIdea device controller" depends on USB_GADGET diff --git a/drivers/usb/chipidea/Makefile b/drivers/usb/chipidea/Makefile index 1fc86a2..4decb12 100644 --- a/drivers/usb/chipidea/Makefile +++ b/drivers/usb/chipidea/Makefile @@ -14,11 +14,6 @@ obj-$(CONFIG_USB_CHIPIDEA) += ci_hdrc_usb2.o obj-$(CONFIG_USB_CHIPIDEA) += ci_hdrc_msm.o obj-$(CONFIG_USB_CHIPIDEA) += ci_hdrc_zevio.o -# PCI doesn't provide stubs, need to check -ifneq ($(CONFIG_PCI),) - obj-$(CONFIG_USB_CHIPIDEA) += ci_hdrc_pci.o -endif +obj-$(CONFIG_USB_CHIPIDEA_PCI) += ci_hdrc_pci.o -ifneq ($(CONFIG_OF),) - obj-$(CONFIG_USB_CHIPIDEA) += usbmisc_imx.o ci_hdrc_imx.o -endif +obj-$(CONFIG_USB_CHIPIDEA_OF) += usbmisc_imx.o ci_hdrc_imx.o -- cgit v0.10.2 From db7869cabd4862d984cca91dee62c14d08ae5b03 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Fri, 20 Mar 2015 16:28:08 +0800 Subject: chipidea: pci: make it depends on NOP_USB_XCEIV After commit ba1aff67f99a (chipidea: pci: register nop PHY) the PCI glue driver requires nop-PHY to be selected. Thus, make it an explicit dependency. Reported-by: kbuild test robot Fixes: ba1aff67f99a (chipidea: pci: register nop PHY) Signed-off-by: Andy Shevchenko Signed-off-by: Peter Chen Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/chipidea/Kconfig b/drivers/usb/chipidea/Kconfig index 8b0edb9..5ce3f1d 100644 --- a/drivers/usb/chipidea/Kconfig +++ b/drivers/usb/chipidea/Kconfig @@ -18,6 +18,7 @@ config USB_CHIPIDEA_OF config USB_CHIPIDEA_PCI tristate depends on PCI + depends on NOP_USB_XCEIV default USB_CHIPIDEA config USB_CHIPIDEA_UDC -- cgit v0.10.2 From f4ea80a6026a09aa0b59ec7443b901660f390550 Mon Sep 17 00:00:00 2001 From: kbuild test robot Date: Wed, 25 Mar 2015 07:54:12 +0800 Subject: usb: host/sl811-hcd: fix platform_no_drv_owner.cocci warnings drivers/usb/host/sl811-hcd.c:1812:3-8: No need to set .owner here. The core will do it. Remove .owner field if calls are used which set it automatically Generated by: scripts/coccinelle/api/platform_no_drv_owner.cocci Signed-off-by: Fengguang Wu Acked-by: Lad, Prabhakar Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c index aceddfd..944a417 100644 --- a/drivers/usb/host/sl811-hcd.c +++ b/drivers/usb/host/sl811-hcd.c @@ -1809,7 +1809,6 @@ static struct platform_driver sl811h_driver = { .resume = sl811h_resume, .driver = { .name = (char *) hcd_name, - .owner = THIS_MODULE, }, }; EXPORT_SYMBOL(sl811h_driver); -- cgit v0.10.2 From b830d07dc3f6891cd4788f651fa240d32fdbc068 Mon Sep 17 00:00:00 2001 From: Peter Hung Date: Tue, 17 Mar 2015 17:48:19 +0800 Subject: USB: f81232: rename private struct member name Change private struct member name from line_status to modem_status. It will store MSR for some functions used Signed-off-by: Peter Hung Signed-off-by: Johan Hovold diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c index c5dc233..669a2f2 100644 --- a/drivers/usb/serial/f81232.c +++ b/drivers/usb/serial/f81232.c @@ -47,7 +47,7 @@ MODULE_DEVICE_TABLE(usb, id_table); struct f81232_private { spinlock_t lock; u8 line_control; - u8 line_status; + u8 modem_status; }; static void f81232_update_line_status(struct usb_serial_port *port, @@ -113,8 +113,8 @@ static void f81232_process_read_urb(struct urb *urb) /* update line status */ spin_lock_irqsave(&priv->lock, flags); - line_status = priv->line_status; - priv->line_status &= ~UART_STATE_TRANSIENT_MASK; + line_status = priv->modem_status; + priv->modem_status &= ~UART_STATE_TRANSIENT_MASK; spin_unlock_irqrestore(&priv->lock, flags); if (!urb->actual_length) @@ -241,7 +241,7 @@ static void f81232_dtr_rts(struct usb_serial_port *port, int on) static int f81232_carrier_raised(struct usb_serial_port *port) { struct f81232_private *priv = usb_get_serial_port_data(port); - if (priv->line_status & UART_DCD) + if (priv->modem_status & UART_DCD) return 1; return 0; } -- cgit v0.10.2 From 8885078949fbb78c6be39ed2c653e4e883568e2f Mon Sep 17 00:00:00 2001 From: Peter Hung Date: Tue, 17 Mar 2015 17:48:20 +0800 Subject: USB: f81232: implement RX bulk-in EP The F81232 bulk-in is RX data + LSR channel, data format is [LSR+Data][LSR+Data]..... , We had implemented in f81232_process_read_urb(). Signed-off-by: Peter Hung [johan: reword comment in process_read_urb ] Signed-off-by: Johan Hovold diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c index 669a2f2..4664cf4 100644 --- a/drivers/usb/serial/f81232.c +++ b/drivers/usb/serial/f81232.c @@ -23,6 +23,7 @@ #include #include #include +#include static const struct usb_device_id id_table[] = { { USB_DEVICE(0x1934, 0x0706) }, @@ -104,44 +105,50 @@ exit: static void f81232_process_read_urb(struct urb *urb) { struct usb_serial_port *port = urb->context; - struct f81232_private *priv = usb_get_serial_port_data(port); unsigned char *data = urb->transfer_buffer; - char tty_flag = TTY_NORMAL; - unsigned long flags; - u8 line_status; - int i; + char tty_flag; + unsigned int i; + u8 lsr; - /* update line status */ - spin_lock_irqsave(&priv->lock, flags); - line_status = priv->modem_status; - priv->modem_status &= ~UART_STATE_TRANSIENT_MASK; - spin_unlock_irqrestore(&priv->lock, flags); - - if (!urb->actual_length) + /* + * When opening the port we get a 1-byte packet with the current LSR, + * which we discard. + */ + if ((urb->actual_length < 2) || (urb->actual_length % 2)) return; - /* break takes precedence over parity, */ - /* which takes precedence over framing errors */ - if (line_status & UART_BREAK_ERROR) - tty_flag = TTY_BREAK; - else if (line_status & UART_PARITY_ERROR) - tty_flag = TTY_PARITY; - else if (line_status & UART_FRAME_ERROR) - tty_flag = TTY_FRAME; - dev_dbg(&port->dev, "%s - tty_flag = %d\n", __func__, tty_flag); - - /* overrun is special, not associated with a char */ - if (line_status & UART_OVERRUN_ERROR) - tty_insert_flip_char(&port->port, 0, TTY_OVERRUN); - - if (port->port.console && port->sysrq) { - for (i = 0; i < urb->actual_length; ++i) - if (!usb_serial_handle_sysrq_char(port, data[i])) - tty_insert_flip_char(&port->port, data[i], - tty_flag); - } else { - tty_insert_flip_string_fixed_flag(&port->port, data, tty_flag, - urb->actual_length); + /* bulk-in data: [LSR(1Byte)+DATA(1Byte)][LSR(1Byte)+DATA(1Byte)]... */ + + for (i = 0; i < urb->actual_length; i += 2) { + tty_flag = TTY_NORMAL; + lsr = data[i]; + + if (lsr & UART_LSR_BRK_ERROR_BITS) { + if (lsr & UART_LSR_BI) { + tty_flag = TTY_BREAK; + port->icount.brk++; + usb_serial_handle_break(port); + } else if (lsr & UART_LSR_PE) { + tty_flag = TTY_PARITY; + port->icount.parity++; + } else if (lsr & UART_LSR_FE) { + tty_flag = TTY_FRAME; + port->icount.frame++; + } + + if (lsr & UART_LSR_OE) { + port->icount.overrun++; + tty_insert_flip_char(&port->port, 0, + TTY_OVERRUN); + } + } + + if (port->port.console && port->sysrq) { + if (usb_serial_handle_sysrq_char(port, data[i + 1])) + continue; + } + + tty_insert_flip_char(&port->port, data[i + 1], tty_flag); } tty_flip_buffer_push(&port->port); -- cgit v0.10.2 From 7139c932859f5b35b5a928b445e03f5a43610fa7 Mon Sep 17 00:00:00 2001 From: Peter Hung Date: Tue, 17 Mar 2015 17:48:21 +0800 Subject: USB: f81232: change lock mechanism The original driver lock with spin_lock_irqsave()/spin_unlock_irqrestore() because of it's maybe used in interrupt context f81232_process_read_urb(). We had remove it from previous patch "implement RX bulk-in EP", so we can change it from busying loop spin_lock to sleepable mutex_lock. Signed-off-by: Peter Hung Signed-off-by: Johan Hovold diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c index 4664cf4..12840cd 100644 --- a/drivers/usb/serial/f81232.c +++ b/drivers/usb/serial/f81232.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include @@ -46,7 +46,7 @@ MODULE_DEVICE_TABLE(usb, id_table); #define UART_CTS 0x80 struct f81232_private { - spinlock_t lock; + struct mutex lock; u8 line_control; u8 modem_status; }; @@ -231,17 +231,16 @@ static void f81232_close(struct usb_serial_port *port) static void f81232_dtr_rts(struct usb_serial_port *port, int on) { struct f81232_private *priv = usb_get_serial_port_data(port); - unsigned long flags; u8 control; - spin_lock_irqsave(&priv->lock, flags); + mutex_lock(&priv->lock); /* Change DTR and RTS */ if (on) priv->line_control |= (CONTROL_DTR | CONTROL_RTS); else priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS); control = priv->line_control; - spin_unlock_irqrestore(&priv->lock, flags); + mutex_unlock(&priv->lock); set_control_lines(port->serial->dev, control); } @@ -285,7 +284,7 @@ static int f81232_port_probe(struct usb_serial_port *port) if (!priv) return -ENOMEM; - spin_lock_init(&priv->lock); + mutex_init(&priv->lock); usb_set_serial_port_data(port, priv); -- cgit v0.10.2 From 87fe5adcd8de001160d9208def72cc11f3780845 Mon Sep 17 00:00:00 2001 From: Peter Hung Date: Tue, 17 Mar 2015 17:48:22 +0800 Subject: USB: f81232: implement read IIR/MSR with endpoint The interrupt endpoint will report current IIR. If we got IIR with MSR changed , We will do read MSR with interrupt_work worker to do f81232_read_msr() function. Signed-off-by: Peter Hung Signed-off-by: Johan Hovold diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c index 12840cd..e53ceea 100644 --- a/drivers/usb/serial/f81232.c +++ b/drivers/usb/serial/f81232.c @@ -31,6 +31,13 @@ static const struct usb_device_id id_table[] = { }; MODULE_DEVICE_TABLE(usb, id_table); +/* USB Control EP parameter */ +#define F81232_REGISTER_REQUEST 0xa0 +#define F81232_GET_REGISTER 0xc0 + +#define SERIAL_BASE_ADDRESS 0x0120 +#define MODEM_STATUS_REGISTER (0x06 + SERIAL_BASE_ADDRESS) + #define CONTROL_DTR 0x01 #define CONTROL_RTS 0x02 @@ -49,19 +56,112 @@ struct f81232_private { struct mutex lock; u8 line_control; u8 modem_status; + struct work_struct interrupt_work; + struct usb_serial_port *port; }; +static int f81232_get_register(struct usb_serial_port *port, u16 reg, u8 *val) +{ + int status; + u8 *tmp; + struct usb_device *dev = port->serial->dev; + + tmp = kmalloc(sizeof(*val), GFP_KERNEL); + if (!tmp) + return -ENOMEM; + + status = usb_control_msg(dev, + usb_rcvctrlpipe(dev, 0), + F81232_REGISTER_REQUEST, + F81232_GET_REGISTER, + reg, + 0, + tmp, + sizeof(*val), + USB_CTRL_GET_TIMEOUT); + if (status != sizeof(*val)) { + dev_err(&port->dev, "%s failed status: %d\n", __func__, status); + + if (status < 0) + status = usb_translate_errors(status); + else + status = -EIO; + } else { + status = 0; + *val = *tmp; + } + + kfree(tmp); + return status; +} + +static void f81232_read_msr(struct usb_serial_port *port) +{ + int status; + u8 current_msr; + struct tty_struct *tty; + struct f81232_private *priv = usb_get_serial_port_data(port); + + mutex_lock(&priv->lock); + status = f81232_get_register(port, MODEM_STATUS_REGISTER, + ¤t_msr); + if (status) { + dev_err(&port->dev, "%s fail, status: %d\n", __func__, status); + mutex_unlock(&priv->lock); + return; + } + + if (!(current_msr & UART_MSR_ANY_DELTA)) { + mutex_unlock(&priv->lock); + return; + } + + priv->modem_status = current_msr; + + if (current_msr & UART_MSR_DCTS) + port->icount.cts++; + if (current_msr & UART_MSR_DDSR) + port->icount.dsr++; + if (current_msr & UART_MSR_TERI) + port->icount.rng++; + if (current_msr & UART_MSR_DDCD) { + port->icount.dcd++; + tty = tty_port_tty_get(&port->port); + if (tty) { + usb_serial_handle_dcd_change(port, tty, + current_msr & UART_MSR_DCD); + + tty_kref_put(tty); + } + } + + wake_up_interruptible(&port->port.delta_msr_wait); + mutex_unlock(&priv->lock); +} + static void f81232_update_line_status(struct usb_serial_port *port, unsigned char *data, - unsigned int actual_length) + size_t actual_length) { - /* - * FIXME: Update port->icount, and call - * - * wake_up_interruptible(&port->port.delta_msr_wait); - * - * on MSR changes. - */ + struct f81232_private *priv = usb_get_serial_port_data(port); + + if (!actual_length) + return; + + switch (data[0] & 0x07) { + case 0x00: /* msr change */ + dev_dbg(&port->dev, "IIR: MSR Change: %02x\n", data[0]); + schedule_work(&priv->interrupt_work); + break; + case 0x02: /* tx-empty */ + break; + case 0x04: /* rx data available */ + break; + case 0x06: /* lsr change */ + /* we can forget it. the LSR will read from bulk-in */ + dev_dbg(&port->dev, "IIR: LSR Change: %02x\n", data[0]); + break; + } } static void f81232_read_int_callback(struct urb *urb) @@ -276,6 +376,14 @@ static int f81232_ioctl(struct tty_struct *tty, return -ENOIOCTLCMD; } +static void f81232_interrupt_work(struct work_struct *work) +{ + struct f81232_private *priv = + container_of(work, struct f81232_private, interrupt_work); + + f81232_read_msr(priv->port); +} + static int f81232_port_probe(struct usb_serial_port *port) { struct f81232_private *priv; @@ -285,10 +393,12 @@ static int f81232_port_probe(struct usb_serial_port *port) return -ENOMEM; mutex_init(&priv->lock); + INIT_WORK(&priv->interrupt_work, f81232_interrupt_work); usb_set_serial_port_data(port, priv); port->port.drain_delay = 256; + priv->port = port; return 0; } -- cgit v0.10.2 From 691545fd92551baea6207781b33c95aa6444bf0d Mon Sep 17 00:00:00 2001 From: Peter Hung Date: Tue, 17 Mar 2015 17:48:23 +0800 Subject: USB: f81232: implement MCR/MSR function This patch implement relative MCR/MSR function, such like tiocmget()/tiocmset()/dtr_rts()/carrier_raised() original f81232_carrier_raised() compared with wrong value UART_DCD. It's should compared with UART_MSR_DCD. Signed-off-by: Peter Hung Signed-off-by: Johan Hovold diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c index e53ceea..307e147 100644 --- a/drivers/usb/serial/f81232.c +++ b/drivers/usb/serial/f81232.c @@ -34,8 +34,10 @@ MODULE_DEVICE_TABLE(usb, id_table); /* USB Control EP parameter */ #define F81232_REGISTER_REQUEST 0xa0 #define F81232_GET_REGISTER 0xc0 +#define F81232_SET_REGISTER 0x40 #define SERIAL_BASE_ADDRESS 0x0120 +#define MODEM_CONTROL_REGISTER (0x04 + SERIAL_BASE_ADDRESS) #define MODEM_STATUS_REGISTER (0x06 + SERIAL_BASE_ADDRESS) #define CONTROL_DTR 0x01 @@ -54,7 +56,7 @@ MODULE_DEVICE_TABLE(usb, id_table); struct f81232_private { struct mutex lock; - u8 line_control; + u8 modem_control; u8 modem_status; struct work_struct interrupt_work; struct usb_serial_port *port; @@ -95,6 +97,42 @@ static int f81232_get_register(struct usb_serial_port *port, u16 reg, u8 *val) return status; } +static int f81232_set_register(struct usb_serial_port *port, u16 reg, u8 val) +{ + int status; + u8 *tmp; + struct usb_device *dev = port->serial->dev; + + tmp = kmalloc(sizeof(val), GFP_KERNEL); + if (!tmp) + return -ENOMEM; + + *tmp = val; + + status = usb_control_msg(dev, + usb_sndctrlpipe(dev, 0), + F81232_REGISTER_REQUEST, + F81232_SET_REGISTER, + reg, + 0, + tmp, + sizeof(val), + USB_CTRL_SET_TIMEOUT); + if (status != sizeof(val)) { + dev_err(&port->dev, "%s failed status: %d\n", __func__, status); + + if (status < 0) + status = usb_translate_errors(status); + else + status = -EIO; + } else { + status = 0; + } + + kfree(tmp); + return status; +} + static void f81232_read_msr(struct usb_serial_port *port) { int status; @@ -139,6 +177,51 @@ static void f81232_read_msr(struct usb_serial_port *port) mutex_unlock(&priv->lock); } +static int f81232_set_mctrl(struct usb_serial_port *port, + unsigned int set, unsigned int clear) +{ + u8 val; + int status; + struct f81232_private *priv = usb_get_serial_port_data(port); + + if (((set | clear) & (TIOCM_DTR | TIOCM_RTS)) == 0) + return 0; /* no change */ + + /* 'set' takes precedence over 'clear' */ + clear &= ~set; + + /* force enable interrupt with OUT2 */ + mutex_lock(&priv->lock); + val = UART_MCR_OUT2 | priv->modem_control; + + if (clear & TIOCM_DTR) + val &= ~UART_MCR_DTR; + + if (clear & TIOCM_RTS) + val &= ~UART_MCR_RTS; + + if (set & TIOCM_DTR) + val |= UART_MCR_DTR; + + if (set & TIOCM_RTS) + val |= UART_MCR_RTS; + + dev_dbg(&port->dev, "%s new:%02x old:%02x\n", __func__, + val, priv->modem_control); + + status = f81232_set_register(port, MODEM_CONTROL_REGISTER, val); + if (status) { + dev_err(&port->dev, "%s set MCR status < 0\n", __func__); + mutex_unlock(&priv->lock); + return status; + } + + priv->modem_control = val; + mutex_unlock(&priv->lock); + + return 0; +} + static void f81232_update_line_status(struct usb_serial_port *port, unsigned char *data, size_t actual_length) @@ -254,12 +337,6 @@ static void f81232_process_read_urb(struct urb *urb) tty_flip_buffer_push(&port->port); } -static int set_control_lines(struct usb_device *dev, u8 value) -{ - /* FIXME - Stubbed out for now */ - return 0; -} - static void f81232_break_ctl(struct tty_struct *tty, int break_state) { /* FIXME - Stubbed out for now */ @@ -287,15 +364,35 @@ static void f81232_set_termios(struct tty_struct *tty, static int f81232_tiocmget(struct tty_struct *tty) { - /* FIXME - Stubbed out for now */ - return 0; + int r; + struct usb_serial_port *port = tty->driver_data; + struct f81232_private *port_priv = usb_get_serial_port_data(port); + u8 mcr, msr; + + /* force get current MSR changed state */ + f81232_read_msr(port); + + mutex_lock(&port_priv->lock); + mcr = port_priv->modem_control; + msr = port_priv->modem_status; + mutex_unlock(&port_priv->lock); + + r = (mcr & UART_MCR_DTR ? TIOCM_DTR : 0) | + (mcr & UART_MCR_RTS ? TIOCM_RTS : 0) | + (msr & UART_MSR_CTS ? TIOCM_CTS : 0) | + (msr & UART_MSR_DCD ? TIOCM_CAR : 0) | + (msr & UART_MSR_RI ? TIOCM_RI : 0) | + (msr & UART_MSR_DSR ? TIOCM_DSR : 0); + + return r; } static int f81232_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear) { - /* FIXME - Stubbed out for now */ - return 0; + struct usb_serial_port *port = tty->driver_data; + + return f81232_set_mctrl(port, set, clear); } static int f81232_open(struct tty_struct *tty, struct usb_serial_port *port) @@ -330,24 +427,22 @@ static void f81232_close(struct usb_serial_port *port) static void f81232_dtr_rts(struct usb_serial_port *port, int on) { - struct f81232_private *priv = usb_get_serial_port_data(port); - u8 control; - - mutex_lock(&priv->lock); - /* Change DTR and RTS */ if (on) - priv->line_control |= (CONTROL_DTR | CONTROL_RTS); + f81232_set_mctrl(port, TIOCM_DTR | TIOCM_RTS, 0); else - priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS); - control = priv->line_control; - mutex_unlock(&priv->lock); - set_control_lines(port->serial->dev, control); + f81232_set_mctrl(port, 0, TIOCM_DTR | TIOCM_RTS); } static int f81232_carrier_raised(struct usb_serial_port *port) { + u8 msr; struct f81232_private *priv = usb_get_serial_port_data(port); - if (priv->modem_status & UART_DCD) + + mutex_lock(&priv->lock); + msr = priv->modem_status; + mutex_unlock(&priv->lock); + + if (msr & UART_MSR_DCD) return 1; return 0; } -- cgit v0.10.2 From 94f87309fb12e3d41dbc56df899f3b357277d0bf Mon Sep 17 00:00:00 2001 From: Peter Hung Date: Tue, 17 Mar 2015 17:48:24 +0800 Subject: USB: f81232: implement port enable/disable method We put FCR/IER initial step to f81232_port_enable()/f81232_port_disable(). When port is open, it set MSR interrupt on. Otherwise set it off. Signed-off-by: Peter Hung Signed-off-by: Johan Hovold diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c index 307e147..9602823 100644 --- a/drivers/usb/serial/f81232.c +++ b/drivers/usb/serial/f81232.c @@ -37,6 +37,8 @@ MODULE_DEVICE_TABLE(usb, id_table); #define F81232_SET_REGISTER 0x40 #define SERIAL_BASE_ADDRESS 0x0120 +#define INTERRUPT_ENABLE_REGISTER (0x01 + SERIAL_BASE_ADDRESS) +#define FIFO_CONTROL_REGISTER (0x02 + SERIAL_BASE_ADDRESS) #define MODEM_CONTROL_REGISTER (0x04 + SERIAL_BASE_ADDRESS) #define MODEM_STATUS_REGISTER (0x06 + SERIAL_BASE_ADDRESS) @@ -348,6 +350,48 @@ static void f81232_break_ctl(struct tty_struct *tty, int break_state) */ } +static int f81232_port_enable(struct usb_serial_port *port) +{ + u8 val; + int status; + + /* fifo on, trigger8, clear TX/RX*/ + val = UART_FCR_TRIGGER_8 | UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR | + UART_FCR_CLEAR_XMIT; + + status = f81232_set_register(port, FIFO_CONTROL_REGISTER, val); + if (status) { + dev_err(&port->dev, "%s failed to set FCR: %d\n", + __func__, status); + return status; + } + + /* MSR Interrupt only, LSR will read from Bulk-in odd byte */ + status = f81232_set_register(port, INTERRUPT_ENABLE_REGISTER, + UART_IER_MSI); + if (status) { + dev_err(&port->dev, "%s failed to set IER: %d\n", + __func__, status); + return status; + } + + return 0; +} + +static int f81232_port_disable(struct usb_serial_port *port) +{ + int status; + + status = f81232_set_register(port, INTERRUPT_ENABLE_REGISTER, 0); + if (status) { + dev_err(&port->dev, "%s failed to set IER: %d\n", + __func__, status); + return status; + } + + return 0; +} + static void f81232_set_termios(struct tty_struct *tty, struct usb_serial_port *port, struct ktermios *old_termios) { @@ -399,6 +443,10 @@ static int f81232_open(struct tty_struct *tty, struct usb_serial_port *port) { int result; + result = f81232_port_enable(port); + if (result) + return result; + /* Setup termios */ if (tty) f81232_set_termios(tty, port, NULL); @@ -421,6 +469,7 @@ static int f81232_open(struct tty_struct *tty, struct usb_serial_port *port) static void f81232_close(struct usb_serial_port *port) { + f81232_port_disable(port); usb_serial_generic_close(port); usb_kill_urb(port->interrupt_in_urb); } -- cgit v0.10.2 From 8bb4ca6b56bdf65944d0848561ea8dcf53a87507 Mon Sep 17 00:00:00 2001 From: Peter Hung Date: Tue, 17 Mar 2015 17:48:25 +0800 Subject: USB: f81232: implement set_termios() The original driver had do not any h/w change in driver. This patch implements with configure H/W for baud/parity/word length/stop bits functional in f81232_set_termios(). This patch also implement DTR/RTS control when baudrate B0. We drop DTR/RTS when B0, otherwise enable it. We are checking baudrate in set_termios() too, If baudrate larger then 115200, it will be changed to 115200 and use tty_encode_baud_rate() to encode into tty Signed-off-by: Peter Hung Signed-off-by: Johan Hovold diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c index 9602823..c00ced1 100644 --- a/drivers/usb/serial/f81232.c +++ b/drivers/usb/serial/f81232.c @@ -31,14 +31,19 @@ static const struct usb_device_id id_table[] = { }; MODULE_DEVICE_TABLE(usb, id_table); +/* Maximum baudrate for F81232 */ +#define F81232_MAX_BAUDRATE 115200 + /* USB Control EP parameter */ #define F81232_REGISTER_REQUEST 0xa0 #define F81232_GET_REGISTER 0xc0 #define F81232_SET_REGISTER 0x40 #define SERIAL_BASE_ADDRESS 0x0120 +#define RECEIVE_BUFFER_REGISTER (0x00 + SERIAL_BASE_ADDRESS) #define INTERRUPT_ENABLE_REGISTER (0x01 + SERIAL_BASE_ADDRESS) #define FIFO_CONTROL_REGISTER (0x02 + SERIAL_BASE_ADDRESS) +#define LINE_CONTROL_REGISTER (0x03 + SERIAL_BASE_ADDRESS) #define MODEM_CONTROL_REGISTER (0x04 + SERIAL_BASE_ADDRESS) #define MODEM_STATUS_REGISTER (0x06 + SERIAL_BASE_ADDRESS) @@ -64,6 +69,11 @@ struct f81232_private { struct usb_serial_port *port; }; +static int calc_baud_divisor(speed_t baudrate) +{ + return DIV_ROUND_CLOSEST(F81232_MAX_BAUDRATE, baudrate); +} + static int f81232_get_register(struct usb_serial_port *port, u16 reg, u8 *val) { int status; @@ -350,6 +360,53 @@ static void f81232_break_ctl(struct tty_struct *tty, int break_state) */ } +static void f81232_set_baudrate(struct usb_serial_port *port, speed_t baudrate) +{ + u8 lcr; + int divisor, status = 0; + + divisor = calc_baud_divisor(baudrate); + + status = f81232_get_register(port, LINE_CONTROL_REGISTER, + &lcr); /* get LCR */ + if (status) { + dev_err(&port->dev, "%s failed to get LCR: %d\n", + __func__, status); + return; + } + + status = f81232_set_register(port, LINE_CONTROL_REGISTER, + lcr | UART_LCR_DLAB); /* Enable DLAB */ + if (status) { + dev_err(&port->dev, "%s failed to set DLAB: %d\n", + __func__, status); + return; + } + + status = f81232_set_register(port, RECEIVE_BUFFER_REGISTER, + divisor & 0x00ff); /* low */ + if (status) { + dev_err(&port->dev, "%s failed to set baudrate MSB: %d\n", + __func__, status); + goto reapply_lcr; + } + + status = f81232_set_register(port, INTERRUPT_ENABLE_REGISTER, + (divisor & 0xff00) >> 8); /* high */ + if (status) { + dev_err(&port->dev, "%s failed to set baudrate LSB: %d\n", + __func__, status); + } + +reapply_lcr: + status = f81232_set_register(port, LINE_CONTROL_REGISTER, + lcr & ~UART_LCR_DLAB); + if (status) { + dev_err(&port->dev, "%s failed to set DLAB: %d\n", + __func__, status); + } +} + static int f81232_port_enable(struct usb_serial_port *port) { u8 val; @@ -395,15 +452,62 @@ static int f81232_port_disable(struct usb_serial_port *port) static void f81232_set_termios(struct tty_struct *tty, struct usb_serial_port *port, struct ktermios *old_termios) { - /* FIXME - Stubbed out for now */ + u8 new_lcr = 0; + int status = 0; + speed_t baudrate; /* Don't change anything if nothing has changed */ if (old_termios && !tty_termios_hw_change(&tty->termios, old_termios)) return; - /* Do the real work here... */ - if (old_termios) - tty_termios_copy_hw(&tty->termios, old_termios); + if (C_BAUD(tty) == B0) + f81232_set_mctrl(port, 0, TIOCM_DTR | TIOCM_RTS); + else if (old_termios && (old_termios->c_cflag & CBAUD) == B0) + f81232_set_mctrl(port, TIOCM_DTR | TIOCM_RTS, 0); + + baudrate = tty_get_baud_rate(tty); + if (baudrate > 0) { + if (baudrate > F81232_MAX_BAUDRATE) { + baudrate = F81232_MAX_BAUDRATE; + tty_encode_baud_rate(tty, baudrate, baudrate); + } + f81232_set_baudrate(port, baudrate); + } + + if (C_PARENB(tty)) { + new_lcr |= UART_LCR_PARITY; + + if (!C_PARODD(tty)) + new_lcr |= UART_LCR_EPAR; + + if (C_CMSPAR(tty)) + new_lcr |= UART_LCR_SPAR; + } + + if (C_CSTOPB(tty)) + new_lcr |= UART_LCR_STOP; + + switch (C_CSIZE(tty)) { + case CS5: + new_lcr |= UART_LCR_WLEN5; + break; + case CS6: + new_lcr |= UART_LCR_WLEN6; + break; + case CS7: + new_lcr |= UART_LCR_WLEN7; + break; + default: + case CS8: + new_lcr |= UART_LCR_WLEN8; + break; + } + + status = f81232_set_register(port, LINE_CONTROL_REGISTER, new_lcr); + if (status) { + dev_err(&port->dev, "%s failed to set LCR: %d\n", + __func__, status); + } } static int f81232_tiocmget(struct tty_struct *tty) -- cgit v0.10.2 From 88d35cffff83cc0b11d6e7a2bef73b602f156da0 Mon Sep 17 00:00:00 2001 From: Peter Hung Date: Tue, 17 Mar 2015 17:48:26 +0800 Subject: USB: f81232: clarify f81232_ioctl() and fix We extract TIOCGSERIAL section in f81232_ioctl() to f81232_get_serial_info() to make it clarify. Also we fix device type from 16654 to 16550A, and set it's baud_base to 115200 (1.8432MHz/16). Signed-off-by: Peter Hung Signed-off-by: Johan Hovold diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c index c00ced1..fd4b7cc 100644 --- a/drivers/usb/serial/f81232.c +++ b/drivers/usb/serial/f81232.c @@ -600,24 +600,32 @@ static int f81232_carrier_raised(struct usb_serial_port *port) return 0; } +static int f81232_get_serial_info(struct usb_serial_port *port, + unsigned long arg) +{ + struct serial_struct ser; + + memset(&ser, 0, sizeof(ser)); + + ser.type = PORT_16550A; + ser.line = port->minor; + ser.port = port->port_number; + ser.baud_base = F81232_MAX_BAUDRATE; + + if (copy_to_user((void __user *)arg, &ser, sizeof(ser))) + return -EFAULT; + + return 0; +} + static int f81232_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg) { - struct serial_struct ser; struct usb_serial_port *port = tty->driver_data; switch (cmd) { case TIOCGSERIAL: - memset(&ser, 0, sizeof ser); - ser.type = PORT_16654; - ser.line = port->minor; - ser.port = port->port_number; - ser.baud_base = 460800; - - if (copy_to_user((void __user *)arg, &ser, sizeof ser)) - return -EFAULT; - - return 0; + return f81232_get_serial_info(port, arg); default: break; } -- cgit v0.10.2 From 9e7d953bbf746cf704238965a716e0afcfe0f5f4 Mon Sep 17 00:00:00 2001 From: Peter Hung Date: Tue, 17 Mar 2015 17:48:27 +0800 Subject: USB: f81232: cleanup non-used define We remove non-used define in this patch to avoid wrong usage. Signed-off-by: Peter Hung Signed-off-by: Johan Hovold diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c index fd4b7cc..ecb5798 100644 --- a/drivers/usb/serial/f81232.c +++ b/drivers/usb/serial/f81232.c @@ -47,20 +47,6 @@ MODULE_DEVICE_TABLE(usb, id_table); #define MODEM_CONTROL_REGISTER (0x04 + SERIAL_BASE_ADDRESS) #define MODEM_STATUS_REGISTER (0x06 + SERIAL_BASE_ADDRESS) -#define CONTROL_DTR 0x01 -#define CONTROL_RTS 0x02 - -#define UART_STATE 0x08 -#define UART_STATE_TRANSIENT_MASK 0x74 -#define UART_DCD 0x01 -#define UART_DSR 0x02 -#define UART_BREAK_ERROR 0x04 -#define UART_RING 0x08 -#define UART_FRAME_ERROR 0x10 -#define UART_PARITY_ERROR 0x20 -#define UART_OVERRUN_ERROR 0x40 -#define UART_CTS 0x80 - struct f81232_private { struct mutex lock; u8 modem_control; -- cgit v0.10.2 From 96ee85c06515407453e2ac09d6fbdece0c791087 Mon Sep 17 00:00:00 2001 From: Peter Hung Date: Tue, 17 Mar 2015 17:48:28 +0800 Subject: USB: f81232: modify/add author Add me to co-author and fix no '>' in greg kh's email Signed-off-by: Peter Hung Signed-off-by: Johan Hovold diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c index ecb5798..68016e7 100644 --- a/drivers/usb/serial/f81232.c +++ b/drivers/usb/serial/f81232.c @@ -688,5 +688,6 @@ static struct usb_serial_driver * const serial_drivers[] = { module_usb_serial_driver(serial_drivers, id_table); MODULE_DESCRIPTION("Fintek F81232 USB to serial adaptor driver"); -MODULE_AUTHOR("Greg Kroah-Hartman "); +MODULE_AUTHOR("Peter Hong "); MODULE_LICENSE("GPL v2"); -- cgit v0.10.2 From 65dd82ae453f5290be0ea83ed0f23163ea49c0eb Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Fri, 27 Mar 2015 17:33:38 +0100 Subject: USB: f81232: fix some minor style issues Fix some really minor coding-style issues. Signed-off-by: Johan Hovold diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c index 68016e7..972f5a5 100644 --- a/drivers/usb/serial/f81232.c +++ b/drivers/usb/serial/f81232.c @@ -32,14 +32,14 @@ static const struct usb_device_id id_table[] = { MODULE_DEVICE_TABLE(usb, id_table); /* Maximum baudrate for F81232 */ -#define F81232_MAX_BAUDRATE 115200 +#define F81232_MAX_BAUDRATE 115200 /* USB Control EP parameter */ -#define F81232_REGISTER_REQUEST 0xa0 +#define F81232_REGISTER_REQUEST 0xa0 #define F81232_GET_REGISTER 0xc0 #define F81232_SET_REGISTER 0x40 -#define SERIAL_BASE_ADDRESS 0x0120 +#define SERIAL_BASE_ADDRESS 0x0120 #define RECEIVE_BUFFER_REGISTER (0x00 + SERIAL_BASE_ADDRESS) #define INTERRUPT_ENABLE_REGISTER (0x01 + SERIAL_BASE_ADDRESS) #define FIFO_CONTROL_REGISTER (0x02 + SERIAL_BASE_ADDRESS) @@ -349,7 +349,8 @@ static void f81232_break_ctl(struct tty_struct *tty, int break_state) static void f81232_set_baudrate(struct usb_serial_port *port, speed_t baudrate) { u8 lcr; - int divisor, status = 0; + int divisor; + int status = 0; divisor = calc_baud_divisor(baudrate); @@ -666,7 +667,7 @@ static struct usb_serial_driver f81232_device = { .bulk_out_size = 256, .open = f81232_open, .close = f81232_close, - .dtr_rts = f81232_dtr_rts, + .dtr_rts = f81232_dtr_rts, .carrier_raised = f81232_carrier_raised, .ioctl = f81232_ioctl, .break_ctl = f81232_break_ctl, -- cgit v0.10.2 From 8b86ed078a65433a60ff59091a136d23724bd6d3 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 26 Mar 2015 16:49:38 -0700 Subject: usb: Fix warnings in chaoskey driver > drivers/usb/misc/chaoskey.c: In function 'chaoskey_read': > >> drivers/usb/misc/chaoskey.c:412:3: error: implicit declaration of function 'copy_to_user' > >> [-Werror=implicit-function-declaration] > remain = copy_to_user(buffer, dev->buf + dev->used, this_time); I was unable to reproduce this locally, but added an explicit #include which should ensure the definition on all architectures. > sparse warnings: (new ones prefixed by >>) > > >> drivers/usb/misc/chaoskey.c:117:30: sparse: incorrect type in assignment (different base types) > drivers/usb/misc/chaoskey.c:117:30: expected int [signed] size > drivers/usb/misc/chaoskey.c:117:30: got restricted __le16 [usertype] wMaxPacketSize Switched the code to using the USB descriptor accessor functions. Signed-off-by: Keith Packard Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/misc/chaoskey.c b/drivers/usb/misc/chaoskey.c index ef80ce9..3ad5d19 100644 --- a/drivers/usb/misc/chaoskey.c +++ b/drivers/usb/misc/chaoskey.c @@ -27,6 +27,8 @@ #include #include #include +#include +#include static struct usb_driver chaoskey_driver; static struct usb_class_driver chaoskey_class; @@ -113,8 +115,8 @@ static int chaoskey_probe(struct usb_interface *interface, /* Find the first bulk IN endpoint and its packet size */ for (i = 0; i < altsetting->desc.bNumEndpoints; i++) { if (usb_endpoint_is_bulk_in(&altsetting->endpoint[i].desc)) { - in_ep = altsetting->endpoint[i].desc.bEndpointAddress; - size = altsetting->endpoint[i].desc.wMaxPacketSize; + in_ep = usb_endpoint_num(&altsetting->endpoint[i].desc); + size = usb_endpoint_maxp(&altsetting->endpoint[i].desc); break; } } -- cgit v0.10.2 From 358d6c87e73310c8e6564153cb556c0cd9e523fc Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Mon, 23 Mar 2015 11:54:50 +0800 Subject: phy: qcom-ufs: Fix build error due to missing export symbols Fix below build error when compile the driver as a module. ERROR: "ufs_qcom_phy_power_off" [drivers/phy/phy-qcom-ufs-qmp-20nm.ko] undefined! ERROR: "ufs_qcom_phy_power_on" [drivers/phy/phy-qcom-ufs-qmp-20nm.ko] undefined! ERROR: "ufs_qcom_phy_exit" [drivers/phy/phy-qcom-ufs-qmp-20nm.ko] undefined! ERROR: "ufs_qcom_phy_calibrate" [drivers/phy/phy-qcom-ufs-qmp-20nm.ko] undefined! ERROR: "ufs_qcom_phy_generic_probe" [drivers/phy/phy-qcom-ufs-qmp-20nm.ko] undefined! ERROR: "ufs_qcom_phy_init_vregulators" [drivers/phy/phy-qcom-ufs-qmp-20nm.ko] undefined! ERROR: "ufs_qcom_phy_init_clks" [drivers/phy/phy-qcom-ufs-qmp-20nm.ko] undefined! ERROR: "ufs_qcom_phy_remove" [drivers/phy/phy-qcom-ufs-qmp-20nm.ko] undefined! ERROR: "get_ufs_qcom_phy" [drivers/phy/phy-qcom-ufs-qmp-20nm.ko] undefined! ERROR: "ufs_qcom_phy_power_off" [drivers/phy/phy-qcom-ufs-qmp-14nm.ko] undefined! ERROR: "ufs_qcom_phy_power_on" [drivers/phy/phy-qcom-ufs-qmp-14nm.ko] undefined! ERROR: "ufs_qcom_phy_exit" [drivers/phy/phy-qcom-ufs-qmp-14nm.ko] undefined! ERROR: "ufs_qcom_phy_generic_probe" [drivers/phy/phy-qcom-ufs-qmp-14nm.ko] undefined! ERROR: "ufs_qcom_phy_init_vregulators" [drivers/phy/phy-qcom-ufs-qmp-14nm.ko] undefined! ERROR: "ufs_qcom_phy_init_clks" [drivers/phy/phy-qcom-ufs-qmp-14nm.ko] undefined! ERROR: "ufs_qcom_phy_calibrate" [drivers/phy/phy-qcom-ufs-qmp-14nm.ko] undefined! ERROR: "ufs_qcom_phy_remove" [drivers/phy/phy-qcom-ufs-qmp-14nm.ko] undefined! ERROR: "get_ufs_qcom_phy" [drivers/phy/phy-qcom-ufs-qmp-14nm.ko] undefined! make[1]: *** [__modpost] Error 1 make: *** [modules] Error 2 Signed-off-by: Axel Lin Signed-off-by: Kishon Vijay Abraham I diff --git a/drivers/phy/phy-qcom-ufs.c b/drivers/phy/phy-qcom-ufs.c index d95effe..a149d92 100644 --- a/drivers/phy/phy-qcom-ufs.c +++ b/drivers/phy/phy-qcom-ufs.c @@ -73,6 +73,7 @@ int ufs_qcom_phy_calibrate(struct ufs_qcom_phy *ufs_qcom_phy, out: return ret; } +EXPORT_SYMBOL_GPL(ufs_qcom_phy_calibrate); struct phy *ufs_qcom_phy_generic_probe(struct platform_device *pdev, struct ufs_qcom_phy *common_cfg, @@ -111,6 +112,7 @@ struct phy *ufs_qcom_phy_generic_probe(struct platform_device *pdev, out: return generic_phy; } +EXPORT_SYMBOL_GPL(ufs_qcom_phy_generic_probe); /* * This assumes the embedded phy structure inside generic_phy is of type @@ -122,6 +124,7 @@ struct ufs_qcom_phy *get_ufs_qcom_phy(struct phy *generic_phy) { return (struct ufs_qcom_phy *)phy_get_drvdata(generic_phy); } +EXPORT_SYMBOL_GPL(get_ufs_qcom_phy); static int ufs_qcom_phy_base_init(struct platform_device *pdev, @@ -229,6 +232,7 @@ ufs_qcom_phy_init_clks(struct phy *generic_phy, out: return err; } +EXPORT_SYMBOL_GPL(ufs_qcom_phy_init_clks); int ufs_qcom_phy_init_vregulators(struct phy *generic_phy, @@ -253,6 +257,7 @@ ufs_qcom_phy_init_vregulators(struct phy *generic_phy, out: return err; } +EXPORT_SYMBOL_GPL(ufs_qcom_phy_init_vregulators); static int __ufs_qcom_phy_init_vreg(struct phy *phy, struct ufs_qcom_phy_vreg *vreg, const char *name, bool optional) @@ -648,6 +653,7 @@ int ufs_qcom_phy_remove(struct phy *generic_phy, return 0; } +EXPORT_SYMBOL_GPL(ufs_qcom_phy_remove); int ufs_qcom_phy_exit(struct phy *generic_phy) { @@ -658,6 +664,7 @@ int ufs_qcom_phy_exit(struct phy *generic_phy) return 0; } +EXPORT_SYMBOL_GPL(ufs_qcom_phy_exit); int ufs_qcom_phy_is_pcs_ready(struct phy *generic_phy) { @@ -726,6 +733,7 @@ out_disable_phy: out: return err; } +EXPORT_SYMBOL_GPL(ufs_qcom_phy_power_on); int ufs_qcom_phy_power_off(struct phy *generic_phy) { @@ -744,3 +752,4 @@ int ufs_qcom_phy_power_off(struct phy *generic_phy) return 0; } +EXPORT_SYMBOL_GPL(ufs_qcom_phy_power_off); -- cgit v0.10.2 From 52ea796b9161b1b81242e6831d9e128ee207ad2d Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Mon, 23 Mar 2015 12:08:18 +0800 Subject: phy: qcom-ufs: Don't return error if fail to get optional resource "dev_ref_clk_ctrl_mem" is optional resource, so don't return error if fail to get the resource. Since it's an optional resource, don't emit error if fail to get dev_ref_clk_ctrl_mem. Also remove redundant test for res, it's done by devm_ioremap_resource(). Signed-off-by: Axel Lin Signed-off-by: Kishon Vijay Abraham I diff --git a/drivers/phy/phy-qcom-ufs.c b/drivers/phy/phy-qcom-ufs.c index a149d92..c4199e6 100644 --- a/drivers/phy/phy-qcom-ufs.c +++ b/drivers/phy/phy-qcom-ufs.c @@ -135,40 +135,23 @@ int ufs_qcom_phy_base_init(struct platform_device *pdev, int err = 0; res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "phy_mem"); - if (!res) { - dev_err(dev, "%s: phy_mem resource not found\n", __func__); - err = -ENOMEM; - goto out; - } - phy_common->mmio = devm_ioremap_resource(dev, res); if (IS_ERR((void const *)phy_common->mmio)) { err = PTR_ERR((void const *)phy_common->mmio); phy_common->mmio = NULL; dev_err(dev, "%s: ioremap for phy_mem resource failed %d\n", __func__, err); - goto out; + return err; } /* "dev_ref_clk_ctrl_mem" is optional resource */ res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dev_ref_clk_ctrl_mem"); - if (!res) { - dev_dbg(dev, "%s: dev_ref_clk_ctrl_mem resource not found\n", - __func__); - goto out; - } - phy_common->dev_ref_clk_ctrl_mmio = devm_ioremap_resource(dev, res); - if (IS_ERR((void const *)phy_common->dev_ref_clk_ctrl_mmio)) { - err = PTR_ERR((void const *)phy_common->dev_ref_clk_ctrl_mmio); + if (IS_ERR((void const *)phy_common->dev_ref_clk_ctrl_mmio)) phy_common->dev_ref_clk_ctrl_mmio = NULL; - dev_err(dev, "%s: ioremap for dev_ref_clk_ctrl_mem resource failed %d\n", - __func__, err); - } -out: - return err; + return 0; } static int __ufs_qcom_phy_clk_get(struct phy *phy, -- cgit v0.10.2 From 609adde838f4557f9d209b0432f4bac5c5eb5e86 Mon Sep 17 00:00:00 2001 From: Tony Lindgren Date: Thu, 19 Mar 2015 17:08:07 -0700 Subject: phy: Add a driver for dm816x USB PHY Add a minimal driver for dm816x USB. This makes USB work on dm816x without any other changes needed as it can use the existing musb_dsps glue layer for the USB controller. Note that this phy is different from dm814x and am335x. Cc: Bin Liu Cc: Brian Hutchinson Cc: Felipe Balbi Cc: Matthijs van Duin Cc: Paul Bolle Cc: Rusty Russell Signed-off-by: Tony Lindgren Signed-off-by: Kishon Vijay Abraham I diff --git a/Documentation/devicetree/bindings/phy/dm816x-phy.txt b/Documentation/devicetree/bindings/phy/dm816x-phy.txt new file mode 100644 index 0000000..2fe3d11 --- /dev/null +++ b/Documentation/devicetree/bindings/phy/dm816x-phy.txt @@ -0,0 +1,24 @@ +Device tree binding documentation for am816x USB PHY +========================= + +Required properties: +- compatible : should be "ti,dm816x-usb-phy" +- reg : offset and length of the PHY register set. +- reg-names : name for the phy registers +- clocks : phandle to the clock +- clock-names : name of the clock +- syscon: phandle for the syscon node to access misc registers +- #phy-cells : from the generic PHY bindings, must be 1 +- syscon: phandle for the syscon node to access misc registers + +Example: + +usb_phy0: usb-phy@20 { + compatible = "ti,dm8168-usb-phy"; + reg = <0x20 0x8>; + reg-names = "phy"; + clocks = <&main_fapll 6>; + clock-names = "refclk"; + #phy-cells = <0>; + syscon = <&scm_conf>; +}; diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig index 2962de2..885c39c 100644 --- a/drivers/phy/Kconfig +++ b/drivers/phy/Kconfig @@ -35,6 +35,13 @@ config ARMADA375_USBCLUSTER_PHY depends on OF select GENERIC_PHY +config PHY_DM816X_USB + tristate "TI dm816x USB PHY driver" + depends on ARCH_OMAP2PLUS + select GENERIC_PHY + help + Enable this for dm816x USB to work. + config PHY_EXYNOS_MIPI_VIDEO tristate "S5P/EXYNOS SoC series MIPI CSI-2/DSI PHY driver" depends on HAS_IOMEM diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile index f080e1b..dab6665 100644 --- a/drivers/phy/Makefile +++ b/drivers/phy/Makefile @@ -5,6 +5,7 @@ obj-$(CONFIG_GENERIC_PHY) += phy-core.o obj-$(CONFIG_PHY_BERLIN_USB) += phy-berlin-usb.o obj-$(CONFIG_PHY_BERLIN_SATA) += phy-berlin-sata.o +obj-$(CONFIG_PHY_DM816X_USB) += phy-dm816x-usb.o obj-$(CONFIG_ARMADA375_USBCLUSTER_PHY) += phy-armada375-usb2.o obj-$(CONFIG_BCM_KONA_USB2_PHY) += phy-bcm-kona-usb2.o obj-$(CONFIG_PHY_EXYNOS_DP_VIDEO) += phy-exynos-dp-video.o diff --git a/drivers/phy/phy-dm816x-usb.c b/drivers/phy/phy-dm816x-usb.c new file mode 100644 index 0000000..7b42555 --- /dev/null +++ b/drivers/phy/phy-dm816x-usb.c @@ -0,0 +1,290 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation version 2. + * + * This program is distributed "as is" WITHOUT ANY WARRANTY of any + * kind, whether express or implied; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +/* + * TRM has two sets of USB_CTRL registers.. The correct register bits + * are in TRM section 24.9.8.2 USB_CTRL Register. The TRM documents the + * phy as being SR70LX Synopsys USB 2.0 OTG nanoPHY. It also seems at + * least dm816x rev c ignores writes to USB_CTRL register, but the TI + * kernel is writing to those so it's possible that later revisions + * have worknig USB_CTRL register. + * + * Also note that At least USB_CTRL register seems to be dm816x specific + * according to the TRM. It's possible that USBPHY_CTRL is more generic, + * but that would have to be checked against the SR70LX documentation + * which does not seem to be publicly available. + * + * Finally, the phy on dm814x and am335x is different from dm816x. + */ +#define DM816X_USB_CTRL_PHYCLKSRC BIT(8) /* 1 = PLL ref clock */ +#define DM816X_USB_CTRL_PHYSLEEP1 BIT(1) /* Enable the first phy */ +#define DM816X_USB_CTRL_PHYSLEEP0 BIT(0) /* Enable the second phy */ + +#define DM816X_USBPHY_CTRL_TXRISETUNE 1 +#define DM816X_USBPHY_CTRL_TXVREFTUNE 0xc +#define DM816X_USBPHY_CTRL_TXPREEMTUNE 0x2 + +struct dm816x_usb_phy { + struct regmap *syscon; + struct device *dev; + unsigned int instance; + struct clk *refclk; + struct usb_phy phy; + unsigned int usb_ctrl; /* Shared between phy0 and phy1 */ + unsigned int usbphy_ctrl; +}; + +static int dm816x_usb_phy_set_host(struct usb_otg *otg, struct usb_bus *host) +{ + otg->host = host; + if (!host) + otg->state = OTG_STATE_UNDEFINED; + + return 0; +} + +static int dm816x_usb_phy_set_peripheral(struct usb_otg *otg, + struct usb_gadget *gadget) +{ + otg->gadget = gadget; + if (!gadget) + otg->state = OTG_STATE_UNDEFINED; + + return 0; +} + +static int dm816x_usb_phy_init(struct phy *x) +{ + struct dm816x_usb_phy *phy = phy_get_drvdata(x); + unsigned int val; + int error; + + if (clk_get_rate(phy->refclk) != 24000000) + dev_warn(phy->dev, "nonstandard phy refclk\n"); + + /* Set PLL ref clock and put phys to sleep */ + error = regmap_update_bits(phy->syscon, phy->usb_ctrl, + DM816X_USB_CTRL_PHYCLKSRC | + DM816X_USB_CTRL_PHYSLEEP1 | + DM816X_USB_CTRL_PHYSLEEP0, + 0); + regmap_read(phy->syscon, phy->usb_ctrl, &val); + if ((val & 3) != 0) + dev_info(phy->dev, + "Working dm816x USB_CTRL! (0x%08x)\n", + val); + + /* + * TI kernel sets these values for "symmetrical eye diagram and + * better signal quality" so let's assume somebody checked the + * values with a scope and set them here too. + */ + regmap_read(phy->syscon, phy->usbphy_ctrl, &val); + val |= DM816X_USBPHY_CTRL_TXRISETUNE | + DM816X_USBPHY_CTRL_TXVREFTUNE | + DM816X_USBPHY_CTRL_TXPREEMTUNE; + regmap_write(phy->syscon, phy->usbphy_ctrl, val); + + return 0; +} + +static struct phy_ops ops = { + .init = dm816x_usb_phy_init, + .owner = THIS_MODULE, +}; + +static int dm816x_usb_phy_runtime_suspend(struct device *dev) +{ + struct dm816x_usb_phy *phy = dev_get_drvdata(dev); + unsigned int mask, val; + int error = 0; + + mask = BIT(phy->instance); + val = ~BIT(phy->instance); + error = regmap_update_bits(phy->syscon, phy->usb_ctrl, + mask, val); + if (error) + dev_err(phy->dev, "phy%i failed to power off\n", + phy->instance); + clk_disable(phy->refclk); + + return 0; +} + +static int dm816x_usb_phy_runtime_resume(struct device *dev) +{ + struct dm816x_usb_phy *phy = dev_get_drvdata(dev); + unsigned int mask, val; + int error; + + error = clk_enable(phy->refclk); + if (error) + return error; + + /* + * Note that at least dm816x rev c does not seem to do + * anything with the USB_CTRL register. But let's follow + * what the TI tree is doing in case later revisions use + * USB_CTRL. + */ + mask = BIT(phy->instance); + val = BIT(phy->instance); + error = regmap_update_bits(phy->syscon, phy->usb_ctrl, + mask, val); + if (error) { + dev_err(phy->dev, "phy%i failed to power on\n", + phy->instance); + clk_disable(phy->refclk); + return error; + } + + return 0; +} + +static UNIVERSAL_DEV_PM_OPS(dm816x_usb_phy_pm_ops, + dm816x_usb_phy_runtime_suspend, + dm816x_usb_phy_runtime_resume, + NULL); + +#ifdef CONFIG_OF +static const struct of_device_id dm816x_usb_phy_id_table[] = { + { + .compatible = "ti,dm8168-usb-phy", + }, + {}, +}; +MODULE_DEVICE_TABLE(of, dm816x_usb_phy_id_table); +#endif + +static int dm816x_usb_phy_probe(struct platform_device *pdev) +{ + struct dm816x_usb_phy *phy; + struct resource *res; + struct phy *generic_phy; + struct phy_provider *phy_provider; + struct usb_otg *otg; + const struct of_device_id *of_id; + const struct usb_phy_data *phy_data; + int error; + + of_id = of_match_device(of_match_ptr(dm816x_usb_phy_id_table), + &pdev->dev); + if (!of_id) + return -EINVAL; + + phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL); + if (!phy) + return -ENOMEM; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) + return -ENOENT; + + phy->syscon = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, + "syscon"); + if (IS_ERR(phy->syscon)) + return PTR_ERR(phy->syscon); + + /* + * According to sprs614e.pdf, the first usb_ctrl is shared and + * the second instance for usb_ctrl is reserved.. Also the + * register bits are different from earlier TRMs. + */ + phy->usb_ctrl = 0x20; + phy->usbphy_ctrl = (res->start & 0xff) + 4; + if (phy->usbphy_ctrl == 0x2c) + phy->instance = 1; + + phy_data = of_id->data; + + otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL); + if (!otg) + return -ENOMEM; + + phy->dev = &pdev->dev; + phy->phy.dev = phy->dev; + phy->phy.label = "dm8168_usb_phy"; + phy->phy.otg = otg; + phy->phy.type = USB_PHY_TYPE_USB2; + otg->set_host = dm816x_usb_phy_set_host; + otg->set_peripheral = dm816x_usb_phy_set_peripheral; + otg->usb_phy = &phy->phy; + + platform_set_drvdata(pdev, phy); + + phy->refclk = devm_clk_get(phy->dev, "refclk"); + if (IS_ERR(phy->refclk)) + return PTR_ERR(phy->refclk); + error = clk_prepare(phy->refclk); + if (error) + return error; + + pm_runtime_enable(phy->dev); + generic_phy = devm_phy_create(phy->dev, NULL, &ops); + if (IS_ERR(generic_phy)) + return PTR_ERR(generic_phy); + + phy_set_drvdata(generic_phy, phy); + + phy_provider = devm_of_phy_provider_register(phy->dev, + of_phy_simple_xlate); + if (IS_ERR(phy_provider)) + return PTR_ERR(phy_provider); + + usb_add_phy_dev(&phy->phy); + + return 0; +} + +static int dm816x_usb_phy_remove(struct platform_device *pdev) +{ + struct dm816x_usb_phy *phy = platform_get_drvdata(pdev); + + usb_remove_phy(&phy->phy); + pm_runtime_disable(phy->dev); + clk_unprepare(phy->refclk); + + return 0; +} + +static struct platform_driver dm816x_usb_phy_driver = { + .probe = dm816x_usb_phy_probe, + .remove = dm816x_usb_phy_remove, + .driver = { + .name = "dm816x-usb-phy", + .pm = &dm816x_usb_phy_pm_ops, + .of_match_table = of_match_ptr(dm816x_usb_phy_id_table), + }, +}; + +module_platform_driver(dm816x_usb_phy_driver); + +MODULE_ALIAS("platform:dm816x_usb"); +MODULE_AUTHOR("Tony Lindgren "); +MODULE_DESCRIPTION("dm816x usb phy driver"); +MODULE_LICENSE("GPL v2"); -- cgit v0.10.2 From 9c3b443026368583d2df3373a11b1c18c361d9a6 Mon Sep 17 00:00:00 2001 From: Chen-Yu Tsai Date: Sat, 14 Mar 2015 11:57:16 +0800 Subject: phy: Add driver to support individual USB PHYs on sun9i Unlike previous Allwinner SoCs, there is no central PHY control block on the A80. Also, OTG support is completely split off into a different controller. This adds a new driver to support the regular USB PHYs. Signed-off-by: Chen-Yu Tsai Acked-by: Maxime Ripard Signed-off-by: Kishon Vijay Abraham I diff --git a/Documentation/devicetree/bindings/phy/sun9i-usb-phy.txt b/Documentation/devicetree/bindings/phy/sun9i-usb-phy.txt new file mode 100644 index 0000000..1cca85c --- /dev/null +++ b/Documentation/devicetree/bindings/phy/sun9i-usb-phy.txt @@ -0,0 +1,38 @@ +Allwinner sun9i USB PHY +----------------------- + +Required properties: +- compatible : should be one of + * allwinner,sun9i-a80-usb-phy +- reg : a list of offset + length pairs +- #phy-cells : from the generic phy bindings, must be 0 +- phy_type : "hsic" for HSIC usage; + other values or absence of this property indicates normal USB +- clocks : phandle + clock specifier for the phy clocks +- clock-names : depending on the "phy_type" property, + * "phy" for normal USB + * "hsic_480M", "hsic_12M" for HSIC +- resets : a list of phandle + reset specifier pairs +- reset-names : depending on the "phy_type" property, + * "phy" for normal USB + * "hsic" for HSIC + +Optional Properties: +- phy-supply : from the generic phy bindings, a phandle to a regulator that + provides power to VBUS. + +It is recommended to list all clocks and resets available. +The driver will only use those matching the phy_type. + +Example: + usbphy1: phy@00a01800 { + compatible = "allwinner,sun9i-a80-usb-phy"; + reg = <0x00a01800 0x4>; + clocks = <&usb_phy_clk 2>, <&usb_phy_clk 10>, + <&usb_phy_clk 3>; + clock-names = "hsic_480M", "hsic_12M", "phy"; + resets = <&usb_phy_clk 18>, <&usb_phy_clk 19>; + reset-names = "hsic", "phy"; + status = "disabled"; + #phy-cells = <0>; + }; diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig index 885c39c..a53bd5b 100644 --- a/drivers/phy/Kconfig +++ b/drivers/phy/Kconfig @@ -181,6 +181,17 @@ config PHY_SUN4I_USB This driver controls the entire USB PHY block, both the USB OTG parts, as well as the 2 regular USB 2 host PHYs. +config PHY_SUN9I_USB + tristate "Allwinner sun9i SoC USB PHY driver" + depends on ARCH_SUNXI && HAS_IOMEM && OF + depends on RESET_CONTROLLER + select GENERIC_PHY + help + Enable this to support the transceiver that is part of Allwinner + sun9i SoCs. + + This driver controls each individual USB 2 host PHY. + config PHY_SAMSUNG_USB2 tristate "Samsung USB 2.0 PHY driver" depends on HAS_IOMEM diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile index dab6665..f126251 100644 --- a/drivers/phy/Makefile +++ b/drivers/phy/Makefile @@ -21,6 +21,7 @@ obj-$(CONFIG_TWL4030_USB) += phy-twl4030-usb.o obj-$(CONFIG_PHY_EXYNOS5250_SATA) += phy-exynos5250-sata.o obj-$(CONFIG_PHY_HIX5HD2_SATA) += phy-hix5hd2-sata.o obj-$(CONFIG_PHY_SUN4I_USB) += phy-sun4i-usb.o +obj-$(CONFIG_PHY_SUN9I_USB) += phy-sun9i-usb.o obj-$(CONFIG_PHY_SAMSUNG_USB2) += phy-exynos-usb2.o phy-exynos-usb2-y += phy-samsung-usb2.o phy-exynos-usb2-$(CONFIG_PHY_EXYNOS4210_USB2) += phy-exynos4210-usb2.o diff --git a/drivers/phy/phy-sun9i-usb.c b/drivers/phy/phy-sun9i-usb.c new file mode 100644 index 0000000..0095914 --- /dev/null +++ b/drivers/phy/phy-sun9i-usb.c @@ -0,0 +1,202 @@ +/* + * Allwinner sun9i USB phy driver + * + * Copyright (C) 2014-2015 Chen-Yu Tsai + * + * Based on phy-sun4i-usb.c from + * Hans de Goede + * + * and code from + * Allwinner Technology Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define SUNXI_AHB_INCR16_BURST_EN BIT(11) +#define SUNXI_AHB_INCR8_BURST_EN BIT(10) +#define SUNXI_AHB_INCR4_BURST_EN BIT(9) +#define SUNXI_AHB_INCRX_ALIGN_EN BIT(8) +#define SUNXI_ULPI_BYPASS_EN BIT(0) + +/* usb1 HSIC specific bits */ +#define SUNXI_EHCI_HS_FORCE BIT(20) +#define SUNXI_HSIC_CONNECT_DET BIT(17) +#define SUNXI_HSIC_CONNECT_INT BIT(16) +#define SUNXI_HSIC BIT(1) + +struct sun9i_usb_phy { + struct phy *phy; + void __iomem *pmu; + struct reset_control *reset; + struct clk *clk; + struct clk *hsic_clk; + enum usb_phy_interface type; +}; + +static void sun9i_usb_phy_passby(struct sun9i_usb_phy *phy, int enable) +{ + u32 bits, reg_value; + + bits = SUNXI_AHB_INCR16_BURST_EN | SUNXI_AHB_INCR8_BURST_EN | + SUNXI_AHB_INCR4_BURST_EN | SUNXI_AHB_INCRX_ALIGN_EN | + SUNXI_ULPI_BYPASS_EN; + + if (phy->type == USBPHY_INTERFACE_MODE_HSIC) + bits |= SUNXI_HSIC | SUNXI_EHCI_HS_FORCE | + SUNXI_HSIC_CONNECT_DET | SUNXI_HSIC_CONNECT_INT; + + reg_value = readl(phy->pmu); + + if (enable) + reg_value |= bits; + else + reg_value &= ~bits; + + writel(reg_value, phy->pmu); +} + +static int sun9i_usb_phy_init(struct phy *_phy) +{ + struct sun9i_usb_phy *phy = phy_get_drvdata(_phy); + int ret; + + ret = clk_prepare_enable(phy->clk); + if (ret) + goto err_clk; + + ret = clk_prepare_enable(phy->hsic_clk); + if (ret) + goto err_hsic_clk; + + ret = reset_control_deassert(phy->reset); + if (ret) + goto err_reset; + + sun9i_usb_phy_passby(phy, 1); + return 0; + +err_reset: + clk_disable_unprepare(phy->hsic_clk); + +err_hsic_clk: + clk_disable_unprepare(phy->clk); + +err_clk: + return ret; +} + +static int sun9i_usb_phy_exit(struct phy *_phy) +{ + struct sun9i_usb_phy *phy = phy_get_drvdata(_phy); + + sun9i_usb_phy_passby(phy, 0); + reset_control_assert(phy->reset); + clk_disable_unprepare(phy->hsic_clk); + clk_disable_unprepare(phy->clk); + + return 0; +} + +static struct phy_ops sun9i_usb_phy_ops = { + .init = sun9i_usb_phy_init, + .exit = sun9i_usb_phy_exit, + .owner = THIS_MODULE, +}; + +static int sun9i_usb_phy_probe(struct platform_device *pdev) +{ + struct sun9i_usb_phy *phy; + struct device *dev = &pdev->dev; + struct device_node *np = dev->of_node; + struct phy_provider *phy_provider; + struct resource *res; + + phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); + if (!phy) + return -ENOMEM; + + phy->type = of_usb_get_phy_mode(np); + if (phy->type == USBPHY_INTERFACE_MODE_HSIC) { + phy->clk = devm_clk_get(dev, "hsic_480M"); + if (IS_ERR(phy->clk)) { + dev_err(dev, "failed to get hsic_480M clock\n"); + return PTR_ERR(phy->clk); + } + + phy->hsic_clk = devm_clk_get(dev, "hsic_12M"); + if (IS_ERR(phy->clk)) { + dev_err(dev, "failed to get hsic_12M clock\n"); + return PTR_ERR(phy->clk); + } + + phy->reset = devm_reset_control_get(dev, "hsic"); + if (IS_ERR(phy->reset)) { + dev_err(dev, "failed to get reset control\n"); + return PTR_ERR(phy->reset); + } + } else { + phy->clk = devm_clk_get(dev, "phy"); + if (IS_ERR(phy->clk)) { + dev_err(dev, "failed to get phy clock\n"); + return PTR_ERR(phy->clk); + } + + phy->reset = devm_reset_control_get(dev, "phy"); + if (IS_ERR(phy->reset)) { + dev_err(dev, "failed to get reset control\n"); + return PTR_ERR(phy->reset); + } + } + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + phy->pmu = devm_ioremap_resource(dev, res); + if (IS_ERR(phy->pmu)) + return PTR_ERR(phy->pmu); + + phy->phy = devm_phy_create(dev, NULL, &sun9i_usb_phy_ops); + if (IS_ERR(phy->phy)) { + dev_err(dev, "failed to create PHY\n"); + return PTR_ERR(phy->phy); + } + + phy_set_drvdata(phy->phy, phy); + phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); + + return PTR_ERR_OR_ZERO(phy_provider); +} + +static const struct of_device_id sun9i_usb_phy_of_match[] = { + { .compatible = "allwinner,sun9i-a80-usb-phy" }, + { }, +}; +MODULE_DEVICE_TABLE(of, sun9i_usb_phy_of_match); + +static struct platform_driver sun9i_usb_phy_driver = { + .probe = sun9i_usb_phy_probe, + .driver = { + .of_match_table = sun9i_usb_phy_of_match, + .name = "sun9i-usb-phy", + } +}; +module_platform_driver(sun9i_usb_phy_driver); + +MODULE_DESCRIPTION("Allwinner sun9i USB phy driver"); +MODULE_AUTHOR("Chen-Yu Tsai "); +MODULE_LICENSE("GPL"); -- cgit v0.10.2 From fbea230e7884044ee2e84bb28f6879dc30e1db24 Mon Sep 17 00:00:00 2001 From: Peter Griffin Date: Mon, 30 Mar 2015 16:17:07 +0100 Subject: phy: miphy365x: Use the generic phy type constants in dt-bindings/phy/phy.h Now there are generic phy type constants declared in phy.h, migrate over to using them rather than defining our own. This change has been done as one atomic commit to be bisectable. Note: The values of the defines are the same, so there is no ABI breakage with this patch. Signed-off-by: Peter Griffin Acked-by: Rob Herring Acked-by: Lee Jones Acked-by: Maxime Coquelin Signed-off-by: Kishon Vijay Abraham I diff --git a/Documentation/devicetree/bindings/phy/phy-miphy365x.txt b/Documentation/devicetree/bindings/phy/phy-miphy365x.txt index 9802d5d..8772900 100644 --- a/Documentation/devicetree/bindings/phy/phy-miphy365x.txt +++ b/Documentation/devicetree/bindings/phy/phy-miphy365x.txt @@ -20,8 +20,8 @@ Required nodes : A sub-node is required for each channel the controller Required properties (port (child) node): - #phy-cells : Should be 1 (See second example) Cell after port phandle is device type from: - - MIPHY_TYPE_SATA - - MIPHY_TYPE_PCI + - PHY_TYPE_SATA + - PHY_TYPE_PCI - reg : Address and length of register sets for each device in "reg-names" - reg-names : The names of the register addresses corresponding to the @@ -68,10 +68,10 @@ property, containing a phandle to the phy port node and a device type. Example: -#include +#include sata0: sata@fe380000 { ... - phys = <&phy_port0 MIPHY_TYPE_SATA>; + phys = <&phy_port0 PHY_TYPE_SATA>; ... }; diff --git a/arch/arm/boot/dts/stih416.dtsi b/arch/arm/boot/dts/stih416.dtsi index ea28eba..eeb7afe 100644 --- a/arch/arm/boot/dts/stih416.dtsi +++ b/arch/arm/boot/dts/stih416.dtsi @@ -10,7 +10,7 @@ #include "stih416-clock.dtsi" #include "stih416-pinctrl.dtsi" -#include +#include #include #include / { @@ -306,7 +306,7 @@ reg = <0xfe380000 0x1000>; interrupts = ; interrupt-names = "hostc"; - phys = <&phy_port0 MIPHY_TYPE_SATA>; + phys = <&phy_port0 PHY_TYPE_SATA>; phy-names = "sata-phy"; resets = <&powerdown STIH416_SATA0_POWERDOWN>, <&softreset STIH416_SATA0_SOFTRESET>; diff --git a/drivers/phy/phy-miphy365x.c b/drivers/phy/phy-miphy365x.c index 6c80154..98bffbc 100644 --- a/drivers/phy/phy-miphy365x.c +++ b/drivers/phy/phy-miphy365x.c @@ -25,7 +25,7 @@ #include #include -#include +#include #define HFC_TIMEOUT 100 @@ -176,7 +176,7 @@ static u8 rx_tx_spd[] = { static int miphy365x_set_path(struct miphy365x_phy *miphy_phy, struct miphy365x_dev *miphy_dev) { - bool sata = (miphy_phy->type == MIPHY_TYPE_SATA); + bool sata = (miphy_phy->type == PHY_TYPE_SATA); return regmap_update_bits(miphy_dev->regmap, miphy_phy->ctrlreg, @@ -430,7 +430,7 @@ static int miphy365x_init(struct phy *phy) } /* Initialise Miphy for PCIe or SATA */ - if (miphy_phy->type == MIPHY_TYPE_PCIE) + if (miphy_phy->type == PHY_TYPE_PCIE) ret = miphy365x_init_pcie_port(miphy_phy, miphy_dev); else ret = miphy365x_init_sata_port(miphy_phy, miphy_dev); @@ -454,8 +454,8 @@ int miphy365x_get_addr(struct device *dev, struct miphy365x_phy *miphy_phy, return ret; } - if (!((!strncmp(name, "sata", 4) && type == MIPHY_TYPE_SATA) || - (!strncmp(name, "pcie", 4) && type == MIPHY_TYPE_PCIE))) + if (!((!strncmp(name, "sata", 4) && type == PHY_TYPE_SATA) || + (!strncmp(name, "pcie", 4) && type == PHY_TYPE_PCIE))) return 0; miphy_phy->base = of_iomap(phynode, index); @@ -498,8 +498,8 @@ static struct phy *miphy365x_xlate(struct device *dev, miphy_phy->type = args->args[0]; - if (!(miphy_phy->type == MIPHY_TYPE_SATA || - miphy_phy->type == MIPHY_TYPE_PCIE)) { + if (!(miphy_phy->type == PHY_TYPE_SATA || + miphy_phy->type == PHY_TYPE_PCIE)) { dev_err(dev, "Unsupported device type: %d\n", miphy_phy->type); return ERR_PTR(-EINVAL); } diff --git a/include/dt-bindings/phy/phy-miphy365x.h b/include/dt-bindings/phy/phy-miphy365x.h deleted file mode 100644 index 8ef8aba..0000000 --- a/include/dt-bindings/phy/phy-miphy365x.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * This header provides constants for the phy framework - * based on the STMicroelectronics MiPHY365x. - * - * Author: Lee Jones - */ -#ifndef _DT_BINDINGS_PHY_MIPHY -#define _DT_BINDINGS_PHY_MIPHY - -#define MIPHY_TYPE_SATA 1 -#define MIPHY_TYPE_PCIE 2 -#define MIPHY_TYPE_USB 3 - -#endif /* _DT_BINDINGS_PHY_MIPHY */ -- cgit v0.10.2 From 247e21c613649f34bcf2f71e57e813e6ed18b458 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Wed, 1 Apr 2015 08:44:32 +0800 Subject: phy: spear1310-miphy: Return proper error for spear1310_miphy_xlate The of_xlate callback should return ERR_PTR on error. Signed-off-by: Axel Lin Signed-off-by: Kishon Vijay Abraham I diff --git a/drivers/phy/phy-spear1310-miphy.c b/drivers/phy/phy-spear1310-miphy.c index 9f47fae..65ae640 100644 --- a/drivers/phy/phy-spear1310-miphy.c +++ b/drivers/phy/phy-spear1310-miphy.c @@ -192,14 +192,14 @@ static struct phy *spear1310_miphy_xlate(struct device *dev, if (args->args_count < 1) { dev_err(dev, "DT did not pass correct no of args\n"); - return NULL; + return ERR_PTR(-ENODEV); } priv->mode = args->args[0]; if (priv->mode != SATA && priv->mode != PCIE) { dev_err(dev, "DT did not pass correct phy mode\n"); - return NULL; + return ERR_PTR(-ENODEV); } return priv->phy; -- cgit v0.10.2 From 407ed8357464851cf12d68c4a969cd933f8dbcaf Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Wed, 1 Apr 2015 08:45:33 +0800 Subject: phy: spear1340-miphy: Return proper error for spear1340_miphy_xlate The of_xlate callback should return ERR_PTR on error. Signed-off-by: Axel Lin Signed-off-by: Kishon Vijay Abraham I diff --git a/drivers/phy/phy-spear1340-miphy.c b/drivers/phy/phy-spear1340-miphy.c index e42bc20..1a00c28 100644 --- a/drivers/phy/phy-spear1340-miphy.c +++ b/drivers/phy/phy-spear1340-miphy.c @@ -229,14 +229,14 @@ static struct phy *spear1340_miphy_xlate(struct device *dev, if (args->args_count < 1) { dev_err(dev, "DT did not pass correct no of args\n"); - return NULL; + return ERR_PTR(-ENODEV); } priv->mode = args->args[0]; if (priv->mode != SATA && priv->mode != PCIE) { dev_err(dev, "DT did not pass correct phy mode\n"); - return NULL; + return ERR_PTR(-ENODEV); } return priv->phy; -- cgit v0.10.2 From e95cf393d2097a7744f98de1c7936fcbde0843e3 Mon Sep 17 00:00:00 2001 From: Peter Griffin Date: Wed, 1 Apr 2015 07:42:41 +0100 Subject: MAINTAINERS: Add phy-miphy28lp.c and phy-miphy365x.c to ARCH/STI architecture This patch adds the phy-miphy28lp.c and phy-miphy365x.c phy drivers found on STMicroelectronics stih407 family SoC's into the STI arch section of the maintainers file. Signed-off-by: Peter Griffin Acked-by: Lee Jones Signed-off-by: Kishon Vijay Abraham I diff --git a/MAINTAINERS b/MAINTAINERS index ddc5a8c..daddc00 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1457,6 +1457,8 @@ F: drivers/clocksource/arm_global_timer.c F: drivers/i2c/busses/i2c-st.c F: drivers/media/rc/st_rc.c F: drivers/mmc/host/sdhci-st.c +F: drivers/phy/phy-miphy28lp.c +F: drivers/phy/phy-miphy365x.c F: drivers/phy/phy-stih407-usb.c F: drivers/phy/phy-stih41x-usb.c F: drivers/pinctrl/pinctrl-st.c -- cgit v0.10.2 From e845d64743ee397ff132e7f81e6bfb3597f9f479 Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Sun, 29 Mar 2015 02:21:20 -0700 Subject: Revert "usb: host/sl811-hcd: fix sparse warning" This reverts commit 1dc6120ef7f003305d99ef12f598a6b05eacc38c. Commit 1dc6120ef7f0 results in the following error when compiling x86_64:allyesconfig. sl811_cs.c:(.text+0x1d3cb72): undefined reference to `sl811h_driver' Fixes: 1dc6120ef7f0 ("usb: host/sl811-hcd: fix sparse warning") Cc: Lad, Prabhakar Signed-off-by: Guenter Roeck Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c index 944a417..f1d5c5a1 100644 --- a/drivers/usb/host/sl811-hcd.c +++ b/drivers/usb/host/sl811-hcd.c @@ -1801,7 +1801,7 @@ sl811h_resume(struct platform_device *dev) /* this driver is exported so sl811_cs can depend on it */ -static struct platform_driver sl811h_driver = { +struct platform_driver sl811h_driver = { .probe = sl811h_probe, .remove = sl811h_remove, -- cgit v0.10.2 From c6ab3aec4bc4beda2d6eb8ea43c6f5be3b215d3f Mon Sep 17 00:00:00 2001 From: Yoshihiro Shimoda Date: Thu, 2 Apr 2015 20:22:34 +0900 Subject: usb: phy: rcar-gen2-usb: Fix USBHS_UGSTS_LOCK value According to the technical update (No. TN-RCS-B011A/E), the UGSTS LOCK bit location is bit 8, not bits 9 and 8. So, this patch fixes the USBHS_UGSTS_LOCK value. Signed-off-by: Yoshihiro Shimoda Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/phy/phy-rcar-gen2-usb.c b/drivers/usb/phy/phy-rcar-gen2-usb.c index f838084..f81800b 100644 --- a/drivers/usb/phy/phy-rcar-gen2-usb.c +++ b/drivers/usb/phy/phy-rcar-gen2-usb.c @@ -47,7 +47,7 @@ struct rcar_gen2_usb_phy_priv { /* USB General status register */ #define USBHS_UGSTS_REG 0x88 -#define USBHS_UGSTS_LOCK (3 << 8) +#define USBHS_UGSTS_LOCK (1 << 8) /* Enable USBHS internal phy */ static int __rcar_gen2_usbhs_phy_enable(void __iomem *base) -- cgit v0.10.2 From d9aab404e60d122ded979fa0b81db42fb680d867 Mon Sep 17 00:00:00 2001 From: Randy Dunlap Date: Thu, 2 Apr 2015 17:10:55 -0700 Subject: usb/misc: fix chaoskey build, needs HW_RANDOM Fix build errors when HW_RANDOM is not enabled: drivers/built-in.o: In function `chaoskey_disconnect': chaoskey.c:(.text+0x5f3f00): undefined reference to `hwrng_unregister' drivers/built-in.o: In function `chaoskey_probe': chaoskey.c:(.text+0x5f42a6): undefined reference to `hwrng_register' Signed-off-by: Randy Dunlap Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig index 8c331f1..f7a7fc2 100644 --- a/drivers/usb/misc/Kconfig +++ b/drivers/usb/misc/Kconfig @@ -258,6 +258,7 @@ config USB_LINK_LAYER_TEST config USB_CHAOSKEY tristate "ChaosKey random number generator driver support" + depends on HW_RANDOM help Say Y here if you want to connect an AltusMetrum ChaosKey to your computer's USB port. The ChaosKey is a hardware random -- cgit v0.10.2 From 22299d13c28b13fe6140037980e79bc6fdb5f329 Mon Sep 17 00:00:00 2001 From: Sergei Shtylyov Date: Sun, 29 Mar 2015 01:46:39 +0300 Subject: wusbcore: rh: use USB_DT_HUB Fix using the bare number to set the 'bDescriptorType' field of the Hub Descriptor while the value is #define'd in . Signed-off-by: Sergei Shtylyov Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/wusbcore/rh.c b/drivers/usb/wusbcore/rh.c index aa5af81..a082fe6 100644 --- a/drivers/usb/wusbcore/rh.c +++ b/drivers/usb/wusbcore/rh.c @@ -182,7 +182,7 @@ static int wusbhc_rh_get_hub_descr(struct wusbhc *wusbhc, u16 wValue, if (wLength < length) return -ENOSPC; descr->bDescLength = 7 + 2 * temp; - descr->bDescriptorType = 0x29; /* HUB type */ + descr->bDescriptorType = USB_DT_HUB; /* HUB type */ descr->bNbrPorts = wusbhc->ports_max; descr->wHubCharacteristics = cpu_to_le16( HUB_CHAR_COMMON_LPSM /* All ports power at once */ -- cgit v0.10.2 From 8f413d807b37efcc7c7fa45f824f08d614a8cc0a Mon Sep 17 00:00:00 2001 From: Sergei Shtylyov Date: Sun, 29 Mar 2015 01:45:02 +0300 Subject: usbip: vhci_hcd: use USB_DT_HUB Fix using the bare number to set the 'bDescriptorType' field of the Hub Descriptor while the value is #define'd in . Signed-off-by: Sergei Shtylyov Acked-by: Valentina Manea Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c index 11f6f61..e9ef1ec 100644 --- a/drivers/usb/usbip/vhci_hcd.c +++ b/drivers/usb/usbip/vhci_hcd.c @@ -216,7 +216,7 @@ done: static inline void hub_descriptor(struct usb_hub_descriptor *desc) { memset(desc, 0, sizeof(*desc)); - desc->bDescriptorType = 0x29; + desc->bDescriptorType = USB_DT_HUB; desc->bDescLength = 9; desc->wHubCharacteristics = __constant_cpu_to_le16( HUB_CHAR_INDV_PORT_LPSM | HUB_CHAR_COMMON_OCPM); -- cgit v0.10.2 From b11373debee613760e81f520899e8807368188ad Mon Sep 17 00:00:00 2001 From: Sergei Shtylyov Date: Sun, 29 Mar 2015 01:43:25 +0300 Subject: renesas_usbhs: mod_host: use USB_DT_HUB Fix using the bare number to set the 'bDescriptorType' field of the Hub Descriptor while the value is #define'd in . Signed-off-by: Sergei Shtylyov Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/renesas_usbhs/mod_host.c b/drivers/usb/renesas_usbhs/mod_host.c index 96eead6..bd05035 100644 --- a/drivers/usb/renesas_usbhs/mod_host.c +++ b/drivers/usb/renesas_usbhs/mod_host.c @@ -1229,7 +1229,7 @@ static int __usbhsh_hub_get_status(struct usbhsh_hpriv *hpriv, break; case GetHubDescriptor: - desc->bDescriptorType = 0x29; + desc->bDescriptorType = USB_DT_HUB; desc->bHubContrCurrent = 0; desc->bNbrPorts = roothub_id; desc->bDescLength = 9; -- cgit v0.10.2 From e95af3aa1dc791d04795dbd12597cbe71405765d Mon Sep 17 00:00:00 2001 From: Sergei Shtylyov Date: Sun, 29 Mar 2015 01:42:06 +0300 Subject: musb_virthub: use USB_DT_HUB Fix using the bare number to set the 'bDescriptorType' field of the Hub Descriptor while the value is #define'd in . Signed-off-by: Sergei Shtylyov Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/musb/musb_virthub.c b/drivers/usb/musb/musb_virthub.c index 294e159..52ee9a7 100644 --- a/drivers/usb/musb/musb_virthub.c +++ b/drivers/usb/musb/musb_virthub.c @@ -345,7 +345,7 @@ int musb_hub_control( struct usb_hub_descriptor *desc = (void *)buf; desc->bDescLength = 9; - desc->bDescriptorType = 0x29; + desc->bDescriptorType = USB_DT_HUB; desc->bNbrPorts = 1; desc->wHubCharacteristics = cpu_to_le16( HUB_CHAR_INDV_PORT_LPSM /* per-port power switching */ -- cgit v0.10.2 From 1cf6563b3e9ecdfd8378fb81484632f715607a04 Mon Sep 17 00:00:00 2001 From: Sergei Shtylyov Date: Sun, 29 Mar 2015 01:40:24 +0300 Subject: isp1760-hcd: use USB_DT_HUB Fix using the bare number to set the 'bDescriptorType' field of the Hub Descriptor while the value is #define'd in . Signed-off-by: Sergei Shtylyov Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/isp1760/isp1760-hcd.c b/drivers/usb/isp1760/isp1760-hcd.c index 3cb98b1..9e23153 100644 --- a/drivers/usb/isp1760/isp1760-hcd.c +++ b/drivers/usb/isp1760/isp1760-hcd.c @@ -1758,7 +1758,7 @@ static void isp1760_hub_descriptor(struct isp1760_hcd *priv, int ports = HCS_N_PORTS(priv->hcs_params); u16 temp; - desc->bDescriptorType = 0x29; + desc->bDescriptorType = USB_DT_HUB; /* priv 1.0, 2.3.9 says 20ms max */ desc->bPwrOn2PwrGood = 10; desc->bHubContrCurrent = 0; -- cgit v0.10.2 From 2569ffd58b03d900f53b073054df4dc45ca67873 Mon Sep 17 00:00:00 2001 From: Sergei Shtylyov Date: Sun, 29 Mar 2015 01:39:09 +0300 Subject: dummy_hcd: use USB_DT[_SS]_HUB Fix using the bare numbers to set the 'bDescriptorType' field of the Hub Descriptors while the values are #define'd in . Signed-off-by: Sergei Shtylyov Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/gadget/udc/dummy_hcd.c b/drivers/usb/gadget/udc/dummy_hcd.c index 7592db7..181112c 100644 --- a/drivers/usb/gadget/udc/dummy_hcd.c +++ b/drivers/usb/gadget/udc/dummy_hcd.c @@ -1923,7 +1923,7 @@ static inline void ss_hub_descriptor(struct usb_hub_descriptor *desc) { memset(desc, 0, sizeof *desc); - desc->bDescriptorType = 0x2a; + desc->bDescriptorType = USB_DT_SS_HUB; desc->bDescLength = 12; desc->wHubCharacteristics = cpu_to_le16( HUB_CHAR_INDV_PORT_LPSM | @@ -1936,7 +1936,7 @@ ss_hub_descriptor(struct usb_hub_descriptor *desc) static inline void hub_descriptor(struct usb_hub_descriptor *desc) { memset(desc, 0, sizeof *desc); - desc->bDescriptorType = 0x29; + desc->bDescriptorType = USB_DT_HUB; desc->bDescLength = 9; desc->wHubCharacteristics = cpu_to_le16( HUB_CHAR_INDV_PORT_LPSM | -- cgit v0.10.2 From a5dd03950aa8be19b61a802cea8e9edde462d4ea Mon Sep 17 00:00:00 2001 From: Sergei Shtylyov Date: Sun, 29 Mar 2015 01:36:28 +0300 Subject: dwc2: hcd: use USB_DT_HUB Fix using the bare number to set the 'bDescriptorType' field of the Hub Descriptor while the value is #define'd in . Signed-off-by: Sergei Shtylyov Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index 559b55e..6f4acfa 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c @@ -1616,7 +1616,7 @@ static int dwc2_hcd_hub_control(struct dwc2_hsotg *hsotg, u16 typereq, dev_dbg(hsotg->dev, "GetHubDescriptor\n"); hub_desc = (struct usb_hub_descriptor *)buf; hub_desc->bDescLength = 9; - hub_desc->bDescriptorType = 0x29; + hub_desc->bDescriptorType = USB_DT_HUB; hub_desc->bNbrPorts = 1; hub_desc->wHubCharacteristics = cpu_to_le16(HUB_CHAR_COMMON_LPSM | -- cgit v0.10.2 From e27465f51aa40f9826553547f3de25330bfcdeec Mon Sep 17 00:00:00 2001 From: Sergei Shtylyov Date: Sun, 29 Mar 2015 01:34:12 +0300 Subject: c67x00-hcd: use USB_DT_HUB Fix using the bare number to set the 'bDescriptorType' field of the Hub Descriptor while the value is #define'd in . Signed-off-by: Sergei Shtylyov Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/c67x00/c67x00-hcd.c b/drivers/usb/c67x00/c67x00-hcd.c index 20ec4ee..c2d1396 100644 --- a/drivers/usb/c67x00/c67x00-hcd.c +++ b/drivers/usb/c67x00/c67x00-hcd.c @@ -34,7 +34,7 @@ static __u8 c67x00_hub_des[] = { 0x09, /* __u8 bLength; */ - 0x29, /* __u8 bDescriptorType; Hub-descriptor */ + USB_DT_HUB, /* __u8 bDescriptorType; Hub-descriptor */ 0x02, /* __u8 bNbrPorts; */ 0x00, /* __u16 wHubCharacteristics; */ 0x00, /* (per-port OC, no power switching) */ -- cgit v0.10.2 From 3e5dd4c349465066b85a487af6fabd4fc32c7987 Mon Sep 17 00:00:00 2001 From: Sergei Shtylyov Date: Sun, 29 Mar 2015 01:30:04 +0300 Subject: uhci-hub: use USB_DT_HUB Fix using the bare numbers to set the 'bHubCharacteristics' field of the Hub Descriptor while the values are #define'd in . Signed-off-by: Sergei Shtylyov Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/host/uhci-hub.c b/drivers/usb/host/uhci-hub.c index 19ba5ea..a7cc022 100644 --- a/drivers/usb/host/uhci-hub.c +++ b/drivers/usb/host/uhci-hub.c @@ -15,7 +15,7 @@ static const __u8 root_hub_hub_des[] = { 0x09, /* __u8 bLength; */ - 0x29, /* __u8 bDescriptorType; Hub-descriptor */ + USB_DT_HUB, /* __u8 bDescriptorType; Hub-descriptor */ 0x02, /* __u8 bNbrPorts; */ HUB_CHAR_NO_LPSM | /* __u16 wHubCharacteristics; */ HUB_CHAR_INDV_PORT_OCPM, /* (per-port OC, no power switching) */ -- cgit v0.10.2 From 0ce6fe9e1b4666ebccb403e6fa4e8304599d50bd Mon Sep 17 00:00:00 2001 From: Sergei Shtylyov Date: Sun, 29 Mar 2015 01:28:15 +0300 Subject: u132-hcd: use USB_DT_HUB Fix using the bare number to set the 'bDescriptorType' field of the Hub Descriptor while the value is #define'd in . Signed-off-by: Sergei Shtylyov Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/host/u132-hcd.c b/drivers/usb/host/u132-hcd.c index ad97e8a..d516877 100644 --- a/drivers/usb/host/u132-hcd.c +++ b/drivers/usb/host/u132-hcd.c @@ -2584,7 +2584,7 @@ static int u132_roothub_descriptor(struct u132 *u132, retval = u132_read_pcimem(u132, roothub.a, &rh_a); if (retval) return retval; - desc->bDescriptorType = 0x29; + desc->bDescriptorType = USB_DT_HUB; desc->bPwrOn2PwrGood = (rh_a & RH_A_POTPGT) >> 24; desc->bHubContrCurrent = 0; desc->bNbrPorts = u132->num_ports; -- cgit v0.10.2 From e283ef1549f7e9de198d1a8988eff97c9e42f878 Mon Sep 17 00:00:00 2001 From: Sergei Shtylyov Date: Sun, 29 Mar 2015 01:26:55 +0300 Subject: sl811-hcd: use USB_DT_HUB Fix using the bare number to set the 'bDescriptorType' field of the Hub Descriptor while the value is #define'd in . Signed-off-by: Sergei Shtylyov Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c index f1d5c5a1..53e4fb7 100644 --- a/drivers/usb/host/sl811-hcd.c +++ b/drivers/usb/host/sl811-hcd.c @@ -1091,7 +1091,7 @@ sl811h_hub_descriptor ( ) { u16 temp = 0; - desc->bDescriptorType = 0x29; + desc->bDescriptorType = USB_DT_HUB; desc->bHubContrCurrent = 0; desc->bNbrPorts = 1; -- cgit v0.10.2 From 5e77beafb10e451b8370e8248b25207810110ed8 Mon Sep 17 00:00:00 2001 From: Sergei Shtylyov Date: Sun, 29 Mar 2015 01:24:24 +0300 Subject: r8a66597-hcd: use USB_DT_HUB Fix using the bare number to set the 'bDescriptorType' field of the Hub Descriptor while the value is #define'd in . Signed-off-by: Sergei Shtylyov Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/host/r8a66597-hcd.c b/drivers/usb/host/r8a66597-hcd.c index bdc82fe..5cbaa98 100644 --- a/drivers/usb/host/r8a66597-hcd.c +++ b/drivers/usb/host/r8a66597-hcd.c @@ -2136,7 +2136,7 @@ static int r8a66597_hub_status_data(struct usb_hcd *hcd, char *buf) static void r8a66597_hub_descriptor(struct r8a66597 *r8a66597, struct usb_hub_descriptor *desc) { - desc->bDescriptorType = 0x29; + desc->bDescriptorType = USB_DT_HUB; desc->bHubContrCurrent = 0; desc->bNbrPorts = r8a66597->max_root_hub; desc->bDescLength = 9; -- cgit v0.10.2 From 2c42c08774f07824ac689cf198e26ffba7831564 Mon Sep 17 00:00:00 2001 From: Sergei Shtylyov Date: Sun, 29 Mar 2015 01:21:10 +0300 Subject: oxu210hp-hcd: use USB_DT_HUB Fix using the bare number to set the 'bDescriptorType' field of the Hub Descriptor while the value is #define'd in . Signed-off-by: Sergei Shtylyov Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/host/oxu210hp-hcd.c b/drivers/usb/host/oxu210hp-hcd.c index ef7efb2..681ce57 100644 --- a/drivers/usb/host/oxu210hp-hcd.c +++ b/drivers/usb/host/oxu210hp-hcd.c @@ -445,7 +445,7 @@ static void ehci_hub_descriptor(struct oxu_hcd *oxu, int ports = HCS_N_PORTS(oxu->hcs_params); u16 temp; - desc->bDescriptorType = 0x29; + desc->bDescriptorType = USB_DT_HUB; desc->bPwrOn2PwrGood = 10; /* oxu 1.0, 2.3.9 says 20ms max */ desc->bHubContrCurrent = 0; -- cgit v0.10.2 From 7a2d2672b89d402312b4b741544ab5fdcd48df19 Mon Sep 17 00:00:00 2001 From: Sergei Shtylyov Date: Sun, 29 Mar 2015 01:19:48 +0300 Subject: ohci-hub: use USB_DT_HUB Fix using the bare number to set the 'bDescriptorType' field of the Hub Descriptor while the value is #define'd in . Signed-off-by: Sergei Shtylyov Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c index fe2aedd..ed678c17 100644 --- a/drivers/usb/host/ohci-hub.c +++ b/drivers/usb/host/ohci-hub.c @@ -536,7 +536,7 @@ ohci_hub_descriptor ( u32 rh = roothub_a (ohci); u16 temp; - desc->bDescriptorType = 0x29; + desc->bDescriptorType = USB_DT_HUB; desc->bPwrOn2PwrGood = (rh & RH_A_POTPGT) >> 24; desc->bHubContrCurrent = 0; -- cgit v0.10.2 From e3d02e0e54bce76e331529dd6f47d61cecc9d375 Mon Sep 17 00:00:00 2001 From: Sergei Shtylyov Date: Sun, 29 Mar 2015 01:14:03 +0300 Subject: max3421-hcd: use USB_DT_HUB Fix using the bare number to set the 'bDescriptorType' field of the Hub Descriptor while the value is #define'd in . Signed-off-by: Sergei Shtylyov Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/host/max3421-hcd.c b/drivers/usb/host/max3421-hcd.c index a98833c..fc1fd40 100644 --- a/drivers/usb/host/max3421-hcd.c +++ b/drivers/usb/host/max3421-hcd.c @@ -1659,7 +1659,7 @@ hub_descriptor(struct usb_hub_descriptor *desc) /* * See Table 11-13: Hub Descriptor in USB 2.0 spec. */ - desc->bDescriptorType = 0x29; /* hub descriptor */ + desc->bDescriptorType = USB_DT_HUB; /* hub descriptor */ desc->bDescLength = 9; desc->wHubCharacteristics = cpu_to_le16(HUB_CHAR_INDV_PORT_LPSM | HUB_CHAR_COMMON_OCPM); -- cgit v0.10.2 From 00d29b3e9320112c3d53d6865af60492dbc29163 Mon Sep 17 00:00:00 2001 From: Sergei Shtylyov Date: Sun, 29 Mar 2015 01:12:31 +0300 Subject: isp1362-hcd: use USB_DT_HUB Fix using the bare number to set the 'bDescriptorType' field of the Hub Descriptor while the value is #define'd in . Signed-off-by: Sergei Shtylyov Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/host/isp1362-hcd.c b/drivers/usb/host/isp1362-hcd.c index b32ab60..6cf82ee 100644 --- a/drivers/usb/host/isp1362-hcd.c +++ b/drivers/usb/host/isp1362-hcd.c @@ -1538,7 +1538,7 @@ static void isp1362_hub_descriptor(struct isp1362_hcd *isp1362_hcd, DBG(3, "%s: enter\n", __func__); - desc->bDescriptorType = 0x29; + desc->bDescriptorType = USB_DT_HUB; desc->bDescLength = 9; desc->bHubContrCurrent = 0; desc->bNbrPorts = reg & 0x3; -- cgit v0.10.2 From 6a0855673ea81f436625ff0e471e990e503232c9 Mon Sep 17 00:00:00 2001 From: Sergei Shtylyov Date: Sun, 29 Mar 2015 01:10:43 +0300 Subject: isp116x-hcd: use USB_DT_HUB Fix using the bare number to set the 'bDescriptorType' field of the Hub Descriptor while the value is #define'd in . Signed-off-by: Sergei Shtylyov Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c index 113d0cc..aa335fa 100644 --- a/drivers/usb/host/isp116x-hcd.c +++ b/drivers/usb/host/isp116x-hcd.c @@ -943,7 +943,7 @@ static void isp116x_hub_descriptor(struct isp116x *isp116x, { u32 reg = isp116x->rhdesca; - desc->bDescriptorType = 0x29; + desc->bDescriptorType = USB_DT_HUB; desc->bDescLength = 9; desc->bHubContrCurrent = 0; desc->bNbrPorts = (u8) (reg & 0x3); -- cgit v0.10.2 From 72cce8cb05bfe9ff545520606e51651adb1bac33 Mon Sep 17 00:00:00 2001 From: Sergei Shtylyov Date: Sun, 29 Mar 2015 01:09:06 +0300 Subject: imx21-hcd: use USB_DT_HUB Fix using the bare number to set the 'bDescriptorType' field of the Hub Descriptor while the value is #define'd in . Signed-off-by: Sergei Shtylyov Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/host/imx21-hcd.c b/drivers/usb/host/imx21-hcd.c index 6a2ad55..f542045 100644 --- a/drivers/usb/host/imx21-hcd.c +++ b/drivers/usb/host/imx21-hcd.c @@ -1474,7 +1474,7 @@ static int get_hub_descriptor(struct usb_hcd *hcd, struct usb_hub_descriptor *desc) { struct imx21 *imx21 = hcd_to_imx21(hcd); - desc->bDescriptorType = 0x29; /* HUB descriptor */ + desc->bDescriptorType = USB_DT_HUB; /* HUB descriptor */ desc->bHubContrCurrent = 0; desc->bNbrPorts = readl(imx21->regs + USBH_ROOTHUBA) -- cgit v0.10.2 From 87327b14621a10f0382c49ac181de7aaa5c2c88a Mon Sep 17 00:00:00 2001 From: Sergei Shtylyov Date: Sun, 29 Mar 2015 01:07:43 +0300 Subject: fusbh200-hcd: use USB_DT_HUB Fix using the bare number to set the 'bDescriptorType' field of the Hub Descriptor while the value is #define'd in . Signed-off-by: Sergei Shtylyov Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/host/fusbh200-hcd.c b/drivers/usb/host/fusbh200-hcd.c index a83eefe..eb39a45 100644 --- a/drivers/usb/host/fusbh200-hcd.c +++ b/drivers/usb/host/fusbh200-hcd.c @@ -1467,7 +1467,7 @@ fusbh200_hub_descriptor ( int ports = HCS_N_PORTS (fusbh200->hcs_params); u16 temp; - desc->bDescriptorType = 0x29; + desc->bDescriptorType = USB_DT_HUB; desc->bPwrOn2PwrGood = 10; /* fusbh200 1.0, 2.3.9 says 20ms max */ desc->bHubContrCurrent = 0; -- cgit v0.10.2 From 4631f4e9856efc296c1e80bcd69b3375d75bf834 Mon Sep 17 00:00:00 2001 From: Sergei Shtylyov Date: Sun, 29 Mar 2015 01:06:21 +0300 Subject: fotg210-hcd: use USB_DT_HUB Fix using the bare number to set the 'bDescriptorType' field of the Hub Descriptor while the value is #define'd in . Signed-off-by: Sergei Shtylyov Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/host/fotg210-hcd.c b/drivers/usb/host/fotg210-hcd.c index 475b21f..af08ff1 100644 --- a/drivers/usb/host/fotg210-hcd.c +++ b/drivers/usb/host/fotg210-hcd.c @@ -1509,7 +1509,7 @@ fotg210_hub_descriptor( int ports = HCS_N_PORTS(fotg210->hcs_params); u16 temp; - desc->bDescriptorType = 0x29; + desc->bDescriptorType = USB_DT_HUB; desc->bPwrOn2PwrGood = 10; /* fotg210 1.0, 2.3.9 says 20ms max */ desc->bHubContrCurrent = 0; -- cgit v0.10.2 From 51a114bc5d20d6540418bc40422a9631cfa73da8 Mon Sep 17 00:00:00 2001 From: Sergei Shtylyov Date: Sun, 29 Mar 2015 01:04:50 +0300 Subject: fhci-hub: use USB_DT_HUB Fix using the bare number to set the 'bDescriptorType' field of the Hub Descriptor while the value is #define'd in . Signed-off-by: Sergei Shtylyov Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/host/fhci-hub.c b/drivers/usb/host/fhci-hub.c index 70116a6..3bacdd7 100644 --- a/drivers/usb/host/fhci-hub.c +++ b/drivers/usb/host/fhci-hub.c @@ -30,7 +30,7 @@ /* virtual root hub specific descriptor */ static u8 root_hub_des[] = { 0x09, /* blength */ - 0x29, /* bDescriptorType;hub-descriptor */ + USB_DT_HUB, /* bDescriptorType;hub-descriptor */ 0x01, /* bNbrPorts */ HUB_CHAR_INDV_PORT_LPSM | HUB_CHAR_NO_OCPM, /* wHubCharacteristics */ 0x00, /* per-port power, no overcurrent */ -- cgit v0.10.2 From 625a4c5910cc8aa63da2afcf662aeb2ca64458e1 Mon Sep 17 00:00:00 2001 From: Sergei Shtylyov Date: Sun, 29 Mar 2015 01:03:03 +0300 Subject: ehci-hub: use USB_DT_HUB Fix using the bare number to set the 'bDescriptorType' field of the Hub Descriptor while the value is #define'd in . Signed-off-by: Sergei Shtylyov Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c index 87cf86f..d7b4b51 100644 --- a/drivers/usb/host/ehci-hub.c +++ b/drivers/usb/host/ehci-hub.c @@ -688,7 +688,7 @@ ehci_hub_descriptor ( int ports = HCS_N_PORTS (ehci->hcs_params); u16 temp; - desc->bDescriptorType = 0x29; + desc->bDescriptorType = USB_DT_HUB; desc->bPwrOn2PwrGood = 10; /* ehci 1.0, 2.3.9 says 20ms max */ desc->bHubContrCurrent = 0; -- cgit v0.10.2 From d30323f810e4da94eb75cf4bfe5165b9518c64df Mon Sep 17 00:00:00 2001 From: Tony Lindgren Date: Wed, 25 Mar 2015 14:18:37 -0700 Subject: usb: musb: dsps: fix build on i386 when COMPILE_TEST is set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit 3e457371f436 ("usb: musb: Fix fifo reads for dm816x with musb_dsps") fixed a USB error on dm816x, but introduced a new build error on i386 when COMPILE_TEST is set: drivers/usb/musb/musb_dsps.c: In function ‘dsps_read_fifo32’: drivers/usb/musb/musb_dsps.c:624:3: error: implicit declaration of function ‘readsl’ [-Werror=implicit-function-declaration] readsl(fifo, dst, len >> 2); Let's fix this by using ioread32_rep() instead of readsl() as that's more portable. Fixes: 3e457371f436 ("usb: musb: Fix fifo reads for dm816x with musb_dsps") Reported-by: Fengguang Wu Cc: Bin Liu Cc: Brian Hutchinson Cc: George Cherian Cc: Sergei Shtylyov Signed-off-by: Tony Lindgren Signed-off-by: Felipe Balbi Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c index b23ad15..65d931a 100644 --- a/drivers/usb/musb/musb_dsps.c +++ b/drivers/usb/musb/musb_dsps.c @@ -621,7 +621,7 @@ static void dsps_read_fifo32(struct musb_hw_ep *hw_ep, u16 len, u8 *dst) void __iomem *fifo = hw_ep->fifo; if (len >= 4) { - readsl(fifo, dst, len >> 2); + ioread32_rep(fifo, dst, len >> 2); dst += len & ~0x03; len &= 0x03; } -- cgit v0.10.2 From 62f0342de1f012f3e90607d39e20fce811391169 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Fri, 13 Feb 2015 14:34:25 -0600 Subject: usb: define a generic USB_RESUME_TIMEOUT macro Every USB Host controller should use this new macro to define for how long resume signalling should be driven on the bus. Currently, almost every single USB controller is using a 20ms timeout for resume signalling. That's problematic for two reasons: a) sometimes that 20ms timer expires a little before 20ms, which makes us fail certification b) some (many) devices actually need more than 20ms resume signalling. Sure, in case of (b) we can state that the device is against the USB spec, but the fact is that we have no control over which device the certification lab will use. We also have no control over which host they will use. Most likely they'll be using a Windows PC which, again, we have no control over how that USB stack is written and how long resume signalling they are using. At the end of the day, we must make sure Linux passes electrical compliance when working as Host or as Device and currently we don't pass compliance as host because we're driving resume signallig for exactly 20ms and that confuses certification test setup resulting in Certification failure. Cc: # v3.10+ Acked-by: Greg Kroah-Hartman Acked-by: Peter Chen Signed-off-by: Felipe Balbi diff --git a/include/linux/usb.h b/include/linux/usb.h index 7ee1b5c..447fe29 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -205,6 +205,32 @@ void usb_put_intf(struct usb_interface *intf); #define USB_MAXINTERFACES 32 #define USB_MAXIADS (USB_MAXINTERFACES/2) +/* + * USB Resume Timer: Every Host controller driver should drive the resume + * signalling on the bus for the amount of time defined by this macro. + * + * That way we will have a 'stable' behavior among all HCDs supported by Linux. + * + * Note that the USB Specification states we should drive resume for *at least* + * 20 ms, but it doesn't give an upper bound. This creates two possible + * situations which we want to avoid: + * + * (a) sometimes an msleep(20) might expire slightly before 20 ms, which causes + * us to fail USB Electrical Tests, thus failing Certification + * + * (b) Some (many) devices actually need more than 20 ms of resume signalling, + * and while we can argue that's against the USB Specification, we don't have + * control over which devices a certification laboratory will be using for + * certification. If CertLab uses a device which was tested against Windows and + * that happens to have relaxed resume signalling rules, we might fall into + * situations where we fail interoperability and electrical tests. + * + * In order to avoid both conditions, we're using a 40 ms resume timeout, which + * should cope with both LPJ calibration errors and devices not following every + * detail of the USB Specification. + */ +#define USB_RESUME_TIMEOUT 40 /* ms */ + /** * struct usb_interface_cache - long-term representation of a device interface * @num_altsetting: number of altsettings defined. -- cgit v0.10.2 From b9e451885deb6262dbaf5cd14aa77d192d9ac759 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Fri, 13 Feb 2015 14:39:13 -0600 Subject: usb: host: xhci: use new USB_RESUME_TIMEOUT Make sure we're using the new macro, so our resume signaling will always pass certification. Cc: # v3.10+ Acked-by: Mathias Nyman Signed-off-by: Felipe Balbi diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 5fb66db..2330481 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -1574,7 +1574,7 @@ static void handle_port_status(struct xhci_hcd *xhci, } else { xhci_dbg(xhci, "resume HS port %d\n", port_id); bus_state->resume_done[faked_port_index] = jiffies + - msecs_to_jiffies(20); + msecs_to_jiffies(USB_RESUME_TIMEOUT); set_bit(faked_port_index, &bus_state->resuming_ports); mod_timer(&hcd->rh_timer, bus_state->resume_done[faked_port_index]); -- cgit v0.10.2 From ea16328f80ca8d74434352157f37ef60e2f55ce2 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Fri, 13 Feb 2015 14:42:25 -0600 Subject: usb: host: ehci: use new USB_RESUME_TIMEOUT Make sure we're using the new macro, so our resume signaling will always pass certification. Cc: # v3.10+ Signed-off-by: Felipe Balbi diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c index 85e56d1..f4d88df 100644 --- a/drivers/usb/host/ehci-hcd.c +++ b/drivers/usb/host/ehci-hcd.c @@ -792,12 +792,12 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd) ehci->reset_done[i] == 0)) continue; - /* start 20 msec resume signaling from this port, - * and make hub_wq collect PORT_STAT_C_SUSPEND to - * stop that signaling. Use 5 ms extra for safety, - * like usb_port_resume() does. + /* start USB_RESUME_TIMEOUT msec resume signaling from + * this port, and make hub_wq collect + * PORT_STAT_C_SUSPEND to stop that signaling. */ - ehci->reset_done[i] = jiffies + msecs_to_jiffies(25); + ehci->reset_done[i] = jiffies + + msecs_to_jiffies(USB_RESUME_TIMEOUT); set_bit(i, &ehci->resuming_ports); ehci_dbg (ehci, "port %d remote wakeup\n", i + 1); usb_hcd_start_port_resume(&hcd->self, i); diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c index 87cf86f..7354d01 100644 --- a/drivers/usb/host/ehci-hub.c +++ b/drivers/usb/host/ehci-hub.c @@ -471,10 +471,13 @@ static int ehci_bus_resume (struct usb_hcd *hcd) ehci_writel(ehci, temp, &ehci->regs->port_status [i]); } - /* msleep for 20ms only if code is trying to resume port */ + /* + * msleep for USB_RESUME_TIMEOUT ms only if code is trying to resume + * port + */ if (resume_needed) { spin_unlock_irq(&ehci->lock); - msleep(20); + msleep(USB_RESUME_TIMEOUT); spin_lock_irq(&ehci->lock); if (ehci->shutdown) goto shutdown; @@ -942,7 +945,7 @@ int ehci_hub_control( temp &= ~PORT_WAKE_BITS; ehci_writel(ehci, temp | PORT_RESUME, status_reg); ehci->reset_done[wIndex] = jiffies - + msecs_to_jiffies(20); + + msecs_to_jiffies(USB_RESUME_TIMEOUT); set_bit(wIndex, &ehci->resuming_ports); usb_hcd_start_port_resume(&hcd->self, wIndex); break; -- cgit v0.10.2 From b8fb6f79f76f478acbbffccc966daa878f172a0a Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Fri, 13 Feb 2015 14:44:17 -0600 Subject: usb: host: uhci: use new USB_RESUME_TIMEOUT Make sure we're using the new macro, so our resume signaling will always pass certification. Cc: # v3.10+ Signed-off-by: Felipe Balbi diff --git a/drivers/usb/host/uhci-hub.c b/drivers/usb/host/uhci-hub.c index 19ba5ea..7b3d1af 100644 --- a/drivers/usb/host/uhci-hub.c +++ b/drivers/usb/host/uhci-hub.c @@ -166,7 +166,7 @@ static void uhci_check_ports(struct uhci_hcd *uhci) /* Port received a wakeup request */ set_bit(port, &uhci->resuming_ports); uhci->ports_timeout = jiffies + - msecs_to_jiffies(25); + msecs_to_jiffies(USB_RESUME_TIMEOUT); usb_hcd_start_port_resume( &uhci_to_hcd(uhci)->self, port); @@ -338,7 +338,8 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, uhci_finish_suspend(uhci, port, port_addr); /* USB v2.0 7.1.7.5 */ - uhci->ports_timeout = jiffies + msecs_to_jiffies(50); + uhci->ports_timeout = jiffies + + msecs_to_jiffies(USB_RESUME_TIMEOUT); break; case USB_PORT_FEAT_POWER: /* UHCI has no power switching */ -- cgit v0.10.2 From 309be239369609929d5d3833ee043f7c5afc95d1 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Fri, 13 Feb 2015 14:46:27 -0600 Subject: usb: musb: use new USB_RESUME_TIMEOUT Make sure we're using the new macro, so our resume signaling will always pass certification. Based on original work by Bin Liu > Cc: Bin Liu Cc: # v3.10+ Signed-off-by: Felipe Balbi diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index a48b5a9..3789b08 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c @@ -99,6 +99,7 @@ #include #include #include +#include #include "musb_core.h" @@ -549,7 +550,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, (USB_PORT_STAT_C_SUSPEND << 16) | MUSB_PORT_STAT_RESUME; musb->rh_timer = jiffies - + msecs_to_jiffies(20); + + msecs_to_jiffies(USB_RESUME_TIMEOUT); musb->need_finish_resume = 1; musb->xceiv->otg->state = OTG_STATE_A_HOST; @@ -2463,7 +2464,7 @@ static int musb_resume(struct device *dev) if (musb->need_finish_resume) { musb->need_finish_resume = 0; schedule_delayed_work(&musb->finish_resume_work, - msecs_to_jiffies(20)); + msecs_to_jiffies(USB_RESUME_TIMEOUT)); } /* @@ -2506,7 +2507,7 @@ static int musb_runtime_resume(struct device *dev) if (musb->need_finish_resume) { musb->need_finish_resume = 0; schedule_delayed_work(&musb->finish_resume_work, - msecs_to_jiffies(20)); + msecs_to_jiffies(USB_RESUME_TIMEOUT)); } return 0; diff --git a/drivers/usb/musb/musb_virthub.c b/drivers/usb/musb/musb_virthub.c index 294e159..5428ed1 100644 --- a/drivers/usb/musb/musb_virthub.c +++ b/drivers/usb/musb/musb_virthub.c @@ -136,7 +136,7 @@ void musb_port_suspend(struct musb *musb, bool do_suspend) /* later, GetPortStatus will stop RESUME signaling */ musb->port1_status |= MUSB_PORT_STAT_RESUME; schedule_delayed_work(&musb->finish_resume_work, - msecs_to_jiffies(20)); + msecs_to_jiffies(USB_RESUME_TIMEOUT)); } } -- cgit v0.10.2 From 8c0ae6574ccfd3d619876a65829aad74c9d22ba5 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Fri, 13 Feb 2015 14:50:10 -0600 Subject: usb: host: isp116x: use new USB_RESUME_TIMEOUT Make sure we're using the new macro, so our resume signaling will always pass certification. Cc: # v3.10+ Signed-off-by: Felipe Balbi diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c index 113d0cc..9ef5644 100644 --- a/drivers/usb/host/isp116x-hcd.c +++ b/drivers/usb/host/isp116x-hcd.c @@ -1490,7 +1490,7 @@ static int isp116x_bus_resume(struct usb_hcd *hcd) spin_unlock_irq(&isp116x->lock); hcd->state = HC_STATE_RESUMING; - msleep(20); + msleep(USB_RESUME_TIMEOUT); /* Go operational */ spin_lock_irq(&isp116x->lock); -- cgit v0.10.2 From 7e136bb71a08e8b8be3bc492f041d9b0bea3856d Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Fri, 13 Feb 2015 14:54:38 -0600 Subject: usb: host: fotg210: use new USB_RESUME_TIMEOUT Make sure we're using the new macro, so our resume signaling will always pass certification. Cc: # v3.10+ Signed-off-by: Felipe Balbi diff --git a/drivers/usb/host/fotg210-hcd.c b/drivers/usb/host/fotg210-hcd.c index 475b21f..7a6681f 100644 --- a/drivers/usb/host/fotg210-hcd.c +++ b/drivers/usb/host/fotg210-hcd.c @@ -1595,7 +1595,7 @@ static int fotg210_hub_control( /* resume signaling for 20 msec */ fotg210_writel(fotg210, temp | PORT_RESUME, status_reg); fotg210->reset_done[wIndex] = jiffies - + msecs_to_jiffies(20); + + msecs_to_jiffies(USB_RESUME_TIMEOUT); break; case USB_PORT_FEAT_C_SUSPEND: clear_bit(wIndex, &fotg210->port_c_suspend); -- cgit v0.10.2 From 595227db1f2d98bfc33f02a55842f268e12b247d Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Fri, 13 Feb 2015 14:55:34 -0600 Subject: usb: host: fusbh200: use new USB_RESUME_TIMEOUT Make sure we're using the new macro, so our resume signaling will always pass certification. Cc: # v3.10+ Signed-off-by: Felipe Balbi diff --git a/drivers/usb/host/fusbh200-hcd.c b/drivers/usb/host/fusbh200-hcd.c index a83eefe..ba77e2e 100644 --- a/drivers/usb/host/fusbh200-hcd.c +++ b/drivers/usb/host/fusbh200-hcd.c @@ -1550,10 +1550,9 @@ static int fusbh200_hub_control ( if ((temp & PORT_PE) == 0) goto error; - /* resume signaling for 20 msec */ fusbh200_writel(fusbh200, temp | PORT_RESUME, status_reg); fusbh200->reset_done[wIndex] = jiffies - + msecs_to_jiffies(20); + + msecs_to_jiffies(USB_RESUME_TIMEOUT); break; case USB_PORT_FEAT_C_SUSPEND: clear_bit(wIndex, &fusbh200->port_c_suspend); -- cgit v0.10.2 From 84c0d178eb9f3a3ae4d63dc97a440266cf17f7f5 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Fri, 13 Feb 2015 14:57:54 -0600 Subject: usb: host: oxu210hp: use new USB_RESUME_TIMEOUT Make sure we're using the new macro, so our resume signaling will always pass certification. Cc: # v3.10+ Signed-off-by: Felipe Balbi diff --git a/drivers/usb/host/oxu210hp-hcd.c b/drivers/usb/host/oxu210hp-hcd.c index ef7efb2..28a2866 100644 --- a/drivers/usb/host/oxu210hp-hcd.c +++ b/drivers/usb/host/oxu210hp-hcd.c @@ -2500,11 +2500,12 @@ static irqreturn_t oxu210_hcd_irq(struct usb_hcd *hcd) || oxu->reset_done[i] != 0) continue; - /* start 20 msec resume signaling from this port, - * and make hub_wq collect PORT_STAT_C_SUSPEND to + /* start USB_RESUME_TIMEOUT resume signaling from this + * port, and make hub_wq collect PORT_STAT_C_SUSPEND to * stop that signaling. */ - oxu->reset_done[i] = jiffies + msecs_to_jiffies(20); + oxu->reset_done[i] = jiffies + + msecs_to_jiffies(USB_RESUME_TIMEOUT); oxu_dbg(oxu, "port %d remote wakeup\n", i + 1); mod_timer(&hcd->rh_timer, oxu->reset_done[i]); } -- cgit v0.10.2 From 7a606ac29752a3e571b83f9b3fceb1eaa1d37781 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Fri, 13 Feb 2015 14:58:53 -0600 Subject: usb: host: r8a66597: use new USB_RESUME_TIMEOUT While this driver was already using a 50ms resume timeout, let's make sure everybody uses the same macro so it's easy to fix later should anything go wrong. It also gives a more "stable" expectation to Linux users. Cc: # v3.10+ Signed-off-by: Felipe Balbi diff --git a/drivers/usb/host/r8a66597-hcd.c b/drivers/usb/host/r8a66597-hcd.c index bdc82fe..54a4170 100644 --- a/drivers/usb/host/r8a66597-hcd.c +++ b/drivers/usb/host/r8a66597-hcd.c @@ -2301,7 +2301,7 @@ static int r8a66597_bus_resume(struct usb_hcd *hcd) rh->port &= ~USB_PORT_STAT_SUSPEND; rh->port |= USB_PORT_STAT_C_SUSPEND << 16; r8a66597_mdfy(r8a66597, RESUME, RESUME | UACT, dvstctr_reg); - msleep(50); + msleep(USB_RESUME_TIMEOUT); r8a66597_mdfy(r8a66597, UACT, RESUME | UACT, dvstctr_reg); } -- cgit v0.10.2 From 08debfb13b199716da6153940c31968c556b195d Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Fri, 13 Feb 2015 15:00:38 -0600 Subject: usb: host: sl811: use new USB_RESUME_TIMEOUT Make sure we're using the new macro, so our resume signaling will always pass certification. Cc: # v3.10+ Signed-off-by: Felipe Balbi diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c index 4f4ba1e..9118cd8 100644 --- a/drivers/usb/host/sl811-hcd.c +++ b/drivers/usb/host/sl811-hcd.c @@ -1259,7 +1259,7 @@ sl811h_hub_control( sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1); mod_timer(&sl811->timer, jiffies - + msecs_to_jiffies(20)); + + msecs_to_jiffies(USB_RESUME_TIMEOUT)); break; case USB_PORT_FEAT_POWER: port_power(sl811, 0); -- cgit v0.10.2 From 74bd7b69801819707713b88e9d0bc074efa2f5e7 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Fri, 13 Feb 2015 15:03:13 -0600 Subject: usb: dwc2: hcd: use new USB_RESUME_TIMEOUT Make sure we're using the new macro, so our resume signaling will always pass certification. Cc: # v3.10+ Signed-off-by: Felipe Balbi diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index 559b55e..545e094 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c @@ -1529,7 +1529,7 @@ static int dwc2_hcd_hub_control(struct dwc2_hsotg *hsotg, u16 typereq, dev_dbg(hsotg->dev, "ClearPortFeature USB_PORT_FEAT_SUSPEND\n"); writel(0, hsotg->regs + PCGCTL); - usleep_range(20000, 40000); + msleep(USB_RESUME_TIMEOUT); hprt0 = dwc2_read_hprt0(hsotg); hprt0 |= HPRT0_RES; -- cgit v0.10.2 From 59c9904cce77b55892e15f40791f1e66e4d3a1e6 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Fri, 13 Feb 2015 15:04:06 -0600 Subject: usb: isp1760: hcd: use new USB_RESUME_TIMEOUT Make sure we're using the new macro, so our resume signaling will always pass certification. Cc: # v3.10+ Signed-off-by: Felipe Balbi diff --git a/drivers/usb/isp1760/isp1760-hcd.c b/drivers/usb/isp1760/isp1760-hcd.c index 3cb98b1..7911b6b 100644 --- a/drivers/usb/isp1760/isp1760-hcd.c +++ b/drivers/usb/isp1760/isp1760-hcd.c @@ -1869,7 +1869,7 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq, reg_write32(hcd->regs, HC_PORTSC1, temp | PORT_RESUME); priv->reset_done = jiffies + - msecs_to_jiffies(20); + msecs_to_jiffies(USB_RESUME_TIMEOUT); } break; case USB_PORT_FEAT_C_SUSPEND: -- cgit v0.10.2 From bbc78c07a51f6fd29c227b1220a9016e585358ba Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Fri, 13 Feb 2015 15:38:33 -0600 Subject: usb: core: hub: use new USB_RESUME_TIMEOUT Make sure we're using the new macro, so our resume signaling will always pass certification. Cc: # v3.10+ Signed-off-by: Felipe Balbi diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index d7c3d5a..3b71516 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -3406,10 +3406,10 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg) if (status) { dev_dbg(&port_dev->dev, "can't resume, status %d\n", status); } else { - /* drive resume for at least 20 msec */ + /* drive resume for USB_RESUME_TIMEOUT msec */ dev_dbg(&udev->dev, "usb %sresume\n", (PMSG_IS_AUTO(msg) ? "auto-" : "")); - msleep(25); + msleep(USB_RESUME_TIMEOUT); /* Virtual root hubs can trigger on GET_PORT_STATUS to * stop resume signaling. Then finish the resume -- cgit v0.10.2 From 9b6567e19bc55187bc1bb094b00a9f63acb30071 Mon Sep 17 00:00:00 2001 From: Li Jun Date: Mon, 23 Mar 2015 16:03:35 +0800 Subject: usb: chipidea: udc: bypass pullup DP when gadget connect in OTG fsm mode By pass pullup DP in OTG fsm mode when do gadget connect, to let it handled by OTG state machine. This patch can fix the problem you found with my HNP polling patchset after below 3 patches introduced: 467a78c usb: chipidea: udc: apply new usb_udc_vbus_handler interface 628ef0d usb: udc: add usb_udc_vbus_handler dfea9c9 usb: udc: store usb_udc pointer in struct usb_gadget Problem: - Connect USB cable and MicroAB cable between two boards - Boot up two boards - load g_mass_storage at B-device side, the enumeration will success, and A will see a usb mass-storage device - load g_mass_storage at A-device side, the problem has occurred, the connection will be lost at the beginning, then connect again. This patch is based on commit eff933c1d3a2e046492b3dfc86db813856553a29 (chipidea: pci: make it depends on NOP_USB_XCEIV) on branch peter-usb-dev of git://git.kernel.org/pub/scm/linux/kernel/git/peter.chen/usb.git Signed-off-by: Li Jun Signed-off-by: Peter Chen diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c index 41914a5..764f668 100644 --- a/drivers/usb/chipidea/udc.c +++ b/drivers/usb/chipidea/udc.c @@ -1574,6 +1574,10 @@ static int ci_udc_pullup(struct usb_gadget *_gadget, int is_on) { struct ci_hdrc *ci = container_of(_gadget, struct ci_hdrc, gadget); + /* Data+ pullup controlled by OTG state machine in OTG fsm mode */ + if (ci_otg_is_fsm_mode(ci)) + return 0; + pm_runtime_get_sync(&ci->gadget.dev); if (is_on) hw_write(ci, OP_USBCMD, USBCMD_RS, USBCMD_RS); -- cgit v0.10.2 From 0c4d6af42d8375e003f0e4626f2f661862b5df4b Mon Sep 17 00:00:00 2001 From: Li Jun Date: Fri, 27 Mar 2015 19:43:01 +0800 Subject: usb: chipidea: debug: add low power mode check before print registers Since the required clock to access registers is gated off in low power mode, add ci->in_lpm check before try to dump registers value. Signed-off-by: Li Jun Signed-off-by: Peter Chen diff --git a/drivers/usb/chipidea/debug.c b/drivers/usb/chipidea/debug.c index 268e423..dfb05ed 100644 --- a/drivers/usb/chipidea/debug.c +++ b/drivers/usb/chipidea/debug.c @@ -336,8 +336,8 @@ static int ci_registers_show(struct seq_file *s, void *unused) struct ci_hdrc *ci = s->private; u32 tmp_reg; - if (!ci) - return 0; + if (!ci || ci->in_lpm) + return -EPERM; /* ------ Registers ----- */ tmp_reg = hw_read_intr_enable(ci); -- cgit v0.10.2 From 42a6630a875c17b8ad129d2cc0472217107147ad Mon Sep 17 00:00:00 2001 From: Gregory Herrero Date: Fri, 3 Apr 2015 10:53:25 +0200 Subject: usb: dwc2: host: sleep USB_RESUME_TIMEOUT during resume msleep(USB_RESUME_TIMEOUT) must be done when the controller drives the resume. This is true after HPRT0_RES is written. Moreover, restore the delay after controller power is up. Signed-off-by: Gregory Herrero Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index 93bd4a1..fbbbac2 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c @@ -1529,13 +1529,13 @@ static int dwc2_hcd_hub_control(struct dwc2_hsotg *hsotg, u16 typereq, dev_dbg(hsotg->dev, "ClearPortFeature USB_PORT_FEAT_SUSPEND\n"); writel(0, hsotg->regs + PCGCTL); - msleep(USB_RESUME_TIMEOUT); + usleep_range(20000, 40000); hprt0 = dwc2_read_hprt0(hsotg); hprt0 |= HPRT0_RES; writel(hprt0, hsotg->regs + HPRT0); hprt0 &= ~HPRT0_SUSP; - usleep_range(100000, 150000); + msleep(USB_RESUME_TIMEOUT); hprt0 &= ~HPRT0_RES; writel(hprt0, hsotg->regs + HPRT0); -- cgit v0.10.2 From 00fe52deb45b1a5ef42b0aa82e632e2df012eddc Mon Sep 17 00:00:00 2001 From: Chase Metzger Date: Thu, 9 Apr 2015 21:41:52 -0700 Subject: drivers/usb/core: devio.c: Removed an uneeded space before tab Ran checkpatch.pl on file and removed a warning about an unwanted space before a tab. Signed-off-by: Chase Metzger Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c index 1163553..4b0448c 100644 --- a/drivers/usb/core/devio.c +++ b/drivers/usb/core/devio.c @@ -2408,7 +2408,7 @@ static int usbdev_notify(struct notifier_block *self, } static struct notifier_block usbdev_nb = { - .notifier_call = usbdev_notify, + .notifier_call = usbdev_notify, }; static struct cdev usb_device_cdev; -- cgit v0.10.2