2 * dwc3-omap.c - OMAP Specific Glue layer
4 * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
7 * Authors: Felipe Balbi <balbi@ti.com>,
8 * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions, and the following disclaimer,
15 * without modification.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. The names of the above-listed copyright holders may not be used
20 * to endorse or promote products derived from this software without
21 * specific prior written permission.
23 * ALTERNATIVELY, this software may be distributed under the terms of the
24 * GNU General Public License ("GPL") version 2, as published by the Free
25 * Software Foundation.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
28 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
29 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
31 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 #include <linux/kernel.h>
41 #include <linux/slab.h>
42 #include <linux/interrupt.h>
43 #include <linux/spinlock.h>
44 #include <linux/platform_device.h>
45 #include <linux/dma-mapping.h>
46 #include <linux/ioport.h>
52 * All these registers belong to OMAP's Wrapper around the
53 * DesignWare USB3 Core.
56 #define USBOTGSS_REVISION 0x0000
57 #define USBOTGSS_SYSCONFIG 0x0010
58 #define USBOTGSS_IRQ_EOI 0x0020
59 #define USBOTGSS_IRQSTATUS_RAW_0 0x0024
60 #define USBOTGSS_IRQSTATUS_0 0x0028
61 #define USBOTGSS_IRQENABLE_SET_0 0x002c
62 #define USBOTGSS_IRQENABLE_CLR_0 0x0030
63 #define USBOTGSS_IRQSTATUS_RAW_1 0x0034
64 #define USBOTGSS_IRQSTATUS_1 0x0038
65 #define USBOTGSS_IRQENABLE_SET_1 0x003c
66 #define USBOTGSS_IRQENABLE_CLR_1 0x0040
67 #define USBOTGSS_UTMI_OTG_CTRL 0x0080
68 #define USBOTGSS_UTMI_OTG_STATUS 0x0084
69 #define USBOTGSS_MMRAM_OFFSET 0x0100
70 #define USBOTGSS_FLADJ 0x0104
71 #define USBOTGSS_DEBUG_CFG 0x0108
72 #define USBOTGSS_DEBUG_DATA 0x010c
74 /* SYSCONFIG REGISTER */
75 #define USBOTGSS_SYSCONFIG_DMADISABLE (1 << 16)
76 #define USBOTGSS_SYSCONFIG_STANDBYMODE(x) ((x) << 4)
77 #define USBOTGSS_SYSCONFIG_IDLEMODE(x) ((x) << 2)
79 /* IRQ_EOI REGISTER */
80 #define USBOTGSS_IRQ_EOI_LINE_NUMBER (1 << 0)
83 #define USBOTGSS_IRQO_COREIRQ_ST (1 << 0)
86 #define USBOTGSS_IRQ1_DMADISABLECLR (1 << 17)
87 #define USBOTGSS_IRQ1_OEVT (1 << 16)
88 #define USBOTGSS_IRQ1_DRVVBUS_RISE (1 << 13)
89 #define USBOTGSS_IRQ1_CHRGVBUS_RISE (1 << 12)
90 #define USBOTGSS_IRQ1_DISCHRGVBUS_RISE (1 << 11)
91 #define USBOTGSS_IRQ1_IDPULLUP_RISE (1 << 8)
92 #define USBOTGSS_IRQ1_DRVVBUS_FALL (1 << 5)
93 #define USBOTGSS_IRQ1_CHRGVBUS_FALL (1 << 4)
94 #define USBOTGSS_IRQ1_DISCHRGVBUS_FALL (1 << 3)
95 #define USBOTGSS_IRQ1_IDPULLUP_FALL (1 << 0)
97 /* UTMI_OTG_CTRL REGISTER */
98 #define USBOTGSS_UTMI_OTG_CTRL_DRVVBUS (1 << 5)
99 #define USBOTGSS_UTMI_OTG_CTRL_CHRGVBUS (1 << 4)
100 #define USBOTGSS_UTMI_OTG_CTRL_DISCHRGVBUS (1 << 3)
101 #define USBOTGSS_UTMI_OTG_CTRL_IDPULLUP (1 << 0)
103 /* UTMI_OTG_STATUS REGISTER */
104 #define USBOTGSS_UTMI_OTG_STATUS_SW_MODE (1 << 31)
105 #define USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT (1 << 9)
106 #define USBOTGSS_UTMI_OTG_STATUS_TXBITSTUFFENABLE (1 << 8)
107 #define USBOTGSS_UTMI_OTG_STATUS_IDDIG (1 << 4)
108 #define USBOTGSS_UTMI_OTG_STATUS_SESSEND (1 << 3)
109 #define USBOTGSS_UTMI_OTG_STATUS_SESSVALID (1 << 2)
110 #define USBOTGSS_UTMI_OTG_STATUS_VBUSVALID (1 << 1)
116 struct platform_device
*dwc3
;
129 static int dwc3_omap_suspend(struct device
*dev
)
131 struct dwc3_omap
*omap
= dev_get_drvdata(dev
);
133 memcpy_fromio(omap
->context
, omap
->base
, omap
->resource_size
);
138 static int dwc3_omap_resume(struct device
*dev
)
140 struct dwc3_omap
*omap
= dev_get_drvdata(dev
);
142 memcpy_toio(omap
->base
, omap
->context
, omap
->resource_size
);
147 static int dwc3_omap_idle(struct device
*dev
)
149 struct dwc3_omap
*omap
= dev_get_drvdata(dev
);
152 /* stop DMA Engine */
153 reg
= dwc3_readl(omap
->base
, USBOTGSS_SYSCONFIG
);
154 reg
&= ~(USBOTGSS_SYSCONFIG_DMADISABLE
);
155 dwc3_writel(omap
->base
, USBOTGSS_SYSCONFIG
, reg
);
160 static UNIVERSAL_DEV_PM_OPS(dwc3_omap_pm_ops
, dwc3_omap_suspend
,
161 dwc3_omap_resume
, dwc3_omap_idle
);
163 #define DEV_PM_OPS (&dwc3_omap_pm_ops)
165 #define DEV_PM_OPS NULL
168 static irqreturn_t
dwc3_omap_interrupt(int irq
, void *_omap
)
170 struct dwc3_omap
*omap
= _omap
;
174 spin_lock(&omap
->lock
);
176 reg
= dwc3_readl(omap
->base
, USBOTGSS_IRQSTATUS_1
);
177 ctrl
= dwc3_readl(omap
->base
, USBOTGSS_UTMI_OTG_CTRL
);
179 if (reg
& USBOTGSS_IRQ1_DMADISABLECLR
) {
180 dev_dbg(omap
->base
, "DMA Disable was Cleared\n");
181 omap
->dma_status
= false;
184 if (reg
& USBOTGSS_IRQ1_OEVT
)
185 dev_dbg(omap
->base
, "OTG Event\n");
187 if (reg
& USBOTGSS_IRQ1_DRVVBUS_RISE
) {
188 dev_dbg(omap
->base
, "DRVVBUS Rise\n");
189 ctrl
|= USBOTGSS_UTMI_OTG_CTRL_DRVVBUS
;
192 if (reg
& USBOTGSS_IRQ1_CHRGVBUS_RISE
) {
193 dev_dbg(omap
->base
, "CHRGVBUS Rise\n");
194 ctrl
|= USBOTGSS_UTMI_OTG_CTRL_CHRGVBUS
;
197 if (reg
& USBOTGSS_IRQ1_DISCHRGVBUS_RISE
) {
198 dev_dbg(omap
->base
, "DISCHRGVBUS Rise\n");
199 ctrl
|= USBOTGSS_UTMI_OTG_CTRL_DISCHRGVBUS
;
202 if (reg
& USBOTGSS_IRQ1_IDPULLUP_RISE
) {
203 dev_dbg(omap
->base
, "IDPULLUP Rise\n");
204 ctrl
|= USBOTGSS_UTMI_OTG_CTRL_IDPULLUP
;
207 if (reg
& USBOTGSS_IRQ1_DRVVBUS_FALL
) {
208 dev_dbg(omap
->base
, "DRVVBUS Fall\n");
209 ctrl
&= ~USBOTGSS_UTMI_OTG_CTRL_DRVVBUS
;
212 if (reg
& USBOTGSS_IRQ1_CHRGVBUS_FALL
) {
213 dev_dbg(omap
->base
, "CHRGVBUS Fall\n");
214 ctrl
&= ~USBOTGSS_UTMI_OTG_CTRL_CHRGVBUS
;
217 if (reg
& USBOTGSS_IRQ1_DISCHRGVBUS_FALL
) {
218 dev_dbg(omap
->base
, "DISCHRGVBUS Fall\n");
219 ctrl
&= ~USBOTGSS_UTMI_OTG_CTRL_DISCHRGVBUS
;
222 if (reg
& USBOTGSS_IRQ1_IDPULLUP_FALL
) {
223 dev_dbg(omap
->base
, "IDPULLUP Fall\n");
224 ctrl
&= ~USBOTGSS_UTMI_OTG_CTRL_IDPULLUP
;
227 dwc3_writel(omap
->base
, USBOTGSS_UTMI_OTG_CTRL
, ctrl
);
229 spin_unlock(&omap
->lock
);
234 static int __devinit
dwc3_omap_probe(struct platform_device
*pdev
)
236 struct platform_device
*dwc3
;
237 struct dwc3_omap
*omap
;
238 struct resource
*res
;
248 omap
= kzalloc(sizeof(*omap
), GFP_KERNEL
);
250 dev_err(&pdev
->dev
, "not enough memory\n");
254 platform_set_drvdata(pdev
, omap
);
256 irq
= platform_get_irq(pdev
, 1);
258 dev_err(&pdev
->dev
, "missing IRQ resource\n");
263 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
265 dev_err(&pdev
->dev
, "missing memory base resource\n");
270 base
= ioremap_nocache(res
->start
, resource_size(res
));
272 dev_err(&pdev
->dev
, "ioremap failed\n");
276 dwc3
= platform_device_alloc("dwc3-omap", -1);
278 dev_err(&pdev
->dev
, "couldn't allocate dwc3 device\n");
282 context
= kzalloc(resource_size(res
), GFP_KERNEL
);
284 dev_err(&pdev
->dev
, "couldn't allocate dwc3 context memory\n");
288 spin_lock_init(&omap
->lock
);
289 dma_set_coherent_mask(&dwc3
->dev
, pdev
->dev
.coherent_dma_mask
);
291 dwc3
->dev
.parent
= &pdev
->dev
;
292 dwc3
->dev
.dma_mask
= pdev
->dev
.dma_mask
;
293 dwc3
->dev
.dma_parms
= pdev
->dev
.dma_parms
;
294 omap
->resource_size
= resource_size(res
);
295 omap
->context
= context
;
296 omap
->dev
= &pdev
->dev
;
301 /* check the DMA Status */
302 reg
= dwc3_readl(omap
->base
, USBOTGSS_SYSCONFIG
);
303 omap
->dma_status
= !!(reg
& USBOTGSS_SYSCONFIG_DMADISABLE
);
305 ret
= request_irq(omap
->irq
, dwc3_omap_interrupt
, 0,
306 "dwc3-wrapper", omap
);
308 dev_err(&pdev
->dev
, "failed to request IRQ #%d --> %d\n",
313 /* enable all IRQs */
314 dwc3_writel(omap
->base
, USBOTGSS_IRQENABLE_SET_0
, 0x01);
316 reg
= (USBOTGSS_IRQ1_DMADISABLECLR
|
318 USBOTGSS_IRQ1_DRVVBUS_RISE
|
319 USBOTGSS_IRQ1_CHRGVBUS_RISE
|
320 USBOTGSS_IRQ1_DISCHRGVBUS_RISE
|
321 USBOTGSS_IRQ1_IDPULLUP_RISE
|
322 USBOTGSS_IRQ1_DRVVBUS_FALL
|
323 USBOTGSS_IRQ1_CHRGVBUS_FALL
|
324 USBOTGSS_IRQ1_DISCHRGVBUS_FALL
|
325 USBOTGSS_IRQ1_IDPULLUP_FALL
);
327 dwc3_writel(omap
->base
, USBOTGSS_IRQENABLE_SET_1
, reg
);
329 ret
= platform_device_add_resources(dwc3
, pdev
->resource
,
330 pdev
->num_resources
);
332 dev_err(&pdev
->dev
, "couldn't add resources to dwc3 device\n");
336 ret
= platform_device_add(dwc3
);
338 dev_err(&pdev
->dev
, "failed to register dwc3 device\n");
345 free_irq(omap
->irq
, omap
);
348 kfree(omap
->context
);
351 platform_device_put(dwc3
);
363 static int __devexit
dwc3_omap_remove(struct platform_device
*pdev
)
365 struct dwc3_omap
*omap
= platform_get_drvdata(pdev
);
367 platform_device_unregister(omap
->dwc3
);
369 free_irq(omap
->irq
, omap
);
372 kfree(omap
->context
);
378 static const struct of_device_id of_dwc3_matach
[] = {
384 MODULE_DEVICE_TABLE(of
, of_dwc3_matach
);
386 static struct platform_driver dwc3_omap_driver
= {
387 .probe
= dwc3_omap_probe
,
388 .remove
= __devexit_p(dwc3_omap_remove
),
392 .of_match_table
= of_dwc3_matach
,
396 MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
397 MODULE_LICENSE("Dual BSD/GPL");
398 MODULE_DESCRIPTION("DesignWare USB3 OMAP Glue Layer");
400 static int __devinit
dwc3_omap_init(void)
402 return platform_driver_register(&dwc3_omap_driver
);
404 module_init(dwc3_omap_init
);
406 static void __exit
dwc3_omap_exit(void)
408 platform_driver_unregister(&dwc3_omap_driver
);
410 module_exit(dwc3_omap_exit
);