usb-init-xlp2.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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/platform_device.h>
  40. #include <linux/irq.h>
  41. #include <asm/netlogic/common.h>
  42. #include <asm/netlogic/haldefs.h>
  43. #include <asm/netlogic/xlp-hal/iomap.h>
  44. #include <asm/netlogic/xlp-hal/xlp.h>
  45. #define XLPII_USB3_CTL_0 0xc0
  46. #define XLPII_VAUXRST BIT(0)
  47. #define XLPII_VCCRST BIT(1)
  48. #define XLPII_NUM2PORT 9
  49. #define XLPII_NUM3PORT 13
  50. #define XLPII_RTUNEREQ BIT(20)
  51. #define XLPII_MS_CSYSREQ BIT(21)
  52. #define XLPII_XS_CSYSREQ BIT(22)
  53. #define XLPII_RETENABLEN BIT(23)
  54. #define XLPII_TX2RX BIT(24)
  55. #define XLPII_XHCIREV BIT(25)
  56. #define XLPII_ECCDIS BIT(26)
  57. #define XLPII_USB3_INT_REG 0xc2
  58. #define XLPII_USB3_INT_MASK 0xc3
  59. #define XLPII_USB_PHY_TEST 0xc6
  60. #define XLPII_PRESET BIT(0)
  61. #define XLPII_ATERESET BIT(1)
  62. #define XLPII_LOOPEN BIT(2)
  63. #define XLPII_TESTPDHSP BIT(3)
  64. #define XLPII_TESTPDSSP BIT(4)
  65. #define XLPII_TESTBURNIN BIT(5)
  66. #define XLPII_USB_PHY_LOS_LV 0xc9
  67. #define XLPII_LOSLEV 0
  68. #define XLPII_LOSBIAS 5
  69. #define XLPII_SQRXTX 8
  70. #define XLPII_TXBOOST 11
  71. #define XLPII_RSLKSEL 16
  72. #define XLPII_FSEL 20
  73. #define XLPII_USB_RFCLK_REG 0xcc
  74. #define XLPII_VVLD 30
  75. #define nlm_read_usb_reg(b, r) nlm_read_reg(b, r)
  76. #define nlm_write_usb_reg(b, r, v) nlm_write_reg(b, r, v)
  77. #define nlm_xlpii_get_usb_pcibase(node, inst) \
  78. nlm_pcicfg_base(XLP2XX_IO_USB_OFFSET(node, inst))
  79. #define nlm_xlpii_get_usb_regbase(node, inst) \
  80. (nlm_xlpii_get_usb_pcibase(node, inst) + XLP_IO_PCI_HDRSZ)
  81. static void xlpii_usb_ack(struct irq_data *data)
  82. {
  83. u64 port_addr;
  84. switch (data->irq) {
  85. case PIC_2XX_XHCI_0_IRQ:
  86. port_addr = nlm_xlpii_get_usb_regbase(0, 1);
  87. break;
  88. case PIC_2XX_XHCI_1_IRQ:
  89. port_addr = nlm_xlpii_get_usb_regbase(0, 2);
  90. break;
  91. case PIC_2XX_XHCI_2_IRQ:
  92. port_addr = nlm_xlpii_get_usb_regbase(0, 3);
  93. break;
  94. default:
  95. pr_err("No matching USB irq!\n");
  96. return;
  97. }
  98. nlm_write_usb_reg(port_addr, XLPII_USB3_INT_REG, 0xffffffff);
  99. }
  100. static void nlm_xlpii_usb_hw_reset(int node, int port)
  101. {
  102. u64 port_addr, xhci_base, pci_base;
  103. void __iomem *corebase;
  104. u32 val;
  105. port_addr = nlm_xlpii_get_usb_regbase(node, port);
  106. /* Set frequency */
  107. val = nlm_read_usb_reg(port_addr, XLPII_USB_PHY_LOS_LV);
  108. val &= ~(0x3f << XLPII_FSEL);
  109. val |= (0x27 << XLPII_FSEL);
  110. nlm_write_usb_reg(port_addr, XLPII_USB_PHY_LOS_LV, val);
  111. val = nlm_read_usb_reg(port_addr, XLPII_USB_RFCLK_REG);
  112. val |= (1 << XLPII_VVLD);
  113. nlm_write_usb_reg(port_addr, XLPII_USB_RFCLK_REG, val);
  114. /* PHY reset */
  115. val = nlm_read_usb_reg(port_addr, XLPII_USB_PHY_TEST);
  116. val &= (XLPII_ATERESET | XLPII_LOOPEN | XLPII_TESTPDHSP
  117. | XLPII_TESTPDSSP | XLPII_TESTBURNIN);
  118. nlm_write_usb_reg(port_addr, XLPII_USB_PHY_TEST, val);
  119. /* Setup control register */
  120. val = XLPII_VAUXRST | XLPII_VCCRST | (1 << XLPII_NUM2PORT)
  121. | (1 << XLPII_NUM3PORT) | XLPII_MS_CSYSREQ | XLPII_XS_CSYSREQ
  122. | XLPII_RETENABLEN | XLPII_XHCIREV;
  123. nlm_write_usb_reg(port_addr, XLPII_USB3_CTL_0, val);
  124. /* Enable interrupts */
  125. nlm_write_usb_reg(port_addr, XLPII_USB3_INT_MASK, 0x00000001);
  126. /* Clear all interrupts */
  127. nlm_write_usb_reg(port_addr, XLPII_USB3_INT_REG, 0xffffffff);
  128. udelay(2000);
  129. /* XHCI configuration at PCI mem */
  130. pci_base = nlm_xlpii_get_usb_pcibase(node, port);
  131. xhci_base = nlm_read_usb_reg(pci_base, 0x4) & ~0xf;
  132. corebase = ioremap(xhci_base, 0x10000);
  133. if (!corebase)
  134. return;
  135. writel(0x240002, corebase + 0xc2c0);
  136. /* GCTL 0xc110 */
  137. val = readl(corebase + 0xc110);
  138. val &= ~(0x3 << 12);
  139. val |= (1 << 12);
  140. writel(val, corebase + 0xc110);
  141. udelay(100);
  142. /* PHYCFG 0xc200 */
  143. val = readl(corebase + 0xc200);
  144. val &= ~(1 << 6);
  145. writel(val, corebase + 0xc200);
  146. udelay(100);
  147. /* PIPECTL 0xc2c0 */
  148. val = readl(corebase + 0xc2c0);
  149. val &= ~(1 << 17);
  150. writel(val, corebase + 0xc2c0);
  151. iounmap(corebase);
  152. }
  153. static int __init nlm_platform_xlpii_usb_init(void)
  154. {
  155. if (!cpu_is_xlpii())
  156. return 0;
  157. pr_info("Initializing 2XX USB Interface\n");
  158. nlm_xlpii_usb_hw_reset(0, 1);
  159. nlm_xlpii_usb_hw_reset(0, 2);
  160. nlm_xlpii_usb_hw_reset(0, 3);
  161. nlm_set_pic_extra_ack(0, PIC_2XX_XHCI_0_IRQ, xlpii_usb_ack);
  162. nlm_set_pic_extra_ack(0, PIC_2XX_XHCI_1_IRQ, xlpii_usb_ack);
  163. nlm_set_pic_extra_ack(0, PIC_2XX_XHCI_2_IRQ, xlpii_usb_ack);
  164. return 0;
  165. }
  166. arch_initcall(nlm_platform_xlpii_usb_init);
  167. static u64 xlp_usb_dmamask = ~(u32)0;
  168. /* Fixup IRQ for USB devices on XLP the SoC PCIe bus */
  169. static void nlm_usb_fixup_final(struct pci_dev *dev)
  170. {
  171. dev->dev.dma_mask = &xlp_usb_dmamask;
  172. dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  173. switch (dev->devfn) {
  174. case 0x21:
  175. dev->irq = PIC_2XX_XHCI_0_IRQ;
  176. break;
  177. case 0x22:
  178. dev->irq = PIC_2XX_XHCI_1_IRQ;
  179. break;
  180. case 0x23:
  181. dev->irq = PIC_2XX_XHCI_2_IRQ;
  182. break;
  183. }
  184. }
  185. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_NETLOGIC, PCI_DEVICE_ID_NLM_XHCI,
  186. nlm_usb_fixup_final);