usb-init-xlp2.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. default:
  118. pr_err("No matching USB irq %d node %d!\n", irq, node);
  119. return;
  120. }
  121. nlm_write_usb_reg(port_addr, XLPII_USB3_INT_REG, 0xffffffff);
  122. }
  123. static void nlm_xlpii_usb_hw_reset(int node, int port)
  124. {
  125. u64 port_addr, xhci_base, pci_base;
  126. void __iomem *corebase;
  127. u32 val;
  128. port_addr = nlm_xlpii_get_usb_regbase(node, port);
  129. /* Set frequency */
  130. val = nlm_read_usb_reg(port_addr, XLPII_USB_PHY_LOS_LV);
  131. val &= ~(0x3f << XLPII_FSEL);
  132. val |= (0x27 << XLPII_FSEL);
  133. nlm_write_usb_reg(port_addr, XLPII_USB_PHY_LOS_LV, val);
  134. val = nlm_read_usb_reg(port_addr, XLPII_USB_RFCLK_REG);
  135. val |= (1 << XLPII_VVLD);
  136. nlm_write_usb_reg(port_addr, XLPII_USB_RFCLK_REG, val);
  137. /* PHY reset */
  138. val = nlm_read_usb_reg(port_addr, XLPII_USB_PHY_TEST);
  139. val &= (XLPII_ATERESET | XLPII_LOOPEN | XLPII_TESTPDHSP
  140. | XLPII_TESTPDSSP | XLPII_TESTBURNIN);
  141. nlm_write_usb_reg(port_addr, XLPII_USB_PHY_TEST, val);
  142. /* Setup control register */
  143. val = XLPII_VAUXRST | XLPII_VCCRST | (1 << XLPII_NUM2PORT)
  144. | (1 << XLPII_NUM3PORT) | XLPII_MS_CSYSREQ | XLPII_XS_CSYSREQ
  145. | XLPII_RETENABLEN | XLPII_XHCIREV;
  146. nlm_write_usb_reg(port_addr, XLPII_USB3_CTL_0, val);
  147. /* Enable interrupts */
  148. nlm_write_usb_reg(port_addr, XLPII_USB3_INT_MASK, 0x00000001);
  149. /* Clear all interrupts */
  150. nlm_write_usb_reg(port_addr, XLPII_USB3_INT_REG, 0xffffffff);
  151. udelay(2000);
  152. /* XHCI configuration at PCI mem */
  153. pci_base = nlm_xlpii_get_usb_pcibase(node, port);
  154. xhci_base = nlm_read_usb_reg(pci_base, 0x4) & ~0xf;
  155. corebase = ioremap(xhci_base, 0x10000);
  156. if (!corebase)
  157. return;
  158. writel(0x240002, corebase + 0xc2c0);
  159. /* GCTL 0xc110 */
  160. val = readl(corebase + 0xc110);
  161. val &= ~(0x3 << 12);
  162. val |= (1 << 12);
  163. writel(val, corebase + 0xc110);
  164. udelay(100);
  165. /* PHYCFG 0xc200 */
  166. val = readl(corebase + 0xc200);
  167. val &= ~(1 << 6);
  168. writel(val, corebase + 0xc200);
  169. udelay(100);
  170. /* PIPECTL 0xc2c0 */
  171. val = readl(corebase + 0xc2c0);
  172. val &= ~(1 << 17);
  173. writel(val, corebase + 0xc2c0);
  174. iounmap(corebase);
  175. }
  176. static int __init nlm_platform_xlpii_usb_init(void)
  177. {
  178. int node;
  179. if (!cpu_is_xlpii())
  180. return 0;
  181. if (!cpu_is_xlp9xx()) {
  182. /* XLP 2XX single node */
  183. pr_info("Initializing 2XX USB Interface\n");
  184. nlm_xlpii_usb_hw_reset(0, 1);
  185. nlm_xlpii_usb_hw_reset(0, 2);
  186. nlm_xlpii_usb_hw_reset(0, 3);
  187. nlm_set_pic_extra_ack(0, PIC_2XX_XHCI_0_IRQ, xlp2xx_usb_ack);
  188. nlm_set_pic_extra_ack(0, PIC_2XX_XHCI_1_IRQ, xlp2xx_usb_ack);
  189. nlm_set_pic_extra_ack(0, PIC_2XX_XHCI_2_IRQ, xlp2xx_usb_ack);
  190. return 0;
  191. }
  192. /* XLP 9XX, multi-node */
  193. pr_info("Initializing 9XX USB Interface\n");
  194. for (node = 0; node < NLM_NR_NODES; node++) {
  195. if (!nlm_node_present(node))
  196. continue;
  197. nlm_xlpii_usb_hw_reset(node, 1);
  198. nlm_xlpii_usb_hw_reset(node, 2);
  199. nlm_set_pic_extra_ack(node, PIC_9XX_XHCI_0_IRQ, xlp9xx_usb_ack);
  200. nlm_set_pic_extra_ack(node, PIC_9XX_XHCI_1_IRQ, xlp9xx_usb_ack);
  201. }
  202. return 0;
  203. }
  204. arch_initcall(nlm_platform_xlpii_usb_init);
  205. static u64 xlp_usb_dmamask = ~(u32)0;
  206. /* Fixup the IRQ for USB devices which is exist on XLP9XX SOC PCIE bus */
  207. static void nlm_xlp9xx_usb_fixup_final(struct pci_dev *dev)
  208. {
  209. int node;
  210. node = xlp_socdev_to_node(dev);
  211. dev->dev.dma_mask = &xlp_usb_dmamask;
  212. dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  213. switch (dev->devfn) {
  214. case 0x21:
  215. dev->irq = nlm_irq_to_xirq(node, PIC_9XX_XHCI_0_IRQ);
  216. break;
  217. case 0x22:
  218. dev->irq = nlm_irq_to_xirq(node, PIC_9XX_XHCI_1_IRQ);
  219. break;
  220. }
  221. }
  222. /* Fixup the IRQ for USB devices which is exist on XLP2XX SOC PCIE bus */
  223. static void nlm_xlp2xx_usb_fixup_final(struct pci_dev *dev)
  224. {
  225. dev->dev.dma_mask = &xlp_usb_dmamask;
  226. dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  227. switch (dev->devfn) {
  228. case 0x21:
  229. dev->irq = PIC_2XX_XHCI_0_IRQ;
  230. break;
  231. case 0x22:
  232. dev->irq = PIC_2XX_XHCI_1_IRQ;
  233. break;
  234. case 0x23:
  235. dev->irq = PIC_2XX_XHCI_2_IRQ;
  236. break;
  237. }
  238. }
  239. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_XLP9XX_XHCI,
  240. nlm_xlp9xx_usb_fixup_final);
  241. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_NETLOGIC, PCI_DEVICE_ID_NLM_XHCI,
  242. nlm_xlp2xx_usb_fixup_final);