1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2014 Marvell
4 * Author: Gregory CLEMENT <gregory.clement@free-electrons.com>
8 #include <linux/mbus.h>
10 #include <linux/platform_device.h>
11 #include <linux/phy/phy.h>
13 #include <linux/usb.h>
14 #include <linux/usb/hcd.h>
16 #include "xhci-mvebu.h"
19 #define USB3_MAX_WINDOWS 4
20 #define USB3_WIN_CTRL(w) (0x0 + ((w) * 8))
21 #define USB3_WIN_BASE(w) (0x4 + ((w) * 8))
23 static void xhci_mvebu_mbus_config(void __iomem *base,
24 const struct mbus_dram_target_info *dram)
28 /* Clear all existing windows */
29 for (win = 0; win < USB3_MAX_WINDOWS; win++) {
30 writel(0, base + USB3_WIN_CTRL(win));
31 writel(0, base + USB3_WIN_BASE(win));
34 /* Program each DRAM CS in a seperate window */
35 for (win = 0; win < dram->num_cs; win++) {
36 const struct mbus_dram_window *cs = dram->cs + win;
38 writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) |
39 (dram->mbus_dram_target_id << 4) | 1,
40 base + USB3_WIN_CTRL(win));
42 writel((cs->base & 0xffff0000), base + USB3_WIN_BASE(win));
46 int xhci_mvebu_mbus_init_quirk(struct usb_hcd *hcd)
48 struct device *dev = hcd->self.controller;
49 struct platform_device *pdev = to_platform_device(dev);
52 const struct mbus_dram_target_info *dram;
54 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
59 * We don't use devm_ioremap() because this mapping should
60 * only exists for the duration of this probe function.
62 base = ioremap(res->start, resource_size(res));
66 dram = mv_mbus_dram_info();
67 xhci_mvebu_mbus_config(base, dram);
70 * This memory area was only needed to configure the MBus
71 * windows, and is therefore no longer useful.
78 int xhci_mvebu_a3700_plat_setup(struct usb_hcd *hcd)
80 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
81 struct device *dev = hcd->self.controller;
85 /* Old bindings miss the PHY handle */
86 phy = of_phy_get(dev->of_node, "usb3-phy");
87 if (IS_ERR(phy) && PTR_ERR(phy) == -EPROBE_DEFER)
96 ret = phy_set_mode(phy, PHY_MODE_USB_HOST_SS);
100 ret = phy_power_on(phy);
101 if (ret == -EOPNOTSUPP) {
102 /* Skip initializatin of XHCI PHY when it is unsupported by firmware */
103 dev_warn(dev, "PHY unsupported by firmware\n");
104 xhci->quirks |= XHCI_SKIP_PHY_INIT;
119 int xhci_mvebu_a3700_init_quirk(struct usb_hcd *hcd)
121 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
123 /* Without reset on resume, the HC won't work at all */
124 xhci->quirks |= XHCI_RESET_ON_RESUME;