blob: 22f337f572190234c4f75fd06a78b14ce4a2faf9 [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>
55#include <linux/usb/nop-usb-xceiv.h>
56
Felipe Balbi5ddcee22011-10-18 13:58:30 +030057#include "core.h"
Felipe Balbi72246da2011-08-19 18:10:58 +030058
59/*
60 * All these registers belong to OMAP's Wrapper around the
61 * DesignWare USB3 Core.
62 */
63
64#define USBOTGSS_REVISION 0x0000
65#define USBOTGSS_SYSCONFIG 0x0010
66#define USBOTGSS_IRQ_EOI 0x0020
67#define USBOTGSS_IRQSTATUS_RAW_0 0x0024
68#define USBOTGSS_IRQSTATUS_0 0x0028
69#define USBOTGSS_IRQENABLE_SET_0 0x002c
70#define USBOTGSS_IRQENABLE_CLR_0 0x0030
71#define USBOTGSS_IRQSTATUS_RAW_1 0x0034
72#define USBOTGSS_IRQSTATUS_1 0x0038
73#define USBOTGSS_IRQENABLE_SET_1 0x003c
74#define USBOTGSS_IRQENABLE_CLR_1 0x0040
75#define USBOTGSS_UTMI_OTG_CTRL 0x0080
76#define USBOTGSS_UTMI_OTG_STATUS 0x0084
77#define USBOTGSS_MMRAM_OFFSET 0x0100
78#define USBOTGSS_FLADJ 0x0104
79#define USBOTGSS_DEBUG_CFG 0x0108
80#define USBOTGSS_DEBUG_DATA 0x010c
81
82/* SYSCONFIG REGISTER */
83#define USBOTGSS_SYSCONFIG_DMADISABLE (1 << 16)
Felipe Balbi4b5faa7a2011-09-06 10:56:51 +030084
Felipe Balbi72246da2011-08-19 18:10:58 +030085/* IRQ_EOI REGISTER */
86#define USBOTGSS_IRQ_EOI_LINE_NUMBER (1 << 0)
87
88/* IRQS0 BITS */
89#define USBOTGSS_IRQO_COREIRQ_ST (1 << 0)
90
91/* IRQ1 BITS */
92#define USBOTGSS_IRQ1_DMADISABLECLR (1 << 17)
93#define USBOTGSS_IRQ1_OEVT (1 << 16)
94#define USBOTGSS_IRQ1_DRVVBUS_RISE (1 << 13)
95#define USBOTGSS_IRQ1_CHRGVBUS_RISE (1 << 12)
96#define USBOTGSS_IRQ1_DISCHRGVBUS_RISE (1 << 11)
97#define USBOTGSS_IRQ1_IDPULLUP_RISE (1 << 8)
98#define USBOTGSS_IRQ1_DRVVBUS_FALL (1 << 5)
99#define USBOTGSS_IRQ1_CHRGVBUS_FALL (1 << 4)
100#define USBOTGSS_IRQ1_DISCHRGVBUS_FALL (1 << 3)
101#define USBOTGSS_IRQ1_IDPULLUP_FALL (1 << 0)
102
103/* UTMI_OTG_CTRL REGISTER */
104#define USBOTGSS_UTMI_OTG_CTRL_DRVVBUS (1 << 5)
105#define USBOTGSS_UTMI_OTG_CTRL_CHRGVBUS (1 << 4)
106#define USBOTGSS_UTMI_OTG_CTRL_DISCHRGVBUS (1 << 3)
107#define USBOTGSS_UTMI_OTG_CTRL_IDPULLUP (1 << 0)
108
109/* UTMI_OTG_STATUS REGISTER */
110#define USBOTGSS_UTMI_OTG_STATUS_SW_MODE (1 << 31)
111#define USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT (1 << 9)
112#define USBOTGSS_UTMI_OTG_STATUS_TXBITSTUFFENABLE (1 << 8)
113#define USBOTGSS_UTMI_OTG_STATUS_IDDIG (1 << 4)
114#define USBOTGSS_UTMI_OTG_STATUS_SESSEND (1 << 3)
115#define USBOTGSS_UTMI_OTG_STATUS_SESSVALID (1 << 2)
116#define USBOTGSS_UTMI_OTG_STATUS_VBUSVALID (1 << 1)
117
118struct dwc3_omap {
119 /* device lock */
120 spinlock_t lock;
121
Felipe Balbia418cc42012-07-19 13:56:07 +0300122 struct platform_device *usb2_phy;
123 struct platform_device *usb3_phy;
Felipe Balbi72246da2011-08-19 18:10:58 +0300124 struct device *dev;
125
126 int irq;
127 void __iomem *base;
128
129 void *context;
130 u32 resource_size;
131
132 u32 dma_status:1;
133};
134
Kishon Vijay Abraham I7e41bba2013-01-25 08:30:49 +0530135struct dwc3_omap *_omap;
136
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 I7e41bba2013-01-25 08:30:49 +0530147void dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status)
148{
149 u32 val;
150 struct dwc3_omap *omap = _omap;
151
152 switch (status) {
153 case OMAP_DWC3_ID_GROUND:
154 dev_dbg(omap->dev, "ID GND\n");
155
156 val = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS);
157 val &= ~(USBOTGSS_UTMI_OTG_STATUS_IDDIG
158 | USBOTGSS_UTMI_OTG_STATUS_VBUSVALID
159 | USBOTGSS_UTMI_OTG_STATUS_SESSEND);
160 val |= USBOTGSS_UTMI_OTG_STATUS_SESSVALID
161 | USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT;
162 dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, val);
163 break;
164
165 case OMAP_DWC3_VBUS_VALID:
166 dev_dbg(omap->dev, "VBUS Connect\n");
167
168 val = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS);
169 val &= ~USBOTGSS_UTMI_OTG_STATUS_SESSEND;
170 val |= USBOTGSS_UTMI_OTG_STATUS_IDDIG
171 | USBOTGSS_UTMI_OTG_STATUS_VBUSVALID
172 | USBOTGSS_UTMI_OTG_STATUS_SESSVALID
173 | USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT;
174 dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, val);
175 break;
176
177 case OMAP_DWC3_ID_FLOAT:
178 case OMAP_DWC3_VBUS_OFF:
179 dev_dbg(omap->dev, "VBUS Disconnect\n");
180
181 val = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS);
182 val &= ~(USBOTGSS_UTMI_OTG_STATUS_SESSVALID
183 | USBOTGSS_UTMI_OTG_STATUS_VBUSVALID
184 | USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT);
185 val |= USBOTGSS_UTMI_OTG_STATUS_SESSEND
186 | USBOTGSS_UTMI_OTG_STATUS_IDDIG;
187 dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, val);
188 break;
189
190 default:
191 dev_dbg(omap->dev, "ID float\n");
192 }
193
194 return;
195}
196EXPORT_SYMBOL_GPL(dwc3_omap_mailbox);
197
Bill Pemberton41ac7b32012-11-19 13:21:48 -0500198static int dwc3_omap_register_phys(struct dwc3_omap *omap)
Felipe Balbia418cc42012-07-19 13:56:07 +0300199{
200 struct nop_usb_xceiv_platform_data pdata;
201 struct platform_device *pdev;
202 int ret;
203
204 memset(&pdata, 0x00, sizeof(pdata));
205
Vivek Gautamb0e45dd2013-01-25 16:52:01 +0530206 pdev = platform_device_alloc("nop_usb_xceiv", PLATFORM_DEVID_AUTO);
Felipe Balbia418cc42012-07-19 13:56:07 +0300207 if (!pdev)
208 return -ENOMEM;
209
210 omap->usb2_phy = pdev;
211 pdata.type = USB_PHY_TYPE_USB2;
212
213 ret = platform_device_add_data(omap->usb2_phy, &pdata, sizeof(pdata));
214 if (ret)
215 goto err1;
216
Vivek Gautamb0e45dd2013-01-25 16:52:01 +0530217 pdev = platform_device_alloc("nop_usb_xceiv", PLATFORM_DEVID_AUTO);
Felipe Balbia418cc42012-07-19 13:56:07 +0300218 if (!pdev) {
219 ret = -ENOMEM;
220 goto err1;
221 }
222
223 omap->usb3_phy = pdev;
224 pdata.type = USB_PHY_TYPE_USB3;
225
226 ret = platform_device_add_data(omap->usb3_phy, &pdata, sizeof(pdata));
227 if (ret)
228 goto err2;
229
230 ret = platform_device_add(omap->usb2_phy);
231 if (ret)
232 goto err2;
233
234 ret = platform_device_add(omap->usb3_phy);
235 if (ret)
236 goto err3;
237
238 return 0;
239
240err3:
241 platform_device_del(omap->usb2_phy);
242
243err2:
244 platform_device_put(omap->usb3_phy);
245
246err1:
247 platform_device_put(omap->usb2_phy);
248
249 return ret;
250}
Ido Shayevitzab5e59d2012-04-24 14:18:38 +0300251
Felipe Balbi72246da2011-08-19 18:10:58 +0300252static irqreturn_t dwc3_omap_interrupt(int irq, void *_omap)
253{
254 struct dwc3_omap *omap = _omap;
255 u32 reg;
Felipe Balbi72246da2011-08-19 18:10:58 +0300256
257 spin_lock(&omap->lock);
258
Ido Shayevitzab5e59d2012-04-24 14:18:38 +0300259 reg = dwc3_omap_readl(omap->base, USBOTGSS_IRQSTATUS_1);
Felipe Balbi72246da2011-08-19 18:10:58 +0300260
261 if (reg & USBOTGSS_IRQ1_DMADISABLECLR) {
Felipe Balbiccba3bc2011-09-01 14:46:16 +0300262 dev_dbg(omap->dev, "DMA Disable was Cleared\n");
Felipe Balbi72246da2011-08-19 18:10:58 +0300263 omap->dma_status = false;
264 }
265
266 if (reg & USBOTGSS_IRQ1_OEVT)
Felipe Balbiccba3bc2011-09-01 14:46:16 +0300267 dev_dbg(omap->dev, "OTG Event\n");
Felipe Balbi72246da2011-08-19 18:10:58 +0300268
Felipe Balbi42077b02011-09-06 12:00:39 +0300269 if (reg & USBOTGSS_IRQ1_DRVVBUS_RISE)
Felipe Balbiccba3bc2011-09-01 14:46:16 +0300270 dev_dbg(omap->dev, "DRVVBUS Rise\n");
Felipe Balbi72246da2011-08-19 18:10:58 +0300271
Felipe Balbi42077b02011-09-06 12:00:39 +0300272 if (reg & USBOTGSS_IRQ1_CHRGVBUS_RISE)
Felipe Balbiccba3bc2011-09-01 14:46:16 +0300273 dev_dbg(omap->dev, "CHRGVBUS Rise\n");
Felipe Balbi72246da2011-08-19 18:10:58 +0300274
Felipe Balbi42077b02011-09-06 12:00:39 +0300275 if (reg & USBOTGSS_IRQ1_DISCHRGVBUS_RISE)
Felipe Balbiccba3bc2011-09-01 14:46:16 +0300276 dev_dbg(omap->dev, "DISCHRGVBUS Rise\n");
Felipe Balbi72246da2011-08-19 18:10:58 +0300277
Felipe Balbi42077b02011-09-06 12:00:39 +0300278 if (reg & USBOTGSS_IRQ1_IDPULLUP_RISE)
Felipe Balbiccba3bc2011-09-01 14:46:16 +0300279 dev_dbg(omap->dev, "IDPULLUP Rise\n");
Felipe Balbi72246da2011-08-19 18:10:58 +0300280
Felipe Balbi42077b02011-09-06 12:00:39 +0300281 if (reg & USBOTGSS_IRQ1_DRVVBUS_FALL)
Felipe Balbiccba3bc2011-09-01 14:46:16 +0300282 dev_dbg(omap->dev, "DRVVBUS Fall\n");
Felipe Balbi72246da2011-08-19 18:10:58 +0300283
Felipe Balbi42077b02011-09-06 12:00:39 +0300284 if (reg & USBOTGSS_IRQ1_CHRGVBUS_FALL)
Felipe Balbiccba3bc2011-09-01 14:46:16 +0300285 dev_dbg(omap->dev, "CHRGVBUS Fall\n");
Felipe Balbi72246da2011-08-19 18:10:58 +0300286
Felipe Balbi42077b02011-09-06 12:00:39 +0300287 if (reg & USBOTGSS_IRQ1_DISCHRGVBUS_FALL)
Felipe Balbiccba3bc2011-09-01 14:46:16 +0300288 dev_dbg(omap->dev, "DISCHRGVBUS Fall\n");
Felipe Balbi72246da2011-08-19 18:10:58 +0300289
Felipe Balbi42077b02011-09-06 12:00:39 +0300290 if (reg & USBOTGSS_IRQ1_IDPULLUP_FALL)
Felipe Balbiccba3bc2011-09-01 14:46:16 +0300291 dev_dbg(omap->dev, "IDPULLUP Fall\n");
Felipe Balbi72246da2011-08-19 18:10:58 +0300292
Ido Shayevitzab5e59d2012-04-24 14:18:38 +0300293 dwc3_omap_writel(omap->base, USBOTGSS_IRQSTATUS_1, reg);
Felipe Balbi42077b02011-09-06 12:00:39 +0300294
Ido Shayevitzab5e59d2012-04-24 14:18:38 +0300295 reg = dwc3_omap_readl(omap->base, USBOTGSS_IRQSTATUS_0);
296 dwc3_omap_writel(omap->base, USBOTGSS_IRQSTATUS_0, reg);
Felipe Balbi72246da2011-08-19 18:10:58 +0300297
298 spin_unlock(&omap->lock);
299
300 return IRQ_HANDLED;
301}
302
Kishon Vijay Abraham I94c6a432013-01-25 08:30:45 +0530303static int dwc3_omap_remove_core(struct device *dev, void *c)
304{
305 struct platform_device *pdev = to_platform_device(dev);
306
307 platform_device_unregister(pdev);
308
309 return 0;
310}
311
Bill Pemberton41ac7b32012-11-19 13:21:48 -0500312static int dwc3_omap_probe(struct platform_device *pdev)
Felipe Balbi72246da2011-08-19 18:10:58 +0300313{
Felipe Balbi99624442011-09-01 22:26:25 +0300314 struct dwc3_omap_data *pdata = pdev->dev.platform_data;
Felipe Balbi45b3cd4a2012-01-25 11:07:03 +0200315 struct device_node *node = pdev->dev.of_node;
316
Felipe Balbi72246da2011-08-19 18:10:58 +0300317 struct dwc3_omap *omap;
318 struct resource *res;
Chanho Park802ca852012-02-15 18:27:55 +0900319 struct device *dev = &pdev->dev;
Felipe Balbi72246da2011-08-19 18:10:58 +0300320
Felipe Balbi45b3cd4a2012-01-25 11:07:03 +0200321 int size;
Felipe Balbi72246da2011-08-19 18:10:58 +0300322 int ret = -ENOMEM;
323 int irq;
324
Felipe Balbi45b3cd4a2012-01-25 11:07:03 +0200325 const u32 *utmi_mode;
Felipe Balbi72246da2011-08-19 18:10:58 +0300326 u32 reg;
327
328 void __iomem *base;
329 void *context;
330
Chanho Park802ca852012-02-15 18:27:55 +0900331 omap = devm_kzalloc(dev, sizeof(*omap), GFP_KERNEL);
Felipe Balbi72246da2011-08-19 18:10:58 +0300332 if (!omap) {
Chanho Park802ca852012-02-15 18:27:55 +0900333 dev_err(dev, "not enough memory\n");
334 return -ENOMEM;
Felipe Balbi72246da2011-08-19 18:10:58 +0300335 }
336
337 platform_set_drvdata(pdev, omap);
338
339 irq = platform_get_irq(pdev, 1);
340 if (irq < 0) {
Chanho Park802ca852012-02-15 18:27:55 +0900341 dev_err(dev, "missing IRQ resource\n");
342 return -EINVAL;
Felipe Balbi72246da2011-08-19 18:10:58 +0300343 }
344
345 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
346 if (!res) {
Chanho Park802ca852012-02-15 18:27:55 +0900347 dev_err(dev, "missing memory base resource\n");
348 return -EINVAL;
Felipe Balbi72246da2011-08-19 18:10:58 +0300349 }
350
Chanho Park802ca852012-02-15 18:27:55 +0900351 base = devm_ioremap_nocache(dev, res->start, resource_size(res));
Felipe Balbi72246da2011-08-19 18:10:58 +0300352 if (!base) {
Chanho Park802ca852012-02-15 18:27:55 +0900353 dev_err(dev, "ioremap failed\n");
354 return -ENOMEM;
Felipe Balbi72246da2011-08-19 18:10:58 +0300355 }
356
Felipe Balbia418cc42012-07-19 13:56:07 +0300357 ret = dwc3_omap_register_phys(omap);
358 if (ret) {
359 dev_err(dev, "couldn't register PHYs\n");
360 return ret;
361 }
362
Chanho Park802ca852012-02-15 18:27:55 +0900363 context = devm_kzalloc(dev, resource_size(res), GFP_KERNEL);
Felipe Balbi72246da2011-08-19 18:10:58 +0300364 if (!context) {
Chanho Park802ca852012-02-15 18:27:55 +0900365 dev_err(dev, "couldn't allocate dwc3 context memory\n");
Kishon Vijay Abraham Ib4bfe6a2013-01-25 08:30:46 +0530366 return -ENOMEM;
Felipe Balbi72246da2011-08-19 18:10:58 +0300367 }
368
369 spin_lock_init(&omap->lock);
Felipe Balbi72246da2011-08-19 18:10:58 +0300370
Felipe Balbi72246da2011-08-19 18:10:58 +0300371 omap->resource_size = resource_size(res);
372 omap->context = context;
Chanho Park802ca852012-02-15 18:27:55 +0900373 omap->dev = dev;
Felipe Balbi72246da2011-08-19 18:10:58 +0300374 omap->irq = irq;
375 omap->base = base;
Felipe Balbi72246da2011-08-19 18:10:58 +0300376
Kishon Vijay Abraham I7e41bba2013-01-25 08:30:49 +0530377 /*
378 * REVISIT if we ever have two instances of the wrapper, we will be
379 * in big trouble
380 */
381 _omap = omap;
382
Kishon Vijay Abraham Iaf310e92013-01-25 08:30:47 +0530383 pm_runtime_enable(dev);
384 ret = pm_runtime_get_sync(dev);
385 if (ret < 0) {
386 dev_err(dev, "get_sync failed with err %d\n", ret);
387 return ret;
388 }
389
Ido Shayevitzab5e59d2012-04-24 14:18:38 +0300390 reg = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS);
Felipe Balbi99624442011-09-01 22:26:25 +0300391
Felipe Balbi45b3cd4a2012-01-25 11:07:03 +0200392 utmi_mode = of_get_property(node, "utmi-mode", &size);
393 if (utmi_mode && size == sizeof(*utmi_mode)) {
394 reg |= *utmi_mode;
Felipe Balbi99624442011-09-01 22:26:25 +0300395 } else {
Felipe Balbi45b3cd4a2012-01-25 11:07:03 +0200396 if (!pdata) {
Chanho Park802ca852012-02-15 18:27:55 +0900397 dev_dbg(dev, "missing platform data\n");
Felipe Balbi45b3cd4a2012-01-25 11:07:03 +0200398 } else {
399 switch (pdata->utmi_mode) {
400 case DWC3_OMAP_UTMI_MODE_SW:
401 reg |= USBOTGSS_UTMI_OTG_STATUS_SW_MODE;
402 break;
403 case DWC3_OMAP_UTMI_MODE_HW:
404 reg &= ~USBOTGSS_UTMI_OTG_STATUS_SW_MODE;
405 break;
406 default:
Chanho Park802ca852012-02-15 18:27:55 +0900407 dev_dbg(dev, "UNKNOWN utmi mode %d\n",
Felipe Balbi45b3cd4a2012-01-25 11:07:03 +0200408 pdata->utmi_mode);
409 }
Felipe Balbi99624442011-09-01 22:26:25 +0300410 }
411 }
412
Ido Shayevitzab5e59d2012-04-24 14:18:38 +0300413 dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, reg);
Felipe Balbi99624442011-09-01 22:26:25 +0300414
Felipe Balbi72246da2011-08-19 18:10:58 +0300415 /* check the DMA Status */
Ido Shayevitzab5e59d2012-04-24 14:18:38 +0300416 reg = dwc3_omap_readl(omap->base, USBOTGSS_SYSCONFIG);
Felipe Balbi72246da2011-08-19 18:10:58 +0300417 omap->dma_status = !!(reg & USBOTGSS_SYSCONFIG_DMADISABLE);
418
Chanho Park802ca852012-02-15 18:27:55 +0900419 ret = devm_request_irq(dev, omap->irq, dwc3_omap_interrupt, 0,
Felipe Balbidd17a6b2011-09-06 10:57:41 +0300420 "dwc3-omap", omap);
Felipe Balbi72246da2011-08-19 18:10:58 +0300421 if (ret) {
Chanho Park802ca852012-02-15 18:27:55 +0900422 dev_err(dev, "failed to request IRQ #%d --> %d\n",
Felipe Balbi72246da2011-08-19 18:10:58 +0300423 omap->irq, ret);
Kishon Vijay Abraham Ib4bfe6a2013-01-25 08:30:46 +0530424 return ret;
Felipe Balbi72246da2011-08-19 18:10:58 +0300425 }
426
427 /* enable all IRQs */
Felipe Balbidf01c612011-09-01 18:22:01 +0300428 reg = USBOTGSS_IRQO_COREIRQ_ST;
Ido Shayevitzab5e59d2012-04-24 14:18:38 +0300429 dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_0, reg);
Felipe Balbi72246da2011-08-19 18:10:58 +0300430
Felipe Balbi324e5482011-09-01 14:52:52 +0300431 reg = (USBOTGSS_IRQ1_OEVT |
Felipe Balbi72246da2011-08-19 18:10:58 +0300432 USBOTGSS_IRQ1_DRVVBUS_RISE |
433 USBOTGSS_IRQ1_CHRGVBUS_RISE |
434 USBOTGSS_IRQ1_DISCHRGVBUS_RISE |
435 USBOTGSS_IRQ1_IDPULLUP_RISE |
436 USBOTGSS_IRQ1_DRVVBUS_FALL |
437 USBOTGSS_IRQ1_CHRGVBUS_FALL |
438 USBOTGSS_IRQ1_DISCHRGVBUS_FALL |
439 USBOTGSS_IRQ1_IDPULLUP_FALL);
440
Ido Shayevitzab5e59d2012-04-24 14:18:38 +0300441 dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_1, reg);
Felipe Balbi72246da2011-08-19 18:10:58 +0300442
Kishon Vijay Abraham Ib4bfe6a2013-01-25 08:30:46 +0530443 if (node) {
444 ret = of_platform_populate(node, NULL, NULL, dev);
445 if (ret) {
446 dev_err(&pdev->dev,
447 "failed to add create dwc3 core\n");
448 return ret;
449 }
Felipe Balbi72246da2011-08-19 18:10:58 +0300450 }
451
452 return 0;
Felipe Balbi72246da2011-08-19 18:10:58 +0300453}
454
Bill Pembertonfb4e98a2012-11-19 13:26:20 -0500455static int dwc3_omap_remove(struct platform_device *pdev)
Felipe Balbi72246da2011-08-19 18:10:58 +0300456{
457 struct dwc3_omap *omap = platform_get_drvdata(pdev);
458
Felipe Balbia418cc42012-07-19 13:56:07 +0300459 platform_device_unregister(omap->usb2_phy);
460 platform_device_unregister(omap->usb3_phy);
Kishon Vijay Abraham Iaf310e92013-01-25 08:30:47 +0530461 pm_runtime_put_sync(&pdev->dev);
462 pm_runtime_disable(&pdev->dev);
Kishon Vijay Abraham I94c6a432013-01-25 08:30:45 +0530463 device_for_each_child(&pdev->dev, NULL, dwc3_omap_remove_core);
464
Felipe Balbi72246da2011-08-19 18:10:58 +0300465 return 0;
466}
467
468static const struct of_device_id of_dwc3_matach[] = {
469 {
470 "ti,dwc3",
471 },
472 { },
473};
474MODULE_DEVICE_TABLE(of, of_dwc3_matach);
475
476static struct platform_driver dwc3_omap_driver = {
477 .probe = dwc3_omap_probe,
Bill Pemberton76904172012-11-19 13:21:08 -0500478 .remove = dwc3_omap_remove,
Felipe Balbi72246da2011-08-19 18:10:58 +0300479 .driver = {
480 .name = "omap-dwc3",
Felipe Balbi72246da2011-08-19 18:10:58 +0300481 .of_match_table = of_dwc3_matach,
482 },
483};
484
Axel Lincc27c962011-11-27 20:16:27 +0800485module_platform_driver(dwc3_omap_driver);
486
Sebastian Andrzej Siewior7ae4fc42011-10-19 19:39:50 +0200487MODULE_ALIAS("platform:omap-dwc3");
Felipe Balbi72246da2011-08-19 18:10:58 +0300488MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
489MODULE_LICENSE("Dual BSD/GPL");
490MODULE_DESCRIPTION("DesignWare USB3 OMAP Glue Layer");