216
217
l = musb_readl(musb->mregs, OTG_FORCESTDBY);
217
218
l |= ENABLEFORCE; /* enable MSTANDBY */
218
219
musb_writel(musb->mregs, OTG_FORCESTDBY, l);
220
l = musb_readl(musb->mregs, OTG_SYSCONFIG);
221
l |= ENABLEWAKEUP; /* enable wakeup */
222
musb_writel(musb->mregs, OTG_SYSCONFIG, l);
225
222
static inline void omap2430_low_level_init(struct musb *musb)
229
l = musb_readl(musb->mregs, OTG_SYSCONFIG);
230
l &= ~ENABLEWAKEUP; /* disable wakeup */
231
musb_writel(musb->mregs, OTG_SYSCONFIG, l);
233
226
l = musb_readl(musb->mregs, OTG_FORCESTDBY);
234
227
l &= ~ENABLEFORCE; /* disable MSTANDBY */
235
228
musb_writel(musb->mregs, OTG_FORCESTDBY, l);
251
244
if (is_otg_enabled(musb)) {
252
245
#ifdef CONFIG_USB_GADGET_MUSB_HDRC
253
246
if (musb->gadget_driver) {
247
pm_runtime_get_sync(musb->controller);
254
248
otg_init(musb->xceiv);
256
if (data->interface_type ==
258
omap2430_musb_set_vbus(musb, 1);
249
omap2430_musb_set_vbus(musb, 1);
253
pm_runtime_get_sync(musb->controller);
263
254
otg_init(musb->xceiv);
264
if (data->interface_type ==
266
omap2430_musb_set_vbus(musb, 1);
255
omap2430_musb_set_vbus(musb, 1);
270
259
case USB_EVENT_VBUS:
271
260
DBG(4, "VBUS Connect\n");
262
#ifdef CONFIG_USB_GADGET_MUSB_HDRC
263
if (musb->gadget_driver)
264
pm_runtime_get_sync(musb->controller);
273
266
otg_init(musb->xceiv);
276
269
case USB_EVENT_NONE:
277
270
DBG(4, "VBUS Disconnect\n");
272
#ifdef CONFIG_USB_GADGET_MUSB_HDRC
273
if (is_otg_enabled(musb) || is_peripheral_enabled(musb))
274
if (musb->gadget_driver)
277
pm_runtime_mark_last_busy(musb->controller);
278
pm_runtime_put_autosuspend(musb->controller);
279
281
if (data->interface_type == MUSB_INTERFACE_UTMI) {
280
282
if (musb->xceiv->set_vbus)
281
283
otg_set_vbus(musb->xceiv, 0);
310
omap2430_low_level_init(musb);
312
l = musb_readl(musb->mregs, OTG_SYSCONFIG);
313
l &= ~ENABLEWAKEUP; /* disable wakeup */
314
l &= ~NOSTDBY; /* remove possible nostdby */
315
l |= SMARTSTDBY; /* enable smart standby */
316
l &= ~AUTOIDLE; /* disable auto idle */
317
l &= ~NOIDLE; /* remove possible noidle */
318
l |= SMARTIDLE; /* enable smart idle */
320
* MUSB AUTOIDLE don't work in 3430.
321
* Workaround by Richard Woodruff/TI
323
if (!cpu_is_omap3430())
324
l |= AUTOIDLE; /* enable auto idle */
325
musb_writel(musb->mregs, OTG_SYSCONFIG, l);
312
status = pm_runtime_get_sync(dev);
314
dev_err(dev, "pm_runtime_get_sync FAILED");
327
318
l = musb_readl(musb->mregs, OTG_INTERFSEL);
351
342
DBG(1, "notification register failed\n");
353
/* check whether cable is already connected */
354
if (musb->xceiv->state ==OTG_STATE_B_IDLE)
355
musb_otg_notifications(&musb->nb, 1,
356
musb->xceiv->gadget);
358
344
setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb);
349
pm_runtime_disable(dev);
353
static void omap2430_musb_enable(struct musb *musb)
356
unsigned long timeout = jiffies + msecs_to_jiffies(1000);
357
struct device *dev = musb->controller;
358
struct musb_hdrc_platform_data *pdata = dev->platform_data;
359
struct omap_musb_board_data *data = pdata->board_data;
361
switch (musb->xceiv->last_event) {
364
otg_init(musb->xceiv);
365
if (data->interface_type == MUSB_INTERFACE_UTMI) {
366
devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
367
/* start the session */
368
devctl |= MUSB_DEVCTL_SESSION;
369
musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
370
while (musb_readb(musb->mregs, MUSB_DEVCTL) &
371
MUSB_DEVCTL_BDEVICE) {
374
if (time_after(jiffies, timeout)) {
375
dev_err(musb->controller,
376
"configured as A device timeout");
384
otg_init(musb->xceiv);
392
static void omap2430_musb_disable(struct musb *musb)
394
if (musb->xceiv->last_event)
395
otg_shutdown(musb->xceiv);
363
398
static int omap2430_musb_exit(struct musb *musb)
378
413
.try_idle = omap2430_musb_try_idle,
380
415
.set_vbus = omap2430_musb_set_vbus,
417
.enable = omap2430_musb_enable,
418
.disable = omap2430_musb_disable,
383
421
static u64 omap2430_dmamask = DMA_BIT_MASK(32);
387
425
struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data;
388
426
struct platform_device *musb;
389
427
struct omap2430_glue *glue;
392
428
int ret = -ENOMEM;
394
430
glue = kzalloc(sizeof(*glue), GFP_KERNEL);
406
clk = clk_get(&pdev->dev, "ick");
408
dev_err(&pdev->dev, "failed to get clock\n");
413
ret = clk_enable(clk);
415
dev_err(&pdev->dev, "failed to enable clock\n");
419
442
musb->dev.parent = &pdev->dev;
420
443
musb->dev.dma_mask = &omap2430_dmamask;
421
444
musb->dev.coherent_dma_mask = omap2430_dmamask;
423
446
glue->dev = &pdev->dev;
424
447
glue->musb = musb;
427
449
pdata->platform_ops = &omap2430_ops;
432
454
pdev->num_resources);
434
456
dev_err(&pdev->dev, "failed to add resources\n");
438
460
ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
440
462
dev_err(&pdev->dev, "failed to add platform_data\n");
444
466
ret = platform_device_add(musb);
446
468
dev_err(&pdev->dev, "failed to register musb device\n");
472
pm_runtime_enable(&pdev->dev);
459
477
platform_device_put(musb);
472
490
platform_device_del(glue->musb);
473
491
platform_device_put(glue->musb);
474
clk_disable(glue->clk);
492
pm_runtime_put(&pdev->dev);
493
pm_runtime_disable(&pdev->dev);
482
static void omap2430_save_context(struct musb *musb)
484
musb->context.otg_sysconfig = musb_readl(musb->mregs, OTG_SYSCONFIG);
485
musb->context.otg_forcestandby = musb_readl(musb->mregs, OTG_FORCESTDBY);
488
static void omap2430_restore_context(struct musb *musb)
490
musb_writel(musb->mregs, OTG_SYSCONFIG, musb->context.otg_sysconfig);
491
musb_writel(musb->mregs, OTG_FORCESTDBY, musb->context.otg_forcestandby);
494
static int omap2430_suspend(struct device *dev)
501
static int omap2430_runtime_suspend(struct device *dev)
496
503
struct omap2430_glue *glue = dev_get_drvdata(dev);
497
504
struct musb *musb = glue_to_musb(glue);
499
506
omap2430_low_level_exit(musb);
500
507
otg_set_suspend(musb->xceiv, 1);
501
omap2430_save_context(musb);
502
clk_disable(glue->clk);
507
static int omap2430_resume(struct device *dev)
512
static int omap2430_runtime_resume(struct device *dev)
509
514
struct omap2430_glue *glue = dev_get_drvdata(dev);
510
515
struct musb *musb = glue_to_musb(glue);
513
ret = clk_enable(glue->clk);
515
dev_err(dev, "faled to enable clock\n");
519
517
omap2430_low_level_init(musb);
520
omap2430_restore_context(musb);
521
518
otg_set_suspend(musb->xceiv, 0);
526
523
static struct dev_pm_ops omap2430_pm_ops = {
527
.suspend = omap2430_suspend,
528
.resume = omap2430_resume,
524
.runtime_suspend = omap2430_runtime_suspend,
525
.runtime_resume = omap2430_runtime_resume,
531
528
#define DEV_PM_OPS (&omap2430_pm_ops)