Loading...
Note: File does not exist in v3.1.
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2014 Marvell
4 * Author: Gregory CLEMENT <gregory.clement@free-electrons.com>
5 */
6
7#include <linux/io.h>
8#include <linux/mbus.h>
9#include <linux/of.h>
10#include <linux/platform_device.h>
11
12#include <linux/usb.h>
13#include <linux/usb/hcd.h>
14
15#include "xhci-mvebu.h"
16
17#define USB3_MAX_WINDOWS 4
18#define USB3_WIN_CTRL(w) (0x0 + ((w) * 8))
19#define USB3_WIN_BASE(w) (0x4 + ((w) * 8))
20
21static void xhci_mvebu_mbus_config(void __iomem *base,
22 const struct mbus_dram_target_info *dram)
23{
24 int win;
25
26 /* Clear all existing windows */
27 for (win = 0; win < USB3_MAX_WINDOWS; win++) {
28 writel(0, base + USB3_WIN_CTRL(win));
29 writel(0, base + USB3_WIN_BASE(win));
30 }
31
32 /* Program each DRAM CS in a seperate window */
33 for (win = 0; win < dram->num_cs; win++) {
34 const struct mbus_dram_window *cs = dram->cs + win;
35
36 writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) |
37 (dram->mbus_dram_target_id << 4) | 1,
38 base + USB3_WIN_CTRL(win));
39
40 writel((cs->base & 0xffff0000), base + USB3_WIN_BASE(win));
41 }
42}
43
44int xhci_mvebu_mbus_init_quirk(struct usb_hcd *hcd)
45{
46 struct device *dev = hcd->self.controller;
47 struct platform_device *pdev = to_platform_device(dev);
48 struct resource *res;
49 void __iomem *base;
50 const struct mbus_dram_target_info *dram;
51
52 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
53 if (!res)
54 return -ENODEV;
55
56 /*
57 * We don't use devm_ioremap() because this mapping should
58 * only exists for the duration of this probe function.
59 */
60 base = ioremap(res->start, resource_size(res));
61 if (!base)
62 return -ENODEV;
63
64 dram = mv_mbus_dram_info();
65 xhci_mvebu_mbus_config(base, dram);
66
67 /*
68 * This memory area was only needed to configure the MBus
69 * windows, and is therefore no longer useful.
70 */
71 iounmap(base);
72
73 return 0;
74}