usb: musb: Perform only write access on MUSB_INTRTXE
[deliverable/linux.git] / drivers / usb / musb / omap2430.c
CommitLineData
550a7375
FB
1/*
2 * Copyright (C) 2005-2007 by Texas Instruments
3 * Some code has been taken from tusb6010.c
4 * Copyrights for that are attributable to:
5 * Copyright (C) 2006 Nokia Corporation
550a7375
FB
6 * Tony Lindgren <tony@atomide.com>
7 *
8 * This file is part of the Inventra Controller Driver for Linux.
9 *
10 * The Inventra Controller Driver for Linux is free software; you
11 * can redistribute it and/or modify it under the terms of the GNU
12 * General Public License version 2 as published by the Free Software
13 * Foundation.
14 *
15 * The Inventra Controller Driver for Linux is distributed in
16 * the hope that it will be useful, but WITHOUT ANY WARRANTY;
17 * without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
19 * License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with The Inventra Controller Driver for Linux ; if not,
23 * write to the Free Software Foundation, Inc., 59 Temple Place,
24 * Suite 330, Boston, MA 02111-1307 USA
25 *
26 */
27#include <linux/module.h>
28#include <linux/kernel.h>
29#include <linux/sched.h>
550a7375
FB
30#include <linux/init.h>
31#include <linux/list.h>
550a7375 32#include <linux/io.h>
00a0b1d5 33#include <linux/of.h>
dc09886b
FB
34#include <linux/platform_device.h>
35#include <linux/dma-mapping.h>
207b0e1f
HH
36#include <linux/pm_runtime.h>
37#include <linux/err.h>
12a19b5f 38#include <linux/delay.h>
c9721438 39#include <linux/usb/musb-omap.h>
550a7375 40
550a7375
FB
41#include "musb_core.h"
42#include "omap2430.h"
43
a3cee12a
FB
44struct omap2430_glue {
45 struct device *dev;
46 struct platform_device *musb;
c9721438 47 enum omap_musb_vbus_id_status status;
1e5acb8d 48 struct work_struct omap_musb_mailbox_work;
5ec40590 49 u32 __iomem *control_otghs;
a3cee12a 50};
c20aebb9 51#define glue_to_musb(g) platform_get_drvdata(g->musb)
a3cee12a 52
c9721438
KVA
53struct omap2430_glue *_glue;
54
550a7375
FB
55static struct timer_list musb_idle_timer;
56
5ec40590
KVA
57/**
58 * omap4_usb_phy_mailbox - write to usb otg mailbox
59 * @glue: struct omap2430_glue *
60 * @val: the value to be written to the mailbox
61 *
62 * On detection of a device (ID pin is grounded), this API should be called
63 * to set AVALID, VBUSVALID and ID pin is grounded.
64 *
65 * When OMAP is connected to a host (OMAP in device mode), this API
66 * is called to set AVALID, VBUSVALID and ID pin in high impedance.
67 *
68 * XXX: This function will be removed once we have a seperate driver for
69 * control module
70 */
71static void omap4_usb_phy_mailbox(struct omap2430_glue *glue, u32 val)
72{
73 if (glue->control_otghs)
74 writel(val, glue->control_otghs);
75}
76
550a7375
FB
77static void musb_do_idle(unsigned long _musb)
78{
79 struct musb *musb = (void *)_musb;
80 unsigned long flags;
81 u8 power;
82 u8 devctl;
83
550a7375
FB
84 spin_lock_irqsave(&musb->lock, flags);
85
84e250ff 86 switch (musb->xceiv->state) {
550a7375 87 case OTG_STATE_A_WAIT_BCON:
550a7375
FB
88
89 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
90 if (devctl & MUSB_DEVCTL_BDEVICE) {
84e250ff 91 musb->xceiv->state = OTG_STATE_B_IDLE;
550a7375
FB
92 MUSB_DEV_MODE(musb);
93 } else {
84e250ff 94 musb->xceiv->state = OTG_STATE_A_IDLE;
550a7375
FB
95 MUSB_HST_MODE(musb);
96 }
97 break;
550a7375
FB
98 case OTG_STATE_A_SUSPEND:
99 /* finish RESUME signaling? */
100 if (musb->port1_status & MUSB_PORT_STAT_RESUME) {
101 power = musb_readb(musb->mregs, MUSB_POWER);
102 power &= ~MUSB_POWER_RESUME;
5c8a86e1 103 dev_dbg(musb->controller, "root port resume stopped, power %02x\n", power);
550a7375
FB
104 musb_writeb(musb->mregs, MUSB_POWER, power);
105 musb->is_active = 1;
106 musb->port1_status &= ~(USB_PORT_STAT_SUSPEND
107 | MUSB_PORT_STAT_RESUME);
108 musb->port1_status |= USB_PORT_STAT_C_SUSPEND << 16;
109 usb_hcd_poll_rh_status(musb_to_hcd(musb));
110 /* NOTE: it might really be A_WAIT_BCON ... */
84e250ff 111 musb->xceiv->state = OTG_STATE_A_HOST;
550a7375
FB
112 }
113 break;
550a7375
FB
114 case OTG_STATE_A_HOST:
115 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
116 if (devctl & MUSB_DEVCTL_BDEVICE)
84e250ff 117 musb->xceiv->state = OTG_STATE_B_IDLE;
550a7375 118 else
84e250ff 119 musb->xceiv->state = OTG_STATE_A_WAIT_BCON;
550a7375
FB
120 default:
121 break;
122 }
123 spin_unlock_irqrestore(&musb->lock, flags);
124}
125
126
743411b3 127static void omap2430_musb_try_idle(struct musb *musb, unsigned long timeout)
550a7375
FB
128{
129 unsigned long default_timeout = jiffies + msecs_to_jiffies(3);
130 static unsigned long last_timer;
131
132 if (timeout == 0)
133 timeout = default_timeout;
134
135 /* Never idle if active, or when VBUS timeout is not set as host */
136 if (musb->is_active || ((musb->a_wait_bcon == 0)
84e250ff 137 && (musb->xceiv->state == OTG_STATE_A_WAIT_BCON))) {
5c8a86e1 138 dev_dbg(musb->controller, "%s active, deleting timer\n",
3df00453 139 otg_state_string(musb->xceiv->state));
550a7375
FB
140 del_timer(&musb_idle_timer);
141 last_timer = jiffies;
142 return;
143 }
144
145 if (time_after(last_timer, timeout)) {
146 if (!timer_pending(&musb_idle_timer))
147 last_timer = timeout;
148 else {
5c8a86e1 149 dev_dbg(musb->controller, "Longer idle timer already pending, ignoring\n");
550a7375
FB
150 return;
151 }
152 }
153 last_timer = timeout;
154
5c8a86e1 155 dev_dbg(musb->controller, "%s inactive, for idle timer for %lu ms\n",
3df00453 156 otg_state_string(musb->xceiv->state),
550a7375
FB
157 (unsigned long)jiffies_to_msecs(timeout - jiffies));
158 mod_timer(&musb_idle_timer, timeout);
159}
160
743411b3 161static void omap2430_musb_set_vbus(struct musb *musb, int is_on)
550a7375 162{
d445b6da 163 struct usb_otg *otg = musb->xceiv->otg;
550a7375 164 u8 devctl;
594632ef 165 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
550a7375
FB
166 /* HDRC controls CPEN, but beware current surges during device
167 * connect. They can trigger transient overcurrent conditions
168 * that must be ignored.
169 */
170
171 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
172
173 if (is_on) {
594632ef 174 if (musb->xceiv->state == OTG_STATE_A_IDLE) {
12a19b5f 175 int loops = 100;
594632ef
HH
176 /* start the session */
177 devctl |= MUSB_DEVCTL_SESSION;
178 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
179 /*
180 * Wait for the musb to set as A device to enable the
181 * VBUS
182 */
183 while (musb_readb(musb->mregs, MUSB_DEVCTL) & 0x80) {
184
12a19b5f 185 mdelay(5);
594632ef
HH
186 cpu_relax();
187
12a19b5f
N
188 if (time_after(jiffies, timeout)
189 || loops-- <= 0) {
594632ef
HH
190 dev_err(musb->controller,
191 "configured as A device timeout");
594632ef
HH
192 break;
193 }
194 }
195
10770c5a 196 if (otg->set_vbus)
6e13c650 197 otg_set_vbus(otg, 1);
594632ef
HH
198 } else {
199 musb->is_active = 1;
d445b6da 200 otg->default_a = 1;
594632ef
HH
201 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE;
202 devctl |= MUSB_DEVCTL_SESSION;
203 MUSB_HST_MODE(musb);
204 }
550a7375
FB
205 } else {
206 musb->is_active = 0;
207
208 /* NOTE: we're skipping A_WAIT_VFALL -> A_IDLE and
209 * jumping right to B_IDLE...
210 */
211
d445b6da 212 otg->default_a = 0;
84e250ff 213 musb->xceiv->state = OTG_STATE_B_IDLE;
550a7375
FB
214 devctl &= ~MUSB_DEVCTL_SESSION;
215
216 MUSB_DEV_MODE(musb);
217 }
218 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
219
5c8a86e1 220 dev_dbg(musb->controller, "VBUS %s, devctl %02x "
550a7375 221 /* otg %3x conf %08x prcm %08x */ "\n",
3df00453 222 otg_state_string(musb->xceiv->state),
550a7375
FB
223 musb_readb(musb->mregs, MUSB_DEVCTL));
224}
550a7375 225
743411b3 226static int omap2430_musb_set_mode(struct musb *musb, u8 musb_mode)
550a7375
FB
227{
228 u8 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
229
230 devctl |= MUSB_DEVCTL_SESSION;
231 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
232
96a274d1 233 return 0;
550a7375
FB
234}
235
c20aebb9
FB
236static inline void omap2430_low_level_exit(struct musb *musb)
237{
238 u32 l;
239
240 /* in any role */
241 l = musb_readl(musb->mregs, OTG_FORCESTDBY);
242 l |= ENABLEFORCE; /* enable MSTANDBY */
243 musb_writel(musb->mregs, OTG_FORCESTDBY, l);
c20aebb9
FB
244}
245
246static inline void omap2430_low_level_init(struct musb *musb)
247{
248 u32 l;
249
c20aebb9
FB
250 l = musb_readl(musb->mregs, OTG_FORCESTDBY);
251 l &= ~ENABLEFORCE; /* disable MSTANDBY */
252 musb_writel(musb->mregs, OTG_FORCESTDBY, l);
253}
254
c9721438 255void omap_musb_mailbox(enum omap_musb_vbus_id_status status)
594632ef 256{
c9721438
KVA
257 struct omap2430_glue *glue = _glue;
258 struct musb *musb = glue_to_musb(glue);
712d8efa 259
c9721438
KVA
260 glue->status = status;
261 if (!musb) {
262 dev_err(glue->dev, "musb core is not yet ready\n");
263 return;
264 }
712d8efa 265
c9721438 266 schedule_work(&glue->omap_musb_mailbox_work);
712d8efa 267}
c9721438 268EXPORT_SYMBOL_GPL(omap_musb_mailbox);
712d8efa 269
c9721438 270static void omap_musb_set_mailbox(struct omap2430_glue *glue)
712d8efa 271{
5ec40590 272 u32 val;
1e5acb8d 273 struct musb *musb = glue_to_musb(glue);
594632ef
HH
274 struct device *dev = musb->controller;
275 struct musb_hdrc_platform_data *pdata = dev->platform_data;
276 struct omap_musb_board_data *data = pdata->board_data;
c83a8542 277 struct usb_otg *otg = musb->xceiv->otg;
594632ef 278
c9721438
KVA
279 switch (glue->status) {
280 case OMAP_MUSB_ID_GROUND:
281 dev_dbg(dev, "ID GND\n");
594632ef 282
c83a8542
KVA
283 otg->default_a = true;
284 musb->xceiv->state = OTG_STATE_A_IDLE;
c9721438 285 musb->xceiv->last_event = USB_EVENT_ID;
032ec49f 286 if (musb->gadget_driver) {
c9721438 287 pm_runtime_get_sync(dev);
5ec40590
KVA
288 val = AVALID | VBUSVALID;
289 omap4_usb_phy_mailbox(glue, val);
70045c57 290 omap2430_musb_set_vbus(musb, 1);
594632ef
HH
291 }
292 break;
293
c9721438
KVA
294 case OMAP_MUSB_VBUS_VALID:
295 dev_dbg(dev, "VBUS Connect\n");
594632ef 296
c83a8542
KVA
297 otg->default_a = false;
298 musb->xceiv->state = OTG_STATE_B_IDLE;
c9721438 299 musb->xceiv->last_event = USB_EVENT_VBUS;
7acc6197 300 if (musb->gadget_driver)
c9721438 301 pm_runtime_get_sync(dev);
5ec40590
KVA
302 val = IDDIG | AVALID | VBUSVALID;
303 omap4_usb_phy_mailbox(glue, val);
594632ef
HH
304 break;
305
c9721438
KVA
306 case OMAP_MUSB_ID_FLOAT:
307 case OMAP_MUSB_VBUS_OFF:
308 dev_dbg(dev, "VBUS Disconnect\n");
594632ef 309
c9721438 310 musb->xceiv->last_event = USB_EVENT_NONE;
032ec49f
FB
311 if (musb->gadget_driver) {
312 pm_runtime_mark_last_busy(dev);
313 pm_runtime_put_autosuspend(dev);
314 }
7acc6197 315
594632ef 316 if (data->interface_type == MUSB_INTERFACE_UTMI) {
6e13c650
HK
317 if (musb->xceiv->otg->set_vbus)
318 otg_set_vbus(musb->xceiv->otg, 0);
594632ef 319 }
5ec40590
KVA
320 val = SESSEND | IDDIG;
321 omap4_usb_phy_mailbox(glue, val);
594632ef
HH
322 break;
323 default:
c9721438 324 dev_dbg(dev, "ID float\n");
594632ef 325 }
594632ef
HH
326}
327
c9721438
KVA
328
329static void omap_musb_mailbox_work(struct work_struct *mailbox_work)
330{
331 struct omap2430_glue *glue = container_of(mailbox_work,
332 struct omap2430_glue, omap_musb_mailbox_work);
333 omap_musb_set_mailbox(glue);
334}
335
743411b3 336static int omap2430_musb_init(struct musb *musb)
550a7375 337{
ad579699
S
338 u32 l;
339 int status = 0;
ea65df57 340 struct device *dev = musb->controller;
c9721438 341 struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
ea65df57
HK
342 struct musb_hdrc_platform_data *plat = dev->platform_data;
343 struct omap_musb_board_data *data = plat->board_data;
550a7375 344
84e250ff
DB
345 /* We require some kind of external transceiver, hooked
346 * up through ULPI. TWL4030-family PMICs include one,
347 * which needs a driver, drivers aren't always needed.
348 */
b1183c24 349 musb->xceiv = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2);
ded017ee 350 if (IS_ERR_OR_NULL(musb->xceiv)) {
84e250ff
DB
351 pr_err("HS USB OTG: no transceiver configured\n");
352 return -ENODEV;
353 }
354
7acc6197
HH
355 status = pm_runtime_get_sync(dev);
356 if (status < 0) {
ad579699 357 dev_err(dev, "pm_runtime_get_sync FAILED %d\n", status);
7acc6197
HH
358 goto err1;
359 }
550a7375 360
8573e6a6 361 l = musb_readl(musb->mregs, OTG_INTERFSEL);
de2e1b0c
MM
362
363 if (data->interface_type == MUSB_INTERFACE_UTMI) {
364 /* OMAP4 uses Internal PHY GS70 which uses UTMI interface */
365 l &= ~ULPI_12PIN; /* Disable ULPI */
366 l |= UTMI_8BIT; /* Enable UTMI */
367 } else {
368 l |= ULPI_12PIN;
369 }
370
8573e6a6 371 musb_writel(musb->mregs, OTG_INTERFSEL, l);
550a7375
FB
372
373 pr_debug("HS USB OTG: revision 0x%x, sysconfig 0x%02x, "
374 "sysstatus 0x%x, intrfsel 0x%x, simenable 0x%x\n",
8573e6a6
FB
375 musb_readl(musb->mregs, OTG_REVISION),
376 musb_readl(musb->mregs, OTG_SYSCONFIG),
377 musb_readl(musb->mregs, OTG_SYSSTATUS),
378 musb_readl(musb->mregs, OTG_INTERFSEL),
379 musb_readl(musb->mregs, OTG_SIMENABLE));
550a7375 380
550a7375
FB
381 setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb);
382
c9721438
KVA
383 if (glue->status != OMAP_MUSB_UNKNOWN)
384 omap_musb_set_mailbox(glue);
385
c04352a5 386 pm_runtime_put_noidle(musb->controller);
550a7375 387 return 0;
7acc6197
HH
388
389err1:
7acc6197 390 return status;
550a7375
FB
391}
392
002eda13
HH
393static void omap2430_musb_enable(struct musb *musb)
394{
395 u8 devctl;
5ec40590 396 u32 val;
002eda13
HH
397 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
398 struct device *dev = musb->controller;
c9721438 399 struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
002eda13
HH
400 struct musb_hdrc_platform_data *pdata = dev->platform_data;
401 struct omap_musb_board_data *data = pdata->board_data;
402
c9721438 403 switch (glue->status) {
002eda13 404
c9721438 405 case OMAP_MUSB_ID_GROUND:
5ec40590
KVA
406 val = AVALID | VBUSVALID;
407 omap4_usb_phy_mailbox(glue, val);
08dec56e
FC
408 if (data->interface_type != MUSB_INTERFACE_UTMI)
409 break;
410 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
411 /* start the session */
412 devctl |= MUSB_DEVCTL_SESSION;
413 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
414 while (musb_readb(musb->mregs, MUSB_DEVCTL) &
415 MUSB_DEVCTL_BDEVICE) {
416 cpu_relax();
417
418 if (time_after(jiffies, timeout)) {
419 dev_err(dev, "configured as A device timeout");
420 break;
002eda13
HH
421 }
422 }
423 break;
424
c9721438 425 case OMAP_MUSB_VBUS_VALID:
5ec40590
KVA
426 val = IDDIG | AVALID | VBUSVALID;
427 omap4_usb_phy_mailbox(glue, val);
002eda13
HH
428 break;
429
430 default:
431 break;
432 }
433}
434
435static void omap2430_musb_disable(struct musb *musb)
436{
5ec40590 437 u32 val;
c9721438
KVA
438 struct device *dev = musb->controller;
439 struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
440
5ec40590
KVA
441 if (glue->status != OMAP_MUSB_UNKNOWN) {
442 val = SESSEND | IDDIG;
443 omap4_usb_phy_mailbox(glue, val);
444 }
550a7375
FB
445}
446
743411b3 447static int omap2430_musb_exit(struct musb *musb)
550a7375 448{
19b9a83e 449 del_timer_sync(&musb_idle_timer);
550a7375 450
c20aebb9 451 omap2430_low_level_exit(musb);
c20aebb9 452
550a7375
FB
453 return 0;
454}
743411b3 455
f7ec9437 456static const struct musb_platform_ops omap2430_ops = {
743411b3
FB
457 .init = omap2430_musb_init,
458 .exit = omap2430_musb_exit,
459
743411b3
FB
460 .set_mode = omap2430_musb_set_mode,
461 .try_idle = omap2430_musb_try_idle,
462
463 .set_vbus = omap2430_musb_set_vbus,
002eda13
HH
464
465 .enable = omap2430_musb_enable,
466 .disable = omap2430_musb_disable,
743411b3 467};
dc09886b
FB
468
469static u64 omap2430_dmamask = DMA_BIT_MASK(32);
470
e9e8c85e 471static int __devinit omap2430_probe(struct platform_device *pdev)
dc09886b
FB
472{
473 struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data;
00a0b1d5 474 struct omap_musb_board_data *data;
dc09886b 475 struct platform_device *musb;
a3cee12a 476 struct omap2430_glue *glue;
00a0b1d5
KVA
477 struct device_node *np = pdev->dev.of_node;
478 struct musb_hdrc_config *config;
5ec40590 479 struct resource *res;
dc09886b 480 int ret = -ENOMEM;
65b3d52d 481 int musbid;
dc09886b 482
b1183c24 483 glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL);
a3cee12a
FB
484 if (!glue) {
485 dev_err(&pdev->dev, "failed to allocate glue context\n");
486 goto err0;
487 }
488
65b3d52d
R
489 /* get the musb id */
490 musbid = musb_get_id(&pdev->dev, GFP_KERNEL);
491 if (musbid < 0) {
492 dev_err(&pdev->dev, "failed to allocate musb id\n");
493 ret = -ENOMEM;
494 goto err0;
495 }
496
497 musb = platform_device_alloc("musb-hdrc", musbid);
dc09886b
FB
498 if (!musb) {
499 dev_err(&pdev->dev, "failed to allocate musb device\n");
65b3d52d 500 goto err1;
dc09886b
FB
501 }
502
65b3d52d 503 musb->id = musbid;
dc09886b
FB
504 musb->dev.parent = &pdev->dev;
505 musb->dev.dma_mask = &omap2430_dmamask;
506 musb->dev.coherent_dma_mask = omap2430_dmamask;
507
a3cee12a
FB
508 glue->dev = &pdev->dev;
509 glue->musb = musb;
c9721438 510 glue->status = OMAP_MUSB_UNKNOWN;
a3cee12a 511
5ec40590
KVA
512 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
513
514 glue->control_otghs = devm_request_and_ioremap(&pdev->dev, res);
515 if (glue->control_otghs == NULL)
516 dev_dbg(&pdev->dev, "Failed to obtain control memory\n");
517
00a0b1d5
KVA
518 if (np) {
519 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
520 if (!pdata) {
521 dev_err(&pdev->dev,
522 "failed to allocate musb platfrom data\n");
523 ret = -ENOMEM;
524 goto err1;
525 }
526
527 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
528 if (!data) {
529 dev_err(&pdev->dev,
530 "failed to allocate musb board data\n");
531 ret = -ENOMEM;
532 goto err1;
533 }
534
535 config = devm_kzalloc(&pdev->dev, sizeof(*config), GFP_KERNEL);
536 if (!data) {
537 dev_err(&pdev->dev,
538 "failed to allocate musb hdrc config\n");
539 goto err1;
540 }
541
542 of_property_read_u32(np, "mode", (u32 *)&pdata->mode);
543 of_property_read_u32(np, "interface_type",
544 (u32 *)&data->interface_type);
545 of_property_read_u32(np, "num_eps", (u32 *)&config->num_eps);
546 of_property_read_u32(np, "ram_bits", (u32 *)&config->ram_bits);
547 of_property_read_u32(np, "power", (u32 *)&pdata->power);
548 config->multipoint = of_property_read_bool(np, "multipoint");
549
550 pdata->board_data = data;
551 pdata->config = config;
552 }
553
f7ec9437
FB
554 pdata->platform_ops = &omap2430_ops;
555
a3cee12a 556 platform_set_drvdata(pdev, glue);
dc09886b 557
c9721438
KVA
558 /*
559 * REVISIT if we ever have two instances of the wrapper, we will be
560 * in big trouble
561 */
562 _glue = glue;
563
1e5acb8d
KVA
564 INIT_WORK(&glue->omap_musb_mailbox_work, omap_musb_mailbox_work);
565
dc09886b
FB
566 ret = platform_device_add_resources(musb, pdev->resource,
567 pdev->num_resources);
568 if (ret) {
569 dev_err(&pdev->dev, "failed to add resources\n");
65b3d52d 570 goto err2;
dc09886b
FB
571 }
572
573 ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
574 if (ret) {
575 dev_err(&pdev->dev, "failed to add platform_data\n");
65b3d52d 576 goto err2;
dc09886b
FB
577 }
578
3006dc8c
KVA
579 pm_runtime_enable(&pdev->dev);
580
dc09886b
FB
581 ret = platform_device_add(musb);
582 if (ret) {
583 dev_err(&pdev->dev, "failed to register musb device\n");
65b3d52d 584 goto err2;
dc09886b
FB
585 }
586
207b0e1f 587 return 0;
03491761 588
65b3d52d 589err2:
b1183c24 590 platform_device_put(musb);
a3cee12a 591
65b3d52d
R
592err1:
593 musb_put_id(&pdev->dev, musbid);
594
dc09886b
FB
595err0:
596 return ret;
597}
598
e9e8c85e 599static int __devexit omap2430_remove(struct platform_device *pdev)
dc09886b 600{
a3cee12a 601 struct omap2430_glue *glue = platform_get_drvdata(pdev);
dc09886b 602
1e5acb8d 603 cancel_work_sync(&glue->omap_musb_mailbox_work);
65b3d52d 604 musb_put_id(&pdev->dev, glue->musb->id);
f039df58 605 platform_device_unregister(glue->musb);
dc09886b
FB
606
607 return 0;
608}
609
c20aebb9 610#ifdef CONFIG_PM
c20aebb9 611
7acc6197 612static int omap2430_runtime_suspend(struct device *dev)
c20aebb9
FB
613{
614 struct omap2430_glue *glue = dev_get_drvdata(dev);
615 struct musb *musb = glue_to_musb(glue);
616
afb76df1
VZ
617 if (musb) {
618 musb->context.otg_interfsel = musb_readl(musb->mregs,
619 OTG_INTERFSEL);
e25bec16 620
afb76df1
VZ
621 omap2430_low_level_exit(musb);
622 usb_phy_set_suspend(musb->xceiv, 1);
623 }
c20aebb9
FB
624
625 return 0;
626}
627
7acc6197 628static int omap2430_runtime_resume(struct device *dev)
c20aebb9
FB
629{
630 struct omap2430_glue *glue = dev_get_drvdata(dev);
631 struct musb *musb = glue_to_musb(glue);
c20aebb9 632
afb76df1
VZ
633 if (musb) {
634 omap2430_low_level_init(musb);
635 musb_writel(musb->mregs, OTG_INTERFSEL,
636 musb->context.otg_interfsel);
e25bec16 637
afb76df1
VZ
638 usb_phy_set_suspend(musb->xceiv, 0);
639 }
c20aebb9
FB
640
641 return 0;
642}
643
644static struct dev_pm_ops omap2430_pm_ops = {
7acc6197
HH
645 .runtime_suspend = omap2430_runtime_suspend,
646 .runtime_resume = omap2430_runtime_resume,
c20aebb9
FB
647};
648
649#define DEV_PM_OPS (&omap2430_pm_ops)
650#else
651#define DEV_PM_OPS NULL
652#endif
653
00a0b1d5
KVA
654#ifdef CONFIG_OF
655static const struct of_device_id omap2430_id_table[] = {
656 {
657 .compatible = "ti,omap4-musb"
658 },
659 {
660 .compatible = "ti,omap3-musb"
661 },
662 {},
663};
664MODULE_DEVICE_TABLE(of, omap2430_id_table);
665#endif
666
dc09886b 667static struct platform_driver omap2430_driver = {
e9e8c85e
FB
668 .probe = omap2430_probe,
669 .remove = __devexit_p(omap2430_remove),
dc09886b
FB
670 .driver = {
671 .name = "musb-omap2430",
c20aebb9 672 .pm = DEV_PM_OPS,
00a0b1d5 673 .of_match_table = of_match_ptr(omap2430_id_table),
dc09886b
FB
674 },
675};
676
677MODULE_DESCRIPTION("OMAP2PLUS MUSB Glue Layer");
678MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
679MODULE_LICENSE("GPL v2");
680
681static int __init omap2430_init(void)
682{
e9e8c85e 683 return platform_driver_register(&omap2430_driver);
dc09886b 684}
c9721438 685subsys_initcall(omap2430_init);
dc09886b
FB
686
687static void __exit omap2430_exit(void)
688{
689 platform_driver_unregister(&omap2430_driver);
690}
691module_exit(omap2430_exit);
This page took 0.380197 seconds and 5 git commands to generate.