blob: afa05e3c9cf40b9b731e6d16f8543c07a6cb62c8 [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 Balbi72246da2011-08-19 18:10:58 +030057/*
58 * All these registers belong to OMAP's Wrapper around the
59 * DesignWare USB3 Core.
60 */
61
62#define USBOTGSS_REVISION 0x0000
63#define USBOTGSS_SYSCONFIG 0x0010
64#define USBOTGSS_IRQ_EOI 0x0020
65#define USBOTGSS_IRQSTATUS_RAW_0 0x0024
66#define USBOTGSS_IRQSTATUS_0 0x0028
67#define USBOTGSS_IRQENABLE_SET_0 0x002c
68#define USBOTGSS_IRQENABLE_CLR_0 0x0030
69#define USBOTGSS_IRQSTATUS_RAW_1 0x0034
70#define USBOTGSS_IRQSTATUS_1 0x0038
71#define USBOTGSS_IRQENABLE_SET_1 0x003c
72#define USBOTGSS_IRQENABLE_CLR_1 0x0040
73#define USBOTGSS_UTMI_OTG_CTRL 0x0080
74#define USBOTGSS_UTMI_OTG_STATUS 0x0084
75#define USBOTGSS_MMRAM_OFFSET 0x0100
76#define USBOTGSS_FLADJ 0x0104
77#define USBOTGSS_DEBUG_CFG 0x0108
78#define USBOTGSS_DEBUG_DATA 0x010c
79
80/* SYSCONFIG REGISTER */
81#define USBOTGSS_SYSCONFIG_DMADISABLE (1 << 16)
Felipe Balbi4b5faa7a2011-09-06 10:56:51 +030082
Felipe Balbi72246da2011-08-19 18:10:58 +030083/* IRQ_EOI REGISTER */
84#define USBOTGSS_IRQ_EOI_LINE_NUMBER (1 << 0)
85
86/* IRQS0 BITS */
87#define USBOTGSS_IRQO_COREIRQ_ST (1 << 0)
88
89/* IRQ1 BITS */
90#define USBOTGSS_IRQ1_DMADISABLECLR (1 << 17)
91#define USBOTGSS_IRQ1_OEVT (1 << 16)
92#define USBOTGSS_IRQ1_DRVVBUS_RISE (1 << 13)
93#define USBOTGSS_IRQ1_CHRGVBUS_RISE (1 << 12)
94#define USBOTGSS_IRQ1_DISCHRGVBUS_RISE (1 << 11)
95#define USBOTGSS_IRQ1_IDPULLUP_RISE (1 << 8)
96#define USBOTGSS_IRQ1_DRVVBUS_FALL (1 << 5)
97#define USBOTGSS_IRQ1_CHRGVBUS_FALL (1 << 4)
98#define USBOTGSS_IRQ1_DISCHRGVBUS_FALL (1 << 3)
99#define USBOTGSS_IRQ1_IDPULLUP_FALL (1 << 0)
100
101/* UTMI_OTG_CTRL REGISTER */
102#define USBOTGSS_UTMI_OTG_CTRL_DRVVBUS (1 << 5)
103#define USBOTGSS_UTMI_OTG_CTRL_CHRGVBUS (1 << 4)
104#define USBOTGSS_UTMI_OTG_CTRL_DISCHRGVBUS (1 << 3)
105#define USBOTGSS_UTMI_OTG_CTRL_IDPULLUP (1 << 0)
106
107/* UTMI_OTG_STATUS REGISTER */
108#define USBOTGSS_UTMI_OTG_STATUS_SW_MODE (1 << 31)
109#define USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT (1 << 9)
110#define USBOTGSS_UTMI_OTG_STATUS_TXBITSTUFFENABLE (1 << 8)
111#define USBOTGSS_UTMI_OTG_STATUS_IDDIG (1 << 4)
112#define USBOTGSS_UTMI_OTG_STATUS_SESSEND (1 << 3)
113#define USBOTGSS_UTMI_OTG_STATUS_SESSVALID (1 << 2)
114#define USBOTGSS_UTMI_OTG_STATUS_VBUSVALID (1 << 1)
115
116struct dwc3_omap {
117 /* device lock */
118 spinlock_t lock;
119
Felipe Balbia418cc42012-07-19 13:56:07 +0300120 struct platform_device *usb2_phy;
121 struct platform_device *usb3_phy;
Felipe Balbi72246da2011-08-19 18:10:58 +0300122 struct device *dev;
123
124 int irq;
125 void __iomem *base;
126
127 void *context;
128 u32 resource_size;
129
130 u32 dma_status:1;
131};
132
Kishon Vijay Abraham I7e41bba2013-01-25 08:30:49 +0530133struct dwc3_omap *_omap;
134
Ido Shayevitzab5e59d2012-04-24 14:18:38 +0300135static inline u32 dwc3_omap_readl(void __iomem *base, u32 offset)
136{
137 return readl(base + offset);
138}
139
140static inline void dwc3_omap_writel(void __iomem *base, u32 offset, u32 value)
141{
142 writel(value, base + offset);
143}
144
Kishon Vijay Abraham I7e41bba2013-01-25 08:30:49 +0530145void dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status)
146{
147 u32 val;
148 struct dwc3_omap *omap = _omap;
149
150 switch (status) {
151 case OMAP_DWC3_ID_GROUND:
152 dev_dbg(omap->dev, "ID GND\n");
153
154 val = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS);
155 val &= ~(USBOTGSS_UTMI_OTG_STATUS_IDDIG
156 | USBOTGSS_UTMI_OTG_STATUS_VBUSVALID
157 | USBOTGSS_UTMI_OTG_STATUS_SESSEND);
158 val |= USBOTGSS_UTMI_OTG_STATUS_SESSVALID
159 | USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT;
160 dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, val);
161 break;
162
163 case OMAP_DWC3_VBUS_VALID:
164 dev_dbg(omap->dev, "VBUS Connect\n");
165
166 val = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS);
167 val &= ~USBOTGSS_UTMI_OTG_STATUS_SESSEND;
168 val |= USBOTGSS_UTMI_OTG_STATUS_IDDIG
169 | USBOTGSS_UTMI_OTG_STATUS_VBUSVALID
170 | USBOTGSS_UTMI_OTG_STATUS_SESSVALID
171 | USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT;
172 dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, val);
173 break;
174
175 case OMAP_DWC3_ID_FLOAT:
176 case OMAP_DWC3_VBUS_OFF:
177 dev_dbg(omap->dev, "VBUS Disconnect\n");
178
179 val = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS);
180 val &= ~(USBOTGSS_UTMI_OTG_STATUS_SESSVALID
181 | USBOTGSS_UTMI_OTG_STATUS_VBUSVALID
182 | USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT);
183 val |= USBOTGSS_UTMI_OTG_STATUS_SESSEND
184 | USBOTGSS_UTMI_OTG_STATUS_IDDIG;
185 dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, val);
186 break;
187
188 default:
189 dev_dbg(omap->dev, "ID float\n");
190 }
191
192 return;
193}
194EXPORT_SYMBOL_GPL(dwc3_omap_mailbox);
195
Bill Pemberton41ac7b32012-11-19 13:21:48 -0500196static int dwc3_omap_register_phys(struct dwc3_omap *omap)
Felipe Balbia418cc42012-07-19 13:56:07 +0300197{
198 struct nop_usb_xceiv_platform_data pdata;
199 struct platform_device *pdev;
200 int ret;
201
202 memset(&pdata, 0x00, sizeof(pdata));
203
Vivek Gautamb0e45dd2013-01-25 16:52:01 +0530204 pdev = platform_device_alloc("nop_usb_xceiv", PLATFORM_DEVID_AUTO);
Felipe Balbia418cc42012-07-19 13:56:07 +0300205 if (!pdev)
206 return -ENOMEM;
207
208 omap->usb2_phy = pdev;
209 pdata.type = USB_PHY_TYPE_USB2;
210
211 ret = platform_device_add_data(omap->usb2_phy, &pdata, sizeof(pdata));
212 if (ret)
213 goto err1;
214
Vivek Gautamb0e45dd2013-01-25 16:52:01 +0530215 pdev = platform_device_alloc("nop_usb_xceiv", PLATFORM_DEVID_AUTO);
Felipe Balbia418cc42012-07-19 13:56:07 +0300216 if (!pdev) {
217 ret = -ENOMEM;
218 goto err1;
219 }
220
221 omap->usb3_phy = pdev;
222 pdata.type = USB_PHY_TYPE_USB3;
223
224 ret = platform_device_add_data(omap->usb3_phy, &pdata, sizeof(pdata));
225 if (ret)
226 goto err2;
227
228 ret = platform_device_add(omap->usb2_phy);
229 if (ret)
230 goto err2;
231
232 ret = platform_device_add(omap->usb3_phy);
233 if (ret)
234 goto err3;
235
236 return 0;
237
238err3:
239 platform_device_del(omap->usb2_phy);
240
241err2:
242 platform_device_put(omap->usb3_phy);
243
244err1:
245 platform_device_put(omap->usb2_phy);
246
247 return ret;
248}
Ido Shayevitzab5e59d2012-04-24 14:18:38 +0300249
Felipe Balbi72246da2011-08-19 18:10:58 +0300250static irqreturn_t dwc3_omap_interrupt(int irq, void *_omap)
251{
252 struct dwc3_omap *omap = _omap;
253 u32 reg;
Felipe Balbi72246da2011-08-19 18:10:58 +0300254
255 spin_lock(&omap->lock);
256
Ido Shayevitzab5e59d2012-04-24 14:18:38 +0300257 reg = dwc3_omap_readl(omap->base, USBOTGSS_IRQSTATUS_1);
Felipe Balbi72246da2011-08-19 18:10:58 +0300258
259 if (reg & USBOTGSS_IRQ1_DMADISABLECLR) {
Felipe Balbiccba3bc2011-09-01 14:46:16 +0300260 dev_dbg(omap->dev, "DMA Disable was Cleared\n");
Felipe Balbi72246da2011-08-19 18:10:58 +0300261 omap->dma_status = false;
262 }
263
264 if (reg & USBOTGSS_IRQ1_OEVT)
Felipe Balbiccba3bc2011-09-01 14:46:16 +0300265 dev_dbg(omap->dev, "OTG Event\n");
Felipe Balbi72246da2011-08-19 18:10:58 +0300266
Felipe Balbi42077b02011-09-06 12:00:39 +0300267 if (reg & USBOTGSS_IRQ1_DRVVBUS_RISE)
Felipe Balbiccba3bc2011-09-01 14:46:16 +0300268 dev_dbg(omap->dev, "DRVVBUS Rise\n");
Felipe Balbi72246da2011-08-19 18:10:58 +0300269
Felipe Balbi42077b02011-09-06 12:00:39 +0300270 if (reg & USBOTGSS_IRQ1_CHRGVBUS_RISE)
Felipe Balbiccba3bc2011-09-01 14:46:16 +0300271 dev_dbg(omap->dev, "CHRGVBUS Rise\n");
Felipe Balbi72246da2011-08-19 18:10:58 +0300272
Felipe Balbi42077b02011-09-06 12:00:39 +0300273 if (reg & USBOTGSS_IRQ1_DISCHRGVBUS_RISE)
Felipe Balbiccba3bc2011-09-01 14:46:16 +0300274 dev_dbg(omap->dev, "DISCHRGVBUS Rise\n");
Felipe Balbi72246da2011-08-19 18:10:58 +0300275
Felipe Balbi42077b02011-09-06 12:00:39 +0300276 if (reg & USBOTGSS_IRQ1_IDPULLUP_RISE)
Felipe Balbiccba3bc2011-09-01 14:46:16 +0300277 dev_dbg(omap->dev, "IDPULLUP Rise\n");
Felipe Balbi72246da2011-08-19 18:10:58 +0300278
Felipe Balbi42077b02011-09-06 12:00:39 +0300279 if (reg & USBOTGSS_IRQ1_DRVVBUS_FALL)
Felipe Balbiccba3bc2011-09-01 14:46:16 +0300280 dev_dbg(omap->dev, "DRVVBUS Fall\n");
Felipe Balbi72246da2011-08-19 18:10:58 +0300281
Felipe Balbi42077b02011-09-06 12:00:39 +0300282 if (reg & USBOTGSS_IRQ1_CHRGVBUS_FALL)
Felipe Balbiccba3bc2011-09-01 14:46:16 +0300283 dev_dbg(omap->dev, "CHRGVBUS Fall\n");
Felipe Balbi72246da2011-08-19 18:10:58 +0300284
Felipe Balbi42077b02011-09-06 12:00:39 +0300285 if (reg & USBOTGSS_IRQ1_DISCHRGVBUS_FALL)
Felipe Balbiccba3bc2011-09-01 14:46:16 +0300286 dev_dbg(omap->dev, "DISCHRGVBUS Fall\n");
Felipe Balbi72246da2011-08-19 18:10:58 +0300287
Felipe Balbi42077b02011-09-06 12:00:39 +0300288 if (reg & USBOTGSS_IRQ1_IDPULLUP_FALL)
Felipe Balbiccba3bc2011-09-01 14:46:16 +0300289 dev_dbg(omap->dev, "IDPULLUP Fall\n");
Felipe Balbi72246da2011-08-19 18:10:58 +0300290
Ido Shayevitzab5e59d2012-04-24 14:18:38 +0300291 dwc3_omap_writel(omap->base, USBOTGSS_IRQSTATUS_1, reg);
Felipe Balbi42077b02011-09-06 12:00:39 +0300292
Ido Shayevitzab5e59d2012-04-24 14:18:38 +0300293 reg = dwc3_omap_readl(omap->base, USBOTGSS_IRQSTATUS_0);
294 dwc3_omap_writel(omap->base, USBOTGSS_IRQSTATUS_0, reg);
Felipe Balbi72246da2011-08-19 18:10:58 +0300295
296 spin_unlock(&omap->lock);
297
298 return IRQ_HANDLED;
299}
300
Kishon Vijay Abraham I94c6a432013-01-25 08:30:45 +0530301static int dwc3_omap_remove_core(struct device *dev, void *c)
302{
303 struct platform_device *pdev = to_platform_device(dev);
304
305 platform_device_unregister(pdev);
306
307 return 0;
308}
309
Bill Pemberton41ac7b32012-11-19 13:21:48 -0500310static int dwc3_omap_probe(struct platform_device *pdev)
Felipe Balbi72246da2011-08-19 18:10:58 +0300311{
Felipe Balbi99624442011-09-01 22:26:25 +0300312 struct dwc3_omap_data *pdata = pdev->dev.platform_data;
Felipe Balbi45b3cd4a2012-01-25 11:07:03 +0200313 struct device_node *node = pdev->dev.of_node;
314
Felipe Balbi72246da2011-08-19 18:10:58 +0300315 struct dwc3_omap *omap;
316 struct resource *res;
Chanho Park802ca852012-02-15 18:27:55 +0900317 struct device *dev = &pdev->dev;
Felipe Balbi72246da2011-08-19 18:10:58 +0300318
Felipe Balbi45b3cd4a2012-01-25 11:07:03 +0200319 int size;
Felipe Balbi72246da2011-08-19 18:10:58 +0300320 int ret = -ENOMEM;
321 int irq;
322
Felipe Balbi45b3cd4a2012-01-25 11:07:03 +0200323 const u32 *utmi_mode;
Felipe Balbi72246da2011-08-19 18:10:58 +0300324 u32 reg;
325
326 void __iomem *base;
327 void *context;
328
Chanho Park802ca852012-02-15 18:27:55 +0900329 omap = devm_kzalloc(dev, sizeof(*omap), GFP_KERNEL);
Felipe Balbi72246da2011-08-19 18:10:58 +0300330 if (!omap) {
Chanho Park802ca852012-02-15 18:27:55 +0900331 dev_err(dev, "not enough memory\n");
332 return -ENOMEM;
Felipe Balbi72246da2011-08-19 18:10:58 +0300333 }
334
335 platform_set_drvdata(pdev, omap);
336
337 irq = platform_get_irq(pdev, 1);
338 if (irq < 0) {
Chanho Park802ca852012-02-15 18:27:55 +0900339 dev_err(dev, "missing IRQ resource\n");
340 return -EINVAL;
Felipe Balbi72246da2011-08-19 18:10:58 +0300341 }
342
343 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
344 if (!res) {
Chanho Park802ca852012-02-15 18:27:55 +0900345 dev_err(dev, "missing memory base resource\n");
346 return -EINVAL;
Felipe Balbi72246da2011-08-19 18:10:58 +0300347 }
348
Chanho Park802ca852012-02-15 18:27:55 +0900349 base = devm_ioremap_nocache(dev, res->start, resource_size(res));
Felipe Balbi72246da2011-08-19 18:10:58 +0300350 if (!base) {
Chanho Park802ca852012-02-15 18:27:55 +0900351 dev_err(dev, "ioremap failed\n");
352 return -ENOMEM;
Felipe Balbi72246da2011-08-19 18:10:58 +0300353 }
354
Felipe Balbia418cc42012-07-19 13:56:07 +0300355 ret = dwc3_omap_register_phys(omap);
356 if (ret) {
357 dev_err(dev, "couldn't register PHYs\n");
358 return ret;
359 }
360
Chanho Park802ca852012-02-15 18:27:55 +0900361 context = devm_kzalloc(dev, resource_size(res), GFP_KERNEL);
Felipe Balbi72246da2011-08-19 18:10:58 +0300362 if (!context) {
Chanho Park802ca852012-02-15 18:27:55 +0900363 dev_err(dev, "couldn't allocate dwc3 context memory\n");
Kishon Vijay Abraham Ib4bfe6a2013-01-25 08:30:46 +0530364 return -ENOMEM;
Felipe Balbi72246da2011-08-19 18:10:58 +0300365 }
366
367 spin_lock_init(&omap->lock);
Felipe Balbi72246da2011-08-19 18:10:58 +0300368
Felipe Balbi72246da2011-08-19 18:10:58 +0300369 omap->resource_size = resource_size(res);
370 omap->context = context;
Chanho Park802ca852012-02-15 18:27:55 +0900371 omap->dev = dev;
Felipe Balbi72246da2011-08-19 18:10:58 +0300372 omap->irq = irq;
373 omap->base = base;
Felipe Balbi72246da2011-08-19 18:10:58 +0300374
Kishon Vijay Abraham I7e41bba2013-01-25 08:30:49 +0530375 /*
376 * REVISIT if we ever have two instances of the wrapper, we will be
377 * in big trouble
378 */
379 _omap = omap;
380
Kishon Vijay Abraham Iaf310e92013-01-25 08:30:47 +0530381 pm_runtime_enable(dev);
382 ret = pm_runtime_get_sync(dev);
383 if (ret < 0) {
384 dev_err(dev, "get_sync failed with err %d\n", ret);
385 return ret;
386 }
387
Ido Shayevitzab5e59d2012-04-24 14:18:38 +0300388 reg = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS);
Felipe Balbi99624442011-09-01 22:26:25 +0300389
Felipe Balbi45b3cd4a2012-01-25 11:07:03 +0200390 utmi_mode = of_get_property(node, "utmi-mode", &size);
391 if (utmi_mode && size == sizeof(*utmi_mode)) {
392 reg |= *utmi_mode;
Felipe Balbi99624442011-09-01 22:26:25 +0300393 } else {
Felipe Balbi45b3cd4a2012-01-25 11:07:03 +0200394 if (!pdata) {
Chanho Park802ca852012-02-15 18:27:55 +0900395 dev_dbg(dev, "missing platform data\n");
Felipe Balbi45b3cd4a2012-01-25 11:07:03 +0200396 } else {
397 switch (pdata->utmi_mode) {
398 case DWC3_OMAP_UTMI_MODE_SW:
399 reg |= USBOTGSS_UTMI_OTG_STATUS_SW_MODE;
400 break;
401 case DWC3_OMAP_UTMI_MODE_HW:
402 reg &= ~USBOTGSS_UTMI_OTG_STATUS_SW_MODE;
403 break;
404 default:
Chanho Park802ca852012-02-15 18:27:55 +0900405 dev_dbg(dev, "UNKNOWN utmi mode %d\n",
Felipe Balbi45b3cd4a2012-01-25 11:07:03 +0200406 pdata->utmi_mode);
407 }
Felipe Balbi99624442011-09-01 22:26:25 +0300408 }
409 }
410
Ido Shayevitzab5e59d2012-04-24 14:18:38 +0300411 dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, reg);
Felipe Balbi99624442011-09-01 22:26:25 +0300412
Felipe Balbi72246da2011-08-19 18:10:58 +0300413 /* check the DMA Status */
Ido Shayevitzab5e59d2012-04-24 14:18:38 +0300414 reg = dwc3_omap_readl(omap->base, USBOTGSS_SYSCONFIG);
Felipe Balbi72246da2011-08-19 18:10:58 +0300415 omap->dma_status = !!(reg & USBOTGSS_SYSCONFIG_DMADISABLE);
416
Chanho Park802ca852012-02-15 18:27:55 +0900417 ret = devm_request_irq(dev, omap->irq, dwc3_omap_interrupt, 0,
Felipe Balbidd17a6b2011-09-06 10:57:41 +0300418 "dwc3-omap", omap);
Felipe Balbi72246da2011-08-19 18:10:58 +0300419 if (ret) {
Chanho Park802ca852012-02-15 18:27:55 +0900420 dev_err(dev, "failed to request IRQ #%d --> %d\n",
Felipe Balbi72246da2011-08-19 18:10:58 +0300421 omap->irq, ret);
Kishon Vijay Abraham Ib4bfe6a2013-01-25 08:30:46 +0530422 return ret;
Felipe Balbi72246da2011-08-19 18:10:58 +0300423 }
424
425 /* enable all IRQs */
Felipe Balbidf01c612011-09-01 18:22:01 +0300426 reg = USBOTGSS_IRQO_COREIRQ_ST;
Ido Shayevitzab5e59d2012-04-24 14:18:38 +0300427 dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_0, reg);
Felipe Balbi72246da2011-08-19 18:10:58 +0300428
Felipe Balbi324e5482011-09-01 14:52:52 +0300429 reg = (USBOTGSS_IRQ1_OEVT |
Felipe Balbi72246da2011-08-19 18:10:58 +0300430 USBOTGSS_IRQ1_DRVVBUS_RISE |
431 USBOTGSS_IRQ1_CHRGVBUS_RISE |
432 USBOTGSS_IRQ1_DISCHRGVBUS_RISE |
433 USBOTGSS_IRQ1_IDPULLUP_RISE |
434 USBOTGSS_IRQ1_DRVVBUS_FALL |
435 USBOTGSS_IRQ1_CHRGVBUS_FALL |
436 USBOTGSS_IRQ1_DISCHRGVBUS_FALL |
437 USBOTGSS_IRQ1_IDPULLUP_FALL);
438
Ido Shayevitzab5e59d2012-04-24 14:18:38 +0300439 dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_1, reg);
Felipe Balbi72246da2011-08-19 18:10:58 +0300440
Kishon Vijay Abraham Ib4bfe6a2013-01-25 08:30:46 +0530441 if (node) {
442 ret = of_platform_populate(node, NULL, NULL, dev);
443 if (ret) {
444 dev_err(&pdev->dev,
445 "failed to add create dwc3 core\n");
446 return ret;
447 }
Felipe Balbi72246da2011-08-19 18:10:58 +0300448 }
449
450 return 0;
Felipe Balbi72246da2011-08-19 18:10:58 +0300451}
452
Bill Pembertonfb4e98a2012-11-19 13:26:20 -0500453static int dwc3_omap_remove(struct platform_device *pdev)
Felipe Balbi72246da2011-08-19 18:10:58 +0300454{
455 struct dwc3_omap *omap = platform_get_drvdata(pdev);
456
Felipe Balbia418cc42012-07-19 13:56:07 +0300457 platform_device_unregister(omap->usb2_phy);
458 platform_device_unregister(omap->usb3_phy);
Kishon Vijay Abraham Iaf310e92013-01-25 08:30:47 +0530459 pm_runtime_put_sync(&pdev->dev);
460 pm_runtime_disable(&pdev->dev);
Kishon Vijay Abraham I94c6a432013-01-25 08:30:45 +0530461 device_for_each_child(&pdev->dev, NULL, dwc3_omap_remove_core);
462
Felipe Balbi72246da2011-08-19 18:10:58 +0300463 return 0;
464}
465
Felipe Balbi2c2dc892013-02-11 10:31:15 +0200466static const struct of_device_id of_dwc3_match[] = {
Felipe Balbi72246da2011-08-19 18:10:58 +0300467 {
468 "ti,dwc3",
469 },
470 { },
471};
Felipe Balbi2c2dc892013-02-11 10:31:15 +0200472MODULE_DEVICE_TABLE(of, of_dwc3_match);
Felipe Balbi72246da2011-08-19 18:10:58 +0300473
474static struct platform_driver dwc3_omap_driver = {
475 .probe = dwc3_omap_probe,
Bill Pemberton76904172012-11-19 13:21:08 -0500476 .remove = dwc3_omap_remove,
Felipe Balbi72246da2011-08-19 18:10:58 +0300477 .driver = {
478 .name = "omap-dwc3",
Felipe Balbi2c2dc892013-02-11 10:31:15 +0200479 .of_match_table = of_dwc3_match,
Felipe Balbi72246da2011-08-19 18:10:58 +0300480 },
481};
482
Axel Lincc27c962011-11-27 20:16:27 +0800483module_platform_driver(dwc3_omap_driver);
484
Sebastian Andrzej Siewior7ae4fc42011-10-19 19:39:50 +0200485MODULE_ALIAS("platform:omap-dwc3");
Felipe Balbi72246da2011-08-19 18:10:58 +0300486MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
487MODULE_LICENSE("Dual BSD/GPL");
488MODULE_DESCRIPTION("DesignWare USB3 OMAP Glue Layer");