usb-init-xlp2.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /*
  2. * Copyright (c) 2003-2013 Broadcom Corporation
  3. * All Rights Reserved
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the Broadcom
  9. * license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. *
  15. * 1. Redistributions of source code must retain the above copyright
  16. * notice, this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright
  18. * notice, this list of conditions and the following disclaimer in
  19. * the documentation and/or other materials provided with the
  20. * distribution.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY BROADCOM ``AS IS'' AND ANY EXPRESS OR
  23. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  24. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  29. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  30. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  31. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  32. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <linux/dma-mapping.h>
  35. #include <linux/kernel.h>
  36. #include <linux/delay.h>
  37. #include <linux/init.h>
  38. #include <linux/pci.h>
  39. #include <linux/pci_ids.h>
  40. #include <linux/platform_device.h>
  41. #include <linux/irq.h>
  42. #include <asm/netlogic/common.h>
  43. #include <asm/netlogic/haldefs.h>
  44. #include <asm/netlogic/xlp-hal/iomap.h>
  45. #include <asm/netlogic/xlp-hal/xlp.h>
  46. #define XLPII_USB3_CTL_0 0xc0
  47. #define XLPII_VAUXRST BIT(0)
  48. #define XLPII_VCCRST BIT(1)
  49. #define XLPII_NUM2PORT 9
  50. #define XLPII_NUM3PORT 13
  51. #define XLPII_RTUNEREQ BIT(20)
  52. #define XLPII_MS_CSYSREQ BIT(21)
  53. #define XLPII_XS_CSYSREQ BIT(22)
  54. #define XLPII_RETENABLEN BIT(23)
  55. #define XLPII_TX2RX BIT(24)
  56. #define XLPII_XHCIREV BIT(25)
  57. #define XLPII_ECCDIS BIT(26)
  58. #define XLPII_USB3_INT_REG 0xc2
  59. #define XLPII_USB3_INT_MASK 0xc3
  60. #define XLPII_USB_PHY_TEST 0xc6
  61. #define XLPII_PRESET BIT(0)
  62. #define XLPII_ATERESET BIT(1)
  63. #define XLPII_LOOPEN BIT(2)
  64. #define XLPII_TESTPDHSP BIT(3)
  65. #define XLPII_TESTPDSSP BIT(4)
  66. #define XLPII_TESTBURNIN BIT(5)
  67. #define XLPII_USB_PHY_LOS_LV 0xc9
  68. #define XLPII_LOSLEV 0
  69. #define XLPII_LOSBIAS 5
  70. #define XLPII_SQRXTX 8
  71. #define XLPII_TXBOOST 11
  72. #define XLPII_RSLKSEL 16
  73. #define XLPII_FSEL 20
  74. #define XLPII_USB_RFCLK_REG 0xcc
  75. #define XLPII_VVLD 30
  76. #define nlm_read_usb_reg(b, r) nlm_read_reg(b, r)
  77. #define nlm_write_usb_reg(b, r, v) nlm_write_reg(b, r, v)
  78. #define nlm_xlpii_get_usb_pcibase(node, inst) \
  79. nlm_pcicfg_base(cpu_is_xlp9xx() ? \
  80. XLP9XX_IO_USB_OFFSET(node, inst) : \
  81. XLP2XX_IO_USB_OFFSET(node, inst))
  82. #define nlm_xlpii_get_usb_regbase(node, inst) \
  83. (nlm_xlpii_get_usb_pcibase(node, inst) + XLP_IO_PCI_HDRSZ)
  84. static void xlp2xx_usb_ack(struct irq_data *data)
  85. {
  86. u64 port_addr;
  87. switch (data->irq) {
  88. case PIC_2XX_XHCI_0_IRQ:
  89. port_addr = nlm_xlpii_get_usb_regbase(0, 1);
  90. break;
  91. case PIC_2XX_XHCI_1_IRQ:
  92. port_addr = nlm_xlpii_get_usb_regbase(0, 2);
  93. break;
  94. case PIC_2XX_XHCI_2_IRQ:
  95. port_addr = nlm_xlpii_get_usb_regbase(0, 3);
  96. break;
  97. default:
  98. pr_err("No matching USB irq!\n");
  99. return;
  100. }
  101. nlm_write_usb_reg(port_addr, XLPII_USB3_INT_REG, 0xffffffff);
  102. }
  103. static void xlp9xx_usb_ack(struct irq_data *data)
  104. {
  105. u64 port_addr;
  106. int node, irq;
  107. /* Find the node and irq on the node */
  108. irq = data->irq % NLM_IRQS_PER_NODE;
  109. node = data->irq / NLM_IRQS_PER_NODE;
  110. switch (irq) {
  111. case PIC_9XX_XHCI_0_IRQ:
  112. port_addr = nlm_xlpii_get_usb_regbase(node, 1);
  113. break;
  114. case PIC_9XX_XHCI_1_IRQ:
  115. port_addr = nlm_xlpii_get_usb_regbase(node, 2);
  116. break;
  117. case PIC_9XX_XHCI_2_IRQ:
  118. port_addr = nlm_xlpii_get_usb_regbase(node, 3);
  119. break;
  120. default:
  121. pr_err("No matching USB irq %d node %d!\n", irq, node);
  122. return;
  123. }
  124. nlm_write_usb_reg(port_addr, XLPII_USB3_INT_REG, 0xffffffff);
  125. }
  126. static void nlm_xlpii_usb_hw_reset(int node, int port)
  127. {
  128. u64 port_addr, xhci_base, pci_base;
  129. void __iomem *corebase;
  130. u32 val;
  131. port_addr = nlm_xlpii_get_usb_regbase(node, port);
  132. /* Set frequency */
  133. val = nlm_read_usb_reg(port_addr, XLPII_USB_PHY_LOS_LV);
  134. val &= ~(0x3f << XLPII_FSEL);
  135. val |= (0x27 << XLPII_FSEL);
  136. nlm_write_usb_reg(port_addr, XLPII_USB_PHY_LOS_LV, val);
  137. val = nlm_read_usb_reg(port_addr, XLPII_USB_RFCLK_REG);
  138. val |= (1 << XLPII_VVLD);
  139. nlm_write_usb_reg(port_addr, XLPII_USB_RFCLK_REG, val);
  140. /* PHY reset */
  141. val = nlm_read_usb_reg(port_addr, XLPII_USB_PHY_TEST);
  142. val &= (XLPII_ATERESET | XLPII_LOOPEN | XLPII_TESTPDHSP
  143. | XLPII_TESTPDSSP | XLPII_TESTBURNIN);
  144. nlm_write_usb_reg(port_addr, XLPII_USB_PHY_TEST, val);
  145. /* Setup control register */
  146. val = XLPII_VAUXRST | XLPII_VCCRST | (1 << XLPII_NUM2PORT)
  147. | (1 << XLPII_NUM3PORT) | XLPII_MS_CSYSREQ | XLPII_XS_CSYSREQ
  148. | XLPII_RETENABLEN | XLPII_XHCIREV;
  149. nlm_write_usb_reg(port_addr, XLPII_USB3_CTL_0, val);
  150. /* Enable interrupts */
  151. nlm_write_usb_reg(port_addr, XLPII_USB3_INT_MASK, 0x00000001);
  152. /* Clear all interrupts */
  153. nlm_write_usb_reg(port_addr, XLPII_USB3_INT_REG, 0xffffffff);
  154. udelay(2000);
  155. /* XHCI configuration at PCI mem */
  156. pci_base = nlm_xlpii_get_usb_pcibase(node, port);
  157. xhci_base = nlm_read_usb_reg(pci_base, 0x4) & ~0xf;
  158. corebase = ioremap(xhci_base, 0x10000);
  159. if (!corebase)
  160. return;
  161. writel(0x240002, corebase + 0xc2c0);
  162. /* GCTL 0xc110 */
  163. val = readl(corebase + 0xc110);
  164. val &= ~(0x3 << 12);
  165. val |= (1 << 12);
  166. writel(val, corebase + 0xc110);
  167. udelay(100);
  168. /* PHYCFG 0xc200 */
  169. val = readl(corebase + 0xc200);
  170. val &= ~(1 << 6);
  171. writel(val, corebase + 0xc200);
  172. udelay(100);
  173. /* PIPECTL 0xc2c0 */
  174. val = readl(corebase + 0xc2c0);
  175. val &= ~(1 << 17);
  176. writel(val, corebase + 0xc2c0);
  177. iounmap(corebase);
  178. }
  179. static int __init nlm_platform_xlpii_usb_init(void)
  180. {
  181. int node;
  182. if (!cpu_is_xlpii())
  183. return 0;
  184. if (!cpu_is_xlp9xx()) {
  185. /* XLP 2XX single node */
  186. pr_info("Initializing 2XX USB Interface\n");
  187. nlm_xlpii_usb_hw_reset(0, 1);
  188. nlm_xlpii_usb_hw_reset(0, 2);
  189. nlm_xlpii_usb_hw_reset(0, 3);
  190. nlm_set_pic_extra_ack(0, PIC_2XX_XHCI_0_IRQ, xlp2xx_usb_ack);
  191. nlm_set_pic_extra_ack(0, PIC_2XX_XHCI_1_IRQ, xlp2xx_usb_ack);
  192. nlm_set_pic_extra_ack(0, PIC_2XX_XHCI_2_IRQ, xlp2xx_usb_ack);
  193. return 0;
  194. }
  195. /* XLP 9XX, multi-node */
  196. pr_info("Initializing 9XX/5XX USB Interface\n");
  197. for (node = 0; node < NLM_NR_NODES; node++) {
  198. if (!nlm_node_present(node))
  199. continue;
  200. nlm_xlpii_usb_hw_reset(node, 1);
  201. nlm_xlpii_usb_hw_reset(node, 2);
  202. nlm_xlpii_usb_hw_reset(node, 3);
  203. nlm_set_pic_extra_ack(node, PIC_9XX_XHCI_0_IRQ, xlp9xx_usb_ack);
  204. nlm_set_pic_extra_ack(node, PIC_9XX_XHCI_1_IRQ, xlp9xx_usb_ack);
  205. nlm_set_pic_extra_ack(node, PIC_9XX_XHCI_2_IRQ, xlp9xx_usb_ack);
  206. }
  207. return 0;
  208. }
  209. arch_initcall(nlm_platform_xlpii_usb_init);
  210. static u64 xlp_usb_dmamask = ~(u32)0;
  211. /* Fixup the IRQ for USB devices which is exist on XLP9XX SOC PCIE bus */
  212. static void nlm_xlp9xx_usb_fixup_final(struct pci_dev *dev)
  213. {
  214. int node;
  215. node = xlp_socdev_to_node(dev);
  216. dev->dev.dma_mask = &xlp_usb_dmamask;
  217. dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  218. switch (dev->devfn) {
  219. case 0x21:
  220. dev->irq = nlm_irq_to_xirq(node, PIC_9XX_XHCI_0_IRQ);
  221. break;
  222. case 0x22:
  223. dev->irq = nlm_irq_to_xirq(node, PIC_9XX_XHCI_1_IRQ);
  224. break;
  225. case 0x23:
  226. dev->irq = nlm_irq_to_xirq(node, PIC_9XX_XHCI_2_IRQ);
  227. break;
  228. }
  229. }
  230. /* Fixup the IRQ for USB devices which is exist on XLP2XX SOC PCIE bus */
  231. static void nlm_xlp2xx_usb_fixup_final(struct pci_dev *dev)
  232. {
  233. dev->dev.dma_mask = &xlp_usb_dmamask;
  234. dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  235. switch (dev->devfn) {
  236. case 0x21:
  237. dev->irq = PIC_2XX_XHCI_0_IRQ;
  238. break;
  239. case 0x22:
  240. dev->irq = PIC_2XX_XHCI_1_IRQ;
  241. break;
  242. case 0x23:
  243. dev->irq = PIC_2XX_XHCI_2_IRQ;
  244. break;
  245. }
  246. }
  247. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_XLP9XX_XHCI,
  248. nlm_xlp9xx_usb_fixup_final);
  249. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_NETLOGIC, PCI_DEVICE_ID_NLM_XHCI,
  250. nlm_xlp2xx_usb_fixup_final);