27 #include <linux/module.h>
28 #include <linux/kernel.h>
29 #include <linux/sched.h>
31 #include <linux/list.h>
51 #define glue_to_musb(g) platform_get_drvdata(g->musb)
77 static void musb_do_idle(
unsigned long _musb)
86 switch (musb->
xceiv->state) {
116 if (devctl & MUSB_DEVCTL_BDEVICE)
123 spin_unlock_irqrestore(&musb->
lock, flags);
127 static void omap2430_musb_try_idle(
struct musb *musb,
unsigned long timeout)
130 static unsigned long last_timer;
133 timeout = default_timeout;
146 if (!timer_pending(&musb_idle_timer))
147 last_timer = timeout;
153 last_timer = timeout;
161 static void omap2430_musb_set_vbus(
struct musb *musb,
int is_on)
191 "configured as A device timeout");
197 otg_set_vbus(otg, 1);
226 static int omap2430_musb_set_mode(
struct musb *musb,
u8 musb_mode)
236 static inline void omap2430_low_level_exit(
struct musb *musb)
246 static inline void omap2430_low_level_init(
struct musb *musb)
262 dev_err(glue->
dev,
"musb core is not yet ready\n");
270 static void omap_musb_set_mailbox(
struct omap2430_glue *glue)
287 pm_runtime_get_sync(dev);
289 omap4_usb_phy_mailbox(glue, val);
290 omap2430_musb_set_vbus(musb, 1);
295 dev_dbg(dev,
"VBUS Connect\n");
301 pm_runtime_get_sync(dev);
303 omap4_usb_phy_mailbox(glue, val);
308 dev_dbg(dev,
"VBUS Disconnect\n");
312 pm_runtime_mark_last_busy(dev);
313 pm_runtime_put_autosuspend(dev);
316 if (data->interface_type == MUSB_INTERFACE_UTMI) {
317 if (musb->
xceiv->otg->set_vbus)
318 otg_set_vbus(musb->
xceiv->otg, 0);
321 omap4_usb_phy_mailbox(glue, val);
329 static void omap_musb_mailbox_work(
struct work_struct *mailbox_work)
333 omap_musb_set_mailbox(glue);
336 static int omap2430_musb_init(
struct musb *musb)
343 struct omap_musb_board_data *data = plat->
board_data;
350 if (IS_ERR_OR_NULL(musb->
xceiv)) {
351 pr_err(
"HS USB OTG: no transceiver configured\n");
355 status = pm_runtime_get_sync(dev);
357 dev_err(dev,
"pm_runtime_get_sync FAILED %d\n", status);
363 if (data->interface_type == MUSB_INTERFACE_UTMI) {
373 pr_debug(
"HS USB OTG: revision 0x%x, sysconfig 0x%02x, "
374 "sysstatus 0x%x, intrfsel 0x%x, simenable 0x%x\n",
381 setup_timer(&musb_idle_timer, musb_do_idle, (
unsigned long) musb);
384 omap_musb_set_mailbox(glue);
393 static void omap2430_musb_enable(
struct musb *musb)
401 struct omap_musb_board_data *data = pdata->
board_data;
407 omap4_usb_phy_mailbox(glue, val);
408 if (data->interface_type != MUSB_INTERFACE_UTMI)
415 MUSB_DEVCTL_BDEVICE) {
419 dev_err(dev,
"configured as A device timeout");
427 omap4_usb_phy_mailbox(glue, val);
435 static void omap2430_musb_disable(
struct musb *musb)
443 omap4_usb_phy_mailbox(glue, val);
447 static int omap2430_musb_exit(
struct musb *musb)
451 omap2430_low_level_exit(musb);
457 .init = omap2430_musb_init,
458 .exit = omap2430_musb_exit,
460 .set_mode = omap2430_musb_set_mode,
461 .try_idle = omap2430_musb_try_idle,
463 .set_vbus = omap2430_musb_set_vbus,
465 .enable = omap2430_musb_enable,
466 .disable = omap2430_musb_disable,
474 struct omap_musb_board_data *
data;
485 dev_err(&pdev->
dev,
"failed to allocate glue context\n");
492 dev_err(&pdev->
dev,
"failed to allocate musb id\n");
499 dev_err(&pdev->
dev,
"failed to allocate musb device\n");
504 musb->
dev.parent = &pdev->
dev;
505 musb->
dev.dma_mask = &omap2430_dmamask;
506 musb->
dev.coherent_dma_mask = omap2430_dmamask;
516 dev_dbg(&pdev->
dev,
"Failed to obtain control memory\n");
522 "failed to allocate musb platfrom data\n");
530 "failed to allocate musb board data\n");
538 "failed to allocate musb hdrc config\n");
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");
556 platform_set_drvdata(pdev, glue);
569 dev_err(&pdev->
dev,
"failed to add resources\n");
575 dev_err(&pdev->
dev,
"failed to add platform_data\n");
583 dev_err(&pdev->
dev,
"failed to register musb device\n");
612 static int omap2430_runtime_suspend(
struct device *dev)
621 omap2430_low_level_exit(musb);
622 usb_phy_set_suspend(musb->
xceiv, 1);
628 static int omap2430_runtime_resume(
struct device *dev)
634 omap2430_low_level_init(musb);
638 usb_phy_set_suspend(musb->
xceiv, 0);
646 .runtime_resume = omap2430_runtime_resume,
649 #define DEV_PM_OPS (&omap2430_pm_ops)
651 #define DEV_PM_OPS NULL
655 static const struct of_device_id omap2430_id_table[] = {
660 .compatible =
"ti,omap3-musb"
668 .probe = omap2430_probe,
671 .name =
"musb-omap2430",
681 static int __init omap2430_init(
void)
687 static void __exit omap2430_exit(
void)