blob: f67ff4c4eaca549964a9acdd956e5c0e39a0a807 [file] [log] [blame]
Felipe Balbi72246da2011-08-19 18:10:58 +03001/**
2 * dwc3-omap.c - OMAP Specific Glue layer
3 *
4 * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
Felipe Balbi72246da2011-08-19 18:10:58 +03005 *
6 * Authors: Felipe Balbi <balbi@ti.com>,
7 * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions, and the following disclaimer,
14 * without modification.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The names of the above-listed copyright holders may not be used
19 * to endorse or promote products derived from this software without
20 * specific prior written permission.
21 *
22 * ALTERNATIVELY, this software may be distributed under the terms of the
23 * GNU General Public License ("GPL") version 2, as published by the Free
24 * Software Foundation.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
27 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
28 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
30 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */
38
Felipe Balbia72e6582011-09-05 13:37:28 +030039#include <linux/module.h>
Felipe Balbi72246da2011-08-19 18:10:58 +030040#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>
Felipe Balbi99624442011-09-01 22:26:25 +030045#include <linux/platform_data/dwc3-omap.h>
Kishon Vijay Abraham I7e41bba2013-01-25 08:30:49 +053046#include <linux/usb/dwc3-omap.h>
Kishon Vijay Abraham Iaf310e92013-01-25 08:30:47 +053047#include <linux/pm_runtime.h>
Felipe Balbi72246da2011-08-19 18:10:58 +030048#include <linux/dma-mapping.h>
49#include <linux/ioport.h>
50#include <linux/io.h>
Felipe Balbi45b3cd4a2012-01-25 11:07:03 +020051#include <linux/of.h>
Kishon Vijay Abraham Ib4bfe6a2013-01-25 08:30:46 +053052#include <linux/of_platform.h>
Felipe Balbi72246da2011-08-19 18:10:58 +030053
Felipe Balbia418cc42012-07-19 13:56:07 +030054#include <linux/usb/otg.h>
Felipe Balbia418cc42012-07-19 13:56:07 +030055
Felipe Balbi72246da2011-08-19 18:10:58 +030056/*
57 * All these registers belong to OMAP's Wrapper around the
58 * DesignWare USB3 Core.
59 */
60
61#define USBOTGSS_REVISION 0x0000
62#define USBOTGSS_SYSCONFIG 0x0010
63#define USBOTGSS_IRQ_EOI 0x0020
64#define USBOTGSS_IRQSTATUS_RAW_0 0x0024
65#define USBOTGSS_IRQSTATUS_0 0x0028
66#define USBOTGSS_IRQENABLE_SET_0 0x002c
67#define USBOTGSS_IRQENABLE_CLR_0 0x0030
68#define USBOTGSS_IRQSTATUS_RAW_1 0x0034
69#define USBOTGSS_IRQSTATUS_1 0x0038
70#define USBOTGSS_IRQENABLE_SET_1 0x003c
71#define USBOTGSS_IRQENABLE_CLR_1 0x0040
72#define USBOTGSS_UTMI_OTG_CTRL 0x0080
73#define USBOTGSS_UTMI_OTG_STATUS 0x0084
74#define USBOTGSS_MMRAM_OFFSET 0x0100
75#define USBOTGSS_FLADJ 0x0104
76#define USBOTGSS_DEBUG_CFG 0x0108
77#define USBOTGSS_DEBUG_DATA 0x010c
78
79/* SYSCONFIG REGISTER */
80#define USBOTGSS_SYSCONFIG_DMADISABLE (1 << 16)
Felipe Balbi4b5faa7a2011-09-06 10:56:51 +030081
Felipe Balbi72246da2011-08-19 18:10:58 +030082/* IRQ_EOI REGISTER */
83#define USBOTGSS_IRQ_EOI_LINE_NUMBER (1 << 0)
84
85/* IRQS0 BITS */
86#define USBOTGSS_IRQO_COREIRQ_ST (1 << 0)
87
88/* IRQ1 BITS */
89#define USBOTGSS_IRQ1_DMADISABLECLR (1 << 17)
90#define USBOTGSS_IRQ1_OEVT (1 << 16)
91#define USBOTGSS_IRQ1_DRVVBUS_RISE (1 << 13)
92#define USBOTGSS_IRQ1_CHRGVBUS_RISE (1 << 12)
93#define USBOTGSS_IRQ1_DISCHRGVBUS_RISE (1 << 11)
94#define USBOTGSS_IRQ1_IDPULLUP_RISE (1 << 8)
95#define USBOTGSS_IRQ1_DRVVBUS_FALL (1 << 5)
96#define USBOTGSS_IRQ1_CHRGVBUS_FALL (1 << 4)
97#define USBOTGSS_IRQ1_DISCHRGVBUS_FALL (1 << 3)
98#define USBOTGSS_IRQ1_IDPULLUP_FALL (1 << 0)
99
100/* UTMI_OTG_CTRL REGISTER */
101#define USBOTGSS_UTMI_OTG_CTRL_DRVVBUS (1 << 5)
102#define USBOTGSS_UTMI_OTG_CTRL_CHRGVBUS (1 << 4)
103#define USBOTGSS_UTMI_OTG_CTRL_DISCHRGVBUS (1 << 3)
104#define USBOTGSS_UTMI_OTG_CTRL_IDPULLUP (1 << 0)
105
106/* UTMI_OTG_STATUS REGISTER */
107#define USBOTGSS_UTMI_OTG_STATUS_SW_MODE (1 << 31)
108#define USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT (1 << 9)
109#define USBOTGSS_UTMI_OTG_STATUS_TXBITSTUFFENABLE (1 << 8)
110#define USBOTGSS_UTMI_OTG_STATUS_IDDIG (1 << 4)
111#define USBOTGSS_UTMI_OTG_STATUS_SESSEND (1 << 3)
112#define USBOTGSS_UTMI_OTG_STATUS_SESSVALID (1 << 2)
113#define USBOTGSS_UTMI_OTG_STATUS_VBUSVALID (1 << 1)
114
115struct dwc3_omap {
116 /* device lock */
117 spinlock_t lock;
118
Felipe Balbi72246da2011-08-19 18:10:58 +0300119 struct device *dev;
120
121 int irq;
122 void __iomem *base;
123
Felipe Balbif3e117f2013-02-11 11:12:02 +0200124 u32 utmi_otg_status;
George Cherian1e2a0642013-06-12 14:53:45 +0530125 u32 utmi_otg_offset;
126 u32 irqmisc_offset;
127 u32 irq_eoi_offset;
128 u32 debug_offset;
129 u32 irq0_offset;
130 u32 revision;
Felipe Balbif3e117f2013-02-11 11:12:02 +0200131
Felipe Balbi72246da2011-08-19 18:10:58 +0300132 u32 dma_status:1;
133};
134
Felipe Balbia33bb212013-03-14 16:00:58 +0200135static struct dwc3_omap *_omap;
Kishon Vijay Abraham I7e41bba2013-01-25 08:30:49 +0530136
Ido Shayevitzab5e59d2012-04-24 14:18:38 +0300137static inline u32 dwc3_omap_readl(void __iomem *base, u32 offset)
138{
139 return readl(base + offset);
140}
141
142static inline void dwc3_omap_writel(void __iomem *base, u32 offset, u32 value)
143{
144 writel(value, base + offset);
145}
146
Kishon Vijay Abraham I2ba79432013-03-07 18:51:44 +0530147int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status)
Kishon Vijay Abraham I7e41bba2013-01-25 08:30:49 +0530148{
149 u32 val;
150 struct dwc3_omap *omap = _omap;
151
Kishon Vijay Abraham I2ba79432013-03-07 18:51:44 +0530152 if (!omap)
153 return -EPROBE_DEFER;
154
Kishon Vijay Abraham I7e41bba2013-01-25 08:30:49 +0530155 switch (status) {
156 case OMAP_DWC3_ID_GROUND:
157 dev_dbg(omap->dev, "ID GND\n");
158
159 val = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS);
160 val &= ~(USBOTGSS_UTMI_OTG_STATUS_IDDIG
161 | USBOTGSS_UTMI_OTG_STATUS_VBUSVALID
162 | USBOTGSS_UTMI_OTG_STATUS_SESSEND);
163 val |= USBOTGSS_UTMI_OTG_STATUS_SESSVALID
164 | USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT;
165 dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, val);
166 break;
167
168 case OMAP_DWC3_VBUS_VALID:
169 dev_dbg(omap->dev, "VBUS Connect\n");
170
171 val = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS);
172 val &= ~USBOTGSS_UTMI_OTG_STATUS_SESSEND;
173 val |= USBOTGSS_UTMI_OTG_STATUS_IDDIG
174 | USBOTGSS_UTMI_OTG_STATUS_VBUSVALID
175 | USBOTGSS_UTMI_OTG_STATUS_SESSVALID
176 | USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT;
177 dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, val);
178 break;
179
180 case OMAP_DWC3_ID_FLOAT:
181 case OMAP_DWC3_VBUS_OFF:
182 dev_dbg(omap->dev, "VBUS Disconnect\n");
183
184 val = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS);
185 val &= ~(USBOTGSS_UTMI_OTG_STATUS_SESSVALID
186 | USBOTGSS_UTMI_OTG_STATUS_VBUSVALID
187 | USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT);
188 val |= USBOTGSS_UTMI_OTG_STATUS_SESSEND
189 | USBOTGSS_UTMI_OTG_STATUS_IDDIG;
190 dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, val);
191 break;
192
193 default:
194 dev_dbg(omap->dev, "ID float\n");
195 }
196
Kishon Vijay Abraham I2ba79432013-03-07 18:51:44 +0530197 return 0;
Kishon Vijay Abraham I7e41bba2013-01-25 08:30:49 +0530198}
199EXPORT_SYMBOL_GPL(dwc3_omap_mailbox);
200
Felipe Balbi72246da2011-08-19 18:10:58 +0300201static irqreturn_t dwc3_omap_interrupt(int irq, void *_omap)
202{
203 struct dwc3_omap *omap = _omap;
204 u32 reg;
Felipe Balbi72246da2011-08-19 18:10:58 +0300205
206 spin_lock(&omap->lock);
207
Ido Shayevitzab5e59d2012-04-24 14:18:38 +0300208 reg = dwc3_omap_readl(omap->base, USBOTGSS_IRQSTATUS_1);
Felipe Balbi72246da2011-08-19 18:10:58 +0300209
210 if (reg & USBOTGSS_IRQ1_DMADISABLECLR) {
Felipe Balbiccba3bc2011-09-01 14:46:16 +0300211 dev_dbg(omap->dev, "DMA Disable was Cleared\n");
Felipe Balbi72246da2011-08-19 18:10:58 +0300212 omap->dma_status = false;
213 }
214
215 if (reg & USBOTGSS_IRQ1_OEVT)
Felipe Balbiccba3bc2011-09-01 14:46:16 +0300216 dev_dbg(omap->dev, "OTG Event\n");
Felipe Balbi72246da2011-08-19 18:10:58 +0300217
Felipe Balbi42077b02011-09-06 12:00:39 +0300218 if (reg & USBOTGSS_IRQ1_DRVVBUS_RISE)
Felipe Balbiccba3bc2011-09-01 14:46:16 +0300219 dev_dbg(omap->dev, "DRVVBUS Rise\n");
Felipe Balbi72246da2011-08-19 18:10:58 +0300220
Felipe Balbi42077b02011-09-06 12:00:39 +0300221 if (reg & USBOTGSS_IRQ1_CHRGVBUS_RISE)
Felipe Balbiccba3bc2011-09-01 14:46:16 +0300222 dev_dbg(omap->dev, "CHRGVBUS Rise\n");
Felipe Balbi72246da2011-08-19 18:10:58 +0300223
Felipe Balbi42077b02011-09-06 12:00:39 +0300224 if (reg & USBOTGSS_IRQ1_DISCHRGVBUS_RISE)
Felipe Balbiccba3bc2011-09-01 14:46:16 +0300225 dev_dbg(omap->dev, "DISCHRGVBUS Rise\n");
Felipe Balbi72246da2011-08-19 18:10:58 +0300226
Felipe Balbi42077b02011-09-06 12:00:39 +0300227 if (reg & USBOTGSS_IRQ1_IDPULLUP_RISE)
Felipe Balbiccba3bc2011-09-01 14:46:16 +0300228 dev_dbg(omap->dev, "IDPULLUP Rise\n");
Felipe Balbi72246da2011-08-19 18:10:58 +0300229
Felipe Balbi42077b02011-09-06 12:00:39 +0300230 if (reg & USBOTGSS_IRQ1_DRVVBUS_FALL)
Felipe Balbiccba3bc2011-09-01 14:46:16 +0300231 dev_dbg(omap->dev, "DRVVBUS Fall\n");
Felipe Balbi72246da2011-08-19 18:10:58 +0300232
Felipe Balbi42077b02011-09-06 12:00:39 +0300233 if (reg & USBOTGSS_IRQ1_CHRGVBUS_FALL)
Felipe Balbiccba3bc2011-09-01 14:46:16 +0300234 dev_dbg(omap->dev, "CHRGVBUS Fall\n");
Felipe Balbi72246da2011-08-19 18:10:58 +0300235
Felipe Balbi42077b02011-09-06 12:00:39 +0300236 if (reg & USBOTGSS_IRQ1_DISCHRGVBUS_FALL)
Felipe Balbiccba3bc2011-09-01 14:46:16 +0300237 dev_dbg(omap->dev, "DISCHRGVBUS Fall\n");
Felipe Balbi72246da2011-08-19 18:10:58 +0300238
Felipe Balbi42077b02011-09-06 12:00:39 +0300239 if (reg & USBOTGSS_IRQ1_IDPULLUP_FALL)
Felipe Balbiccba3bc2011-09-01 14:46:16 +0300240 dev_dbg(omap->dev, "IDPULLUP Fall\n");
Felipe Balbi72246da2011-08-19 18:10:58 +0300241
Ido Shayevitzab5e59d2012-04-24 14:18:38 +0300242 dwc3_omap_writel(omap->base, USBOTGSS_IRQSTATUS_1, reg);
Felipe Balbi42077b02011-09-06 12:00:39 +0300243
Ido Shayevitzab5e59d2012-04-24 14:18:38 +0300244 reg = dwc3_omap_readl(omap->base, USBOTGSS_IRQSTATUS_0);
245 dwc3_omap_writel(omap->base, USBOTGSS_IRQSTATUS_0, reg);
Felipe Balbi72246da2011-08-19 18:10:58 +0300246
247 spin_unlock(&omap->lock);
248
249 return IRQ_HANDLED;
250}
251
Kishon Vijay Abraham I94c6a432013-01-25 08:30:45 +0530252static int dwc3_omap_remove_core(struct device *dev, void *c)
253{
254 struct platform_device *pdev = to_platform_device(dev);
255
256 platform_device_unregister(pdev);
257
258 return 0;
259}
260
Felipe Balbi9a4b5da2013-02-11 11:03:59 +0200261static void dwc3_omap_enable_irqs(struct dwc3_omap *omap)
262{
263 u32 reg;
264
265 /* enable all IRQs */
266 reg = USBOTGSS_IRQO_COREIRQ_ST;
267 dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_0, reg);
268
269 reg = (USBOTGSS_IRQ1_OEVT |
270 USBOTGSS_IRQ1_DRVVBUS_RISE |
271 USBOTGSS_IRQ1_CHRGVBUS_RISE |
272 USBOTGSS_IRQ1_DISCHRGVBUS_RISE |
273 USBOTGSS_IRQ1_IDPULLUP_RISE |
274 USBOTGSS_IRQ1_DRVVBUS_FALL |
275 USBOTGSS_IRQ1_CHRGVBUS_FALL |
276 USBOTGSS_IRQ1_DISCHRGVBUS_FALL |
277 USBOTGSS_IRQ1_IDPULLUP_FALL);
278
279 dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_1, reg);
280}
281
282static void dwc3_omap_disable_irqs(struct dwc3_omap *omap)
283{
284 /* disable all IRQs */
285 dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_1, 0x00);
286 dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_0, 0x00);
287}
288
Kishon Vijay Abraham Iddff14f2013-03-07 18:51:43 +0530289static u64 dwc3_omap_dma_mask = DMA_BIT_MASK(32);
290
Bill Pemberton41ac7b32012-11-19 13:21:48 -0500291static int dwc3_omap_probe(struct platform_device *pdev)
Felipe Balbi72246da2011-08-19 18:10:58 +0300292{
Felipe Balbi45b3cd4a2012-01-25 11:07:03 +0200293 struct device_node *node = pdev->dev.of_node;
294
Felipe Balbi72246da2011-08-19 18:10:58 +0300295 struct dwc3_omap *omap;
296 struct resource *res;
Chanho Park802ca852012-02-15 18:27:55 +0900297 struct device *dev = &pdev->dev;
Felipe Balbi72246da2011-08-19 18:10:58 +0300298
299 int ret = -ENOMEM;
300 int irq;
301
Kishon Vijay Abraham Ie36a0c82013-02-26 20:03:27 +0530302 int utmi_mode = 0;
303
Felipe Balbi72246da2011-08-19 18:10:58 +0300304 u32 reg;
305
306 void __iomem *base;
Felipe Balbi72246da2011-08-19 18:10:58 +0300307
Kishon Vijay Abraham I4495afc2013-02-26 20:03:28 +0530308 if (!node) {
309 dev_err(dev, "device node not found\n");
310 return -EINVAL;
311 }
312
Chanho Park802ca852012-02-15 18:27:55 +0900313 omap = devm_kzalloc(dev, sizeof(*omap), GFP_KERNEL);
Felipe Balbi72246da2011-08-19 18:10:58 +0300314 if (!omap) {
Chanho Park802ca852012-02-15 18:27:55 +0900315 dev_err(dev, "not enough memory\n");
316 return -ENOMEM;
Felipe Balbi72246da2011-08-19 18:10:58 +0300317 }
318
319 platform_set_drvdata(pdev, omap);
320
Kishon Vijay Abraham Ie36a0c82013-02-26 20:03:27 +0530321 irq = platform_get_irq(pdev, 0);
Felipe Balbi72246da2011-08-19 18:10:58 +0300322 if (irq < 0) {
Chanho Park802ca852012-02-15 18:27:55 +0900323 dev_err(dev, "missing IRQ resource\n");
324 return -EINVAL;
Felipe Balbi72246da2011-08-19 18:10:58 +0300325 }
326
Kishon Vijay Abraham Ie36a0c82013-02-26 20:03:27 +0530327 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Felipe Balbi72246da2011-08-19 18:10:58 +0300328 if (!res) {
Chanho Park802ca852012-02-15 18:27:55 +0900329 dev_err(dev, "missing memory base resource\n");
330 return -EINVAL;
Felipe Balbi72246da2011-08-19 18:10:58 +0300331 }
332
Chanho Park802ca852012-02-15 18:27:55 +0900333 base = devm_ioremap_nocache(dev, res->start, resource_size(res));
Felipe Balbi72246da2011-08-19 18:10:58 +0300334 if (!base) {
Chanho Park802ca852012-02-15 18:27:55 +0900335 dev_err(dev, "ioremap failed\n");
336 return -ENOMEM;
Felipe Balbi72246da2011-08-19 18:10:58 +0300337 }
338
Felipe Balbi72246da2011-08-19 18:10:58 +0300339 spin_lock_init(&omap->lock);
Felipe Balbi72246da2011-08-19 18:10:58 +0300340
Chanho Park802ca852012-02-15 18:27:55 +0900341 omap->dev = dev;
Felipe Balbi72246da2011-08-19 18:10:58 +0300342 omap->irq = irq;
343 omap->base = base;
Kishon Vijay Abraham Iddff14f2013-03-07 18:51:43 +0530344 dev->dma_mask = &dwc3_omap_dma_mask;
Felipe Balbi72246da2011-08-19 18:10:58 +0300345
Kishon Vijay Abraham I7e41bba2013-01-25 08:30:49 +0530346 /*
347 * REVISIT if we ever have two instances of the wrapper, we will be
348 * in big trouble
349 */
350 _omap = omap;
351
Kishon Vijay Abraham Iaf310e92013-01-25 08:30:47 +0530352 pm_runtime_enable(dev);
353 ret = pm_runtime_get_sync(dev);
354 if (ret < 0) {
355 dev_err(dev, "get_sync failed with err %d\n", ret);
Kishon Vijay Abraham I594daba2013-06-03 21:43:39 +0530356 goto err0;
Kishon Vijay Abraham Iaf310e92013-01-25 08:30:47 +0530357 }
358
Ido Shayevitzab5e59d2012-04-24 14:18:38 +0300359 reg = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS);
Felipe Balbi99624442011-09-01 22:26:25 +0300360
Kishon Vijay Abraham I4495afc2013-02-26 20:03:28 +0530361 of_property_read_u32(node, "utmi-mode", &utmi_mode);
Kishon Vijay Abraham Ie36a0c82013-02-26 20:03:27 +0530362
363 switch (utmi_mode) {
364 case DWC3_OMAP_UTMI_MODE_SW:
365 reg |= USBOTGSS_UTMI_OTG_STATUS_SW_MODE;
366 break;
367 case DWC3_OMAP_UTMI_MODE_HW:
368 reg &= ~USBOTGSS_UTMI_OTG_STATUS_SW_MODE;
369 break;
370 default:
371 dev_dbg(dev, "UNKNOWN utmi mode %d\n", utmi_mode);
Felipe Balbi99624442011-09-01 22:26:25 +0300372 }
373
Ido Shayevitzab5e59d2012-04-24 14:18:38 +0300374 dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, reg);
Felipe Balbi99624442011-09-01 22:26:25 +0300375
Felipe Balbi72246da2011-08-19 18:10:58 +0300376 /* check the DMA Status */
Ido Shayevitzab5e59d2012-04-24 14:18:38 +0300377 reg = dwc3_omap_readl(omap->base, USBOTGSS_SYSCONFIG);
Felipe Balbi72246da2011-08-19 18:10:58 +0300378 omap->dma_status = !!(reg & USBOTGSS_SYSCONFIG_DMADISABLE);
379
Chanho Park802ca852012-02-15 18:27:55 +0900380 ret = devm_request_irq(dev, omap->irq, dwc3_omap_interrupt, 0,
Felipe Balbidd17a6b2011-09-06 10:57:41 +0300381 "dwc3-omap", omap);
Felipe Balbi72246da2011-08-19 18:10:58 +0300382 if (ret) {
Chanho Park802ca852012-02-15 18:27:55 +0900383 dev_err(dev, "failed to request IRQ #%d --> %d\n",
Felipe Balbi72246da2011-08-19 18:10:58 +0300384 omap->irq, ret);
Kishon Vijay Abraham I594daba2013-06-03 21:43:39 +0530385 goto err1;
Felipe Balbi72246da2011-08-19 18:10:58 +0300386 }
387
Felipe Balbi9a4b5da2013-02-11 11:03:59 +0200388 dwc3_omap_enable_irqs(omap);
Felipe Balbi72246da2011-08-19 18:10:58 +0300389
Kishon Vijay Abraham I4495afc2013-02-26 20:03:28 +0530390 ret = of_platform_populate(node, NULL, NULL, dev);
391 if (ret) {
392 dev_err(&pdev->dev, "failed to create dwc3 core\n");
Kishon Vijay Abraham I594daba2013-06-03 21:43:39 +0530393 goto err2;
Felipe Balbi72246da2011-08-19 18:10:58 +0300394 }
395
396 return 0;
Kishon Vijay Abraham I594daba2013-06-03 21:43:39 +0530397
398err2:
399 dwc3_omap_disable_irqs(omap);
400
401err1:
402 pm_runtime_put_sync(dev);
403
404err0:
405 pm_runtime_disable(dev);
406
407 return ret;
Felipe Balbi72246da2011-08-19 18:10:58 +0300408}
409
Bill Pembertonfb4e98a2012-11-19 13:26:20 -0500410static int dwc3_omap_remove(struct platform_device *pdev)
Felipe Balbi72246da2011-08-19 18:10:58 +0300411{
Felipe Balbi9a4b5da2013-02-11 11:03:59 +0200412 struct dwc3_omap *omap = platform_get_drvdata(pdev);
413
414 dwc3_omap_disable_irqs(omap);
Kishon Vijay Abraham Iaf310e92013-01-25 08:30:47 +0530415 pm_runtime_put_sync(&pdev->dev);
416 pm_runtime_disable(&pdev->dev);
Kishon Vijay Abraham I94c6a432013-01-25 08:30:45 +0530417 device_for_each_child(&pdev->dev, NULL, dwc3_omap_remove_core);
418
Felipe Balbi72246da2011-08-19 18:10:58 +0300419 return 0;
420}
421
Felipe Balbi2c2dc892013-02-11 10:31:15 +0200422static const struct of_device_id of_dwc3_match[] = {
Felipe Balbi72246da2011-08-19 18:10:58 +0300423 {
Kishon Vijay Abraham Ie36a0c82013-02-26 20:03:27 +0530424 .compatible = "ti,dwc3"
Felipe Balbi72246da2011-08-19 18:10:58 +0300425 },
426 { },
427};
Felipe Balbi2c2dc892013-02-11 10:31:15 +0200428MODULE_DEVICE_TABLE(of, of_dwc3_match);
Felipe Balbi72246da2011-08-19 18:10:58 +0300429
Jingoo Han19fda7c2013-03-26 01:52:48 +0000430#ifdef CONFIG_PM_SLEEP
Felipe Balbif3e117f2013-02-11 11:12:02 +0200431static int dwc3_omap_prepare(struct device *dev)
432{
433 struct dwc3_omap *omap = dev_get_drvdata(dev);
434
435 dwc3_omap_disable_irqs(omap);
436
437 return 0;
438}
439
440static void dwc3_omap_complete(struct device *dev)
441{
442 struct dwc3_omap *omap = dev_get_drvdata(dev);
443
444 dwc3_omap_enable_irqs(omap);
445}
446
447static int dwc3_omap_suspend(struct device *dev)
448{
449 struct dwc3_omap *omap = dev_get_drvdata(dev);
450
451 omap->utmi_otg_status = dwc3_omap_readl(omap->base,
452 USBOTGSS_UTMI_OTG_STATUS);
453
454 return 0;
455}
456
457static int dwc3_omap_resume(struct device *dev)
458{
459 struct dwc3_omap *omap = dev_get_drvdata(dev);
460
461 dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS,
462 omap->utmi_otg_status);
463
464 pm_runtime_disable(dev);
465 pm_runtime_set_active(dev);
466 pm_runtime_enable(dev);
467
468 return 0;
469}
470
471static const struct dev_pm_ops dwc3_omap_dev_pm_ops = {
472 .prepare = dwc3_omap_prepare,
473 .complete = dwc3_omap_complete,
474
475 SET_SYSTEM_SLEEP_PM_OPS(dwc3_omap_suspend, dwc3_omap_resume)
476};
477
478#define DEV_PM_OPS (&dwc3_omap_dev_pm_ops)
479#else
480#define DEV_PM_OPS NULL
Jingoo Han19fda7c2013-03-26 01:52:48 +0000481#endif /* CONFIG_PM_SLEEP */
Felipe Balbif3e117f2013-02-11 11:12:02 +0200482
Felipe Balbi72246da2011-08-19 18:10:58 +0300483static struct platform_driver dwc3_omap_driver = {
484 .probe = dwc3_omap_probe,
Bill Pemberton76904172012-11-19 13:21:08 -0500485 .remove = dwc3_omap_remove,
Felipe Balbi72246da2011-08-19 18:10:58 +0300486 .driver = {
487 .name = "omap-dwc3",
Felipe Balbi2c2dc892013-02-11 10:31:15 +0200488 .of_match_table = of_dwc3_match,
Felipe Balbif3e117f2013-02-11 11:12:02 +0200489 .pm = DEV_PM_OPS,
Felipe Balbi72246da2011-08-19 18:10:58 +0300490 },
491};
492
Axel Lincc27c962011-11-27 20:16:27 +0800493module_platform_driver(dwc3_omap_driver);
494
Sebastian Andrzej Siewior7ae4fc42011-10-19 19:39:50 +0200495MODULE_ALIAS("platform:omap-dwc3");
Felipe Balbi72246da2011-08-19 18:10:58 +0300496MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
497MODULE_LICENSE("Dual BSD/GPL");
498MODULE_DESCRIPTION("DesignWare USB3 OMAP Glue Layer");