2 * Copyright (c) 2003-2013 Broadcom Corporation
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
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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
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.
35 #include <linux/dma-mapping.h>
36 #include <linux/kernel.h>
37 #include <linux/delay.h>
38 #include <linux/init.h>
39 #include <linux/pci.h>
40 #include <linux/platform_device.h>
41 #include <linux/irq.h>
43 #include <asm/netlogic/common.h>
44 #include <asm/netlogic/haldefs.h>
45 #include <asm/netlogic/xlp-hal/iomap.h>
46 #include <asm/netlogic/xlp-hal/xlp.h>
48 #define XLPII_USB3_CTL_0 0xc0
49 #define XLPII_VAUXRST BIT(0)
50 #define XLPII_VCCRST BIT(1)
51 #define XLPII_NUM2PORT 9
52 #define XLPII_NUM3PORT 13
53 #define XLPII_RTUNEREQ BIT(20)
54 #define XLPII_MS_CSYSREQ BIT(21)
55 #define XLPII_XS_CSYSREQ BIT(22)
56 #define XLPII_RETENABLEN BIT(23)
57 #define XLPII_TX2RX BIT(24)
58 #define XLPII_XHCIREV BIT(25)
59 #define XLPII_ECCDIS BIT(26)
61 #define XLPII_USB3_INT_REG 0xc2
62 #define XLPII_USB3_INT_MASK 0xc3
64 #define XLPII_USB_PHY_TEST 0xc6
65 #define XLPII_PRESET BIT(0)
66 #define XLPII_ATERESET BIT(1)
67 #define XLPII_LOOPEN BIT(2)
68 #define XLPII_TESTPDHSP BIT(3)
69 #define XLPII_TESTPDSSP BIT(4)
70 #define XLPII_TESTBURNIN BIT(5)
72 #define XLPII_USB_PHY_LOS_LV 0xc9
73 #define XLPII_LOSLEV 0
74 #define XLPII_LOSBIAS 5
75 #define XLPII_SQRXTX 8
76 #define XLPII_TXBOOST 11
77 #define XLPII_RSLKSEL 16
80 #define XLPII_USB_RFCLK_REG 0xcc
83 #define nlm_read_usb_reg(b, r) nlm_read_reg(b, r)
84 #define nlm_write_usb_reg(b, r, v) nlm_write_reg(b, r, v)
86 #define nlm_xlpii_get_usb_pcibase(node, inst) \
87 nlm_pcicfg_base(XLP2XX_IO_USB_OFFSET(node, inst))
88 #define nlm_xlpii_get_usb_regbase(node, inst) \
89 (nlm_xlpii_get_usb_pcibase(node, inst) + XLP_IO_PCI_HDRSZ)
91 static void xlpii_usb_ack(struct irq_data
*data
)
96 case PIC_2XX_XHCI_0_IRQ
:
97 port_addr
= nlm_xlpii_get_usb_regbase(0, 1);
99 case PIC_2XX_XHCI_1_IRQ
:
100 port_addr
= nlm_xlpii_get_usb_regbase(0, 2);
102 case PIC_2XX_XHCI_2_IRQ
:
103 port_addr
= nlm_xlpii_get_usb_regbase(0, 3);
106 pr_err("No matching USB irq!\n");
109 nlm_write_usb_reg(port_addr
, XLPII_USB3_INT_REG
, 0xffffffff);
112 static void nlm_xlpii_usb_hw_reset(int node
, int port
)
114 u64 port_addr
, xhci_base
, pci_base
;
115 void __iomem
*corebase
;
118 port_addr
= nlm_xlpii_get_usb_regbase(node
, port
);
121 val
= nlm_read_usb_reg(port_addr
, XLPII_USB_PHY_LOS_LV
);
122 val
&= ~(0x3f << XLPII_FSEL
);
123 val
|= (0x27 << XLPII_FSEL
);
124 nlm_write_usb_reg(port_addr
, XLPII_USB_PHY_LOS_LV
, val
);
126 val
= nlm_read_usb_reg(port_addr
, XLPII_USB_RFCLK_REG
);
127 val
|= (1 << XLPII_VVLD
);
128 nlm_write_usb_reg(port_addr
, XLPII_USB_RFCLK_REG
, val
);
131 val
= nlm_read_usb_reg(port_addr
, XLPII_USB_PHY_TEST
);
132 val
&= (XLPII_ATERESET
| XLPII_LOOPEN
| XLPII_TESTPDHSP
133 | XLPII_TESTPDSSP
| XLPII_TESTBURNIN
);
134 nlm_write_usb_reg(port_addr
, XLPII_USB_PHY_TEST
, val
);
136 /* Setup control register */
137 val
= XLPII_VAUXRST
| XLPII_VCCRST
| (1 << XLPII_NUM2PORT
)
138 | (1 << XLPII_NUM3PORT
) | XLPII_MS_CSYSREQ
| XLPII_XS_CSYSREQ
139 | XLPII_RETENABLEN
| XLPII_XHCIREV
;
140 nlm_write_usb_reg(port_addr
, XLPII_USB3_CTL_0
, val
);
142 /* Enable interrupts */
143 nlm_write_usb_reg(port_addr
, XLPII_USB3_INT_MASK
, 0x00000001);
145 /* Clear all interrupts */
146 nlm_write_usb_reg(port_addr
, XLPII_USB3_INT_REG
, 0xffffffff);
150 /* XHCI configuration at PCI mem */
151 pci_base
= nlm_xlpii_get_usb_pcibase(node
, port
);
152 xhci_base
= nlm_read_usb_reg(pci_base
, 0x4) & ~0xf;
153 corebase
= ioremap(xhci_base
, 0x10000);
157 writel(0x240002, corebase
+ 0xc2c0);
159 val
= readl(corebase
+ 0xc110);
162 writel(val
, corebase
+ 0xc110);
166 val
= readl(corebase
+ 0xc200);
168 writel(val
, corebase
+ 0xc200);
172 val
= readl(corebase
+ 0xc2c0);
174 writel(val
, corebase
+ 0xc2c0);
179 static int __init
nlm_platform_xlpii_usb_init(void)
184 pr_info("Initializing 2XX USB Interface\n");
185 nlm_xlpii_usb_hw_reset(0, 1);
186 nlm_xlpii_usb_hw_reset(0, 2);
187 nlm_xlpii_usb_hw_reset(0, 3);
188 nlm_set_pic_extra_ack(0, PIC_2XX_XHCI_0_IRQ
, xlpii_usb_ack
);
189 nlm_set_pic_extra_ack(0, PIC_2XX_XHCI_1_IRQ
, xlpii_usb_ack
);
190 nlm_set_pic_extra_ack(0, PIC_2XX_XHCI_2_IRQ
, xlpii_usb_ack
);
195 arch_initcall(nlm_platform_xlpii_usb_init
);
197 static u64 xlp_usb_dmamask
= ~(u32
)0;
199 /* Fixup IRQ for USB devices on XLP the SoC PCIe bus */
200 static void nlm_usb_fixup_final(struct pci_dev
*dev
)
202 dev
->dev
.dma_mask
= &xlp_usb_dmamask
;
203 dev
->dev
.coherent_dma_mask
= DMA_BIT_MASK(32);
204 switch (dev
->devfn
) {
206 dev
->irq
= PIC_2XX_XHCI_0_IRQ
;
209 dev
->irq
= PIC_2XX_XHCI_1_IRQ
;
212 dev
->irq
= PIC_2XX_XHCI_2_IRQ
;
217 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_NETLOGIC
, PCI_DEVICE_ID_NLM_XHCI
,
218 nlm_usb_fixup_final
);