Advertisement
m-ric

linaro-11.09_android-omap-panda-3.0_kernel-drivers-usb.diff

Jul 4th, 2012
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 57.75 KB | None | 0 0
  1. diff --git a/kernel_linaro/drivers/usb/gadget/android.c b/kernel/drivers/usb/gadget/android.c
  2. index b13633b..2b76310 100644
  3. --- a/kernel_linaro/drivers/usb/gadget/android.c
  4. +++ b/kernel/drivers/usb/gadget/android.c
  5. @@ -87,8 +87,7 @@ struct android_usb_function {
  6.  
  7.     /* Optional: called when the configuration is removed */
  8.     void (*unbind_config)(struct android_usb_function *, struct usb_configuration *);
  9. -   /* Optional: handle ctrl requests before the device is configured
  10. -    *  and/or before the function is enabled */
  11. +   /* Optional: handle ctrl requests before the device is configured */
  12.     int (*ctrlrequest)(struct android_usb_function *,
  13.                     struct usb_composite_dev *,
  14.                     const struct usb_ctrlrequest *);
  15. @@ -164,22 +163,23 @@ static void android_work(struct work_struct *data)
  16.     char *disconnected[2] = { "USB_STATE=DISCONNECTED", NULL };
  17.     char *connected[2]    = { "USB_STATE=CONNECTED", NULL };
  18.     char *configured[2]   = { "USB_STATE=CONFIGURED", NULL };
  19. +   char **uevent_envp = NULL;
  20.     unsigned long flags;
  21.  
  22.     spin_lock_irqsave(&cdev->lock, flags);
  23. -        if (cdev->config) {
  24. -       spin_unlock_irqrestore(&cdev->lock, flags);
  25. -       kobject_uevent_env(&dev->dev->kobj, KOBJ_CHANGE,
  26. -                           configured);
  27. -       return;
  28. -   }
  29. -   if (dev->connected != dev->sw_connected) {
  30. -       dev->sw_connected = dev->connected;
  31. -       spin_unlock_irqrestore(&cdev->lock, flags);
  32. -       kobject_uevent_env(&dev->dev->kobj, KOBJ_CHANGE,
  33. -               dev->sw_connected ? connected : disconnected);
  34. +        if (cdev->config)
  35. +       uevent_envp = configured;
  36. +   else if (dev->connected != dev->sw_connected)
  37. +       uevent_envp = dev->connected ? connected : disconnected;
  38. +   dev->sw_connected = dev->connected;
  39. +   spin_unlock_irqrestore(&cdev->lock, flags);
  40. +
  41. +   if (uevent_envp) {
  42. +       kobject_uevent_env(&dev->dev->kobj, KOBJ_CHANGE, uevent_envp);
  43. +       pr_info("%s: sent uevent %s\n", __func__, uevent_envp[0]);
  44.     } else {
  45. -       spin_unlock_irqrestore(&cdev->lock, flags);
  46. +       pr_info("%s: did not send uevent (%d %d %p)\n", __func__,
  47. +            dev->connected, dev->sw_connected, cdev->config);
  48.     }
  49.  }
  50.  
  51. @@ -823,6 +823,7 @@ static ssize_t enable_store(struct device *pdev, struct device_attribute *attr,
  52.  
  53.     sscanf(buff, "%d", &enabled);
  54.     if (enabled && !dev->enabled) {
  55. +       cdev->next_string_id = 0;
  56.         /* update values in composite driver's copy of device descriptor */
  57.         cdev->desc.idVendor = device_desc.idVendor;
  58.         cdev->desc.idProduct = device_desc.idProduct;
  59. @@ -836,6 +837,8 @@ static ssize_t enable_store(struct device *pdev, struct device_attribute *attr,
  60.         dev->enabled = true;
  61.     } else if (!enabled && dev->enabled) {
  62.         usb_gadget_disconnect(cdev->gadget);
  63. +       /* Cancel pending control requests */
  64. +       usb_ep_dequeue(cdev->gadget->ep0, cdev->req);
  65.         usb_remove_config(cdev, &android_config_driver);
  66.         dev->enabled = false;
  67.     } else {
  68. @@ -1057,6 +1060,12 @@ android_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *c)
  69.         }
  70.     }
  71.  
  72. +   /* Special case the accessory function.
  73. +    * It needs to handle control requests before it is enabled.
  74. +    */
  75. +   if (value < 0)
  76. +       value = acc_ctrlrequest(cdev, c);
  77. +
  78.     if (value < 0)
  79.         value = composite_setup(gadget, c);
  80.  
  81. @@ -1076,9 +1085,15 @@ android_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *c)
  82.  static void android_disconnect(struct usb_gadget *gadget)
  83.  {
  84.     struct android_dev *dev = _android_dev;
  85. +   struct usb_composite_dev *cdev = get_gadget_data(gadget);
  86. +   unsigned long flags;
  87. +
  88. +   composite_disconnect(gadget);
  89. +
  90. +   spin_lock_irqsave(&cdev->lock, flags);
  91.     dev->connected = 0;
  92.     schedule_work(&dev->work);
  93. -   composite_disconnect(gadget);
  94. +   spin_unlock_irqrestore(&cdev->lock, flags);
  95.  }
  96.  
  97.  static int android_create_device(struct android_dev *dev)
  98. diff --git a/kernel_linaro/drivers/usb/host/ehci-hub.c b/kernel/drivers/usb/host/ehci-hub.c
  99. index 88cfb8f..0f3a724 100644
  100. --- a/kernel_linaro/drivers/usb/host/ehci-hub.c
  101. +++ b/kernel/drivers/usb/host/ehci-hub.c
  102. @@ -343,7 +343,7 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
  103.     u32         temp;
  104.     u32         power_okay;
  105.     int         i;
  106. -   u8          resume_needed = 0;
  107. +   unsigned long       resume_needed = 0;
  108.  
  109.     if (time_before (jiffies, ehci->next_statechange))
  110.         msleep(5);
  111. @@ -416,7 +416,7 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
  112.         if (test_bit(i, &ehci->bus_suspended) &&
  113.                 (temp & PORT_SUSPEND)) {
  114.             temp |= PORT_RESUME;
  115. -           resume_needed = 1;
  116. +           set_bit(i, &resume_needed);
  117.         }
  118.         ehci_writel(ehci, temp, &ehci->regs->port_status [i]);
  119.     }
  120. @@ -431,8 +431,7 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
  121.     i = HCS_N_PORTS (ehci->hcs_params);
  122.     while (i--) {
  123.         temp = ehci_readl(ehci, &ehci->regs->port_status [i]);
  124. -       if (test_bit(i, &ehci->bus_suspended) &&
  125. -               (temp & PORT_SUSPEND)) {
  126. +       if (test_bit(i, &resume_needed)) {
  127.             temp &= ~(PORT_RWC_BITS | PORT_RESUME);
  128.             ehci_writel(ehci, temp, &ehci->regs->port_status [i]);
  129.             ehci_vdbg (ehci, "resumed port %d\n", i + 1);
  130. diff --git a/kernel_linaro/drivers/usb/host/ehci-omap.c b/kernel/drivers/usb/host/ehci-omap.c
  131. index 55a57c2..d534fa6 100644
  132. --- a/kernel_linaro/drivers/usb/host/ehci-omap.c
  133. +++ b/kernel/drivers/usb/host/ehci-omap.c
  134. @@ -39,8 +39,13 @@
  135.  #include <linux/platform_device.h>
  136.  #include <linux/slab.h>
  137.  #include <linux/usb/ulpi.h>
  138. -#include <plat/usb.h>
  139.  #include <linux/regulator/consumer.h>
  140. +#include <linux/pm_runtime.h>
  141. +#include <linux/clk.h>
  142. +
  143. +#include <plat/omap_hwmod.h>
  144. +#include <plat/usb.h>
  145. +#include <plat/clock.h>
  146.  
  147.  /* EHCI Register Set */
  148.  #define EHCI_INSNREG04                 (0xA0)
  149. @@ -178,11 +183,7 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
  150.         }
  151.     }
  152.  
  153. -   ret = omap_usbhs_enable(dev);
  154. -   if (ret) {
  155. -       dev_err(dev, "failed to start usbhs with err %d\n", ret);
  156. -       goto err_enable;
  157. -   }
  158. +   pm_runtime_get_sync(dev->parent);
  159.  
  160.     /*
  161.      * An undocumented "feature" in the OMAP3 EHCI controller,
  162. @@ -228,10 +229,7 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
  163.     return 0;
  164.  
  165.  err_add_hcd:
  166. -   omap_usbhs_disable(dev);
  167. -
  168. -err_enable:
  169. -   usb_put_hcd(hcd);
  170. +   pm_runtime_put_sync(dev->parent);
  171.  
  172.  err_io:
  173.     return ret;
  174. @@ -252,25 +250,87 @@ static int ehci_hcd_omap_remove(struct platform_device *pdev)
  175.     struct usb_hcd *hcd = dev_get_drvdata(dev);
  176.  
  177.     usb_remove_hcd(hcd);
  178. -   omap_usbhs_disable(dev);
  179. +   pm_runtime_put_sync(dev->parent);
  180.     usb_put_hcd(hcd);
  181.     return 0;
  182.  }
  183.  
  184.  static void ehci_hcd_omap_shutdown(struct platform_device *pdev)
  185.  {
  186. +   struct device *dev  = &pdev->dev;
  187.     struct usb_hcd *hcd = dev_get_drvdata(&pdev->dev);
  188.  
  189. -   if (hcd->driver->shutdown)
  190. +   if (hcd->driver->shutdown) {
  191. +       pm_runtime_get_sync(dev->parent);
  192.         hcd->driver->shutdown(hcd);
  193. +       pm_runtime_put(dev->parent);
  194. +   }
  195. +}
  196. +
  197. +static int ehci_omap_bus_suspend(struct usb_hcd *hcd)
  198. +{
  199. +   struct device *dev = hcd->self.controller;
  200. +   struct ehci_hcd_omap_platform_data  *pdata;
  201. +   struct omap_hwmod   *oh;
  202. +   struct clk *clk;
  203. +   int ret = 0;
  204. +   int i;
  205. +
  206. +   dev_dbg(dev, "ehci_omap_bus_suspend\n");
  207. +
  208. +   ret = ehci_bus_suspend(hcd);
  209. +
  210. +   if (ret != 0) {
  211. +       dev_dbg(dev, "ehci_omap_bus_suspend failed %d\n", ret);
  212. +       return ret;
  213. +   }
  214. +
  215. +   oh = omap_hwmod_lookup(USBHS_EHCI_HWMODNAME);
  216. +
  217. +   omap_hwmod_enable_ioring_wakeup(oh);
  218. +
  219. +   if (dev->parent)
  220. +       pm_runtime_put_sync(dev->parent);
  221. +
  222. +   /* At the end, disable any external transceiver clocks */
  223. +   pdata = dev->platform_data;
  224. +   for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) {
  225. +       clk = pdata->transceiver_clk[i];
  226. +       if (clk)
  227. +           clk_disable(clk);
  228. +   }
  229. +
  230. +   return ret;
  231. +}
  232. +
  233. +static int ehci_omap_bus_resume(struct usb_hcd *hcd)
  234. +{
  235. +   struct device *dev = hcd->self.controller;
  236. +   struct ehci_hcd_omap_platform_data  *pdata;
  237. +   struct clk *clk;
  238. +   int i;
  239. +
  240. +   dev_dbg(dev, "ehci_omap_bus_resume\n");
  241. +
  242. +   /* Re-enable any external transceiver clocks first */
  243. +   pdata = dev->platform_data;
  244. +   for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) {
  245. +       clk = pdata->transceiver_clk[i];
  246. +       if (clk)
  247. +           clk_enable(clk);
  248. +   }
  249. +
  250. +   if (dev->parent) {
  251. +       pm_runtime_get_sync(dev->parent);
  252. +   }
  253. +
  254. +   return ehci_bus_resume(hcd);
  255.  }
  256.  
  257.  static struct platform_driver ehci_hcd_omap_driver = {
  258.     .probe          = ehci_hcd_omap_probe,
  259.     .remove         = ehci_hcd_omap_remove,
  260.     .shutdown       = ehci_hcd_omap_shutdown,
  261. -   /*.suspend      = ehci_hcd_omap_suspend, */
  262. -   /*.resume       = ehci_hcd_omap_resume, */
  263.     .driver = {
  264.         .name       = "ehci-omap",
  265.     }
  266. @@ -315,8 +375,8 @@ static const struct hc_driver ehci_omap_hc_driver = {
  267.      */
  268.     .hub_status_data    = ehci_hub_status_data,
  269.     .hub_control        = ehci_hub_control,
  270. -   .bus_suspend        = ehci_bus_suspend,
  271. -   .bus_resume     = ehci_bus_resume,
  272. +   .bus_suspend        = ehci_omap_bus_suspend,
  273. +   .bus_resume     = ehci_omap_bus_resume,
  274.  
  275.     .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  276.  };
  277. diff --git a/kernel_linaro/drivers/usb/host/ehci-q.c b/kernel/drivers/usb/host/ehci-q.c
  278. index b7f9496..6c6013c 100644
  279. --- a/kernel_linaro/drivers/usb/host/ehci-q.c
  280. +++ b/kernel/drivers/usb/host/ehci-q.c
  281. @@ -498,6 +498,11 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
  282.             last = list_entry (qtd->qtd_list.prev,
  283.                     struct ehci_qtd, qtd_list);
  284.             last->hw_next = qtd->hw_next;
  285. +           /*
  286. +            * Make sure the new hw_next pointer is visible
  287. +            * to the HW before freeing the old one
  288. +            */
  289. +           wmb();
  290.         }
  291.  
  292.         /* remove qtd; it's recycled after possible urb completion */
  293. @@ -998,7 +1003,7 @@ static void qh_link_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
  294.     /*
  295.      * flush qh descriptor into memory immediately,
  296.      * see comments in qh_append_tds.
  297. -    */
  298. +    * */
  299.     ehci_sync_mem();
  300.  
  301.     qh_get(qh);
  302. @@ -1097,7 +1102,7 @@ static struct ehci_qh *qh_append_tds (
  303.              * is added to flush 'token' immediatelly into
  304.              * memory, so that ehci can execute the transaction
  305.              * ASAP.
  306. -            */
  307. +            * */
  308.             ehci_sync_mem();
  309.  
  310.             urb->hcpriv = qh_get (qh);
  311. diff --git a/kernel_linaro/drivers/usb/host/ehci-s5p.c b/kernel/drivers/usb/host/ehci-s5p.c
  312. index e3374c8..491a209 100644
  313. --- a/kernel_linaro/drivers/usb/host/ehci-s5p.c
  314. +++ b/kernel/drivers/usb/host/ehci-s5p.c
  315. @@ -86,6 +86,7 @@ static int __devinit s5p_ehci_probe(struct platform_device *pdev)
  316.         goto fail_hcd;
  317.     }
  318.  
  319. +   s5p_ehci->hcd = hcd;
  320.     s5p_ehci->clk = clk_get(&pdev->dev, "usbhost");
  321.  
  322.     if (IS_ERR(s5p_ehci->clk)) {
  323. diff --git a/kernel_linaro/drivers/usb/host/ehci.h b/kernel/drivers/usb/host/ehci.h
  324. index 6fb0de8..9706c2b 100644
  325. --- a/kernel_linaro/drivers/usb/host/ehci.h
  326. +++ b/kernel/drivers/usb/host/ehci.h
  327. @@ -741,7 +741,7 @@ static inline u32 hc32_to_cpup (const struct ehci_hcd *ehci, const __hc32 *x)
  328.   * writing buffer, so introduce the helper which can flush L2 writing
  329.   * buffer into memory immediately, especially used to flush ehci
  330.   * descriptor to memory.
  331. - */
  332. + * */
  333.  #ifdef CONFIG_ARM_DMA_MEM_BUFFERABLE
  334.  static inline void ehci_sync_mem()
  335.  {
  336. diff --git a/kernel_linaro/drivers/usb/host/ohci-omap3.c b/kernel/drivers/usb/host/ohci-omap3.c
  337. index 6048f2f..875a837 100644
  338. --- a/kernel_linaro/drivers/usb/host/ohci-omap3.c
  339. +++ b/kernel/drivers/usb/host/ohci-omap3.c
  340. @@ -31,6 +31,8 @@
  341.  
  342.  #include <linux/platform_device.h>
  343.  #include <plat/usb.h>
  344. +#include <plat/omap_hwmod.h>
  345. +#include <linux/pm_runtime.h>
  346.  
  347.  /*-------------------------------------------------------------------------*/
  348.  
  349. @@ -41,6 +43,51 @@ static int ohci_omap3_init(struct usb_hcd *hcd)
  350.     return ohci_init(hcd_to_ohci(hcd));
  351.  }
  352.  
  353. +static int ohci_omap3_bus_suspend(struct usb_hcd *hcd)
  354. +{
  355. +   struct device *dev = hcd->self.controller;
  356. +   struct omap_hwmod   *oh;
  357. +   int ret = 0;
  358. +
  359. +   dev_dbg(dev, "ohci_omap3_bus_suspend\n");
  360. +
  361. +   ret = ohci_bus_suspend(hcd);
  362. +
  363. +   /* Delay required so that after ohci suspend
  364. +    * smart stand by can be set in the driver.
  365. +    * required for power mangament
  366. +    */
  367. +   msleep(5);
  368. +
  369. +   if (ret != 0) {
  370. +       dev_dbg(dev, "ohci_omap3_bus_suspend failed %d\n", ret);
  371. +       return ret;
  372. +   }
  373. +
  374. +   oh = omap_hwmod_lookup(USBHS_OHCI_HWMODNAME);
  375. +
  376. +   omap_hwmod_enable_ioring_wakeup(oh);
  377. +
  378. +   if (dev->parent)
  379. +       pm_runtime_put_sync(dev->parent);
  380. +
  381. +   return ret;
  382. +}
  383. +
  384. +
  385. +static int ohci_omap3_bus_resume(struct usb_hcd *hcd)
  386. +{
  387. +   struct device *dev = hcd->self.controller;
  388. +
  389. +   dev_dbg(dev, "ohci_omap3_bus_resume\n");
  390. +
  391. +   if (dev->parent)
  392. +       pm_runtime_get_sync(dev->parent);
  393. +
  394. +   return ohci_bus_resume(hcd);
  395. +}
  396. +
  397. +
  398.  /*-------------------------------------------------------------------------*/
  399.  
  400.  static int ohci_omap3_start(struct usb_hcd *hcd)
  401. @@ -104,8 +151,8 @@ static const struct hc_driver ohci_omap3_hc_driver = {
  402.     .hub_status_data =  ohci_hub_status_data,
  403.     .hub_control =      ohci_hub_control,
  404.  #ifdef CONFIG_PM
  405. -   .bus_suspend =      ohci_bus_suspend,
  406. -   .bus_resume =       ohci_bus_resume,
  407. +   .bus_suspend =      ohci_omap3_bus_suspend,
  408. +   .bus_resume =       ohci_omap3_bus_resume,
  409.  #endif
  410.     .start_port_reset = ohci_start_port_reset,
  411.  };
  412. @@ -172,11 +219,7 @@ static int __devinit ohci_hcd_omap3_probe(struct platform_device *pdev)
  413.     hcd->rsrc_len = resource_size(res);
  414.     hcd->regs =  regs;
  415.  
  416. -   ret = omap_usbhs_enable(dev);
  417. -   if (ret) {
  418. -       dev_dbg(dev, "failed to start ohci\n");
  419. -       goto err_end;
  420. -   }
  421. +   pm_runtime_get_sync(dev->parent);
  422.  
  423.     ohci_hcd_init(hcd_to_ohci(hcd));
  424.  
  425. @@ -189,7 +232,7 @@ static int __devinit ohci_hcd_omap3_probe(struct platform_device *pdev)
  426.     return 0;
  427.  
  428.  err_add_hcd:
  429. -   omap_usbhs_disable(dev);
  430. +   pm_runtime_get_sync(dev->parent);
  431.  
  432.  err_end:
  433.     usb_put_hcd(hcd);
  434. @@ -220,9 +263,8 @@ static int __devexit ohci_hcd_omap3_remove(struct platform_device *pdev)
  435.  
  436.     iounmap(hcd->regs);
  437.     usb_remove_hcd(hcd);
  438. -   omap_usbhs_disable(dev);
  439. +   pm_runtime_put_sync(dev->parent);
  440.     usb_put_hcd(hcd);
  441. -
  442.     return 0;
  443.  }
  444.  
  445. diff --git a/kernel_linaro/drivers/usb/host/pci-quirks.c b/kernel/drivers/usb/host/pci-quirks.c
  446. index e9f004e..629a968 100644
  447. --- a/kernel_linaro/drivers/usb/host/pci-quirks.c
  448. +++ b/kernel/drivers/usb/host/pci-quirks.c
  449. @@ -535,20 +535,34 @@ static void __devinit quirk_usb_handoff_ohci(struct pci_dev *pdev)
  450.     iounmap(base);
  451.  }
  452.  
  453. +static const struct dmi_system_id __devinitconst ehci_dmi_nohandoff_table[] = {
  454. +   {
  455. +       /*  Pegatron Lucid (ExoPC) */
  456. +       .matches = {
  457. +           DMI_MATCH(DMI_BOARD_NAME, "EXOPG06411"),
  458. +           DMI_MATCH(DMI_BIOS_VERSION, "Lucid-CE-133"),
  459. +       },
  460. +   },
  461. +   {
  462. +       /*  Pegatron Lucid (Ordissimo AIRIS) */
  463. +       .matches = {
  464. +           DMI_MATCH(DMI_BOARD_NAME, "M11JB"),
  465. +           DMI_MATCH(DMI_BIOS_VERSION, "Lucid-GE-133"),
  466. +       },
  467. +   },
  468. +   { }
  469. +};
  470. +
  471.  static void __devinit ehci_bios_handoff(struct pci_dev *pdev,
  472.                     void __iomem *op_reg_base,
  473.                     u32 cap, u8 offset)
  474.  {
  475.     int try_handoff = 1, tried_handoff = 0;
  476.  
  477. -   /* The Pegatron Lucid (ExoPC) tablet sporadically waits for 90
  478. -    * seconds trying the handoff on its unused controller.  Skip
  479. -    * it. */
  480. +   /* The Pegatron Lucid tablet sporadically waits for 98 seconds trying
  481. +    * the handoff on its unused controller.  Skip it. */
  482.     if (pdev->vendor == 0x8086 && pdev->device == 0x283a) {
  483. -       const char *dmi_bn = dmi_get_system_info(DMI_BOARD_NAME);
  484. -       const char *dmi_bv = dmi_get_system_info(DMI_BIOS_VERSION);
  485. -       if (dmi_bn && !strcmp(dmi_bn, "EXOPG06411") &&
  486. -           dmi_bv && !strcmp(dmi_bv, "Lucid-CE-133"))
  487. +       if (dmi_check_system(ehci_dmi_nohandoff_table))
  488.             try_handoff = 0;
  489.     }
  490.  
  491. diff --git a/kernel_linaro/drivers/usb/host/xhci-hub.c b/kernel/drivers/usb/host/xhci-hub.c
  492. index 0be788c..723f823 100644
  493. --- a/kernel_linaro/drivers/usb/host/xhci-hub.c
  494. +++ b/kernel/drivers/usb/host/xhci-hub.c
  495. @@ -463,11 +463,12 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
  496.                     && (temp & PORT_POWER))
  497.                 status |= USB_PORT_STAT_SUSPEND;
  498.         }
  499. -       if ((temp & PORT_PLS_MASK) == XDEV_RESUME) {
  500. +       if ((temp & PORT_PLS_MASK) == XDEV_RESUME &&
  501. +               !DEV_SUPERSPEED(temp)) {
  502.             if ((temp & PORT_RESET) || !(temp & PORT_PE))
  503.                 goto error;
  504. -           if (!DEV_SUPERSPEED(temp) && time_after_eq(jiffies,
  505. -                       bus_state->resume_done[wIndex])) {
  506. +           if (time_after_eq(jiffies,
  507. +                   bus_state->resume_done[wIndex])) {
  508.                 xhci_dbg(xhci, "Resume USB2 port %d\n",
  509.                     wIndex + 1);
  510.                 bus_state->resume_done[wIndex] = 0;
  511. @@ -487,6 +488,14 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
  512.                 xhci_ring_device(xhci, slot_id);
  513.                 bus_state->port_c_suspend |= 1 << wIndex;
  514.                 bus_state->suspended_ports &= ~(1 << wIndex);
  515. +           } else {
  516. +               /*
  517. +                * The resume has been signaling for less than
  518. +                * 20ms. Report the port status as SUSPEND,
  519. +                * let the usbcore check port status again
  520. +                * and clear resume signaling later.
  521. +                */
  522. +               status |= USB_PORT_STAT_SUSPEND;
  523.             }
  524.         }
  525.         if ((temp & PORT_PLS_MASK) == XDEV_U0
  526. @@ -664,7 +673,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
  527.             xhci_dbg(xhci, "PORTSC %04x\n", temp);
  528.             if (temp & PORT_RESET)
  529.                 goto error;
  530. -           if (temp & XDEV_U3) {
  531. +           if ((temp & PORT_PLS_MASK) == XDEV_U3) {
  532.                 if ((temp & PORT_PE) == 0)
  533.                     goto error;
  534.  
  535. @@ -752,7 +761,7 @@ int xhci_hub_status_data(struct usb_hcd *hcd, char *buf)
  536.     memset(buf, 0, retval);
  537.     status = 0;
  538.  
  539. -   mask = PORT_CSC | PORT_PEC | PORT_OCC | PORT_PLC;
  540. +   mask = PORT_CSC | PORT_PEC | PORT_OCC | PORT_PLC | PORT_WRC;
  541.  
  542.     spin_lock_irqsave(&xhci->lock, flags);
  543.     /* For each port, did anything change?  If so, set that bit in buf. */
  544. diff --git a/kernel_linaro/drivers/usb/host/xhci-ring.c b/kernel/drivers/usb/host/xhci-ring.c
  545. index 70cacbb..d0871ea 100644
  546. --- a/kernel_linaro/drivers/usb/host/xhci-ring.c
  547. +++ b/kernel/drivers/usb/host/xhci-ring.c
  548. @@ -516,8 +516,12 @@ void xhci_find_new_dequeue_state(struct xhci_hcd *xhci,
  549.             (unsigned long long) addr);
  550.  }
  551.  
  552. +/* flip_cycle means flip the cycle bit of all but the first and last TRB.
  553. + * (The last TRB actually points to the ring enqueue pointer, which is not part
  554. + * of this TD.)  This is used to remove partially enqueued isoc TDs from a ring.
  555. + */
  556.  static void td_to_noop(struct xhci_hcd *xhci, struct xhci_ring *ep_ring,
  557. -       struct xhci_td *cur_td)
  558. +       struct xhci_td *cur_td, bool flip_cycle)
  559.  {
  560.     struct xhci_segment *cur_seg;
  561.     union xhci_trb *cur_trb;
  562. @@ -531,6 +535,12 @@ static void td_to_noop(struct xhci_hcd *xhci, struct xhci_ring *ep_ring,
  563.              * leave the pointers intact.
  564.              */
  565.             cur_trb->generic.field[3] &= cpu_to_le32(~TRB_CHAIN);
  566. +           /* Flip the cycle bit (link TRBs can't be the first
  567. +            * or last TRB).
  568. +            */
  569. +           if (flip_cycle)
  570. +               cur_trb->generic.field[3] ^=
  571. +                   cpu_to_le32(TRB_CYCLE);
  572.             xhci_dbg(xhci, "Cancel (unchain) link TRB\n");
  573.             xhci_dbg(xhci, "Address = %p (0x%llx dma); "
  574.                     "in seg %p (0x%llx dma)\n",
  575. @@ -544,6 +554,11 @@ static void td_to_noop(struct xhci_hcd *xhci, struct xhci_ring *ep_ring,
  576.             cur_trb->generic.field[2] = 0;
  577.             /* Preserve only the cycle bit of this TRB */
  578.             cur_trb->generic.field[3] &= cpu_to_le32(TRB_CYCLE);
  579. +           /* Flip the cycle bit except on the first or last TRB */
  580. +           if (flip_cycle && cur_trb != cur_td->first_trb &&
  581. +                   cur_trb != cur_td->last_trb)
  582. +               cur_trb->generic.field[3] ^=
  583. +                   cpu_to_le32(TRB_CYCLE);
  584.             cur_trb->generic.field[3] |= cpu_to_le32(
  585.                 TRB_TYPE(TRB_TR_NOOP));
  586.             xhci_dbg(xhci, "Cancel TRB %p (0x%llx dma) "
  587. @@ -722,14 +737,14 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci,
  588.                     cur_td->urb->stream_id,
  589.                     cur_td, &deq_state);
  590.         else
  591. -           td_to_noop(xhci, ep_ring, cur_td);
  592. +           td_to_noop(xhci, ep_ring, cur_td, false);
  593.  remove_finished_td:
  594.         /*
  595.          * The event handler won't see a completion for this TD anymore,
  596.          * so remove it from the endpoint ring's TD list.  Keep it in
  597.          * the cancelled TD list for URB completion later.
  598.          */
  599. -       list_del(&cur_td->td_list);
  600. +       list_del_init(&cur_td->td_list);
  601.     }
  602.     last_unlinked_td = cur_td;
  603.     xhci_stop_watchdog_timer_in_irq(xhci, ep);
  604. @@ -757,7 +772,7 @@ remove_finished_td:
  605.     do {
  606.         cur_td = list_entry(ep->cancelled_td_list.next,
  607.                 struct xhci_td, cancelled_td_list);
  608. -       list_del(&cur_td->cancelled_td_list);
  609. +       list_del_init(&cur_td->cancelled_td_list);
  610.  
  611.         /* Clean up the cancelled URB */
  612.         /* Doesn't matter what we pass for status, since the core will
  613. @@ -865,9 +880,9 @@ void xhci_stop_endpoint_command_watchdog(unsigned long arg)
  614.                 cur_td = list_first_entry(&ring->td_list,
  615.                         struct xhci_td,
  616.                         td_list);
  617. -               list_del(&cur_td->td_list);
  618. +               list_del_init(&cur_td->td_list);
  619.                 if (!list_empty(&cur_td->cancelled_td_list))
  620. -                   list_del(&cur_td->cancelled_td_list);
  621. +                   list_del_init(&cur_td->cancelled_td_list);
  622.                 xhci_giveback_urb_in_irq(xhci, cur_td,
  623.                         -ESHUTDOWN, "killed");
  624.             }
  625. @@ -876,7 +891,7 @@ void xhci_stop_endpoint_command_watchdog(unsigned long arg)
  626.                         &temp_ep->cancelled_td_list,
  627.                         struct xhci_td,
  628.                         cancelled_td_list);
  629. -               list_del(&cur_td->cancelled_td_list);
  630. +               list_del_init(&cur_td->cancelled_td_list);
  631.                 xhci_giveback_urb_in_irq(xhci, cur_td,
  632.                         -ESHUTDOWN, "killed");
  633.             }
  634. @@ -1567,10 +1582,10 @@ td_cleanup:
  635.             else
  636.                 *status = 0;
  637.         }
  638. -       list_del(&td->td_list);
  639. +       list_del_init(&td->td_list);
  640.         /* Was this TD slated to be cancelled but completed anyway? */
  641.         if (!list_empty(&td->cancelled_td_list))
  642. -           list_del(&td->cancelled_td_list);
  643. +           list_del_init(&td->cancelled_td_list);
  644.  
  645.         urb_priv->td_cnt++;
  646.         /* Giveback the urb when all the tds are completed */
  647. @@ -2508,11 +2523,8 @@ static int prepare_transfer(struct xhci_hcd *xhci,
  648.  
  649.     if (td_index == 0) {
  650.         ret = usb_hcd_link_urb_to_ep(bus_to_hcd(urb->dev->bus), urb);
  651. -       if (unlikely(ret)) {
  652. -           xhci_urb_free_priv(xhci, urb_priv);
  653. -           urb->hcpriv = NULL;
  654. +       if (unlikely(ret))
  655.             return ret;
  656. -       }
  657.     }
  658.  
  659.     td->urb = urb;
  660. @@ -2680,6 +2692,10 @@ static u32 xhci_v1_0_td_remainder(int running_total, int trb_buff_len,
  661.  {
  662.     int packets_transferred;
  663.  
  664. +   /* One TRB with a zero-length data packet. */
  665. +   if (running_total == 0 && trb_buff_len == 0)
  666. +       return 0;
  667. +
  668.     /* All the TRB queueing functions don't count the current TRB in
  669.      * running_total.
  670.      */
  671. @@ -3121,20 +3137,15 @@ static int count_isoc_trbs_needed(struct xhci_hcd *xhci,
  672.         struct urb *urb, int i)
  673.  {
  674.     int num_trbs = 0;
  675. -   u64 addr, td_len, running_total;
  676. +   u64 addr, td_len;
  677.  
  678.     addr = (u64) (urb->transfer_dma + urb->iso_frame_desc[i].offset);
  679.     td_len = urb->iso_frame_desc[i].length;
  680.  
  681. -   running_total = TRB_MAX_BUFF_SIZE - (addr & (TRB_MAX_BUFF_SIZE - 1));
  682. -   running_total &= TRB_MAX_BUFF_SIZE - 1;
  683. -   if (running_total != 0)
  684. -       num_trbs++;
  685. -
  686. -   while (running_total < td_len) {
  687. +   num_trbs = DIV_ROUND_UP(td_len + (addr & (TRB_MAX_BUFF_SIZE - 1)),
  688. +           TRB_MAX_BUFF_SIZE);
  689. +   if (num_trbs == 0)
  690.         num_trbs++;
  691. -       running_total += TRB_MAX_BUFF_SIZE;
  692. -   }
  693.  
  694.     return num_trbs;
  695.  }
  696. @@ -3234,6 +3245,7 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
  697.     start_trb = &ep_ring->enqueue->generic;
  698.     start_cycle = ep_ring->cycle_state;
  699.  
  700. +   urb_priv = urb->hcpriv;
  701.     /* Queue the first TRB, even if it's zero-length */
  702.     for (i = 0; i < num_tds; i++) {
  703.         unsigned int total_packet_count;
  704. @@ -3245,9 +3257,11 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
  705.         addr = start_addr + urb->iso_frame_desc[i].offset;
  706.         td_len = urb->iso_frame_desc[i].length;
  707.         td_remain_len = td_len;
  708. -       /* FIXME: Ignoring zero-length packets, can those happen? */
  709.         total_packet_count = roundup(td_len,
  710.                 le16_to_cpu(urb->ep->desc.wMaxPacketSize));
  711. +       /* A zero-length transfer still involves at least one packet. */
  712. +       if (total_packet_count == 0)
  713. +           total_packet_count++;
  714.         burst_count = xhci_get_burst_count(xhci, urb->dev, urb,
  715.                 total_packet_count);
  716.         residue = xhci_get_last_burst_packet_count(xhci,
  717. @@ -3257,12 +3271,13 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
  718.  
  719.         ret = prepare_transfer(xhci, xhci->devs[slot_id], ep_index,
  720.                 urb->stream_id, trbs_per_td, urb, i, mem_flags);
  721. -       if (ret < 0)
  722. -           return ret;
  723. +       if (ret < 0) {
  724. +           if (i == 0)
  725. +               return ret;
  726. +           goto cleanup;
  727. +       }
  728.  
  729. -       urb_priv = urb->hcpriv;
  730.         td = urb_priv->td[i];
  731. -
  732.         for (j = 0; j < trbs_per_td; j++) {
  733.             u32 remainder = 0;
  734.             field = TRB_TBC(burst_count) | TRB_TLBPC(residue);
  735. @@ -3352,6 +3367,27 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
  736.     giveback_first_trb(xhci, slot_id, ep_index, urb->stream_id,
  737.             start_cycle, start_trb);
  738.     return 0;
  739. +cleanup:
  740. +   /* Clean up a partially enqueued isoc transfer. */
  741. +
  742. +   for (i--; i >= 0; i--)
  743. +       list_del_init(&urb_priv->td[i]->td_list);
  744. +
  745. +   /* Use the first TD as a temporary variable to turn the TDs we've queued
  746. +    * into No-ops with a software-owned cycle bit. That way the hardware
  747. +    * won't accidentally start executing bogus TDs when we partially
  748. +    * overwrite them.  td->first_trb and td->start_seg are already set.
  749. +    */
  750. +   urb_priv->td[0]->last_trb = ep_ring->enqueue;
  751. +   /* Every TRB except the first & last will have its cycle bit flipped. */
  752. +   td_to_noop(xhci, ep_ring, urb_priv->td[0], true);
  753. +
  754. +   /* Reset the ring enqueue back to the first TRB and its cycle bit. */
  755. +   ep_ring->enqueue = urb_priv->td[0]->first_trb;
  756. +   ep_ring->enq_seg = urb_priv->td[0]->start_seg;
  757. +   ep_ring->cycle_state = start_cycle;
  758. +   usb_hcd_unlink_urb_from_ep(bus_to_hcd(urb->dev->bus), urb);
  759. +   return ret;
  760.  }
  761.  
  762.  /*
  763. diff --git a/kernel_linaro/drivers/usb/host/xhci.c b/kernel/drivers/usb/host/xhci.c
  764. index 9824761..7ea48b3 100644
  765. --- a/kernel_linaro/drivers/usb/host/xhci.c
  766. +++ b/kernel/drivers/usb/host/xhci.c
  767. @@ -1085,8 +1085,11 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags)
  768.         if (urb->dev->speed == USB_SPEED_FULL) {
  769.             ret = xhci_check_maxpacket(xhci, slot_id,
  770.                     ep_index, urb);
  771. -           if (ret < 0)
  772. +           if (ret < 0) {
  773. +               xhci_urb_free_priv(xhci, urb_priv);
  774. +               urb->hcpriv = NULL;
  775.                 return ret;
  776. +           }
  777.         }
  778.  
  779.         /* We have a spinlock and interrupts disabled, so we must pass
  780. @@ -1097,6 +1100,8 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags)
  781.             goto dying;
  782.         ret = xhci_queue_ctrl_tx(xhci, GFP_ATOMIC, urb,
  783.                 slot_id, ep_index);
  784. +       if (ret)
  785. +           goto free_priv;
  786.         spin_unlock_irqrestore(&xhci->lock, flags);
  787.     } else if (usb_endpoint_xfer_bulk(&urb->ep->desc)) {
  788.         spin_lock_irqsave(&xhci->lock, flags);
  789. @@ -1117,6 +1122,8 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags)
  790.             ret = xhci_queue_bulk_tx(xhci, GFP_ATOMIC, urb,
  791.                     slot_id, ep_index);
  792.         }
  793. +       if (ret)
  794. +           goto free_priv;
  795.         spin_unlock_irqrestore(&xhci->lock, flags);
  796.     } else if (usb_endpoint_xfer_int(&urb->ep->desc)) {
  797.         spin_lock_irqsave(&xhci->lock, flags);
  798. @@ -1124,6 +1131,8 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags)
  799.             goto dying;
  800.         ret = xhci_queue_intr_tx(xhci, GFP_ATOMIC, urb,
  801.                 slot_id, ep_index);
  802. +       if (ret)
  803. +           goto free_priv;
  804.         spin_unlock_irqrestore(&xhci->lock, flags);
  805.     } else {
  806.         spin_lock_irqsave(&xhci->lock, flags);
  807. @@ -1131,18 +1140,22 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags)
  808.             goto dying;
  809.         ret = xhci_queue_isoc_tx_prepare(xhci, GFP_ATOMIC, urb,
  810.                 slot_id, ep_index);
  811. +       if (ret)
  812. +           goto free_priv;
  813.         spin_unlock_irqrestore(&xhci->lock, flags);
  814.     }
  815.  exit:
  816.     return ret;
  817.  dying:
  818. -   xhci_urb_free_priv(xhci, urb_priv);
  819. -   urb->hcpriv = NULL;
  820.     xhci_dbg(xhci, "Ep 0x%x: URB %p submitted for "
  821.             "non-responsive xHCI host.\n",
  822.             urb->ep->desc.bEndpointAddress, urb);
  823. +   ret = -ESHUTDOWN;
  824. +free_priv:
  825. +   xhci_urb_free_priv(xhci, urb_priv);
  826. +   urb->hcpriv = NULL;
  827.     spin_unlock_irqrestore(&xhci->lock, flags);
  828. -   return -ESHUTDOWN;
  829. +   return ret;
  830.  }
  831.  
  832.  /* Get the right ring for the given URB.
  833. @@ -1239,6 +1252,13 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
  834.     if (temp == 0xffffffff || (xhci->xhc_state & XHCI_STATE_HALTED)) {
  835.         xhci_dbg(xhci, "HW died, freeing TD.\n");
  836.         urb_priv = urb->hcpriv;
  837. +       for (i = urb_priv->td_cnt; i < urb_priv->length; i++) {
  838. +           td = urb_priv->td[i];
  839. +           if (!list_empty(&td->td_list))
  840. +               list_del_init(&td->td_list);
  841. +           if (!list_empty(&td->cancelled_td_list))
  842. +               list_del_init(&td->cancelled_td_list);
  843. +       }
  844.  
  845.         usb_hcd_unlink_urb_from_ep(hcd, urb);
  846.         spin_unlock_irqrestore(&xhci->lock, flags);
  847. diff --git a/kernel_linaro/drivers/usb/musb/cppi_dma.c b/kernel/drivers/usb/musb/cppi_dma.c
  848. index 149f3f3..318fb4e 100644
  849. --- a/kernel_linaro/drivers/usb/musb/cppi_dma.c
  850. +++ b/kernel/drivers/usb/musb/cppi_dma.c
  851. @@ -226,8 +226,10 @@ static int cppi_controller_stop(struct dma_controller *c)
  852.     struct cppi     *controller;
  853.     void __iomem        *tibase;
  854.     int         i;
  855. +   struct musb     *musb;
  856.  
  857.     controller = container_of(c, struct cppi, controller);
  858. +   musb = controller->musb;
  859.  
  860.     tibase = controller->tibase;
  861.     /* DISABLE INDIVIDUAL CHANNEL Interrupts */
  862. @@ -289,9 +291,11 @@ cppi_channel_allocate(struct dma_controller *c,
  863.     u8          index;
  864.     struct cppi_channel *cppi_ch;
  865.     void __iomem        *tibase;
  866. +   struct musb     *musb;
  867.  
  868.     controller = container_of(c, struct cppi, controller);
  869.     tibase = controller->tibase;
  870. +   musb = controller->musb;
  871.  
  872.     /* ep0 doesn't use DMA; remember cppi indices are 0..N-1 */
  873.     index = ep->epnum - 1;
  874. @@ -339,7 +343,8 @@ static void cppi_channel_release(struct dma_channel *channel)
  875.     c = container_of(channel, struct cppi_channel, channel);
  876.     tibase = c->controller->tibase;
  877.     if (!c->hw_ep)
  878. -       dev_dbg(musb->controller, "releasing idle DMA channel %p\n", c);
  879. +       dev_dbg(c->controller->musb->controller,
  880. +           "releasing idle DMA channel %p\n", c);
  881.     else if (!c->transmit)
  882.         core_rxirq_enable(tibase, c->index + 1);
  883.  
  884. @@ -357,10 +362,11 @@ cppi_dump_rx(int level, struct cppi_channel *c, const char *tag)
  885.  
  886.     musb_ep_select(base, c->index + 1);
  887.  
  888. -   DBG(level, "RX DMA%d%s: %d left, csr %04x, "
  889. -           "%08x H%08x S%08x C%08x, "
  890. -           "B%08x L%08x %08x .. %08x"
  891. -           "\n",
  892. +   dev_dbg(c->controller->musb->controller,
  893. +       "RX DMA%d%s: %d left, csr %04x, "
  894. +       "%08x H%08x S%08x C%08x, "
  895. +       "B%08x L%08x %08x .. %08x"
  896. +       "\n",
  897.         c->index, tag,
  898.         musb_readl(c->controller->tibase,
  899.             DAVINCI_RXCPPI_BUFCNT0_REG + 4 * c->index),
  900. @@ -387,10 +393,11 @@ cppi_dump_tx(int level, struct cppi_channel *c, const char *tag)
  901.  
  902.     musb_ep_select(base, c->index + 1);
  903.  
  904. -   DBG(level, "TX DMA%d%s: csr %04x, "
  905. -           "H%08x S%08x C%08x %08x, "
  906. -           "F%08x L%08x .. %08x"
  907. -           "\n",
  908. +   dev_dbg(c->controller->musb->controller,
  909. +       "TX DMA%d%s: csr %04x, "
  910. +       "H%08x S%08x C%08x %08x, "
  911. +       "F%08x L%08x .. %08x"
  912. +       "\n",
  913.         c->index, tag,
  914.         musb_readw(c->hw_ep->regs, MUSB_TXCSR),
  915.  
  916. @@ -1022,6 +1029,7 @@ static bool cppi_rx_scan(struct cppi *cppi, unsigned ch)
  917.     int             i;
  918.     dma_addr_t          safe2ack;
  919.     void __iomem            *regs = rx->hw_ep->regs;
  920. +   struct musb         *musb = cppi->musb;
  921.  
  922.     cppi_dump_rx(6, rx, "/K");
  923.  
  924. diff --git a/kernel_linaro/drivers/usb/musb/musb_core.c b/kernel/drivers/usb/musb/musb_core.c
  925. index dce7182..e2648ff 100644
  926. --- a/kernel_linaro/drivers/usb/musb/musb_core.c
  927. +++ b/kernel/drivers/usb/musb/musb_core.c
  928. @@ -2214,6 +2214,7 @@ static void musb_save_context(struct musb *musb)
  929.     musb->context.devctl = musb_readb(musb_base, MUSB_DEVCTL);
  930.  
  931.     for (i = 0; i < musb->config->num_eps; ++i) {
  932. +       musb_writeb(musb_base, MUSB_INDEX, i);
  933.         epio = musb->endpoints[i].regs;
  934.         musb->context.index_regs[i].txmaxp =
  935.             musb_readw(epio, MUSB_TXMAXP);
  936. @@ -2280,6 +2281,7 @@ static void musb_restore_context(struct musb *musb)
  937.     musb_writeb(musb_base, MUSB_DEVCTL, musb->context.devctl);
  938.  
  939.     for (i = 0; i < musb->config->num_eps; ++i) {
  940. +       musb_writeb(musb_base, MUSB_INDEX, i);
  941.         epio = musb->endpoints[i].regs;
  942.         musb_writew(epio, MUSB_TXMAXP,
  943.             musb->context.index_regs[i].txmaxp);
  944. @@ -2337,7 +2339,8 @@ static int musb_suspend(struct device *dev)
  945.     struct platform_device *pdev = to_platform_device(dev);
  946.     unsigned long   flags;
  947.     struct musb *musb = dev_to_musb(&pdev->dev);
  948. -
  949. +   if (pm_runtime_suspended(dev))
  950. +       return 0;
  951.     spin_lock_irqsave(&musb->lock, flags);
  952.  
  953.     if (is_peripheral_active(musb)) {
  954. @@ -2349,7 +2352,6 @@ static int musb_suspend(struct device *dev)
  955.          * they will even be wakeup-enabled.
  956.          */
  957.     }
  958. -
  959.     musb_save_context(musb);
  960.  
  961.     spin_unlock_irqrestore(&musb->lock, flags);
  962. @@ -2360,7 +2362,8 @@ static int musb_resume_noirq(struct device *dev)
  963.  {
  964.     struct platform_device *pdev = to_platform_device(dev);
  965.     struct musb *musb = dev_to_musb(&pdev->dev);
  966. -
  967. +   if (pm_runtime_suspended(dev))
  968. +       return 0;
  969.     musb_restore_context(musb);
  970.  
  971.     /* for static cmos like DaVinci, register values were preserved
  972. diff --git a/kernel_linaro/drivers/usb/musb/musb_core.h b/kernel/drivers/usb/musb/musb_core.h
  973. index 0e053b5..263d31c 100644
  974. --- a/kernel_linaro/drivers/usb/musb/musb_core.h
  975. +++ b/kernel/drivers/usb/musb/musb_core.h
  976. @@ -370,6 +370,7 @@ struct musb_context_registers {
  977.     u8 index, testmode;
  978.  
  979.     u8 devctl, busctl, misc;
  980. +   u32 otg_interfsel;
  981.  
  982.     struct musb_csr_regs index_regs[MUSB_C_NUM_EPS];
  983.  };
  984. @@ -386,6 +387,7 @@ struct musb {
  985.  
  986.     irqreturn_t     (*isr)(int, void *);
  987.     struct work_struct  irq_work;
  988. +   struct workqueue_struct *otg_notifier_wq;
  989.     u16         hwvers;
  990.  
  991.  /* this hub status bit is reserved by USB 2.0 and not seen by usbcore */
  992. @@ -497,6 +499,7 @@ struct musb {
  993.     struct usb_gadget   g;          /* the gadget */
  994.     struct usb_gadget_driver *gadget_driver;    /* its driver */
  995.  #endif
  996. +   bool            is_ac_charger:1;
  997.  
  998.     /*
  999.      * FIXME: Remove this flag.
  1000. @@ -518,6 +521,12 @@ struct musb {
  1001.  #endif
  1002.  };
  1003.  
  1004. +struct musb_otg_work {
  1005. +   struct work_struct  work;
  1006. +   enum usb_xceiv_events   xceiv_event;
  1007. +   struct musb     *musb;
  1008. +};
  1009. +
  1010.  #ifdef CONFIG_USB_GADGET_MUSB_HDRC
  1011.  static inline struct musb *gadget_to_musb(struct usb_gadget *g)
  1012.  {
  1013. diff --git a/kernel_linaro/drivers/usb/musb/omap2430.c b/kernel/drivers/usb/musb/omap2430.c
  1014. index c5d4c44..e685787 100644
  1015. --- a/kernel_linaro/drivers/usb/musb/omap2430.c
  1016. +++ b/kernel/drivers/usb/musb/omap2430.c
  1017. @@ -230,15 +230,37 @@ static inline void omap2430_low_level_init(struct musb *musb)
  1018.  }
  1019.  
  1020.  /* blocking notifier support */
  1021. +static void musb_otg_notifier_work(struct work_struct *data_notifier_work);
  1022. +
  1023.  static int musb_otg_notifications(struct notifier_block *nb,
  1024.         unsigned long event, void *unused)
  1025.  {
  1026.     struct musb *musb = container_of(nb, struct musb, nb);
  1027. +   struct musb_otg_work *otg_work;
  1028. +
  1029. +   otg_work = kmalloc(sizeof(struct musb_otg_work), GFP_ATOMIC);
  1030. +   if (!otg_work)
  1031. +       return notifier_from_errno(-ENOMEM);
  1032. +   INIT_WORK(&otg_work->work, musb_otg_notifier_work);
  1033. +   otg_work->xceiv_event = event;
  1034. +   otg_work->musb = musb;
  1035. +   queue_work(musb->otg_notifier_wq, &otg_work->work);
  1036. +   return 0;
  1037. +}
  1038. +
  1039. +static void musb_otg_notifier_work(struct work_struct *data_notifier_work)
  1040. +{
  1041. +   struct musb_otg_work *otg_work =
  1042. +       container_of(data_notifier_work, struct musb_otg_work, work);
  1043. +        struct musb *musb = otg_work->musb;
  1044.     struct device *dev = musb->controller;
  1045.     struct musb_hdrc_platform_data *pdata = dev->platform_data;
  1046.     struct omap_musb_board_data *data = pdata->board_data;
  1047. +   enum usb_xceiv_events xceiv_event = otg_work->xceiv_event;
  1048.  
  1049. -   switch (event) {
  1050. +   kfree(otg_work);
  1051. +
  1052. +   switch (xceiv_event) {
  1053.     case USB_EVENT_ID:
  1054.         dev_dbg(musb->controller, "ID GND\n");
  1055.  
  1056. @@ -257,6 +279,11 @@ static int musb_otg_notifications(struct notifier_block *nb,
  1057.         }
  1058.         break;
  1059.  
  1060. +   case USB_EVENT_CHARGER:
  1061. +       dev_dbg(musb->controller, "Dedicated charger connect\n");
  1062. +       musb->is_ac_charger = true;
  1063. +       break;
  1064. +
  1065.     case USB_EVENT_VBUS:
  1066.         dev_dbg(musb->controller, "VBUS Connect\n");
  1067.  
  1068. @@ -268,6 +295,13 @@ static int musb_otg_notifications(struct notifier_block *nb,
  1069.         break;
  1070.  
  1071.     case USB_EVENT_NONE:
  1072. +       if (musb->is_ac_charger) {
  1073. +           dev_dbg(musb->controller,
  1074. +               "Dedicated charger disconnect\n");
  1075. +           musb->is_ac_charger = false;
  1076. +           break;
  1077. +       }
  1078. +
  1079.         dev_dbg(musb->controller, "VBUS Disconnect\n");
  1080.  
  1081.  #ifdef CONFIG_USB_GADGET_MUSB_HDRC
  1082. @@ -295,7 +329,8 @@ static int musb_otg_notifications(struct notifier_block *nb,
  1083.  
  1084.  static int omap2430_musb_init(struct musb *musb)
  1085.  {
  1086. -   u32 l, status = 0;
  1087. +   u32 l;
  1088. +   int status = 0;
  1089.     struct device *dev = musb->controller;
  1090.     struct musb_hdrc_platform_data *plat = dev->platform_data;
  1091.     struct omap_musb_board_data *data = plat->board_data;
  1092. @@ -310,10 +345,17 @@ static int omap2430_musb_init(struct musb *musb)
  1093.         return -ENODEV;
  1094.     }
  1095.  
  1096. +   musb->otg_notifier_wq = create_singlethread_workqueue("musb-otg");
  1097. +   if (!musb->otg_notifier_wq) {
  1098. +       pr_err("HS USB OTG: cannot allocate otg event wq\n");
  1099. +       status = -ENOMEM;
  1100. +       goto err1;
  1101. +   }
  1102. +
  1103.     status = pm_runtime_get_sync(dev);
  1104.     if (status < 0) {
  1105.         dev_err(dev, "pm_runtime_get_sync FAILED");
  1106. -       goto err1;
  1107. +       goto err2;
  1108.     }
  1109.  
  1110.     l = musb_readl(musb->mregs, OTG_INTERFSEL);
  1111. @@ -346,7 +388,10 @@ static int omap2430_musb_init(struct musb *musb)
  1112.  
  1113.     return 0;
  1114.  
  1115. +err2:
  1116. +   destroy_workqueue(musb->otg_notifier_wq);
  1117.  err1:
  1118. +   otg_put_transceiver(musb->xceiv);
  1119.     pm_runtime_disable(dev);
  1120.     return status;
  1121.  }
  1122. @@ -400,6 +445,8 @@ static int omap2430_musb_exit(struct musb *musb)
  1123.  {
  1124.     del_timer_sync(&musb_idle_timer);
  1125.  
  1126. +   otg_unregister_notifier(musb->xceiv, &musb->nb);
  1127. +   destroy_workqueue(musb->otg_notifier_wq);
  1128.     omap2430_low_level_exit(musb);
  1129.     otg_put_transceiver(musb->xceiv);
  1130.  
  1131. @@ -504,6 +551,9 @@ static int omap2430_runtime_suspend(struct device *dev)
  1132.     struct omap2430_glue        *glue = dev_get_drvdata(dev);
  1133.     struct musb         *musb = glue_to_musb(glue);
  1134.  
  1135. +   musb->context.otg_interfsel = musb_readl(musb->mregs,
  1136. +                       OTG_INTERFSEL);
  1137. +
  1138.     omap2430_low_level_exit(musb);
  1139.     otg_set_suspend(musb->xceiv, 1);
  1140.  
  1141. @@ -516,6 +566,9 @@ static int omap2430_runtime_resume(struct device *dev)
  1142.     struct musb         *musb = glue_to_musb(glue);
  1143.  
  1144.     omap2430_low_level_init(musb);
  1145. +   musb_writel(musb->mregs, OTG_INTERFSEL,
  1146. +                   musb->context.otg_interfsel);
  1147. +
  1148.     otg_set_suspend(musb->xceiv, 0);
  1149.  
  1150.     return 0;
  1151. diff --git a/kernel_linaro/drivers/usb/otg/otg-wakelock.c b/kernel/drivers/usb/otg/otg-wakelock.c
  1152. index 9931626..2f11472 100644
  1153. --- a/kernel_linaro/drivers/usb/otg/otg-wakelock.c
  1154. +++ b/kernel/drivers/usb/otg/otg-wakelock.c
  1155. @@ -21,13 +21,15 @@
  1156.  #include <linux/spinlock.h>
  1157.  #include <linux/usb/otg.h>
  1158.  
  1159. +#define TEMPORARY_HOLD_TIME    2000
  1160. +
  1161.  static bool enabled = true;
  1162.  static struct otg_transceiver *otgwl_xceiv;
  1163.  static struct notifier_block otgwl_nb;
  1164.  
  1165.  /*
  1166.   * otgwl_spinlock is held while the VBUS lock is grabbed or dropped and the
  1167. - * locked field is updated to match.
  1168. + * held field is updated to match.
  1169.   */
  1170.  
  1171.  static DEFINE_SPINLOCK(otgwl_spinlock);
  1172. @@ -39,51 +41,62 @@ static DEFINE_SPINLOCK(otgwl_spinlock);
  1173.  struct otgwl_lock {
  1174.     char name[40];
  1175.     struct wake_lock wakelock;
  1176. -   bool locked;
  1177. +   bool held;
  1178.  };
  1179.  
  1180.  /*
  1181. - * VBUS present lock.
  1182. + * VBUS present lock.  Also used as a timed lock on charger
  1183. + * connect/disconnect and USB host disconnect, to allow the system
  1184. + * to react to the change in power.
  1185.   */
  1186.  
  1187.  static struct otgwl_lock vbus_lock;
  1188.  
  1189. -static void otgwl_grab(struct otgwl_lock *lock)
  1190. +static void otgwl_hold(struct otgwl_lock *lock)
  1191.  {
  1192. -   if (!lock->locked) {
  1193. +   if (!lock->held) {
  1194.         wake_lock(&lock->wakelock);
  1195. -       lock->locked = true;
  1196. +       lock->held = true;
  1197.     }
  1198.  }
  1199.  
  1200. +static void otgwl_temporary_hold(struct otgwl_lock *lock)
  1201. +{
  1202. +   wake_lock_timeout(&lock->wakelock,
  1203. +             msecs_to_jiffies(TEMPORARY_HOLD_TIME));
  1204. +   lock->held = false;
  1205. +}
  1206. +
  1207.  static void otgwl_drop(struct otgwl_lock *lock)
  1208.  {
  1209. -   if (lock->locked) {
  1210. +   if (lock->held) {
  1211.         wake_unlock(&lock->wakelock);
  1212. -       lock->locked = false;
  1213. +       lock->held = false;
  1214.     }
  1215.  }
  1216.  
  1217. -static int otgwl_otg_notifications(struct notifier_block *nb,
  1218. -                  unsigned long event, void *unused)
  1219. +static void otgwl_handle_event(unsigned long event)
  1220.  {
  1221.     unsigned long irqflags;
  1222.  
  1223. -   if (!enabled)
  1224. -       return NOTIFY_OK;
  1225. -
  1226.     spin_lock_irqsave(&otgwl_spinlock, irqflags);
  1227.  
  1228. +   if (!enabled) {
  1229. +       otgwl_drop(&vbus_lock);
  1230. +       spin_unlock_irqrestore(&otgwl_spinlock, irqflags);
  1231. +       return;
  1232. +   }
  1233. +
  1234.     switch (event) {
  1235.     case USB_EVENT_VBUS:
  1236.     case USB_EVENT_ENUMERATED:
  1237. -       otgwl_grab(&vbus_lock);
  1238. +       otgwl_hold(&vbus_lock);
  1239.         break;
  1240.  
  1241.     case USB_EVENT_NONE:
  1242.     case USB_EVENT_ID:
  1243.     case USB_EVENT_CHARGER:
  1244. -       otgwl_drop(&vbus_lock);
  1245. +       otgwl_temporary_hold(&vbus_lock);
  1246.         break;
  1247.  
  1248.     default:
  1249. @@ -91,71 +104,25 @@ static int otgwl_otg_notifications(struct notifier_block *nb,
  1250.     }
  1251.  
  1252.     spin_unlock_irqrestore(&otgwl_spinlock, irqflags);
  1253. -   return NOTIFY_OK;
  1254. -}
  1255. -
  1256. -static void sync_with_xceiv_state(void)
  1257. -{
  1258. -   if ((otgwl_xceiv->last_event == USB_EVENT_VBUS) ||
  1259. -       (otgwl_xceiv->last_event == USB_EVENT_ENUMERATED))
  1260. -       otgwl_grab(&vbus_lock);
  1261. -   else
  1262. -       otgwl_drop(&vbus_lock);
  1263.  }
  1264.  
  1265. -static int init_for_xceiv(void)
  1266. +static int otgwl_otg_notifications(struct notifier_block *nb,
  1267. +                  unsigned long event, void *unused)
  1268.  {
  1269. -   int rv;
  1270. -
  1271. -   if (!otgwl_xceiv) {
  1272. -       otgwl_xceiv = otg_get_transceiver();
  1273. -
  1274. -       if (!otgwl_xceiv) {
  1275. -           pr_err("%s: No OTG transceiver found\n", __func__);
  1276. -           return -ENODEV;
  1277. -       }
  1278. -
  1279. -       snprintf(vbus_lock.name, sizeof(vbus_lock.name), "vbus-%s",
  1280. -            dev_name(otgwl_xceiv->dev));
  1281. -       wake_lock_init(&vbus_lock.wakelock, WAKE_LOCK_SUSPEND,
  1282. -                  vbus_lock.name);
  1283. -
  1284. -       rv = otg_register_notifier(otgwl_xceiv, &otgwl_nb);
  1285. -
  1286. -       if (rv) {
  1287. -           pr_err("%s: otg_register_notifier on transceiver %s"
  1288. -                  " failed\n", __func__,
  1289. -                  dev_name(otgwl_xceiv->dev));
  1290. -           otgwl_xceiv = NULL;
  1291. -           wake_lock_destroy(&vbus_lock.wakelock);
  1292. -           return rv;
  1293. -       }
  1294. -   }
  1295. -
  1296. -   return 0;
  1297. +   otgwl_handle_event(event);
  1298. +   return NOTIFY_OK;
  1299.  }
  1300.  
  1301.  static int set_enabled(const char *val, const struct kernel_param *kp)
  1302.  {
  1303. -   unsigned long irqflags;
  1304.     int rv = param_set_bool(val, kp);
  1305.  
  1306.     if (rv)
  1307.         return rv;
  1308.  
  1309. -   rv = init_for_xceiv();
  1310. -
  1311. -   if (rv)
  1312. -       return rv;
  1313. -
  1314. -   spin_lock_irqsave(&otgwl_spinlock, irqflags);
  1315. -
  1316. -   if (enabled)
  1317. -       sync_with_xceiv_state();
  1318. -   else
  1319. -       otgwl_drop(&vbus_lock);
  1320. +   if (otgwl_xceiv)
  1321. +       otgwl_handle_event(otgwl_xceiv->last_event);
  1322.  
  1323. -   spin_unlock_irqrestore(&otgwl_spinlock, irqflags);
  1324.     return 0;
  1325.  }
  1326.  
  1327. @@ -169,22 +136,34 @@ MODULE_PARM_DESC(enabled, "enable wakelock when VBUS present");
  1328.  
  1329.  static int __init otg_wakelock_init(void)
  1330.  {
  1331. -   unsigned long irqflags;
  1332. +   int ret;
  1333.  
  1334. -   otgwl_nb.notifier_call = otgwl_otg_notifications;
  1335. +   otgwl_xceiv = otg_get_transceiver();
  1336.  
  1337. -   if (!init_for_xceiv()) {
  1338. -       spin_lock_irqsave(&otgwl_spinlock, irqflags);
  1339. +   if (!otgwl_xceiv) {
  1340. +       pr_err("%s: No OTG transceiver found\n", __func__);
  1341. +       return -ENODEV;
  1342. +   }
  1343.  
  1344. -       if (enabled)
  1345. -           sync_with_xceiv_state();
  1346. +   snprintf(vbus_lock.name, sizeof(vbus_lock.name), "vbus-%s",
  1347. +        dev_name(otgwl_xceiv->dev));
  1348. +   wake_lock_init(&vbus_lock.wakelock, WAKE_LOCK_SUSPEND,
  1349. +              vbus_lock.name);
  1350.  
  1351. -       spin_unlock_irqrestore(&otgwl_spinlock, irqflags);
  1352. -   } else {
  1353. -       enabled = false;
  1354. +   otgwl_nb.notifier_call = otgwl_otg_notifications;
  1355. +   ret = otg_register_notifier(otgwl_xceiv, &otgwl_nb);
  1356. +
  1357. +   if (ret) {
  1358. +       pr_err("%s: otg_register_notifier on transceiver %s"
  1359. +              " failed\n", __func__,
  1360. +              dev_name(otgwl_xceiv->dev));
  1361. +       otgwl_xceiv = NULL;
  1362. +       wake_lock_destroy(&vbus_lock.wakelock);
  1363. +       return ret;
  1364.     }
  1365.  
  1366. -   return 0;
  1367. +   otgwl_handle_event(otgwl_xceiv->last_event);
  1368. +   return ret;
  1369.  }
  1370.  
  1371.  late_initcall(otg_wakelock_init);
  1372. diff --git a/kernel_linaro/drivers/usb/otg/otg_id.c b/kernel/drivers/usb/otg/otg_id.c
  1373. index ce22b46..8037edb 100644
  1374. --- a/kernel_linaro/drivers/usb/otg/otg_id.c
  1375. +++ b/kernel/drivers/usb/otg/otg_id.c
  1376. @@ -26,6 +26,8 @@ static struct plist_head otg_id_plist =
  1377.  static struct otg_id_notifier_block *otg_id_active;
  1378.  static bool otg_id_cancelling;
  1379.  static bool otg_id_inited;
  1380. +static int otg_id_suspended;
  1381. +static bool otg_id_pending;
  1382.  
  1383.  static void otg_id_cancel(void)
  1384.  {
  1385. @@ -139,8 +141,65 @@ void otg_id_notify(void)
  1386.     if (otg_id_cancelling)
  1387.         goto out;
  1388.  
  1389. +   if (otg_id_suspended != 0) {
  1390. +       otg_id_pending = true;
  1391. +       goto out;
  1392. +   }
  1393. +
  1394.     __otg_id_notify();
  1395. +out:
  1396. +   mutex_unlock(&otg_id_lock);
  1397. +}
  1398. +
  1399. +/**
  1400. + * otg_id_suspend
  1401. + *
  1402. + * Mark the otg_id subsystem as going into suspend. From here on out,
  1403. + * any notifications will be deferred until the last otg_id client resumes.
  1404. + * If there is a pending notification when calling this function, it will
  1405. + * return a negative errno and expects that the caller will abort suspend.
  1406. + * Returs 0 on success.
  1407. + */
  1408. +int otg_id_suspend(void)
  1409. +{
  1410. +   int ret = 0;
  1411. +
  1412. +   mutex_lock(&otg_id_lock);
  1413. +
  1414. +   /*
  1415. +    * if there's a pending notification, tell the caller to abort suspend
  1416. +    */
  1417. +   if (otg_id_suspended != 0 && otg_id_pending) {
  1418. +       pr_info("otg_id: pending notification, should abort suspend\n");
  1419. +       ret = -EBUSY;
  1420. +       goto out;
  1421. +   }
  1422.  
  1423. +   otg_id_suspended++;
  1424. +out:
  1425. +   mutex_unlock(&otg_id_lock);
  1426. +   return ret;
  1427. +}
  1428. +
  1429. +/**
  1430. + * otg_id_resume
  1431. + *
  1432. + * Inform the otg_id subsystem that a client is resuming. If this is the
  1433. + * last client to be resumed and there's a pending notification,
  1434. + * otg_id_notify() is called.
  1435. + */
  1436. +void otg_id_resume(void)
  1437. +{
  1438. +   mutex_lock(&otg_id_lock);
  1439. +   if (WARN(!otg_id_suspended, "unbalanced otg_id_resume\n"))
  1440. +       goto out;
  1441. +   if (--otg_id_suspended == 0) {
  1442. +       if (otg_id_pending) {
  1443. +           pr_info("otg_id: had pending notification\n");
  1444. +           otg_id_pending = false;
  1445. +           __otg_id_notify();
  1446. +       }
  1447. +   }
  1448.  out:
  1449.     mutex_unlock(&otg_id_lock);
  1450.  }
  1451. diff --git a/kernel_linaro/drivers/usb/otg/twl6030-usb.c b/kernel/drivers/usb/otg/twl6030-usb.c
  1452. index cfb5aa7..9f51eaf 100644
  1453. --- a/kernel_linaro/drivers/usb/otg/twl6030-usb.c
  1454. +++ b/kernel/drivers/usb/otg/twl6030-usb.c
  1455. @@ -63,9 +63,6 @@
  1456.  #define USB_OTG_ADP_RISE       0x19
  1457.  #define USB_OTG_REVISION       0x1A
  1458.  
  1459. -/* to be moved to LDO */
  1460. -#define TWL6030_MISC2          0xE5
  1461. -#define TWL6030_CFG_LDO_PD2        0xF5
  1462.  #define TWL6030_BACKUP_REG     0xFA
  1463.  
  1464.  #define STS_HW_CONDITIONS      0x21
  1465. @@ -95,11 +92,15 @@ struct twl6030_usb {
  1466.  
  1467.     struct regulator        *usb3v3;
  1468.  
  1469. +   /* used to set vbus, in atomic path */
  1470. +   struct work_struct  set_vbus_work;
  1471. +
  1472.     int         irq1;
  1473.     int         irq2;
  1474.     u8          linkstat;
  1475.     u8          asleep;
  1476.     bool            irq_enabled;
  1477. +   bool            vbus_enable;
  1478.     unsigned long       features;
  1479.  };
  1480.  
  1481. @@ -215,12 +216,6 @@ static int twl6030_usb_ldo_init(struct twl6030_usb *twl)
  1482.     /* Set to OTG_REV 1.3 and turn on the ID_WAKEUP_COMP */
  1483.     twl6030_writeb(twl, TWL6030_MODULE_ID0 , 0x1, TWL6030_BACKUP_REG);
  1484.  
  1485. -   /* Program CFG_LDO_PD2 register and set VUSB bit */
  1486. -   twl6030_writeb(twl, TWL6030_MODULE_ID0 , 0x1, TWL6030_CFG_LDO_PD2);
  1487. -
  1488. -   /* Program MISC2 register and set bit VUSB_IN_VBAT */
  1489. -   twl6030_writeb(twl, TWL6030_MODULE_ID0 , 0x10, TWL6030_MISC2);
  1490. -
  1491.     twl->usb3v3 = regulator_get(twl->dev, regulator_name);
  1492.     if (IS_ERR(twl->usb3v3))
  1493.         return -ENODEV;
  1494. @@ -370,20 +365,28 @@ static int twl6030_enable_irq(struct otg_transceiver *x)
  1495.     return 0;
  1496.  }
  1497.  
  1498. -static int twl6030_set_vbus(struct otg_transceiver *x, bool enabled)
  1499. +static void otg_set_vbus_work(struct work_struct *data)
  1500.  {
  1501. -   struct twl6030_usb *twl = xceiv_to_twl(x);
  1502. -
  1503. +   struct twl6030_usb *twl = container_of(data, struct twl6030_usb,
  1504. +                               set_vbus_work);
  1505.     /*
  1506.      * Start driving VBUS. Set OPA_MODE bit in CHARGERUSB_CTRL1
  1507.      * register. This enables boost mode.
  1508.      */
  1509. -   if (enabled)
  1510. +   if (twl->vbus_enable)
  1511.         twl6030_writeb(twl, TWL_MODULE_MAIN_CHARGE , 0x40,
  1512.                         CHARGERUSB_CTRL1);
  1513. -    else
  1514. +   else
  1515.         twl6030_writeb(twl, TWL_MODULE_MAIN_CHARGE , 0x00,
  1516.                         CHARGERUSB_CTRL1);
  1517. +}
  1518. +
  1519. +static int twl6030_set_vbus(struct otg_transceiver *x, bool enabled)
  1520. +{
  1521. +   struct twl6030_usb *twl = xceiv_to_twl(x);
  1522. +
  1523. +   twl->vbus_enable = enabled;
  1524. +   schedule_work(&twl->set_vbus_work);
  1525.     return 0;
  1526.  }
  1527.  
  1528. @@ -444,6 +447,9 @@ static int __devinit twl6030_usb_probe(struct platform_device *pdev)
  1529.  
  1530.     ATOMIC_INIT_NOTIFIER_HEAD(&twl->otg.notifier);
  1531.  
  1532. +   INIT_WORK(&twl->set_vbus_work, otg_set_vbus_work);
  1533. +
  1534. +   twl->vbus_enable = false;
  1535.     twl->irq_enabled = true;
  1536.     status = request_threaded_irq(twl->irq1, NULL, twl6030_usbotg_irq,
  1537.             IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
  1538. @@ -494,6 +500,7 @@ static int __exit twl6030_usb_remove(struct platform_device *pdev)
  1539.     regulator_put(twl->usb3v3);
  1540.     pdata->phy_exit(twl->dev);
  1541.     device_remove_file(twl->dev, &dev_attr_vbus);
  1542. +   cancel_work_sync(&twl->set_vbus_work);
  1543.     kfree(twl);
  1544.  
  1545.     return 0;
  1546. diff --git a/kernel_linaro/drivers/usb/serial/ftdi_sio.c b/kernel/drivers/usb/serial/ftdi_sio.c
  1547. index 9afb361..f968a3d 100644
  1548. --- a/kernel_linaro/drivers/usb/serial/ftdi_sio.c
  1549. +++ b/kernel/drivers/usb/serial/ftdi_sio.c
  1550. @@ -101,6 +101,7 @@ static int   ftdi_jtag_probe(struct usb_serial *serial);
  1551.  static int   ftdi_mtxorb_hack_setup(struct usb_serial *serial);
  1552.  static int   ftdi_NDI_device_setup(struct usb_serial *serial);
  1553.  static int   ftdi_stmclite_probe(struct usb_serial *serial);
  1554. +static int   ftdi_8u2232c_probe(struct usb_serial *serial);
  1555.  static void  ftdi_USB_UIRT_setup(struct ftdi_private *priv);
  1556.  static void  ftdi_HE_TIRA1_setup(struct ftdi_private *priv);
  1557.  
  1558. @@ -128,6 +129,10 @@ static struct ftdi_sio_quirk ftdi_stmclite_quirk = {
  1559.     .probe  = ftdi_stmclite_probe,
  1560.  };
  1561.  
  1562. +static struct ftdi_sio_quirk ftdi_8u2232c_quirk = {
  1563. +   .probe  = ftdi_8u2232c_probe,
  1564. +};
  1565. +
  1566.  /*
  1567.   * The 8U232AM has the same API as the sio except for:
  1568.   * - it can support MUCH higher baudrates; up to:
  1569. @@ -177,7 +182,8 @@ static struct usb_device_id id_table_combined [] = {
  1570.     { USB_DEVICE(FTDI_VID, FTDI_8U232AM_PID) },
  1571.     { USB_DEVICE(FTDI_VID, FTDI_8U232AM_ALT_PID) },
  1572.     { USB_DEVICE(FTDI_VID, FTDI_232RL_PID) },
  1573. -   { USB_DEVICE(FTDI_VID, FTDI_8U2232C_PID) },
  1574. +   { USB_DEVICE(FTDI_VID, FTDI_8U2232C_PID) ,
  1575. +       .driver_info = (kernel_ulong_t)&ftdi_8u2232c_quirk },
  1576.     { USB_DEVICE(FTDI_VID, FTDI_4232H_PID) },
  1577.     { USB_DEVICE(FTDI_VID, FTDI_232H_PID) },
  1578.     { USB_DEVICE(FTDI_VID, FTDI_MICRO_CHAMELEON_PID) },
  1579. @@ -1733,6 +1739,18 @@ static int ftdi_jtag_probe(struct usb_serial *serial)
  1580.     return 0;
  1581.  }
  1582.  
  1583. +static int ftdi_8u2232c_probe(struct usb_serial *serial)
  1584. +{
  1585. +   struct usb_device *udev = serial->dev;
  1586. +
  1587. +   dbg("%s", __func__);
  1588. +
  1589. +   if (strcmp(udev->manufacturer, "CALAO Systems") == 0)
  1590. +       return ftdi_jtag_probe(serial);
  1591. +
  1592. +   return 0;
  1593. +}
  1594. +
  1595.  /*
  1596.   * First and second port on STMCLiteadaptors is reserved for JTAG interface
  1597.   * and the forth port for pio
  1598. diff --git a/kernel_linaro/drivers/usb/serial/option.c b/kernel/drivers/usb/serial/option.c
  1599. index 8156561..fe22e90 100644
  1600. --- a/kernel_linaro/drivers/usb/serial/option.c
  1601. +++ b/kernel/drivers/usb/serial/option.c
  1602. @@ -148,6 +148,8 @@ static void option_instat_callback(struct urb *urb);
  1603.  #define HUAWEI_PRODUCT_K4505           0x1464
  1604.  #define HUAWEI_PRODUCT_K3765           0x1465
  1605.  #define HUAWEI_PRODUCT_E14AC           0x14AC
  1606. +#define HUAWEI_PRODUCT_K3806           0x14AE
  1607. +#define HUAWEI_PRODUCT_K4605           0x14C6
  1608.  #define HUAWEI_PRODUCT_K3770           0x14C9
  1609.  #define HUAWEI_PRODUCT_K3771           0x14CA
  1610.  #define HUAWEI_PRODUCT_K4510           0x14CB
  1611. @@ -416,6 +418,56 @@ static void option_instat_callback(struct urb *urb);
  1612.  #define SAMSUNG_VENDOR_ID                       0x04e8
  1613.  #define SAMSUNG_PRODUCT_GT_B3730                0x6889
  1614.  
  1615. +/* YUGA products  www.yuga-info.com*/
  1616. +#define YUGA_VENDOR_ID             0x257A
  1617. +#define YUGA_PRODUCT_CEM600            0x1601
  1618. +#define YUGA_PRODUCT_CEM610            0x1602
  1619. +#define YUGA_PRODUCT_CEM500            0x1603
  1620. +#define YUGA_PRODUCT_CEM510            0x1604
  1621. +#define YUGA_PRODUCT_CEM800            0x1605
  1622. +#define YUGA_PRODUCT_CEM900            0x1606
  1623. +
  1624. +#define YUGA_PRODUCT_CEU818            0x1607
  1625. +#define YUGA_PRODUCT_CEU816            0x1608
  1626. +#define YUGA_PRODUCT_CEU828            0x1609
  1627. +#define YUGA_PRODUCT_CEU826            0x160A
  1628. +#define YUGA_PRODUCT_CEU518            0x160B
  1629. +#define YUGA_PRODUCT_CEU516            0x160C
  1630. +#define YUGA_PRODUCT_CEU528            0x160D
  1631. +#define YUGA_PRODUCT_CEU526            0x160F
  1632. +
  1633. +#define YUGA_PRODUCT_CWM600            0x2601
  1634. +#define YUGA_PRODUCT_CWM610            0x2602
  1635. +#define YUGA_PRODUCT_CWM500            0x2603
  1636. +#define YUGA_PRODUCT_CWM510            0x2604
  1637. +#define YUGA_PRODUCT_CWM800            0x2605
  1638. +#define YUGA_PRODUCT_CWM900            0x2606
  1639. +
  1640. +#define YUGA_PRODUCT_CWU718            0x2607
  1641. +#define YUGA_PRODUCT_CWU716            0x2608
  1642. +#define YUGA_PRODUCT_CWU728            0x2609
  1643. +#define YUGA_PRODUCT_CWU726            0x260A
  1644. +#define YUGA_PRODUCT_CWU518            0x260B
  1645. +#define YUGA_PRODUCT_CWU516            0x260C
  1646. +#define YUGA_PRODUCT_CWU528            0x260D
  1647. +#define YUGA_PRODUCT_CWU526            0x260F
  1648. +
  1649. +#define YUGA_PRODUCT_CLM600            0x2601
  1650. +#define YUGA_PRODUCT_CLM610            0x2602
  1651. +#define YUGA_PRODUCT_CLM500            0x2603
  1652. +#define YUGA_PRODUCT_CLM510            0x2604
  1653. +#define YUGA_PRODUCT_CLM800            0x2605
  1654. +#define YUGA_PRODUCT_CLM900            0x2606
  1655. +
  1656. +#define YUGA_PRODUCT_CLU718            0x2607
  1657. +#define YUGA_PRODUCT_CLU716            0x2608
  1658. +#define YUGA_PRODUCT_CLU728            0x2609
  1659. +#define YUGA_PRODUCT_CLU726            0x260A
  1660. +#define YUGA_PRODUCT_CLU518            0x260B
  1661. +#define YUGA_PRODUCT_CLU516            0x260C
  1662. +#define YUGA_PRODUCT_CLU528            0x260D
  1663. +#define YUGA_PRODUCT_CLU526            0x260F
  1664. +
  1665.  /* some devices interfaces need special handling due to a number of reasons */
  1666.  enum option_blacklist_reason {
  1667.         OPTION_BLACKLIST_NONE = 0,
  1668. @@ -551,6 +603,8 @@ static const struct usb_device_id option_ids[] = {
  1669.     { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K3765, 0xff, 0xff, 0xff) },
  1670.     { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_ETS1220, 0xff, 0xff, 0xff) },
  1671.     { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E14AC, 0xff, 0xff, 0xff) },
  1672. +   { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K3806, 0xff, 0xff, 0xff) },
  1673. +   { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K4605, 0xff, 0xff, 0xff) },
  1674.     { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K3770, 0xff, 0x02, 0x31) },
  1675.     { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K3770, 0xff, 0x02, 0x32) },
  1676.     { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K3771, 0xff, 0x02, 0x31) },
  1677. @@ -1005,6 +1059,48 @@ static const struct usb_device_id option_ids[] = {
  1678.     { USB_DEVICE(CELOT_VENDOR_ID, CELOT_PRODUCT_CT680M) }, /* CT-650 CDMA 450 1xEVDO modem */
  1679.     { USB_DEVICE(ONDA_VENDOR_ID, ONDA_MT825UP) }, /* ONDA MT825UP modem */
  1680.     { USB_DEVICE_AND_INTERFACE_INFO(SAMSUNG_VENDOR_ID, SAMSUNG_PRODUCT_GT_B3730, USB_CLASS_CDC_DATA, 0x00, 0x00) }, /* Samsung GT-B3730 LTE USB modem.*/
  1681. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CEM600) },
  1682. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CEM610) },
  1683. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CEM500) },
  1684. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CEM510) },
  1685. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CEM800) },
  1686. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CEM900) },
  1687. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CEU818) },
  1688. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CEU816) },
  1689. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CEU828) },
  1690. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CEU826) },
  1691. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CEU518) },
  1692. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CEU516) },
  1693. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CEU528) },
  1694. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CEU526) },
  1695. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CWM600) },
  1696. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CWM610) },
  1697. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CWM500) },
  1698. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CWM510) },
  1699. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CWM800) },
  1700. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CWM900) },
  1701. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CWU718) },
  1702. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CWU716) },
  1703. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CWU728) },
  1704. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CWU726) },
  1705. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CWU518) },
  1706. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CWU516) },
  1707. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CWU528) },
  1708. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CWU526) },
  1709. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CLM600) },
  1710. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CLM610) },
  1711. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CLM500) },
  1712. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CLM510) },
  1713. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CLM800) },
  1714. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CLM900) },
  1715. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CLU718) },
  1716. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CLU716) },
  1717. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CLU728) },
  1718. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CLU726) },
  1719. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CLU518) },
  1720. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CLU516) },
  1721. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CLU528) },
  1722. +   { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CLU526) },
  1723.     { } /* Terminating entry */
  1724.  };
  1725.  MODULE_DEVICE_TABLE(usb, option_ids);
  1726. @@ -1134,11 +1230,13 @@ static int option_probe(struct usb_serial *serial,
  1727.         serial->interface->cur_altsetting->desc.bInterfaceClass != 0xff)
  1728.         return -ENODEV;
  1729.  
  1730. -   /* Don't bind network interfaces on Huawei K3765 & K4505 */
  1731. +   /* Don't bind network interfaces on Huawei K3765, K4505 & K4605 */
  1732.     if (serial->dev->descriptor.idVendor == HUAWEI_VENDOR_ID &&
  1733.         (serial->dev->descriptor.idProduct == HUAWEI_PRODUCT_K3765 ||
  1734. -           serial->dev->descriptor.idProduct == HUAWEI_PRODUCT_K4505) &&
  1735. -       serial->interface->cur_altsetting->desc.bInterfaceNumber == 1)
  1736. +           serial->dev->descriptor.idProduct == HUAWEI_PRODUCT_K4505 ||
  1737. +           serial->dev->descriptor.idProduct == HUAWEI_PRODUCT_K4605) &&
  1738. +       (serial->interface->cur_altsetting->desc.bInterfaceNumber == 1 ||
  1739. +           serial->interface->cur_altsetting->desc.bInterfaceNumber == 2))
  1740.         return -ENODEV;
  1741.  
  1742.     /* Don't bind network interface on Samsung GT-B3730, it is handled by a separate module */
  1743. diff --git a/kernel_linaro/drivers/usb/serial/pl2303.c b/kernel/drivers/usb/serial/pl2303.c
  1744. index 0c20831..1d33260 100644
  1745. --- a/kernel_linaro/drivers/usb/serial/pl2303.c
  1746. +++ b/kernel/drivers/usb/serial/pl2303.c
  1747. @@ -343,10 +343,28 @@ static void pl2303_set_termios(struct tty_struct *tty,
  1748.                 baud = 6000000;
  1749.         }
  1750.         dbg("%s - baud set = %d", __func__, baud);
  1751. -       buf[0] = baud & 0xff;
  1752. -       buf[1] = (baud >> 8) & 0xff;
  1753. -       buf[2] = (baud >> 16) & 0xff;
  1754. -       buf[3] = (baud >> 24) & 0xff;
  1755. +       if (baud <= 115200) {
  1756. +           buf[0] = baud & 0xff;
  1757. +           buf[1] = (baud >> 8) & 0xff;
  1758. +           buf[2] = (baud >> 16) & 0xff;
  1759. +           buf[3] = (baud >> 24) & 0xff;
  1760. +       } else {
  1761. +           /* apparently the formula for higher speeds is:
  1762. +            * baudrate = 12M * 32 / (2^buf[1]) / buf[0]
  1763. +            */
  1764. +           unsigned tmp = 12*1000*1000*32 / baud;
  1765. +           buf[3] = 0x80;
  1766. +           buf[2] = 0;
  1767. +           buf[1] = (tmp >= 256);
  1768. +           while (tmp >= 256) {
  1769. +               tmp >>= 2;
  1770. +               buf[1] <<= 1;
  1771. +           }
  1772. +           if (tmp > 256) {
  1773. +               tmp %= 256;
  1774. +           }
  1775. +           buf[0] = tmp;
  1776. +       }
  1777.     }
  1778.  
  1779.     /* For reference buf[4]=0 is 1 stop bits */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement