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