812-USB-bcma-add-USB-3.0-support.patch 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. From 12c6932caa6b1fce44d0f0c68ec77d4c00ac0be7 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
  3. Date: Tue, 16 Jun 2015 17:14:26 +0200
  4. Subject: [PATCH] USB: bcma: add USB 3.0 support
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
  9. ---
  10. drivers/usb/host/bcma-hcd.c | 219 ++++++++++++++++++++++++++++++++++++++++++++
  11. 1 file changed, 219 insertions(+)
  12. --- a/drivers/usb/host/bcma-hcd.c
  13. +++ b/drivers/usb/host/bcma-hcd.c
  14. @@ -38,6 +38,7 @@ struct bcma_hcd_device {
  15. struct bcma_device *core;
  16. struct platform_device *ehci_dev;
  17. struct platform_device *ohci_dev;
  18. + struct platform_device *xhci_dev;
  19. struct gpio_desc *gpio_desc;
  20. };
  21. @@ -338,6 +339,166 @@ err_unregister_ohci_dev:
  22. return err;
  23. }
  24. +static bool bcma_wait_reg(struct bcma_bus *bus, void __iomem *addr, u32 mask,
  25. + u32 value, int timeout)
  26. +{
  27. + unsigned long deadline = jiffies + timeout;
  28. + u32 val;
  29. +
  30. + do {
  31. + val = readl(addr);
  32. + if ((val & mask) == value)
  33. + return true;
  34. + cpu_relax();
  35. + udelay(10);
  36. + } while (!time_after_eq(jiffies, deadline));
  37. +
  38. + pr_err("Timeout waiting for register %p\n", addr);
  39. +
  40. + return false;
  41. +}
  42. +
  43. +static void bcma_hcd_usb30_phy_init(struct bcma_hcd_device *bcma_hcd)
  44. +{
  45. + struct bcma_device *core = bcma_hcd->core;
  46. + struct bcma_bus *bus = core->bus;
  47. + struct bcma_chipinfo *chipinfo = &bus->chipinfo;
  48. + struct bcma_drv_cc_b *ccb = &bus->drv_cc_b;
  49. + struct bcma_device *arm_core;
  50. + void __iomem *dmu = NULL;
  51. + u32 cru_straps_ctrl;
  52. +
  53. + if (chipinfo->id != BCMA_CHIP_ID_BCM4707 &&
  54. + chipinfo->id != BCMA_CHIP_ID_BCM47094 &&
  55. + chipinfo->id != BCMA_CHIP_ID_BCM53018)
  56. + return;
  57. +
  58. + arm_core = bcma_find_core(bus, BCMA_CORE_ARMCA9);
  59. + if (!arm_core)
  60. + return;
  61. +
  62. + dmu = ioremap_nocache(arm_core->addr_s[0], 0x1000);
  63. + if (!dmu)
  64. + goto out;
  65. +
  66. + /* Check strapping of PCIE/USB3 SEL */
  67. + cru_straps_ctrl = ioread32(dmu + 0x2a0);
  68. + if ((cru_straps_ctrl & 0x10) == 0)
  69. + goto out;
  70. +
  71. + /* Perform USB3 system soft reset */
  72. + bcma_awrite32(core, BCMA_RESET_CTL, BCMA_RESET_CTL_RESET);
  73. +
  74. + /* Enable MDIO. Setting MDCDIV as 26 */
  75. + iowrite32(0x0000009a, ccb->mii + 0x000);
  76. + udelay(2);
  77. +
  78. + if (chipinfo->id == BCMA_CHIP_ID_BCM53018 ||
  79. + (chipinfo->id == BCMA_CHIP_ID_BCM4707 && (chipinfo->rev == 4 || chipinfo->rev == 6)) ||
  80. + chipinfo->id == BCMA_CHIP_ID_BCM47094) {
  81. + /* For NS-B0, USB3 PLL Block */
  82. + bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
  83. + iowrite32(0x587e8000, ccb->mii + 0x004);
  84. +
  85. + /* Clear ana_pllSeqStart */
  86. + bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
  87. + iowrite32(0x58061000, ccb->mii + 0x004);
  88. +
  89. + /* CMOS Divider ratio to 25 */
  90. + bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
  91. + iowrite32(0x582a6400, ccb->mii + 0x004);
  92. +
  93. + /* Asserting PLL Reset */
  94. + bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
  95. + iowrite32(0x582ec000, ccb->mii + 0x004);
  96. +
  97. + /* Deaaserting PLL Reset */
  98. + bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
  99. + iowrite32(0x582e8000, ccb->mii + 0x004);
  100. +
  101. + /* Waiting MII Mgt interface idle */
  102. + bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
  103. +
  104. + /* Deasserting USB3 system reset */
  105. + bcma_awrite32(core, BCMA_RESET_CTL, 0);
  106. +
  107. + /* PLL frequency monitor enable */
  108. + bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
  109. + iowrite32(0x58069000, ccb->mii + 0x004);
  110. +
  111. + /* PIPE Block */
  112. + bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
  113. + iowrite32(0x587e8060, ccb->mii + 0x004);
  114. +
  115. + /* CMPMAX & CMPMINTH setting */
  116. + bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
  117. + iowrite32(0x580af30d, ccb->mii + 0x004);
  118. +
  119. + /* DEGLITCH MIN & MAX setting */
  120. + bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
  121. + iowrite32(0x580e6302, ccb->mii + 0x004);
  122. +
  123. + /* TXPMD block */
  124. + bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
  125. + iowrite32(0x587e8040, ccb->mii + 0x004);
  126. +
  127. + /* Enabling SSC */
  128. + bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
  129. + iowrite32(0x58061003, ccb->mii + 0x004);
  130. +
  131. + /* Waiting MII Mgt interface idle */
  132. + bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
  133. + } else if (chipinfo->id == BCMA_CHIP_ID_BCM4707) {
  134. + /* PLL30 block */
  135. + bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
  136. + iowrite32(0x587e8000, ccb->mii + 0x004);
  137. +
  138. + bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
  139. + iowrite32(0x582a6400, ccb->mii + 0x004);
  140. +
  141. + bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
  142. + iowrite32(0x587e80e0, ccb->mii + 0x004);
  143. +
  144. + bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
  145. + iowrite32(0x580a009c, ccb->mii + 0x004);
  146. +
  147. + /* Enable SSC */
  148. + bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
  149. + iowrite32(0x587e8040, ccb->mii + 0x004);
  150. +
  151. + bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
  152. + iowrite32(0x580a21d3, ccb->mii + 0x004);
  153. +
  154. + bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
  155. + iowrite32(0x58061003, ccb->mii + 0x004);
  156. +
  157. + /* Waiting MII Mgt interface idle */
  158. + bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
  159. +
  160. + /* Deasserting USB3 system reset */
  161. + bcma_awrite32(core, BCMA_RESET_CTL, 0);
  162. + }
  163. +out:
  164. + if (dmu)
  165. + iounmap(dmu);
  166. +}
  167. +
  168. +static int bcma_hcd_usb30_init(struct bcma_hcd_device *bcma_hcd)
  169. +{
  170. + struct bcma_device *core = bcma_hcd->core;
  171. +
  172. + bcma_core_enable(core, 0);
  173. +
  174. + bcma_hcd_usb30_phy_init(bcma_hcd);
  175. +
  176. + bcma_hcd->xhci_dev = bcma_hcd_create_pdev(core, "xhci-hcd", core->addr,
  177. + NULL, 0);
  178. + if (IS_ERR(bcma_hcd->ohci_dev))
  179. + return PTR_ERR(bcma_hcd->ohci_dev);
  180. +
  181. + return 0;
  182. +}
  183. +
  184. static int bcma_hcd_probe(struct bcma_device *core)
  185. {
  186. int err;
  187. @@ -362,6 +523,11 @@ static int bcma_hcd_probe(struct bcma_de
  188. if (err)
  189. return err;
  190. break;
  191. + case BCMA_CORE_NS_USB30:
  192. + err = bcma_hcd_usb30_init(usb_dev);
  193. + if (err)
  194. + return err;
  195. + break;
  196. default:
  197. return -ENODEV;
  198. }
  199. @@ -375,11 +541,14 @@ static void bcma_hcd_remove(struct bcma_
  200. struct bcma_hcd_device *usb_dev = bcma_get_drvdata(dev);
  201. struct platform_device *ohci_dev = usb_dev->ohci_dev;
  202. struct platform_device *ehci_dev = usb_dev->ehci_dev;
  203. + struct platform_device *xhci_dev = usb_dev->xhci_dev;
  204. if (ohci_dev)
  205. platform_device_unregister(ohci_dev);
  206. if (ehci_dev)
  207. platform_device_unregister(ehci_dev);
  208. + if (xhci_dev)
  209. + platform_device_unregister(xhci_dev);
  210. bcma_core_disable(dev, 0);
  211. }
  212. @@ -416,6 +585,7 @@ static int bcma_hcd_resume(struct bcma_d
  213. static const struct bcma_device_id bcma_hcd_table[] = {
  214. BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_USB20_HOST, BCMA_ANY_REV, BCMA_ANY_CLASS),
  215. BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_NS_USB20, BCMA_ANY_REV, BCMA_ANY_CLASS),
  216. + BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_NS_USB30, BCMA_ANY_REV, BCMA_ANY_CLASS),
  217. BCMA_CORETABLE_END
  218. };
  219. MODULE_DEVICE_TABLE(bcma, bcma_hcd_table);