aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/cns21xx/patches-3.10/104-cns21xx-usb-ehci-support.patch
blob: 6ccfa4dee937440973741be7da75b468ba2a4185 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
--- /dev/null
+++ b/drivers/usb/host/ehci-cns21xx.c
@@ -0,0 +1,130 @@
+/*
+ *  Copyright (c) 2008 Cavium Networks
+ *  Copyright (c) 2010-2013 Gabor Juhos <juhosg@openwrt.org>
+ *
+ *  This file is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License, Version 2, as
+ *  published by the Free Software Foundation.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/io.h>
+#include <linux/platform_device.h>
+#include <linux/irq.h>
+#include <linux/usb.h>
+#include <linux/usb/hcd.h>
+
+#include <mach/cns21xx.h>
+
+#include "ehci.h"
+
+#define DRIVER_NAME	"cns21xx-ehci"
+
+static const char hcd_name[] = "ehci-cns21xx";
+static struct hc_driver __read_mostly ehci_cns21xx_hc_driver;
+
+static void ehci_cns21xx_init_hc(void)
+{
+	void __iomem *base = (void __iomem *) CNS21XX_EHCI_CONFIG_BASE_VIRT;
+
+	__raw_writel(0x106, base + 0x04);
+	__raw_writel((3 << 5) | 0x2000, base + 0x40);
+	msleep(100);
+}
+
+static int ehci_cns21xx_probe(struct platform_device *pdev)
+{
+	struct usb_hcd *hcd;
+	struct ehci_hcd *ehci;
+	struct resource *res;
+	int irq;
+	int ret;
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0) {
+		dev_dbg(&pdev->dev, "no IRQ specified for %s\n",
+			dev_name(&pdev->dev));
+		return -ENODEV;
+	}
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_dbg(&pdev->dev, "no base address specified for %s\n",
+			dev_name(&pdev->dev));
+		return -EINVAL;
+	}
+
+	hcd = usb_create_hcd(&ehci_cns21xx_hc_driver, &pdev->dev,
+			     dev_name(&pdev->dev));
+	if (!hcd)
+		return -ENOMEM;
+
+	hcd->rsrc_start	= res->start;
+	hcd->rsrc_len	= res->end - res->start + 1;
+
+	hcd->regs = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(hcd->regs)) {
+		ret = PTR_ERR(hcd->regs);
+		goto err_put_hcd;
+	}
+
+	ehci_cns21xx_init_hc();
+
+	ehci = hcd_to_ehci(hcd);
+	ehci->caps = hcd->regs;
+
+	ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
+	if (ret)
+		goto err_put_hcd;
+
+	platform_set_drvdata(pdev, hcd);
+
+	return 0;
+
+err_put_hcd:
+	usb_put_hcd(hcd);
+
+	return ret;
+}
+
+static int ehci_cns21xx_remove(struct platform_device *pdev)
+{
+	struct usb_hcd *hcd = platform_get_drvdata(pdev);
+
+	usb_remove_hcd(hcd);
+	usb_put_hcd(hcd);
+
+	return 0;
+}
+
+static struct platform_driver ehci_cns21xx_driver = {
+	.probe		= ehci_cns21xx_probe,
+	.remove		= ehci_cns21xx_remove,
+	.shutdown       = usb_hcd_platform_shutdown,
+	.driver		= {
+		.owner	= THIS_MODULE,
+		.name	= DRIVER_NAME,
+	},
+};
+
+static int __init ehci_cns21xx_init(void)
+{
+	if (usb_disabled())
+		return -ENODEV;
+
+	ehci_init_driver(&ehci_cns21xx_hc_driver, NULL);
+
+	return platform_driver_register(&ehci_cns21xx_driver);
+}
+module_init(ehci_cns21xx_init);
+
+static void __exit ehci_cns21xx_exit(void)
+{
+	platform_driver_unregister(&ehci_cns21xx_driver);
+}
+module_exit(ehci_cns21xx_exit);
+
+MODULE_DESCRIPTION("Cavium Networks CNS21xx built-in EHCI controller driver");
+MODULE_ALIAS("platform:" DRIVER_NAME);
+MODULE_LICENSE("GPL v2");
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -375,6 +375,7 @@ config ARCH_CNS21XX
 	select ARCH_REQUIRE_GPIOLIB
 	select ARM_L1_CACHE_SHIFT_4
 	select USB_ARCH_HAS_OHCI
+	select USB_ARCH_HAS_EHCI
 	help
 	  Support for Cavium Networks CNS21xx family.
 
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -249,6 +249,14 @@ config USB_W90X900_EHCI
 	---help---
 		Enables support for the W90X900 USB controller
 
+config USB_EHCI_CNS21XX
+	tristate "EHCI support for the Cavium CNS21XX SoCs"
+	depends on ARCH_CNS21XX
+	default y
+	help
+	  Enables support for the built-in EHCI controller of the
+	  Cavium CNS21xx SoCs.
+
 config USB_CNS3XXX_EHCI
 	bool "Cavium CNS3XXX EHCI Module (DEPRECATED)"
 	depends on ARCH_CNS3XXX
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -33,6 +33,7 @@ obj-$(CONFIG_USB_EHCI_HCD_SPEAR)	+= ehci
 obj-$(CONFIG_USB_EHCI_S5P)	+= ehci-s5p.o
 obj-$(CONFIG_USB_EHCI_HCD_AT91) += ehci-atmel.o
 obj-$(CONFIG_USB_EHCI_MSM)	+= ehci-msm.o
+obj-$(CONFIG_USB_EHCI_CNS21XX)	+= ehci-cns21xx.o
 
 obj-$(CONFIG_USB_OXU210HP_HCD)	+= oxu210hp-hcd.o
 obj-$(CONFIG_USB_ISP116X_HCD)	+= isp116x-hcd.o