aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/musb
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-04-05 18:18:00 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-04-05 18:18:00 -0400
commit64dc9e2e7320f079b97c46b106133b58b8e18d40 (patch)
treeab010dc1337d44e29c2b32b7f11788620a91fe4f /drivers/usb/musb
parent01a60e76b6392547ad3dca3ac05b9c886fa5da45 (diff)
parent9b192de60b5a584ee4ed967fb6758773c75e4643 (diff)
Merge tag 'usb-for-v3.10' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-next
Felipe writes: usb: patches for v3.10 merge window Here is the big Gadget & PHY pull request. Many of us have been really busy lately getting multiple drivers to a better position. Since this pull request is so large, I will divide it in sections so it's easier to grasp what's included. - cleanups: . UDC drivers no longer touch gadget->dev, that's now udc-core responsibility . Many more UDC drivers converted to usb_gadget_map/unmap_request() . UDC drivers no longer initialize DMA-related fields from gadget's device structure . UDC drivers don't touch gadget.dev.driver directly . UDC drivers don't assign gadget.dev.release directly . Removal of some unused DMA_ADDR_INVALID . Introduction of CONFIG_USB_PHY . All phy drivers have been moved to drivers/usb/phy and renamed to a common naming scheme . Fix PHY layer so it never returns a NULL pointer, also fix all callers to avoid using IS_ERR_OR_NULL() . Sparse fixes all over the place . drivers/usb/otg/ has been deleted . Marvel drivers (mv_udc, ehci-mv, mv_otg and mv_u3d) improved clock usage - new features: . UDC core now provides a generic way for tracking and reporting UDC's state (not attached, resuming, suspended, addressed, default, etc) . twl4030-usb learned that it shouldn't be enabled during init . Full DT support for DWC3 has been implemented . ab8500-usb learned about pinctrl framework . nop PHY learned about DeviceTree and regulators . DWC3 learned about suspend/resume . DWC3 can now be compiled in host-only and gadget-only (as well as DRD) configurations . UVC now enables streaming endpoint based on negotiated speed . isp1301 now implements the PHY API properly . configfs-based interface for gadget drivers which will lead to the removal of all code which just combines functions together to build functional gadget drivers. . f_serial and f_obex were converted to new configfs interface while maintaining old interface around. - non-critical fixes: . UVC gadget driver got fixes for Endpoint usage and stream calculation . ab8500-usb fixed unbalanced clock and regulator API usage . twl4030-usb got a fix for when OMAP3 is booted with cable connected . fusb300_udc got a fix for DMA usage . UVC got fixes for two assertions of the USB Video Class Compliance specification revision 1.1 . build warning issues caused by recent addition of __must_check to regulator API These are all changes which deserve a mention, all other changes are related to these one or minor spelling fixes and other similar tasks. Signed-of-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/musb')
-rw-r--r--drivers/usb/musb/Kconfig6
-rw-r--r--drivers/usb/musb/am35x.c8
-rw-r--r--drivers/usb/musb/blackfin.c6
-rw-r--r--drivers/usb/musb/cppi_dma.c17
-rw-r--r--drivers/usb/musb/da8xx.c8
-rw-r--r--drivers/usb/musb/davinci.c4
-rw-r--r--drivers/usb/musb/musb_core.c71
-rw-r--r--drivers/usb/musb/musb_dsps.c14
-rw-r--r--drivers/usb/musb/musb_gadget.c156
-rw-r--r--drivers/usb/musb/musb_gadget_ep0.c6
-rw-r--r--drivers/usb/musb/musb_host.c119
-rw-r--r--drivers/usb/musb/musb_virthub.c4
-rw-r--r--drivers/usb/musb/omap2430.c32
-rw-r--r--drivers/usb/musb/tusb6010.c14
-rw-r--r--drivers/usb/musb/ux500.c106
-rw-r--r--drivers/usb/musb/ux500_dma.c24
16 files changed, 349 insertions, 246 deletions
diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
index 05e51432dd2f..47442d35b6fc 100644
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -7,7 +7,6 @@
7config USB_MUSB_HDRC 7config USB_MUSB_HDRC
8 tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, ...)' 8 tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, ...)'
9 depends on USB && USB_GADGET 9 depends on USB && USB_GADGET
10 select USB_OTG_UTILS
11 help 10 help
12 Say Y here if your system has a dual role high speed USB 11 Say Y here if your system has a dual role high speed USB
13 controller based on the Mentor Graphics silicon IP. Then 12 controller based on the Mentor Graphics silicon IP. Then
@@ -34,10 +33,12 @@ choice
34config USB_MUSB_DAVINCI 33config USB_MUSB_DAVINCI
35 tristate "DaVinci" 34 tristate "DaVinci"
36 depends on ARCH_DAVINCI_DMx 35 depends on ARCH_DAVINCI_DMx
36 depends on BROKEN
37 37
38config USB_MUSB_DA8XX 38config USB_MUSB_DA8XX
39 tristate "DA8xx/OMAP-L1x" 39 tristate "DA8xx/OMAP-L1x"
40 depends on ARCH_DAVINCI_DA8XX 40 depends on ARCH_DAVINCI_DA8XX
41 depends on BROKEN
41 42
42config USB_MUSB_TUSB6010 43config USB_MUSB_TUSB6010
43 tristate "TUSB6010" 44 tristate "TUSB6010"
@@ -53,7 +54,6 @@ config USB_MUSB_AM35X
53 54
54config USB_MUSB_DSPS 55config USB_MUSB_DSPS
55 tristate "TI DSPS platforms" 56 tristate "TI DSPS platforms"
56 depends on SOC_TI81XX || SOC_AM33XX
57 57
58config USB_MUSB_BLACKFIN 58config USB_MUSB_BLACKFIN
59 tristate "Blackfin" 59 tristate "Blackfin"
@@ -61,12 +61,12 @@ config USB_MUSB_BLACKFIN
61 61
62config USB_MUSB_UX500 62config USB_MUSB_UX500
63 tristate "U8500 and U5500" 63 tristate "U8500 and U5500"
64 depends on (ARCH_U8500 && AB8500_USB)
65 64
66endchoice 65endchoice
67 66
68choice 67choice
69 prompt 'MUSB DMA mode' 68 prompt 'MUSB DMA mode'
69 default MUSB_PIO_ONLY if ARCH_MULTIPLATFORM
70 default USB_UX500_DMA if USB_MUSB_UX500 70 default USB_UX500_DMA if USB_MUSB_UX500
71 default USB_INVENTRA_DMA if USB_MUSB_OMAP2PLUS || USB_MUSB_BLACKFIN 71 default USB_INVENTRA_DMA if USB_MUSB_OMAP2PLUS || USB_MUSB_BLACKFIN
72 default USB_TI_CPPI_DMA if USB_MUSB_DAVINCI 72 default USB_TI_CPPI_DMA if USB_MUSB_DAVINCI
diff --git a/drivers/usb/musb/am35x.c b/drivers/usb/musb/am35x.c
index 59eea219034a..2231850c0625 100644
--- a/drivers/usb/musb/am35x.c
+++ b/drivers/usb/musb/am35x.c
@@ -149,7 +149,7 @@ static void otg_timer(unsigned long _musb)
149 */ 149 */
150 devctl = musb_readb(mregs, MUSB_DEVCTL); 150 devctl = musb_readb(mregs, MUSB_DEVCTL);
151 dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl, 151 dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl,
152 otg_state_string(musb->xceiv->state)); 152 usb_otg_state_string(musb->xceiv->state));
153 153
154 spin_lock_irqsave(&musb->lock, flags); 154 spin_lock_irqsave(&musb->lock, flags);
155 switch (musb->xceiv->state) { 155 switch (musb->xceiv->state) {
@@ -195,7 +195,7 @@ static void am35x_musb_try_idle(struct musb *musb, unsigned long timeout)
195 if (musb->is_active || (musb->a_wait_bcon == 0 && 195 if (musb->is_active || (musb->a_wait_bcon == 0 &&
196 musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) { 196 musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) {
197 dev_dbg(musb->controller, "%s active, deleting timer\n", 197 dev_dbg(musb->controller, "%s active, deleting timer\n",
198 otg_state_string(musb->xceiv->state)); 198 usb_otg_state_string(musb->xceiv->state));
199 del_timer(&otg_workaround); 199 del_timer(&otg_workaround);
200 last_timer = jiffies; 200 last_timer = jiffies;
201 return; 201 return;
@@ -208,7 +208,7 @@ static void am35x_musb_try_idle(struct musb *musb, unsigned long timeout)
208 last_timer = timeout; 208 last_timer = timeout;
209 209
210 dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", 210 dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n",
211 otg_state_string(musb->xceiv->state), 211 usb_otg_state_string(musb->xceiv->state),
212 jiffies_to_msecs(timeout - jiffies)); 212 jiffies_to_msecs(timeout - jiffies));
213 mod_timer(&otg_workaround, timeout); 213 mod_timer(&otg_workaround, timeout);
214} 214}
@@ -298,7 +298,7 @@ static irqreturn_t am35x_musb_interrupt(int irq, void *hci)
298 /* NOTE: this must complete power-on within 100 ms. */ 298 /* NOTE: this must complete power-on within 100 ms. */
299 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", 299 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n",
300 drvvbus ? "on" : "off", 300 drvvbus ? "on" : "off",
301 otg_state_string(musb->xceiv->state), 301 usb_otg_state_string(musb->xceiv->state),
302 err ? " ERROR" : "", 302 err ? " ERROR" : "",
303 devctl); 303 devctl);
304 ret = IRQ_HANDLED; 304 ret = IRQ_HANDLED;
diff --git a/drivers/usb/musb/blackfin.c b/drivers/usb/musb/blackfin.c
index dbb31b30c7fa..5e63b160db0c 100644
--- a/drivers/usb/musb/blackfin.c
+++ b/drivers/usb/musb/blackfin.c
@@ -280,13 +280,13 @@ static void musb_conn_timer_handler(unsigned long _musb)
280 break; 280 break;
281 default: 281 default:
282 dev_dbg(musb->controller, "%s state not handled\n", 282 dev_dbg(musb->controller, "%s state not handled\n",
283 otg_state_string(musb->xceiv->state)); 283 usb_otg_state_string(musb->xceiv->state));
284 break; 284 break;
285 } 285 }
286 spin_unlock_irqrestore(&musb->lock, flags); 286 spin_unlock_irqrestore(&musb->lock, flags);
287 287
288 dev_dbg(musb->controller, "state is %s\n", 288 dev_dbg(musb->controller, "state is %s\n",
289 otg_state_string(musb->xceiv->state)); 289 usb_otg_state_string(musb->xceiv->state));
290} 290}
291 291
292static void bfin_musb_enable(struct musb *musb) 292static void bfin_musb_enable(struct musb *musb)
@@ -307,7 +307,7 @@ static void bfin_musb_set_vbus(struct musb *musb, int is_on)
307 307
308 dev_dbg(musb->controller, "VBUS %s, devctl %02x " 308 dev_dbg(musb->controller, "VBUS %s, devctl %02x "
309 /* otg %3x conf %08x prcm %08x */ "\n", 309 /* otg %3x conf %08x prcm %08x */ "\n",
310 otg_state_string(musb->xceiv->state), 310 usb_otg_state_string(musb->xceiv->state),
311 musb_readb(musb->mregs, MUSB_DEVCTL)); 311 musb_readb(musb->mregs, MUSB_DEVCTL));
312} 312}
313 313
diff --git a/drivers/usb/musb/cppi_dma.c b/drivers/usb/musb/cppi_dma.c
index f522000e8f06..9db211ee15b5 100644
--- a/drivers/usb/musb/cppi_dma.c
+++ b/drivers/usb/musb/cppi_dma.c
@@ -435,7 +435,6 @@ cppi_rndis_update(struct cppi_channel *c, int is_rx,
435 } 435 }
436} 436}
437 437
438#ifdef CONFIG_USB_MUSB_DEBUG
439static void cppi_dump_rxbd(const char *tag, struct cppi_descriptor *bd) 438static void cppi_dump_rxbd(const char *tag, struct cppi_descriptor *bd)
440{ 439{
441 pr_debug("RXBD/%s %08x: " 440 pr_debug("RXBD/%s %08x: "
@@ -444,21 +443,16 @@ static void cppi_dump_rxbd(const char *tag, struct cppi_descriptor *bd)
444 bd->hw_next, bd->hw_bufp, bd->hw_off_len, 443 bd->hw_next, bd->hw_bufp, bd->hw_off_len,
445 bd->hw_options); 444 bd->hw_options);
446} 445}
447#endif
448 446
449static void cppi_dump_rxq(int level, const char *tag, struct cppi_channel *rx) 447static void cppi_dump_rxq(int level, const char *tag, struct cppi_channel *rx)
450{ 448{
451#ifdef CONFIG_USB_MUSB_DEBUG
452 struct cppi_descriptor *bd; 449 struct cppi_descriptor *bd;
453 450
454 if (!_dbg_level(level))
455 return;
456 cppi_dump_rx(level, rx, tag); 451 cppi_dump_rx(level, rx, tag);
457 if (rx->last_processed) 452 if (rx->last_processed)
458 cppi_dump_rxbd("last", rx->last_processed); 453 cppi_dump_rxbd("last", rx->last_processed);
459 for (bd = rx->head; bd; bd = bd->next) 454 for (bd = rx->head; bd; bd = bd->next)
460 cppi_dump_rxbd("active", bd); 455 cppi_dump_rxbd("active", bd);
461#endif
462} 456}
463 457
464 458
@@ -784,6 +778,7 @@ cppi_next_rx_segment(struct musb *musb, struct cppi_channel *rx, int onepacket)
784 void __iomem *tibase = musb->ctrl_base; 778 void __iomem *tibase = musb->ctrl_base;
785 int is_rndis = 0; 779 int is_rndis = 0;
786 struct cppi_rx_stateram __iomem *rx_ram = rx->state_ram; 780 struct cppi_rx_stateram __iomem *rx_ram = rx->state_ram;
781 struct cppi_descriptor *d;
787 782
788 if (onepacket) { 783 if (onepacket) {
789 /* almost every USB driver, host or peripheral side */ 784 /* almost every USB driver, host or peripheral side */
@@ -897,14 +892,8 @@ cppi_next_rx_segment(struct musb *musb, struct cppi_channel *rx, int onepacket)
897 bd->hw_options |= CPPI_SOP_SET; 892 bd->hw_options |= CPPI_SOP_SET;
898 tail->hw_options |= CPPI_EOP_SET; 893 tail->hw_options |= CPPI_EOP_SET;
899 894
900#ifdef CONFIG_USB_MUSB_DEBUG 895 for (d = rx->head; d; d = d->next)
901 if (_dbg_level(5)) { 896 cppi_dump_rxbd("S", d);
902 struct cppi_descriptor *d;
903
904 for (d = rx->head; d; d = d->next)
905 cppi_dump_rxbd("S", d);
906 }
907#endif
908 897
909 /* in case the preceding transfer left some state... */ 898 /* in case the preceding transfer left some state... */
910 tail = rx->last_processed; 899 tail = rx->last_processed;
diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 41613a2b35e8..b903b744a224 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -198,7 +198,7 @@ static void otg_timer(unsigned long _musb)
198 */ 198 */
199 devctl = musb_readb(mregs, MUSB_DEVCTL); 199 devctl = musb_readb(mregs, MUSB_DEVCTL);
200 dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl, 200 dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl,
201 otg_state_string(musb->xceiv->state)); 201 usb_otg_state_string(musb->xceiv->state));
202 202
203 spin_lock_irqsave(&musb->lock, flags); 203 spin_lock_irqsave(&musb->lock, flags);
204 switch (musb->xceiv->state) { 204 switch (musb->xceiv->state) {
@@ -267,7 +267,7 @@ static void da8xx_musb_try_idle(struct musb *musb, unsigned long timeout)
267 if (musb->is_active || (musb->a_wait_bcon == 0 && 267 if (musb->is_active || (musb->a_wait_bcon == 0 &&
268 musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) { 268 musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) {
269 dev_dbg(musb->controller, "%s active, deleting timer\n", 269 dev_dbg(musb->controller, "%s active, deleting timer\n",
270 otg_state_string(musb->xceiv->state)); 270 usb_otg_state_string(musb->xceiv->state));
271 del_timer(&otg_workaround); 271 del_timer(&otg_workaround);
272 last_timer = jiffies; 272 last_timer = jiffies;
273 return; 273 return;
@@ -280,7 +280,7 @@ static void da8xx_musb_try_idle(struct musb *musb, unsigned long timeout)
280 last_timer = timeout; 280 last_timer = timeout;
281 281
282 dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", 282 dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n",
283 otg_state_string(musb->xceiv->state), 283 usb_otg_state_string(musb->xceiv->state),
284 jiffies_to_msecs(timeout - jiffies)); 284 jiffies_to_msecs(timeout - jiffies));
285 mod_timer(&otg_workaround, timeout); 285 mod_timer(&otg_workaround, timeout);
286} 286}
@@ -360,7 +360,7 @@ static irqreturn_t da8xx_musb_interrupt(int irq, void *hci)
360 360
361 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", 361 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n",
362 drvvbus ? "on" : "off", 362 drvvbus ? "on" : "off",
363 otg_state_string(musb->xceiv->state), 363 usb_otg_state_string(musb->xceiv->state),
364 err ? " ERROR" : "", 364 err ? " ERROR" : "",
365 devctl); 365 devctl);
366 ret = IRQ_HANDLED; 366 ret = IRQ_HANDLED;
diff --git a/drivers/usb/musb/davinci.c b/drivers/usb/musb/davinci.c
index e040d9103735..bea6cc35471c 100644
--- a/drivers/usb/musb/davinci.c
+++ b/drivers/usb/musb/davinci.c
@@ -215,7 +215,7 @@ static void otg_timer(unsigned long _musb)
215 */ 215 */
216 devctl = musb_readb(mregs, MUSB_DEVCTL); 216 devctl = musb_readb(mregs, MUSB_DEVCTL);
217 dev_dbg(musb->controller, "poll devctl %02x (%s)\n", devctl, 217 dev_dbg(musb->controller, "poll devctl %02x (%s)\n", devctl,
218 otg_state_string(musb->xceiv->state)); 218 usb_otg_state_string(musb->xceiv->state));
219 219
220 spin_lock_irqsave(&musb->lock, flags); 220 spin_lock_irqsave(&musb->lock, flags);
221 switch (musb->xceiv->state) { 221 switch (musb->xceiv->state) {
@@ -349,7 +349,7 @@ static irqreturn_t davinci_musb_interrupt(int irq, void *__hci)
349 davinci_musb_source_power(musb, drvvbus, 0); 349 davinci_musb_source_power(musb, drvvbus, 0);
350 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", 350 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n",
351 drvvbus ? "on" : "off", 351 drvvbus ? "on" : "off",
352 otg_state_string(musb->xceiv->state), 352 usb_otg_state_string(musb->xceiv->state),
353 err ? " ERROR" : "", 353 err ? " ERROR" : "",
354 devctl); 354 devctl);
355 retval = IRQ_HANDLED; 355 retval = IRQ_HANDLED;
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index daec6e0f7e38..37a261a6bb6a 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -372,13 +372,13 @@ static void musb_otg_timer_func(unsigned long data)
372 case OTG_STATE_A_SUSPEND: 372 case OTG_STATE_A_SUSPEND:
373 case OTG_STATE_A_WAIT_BCON: 373 case OTG_STATE_A_WAIT_BCON:
374 dev_dbg(musb->controller, "HNP: %s timeout\n", 374 dev_dbg(musb->controller, "HNP: %s timeout\n",
375 otg_state_string(musb->xceiv->state)); 375 usb_otg_state_string(musb->xceiv->state));
376 musb_platform_set_vbus(musb, 0); 376 musb_platform_set_vbus(musb, 0);
377 musb->xceiv->state = OTG_STATE_A_WAIT_VFALL; 377 musb->xceiv->state = OTG_STATE_A_WAIT_VFALL;
378 break; 378 break;
379 default: 379 default:
380 dev_dbg(musb->controller, "HNP: Unhandled mode %s\n", 380 dev_dbg(musb->controller, "HNP: Unhandled mode %s\n",
381 otg_state_string(musb->xceiv->state)); 381 usb_otg_state_string(musb->xceiv->state));
382 } 382 }
383 musb->ignore_disconnect = 0; 383 musb->ignore_disconnect = 0;
384 spin_unlock_irqrestore(&musb->lock, flags); 384 spin_unlock_irqrestore(&musb->lock, flags);
@@ -393,13 +393,14 @@ void musb_hnp_stop(struct musb *musb)
393 void __iomem *mbase = musb->mregs; 393 void __iomem *mbase = musb->mregs;
394 u8 reg; 394 u8 reg;
395 395
396 dev_dbg(musb->controller, "HNP: stop from %s\n", otg_state_string(musb->xceiv->state)); 396 dev_dbg(musb->controller, "HNP: stop from %s\n",
397 usb_otg_state_string(musb->xceiv->state));
397 398
398 switch (musb->xceiv->state) { 399 switch (musb->xceiv->state) {
399 case OTG_STATE_A_PERIPHERAL: 400 case OTG_STATE_A_PERIPHERAL:
400 musb_g_disconnect(musb); 401 musb_g_disconnect(musb);
401 dev_dbg(musb->controller, "HNP: back to %s\n", 402 dev_dbg(musb->controller, "HNP: back to %s\n",
402 otg_state_string(musb->xceiv->state)); 403 usb_otg_state_string(musb->xceiv->state));
403 break; 404 break;
404 case OTG_STATE_B_HOST: 405 case OTG_STATE_B_HOST:
405 dev_dbg(musb->controller, "HNP: Disabling HR\n"); 406 dev_dbg(musb->controller, "HNP: Disabling HR\n");
@@ -413,7 +414,7 @@ void musb_hnp_stop(struct musb *musb)
413 break; 414 break;
414 default: 415 default:
415 dev_dbg(musb->controller, "HNP: Stopping in unknown state %s\n", 416 dev_dbg(musb->controller, "HNP: Stopping in unknown state %s\n",
416 otg_state_string(musb->xceiv->state)); 417 usb_otg_state_string(musb->xceiv->state));
417 } 418 }
418 419
419 /* 420 /*
@@ -451,7 +452,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
451 */ 452 */
452 if (int_usb & MUSB_INTR_RESUME) { 453 if (int_usb & MUSB_INTR_RESUME) {
453 handled = IRQ_HANDLED; 454 handled = IRQ_HANDLED;
454 dev_dbg(musb->controller, "RESUME (%s)\n", otg_state_string(musb->xceiv->state)); 455 dev_dbg(musb->controller, "RESUME (%s)\n", usb_otg_state_string(musb->xceiv->state));
455 456
456 if (devctl & MUSB_DEVCTL_HM) { 457 if (devctl & MUSB_DEVCTL_HM) {
457 void __iomem *mbase = musb->mregs; 458 void __iomem *mbase = musb->mregs;
@@ -493,7 +494,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
493 default: 494 default:
494 WARNING("bogus %s RESUME (%s)\n", 495 WARNING("bogus %s RESUME (%s)\n",
495 "host", 496 "host",
496 otg_state_string(musb->xceiv->state)); 497 usb_otg_state_string(musb->xceiv->state));
497 } 498 }
498 } else { 499 } else {
499 switch (musb->xceiv->state) { 500 switch (musb->xceiv->state) {
@@ -522,7 +523,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
522 default: 523 default:
523 WARNING("bogus %s RESUME (%s)\n", 524 WARNING("bogus %s RESUME (%s)\n",
524 "peripheral", 525 "peripheral",
525 otg_state_string(musb->xceiv->state)); 526 usb_otg_state_string(musb->xceiv->state));
526 } 527 }
527 } 528 }
528 } 529 }
@@ -538,7 +539,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
538 } 539 }
539 540
540 dev_dbg(musb->controller, "SESSION_REQUEST (%s)\n", 541 dev_dbg(musb->controller, "SESSION_REQUEST (%s)\n",
541 otg_state_string(musb->xceiv->state)); 542 usb_otg_state_string(musb->xceiv->state));
542 543
543 /* IRQ arrives from ID pin sense or (later, if VBUS power 544 /* IRQ arrives from ID pin sense or (later, if VBUS power
544 * is removed) SRP. responses are time critical: 545 * is removed) SRP. responses are time critical:
@@ -602,8 +603,9 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
602 break; 603 break;
603 } 604 }
604 605
605 dev_dbg(musb->controller, "VBUS_ERROR in %s (%02x, %s), retry #%d, port1 %08x\n", 606 dev_printk(ignore ? KERN_DEBUG : KERN_ERR, musb->controller,
606 otg_state_string(musb->xceiv->state), 607 "VBUS_ERROR in %s (%02x, %s), retry #%d, port1 %08x\n",
608 usb_otg_state_string(musb->xceiv->state),
607 devctl, 609 devctl,
608 ({ char *s; 610 ({ char *s;
609 switch (devctl & MUSB_DEVCTL_VBUS) { 611 switch (devctl & MUSB_DEVCTL_VBUS) {
@@ -628,7 +630,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
628 630
629 if (int_usb & MUSB_INTR_SUSPEND) { 631 if (int_usb & MUSB_INTR_SUSPEND) {
630 dev_dbg(musb->controller, "SUSPEND (%s) devctl %02x\n", 632 dev_dbg(musb->controller, "SUSPEND (%s) devctl %02x\n",
631 otg_state_string(musb->xceiv->state), devctl); 633 usb_otg_state_string(musb->xceiv->state), devctl);
632 handled = IRQ_HANDLED; 634 handled = IRQ_HANDLED;
633 635
634 switch (musb->xceiv->state) { 636 switch (musb->xceiv->state) {
@@ -745,12 +747,12 @@ b_host:
745 usb_hcd_resume_root_hub(hcd); 747 usb_hcd_resume_root_hub(hcd);
746 748
747 dev_dbg(musb->controller, "CONNECT (%s) devctl %02x\n", 749 dev_dbg(musb->controller, "CONNECT (%s) devctl %02x\n",
748 otg_state_string(musb->xceiv->state), devctl); 750 usb_otg_state_string(musb->xceiv->state), devctl);
749 } 751 }
750 752
751 if ((int_usb & MUSB_INTR_DISCONNECT) && !musb->ignore_disconnect) { 753 if ((int_usb & MUSB_INTR_DISCONNECT) && !musb->ignore_disconnect) {
752 dev_dbg(musb->controller, "DISCONNECT (%s) as %s, devctl %02x\n", 754 dev_dbg(musb->controller, "DISCONNECT (%s) as %s, devctl %02x\n",
753 otg_state_string(musb->xceiv->state), 755 usb_otg_state_string(musb->xceiv->state),
754 MUSB_MODE(musb), devctl); 756 MUSB_MODE(musb), devctl);
755 handled = IRQ_HANDLED; 757 handled = IRQ_HANDLED;
756 758
@@ -787,7 +789,7 @@ b_host:
787 break; 789 break;
788 default: 790 default:
789 WARNING("unhandled DISCONNECT transition (%s)\n", 791 WARNING("unhandled DISCONNECT transition (%s)\n",
790 otg_state_string(musb->xceiv->state)); 792 usb_otg_state_string(musb->xceiv->state));
791 break; 793 break;
792 } 794 }
793 } 795 }
@@ -813,7 +815,7 @@ b_host:
813 } 815 }
814 } else { 816 } else {
815 dev_dbg(musb->controller, "BUS RESET as %s\n", 817 dev_dbg(musb->controller, "BUS RESET as %s\n",
816 otg_state_string(musb->xceiv->state)); 818 usb_otg_state_string(musb->xceiv->state));
817 switch (musb->xceiv->state) { 819 switch (musb->xceiv->state) {
818 case OTG_STATE_A_SUSPEND: 820 case OTG_STATE_A_SUSPEND:
819 /* We need to ignore disconnect on suspend 821 /* We need to ignore disconnect on suspend
@@ -826,7 +828,7 @@ b_host:
826 case OTG_STATE_A_WAIT_BCON: /* OPT TD.4.7-900ms */ 828 case OTG_STATE_A_WAIT_BCON: /* OPT TD.4.7-900ms */
827 /* never use invalid T(a_wait_bcon) */ 829 /* never use invalid T(a_wait_bcon) */
828 dev_dbg(musb->controller, "HNP: in %s, %d msec timeout\n", 830 dev_dbg(musb->controller, "HNP: in %s, %d msec timeout\n",
829 otg_state_string(musb->xceiv->state), 831 usb_otg_state_string(musb->xceiv->state),
830 TA_WAIT_BCON(musb)); 832 TA_WAIT_BCON(musb));
831 mod_timer(&musb->otg_timer, jiffies 833 mod_timer(&musb->otg_timer, jiffies
832 + msecs_to_jiffies(TA_WAIT_BCON(musb))); 834 + msecs_to_jiffies(TA_WAIT_BCON(musb)));
@@ -838,7 +840,7 @@ b_host:
838 break; 840 break;
839 case OTG_STATE_B_WAIT_ACON: 841 case OTG_STATE_B_WAIT_ACON:
840 dev_dbg(musb->controller, "HNP: RESET (%s), to b_peripheral\n", 842 dev_dbg(musb->controller, "HNP: RESET (%s), to b_peripheral\n",
841 otg_state_string(musb->xceiv->state)); 843 usb_otg_state_string(musb->xceiv->state));
842 musb->xceiv->state = OTG_STATE_B_PERIPHERAL; 844 musb->xceiv->state = OTG_STATE_B_PERIPHERAL;
843 musb_g_reset(musb); 845 musb_g_reset(musb);
844 break; 846 break;
@@ -850,7 +852,7 @@ b_host:
850 break; 852 break;
851 default: 853 default:
852 dev_dbg(musb->controller, "Unhandled BUS RESET as %s\n", 854 dev_dbg(musb->controller, "Unhandled BUS RESET as %s\n",
853 otg_state_string(musb->xceiv->state)); 855 usb_otg_state_string(musb->xceiv->state));
854 } 856 }
855 } 857 }
856 } 858 }
@@ -1632,7 +1634,7 @@ musb_mode_show(struct device *dev, struct device_attribute *attr, char *buf)
1632 int ret = -EINVAL; 1634 int ret = -EINVAL;
1633 1635
1634 spin_lock_irqsave(&musb->lock, flags); 1636 spin_lock_irqsave(&musb->lock, flags);
1635 ret = sprintf(buf, "%s\n", otg_state_string(musb->xceiv->state)); 1637 ret = sprintf(buf, "%s\n", usb_otg_state_string(musb->xceiv->state));
1636 spin_unlock_irqrestore(&musb->lock, flags); 1638 spin_unlock_irqrestore(&musb->lock, flags);
1637 1639
1638 return ret; 1640 return ret;
@@ -1951,9 +1953,13 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
1951 musb_write_ulpi_buscontrol(musb->mregs, busctl); 1953 musb_write_ulpi_buscontrol(musb->mregs, busctl);
1952 } 1954 }
1953 1955
1954 MUSB_DEV_MODE(musb); 1956 if (musb->xceiv->otg->default_a) {
1955 musb->xceiv->otg->default_a = 0; 1957 MUSB_HST_MODE(musb);
1956 musb->xceiv->state = OTG_STATE_B_IDLE; 1958 musb->xceiv->state = OTG_STATE_A_IDLE;
1959 } else {
1960 MUSB_DEV_MODE(musb);
1961 musb->xceiv->state = OTG_STATE_B_IDLE;
1962 }
1957 1963
1958 status = musb_gadget_setup(musb); 1964 status = musb_gadget_setup(musb);
1959 1965
@@ -2008,7 +2014,6 @@ static int musb_probe(struct platform_device *pdev)
2008{ 2014{
2009 struct device *dev = &pdev->dev; 2015 struct device *dev = &pdev->dev;
2010 int irq = platform_get_irq_byname(pdev, "mc"); 2016 int irq = platform_get_irq_byname(pdev, "mc");
2011 int status;
2012 struct resource *iomem; 2017 struct resource *iomem;
2013 void __iomem *base; 2018 void __iomem *base;
2014 2019
@@ -2016,24 +2021,17 @@ static int musb_probe(struct platform_device *pdev)
2016 if (!iomem || irq <= 0) 2021 if (!iomem || irq <= 0)
2017 return -ENODEV; 2022 return -ENODEV;
2018 2023
2019 base = ioremap(iomem->start, resource_size(iomem)); 2024 base = devm_ioremap_resource(dev, iomem);
2020 if (!base) { 2025 if (IS_ERR(base))
2021 dev_err(dev, "ioremap failed\n"); 2026 return PTR_ERR(base);
2022 return -ENOMEM;
2023 }
2024 2027
2025 status = musb_init_controller(dev, irq, base); 2028 return musb_init_controller(dev, irq, base);
2026 if (status < 0)
2027 iounmap(base);
2028
2029 return status;
2030} 2029}
2031 2030
2032static int musb_remove(struct platform_device *pdev) 2031static int musb_remove(struct platform_device *pdev)
2033{ 2032{
2034 struct device *dev = &pdev->dev; 2033 struct device *dev = &pdev->dev;
2035 struct musb *musb = dev_to_musb(dev); 2034 struct musb *musb = dev_to_musb(dev);
2036 void __iomem *ctrl_base = musb->ctrl_base;
2037 2035
2038 /* this gets called on rmmod. 2036 /* this gets called on rmmod.
2039 * - Host mode: host may still be active 2037 * - Host mode: host may still be active
@@ -2044,7 +2042,6 @@ static int musb_remove(struct platform_device *pdev)
2044 musb_shutdown(pdev); 2042 musb_shutdown(pdev);
2045 2043
2046 musb_free(musb); 2044 musb_free(musb);
2047 iounmap(ctrl_base);
2048 device_init_wakeup(dev, 0); 2045 device_init_wakeup(dev, 0);
2049#ifndef CONFIG_MUSB_PIO_ONLY 2046#ifndef CONFIG_MUSB_PIO_ONLY
2050 dma_set_mask(dev, *dev->parent->dma_mask); 2047 dma_set_mask(dev, *dev->parent->dma_mask);
@@ -2293,8 +2290,6 @@ static int __init musb_init(void)
2293 if (usb_disabled()) 2290 if (usb_disabled())
2294 return 0; 2291 return 0;
2295 2292
2296 pr_info("%s: version " MUSB_VERSION ", ?dma?, otg (peripheral+host)\n",
2297 musb_driver_name);
2298 return platform_driver_register(&musb_driver); 2293 return platform_driver_register(&musb_driver);
2299} 2294}
2300module_init(musb_init); 2295module_init(musb_init);
diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c
index 6bb89715b637..3a18e44e9391 100644
--- a/drivers/usb/musb/musb_dsps.c
+++ b/drivers/usb/musb/musb_dsps.c
@@ -38,6 +38,7 @@
38#include <linux/module.h> 38#include <linux/module.h>
39#include <linux/usb/nop-usb-xceiv.h> 39#include <linux/usb/nop-usb-xceiv.h>
40#include <linux/platform_data/usb-omap.h> 40#include <linux/platform_data/usb-omap.h>
41#include <linux/sizes.h>
41 42
42#include <linux/of.h> 43#include <linux/of.h>
43#include <linux/of_device.h> 44#include <linux/of_device.h>
@@ -224,7 +225,7 @@ static void otg_timer(unsigned long _musb)
224 */ 225 */
225 devctl = dsps_readb(mregs, MUSB_DEVCTL); 226 devctl = dsps_readb(mregs, MUSB_DEVCTL);
226 dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl, 227 dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl,
227 otg_state_string(musb->xceiv->state)); 228 usb_otg_state_string(musb->xceiv->state));
228 229
229 spin_lock_irqsave(&musb->lock, flags); 230 spin_lock_irqsave(&musb->lock, flags);
230 switch (musb->xceiv->state) { 231 switch (musb->xceiv->state) {
@@ -273,7 +274,7 @@ static void dsps_musb_try_idle(struct musb *musb, unsigned long timeout)
273 if (musb->is_active || (musb->a_wait_bcon == 0 && 274 if (musb->is_active || (musb->a_wait_bcon == 0 &&
274 musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) { 275 musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) {
275 dev_dbg(musb->controller, "%s active, deleting timer\n", 276 dev_dbg(musb->controller, "%s active, deleting timer\n",
276 otg_state_string(musb->xceiv->state)); 277 usb_otg_state_string(musb->xceiv->state));
277 del_timer(&glue->timer[pdev->id]); 278 del_timer(&glue->timer[pdev->id]);
278 glue->last_timer[pdev->id] = jiffies; 279 glue->last_timer[pdev->id] = jiffies;
279 return; 280 return;
@@ -288,7 +289,7 @@ static void dsps_musb_try_idle(struct musb *musb, unsigned long timeout)
288 glue->last_timer[pdev->id] = timeout; 289 glue->last_timer[pdev->id] = timeout;
289 290
290 dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", 291 dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n",
291 otg_state_string(musb->xceiv->state), 292 usb_otg_state_string(musb->xceiv->state),
292 jiffies_to_msecs(timeout - jiffies)); 293 jiffies_to_msecs(timeout - jiffies));
293 mod_timer(&glue->timer[pdev->id], timeout); 294 mod_timer(&glue->timer[pdev->id], timeout);
294} 295}
@@ -334,7 +335,7 @@ static irqreturn_t dsps_interrupt(int irq, void *hci)
334 * value but DEVCTL.BDEVICE is invalid without DEVCTL.SESSION set. 335 * value but DEVCTL.BDEVICE is invalid without DEVCTL.SESSION set.
335 * Also, DRVVBUS pulses for SRP (but not at 5V) ... 336 * Also, DRVVBUS pulses for SRP (but not at 5V) ...
336 */ 337 */
337 if (usbintr & MUSB_INTR_BABBLE) 338 if (is_host_active(musb) && usbintr & MUSB_INTR_BABBLE)
338 pr_info("CAUTION: musb: Babble Interrupt Occurred\n"); 339 pr_info("CAUTION: musb: Babble Interrupt Occurred\n");
339 340
340 if (usbintr & ((1 << wrp->drvvbus) << wrp->usb_shift)) { 341 if (usbintr & ((1 << wrp->drvvbus) << wrp->usb_shift)) {
@@ -377,7 +378,7 @@ static irqreturn_t dsps_interrupt(int irq, void *hci)
377 /* NOTE: this must complete power-on within 100 ms. */ 378 /* NOTE: this must complete power-on within 100 ms. */
378 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", 379 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n",
379 drvvbus ? "on" : "off", 380 drvvbus ? "on" : "off",
380 otg_state_string(musb->xceiv->state), 381 usb_otg_state_string(musb->xceiv->state),
381 err ? " ERROR" : "", 382 err ? " ERROR" : "",
382 devctl); 383 devctl);
383 ret = IRQ_HANDLED; 384 ret = IRQ_HANDLED;
@@ -596,14 +597,13 @@ err0:
596 597
597static int dsps_probe(struct platform_device *pdev) 598static int dsps_probe(struct platform_device *pdev)
598{ 599{
599 struct device_node *np = pdev->dev.of_node;
600 const struct of_device_id *match; 600 const struct of_device_id *match;
601 const struct dsps_musb_wrapper *wrp; 601 const struct dsps_musb_wrapper *wrp;
602 struct dsps_glue *glue; 602 struct dsps_glue *glue;
603 struct resource *iomem; 603 struct resource *iomem;
604 int ret, i; 604 int ret, i;
605 605
606 match = of_match_node(musb_dsps_of_match, np); 606 match = of_match_node(musb_dsps_of_match, pdev->dev.of_node);
607 if (!match) { 607 if (!match) {
608 dev_err(&pdev->dev, "fail to get matching of_match struct\n"); 608 dev_err(&pdev->dev, "fail to get matching of_match struct\n");
609 ret = -EINVAL; 609 ret = -EINVAL;
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 83eddedcd9be..ba7092349fa9 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -46,48 +46,6 @@
46#include "musb_core.h" 46#include "musb_core.h"
47 47
48 48
49/* MUSB PERIPHERAL status 3-mar-2006:
50 *
51 * - EP0 seems solid. It passes both USBCV and usbtest control cases.
52 * Minor glitches:
53 *
54 * + remote wakeup to Linux hosts work, but saw USBCV failures;
55 * in one test run (operator error?)
56 * + endpoint halt tests -- in both usbtest and usbcv -- seem
57 * to break when dma is enabled ... is something wrongly
58 * clearing SENDSTALL?
59 *
60 * - Mass storage behaved ok when last tested. Network traffic patterns
61 * (with lots of short transfers etc) need retesting; they turn up the
62 * worst cases of the DMA, since short packets are typical but are not
63 * required.
64 *
65 * - TX/IN
66 * + both pio and dma behave in with network and g_zero tests
67 * + no cppi throughput issues other than no-hw-queueing
68 * + failed with FLAT_REG (DaVinci)
69 * + seems to behave with double buffering, PIO -and- CPPI
70 * + with gadgetfs + AIO, requests got lost?
71 *
72 * - RX/OUT
73 * + both pio and dma behave in with network and g_zero tests
74 * + dma is slow in typical case (short_not_ok is clear)
75 * + double buffering ok with PIO
76 * + double buffering *FAILS* with CPPI, wrong data bytes sometimes
77 * + request lossage observed with gadgetfs
78 *
79 * - ISO not tested ... might work, but only weakly isochronous
80 *
81 * - Gadget driver disabling of softconnect during bind() is ignored; so
82 * drivers can't hold off host requests until userspace is ready.
83 * (Workaround: they can turn it off later.)
84 *
85 * - PORTABILITY (assumes PIO works):
86 * + DaVinci, basically works with cppi dma
87 * + OMAP 2430, ditto with mentor dma
88 * + TUSB 6010, platform-specific dma in the works
89 */
90
91/* ----------------------------------------------------------------------- */ 49/* ----------------------------------------------------------------------- */
92 50
93#define is_buffer_mapped(req) (is_dma_capable() && \ 51#define is_buffer_mapped(req) (is_dma_capable() && \
@@ -280,41 +238,6 @@ static inline int max_ep_writesize(struct musb *musb, struct musb_ep *ep)
280 return ep->packet_sz; 238 return ep->packet_sz;
281} 239}
282 240
283
284#ifdef CONFIG_USB_INVENTRA_DMA
285
286/* Peripheral tx (IN) using Mentor DMA works as follows:
287 Only mode 0 is used for transfers <= wPktSize,
288 mode 1 is used for larger transfers,
289
290 One of the following happens:
291 - Host sends IN token which causes an endpoint interrupt
292 -> TxAvail
293 -> if DMA is currently busy, exit.
294 -> if queue is non-empty, txstate().
295
296 - Request is queued by the gadget driver.
297 -> if queue was previously empty, txstate()
298
299 txstate()
300 -> start
301 /\ -> setup DMA
302 | (data is transferred to the FIFO, then sent out when
303 | IN token(s) are recd from Host.
304 | -> DMA interrupt on completion
305 | calls TxAvail.
306 | -> stop DMA, ~DMAENAB,
307 | -> set TxPktRdy for last short pkt or zlp
308 | -> Complete Request
309 | -> Continue next request (call txstate)
310 |___________________________________|
311
312 * Non-Mentor DMA engines can of course work differently, such as by
313 * upleveling from irq-per-packet to irq-per-buffer.
314 */
315
316#endif
317
318/* 241/*
319 * An endpoint is transmitting data. This can be called either from 242 * An endpoint is transmitting data. This can be called either from
320 * the IRQ routine or from ep.queue() to kickstart a request on an 243 * the IRQ routine or from ep.queue() to kickstart a request on an
@@ -621,37 +544,6 @@ void musb_g_tx(struct musb *musb, u8 epnum)
621 544
622/* ------------------------------------------------------------ */ 545/* ------------------------------------------------------------ */
623 546
624#ifdef CONFIG_USB_INVENTRA_DMA
625
626/* Peripheral rx (OUT) using Mentor DMA works as follows:
627 - Only mode 0 is used.
628
629 - Request is queued by the gadget class driver.
630 -> if queue was previously empty, rxstate()
631
632 - Host sends OUT token which causes an endpoint interrupt
633 /\ -> RxReady
634 | -> if request queued, call rxstate
635 | /\ -> setup DMA
636 | | -> DMA interrupt on completion
637 | | -> RxReady
638 | | -> stop DMA
639 | | -> ack the read
640 | | -> if data recd = max expected
641 | | by the request, or host
642 | | sent a short packet,
643 | | complete the request,
644 | | and start the next one.
645 | |_____________________________________|
646 | else just wait for the host
647 | to send the next OUT token.
648 |__________________________________________________|
649
650 * Non-Mentor DMA engines can of course work differently.
651 */
652
653#endif
654
655/* 547/*
656 * Context: controller locked, IRQs blocked, endpoint selected 548 * Context: controller locked, IRQs blocked, endpoint selected
657 */ 549 */
@@ -740,7 +632,7 @@ static void rxstate(struct musb *musb, struct musb_request *req)
740 struct dma_controller *c; 632 struct dma_controller *c;
741 struct dma_channel *channel; 633 struct dma_channel *channel;
742 int use_dma = 0; 634 int use_dma = 0;
743 int transfer_size; 635 unsigned int transfer_size;
744 636
745 c = musb->dma_controller; 637 c = musb->dma_controller;
746 channel = musb_ep->dma; 638 channel = musb_ep->dma;
@@ -782,10 +674,11 @@ static void rxstate(struct musb *musb, struct musb_request *req)
782 csr | MUSB_RXCSR_DMAMODE); 674 csr | MUSB_RXCSR_DMAMODE);
783 musb_writew(epio, MUSB_RXCSR, csr); 675 musb_writew(epio, MUSB_RXCSR, csr);
784 676
785 transfer_size = min(request->length - request->actual, 677 transfer_size = min_t(unsigned int,
678 request->length -
679 request->actual,
786 channel->max_len); 680 channel->max_len);
787 musb_ep->dma->desired_mode = 1; 681 musb_ep->dma->desired_mode = 1;
788
789 } else { 682 } else {
790 if (!musb_ep->hb_mult && 683 if (!musb_ep->hb_mult &&
791 musb_ep->hw_ep->rx_double_buffered) 684 musb_ep->hw_ep->rx_double_buffered)
@@ -815,7 +708,7 @@ static void rxstate(struct musb *musb, struct musb_request *req)
815 708
816 struct dma_controller *c; 709 struct dma_controller *c;
817 struct dma_channel *channel; 710 struct dma_channel *channel;
818 int transfer_size = 0; 711 unsigned int transfer_size = 0;
819 712
820 c = musb->dma_controller; 713 c = musb->dma_controller;
821 channel = musb_ep->dma; 714 channel = musb_ep->dma;
@@ -824,11 +717,13 @@ static void rxstate(struct musb *musb, struct musb_request *req)
824 if (fifo_count < musb_ep->packet_sz) 717 if (fifo_count < musb_ep->packet_sz)
825 transfer_size = fifo_count; 718 transfer_size = fifo_count;
826 else if (request->short_not_ok) 719 else if (request->short_not_ok)
827 transfer_size = min(request->length - 720 transfer_size = min_t(unsigned int,
721 request->length -
828 request->actual, 722 request->actual,
829 channel->max_len); 723 channel->max_len);
830 else 724 else
831 transfer_size = min(request->length - 725 transfer_size = min_t(unsigned int,
726 request->length -
832 request->actual, 727 request->actual,
833 (unsigned)fifo_count); 728 (unsigned)fifo_count);
834 729
@@ -1681,7 +1576,7 @@ static int musb_gadget_wakeup(struct usb_gadget *gadget)
1681 goto done; 1576 goto done;
1682 default: 1577 default:
1683 dev_dbg(musb->controller, "Unhandled wake: %s\n", 1578 dev_dbg(musb->controller, "Unhandled wake: %s\n",
1684 otg_state_string(musb->xceiv->state)); 1579 usb_otg_state_string(musb->xceiv->state));
1685 goto done; 1580 goto done;
1686 } 1581 }
1687 1582
@@ -1801,13 +1696,6 @@ static const struct usb_gadget_ops musb_gadget_operations = {
1801 * all peripheral ports are external... 1696 * all peripheral ports are external...
1802 */ 1697 */
1803 1698
1804static void musb_gadget_release(struct device *dev)
1805{
1806 /* kref_put(WHAT) */
1807 dev_dbg(dev, "%s\n", __func__);
1808}
1809
1810
1811static void 1699static void
1812init_peripheral_ep(struct musb *musb, struct musb_ep *ep, u8 epnum, int is_in) 1700init_peripheral_ep(struct musb *musb, struct musb_ep *ep, u8 epnum, int is_in)
1813{ 1701{
@@ -1892,12 +1780,7 @@ int musb_gadget_setup(struct musb *musb)
1892 musb->g.speed = USB_SPEED_UNKNOWN; 1780 musb->g.speed = USB_SPEED_UNKNOWN;
1893 1781
1894 /* this "gadget" abstracts/virtualizes the controller */ 1782 /* this "gadget" abstracts/virtualizes the controller */
1895 dev_set_name(&musb->g.dev, "gadget");
1896 musb->g.dev.parent = musb->controller;
1897 musb->g.dev.dma_mask = musb->controller->dma_mask;
1898 musb->g.dev.release = musb_gadget_release;
1899 musb->g.name = musb_driver_name; 1783 musb->g.name = musb_driver_name;
1900
1901 musb->g.is_otg = 1; 1784 musb->g.is_otg = 1;
1902 1785
1903 musb_g_init_endpoints(musb); 1786 musb_g_init_endpoints(musb);
@@ -1905,11 +1788,6 @@ int musb_gadget_setup(struct musb *musb)
1905 musb->is_active = 0; 1788 musb->is_active = 0;
1906 musb_platform_try_idle(musb, 0); 1789 musb_platform_try_idle(musb, 0);
1907 1790
1908 status = device_register(&musb->g.dev);
1909 if (status != 0) {
1910 put_device(&musb->g.dev);
1911 return status;
1912 }
1913 status = usb_add_gadget_udc(musb->controller, &musb->g); 1791 status = usb_add_gadget_udc(musb->controller, &musb->g);
1914 if (status) 1792 if (status)
1915 goto err; 1793 goto err;
@@ -1924,8 +1802,6 @@ err:
1924void musb_gadget_cleanup(struct musb *musb) 1802void musb_gadget_cleanup(struct musb *musb)
1925{ 1803{
1926 usb_del_gadget_udc(&musb->g); 1804 usb_del_gadget_udc(&musb->g);
1927 if (musb->g.dev.parent)
1928 device_unregister(&musb->g.dev);
1929} 1805}
1930 1806
1931/* 1807/*
@@ -1977,9 +1853,8 @@ static int musb_gadget_start(struct usb_gadget *g,
1977 goto err; 1853 goto err;
1978 } 1854 }
1979 1855
1980 if ((musb->xceiv->last_event == USB_EVENT_ID) 1856 if (musb->xceiv->last_event == USB_EVENT_ID)
1981 && otg->set_vbus) 1857 musb_platform_set_vbus(musb, 1);
1982 otg_set_vbus(otg, 1);
1983 1858
1984 hcd->self.uses_pio_for_control = 1; 1859 hcd->self.uses_pio_for_control = 1;
1985 1860
@@ -2063,6 +1938,7 @@ static int musb_gadget_stop(struct usb_gadget *g,
2063 dev_dbg(musb->controller, "unregistering driver %s\n", driver->function); 1938 dev_dbg(musb->controller, "unregistering driver %s\n", driver->function);
2064 1939
2065 musb->is_active = 0; 1940 musb->is_active = 0;
1941 musb->gadget_driver = NULL;
2066 musb_platform_try_idle(musb, 0); 1942 musb_platform_try_idle(musb, 0);
2067 spin_unlock_irqrestore(&musb->lock, flags); 1943 spin_unlock_irqrestore(&musb->lock, flags);
2068 1944
@@ -2099,7 +1975,7 @@ void musb_g_resume(struct musb *musb)
2099 break; 1975 break;
2100 default: 1976 default:
2101 WARNING("unhandled RESUME transition (%s)\n", 1977 WARNING("unhandled RESUME transition (%s)\n",
2102 otg_state_string(musb->xceiv->state)); 1978 usb_otg_state_string(musb->xceiv->state));
2103 } 1979 }
2104} 1980}
2105 1981
@@ -2129,7 +2005,7 @@ void musb_g_suspend(struct musb *musb)
2129 * A_PERIPHERAL may need care too 2005 * A_PERIPHERAL may need care too
2130 */ 2006 */
2131 WARNING("unhandled SUSPEND transition (%s)\n", 2007 WARNING("unhandled SUSPEND transition (%s)\n",
2132 otg_state_string(musb->xceiv->state)); 2008 usb_otg_state_string(musb->xceiv->state));
2133 } 2009 }
2134} 2010}
2135 2011
@@ -2163,7 +2039,7 @@ void musb_g_disconnect(struct musb *musb)
2163 switch (musb->xceiv->state) { 2039 switch (musb->xceiv->state) {
2164 default: 2040 default:
2165 dev_dbg(musb->controller, "Unhandled disconnect %s, setting a_idle\n", 2041 dev_dbg(musb->controller, "Unhandled disconnect %s, setting a_idle\n",
2166 otg_state_string(musb->xceiv->state)); 2042 usb_otg_state_string(musb->xceiv->state));
2167 musb->xceiv->state = OTG_STATE_A_IDLE; 2043 musb->xceiv->state = OTG_STATE_A_IDLE;
2168 MUSB_HST_MODE(musb); 2044 MUSB_HST_MODE(musb);
2169 break; 2045 break;
diff --git a/drivers/usb/musb/musb_gadget_ep0.c b/drivers/usb/musb/musb_gadget_ep0.c
index c9c1ac4e075f..2af45a0c8930 100644
--- a/drivers/usb/musb/musb_gadget_ep0.c
+++ b/drivers/usb/musb/musb_gadget_ep0.c
@@ -505,8 +505,10 @@ static void ep0_rxstate(struct musb *musb)
505 req->status = -EOVERFLOW; 505 req->status = -EOVERFLOW;
506 count = len; 506 count = len;
507 } 507 }
508 musb_read_fifo(&musb->endpoints[0], count, buf); 508 if (count > 0) {
509 req->actual += count; 509 musb_read_fifo(&musb->endpoints[0], count, buf);
510 req->actual += count;
511 }
510 csr = MUSB_CSR0_P_SVDRXPKTRDY; 512 csr = MUSB_CSR0_P_SVDRXPKTRDY;
511 if (count < 64 || req->actual == req->length) { 513 if (count < 64 || req->actual == req->length) {
512 musb->ep0_state = MUSB_EP0_STAGE_STATUSIN; 514 musb->ep0_state = MUSB_EP0_STAGE_STATUSIN;
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index 1ce1fcf3f3e7..8914dec49f01 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -2453,7 +2453,7 @@ static int musb_bus_suspend(struct usb_hcd *hcd)
2453 2453
2454 if (musb->is_active) { 2454 if (musb->is_active) {
2455 WARNING("trying to suspend as %s while active\n", 2455 WARNING("trying to suspend as %s while active\n",
2456 otg_state_string(musb->xceiv->state)); 2456 usb_otg_state_string(musb->xceiv->state));
2457 return -EBUSY; 2457 return -EBUSY;
2458 } else 2458 } else
2459 return 0; 2459 return 0;
@@ -2465,6 +2465,118 @@ static int musb_bus_resume(struct usb_hcd *hcd)
2465 return 0; 2465 return 0;
2466} 2466}
2467 2467
2468
2469#ifndef CONFIG_MUSB_PIO_ONLY
2470
2471#define MUSB_USB_DMA_ALIGN 4
2472
2473struct musb_temp_buffer {
2474 void *kmalloc_ptr;
2475 void *old_xfer_buffer;
2476 u8 data[0];
2477};
2478
2479static void musb_free_temp_buffer(struct urb *urb)
2480{
2481 enum dma_data_direction dir;
2482 struct musb_temp_buffer *temp;
2483
2484 if (!(urb->transfer_flags & URB_ALIGNED_TEMP_BUFFER))
2485 return;
2486
2487 dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
2488
2489 temp = container_of(urb->transfer_buffer, struct musb_temp_buffer,
2490 data);
2491
2492 if (dir == DMA_FROM_DEVICE) {
2493 memcpy(temp->old_xfer_buffer, temp->data,
2494 urb->transfer_buffer_length);
2495 }
2496 urb->transfer_buffer = temp->old_xfer_buffer;
2497 kfree(temp->kmalloc_ptr);
2498
2499 urb->transfer_flags &= ~URB_ALIGNED_TEMP_BUFFER;
2500}
2501
2502static int musb_alloc_temp_buffer(struct urb *urb, gfp_t mem_flags)
2503{
2504 enum dma_data_direction dir;
2505 struct musb_temp_buffer *temp;
2506 void *kmalloc_ptr;
2507 size_t kmalloc_size;
2508
2509 if (urb->num_sgs || urb->sg ||
2510 urb->transfer_buffer_length == 0 ||
2511 !((uintptr_t)urb->transfer_buffer & (MUSB_USB_DMA_ALIGN - 1)))
2512 return 0;
2513
2514 dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
2515
2516 /* Allocate a buffer with enough padding for alignment */
2517 kmalloc_size = urb->transfer_buffer_length +
2518 sizeof(struct musb_temp_buffer) + MUSB_USB_DMA_ALIGN - 1;
2519
2520 kmalloc_ptr = kmalloc(kmalloc_size, mem_flags);
2521 if (!kmalloc_ptr)
2522 return -ENOMEM;
2523
2524 /* Position our struct temp_buffer such that data is aligned */
2525 temp = PTR_ALIGN(kmalloc_ptr, MUSB_USB_DMA_ALIGN);
2526
2527
2528 temp->kmalloc_ptr = kmalloc_ptr;
2529 temp->old_xfer_buffer = urb->transfer_buffer;
2530 if (dir == DMA_TO_DEVICE)
2531 memcpy(temp->data, urb->transfer_buffer,
2532 urb->transfer_buffer_length);
2533 urb->transfer_buffer = temp->data;
2534
2535 urb->transfer_flags |= URB_ALIGNED_TEMP_BUFFER;
2536
2537 return 0;
2538}
2539
2540static int musb_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
2541 gfp_t mem_flags)
2542{
2543 struct musb *musb = hcd_to_musb(hcd);
2544 int ret;
2545
2546 /*
2547 * The DMA engine in RTL1.8 and above cannot handle
2548 * DMA addresses that are not aligned to a 4 byte boundary.
2549 * For such engine implemented (un)map_urb_for_dma hooks.
2550 * Do not use these hooks for RTL<1.8
2551 */
2552 if (musb->hwvers < MUSB_HWVERS_1800)
2553 return usb_hcd_map_urb_for_dma(hcd, urb, mem_flags);
2554
2555 ret = musb_alloc_temp_buffer(urb, mem_flags);
2556 if (ret)
2557 return ret;
2558
2559 ret = usb_hcd_map_urb_for_dma(hcd, urb, mem_flags);
2560 if (ret)
2561 musb_free_temp_buffer(urb);
2562
2563 return ret;
2564}
2565
2566static void musb_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
2567{
2568 struct musb *musb = hcd_to_musb(hcd);
2569
2570 usb_hcd_unmap_urb_for_dma(hcd, urb);
2571
2572 /* Do not use this hook for RTL<1.8 (see description above) */
2573 if (musb->hwvers < MUSB_HWVERS_1800)
2574 return;
2575
2576 musb_free_temp_buffer(urb);
2577}
2578#endif /* !CONFIG_MUSB_PIO_ONLY */
2579
2468const struct hc_driver musb_hc_driver = { 2580const struct hc_driver musb_hc_driver = {
2469 .description = "musb-hcd", 2581 .description = "musb-hcd",
2470 .product_desc = "MUSB HDRC host driver", 2582 .product_desc = "MUSB HDRC host driver",
@@ -2484,6 +2596,11 @@ const struct hc_driver musb_hc_driver = {
2484 .urb_dequeue = musb_urb_dequeue, 2596 .urb_dequeue = musb_urb_dequeue,
2485 .endpoint_disable = musb_h_disable, 2597 .endpoint_disable = musb_h_disable,
2486 2598
2599#ifndef CONFIG_MUSB_PIO_ONLY
2600 .map_urb_for_dma = musb_map_urb_for_dma,
2601 .unmap_urb_for_dma = musb_unmap_urb_for_dma,
2602#endif
2603
2487 .hub_status_data = musb_hub_status_data, 2604 .hub_status_data = musb_hub_status_data,
2488 .hub_control = musb_hub_control, 2605 .hub_control = musb_hub_control,
2489 .bus_suspend = musb_bus_suspend, 2606 .bus_suspend = musb_bus_suspend,
diff --git a/drivers/usb/musb/musb_virthub.c b/drivers/usb/musb/musb_virthub.c
index f70579154ded..ef7d11045f56 100644
--- a/drivers/usb/musb/musb_virthub.c
+++ b/drivers/usb/musb/musb_virthub.c
@@ -95,7 +95,7 @@ static void musb_port_suspend(struct musb *musb, bool do_suspend)
95 break; 95 break;
96 default: 96 default:
97 dev_dbg(musb->controller, "bogus rh suspend? %s\n", 97 dev_dbg(musb->controller, "bogus rh suspend? %s\n",
98 otg_state_string(musb->xceiv->state)); 98 usb_otg_state_string(musb->xceiv->state));
99 } 99 }
100 } else if (power & MUSB_POWER_SUSPENDM) { 100 } else if (power & MUSB_POWER_SUSPENDM) {
101 power &= ~MUSB_POWER_SUSPENDM; 101 power &= ~MUSB_POWER_SUSPENDM;
@@ -203,7 +203,7 @@ void musb_root_disconnect(struct musb *musb)
203 break; 203 break;
204 default: 204 default:
205 dev_dbg(musb->controller, "host disconnect (%s)\n", 205 dev_dbg(musb->controller, "host disconnect (%s)\n",
206 otg_state_string(musb->xceiv->state)); 206 usb_otg_state_string(musb->xceiv->state));
207 } 207 }
208} 208}
209 209
diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index 1a42a458f2c4..3551f1a30c65 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -117,7 +117,7 @@ static void omap2430_musb_try_idle(struct musb *musb, unsigned long timeout)
117 if (musb->is_active || ((musb->a_wait_bcon == 0) 117 if (musb->is_active || ((musb->a_wait_bcon == 0)
118 && (musb->xceiv->state == OTG_STATE_A_WAIT_BCON))) { 118 && (musb->xceiv->state == OTG_STATE_A_WAIT_BCON))) {
119 dev_dbg(musb->controller, "%s active, deleting timer\n", 119 dev_dbg(musb->controller, "%s active, deleting timer\n",
120 otg_state_string(musb->xceiv->state)); 120 usb_otg_state_string(musb->xceiv->state));
121 del_timer(&musb_idle_timer); 121 del_timer(&musb_idle_timer);
122 last_timer = jiffies; 122 last_timer = jiffies;
123 return; 123 return;
@@ -134,7 +134,7 @@ static void omap2430_musb_try_idle(struct musb *musb, unsigned long timeout)
134 last_timer = timeout; 134 last_timer = timeout;
135 135
136 dev_dbg(musb->controller, "%s inactive, for idle timer for %lu ms\n", 136 dev_dbg(musb->controller, "%s inactive, for idle timer for %lu ms\n",
137 otg_state_string(musb->xceiv->state), 137 usb_otg_state_string(musb->xceiv->state),
138 (unsigned long)jiffies_to_msecs(timeout - jiffies)); 138 (unsigned long)jiffies_to_msecs(timeout - jiffies));
139 mod_timer(&musb_idle_timer, timeout); 139 mod_timer(&musb_idle_timer, timeout);
140} 140}
@@ -174,8 +174,7 @@ static void omap2430_musb_set_vbus(struct musb *musb, int is_on)
174 } 174 }
175 } 175 }
176 176
177 if (otg->set_vbus) 177 otg_set_vbus(otg, 1);
178 otg_set_vbus(otg, 1);
179 } else { 178 } else {
180 musb->is_active = 1; 179 musb->is_active = 1;
181 otg->default_a = 1; 180 otg->default_a = 1;
@@ -200,7 +199,7 @@ static void omap2430_musb_set_vbus(struct musb *musb, int is_on)
200 199
201 dev_dbg(musb->controller, "VBUS %s, devctl %02x " 200 dev_dbg(musb->controller, "VBUS %s, devctl %02x "
202 /* otg %3x conf %08x prcm %08x */ "\n", 201 /* otg %3x conf %08x prcm %08x */ "\n",
203 otg_state_string(musb->xceiv->state), 202 usb_otg_state_string(musb->xceiv->state),
204 musb_readb(musb->mregs, MUSB_DEVCTL)); 203 musb_readb(musb->mregs, MUSB_DEVCTL));
205} 204}
206 205
@@ -292,14 +291,14 @@ static void omap_musb_set_mailbox(struct omap2430_glue *glue)
292 291
293 musb->xceiv->last_event = USB_EVENT_NONE; 292 musb->xceiv->last_event = USB_EVENT_NONE;
294 if (musb->gadget_driver) { 293 if (musb->gadget_driver) {
294 omap2430_musb_set_vbus(musb, 0);
295 pm_runtime_mark_last_busy(dev); 295 pm_runtime_mark_last_busy(dev);
296 pm_runtime_put_autosuspend(dev); 296 pm_runtime_put_autosuspend(dev);
297 } 297 }
298 298
299 if (data->interface_type == MUSB_INTERFACE_UTMI) { 299 if (data->interface_type == MUSB_INTERFACE_UTMI)
300 if (musb->xceiv->otg->set_vbus) 300 otg_set_vbus(musb->xceiv->otg, 0);
301 otg_set_vbus(musb->xceiv->otg, 0); 301
302 }
303 omap_control_usb_set_mode(glue->control_otghs, 302 omap_control_usb_set_mode(glue->control_otghs,
304 USB_MODE_DISCONNECT); 303 USB_MODE_DISCONNECT);
305 break; 304 break;
@@ -355,7 +354,12 @@ static int omap2430_musb_init(struct musb *musb)
355 else 354 else
356 musb->xceiv = devm_usb_get_phy_dev(dev, 0); 355 musb->xceiv = devm_usb_get_phy_dev(dev, 0);
357 356
358 if (IS_ERR_OR_NULL(musb->xceiv)) { 357 if (IS_ERR(musb->xceiv)) {
358 status = PTR_ERR(musb->xceiv);
359
360 if (status == -ENXIO)
361 return status;
362
359 pr_err("HS USB OTG: no transceiver configured\n"); 363 pr_err("HS USB OTG: no transceiver configured\n");
360 return -EPROBE_DEFER; 364 return -EPROBE_DEFER;
361 } 365 }
@@ -393,6 +397,8 @@ static int omap2430_musb_init(struct musb *musb)
393 if (glue->status != OMAP_MUSB_UNKNOWN) 397 if (glue->status != OMAP_MUSB_UNKNOWN)
394 omap_musb_set_mailbox(glue); 398 omap_musb_set_mailbox(glue);
395 399
400 usb_phy_init(musb->xceiv);
401
396 pm_runtime_put_noidle(musb->controller); 402 pm_runtime_put_noidle(musb->controller);
397 return 0; 403 return 0;
398 404
@@ -526,10 +532,10 @@ static int omap2430_probe(struct platform_device *pdev)
526 } 532 }
527 533
528 of_property_read_u32(np, "mode", (u32 *)&pdata->mode); 534 of_property_read_u32(np, "mode", (u32 *)&pdata->mode);
529 of_property_read_u32(np, "interface_type", 535 of_property_read_u32(np, "interface-type",
530 (u32 *)&data->interface_type); 536 (u32 *)&data->interface_type);
531 of_property_read_u32(np, "num_eps", (u32 *)&config->num_eps); 537 of_property_read_u32(np, "num-eps", (u32 *)&config->num_eps);
532 of_property_read_u32(np, "ram_bits", (u32 *)&config->ram_bits); 538 of_property_read_u32(np, "ram-bits", (u32 *)&config->ram_bits);
533 of_property_read_u32(np, "power", (u32 *)&pdata->power); 539 of_property_read_u32(np, "power", (u32 *)&pdata->power);
534 config->multipoint = of_property_read_bool(np, "multipoint"); 540 config->multipoint = of_property_read_bool(np, "multipoint");
535 pdata->has_mailbox = of_property_read_bool(np, 541 pdata->has_mailbox = of_property_read_bool(np,
diff --git a/drivers/usb/musb/tusb6010.c b/drivers/usb/musb/tusb6010.c
index 464bd23cccda..7369ba33c94f 100644
--- a/drivers/usb/musb/tusb6010.c
+++ b/drivers/usb/musb/tusb6010.c
@@ -423,7 +423,7 @@ static void musb_do_idle(unsigned long _musb)
423 && (musb->idle_timeout == 0 423 && (musb->idle_timeout == 0
424 || time_after(jiffies, musb->idle_timeout))) { 424 || time_after(jiffies, musb->idle_timeout))) {
425 dev_dbg(musb->controller, "Nothing connected %s, turning off VBUS\n", 425 dev_dbg(musb->controller, "Nothing connected %s, turning off VBUS\n",
426 otg_state_string(musb->xceiv->state)); 426 usb_otg_state_string(musb->xceiv->state));
427 } 427 }
428 /* FALLTHROUGH */ 428 /* FALLTHROUGH */
429 case OTG_STATE_A_IDLE: 429 case OTG_STATE_A_IDLE:
@@ -478,7 +478,7 @@ static void tusb_musb_try_idle(struct musb *musb, unsigned long timeout)
478 if (musb->is_active || ((musb->a_wait_bcon == 0) 478 if (musb->is_active || ((musb->a_wait_bcon == 0)
479 && (musb->xceiv->state == OTG_STATE_A_WAIT_BCON))) { 479 && (musb->xceiv->state == OTG_STATE_A_WAIT_BCON))) {
480 dev_dbg(musb->controller, "%s active, deleting timer\n", 480 dev_dbg(musb->controller, "%s active, deleting timer\n",
481 otg_state_string(musb->xceiv->state)); 481 usb_otg_state_string(musb->xceiv->state));
482 del_timer(&musb_idle_timer); 482 del_timer(&musb_idle_timer);
483 last_timer = jiffies; 483 last_timer = jiffies;
484 return; 484 return;
@@ -495,7 +495,7 @@ static void tusb_musb_try_idle(struct musb *musb, unsigned long timeout)
495 last_timer = timeout; 495 last_timer = timeout;
496 496
497 dev_dbg(musb->controller, "%s inactive, for idle timer for %lu ms\n", 497 dev_dbg(musb->controller, "%s inactive, for idle timer for %lu ms\n",
498 otg_state_string(musb->xceiv->state), 498 usb_otg_state_string(musb->xceiv->state),
499 (unsigned long)jiffies_to_msecs(timeout - jiffies)); 499 (unsigned long)jiffies_to_msecs(timeout - jiffies));
500 mod_timer(&musb_idle_timer, timeout); 500 mod_timer(&musb_idle_timer, timeout);
501} 501}
@@ -571,7 +571,7 @@ static void tusb_musb_set_vbus(struct musb *musb, int is_on)
571 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); 571 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
572 572
573 dev_dbg(musb->controller, "VBUS %s, devctl %02x otg %3x conf %08x prcm %08x\n", 573 dev_dbg(musb->controller, "VBUS %s, devctl %02x otg %3x conf %08x prcm %08x\n",
574 otg_state_string(musb->xceiv->state), 574 usb_otg_state_string(musb->xceiv->state),
575 musb_readb(musb->mregs, MUSB_DEVCTL), 575 musb_readb(musb->mregs, MUSB_DEVCTL),
576 musb_readl(tbase, TUSB_DEV_OTG_STAT), 576 musb_readl(tbase, TUSB_DEV_OTG_STAT),
577 conf, prcm); 577 conf, prcm);
@@ -678,13 +678,13 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *tbase)
678 musb->is_active = 0; 678 musb->is_active = 0;
679 } 679 }
680 dev_dbg(musb->controller, "vbus change, %s, otg %03x\n", 680 dev_dbg(musb->controller, "vbus change, %s, otg %03x\n",
681 otg_state_string(musb->xceiv->state), otg_stat); 681 usb_otg_state_string(musb->xceiv->state), otg_stat);
682 idle_timeout = jiffies + (1 * HZ); 682 idle_timeout = jiffies + (1 * HZ);
683 schedule_work(&musb->irq_work); 683 schedule_work(&musb->irq_work);
684 684
685 } else /* A-dev state machine */ { 685 } else /* A-dev state machine */ {
686 dev_dbg(musb->controller, "vbus change, %s, otg %03x\n", 686 dev_dbg(musb->controller, "vbus change, %s, otg %03x\n",
687 otg_state_string(musb->xceiv->state), otg_stat); 687 usb_otg_state_string(musb->xceiv->state), otg_stat);
688 688
689 switch (musb->xceiv->state) { 689 switch (musb->xceiv->state) {
690 case OTG_STATE_A_IDLE: 690 case OTG_STATE_A_IDLE:
@@ -733,7 +733,7 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *tbase)
733 u8 devctl; 733 u8 devctl;
734 734
735 dev_dbg(musb->controller, "%s timer, %03x\n", 735 dev_dbg(musb->controller, "%s timer, %03x\n",
736 otg_state_string(musb->xceiv->state), otg_stat); 736 usb_otg_state_string(musb->xceiv->state), otg_stat);
737 737
738 switch (musb->xceiv->state) { 738 switch (musb->xceiv->state) {
739 case OTG_STATE_A_WAIT_VRISE: 739 case OTG_STATE_A_WAIT_VRISE:
diff --git a/drivers/usb/musb/ux500.c b/drivers/usb/musb/ux500.c
index 13a392913769..2c80004e0a83 100644
--- a/drivers/usb/musb/ux500.c
+++ b/drivers/usb/musb/ux500.c
@@ -26,6 +26,7 @@
26#include <linux/err.h> 26#include <linux/err.h>
27#include <linux/io.h> 27#include <linux/io.h>
28#include <linux/platform_device.h> 28#include <linux/platform_device.h>
29#include <linux/usb/musb-ux500.h>
29 30
30#include "musb_core.h" 31#include "musb_core.h"
31 32
@@ -36,6 +37,98 @@ struct ux500_glue {
36}; 37};
37#define glue_to_musb(g) platform_get_drvdata(g->musb) 38#define glue_to_musb(g) platform_get_drvdata(g->musb)
38 39
40static void ux500_musb_set_vbus(struct musb *musb, int is_on)
41{
42 u8 devctl;
43 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
44 /* HDRC controls CPEN, but beware current surges during device
45 * connect. They can trigger transient overcurrent conditions
46 * that must be ignored.
47 */
48
49 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
50
51 if (is_on) {
52 if (musb->xceiv->state == OTG_STATE_A_IDLE) {
53 /* start the session */
54 devctl |= MUSB_DEVCTL_SESSION;
55 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
56 /*
57 * Wait for the musb to set as A device to enable the
58 * VBUS
59 */
60 while (musb_readb(musb->mregs, MUSB_DEVCTL) & 0x80) {
61
62 if (time_after(jiffies, timeout)) {
63 dev_err(musb->controller,
64 "configured as A device timeout");
65 break;
66 }
67 }
68
69 } else {
70 musb->is_active = 1;
71 musb->xceiv->otg->default_a = 1;
72 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE;
73 devctl |= MUSB_DEVCTL_SESSION;
74 MUSB_HST_MODE(musb);
75 }
76 } else {
77 musb->is_active = 0;
78
79 /* NOTE: we're skipping A_WAIT_VFALL -> A_IDLE and jumping
80 * right to B_IDLE...
81 */
82 musb->xceiv->otg->default_a = 0;
83 devctl &= ~MUSB_DEVCTL_SESSION;
84 MUSB_DEV_MODE(musb);
85 }
86 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
87
88 /*
89 * Devctl values will be updated after vbus goes below
90 * session_valid. The time taken depends on the capacitance
91 * on VBUS line. The max discharge time can be upto 1 sec
92 * as per the spec. Typically on our platform, it is 200ms
93 */
94 if (!is_on)
95 mdelay(200);
96
97 dev_dbg(musb->controller, "VBUS %s, devctl %02x\n",
98 usb_otg_state_string(musb->xceiv->state),
99 musb_readb(musb->mregs, MUSB_DEVCTL));
100}
101
102static int musb_otg_notifications(struct notifier_block *nb,
103 unsigned long event, void *unused)
104{
105 struct musb *musb = container_of(nb, struct musb, nb);
106
107 dev_dbg(musb->controller, "musb_otg_notifications %ld %s\n",
108 event, usb_otg_state_string(musb->xceiv->state));
109
110 switch (event) {
111 case UX500_MUSB_ID:
112 dev_dbg(musb->controller, "ID GND\n");
113 ux500_musb_set_vbus(musb, 1);
114 break;
115 case UX500_MUSB_VBUS:
116 dev_dbg(musb->controller, "VBUS Connect\n");
117 break;
118 case UX500_MUSB_NONE:
119 dev_dbg(musb->controller, "VBUS Disconnect\n");
120 if (is_host_active(musb))
121 ux500_musb_set_vbus(musb, 0);
122 else
123 musb->xceiv->state = OTG_STATE_B_IDLE;
124 break;
125 default:
126 dev_dbg(musb->controller, "ID float\n");
127 return NOTIFY_DONE;
128 }
129 return NOTIFY_OK;
130}
131
39static irqreturn_t ux500_musb_interrupt(int irq, void *__hci) 132static irqreturn_t ux500_musb_interrupt(int irq, void *__hci)
40{ 133{
41 unsigned long flags; 134 unsigned long flags;
@@ -58,12 +151,21 @@ static irqreturn_t ux500_musb_interrupt(int irq, void *__hci)
58 151
59static int ux500_musb_init(struct musb *musb) 152static int ux500_musb_init(struct musb *musb)
60{ 153{
154 int status;
155
61 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); 156 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
62 if (IS_ERR_OR_NULL(musb->xceiv)) { 157 if (IS_ERR_OR_NULL(musb->xceiv)) {
63 pr_err("HS USB OTG: no transceiver configured\n"); 158 pr_err("HS USB OTG: no transceiver configured\n");
64 return -EPROBE_DEFER; 159 return -EPROBE_DEFER;
65 } 160 }
66 161
162 musb->nb.notifier_call = musb_otg_notifications;
163 status = usb_register_notifier(musb->xceiv, &musb->nb);
164 if (status < 0) {
165 dev_dbg(musb->controller, "notification register failed\n");
166 return status;
167 }
168
67 musb->isr = ux500_musb_interrupt; 169 musb->isr = ux500_musb_interrupt;
68 170
69 return 0; 171 return 0;
@@ -71,6 +173,8 @@ static int ux500_musb_init(struct musb *musb)
71 173
72static int ux500_musb_exit(struct musb *musb) 174static int ux500_musb_exit(struct musb *musb)
73{ 175{
176 usb_unregister_notifier(musb->xceiv, &musb->nb);
177
74 usb_put_phy(musb->xceiv); 178 usb_put_phy(musb->xceiv);
75 179
76 return 0; 180 return 0;
@@ -79,6 +183,8 @@ static int ux500_musb_exit(struct musb *musb)
79static const struct musb_platform_ops ux500_ops = { 183static const struct musb_platform_ops ux500_ops = {
80 .init = ux500_musb_init, 184 .init = ux500_musb_init,
81 .exit = ux500_musb_exit, 185 .exit = ux500_musb_exit,
186
187 .set_vbus = ux500_musb_set_vbus,
82}; 188};
83 189
84static int ux500_probe(struct platform_device *pdev) 190static int ux500_probe(struct platform_device *pdev)
diff --git a/drivers/usb/musb/ux500_dma.c b/drivers/usb/musb/ux500_dma.c
index 039e567dd3b6..338120641145 100644
--- a/drivers/usb/musb/ux500_dma.c
+++ b/drivers/usb/musb/ux500_dma.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * drivers/usb/musb/ux500_dma.c 2 * drivers/usb/musb/ux500_dma.c
3 * 3 *
4 * U8500 and U5500 DMA support code 4 * U8500 DMA support code
5 * 5 *
6 * Copyright (C) 2009 STMicroelectronics 6 * Copyright (C) 2009 STMicroelectronics
7 * Copyright (C) 2011 ST-Ericsson SA 7 * Copyright (C) 2011 ST-Ericsson SA
@@ -30,6 +30,7 @@
30#include <linux/dma-mapping.h> 30#include <linux/dma-mapping.h>
31#include <linux/dmaengine.h> 31#include <linux/dmaengine.h>
32#include <linux/pfn.h> 32#include <linux/pfn.h>
33#include <linux/sizes.h>
33#include <linux/platform_data/usb-musb-ux500.h> 34#include <linux/platform_data/usb-musb-ux500.h>
34#include "musb_core.h" 35#include "musb_core.h"
35 36
@@ -56,7 +57,7 @@ struct ux500_dma_controller {
56}; 57};
57 58
58/* Work function invoked from DMA callback to handle rx transfers. */ 59/* Work function invoked from DMA callback to handle rx transfers. */
59void ux500_dma_callback(void *private_data) 60static void ux500_dma_callback(void *private_data)
60{ 61{
61 struct dma_channel *channel = private_data; 62 struct dma_channel *channel = private_data;
62 struct ux500_dma_channel *ux500_channel = channel->private_data; 63 struct ux500_dma_channel *ux500_channel = channel->private_data;
@@ -93,8 +94,9 @@ static bool ux500_configure_channel(struct dma_channel *channel,
93 struct musb *musb = ux500_channel->controller->private_data; 94 struct musb *musb = ux500_channel->controller->private_data;
94 95
95 dev_dbg(musb->controller, 96 dev_dbg(musb->controller,
96 "packet_sz=%d, mode=%d, dma_addr=0x%x, len=%d is_tx=%d\n", 97 "packet_sz=%d, mode=%d, dma_addr=0x%llu, len=%d is_tx=%d\n",
97 packet_sz, mode, dma_addr, len, ux500_channel->is_tx); 98 packet_sz, mode, (unsigned long long) dma_addr,
99 len, ux500_channel->is_tx);
98 100
99 ux500_channel->cur_len = len; 101 ux500_channel->cur_len = len;
100 102
@@ -191,7 +193,7 @@ static int ux500_dma_is_compatible(struct dma_channel *channel,
191 u16 maxpacket, void *buf, u32 length) 193 u16 maxpacket, void *buf, u32 length)
192{ 194{
193 if ((maxpacket & 0x3) || 195 if ((maxpacket & 0x3) ||
194 ((int)buf & 0x3) || 196 ((unsigned long int) buf & 0x3) ||
195 (length < 512) || 197 (length < 512) ||
196 (length & 0x3)) 198 (length & 0x3))
197 return false; 199 return false;
@@ -372,12 +374,17 @@ struct dma_controller *dma_controller_create(struct musb *musb, void __iomem *ba
372 374
373 controller = kzalloc(sizeof(*controller), GFP_KERNEL); 375 controller = kzalloc(sizeof(*controller), GFP_KERNEL);
374 if (!controller) 376 if (!controller)
375 return NULL; 377 goto kzalloc_fail;
376 378
377 controller->private_data = musb; 379 controller->private_data = musb;
378 380
379 /* Save physical address for DMA controller. */ 381 /* Save physical address for DMA controller. */
380 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 382 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
383 if (!iomem) {
384 dev_err(musb->controller, "no memory resource defined\n");
385 goto plat_get_fail;
386 }
387
381 controller->phy_base = (dma_addr_t) iomem->start; 388 controller->phy_base = (dma_addr_t) iomem->start;
382 389
383 controller->controller.start = ux500_dma_controller_start; 390 controller->controller.start = ux500_dma_controller_start;
@@ -389,4 +396,9 @@ struct dma_controller *dma_controller_create(struct musb *musb, void __iomem *ba
389 controller->controller.is_compatible = ux500_dma_is_compatible; 396 controller->controller.is_compatible = ux500_dma_is_compatible;
390 397
391 return &controller->controller; 398 return &controller->controller;
399
400plat_get_fail:
401 kfree(controller);
402kzalloc_fail:
403 return NULL;
392} 404}