bcm53xx: simpify USB 3.0 PHY initialization
[openwrt.git] / target / linux / bcm53xx / patches-4.4 / 197-USB-bcma-add-USB-3.0-support.patch
1 From 121ec6539abedbc0e975cf35f48ee044b323e4c3 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 v3 5/6] 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
9 Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
10 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
11 ---
12  drivers/usb/host/bcma-hcd.c | 225 ++++++++++++++++++++++++++++++++++++++++++++
13  1 file changed, 225 insertions(+)
14
15 --- a/drivers/usb/host/bcma-hcd.c
16 +++ b/drivers/usb/host/bcma-hcd.c
17 @@ -29,6 +29,7 @@
18  #include <linux/of_gpio.h>
19  #include <linux/usb/ehci_pdriver.h>
20  #include <linux/usb/ohci_pdriver.h>
21 +#include <linux/usb/xhci_pdriver.h>
22  
23  MODULE_AUTHOR("Hauke Mehrtens");
24  MODULE_DESCRIPTION("Common USB driver for BCMA Bus");
25 @@ -38,6 +39,7 @@ struct bcma_hcd_device {
26         struct bcma_device *core;
27         struct platform_device *ehci_dev;
28         struct platform_device *ohci_dev;
29 +       struct platform_device *xhci_dev;
30         struct gpio_desc *gpio_desc;
31  };
32  
33 @@ -245,6 +247,10 @@ static const struct usb_ehci_pdata ehci_
34  static const struct usb_ohci_pdata ohci_pdata = {
35  };
36  
37 +static const struct usb_xhci_pdata xhci_pdata = {
38 +       .usb3_fake_doorbell = 1
39 +};
40 +
41  static struct platform_device *bcma_hcd_create_pdev(struct bcma_device *dev,
42                                                     const char *name, u32 addr,
43                                                     const void *data,
44 @@ -338,6 +344,165 @@ err_unregister_ohci_dev:
45         return err;
46  }
47  
48 +static bool bcma_wait_reg(struct bcma_bus *bus, void __iomem *addr, u32 mask,
49 +                         u32 value, int timeout)
50 +{
51 +       unsigned long deadline = jiffies + timeout;
52 +       u32 val;
53 +
54 +       do {
55 +               val = readl(addr);
56 +               if ((val & mask) == value)
57 +                       return true;
58 +               cpu_relax();
59 +               udelay(10);
60 +       } while (!time_after_eq(jiffies, deadline));
61 +
62 +       pr_err("Timeout waiting for register %p\n", addr);
63 +
64 +       return false;
65 +}
66 +
67 +static void bcma_hcd_usb30_phy_init(struct bcma_hcd_device *bcma_hcd)
68 +{
69 +       struct bcma_device *core = bcma_hcd->core;
70 +       struct bcma_bus *bus = core->bus;
71 +       struct bcma_chipinfo *chipinfo = &bus->chipinfo;
72 +       struct bcma_drv_cc_b *ccb = &bus->drv_cc_b;
73 +       struct bcma_device *arm_core;
74 +       void __iomem *dmu = NULL;
75 +       u32 cru_straps_ctrl;
76 +
77 +       if (chipinfo->id != BCMA_CHIP_ID_BCM4707 &&
78 +           chipinfo->id != BCMA_CHIP_ID_BCM53018)
79 +               return;
80 +
81 +       arm_core = bcma_find_core(bus, BCMA_CORE_ARMCA9);
82 +       if (!arm_core)
83 +               return;
84 +
85 +       dmu = ioremap_nocache(arm_core->addr_s[0], 0x1000);
86 +       if (!dmu)
87 +               goto out;
88 +
89 +       /* Check strapping of PCIE/USB3 SEL */
90 +       cru_straps_ctrl = ioread32(dmu + 0x2a0);
91 +       if ((cru_straps_ctrl & 0x10) == 0)
92 +               goto out;
93 +
94 +       /* Perform USB3 system soft reset */
95 +       bcma_awrite32(core, BCMA_RESET_CTL, BCMA_RESET_CTL_RESET);
96 +
97 +       /* Enable MDIO. Setting MDCDIV as 26  */
98 +       iowrite32(0x0000009a, ccb->mii + 0x000);
99 +       udelay(2);
100 +
101 +       if (chipinfo->id == BCMA_CHIP_ID_BCM53018 ||
102 +           chipinfo->id == BCMA_CHIP_ID_BCM4707 && chipinfo->rev == 4) {
103 +                       /* For NS-B0, USB3 PLL Block */
104 +                       bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
105 +                       iowrite32(0x587e8000, ccb->mii + 0x004);
106 +
107 +                       /* Clear ana_pllSeqStart */
108 +                       bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
109 +                       iowrite32(0x58061000, ccb->mii + 0x004);
110 +
111 +                       /* CMOS Divider ratio to 25 */
112 +                       bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
113 +                       iowrite32(0x582a6400, ccb->mii + 0x004);
114 +
115 +                       /* Asserting PLL Reset */
116 +                       bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
117 +                       iowrite32(0x582ec000, ccb->mii + 0x004);
118 +
119 +                       /* Deaaserting PLL Reset */
120 +                       bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
121 +                       iowrite32(0x582e8000, ccb->mii + 0x004);
122 +
123 +                       /* Waiting MII Mgt interface idle */
124 +                       bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
125 +
126 +                       /* Deasserting USB3 system reset */
127 +                       bcma_awrite32(core, BCMA_RESET_CTL, 0);
128 +
129 +                       /* PLL frequency monitor enable */
130 +                       bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
131 +                       iowrite32(0x58069000, ccb->mii + 0x004);
132 +
133 +                       /* PIPE Block */
134 +                       bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
135 +                       iowrite32(0x587e8060, ccb->mii + 0x004);
136 +
137 +                       /* CMPMAX & CMPMINTH setting */
138 +                       bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
139 +                       iowrite32(0x580af30d, ccb->mii + 0x004);
140 +
141 +                       /* DEGLITCH MIN & MAX setting */
142 +                       bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
143 +                       iowrite32(0x580e6302, ccb->mii + 0x004);
144 +
145 +                       /* TXPMD block */
146 +                       bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
147 +                       iowrite32(0x587e8040, ccb->mii + 0x004);
148 +
149 +                       /* Enabling SSC */
150 +                       bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
151 +                       iowrite32(0x58061003, ccb->mii + 0x004);
152 +
153 +                       /* Waiting MII Mgt interface idle */
154 +                       bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
155 +       } else if (chipinfo->id == BCMA_CHIP_ID_BCM4707) {
156 +                       /* PLL30 block */
157 +                       bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
158 +                       iowrite32(0x587e8000, ccb->mii + 0x004);
159 +
160 +                       bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
161 +                       iowrite32(0x582a6400, ccb->mii + 0x004);
162 +
163 +                       bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
164 +                       iowrite32(0x587e80e0, ccb->mii + 0x004);
165 +
166 +                       bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
167 +                       iowrite32(0x580a009c, ccb->mii + 0x004);
168 +
169 +                       /* Enable SSC */
170 +                       bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
171 +                       iowrite32(0x587e8040, ccb->mii + 0x004);
172 +
173 +                       bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
174 +                       iowrite32(0x580a21d3, ccb->mii + 0x004);
175 +
176 +                       bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
177 +                       iowrite32(0x58061003, ccb->mii + 0x004);
178 +
179 +                       /* Waiting MII Mgt interface idle */
180 +                       bcma_wait_reg(bus, ccb->mii + 0x000, 0x0100, 0x0000, 1000);
181 +
182 +                       /* Deasserting USB3 system reset */
183 +                       bcma_awrite32(core, BCMA_RESET_CTL, 0);
184 +       }
185 +out:
186 +       if (dmu)
187 +               iounmap(dmu);
188 +}
189 +
190 +static int bcma_hcd_usb30_init(struct bcma_hcd_device *bcma_hcd)
191 +{
192 +       struct bcma_device *core = bcma_hcd->core;
193 +
194 +       bcma_core_enable(core, 0);
195 +
196 +       bcma_hcd_usb30_phy_init(bcma_hcd);
197 +
198 +       bcma_hcd->xhci_dev = bcma_hcd_create_pdev(core, "xhci-hcd", core->addr,
199 +                                                 &xhci_pdata,
200 +                                                 sizeof(xhci_pdata));
201 +       if (IS_ERR(bcma_hcd->ohci_dev))
202 +               return PTR_ERR(bcma_hcd->ohci_dev);
203 +
204 +       return 0;
205 +}
206 +
207  static int bcma_hcd_probe(struct bcma_device *core)
208  {
209         int err;
210 @@ -364,6 +529,11 @@ static int bcma_hcd_probe(struct bcma_de
211                 if (err)
212                         return err;
213                 break;
214 +       case BCMA_CORE_NS_USB30:
215 +               err = bcma_hcd_usb30_init(usb_dev);
216 +               if (err)
217 +                       return err;
218 +               break;
219         default:
220                 return -ENODEV;
221         }
222 @@ -377,11 +547,14 @@ static void bcma_hcd_remove(struct bcma_
223         struct bcma_hcd_device *usb_dev = bcma_get_drvdata(dev);
224         struct platform_device *ohci_dev = usb_dev->ohci_dev;
225         struct platform_device *ehci_dev = usb_dev->ehci_dev;
226 +       struct platform_device *xhci_dev = usb_dev->xhci_dev;
227  
228         if (ohci_dev)
229                 platform_device_unregister(ohci_dev);
230         if (ehci_dev)
231                 platform_device_unregister(ehci_dev);
232 +       if (xhci_dev)
233 +               platform_device_unregister(xhci_dev);
234  
235         bcma_core_disable(dev, 0);
236  }
237 @@ -418,6 +591,7 @@ static int bcma_hcd_resume(struct bcma_d
238  static const struct bcma_device_id bcma_hcd_table[] = {
239         BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_USB20_HOST, BCMA_ANY_REV, BCMA_ANY_CLASS),
240         BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_NS_USB20, BCMA_ANY_REV, BCMA_ANY_CLASS),
241 +       BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_NS_USB30, BCMA_ANY_REV, BCMA_ANY_CLASS),
242         {},
243  };
244  MODULE_DEVICE_TABLE(bcma, bcma_hcd_table);