aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/dwc3
diff options
context:
space:
mode:
authorWingMan Kwok <w-kwok2@ti.com>2013-12-12 12:25:29 -0500
committerFelipe Balbi <balbi@ti.com>2013-12-12 14:43:07 -0500
commit943befc314ae5848e3be50d1fcdbdf6456e8d6d4 (patch)
treefc0c71c034ca515bc404b142e1466f6bc23f464a /drivers/usb/dwc3
parenta4b9d94b3dc8e65951c1819d37f213b3c6815adc (diff)
usb: dwc3: add Keystone specific glue layer
Add Keystone platform specific glue layer to support USB3 Host mode. [ balbi@ti.com : fix order of clk_disable() and platform_device_unregister() ] Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Acked-by: Santosh Shilimkar <santosh.shilimkar@ti.com> Signed-off-by: WingMan Kwok <w-kwok2@ti.com> Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/dwc3')
-rw-r--r--drivers/usb/dwc3/Kconfig7
-rw-r--r--drivers/usb/dwc3/Makefile1
-rw-r--r--drivers/usb/dwc3/dwc3-keystone.c202
3 files changed, 210 insertions, 0 deletions
diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig
index 70fc43027a5c..e2c730fc9a90 100644
--- a/drivers/usb/dwc3/Kconfig
+++ b/drivers/usb/dwc3/Kconfig
@@ -70,6 +70,13 @@ config USB_DWC3_PCI
70 One such PCIe-based platform is Synopsys' PCIe HAPS model of 70 One such PCIe-based platform is Synopsys' PCIe HAPS model of
71 this IP. 71 this IP.
72 72
73config USB_DWC3_KEYSTONE
74 tristate "Texas Instruments Keystone2 Platforms"
75 default USB_DWC3
76 help
77 Support of USB2/3 functionality in TI Keystone2 platforms.
78 Say 'Y' or 'M' here if you have one such device
79
73comment "Debugging features" 80comment "Debugging features"
74 81
75config USB_DWC3_DEBUG 82config USB_DWC3_DEBUG
diff --git a/drivers/usb/dwc3/Makefile b/drivers/usb/dwc3/Makefile
index dd1760145c46..10ac3e72482e 100644
--- a/drivers/usb/dwc3/Makefile
+++ b/drivers/usb/dwc3/Makefile
@@ -32,3 +32,4 @@ endif
32obj-$(CONFIG_USB_DWC3_OMAP) += dwc3-omap.o 32obj-$(CONFIG_USB_DWC3_OMAP) += dwc3-omap.o
33obj-$(CONFIG_USB_DWC3_EXYNOS) += dwc3-exynos.o 33obj-$(CONFIG_USB_DWC3_EXYNOS) += dwc3-exynos.o
34obj-$(CONFIG_USB_DWC3_PCI) += dwc3-pci.o 34obj-$(CONFIG_USB_DWC3_PCI) += dwc3-pci.o
35obj-$(CONFIG_USB_DWC3_KEYSTONE) += dwc3-keystone.o
diff --git a/drivers/usb/dwc3/dwc3-keystone.c b/drivers/usb/dwc3/dwc3-keystone.c
new file mode 100644
index 000000000000..1fad1618df6e
--- /dev/null
+++ b/drivers/usb/dwc3/dwc3-keystone.c
@@ -0,0 +1,202 @@
1/**
2 * dwc3-keystone.c - Keystone Specific Glue layer
3 *
4 * Copyright (C) 2010-2013 Texas Instruments Incorporated - http://www.ti.com
5 *
6 * Author: WingMan Kwok <w-kwok2@ti.com>
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 of
10 * the License as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
18#include <linux/clk.h>
19#include <linux/module.h>
20#include <linux/kernel.h>
21#include <linux/interrupt.h>
22#include <linux/platform_device.h>
23#include <linux/dma-mapping.h>
24#include <linux/io.h>
25#include <linux/of_platform.h>
26
27/* USBSS register offsets */
28#define USBSS_REVISION 0x0000
29#define USBSS_SYSCONFIG 0x0010
30#define USBSS_IRQ_EOI 0x0018
31#define USBSS_IRQSTATUS_RAW_0 0x0020
32#define USBSS_IRQSTATUS_0 0x0024
33#define USBSS_IRQENABLE_SET_0 0x0028
34#define USBSS_IRQENABLE_CLR_0 0x002c
35
36/* IRQ register bits */
37#define USBSS_IRQ_EOI_LINE(n) BIT(n)
38#define USBSS_IRQ_EVENT_ST BIT(0)
39#define USBSS_IRQ_COREIRQ_EN BIT(0)
40#define USBSS_IRQ_COREIRQ_CLR BIT(0)
41
42static u64 kdwc3_dma_mask;
43
44struct dwc3_keystone {
45 struct device *dev;
46 struct clk *clk;
47 void __iomem *usbss;
48};
49
50static inline u32 kdwc3_readl(void __iomem *base, u32 offset)
51{
52 return readl(base + offset);
53}
54
55static inline void kdwc3_writel(void __iomem *base, u32 offset, u32 value)
56{
57 writel(value, base + offset);
58}
59
60static void kdwc3_enable_irqs(struct dwc3_keystone *kdwc)
61{
62 u32 val;
63
64 val = kdwc3_readl(kdwc->usbss, USBSS_IRQENABLE_SET_0);
65 val |= USBSS_IRQ_COREIRQ_EN;
66 kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_SET_0, val);
67}
68
69static void kdwc3_disable_irqs(struct dwc3_keystone *kdwc)
70{
71 u32 val;
72
73 val = kdwc3_readl(kdwc->usbss, USBSS_IRQENABLE_SET_0);
74 val &= ~USBSS_IRQ_COREIRQ_EN;
75 kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_SET_0, val);
76}
77
78static irqreturn_t dwc3_keystone_interrupt(int irq, void *_kdwc)
79{
80 struct dwc3_keystone *kdwc = _kdwc;
81
82 kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_CLR_0, USBSS_IRQ_COREIRQ_CLR);
83 kdwc3_writel(kdwc->usbss, USBSS_IRQSTATUS_0, USBSS_IRQ_EVENT_ST);
84 kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_SET_0, USBSS_IRQ_COREIRQ_EN);
85 kdwc3_writel(kdwc->usbss, USBSS_IRQ_EOI, USBSS_IRQ_EOI_LINE(0));
86
87 return IRQ_HANDLED;
88}
89
90static int kdwc3_probe(struct platform_device *pdev)
91{
92 struct device *dev = &pdev->dev;
93 struct device_node *node = pdev->dev.of_node;
94 struct dwc3_keystone *kdwc;
95 struct resource *res;
96 int error, irq;
97
98 kdwc = devm_kzalloc(dev, sizeof(*kdwc), GFP_KERNEL);
99 if (!kdwc)
100 return -ENOMEM;
101
102 platform_set_drvdata(pdev, kdwc);
103
104 kdwc->dev = dev;
105
106 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
107 if (!res) {
108 dev_err(dev, "missing usbss resource\n");
109 return -EINVAL;
110 }
111
112 kdwc->usbss = devm_ioremap_resource(dev, res);
113 if (IS_ERR(kdwc->usbss))
114 return PTR_ERR(kdwc->usbss);
115
116 kdwc3_dma_mask = dma_get_mask(dev);
117 dev->dma_mask = &kdwc3_dma_mask;
118
119 kdwc->clk = devm_clk_get(kdwc->dev, "usb");
120
121 error = clk_prepare_enable(kdwc->clk);
122 if (error < 0) {
123 dev_dbg(kdwc->dev, "unable to enable usb clock, err %d\n",
124 error);
125 return error;
126 }
127
128 irq = platform_get_irq(pdev, 0);
129 if (irq < 0) {
130 dev_err(&pdev->dev, "missing irq\n");
131 goto err_irq;
132 }
133
134 error = devm_request_irq(dev, irq, dwc3_keystone_interrupt, IRQF_SHARED,
135 dev_name(dev), kdwc);
136 if (error) {
137 dev_err(dev, "failed to request IRQ #%d --> %d\n",
138 irq, error);
139 goto err_irq;
140 }
141
142 kdwc3_enable_irqs(kdwc);
143
144 error = of_platform_populate(node, NULL, NULL, dev);
145 if (error) {
146 dev_err(&pdev->dev, "failed to create dwc3 core\n");
147 goto err_core;
148 }
149
150 return 0;
151
152err_core:
153 kdwc3_disable_irqs(kdwc);
154err_irq:
155 clk_disable_unprepare(kdwc->clk);
156
157 return error;
158}
159
160static int kdwc3_remove_core(struct device *dev, void *c)
161{
162 struct platform_device *pdev = to_platform_device(dev);
163
164 platform_device_unregister(pdev);
165
166 return 0;
167}
168
169static int kdwc3_remove(struct platform_device *pdev)
170{
171 struct dwc3_keystone *kdwc = platform_get_drvdata(pdev);
172
173 kdwc3_disable_irqs(kdwc);
174 device_for_each_child(&pdev->dev, NULL, kdwc3_remove_core);
175 clk_disable_unprepare(kdwc->clk);
176 platform_set_drvdata(pdev, NULL);
177
178 return 0;
179}
180
181static const struct of_device_id kdwc3_of_match[] = {
182 { .compatible = "ti,keystone-dwc3", },
183 {},
184};
185MODULE_DEVICE_TABLE(of, kdwc3_of_match);
186
187static struct platform_driver kdwc3_driver = {
188 .probe = kdwc3_probe,
189 .remove = kdwc3_remove,
190 .driver = {
191 .name = "keystone-dwc3",
192 .owner = THIS_MODULE,
193 .of_match_table = kdwc3_of_match,
194 },
195};
196
197module_platform_driver(kdwc3_driver);
198
199MODULE_ALIAS("platform:keystone-dwc3");
200MODULE_AUTHOR("WingMan Kwok <w-kwok2@ti.com>");
201MODULE_LICENSE("GPL v2");
202MODULE_DESCRIPTION("DesignWare USB3 KEYSTONE Glue Layer");