platform: msm_shared: Cleanup usb stop.

Change-Id: I9c860f2ae88bf2dc7fead5c4ea18f47998c99658
diff --git a/platform/msm_shared/hsusb.c b/platform/msm_shared/hsusb.c
index e5bd7b5..e44501f 100644
--- a/platform/msm_shared/hsusb.c
+++ b/platform/msm_shared/hsusb.c
@@ -2,7 +2,7 @@
  * Copyright (c) 2008, Google Inc.
  * All rights reserved.
  *
- * Copyright (c) 2009-2012, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2009-2013, The Linux Foundation. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -918,15 +918,26 @@
 
 int udc_stop(void)
 {
+	uint32_t val;
+
+	/* Flush all primed end points. */
+	writel(0xffffffff, USB_ENDPTFLUSH);
+
+	/* Stop controller. */
+	val = readl(USB_USBCMD);
+	writel(val & ~USBCMD_ATTACH, USB_USBCMD);
+
+	/* Mask the interrupts. */
 	writel(0, USB_USBINTR);
 	mask_interrupt(INT_USB_HS);
 
-	/* disable pullup */
-	writel(0x00080000, USB_USBCMD);
-
+	/* Perform any target specific clean up. */
 	target_usb_stop();
 
-	thread_sleep(10);
+	/* Reset the controller. */
+	writel(USBCMD_RESET, USB_USBCMD);
+	/* Wait until reset completes. */
+	while(readl(USB_USBCMD) & USBCMD_RESET);
 
 	return 0;
 }