From e4e5b136eb6f2d3aa10dca108a1b787dc92d67df Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Mon, 27 Jun 2011 15:57:46 +0300 Subject: usb: musb: be careful when using different fifo_modes if we have more endpoints configured than enabled on fifo_mode, then we need to be careful on save/restore context operations, otherwise we will try to access uninitialized __iomem pointer. Signed-off-by: Felipe Balbi Signed-off-by: Greg Kroah-Hartman --- drivers/usb/musb/musb_core.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'drivers/usb/musb/musb_core.c') diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index c71b037..b1faed7 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c @@ -2214,7 +2214,16 @@ static void musb_save_context(struct musb *musb) musb->context.devctl = musb_readb(musb_base, MUSB_DEVCTL); for (i = 0; i < musb->config->num_eps; ++i) { - epio = musb->endpoints[i].regs; + struct musb_hw_ep *hw_ep; + + hw_ep = &musb->endpoints[i]; + if (!hw_ep) + continue; + + epio = hw_ep->regs; + if (!epio) + continue; + musb->context.index_regs[i].txmaxp = musb_readw(epio, MUSB_TXMAXP); musb->context.index_regs[i].txcsr = @@ -2280,7 +2289,16 @@ static void musb_restore_context(struct musb *musb) musb_writeb(musb_base, MUSB_DEVCTL, musb->context.devctl); for (i = 0; i < musb->config->num_eps; ++i) { - epio = musb->endpoints[i].regs; + struct musb_hw_ep *hw_ep; + + hw_ep = &musb->endpoints[i]; + if (!hw_ep) + continue; + + epio = hw_ep->regs; + if (!epio) + continue; + musb_writew(epio, MUSB_TXMAXP, musb->context.index_regs[i].txmaxp); musb_writew(epio, MUSB_TXCSR, -- cgit v1.1 From 622859634a663c5e55d0e2a2cdbb55ac058d97b3 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Wed, 22 Jun 2011 17:28:09 +0300 Subject: usb: musb: drop a gigantic amount of ifdeferry the MUSB IP is always OTG, so there's no point in adding so many ifdefs on the code. Drop those and always compile the driver for OTG support. This also allows us to drop the useless "driver mode" choice. For doing that, we need to make musb depend on both Host and Peripheral side. Signed-off-by: Felipe Balbi Signed-off-by: Greg Kroah-Hartman --- drivers/usb/musb/musb_core.c | 86 +------------------------------------------- 1 file changed, 1 insertion(+), 85 deletions(-) (limited to 'drivers/usb/musb/musb_core.c') diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index b1faed7..7ab9497 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c @@ -328,8 +328,6 @@ void musb_load_testpacket(struct musb *musb) /*-------------------------------------------------------------------------*/ -#ifdef CONFIG_USB_MUSB_OTG - /* * Handles OTG hnp timeouts, such as b_ase0_brst */ @@ -401,8 +399,6 @@ void musb_hnp_stop(struct musb *musb) musb->port1_status &= ~(USB_PORT_STAT_C_CONNECTION << 16); } -#endif - /* * Interrupt Service Routine to record USB "global" interrupts. * Since these do not happen often and signify things of @@ -432,7 +428,6 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, dev_dbg(musb->controller, "RESUME (%s)\n", otg_state_string(musb->xceiv->state)); if (devctl & MUSB_DEVCTL_HM) { -#ifdef CONFIG_USB_MUSB_HDRC_HCD void __iomem *mbase = musb->mregs; switch (musb->xceiv->state) { @@ -472,17 +467,13 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, "host", otg_state_string(musb->xceiv->state)); } -#endif } else { switch (musb->xceiv->state) { -#ifdef CONFIG_USB_MUSB_HDRC_HCD case OTG_STATE_A_SUSPEND: /* possibly DISCONNECT is upcoming */ musb->xceiv->state = OTG_STATE_A_HOST; usb_hcd_resume_root_hub(musb_to_hcd(musb)); break; -#endif -#ifdef CONFIG_USB_GADGET_MUSB_HDRC case OTG_STATE_B_WAIT_ACON: case OTG_STATE_B_PERIPHERAL: /* disconnect while suspended? we may @@ -500,7 +491,6 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, case OTG_STATE_B_IDLE: musb->int_usb &= ~MUSB_INTR_SUSPEND; break; -#endif default: WARNING("bogus %s RESUME (%s)\n", "peripheral", @@ -509,7 +499,6 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, } } -#ifdef CONFIG_USB_MUSB_HDRC_HCD /* see manual for the order of the tests */ if (int_usb & MUSB_INTR_SESSREQ) { void __iomem *mbase = musb->mregs; @@ -609,14 +598,12 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, handled = IRQ_HANDLED; } -#endif if (int_usb & MUSB_INTR_SUSPEND) { dev_dbg(musb->controller, "SUSPEND (%s) devctl %02x power %02x\n", otg_state_string(musb->xceiv->state), devctl, power); handled = IRQ_HANDLED; switch (musb->xceiv->state) { -#ifdef CONFIG_USB_MUSB_OTG case OTG_STATE_A_PERIPHERAL: /* We also come here if the cable is removed, since * this silicon doesn't report ID-no-longer-grounded. @@ -633,7 +620,6 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, ? : OTG_TIME_A_WAIT_BCON)); break; -#endif case OTG_STATE_B_IDLE: if (!musb->is_active) break; @@ -642,13 +628,11 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, musb->is_active = is_otg_enabled(musb) && musb->xceiv->gadget->b_hnp_enable; if (musb->is_active) { -#ifdef CONFIG_USB_MUSB_OTG musb->xceiv->state = OTG_STATE_B_WAIT_ACON; dev_dbg(musb->controller, "HNP: Setting timer for b_ase0_brst\n"); mod_timer(&musb->otg_timer, jiffies + msecs_to_jiffies( OTG_TIME_B_ASE0_BRST)); -#endif } break; case OTG_STATE_A_WAIT_BCON: @@ -672,7 +656,6 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, } } -#ifdef CONFIG_USB_MUSB_HDRC_HCD if (int_usb & MUSB_INTR_CONNECT) { struct usb_hcd *hcd = musb_to_hcd(musb); @@ -682,7 +665,6 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, musb->ep0_stage = MUSB_EP0_START; -#ifdef CONFIG_USB_MUSB_OTG /* flush endpoints when transitioning from Device Mode */ if (is_peripheral_active(musb)) { /* REVISIT HNP; just force disconnect */ @@ -690,7 +672,6 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, musb_writew(musb->mregs, MUSB_INTRTXE, musb->epmask); musb_writew(musb->mregs, MUSB_INTRRXE, musb->epmask & 0xfffe); musb_writeb(musb->mregs, MUSB_INTRUSBE, 0xf7); -#endif musb->port1_status &= ~(USB_PORT_STAT_LOW_SPEED |USB_PORT_STAT_HIGH_SPEED |USB_PORT_STAT_ENABLE @@ -739,7 +720,6 @@ b_host: dev_dbg(musb->controller, "CONNECT (%s) devctl %02x\n", otg_state_string(musb->xceiv->state), devctl); } -#endif /* CONFIG_USB_MUSB_HDRC_HCD */ if ((int_usb & MUSB_INTR_DISCONNECT) && !musb->ignore_disconnect) { dev_dbg(musb->controller, "DISCONNECT (%s) as %s, devctl %02x\n", @@ -748,7 +728,6 @@ b_host: handled = IRQ_HANDLED; switch (musb->xceiv->state) { -#ifdef CONFIG_USB_MUSB_HDRC_HCD case OTG_STATE_A_HOST: case OTG_STATE_A_SUSPEND: usb_hcd_resume_root_hub(musb_to_hcd(musb)); @@ -757,8 +736,6 @@ b_host: musb_platform_try_idle(musb, jiffies + msecs_to_jiffies(musb->a_wait_bcon)); break; -#endif /* HOST */ -#ifdef CONFIG_USB_MUSB_OTG case OTG_STATE_B_HOST: /* REVISIT this behaves for "real disconnect" * cases; make sure the other transitions from @@ -777,13 +754,10 @@ b_host: /* FALLTHROUGH */ case OTG_STATE_B_WAIT_ACON: /* FALLTHROUGH */ -#endif /* OTG */ -#ifdef CONFIG_USB_GADGET_MUSB_HDRC case OTG_STATE_B_PERIPHERAL: case OTG_STATE_B_IDLE: musb_g_disconnect(musb); break; -#endif /* GADGET */ default: WARNING("unhandled DISCONNECT transition (%s)\n", otg_state_string(musb->xceiv->state)); @@ -814,7 +788,6 @@ b_host: dev_dbg(musb->controller, "BUS RESET as %s\n", otg_state_string(musb->xceiv->state)); switch (musb->xceiv->state) { -#ifdef CONFIG_USB_OTG case OTG_STATE_A_SUSPEND: /* We need to ignore disconnect on suspend * otherwise tusb 2.0 won't reconnect after a @@ -842,7 +815,6 @@ b_host: musb->xceiv->state = OTG_STATE_B_PERIPHERAL; musb_g_reset(musb); break; -#endif case OTG_STATE_B_IDLE: musb->xceiv->state = OTG_STATE_B_PERIPHERAL; /* FALLTHROUGH */ @@ -1191,14 +1163,12 @@ fifo_setup(struct musb *musb, struct musb_hw_ep *hw_ep, /* configure the FIFO */ musb_writeb(mbase, MUSB_INDEX, hw_ep->epnum); -#ifdef CONFIG_USB_MUSB_HDRC_HCD /* EP0 reserved endpoint for control, bidirectional; * EP1 reserved for bulk, two unidirection halves. */ if (hw_ep->epnum == 1) musb->bulk_ep = hw_ep; /* REVISIT error check: be sure ep0 can both rx and tx ... */ -#endif switch (cfg->style) { case FIFO_TX: musb_write_txfifosz(mbase, c_size); @@ -1317,12 +1287,10 @@ done: n + 1, musb->config->num_eps * 2 - 1, offset, (1 << (musb->config->ram_bits + 2))); -#ifdef CONFIG_USB_MUSB_HDRC_HCD if (!musb->bulk_ep) { pr_debug("%s: missing bulk\n", musb_driver_name); return -EINVAL; } -#endif return 0; } @@ -1353,7 +1321,6 @@ static int __init ep_config_from_hw(struct musb *musb) /* FIXME set up hw_ep->{rx,tx}_double_buffered */ -#ifdef CONFIG_USB_MUSB_HDRC_HCD /* pick an RX/TX endpoint for bulk */ if (hw_ep->max_packet_sz_tx < 512 || hw_ep->max_packet_sz_rx < 512) @@ -1365,15 +1332,12 @@ static int __init ep_config_from_hw(struct musb *musb) if (musb->bulk_ep) continue; musb->bulk_ep = hw_ep; -#endif } -#ifdef CONFIG_USB_MUSB_HDRC_HCD if (!musb->bulk_ep) { pr_debug("%s: missing bulk\n", musb_driver_name); return -EINVAL; } -#endif return 0; } @@ -1429,13 +1393,11 @@ static int __init musb_core_init(u16 musb_type, struct musb *musb) } else { musb->is_multipoint = 0; type = ""; -#ifdef CONFIG_USB_MUSB_HDRC_HCD #ifndef CONFIG_USB_OTG_BLACKLIST_HUB printk(KERN_ERR "%s: kernel must blacklist external hubs\n", musb_driver_name); #endif -#endif } /* log release info */ @@ -1479,11 +1441,9 @@ static int __init musb_core_init(u16 musb_type, struct musb *musb) #endif hw_ep->regs = MUSB_EP_OFFSET(i, 0) + mbase; -#ifdef CONFIG_USB_MUSB_HDRC_HCD hw_ep->target_regs = musb_read_target_reg_base(i, mbase); hw_ep->rx_reinit = 1; hw_ep->tx_reinit = 1; -#endif if (hw_ep->max_packet_sz_tx) { dev_dbg(musb->controller, @@ -1561,13 +1521,11 @@ irqreturn_t musb_interrupt(struct musb *musb) (devctl & MUSB_DEVCTL_HM) ? "host" : "peripheral", musb->int_usb, musb->int_tx, musb->int_rx); -#ifdef CONFIG_USB_GADGET_MUSB_HDRC if (is_otg_enabled(musb) || is_peripheral_enabled(musb)) if (!musb->gadget_driver) { dev_dbg(musb->controller, "No gadget driver loaded\n"); return IRQ_HANDLED; } -#endif /* the core can interrupt us for multiple reasons; docs have * a generic interrupt flowchart to follow @@ -1767,8 +1725,6 @@ musb_vbus_show(struct device *dev, struct device_attribute *attr, char *buf) } static DEVICE_ATTR(vbus, 0644, musb_vbus_show, musb_vbus_store); -#ifdef CONFIG_USB_GADGET_MUSB_HDRC - /* Gadget drivers can't know that a host is connected so they might want * to start SRP, but users can. This allows userspace to trigger SRP. */ @@ -1792,14 +1748,10 @@ musb_srp_store(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR(srp, 0644, NULL, musb_srp_store); -#endif /* CONFIG_USB_GADGET_MUSB_HDRC */ - static struct attribute *musb_attributes[] = { &dev_attr_mode.attr, &dev_attr_vbus.attr, -#ifdef CONFIG_USB_GADGET_MUSB_HDRC &dev_attr_srp.attr, -#endif NULL }; @@ -1832,7 +1784,6 @@ allocate_instance(struct device *dev, struct musb *musb; struct musb_hw_ep *ep; int epnum; -#ifdef CONFIG_USB_MUSB_HDRC_HCD struct usb_hcd *hcd; hcd = usb_create_hcd(&musb_hc_driver, dev, dev_name(dev)); @@ -1850,12 +1801,6 @@ allocate_instance(struct device *dev, musb->vbuserr_retry = VBUSERR_RETRY_COUNT; musb->a_wait_bcon = OTG_TIME_A_WAIT_BCON; -#else - musb = kzalloc(sizeof *musb, GFP_KERNEL); - if (!musb) - return NULL; - -#endif dev_set_drvdata(dev, musb); musb->mregs = mbase; musb->ctrl_base = mbase; @@ -1885,9 +1830,7 @@ static void musb_free(struct musb *musb) sysfs_remove_group(&musb->controller->kobj, &musb_attr_group); #endif -#ifdef CONFIG_USB_GADGET_MUSB_HDRC musb_gadget_cleanup(musb); -#endif if (musb->nIrq >= 0) { if (musb->irq_wake) @@ -1901,11 +1844,7 @@ static void musb_free(struct musb *musb) dma_controller_destroy(c); } -#ifdef CONFIG_USB_MUSB_HDRC_HCD - usb_put_hcd(musb_to_hcd(musb)); -#else kfree(musb); -#endif } /* @@ -2000,9 +1939,7 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl) if (status < 0) goto fail3; -#ifdef CONFIG_USB_MUSB_OTG setup_timer(&musb->otg_timer, musb_otg_timer_func, (unsigned long) musb); -#endif /* Init IRQ workqueue before request_irq */ INIT_WORK(&musb->irq_work, musb_irq_work); @@ -2444,34 +2381,13 @@ static struct platform_driver musb_driver = { static int __init musb_init(void) { -#ifdef CONFIG_USB_MUSB_HDRC_HCD if (usb_disabled()) return 0; -#endif pr_info("%s: version " MUSB_VERSION ", " -#ifdef CONFIG_MUSB_PIO_ONLY - "pio" -#elif defined(CONFIG_USB_TI_CPPI_DMA) - "cppi-dma" -#elif defined(CONFIG_USB_INVENTRA_DMA) - "musb-dma" -#elif defined(CONFIG_USB_TUSB_OMAP_DMA) - "tusb-omap-dma" -#elif defined(CONFIG_USB_UX500_DMA) - "ux500-dma" -#else "?dma?" -#endif ", " -#ifdef CONFIG_USB_MUSB_OTG - "otg (peripheral+host)" -#elif defined(CONFIG_USB_GADGET_MUSB_HDRC) - "peripheral" -#elif defined(CONFIG_USB_MUSB_HDRC_HCD) - "host" -#endif - , + "otg (peripheral+host)", musb_driver_name); return platform_driver_probe(&musb_driver, musb_probe); } -- cgit v1.1 From ee34e51a7458ba59af65d1b0eb9c7fa9d19a7586 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Wed, 29 Jun 2011 12:45:03 +0300 Subject: usb: musb: choose correct fifo_mode When we start building glue layers as modules, we need to be careful with the fifo_mode changes otherwise that weird ifdeferry won't evaluate correctly. Add the missing _MODULE variants for all glue layers to prevent everybody from using fifo_mode 2. Signed-off-by: Felipe Balbi Signed-off-by: Greg Kroah-Hartman --- drivers/usb/musb/musb_core.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'drivers/usb/musb/musb_core.c') diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index 7ab9497..391237b 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c @@ -1010,10 +1010,15 @@ static void musb_shutdown(struct platform_device *pdev) * We don't currently use dynamic fifo setup capability to do anything * more than selecting one of a bunch of predefined configurations. */ -#if defined(CONFIG_USB_MUSB_TUSB6010) || defined(CONFIG_USB_MUSB_OMAP2PLUS) \ - || defined(CONFIG_USB_MUSB_AM35X) +#if defined(CONFIG_USB_MUSB_TUSB6010) \ + || defined(CONFIG_USB_MUSB_TUSB6010_MODULE) \ + || defined(CONFIG_USB_MUSB_OMAP2PLUS) \ + || defined(CONFIG_USB_MUSB_OMAP2PLUS_MODULE) \ + || defined(CONFIG_USB_MUSB_AM35X) \ + || defined(CONFIG_USB_MUSB_AM35X_MODULE) static ushort __initdata fifo_mode = 4; -#elif defined(CONFIG_USB_MUSB_UX500) +#elif defined(CONFIG_USB_MUSB_UX500) \ + || defined(CONFIG_USB_MUSB_UX500_MODULE) static ushort __initdata fifo_mode = 5; #else static ushort __initdata fifo_mode = 2; -- cgit v1.1 From e71eb392c2014e2b377810ad329e36b0229d041c Mon Sep 17 00:00:00 2001 From: Sebastian Andrzej Siewior Date: Thu, 23 Jun 2011 14:26:16 +0200 Subject: usb: musb: convert musb to new style bind udc-core checks for valid callbacks so there is no need for the driver to do so. Also "can-be-bound-once" is verified by udc-core. The pull-up callback is called by udc-core afterwords. [ balbi@ti.com : keep holding gadget_driver pointer for now remove the stupid check for gadget_driver otherwise we don't handle IRQs ] Signed-off-by: Sebastian Andrzej Siewior Signed-off-by: Felipe Balbi Signed-off-by: Greg Kroah-Hartman --- drivers/usb/musb/musb_core.c | 7 ------- 1 file changed, 7 deletions(-) (limited to 'drivers/usb/musb/musb_core.c') diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index 391237b..e2ab452 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c @@ -899,7 +899,6 @@ void musb_start(struct musb *musb) /* put into basic highspeed mode and start session */ musb_writeb(regs, MUSB_POWER, MUSB_POWER_ISOUPDATE - | MUSB_POWER_SOFTCONN | MUSB_POWER_HSENAB /* ENSUSPEND wedges tusb */ /* | MUSB_POWER_ENSUSPEND */ @@ -1526,12 +1525,6 @@ irqreturn_t musb_interrupt(struct musb *musb) (devctl & MUSB_DEVCTL_HM) ? "host" : "peripheral", musb->int_usb, musb->int_tx, musb->int_rx); - if (is_otg_enabled(musb) || is_peripheral_enabled(musb)) - if (!musb->gadget_driver) { - dev_dbg(musb->controller, "No gadget driver loaded\n"); - return IRQ_HANDLED; - } - /* the core can interrupt us for multiple reasons; docs have * a generic interrupt flowchart to follow */ -- cgit v1.1 From 8220796df85d58a445863424b7b2053d4741e931 Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Mon, 27 Jun 2011 15:57:12 +0300 Subject: usb: musb: no need to access platform_device dev_get_drvdata() is exactly the same as platform_get_drvdata(). Drop that useless access to the platform device. Signed-off-by: Felipe Balbi Signed-off-by: Greg Kroah-Hartman --- drivers/usb/musb/musb_core.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'drivers/usb/musb/musb_core.c') diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index e2ab452..c6ab321 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c @@ -2286,9 +2286,8 @@ static void musb_restore_context(struct musb *musb) static int musb_suspend(struct device *dev) { - struct platform_device *pdev = to_platform_device(dev); + struct musb *musb = dev_to_musb(dev); unsigned long flags; - struct musb *musb = dev_to_musb(&pdev->dev); spin_lock_irqsave(&musb->lock, flags); @@ -2310,8 +2309,7 @@ static int musb_suspend(struct device *dev) static int musb_resume_noirq(struct device *dev) { - struct platform_device *pdev = to_platform_device(dev); - struct musb *musb = dev_to_musb(&pdev->dev); + struct musb *musb = dev_to_musb(dev); musb_restore_context(musb); -- cgit v1.1 From 3c5fec75e121b21a2eb35e5a6b44291509abba6f Mon Sep 17 00:00:00 2001 From: Ajay Kumar Gupta Date: Fri, 8 Jul 2011 15:06:13 +0530 Subject: usb: musb: restore INDEX register in resume path Restoring the missing INDEX register value in musb_restore_context(). Without this suspend resume functionality is broken with offmode enabled. Cc: stable@kernel.org Acked-by: Anand Gadiyar Signed-off-by: Ajay Kumar Gupta Signed-off-by: Felipe Balbi --- drivers/usb/musb/musb_core.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/usb/musb/musb_core.c') diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index c6ab321..4d39e08 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c @@ -2282,6 +2282,7 @@ static void musb_restore_context(struct musb *musb) musb->context.index_regs[i].rxhubport); } } + musb_writeb(musb_base, MUSB_INDEX, musb->context.index); } static int musb_suspend(struct device *dev) -- cgit v1.1